# HG changeset patch # User Luke Mewburn # Date 1582849327 -39600 # Node ID c25dea477d6aa60c06b34c9b7ec726874a6fbdfd # Parent da5e5b9c962353db508d6cb8d39a570147ae35e5 dbg_dict_dump: dump to conffile if provided If conffile is provided, write to that file instead of the log. Inspired by similar behaviour of dbg_dict_dump_json. diff -r da5e5b9c9623 -r c25dea477d6a extensions/dbg_dict_dump/dbg_dict_dump.c --- a/extensions/dbg_dict_dump/dbg_dict_dump.c Fri Feb 28 11:05:24 2020 +1100 +++ b/extensions/dbg_dict_dump/dbg_dict_dump.c Fri Feb 28 11:22:07 2020 +1100 @@ -33,7 +33,12 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -/* This extension logs a dump of the global dictionary */ +/* + * Dump Diameter dictionary (using fd_dict_dump()) to a file or the log. + * + * If conffile is provided, write the dump to that file, + * otherwise write to log. + */ #include @@ -41,13 +46,33 @@ { TRACE_ENTRY("%p", conffile); + FILE * out = NULL; + if (conffile) { + LOG_N("Dictionary dump to file '%s'", conffile); + out = fopen(conffile, "w"); + if (NULL == out) { + LOG_E("Cannot open output file '%s' for writing", conffile); + return EINVAL; + } + } else { + LOG_N("Dictionary dump to log"); + } + char * tbuf = NULL; size_t tbuflen = 0; - LOG_N("Dumping dictionary information"); - LOG_N("%s", fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict)); + if (NULL == fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict)) { + LOG_E("Cannot dump dictionary"); + } else if (out) { + fprintf(out, "%s\n", tbuf); + } else { + LOG_N("%s", fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict)); + } free(tbuf); + if (out) { + fclose(out); + out = NULL; + } - LOG_N("Dictionary dumped"); - + LOG_N("Dictionary dump completed"); return 0; }