summaryrefslogtreecommitdiffstats
path: root/avahi-common/strlst.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-22 19:15:22 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-22 19:15:22 +0000
commiteb3966f2d8bbfab5554b9312998e1d4812b0e28b (patch)
tree603900f575c1eaed65a909302d5ccdf1f068edee /avahi-common/strlst.c
parent723e4d07d4782c866ffee5329a373d8cbed2e5ff (diff)
* add four new AvahiStringList functions (this is four you, Sebastien!)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@395 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common/strlst.c')
-rw-r--r--avahi-common/strlst.c98
1 files changed, 93 insertions, 5 deletions
diff --git a/avahi-common/strlst.c b/avahi-common/strlst.c
index 574b151..d1e17be 100644
--- a/avahi-common/strlst.c
+++ b/avahi-common/strlst.c
@@ -117,8 +117,6 @@ char* avahi_string_list_to_string(AvahiStringList *l) {
size_t s = 0;
char *t, *e;
- l = avahi_string_list_reverse(l);
-
for (n = l; n; n = n->next) {
if (n != l)
s ++;
@@ -126,11 +124,11 @@ char* avahi_string_list_to_string(AvahiStringList *l) {
s += n->size+2;
}
- if (!(t = e = avahi_new(char, s+1))) {
- l = avahi_string_list_reverse(l);
+ if (!(t = e = avahi_new(char, s+1)))
return NULL;
- }
+ l = avahi_string_list_reverse(l);
+
for (n = l; n; n = n->next) {
if (n != l)
*(e++) = ' ';
@@ -337,3 +335,93 @@ AvahiStringList *avahi_string_list_add_printf(AvahiStringList *l, const char *fo
return l;
}
+
+AvahiStringList *avahi_string_list_find(AvahiStringList *l, const char *key) {
+ size_t n;
+
+ assert(key);
+ n = strlen(key);
+
+ for (; l; l = l->next) {
+ if (strcasecmp((char*) l->text, key) == 0)
+ return l;
+
+ if (strncasecmp((char*) l->text, key, n) == 0 && l->text[n] == '=')
+ return l;
+ }
+
+ return NULL;
+}
+
+AvahiStringList *avahi_string_list_add_pair(AvahiStringList *l, const char *key, const char *value) {
+ assert(key);
+
+ if (value)
+ return avahi_string_list_add_printf(l, "%s=%s", key, value);
+ else
+ return avahi_string_list_add(l, key);
+}
+
+AvahiStringList *avahi_string_list_add_pair_arbitrary(AvahiStringList *l, const char *key, const uint8_t *value, size_t size) {
+ size_t n;
+ assert(key);
+
+ if (!value)
+ return avahi_string_list_add(l, key);
+
+ n = strlen(key);
+
+ if (!(l = avahi_string_list_add_anonymous(l, n + 1 + size)))
+ return NULL;
+
+ memcpy(l->text, key, n);
+ l->text[n] = '=';
+ memcpy(l->text + n + 1, value, size);
+
+ 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 (value)
+ *value = NULL;
+
+ if (size)
+ *size = 0;
+
+ } else {
+ size_t n;
+
+ if (!(*key = avahi_strndup((char*) l->text, e - (char *) l->text)))
+ return -1;
+
+ e++; /* Advance after '=' */
+
+ n = l->size - (e - (char*) l->text);
+
+ if (value) {
+
+ if (!(*value = avahi_memdup(e, n+1))) {
+ avahi_free(*key);
+ return -1;
+ }
+
+ (*value)[n] = 0;
+ }
+
+ if (size)
+ *size = n;
+ }
+
+ return 0;
+}