Restructured error,debug anf log API
Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err()
This commit is contained in:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -326,7 +326,7 @@ In the CLI a netconf rpc call is constructed and sent to the backend: See `examp
|
|||
The clixon backend plugin [example_backend.c] reveives the netconf call and replies. This is made byregistering a callback handling handling the RPC:
|
||||
```
|
||||
static int
|
||||
example_rpc(clicon_handle h,
|
||||
example_rpc(clixon_handle h,
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* Client session */
|
||||
|
|
@ -336,7 +336,7 @@ example_rpc(clicon_handle h,
|
|||
return 0;
|
||||
}
|
||||
int
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
...
|
||||
rpc_callback_register(h, example_rpc, NULL, "example");
|
||||
|
|
@ -426,7 +426,7 @@ static clixon_plugin_api api = {
|
|||
};
|
||||
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
/* Optional callback registration for RPC calls */
|
||||
rpc_callback_register(h, example_rpc, NULL, "example");
|
||||
|
|
|
|||
|
|
@ -60,10 +60,10 @@
|
|||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* clicon */
|
||||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* Clicon library functions. */
|
||||
/* Clixon library functions. */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
/* These include signatures for plugin and transaction callbacks. */
|
||||
|
|
@ -182,10 +182,10 @@ static char *_validate_fail_xpath = NULL;
|
|||
static int _validate_fail_toggle = 0; /* fail at validate and commit */
|
||||
|
||||
/* forward */
|
||||
static int example_stream_timer_setup(clicon_handle h);
|
||||
static int example_stream_timer_setup(clixon_handle h);
|
||||
|
||||
int
|
||||
main_begin(clicon_handle h,
|
||||
main_begin(clixon_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(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -205,7 +205,7 @@ main_validate(clicon_handle h,
|
|||
if (_validate_fail_toggle==0 &&
|
||||
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
|
||||
_validate_fail_toggle = 1; /* toggle if triggered */
|
||||
clicon_err(OE_XML, 0, "User error");
|
||||
clixon_err(OE_XML, 0, "User error");
|
||||
return -1; /* induce fail */
|
||||
}
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ main_validate(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_complete(clicon_handle h,
|
||||
main_complete(clixon_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(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
cxobj *target = transaction_target(td); /* wanted XML tree */
|
||||
|
|
@ -239,7 +239,7 @@ main_commit(clicon_handle h,
|
|||
if (_validate_fail_toggle==1 &&
|
||||
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
|
||||
_validate_fail_toggle = 0; /* toggle if triggered */
|
||||
clicon_err(OE_XML, 0, "User error");
|
||||
clixon_err(OE_XML, 0, "User error");
|
||||
return -1; /* induce fail */
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +263,7 @@ main_commit(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
main_commit_done(clicon_handle h,
|
||||
main_commit_done(clixon_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(clixon_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(clixon_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(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -305,7 +305,7 @@ example_stream_timer(int fd,
|
|||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h = (clicon_handle)arg;
|
||||
clixon_handle h = (clixon_handle)arg;
|
||||
|
||||
/* XXX Change to actual netconf notifications and namespace */
|
||||
if (stream_notify(h, "EXAMPLE", "<event xmlns=\"urn:example:clixon\"><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>") < 0)
|
||||
|
|
@ -320,7 +320,7 @@ example_stream_timer(int fd,
|
|||
/*! Set up example stream notification timer
|
||||
*/
|
||||
static int
|
||||
example_stream_timer_setup(clicon_handle h)
|
||||
example_stream_timer_setup(clixon_handle h)
|
||||
{
|
||||
struct timeval t, t1;
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ example_stream_timer_setup(clicon_handle h)
|
|||
* in [RFC6241].
|
||||
*/
|
||||
static int
|
||||
empty_rpc(clicon_handle h, /* Clixon handle */
|
||||
empty_rpc(clixon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -353,7 +353,7 @@ empty_rpc(clicon_handle h, /* Clixon handle */
|
|||
* The RPC returns the incoming parameters
|
||||
*/
|
||||
static int
|
||||
example_rpc(clicon_handle h, /* Clixon handle */
|
||||
example_rpc(clixon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -367,7 +367,7 @@ example_rpc(clicon_handle h, /* Clixon handle */
|
|||
|
||||
/* get namespace from rpc name, return back in each output parameter */
|
||||
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<rpc-reply xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -395,7 +395,7 @@ example_rpc(clicon_handle h, /* Clixon handle */
|
|||
/*! This will be called as a hook right after the original system copy-config
|
||||
*/
|
||||
static int
|
||||
example_copy_extra(clicon_handle h, /* Clixon handle */
|
||||
example_copy_extra(clixon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -414,7 +414,7 @@ example_copy_extra(clicon_handle h, /* Clixon handle */
|
|||
* @note callback is hardcoded C, while registration is controlled by -- -a option
|
||||
*/
|
||||
static int
|
||||
example_action_reset(clicon_handle h, /* Clixon handle */
|
||||
example_action_reset(clixon_handle h, /* Clixon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
|
|
@ -453,7 +453,7 @@ example_action_reset(clicon_handle h, /* Clixon handle */
|
|||
* @see example_statefile where state is read from file and also pagination
|
||||
*/
|
||||
int
|
||||
example_statedata(clicon_handle h,
|
||||
example_statedata(clixon_handle h,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
cxobj *xstate)
|
||||
|
|
@ -471,7 +471,7 @@ example_statedata(clicon_handle h,
|
|||
if (!_state)
|
||||
goto ok;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
|
|
@ -549,7 +549,7 @@ example_statedata(clicon_handle h,
|
|||
* @see example_statefile where state is programmatically added
|
||||
*/
|
||||
int
|
||||
example_statefile(clicon_handle h,
|
||||
example_statefile(clixon_handle h,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
cxobj *xstate)
|
||||
|
|
@ -574,7 +574,7 @@ example_statefile(clicon_handle h,
|
|||
if (_state_file_cached == 0 ||
|
||||
_state_xml_cache == NULL){
|
||||
if ((fp = fopen(_state_file, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", _state_file);
|
||||
goto done;
|
||||
}
|
||||
if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
|
||||
|
|
@ -641,7 +641,7 @@ example_pagination(void *h0,
|
|||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h = (clicon_handle)h0;
|
||||
clixon_handle h = (clixon_handle)h0;
|
||||
int locked;
|
||||
uint32_t offset;
|
||||
uint32_t limit;
|
||||
|
|
@ -675,7 +675,7 @@ example_pagination(void *h0,
|
|||
if (_state_file_cached == 0 ||
|
||||
_state_xml_cache == NULL){
|
||||
if ((fp = fopen(_state_file, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", _state_file);
|
||||
goto done;
|
||||
}
|
||||
if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
|
||||
|
|
@ -745,7 +745,7 @@ example_pagination(void *h0,
|
|||
* @retval -1 Fatal error
|
||||
*/
|
||||
int
|
||||
example_lockdb(clicon_handle h,
|
||||
example_lockdb(clixon_handle h,
|
||||
char *db,
|
||||
int lock,
|
||||
int id)
|
||||
|
|
@ -777,7 +777,7 @@ example_lockdb(clicon_handle h,
|
|||
* @retval -1 Error in one callback
|
||||
*/
|
||||
int
|
||||
example_extension(clicon_handle h,
|
||||
example_extension(clixon_handle h,
|
||||
yang_stmt *yext,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
|
|
@ -841,7 +841,7 @@ static const map_str2str namespace_map[] = {
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
example_upgrade(clicon_handle h,
|
||||
example_upgrade(clixon_handle h,
|
||||
const char *db,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msd)
|
||||
|
|
@ -891,7 +891,7 @@ example_upgrade(clicon_handle h,
|
|||
mypath = ms->ms_s0;
|
||||
mynamespace = ms->ms_s1;
|
||||
if (xml_nsctx_get_prefix(nsc, mynamespace, &myprefix) == 0){
|
||||
clicon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map",
|
||||
clixon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map",
|
||||
mynamespace);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -933,7 +933,7 @@ example_upgrade(clicon_handle h,
|
|||
* @see RFC 8528
|
||||
*/
|
||||
int
|
||||
main_yang_mount(clicon_handle h,
|
||||
main_yang_mount(clixon_handle h,
|
||||
cxobj *xt,
|
||||
int *config,
|
||||
validate_level *vl,
|
||||
|
|
@ -948,7 +948,7 @@ main_yang_mount(clicon_handle h,
|
|||
*vl = VL_FULL;
|
||||
if (yanglib && _mount_yang){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">");
|
||||
|
|
@ -999,7 +999,7 @@ main_yang_mount(clicon_handle h,
|
|||
* - Rename /interfaces/interface/description to descr
|
||||
*/
|
||||
static int
|
||||
upgrade_2014_to_2016(clicon_handle h,
|
||||
upgrade_2014_to_2016(clixon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
|
|
@ -1103,7 +1103,7 @@ 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,
|
||||
upgrade_2016_to_2018(clixon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
|
|
@ -1159,7 +1159,7 @@ upgrade_2016_to_2018(clicon_handle h,
|
|||
cbuf *cb;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -1204,7 +1204,7 @@ upgrade_2016_to_2018(clicon_handle h,
|
|||
* - Rename /interfaces/interface/description to descr
|
||||
*/
|
||||
static int
|
||||
upgrade_interfaces(clicon_handle h,
|
||||
upgrade_interfaces(clixon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
|
|
@ -1216,7 +1216,7 @@ upgrade_interfaces(clicon_handle h,
|
|||
int retval = -1;
|
||||
|
||||
if (_module_upgrade) /* For testing */
|
||||
clicon_log(LOG_NOTICE, "%s %s op:%s from:%d to:%d",
|
||||
clixon_log(h, LOG_NOTICE, "%s %s op:%s from:%d to:%d",
|
||||
__FUNCTION__, ns,
|
||||
(op&XML_FLAG_ADD)?"ADD":(op&XML_FLAG_DEL)?"DEL":"CHANGE",
|
||||
from, to);
|
||||
|
|
@ -1254,7 +1254,7 @@ upgrade_interfaces(clicon_handle h,
|
|||
* In this example, a loopback parameter is added
|
||||
*/
|
||||
int
|
||||
example_reset(clicon_handle h,
|
||||
example_reset(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1279,14 +1279,14 @@ example_reset(clicon_handle h,
|
|||
/* xmldb_put requires modification tree to be: <config>... */
|
||||
xml_name_set(xt, "config");
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Merge user reset state */
|
||||
if ((ret = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, 0, "Error when writing to XML database: %s",
|
||||
clixon_err(OE_XML, 0, "Error when writing to XML database: %s",
|
||||
cbuf_get(cbret));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1312,7 +1312,7 @@ example_reset(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
example_start(clicon_handle h)
|
||||
example_start(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -1326,7 +1326,7 @@ example_start(clicon_handle h)
|
|||
*/
|
||||
if (_action_instanceid){
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
clixon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
if (yang_abs_schema_nodeid(yspec, _action_instanceid, &ya) == 0){
|
||||
|
|
@ -1348,7 +1348,7 @@ example_start(clicon_handle h)
|
|||
* the main event loop is entered.
|
||||
*/
|
||||
int
|
||||
example_daemon(clicon_handle h)
|
||||
example_daemon(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
int ret;
|
||||
|
|
@ -1360,7 +1360,7 @@ example_daemon(clicon_handle h)
|
|||
if (_state && _state_file && _state_file_cached){
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((fp = fopen(_state_file, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", _state_file);
|
||||
goto done;
|
||||
}
|
||||
/* Need to be yang bound for eg xml_copy_marked() in example_pagination
|
||||
|
|
@ -1382,7 +1382,7 @@ example_daemon(clicon_handle h)
|
|||
}
|
||||
|
||||
int
|
||||
example_exit(clicon_handle h)
|
||||
example_exit(clixon_handle h)
|
||||
{
|
||||
if (_state_xml_cache){
|
||||
xml_free(_state_xml_cache);
|
||||
|
|
@ -1392,7 +1392,7 @@ example_exit(clicon_handle h)
|
|||
}
|
||||
|
||||
/* Forward declaration */
|
||||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||
clixon_plugin_api *clixon_plugin_init(clixon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
|
|
@ -1419,13 +1419,13 @@ static clixon_plugin_api api = {
|
|||
/*! Backend plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval NULL Error
|
||||
* @retval api Pointer to API struct
|
||||
* In this example, you can pass -r, -s, -u to control the behaviour, mainly
|
||||
* for use in the test suites.
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
struct timeval retention = {0,0};
|
||||
int argc; /* command-line options (after --) */
|
||||
|
|
@ -1482,7 +1482,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
break;
|
||||
}
|
||||
if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
|
||||
goto done;
|
||||
}
|
||||
if (_state_file){
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/syslog.h>
|
||||
|
||||
/* clicon */
|
||||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* Clicon library functions. */
|
||||
|
|
@ -84,7 +84,7 @@ static char *_validate_fail_xpath = NULL;
|
|||
static int _validate_fail_toggle = 0; /* fail at validate and commit */
|
||||
|
||||
int
|
||||
nacm_begin(clicon_handle h,
|
||||
nacm_begin(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -94,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(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -103,7 +103,7 @@ nacm_validate(clicon_handle h,
|
|||
if (_validate_fail_toggle==0 &&
|
||||
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
|
||||
_validate_fail_toggle = 1; /* toggle if triggered */
|
||||
clicon_err(OE_XML, 0, "User error");
|
||||
clixon_err(OE_XML, 0, "User error");
|
||||
return -1; /* induce fail */
|
||||
}
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ nacm_validate(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_complete(clicon_handle h,
|
||||
nacm_complete(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -122,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(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -131,7 +131,7 @@ nacm_commit(clicon_handle h,
|
|||
if (_validate_fail_toggle==1 &&
|
||||
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
|
||||
_validate_fail_toggle = 0; /* toggle if triggered */
|
||||
clicon_err(OE_XML, 0, "User error");
|
||||
clixon_err(OE_XML, 0, "User error");
|
||||
return -1; /* induce fail */
|
||||
}
|
||||
}
|
||||
|
|
@ -139,7 +139,7 @@ nacm_commit(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_commit_done(clicon_handle h,
|
||||
nacm_commit_done(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -148,7 +148,7 @@ nacm_commit_done(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_revert(clicon_handle h,
|
||||
nacm_revert(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -157,7 +157,7 @@ nacm_revert(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_end(clicon_handle h,
|
||||
nacm_end(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -166,7 +166,7 @@ nacm_end(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
nacm_abort(clicon_handle h,
|
||||
nacm_abort(clixon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
if (_transaction_log)
|
||||
|
|
@ -187,7 +187,7 @@ nacm_abort(clicon_handle h,
|
|||
* Real code would poll state
|
||||
*/
|
||||
int
|
||||
nacm_statedata(clicon_handle h,
|
||||
nacm_statedata(clixon_handle h,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
cxobj *xstate)
|
||||
|
|
@ -209,7 +209,7 @@ nacm_statedata(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||
clixon_plugin_api *clixon_plugin_init(clixon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
"nacm", /* name */ /*--- Common fields. ---*/
|
||||
|
|
@ -230,11 +230,11 @@ static clixon_plugin_api api = {
|
|||
/*! Backend plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval NULL Error
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
char *nacm_mode;
|
||||
int argc; /* command-line options (after --) */
|
||||
|
|
@ -259,7 +259,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
|
||||
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
|
||||
if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){
|
||||
clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
|
||||
clixon_log(h, 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)
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <signal.h> /* matching strings */
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <cligen/cligen.h>
|
||||
#include <clixon/clixon.h>
|
||||
#include <clixon/clixon_cli.h>
|
||||
|
|
@ -67,7 +67,9 @@ static char *_mount_namespace = NULL;
|
|||
/*! Example cli function
|
||||
*/
|
||||
int
|
||||
mycallback(clicon_handle h, cvec *cvv, cvec *argv)
|
||||
mycallback(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xret = NULL;
|
||||
|
|
@ -101,7 +103,7 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
|
|||
/*! Example "downcall", ie initiate an RPC to the backend
|
||||
*/
|
||||
int
|
||||
example_client_rpc(clicon_handle h,
|
||||
example_client_rpc(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -129,7 +131,7 @@ example_client_rpc(clicon_handle h,
|
|||
if (clicon_rpc_netconf_xml(h, xrpc, &xret, NULL) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
clixon_netconf_error(h, xerr, "Get configuration", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
|
||||
goto done;
|
||||
}
|
||||
/* Print result */
|
||||
|
|
@ -168,7 +170,7 @@ cli_incstr(cligen_handle h,
|
|||
if (cv == NULL || cv_type_get(cv) != CGV_STRING)
|
||||
return 0;
|
||||
if ((str = cv_string_get(cv)) == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "cv string is NULL");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "cv string is NULL");
|
||||
return -1;
|
||||
}
|
||||
for (i=0; i<strlen(str); i++)
|
||||
|
|
@ -190,7 +192,7 @@ cli_incstr(cligen_handle h,
|
|||
* @see RFC 8528
|
||||
*/
|
||||
int
|
||||
example_cli_yang_mount(clicon_handle h,
|
||||
example_cli_yang_mount(clixon_handle h,
|
||||
cxobj *xt,
|
||||
int *config,
|
||||
validate_level *vl,
|
||||
|
|
@ -205,7 +207,7 @@ example_cli_yang_mount(clicon_handle h,
|
|||
*vl = VL_FULL;
|
||||
if (yanglib && _mount_yang){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">");
|
||||
|
|
@ -242,7 +244,7 @@ example_cli_yang_mount(clicon_handle h,
|
|||
* @see netconf_err2cb this errmsg is the same as the default
|
||||
*/
|
||||
int
|
||||
example_cli_errmsg(clicon_handle h,
|
||||
example_cli_errmsg(clixon_handle h,
|
||||
cxobj *xerr,
|
||||
cbuf *cberr)
|
||||
{
|
||||
|
|
@ -281,7 +283,7 @@ example_cli_errmsg(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
example_version(clicon_handle h,
|
||||
example_version(clixon_handle h,
|
||||
FILE *f)
|
||||
{
|
||||
cligen_output(f, "Clixon main example version 0\n");
|
||||
|
|
@ -302,11 +304,11 @@ static clixon_plugin_api api = {
|
|||
/*! CLI plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval NULL Error
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
struct timeval tv;
|
||||
int c;
|
||||
|
|
@ -330,7 +332,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
break;
|
||||
}
|
||||
if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
|
||||
goto done;
|
||||
}
|
||||
/* XXX Not implemented: CLI completion for mountpoints, see clixon-controller
|
||||
|
|
|
|||
|
|
@ -55,13 +55,13 @@
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
int
|
||||
plugin_start(clicon_handle h)
|
||||
plugin_start(clixon_handle h)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
plugin_exit(clicon_handle h)
|
||||
plugin_exit(clixon_handle h)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ plugin_exit(clicon_handle h)
|
|||
/*! Local example netconf rpc callback
|
||||
*/
|
||||
int
|
||||
netconf_client_rpc(clicon_handle h,
|
||||
netconf_client_rpc(clixon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
|
|
@ -81,7 +81,7 @@ netconf_client_rpc(clicon_handle h,
|
|||
|
||||
/* get namespace from rpc name, return back in each output parameter */
|
||||
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -103,7 +103,7 @@ netconf_client_rpc(clicon_handle h,
|
|||
return 0;
|
||||
}
|
||||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
clixon_plugin_api * clixon_plugin_init(clixon_handle h);
|
||||
|
||||
static struct clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
|
|
@ -115,11 +115,11 @@ static struct clixon_plugin_api api = {
|
|||
/*! Netconf plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval NULL Error
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__);
|
||||
/* Register local netconf rpc client (note not backend rpc client) */
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
#include <clixon/clixon_restconf.h> /* minor use */
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ b64_decode(const char *src,
|
|||
* @note: Three hardwired users: andy, wilma, guest w password "bar".
|
||||
*/
|
||||
static int
|
||||
example_basic_auth(clicon_handle h,
|
||||
example_basic_auth(clixon_handle h,
|
||||
void *req,
|
||||
char **authp)
|
||||
{
|
||||
|
|
@ -222,7 +222,7 @@ example_basic_auth(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (authp == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* At this point in the code we must use HTTP basic authentication */
|
||||
|
|
@ -235,7 +235,7 @@ example_basic_auth(clicon_handle h,
|
|||
auth += strlen("Basic ");
|
||||
authlen = strlen(auth)*2;
|
||||
if ((user = malloc(authlen)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(user, 0, authlen);
|
||||
|
|
@ -289,7 +289,7 @@ example_basic_auth(clicon_handle h,
|
|||
* @note authp should be malloced
|
||||
*/
|
||||
int
|
||||
example_restconf_credentials(clicon_handle h,
|
||||
example_restconf_credentials(clixon_handle h,
|
||||
void *req,
|
||||
clixon_auth_type_t auth_type,
|
||||
char **authp)
|
||||
|
|
@ -317,7 +317,7 @@ example_restconf_credentials(clicon_handle h,
|
|||
/*! Local example restconf rpc callback
|
||||
*/
|
||||
int
|
||||
restconf_client_rpc(clicon_handle h,
|
||||
restconf_client_rpc(clixon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
|
|
@ -329,7 +329,7 @@ restconf_client_rpc(clicon_handle h,
|
|||
|
||||
/* get namespace from rpc name, return back in each output parameter */
|
||||
if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<rpc-reply xmlns=\"%s\">", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -352,7 +352,7 @@ restconf_client_rpc(clicon_handle h,
|
|||
/*! Start example restonf plugin. Set authentication method
|
||||
*/
|
||||
int
|
||||
example_restconf_start(clicon_handle h)
|
||||
example_restconf_start(clixon_handle h)
|
||||
{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
return 0;
|
||||
|
|
@ -372,7 +372,7 @@ example_restconf_start(clicon_handle h)
|
|||
* @see RFC 8528
|
||||
*/
|
||||
int
|
||||
restconf_yang_mount(clicon_handle h,
|
||||
restconf_yang_mount(clixon_handle h,
|
||||
cxobj *xt,
|
||||
int *config,
|
||||
validate_level *vl,
|
||||
|
|
@ -387,7 +387,7 @@ restconf_yang_mount(clicon_handle h,
|
|||
*vl = VL_FULL;
|
||||
if (yanglib && _mount_yang){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">");
|
||||
|
|
@ -414,7 +414,7 @@ restconf_yang_mount(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
clixon_plugin_api * clixon_plugin_init(clixon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
|
|
@ -428,12 +428,12 @@ static clixon_plugin_api api = {
|
|||
/*! Restconf plugin initialization
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval NULL Error
|
||||
* @retval api Pointer to API struct
|
||||
* Arguments are argc/argv after --
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
clixon_plugin_init(clixon_handle h)
|
||||
{
|
||||
int argc; /* command-line options (after --) */
|
||||
char **argv = NULL;
|
||||
|
|
@ -457,7 +457,7 @@ clixon_plugin_init(clicon_handle h)
|
|||
break;
|
||||
}
|
||||
if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts");
|
||||
goto done;
|
||||
}
|
||||
/* Register local netconf rpc client (note not backend rpc client) */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue