7 /* dictionary manager interface to hash tables
9 /* #include <dict_ht.h>
11 /* DICT *dict_ht_open(name, table, remove)
14 /* void (*remove)(char *value)
16 /* dict_ht_open() makes specified hash table accessible via the
17 /* generic dictionary operations documented in dict_open(3).
18 /* \fIremove\fR specifies an optional callback function
19 /* that is called by the hash table manager when the hash table is
20 /* removed from the dictionary manager's care. The hash table is not
21 /* destroyed when \fIremove\fR is a null pointer.
23 /* dict(3) generic dictionary manager
27 /* The Secure Mailer license must be distributed with this software.
30 /* IBM T.J. Watson Research
32 /* Yorktown Heights, NY 10598, USA
39 /* Utility library. */
46 /* Application-specific. */
49 DICT dict
; /* generic members */
50 HTABLE
*table
; /* hash table */
51 void (*remove
) (char *); /* callback */
54 /* dict_ht_lookup - find hash-table entry */
56 static const char *dict_ht_lookup(DICT
*dict
, const char *name
)
58 DICT_HT
*dict_ht
= (DICT_HT
*) dict
;
62 return (htable_find(dict_ht
->table
, name
));
65 /* dict_ht_update - add or update hash-table entry */
67 static void dict_ht_update(DICT
*dict
, const char *name
, const char *value
)
69 DICT_HT
*dict_ht
= (DICT_HT
*) dict
;
72 if ((ht
= htable_locate(dict_ht
->table
, name
)) != 0) {
75 ht
= htable_enter(dict_ht
->table
, name
, (char *) 0);
77 ht
->value
= mystrdup(value
);
80 /* dict_ht_close - disassociate from hash table */
82 static void dict_ht_close(DICT
*dict
)
84 DICT_HT
*dict_ht
= (DICT_HT
*) dict
;
87 htable_free(dict_ht
->table
, dict_ht
->remove
);
91 /* dict_ht_open - create association with hash table */
93 DICT
*dict_ht_open(const char *name
, HTABLE
*table
, void (*remove
) (char *))
97 dict_ht
= (DICT_HT
*) dict_alloc(DICT_TYPE_HT
, name
, sizeof(*dict_ht
));
98 dict_ht
->dict
.lookup
= dict_ht_lookup
;
99 dict_ht
->dict
.update
= dict_ht_update
;
100 dict_ht
->dict
.close
= dict_ht_close
;
101 dict_ht
->table
= table
;
102 dict_ht
->remove
= remove
;
103 return (&dict_ht
->dict
);