Index: pbx/pbx_dundi.c =================================================================== --- pbx/pbx_dundi.c (revision 334005) +++ pbx/pbx_dundi.c (working copy) @@ -2884,6 +2884,145 @@ #undef FORMAT2 } +static char *dundi_show_cache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ +#define FORMAT2 "%-12.12s %-16.16s %-10.10s %-18s %-7s %s\n" +#define FORMAT "%-12.12s %-16.16s %6d sec %-18s %-7d %s/%s (%s)\n" + struct ast_db_entry *db_tree, *db_entry; + int cnt = 0; + time_t ts, now; + dundi_eid src_eid; + char src_eid_str[20]; + int expiry, tech, weight; + struct ast_flags flags; + char fs[256]; + int length; + char *ptr, *term, *src, *number, *context, *dst; + + switch (cmd) { + case CLI_INIT: + e->command = "dundi show cache"; + e->usage = "Usage: dundi show cache\n" + " Lists all DUNDi cache entries.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc != 3) + return CLI_SHOWUSAGE; + + time(&now); + db_tree = ast_db_gettree("dundi/cache", NULL); + db_entry = db_tree; + ast_cli(a->fd, FORMAT2, "Number", "Context", "Expiration", "From", "Weight", "Destination (Flags)"); + while(db_entry) { + if (!ast_get_time_t(db_entry->data, &ts, 0, &length)) { + expiry = ts - now; + if (expiry > 0) { + ptr = db_entry->key + sizeof("/dundi/cache/"); + ptr = strchr(ptr, '/') + 1; + number = ptr; + ptr = strchr(ptr, '/'); + *ptr = '\0'; + context = ++ptr; + ptr = strchr(ptr, '/'); + *ptr = '\0'; + ptr++; + if (*ptr == 'e') { + ptr = db_entry->data + length + 1; + if ((sscanf(ptr, "%30d/%30d/%30d/%n", &(flags.flags), &weight, &tech, &length) == 3)) { + cnt++; + ptr += length; + dst = ptr; + term = strchr(ptr, '|'); + if (term) { + *term = '\0'; + src = strrchr(ptr, '/'); + dundi_eid_zero(&src_eid); + if (src) { + *src = '\0'; + src++; + dundi_str_short_to_eid(&src_eid, src); + ast_eid_to_str(src_eid_str, sizeof(src_eid_str), &src_eid); + } + ast_cli(a->fd, FORMAT, number, context, expiry, src_eid_str, weight, tech2str(tech), dst, dundi_flags2str(fs, sizeof(fs), flags.flags)); + } + } + } + } + } + db_entry = db_entry->next; + } + ast_cli(a->fd, "Number of entries: %d\n", cnt); + ast_db_freetree(db_tree); + + return CLI_SUCCESS; +#undef FORMAT +#undef FORMAT2 +} + +static char *dundi_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ +#define FORMAT2 "%-12.12s %-16.16s %-10.10s %-18s\n" +#define FORMAT "%-12.12s %-16.16s %6d sec %-18s\n" + struct ast_db_entry *db_tree, *db_entry; + int cnt = 0; + time_t ts, now; + dundi_eid src_eid; + char src_eid_str[20]; + int expiry; + int length; + char *ptr, *src, *number, *context; + + switch (cmd) { + case CLI_INIT: + e->command = "dundi show hints"; + e->usage = "Usage: dundi show hints\n" + " Lists all DUNDi 'DONTASK' hints in the cache.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc != 3) + return CLI_SHOWUSAGE; + + time(&now); + db_tree = ast_db_gettree("dundi/cache/hint", NULL); + db_entry = db_tree; + ast_cli(a->fd, FORMAT2, "Prefix", "Context", "Expiration", "From"); + while(db_entry) { + if (!ast_get_time_t(db_entry->data, &ts, 0, &length)) { + expiry = ts - now; + if (expiry > 0) { + ptr = db_entry->key + sizeof("/dundi/cache/hint/"); + src = ptr; + ptr = strchr(ptr, '/'); + *ptr = '\0'; + number = ++ptr; + ptr = strchr(ptr, '/'); + *ptr = '\0'; + context = ++ptr; + ptr = strchr(ptr, '/'); + *ptr = '\0'; + ptr++; + if (*ptr == 'e') { + cnt++; + dundi_str_short_to_eid(&src_eid, src); + ast_eid_to_str(src_eid_str, sizeof(src_eid_str), &src_eid); + ast_cli(a->fd, FORMAT, number, context, expiry, src_eid_str); + } + } + } + db_entry = db_entry->next; + } + ast_cli(a->fd, "Number of entries: %d\n", cnt); + ast_db_freetree(db_tree); + + return CLI_SUCCESS; +#undef FORMAT +#undef FORMAT2 +} + static struct ast_cli_entry cli_dundi[] = { AST_CLI_DEFINE(dundi_set_debug, "Enable/Disable DUNDi debugging"), AST_CLI_DEFINE(dundi_store_history, "Enable/Disable DUNDi historic records"), @@ -2895,6 +3034,8 @@ AST_CLI_DEFINE(dundi_show_precache, "Show DUNDi precache"), AST_CLI_DEFINE(dundi_show_requests, "Show DUNDi requests"), AST_CLI_DEFINE(dundi_show_peer, "Show info on a specific DUNDi peer"), + AST_CLI_DEFINE(dundi_show_cache, "Show DUNDi cache"), + AST_CLI_DEFINE(dundi_show_hints, "Show DUNDi hints in the cache"), AST_CLI_DEFINE(dundi_do_precache, "Precache a number in DUNDi"), AST_CLI_DEFINE(dundi_do_lookup, "Lookup a number in DUNDi"), AST_CLI_DEFINE(dundi_do_query, "Query a DUNDi EID"),