gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34757 - in libmicrohttpd/src: include microhttpd


From: gnunet
Subject: [GNUnet-SVN] r34757 - in libmicrohttpd/src: include microhttpd
Date: Mon, 22 Dec 2014 20:42:01 +0100

Author: Karlson2k
Date: 2014-12-22 20:42:00 +0100 (Mon, 22 Dec 2014)
New Revision: 34757

Modified:
   libmicrohttpd/src/include/platform_interface.h
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/digestauth.c
   libmicrohttpd/src/microhttpd/postprocessor.c
Log:
Replace strcasecmp/strncasecmp with platform-independent macros

Modified: libmicrohttpd/src/include/platform_interface.h
===================================================================
--- libmicrohttpd/src/include/platform_interface.h      2014-12-22 19:41:51 UTC 
(rev 34756)
+++ libmicrohttpd/src/include/platform_interface.h      2014-12-22 19:42:00 UTC 
(rev 34757)
@@ -31,6 +31,49 @@
 #include "w32functions.h"
 #endif
 
+/* ***************************** 
+     General function mapping 
+   *****************************/
+#if !defined(_WIN32) || defined(__CYGWIN__)
+/**
+ * Check two strings case-insensitive equality
+ * @param a first string to check
+ * @param b second string to check
+ * @return boolean true if strings are equal, boolean false if strings are 
unequal
+ */
+#define MHD_str_equal_caseless_(a,b) (0==strcasecmp((a),(b)))
+#else
+/**
+ * Check two strings case-insensitive equality
+ * @param a first string to check
+ * @param b second string to check
+ * @return boolean true if strings are equal, boolean false if strings are 
unequal
+ */
+#define MHD_str_equal_caseless_(a,b) (0==_stricmp((a),(b)))
+#endif
+
+#if !defined(_WIN32) || defined(__CYGWIN__)
+/**
+ * Check not more than n chars in two strings case-insensitive equality
+ * @param a first string to check
+ * @param b second string to check
+ * @param n maximum number of chars to check
+ * @return boolean true if strings are equal, boolean false if strings are 
unequal
+ */
+#define MHD_str_equal_caseless_n_(a,b,n) (0==strncasecmp((a),(b),(n)))
+#else
+/**
+ * Check not more than n chars in two strings case-insensitive equality
+ * @param a first string to check
+ * @param b second string to check
+ * @param n maximum number of chars to check
+ * @return boolean true if strings are equal, boolean false if strings are 
unequal
+ */
+#define MHD_str_equal_caseless_n_(a,b,n) (0==_strnicmp((a),(b),(n)))
+#endif
+
+
+
 /* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket FDs (W32) 
*/
 #if !defined(_WIN32) || defined(__CYGWIN__)
 #define MHD_socket_close_(fd) close((fd))

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2014-12-22 19:41:51 UTC (rev 
34756)
+++ libmicrohttpd/src/microhttpd/connection.c   2014-12-22 19:42:00 UTC (rev 
34757)
@@ -226,7 +226,7 @@
        ( (key == pos->header) ||
          ( (NULL != pos->header) &&
            (NULL != key) &&
-           (0 == strcasecmp (key, pos->header))) ))
+        (MHD_str_equal_caseless_(key, pos->header)))))
       return pos->value;
   return NULL;
 }
@@ -246,12 +246,12 @@
 
   return ( (NULL == connection->response) &&
           (NULL != connection->version) &&
-          (0 == strcasecmp (connection->version,
+       (MHD_str_equal_caseless_(connection->version,
                             MHD_HTTP_VERSION_1_1)) &&
           (NULL != (expect = MHD_lookup_connection_value (connection,
                                                           MHD_HEADER_KIND,
                                                           
MHD_HTTP_HEADER_EXPECT))) &&
-          (0 == strcasecmp (expect, "100-continue")) &&
+          (MHD_str_equal_caseless_(expect, "100-continue")) &&
           (connection->continue_message_write_offset <
            strlen (HTTP_100_CONTINUE)) );
 }
@@ -519,22 +519,22 @@
   end = MHD_lookup_connection_value (connection,
                                      MHD_HEADER_KIND,
                                      MHD_HTTP_HEADER_CONNECTION);
-  if (0 == strcasecmp (connection->version,
+  if (MHD_str_equal_caseless_(connection->version,
                        MHD_HTTP_VERSION_1_1))
   {
     if (NULL == end)
       return MHD_YES;
-    if ( (0 == strcasecmp (end, "close")) ||
-         (0 == strcasecmp (end, "upgrade")) )
+    if ( (MHD_str_equal_caseless_ (end, "close")) ||
+         (MHD_str_equal_caseless_ (end, "upgrade")) )
       return MHD_NO;
    return MHD_YES;
   }
-  if (0 == strcasecmp (connection->version,
+  if (MHD_str_equal_caseless_(connection->version,
                        MHD_HTTP_VERSION_1_0))
   {
     if (NULL == end)
       return MHD_NO;
-    if (0 == strcasecmp (end, "Keep-Alive"))
+    if (MHD_str_equal_caseless_(end, "Keep-Alive"))
       return MHD_YES;
     return MHD_NO;
   }
@@ -678,7 +678,7 @@
                "%s %u %s\r\n",
               (0 != (connection->responseCode & MHD_ICY_FLAG))
               ? "ICY"
-              : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0,
+              : ( (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_0,
                                     connection->version))
                   ? MHD_HTTP_VERSION_1_0
                   : MHD_HTTP_VERSION_1_1),
@@ -717,16 +717,16 @@
                                                     
MHD_HTTP_HEADER_CONNECTION);
       response_has_keepalive = response_has_close;
       if ( (NULL != response_has_close) &&
-           (0 != strcasecmp (response_has_close, "close")) )
+           (!MHD_str_equal_caseless_ (response_has_close, "close")) )
         response_has_close = NULL;
       if ( (NULL != response_has_keepalive) &&
-           (0 != strcasecmp (response_has_keepalive, "Keep-Alive")) )
+           (!MHD_str_equal_caseless_ (response_has_keepalive, "Keep-Alive")) )
         response_has_keepalive = NULL;
       client_requested_close = MHD_lookup_connection_value (connection,
                                                             MHD_HEADER_KIND,
                                                             
MHD_HTTP_HEADER_CONNECTION);
       if ( (NULL != client_requested_close) &&
-           (0 != strcasecmp (client_requested_close, "close")) )
+           (!MHD_str_equal_caseless_ (client_requested_close, "close")) )
         client_requested_close = NULL;
 
       /* now analyze chunked encoding situation */
@@ -750,7 +750,7 @@
                   must_add_chunked_encoding = MHD_YES;
                   connection->have_chunked_upload = MHD_YES;
                 }
-              else if (0 == strcasecmp (have_encoding, "identity"))
+              else if (MHD_str_equal_caseless_(have_encoding, "identity"))
                 {
                   /* application forced identity encoding, can't do 'chunked' 
*/
                   must_add_close = MHD_YES;
@@ -782,7 +782,7 @@
       if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) &&
            (NULL == have_content_length) &&
            ( (NULL == connection->method) ||
-             (0 != strcasecmp (connection->method,
+             (!MHD_str_equal_caseless_ (connection->method,
                                MHD_HTTP_METHOD_CONNECT)) ) )
         {
           /*
@@ -836,7 +836,7 @@
     if ( (pos->kind == kind) &&
          (! ( (MHD_YES == must_add_close) &&
               (pos->value == response_has_keepalive) &&
-              (0 == strcasecmp (pos->header,
+              (MHD_str_equal_caseless_(pos->header,
                                 MHD_HTTP_HEADER_CONNECTION) ) ) ) )
       size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, 
linefeeds */
   /* produce data */
@@ -889,7 +889,7 @@
     if ( (pos->kind == kind) &&
          (! ( (pos->value == response_has_keepalive) &&
               (MHD_YES == must_add_close) &&
-              (0 == strcasecmp (pos->header,
+              (MHD_str_equal_caseless_(pos->header,
                                 MHD_HTTP_HEADER_CONNECTION) ) ) ) )
       off += sprintf (&data[off],
                      "%s: %s\r\n",
@@ -1916,7 +1916,7 @@
   parse_cookie_header (connection);
   if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) &&
        (NULL != connection->version) &&
-       (0 == strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)) &&
+       (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1, connection->version)) &&
        (NULL ==
         MHD_lookup_connection_value (connection,
                                      MHD_HEADER_KIND,
@@ -1947,7 +1947,7 @@
   if (NULL != enc)
     {
       connection->remaining_upload_size = MHD_SIZE_UNKNOWN;
-      if (0 == strcasecmp (enc, "chunked"))
+      if (MHD_str_equal_caseless_(enc, "chunked"))
         connection->have_chunked_upload = MHD_YES;
     }
   else
@@ -2390,9 +2390,9 @@
               break;
             }
           if ( (NULL != connection->response) &&
-              ( (0 == strcasecmp (connection->method,
+              ( (MHD_str_equal_caseless_ (connection->method,
                                   MHD_HTTP_METHOD_POST)) ||
-                (0 == strcasecmp (connection->method,
+                (MHD_str_equal_caseless_ (connection->method,
                                   MHD_HTTP_METHOD_PUT))) )
             {
               /* we refused (no upload allowed!) */
@@ -2607,7 +2607,7 @@
                                          MHD_HTTP_HEADER_CONNECTION);
           if ( (MHD_YES == connection->read_closed) ||
                (client_close) ||
-               ((NULL != end) && (0 == strcasecmp (end, "close"))) )
+               ((NULL != end) && (MHD_str_equal_caseless_ (end, "close"))) )
             {
               connection->read_closed = MHD_YES;
               connection->read_buffer_offset = 0;
@@ -2918,7 +2918,7 @@
   connection->response = response;
   connection->responseCode = status_code;
   if ( (NULL != connection->method) &&
-       (0 == strcasecmp (connection->method, MHD_HTTP_METHOD_HEAD)) )
+       (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) )
     {
       /* if this is a "HEAD" request, pretend that we
          have already sent the full message body */
@@ -2926,9 +2926,9 @@
     }
   if ( (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) &&
        (NULL != connection->method) &&
-       ( (0 == strcasecmp (connection->method,
+       ( (MHD_str_equal_caseless_ (connection->method,
                           MHD_HTTP_METHOD_POST)) ||
-        (0 == strcasecmp (connection->method,
+        (MHD_str_equal_caseless_ (connection->method,
                           MHD_HTTP_METHOD_PUT))) )
     {
       /* response was queued "early", refuse to read body / footers or

Modified: libmicrohttpd/src/microhttpd/digestauth.c
===================================================================
--- libmicrohttpd/src/microhttpd/digestauth.c   2014-12-22 19:41:51 UTC (rev 
34756)
+++ libmicrohttpd/src/microhttpd/digestauth.c   2014-12-22 19:42:00 UTC (rev 
34757)
@@ -114,7 +114,7 @@
   MD5Update (&md5, ":", 1);
   MD5Update (&md5, password, strlen (password));
   MD5Final (ha1, &md5);
-  if (0 == strcasecmp (alg, "md5-sess"))
+  if (MHD_str_equal_caseless_(alg, "md5-sess"))
     {
       MD5Init (&md5);
       MD5Update (&md5, ha1, sizeof (ha1));
@@ -246,7 +246,7 @@
            return 0; /* end quote not found */
          qn = q2 + 1;
        }
-      if ( (0 == strncasecmp (ptr,
+      if ((MHD_str_equal_caseless_n_(ptr,
                              key,
                              keylen)) &&
           (eq == &ptr[keylen]) )

Modified: libmicrohttpd/src/microhttpd/postprocessor.c
===================================================================
--- libmicrohttpd/src/microhttpd/postprocessor.c        2014-12-22 19:41:51 UTC 
(rev 34756)
+++ libmicrohttpd/src/microhttpd/postprocessor.c        2014-12-22 19:42:00 UTC 
(rev 34757)
@@ -286,11 +286,10 @@
   if (encoding == NULL)
     return NULL;
   boundary = NULL;
-  if (0 != strncasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding,
+  if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, 
encoding,
                         strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
     {
-      if (0 !=
-          strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding,
+      if (!MHD_str_equal_caseless_n_ 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding,
                        strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
         return NULL;
       boundary =
@@ -503,7 +502,7 @@
     return MHD_NO;
   while (*line != 0)
     {
-      if (0 == strncasecmp (prefix, line, strlen (prefix)))
+      if (MHD_str_equal_caseless_n_ (prefix, line, strlen (prefix)))
         {
           *suffix = strdup (&line[strlen (prefix)]);
           return MHD_YES;
@@ -663,7 +662,7 @@
   if (buf[newline] == '\r')
     pp->skip_rn = RN_OptN;
   buf[newline] = '\0';
-  if (0 == strncasecmp ("Content-disposition: ",
+  if (MHD_str_equal_caseless_n_ ("Content-disposition: ",
                         buf, strlen ("Content-disposition: ")))
     {
       try_get_value (&buf[strlen ("Content-disposition: ")],
@@ -969,7 +968,7 @@
           break;
         case PP_PerformCheckMultipart:
           if ((pp->content_type != NULL) &&
-              (0 == strncasecmp (pp->content_type,
+              (MHD_str_equal_caseless_n_ (pp->content_type,
                                  "multipart/mixed",
                                  strlen ("multipart/mixed"))))
             {
@@ -1137,11 +1136,10 @@
     return MHD_YES;
   if (NULL == pp)
     return MHD_NO;
-  if (0 == strncasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, pp->encoding,
+  if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, 
pp->encoding,
                          strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
     return post_process_urlencoded (pp, post_data, post_data_len);
-  if (0 ==
-      strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, pp->encoding,
+  if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, 
pp->encoding,
                    strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
     return post_process_multipart (pp, post_data, post_data_len);
   /* this should never be reached */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]