void isc_symtab_destroy(isc_symtab_t **symtabp) { isc_symtab_t *symtab; unsigned int i; elt_t *elt, *nelt; REQUIRE(symtabp != NULL); symtab = *symtabp; REQUIRE(VALID_SYMTAB(symtab)); for (i = 0; i < symtab->size; i++) { for (elt = HEAD(symtab->table[i]); elt != NULL; elt = nelt) { nelt = NEXT(elt, link); if (symtab->undefine_action != NULL) (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); isc_mem_put(symtab->mctx, elt, sizeof(*elt)); } } isc_mem_put(symtab->mctx, symtab->table, symtab->size * sizeof(eltlist_t)); symtab->magic = 0; isc_mem_put(symtab->mctx, symtab, sizeof(*symtab)); *symtabp = NULL; }
isc_result_t isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type, isc_symvalue_t value, isc_symexists_t exists_policy) { unsigned int bucket; elt_t *elt; REQUIRE(VALID_SYMTAB(symtab)); REQUIRE(key != NULL); REQUIRE(type != 0); FIND(symtab, key, type, bucket, elt); if (exists_policy != isc_symexists_add && elt != NULL) { if (exists_policy == isc_symexists_reject) return (ISC_R_EXISTS); INSIST(exists_policy == isc_symexists_replace); UNLINK(symtab->table[bucket], elt, link); if (symtab->undefine_action != NULL) (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); } else { elt = (elt_t *)isc_mem_get(symtab->mctx, sizeof(*elt)); if (elt == NULL) return (ISC_R_NOMEMORY); ISC_LINK_INIT(elt, link); symtab->count++; } /* * Though the "key" can be const coming in, it is not stored as const * so that the calling program can easily have writable access to * it in its undefine_action function. In the event that it *was* * truly const coming in and then the caller modified it anyway ... * well, don't do that! */ DE_CONST(key, elt->key); elt->type = type; elt->value = value; /* * We prepend so that the most recent definition will be found. */ PREPEND(symtab->table[bucket], elt, link); if (symtab->count > symtab->maxload) grow_table(symtab); return (ISC_R_SUCCESS); }
isc_result_t isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type, isc_symvalue_t *value) { unsigned int bucket; elt_t *elt; REQUIRE(VALID_SYMTAB(symtab)); REQUIRE(key != NULL); FIND(symtab, key, type, bucket, elt); if (elt == NULL) return (ISC_R_NOTFOUND); if (value != NULL) *value = elt->value; return (ISC_R_SUCCESS); }
isc_result_t isc_symtab_undefine(isc_symtab_t *symtab, const char *key, unsigned int type) { unsigned int bucket; elt_t *elt; REQUIRE(VALID_SYMTAB(symtab)); REQUIRE(key != NULL); FIND(symtab, key, type, bucket, elt); if (elt == NULL) return (ISC_R_NOTFOUND); if (symtab->undefine_action != NULL) (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); UNLINK(symtab->table[bucket], elt, link); isc_mem_put(symtab->mctx, elt, sizeof(*elt)); return (ISC_R_SUCCESS); }
unsigned int isc_symtab_count(isc_symtab_t *symtab) { REQUIRE(VALID_SYMTAB(symtab)); return (symtab->count); }