summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-09-10 00:54:02 +0000
committerLennart Poettering <lennart@poettering.net>2005-09-10 00:54:02 +0000
commit9b68da84a46cfb4989bee3499278ada856d96758 (patch)
tree4c7526c14208b23283224704d47d2514040ec1c4
parentccae11c51822c2d2fd0a83012346c4c16ef86529 (diff)
add new API function avahi_string_list_get_service_cookie()
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@557 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--avahi-common/strlst.c39
-rw-r--r--avahi-common/strlst.h4
2 files changed, 35 insertions, 8 deletions
diff --git a/avahi-common/strlst.c b/avahi-common/strlst.c
index 5bde68a..a7df6c9 100644
--- a/avahi-common/strlst.c
+++ b/avahi-common/strlst.c
@@ -27,9 +27,11 @@
#include <stdarg.h>
#include <assert.h>
#include <stdio.h>
+#include <stdlib.h>
#include "strlst.h"
#include "malloc.h"
+#include "defs.h"
AvahiStringList*avahi_string_list_add_anonymous(AvahiStringList *l, size_t size) {
AvahiStringList *n;
@@ -402,17 +404,16 @@ AvahiStringList *avahi_string_list_add_pair_arbitrary(AvahiStringList *l, const
return l;
}
-
int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, size_t *size) {
char *e;
assert(l);
- assert(key);
if (!(e = memchr(l->text, '=', l->size))) {
-
- if (!(*key = avahi_strdup((char*) l->text)))
- return -1;
+
+ if (key)
+ if (!(*key = avahi_strdup((char*) l->text)))
+ return -1;
if (value)
*value = NULL;
@@ -423,8 +424,9 @@ int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, siz
} else {
size_t n;
- if (!(*key = avahi_strndup((char*) l->text, e - (char *) l->text)))
- return -1;
+ if (key)
+ if (!(*key = avahi_strndup((char*) l->text, e - (char *) l->text)))
+ return -1;
e++; /* Advance after '=' */
@@ -433,7 +435,8 @@ int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, siz
if (value) {
if (!(*value = avahi_memdup(e, n+1))) {
- avahi_free(*key);
+ if (key)
+ avahi_free(*key);
return -1;
}
@@ -461,3 +464,23 @@ size_t avahi_string_list_get_size(AvahiStringList *l) {
assert(l);
return l->size;
}
+
+uint32_t avahi_string_list_get_service_cookie(AvahiStringList *l) {
+ AvahiStringList *f;
+ char *value = NULL, *end = NULL;
+ uint32_t ret;
+
+ if (!(f = avahi_string_list_find(l, AVAHI_SERVICE_COOKIE)))
+ return AVAHI_SERVICE_COOKIE_INVALID;
+
+ if (avahi_string_list_get_pair(f, NULL, &value, NULL) < 0 || !value)
+ return AVAHI_SERVICE_COOKIE_INVALID;
+
+ ret = (uint32_t) strtoll(value, &end, 0);
+ avahi_free(value);
+
+ if (*value && end && *end != 0)
+ return AVAHI_SERVICE_COOKIE_INVALID;
+
+ return ret;
+}
diff --git a/avahi-common/strlst.h b/avahi-common/strlst.h
index 2c39351..925e944 100644
--- a/avahi-common/strlst.h
+++ b/avahi-common/strlst.h
@@ -142,6 +142,10 @@ uint8_t *avahi_string_list_get_text(AvahiStringList *l);
/** Returns the size of the current text */
size_t avahi_string_list_get_size(AvahiStringList *l);
+/** Try to find a magic service cookie in the specified DNS-SD string
+ * list. Or return AVAHI_SERVICE_COOKIE_INVALID if none is found. */
+uint32_t avahi_string_list_get_service_cookie(AvahiStringList *l);
+
AVAHI_C_DECL_END
#endif