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
31 AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const guint8*text, guint size) {
36 n = g_malloc(sizeof(AvahiStringList) + size);
38 memcpy(n->text, text, n->size = size);
43 AvahiStringList *avahi_string_list_add(AvahiStringList *l, const gchar *text) {
46 return avahi_string_list_add_arbitrary(l, (const guint8*) text, strlen(text));
49 AvahiStringList *avahi_string_list_parse(gconstpointer data, guint size) {
50 AvahiStringList *r = NULL;
62 r = avahi_string_list_add_arbitrary(r, c, k);
71 void avahi_string_list_free(AvahiStringList *l) {
81 AvahiStringList* avahi_string_list_reverse(AvahiStringList *l) {
82 AvahiStringList *r = NULL, *n;
94 gchar* avahi_string_list_to_string(AvahiStringList *l) {
99 l = avahi_string_list_reverse(l);
101 for (n = l; n; n = n->next) {
108 t = e = g_new(gchar, s+1);
110 for (n = l; n; n = n->next) {
115 strncpy(e, (gchar*) n->text, n->size);
123 l = avahi_string_list_reverse(l);
130 guint avahi_string_list_serialize(AvahiStringList *l, gpointer data, guint size) {
139 l = avahi_string_list_reverse(l);
142 for (n = l; n; n = n->next) {
155 memcpy(c, n->text, k);
161 l = avahi_string_list_reverse(l);
165 for (n = l; n; n = n->next) {
179 gboolean avahi_string_list_equal(const AvahiStringList *a, const AvahiStringList *b) {
188 if (a->size != b->size)
191 if (a->size != 0 && memcmp(a->text, b->text, a->size) != 0)
199 AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...) {
203 r = avahi_string_list_add_many_va(r, va);
209 AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va) {
212 while ((txt = va_arg(va, const gchar*)))
213 r = avahi_string_list_add(r, txt);
219 AvahiStringList *avahi_string_list_new(const gchar *txt, ...) {
221 AvahiStringList *r = NULL;
224 r = avahi_string_list_add(r, txt);
227 r = avahi_string_list_add_many_va(r, va);
234 AvahiStringList *avahi_string_list_new_va(va_list va) {
235 return avahi_string_list_add_many_va(NULL, va);
238 AvahiStringList *avahi_string_list_copy(const AvahiStringList *l) {
239 AvahiStringList *r = NULL;
241 for (; l; l = l->next)
242 r = avahi_string_list_add_arbitrary(r, l->text, l->size);
244 return avahi_string_list_reverse(r);
247 AvahiStringList *avahi_string_list_new_from_array(const gchar *array[], gint length) {
248 AvahiStringList *r = NULL;
253 for (i = 0; length >= 0 ? i < length : !!array[i]; i++)
254 r = avahi_string_list_add(r, array[i]);
259 guint avahi_string_list_length(const AvahiStringList *l) {
262 for (; l; l = l->next)