Merge branch 'master' of https://github.com/clicon/clixon
This commit is contained in:
commit
241ae26e55
137 changed files with 1558 additions and 1405 deletions
|
|
@ -714,13 +714,13 @@ compare_dbs(clicon_handle h,
|
|||
astext = 0;
|
||||
if (clicon_rpc_get_config(h, NULL, "running", "/", NULL, &xc1) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xc1, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_get_config(h, NULL, "candidate", "/", NULL, &xc2) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xc2, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -884,7 +884,7 @@ save_config_file(clicon_handle h,
|
|||
clicon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */
|
||||
goto done;
|
||||
}
|
||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -992,7 +992,7 @@ cli_notification_cb(int s,
|
|||
}
|
||||
if (clicon_msg_decode(reply, NULL, NULL, &xt) < 0) /* XXX pass yang_spec */
|
||||
goto done;
|
||||
if ((xe = xpath_first(xt, "//event")) != NULL){
|
||||
if ((xe = xpath_first(xt, NULL, "//event")) != NULL){
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xe, x, -1)) != NULL) {
|
||||
switch (format){
|
||||
|
|
@ -1224,7 +1224,7 @@ cli_copy_config(clicon_handle h,
|
|||
/* Get from object configuration and store in x1 */
|
||||
if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cb), nsc, &x1) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(x1, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(x1, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1243,7 +1243,7 @@ cli_copy_config(clicon_handle h,
|
|||
xml_name_set(x2, "config");
|
||||
cprintf(cb, "/%s", keyname);
|
||||
|
||||
if ((x = xpath_first_nsc(x2, nsc, "%s", cbuf_get(cb))) == NULL){
|
||||
if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,10 +162,10 @@ cli_cligen(clicon_handle h)
|
|||
|
||||
int
|
||||
cli_parse_file(clicon_handle h,
|
||||
FILE *f,
|
||||
char *name, /* just for errs */
|
||||
parse_tree *pt,
|
||||
cvec *globals)
|
||||
FILE *f,
|
||||
char *name, /* just for errs */
|
||||
parse_tree *pt,
|
||||
cvec *globals)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ cli_susp_hook(clicon_handle h,
|
|||
return cligen_susp_hook(ch, fn);
|
||||
}
|
||||
int
|
||||
cli_interrupt_hook(clicon_handle h,
|
||||
cli_interrupt_hook(clicon_handle h,
|
||||
cligen_interrupt_cb_t *fn)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
|
|
@ -200,14 +200,16 @@ cli_nomatch(clicon_handle h)
|
|||
}
|
||||
|
||||
int
|
||||
cli_prompt_set(clicon_handle h, char *prompt)
|
||||
cli_prompt_set(clicon_handle h,
|
||||
char *prompt)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
return cligen_prompt_set(ch, prompt);
|
||||
}
|
||||
|
||||
int
|
||||
cli_logsyntax_set(clicon_handle h, int status)
|
||||
cli_logsyntax_set(clicon_handle h,
|
||||
int status)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
return cligen_logsyntax_set(ch, status);
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ static int
|
|||
cli_terminate(clicon_handle h)
|
||||
{
|
||||
yang_stmt *yspec;
|
||||
cvec *nsctx;
|
||||
cxobj *x;
|
||||
|
||||
clicon_rpc_close_session(h);
|
||||
|
|
@ -170,6 +171,8 @@ cli_terminate(clicon_handle h)
|
|||
yspec_free(yspec);
|
||||
if ((yspec = clicon_config_yang(h)) != NULL)
|
||||
yspec_free(yspec);
|
||||
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
|
||||
cvec_free(nsctx);
|
||||
if ((x = clicon_conf_xml(h)) != NULL)
|
||||
xml_free(x);
|
||||
cli_plugin_finish(h);
|
||||
|
|
@ -280,12 +283,12 @@ main(int argc, char **argv)
|
|||
int logdst = CLICON_LOG_STDERR;
|
||||
char *restarg = NULL; /* what remains after options */
|
||||
yang_stmt *yspec;
|
||||
yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */
|
||||
struct passwd *pw;
|
||||
char *str;
|
||||
int tabmode;
|
||||
char *dir;
|
||||
uint32_t id = 0;
|
||||
cvec *nsctx_global = NULL; /* Global namespace context */
|
||||
|
||||
/* Defaults */
|
||||
once = 0;
|
||||
|
|
@ -348,16 +351,13 @@ main(int argc, char **argv)
|
|||
|
||||
clicon_debug_init(debug, NULL);
|
||||
|
||||
/* Create top-level yang spec and store as option */
|
||||
if ((yspecfg = yspec_new()) == NULL)
|
||||
goto done;
|
||||
/* Find and read configfile */
|
||||
if (clicon_options_main(h, yspecfg) < 0){
|
||||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0){
|
||||
if (help)
|
||||
usage(h, argv[0]);
|
||||
return -1;
|
||||
}
|
||||
clicon_config_yang_set(h, yspecfg);
|
||||
|
||||
/* Now rest of options */
|
||||
opterr = 0;
|
||||
optind = 1;
|
||||
|
|
@ -513,6 +513,14 @@ main(int argc, char **argv)
|
|||
if (netconf_module_load(h) < 0)
|
||||
goto done;
|
||||
|
||||
/* Here all modules are loaded
|
||||
* Compute and set canonical namespace context
|
||||
*/
|
||||
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
|
||||
goto done;
|
||||
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
|
||||
goto done;
|
||||
|
||||
/* Create tree generated from dataspec. If no other trees exists, this is
|
||||
* the only one.
|
||||
* The following code creates the tree @datamodel
|
||||
|
|
@ -533,7 +541,7 @@ main(int argc, char **argv)
|
|||
cligen_tree_add(cli_cligen(h), treeref, pt);
|
||||
|
||||
if (printgen)
|
||||
cligen_print(stdout, pt, 1);
|
||||
cligen_print(stdout, pt, 1); /* pt_print */
|
||||
}
|
||||
|
||||
/* Initialize cli syntax */
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <dlfcn.h>
|
||||
#include <dirent.h>
|
||||
#include <libgen.h>
|
||||
|
|
@ -209,27 +208,29 @@ clixon_str2fn(char *name,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*! Append to syntax mode from file
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
|
||||
* @param[in] dir Name of dir, or NULL
|
||||
/*! Load a file containing syntax and append to specified modes, also load C plugin
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
|
||||
* @param[in] dir Name of dir, or NULL
|
||||
* @param[out] allpt Universal CLIgen parse tree: apply to all modes
|
||||
*/
|
||||
static int
|
||||
cli_load_syntax(clicon_handle h,
|
||||
const char *filename,
|
||||
const char *dir)
|
||||
cli_load_syntax_file(clicon_handle h,
|
||||
const char *filename,
|
||||
const char *dir,
|
||||
parse_tree *ptall)
|
||||
{
|
||||
void *handle = NULL; /* Handle to plugin .so module */
|
||||
char *mode = NULL; /* Name of syntax mode to append new syntax */
|
||||
parse_tree pt = {0,};
|
||||
int retval = -1;
|
||||
FILE *f;
|
||||
char filepath[MAXPATHLEN];
|
||||
cvec *cvv = NULL;
|
||||
char *prompt = NULL;
|
||||
char **vec = NULL;
|
||||
int i, nvec;
|
||||
char *plgnam;
|
||||
void *handle = NULL; /* Handle to plugin .so module */
|
||||
char *mode = NULL; /* Name of syntax mode to append new syntax */
|
||||
parse_tree pt = {0,};
|
||||
int retval = -1;
|
||||
FILE *f;
|
||||
char filepath[MAXPATHLEN];
|
||||
cvec *cvv = NULL;
|
||||
char *prompt = NULL;
|
||||
char **vec = NULL;
|
||||
int i, nvec;
|
||||
char *plgnam;
|
||||
clixon_plugin *cp;
|
||||
|
||||
if (dir)
|
||||
|
|
@ -253,10 +254,18 @@ cli_load_syntax(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
fclose(f);
|
||||
/* Get CLICON specific global variables */
|
||||
/* Get CLICON specific global variables:
|
||||
* CLICON_MODE: which mode(s) this syntax applies to
|
||||
* CLICON_PROMPT: Cli prompt in this mode
|
||||
* CLICON_PLUGIN: Name of C API plugin
|
||||
* Note: the base case is that it is:
|
||||
* (1) a single mode or
|
||||
* (2) "*" all modes or "m1:m2" - a list of modes
|
||||
* but for (2), prompt and plgnam may have unclear semantics
|
||||
*/
|
||||
mode = cvec_find_str(cvv, "CLICON_MODE");
|
||||
prompt = cvec_find_str(cvv, "CLICON_PROMPT");
|
||||
plgnam = cvec_find_str(cvv, "CLICON_PLUGIN");
|
||||
mode = cvec_find_str(cvv, "CLICON_MODE");
|
||||
|
||||
if (plgnam != NULL) { /* Find plugin for callback resolving */
|
||||
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
|
||||
|
|
@ -288,8 +297,19 @@ cli_load_syntax(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
}
|
||||
/* Find all modes in CLICON_MODE string: where to append the pt syntax tree */
|
||||
if ((vec = clicon_strsep(mode, ":", &nvec)) == NULL)
|
||||
goto done;
|
||||
|
||||
if (nvec == 1 && strcmp(vec[0], "*") == 0){
|
||||
/* Special case: Add this to all modes. Add to special "universal" syntax
|
||||
* and add to all syntaxes after all files have been loaded. At this point
|
||||
* all modes may not be known (not yet loaded)
|
||||
*/
|
||||
if (cligen_parsetree_merge(ptall, NULL, pt) < 0)
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < nvec; i++) {
|
||||
if (syntax_append(h,
|
||||
cli_syntax(h),
|
||||
|
|
@ -300,6 +320,7 @@ cli_load_syntax(clicon_handle h,
|
|||
if (prompt)
|
||||
cli_set_prompt(h, vec[i], prompt);
|
||||
}
|
||||
}
|
||||
|
||||
cligen_parsetree_free(pt, 1);
|
||||
retval = 0;
|
||||
|
|
@ -329,6 +350,7 @@ cli_syntax_load(clicon_handle h)
|
|||
cligen_susp_cb_t *fns = NULL;
|
||||
cligen_interrupt_cb_t *fni = NULL;
|
||||
clixon_plugin *cp;
|
||||
parse_tree ptall = {0,}; /* Universal CLIgen parse tree all modes */
|
||||
|
||||
/* Syntax already loaded. XXX should we re-load?? */
|
||||
if ((stx = cli_syntax(h)) != NULL)
|
||||
|
|
@ -347,30 +369,38 @@ cli_syntax_load(clicon_handle h)
|
|||
|
||||
cli_syntax_set(h, stx);
|
||||
|
||||
/* Load single specific clispec file */
|
||||
if (clispec_file){
|
||||
if (cli_load_syntax(h, clispec_file, NULL) < 0)
|
||||
if (cli_load_syntax_file(h, clispec_file, NULL, &ptall) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Load all clispec .cli files in directory */
|
||||
if (clispec_dir){
|
||||
/* load syntaxfiles */
|
||||
/* Get directory list of files */
|
||||
if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG)) < 0)
|
||||
goto done;
|
||||
/* Load the rest */
|
||||
/* Load the syntax parse trees into cli_syntax stx structure */
|
||||
for (i = 0; i < ndp; i++) {
|
||||
clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
|
||||
(int)strlen(dp[i].d_name)-4, dp[i].d_name);
|
||||
if (cli_load_syntax(h, dp[i].d_name, clispec_dir) < 0)
|
||||
if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, &ptall) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* Did we successfully load any syntax modes? */
|
||||
/* Were any syntax modes successfully loaded? If not, leave */
|
||||
if (stx->stx_nmodes <= 0) {
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
/* Parse syntax tree for all modes */
|
||||
|
||||
/* Go thorugh all modes and :
|
||||
* 1) Add the universal syntax
|
||||
* 2) add syntax tree (of those modes - "activate" syntax from stx to CLIgen)
|
||||
*/
|
||||
m = stx->stx_modes;
|
||||
do {
|
||||
if (cligen_parsetree_merge(&m->csm_pt, NULL, ptall) < 0)
|
||||
return -1;
|
||||
if (gen_parse_tree(h, m) != 0)
|
||||
goto done;
|
||||
m = NEXTQ(cli_syntaxmode_t *, m);
|
||||
|
|
@ -389,13 +419,13 @@ cli_syntax_load(clicon_handle h)
|
|||
|
||||
/* All good. We can now proudly return a new group */
|
||||
retval = 0;
|
||||
|
||||
done:
|
||||
if (retval != 0) {
|
||||
clixon_plugin_exit(h);
|
||||
cli_syntax_unload(h);
|
||||
cli_syntax_set(h, NULL);
|
||||
}
|
||||
cligen_parsetree_free(ptall, 1);
|
||||
if (dp)
|
||||
free(dp);
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ expand_dbvar(void *h,
|
|||
/* Get configuration */
|
||||
if (clicon_rpc_get_config(h, NULL, dbstr, xpath, nsc, &xt) < 0) /* XXX */
|
||||
goto done;
|
||||
if ((xe = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
if ((xe = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xe);
|
||||
goto ok;
|
||||
}
|
||||
|
|
@ -204,12 +204,12 @@ expand_dbvar(void *h,
|
|||
fprintf(stderr, "%s\n", reason);
|
||||
goto done;
|
||||
}
|
||||
if ((xcur = xpath_first_nsc(xt, nsc, "%s", xpath)) == NULL){
|
||||
if ((xcur = xpath_first(xt, nsc, "%s", xpath)) == NULL){
|
||||
clicon_err(OE_DB, 0, "xpath %s should return merged content", xpath);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (xpath_vec_nsc(xcur, nsc, "%s", &xvec, &xlen, xpathcur) < 0)
|
||||
if (xpath_vec(xcur, nsc, "%s", &xvec, &xlen, xpathcur) < 0)
|
||||
goto done;
|
||||
/* Loop for inserting into commands cvec.
|
||||
* Detect duplicates: for ordered-by system assume list is ordered, so you need
|
||||
|
|
@ -486,7 +486,7 @@ cli_show_config1(clicon_handle h,
|
|||
if (clicon_rpc_get(h, cbuf_get(cbxpath), nsc, CONTENT_ALL, -1, &xt) < 0)
|
||||
goto done;
|
||||
}
|
||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -634,12 +634,12 @@ show_conf_xpath(clicon_handle h,
|
|||
goto done;
|
||||
if (clicon_rpc_get_config(h, NULL, str, xpath, nsc, &xt) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (xpath_vec_nsc(xt, nsc, "%s", &xv, &xlen, xpath) < 0)
|
||||
if (xpath_vec(xt, nsc, "%s", &xv, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
for (i=0; i<xlen; i++)
|
||||
xml_print(stdout, xv[i]);
|
||||
|
|
@ -737,11 +737,11 @@ cli_show_auto1(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
|
||||
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error("Get configuration", xerr);
|
||||
goto done;
|
||||
}
|
||||
if ((xp = xpath_first_nsc(xt, nsc, "%s", xpath)) != NULL)
|
||||
if ((xp = xpath_first(xt, nsc, "%s", xpath)) != NULL)
|
||||
/* Print configuration according to format */
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue