4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 AvahiStringList*avahi_string_list_add_anonymous(AvahiStringList *l, size_t size) {
36 if (!(n = avahi_malloc(sizeof(AvahiStringList) + size)))
45 AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const uint8_t*text, size_t size) {
50 if (!(n = avahi_string_list_add_anonymous(l, size)))
54 memcpy(n->text, text, size);
59 AvahiStringList *avahi_string_list_add(AvahiStringList *l, const char *text) {
62 return avahi_string_list_add_arbitrary(l, (const uint8_t*) text, strlen(text));
65 AvahiStringList *avahi_string_list_parse(const void* data, size_t size) {
66 AvahiStringList *r = NULL;
79 r = avahi_string_list_add_arbitrary(r, c, k);
88 void avahi_string_list_free(AvahiStringList *l) {
98 AvahiStringList* avahi_string_list_reverse(AvahiStringList *l) {
99 AvahiStringList *r = NULL, *n;
111 char* avahi_string_list_to_string(AvahiStringList *l) {
116 l = avahi_string_list_reverse(l);
118 for (n = l; n; n = n->next) {
125 if (!(t = e = avahi_new(char, s+1))) {
126 l = avahi_string_list_reverse(l);
130 for (n = l; n; n = n->next) {
135 strncpy(e, (char*) n->text, n->size);
143 l = avahi_string_list_reverse(l);
150 size_t avahi_string_list_serialize(AvahiStringList *l, void *data, size_t size) {
159 l = avahi_string_list_reverse(l);
162 for (n = l; n; n = n->next) {
175 memcpy(c, n->text, k);
181 l = avahi_string_list_reverse(l);
185 for (n = l; n; n = n->next) {
199 int avahi_string_list_equal(const AvahiStringList *a, const AvahiStringList *b) {
208 if (a->size != b->size)
211 if (a->size != 0 && memcmp(a->text, b->text, a->size) != 0)
219 AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...) {
223 r = avahi_string_list_add_many_va(r, va);
229 AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va) {
232 while ((txt = va_arg(va, const char*)))
233 r = avahi_string_list_add(r, txt);
238 AvahiStringList *avahi_string_list_new(const char *txt, ...) {
240 AvahiStringList *r = NULL;
243 r = avahi_string_list_add(r, txt);
246 r = avahi_string_list_add_many_va(r, va);
253 AvahiStringList *avahi_string_list_new_va(va_list va) {
254 return avahi_string_list_add_many_va(NULL, va);
257 AvahiStringList *avahi_string_list_copy(const AvahiStringList *l) {
258 AvahiStringList *r = NULL;
260 for (; l; l = l->next)
261 r = avahi_string_list_add_arbitrary(r, l->text, l->size);
263 return avahi_string_list_reverse(r);
266 AvahiStringList *avahi_string_list_new_from_array(const char *array[], int length) {
267 AvahiStringList *r = NULL;
272 for (i = 0; length >= 0 ? i < length : !!array[i]; i++)
273 r = avahi_string_list_add(r, array[i]);
278 unsigned avahi_string_list_length(const AvahiStringList *l) {
281 for (; l; l = l->next)