7 This file is part of avahi.
9 avahi is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 avahi is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17 Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with avahi; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <avahi-common/cdecl.h>
28 /** \file strlst.h Implementation of a data type to store lists of strings */
32 /** Linked list of strings that can contain any number of binary
33 * characters, including NUL bytes. An empty list is created by
34 * assigning a NULL to a pointer to AvahiStringList. The string list
35 * is stored in reverse order, so that appending to the string list is
36 * effectively a prepending to the linked list. This object is used
37 * primarily for storing DNS TXT record data. */
38 typedef struct AvahiStringList {
39 struct AvahiStringList *next; /**< Pointe to the next linked list element */
40 guint size; /**< Size of text[] */
41 guint8 text[1]; /**< Character data */
44 /** Create a new string list by taking a variable list of NUL
45 * terminated strings. The strings are copied using g_strdup(). The
46 * argument list must be terminated by a NULL pointer. */
47 AvahiStringList *avahi_string_list_new(const gchar *txt, ...);
49 /** Same as avahi_string_list_new() but pass a va_list structure */
50 AvahiStringList *avahi_string_list_new_va(va_list va);
52 /** Create a new string list from a string array. The strings are
53 * copied using g_strdup(). length should contain the length of the
54 * array, or -1 if the array is NULL terminated*/
55 AvahiStringList *avahi_string_list_new_from_array(const gchar **array, gint length);
57 /** Free a string list */
58 void avahi_string_list_free(AvahiStringList *l);
60 /** Append a NUL terminated string to the specified string list. The
61 * passed string is copied using g_strdup(). Returns the new list
63 AvahiStringList *avahi_string_list_add(AvahiStringList *l, const gchar *text);
65 /** Append an arbitrary length byte string to the list. Returns the
67 AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const guint8 *text, guint size);
69 /** Append a new entry to the string list. The string is not filled
70 with data. The caller should fill in string data afterwards by writing
71 it to l->text, where l is the pointer returned by this function. This
72 function exists solely to optimize a few operations where otherwise
73 superfluous string copying would be necessary. */
74 AvahiStringList*avahi_string_list_add_anonymous(AvahiStringList *l, guint size);
76 /** Same as avahi_string_list_add(), but takes a variable number of
77 * NUL terminated strings. The argument list must be terminated by a
78 * NULL pointer. Returns the new list start. */
79 AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...);
81 /** Same as avahi_string_list_add_many(), but use a va_list
82 * structure. Returns the new list start. */
83 AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va);
85 /** Convert the string list object to a single character string,
86 * seperated by spaces and enclosed in "". g_free() the result! This
87 * function doesn't work well with string that contain NUL bytes. */
88 gchar* avahi_string_list_to_string(AvahiStringList *l);
90 /** Serialize the string list object in a way that is compatible with
91 * the storing of DNS TXT records. Strings longer than 255 bytes are truncated. */
92 guint avahi_string_list_serialize(AvahiStringList *l, gpointer data, guint size);
94 /** Inverse of avahi_string_list_serialize() */
95 AvahiStringList *avahi_string_list_parse(gconstpointer data, guint size);
97 /** Compare to string lists */
98 gboolean avahi_string_list_equal(const AvahiStringList *a, const AvahiStringList *b);
100 /** Copy a string list */
101 AvahiStringList *avahi_string_list_copy(const AvahiStringList *l);
103 /** Reverse the string list. */
104 AvahiStringList* avahi_string_list_reverse(AvahiStringList *l);
106 /** Return the number of elements in the string list */
107 guint avahi_string_list_length(const AvahiStringList *l);