Rizin
unix-like reverse engineering framework and cli tools
sdb.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: MIT
3 
4 #ifndef SDB_H
5 #define SDB_H
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include <rz_types.h>
12 #include "sdbht.h"
13 #include "ls.h"
14 #include "cdb.h"
15 #include "cdb_make.h"
16 
17 /* Key value sizes */
18 #define SDB_CDB_MIN_VALUE 1
19 #define SDB_CDB_MAX_VALUE CDB_MAX_VALUE
20 #define SDB_CDB_MIN_KEY 1
21 #define SDB_CDB_MAX_KEY CDB_MAX_KEY
22 
23 #if __WINDOWS__ && !__CYGWIN__
24 #include <fcntl.h>
25 #include <stdbool.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <io.h>
29 #define ftruncate _chsize
30 #ifndef _MSC_VER
31 extern __attribute__((dllimport)) void *__cdecl _aligned_malloc(size_t, size_t);
32 extern __attribute__((dllimport)) void __cdecl _aligned_free(void *memblock);
33 extern char *strdup(const char *);
34 #else
35 #include <process.h>
36 #include <malloc.h> // for _aligned_malloc
37 #endif
38 
39 //#define SDB_MODE 0
40 #define SDB_MODE _S_IWRITE | _S_IREAD
41 #else
42 #define SDB_MODE 0644
43 //#define SDB_MODE 0600
44 #endif
45 
46 //#define SDB_RS '\x1e'
47 #define SDB_RS ','
48 #define SDB_SS ","
49 #define SDB_MAX_PATH 256
50 #define SDB_NUM_BASE 16
51 #define SDB_NUM_BUFSZ 64
52 
53 #define SDB_OPTION_NONE 0
54 #define SDB_OPTION_ALL 0xff
55 #define SDB_OPTION_SYNC (1 << 0)
56 #define SDB_OPTION_NOSTAMP (1 << 1)
57 #define SDB_OPTION_FS (1 << 2)
58 #define SDB_OPTION_JOURNAL (1 << 3)
59 
60 #define SDB_LIST_UNSORTED 0
61 #define SDB_LIST_SORTED 1
62 
63 typedef struct sdb_t {
64  char *dir; // path+name
65  char *path;
66  char *name;
67  int fd;
68  int refs; // reference counter
69  int lock;
70  int journal;
71  struct cdb db;
72  struct cdb_make m;
73  HtPP *ht;
76  int fdump;
77  char *ndump;
79  ut64 last; // timestamp of last change
80  int options;
81  int ns_lock; // TODO: merge into options?
86 } Sdb;
87 
88 typedef struct sdb_ns_t {
89  char *name;
91  Sdb *sdb;
93 
94 RZ_API Sdb *sdb_new0(void);
95 RZ_API Sdb *sdb_new(const char *path, const char *file, int lock);
96 
97 RZ_API int sdb_open(Sdb *s, const char *file);
98 RZ_API void sdb_close(Sdb *s);
99 
100 RZ_API void sdb_config(Sdb *s, int options);
101 RZ_API bool sdb_free(Sdb *s);
102 RZ_API void sdb_file(Sdb *s, const char *dir);
103 RZ_API bool sdb_merge(Sdb *d, Sdb *s);
104 RZ_API int sdb_count(Sdb *s);
105 RZ_API void sdb_reset(Sdb *s);
107 RZ_API void sdb_drain(Sdb *, Sdb *);
108 
109 // Copy everything, including namespaces, from src to dst
110 RZ_API void sdb_copy(Sdb *src, Sdb *dst);
111 
112 RZ_API bool sdb_stats(Sdb *s, ut32 *disk, ut32 *mem);
114 
115 typedef bool (*SdbForeachCallback)(void *user, const char *k, const char *v);
116 RZ_API bool sdb_foreach(Sdb *s, SdbForeachCallback cb, void *user);
117 RZ_API SdbList *sdb_foreach_list(Sdb *s, bool sorted);
120 RZ_API SdbList *sdb_foreach_match(Sdb *s, const char *expr, bool sorted);
121 
122 RZ_API int sdb_query(Sdb *s, const char *cmd);
123 RZ_API int sdb_queryf(Sdb *s, const char *fmt, ...);
124 RZ_API int sdb_query_lines(Sdb *s, const char *cmd);
125 RZ_API char *sdb_querys(Sdb *s, char *buf, size_t len, const char *cmd);
126 RZ_API char *sdb_querysf(Sdb *s, char *buf, size_t buflen, const char *fmt, ...);
127 RZ_API int sdb_query_file(Sdb *s, const char *file);
128 RZ_API bool sdb_exists(Sdb *, const char *key);
129 RZ_API bool sdb_remove(Sdb *, const char *key, ut32 cas);
130 RZ_API int sdb_unset(Sdb *, const char *key, ut32 cas);
131 RZ_API int sdb_unset_like(Sdb *s, const char *k);
132 RZ_API char **sdb_like(Sdb *s, const char *k, const char *v, SdbForeachCallback cb);
133 
134 // diffing
135 typedef struct sdb_diff_t {
136  const SdbList *path;
137  const char *k;
138  const char *v; // if null, k is a namespace
139  bool add;
141 
142 // Format diff in a readable form into str. str, size and return are like in snprintf.
143 RZ_API int sdb_diff_format(char *str, int size, const SdbDiff *diff);
144 
145 typedef void (*SdbDiffCallback)(const SdbDiff *diff, void *user);
146 
147 // Returns true iff the contents of a and b are equal including contained namespaces
148 // If cb is non-null, it will be called subsequently with differences.
149 RZ_API bool sdb_diff(Sdb *a, Sdb *b, SdbDiffCallback cb, void *cb_user);
150 
151 // Gets a pointer to the value associated with `key`.
152 RZ_API char *sdb_get(Sdb *, const char *key, ut32 *cas);
153 
154 // Gets a pointer to the value associated with `key` and returns in `vlen` the
155 // length of the value string.
156 RZ_API char *sdb_get_len(Sdb *, const char *key, int *vlen, ut32 *cas);
157 
158 // Gets a const pointer to the value associated with `key`
159 RZ_API const char *sdb_const_get(Sdb *, const char *key, ut32 *cas);
160 
161 // Gets a const pointer to the value associated with `key` and returns in
162 // `vlen` the length of the value string.
163 RZ_API const char *sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas);
164 RZ_API int sdb_set(Sdb *, const char *key, const char *data, ut32 cas);
165 RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas);
166 RZ_API int sdb_concat(Sdb *s, const char *key, const char *value, ut32 cas);
167 RZ_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas);
168 RZ_API int sdb_add(Sdb *s, const char *key, const char *val, ut32 cas);
169 RZ_API bool sdb_sync(Sdb *);
170 RZ_API void sdbkv_free(SdbKv *kv);
171 
172 /* num.c */
173 RZ_API bool sdb_num_exists(Sdb *, const char *key);
174 RZ_API int sdb_num_base(const char *s);
175 RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas);
176 RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas);
177 RZ_API int sdb_num_add(Sdb *s, const char *key, ut64 v, ut32 cas);
178 RZ_API ut64 sdb_num_inc(Sdb *s, const char *key, ut64 n, ut32 cas);
179 RZ_API ut64 sdb_num_dec(Sdb *s, const char *key, ut64 n, ut32 cas);
180 RZ_API int sdb_num_min(Sdb *s, const char *key, ut64 v, ut32 cas);
181 RZ_API int sdb_num_max(Sdb *s, const char *key, ut64 v, ut32 cas);
182 
183 /* ptr */
184 RZ_API int sdb_ptr_set(Sdb *db, const char *key, void *p, ut32 cas);
185 RZ_API void *sdb_ptr_get(Sdb *db, const char *key, ut32 *cas);
186 
187 /* create db */
188 RZ_API bool sdb_disk_create(Sdb *s);
189 RZ_API bool sdb_disk_insert(Sdb *s, const char *key, const char *val);
190 RZ_API bool sdb_disk_finish(Sdb *s);
191 RZ_API bool sdb_disk_unlink(Sdb *s);
192 
193 /* plaintext sdb files */
194 RZ_API bool sdb_text_save_fd(Sdb *s, int fd, bool sort);
195 RZ_API bool sdb_text_save(Sdb *s, const char *file, bool sort);
196 RZ_API bool sdb_text_load_buf(Sdb *s, char *buf, size_t sz);
197 RZ_API bool sdb_text_load(Sdb *s, const char *file);
198 
199 /* iterate */
200 RZ_API void sdb_dump_begin(Sdb *s);
202 RZ_API bool sdb_dump_dupnext(Sdb *s, char *key, char **value, int *_vlen);
203 
204 /* journaling */
208 RZ_API bool sdb_journal_log(Sdb *s, const char *key, const char *val);
211 
212 /* numeric */
213 RZ_API char *sdb_itoa(ut64 n, char *s, int base);
214 RZ_API ut64 sdb_atoi(const char *s);
215 RZ_API const char *sdb_itoca(ut64 n);
216 
217 /* locking */
218 RZ_API bool sdb_lock(const char *s);
219 RZ_API const char *sdb_lock_file(const char *f);
220 RZ_API void sdb_unlock(const char *s);
221 RZ_API bool sdb_unlink(Sdb *s);
222 RZ_API int sdb_lock_wait(RZ_UNUSED const char *s);
223 
224 /* expiration */
225 RZ_API bool sdb_expire_set(Sdb *s, const char *key, ut64 expire, ut32 cas);
226 RZ_API ut64 sdb_expire_get(Sdb *s, const char *key, ut32 *cas);
227 RZ_API ut64 sdb_now(void);
229 RZ_API ut32 sdb_hash(const char *key);
230 RZ_API ut32 sdb_hash_len(const char *key, ut32 *len);
231 RZ_API ut8 sdb_hash_byte(const char *s);
232 
233 // namespace
234 RZ_API Sdb *sdb_ns(Sdb *s, const char *name, int create);
235 RZ_API Sdb *sdb_ns_path(Sdb *s, const char *path, int create);
237 RZ_API void sdb_ns_free_all(Sdb *s);
238 RZ_API void sdb_ns_lock(Sdb *s, int lock, int depth);
239 RZ_API void sdb_ns_sync(Sdb *s);
240 RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r);
241 RZ_API bool sdb_ns_unset(Sdb *s, const char *name, Sdb *r);
242 
243 // array
244 RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val, ut32 *cas);
245 RZ_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 val, ut32 *cas);
246 RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, ut32 cas);
247 RZ_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, ut32 cas);
248 RZ_API int sdb_array_set_num(Sdb *s, const char *key, int idx, ut64 val, ut32 cas);
249 RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val, ut32 cas);
250 RZ_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val, ut32 cas);
251 RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val, ut32 cas);
252 RZ_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 val, ut32 cas);
253 RZ_API char *sdb_array_get(Sdb *s, const char *key, int idx, ut32 *cas);
254 RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx, ut32 *cas);
255 RZ_API int sdb_array_get_idx(Sdb *s, const char *key, const char *val, ut32 cas); // agetv
256 RZ_API int sdb_array_insert(Sdb *s, const char *key, int idx, const char *val, ut32 cas);
257 RZ_API int sdb_array_insert_num(Sdb *s, const char *key, int idx, ut64 val, ut32 cas);
258 RZ_API int sdb_array_unset(Sdb *s, const char *key, int n, ut32 cas); // leaves empty bucket
259 RZ_API int sdb_array_delete(Sdb *s, const char *key, int n, ut32 cas);
260 RZ_API void sdb_array_sort(Sdb *s, const char *key, ut32 cas);
261 RZ_API void sdb_array_sort_num(Sdb *s, const char *key, ut32 cas);
262 // set
263 
264 // Adds string `val` at the end of array `key`.
265 RZ_API int sdb_array_add(Sdb *s, const char *key, const char *val, ut32 cas);
266 
267 // Adds number `val` at the end of array `key`.
268 RZ_API int sdb_array_add_num(Sdb *s, const char *key, ut64 val, ut32 cas);
269 
270 // Adds string `val` in the sorted array `key`.
271 RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 cas);
272 
273 // Adds number `val` in the sorted array `key`.
274 RZ_API int sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val, ut32 cas);
275 
276 // Removes the string `val` from the array `key`.
277 RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val, ut32 cas);
278 
279 // Removes the number `val` from the array `key`.
280 RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val, ut32 cas);
281 
282 // helpers
283 RZ_API char *sdb_anext(char *str, char **next);
284 RZ_API const char *sdb_const_anext(const char *str);
285 RZ_API int sdb_alen(const char *str);
286 RZ_API int sdb_alen_ignore_empty(const char *str);
287 RZ_API int sdb_array_size(Sdb *s, const char *key);
288 RZ_API int sdb_array_length(Sdb *s, const char *key);
289 
290 int sdb_array_list(Sdb *s, const char *key);
291 
292 // Adds the string `val` to the start of array `key`.
293 RZ_API bool sdb_array_push(Sdb *s, const char *key, const char *val, ut32 cas);
294 
295 // Returns the string at the start of array `key` or
296 // NULL if there are no elements.
297 RZ_API char *sdb_array_pop(Sdb *s, const char *key, ut32 *cas);
298 
299 // Adds the number `val` to the start of array `key`.
300 RZ_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num, ut32 cas);
301 
302 // Returns the number at the start of array `key`.
303 RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key, ut32 *cas);
304 
305 RZ_API char *sdb_array_pop_head(Sdb *s, const char *key, ut32 *cas);
306 RZ_API char *sdb_array_pop_tail(Sdb *s, const char *key, ut32 *cas);
307 
308 typedef void (*SdbHook)(Sdb *s, void *user, const char *k, const char *v);
309 
310 RZ_API void sdb_global_hook(SdbHook hook, void *user);
311 RZ_API bool sdb_hook(Sdb *s, SdbHook cb, void *user);
312 RZ_API bool sdb_unhook(Sdb *s, SdbHook h);
313 RZ_API int sdb_hook_call(Sdb *s, const char *k, const char *v);
314 RZ_API void sdb_hook_free(Sdb *s);
315 /* Util.c */
316 RZ_API int sdb_isnum(const char *s);
317 RZ_API bool sdb_isempty(Sdb *s);
318 
319 RZ_API const char *sdb_type(const char *k);
320 RZ_API bool sdb_match(const char *str, const char *glob);
321 RZ_API int sdb_bool_set(Sdb *db, const char *str, bool v, ut32 cas);
322 RZ_API bool sdb_bool_get(Sdb *db, const char *str, ut32 *cas);
323 
324 // base64
325 RZ_API ut8 *sdb_decode(const char *in, int *len);
326 RZ_API char *sdb_encode(const ut8 *bin, int len);
327 RZ_API void sdb_encode_raw(char *bout, const ut8 *bin, int len);
328 RZ_API int sdb_decode_raw(ut8 *bout, const char *bin, int len);
329 
330 // binfmt
331 RZ_API char *sdb_fmt(const char *fmt, ...) RZ_PRINTF_CHECK(1, 2);
332 RZ_API int sdb_fmt_init(void *p, const char *fmt);
333 RZ_API void sdb_fmt_free(void *p, const char *fmt);
334 RZ_API int sdb_fmt_tobin(const char *_str, const char *fmt, void *stru);
335 RZ_API char *sdb_fmt_tostr(void *stru, const char *fmt);
336 RZ_API char **sdb_fmt_array(const char *list);
338 
339 // raw array helpers
340 RZ_API char *sdb_array_compact(char *p);
341 RZ_API char *sdb_aslice(char *out, int from, int to);
342 #define sdb_aforeach(x, y) \
343  { \
344  char *next; \
345  if (y) \
346  for (x = y;;) { \
347  x = sdb_anext(x, &next);
348 #define sdb_aforeach_next(x) \
349  if (!next) \
350  break; \
351  *(next - 1) = ','; \
352  x = next; \
353  } \
354  }
355 
356 #ifdef __cplusplus
357 }
358 #endif
359 
360 #endif
size_t len
Definition: 6502dis.c:15
lzma_index * src
Definition: index.h:567
ut16 val
Definition: armass64_const.h:6
static RzBuffer * create(RzBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
Definition: bin_cgc.c:16
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167
static int value
Definition: cmd_api.c:93
#define RZ_API
#define r
Definition: crypto_rc6.c:12
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
uint32_t ut32
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
void * mem
Definition: libc.cpp:91
#define const
Definition: ansidecl.h:240
#define __attribute__(x)
Definition: ansidecl.h:266
static void list(RzEgg *egg)
Definition: rz-gg.c:52
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
char * dst
Definition: lz4.h:724
int n
Definition: mipsasm.c:19
int idx
Definition: setup.py:197
static RzSocket * s
Definition: rtr.c:28
#define RZ_UNUSED
Definition: rz_types.h:73
#define RZ_PRINTF_CHECK(fmt, dots)
Definition: rz_types.h:192
RZ_API bool sdb_array_prepend_num(Sdb *s, const char *key, ut64 val, ut32 cas)
Definition: array.c:537
RZ_API bool sdb_dump_dupnext(Sdb *s, char *key, char **value, int *_vlen)
Definition: sdb.c:877
RZ_API char * sdb_anext(char *str, char **next)
Definition: util.c:192
struct sdb_diff_t SdbDiff
RZ_API int sdb_array_length(Sdb *s, const char *key)
Definition: array.c:524
void(* SdbDiffCallback)(const SdbDiff *diff, void *user)
Definition: sdb.h:145
RZ_API void * sdb_ptr_get(Sdb *db, const char *key, ut32 *cas)
Definition: num.c:87
RZ_API ut8 * sdb_decode(const char *in, int *len)
Definition: base64.c:37
RZ_API void sdb_file(Sdb *s, const char *dir)
Definition: sdb.c:128
RZ_API int sdb_set(Sdb *, const char *key, const char *data, ut32 cas)
Definition: sdb.c:611
RZ_API char * sdb_fmt_tostr(void *stru, const char *fmt)
Definition: fmt.c:43
RZ_API bool sdb_array_append_num(Sdb *s, const char *key, ut64 val, ut32 cas)
Definition: array.c:338
RZ_API int sdb_array_size(Sdb *s, const char *key)
Definition: array.c:519
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API void sdb_ns_free_all(Sdb *s)
Definition: ns.c:74
RZ_API Sdb * sdb_ns_path(Sdb *s, const char *path, int create)
Definition: ns.c:213
RZ_API ut8 sdb_hash_byte(const char *s)
Definition: util.c:26
RZ_API bool sdb_disk_insert(Sdb *s, const char *key, const char *val)
Definition: disk.c:67
RZ_API char * sdb_array_get(Sdb *s, const char *key, int idx, ut32 *cas)
Definition: array.c:81
RZ_API Sdb * sdb_new(const char *path, const char *file, int lock)
Definition: sdb.c:47
RZ_API char * sdb_querys(Sdb *s, char *buf, size_t len, const char *cmd)
Definition: query.c:164
RZ_API int sdb_array_add_sorted_num(Sdb *s, const char *key, ut64 val, ut32 cas)
Definition: array.c:290
RZ_API int sdb_ptr_set(Sdb *db, const char *key, void *p, ut32 cas)
Definition: num.c:83
RZ_API bool sdb_dump_hasnext(Sdb *s)
Definition: sdb.c:844
RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas)
Definition: sdb.c:607
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186
RZ_API void sdb_unlock(const char *s)
Definition: lock.c:60
RZ_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:415
RZ_API bool sdb_isempty(Sdb *s)
Definition: sdb.c:148
RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key, ut32 *cas)
Definition: array.c:572
bool(* SdbForeachCallback)(void *user, const char *k, const char *v)
Definition: sdb.h:115
RZ_API ut64 sdb_now(void)
Definition: util.c:211
RZ_API int sdb_isnum(const char *s)
Definition: util.c:216
RZ_API int sdb_array_add_num(Sdb *s, const char *key, ut64 val, ut32 cas)
Definition: array.c:211
RZ_API int sdb_num_add(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:18
RZ_API bool sdb_bool_get(Sdb *db, const char *str, ut32 *cas)
Definition: num.c:76
RZ_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:231
RZ_API SdbKv * sdb_dump_next(Sdb *s)
RZ_API void sdb_close(Sdb *s)
Definition: sdb.c:416
RZ_API int sdb_array_unset(Sdb *s, const char *key, int n, ut32 cas)
Definition: array.c:308
RZ_API void sdb_drain(Sdb *, Sdb *)
Definition: sdb.c:1069
RZ_API ut64 sdb_expire_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:971
RZ_API bool sdb_journal_open(Sdb *s)
Definition: journal.c:23
RZ_API int sdb_array_insert_num(Sdb *s, const char *key, int idx, ut64 val, ut32 cas)
Definition: array.c:131
RZ_API bool sdb_array_prepend(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:543
RZ_API char * sdb_aslice(char *out, int from, int to)
Definition: util.c:116
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API int sdb_num_min(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:58
RZ_API int sdb_add(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:351
RZ_API bool sdb_unhook(Sdb *s, SdbHook h)
Definition: sdb.c:1003
RZ_API int sdb_alen(const char *str)
Definition: util.c:151
RZ_API char ** sdb_like(Sdb *s, const char *k, const char *v, SdbForeachCallback cb)
Definition: sdb.c:1155
RZ_API ut64 sdb_num_dec(Sdb *s, const char *key, ut64 n, ut32 cas)
Definition: num.c:43
RZ_API char * sdb_itoa(ut64 n, char *s, int base)
Definition: util.c:38
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
struct sdb_t Sdb
RZ_API void sdb_setup(Sdb *s, int options)
RZ_API void sdb_ns_lock(Sdb *s, int lock, int depth)
Definition: ns.c:6
RZ_API int sdb_array_get_idx(Sdb *s, const char *key, const char *val, ut32 cas)
RZ_API char ** sdb_fmt_array(const char *list)
Definition: fmt.c:209
RZ_API bool sdb_merge(Sdb *d, Sdb *s)
Definition: sdb.c:144
RZ_API void sdb_encode_raw(char *bout, const ut8 *bin, int len)
Definition: base64.c:10
RZ_API char * sdb_get(Sdb *, const char *key, ut32 *cas)
Definition: sdb.c:290
RZ_API char * sdb_querysf(Sdb *s, char *buf, size_t buflen, const char *fmt,...)
Definition: query.c:68
RZ_API bool sdb_text_save(Sdb *s, const char *file, bool sort)
Definition: text.c:199
RZ_API int sdb_unset(Sdb *, const char *key, ut32 cas)
Definition: sdb.c:294
RZ_API ut64 sdb_unow(void)
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RZ_API bool sdb_text_load(Sdb *s, const char *file)
Definition: text.c:405
RZ_API char * sdb_fmt(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API bool sdb_disk_unlink(Sdb *s)
Definition: disk.c:121
RZ_API int sdb_hook_call(Sdb *s, const char *k, const char *v)
Definition: sdb.c:1019
RZ_API int sdb_queryf(Sdb *s, const char *fmt,...)
Definition: query.c:57
RZ_API bool sdb_array_append(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:312
RZ_API bool sdb_num_exists(Sdb *, const char *key)
Definition: num.c:8
RZ_API int sdb_query(Sdb *s, const char *cmd)
Definition: query.c:785
RZ_API bool sdb_match(const char *str, const char *glob)
Definition: match.c:95
RZ_API int sdb_num_max(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:65
RZ_API int sdb_journal_load(Sdb *s)
Definition: journal.c:38
RZ_API void sdb_array_sort(Sdb *s, const char *key, ut32 cas)
Definition: array.c:635
RZ_API int sdb_count(Sdb *s)
Definition: sdb.c:163
RZ_API bool sdb_text_load_buf(Sdb *s, char *buf, size_t sz)
Definition: text.c:386
RZ_API int sdb_array_set(Sdb *s, const char *key, int idx, const char *val, ut32 cas)
Definition: array.c:342
RZ_API int sdb_decode_raw(ut8 *bout, const char *bin, int len)
Definition: base64.c:14
RZ_API int sdb_array_add(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:224
RZ_API bool sdb_array_push(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:533
RZ_API void sdb_reset(Sdb *s)
Definition: sdb.c:433
RZ_API const char * sdb_const_get(Sdb *, const char *key, ut32 *cas)
Definition: sdb.c:279
RZ_API bool sdb_lock(const char *s)
Definition: lock.c:29
RZ_API SdbList * sdb_foreach_list_filter_user(Sdb *s, SdbForeachCallback filter, bool sorted, void *user)
Definition: sdb.c:668
RZ_API char * sdb_array_compact(char *p)
Definition: util.c:99
RZ_API void sdb_copy(Sdb *src, Sdb *dst)
Definition: sdb.c:1084
RZ_API int sdb_lock_wait(RZ_UNUSED const char *s)
RZ_API bool sdb_foreach(Sdb *s, SdbForeachCallback cb, void *user)
Definition: sdb.c:758
RZ_API bool sdb_diff(Sdb *a, Sdb *b, SdbDiffCallback cb, void *cb_user)
Definition: diff.c:159
void(* SdbHook)(Sdb *s, void *user, const char *k, const char *v)
Definition: sdb.h:308
RZ_API bool sdb_stats(Sdb *s, ut32 *disk, ut32 *mem)
Definition: sdb.c:856
RZ_API bool sdb_unlink(Sdb *s)
Definition: sdb.c:1064
RZ_API bool sdb_journal_clear(Sdb *s)
Definition: journal.c:96
RZ_API const char * sdb_type(const char *k)
Definition: util.c:231
RZ_API int sdb_fmt_tobin(const char *_str, const char *fmt, void *stru)
Definition: fmt.c:84
RZ_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas)
Definition: sdb.c:304
RZ_API const char * sdb_const_anext(const char *str)
Definition: util.c:206
RZ_API int sdb_array_insert(Sdb *s, const char *key, int idx, const char *val, ut32 cas)
Definition: array.c:139
RZ_API void sdb_ns_init(Sdb *s)
RZ_API int sdb_alen_ignore_empty(const char *str)
Definition: util.c:167
RZ_API int sdb_bool_set(Sdb *db, const char *str, bool v, ut32 cas)
Definition: num.c:72
RZ_API char * sdb_array_pop(Sdb *s, const char *key, ut32 *cas)
Definition: array.c:589
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
RZ_API SdbList * sdb_foreach_list_filter(Sdb *s, SdbForeachCallback filter, bool sorted)
Definition: sdb.c:685
RZ_API bool sdb_disk_finish(Sdb *s)
Definition: disk.c:79
RZ_API char * sdb_array_pop_tail(Sdb *s, const char *key, ut32 *cas)
Definition: array.c:614
RZ_API int sdb_array_remove(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:436
RZ_API int sdb_open(Sdb *s, const char *file)
Definition: sdb.c:383
RZ_API bool sdb_remove(Sdb *, const char *key, ut32 cas)
Definition: sdb.c:299
RZ_API bool sdb_journal_log(Sdb *s, const char *key, const char *val)
Definition: journal.c:81
RZ_API int sdb_unset_like(Sdb *s, const char *k)
Definition: sdb.c:1106
RZ_API char * sdb_get_len(Sdb *, const char *key, int *vlen, ut32 *cas)
Definition: sdb.c:285
RZ_API bool sdb_exists(Sdb *, const char *key)
Definition: sdb.c:358
int sdb_array_list(Sdb *s, const char *key)
RZ_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val, ut32 cas)
Definition: array.c:394
RZ_API int sdb_array_delete(Sdb *s, const char *key, int n, ut32 cas)
Definition: array.c:456
RZ_API ut32 sdb_hash(const char *key)
Definition: util.c:22
RZ_API SdbList * sdb_foreach_list(Sdb *s, bool sorted)
Definition: sdb.c:630
RZ_API bool sdb_array_contains(Sdb *s, const char *key, const char *val, ut32 *cas)
Definition: array.c:497
RZ_API bool sdb_sync(Sdb *)
Definition: sdb.c:803
RZ_API char * sdb_encode(const ut8 *bin, int len)
Definition: base64.c:18
RZ_API void sdbkv_free(SdbKv *kv)
Definition: sdb.c:524
RZ_API void sdb_hook_free(Sdb *s)
Definition: sdb.c:1036
RZ_API bool sdb_journal_unlink(Sdb *s)
Definition: journal.c:103
RZ_API const char * sdb_lock_file(const char *f)
Definition: lock.c:14
RZ_API void sdb_array_sort_num(Sdb *s, const char *key, ut32 cas)
Definition: array.c:667
RZ_API int sdb_concat(Sdb *s, const char *key, const char *value, ut32 cas)
Definition: sdb.c:329
RZ_API bool sdb_text_save_fd(Sdb *s, int fd, bool sort)
Definition: text.c:189
RZ_API ut32 sdb_hash_len(const char *key, ut32 *len)
Definition: util.c:7
RZ_API int sdb_array_push_num(Sdb *s, const char *key, ut64 num, ut32 cas)
Definition: array.c:528
RZ_API void sdb_fmt_free(void *p, const char *fmt)
Definition: fmt.c:128
RZ_API bool sdb_journal_close(Sdb *s)
Definition: journal.c:13
RZ_API void sdb_dump_begin(Sdb *s)
Definition: sdb.c:835
RZ_API ut64 sdb_num_inc(Sdb *s, const char *key, ut64 n, ut32 cas)
Definition: num.c:32
RZ_API int sdb_array_set_num(Sdb *s, const char *key, int idx, ut64 val, ut32 cas)
Definition: array.c:204
RZ_API ut64 sdb_atoi(const char *s)
Definition: util.c:88
RZ_API bool sdb_hook(Sdb *s, SdbHook cb, void *user)
Definition: sdb.c:983
RZ_API int sdb_query_file(Sdb *s, const char *file)
Definition: query.c:856
RZ_API const char * sdb_itoca(ut64 n)
Definition: util.c:32
RZ_API ut64 * sdb_fmt_array_num(const char *list)
Definition: fmt.c:184
RZ_API bool sdb_expire_set(Sdb *s, const char *key, ut64 expire, ut32 cas)
Definition: sdb.c:930
RZ_API char RZ_API int sdb_fmt_init(void *p, const char *fmt)
Definition: fmt.c:151
RZ_API ut64 sdb_array_get_num(Sdb *s, const char *key, int idx, ut32 *cas)
Definition: array.c:63
RZ_API void sdb_ns_sync(Sdb *s)
Definition: ns.c:248
RZ_API void sdb_global_hook(SdbHook hook, void *user)
Definition: sdb.c:37
RZ_API const char * sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas)
Definition: sdb.c:220
RZ_API bool sdb_ns_unset(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:136
RZ_API bool sdb_disk_create(Sdb *s)
Definition: disk.c:17
RZ_API char * sdb_array_pop_head(Sdb *s, const char *key, ut32 *cas)
Definition: array.c:593
RZ_API int sdb_diff_format(char *str, int size, const SdbDiff *diff)
Definition: diff.c:6
RZ_API bool sdb_array_contains_num(Sdb *s, const char *key, ut64 val, ut32 *cas)
Definition: array.c:491
RZ_API int sdb_query_lines(Sdb *s, const char *cmd)
Definition: query.c:800
struct sdb_ns_t SdbNs
RZ_API SdbList * sdb_foreach_match(Sdb *s, const char *expr, bool sorted)
Definition: sdb.c:710
RZ_API int sdb_num_base(const char *s)
Definition: util.c:221
RZ_API void sdb_config(Sdb *s, int options)
Definition: sdb.c:1041
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
#define d(i)
Definition: sha256.c:44
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
Definition: malloc.c:26
Definition: cdb.h:20
Definition: gzappend.c:170
Definition: ls.h:22
Definition: z80asm.h:102
const char * k
Definition: sdb.h:137
const char * v
Definition: sdb.h:138
const SdbList * path
Definition: sdb.h:136
bool add
Definition: sdb.h:139
Definition: sdbht.h:14
Definition: sdb.h:88
char * name
Definition: sdb.h:89
Sdb * sdb
Definition: sdb.h:91
ut32 hash
Definition: sdb.h:90
Definition: sdb.h:63
SdbList * ns
Definition: sdb.h:82
char * path
Definition: sdb.h:65
int fdump
Definition: sdb.h:76
ut32 pos
Definition: sdb.h:75
struct cdb db
Definition: sdb.h:71
struct cdb_make m
Definition: sdb.h:72
int journal
Definition: sdb.h:70
int ns_lock
Definition: sdb.h:81
int fd
Definition: sdb.h:67
ut32 depth
Definition: sdb.h:84
SdbList * hooks
Definition: sdb.h:83
int options
Definition: sdb.h:80
ut64 expire
Definition: sdb.h:78
bool timestamped
Definition: sdb.h:85
char * dir
Definition: sdb.h:64
int refs
Definition: sdb.h:68
char * ndump
Definition: sdb.h:77
int lock
Definition: sdb.h:69
char * name
Definition: sdb.h:66
HtPP * ht
Definition: sdb.h:73
ut64 last
Definition: sdb.h:79
ut32 eod
Definition: sdb.h:74
ut64 buflen
Definition: core.c:76
#define bool
Definition: sysdefs.h:146
static void lock(volatile int *lk)
Definition: malloc.c:61
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
static const char * cb[]
Definition: z80_tab.h:176