1#ifndef LIBNAGIOS_KVVEC_H_INCLUDED
2#define LIBNAGIOS_KVVEC_H_INCLUDED
49#define KVVEC_INITIALIZER { NULL, 0, 0, 0 }
52#define KVVEC_FREE_KEYS 1
53#define KVVEC_FREE_VALUES 2
55#define KVVEC_FREE_ALL (KVVEC_FREE_KEYS | KVVEC_FREE_VALUES)
134#define kvvec_addkv(kvv, key, value) kvvec_addkv_wlen(kvv, key, 0, value, 0)
191extern struct kvvec *
buf2kvvec(
char *str,
unsigned int len,
const char kvsep,
const char pair_sep,
int flags);
205extern int buf2kvvec_prealloc(
struct kvvec *kvv,
char *str,
unsigned int len,
const char kvsep,
const char pair_sep,
int flags);
void kvvec_free_kvpairs(struct kvvec *kvv, int flags)
Free key/value pairs associated with a key/value vector.
unsigned int kvvec_capacity(struct kvvec *kvv)
Return remaining storage capacity of key/value vector.
int kvvec_addkv_wlen(struct kvvec *kvv, const char *key, int keylen, const char *value, int valuelen)
Add a key/value pair to an existing key/value vector, with lengths of strings already calculated.
struct kvvec_buf * kvvec2buf(struct kvvec *kvv, char kv_sep, char pair_sep, int overalloc)
Create a linear buffer of all the key/value pairs and return it as a kvvec_buf.
struct kvvec * kvvec_init(struct kvvec *kvv, int hint)
Initialize a previously allocated key/value vector.
int kvvec_foreach(struct kvvec *kvv, void *arg, int(*callback)(struct key_value *, void *))
Walk each key/value pair in a key/value vector, sending them as arguments to a callback function.
struct kvvec * buf2kvvec(char *str, unsigned int len, const char kvsep, const char pair_sep, int flags)
Create a key/value vector from a pre-parsed buffer.
int kvvec_resize(struct kvvec *kvv, int size)
Resize a key/value vector Used by kvvec_grow().
struct kvvec * kvvec_create(int hint)
Create a key/value vector.
int kvvec_grow(struct kvvec *kvv, int hint)
Grow a key/value vector.
int kvvec_destroy(struct kvvec *kvv, int flags)
Destroy a key/value vector.
int buf2kvvec_prealloc(struct kvvec *kvv, char *str, unsigned int len, const char kvsep, const char pair_sep, int flags)
Parse a buffer into the pre-allocated key/value vector.
int kvvec_sort(struct kvvec *kvv)
Sort a key/value vector alphabetically by key name.
key/value pair One of the two major components of the kvvec api
Definition kvvec.h:18
int value_len
Length of value.
Definition kvvec.h:22
char * key
The key.
Definition kvvec.h:19
char * value
The value.
Definition kvvec.h:20
int key_len
Length of key.
Definition kvvec.h:21
key/value vector buffer.
Definition kvvec.h:29
char * buf
The buffer.
Definition kvvec.h:30
unsigned long buflen
Length of buffer.
Definition kvvec.h:31
unsigned long bufsize
Size of buffer (includes overalloc)
Definition kvvec.h:32
key/value vector struct This is the main component of the kvvec library
Definition kvvec.h:41
int kv_alloc
Allocated size of key/value array.
Definition kvvec.h:43
struct key_value * kv
The key/value array.
Definition kvvec.h:42
int kv_pairs
Number of key/value pairs.
Definition kvvec.h:44
int kvv_sorted
Determines if this kvvec has been sorted.
Definition kvvec.h:45