avahi  0.7
strlst.h File Reference

Implementation of a data type to store lists of strings. More...

#include <sys/types.h>
#include <inttypes.h>
#include <stdarg.h>
#include <avahi-common/cdecl.h>
#include <avahi-common/gccmacro.h>

Go to the source code of this file.

Data Structures

struct  AvahiStringList
 Linked list of strings that can contain any number of binary characters, including NUL bytes. More...
 

Typedefs

typedef struct AvahiStringList AvahiStringList
 Linked list of strings that can contain any number of binary characters, including NUL bytes. More...
 

Functions

Construction and destruction
AvahiStringListavahi_string_list_new (const char *txt,...) AVAHI_GCC_SENTINEL
 Create a new string list by taking a variable list of NUL terminated strings. More...
 
AvahiStringListavahi_string_list_new_from_array (const char **array, int length)
 Create a new string list from a string array. More...
 
void avahi_string_list_free (AvahiStringList *l)
 Free a string list. More...
 
Adding strings
AvahiStringListavahi_string_list_add (AvahiStringList *l, const char *text)
 Append a NUL terminated string to the specified string list. More...
 
AvahiStringListavahi_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. More...
 
AvahiStringListavahi_string_list_add_arbitrary (AvahiStringList *l, const uint8_t *text, size_t size)
 Append an arbitrary length byte string to the list. More...
 
AvahiStringListavahi_string_list_add_anonymous (AvahiStringList *l, size_t size)
 Append a new entry to the string list. More...
 
AvahiStringListavahi_string_list_add_many (AvahiStringList *r,...) AVAHI_GCC_SENTINEL
 Same as avahi_string_list_add(), but takes a variable number of NUL terminated strings. More...
 
String list operations
char * avahi_string_list_to_string (AvahiStringList *l)
 Convert the string list object to a single character string, seperated by spaces and enclosed in "". More...
 
int avahi_string_list_equal (const AvahiStringList *a, const AvahiStringList *b)
 Compare to string lists. More...
 
AvahiStringListavahi_string_list_copy (const AvahiStringList *l)
 Copy a string list. More...
 
AvahiStringListavahi_string_list_reverse (AvahiStringList *l)
 Reverse the string list. More...
 
unsigned avahi_string_list_length (const AvahiStringList *l)
 Return the number of elements in the string list. More...
 
Accessing items
AvahiStringListavahi_string_list_get_next (AvahiStringList *l)
 Returns the next item in the string list. More...
 
uint8_t * avahi_string_list_get_text (AvahiStringList *l)
 Returns the text for the current item. More...
 
size_t avahi_string_list_get_size (AvahiStringList *l)
 Returns the size of the current text. More...
 
DNS-SD TXT pair handling
AvahiStringListavahi_string_list_find (AvahiStringList *l, const char *key)
 Find the string list entry for the given DNS-SD TXT key. More...
 
int avahi_string_list_get_pair (AvahiStringList *l, char **key, char **value, size_t *size)
 Return the DNS-SD TXT key and value for the specified string list item. More...
 
AvahiStringListavahi_string_list_add_pair (AvahiStringList *l, const char *key, const char *value)
 Add a new DNS-SD TXT key value pair to the string list. More...
 
AvahiStringListavahi_string_list_add_pair_arbitrary (AvahiStringList *l, const char *key, const uint8_t *value, size_t size)
 Same as avahi_string_list_add_pair() but allow strings containing NUL bytes in *value. More...
 

Detailed Description

Implementation of a data type to store lists of strings.

Definition in file strlst.h.

Typedef Documentation

◆ AvahiStringList

Linked list of strings that can contain any number of binary characters, including NUL bytes.

An empty list is created by assigning a NULL to a pointer to AvahiStringList. The string list is stored in reverse order, so that appending to the string list is effectively a prepending to the linked list. This object is used primarily for storing DNS TXT record data.

Function Documentation

◆ avahi_string_list_add()

AvahiStringList* avahi_string_list_add ( AvahiStringList l,
const char *  text 
)

Append a NUL terminated string to the specified string list.

The passed string is copied using g_strdup(). Returns the new list start.

◆ avahi_string_list_add_anonymous()

AvahiStringList* avahi_string_list_add_anonymous ( AvahiStringList l,
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.

◆ avahi_string_list_add_arbitrary()

AvahiStringList* avahi_string_list_add_arbitrary ( AvahiStringList l,
const uint8_t *  text,
size_t  size 
)

Append an arbitrary length byte string to the list.

Returns the new list start.

◆ avahi_string_list_add_many()

AvahiStringList* avahi_string_list_add_many ( AvahiStringList r,
  ... 
)

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.

◆ avahi_string_list_add_pair()

AvahiStringList* avahi_string_list_add_pair ( AvahiStringList l,
const char *  key,
const char *  value 
)

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

◆ avahi_string_list_add_pair_arbitrary()

AvahiStringList* avahi_string_list_add_pair_arbitrary ( AvahiStringList l,
const char *  key,
const uint8_t *  value,
size_t  size 
)

Same as avahi_string_list_add_pair() but allow strings containing NUL bytes in *value.

◆ avahi_string_list_add_printf()

AvahiStringList* avahi_string_list_add_printf ( AvahiStringList l,
const char *  format,
  ... 
)

Append a new NUL terminated formatted string to the specified string list.

◆ avahi_string_list_copy()

AvahiStringList* avahi_string_list_copy ( const AvahiStringList l)

Copy a string list.

◆ avahi_string_list_equal()

int avahi_string_list_equal ( const AvahiStringList a,
const AvahiStringList b 
)

Compare to string lists.

◆ avahi_string_list_find()

AvahiStringList* avahi_string_list_find ( AvahiStringList l,
const char *  key 
)

Find the string list entry for the given DNS-SD TXT key.

◆ avahi_string_list_free()

void avahi_string_list_free ( AvahiStringList l)

Free a string list.

◆ avahi_string_list_get_next()

AvahiStringList* avahi_string_list_get_next ( AvahiStringList l)

Returns the next item in the string list.

◆ avahi_string_list_get_pair()

int avahi_string_list_get_pair ( AvahiStringList l,
char **  key,
char **  value,
size_t *  size 
)

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.

◆ avahi_string_list_get_size()

size_t avahi_string_list_get_size ( AvahiStringList l)

Returns the size of the current text.

◆ avahi_string_list_get_text()

uint8_t* avahi_string_list_get_text ( AvahiStringList l)

Returns the text for the current item.

◆ avahi_string_list_length()

unsigned avahi_string_list_length ( const AvahiStringList l)

Return the number of elements in the string list.

◆ avahi_string_list_new()

AvahiStringList* avahi_string_list_new ( const char *  txt,
  ... 
)

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.

◆ avahi_string_list_new_from_array()

AvahiStringList* avahi_string_list_new_from_array ( const char **  array,
int  length 
)

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

◆ avahi_string_list_reverse()

AvahiStringList* avahi_string_list_reverse ( AvahiStringList l)

Reverse the string list.

◆ avahi_string_list_to_string()

char* avahi_string_list_to_string ( AvahiStringList l)

Convert the string list object to a single character string, seperated by spaces and enclosed in "".

avahi_free() the result! This function doesn't work well with strings that contain NUL bytes.

Examples:
client-browse-services.c.