aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2014-12-22 19:42:00 +0000
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2014-12-22 19:42:00 +0000
commit2a2a389a340561ff886d8349bb2802c99892c92d (patch)
treee3be8994c64211c9ebd5de21fc5ffcfcf26f7872
parentba88f0d73373d4a6dedb23b07415a4dac976fbf8 (diff)
downloadlibmicrohttpd-2a2a389a340561ff886d8349bb2802c99892c92d.tar.gz
libmicrohttpd-2a2a389a340561ff886d8349bb2802c99892c92d.zip
Replace strcasecmp/strncasecmp with platform-independent macros
-rw-r--r--src/include/platform_interface.h43
-rw-r--r--src/microhttpd/connection.c48
-rw-r--r--src/microhttpd/digestauth.c4
-rw-r--r--src/microhttpd/postprocessor.c16
4 files changed, 76 insertions, 35 deletions
diff --git a/src/include/platform_interface.h b/src/include/platform_interface.h
index f7373e7d..64b810c5 100644
--- a/src/include/platform_interface.h
+++ b/src/include/platform_interface.h
@@ -31,6 +31,49 @@
31#include "w32functions.h" 31#include "w32functions.h"
32#endif 32#endif
33 33
34/* *****************************
35 General function mapping
36 *****************************/
37#if !defined(_WIN32) || defined(__CYGWIN__)
38/**
39 * Check two strings case-insensitive equality
40 * @param a first string to check
41 * @param b second string to check
42 * @return boolean true if strings are equal, boolean false if strings are unequal
43 */
44#define MHD_str_equal_caseless_(a,b) (0==strcasecmp((a),(b)))
45#else
46/**
47 * Check two strings case-insensitive equality
48 * @param a first string to check
49 * @param b second string to check
50 * @return boolean true if strings are equal, boolean false if strings are unequal
51 */
52#define MHD_str_equal_caseless_(a,b) (0==_stricmp((a),(b)))
53#endif
54
55#if !defined(_WIN32) || defined(__CYGWIN__)
56/**
57 * Check not more than n chars in two strings case-insensitive equality
58 * @param a first string to check
59 * @param b second string to check
60 * @param n maximum number of chars to check
61 * @return boolean true if strings are equal, boolean false if strings are unequal
62 */
63#define MHD_str_equal_caseless_n_(a,b,n) (0==strncasecmp((a),(b),(n)))
64#else
65/**
66 * Check not more than n chars in two strings case-insensitive equality
67 * @param a first string to check
68 * @param b second string to check
69 * @param n maximum number of chars to check
70 * @return boolean true if strings are equal, boolean false if strings are unequal
71 */
72#define MHD_str_equal_caseless_n_(a,b,n) (0==_strnicmp((a),(b),(n)))
73#endif
74
75
76
34/* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket FDs (W32) */ 77/* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket FDs (W32) */
35#if !defined(_WIN32) || defined(__CYGWIN__) 78#if !defined(_WIN32) || defined(__CYGWIN__)
36#define MHD_socket_close_(fd) close((fd)) 79#define MHD_socket_close_(fd) close((fd))
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index ae90e8a4..8464e909 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -226,7 +226,7 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
226 ( (key == pos->header) || 226 ( (key == pos->header) ||
227 ( (NULL != pos->header) && 227 ( (NULL != pos->header) &&
228 (NULL != key) && 228 (NULL != key) &&
229 (0 == strcasecmp (key, pos->header))) )) 229 (MHD_str_equal_caseless_(key, pos->header)))))
230 return pos->value; 230 return pos->value;
231 return NULL; 231 return NULL;
232} 232}
@@ -246,12 +246,12 @@ need_100_continue (struct MHD_Connection *connection)
246 246
247 return ( (NULL == connection->response) && 247 return ( (NULL == connection->response) &&
248 (NULL != connection->version) && 248 (NULL != connection->version) &&
249 (0 == strcasecmp (connection->version, 249 (MHD_str_equal_caseless_(connection->version,
250 MHD_HTTP_VERSION_1_1)) && 250 MHD_HTTP_VERSION_1_1)) &&
251 (NULL != (expect = MHD_lookup_connection_value (connection, 251 (NULL != (expect = MHD_lookup_connection_value (connection,
252 MHD_HEADER_KIND, 252 MHD_HEADER_KIND,
253 MHD_HTTP_HEADER_EXPECT))) && 253 MHD_HTTP_HEADER_EXPECT))) &&
254 (0 == strcasecmp (expect, "100-continue")) && 254 (MHD_str_equal_caseless_(expect, "100-continue")) &&
255 (connection->continue_message_write_offset < 255 (connection->continue_message_write_offset <
256 strlen (HTTP_100_CONTINUE)) ); 256 strlen (HTTP_100_CONTINUE)) );
257} 257}
@@ -519,22 +519,22 @@ keepalive_possible (struct MHD_Connection *connection)
519 end = MHD_lookup_connection_value (connection, 519 end = MHD_lookup_connection_value (connection,
520 MHD_HEADER_KIND, 520 MHD_HEADER_KIND,
521 MHD_HTTP_HEADER_CONNECTION); 521 MHD_HTTP_HEADER_CONNECTION);
522 if (0 == strcasecmp (connection->version, 522 if (MHD_str_equal_caseless_(connection->version,
523 MHD_HTTP_VERSION_1_1)) 523 MHD_HTTP_VERSION_1_1))
524 { 524 {
525 if (NULL == end) 525 if (NULL == end)
526 return MHD_YES; 526 return MHD_YES;
527 if ( (0 == strcasecmp (end, "close")) || 527 if ( (MHD_str_equal_caseless_ (end, "close")) ||
528 (0 == strcasecmp (end, "upgrade")) ) 528 (MHD_str_equal_caseless_ (end, "upgrade")) )
529 return MHD_NO; 529 return MHD_NO;
530 return MHD_YES; 530 return MHD_YES;
531 } 531 }
532 if (0 == strcasecmp (connection->version, 532 if (MHD_str_equal_caseless_(connection->version,
533 MHD_HTTP_VERSION_1_0)) 533 MHD_HTTP_VERSION_1_0))
534 { 534 {
535 if (NULL == end) 535 if (NULL == end)
536 return MHD_NO; 536 return MHD_NO;
537 if (0 == strcasecmp (end, "Keep-Alive")) 537 if (MHD_str_equal_caseless_(end, "Keep-Alive"))
538 return MHD_YES; 538 return MHD_YES;
539 return MHD_NO; 539 return MHD_NO;
540 } 540 }
@@ -678,7 +678,7 @@ build_header_response (struct MHD_Connection *connection)
678 "%s %u %s\r\n", 678 "%s %u %s\r\n",
679 (0 != (connection->responseCode & MHD_ICY_FLAG)) 679 (0 != (connection->responseCode & MHD_ICY_FLAG))
680 ? "ICY" 680 ? "ICY"
681 : ( (0 == strcasecmp (MHD_HTTP_VERSION_1_0, 681 : ( (MHD_str_equal_caseless_ (MHD_HTTP_VERSION_1_0,
682 connection->version)) 682 connection->version))
683 ? MHD_HTTP_VERSION_1_0 683 ? MHD_HTTP_VERSION_1_0
684 : MHD_HTTP_VERSION_1_1), 684 : MHD_HTTP_VERSION_1_1),
@@ -717,16 +717,16 @@ build_header_response (struct MHD_Connection *connection)
717 MHD_HTTP_HEADER_CONNECTION); 717 MHD_HTTP_HEADER_CONNECTION);
718 response_has_keepalive = response_has_close; 718 response_has_keepalive = response_has_close;
719 if ( (NULL != response_has_close) && 719 if ( (NULL != response_has_close) &&
720 (0 != strcasecmp (response_has_close, "close")) ) 720 (!MHD_str_equal_caseless_ (response_has_close, "close")) )
721 response_has_close = NULL; 721 response_has_close = NULL;
722 if ( (NULL != response_has_keepalive) && 722 if ( (NULL != response_has_keepalive) &&
723 (0 != strcasecmp (response_has_keepalive, "Keep-Alive")) ) 723 (!MHD_str_equal_caseless_ (response_has_keepalive, "Keep-Alive")) )
724 response_has_keepalive = NULL; 724 response_has_keepalive = NULL;
725 client_requested_close = MHD_lookup_connection_value (connection, 725 client_requested_close = MHD_lookup_connection_value (connection,
726 MHD_HEADER_KIND, 726 MHD_HEADER_KIND,
727 MHD_HTTP_HEADER_CONNECTION); 727 MHD_HTTP_HEADER_CONNECTION);
728 if ( (NULL != client_requested_close) && 728 if ( (NULL != client_requested_close) &&
729 (0 != strcasecmp (client_requested_close, "close")) ) 729 (!MHD_str_equal_caseless_ (client_requested_close, "close")) )
730 client_requested_close = NULL; 730 client_requested_close = NULL;
731 731
732 /* now analyze chunked encoding situation */ 732 /* now analyze chunked encoding situation */
@@ -750,7 +750,7 @@ build_header_response (struct MHD_Connection *connection)
750 must_add_chunked_encoding = MHD_YES; 750 must_add_chunked_encoding = MHD_YES;
751 connection->have_chunked_upload = MHD_YES; 751 connection->have_chunked_upload = MHD_YES;
752 } 752 }
753 else if (0 == strcasecmp (have_encoding, "identity")) 753 else if (MHD_str_equal_caseless_(have_encoding, "identity"))
754 { 754 {
755 /* application forced identity encoding, can't do 'chunked' */ 755 /* application forced identity encoding, can't do 'chunked' */
756 must_add_close = MHD_YES; 756 must_add_close = MHD_YES;
@@ -782,7 +782,7 @@ build_header_response (struct MHD_Connection *connection)
782 if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) && 782 if ( (MHD_SIZE_UNKNOWN != connection->response->total_size) &&
783 (NULL == have_content_length) && 783 (NULL == have_content_length) &&
784 ( (NULL == connection->method) || 784 ( (NULL == connection->method) ||
785 (0 != strcasecmp (connection->method, 785 (!MHD_str_equal_caseless_ (connection->method,
786 MHD_HTTP_METHOD_CONNECT)) ) ) 786 MHD_HTTP_METHOD_CONNECT)) ) )
787 { 787 {
788 /* 788 /*
@@ -836,7 +836,7 @@ build_header_response (struct MHD_Connection *connection)
836 if ( (pos->kind == kind) && 836 if ( (pos->kind == kind) &&
837 (! ( (MHD_YES == must_add_close) && 837 (! ( (MHD_YES == must_add_close) &&
838 (pos->value == response_has_keepalive) && 838 (pos->value == response_has_keepalive) &&
839 (0 == strcasecmp (pos->header, 839 (MHD_str_equal_caseless_(pos->header,
840 MHD_HTTP_HEADER_CONNECTION) ) ) ) ) 840 MHD_HTTP_HEADER_CONNECTION) ) ) ) )
841 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */ 841 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */
842 /* produce data */ 842 /* produce data */
@@ -889,7 +889,7 @@ build_header_response (struct MHD_Connection *connection)
889 if ( (pos->kind == kind) && 889 if ( (pos->kind == kind) &&
890 (! ( (pos->value == response_has_keepalive) && 890 (! ( (pos->value == response_has_keepalive) &&
891 (MHD_YES == must_add_close) && 891 (MHD_YES == must_add_close) &&
892 (0 == strcasecmp (pos->header, 892 (MHD_str_equal_caseless_(pos->header,
893 MHD_HTTP_HEADER_CONNECTION) ) ) ) ) 893 MHD_HTTP_HEADER_CONNECTION) ) ) ) )
894 off += sprintf (&data[off], 894 off += sprintf (&data[off],
895 "%s: %s\r\n", 895 "%s: %s\r\n",
@@ -1916,7 +1916,7 @@ parse_connection_headers (struct MHD_Connection *connection)
1916 parse_cookie_header (connection); 1916 parse_cookie_header (connection);
1917 if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) && 1917 if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) &&
1918 (NULL != connection->version) && 1918 (NULL != connection->version) &&
1919 (0 == strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)) && 1919 (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1, connection->version)) &&
1920 (NULL == 1920 (NULL ==
1921 MHD_lookup_connection_value (connection, 1921 MHD_lookup_connection_value (connection,
1922 MHD_HEADER_KIND, 1922 MHD_HEADER_KIND,
@@ -1947,7 +1947,7 @@ parse_connection_headers (struct MHD_Connection *connection)
1947 if (NULL != enc) 1947 if (NULL != enc)
1948 { 1948 {
1949 connection->remaining_upload_size = MHD_SIZE_UNKNOWN; 1949 connection->remaining_upload_size = MHD_SIZE_UNKNOWN;
1950 if (0 == strcasecmp (enc, "chunked")) 1950 if (MHD_str_equal_caseless_(enc, "chunked"))
1951 connection->have_chunked_upload = MHD_YES; 1951 connection->have_chunked_upload = MHD_YES;
1952 } 1952 }
1953 else 1953 else
@@ -2390,9 +2390,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2390 break; 2390 break;
2391 } 2391 }
2392 if ( (NULL != connection->response) && 2392 if ( (NULL != connection->response) &&
2393 ( (0 == strcasecmp (connection->method, 2393 ( (MHD_str_equal_caseless_ (connection->method,
2394 MHD_HTTP_METHOD_POST)) || 2394 MHD_HTTP_METHOD_POST)) ||
2395 (0 == strcasecmp (connection->method, 2395 (MHD_str_equal_caseless_ (connection->method,
2396 MHD_HTTP_METHOD_PUT))) ) 2396 MHD_HTTP_METHOD_PUT))) )
2397 { 2397 {
2398 /* we refused (no upload allowed!) */ 2398 /* we refused (no upload allowed!) */
@@ -2607,7 +2607,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2607 MHD_HTTP_HEADER_CONNECTION); 2607 MHD_HTTP_HEADER_CONNECTION);
2608 if ( (MHD_YES == connection->read_closed) || 2608 if ( (MHD_YES == connection->read_closed) ||
2609 (client_close) || 2609 (client_close) ||
2610 ((NULL != end) && (0 == strcasecmp (end, "close"))) ) 2610 ((NULL != end) && (MHD_str_equal_caseless_ (end, "close"))) )
2611 { 2611 {
2612 connection->read_closed = MHD_YES; 2612 connection->read_closed = MHD_YES;
2613 connection->read_buffer_offset = 0; 2613 connection->read_buffer_offset = 0;
@@ -2918,7 +2918,7 @@ MHD_queue_response (struct MHD_Connection *connection,
2918 connection->response = response; 2918 connection->response = response;
2919 connection->responseCode = status_code; 2919 connection->responseCode = status_code;
2920 if ( (NULL != connection->method) && 2920 if ( (NULL != connection->method) &&
2921 (0 == strcasecmp (connection->method, MHD_HTTP_METHOD_HEAD)) ) 2921 (MHD_str_equal_caseless_ (connection->method, MHD_HTTP_METHOD_HEAD)) )
2922 { 2922 {
2923 /* if this is a "HEAD" request, pretend that we 2923 /* if this is a "HEAD" request, pretend that we
2924 have already sent the full message body */ 2924 have already sent the full message body */
@@ -2926,9 +2926,9 @@ MHD_queue_response (struct MHD_Connection *connection,
2926 } 2926 }
2927 if ( (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) && 2927 if ( (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) &&
2928 (NULL != connection->method) && 2928 (NULL != connection->method) &&
2929 ( (0 == strcasecmp (connection->method, 2929 ( (MHD_str_equal_caseless_ (connection->method,
2930 MHD_HTTP_METHOD_POST)) || 2930 MHD_HTTP_METHOD_POST)) ||
2931 (0 == strcasecmp (connection->method, 2931 (MHD_str_equal_caseless_ (connection->method,
2932 MHD_HTTP_METHOD_PUT))) ) 2932 MHD_HTTP_METHOD_PUT))) )
2933 { 2933 {
2934 /* response was queued "early", refuse to read body / footers or 2934 /* response was queued "early", refuse to read body / footers or
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 0816b3ff..04676f53 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -114,7 +114,7 @@ digest_calc_ha1 (const char *alg,
114 MD5Update (&md5, ":", 1); 114 MD5Update (&md5, ":", 1);
115 MD5Update (&md5, password, strlen (password)); 115 MD5Update (&md5, password, strlen (password));
116 MD5Final (ha1, &md5); 116 MD5Final (ha1, &md5);
117 if (0 == strcasecmp (alg, "md5-sess")) 117 if (MHD_str_equal_caseless_(alg, "md5-sess"))
118 { 118 {
119 MD5Init (&md5); 119 MD5Init (&md5);
120 MD5Update (&md5, ha1, sizeof (ha1)); 120 MD5Update (&md5, ha1, sizeof (ha1));
@@ -246,7 +246,7 @@ lookup_sub_value (char *dest,
246 return 0; /* end quote not found */ 246 return 0; /* end quote not found */
247 qn = q2 + 1; 247 qn = q2 + 1;
248 } 248 }
249 if ( (0 == strncasecmp (ptr, 249 if ((MHD_str_equal_caseless_n_(ptr,
250 key, 250 key,
251 keylen)) && 251 keylen)) &&
252 (eq == &ptr[keylen]) ) 252 (eq == &ptr[keylen]) )
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 95c7938f..c3814926 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -286,11 +286,10 @@ MHD_create_post_processor (struct MHD_Connection *connection,
286 if (encoding == NULL) 286 if (encoding == NULL)
287 return NULL; 287 return NULL;
288 boundary = NULL; 288 boundary = NULL;
289 if (0 != strncasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding, 289 if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, encoding,
290 strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED))) 290 strlen (MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
291 { 291 {
292 if (0 != 292 if (!MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding,
293 strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding,
294 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))) 293 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
295 return NULL; 294 return NULL;
296 boundary = 295 boundary =
@@ -503,7 +502,7 @@ try_match_header (const char *prefix, char *line, char **suffix)
503 return MHD_NO; 502 return MHD_NO;
504 while (*line != 0) 503 while (*line != 0)
505 { 504 {
506 if (0 == strncasecmp (prefix, line, strlen (prefix))) 505 if (MHD_str_equal_caseless_n_ (prefix, line, strlen (prefix)))
507 { 506 {
508 *suffix = strdup (&line[strlen (prefix)]); 507 *suffix = strdup (&line[strlen (prefix)]);
509 return MHD_YES; 508 return MHD_YES;
@@ -663,7 +662,7 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
663 if (buf[newline] == '\r') 662 if (buf[newline] == '\r')
664 pp->skip_rn = RN_OptN; 663 pp->skip_rn = RN_OptN;
665 buf[newline] = '\0'; 664 buf[newline] = '\0';
666 if (0 == strncasecmp ("Content-disposition: ", 665 if (MHD_str_equal_caseless_n_ ("Content-disposition: ",
667 buf, strlen ("Content-disposition: "))) 666 buf, strlen ("Content-disposition: ")))
668 { 667 {
669 try_get_value (&buf[strlen ("Content-disposition: ")], 668 try_get_value (&buf[strlen ("Content-disposition: ")],
@@ -969,7 +968,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
969 break; 968 break;
970 case PP_PerformCheckMultipart: 969 case PP_PerformCheckMultipart:
971 if ((pp->content_type != NULL) && 970 if ((pp->content_type != NULL) &&
972 (0 == strncasecmp (pp->content_type, 971 (MHD_str_equal_caseless_n_ (pp->content_type,
973 "multipart/mixed", 972 "multipart/mixed",
974 strlen ("multipart/mixed")))) 973 strlen ("multipart/mixed"))))
975 { 974 {
@@ -1137,11 +1136,10 @@ MHD_post_process (struct MHD_PostProcessor *pp,
1137 return MHD_YES; 1136 return MHD_YES;
1138 if (NULL == pp) 1137 if (NULL == pp)
1139 return MHD_NO; 1138 return MHD_NO;
1140 if (0 == strncasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, pp->encoding, 1139 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, pp->encoding,
1141 strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED))) 1140 strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
1142 return post_process_urlencoded (pp, post_data, post_data_len); 1141 return post_process_urlencoded (pp, post_data, post_data_len);
1143 if (0 == 1142 if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, pp->encoding,
1144 strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, pp->encoding,
1145 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))) 1143 strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
1146 return post_process_multipart (pp, post_data, post_data_len); 1144 return post_process_multipart (pp, post_data, post_data_len);
1147 /* this should never be reached */ 1145 /* this should never be reached */