Skip to content

Commit

Permalink
Remove unused sdb hook feature (#4478)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah authored May 7, 2024
1 parent f818ca4 commit 4594027
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
63 changes: 0 additions & 63 deletions librz/util/sdb/src/sdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ static void sdb_fini(Sdb *s, int donull) {
if (!s) {
return;
}
sdb_hook_free(s);
cdb_free(&s->db);
if (s->lock) {
sdb_unlock(sdb_lock_file(s->dir));
Expand Down Expand Up @@ -564,7 +563,6 @@ static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32
return 0;
}
if (vlen == sdbkv_value_len(kv) && !strcmp(sdbkv_value(kv), val)) {
sdb_hook_call(s, key, val);
return kv->cas;
}
kv->cas = cas = nextcas();
Expand All @@ -583,7 +581,6 @@ static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32
} else {
sdb_ht_delete(s->ht, key);
}
sdb_hook_call(s, key, val);
return cas;
}
// empty values are also stored
Expand All @@ -601,10 +598,8 @@ static ut32 sdb_set_internal(Sdb *s, const char *key, char *val, int owned, ut32
ut32 cas = kv->cas = nextcas();
sdb_ht_insert_kvp(s->ht, kv, true /*update*/);
free(kv);
sdb_hook_call(s, key, val);
return cas;
}
// kv set failed, no need to callback sdb_hook_call (s, key, val);
return 0;
}

Expand Down Expand Up @@ -977,64 +972,6 @@ RZ_API ut64 sdb_expire_get(Sdb *s, const char *key, ut32 *cas) {
return 0LL;
}

RZ_API bool sdb_hook(Sdb *s, SdbHook cb, void *user) {
int i = 0;
SdbHook hook;
SdbListIter *iter;
if (s->hooks) {
ls_foreach (s->hooks, iter, hook) {
if (!(i % 2) && (hook == cb)) {
return false;
}
i++;
}
} else {
s->hooks = ls_new();
s->hooks->free = NULL;
}
ls_append(s->hooks, (void *)cb);
ls_append(s->hooks, user);
return true;
}

RZ_API bool sdb_unhook(Sdb *s, SdbHook h) {
int i = 0;
SdbHook hook;
SdbListIter *iter, *iter2;
ls_foreach (s->hooks, iter, hook) {
if (!(i % 2) && (hook == h)) {
iter2 = iter->n;
ls_delete(s->hooks, iter);
ls_delete(s->hooks, iter2);
return true;
}
i++;
}
return false;
}

RZ_API int sdb_hook_call(Sdb *s, const char *k, const char *v) {
SdbListIter *iter;
SdbHook hook;
int i = 0;
if (s->timestamped && s->last) {
s->last = sdb_now();
}
ls_foreach (s->hooks, iter, hook) {
if (!(i % 2) && k && iter->n) {
void *u = iter->n->data;
hook(s, u, k, v);
}
i++;
}
return i >> 1;
}

RZ_API void sdb_hook_free(Sdb *s) {
ls_free(s->hooks);
s->hooks = NULL;
}

RZ_API void sdb_config(Sdb *s, int options) {
s->options = options;
if (options & SDB_OPTION_SYNC) {
Expand Down
7 changes: 0 additions & 7 deletions librz/util/sdb/src/sdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ typedef struct sdb_t {
int options;
int ns_lock; // TODO: merge into options?
SdbList *ns;
SdbList *hooks;
ut32 depth;
bool timestamped;
} Sdb;
Expand Down Expand Up @@ -297,12 +296,6 @@ RZ_API ut64 sdb_array_pop_num(Sdb *s, const char *key, ut32 *cas);
RZ_API char *sdb_array_pop_head(Sdb *s, const char *key, ut32 *cas);
RZ_API char *sdb_array_pop_tail(Sdb *s, const char *key, ut32 *cas);

typedef void (*SdbHook)(Sdb *s, void *user, const char *k, const char *v);

RZ_API bool sdb_hook(Sdb *s, SdbHook cb, void *user);
RZ_API bool sdb_unhook(Sdb *s, SdbHook h);
RZ_API int sdb_hook_call(Sdb *s, const char *k, const char *v);
RZ_API void sdb_hook_free(Sdb *s);
/* Util.c */
RZ_API int sdb_isnum(const char *s);
RZ_API bool sdb_isempty(Sdb *s);
Expand Down

0 comments on commit 4594027

Please sign in to comment.