/src/opensips/cachedb/cachedb_dict.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Doubly-linked list implementation of a dictionary |
3 | | * |
4 | | * Copyright (C) 2018 OpenSIPS Solutions |
5 | | * |
6 | | * This file is part of opensips, a free SIP server. |
7 | | * |
8 | | * opensips is free software; you can redistribute it and/or modify |
9 | | * it under the terms of the GNU General Public License as published by |
10 | | * the Free Software Foundation; either version 2 of the License, or |
11 | | * (at your option) any later version |
12 | | * |
13 | | * opensips is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU General Public License |
19 | | * along with this program; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA |
21 | | */ |
22 | | |
23 | | #ifndef __CACHEDB_DICT_H__ |
24 | | #define __CACHEDB_DICT_H__ |
25 | | |
26 | | struct cdb_key; |
27 | | struct cdb_val; |
28 | | struct cdb_pair; |
29 | | |
30 | | #include "../lib/list.h" |
31 | | |
32 | | typedef struct list_head cdb_dict_t; /* list of cdb_pair_t */ |
33 | | |
34 | | static inline void cdb_dict_init(cdb_dict_t *dict) |
35 | 0 | { |
36 | 0 | INIT_LIST_HEAD(dict); |
37 | 0 | } Unexecuted instantiation: core_cmds.c:cdb_dict_init Unexecuted instantiation: cachedb.c:cdb_dict_init |
38 | | |
39 | | int cdb_dict_add_str(cdb_dict_t *dest, const char *key, int key_len, |
40 | | const str *val); |
41 | | #define CDB_DICT_ADD_STR(dest, key, val) \ |
42 | | cdb_dict_add_str(dest, key, strlen(key), val) |
43 | | |
44 | | int cdb_dict_add_int32(cdb_dict_t *dest, const char *key, int key_len, |
45 | | uint32_t v); |
46 | | #define CDB_DICT_ADD_INT32(dest, key, val) \ |
47 | | cdb_dict_add_int32(dest, key, strlen(key), val) |
48 | | |
49 | | int cdb_dict_add_int64(cdb_dict_t *dest, const char *key, int key_len, |
50 | | uint64_t v); |
51 | | #define CDB_DICT_ADD_INT64(dest, key, val) \ |
52 | | cdb_dict_add_int64(dest, key, strlen(key), val) |
53 | | |
54 | | int cdb_dict_add_null(cdb_dict_t *dest, const char *key, int key_len); |
55 | | #define CDB_DICT_ADD_NULL(dest, key) \ |
56 | | cdb_dict_add_null(dest, key, strlen(key)) |
57 | | |
58 | | void cdb_dict_add(struct cdb_pair *pair, cdb_dict_t *dict); |
59 | | void cdb_free_entries(cdb_dict_t *dict, void (*free_val_str) (void *val)); |
60 | | |
61 | | struct cdb_pair *cdb_dict_fetch(const struct cdb_key *key, |
62 | | const cdb_dict_t *dict); |
63 | | int cdb_dict_has_pair(const cdb_dict_t *haystack, const struct cdb_pair *pair); |
64 | | int cdb_dict_has_subkeys(const cdb_dict_t *dict); |
65 | | struct cdb_pair *nth_pair(const cdb_dict_t *dict, int nth); |
66 | | char *cdb_dict_to_json(const cdb_dict_t *dict, |
67 | | unsigned int (*escape)(char *dst, const str *src), |
68 | | unsigned int (*calc_escaped_len)(str *in)); |
69 | | int cdb_json_to_dict(const char *json, cdb_dict_t *out, |
70 | | void (*unescape)(char *inout)); |
71 | | int dict_cmp(const cdb_dict_t *a, const cdb_dict_t *b); |
72 | | int val_cmp(const struct cdb_val *v1, const struct cdb_val *v2); |
73 | | |
74 | | |
75 | | static inline int cdb_dict_empty(cdb_dict_t *dict) |
76 | 0 | { |
77 | 0 | return list_empty(dict); |
78 | 0 | } Unexecuted instantiation: core_cmds.c:cdb_dict_empty Unexecuted instantiation: cachedb.c:cdb_dict_empty |
79 | | |
80 | | #define dbg_cdb_dict(_pre_text, _dict_ptr) \ |
81 | | do { \ |
82 | | if (is_printable(L_DBG)) \ |
83 | | _dbg_cdb_dict(_pre_text, _dict_ptr); \ |
84 | | } while (0) |
85 | | void _dbg_cdb_dict(const char *pre_txt, const cdb_dict_t *dict); |
86 | | |
87 | | #endif /* __CACHEDB_DICT_H__ */ |