X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=util.c;fp=util.c;h=0fcedc71c0fee844ba99015c4b5a6fcd421bb883;hb=4ccd2cdd5ae567dc2cb6c05ca5e5a9537a9dc1c4;hp=3edaa8878398166b13e36bfc3efdba6a404cabc5;hpb=601f0a4ff139521db8f2999646717ec37005b984;p=catta diff --git a/util.c b/util.c index 3edaa88..0fcedc7 100644 --- a/util.c +++ b/util.c @@ -125,3 +125,34 @@ gint flx_age(const GTimeVal *a) { return flx_timeval_diff(&now, a); } + +gboolean flx_domain_equal(const gchar *a, const gchar *b) { + g_assert(a); + g_assert(b); + + for (;;) { + if (*a == 0 && *b == 0) + return TRUE; + + if (*a == 0 && *b == '.' && *(b+1) == 0) + return TRUE; + + if (*a == '.' && *(a+1) == 0 && *b == 0) + return TRUE; + + if (*a != *b) + return FALSE; + + a++; + b++; + } +} + +guint flx_domain_hash(const gchar *p) { + char t[256]; + strncpy(t, p, sizeof(t)-1); + t[sizeof(t)-1] = 0; + + return g_int_hash(t); +} +