GUID name_to_guid(const char *in_name) { GUID result; char *name = (char*)in_name; unsigned i; if (memcasecmp(name, "\\Device\\NPF_{", 13) == 0) name += 13; result.Data1 = strtoul(name, &name, 16); if (*name == '-') name++; result.Data2 = (unsigned short)strtoul(name, &name, 16); if (*name == '-') name++; result.Data3 = (unsigned short)strtoul(name, &name, 16); if (*name == '-') name++; for (i=0; i<8; i++) { if (*name == '-') name++; if (isxdigit(*name)) { result.Data4[i] = hexval(*name)<<4; name++; } if (isxdigit(*name)) { unsigned char x = hexval(*name); result.Data4[i] |= x; name++; } } return result; }
int StringPiece::ignore_case_compare(const StringPiece& x) const { int r = memcasecmp(m_ptr, x.m_ptr, m_length < x.m_length ? m_length : x.m_length); if (r != 0) return r; if (m_length < x.m_length) return -1; else if (m_length > x.m_length) return 1; return 0; }
int StringPiece::ignore_case_compare(const StringPiece& x) const { int r = memcasecmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_); if (r != 0) return r; if (length_ < x.length_) return -1; else if (length_ > x.length_) return 1; return 0; }
int xdomain_is_equal(const struct DB_XDomain *lhs, const struct DomainPointer *rhs, unsigned max_labels) { unsigned i; const unsigned char *rhs_label = rhs->name; if (max_labels > lhs->label_count) return 0; for (i=max_labels; i>0; i--) { const unsigned char *lhs_label = lhs->labels[i-1].name; if (memcasecmp(lhs_label, rhs_label, *lhs_label+1) != 0) return 0; rhs_label += *rhs_label + 1; } return 1; }
bool StringPiece::ignore_case_equal(const StringPiece& other) const { return size() == other.size() && memcasecmp(data(), other.data(), size()) == 0; }
int checker_check(const struct CheckerA *a, const struct CheckerB *b, const unsigned char *px) { const unsigned char *a_name = (const unsigned char *)a->rname; const unsigned char *b_name = px; unsigned a_offset; unsigned b_offset; int b_type; int b_class; unsigned b_rdlength; const unsigned char *b_rdata; b_type = px[b->offset_data+0]<<8 | px[b->offset_data+1]; if (b_type != a->rtype) return 0; b_class = px[b->offset_data+2]<<8 | px[b->offset_data+3]; if (b_class != 1) return 0; b_rdlength = px[b->offset_data+8]<<8 | px[b->offset_data+9]; b_rdata = px + b->offset_data + 10; /* * First let's check the names */ a_offset = 0; b_offset = b->offset_name; for (;;) { unsigned a_len; unsigned b_len; /* handle compression at this point */ if (b_name[b_offset] & 0xC0) { b_offset = (b_name[b_offset]&0x3F)<<8 | b_name[b_offset+1]; } /* find the lable lengths */ for (a_len=0; a_name[a_offset+a_len] != '.' && a_name[a_offset+a_len]; a_len++) ; b_len = b_name[b_offset++]; /* compare the labels */ if (a_len != b_len) return 0; if (memcasecmp(&a_name[a_offset], &b_name[b_offset], a_len) != 0) return 0; /* move to next label */ a_offset += a_len; if (a_name[a_offset] == '.') a_offset++; b_offset += b_len; /* BREAK when we reac the end */ if (a_len == 0) break; } /* now let's check the data */ switch (b_type) { case TYPE_SOA: { unsigned char buf[1024]; unsigned buf_length = 0; int x; x = expand_soa(buf, &buf_length, sizeof(buf), b_rdata, b_rdlength, px); if (x == Failure) return 0; if (a->rdlength != buf_length) return 0; return memcasecmp(a->rdata, buf, buf_length) == 0; } break; default: if (a->rdlength != b_rdlength) return 0; return memcmp(a->rdata, b_rdata, b_rdlength) == 0; } }
bool StringStartsWithIgnoreCase(const StringPiece& str, const StringPiece& prefix) { return str.size() >= prefix.size() && memcasecmp(str.data(), prefix.data(), prefix.length()) == 0; }
int main (void) { /* Test equal / not equal distinction. */ ASSERT (memcasecmp (zerosize_ptr (), zerosize_ptr (), 0) == 0); ASSERT (memcasecmp ("foo", "foobar", 2) == 0); ASSERT (memcasecmp ("foo", "foobar", 3) == 0); ASSERT (memcasecmp ("foo", "foobar", 4) != 0); ASSERT (memcasecmp ("foo", "bar", 1) != 0); ASSERT (memcasecmp ("foo", "bar", 3) != 0); /* Test less / equal / greater distinction. */ ASSERT (memcasecmp ("foo", "moo", 4) < 0); ASSERT (memcasecmp ("moo", "foo", 4) > 0); ASSERT (memcasecmp ("oomph", "oops", 3) < 0); ASSERT (memcasecmp ("oops", "oomph", 3) > 0); ASSERT (memcasecmp ("foo", "foobar", 4) < 0); ASSERT (memcasecmp ("foobar", "foo", 4) > 0); /* Test embedded NULs. */ ASSERT (memcasecmp ("1\0", "2\0", 2) < 0); ASSERT (memcasecmp ("2\0", "1\0", 2) > 0); ASSERT (memcasecmp ("x\0""1", "x\0""2", 3) < 0); ASSERT (memcasecmp ("x\0""2", "x\0""1", 3) > 0); /* The Next x86 OpenStep bug shows up only when comparing 16 bytes or more and with at least one buffer not starting on a 4-byte boundary. William Lewis provided this test program. */ { char foo[21]; char bar[21]; int i; for (i = 0; i < 4; i++) { char *a = foo + i; char *b = bar + i; strcpy (a, "--------01111111"); strcpy (b, "--------10000000"); ASSERT (memcasecmp (a, b, 16) < 0); } } return 0; }
/**************************************************************************** * Compares an expected response record 'a' with a record in the produced * response packet 'b'. * * Normally, the response will be "failure". That's because for each * expected record, we test if it exists anywhere in the response packet. * Thus, the caller of this function will be going through many non-matches * in a packet until it finds the match. * ****************************************************************************/ int selftest_verify_one_item( const struct CheckerA *a, const struct CheckerB *b, const unsigned char *px, int print_message) { const unsigned char *a_name = (const unsigned char *)a->rname; const unsigned char *b_name = px; unsigned a_offset; unsigned b_offset; int b_type; int b_class; unsigned b_rdlength; const unsigned char *b_rdata; /* * STEP #1: * quick checks: * type must equal * class must equal */ b_type = px[b->offset_data+0]<<8 | px[b->offset_data+1]; if (b_type != a->rtype) return 0; b_class = px[b->offset_data+2]<<8 | px[b->offset_data+3]; if (b_class != 1) return 0; b_rdlength = px[b->offset_data+8]<<8 | px[b->offset_data+9]; b_rdata = px + b->offset_data + 10; if (print_message) printf("*******************************\n"); /* * STEP #2: * check that the "label" (domain name) matches */ a_offset = 0; b_offset = b->offset_name; for (;;) { unsigned a_len; unsigned b_len; /* handle compression at this point */ if (b_name[b_offset] & 0xC0) { b_offset = (b_name[b_offset]&0x3F)<<8 | b_name[b_offset+1]; } /* find the lable lengths */ for (a_len=0; a_name[a_offset+a_len] != '.' && a_name[a_offset+a_len]; a_len++) ; b_len = b_name[b_offset++]; if (print_message) { printf("\"%.*s\" -- \"%.*s\n", a_len, &a_name[a_offset], b_len, &b_name[b_offset]); } /* compare the labels */ if (a_len != b_len) return 0; if (memcasecmp(&a_name[a_offset], &b_name[b_offset], a_len) != 0) return 0; /* move to next label */ a_offset += a_len; if (a_name[a_offset] == '.') a_offset++; b_offset += b_len; /* BREAK when we reac the end */ if (a_len == 0) break; } if (print_message) printf("names match\n"); /* * STEP #3 * check that the 'rdata' (contents) of the record matches. Note that * some records (e.g. SOA) that contain compressable domain names * need to first be decompressed/expanded. */ switch (b_type) { case TYPE_SOA: { unsigned char buf[1024]; unsigned buf_length = 0; int x; x = decompress_soa(buf, &buf_length, sizeof(buf), b_rdata, b_rdlength, px); if (x == Failure) return 0; if (a->rdlength != buf_length) return 0; return memcasecmp(a->rdata, buf, buf_length) == 0; } break; default: if (a->rdlength != b_rdlength) return 0; { int x = (memcmp(a->rdata, b_rdata, b_rdlength) == 0); if (print_message) { if (x) printf("rdata matches\n"); else { printf("rdata FAIL\n"); } } return x; } } }
static int string_ci_cmp(string s1, string s2) { size_t len = (s1->len < s2->len) ? s1->len : s2->len; int retval = memcasecmp(s1->data, s2->data, len); return retval ? retval : (long)(s1->len - s2->len); }