7 /* attribute list manager
9 /* #include <nvtable.h>
15 /* /* private fields... */
19 /* NVTABLE *nvtable_create(size)
22 /* NVTABLE_INFO *nvtable_update(table, key, value)
27 /* char *nvtable_find(table, key)
31 /* NVTABLE_INFO *nvtable_locate(table, key)
35 /* void nvtable_delete(table, key)
39 /* void nvtable_free(table)
42 /* void nvtable_walk(table, action, ptr)
44 /* void (*action)(NVTABLE_INFO *, char *ptr);
47 /* NVTABLE_INFO **nvtable_list(table)
50 /* This module maintains one or more attribute lists. It provides a
51 /* more convenient interface than hash tables, although it uses the
52 /* same underlying implementation. Each attribute list entry consists
53 /* of a unique string-valued lookup key and a string value.
55 /* nvtable_create() creates a table of the specified size and returns a
56 /* pointer to the result.
58 /* nvtable_update() stores or updates a (key, value) pair in the specified
59 /* table and returns a pointer to the resulting entry. The key and the
62 /* nvtable_find() returns the value that was stored under the given key,
63 /* or a null pointer if it was not found. In order to distinguish
64 /* a null value from a non-existent value, use nvtable_locate().
66 /* nvtable_locate() returns a pointer to the entry that was stored
67 /* for the given key, or a null pointer if it was not found.
69 /* nvtable_delete() removes one entry that was stored under the given key.
71 /* nvtable_free() destroys a hash table, including contents.
73 /* nvtable_walk() invokes the action function for each table entry, with
74 /* a pointer to the entry as its argument. The ptr argument is passed
75 /* on to the action function.
77 /* nvtable_list() returns a null-terminated list of pointers to
78 /* all elements in the named table. The list should be passed to
81 /* A callback function should not modify the attribute list that is
82 /* specified to its caller.
84 /* The following conditions are reported and cause the program to
85 /* terminate immediately: memory allocation failure; an attempt
86 /* to delete a non-existent entry.
88 /* mymalloc(3) memory management wrapper
89 /* htable(3) hash table manager
93 /* The Secure Mailer license must be distributed with this software.
96 /* IBM T.J. Watson Research
98 /* Yorktown Heights, NY 10598, USA
103 #include <sys_defs.h>
105 /* Utility library. */
107 #include <mymalloc.h>
111 /* nvtable_update - update or enter (key, value) pair */
113 NVTABLE_INFO
*nvtable_update(NVTABLE
* table
, const char *key
, const char *value
)
117 if ((ht
= htable_locate(table
, key
)) != 0) {
120 ht
= htable_enter(table
, key
, (char *) 0);
122 ht
->value
= mystrdup(value
);