|
|
@ -19,6 +19,7 @@ static int rpd_keyval_realloc(rpd_keyval *keyval, int capacity); |
|
|
|
int rpd_keyval_init(rpd_keyval *keyval, int capacity) |
|
|
|
int rpd_keyval_init(rpd_keyval *keyval, int capacity) |
|
|
|
{ |
|
|
|
{ |
|
|
|
keyval->size = keyval->capacity = 0; |
|
|
|
keyval->size = keyval->capacity = 0; |
|
|
|
|
|
|
|
keyval->unique = 1; |
|
|
|
|
|
|
|
|
|
|
|
if (capacity == 0) { |
|
|
|
if (capacity == 0) { |
|
|
|
keyval->items = NULL; |
|
|
|
keyval->items = NULL; |
|
|
@ -45,7 +46,7 @@ int rpd_keyval_insert(rpd_keyval *keyval, const char *key, const char *value) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rpd_keyval_item *item = rpd_keyval_find(keyval, key); |
|
|
|
rpd_keyval_item *item = rpd_keyval_find(keyval, key); |
|
|
|
if (item) { |
|
|
|
if (item && keyval->unique) { |
|
|
|
free(item->key); |
|
|
|
free(item->key); |
|
|
|
item->key = NULL; |
|
|
|
item->key = NULL; |
|
|
|
if (item->val) { |
|
|
|
if (item->val) { |
|
|
@ -75,6 +76,36 @@ rpd_keyval_item *rpd_keyval_find(const rpd_keyval *keyval, const char *key) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rpd_keyval_item **rpd_keyval_findall(const rpd_keyval *keyval, const char *key) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int i = 0, n = 0; |
|
|
|
|
|
|
|
rpd_keyval_item **items = NULL; |
|
|
|
|
|
|
|
while (i < keyval->size) { |
|
|
|
|
|
|
|
if (!strcmp(keyval->items[i].key, key)) { |
|
|
|
|
|
|
|
n++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!n) |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items = malloc(sizeof(rpd_keyval_item *) * (n + 1)); |
|
|
|
|
|
|
|
if (!items) |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items[n] = NULL; |
|
|
|
|
|
|
|
i = 0, n = 0; |
|
|
|
|
|
|
|
while (i < keyval->size) { |
|
|
|
|
|
|
|
if (!strcmp(keyval->items[i].key, key)) { |
|
|
|
|
|
|
|
items[n] = keyval->items + i; |
|
|
|
|
|
|
|
n++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return items; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rpd_keyval_cleanup(rpd_keyval *keyval) |
|
|
|
void rpd_keyval_cleanup(rpd_keyval *keyval) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (keyval->items) { |
|
|
|
if (keyval->items) { |
|
|
|