int mutt_hcache_delete(header_cache_t *h, const char *filename, size_t(*keylen) (const char *fn)) { char path[_POSIX_PATH_MAX]; int ksize; if (!h) return -1; strncpy(path, h->folder, sizeof (path)); safe_strcat(path, sizeof (path), filename); ksize = strlen(h->folder) + keylen(path + strlen(h->folder)); return tcbdbout(h->db, path, ksize); }
/* out */ JNIEXPORT jboolean JNICALL Java_tokyocabinet_BDB_out (JNIEnv *env, jobject self, jbyteArray key){ if(!key){ throwillarg(env); return false; } TCBDB *bdb = (TCBDB *)(intptr_t)(*env)->GetLongField(env, self, bdb_fid_ptr); jboolean ick; jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick); if(!kbuf){ throwoutmem(env); return false; } int ksiz = (*env)->GetArrayLength(env, key); bool rv = tcbdbout(bdb, kbuf, ksiz); (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT); return rv; }
int db_delete(void *vhandle, const dbv_t *token) { int ret; dbh_t *handle = vhandle; TCBDB *dbp; dbp = handle->dbp; ret = tcbdbout(dbp, token->data, token->leng); if (ret == 0) { print_error(__FILE__, __LINE__, "(tc) tcbdbout('%.*s'), err: %d, %s", CLAMP_INT_MAX(token->leng), (char *)token->data, tcbdbecode(dbp), tcbdberrmsg(tcbdbecode(dbp))); exit(EX_ERROR); } ret = ret ^ 1; /* ok is 1 in qdbm and 0 in bogofilter */ return ret; /* 0 if ok */ }
/* perform out command */ static int procout(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode) { TCBDB *bdb = tcbdbnew(); if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd); if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb); if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb); if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) { printerr(bdb); tcbdbdel(bdb); return 1; } bool err = false; if (!tcbdbout(bdb, kbuf, ksiz)) { printerr(bdb); err = true; } if (!tcbdbclose(bdb)) { if (!err) printerr(bdb); err = true; } tcbdbdel(bdb); return err ? 1 : 0; }
/* Synchronize updating contents on memory of a word database object. */ bool tcwdbmemsync(TCWDB *wdb, int level){ assert(wdb); if(!wdb->open || !wdb->cc){ tcbdbsetecode(wdb->idx, TCEINVALID, __FILE__, __LINE__, __func__); return false; } bool err = false; bool (*synccb)(int, int, const char *, void *) = wdb->synccb; void *syncopq = wdb->syncopq; bool (*addcb)(const char *, void *) = wdb->addcb; void *addopq = wdb->addopq; TCBDB *idx = wdb->idx; TCMAP *cc = wdb->cc; if(synccb && !synccb(0, 0, "started", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); return false; } if(tcmaprnum(cc) > 0){ if(synccb && !synccb(0, 0, "getting tokens", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); return false; } int kn; const char **keys = tcmapkeys2(cc, &kn); if(synccb && !synccb(kn, 0, "sorting tokens", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); tcfree(keys); return false; } qsort(keys, kn, sizeof(*keys), (int(*)(const void *, const void *))tccmpwords); for(int i = 0; i < kn; i++){ if(synccb && !synccb(kn, i + 1, "storing tokens", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); tcfree(keys); return false; } const char *kbuf = keys[i]; int ksiz = strlen(kbuf); int vsiz; const char *vbuf = tcmapget(cc, kbuf, ksiz, &vsiz); if(!tcbdbputcat(idx, kbuf, ksiz, vbuf, vsiz)) err = true; } if(addcb){ if(synccb && !synccb(0, 0, "storing keyword list", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); tcfree(keys); return false; } for(int i = 0; i < kn; i++){ if(!addcb(keys[i], addopq)){ tcfree(keys); return false; } } } tcfree(keys); tcmapclear(cc); } TCMAP *dtokens = wdb->dtokens; TCIDSET *dids = wdb->dids; if(tcmaprnum(dtokens) > 0){ if(synccb && !synccb(0, 0, "getting deleted tokens", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); return false; } int kn; const char **keys = tcmapkeys2(dtokens, &kn); if(synccb && !synccb(kn, 0, "sorting deleted tokens", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); tcfree(keys); return false; } qsort(keys, kn, sizeof(*keys), (int(*)(const void *, const void *))tccmpwords); for(int i = 0; i < kn; i++){ if(synccb && !synccb(kn, i + 1, "storing deleted tokens", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); tcfree(keys); return false; } const char *kbuf = keys[i]; int ksiz = strlen(kbuf); int vsiz; const char *vbuf = tcbdbget3(idx, kbuf, ksiz, &vsiz); if(!vbuf) continue; char *nbuf = tcmalloc(vsiz + 1); char *wp = nbuf; const char *pv; while(vsiz > 0){ pv = vbuf; int step; uint64_t id; TDREADVNUMBUF64(vbuf, id, step); vbuf += step; vsiz -= step; if(!tcidsetcheck(dids, id)){ int len = vbuf - pv; memcpy(wp, pv, len); wp += len; } } int nsiz = wp - nbuf; if(nsiz > 0){ if(!tcbdbput(idx, kbuf, ksiz, nbuf, nsiz)) err = true; } else { if(!tcbdbout(idx, kbuf, ksiz)) err = true; } tcfree(nbuf); } tcfree(keys); tcmapclear(dtokens); tcidsetclear(dids); } if(level > 0){ if(synccb && !synccb(0, 0, "synchronizing database", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); return false; } if(!tcbdbmemsync(idx, level > 1)) err = true; } if(synccb && !synccb(0, 0, "finished", syncopq)){ tcbdbsetecode(wdb->idx, TCEMISC, __FILE__, __LINE__, __func__); return false; } return !err; }