C-style update: Unified comment, retvals in order, remove trailing spaces
Changed function name for `clicon_debug` functions
This commit is contained in:
parent
6e314dd96f
commit
62348fc9c7
204 changed files with 6047 additions and 4904 deletions
|
|
@ -46,8 +46,8 @@
|
|||
* (Duplicated. Also in netconf_*.h)
|
||||
*/
|
||||
int netconf_xpath(cxobj *xsearch,
|
||||
cxobj *xfilter,
|
||||
cbuf *xf, cbuf *xf_err,
|
||||
cxobj *xfilter,
|
||||
cbuf *xf, cbuf *xf_err,
|
||||
cxobj *xt);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -97,16 +97,17 @@ leafstring(cxobj *x)
|
|||
}
|
||||
|
||||
/*! Internal recursive part where configuration xml tree is pruned from filter
|
||||
*
|
||||
* assume parent has been selected and filter match (same name) as parent
|
||||
* parent is pruned according to selection.
|
||||
* @param[in] xfilter Filter xml
|
||||
* @param[out] xconf Configuration xml
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
xml_filter_recursive(cxobj *xfilter,
|
||||
cxobj *xparent,
|
||||
xml_filter_recursive(cxobj *xfilter,
|
||||
cxobj *xparent,
|
||||
int *remove_me)
|
||||
{
|
||||
cxobj *s;
|
||||
|
|
@ -122,7 +123,7 @@ xml_filter_recursive(cxobj *xfilter,
|
|||
|
||||
*remove_me = 0;
|
||||
/* 1. Check selection */
|
||||
if (xml_child_nr(xfilter) == 0)
|
||||
if (xml_child_nr(xfilter) == 0)
|
||||
goto match;
|
||||
|
||||
/* Count containment/selection nodes in filter */
|
||||
|
|
@ -190,6 +191,7 @@ xml_filter_recursive(cxobj *xfilter,
|
|||
}
|
||||
|
||||
/*! Remove parts of configuration xml tree that does not match filter xml tree
|
||||
*
|
||||
* @param[in] xfilter Filter xml
|
||||
* @param[out] xconf Configuration xml
|
||||
* @retval 0 OK
|
||||
|
|
@ -197,15 +199,15 @@ xml_filter_recursive(cxobj *xfilter,
|
|||
* This is the top-level function, calls a recursive variant.
|
||||
*/
|
||||
int
|
||||
xml_filter(cxobj *xfilter,
|
||||
xml_filter(cxobj *xfilter,
|
||||
cxobj *xconfig)
|
||||
{
|
||||
int retval;
|
||||
int remove_s;
|
||||
|
||||
/* Call recursive variant */
|
||||
retval = xml_filter_recursive(xfilter,
|
||||
xconfig,
|
||||
retval = xml_filter_recursive(xfilter,
|
||||
xconfig,
|
||||
&remove_s);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
*/
|
||||
int xml_filter(cxobj *xf, cxobj *xn);
|
||||
|
||||
#endif /* _NETCONF_FILTER_H_ */
|
||||
|
|
|
|||
|
|
@ -99,6 +99,8 @@ static int _netconf_hello_nr = 0;
|
|||
* includes any "xmlns" attributes.
|
||||
* @param[in] xrpc Incoming message on the form <rpc>...
|
||||
* @param[in,out] xrep Reply message on the form <rpc-reply>...
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
netconf_add_request_attr(cxobj *xrpc,
|
||||
|
|
@ -133,9 +135,14 @@ netconf_add_request_attr(cxobj *xrpc,
|
|||
}
|
||||
|
||||
/*! Process netconf hello message
|
||||
*
|
||||
* A server receiving a <hello> message with a <session-id> element MUST
|
||||
* terminate the NETCONF session.
|
||||
* @param[out] eof Request termination
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn
|
||||
* @param[out] eof Request termination
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
netconf_hello_msg(clicon_handle h,
|
||||
|
|
@ -152,7 +159,7 @@ netconf_hello_msg(clicon_handle h,
|
|||
int foundbase_11 = 0;
|
||||
char *body;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
_netconf_hello_nr++;
|
||||
if (xml_find_type(xn, NULL, "session-id", CX_ELMNT) != NULL) {
|
||||
clicon_err(OE_XML, errno, "Server received hello with session-id from client, terminating (see RFC 6241 Sec 8.1");
|
||||
|
|
@ -172,12 +179,12 @@ netconf_hello_msg(clicon_handle h,
|
|||
* event any parameters are encoded at the end of the URI string. */
|
||||
if (strncmp(body, NETCONF_BASE_CAPABILITY_1_0, strlen(NETCONF_BASE_CAPABILITY_1_0)) == 0){ /* RFC 4741 */
|
||||
foundbase_10++;
|
||||
clicon_debug(1, "%s foundbase10", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s foundbase10", __FUNCTION__);
|
||||
}
|
||||
else if (strncmp(body, NETCONF_BASE_CAPABILITY_1_1, strlen(NETCONF_BASE_CAPABILITY_1_1)) == 0 &&
|
||||
clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0){ /* RFC 6241 */
|
||||
foundbase_11++;
|
||||
clicon_debug(1, "%s foundbase11", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s foundbase11", __FUNCTION__);
|
||||
clicon_data_int_set(h, NETCONF_FRAMING_TYPE, NETCONF_SSH_CHUNKED); /* enable chunked enc */
|
||||
}
|
||||
}
|
||||
|
|
@ -195,6 +202,7 @@ netconf_hello_msg(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Process incoming Netconf RPC netconf message
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xreq XML tree containing netconf RPC message
|
||||
* @param[in] yspec YANG spec
|
||||
|
|
@ -223,7 +231,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
/* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
|
||||
if (netconf_add_request_attr(xrpc, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -239,12 +247,12 @@ netconf_rpc_message(clicon_handle h,
|
|||
if ((ret = xml_bind_yang_rpc(h, xrpc, yspec, &xret)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 &&
|
||||
(ret = xml_yang_validate_rpc(h, xrpc, 0, &xret)) < 0)
|
||||
(ret = xml_yang_validate_rpc(h, xrpc, 0, &xret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (netconf_add_request_attr(xrpc, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -265,7 +273,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
goto done;
|
||||
if (netconf_add_request_attr(xrpc, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -281,7 +289,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
/* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
|
||||
if (netconf_add_request_attr(xrpc, xc) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -303,6 +311,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Process incoming a single netconf message parsed as XML
|
||||
*
|
||||
* Identify what netconf message it is
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xreq XML tree containing netconf
|
||||
|
|
@ -325,8 +334,8 @@ netconf_input_packet(clicon_handle h,
|
|||
cxobj *xret = NULL;
|
||||
netconf_framing_type framing;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clicon_debug_xml(1, xreq, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
clixon_debug_xml(1, xreq, "%s", __FUNCTION__);
|
||||
rpcname = xml_name(xreq);
|
||||
rpcprefix = xml_prefix(xreq);
|
||||
framing = clicon_data_int_get(h, NETCONF_FRAMING_TYPE);
|
||||
|
|
@ -339,7 +348,7 @@ netconf_input_packet(clicon_handle h,
|
|||
goto done;
|
||||
if (netconf_add_request_attr(xreq, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -381,8 +390,11 @@ netconf_input_packet(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Get netconf message: detect end-of-msg
|
||||
* @param[in] s Socket where input arrived. read from this.
|
||||
* @param[in] arg Clixon handle.
|
||||
*
|
||||
* @param[in] s Socket where input arrived. read from this.
|
||||
* @param[in] arg Clixon handle.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* This routine continuously reads until no more data on s. There could
|
||||
* be risk of starvation, but the netconf client does little else than
|
||||
* read data so I do not see a danger of true starvation here.
|
||||
|
|
@ -418,7 +430,7 @@ netconf_input_cb(int s,
|
|||
unsigned char *p = buf;
|
||||
ssize_t len;
|
||||
size_t plen;
|
||||
|
||||
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
/* Get unfinished frame */
|
||||
if ((ptr = clicon_hash_value(cdat, NETCONF_FRAME_MSG, &cdatlen)) != NULL){
|
||||
|
|
@ -457,14 +469,14 @@ netconf_input_cb(int s,
|
|||
&eom) < 0)
|
||||
goto done;
|
||||
if (eom == 0){ /* frame not complete */
|
||||
clicon_debug(CLIXON_DBG_DETAIL, "%s: frame: %lu", __FUNCTION__, cbuf_len(cbmsg));
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s: frame: %lu", __FUNCTION__, cbuf_len(cbmsg));
|
||||
/* Extra data to read, save data and continue on next round */
|
||||
if (clicon_hash_add(cdat, NETCONF_FRAME_MSG, &cbmsg, sizeof(cbmsg)) == NULL)
|
||||
goto done;
|
||||
cbmsg = NULL;
|
||||
break;
|
||||
}
|
||||
clicon_debug(CLIXON_DBG_MSG, "Recv ext: %s", cbuf_get(cbmsg));
|
||||
clixon_debug(CLIXON_DBG_MSG, "Recv ext: %s", cbuf_get(cbmsg));
|
||||
if ((ret = netconf_input_frame2(cbmsg, YB_RPC, yspec, &xtop, &xerr)) < 0)
|
||||
goto done;
|
||||
cbuf_reset(cbmsg);
|
||||
|
|
@ -499,7 +511,7 @@ netconf_input_cb(int s,
|
|||
}
|
||||
}
|
||||
if (eof){ /* socket closed / read returns 0 */
|
||||
clicon_debug(1, "%s len==0, closing", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s len==0, closing", __FUNCTION__);
|
||||
clixon_event_unreg_fd(s, netconf_input_cb);
|
||||
close(s);
|
||||
clixon_exit_set(1);
|
||||
|
|
@ -522,16 +534,19 @@ netconf_input_cb(int s,
|
|||
}
|
||||
|
||||
/*! Send netconf hello message
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] s File descriptor to write on (eg 1 - stdout)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
send_hello(clicon_handle h,
|
||||
int s,
|
||||
uint32_t id)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb;
|
||||
int retval = -1;
|
||||
cbuf *cb;
|
||||
netconf_framing_type framing;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
|
|
@ -553,6 +568,7 @@ send_hello(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Clean and close all state of netconf process (but dont exit).
|
||||
*
|
||||
* Cannot use h after this
|
||||
* @param[in] h Clixon handle
|
||||
*/
|
||||
|
|
@ -562,7 +578,7 @@ netconf_terminate(clicon_handle h)
|
|||
yang_stmt *yspec;
|
||||
cvec *nsctx;
|
||||
cxobj *x;
|
||||
|
||||
|
||||
if (clixon_exit_get() == 0)
|
||||
clixon_exit_set(1);
|
||||
/* Delete all plugins, and RPC callbacks */
|
||||
|
|
@ -591,7 +607,7 @@ static int
|
|||
netconf_signal_init (clicon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
|
||||
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
|
||||
goto done;
|
||||
|
|
@ -606,10 +622,11 @@ timeout_fn(int s,
|
|||
void *arg)
|
||||
{
|
||||
clicon_err(OE_EVENTS, ETIMEDOUT, "User request timeout");
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Usage help routine
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] argv0 command line
|
||||
*/
|
||||
|
|
@ -666,12 +683,12 @@ main(int argc,
|
|||
size_t sz;
|
||||
int config_dump = 0;
|
||||
enum format_enum config_dump_format = FORMAT_XML;
|
||||
|
||||
|
||||
/* Create handle */
|
||||
if ((h = clicon_handle_init()) == NULL)
|
||||
return -1;
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
||||
/* Set username to clixon handle. Use in all communication to backend */
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
|
|
@ -712,14 +729,14 @@ main(int argc,
|
|||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clicon_debug_init(dbg, NULL);
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clixon_debug_init(dbg, NULL);
|
||||
yang_init(h);
|
||||
|
||||
|
||||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
/* Now rest of options */
|
||||
optind = 1;
|
||||
opterr = 0;
|
||||
|
|
@ -822,23 +839,23 @@ main(int argc,
|
|||
/* Setup signal handlers, int particular PIPE that occurs if backend closes / restarts */
|
||||
if (netconf_signal_init(h) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
/* Initialize plugin module by creating a handle holding plugin and callback lists */
|
||||
if (clixon_plugin_module_init(h) < 0)
|
||||
goto done;
|
||||
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
|
||||
if (yang_metadata_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Create top-level yang spec and store as option */
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
/* Load netconf plugins before yangs are loaded (eg extension callbacks) */
|
||||
if ((dir = clicon_netconf_dir(h)) != NULL &&
|
||||
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
/* Load Yang modules
|
||||
* 1. Load a yang module as a specific absolute filename */
|
||||
if ((str = clicon_yang_main_file(h)) != NULL){
|
||||
|
|
@ -865,7 +882,7 @@ main(int argc,
|
|||
/* Add netconf yang spec, used by netconf client and as internal protocol */
|
||||
if (netconf_module_load(h) < 0)
|
||||
goto done;
|
||||
/* Here all modules are loaded
|
||||
/* Here all modules are loaded
|
||||
* Compute and set canonical namespace context
|
||||
*/
|
||||
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
|
||||
|
|
@ -894,7 +911,7 @@ main(int argc,
|
|||
if (clicon_hello_req(h, "cl:netconf", NULL, &id) < 0)
|
||||
goto done;
|
||||
clicon_session_id_set(h, id);
|
||||
|
||||
|
||||
/* Send hello to northbound client
|
||||
* Note that this is a violation of RDFC 6241 Sec 8.1:
|
||||
* When the NETCONF session is opened, each peer(both client and server) MUST send a <hello..
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@
|
|||
*/
|
||||
|
||||
static int
|
||||
netconf_get_config_subtree(clicon_handle h,
|
||||
cxobj *xfilter,
|
||||
netconf_get_config_subtree(clicon_handle h,
|
||||
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;
|
||||
|
|
@ -107,9 +107,12 @@ ok:
|
|||
}
|
||||
|
||||
/*! Get configuration
|
||||
* @param[in] h Clicon handle
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
|
||||
* @param[out] xret Return XML, error or OK
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note filter type subtree and xpath is supported, but xpath is preferred, and
|
||||
* better performance and tested. Please use xpath.
|
||||
*
|
||||
|
|
@ -155,8 +158,8 @@ ok:
|
|||
<rpc><get-config><source><candidate/></source><filter type="xpath" select="/interfaces/interface/ipv4"/></get-config></rpc>]]>]]>
|
||||
*/
|
||||
static int
|
||||
netconf_get_config(clicon_handle h,
|
||||
cxobj *xn,
|
||||
netconf_get_config(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -206,13 +209,14 @@ netconf_get_config(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Get options from netconf edit-config
|
||||
*
|
||||
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
|
||||
* @param[out] op Operation type, eg merge,replace,...
|
||||
* @param[out] testopt test option, eg set, test
|
||||
* @param[out] erropt Error option, eg stop-on-error
|
||||
* @retval -1 Fatal Error
|
||||
* @retval 0 parameter error, xret returns error
|
||||
* @retval 1 OK, op, testopt and erropt set
|
||||
* @retval 0 parameter error, xret returns error
|
||||
* @retval -1 Fatal Error
|
||||
* @example
|
||||
* <edit-config>
|
||||
* <config>...</config>
|
||||
|
|
@ -230,7 +234,7 @@ get_edit_opts(cxobj *xn,
|
|||
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)
|
||||
|
|
@ -267,6 +271,7 @@ get_edit_opts(cxobj *xn,
|
|||
}
|
||||
|
||||
/*! Netconf edit configuration
|
||||
*
|
||||
Write the change on a tmp file, then load that into candidate configuration.
|
||||
<edit-config>
|
||||
<target>
|
||||
|
|
@ -317,7 +322,7 @@ CLIXON addition:
|
|||
*/
|
||||
static int
|
||||
netconf_edit_config(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -353,9 +358,11 @@ netconf_edit_config(clicon_handle h,
|
|||
|
||||
/*! Get running configuration and device state information
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
|
||||
* @param[out] xret Return XML, error or OK
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note filter type subtree and xpath is supported, but xpath is preferred, and
|
||||
* better performance and tested. Please use xpath.
|
||||
*
|
||||
|
|
@ -364,8 +371,8 @@ netconf_edit_config(clicon_handle h,
|
|||
* </get></rpc>]]>]]>
|
||||
*/
|
||||
static int
|
||||
netconf_get(clicon_handle h,
|
||||
cxobj *xn,
|
||||
netconf_get(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -409,11 +416,12 @@ netconf_get(clicon_handle h,
|
|||
retval = 0;
|
||||
done:
|
||||
if(nsc)
|
||||
cvec_free(nsc);
|
||||
cvec_free(nsc);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Called when a notification has happened on backend
|
||||
*
|
||||
* and this session has registered for that event.
|
||||
* Filter it and forward it.
|
||||
<notification>
|
||||
|
|
@ -436,7 +444,7 @@ netconf_get(clicon_handle h,
|
|||
* beyond the scope of this document.
|
||||
*/
|
||||
static int
|
||||
netconf_notification_cb(int s,
|
||||
netconf_notification_cb(int s,
|
||||
void *arg)
|
||||
{
|
||||
struct clicon_msg *reply = NULL;
|
||||
|
|
@ -449,9 +457,9 @@ netconf_notification_cb(int s,
|
|||
yang_stmt *yspec = NULL;
|
||||
cvec *nsc = NULL;
|
||||
int ret;
|
||||
cxobj *xerr = NULL;
|
||||
cxobj *xerr = NULL;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
/* get msg (this is the reason this function is called) */
|
||||
if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0)
|
||||
goto done;
|
||||
|
|
@ -464,7 +472,7 @@ netconf_notification_cb(int s,
|
|||
goto done;
|
||||
}
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0)
|
||||
if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){ /* XXX use xerr */
|
||||
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
|
|
@ -496,7 +504,7 @@ netconf_notification_cb(int s,
|
|||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, retval);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
if (nsc)
|
||||
|
|
@ -524,12 +532,12 @@ netconf_notification_cb(int s,
|
|||
* @see netconf_notification_cb for asynchronous stream notifications
|
||||
*/
|
||||
static int
|
||||
netconf_create_subscription(clicon_handle h,
|
||||
cxobj *xn,
|
||||
netconf_create_subscription(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xfilter;
|
||||
cxobj *xfilter;
|
||||
int s;
|
||||
char *ftype;
|
||||
|
||||
|
|
@ -552,8 +560,8 @@ netconf_create_subscription(clicon_handle h,
|
|||
goto done;
|
||||
if (xpath_first(*xret, NULL, "rpc-reply/rpc-error") != NULL)
|
||||
goto ok;
|
||||
if (clixon_event_reg_fd(s,
|
||||
netconf_notification_cb,
|
||||
if (clixon_event_reg_fd(s,
|
||||
netconf_notification_cb,
|
||||
h,
|
||||
"notification socket") < 0)
|
||||
goto done;
|
||||
|
|
@ -571,15 +579,14 @@ netconf_create_subscription(clicon_handle h,
|
|||
* @param[in] h clicon handle
|
||||
* @param[in] xn Sub-tree (under xorig) at child of rpc: <rpc><xn></rpc>.
|
||||
* @param[out] xret Return XML, error or OK
|
||||
*
|
||||
* @retval -1 Error
|
||||
* @retval 0 OK, not found handler.
|
||||
* @retval 1 OK, handler called
|
||||
* @retval 0 OK, not found handler.
|
||||
* @retval -1 Error
|
||||
* @see netconf_input_packet Assume bind and validation made there
|
||||
*/
|
||||
static int
|
||||
netconf_application_rpc(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj *xn,
|
||||
cxobj **xret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -593,7 +600,7 @@ netconf_application_rpc(clicon_handle h,
|
|||
cbuf *cbret = NULL;
|
||||
int ret;
|
||||
int nr = 0;
|
||||
|
||||
|
||||
/* First check system / netconf RPC:s */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
|
|
@ -658,7 +665,7 @@ netconf_application_rpc(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0){
|
||||
if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
|
||||
goto ok;
|
||||
}
|
||||
|
|
@ -679,6 +686,7 @@ netconf_application_rpc(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! The central netconf rpc dispatcher. Look at first tag and dispach to sub-functions.
|
||||
*
|
||||
* Call plugin handler if tag not found. If not handled by any handler, return
|
||||
* error.
|
||||
* @param[in] h clicon handle
|
||||
|
|
@ -690,7 +698,7 @@ netconf_application_rpc(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
netconf_rpc_dispatch(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj *xn,
|
||||
cxobj **xret,
|
||||
int *eof)
|
||||
{
|
||||
|
|
@ -698,7 +706,7 @@ netconf_rpc_dispatch(clicon_handle h,
|
|||
cxobj *xe;
|
||||
char *username;
|
||||
cxobj *xa;
|
||||
|
||||
|
||||
/* Tag username on all incoming requests in case they are forwarded as internal messages
|
||||
* This may be unecesary since not all are forwarded.
|
||||
* It may even be wrong if something else is done with the incoming message?
|
||||
|
|
@ -721,12 +729,12 @@ netconf_rpc_dispatch(clicon_handle h,
|
|||
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), "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;
|
||||
goto done;
|
||||
}
|
||||
else if (strcmp(xml_name(xe), "get-config") == 0){
|
||||
if (netconf_get_config(h, xe, xret) < 0)
|
||||
|
|
@ -743,7 +751,7 @@ netconf_rpc_dispatch(clicon_handle h,
|
|||
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;
|
||||
goto done;
|
||||
}
|
||||
/* RFC 5277 :notification */
|
||||
else if (strcmp(xml_name(xe), "create-subscription") == 0){
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@
|
|||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
*/
|
||||
int
|
||||
netconf_rpc_dispatch(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cxobj *xn,
|
||||
cxobj **xret,
|
||||
int *eof);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue