Example #1
0
static int compare_ascii(const char *s1, size_t s1len, const char *s2, size_t s2len)
{
	size_t i;
	for(i = 0;; i++)
	{
		if(i == s1len)
		{
			if(i == s2len)
				break;
			return -1;
		}
		else if(i == s2len)
		{
			return +1;
		}
		if(tolower_ascii(s1[i]) != tolower_ascii(s2[i]))
			return s1[i] - s2[i];
	}
	return 0;
}
Example #2
0
inline bool bool_str_cmp(const char** b, size_t len, const char* value) {
  // Can't use strncasecmp, since we want to ensure that the full value matches
  const char* p = *b;
  const char* e = *b + len;
  const char* v = value;
  while (*v != '\0') {
    if (p == e || tolower_ascii(*p) != *v) { // value is already lowercase
      return false;
    }
    ++p;
    ++v;
  }

  *b = p;
  return true;
}
Example #3
0
static void compare_Test()
{
	assert('a' == tolower_ascii('a'));
	assert('a' == tolower_ascii('A'));
	assert('f' == tolower_ascii('F'));
	assert('w' == tolower_ascii('w'));
	assert('w' == tolower_ascii('W'));
	assert('z' == tolower_ascii('Z'));
	assert('z' == tolower_ascii('z'));
	assert(0 == compare_ascii("hello", 5, "hello", 5));
	assert(0 == compare_ascii("Hello", 5, "hello", 5));
	assert(0 == compare_rfc1459("Hello", 5, "hello", 5));
	assert(0 == compare_rfc1459("H~l\\o", 5, "h^l|o", 5));
	assert(0 == compare_strict_rfc1459("Hello", 5, "hello", 5));
	assert(0 == compare_strict_rfc1459("Hel\\o", 5, "hel|o", 5));
}
Example #4
0
static void cache_mangled_name( const char mangled_name[13],
				const char *raw_name )
{
	TDB_DATA data_val;
	char mangled_name_key[13];
	char *s1;
	char *s2;

	/* If the cache isn't initialized, give up. */
	if( !tdb_mangled_cache )
		return;

	/* Init the string lengths. */
	safe_strcpy(mangled_name_key, mangled_name, sizeof(mangled_name_key)-1);

	/* See if the extensions are unmangled.  If so, store the entry
	 * without the extension, thus creating a "group" reverse map.
	 */
	s1 = strrchr( mangled_name_key, '.' );
	if( s1 && (s2 = strrchr( raw_name, '.' )) ) {
		size_t i = 1;
		while( s1[i] && (tolower_ascii( s1[i] ) == s2[i]) )
			i++;
		if( !s1[i] && !s2[i] ) {
			/* Truncate at the '.' */
			*s1 = '\0';
			*s2 = '\0';
		}
	}

	/* Allocate a new cache entry.  If the allocation fails, just return. */
	data_val = string_term_tdb_data(raw_name);
	if (tdb_store_bystring(tdb_mangled_cache, mangled_name_key, data_val, TDB_REPLACE) != 0) {
		DEBUG(0,("cache_mangled_name: Error storing entry %s -> %s\n", mangled_name_key, raw_name));
	} else {
		DEBUG(5,("cache_mangled_name: Stored entry %s -> %s\n", mangled_name_key, raw_name));
	}
}