Restricted yang (sub)module file match to match RFC6020 exactly

This commit is contained in:
Olof hagsand 2017-06-25 17:48:21 +02:00
parent 148d5d9432
commit 43c39160a5
10 changed files with 86 additions and 55 deletions

View file

@ -644,6 +644,7 @@ compare_dbs(clicon_handle h,
{
cxobj *xc1 = NULL; /* running xml */
cxobj *xc2 = NULL; /* candidate xml */
cxobj *xerr;
int retval = -1;
int astext;
@ -655,10 +656,18 @@ compare_dbs(clicon_handle h,
astext = cv_int32_get(cvec_i(argv, 0));
else
astext = 0;
if (clicon_rpc_get_config(h, "running", "/", 0, &xc1) < 0)
if (clicon_rpc_get_config(h, "running", "/", &xc1) < 0)
goto done;
if (clicon_rpc_get_config(h, "candidate", "/", 0, &xc2) < 0)
if ((xerr = xpath_first(xc1, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
if (clicon_rpc_get_config(h, "candidate", "/", &xc2) < 0)
goto done;
if ((xerr = xpath_first(xc2, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
if (compare_xmls(xc1, xc2, astext) < 0) /* astext? */
goto done;
retval = 0;
@ -800,6 +809,7 @@ save_config_file(clicon_handle h,
char *dbstr;
char *varstr;
cxobj *xt = NULL;
cxobj *xerr;
FILE *f = NULL;
if (cvec_len(argv) != 2){
@ -823,8 +833,12 @@ save_config_file(clicon_handle h,
goto done;
}
filename = cv_string_get(cv);
if (clicon_rpc_get_config(h, dbstr,"/", 0, &xt) < 0)
if (clicon_rpc_get_config(h, dbstr,"/", &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
if ((f = fopen(filename, "wb")) == NULL){
clicon_err(OE_CFG, errno, "Creating file %s", filename);
goto done;
@ -1122,6 +1136,7 @@ cli_copy_config(clicon_handle h,
char *tovar;
cg_var *tocv;
char *toname;
cxobj *xerr;
if (cvec_len(argv) != 5){
clicon_err(OE_PLUGIN, 0, "%s: Requires four elements: <db> <xpath> <keyname> <from> <to>", __FUNCTION__);
@ -1162,8 +1177,12 @@ cli_copy_config(clicon_handle h,
cprintf(cb, xpath, keyname, fromname);
/* Get from object configuration and store in x1 */
if (clicon_rpc_get_config(h, db, cbuf_get(cb), 0, &x1) < 0)
if (clicon_rpc_get_config(h, db, cbuf_get(cb), &x1) < 0)
goto done;
if ((xerr = xpath_first(x1, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
/* Get to variable -> cv -> to name */
if ((tocv = cvec_find_var(cvv, tovar)) == NULL){

View file

@ -104,6 +104,7 @@ expand_dbvar(void *h,
cxobj *xt = NULL;
char *xpath = NULL;
cxobj **xvec = NULL;
cxobj *xerr;
size_t xlen = 0;
cxobj *x;
char *bodystr;
@ -140,8 +141,12 @@ expand_dbvar(void *h,
if (api_path_fmt2xpath(api_path, cvv, &xpath) < 0)
goto done;
/* XXX read whole configuration, why not send xpath? */
if (clicon_rpc_get_config(h, dbstr, "/", 0, &xt) < 0)
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
/* One round to detect duplicates
* XXX The code below would benefit from some cleanup
*/
@ -379,6 +384,7 @@ cli_show_config(clicon_handle h,
char *val = NULL;
cxobj *xt = NULL;
cxobj *xc;
cxobj *xerr;
enum genmodel_type gt;
if (cvec_len(argv) != 3 && cvec_len(argv) != 4){
@ -426,8 +432,12 @@ cli_show_config(clicon_handle h,
else
cprintf(cbxpath, "%s", xpath);
/* Get configuration from database */
if (clicon_rpc_get_config(h, db, cbuf_get(cbxpath), 0, &xt) < 0)
if (clicon_rpc_get_config(h, db, cbuf_get(cbxpath), &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
/* Print configuration according to format */
switch (format){
case FORMAT_XML:
@ -487,6 +497,7 @@ show_conf_xpath(clicon_handle h,
char *xpath;
cg_var *cv;
cxobj *xt = NULL;
cxobj *xerr;
cxobj **xv = NULL;
size_t xlen;
int i;
@ -505,8 +516,12 @@ show_conf_xpath(clicon_handle h,
}
cv = cvec_find_var(cvv, "xpath");
xpath = cv_string_get(cv);
if (clicon_rpc_get_config(h, str, xpath, 0, &xt) < 0)
if (clicon_rpc_get_config(h, str, xpath, &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
goto done;
}
if (xpath_vec(xt, xpath, &xv, &xlen) < 0)
goto done;
for (i=0; i<xlen; i++)

View file

@ -157,6 +157,7 @@ api_data_get_gen(clicon_handle h,
yang_spec *yspec;
cxobj *xret = NULL;
cxobj *xerr;
cxobj *xtag;
cbuf *cbj = NULL;;
int code;
const char *reason_phrase;
@ -170,7 +171,7 @@ api_data_get_gen(clicon_handle h,
goto done;
}
clicon_debug(1, "%s path:%s", __FUNCTION__, cbuf_get(path));
if (clicon_rpc_get_config(h, "running", cbuf_get(path), 1, &xret) < 0){
if (clicon_rpc_get_config(h, "running", cbuf_get(path), &xret) < 0){
notfound(r);
goto done;
}
@ -182,22 +183,22 @@ api_data_get_gen(clicon_handle h,
cbuf_free(cb);
}
#endif
if (strcmp(xml_name(xret), "rpc-error") == 0){
if ((xerr = xpath_first(xret, "/rpc-error")) != NULL){
if ((cbj = cbuf_new()) == NULL)
goto done;
if ((xerr = xpath_first(xret, "/error-tag")) == NULL){
if ((xtag = xpath_first(xerr, "/error-tag")) == NULL){
notfound(r); /* bad reply? */
goto done;
}
code = clicon_str2int(netconf_restconf_map, xml_body(xerr));
code = clicon_str2int(netconf_restconf_map, xml_body(xtag));
if ((reason_phrase = clicon_int2str(http_reason_phrase_map, code)) == NULL)
reason_phrase="";
clicon_debug(1, "%s code:%d reason phrase:%s",
__FUNCTION__, code, reason_phrase);
if (xml_name_set(xret, "error") < 0)
if (xml_name_set(xerr, "error") < 0)
goto done;
if (xml2json_cbuf(cbj, xret, 1) < 0)
if (xml2json_cbuf(cbj, xerr, 1) < 0)
goto done;
FCGX_FPrintF(r->out, "Status: %d %s\r\n", code, reason_phrase);
FCGX_FPrintF(r->out, "Content-Type: application/yang-data+json\r\n\r\n");