X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Fstrlst.h;h=47fd14bc349c20493de4703764fbf16af2f35d1e;hb=cbe416351c4c1a99df476d3cee4a20af64fb3b89;hp=a4a4202a19c16ca9ca9f1962b3b10b60d85811e9;hpb=aa458a0a13d18882354f33c07b0a4e8e82e7a424;p=catta diff --git a/avahi-common/strlst.h b/avahi-common/strlst.h index a4a4202..47fd14b 100644 --- a/avahi-common/strlst.h +++ b/avahi-common/strlst.h @@ -22,11 +22,15 @@ USA. ***/ -#include -#include - /** \file strlst.h Implementation of a data type to store lists of strings */ +#include +#include +#include + +#include +#include + AVAHI_C_DECL_BEGIN /** Linked list of strings that can contain any number of binary @@ -37,14 +41,14 @@ AVAHI_C_DECL_BEGIN * primarily for storing DNS TXT record data. */ typedef struct AvahiStringList { struct AvahiStringList *next; /**< Pointe to the next linked list element */ - guint size; /**< Size of text[] */ - guint8 text[1]; /**< Character data */ + size_t size; /**< Size of text[] */ + uint8_t text[1]; /**< Character data */ } AvahiStringList; /** Create a new string list by taking a variable list of NUL * terminated strings. The strings are copied using g_strdup(). The * argument list must be terminated by a NULL pointer. */ -AvahiStringList *avahi_string_list_new(const gchar *txt, ...); +AvahiStringList *avahi_string_list_new(const char *txt, ...) AVAHI_GCC_SENTINEL; /** Same as avahi_string_list_new() but pass a va_list structure */ AvahiStringList *avahi_string_list_new_va(va_list va); @@ -52,7 +56,7 @@ AvahiStringList *avahi_string_list_new_va(va_list va); /** Create a new string list from a string array. The strings are * copied using g_strdup(). length should contain the length of the * array, or -1 if the array is NULL terminated*/ -AvahiStringList *avahi_string_list_new_from_array(const gchar **array, gint length); +AvahiStringList *avahi_string_list_new_from_array(const char **array, int length); /** Free a string list */ void avahi_string_list_free(AvahiStringList *l); @@ -60,23 +64,29 @@ void avahi_string_list_free(AvahiStringList *l); /** Append a NUL terminated string to the specified string list. The * passed string is copied using g_strdup(). Returns the new list * start. */ -AvahiStringList *avahi_string_list_add(AvahiStringList *l, const gchar *text); +AvahiStringList *avahi_string_list_add(AvahiStringList *l, const char *text); + +/** Append a new NUL terminated formatted string to the specified string list */ +AvahiStringList *avahi_string_list_add_printf(AvahiStringList *l, const char *format, ...) AVAHI_GCC_PRINTF_ATTR23; + +/** Append a new NUL terminated formatted string to the specified string list */ +AvahiStringList *avahi_string_list_add_vprintf(AvahiStringList *l, const char *format, va_list va); /** Append an arbitrary length byte string to the list. Returns the * new list start. */ -AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const guint8 *text, guint size); +AvahiStringList *avahi_string_list_add_arbitrary(AvahiStringList *l, const uint8_t *text, size_t size); /** Append a new entry to the string list. The string is not filled with data. The caller should fill in string data afterwards by writing it to l->text, where l is the pointer returned by this function. This function exists solely to optimize a few operations where otherwise superfluous string copying would be necessary. */ -AvahiStringList*avahi_string_list_add_anonymous(AvahiStringList *l, guint size); +AvahiStringList*avahi_string_list_add_anonymous(AvahiStringList *l, size_t size); /** Same as avahi_string_list_add(), but takes a variable number of * NUL terminated strings. The argument list must be terminated by a * NULL pointer. Returns the new list start. */ -AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...); +AvahiStringList *avahi_string_list_add_many(AvahiStringList *r, ...) AVAHI_GCC_SENTINEL; /** Same as avahi_string_list_add_many(), but use a va_list * structure. Returns the new list start. */ @@ -85,17 +95,17 @@ AvahiStringList *avahi_string_list_add_many_va(AvahiStringList *r, va_list va); /** Convert the string list object to a single character string, * seperated by spaces and enclosed in "". g_free() the result! This * function doesn't work well with string that contain NUL bytes. */ -gchar* avahi_string_list_to_string(AvahiStringList *l); +char* avahi_string_list_to_string(AvahiStringList *l); /** Serialize the string list object in a way that is compatible with * the storing of DNS TXT records. Strings longer than 255 bytes are truncated. */ -guint avahi_string_list_serialize(AvahiStringList *l, gpointer data, guint size); +size_t avahi_string_list_serialize(AvahiStringList *l, void * data, size_t size); /** Inverse of avahi_string_list_serialize() */ -AvahiStringList *avahi_string_list_parse(gconstpointer data, guint size); +AvahiStringList *avahi_string_list_parse(const void *data, size_t size); /** Compare to string lists */ -gboolean avahi_string_list_equal(const AvahiStringList *a, const AvahiStringList *b); +int avahi_string_list_equal(const AvahiStringList *a, const AvahiStringList *b); /** Copy a string list */ AvahiStringList *avahi_string_list_copy(const AvahiStringList *l); @@ -104,8 +114,24 @@ AvahiStringList *avahi_string_list_copy(const AvahiStringList *l); AvahiStringList* avahi_string_list_reverse(AvahiStringList *l); /** Return the number of elements in the string list */ -guint avahi_string_list_length(const AvahiStringList *l); +unsigned avahi_string_list_length(const AvahiStringList *l); + +/** Find the string list entry for the given DNS-SD TXT key */ +AvahiStringList *avahi_string_list_find(AvahiStringList *l, const char *key); + +/** Return the DNS-SD TXT key and value for the specified string list + * item. If size is not NULL it will be filled with the length of + * value. (for strings containing NUL bytes). If the entry doesn't + * contain a value *value will be set to NULL. You need to + * avahi_free() the strings returned in *key and *value. */ +int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, size_t *size); + +/** Add a new DNS-SD TXT key value pair to the string list. value may + * be NULL in case you want to specify a key without a value */ +AvahiStringList *avahi_string_list_add_pair(AvahiStringList *l, const char *key, const char *value); +/** Same as avahi_string_list_add_pair() but allow strings containing NUL bytes in *value. */ +AvahiStringList *avahi_string_list_add_pair_arbitrary(AvahiStringList *l, const char *key, const uint8_t *value, size_t size); AVAHI_C_DECL_END