int ascii_strcasecmp (char const *a, char const *b) { if (a == b) return 0; for (; *a && *b; a++, b++) { if (*a != *b && ascii_toupper (*a) != ascii_toupper (*b)) break; } return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); }
int _ksba_ascii_memcasecmp (const void *a_arg, const void *b_arg, size_t n) { const char *a = a_arg; const char *b = b_arg; if (a == b) return 0; for ( ; n; n--, a++, b++ ) { if (*a != *b && ascii_toupper (*a) != ascii_toupper (*b)) return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); } return 0; }
const char * ascii_memistr( const char *buf, size_t buflen, const char *sub ) { const byte *t, *s ; size_t n; for( t=buf, n=buflen, s=sub ; n ; t++, n-- ) if( ascii_toupper(*t) == ascii_toupper(*s) ) { for( buf=t++, buflen = n--, s++; n && ascii_toupper(*t) == ascii_toupper(*s); t++, s++, n-- ) ; if( !*s ) return buf; t = buf; n = buflen; s = sub ; } return NULL ; }
static bool keybinding_equals(struct key_input *input1, struct key_input *input2, bool *conflict) { if (input1->modifiers.control && input1->modifiers.multibytes && !memcmp(&input1->modifiers, &input2->modifiers, sizeof(input1->modifiers)) && strlen(input1->data.bytes) == 1 && strlen(input2->data.bytes) == 1) { int c1 = input1->data.bytes[0]; int c2 = input2->data.bytes[0]; bool equals = ascii_toupper(c1) == ascii_toupper(c2); if (equals && c1 != c2) *conflict = TRUE; return equals; } return !memcmp(input1, input2, sizeof(*input1)); }
frenzy::ustring frenzy::dom::Element::get_tagName() const { // TODO: If namespace prefix is not null, prepend namespace: ustring ret = get_localName(); // TODO: If element in HTML namespace and node document in HTML namespace: ret = ascii_toupper(ret); return ret; }
int string_enum_compare(const char *str1, const char *str2, int len) { size_t i; #define string_enum_sep(x) ((x) == '-' || (x) == '_') /* Diff-Header == DIFF_HEADER */ for (i = 0; i < len; i++) { if (ascii_toupper(str1[i]) == ascii_toupper(str2[i])) continue; if (string_enum_sep(str1[i]) && string_enum_sep(str2[i])) continue; return str1[i] - str2[i]; } return 0; }
static bool keybinding_matches(const struct keybinding *keybinding, const struct key key[], size_t keys, bool *conflict_ptr) { bool conflict = false; int i; if (keybinding->keys < keys) return false; for (i = 0; i < keys; i++) { const struct key *key1 = &keybinding->key[i]; const struct key *key2 = &key[i]; if (key1->modifiers.control && key1->modifiers.multibytes && !memcmp(&key1->modifiers, &key2->modifiers, sizeof(key1->modifiers)) && strlen(key1->data.bytes) == 1 && strlen(key2->data.bytes) == 1) { int c1 = key1->data.bytes[0]; int c2 = key2->data.bytes[0]; if (ascii_toupper(c1) != ascii_toupper(c2)) return false; if (c1 != c2) conflict = true; } else { if (memcmp(key1, key2, sizeof(*key1))) return false; } } if (conflict_ptr && keybinding->request != REQ_NONE) *conflict_ptr = conflict; return true; }
static enum html_attr parse_attribute(const struct array attr) { static const struct { const char *name; enum html_attr attr; } tab[] = { #define D(x) { #x, HTML_ATTR_ ## x, } D(ALT), D(HEIGHT), D(HREF), D(LANG), D(NAME), D(SRC), D(TARGET), D(WIDTH), #undef D }; size_t i, len; char name[32]; STATIC_ASSERT(N_ITEMS(tab) == NUM_HTML_ATTR - 1); len = 0; for (i = 0; i < attr.size; i++) { const unsigned char c = attr.data[i]; if (N_ITEMS(name) == len || !is_ascii_alpha(c)) break; name[len] = ascii_toupper(c); len++; } if (len > 0 && len < N_ITEMS(name)) { name[len] = '\0'; for (i = 0; i < N_ITEMS(tab); i++) { if (0 == strcmp(name, tab[i].name)) return tab[i].attr; } g_warning("%s(): unknown attribute: \"%s\"", G_STRFUNC, name); } return HTML_ATTR_UNKNOWN; }
static enum html_tag parse_tag(const struct array tag) { static const struct { const char *name; enum html_tag tag; } tab[] = { #define D(x) { #x, HTML_TAG_ ## x, } D(UNKNOWN), D(A), D(B), D(BODY), D(BR), D(COL), D(CODE), D(DD), D(DIV), D(DL), D(DT), D(EM), D(H1), D(H2), D(H3), D(H4), D(H5), D(H6), D(HR), D(HEAD), D(HTML), D(I), D(IMG), D(KBD), D(LI), D(META), D(OL), D(P), D(PRE), D(Q), D(SPAN), D(STRONG), D(TABLE), D(TBODY), D(TD), D(TH), D(THEAD), D(TITLE), D(TR), D(TT), D(UL), { "!--", HTML_TAG_COMMENT }, { "!DOCTYPE", HTML_TAG_DOCTYPE }, #undef D }; size_t i, len; char name[32]; STATIC_ASSERT(N_ITEMS(tab) == NUM_HTML_TAG); len = 0; for (i = 0; i < tag.size; i++) { const unsigned char c = tag.data[i]; if (N_ITEMS(name) == len) break; if (0 == len) { if ('/' == c && 0 == i) continue; if (!is_ascii_alnum(c) && '!' != c && '?' != c) break; } else if (!is_ascii_alnum(c) && '-' != c) { break; } name[len] = ascii_toupper(c); len++; } if (len > 0 && len < N_ITEMS(name)) { name[len] = '\0'; for (i = 0; i < N_ITEMS(tab); i++) { if (0 == strcmp(name, tab[i].name)) return tab[i].tag; } g_warning("%s(): unknown tag: \"%s\"", G_STRFUNC, name); } return HTML_TAG_UNKNOWN; }
/** * Called from gwc_parse_dispatch_lines() for each complete line of output. * * @return FALSE to stop processing of any remaining data. */ static bool gwc_host_line(struct gwc_parse_context *ctx, const char *buf, size_t len) { int c; if (GNET_PROPERTY(bootstrap_debug) > 3) g_message("BOOT GWC host line (%lu bytes): %s", (ulong) len, buf); if (is_strprefix(buf, "ERROR")) { g_warning("GWC cache \"%s\" returned %s", http_async_url(ctx->handle), buf); http_async_cancel(ctx->handle); return FALSE; } if (len <= 2) return TRUE; /* Skip this line silently */ /* * A line starting with "H|" is a host, with "U|" a GWC URL. * Letters are case-insensitive. */ if (buf[1] != '|') goto malformed; c = ascii_toupper(buf[0]); if ('H' == c) { host_addr_t addr; uint16 port; if (string_to_host_addr_port(&buf[2], NULL, &addr, &port)) { ctx->processed++; hcache_add_caught(HOST_G2HUB, addr, port, "GWC"); if (GNET_PROPERTY(bootstrap_debug) > 1) { g_message("BOOT (G2) collected %s from GWC %s", host_addr_port_to_string(addr, port), http_async_url(ctx->handle)); } } return TRUE; } else if ('U' == c) { char *end = strchr(&buf[2], '|'); char *url; if (NULL == end) goto malformed; ctx->processed++; url = h_strndup(&buf[2], ptr_diff(end, &buf[2])); gwc_add(url); hfree(url); return TRUE; } else if ('I' == c) { return TRUE; /* Ignore information line */ } /* * If we come here, we did not recognize the line properly. */ if (GNET_PROPERTY(bootstrap_debug) > 2) { g_warning("GWC ignoring unknown line \"%s\" from %s", buf, http_async_url(ctx->handle)); } return TRUE; malformed: if (GNET_PROPERTY(bootstrap_debug)) { g_warning("GWC ignoring malformed line \"%s\" from %s", buf, http_async_url(ctx->handle)); } return TRUE; }