summaryrefslogtreecommitdiffstats
path: root/avahi-core/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-05-16 01:01:43 +0000
committerLennart Poettering <lennart@poettering.net>2005-05-16 01:01:43 +0000
commitf5a4db2039532ef93fbb3d98fa048be9d74a83fe (patch)
treeb3db891f27468f13ed2851f3f69e843823780dbc /avahi-core/util.c
parenta3596a5e3ec4937a220e6e60218639e2aba82701 (diff)
* 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
Diffstat (limited to 'avahi-core/util.c')
-rw-r--r--avahi-core/util.c54
1 files changed, 54 insertions, 0 deletions
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 <errno.h>
#include <limits.h>
#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
#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);
+}