summaryrefslogtreecommitdiffstats
path: root/avahi-common/alternative.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-08-21 20:53:24 +0000
committerLennart Poettering <lennart@poettering.net>2006-08-21 20:53:24 +0000
commit8cf0e9e31837c813fb05b90acfcec828e6309d76 (patch)
tree5a8920b54eab495d1a11c7b1bfba08e5211ae34c /avahi-common/alternative.c
parent2376babecb8f095a2bcbea3c3cbb3b1109291869 (diff)
follow Bonjour's hostname number incrementing algorithm for handling conflicts. On collision the name "foobar" will now become "foobar-2" and not "foobar2". (closes #40)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1250 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common/alternative.c')
-rw-r--r--avahi-common/alternative.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/avahi-common/alternative.c b/avahi-common/alternative.c
index 436a0d4..77470ba 100644
--- a/avahi-common/alternative.c
+++ b/avahi-common/alternative.c
@@ -32,20 +32,31 @@
#include "malloc.h"
char * avahi_alternative_host_name(const char *s) {
- const char *p, *e;
+ const char *e;
char *r;
assert(s);
- e = s;
-
- for (p = s; *p; p++)
- if (!isdigit(*p))
- e = p+1;
+ e = strrchr(s, '-');
+
+ if (e) {
+ const char *p;
+
+ for (p = e+1; *p; p++)
+ if (!isdigit(*p)) {
+ e = NULL;
+ break;
+ }
+
+ if (e && (*(e+1) == '0' || (*(e+1) == 0)))
+ e = NULL;
+ }
- if (*e) {
+ if (e) {
char *c;
+ e++;
+
if (!(c = avahi_strndup(s, e-s)))
return NULL;
@@ -53,7 +64,7 @@ char * avahi_alternative_host_name(const char *s) {
avahi_free(c);
} else
- r = avahi_strdup_printf("%s2", s);
+ r = avahi_strdup_printf("%s-2", s);
return r;
}
@@ -76,6 +87,9 @@ char *avahi_alternative_service_name(const char *s) {
e = NULL;
break;
}
+
+ if (e && (*e == '0' || *e == 0))
+ e = NULL;
}
if (e) {