From f5a4db2039532ef93fbb3d98fa048be9d74a83fe Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 16 May 2005 01:01:43 +0000 Subject: * case insensitive name comparisons * corectly handle RRsets * make addresses unique * return to probe state on conflict * a bunch of fixes detected while testing against the Apple Bonjour Conformance Test * a fix in avahi_record_lexicographical_cmp() regarding TXT records * API for choosing alternative host and service names * remove a bunch of unused crap from cache.c and server.c * flush cache when an interface becomes unavailable git-svn-id: file:///home/lennart/svn/public/avahi/trunk@72 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/util.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'avahi-core/util.c') diff --git a/avahi-core/util.c b/avahi-core/util.c index 086c041..9b84d12 100644 --- a/avahi-core/util.c +++ b/avahi-core/util.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "util.h" @@ -401,3 +403,55 @@ gint avahi_domain_hash(const gchar *s) { g_free(n); } } + + +gchar * avahi_alternative_host_name(const gchar *s) { + const gchar *p, *e = NULL; + gchar *c, *r; + gint n; + + g_assert(s); + + for (p = s; *p; p++) + if (!isdigit(*p)) + e = p+1; + + if (e && *e) + n = atoi(e)+1; + else + n = 2; + + c = e ? g_strndup(s, e-s) : g_strdup(s); + r = g_strdup_printf("%s%i", c, n); + g_free(c); + + return r; + +} + +gchar *avahi_alternative_service_name(const gchar *s) { + const gchar *e; + g_assert(s); + + if ((e = strstr(s, " #"))) { + const gchar *n, *p; + e += 2; + + while ((n = strstr(e, " #"))) + e = n + 2; + + for (p = e; *p; p++) + if (!isdigit(*p)) { + e = NULL; + break; + } + } + + if (e) { + gchar *r, *c = g_strndup(s, e-s); + r = g_strdup_printf("%s%i", c, atoi(e)+1); + g_free(c); + return r; + } else + return g_strdup_printf("%s #2", s); +} -- cgit