#include <sys_defs.h>
#include <msg.h>
#include <mymalloc.h>
#include <dict.h>
typedef struct {
DICT dict;
DICT *real_dict;
} DICT_DEBUG;
static const char *dict_debug_lookup(DICT *dict, const char *key)
{
DICT_DEBUG *dict_debug = (DICT_DEBUG *) dict;
const char *result;
result = dict_get(dict_debug->real_dict, key);
msg_info("%s:%s lookup: \"%s\" = \"%s\"", dict->type, dict->name, key,
result ? result : dict_errno ? "try again" : "not_found");
return (result);
}
static void dict_debug_update(DICT *dict, const char *key, const char *value)
{
DICT_DEBUG *dict_debug = (DICT_DEBUG *) dict;
msg_info("%s:%s update: \"%s\" = \"%s\"", dict->type, dict->name,
key, value);
dict_put(dict_debug->real_dict, key, value);
}
static int dict_debug_delete(DICT *dict, const char *key)
{
DICT_DEBUG *dict_debug = (DICT_DEBUG *) dict;
int result;
result = dict_del(dict_debug->real_dict, key);
msg_info("%s:%s delete: \"%s\" = \"%s\"", dict->type, dict->name, key,
result ? "failed" : "success");
return (result);
}
static int dict_debug_sequence(DICT *dict, int function,
const char **key, const char **value)
{
DICT_DEBUG *dict_debug = (DICT_DEBUG *) dict;
int result;
result = dict_seq(dict_debug->real_dict, function, key, value);
if (result == 0)
msg_info("%s:%s sequence: \"%s\" = \"%s\"", dict->type, dict->name,
*key, *value);
else
msg_info("%s:%s sequence: found EOF", dict->type, dict->name);
return (result);
}
static void dict_debug_close(DICT *dict)
{
DICT_DEBUG *dict_debug = (DICT_DEBUG *) dict;
dict_close(dict_debug->real_dict);
dict_free(dict);
}
DICT *dict_debug(DICT *real_dict)
{
DICT_DEBUG *dict_debug;
dict_debug = (DICT_DEBUG *) dict_alloc(real_dict->type,
real_dict->name, sizeof(*dict_debug));
dict_debug->dict.flags = real_dict->flags;
dict_debug->dict.lookup = dict_debug_lookup;
dict_debug->dict.update = dict_debug_update;
dict_debug->dict.delete = dict_debug_delete;
dict_debug->dict.sequence = dict_debug_sequence;
dict_debug->dict.close = dict_debug_close;
dict_debug->real_dict = real_dict;
return (&dict_debug->dict);
}