void hcache_del(struct hcache *cache, struct stat *st) { datum key; _hcache_validate_done(cache); key = _hcache_genkey(cache,st); gdbm_delete(cache->dbf,key); free(key.dptr); }
static void addrec_gdbm(void) { int klen, dlen; char *k, *d; datum key, data; klen = 1 + (rand() % 4); dlen = 1 + (rand() % 100); k = randbuf(klen); d = randbuf(dlen); key.dptr = k; key.dsize = klen+1; data.dptr = d; data.dsize = dlen+1; if (rand() % DELETE_PROB == 0) { gdbm_delete(gdbm, key); } else if (rand() % STORE_PROB == 0) { if (gdbm_store(gdbm, key, data, GDBM_REPLACE) != 0) { fatal("gdbm_store failed"); } } else { data = gdbm_fetch(gdbm, key); if (data.dptr) free(data.dptr); } free(k); free(d); }
int pa_database_unset(pa_database *db, const pa_datum *key) { datum gdbm_key; pa_assert(db); pa_assert(key); return gdbm_delete(MAKE_GDBM_FILE(db), *datum_to_gdbm(&gdbm_key, key)) != 0 ? -1 : 0; }
int dbm_delete (DBM *dbm, datum key) { int rc = gdbm_delete (dbm->file, key); if (rc) __gdbm_error_to_ndbm (dbm); return rc; }
/** cht_del: @pkey:The string of the key. Delete a message from database. */ void cht_del(gchar *pkey) { struct datum keys; g_return_if_fail (pkey != NULL); keys.dptr = pkey; keys.dptr = strlen (pkey); if (gdbm_delete (cht_file, keys)) dbg_print ("Failed to delete the chatlog entry."); }
/** Maze z databaze informace o souboru. * * Presahne-li pocet smazanych polozek MAX_DELETED_ITEMS, reorganizuje * databazi. * * Navratove hodnoty: * * - 1 vse OK. * - -1 chyba pri vytvareni klice k souboru * - -2 chyba pri zamykani/odemykani databaze * - -3 chyba pri praci s databazi * */ int DirectoryDatabase::DeleteFileInfo(string &name) { string key; datum keyd, datad; int ret; ret = File2Key(name.c_str(), key); if (ret != 1) return -1; keyd.dptr = (char *) key.c_str(); keyd.dsize = key.size(); // --- zacatek KRITICKE SEKCE --- if (LockDatabase() != 1) return -2; // otevreme databazi pro zapis db_file = gdbm_open((char *)db_name.c_str(), GDBM_BLOCK_SIZE, GDBM_WRITER, S_IRUSR | S_IWUSR, 0); if (db_file == 0) { #ifdef DD_DEBUG cout << getpid() << "DD::DFI open gdbm_errno = " << gdbm_errno << " ... " << gdbm_strerror(gdbm_errno) << endl; #endif UnlockDatabase(); return -3; } if (gdbm_delete(db_file, keyd) != 0) { #ifdef DD_DEBUG cout << getpid() << " - Informace o souboru " << name << " nelze z databaze odstranit." << endl; #endif gdbm_close(db_file); UnlockDatabase(); return -3; } else { num_of_deleted_items++; if (num_of_deleted_items >= MAX_DELETED_ITEMS) { // gdbm samo nezmensi velikost souboru databaze, je potreba ho // donutit pomoci gdbm_reorganize(), ktere by se nemelo volat moc // casto if (gdbm_reorganize(db_file) != 0) { #ifdef DD_DEBUG cout << getpid() << " - Nejspis se nepovedla reorganizace databaze ..." << endl; #endif } } }//else gdbm_close(db_file); if (UnlockDatabase() != 1) return -2; // --- konec KRITICKE SEKCE --- return 1; }
static void gdbmunsetfn(Param pm, UNUSED(int um)) { datum key; GDBM_FILE dbf; key.dptr = pm->node.nam; key.dsize = strlen(key.dptr) + 1; dbf = (GDBM_FILE)(pm->u.hash->tmpdata); (void)gdbm_delete(dbf, key); }
void sterg(void){ datum key, nextkey; key = gdbm_firstkey( bz ); while(key.dptr){ nextkey = gdbm_nextkey(bz, key); gdbm_delete(bz, key); key = nextkey; } gdbm_reorganize(bz); smsg("\n Am initializat dictionarul \n"); }
int gdbmobj_delete(struct gdbmobj *obj, const char *key, size_t keylen) { datum dkey; if (!obj->has_dbf) return (0); dkey.dptr=(char *)key; dkey.dsize=keylen; if (gdbm_delete(obj->dbf, dkey)) return (-1); return (0); }
int ldbm_delete( LDBM ldbm, Datum key ) { int rc; LDBM_WLOCK; rc = gdbm_delete( ldbm, key ); gdbm_sync( ldbm ); LDBM_WUNLOCK; return( rc ); }
static void gdbmhashsetfn(Param pm, HashTable ht) { int i; HashNode hn; GDBM_FILE dbf; datum key, content; if (!pm->u.hash || pm->u.hash == ht) return; if (!(dbf = (GDBM_FILE)(pm->u.hash->tmpdata))) return; key = gdbm_firstkey(dbf); while (key.dptr) { queue_signals(); (void)gdbm_delete(dbf, key); free(key.dptr); unqueue_signals(); key = gdbm_firstkey(dbf); } /* just deleted everything, clean up */ (void)gdbm_reorganize(dbf); if (!ht) return; for (i = 0; i < ht->hsize; i++) for (hn = ht->nodes[i]; hn; hn = hn->next) { struct value v; v.isarr = v.flags = v.start = 0; v.end = -1; v.arr = NULL; v.pm = (Param) hn; key.dptr = v.pm->node.nam; key.dsize = strlen(key.dptr) + 1; queue_signals(); content.dptr = getstrvalue(&v); content.dsize = strlen(content.dptr) + 1; (void)gdbm_store(dbf, key, content, GDBM_REPLACE); unqueue_signals(); } }
/** * Remove a bookmark from the DB, based on the page. */ int delete_bookmark_for_page(Page* page) { datum key; char* sectpage = (char*) malloc(strlen(page->name) + 3); sectpage[0] = '0' + page->sect; sectpage[1] = ':'; strcpy(sectpage + 2, page->name); sectpage[strlen(page->name) + 3] = '\0'; _datum(&key, sectpage); if (gdbm_delete(db, key)) return -1; return 0; }
/** * hcache_gdbm_delete - Implements HcacheOps::delete() */ static int hcache_gdbm_delete(void *ctx, const char *key, size_t keylen) { datum dkey; if (!ctx) return -1; GDBM_FILE db = ctx; dkey.dptr = (char *) key; dkey.dsize = keylen; return gdbm_delete(db, dkey); }
int mutt_hcache_delete(header_cache_t *h, const char *filename, size_t(*keylen) (const char *fn)) { datum key; char path[_POSIX_PATH_MAX]; if (!h) return -1; strncpy(path, h->folder, sizeof (path)); safe_strcat(path, sizeof (path), filename); key.dptr = path; key.dsize = strlen(h->folder) + keylen(path + strlen(h->folder)); return gdbm_delete(h->db, key); }
void stergc(const char *cv, const char *defno){ datum key, nextkey; int len_cv, i_defno; i_defno = atoi(defno); //aici prelucrez defno len_cv = strlen(cv); i_defno = i_defno + 1 + len_cv; //am obtinut key.dsize pe care-l caut key = gdbm_firstkey( bz ); while(key.dptr){ if(strcmp(key.dptr,cv) == 0 && key.dsize == i_defno){ gdbm_delete(bz, key); smsg("\nAm sters un cuvant \n"); } nextkey = gdbm_nextkey(bz, key); key = nextkey; } gdbm_reorganize(bz); }
int pa_database_clear(pa_database *db) { datum gdbm_key; pa_assert(db); gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db)); while (gdbm_key.dptr) { datum next; next = gdbm_nextkey(MAKE_GDBM_FILE(db), gdbm_key); gdbm_delete(MAKE_GDBM_FILE(db), gdbm_key); free(gdbm_key.dptr); gdbm_key = next; } return gdbm_reorganize(MAKE_GDBM_FILE(db)) == 0 ? 0 : -1; }
static int dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) { datum krec, drec; if (!PyArg_Parse(v, "s#", &krec.dptr, &krec.dsize) ) { PyErr_SetString(PyExc_TypeError, "gdbm mappings have string indices only"); return -1; } if (dp->di_dbm == NULL) { PyErr_SetString(DbmError, "GDBM object has already been closed"); return -1; } dp->di_size = -1; if (w == NULL) { if (gdbm_delete(dp->di_dbm, krec) < 0) { PyErr_SetString(PyExc_KeyError, PyString_AS_STRING((PyStringObject *)v)); return -1; } } else { if (!PyArg_Parse(w, "s#", &drec.dptr, &drec.dsize)) { PyErr_SetString(PyExc_TypeError, "gdbm mappings have string elements only"); return -1; } errno = 0; if (gdbm_store(dp->di_dbm, krec, drec, GDBM_REPLACE) < 0) { if (errno != 0) PyErr_SetFromErrno(DbmError); else PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno)); return -1; } } return 0; }
static int _gdbm_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key) { struct gdbm_descr *gd = db->db_descr; datum keydat; keydat.dptr = key->mu_dptr; keydat.dsize = key->mu_dsize; gdbm_errno = 0; if (gdbm_delete (gd->file, keydat)) { if (gdbm_errno == GDBM_ITEM_NOT_FOUND) return MU_ERR_NOENT; else { db->db_errno.n = gdbm_errno; return MU_ERR_FAILURE; } } return 0; }
static ClRcT cdbGDBMRecordDelete(ClDBHandleT dbHandle, /* Handle to the database */ ClDBKeyT dbKey, /* Handle to the key of the record being deleted */ ClUint32T keySize) /* Size of the key */ { ClRcT errorCode = CL_OK; GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle; ClInt32T returnCode = 0; datum key = {NULL, 0}; CL_FUNC_ENTER(); key.dsize = keySize; key.dptr = (ClCharT *)dbKey; returnCode = gdbm_delete(pGDBMHandle->gdbmInstance, key); if(0 != returnCode) { errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST); CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM delete failed")); CL_FUNC_EXIT(); return(errorCode); } pGDBMHandle->deleteRecCnt++; if( CL_GDBM_MAX_DEL_CNT <= pGDBMHandle->deleteRecCnt ) { returnCode = gdbm_reorganize(pGDBMHandle->gdbmInstance); if(0 != returnCode) { errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST); CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM reorganize failed")); CL_FUNC_EXIT(); return(errorCode); } pGDBMHandle->deleteRecCnt = 0; } CL_FUNC_EXIT(); return(CL_OK); }
int system_dbmdelete(int handle, M2_string key) { return gdbm_delete(gdbm_files[handle],todatum(key)); }
/* * execute the 'index' function */ int sblib_func_exec(int index, int param_count, slib_par_t *params, var_t *retval) { int success = 0; switch ( index ) { case 0: // handle <- GDBM_OPEN(file[, block_size, flags, mode]) { char *file; int bsize, flags, mode; success = mod_parstr_ptr(0, params, param_count, &file); success = mod_opt_parint(1, params, param_count, &bsize, 0); success = mod_opt_parint(2, params, param_count, &flags, GDBM_WRCREAT); success = mod_opt_parint(3, params, param_count, &mode, 0666); if ( success ) { int handle; handle = get_free_handle(); if ( handle >= 0 ) { table[handle].dbf = gdbm_open(file, bsize, flags, mode, NULL); success = (table[handle].dbf != NULL); if ( success ) v_setint(retval, handle); else v_setstr(retval, gdbm_strerror(gdbm_errno)); } else { success = 0; v_setstr(retval, "GDBM_OPEN: NO FREE HANDLES"); } } else v_setstr(retval, "GDBM_OPEN: argument error"); } break; case 1: // handle <- GDBM_STORE(handle, key, data [, flags]) { int handle, flags; char *key, *data; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); success = mod_parstr_ptr(2, params, param_count, &data); success = mod_opt_parint(3, params, param_count, &flags, GDBM_REPLACE); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key, dt_data; int r; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; dt_data.dptr = data; dt_data.dsize = strlen(data) + 1; r = gdbm_store(table[handle].dbf, dt_key, dt_data, flags); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_STORE: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_STORE: argument error"); } break; case 2: // data <- GDBM_FETCH(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key, dt_data; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; dt_data = gdbm_fetch(table[handle].dbf, dt_key); v_setstr(retval, (char *) dt_data.dptr); success = 1; } else { success = 0; v_setstr(retval, "GDBM_FETCH: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_FETCH: argument error"); } break; case 3: // status <- GDBM_DELETE(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; int r; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; r = gdbm_delete(table[handle].dbf, dt_key); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_DELETE: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_DELETE: argument error"); } break; case 4: // key <- GDBM_FIRSTKEY(handle) { int handle; success = mod_parint (0, params, param_count, &handle); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; dt_key = gdbm_firstkey(table[handle].dbf); v_setstr(retval, (char *) dt_key.dptr); success = 1; } else { success = 0; v_setstr(retval, "GDBM_FIRSTKEY: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_FIRSTKEY: argument error"); } break; case 5: // key <- GDBM_NEXTKEY(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; dt_key = gdbm_nextkey(table[handle].dbf, dt_key); v_setstr(retval, (char *) dt_key.dptr); success = 1; } else { success = 0; v_setstr(retval, "GDBM_NEXTKEY: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_NEXTKEY: argument error"); } break; case 6: // status <- GDBM_REORGANIZE(handle) { int handle; success = mod_parint (0, params, param_count, &handle); if ( success ) { if ( is_valid_handle(handle) ) { int r; r = gdbm_reorganize(table[handle].dbf); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_REORGANIZE: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_REORGANIZE: argument error"); } break; case 7: // status <- GDBM_EXISTS(handle, key) { int handle; char *key; success = mod_parint (0, params, param_count, &handle); success = mod_parstr_ptr(1, params, param_count, &key); if ( success ) { if ( is_valid_handle(handle) ) { datum dt_key; int r; dt_key.dptr = key; dt_key.dsize = strlen(key) + 1; r = gdbm_exists(table[handle].dbf, dt_key); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_EXISTS: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_EXISTS: argument error"); } break; case 8: // str <- GDBM_STRERROR() v_setstr(retval, gdbm_strerror(gdbm_errno)); break; case 9: // status <- GDBM_SETOPT(handle, option, value, size) { int handle, option, value, size; success = mod_parint (0, params, param_count, &handle); success = mod_parint (1, params, param_count, &option); success = mod_parint (2, params, param_count, &value); success = mod_parint (3, params, param_count, &size); if ( success ) { if ( is_valid_handle(handle) ) { int r; r = gdbm_setopt(table[handle].dbf, option, &value, size); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_SETOPT: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_SETOPT: argument error"); } break; case 10: // status <- GDBM_FDESC(handle) { int handle; success = mod_parint (0, params, param_count, &handle); if ( success ) { if ( is_valid_handle(handle) ) { int r; r = gdbm_fdesc(table[handle].dbf); v_setint(retval, r); success = 1; } else { success = 0; v_setstr(retval, "GDBM_FDESC: INVALID HANDLE"); } } else v_setstr(retval, "GDBM_FDESC: argument error"); } break; default: v_setstr(retval, "GDBM: function does not exist!"); } return success; }
/* * Find the named user in this modules database. Create the set * of attribute-value pairs to check and reply with for this user * from the database. The authentication code only needs to check * the password, the rest is done here. */ static int caching_authorize(void *instance, REQUEST *request) { rlm_caching_t *data = (rlm_caching_t *) instance; char key[MAX_STRING_LEN]; datum key_datum; datum data_datum; rlm_caching_data cache_data; VALUE_PAIR *reply_item; VALUE_PAIR *item; char *tmp; int len = 0; int delete_cache = 0; float hit_ratio = 0.0; /* quiet the compiler */ instance = instance; request = request; if (pairfind(request->packet->vps, PW_CACHE_NO_CACHING, 0) != NULL){ DEBUG("rlm_caching: Cache-No-Caching is set. Returning NOOP"); return RLM_MODULE_NOOP; } if (pairfind(request->packet->vps, PW_CACHE_DELETE_CACHE, 0) != NULL){ DEBUG("rlm_caching: Found Cache-Delete-Cache. Will delete record if found"); delete_cache = 1; } if (!radius_xlat(key,sizeof(key), data->key, request, NULL)){ radlog(L_ERR, "rlm_caching: xlat on key '%s' failed.",data->key); return RLM_MODULE_FAIL; } key_datum.dptr = key; key_datum.dsize = strlen(key); DEBUG("rlm_caching: Searching the database for key '%s'",key); pthread_mutex_lock(&data->mutex); data_datum = gdbm_fetch(data->gdbm, key_datum); pthread_mutex_unlock(&data->mutex); data->cache_queries++; if (data_datum.dptr != NULL){ DEBUG("rlm_caching: Key Found."); data->cache_hits++; hit_ratio = (float)data->cache_hits / data->cache_queries; hit_ratio *= 100.0; memcpy(&cache_data, data_datum.dptr, sizeof(rlm_caching_data)); free(data_datum.dptr); if (delete_cache == 0 && cache_data.creation + data->cache_ttl <= time(NULL)){ DEBUG("rlm_caching: Cache entry has expired"); DEBUG("rlm_caching: Cache Queries: %7d, Cache Hits: %7d, Hit Ratio: %.2f%%", data->cache_queries,data->cache_hits,hit_ratio); show_hit_ratio; delete_cache = 1; } if (delete_cache){ DEBUG("rlm_caching: Deleting record"); pthread_mutex_lock(&data->mutex); gdbm_delete(data->gdbm, key_datum); pthread_mutex_unlock(&data->mutex); return RLM_MODULE_NOOP; } tmp = cache_data.data; if (tmp){ pairfree(&request->reply->vps); while(tmp && len < cache_data.len){ reply_item = NULL; if (userparse(tmp, &reply_item) > 0 && reply_item != NULL) pairadd(&request->reply->vps, reply_item); len += (strlen(tmp) + 1); DEBUG("rlm_caching: VP='%s',VALUE='%s',lenth='%d',cache record length='%d'", reply_item->name,reply_item->vp_strvalue,reply_item->length,len); tmp = cache_data.data + len; } } else{ DEBUG("rlm_caching: No reply items found. Returning NOOP"); return RLM_MODULE_NOOP; } if (cache_data.auth_type){ DEBUG("rlm_caching: Adding Auth-Type '%s'",cache_data.auth_type); if ((item = pairfind(request->config_items, PW_AUTH_TYPE, 0)) == NULL){ item = pairmake("Auth-Type", cache_data.auth_type, T_OP_SET); pairadd(&request->config_items, item); } else{ strcmp(item->vp_strvalue, cache_data.auth_type); item->length = strlen(cache_data.auth_type); } } if (data->post_auth){ DEBUG("rlm_caching: Adding Post-Auth-Type '%s'",data->post_auth); if ((item = pairfind(request->config_items, PW_POST_AUTH_TYPE, 0)) == NULL){ item = pairmake("Post-Auth-Type", data->post_auth, T_OP_SET); pairadd(&request->config_items, item); } else{ strcmp(item->vp_strvalue, data->post_auth); item->length = strlen(data->post_auth); } } item = pairmake("Cache-No-Caching", "YES", T_OP_EQ); pairadd(&request->packet->vps, item); DEBUG("rlm_caching: Cache Queries: %7d, Cache Hits: %7d, Hit Ratio: %.2f%%", data->cache_queries,data->cache_hits,hit_ratio); show_hit_ratio; return RLM_MODULE_OK; } else{ DEBUG("rlm_caching: Could not find the requested key in the database."); DEBUG("rlm_caching: Cache Queries: %7d, Cache Hits: %7d, Hit Ratio: %.2f%%", data->cache_queries,data->cache_hits,hit_ratio); show_hit_ratio; } return RLM_MODULE_NOOP; }