-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
53 lines (43 loc) · 1.29 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef UTIL_H
#define UTIL_H
#include <stdlib.h>
/* KeyValue struct
*
* Struct holding a key and value string and the corresponding lengths
*
* key -> Key string
* key_length -> Length of the key string
* value -> Value string corresponding to the keylen
* value_length -> Length of the value string
*
*/
typedef struct _key_value_
{
char *key;
size_t key_length;
char* value;
size_t value_length;
} KeyValue;
/* KeyValueArray
*
* Array for storing key-value pairs. Keeps track of the size and provides
* an interface to interact with the array
*
* data -> array (pointer) the key-value pairs are stored in
* size -> size of the array
*
*/
typedef struct _key_value_array_
{
KeyValue *data;
size_t size;
} KeyValueArray;
void initKeyValue(KeyValue *element);
void initKeyValueArray(KeyValueArray *array);
void freeKeyValueArray(KeyValueArray *array);
int addField(KeyValueArray *array, const char *key, size_t keylen, const char *value, size_t valuelen);
const char * getValue(const KeyValueArray *array, const char *key);
int setValue(KeyValueArray *array, const char *key, const char *new_value, size_t new_value_len);
int setString(char **destination, const char *source);
int setStringN(char **destination, const char *source, size_t source_len);
#endif