From 58ea4eba27108ac8124afa5ca1e8f61d6e7f0b4b Mon Sep 17 00:00:00 2001 From: shmuels Date: Thu, 2 Jul 2020 15:00:53 +0300 Subject: [PATCH] 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. --- apps/backend/clixon_backend.h | 9 ++- apps/cli/clixon_cli.h | 8 +++ apps/restconf/clixon_restconf.h | 9 ++- apps/restconf/restconf_lib.h | 9 +++ lib/clixon/clixon.h.in | 10 +++ lib/clixon/clixon_netconf_lib.h | 4 +- lib/clixon/clixon_plugin.h | 12 ++-- lib/clixon/clixon_string.h | 2 +- lib/clixon/clixon_xml.h | 6 +- lib/clixon/clixon_xml_changelog.h | 4 +- lib/clixon/clixon_xml_map.h | 2 +- lib/clixon/clixon_xml_nsctx.h | 8 +-- lib/clixon/clixon_xml_sort.h | 4 +- lib/clixon/clixon_yang.h | 4 +- lib/clixon/clixon_yang_module.h | 2 +- lib/src/clixon_datastore_write.c | 6 +- lib/src/clixon_json.c | 14 ++-- lib/src/clixon_netconf_lib.c | 8 +-- lib/src/clixon_plugin.c | 24 +++---- lib/src/clixon_validate.c | 14 ++-- lib/src/clixon_xml_changelog.c | 16 ++--- lib/src/clixon_xml_map.c | 22 +++--- lib/src/clixon_xml_nsctx.c | 22 +++--- lib/src/clixon_xml_sort.c | 10 +-- lib/src/clixon_yang.c | 42 +++++------ lib/src/clixon_yang_module.c | 8 +-- test/test_c++.sh | 114 ++++++++++++++++++++++++++++++ 27 files changed, 274 insertions(+), 119 deletions(-) create mode 100644 test/test_c++.sh diff --git a/apps/backend/clixon_backend.h b/apps/backend/clixon_backend.h index 37e046b1..9c5650b0 100644 --- a/apps/backend/clixon_backend.h +++ b/apps/backend/clixon_backend.h @@ -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 #endif /* _CLIXON_BACKEND_H_ */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + diff --git a/apps/cli/clixon_cli.h b/apps/cli/clixon_cli.h index e98141ab..57ec9c3f 100644 --- a/apps/cli/clixon_cli.h +++ b/apps/cli/clixon_cli.h @@ -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 + diff --git a/apps/restconf/clixon_restconf.h b/apps/restconf/clixon_restconf.h index 62cdf758..2c23f61d 100644 --- a/apps/restconf/clixon_restconf.h +++ b/apps/restconf/clixon_restconf.h @@ -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 + diff --git a/apps/restconf/restconf_lib.h b/apps/restconf/restconf_lib.h index bdb7c021..3c0d9569 100644 --- a/apps/restconf/restconf_lib.h +++ b/apps/restconf/restconf_lib.h @@ -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 + diff --git a/lib/clixon/clixon.h.in b/lib/clixon/clixon.h.in index 59043ede..8d2bfec0 100644 --- a/lib/clixon/clixon.h.in +++ b/lib/clixon/clixon.h.in @@ -41,6 +41,11 @@ * file in clicon lib-routines. */ + +#ifdef __cplusplus +extern "C" { +#endif + /* This include file requires the following include file dependencies */ #include #include @@ -105,3 +110,8 @@ */ extern const char CLIXON_BUILDSTR[]; extern const char CLIXON_VERSION[]; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + diff --git a/lib/clixon/clixon_netconf_lib.h b/lib/clixon/clixon_netconf_lib.h index 4871d51f..68970c04 100644 --- a/lib/clixon/clixon_netconf_lib.h +++ b/lib/clixon/clixon_netconf_lib.h @@ -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); diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index a35ffe36..a3a29412 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -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_ */ diff --git a/lib/clixon/clixon_string.h b/lib/clixon/clixon_string.h index 7e4b54b2..9613ecf4 100644 --- a/lib/clixon/clixon_string.h +++ b/lib/clixon/clixon_string.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; diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 16e2fa95..822a6d35 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -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); diff --git a/lib/clixon/clixon_xml_changelog.h b/lib/clixon/clixon_xml_changelog.h index c5251bb0..6f63977c 100644 --- a/lib/clixon/clixon_xml_changelog.h +++ b/lib/clixon/clixon_xml_changelog.h @@ -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 */ diff --git a/lib/clixon/clixon_xml_map.h b/lib/clixon/clixon_xml_map.h index c31441f3..ad404a7a 100644 --- a/lib/clixon/clixon_xml_map.h +++ b/lib/clixon/clixon_xml_map.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); diff --git a/lib/clixon/clixon_xml_nsctx.h b/lib/clixon/clixon_xml_nsctx.h index 9b98ea54..3b187fb2 100644 --- a/lib/clixon/clixon_xml_nsctx.h +++ b/lib/clixon/clixon_xml_nsctx.h @@ -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 */ diff --git a/lib/clixon/clixon_xml_sort.h b/lib/clixon/clixon_xml_sort.h index 45961764..e5355a88 100644 --- a/lib/clixon/clixon_xml_sort.h +++ b/lib/clixon/clixon_xml_sort.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); diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index fa6d8342..309dcaac 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -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); diff --git a/lib/clixon/clixon_yang_module.h b/lib/clixon/clixon_yang_module.h index 977a84ed..583500e4 100644 --- a/lib/clixon/clixon_yang_module.h +++ b/lib/clixon/clixon_yang_module.h @@ -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_ */ diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 49ac2b29..8c90923a 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -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; diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index a6e14938..ab1abba5 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -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: 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: 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 diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index f1a789b1..266fa62b 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -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 diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index d34e3195..13d24b83 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -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: diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index 16466235..3abe3750 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -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; diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index 02bef24e..b156ce36 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -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; iys_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; diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c index 0cf52626..52676d73 100644 --- a/lib/src/clixon_yang_module.c +++ b/lib/src/clixon_yang_module.c @@ -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: diff --git a/test/test_c++.sh b/test/test_c++.sh new file mode 100644 index 00000000..7835f1eb --- /dev/null +++ b/test/test_c++.sh @@ -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< $cfile +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/*! 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, ""); + if (!xml_child_nr_type(xe, CX_ELMNT)) + cprintf(cbret, ""); + 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, ""); + 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 +