From d1b8dcdf1f15201f149d757407ac9943c426be43 Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Fri, 18 Aug 2023 17:50:33 -0600 Subject: [PATCH] Add -s dump-xml mode --- apps/backend/backend_main.c | 13 +++++++++---- lib/clixon/clixon_options.h | 3 ++- lib/src/clixon_options.c | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index d3c0e7eb..7b144c3b 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -906,8 +906,8 @@ main(int argc, /* [Delete and] create running db */ if (xmldb_db_reset(h, "running") < 0) goto done; - case SM_NONE: /* Fall through * - * Load plugins and call plugin_init() */ + /* FALLTHRU */ + case SM_NONE: /* Load plugins and call plugin_init() */ if ((ret = startup_extraxml(h, NULL, cbret)) < 0) goto done; status = STARTUP_OK; @@ -940,8 +940,13 @@ main(int argc, if (ret2status(ret, &status) < 0) goto done; /* if status = STARTUP_INVALID, cbret contains info */ - break; - default:; + break; + case SM_DUMP_XML: + /* dump the tree */ + cxobj *xc = clicon_conf_xml(h); + ret = clixon_xml2file(stdout, xc, 0, 1, "", &fprintf, 0, 1); + goto ok; + default: break; } /* Quit after upgrade catch-all, running/startup quits in upgrade code */ diff --git a/lib/clixon/clixon_options.h b/lib/clixon/clixon_options.h index 529e782d..59428cf7 100644 --- a/lib/clixon/clixon_options.h +++ b/lib/clixon/clixon_options.h @@ -67,7 +67,8 @@ enum startup_mode_t{ SM_INIT, /* Initialize running state */ SM_RUNNING, /* Commit running db configuration into running state */ SM_STARTUP, /* Commit startup configuration into running state */ - SM_RUNNING_STARTUP /* First try running db, if it is empty try startup db */ + SM_RUNNING_STARTUP, /* First try running db, if it is empty try startup db */ + SM_DUMP_XML /* Dump XML configuration to stdout and exit */ }; /*! See clixon-config.yang type priv_mode (privileges mode) */ diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 5906d4d0..3e92c210 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -90,6 +90,7 @@ static const map_str2int startup_mode_map[] = { {"running", SM_RUNNING}, {"startup", SM_STARTUP}, {"running-startup", SM_RUNNING_STARTUP}, + {"dump-xml", SM_DUMP_XML}, {NULL, -1} };