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
|
|
@ -78,7 +78,7 @@ CPPFLAGS = @CPPFLAGS@
|
|||
|
||||
INCLUDES = -I. @INCLUDES@ -I$(top_srcdir)/lib/clixon -I$(top_srcdir)/include -I$(top_srcdir)
|
||||
|
||||
SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_err.c clixon_event.c \
|
||||
SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_debug.c clixon_err.c clixon_event.c \
|
||||
clixon_string.c clixon_regex.c clixon_handle.c clixon_file.c \
|
||||
clixon_xml.c clixon_xml_io.c clixon_xml_sort.c clixon_xml_map.c clixon_xml_vec.c \
|
||||
clixon_xml_default.c clixon_xml_bind.c clixon_json.c clixon_proc.c \
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@
|
|||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_path.h"
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
/* typecast macro */
|
||||
#define _AY ((clixon_api_path_yacc *)_ay)
|
||||
|
||||
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_api_path_parsetext, _AY->ay_linenum); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_api_path_parsetext, _AY->ay_linenum); YYERROR;}
|
||||
|
||||
/* add _yy to error parameters */
|
||||
#define YY_(msgid) msgid
|
||||
|
|
@ -103,12 +103,14 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_path.h"
|
||||
|
|
@ -133,7 +135,7 @@ void
|
|||
clixon_api_path_parseerror(void *_ay,
|
||||
char *s)
|
||||
{
|
||||
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
|
||||
clixon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
|
||||
_AY->ay_name,
|
||||
_AY->ay_linenum,
|
||||
s,
|
||||
|
|
@ -186,17 +188,17 @@ path_new(char *module_name,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, module_name, id);
|
||||
if ((cp = malloc(sizeof(*cp))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(cp, 0, sizeof(*cp));
|
||||
if (module_name)
|
||||
if ((cp->cp_prefix = strdup(module_name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if ((cp->cp_id = strdup(id)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
return cp;
|
||||
|
|
@ -220,11 +222,11 @@ keyval_add(cvec *cvv,
|
|||
goto done;
|
||||
if (cvv == NULL &&
|
||||
(cvv = cvec_new(0)) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (cvec_append_var(cvv, cv) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_append_var");
|
||||
clixon_err(OE_UNIX, errno, "cvec_append_var");
|
||||
cvv = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -243,16 +245,16 @@ keyval_set(char *name,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name?name:"NULL", val);
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_new");
|
||||
clixon_err(OE_UNIX, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (name && cv_name_set(cv, name) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
cv = NULL;
|
||||
goto done;
|
||||
}
|
||||
if (cv_string_set(cv, val) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
cv = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_options.h"
|
||||
|
|
@ -84,7 +85,7 @@
|
|||
*/
|
||||
struct clixon_client_handle{
|
||||
uint32_t cch_magic; /* magic number */
|
||||
clicon_handle cch_h; /* Clixon handle */
|
||||
clixon_handle cch_h; /* Clixon handle */
|
||||
clixon_client_type cch_type; /* Clixon socket type */
|
||||
int cch_socket; /* Input/output socket */
|
||||
char *cch_descr; /* Description of socket / peer for logging XXX NYI */
|
||||
|
|
@ -117,11 +118,11 @@ clixon_client_handle_check(clixon_client_handle ch)
|
|||
clixon_handle
|
||||
clixon_client_init(const char *config_file)
|
||||
{
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
/* Initiate CLICON handle. CLIgen is also initialized */
|
||||
if ((h = clicon_handle_init()) == NULL)
|
||||
if ((h = clixon_handle_init()) == NULL)
|
||||
return NULL;
|
||||
/* Set clixon config file - reuse the one in the main installation */
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE",
|
||||
|
|
@ -138,10 +139,10 @@ clixon_client_init(const char *config_file)
|
|||
* @see clixon_client_init
|
||||
*/
|
||||
int
|
||||
clixon_client_terminate(clicon_handle h)
|
||||
clixon_client_terminate(clixon_handle h)
|
||||
{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
clicon_handle_exit(h);
|
||||
clixon_handle_exit(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -171,15 +172,15 @@ clixon_client_lock(clixon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (db == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "Expected db");
|
||||
clixon_err(OE_XML, EINVAL, "Expected db");
|
||||
goto done;
|
||||
}
|
||||
if ((msg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((msgret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(msg, "<rpc xmlns=\"%s\" %s>"
|
||||
|
|
@ -191,14 +192,14 @@ clixon_client_lock(clixon_handle h,
|
|||
goto done;
|
||||
if (eof){
|
||||
close(sock);
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_parse_string(cbuf_get(msgret), YB_NONE, NULL, &xret, NULL) < 0)
|
||||
goto done;
|
||||
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL){
|
||||
xd = xml_parent(xd); /* point to rpc-reply */
|
||||
clixon_netconf_error(h, xd, "Get config", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xd, "Get configuration");
|
||||
goto done; /* Not fatal */
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -231,7 +232,7 @@ clixon_client_hello(int sock,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((msg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
// cprintf(msg, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||
|
|
@ -254,7 +255,7 @@ clixon_client_hello(int sock,
|
|||
/*!
|
||||
*/
|
||||
static int
|
||||
clixon_client_connect_netconf(clicon_handle h,
|
||||
clixon_client_connect_netconf(clixon_handle h,
|
||||
struct clixon_client_handle *cch)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -269,14 +270,14 @@ clixon_client_connect_netconf(clicon_handle h,
|
|||
if (clixon_debug_get() != 0)
|
||||
nr += 2;
|
||||
if ((argv = calloc(nr, sizeof(char *))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
i = 0;
|
||||
if ((netconf_bin = getenv("CLIXON_NETCONF_BIN")) == NULL)
|
||||
netconf_bin = CLIXON_NETCONF_BIN;
|
||||
if (stat(netconf_bin, &st) < 0){
|
||||
clicon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=",
|
||||
clixon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=",
|
||||
netconf_bin);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -293,7 +294,7 @@ clixon_client_connect_netconf(clicon_handle h,
|
|||
}
|
||||
argv[i++] = NULL;
|
||||
assert(i==nr);
|
||||
if (clixon_proc_socket(argv, SOCK_DGRAM, &cch->cch_pid, &cch->cch_socket) < 0){
|
||||
if (clixon_proc_socket(h, argv, SOCK_DGRAM, &cch->cch_pid, &cch->cch_socket) < 0){
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -304,7 +305,7 @@ clixon_client_connect_netconf(clicon_handle h,
|
|||
/*!
|
||||
*/
|
||||
static int
|
||||
clixon_client_connect_ssh(clicon_handle h,
|
||||
clixon_client_connect_ssh(clixon_handle h,
|
||||
struct clixon_client_handle *cch,
|
||||
const char *dest)
|
||||
{
|
||||
|
|
@ -318,12 +319,12 @@ clixon_client_connect_ssh(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
nr = 5;
|
||||
if ((argv = calloc(nr, sizeof(char *))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
i = 0;
|
||||
if (stat(ssh_bin, &st) < 0){
|
||||
clicon_err(OE_NETCONF, errno, "ssh binary %s", ssh_bin);
|
||||
clixon_err(OE_NETCONF, errno, "ssh binary %s", ssh_bin);
|
||||
goto done;
|
||||
}
|
||||
argv[i++] = ssh_bin;
|
||||
|
|
@ -334,7 +335,7 @@ clixon_client_connect_ssh(clicon_handle h,
|
|||
assert(i==nr);
|
||||
for (i=0;i<nr;i++)
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s: argv[%d]:%s", __FUNCTION__, i, argv[i]);
|
||||
if (clixon_proc_socket(argv, SOCK_STREAM, &cch->cch_pid, &cch->cch_socket) < 0){
|
||||
if (clixon_proc_socket(h, argv, SOCK_STREAM, &cch->cch_pid, &cch->cch_socket) < 0){
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -352,7 +353,7 @@ clixon_client_connect_ssh(clicon_handle h,
|
|||
* @see clixon_client_disconnect Close the socket returned here
|
||||
*/
|
||||
clixon_client_handle
|
||||
clixon_client_connect(clicon_handle h,
|
||||
clixon_client_connect(clixon_handle h,
|
||||
clixon_client_type socktype,
|
||||
const char *dest)
|
||||
{
|
||||
|
|
@ -361,7 +362,7 @@ clixon_client_connect(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((cch = malloc(sz)) == NULL){
|
||||
clicon_err(OE_NETCONF, errno, "malloc");
|
||||
clixon_err(OE_NETCONF, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(cch, 0, sz);
|
||||
|
|
@ -382,7 +383,7 @@ clixon_client_connect(clicon_handle h,
|
|||
if (clixon_client_connect_ssh(h, cch, dest) < 0)
|
||||
goto err;
|
||||
#else
|
||||
clicon_err(OE_UNIX, 0, "No ssh bin");
|
||||
clixon_err(OE_UNIX, 0, "No ssh bin");
|
||||
goto done;
|
||||
#endif
|
||||
break;
|
||||
|
|
@ -413,7 +414,7 @@ clixon_client_disconnect(clixon_client_handle ch)
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (cch == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "Expected cch handle");
|
||||
clixon_err(OE_XML, EINVAL, "Expected cch handle");
|
||||
goto done;
|
||||
}
|
||||
/* unlock (if locked) */
|
||||
|
|
@ -484,7 +485,7 @@ clixon_xml_bottom(cxobj *xtop,
|
|||
* @note configurable netconf framing type, now hardwired to 0
|
||||
*/
|
||||
static int
|
||||
clixon_client_get_xdata(clicon_handle h,
|
||||
clixon_client_get_xdata(clixon_handle h,
|
||||
int sock,
|
||||
const char *descr,
|
||||
const char *namespace,
|
||||
|
|
@ -502,11 +503,11 @@ clixon_client_get_xdata(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((msg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((msgret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(msg, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -534,14 +535,14 @@ clixon_client_get_xdata(clicon_handle h,
|
|||
goto done;
|
||||
if (eof){
|
||||
close(sock);
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_parse_string(cbuf_get(msgret), YB_NONE, NULL, &xret, NULL) < 0)
|
||||
goto done;
|
||||
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL){
|
||||
xd = xml_parent(xd); /* point to rpc-reply */
|
||||
clixon_netconf_error(h, xd, "Get config", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xd, "Get configuration");
|
||||
goto done; /* Not fatal */
|
||||
}
|
||||
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
|
||||
|
|
@ -577,7 +578,7 @@ clixon_client_get_xdata(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
clixon_client_get_body_val(clicon_handle h,
|
||||
clixon_client_get_body_val(clixon_handle h,
|
||||
int sock,
|
||||
const char *descr,
|
||||
const char *namespace,
|
||||
|
|
@ -590,24 +591,24 @@ clixon_client_get_body_val(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (val == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "Expected val");
|
||||
clixon_err(OE_XML, EINVAL, "Expected val");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_client_get_xdata(h, sock, descr, namespace, xpath, &xdata) < 0)
|
||||
goto done;
|
||||
if (xdata == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No xml obj found");
|
||||
clixon_err(OE_XML, EINVAL, "No xml obj found");
|
||||
goto done;
|
||||
}
|
||||
/* Is this an error, maybe an "unset" retval ? */
|
||||
if (xml_child_nr_type(xdata, CX_ELMNT) == 0){
|
||||
clicon_err(OE_XML, EINVAL, "Value not found");
|
||||
clixon_err(OE_XML, EINVAL, "Value not found");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_bottom(xdata, &xobj) < 0)
|
||||
goto done;
|
||||
if (xobj == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No xml value found");
|
||||
clixon_err(OE_XML, EINVAL, "No xml value found");
|
||||
goto done;
|
||||
}
|
||||
*val = xml_body(xobj);
|
||||
|
|
@ -644,11 +645,11 @@ clixon_client_get_bool(clixon_client_handle ch,
|
|||
namespace, xpath, &val) < 0)
|
||||
goto done;
|
||||
if ((ret = parse_bool(val, &val0, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_bool");
|
||||
clixon_err(OE_XML, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "%s", reason);
|
||||
clixon_err(OE_XML, EINVAL, "%s", reason);
|
||||
goto done;
|
||||
}
|
||||
*rval = (int)val0;
|
||||
|
|
@ -717,11 +718,11 @@ clixon_client_get_uint8(clixon_client_handle ch,
|
|||
namespace, xpath, &val) < 0)
|
||||
goto done;
|
||||
if ((ret = parse_uint8(val, rval, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_bool");
|
||||
clixon_err(OE_XML, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "%s", reason);
|
||||
clixon_err(OE_XML, EINVAL, "%s", reason);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -757,11 +758,11 @@ clixon_client_get_uint16(clixon_client_handle ch,
|
|||
namespace, xpath, &val) < 0)
|
||||
goto done;
|
||||
if ((ret = parse_uint16(val, rval, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_bool");
|
||||
clixon_err(OE_XML, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "%s", reason);
|
||||
clixon_err(OE_XML, EINVAL, "%s", reason);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -797,15 +798,15 @@ clixon_client_get_uint32(clixon_client_handle ch,
|
|||
namespace, xpath, &val) < 0)
|
||||
goto done;
|
||||
if (val == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "val is NULL");
|
||||
clixon_err(OE_XML, EFAULT, "val is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = parse_uint32(val, rval, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_bool");
|
||||
clixon_err(OE_XML, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "%s", reason);
|
||||
clixon_err(OE_XML, EINVAL, "%s", reason);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -842,11 +843,11 @@ clixon_client_get_uint64(clixon_client_handle ch,
|
|||
namespace, xpath, &val) < 0)
|
||||
goto done;
|
||||
if ((ret = parse_uint64(val, rval, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_bool");
|
||||
clixon_err(OE_XML, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "%s", reason);
|
||||
clixon_err(OE_XML, EINVAL, "%s", reason);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -59,13 +59,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_sort.h"
|
||||
|
|
@ -87,7 +88,7 @@
|
|||
* @see clicon_option_str
|
||||
*/
|
||||
int
|
||||
clicon_data_get(clicon_handle h,
|
||||
clicon_data_get(clixon_handle h,
|
||||
const char *name,
|
||||
char **val)
|
||||
{
|
||||
|
|
@ -110,7 +111,7 @@ clicon_data_get(clicon_handle h,
|
|||
* @see clicon_option_str_set
|
||||
*/
|
||||
int
|
||||
clicon_data_set(clicon_handle h,
|
||||
clicon_data_set(clixon_handle h,
|
||||
const char *name,
|
||||
char *val)
|
||||
{
|
||||
|
|
@ -128,7 +129,7 @@ clicon_data_set(clicon_handle h,
|
|||
* @see clicon_option_del
|
||||
*/
|
||||
int
|
||||
clicon_data_del(clicon_handle h,
|
||||
clicon_data_del(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -146,7 +147,7 @@ clicon_data_del(clicon_handle h,
|
|||
* @see clicon_option_str
|
||||
*/
|
||||
int
|
||||
clicon_ptr_get(clicon_handle h,
|
||||
clicon_ptr_get(clixon_handle h,
|
||||
const char *name,
|
||||
void **ptr)
|
||||
{
|
||||
|
|
@ -173,7 +174,7 @@ clicon_ptr_get(clicon_handle h,
|
|||
* @see clicon_option_str_set
|
||||
*/
|
||||
int
|
||||
clicon_ptr_set(clicon_handle h,
|
||||
clicon_ptr_set(clixon_handle h,
|
||||
const char *name,
|
||||
void *ptr)
|
||||
{
|
||||
|
|
@ -191,7 +192,7 @@ clicon_ptr_set(clicon_handle h,
|
|||
* @see clicon_option_del
|
||||
*/
|
||||
int
|
||||
clicon_ptr_del(clicon_handle h,
|
||||
clicon_ptr_del(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -212,7 +213,7 @@ clicon_ptr_del(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
cvec *
|
||||
clicon_data_cvec_get(clicon_handle h,
|
||||
clicon_data_cvec_get(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
cvec *cvv = NULL;
|
||||
|
|
@ -229,7 +230,7 @@ clicon_data_cvec_get(clicon_handle h,
|
|||
* @param[in] cvv CLIgen variable vector (cvv) (malloced)
|
||||
*/
|
||||
int
|
||||
clicon_data_cvec_set(clicon_handle h,
|
||||
clicon_data_cvec_set(clixon_handle h,
|
||||
const char *name,
|
||||
cvec *cvv)
|
||||
{
|
||||
|
|
@ -247,7 +248,7 @@ clicon_data_cvec_set(clicon_handle h,
|
|||
* @param[in] name Name
|
||||
*/
|
||||
int
|
||||
clicon_data_cvec_del(clicon_handle h,
|
||||
clicon_data_cvec_del(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
cvec *cvv = NULL;
|
||||
|
|
@ -260,7 +261,7 @@ clicon_data_cvec_del(clicon_handle h,
|
|||
|
||||
/*! Get data option as integer but store as string
|
||||
*
|
||||
* @param[in] h clicon_handle
|
||||
* @param[in] h clixon_handle
|
||||
* @param[in] name option name
|
||||
* @retval int An integer as a result of atoi
|
||||
* @retval -1 If option does not exist
|
||||
|
|
@ -268,7 +269,7 @@ clicon_data_cvec_del(clicon_handle h,
|
|||
* @see clicon_option_int for values in clixon config file
|
||||
*/
|
||||
int
|
||||
clicon_data_int_get(clicon_handle h,
|
||||
clicon_data_int_get(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -282,14 +283,14 @@ clicon_data_int_get(clicon_handle h,
|
|||
|
||||
/*! Set a single string data via handle
|
||||
*
|
||||
* @param[in] h clicon_handle
|
||||
* @param[in] h clixon_handle
|
||||
* @param[in] name option name
|
||||
* @param[in] val option value, must be null-terminated string
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_data_int_set(clicon_handle h,
|
||||
clicon_data_int_set(clixon_handle h,
|
||||
const char *name,
|
||||
int val)
|
||||
{
|
||||
|
|
@ -303,13 +304,13 @@ clicon_data_int_set(clicon_handle h,
|
|||
|
||||
/*! Delete single int data via handle
|
||||
*
|
||||
* @param[in] h clicon_handle
|
||||
* @param[in] h clixon_handle
|
||||
* @param[in] name option name
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_data_int_del(clicon_handle h,
|
||||
clicon_data_int_del(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -324,7 +325,7 @@ clicon_data_int_del(clicon_handle h,
|
|||
* @see clicon_config_yang for the configuration yang
|
||||
*/
|
||||
yang_stmt *
|
||||
clicon_dbspec_yang(clicon_handle h)
|
||||
clicon_dbspec_yang(clixon_handle h)
|
||||
{
|
||||
yang_stmt *ys = NULL;
|
||||
|
||||
|
|
@ -340,7 +341,7 @@ clicon_dbspec_yang(clicon_handle h)
|
|||
* @see clicon_config_yang_set for the configuration yang
|
||||
*/
|
||||
int
|
||||
clicon_dbspec_yang_set(clicon_handle h,
|
||||
clicon_dbspec_yang_set(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
return clicon_ptr_set(h, "dbspec_yang", ys);
|
||||
|
|
@ -353,7 +354,7 @@ clicon_dbspec_yang_set(clicon_handle h,
|
|||
* @see clicon_dbspec_yang for the application specs
|
||||
*/
|
||||
yang_stmt *
|
||||
clicon_config_yang(clicon_handle h)
|
||||
clicon_config_yang(clixon_handle h)
|
||||
{
|
||||
yang_stmt *ys = NULL;
|
||||
|
||||
|
|
@ -369,7 +370,7 @@ clicon_config_yang(clicon_handle h)
|
|||
* @see clicon_dbspec_yang_set for the application specs
|
||||
*/
|
||||
int
|
||||
clicon_config_yang_set(clicon_handle h,
|
||||
clicon_config_yang_set(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
return clicon_ptr_set(h, "control_yang", ys);
|
||||
|
|
@ -382,7 +383,7 @@ clicon_config_yang_set(clicon_handle h,
|
|||
* @see clicon_nacm_ext for external NACM XML
|
||||
*/
|
||||
yang_stmt *
|
||||
clicon_nacm_ext_yang(clicon_handle h)
|
||||
clicon_nacm_ext_yang(clixon_handle h)
|
||||
{
|
||||
yang_stmt *ys = NULL;
|
||||
|
||||
|
|
@ -398,7 +399,7 @@ clicon_nacm_ext_yang(clicon_handle h)
|
|||
* @see clicon_nacm_ext_set for external NACM XML
|
||||
*/
|
||||
int
|
||||
clicon_nacm_ext_yang_set(clicon_handle h,
|
||||
clicon_nacm_ext_yang_set(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
return clicon_ptr_set(h, "nacm_ext_yang", ys);
|
||||
|
|
@ -415,7 +416,7 @@ clicon_nacm_ext_yang_set(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
cvec *
|
||||
clicon_nsctx_global_get(clicon_handle h)
|
||||
clicon_nsctx_global_get(clixon_handle h)
|
||||
{
|
||||
cvec *cvv = NULL;
|
||||
|
||||
|
|
@ -431,7 +432,7 @@ clicon_nsctx_global_get(clicon_handle h)
|
|||
* @param[in] nsctx Namespace context (malloced)
|
||||
*/
|
||||
int
|
||||
clicon_nsctx_global_set(clicon_handle h,
|
||||
clicon_nsctx_global_set(clixon_handle h,
|
||||
cvec *nsctx)
|
||||
{
|
||||
return clicon_ptr_set(h, "nsctx_global", nsctx);
|
||||
|
|
@ -445,7 +446,7 @@ clicon_nsctx_global_set(clicon_handle h,
|
|||
* @see clicon_nacm_ext_set
|
||||
*/
|
||||
cxobj *
|
||||
clicon_nacm_ext(clicon_handle h)
|
||||
clicon_nacm_ext(clixon_handle h)
|
||||
{
|
||||
cxobj *x = NULL;
|
||||
|
||||
|
|
@ -462,7 +463,7 @@ clicon_nacm_ext(clicon_handle h)
|
|||
* @see clicon_nacm_ext
|
||||
*/
|
||||
int
|
||||
clicon_nacm_ext_set(clicon_handle h,
|
||||
clicon_nacm_ext_set(clixon_handle h,
|
||||
cxobj *x)
|
||||
{
|
||||
cxobj *x0 = NULL;
|
||||
|
|
@ -480,7 +481,7 @@ clicon_nacm_ext_set(clicon_handle h,
|
|||
* @see from_client_msg
|
||||
*/
|
||||
cxobj *
|
||||
clicon_nacm_cache(clicon_handle h)
|
||||
clicon_nacm_cache(clixon_handle h)
|
||||
{
|
||||
cxobj *x = NULL;
|
||||
|
||||
|
|
@ -497,7 +498,7 @@ clicon_nacm_cache(clicon_handle h)
|
|||
* @see from_client_msg
|
||||
*/
|
||||
int
|
||||
clicon_nacm_cache_set(clicon_handle h,
|
||||
clicon_nacm_cache_set(clixon_handle h,
|
||||
cxobj *xn)
|
||||
{
|
||||
return clicon_ptr_set(h, "nacm_cache", xn);
|
||||
|
|
@ -516,7 +517,7 @@ clicon_nacm_cache_set(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
cxobj *
|
||||
clicon_conf_xml(clicon_handle h)
|
||||
clicon_conf_xml(clixon_handle h)
|
||||
{
|
||||
cxobj *x = NULL;
|
||||
|
||||
|
|
@ -530,7 +531,7 @@ clicon_conf_xml(clicon_handle h)
|
|||
* ys must be a malloced pointer
|
||||
*/
|
||||
int
|
||||
clicon_conf_xml_set(clicon_handle h,
|
||||
clicon_conf_xml_set(clixon_handle h,
|
||||
cxobj *x)
|
||||
{
|
||||
return clicon_ptr_set(h, "clixon_conf", x);
|
||||
|
|
@ -548,7 +549,7 @@ clicon_conf_xml_set(clicon_handle h,
|
|||
* CLICON_BACKEND_RESTCONF_PROCESS is true
|
||||
*/
|
||||
cxobj *
|
||||
clicon_conf_restconf(clicon_handle h)
|
||||
clicon_conf_restconf(clixon_handle h)
|
||||
{
|
||||
cxobj *xconfig = NULL;
|
||||
|
||||
|
|
@ -567,7 +568,7 @@ clicon_conf_restconf(clicon_handle h)
|
|||
* @endcode
|
||||
*/
|
||||
cxobj *
|
||||
clicon_conf_autocli(clicon_handle h)
|
||||
clicon_conf_autocli(clixon_handle h)
|
||||
{
|
||||
cxobj *xconfig = NULL;
|
||||
|
||||
|
|
@ -582,7 +583,7 @@ clicon_conf_autocli(clicon_handle h)
|
|||
* @retval username
|
||||
*/
|
||||
char *
|
||||
clicon_username_get(clicon_handle h)
|
||||
clicon_username_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
||||
|
|
@ -596,7 +597,7 @@ clicon_username_get(clicon_handle h)
|
|||
* @note Just keep note of it, dont allocate it or so.
|
||||
*/
|
||||
int
|
||||
clicon_username_set(clicon_handle h,
|
||||
clicon_username_set(clixon_handle h,
|
||||
void *username)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -612,7 +613,7 @@ clicon_username_set(clicon_handle h,
|
|||
* @retval status Startup status
|
||||
*/
|
||||
enum startup_status
|
||||
clicon_startup_status_get(clicon_handle h)
|
||||
clicon_startup_status_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
void *p;
|
||||
|
|
@ -630,7 +631,7 @@ clicon_startup_status_get(clicon_handle h)
|
|||
* @retval -1 Error (when setting value)
|
||||
*/
|
||||
int
|
||||
clicon_startup_status_set(clicon_handle h,
|
||||
clicon_startup_status_set(clixon_handle h,
|
||||
enum startup_status status)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -646,7 +647,7 @@ clicon_startup_status_set(clicon_handle h,
|
|||
* @retval -1 No open socket
|
||||
*/
|
||||
int
|
||||
clicon_socket_get(clicon_handle h)
|
||||
clicon_socket_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
void *p;
|
||||
|
|
@ -664,7 +665,7 @@ clicon_socket_get(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_socket_set(clicon_handle h,
|
||||
clicon_socket_set(clixon_handle h,
|
||||
int s)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -681,7 +682,7 @@ clicon_socket_set(clicon_handle h,
|
|||
* @retval -1 No open socket
|
||||
*/
|
||||
int
|
||||
clicon_client_socket_get(clicon_handle h)
|
||||
clicon_client_socket_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
void *p;
|
||||
|
|
@ -699,7 +700,7 @@ clicon_client_socket_get(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_client_socket_set(clicon_handle h,
|
||||
clicon_client_socket_set(clixon_handle h,
|
||||
int s)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -717,7 +718,7 @@ clicon_client_socket_set(clicon_handle h,
|
|||
* xms is on the form: <modules-state>...
|
||||
*/
|
||||
cxobj *
|
||||
clicon_modst_cache_get(clicon_handle h,
|
||||
clicon_modst_cache_get(clixon_handle h,
|
||||
int brief)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -737,7 +738,7 @@ clicon_modst_cache_get(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_modst_cache_set(clicon_handle h,
|
||||
clicon_modst_cache_set(clixon_handle h,
|
||||
int brief,
|
||||
cxobj *xms)
|
||||
{
|
||||
|
|
@ -763,7 +764,7 @@ clicon_modst_cache_set(clicon_handle h,
|
|||
* @see draft-wang-netmod-module-revision-management-01
|
||||
*/
|
||||
cxobj *
|
||||
clicon_xml_changelog_get(clicon_handle h)
|
||||
clicon_xml_changelog_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
void *p;
|
||||
|
|
@ -782,7 +783,7 @@ clicon_xml_changelog_get(clicon_handle h)
|
|||
* @see draft-wang-netmod-module-revision-management-01
|
||||
*/
|
||||
int
|
||||
clicon_xml_changelog_set(clicon_handle h,
|
||||
clicon_xml_changelog_set(clixon_handle h,
|
||||
cxobj *xchlog)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -801,7 +802,7 @@ clicon_xml_changelog_set(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_argv_get(clicon_handle h,
|
||||
clicon_argv_get(clixon_handle h,
|
||||
int *argc,
|
||||
char ***argv)
|
||||
{
|
||||
|
|
@ -832,7 +833,7 @@ clicon_argv_get(clicon_handle h,
|
|||
* @note If argv=NULL deallocate allocated argv vector if exists.
|
||||
*/
|
||||
int
|
||||
clicon_argv_set(clicon_handle h,
|
||||
clicon_argv_set(clixon_handle h,
|
||||
char *prgm,
|
||||
int argc,
|
||||
char **argv)
|
||||
|
|
@ -845,7 +846,7 @@ clicon_argv_set(clicon_handle h,
|
|||
/* add space for null-termination and argv[0] program name */
|
||||
len = argc+2;
|
||||
if ((argvv = calloc(len, sizeof(char*))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
memcpy(argvv+1, argv, argc*sizeof(char*));
|
||||
|
|
@ -871,7 +872,7 @@ clicon_argv_set(clicon_handle h,
|
|||
* @retval NULL None found
|
||||
*/
|
||||
db_elmnt *
|
||||
clicon_db_elmnt_get(clicon_handle h,
|
||||
clicon_db_elmnt_get(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_db_elmnt(h);
|
||||
|
|
@ -892,7 +893,7 @@ clicon_db_elmnt_get(clicon_handle h,
|
|||
* @see xmldb_disconnect
|
||||
*/
|
||||
int
|
||||
clicon_db_elmnt_set(clicon_handle h,
|
||||
clicon_db_elmnt_set(clixon_handle h,
|
||||
const char *db,
|
||||
db_elmnt *de)
|
||||
{
|
||||
|
|
@ -916,7 +917,7 @@ clicon_db_elmnt_set(clicon_handle h,
|
|||
* A backend getting a session-id of an ongoing session should use ce->ce_id
|
||||
*/
|
||||
int
|
||||
clicon_session_id_get(clicon_handle h,
|
||||
clicon_session_id_get(clixon_handle h,
|
||||
uint32_t *id)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -931,7 +932,7 @@ clicon_session_id_get(clicon_handle h,
|
|||
/*! Delete session id
|
||||
*/
|
||||
int
|
||||
clicon_session_id_del(clicon_handle h)
|
||||
clicon_session_id_del(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
||||
|
|
@ -947,7 +948,7 @@ clicon_session_id_del(clicon_handle h)
|
|||
* Session-ids survive TCP sessions that are created for each message sent to the backend.
|
||||
*/
|
||||
int
|
||||
clicon_session_id_set(clicon_handle h,
|
||||
clicon_session_id_set(clixon_handle h,
|
||||
uint32_t id)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -964,7 +965,7 @@ clicon_session_id_set(clicon_handle h,
|
|||
* If set, quit startup directly after upgrade
|
||||
*/
|
||||
int
|
||||
clicon_quit_upgrade_get(clicon_handle h)
|
||||
clicon_quit_upgrade_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
void *p;
|
||||
|
|
@ -983,7 +984,7 @@ clicon_quit_upgrade_get(clicon_handle h)
|
|||
* If set, quit startup directly after upgrade
|
||||
*/
|
||||
int
|
||||
clicon_quit_upgrade_set(clicon_handle h,
|
||||
clicon_quit_upgrade_set(clixon_handle h,
|
||||
int val)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
|
|||
|
|
@ -62,11 +62,12 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
|
|
@ -94,7 +95,7 @@
|
|||
* The filename reside in CLICON_XMLDB_DIR option
|
||||
*/
|
||||
int
|
||||
xmldb_db2file(clicon_handle h,
|
||||
xmldb_db2file(clixon_handle h,
|
||||
const char *db,
|
||||
char **filename)
|
||||
{
|
||||
|
|
@ -103,16 +104,16 @@ xmldb_db2file(clicon_handle h,
|
|||
char *dir;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((dir = clicon_xmldb_dir(h)) == NULL){
|
||||
clicon_err(OE_XML, errno, "dbdir not set");
|
||||
clixon_err(OE_XML, errno, "dbdir not set");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s/%s_db", dir, db);
|
||||
if ((*filename = strdup4(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -129,7 +130,7 @@ xmldb_db2file(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_connect(clicon_handle h)
|
||||
xmldb_connect(clixon_handle h)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -141,7 +142,7 @@ xmldb_connect(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_disconnect(clicon_handle h)
|
||||
xmldb_disconnect(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
char **keys = NULL;
|
||||
|
|
@ -174,7 +175,7 @@ xmldb_disconnect(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_copy(clicon_handle h,
|
||||
xmldb_copy(clixon_handle h,
|
||||
const char *from,
|
||||
const char *to)
|
||||
{
|
||||
|
|
@ -252,7 +253,7 @@ xmldb_copy(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_lock(clicon_handle h,
|
||||
xmldb_lock(clixon_handle h,
|
||||
const char *db,
|
||||
uint32_t id)
|
||||
{
|
||||
|
|
@ -277,7 +278,7 @@ xmldb_lock(clicon_handle h,
|
|||
* Assume all sanity checks have been made
|
||||
*/
|
||||
int
|
||||
xmldb_unlock(clicon_handle h,
|
||||
xmldb_unlock(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
db_elmnt *de = NULL;
|
||||
|
|
@ -298,7 +299,7 @@ xmldb_unlock(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_unlock_all(clicon_handle h,
|
||||
xmldb_unlock_all(clixon_handle h,
|
||||
uint32_t id)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -335,7 +336,7 @@ xmldb_unlock_all(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
uint32_t
|
||||
xmldb_islocked(clicon_handle h,
|
||||
xmldb_islocked(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
db_elmnt *de;
|
||||
|
|
@ -354,7 +355,7 @@ xmldb_islocked(clicon_handle h,
|
|||
* @retval -1 No timestamp / not locked
|
||||
*/
|
||||
int
|
||||
xmldb_lock_timestamp(clicon_handle h,
|
||||
xmldb_lock_timestamp(clixon_handle h,
|
||||
const char *db,
|
||||
struct timeval *tv)
|
||||
{
|
||||
|
|
@ -376,7 +377,7 @@ xmldb_lock_timestamp(clicon_handle h,
|
|||
* @note An empty datastore is treated as not existent so that a backend after dropping priviliges can re-create it
|
||||
*/
|
||||
int
|
||||
xmldb_exists(clicon_handle h,
|
||||
xmldb_exists(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -409,7 +410,7 @@ xmldb_exists(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_clear(clicon_handle h,
|
||||
xmldb_clear(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
cxobj *xt = NULL;
|
||||
|
|
@ -434,7 +435,7 @@ xmldb_clear(clicon_handle h,
|
|||
* @note Datastore is not actually deleted so that a backend after dropping priviliges can re-create it
|
||||
*/
|
||||
int
|
||||
xmldb_delete(clicon_handle h,
|
||||
xmldb_delete(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -448,7 +449,7 @@ xmldb_delete(clicon_handle h,
|
|||
goto done;
|
||||
if (lstat(filename, &sb) == 0)
|
||||
if (truncate(filename, 0) < 0){
|
||||
clicon_err(OE_DB, errno, "truncate %s", filename);
|
||||
clixon_err(OE_DB, errno, "truncate %s", filename);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -466,7 +467,7 @@ xmldb_delete(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_create(clicon_handle h,
|
||||
xmldb_create(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -485,7 +486,7 @@ xmldb_create(clicon_handle h,
|
|||
if (xmldb_db2file(h, db, &filename) < 0)
|
||||
goto done;
|
||||
if ((fd = open(filename, O_CREAT|O_WRONLY, S_IRWXU)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", filename);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -506,7 +507,7 @@ xmldb_create(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xmldb_db_reset(clicon_handle h,
|
||||
xmldb_db_reset(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
if (xmldb_exists(h, db) == 1){
|
||||
|
|
@ -525,7 +526,7 @@ xmldb_db_reset(clicon_handle h,
|
|||
* @retval xml XML cached tree or NULL
|
||||
*/
|
||||
cxobj *
|
||||
xmldb_cache_get(clicon_handle h,
|
||||
xmldb_cache_get(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
db_elmnt *de;
|
||||
|
|
@ -546,13 +547,13 @@ xmldb_cache_get(clicon_handle h,
|
|||
* @note This only works if db cache is used,...
|
||||
*/
|
||||
int
|
||||
xmldb_modified_get(clicon_handle h,
|
||||
xmldb_modified_get(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
db_elmnt *de;
|
||||
|
||||
if ((de = clicon_db_elmnt_get(h, db)) == NULL){
|
||||
clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
|
||||
clixon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
|
||||
return -1;
|
||||
}
|
||||
return de->de_modified;
|
||||
|
|
@ -567,13 +568,13 @@ xmldb_modified_get(clicon_handle h,
|
|||
* @retval -1 Error (datastore does not exist)
|
||||
*/
|
||||
int
|
||||
xmldb_empty_get(clicon_handle h,
|
||||
xmldb_empty_get(clixon_handle h,
|
||||
const char *db)
|
||||
{
|
||||
db_elmnt *de;
|
||||
|
||||
if ((de = clicon_db_elmnt_get(h, db)) == NULL){
|
||||
clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
|
||||
clixon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
|
||||
return -1;
|
||||
}
|
||||
return de->de_empty;
|
||||
|
|
@ -590,14 +591,14 @@ xmldb_empty_get(clicon_handle h,
|
|||
* @note This only works if db cache is used,...
|
||||
*/
|
||||
int
|
||||
xmldb_modified_set(clicon_handle h,
|
||||
xmldb_modified_set(clixon_handle h,
|
||||
const char *db,
|
||||
int value)
|
||||
{
|
||||
db_elmnt *de;
|
||||
|
||||
if ((de = clicon_db_elmnt_get(h, db)) == NULL){
|
||||
clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
|
||||
clixon_err(OE_CFG, EFAULT, "datastore %s does not exist", db);
|
||||
return -1;
|
||||
}
|
||||
de->de_modified = value;
|
||||
|
|
@ -607,7 +608,7 @@ xmldb_modified_set(clicon_handle h,
|
|||
/* Print the datastore meta-info to file
|
||||
*/
|
||||
int
|
||||
xmldb_print(clicon_handle h,
|
||||
xmldb_print(clixon_handle h,
|
||||
FILE *f)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -644,7 +645,7 @@ xmldb_print(clicon_handle h,
|
|||
* @note if newdb and suffix are null, OK is returned as it is a no-op
|
||||
*/
|
||||
int
|
||||
xmldb_rename(clicon_handle h,
|
||||
xmldb_rename(clixon_handle h,
|
||||
const char *db,
|
||||
const char *newdb,
|
||||
const char *suffix)
|
||||
|
|
@ -659,7 +660,7 @@ xmldb_rename(clicon_handle h,
|
|||
if (newdb == NULL && suffix == NULL) // no-op
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s", newdb == NULL ? old : newdb);
|
||||
|
|
@ -667,7 +668,7 @@ xmldb_rename(clicon_handle h,
|
|||
cprintf(cb, "%s", suffix);
|
||||
fname = cbuf_get(cb);
|
||||
if ((rename(old, fname)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "rename: %s", strerror(errno));
|
||||
clixon_err(OE_UNIX, errno, "rename: %s", strerror(errno));
|
||||
goto done;
|
||||
};
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -56,12 +56,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -89,8 +90,7 @@
|
|||
/*! Ensure that xt only has a single sub-element and that is "config"
|
||||
*
|
||||
* @retval 0 There exists a single "config" sub-element
|
||||
* @retval -1 Top element not "config" or "config" element not unique or
|
||||
* other error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error: Top element not "config" or "config" element not unique or other
|
||||
*/
|
||||
static int
|
||||
singleconfigroot(cxobj *xt,
|
||||
|
|
@ -105,13 +105,13 @@ singleconfigroot(cxobj *xt,
|
|||
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){
|
||||
i++;
|
||||
if (strcmp(xml_name(x), DATASTORE_TOP_SYMBOL)){
|
||||
clicon_err(OE_DB, ENOENT, "Wrong top-element %s expected %s",
|
||||
clixon_err(OE_DB, ENOENT, "Wrong top-element %s expected %s",
|
||||
xml_name(x), DATASTORE_TOP_SYMBOL);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (i != 1){
|
||||
clicon_err(OE_DB, ENOENT, "Top-element is not unique, expecting single config");
|
||||
clixon_err(OE_DB, ENOENT, "Top-element is not unique, expecting single config");
|
||||
goto done;
|
||||
}
|
||||
x = NULL;
|
||||
|
|
@ -131,7 +131,7 @@ singleconfigroot(cxobj *xt,
|
|||
/*! Recurse up from x0 up to x0t then create objects from x1t down to new object x1
|
||||
*
|
||||
* @retval 0 OK
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 OK
|
||||
*/
|
||||
static int
|
||||
xml_copy_bottom_recurse(cxobj *x0t,
|
||||
|
|
@ -157,7 +157,7 @@ xml_copy_bottom_recurse(cxobj *x0t,
|
|||
goto ok;
|
||||
}
|
||||
if ((x0p = xml_parent(x0)) == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "Reached top of tree");
|
||||
clixon_err(OE_XML, EFAULT, "Reached top of tree");
|
||||
goto done;
|
||||
}
|
||||
if (xml_copy_bottom_recurse(x0t, x0p, x1t, &x1p) < 0)
|
||||
|
|
@ -210,7 +210,7 @@ xml_copy_bottom_recurse(cxobj *x0t,
|
|||
/*! Copy an XML tree bottom-up
|
||||
*
|
||||
* @retval 0 OK
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 OK
|
||||
*/
|
||||
static int
|
||||
xml_copy_from_bottom(cxobj *x0t,
|
||||
|
|
@ -252,7 +252,7 @@ xml_copy_from_bottom(cxobj *x0t,
|
|||
* @param[in] xt XML tree
|
||||
* @param[out] msdiff Modules-state differences
|
||||
* @retval 0 OK
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
*
|
||||
* The modstate difference contains:
|
||||
* - if there is a modstate
|
||||
|
|
@ -273,7 +273,7 @@ xml_copy_from_bottom(cxobj *x0t,
|
|||
* 4a) If there is no such module in the file -> add to list mark as ADD
|
||||
*/
|
||||
static int
|
||||
text_read_modstate(clicon_handle h,
|
||||
text_read_modstate(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msdiff)
|
||||
|
|
@ -315,7 +315,7 @@ text_read_modstate(clicon_handle h,
|
|||
if (!rfc7895){
|
||||
if ((xf = xpath_first(xt, NULL, "yang-library/content-id")) != NULL){
|
||||
if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -326,7 +326,7 @@ text_read_modstate(clicon_handle h,
|
|||
if (rfc7895){
|
||||
if (strcmp(xml_name(xf), "module-set-id") == 0){
|
||||
if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
|
|
@ -400,7 +400,7 @@ text_read_modstate(clicon_handle h,
|
|||
* @param[in] xt Top-level XML
|
||||
* @param[in] yspec YANG spec
|
||||
* @retval 0 OK
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
disable_nacm_on_empty(cxobj *xt,
|
||||
|
|
@ -457,7 +457,7 @@ disable_nacm_on_empty(cxobj *xt,
|
|||
* @see xml_creator_metadata_write
|
||||
*/
|
||||
static int
|
||||
xml_creator_metadata_read(clicon_handle h,
|
||||
xml_creator_metadata_read(clixon_handle h,
|
||||
cxobj *xn)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -504,13 +504,13 @@ xml_creator_metadata_read(clicon_handle h,
|
|||
* @param[out] xerr XML error if retval is 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note Use of 1 for OK
|
||||
* @note retval 0 is NYI because calling functions cannot handle it yet
|
||||
* XXX if this code pass tests this code can be rewritten, esp the modstate stuff
|
||||
*/
|
||||
int
|
||||
xmldb_readfile(clicon_handle h,
|
||||
xmldb_readfile(clixon_handle h,
|
||||
const char *db,
|
||||
yang_bind yb,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -537,23 +537,23 @@ xmldb_readfile(clicon_handle h,
|
|||
yang_stmt *yspec1 = NULL;
|
||||
|
||||
if (yb != YB_MODULE && yb != YB_NONE){
|
||||
clicon_err(OE_XML, EINVAL, "yb is %d but should be module or none", yb);
|
||||
clixon_err(OE_XML, EINVAL, "yb is %d but should be module or none", yb);
|
||||
goto done;
|
||||
}
|
||||
if (xmldb_db2file(h, db, &dbfile) < 0)
|
||||
goto done;
|
||||
if (dbfile==NULL){
|
||||
clicon_err(OE_XML, 0, "dbfile NULL");
|
||||
clixon_err(OE_XML, 0, "dbfile NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
|
||||
clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "Reading datastore %s using %s", dbfile, format);
|
||||
/* Parse file into internal XML tree from different formats */
|
||||
if ((fp = fopen(dbfile, "r")) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", dbfile);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", dbfile);
|
||||
goto done;
|
||||
}
|
||||
/* Read whole datastore file on the form:
|
||||
|
|
@ -646,14 +646,14 @@ xmldb_readfile(clicon_handle h,
|
|||
/* YANG Module not found, look for it and append if found */
|
||||
if (yang_spec_parse_module(h, name, rev, yspec) < 0){
|
||||
/* Special case: file-not-found errors */
|
||||
if (clicon_suberrno == ENOENT){
|
||||
if (clixon_err_subnr() == ENOENT){
|
||||
cbuf *cberr = NULL;
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Internal error: %s", clicon_err_reason);
|
||||
clicon_err_reset();
|
||||
cprintf(cberr, "Internal error: %s", clixon_err_reason());
|
||||
clixon_err_reset();
|
||||
if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr))< 0)
|
||||
goto done;
|
||||
cbuf_free(cberr);
|
||||
|
|
@ -739,12 +739,12 @@ xmldb_readfile(clicon_handle h,
|
|||
* @param[out] xerr XML error if retval is 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note Use of 1 for OK
|
||||
* @see xmldb_get the generic API function
|
||||
*/
|
||||
static int
|
||||
xmldb_get_nocache(clicon_handle h,
|
||||
xmldb_get_nocache(clixon_handle h,
|
||||
const char *db,
|
||||
yang_bind yb,
|
||||
cvec *nsc,
|
||||
|
|
@ -766,7 +766,7 @@ xmldb_get_nocache(clicon_handle h,
|
|||
db_elmnt de0 = {0,};
|
||||
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
clixon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
/* xml looks like: <top><config><x>... where "x" is a top-level symbol in a module */
|
||||
|
|
@ -861,7 +861,7 @@ xmldb_get_nocache(clicon_handle h,
|
|||
}
|
||||
#if 0 /* debug */
|
||||
if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
|
||||
clicon_log(LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
|
||||
clixon_log(h, LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
|
||||
#endif
|
||||
if (clixon_debug_get()>1)
|
||||
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
|
||||
|
|
@ -898,12 +898,12 @@ xmldb_get_nocache(clicon_handle h,
|
|||
* @param[out] xerr XML error if retval is 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note Use of 1 for OK
|
||||
* @see xmldb_get the generic API function
|
||||
*/
|
||||
static int
|
||||
xmldb_get_cache(clicon_handle h,
|
||||
xmldb_get_cache(clixon_handle h,
|
||||
const char *db,
|
||||
yang_bind yb,
|
||||
cvec *nsc,
|
||||
|
|
@ -927,7 +927,7 @@ xmldb_get_cache(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
clixon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
de = clicon_db_elmnt_get(h, db);
|
||||
|
|
@ -1086,11 +1086,11 @@ xmldb_get_cache(clicon_handle h,
|
|||
* @param[out] xerr XML error if retval is 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note Use of 1 for OK
|
||||
*/
|
||||
static int
|
||||
xmldb_get_zerocopy(clicon_handle h,
|
||||
xmldb_get_zerocopy(clixon_handle h,
|
||||
const char *db,
|
||||
yang_bind yb,
|
||||
cvec *nsc,
|
||||
|
|
@ -1113,7 +1113,7 @@ xmldb_get_zerocopy(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
clixon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
de = clicon_db_elmnt_get(h, db);
|
||||
|
|
@ -1231,7 +1231,7 @@ xmldb_get_zerocopy(clicon_handle h,
|
|||
* @param[out] xret Single return XML tree. Free with xml_free()
|
||||
* @retval 1 OK
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note Use of 1 for OK
|
||||
* @code
|
||||
* if (xmldb_get(xh, "running", NULL, "/interfaces/interface[name="eth"]", &xt) < 0)
|
||||
|
|
@ -1241,7 +1241,7 @@ xmldb_get_zerocopy(clicon_handle h,
|
|||
* @see xmldb_get0 Underlying more capable API for enabling zero-copy
|
||||
*/
|
||||
int
|
||||
xmldb_get(clicon_handle h,
|
||||
xmldb_get(clixon_handle h,
|
||||
const char *db,
|
||||
cvec *nsc,
|
||||
char *xpath,
|
||||
|
|
@ -1270,7 +1270,7 @@ xmldb_get(clicon_handle h,
|
|||
* @param[out] xerr XML error if retval is 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note Use of 1 for OK
|
||||
* @code
|
||||
* cxobj *xt;
|
||||
|
|
@ -1302,7 +1302,7 @@ xmldb_get(clicon_handle h,
|
|||
* <c><x>0</x></c>
|
||||
*/
|
||||
int
|
||||
xmldb_get0(clicon_handle h,
|
||||
xmldb_get0(clixon_handle h,
|
||||
const char *db,
|
||||
yang_bind yb,
|
||||
cvec *nsc,
|
||||
|
|
@ -1316,7 +1316,7 @@ xmldb_get0(clicon_handle h,
|
|||
int retval = -1;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_DB, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_DB, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
switch (clicon_datastore_cache(h)){
|
||||
|
|
@ -1354,12 +1354,12 @@ xmldb_get0(clicon_handle h,
|
|||
* @param[in] h Clixon handle
|
||||
* @param[in] db Name of datastore
|
||||
* @retval 0 OK
|
||||
* @retval -1 General error, check specific clicon_errno, clicon_suberrno
|
||||
* @retval -1 Error
|
||||
* @note "Clear" an xml tree means removing default values and resetting all flags.
|
||||
* @see xmldb_get0
|
||||
*/
|
||||
int
|
||||
xmldb_get0_clear(clicon_handle h,
|
||||
xmldb_get0_clear(clixon_handle h,
|
||||
cxobj *x)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1389,7 +1389,7 @@ xmldb_get0_clear(clicon_handle h,
|
|||
* @see xmldb_get0
|
||||
*/
|
||||
int
|
||||
xmldb_get0_free(clicon_handle h,
|
||||
xmldb_get0_free(clixon_handle h,
|
||||
cxobj **xp)
|
||||
{
|
||||
if (*xp == NULL)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int xmldb_readfile(clicon_handle h, const char *db, yang_bind yb, yang_stmt *yspec,
|
||||
int xmldb_readfile(clixon_handle h, const char *db, yang_bind yb, yang_stmt *yspec,
|
||||
cxobj **xp, db_elmnt *de, modstate_diff_t *msd, cxobj **xerr);
|
||||
|
||||
#endif /* _CLIXON_DATASTORE_READ_H */
|
||||
|
|
|
|||
|
|
@ -56,12 +56,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -126,7 +127,7 @@ attr_ns_value(cxobj *x,
|
|||
if (ns == NULL ||
|
||||
strcmp(ans, ns) == 0){
|
||||
if ((val = strdup(xml_value(xa))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
xml_purge(xa);
|
||||
|
|
@ -257,7 +258,7 @@ check_body_namespace(cxobj *x0,
|
|||
* XXX return netconf error instead bad-attribue?
|
||||
*/
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "identityref: \"%s\": namespace collision %s vs %s", x1bstr, ns0, ns1);
|
||||
|
|
@ -303,7 +304,7 @@ check_body_namespace(cxobj *x0,
|
|||
}
|
||||
#else
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "identityref: \"%s\": prefix \"%s\" has no associated namespace", x1bstr, prefix);
|
||||
|
|
@ -371,7 +372,7 @@ check_when_condition(cxobj *x0p,
|
|||
goto done;
|
||||
if (nr == 0){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Node '%s' tagged with 'when' condition '%s' in module '%s' evaluates to false in edit-config operation (see RFC 7950 Sec 8.3.2)",
|
||||
|
|
@ -519,7 +520,7 @@ choice_delete_other(cxobj *x0,
|
|||
* in the list the entry is inserted.
|
||||
*/
|
||||
static int
|
||||
text_modify(clicon_handle h,
|
||||
text_modify(clixon_handle h,
|
||||
cxobj *x0,
|
||||
cxobj *x0p,
|
||||
cxobj *x0t,
|
||||
|
|
@ -559,7 +560,7 @@ text_modify(clicon_handle h,
|
|||
char *creator = NULL;
|
||||
|
||||
if (x1 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "x1 is missing");
|
||||
clixon_err(OE_XML, EINVAL, "x1 is missing");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = check_when_condition(x0p, x1, y0, cbret)) < 0)
|
||||
|
|
@ -708,7 +709,7 @@ text_modify(clicon_handle h,
|
|||
if (yang_type_get(y0, NULL, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
|
||||
goto done;
|
||||
if (yrestype == NULL){
|
||||
clicon_err(OE_CFG, EFAULT, "No restype (internal error)");
|
||||
clixon_err(OE_CFG, EFAULT, "No restype (internal error)");
|
||||
goto done;
|
||||
}
|
||||
restype = yang_argument_get(yrestype);
|
||||
|
|
@ -940,7 +941,7 @@ text_modify(clicon_handle h,
|
|||
* collect matching nodes from x0 in x0vec (no changes to x0 children)
|
||||
*/
|
||||
if ((x0vec = calloc(xml_child_nr_type(x1, CX_ELMNT), sizeof(x1))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
x1c = NULL;
|
||||
|
|
@ -957,7 +958,7 @@ text_modify(clicon_handle h,
|
|||
if ((yc = yang_anydata_add(y0, x1cname)) < 0)
|
||||
goto done;
|
||||
xml_spec_set(x1c, yc);
|
||||
clicon_log(LOG_WARNING,
|
||||
clixon_log(h, LOG_WARNING,
|
||||
"%s: %d: No YANG spec for %s, anydata used",
|
||||
__FUNCTION__, __LINE__, x1cname);
|
||||
}
|
||||
|
|
@ -973,7 +974,7 @@ text_modify(clicon_handle h,
|
|||
* As an alternative, return in populate where this is detected first time.
|
||||
*/
|
||||
if (yc != xml_spec(x1c)){
|
||||
clicon_err(OE_YANG, errno, "XML node \"%s\" not in namespace %s",
|
||||
clixon_err(OE_YANG, errno, "XML node \"%s\" not in namespace %s",
|
||||
x1cname, yang_find_mynamespace(y0));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1101,7 +1102,7 @@ text_modify(clicon_handle h,
|
|||
* @see text_modify
|
||||
*/
|
||||
static int
|
||||
text_modify_top(clicon_handle h,
|
||||
text_modify_top(clixon_handle h,
|
||||
cxobj *x0t,
|
||||
cxobj *x1t,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -1210,7 +1211,7 @@ text_modify_top(clicon_handle h,
|
|||
if ((yc = yang_anydata_add(ymod, x1cname)) < 0)
|
||||
goto done;
|
||||
xml_spec_set(x1c, yc);
|
||||
clicon_log(LOG_WARNING,
|
||||
clixon_log(h, LOG_WARNING,
|
||||
"%s: %d: No YANG spec for %s, anydata used",
|
||||
__FUNCTION__, __LINE__, x1cname);
|
||||
}
|
||||
|
|
@ -1275,7 +1276,7 @@ text_modify_top(clicon_handle h,
|
|||
* @note if xret is non-null, it may contain error message
|
||||
*/
|
||||
int
|
||||
xmldb_put(clicon_handle h,
|
||||
xmldb_put(clixon_handle h,
|
||||
const char *db,
|
||||
enum operation_type op,
|
||||
cxobj *x1,
|
||||
|
|
@ -1302,15 +1303,15 @@ xmldb_put(clicon_handle h,
|
|||
cxobj *xmeta = NULL;
|
||||
|
||||
if (cbret == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "cbret is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "cbret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
clixon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
if (x1 && strcmp(xml_name(x1), NETCONF_INPUT_CONFIG) != 0){
|
||||
clicon_err(OE_XML, 0, "Top-level symbol of modification tree is %s, expected \"%s\"",
|
||||
clixon_err(OE_XML, 0, "Top-level symbol of modification tree is %s, expected \"%s\"",
|
||||
xml_name(x1), NETCONF_INPUT_CONFIG);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1329,7 +1330,7 @@ xmldb_put(clicon_handle h,
|
|||
}
|
||||
if (strcmp(xml_name(x0), DATASTORE_TOP_SYMBOL) !=0 ||
|
||||
xml_flag(x0, XML_FLAG_TOP) == 0){
|
||||
clicon_err(OE_XML, 0, "Top-level symbol is %s, expected \"%s\"",
|
||||
clixon_err(OE_XML, 0, "Top-level symbol is %s, expected \"%s\"",
|
||||
xml_name(x0), DATASTORE_TOP_SYMBOL);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1346,7 +1347,7 @@ xmldb_put(clicon_handle h,
|
|||
/* Here x0 looks like: <config>...</config> */
|
||||
#if 0 /* debug */
|
||||
if (xml_apply0(x1, -1, xml_sort_verify, NULL) < 0)
|
||||
clicon_log(LOG_NOTICE, "%s: verify failed #1", __FUNCTION__);
|
||||
clixon_log(h, LOG_NOTICE, "%s: verify failed #1", __FUNCTION__);
|
||||
#endif
|
||||
xnacm = clicon_nacm_cache(h);
|
||||
permit = (xnacm==NULL);
|
||||
|
|
@ -1380,7 +1381,7 @@ xmldb_put(clicon_handle h,
|
|||
goto done;
|
||||
#if 0 /* debug */
|
||||
if (xml_apply0(x0, -1, xml_sort_verify, NULL) < 0)
|
||||
clicon_log(LOG_NOTICE, "%s: verify failed #3", __FUNCTION__);
|
||||
clixon_log(h, LOG_NOTICE, "%s: verify failed #3", __FUNCTION__);
|
||||
#endif
|
||||
/* Write back to datastore cache if first time */
|
||||
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
|
||||
|
|
@ -1395,7 +1396,7 @@ xmldb_put(clicon_handle h,
|
|||
if (xmldb_db2file(h, db, &dbfile) < 0)
|
||||
goto done;
|
||||
if (dbfile==NULL){
|
||||
clicon_err(OE_XML, 0, "dbfile NULL");
|
||||
clixon_err(OE_XML, 0, "dbfile NULL");
|
||||
goto done;
|
||||
}
|
||||
/* Add module revision info before writing to file)
|
||||
|
|
@ -1408,11 +1409,11 @@ xmldb_put(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
|
||||
clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
|
||||
goto done;
|
||||
}
|
||||
if ((f = fopen(dbfile, "w")) == NULL){
|
||||
clicon_err(OE_CFG, errno, "Creating file %s", dbfile);
|
||||
clixon_err(OE_CFG, errno, "Creating file %s", dbfile);
|
||||
goto done;
|
||||
}
|
||||
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
|
||||
|
|
@ -1466,7 +1467,7 @@ xmldb_put(clicon_handle h,
|
|||
/* Dump a datastore to file including modstate
|
||||
*/
|
||||
int
|
||||
xmldb_dump(clicon_handle h,
|
||||
xmldb_dump(clixon_handle h,
|
||||
FILE *f,
|
||||
cxobj *xt)
|
||||
{
|
||||
|
|
@ -1487,7 +1488,7 @@ xmldb_dump(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
|
||||
clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
|
||||
goto done;
|
||||
}
|
||||
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
|
||||
|
|
|
|||
|
|
@ -45,6 +45,6 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret);
|
||||
int xmldb_put(clixon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret);
|
||||
|
||||
#endif /* _CLIXON_DATASTORE_WRITE_H */
|
||||
|
|
|
|||
165
lib/src/clixon_debug.c
Normal file
165
lib/src/clixon_debug.c
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2017-2019 Olof Hagsand
|
||||
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate)
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
the GNU General Public License Version 3 or later (the "GPL"),
|
||||
in which case the provisions of the GPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of the GPL, and not to allow others to
|
||||
use your version of this file under the terms of Apache License version 2,
|
||||
indicate your decision by deleting the provisions above and replace them with
|
||||
the notice and other provisions required by the GPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the Apache License version 2 or the GPL.
|
||||
|
||||
***** END LICENSE BLOCK *****
|
||||
|
||||
*
|
||||
* Regular logging and debugging. Syslog using levels.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "clixon_config.h" /* generated by config & autoconf */
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
|
||||
/*
|
||||
* Local Variables
|
||||
*/
|
||||
|
||||
/*! The global debug level. 0 means no debug
|
||||
*
|
||||
* @note There are pros and cons in having the debug state as a global variable. The
|
||||
* alternative to bind it to the clicon handle (h) was considered but it limits its
|
||||
* usefulness, since not all functions have h
|
||||
*/
|
||||
static int _debug_level = 0;
|
||||
|
||||
/*! Initialize debug messages. Set debug level.
|
||||
*
|
||||
* Initialize debug module. The level is used together with clixon_debug(dbglevel) calls as follows:
|
||||
* print message if level >= dbglevel.
|
||||
* Example: clixon_debug_init(1) -> debug(1) is printed, but not debug(2).
|
||||
* Normally, debug messages are sent to clixon_log() which in turn can be sent to syslog and/or stderr.
|
||||
* But you can also override this with a specific debug file so that debug messages are written on the file
|
||||
* independently of log or errors. This is to ensure that a syslog of normal logs is unpolluted by extensive
|
||||
* debugging.
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] dbglevel 0 is show no debug messages, 1 is normal, 2.. is high debug.
|
||||
* Note this is _not_ level from syslog(3)
|
||||
* @param[in] f Debug-file. Open file where debug messages are directed.
|
||||
* @see clixon_log_file For specifying a debug-file
|
||||
*/
|
||||
int
|
||||
clixon_debug_init(clixon_handle h,
|
||||
int dbglevel)
|
||||
{
|
||||
_debug_level = dbglevel; /* Global variable */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get debug level
|
||||
*/
|
||||
int
|
||||
clixon_debug_get(void)
|
||||
{
|
||||
return _debug_level;
|
||||
}
|
||||
|
||||
/*! Print a debug message with debug-level. Settings determine where msg appears.
|
||||
*
|
||||
* If the dbglevel passed in the function is equal to or lower than the one set by
|
||||
* clixon_debug_init(level). That is, only print debug messages <= than what you want:
|
||||
* print message if level >= dbglevel.
|
||||
* The message is sent to clixon_log. EIther to syslog, stderr or both, depending on
|
||||
* clixon_log_init() setting
|
||||
* @param[in] dbglevel Mask of CLIXON_DBG_DEFAULT and other masks
|
||||
* @param[in] format Message to print as argv.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see clixon_debug_xml Specialization for XML tree
|
||||
* @see CLIXON_DBG_DEFAULT and other flags
|
||||
*/
|
||||
int
|
||||
clixon_debug(int dbglevel,
|
||||
const char *format, ...)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
size_t len;
|
||||
char *msg = NULL;
|
||||
size_t trunc;
|
||||
|
||||
/* Mask debug level with global dbg variable */
|
||||
if ((dbglevel & clixon_debug_get()) == 0)
|
||||
return 0;
|
||||
/* first round: compute length of debug message */
|
||||
va_start(args, format);
|
||||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
|
||||
/* Truncate long debug strings */
|
||||
if ((trunc = clixon_log_string_limit_get()) && trunc < len)
|
||||
len = trunc;
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from format and args */
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
clixon_log_str(LOG_DEBUG, msg);
|
||||
retval = 0;
|
||||
done:
|
||||
if (msg)
|
||||
free(msg);
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -35,9 +35,7 @@
|
|||
|
||||
*
|
||||
* Errors may be syslogged using LOG_ERR, and printed to stderr, as controlled
|
||||
* by clicon_log_init
|
||||
* global error variables are set:
|
||||
* clicon_errno, clicon_suberrno, clicon_err_reason.
|
||||
* by clixon_log_init
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
@ -61,8 +59,11 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
|
||||
/*
|
||||
|
|
@ -74,8 +75,8 @@ struct errvec{
|
|||
};
|
||||
|
||||
struct err_state{
|
||||
int es_errno;
|
||||
int es_suberrno;
|
||||
int es_category;
|
||||
int es_subnr;
|
||||
char es_reason[ERR_STRLEN];
|
||||
};
|
||||
|
||||
|
|
@ -85,21 +86,29 @@ struct err_state{
|
|||
*/
|
||||
struct clixon_err_cats {
|
||||
qelem_t cec_qelem; /* List header */
|
||||
enum clicon_err cec_category;
|
||||
enum clixon_err cec_category;
|
||||
void *cec_handle;
|
||||
clixon_cat_log_cb *cec_logfn;
|
||||
};
|
||||
typedef struct clixon_err_cats clixon_err_cats;
|
||||
|
||||
/*
|
||||
* Local Variables
|
||||
*/
|
||||
|
||||
/* Cache handle since some error calls does not have handle access */
|
||||
static clixon_handle _err_clixon_h = NULL;
|
||||
/* Internal global list of category callbacks */
|
||||
static clixon_err_cats *_err_cat_list = NULL;
|
||||
|
||||
/*
|
||||
* Variables
|
||||
*/
|
||||
int clicon_errno = 0; /* See enum clicon_err XXX: hide this and change to err_category */
|
||||
int clicon_suberrno = 0; /* Corresponds to errno.h XXX: change to errno */
|
||||
char clicon_err_reason[ERR_STRLEN] = {0, };
|
||||
/* See enum clixon_err XXX: hide this and change to err_category */
|
||||
static int _err_category = 0;
|
||||
|
||||
/* Corresponds to errno.h XXX: change to errno */
|
||||
static int _err_subnr = 0;
|
||||
|
||||
/* Clixon error reason */
|
||||
static char _err_reason[ERR_STRLEN] = {0, };
|
||||
|
||||
/*
|
||||
* Error descriptions. Must stop with NULL element.
|
||||
|
|
@ -129,8 +138,59 @@ static struct errvec EV[] = {
|
|||
{NULL, -1}
|
||||
};
|
||||
|
||||
/*! Initialize clixon errors
|
||||
*
|
||||
* Mainly to cache handle since many clixon_err calls may not have access to a handle
|
||||
* @param[in] h Clixon handle
|
||||
* @see clixon_log_init inits log
|
||||
*/
|
||||
int
|
||||
clixon_err_init(clixon_handle h)
|
||||
{
|
||||
if (h == NULL){
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
_err_clixon_h = h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Access function: return clixon category of last error
|
||||
*
|
||||
* @retval category Clixon error category
|
||||
* @see clixon_err_save
|
||||
*/
|
||||
int
|
||||
clixon_err_category(void)
|
||||
{
|
||||
return _err_category;
|
||||
}
|
||||
|
||||
/*! Access function: return clixon errno of last error
|
||||
*
|
||||
* @retval errno Clixon sub error number
|
||||
* @see clixon_err_save
|
||||
*/
|
||||
int
|
||||
clixon_err_subnr(void)
|
||||
{
|
||||
return _err_subnr;
|
||||
}
|
||||
|
||||
/*! Access function: return clixon error reason string of last error (direct pointer)
|
||||
*
|
||||
* @retval reason Pointer to static string
|
||||
* Consider copy or malloc instead of pointer to static string?
|
||||
* @see clixon_err_save
|
||||
*/
|
||||
char *
|
||||
clixon_err_reason(void)
|
||||
{
|
||||
return _err_reason;
|
||||
}
|
||||
|
||||
static char *
|
||||
clicon_strerror1(int err,
|
||||
clixon_strerror1(int err,
|
||||
struct errvec vec[])
|
||||
{
|
||||
struct errvec *ev;
|
||||
|
|
@ -138,7 +198,15 @@ clicon_strerror1(int err,
|
|||
for (ev=vec; ev->ev_err != -1; ev++)
|
||||
if (ev->ev_err == err)
|
||||
break;
|
||||
return ev?(ev->ev_str?ev->ev_str:"unknown"):"CLICON unknown error";
|
||||
return ev?(ev->ev_str?ev->ev_str:"unknown"):"Clixon unknown error";
|
||||
}
|
||||
|
||||
/*! Translate from numeric error to string representation
|
||||
*/
|
||||
char *
|
||||
clixon_err_str(void)
|
||||
{
|
||||
return clixon_strerror1(_err_category, EV);
|
||||
}
|
||||
|
||||
/*! Clear error state and continue.
|
||||
|
|
@ -146,11 +214,11 @@ clicon_strerror1(int err,
|
|||
* Clear error state and get on with it, typically non-fatal error and you wish to continue.
|
||||
*/
|
||||
int
|
||||
clicon_err_reset(void)
|
||||
clixon_err_reset(void)
|
||||
{
|
||||
clicon_errno = 0;
|
||||
clicon_suberrno = 0;
|
||||
memset(clicon_err_reason, 0, ERR_STRLEN);
|
||||
_err_category = 0;
|
||||
_err_subnr = 0;
|
||||
memset(_err_reason, 0, ERR_STRLEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -178,162 +246,182 @@ find_category(int category)
|
|||
return found?cec:NULL;
|
||||
}
|
||||
|
||||
/*! Report an error.
|
||||
/*! Report an error, constant args variant, see clixon_err() for most common function
|
||||
*
|
||||
* Library routines should call this function when an error occurs.
|
||||
* The function does he following:
|
||||
* - Logs to syslog with LOG_ERR
|
||||
* - Set global error variable name clicon_errno
|
||||
* - Set global reason string clicon_err_reason
|
||||
* Typically a call to clicon_err() is followed by a return -1 (or NULL) that signals
|
||||
* a fatal error that fails early and loud.
|
||||
* However there are some cases where such an error does not cause an exit. This includes
|
||||
* CLI operations of callbacks and expand functions. The reason is that user-defined errors
|
||||
* should just signal an error and not terminate. To override this one can set a suberr to
|
||||
* ESHUTDOWN.
|
||||
*
|
||||
* @note: err direction (syslog and/or stderr) controlled by clicon_log_init()
|
||||
*
|
||||
* @param[in] fn Inline function name (when called from clicon_err() macro)
|
||||
* @param[in] line Inline file line number (when called from clicon_err() macro)
|
||||
* @param[in] category Clixon error category, See enum clicon_err
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] fn Inline function name (when called from clixon_err() macro)
|
||||
* @param[in] line Inline file line number (when called from clixon_err() macro)
|
||||
* @param[in] category Clixon error category, See enum clixon_err
|
||||
* @param[in] suberr Error number, typically errno
|
||||
* @param[in] format Error string, format with argv
|
||||
* @param[in] msg Error string
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see clicon_err_reset Reset the global error variables.
|
||||
* @see clixon_err_fn for a variable-argument variant
|
||||
*/
|
||||
int
|
||||
clicon_err_fn(const char *fn,
|
||||
const int line,
|
||||
int category,
|
||||
int suberr,
|
||||
const char *format, ...)
|
||||
clixon_err_args(clixon_handle h,
|
||||
const char *fn,
|
||||
const int line,
|
||||
int category,
|
||||
int suberr,
|
||||
char *msg)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
int len;
|
||||
char *msg = NULL;
|
||||
int retval = -1;
|
||||
struct clixon_err_cats *cec;
|
||||
|
||||
cbuf *cb = NULL;
|
||||
|
||||
/* Set the global variables */
|
||||
clicon_errno = category;
|
||||
clicon_suberrno = suberr;
|
||||
|
||||
/* first round: compute length of error message */
|
||||
va_start(args, format);
|
||||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* second round: compute write message from format and args */
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
strncpy(clicon_err_reason, msg, ERR_STRLEN-1);
|
||||
strncpy(_err_reason, msg, ERR_STRLEN-1);
|
||||
_err_category = category;
|
||||
_err_subnr = suberr;
|
||||
/* Check category callbacks as defined in clixon_err_cat_reg */
|
||||
if ((cec = find_category(category)) != NULL &&
|
||||
cec->cec_logfn){
|
||||
cbuf *cb = NULL;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
if (cec->cec_logfn(cec->cec_handle, suberr, cb) < 0)
|
||||
goto done;
|
||||
/* Here we could take care of specific errno, like application-defined errors */
|
||||
if (fn)
|
||||
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
|
||||
clixon_log(h, LOG_ERR, "%s: %d: %s: %s: %s",
|
||||
fn,
|
||||
line,
|
||||
clicon_strerror(category),
|
||||
clixon_strerror1(category, EV),
|
||||
cbuf_get(cb),
|
||||
msg);
|
||||
else
|
||||
clicon_log(LOG_ERR, "%s: %s: %s",
|
||||
clicon_strerror(category),
|
||||
clixon_log(h, LOG_ERR, "%s: %s: %s",
|
||||
clixon_strerror1(category, EV),
|
||||
cbuf_get(cb),
|
||||
msg);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
}
|
||||
else if (suberr){ /* Actually log it */
|
||||
/* Here we could take care of specific errno, like application-defined errors */
|
||||
if (fn)
|
||||
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
|
||||
clixon_log(h, LOG_ERR, "%s: %d: %s: %s: %s",
|
||||
fn,
|
||||
line,
|
||||
clicon_strerror(category),
|
||||
clixon_strerror1(category, EV),
|
||||
msg,
|
||||
suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
|
||||
else
|
||||
clicon_log(LOG_ERR, "%s: %s: %s",
|
||||
clicon_strerror(category),
|
||||
clixon_log(h, LOG_ERR, "%s: %s: %s",
|
||||
clixon_strerror1(category, EV),
|
||||
msg,
|
||||
suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr));
|
||||
}
|
||||
else{
|
||||
if (fn)
|
||||
clicon_log(LOG_ERR, "%s: %d: %s: %s",
|
||||
clixon_log(h, LOG_ERR, "%s: %d: %s: %s",
|
||||
fn,
|
||||
line,
|
||||
clicon_strerror(category),
|
||||
clixon_strerror1(category, EV),
|
||||
msg);
|
||||
else
|
||||
clicon_log(LOG_ERR, "%s: %s",
|
||||
clicon_strerror(category),
|
||||
clixon_log(h, LOG_ERR, "%s: %s",
|
||||
clixon_strerror1(category, EV),
|
||||
msg);
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Report an error.
|
||||
*
|
||||
* Library routines should call this function when an error occurs.
|
||||
* The function does he following:
|
||||
* - Logs to syslog with LOG_ERR
|
||||
* - Set global error variable name clixon_errno
|
||||
* - Set global reason string clixon_err_reason
|
||||
* Typically a call to clixon_err() is followed by a return -1 (or NULL) that signals
|
||||
* a fatal error that fails early and loud.
|
||||
* However there are some cases where such an error does not cause an exit. This includes
|
||||
* CLI operations of callbacks and expand functions. The reason is that user-defined errors
|
||||
* should just signal an error and not terminate. To override this one can set a suberr to
|
||||
* ESHUTDOWN.
|
||||
*
|
||||
* @note: err direction (syslog and/or stderr) controlled by clixon_log_init()
|
||||
*
|
||||
* @param[in] fn Inline function name (when called from clixon_err() macro)
|
||||
* @param[in] line Inline file line number (when called from clixon_err() macro)
|
||||
* @param[in] category Clixon error category, See enum clixon_err
|
||||
* @param[in] suberr Error number, typically errno
|
||||
* @param[in] format Error string, format with argv
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see clixon_err_netconf For variant with netconf error message
|
||||
*/
|
||||
int
|
||||
clixon_err_fn(const char *fn,
|
||||
const int line,
|
||||
int category,
|
||||
int suberr,
|
||||
const char *format, ...)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
int len;
|
||||
char *msg = NULL;
|
||||
|
||||
/* first round: compute length of error message */
|
||||
va_start(args, format);
|
||||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from format and args */
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
if (clixon_err_args(_err_clixon_h, fn, line, category, suberr, msg) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (msg)
|
||||
free(msg);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Translate from numeric error to string representation
|
||||
*/
|
||||
char *
|
||||
clicon_strerror(int err)
|
||||
{
|
||||
return clicon_strerror1(err, EV);
|
||||
}
|
||||
|
||||
/*! Push an error state, if recursive error handling
|
||||
*
|
||||
* @see clixon_err_vars
|
||||
*/
|
||||
void*
|
||||
clicon_err_save(void)
|
||||
clixon_err_save(void)
|
||||
{
|
||||
struct err_state *es;
|
||||
|
||||
if ((es = malloc(sizeof(*es))) == NULL)
|
||||
return NULL;
|
||||
es->es_errno = clicon_errno;
|
||||
es->es_suberrno = clicon_suberrno;
|
||||
strncpy(es->es_reason, clicon_err_reason, ERR_STRLEN);
|
||||
es->es_category = _err_category;
|
||||
es->es_subnr = _err_subnr;
|
||||
strncpy(es->es_reason, _err_reason, ERR_STRLEN);
|
||||
return (void*)es;
|
||||
}
|
||||
|
||||
/*! Pop an error state, if recursive error handling
|
||||
*/
|
||||
int
|
||||
clicon_err_restore(void* handle)
|
||||
clixon_err_restore(void* handle)
|
||||
{
|
||||
struct err_state *es;
|
||||
|
||||
if ((es = (struct err_state *)handle) != NULL){
|
||||
clicon_errno = es->es_errno;
|
||||
clicon_suberrno = es->es_suberrno;
|
||||
strncpy(clicon_err_reason, es->es_reason, ERR_STRLEN);
|
||||
_err_category = es->es_category;
|
||||
_err_subnr = es->es_subnr;
|
||||
strncpy(_err_reason, es->es_reason, ERR_STRLEN);
|
||||
free(es);
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -341,18 +429,18 @@ clicon_err_restore(void* handle)
|
|||
|
||||
/*! Register error categories for application-based error handling
|
||||
*
|
||||
* @param[in] category Applies for this category (first arg to clicon_err())
|
||||
* @param[in] category Applies for this category (first arg to clixon_err())
|
||||
* @param[in] logfn Call att error for generating application-defined errstring
|
||||
*/
|
||||
int
|
||||
clixon_err_cat_reg(enum clicon_err category,
|
||||
void *handle,
|
||||
clixon_cat_log_cb logfn)
|
||||
clixon_err_cat_reg(enum clixon_err category,
|
||||
void *handle,
|
||||
clixon_cat_log_cb logfn)
|
||||
{
|
||||
clixon_err_cats *cec;
|
||||
|
||||
if ((cec = malloc(sizeof *cec)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return -1;
|
||||
}
|
||||
memset(cec, 0, sizeof *cec);
|
||||
|
|
|
|||
|
|
@ -56,9 +56,10 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_sig.h"
|
||||
#include "clixon_proc.h"
|
||||
|
|
@ -184,7 +185,7 @@ clixon_event_reg_fd(int fd,
|
|||
struct event_data *e;
|
||||
|
||||
if ((e = (struct event_data *)malloc(sizeof(struct event_data))) == NULL){
|
||||
clicon_err(OE_EVENTS, errno, "malloc");
|
||||
clixon_err(OE_EVENTS, errno, "malloc");
|
||||
return -1;
|
||||
}
|
||||
memset(e, 0, sizeof(struct event_data));
|
||||
|
|
@ -267,11 +268,11 @@ clixon_event_reg_timeout(struct timeval t,
|
|||
struct event_data **e_prev;
|
||||
|
||||
if (str == NULL || fn == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "str or fn is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "str or fn is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((e = (struct event_data *)malloc(sizeof(struct event_data))) == NULL){
|
||||
clicon_err(OE_EVENTS, errno, "malloc");
|
||||
clixon_err(OE_EVENTS, errno, "malloc");
|
||||
return -1;
|
||||
}
|
||||
memset(e, 0, sizeof(struct event_data));
|
||||
|
|
@ -344,7 +345,7 @@ clixon_event_poll(int fd)
|
|||
FD_ZERO(&fdset);
|
||||
FD_SET(fd, &fdset);
|
||||
if ((retval = select(FD_SETSIZE, &fdset, NULL, NULL, &tnull)) < 0)
|
||||
clicon_err(OE_EVENTS, errno, "select");
|
||||
clixon_err(OE_EVENTS, errno, "select");
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -358,7 +359,7 @@ clixon_event_poll(int fd)
|
|||
* One could try to poll the file descriptors after a timeout?
|
||||
*/
|
||||
int
|
||||
clixon_event_loop(clicon_handle h)
|
||||
clixon_event_loop(clixon_handle h)
|
||||
{
|
||||
struct event_data *e;
|
||||
struct event_data *e_next;
|
||||
|
|
@ -407,7 +408,7 @@ clixon_event_loop(clicon_handle h)
|
|||
*/
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s select: %s", __FUNCTION__, strerror(errno));
|
||||
if (clixon_exit_get() == 1){
|
||||
clicon_err(OE_EVENTS, errno, "select");
|
||||
clixon_err(OE_EVENTS, errno, "select");
|
||||
retval = 0;
|
||||
}
|
||||
else if (clicon_sig_child_get()){
|
||||
|
|
@ -422,10 +423,10 @@ clixon_event_loop(clicon_handle h)
|
|||
continue;
|
||||
}
|
||||
else
|
||||
clicon_err(OE_EVENTS, errno, "select");
|
||||
clixon_err(OE_EVENTS, errno, "select");
|
||||
}
|
||||
else
|
||||
clicon_err(OE_EVENTS, errno, "select");
|
||||
clixon_err(OE_EVENTS, errno, "select");
|
||||
goto err;
|
||||
}
|
||||
if (n==0){ /* Timeout */
|
||||
|
|
|
|||
|
|
@ -55,11 +55,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_file.h"
|
||||
|
||||
/*! qsort "compar" for directory alphabetically sorting, see qsort(3)
|
||||
|
|
@ -91,7 +94,7 @@ clicon_files_recursive1(const char *dir,
|
|||
struct stat st;
|
||||
|
||||
if (dir == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "Requires dir != NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "Requires dir != NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((dirp = opendir(dir)) != NULL)
|
||||
|
|
@ -115,13 +118,13 @@ clicon_files_recursive1(const char *dir,
|
|||
continue;
|
||||
snprintf(path, MAXPATHLEN-1, "%s/%s", dir, dent->d_name);
|
||||
if ((res = lstat(path, &st)) != 0){
|
||||
clicon_err(OE_UNIX, errno, "lstat");
|
||||
clixon_err(OE_UNIX, errno, "lstat");
|
||||
goto done;
|
||||
}
|
||||
if ((st.st_mode & S_IFREG) == 0)
|
||||
continue;
|
||||
if (cvec_add_string(cvv, dent->d_name, path) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add_string");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add_string");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -148,7 +151,7 @@ clicon_files_recursive(const char *dir,
|
|||
clixon_debug(CLIXON_DBG_DETAIL, "%s dir:%s", __FUNCTION__, dir);
|
||||
if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) {
|
||||
regerror(res, &re, errbuf, sizeof(errbuf));
|
||||
clicon_err(OE_DB, 0, "regcomp: %s", errbuf);
|
||||
clixon_err(OE_DB, 0, "regcomp: %s", errbuf);
|
||||
goto done;
|
||||
}
|
||||
if (clicon_files_recursive1(dir, &re, cvv) < 0)
|
||||
|
|
@ -206,14 +209,14 @@ clicon_file_dirent(const char *dir,
|
|||
nent = 0;
|
||||
if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) {
|
||||
regerror(res, &re, errbuf, sizeof(errbuf));
|
||||
clicon_err(OE_DB, 0, "regcomp: %s", errbuf);
|
||||
clixon_err(OE_DB, 0, "regcomp: %s", errbuf);
|
||||
return -1;
|
||||
}
|
||||
if ((dirp = opendir(dir)) == NULL) {
|
||||
if (errno == ENOENT) /* Dir does not exist -> return 0 matches */
|
||||
retval = 0;
|
||||
else
|
||||
clicon_err(OE_UNIX, errno, "opendir(%s)", dir);
|
||||
clixon_err(OE_UNIX, errno, "opendir(%s)", dir);
|
||||
goto quit;
|
||||
}
|
||||
while((dent = readdir(dirp)) != NULL) {
|
||||
|
|
@ -227,7 +230,7 @@ clicon_file_dirent(const char *dir,
|
|||
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dent->d_name);
|
||||
res = lstat(filename, &st);
|
||||
if (res != 0) {
|
||||
clicon_err(OE_UNIX, errno, "lstat");
|
||||
clixon_err(OE_UNIX, errno, "lstat");
|
||||
goto quit;
|
||||
}
|
||||
if ((type & st.st_mode) == 0)
|
||||
|
|
@ -235,7 +238,7 @@ clicon_file_dirent(const char *dir,
|
|||
}
|
||||
direntStructSize = offsetof(struct dirent, d_name) + strlen(dent->d_name) + 1;
|
||||
if ((new = realloc(new, (nent+1)*sizeof(struct dirent))) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "realloc");
|
||||
clixon_err(OE_UNIX, errno, "realloc");
|
||||
goto quit;
|
||||
} /* realloc */
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize);
|
||||
|
|
@ -280,21 +283,21 @@ clicon_file_copy(char *src,
|
|||
struct stat st;
|
||||
|
||||
if (stat(src, &st) != 0){
|
||||
clicon_err(OE_UNIX, errno, "stat");
|
||||
clixon_err(OE_UNIX, errno, "stat");
|
||||
return -1;
|
||||
}
|
||||
if((inF = open(src, O_RDONLY)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s) for read", src);
|
||||
clixon_err(OE_UNIX, errno, "open(%s) for read", src);
|
||||
return -1;
|
||||
}
|
||||
if((ouF = open(target, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s) for write", target);
|
||||
clixon_err(OE_UNIX, errno, "open(%s) for write", target);
|
||||
err = errno;
|
||||
goto error;
|
||||
}
|
||||
while((bytes = read(inF, line, sizeof(line))) > 0)
|
||||
if (write(ouF, line, bytes) < 0){
|
||||
clicon_err(OE_UNIX, errno, "write(%s)", src);
|
||||
clixon_err(OE_UNIX, errno, "write(%s)", src);
|
||||
err = errno;
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -327,16 +330,16 @@ clicon_file_cbuf(const char *filename,
|
|||
struct stat st;
|
||||
|
||||
if (stat(filename, &st) != 0){
|
||||
clicon_err(OE_UNIX, errno, "stat");
|
||||
clixon_err(OE_UNIX, errno, "stat");
|
||||
return -1;
|
||||
}
|
||||
if ((fd = open(filename, O_RDONLY)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s) for read", filename);
|
||||
clixon_err(OE_UNIX, errno, "open(%s) for read", filename);
|
||||
return -1;
|
||||
}
|
||||
while((bytes = read(fd, line, sizeof(line))) > 0)
|
||||
if (cbuf_append_buf(cb, line, bytes) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_append_buf(%s)", filename);
|
||||
clixon_err(OE_UNIX, errno, "cbuf_append_buf(%s)", filename);
|
||||
err = errno;
|
||||
goto error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,11 +49,12 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -61,15 +62,15 @@
|
|||
#include "clixon_data.h"
|
||||
#include "clixon_options.h"
|
||||
|
||||
#define CLICON_MAGIC 0x99aafabe
|
||||
#define CLIXON_MAGIC 0x99aafabe
|
||||
|
||||
#define handle(h) (assert(clicon_handle_check(h)==0),(struct clicon_handle *)(h))
|
||||
#define handle(h) (assert(clixon_handle_check(h)==0),(struct clixon_handle *)(h))
|
||||
|
||||
/*! Internal structure of basic handle. Also header of all other handles.
|
||||
*
|
||||
* @note If you change here, you must also change the structs below:
|
||||
* This is the internal definition of a "Clixon handle" which in its external
|
||||
* form is "clicon_handle" and is used in most Clixon API calls.
|
||||
* form is "clixon_handle" and is used in most Clixon API calls.
|
||||
* Some details:
|
||||
* 1) the internal structure contains a header (defined here) whereas higher
|
||||
* order libs (eg cli and backend) introduce more fields appended to this
|
||||
|
|
@ -86,7 +87,7 @@
|
|||
* @see struct backend_handle
|
||||
* @see struct restconf_handle
|
||||
*/
|
||||
struct clicon_handle {
|
||||
struct clixon_handle {
|
||||
int ch_magic; /* magic (HDR) */
|
||||
clicon_hash_t *ch_copt; /* clicon option list (HDR) */
|
||||
clicon_hash_t *ch_data; /* internal clicon data (HDR) */
|
||||
|
|
@ -103,31 +104,31 @@ struct clicon_handle {
|
|||
* So far the only common options is a MAGIC cookie for sanity checks and
|
||||
* CLICON options
|
||||
*/
|
||||
clicon_handle
|
||||
clicon_handle_init0(int size)
|
||||
clixon_handle
|
||||
clixon_handle_init0(int size)
|
||||
{
|
||||
struct clicon_handle *ch;
|
||||
clicon_handle h = NULL;
|
||||
struct clixon_handle *ch;
|
||||
clixon_handle h = NULL;
|
||||
|
||||
if ((ch = malloc(size)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(ch, 0, size);
|
||||
ch->ch_magic = CLICON_MAGIC;
|
||||
ch->ch_magic = CLIXON_MAGIC;
|
||||
if ((ch->ch_copt = clicon_hash_init()) == NULL){
|
||||
clicon_handle_exit((clicon_handle)ch);
|
||||
clixon_handle_exit((clixon_handle)ch);
|
||||
goto done;
|
||||
}
|
||||
if ((ch->ch_data = clicon_hash_init()) == NULL){
|
||||
clicon_handle_exit((clicon_handle)ch);
|
||||
clixon_handle_exit((clixon_handle)ch);
|
||||
goto done;
|
||||
}
|
||||
if ((ch->ch_db_elmnt = clicon_hash_init()) == NULL){
|
||||
clicon_handle_exit((clicon_handle)ch);
|
||||
clixon_handle_exit((clixon_handle)ch);
|
||||
goto done;
|
||||
}
|
||||
h = (clicon_handle)ch;
|
||||
h = (clixon_handle)ch;
|
||||
done:
|
||||
return h;
|
||||
}
|
||||
|
|
@ -140,10 +141,10 @@ clicon_handle_init0(int size)
|
|||
* elaborate applications (cli/backend/netconf). This should be used by the most
|
||||
* basic applications that use CLICON lib directly.
|
||||
*/
|
||||
clicon_handle
|
||||
clicon_handle_init(void)
|
||||
clixon_handle
|
||||
clixon_handle_init(void)
|
||||
{
|
||||
return clicon_handle_init0(sizeof(struct clicon_handle));
|
||||
return clixon_handle_init0(sizeof(struct clixon_handle));
|
||||
}
|
||||
|
||||
/*! Deallocate clicon handle, including freeing handle data.
|
||||
|
|
@ -154,10 +155,10 @@ clicon_handle_init(void)
|
|||
* @note: handle 'h' cannot be used in calls after this
|
||||
*/
|
||||
int
|
||||
clicon_handle_exit(clicon_handle h)
|
||||
clixon_handle_exit(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
clicon_hash_t *ha;
|
||||
|
||||
if ((ha = clicon_options(h)) != NULL)
|
||||
|
|
@ -179,12 +180,12 @@ clicon_handle_exit(clicon_handle h)
|
|||
* @retval -1 Sanity check failed
|
||||
*/
|
||||
int
|
||||
clicon_handle_check(clicon_handle h)
|
||||
clixon_handle_check(clixon_handle h)
|
||||
{
|
||||
/* Dont use handle macro to avoid recursion */
|
||||
struct clicon_handle *ch = (struct clicon_handle *)(h);
|
||||
struct clixon_handle *ch = (struct clixon_handle *)(h);
|
||||
|
||||
return ch->ch_magic == CLICON_MAGIC ? 0 : -1;
|
||||
return ch->ch_magic == CLIXON_MAGIC ? 0 : -1;
|
||||
}
|
||||
|
||||
/*! Return clicon options (hash-array) given a handle.
|
||||
|
|
@ -192,9 +193,9 @@ clicon_handle_check(clicon_handle h)
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
clicon_hash_t *
|
||||
clicon_options(clicon_handle h)
|
||||
clicon_options(clixon_handle h)
|
||||
{
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
|
||||
return ch->ch_copt;
|
||||
}
|
||||
|
|
@ -204,9 +205,9 @@ clicon_options(clicon_handle h)
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
clicon_hash_t *
|
||||
clicon_data(clicon_handle h)
|
||||
clicon_data(clixon_handle h)
|
||||
{
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
|
||||
return ch->ch_data;
|
||||
}
|
||||
|
|
@ -216,9 +217,9 @@ clicon_data(clicon_handle h)
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
clicon_hash_t *
|
||||
clicon_db_elmnt(clicon_handle h)
|
||||
clicon_db_elmnt(clixon_handle h)
|
||||
{
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
|
||||
return ch->ch_db_elmnt;
|
||||
}
|
||||
|
|
@ -228,28 +229,28 @@ clicon_db_elmnt(clicon_handle h)
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
event_stream_t *
|
||||
clicon_stream(clicon_handle h)
|
||||
clicon_stream(clixon_handle h)
|
||||
{
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
|
||||
return ch->ch_stream;
|
||||
}
|
||||
|
||||
int
|
||||
clicon_stream_set(clicon_handle h,
|
||||
clicon_stream_set(clixon_handle h,
|
||||
event_stream_t *es)
|
||||
{
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
|
||||
ch->ch_stream = es;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
clicon_stream_append(clicon_handle h,
|
||||
clicon_stream_append(clixon_handle h,
|
||||
event_stream_t *es)
|
||||
{
|
||||
struct clicon_handle *ch = handle(h);
|
||||
struct clixon_handle *ch = handle(h);
|
||||
|
||||
ADDQ(es, ch->ch_stream);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -95,8 +95,9 @@
|
|||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
|
||||
#define HASH_SIZE 1031 /* Number of hash buckets. Should be a prime */
|
||||
#define align4(s) (((s)/4)*4 + 4)
|
||||
|
|
@ -125,7 +126,7 @@ clicon_hash_init(void)
|
|||
clicon_hash_t *hash;
|
||||
|
||||
if ((hash = (clicon_hash_t *)malloc(sizeof(clicon_hash_t) * HASH_SIZE)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(hash, 0, sizeof(clicon_hash_t)*HASH_SIZE);
|
||||
|
|
@ -197,7 +198,7 @@ clicon_hash_value(clicon_hash_t *hash,
|
|||
clicon_hash_t h;
|
||||
|
||||
if (hash == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
return NULL;
|
||||
}
|
||||
h = clicon_hash_lookup(hash, key);
|
||||
|
|
@ -230,26 +231,26 @@ clicon_hash_add(clicon_hash_t *hash,
|
|||
clicon_hash_t new = NULL;
|
||||
|
||||
if (hash == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
return NULL;
|
||||
}
|
||||
/* Check NULL case */
|
||||
if ((val == NULL && vlen != 0) ||
|
||||
(val != NULL && vlen == 0)){
|
||||
clicon_err(OE_UNIX, EINVAL, "Mismatch in value and length, only one is zero");
|
||||
clixon_err(OE_UNIX, EINVAL, "Mismatch in value and length, only one is zero");
|
||||
goto catch;
|
||||
}
|
||||
/* If variable exist, don't allocate a new. just replace value */
|
||||
h = clicon_hash_lookup(hash, key);
|
||||
if (h == NULL) {
|
||||
if ((new = (clicon_hash_t)malloc(sizeof(*new))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto catch;
|
||||
}
|
||||
memset(new, 0, sizeof(*new));
|
||||
new->h_key = strdup(key);
|
||||
if (new->h_key == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto catch;
|
||||
}
|
||||
h = new;
|
||||
|
|
@ -258,7 +259,7 @@ clicon_hash_add(clicon_hash_t *hash,
|
|||
/* Make copy of value. aligned */
|
||||
newval = malloc(align4(vlen+3));
|
||||
if (newval == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto catch;
|
||||
}
|
||||
memcpy(newval, val, vlen);
|
||||
|
|
@ -299,7 +300,7 @@ clicon_hash_del(clicon_hash_t *hash,
|
|||
clicon_hash_t h;
|
||||
|
||||
if (hash == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
return -1;
|
||||
}
|
||||
h = clicon_hash_lookup(hash, key);
|
||||
|
|
@ -334,7 +335,7 @@ clicon_hash_keys(clicon_hash_t *hash,
|
|||
char **keys = NULL;
|
||||
|
||||
if (hash == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "hash is NULL");
|
||||
return -1;
|
||||
}
|
||||
*nkeys = 0;
|
||||
|
|
@ -345,7 +346,7 @@ clicon_hash_keys(clicon_hash_t *hash,
|
|||
break;
|
||||
tmp = realloc(keys, ((*nkeys)+1) * sizeof(char *));
|
||||
if (tmp == NULL){
|
||||
clicon_err(OE_UNIX, errno, "realloc");
|
||||
clixon_err(OE_UNIX, errno, "realloc");
|
||||
goto catch;
|
||||
}
|
||||
keys = tmp;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_path.h"
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@
|
|||
/* typecast macro */
|
||||
#define _IY ((clixon_instance_id_yacc *)_iy)
|
||||
|
||||
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_instance_id_parsetext, _IY->iy_linenum); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_instance_id_parsetext, _IY->iy_linenum); YYERROR;}
|
||||
|
||||
/* add _yy to error parameters */
|
||||
#define YY_(msgid) msgid
|
||||
|
|
@ -115,12 +115,13 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_path.h"
|
||||
|
|
@ -140,7 +141,7 @@ void
|
|||
clixon_instance_id_parseerror(void *_iy,
|
||||
char *s)
|
||||
{
|
||||
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
|
||||
clixon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
|
||||
_IY->iy_name,
|
||||
_IY->iy_linenum ,
|
||||
s,
|
||||
|
|
@ -198,17 +199,17 @@ path_new(char *prefix,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, prefix, id);
|
||||
if ((cp = malloc(sizeof(*cp))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(cp, 0, sizeof(*cp));
|
||||
if (prefix)
|
||||
if ((cp->cp_prefix = strdup(prefix)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if ((cp->cp_id = strdup(id)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
return cp;
|
||||
|
|
@ -228,18 +229,18 @@ keyval_pos(char *uint)
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s)", __FUNCTION__, uint);
|
||||
if ((cvv = cvec_new(1)) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(cvv, 0);
|
||||
cv_type_set(cv, CGV_UINT32);
|
||||
if ((ret = cv_parse1(uint, cv, &reason)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cv_parse1");
|
||||
clixon_err(OE_UNIX, errno, "cv_parse1");
|
||||
cvv = NULL;
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_UNIX, errno, "cv_parse1: %s", reason);
|
||||
clixon_err(OE_UNIX, errno, "cv_parse1: %s", reason);
|
||||
cvv = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -265,11 +266,11 @@ keyval_add(cvec *cvv,
|
|||
goto done;
|
||||
if (cvv == NULL &&
|
||||
(cvv = cvec_new(0)) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (cvec_append_var(cvv, cv) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_append_var");
|
||||
clixon_err(OE_UNIX, errno, "cvec_append_var");
|
||||
cvv = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -288,16 +289,16 @@ keyval_set(char *name,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name, val);
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_new");
|
||||
clixon_err(OE_UNIX, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (name && cv_name_set(cv, name) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
cv = NULL;
|
||||
goto done;
|
||||
}
|
||||
if (cv_string_set(cv, val) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
cv = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,12 +58,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -355,7 +356,7 @@ json2xml_decode_identityref(cxobj *x,
|
|||
/* Here prefix2 is valid and can be NULL
|
||||
Change body prefix to prefix2:id */
|
||||
if ((cbv = cbuf_new()) == NULL){
|
||||
clicon_err(OE_JSON, errno, "cbuf_new");
|
||||
clixon_err(OE_JSON, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (prefix2)
|
||||
|
|
@ -540,7 +541,7 @@ xml2json_encode_leafs(cxobj *xb,
|
|||
cbuf *cb = NULL; /* the variable itself */
|
||||
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
body = xb?xml_value(xb):NULL;
|
||||
|
|
@ -953,7 +954,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
break;
|
||||
}
|
||||
if ((metacbc = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Check for typed sub-body if:
|
||||
|
|
@ -1282,7 +1283,7 @@ clixon_json2file(FILE *f,
|
|||
if (fn == NULL)
|
||||
fn = fprintf;
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_json2cbuf(cb, xn, pretty, skiptop, autocliext) < 0)
|
||||
|
|
@ -1335,7 +1336,7 @@ xml2json_vec(FILE *f,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml2json_cbuf_vec(cb, vec, veclen, pretty, skiptop) < 0)
|
||||
|
|
@ -1428,7 +1429,7 @@ json_xmlns_translate(yang_stmt *yspec,
|
|||
* @param[out] xerr Reason for invalid returned as netconf err msg
|
||||
* @retval 1 OK and valid
|
||||
* @retval 0 Invalid (only if yang spec)
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @see _xml_parse for XML variant
|
||||
* @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
|
||||
|
|
@ -1460,9 +1461,9 @@ _json_parse(char *str,
|
|||
if (json_parse_init(&jy) < 0)
|
||||
goto done;
|
||||
if (clixon_json_parseparse(&jy) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "JSON error: line %d", jy.jy_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_JSON, 0, "JSON parser error with no error code (should not happen)");
|
||||
clixon_log(NULL, LOG_NOTICE, "JSON error: line %d", jy.jy_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_JSON, 0, "JSON parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
/* Traverse new objects */
|
||||
|
|
@ -1475,7 +1476,7 @@ _json_parse(char *str,
|
|||
/* XXX: For top-level config file: */
|
||||
if (yb != YB_NONE || strcmp(xml_name(x),DATASTORE_TOP_SYMBOL)!=0){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Top-level JSON object %s is not qualified with namespace which is a MUST according to RFC 7951", xml_name(x));
|
||||
|
|
@ -1559,7 +1560,7 @@ _json_parse(char *str,
|
|||
* @param[out] xerr Reason for invalid returned as netconf err msg
|
||||
* @retval 1 OK and valid
|
||||
* @retval 0 Invalid (only if yang spec) w xerr set
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @code
|
||||
* cxobj *x = NULL;
|
||||
|
|
@ -1581,7 +1582,7 @@ clixon_json_parse_string(char *str,
|
|||
{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (xt==NULL){
|
||||
clicon_err(OE_JSON, EINVAL, "xt is NULL");
|
||||
clixon_err(OE_JSON, EINVAL, "xt is NULL");
|
||||
return -1;
|
||||
}
|
||||
if (*xt == NULL){
|
||||
|
|
@ -1611,7 +1612,7 @@ clixon_json_parse_string(char *str,
|
|||
* @param[out] xerr Reason for invalid returned as netconf err msg
|
||||
* @retval 1 OK and valid
|
||||
* @retval 0 Invalid (only if yang spec) w xerr set
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @code
|
||||
* cxobj *xt = NULL;
|
||||
|
|
@ -1643,18 +1644,18 @@ clixon_json_parse_file(FILE *fp,
|
|||
int len = 0;
|
||||
|
||||
if (xt==NULL){
|
||||
clicon_err(OE_JSON, EINVAL, "xt is NULL");
|
||||
clixon_err(OE_JSON, EINVAL, "xt is NULL");
|
||||
return -1;
|
||||
}
|
||||
if ((jsonbuf = malloc(jsonbuflen)) == NULL){
|
||||
clicon_err(OE_JSON, errno, "malloc");
|
||||
clixon_err(OE_JSON, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(jsonbuf, 0, jsonbuflen);
|
||||
ptr = jsonbuf;
|
||||
while (1){
|
||||
if ((ret = fread(&ch, 1, 1, fp)) < 0){
|
||||
clicon_err(OE_JSON, errno, "read");
|
||||
clixon_err(OE_JSON, errno, "read");
|
||||
break;
|
||||
}
|
||||
if (ret != 0)
|
||||
|
|
@ -1675,7 +1676,7 @@ clixon_json_parse_file(FILE *fp,
|
|||
oldjsonbuflen = jsonbuflen;
|
||||
jsonbuflen *= 2;
|
||||
if ((jsonbuf = realloc(jsonbuf, jsonbuflen)) == NULL){
|
||||
clicon_err(OE_JSON, errno, "realloc");
|
||||
clixon_err(OE_JSON, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
memset(jsonbuf+oldjsonbuflen, 0, jsonbuflen-oldjsonbuflen);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
#include "clixon_string.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_json_parse.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ object.
|
|||
/* typecast macro */
|
||||
#define _JY ((clixon_json_yacc *)_jy)
|
||||
|
||||
#define _YYERROR(msg) {clicon_err(OE_JSON, 0, "YYERROR %s '%s' %d", (msg), clixon_json_parsetext, _JY->jy_linenum); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_JSON, 0, "YYERROR %s '%s' %d", (msg), clixon_json_parsetext, _JY->jy_linenum); YYERROR;}
|
||||
|
||||
/* add _yy to error parameters */
|
||||
#define YY_(msgid) msgid
|
||||
|
|
@ -124,12 +124,14 @@ object.
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
||||
|
|
@ -152,7 +154,7 @@ void
|
|||
clixon_json_parseerror(void *_jy,
|
||||
char *s)
|
||||
{
|
||||
clicon_err(OE_JSON, 0, "json_parse: line %d: %s at or before: '%s'",
|
||||
clixon_err(OE_JSON, 0, "json_parse: line %d: %s at or before: '%s'",
|
||||
_JY->jy_linenum,
|
||||
s,
|
||||
clixon_json_parsetext);
|
||||
|
|
@ -164,7 +166,6 @@ clixon_json_parseerror(void *_jy,
|
|||
int
|
||||
json_parse_init(clixon_json_yacc *jy)
|
||||
{
|
||||
// clixon_debug_init(2, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
|
|
@ -56,61 +56,86 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_log.h"
|
||||
|
||||
/* The global debug level. 0 means no debug
|
||||
* @note There are pros and cons in having the debug state as a global variable. The
|
||||
* alternative to bind it to the clicon handle (h) was considered but it limits its
|
||||
* usefulness, since not all functions have h
|
||||
/*
|
||||
* Local Variables
|
||||
*/
|
||||
static int _clixon_debug = 0;
|
||||
|
||||
/* Bitmask whether to log to syslog or stderr: CLICON_LOG_STDERR | CLICON_LOG_SYSLOG */
|
||||
static int _logflags = 0x0;
|
||||
/* Cache handle since some error calls does not have handle access */
|
||||
static clixon_handle _log_clixon_h = NULL;
|
||||
|
||||
/* Bitmask whether to log to syslog or stderr: CLIXON_LOG_STDERR | CLIXON_LOG_SYSLOG */
|
||||
static int _log_flags = 0x0;
|
||||
|
||||
/* Set to open file to write debug messages directly to file */
|
||||
static FILE *_logfile = NULL;
|
||||
static FILE *_log_file = NULL;
|
||||
|
||||
/* Truncate debug strings to this length. 0 means unlimited */
|
||||
static int _clixon_log_trunc = 0;
|
||||
static int _log_trunc = 0;
|
||||
|
||||
/*! Initialize system logger.
|
||||
*
|
||||
* Make syslog(3) calls with specified ident and gates calls of level upto specified level (upto).
|
||||
* May also print to stderr, if err is set.
|
||||
* Applies to clicon_err() and clixon_debug too
|
||||
* Applies to clixon_err() and clixon_debug too
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] ident prefix that appears on syslog (eg 'cli')
|
||||
* @param[in] upto log priority, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG (see syslog(3)).
|
||||
* @param[in] flags bitmask: if CLICON_LOG_STDERR, then print logs to stderr
|
||||
* if CLICON_LOG_SYSLOG, then print logs to syslog
|
||||
* @param[in] flags bitmask: if CLIXON_LOG_STDERR, then print logs to stderr
|
||||
* if CLIXON_LOG_SYSLOG, then print logs to syslog
|
||||
* You can do a combination of both
|
||||
* @retval 0 OK
|
||||
* @code
|
||||
* clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR);
|
||||
* clixon_log_init(__PROGRAM__, LOG_INFO, CLIXON_LOG_STDERR);
|
||||
* @endcode
|
||||
*/
|
||||
int
|
||||
clicon_log_init(char *ident,
|
||||
int upto,
|
||||
int flags)
|
||||
clixon_log_init(clixon_handle h,
|
||||
char *ident,
|
||||
int upto,
|
||||
int flags)
|
||||
{
|
||||
_logflags = flags;
|
||||
if (flags & CLICON_LOG_SYSLOG){
|
||||
if (h == NULL){
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
_log_clixon_h = h;
|
||||
_log_flags = flags;
|
||||
if (flags & CLIXON_LOG_SYSLOG){
|
||||
if (setlogmask(LOG_UPTO(upto)) < 0)
|
||||
/* Cant syslog here */
|
||||
fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno));
|
||||
openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clicon_log */
|
||||
openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clixon_log */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef COMPAT_6_5
|
||||
/* Required for clixon-example autoconf
|
||||
*/
|
||||
int
|
||||
clicon_log_exit(void)
|
||||
clicon_log_init(char *ident,
|
||||
int upto,
|
||||
int flags)
|
||||
{
|
||||
if (_logfile)
|
||||
fclose(_logfile);
|
||||
return clixon_log_init(NULL, ident, upto, flags);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
clixon_log_exit(void)
|
||||
{
|
||||
if (_log_file)
|
||||
fclose(_log_file);
|
||||
closelog(); /* optional */
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -118,26 +143,26 @@ clicon_log_exit(void)
|
|||
/*! Utility function to set log destination/flag using command-line option
|
||||
*
|
||||
* @param[in] c Log option,one of s,f,e,o
|
||||
* @retval 0 One of CLICON_LOG_SYSLOG|STDERR|STDOUT|FILE
|
||||
* @retval 0 One of CLIXON_LOG_SYSLOG|STDERR|STDOUT|FILE
|
||||
* @retval -1 No match
|
||||
*/
|
||||
int
|
||||
clicon_log_opt(char c)
|
||||
clixon_log_opt(char c)
|
||||
{
|
||||
int logdst = -1;
|
||||
|
||||
switch (c){
|
||||
case 's':
|
||||
logdst = CLICON_LOG_SYSLOG;
|
||||
logdst = CLIXON_LOG_SYSLOG;
|
||||
break;
|
||||
case 'e':
|
||||
logdst = CLICON_LOG_STDERR;
|
||||
logdst = CLIXON_LOG_STDERR;
|
||||
break;
|
||||
case 'o':
|
||||
logdst = CLICON_LOG_STDOUT;
|
||||
logdst = CLIXON_LOG_STDOUT;
|
||||
break;
|
||||
case 'f':
|
||||
logdst = CLICON_LOG_FILE;
|
||||
logdst = CLIXON_LOG_FILE;
|
||||
break;
|
||||
case 'n':
|
||||
logdst = 0;
|
||||
|
|
@ -148,7 +173,7 @@ clicon_log_opt(char c)
|
|||
return logdst;
|
||||
}
|
||||
|
||||
/*! If log flags include CLICON_LOG_FILE, set the file
|
||||
/*! If log flags include CLIXON_LOG_FILE, set the file
|
||||
*
|
||||
* @param[in] filename File to log to
|
||||
* @retval 0 OK
|
||||
|
|
@ -156,38 +181,64 @@ clicon_log_opt(char c)
|
|||
* @see clixon_debug_init where a strean
|
||||
*/
|
||||
int
|
||||
clicon_log_file(char *filename)
|
||||
clixon_log_file(char *filename)
|
||||
{
|
||||
if (_logfile)
|
||||
fclose(_logfile);
|
||||
if ((_logfile = fopen(filename, "a")) == NULL){
|
||||
fprintf(stderr, "fopen: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
if (_log_file)
|
||||
fclose(_log_file);
|
||||
if ((_log_file = fopen(filename, "a")) == NULL){
|
||||
fprintf(stderr, "fopen: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
clicon_get_logflags(void)
|
||||
clixon_get_logflags(void)
|
||||
{
|
||||
return _logflags;
|
||||
return _log_flags;
|
||||
}
|
||||
|
||||
/*! Truncate log/debug string length
|
||||
*/
|
||||
int
|
||||
clicon_log_string_limit_set(size_t sz)
|
||||
clixon_log_string_limit_set(size_t sz)
|
||||
{
|
||||
_clixon_log_trunc = sz;
|
||||
_log_trunc = sz;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get truncate log/debug string length
|
||||
*/
|
||||
size_t
|
||||
clicon_log_string_limit_get(void)
|
||||
clixon_log_string_limit_get(void)
|
||||
{
|
||||
return _clixon_log_trunc;
|
||||
return _log_trunc;
|
||||
}
|
||||
|
||||
/*! Translate month number (0..11) to a three letter month name
|
||||
*
|
||||
* @param[in] md month number, where 0 is january
|
||||
*/
|
||||
static char *
|
||||
mon2name(int md)
|
||||
{
|
||||
switch(md){
|
||||
case 0: return "Jan";
|
||||
case 1: return "Feb";
|
||||
case 2: return "Mar";
|
||||
case 3: return "Apr";
|
||||
case 4: return "May";
|
||||
case 5: return "Jun";
|
||||
case 6: return "Jul";
|
||||
case 7: return "Aug";
|
||||
case 8: return "Sep";
|
||||
case 9: return "Oct";
|
||||
case 10: return "Nov";
|
||||
case 11: return "Dec";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Mimic syslog and print a time on file f
|
||||
|
|
@ -241,28 +292,28 @@ slogtime(void)
|
|||
* @see clixon_debug
|
||||
*/
|
||||
int
|
||||
clicon_log_str(int level,
|
||||
clixon_log_str(int level,
|
||||
char *msg)
|
||||
{
|
||||
if (_logflags & CLICON_LOG_SYSLOG)
|
||||
if (_log_flags & CLIXON_LOG_SYSLOG)
|
||||
syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg); // XXX this may block
|
||||
/* syslog makes own filtering, we do it here:
|
||||
* if normal (not debug) then filter loglevels >= debug
|
||||
*/
|
||||
if (_clixon_debug == 0 && level >= LOG_DEBUG)
|
||||
if (clixon_debug_get() == 0 && level >= LOG_DEBUG)
|
||||
goto done;
|
||||
if (_logflags & CLICON_LOG_STDERR){
|
||||
if (_log_flags & CLIXON_LOG_STDERR){
|
||||
flogtime(stderr);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
||||
if (_logflags & CLICON_LOG_STDOUT){
|
||||
if (_log_flags & CLIXON_LOG_STDOUT){
|
||||
flogtime(stdout);
|
||||
fprintf(stdout, "%s\n", msg);
|
||||
}
|
||||
if ((_logflags & CLICON_LOG_FILE) && _logfile){
|
||||
flogtime(_logfile);
|
||||
fprintf(_logfile, "%s\n", msg);
|
||||
fflush(_logfile);
|
||||
if ((_log_flags & CLIXON_LOG_FILE) && _log_file){
|
||||
flogtime(_log_file);
|
||||
fprintf(_log_file, "%s\n", msg);
|
||||
fflush(_log_file);
|
||||
}
|
||||
/* Enable this if you want syslog in a stream. But there are problems with
|
||||
* recursion
|
||||
|
|
@ -273,20 +324,22 @@ clicon_log_str(int level,
|
|||
|
||||
/*! Make a logging call to syslog using variable arg syntax.
|
||||
*
|
||||
* @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. This
|
||||
* is OR:d with facility == LOG_USER
|
||||
* @param[in] format Message to print as argv.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @param[in] h Clixon handle (may be NULL)
|
||||
* @param[in] level Log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. This
|
||||
* is OR:d with facility == LOG_USER
|
||||
* @param[in] format Message to print as argv.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
clicon_log(LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__);
|
||||
clixon_log(h, LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__);
|
||||
* @endcode
|
||||
* @see clicon_log_init clicon_log_str
|
||||
* @see clicon_log_xml
|
||||
* @see clixon_log_init clixon_log_str
|
||||
* @see clixon_log_xml
|
||||
*/
|
||||
int
|
||||
clicon_log(int level,
|
||||
const char *format, ...)
|
||||
clixon_log(clixon_handle h,
|
||||
int level,
|
||||
const char *format, ...)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
|
|
@ -300,12 +353,12 @@ clicon_log(int level,
|
|||
va_end(args);
|
||||
|
||||
/* Truncate long debug strings */
|
||||
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
|
||||
if ((trunc = clixon_log_string_limit_get()) && trunc < len)
|
||||
len = trunc;
|
||||
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -313,12 +366,12 @@ clicon_log(int level,
|
|||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
/* Actually log it */
|
||||
clicon_log_str(level, msg);
|
||||
clixon_log_str(level, msg);
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -326,123 +379,3 @@ clicon_log(int level,
|
|||
free(msg);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Initialize debug messages. Set debug level.
|
||||
*
|
||||
* Initialize debug module. The level is used together with clixon_debug(dbglevel) calls as follows:
|
||||
* print message if level >= dbglevel.
|
||||
* Example: clixon_debug_init(1) -> debug(1) is printed, but not debug(2).
|
||||
* Normally, debug messages are sent to clicon_log() which in turn can be sent to syslog and/or stderr.
|
||||
* But you can also override this with a specific debug file so that debug messages are written on the file
|
||||
* independently of log or errors. This is to ensure that a syslog of normal logs is unpolluted by extensive
|
||||
* debugging.
|
||||
*
|
||||
* @param[in] dbglevel 0 is show no debug messages, 1 is normal, 2.. is high debug.
|
||||
* Note this is _not_ level from syslog(3)
|
||||
* @param[in] f Debug-file. Open file where debug messages are directed.
|
||||
* If not NULL, it overrides the clicon_log settings which is otherwise
|
||||
* where debug messages are directed.
|
||||
* @see clicon_log_file where a filename can be given
|
||||
*/
|
||||
int
|
||||
clixon_debug_init(int dbglevel,
|
||||
FILE *f)
|
||||
{
|
||||
_clixon_debug = dbglevel; /* Global variable */
|
||||
|
||||
if (f != NULL){
|
||||
if (_logfile)
|
||||
fclose(_logfile);
|
||||
_logfile = f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
clixon_debug_get(void)
|
||||
{
|
||||
return _clixon_debug;
|
||||
}
|
||||
|
||||
/*! Print a debug message with debug-level. Settings determine where msg appears.
|
||||
*
|
||||
* If the dbglevel passed in the function is equal to or lower than the one set by
|
||||
* clixon_debug_init(level). That is, only print debug messages <= than what you want:
|
||||
* print message if level >= dbglevel.
|
||||
* The message is sent to clicon_log. EIther to syslog, stderr or both, depending on
|
||||
* clicon_log_init() setting
|
||||
* @param[in] dbglevel Mask of CLIXON_DBG_DEFAULT and other masks
|
||||
* @param[in] format Message to print as argv.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see clixon_debug_xml Specialization for XML tree
|
||||
* @see CLIXON_DBG_DEFAULT and other flags
|
||||
*/
|
||||
int
|
||||
clixon_debug(int dbglevel,
|
||||
const char *format, ...)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
size_t len;
|
||||
char *msg = NULL;
|
||||
size_t trunc;
|
||||
|
||||
/* Mask debug level with global dbg variable */
|
||||
if ((dbglevel & clixon_debug_get()) == 0)
|
||||
return 0;
|
||||
/* first round: compute length of debug message */
|
||||
va_start(args, format);
|
||||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
|
||||
/* Truncate long debug strings */
|
||||
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
|
||||
len = trunc;
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from format and args */
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
clicon_log_str(LOG_DEBUG, msg);
|
||||
retval = 0;
|
||||
done:
|
||||
if (msg)
|
||||
free(msg);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Translate month number (0..11) to a three letter month name
|
||||
*
|
||||
* @param[in] md month number, where 0 is january
|
||||
*/
|
||||
char *
|
||||
mon2name(int md)
|
||||
{
|
||||
switch(md){
|
||||
case 0: return "Jan";
|
||||
case 1: return "Feb";
|
||||
case 2: return "Mar";
|
||||
case 3: return "Apr";
|
||||
case 4: return "May";
|
||||
case 5: return "Jun";
|
||||
case 6: return "Jul";
|
||||
case 7: return "Aug";
|
||||
case 8: return "Sep";
|
||||
case 9: return "Oct";
|
||||
case 10: return "Nov";
|
||||
case 11: return "Dec";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,10 +56,11 @@
|
|||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_options.h"
|
||||
|
|
@ -345,7 +346,7 @@ prepvec_add(prepvec **pv_listp,
|
|||
prepvec *pv;
|
||||
|
||||
if ((pv = malloc(sizeof(*pv))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(pv, 0, sizeof(*pv));
|
||||
|
|
@ -368,7 +369,7 @@ prepvec_add(prepvec **pv_listp,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
nacm_datanode_prepare(clicon_handle h,
|
||||
nacm_datanode_prepare(clixon_handle h,
|
||||
cxobj *xt,
|
||||
enum nacm_access access,
|
||||
cxobj **gvec,
|
||||
|
|
@ -446,7 +447,7 @@ nacm_datanode_prepare(clicon_handle h,
|
|||
continue;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, EINVAL, "Access %d unupported (shouldnt happen)", access);
|
||||
clixon_err(OE_XML, EINVAL, "Access %d unupported (shouldnt happen)", access);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -464,7 +465,7 @@ nacm_datanode_prepare(clicon_handle h,
|
|||
path0 = clixon_trim2(xml_body(pathobj), " \t\n");
|
||||
/* Get canonical namespace context for nacm paths */
|
||||
if ((path = strdup(path0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
#if 0
|
||||
|
|
@ -608,7 +609,7 @@ nacm_data_write_xrule_xml(cxobj *xn,
|
|||
* deny: Send error message
|
||||
*/
|
||||
static int
|
||||
nacm_datanode_write_recurse(clicon_handle h,
|
||||
nacm_datanode_write_recurse(clixon_handle h,
|
||||
cxobj *xn,
|
||||
prepvec *pv_list,
|
||||
int defpermit,
|
||||
|
|
@ -685,7 +686,7 @@ nacm_datanode_write_recurse(clicon_handle h,
|
|||
* @see nacm_rpc
|
||||
*/
|
||||
int
|
||||
nacm_datanode_write(clicon_handle h,
|
||||
nacm_datanode_write(clixon_handle h,
|
||||
cxobj *xreq,
|
||||
cxobj *xt,
|
||||
enum nacm_access access,
|
||||
|
|
@ -711,7 +712,7 @@ nacm_datanode_write(clicon_handle h,
|
|||
goto permit;
|
||||
/* write-default (create, update, or delete) has default deny so should never be NULL */
|
||||
if ((write_default = xml_find_body(xnacm, "write-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No nacm write-default rule");
|
||||
clixon_err(OE_XML, EINVAL, "No nacm write-default rule");
|
||||
goto done;
|
||||
}
|
||||
/* 3. Check all the "group" entries to see if any of them contain a
|
||||
|
|
@ -891,7 +892,7 @@ nacm_data_read_xrule_xml(cxobj *xn,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
nacm_datanode_read_recurse(clicon_handle h,
|
||||
nacm_datanode_read_recurse(clixon_handle h,
|
||||
cxobj *xn,
|
||||
prepvec *pv_list,
|
||||
yang_stmt *yspec)
|
||||
|
|
@ -995,7 +996,7 @@ nacm_datanode_read_recurse(clicon_handle h,
|
|||
* @see nacm_rpc
|
||||
*/
|
||||
int
|
||||
nacm_datanode_read(clicon_handle h,
|
||||
nacm_datanode_read(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj **xrvec,
|
||||
size_t xrlen,
|
||||
|
|
@ -1035,7 +1036,7 @@ nacm_datanode_read(clicon_handle h,
|
|||
goto done;
|
||||
/* read-default has default permit so should never be NULL */
|
||||
if ((read_default = xml_find_body(xnacm, "read-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No nacm read-default rule");
|
||||
clixon_err(OE_XML, EINVAL, "No nacm read-default rule");
|
||||
goto done;
|
||||
}
|
||||
/* First run through rules and cache rules as well as lookup objects in xt.
|
||||
|
|
@ -1113,7 +1114,7 @@ nacm_datanode_read(clicon_handle h,
|
|||
* @see RFC8341 3.4 Access Control Enforcement Procedures
|
||||
*/
|
||||
static int
|
||||
nacm_access_check(clicon_handle h,
|
||||
nacm_access_check(clixon_handle h,
|
||||
cxobj *xnacm,
|
||||
char *peername,
|
||||
char *username)
|
||||
|
|
@ -1210,7 +1211,7 @@ nacm_access_check(clicon_handle h,
|
|||
* @see RFC8341 3.4 Access Control Enforcement Procedures
|
||||
*/
|
||||
int
|
||||
nacm_access_pre(clicon_handle h,
|
||||
nacm_access_pre(clixon_handle h,
|
||||
char *peername,
|
||||
char *username,
|
||||
cxobj **xnacmp)
|
||||
|
|
@ -1238,7 +1239,7 @@ nacm_access_pre(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_XML, 0, "Invalid NACM mode: %s", mode);
|
||||
clixon_err(OE_XML, 0, "Invalid NACM mode: %s", mode);
|
||||
goto done;
|
||||
}
|
||||
if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL)
|
||||
|
|
@ -1293,7 +1294,7 @@ nacm_access_pre(clicon_handle h,
|
|||
* - peer user is www (can be any NACM user)
|
||||
*/
|
||||
int
|
||||
verify_nacm_user(clicon_handle h,
|
||||
verify_nacm_user(clixon_handle h,
|
||||
enum nacm_credentials_t cred,
|
||||
char *peername,
|
||||
char *nacmname,
|
||||
|
|
@ -1328,7 +1329,7 @@ verify_nacm_user(clicon_handle h,
|
|||
}
|
||||
if (strcmp(peername, nacmname) != 0){
|
||||
if ((cbmsg = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbmsg, "User %s credential not matching NACM user %s", peername, nacmname);
|
||||
|
|
|
|||
|
|
@ -58,17 +58,18 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* clicon */
|
||||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* Local includes */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_io.h"
|
||||
#include "clixon_proto.h"
|
||||
|
|
@ -98,7 +99,7 @@ netconf_input_read2(int s,
|
|||
if (errno == ECONNRESET)
|
||||
len = 0; /* emulate EOF */
|
||||
else{
|
||||
clicon_log(LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno));
|
||||
clixon_log(NULL, LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno));
|
||||
goto done;
|
||||
}
|
||||
} /* read */
|
||||
|
|
@ -219,7 +220,7 @@ netconf_input_frame2(cbuf *cb,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
|
||||
if (xrecv == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "xrecv is NULL");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "xrecv is NULL");
|
||||
goto done;
|
||||
}
|
||||
str = cbuf_get(cb);
|
||||
|
|
@ -232,7 +233,7 @@ netconf_input_frame2(cbuf *cb,
|
|||
/* Fix to distinguish RPC and REPLIES */
|
||||
if ((ret = clixon_xml_parse_string(str, yb, yspec, &xtop, xerr)) < 0){
|
||||
/* XXX possibly should quit on -1? */
|
||||
if (netconf_operation_failed_xml(xerr, "rpc", clicon_err_reason)< 0)
|
||||
if (netconf_operation_failed_xml(xerr, "rpc", clixon_err_reason())< 0)
|
||||
goto done;
|
||||
goto failed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,11 @@
|
|||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_data.h"
|
||||
|
|
@ -146,7 +147,7 @@ netconf_in_use(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +170,7 @@ netconf_invalid_value_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -268,7 +269,7 @@ netconf_too_big(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +294,7 @@ netconf_missing_attribute_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -409,7 +410,7 @@ netconf_bad_attribute_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -481,7 +482,7 @@ netconf_unknown_attribute(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -508,7 +509,7 @@ netconf_common_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -780,7 +781,7 @@ netconf_access_denied_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -850,7 +851,7 @@ netconf_lock_denied(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -891,7 +892,7 @@ netconf_resource_denied(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -933,7 +934,7 @@ netconf_rollback_failed(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -974,7 +975,7 @@ netconf_data_exists(cbuf *cb,
|
|||
free(encstr);
|
||||
return retval;
|
||||
err:
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -1025,7 +1026,7 @@ netconf_data_missing_xml(cxobj **xret,
|
|||
cxobj *xerr;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1084,7 +1085,7 @@ netconf_missing_choice_xml(cxobj **xret,
|
|||
char *encpath = NULL;
|
||||
|
||||
if (xret == NULL || name == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret or name is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret or name is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1158,7 +1159,7 @@ netconf_operation_not_supported_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1276,7 +1277,7 @@ netconf_operation_failed_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1365,7 +1366,7 @@ netconf_malformed_message_xml(cxobj **xret,
|
|||
char *encstr = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1451,7 +1452,7 @@ netconf_data_not_unique_xml(cxobj **xret,
|
|||
char *encpath = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1522,7 +1523,7 @@ netconf_minmax_elements_xml(cxobj **xret,
|
|||
char *encpath = NULL;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1578,7 +1579,7 @@ netconf_trymerge(cxobj *x,
|
|||
cxobj *xc;
|
||||
|
||||
if (xret == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "xret is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (*xret == NULL){
|
||||
|
|
@ -1621,13 +1622,13 @@ netconf_trymerge(cxobj *x,
|
|||
* @see netconf_module_load that is called later
|
||||
*/
|
||||
int
|
||||
netconf_module_features(clicon_handle h)
|
||||
netconf_module_features(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xc;
|
||||
|
||||
if ((xc = clicon_conf_xml(h)) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "Clicon configuration not loaded");
|
||||
clixon_err(OE_CFG, ENOENT, "Clicon configuration not loaded");
|
||||
goto done;
|
||||
}
|
||||
/* Enable features (hardcoded here) */
|
||||
|
|
@ -1653,7 +1654,7 @@ netconf_module_features(clicon_handle h)
|
|||
* @see netconf_module_feature should be called before any yang modules
|
||||
*/
|
||||
int
|
||||
netconf_module_load(clicon_handle h)
|
||||
netconf_module_load(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -1747,61 +1748,6 @@ netconf_db_find(cxobj *xn,
|
|||
return db;
|
||||
}
|
||||
|
||||
/*! Generate netconf error msg to cbuf using callback to use in string printout or logs
|
||||
*
|
||||
* If no callback is registered, a default error message is genereated
|
||||
* @param[in] xerr Netconf error message on the level: <rpc-error>
|
||||
* @param[out] cberr Translation from netconf err to cbuf.
|
||||
* @retval 0 OK, with cberr set
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
* cbuf *cb = NULL;
|
||||
* if ((cb = cbuf_new()) ==NULL){
|
||||
* err;
|
||||
* if (netconf_err2cb(h, xerr, cb) < 0)
|
||||
* err;
|
||||
* printf("%s", cbuf_get(cb));
|
||||
* cbuf_free(cb);
|
||||
* @endcode
|
||||
* @see clixon_netconf_error_fn
|
||||
*/
|
||||
int
|
||||
netconf_err2cb(clicon_handle h,
|
||||
cxobj *xerr,
|
||||
cbuf *cberr)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *x;
|
||||
size_t len;
|
||||
|
||||
// XXX: some calls are <rpc-reply><rpc-error>, change calls instead
|
||||
if (strcmp(xml_name(xerr), "rpc-error") != 0)
|
||||
xerr = xml_child_i_type(xerr, 0, CX_ELMNT);
|
||||
len = cbuf_len(cberr);
|
||||
if (clixon_plugin_netconf_errmsg_all(h, xerr, cberr) < 0)
|
||||
goto done;
|
||||
if (cbuf_len(cberr) == len){ /* Same as on-entry, use default */
|
||||
if ((x = xml_find_type(xerr, NULL, "error-type", CX_ELMNT)) != NULL)
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x = xml_find_type(xerr, NULL, "error-tag", CX_ELMNT)) != NULL)
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x = xml_find_type(xerr, NULL, "error-message", CX_ELMNT)) != NULL)
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x = xml_find_type(xerr, NULL, "error-info", CX_ELMNT)) != NULL &&
|
||||
xml_child_nr(x) > 0){
|
||||
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if ((x = xml_find_type(xerr, NULL, "error-app-tag", CX_ELMNT)) != NULL)
|
||||
cprintf(cberr, ": %s ", xml_body(x));
|
||||
if ((x = xml_find_type(xerr, NULL, "error-path", CX_ELMNT)) != NULL)
|
||||
cprintf(cberr, ": %s ", xml_body(x));
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* See RFC 8040 4.8.1
|
||||
* @see netconf_content_str2int
|
||||
*/
|
||||
|
|
@ -1848,7 +1794,7 @@ netconf_content_int2str(netconf_content nr)
|
|||
* urn:ietf:params:netconf:capability:notification:1.0 (RFC5277)
|
||||
*/
|
||||
int
|
||||
netconf_capabilites(clicon_handle h,
|
||||
netconf_capabilites(clixon_handle h,
|
||||
cbuf *cb)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1942,7 +1888,7 @@ netconf_capabilites(clicon_handle h,
|
|||
* @see netconf_module_load
|
||||
*/
|
||||
int
|
||||
netconf_hello_server(clicon_handle h,
|
||||
netconf_hello_server(clixon_handle h,
|
||||
cbuf *cb,
|
||||
uint32_t session_id)
|
||||
{
|
||||
|
|
@ -1959,56 +1905,6 @@ netconf_hello_server(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Generate and print textual error log from Netconf error message
|
||||
*
|
||||
* Get a text error message from netconf error message and generate error on the form:
|
||||
* <msg>: "<arg>": <netconf-error> or <msg>: <netconf-error>
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] fn Inline function name (when called from clicon_err() macro)
|
||||
* @param[in] line Inline file line number (when called from clicon_err() macro)
|
||||
* @param[in] xerr Netconf error xml tree on the form: <rpc-error>
|
||||
* @param[in] format Format string
|
||||
* @param[in] arg String argument to format (optional)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see netconf_err2cb
|
||||
* ßee clixon_netconf_error macro
|
||||
*/
|
||||
int
|
||||
clixon_netconf_error_fn(clicon_handle h,
|
||||
const char *fn,
|
||||
const int line,
|
||||
cxobj *xerr,
|
||||
const char *msg,
|
||||
const char *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (msg){
|
||||
cprintf(cb, "%s", msg);
|
||||
if (arg)
|
||||
cprintf(cb, " \"%s\" ", arg);
|
||||
|
||||
cprintf(cb, ": ");
|
||||
}
|
||||
if (netconf_err2cb(h, xerr, cb) < 0)
|
||||
goto done;
|
||||
#if 0 /* More verbose output for debugging */
|
||||
clicon_log(LOG_ERR, "%s: %d: %s", fn, line, cbuf_get(cb));
|
||||
#else
|
||||
clicon_log(LOG_ERR, "%s", cbuf_get(cb));
|
||||
#endif
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Add internal error info to existing netconf error message by rewriting
|
||||
*
|
||||
|
|
@ -2087,14 +1983,14 @@ netconf_parse_uint32(char *name,
|
|||
char *reason = NULL;
|
||||
|
||||
if (valstr == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "valstr is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "valstr is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (defaultstr && strcmp(valstr, defaultstr) == 0)
|
||||
*value = defaultvalue;
|
||||
else {
|
||||
if ((ret = parse_uint32(valstr, value, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint32");
|
||||
clixon_err(OE_XML, errno, "parse_uint32");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
|
|
@ -2131,14 +2027,14 @@ netconf_parse_uint32_xml(char *name,
|
|||
char *reason = NULL;
|
||||
|
||||
if (valstr == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "valstr is NULL");
|
||||
clixon_err(OE_NETCONF, EINVAL, "valstr is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (defaultstr && strcmp(valstr, defaultstr) == 0)
|
||||
*value = defaultvalue;
|
||||
else {
|
||||
if ((ret = parse_uint32(valstr, value, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint32");
|
||||
clixon_err(OE_XML, errno, "parse_uint32");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
|
|
@ -2164,7 +2060,7 @@ netconf_parse_uint32_xml(char *name,
|
|||
* @retval msgid Next message id
|
||||
*/
|
||||
int
|
||||
netconf_message_id_next(clicon_handle h)
|
||||
netconf_message_id_next(clixon_handle h)
|
||||
{
|
||||
int msgid;
|
||||
|
||||
|
|
@ -2200,7 +2096,7 @@ netconf_framing_preamble(netconf_framing_type framing,
|
|||
break;
|
||||
case NETCONF_SSH_CHUNKED:
|
||||
if ((body = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
cbuf_reset(cb);
|
||||
|
|
@ -2269,7 +2165,7 @@ netconf_output(int s,
|
|||
if (errno == EPIPE)
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s write err SIGPIPE", __FUNCTION__);
|
||||
else
|
||||
clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno));
|
||||
clixon_log(NULL, LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno));
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -2356,7 +2252,7 @@ netconf_input_chunked_framing(char ch,
|
|||
(*state)++;
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected \\n but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected \\n but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
case 1:
|
||||
|
|
@ -2365,7 +2261,7 @@ netconf_input_chunked_framing(char ch,
|
|||
(*state)++;
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
case 2:
|
||||
|
|
@ -2379,7 +2275,7 @@ netconf_input_chunked_framing(char ch,
|
|||
*size = ch-'0';
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected 1-9 or # but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected 1-9 or # but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
case 3:
|
||||
|
|
@ -2391,7 +2287,7 @@ netconf_input_chunked_framing(char ch,
|
|||
(*state)++;
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-size: expected 0-9 or \\n but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-size: expected 0-9 or \\n but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
case 4:
|
||||
|
|
@ -2404,7 +2300,7 @@ netconf_input_chunked_framing(char ch,
|
|||
(*state)++;
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
case 6:
|
||||
|
|
@ -2417,7 +2313,7 @@ netconf_input_chunked_framing(char ch,
|
|||
*size = ch-'0';
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
case 7:
|
||||
|
|
@ -2426,11 +2322,11 @@ netconf_input_chunked_framing(char ch,
|
|||
retval = 2; /* end of frame */
|
||||
break;
|
||||
}
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_NETCONF, 0, "NETCONF framing error %c , invalid state:%d", ch, *state);
|
||||
clixon_err(OE_NETCONF, 0, "NETCONF framing error %c , invalid state:%d", ch, *state);
|
||||
goto err;
|
||||
break;
|
||||
}
|
||||
|
|
@ -2442,3 +2338,125 @@ netconf_input_chunked_framing(char ch,
|
|||
goto done;
|
||||
}
|
||||
|
||||
/*! Generate netconf error msg to cbuf using callback to use in string printout or logs
|
||||
*
|
||||
* If no callback is registered, a default error message is genereated
|
||||
* @param[in] xerr Netconf error message on the level: <rpc-error>
|
||||
* @param[out] cberr Translation from netconf err to cbuf.
|
||||
* @retval 0 OK, with cberr set
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
* cbuf *cb = NULL;
|
||||
* if ((cb = cbuf_new()) ==NULL){
|
||||
* err;
|
||||
* if (netconf_err2cb(h, xerr, cb) < 0)
|
||||
* err;
|
||||
* printf("%s", cbuf_get(cb));
|
||||
* cbuf_free(cb);
|
||||
* @endcode
|
||||
* @see clixon_netconf_error_fn
|
||||
*/
|
||||
int
|
||||
netconf_err2cb(clixon_handle h,
|
||||
cxobj *xerr,
|
||||
cbuf *cberr)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *x;
|
||||
size_t len;
|
||||
|
||||
// XXX: some calls are <rpc-reply><rpc-error>, change calls instead
|
||||
if (strcmp(xml_name(xerr), "rpc-error") != 0)
|
||||
xerr = xml_child_i_type(xerr, 0, CX_ELMNT);
|
||||
len = cbuf_len(cberr);
|
||||
if (clixon_plugin_netconf_errmsg_all(h, xerr, cberr) < 0)
|
||||
goto done;
|
||||
if (cbuf_len(cberr) == len){ /* Same as on-entry, use default */
|
||||
if ((x=xpath_first(xerr, NULL, "//error-type"))!=NULL)
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, NULL, "//error-tag"))!=NULL)
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, NULL, "//error-message"))!=NULL)
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, NULL, "//error-info")) != NULL &&
|
||||
xml_child_nr(x) > 0){
|
||||
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if ((x=xpath_first(xerr, NULL, "//error-app-tag"))!=NULL)
|
||||
cprintf(cberr, ": %s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, NULL, "//error-path"))!=NULL)
|
||||
cprintf(cberr, ": %s ", xml_body(x));
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Generate and print textual error log from Netconf error message
|
||||
*
|
||||
* Get a text error message from netconf error message and generate error logmsg:
|
||||
* <msg>: "<arg>": <netconf-error> or <msg>: <netconf-error>
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] fn Inline function name (when called from clixon_err() macro)
|
||||
* @param[in] line Inline file line number (when called from clixon_err() macro)
|
||||
* @param[in] xerr Netconf error xml tree on the form: <rpc-error>
|
||||
* @param[in] format Format string
|
||||
* @param[in] arg String argument to format (optional)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see netconf_err2cb
|
||||
* @see clixon_netconf_error macro
|
||||
*/
|
||||
int
|
||||
clixon_err_netconf_fn(clixon_handle h,
|
||||
const char *fn,
|
||||
const int line,
|
||||
int category,
|
||||
int suberr,
|
||||
cxobj *xerr,
|
||||
const char *format, ...)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
int len;
|
||||
char *msg = NULL;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
/* first round: compute length of error message */
|
||||
va_start(args, format);
|
||||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from format and args */
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s: ", msg);
|
||||
/* Translate netconf error to string */
|
||||
if (netconf_err2cb(h, xerr, cb) < 0)
|
||||
goto done;
|
||||
if (clixon_err_args(h, fn, line, category, suberr, cbuf_get(cb)) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (msg)
|
||||
free(msg);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,24 +51,25 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_yang_module.h"
|
||||
#include "clixon_xml_io.h"
|
||||
#include "clixon_netconf_lib.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_data.h"
|
||||
#include "clixon_datastore.h"
|
||||
#include "clixon_netconf_monitoring.h"
|
||||
|
||||
static int
|
||||
per_datastore(clicon_handle h,
|
||||
per_datastore(clixon_handle h,
|
||||
cbuf *cb,
|
||||
const char *db)
|
||||
{
|
||||
|
|
@ -84,7 +85,7 @@ per_datastore(clicon_handle h,
|
|||
cprintf(cb, "<locked-by-session>%u</locked-by-session>", sid);
|
||||
xmldb_lock_timestamp(h, db, &tv);
|
||||
if (time2str(&tv, timestr, sizeof(timestr)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "time2str");
|
||||
clixon_err(OE_UNIX, errno, "time2str");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<locked-time>%s</locked-time>", timestr);
|
||||
|
|
@ -107,7 +108,7 @@ per_datastore(clicon_handle h,
|
|||
* @see RFC 6022 Section 2.1.2
|
||||
*/
|
||||
static int
|
||||
netconf_monitoring_datastores(clicon_handle h,
|
||||
netconf_monitoring_datastores(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
cbuf *cb)
|
||||
{
|
||||
|
|
@ -138,7 +139,7 @@ netconf_monitoring_datastores(clicon_handle h,
|
|||
* @see RFC 6022 Section 2.1.3
|
||||
*/
|
||||
static int
|
||||
netconf_monitoring_schemas(clicon_handle h,
|
||||
netconf_monitoring_schemas(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
cbuf *cb)
|
||||
{
|
||||
|
|
@ -189,7 +190,7 @@ netconf_monitoring_schemas(clicon_handle h,
|
|||
* @see RFC 6022 Section 2.1.5
|
||||
*/
|
||||
static int
|
||||
netconf_monitoring_statistics(clicon_handle h,
|
||||
netconf_monitoring_statistics(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
cbuf *cb)
|
||||
{
|
||||
|
|
@ -243,7 +244,7 @@ netconf_monitoring_statistics(clicon_handle h,
|
|||
* @see RFC 6022
|
||||
*/
|
||||
int
|
||||
netconf_monitoring_state_get(clicon_handle h,
|
||||
netconf_monitoring_state_get(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
char *xpath,
|
||||
cvec *nsc,
|
||||
|
|
@ -255,7 +256,7 @@ netconf_monitoring_state_get(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<netconf-state xmlns=\"%s\">", NETCONF_MONITORING_NAMESPACE);
|
||||
|
|
@ -300,7 +301,7 @@ stat_counter_add(cvec *cvv,
|
|||
cg_var *cv;
|
||||
|
||||
if ((cv = cvec_add(cvv, CGV_UINT32)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add");
|
||||
goto done;
|
||||
}
|
||||
cv_name_set(cv, name);
|
||||
|
|
@ -317,7 +318,7 @@ stat_counter_add(cvec *cvv,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
netconf_monitoring_statistics_init(clicon_handle h)
|
||||
netconf_monitoring_statistics_init(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
struct timeval tv;
|
||||
|
|
@ -329,7 +330,7 @@ netconf_monitoring_statistics_init(clicon_handle h)
|
|||
goto done;
|
||||
clicon_data_set(h, "netconf-start-time", timestr); /* RFC 6022 */
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_data_cvec_set(h, "netconf-statistics", cvv) < 0)
|
||||
|
|
@ -360,7 +361,7 @@ netconf_monitoring_statistics_init(clicon_handle h)
|
|||
* @retval 0 OK
|
||||
*/
|
||||
int
|
||||
netconf_monitoring_counter_inc(clicon_handle h,
|
||||
netconf_monitoring_counter_inc(clixon_handle h,
|
||||
char *name)
|
||||
{
|
||||
cvec *cvv = NULL;
|
||||
|
|
|
|||
|
|
@ -41,8 +41,12 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_netns.h"
|
||||
|
||||
#ifdef HAVE_SETNS
|
||||
|
|
@ -70,7 +74,7 @@ send_sock(int usock,
|
|||
memcpy(fdptr,&fd,sizeof(fd));
|
||||
msg.msg_controllen=CMSG_SPACE(sizeof(fd));
|
||||
if (sendmsg(usock, &msg, 0) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sendmsg");
|
||||
clixon_err(OE_UNIX, errno, "sendmsg");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -96,7 +100,7 @@ get_sock(int usock,
|
|||
msg.msg_controllen=sizeof(buf);
|
||||
/* Block here */
|
||||
if (recvmsg(usock, &msg, 0) < 0){
|
||||
clicon_err(OE_UNIX, errno, "recvmsg");
|
||||
clixon_err(OE_UNIX, errno, "recvmsg");
|
||||
goto done;
|
||||
}
|
||||
cmsg=CMSG_FIRSTHDR(&msg);
|
||||
|
|
@ -133,7 +137,7 @@ create_socket(struct sockaddr *sa,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (sock == NULL){
|
||||
clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
|
||||
clixon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
|
||||
goto done;
|
||||
}
|
||||
/* create inet socket */
|
||||
|
|
@ -146,39 +150,39 @@ create_socket(struct sockaddr *sa,
|
|||
|
||||
if ((s = socket(sa->sa_family, flags,
|
||||
0)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "socket");
|
||||
clixon_err(OE_UNIX, errno, "socket");
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (fcntl(s, O_CLOEXEC)) {
|
||||
clicon_err(OE_UNIX, errno, "fcntl");
|
||||
clixon_err(OE_UNIX, errno, "fcntl");
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE");
|
||||
clixon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE");
|
||||
goto done;
|
||||
}
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
|
||||
clixon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */
|
||||
if (sa->sa_family == AF_INET6 &&
|
||||
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6");
|
||||
clixon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6");
|
||||
goto done;
|
||||
}
|
||||
if (bind(s, sa, sin_len) == -1) {
|
||||
/* Note may be ignored in upper layer by checking for EADDRNOTAVAIL, see eg restconf_openssl_init */
|
||||
clicon_err(OE_UNIX, errno, "bind(%s)", addrstr);
|
||||
clixon_err(OE_UNIX, errno, "bind(%s)", addrstr);
|
||||
goto done;
|
||||
}
|
||||
if (listen(s, backlog ) < 0){
|
||||
clicon_err(OE_UNIX, errno, "listen");
|
||||
clixon_err(OE_UNIX, errno, "listen");
|
||||
goto done;
|
||||
}
|
||||
if (sock)
|
||||
|
|
@ -228,18 +232,18 @@ fork_netns_socket(const char *netns,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, netns);
|
||||
if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){
|
||||
clicon_err(OE_UNIX, errno, "socketpair");
|
||||
clixon_err(OE_UNIX, errno, "socketpair");
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (fcntl(sp[0], O_CLOEXEC)) {
|
||||
clicon_err(OE_UNIX, errno, "fcntl, sp[0]");
|
||||
clixon_err(OE_UNIX, errno, "fcntl, sp[0]");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fcntl(sp[1], O_CLOEXEC)) {
|
||||
clicon_err(OE_UNIX, errno, "fcntl, sp[1]");
|
||||
clixon_err(OE_UNIX, errno, "fcntl, sp[1]");
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -247,11 +251,11 @@ fork_netns_socket(const char *netns,
|
|||
/* Check namespace exists */
|
||||
sprintf(nspath,"/var/run/netns/%s", netns);
|
||||
if (stat(nspath, &st) < 0){
|
||||
clicon_err(OE_UNIX, errno, ": stat(%s)", nspath);
|
||||
clixon_err(OE_UNIX, errno, ": stat(%s)", nspath);
|
||||
goto done;
|
||||
}
|
||||
if ((child = fork()) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "fork");
|
||||
clixon_err(OE_UNIX, errno, "fork");
|
||||
goto done;
|
||||
}
|
||||
if (child == 0) { /* Child */
|
||||
|
|
@ -261,13 +265,13 @@ fork_netns_socket(const char *netns,
|
|||
close(sp[0]);
|
||||
/* Switch to namespace */
|
||||
if ((fd=open(nspath, O_RDONLY)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", nspath);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", nspath);
|
||||
send_sock(sp[1], sp[1]); /* Dummy to wake parent */
|
||||
exit(1); /* Dont do return here, need to exit child */
|
||||
}
|
||||
#ifdef HAVE_SETNS
|
||||
if (setns(fd, CLONE_NEWNET) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setns(%s)", netns);
|
||||
clixon_err(OE_UNIX, errno, "setns(%s)", netns);
|
||||
send_sock(sp[1], sp[1]); /* Dummy to wake parent */
|
||||
exit(1); /* Dont do return here, need to exit child */
|
||||
}
|
||||
|
|
@ -295,7 +299,7 @@ fork_netns_socket(const char *netns,
|
|||
if (WEXITSTATUS(wstatus)){
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus));
|
||||
*sock = -1;
|
||||
clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
|
||||
clixon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -339,7 +343,7 @@ clixon_netns_socket(const char *netns,
|
|||
if (fork_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, sock) < 0)
|
||||
goto done;
|
||||
#else
|
||||
clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);
|
||||
clixon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,13 +62,15 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_sort.h"
|
||||
|
|
@ -144,7 +146,7 @@ static const map_str2int yang_regexp_map[] = {
|
|||
* @see cli_show_options
|
||||
*/
|
||||
int
|
||||
clicon_option_dump(clicon_handle h,
|
||||
clicon_option_dump(clixon_handle h,
|
||||
int dbglevel)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -208,7 +210,7 @@ clicon_option_dump(clicon_handle h,
|
|||
* @see clicon_option_dump for debug log
|
||||
*/
|
||||
int
|
||||
clicon_option_dump1(clicon_handle h,
|
||||
clicon_option_dump1(clixon_handle h,
|
||||
FILE *f,
|
||||
int format,
|
||||
int pretty)
|
||||
|
|
@ -231,7 +233,7 @@ clicon_option_dump1(clicon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, EINVAL, "%s not supported", format_int2str(format));
|
||||
clixon_err(OE_XML, EINVAL, "%s not supported", format_int2str(format));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -250,7 +252,7 @@ clicon_option_dump1(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
parse_configfile_one(clicon_handle h,
|
||||
parse_configfile_one(clixon_handle h,
|
||||
const char *filename,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xconfig)
|
||||
|
|
@ -260,30 +262,22 @@ parse_configfile_one(clicon_handle h,
|
|||
cxobj *xt = NULL;
|
||||
cxobj *xerr = NULL;
|
||||
cxobj *xa;
|
||||
cbuf *cbret = NULL;
|
||||
int ret;
|
||||
|
||||
if ((fp = fopen(filename, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "open configure file: %s", filename);
|
||||
clixon_err(OE_UNIX, errno, "open configure file: %s", filename);
|
||||
return -1;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s: Reading config file %s", __FUNCTION__, filename);
|
||||
if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(h, xerr, cbret) < 0)
|
||||
goto done;
|
||||
/* Here one could make it more relaxing to not quit on unrecognized option? */
|
||||
clixon_netconf_error(h, xerr, NULL, NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Config file: %s", filename);
|
||||
goto done;
|
||||
}
|
||||
/* Ensure a single root */
|
||||
if (xt == NULL || xml_child_nr(xt) != 1){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename);
|
||||
clixon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename);
|
||||
goto done;
|
||||
}
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
|
|
@ -292,7 +286,7 @@ parse_configfile_one(clicon_handle h,
|
|||
if (strcmp(xml_name(xt), "clixon-config") != 0 ||
|
||||
(xa = xml_find_type(xt, NULL, "xmlns", CX_ATTR)) == NULL ||
|
||||
strcmp(xml_value(xa), CLIXON_CONF_NS) != 0){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: <clixon-config xmlns=\"%s\">", filename, CLIXON_CONF_NS);
|
||||
clixon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: <clixon-config xmlns=\"%s\">", filename, CLIXON_CONF_NS);
|
||||
goto done;
|
||||
}
|
||||
*xconfig = xt;
|
||||
|
|
@ -304,8 +298,6 @@ parse_configfile_one(clicon_handle h,
|
|||
xml_free(xt);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (cbret)
|
||||
cbuf_free(cbret);
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
return retval;
|
||||
|
|
@ -314,7 +306,7 @@ parse_configfile_one(clicon_handle h,
|
|||
/*! Merge XML sub config file into main config-file
|
||||
*/
|
||||
static int
|
||||
merge_control_xml(clicon_handle h,
|
||||
merge_control_xml(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xe)
|
||||
{
|
||||
|
|
@ -384,7 +376,7 @@ merge_control_xml(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
parse_configfile(clicon_handle h,
|
||||
parse_configfile(clixon_handle h,
|
||||
const char *filename,
|
||||
char *extraconfdir0,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -412,15 +404,15 @@ parse_configfile(clicon_handle h,
|
|||
DIR *dirp;
|
||||
|
||||
if (filename == NULL || !strlen(filename)){
|
||||
clicon_err(OE_UNIX, 0, "Not specified");
|
||||
clixon_err(OE_UNIX, 0, "Not specified");
|
||||
goto done;
|
||||
}
|
||||
if (stat(filename, &st) < 0){
|
||||
clicon_err(OE_UNIX, errno, "%s", filename);
|
||||
clixon_err(OE_UNIX, errno, "%s", filename);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(st.st_mode)){
|
||||
clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
|
||||
clixon_err(OE_UNIX, 0, "%s is not a regular file", filename);
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -437,7 +429,7 @@ parse_configfile(clicon_handle h,
|
|||
if (extraconfdir){ /* If extra dir, parse extra config files */
|
||||
/* A check it exists (also done in clicon_file_dirent) */
|
||||
if ((dirp = opendir(extraconfdir)) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir);
|
||||
clixon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir);
|
||||
goto done;
|
||||
}
|
||||
closedir(dirp);
|
||||
|
|
@ -461,7 +453,7 @@ parse_configfile(clicon_handle h,
|
|||
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
|
||||
if ((y = xml_spec(x)) != NULL){
|
||||
if ((yang_find(y, Y_STATUS, "obsolete")) != NULL){
|
||||
clicon_err(OE_CFG, 0, "Clixon option %s is obsolete but given in the config file which is considered an error",
|
||||
clixon_err(OE_CFG, 0, "Clixon option %s is obsolete but given in the config file which is considered an error",
|
||||
xml_name(x));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -473,12 +465,10 @@ parse_configfile(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0){
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(h, xerr, cbret) < 0)
|
||||
goto done;
|
||||
clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret));
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Config file validation");
|
||||
goto done;
|
||||
}
|
||||
/* Add top-level hash options.
|
||||
|
|
@ -540,7 +530,7 @@ parse_configfile(clicon_handle h,
|
|||
* @see clicon_options_main For loading options from file
|
||||
*/
|
||||
int
|
||||
clicon_option_add(clicon_handle h,
|
||||
clicon_option_add(clixon_handle h,
|
||||
const char *name,
|
||||
char *value)
|
||||
{
|
||||
|
|
@ -550,7 +540,7 @@ clicon_option_add(clicon_handle h,
|
|||
cxobj *xopt;
|
||||
|
||||
if ((xconfig = clicon_conf_xml(h)) == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
|
||||
clixon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
|
||||
goto done;
|
||||
}
|
||||
if (strcmp(name, "CLICON_FEATURE")==0 ||
|
||||
|
|
@ -594,7 +584,7 @@ clicon_option_add(clicon_handle h,
|
|||
* other yang modules.
|
||||
*/
|
||||
int
|
||||
clicon_options_main(clicon_handle h)
|
||||
clicon_options_main(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
char *configfile;
|
||||
|
|
@ -625,13 +615,13 @@ clicon_options_main(clicon_handle h)
|
|||
xml = strcmp(suffix, "xml") == 0;
|
||||
}
|
||||
if (xml == 0){
|
||||
clicon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix);
|
||||
clixon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix);
|
||||
goto done;
|
||||
}
|
||||
/* Override extraconfdir */
|
||||
if (clicon_option_str(h, "CLICON_CONFIGDIR") &&
|
||||
(extraconfdir = strdup(clicon_option_str(h, "CLICON_CONFIGDIR"))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -673,7 +663,7 @@ clicon_options_main(clicon_handle h)
|
|||
if (parse_configfile(h, configfile, extraconfdir, yspec, &xconfig) < 0)
|
||||
goto done;
|
||||
if (xml_spec(xconfig) == NULL){
|
||||
clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: <clixon-config xmlns=\"%s\"> or clixon-config.yang not found?", configfile, CLIXON_CONF_NS);
|
||||
clixon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: <clixon-config xmlns=\"%s\"> or clixon-config.yang not found?", configfile, CLIXON_CONF_NS);
|
||||
goto done;
|
||||
}
|
||||
/* Set yang config spec (must store to free at exit, since conf_xml below uses it) */
|
||||
|
|
@ -696,13 +686,13 @@ clicon_options_main(clicon_handle h)
|
|||
|
||||
/*! Check if a clicon option has a value
|
||||
*
|
||||
* @param[in] h clicon_handle
|
||||
* @param[in] h clixon_handle
|
||||
* @param[in] name option name
|
||||
* @retval !=0 option exists
|
||||
* @retval 0 option does not exist
|
||||
*/
|
||||
int
|
||||
clicon_option_exists(clicon_handle h,
|
||||
clicon_option_exists(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
|
@ -712,7 +702,7 @@ clicon_option_exists(clicon_handle h,
|
|||
|
||||
/*! Get a single string option string via handle
|
||||
*
|
||||
* @param[in] h clicon_handle
|
||||
* @param[in] h clixon_handle
|
||||
* @param[in] name option name
|
||||
* @retval string value of option if found
|
||||
* @retval NULL If option not found, or value of option is NULL
|
||||
|
|
@ -721,7 +711,7 @@ clicon_option_exists(clicon_handle h,
|
|||
* clicon_option_exists() before the call
|
||||
*/
|
||||
char *
|
||||
clicon_option_str(clicon_handle h,
|
||||
clicon_option_str(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
|
@ -733,14 +723,14 @@ clicon_option_str(clicon_handle h,
|
|||
|
||||
/*! Set a single string option via handle
|
||||
*
|
||||
* @param[in] h clicon_handle
|
||||
* @param[in] h clixon_handle
|
||||
* @param[in] name option name
|
||||
* @param[in] val option value, must be null-terminated string
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_option_str_set(clicon_handle h,
|
||||
clicon_option_str_set(clixon_handle h,
|
||||
const char *name,
|
||||
char *val)
|
||||
{
|
||||
|
|
@ -767,7 +757,7 @@ clicon_option_str_set(clicon_handle h,
|
|||
* @see clicon_data_int_get for transient values (not clixon config file)
|
||||
*/
|
||||
int
|
||||
clicon_option_int(clicon_handle h,
|
||||
clicon_option_int(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
char *s;
|
||||
|
|
@ -784,7 +774,7 @@ clicon_option_int(clicon_handle h,
|
|||
* @param[in] val Integer value
|
||||
*/
|
||||
int
|
||||
clicon_option_int_set(clicon_handle h,
|
||||
clicon_option_int_set(clixon_handle h,
|
||||
const char *name,
|
||||
int val)
|
||||
{
|
||||
|
|
@ -812,7 +802,7 @@ clicon_option_int_set(clicon_handle h,
|
|||
* supply a default value as shown in the example.
|
||||
*/
|
||||
int
|
||||
clicon_option_bool(clicon_handle h,
|
||||
clicon_option_bool(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
char *s;
|
||||
|
|
@ -833,18 +823,18 @@ clicon_option_bool(clicon_handle h,
|
|||
* @param[in] val Boolean value, 0 or 1
|
||||
*/
|
||||
int
|
||||
clicon_option_bool_set(clicon_handle h,
|
||||
clicon_option_bool_set(clixon_handle h,
|
||||
const char *name,
|
||||
int val)
|
||||
{
|
||||
char s[64];
|
||||
|
||||
if (val != 0 && val != 1){
|
||||
clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
|
||||
clixon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
|
||||
return -1;
|
||||
}
|
||||
if (snprintf(s, sizeof(s)-1, "%s", val?"true":"false") < 0){
|
||||
clicon_err(OE_CFG, errno, "snprintf");
|
||||
clixon_err(OE_CFG, errno, "snprintf");
|
||||
return -1;
|
||||
}
|
||||
return clicon_option_str_set(h, name, s);
|
||||
|
|
@ -856,7 +846,7 @@ clicon_option_bool_set(clicon_handle h,
|
|||
* @param[in] name Name of option to delete
|
||||
*/
|
||||
int
|
||||
clicon_option_del(clicon_handle h,
|
||||
clicon_option_del(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clicon_hash_t *copt = clicon_options(h);
|
||||
|
|
@ -882,7 +872,7 @@ clicon_option_del(clicon_handle h,
|
|||
* @see clixon-config@<date>.yang CLICON_CLI_VARONLY
|
||||
*/
|
||||
int
|
||||
clicon_cli_varonly(clicon_handle h)
|
||||
clicon_cli_varonly(clixon_handle h)
|
||||
{
|
||||
char const *opt = "CLICON_CLI_VARONLY";
|
||||
|
||||
|
|
@ -899,7 +889,7 @@ clicon_cli_varonly(clicon_handle h)
|
|||
* @retval fam Socket family
|
||||
*/
|
||||
int
|
||||
clicon_sock_family(clicon_handle h)
|
||||
clicon_sock_family(clixon_handle h)
|
||||
{
|
||||
char *s;
|
||||
|
||||
|
|
@ -922,7 +912,7 @@ clicon_sock_family(clicon_handle h)
|
|||
* @see clixon-config@<date>.yang CLICON_SOCK_PORT
|
||||
*/
|
||||
int
|
||||
clicon_sock_port(clicon_handle h)
|
||||
clicon_sock_port(clixon_handle h)
|
||||
{
|
||||
char *s;
|
||||
|
||||
|
|
@ -937,7 +927,7 @@ clicon_sock_port(clicon_handle h)
|
|||
* @retval flag Autocommit (or not)
|
||||
*/
|
||||
int
|
||||
clicon_autocommit(clicon_handle h)
|
||||
clicon_autocommit(clixon_handle h)
|
||||
{
|
||||
char const *opt = "CLICON_AUTOCOMMIT";
|
||||
|
||||
|
|
@ -953,7 +943,7 @@ clicon_autocommit(clicon_handle h)
|
|||
* @retval mode Startup mode
|
||||
*/
|
||||
int
|
||||
clicon_startup_mode(clicon_handle h)
|
||||
clicon_startup_mode(clixon_handle h)
|
||||
{
|
||||
char *mode;
|
||||
|
||||
|
|
@ -968,7 +958,7 @@ clicon_startup_mode(clicon_handle h)
|
|||
* @retval mode Privileges mode
|
||||
*/
|
||||
enum priv_mode_t
|
||||
clicon_backend_privileges_mode(clicon_handle h)
|
||||
clicon_backend_privileges_mode(clixon_handle h)
|
||||
{
|
||||
char *mode;
|
||||
|
||||
|
|
@ -983,7 +973,7 @@ clicon_backend_privileges_mode(clicon_handle h)
|
|||
* @retval mode Privileges mode
|
||||
*/
|
||||
enum priv_mode_t
|
||||
clicon_restconf_privileges_mode(clicon_handle h)
|
||||
clicon_restconf_privileges_mode(clixon_handle h)
|
||||
{
|
||||
char *mode;
|
||||
|
||||
|
|
@ -998,7 +988,7 @@ clicon_restconf_privileges_mode(clicon_handle h)
|
|||
* @retval mode Privileges mode
|
||||
*/
|
||||
enum nacm_credentials_t
|
||||
clicon_nacm_credentials(clicon_handle h)
|
||||
clicon_nacm_credentials(clixon_handle h)
|
||||
{
|
||||
char *mode;
|
||||
|
||||
|
|
@ -1014,7 +1004,7 @@ clicon_nacm_credentials(clicon_handle h)
|
|||
* @see clixon-config@<date>.yang CLICON_DATASTORE_CACHE
|
||||
*/
|
||||
enum datastore_cache
|
||||
clicon_datastore_cache(clicon_handle h)
|
||||
clicon_datastore_cache(clixon_handle h)
|
||||
{
|
||||
char *str;
|
||||
|
||||
|
|
@ -1031,7 +1021,7 @@ clicon_datastore_cache(clicon_handle h)
|
|||
* @see clixon-config@<date>.yang CLICON_YANG_REGEXP
|
||||
*/
|
||||
enum regexp_mode
|
||||
clicon_yang_regexp(clicon_handle h)
|
||||
clicon_yang_regexp(clixon_handle h)
|
||||
{
|
||||
char *str;
|
||||
|
||||
|
|
@ -1053,7 +1043,7 @@ clicon_yang_regexp(clicon_handle h)
|
|||
* @retval flag quiet mode on or off
|
||||
*/
|
||||
int
|
||||
clicon_quiet_mode(clicon_handle h)
|
||||
clicon_quiet_mode(clixon_handle h)
|
||||
{
|
||||
char *s;
|
||||
if ((s = clicon_option_str(h, "CLICON_QUIET")) == NULL)
|
||||
|
|
@ -1067,7 +1057,7 @@ clicon_quiet_mode(clicon_handle h)
|
|||
* @param[in] val Flag value
|
||||
*/
|
||||
int
|
||||
clicon_quiet_mode_set(clicon_handle h,
|
||||
clicon_quiet_mode_set(clixon_handle h,
|
||||
int val)
|
||||
{
|
||||
return clicon_option_int_set(h, "CLICON_QUIET", val);
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@
|
|||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -140,9 +141,9 @@ api_path_parse(char *api_path,
|
|||
if (api_path_parse_init(&ay) < 0)
|
||||
goto done;
|
||||
if (clixon_api_path_parseparse(&ay) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "API-PATH error: on line %d", ay.ay_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_XML, 0, "API-PATH parser error with no error code (should not happen)");
|
||||
clixon_log(NULL, LOG_NOTICE, "API-PATH error: on line %d", ay.ay_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_XML, 0, "API-PATH parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
api_path_parse_exit(&ay);
|
||||
|
|
@ -185,9 +186,9 @@ instance_id_parse(char *path,
|
|||
if (instance_id_parse_init(&iy) < 0)
|
||||
goto done;
|
||||
if (clixon_instance_id_parseparse(&iy) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "Instance-id error: on line %d", iy.iy_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_XML, 0, "Instance-id parser error with no error code (should not happen)");
|
||||
clixon_log(NULL, LOG_NOTICE, "Instance-id error: on line %d", iy.iy_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_XML, 0, "Instance-id parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
instance_id_parse_exit(&iy);
|
||||
|
|
@ -309,7 +310,7 @@ yang2api_path_fmt_1(yang_stmt *ys,
|
|||
enum rfc_6020 ypkeyw = -1;
|
||||
|
||||
if ((yp = yang_parent_get(ys)) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
|
||||
clixon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys));
|
||||
goto done;
|
||||
}
|
||||
if (yp)
|
||||
|
|
@ -409,13 +410,13 @@ yang2api_path_fmt(yang_stmt *ys,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (yang2api_path_fmt_1(ys, inclkey, cb) < 0)
|
||||
goto done;
|
||||
if ((*api_path_fmt = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -476,7 +477,7 @@ api_path_fmt2api_path(const char *api_path_fmt,
|
|||
size_t len;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
j = 1; /* j==0 is cli string */
|
||||
|
|
@ -491,11 +492,11 @@ api_path_fmt2api_path(const char *api_path_fmt,
|
|||
;
|
||||
else{
|
||||
if ((cv = cvec_i(cvv, j++)) == NULL){
|
||||
clicon_err(OE_XML, 0, "Number of elements in cvv does not match api_path_fmt string");
|
||||
clixon_err(OE_XML, 0, "Number of elements in cvv does not match api_path_fmt string");
|
||||
goto done;
|
||||
}
|
||||
if ((str = cv2str_dup(cv)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
goto done;
|
||||
}
|
||||
if (uri_percent_encode(&strenc, "%s", str) < 0)
|
||||
|
|
@ -516,7 +517,7 @@ api_path_fmt2api_path(const char *api_path_fmt,
|
|||
}
|
||||
}
|
||||
if ((*api_path = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if (cvv_i) /* Last entry in cvv used */
|
||||
|
|
@ -570,7 +571,7 @@ api_path_fmt2xpath(char *api_path_fmt,
|
|||
size_t len;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
j = 1; /* j==0 is cli string */
|
||||
|
|
@ -586,7 +587,7 @@ api_path_fmt2xpath(char *api_path_fmt,
|
|||
else{
|
||||
cv = cvec_i(cvv, j++);
|
||||
if ((str = cv2str_dup(cv)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "[%s='%s']", cv_name_get(cv), str);
|
||||
|
|
@ -604,7 +605,7 @@ api_path_fmt2xpath(char *api_path_fmt,
|
|||
}
|
||||
}
|
||||
if ((*xpath = strdup4(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -624,7 +625,7 @@ api_path_fmt2xpath(char *api_path_fmt,
|
|||
* @param[out] xerr Netconf error message
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid api_path or associated XML, netconf error xml set
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error
|
||||
*
|
||||
* @code
|
||||
* cbuf *xpath = cbuf_new();
|
||||
|
|
@ -645,7 +646,7 @@ api_path_fmt2xpath(char *api_path_fmt,
|
|||
* ["www.foo.com" "restconf" "a" "b=c"]
|
||||
* which means the api-path is ["a" "b=c"] corresponding to "a/b=c"
|
||||
* @note "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3
|
||||
* @note retval -1 sets clicon_err, retval 0 sets netconf xml msg
|
||||
* @note retval -1 sets clixon_err, retval 0 sets netconf xml msg
|
||||
* @note Not proper namespace translation from api-path 2 xpath!!!
|
||||
* @see api_path2xml For api-path to xml tree
|
||||
* @see api_path2xpath Using strings as parameters
|
||||
|
|
@ -687,7 +688,7 @@ api_path2xpath_cvv(cvec *api_path,
|
|||
if ((nsc = xml_nsctx_init(NULL, NULL)) == NULL)
|
||||
goto done;
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
root = 1; /* root or mountpoint */
|
||||
|
|
@ -865,7 +866,7 @@ api_path2xpath_cvv(cvec *api_path,
|
|||
* @param[out] xerr Netconf error message
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid api_path or associated XML, netconf called
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error
|
||||
* @code
|
||||
* char *xpath = NULL;
|
||||
* cvec *nsc = NULL;
|
||||
|
|
@ -892,7 +893,7 @@ api_path2xpath(char *api_path,
|
|||
int ret;
|
||||
|
||||
if (api_path == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "api_path is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "api_path is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* Special case: "//" is not handled proerly by uri_str2cvec
|
||||
|
|
@ -916,7 +917,7 @@ api_path2xpath(char *api_path,
|
|||
/* prepare output xpath parameter */
|
||||
if (xpathp)
|
||||
if ((*xpathp = strdup(cbuf_get(xpath))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 1;
|
||||
|
|
@ -944,9 +945,9 @@ api_path2xpath(char *api_path,
|
|||
* @param[out] xerr Netconf error message (if retval=0)
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid api_path or associated XML, netconf error
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error
|
||||
*
|
||||
* @note both retval -1 set clicon_err, retval 0 set xerr netconf xml
|
||||
* @note both retval -1 set clixon_err, retval 0 set xerr netconf xml
|
||||
* @see api_path2xpath For api-path to xml xpath translation
|
||||
* @see api_path2xml
|
||||
*/
|
||||
|
|
@ -994,7 +995,7 @@ api_path2xml_vec(char **vec,
|
|||
goto ok;
|
||||
} /* E.g "x=1,2" -> nodeid:x restval=1,2 */
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* restval is RFC 3896 encoded */
|
||||
|
|
@ -1046,7 +1047,7 @@ api_path2xml_vec(char **vec,
|
|||
case Y_LEAF_LIST:
|
||||
#if 0
|
||||
if (restval==NULL){
|
||||
clicon_err(OE_XML, 0, "malformed key, expected '=restval'");
|
||||
clixon_err(OE_XML, 0, "malformed key, expected '=restval'");
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1162,7 +1163,7 @@ api_path2xml_vec(char **vec,
|
|||
if (xml2xpath(x, nsc, 0, 1, &xpath) < 0) // XXX should be canonical
|
||||
goto done;
|
||||
if (xpath == NULL){
|
||||
clicon_err(OE_YANG, 0, "No xpath from xml");
|
||||
clixon_err(OE_YANG, 0, "No xpath from xml");
|
||||
goto done;
|
||||
}
|
||||
/* cf xml_bind_yang0_opt/xml_yang_mount_get */
|
||||
|
|
@ -1214,8 +1215,8 @@ api_path2xml_vec(char **vec,
|
|||
* @param[out] xerr Netconf error message (if retval=0)
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid api_path or associated XML, netconf error
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @note both retval -1 set clicon_err, retval 0 set xerr netconf xml
|
||||
* @retval -1 Fatal error
|
||||
* @note both retval -1 set clixon_err, retval 0 set xerr netconf xml
|
||||
* @example
|
||||
* api_path: /subif-entry=foo/subid
|
||||
* xtop[in] <config/>
|
||||
|
|
@ -1250,7 +1251,7 @@ api_path2xml(char *api_path,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s api_path:%s", __FUNCTION__, api_path);
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (*api_path != '/'){
|
||||
|
|
@ -1413,16 +1414,16 @@ api_path_resolve(clixon_path *cplist,
|
|||
do {
|
||||
if (yang_keyword_get(yt) == Y_SPEC){
|
||||
if (cp->cp_prefix == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Modulename not defined for top-level id.");
|
||||
clixon_err(OE_YANG, ENOENT, "Modulename not defined for top-level id.");
|
||||
goto fail;
|
||||
}
|
||||
if ((yt = yang_find_module_by_name(yt, cp->cp_prefix)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Modulename in api-path does not correspond to existing module");
|
||||
clixon_err(OE_YANG, ENOENT, "Modulename in api-path does not correspond to existing module");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Corresponding yang node for id not found");
|
||||
clixon_err(OE_YANG, ENOENT, "Corresponding yang node for id not found");
|
||||
goto fail;
|
||||
}
|
||||
cp->cp_yang = yc;
|
||||
|
|
@ -1438,14 +1439,14 @@ api_path_resolve(clixon_path *cplist,
|
|||
else if (yang_keyword_get(yc) == Y_LIST){
|
||||
cvk = yang_cvec_get(yc);
|
||||
if (cvec_len(cp->cp_cvk) > cvec_len(cvk)){
|
||||
clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list");
|
||||
clixon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list");
|
||||
goto fail;
|
||||
}
|
||||
i = 0;
|
||||
cva = NULL;
|
||||
while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
|
||||
if (cv_name_get(cva) != NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Unexpected named key %s (shouldnt happen)",
|
||||
clixon_err(OE_YANG, ENOENT, "Unexpected named key %s (shouldnt happen)",
|
||||
cv_name_get(cva));
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -1454,7 +1455,7 @@ api_path_resolve(clixon_path *cplist,
|
|||
}
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
|
||||
clixon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
|
@ -1507,12 +1508,12 @@ instance_id_resolve(clixon_path *cplist,
|
|||
if ((cp = cplist) != NULL){
|
||||
do {
|
||||
if (cp->cp_prefix == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No prefix of identifier (keynames may omit prefix)");
|
||||
clixon_err(OE_YANG, ENOENT, "No prefix of identifier (keynames may omit prefix)");
|
||||
goto fail;
|
||||
}
|
||||
if (yang_keyword_get(yt) == Y_SPEC){
|
||||
if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
|
||||
clixon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
|
@ -1521,13 +1522,13 @@ instance_id_resolve(clixon_path *cplist,
|
|||
if (ret == 1){
|
||||
if (yang_mount_get_yspec_any(yt, &yspec) == 1){
|
||||
if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
|
||||
clixon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node",
|
||||
clixon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node",
|
||||
cp->cp_id);
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -1536,14 +1537,14 @@ instance_id_resolve(clixon_path *cplist,
|
|||
case Y_LIST:
|
||||
if (cp->cp_cvk == NULL){
|
||||
#if 0 /* see key-value presence in lists note above */
|
||||
clicon_err(OE_YANG, ENOENT, "key-values mandatory for lists");
|
||||
clixon_err(OE_YANG, ENOENT, "key-values mandatory for lists");
|
||||
goto fail;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if 0 /* see key-value presence in lists note above */
|
||||
if (cvec_len(cp->cp_cvk) > cvec_len(yang_cvec_get(yc))){
|
||||
clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list ");
|
||||
clixon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list ");
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1551,7 +1552,7 @@ instance_id_resolve(clixon_path *cplist,
|
|||
while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) {
|
||||
if ((kname = cv_name_get(cva)) != NULL){ /* Check var exists */
|
||||
if (yang_find(yc, 0, kname) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Index variable %s used in path is not child of Yang node %s",
|
||||
clixon_err(OE_YANG, ENOENT, "Index variable %s used in path is not child of Yang node %s",
|
||||
kname, yang_argument_get(yc));
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -1564,7 +1565,7 @@ instance_id_resolve(clixon_path *cplist,
|
|||
break;
|
||||
default:
|
||||
if (cp->cp_cvk != NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
|
||||
clixon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list");
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1705,13 +1706,13 @@ clixon_xml_find_api_path(cxobj *xt,
|
|||
va_end(ap);
|
||||
/* allocate an api-path string exactly fitting the length */
|
||||
if ((api_path = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: actually compute api-path string content */
|
||||
va_start(ap, format);
|
||||
if (vsnprintf(api_path, len+1, format, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1799,13 +1800,13 @@ clixon_xml_find_instance_id(cxobj *xt,
|
|||
va_end(ap);
|
||||
/* allocate a path string exactly fitting the length */
|
||||
if ((path = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: actually compute api-path string content */
|
||||
va_start(ap, format);
|
||||
if (vsnprintf(path, len+1, format, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1887,13 +1888,13 @@ clixon_instance_id_bind(yang_stmt *yt,
|
|||
va_end(ap);
|
||||
/* allocate a path string exactly fitting the length */
|
||||
if ((path = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: actually compute api-path string content */
|
||||
va_start(ap, format);
|
||||
if (vsnprintf(path, len+1, format, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1963,13 +1964,13 @@ clixon_instance_id_parse(yang_stmt *yt,
|
|||
va_end(ap);
|
||||
/* allocate a path string exactly fitting the length */
|
||||
if ((path = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: actually compute api-path string content */
|
||||
va_start(ap, format);
|
||||
if (vsnprintf(path, len+1, format, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1982,7 +1983,7 @@ clixon_instance_id_parse(yang_stmt *yt,
|
|||
if ((ret = instance_id_resolve(cplist, yt)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (xerr && netconf_invalid_value_xml(xerr, "application", clicon_err_reason) < 0)
|
||||
if (xerr && netconf_invalid_value_xml(xerr, "application", clixon_err_reason()) < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,13 +55,15 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -126,7 +128,7 @@ typedef struct plugin_module_struct plugin_module_struct;
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
static plugin_module_struct *
|
||||
plugin_module_struct_get(clicon_handle h)
|
||||
plugin_module_struct_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
size_t len;
|
||||
|
|
@ -145,7 +147,7 @@ plugin_module_struct_get(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
plugin_module_struct_set(clicon_handle h,
|
||||
plugin_module_struct_set(clixon_handle h,
|
||||
plugin_module_struct *ms)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -206,7 +208,7 @@ clixon_plugin_handle_get(clixon_plugin_t *cp)
|
|||
* @note Not optimized, always iterates from the start of the list
|
||||
*/
|
||||
clixon_plugin_t *
|
||||
clixon_plugin_each(clicon_handle h,
|
||||
clixon_plugin_each(clixon_handle h,
|
||||
clixon_plugin_t *cpprev)
|
||||
{
|
||||
clixon_plugin_t *cpnext = NULL;
|
||||
|
|
@ -242,7 +244,7 @@ clixon_plugin_each(clicon_handle h,
|
|||
* @note Not optimized, always iterates from the start of the list
|
||||
*/
|
||||
clixon_plugin_t *
|
||||
clixon_plugin_each_revert(clicon_handle h,
|
||||
clixon_plugin_each_revert(clixon_handle h,
|
||||
clixon_plugin_t *cpprev,
|
||||
int nr)
|
||||
{
|
||||
|
|
@ -251,7 +253,7 @@ clixon_plugin_each_revert(clicon_handle h,
|
|||
int i;
|
||||
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
return NULL;
|
||||
}
|
||||
if (ms->ms_plugin_list == NULL)
|
||||
|
|
@ -287,14 +289,14 @@ clixon_plugin_each_revert(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
clixon_plugin_t *
|
||||
clixon_plugin_find(clicon_handle h,
|
||||
clixon_plugin_find(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
clixon_plugin_t *cp = NULL;
|
||||
plugin_module_struct *ms = plugin_module_struct_get(h);
|
||||
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
return NULL;
|
||||
}
|
||||
if ((cp = ms->ms_plugin_list) != NULL){
|
||||
|
|
@ -320,7 +322,7 @@ clixon_plugin_find(clicon_handle h,
|
|||
* @see clixon_plugins_load Load all plugins
|
||||
*/
|
||||
static int
|
||||
plugin_load_one(clicon_handle h,
|
||||
plugin_load_one(clixon_handle h,
|
||||
char *file, /* note modified */
|
||||
const char *function,
|
||||
int dlflags,
|
||||
|
|
@ -340,30 +342,30 @@ plugin_load_one(clicon_handle h,
|
|||
dlerror(); /* Clear any existing error */
|
||||
if ((handle = dlopen(file, dlflags)) == NULL) {
|
||||
error = (char*)dlerror();
|
||||
clicon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error");
|
||||
clixon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error");
|
||||
goto done;
|
||||
}
|
||||
/* call plugin_init() if defined, eg CLIXON_PLUGIN_INIT or CLIXON_BACKEND_INIT */
|
||||
if ((initfn = dlsym(handle, function)) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "Failed to find %s when loading clixon plugin %s", CLIXON_PLUGIN_INIT, file);
|
||||
clixon_err(OE_PLUGIN, errno, "Failed to find %s when loading clixon plugin %s", CLIXON_PLUGIN_INIT, file);
|
||||
goto done;
|
||||
}
|
||||
if ((error = (char*)dlerror()) != NULL) {
|
||||
clicon_err(OE_UNIX, 0, "dlsym: %s: %s", file, error);
|
||||
clixon_err(OE_UNIX, 0, "dlsym: %s: %s", file, error);
|
||||
goto done;
|
||||
}
|
||||
clicon_err_reset();
|
||||
clixon_err_reset();
|
||||
wh = NULL;
|
||||
if (plugin_context_check(h, &wh, file, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if ((api = initfn(h)) == NULL) {
|
||||
if (!clicon_errno){ /* if clicon_err() is not called then log and continue */
|
||||
clicon_log(LOG_DEBUG, "Warning: failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
|
||||
if (!clixon_err_category()){ /* if clixon_err() is not called then log and continue */
|
||||
clixon_log(h, LOG_DEBUG, "Warning: failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_PLUGIN, errno, "Failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
|
||||
clixon_err(OE_PLUGIN, errno, "Failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -372,7 +374,7 @@ plugin_load_one(clicon_handle h,
|
|||
|
||||
/* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */
|
||||
if ((cp = (clixon_plugin_t *)malloc(sizeof(struct clixon_plugin))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(cp, 0, sizeof(struct clixon_plugin));
|
||||
|
|
@ -411,7 +413,7 @@ plugin_load_one(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_plugins_load(clicon_handle h,
|
||||
clixon_plugins_load(clixon_handle h,
|
||||
const char *function,
|
||||
const char *dir,
|
||||
const char *regexp)
|
||||
|
|
@ -428,7 +430,7 @@ clixon_plugins_load(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
goto done;
|
||||
}
|
||||
/* Get plugin objects names from plugin directory */
|
||||
|
|
@ -471,7 +473,7 @@ done:
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
clixon_pseudo_plugin(clicon_handle h,
|
||||
clixon_pseudo_plugin(clixon_handle h,
|
||||
const char *name,
|
||||
clixon_plugin_t **cpp)
|
||||
{
|
||||
|
|
@ -481,13 +483,13 @@ clixon_pseudo_plugin(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name);
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
goto done;
|
||||
}
|
||||
/* Create a pseudo plugins */
|
||||
/* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */
|
||||
if ((cp = (clixon_plugin_t *)malloc(sizeof(struct clixon_plugin))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(cp, 0, sizeof(struct clixon_plugin));
|
||||
|
|
@ -516,17 +518,17 @@ plugin_context_get(void)
|
|||
struct plugin_context *pc = NULL;
|
||||
|
||||
if ((pc = malloc(sizeof(*pc))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(pc, 0, sizeof(*pc));
|
||||
if (sigprocmask(0, NULL, &pc->pc_sigset) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigprocmask");
|
||||
clixon_err(OE_UNIX, errno, "sigprocmask");
|
||||
goto done;
|
||||
}
|
||||
for (i=1; i<32; i++){
|
||||
if (sigaction(i, NULL, &pc->pc_sigaction_vec[i]) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigaction");
|
||||
clixon_err(OE_UNIX, errno, "sigaction");
|
||||
goto done;
|
||||
}
|
||||
/* Mask SA_RESTORER: Not intended for application use.
|
||||
|
|
@ -539,7 +541,7 @@ plugin_context_get(void)
|
|||
#endif
|
||||
}
|
||||
if (isatty(0) && tcgetattr(0, &pc->pc_termios) < 0){
|
||||
clicon_err(OE_UNIX, errno, "tcgetattr %d", errno);
|
||||
clixon_err(OE_UNIX, errno, "tcgetattr %d", errno);
|
||||
goto done;
|
||||
}
|
||||
return pc;
|
||||
|
|
@ -573,7 +575,7 @@ plugin_context_get(void)
|
|||
* @see CLICON_PLUGIN_CALLBACK_CHECK Enable to activate these checks
|
||||
*/
|
||||
int
|
||||
plugin_context_check(clicon_handle h,
|
||||
plugin_context_check(clixon_handle h,
|
||||
void **wh,
|
||||
const char *name,
|
||||
const char *fn)
|
||||
|
|
@ -605,28 +607,28 @@ plugin_context_check(clicon_handle h,
|
|||
if ((newpc = plugin_context_get()) == NULL)
|
||||
goto done;
|
||||
if (oldpc->pc_termios.c_iflag != newpc->pc_termios.c_iflag){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios input modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios input modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
name, fn,
|
||||
oldpc->pc_termios.c_iflag,
|
||||
newpc->pc_termios.c_iflag);
|
||||
failed++;
|
||||
}
|
||||
if (oldpc->pc_termios.c_oflag != newpc->pc_termios.c_oflag){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios output modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios output modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
name, fn,
|
||||
oldpc->pc_termios.c_oflag,
|
||||
newpc->pc_termios.c_oflag);
|
||||
failed++;
|
||||
}
|
||||
if (oldpc->pc_termios.c_cflag != newpc->pc_termios.c_cflag){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios control modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios control modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
name, fn,
|
||||
oldpc->pc_termios.c_cflag,
|
||||
newpc->pc_termios.c_cflag);
|
||||
failed++;
|
||||
}
|
||||
if (oldpc->pc_termios.c_lflag != newpc->pc_termios.c_lflag){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios local modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios local modes from 0x%x to 0x%x", __FUNCTION__,
|
||||
name, fn,
|
||||
oldpc->pc_termios.c_lflag,
|
||||
newpc->pc_termios.c_lflag);
|
||||
|
|
@ -639,7 +641,7 @@ plugin_context_check(clicon_handle h,
|
|||
abort();
|
||||
for (i=1; i<32; i++){
|
||||
if (sigismember(&oldpc->pc_sigset, i) != sigismember(&newpc->pc_sigset, i)){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__,
|
||||
name, fn, strsignal(i), i,
|
||||
sigismember(&oldpc->pc_sigset, i),
|
||||
sigismember(&newpc->pc_sigset, i)
|
||||
|
|
@ -647,14 +649,14 @@ plugin_context_check(clicon_handle h,
|
|||
failed++;
|
||||
}
|
||||
if (oldpc->pc_sigaction_vec[i].sa_flags != newpc->pc_sigaction_vec[i].sa_flags){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__,
|
||||
name, fn, strsignal(i), i,
|
||||
oldpc->pc_sigaction_vec[i].sa_flags,
|
||||
newpc->pc_sigaction_vec[i].sa_flags);;
|
||||
failed++;
|
||||
}
|
||||
if (oldpc->pc_sigaction_vec[i].sa_sigaction != newpc->pc_sigaction_vec[i].sa_sigaction){
|
||||
clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__,
|
||||
clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__,
|
||||
name, fn, strsignal(i), i,
|
||||
oldpc->pc_sigaction_vec[i].sa_sigaction,
|
||||
newpc->pc_sigaction_vec[i].sa_sigaction);
|
||||
|
|
@ -690,7 +692,7 @@ plugin_context_check(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_start_one(clixon_plugin_t *cp,
|
||||
clicon_handle h)
|
||||
clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
plgstart_t *fn; /* Plugin start */
|
||||
|
|
@ -701,8 +703,8 @@ clixon_plugin_start_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Start callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Start callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -723,7 +725,7 @@ clixon_plugin_start_one(clixon_plugin_t *cp,
|
|||
* @note Start functions can use clicon_argv_get() to get -- command line options
|
||||
*/
|
||||
int
|
||||
clixon_plugin_start_all(clicon_handle h)
|
||||
clixon_plugin_start_all(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
clixon_plugin_t *cp = NULL;
|
||||
|
|
@ -747,7 +749,7 @@ clixon_plugin_start_all(clicon_handle h)
|
|||
*/
|
||||
static int
|
||||
clixon_plugin_exit_one(clixon_plugin_t *cp,
|
||||
clicon_handle h)
|
||||
clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
char *error;
|
||||
|
|
@ -759,8 +761,8 @@ clixon_plugin_exit_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Exit callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Exit callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -768,7 +770,7 @@ clixon_plugin_exit_one(clixon_plugin_t *cp,
|
|||
goto done;
|
||||
if (dlclose(cp->cp_handle) != 0) {
|
||||
error = (char*)dlerror();
|
||||
clicon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error");
|
||||
clixon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error");
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -783,7 +785,7 @@ clixon_plugin_exit_one(clixon_plugin_t *cp,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
clixon_plugin_exit_all(clicon_handle h)
|
||||
clixon_plugin_exit_all(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
clixon_plugin_t *cp = NULL;
|
||||
|
|
@ -819,7 +821,7 @@ clixon_plugin_exit_all(clicon_handle h)
|
|||
*/
|
||||
static int
|
||||
clixon_plugin_auth_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
void *req,
|
||||
clixon_auth_type_t auth_type,
|
||||
char **authp)
|
||||
|
|
@ -834,8 +836,8 @@ clixon_plugin_auth_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if ((retval = fn(h, req, auth_type, authp)) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Auth callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Auth callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -865,7 +867,7 @@ clixon_plugin_auth_one(clixon_plugin_t *cp,
|
|||
* @note If authp returns string, it should be malloced
|
||||
*/
|
||||
int
|
||||
clixon_plugin_auth_all(clicon_handle h,
|
||||
clixon_plugin_auth_all(clixon_handle h,
|
||||
void *req,
|
||||
clixon_auth_type_t auth_type,
|
||||
char **authp)
|
||||
|
|
@ -876,7 +878,7 @@ clixon_plugin_auth_all(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;
|
||||
}
|
||||
*authp = NULL;
|
||||
|
|
@ -906,7 +908,7 @@ clixon_plugin_auth_all(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_extension_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
yang_stmt *yext,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
|
|
@ -919,8 +921,8 @@ clixon_plugin_extension_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h, yext, ys) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Extension callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Extension callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -946,7 +948,7 @@ clixon_plugin_extension_one(clixon_plugin_t *cp,
|
|||
* @retval -1 Error in one callback
|
||||
*/
|
||||
int
|
||||
clixon_plugin_extension_all(clicon_handle h,
|
||||
clixon_plugin_extension_all(clixon_handle h,
|
||||
yang_stmt *yext,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
|
|
@ -975,7 +977,7 @@ clixon_plugin_extension_all(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
const char *db,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msd)
|
||||
|
|
@ -990,8 +992,8 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h, db, xt, msd) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Datastore upgrade callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Datastore upgrade callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1014,7 +1016,7 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp,
|
|||
* Upgrade datastore on load before or as an alternative to module-specific upgrading mechanism
|
||||
*/
|
||||
int
|
||||
clixon_plugin_datastore_upgrade_all(clicon_handle h,
|
||||
clixon_plugin_datastore_upgrade_all(clixon_handle h,
|
||||
const char *db,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msd)
|
||||
|
|
@ -1046,7 +1048,7 @@ clixon_plugin_datastore_upgrade_all(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_yang_mount_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
cxobj *xt,
|
||||
int *config,
|
||||
validate_level *vl,
|
||||
|
|
@ -1061,8 +1063,8 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h, xt, config, vl, yanglib) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Yang mount callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Yang mount callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1085,7 +1087,7 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_plugin_yang_mount_all(clicon_handle h,
|
||||
clixon_plugin_yang_mount_all(clixon_handle h,
|
||||
cxobj *xt,
|
||||
int *config,
|
||||
validate_level *vl,
|
||||
|
|
@ -1116,7 +1118,7 @@ clixon_plugin_yang_mount_all(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_yang_patch_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
yang_stmt *ymod)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1128,8 +1130,8 @@ clixon_plugin_yang_patch_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h, ymod) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Yang patch callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Yang patch callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1149,7 +1151,7 @@ clixon_plugin_yang_patch_one(clixon_plugin_t *cp,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_plugin_yang_patch_all(clicon_handle h,
|
||||
clixon_plugin_yang_patch_all(clixon_handle h,
|
||||
yang_stmt *ymod)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1175,7 +1177,7 @@ clixon_plugin_yang_patch_all(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
cxobj *xerr,
|
||||
cbuf *cberr)
|
||||
{
|
||||
|
|
@ -1188,8 +1190,8 @@ clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h, xerr, cberr) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: Netconf err callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: Netconf err callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1210,7 +1212,7 @@ clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_plugin_netconf_errmsg_all(clicon_handle h,
|
||||
clixon_plugin_netconf_errmsg_all(clixon_handle h,
|
||||
cxobj *xerr,
|
||||
cbuf *cberr)
|
||||
{
|
||||
|
|
@ -1236,7 +1238,7 @@ clixon_plugin_netconf_errmsg_all(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clixon_plugin_version_one(clixon_plugin_t *cp,
|
||||
clicon_handle h,
|
||||
clixon_handle h,
|
||||
FILE *f)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1248,8 +1250,8 @@ clixon_plugin_version_one(clixon_plugin_t *cp,
|
|||
if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0)
|
||||
goto done;
|
||||
if (fn(h, f) < 0) {
|
||||
if (clicon_errno < 0)
|
||||
clicon_log(LOG_WARNING, "%s: Internal error: version callback in plugin: %s returned -1 but did not make a clicon_err call",
|
||||
if (clixon_err_category() < 0)
|
||||
clixon_log(h, LOG_WARNING, "%s: Internal error: version callback in plugin: %s returned -1 but did not make a clixon_err call",
|
||||
__FUNCTION__, cp->cp_name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1269,7 +1271,7 @@ clixon_plugin_version_one(clixon_plugin_t *cp,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_plugin_version_all(clicon_handle h,
|
||||
clixon_plugin_version_all(clixon_handle h,
|
||||
FILE *f)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1290,7 +1292,7 @@ clixon_plugin_version_all(clicon_handle h,
|
|||
|
||||
#if 0 /* Debugging */
|
||||
static int
|
||||
rpc_callback_dump(clicon_handle h)
|
||||
rpc_callback_dump(clixon_handle h)
|
||||
{
|
||||
rpc_callback_t *rc;
|
||||
plugin_module_struct *ms = plugin_module_struct_get(h);
|
||||
|
|
@ -1317,7 +1319,7 @@ rpc_callback_dump(clicon_handle h)
|
|||
* @see rpc_callback_call which makes the actual callback
|
||||
*/
|
||||
int
|
||||
rpc_callback_register(clicon_handle h,
|
||||
rpc_callback_register(clixon_handle h,
|
||||
clicon_rpc_cb cb,
|
||||
void *arg,
|
||||
const char *ns,
|
||||
|
|
@ -1328,15 +1330,15 @@ rpc_callback_register(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name);
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
goto done;
|
||||
}
|
||||
if (name == NULL || ns == NULL){
|
||||
clicon_err(OE_DB, EINVAL, "name or namespace NULL");
|
||||
clixon_err(OE_DB, EINVAL, "name or namespace NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) {
|
||||
clicon_err(OE_DB, errno, "malloc");
|
||||
clixon_err(OE_DB, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(rc, 0, sizeof(*rc));
|
||||
|
|
@ -1360,7 +1362,7 @@ rpc_callback_register(clicon_handle h,
|
|||
/*! Delete all RPC callbacks
|
||||
*/
|
||||
static int
|
||||
rpc_callback_delete_all(clicon_handle h)
|
||||
rpc_callback_delete_all(clixon_handle h)
|
||||
{
|
||||
rpc_callback_t *rc;
|
||||
plugin_module_struct *ms = plugin_module_struct_get(h);
|
||||
|
|
@ -1393,7 +1395,7 @@ rpc_callback_delete_all(clicon_handle h)
|
|||
* leaving it, replacing it or amending it.
|
||||
*/
|
||||
int
|
||||
rpc_callback_call(clicon_handle h,
|
||||
rpc_callback_call(clixon_handle h,
|
||||
cxobj *xe,
|
||||
void *arg,
|
||||
int *nrp,
|
||||
|
|
@ -1410,7 +1412,7 @@ rpc_callback_call(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
goto done;
|
||||
}
|
||||
name = xml_name(xe);
|
||||
|
|
@ -1470,7 +1472,7 @@ rpc_callback_call(clicon_handle h,
|
|||
* @see rpc_callback_register which registers global callbacks
|
||||
*/
|
||||
int
|
||||
action_callback_register(clicon_handle h,
|
||||
action_callback_register(clixon_handle h,
|
||||
yang_stmt *ya,
|
||||
clicon_rpc_cb cb,
|
||||
void *arg)
|
||||
|
|
@ -1481,12 +1483,12 @@ action_callback_register(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (ya == NULL){
|
||||
clicon_err(OE_DB, EINVAL, "yang node is NULL");
|
||||
clixon_err(OE_DB, EINVAL, "yang node is NULL");
|
||||
goto done;
|
||||
}
|
||||
name = yang_argument_get(ya);
|
||||
if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) {
|
||||
clicon_err(OE_DB, errno, "malloc");
|
||||
clixon_err(OE_DB, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(rc, 0, sizeof(*rc));
|
||||
|
|
@ -1517,7 +1519,7 @@ action_callback_register(clicon_handle h,
|
|||
* leaving it, replacing it or amending it.
|
||||
*/
|
||||
int
|
||||
action_callback_call(clicon_handle h,
|
||||
action_callback_call(clixon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
|
|
@ -1594,7 +1596,7 @@ action_callback_call(clicon_handle h,
|
|||
* @see upgrade_callback_call which makes the actual callback
|
||||
*/
|
||||
int
|
||||
upgrade_callback_reg_fn(clicon_handle h,
|
||||
upgrade_callback_reg_fn(clixon_handle h,
|
||||
clicon_upgrade_cb cb,
|
||||
const char *fnstr,
|
||||
const char *ns,
|
||||
|
|
@ -1604,11 +1606,11 @@ upgrade_callback_reg_fn(clicon_handle h,
|
|||
plugin_module_struct *ms = plugin_module_struct_get(h);
|
||||
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
goto done;
|
||||
}
|
||||
if ((uc = malloc(sizeof(upgrade_callback_t))) == NULL) {
|
||||
clicon_err(OE_DB, errno, "malloc");
|
||||
clixon_err(OE_DB, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(uc, 0, sizeof(*uc));
|
||||
|
|
@ -1631,7 +1633,7 @@ upgrade_callback_reg_fn(clicon_handle h,
|
|||
/*! Delete all Upgrade callbacks
|
||||
*/
|
||||
static int
|
||||
upgrade_callback_delete_all(clicon_handle h)
|
||||
upgrade_callback_delete_all(clixon_handle h)
|
||||
{
|
||||
upgrade_callback_t *uc;
|
||||
plugin_module_struct *ms = plugin_module_struct_get(h);
|
||||
|
|
@ -1661,7 +1663,7 @@ upgrade_callback_delete_all(clicon_handle h)
|
|||
* @see upgrade_callback_reg_fn which registers the callbacks
|
||||
*/
|
||||
int
|
||||
upgrade_callback_call(clicon_handle h,
|
||||
upgrade_callback_call(clixon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
|
|
@ -1676,7 +1678,7 @@ upgrade_callback_call(clicon_handle h,
|
|||
plugin_module_struct *ms = plugin_module_struct_get(h);
|
||||
|
||||
if (ms == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized");
|
||||
goto done;
|
||||
}
|
||||
if ((uc = ms->ms_upgrade_callbacks) != NULL)
|
||||
|
|
@ -1696,7 +1698,7 @@ upgrade_callback_call(clicon_handle h,
|
|||
}
|
||||
if (ret == 0){
|
||||
if (cbuf_len(cbret)==0){
|
||||
clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
|
||||
clixon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
|
||||
uc->uc_fnstr, ns);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1751,17 +1753,17 @@ clixon_auth_type_int2str(clixon_auth_type_t auth_type)
|
|||
* @see clixon_plugin_module_exit
|
||||
*/
|
||||
int
|
||||
clixon_plugin_module_init(clicon_handle h)
|
||||
clixon_plugin_module_init(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
struct plugin_module_struct *ph;
|
||||
|
||||
if (plugin_module_struct_get(h) != NULL){
|
||||
clicon_err(OE_PLUGIN, EFAULT, "Already initialized");
|
||||
clixon_err(OE_PLUGIN, EFAULT, "Already initialized");
|
||||
goto done;
|
||||
}
|
||||
if ((ph = malloc(sizeof(*ph))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(ph, 0, sizeof(*ph));
|
||||
|
|
@ -1778,7 +1780,7 @@ clixon_plugin_module_init(clicon_handle h)
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
int
|
||||
clixon_plugin_module_exit(clicon_handle h)
|
||||
clixon_plugin_module_exit(clixon_handle h)
|
||||
{
|
||||
struct plugin_module_struct *ph;
|
||||
|
||||
|
|
|
|||
|
|
@ -110,12 +110,13 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_uid.h"
|
||||
#include "clixon_event.h"
|
||||
|
|
@ -159,7 +160,7 @@ struct process_entry_t {
|
|||
};
|
||||
|
||||
/* Forward declaration */
|
||||
static int clixon_process_sched_register(clicon_handle h, int delay);
|
||||
static int clixon_process_sched_register(clixon_handle h, int delay);
|
||||
static int clixon_process_delete_only(process_entry_t *pe);
|
||||
|
||||
static void
|
||||
|
|
@ -170,6 +171,7 @@ clixon_proc_sigint(int sig)
|
|||
|
||||
/*! Fork a child, exec a child and setup socket to child and return to caller
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] argv NULL-terminated Argument vector
|
||||
* @param[in] sock_flags Socket type/flags, typically SOCK_DGRAM or SOCK_STREAM, see
|
||||
* @param[out] pid Process-id of child
|
||||
|
|
@ -180,10 +182,11 @@ clixon_proc_sigint(int sig)
|
|||
* @see for flags usage see man sockerpair(2)
|
||||
*/
|
||||
int
|
||||
clixon_proc_socket(char **argv,
|
||||
int sock_flags,
|
||||
pid_t *pid,
|
||||
int *sock)
|
||||
clixon_proc_socket(clixon_handle h,
|
||||
char **argv,
|
||||
int sock_flags,
|
||||
pid_t *pid,
|
||||
int *sock)
|
||||
{
|
||||
int retval = -1;
|
||||
int sp[2] = {-1, -1};
|
||||
|
|
@ -195,25 +198,25 @@ clixon_proc_socket(char **argv,
|
|||
char *flattened;
|
||||
|
||||
if (argv == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "argv is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "argv is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (argv[0] == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "argv[0] is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "argv[0] is NULL");
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (argc = 0; argv[argc] != NULL; ++argc)
|
||||
;
|
||||
if ((flattened = clicon_strjoin(argc, argv, "', '")) == NULL){
|
||||
clicon_err(OE_UNIX, ENOMEM, "clicon_strjoin");
|
||||
clixon_err(OE_UNIX, ENOMEM, "clicon_strjoin");
|
||||
goto done;
|
||||
}
|
||||
clicon_log(LOG_INFO, "%s '%s'", __FUNCTION__, flattened);
|
||||
clixon_log(h, LOG_INFO, "%s '%s'", __FUNCTION__, flattened);
|
||||
free(flattened);
|
||||
|
||||
if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){
|
||||
clicon_err(OE_UNIX, errno, "socketpair");
|
||||
clixon_err(OE_UNIX, errno, "socketpair");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +224,7 @@ clixon_proc_socket(char **argv,
|
|||
set_signal(SIGINT, clixon_proc_sigint, &oldhandler);
|
||||
sig++;
|
||||
if ((child = fork()) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "fork");
|
||||
clixon_err(OE_UNIX, errno, "fork");
|
||||
goto done;
|
||||
}
|
||||
if (child == 0) { /* Child */
|
||||
|
|
@ -232,17 +235,17 @@ clixon_proc_socket(char **argv,
|
|||
close(sp[0]);
|
||||
close(0);
|
||||
if (dup2(sp[1], STDIN_FILENO) < 0){
|
||||
clicon_err(OE_UNIX, errno, "dup2(STDIN)");
|
||||
clixon_err(OE_UNIX, errno, "dup2(STDIN)");
|
||||
return -1;
|
||||
}
|
||||
close(1);
|
||||
if (dup2(sp[1], STDOUT_FILENO) < 0){
|
||||
clicon_err(OE_UNIX, errno, "dup2(STDOUT)");
|
||||
clixon_err(OE_UNIX, errno, "dup2(STDOUT)");
|
||||
return -1;
|
||||
}
|
||||
close(sp[1]);
|
||||
if (execvp(argv[0], argv) < 0){
|
||||
clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]);
|
||||
clixon_err(OE_UNIX, errno, "execvp(%s)", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
exit(-1); /* Shouldnt reach here */
|
||||
|
|
@ -288,6 +291,7 @@ clixon_proc_socket_close(pid_t pid,
|
|||
|
||||
/*! Fork and exec a sub-process, let it run and return pid
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] argv NULL-terminated Argument vector
|
||||
* @param[in] netns Network namespace (or NULL)
|
||||
* @param[in] uid User-id or -1 to keep existing
|
||||
|
|
@ -297,12 +301,13 @@ clixon_proc_socket_close(pid_t pid,
|
|||
* @retval -1 Error.
|
||||
*/
|
||||
static int
|
||||
clixon_proc_background(char **argv,
|
||||
const char *netns,
|
||||
uid_t uid,
|
||||
gid_t gid,
|
||||
int fdkeep,
|
||||
pid_t *pid0)
|
||||
clixon_proc_background(clixon_handle h,
|
||||
char **argv,
|
||||
const char *netns,
|
||||
uid_t uid,
|
||||
gid_t gid,
|
||||
int fdkeep,
|
||||
pid_t *pid0)
|
||||
{
|
||||
int retval = -1;
|
||||
pid_t child = 0;
|
||||
|
|
@ -316,26 +321,26 @@ clixon_proc_background(char **argv,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (argv == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "argv is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "argv is NULL");
|
||||
goto quit;
|
||||
}
|
||||
if (argv[0] == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "argv[0] is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "argv[0] is NULL");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
for (argc = 0; argv[argc] != NULL; ++argc)
|
||||
;
|
||||
if ((flattened = clicon_strjoin(argc, argv, "', '")) == NULL){
|
||||
clicon_err(OE_UNIX, ENOMEM, "clicon_strjoin");
|
||||
clixon_err(OE_UNIX, ENOMEM, "clicon_strjoin");
|
||||
goto quit;
|
||||
}
|
||||
clicon_log(LOG_INFO, "%s '%s'", __FUNCTION__, flattened);
|
||||
clixon_log(h, LOG_INFO, "%s '%s'", __FUNCTION__, flattened);
|
||||
free(flattened);
|
||||
|
||||
/* Sanity check: program exists */
|
||||
if (stat(argv[0], &fstat) < 0) {
|
||||
clicon_err(OE_FATAL, errno, "%s", argv[0]);
|
||||
clixon_err(OE_FATAL, errno, "%s", argv[0]);
|
||||
goto quit;
|
||||
}
|
||||
/* Before here call quit on error */
|
||||
|
|
@ -343,7 +348,7 @@ clixon_proc_background(char **argv,
|
|||
set_signal(SIGINT, clixon_proc_sigint, &oldhandler);
|
||||
/* Now call done on error */
|
||||
if ((child = fork()) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "fork");
|
||||
clixon_err(OE_UNIX, errno, "fork");
|
||||
goto done;
|
||||
}
|
||||
if (child == 0) { /* Child */
|
||||
|
|
@ -355,7 +360,7 @@ clixon_proc_background(char **argv,
|
|||
clicon_signal_unblock(0);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
if (chdir("/") < 0){
|
||||
clicon_err(OE_UNIX, errno, "chdir");
|
||||
clixon_err(OE_UNIX, errno, "chdir");
|
||||
exit(1);
|
||||
}
|
||||
/* Close open descriptors */
|
||||
|
|
@ -374,23 +379,23 @@ clixon_proc_background(char **argv,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s nsfile:%s", __FUNCTION__, nsfile);
|
||||
/* Change network namespace */
|
||||
if ((nsfd = open(nsfile, O_RDONLY | O_CLOEXEC)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "open");
|
||||
clixon_err(OE_UNIX, errno, "open");
|
||||
exit(1);
|
||||
}
|
||||
if (setns(nsfd, 0) < 0){ /* Join that namespace */
|
||||
clicon_err(OE_UNIX, errno, "setns");
|
||||
clixon_err(OE_UNIX, errno, "setns");
|
||||
exit(1);
|
||||
}
|
||||
close(nsfd);
|
||||
if (unshare(CLONE_NEWNS) < 0){
|
||||
clicon_err(OE_UNIX, errno, "unshare");
|
||||
clixon_err(OE_UNIX, errno, "unshare");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_SETNS */
|
||||
if (gid != -1){
|
||||
if (setgid(gid) == -1) {
|
||||
clicon_err(OE_DAEMON, errno, "setgid %d", gid);
|
||||
clixon_err(OE_DAEMON, errno, "setgid %d", gid);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -399,7 +404,7 @@ clixon_proc_background(char **argv,
|
|||
goto done;
|
||||
}
|
||||
if (execvp(argv[0], argv) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]);
|
||||
clixon_err(OE_UNIX, errno, "execvp(%s)", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
/* Not reached */
|
||||
|
|
@ -456,7 +461,7 @@ clixon_process_op_str2int(char *opstr)
|
|||
* itself, but its elements can be freed and re-alloced.
|
||||
*/
|
||||
int
|
||||
clixon_process_argv_get(clicon_handle h,
|
||||
clixon_process_argv_get(clixon_handle h,
|
||||
const char *name,
|
||||
char ***argv,
|
||||
int *argc)
|
||||
|
|
@ -491,7 +496,7 @@ clixon_process_argv_get(clicon_handle h,
|
|||
* @note name, netns, argv and its elements are all copied / re-alloced.
|
||||
*/
|
||||
int
|
||||
clixon_process_register(clicon_handle h,
|
||||
clixon_process_register(clixon_handle h,
|
||||
const char *name,
|
||||
const char *description,
|
||||
const char *netns,
|
||||
|
|
@ -507,33 +512,33 @@ clixon_process_register(clicon_handle h,
|
|||
int i;
|
||||
|
||||
if (name == NULL){
|
||||
clicon_err(OE_DB, EINVAL, "name is NULL");
|
||||
clixon_err(OE_DB, EINVAL, "name is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (argv == NULL){
|
||||
clicon_err(OE_DB, EINVAL, "argv is NULL");
|
||||
clixon_err(OE_DB, EINVAL, "argv is NULL");
|
||||
goto done;
|
||||
}
|
||||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s name:%s (%s)", __FUNCTION__, name, argv[0]);
|
||||
|
||||
if ((pe = malloc(sizeof(process_entry_t))) == NULL) {
|
||||
clicon_err(OE_DB, errno, "malloc");
|
||||
clixon_err(OE_DB, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(pe, 0, sizeof(*pe));
|
||||
if ((pe->pe_name = strdup(name)) == NULL){
|
||||
clicon_err(OE_DB, errno, "strdup name");
|
||||
clixon_err(OE_DB, errno, "strdup name");
|
||||
free(pe);
|
||||
goto done;
|
||||
}
|
||||
if (description && (pe->pe_description = strdup(description)) == NULL){
|
||||
clicon_err(OE_DB, errno, "strdup description");
|
||||
clixon_err(OE_DB, errno, "strdup description");
|
||||
clixon_process_delete_only(pe);
|
||||
goto done;
|
||||
}
|
||||
if (netns && (pe->pe_netns = strdup(netns)) == NULL){
|
||||
clicon_err(OE_DB, errno, "strdup netns");
|
||||
clixon_err(OE_DB, errno, "strdup netns");
|
||||
clixon_process_delete_only(pe);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -542,14 +547,14 @@ clixon_process_register(clicon_handle h,
|
|||
pe->pe_fdkeep = fdkeep;
|
||||
pe->pe_argc = argc;
|
||||
if ((pe->pe_argv = calloc(argc, sizeof(char *))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_process_delete_only(pe);
|
||||
goto done;
|
||||
}
|
||||
for (i=0; i<argc; i++){
|
||||
if (argv[i] != NULL &&
|
||||
(pe->pe_argv[i] = strdup(argv[i])) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_process_delete_only(pe);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -591,7 +596,7 @@ clixon_process_delete_only(process_entry_t *pe)
|
|||
/*! Delete all Upgrade callbacks
|
||||
*/
|
||||
int
|
||||
clixon_process_delete_all(clicon_handle h)
|
||||
clixon_process_delete_all(clixon_handle h)
|
||||
{
|
||||
process_entry_t *pe;
|
||||
|
||||
|
|
@ -621,7 +626,7 @@ proc_op_run(pid_t pid0,
|
|||
run = 0;
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_UNIX, errno, "kill(%d)", pid);
|
||||
clixon_err(OE_UNIX, errno, "kill(%d)", pid);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -634,7 +639,7 @@ proc_op_run(pid_t pid0,
|
|||
}
|
||||
|
||||
int
|
||||
clixon_process_pid(clicon_handle h,
|
||||
clixon_process_pid(clixon_handle h,
|
||||
const char *name,
|
||||
pid_t *pid)
|
||||
{
|
||||
|
|
@ -682,7 +687,7 @@ done:
|
|||
* @see clixon_process_sched where operations are actually executed
|
||||
*/
|
||||
int
|
||||
clixon_process_operation(clicon_handle h,
|
||||
clixon_process_operation(clixon_handle h,
|
||||
const char *name,
|
||||
proc_operation op0,
|
||||
int wrapit)
|
||||
|
|
@ -716,7 +721,7 @@ clixon_process_operation(clicon_handle h,
|
|||
if (proc_op_run(pe->pe_pid, &isrunning) < 0)
|
||||
goto done;
|
||||
if (isrunning) {
|
||||
clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
|
||||
clixon_log(h, LOG_NOTICE, "Killing old process %s with pid: %d",
|
||||
pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
|
||||
kill(pe->pe_pid, SIGTERM);
|
||||
delay = 1;
|
||||
|
|
@ -757,7 +762,7 @@ clixon_process_operation(clicon_handle h,
|
|||
|
||||
*/
|
||||
int
|
||||
clixon_process_status(clicon_handle h,
|
||||
clixon_process_status(clixon_handle h,
|
||||
const char *name,
|
||||
cbuf *cbret)
|
||||
{
|
||||
|
|
@ -798,7 +803,7 @@ clixon_process_status(clicon_handle h,
|
|||
clicon_int2str(proc_state_map, pe->pe_state));
|
||||
if (timerisset(&pe->pe_starttime)){
|
||||
if (time2str(&pe->pe_starttime, timestr, sizeof(timestr)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "time2str");
|
||||
clixon_err(OE_UNIX, errno, "time2str");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<starttime xmlns=\"%s\">%s</starttime>", CLIXON_LIB_NS, timestr);
|
||||
|
|
@ -831,7 +836,7 @@ clixon_process_status(clicon_handle h,
|
|||
* where commits are not made.
|
||||
*/
|
||||
int
|
||||
clixon_process_start_all(clicon_handle h)
|
||||
clixon_process_start_all(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
process_entry_t *pe;
|
||||
|
|
@ -878,7 +883,7 @@ clixon_process_start_all(clicon_handle h)
|
|||
*/
|
||||
static int
|
||||
clixon_process_sched(int fd,
|
||||
clicon_handle h)
|
||||
clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
process_entry_t *pe;
|
||||
|
|
@ -903,7 +908,7 @@ clixon_process_sched(int fd,
|
|||
if (proc_op_run(pe->pe_pid, &isrunning) < 0)
|
||||
goto done;
|
||||
if (isrunning) {
|
||||
clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
|
||||
clixon_log(h, LOG_NOTICE, "Killing old process %s with pid: %d",
|
||||
pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
|
||||
kill(pe->pe_pid, SIGTERM);
|
||||
sched++; /* Not immediate: wait timeout */
|
||||
|
|
@ -921,7 +926,7 @@ clixon_process_sched(int fd,
|
|||
if (proc_op_run(pe->pe_pid, &isrunning) < 0)
|
||||
goto done;
|
||||
if (!isrunning)
|
||||
if (clixon_proc_background(pe->pe_argv, pe->pe_netns,
|
||||
if (clixon_proc_background(h, pe->pe_argv, pe->pe_netns,
|
||||
pe->pe_uid, pe->pe_gid, pe->pe_fdkeep,
|
||||
&pe->pe_pid) < 0)
|
||||
goto done;
|
||||
|
|
@ -949,7 +954,7 @@ clixon_process_sched(int fd,
|
|||
case PROC_OP_START:
|
||||
if (isrunning) /* Already runs */
|
||||
break;
|
||||
if (clixon_proc_background(pe->pe_argv, pe->pe_netns,
|
||||
if (clixon_proc_background(h, pe->pe_argv, pe->pe_netns,
|
||||
pe->pe_uid, pe->pe_gid, pe->pe_fdkeep,
|
||||
&pe->pe_pid) < 0)
|
||||
goto done;
|
||||
|
|
@ -992,7 +997,7 @@ clixon_process_sched(int fd,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
clixon_process_sched_register(clicon_handle h,
|
||||
clixon_process_sched_register(clixon_handle h,
|
||||
int delay)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1021,7 +1026,7 @@ clixon_process_sched_register(clicon_handle h,
|
|||
|
||||
*/
|
||||
int
|
||||
clixon_process_waitpid(clicon_handle h)
|
||||
clixon_process_waitpid(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
process_entry_t *pe;
|
||||
|
|
@ -1063,7 +1068,7 @@ clixon_process_waitpid(clicon_handle h)
|
|||
case PROC_OP_RESTART:
|
||||
/* This is the case where there is an existing process running.
|
||||
* it was killed above but still runs and needs to be reaped */
|
||||
if (clixon_proc_background(pe->pe_argv, pe->pe_netns,
|
||||
if (clixon_proc_background(h, pe->pe_argv, pe->pe_netns,
|
||||
pe->pe_uid, pe->pe_gid, pe->pe_fdkeep,
|
||||
&pe->pe_pid) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -63,13 +63,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_event.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_sig.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -158,7 +159,7 @@ clicon_msg_encode(uint32_t id,
|
|||
|
||||
len = hdrlen + xmllen;
|
||||
if ((msg = (struct clicon_msg *)malloc(len)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "malloc");
|
||||
clixon_err(OE_PROTO, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(msg, 0, len);
|
||||
|
|
@ -182,7 +183,7 @@ clicon_msg_encode(uint32_t id,
|
|||
* @param[out] xerr Reason for failure (yang assignment not made) if retval =0
|
||||
* @retval 1 Parse OK and all yang assignment made
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial)
|
||||
* @retval -1 Error with clicon_err called. Includes parse error
|
||||
* @retval -1 Error with clixon_err called. Includes parse error
|
||||
*/
|
||||
int
|
||||
clicon_msg_decode(struct clicon_msg *msg,
|
||||
|
|
@ -222,7 +223,7 @@ clicon_msg_decode(struct clicon_msg *msg,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_connect_unix(clicon_handle h,
|
||||
clicon_connect_unix(clixon_handle h,
|
||||
char *sockpath)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
|
|
@ -230,7 +231,7 @@ clicon_connect_unix(clicon_handle h,
|
|||
int s;
|
||||
|
||||
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
clicon_err(OE_CFG, errno, "socket");
|
||||
clixon_err(OE_CFG, errno, "socket");
|
||||
return -1;
|
||||
}
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
|
@ -240,11 +241,11 @@ clicon_connect_unix(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DETAIL, "%s: connecting to %s", __FUNCTION__, addr.sun_path);
|
||||
if (connect(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){
|
||||
if (errno == EACCES)
|
||||
clicon_err(OE_CFG, errno, "connecting unix socket: %s. "
|
||||
clixon_err(OE_CFG, errno, "connecting unix socket: %s. "
|
||||
"Is user not member of group: \"%s\"?",
|
||||
sockpath, clicon_sock_group(h));
|
||||
else
|
||||
clicon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath);
|
||||
clixon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath);
|
||||
close(s);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -323,7 +324,7 @@ msg_hex(int dbglevel,
|
|||
if ((dbglevel & clixon_debug_get()) == 0) /* compare debug level with global variable */
|
||||
goto ok;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_CFG, errno, "cbuf_new");
|
||||
clixon_err(OE_CFG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s:", file);
|
||||
|
|
@ -374,8 +375,8 @@ clicon_msg_send(int s,
|
|||
if (atomicio((ssize_t (*)(int, void *, size_t))write,
|
||||
s, msg, ntohl(msg->op_len)) < 0){
|
||||
e = errno;
|
||||
clicon_err(OE_CFG, e, "atomicio");
|
||||
clicon_log(LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__,
|
||||
clixon_err(OE_CFG, e, "atomicio");
|
||||
clixon_log(NULL, LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__,
|
||||
strerror(e), ntohs(msg->op_len), msg->op_body);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -428,7 +429,7 @@ clicon_msg_rcv(int s,
|
|||
if (intr && _atomicio_sig)
|
||||
;
|
||||
else
|
||||
clicon_err(OE_CFG, errno, "atomicio");
|
||||
clixon_err(OE_CFG, errno, "atomicio");
|
||||
goto done;
|
||||
}
|
||||
msg_hex(CLIXON_DBG_EXTRA, (char*)&hdr, hlen, __FUNCTION__);
|
||||
|
|
@ -437,7 +438,7 @@ clicon_msg_rcv(int s,
|
|||
goto ok;
|
||||
}
|
||||
if (hlen != sizeof(hdr)){
|
||||
clicon_err(OE_PROTO, errno, "header too short (%d)", hlen);
|
||||
clixon_err(OE_PROTO, errno, "header too short (%d)", hlen);
|
||||
goto done;
|
||||
}
|
||||
mlen = ntohl(hdr.op_len);
|
||||
|
|
@ -446,28 +447,28 @@ clicon_msg_rcv(int s,
|
|||
clixon_debug(CLIXON_DBG_DETAIL, "%s: rcv msg len=%d",
|
||||
__FUNCTION__, mlen);
|
||||
if (mlen <= sizeof(hdr)){
|
||||
clicon_err(OE_PROTO, 0, "op_len:%u too short", mlen);
|
||||
clixon_err(OE_PROTO, 0, "op_len:%u too short", mlen);
|
||||
*eof = 1;
|
||||
goto ok;
|
||||
}
|
||||
if ((*msg = (struct clicon_msg *)malloc(mlen+1)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "malloc");
|
||||
clixon_err(OE_PROTO, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memcpy(*msg, &hdr, hlen);
|
||||
if ((len2 = atomicio(read, s, (*msg)->op_body, mlen - sizeof(hdr))) < 0){
|
||||
clicon_err(OE_PROTO, errno, "read");
|
||||
clixon_err(OE_PROTO, errno, "read");
|
||||
goto done;
|
||||
}
|
||||
if (len2)
|
||||
msg_hex(CLIXON_DBG_EXTRA, (*msg)->op_body, len2, __FUNCTION__);
|
||||
if (len2 != mlen - sizeof(hdr)){
|
||||
clicon_err(OE_PROTO, 0, "body too short");
|
||||
clixon_err(OE_PROTO, 0, "body too short");
|
||||
*eof = 1;
|
||||
goto ok;
|
||||
}
|
||||
if (((char*)*msg)[mlen-1] != '\0'){
|
||||
clicon_err(OE_PROTO, 0, "body not NULL terminated");
|
||||
clixon_err(OE_PROTO, 0, "body not NULL terminated");
|
||||
*eof = 1;
|
||||
goto ok;
|
||||
}
|
||||
|
|
@ -519,7 +520,7 @@ clicon_msg_rcv1(int s,
|
|||
if (errno == ECONNRESET)
|
||||
len = 0; /* emulate EOF */
|
||||
else{
|
||||
clicon_log(LOG_ERR, "%s: read: %s errno:%d", __FUNCTION__, strerror(errno), errno);
|
||||
clixon_log(NULL, LOG_ERR, "%s: read: %s errno:%d", __FUNCTION__, strerror(errno), errno);
|
||||
goto done;
|
||||
}
|
||||
} /* read */
|
||||
|
|
@ -581,8 +582,8 @@ clicon_msg_send1(int s,
|
|||
clixon_debug(CLIXON_DBG_MSG, "Send: %s", cbuf_get(cb));
|
||||
if (atomicio((ssize_t (*)(int, void *, size_t))write,
|
||||
s, cbuf_get(cb), cbuf_len(cb)) < 0){
|
||||
clicon_err(OE_CFG, errno, "atomicio");
|
||||
clicon_log(LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno));
|
||||
clixon_err(OE_CFG, errno, "atomicio");
|
||||
clixon_log(NULL, LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno));
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -602,7 +603,7 @@ clicon_msg_send1(int s,
|
|||
* @see clicon_rpc But this is one-shot rpc: open, send, get reply and close.
|
||||
*/
|
||||
int
|
||||
clicon_rpc_connect_unix(clicon_handle h,
|
||||
clicon_rpc_connect_unix(clixon_handle h,
|
||||
char *sockpath,
|
||||
int *sock0)
|
||||
{
|
||||
|
|
@ -612,16 +613,16 @@ clicon_rpc_connect_unix(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "Send msg on %s", sockpath);
|
||||
if (sock0 == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "sock0 expected");
|
||||
clixon_err(OE_NETCONF, EINVAL, "sock0 expected");
|
||||
goto done;
|
||||
}
|
||||
/* special error handling to get understandable messages (otherwise ENOENT) */
|
||||
if (stat(sockpath, &sb) < 0){
|
||||
clicon_err(OE_PROTO, errno, "%s: config daemon not running?", sockpath);
|
||||
clixon_err(OE_PROTO, errno, "%s: config daemon not running?", sockpath);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISSOCK(sb.st_mode)){
|
||||
clicon_err(OE_PROTO, EIO, "%s: Not unix socket", sockpath);
|
||||
clixon_err(OE_PROTO, EIO, "%s: Not unix socket", sockpath);
|
||||
goto done;
|
||||
}
|
||||
if ((s = clicon_connect_unix(h, sockpath)) < 0)
|
||||
|
|
@ -644,7 +645,7 @@ clicon_rpc_connect_unix(clicon_handle h,
|
|||
* @see clicon_rpc But this is one-shot rpc: open, send, get reply and close.
|
||||
*/
|
||||
int
|
||||
clicon_rpc_connect_inet(clicon_handle h,
|
||||
clicon_rpc_connect_inet(clixon_handle h,
|
||||
char *dst,
|
||||
uint16_t port,
|
||||
int *sock0)
|
||||
|
|
@ -655,7 +656,7 @@ clicon_rpc_connect_inet(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "Send msg to %s:%hu", dst, port);
|
||||
if (sock0 == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "sock0 expected");
|
||||
clixon_err(OE_NETCONF, EINVAL, "sock0 expected");
|
||||
goto done;
|
||||
}
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
|
@ -665,11 +666,11 @@ clicon_rpc_connect_inet(clicon_handle h,
|
|||
goto done; /* Could check getaddrinfo */
|
||||
/* special error handling to get understandable messages (otherwise ENOENT) */
|
||||
if ((s = socket(addr.sin_family, SOCK_STREAM, 0)) < 0) {
|
||||
clicon_err(OE_CFG, errno, "socket");
|
||||
clixon_err(OE_CFG, errno, "socket");
|
||||
return -1;
|
||||
}
|
||||
if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) < 0){
|
||||
clicon_err(OE_CFG, errno, "connecting socket inet4");
|
||||
clixon_err(OE_CFG, errno, "connecting socket inet4");
|
||||
close(s);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -716,7 +717,7 @@ clicon_rpc(int sock,
|
|||
data = reply->op_body; /* assume string */
|
||||
if (ret && data)
|
||||
if ((*ret = strdup(data)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
|
|
@ -839,7 +840,7 @@ send_msg_notify(int s,
|
|||
* @see send_msg_notify
|
||||
*/
|
||||
int
|
||||
send_msg_notify_xml(clicon_handle h,
|
||||
send_msg_notify_xml(clixon_handle h,
|
||||
int s,
|
||||
const char *descr,
|
||||
cxobj *xev)
|
||||
|
|
@ -848,7 +849,7 @@ send_msg_notify_xml(clicon_handle h,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, xev, 0, 0, NULL, -1, 0) < 0)
|
||||
|
|
@ -941,7 +942,7 @@ clixon_inet2sin(const char *addrtype,
|
|||
sin->sin_addr.s_addr = inet_addr(addrstr);
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype);
|
||||
clixon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -57,11 +57,13 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_options.h"
|
||||
|
|
@ -72,7 +74,6 @@
|
|||
#include "clixon_xpath_ctx.h"
|
||||
#include "clixon_xpath.h"
|
||||
#include "clixon_proto.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_event.h"
|
||||
#include "clixon_stream.h"
|
||||
#include "clixon_err_string.h"
|
||||
|
|
@ -95,7 +96,7 @@
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clicon_rpc_connect(clicon_handle h,
|
||||
clicon_rpc_connect(clixon_handle h,
|
||||
int *sockp)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -103,7 +104,7 @@ clicon_rpc_connect(clicon_handle h,
|
|||
int port;
|
||||
|
||||
if ((sockstr = clicon_sock_str(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
|
||||
clixon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
|
||||
goto done;
|
||||
}
|
||||
/* What to do if inet socket? */
|
||||
|
|
@ -121,11 +122,11 @@ clicon_rpc_connect(clicon_handle h,
|
|||
break;
|
||||
case AF_INET:
|
||||
if ((port = clicon_sock_port(h)) < 0){
|
||||
clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
|
||||
clixon_err(OE_FATAL, 0, "CLICON_SOCK option not set");
|
||||
goto done;
|
||||
}
|
||||
if (port < 0){
|
||||
clicon_err(OE_FATAL, 0, "CLICON_SOCK_PORT not set");
|
||||
clixon_err(OE_FATAL, 0, "CLICON_SOCK_PORT not set");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_connect_inet(h, sockstr, port, sockp) < 0)
|
||||
|
|
@ -149,7 +150,7 @@ clicon_rpc_connect(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
clicon_rpc_msg_once(clicon_handle h,
|
||||
clicon_rpc_msg_once(clixon_handle h,
|
||||
struct clicon_msg *msg,
|
||||
int cache,
|
||||
char **retdata,
|
||||
|
|
@ -195,7 +196,7 @@ clicon_rpc_msg_once(clicon_handle h,
|
|||
* @see clicon_rpc_close_session
|
||||
*/
|
||||
int
|
||||
clicon_rpc_msg(clicon_handle h,
|
||||
clicon_rpc_msg(clixon_handle h,
|
||||
struct clicon_msg *msg,
|
||||
cxobj **xret0)
|
||||
{
|
||||
|
|
@ -225,16 +226,16 @@ clicon_rpc_msg(clicon_handle h,
|
|||
close(s);
|
||||
s = -1;
|
||||
clicon_client_socket_set(h, -1);
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
goto done;
|
||||
}
|
||||
/* To disable this restart, unset PROTO_RESTART_RECONNECT */
|
||||
clicon_session_id_del(h);
|
||||
clicon_log(LOG_WARNING, "The backend was probably restarted and the client has reconnected to the backend. Any locks or candidate edits are lost.");
|
||||
clixon_log(h, LOG_WARNING, "The backend was probably restarted and the client has reconnected to the backend. Any locks or candidate edits are lost.");
|
||||
|
||||
}
|
||||
#else
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -272,7 +273,7 @@ clicon_rpc_msg(clicon_handle h,
|
|||
* @note xret is populated with yangspec according to standard handle yangspec
|
||||
*/
|
||||
int
|
||||
clicon_rpc_msg_persistent(clicon_handle h,
|
||||
clicon_rpc_msg_persistent(clixon_handle h,
|
||||
struct clicon_msg *msg,
|
||||
cxobj **xret0,
|
||||
int *sock0)
|
||||
|
|
@ -284,7 +285,7 @@ clicon_rpc_msg_persistent(clicon_handle h,
|
|||
int eof = 0;
|
||||
|
||||
if (sock0 == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "Missing socket pointer");
|
||||
clixon_err(OE_NETCONF, EINVAL, "Missing socket pointer");
|
||||
goto done;
|
||||
}
|
||||
#ifdef RPC_USERNAME_ASSERT
|
||||
|
|
@ -302,7 +303,7 @@ clicon_rpc_msg_persistent(clicon_handle h,
|
|||
/* Note here one could try a restart as done in clicon_rpc_msg, but seems not
|
||||
* right since if backend is restarted, the notification stream is gone.
|
||||
*/
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed.");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s retdata:%s", __FUNCTION__, retdata);
|
||||
|
|
@ -345,7 +346,7 @@ clicon_rpc_msg_persistent(clicon_handle h,
|
|||
* @note This function may send a synchronous(blocking) HELLO request to the backend as a side-effect
|
||||
*/
|
||||
static int
|
||||
session_id_check(clicon_handle h,
|
||||
session_id_check(clixon_handle h,
|
||||
uint32_t *session_id)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -381,7 +382,7 @@ session_id_check(clicon_handle h,
|
|||
* @see clicon_rpc_netconf_xml xml as tree instead of string
|
||||
*/
|
||||
int
|
||||
clicon_rpc_netconf(clicon_handle h,
|
||||
clicon_rpc_netconf(clixon_handle h,
|
||||
char *xmlstr,
|
||||
cxobj **xret,
|
||||
int *sp)
|
||||
|
|
@ -427,7 +428,7 @@ clicon_rpc_netconf(clicon_handle h,
|
|||
* @see clicon_rpc_netconf xml as string instead of tree
|
||||
*/
|
||||
int
|
||||
clicon_rpc_netconf_xml(clicon_handle h,
|
||||
clicon_rpc_netconf_xml(clixon_handle h,
|
||||
cxobj *xml,
|
||||
cxobj **xret,
|
||||
int *sp)
|
||||
|
|
@ -442,11 +443,11 @@ clicon_rpc_netconf_xml(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((xname = xml_child_i_type(xml, 0, 0)) == NULL){
|
||||
clicon_err(OE_NETCONF, EINVAL, "Missing rpc name");
|
||||
clixon_err(OE_NETCONF, EINVAL, "Missing rpc name");
|
||||
goto done;
|
||||
}
|
||||
rpcname = xml_name(xname); /* Store rpc name and use in yang binding after reply */
|
||||
|
|
@ -512,7 +513,7 @@ clicon_rpc_netconf_xml(clicon_handle h,
|
|||
* @note the netconf return message is yang populated, as well as the return data
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get_config(clicon_handle h,
|
||||
clicon_rpc_get_config(clixon_handle h,
|
||||
char *username, // XXX: why is this only rpc call with username parameter?
|
||||
char *db,
|
||||
char *xpath,
|
||||
|
|
@ -534,7 +535,7 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -586,7 +587,7 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
NULL) < 0)
|
||||
goto done;
|
||||
if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
|
||||
clixon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -633,7 +634,7 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
clicon_rpc_edit_config(clicon_handle h,
|
||||
clicon_rpc_edit_config(clixon_handle h,
|
||||
char *db,
|
||||
enum operation_type op,
|
||||
char *xmlstr)
|
||||
|
|
@ -649,7 +650,7 @@ clicon_rpc_edit_config(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -670,7 +671,11 @@ clicon_rpc_edit_config(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Editing configuration");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Editing configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -699,7 +704,7 @@ clicon_rpc_edit_config(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
clicon_rpc_copy_config(clicon_handle h,
|
||||
clicon_rpc_copy_config(clixon_handle h,
|
||||
char *db1,
|
||||
char *db2)
|
||||
{
|
||||
|
|
@ -714,7 +719,7 @@ clicon_rpc_copy_config(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -732,7 +737,11 @@ clicon_rpc_copy_config(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Copying configuration");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Copying configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -758,7 +767,7 @@ clicon_rpc_copy_config(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
clicon_rpc_delete_config(clicon_handle h,
|
||||
clicon_rpc_delete_config(clixon_handle h,
|
||||
char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -772,7 +781,7 @@ clicon_rpc_delete_config(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -790,7 +799,11 @@ clicon_rpc_delete_config(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Deleting configuration");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Deleting configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -812,7 +825,7 @@ clicon_rpc_delete_config(clicon_handle h,
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
clicon_rpc_lock(clicon_handle h,
|
||||
clicon_rpc_lock(clixon_handle h,
|
||||
char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -826,7 +839,7 @@ clicon_rpc_lock(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -844,7 +857,11 @@ clicon_rpc_lock(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Locking configuration");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Locking configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -866,7 +883,7 @@ clicon_rpc_lock(clicon_handle h,
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
clicon_rpc_unlock(clicon_handle h,
|
||||
clicon_rpc_unlock(clixon_handle h,
|
||||
char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -880,7 +897,7 @@ clicon_rpc_unlock(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -898,7 +915,11 @@ clicon_rpc_unlock(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Unlocking configuration");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Configuration unlock", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -936,7 +957,7 @@ clicon_rpc_unlock(clicon_handle h,
|
|||
* if (clicon_rpc_get(h, "/hello/world", nsc, CONTENT_ALL, -1, &xt) < 0)
|
||||
* err;
|
||||
* if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
* clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL);
|
||||
* clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
|
||||
* err;
|
||||
* }
|
||||
* if (xt)
|
||||
|
|
@ -945,11 +966,11 @@ clicon_rpc_unlock(clicon_handle h,
|
|||
* xml_nsctx_free(nsc);
|
||||
* @endcode
|
||||
* @see clicon_rpc_get_config which is almost the same as with content=config, but you can also select dbname
|
||||
* @see clixon_netconf_error
|
||||
* @see clixon_err_netconf
|
||||
* @note the netconf return message is yang populated, as well as the return data
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get(clicon_handle h,
|
||||
clicon_rpc_get(clixon_handle h,
|
||||
char *xpath,
|
||||
cvec *nsc, /* namespace context for filter */
|
||||
netconf_content content,
|
||||
|
|
@ -984,7 +1005,7 @@ clicon_rpc_get(clicon_handle h,
|
|||
* if (clicon_rpc_get(h, "/hello/world", nsc, CONTENT_ALL, -1, &xt) < 0)
|
||||
* err;
|
||||
* if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
* clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL);
|
||||
* clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
|
||||
* err;
|
||||
* }
|
||||
* if (xt)
|
||||
|
|
@ -993,11 +1014,11 @@ clicon_rpc_get(clicon_handle h,
|
|||
* xml_nsctx_free(nsc);
|
||||
* @endcode
|
||||
* @see clicon_rpc_get_config which is almost the same as with content=config, but you can also select dbname
|
||||
* @see clixon_netconf_error
|
||||
* @see clixon_err_netconf
|
||||
* @note the netconf return message is yang populated, as well as the return data
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get2(clicon_handle h,
|
||||
clicon_rpc_get2(clixon_handle h,
|
||||
char *xpath,
|
||||
cvec *nsc, /* namespace context for filter */
|
||||
netconf_content content,
|
||||
|
|
@ -1022,7 +1043,7 @@ clicon_rpc_get2(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1141,7 +1162,7 @@ clicon_rpc_get2(clicon_handle h,
|
|||
* @note the netconf return message is yang populated, as well as the return data
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get_pageable_list(clicon_handle h,
|
||||
clicon_rpc_get_pageable_list(clixon_handle h,
|
||||
char *datastore,
|
||||
char *xpath,
|
||||
cvec *nsc, /* namespace context for xpath */
|
||||
|
|
@ -1168,13 +1189,13 @@ clicon_rpc_get_pageable_list(clicon_handle h,
|
|||
cvec *nscd = NULL;
|
||||
|
||||
if (datastore == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "datastore not given");
|
||||
clixon_err(OE_XML, EINVAL, "datastore not given");
|
||||
goto done;
|
||||
}
|
||||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1253,7 +1274,7 @@ clicon_rpc_get_pageable_list(clicon_handle h,
|
|||
NULL) < 0)
|
||||
goto done;
|
||||
if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
|
||||
clixon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1293,7 +1314,7 @@ clicon_rpc_get_pageable_list(clicon_handle h,
|
|||
* @note Maybe separate closing session and closing socket.
|
||||
*/
|
||||
int
|
||||
clicon_rpc_close_session(clicon_handle h)
|
||||
clicon_rpc_close_session(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
struct clicon_msg *msg = NULL;
|
||||
|
|
@ -1307,7 +1328,7 @@ clicon_rpc_close_session(clicon_handle h)
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1329,7 +1350,11 @@ clicon_rpc_close_session(clicon_handle h)
|
|||
clicon_client_socket_set(h, -1);
|
||||
}
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Close session");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Close session", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1351,7 +1376,7 @@ clicon_rpc_close_session(clicon_handle h)
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
clicon_rpc_kill_session(clicon_handle h,
|
||||
clicon_rpc_kill_session(clixon_handle h,
|
||||
uint32_t session_id)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1365,7 +1390,7 @@ clicon_rpc_kill_session(clicon_handle h,
|
|||
if (session_id_check(h, &my_session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1383,7 +1408,11 @@ clicon_rpc_kill_session(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Kill session");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Kill session", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1407,7 +1436,7 @@ clicon_rpc_kill_session(clicon_handle h,
|
|||
* @note error returns are logged but not returned
|
||||
*/
|
||||
int
|
||||
clicon_rpc_validate(clicon_handle h,
|
||||
clicon_rpc_validate(clixon_handle h,
|
||||
char *db)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1421,7 +1450,7 @@ clicon_rpc_validate(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1439,7 +1468,11 @@ clicon_rpc_validate(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, CLIXON_ERRSTR_VALIDATE_FAILED);
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, CLIXON_ERRSTR_VALIDATE_FAILED, NULL);
|
||||
#endif
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1469,7 +1502,7 @@ clicon_rpc_validate(clicon_handle h,
|
|||
* @note error returns are logged but not returned
|
||||
*/
|
||||
int
|
||||
clicon_rpc_commit(clicon_handle h,
|
||||
clicon_rpc_commit(clixon_handle h,
|
||||
int confirmed,
|
||||
int cancel,
|
||||
uint32_t timeout,
|
||||
|
|
@ -1489,14 +1522,14 @@ clicon_rpc_commit(clicon_handle h,
|
|||
|
||||
if (persist_id) {
|
||||
if ((persist_id_xml = malloc(strlen(persist_id) + strlen(PERSIST_ID_XML_FMT) + 1)) == NULL) {
|
||||
clicon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
|
||||
clixon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
|
||||
}
|
||||
sprintf(persist_id_xml, PERSIST_ID_XML_FMT, persist_id);
|
||||
}
|
||||
|
||||
if (persist) {
|
||||
if ((persist_xml = malloc(strlen(persist) + strlen(PERSIST_XML_FMT) + 1)) == NULL) {
|
||||
clicon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
|
||||
clixon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
|
||||
};
|
||||
sprintf(persist_xml, PERSIST_XML_FMT, persist);
|
||||
}
|
||||
|
|
@ -1508,7 +1541,7 @@ clicon_rpc_commit(clicon_handle h,
|
|||
*/
|
||||
|
||||
if ((timeout_xml = malloc(10 + 1 + strlen(TIMEOUT_XML_FMT))) == NULL) {
|
||||
clicon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
|
||||
clixon_err(OE_UNIX, 0, "malloc: %s", strerror(errno));
|
||||
};
|
||||
sprintf(timeout_xml, TIMEOUT_XML_FMT, timeout);
|
||||
}
|
||||
|
|
@ -1516,7 +1549,7 @@ clicon_rpc_commit(clicon_handle h,
|
|||
goto done;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1546,7 +1579,11 @@ clicon_rpc_commit(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, CLIXON_ERRSTR_COMMIT_FAILED);
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, CLIXON_ERRSTR_COMMIT_FAILED, NULL);
|
||||
#endif
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1574,7 +1611,7 @@ clicon_rpc_commit(clicon_handle h,
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
clicon_rpc_discard_changes(clicon_handle h)
|
||||
clicon_rpc_discard_changes(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
struct clicon_msg *msg = NULL;
|
||||
|
|
@ -1587,7 +1624,7 @@ clicon_rpc_discard_changes(clicon_handle h)
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1605,7 +1642,11 @@ clicon_rpc_discard_changes(clicon_handle h)
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Discard changes");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Discard changes", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1630,7 +1671,7 @@ clicon_rpc_discard_changes(clicon_handle h)
|
|||
* @note When using netconf create-subsrciption,status and format is not supported
|
||||
*/
|
||||
int
|
||||
clicon_rpc_create_subscription(clicon_handle h,
|
||||
clicon_rpc_create_subscription(clixon_handle h,
|
||||
char *stream,
|
||||
char *filter,
|
||||
int *s0)
|
||||
|
|
@ -1646,7 +1687,7 @@ clicon_rpc_create_subscription(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1670,7 +1711,11 @@ clicon_rpc_create_subscription(clicon_handle h,
|
|||
if (clicon_rpc_msg_persistent(h, msg, &xret, s0) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Create subscription");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Create subscription", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1692,7 +1737,7 @@ clicon_rpc_create_subscription(clicon_handle h,
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
clicon_rpc_debug(clicon_handle h,
|
||||
clicon_rpc_debug(clixon_handle h,
|
||||
int level)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1706,7 +1751,7 @@ clicon_rpc_debug(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1725,11 +1770,15 @@ clicon_rpc_debug(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Debug");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Debug", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
|
||||
clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
|
||||
clixon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1755,7 +1804,7 @@ clicon_rpc_debug(clicon_handle h,
|
|||
* 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf)
|
||||
*/
|
||||
int
|
||||
clicon_rpc_restconf_debug(clicon_handle h,
|
||||
clicon_rpc_restconf_debug(clixon_handle h,
|
||||
int level)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1769,7 +1818,7 @@ clicon_rpc_restconf_debug(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1791,11 +1840,15 @@ clicon_rpc_restconf_debug(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Debug");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Debug", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
|
||||
clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
|
||||
clixon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
|
||||
goto done;
|
||||
}
|
||||
if ((retval = clicon_rpc_commit(h, 0, 0, 0, NULL, NULL)) < 1)
|
||||
|
|
@ -1826,7 +1879,7 @@ clicon_rpc_restconf_debug(clicon_handle h,
|
|||
* Example: cl:cli, cl:restconf, cl:netconf
|
||||
*/
|
||||
int
|
||||
clicon_hello_req(clicon_handle h,
|
||||
clicon_hello_req(clixon_handle h,
|
||||
char *transport,
|
||||
char *source_host,
|
||||
uint32_t *id)
|
||||
|
|
@ -1845,7 +1898,7 @@ clicon_hello_req(clicon_handle h,
|
|||
char *prefix = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<hello xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1880,16 +1933,20 @@ clicon_hello_req(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
#if 1
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Hello");
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Hello", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
if ((x = xpath_first(xret, NULL, "hello/session-id")) == NULL){
|
||||
clicon_err(OE_XML, 0, "hello session-id");
|
||||
clixon_err(OE_XML, 0, "hello session-id");
|
||||
goto done;
|
||||
}
|
||||
b = xml_body(x);
|
||||
if ((ret = parse_uint32(b, id, NULL)) <= 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint32");
|
||||
clixon_err(OE_XML, errno, "parse_uint32");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1911,7 +1968,7 @@ clicon_hello_req(clicon_handle h,
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
clicon_rpc_restart_plugin(clicon_handle h,
|
||||
clicon_rpc_restart_plugin(clixon_handle h,
|
||||
char *plugin)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1925,7 +1982,7 @@ clicon_rpc_restart_plugin(clicon_handle h,
|
|||
if (session_id_check(h, &session_id) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1944,11 +2001,11 @@ clicon_rpc_restart_plugin(clicon_handle h,
|
|||
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
clixon_netconf_error(h, xerr, "Debug", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Debug");
|
||||
goto done;
|
||||
}
|
||||
if (xpath_first(xret, NULL, "//rpc-reply/ok") == NULL){
|
||||
clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
|
||||
clixon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -55,12 +55,13 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_regex.h"
|
||||
|
|
@ -245,7 +246,7 @@ regexp_xsd2posix(char *xsd,
|
|||
size_t len;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
esc=0;
|
||||
|
|
@ -357,7 +358,7 @@ regexp_xsd2posix(char *xsd,
|
|||
cprintf(cb, "%c", x);
|
||||
}
|
||||
if ((*posix = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -382,7 +383,7 @@ regexp_xsd2posix(char *xsd,
|
|||
* translate from XSD to POSIX.
|
||||
*/
|
||||
int
|
||||
regex_compile(clicon_handle h,
|
||||
regex_compile(clixon_handle h,
|
||||
char *regexp,
|
||||
void **recomp)
|
||||
{
|
||||
|
|
@ -399,7 +400,7 @@ regex_compile(clicon_handle h,
|
|||
retval = cligen_regex_libxml2_compile(regexp, recomp);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h));
|
||||
clixon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h));
|
||||
break;
|
||||
}
|
||||
/* retval from fns above */
|
||||
|
|
@ -418,7 +419,7 @@ regex_compile(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
regex_exec(clicon_handle h,
|
||||
regex_exec(clixon_handle h,
|
||||
void *recomp,
|
||||
char *string)
|
||||
{
|
||||
|
|
@ -432,7 +433,7 @@ regex_exec(clicon_handle h,
|
|||
retval = cligen_regex_libxml2_exec(recomp, string);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d",
|
||||
clixon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d",
|
||||
clicon_yang_regexp(h));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -449,7 +450,7 @@ regex_exec(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
regex_free(clicon_handle h,
|
||||
regex_free(clixon_handle h,
|
||||
void *recomp)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -462,7 +463,7 @@ regex_free(clicon_handle h,
|
|||
retval = cligen_regex_libxml2_free(recomp);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h));
|
||||
clixon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h));
|
||||
goto done;
|
||||
}
|
||||
/* retval from fns above */
|
||||
|
|
|
|||
|
|
@ -52,8 +52,12 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_sig.h"
|
||||
|
||||
/*! Set a signal handler.
|
||||
|
|
@ -96,7 +100,7 @@ set_signal_flags(int signo,
|
|||
sigemptyset(&snew.sa_mask);
|
||||
snew.sa_flags = flags;
|
||||
if (sigaction(signo, &snew, &sold) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigaction");
|
||||
clixon_err(OE_UNIX, errno, "sigaction");
|
||||
return -1;
|
||||
}
|
||||
if (oldhandler)
|
||||
|
|
@ -151,12 +155,12 @@ clixon_signal_save(sigset_t *sigset,
|
|||
int i;
|
||||
|
||||
if (sigprocmask(0, NULL, sigset) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigprocmask");
|
||||
clixon_err(OE_UNIX, errno, "sigprocmask");
|
||||
goto done;
|
||||
}
|
||||
for (i=1; i<32; i++){
|
||||
if (sigaction(i, NULL, &sigaction_vec[i]) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigaction");
|
||||
clixon_err(OE_UNIX, errno, "sigaction");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -179,14 +183,14 @@ clixon_signal_restore(sigset_t *sigset,
|
|||
int i;
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, sigset, NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigprocmask");
|
||||
clixon_err(OE_UNIX, errno, "sigprocmask");
|
||||
goto done;
|
||||
}
|
||||
for (i=1; i<32; i++){
|
||||
if (i == SIGKILL || i == SIGSTOP)
|
||||
continue;
|
||||
if (sigaction(i, &sigaction_vec[i], NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sigaction");
|
||||
clixon_err(OE_UNIX, errno, "sigaction");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -253,17 +257,17 @@ pidfile_zapold(pid_t pid)
|
|||
{
|
||||
int retval = -1;
|
||||
|
||||
clicon_log(LOG_NOTICE, "Killing old daemon with pid: %d", pid);
|
||||
clixon_log(NULL, LOG_NOTICE, "Killing old daemon with pid: %d", pid);
|
||||
killpg(pid, SIGTERM);
|
||||
kill(pid, SIGTERM);
|
||||
/* Need to sleep process properly and then check again */
|
||||
if (usleep(100000) < 0){
|
||||
clicon_err(OE_UNIX, errno, "usleep");
|
||||
clixon_err(OE_UNIX, errno, "usleep");
|
||||
goto done;
|
||||
}
|
||||
if ((kill(pid, 0)) < 0){
|
||||
if (errno != ESRCH){
|
||||
clicon_err(OE_DAEMON, errno, "Killing old daemon");
|
||||
clixon_err(OE_DAEMON, errno, "Killing old daemon");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -287,13 +291,13 @@ pidfile_write(char *pidfile)
|
|||
/* Here, there should be no old agent and no pidfile */
|
||||
if ((f = fopen(pidfile, "w")) == NULL){
|
||||
if (errno == EACCES)
|
||||
clicon_err(OE_DAEMON, errno, "Creating pid-file %s (Try run as root?)", pidfile);
|
||||
clixon_err(OE_DAEMON, errno, "Creating pid-file %s (Try run as root?)", pidfile);
|
||||
else
|
||||
clicon_err(OE_DAEMON, errno, "Creating pid-file %s", pidfile);
|
||||
clixon_err(OE_DAEMON, errno, "Creating pid-file %s", pidfile);
|
||||
goto done;
|
||||
}
|
||||
if ((retval = fprintf(f, "%ld\n", (long) getpid())) < 1){
|
||||
clicon_err(OE_DAEMON, errno, "Could not write pid to %s", pidfile);
|
||||
clixon_err(OE_DAEMON, errno, "Could not write pid to %s", pidfile);
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "Opened pidfile %s with pid %d", pidfile, getpid());
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
* +---------------+ +-->| subscription |
|
||||
* / +---------------+
|
||||
* +---------------+ * +---------------+
|
||||
* | clicon_handle |--------->| event_stream |
|
||||
* | clixon_handle |--------->| event_stream |
|
||||
* +---------------+ +---------------+
|
||||
* \ * +---------------+
|
||||
* +-->| replay |
|
||||
|
|
@ -69,13 +69,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_event.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -98,7 +99,7 @@
|
|||
* @retval NULL Not found
|
||||
*/
|
||||
event_stream_t *
|
||||
stream_find(clicon_handle h,
|
||||
stream_find(clixon_handle h,
|
||||
const char *name)
|
||||
{
|
||||
event_stream_t *es0;
|
||||
|
|
@ -125,7 +126,7 @@ stream_find(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
stream_add(clicon_handle h,
|
||||
stream_add(clixon_handle h,
|
||||
const char *name,
|
||||
const char *description,
|
||||
const int replay_enabled,
|
||||
|
|
@ -137,16 +138,16 @@ stream_add(clicon_handle h,
|
|||
if ((es = stream_find(h, name)) != NULL)
|
||||
goto ok;
|
||||
if ((es = malloc(sizeof(event_stream_t))) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(es, 0, sizeof(event_stream_t));
|
||||
if ((es->es_name = strdup(name)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if ((es->es_description = strdup(description)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
es->es_replay_enabled = replay_enabled;
|
||||
|
|
@ -166,7 +167,7 @@ stream_add(clicon_handle h,
|
|||
* @retval 0 OK
|
||||
*/
|
||||
int
|
||||
stream_delete_all(clicon_handle h,
|
||||
stream_delete_all(clixon_handle h,
|
||||
int force)
|
||||
{
|
||||
struct stream_replay *r;
|
||||
|
|
@ -203,7 +204,7 @@ stream_delete_all(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
stream_get_xml(clicon_handle h,
|
||||
stream_get_xml(clixon_handle h,
|
||||
int access,
|
||||
cbuf *cb)
|
||||
{
|
||||
|
|
@ -250,7 +251,7 @@ stream_timer_setup(int fd,
|
|||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h = (clicon_handle)arg;
|
||||
clixon_handle h = (clixon_handle)arg;
|
||||
struct timeval now;
|
||||
struct timeval t;
|
||||
struct timeval t1 = {STREAM_TIMER_TIMEOUT_S, 0};
|
||||
|
|
@ -331,7 +332,7 @@ stream_timer_setup(int fd,
|
|||
* @retval -1 Error, ie no such stream
|
||||
*/
|
||||
struct stream_subscription *
|
||||
stream_ss_add(clicon_handle h,
|
||||
stream_ss_add(clixon_handle h,
|
||||
char *stream,
|
||||
char *xpath,
|
||||
struct timeval *starttime,
|
||||
|
|
@ -344,16 +345,16 @@ stream_ss_add(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((es = stream_find(h, stream)) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "Stream %s not found", stream);
|
||||
clixon_err(OE_CFG, ENOENT, "Stream %s not found", stream);
|
||||
goto done;
|
||||
}
|
||||
if ((ss = malloc(sizeof(*ss))) == NULL){
|
||||
clicon_err(OE_CFG, errno, "malloc");
|
||||
clixon_err(OE_CFG, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(ss, 0, sizeof(*ss));
|
||||
if ((ss->ss_stream = strdup(stream)) == NULL){
|
||||
clicon_err(OE_CFG, errno, "strdup");
|
||||
clixon_err(OE_CFG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if (stoptime)
|
||||
|
|
@ -361,7 +362,7 @@ stream_ss_add(clicon_handle h,
|
|||
if (starttime)
|
||||
ss->ss_starttime = *starttime;
|
||||
if (xpath && (ss->ss_xpath = strdup(xpath)) == NULL){
|
||||
clicon_err(OE_CFG, errno, "strdup");
|
||||
clixon_err(OE_CFG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
ss->ss_fn = fn;
|
||||
|
|
@ -384,7 +385,7 @@ stream_ss_add(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
stream_ss_rm(clicon_handle h,
|
||||
stream_ss_rm(clixon_handle h,
|
||||
event_stream_t *es,
|
||||
struct stream_subscription *ss,
|
||||
int force)
|
||||
|
|
@ -438,7 +439,7 @@ stream_ss_find(event_stream_t *es,
|
|||
* @see stream_ss_delete For single stream
|
||||
*/
|
||||
int
|
||||
stream_ss_delete_all(clicon_handle h,
|
||||
stream_ss_delete_all(clixon_handle h,
|
||||
stream_fn_t fn,
|
||||
void *arg)
|
||||
{
|
||||
|
|
@ -469,7 +470,7 @@ stream_ss_delete_all(clicon_handle h,
|
|||
* @see stream_ss_delete_all (merge with this?)
|
||||
*/
|
||||
int
|
||||
stream_ss_delete(clicon_handle h,
|
||||
stream_ss_delete(clixon_handle h,
|
||||
char *name,
|
||||
stream_fn_t fn,
|
||||
void *arg)
|
||||
|
|
@ -500,12 +501,12 @@ stream_ss_delete(clicon_handle h,
|
|||
* @param[in] tv Timestamp. Dont notify if subscription has stoptime<tv
|
||||
* @param[in] event Notification as xml tree
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
* @see stream_notify
|
||||
* @see stream_ss_timeout where subscriptions are removed if stoptime<now
|
||||
*/
|
||||
static int
|
||||
stream_notify1(clicon_handle h,
|
||||
stream_notify1(clixon_handle h,
|
||||
event_stream_t *es,
|
||||
struct timeval *tv,
|
||||
cxobj *xevent)
|
||||
|
|
@ -546,7 +547,7 @@ stream_notify1(clicon_handle h,
|
|||
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
|
||||
* @param[in] event Notification as format string according to printf(3)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
* if (stream_notify(h, "NETCONF", "<event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>") < 0)
|
||||
* err;
|
||||
|
|
@ -554,7 +555,7 @@ stream_notify1(clicon_handle h,
|
|||
* @see stream_notify1 Internal
|
||||
*/
|
||||
int
|
||||
stream_notify(clicon_handle h,
|
||||
stream_notify(clixon_handle h,
|
||||
char *stream,
|
||||
const char *event, ...)
|
||||
{
|
||||
|
|
@ -576,7 +577,7 @@ stream_notify(clicon_handle h,
|
|||
len = vsnprintf(NULL, 0, event, args) + 1;
|
||||
va_end(args);
|
||||
if ((str = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(str, 0, len);
|
||||
|
|
@ -584,16 +585,16 @@ stream_notify(clicon_handle h,
|
|||
len = vsnprintf(str, len, event, args) + 1;
|
||||
va_end(args);
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No yang spec");
|
||||
clixon_err(OE_YANG, 0, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
gettimeofday(&tv, NULL);
|
||||
if (time2str(&tv, timestr, sizeof(timestr)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "time2str");
|
||||
clixon_err(OE_UNIX, errno, "time2str");
|
||||
goto done;
|
||||
}
|
||||
/* From RFC5277 */
|
||||
|
|
@ -628,11 +629,11 @@ stream_notify(clicon_handle h,
|
|||
* @param[in] stream Name of event stream. CLICON is predefined as LOG stream
|
||||
* @param[in] xml Notification as XML stream. Is copied.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
* @see stream_notify Should be merged with this
|
||||
*/
|
||||
int
|
||||
stream_notify_xml(clicon_handle h,
|
||||
stream_notify_xml(clixon_handle h,
|
||||
char *stream,
|
||||
cxobj *xml)
|
||||
{
|
||||
|
|
@ -650,16 +651,16 @@ stream_notify_xml(clicon_handle h,
|
|||
if ((es = stream_find(h, stream)) == NULL)
|
||||
goto ok;
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No yang spec");
|
||||
clixon_err(OE_YANG, 0, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
gettimeofday(&tv, NULL);
|
||||
if (time2str(&tv, timestr, sizeof(timestr)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "time2str");
|
||||
clixon_err(OE_UNIX, errno, "time2str");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<notification xmlns=\"%s\"><eventTime>%s</eventTime>NULL</notification>",
|
||||
|
|
@ -720,7 +721,7 @@ stream_notify_xml(clicon_handle h,
|
|||
* Assume no future sample timestamps.
|
||||
*/
|
||||
static int
|
||||
stream_replay_notify(clicon_handle h,
|
||||
stream_replay_notify(clixon_handle h,
|
||||
event_stream_t *es,
|
||||
struct stream_subscription *ss)
|
||||
{
|
||||
|
|
@ -775,7 +776,7 @@ stream_replay_add(event_stream_t *es,
|
|||
struct stream_replay *new;
|
||||
|
||||
if ((new = malloc(sizeof *new)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(new, 0, (sizeof *new));
|
||||
|
|
@ -791,7 +792,7 @@ stream_replay_add(event_stream_t *es,
|
|||
* stream and subscription
|
||||
*/
|
||||
struct replay_arg{
|
||||
clicon_handle ra_h;
|
||||
clixon_handle ra_h;
|
||||
char *ra_stream; /* Name of stream - malloced: free by cb */
|
||||
stream_fn_t ra_fn; /* Stream callback */
|
||||
void *ra_arg; /* Argument - typically unique client handle */
|
||||
|
|
@ -844,7 +845,7 @@ stream_replay_cb(int fd,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
stream_replay_trigger(clicon_handle h,
|
||||
stream_replay_trigger(clixon_handle h,
|
||||
char *stream,
|
||||
stream_fn_t fn,
|
||||
void *arg)
|
||||
|
|
@ -854,13 +855,13 @@ stream_replay_trigger(clicon_handle h,
|
|||
struct replay_arg *ra;
|
||||
|
||||
if ((ra = malloc(sizeof(*ra))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(ra, 0, sizeof(*ra));
|
||||
ra->ra_h = h;
|
||||
if ((ra->ra_stream = strdup(stream)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
ra->ra_fn = fn;
|
||||
|
|
@ -987,7 +988,7 @@ url_post(char *url,
|
|||
* @see stream_ss_add
|
||||
*/
|
||||
static int
|
||||
stream_publish_cb(clicon_handle h,
|
||||
stream_publish_cb(clixon_handle h,
|
||||
int op,
|
||||
cxobj *event,
|
||||
void *arg)
|
||||
|
|
@ -1004,17 +1005,17 @@ stream_publish_cb(clicon_handle h,
|
|||
goto ok;
|
||||
/* Create pub url */
|
||||
if ((u = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((pub_prefix = clicon_option_str(h, "CLICON_STREAM_PUB")) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined");
|
||||
clixon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined");
|
||||
goto done;
|
||||
}
|
||||
cprintf(u, "%s/%s", pub_prefix, stream);
|
||||
/* Create XML data as string */
|
||||
if ((d = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(d, event, 0, 0, NULL, -1, 0) < 0)
|
||||
|
|
@ -1041,7 +1042,7 @@ stream_publish_cb(clicon_handle h,
|
|||
/*! Publish all streams on a pubsub channel, eg using SSE
|
||||
*/
|
||||
int
|
||||
stream_publish(clicon_handle h,
|
||||
stream_publish(clixon_handle h,
|
||||
char *stream)
|
||||
{
|
||||
#ifdef CLIXON_PUBLISH_STREAMS
|
||||
|
|
@ -1053,9 +1054,9 @@ stream_publish(clicon_handle h,
|
|||
done:
|
||||
return retval;
|
||||
#else
|
||||
clicon_log(LOG_WARNING, "%s called but CLIXON_PUBLISH_STREAMS not enabled (enable with configure --enable-publish)", __FUNCTION__);
|
||||
clicon_log_init("xpath", LOG_WARNING, CLICON_LOG_STDERR);
|
||||
return 0;
|
||||
clixon_log(h, LOG_WARNING, "%s called but CLIXON_PUBLISH_STREAMS not enabled (enable with configure --enable-publish)", __FUNCTION__);
|
||||
clixon_log_init(h, "xpath", LOG_WARNING, CLIXON_LOG_STDERR);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1066,7 +1067,7 @@ stream_publish_init()
|
|||
int retval = -1;
|
||||
|
||||
if (curl_global_init(CURL_GLOBAL_ALL) != 0){
|
||||
clicon_err(OE_PLUGIN, errno, "curl_global_init");
|
||||
clixon_err(OE_PLUGIN, errno, "curl_global_init");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -47,8 +47,10 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
|
||||
|
|
@ -103,7 +105,7 @@ clicon_strsep(char *string,
|
|||
/* alloc vector and append copy of string */
|
||||
siz = (nvec+1)* sizeof(char*) + strlen(string)+1;
|
||||
if ((vec = (char**)malloc(siz)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(vec, 0, siz);
|
||||
|
|
@ -167,7 +169,7 @@ clixon_string_del_join(char *str1,
|
|||
int len;
|
||||
|
||||
if (str2 == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "str2 is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "str2 is NULL");
|
||||
return NULL;
|
||||
}
|
||||
len = strlen(str2) + 1;
|
||||
|
|
@ -175,7 +177,7 @@ clixon_string_del_join(char *str1,
|
|||
len += strlen(str1);
|
||||
len += strlen(del);
|
||||
if ((str = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
snprintf(str, len, "%s%s%s", (str1 ? str1 : ""), del, str2);
|
||||
|
|
@ -215,21 +217,21 @@ clixon_strsplit(char *string,
|
|||
|
||||
if ((str = strchr(string, delim)) == NULL){
|
||||
if (suffix && (*suffix = strdup(string)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (prefix){
|
||||
if ((*prefix = strdup(string)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
(*prefix)[str-string] = '\0';
|
||||
}
|
||||
str++;
|
||||
if (suffix && (*suffix = strdup(str)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -297,7 +299,7 @@ uri_percent_encode(char **encp,
|
|||
fmtlen = vsnprintf(NULL, 0, fmt, args) + 1;
|
||||
va_end(args);
|
||||
if ((str = malloc(fmtlen)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(str, 0, fmtlen);
|
||||
|
|
@ -310,7 +312,7 @@ uri_percent_encode(char **encp,
|
|||
/* This is max */
|
||||
len = strlen(str)*3+1;
|
||||
if ((enc = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(enc, 0, len);
|
||||
|
|
@ -355,13 +357,13 @@ uri_percent_decode(char *enc,
|
|||
char *ptr;
|
||||
|
||||
if (enc == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "enc is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "enc is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* This is max */
|
||||
len = strlen(enc)+1;
|
||||
if ((str = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(str, 0, len);
|
||||
|
|
@ -435,7 +437,7 @@ xml_chardata_encode(char **escp,
|
|||
fmtlen = vsnprintf(NULL, 0, fmt, args) + 1;
|
||||
va_end(args);
|
||||
if ((str = malloc(fmtlen)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(str, 0, fmtlen);
|
||||
|
|
@ -477,7 +479,7 @@ xml_chardata_encode(char **escp,
|
|||
len++; /* trailing \0 */
|
||||
/* We know length, allocate encoding buffer */
|
||||
if ((esc = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(esc, 0, len);
|
||||
|
|
@ -498,7 +500,7 @@ xml_chardata_encode(char **escp,
|
|||
switch (str[i]){
|
||||
case '&':
|
||||
if ((l=snprintf(&esc[j], 6, "&")) < 0){
|
||||
clicon_err(OE_UNIX, errno, "snprintf");
|
||||
clixon_err(OE_UNIX, errno, "snprintf");
|
||||
goto done;
|
||||
}
|
||||
j += l;
|
||||
|
|
@ -510,14 +512,14 @@ xml_chardata_encode(char **escp,
|
|||
break;
|
||||
}
|
||||
if ((l=snprintf(&esc[j], 5, "<")) < 0){
|
||||
clicon_err(OE_UNIX, errno, "snprintf");
|
||||
clixon_err(OE_UNIX, errno, "snprintf");
|
||||
goto done;
|
||||
}
|
||||
j += l;
|
||||
break;
|
||||
case '>':
|
||||
if ((l=snprintf(&esc[j], 5, ">")) < 0){
|
||||
clicon_err(OE_UNIX, errno, "snprintf");
|
||||
clixon_err(OE_UNIX, errno, "snprintf");
|
||||
goto done;
|
||||
}
|
||||
j += l;
|
||||
|
|
@ -632,7 +634,7 @@ xml_chardata_decode_ampersand(char *str,
|
|||
else if (len > 0 && *p == '#'){
|
||||
p++;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "parse_uint32");
|
||||
clixon_err(OE_UNIX, errno, "parse_uint32");
|
||||
goto done;
|
||||
}
|
||||
if (len > 1 && *p == 'x'){
|
||||
|
|
@ -641,7 +643,7 @@ xml_chardata_decode_ampersand(char *str,
|
|||
}
|
||||
cprintf(cb, "%s", p);
|
||||
if ((ret = parse_uint32(cbuf_get(cb), &code, NULL)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "parse_uint32");
|
||||
clixon_err(OE_UNIX, errno, "parse_uint32");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
|
|
@ -692,7 +694,7 @@ xml_chardata_decode(char **decp,
|
|||
fmtlen = vsnprintf(NULL, 0, fmt, args) + 1;
|
||||
va_end(args);
|
||||
if ((str = malloc(fmtlen)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(str, 0, fmtlen);
|
||||
|
|
@ -705,7 +707,7 @@ xml_chardata_decode(char **decp,
|
|||
* First allocate decoded string, encoded is always >= larger */
|
||||
slen = strlen(str);
|
||||
if ((dec = malloc(slen+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
j = 0;
|
||||
|
|
@ -776,12 +778,12 @@ uri_str2cvec(char *string,
|
|||
cg_var *cv;
|
||||
|
||||
if ((s0 = strdup(string)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto err;
|
||||
}
|
||||
s = s0;
|
||||
if ((cvv = cvec_new(0)) ==NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto err;
|
||||
}
|
||||
while (s != NULL) {
|
||||
|
|
@ -802,11 +804,11 @@ uri_str2cvec(char *string,
|
|||
}
|
||||
else
|
||||
if ((valu = strdup(val)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto err;
|
||||
}
|
||||
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add");
|
||||
goto err;
|
||||
}
|
||||
while ((strlen(s) > 0) && isblank(*s))
|
||||
|
|
@ -818,7 +820,7 @@ uri_str2cvec(char *string,
|
|||
else{
|
||||
if (strlen(s)){
|
||||
if ((cv = cvec_add(cvv, CGV_EMPTY)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add");
|
||||
goto err;
|
||||
}
|
||||
cv_name_set(cv, s);
|
||||
|
|
@ -1069,7 +1071,7 @@ clixon_unicode2utf8_one(uint16_t uc16,
|
|||
int retval = -1;
|
||||
|
||||
if (utflen < 5){
|
||||
clicon_err(OE_UNIX, EINVAL, "Length of utfstr is not >=4");
|
||||
clixon_err(OE_UNIX, EINVAL, "Length of utfstr is not >=4");
|
||||
goto done;
|
||||
}
|
||||
if (uc16<0x80)
|
||||
|
|
@ -1079,11 +1081,11 @@ clixon_unicode2utf8_one(uint16_t uc16,
|
|||
*utfstr++=128+uc16%64;
|
||||
}
|
||||
else if (uc16-0xd800u<0x800){
|
||||
clicon_err(OE_UNIX, EINVAL, "unicode2utf error");
|
||||
clixon_err(OE_UNIX, EINVAL, "unicode2utf error");
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_UNIX, EINVAL, "unicode2utf error");
|
||||
clixon_err(OE_UNIX, EINVAL, "unicode2utf error");
|
||||
goto done;
|
||||
}
|
||||
*utfstr++=0;
|
||||
|
|
@ -1112,11 +1114,11 @@ clixon_unicode2utf8(char *ucstr,
|
|||
uint16_t uc16 = 0;
|
||||
|
||||
if (ucstr == NULL || utfstr == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "input param is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "input param is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((len = strlen(ucstr)) != 4){
|
||||
clicon_err(OE_UNIX, EINVAL, "Length of ucstr is not 4");
|
||||
clixon_err(OE_UNIX, EINVAL, "Length of ucstr is not 4");
|
||||
goto done;
|
||||
}
|
||||
for (i=0; i<len; i++){
|
||||
|
|
@ -1128,7 +1130,7 @@ clixon_unicode2utf8(char *ucstr,
|
|||
else if ('a' <= c && c <= 'f')
|
||||
j = c+10-'a';
|
||||
else{
|
||||
clicon_err(OE_UNIX, 0, "no match");
|
||||
clixon_err(OE_UNIX, 0, "no match");
|
||||
goto done;
|
||||
}
|
||||
if (uc16 != 0)
|
||||
|
|
|
|||
|
|
@ -52,12 +52,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -142,7 +143,7 @@ text2file(cxobj *xn,
|
|||
char *prefix = NULL;
|
||||
#endif
|
||||
if (xn == NULL || fn == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xn or fn is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((yn = xml_spec(xn)) != NULL){
|
||||
|
|
@ -168,7 +169,7 @@ text2file(cxobj *xn,
|
|||
#endif
|
||||
if (yang_keyword_get(yn) == Y_LIST){
|
||||
if ((cvk = yang_cvec_get(yn)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No keys");
|
||||
clixon_err(OE_YANG, 0, "No keys");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -190,7 +191,7 @@ text2file(cxobj *xn,
|
|||
switch (xml_type(xn)){
|
||||
case CX_BODY:{
|
||||
if ((cbb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
value = xml_value(xn);
|
||||
|
|
@ -331,7 +332,7 @@ text2cbuf(cbuf *cb,
|
|||
char *prefix = NULL;
|
||||
|
||||
if (xn == NULL || cb == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xn or cb is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xn or cb is NULL");
|
||||
goto done;
|
||||
}
|
||||
level1 = level*PRETTYPRINT_INDENT;
|
||||
|
|
@ -349,7 +350,7 @@ text2cbuf(cbuf *cb,
|
|||
#endif
|
||||
if (yang_keyword_get(yn) == Y_LIST){
|
||||
if ((cvk = yang_cvec_get(yn)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No keys");
|
||||
clixon_err(OE_YANG, 0, "No keys");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -373,7 +374,7 @@ text2cbuf(cbuf *cb,
|
|||
switch (xml_type(xn)){
|
||||
case CX_BODY:{
|
||||
if ((cbb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
value = xml_value(xn);
|
||||
|
|
@ -800,7 +801,7 @@ text_populate_list(cxobj *xn)
|
|||
continue;
|
||||
xml_flag_reset(xb, XML_FLAG_BODYKEY);
|
||||
if ((cvi = cvec_next(cvk, cvi)) == NULL){
|
||||
clicon_err(OE_XML, 0, "text parser, key and body mismatch");
|
||||
clixon_err(OE_XML, 0, "text parser, key and body mismatch");
|
||||
goto done;
|
||||
}
|
||||
namei = cv_string_get(cvi);
|
||||
|
|
@ -836,7 +837,7 @@ text_populate_list(cxobj *xn)
|
|||
* @param[out] xerr Reason for invalid returned as netconf err msg
|
||||
* @retval 1 OK and valid
|
||||
* @retval 0 Invalid (only if yang spec)
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
* @see _xml_parse for XML variant
|
||||
* @note Parsing requires YANG, which means yb must be YB_MODULE/_NEXT
|
||||
*/
|
||||
|
|
@ -857,7 +858,7 @@ _text_syntax_parse(char *str,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d %s", __FUNCTION__, yb, str);
|
||||
if (yb != YB_MODULE && yb != YB_MODULE_NEXT){
|
||||
clicon_err(OE_YANG, EINVAL, "yb must be YB_MODULE or YB_MODULE_NEXT");
|
||||
clixon_err(OE_YANG, EINVAL, "yb must be YB_MODULE or YB_MODULE_NEXT");
|
||||
return -1;
|
||||
}
|
||||
ts.ts_parse_string = str;
|
||||
|
|
@ -867,9 +868,9 @@ _text_syntax_parse(char *str,
|
|||
if (clixon_text_syntax_parsel_init(&ts) < 0)
|
||||
goto done;
|
||||
if (clixon_text_syntax_parseparse(&ts) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "TEXT SYNTAX error: line %d", ts.ts_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_JSON, 0, "TEXT SYNTAX parser error with no error code (should not happen)");
|
||||
clixon_log(NULL, LOG_NOTICE, "TEXT SYNTAX error: line %d", ts.ts_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_JSON, 0, "TEXT SYNTAX parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -931,7 +932,7 @@ _text_syntax_parse(char *str,
|
|||
* @param[out] xerr Reason for invalid returned as netconf err msg
|
||||
* @retval 1 OK and valid
|
||||
* @retval 0 Invalid (only if yang spec) w xerr set
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
* cxobj *x = NULL;
|
||||
* if (clixon_text_syntax_parse_string(str, YB_MODULE, yspec, &x, &xerr) < 0)
|
||||
|
|
@ -950,7 +951,7 @@ clixon_text_syntax_parse_string(char *str,
|
|||
{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (xt==NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xt is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xt is NULL");
|
||||
return -1;
|
||||
}
|
||||
if (*xt == NULL){
|
||||
|
|
@ -974,7 +975,7 @@ clixon_text_syntax_parse_string(char *str,
|
|||
* @param[out] xerr Reason for invalid returned as netconf err msg
|
||||
* @retval 1 OK and valid
|
||||
* @retval 0 Invalid (only if yang spec) w xerr set
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @code
|
||||
* cxobj *xt = NULL;
|
||||
|
|
@ -1006,18 +1007,18 @@ clixon_text_syntax_parse_file(FILE *fp,
|
|||
int len = 0;
|
||||
|
||||
if (xt == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xt is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xt is NULL");
|
||||
return -1;
|
||||
}
|
||||
if ((textbuf = malloc(textbuflen)) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(textbuf, 0, textbuflen);
|
||||
ptr = textbuf;
|
||||
while (1){
|
||||
if ((ret = fread(&ch, 1, 1, fp)) < 0){
|
||||
clicon_err(OE_XML, errno, "read");
|
||||
clixon_err(OE_XML, errno, "read");
|
||||
break;
|
||||
}
|
||||
if (ret != 0)
|
||||
|
|
@ -1038,7 +1039,7 @@ clixon_text_syntax_parse_file(FILE *fp,
|
|||
oldtextbuflen = textbuflen;
|
||||
textbuflen *= 2;
|
||||
if ((textbuf = realloc(textbuf, textbuflen)) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
memset(textbuf+oldtextbuflen, 0, textbuflen-oldtextbuflen);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -69,13 +69,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_nsctx.h"
|
||||
|
|
@ -96,7 +97,7 @@ clixon_text_syntax_parseerror(void *arg,
|
|||
{
|
||||
clixon_text_syntax_yacc *ts = (clixon_text_syntax_yacc *)arg;
|
||||
|
||||
clicon_err(OE_XML, XMLPARSE_ERRNO, "text_syntax_parse: line %d: %s: at or before: %s",
|
||||
clixon_err(OE_XML, XMLPARSE_ERRNO, "text_syntax_parse: line %d: %s: at or before: %s",
|
||||
ts->ts_linenum,
|
||||
s,
|
||||
clixon_text_syntax_parsetext);
|
||||
|
|
@ -140,7 +141,7 @@ text_create_node(clixon_text_syntax_yacc *ts,
|
|||
/* Silently ignore if module name not found */
|
||||
if ((ymod = yang_find(ts->ts_yspec, Y_MODULE, prefix)) != NULL){
|
||||
if ((ns = yang_find_mynamespace(ymod)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No namespace");
|
||||
clixon_err(OE_YANG, 0, "No namespace");
|
||||
goto done;
|
||||
}
|
||||
/* Set default namespace */
|
||||
|
|
@ -166,7 +167,7 @@ strjoin(char *str0,
|
|||
len0 = str0?strlen(str0):0;
|
||||
len = len0 + strlen(str1) + 1;
|
||||
if ((str0 = realloc(str0, len)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "realloc");
|
||||
clixon_err(OE_YANG, errno, "realloc");
|
||||
return NULL;
|
||||
}
|
||||
strcpy(str0+len0, str1);
|
||||
|
|
|
|||
|
|
@ -59,8 +59,12 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_uid.h"
|
||||
|
||||
/*! Translate group name to gid. Return -1 if error or not found.
|
||||
|
|
@ -83,11 +87,11 @@ group_name2gid(const char *name,
|
|||
gr = &g0;
|
||||
/* This leaks memory in ubuntu */
|
||||
if (getgrnam_r(name, gr, buf, sizeof(buf), >mp) < 0){
|
||||
clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
|
||||
clixon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
|
||||
goto done;
|
||||
}
|
||||
if (gtmp == NULL){
|
||||
clicon_err(OE_UNIX, 0, "No such group: %s", name);
|
||||
clixon_err(OE_UNIX, 0, "No such group: %s", name);
|
||||
goto done;
|
||||
}
|
||||
if (gid)
|
||||
|
|
@ -114,11 +118,11 @@ name2uid(const char *name,
|
|||
struct passwd *pwbufp = NULL;
|
||||
|
||||
if (getpwnam_r(name, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
|
||||
clicon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
|
||||
clixon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
|
||||
goto done;
|
||||
}
|
||||
if (pwbufp == NULL){
|
||||
clicon_err(OE_UNIX, 0, "No such user: %s", name);
|
||||
clixon_err(OE_UNIX, 0, "No such user: %s", name);
|
||||
goto done;
|
||||
}
|
||||
if (uid)
|
||||
|
|
@ -145,17 +149,17 @@ uid2name(const uid_t uid,
|
|||
struct passwd *pwbufp = NULL;
|
||||
|
||||
if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid);
|
||||
clixon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid);
|
||||
goto done;
|
||||
}
|
||||
if (pwbufp == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
|
||||
clixon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (name){
|
||||
if ((*name = strdup(pwbufp->pw_name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,11 +186,11 @@ drop_priv_temp(uid_t new_uid)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid);
|
||||
/* XXX: implicit declaration of function 'setresuid' on travis */
|
||||
if (setresuid(-1, new_uid, geteuid()) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (geteuid() != new_uid){
|
||||
clicon_err(OE_UNIX, errno, "geteuid");
|
||||
clixon_err(OE_UNIX, errno, "geteuid");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -216,17 +220,17 @@ drop_priv_perm(uid_t new_uid)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid);
|
||||
|
||||
if (setresuid(new_uid, new_uid, new_uid) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (getresuid(&ruid, &euid, &suid) < 0){
|
||||
clicon_err(OE_UNIX, errno, "getresuid");
|
||||
clixon_err(OE_UNIX, errno, "getresuid");
|
||||
goto done;
|
||||
}
|
||||
if (ruid != new_uid ||
|
||||
euid != new_uid ||
|
||||
suid != new_uid){
|
||||
clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
clixon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -251,15 +255,15 @@ restore_priv(void)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
|
||||
if (getresuid(&ruid, &euid, &suid) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (setresuid(-1, suid, -1) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (geteuid() != suid){
|
||||
clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
clixon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
|
|
@ -64,6 +63,7 @@
|
|||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_data.h"
|
||||
|
|
@ -147,7 +147,7 @@ validate_leafref(cxobj *xt,
|
|||
goto ok;
|
||||
if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Leafref requires path statement");
|
||||
|
|
@ -158,7 +158,7 @@ validate_leafref(cxobj *xt,
|
|||
goto fail;
|
||||
}
|
||||
if ((path_arg = yang_argument_get(ypath)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No argument for Y_PATH");
|
||||
clixon_err(OE_YANG, 0, "No argument for Y_PATH");
|
||||
goto done;
|
||||
}
|
||||
if ((leafrefbody = xml_body(xt)) == NULL)
|
||||
|
|
@ -176,7 +176,7 @@ validate_leafref(cxobj *xt,
|
|||
}
|
||||
if (i==xlen){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
ymod = ys_module(ys);
|
||||
|
|
@ -246,11 +246,11 @@ validate_identityref(cxobj *xt,
|
|||
yang_stmt *ymod;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Get idref value. Then see if this value is derived from ytype.
|
||||
|
|
@ -368,7 +368,7 @@ validate_identityref(cxobj *xt,
|
|||
* @note Should need a variant accepting cxobj **xret
|
||||
*/
|
||||
int
|
||||
xml_yang_validate_rpc(clicon_handle h,
|
||||
xml_yang_validate_rpc(clixon_handle h,
|
||||
cxobj *xrpc,
|
||||
int expanddefault,
|
||||
cxobj **xret)
|
||||
|
|
@ -380,7 +380,7 @@ xml_yang_validate_rpc(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if (strcmp(xml_name(xrpc), "rpc")){
|
||||
clicon_err(OE_XML, EINVAL, "Expected RPC");
|
||||
clixon_err(OE_XML, EINVAL, "Expected RPC");
|
||||
goto done;
|
||||
}
|
||||
rpcprefix = xml_prefix(xrpc);
|
||||
|
|
@ -423,7 +423,7 @@ xml_yang_validate_rpc(clicon_handle h,
|
|||
}
|
||||
|
||||
int
|
||||
xml_yang_validate_rpc_reply(clicon_handle h,
|
||||
xml_yang_validate_rpc_reply(clixon_handle h,
|
||||
cxobj *xrpc,
|
||||
cxobj **xret)
|
||||
{
|
||||
|
|
@ -435,7 +435,7 @@ xml_yang_validate_rpc_reply(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if (strcmp(xml_name(xrpc), "rpc-reply")){
|
||||
clicon_err(OE_XML, EINVAL, "Expected RPC");
|
||||
clixon_err(OE_XML, EINVAL, "Expected RPC");
|
||||
goto done;
|
||||
}
|
||||
rpcprefix = xml_prefix(xrpc);
|
||||
|
|
@ -661,7 +661,7 @@ check_list_key(cxobj *xt,
|
|||
char *keyname;
|
||||
|
||||
if (yt == NULL || !yang_config(yt) || yang_keyword_get(yt) != Y_LIST){
|
||||
clicon_err(OE_YANG, EINVAL, "yt is not a config true list node");
|
||||
clixon_err(OE_YANG, EINVAL, "yt is not a config true list node");
|
||||
goto done;
|
||||
}
|
||||
yc = NULL;
|
||||
|
|
@ -680,7 +680,7 @@ check_list_key(cxobj *xt,
|
|||
enum rfc_6020 keyw;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
ymod = ys_module(yt);
|
||||
|
|
@ -731,7 +731,7 @@ choice_mandatory_check(cxobj *xt,
|
|||
fail++;
|
||||
if (xret){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Mandatory variable %s in module %s",
|
||||
|
|
@ -901,7 +901,7 @@ check_mandatory(cxobj *xt,
|
|||
int ret;
|
||||
|
||||
if (yt == NULL || !yang_config(yt)){
|
||||
clicon_err(OE_YANG, EINVAL, "yt is not config true");
|
||||
clixon_err(OE_YANG, EINVAL, "yt is not config true");
|
||||
goto done;
|
||||
}
|
||||
if (yang_keyword_get(yt) == Y_LIST){
|
||||
|
|
@ -957,7 +957,7 @@ check_mandatory(cxobj *xt,
|
|||
}
|
||||
if (x == NULL){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Mandatory variable of %s in module %s", xml_name(xt), yang_argument_get(ys_module(yc)));
|
||||
|
|
@ -1002,7 +1002,7 @@ check_mandatory(cxobj *xt,
|
|||
* @note Should need a variant accepting cxobj **xret
|
||||
*/
|
||||
int
|
||||
xml_yang_validate_add(clicon_handle h,
|
||||
xml_yang_validate_add(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj **xret)
|
||||
{
|
||||
|
|
@ -1040,7 +1040,7 @@ xml_yang_validate_add(clicon_handle h,
|
|||
if ((cv0 = yang_cv_get(yt)) == NULL)
|
||||
break;
|
||||
if ((cv = cv_dup(cv0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv_dup");
|
||||
goto done;
|
||||
}
|
||||
/* In the union and leafref case, value is parsed as generic REST type,
|
||||
|
|
@ -1138,7 +1138,7 @@ xml_yang_validate_list_key_only(cxobj *xt,
|
|||
}
|
||||
|
||||
static int
|
||||
xml_yang_validate_leaf_union(clicon_handle h,
|
||||
xml_yang_validate_leaf_union(clixon_handle h,
|
||||
cxobj *xt,
|
||||
yang_stmt *yt,
|
||||
yang_stmt *yrestype,
|
||||
|
|
@ -1219,7 +1219,7 @@ xml_yang_validate_leaf_union(clicon_handle h,
|
|||
* @see xml_yang_validate_rpc
|
||||
*/
|
||||
int
|
||||
xml_yang_validate_all(clicon_handle h,
|
||||
xml_yang_validate_all(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj **xret)
|
||||
{
|
||||
|
|
@ -1249,13 +1249,13 @@ xml_yang_validate_all(clicon_handle h,
|
|||
and !Node has a config sub-statement and it is false */
|
||||
if ((yt = xml_spec(xt)) == NULL){
|
||||
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1) {
|
||||
clicon_log(LOG_WARNING,
|
||||
clixon_log(h, LOG_WARNING,
|
||||
"%s: %d: No YANG spec for %s, validation skipped",
|
||||
__FUNCTION__, __LINE__, xml_name(xt));
|
||||
goto ok;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Failed to find YANG spec of XML node: %s", xml_name(xt));
|
||||
|
|
@ -1274,7 +1274,7 @@ xml_yang_validate_all(clicon_handle h,
|
|||
goto done;
|
||||
if (hit && nr == 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Failed WHEN condition of %s in module %s (WHEN xpath is %s)",
|
||||
|
|
@ -1345,7 +1345,7 @@ xml_yang_validate_all(clicon_handle h,
|
|||
if (!nr){
|
||||
ye = yang_find(yc, Y_ERROR_MESSAGE, NULL);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Failed MUST xpath '%s' of '%s' in module %s",
|
||||
|
|
@ -1398,7 +1398,7 @@ xml_yang_validate_all(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xml_yang_validate_all_top(clicon_handle h,
|
||||
xml_yang_validate_all_top(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj **xret)
|
||||
{
|
||||
|
|
@ -1424,7 +1424,7 @@ xml_yang_validate_all_top(clicon_handle h,
|
|||
* @note Parses cbret which seems one time too many
|
||||
*/
|
||||
int
|
||||
rpc_reply_check(clicon_handle h,
|
||||
rpc_reply_check(clixon_handle h,
|
||||
char *rpcname,
|
||||
cbuf *cbret)
|
||||
{
|
||||
|
|
@ -1435,7 +1435,7 @@ rpc_reply_check(clicon_handle h,
|
|||
yang_stmt *yspec;
|
||||
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No yang spec9");
|
||||
clixon_err(OE_YANG, ENOENT, "No yang spec9");
|
||||
goto done;
|
||||
}
|
||||
/* Validate outgoing RPC */
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
|
|
@ -64,6 +63,7 @@
|
|||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_data.h"
|
||||
|
|
@ -124,7 +124,7 @@ unique_search_xpath(cxobj *x,
|
|||
}
|
||||
(*slen) ++;
|
||||
if (((*svec) = realloc((*svec), (*slen)*sizeof(char*))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "realloc");
|
||||
clixon_err(OE_UNIX, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
(*svec)[(*slen)-1] = bi;
|
||||
|
|
@ -242,7 +242,7 @@ check_unique_list_direct(cxobj *x,
|
|||
goto ok;
|
||||
}
|
||||
if ((vec = calloc(clen*xml_child_nr(xt), sizeof(char*))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
/* A vector is built with key-values, for each iteration check "backward" in the vector
|
||||
|
|
@ -258,7 +258,7 @@ check_unique_list_direct(cxobj *x,
|
|||
* referenced leafs are not taken into account */
|
||||
str = cv_string_get(cvi);
|
||||
if (index(str, '/') != NULL){
|
||||
clicon_err(OE_YANG, 0, "Multiple descendant nodes not allowed (w /)");
|
||||
clixon_err(OE_YANG, 0, "Multiple descendant nodes not allowed (w /)");
|
||||
goto done;
|
||||
}
|
||||
if ((xi = xml_find(x, str)) == NULL)
|
||||
|
|
@ -340,7 +340,7 @@ check_unique_list(cxobj *x,
|
|||
}
|
||||
cvi = cvec_i(cvk, 0);
|
||||
if (cvi == NULL || (xpath0 = cv_string_get(cvi)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No descendant schemanode");
|
||||
clixon_err(OE_YANG, 0, "No descendant schemanode");
|
||||
goto done;
|
||||
}
|
||||
/* Check if direct schmeanode-id , ie not xpath */
|
||||
|
|
|
|||
|
|
@ -58,12 +58,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_options.h" /* xml_bind_yang */
|
||||
|
|
@ -317,7 +318,7 @@ xml_stats(cxobj *xt,
|
|||
cxobj *xc;
|
||||
|
||||
if (xt == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xml node is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xml node is NULL");
|
||||
goto done;
|
||||
}
|
||||
*nrp += 1;
|
||||
|
|
@ -370,7 +371,7 @@ xml_name_set(cxobj *xn,
|
|||
}
|
||||
if (name){
|
||||
if ((xn->x_name = strdup(name)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -405,7 +406,7 @@ xml_prefix_set(cxobj *xn,
|
|||
}
|
||||
if (prefix){
|
||||
if ((xn->x_prefix = strdup(prefix)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -657,7 +658,7 @@ xml_creator_add(cxobj *xn,
|
|||
goto ok;
|
||||
if (xn->x_creators == NULL){
|
||||
if ((xn->x_creators = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
clixon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -750,7 +751,7 @@ xml_creator_copy_one(cxobj *x0,
|
|||
|
||||
if (x0->x_creators)
|
||||
if ((x1->x_creators = cvec_dup(x0->x_creators)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -884,13 +885,13 @@ xml_value_set(cxobj *xn,
|
|||
if (!is_bodyattr(xn))
|
||||
return 0;
|
||||
if (val == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "value is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "value is NULL");
|
||||
goto done;
|
||||
}
|
||||
sz = strlen(val)+1;
|
||||
if (xn->x_value_cb == NULL){
|
||||
if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -919,18 +920,18 @@ xml_value_append(cxobj *xn,
|
|||
if (!is_bodyattr(xn))
|
||||
return 0;
|
||||
if (val == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "value is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "value is NULL");
|
||||
goto done;
|
||||
}
|
||||
sz = strlen(val)+1;
|
||||
if (xn->x_value_cb == NULL){
|
||||
if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (cbuf_append_str(xn->x_value_cb, val) < 0){
|
||||
clicon_err(OE_XML, errno, "cprintf");
|
||||
clixon_err(OE_XML, errno, "cprintf");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1251,7 +1252,7 @@ xml_child_append(cxobj *xp,
|
|||
xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD;
|
||||
xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*));
|
||||
if (xp->x_childvec == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1281,7 +1282,7 @@ xml_child_insert_pos(cxobj *xp,
|
|||
xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD;
|
||||
xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*));
|
||||
if (xp->x_childvec == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1310,7 +1311,7 @@ xml_childvec_set(cxobj *x,
|
|||
if (x->x_childvec)
|
||||
free(x->x_childvec);
|
||||
if ((x->x_childvec = calloc(len, sizeof(cxobj*))) == NULL){
|
||||
clicon_err(OE_XML, errno, "calloc");
|
||||
clixon_err(OE_XML, errno, "calloc");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -1358,7 +1359,7 @@ clixon_child_xvec_append(cxobj *xn,
|
|||
* @param[in] xp The parent where the new xml node will be appended
|
||||
* @param[in] type XML type
|
||||
* @retval xml Created xml object if successful. Free with xml_free()
|
||||
* @retval NULL Error and clicon_err() called
|
||||
* @retval NULL Error and clixon_err() called
|
||||
* @code
|
||||
* cxobj *x;
|
||||
* if ((x = xml_new(name, xparent, CX_ELMNT)) == NULL)
|
||||
|
|
@ -1386,12 +1387,12 @@ xml_new(char *name,
|
|||
sz = sizeof(struct xmlbody);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, EINVAL, "Invalid type: %d", type);
|
||||
clixon_err(OE_XML, EINVAL, "Invalid type: %d", type);
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
if ((x = malloc(sz)) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(x, 0, sz);
|
||||
|
|
@ -1712,7 +1713,7 @@ xml_child_rm(cxobj *xp,
|
|||
if (!is_element(xp))
|
||||
return 0;
|
||||
if ((xc = xml_child_i(xp, i)) == NULL){
|
||||
clicon_err(OE_XML, 0, "Child not found");
|
||||
clixon_err(OE_XML, 0, "Child not found");
|
||||
goto done;
|
||||
}
|
||||
xml_parent_set(xc, NULL);
|
||||
|
|
@ -1833,11 +1834,11 @@ xml_rootchild(cxobj *xp,
|
|||
if (!is_element(xp))
|
||||
return 0;
|
||||
if (xml_parent(xp) != NULL){
|
||||
clicon_err(OE_XML, 0, "Parent is not root");
|
||||
clixon_err(OE_XML, 0, "Parent is not root");
|
||||
goto done;
|
||||
}
|
||||
if ((xc = xml_child_i(xp, i)) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "Child %d of parent %s not found", i, xml_name(xp));
|
||||
clixon_err(OE_XML, ENOENT, "Child %d of parent %s not found", i, xml_name(xp));
|
||||
goto done;
|
||||
}
|
||||
if (xml_child_rm(xp, i) < 0)
|
||||
|
|
@ -1873,7 +1874,7 @@ xml_rootchild_node(cxobj *xp,
|
|||
if (!is_element(xp))
|
||||
return 0;
|
||||
if (xml_parent(xp) != NULL){
|
||||
clicon_err(OE_XML, 0, "Parent is not root");
|
||||
clixon_err(OE_XML, 0, "Parent is not root");
|
||||
goto done;
|
||||
}
|
||||
x = NULL; i = 0;
|
||||
|
|
@ -2213,7 +2214,7 @@ xml_copy_one(cxobj *x0,
|
|||
char *s;
|
||||
|
||||
if (x0 == NULL || x1 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "x0 or x1 is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "x0 or x1 is NULL");
|
||||
goto done;
|
||||
}
|
||||
xml_type_set(x1, xml_type(x0));
|
||||
|
|
@ -2333,7 +2334,7 @@ cxvec_append(cxobj *x,
|
|||
int retval = -1;
|
||||
|
||||
if ((*vec = realloc(*vec, sizeof(cxobj *) * (*len+1))) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
(*vec)[(*len)++] = x;
|
||||
|
|
@ -2370,7 +2371,7 @@ cxvec_prepend(cxobj *x,
|
|||
int retval = -1;
|
||||
|
||||
if ((*vec = realloc(*vec, sizeof(cxobj *) * (*len+1))) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
memmove(&(*vec)[1], &(*vec)[0], sizeof(cxobj *) * (*len));
|
||||
|
|
@ -2587,7 +2588,7 @@ xml_operation(char *opstr,
|
|||
else if (strcmp("none", opstr) == 0)
|
||||
*op = OP_NONE;
|
||||
else{
|
||||
clicon_err(OE_XML, 0, "Bad-attribute operation: %s", opstr);
|
||||
clixon_err(OE_XML, 0, "Bad-attribute operation: %s", opstr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -2648,7 +2649,7 @@ xml_attr_insert2val(char *instr,
|
|||
else if (strcmp("after", instr) == 0)
|
||||
*ins = INS_AFTER;
|
||||
else{
|
||||
clicon_err(OE_XML, 0, "Bad-attribute operation: %s", instr);
|
||||
clixon_err(OE_XML, 0, "Bad-attribute operation: %s", instr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -2698,8 +2699,9 @@ xml_add_attr(cxobj *xn,
|
|||
goto ret;
|
||||
}
|
||||
|
||||
/*! Specialization of clicon_log with xml tree
|
||||
/*! Specialization of clixon_log with xml tree
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] dbglevel
|
||||
* @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG.
|
||||
* @param[in] x XML tree that is logged without prettyprint
|
||||
|
|
@ -2709,9 +2711,10 @@ xml_add_attr(cxobj *xn,
|
|||
* @see clixon_debug_xml which uses debug setting instead of direct syslog
|
||||
*/
|
||||
int
|
||||
clicon_log_xml(int level,
|
||||
cxobj *x,
|
||||
const char *format, ...)
|
||||
clixon_log_xml(clixon_handle h,
|
||||
int level,
|
||||
cxobj *x,
|
||||
const char *format, ...)
|
||||
{
|
||||
int retval = -1;
|
||||
va_list args;
|
||||
|
|
@ -2722,7 +2725,7 @@ clicon_log_xml(int level,
|
|||
|
||||
/* Print xml as cbuf */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, x, 0, 0, NULL, -1, 0) < 0)
|
||||
|
|
@ -2732,12 +2735,12 @@ clicon_log_xml(int level,
|
|||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
/* Truncate long debug strings */
|
||||
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
|
||||
if ((trunc = clixon_log_string_limit_get()) && trunc < len)
|
||||
len = trunc;
|
||||
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -2745,13 +2748,13 @@ clicon_log_xml(int level,
|
|||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
/* Actually log it */
|
||||
clicon_log(level, "%s: %s", msg, cbuf_get(cb));
|
||||
clixon_log(h, level, "%s: %s", msg, cbuf_get(cb));
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -2789,7 +2792,7 @@ clixon_debug_xml(int dbglevel,
|
|||
return 0;
|
||||
/* Print xml as cbuf */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, x, 0, 0, NULL, -1, 0) < 0)
|
||||
|
|
@ -2799,12 +2802,12 @@ clixon_debug_xml(int dbglevel,
|
|||
len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
/* Truncate long debug strings */
|
||||
if ((trunc = clicon_log_string_limit_get()) && trunc < len)
|
||||
if ((trunc = clixon_log_string_limit_get()) && trunc < len)
|
||||
len = trunc;
|
||||
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((msg = malloc(len+1)) == NULL){
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -2812,7 +2815,7 @@ clixon_debug_xml(int dbglevel,
|
|||
va_start(args, format);
|
||||
if (vsnprintf(msg, len+1, format, args) < 0){
|
||||
va_end(args);
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||
fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */
|
||||
goto done;
|
||||
}
|
||||
va_end(args);
|
||||
|
|
@ -2899,12 +2902,12 @@ xml_search_index_add(cxobj *x,
|
|||
struct search_index *si = NULL;
|
||||
|
||||
if ((si = malloc(sizeof(struct search_index))) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(si, 0, sizeof(struct search_index));
|
||||
if ((si->si_name = strdup(name)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
free(si);
|
||||
si = NULL;
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -56,12 +56,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -73,8 +75,6 @@
|
|||
#include "clixon_xml_nsctx.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
#include "clixon_xpath.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_netconf_lib.h"
|
||||
#include "clixon_plugin.h"
|
||||
#include "clixon_xml_sort.h"
|
||||
|
|
@ -140,6 +140,7 @@ strip_body_objects(cxobj *xt)
|
|||
|
||||
/*! Associate XML node x with x:s parents yang:s matching child
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xt XML tree node
|
||||
* @param[in] xsibling
|
||||
* @param[in] yspec Top-level YANG spec / mount-point
|
||||
|
|
@ -152,10 +153,11 @@ strip_body_objects(cxobj *xt)
|
|||
* @see populate_self_top
|
||||
*/
|
||||
static int
|
||||
populate_self_parent(cxobj *xt,
|
||||
cxobj *xsibling,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xerr)
|
||||
populate_self_parent(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xsibling,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xerr)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *y = NULL; /* yang node */
|
||||
|
|
@ -200,13 +202,13 @@ populate_self_parent(cxobj *xt,
|
|||
goto done;
|
||||
xml_spec_set(xt, y);
|
||||
retval = 2; /* treat as anydata */
|
||||
clicon_log(LOG_WARNING,
|
||||
clixon_log(h, LOG_WARNING,
|
||||
"%s: %d: No YANG spec for %s, anydata used",
|
||||
__FUNCTION__, __LINE__, name);
|
||||
goto done;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
|
||||
|
|
@ -228,7 +230,7 @@ populate_self_parent(cxobj *xt,
|
|||
/* Assign spec only if namespaces match */
|
||||
if (strcmp(ns, nsy) != 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Namespace mismatch: %s in XML does not match %s in yang", ns, nsy);
|
||||
|
|
@ -255,6 +257,7 @@ populate_self_parent(cxobj *xt,
|
|||
|
||||
/*! Associate XML node x with yang spec y by going through all top-level modules and finding match
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xt XML tree node
|
||||
* @param[in] yspec Yang spec
|
||||
* @param[out] xerr Reason for failure, or NULL
|
||||
|
|
@ -264,9 +267,10 @@ populate_self_parent(cxobj *xt,
|
|||
* @see populate_self_parent
|
||||
*/
|
||||
static int
|
||||
populate_self_top(cxobj *xt,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xerr)
|
||||
populate_self_top(clixon_handle h,
|
||||
cxobj *xt,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xerr)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *y = NULL; /* yang node */
|
||||
|
|
@ -292,7 +296,7 @@ populate_self_top(cxobj *xt,
|
|||
if (ymod == NULL){
|
||||
if (xerr){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
|
||||
|
|
@ -313,13 +317,13 @@ populate_self_top(cxobj *xt,
|
|||
goto done;
|
||||
xml_spec_set(xt, y);
|
||||
retval = 2; /* treat as anydata */
|
||||
clicon_log(LOG_WARNING,
|
||||
clixon_log(h, LOG_WARNING,
|
||||
"%s: %d: No YANG spec for %s, anydata used",
|
||||
__FUNCTION__, __LINE__, name);
|
||||
goto done;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Failed to find YANG spec of XML node: %s", name);
|
||||
|
|
@ -380,7 +384,7 @@ populate_self_top(cxobj *xt,
|
|||
* @note For subs to anyxml nodes will not have spec set
|
||||
*/
|
||||
int
|
||||
xml_bind_yang(clicon_handle h,
|
||||
xml_bind_yang(clixon_handle h,
|
||||
cxobj *xt,
|
||||
yang_bind yb,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -419,7 +423,7 @@ xml_bind_yang(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
xml_bind_yang0_opt(clicon_handle h,
|
||||
xml_bind_yang0_opt(clixon_handle h,
|
||||
cxobj *xt,
|
||||
yang_bind yb,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -441,15 +445,15 @@ xml_bind_yang0_opt(clicon_handle h,
|
|||
|
||||
switch (yb){
|
||||
case YB_MODULE:
|
||||
if ((ret = populate_self_top(xt, yspec, xerr)) < 0)
|
||||
if ((ret = populate_self_top(h, xt, yspec, xerr)) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case YB_PARENT:
|
||||
if ((ret = populate_self_parent(xt, xsibling, yspec, xerr)) < 0)
|
||||
if ((ret = populate_self_parent(h, xt, xsibling, yspec, xerr)) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
|
||||
clixon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -538,7 +542,7 @@ xml_bind_yang0_opt(clicon_handle h,
|
|||
* @see xml_bind_yang If only children of xt should be populated, not xt itself
|
||||
*/
|
||||
int
|
||||
xml_bind_yang0(clicon_handle h,
|
||||
xml_bind_yang0(clixon_handle h,
|
||||
cxobj *xt,
|
||||
yang_bind yb,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -550,18 +554,18 @@ xml_bind_yang0(clicon_handle h,
|
|||
|
||||
switch (yb){
|
||||
case YB_MODULE:
|
||||
if ((ret = populate_self_top(xt, yspec, xerr)) < 0)
|
||||
if ((ret = populate_self_top(h, xt, yspec, xerr)) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case YB_PARENT:
|
||||
if ((ret = populate_self_parent(xt, NULL, yspec, xerr)) < 0)
|
||||
if ((ret = populate_self_parent(h, xt, NULL, yspec, xerr)) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case YB_NONE:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
|
||||
clixon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -597,7 +601,7 @@ xml_bind_yang0(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
xml_bind_yang_rpc_rpc(clicon_handle h,
|
||||
xml_bind_yang_rpc_rpc(clixon_handle h,
|
||||
cxobj *x,
|
||||
yang_stmt *yrpc,
|
||||
char *rpcname,
|
||||
|
|
@ -617,7 +621,7 @@ xml_bind_yang_rpc_rpc(clicon_handle h,
|
|||
xc = xml_child_i_type(x, 0, CX_ELMNT); /* Pick first */
|
||||
name = xml_name(xc);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Unrecognized parameter: %s in rpc: %s", name, rpcname);
|
||||
|
|
@ -662,7 +666,7 @@ xml_bind_yang_rpc_rpc(clicon_handle h,
|
|||
* XXX if not more action, consider folding into calling function
|
||||
*/
|
||||
static int
|
||||
xml_bind_yang_rpc_action(clicon_handle h,
|
||||
xml_bind_yang_rpc_action(clixon_handle h,
|
||||
cxobj *xn,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xerr)
|
||||
|
|
@ -708,7 +712,7 @@ xml_bind_yang_rpc_action(clicon_handle h,
|
|||
* @see xml_bind_yang_rpc_reply
|
||||
*/
|
||||
int
|
||||
xml_bind_yang_rpc(clicon_handle h,
|
||||
xml_bind_yang_rpc(clixon_handle h,
|
||||
cxobj *xrpc,
|
||||
yang_stmt *yspec,
|
||||
cxobj **xerr)
|
||||
|
|
@ -752,7 +756,7 @@ xml_bind_yang_rpc(clicon_handle h,
|
|||
if (xerr &&
|
||||
netconf_unknown_element_xml(xerr, "protocol", name, "Unrecognized hello element") < 0)
|
||||
goto done;
|
||||
clicon_err(OE_XML, EFAULT, "Unrecognized hello element: %s", name);
|
||||
clixon_err(OE_XML, EFAULT, "Unrecognized hello element: %s", name);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
|
@ -838,7 +842,7 @@ xml_bind_yang_rpc(clicon_handle h,
|
|||
* @see xml_bind_yang For other generic cases
|
||||
*/
|
||||
int
|
||||
xml_bind_yang_rpc_reply(clicon_handle h,
|
||||
xml_bind_yang_rpc_reply(clixon_handle h,
|
||||
cxobj *xrpc,
|
||||
char *name,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -858,7 +862,7 @@ xml_bind_yang_rpc_reply(clicon_handle h,
|
|||
opname = xml_name(xrpc);
|
||||
if (strcmp(opname, "rpc-reply")){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Internal error, unrecognized netconf operation in backend reply, expected rpc-reply but received: %s", opname);
|
||||
|
|
@ -896,7 +900,7 @@ xml_bind_yang_rpc_reply(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Internal error in backend reply: ");
|
||||
|
|
|
|||
|
|
@ -60,10 +60,11 @@
|
|||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_data.h"
|
||||
|
|
@ -79,7 +80,7 @@
|
|||
#include "clixon_xpath.h"
|
||||
|
||||
static int
|
||||
changelog_rename(clicon_handle h,
|
||||
changelog_rename(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xw,
|
||||
cvec *nsc,
|
||||
|
|
@ -90,7 +91,7 @@ changelog_rename(clicon_handle h,
|
|||
char *str = NULL;
|
||||
|
||||
if (tag == NULL){
|
||||
clicon_err(OE_XML, 0, "tag required");
|
||||
clixon_err(OE_XML, 0, "tag required");
|
||||
goto done;
|
||||
}
|
||||
if (xpath_vec_ctx(xw, nsc, tag, 0, &xctx) < 0)
|
||||
|
|
@ -98,7 +99,7 @@ changelog_rename(clicon_handle h,
|
|||
if (ctx2string(xctx, &str) < 0)
|
||||
goto done;
|
||||
if (!strlen(str)){
|
||||
clicon_err(OE_XML, 0, "invalid rename tag: \"%s\"", str);
|
||||
clixon_err(OE_XML, 0, "invalid rename tag: \"%s\"", str);
|
||||
goto done;
|
||||
}
|
||||
if (xml_name_set(xw, str) < 0)
|
||||
|
|
@ -118,7 +119,7 @@ changelog_rename(clicon_handle h,
|
|||
|
||||
/* replace target XML */
|
||||
static int
|
||||
changelog_replace(clicon_handle h,
|
||||
changelog_replace(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xw,
|
||||
cxobj *xnew)
|
||||
|
|
@ -129,7 +130,7 @@ changelog_replace(clicon_handle h,
|
|||
/* create a new node by parsing fttransform string and insert it at
|
||||
target */
|
||||
if (xnew == NULL){
|
||||
clicon_err(OE_XML, 0, "new required");
|
||||
clixon_err(OE_XML, 0, "new required");
|
||||
goto done;
|
||||
}
|
||||
/* replace: remove all children of target */
|
||||
|
|
@ -138,7 +139,7 @@ changelog_replace(clicon_handle h,
|
|||
goto done;
|
||||
/* replace: first single node under <new> */
|
||||
if (xml_child_nr(xnew) != 1){
|
||||
clicon_err(OE_XML, 0, "Single child to <new> required");
|
||||
clixon_err(OE_XML, 0, "Single child to <new> required");
|
||||
goto done;
|
||||
}
|
||||
x = xml_child_i(xnew, 0);
|
||||
|
|
@ -153,7 +154,7 @@ changelog_replace(clicon_handle h,
|
|||
/* create a new node by parsing "new" and insert it at
|
||||
target */
|
||||
static int
|
||||
changelog_insert(clicon_handle h,
|
||||
changelog_insert(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xw,
|
||||
cxobj *xnew)
|
||||
|
|
@ -162,7 +163,7 @@ changelog_insert(clicon_handle h,
|
|||
cxobj *x;
|
||||
|
||||
if (xnew == NULL){
|
||||
clicon_err(OE_XML, 0, "new required");
|
||||
clixon_err(OE_XML, 0, "new required");
|
||||
goto done;
|
||||
}
|
||||
/* replace: add all new children to target */
|
||||
|
|
@ -180,7 +181,7 @@ changelog_insert(clicon_handle h,
|
|||
|
||||
/* delete target */
|
||||
static int
|
||||
changelog_delete(clicon_handle h,
|
||||
changelog_delete(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xw)
|
||||
{
|
||||
|
|
@ -195,7 +196,7 @@ changelog_delete(clicon_handle h,
|
|||
|
||||
/* Move target node to location */
|
||||
static int
|
||||
changelog_move(clicon_handle h,
|
||||
changelog_move(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xw,
|
||||
cvec *nsc,
|
||||
|
|
@ -205,7 +206,7 @@ changelog_move(clicon_handle h,
|
|||
cxobj *xp; /* destination parent node */
|
||||
|
||||
if ((xp = xpath_first(xt, nsc, "%s", dst)) == NULL){
|
||||
clicon_err(OE_XML, 0, "path required");
|
||||
clixon_err(OE_XML, 0, "path required");
|
||||
goto done;
|
||||
}
|
||||
if (xml_addsub(xp, xw) < 0)
|
||||
|
|
@ -226,7 +227,7 @@ changelog_move(clicon_handle h,
|
|||
* @note XXX xn --> xt xpath may not match
|
||||
*/
|
||||
static int
|
||||
changelog_op(clicon_handle h,
|
||||
changelog_op(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xi)
|
||||
|
||||
|
|
@ -293,7 +294,7 @@ changelog_op(clicon_handle h,
|
|||
ret = changelog_move(h, xt, xw, nsc, dst);
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_XML, 0, "Unknown operation: %s", op);
|
||||
clixon_err(OE_XML, 0, "Unknown operation: %s", op);
|
||||
goto done;
|
||||
}
|
||||
if (ret < 0)
|
||||
|
|
@ -326,7 +327,7 @@ changelog_op(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
changelog_iterate(clicon_handle h,
|
||||
changelog_iterate(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xch)
|
||||
|
||||
|
|
@ -373,7 +374,7 @@ changelog_iterate(clicon_handle h,
|
|||
* @see upgrade_callback_register where this function should be registered
|
||||
*/
|
||||
int
|
||||
xml_changelog_upgrade(clicon_handle h,
|
||||
xml_changelog_upgrade(clixon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
|
|
@ -438,7 +439,7 @@ xml_changelog_upgrade(clicon_handle h,
|
|||
/*! Initialize module revision. read changelog, etc
|
||||
*/
|
||||
int
|
||||
clixon_xml_changelog_init(clicon_handle h)
|
||||
clixon_xml_changelog_init(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
char *filename;
|
||||
|
|
@ -452,7 +453,7 @@ clixon_xml_changelog_init(clicon_handle h)
|
|||
yspec = clicon_dbspec_yang(h);
|
||||
if ((filename = clicon_option_str(h, "CLICON_XML_CHANGELOG_FILE")) != NULL){
|
||||
if ((fp = fopen(filename, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "fopen(%s)", filename);
|
||||
clixon_err(OE_UNIX, errno, "fopen(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL) < 0)
|
||||
|
|
@ -465,12 +466,12 @@ clixon_xml_changelog_init(clicon_handle h)
|
|||
goto done;
|
||||
if (ret == 0){ /* validation failed */
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(h, xret, cbret) < 0)
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "validation failed: %s", cbuf_get(cbret));
|
||||
clixon_err(OE_YANG, 0, "validation failed: %s", cbuf_get(cbret));
|
||||
goto done;
|
||||
}
|
||||
if (clicon_xml_changelog_set(h, xt) < 0)
|
||||
|
|
@ -507,7 +508,7 @@ clixon_xml_changelog_init(clicon_handle h)
|
|||
* vec ::= [<a xmlns="urn:example:a"/>, <aaa xmlns="urn:example:a"/>, NULL]
|
||||
*/
|
||||
int
|
||||
xml_namespace_vec(clicon_handle h,
|
||||
xml_namespace_vec(clixon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
cxobj ***vecp,
|
||||
|
|
@ -525,7 +526,7 @@ xml_namespace_vec(clicon_handle h,
|
|||
*/
|
||||
xlen = xml_child_nr_type(xt, CX_ELMNT)+1;
|
||||
if ((xvec = calloc(xlen, sizeof(cxobj*))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
/* Iterate and find xml nodes with assoctaed namespace */
|
||||
|
|
|
|||
|
|
@ -55,13 +55,13 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -143,11 +143,11 @@ xml_default_create(yang_stmt *y,
|
|||
if ((xb = xml_new("body", xc, CX_BODY)) == NULL)
|
||||
goto done;
|
||||
if ((cv = yang_cv_get(y)) == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "No yang cv of %s", yang_argument_get(y));
|
||||
clixon_err(OE_UNIX, ENOENT, "No yang cv of %s", yang_argument_get(y));
|
||||
goto done;
|
||||
}
|
||||
if ((str = cv2str_dup(cv)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
goto done;
|
||||
}
|
||||
if (xml_value_set(xb, str) < 0)
|
||||
|
|
@ -225,7 +225,7 @@ xml_nopresence_try(yang_stmt *yt,
|
|||
yang_stmt *ydef;
|
||||
|
||||
if (yt == NULL || yang_keyword_get(yt) != Y_CONTAINER){
|
||||
clicon_err(OE_XML, EINVAL, "yt argument is not container");
|
||||
clixon_err(OE_XML, EINVAL, "yt argument is not container");
|
||||
goto done;
|
||||
}
|
||||
*createp = 0;
|
||||
|
|
@ -298,7 +298,7 @@ xml_default(yang_stmt *yt,
|
|||
cg_var *cv;
|
||||
|
||||
if (xt == NULL){ /* No xml */
|
||||
clicon_err(OE_XML, EINVAL, "No XML argument");
|
||||
clixon_err(OE_XML, EINVAL, "No XML argument");
|
||||
goto done;
|
||||
}
|
||||
switch (yang_keyword_get(yt)){
|
||||
|
|
@ -321,7 +321,7 @@ xml_default(yang_stmt *yt,
|
|||
if (state && yang_config_ancestor(yc))
|
||||
break;
|
||||
if ((cv = yang_cv_get(yc)) == NULL){
|
||||
clicon_err(OE_YANG,0, "Internal error: yang leaf %s not populated with cv as it should",
|
||||
clixon_err(OE_YANG,0, "Internal error: yang leaf %s not populated with cv as it should",
|
||||
yang_argument_get(yc));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -437,7 +437,7 @@ xml_global_defaults_create(cxobj *xt,
|
|||
yang_stmt *ymod = NULL;
|
||||
|
||||
if (yspec == NULL || yang_keyword_get(yspec) != Y_SPEC){
|
||||
clicon_err(OE_XML, EINVAL, "yspec argument is not yang spec");
|
||||
clixon_err(OE_XML, EINVAL, "yspec argument is not yang spec");
|
||||
goto done;
|
||||
}
|
||||
while ((ymod = yn_each(yspec, ymod)) != NULL)
|
||||
|
|
@ -462,7 +462,7 @@ xml_global_defaults_create(cxobj *xt,
|
|||
* @see xml_default_recurse
|
||||
*/
|
||||
int
|
||||
xml_global_defaults(clicon_handle h,
|
||||
xml_global_defaults(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cvec *nsc,
|
||||
const char *xpath,
|
||||
|
|
|
|||
|
|
@ -57,12 +57,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_options.h"
|
||||
|
|
@ -543,7 +544,7 @@ xmltree2cbuf(cbuf *cb,
|
|||
* @param[out] xerr Reason for failure (yang assignment not made)
|
||||
* @retval 1 Parse OK and all yang assignment made
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 Error with clicon_err called. Includes parse error
|
||||
* @retval -1 Error
|
||||
* @see clixon_xml_parse_file
|
||||
* @see clixon_xml_parse_string
|
||||
* @see _json_parse
|
||||
|
|
@ -578,11 +579,11 @@ _xml_parse(const char *str,
|
|||
return 1; /* OK */
|
||||
}
|
||||
if (xt == NULL){
|
||||
clicon_err(OE_XML, errno, "Unexpected NULL XML");
|
||||
clixon_err(OE_XML, errno, "Unexpected NULL XML");
|
||||
return -1;
|
||||
}
|
||||
if ((xy.xy_parse_string = strdup(str)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
return -1;
|
||||
}
|
||||
xy.xy_xtop = xt;
|
||||
|
|
@ -672,7 +673,7 @@ _xml_parse(const char *str,
|
|||
* @param[out] xerr Pointer to XML error tree, if retval is 0
|
||||
* @retval 1 Parse OK and all yang assignment made
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set
|
||||
* @retval -1 Error with clicon_err called. Includes parse error
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @code
|
||||
* cxobj *xt = NULL;
|
||||
|
|
@ -707,22 +708,22 @@ clixon_xml_parse_file(FILE *fp,
|
|||
int failed = 0;
|
||||
|
||||
if (xt==NULL || fp == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "arg is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "arg is NULL");
|
||||
return -1;
|
||||
}
|
||||
if (yb == YB_MODULE && yspec == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
|
||||
clixon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
|
||||
return -1;
|
||||
}
|
||||
if ((xmlbuf = malloc(xmlbuflen)) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xmlbuf, 0, xmlbuflen);
|
||||
ptr = xmlbuf;
|
||||
while (1){
|
||||
if ((ret = fread(&ch, 1, 1, fp)) < 0){
|
||||
clicon_err(OE_XML, errno, "read");
|
||||
clixon_err(OE_XML, errno, "read");
|
||||
break;
|
||||
}
|
||||
if (ret != 0){
|
||||
|
|
@ -742,7 +743,7 @@ clixon_xml_parse_file(FILE *fp,
|
|||
oldxmlbuflen = xmlbuflen;
|
||||
xmlbuflen *= 2;
|
||||
if ((xmlbuf = realloc(xmlbuf, xmlbuflen)) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xmlbuf+oldxmlbuflen, 0, xmlbuflen-oldxmlbuflen);
|
||||
|
|
@ -769,7 +770,7 @@ clixon_xml_parse_file(FILE *fp,
|
|||
* @param[out] xerr Reason for failure (yang assignment not made) if retval = 0
|
||||
* @retval 1 Parse OK and all yang assignment made
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial), xerr is set
|
||||
* @retval -1 Error with clicon_err called. Includes parse error
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @code
|
||||
* cxobj *xt = NULL;
|
||||
|
|
@ -794,11 +795,11 @@ clixon_xml_parse_string(const char *str,
|
|||
cxobj **xerr)
|
||||
{
|
||||
if (xt==NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xt is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xt is NULL");
|
||||
return -1;
|
||||
}
|
||||
if (yb == YB_MODULE && yspec == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
|
||||
clixon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
|
||||
return -1;
|
||||
}
|
||||
if (*xt == NULL){
|
||||
|
|
@ -819,7 +820,7 @@ clixon_xml_parse_string(const char *str,
|
|||
* @param[in] format Format string for stdarg according to printf(3)
|
||||
* @retval 1 Parse OK and all yang assignment made
|
||||
* @retval 0 Parse OK but yang assigment not made (or only partial)
|
||||
* @retval -1 Error with clicon_err called. Includes parse error
|
||||
* @retval -1 Error
|
||||
*
|
||||
* @code
|
||||
* cxobj *xt = NULL;
|
||||
|
|
@ -847,7 +848,7 @@ clixon_xml_parse_va(yang_bind yb,
|
|||
len = vsnprintf(NULL, 0, format, args) + 1;
|
||||
va_end(args);
|
||||
if ((str = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(str, 0, len);
|
||||
|
|
@ -884,7 +885,7 @@ clixon_xml_attr_copy(cxobj *xin,
|
|||
cxobj *xa;
|
||||
|
||||
if (xin == NULL || xout == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xin or xout NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xin or xout NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((msgid = xml_find_value(xin, name)) != NULL){
|
||||
|
|
|
|||
|
|
@ -56,12 +56,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -72,8 +74,6 @@
|
|||
#include "clixon_xml_nsctx.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
#include "clixon_xpath.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_netconf_lib.h"
|
||||
#include "clixon_xml_sort.h"
|
||||
#include "clixon_yang_type.h"
|
||||
|
|
@ -115,7 +115,7 @@ isxmlns(cxobj *x)
|
|||
* @param[in] ys Yang spec containing type specification of top-node of xt
|
||||
* @param[out] cvv CLIgen variable vector. Should be freed by cvec_free()
|
||||
* @retval 0 Everything OK, cvv allocated and set
|
||||
* @retval -1 Something wrong, clicon_err() called to set error. No cvv returned
|
||||
* @retval -1 Something wrong, clixon_err() called to set error. No cvv returned
|
||||
* @note cvv Should be freed by cvec_free() after use.
|
||||
* 'Not recursive' means that only one level of XML bodies is translated to cvec:s.
|
||||
* If range is wriong (eg 1000 for uint8) a warning is logged, the value is
|
||||
|
|
@ -151,7 +151,7 @@ xml2cvec(cxobj *xt,
|
|||
xc = NULL;
|
||||
/* Tried to allocate whole cvv here, but some cg_vars may be invalid */
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto err;
|
||||
}
|
||||
xc = NULL;
|
||||
|
|
@ -163,17 +163,17 @@ xml2cvec(cxobj *xt,
|
|||
__FUNCTION__, name, yang_argument_get(yt));
|
||||
if ((body = xml_body(xc)) != NULL){
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cv_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cv_new");
|
||||
goto err;
|
||||
}
|
||||
cv_name_set(cv, name);
|
||||
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cv_parse %s",name);
|
||||
clixon_err(OE_PLUGIN, errno, "cv_parse %s",name);
|
||||
goto err;
|
||||
}
|
||||
/* If value is out-of-range, log and skip value, and continue */
|
||||
if (ret == 0){
|
||||
clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
|
||||
clixon_log(NULL, LOG_WARNING, "cv_parse %s: %s", name, reason);
|
||||
if (reason)
|
||||
free(reason);
|
||||
}
|
||||
|
|
@ -185,19 +185,19 @@ xml2cvec(cxobj *xt,
|
|||
else if ((ycv = yang_cv_get(ys)) != NULL){
|
||||
if ((body = xml_body(xc)) != NULL){
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cv_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cv_new");
|
||||
goto err;
|
||||
}
|
||||
if (cv_cp(cv, ycv) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cv_cp");
|
||||
clixon_err(OE_PLUGIN, errno, "cv_cp");
|
||||
goto err;
|
||||
}
|
||||
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cv_parse: %s", name);
|
||||
clixon_err(OE_PLUGIN, errno, "cv_parse: %s", name);
|
||||
goto err;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
|
||||
clixon_log(NULL, LOG_WARNING, "cv_parse %s: %s", name, reason);
|
||||
if (reason)
|
||||
free(reason);
|
||||
}
|
||||
|
|
@ -226,7 +226,7 @@ xml2cvec(cxobj *xt,
|
|||
* @param[in] xt Parent, or NULL
|
||||
* @param[out] xt Pointer to XML tree containing one top node. Should be freed with xml_free
|
||||
* @retval 0 Everything OK, cvv allocated and set
|
||||
* @retval -1 Something wrong, clicon_err() called to set error. No xt returned
|
||||
* @retval -1 Something wrong, clixon_err() called to set error. No xt returned
|
||||
* @see xml2cvec
|
||||
* @see cvec2xml This does more but has an internal xml2cvec translation
|
||||
*/
|
||||
|
|
@ -789,7 +789,7 @@ xml_sanity(cxobj *xt,
|
|||
}
|
||||
name = xml_name(xt);
|
||||
if (strstr(yang_argument_get(ys), name)==NULL){
|
||||
clicon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'",
|
||||
clixon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'",
|
||||
name, yang_argument_get(ys));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -824,7 +824,7 @@ xml_non_config_data(cxobj *xt,
|
|||
if (!yang_config(y)){ /* config == false means state data */
|
||||
if (xerr){ /* behaviour 1: return on error */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "module %s: state data node unexpected", yang_argument_get(ys_module(y)));
|
||||
|
|
@ -875,12 +875,12 @@ xmlns_assign(cxobj *x)
|
|||
char *ns_xml; /* may be null or incorrect */
|
||||
|
||||
if ((y = xml_spec(x)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "XML %s does not have yang spec", xml_name(x));
|
||||
clixon_err(OE_YANG, ENOENT, "XML %s does not have yang spec", xml_name(x));
|
||||
goto done;
|
||||
}
|
||||
/* 1. Check which namespace x should have (via yang). This is correct namespace. */
|
||||
if ((ns_correct = yang_find_mynamespace(y)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "yang node %s does not have namespace", yang_argument_get(y));
|
||||
clixon_err(OE_YANG, ENOENT, "yang node %s does not have namespace", yang_argument_get(y));
|
||||
goto done;
|
||||
}
|
||||
/* 2. Check which namespace x has via its XML tree */
|
||||
|
|
@ -924,7 +924,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
/* Yes, and it has prefix pexist */
|
||||
if (pexist){
|
||||
if ((prefix1 = strdup(pexist)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -936,7 +936,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
/* And copy namespace context from parent to child */
|
||||
if ((nsc0 = nscache_get_all(x1p)) != NULL){
|
||||
if ((nsc = cvec_dup(nsc0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
nscache_replace(x1, nsc);
|
||||
|
|
@ -962,7 +962,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
*/
|
||||
if (isroot){
|
||||
if (prefix0 && (prefix1 = strdup(prefix0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1023,7 +1023,7 @@ assign_namespace_element(cxobj *x0, /* source */
|
|||
if (xml2ns(x0, prefix0, &namespace) < 0)
|
||||
goto done;
|
||||
if (namespace == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "No namespace found for prefix:%s",
|
||||
clixon_err(OE_XML, ENOENT, "No namespace found for prefix:%s",
|
||||
prefix0?prefix0:"NULL");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1136,7 +1136,7 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
char *pxe;
|
||||
|
||||
if (x1 == NULL || xml_type(x1) != CX_ELMNT || y0 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "x1 is NULL or not XML element, or lacks yang spec");
|
||||
clixon_err(OE_XML, EINVAL, "x1 is NULL or not XML element, or lacks yang spec");
|
||||
goto done;
|
||||
}
|
||||
if (x0 == NULL){
|
||||
|
|
@ -1189,7 +1189,7 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
goto done;
|
||||
twophase_len = xml_child_nr(x1);
|
||||
if ((twophase = calloc(twophase_len, sizeof(*twophase))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
i = 0;
|
||||
|
|
@ -1201,12 +1201,12 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
if ((yc = yang_find_datanode(y0, x1cname)) == NULL){
|
||||
if (reason){
|
||||
if ((cbr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbr, "XML node %s/%s has no corresponding yang specification (Invalid XML or wrong Yang spec?", xml_name(x1), x1cname);
|
||||
if ((*reason = strdup(cbuf_get(cbr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1290,12 +1290,12 @@ xml_merge(cxobj *x0,
|
|||
int ret;
|
||||
|
||||
if (x0 == NULL || x1 == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "parameters x0 or x1 is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "parameters x0 or x1 is NULL");
|
||||
goto done;
|
||||
}
|
||||
twophase_len = xml_child_nr(x1);
|
||||
if ((twophase = calloc(twophase_len, sizeof(*twophase))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
/* Loop through children of the modification tree */
|
||||
|
|
@ -1308,7 +1308,7 @@ xml_merge(cxobj *x0,
|
|||
if (ymod == NULL){
|
||||
if (reason &&
|
||||
(*reason = strdup("Namespace not found or yang spec not loaded")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
goto fail;
|
||||
|
|
@ -1317,12 +1317,12 @@ xml_merge(cxobj *x0,
|
|||
if ((yc = yang_find_datanode(ymod, x1cname)) == NULL){
|
||||
if (reason){
|
||||
if ((cbr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbr, "XML node %s/%s has no corresponding yang specification (Invalid XML or wrong Yang spec?)", xml_name(x1), x1cname);
|
||||
if ((*reason = strdup(cbuf_get(cbr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1387,7 +1387,7 @@ yang_valstr2enum(yang_stmt *ytype,
|
|||
yang_stmt *yval;
|
||||
|
||||
if (enumstr == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "str is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "str is NULL");
|
||||
goto done;
|
||||
}
|
||||
while ((yenum = yn_each(ytype, yenum)) != NULL) {
|
||||
|
|
@ -1422,7 +1422,7 @@ yang_enum2valstr(yang_stmt *ytype,
|
|||
yang_stmt *yval;
|
||||
|
||||
if (valstr == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "valstr is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "valstr is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((yenum = yang_find(ytype, Y_ENUM, enumstr)) == NULL)
|
||||
|
|
@ -1477,7 +1477,7 @@ yang_enum_int_value(cxobj *node,
|
|||
NULL, NULL, NULL, NULL, NULL) < 0)
|
||||
goto done;
|
||||
if (yrestype == NULL){
|
||||
clicon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
goto done;
|
||||
}
|
||||
if (yrestype==NULL || strcmp(yang_argument_get(yrestype), "enumeration"))
|
||||
|
|
@ -1870,7 +1870,7 @@ clixon_compare_xmls(cxobj *xc1,
|
|||
snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX");
|
||||
snprintf(filename2, sizeof(filename2), "/tmp/cliconXXXXXX");
|
||||
if ((fd = mkstemp(filename1)) < 0){
|
||||
clicon_err(OE_UNDEF, errno, "tmpfile");
|
||||
clixon_err(OE_UNDEF, errno, "tmpfile");
|
||||
goto done;
|
||||
}
|
||||
if ((f = fdopen(fd, "w")) == NULL)
|
||||
|
|
@ -1890,7 +1890,7 @@ clixon_compare_xmls(cxobj *xc1,
|
|||
close(fd);
|
||||
|
||||
if ((fd = mkstemp(filename2)) < 0){
|
||||
clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno));
|
||||
clixon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno));
|
||||
goto done;
|
||||
}
|
||||
if ((f = fdopen(fd, "w")) == NULL)
|
||||
|
|
@ -1911,7 +1911,7 @@ clixon_compare_xmls(cxobj *xc1,
|
|||
close(fd);
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_CFG, errno, "cbuf_new");
|
||||
clixon_err(OE_CFG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "diff -dU 1 %s %s | grep -v @@ | sed 1,2d",
|
||||
|
|
|
|||
|
|
@ -58,12 +58,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -88,7 +89,7 @@ static int _USE_NAMESPACE_NETCONF_DEFAULT = 0;
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
int
|
||||
xml_nsctx_namespace_netconf_default(clicon_handle h)
|
||||
xml_nsctx_namespace_netconf_default(clixon_handle h)
|
||||
{
|
||||
_USE_NAMESPACE_NETCONF_DEFAULT = clicon_option_bool(h, "CLICON_NAMESPACE_NETCONF_DEFAULT");
|
||||
return 0;
|
||||
|
|
@ -117,7 +118,7 @@ xml_nsctx_init(char *prefix,
|
|||
cvec *cvv = NULL;
|
||||
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
clixon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (ns && xml_nsctx_add(cvv, prefix, ns) < 0)
|
||||
|
|
@ -291,7 +292,7 @@ xml_nsctx_node(cxobj *xn,
|
|||
cvec *nc = NULL;
|
||||
|
||||
if ((nc = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
clixon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml_nsctx_node1(xn, nc) < 0)
|
||||
|
|
@ -341,19 +342,19 @@ xml_nsctx_yang(yang_stmt *yn,
|
|||
char *myprefix;
|
||||
|
||||
if (yang_keyword_get(yn) == Y_SPEC){
|
||||
clicon_err(OE_YANG, EINVAL, "yang spec node is invalid argument");
|
||||
clixon_err(OE_YANG, EINVAL, "yang spec node is invalid argument");
|
||||
goto done;
|
||||
}
|
||||
if ((nc = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
clixon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if ((myprefix = yang_find_myprefix(yn)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "My yang prefix not found");
|
||||
clixon_err(OE_YANG, ENOENT, "My yang prefix not found");
|
||||
goto done;
|
||||
}
|
||||
if ((mynamespace = yang_find_mynamespace(yn)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "My yang namespace not found");
|
||||
clixon_err(OE_YANG, ENOENT, "My yang namespace not found");
|
||||
goto done;
|
||||
}
|
||||
/* Add my prefix and default namespace (from real module) */
|
||||
|
|
@ -363,7 +364,7 @@ xml_nsctx_yang(yang_stmt *yn,
|
|||
goto done;
|
||||
/* Find top-most module or sub-module and get prefixes from that */
|
||||
if ((ymod = ys_module(yn)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "My yang module not found");
|
||||
clixon_err(OE_YANG, ENOENT, "My yang module not found");
|
||||
goto done;
|
||||
}
|
||||
yspec = yang_parent_get(ymod); /* Assume yspec exists */
|
||||
|
|
@ -427,7 +428,7 @@ xml_nsctx_yangspec(yang_stmt *yspec,
|
|||
if (ncp && *ncp)
|
||||
nc = *ncp;
|
||||
else if ((nc = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
clixon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
ymod = NULL;
|
||||
|
|
@ -562,7 +563,7 @@ xml2ns_recurse(cxobj *xt)
|
|||
if (xml2ns(x, prefix, &namespace) < 0)
|
||||
goto done;
|
||||
if (namespace == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x));
|
||||
clixon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -72,11 +72,13 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
|
|
@ -95,7 +97,7 @@ void
|
|||
clixon_xml_parseerror(void *_xy,
|
||||
char *s)
|
||||
{
|
||||
clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s",
|
||||
clixon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s",
|
||||
_XY->xy_linenum,
|
||||
s,
|
||||
clixon_xml_parsetext);
|
||||
|
|
@ -183,7 +185,7 @@ xml_parse_version(clixon_xml_yacc *xy,
|
|||
char *ver)
|
||||
{
|
||||
if(strcmp(ver, "1.0")){
|
||||
clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML version: %s expected 1.0", ver);
|
||||
clixon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML version: %s expected 1.0", ver);
|
||||
free(ver);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -211,7 +213,7 @@ xml_parse_encoding(clixon_xml_yacc *xy,
|
|||
char *enc)
|
||||
{
|
||||
if(strcasecmp(enc, "UTF-8")){
|
||||
clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML encoding: %s expected UTF-8", enc);
|
||||
clixon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML encoding: %s expected UTF-8", enc);
|
||||
free(enc);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -312,7 +314,7 @@ xml_parse_bslash(clixon_xml_yacc *xy,
|
|||
/* Check name or prerix unequal from begin-tag */
|
||||
if (clicon_strcmp(name0, name) ||
|
||||
clicon_strcmp(prefix0, prefix)){
|
||||
clicon_err(OE_XML, XMLPARSE_ERRNO, "Sanity check failed: %s%s%s vs %s%s%s",
|
||||
clixon_err(OE_XML, XMLPARSE_ERRNO, "Sanity check failed: %s%s%s vs %s%s%s",
|
||||
prefix0?prefix0:"", prefix0?":":"", name0,
|
||||
prefix?prefix:"", prefix?":":"", name);
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -54,12 +54,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_nsctx.h"
|
||||
|
|
@ -104,29 +105,29 @@ xml_cv_cache(cxobj *x,
|
|||
if ((cv = xml_cv(x)) != NULL)
|
||||
goto ok;
|
||||
if ((y = xml_spec(x)) == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body);
|
||||
clixon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body);
|
||||
goto done;
|
||||
}
|
||||
if (yang_type_get(y, NULL, &yrestype, &options, NULL, NULL, NULL, &fraction) < 0)
|
||||
goto done;
|
||||
yang2cv_type(yang_argument_get(yrestype), &cvtype);
|
||||
if (cvtype==CGV_ERR){
|
||||
clicon_err(OE_YANG, errno, "yang->cligen type %s mapping failed",
|
||||
clixon_err(OE_YANG, errno, "yang->cligen type %s mapping failed",
|
||||
yang_argument_get(yrestype));
|
||||
goto done;
|
||||
}
|
||||
if ((cv = cv_new(cvtype)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (cvtype == CGV_DEC64)
|
||||
cv_dec64_n_set(cv, fraction);
|
||||
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
||||
clicon_err(OE_YANG, errno, "cv_parse1");
|
||||
clixon_err(OE_YANG, errno, "cv_parse1");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason);
|
||||
clixon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason);
|
||||
goto done;
|
||||
}
|
||||
if (xml_cv_set(x, cv) < 0)
|
||||
|
|
@ -647,7 +648,7 @@ xml_search_indexvar_binary_pos(cxobj *x1,
|
|||
cxobj *xc;
|
||||
|
||||
if (upper < low){ /* beyond range */
|
||||
clicon_err(OE_XML, 0, "low>upper %d %d", low, upper);
|
||||
clixon_err(OE_XML, 0, "low>upper %d %d", low, upper);
|
||||
goto done;
|
||||
}
|
||||
if (low == upper){
|
||||
|
|
@ -656,7 +657,7 @@ xml_search_indexvar_binary_pos(cxobj *x1,
|
|||
}
|
||||
mid = (low + upper) / 2;
|
||||
if (mid >= max){ /* beyond range */
|
||||
clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
|
||||
clixon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
|
||||
goto done;
|
||||
}
|
||||
xc = clixon_xvec_i(ivec, mid);
|
||||
|
|
@ -839,7 +840,7 @@ xml_search_yang(cxobj *xp,
|
|||
int yangi;
|
||||
|
||||
if (xp == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xp is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xp is NULL");
|
||||
goto done;
|
||||
}
|
||||
upper = xml_child_nr(xp);
|
||||
|
|
@ -926,31 +927,31 @@ xml_insert_userorder(cxobj *xp,
|
|||
case INS_AFTER: /* see retval handling different between before and after */
|
||||
if (key_val == NULL)
|
||||
/* shouldnt happen */
|
||||
clicon_err(OE_YANG, 0, "Missing key/value attribute when insert is before");
|
||||
clixon_err(OE_YANG, 0, "Missing key/value attribute when insert is before");
|
||||
else{
|
||||
switch (yang_keyword_get(yn)){
|
||||
case Y_LEAF_LIST:
|
||||
if ((xc = xpath_first(xp, nsc_key, "%s[.='%s']", xml_name(xn), key_val)) == NULL)
|
||||
clicon_err(OE_YANG, 0, "bad-attribute: value, missing-instance: %s", key_val);
|
||||
clixon_err(OE_YANG, 0, "bad-attribute: value, missing-instance: %s", key_val);
|
||||
else {
|
||||
if ((i = xml_child_order(xp, xc)) < 0)
|
||||
clicon_err(OE_YANG, 0, "internal error xpath found but not in child list");
|
||||
clixon_err(OE_YANG, 0, "internal error xpath found but not in child list");
|
||||
else
|
||||
retval = (ins==INS_BEFORE)?i:i+1;
|
||||
}
|
||||
break;
|
||||
case Y_LIST:
|
||||
if ((xc = xpath_first(xp, nsc_key, "%s%s", xml_name(xn), key_val)) == NULL)
|
||||
clicon_err(OE_YANG, 0, "bad-attribute: key, missing-instance: %s", key_val);
|
||||
clixon_err(OE_YANG, 0, "bad-attribute: key, missing-instance: %s", key_val);
|
||||
else {
|
||||
if ((i = xml_child_order(xp, xc)) < 0)
|
||||
clicon_err(OE_YANG, 0, "internal error xpath found but not in child list");
|
||||
clixon_err(OE_YANG, 0, "internal error xpath found but not in child list");
|
||||
else
|
||||
retval = (ins==INS_BEFORE)?i:i+1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_YANG, 0, "insert only for leaf or leaf-list");
|
||||
clixon_err(OE_YANG, 0, "insert only for leaf or leaf-list");
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
|
|
@ -996,7 +997,7 @@ xml_insert2(cxobj *xp,
|
|||
int yi;
|
||||
|
||||
if (low > upper){ /* beyond range */
|
||||
clicon_err(OE_XML, 0, "low>upper %d %d", low, upper);
|
||||
clixon_err(OE_XML, 0, "low>upper %d %d", low, upper);
|
||||
goto done;
|
||||
}
|
||||
if (low == upper){
|
||||
|
|
@ -1005,16 +1006,16 @@ xml_insert2(cxobj *xp,
|
|||
}
|
||||
mid = (low + upper) / 2;
|
||||
if (mid >= xml_child_nr(xp)){ /* beyond range */
|
||||
clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
|
||||
clixon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper);
|
||||
goto done;
|
||||
}
|
||||
xc = xml_child_i(xp, mid);
|
||||
if ((yc = xml_spec(xc)) == NULL){
|
||||
if (xml_type(xc) != CX_ELMNT)
|
||||
clicon_err(OE_XML, 0, "No spec found %s (wrong xml type:%s)",
|
||||
clixon_err(OE_XML, 0, "No spec found %s (wrong xml type:%s)",
|
||||
xml_name(xc), xml_type2str(xml_type(xc)));
|
||||
else
|
||||
clicon_err(OE_XML, 0, "No spec found %s", xml_name(xc));
|
||||
clixon_err(OE_XML, 0, "No spec found %s", xml_name(xc));
|
||||
goto done;
|
||||
}
|
||||
if (yc == yn){ /* Same yang */
|
||||
|
|
@ -1086,11 +1087,11 @@ xml_insert(cxobj *xp,
|
|||
* added as a child
|
||||
*/
|
||||
if (xml_parent(xi) != NULL){
|
||||
clicon_err(OE_XML, 0, "XML node %s should not have parent", xml_name(xi));
|
||||
clixon_err(OE_XML, 0, "XML node %s should not have parent", xml_name(xi));
|
||||
goto done;
|
||||
}
|
||||
if ((y = xml_spec(xi)) == NULL){
|
||||
clicon_err(OE_XML, 0, "No spec found %s", xml_name(xi));
|
||||
clixon_err(OE_XML, 0, "No spec found %s", xml_name(xi));
|
||||
goto done;
|
||||
}
|
||||
upper = xml_child_nr(xp);
|
||||
|
|
@ -1302,7 +1303,7 @@ xml_find_noyang_name(cxobj *xp,
|
|||
char *ns;
|
||||
|
||||
if (name == NULL || ns0 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "name and namespace required");
|
||||
clixon_err(OE_XML, EINVAL, "name and namespace required");
|
||||
goto done;
|
||||
}
|
||||
/* Go through children linearly */
|
||||
|
|
@ -1369,12 +1370,12 @@ xml_find_index_yang(cxobj *xp,
|
|||
char *indexvar = NULL;
|
||||
|
||||
if (xp == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xp is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xp is NULL");
|
||||
goto done;
|
||||
}
|
||||
name = yang_argument_get(yc);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
switch (yang_keyword_get(yc)){
|
||||
|
|
@ -1389,7 +1390,7 @@ xml_find_index_yang(cxobj *xp,
|
|||
i = 0;
|
||||
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
|
||||
if ((kname = cv_name_get(cvi)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "missing yang key name in cvk");
|
||||
clixon_err(OE_YANG, ENOENT, "missing yang key name in cvk");
|
||||
goto done;
|
||||
}
|
||||
/* Parameter in cvk is not key or not in right key order, then we cannot call
|
||||
|
|
@ -1411,7 +1412,7 @@ xml_find_index_yang(cxobj *xp,
|
|||
break;
|
||||
case Y_LEAF_LIST:
|
||||
if (cvec_len(cvk) != 1){
|
||||
clicon_err(OE_YANG, ENOENT, "expected exactly one leaf-list key");
|
||||
clixon_err(OE_YANG, ENOENT, "expected exactly one leaf-list key");
|
||||
goto done;
|
||||
}
|
||||
cvi = cvec_i(cvk, 0);
|
||||
|
|
@ -1455,7 +1456,7 @@ xml_find_index_yang(cxobj *xp,
|
|||
xk = NULL;
|
||||
while ((xk = xml_child_each(xc, xk, CX_ELMNT)) != NULL) {
|
||||
if ((yk = yang_find(yc, Y_LEAF, xml_name(xk))) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "yang spec of key %s not found", xml_name(xk));
|
||||
clixon_err(OE_YANG, ENOENT, "yang spec of key %s not found", xml_name(xk));
|
||||
goto done;
|
||||
}
|
||||
if (xml_spec_set(xk, yk) < 0)
|
||||
|
|
@ -1540,11 +1541,11 @@ clixon_xml_find_index(cxobj *xp,
|
|||
yang_stmt *yc = NULL;
|
||||
|
||||
if (xvec == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "xvec");
|
||||
clixon_err(OE_YANG, EINVAL, "xvec");
|
||||
goto done;
|
||||
}
|
||||
if (name == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "name");
|
||||
clixon_err(OE_YANG, EINVAL, "name");
|
||||
goto done;
|
||||
}
|
||||
if (yp == NULL)
|
||||
|
|
@ -1595,7 +1596,7 @@ clixon_xml_find_pos(cxobj *xp,
|
|||
uint32_t u;
|
||||
|
||||
if (yc == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "yang spec not found");
|
||||
clixon_err(OE_YANG, ENOENT, "yang spec not found");
|
||||
goto done;
|
||||
}
|
||||
name = yang_argument_get(yc);
|
||||
|
|
|
|||
|
|
@ -53,12 +53,13 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_io.h"
|
||||
|
|
@ -101,7 +102,7 @@ clixon_xvec_inc(clixon_xvec *xv)
|
|||
else
|
||||
xv->xv_max += XVEC_MAX_THRESHOLD; /* Add - linear growth */
|
||||
if ((xv->xv_vec = realloc(xv->xv_vec, sizeof(cxobj *) * xv->xv_max)) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -123,7 +124,7 @@ clixon_xvec_new(void)
|
|||
clixon_xvec *xv = NULL;
|
||||
|
||||
if ((xv = malloc(sizeof(*xv))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xv, 0, sizeof(*xv));
|
||||
|
|
@ -151,7 +152,7 @@ clixon_xvec_dup(clixon_xvec *xv0)
|
|||
xv1->xv_vec = NULL;
|
||||
if (xv1->xv_max &&
|
||||
(xv1->xv_vec = calloc(xv1->xv_max, sizeof(cxobj*))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
free(xv1);
|
||||
xv1 = NULL;
|
||||
goto done;
|
||||
|
|
@ -219,7 +220,7 @@ clixon_xvec_extract(clixon_xvec *xv,
|
|||
int retval = -1;
|
||||
|
||||
if (xv == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xv is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "xv is NULL");
|
||||
goto done;
|
||||
}
|
||||
*xvec = xv->xv_vec;
|
||||
|
|
|
|||
|
|
@ -80,13 +80,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_nsctx.h"
|
||||
|
|
@ -245,7 +246,7 @@ xpath_tree_print(FILE *f,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xpath_tree_print0(cb, xs, 0) < 0)
|
||||
|
|
@ -379,7 +380,7 @@ xpath_tree_append(xpath_tree *xt,
|
|||
int retval = -1;
|
||||
|
||||
if ((*vec = realloc(*vec, sizeof(xpath_tree *) * (*len+1))) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
(*vec)[(*len)++] = xt;
|
||||
|
|
@ -559,7 +560,7 @@ xpath_parse(const char *xpath,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
|
||||
if (xpath == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "XPath is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "XPath is NULL");
|
||||
goto done;
|
||||
}
|
||||
xpy.xpy_parse_string = xpath;
|
||||
|
|
@ -570,15 +571,15 @@ xpath_parse(const char *xpath,
|
|||
if (xpath_parse_init(&xpy) < 0)
|
||||
goto done;
|
||||
if (clixon_xpath_parseparse(&xpy) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "XPath error: on line %d", xpy.xpy_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_XML, 0, "XPath parser error with no error code (should not happen)");
|
||||
clixon_log(NULL, LOG_NOTICE, "XPath error: on line %d", xpy.xpy_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_XML, 0, "XPath parser error with no error code (should not happen)");
|
||||
xpath_scan_exit(&xpy);
|
||||
goto done;
|
||||
}
|
||||
if (clixon_debug_get() > 2){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
xpath_tree_print_cb(cb, xpy.xpy_top);
|
||||
|
|
@ -688,13 +689,13 @@ xpath_first(cxobj *xcur,
|
|||
va_end(ap);
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((xpath = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from reason and args */
|
||||
va_start(ap, xpformat);
|
||||
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -747,13 +748,13 @@ xpath_first_localonly(cxobj *xcur,
|
|||
va_end(ap);
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((xpath = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from reason and args */
|
||||
va_start(ap, xpformat);
|
||||
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -771,6 +772,7 @@ xpath_first_localonly(cxobj *xcur,
|
|||
}
|
||||
|
||||
/*! Given XML tree and xpath, returns nodeset as xml node vector
|
||||
*
|
||||
* If result is not nodeset, return empty nodeset
|
||||
* @param[in] xcur xml-tree where to search
|
||||
* @param[in] nsc External XML namespace context, or NULL
|
||||
|
|
@ -811,13 +813,13 @@ xpath_vec(cxobj *xcur,
|
|||
va_end(ap);
|
||||
/* allocate an xpath string exactly fitting the length */
|
||||
if ((xpath = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: actually compute xpath string content */
|
||||
va_start(ap, veclen);
|
||||
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -888,13 +890,13 @@ xpath_vec_flag(cxobj *xcur,
|
|||
va_end(ap);
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((xpath = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from reason and args */
|
||||
va_start(ap, veclen);
|
||||
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -947,13 +949,13 @@ xpath_vec_bool(cxobj *xcur,
|
|||
va_end(ap);
|
||||
/* allocate a message string exactly fitting the message length */
|
||||
if ((xpath = malloc(len+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute write message from reason and args */
|
||||
va_start(ap, xpformat);
|
||||
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1006,7 +1008,7 @@ xpath_traverse_canonical(xpath_tree *xs,
|
|||
// name = xs->xs_s1;
|
||||
if ((namespace = xml_nsctx_get(nsc0, prefix0)) == NULL){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "No namespace found for prefix: %s", prefix0);
|
||||
|
|
@ -1017,7 +1019,7 @@ xpath_traverse_canonical(xpath_tree *xs,
|
|||
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){
|
||||
#if 0 /* Just accept it, see note in xpath2canonical */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "No yang found for namespace: %s", namespace);
|
||||
|
|
@ -1031,7 +1033,7 @@ xpath_traverse_canonical(xpath_tree *xs,
|
|||
else
|
||||
if ((prefix1 = yang_find_myprefix(ymod)) == NULL){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "No prefix found in module: %s", yang_argument_get(ymod));
|
||||
|
|
@ -1046,7 +1048,7 @@ xpath_traverse_canonical(xpath_tree *xs,
|
|||
if (xs->xs_s0)
|
||||
free(xs->xs_s0);
|
||||
if ((xs->xs_s0 = strdup(prefix1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1139,14 +1141,14 @@ xpath2canonical(const char *xpath0,
|
|||
goto fail;
|
||||
/* Print tree with new prefixes */
|
||||
if ((xcb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xpath_tree2cbuf(xpt, xcb) < 0)
|
||||
goto done;
|
||||
if (xpath1){
|
||||
if ((*xpath1 = strdup(cbuf_get(xcb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1189,7 +1191,7 @@ xpath_count(cxobj *xcur,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "count(%s)", xpath);
|
||||
|
|
@ -1292,7 +1294,7 @@ xml2xpath1(cxobj *x,
|
|||
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
|
||||
keyname = cv_string_get(cvi);
|
||||
if ((xkey = xml_find(x, keyname)) == NULL){
|
||||
clicon_err(OE_XML, 0, "No key %s in list %s", keyname, xml_name(x));
|
||||
clixon_err(OE_XML, 0, "No key %s in list %s", keyname, xml_name(x));
|
||||
goto done;
|
||||
}
|
||||
if ((xb = xml_find(x, keyname)) == NULL)
|
||||
|
|
@ -1358,7 +1360,7 @@ xml2xpath(cxobj *x,
|
|||
char *xpath = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml2xpath1(x, nsc, spec, apostrophe, cb) < 0)
|
||||
|
|
@ -1367,7 +1369,7 @@ xml2xpath(cxobj *x,
|
|||
xpath = cbuf_get(cb);
|
||||
if (xpathp){
|
||||
if ((*xpathp = strdup(xpath)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
xpath = NULL;
|
||||
|
|
@ -1388,7 +1390,7 @@ xml2xpath(cxobj *x,
|
|||
* @param[out] xerr Netconf error message (if retval=0)
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid xpath
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error, clixon_err called
|
||||
* @see xpath_traverse_canonical
|
||||
*/
|
||||
static int
|
||||
|
|
@ -1419,7 +1421,7 @@ xpath2xml_traverse(xpath_tree *xs,
|
|||
name = xs->xs_s1;
|
||||
if ((namespace = xml_nsctx_get(nsc, prefix)) == NULL){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "No namespace found for prefix: %s", prefix);
|
||||
|
|
@ -1498,7 +1500,7 @@ xpath2xml_traverse(xpath_tree *xs,
|
|||
* @param[out] xerr Netconf error message (if retval=0)
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid xpath
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error, clixon_err called
|
||||
* @see api_path2xml
|
||||
* @see xml2xpath
|
||||
* @note xpath is restricted to absolute paths, and simple expressions, eg as "node-identifier"
|
||||
|
|
@ -1518,7 +1520,7 @@ xpath2xml(char *xpath,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s xpath:%s", __FUNCTION__, xpath);
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (*xpath != '/'){
|
||||
|
|
|
|||
|
|
@ -50,13 +50,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
|
|
@ -93,21 +94,21 @@ ctx_dup(xp_ctx *xc0)
|
|||
xp_ctx *xc = NULL;
|
||||
|
||||
if ((xc = malloc(sizeof(*xc))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xc, 0, sizeof(*xc));
|
||||
*xc = *xc0;
|
||||
if (xc0->xc_size){
|
||||
if ((xc->xc_nodeset = calloc(xc0->xc_size, sizeof(cxobj*))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
memcpy(xc->xc_nodeset, xc0->xc_nodeset, xc->xc_size*sizeof(cxobj*));
|
||||
}
|
||||
if (xc0->xc_string)
|
||||
if ((xc->xc_string = strdup(xc0->xc_string)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
|
|
@ -173,7 +174,7 @@ ctx_print(FILE *f,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
ctx_print_cb(cb, xc, 0, str);
|
||||
|
|
@ -238,19 +239,19 @@ ctx2string(xp_ctx *xc,
|
|||
case XT_NODESET:
|
||||
if (xc->xc_size && (b = xml_body(xc->xc_nodeset[0]))){
|
||||
if ((str = strdup(b)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else
|
||||
if ((str = strdup("")) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case XT_BOOL:
|
||||
if ((str = strdup(xc->xc_bool == 0?"false":"true")) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -258,14 +259,14 @@ ctx2string(xp_ctx *xc,
|
|||
len = snprintf(NULL, 0, "%0lf", xc->xc_number);
|
||||
len++;
|
||||
if ((str = malloc(len)) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
snprintf(str, len, "%0lf", xc->xc_number);
|
||||
break;
|
||||
case XT_STRING:
|
||||
if ((str = strdup(xc->xc_string)) == NULL){
|
||||
clicon_err(OE_XML, errno, "strdup");
|
||||
clixon_err(OE_XML, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -72,13 +72,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_yang_type.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -429,7 +430,7 @@ xp_eval_step(xp_ctx *xc0,
|
|||
case A_SELF:
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "No such axisname: %d", xs->xs_int);
|
||||
clixon_err(OE_XML, 0, "No such axisname: %d", xs->xs_int);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -442,7 +443,7 @@ xp_eval_step(xp_ctx *xc0,
|
|||
xc = NULL;
|
||||
}
|
||||
if (*xrp == NULL){
|
||||
clicon_err(OE_XML, 0, "Internal error xrp is NULL");
|
||||
clixon_err(OE_XML, 0, "Internal error xrp is NULL");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -507,7 +508,7 @@ xp_eval_predicate(xp_ctx *xc,
|
|||
* XXX: alt to check xr0 is nodeset: set new var nodeset to NULL
|
||||
*/
|
||||
if ((xr1 = malloc(sizeof(*xr1))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr1, 0, sizeof(*xr1));
|
||||
|
|
@ -518,7 +519,7 @@ xp_eval_predicate(xp_ctx *xc,
|
|||
x = xr0->xc_nodeset[i];
|
||||
/* Create new context */
|
||||
if ((xcc = malloc(sizeof(*xcc))) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xcc, 0, sizeof(*xcc));
|
||||
|
|
@ -553,7 +554,7 @@ xp_eval_predicate(xp_ctx *xc,
|
|||
}
|
||||
}
|
||||
if (xr0 == NULL && xr1 == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
|
||||
clixon_err(OE_XML, EFAULT, "Internal error: no result produced");
|
||||
goto done;
|
||||
}
|
||||
if (xr1){
|
||||
|
|
@ -597,7 +598,7 @@ xp_logop(xp_ctx *xc1,
|
|||
int b2;
|
||||
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -615,7 +616,7 @@ xp_logop(xp_ctx *xc1,
|
|||
xr->xc_bool = b1 || b2;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
|
||||
clixon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
|
||||
__FUNCTION__, clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -648,7 +649,7 @@ xp_numop(xp_ctx *xc1,
|
|||
double n2;
|
||||
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -678,7 +679,7 @@ xp_numop(xp_ctx *xc1,
|
|||
xr->xc_number = n1-n2;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_UNIX, errno, "Invalid operator %s in this context",
|
||||
clixon_err(OE_UNIX, errno, "Invalid operator %s in this context",
|
||||
clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -719,29 +720,29 @@ xml_cv_cache(cxobj *x,
|
|||
if ((cv = xml_cv(x)) != NULL)
|
||||
goto ok;
|
||||
if ((y = xml_spec(x)) == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body);
|
||||
clixon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body);
|
||||
goto done;
|
||||
}
|
||||
if (yang_type_get(y, NULL, &yrestype, &options, NULL, NULL, NULL, &fraction) < 0)
|
||||
goto done;
|
||||
yang2cv_type(yang_argument_get(yrestype), &cvtype);
|
||||
if (cvtype==CGV_ERR){
|
||||
clicon_err(OE_YANG, errno, "yang->cligen type %s mapping failed",
|
||||
clixon_err(OE_YANG, errno, "yang->cligen type %s mapping failed",
|
||||
yang_argument_get(yrestype));
|
||||
goto done;
|
||||
}
|
||||
if ((cv = cv_new(cvtype)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (cvtype == CGV_DEC64)
|
||||
cv_dec64_n_set(cv, fraction);
|
||||
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
||||
clicon_err(OE_YANG, errno, "cv_parse1");
|
||||
clixon_err(OE_YANG, errno, "cv_parse1");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason);
|
||||
clixon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason);
|
||||
goto done;
|
||||
}
|
||||
if (xml_cv_set(x, cv) < 0)
|
||||
|
|
@ -803,11 +804,11 @@ xp_relop(xp_ctx *xc1,
|
|||
int ret;
|
||||
|
||||
if (xc1 == NULL || xc2 == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -865,7 +866,7 @@ xp_relop(xp_ctx *xc1,
|
|||
xr->xc_bool = (ret > 0);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
|
||||
clixon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -891,7 +892,7 @@ xp_relop(xp_ctx *xc1,
|
|||
xr->xc_bool = (strcmp(s1, s2)>0);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
|
||||
clixon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -927,7 +928,7 @@ xp_relop(xp_ctx *xc1,
|
|||
xr->xc_bool = (xc1->xc_number > xc2->xc_number);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
|
||||
clixon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -939,7 +940,7 @@ xp_relop(xp_ctx *xc1,
|
|||
}
|
||||
else if (xc1->xc_type != XT_NODESET &&
|
||||
xc2->xc_type != XT_NODESET){
|
||||
clicon_err(OE_XML, 0, "Mixed types not supported, %d %d", xc1->xc_type, xc2->xc_type);
|
||||
clixon_err(OE_XML, 0, "Mixed types not supported, %d %d", xc1->xc_type, xc2->xc_type);
|
||||
goto done;
|
||||
}
|
||||
else{ /* one is nodeset, ie (1) above */
|
||||
|
|
@ -964,7 +965,7 @@ xp_relop(xp_ctx *xc1,
|
|||
xr->xc_bool = (b != xc2->xc_bool);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and bool", clicon_int2str(xpopmap,op));
|
||||
clixon_err(OE_XML, 0, "Operator %s not supported for nodeset and bool", clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
break;
|
||||
} /* switch op */
|
||||
|
|
@ -1008,7 +1009,7 @@ xp_relop(xp_ctx *xc1,
|
|||
xr->xc_bool = (strcmp(s1, s2));
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and string", clicon_int2str(xpopmap,op));
|
||||
clixon_err(OE_XML, 0, "Operator %s not supported for nodeset and string", clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1044,7 +1045,7 @@ xp_relop(xp_ctx *xc1,
|
|||
xr->xc_bool = reverse?(n2 > n1):(n1 > n2);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and number", clicon_int2str(xpopmap,op));
|
||||
clixon_err(OE_XML, 0, "Operator %s not supported for nodeset and number", clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1053,7 +1054,7 @@ xp_relop(xp_ctx *xc1,
|
|||
}
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Type %d not supported", xc2->xc_type);
|
||||
clixon_err(OE_XML, 0, "Type %d not supported", xc2->xc_type);
|
||||
} /* switch type */
|
||||
}
|
||||
ok:
|
||||
|
|
@ -1090,12 +1091,12 @@ xp_union(xp_ctx *xc1,
|
|||
int i;
|
||||
|
||||
if (op != XO_UNION){
|
||||
clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
|
||||
clixon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
|
||||
__FUNCTION__, clicon_int2str(xpopmap,op));
|
||||
goto done;
|
||||
}
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -1245,7 +1246,7 @@ xp_eval(xp_ctx *xc,
|
|||
goto ok;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, EFAULT, "XPath function not implemented: %s", xs->xs_s0);
|
||||
clixon_err(OE_XML, EFAULT, "XPath function not implemented: %s", xs->xs_s0);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1286,7 +1287,7 @@ xp_eval(xp_ctx *xc,
|
|||
/* Special case, no c0 or c1, single "/" */
|
||||
if (xs->xs_c0 == NULL){
|
||||
if ((xr0 = malloc(sizeof(*xr0))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr0, 0, sizeof(*xr0));
|
||||
|
|
@ -1316,7 +1317,7 @@ xp_eval(xp_ctx *xc,
|
|||
break;
|
||||
case XP_PRIME_NR: /* primaryexpr -> [<number>] */
|
||||
if ((xr0 = malloc(sizeof(*xr0))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr0, 0, sizeof(*xr0));
|
||||
|
|
@ -1326,7 +1327,7 @@ xp_eval(xp_ctx *xc,
|
|||
break;
|
||||
case XP_PRIME_STR:
|
||||
if ((xr0 = malloc(sizeof(*xr0))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr0, 0, sizeof(*xr0));
|
||||
|
|
@ -1370,7 +1371,7 @@ xp_eval(xp_ctx *xc,
|
|||
else
|
||||
xc->xc_descendant = 0;
|
||||
if (xr0 == NULL && xr1 == NULL && xr2 == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
|
||||
clixon_err(OE_XML, EFAULT, "Internal error: no result produced");
|
||||
goto done;
|
||||
}
|
||||
if (xr2){
|
||||
|
|
|
|||
|
|
@ -54,13 +54,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_yang_type.h"
|
||||
|
|
@ -281,7 +282,7 @@ derived_from_one(char *baseidentity,
|
|||
else {
|
||||
/* Allocate cbuf */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
|
||||
|
|
@ -337,7 +338,7 @@ xp_function_derived_from(xp_ctx *xc,
|
|||
int ret = 0;
|
||||
|
||||
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments");
|
||||
clixon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments");
|
||||
goto done;
|
||||
}
|
||||
/* contains two arguments in xs: boolean derived-from(node-set, string) */
|
||||
|
|
@ -353,7 +354,7 @@ xp_function_derived_from(xp_ctx *xc,
|
|||
goto done;
|
||||
/* Allocate a return struct of type boolean */
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -415,7 +416,7 @@ xp_function_bit_is_set(xp_ctx *xc,
|
|||
char *body;
|
||||
|
||||
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
|
||||
clixon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
|
||||
goto done;
|
||||
}
|
||||
/* First node-set argument */
|
||||
|
|
@ -427,7 +428,7 @@ xp_function_bit_is_set(xp_ctx *xc,
|
|||
if (ctx2string(xr1, &s1) < 0)
|
||||
goto done;
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -475,7 +476,7 @@ xp_function_position(xp_ctx *xc,
|
|||
xp_ctx *xr = NULL;
|
||||
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -504,13 +505,13 @@ xp_function_count(xp_ctx *xc,
|
|||
xp_ctx *xr0 = NULL;
|
||||
|
||||
if (xs == NULL || xs->xs_c0 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "count expects but did not get one argument");
|
||||
clixon_err(OE_XML, EINVAL, "count expects but did not get one argument");
|
||||
goto done;
|
||||
}
|
||||
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
|
||||
goto done;
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -546,13 +547,13 @@ xp_function_name(xp_ctx *xc,
|
|||
cxobj *x;
|
||||
|
||||
if (xs == NULL || xs->xs_c0 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
|
||||
clixon_err(OE_XML, EINVAL, "not expects but did not get one argument");
|
||||
goto done;
|
||||
}
|
||||
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
|
||||
goto done;
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -561,7 +562,7 @@ xp_function_name(xp_ctx *xc,
|
|||
if ((x = xr0->xc_nodeset[i]) == NULL)
|
||||
continue;
|
||||
if ((xr->xc_string = strdup(xml_name(x))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -602,7 +603,7 @@ xp_function_contains(xp_ctx *xc,
|
|||
char *s1 = NULL;
|
||||
|
||||
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
|
||||
clixon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
|
||||
goto done;
|
||||
}
|
||||
/* contains two arguments in xs: boolean contains(string, string) */
|
||||
|
|
@ -615,7 +616,7 @@ xp_function_contains(xp_ctx *xc,
|
|||
if (ctx2string(xr1, &s1) < 0)
|
||||
goto done;
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -659,14 +660,14 @@ xp_function_boolean(xp_ctx *xc,
|
|||
int bool;
|
||||
|
||||
if (xs == NULL || xs->xs_c0 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
|
||||
clixon_err(OE_XML, EINVAL, "not expects but did not get one argument");
|
||||
goto done;
|
||||
}
|
||||
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
|
||||
goto done;
|
||||
bool = ctx2boolean(xr0);
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -712,7 +713,7 @@ xp_function_true(xp_ctx *xc,
|
|||
xp_ctx *xr = NULL;
|
||||
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
@ -739,7 +740,7 @@ xp_function_false(xp_ctx *xc,
|
|||
xp_ctx *xr = NULL;
|
||||
|
||||
if ((xr = malloc(sizeof(*xr))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xr, 0, sizeof(*xr));
|
||||
|
|
|
|||
|
|
@ -54,13 +54,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_vec.h"
|
||||
|
|
@ -194,7 +195,7 @@ loop_preds(xpath_tree *xt,
|
|||
if (veclen != 2)
|
||||
goto ok;
|
||||
if ((cvi = cvec_add(cvk, CGV_STRING)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_add");
|
||||
clixon_err(OE_XML, errno, "cvec_add");
|
||||
goto done;
|
||||
}
|
||||
cv_name_set(cvi, vec[0]->xs_s1);
|
||||
|
|
@ -285,7 +286,7 @@ xpath_list_optimize_fn(xpath_tree *xt,
|
|||
goto ok;
|
||||
xtp = vec[1];
|
||||
if ((cvk = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_new");
|
||||
clixon_err(OE_YANG, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = loop_preds(xtp, xem, cvk)) < 0)
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ There are some special lexical rules in https://www.w3.org/TR/xpath-10
|
|||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@
|
|||
/* typecast macro */
|
||||
#define _XPY ((clixon_xpath_yacc *)_xpy)
|
||||
|
||||
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_xpath_parsetext, _XPY->xpy_linenum); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_xpath_parsetext, _XPY->xpy_linenum); YYERROR;}
|
||||
|
||||
/* add _yy to error parameters */
|
||||
#define YY_(msgid) msgid
|
||||
|
|
@ -118,12 +118,13 @@
|
|||
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
|
|
@ -157,7 +158,7 @@ clixon_xpath_parseerror(void *_xpy,
|
|||
char *s)
|
||||
{
|
||||
errno = 0;
|
||||
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", /* Note lineno here is xpath, not yang */
|
||||
clixon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", /* Note lineno here is xpath, not yang */
|
||||
_XPY->xpy_name,
|
||||
_XPY->xpy_linenum,
|
||||
s,
|
||||
|
|
@ -168,7 +169,6 @@ clixon_xpath_parseerror(void *_xpy,
|
|||
int
|
||||
xpath_parse_init(clixon_xpath_yacc *xpy)
|
||||
{
|
||||
// clixon_debug_init(3, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ xp_new(enum xp_type type,
|
|||
xpath_tree *xs = NULL;
|
||||
|
||||
if ((xs = malloc(sizeof(xpath_tree))) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xs, 0, sizeof(*xs));
|
||||
|
|
@ -209,7 +209,7 @@ xp_new(enum xp_type type,
|
|||
if (numstr){
|
||||
xs->xs_strnr = numstr;
|
||||
if (sscanf(numstr, "%lf", &xs->xs_double) == EOF){
|
||||
clicon_err(OE_XML, errno, "sscanf");
|
||||
clixon_err(OE_XML, errno, "sscanf");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -242,7 +242,7 @@ xp_primary_function(clixon_xpath_yacc *xpy,
|
|||
|
||||
if ((ret = xp_fnname_str2int(name)) < 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Unknown xpath function \"%s\"", name);
|
||||
|
|
@ -273,7 +273,7 @@ xp_primary_function(clixon_xpath_yacc *xpy,
|
|||
case XPATHFN_CEILING:
|
||||
case XPATHFN_ROUND:
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "XPath function \"%s\" is not implemented", name);
|
||||
|
|
@ -296,7 +296,7 @@ xp_primary_function(clixon_xpath_yacc *xpy,
|
|||
break;
|
||||
default:
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Unknown xpath function \"%s\"", name);
|
||||
|
|
@ -334,7 +334,7 @@ xp_nodetest_function(clixon_xpath_yacc *xpy,
|
|||
|
||||
if ((ret = xp_fnname_str2int(name)) < 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Unknown xpath function \"%s\"", name);
|
||||
|
|
@ -346,7 +346,7 @@ xp_nodetest_function(clixon_xpath_yacc *xpy,
|
|||
case XPATHFN_COMMENT: /* Group of not implemented node functions */
|
||||
case XPATHFN_PROCESSING_INSTRUCTIONS:
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "XPath function \"%s\" is not implemented", name);
|
||||
|
|
@ -358,7 +358,7 @@ xp_nodetest_function(clixon_xpath_yacc *xpy,
|
|||
break;
|
||||
default:
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Unknown xpath nodetest function \"%s\"", name);
|
||||
|
|
@ -391,7 +391,7 @@ xp_axisname_function(clixon_xpath_yacc *xpy,
|
|||
|
||||
if ((fn = axis_type_str2int(name)) < 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "Unknown xpath axisname \"%s\"", name);
|
||||
|
|
|
|||
|
|
@ -53,13 +53,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_nsctx.h"
|
||||
|
|
@ -88,7 +89,7 @@ xy_dup(xp_yang_ctx *xy0)
|
|||
xp_yang_ctx *xy = NULL;
|
||||
|
||||
if ((xy = malloc(sizeof(*xy))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(xy, 0, sizeof(*xy));
|
||||
|
|
@ -159,7 +160,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
|
|||
switch (xptree->xs_int){
|
||||
case A_CHILD:
|
||||
if ((nodetest = xptree->xs_c0) == NULL){
|
||||
clicon_err(OE_YANG, 0, "child step nodetest expected");
|
||||
clixon_err(OE_YANG, 0, "child step nodetest expected");
|
||||
goto done;
|
||||
}
|
||||
switch (nodetest->xs_type){
|
||||
|
|
@ -187,7 +188,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
|
|||
case XP_NODE_FN:
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_YANG, 0, "Invalid xpath-tree nodetest: %s",
|
||||
clixon_err(OE_YANG, 0, "Invalid xpath-tree nodetest: %s",
|
||||
xpath_tree_int2str(nodetest->xs_type));
|
||||
goto done;
|
||||
break;
|
||||
|
|
@ -197,7 +198,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
|
|||
xy->xy_node = yang_parent_get(ys);
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_YANG, 0, "Invalid path-arg step: %s",
|
||||
clixon_err(OE_YANG, 0, "Invalid path-arg step: %s",
|
||||
axis_type_int2str(xptree->xs_int));
|
||||
goto done;
|
||||
break;
|
||||
|
|
@ -298,7 +299,7 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
case XP_ADD:
|
||||
case XP_UNION:
|
||||
if (xptree->xs_c1 != NULL){
|
||||
clicon_err(OE_XML, 0, "Function %s having two args is invalid for path-arg", xptree->xs_s0);
|
||||
clixon_err(OE_XML, 0, "Function %s having two args is invalid for path-arg", xptree->xs_s0);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -322,7 +323,7 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
goto ok;
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_XML, 0, "Function %s invalid for path-arg", xptree->xs_s0);
|
||||
clixon_err(OE_XML, 0, "Function %s invalid for path-arg", xptree->xs_s0);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -350,7 +351,7 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
goto ok; /* Skip generic child traverse */
|
||||
break;
|
||||
default: /* Here we explicitly fail on node types for those not appearing in path-arg */
|
||||
clicon_err(OE_YANG, 0, "Invalid xpath-tree node name: %s",
|
||||
clixon_err(OE_YANG, 0, "Invalid xpath-tree node name: %s",
|
||||
xpath_tree_int2str(xptree->xs_type));
|
||||
goto done;
|
||||
break;
|
||||
|
|
@ -387,7 +388,7 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */
|
||||
/* Check op: only EQ allowed in path-arg */
|
||||
if (xptree->xs_int != XO_EQ){
|
||||
clicon_err(OE_YANG, 0, "Invalid xpath-tree relational operator: %d, only eq allowed",
|
||||
clixon_err(OE_YANG, 0, "Invalid xpath-tree relational operator: %d, only eq allowed",
|
||||
xptree->xs_int);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -404,7 +405,7 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
goto done;
|
||||
}
|
||||
else {
|
||||
clicon_err(OE_XML, EFAULT, "Internal error: no result produced");
|
||||
clixon_err(OE_XML, EFAULT, "Internal error: no result produced");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -472,7 +473,7 @@ yang_path_arg(yang_stmt *ys,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
|
||||
if (path_arg == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "path-arg is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "path-arg is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (xpath_parse(path_arg, &xptree) < 0)
|
||||
|
|
|
|||
|
|
@ -63,13 +63,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_hash.h"
|
||||
|
|
@ -88,7 +89,7 @@
|
|||
#include "clixon_yang_internal.h" /* internal included by this file only, not API*/
|
||||
|
||||
#ifdef XML_EXPLICIT_INDEX
|
||||
static int yang_search_index_extension(clicon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
static int yang_search_index_extension(clixon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -329,17 +330,17 @@ yang_cvec_add(yang_stmt *ys,
|
|||
|
||||
if ((cvv = yang_cvec_get(ys)) == NULL){
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_new");
|
||||
clixon_err(OE_YANG, errno, "cvec_new");
|
||||
return NULL;
|
||||
}
|
||||
yang_cvec_set(ys, cvv);
|
||||
}
|
||||
if ((cv = cvec_add(cvv, type)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_add");
|
||||
clixon_err(OE_YANG, errno, "cvec_add");
|
||||
return NULL;
|
||||
}
|
||||
if (cv_name_set(cv, name) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_name_set(%s)", name);
|
||||
clixon_err(OE_YANG, errno, "cv_name_set(%s)", name);
|
||||
return NULL;
|
||||
}
|
||||
return cv;
|
||||
|
|
@ -380,7 +381,7 @@ yang_ref_dec(yang_stmt *ys)
|
|||
int retval = -1;
|
||||
|
||||
if (ys->ys_ref <= 0){
|
||||
clicon_err(OE_YANG, 0, "reference count is %d cannot decrement", ys->ys_ref);
|
||||
clixon_err(OE_YANG, 0, "reference count is %d cannot decrement", ys->ys_ref);
|
||||
goto done;
|
||||
}
|
||||
ys->ys_ref--;
|
||||
|
|
@ -460,11 +461,11 @@ yang_when_xpath_set(yang_stmt *ys,
|
|||
int retval = -1;
|
||||
|
||||
if (xpath == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "xpath is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "xpath is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((ys->ys_when_xpath = strdup(xpath)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -502,7 +503,7 @@ yang_when_nsc_set(yang_stmt *ys,
|
|||
int retval = -1;
|
||||
|
||||
if (nsc && (ys->ys_when_nsc = cvec_dup(nsc)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_dup");
|
||||
clixon_err(OE_YANG, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -535,7 +536,7 @@ yang_filename_set(yang_stmt *ys,
|
|||
const char *filename)
|
||||
{
|
||||
if ((ys->ys_filename = strdup(filename)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -642,7 +643,7 @@ yang_stats(yang_stmt *yt,
|
|||
yang_stmt *ys;
|
||||
|
||||
if (yt == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "yang spec is NULL");
|
||||
clixon_err(OE_XML, EINVAL, "yang spec is NULL");
|
||||
goto done;
|
||||
}
|
||||
*nrp += 1;
|
||||
|
|
@ -674,7 +675,7 @@ yspec_new(void)
|
|||
yang_stmt *yspec;
|
||||
|
||||
if ((yspec = malloc(sizeof(*yspec))) == NULL){
|
||||
clicon_err(OE_YANG, errno, "malloc");
|
||||
clixon_err(OE_YANG, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(yspec, 0, sizeof(*yspec));
|
||||
|
|
@ -694,7 +695,7 @@ ys_new(enum rfc_6020 keyw)
|
|||
yang_stmt *ys;
|
||||
|
||||
if ((ys = malloc(sizeof(*ys))) == NULL){
|
||||
clicon_err(OE_YANG, errno, "malloc");
|
||||
clixon_err(OE_YANG, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(ys, 0, sizeof(*ys));
|
||||
|
|
@ -881,7 +882,7 @@ yn_realloc(yang_stmt *yn)
|
|||
yn->ys_len++;
|
||||
|
||||
if ((yn->ys_stmt = realloc(yn->ys_stmt, (yn->ys_len)*sizeof(yang_stmt *))) == 0){
|
||||
clicon_err(OE_YANG, errno, "realloc");
|
||||
clixon_err(OE_YANG, errno, "realloc");
|
||||
return -1;
|
||||
}
|
||||
yn->ys_stmt[yn->ys_len - 1] = NULL; /* init field */
|
||||
|
|
@ -916,25 +917,25 @@ ys_cp(yang_stmt *ynew,
|
|||
ynew->ys_parent = NULL;
|
||||
if (yold->ys_stmt)
|
||||
if ((ynew->ys_stmt = calloc(yold->ys_len, sizeof(yang_stmt *))) == NULL){
|
||||
clicon_err(OE_YANG, errno, "calloc");
|
||||
clixon_err(OE_YANG, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
if (yold->ys_argument)
|
||||
if ((ynew->ys_argument = strdup(yold->ys_argument)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
yang_cv_set(ynew, NULL);
|
||||
if ((cvo = yang_cv_get(yold)) != NULL){
|
||||
if ((cvn = cv_dup(cvo)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_dup");
|
||||
clixon_err(OE_YANG, errno, "cv_dup");
|
||||
goto done;
|
||||
}
|
||||
yang_cv_set(ynew, cvn);
|
||||
}
|
||||
if (yold->ys_cvec)
|
||||
if ((ynew->ys_cvec = cvec_dup(yold->ys_cvec)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_dup");
|
||||
clixon_err(OE_YANG, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
if (yold->ys_typecache){
|
||||
|
|
@ -944,12 +945,12 @@ ys_cp(yang_stmt *ynew,
|
|||
}
|
||||
if (yold->ys_when_xpath)
|
||||
if ((ynew->ys_when_xpath = strdup(yold->ys_when_xpath)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if (yold->ys_when_nsc){
|
||||
if ((ynew->ys_when_nsc = cvec_dup(yold->ys_when_nsc)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_dup");
|
||||
clixon_err(OE_YANG, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1364,11 +1365,11 @@ yang_find_myprefix(yang_stmt *ys)
|
|||
if (ys_real_module(ys, &ymod) < 0)
|
||||
goto done;
|
||||
if (ymod == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Internal error: no module");
|
||||
clixon_err(OE_YANG, ENOENT, "Internal error: no module");
|
||||
goto done;
|
||||
}
|
||||
if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod));
|
||||
clixon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod));
|
||||
goto done;
|
||||
}
|
||||
prefix = yang_argument_get(yprefix);
|
||||
|
|
@ -1396,7 +1397,7 @@ yang_find_mynamespace(yang_stmt *ys)
|
|||
if (ys_real_module(ys, &ymod) < 0)
|
||||
goto done;
|
||||
if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod));
|
||||
clixon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod));
|
||||
goto done;
|
||||
}
|
||||
ns = yang_argument_get(ynamespace);
|
||||
|
|
@ -1441,7 +1442,7 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
|
||||
if (prefix == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "prefix is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "prefix is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* First check if namespace is my own module */
|
||||
|
|
@ -1503,7 +1504,7 @@ yang_find_namespace_by_prefix(yang_stmt *ys,
|
|||
yang_stmt *ym;
|
||||
|
||||
if (ns == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "ns is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "ns is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((ym = yang_find_module_by_prefix(ys, prefix)) == NULL)
|
||||
|
|
@ -1735,7 +1736,7 @@ yang_order(yang_stmt *y)
|
|||
}
|
||||
}
|
||||
if (yang_order1(yp, y, &j) < 0){
|
||||
clicon_err(OE_YANG, 0, "YANG node %s not ordered: not found", yang_argument_get(y));
|
||||
clixon_err(OE_YANG, 0, "YANG node %s not ordered: not found", yang_argument_get(y));
|
||||
goto done;
|
||||
}
|
||||
retval = tot + j;
|
||||
|
|
@ -1863,22 +1864,22 @@ ys_real_module(yang_stmt *ys,
|
|||
yang_stmt *yspec;
|
||||
|
||||
if (ymod == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "ymod is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "ymod is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((ym = ys_module(ys)) != NULL){
|
||||
yspec = ys_spec(ym);
|
||||
while (ym && yang_keyword_get(ym) == Y_SUBMODULE){
|
||||
if ((yb = yang_find(ym, Y_BELONGS_TO, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */
|
||||
clixon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */
|
||||
goto done;
|
||||
}
|
||||
if ((name = yang_argument_get(yb)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */
|
||||
clixon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */
|
||||
goto done;
|
||||
}
|
||||
if ((ysubm = yang_find_module_by_name(yspec, name)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "submodule %s references non-existent module %s in its belongs-to statement",
|
||||
clixon_err(OE_YANG, ENOENT, "submodule %s references non-existent module %s in its belongs-to statement",
|
||||
yang_argument_get(ym), name);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1944,7 +1945,7 @@ yang_print_cb(FILE *f,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cbuf_new");
|
||||
clixon_err(OE_YANG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (yang_print_cbuf(cb, yn, 0, 1) < 0)
|
||||
|
|
@ -1984,7 +1985,7 @@ yang_spec_print(FILE *f,
|
|||
yang_stmt *yrev;
|
||||
|
||||
if (yspec == NULL || yang_keyword_get(yspec) != Y_SPEC){
|
||||
clicon_err(OE_YANG, EINVAL, "yspec is not of type YSPEC");
|
||||
clixon_err(OE_YANG, EINVAL, "yspec is not of type YSPEC");
|
||||
return -1;
|
||||
}
|
||||
while ((ym = yn_each(yspec, ym)) != NULL) {
|
||||
|
|
@ -2013,7 +2014,7 @@ yang_spec_dump(yang_stmt *yspec,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_YANG, errno, "cbuf_new");
|
||||
clixon_err(OE_YANG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
while ((ym = yn_each(yspec, ym)) != NULL) {
|
||||
|
|
@ -2060,7 +2061,7 @@ yang_print_cbuf(cbuf *cb,
|
|||
char *arg;
|
||||
|
||||
if (yn == NULL || cb == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "cb or yn is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "cb or yn is NULL");
|
||||
goto done;
|
||||
}
|
||||
keyw = yang_keyword_get(yn);
|
||||
|
|
@ -2128,7 +2129,7 @@ yang_deviation(yang_stmt *ys,
|
|||
yang_stmt *yc1;
|
||||
yang_stmt *ytc;
|
||||
char *devop;
|
||||
clicon_handle h = (clicon_handle)arg;
|
||||
clixon_handle h = (clixon_handle)arg;
|
||||
enum rfc_6020 kw;
|
||||
int min;
|
||||
int max;
|
||||
|
|
@ -2137,17 +2138,17 @@ yang_deviation(yang_stmt *ys,
|
|||
goto ok;
|
||||
/* Absolute schema node identifier identifying target node */
|
||||
if ((nodeid = yang_argument_get(ys)) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "No argument to deviation");
|
||||
clixon_err(OE_YANG, EINVAL, "No argument to deviation");
|
||||
goto done;
|
||||
}
|
||||
/* Get target node */
|
||||
if (yang_abs_schema_nodeid(ys, nodeid, &ytarget) < 0)
|
||||
goto done;
|
||||
if (ytarget == NULL){
|
||||
clicon_log(LOG_WARNING, "deviation %s: target not found", nodeid);
|
||||
clixon_log(h, LOG_WARNING, "deviation %s: target not found", nodeid);
|
||||
goto ok;
|
||||
/* The RFC does not explicitly say the target node MUST exist
|
||||
clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid);
|
||||
clixon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid);
|
||||
goto done;
|
||||
*/
|
||||
}
|
||||
|
|
@ -2178,7 +2179,7 @@ yang_deviation(yang_stmt *ys,
|
|||
&max) < 0)
|
||||
goto done;
|
||||
if (max == 1){
|
||||
clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" added but node already exist in target %s",
|
||||
clixon_err(OE_YANG, 0, "deviation %s: \"%s %s\" added but node already exist in target %s",
|
||||
nodeid,
|
||||
yang_key2str(kw), yang_argument_get(yc),
|
||||
yang_argument_get(ytarget));
|
||||
|
|
@ -2203,7 +2204,7 @@ yang_deviation(yang_stmt *ys,
|
|||
break;
|
||||
default:
|
||||
if (ytc == NULL){
|
||||
clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
|
||||
clixon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
|
||||
nodeid,
|
||||
yang_key2str(kw), yang_argument_get(yc),
|
||||
yang_argument_get(ytarget));
|
||||
|
|
@ -2233,7 +2234,7 @@ yang_deviation(yang_stmt *ys,
|
|||
* target node. */
|
||||
kw = yang_keyword_get(yc);
|
||||
if ((ytc = yang_find(ytarget, kw, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
|
||||
clixon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s",
|
||||
nodeid,
|
||||
yang_key2str(kw), yang_argument_get(yc),
|
||||
yang_argument_get(ytarget));
|
||||
|
|
@ -2246,7 +2247,7 @@ yang_deviation(yang_stmt *ys,
|
|||
}
|
||||
}
|
||||
else{ /* Shouldnt happen, lex/yacc takes it */
|
||||
clicon_err(OE_YANG, EINVAL, "%s: invalid deviate operator", devop);
|
||||
clixon_err(OE_YANG, EINVAL, "%s: invalid deviate operator", devop);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -2268,10 +2269,10 @@ yang_deviation(yang_stmt *ys,
|
|||
* @param[in] h Clixon handle
|
||||
* @param[in] ys The yang statement to populate.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error with clicon_err called
|
||||
* @retval -1 Error with clixon_err called
|
||||
*/
|
||||
static int
|
||||
ys_populate_leaf(clicon_handle h,
|
||||
ys_populate_leaf(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -2298,14 +2299,14 @@ ys_populate_leaf(clicon_handle h,
|
|||
goto done;
|
||||
/* 2. Create the CV using cvtype and name it */
|
||||
if ((cv = cv_new(cvtype)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (options & YANG_OPTIONS_FRACTION_DIGITS && cvtype == CGV_DEC64) /* XXX: Seems misplaced? / too specific */
|
||||
cv_dec64_n_set(cv, fraction_digits);
|
||||
|
||||
if (cv_name_set(cv, ys->ys_argument) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_name_set");
|
||||
clixon_err(OE_YANG, errno, "cv_name_set");
|
||||
goto done;
|
||||
}
|
||||
/* get parent of where type is defined, can be original object */
|
||||
|
|
@ -2317,11 +2318,11 @@ ys_populate_leaf(clicon_handle h,
|
|||
*/
|
||||
if ((ydef = yang_find(ys, Y_DEFAULT, NULL)) != NULL){
|
||||
if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */
|
||||
clicon_err(OE_YANG, errno, "parsing cv");
|
||||
clixon_err(OE_YANG, errno, "parsing cv");
|
||||
goto done;
|
||||
}
|
||||
if (cvret == 0){ /* parsing failed */
|
||||
clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
clixon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
free(reason);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2330,11 +2331,11 @@ ys_populate_leaf(clicon_handle h,
|
|||
else if (ytypedef != ys &&
|
||||
(ydef = yang_find(ytypedef, Y_DEFAULT, NULL)) != NULL) {
|
||||
if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */
|
||||
clicon_err(OE_YANG, errno, "parsing cv");
|
||||
clixon_err(OE_YANG, errno, "parsing cv");
|
||||
goto done;
|
||||
}
|
||||
if (cvret == 0){ /* parsing failed */
|
||||
clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
clixon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
free(reason);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2366,7 +2367,7 @@ ys_populate_leaf(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
ys_populate_list(clicon_handle h,
|
||||
ys_populate_list(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
yang_stmt *ykey;
|
||||
|
|
@ -2400,7 +2401,7 @@ bound_add(yang_stmt *ys,
|
|||
int ret = 1;
|
||||
|
||||
if (ys == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "ys is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "ys is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((cv = yang_cvec_add(ys, cvtype, name)) == NULL)
|
||||
|
|
@ -2412,11 +2413,11 @@ bound_add(yang_stmt *ys,
|
|||
else if (strcmp(val, "max") == 0)
|
||||
cv_max_set(cv);
|
||||
else if ((ret = cv_parse1(val, cv, &reason)) < 0){
|
||||
clicon_err(OE_YANG, errno, "cv_parse1");
|
||||
clixon_err(OE_YANG, errno, "cv_parse1");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){ /* parsing failed */
|
||||
clicon_err(OE_YANG, errno, "range statement %s: %s", val, reason);
|
||||
clixon_err(OE_YANG, errno, "range statement %s: %s", val, reason);
|
||||
free(reason);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2482,7 +2483,7 @@ range_parse(yang_stmt *ys,
|
|||
* ascending order
|
||||
*/
|
||||
static int
|
||||
ys_populate_range(clicon_handle h,
|
||||
ys_populate_range(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -2496,14 +2497,14 @@ ys_populate_range(clicon_handle h,
|
|||
|
||||
yparent = ys->ys_parent; /* Find parent: type */
|
||||
if (yparent->ys_keyword != Y_TYPE){
|
||||
clicon_err(OE_YANG, 0, "parent should be type");
|
||||
clixon_err(OE_YANG, 0, "parent should be type");
|
||||
goto done;
|
||||
}
|
||||
if (yang_type_resolve(ys, ys, (yang_stmt*)yparent, &yrestype,
|
||||
&options, NULL, NULL, NULL, &fraction_digits) < 0)
|
||||
goto done;
|
||||
if (yrestype == NULL){
|
||||
clicon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
goto done;
|
||||
}
|
||||
restype = yrestype?yrestype->ys_argument:NULL;
|
||||
|
|
@ -2513,7 +2514,7 @@ ys_populate_range(clicon_handle h,
|
|||
if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0)
|
||||
goto done;
|
||||
if (!cv_isint(cvtype) && cvtype != CGV_DEC64){
|
||||
clicon_err(OE_YANG, 0, "The range substatement only applies to int types, not to type: %s", origtype);
|
||||
clixon_err(OE_YANG, 0, "The range substatement only applies to int types, not to type: %s", origtype);
|
||||
goto done;
|
||||
}
|
||||
if (range_parse(ys, cvtype, fraction_digits) < 0)
|
||||
|
|
@ -2544,7 +2545,7 @@ ys_populate_range(clicon_handle h,
|
|||
* be disjoint and MUST be in ascending order.
|
||||
*/
|
||||
static int
|
||||
ys_populate_length(clicon_handle h,
|
||||
ys_populate_length(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -2553,7 +2554,7 @@ ys_populate_length(clicon_handle h,
|
|||
|
||||
yparent = ys->ys_parent; /* Find parent: type */
|
||||
if (yparent->ys_keyword != Y_TYPE){
|
||||
clicon_err(OE_YANG, 0, "parent should be type");
|
||||
clixon_err(OE_YANG, 0, "parent should be type");
|
||||
goto done;
|
||||
}
|
||||
cvtype = CGV_UINT64;
|
||||
|
|
@ -2573,7 +2574,7 @@ ys_populate_length(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
ys_populate_type(clicon_handle h,
|
||||
ys_populate_type(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
|
||||
{
|
||||
|
|
@ -2582,18 +2583,18 @@ ys_populate_type(clicon_handle h,
|
|||
|
||||
if (strcmp(ys->ys_argument, "decimal64") == 0){
|
||||
if (yang_find(ys, Y_FRACTION_DIGITS, NULL) == NULL){
|
||||
clicon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement");
|
||||
clixon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (strcmp(ys->ys_argument, "identityref") == 0){
|
||||
if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "identityref type requires base sub-statement");
|
||||
clixon_err(OE_YANG, 0, "identityref type requires base sub-statement");
|
||||
goto done;
|
||||
}
|
||||
if ((yang_find_identity(ys, ybase->ys_argument)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "Identity %s not found (base type of %s)",
|
||||
clixon_err(OE_YANG, 0, "Identity %s not found (base type of %s)",
|
||||
ybase->ys_argument, ys->ys_argument);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2617,7 +2618,7 @@ ys_populate_type(clicon_handle h,
|
|||
* @see validate_identityref which in runtime validates actual values
|
||||
*/
|
||||
static int
|
||||
ys_populate_identity(clicon_handle h,
|
||||
ys_populate_identity(clixon_handle h,
|
||||
yang_stmt *ys,
|
||||
char *idref)
|
||||
{
|
||||
|
|
@ -2637,13 +2638,13 @@ ys_populate_identity(clicon_handle h,
|
|||
if (idref == NULL){
|
||||
/* Create derived identity through prefix:id if not recursively called*/
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0)
|
||||
goto done;
|
||||
if ((ymod = ys_module(ys)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No module found");
|
||||
clixon_err(OE_YANG, ENOENT, "No module found");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
|
||||
|
|
@ -2658,7 +2659,7 @@ ys_populate_identity(clicon_handle h,
|
|||
continue;
|
||||
baseid = yang_argument_get(yc); /* on the form: prefix:id */
|
||||
if (((ybaseid = yang_find_identity(ys, baseid))) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No such identity: %s", baseid);
|
||||
clixon_err(OE_YANG, ENOENT, "No such identity: %s", baseid);
|
||||
goto done;
|
||||
}
|
||||
// continue; /* root identity */
|
||||
|
|
@ -2670,7 +2671,7 @@ ys_populate_identity(clicon_handle h,
|
|||
continue;
|
||||
/* Add derived id to ybaseid */
|
||||
if (yang_cvec_add(ybaseid, CGV_STRING, idref) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_new");
|
||||
clixon_err(OE_UNIX, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
/* Transitive to the root */
|
||||
|
|
@ -2724,7 +2725,7 @@ if_feature(yang_stmt *yspec,
|
|||
* Bootstrapping: A feature is enabled if found in clixon-config
|
||||
*/
|
||||
int
|
||||
ys_populate_feature(clicon_handle h,
|
||||
ys_populate_feature(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -2744,7 +2745,7 @@ ys_populate_feature(clicon_handle h,
|
|||
if ((x = clicon_conf_xml(h)) == NULL)
|
||||
goto ok;
|
||||
if ((ymod = ys_module(ys)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "module not found");
|
||||
clixon_err(OE_YANG, 0, "module not found");
|
||||
goto done;
|
||||
}
|
||||
module = ymod->ys_argument;
|
||||
|
|
@ -2769,7 +2770,7 @@ ys_populate_feature(clicon_handle h,
|
|||
if (f) free(f);
|
||||
}
|
||||
if ((cv = cv_new(CGV_BOOL)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
cv_name_set(cv, feature);
|
||||
|
|
@ -2791,7 +2792,7 @@ ys_populate_feature(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
ys_populate_unique(clicon_handle h,
|
||||
ys_populate_unique(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
cvec *cvv;
|
||||
|
|
@ -2827,7 +2828,7 @@ ys_populate_unique(clicon_handle h,
|
|||
* @see yang_extension_value Called on expanded YANG, eg in context of (y2)
|
||||
*/
|
||||
static int
|
||||
ys_populate_unknown(clicon_handle h,
|
||||
ys_populate_unknown(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -2843,13 +2844,13 @@ ys_populate_unknown(clicon_handle h,
|
|||
if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0)
|
||||
goto done;
|
||||
if ((ymod = yang_find_module_by_prefix(ys, prefix)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id);
|
||||
clixon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id);
|
||||
goto done;
|
||||
}
|
||||
/* To find right binding eg after grouping/uses */
|
||||
ys->ys_mymodule = ys_module(ys);
|
||||
if ((yext = yang_find(ymod, Y_EXTENSION, id)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id);
|
||||
clixon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id);
|
||||
goto done;
|
||||
}
|
||||
/* Optional argument (only if "argument") - save it in ys_cv */
|
||||
|
|
@ -2857,7 +2858,7 @@ ys_populate_unknown(clicon_handle h,
|
|||
(argument = cv_string_get(cv)) != NULL){
|
||||
if (yang_find(yext, Y_ARGUMENT, NULL) == NULL &&
|
||||
argument != NULL){
|
||||
clicon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument);
|
||||
clixon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -2899,7 +2900,7 @@ ys_populate_unknown(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
ys_populate_module_submodule(clicon_handle h,
|
||||
ys_populate_module_submodule(clixon_handle h,
|
||||
yang_stmt *ym)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -2920,7 +2921,7 @@ ys_populate_module_submodule(clicon_handle h,
|
|||
yp = yang_find(yi, Y_PREFIX, NULL);
|
||||
pi = yang_argument_get(yp);
|
||||
if (p0 && strcmp(p0, pi) == 0){ /* Check top-level */
|
||||
clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
|
||||
clixon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
|
||||
pi, yang_argument_get(ym));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2932,7 +2933,7 @@ ys_populate_module_submodule(clicon_handle h,
|
|||
yp = yang_find(yi2, Y_PREFIX, NULL);
|
||||
pi2 = yang_argument_get(yp);
|
||||
if (strcmp(pi2, pi) == 0){
|
||||
clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
|
||||
clixon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)",
|
||||
pi, yang_argument_get(ym));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -2963,7 +2964,7 @@ ys_populate(yang_stmt *ys,
|
|||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h = (clicon_handle)arg;
|
||||
clixon_handle h = (clixon_handle)arg;
|
||||
|
||||
switch(ys->ys_keyword){
|
||||
case Y_IDENTITY:
|
||||
|
|
@ -3016,7 +3017,7 @@ ys_populate2(yang_stmt *ys,
|
|||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h = (clicon_handle)arg;
|
||||
clixon_handle h = (clixon_handle)arg;
|
||||
int ret;
|
||||
|
||||
switch(ys->ys_keyword){
|
||||
|
|
@ -3056,7 +3057,7 @@ ys_populate2(yang_stmt *ys,
|
|||
* @note if-features is parsed in full context here, previous restricted pass in ys_parse_sub
|
||||
*/
|
||||
int
|
||||
yang_features(clicon_handle h,
|
||||
yang_features(clixon_handle h,
|
||||
yang_stmt *yt)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -3212,7 +3213,7 @@ yang_datanode(yang_stmt *ys)
|
|||
* @param[in] nsc Namespace context from yang for the prefixes (names) of cvv
|
||||
* @param[out] yres Result yang statement node, or NULL if not found
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error, with clicon_err called
|
||||
* @retval -1 Error, with clixon_err called
|
||||
* A schema node identifier consists of a path of identifiers, separated by slashes ("/").
|
||||
* References to identifiers defined in external modules MUST be
|
||||
* qualified with appropriate prefixes, and references to identifiers
|
||||
|
|
@ -3248,14 +3249,14 @@ schema_nodeid_iterate(yang_stmt *yn,
|
|||
* matching module below
|
||||
* Get namespace */
|
||||
if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){
|
||||
clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier in module %s",
|
||||
clixon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier in module %s",
|
||||
prefix,
|
||||
yang_argument_get(ys_module(yn)));
|
||||
goto done;
|
||||
}
|
||||
/* Get yang module */
|
||||
if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){
|
||||
clicon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns);
|
||||
clixon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns);
|
||||
goto done;
|
||||
}
|
||||
ys = yang_find_schemanode(yp, id);
|
||||
|
|
@ -3296,7 +3297,7 @@ schema_nodeid_iterate(yang_stmt *yn,
|
|||
* @param[in] schema_nodeid Absolute schema-node-id, ie /a/b
|
||||
* @param[out] yres Result yang statement node, or NULL if not found
|
||||
* @retval 0 OK , with result in yres
|
||||
* @retval -1 Error, with clicon_err called
|
||||
* @retval -1 Error, with clixon_err called
|
||||
* Assume schema nodeid:s have prefixes, (actually the first).
|
||||
* @see RFC7950 6.5
|
||||
* o schema node: A node in the schema tree. One of action, container,
|
||||
|
|
@ -3321,13 +3322,13 @@ yang_abs_schema_nodeid(yang_stmt *yn,
|
|||
char *str;
|
||||
|
||||
if ((yspec = ys_spec(yn)) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "No yang spec");
|
||||
clixon_err(OE_YANG, EINVAL, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
*yres = NULL;
|
||||
/* check absolute schema_nodeid */
|
||||
if (schema_nodeid[0] != '/'){
|
||||
clicon_err(OE_YANG, EINVAL, "absolute schema nodeid should start with /");
|
||||
clixon_err(OE_YANG, EINVAL, "absolute schema nodeid should start with /");
|
||||
goto done;
|
||||
}
|
||||
/* Split nodeid on the form /p0:i0/p1:i1 to a cvec with [name:p0 value:i0][...]
|
||||
|
|
@ -3343,7 +3344,7 @@ yang_abs_schema_nodeid(yang_stmt *yn,
|
|||
cv_type_set(cv, CGV_STRING);
|
||||
if ((str = cv_string_get(cv)) == NULL || !strlen(str)){
|
||||
if (cv_string_set(cv, cv_name_get(cv)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
goto done;
|
||||
}
|
||||
cv_name_set(cv, NULL);
|
||||
|
|
@ -3361,13 +3362,13 @@ yang_abs_schema_nodeid(yang_stmt *yn,
|
|||
cv = cvec_i(nodeid_cvv, 0);
|
||||
prefix = cv_name_get(cv);
|
||||
if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){
|
||||
clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier: %s",
|
||||
clixon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier: %s",
|
||||
prefix, schema_nodeid);
|
||||
goto done;
|
||||
}
|
||||
/* Get yang module */
|
||||
if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){
|
||||
clicon_err(OE_YANG, EFAULT, "No module for namespace: %s in schema node identifier: %s",
|
||||
clixon_err(OE_YANG, EFAULT, "No module for namespace: %s in schema node identifier: %s",
|
||||
ns, schema_nodeid);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -3392,7 +3393,7 @@ yang_abs_schema_nodeid(yang_stmt *yn,
|
|||
* @param[in] ns Namespace context
|
||||
* @param[out] yres First yang node matching schema nodeid
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error, with clicon_err called
|
||||
* @retval -1 Error, with clixon_err called
|
||||
* Used in yang: unique, refine, uses augment
|
||||
* @see yang_abs_schema_nodeid
|
||||
*/
|
||||
|
|
@ -3409,17 +3410,17 @@ yang_desc_schema_nodeid(yang_stmt *yn,
|
|||
cvec *nsc = NULL;
|
||||
|
||||
if (schema_nodeid == NULL || strlen(schema_nodeid) == 0){
|
||||
clicon_err(OE_YANG, EINVAL, "nodeid is empty");
|
||||
clixon_err(OE_YANG, EINVAL, "nodeid is empty");
|
||||
goto done;
|
||||
}
|
||||
if ((yspec = ys_spec(yn)) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "No yang spec");
|
||||
clixon_err(OE_YANG, EINVAL, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
*yres = NULL;
|
||||
/* check absolute schema_nodeid */
|
||||
if (schema_nodeid[0] == '/'){
|
||||
clicon_err(OE_YANG, EINVAL, "descendant schema nodeid should not start with /");
|
||||
clixon_err(OE_YANG, EINVAL, "descendant schema nodeid should not start with /");
|
||||
goto done;
|
||||
}
|
||||
/* Split nodeid on the form /p0:i0/p1:i1 to a cvec with [name:p0 value:i0][...]
|
||||
|
|
@ -3435,7 +3436,7 @@ yang_desc_schema_nodeid(yang_stmt *yn,
|
|||
cv_type_set(cv, CGV_STRING);
|
||||
if ((str = cv_string_get(cv)) == NULL || !strlen(str)){
|
||||
if (cv_string_set(cv, cv_name_get(cv)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
goto done;
|
||||
}
|
||||
cv_name_set(cv, NULL);
|
||||
|
|
@ -3549,14 +3550,14 @@ yang_arg2cvec(yang_stmt *ys,
|
|||
if ((vec = clicon_strsep(ys->ys_argument, " ", &nvec)) == NULL)
|
||||
goto done;
|
||||
if ((cvv = cvec_new(nvec)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_new");
|
||||
clixon_err(OE_YANG, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
for (i = 0; i < nvec; i++) {
|
||||
cv = cvec_i(cvv, i);
|
||||
cv_type_set(cv, CGV_STRING);
|
||||
if ((cv_string_set(cv, vec[i])) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_string_set");
|
||||
clixon_err(OE_YANG, errno, "cv_string_set");
|
||||
cvv = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -3636,11 +3637,11 @@ yang_type_cache_set(yang_stmt *ys,
|
|||
yang_type_cache *ycache;
|
||||
|
||||
if (ys->ys_typecache != NULL){
|
||||
clicon_err(OE_YANG, EEXIST, "yang type cache");
|
||||
clixon_err(OE_YANG, EEXIST, "yang type cache");
|
||||
goto done;
|
||||
}
|
||||
if ((ys->ys_typecache = (yang_type_cache *)malloc(sizeof(*ycache))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
ycache = ys->ys_typecache;
|
||||
|
|
@ -3649,12 +3650,12 @@ yang_type_cache_set(yang_stmt *ys,
|
|||
ycache->yc_options = options;
|
||||
if (cvv){
|
||||
if ((ycache->yc_cvv = cvec_dup(cvv)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (patterns && (ycache->yc_patterns = cvec_dup(patterns)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
ycache->yc_fraction = fraction;
|
||||
|
|
@ -3684,7 +3685,7 @@ yang_type_cache_regexp_set(yang_stmt *ytype,
|
|||
assert(ycache->yc_regexps == NULL);
|
||||
ycache->yc_rxmode = rxmode;
|
||||
if ((ycache->yc_regexps = cvec_dup(regexps)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -3758,7 +3759,7 @@ yang_type_cache_cp(yang_stmt *ynew,
|
|||
int ret;
|
||||
|
||||
if ((patterns = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
/* Note, regexps are not copied since they are voids, if they were, they
|
||||
|
|
@ -3792,7 +3793,7 @@ yang_type_cache_free(yang_type_cache *ycache)
|
|||
if (ycache->yc_regexps){
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(ycache->yc_regexps, cv)) != NULL){
|
||||
/* need to store mode since clicon_handle is not available */
|
||||
/* need to store mode since clixon_handle is not available */
|
||||
switch (ycache->yc_rxmode){
|
||||
case REGEXP_POSIX:
|
||||
cligen_regex_posix_free(cv_void_get(cv));
|
||||
|
|
@ -3838,7 +3839,7 @@ yang_anydata_add(yang_stmt *yp,
|
|||
if ((ys = ys_new(Y_ANYDATA)) == NULL)
|
||||
goto done;
|
||||
if ((name = strdup(name0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
yang_argument_set(ys, name);
|
||||
|
|
@ -3887,13 +3888,13 @@ yang_extension_value(yang_stmt *ys,
|
|||
int ret;
|
||||
|
||||
if (ys == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "ys is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "ys is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (exist)
|
||||
*exist = 0;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
yext = NULL; /* This loop gets complicated in the case the extension is augmented */
|
||||
|
|
@ -3973,7 +3974,7 @@ yang_sort_subelements(yang_stmt *ys)
|
|||
}
|
||||
|
||||
int
|
||||
yang_init(clicon_handle h)
|
||||
yang_init(clixon_handle h)
|
||||
{
|
||||
return yang_cardinality_init(h);
|
||||
}
|
||||
|
|
@ -3992,7 +3993,7 @@ yang_list_index_add(yang_stmt *ys)
|
|||
|
||||
if ((yp = yang_parent_get(ys)) == NULL ||
|
||||
yang_keyword_get(yp) != Y_LIST){
|
||||
clicon_log(LOG_WARNING, "search_index should in a list");
|
||||
clixon_log(NULL, LOG_WARNING, "search_index should in a list");
|
||||
goto ok;
|
||||
}
|
||||
yang_flag_set(ys, YANG_FLAG_INDEX);
|
||||
|
|
@ -4011,7 +4012,7 @@ yang_list_index_add(yang_stmt *ys)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_search_index_extension(clicon_handle h,
|
||||
yang_search_index_extension(clixon_handle h,
|
||||
yang_stmt *yext,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
|
|
@ -4108,7 +4109,7 @@ yang_action_cb_add(yang_stmt *ys,
|
|||
rpc_callback_t *rc = (rpc_callback_t *)arg;
|
||||
|
||||
if (rc == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "arg is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "arg is NULL");
|
||||
return -1;
|
||||
}
|
||||
ADDQ(rc, ys->ys_action_cb);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
@ -483,7 +483,7 @@ static int _yc_exist[Y_SPEC] = {0,};
|
|||
* @note always accept UNKNOWN (due to extension)
|
||||
*/
|
||||
int
|
||||
yang_cardinality(clicon_handle h,
|
||||
yang_cardinality(clixon_handle h,
|
||||
yang_stmt *yt,
|
||||
char *modname)
|
||||
{
|
||||
|
|
@ -511,7 +511,7 @@ yang_cardinality(clicon_handle h,
|
|||
continue;
|
||||
/* Find entry in yang cardinality table from parent/child keyword pair */
|
||||
if ((yc = _yc_search[pk][ck]) == NULL){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be",
|
||||
clixon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be",
|
||||
modname,
|
||||
yang_key2str(ck),
|
||||
yang_argument_get(ys),
|
||||
|
|
@ -520,7 +520,7 @@ yang_cardinality(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if (order > yc->yc_order){
|
||||
clicon_err(OE_YANG, 0, "%s: yang node \"%s\"(%s) which is child of \"%s\"(%s) is not in correct order (should not be after \"%s\"(%s))",
|
||||
clixon_err(OE_YANG, 0, "%s: yang node \"%s\"(%s) which is child of \"%s\"(%s) is not in correct order (should not be after \"%s\"(%s))",
|
||||
modname,
|
||||
yang_key2str(ck),
|
||||
yang_argument_get(ys),
|
||||
|
|
@ -541,13 +541,13 @@ yang_cardinality(clicon_handle h,
|
|||
continue;
|
||||
if (yc->yc_min &&
|
||||
yang_find(yt, yc->yc_child, NULL) == NULL){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"",
|
||||
clixon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"",
|
||||
modname, yang_key2str(yc->yc_child), yang_key2str(pk));
|
||||
goto done;
|
||||
}
|
||||
if (yc->yc_max<NMAX &&
|
||||
(nr = yang_match(yt, yc->yc_child, NULL)) > yc->yc_max){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed",
|
||||
clixon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed",
|
||||
modname,
|
||||
yang_key2str(pk),
|
||||
nr,
|
||||
|
|
@ -580,7 +580,7 @@ yang_cardinality(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_cardinality_interval(clicon_handle h,
|
||||
yang_cardinality_interval(clixon_handle h,
|
||||
enum rfc_6020 parent_key,
|
||||
enum rfc_6020 child_key,
|
||||
int *min,
|
||||
|
|
@ -590,7 +590,7 @@ yang_cardinality_interval(clicon_handle h,
|
|||
const struct ycard *ycplist; /* ycard parent table*/
|
||||
|
||||
if ((ycplist = _yc_search[parent_key][child_key]) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality",
|
||||
clixon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality",
|
||||
parent_key, child_key);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -606,7 +606,7 @@ yang_cardinality_interval(clicon_handle h,
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
int
|
||||
yang_cardinality_init(clicon_handle h)
|
||||
yang_cardinality_init(clixon_handle h)
|
||||
{
|
||||
const struct ycard *yc;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int yang_cardinality(clicon_handle h, yang_stmt *yt, char *modname);
|
||||
int yang_cardinality_interval(clicon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, int *max);
|
||||
int yang_cardinality_init(clicon_handle h);
|
||||
int yang_cardinality(clixon_handle h, yang_stmt *yt, char *modname);
|
||||
int yang_cardinality_interval(clixon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, int *max);
|
||||
int yang_cardinality_init(clixon_handle h);
|
||||
|
||||
#endif /* _CLIXON_YANG_CARDINALITY_H_ */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
|
|
@ -60,13 +60,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
|
|
@ -100,7 +101,7 @@ modstate_diff_new(void)
|
|||
modstate_diff_t *md;
|
||||
|
||||
if ((md = malloc(sizeof(modstate_diff_t))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(md, 0, sizeof(modstate_diff_t));
|
||||
|
|
@ -135,7 +136,7 @@ modstate_diff_free(modstate_diff_t *md)
|
|||
* @see netconf_module_load
|
||||
*/
|
||||
int
|
||||
yang_modules_init(clicon_handle h)
|
||||
yang_modules_init(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -145,7 +146,7 @@ yang_modules_init(clicon_handle h)
|
|||
goto ok;
|
||||
/* Ensure module-set-id is set */
|
||||
if (!clicon_option_exists(h, "CLICON_MODULE_SET_ID")){
|
||||
clicon_err(OE_CFG, ENOENT, "CLICON_MODULE_SET_ID must be defined when CLICON_YANG_LIBRARY is enabled");
|
||||
clixon_err(OE_CFG, ENOENT, "CLICON_MODULE_SET_ID must be defined when CLICON_YANG_LIBRARY is enabled");
|
||||
goto done;
|
||||
}
|
||||
/* Ensure revision exists is set */
|
||||
|
|
@ -153,7 +154,7 @@ yang_modules_init(clicon_handle h)
|
|||
goto done;
|
||||
/* Find revision */
|
||||
if (yang_modules_revision(h) == NULL){
|
||||
clicon_err(OE_CFG, ENOENT, "Yang client library yang spec has no revision");
|
||||
clixon_err(OE_CFG, ENOENT, "Yang client library yang spec has no revision");
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
|
|
@ -169,7 +170,7 @@ yang_modules_init(clicon_handle h)
|
|||
* @retval NULL Error: RFC7895 not loaded or revision not found
|
||||
*/
|
||||
char *
|
||||
yang_modules_revision(clicon_handle h)
|
||||
yang_modules_revision(clixon_handle h)
|
||||
{
|
||||
yang_stmt *yspec;
|
||||
yang_stmt *ymod;
|
||||
|
|
@ -199,7 +200,7 @@ yang_modules_revision(clicon_handle h)
|
|||
* @see RFC8525
|
||||
*/
|
||||
int
|
||||
yang_modules_state_build(clicon_handle h,
|
||||
yang_modules_state_build(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
char *msid,
|
||||
int brief,
|
||||
|
|
@ -220,11 +221,11 @@ yang_modules_state_build(clicon_handle h,
|
|||
if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL
|
||||
/* && (ylib = yang_find(yspec0, Y_SUBMODULE, module)) == NULL */
|
||||
){
|
||||
clicon_err(OE_YANG, 0, "%s not found", module);
|
||||
clixon_err(OE_YANG, 0, "%s not found", module);
|
||||
goto done;
|
||||
}
|
||||
if ((yns = yang_find(ylib, Y_NAMESPACE, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "%s yang namespace not found", module);
|
||||
clixon_err(OE_YANG, 0, "%s yang namespace not found", module);
|
||||
goto done;
|
||||
}
|
||||
/* RFC 8525 */
|
||||
|
|
@ -319,7 +320,7 @@ x +--ro namespace inet:uri
|
|||
* @see netconf_hello_server
|
||||
*/
|
||||
int
|
||||
yang_modules_state_get(clicon_handle h,
|
||||
yang_modules_state_get(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
char *xpath,
|
||||
cvec *nsc,
|
||||
|
|
@ -353,7 +354,7 @@ yang_modules_state_get(clicon_handle h,
|
|||
}
|
||||
else { /* No cache -> build the tree */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "clicon buffer");
|
||||
clixon_err(OE_UNIX, 0, "clicon buffer");
|
||||
goto done;
|
||||
}
|
||||
/* Build a cb string: <modules-state>... */
|
||||
|
|
@ -363,7 +364,7 @@ yang_modules_state_get(clicon_handle h,
|
|||
* Note, list is not sorted since it is state (should not be)
|
||||
*/
|
||||
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){
|
||||
if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0)
|
||||
if (xret && netconf_operation_failed_xml(xret, "protocol", clixon_err_reason())< 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -419,7 +420,7 @@ yang_modules_state_get(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
mod_ns_upgrade(clicon_handle h,
|
||||
mod_ns_upgrade(clixon_handle h,
|
||||
cxobj *xt,
|
||||
cxobj *xmod,
|
||||
char *ns,
|
||||
|
|
@ -479,7 +480,7 @@ mod_ns_upgrade(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_module_upgrade(clicon_handle h,
|
||||
clixon_module_upgrade(clixon_handle h,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msd,
|
||||
cbuf *cbret)
|
||||
|
|
@ -490,7 +491,7 @@ clixon_module_upgrade(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if (msd == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "No modstate");
|
||||
clixon_err(OE_CFG, EINVAL, "No modstate");
|
||||
goto done;
|
||||
}
|
||||
if (msd->md_status == 0) /* No modstate in startup */
|
||||
|
|
@ -542,12 +543,12 @@ yang_find_module_by_prefix(yang_stmt *ys,
|
|||
char *myprefix;
|
||||
|
||||
if ((yspec = ys_spec(ys)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "My yang spec not found");
|
||||
clixon_err(OE_YANG, 0, "My yang spec not found");
|
||||
goto done;
|
||||
}
|
||||
/* First try own module */
|
||||
if ((my_ymod = ys_module(ys)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "My yang module not found");
|
||||
clixon_err(OE_YANG, 0, "My yang module not found");
|
||||
goto done;
|
||||
}
|
||||
myprefix = yang_find_myprefix(ys);
|
||||
|
|
@ -567,7 +568,7 @@ yang_find_module_by_prefix(yang_stmt *ys,
|
|||
}
|
||||
if (yimport){
|
||||
if ((ymod = yang_find(yspec, Y_MODULE, yang_argument_get(yimport))) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No module or sub-module found with prefix %s",
|
||||
clixon_err(OE_YANG, 0, "No module or sub-module found with prefix %s",
|
||||
prefix);
|
||||
yimport = NULL;
|
||||
goto done; /* unresolved */
|
||||
|
|
@ -644,7 +645,7 @@ yang_find_module_by_namespace_revision(yang_stmt *yspec,
|
|||
char *rev1;
|
||||
|
||||
if (ns == NULL || rev == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "No ns or rev");
|
||||
clixon_err(OE_CFG, EINVAL, "No ns or rev");
|
||||
goto done;
|
||||
}
|
||||
while ((ymod = yn_each(yspec, ymod)) != NULL) {
|
||||
|
|
@ -680,7 +681,7 @@ yang_find_module_by_name_revision(yang_stmt *yspec,
|
|||
char *rev1;
|
||||
|
||||
if (name == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "No ns or rev");
|
||||
clixon_err(OE_CFG, EINVAL, "No ns or rev");
|
||||
goto done;
|
||||
}
|
||||
while ((ymod = yn_each(yspec, ymod)) != NULL) {
|
||||
|
|
@ -739,7 +740,7 @@ yang_find_module_by_name(yang_stmt *yspec,
|
|||
* @see yang_metadata_annotation_check
|
||||
*/
|
||||
static int
|
||||
ietf_yang_metadata_extension_cb(clicon_handle h,
|
||||
ietf_yang_metadata_extension_cb(clixon_handle h,
|
||||
yang_stmt *yext,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
|
|
@ -816,7 +817,7 @@ yang_metadata_annotation_check(cxobj *xa,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_metadata_init(clicon_handle h)
|
||||
yang_metadata_init(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
clixon_plugin_t *cp = NULL;
|
||||
|
|
@ -847,7 +848,7 @@ yang_metadata_init(clicon_handle h)
|
|||
* XXX: Ensure yang-lib is always there otherwise get state dont work for mountpoint
|
||||
*/
|
||||
int
|
||||
yang_lib2yspec(clicon_handle h,
|
||||
yang_lib2yspec(clixon_handle h,
|
||||
cxobj *xyanglib,
|
||||
yang_stmt *yspec)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -193,6 +193,7 @@
|
|||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_yang_parse_lib.h"
|
||||
#include "clixon_yang_parse.h"
|
||||
|
|
@ -219,7 +220,7 @@ void
|
|||
clixon_yang_parseerror(void *_yy,
|
||||
char *s)
|
||||
{
|
||||
clicon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'",
|
||||
clixon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'",
|
||||
_YY->yy_name,
|
||||
_YY->yy_linenum,
|
||||
s,
|
||||
|
|
@ -252,7 +253,7 @@ ystack_pop(clixon_yang_yacc *yy)
|
|||
struct ys_stack *ystack;
|
||||
|
||||
if ((ystack = yy->yy_stack) == NULL){
|
||||
clicon_err(OE_YANG, 0, "ystack is NULL");
|
||||
clixon_err(OE_YANG, 0, "ystack is NULL");
|
||||
return -1;
|
||||
}
|
||||
if (yang_sort_subelements(ystack->ys_node) < 0)
|
||||
|
|
@ -274,7 +275,7 @@ ystack_push(clixon_yang_yacc *yy,
|
|||
struct ys_stack *ystack;
|
||||
|
||||
if ((ystack = malloc(sizeof(*ystack))) == NULL) {
|
||||
clicon_err(OE_YANG, errno, "malloc");
|
||||
clixon_err(OE_YANG, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(ystack, 0, sizeof(*ystack));
|
||||
|
|
@ -305,11 +306,11 @@ ysp_add(clixon_yang_yacc *yy,
|
|||
|
||||
ystack = yy->yy_stack;
|
||||
if (ystack == NULL){
|
||||
clicon_err(OE_YANG, errno, "No stack");
|
||||
clixon_err(OE_YANG, errno, "No stack");
|
||||
goto err;
|
||||
}
|
||||
if ((yn = ystack->ys_node) == NULL){
|
||||
clicon_err(OE_YANG, errno, "No ys_node");
|
||||
clixon_err(OE_YANG, errno, "No ys_node");
|
||||
goto err;
|
||||
}
|
||||
if ((ys = ys_new(keyword)) == NULL)
|
||||
|
|
|
|||
|
|
@ -74,13 +74,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_file.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_hash.h"
|
||||
|
|
@ -154,7 +155,7 @@ ys_grouping_module_resolve(yang_stmt *ymod,
|
|||
* @param[in] name Name of grouping to look for
|
||||
* @param[out] ygrouping0 A found grouping yang structure as result
|
||||
* @retval 0 OK, ygrouping may be NULL
|
||||
* @retval -1 Error, with clicon_err called
|
||||
* @retval -1 Error, with clixon_err called
|
||||
*/
|
||||
int
|
||||
ys_grouping_resolve(yang_stmt *yuses,
|
||||
|
|
@ -222,7 +223,7 @@ ys_grouping_resolve(yang_stmt *yuses,
|
|||
* a special "when" struct to the yang statements being inserted.
|
||||
*/
|
||||
static int
|
||||
yang_augment_node(clicon_handle h,
|
||||
yang_augment_node(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -238,7 +239,7 @@ yang_augment_node(clicon_handle h,
|
|||
enum rfc_6020 childkey;
|
||||
|
||||
if ((ymod = ys_module(ys)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "My yang module not found");
|
||||
clixon_err(OE_YANG, 0, "My yang module not found");
|
||||
goto done;
|
||||
}
|
||||
schema_nodeid = yang_argument_get(ys);
|
||||
|
|
@ -252,7 +253,7 @@ yang_augment_node(clicon_handle h,
|
|||
/* Log a warning and proceed if augment target not found
|
||||
* This may be necessary with some broken models
|
||||
*/
|
||||
clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found",
|
||||
clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found",
|
||||
yang_argument_get(ys_module(ys)),
|
||||
schema_nodeid);
|
||||
goto ok;
|
||||
|
|
@ -261,7 +262,7 @@ yang_augment_node(clicon_handle h,
|
|||
/* Fail with fatal error if augment target not found
|
||||
* This is "correct"
|
||||
*/
|
||||
clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found",
|
||||
clixon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found",
|
||||
yang_argument_get(ys_module(ys)),
|
||||
schema_nodeid);
|
||||
goto done;
|
||||
|
|
@ -302,7 +303,7 @@ yang_augment_node(clicon_handle h,
|
|||
/* Special case if yc0 is disabled by if-feature=false, then it is transformed to ANYDATA
|
||||
*/
|
||||
if (yang_flag_get(yc0, YANG_FLAG_DISABLED) == 0)
|
||||
clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)",
|
||||
clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)",
|
||||
yang_argument_get(ys_module(ys)),
|
||||
yang_argument_get(yc0),
|
||||
yang_key2str(childkey),
|
||||
|
|
@ -321,7 +322,7 @@ yang_augment_node(clicon_handle h,
|
|||
if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
|
||||
childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE &&
|
||||
childkey != Y_UNKNOWN){
|
||||
clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
|
||||
clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
|
||||
yang_argument_get(ys_module(ys)),
|
||||
yang_key2str(childkey),
|
||||
childkey,
|
||||
|
|
@ -342,7 +343,7 @@ yang_augment_node(clicon_handle h,
|
|||
childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF &&
|
||||
childkey != Y_LIST && childkey != Y_LEAF_LIST){
|
||||
|
||||
clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
|
||||
clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
|
||||
yang_argument_get(ys_module(ys)),
|
||||
yang_key2str(childkey),
|
||||
childkey,
|
||||
|
|
@ -398,7 +399,7 @@ yang_augment_node(clicon_handle h,
|
|||
* another module not yet augmented.
|
||||
*/
|
||||
static int
|
||||
yang_augment_module(clicon_handle h,
|
||||
yang_augment_module(clixon_handle h,
|
||||
yang_stmt *ymod)
|
||||
|
||||
{
|
||||
|
|
@ -558,7 +559,7 @@ yang_expand_uses_node(yang_stmt *yn,
|
|||
if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0)
|
||||
goto done;
|
||||
if (ygrouping == NULL){
|
||||
clicon_log(LOG_NOTICE, "%s: Yang error : grouping \"%s\" not found in module \"%s\"",
|
||||
clixon_log(NULL, LOG_NOTICE, "%s: Yang error : grouping \"%s\" not found in module \"%s\"",
|
||||
__FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -567,7 +568,7 @@ yang_expand_uses_node(yang_stmt *yn,
|
|||
yp = yn;
|
||||
do {
|
||||
if (yp == ygrouping){
|
||||
clicon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself",
|
||||
clixon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself",
|
||||
yang_argument_get(ys),
|
||||
yang_argument_get(ys_module(yn))
|
||||
);
|
||||
|
|
@ -609,7 +610,7 @@ yang_expand_uses_node(yang_stmt *yn,
|
|||
size = (yang_len_get(yn) - i - 1)*sizeof(struct yang_stmt *);
|
||||
yn->ys_len += glen;
|
||||
if ((yn->ys_stmt = realloc(yn->ys_stmt, (yang_len_get(yn))*sizeof(yang_stmt *))) == 0){
|
||||
clicon_err(OE_YANG, errno, "realloc");
|
||||
clixon_err(OE_YANG, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
/* Here, glen last elements are not initialized.
|
||||
|
|
@ -676,7 +677,7 @@ yang_expand_uses_node(yang_stmt *yn,
|
|||
* If a key leaf is defined in a grouping that is used in a list, the
|
||||
* "uses" statement MUST NOT have a "when" statement.
|
||||
*/
|
||||
clicon_err(OE_YANG, 0, "Key leaf '%s' defined in grouping '%s' is used in a 'uses' statement, This is not allowed according to RFC 7950 Sec 7.21.5",
|
||||
clixon_err(OE_YANG, 0, "Key leaf '%s' defined in grouping '%s' is used in a 'uses' statement, This is not allowed according to RFC 7950 Sec 7.21.5",
|
||||
yang_argument_get(yg),
|
||||
yang_argument_get(ygrouping)
|
||||
);
|
||||
|
|
@ -795,7 +796,7 @@ yang_parse_str(char *str,
|
|||
yang_stmt *ymod = NULL;
|
||||
|
||||
if (yspec == NULL){
|
||||
clicon_err(OE_YANG, 0, "Yang parse need top level yang spec");
|
||||
clixon_err(OE_YANG, 0, "Yang parse need top level yang spec");
|
||||
goto done;
|
||||
}
|
||||
yy.yy_name = (char*)name;
|
||||
|
|
@ -811,9 +812,9 @@ yang_parse_str(char *str,
|
|||
if (yang_parse_init(&yy) < 0)
|
||||
goto done;
|
||||
if (clixon_yang_parseparse(&yy) != 0) { /* yacc returns 1 on error */
|
||||
clicon_log(LOG_NOTICE, "Yang error: %s on line %d", name, yy.yy_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_YANG, 0, "yang parser error with no error code (should not happen)");
|
||||
clixon_log(NULL, LOG_NOTICE, "Yang error: %s on line %d", name, yy.yy_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_YANG, 0, "yang parser error with no error code (should not happen)");
|
||||
yang_parse_exit(&yy);
|
||||
yang_scan_exit(&yy);
|
||||
goto done;
|
||||
|
|
@ -824,7 +825,7 @@ yang_parse_str(char *str,
|
|||
goto done;
|
||||
}
|
||||
if ((ymod = yy.yy_module) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No module in YANG %s", name);
|
||||
clixon_err(OE_YANG, 0, "No module in YANG %s", name);
|
||||
goto done;
|
||||
}
|
||||
/* Add filename for debugging and errors, see also ys_linenum on (each symbol?) */
|
||||
|
|
@ -860,21 +861,21 @@ yang_parse_file(FILE *fp,
|
|||
|
||||
len = BUFLEN; /* any number is fine */
|
||||
if ((buf = malloc(len)) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(buf, 0, len);
|
||||
i = 0; /* position in buf */
|
||||
while (1){ /* read the whole file */
|
||||
if ((ret = fread(&c, 1, 1, fp)) < 0){
|
||||
clicon_err(OE_XML, errno, "read");
|
||||
clixon_err(OE_XML, errno, "read");
|
||||
break;
|
||||
}
|
||||
if (ret == 0)
|
||||
break; /* eof */
|
||||
if (i == len-1){
|
||||
if ((buf = realloc(buf, 2*len)) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
memset(buf+len, 0, len);
|
||||
|
|
@ -909,7 +910,7 @@ filename2revision(const char *filename,
|
|||
|
||||
/* base = module name [+ @rev ] + .yang */
|
||||
if ((base = strdup(filename)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, base);
|
||||
|
|
@ -943,7 +944,7 @@ filename2revision(const char *filename,
|
|||
* @note for bootstrapping, dir may have to be set.
|
||||
*/
|
||||
int
|
||||
yang_file_find_match(clicon_handle h,
|
||||
yang_file_find_match(clixon_handle h,
|
||||
const char *module,
|
||||
const char *revision,
|
||||
cbuf *fbuf)
|
||||
|
|
@ -961,7 +962,7 @@ yang_file_find_match(clicon_handle h,
|
|||
if ((x = clicon_conf_xml(h)) == NULL)
|
||||
goto ok;
|
||||
if ((regex = cbuf_new()) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cbuf_new");
|
||||
clixon_err(OE_YANG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* RFC 6020: The name of the file SHOULD be of the form:
|
||||
|
|
@ -1004,7 +1005,7 @@ yang_file_find_match(clicon_handle h,
|
|||
(dir = xml_body(xc)) != NULL){
|
||||
/* get all matching files in this directory recursively */
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_files_recursive(dir, cbuf_get(regex), cvv) < 0)
|
||||
|
|
@ -1055,7 +1056,7 @@ done:
|
|||
* See top of file for diagram of calling order
|
||||
*/
|
||||
yang_stmt *
|
||||
yang_parse_filename(clicon_handle h,
|
||||
yang_parse_filename(clixon_handle h,
|
||||
const char *filename,
|
||||
yang_stmt *yspec)
|
||||
{
|
||||
|
|
@ -1065,11 +1066,11 @@ yang_parse_filename(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename);
|
||||
if (stat(filename, &st) < 0){
|
||||
clicon_err(OE_YANG, errno, "%s not found", filename);
|
||||
clixon_err(OE_YANG, errno, "%s not found", filename);
|
||||
goto done;
|
||||
}
|
||||
if ((fp = fopen(filename, "r")) == NULL){
|
||||
clicon_err(OE_YANG, errno, "fopen(%s)", filename);
|
||||
clixon_err(OE_YANG, errno, "fopen(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
if ((ymod = yang_parse_file(fp, filename, yspec)) < 0)
|
||||
|
|
@ -1098,7 +1099,7 @@ yang_parse_filename(clicon_handle h,
|
|||
* @note does not check wether the module is already loaded
|
||||
*/
|
||||
yang_stmt *
|
||||
yang_parse_module(clicon_handle h,
|
||||
yang_parse_module(clixon_handle h,
|
||||
const char *module,
|
||||
const char *revision,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -1114,7 +1115,7 @@ yang_parse_module(clicon_handle h,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((fbuf = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Match a yang file with or without revision in yang-dir list */
|
||||
|
|
@ -1122,16 +1123,16 @@ yang_parse_module(clicon_handle h,
|
|||
goto done;
|
||||
if (nr == 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s", module);
|
||||
if (revision)
|
||||
cprintf(cb, "@%s", revision);
|
||||
if (origname)
|
||||
clicon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs when loading %s.yang", cbuf_get(cb), origname);
|
||||
clixon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs when loading %s.yang", cbuf_get(cb), origname);
|
||||
else
|
||||
clicon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs", cbuf_get(cb));
|
||||
clixon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs", cbuf_get(cb));
|
||||
goto done;
|
||||
}
|
||||
filename = cbuf_get(fbuf);
|
||||
|
|
@ -1142,7 +1143,7 @@ yang_parse_module(clicon_handle h,
|
|||
* RFC 7950 Sec 5.2
|
||||
*/
|
||||
if (strcmp(yang_argument_get(ymod), module) != 0){
|
||||
clicon_err(OE_YANG, EINVAL, "File %s contains yang module \"%s\" which does not match expected module %s",
|
||||
clixon_err(OE_YANG, EINVAL, "File %s contains yang module \"%s\" which does not match expected module %s",
|
||||
filename,
|
||||
yang_argument_get(ymod),
|
||||
module);
|
||||
|
|
@ -1159,7 +1160,7 @@ yang_parse_module(clicon_handle h,
|
|||
goto done;
|
||||
/* Sanity check that file revision does not match internal rev stmt */
|
||||
if (revf && revm && revm != revf){
|
||||
clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s vs %u", filename, revm);
|
||||
clixon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s vs %u", filename, revm);
|
||||
ymod = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1183,7 +1184,7 @@ yang_parse_module(clicon_handle h,
|
|||
* See top of file for diagram of calling order
|
||||
*/
|
||||
static int
|
||||
yang_parse_recurse(clicon_handle h,
|
||||
yang_parse_recurse(clixon_handle h,
|
||||
yang_stmt *ymod,
|
||||
yang_stmt *ysp)
|
||||
{
|
||||
|
|
@ -1222,11 +1223,11 @@ yang_parse_recurse(clicon_handle h,
|
|||
if (keyw == Y_INCLUDE){
|
||||
ybelongto = yang_find(subymod, Y_BELONGS_TO, NULL);
|
||||
if (ybelongto == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" does not have a belongs-to statement", submodule); /* shouldnt happen */
|
||||
clixon_err(OE_YANG, ENOENT, "Sub-module \"%s\" does not have a belongs-to statement", submodule); /* shouldnt happen */
|
||||
goto done;
|
||||
}
|
||||
if (strcmp(yang_argument_get(ybelongto), yang_argument_get(yrealmod)) != 0){
|
||||
clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" references module \"%s\" in its belongs-to statement but should reference \"%s\"",
|
||||
clixon_err(OE_YANG, ENOENT, "Sub-module \"%s\" references module \"%s\" in its belongs-to statement but should reference \"%s\"",
|
||||
submodule,
|
||||
yang_argument_get(ybelongto),
|
||||
yang_argument_get(yrealmod));
|
||||
|
|
@ -1257,7 +1258,7 @@ yang_parse_recurse(clicon_handle h,
|
|||
* Unless it is the "errors" rule of the ietf-restconf spec which seems to be a special case.
|
||||
*/
|
||||
static int
|
||||
ys_list_check(clicon_handle h,
|
||||
ys_list_check(clixon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1281,7 +1282,7 @@ ys_list_check(clicon_handle h,
|
|||
/* Except nokey exceptions such as rrc 8040 yang-data */
|
||||
if (!yang_flag_get(yroot, YANG_FLAG_NOKEY)){
|
||||
/* Note obsolete */
|
||||
clicon_log(LOG_ERR, "Error: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)",
|
||||
clixon_log(h, LOG_ERR, "Error: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)",
|
||||
yang_argument_get(ys),
|
||||
yang_argument_get(ymod)
|
||||
);
|
||||
|
|
@ -1325,7 +1326,7 @@ ys_visit(struct yang_stmt *yn,
|
|||
|
||||
if (yn == NULL ||
|
||||
(yang_keyword_get(yn) != Y_MODULE && yang_keyword_get(yn) != Y_SUBMODULE)){
|
||||
clicon_err(OE_YANG, EINVAL, "Expected module or submodule");
|
||||
clixon_err(OE_YANG, EINVAL, "Expected module or submodule");
|
||||
goto done;
|
||||
}
|
||||
yspec = ys_spec(yn);
|
||||
|
|
@ -1334,7 +1335,7 @@ ys_visit(struct yang_stmt *yn,
|
|||
return 0;
|
||||
/* if n has a temporary mark then stop (not a DAG) */
|
||||
if (yang_flag_get(yn, YANG_FLAG_TMP)){
|
||||
clicon_err(OE_YANG, EFAULT, "Yang module %s import/include is circular", yang_argument_get(yn));
|
||||
clixon_err(OE_YANG, EFAULT, "Yang module %s import/include is circular", yang_argument_get(yn));
|
||||
goto done;
|
||||
}
|
||||
/* mark n with a temporary mark */
|
||||
|
|
@ -1349,7 +1350,7 @@ ys_visit(struct yang_stmt *yn,
|
|||
continue;
|
||||
if ((ymod = yang_find(yspec, Y_MODULE, yang_argument_get(yi))) == NULL &&
|
||||
(ymod = yang_find(yspec, Y_SUBMODULE, yang_argument_get(yi))) == NULL){
|
||||
clicon_err(OE_YANG, EFAULT, "Yang module %s import/include not found",
|
||||
clixon_err(OE_YANG, EFAULT, "Yang module %s import/include not found",
|
||||
yang_argument_get(yi)); /* shouldnt happen */
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1363,7 +1364,7 @@ ys_visit(struct yang_stmt *yn,
|
|||
/* add n to head of L. NB reversed */
|
||||
(*ylen)++;
|
||||
if ((*ylist = realloc(*ylist, (*ylen)*sizeof(yang_stmt *))) == 0){
|
||||
clicon_err(OE_YANG, errno, "realloc");
|
||||
clixon_err(OE_YANG, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
(*ylist)[*ylen - 1] = yn;
|
||||
|
|
@ -1404,7 +1405,7 @@ yang_sort_modules(yang_stmt *yspec,
|
|||
}
|
||||
}
|
||||
if (*ylen != modmax-modmin){
|
||||
clicon_err(OE_YANG, EFAULT, "Internal error: mismatch sort vector lengths");
|
||||
clixon_err(OE_YANG, EFAULT, "Internal error: mismatch sort vector lengths");
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -1434,7 +1435,7 @@ yang_sort_modules(yang_stmt *yspec,
|
|||
* @retval -1 Error encountered
|
||||
*/
|
||||
int
|
||||
yang_parse_post(clicon_handle h,
|
||||
yang_parse_post(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
int modmin)
|
||||
{
|
||||
|
|
@ -1445,7 +1446,7 @@ yang_parse_post(clicon_handle h,
|
|||
int ylen = 0; /* Length of ylist */
|
||||
|
||||
if (modmin < 0){
|
||||
clicon_err(OE_YANG, EINVAL, "modmin negative");
|
||||
clixon_err(OE_YANG, EINVAL, "modmin negative");
|
||||
goto done;
|
||||
}
|
||||
/* 1: Parse from text to yang parse-tree.
|
||||
|
|
@ -1555,7 +1556,7 @@ yang_parse_post(clicon_handle h,
|
|||
* @see yang_spec_parse_file
|
||||
*/
|
||||
int
|
||||
yang_spec_parse_module(clicon_handle h,
|
||||
yang_spec_parse_module(clixon_handle h,
|
||||
const char *name,
|
||||
const char *revision,
|
||||
yang_stmt *yspec)
|
||||
|
|
@ -1565,11 +1566,11 @@ yang_spec_parse_module(clicon_handle h,
|
|||
char *base = NULL;;
|
||||
|
||||
if (yspec == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "yang spec is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "yang spec is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (name == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "yang module not set");
|
||||
clixon_err(OE_YANG, EINVAL, "yang module not set");
|
||||
goto done;
|
||||
}
|
||||
/* Apply steps 2.. on new modules, ie ones after modmin. */
|
||||
|
|
@ -1602,7 +1603,7 @@ yang_spec_parse_module(clicon_handle h,
|
|||
* @see yang_spec_load_dir For loading all files in a directory
|
||||
*/
|
||||
int
|
||||
yang_spec_parse_file(clicon_handle h,
|
||||
yang_spec_parse_file(clixon_handle h,
|
||||
char *filename,
|
||||
yang_stmt *yspec)
|
||||
{
|
||||
|
|
@ -1614,11 +1615,11 @@ yang_spec_parse_file(clicon_handle h,
|
|||
modmin = yang_len_get(yspec);
|
||||
/* Find module, and do not load file if module already exists */
|
||||
if (basename(filename) == NULL){
|
||||
clicon_err(OE_YANG, errno, "No basename");
|
||||
clixon_err(OE_YANG, errno, "No basename");
|
||||
goto done;
|
||||
}
|
||||
if ((base = strdup(basename(filename))) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if (index(base, '@') != NULL)
|
||||
|
|
@ -1654,7 +1655,7 @@ yang_spec_parse_file(clicon_handle h,
|
|||
* the oldest module if 1-3 for some reason fails.
|
||||
*/
|
||||
int
|
||||
yang_spec_load_dir(clicon_handle h,
|
||||
yang_spec_load_dir(clixon_handle h,
|
||||
char *dir,
|
||||
yang_stmt *yspec)
|
||||
{
|
||||
|
|
@ -1737,7 +1738,7 @@ yang_spec_load_dir(clicon_handle h,
|
|||
revm = cv_uint32_get(yang_cv_get(yrev));
|
||||
/* Sanity check that file revision does not match internal rev stmt */
|
||||
if (revf && revm && revm != revf){ /* XXX */
|
||||
clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s(%u) vs %u", filename, revf, revm);
|
||||
clixon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s(%u) vs %u", filename, revf, revm);
|
||||
goto done;
|
||||
}
|
||||
/* If ym0 and ym exists, delete the yang with oldest revision
|
||||
|
|
@ -1783,21 +1784,21 @@ ys_parse_date_arg(char *datearg,
|
|||
uint32_t d = 0;
|
||||
|
||||
if (strlen(datearg) != 10 || datearg[4] != '-' || datearg[7] != '-'){
|
||||
clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
goto done;
|
||||
}
|
||||
if ((i = cligen_tonum(4, datearg)) < 0){
|
||||
clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
goto done;
|
||||
}
|
||||
d = i*10000; /* year */
|
||||
if ((i = cligen_tonum(2, &datearg[5])) < 0){
|
||||
clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
goto done;
|
||||
}
|
||||
d += i*100; /* month */
|
||||
if ((i = cligen_tonum(2, &datearg[8])) < 0){
|
||||
clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg);
|
||||
goto done;
|
||||
}
|
||||
d += i; /* day */
|
||||
|
|
@ -1827,15 +1828,15 @@ ys_parse(yang_stmt *ys,
|
|||
yang_cv_set(ys, NULL);
|
||||
}
|
||||
if ((cv = cv_new(cvtype)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if ((cvret = cv_parse1(yang_argument_get(ys), cv, &reason)) < 0){ /* error */
|
||||
clicon_err(OE_YANG, errno, "parsing cv");
|
||||
clixon_err(OE_YANG, errno, "parsing cv");
|
||||
goto done;
|
||||
}
|
||||
if (cvret == 0){ /* parsing failed */
|
||||
clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
clixon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
goto done;
|
||||
}
|
||||
yang_cv_set(ys, cv);
|
||||
|
|
@ -1895,12 +1896,12 @@ ys_parse_sub(yang_stmt *ys,
|
|||
if (ys_parse(ys, CGV_UINT8) == NULL)
|
||||
goto done;
|
||||
if ((cv = yang_cv_get(ys)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "Unexpected NULL cv");
|
||||
clixon_err(OE_YANG, ENOENT, "Unexpected NULL cv");
|
||||
goto done;
|
||||
}
|
||||
fd = cv_uint8_get(cv);
|
||||
if (fd < 1 || fd > 18){
|
||||
clicon_err(OE_YANG, errno, "%u: Out of range, should be [1:18]", fd);
|
||||
clixon_err(OE_YANG, errno, "%u: Out of range, should be [1:18]", fd);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1914,7 +1915,7 @@ ys_parse_sub(yang_stmt *ys,
|
|||
if (ys_parse_date_arg(arg, &date) < 0)
|
||||
goto done;
|
||||
if ((cv = cv_new(CGV_UINT32)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
yang_cv_set(ys, cv);
|
||||
|
|
@ -1924,7 +1925,7 @@ ys_parse_sub(yang_stmt *ys,
|
|||
if (strcmp(arg, "current") &&
|
||||
strcmp(arg, "deprecated") &&
|
||||
strcmp(arg, "obsolete")){
|
||||
clicon_err(OE_YANG, errno, "Invalid status: \"%s\", expected current, deprecated, or obsolete", arg);
|
||||
clixon_err(OE_YANG, errno, "Invalid status: \"%s\", expected current, deprecated, or obsolete", arg);
|
||||
goto done;
|
||||
|
||||
}
|
||||
|
|
@ -1932,7 +1933,7 @@ ys_parse_sub(yang_stmt *ys,
|
|||
case Y_MAX_ELEMENTS:
|
||||
case Y_MIN_ELEMENTS:
|
||||
if ((cv = cv_new(CGV_UINT32)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
yang_cv_set(ys, cv);
|
||||
|
|
@ -1941,11 +1942,11 @@ ys_parse_sub(yang_stmt *ys,
|
|||
cv_uint32_set(cv, 0); /* 0 means unbounded for max */
|
||||
else{
|
||||
if ((ret = parse_uint32(arg, &minmax, &reason)) < 0){
|
||||
clicon_err(OE_YANG, errno, "parse_uint32");
|
||||
clixon_err(OE_YANG, errno, "parse_uint32");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_YANG, EINVAL, "element-min/max parse error: %s", reason);
|
||||
clixon_err(OE_YANG, EINVAL, "element-min/max parse error: %s", reason);
|
||||
if (reason)
|
||||
free(reason);
|
||||
goto done;
|
||||
|
|
@ -1955,7 +1956,7 @@ ys_parse_sub(yang_stmt *ys,
|
|||
break;
|
||||
case Y_MODIFIER:
|
||||
if (strcmp(yang_argument_get(ys), "invert-match")){
|
||||
clicon_err(OE_YANG, EINVAL, "modifier %s, expected invert-match", yang_argument_get(ys));
|
||||
clixon_err(OE_YANG, EINVAL, "modifier %s, expected invert-match", yang_argument_get(ys));
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1987,16 +1988,16 @@ ys_parse_sub(yang_stmt *ys,
|
|||
if (extra == NULL)
|
||||
break;
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
yang_cv_set(ys, cv);
|
||||
if ((ret = cv_parse1(extra, cv, &reason)) < 0){ /* error */
|
||||
clicon_err(OE_YANG, errno, "parsing cv");
|
||||
clixon_err(OE_YANG, errno, "parsing cv");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){ /* parsing failed */
|
||||
clicon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
clixon_err(OE_YANG, errno, "Parsing CV: %s", reason);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@
|
|||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_io.h"
|
||||
|
|
@ -110,7 +111,7 @@ yang_schema_mount_point0(yang_stmt *y)
|
|||
char *value = NULL;
|
||||
|
||||
if (y == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "y is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "y is NULL");
|
||||
goto done;
|
||||
}
|
||||
keyw = yang_keyword_get(y);
|
||||
|
|
@ -160,7 +161,7 @@ yang_mount_get(yang_stmt *y,
|
|||
cvec *cvv;
|
||||
cg_var *cv;
|
||||
|
||||
clicon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y);
|
||||
/* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */
|
||||
if ((cvv = yang_cvec_get(y)) != NULL &&
|
||||
(cv = cvec_find(cvv, xpath)) != NULL &&
|
||||
|
|
@ -192,7 +193,7 @@ yang_mount_set(yang_stmt *y,
|
|||
cg_var *cv;
|
||||
cg_var *cv2;
|
||||
|
||||
clicon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y);
|
||||
if ((cvv = yang_cvec_get(y)) != NULL &&
|
||||
(cv = cvec_find(cvv, xpath)) != NULL &&
|
||||
(yspec0 = cv_void_get(cv)) != NULL){
|
||||
|
|
@ -204,11 +205,11 @@ yang_mount_set(yang_stmt *y,
|
|||
else if ((cv = yang_cvec_add(y, CGV_VOID, xpath)) == NULL)
|
||||
goto done;
|
||||
if ((cv2 = cv_new(CGV_STRING)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cv_new");
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (cv_string_set(cv2, xpath) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_string_set");
|
||||
clixon_err(OE_UNIX, errno, "cv_string_set");
|
||||
goto done;
|
||||
}
|
||||
/* tag yspec with key/xpath */
|
||||
|
|
@ -231,7 +232,7 @@ yang_mount_set(yang_stmt *y,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xml_yang_mount_get(clicon_handle h,
|
||||
xml_yang_mount_get(clixon_handle h,
|
||||
cxobj *xt,
|
||||
validate_level *vl,
|
||||
yang_stmt **yspec)
|
||||
|
|
@ -293,7 +294,7 @@ xml_yang_mount_get(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xml_yang_mount_set(clicon_handle h,
|
||||
xml_yang_mount_set(clixon_handle h,
|
||||
cxobj *x,
|
||||
yang_stmt *yspec)
|
||||
{
|
||||
|
|
@ -308,7 +309,7 @@ xml_yang_mount_set(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((y = xml_spec(x)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No yang-spec");
|
||||
clixon_err(OE_YANG, 0, "No yang-spec");
|
||||
goto done;
|
||||
}
|
||||
if (xml2xpath(x, NULL, 1, 0, &xpath0) < 0)
|
||||
|
|
@ -319,7 +320,7 @@ xml_yang_mount_set(clicon_handle h,
|
|||
if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc1, &reason)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_err(OE_YANG, 0, "%s", cbuf_get(reason));
|
||||
clixon_err(OE_YANG, 0, "%s", cbuf_get(reason));
|
||||
goto done;
|
||||
}
|
||||
if (yang_mount_set(y, xpath1, yspec) < 0)
|
||||
|
|
@ -413,7 +414,7 @@ find_schema_mounts(cxobj *x,
|
|||
if (ret == 0)
|
||||
return 0;
|
||||
if ((cv = cvec_add(cvv, CGV_VOID)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add");
|
||||
return -1;
|
||||
}
|
||||
cv_void_set(cv, x);
|
||||
|
|
@ -442,7 +443,7 @@ find_schema_mounts(cxobj *x,
|
|||
* @note: Mountpoints must exist in xret on entry
|
||||
*/
|
||||
static int
|
||||
yang_schema_mount_statedata_yanglib(clicon_handle h,
|
||||
yang_schema_mount_statedata_yanglib(clixon_handle h,
|
||||
char *xpath,
|
||||
cvec *nsc,
|
||||
cxobj **xret,
|
||||
|
|
@ -460,11 +461,11 @@ yang_schema_mount_statedata_yanglib(clicon_handle h,
|
|||
validate_level vl = VL_FULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "clicon buffer");
|
||||
clixon_err(OE_UNIX, 0, "clicon buffer");
|
||||
goto done;
|
||||
}
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml_apply(*xret, CX_ELMNT, find_schema_mounts, cvv) < 0)
|
||||
|
|
@ -513,7 +514,7 @@ yang_schema_mount_statedata_yanglib(clicon_handle h,
|
|||
* @note Only "inline" specification of mounted schema supported, not "shared schema"
|
||||
*/
|
||||
int
|
||||
yang_schema_mount_statedata(clicon_handle h,
|
||||
yang_schema_mount_statedata(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
char *xpath,
|
||||
cvec *nsc,
|
||||
|
|
@ -536,12 +537,12 @@ yang_schema_mount_statedata(clicon_handle h,
|
|||
if ((ymodext = yang_find(yspec, Y_MODULE, "ietf-yang-schema-mount")) == NULL ||
|
||||
(yext = yang_find(ymodext, Y_EXTENSION, "mount-point")) == NULL){
|
||||
goto ok;
|
||||
// clicon_err(OE_YANG, 0, "yang schema mount-point extension not found");
|
||||
// clixon_err(OE_YANG, 0, "yang schema mount-point extension not found");
|
||||
// goto done;
|
||||
}
|
||||
if ((cvv = yang_cvec_get(yext)) != NULL){
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<schema-mounts xmlns=\"%s\">", YANG_SCHEMA_MOUNT_NAMESPACE); // XXX only if hit
|
||||
|
|
@ -550,7 +551,7 @@ yang_schema_mount_statedata(clicon_handle h,
|
|||
ymount = (yang_stmt*)cv_void_get(cv);
|
||||
ymod = ys_module(ymount);
|
||||
if ((cv1 = yang_cv_get(ymount)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "mount-point extension must have label");
|
||||
clixon_err(OE_YANG, 0, "mount-point extension must have label");
|
||||
goto done;
|
||||
}
|
||||
label = cv_string_get(cv1);
|
||||
|
|
@ -596,7 +597,7 @@ yang_schema_mount_statedata(clicon_handle h,
|
|||
* @see yang_schema_mount_statedata
|
||||
*/
|
||||
int
|
||||
yang_schema_mount_statistics(clicon_handle h,
|
||||
yang_schema_mount_statistics(clixon_handle h,
|
||||
cxobj *xt,
|
||||
int modules,
|
||||
cbuf *cb)
|
||||
|
|
@ -613,7 +614,7 @@ yang_schema_mount_statistics(clicon_handle h,
|
|||
size_t sz;
|
||||
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml_apply(xt, CX_ELMNT, find_schema_mounts, cvv) < 0)
|
||||
|
|
@ -670,7 +671,7 @@ yang_schema_mount_statistics(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_schema_yanglib_parse_mount(clicon_handle h,
|
||||
yang_schema_yanglib_parse_mount(clixon_handle h,
|
||||
cxobj *xt)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -718,7 +719,7 @@ yang_schema_yanglib_parse_mount(clicon_handle h,
|
|||
* XXX maybe not needed
|
||||
*/
|
||||
int
|
||||
yang_schema_get_child(clicon_handle h,
|
||||
yang_schema_get_child(clixon_handle h,
|
||||
cxobj *x1,
|
||||
cxobj *x1c,
|
||||
yang_stmt **yc)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
/* typecast macro */
|
||||
#define _IF ((clixon_yang_schemanode_yacc *)_if)
|
||||
#define _YYERROR(msg) {clicon_err(OE_YANG, 0, "%s", (msg)); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_YANG, 0, "%s", (msg)); YYERROR;}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -78,13 +78,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_yang_module.h"
|
||||
|
|
@ -106,7 +107,7 @@ clixon_yang_schemanode_parseerror(void *arg,
|
|||
{
|
||||
clixon_yang_schemanode_yacc *ife = (clixon_yang_schemanode_yacc *)arg;
|
||||
|
||||
clicon_err_fn(NULL, 0, OE_YANG, 0, "yang_schemanode_parse: file:%s:%d \"%s\" %s: at or before: %s",
|
||||
clixon_err_fn(NULL, 0, OE_YANG, 0, "yang_schemanode_parse: file:%s:%d \"%s\" %s: at or before: %s",
|
||||
ife->if_mainfile,
|
||||
ife->if_linenum,
|
||||
ife->if_parse_string,
|
||||
|
|
|
|||
|
|
@ -47,12 +47,13 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_yang_sub_parse.h"
|
||||
#include "clixon_yang_schemanode_parse.h"
|
||||
|
|
@ -76,7 +77,7 @@ yang_subparse(char *str,
|
|||
const char *mainfile,
|
||||
int linenum,
|
||||
int *enabled,
|
||||
clicon_handle h)
|
||||
clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
clixon_yang_sub_parse_yacc ife = {0,};
|
||||
|
|
@ -92,8 +93,8 @@ yang_subparse(char *str,
|
|||
if (clixon_yang_sub_parsel_init(&ife) < 0)
|
||||
goto done;
|
||||
if (clixon_yang_sub_parseparse(&ife) != 0) { /* yacc returns 1 on error */
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_YANG, 0, "If-feature parser error with no error code (should not happen)");
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_YANG, 0, "If-feature parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
if (enabled)
|
||||
|
|
@ -131,8 +132,8 @@ yang_schema_nodeid_subparse(char *str,
|
|||
if (clixon_yang_schemanode_parsel_init(&ife) < 0)
|
||||
goto done;
|
||||
if (clixon_yang_schemanode_parseparse(&ife) != 0) { /* yacc returns 1 on error */
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_YANG, 0, "descendant-schema-nodeid parser error with no error code (should not happen)");
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_YANG, 0, "descendant-schema-nodeid parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ struct clixon_yang_sub_parse_yacc {
|
|||
yang_stmt *if_ys; /* Yang statement, NULL if no check */
|
||||
enum yang_sub_parse_accept if_accept; /* Which sub-parse rule to accept */
|
||||
int if_enabled; /* Result: 0: feature disabled, 1: enabled */
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
};
|
||||
typedef struct clixon_yang_sub_parse_yacc clixon_yang_sub_parse_yacc;
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ int clixon_yang_sub_parsel_linenr(void);
|
|||
int clixon_yang_sub_parselex(void *);
|
||||
int clixon_yang_sub_parseparse(void *);
|
||||
|
||||
int yang_subparse(char *str, yang_stmt *ys, enum yang_sub_parse_accept accept, const char *mainfile, int linenum, int *enabled, clicon_handle h);
|
||||
int yang_subparse(char *str, yang_stmt *ys, enum yang_sub_parse_accept accept, const char *mainfile, int linenum, int *enabled, clixon_handle h);
|
||||
int yang_schema_nodeid_subparse(char *str, enum yang_sub_parse_accept accept, const char *mainfile, int linenum);
|
||||
|
||||
#endif /* _CLIXON_YANG_SUB_PARSER_H_ */
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
/* typecast macro */
|
||||
#define _IF ((clixon_yang_sub_parse_yacc *)_if)
|
||||
#define _YYERROR(msg) {clicon_err(OE_YANG, 0, "%s", (msg)); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_YANG, 0, "%s", (msg)); YYERROR;}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -89,13 +89,14 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_yang_module.h"
|
||||
|
|
@ -116,7 +117,7 @@ clixon_yang_sub_parseerror(void *arg,
|
|||
{
|
||||
clixon_yang_sub_parse_yacc *ife = (clixon_yang_sub_parse_yacc *)arg;
|
||||
|
||||
clicon_err_fn(NULL, 0, OE_YANG, 0, "yang_sub_parse: file:%s:%d \"%s\" %s: at or before: %s",
|
||||
clixon_err_fn(NULL, 0, OE_YANG, 0, "yang_sub_parse: file:%s:%d \"%s\" %s: at or before: %s",
|
||||
ife->if_mainfile,
|
||||
ife->if_linenum,
|
||||
ife->if_parse_string,
|
||||
|
|
@ -157,7 +158,7 @@ if_feature_check(clixon_yang_sub_parse_yacc *ife,
|
|||
goto done;
|
||||
/* Check if feature exists, and is set, otherwise remove */
|
||||
if ((yfeat = yang_find(ymod, Y_FEATURE, feature)) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Yang module %s has IF_FEATURE %s, but no such FEATURE statement exists",
|
||||
clixon_err(OE_YANG, EINVAL, "Yang module %s has IF_FEATURE %s, but no such FEATURE statement exists",
|
||||
ymod?yang_argument_get(ymod):"none",
|
||||
feature);
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -83,15 +83,13 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_err.h"
|
||||
/* clixon */
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_regex.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_yang.h"
|
||||
#include "clixon_xml.h"
|
||||
#include "clixon_xml_nsctx.h"
|
||||
|
|
@ -174,7 +172,7 @@ yang_builtin(char *type)
|
|||
*
|
||||
* and re-store into "patterns" cvec.
|
||||
* This is done here instead of deep in resolve code (resolve_restrictions)
|
||||
* since it id dependent on clicon_handle.
|
||||
* since it id dependent on clixon_handle.
|
||||
* The downside is that all accesses to "patterns" must pass via the cache.
|
||||
* If calls to yang_type_resolve is made without the cache is set, will be
|
||||
* wrong.
|
||||
|
|
@ -182,7 +180,7 @@ yang_builtin(char *type)
|
|||
* @see yang_type_resolve_restrictions where patterns is set
|
||||
*/
|
||||
static int
|
||||
compile_pattern2regexp(clicon_handle h,
|
||||
compile_pattern2regexp(clixon_handle h,
|
||||
cvec *patterns,
|
||||
cvec *regexps)
|
||||
{
|
||||
|
|
@ -200,13 +198,13 @@ compile_pattern2regexp(clicon_handle h,
|
|||
if ((ret = regex_compile(h, pattern, &re)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_err(OE_YANG, errno, "regexp compile fail: \"%s\"",
|
||||
clixon_err(OE_YANG, errno, "regexp compile fail: \"%s\"",
|
||||
pattern);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
if ((rcv = cvec_add(regexps, CGV_VOID)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add");
|
||||
goto done;
|
||||
}
|
||||
if (re != NULL)
|
||||
|
|
@ -234,7 +232,7 @@ int
|
|||
ys_resolve_type(yang_stmt *ys,
|
||||
void *arg)
|
||||
{
|
||||
// clicon_handle h = (clicon_handle)arg;
|
||||
// clixon_handle h = (clixon_handle)arg;
|
||||
int retval = -1;
|
||||
int options = 0x0;
|
||||
cvec *cvv = NULL;
|
||||
|
|
@ -243,11 +241,11 @@ ys_resolve_type(yang_stmt *ys,
|
|||
yang_stmt *resolved = NULL;
|
||||
|
||||
if (yang_keyword_get(ys) != Y_TYPE){
|
||||
clicon_err(OE_YANG, EINVAL, "Expected Y_TYPE");
|
||||
clixon_err(OE_YANG, EINVAL, "Expected Y_TYPE");
|
||||
goto done;
|
||||
}
|
||||
if ((patterns = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
/* Recursively resolve ys -> resolve with restrictions(options, etc)
|
||||
|
|
@ -258,11 +256,11 @@ ys_resolve_type(yang_stmt *ys,
|
|||
&options, &cvv, patterns, NULL, &fraction) < 0)
|
||||
goto done;
|
||||
if (resolved == NULL){
|
||||
clicon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
goto done;
|
||||
}
|
||||
/* Cache the type resolving locally. Only place where this is done.
|
||||
* Why not do it in yang_type_resolve? (compile regexps needs clicon_handle)
|
||||
* Why not do it in yang_type_resolve? (compile regexps needs clixon_handle)
|
||||
*/
|
||||
if (yang_type_cache_set(ys, resolved, options, cvv,
|
||||
patterns, fraction) < 0)
|
||||
|
|
@ -366,7 +364,7 @@ clicon_type2cv(char *origtype,
|
|||
*/
|
||||
yang2cv_type(origtype, cvtype);
|
||||
if (*cvtype == CGV_ERR){
|
||||
clicon_err(OE_YANG, 0, "%s:\"%s\": type not resolved",
|
||||
clixon_err(OE_YANG, 0, "%s:\"%s\": type not resolved",
|
||||
yang_argument_get(ym), origtype);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -374,7 +372,7 @@ clicon_type2cv(char *origtype,
|
|||
else {
|
||||
yang2cv_type(restype, cvtype);
|
||||
if (*cvtype == CGV_ERR){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\" type not translated",
|
||||
clixon_err(OE_YANG, 0, "%s: \"%s\" type not translated",
|
||||
yang_argument_get(ym), restype);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -395,7 +393,7 @@ clicon_type2cv(char *origtype,
|
|||
* @retval -1 Error (fatal), with errno set to indicate error
|
||||
*/
|
||||
static int
|
||||
cv_validate_pattern(clicon_handle h,
|
||||
cv_validate_pattern(clixon_handle h,
|
||||
cvec *regexps,
|
||||
yang_stmt *yrestype,
|
||||
char *str,
|
||||
|
|
@ -462,7 +460,7 @@ outofrange(cg_var *cv0,
|
|||
while (i<cvec_len(cvv)){
|
||||
cv1 = cvec_i(cvv, i++); /* Increment to check for max pair */
|
||||
if (strcmp(cv_name_get(cv1),"range_min") != 0){
|
||||
clicon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
|
||||
clixon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
|
||||
goto done;
|
||||
}
|
||||
if (i<cvec_len(cvv) &&
|
||||
|
|
@ -512,7 +510,7 @@ outoflength(uint64_t u64,
|
|||
while (i<cvec_len(cvv)){
|
||||
cv1 = cvec_i(cvv, i++); /* Increment to check for max pair */
|
||||
if (strcmp(cv_name_get(cv1),"range_min") != 0){
|
||||
clicon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
|
||||
clixon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
|
||||
goto done;
|
||||
}
|
||||
if (i<cvec_len(cvv) &&
|
||||
|
|
@ -552,7 +550,7 @@ outoflength(uint64_t u64,
|
|||
* @see cv_validate Corresponding type check in cligen
|
||||
*/
|
||||
static int
|
||||
cv_validate1(clicon_handle h,
|
||||
cv_validate1(clixon_handle h,
|
||||
cg_var *cv,
|
||||
enum cv_type cvtype,
|
||||
int options,
|
||||
|
|
@ -590,7 +588,7 @@ cv_validate1(clicon_handle h,
|
|||
while (i<cvec_len(cvv)){
|
||||
cv1 = cvec_i(cvv, i++); /* Increment to check for max pair */
|
||||
if (strcmp(cv_name_get(cv1),"range_min") != 0){
|
||||
clicon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
|
||||
clixon_err(OE_YANG, EINVAL, "Internal error, expected range_min");
|
||||
goto done;
|
||||
}
|
||||
if (i<cvec_len(cvv) &&
|
||||
|
|
@ -755,11 +753,11 @@ cv_validate1(clicon_handle h,
|
|||
}
|
||||
|
||||
/* Forward */
|
||||
static int ys_cv_validate_union(clicon_handle h,yang_stmt *ys, char **reason,
|
||||
static int ys_cv_validate_union(clixon_handle h,yang_stmt *ys, char **reason,
|
||||
yang_stmt *yrestype, char *type, char *val, yang_stmt **ysubp);
|
||||
|
||||
static int
|
||||
ys_cv_validate_leafref(clicon_handle h,
|
||||
ys_cv_validate_leafref(clixon_handle h,
|
||||
char *body,
|
||||
yang_stmt *ys,
|
||||
yang_stmt *yrestype,
|
||||
|
|
@ -774,26 +772,26 @@ ys_cv_validate_leafref(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No Y_PATH for leafref");
|
||||
clixon_err(OE_YANG, 0, "No Y_PATH for leafref");
|
||||
goto done;
|
||||
}
|
||||
if ((path_arg = yang_argument_get(ypath)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No argument for Y_PATH");
|
||||
clixon_err(OE_YANG, 0, "No argument for Y_PATH");
|
||||
goto done;
|
||||
}
|
||||
if (yang_path_arg(ys, path_arg, &yref) < 0)
|
||||
goto done;
|
||||
if (yref == NULL){
|
||||
clicon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", path_arg);
|
||||
clixon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", path_arg);
|
||||
goto done;
|
||||
}
|
||||
/* reparse cv with new type */
|
||||
if ((cv = cv_dup(yang_cv_get(yref))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv_dup");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = cv_parse1(body, cv, reason)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cv_parse");
|
||||
clixon_err(OE_UNIX, errno, "cv_parse");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0)
|
||||
|
|
@ -822,7 +820,7 @@ ys_cv_validate_leafref(clicon_handle h,
|
|||
* @retval -1 Error (fatal), with errno set to indicate error
|
||||
*/
|
||||
static int
|
||||
ys_cv_validate_union_one(clicon_handle h,
|
||||
ys_cv_validate_union_one(clixon_handle h,
|
||||
yang_stmt *ys,
|
||||
char **reason,
|
||||
yang_stmt *yt,
|
||||
|
|
@ -842,18 +840,18 @@ ys_cv_validate_union_one(clicon_handle h,
|
|||
yang_stmt *ysubt = NULL;
|
||||
|
||||
if ((regexps = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if ((patterns = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (yang_type_resolve(ys, ys, yt, &yrestype, &options, &cvv, patterns, regexps,
|
||||
&fraction) < 0)
|
||||
goto done;
|
||||
if (yrestype == NULL){
|
||||
clicon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
goto done;
|
||||
}
|
||||
restype = yrestype?yang_argument_get(yrestype):NULL;
|
||||
|
|
@ -871,7 +869,7 @@ ys_cv_validate_union_one(clicon_handle h,
|
|||
goto done;
|
||||
/* reparse value with the new type */
|
||||
if ((cvt = cv_new(cvtype)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_new");
|
||||
clixon_err(OE_UNIX, errno, "cv_new");
|
||||
goto done;
|
||||
}
|
||||
if (cvtype == CGV_DEC64)
|
||||
|
|
@ -881,7 +879,7 @@ ys_cv_validate_union_one(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if ((retval = cv_parse1(val, cvt, reason)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cv_parse");
|
||||
clixon_err(OE_UNIX, errno, "cv_parse");
|
||||
goto done;
|
||||
}
|
||||
if (retval == 0)
|
||||
|
|
@ -925,7 +923,7 @@ ys_cv_validate_union_one(clicon_handle h,
|
|||
* @retval -1 Error (fatal), with errno set to indicate error
|
||||
*/
|
||||
static int
|
||||
ys_cv_validate_union(clicon_handle h,
|
||||
ys_cv_validate_union(clixon_handle h,
|
||||
yang_stmt *ys,
|
||||
char **reason,
|
||||
yang_stmt *yrestype,
|
||||
|
|
@ -984,7 +982,7 @@ ys_cv_validate_union(clicon_handle h,
|
|||
* @note reason if given must be freed by caller
|
||||
*/
|
||||
int
|
||||
ys_cv_validate(clicon_handle h,
|
||||
ys_cv_validate(clixon_handle h,
|
||||
cg_var *cv,
|
||||
yang_stmt *ys,
|
||||
yang_stmt **ysub,
|
||||
|
|
@ -1013,11 +1011,11 @@ ys_cv_validate(clicon_handle h,
|
|||
}
|
||||
ycv = yang_cv_get(ys);
|
||||
if ((regexps = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if ((patterns = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (yang_type_get(ys, &origtype, &yrestype,
|
||||
|
|
@ -1034,7 +1032,7 @@ ys_cv_validate(clicon_handle h,
|
|||
if (cvtype == CGV_STRING && cv_type_get(ycv) == CGV_REST)
|
||||
;
|
||||
else {
|
||||
clicon_err(OE_DB, 0, "Type mismatch data:%s != yang:%s",
|
||||
clixon_err(OE_DB, 0, "Type mismatch data:%s != yang:%s",
|
||||
cv_type2str(cvtype), cv_type2str(cv_type_get(ycv)));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1042,7 +1040,7 @@ ys_cv_validate(clicon_handle h,
|
|||
/* Note restype can be NULL here for example with unresolved hardcoded uuid */
|
||||
if (restype && strcmp(restype, "union") == 0){
|
||||
if (cvtype != CGV_REST){
|
||||
clicon_err(OE_YANG, 0, "union must be rest cv type but is %d", cvtype);
|
||||
clixon_err(OE_YANG, 0, "union must be rest cv type but is %d", cvtype);
|
||||
goto done;
|
||||
}
|
||||
/* Instead of NULL, give an empty string to validate, this is to avoid cv_parse
|
||||
|
|
@ -1079,7 +1077,7 @@ ys_cv_validate(clicon_handle h,
|
|||
*/
|
||||
if (restype && strcmp(restype,"leafref") == 0){
|
||||
if (cvtype != CGV_REST){
|
||||
clicon_err(OE_YANG, 0, "leafref must be rest cv type but is %d", cvtype);
|
||||
clixon_err(OE_YANG, 0, "leafref must be rest cv type but is %d", cvtype);
|
||||
goto done;
|
||||
}
|
||||
/* Instead of NULL, give an empty string to validate, this is to avoid cv_parse
|
||||
|
|
@ -1270,7 +1268,7 @@ yang_type_resolve_restrictions(yang_stmt *ytype,
|
|||
if (yang_keyword_get(ys) != Y_PATTERN)
|
||||
continue;
|
||||
if ((cv = cvec_add(regexps, CGV_STRING)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_add");
|
||||
clixon_err(OE_UNIX, errno, "cvec_add");
|
||||
goto done;
|
||||
}
|
||||
pattern = yang_argument_get(ys); /* clear text pattern */
|
||||
|
|
@ -1305,7 +1303,7 @@ yang_type_resolve_restrictions(yang_stmt *ytype,
|
|||
* @param[out] fraction for decimal64, how many digits after period
|
||||
* Present if options&YANG_OPTIONS_FRACTION_DIGITS
|
||||
* @retval 0 OK. Note yrestype may still be NULL.
|
||||
* @retval -1 Error, clicon_err handles errors
|
||||
* @retval -1 Error
|
||||
* The setting of the options argument has the following semantics:
|
||||
* options&YANG_OPTIONS_RANGE or YANG_OPTIONS_LENGTH --> cvv is set containing
|
||||
* array of range_min, range_max cv:s
|
||||
|
|
@ -1366,7 +1364,7 @@ yang_type_resolve(yang_stmt *yorig,
|
|||
/* Not basic type. Now check if prefix which means we look in other module */
|
||||
if (prefix){ /* Go to top and find import that matches */
|
||||
if ((yrmod = yang_find_module_by_prefix(ytype, prefix)) == NULL){
|
||||
clicon_err(OE_DB, 0, "Type not resolved: \"%s:%s\" in module %s",
|
||||
clixon_err(OE_DB, 0, "Type not resolved: \"%s:%s\" in module %s",
|
||||
prefix, type, yang_argument_get(ys_module(yorig)));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1393,7 +1391,7 @@ yang_type_resolve(yang_stmt *yorig,
|
|||
if (rytypedef != NULL){ /* We have found a typedef */
|
||||
/* Find associated type statement */
|
||||
if ((rytype = yang_find(rytypedef, Y_TYPE, NULL)) == NULL){
|
||||
clicon_err(OE_DB, 0, "mandatory type object is not found");
|
||||
clixon_err(OE_DB, 0, "mandatory type object is not found");
|
||||
goto done;
|
||||
}
|
||||
/* recursively resolve this new type */
|
||||
|
|
@ -1403,7 +1401,7 @@ yang_type_resolve(yang_stmt *yorig,
|
|||
fraction) < 0)
|
||||
goto done;
|
||||
if (yrestype && *yrestype == NULL){
|
||||
clicon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
goto done;
|
||||
}
|
||||
/* appends patterns, overwrites others if any */
|
||||
|
|
@ -1415,7 +1413,7 @@ yang_type_resolve(yang_stmt *yorig,
|
|||
done:
|
||||
#if 1
|
||||
if (retval == 0 && yrestype != NULL && *yrestype == NULL){
|
||||
clicon_err(OE_YANG, 0, "No such type: \"%s\"", type);
|
||||
clixon_err(OE_YANG, 0, "No such type: \"%s\"", type);
|
||||
retval = -1;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1457,7 +1455,7 @@ yang_type_resolve(yang_stmt *yorig,
|
|||
* @param[out] fraction for decimal64, how many digits after period
|
||||
* Present if options&YANG_OPTIONS_FRACTION_DIGITS
|
||||
* @retval 0 OK, but note that restype==NULL means not resolved.
|
||||
* @retval -1 Error, clicon_err handles errors
|
||||
* @retval -1 Error
|
||||
* The setting of the options argument has the following semantics:
|
||||
* options&YANG_OPTIONS_RANGE or YANG_OPTIONS_LENGTH --> cvv is set containing
|
||||
* array of range_min, range_max cv:s
|
||||
|
|
@ -1485,7 +1483,7 @@ yang_type_get(yang_stmt *ys,
|
|||
*options = 0x0;
|
||||
/* Find mandatory type */
|
||||
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){
|
||||
clicon_err(OE_DB, ENOENT, "mandatory type object is not found");
|
||||
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
|
||||
goto done;
|
||||
}
|
||||
/* XXX: here we seem to have some problems if type is union */
|
||||
|
|
@ -1493,14 +1491,14 @@ yang_type_get(yang_stmt *ys,
|
|||
goto done;
|
||||
if (origtype &&
|
||||
(*origtype = strdup(type)) == NULL){
|
||||
clicon_err(OE_XML, errno, "stdup");
|
||||
clixon_err(OE_XML, errno, "stdup");
|
||||
goto done;
|
||||
}
|
||||
if (yang_type_resolve(ys, ys, ytype, yrestype,
|
||||
options, cvv, patterns, regexps, fraction) < 0)
|
||||
goto done;
|
||||
if (yrestype && *yrestype == NULL){
|
||||
clicon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
clixon_err(OE_YANG, 0, "result-type should not be NULL");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue