[Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)
* Applies to all c/h/y/l/sh files and .editorconfig
This commit is contained in:
parent
a9d1ab006c
commit
d84c529ff1
376 changed files with 38147 additions and 38133 deletions
|
|
@ -137,7 +137,7 @@ static const map_str2int yang_regexp_map[] = {
|
|||
*/
|
||||
int
|
||||
clicon_option_dump(clicon_handle h,
|
||||
int dbglevel)
|
||||
int dbglevel)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_hash_t *hash = clicon_options(h);
|
||||
|
|
@ -149,43 +149,43 @@ clicon_option_dump(clicon_handle h,
|
|||
cxobj *x = NULL;
|
||||
|
||||
if (clicon_hash_keys(hash, &keys, &klen) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
for(i = 0; i < klen; i++) {
|
||||
val = clicon_hash_value(hash, keys[i], &vlen);
|
||||
if (vlen){
|
||||
if (((char*)val)[vlen-1]=='\0') /* assume string */
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val);
|
||||
else
|
||||
clicon_debug(dbglevel, "%s =\t 0x%p , length %zu", keys[i], val, vlen);
|
||||
}
|
||||
else
|
||||
clicon_debug(dbglevel, "%s = NULL", keys[i]);
|
||||
val = clicon_hash_value(hash, keys[i], &vlen);
|
||||
if (vlen){
|
||||
if (((char*)val)[vlen-1]=='\0') /* assume string */
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val);
|
||||
else
|
||||
clicon_debug(dbglevel, "%s =\t 0x%p , length %zu", keys[i], val, vlen);
|
||||
}
|
||||
else
|
||||
clicon_debug(dbglevel, "%s = NULL", keys[i]);
|
||||
}
|
||||
/* Next print CLICON_FEATURE, CLICON_YANG_DIR and CLICON_SNMP_DIR from config tree
|
||||
* Since they are lists they are placed in the config tree.
|
||||
*/
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
}
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(x), "CLICON_FEATURE") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
if (strcmp(xml_name(x), "CLICON_FEATURE") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
}
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (keys)
|
||||
free(keys);
|
||||
free(keys);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -196,8 +196,8 @@ clicon_option_dump(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
parse_configfile_one(const char *filename,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xconfig)
|
||||
yang_stmt *yspec,
|
||||
cxobj **xconfig)
|
||||
{
|
||||
int retval = -1;
|
||||
FILE *fp = NULL;
|
||||
|
|
@ -208,49 +208,49 @@ parse_configfile_one(const char *filename,
|
|||
int ret;
|
||||
|
||||
if ((fp = fopen(filename, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "open configure file: %s", filename);
|
||||
return -1;
|
||||
clicon_err(OE_UNIX, errno, "open configure file: %s", filename);
|
||||
return -1;
|
||||
}
|
||||
clicon_debug(2, "%s: Reading config file %s", __FUNCTION__, filename);
|
||||
if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(xerr, cbret) < 0)
|
||||
goto done;
|
||||
/* Here one could make it more relaxing to not quit on unrecognized option? */
|
||||
clixon_netconf_error(xerr, NULL, NULL);
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(xerr, cbret) < 0)
|
||||
goto done;
|
||||
/* Here one could make it more relaxing to not quit on unrecognized option? */
|
||||
clixon_netconf_error(xerr, NULL, NULL);
|
||||
goto done;
|
||||
}
|
||||
/* Ensure a single root */
|
||||
if (xt == NULL || xml_child_nr(xt) != 1){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename);
|
||||
goto done;
|
||||
clicon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename);
|
||||
goto done;
|
||||
}
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Check well-formedness */
|
||||
if (strcmp(xml_name(xt), "clixon-config") != 0 ||
|
||||
(xa = xml_find_type(xt, NULL, "xmlns", CX_ATTR)) == NULL ||
|
||||
strcmp(xml_value(xa), CLIXON_CONF_NS) != 0){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: <clixon-config xmlns=\"%s\">", filename, CLIXON_CONF_NS);
|
||||
goto done;
|
||||
(xa = xml_find_type(xt, NULL, "xmlns", CX_ATTR)) == NULL ||
|
||||
strcmp(xml_value(xa), CLIXON_CONF_NS) != 0){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: <clixon-config xmlns=\"%s\">", filename, CLIXON_CONF_NS);
|
||||
goto done;
|
||||
}
|
||||
*xconfig = xt;
|
||||
xt = NULL;
|
||||
retval = 0;
|
||||
done:
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
xml_free(xt);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
fclose(fp);
|
||||
if (cbret)
|
||||
cbuf_free(cbret);
|
||||
cbuf_free(cbret);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
xml_free(xerr);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -266,10 +266,10 @@ parse_configfile_one(const char *filename,
|
|||
*/
|
||||
static int
|
||||
parse_configfile(clicon_handle h,
|
||||
const char *filename,
|
||||
char *extraconfdir0,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xconfig)
|
||||
const char *filename,
|
||||
char *extraconfdir0,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xconfig)
|
||||
{
|
||||
int retval = -1;
|
||||
struct stat st;
|
||||
|
|
@ -293,123 +293,123 @@ parse_configfile(clicon_handle h,
|
|||
DIR *dirp;
|
||||
|
||||
if (filename == NULL || !strlen(filename)){
|
||||
clicon_err(OE_UNIX, 0, "Not specified");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, 0, "Not specified");
|
||||
goto done;
|
||||
}
|
||||
if (stat(filename, &st) < 0){
|
||||
clicon_err(OE_UNIX, errno, "%s", filename);
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "%s", filename);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(st.st_mode)){
|
||||
clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
|
||||
goto done;
|
||||
}
|
||||
/* Parse main config file */
|
||||
if (parse_configfile_one(filename, yspec, &xt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* xt is a single-rooted: <clixon-config>...</clixon-config>
|
||||
* If no override (eg from command-line)
|
||||
* Bootstrap: Shortcut to read extra confdir inline */
|
||||
if ((extraconfdir = extraconfdir0) == NULL)
|
||||
if ((xc = xpath_first(xt, 0, "CLICON_CONFIGDIR")) != NULL)
|
||||
extraconfdir = xml_body(xc);
|
||||
if ((xc = xpath_first(xt, 0, "CLICON_CONFIGDIR")) != NULL)
|
||||
extraconfdir = xml_body(xc);
|
||||
if (extraconfdir){ /* If extra dir, parse extra config files */
|
||||
/* A check it exists (also done in clicon_file_dirent) */
|
||||
if ((dirp = opendir(extraconfdir)) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir);
|
||||
goto done;
|
||||
}
|
||||
closedir(dirp);
|
||||
if((ndp = clicon_file_dirent(extraconfdir, &dp, NULL, S_IFREG)) < 0) /* Read dir */
|
||||
goto done;
|
||||
/* Loop through files */
|
||||
for (i = 0; i < ndp; i++){
|
||||
snprintf(filename1, sizeof(filename1), "%s/%s", extraconfdir, dp[i].d_name);
|
||||
if (parse_configfile_one(filename1, yspec, &xe) < 0)
|
||||
goto done;
|
||||
/* Drain objects from extrafile and replace/append to main */
|
||||
while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) {
|
||||
name = xml_name(xec);
|
||||
body = xml_body(xec);
|
||||
/* Ignore non-leafs */
|
||||
if (name == NULL || body == NULL)
|
||||
continue;
|
||||
/* Ignored from file due to bootstrapping */
|
||||
if (strcmp(name,"CLICON_CONFIGFILE")==0)
|
||||
continue;
|
||||
/* List options for configure options that are lists or leaf-lists: append to main */
|
||||
if (strcmp(name,"CLICON_FEATURE")==0 ||
|
||||
strcmp(name,"CLICON_YANG_DIR")==0 ||
|
||||
strcmp(name,"CLICON_SNMP_MIB")==0){
|
||||
if (xml_addsub(xt, xec) < 0)
|
||||
goto done;
|
||||
continue;
|
||||
}
|
||||
/* Remove existing in master if any */
|
||||
if ((x = xml_find_type(xt, NULL, name, CX_ELMNT)) != NULL)
|
||||
xml_purge(x);
|
||||
/* Append to master (removed from xe) */
|
||||
if (xml_addsub(xt, xec) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (xe)
|
||||
xml_free(xe);
|
||||
xe = NULL;
|
||||
}
|
||||
/* A check it exists (also done in clicon_file_dirent) */
|
||||
if ((dirp = opendir(extraconfdir)) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir);
|
||||
goto done;
|
||||
}
|
||||
closedir(dirp);
|
||||
if((ndp = clicon_file_dirent(extraconfdir, &dp, NULL, S_IFREG)) < 0) /* Read dir */
|
||||
goto done;
|
||||
/* Loop through files */
|
||||
for (i = 0; i < ndp; i++){
|
||||
snprintf(filename1, sizeof(filename1), "%s/%s", extraconfdir, dp[i].d_name);
|
||||
if (parse_configfile_one(filename1, yspec, &xe) < 0)
|
||||
goto done;
|
||||
/* Drain objects from extrafile and replace/append to main */
|
||||
while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) {
|
||||
name = xml_name(xec);
|
||||
body = xml_body(xec);
|
||||
/* Ignore non-leafs */
|
||||
if (name == NULL || body == NULL)
|
||||
continue;
|
||||
/* Ignored from file due to bootstrapping */
|
||||
if (strcmp(name,"CLICON_CONFIGFILE")==0)
|
||||
continue;
|
||||
/* List options for configure options that are lists or leaf-lists: append to main */
|
||||
if (strcmp(name,"CLICON_FEATURE")==0 ||
|
||||
strcmp(name,"CLICON_YANG_DIR")==0 ||
|
||||
strcmp(name,"CLICON_SNMP_MIB")==0){
|
||||
if (xml_addsub(xt, xec) < 0)
|
||||
goto done;
|
||||
continue;
|
||||
}
|
||||
/* Remove existing in master if any */
|
||||
if ((x = xml_find_type(xt, NULL, name, CX_ELMNT)) != NULL)
|
||||
xml_purge(x);
|
||||
/* Append to master (removed from xe) */
|
||||
if (xml_addsub(xt, xec) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (xe)
|
||||
xml_free(xe);
|
||||
xe = NULL;
|
||||
}
|
||||
}
|
||||
if (xml_default_recurse(xt, 0) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((ret = xml_yang_validate_add(h, xt, &xerr)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(xerr, cbret) < 0)
|
||||
goto done;
|
||||
clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret));
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(xerr, cbret) < 0)
|
||||
goto done;
|
||||
clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret));
|
||||
goto done;
|
||||
}
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
|
||||
name = xml_name(x);
|
||||
body = xml_body(x);
|
||||
/* Ignore non-leafs */
|
||||
if (name == NULL || body == NULL)
|
||||
continue;
|
||||
/* Ignored from file due to bootstrapping */
|
||||
if (strcmp(name,"CLICON_CONFIGFILE")==0)
|
||||
continue;
|
||||
/* List options for configure options that are leaf-lists (not leaf)
|
||||
* They must be accessed directly by looping over clicon_conf_xml(h)
|
||||
*/
|
||||
if (strcmp(name,"CLICON_FEATURE")==0)
|
||||
continue;
|
||||
if (strcmp(name,"CLICON_YANG_DIR")==0)
|
||||
continue;
|
||||
if (strcmp(name,"CLICON_SNMP_MIB")==0)
|
||||
continue;
|
||||
if (clicon_hash_add(copt,
|
||||
name,
|
||||
body,
|
||||
strlen(body)+1) == NULL)
|
||||
goto done;
|
||||
name = xml_name(x);
|
||||
body = xml_body(x);
|
||||
/* Ignore non-leafs */
|
||||
if (name == NULL || body == NULL)
|
||||
continue;
|
||||
/* Ignored from file due to bootstrapping */
|
||||
if (strcmp(name,"CLICON_CONFIGFILE")==0)
|
||||
continue;
|
||||
/* List options for configure options that are leaf-lists (not leaf)
|
||||
* They must be accessed directly by looping over clicon_conf_xml(h)
|
||||
*/
|
||||
if (strcmp(name,"CLICON_FEATURE")==0)
|
||||
continue;
|
||||
if (strcmp(name,"CLICON_YANG_DIR")==0)
|
||||
continue;
|
||||
if (strcmp(name,"CLICON_SNMP_MIB")==0)
|
||||
continue;
|
||||
if (clicon_hash_add(copt,
|
||||
name,
|
||||
body,
|
||||
strlen(body)+1) == NULL)
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
*xconfig = xt;
|
||||
xt = NULL;
|
||||
done:
|
||||
if (dp)
|
||||
free(dp);
|
||||
free(dp);
|
||||
if (nsc)
|
||||
xml_nsctx_free(nsc);
|
||||
xml_nsctx_free(nsc);
|
||||
if (cbret)
|
||||
cbuf_free(cbret);
|
||||
cbuf_free(cbret);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
xml_free(xerr);
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
xml_free(xt);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -425,29 +425,29 @@ parse_configfile(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_add(clicon_handle h,
|
||||
const char *name,
|
||||
char *value)
|
||||
const char *name,
|
||||
char *value)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
cxobj *x;
|
||||
|
||||
if (strcmp(name, "CLICON_FEATURE")==0 ||
|
||||
strcmp(name, "CLICON_YANG_DIR")==0 ||
|
||||
strcmp(name, "CLICON_SNMP_MIB")==0){
|
||||
if ((x = clicon_conf_xml(h)) == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_parse_va(YB_NONE, NULL, &x, NULL, "<%s>%s</%s>",
|
||||
name, value, name) < 0)
|
||||
goto done;
|
||||
strcmp(name, "CLICON_YANG_DIR")==0 ||
|
||||
strcmp(name, "CLICON_SNMP_MIB")==0){
|
||||
if ((x = clicon_conf_xml(h)) == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_parse_va(YB_NONE, NULL, &x, NULL, "<%s>%s</%s>",
|
||||
name, value, name) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (clicon_hash_add(copt,
|
||||
name,
|
||||
value,
|
||||
strlen(value)+1) == NULL)
|
||||
goto done;
|
||||
name,
|
||||
value,
|
||||
strlen(value)+1) == NULL)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -478,32 +478,32 @@ clicon_options_main(clicon_handle h)
|
|||
|
||||
/* Create configure yang-spec */
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
/*
|
||||
* Set configure file if not set by command-line above
|
||||
*/
|
||||
if (!clicon_hash_lookup(copt, "CLICON_CONFIGFILE")){
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", CLIXON_DEFAULT_CONFIG);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", CLIXON_DEFAULT_CONFIG);
|
||||
}
|
||||
configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL);
|
||||
if (strlen(configfile) == 0)
|
||||
configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL);
|
||||
configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL);
|
||||
clicon_debug(1, "CLICON_CONFIGFILE=%s", configfile);
|
||||
/* File must end with .xml */
|
||||
if ((suffix = rindex(configfile, '.')) != NULL){
|
||||
suffix++;
|
||||
xml = strcmp(suffix, "xml") == 0;
|
||||
suffix++;
|
||||
xml = strcmp(suffix, "xml") == 0;
|
||||
}
|
||||
if (xml == 0){
|
||||
clicon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix);
|
||||
goto done;
|
||||
clicon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Override extraconfdir */
|
||||
if (clicon_option_str(h, "CLICON_CONFIGDIR") &&
|
||||
(extraconfdir = strdup(clicon_option_str(h, "CLICON_CONFIGDIR"))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
(extraconfdir = strdup(clicon_option_str(h, "CLICON_CONFIGDIR"))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Read configfile first without yangspec, and without extra config dir for bootstrapping,
|
||||
|
|
@ -515,7 +515,7 @@ clicon_options_main(clicon_handle h)
|
|||
* - no extra config dir
|
||||
*/
|
||||
if (parse_configfile(h, configfile, extraconfdir, NULL, &xconfig) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
clicon_conf_xml_set(h, xconfig);
|
||||
|
||||
|
|
@ -528,26 +528,26 @@ clicon_options_main(clicon_handle h)
|
|||
* If fcgi option gets secondary this should probably be changed
|
||||
*/
|
||||
if (clixon_xml_parse_string("<CLICON_FEATURE>clixon-restconf:fcgi</CLICON_FEATURE>",
|
||||
YB_PARENT, NULL, &xconfig, NULL) < 0)
|
||||
goto done;
|
||||
YB_PARENT, NULL, &xconfig, NULL) < 0)
|
||||
goto done;
|
||||
#endif
|
||||
/* Parse clixon yang spec */
|
||||
if (yang_spec_parse_module(h, "clixon-config", NULL, yspec) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Load restconf yang. Note this is also a part of clixon-config */
|
||||
if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
|
||||
goto done;
|
||||
goto done;
|
||||
clicon_conf_xml_set(h, NULL);
|
||||
if (xconfig){
|
||||
xml_free(xconfig);
|
||||
xconfig = NULL;
|
||||
xml_free(xconfig);
|
||||
xconfig = NULL;
|
||||
}
|
||||
/* Read configfile second time now with check yang spec */
|
||||
if (parse_configfile(h, configfile, extraconfdir, yspec, &xconfig) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (xml_spec(xconfig) == NULL){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: <clixon-config xmlns=\"%s\"> or clixon-config.yang not found?", configfile, CLIXON_CONF_NS);
|
||||
goto done;
|
||||
clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: <clixon-config xmlns=\"%s\"> or clixon-config.yang not found?", configfile, CLIXON_CONF_NS);
|
||||
goto done;
|
||||
}
|
||||
/* Set yang config spec (must store to free at exit, since conf_xml below uses it) */
|
||||
if (clicon_config_yang_set(h, yspec) < 0)
|
||||
|
|
@ -555,14 +555,14 @@ clicon_options_main(clicon_handle h)
|
|||
yspec = NULL;
|
||||
/* Set clixon_conf pointer to handle */
|
||||
if (clicon_conf_xml_set(h, xconfig) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
if (yspec)
|
||||
ys_free(yspec);
|
||||
ys_free(yspec);
|
||||
if (extraconfdir)
|
||||
free(extraconfdir);
|
||||
free(extraconfdir);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -574,7 +574,7 @@ clicon_options_main(clicon_handle h)
|
|||
*/
|
||||
int
|
||||
clicon_option_exists(clicon_handle h,
|
||||
const char *name)
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
||||
|
|
@ -593,12 +593,12 @@ clicon_option_exists(clicon_handle h,
|
|||
*/
|
||||
char *
|
||||
clicon_option_str(clicon_handle h,
|
||||
const char *name)
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
||||
if (clicon_hash_lookup(copt, (char*)name) == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
return clicon_hash_value(copt, (char*)name, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -611,8 +611,8 @@ clicon_option_str(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_str_set(clicon_handle h,
|
||||
const char *name,
|
||||
char *val)
|
||||
const char *name,
|
||||
char *val)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
||||
|
|
@ -627,7 +627,7 @@ clicon_option_str_set(clicon_handle h,
|
|||
* @retval -1 If option does not exist
|
||||
* @code
|
||||
* if (clicon_option_exists(h, "X"))
|
||||
* return clicon_option_int(h, "X");
|
||||
* return clicon_option_int(h, "X");
|
||||
* else
|
||||
* return 0;
|
||||
* @endcode
|
||||
|
|
@ -637,12 +637,12 @@ clicon_option_str_set(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_int(clicon_handle h,
|
||||
const char *name)
|
||||
const char *name)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if ((s = clicon_option_str(h, name)) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
return atoi(s);
|
||||
}
|
||||
|
||||
|
|
@ -653,13 +653,13 @@ clicon_option_int(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_int_set(clicon_handle h,
|
||||
const char *name,
|
||||
int val)
|
||||
const char *name,
|
||||
int val)
|
||||
{
|
||||
char s[64];
|
||||
|
||||
if (snprintf(s, sizeof(s)-1, "%u", val) < 0)
|
||||
return -1;
|
||||
return -1;
|
||||
return clicon_option_str_set(h, name, s);
|
||||
}
|
||||
|
||||
|
|
@ -671,7 +671,7 @@ clicon_option_int_set(clicon_handle h,
|
|||
* @retval 1 true
|
||||
* @code
|
||||
* if (clicon_option_exists(h, "X")
|
||||
* return clicon_option_bool(h, "X");
|
||||
* return clicon_option_bool(h, "X");
|
||||
* else
|
||||
* return 0; # default false?
|
||||
* @endcode
|
||||
|
|
@ -681,16 +681,16 @@ clicon_option_int_set(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_bool(clicon_handle h,
|
||||
const char *name)
|
||||
const char *name)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if ((s = clicon_option_str(h, name)) == NULL)
|
||||
return 0;
|
||||
return 0;
|
||||
if (strcmp(s,"true")==0)
|
||||
return 1;
|
||||
return 1;
|
||||
if (strcmp(s,"1")==0)
|
||||
return 1;
|
||||
return 1;
|
||||
return 0; /* Hopefully false, but anything else than "true" or "one" */
|
||||
}
|
||||
|
||||
|
|
@ -701,18 +701,18 @@ clicon_option_bool(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_bool_set(clicon_handle h,
|
||||
const char *name,
|
||||
int val)
|
||||
const char *name,
|
||||
int val)
|
||||
{
|
||||
char s[64];
|
||||
|
||||
if (val != 0 && val != 1){
|
||||
clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
|
||||
return -1;
|
||||
clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
|
||||
return -1;
|
||||
}
|
||||
if (snprintf(s, sizeof(s)-1, "%s", val?"true":"false") < 0){
|
||||
clicon_err(OE_CFG, errno, "snprintf");
|
||||
return -1;
|
||||
clicon_err(OE_CFG, errno, "snprintf");
|
||||
return -1;
|
||||
}
|
||||
return clicon_option_str_set(h, name, s);
|
||||
}
|
||||
|
|
@ -723,7 +723,7 @@ clicon_option_bool_set(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_option_del(clicon_handle h,
|
||||
const char *name)
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
||||
|
|
@ -752,9 +752,9 @@ clicon_cli_varonly(clicon_handle h)
|
|||
char const *opt = "CLICON_CLI_VARONLY";
|
||||
|
||||
if (clicon_option_exists(h, opt))
|
||||
return clicon_option_int(h, opt);
|
||||
return clicon_option_int(h, opt);
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get family of backend socket: AF_UNIX, AF_INET or AF_INET6
|
||||
|
|
@ -768,15 +768,15 @@ clicon_sock_family(clicon_handle h)
|
|||
char *s;
|
||||
|
||||
if ((s = clicon_option_str(h, "CLICON_SOCK_FAMILY")) == NULL)
|
||||
return AF_UNIX;
|
||||
return AF_UNIX;
|
||||
else if (strcmp(s, "IPv4")==0)
|
||||
return AF_INET;
|
||||
return AF_INET;
|
||||
else if (strcmp(s, "IPv6")==0)
|
||||
return AF_INET6;
|
||||
return AF_INET6;
|
||||
else if (strcmp(s, "UNIX")==0)
|
||||
return AF_UNIX;
|
||||
return AF_UNIX;
|
||||
else
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Get port for backend socket in case of AF_INET or AF_INET6
|
||||
|
|
@ -790,7 +790,7 @@ clicon_sock_port(clicon_handle h)
|
|||
char *s;
|
||||
|
||||
if ((s = clicon_option_str(h, "CLICON_SOCK_PORT")) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
return atoi(s);
|
||||
}
|
||||
|
||||
|
|
@ -804,9 +804,9 @@ clicon_autocommit(clicon_handle h)
|
|||
char const *opt = "CLICON_AUTOCOMMIT";
|
||||
|
||||
if (clicon_option_exists(h, opt))
|
||||
return clicon_option_int(h, opt);
|
||||
return clicon_option_int(h, opt);
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Which method to boot/start clicon backend
|
||||
|
|
@ -819,7 +819,7 @@ clicon_startup_mode(clicon_handle h)
|
|||
char *mode;
|
||||
|
||||
if ((mode = clicon_option_str(h, "CLICON_STARTUP_MODE")) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
return clicon_str2int(startup_mode_map, mode);
|
||||
}
|
||||
|
||||
|
|
@ -833,7 +833,7 @@ clicon_backend_privileges_mode(clicon_handle h)
|
|||
char *mode;
|
||||
|
||||
if ((mode = clicon_option_str(h, "CLICON_BACKEND_PRIVILEGES")) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
return clicon_str2int(priv_mode_map, mode);
|
||||
}
|
||||
|
||||
|
|
@ -847,7 +847,7 @@ clicon_restconf_privileges_mode(clicon_handle h)
|
|||
char *mode;
|
||||
|
||||
if ((mode = clicon_option_str(h, "CLICON_RESTCONF_PRIVILEGES")) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
return clicon_str2int(priv_mode_map, mode);
|
||||
}
|
||||
|
||||
|
|
@ -861,7 +861,7 @@ clicon_nacm_credentials(clicon_handle h)
|
|||
char *mode;
|
||||
|
||||
if ((mode = clicon_option_str(h, "CLICON_NACM_CREDENTIALS")) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
return clicon_str2int(nacm_credentials_map, mode);
|
||||
}
|
||||
|
||||
|
|
@ -876,9 +876,9 @@ clicon_datastore_cache(clicon_handle h)
|
|||
char *str;
|
||||
|
||||
if ((str = clicon_option_str(h, "CLICON_DATASTORE_CACHE")) == NULL)
|
||||
return DATASTORE_CACHE;
|
||||
return DATASTORE_CACHE;
|
||||
else
|
||||
return clicon_str2int(datastore_cache_map, str);
|
||||
return clicon_str2int(datastore_cache_map, str);
|
||||
}
|
||||
|
||||
/*! Which Yang regexp/pattern engine to use
|
||||
|
|
@ -892,9 +892,9 @@ clicon_yang_regexp(clicon_handle h)
|
|||
char *str;
|
||||
|
||||
if ((str = clicon_option_str(h, "CLICON_YANG_REGEXP")) == NULL)
|
||||
return REGEXP_POSIX;
|
||||
return REGEXP_POSIX;
|
||||
else
|
||||
return clicon_str2int(yang_regexp_map, str);
|
||||
return clicon_str2int(yang_regexp_map, str);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
|
|
@ -912,7 +912,7 @@ clicon_quiet_mode(clicon_handle h)
|
|||
{
|
||||
char *s;
|
||||
if ((s = clicon_option_str(h, "CLICON_QUIET")) == NULL)
|
||||
return 0; /* default */
|
||||
return 0; /* default */
|
||||
return atoi(s);
|
||||
}
|
||||
|
||||
|
|
@ -922,7 +922,7 @@ clicon_quiet_mode(clicon_handle h)
|
|||
*/
|
||||
int
|
||||
clicon_quiet_mode_set(clicon_handle h,
|
||||
int val)
|
||||
int val)
|
||||
{
|
||||
return clicon_option_int_set(h, "CLICON_QUIET", val);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue