and use them when appropriate.
*/
int yaz_memcmp(const void *a, const void *b, size_t len_a, size_t len_b);
+/** \brief ala strncasecmp - no locale
+ \param s1 first buffer
+ \param s2 second buffer
+ \param n number of bytes to compare
+ \retval 0 buffers are equal
+ \retval >0 a > b
+ \retval <0 a < b
+*/
+int yaz_strncasecmp(const char *s1, const char *s2, size_t n);
+
+/** \brief ala strcasecmp - no locale
+ \param s1 first buffer
+ \param s2 second buffer
+ \retval 0 buffers are equal
+ \retval >0 a > b
+ \retval <0 a < b
+*/
+int yaz_strcasecmp(const char *s1, const char *s2);
+
YAZ_END_CDECL
#include <yaz/tcpip.h>
#include <yaz/unix.h>
#include <yaz/odr.h>
-
-#ifdef WIN32
-#define strncasecmp _strnicmp
-#endif
+#include <yaz/matchstr.h>
#if HAVE_GNUTLS_H
#define ENABLE_SSL 1
break;
}
else if (i < len - 20 &&
- !strncasecmp((const char *) buf+i, "Transfer-Encoding:", 18))
+ !yaz_strncasecmp((const char *) buf+i,
+ "Transfer-Encoding:", 18))
{
i+=18;
while (buf[i] == ' ')
i++;
if (i < len - 8)
- if (!strncasecmp((const char *) buf+i, "chunked", 7))
+ if (!yaz_strncasecmp((const char *) buf+i, "chunked", 7))
chunked = 1;
}
else if (i < len - 17 &&
- !strncasecmp((const char *)buf+i, "Content-Length:", 15))
+ !yaz_strncasecmp((const char *)buf+i,
+ "Content-Length:", 15))
{
i+= 15;
while (buf[i] == ' ')
#include <yaz/zgdu.h>
#include <yaz/base64.h>
-#ifdef WIN32
-#define strncasecmp _strnicmp
-#define strcasecmp _stricmp
-#endif
-
static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers,
char **content_buf, int *content_len)
{
memcpy ((*headers)->value, o->buf + po, i - po);
(*headers)->value[i - po] = '\0';
- if (!strcasecmp((*headers)->name, "Transfer-Encoding")
+ if (!yaz_strcasecmp((*headers)->name, "Transfer-Encoding")
&&
- !strcasecmp((*headers)->value, "chunked"))
+ !yaz_strcasecmp((*headers)->value, "chunked"))
chunked = 1;
headers = &(*headers)->next;
if (i < o->size-1 && o->buf[i] == '\r')
{
while (*hp)
{
- if (!strcmp((*hp)->name, n))
+ if (!yaz_strcasecmp((*hp)->name, n))
{
(*hp)->value = odr_strdup(o, v);
return;
const char *z_HTTP_header_lookup(const Z_HTTP_Header *hp, const char *n)
{
for (; hp; hp = hp->next)
- if (!yaz_matchstr(hp->name, n))
+ if (!yaz_strcasecmp(hp->name, n))
return hp->value;
return 0;
}
odr_write2(o, sbuf, strlen(sbuf));
for (h = hr->headers; h; h = h->next)
{
- if (yaz_matchstr(h->name, "Content-Length")
- && yaz_matchstr(h->name, "Transfer-Encoding"))
+ if (yaz_strcasecmp(h->name, "Content-Length")
+ && yaz_strcasecmp(h->name, "Transfer-Encoding"))
{ /* skip Content-Length if given. content_len rules */
odr_write2(o, h->name, strlen(h->name));
odr_write2(o, ": ", 2);
#include <yaz/yaz-iconv.h>
#include <yaz/matchstr.h>
+int yaz_strcasecmp(const char *s1, const char *s2)
+{
+ return yaz_strncasecmp(s1, s2, strlen(s1) + 1);
+}
+
+int yaz_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ while (n--)
+ {
+ unsigned char c1 = *s1++;
+ unsigned char c2 = *s2++;
+ if (yaz_isupper(c1))
+ c1 = yaz_tolower(c1);
+ if (yaz_isupper(c2))
+ c2 = yaz_tolower(c2);
+ if (c1 != c2)
+ return c1 - c2;
+ }
+ return 0;
+}
+
int yaz_matchstr(const char *s1, const char *s2)
{
while (*s1 && *s2)
YAZ_CHECK(yaz_matchstr("a123", "a1.") > 0);
YAZ_CHECK(yaz_matchstr("a123", "a...") == 0);
+ YAZ_CHECK_EQ(yaz_strncasecmp("a", "b", 0), 0);
+ YAZ_CHECK_EQ(yaz_strncasecmp("a", "a", 1), 0);
+ YAZ_CHECK_EQ(yaz_strncasecmp("a", "a", 2), 0);
+ YAZ_CHECK_EQ(yaz_strncasecmp("a", "b", 1), -1);
+ YAZ_CHECK_EQ(yaz_strncasecmp("a", "b", 2), -1);
+ YAZ_CHECK_EQ(yaz_strncasecmp("b", "a", 1), 1);
+ YAZ_CHECK_EQ(yaz_strncasecmp("b", "a", 2), 1);
+
+ YAZ_CHECK_EQ(yaz_strncasecmp("bb", "ba", 1), 0);
+ YAZ_CHECK_EQ(yaz_strncasecmp("bb", "ba", 2), 1);
+ YAZ_CHECK_EQ(yaz_strncasecmp("ba", "bb", 2), -1);
+ YAZ_CHECK_EQ(yaz_strncasecmp("ba", "b", 2), 'a');
+ YAZ_CHECK_EQ(yaz_strncasecmp("b", "ba", 2), -'a');
+
+ YAZ_CHECK_EQ(yaz_strcasecmp("", ""), 0);
+ YAZ_CHECK_EQ(yaz_strcasecmp("a", "a"), 0);
+ YAZ_CHECK_EQ(yaz_strcasecmp("a", "b"), -1);
+ YAZ_CHECK_EQ(yaz_strcasecmp("b", "a"), 1);
+
+ YAZ_CHECK_EQ(yaz_strcasecmp("bb", "ba"), 1);
+ YAZ_CHECK_EQ(yaz_strcasecmp("ba", "bb"), -1);
+ YAZ_CHECK_EQ(yaz_strcasecmp("ba", "b"), 'a');
+ YAZ_CHECK_EQ(yaz_strcasecmp("b", "ba"), -'a');
+
YAZ_CHECK_TERM;
}