[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
|
|
@ -81,24 +81,24 @@
|
|||
|
||||
static int
|
||||
netconf_get_config_subtree(clicon_handle h,
|
||||
cxobj *xfilter,
|
||||
cxobj **xret)
|
||||
cxobj *xfilter,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xdata;
|
||||
|
||||
/* a subtree filter is comprised of zero or more element subtrees*/
|
||||
if ((xdata = xpath_first(*xret, NULL, "/rpc-reply/data")) == NULL)
|
||||
goto ok;
|
||||
goto ok;
|
||||
if (xml_filter(xfilter, xdata) < 0){
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>application</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-info>filtering</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE
|
||||
);
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>application</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-info>filtering</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE
|
||||
);
|
||||
}
|
||||
ok:
|
||||
retval = 0;
|
||||
|
|
@ -114,20 +114,20 @@ ok:
|
|||
* better performance and tested. Please use xpath.
|
||||
*
|
||||
* <get-config>
|
||||
* <source>
|
||||
* <candidate/> | <running/>
|
||||
* </source>
|
||||
* <source>
|
||||
* <candidate/> | <running/>
|
||||
* </source>
|
||||
* </get-config>
|
||||
*
|
||||
* <get-config>
|
||||
* <source>
|
||||
* <candidate/> | <running/>
|
||||
* </source>
|
||||
* <filter type="subtree">
|
||||
* <configuration>
|
||||
* <!- - tag elements for each configuration element to return - ->
|
||||
* </configuration>
|
||||
* </filter>
|
||||
* <source>
|
||||
* <candidate/> | <running/>
|
||||
* </source>
|
||||
* <filter type="subtree">
|
||||
* <configuration>
|
||||
* <!- - tag elements for each configuration element to return - ->
|
||||
* </configuration>
|
||||
* </filter>
|
||||
* </get-config>
|
||||
*
|
||||
* Example:
|
||||
|
|
@ -156,8 +156,8 @@ ok:
|
|||
*/
|
||||
static int
|
||||
netconf_get_config(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xfilter; /* filter */
|
||||
|
|
@ -223,46 +223,46 @@ netconf_get_config(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
get_edit_opts(cxobj *xn,
|
||||
enum test_option *testopt,
|
||||
enum error_option *erropt,
|
||||
cxobj **xret)
|
||||
enum test_option *testopt,
|
||||
enum error_option *erropt,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *x;
|
||||
char *optstr;
|
||||
|
||||
if ((x = xpath_first(xn, NULL, "test-option")) != NULL){
|
||||
if ((optstr = xml_body(x)) != NULL){
|
||||
if (strcmp(optstr, "test-then-set") == 0)
|
||||
*testopt = TEST_THEN_SET;
|
||||
else if (strcmp(optstr, "set") == 0)
|
||||
*testopt = SET;
|
||||
else if (strcmp(optstr, "test-only") == 0)
|
||||
*testopt = TEST_ONLY;
|
||||
else
|
||||
goto parerr;
|
||||
}
|
||||
if ((optstr = xml_body(x)) != NULL){
|
||||
if (strcmp(optstr, "test-then-set") == 0)
|
||||
*testopt = TEST_THEN_SET;
|
||||
else if (strcmp(optstr, "set") == 0)
|
||||
*testopt = SET;
|
||||
else if (strcmp(optstr, "test-only") == 0)
|
||||
*testopt = TEST_ONLY;
|
||||
else
|
||||
goto parerr;
|
||||
}
|
||||
}
|
||||
if ((x = xpath_first(xn, NULL, "error-option")) != NULL){
|
||||
if ((optstr = xml_body(x)) != NULL){
|
||||
if (strcmp(optstr, "stop-on-error") == 0)
|
||||
*erropt = STOP_ON_ERROR;
|
||||
else
|
||||
if (strcmp(optstr, "continue-on-error") == 0)
|
||||
*erropt = CONTINUE_ON_ERROR;
|
||||
else
|
||||
goto parerr;
|
||||
}
|
||||
if ((optstr = xml_body(x)) != NULL){
|
||||
if (strcmp(optstr, "stop-on-error") == 0)
|
||||
*erropt = STOP_ON_ERROR;
|
||||
else
|
||||
if (strcmp(optstr, "continue-on-error") == 0)
|
||||
*erropt = CONTINUE_ON_ERROR;
|
||||
else
|
||||
goto parerr;
|
||||
}
|
||||
}
|
||||
retval = 1; /* hunky dory */
|
||||
return retval;
|
||||
parerr: /* parameter error, xret set */
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>invalid-value</error-tag>"
|
||||
"<error-type>protocol</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
"<error-tag>invalid-value</error-tag>"
|
||||
"<error-type>protocol</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -317,8 +317,8 @@ CLIXON addition:
|
|||
*/
|
||||
static int
|
||||
netconf_edit_config(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
int optret;
|
||||
|
|
@ -326,25 +326,25 @@ netconf_edit_config(clicon_handle h,
|
|||
enum error_option erropt = STOP_ON_ERROR; /* only supports this */
|
||||
|
||||
if ((optret = get_edit_opts(xn, &testopt, &erropt, xret)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (optret == 0) /* error in opt parameters */
|
||||
goto ok;
|
||||
goto ok;
|
||||
/* These constraints are clixon-specific since :validate should
|
||||
* support all testopts, and erropts should be supported
|
||||
* And therefore extends the validation
|
||||
* (implement the features before removing these checks)
|
||||
*/
|
||||
if (testopt!=TEST_THEN_SET || erropt!=STOP_ON_ERROR){
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-not-supported</error-tag>"
|
||||
"<error-type>protocol</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
goto ok;
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-not-supported</error-tag>"
|
||||
"<error-type>protocol</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
goto ok;
|
||||
}
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -365,8 +365,8 @@ netconf_edit_config(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
netconf_get(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xfilter; /* filter */
|
||||
|
|
@ -409,7 +409,7 @@ netconf_get(clicon_handle h,
|
|||
retval = 0;
|
||||
done:
|
||||
if(nsc)
|
||||
cvec_free(nsc);
|
||||
cvec_free(nsc);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -437,7 +437,7 @@ netconf_get(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
netconf_notification_cb(int s,
|
||||
void *arg)
|
||||
void *arg)
|
||||
{
|
||||
struct clicon_msg *reply = NULL;
|
||||
int eof;
|
||||
|
|
@ -454,43 +454,43 @@ netconf_notification_cb(int s,
|
|||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
/* get msg (this is the reason this function is called) */
|
||||
if (clicon_msg_rcv(s, &reply, &eof) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* handle close from remote end: this will exit the client */
|
||||
if (eof){
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
close(s);
|
||||
errno = ESHUTDOWN;
|
||||
clixon_event_unreg_fd(s, netconf_notification_cb);
|
||||
goto done;
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
close(s);
|
||||
errno = ESHUTDOWN;
|
||||
clixon_event_unreg_fd(s, netconf_notification_cb);
|
||||
goto done;
|
||||
}
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0){ /* XXX use xerr */
|
||||
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
goto done;
|
||||
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
goto done;
|
||||
}
|
||||
if ((nsc = xml_nsctx_init(NULL, NOTIFICATION_RFC5277_NAMESPACE)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((xn = xpath_first(xt, nsc, "notification")) == NULL)
|
||||
goto ok;
|
||||
goto ok;
|
||||
/* create netconf message */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Send it to listening client on stdout */
|
||||
if (netconf_output_encap(clicon_option_int(h, "netconf-framing"), cb) < 0){
|
||||
goto done;
|
||||
goto done;
|
||||
}
|
||||
if (netconf_output(1, cb, "notification") < 0){
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
close(s);
|
||||
errno = ESHUTDOWN;
|
||||
clixon_event_unreg_fd(s, netconf_notification_cb);
|
||||
goto done;
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
close(s);
|
||||
errno = ESHUTDOWN;
|
||||
clixon_event_unreg_fd(s, netconf_notification_cb);
|
||||
goto done;
|
||||
}
|
||||
fflush(stdout);
|
||||
ok:
|
||||
|
|
@ -498,15 +498,15 @@ netconf_notification_cb(int s,
|
|||
done:
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, retval);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
cbuf_free(cb);
|
||||
if (nsc)
|
||||
xml_nsctx_free(nsc);
|
||||
xml_nsctx_free(nsc);
|
||||
if (xt != NULL)
|
||||
xml_free(xt);
|
||||
xml_free(xt);
|
||||
if (xerr != NULL)
|
||||
xml_free(xerr);
|
||||
xml_free(xerr);
|
||||
if (reply)
|
||||
free(reply);
|
||||
free(reply);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -525,8 +525,8 @@ netconf_notification_cb(int s,
|
|||
*/
|
||||
static int
|
||||
netconf_create_subscription(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xfilter;
|
||||
|
|
@ -534,29 +534,29 @@ netconf_create_subscription(clicon_handle h,
|
|||
char *ftype;
|
||||
|
||||
if ((xfilter = xpath_first(xn, NULL, "//filter")) != NULL){
|
||||
if ((ftype = xml_find_value(xfilter, "type")) != NULL){
|
||||
if (strcmp(ftype, "xpath") != 0){
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>application</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-message>only xpath filter type supported</error-message>"
|
||||
"<error-info>type</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
if ((ftype = xml_find_value(xfilter, "type")) != NULL){
|
||||
if (strcmp(ftype, "xpath") != 0){
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>application</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-message>only xpath filter type supported</error-message>"
|
||||
"<error-info>type</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, &s) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (xpath_first(*xret, NULL, "rpc-reply/rpc-error") != NULL)
|
||||
goto ok;
|
||||
goto ok;
|
||||
if (clixon_event_reg_fd(s,
|
||||
netconf_notification_cb,
|
||||
h,
|
||||
"notification socket") < 0)
|
||||
goto done;
|
||||
netconf_notification_cb,
|
||||
h,
|
||||
"notification socket") < 0)
|
||||
goto done;
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -579,8 +579,8 @@ netconf_create_subscription(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
netconf_application_rpc(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec = NULL; /* application yspec */
|
||||
|
|
@ -596,85 +596,85 @@ netconf_application_rpc(clicon_handle h,
|
|||
|
||||
/* First check system / netconf RPC:s */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Find yang rpc statement, return yang rpc statement if found
|
||||
Check application RPC */
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
cbuf_reset(cb);
|
||||
if (ys_module_by_xml(yspec, xn, &ymod) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ymod == NULL){
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>rpc</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-message>%s</error-message>"
|
||||
"<error-info>Not recognized module</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE, xml_name(xn));
|
||||
goto ok;
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>rpc</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-message>%s</error-message>"
|
||||
"<error-info>Not recognized module</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE, xml_name(xn));
|
||||
goto ok;
|
||||
}
|
||||
yrpc = yang_find(ymod, Y_RPC, xml_name(xn));
|
||||
/* Check if found */
|
||||
if (yrpc != NULL){
|
||||
/* No need to check xn arguments with input statement since already bound and validated. */
|
||||
/* Look for local (client-side) netconf plugins. */
|
||||
if ((ret = rpc_callback_call(h, xn, NULL, &nr, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (nr > 0){ /* Handled locally */
|
||||
if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else /* Send to backend */
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
|
||||
goto done;
|
||||
/* Sanity check of outgoing XML
|
||||
* For now, skip outgoing checks.
|
||||
* (1) Does not handle <ok/> properly
|
||||
* (2) Uncertain how validation errors should be logged/handled
|
||||
*/
|
||||
if (0)
|
||||
if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){
|
||||
xoutput=xpath_first(*xret, NULL, "/");
|
||||
xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
|
||||
if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 && (ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 && (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
retval = 1; /* handled by callback */
|
||||
goto done;
|
||||
/* No need to check xn arguments with input statement since already bound and validated. */
|
||||
/* Look for local (client-side) netconf plugins. */
|
||||
if ((ret = rpc_callback_call(h, xn, NULL, &nr, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (nr > 0){ /* Handled locally */
|
||||
if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else /* Send to backend */
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
|
||||
goto done;
|
||||
/* Sanity check of outgoing XML
|
||||
* For now, skip outgoing checks.
|
||||
* (1) Does not handle <ok/> properly
|
||||
* (2) Uncertain how validation errors should be logged/handled
|
||||
*/
|
||||
if (0)
|
||||
if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){
|
||||
xoutput=xpath_first(*xret, NULL, "/");
|
||||
xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
|
||||
if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 && (ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 && (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
|
||||
goto ok;
|
||||
}
|
||||
}
|
||||
retval = 1; /* handled by callback */
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
xml_free(xerr);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
cbuf_free(cb);
|
||||
if (cbret)
|
||||
cbuf_free(cbret);
|
||||
cbuf_free(cbret);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -690,9 +690,9 @@ netconf_application_rpc(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
netconf_rpc_dispatch(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret,
|
||||
int *eof)
|
||||
cxobj *xn,
|
||||
cxobj **xret,
|
||||
int *eof)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xe;
|
||||
|
|
@ -704,10 +704,10 @@ netconf_rpc_dispatch(clicon_handle h,
|
|||
* It may even be wrong if something else is done with the incoming message?
|
||||
*/
|
||||
if ((username = clicon_username_get(h)) != NULL){
|
||||
if ((xa = xml_new("username", xn, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (xml_value_set(xa, username) < 0)
|
||||
goto done;
|
||||
if ((xa = xml_new("username", xn, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (xml_value_set(xa, username) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Many of these calls are now calling generic clicon_rpc_netconf_xml
|
||||
* directly, since the validation is generic and done before this place
|
||||
|
|
@ -716,65 +716,65 @@ netconf_rpc_dispatch(clicon_handle h,
|
|||
*/
|
||||
xe = NULL;
|
||||
while ((xe = xml_child_each(xn, xe, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(xe), "copy-config") == 0 ||
|
||||
strcmp(xml_name(xe), "delete-config") == 0 ||
|
||||
strcmp(xml_name(xe), "lock") == 0 ||
|
||||
strcmp(xml_name(xe), "unlock") == 0 ||
|
||||
strcmp(xml_name(xe), "kill-session") == 0 ||
|
||||
strcmp(xml_name(xe), "validate") == 0 || /* :validate */
|
||||
strcmp(xml_name(xe), "commit") == 0 || /* :candidate */
|
||||
strcmp(xml_name(xe), "cancel-commit") == 0 ||
|
||||
strcmp(xml_name(xe), "discard-changes") == 0 ||
|
||||
strcmp(xml_name(xe), "action") == 0
|
||||
){
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "get-config") == 0){
|
||||
if (netconf_get_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "edit-config") == 0){
|
||||
if (netconf_edit_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "get") == 0){
|
||||
if (netconf_get(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "close-session") == 0){
|
||||
*eof = 1; /* Pending close */
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* RFC 5277 :notification */
|
||||
else if (strcmp(xml_name(xe), "create-subscription") == 0){
|
||||
if (netconf_create_subscription(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Others */
|
||||
else {
|
||||
/* Look for application-defined RPC. This may either be local
|
||||
client-side or backend. If backend send as netconf RPC. */
|
||||
if ((retval = netconf_application_rpc(h, xe, xret)) < 0)
|
||||
goto done;
|
||||
if (retval == 0){ /* not handled by callback */
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>rpc</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-message>%s</error-message>"
|
||||
"<error-info>Not recognized</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE, xml_name(xe));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (strcmp(xml_name(xe), "copy-config") == 0 ||
|
||||
strcmp(xml_name(xe), "delete-config") == 0 ||
|
||||
strcmp(xml_name(xe), "lock") == 0 ||
|
||||
strcmp(xml_name(xe), "unlock") == 0 ||
|
||||
strcmp(xml_name(xe), "kill-session") == 0 ||
|
||||
strcmp(xml_name(xe), "validate") == 0 || /* :validate */
|
||||
strcmp(xml_name(xe), "commit") == 0 || /* :candidate */
|
||||
strcmp(xml_name(xe), "cancel-commit") == 0 ||
|
||||
strcmp(xml_name(xe), "discard-changes") == 0 ||
|
||||
strcmp(xml_name(xe), "action") == 0
|
||||
){
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "get-config") == 0){
|
||||
if (netconf_get_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "edit-config") == 0){
|
||||
if (netconf_edit_config(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "get") == 0){
|
||||
if (netconf_get(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "close-session") == 0){
|
||||
*eof = 1; /* Pending close */
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xe), xret, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* RFC 5277 :notification */
|
||||
else if (strcmp(xml_name(xe), "create-subscription") == 0){
|
||||
if (netconf_create_subscription(h, xe, xret) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Others */
|
||||
else {
|
||||
/* Look for application-defined RPC. This may either be local
|
||||
client-side or backend. If backend send as netconf RPC. */
|
||||
if ((retval = netconf_application_rpc(h, xe, xret)) < 0)
|
||||
goto done;
|
||||
if (retval == 0){ /* not handled by callback */
|
||||
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply xmlns=\"%s\"><rpc-error>"
|
||||
"<error-tag>operation-failed</error-tag>"
|
||||
"<error-type>rpc</error-type>"
|
||||
"<error-severity>error</error-severity>"
|
||||
"<error-message>%s</error-message>"
|
||||
"<error-info>Not recognized</error-info>"
|
||||
"</rpc-error></rpc-reply>",
|
||||
NETCONF_BASE_NAMESPACE, xml_name(xe));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
/* Username attribute added at top - otherwise it is returned to sender */
|
||||
if ((xa = xml_find(xn, "username")) != NULL)
|
||||
xml_purge(xa);
|
||||
xml_purge(xa);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue