Changed code so that it will be compatible with c++.
1. Added #ifdef extern "C" to public header files. 2. Changed variables that are key words in c++, to different names (like ns instead of namespace). 3. Changed char* to const char* for constant strings.
This commit is contained in:
parent
eda4a58ebf
commit
58ea4eba27
27 changed files with 274 additions and 119 deletions
|
|
@ -36,7 +36,9 @@
|
|||
* only include this file.
|
||||
* Internal code should not include this file
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifndef _CLIXON_BACKEND_H_
|
||||
#define _CLIXON_BACKEND_H_
|
||||
|
||||
|
|
@ -50,3 +52,8 @@
|
|||
#include <clixon/clixon_backend_transaction.h>
|
||||
|
||||
#endif /* _CLIXON_BACKEND_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _CLIXON_CLI_H_
|
||||
#define _CLIXON_CLI_H_
|
||||
|
|
@ -60,3 +63,8 @@ int plugin_start(clicon_handle h, int argc, char **argv);
|
|||
int plugin_exit(clicon_handle h);
|
||||
|
||||
#endif /* _CLIXON_CLI_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@
|
|||
* The exported interface to plugins. External apps (eg frontend restconf plugins)
|
||||
* should only include this file (not the restconf_*.h)
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifndef _CLIXON_RESTCONF_H_
|
||||
#define _CLIXON_RESTCONF_H_
|
||||
|
||||
|
|
@ -65,3 +67,8 @@ char *restconf_param_get(clicon_handle h, char *param);
|
|||
int restconf_param_set(clicon_handle h, char *param, char *val);
|
||||
|
||||
#endif /* _CLIXON_RESTCONF_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _RESTCONF_LIB_H_
|
||||
#define _RESTCONF_LIB_H_
|
||||
|
||||
|
|
@ -68,3 +72,8 @@ char *restconf_uripath(clicon_handle h);
|
|||
int restconf_drop_privileges(clicon_handle h, char *user);
|
||||
|
||||
#endif /* _RESTCONF_LIB_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@
|
|||
* file in clicon lib-routines.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This include file requires the following include file dependencies */
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -105,3 +110,8 @@
|
|||
*/
|
||||
extern const char CLIXON_BUILDSTR[];
|
||||
extern const char CLIXON_VERSION[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ int netconf_bad_element(cbuf *cb, char *type, char *info, char *element);
|
|||
int netconf_bad_element_xml(cxobj **xret, char *type, char *info, char *element);
|
||||
int netconf_unknown_element(cbuf *cb, char *type, char *element, char *message);
|
||||
int netconf_unknown_element_xml(cxobj **xret, char *type, char *element, char *message);
|
||||
int netconf_unknown_namespace(cbuf *cb, char *type, char *namespace, char *message);
|
||||
int netconf_unknown_namespace_xml(cxobj **xret, char *type, char *namespace, char *message);
|
||||
int netconf_unknown_namespace(cbuf *cb, char *type, char *ns, char *message);
|
||||
int netconf_unknown_namespace_xml(cxobj **xret, char *type, char *ns, char *message);
|
||||
int netconf_access_denied(cbuf *cb, char *type, char *message);
|
||||
int netconf_access_denied_xml(cxobj **xret, char *type, char *message);
|
||||
int netconf_lock_denied(cbuf *cb, char *info, char *message);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ typedef int (*clicon_rpc_cb)(
|
|||
/*! Registered Upgrade callback function
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] namespace Namespace of module
|
||||
* @param[in] ns Namespace of module
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
* @param[in] from From revision on the form YYYYMMDD (if DEL or CHANGE)
|
||||
* @param[in] to To revision on the form YYYYMMDD (if ADD or CHANGE)
|
||||
|
|
@ -84,7 +84,7 @@ typedef int (*clicon_rpc_cb)(
|
|||
typedef int (*clicon_upgrade_cb)(
|
||||
clicon_handle h,
|
||||
cxobj *xn,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
|
|
@ -255,7 +255,7 @@ struct clixon_plugin_api{
|
|||
/*
|
||||
* Macros
|
||||
*/
|
||||
#define upgrade_callback_register(h, cb, namespace, arg) upgrade_callback_reg_fn((h), (cb), #cb, (namespace), (arg))
|
||||
#define upgrade_callback_register(h, cb, ns, arg) upgrade_callback_reg_fn((h), (cb), #cb, (ns), (arg))
|
||||
|
||||
typedef struct clixon_plugin_api clixon_plugin_api;
|
||||
|
||||
|
|
@ -306,13 +306,13 @@ int clixon_plugin_datastore_upgrade_one(clixon_plugin *cp, clicon_handle h, char
|
|||
int clixon_plugin_datastore_upgrade_all(clicon_handle h, char *db, cxobj *xt, modstate_diff_t *msd);
|
||||
|
||||
/* rpc callback API */
|
||||
int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, char *namespace, char *name);
|
||||
int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, char *ns, char *name);
|
||||
int rpc_callback_delete_all(clicon_handle h);
|
||||
int rpc_callback_call(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg);
|
||||
|
||||
/* upgrade callback API */
|
||||
int upgrade_callback_reg_fn(clicon_handle h, clicon_upgrade_cb cb, const char *strfn, char *namespace, void *arg);
|
||||
int upgrade_callback_reg_fn(clicon_handle h, clicon_upgrade_cb cb, const char *strfn, char *ns, void *arg);
|
||||
int upgrade_callback_delete_all(clicon_handle h);
|
||||
int upgrade_callback_call(clicon_handle h, cxobj *xt, char *namespace, uint16_t op, uint32_t from, uint32_t to, cbuf *cbret);
|
||||
int upgrade_callback_call(clicon_handle h, cxobj *xt, char *ns, uint16_t op, uint32_t from, uint32_t to, cbuf *cbret);
|
||||
|
||||
#endif /* _CLIXON_PLUGIN_H_ */
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ static inline char * strdup4(char *str)
|
|||
char *dup;
|
||||
int len;
|
||||
len = align4(strlen(str)+1);
|
||||
if ((dup = malloc(len)) == NULL)
|
||||
if ((dup = (char*) malloc(len)) == NULL)
|
||||
return NULL;
|
||||
strncpy(dup, str, len);
|
||||
return dup;
|
||||
|
|
|
|||
|
|
@ -160,13 +160,13 @@ int xml_name_set(cxobj *xn, char *name);
|
|||
char *xml_prefix(cxobj *xn);
|
||||
int xml_prefix_set(cxobj *xn, char *name);
|
||||
char *nscache_get(cxobj *x, char *prefix);
|
||||
int nscache_get_prefix(cxobj *x, char *namespace, char **prefix);
|
||||
int nscache_get_prefix(cxobj *x, char *ns, char **prefix);
|
||||
cvec *nscache_get_all(cxobj *x);
|
||||
int nscache_set(cxobj *x, char *prefix, char *namespace);
|
||||
int nscache_set(cxobj *x, char *prefix, char *ns);
|
||||
int nscache_clear(cxobj *x);
|
||||
int nscache_replace(cxobj *x, cvec *ns);
|
||||
|
||||
int xmlns_set(cxobj *x, char *prefix, char *namespace);
|
||||
int xmlns_set(cxobj *x, char *prefix, char *ns);
|
||||
cxobj *xml_parent(cxobj *xn);
|
||||
int xml_parent_set(cxobj *xn, cxobj *parent);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int xml_changelog_upgrade(clicon_handle h, cxobj *xn, char *namespace, uint16_t op, uint32_t from, uint32_t to, void *arg, cbuf *cbret);
|
||||
int xml_changelog_upgrade(clicon_handle h, cxobj *xn, char *ns, uint16_t op, uint32_t from, uint32_t to, void *arg, cbuf *cbret);
|
||||
int clixon_xml_changelog_init(clicon_handle h);
|
||||
int xml_namespace_vec(clicon_handle h, cxobj *xt, char *namespace, cxobj ***vec, size_t *veclen);
|
||||
int xml_namespace_vec(clicon_handle h, cxobj *xt, char *ns, cxobj ***vec, size_t *veclen);
|
||||
|
||||
#endif /* _CLIXON_XML_CHANGELOG_H */
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ int xml_diff(yang_stmt *yspec, cxobj *x0, cxobj *x1,
|
|||
cxobj ***changed_x0, cxobj ***changed_x1, int *changedlen);
|
||||
int xml_tree_prune_flagged_sub(cxobj *xt, int flag, int test, int *upmark);
|
||||
int xml_tree_prune_flagged(cxobj *xt, int flag, int test);
|
||||
int xml_namespace_change(cxobj *x, char *namespace, char *prefix);
|
||||
int xml_namespace_change(cxobj *x, char *ns, char *prefix);
|
||||
int xml_default(cxobj *x);
|
||||
int xml_default_recurse(cxobj *xn);
|
||||
int xml_sanity(cxobj *x, void *arg);
|
||||
|
|
|
|||
|
|
@ -48,17 +48,17 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
cvec *xml_nsctx_init(char *prefix, char *namespace);
|
||||
cvec *xml_nsctx_init(char *prefix, char *ns);
|
||||
int xml_nsctx_free(cvec *nsc);
|
||||
char *xml_nsctx_get(cvec *nsc, char *prefix);
|
||||
int xml_nsctx_get_prefix(cvec *cvv, char *namespace, char **prefix);
|
||||
int xml_nsctx_add(cvec *nsc, char *prefix, char *namespace);
|
||||
int xml_nsctx_add(cvec *nsc, char *prefix, char *ns);
|
||||
int xml_nsctx_node(cxobj *x, cvec **ncp);
|
||||
int xml_nsctx_yang(yang_stmt *yn, cvec **ncp);
|
||||
int xml_nsctx_yangspec(yang_stmt *yspec, cvec **ncp);
|
||||
|
||||
int xml2ns(cxobj *x, char *localname, char **namespace);
|
||||
int xml2ns(cxobj *x, char *localname, char **ns);
|
||||
int xml2ns_recurse(cxobj *x);
|
||||
int xml2prefix(cxobj *xn, char *namespace, char **prefixp);
|
||||
int xml2prefix(cxobj *xn, char *ns, char **prefixp);
|
||||
|
||||
#endif /* _CLIXON_XML_NSCTX_H */
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int xml_cmp(cxobj *x1, cxobj *x2, int same, int skip1, char *explicit);
|
||||
int xml_cmp(cxobj *x1, cxobj *x2, int same, int skip1, char *expl);
|
||||
int xml_sort(cxobj *x0);
|
||||
int xml_sort_recurse(cxobj *xn);
|
||||
int xml_insert(cxobj *xp, cxobj *xc, enum insert_type ins, char *key_val, cvec *nsckey);
|
||||
|
|
@ -51,7 +51,7 @@ int xml_search_indexvar_binary_pos(cxobj *xp, char *indexvar, clixon_xvec *xvec,
|
|||
int low, int upper, int max, int *eq);
|
||||
#endif
|
||||
int match_base_child(cxobj *x0, cxobj *x1c, yang_stmt *yc, cxobj **x0cp);
|
||||
int clixon_xml_find_index(cxobj *xp, yang_stmt *yp, char *namespace, char *name,
|
||||
int clixon_xml_find_index(cxobj *xp, yang_stmt *yp, char *ns, char *name,
|
||||
cvec *cvk, clixon_xvec *xvec);
|
||||
int clixon_xml_find_pos(cxobj *xp, yang_stmt *yc, uint32_t pos, clixon_xvec *xvec);
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ yang_stmt *ys_prune(yang_stmt *yp, int i);
|
|||
|
||||
int ys_free(yang_stmt *ys);
|
||||
int yspec_free(yang_stmt *yspec);
|
||||
int ys_cp(yang_stmt *new, yang_stmt *old);
|
||||
int ys_cp(yang_stmt *nw, yang_stmt *old);
|
||||
yang_stmt *ys_dup(yang_stmt *old);
|
||||
int yn_insert(yang_stmt *ys_parent, yang_stmt *ys_child);
|
||||
yang_stmt *yn_each(yang_stmt *yn, yang_stmt *ys);
|
||||
|
|
@ -223,7 +223,7 @@ yang_stmt *yang_find_datanode(yang_stmt *yn, char *argument);
|
|||
yang_stmt *yang_find_schemanode(yang_stmt *yn, char *argument);
|
||||
char *yang_find_myprefix(yang_stmt *ys);
|
||||
char *yang_find_mynamespace(yang_stmt *ys);
|
||||
int yang_find_prefix_by_namespace(yang_stmt *ys, char *namespace, char **prefix);
|
||||
int yang_find_prefix_by_namespace(yang_stmt *ys, char *ns, char **prefix);
|
||||
yang_stmt *yang_myroot(yang_stmt *ys);
|
||||
yang_stmt *yang_choice(yang_stmt *y);
|
||||
int yang_order(yang_stmt *y);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ int yang_modules_state_get(clicon_handle h, yang_stmt *yspec, char *xpath,
|
|||
int clixon_module_upgrade(clicon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb);
|
||||
yang_stmt *yang_find_module_by_prefix(yang_stmt *ys, char *prefix);
|
||||
yang_stmt *yang_find_module_by_prefix_yspec(yang_stmt *yspec, char *prefix);
|
||||
yang_stmt *yang_find_module_by_namespace(yang_stmt *yspec, char *namespace);
|
||||
yang_stmt *yang_find_module_by_namespace(yang_stmt *yspec, char *ns);
|
||||
yang_stmt *yang_find_module_by_name(yang_stmt *yspec, char *name);
|
||||
|
||||
#endif /* _CLIXON_YANG_MODULE_H_ */
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@
|
|||
* If such an attribute its found, its string value is returned.
|
||||
* @param[in] x XML node (where to look for attribute)
|
||||
* @param[in] name Attribute name
|
||||
* @param[in] namespace (Expected)Namespace of attribute
|
||||
* @param[in] ns (Expected)Namespace of attribute
|
||||
* @param[out] cbret Error message (if retval=0)
|
||||
* @param[out] valp Pointer to value (if retval=1)
|
||||
* @retval -1 Error
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
static int
|
||||
attr_ns_value(cxobj *x,
|
||||
char *name,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
cbuf *cbret,
|
||||
char **valp)
|
||||
{
|
||||
|
|
@ -119,7 +119,7 @@ attr_ns_value(cxobj *x,
|
|||
goto fail;
|
||||
}
|
||||
/* the attribute exists, but not w expected namespace */
|
||||
if (strcmp(ans, namespace) == 0)
|
||||
if (strcmp(ans, ns) == 0)
|
||||
val = xml_value(xa);
|
||||
}
|
||||
*valp = val;
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ json2xml_decode_identityref(cxobj *x,
|
|||
cxobj **xerr)
|
||||
{
|
||||
int retval = -1;
|
||||
char *namespace;
|
||||
char *ns;
|
||||
char *body;
|
||||
cxobj *xb;
|
||||
cxobj *xa;
|
||||
|
|
@ -319,7 +319,7 @@ json2xml_decode_identityref(cxobj *x,
|
|||
/* prefix is a module name -> find module */
|
||||
if (prefix){
|
||||
if ((ymod = yang_find_module_by_name(yspec, prefix)) != NULL){
|
||||
namespace = yang_find_mynamespace(ymod);
|
||||
ns = yang_find_mynamespace(ymod);
|
||||
/* Is this namespace in the xml context?
|
||||
* (yes) use its prefix (unless it is NULL)
|
||||
* (no) insert a xmlns:<prefix> statement
|
||||
|
|
@ -328,15 +328,15 @@ json2xml_decode_identityref(cxobj *x,
|
|||
if (xml_nsctx_node(x, &nsc) < 0)
|
||||
goto done;
|
||||
clicon_debug(1, "%s prefix:%s body:%s namespace:%s",
|
||||
__FUNCTION__, prefix, body, namespace);
|
||||
if (!xml_nsctx_get_prefix(nsc, namespace, &prefix2)){
|
||||
__FUNCTION__, prefix, body, ns);
|
||||
if (!xml_nsctx_get_prefix(nsc, ns, &prefix2)){
|
||||
/* (no) insert a xmlns:<prefix> statement
|
||||
* Get yang prefix from import statement of my mod */
|
||||
if (yang_find_prefix_by_namespace(y, namespace, &prefix2) == 0){
|
||||
if (yang_find_prefix_by_namespace(y, ns, &prefix2) == 0){
|
||||
#ifndef IDENTITYREF_KLUDGE
|
||||
/* Just get the prefix from the module's own namespace */
|
||||
if (xerr && netconf_unknown_namespace_xml(xerr, "application",
|
||||
namespace,
|
||||
ns,
|
||||
"No local prefix corresponding to namespace") < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
|
|
@ -350,7 +350,7 @@ json2xml_decode_identityref(cxobj *x,
|
|||
goto done;
|
||||
if (xml_prefix_set(xa, "xmlns") < 0)
|
||||
goto done;
|
||||
if (xml_value_set(xa, namespace) < 0)
|
||||
if (xml_value_set(xa, ns) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Here prefix2 is valid and can be NULL
|
||||
|
|
|
|||
|
|
@ -568,14 +568,14 @@ netconf_unknown_element_xml(cxobj **xret,
|
|||
int
|
||||
netconf_unknown_namespace(cbuf *cb,
|
||||
char *type,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char *message)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xret = NULL;
|
||||
|
||||
if (netconf_common_xml(&xret, type, "unknown-namespace",
|
||||
"bad-namespace", namespace, message) < 0)
|
||||
"bad-namespace", ns, message) < 0)
|
||||
goto done;
|
||||
if (clicon_xml2cbuf(cb, xret, 0, 0, -1) < 0)
|
||||
goto done;
|
||||
|
|
@ -589,11 +589,11 @@ netconf_unknown_namespace(cbuf *cb,
|
|||
int
|
||||
netconf_unknown_namespace_xml(cxobj **xret,
|
||||
char *type,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char *message)
|
||||
{
|
||||
return netconf_common_xml(xret, type, "unknown-namespace",
|
||||
"bad-namespace", namespace, message);
|
||||
"bad-namespace", ns, message);
|
||||
}
|
||||
|
||||
/*! Create Netconf access-denied error cbuf according to RFC 6241 App A
|
||||
|
|
|
|||
|
|
@ -672,7 +672,7 @@ static rpc_callback_t *rpc_cb_list = NULL;
|
|||
* @param[in] h clicon handle
|
||||
* @param[in] cb Callback called
|
||||
* @param[in] arg Domain-specific argument to send to callback
|
||||
* @param[in] namespace namespace of rpc
|
||||
* @param[in] ns namespace of rpc
|
||||
* @param[in] name RPC name
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
|
@ -682,12 +682,12 @@ int
|
|||
rpc_callback_register(clicon_handle h,
|
||||
clicon_rpc_cb cb,
|
||||
void *arg,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char *name)
|
||||
{
|
||||
rpc_callback_t *rc = NULL;
|
||||
|
||||
if (name == NULL || namespace == NULL){
|
||||
if (name == NULL || ns == NULL){
|
||||
clicon_err(OE_DB, EINVAL, "name or namespace NULL");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -698,7 +698,7 @@ rpc_callback_register(clicon_handle h,
|
|||
memset(rc, 0, sizeof(*rc));
|
||||
rc->rc_callback = cb;
|
||||
rc->rc_arg = arg;
|
||||
rc->rc_namespace = strdup(namespace);
|
||||
rc->rc_namespace = strdup(ns);
|
||||
rc->rc_name = strdup(name);
|
||||
ADDQ(rc, rpc_cb_list);
|
||||
return 0;
|
||||
|
|
@ -755,19 +755,19 @@ rpc_callback_call(clicon_handle h,
|
|||
rpc_callback_t *rc;
|
||||
char *name;
|
||||
char *prefix;
|
||||
char *namespace;
|
||||
char *ns;
|
||||
int nr = 0; /* How many callbacks */
|
||||
|
||||
if (rpc_cb_list == NULL)
|
||||
return 0;
|
||||
name = xml_name(xe);
|
||||
prefix = xml_prefix(xe);
|
||||
xml2ns(xe, prefix, &namespace);
|
||||
xml2ns(xe, prefix, &ns);
|
||||
rc = rpc_cb_list;
|
||||
do {
|
||||
if (strcmp(rc->rc_name, name) == 0 &&
|
||||
namespace && rc->rc_namespace &&
|
||||
strcmp(rc->rc_namespace, namespace) == 0){
|
||||
ns && rc->rc_namespace &&
|
||||
strcmp(rc->rc_namespace, ns) == 0){
|
||||
if (rc->rc_callback(h, xe, cbret, arg, rc->rc_arg) < 0){
|
||||
clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name);
|
||||
goto done;
|
||||
|
|
@ -804,7 +804,7 @@ static upgrade_callback_t *upgrade_cb_list = NULL;
|
|||
* @param[in] cb Callback called
|
||||
* @param[in] fnstr Stringified function for debug
|
||||
* @param[in] arg Domain-specific argument to send to callback
|
||||
* @param[in] namespace Module namespace (if NULL all modules)
|
||||
* @param[in] ns Module namespace (if NULL all modules)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see upgrade_callback_call which makes the actual callback
|
||||
|
|
@ -813,7 +813,7 @@ int
|
|||
upgrade_callback_reg_fn(clicon_handle h,
|
||||
clicon_upgrade_cb cb,
|
||||
const char *fnstr,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
void *arg)
|
||||
{
|
||||
upgrade_callback_t *uc;
|
||||
|
|
@ -826,8 +826,8 @@ upgrade_callback_reg_fn(clicon_handle h,
|
|||
uc->uc_callback = cb;
|
||||
uc->uc_fnstr = fnstr;
|
||||
uc->uc_arg = arg;
|
||||
if (namespace)
|
||||
uc->uc_namespace = strdup(namespace);
|
||||
if (ns)
|
||||
uc->uc_namespace = strdup(ns);
|
||||
ADDQ(uc, upgrade_cb_list);
|
||||
return 0;
|
||||
done:
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ validate_identityref(cxobj *xt,
|
|||
* see IDENTITYREF_KLUDGE
|
||||
*/
|
||||
if (0){
|
||||
char *namespace;
|
||||
char *ns;
|
||||
yang_stmt *ymod;
|
||||
yang_stmt *yspec;
|
||||
|
||||
|
|
@ -246,11 +246,11 @@ validate_identityref(cxobj *xt,
|
|||
* identityref list associated with the base identities.
|
||||
*/
|
||||
/* Get namespace (of idref) from xml */
|
||||
if (xml2ns(xt, prefix, &namespace) < 0)
|
||||
if (xml2ns(xt, prefix, &ns) < 0)
|
||||
goto done;
|
||||
yspec = ys_spec(ys);
|
||||
/* Get module of that namespace */
|
||||
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){
|
||||
if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "No module found");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1083,7 +1083,7 @@ xml_yang_validate_all(clicon_handle h,
|
|||
int ret;
|
||||
cxobj *x;
|
||||
cxobj *xp;
|
||||
char *namespace = NULL;
|
||||
char *ns = NULL;
|
||||
cbuf *cb = NULL;
|
||||
cvec *nsc = NULL;
|
||||
|
||||
|
|
@ -1100,10 +1100,10 @@ xml_yang_validate_all(clicon_handle h,
|
|||
cprintf(cb, "Failed to find YANG spec of XML node: %s", xml_name(xt));
|
||||
if ((xp = xml_parent(xt)) != NULL)
|
||||
cprintf(cb, " with parent: %s", xml_name(xp));
|
||||
if (xml2ns(xt, xml_prefix(xt), &namespace) < 0)
|
||||
if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
|
||||
goto done;
|
||||
if (namespace)
|
||||
cprintf(cb, " in namespace: %s", namespace);
|
||||
if (ns)
|
||||
cprintf(cb, " in namespace: %s", ns);
|
||||
if (netconf_unknown_element_xml(xret, "application", xml_name(xt), cbuf_get(cb)) < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ changelog_iterate(clicon_handle h,
|
|||
/*! Automatic upgrade using changelog
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xt Top-level XML tree to be updated (includes other ns as well)
|
||||
* @param[in] namespace Namespace of module (for info)
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
* @param[in] from From revision on the form YYYYMMDD
|
||||
* @param[in] to To revision on the form YYYYMMDD (0 not in system)
|
||||
|
|
@ -369,7 +369,7 @@ changelog_iterate(clicon_handle h,
|
|||
int
|
||||
xml_changelog_upgrade(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
|
|
@ -399,7 +399,7 @@ xml_changelog_upgrade(clicon_handle h,
|
|||
* - note it t=0 then no changelog is applied
|
||||
*/
|
||||
if (xpath_vec(xchlog, NULL, "changelog[namespace=\"%s\"]",
|
||||
&vec, &veclen, namespace) < 0)
|
||||
&vec, &veclen, ns) < 0)
|
||||
goto done;
|
||||
/* Get all changelogs in the interval [from,to]*/
|
||||
for (i=0; i<veclen; i++){
|
||||
|
|
@ -487,7 +487,7 @@ clixon_xml_changelog_init(clicon_handle h)
|
|||
/*! Given a top-level XML tree and a namespace, return a vector of matching XML nodes
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xt Top-level XML tree, with children marked with namespaces
|
||||
* @param[in] namespace The namespace to select
|
||||
* @param[in] ns The namespace to select
|
||||
* @param[out] vecp Vector containining XML nodes w namespace. Null-terminated.
|
||||
* @param[out] veclenp Length of vector
|
||||
* @note Need to free vec after use with free()
|
||||
|
|
@ -500,7 +500,7 @@ clixon_xml_changelog_init(clicon_handle h)
|
|||
int
|
||||
xml_namespace_vec(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
cxobj ***vecp,
|
||||
size_t *veclenp)
|
||||
{
|
||||
|
|
@ -508,7 +508,7 @@ xml_namespace_vec(clicon_handle h,
|
|||
cxobj **xvec = NULL;
|
||||
size_t xlen;
|
||||
cxobj *xc;
|
||||
char *ns;
|
||||
char *ns0;
|
||||
int i;
|
||||
|
||||
/* Allocate upper bound on length (ie could be too large) + a NULL element
|
||||
|
|
@ -523,9 +523,9 @@ xml_namespace_vec(clicon_handle h,
|
|||
xc = NULL;
|
||||
i = 0;
|
||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL) {
|
||||
if (xml2ns(xc, NULL, &ns) < 0) /* Get namespace of XML */
|
||||
if (xml2ns(xc, NULL, &ns0) < 0) /* Get namespace of XML */
|
||||
goto done;
|
||||
if (strcmp(namespace, ns))
|
||||
if (strcmp(ns, ns0))
|
||||
continue; /* no match */
|
||||
xvec[i++] = xc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -933,14 +933,14 @@ add_namespace(cxobj *x,
|
|||
/*! Change namespace of XML node
|
||||
*
|
||||
* @param[in] x XML node
|
||||
* @param[in] namespace Change to this namespace (if ns does not exist in tree)
|
||||
* @param[in] ns Change to this namespace (if ns does not exist in tree)
|
||||
* @param[in] prefix If change, use this prefix
|
||||
* @param 0 OK
|
||||
* @param -1 Error
|
||||
*/
|
||||
int
|
||||
xml_namespace_change(cxobj *x,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char *prefix)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -951,10 +951,10 @@ xml_namespace_change(cxobj *x,
|
|||
ns0 = NULL;
|
||||
if (xml2ns(x, xml_prefix(x), &ns0) < 0)
|
||||
goto done;
|
||||
if (ns0 && strcmp(ns0, namespace) == 0)
|
||||
if (ns0 && strcmp(ns0, ns) == 0)
|
||||
goto ok; /* Already has right namespace */
|
||||
/* Is namespace already declared? */
|
||||
if (xml2prefix(x, namespace, &prefix0) == 1){
|
||||
if (xml2prefix(x, ns, &prefix0) == 1){
|
||||
/* Yes it is declared and the prefix is prefix0 */
|
||||
if (xml_prefix_set(x, prefix0) < 0)
|
||||
goto done;
|
||||
|
|
@ -967,7 +967,7 @@ xml_namespace_change(cxobj *x,
|
|||
xp = x;
|
||||
else
|
||||
xp = xml_parent(x);
|
||||
if (add_namespace(x, xp, prefix, namespace) < 0)
|
||||
if (add_namespace(x, xp, prefix, ns) < 0)
|
||||
goto done;
|
||||
/* Add prefix to x, if any */
|
||||
if (prefix && xml_prefix_set(x, prefix) < 0)
|
||||
|
|
@ -1279,7 +1279,7 @@ assign_namespace(cxobj *x0, /* source */
|
|||
cxobj *x1, /* target */
|
||||
cxobj *x1p,
|
||||
int isroot,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char *prefix0)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1290,7 +1290,7 @@ assign_namespace(cxobj *x0, /* source */
|
|||
yang_stmt *y;
|
||||
|
||||
/* 2a. Detect if namespace is declared in x1 target parent */
|
||||
if (xml2prefix(x1p, namespace, &pexist) == 1){
|
||||
if (xml2prefix(x1p, ns, &pexist) == 1){
|
||||
/* Yes, and it has prefix pexist */
|
||||
if (pexist){
|
||||
if ((prefix1 = strdup(pexist)) == NULL){
|
||||
|
|
@ -1312,12 +1312,12 @@ assign_namespace(cxobj *x0, /* source */
|
|||
nscache_replace(x1, nsc);
|
||||
}
|
||||
/* Just in case */
|
||||
if (nscache_set(x1, prefix1, namespace) < 0)
|
||||
if (nscache_set(x1, prefix1, ns) < 0)
|
||||
goto done;
|
||||
}
|
||||
else{ /* No, namespace does not exist in x1 _parent_
|
||||
* Check if it is exists in x1 itself */
|
||||
if (xml2prefix(x1, namespace, &pexist) == 1){
|
||||
if (xml2prefix(x1, ns, &pexist) == 1){
|
||||
/* Yes it exists, but is it equal? */
|
||||
if (clicon_strcmp(pexist, prefix0) == 0)
|
||||
; /* Equal, reuse */
|
||||
|
|
@ -1345,7 +1345,7 @@ assign_namespace(cxobj *x0, /* source */
|
|||
goto done;
|
||||
}
|
||||
/* Find local (imported) prefix for that module namespace */
|
||||
if (yang_find_prefix_by_namespace(y, namespace, &ptmp) < 0)
|
||||
if (yang_find_prefix_by_namespace(y, ns, &ptmp) < 0)
|
||||
goto done;
|
||||
if ((prefix1 = strdup(ptmp)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
|
|
@ -1354,7 +1354,7 @@ assign_namespace(cxobj *x0, /* source */
|
|||
|
||||
}
|
||||
}
|
||||
if (add_namespace(x1, x1, prefix1, namespace) < 0)
|
||||
if (add_namespace(x1, x1, prefix1, ns) < 0)
|
||||
goto done;
|
||||
if (prefix1 && xml_prefix_set(x1, prefix1) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
/*! Create and initialize XML namespace context
|
||||
* @param[in] prefix Namespace prefix, or NULL for default
|
||||
* @param[in] namespace Set this namespace. If NULL create empty nsctx
|
||||
* @param[in] ns Set this namespace. If NULL create empty nsctx
|
||||
* @retval nsc Return namespace context in form of a cvec
|
||||
* @retval NULL Error
|
||||
* @code
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
*/
|
||||
cvec *
|
||||
xml_nsctx_init(char *prefix,
|
||||
char *namespace)
|
||||
char *ns)
|
||||
{
|
||||
cvec *cvv = NULL;
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ xml_nsctx_init(char *prefix,
|
|||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
if (namespace && xml_nsctx_add(cvv, prefix, namespace) < 0)
|
||||
if (ns && xml_nsctx_add(cvv, prefix, ns) < 0)
|
||||
goto done;
|
||||
done:
|
||||
return cvv;
|
||||
|
|
@ -143,15 +143,15 @@ xml_nsctx_get(cvec *cvv,
|
|||
*/
|
||||
int
|
||||
xml_nsctx_get_prefix(cvec *cvv,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char **prefix)
|
||||
{
|
||||
cg_var *cv = NULL;
|
||||
char *ns = NULL;
|
||||
char *ns0 = NULL;
|
||||
|
||||
while ((cv = cvec_each(cvv, cv)) != NULL){
|
||||
if ((ns = cv_string_get(cv)) != NULL &&
|
||||
strcmp(ns, namespace) == 0){
|
||||
if ((ns0 = cv_string_get(cv)) != NULL &&
|
||||
strcmp(ns0, ns) == 0){
|
||||
if (prefix)
|
||||
*prefix = cv_name_get(cv); /* can be NULL */
|
||||
return 1;
|
||||
|
|
@ -165,22 +165,22 @@ xml_nsctx_get_prefix(cvec *cvv,
|
|||
/*! Set or replace namespace in namespace context
|
||||
* @param[in] cvv Namespace context
|
||||
* @param[in] prefix Namespace prefix, or NULL for default
|
||||
* @param[in] namespace Cached namespace to set (assume non-null?)
|
||||
* @param[in] ns Cached namespace to set (assume non-null?)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xml_nsctx_add(cvec *cvv,
|
||||
char *prefix,
|
||||
char *namespace)
|
||||
char *ns)
|
||||
{
|
||||
int retval = -1;
|
||||
cg_var *cv;
|
||||
|
||||
if ((cv = cvec_find(cvv, prefix)) != NULL) /* found, replace that */
|
||||
cv_string_set(cv, namespace);
|
||||
cv_string_set(cv, ns);
|
||||
else /* cvec exists, but not prefix */
|
||||
cvec_add_string(cvv, prefix, namespace);
|
||||
cvec_add_string(cvv, prefix, ns);
|
||||
retval = 0;
|
||||
// done:
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -1464,7 +1464,7 @@ xml_find_index_yang(cxobj *xp,
|
|||
*
|
||||
* @param[in] xp Parent xml node.
|
||||
* @param[in] yp Yang spec of parent node or yang-spec/yang (Alternative if yc not given).
|
||||
* @param[in] namespace Namespace (needed only if name is derived from top-symbol)
|
||||
* @param[in] ns Namespace (needed only if name is derived from top-symbol)
|
||||
* @param[in] name Name of child
|
||||
* @param[in] cvk List of keys and values as CLIgen vector on the form k1=foo, k2=bar
|
||||
* @param[out] xvec Array of result nodes. Must be initialized on entry
|
||||
|
|
@ -1493,7 +1493,7 @@ xml_find_index_yang(cxobj *xp,
|
|||
int
|
||||
clixon_xml_find_index(cxobj *xp,
|
||||
yang_stmt *yp,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char *name,
|
||||
cvec *cvk,
|
||||
clixon_xvec *xvec)
|
||||
|
|
@ -1514,7 +1514,7 @@ clixon_xml_find_index(cxobj *xp,
|
|||
yp = xml_spec(xp);
|
||||
if (yp){/* 2. YANG spec of parent + name derives yc. If not found use just name. */
|
||||
if (yang_keyword_get(yp) == Y_SPEC)
|
||||
yp = yang_find_module_by_namespace(yp, namespace);
|
||||
yp = yang_find_module_by_namespace(yp, ns);
|
||||
if (yp)
|
||||
yc = yang_find_datanode(yp, name);
|
||||
}
|
||||
|
|
@ -1524,12 +1524,12 @@ clixon_xml_find_index(cxobj *xp,
|
|||
if (ret == 0){ /* This means yang method did not work for some reason
|
||||
* such as not being list key indexes in cvk, for example
|
||||
*/
|
||||
if (xml_find_noyang_name(xp, namespace, name, cvk, xvec) < 0)
|
||||
if (xml_find_noyang_name(xp, ns, name, cvk, xvec) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (xml_find_noyang_name(xp, namespace, name, cvk, xvec) < 0)
|
||||
if (xml_find_noyang_name(xp, ns, name, cvk, xvec) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ ys_cp(yang_stmt *ynew,
|
|||
/*! Create a new yang node and copy the contents recursively from the original. *
|
||||
* @param[in] old Old existing yang statement (from)
|
||||
* @retval NULL Error
|
||||
* @retval new New created yang statement
|
||||
* @retval nw New created yang statement
|
||||
* This may involve duplicating strings, etc.
|
||||
* The new yang tree needs to be freed by ys_free().
|
||||
* The parent of new is NULL, it needs to be explicityl inserted somewhere
|
||||
|
|
@ -526,19 +526,19 @@ ys_cp(yang_stmt *ynew,
|
|||
yang_stmt *
|
||||
ys_dup(yang_stmt *old)
|
||||
{
|
||||
yang_stmt *new;
|
||||
yang_stmt *nw;
|
||||
|
||||
if ((new = ys_new(old->ys_keyword)) == NULL)
|
||||
if ((nw = ys_new(old->ys_keyword)) == NULL)
|
||||
return NULL;
|
||||
if (new->ys_cvec){
|
||||
cvec_free(new->ys_cvec);
|
||||
new->ys_cvec = NULL;
|
||||
if (nw->ys_cvec){
|
||||
cvec_free(nw->ys_cvec);
|
||||
nw->ys_cvec = NULL;
|
||||
}
|
||||
if (ys_cp(new, old) < 0){
|
||||
ys_free(new);
|
||||
if (ys_cp(nw, old) < 0){
|
||||
ys_free(nw);
|
||||
return NULL;
|
||||
}
|
||||
return new;
|
||||
return nw;
|
||||
}
|
||||
|
||||
/*! Append yang statement as child of a parent yang_statement, last in list
|
||||
|
|
@ -849,7 +849,7 @@ yang_find_myprefix(yang_stmt *ys)
|
|||
/*! Given a yang statement, find the namespace URI associated to this module
|
||||
* @param[in] ys Yang statement in module tree (or module itself)
|
||||
* @retval NULL Not found
|
||||
* @retval namespace Namspace URI as char* pointer into yang tree
|
||||
* @retval ns Namspace URI as char* pointer into yang tree
|
||||
* @code
|
||||
* char *myns = yang_find_mynamespace(ys);
|
||||
* @endcode
|
||||
|
|
@ -860,7 +860,7 @@ yang_find_mynamespace(yang_stmt *ys)
|
|||
{
|
||||
yang_stmt *ymod; /* My module */
|
||||
yang_stmt *ynamespace;
|
||||
char *namespace = NULL;
|
||||
char *ns = NULL;
|
||||
|
||||
if ((ymod = ys_real_module(ys)) == NULL){
|
||||
clicon_err(OE_YANG, ENOENT, "My yang module not found");
|
||||
|
|
@ -868,9 +868,9 @@ yang_find_mynamespace(yang_stmt *ys)
|
|||
}
|
||||
if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL)
|
||||
goto done;
|
||||
namespace = yang_argument_get(ynamespace);
|
||||
ns = yang_argument_get(ynamespace);
|
||||
done:
|
||||
return namespace;
|
||||
return ns;
|
||||
}
|
||||
|
||||
/*! Given a yang statement and namespace, find local prefix valid in module
|
||||
|
|
@ -878,7 +878,7 @@ yang_find_mynamespace(yang_stmt *ys)
|
|||
* (global) namespace of a module, but you do not know the local prefix
|
||||
* used to access it in XML.
|
||||
* @param[in] ys Yang statement in module tree (or module itself)
|
||||
* @param[in] namespace Namspace URI as char* pointer into yang tree
|
||||
* @param[in] ns Namspace URI as char* pointer into yang tree
|
||||
* @param[out] prefix Local prefix to access module with (direct pointer)
|
||||
* @retval 0 not found
|
||||
* @retval -1 found
|
||||
|
|
@ -891,7 +891,7 @@ yang_find_mynamespace(yang_stmt *ys)
|
|||
*/
|
||||
int
|
||||
yang_find_prefix_by_namespace(yang_stmt *ys,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
char **prefix)
|
||||
{
|
||||
int retval = 0; /* not found */
|
||||
|
|
@ -906,13 +906,13 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
|
|||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
/* First check if namespace is my own module */
|
||||
myns = yang_find_mynamespace(ys);
|
||||
if (strcmp(myns, namespace) == 0){
|
||||
if (strcmp(myns, ns) == 0){
|
||||
*prefix = yang_find_myprefix(ys); /* or NULL? */
|
||||
goto found;
|
||||
}
|
||||
/* Next, find namespaces in imported modules */
|
||||
yspec = ys_spec(ys);
|
||||
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL)
|
||||
if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL)
|
||||
goto notfound;
|
||||
modname = yang_argument_get(ymod);
|
||||
my_ymod = ys_module(ys);
|
||||
|
|
@ -1132,18 +1132,18 @@ ys_module_by_xml(yang_stmt *yspec,
|
|||
int retval = -1;
|
||||
yang_stmt *ym = NULL; /* module */
|
||||
char *prefix = NULL;
|
||||
char *namespace = NULL; /* namespace URI */
|
||||
char *ns = NULL; /* namespace URI */
|
||||
|
||||
if (ymodp)
|
||||
*ymodp = NULL;
|
||||
prefix = xml_prefix(xt);
|
||||
if (xml2ns(xt, prefix, &namespace) < 0) /* prefix may be NULL */
|
||||
if (xml2ns(xt, prefix, &ns) < 0) /* prefix may be NULL */
|
||||
goto done;
|
||||
/* No namespace found, give up */
|
||||
if (namespace == NULL)
|
||||
if (ns == NULL)
|
||||
goto ok;
|
||||
/* We got the namespace, now get the module */
|
||||
ym = yang_find_module_by_namespace(yspec, namespace);
|
||||
ym = yang_find_module_by_namespace(yspec, ns);
|
||||
/* Set result param */
|
||||
if (ymodp && ym)
|
||||
*ymodp = ym;
|
||||
|
|
|
|||
|
|
@ -555,7 +555,7 @@ yang_find_module_by_prefix_yspec(yang_stmt *yspec,
|
|||
/*! Given a yang spec and a namespace, return yang module
|
||||
*
|
||||
* @param[in] yspec A yang specification
|
||||
* @param[in] namespace namespace
|
||||
* @param[in] ns namespace
|
||||
* @retval ymod Yang module statement if found
|
||||
* @retval NULL not found
|
||||
* @see yang_find_module_by_name
|
||||
|
|
@ -563,14 +563,14 @@ yang_find_module_by_prefix_yspec(yang_stmt *yspec,
|
|||
*/
|
||||
yang_stmt *
|
||||
yang_find_module_by_namespace(yang_stmt *yspec,
|
||||
char *namespace)
|
||||
char *ns)
|
||||
{
|
||||
yang_stmt *ymod = NULL;
|
||||
|
||||
if (namespace == NULL)
|
||||
if (ns == NULL)
|
||||
goto done;
|
||||
while ((ymod = yn_each(yspec, ymod)) != NULL) {
|
||||
if (yang_find(ymod, Y_NAMESPACE, namespace) != NULL)
|
||||
if (yang_find(ymod, Y_NAMESPACE, ns) != NULL)
|
||||
break;
|
||||
}
|
||||
done:
|
||||
|
|
|
|||
114
test/test_c++.sh
Normal file
114
test/test_c++.sh
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#!/usr/bin/env bash
|
||||
# Tests cpp compatibility with clixon
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
cfile=$dir/c++.cpp
|
||||
|
||||
CXX=g++
|
||||
|
||||
cat<<EOF > $cfile
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <cligen/cligen.h>
|
||||
#include <clixon/clixon.h>
|
||||
#include <clixon/clixon_netconf.h>
|
||||
|
||||
/*! Plugin start
|
||||
* Called once everything has been initialized, right before
|
||||
* the main event loop is entered.
|
||||
*/
|
||||
int
|
||||
plugin_start(clicon_handle h)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
plugin_exit(clicon_handle h)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Local example netconf rpc callback
|
||||
*/
|
||||
int
|
||||
netconf_client_rpc(clicon_handle h,
|
||||
cxobj *xe,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
void *regarg)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *x = NULL;
|
||||
char *ns;
|
||||
|
||||
/* get namespace from rpc name, return back in each output parameter */
|
||||
if ((ns = xml_find_type_value(xe, NULL, (char*)"xmlns", CX_ATTR)) == NULL){
|
||||
clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe));
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<rpc-reply>");
|
||||
if (!xml_child_nr_type(xe, CX_ELMNT))
|
||||
cprintf(cbret, "<ok/>");
|
||||
else while ((x = xml_child_each(xe, x, CX_ELMNT)) != NULL) {
|
||||
if (xmlns_set(x, NULL, ns) < 0)
|
||||
goto done;
|
||||
if (clicon_xml2cbuf(cbret, x, 0, 0, -1) < 0)
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "</rpc-reply>");
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static struct clixon_plugin_api api;
|
||||
|
||||
void api_initialization(void)
|
||||
{
|
||||
strcpy(api.ca_name, "c++ netconf test"); /* name */
|
||||
api.ca_init = clixon_plugin_init; /* init */
|
||||
api.ca_start = plugin_start; /* start */
|
||||
api.ca_exit = plugin_exit; /* exit */
|
||||
};
|
||||
|
||||
/*! Netconf plugin initialization
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
|
||||
api_initialization();
|
||||
|
||||
clicon_debug(1, (char*)"%s netconf", __FUNCTION__);
|
||||
/* Register local netconf rpc client (note not backend rpc client) */
|
||||
if (rpc_callback_register(h, netconf_client_rpc, NULL,
|
||||
(char*)"urn:example:clixon", (char*)"client-rpc") < 0)
|
||||
return NULL;
|
||||
return &api;
|
||||
}
|
||||
|
||||
EOF
|
||||
|
||||
new "C++ compile"
|
||||
expectpart "$($CXX -g -Wall -rdynamic -fPIC -shared $cfile -o c++.o)" 0 ""
|
||||
|
||||
rm -f c++.o
|
||||
rm -rf $dir
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue