]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/server: stop using libcurl string comparisons
authorDaniel Stenberg <daniel@haxx.se>
Mon, 12 May 2025 20:48:47 +0000 (22:48 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 13 May 2025 08:28:19 +0000 (10:28 +0200)
Further untangle the test server code from curl code. While the string
comparison functions are available in the libcurl API, the tests servers
don't link with libcurl. Use native functions instead.

Closes #17328

lib/curlx/strparse.c
tests/server/CMakeLists.txt
tests/server/Makefile.am
tests/server/Makefile.inc
tests/server/rtspd.c
tests/server/sws.c
tests/server/util.h

index d501d56d575014d963dd73179a445bc2273dafbf..b8b2a14d3cb1181e5b1a81eb046e97753080884d 100644 (file)
@@ -232,13 +232,15 @@ int curlx_str_newline(const char **linep)
   return STRE_NEWLINE;
 }
 
-/* case insensitive compare that the parsed string matches the
-   given string. Returns non-zero on match. */
+#ifndef WITHOUT_LIBCURL
+/* case insensitive compare that the parsed string matches the given string.
+   Returns non-zero on match. */
 int curlx_str_casecompare(struct Curl_str *str, const char *check)
 {
   size_t clen = check ? strlen(check) : 0;
   return ((str->len == clen) && strncasecompare(str->str, check, clen));
 }
+#endif
 
 /* case sensitive string compare. Returns non-zero on match. */
 int curlx_str_cmp(struct Curl_str *str, const char *check)
index 8ff5c65c3a567bc3e25bb097595635112002617d..17bf633000486bd204dce9a22f816f44a0d9b085 100644 (file)
@@ -58,6 +58,7 @@ foreach(_target IN LISTS SERVERPROGS)
   if(ENABLE_SERVER_DEBUG)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
   endif()
+  set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "WITHOUT_LIBCURL")
   # Test servers simply are standalone programs that do not use libcurl
   # library.  For convenience and to ease portability of these servers,
   # some source code files from the libcurl subdirectory are also used
index a99f14c8357c5008357874a5efc45834140a5d07..3b3e6a80e01f0570f772380a92e6bb4c032f7f88 100644 (file)
@@ -57,6 +57,8 @@ AM_CPPFLAGS += -DCURLDEBUG
 endif
 endif
 
+AM_CPPFLAGS += -DWITHOUT_LIBCURL
+
 # Makefile.inc provides neat definitions
 include Makefile.inc
 
index 00cc9a71c14252799afff0cd739d01b42ee7d470..f80d4eab566ab5d8030feaf0364d8b06df389be2 100644 (file)
@@ -31,11 +31,9 @@ MEMDEBUG = \
 CURLX_SRCS = \
   ../../lib/curlx/nonblock.c \
   ../../lib/curlx/strparse.c \
-  ../../lib/strequal.c \
   ../../lib/curlx/warnless.c \
   ../../lib/curlx/timediff.c \
   ../../lib/curlx/timeval.c \
-  ../../lib/strcase.c \
   ../../lib/curlx/multibyte.c \
   ../../lib/curlx/version_win32.c
 
@@ -43,11 +41,9 @@ CURLX_HDRS = \
   ../../lib/curlx/curlx.h \
   ../../lib/curl_ctype.h \
   ../../lib/curlx/nonblock.h \
-  ../../lib/strcase.h \
   ../../lib/curlx/warnless.h \
   ../../lib/curlx/timediff.h \
   ../../lib/curlx/timeval.h \
-  ../../lib/strcase.h \
   ../../lib/curlx/multibyte.h \
   ../../lib/curlx/version_win32.h
 
index 8e26168a2ddd9f929d4e3e364e661a87e0441fe1..fd99458922740ab0e3e7b0c8ff9e66b462ff5ce8 100644 (file)
@@ -425,7 +425,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
     if(got_exit_signal)
       return 1; /* done */
 
-    if((req->cl == 0) && curl_strnequal("Content-Length:", line, 15)) {
+    if((req->cl == 0) && !CURL_STRNICMP("Content-Length:", line, 15)) {
       /* If we don't ignore content-length, we read it and we read the whole
          request including the body before we return. If we've been told to
          ignore the content-length, we will return as soon as all headers
@@ -445,8 +445,8 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
         logmsg("... but will abort after %zu bytes", req->cl);
       break;
     }
-    else if(curl_strnequal("Transfer-Encoding: chunked", line,
-                            strlen("Transfer-Encoding: chunked"))) {
+    else if(!CURL_STRNICMP("Transfer-Encoding: chunked", line,
+                           strlen("Transfer-Encoding: chunked"))) {
       /* chunked data coming in */
       chunked = TRUE;
     }
index c33b99c044f5efb5e020cc8ec1c00d829884d744..67a01cfdc083065f1e7d892e964c8355ecd4bb1c 100644 (file)
@@ -573,7 +573,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
     if(got_exit_signal)
       return 1; /* done */
 
-    if((req->cl == 0) && curl_strnequal("Content-Length:", line, 15)) {
+    if((req->cl == 0) && !CURL_STRNICMP("Content-Length:", line, 15)) {
       /* If we don't ignore content-length, we read it and we read the whole
          request including the body before we return. If we've been told to
          ignore the content-length, we will return as soon as all headers
@@ -595,14 +595,13 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
       if(req->skip)
         logmsg("... but will abort after %zu bytes", req->cl);
     }
-    else if(curl_strnequal("Transfer-Encoding: chunked", line,
-                            strlen("Transfer-Encoding: chunked"))) {
+    else if(!CURL_STRNICMP("Transfer-Encoding: chunked", line,
+                           strlen("Transfer-Encoding: chunked"))) {
       /* chunked data coming in */
       chunked = TRUE;
     }
-    else if(req->noexpect &&
-            curl_strnequal("Expect: 100-continue", line,
-                            strlen("Expect: 100-continue"))) {
+    else if(req->noexpect && !CURL_STRNICMP("Expect: 100-continue", line,
+                                            strlen("Expect: 100-continue"))) {
       if(req->cl)
         req->cl = 0;
       req->skipall = TRUE;
index 3420006f7eed17813df413a751ad78aa5b525404..da84e4f5dbb386e018543e5c58f5d6001fd2b2b7 100644 (file)
 #  endif
 #endif
 
+#ifdef _WIN32
+#  define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n)
+#elif defined(HAVE_STRCASECMP)
+#  ifdef HAVE_STRINGS_H
+#    include <strings.h>
+#  endif
+#  define CURL_STRNICMP(p1, p2, n) strncasecmp(p1, p2, n)
+#elif defined(HAVE_STRCMPI)
+#  define CURL_STRNICMP(p1, p2, n) strncmpi(p1, p2, n)
+#elif defined(HAVE_STRICMP)
+#  define CURL_STRNICMP(p1, p2, n) strnicmp(p1, p2, n)
+#else
+#  error "missing case insensitive comparison function"
+#endif
+
 enum {
   DOCNUMBER_NOTHING    = -7,
   DOCNUMBER_QUIT       = -6,