X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Fstrlst.c;h=04941b4e9d116fe2d88afcfeb0047c8530cbe433;hb=9ca377e8bc8ef73714180143c24223016acbc845;hp=5bde68afe2da0907e7710bfccddb599ca668c0d9;hpb=79ae5a976987130b9b6eb4920e2656d8ef4fe37c;p=catta diff --git a/avahi-common/strlst.c b/avahi-common/strlst.c index 5bde68a..04941b4 100644 --- a/avahi-common/strlst.c +++ b/avahi-common/strlst.c @@ -27,9 +27,11 @@ #include #include #include +#include #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,26 @@ 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); + + if (*value && end && *end != 0) { + avahi_free(value); + return AVAHI_SERVICE_COOKIE_INVALID; + } + + avahi_free(value); + + return ret; +}