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:
Olof hagsand 2023-11-13 10:12:52 +01:00
parent 261469be16
commit 24a4991ec8
199 changed files with 4668 additions and 4158 deletions

View file

@ -452,6 +452,7 @@ fi
function err(){
expect=$1
ret=$2
stty $STTYSETTINGS >/dev/null
echo -e "\e[31m\nError in Test$testnr [$testname]:"
if [ $# -gt 0 ]; then
echo "Expected"
@ -470,6 +471,7 @@ function err(){
# Don't print diffs
function err1(){
stty $STTYSETTINGS >/dev/null
echo -e "\e[31m\nError in Test$testnr [$testname]:"
if [ $# -gt 0 ]; then
echo "Expected: $1"
@ -601,9 +603,10 @@ function wait_backend(){
# Start restconf daemon
# @see wait_restconf
function start_restconf(){
# remove -g
local clixon_restconf_="${clixon_restconf#sudo -g * }"
# Start in background
# echo "sudo -u $wwwstartuser $clixon_restconf_ $RCLOG -D $DBG $*"
# echo "sudo -u $wwwstartuser ${clixon_restconf_} $RCLOG -D $DBG $*"
sudo -u $wwwstartuser $clixon_restconf_ $RCLOG -D $DBG $* </dev/null &>/dev/null &
if [ $? -ne 0 ]; then
err1 "expected 0" "$?"

View file

@ -96,21 +96,21 @@ cat<<EOF > $cfile
#include <sys/time.h>
#include <sys/syslog.h>
/* clicon */
/* cligen */
#include <cligen/cligen.h>
/* Clicon library functions. */
/* Clixon */
#include <clixon/clixon.h>
/* These include signatures for plugin and transaction callbacks. */
#include <clixon/clixon_backend.h>
static int
trigger_rpc(clicon_handle h, /* Clicon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */
void *regarg) /* Argument given at register */
trigger_rpc(clixon_handle h, /* Clicon handle */
cxobj *xe, /* Request: <rpc><xn></rpc> */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg, /* client_entry */
void *regarg) /* Argument given at register */
{
int retval = -1;
cxobj *xret = NULL;
@ -124,9 +124,9 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
if (xmldb_get(h, "running", NULL, "/c", &xret) < 0)
goto done;
clicon_debug(1, "%s xret:%s", __FUNCTION__, xml_name(xret));
clixon_debug(CLIXON_DBG_DEFAULT, "%s xret:%s", __FUNCTION__, xml_name(xret));
xc = xpath_first(xret, NULL, "/c");
clicon_debug(1, "%s xc:%s", __FUNCTION__, xml_name(xc));
clixon_debug(CLIXON_DBG_DEFAULT, "%s xc:%s", __FUNCTION__, xml_name(xc));
/* Method 1 loop */
x = NULL;
@ -140,19 +140,19 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
break;
}
}
clicon_debug(1, "%s Method 1: val:%s", __FUNCTION__, val?val:"null");
clixon_debug(CLIXON_DBG_DEFAULT, "%s Method 1: val:%s", __FUNCTION__, val?val:"null");
/* Method 2 xpath */
val = NULL;
if ((x = xpath_first(xc, NULL, "y3[k=5]")) != NULL)
val = xml_find_body(x, "val");
clicon_debug(1, "%s Method 2: val:%s", __FUNCTION__, val?val:"null");
clixon_debug(CLIXON_DBG_DEFAULT, "%s Method 2: val:%s", __FUNCTION__, val?val:"null");
/* Method 3 binsearch */
val = NULL;
/* Add key/value vector */
if ((cvk = cvec_new(0)) == NULL){
clicon_err(OE_YANG, errno, "cvec_new");
clixon_err(OE_YANG, errno, "cvec_new");
goto done;
}
if ((cv = cvec_add(cvk, CGV_STRING)) == NULL)
@ -168,12 +168,12 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
val = xml_find_body(clixon_xvec_i(xv,0), "val");
else
val = NULL;
clicon_debug(1, "%s Method 3: val:%s", __FUNCTION__, val?val:"null");
clixon_debug(CLIXON_DBG_DEFAULT, "%s Method 3: val:%s", __FUNCTION__, val?val:"null");
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
retval = 0;
done:
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval);
if (cvk)
cvec_free(cvk);
if (xret)
@ -183,7 +183,7 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
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 = {
"order", /* name */ /*--- Common fields. ---*/
@ -192,13 +192,13 @@ static clixon_plugin_api api = {
/*! Backend plugin initialization
* @param[in] h Clixon handle
* @retval NULL Error with clicon_err set
* @retval NULL
* @retval api Pointer to API struct
*/
clixon_plugin_api *
clixon_plugin_init(clicon_handle h)
clixon_plugin_init(clixon_handle h)
{
clicon_debug(1, "%s test-order", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s test-order", __FUNCTION__);
/* From example.yang (clicon) */
if (rpc_callback_register(h, trigger_rpc,

View file

@ -85,14 +85,14 @@ cat<<EOF > $cfile
* the main event loop is entered.
*/
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
clixon_plugin_api * clixon_plugin_init(clixon_handle h);
int plugin_start(clicon_handle h)
int plugin_start(clixon_handle h)
{
return 0;
}
int plugin_exit(clicon_handle h)
int plugin_exit(clixon_handle h)
{
return 0;
}
@ -103,7 +103,7 @@ private:
struct clixon_plugin_api api;
public:
netconf_test(plginit2_t* init, plgstart_t* start, plgexit_t* exit, const char* str = "c++ netconf test") : api()
netconf_test(plginit_t* init, plgstart_t* start, plgexit_t* exit, const char* str = "c++ netconf test") : api()
{
strcpy(api.ca_name, str);
api.ca_init = clixon_plugin_init;
@ -121,11 +121,11 @@ static netconf_test api(clixon_plugin_init, plugin_start, plugin_exit);
/*! Local example netconf rpc callback
*/
int example_rpc(clicon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *regarg)
int example_rpc(clixon_handle h,
cxobj *xe,
cbuf *cbret,
void *arg,
void *regarg)
{
int retval = -1;
cxobj *x = NULL;
@ -134,7 +134,7 @@ int example_rpc(clicon_handle h,
/* get namespace from rpc name, return back in each output parameter */
if ((ns = 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);
@ -157,12 +157,12 @@ int example_rpc(clicon_handle h,
/*! 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_api* clixon_plugin_init(clixon_handle h)
{
clicon_debug(1, "%s netconf", __FUNCTION__);
clixon_debug(1, "%s netconf", __FUNCTION__);
/* Register local netconf rpc client (note not backend rpc client) */
if (rpc_callback_register(h, example_rpc, NULL, "urn:example:clixon", "example") < 0)
return NULL;

View file

@ -77,6 +77,9 @@ cat<<EOF > $cfile
#include <stdint.h>
#include <syslog.h> // debug
#include <clixon/clixon_queue.h>
#include <clixon/clixon_hash.h>
#include <clixon/clixon_handle.h>
#include <clixon/clixon_log.h> // debug
#include <clixon/clixon_client.h>
@ -89,12 +92,13 @@ main(int argc,
clixon_client_handle ch = NULL; /* clixon client handle */
int s;
clicon_log_init("client", LOG_DEBUG, CLICON_LOG_STDERR); // debug
clicon_debug_init($debug, NULL); // debug
/* Provide a clixon config-file, get a clixon handle */
if ((h = clixon_client_init("$cfg")) == NULL)
return -1;
clixon_log_init(h, "client", LOG_DEBUG, CLIXON_LOG_STDERR);
clixon_err_init(h);
clixon_debug_init(h, $debug, NULL);
/* Make a connection over netconf or ssh/netconf */
if ((ch = clixon_client_connect(h, CLIXON_CLIENT_NETCONF, NULL)) == NULL)
return -1;