7 /* dictionary manager, logging proxy
11 /* DICT *dict_debug(dict_handle)
14 /* DICT *DICT_DEBUG(dict_handle)
17 /* dict_debug() encapsulates the given dictionary object and returns
18 /* a proxy object that logs all access to the encapsulated object.
19 /* This is more convenient than having to add logging capability
20 /* to each individual dictionary access method.
22 /* DICT_DEBUG() is an unsafe macro that returns the original object if
23 /* the object's debugging flag is not set, and that otherwise encapsulates
24 /* the object with dict_debug(). This macro simplifies usage by avoiding
25 /* clumsy expressions. The macro evaluates its argument multiple times.
27 /* Fatal errors: out of memory.
31 /* The Secure Mailer license must be distributed with this software.
34 /* IBM T.J. Watson Research
36 /* Yorktown Heights, NY 10598, USA
39 /* System libraries. */
43 /* Utility library. */
49 /* Application-specific. */
52 DICT dict
; /* the proxy service */
53 DICT
*real_dict
; /* encapsulated object */
56 /* dict_debug_lookup - log lookup operation */
58 static const char *dict_debug_lookup(DICT
*dict
, const char *key
)
60 DICT_DEBUG
*dict_debug
= (DICT_DEBUG
*) dict
;
63 result
= dict_get(dict_debug
->real_dict
, key
);
64 msg_info("%s:%s lookup: \"%s\" = \"%s\"", dict
->type
, dict
->name
, key
,
65 result
? result
: dict_errno
? "try again" : "not_found");
69 /* dict_debug_update - log update operation */
71 static void dict_debug_update(DICT
*dict
, const char *key
, const char *value
)
73 DICT_DEBUG
*dict_debug
= (DICT_DEBUG
*) dict
;
75 msg_info("%s:%s update: \"%s\" = \"%s\"", dict
->type
, dict
->name
,
77 dict_put(dict_debug
->real_dict
, key
, value
);
80 /* dict_debug_delete - log delete operation */
82 static int dict_debug_delete(DICT
*dict
, const char *key
)
84 DICT_DEBUG
*dict_debug
= (DICT_DEBUG
*) dict
;
87 result
= dict_del(dict_debug
->real_dict
, key
);
88 msg_info("%s:%s delete: \"%s\" = \"%s\"", dict
->type
, dict
->name
, key
,
89 result
? "failed" : "success");
93 /* dict_debug_sequence - log sequence operation */
95 static int dict_debug_sequence(DICT
*dict
, int function
,
96 const char **key
, const char **value
)
98 DICT_DEBUG
*dict_debug
= (DICT_DEBUG
*) dict
;
101 result
= dict_seq(dict_debug
->real_dict
, function
, key
, value
);
103 msg_info("%s:%s sequence: \"%s\" = \"%s\"", dict
->type
, dict
->name
,
106 msg_info("%s:%s sequence: found EOF", dict
->type
, dict
->name
);
110 /* dict_debug_close - log operation */
112 static void dict_debug_close(DICT
*dict
)
114 DICT_DEBUG
*dict_debug
= (DICT_DEBUG
*) dict
;
116 dict_close(dict_debug
->real_dict
);
120 /* dict_debug - encapsulate dictionary object and install proxies */
122 DICT
*dict_debug(DICT
*real_dict
)
124 DICT_DEBUG
*dict_debug
;
126 dict_debug
= (DICT_DEBUG
*) dict_alloc(real_dict
->type
,
127 real_dict
->name
, sizeof(*dict_debug
));
128 dict_debug
->dict
.flags
= real_dict
->flags
; /* XXX not synchronized */
129 dict_debug
->dict
.lookup
= dict_debug_lookup
;
130 dict_debug
->dict
.update
= dict_debug_update
;
131 dict_debug
->dict
.delete = dict_debug_delete
;
132 dict_debug
->dict
.sequence
= dict_debug_sequence
;
133 dict_debug
->dict
.close
= dict_debug_close
;
134 dict_debug
->real_dict
= real_dict
;
135 return (&dict_debug
->dict
);