Navigation


Changeset 1458:c25dea477d6a in freeDiameter for extensions


Ignore:
Timestamp:
Feb 28, 2020, 9:22:07 AM (4 years ago)
Author:
Luke Mewburn <luke@mewburn.net>
Branch:
default
Phase:
public
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_dict_dump/dbg_dict_dump.c

    r1436 r1458  
    3434*********************************************************************************************************/
    3535
    36 /* This extension logs a dump of the global dictionary */
     36/*
     37 * Dump Diameter dictionary (using fd_dict_dump()) to a file or the log.
     38 *
     39 * If conffile is provided, write the dump to that file,
     40 * otherwise write to log.
     41 */
    3742
    3843#include <freeDiameter/extension.h>
     
    4247        TRACE_ENTRY("%p", conffile);
    4348
     49        FILE * out = NULL;
     50        if (conffile) {
     51                LOG_N("Dictionary dump to file '%s'", conffile);
     52                out = fopen(conffile, "w");
     53                if (NULL == out) {
     54                        LOG_E("Cannot open output file '%s' for writing", conffile);
     55                        return EINVAL;
     56                }
     57        } else {
     58                LOG_N("Dictionary dump to log");
     59        }
     60
    4461        char * tbuf = NULL; size_t tbuflen = 0;
    45         LOG_N("Dumping dictionary information");
    46         LOG_N("%s", fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict));
     62        if (NULL == fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict)) {
     63                LOG_E("Cannot dump dictionary");
     64        } else if (out) {
     65                fprintf(out, "%s\n", tbuf);
     66        } else {
     67                LOG_N("%s", fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict));
     68        }
    4769        free(tbuf);
     70        if (out) {
     71                fclose(out);
     72                out = NULL;
     73        }
    4874
    49         LOG_N("Dictionary dumped");
    50 
     75        LOG_N("Dictionary dump completed");
    5176        return 0;
    5277}
Note: See TracChangeset for help on using the changeset viewer.