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
|
|
@ -67,7 +67,7 @@
|
|||
#include <clixon/clixon.h>
|
||||
|
||||
/* These include signatures for plugin and transaction callbacks. */
|
||||
#include <clixon/clixon_backend.h>
|
||||
#include <clixon/clixon_backend.h>
|
||||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#define BACKEND_EXAMPLE_OPTS "a:m:M:nrsS:x:iuUtV:"
|
||||
|
|
@ -123,7 +123,7 @@ static int _state = 0;
|
|||
*/
|
||||
static char *_state_file = NULL;
|
||||
|
||||
/*! XPath to register for pagination state XML from file,
|
||||
/*! XPath to register for pagination state XML from file,
|
||||
*
|
||||
* if _state is true -- -sS <file> -x <xpath>
|
||||
* Primarily for testing
|
||||
|
|
@ -185,7 +185,7 @@ static int _validate_fail_toggle = 0; /* fail at validate and commit */
|
|||
static int example_stream_timer_setup(clicon_handle h);
|
||||
|
||||
int
|
||||
main_begin(clicon_handle h,
|
||||
main_begin(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -196,7 +196,7 @@ main_begin(clicon_handle h,
|
|||
/*! This is called on validate (and commit). Check validity of candidate
|
||||
*/
|
||||
int
|
||||
main_validate(clicon_handle h,
|
||||
main_validate(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -213,7 +213,7 @@ main_validate(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_complete(clicon_handle h,
|
||||
main_complete(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -224,7 +224,7 @@ main_complete(clicon_handle h,
|
|||
/*! This is called on commit. Identify modifications and adjust machine state
|
||||
*/
|
||||
int
|
||||
main_commit(clicon_handle h,
|
||||
main_commit(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
cxobj *target = transaction_target(td); /* wanted XML tree */
|
||||
|
|
@ -251,7 +251,7 @@ main_commit(clicon_handle h,
|
|||
/* Get all added i/fs */
|
||||
if (xpath_vec_flag(target, nsc, "//interface", XML_FLAG_ADD, &vec, &len) < 0)
|
||||
return -1;
|
||||
if (clicon_debug_get())
|
||||
if (clixon_debug_get())
|
||||
for (i=0; i<len; i++) /* Loop over added i/fs */
|
||||
xml_print(stdout, vec[i]); /* Print the added interface */
|
||||
done:
|
||||
|
|
@ -263,7 +263,7 @@ main_commit(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_commit_done(clicon_handle h,
|
||||
main_commit_done(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -272,7 +272,7 @@ main_commit_done(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_revert(clicon_handle h,
|
||||
main_revert(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -281,7 +281,7 @@ main_revert(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_end(clicon_handle h,
|
||||
main_end(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -290,7 +290,7 @@ main_end(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_abort(clicon_handle h,
|
||||
main_abort(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -301,7 +301,7 @@ main_abort(clicon_handle h,
|
|||
/*! Routing example notification timer handler. Here is where the periodic action is
|
||||
*/
|
||||
static int
|
||||
example_stream_timer(int fd,
|
||||
example_stream_timer(int fd,
|
||||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -337,8 +337,8 @@ example_stream_timer_setup(clicon_handle h)
|
|||
* are returned, the <rpc-reply> contains a single <ok/> element defined
|
||||
* in [RFC6241].
|
||||
*/
|
||||
static int
|
||||
empty_rpc(clicon_handle h, /* Clicon handle */
|
||||
static int
|
||||
empty_rpc(clicon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -352,8 +352,8 @@ empty_rpc(clicon_handle h, /* Clicon handle */
|
|||
*
|
||||
* The RPC returns the incoming parameters
|
||||
*/
|
||||
static int
|
||||
example_rpc(clicon_handle h, /* Clicon handle */
|
||||
static int
|
||||
example_rpc(clicon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -394,8 +394,8 @@ example_rpc(clicon_handle h, /* Clicon handle */
|
|||
|
||||
/*! This will be called as a hook right after the original system copy-config
|
||||
*/
|
||||
static int
|
||||
example_copy_extra(clicon_handle h, /* Clicon handle */
|
||||
static int
|
||||
example_copy_extra(clicon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -413,8 +413,8 @@ example_copy_extra(clicon_handle h, /* Clicon handle */
|
|||
*
|
||||
* @note callback is hardcoded C, while registration is controlled by -- -a option
|
||||
*/
|
||||
static int
|
||||
example_action_reset(clicon_handle h, /* Clicon handle */
|
||||
static int
|
||||
example_action_reset(clicon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -434,7 +434,7 @@ example_action_reset(clicon_handle h, /* Clicon handle */
|
|||
|
||||
/*! Called to get state data from plugin by programmatically adding state
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] nsc External XML namespace context, or NULL
|
||||
* @param[in] xpath String with XPATH syntax. or NULL for all
|
||||
* @param[out] xstate XML tree, <config/> on entry.
|
||||
|
|
@ -452,8 +452,8 @@ example_action_reset(clicon_handle h, /* Clicon handle */
|
|||
* This yang snippet is present in clixon-example.yang for example.
|
||||
* @see example_statefile where state is read from file and also pagination
|
||||
*/
|
||||
int
|
||||
example_statedata(clicon_handle h,
|
||||
int
|
||||
example_statedata(clicon_handle h,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
cxobj *xstate)
|
||||
|
|
@ -539,7 +539,7 @@ example_statedata(clicon_handle h,
|
|||
*
|
||||
* The example shows how to read and parse a state XML file, (which is cached in the -i case).
|
||||
* Return the requested xpath / pagination xstate by copying from the parsed state XML file
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] nsc External XML namespace context, or NULL
|
||||
* @param[in] xpath String with XPATH syntax. or NULL for all
|
||||
* @param[out] xstate XML tree, <config/> on entry. Copy to this
|
||||
|
|
@ -548,8 +548,8 @@ example_statedata(clicon_handle h,
|
|||
* @see xmldb_get
|
||||
* @see example_statefile where state is programmatically added
|
||||
*/
|
||||
int
|
||||
example_statefile(clicon_handle h,
|
||||
int
|
||||
example_statefile(clicon_handle h,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
cxobj *xstate)
|
||||
|
|
@ -587,8 +587,8 @@ example_statefile(clicon_handle h,
|
|||
if (_state_file_cached)
|
||||
xt = _state_xml_cache;
|
||||
#ifdef _STATEFILTER
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
/* Mark elements to copy:
|
||||
* For every node found in x0, mark the tree as changed
|
||||
*/
|
||||
|
|
@ -601,7 +601,7 @@ example_statefile(clicon_handle h,
|
|||
/* Copy the marked elements:
|
||||
* note is yang-aware for copying of keys which means XML must be bound
|
||||
*/
|
||||
if (xml_copy_marked(xt, xstate) < 0)
|
||||
if (xml_copy_marked(xt, xstate) < 0)
|
||||
goto done;
|
||||
/* Unmark original tree */
|
||||
if (xml_apply(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE)) < 0)
|
||||
|
|
@ -610,7 +610,7 @@ example_statefile(clicon_handle h,
|
|||
if (xml_apply(xstate, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE)) < 0)
|
||||
goto done;
|
||||
#else
|
||||
if (xml_copy(xt, xstate) < 0)
|
||||
if (xml_copy(xt, xstate) < 0)
|
||||
goto done;
|
||||
#endif
|
||||
if (_state_file_cached)
|
||||
|
|
@ -634,7 +634,7 @@ example_statefile(clicon_handle h,
|
|||
* @param[in] userargs Per-call user arguments
|
||||
* @param[in] arg Per-path user argument (at register time)
|
||||
*/
|
||||
int
|
||||
int
|
||||
example_pagination(void *h0,
|
||||
char *xpath,
|
||||
pagination_data pd,
|
||||
|
|
@ -657,16 +657,16 @@ example_pagination(void *h0,
|
|||
uint32_t upper;
|
||||
int ret;
|
||||
cvec *nsc = NULL;
|
||||
|
||||
|
||||
/* If -S is set, then read state data from file */
|
||||
if (!_state || !_state_file)
|
||||
goto ok;
|
||||
|
||||
locked = pagination_locked(pd);
|
||||
offset = pagination_offset(pd);
|
||||
limit = pagination_limit(pd);
|
||||
xstate = pagination_xstate(pd);
|
||||
|
||||
locked = pagination_locked(pd);
|
||||
offset = pagination_offset(pd);
|
||||
limit = pagination_limit(pd);
|
||||
xstate = pagination_xstate(pd);
|
||||
|
||||
/* Get canonical namespace context */
|
||||
if (xml_nsctx_yangspec(yspec, &nsc) < 0)
|
||||
goto done;
|
||||
|
|
@ -687,8 +687,8 @@ example_pagination(void *h0,
|
|||
}
|
||||
if (_state_file_cached)
|
||||
xt = _state_xml_cache;
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
lower = offset;
|
||||
if (limit == 0)
|
||||
upper = xlen;
|
||||
|
|
@ -732,7 +732,7 @@ example_pagination(void *h0,
|
|||
free(xvec);
|
||||
if (nsc)
|
||||
cvec_free(nsc);
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Lock databse status has changed status
|
||||
|
|
@ -752,7 +752,7 @@ example_lockdb(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
clicon_debug(1, "%s Lock callback: db%s: locked:%d", __FUNCTION__, db, lock);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s Lock callback: db%s: locked:%d", __FUNCTION__, db, lock);
|
||||
/* Part of cached pagination example
|
||||
*/
|
||||
if (strcmp(db, "running") == 0 && lock == 0 &&
|
||||
|
|
@ -769,15 +769,15 @@ example_lockdb(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Callback for yang extensions example:e4
|
||||
*
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] yext Yang node of extension
|
||||
* @param[in] ys Yang node of (unknown) statement belonging to extension
|
||||
* @retval 0 OK, all callbacks executed OK
|
||||
* @retval -1 Error in one callback
|
||||
* @retval 0 OK, all callbacks executed OK
|
||||
* @retval -1 Error in one callback
|
||||
*/
|
||||
int
|
||||
example_extension(clicon_handle h,
|
||||
example_extension(clicon_handle h,
|
||||
yang_stmt *yext,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
|
|
@ -787,13 +787,13 @@ example_extension(clicon_handle h,
|
|||
yang_stmt *ymod;
|
||||
yang_stmt *yc;
|
||||
yang_stmt *yn = NULL;
|
||||
|
||||
|
||||
ymod = ys_module(yext);
|
||||
modname = yang_argument_get(ymod);
|
||||
extname = yang_argument_get(yext);
|
||||
if (strcmp(modname, "example") != 0 || strcmp(extname, "e4") != 0)
|
||||
goto ok;
|
||||
clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname);
|
||||
if ((yc = yang_find(ys, 0, NULL)) == NULL)
|
||||
goto ok;
|
||||
if ((yn = ys_dup(yc)) == NULL)
|
||||
|
|
@ -833,7 +833,7 @@ static const map_str2str namespace_map[] = {
|
|||
*
|
||||
* Gets called on startup after initial XML parsing, but before module-specific upgrades
|
||||
* and before validation.
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] db Name of datastore, eg "running", "startup" or "tmp"
|
||||
* @param[in] xt XML tree. Upgrade this "in place"
|
||||
* @param[in] msd Info on datastore module-state, if any
|
||||
|
|
@ -848,10 +848,10 @@ example_upgrade(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
cvec *nsc = NULL; /* Canonical namespace */
|
||||
yang_stmt *yspec;
|
||||
yang_stmt *yspec;
|
||||
const struct map_str2str *ms; /* map iterator */
|
||||
cxobj **xvec = NULL; /* vector of result nodes */
|
||||
size_t xlen;
|
||||
size_t xlen;
|
||||
int i;
|
||||
const char **pp;
|
||||
|
||||
|
|
@ -868,7 +868,7 @@ example_upgrade(clicon_handle h,
|
|||
/* 1. Remove paths */
|
||||
for (pp = remove_map; *pp; ++pp){
|
||||
/* Find all nodes matching n */
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, *pp) < 0)
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, *pp) < 0)
|
||||
goto done;
|
||||
/* Remove them */
|
||||
/* Loop through all nodes matching mypath and change theoir namespace */
|
||||
|
|
@ -896,11 +896,11 @@ example_upgrade(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
/* Find all nodes matching mypath */
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, mypath) < 0)
|
||||
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, mypath) < 0)
|
||||
goto done;
|
||||
/* Loop through all nodes matching mypath and change theoir namespace */
|
||||
for (i=0; i<xlen; i++){
|
||||
/* Change namespace of this node (using myprefix) */
|
||||
/* Change namespace of this node (using myprefix) */
|
||||
if (xml_namespace_change(xvec[i], mynamespace, myprefix) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -977,7 +977,7 @@ main_yang_mount(clicon_handle h,
|
|||
|
||||
/*! Testcase module-specific upgrade function moving interfaces-state to interfaces
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
|
|
@ -999,13 +999,13 @@ main_yang_mount(clicon_handle h,
|
|||
* - Rename /interfaces/interface/description to descr
|
||||
*/
|
||||
static int
|
||||
upgrade_2014_to_2016(clicon_handle h,
|
||||
cxobj *xt,
|
||||
upgrade_2014_to_2016(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1020,11 +1020,11 @@ upgrade_2014_to_2016(clicon_handle h,
|
|||
int i;
|
||||
char *name;
|
||||
|
||||
clicon_debug(1, "%s from:%d to:%d", __FUNCTION__, from, to);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s from:%d to:%d", __FUNCTION__, from, to);
|
||||
if (op != XML_FLAG_CHANGE) /* Only treat fully present modules */
|
||||
goto ok;
|
||||
/* Get Yang module for this namespace. Note it may not exist (if obsolete) */
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ym = yang_find_module_by_namespace(yspec, ns)) == NULL)
|
||||
goto ok; /* shouldnt happen */
|
||||
/* Get all XML nodes with that namespace */
|
||||
|
|
@ -1045,7 +1045,7 @@ upgrade_2014_to_2016(clicon_handle h,
|
|||
continue; /* shouldnt happen */
|
||||
/* Get corresponding /interfaces/interface entry */
|
||||
xif = xpath_first(xt, NULL, "/interfaces/interface[name=\"%s\"]", name);
|
||||
/* - Move /if:interfaces-state/if:interface/if:admin-status to
|
||||
/* - Move /if:interfaces-state/if:interface/if:admin-status to
|
||||
* /if:interfaces/if:interface/ */
|
||||
if ((x = xml_find(xi, "admin-status")) != NULL && xif){
|
||||
if (xml_addsub(xif, x) < 0)
|
||||
|
|
@ -1082,7 +1082,7 @@ upgrade_2014_to_2016(clicon_handle h,
|
|||
|
||||
/*! Testcase upgrade function removing interfaces-state
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
|
|
@ -1103,13 +1103,13 @@ upgrade_2014_to_2016(clicon_handle h,
|
|||
* fraction-digits 3 and divide all values with 1000
|
||||
*/
|
||||
static int
|
||||
upgrade_2016_to_2018(clicon_handle h,
|
||||
cxobj *xt,
|
||||
upgrade_2016_to_2018(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1123,14 +1123,14 @@ upgrade_2016_to_2018(clicon_handle h,
|
|||
size_t vlen;
|
||||
int i;
|
||||
|
||||
clicon_debug(1, "%s from:%d to:%d", __FUNCTION__, from, to);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s from:%d to:%d", __FUNCTION__, from, to);
|
||||
if (op != XML_FLAG_CHANGE) /* Only treat fully present modules */
|
||||
goto ok;
|
||||
/* Get Yang module for this namespace. Note it may not exist (if obsolete) */
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ym = yang_find_module_by_namespace(yspec, ns)) == NULL)
|
||||
goto ok; /* shouldnt happen */
|
||||
clicon_debug(1, "%s module %s", __FUNCTION__, ym?yang_argument_get(ym):"none");
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s module %s", __FUNCTION__, ym?yang_argument_get(ym):"none");
|
||||
/* Get all XML nodes with that namespace */
|
||||
if (xml_namespace_vec(h, xt, ns, &vec, &vlen) < 0)
|
||||
goto done;
|
||||
|
|
@ -1182,7 +1182,7 @@ upgrade_2016_to_2018(clicon_handle h,
|
|||
|
||||
/*! Testcase module-specific upgrade function moving interfaces-state to interfaces
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
|
|
@ -1204,13 +1204,13 @@ upgrade_2016_to_2018(clicon_handle h,
|
|||
* - Rename /interfaces/interface/description to descr
|
||||
*/
|
||||
static int
|
||||
upgrade_interfaces(clicon_handle h,
|
||||
cxobj *xt,
|
||||
upgrade_interfaces(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1247,8 +1247,10 @@ upgrade_interfaces(clicon_handle h,
|
|||
* is well defined.
|
||||
* This involves creating default configuration files for various daemons, set interface
|
||||
* flags etc.
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] db Name of database. Not3 may be other than "running"
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* In this example, a loopback parameter is added
|
||||
*/
|
||||
int
|
||||
|
|
@ -1264,15 +1266,14 @@ example_reset(clicon_handle h,
|
|||
|
||||
if (!_reset)
|
||||
goto ok; /* Note not enabled by default */
|
||||
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
/* Parse extra XML */
|
||||
if ((ret = clixon_xml_parse_string("<table xmlns=\"urn:example:clixon\">"
|
||||
"<parameter><name>loopback</name><value>99</value></parameter>"
|
||||
"</table>", YB_MODULE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_debug_xml(1, xerr, "Error when parsing XML");
|
||||
clixon_debug_xml(CLIXON_DBG_DEFAULT, xerr, "Error when parsing XML");
|
||||
goto ok;
|
||||
}
|
||||
/* xmldb_put requires modification tree to be: <config>... */
|
||||
|
|
@ -1306,7 +1307,9 @@ example_reset(clicon_handle h,
|
|||
* Called when application is "started", (almost) all initialization is complete
|
||||
* Backend: daemon is in the background. If daemon privileges are dropped
|
||||
* this callback is called *before* privileges are dropped.
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
example_start(clicon_handle h)
|
||||
|
|
@ -1338,7 +1341,9 @@ example_start(clicon_handle h)
|
|||
|
||||
/*! Plugin daemon.
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] h Clixon handle
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* plugin_daemon is called once after daemonization has been made but before lowering of privileges
|
||||
* the main event loop is entered.
|
||||
*/
|
||||
|
|
@ -1376,7 +1381,7 @@ example_daemon(clicon_handle h)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
example_exit(clicon_handle h)
|
||||
{
|
||||
if (_state_xml_cache){
|
||||
|
|
@ -1390,7 +1395,7 @@ example_exit(clicon_handle h)
|
|||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
"example", /* name */
|
||||
clixon_plugin_init, /* init - must be called clixon_plugin_init */
|
||||
example_start, /* start */
|
||||
example_exit, /* exit */
|
||||
|
|
@ -1427,7 +1432,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
char **argv;
|
||||
int c;
|
||||
|
||||
clicon_debug(1, "%s backend", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s backend", __FUNCTION__);
|
||||
|
||||
/* Get user command-line options (after --) */
|
||||
if (clicon_argv_get(h, &argc, &argv) < 0)
|
||||
|
|
@ -1491,7 +1496,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_notification_stream){
|
||||
/* Example stream initialization:
|
||||
* 1) Register EXAMPLE stream
|
||||
|
|
@ -1514,22 +1519,22 @@ clixon_plugin_init(clicon_handle h)
|
|||
/* Register callback for routing rpc calls
|
||||
*/
|
||||
/* From example.yang (clicon) */
|
||||
if (rpc_callback_register(h, empty_rpc,
|
||||
NULL,
|
||||
if (rpc_callback_register(h, empty_rpc,
|
||||
NULL,
|
||||
"urn:example:clixon",
|
||||
"empty"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
/* Same as example but with optional input/output */
|
||||
if (rpc_callback_register(h, example_rpc,
|
||||
NULL,
|
||||
if (rpc_callback_register(h, example_rpc,
|
||||
NULL,
|
||||
"urn:example:clixon",
|
||||
"optional"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
/* Same as example but with optional input/output */
|
||||
if (rpc_callback_register(h, example_rpc,
|
||||
NULL,
|
||||
if (rpc_callback_register(h, example_rpc,
|
||||
NULL,
|
||||
"urn:example:clixon",
|
||||
"example"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
|
|
@ -1538,8 +1543,8 @@ clixon_plugin_init(clicon_handle h)
|
|||
* If you want to have it called _after_ the system callback, place this call in
|
||||
* the _start function.
|
||||
*/
|
||||
if (rpc_callback_register(h, example_copy_extra,
|
||||
NULL,
|
||||
if (rpc_callback_register(h, example_copy_extra,
|
||||
NULL,
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
"copy-config"
|
||||
) < 0)
|
||||
|
|
|
|||
|
|
@ -56,18 +56,20 @@
|
|||
#include <clixon/clixon.h>
|
||||
|
||||
/* These include signatures for plugin and transaction callbacks. */
|
||||
#include <clixon/clixon_backend.h>
|
||||
#include <clixon/clixon_backend.h>
|
||||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#define BACKEND_NACM_OPTS "tv:"
|
||||
|
||||
/*! Variable to control transaction logging (for debug)
|
||||
*
|
||||
* If set, call syslog for every transaction callback
|
||||
* Start backend with -- -t
|
||||
*/
|
||||
static int _transaction_log = 0;
|
||||
|
||||
/*! Variable to trigger validation/commit errors (synthetic errors) for tests
|
||||
*
|
||||
* XPath to trigger validation error, ie if the XPath matches, then validate fails
|
||||
* This is to make tests where a transaction fails midway and aborts/reverts the transaction.
|
||||
* Start backend with -- -v <xpath>
|
||||
|
|
@ -76,12 +78,13 @@ static int _transaction_log = 0;
|
|||
static char *_validate_fail_xpath = NULL;
|
||||
|
||||
/*! Sub state variable to fail on validate/commit (not configured)
|
||||
*
|
||||
* Obscure, but a way to first trigger a validation error, next time to trigger a commit error
|
||||
*/
|
||||
static int _validate_fail_toggle = 0; /* fail at validate and commit */
|
||||
|
||||
int
|
||||
nacm_begin(clicon_handle h,
|
||||
nacm_begin(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -91,7 +94,7 @@ nacm_begin(clicon_handle h,
|
|||
/*! This is called on validate (and commit). Check validity of candidate
|
||||
*/
|
||||
int
|
||||
nacm_validate(clicon_handle h,
|
||||
nacm_validate(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -108,7 +111,7 @@ nacm_validate(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_complete(clicon_handle h,
|
||||
nacm_complete(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -119,7 +122,7 @@ nacm_complete(clicon_handle h,
|
|||
/*! This is called on commit. Identify modifications and adjust machine state
|
||||
*/
|
||||
int
|
||||
nacm_commit(clicon_handle h,
|
||||
nacm_commit(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -136,7 +139,7 @@ nacm_commit(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_commit_done(clicon_handle h,
|
||||
nacm_commit_done(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -145,7 +148,7 @@ nacm_commit_done(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_revert(clicon_handle h,
|
||||
nacm_revert(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -154,7 +157,7 @@ nacm_revert(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_end(clicon_handle h,
|
||||
nacm_end(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -163,7 +166,7 @@ nacm_end(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_abort(clicon_handle h,
|
||||
nacm_abort(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -172,9 +175,10 @@ nacm_abort(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Called to get NACM state data
|
||||
* @param[in] h Clicon handle
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] nsc External XML namespace context, or NULL
|
||||
* @param[in] xpath String with XPATH syntax. or NULL for all
|
||||
* @param[in] xpath String with XPath syntax. or NULL for all
|
||||
* @param[in] xtop XML tree, <config/> on entry.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
|
@ -182,8 +186,8 @@ nacm_abort(clicon_handle h,
|
|||
* @note this example code returns a static statedata used in testing.
|
||||
* Real code would poll state
|
||||
*/
|
||||
int
|
||||
nacm_statedata(clicon_handle h,
|
||||
int
|
||||
nacm_statedata(clicon_handle h,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
cxobj *xstate)
|
||||
|
|
@ -224,6 +228,7 @@ static clixon_plugin_api api = {
|
|||
};
|
||||
|
||||
/*! Backend plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
|
|
@ -235,8 +240,8 @@ clixon_plugin_init(clicon_handle h)
|
|||
int argc; /* command-line options (after --) */
|
||||
char **argv;
|
||||
int c;
|
||||
|
||||
clicon_debug(1, "%s backend nacm", __FUNCTION__);
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s backend nacm", __FUNCTION__);
|
||||
/* Get user command-line options (after --) */
|
||||
if (clicon_argv_get(h, &argc, &argv) < 0)
|
||||
goto done;
|
||||
|
|
@ -256,7 +261,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){
|
||||
clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
|
||||
/* Skip nacm module if not enabled _unless_ we use transaction tests */
|
||||
if (_transaction_log == 0)
|
||||
if (_transaction_log == 0)
|
||||
return NULL;
|
||||
}
|
||||
/* Return plugin API */
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@
|
|||
static char *_mount_yang = NULL;
|
||||
static char *_mount_namespace = NULL;
|
||||
|
||||
/*! Example cli function */
|
||||
/*! Example cli function
|
||||
*/
|
||||
int
|
||||
mycallback(clicon_handle h, cvec *cvv, cvec *argv)
|
||||
{
|
||||
|
|
@ -80,10 +81,10 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
|
|||
|
||||
if ((nsc = xml_nsctx_init(NULL, "urn:example:clixon")) == NULL)
|
||||
goto done;
|
||||
/* Show eth0 interfaces config using XPATH */
|
||||
/* Show eth0 interfaces config using XPath */
|
||||
if (clicon_rpc_get_config(h, NULL, "running",
|
||||
"/interfaces/interface[name='eth0']",
|
||||
nsc, NULL,
|
||||
nsc, NULL,
|
||||
&xret) < 0)
|
||||
goto done;
|
||||
if (clixon_xml2file(stdout, xret, 0, 1, NULL, cligen_output, 0, 1) < 0)
|
||||
|
|
@ -97,10 +98,11 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Example "downcall", ie initiate an RPC to the backend */
|
||||
/*! Example "downcall", ie initiate an RPC to the backend
|
||||
*/
|
||||
int
|
||||
example_client_rpc(clicon_handle h,
|
||||
cvec *cvv,
|
||||
example_client_rpc(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -148,7 +150,11 @@ example_client_rpc(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Translate function from an original value to a new.
|
||||
*
|
||||
* In this case, assume string and increment characters, eg HAL->IBM
|
||||
* @param[in] h Clixon handle
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_incstr(cligen_handle h,
|
||||
|
|
@ -156,8 +162,8 @@ cli_incstr(cligen_handle h,
|
|||
{
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
/* Filter out other than strings
|
||||
|
||||
/* Filter out other than strings
|
||||
* this is specific to this example, one can do translation */
|
||||
if (cv == NULL || cv_type_get(cv) != CGV_STRING)
|
||||
return 0;
|
||||
|
|
@ -239,6 +245,7 @@ static clixon_plugin_api api = {
|
|||
};
|
||||
|
||||
/*! CLI plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
|
|
|
|||
|
|
@ -49,8 +49,10 @@
|
|||
#include <clixon/clixon_netconf.h>
|
||||
|
||||
/*! Plugin start
|
||||
*
|
||||
* Called once everything has been initialized, right before
|
||||
* the main event loop is entered.
|
||||
* @param[in] h Clixon handle
|
||||
*/
|
||||
int
|
||||
plugin_start(clicon_handle h)
|
||||
|
|
@ -67,9 +69,9 @@ plugin_exit(clicon_handle h)
|
|||
/*! Local example netconf rpc callback
|
||||
*/
|
||||
int
|
||||
netconf_client_rpc(clicon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
netconf_client_rpc(clicon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
void *regarg)
|
||||
{
|
||||
|
|
@ -111,6 +113,7 @@ static struct clixon_plugin_api api = {
|
|||
};
|
||||
|
||||
/*! Netconf plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
|
|
@ -118,7 +121,7 @@ static struct clixon_plugin_api api = {
|
|||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__);
|
||||
/* Register local netconf rpc client (note not backend rpc client) */
|
||||
if (rpc_callback_register(h, netconf_client_rpc, NULL,
|
||||
"urn:example:clixon", "client-rpc") < 0)
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ static const char Pad64 = '=';
|
|||
@note what is copyright of this?
|
||||
*/
|
||||
int
|
||||
b64_decode(const char *src,
|
||||
char *target,
|
||||
b64_decode(const char *src,
|
||||
char *target,
|
||||
size_t targsize)
|
||||
{
|
||||
int tarindex, state, ch;
|
||||
|
|
@ -185,14 +185,15 @@ b64_decode(const char *src,
|
|||
}
|
||||
|
||||
/*! HTTP basic authentication example (note hardwired)
|
||||
* @param[in] h Clicon handle
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] req Per-message request www handle to use with restconf_api.h
|
||||
* @param[out] authp NULL: Credentials failed, no user set (401 returned).
|
||||
* String: Credentials OK, the associated user, must be mallloc:ed
|
||||
* Parameter signtificant only if retval is 1/OK
|
||||
* @retval -1 Fatal error
|
||||
* @retval 0 Ignore, undecided, not handled, same as no callback
|
||||
* @retval 1 OK, see authp parameter for result.
|
||||
* @retval 0 Ignore, undecided, not handled, same as no callback
|
||||
* @retval -1 Fatal error
|
||||
* @note authp should be malloced
|
||||
* @note: Three hardwired users: andy, wilma, guest w password "bar".
|
||||
*/
|
||||
|
|
@ -211,14 +212,14 @@ example_basic_auth(clicon_handle h,
|
|||
size_t authlen;
|
||||
int ret;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (authp == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* At this point in the code we must use HTTP basic authentication */
|
||||
if ((auth = restconf_param_get(h, "HTTP_AUTHORIZATION")) == NULL)
|
||||
goto fail;
|
||||
goto fail;
|
||||
if (strlen(auth) < strlen("Basic "))
|
||||
goto fail;
|
||||
if (strncmp("Basic ", auth, strlen("Basic ")))
|
||||
|
|
@ -237,7 +238,7 @@ example_basic_auth(clicon_handle h,
|
|||
goto fail;
|
||||
*passwd = '\0';
|
||||
passwd++;
|
||||
clicon_debug(1, "%s http user:%s passwd:%s", __FUNCTION__, user, passwd);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s http user:%s passwd:%s", __FUNCTION__, user, passwd);
|
||||
/* Here get auth sub-tree where all the users are */
|
||||
if ((cb = cbuf_new()) == NULL)
|
||||
goto done;
|
||||
|
|
@ -252,7 +253,7 @@ example_basic_auth(clicon_handle h,
|
|||
user=NULL; /* to avoid free below */
|
||||
retval = 1;
|
||||
done: /* error */
|
||||
clicon_debug(1, "%s retval:%d authp:%s", __FUNCTION__, retval, authp?"":*authp);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d authp:%s", __FUNCTION__, retval, authp?"":*authp);
|
||||
if (user)
|
||||
free(user);
|
||||
if (cb)
|
||||
|
|
@ -267,15 +268,16 @@ example_basic_auth(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Authentication callback
|
||||
* @param[in] h Clicon handle
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] req Per-message request www handle to use with restconf_api.h
|
||||
* @param[in] auth_type Authentication type: none, user-defined, or client-cert
|
||||
* @param[out] authp NULL: Credentials failed, no user set (401 returned).
|
||||
* String: Credentials OK, the associated user, must be mallloc:ed
|
||||
* Parameter signtificant only if retval is 1/OK
|
||||
* @retval -1 Fatal error
|
||||
* @retval 0 Ignore, undecided, not handled, same as no callback
|
||||
* @retval 1 OK, see authp parameter for result.
|
||||
* @retval 0 Ignore, undecided, not handled, same as no callback
|
||||
* @retval -1 Fatal error
|
||||
* @note authp should be malloced
|
||||
*/
|
||||
int
|
||||
|
|
@ -285,8 +287,8 @@ example_restconf_credentials(clicon_handle h,
|
|||
char **authp)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
clicon_debug(1, "%s auth:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s auth:%s", __FUNCTION__, clixon_auth_type_int2str(auth_type));
|
||||
switch (auth_type){
|
||||
case CLIXON_AUTH_NONE: /* FEATURE clixon-restconf:allow-auth-none must be enabled */
|
||||
retval = 0;
|
||||
|
|
@ -300,16 +302,16 @@ example_restconf_credentials(clicon_handle h,
|
|||
break;
|
||||
}
|
||||
done:
|
||||
clicon_debug(1, "%s retval:%d authp:%s", __FUNCTION__, retval, *authp);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d authp:%s", __FUNCTION__, retval, *authp);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Local example restconf rpc callback
|
||||
*/
|
||||
int
|
||||
restconf_client_rpc(clicon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
restconf_client_rpc(clicon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
void *regarg)
|
||||
{
|
||||
|
|
@ -344,7 +346,7 @@ restconf_client_rpc(clicon_handle h,
|
|||
int
|
||||
example_restconf_start(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -359,6 +361,7 @@ static clixon_plugin_api api = {
|
|||
};
|
||||
|
||||
/*! Restconf plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
|
|
@ -370,8 +373,8 @@ clixon_plugin_init(clicon_handle h)
|
|||
int argc; /* command-line options (after --) */
|
||||
char **argv = NULL;
|
||||
int c;
|
||||
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__);
|
||||
/* Get user command-line options (after --) */
|
||||
if (clicon_argv_get(h, &argc, &argv) < 0)
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue