14 return (
SdbKv *)((
char *)kv + ht->opt.elem_size);
17 #define BUCKET_FOREACH(ht, bt, j, kv) \
18 for ((j) = 0, (kv) = (SdbKv *)(bt)->arr; j < (bt)->count; (j)++, (kv) = next_kv(ht, kv))
20 #define BUCKET_FOREACH_SAFE(ht, bt, j, count, kv) \
22 for ((j) = 0, (kv) = (SdbKv *)(bt)->arr, (count) = (ht)->count; \
24 (j) = (count) == (ht)->count ? j + 1 : j, (kv) = (count) == (ht)->count ? next_kv(ht, kv) : kv, (count) = (ht)->count)
60 int plen = strlen(
path);
61 int nlen = strlen(
name);
62 s->dir =
malloc(plen + nlen + 2);
87 s->last =
s->timestamped ?
sdb_now() : 0LL;
92 s->last =
s->timestamped ?
sdb_now() : 0LL;
150 if (
s->db.
fd != -1) {
156 if (
s->ht &&
s->ht->count > 0) {
166 if (
s->db.
fd != -1) {
207 if (
s &&
s->ht &&
s->refs) {
235 size_t keylen = strlen(
key);
243 if (
s->timestamped && kv->
expire) {
276 return s->db.map +
pos;
314 valen = strlen(
value);
316 while ((
p = strstr(
v,
value))) {
317 memmove(
p,
p + valen, strlen(
p + valen) + 1);
362 int klen = strlen(
key) + 1;
394 if (
file !=
s->dir) {
402 if ((S_IFREG & st.st_mode) != S_IFREG) {
403 eprintf(
"Database must be a file\n");
408 s->last = st.st_mtime;
419 if (
s->db.
fd != -1 &&
s->db.
fd ==
s->
fd) {
451 bool startsWith = *
expr ==
'^';
453 if (startsWith && endsWith) {
454 return strlen(
str) == strlen(
expr) - 2 &&
461 int alen = strlen(
str);
462 int blen = strlen(
expr) - 1;
466 const char *
a =
str + strlen(
str) - blen;
467 return (!strncmp(
a,
expr, blen));
476 const char *
eq = strchr(
expr,
'=');
499 kv->
base.key_len = kl;
506 kv->
base.value_len = vl;
509 if (!kv->
base.value) {
517 kv->
base.value_len = 0;
549 if (
s->journal != -1) {
556 if (cas && kv->
cas != cas) {
568 kv->
base.value_len = vlen;
572 if ((
ut32)vlen > kv->
base.value_len) {
577 kv->
base.value_len = vlen;
591 kv->
base.value_len = vlen;
657 if (!kv->
base.key || !kv->
base.value) {
697 SdbKv tkv = { .
base.key = (
char *)
k, .base.value = (
char *)
v };
748 if (!
cb(user,
k,
v)) {
769 for (
i = 0;
i <
s->ht->size; ++
i) {
770 HtPPBucket *bt = &
s->ht->table[
i];
816 for (
i = 0;
i <
s->ht->size; ++
i) {
817 HtPPBucket *bt = &
s->ht->table[
i];
837 s->pos =
sizeof(((
struct cdb_make *)0)->final);
849 if (
k < 1 ||
v < 1) {
878 ut32 vlen = 0, klen = 0;
889 if (klen < 1 || vlen < 1) {
923 const ut64 month = 30 * 24 * 60 * 60;
924 if (
e > 0 &&
e < month) {
935 s->timestamped =
true;
943 if (!cas || cas == kv->
cas) {
989 if (!(
i % 2) && (hook ==
cb)) {
996 s->hooks->free =
NULL;
1008 if (!(
i % 2) && (hook ==
h)) {
1023 if (
s->timestamped &&
s->last) {
1027 if (!(
i % 2) &&
k &&
iter->n) {
1028 void *u =
iter->n->data;
1121 static bool like_cb(
void *user,
const char *
k,
const char *
v) {
1134 int newsize = lcd->
array_size +
sizeof(
char *) * 2;
1135 const char **newarray = (
const char **)
realloc((
void *)lcd->
array, newsize);
1139 lcd->
array = newarray;
1178 return (
char **)lcd.
array;
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
bool cdb_init(struct cdb *c, int fd)
bool cdb_getkvlen(struct cdb *c, ut32 *klen, ut32 *vlen, ut32 pos)
void cdb_free(struct cdb *c)
bool cdb_read(struct cdb *c, char *buf, ut32 len, ut32 pos)
void cdb_findstart(struct cdb *c)
int cdb_findnext(struct cdb *c, ut32 u, const char *key, ut32 len)
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static fork const void static count close
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 count
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 fstat
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
RZ_API bool sdb_disk_insert(Sdb *s, const char *key, const char *val)
RZ_API bool sdb_disk_unlink(Sdb *s)
RZ_API bool sdb_disk_finish(Sdb *s)
RZ_API bool sdb_disk_create(Sdb *s)
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API const KEY_TYPE bool * found
RZ_API bool sdb_journal_open(Sdb *s)
RZ_API int sdb_journal_load(Sdb *s)
RZ_API bool sdb_journal_clear(Sdb *s)
RZ_API bool sdb_journal_log(Sdb *s, const char *key, const char *val)
RZ_API bool sdb_journal_close(Sdb *s)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
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
RZ_API void sdb_unlock(const char *s)
RZ_API bool sdb_lock(const char *s)
RZ_API int sdb_lock_wait(const char *s)
RZ_API const char * sdb_lock_file(const char *f)
RZ_API SdbList * ls_new(void)
RZ_API SdbListIter * ls_append(SdbList *list, void *data)
RZ_API void ls_free(SdbList *list)
RZ_API bool ls_sort(SdbList *list, SdbListComparator cmp)
RZ_API void ls_delete(SdbList *list, SdbListIter *iter)
RZ_API SdbList * ls_newf(SdbListFree freefn)
void(* SdbListFree)(void *ptr)
#define ls_foreach(list, it, pos)
RZ_API bool sdb_match(const char *str, const char *glob)
RZ_API void sdb_ns_free_all(Sdb *s)
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
RZ_API bool sdb_dump_dupnext(Sdb *s, char *key, char **value, int *_vlen)
RZ_API SdbKv * sdbkv_new2(const char *k, int kl, const char *v, int vl)
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
RZ_API void sdb_file(Sdb *s, const char *dir)
static bool sdb_merge_cb(void *user, const char *k, const char *v)
static int getbytes(Sdb *s, char *b, int len)
RZ_API bool sdb_dump_hasnext(Sdb *s)
static bool _insert_into_disk(void *user, const char *key, const char *value)
RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas)
static bool sdb_foreach_cdb(Sdb *s, SdbForeachCallback cb, SdbForeachCallback cb2, void *user)
RZ_API bool sdb_isempty(Sdb *s)
static bool copy_foreach_cb(void *user, const char *k, const char *v)
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32 cas)
static bool sdb_foreach_end(Sdb *s, bool result)
RZ_API void sdb_close(Sdb *s)
static bool match(const char *str, const char *expr)
RZ_API ut64 sdb_expire_get(Sdb *s, const char *key, ut32 *cas)
RZ_API void sdb_drain(Sdb *s, Sdb *f)
RZ_API Sdb * sdb_new0(void)
RZ_API int sdb_add(Sdb *s, const char *key, const char *val, ut32 cas)
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
RZ_API bool sdb_unhook(Sdb *s, SdbHook h)
RZ_API char ** sdb_like(Sdb *s, const char *k, const char *v, SdbForeachCallback cb)
RZ_API bool sdb_remove(Sdb *s, const char *key, ut32 cas)
RZ_API char * sdb_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas)
RZ_API SdbList * sdb_foreach_match(Sdb *s, const char *expr, bool single)
RZ_API bool sdb_merge(Sdb *d, Sdb *s)
RZ_API bool sdb_free(Sdb *s)
static bool unset_cb(void *user, const char *k, const char *v)
RZ_API int sdb_hook_call(Sdb *s, const char *k, const char *v)
static SdbKv * next_kv(HtPP *ht, SdbKv *kv)
RZ_API int sdb_count(Sdb *s)
RZ_API void sdb_reset(Sdb *s)
RZ_API SdbList * sdb_foreach_list_filter_user(Sdb *s, SdbForeachCallback filter, bool sorted, void *user)
RZ_API const char * sdb_const_get(Sdb *s, const char *key, ut32 *cas)
RZ_API void sdb_copy(Sdb *src, Sdb *dst)
static char lastChar(const char *str)
static void * global_user
RZ_API bool sdb_foreach(Sdb *s, SdbForeachCallback cb, void *user)
RZ_API bool sdb_stats(Sdb *s, ut32 *disk, ut32 *mem)
RZ_API bool sdb_unlink(Sdb *s)
RZ_API int sdb_uncat(Sdb *s, const char *key, const char *value, ut32 cas)
static bool sdb_foreach_list_filter_cb(void *user, const char *k, const char *v)
static bool sdb_foreach_match_cb(void *user, const char *k, const char *v)
RZ_API SdbList * sdb_foreach_list_filter(Sdb *s, SdbForeachCallback filter, bool sorted)
RZ_API int sdb_open(Sdb *s, const char *file)
static int __cmp_asc(const void *a, const void *b)
RZ_API int sdb_unset_like(Sdb *s, const char *k)
static SdbHook global_hook
RZ_API bool sdbkv_match(SdbKv *kv, const char *expr)
RZ_API int sdb_unset(Sdb *s, const char *key, ut32 cas)
RZ_API SdbList * sdb_foreach_list(Sdb *s, bool sorted)
static bool sdb_foreach_list_cb(void *user, const char *k, const char *v)
RZ_API void sdbkv_free(SdbKv *kv)
RZ_API void sdb_hook_free(Sdb *s)
static bool like_cb(void *user, const char *k, const char *v)
RZ_API int sdb_concat(Sdb *s, const char *key, const char *value, ut32 cas)
RZ_API void sdb_dump_begin(Sdb *s)
RZ_API bool sdb_hook(Sdb *s, SdbHook cb, void *user)
#define BUCKET_FOREACH_SAFE(ht, bt, j, count, kv)
RZ_API bool sdb_expire_set(Sdb *s, const char *key, ut64 expire, ut32 cas)
static bool _remove_afer_insert(void *user, const char *k, const char *v)
static void sdb_fini(Sdb *s, int donull)
RZ_API void sdb_global_hook(SdbHook hook, void *user)
RZ_API const char * sdb_const_get_len(Sdb *s, const char *key, int *vlen, ut32 *cas)
RZ_API bool sdb_exists(Sdb *s, const char *key)
static ut64 parse_expire(ut64 e)
RZ_API bool sdb_sync(Sdb *s)
RZ_API void sdb_config(Sdb *s, int options)
RZ_API SdbKv * sdbkv_new(const char *k, const char *v)
bool(* SdbForeachCallback)(void *user, const char *k, const char *v)
RZ_API ut64 sdb_now(void)
#define SDB_OPTION_JOURNAL
#define SDB_CDB_MAX_VALUE
void(* SdbHook)(Sdb *s, void *user, const char *k, const char *v)
RZ_API ut32 sdb_hash(const char *key)
#define SDB_OPTION_NOSTAMP
static int seek_set(int fd, off_t pos)
RZ_API SdbKv * sdb_ht_find_kvp(HtPP *ht, const char *key, bool *found)
RZ_API HtPP * sdb_ht_new(void)
RZ_API void sdb_ht_free(HtPP *ht)
RZ_API bool sdb_ht_insert_kvp(HtPP *ht, SdbKv *kvp, bool update)
RZ_API bool sdb_ht_delete(HtPP *ht, const char *key)
static char * sdbkv_key(const SdbKv *kv)
static ut32 sdbkv_value_len(const SdbKv *kv)
static char * sdbkv_value(const SdbKv *kv)
SdbForeachCallback filter
static void lock(volatile int *lk)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()