diff options
Diffstat (limited to 'http.c')
| -rw-r--r-- | http.c | 41 |
1 files changed, 37 insertions, 4 deletions
@@ -4,6 +4,7 @@ #include <dynstr.h> #include <sys/types.h> #include <unistd.h> +#include <ctype.h> #include <errno.h> #include <inttypes.h> #include <locale.h> @@ -1592,13 +1593,18 @@ static int process_header(struct http_ctx *const h, const char *const line, const struct header *const hdr = &headers[i]; int ret; - if (!strncasecmp(line, hdr->header, n)) + if ((ret = http_strncasecmp(line, hdr->header, n))) { - if ((ret = hdr->f(h, value))) + if (ret < 0) + { + fprintf(stderr, "%s: http_strncasecmp failed\n", __func__); return ret; - - break; + } } + else if ((ret = hdr->f(h, value))) + return ret; + else + break; } return append_header(h, line, n, value); @@ -2968,3 +2974,30 @@ end: return ret; } + +int http_strncasecmp(const char *s1, const char *s2, const size_t n) +{ + int ret = -1; + const locale_t l = newlocale(LC_CTYPE_MASK, "POSIX", (locale_t)0); + + if (l == (locale_t)0) + { + fprintf(stderr, "%s: newlocale(3): %s\n", __func__, strerror(errno)); + goto end; + } + + for (size_t i = 0; i < n; i++, s1++, s2++) + if (!*s1 || !*s2 || tolower_l(*s1, l) != tolower_l(*s2, l)) + { + ret = 1; + goto end; + } + + ret = 0; + +end: + if (l != (locale_t)0) + freelocale(l); + + return ret; +} |
