static int deleteBySpaceCB(void *user, const char *k, const char *v) { struct ctxDeleteCB *ctx = (struct ctxDeleteCB *) user; if (!strncmp (k, ctx->buf, strlen (ctx->buf))) { sdb_remove (ctx->anal->sdb_zigns, k, 0); } return 1; }
SDB_VISIBLE char *sdb_get (Sdb* s, const char *key, ut32 *cas) { char *buf; ut32 hash, pos, len, keylen; SdbKv *kv; ut64 now = 0LL; if (cas) *cas = 0; if (!s || !key) return NULL; keylen = strlen (key)+1; hash = sdb_hash (key, keylen); /* search in memory */ kv = (SdbKv*)ht_lookup (s->ht, hash); if (kv) { if (*kv->value) { if (kv->expire) { if (!now) now = sdb_now (); if (now > kv->expire) { sdb_remove (s, key, 0); return NULL; } } if (cas) *cas = kv->cas; return strdup (kv->value); // XXX too many mallocs } return NULL; } /* search in disk */ if (s->fd == -1) return NULL; cdb_findstart (&s->db); if (!cdb_findnext (&s->db, hash, key, keylen)) return NULL; len = cdb_datalen (&s->db); if (len == 0) return NULL; pos = cdb_datapos (&s->db); if (!(buf = malloc (len+1))) // XXX too many mallocs return NULL; cdb_read (&s->db, buf, len, pos); buf[len] = 0; return buf; }
R_API bool r_sign_delete(RAnal *a, const char *name) { struct ctxDeleteCB ctx; char k[R_SIGN_KEY_MAXSZ]; // Remove all zigns if (name[0] == '*') { if (a->zign_spaces.space_idx == -1) { sdb_reset (a->sdb_zigns); return true; } else { ctx.anal = a; serializeKey (a, a->zign_spaces.space_idx, "", ctx.buf); sdb_foreach (a->sdb_zigns, deleteBySpaceCB, &ctx); return true; } } // Remove specific zign serializeKey (a, a->zign_spaces.space_idx, name, k); return sdb_remove (a->sdb_zigns, k, 0); }
SDB_VISIBLE const char *sdb_getc (Sdb* s, const char *key, ut32 *cas) { ut32 hash, pos, len, keylen; SdbKv *kv; ut64 now = 0LL; if (cas) *cas = 0; if (!s||!key) return NULL; keylen = strlen (key)+1; hash = sdb_hash (key, keylen); /* search in memory */ kv = (SdbKv*)ht_lookup (s->ht, hash); if (kv) { if (*kv->value) { if (kv->expire) { if (!now) now = sdb_now (); if (now > kv->expire) { sdb_remove (s, key, 0); return NULL; } } if (cas) *cas = kv->cas; return kv->value; } return NULL; } /* search in disk */ if (s->fd == -1) return NULL; cdb_findstart (&s->db); if (!cdb_findnext (&s->db, hash, key, keylen)) return NULL; len = cdb_datalen (&s->db); if (len == 0) return NULL; pos = cdb_datapos (&s->db); return s->db.map+pos; }