Browse Source

util: match_domains function

Luke Dashjr 11 years ago
parent
commit
03e0ac2353
2 changed files with 14 additions and 0 deletions
  1. 13 0
      util.c
  2. 1 0
      util.h

+ 13 - 0
util.c

@@ -1977,6 +1977,19 @@ const char *extract_domain(size_t * const out_domainlen, const char * const uri,
 	return b;
 }
 
+bool match_domains(const char * const a, const size_t alen, const char * const b, const size_t blen)
+{
+	size_t a_domainlen, b_domainlen;
+	const char *a_domain, *b_domain;
+	a_domain = extract_domain(&a_domainlen, a, alen);
+	a_domain = get_registered_domain(&a_domainlen, a_domain, a_domainlen);
+	b_domain = extract_domain(&b_domainlen, b, blen);
+	b_domain = get_registered_domain(&b_domainlen, b_domain, b_domainlen);
+	if (a_domainlen != b_domainlen)
+		return false;
+	return !strncasecmp(a_domain, b_domain, a_domainlen);
+}
+
 static
 void _test_extract_domain(const char * const expect, const char * const uri)
 {

+ 1 - 0
util.h

@@ -114,6 +114,7 @@ bool isCspace(int c)
 
 extern const char *get_registered_domain(size_t *out_len, const char *, size_t len);
 extern const char *extract_domain(size_t *out_len, const char *uri, size_t urilen);
+extern bool match_domains(const char *a, size_t alen, const char *b, size_t blen);
 extern void test_domain_funcs();
 
 typedef struct timeval cgtimer_t;