]> granicus.if.org Git - curl/commitdiff
tests/util: get a private strncasecompare clone
authorDaniel Stenberg <daniel@haxx.se>
Mon, 31 Oct 2016 22:49:54 +0000 (23:49 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 31 Oct 2016 22:49:54 +0000 (23:49 +0100)
... since the curlx_* code no longer provides one and we don't link
libcurl to these test servers.

tests/server/Makefile.inc
tests/server/rtspd.c
tests/server/sws.c
tests/server/util.c
tests/server/util.h

index 3490e7872e855c6c382a13d16b636d2e20e6418d..c3ea664b690f3344351e3c5313b5368bed170fbd 100644 (file)
@@ -3,7 +3,6 @@ noinst_PROGRAMS = getpart resolve rtspd sockfilt sws tftpd fake_ntlm
 CURLX_SRCS = \
  ../../lib/mprintf.c \
  ../../lib/nonblock.c \
- ../../lib/strcase.c \
  ../../lib/strtoofft.c \
  ../../lib/timeval.c \
  ../../lib/warnless.c
@@ -11,7 +10,6 @@ CURLX_SRCS = \
 CURLX_HDRS = \
  ../../lib/curlx.h \
  ../../lib/nonblock.h \
- ../../lib/strcase.h \
  ../../lib/strtoofft.h \
  ../../lib/timeval.h \
  ../../lib/warnless.h
index 96310cf89af8e9f29e1317aa633ccab69ad1d6f5..db95917a93441c49bc991436ffd3d04fb1d1b054 100644 (file)
@@ -590,7 +590,7 @@ static int ProcessRequest(struct httprequest *req)
     if(got_exit_signal)
       return 1; /* done */
 
-    if((req->cl==0) && curlx_strncasecompare("Content-Length:", line, 15)) {
+    if((req->cl==0) && strncasecompare("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
@@ -616,8 +616,8 @@ static int ProcessRequest(struct httprequest *req)
         logmsg("... but will abort after %zu bytes", req->cl);
       break;
     }
-    else if(curlx_strncasecompare("Transfer-Encoding: chunked", line,
-                                  strlen("Transfer-Encoding: chunked"))) {
+    else if(strncasecompare("Transfer-Encoding: chunked", line,
+                            strlen("Transfer-Encoding: chunked"))) {
       /* chunked data coming in */
       chunked = TRUE;
     }
index 801a7b83f6eb358b789309db33258c829e292c06..c94e23453d97263e6708de49cf8c35452604b4b1 100644 (file)
@@ -697,7 +697,7 @@ static int ProcessRequest(struct httprequest *req)
     if(got_exit_signal)
       return 1; /* done */
 
-    if((req->cl==0) && curlx_strncasecompare("Content-Length:", line, 15)) {
+    if((req->cl==0) && strncasecompare("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
@@ -723,8 +723,8 @@ static int ProcessRequest(struct httprequest *req)
         logmsg("... but will abort after %zu bytes", req->cl);
       break;
     }
-    else if(curlx_strncasecompare("Transfer-Encoding: chunked", line,
-                                  strlen("Transfer-Encoding: chunked"))) {
+    else if(strncasecompare("Transfer-Encoding: chunked", line,
+                            strlen("Transfer-Encoding: chunked"))) {
       /* chunked data coming in */
       chunked = TRUE;
     }
index d99336397fe91b8a9d243191bdfd307841568732..e6547078609b10cdbce051c7c879ef866efb0d70 100644 (file)
@@ -305,3 +305,87 @@ void clear_advisor_read_lock(const char *filename)
     logmsg("Error removing lock file %s error: %d %s",
            filename, error, strerror(error));
 }
+
+
+/* Portable, consistent toupper (remember EBCDIC). Do not use toupper() because
+   its behavior is altered by the current locale. */
+static char raw_toupper(char in)
+{
+#if !defined(CURL_DOES_CONVERSIONS)
+  if(in >= 'a' && in <= 'z')
+    return (char)('A' + in - 'a');
+#else
+  switch (in) {
+  case 'a':
+    return 'A';
+  case 'b':
+    return 'B';
+  case 'c':
+    return 'C';
+  case 'd':
+    return 'D';
+  case 'e':
+    return 'E';
+  case 'f':
+    return 'F';
+  case 'g':
+    return 'G';
+  case 'h':
+    return 'H';
+  case 'i':
+    return 'I';
+  case 'j':
+    return 'J';
+  case 'k':
+    return 'K';
+  case 'l':
+    return 'L';
+  case 'm':
+    return 'M';
+  case 'n':
+    return 'N';
+  case 'o':
+    return 'O';
+  case 'p':
+    return 'P';
+  case 'q':
+    return 'Q';
+  case 'r':
+    return 'R';
+  case 's':
+    return 'S';
+  case 't':
+    return 'T';
+  case 'u':
+    return 'U';
+  case 'v':
+    return 'V';
+  case 'w':
+    return 'W';
+  case 'x':
+    return 'X';
+  case 'y':
+    return 'Y';
+  case 'z':
+    return 'Z';
+  }
+#endif
+
+  return in;
+}
+
+int strncasecompare(const char *first, const char *second, size_t max)
+{
+  while(*first && *second && max) {
+    if(raw_toupper(*first) != raw_toupper(*second)) {
+      break;
+    }
+    max--;
+    first++;
+    second++;
+  }
+  if(0 == max)
+    return 1; /* they are equal this far */
+
+  return raw_toupper(*first) == raw_toupper(*second);
+}
index 2a19a613bae627404ecd40d3af5103b3ef0b57d5..c90fcdf32ade97b63f853c23d03d008e4ad71b89 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -63,4 +63,6 @@ void set_advisor_read_lock(const char *filename);
 
 void clear_advisor_read_lock(const char *filename);
 
+int strncasecompare(const char *first, const char *second, size_t max);
+
 #endif  /* HEADER_CURL_SERVER_UTIL_H */