comparison extensions/dbg_dict_dump/dbg_dict_dump.c @ 1458:c25dea477d6a

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.
author Luke Mewburn <luke@mewburn.net>
date Fri, 28 Feb 2020 11:22:07 +1100
parents ad50ef2eddea
children
comparison
equal deleted inserted replaced
1457:da5e5b9c9623 1458:c25dea477d6a
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * 32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/ 34 *********************************************************************************************************/
35 35
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 */
37 42
38 #include <freeDiameter/extension.h> 43 #include <freeDiameter/extension.h>
39 44
40 static int dbg_dict_dump_entry(char * conffile) 45 static int dbg_dict_dump_entry(char * conffile)
41 { 46 {
42 TRACE_ENTRY("%p", conffile); 47 TRACE_ENTRY("%p", conffile);
43 48
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
44 char * tbuf = NULL; size_t tbuflen = 0; 61 char * tbuf = NULL; size_t tbuflen = 0;
45 LOG_N("Dumping dictionary information"); 62 if (NULL == fd_dict_dump(&tbuf, &tbuflen, NULL, fd_g_config->cnf_dict)) {
46 LOG_N("%s", 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 }
47 free(tbuf); 69 free(tbuf);
70 if (out) {
71 fclose(out);
72 out = NULL;
73 }
48 74
49 LOG_N("Dictionary dumped"); 75 LOG_N("Dictionary dump completed");
50
51 return 0; 76 return 0;
52 } 77 }
53 78
54 void fd_ext_fini(void) 79 void fd_ext_fini(void)
55 { 80 {
"Welcome to our mercurial repository"