From 62348fc9c790d6e42d04c8ef95fff04412a844df Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 22 Oct 2023 18:04:47 +0200 Subject: [PATCH] C-style update: Unified comment, retvals in order, remove trailing spaces Changed function name for `clicon_debug` functions --- CHANGELOG.md | 8 + apps/backend/backend_client.c | 213 ++++---- apps/backend/backend_client.h | 2 +- apps/backend/backend_commit.c | 114 ++-- apps/backend/backend_confirm.c | 51 +- apps/backend/backend_get.c | 57 +- apps/backend/backend_get.h | 2 +- apps/backend/backend_main.c | 21 +- apps/backend/backend_plugin.c | 164 +++--- apps/backend/backend_plugin_restconf.c | 45 +- apps/backend/backend_socket.c | 29 +- apps/backend/backend_socket.h | 2 +- apps/backend/backend_startup.c | 24 +- apps/backend/backend_startup.h | 2 +- apps/backend/clixon_backend_handle.c | 20 +- apps/backend/clixon_backend_plugin.h | 4 +- apps/backend/clixon_backend_transaction.c | 23 +- apps/backend/clixon_backend_transaction.h | 8 +- apps/cli/cli_auto.c | 70 ++- apps/cli/cli_autocli.c | 41 +- apps/cli/cli_common.c | 418 +++++++++------ apps/cli/cli_generate.c | 199 ++++--- apps/cli/cli_handle.c | 15 +- apps/cli/cli_main.c | 58 +- apps/cli/cli_pipe.c | 20 +- apps/cli/cli_plugin.c | 90 ++-- apps/cli/cli_show.c | 160 +++--- apps/cli/clixon_cli.h | 1 + apps/cli/clixon_cli_api.h | 11 +- apps/netconf/clixon_netconf.h | 4 +- apps/netconf/netconf_filter.c | 18 +- apps/netconf/netconf_filter.h | 2 +- apps/netconf/netconf_main.c | 87 +-- apps/netconf/netconf_rpc.c | 78 +-- apps/netconf/netconf_rpc.h | 4 +- apps/restconf/clixon_http1_parse.h | 2 +- apps/restconf/clixon_http1_parse.l | 21 +- apps/restconf/clixon_http1_parse.y | 48 +- apps/restconf/clixon_http_data.c | 71 +-- apps/restconf/clixon_restconf.h | 1 + apps/restconf/restconf_api_fcgi.c | 30 +- apps/restconf/restconf_api_native.c | 30 +- apps/restconf/restconf_err.c | 35 +- apps/restconf/restconf_handle.c | 39 +- apps/restconf/restconf_http1.c | 42 +- apps/restconf/restconf_lib.c | 81 +-- apps/restconf/restconf_lib.h | 3 +- apps/restconf/restconf_main_fcgi.c | 63 ++- apps/restconf/restconf_main_native.c | 108 ++-- apps/restconf/restconf_methods.c | 90 ++-- apps/restconf/restconf_methods.h | 11 +- apps/restconf/restconf_methods_get.c | 92 ++-- apps/restconf/restconf_methods_get.h | 6 +- apps/restconf/restconf_methods_patch.c | 66 ++- apps/restconf/restconf_methods_post.c | 80 +-- apps/restconf/restconf_methods_post.h | 2 +- apps/restconf/restconf_native.c | 210 ++++---- apps/restconf/restconf_native.h | 8 +- apps/restconf/restconf_nghttp2.c | 128 ++--- apps/restconf/restconf_root.c | 106 ++-- apps/restconf/restconf_stream_fcgi.c | 101 ++-- apps/snmp/snmp_handler.c | 131 ++--- apps/snmp/snmp_lib.c | 116 ++-- apps/snmp/snmp_lib.h | 6 +- apps/snmp/snmp_main.c | 66 +-- apps/snmp/snmp_register.c | 45 +- doc/FAQ.md | 4 +- example/main/example_backend.c | 183 +++---- example/main/example_backend_nacm.c | 37 +- example/main/example_cli.c | 23 +- example/main/example_netconf.c | 11 +- example/main/example_restconf.c | 47 +- include/clixon_custom.h | 17 +- lib/clixon/clixon_client.h | 10 +- lib/clixon/clixon_data.h | 8 +- lib/clixon/clixon_datastore.h | 2 +- lib/clixon/clixon_dispatcher.h | 1 + lib/clixon/clixon_err.h | 11 +- lib/clixon/clixon_event.h | 2 +- lib/clixon/clixon_file.h | 2 +- lib/clixon/clixon_handle.h | 2 +- lib/clixon/clixon_log.h | 13 +- lib/clixon/clixon_netconf_input.h | 2 +- lib/clixon/clixon_netconf_lib.h | 10 +- lib/clixon/clixon_options.h | 3 + lib/clixon/clixon_path.h | 4 +- lib/clixon/clixon_plugin.h | 41 +- lib/clixon/clixon_proc.h | 6 +- lib/clixon/clixon_proto.h | 4 +- lib/clixon/clixon_proto_client.h | 4 +- lib/clixon/clixon_queue.h | 7 +- lib/clixon/clixon_regex.h | 2 +- lib/clixon/clixon_sig.h | 2 +- lib/clixon/clixon_stream.h | 3 +- lib/clixon/clixon_string.h | 9 +- lib/clixon/clixon_uid.h | 2 +- lib/clixon/clixon_xml.h | 28 +- lib/clixon/clixon_xml_io.h | 2 +- lib/clixon/clixon_xml_map.h | 6 +- lib/clixon/clixon_xpath.h | 15 +- lib/clixon/clixon_xpath_ctx.h | 7 +- lib/clixon/clixon_xpath_optimize.h | 4 +- lib/clixon/clixon_xpath_yang.h | 4 +- lib/clixon/clixon_yang.h | 14 +- lib/clixon/clixon_yang_module.h | 3 +- lib/clixon/clixon_yang_schema_mount.h | 1 + lib/clixon/clixon_yang_type.h | 6 +- lib/src/clixon_api_path_parse.h | 2 +- lib/src/clixon_api_path_parse.y | 48 +- lib/src/clixon_client.c | 108 ++-- lib/src/clixon_data.c | 204 ++++--- lib/src/clixon_datastore.c | 88 ++-- lib/src/clixon_datastore_read.c | 113 ++-- lib/src/clixon_datastore_write.c | 78 +-- lib/src/clixon_dispatcher.c | 6 +- lib/src/clixon_err.c | 20 +- lib/src/clixon_event.c | 59 ++- lib/src/clixon_file.c | 26 +- lib/src/clixon_handle.c | 35 +- lib/src/clixon_hash.c | 31 +- lib/src/clixon_instance_id_parse.h | 2 +- lib/src/clixon_instance_id_parse.l | 17 +- lib/src/clixon_instance_id_parse.y | 18 +- lib/src/clixon_json.c | 183 +++---- lib/src/clixon_json_parse.h | 2 +- lib/src/clixon_json_parse.l | 14 +- lib/src/clixon_json_parse.y | 48 +- lib/src/clixon_log.c | 72 +-- lib/src/clixon_nacm.c | 154 +++--- lib/src/clixon_netconf_input.c | 16 +- lib/src/clixon_netconf_lib.c | 98 +++- lib/src/clixon_netconf_monitoring.c | 25 +- lib/src/clixon_netns.c | 36 +- lib/src/clixon_options.c | 129 ++--- lib/src/clixon_path.c | 164 +++--- lib/src/clixon_plugin.c | 192 ++++--- lib/src/clixon_proc.c | 121 +++-- lib/src/clixon_proto.c | 119 ++--- lib/src/clixon_proto_client.c | 123 +++-- lib/src/clixon_regex.c | 20 +- lib/src/clixon_sig.c | 72 +-- lib/src/clixon_stream.c | 144 ++--- lib/src/clixon_string.c | 81 +-- lib/src/clixon_text_syntax.c | 69 +-- lib/src/clixon_text_syntax_parse.h | 3 +- lib/src/clixon_text_syntax_parse.l | 2 +- lib/src/clixon_text_syntax_parse.y | 23 +- lib/src/clixon_uid.c | 50 +- lib/src/clixon_validate.c | 114 ++-- lib/src/clixon_validate_minmax.c | 46 +- lib/src/clixon_xml.c | 362 ++++++++----- lib/src/clixon_xml_bind.c | 31 +- lib/src/clixon_xml_changelog.c | 43 +- lib/src/clixon_xml_default.c | 38 +- lib/src/clixon_xml_io.c | 91 ++-- lib/src/clixon_xml_map.c | 199 ++++--- lib/src/clixon_xml_nsctx.c | 34 +- lib/src/clixon_xml_parse.l | 10 +- lib/src/clixon_xml_parse.y | 111 ++-- lib/src/clixon_xml_sort.c | 110 ++-- lib/src/clixon_xml_vec.c | 20 +- lib/src/clixon_xpath.c | 83 +-- lib/src/clixon_xpath_ctx.c | 45 +- lib/src/clixon_xpath_eval.c | 120 +++-- lib/src/clixon_xpath_eval.h | 2 +- lib/src/clixon_xpath_function.c | 56 +- lib/src/clixon_xpath_function.h | 2 +- lib/src/clixon_xpath_optimize.c | 36 +- lib/src/clixon_xpath_parse.h | 4 +- lib/src/clixon_xpath_parse.l | 26 +- lib/src/clixon_xpath_parse.y | 136 ++--- lib/src/clixon_xpath_yang.c | 26 +- lib/src/clixon_yang.c | 416 ++++++++------- lib/src/clixon_yang_cardinality.c | 26 +- lib/src/clixon_yang_internal.h | 4 +- lib/src/clixon_yang_module.c | 72 ++- lib/src/clixon_yang_parse.h | 2 +- lib/src/clixon_yang_parse.l | 17 +- lib/src/clixon_yang_parse.y | 614 +++++++++++----------- lib/src/clixon_yang_parse_lib.c | 158 +++--- lib/src/clixon_yang_schema_mount.c | 28 +- lib/src/clixon_yang_schemanode_parse.l | 2 +- lib/src/clixon_yang_schemanode_parse.y | 36 +- lib/src/clixon_yang_sub_parse.c | 4 +- lib/src/clixon_yang_sub_parse.h | 2 +- lib/src/clixon_yang_sub_parse.l | 2 +- lib/src/clixon_yang_sub_parse.y | 33 +- lib/src/clixon_yang_type.c | 168 +++--- util/clixon_netconf_ssh_callhome_client.c | 11 +- util/clixon_restconf_callhome_client.c | 70 +-- util/clixon_util_datastore.c | 4 +- util/clixon_util_dispatcher.c | 8 +- util/clixon_util_grpc.c | 53 +- util/clixon_util_json.c | 4 +- util/clixon_util_path.c | 15 +- util/clixon_util_regexp.c | 15 +- util/clixon_util_socket.c | 8 +- util/clixon_util_ssl.c | 53 +- util/clixon_util_stream.c | 33 +- util/clixon_util_validate.c | 8 +- util/clixon_util_xml.c | 13 +- util/clixon_util_xml_mod.c | 22 +- util/clixon_util_xpath.c | 23 +- util/clixon_util_yang.c | 2 +- 204 files changed, 6047 insertions(+), 4904 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 838ccf64..2a31af71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,14 @@ ## 6.5.0 Expected: December 2023 +### C/CLI-API changes on existing features +Developers may need to change their code + +* Changed function name for `clicon_debug` functions. You need to rename as follows: + * clicon_debug() -> clixon_debug() + * clicon_debug_init() -> clixon_debug_init() + * clicon_debug_get() -> clixon_debug_get() + ### Corrected Bugs * Fixed: [Does clixon cli support autocompletion for leafrefs pointed to another module?](https://github.com/clicon/clixon/issues/455) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index a1381d07..ab8d0b6c 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -104,8 +104,8 @@ ce_event_cb(clicon_handle h, void *arg) { struct client_entry *ce = (struct client_entry *)arg; - - clicon_debug(1, "%s op:%d", __FUNCTION__, op); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s op:%d", __FUNCTION__, op); switch (op){ case 1: /* Risk of recursion here */ @@ -140,7 +140,7 @@ ce_client_string(struct client_entry *ce, int retval = -1; cbuf *cb = NULL; char *id = NULL; - + if (ce == NULL || cbp == NULL){ clicon_err(OE_UNIX, EINVAL, "ce or cbp is NULL"); goto done; @@ -273,7 +273,7 @@ backend_monitoring_state_get(clicon_handle h, goto fail; retval = 1; done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); if (cb) cbuf_free(cb); return retval; @@ -293,7 +293,7 @@ backend_monitoring_state_get(clicon_handle h, * @see backend_client_delete for actual deallocation of client entry struct */ int -backend_client_rm(clicon_handle h, +backend_client_rm(clicon_handle h, struct client_entry *ce) { struct client_entry *c; @@ -311,10 +311,10 @@ backend_client_rm(clicon_handle h, if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { if (confirmed_commit_state_get(h) == EPHEMERAL) { /* See if this client is the origin */ - clicon_debug(1, "session_id: %u, confirmed_commit.session_id: %u", ce->ce_id, confirmed_commit_session_id_get(h)); + clixon_debug(CLIXON_DBG_DEFAULT, "session_id: %u, confirmed_commit.session_id: %u", ce->ce_id, confirmed_commit_session_id_get(h)); if (myid == confirmed_commit_session_id_get(h)) { - clicon_debug(1, "ok, rolling back"); + clixon_debug(CLIXON_DBG_DEFAULT, "ok, rolling back"); clicon_log(LOG_NOTICE, "a client with an active ephemeral confirmed-commit has disconnected; rolling back"); /* do_rollback errors are logged internally and there is no client to report errors to, so errors are @@ -326,7 +326,7 @@ backend_client_rm(clicon_handle h, } } - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); /* for all streams: XXX better to do it top-level? */ stream_ss_delete_all(h, ce_event_cb, (void*)ce); c0 = backend_client_list(h); @@ -367,8 +367,8 @@ clixon_stats_datastore_get(clicon_handle h, uint64_t nr = 0; size_t sz = 0; cxobj *xn = NULL; - - clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, dbname); + + clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, dbname); /* This is the db cache */ if ((xt = xmldb_cache_get(h, dbname)) == NULL){ /* Trigger cache if no exist (trick to ensure cache is present) */ @@ -409,7 +409,7 @@ clixon_stats_module_get(clicon_handle h, uint64_t nr = 0; size_t sz = 0; cxobj *xn = NULL; - + if (ys == NULL) return 0; if (yang_stats(ys, &nr, &sz) < 0) @@ -439,7 +439,7 @@ clixon_stats_module_get(clicon_handle h, * However, what really should be done is to apply the change to the datastore and then * validate, if error, discard to previous state. * But this could discard other previous changes to candidate. - */ + */ static int from_client_edit_config(clicon_handle h, cxobj *xn, @@ -480,7 +480,7 @@ from_client_edit_config(clicon_handle h, if ((cbx = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; - } + } /* Check if target locked by other client */ iddb = xmldb_islocked(h, target); if (iddb && myid != iddb){ @@ -645,22 +645,21 @@ from_client_edit_config(clicon_handle h, xml_free(xret); if (cbx) cbuf_free(cbx); - clicon_debug(1, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s done cbret:%s", __FUNCTION__, cbuf_get(cbret)); return retval; - } /* from_client_edit_config */ /*! Create or replace an entire config with another complete config db * - * @param[in] h Clixon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., only exec permission - * else: + * else: * - omit data nodes to which the client does not have read access * - access denied if user lacks create/delete/update */ @@ -679,7 +678,7 @@ from_client_copy_config(clicon_handle h, uint32_t myid = ce->ce_id; cbuf *cbx = NULL; /* Assist cbuf */ cbuf *cbmsg = NULL; - + if ((source = netconf_db_find(xe, "source")) == NULL){ if (netconf_missing_element(cbret, "protocol", "source", NULL) < 0) goto done; @@ -688,7 +687,7 @@ from_client_copy_config(clicon_handle h, if ((cbx = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; - } + } if ((target = netconf_db_find(xe, "target")) == NULL){ if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0) goto done; @@ -727,10 +726,10 @@ from_client_copy_config(clicon_handle h, /*! Delete a configuration datastore. * * @param[in] h Clixon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., ", NETCONF_BASE_NAMESPACE) < 0) goto done; @@ -959,7 +958,7 @@ from_client_unlock(clicon_handle h, /*! Request graceful termination of a NETCONF session. * - * @param[in] h Clixon handle + * @param[in] h Clixon handle * @param[in] xe Request: * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., ", NETCONF_BASE_NAMESPACE); @@ -1043,11 +1042,11 @@ from_client_kill_session(clicon_handle h, /*! Create a notification subscription * - * @param[in] h Clixon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., is not present, this is not a replay * subscription. * Schedule the replay to occur right after this RPC completes, eg "now" */ - if (starttime){ + if (starttime){ if (stream_replay_trigger(h, stream, ce_event_cb, (void*)ce) < 0) goto done; } @@ -1143,7 +1142,7 @@ from_client_create_subscription(clicon_handle h, /*! Retrieve a schema from the NETCONF server. * - * @param[in] h Clixon handle + * @param[in] h Clixon handle * @param[in] xe Request: * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., ", NETCONF_BASE_NAMESPACE); ok: retval = 0; @@ -1304,11 +1303,11 @@ from_client_debug(clicon_handle h, /*! Check liveness of backend daemon, just send a reply * - * @param[in] h Clixon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., %s", yang_argument_get(ym)); if (clixon_stats_module_get(h, ym, cbret) < 0) goto done; @@ -1418,11 +1417,11 @@ from_client_stats(clicon_handle h, /*! Request restart of specific plugins * - * @param[in] h Clixon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., ce_id != op_id && strcmp(rpcname, "create-subscription")){ - clicon_debug(1, "%s Warning: incoming session-id:%u does not match ce_id:%u on socket: %d", __FUNCTION__, op_id, ce->ce_id, ce->ce_s); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Warning: incoming session-id:%u does not match ce_id:%u on socket: %d", __FUNCTION__, op_id, ce->ce_id, ce->ce_s); } /* Note that this validation is also made in xml_yang_validate_rpc, but not for hello */ @@ -1707,7 +1706,7 @@ from_client_msg(clicon_handle h, goto done; } module = yang_argument_get(ymod); - clicon_debug(CLIXON_DBG_DEFAULT, "%s module:%s rpc:%s ce_id:%u s:%d", __FUNCTION__, module, + clixon_debug(CLIXON_DBG_DEFAULT, "%s module:%s rpc:%s ce_id:%u s:%d", __FUNCTION__, module, rpc, ce->ce_id, ce->ce_s); /* Pre-NACM access step */ xnacm = NULL; @@ -1773,7 +1772,7 @@ from_client_msg(clicon_handle h, if (cbuf_len(cbret) == 0) if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0) goto done; - // XXX clicon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret)); + // XXX clixon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret)); /* XXX problem here is that cbret has not been parsed so may contain parse errors */ if (ce_client_string(ce, &cbce) < 0) @@ -1797,8 +1796,8 @@ from_client_msg(clicon_handle h, } // ok: retval = 0; - done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + done: + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); if (xnacm){ xml_free(xnacm); if (clicon_nacm_cache_set(h, NULL) < 0) @@ -1813,10 +1812,10 @@ from_client_msg(clicon_handle h, if (cbret) cbuf_free(cbret); /* Sanity: log if clicon_err() is not called ! */ - if (retval < 0 && clicon_errno < 0) + if (retval < 0 && clicon_errno < 0) clicon_log(LOG_NOTICE, "%s: Internal error: No clicon_err call on RPC error (message: %s)", __FUNCTION__, rpc?rpc:""); - // clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + // clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval;// -1 here terminates backend } @@ -1829,7 +1828,7 @@ from_client_msg(clicon_handle h, * propagated back to client. */ int -from_client(int s, +from_client(int s, void* arg) { int retval = -1; @@ -1839,7 +1838,7 @@ from_client(int s, int eof = 0; cbuf *cbce = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (s != ce->ce_s){ clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s"); goto done; @@ -1849,7 +1848,7 @@ from_client(int s, if (clicon_msg_rcv(ce->ce_s, cbuf_get(cbce), 0, &msg, &eof) < 0) goto done; if (eof){ - backend_client_rm(h, ce); + backend_client_rm(h, ce); netconf_monitoring_counter_inc(h, "dropped-sessions"); } else @@ -1857,7 +1856,7 @@ from_client(int s, goto done; retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval=%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval=%d", __FUNCTION__, retval); if (cbce) cbuf_free(cbce); if (msg) diff --git a/apps/backend/backend_client.h b/apps/backend/backend_client.h index 590d024b..5d2547c9 100644 --- a/apps/backend/backend_client.h +++ b/apps/backend/backend_client.h @@ -39,7 +39,7 @@ /* * Prototypes - */ + */ int backend_monitoring_state_get(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); int backend_client_rm(clicon_handle h, struct client_entry *ce); int from_client(int fd, void *arg); diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index f7f578df..a61dc4d1 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -102,7 +102,7 @@ generic_validate(clicon_handle h, cbuf *cb = NULL; /* All entries */ - if ((ret = xml_yang_validate_all_top(h, td->td_target, xret)) < 0) + if ((ret = xml_yang_validate_all_top(h, td->td_target, xret)) < 0) goto done; if (ret == 0) goto fail; @@ -135,10 +135,11 @@ generic_validate(clicon_handle h, } /*! Common startup validation + * * Get db, upgrade it w potential transformed XML, populate it w yang spec, * sort it, validate it by triggering a transaction * and call application callback validations. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db The startup database. The wanted backend state * @param[in] td Transaction data * @param[out] cbret CLIgen buffer w error stmt if retval = 0 @@ -157,7 +158,7 @@ generic_validate(clicon_handle h, * @see validate_common for incoming validate/commit */ static int -startup_common(clicon_handle h, +startup_common(clicon_handle h, char *db, transaction_data_t *td, cbuf *cbret) @@ -177,7 +178,7 @@ startup_common(clicon_handle h, if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE")) if ((msdiff = modstate_diff_new()) == NULL) goto done; - clicon_debug(1, "Reading initial config from %s", db); + clixon_debug(CLIXON_DBG_DEFAULT, "Reading initial config from %s", db); /* Get the startup datastore WITHOUT binding to YANG, sorting and default setting. * It is done below, later in this function */ @@ -189,7 +190,7 @@ startup_common(clicon_handle h, if (clicon_quit_upgrade_get(h) == 1){ xml_print(stderr, xerr); clicon_err(OE_XML, 0, "invalid configuration before upgrade"); - exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding + exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding * See similar clause below */ } @@ -202,7 +203,7 @@ startup_common(clicon_handle h, if (xmldb_get0(h, db, YB_NONE, NULL, "/", 0, 0, &xt, msdiff, &xerr) < 0) goto done; } - clicon_debug_xml(CLIXON_DBG_DETAIL, xt, "startup"); + clixon_debug_xml(CLIXON_DBG_DETAIL, xt, "startup"); if (msdiff && msdiff->md_status == 0){ // Possibly check for CLICON_XMLDB_MODSTATE clicon_log(LOG_WARNING, "Modstate expected in startup datastore but not found\n" "This may indicate that the datastore is not initialized corrrectly, such as copy/pasted.\n" @@ -212,7 +213,7 @@ startup_common(clicon_handle h, clicon_err(OE_YANG, 0, "Yang spec not set"); goto done; } - clicon_debug(1, "Reading startup config done"); + clixon_debug(CLIXON_DBG_DEFAULT, "Reading startup config done"); /* Clear flags xpath for get */ xml_apply0(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE)); @@ -253,7 +254,7 @@ startup_common(clicon_handle h, stack. Alternative is to make a separate function stack for this. */ } /* If empty skip. Note upgrading can add children, so it may be empty before that. */ - if (xml_child_nr(xt) == 0){ + if (xml_child_nr(xt) == 0){ td->td_target = xt; xt = NULL; goto ok; @@ -264,7 +265,7 @@ startup_common(clicon_handle h, if (ret == 0){ if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; - goto fail; + goto fail; } /* After upgrade check no state data */ if ((ret = xml_non_config_data(xt, &xret)) < 0) @@ -272,7 +273,7 @@ startup_common(clicon_handle h, if (ret == 0){ if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; - goto fail; + goto fail; } /* Sort xml */ if (xml_sort_recurse(xt) < 0) @@ -283,7 +284,7 @@ startup_common(clicon_handle h, /* Apply default values (removed in clear function) */ if (xml_default_recurse(xt, 0) < 0) goto done; - + /* Handcraft transition with with only add tree */ td->td_target = xt; xt = NULL; @@ -291,7 +292,7 @@ startup_common(clicon_handle h, while ((x = xml_child_each(td->td_target, x, CX_ELMNT)) != NULL){ xml_flag_set(x, XML_FLAG_ADD); /* Also down */ xml_apply(x, CX_ELMNT, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_ADD); - if (cxvec_append(x, &td->td_avec, &td->td_alen) < 0) + if (cxvec_append(x, &td->td_avec, &td->td_alen) < 0) goto done; } @@ -301,7 +302,7 @@ startup_common(clicon_handle h, /* 5. Make generic validation on all new or changed data. Note this is only call that uses 3-values */ - clicon_debug(1, "Validating startup %s", db); + clixon_debug(CLIXON_DBG_DEFAULT, "Validating startup %s", db); if ((ret = generic_validate(h, yspec, td, &xret)) < 0) goto done; if (ret == 0){ @@ -328,14 +329,14 @@ startup_common(clicon_handle h, if (msdiff) modstate_diff_free(msdiff); return retval; - fail: + fail: retval = 0; goto done; } /*! Read startup db, check upgrades and validate it, return upgraded XML * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db The startup database. The wanted backend state * @param[out] xtr (Potentially) transformed XML * @param[out] cbret CLIgen buffer w error stmt if retval = 0 @@ -344,7 +345,7 @@ startup_common(clicon_handle h, * @retval -1 Error - or validation failed (but cbret not set) */ int -startup_validate(clicon_handle h, +startup_validate(clicon_handle h, char *db, cxobj **xtr, cbuf *cbret) @@ -369,7 +370,7 @@ startup_validate(clicon_handle h, if (xmldb_get0_clear(h, td->td_target) < 0) goto done; if (xtr){ - *xtr = td->td_target; + *xtr = td->td_target; td->td_target = NULL; } retval = 1; @@ -386,7 +387,7 @@ startup_validate(clicon_handle h, /*! Read startup db, check upgrades and commit it * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db The startup database. The wanted backend state * @param[out] cbret CLIgen buffer w error stmt if retval = 0 * @retval 1 Validation OK @@ -395,7 +396,7 @@ startup_validate(clicon_handle h, * Only called from startup_mode_startup */ int -startup_commit(clicon_handle h, +startup_commit(clicon_handle h, char *db, cbuf *cbret) { @@ -426,7 +427,7 @@ startup_commit(clicon_handle h, /* [Delete and] create running db */ if (xmldb_exists(h, "running") == 1){ - if (xmldb_delete(h, "running") != 0 && errno != ENOENT) + if (xmldb_delete(h, "running") != 0 && errno != ENOENT) goto done;; } if (xmldb_create(h, "running") < 0) @@ -463,9 +464,10 @@ startup_commit(clicon_handle h, } /*! Validate a candidate db and comnpare to running + * * Get both source and dest datastore, validate target, compute diffs * and call application callback validations. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db The (candidate) database. The wanted backend state * @param[in] td Transaction data * @param[out] xret Error XML tree, if retval is 0. Free with xml_free after use @@ -477,7 +479,7 @@ startup_commit(clicon_handle h, * @see startup_common for startup scenario */ static int -validate_common(clicon_handle h, +validate_common(clicon_handle h, char *db, transaction_data_t *td, cxobj **xret) @@ -487,11 +489,11 @@ validate_common(clicon_handle h, int i; cxobj *xn; int ret; - + if ((yspec = clicon_dbspec_yang(h)) == NULL){ clicon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; - } + } /* This is the state we are going to */ if ((ret = xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, 0, &td->td_target, NULL, xret)) < 0) goto done; @@ -500,7 +502,7 @@ validate_common(clicon_handle h, /* Clear flags xpath for get */ xml_apply0(td->td_target, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE)); - /* 2. Parse xml trees + /* 2. Parse xml trees * This is the state we are going from */ if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 0, 0, &td->td_src, NULL, xret)) < 0) goto done; @@ -520,7 +522,7 @@ validate_common(clicon_handle h, &td->td_tcvec, /* changed: wanted values */ &td->td_clen) < 0) goto done; - if (clicon_debug_get() & CLIXON_DBG_DETAIL) + if (clixon_debug_get() & CLIXON_DBG_DETAIL) transaction_dbg(h, CLIXON_DBG_DETAIL, td, __FUNCTION__); /* Mark as changed in tree */ for (i=0; itd_dlen; i++){ /* Also down */ @@ -571,7 +573,7 @@ validate_common(clicon_handle h, /*! Start a validate transaction * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db A candidate database, typically "candidate" but not necessarily so * @param[out] cbret CLIgen buffer w error stmt if retval = 0 * @retval 1 Validation OK @@ -579,7 +581,7 @@ validate_common(clicon_handle h, * @retval -1 Error - or validation failed */ int -candidate_validate(clicon_handle h, +candidate_validate(clicon_handle h, char *db, cbuf *cbret) { @@ -587,8 +589,8 @@ candidate_validate(clicon_handle h, transaction_data_t *td = NULL; cxobj *xret = NULL; int ret; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (db == NULL || cbret == NULL){ clicon_err(OE_CFG, EINVAL, "db or cbret is NULL"); goto done; @@ -647,7 +649,7 @@ candidate_validate(clicon_handle h, * The code reverts changes if the commit fails. But if the revert * fails, we just ignore the errors and proceed. Maybe we should * do something more drastic? - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xe Request: (or NULL) * @param[in] db A candidate database, not necessarily "candidate" * @param[in] myid Client id of triggering incoming message (or 0) @@ -658,7 +660,7 @@ candidate_validate(clicon_handle h, * @retval -1 Error - or validation failed */ int -candidate_commit(clicon_handle h, +candidate_commit(clicon_handle h, cxobj *xe, char *db, uint32_t myid, @@ -713,7 +715,7 @@ candidate_commit(clicon_handle h, /* After commit, make a post-commit call (sure that all plugins have committed) */ if (plugin_transaction_commit_done_all(h, td) < 0) goto done; - + /* Clear cached trees from default values and marking */ if (xmldb_get0_clear(h, td->td_target) < 0) goto done; @@ -738,7 +740,6 @@ candidate_commit(clicon_handle h, /* 9. Call plugin transaction end callbacks */ plugin_transaction_end_all(h, td); - retval = 1; done: /* In case of failure (or error), call plugin transaction termination callbacks */ @@ -759,11 +760,11 @@ candidate_commit(clicon_handle h, /*! Commit the candidate configuration as the device's new current configuration * - * @param[in] h Clicon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., ce_id; uint32_t iddb; cbuf *cbx = NULL; /* Assist cbuf */ - + /* Check if target locked by other client */ iddb = xmldb_islocked(h, "candidate"); if (iddb && myid != iddb){ if ((cbx = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; - } + } cprintf(cbx, "%u", iddb); if (netconf_lock_denied(cbret, cbuf_get(cbx), "Operation failed, lock is already held") < 0) goto done; @@ -890,11 +890,12 @@ from_client_discard_changes(clicon_handle h, } /*! Validates the contents of the specified configuration. - * @param[in] h Clicon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., cc_persist_id != NULL) @@ -130,7 +131,7 @@ enum confirmed_commit_state confirmed_commit_state_get(clicon_handle h) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); return cc->cc_state; } @@ -140,7 +141,7 @@ confirmed_commit_state_set(clicon_handle h, enum confirmed_commit_state state) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); cc->cc_state = state; return 0; @@ -150,7 +151,7 @@ char * confirmed_commit_persist_id_get(clicon_handle h) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); return cc->cc_persist_id; } @@ -160,7 +161,7 @@ confirmed_commit_persist_id_set(clicon_handle h, char *persist_id) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); if (cc->cc_persist_id) free(cc->cc_persist_id); @@ -179,7 +180,7 @@ uint32_t confirmed_commit_session_id_get(clicon_handle h) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); return cc->cc_session_id; } @@ -189,7 +190,7 @@ confirmed_commit_session_id_set(clicon_handle h, uint32_t session_id) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); cc->cc_session_id = session_id; return 0; @@ -201,7 +202,7 @@ confirmed_commit_fn_arg_get(clicon_handle h, void **arg) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); *fn = cc->cc_fn; *arg = cc->cc_arg; @@ -214,7 +215,7 @@ confirmed_commit_fn_arg_set(clicon_handle h, void *arg) { struct confirmed_commit *cc = NULL; - + clicon_ptr_get(h, "confirmed-commit-struct", (void**)&cc); cc->cc_fn = fn; cc->cc_arg = arg; @@ -222,6 +223,7 @@ confirmed_commit_fn_arg_set(clicon_handle h, } /*! Return if confirmed tag found + * * @param[in] xe Commit rpc xml * @retval 1 Confirmed tag exists * @retval 0 Confirmed tag does not exist @@ -233,6 +235,7 @@ xe_confirmed(cxobj *xe) } /*! Return if persist exists and its string value field + * * @param[in] xe Commit rpc xml * @param[out] str Pointer to persist * @retval 1 Persist field exists @@ -274,6 +277,7 @@ xe_persist_id(cxobj *xe, } /*! Return timeout + * * @param[in] xe Commit rpc xml * @retval sec Timeout in seconds, can be 0 if no timeout exists or is zero */ @@ -282,7 +286,7 @@ xe_timeout(cxobj *xe) { cxobj *xml; char *str; - + if ((xml = xml_find_type(xe, NULL, "confirm-timeout", CX_ELMNT)) != NULL && (str = xml_body(xml)) != NULL) return strtoul(str, NULL, 10); @@ -293,7 +297,7 @@ xe_timeout(cxobj *xe) * * @param[in] h Clixon handle * @retval 0 Rollback event successfully cancelled - * @retval -1 No Rollback event was found + * @retval -1 No Rollback event was found */ int cancel_rollback_event(clicon_handle h) @@ -317,7 +321,7 @@ cancel_rollback_event(clicon_handle h) * @param[in] fd a dummy argument per the event callback semantics * @param[in] arg a void pointer to a clicon_handle * @retval 0 the rollback was successful - * @retval -1 the rollback failed + * @retval -1 the rollback failed * @see do_rollback() */ static int @@ -337,7 +341,7 @@ rollback_fn(int fd, * @param[in] timeout a uint32 representing the number of seconds before the rollback event should fire * * @retval 0 Rollback event successfully scheduled - * @retval -1 Rollback event was not scheduled + * @retval -1 Rollback event was not scheduled */ static int schedule_rollback_event(clicon_handle h, @@ -373,6 +377,7 @@ schedule_rollback_event(clicon_handle h, } /*! Cancel a confirming commit by removing rollback, and free state + * * @param[in] h * @param[out] cbret * @retval 0 OK @@ -401,12 +406,12 @@ cancel_confirmed_commit(clicon_handle h) * without a value, OR * 2) be presented with a value that matches the value accompanying the prior confirmed-commit * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xe Request: * @param[in] myid current client session-id * @retval 1 The confirming-commit is valid * @retval 0 The confirming-commit is not valid - * @retval -1 Error + * @retval -1 Error */ static int check_valid_confirming_commit(clicon_handle h, @@ -452,7 +457,7 @@ check_valid_confirming_commit(clicon_handle h, "not issued on the same session as the confirmed-commit"); goto invalid; default: - clicon_debug(1, "commit-confirmed state !? %d", confirmed_commit_state_get(h)); + clixon_debug(CLIXON_DBG_DEFAULT, "commit-confirmed state !? %d", confirmed_commit_state_get(h)); goto invalid; } retval = 1; // valid @@ -471,11 +476,11 @@ check_valid_confirming_commit(clicon_handle h, * In the second phase, the action taken is to handle both confirming- and confirmed-commit by creating the * rollback database as required, then deleting it once the sequence is complete. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xe Commit rpc xml or NULL * @param[in] myid Current session-id, only valid > 0 if call is made as a result of an incoming message * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * @note There are some calls to this function where myid is 0 (which is invalid). It is unclear if such calls * actually occur, and if so, if they are correctly handled. The calls are from do_rollback() and load_failsafe() */ @@ -622,9 +627,9 @@ handle_confirmed_commit(clicon_handle h, * 2. from_client_cancel_commit() (invoked either by netconf client, or CLI) * 3. rollback_fn() (invoked by expiration of the rollback event timer) * - * @param[in] h Clicon handle - * @retval -1 Error + * @param[in] h Clixon handle * @retval 0 Success + * @retval -1 Error * @see backend_client_rm() * @see from_client_cancel_commit() * @see rollback_fn() @@ -696,12 +701,13 @@ do_rollback(clicon_handle h, } /*! Cancel an ongoing confirmed commit. + * * If the confirmed commit is persistent, the parameter 'persist-id' must be * given, and it must match the value of the 'persist' parameter. * If the confirmed-commit is ephemeral, the 'persist-id' must not be given and both the confirmed-commit and the * cancel-commit must originate from the same session. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xe Request: * @param[out] cbret Return xml tree, eg ..., * @param[in] myid Client-id * @param[out] cbret Return xml tree diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c index 174d09fd..55291511 100644 --- a/apps/backend/backend_get.c +++ b/apps/backend/backend_get.c @@ -72,12 +72,15 @@ #include "backend_handle.h" #include "backend_get.h" -/*! +/*! restrconf get capabilities + * * Maybe should be in the restconf client instead of backend? - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in] xpath Xpath selection, not used but may be to filter early * @param[out] xrs XML restconf-state node + * @retval 0 OK + * @retval -1 Error * @see netconf_hello_server * @see rfc8040 Sections 9.1 */ @@ -114,7 +117,8 @@ restconf_client_get_capabilities(clicon_handle h, } /*! Get streams state according to RFC 8040 or RFC5277 common function - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in] xpath Xpath selection, not used but may be to filter early * @param[in] module Name of yang module @@ -176,7 +180,8 @@ client_get_streams(clicon_handle h, } /*! Get system state-data, including streams and plugins - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xpath XPath selection, may be used to filter early * @param[in] nsc XML Namespace context for xpath * @param[in] wdef With-defaults parameter, see RFC 6243 @@ -213,7 +218,7 @@ get_statedata(clicon_handle h, cbuf *cb = NULL; cxobj *xerr = NULL; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((yspec = clicon_dbspec_yang(h)) == NULL){ clicon_err(OE_YANG, ENOENT, "No yang spec"); goto done; @@ -368,7 +373,7 @@ get_statedata(clicon_handle h, } /* switch wdef */ retval = 1; /* OK */ done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); if (xerr) xml_free(xerr); if (x1) @@ -390,7 +395,7 @@ get_statedata(clicon_handle h, * and we need to re-add it. * Note original xpath * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in] xret Result XML tree * @param[in] xvec xpath lookup result on xret @@ -438,7 +443,7 @@ filter_xpath_again(clicon_handle h, /*! Help function for NACM access and return message * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xret Result XML tree * @param[in] xvec xpath lookup result on xret * @param[in] xlen length of xvec @@ -520,7 +525,7 @@ element2value(clicon_handle h, /*! Extract offset and limit from get/list-pagination * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xe Request: * @param[out] offset Number of entries in the working result-set that should be skipped * @param[out] limit Limits the number of entries returned from the working result-set @@ -552,7 +557,7 @@ list_pagination_hdr(clicon_handle h, * * It is specialized enough to have its own function. Specifically, extra attributes as well * as the list-paginaiton API - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ce Client entry, for locking * @param[in] xe Request: * @param[in] content Get config/state/both @@ -764,7 +769,7 @@ get_list_pagination(clicon_handle h, if ((ret = xml_bind_yang(h, xret, YB_MODULE, yspec, &xerr)) < 0) goto done; if (ret == 0){ - clicon_debug_xml(1, xret, "Yang bind pagination state"); + clixon_debug_xml(1, xret, "Yang bind pagination state"); if (clixon_netconf_internal_error(xerr, ". Internal error, state callback returned invalid XML", NULL) < 0) @@ -821,7 +826,7 @@ get_list_pagination(clicon_handle h, /*! Common get/get-config code for retrieving configuration and state information. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ce Client entry, for locking * @param[in] xe Request: * @param[in] content Get config/state/both @@ -867,7 +872,7 @@ get_common(clicon_handle h, char *wdefstr; wdef = WITHDEFAULTS_EXPLICIT; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); username = clicon_username_get(h); if ((yspec = clicon_dbspec_yang(h)) == NULL){ clicon_err(OE_YANG, ENOENT, "No yang spec9"); @@ -1013,7 +1018,7 @@ get_common(clicon_handle h, (ret = xml_yang_validate_add(h, xret, &xerr)) < 0) goto done; if (ret == 0){ - clicon_debug_xml(1, xret, "VALIDATE_STATE"); + clixon_debug_xml(1, xret, "VALIDATE_STATE"); if (clixon_netconf_internal_error(xerr, ". Internal error, state callback returned invalid XML", NULL) < 0) @@ -1044,7 +1049,7 @@ get_common(clicon_handle h, ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); if (xvec) free(xvec); if (xret) @@ -1067,12 +1072,12 @@ get_common(clicon_handle h, } /*! Retrieve all or part of a specified configuration. - * - * @param[in] h Clicon handle - * @param[in] xe Request: - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., - * @param[out] cbret Return xml tree, eg ..., + * @param[out] cbret Return xml tree, eg ..., ca_daemon) != NULL){ @@ -212,7 +212,7 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp, if (fn(h) < 0) { if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; - if (clicon_errno < 0) + if (clicon_errno < 0) clicon_log(LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clicon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; @@ -224,14 +224,14 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp, done: return retval; } - + /*! Call all plugins "post-" daemonize callbacks - * + * * This point in time is after "start" and after "pre-daemon" and * after daemonization/fork, ie when * daemon is in the background but before dropped privileges. * In case of foreground mode (-F) it is still called but no fork has occured. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval 0 OK * @retval -1 Error * @note Also called for non-background mode @@ -241,8 +241,8 @@ clixon_plugin_daemon_all(clicon_handle h) { int retval = -1; clixon_plugin_t *cp = NULL; - - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); /* Loop through all plugins, call callbacks in each */ while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (clixon_plugin_daemon_one(cp, h) < 0) @@ -289,7 +289,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp, plgstatedata_t *fn; /* Plugin statedata fn */ cxobj *x = NULL; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){ if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL) goto done; @@ -299,7 +299,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp, if (fn(h, nsc, xpath, x) < 0){ if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; - if (clicon_errno < 0) + if (clicon_errno < 0) clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto fail; /* Dont quit here on user callbacks */ @@ -344,10 +344,10 @@ clixon_plugin_statedata_all(clicon_handle h, int ret; cxobj *x = NULL; clixon_plugin_t *cp = NULL; - cbuf *cberr = NULL; + cbuf *cberr = NULL; cxobj *xerr = NULL; - - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); while ((cp = clixon_plugin_each(h, cp)) != NULL) { if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, &x)) < 0) goto done; @@ -373,7 +373,7 @@ clixon_plugin_statedata_all(clicon_handle h, x = NULL; continue; } - clicon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp)); + clixon_debug_xml(CLIXON_DBG_DETAIL, x, "%s %s STATE:", __FUNCTION__, clixon_plugin_name_get(cp)); /* XXX: ret == 0 invalid yang binding should be handled as internal error */ if ((ret = xml_bind_yang(h, x, YB_MODULE, yspec, &xerr)) < 0) goto done; @@ -436,13 +436,13 @@ clixon_plugin_lockdb_one(clixon_plugin_t *cp, int retval = -1; plglockdb_t *fn; /* Plugin statedata fn */ void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_lockdb) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (fn(h, db, lock, id) < 0) - goto done; + goto done; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; } @@ -470,12 +470,12 @@ clixon_plugin_lockdb_all(clicon_handle h, { int retval = -1; clixon_plugin_t *cp = NULL; - - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (clixon_plugin_lockdb_one(cp, h, db, lock, id) < 0) goto done; - } + } retval = 0; done: return retval; @@ -485,6 +485,8 @@ clixon_plugin_lockdb_all(clicon_handle h, * * @param[in] h Clixon handle * @param[in] xpath Registered XPath using canonical prefixes + * @retval 1 OK + * @retval -1 Error */ int clixon_pagination_cb_call(clicon_handle h, @@ -505,17 +507,19 @@ clixon_pagination_cb_call(clicon_handle h, clicon_ptr_get(h, "pagination-entries", (void**)&htable); if (htable && dispatcher_call_handlers(htable, h, xpath, &pd) < 0) goto done; - retval = 1; + retval = 1; // XXX 0? done: return retval; } -/*! Register a state data callback - * +/*! Register a state data callback + * * @param[in] h Clixon handle * @param[in] fn Callback * @param[in] xpath Registered XPath using canonical prefixes * @param[in] arg Domain-specific argument to send to callback + * @retval 0 OK + * @retval -1 Error */ int clixon_pagination_cb_register(clicon_handle h, @@ -526,7 +530,7 @@ clixon_pagination_cb_register(clicon_handle h, int retval = -1; dispatcher_definition x = {xpath, fn, arg}; dispatcher_entry_t *htable = NULL; - + clicon_ptr_get(h, "pagination-entries", (void**)&htable); if (dispatcher_register_handler(&htable, &x) < 0){ clicon_err(OE_PLUGIN, errno, "dispatcher"); @@ -547,7 +551,7 @@ int clixon_pagination_free(clicon_handle h) { dispatcher_entry_t *htable = NULL; - + clicon_ptr_get(h, "pagination-entries", (void**)&htable); if (htable) dispatcher_free(htable); @@ -579,7 +583,7 @@ transaction_new(void) * * @param[in] td Transaction data will be deallocated after the call */ -int +int transaction_free(transaction_data_t *td) { if (td->td_src) @@ -608,13 +612,13 @@ transaction_free(transaction_data_t *td) */ int plugin_transaction_begin_one(clixon_plugin_t *cp, - clicon_handle h, + clicon_handle h, transaction_data_t *td) { int retval = -1; trans_cb_t *fn; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_trans_begin) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) @@ -623,7 +627,7 @@ plugin_transaction_begin_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -639,19 +643,19 @@ plugin_transaction_begin_one(clixon_plugin_t *cp, /*! Call transaction_begin() in all plugins before a validate/commit. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK * @retval -1 Error: one of the plugin callbacks returned error */ int -plugin_transaction_begin_all(clicon_handle h, +plugin_transaction_begin_all(clicon_handle h, transaction_data_t *td) { int retval = -1; clixon_plugin_t *cp = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (plugin_transaction_begin_one(cp, h, td) < 0) goto done; @@ -670,8 +674,8 @@ plugin_transaction_begin_all(clicon_handle h, * @retval -1 Error */ int -plugin_transaction_validate_one(clixon_plugin_t *cp, - clicon_handle h, +plugin_transaction_validate_one(clixon_plugin_t *cp, + clicon_handle h, transaction_data_t *td) { int retval = -1; @@ -686,7 +690,7 @@ plugin_transaction_validate_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; @@ -701,13 +705,13 @@ plugin_transaction_validate_one(clixon_plugin_t *cp, /*! Call transaction_validate callbacks in all backend plugins * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK. Validation succeeded in all plugins * @retval -1 Error: one of the plugin callbacks returned validation fail */ int -plugin_transaction_validate_all(clicon_handle h, +plugin_transaction_validate_all(clicon_handle h, transaction_data_t *td) { int retval = -1; @@ -732,14 +736,14 @@ plugin_transaction_validate_all(clicon_handle h, * @retval -1 Error */ int -plugin_transaction_complete_one(clixon_plugin_t *cp, - clicon_handle h, +plugin_transaction_complete_one(clixon_plugin_t *cp, + clicon_handle h, transaction_data_t *td) { int retval = -1; trans_cb_t *fn; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_trans_complete) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) @@ -748,7 +752,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -762,7 +766,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp, /*! Call transaction_complete() in all plugins after validation (before commit) * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK * @retval -1 Error: one of the plugin callbacks returned error @@ -770,7 +774,7 @@ plugin_transaction_complete_one(clixon_plugin_t *cp, * @note Rename to transaction_complete? */ int -plugin_transaction_complete_all(clicon_handle h, +plugin_transaction_complete_all(clicon_handle h, transaction_data_t *td) { int retval = -1; @@ -796,21 +800,21 @@ plugin_transaction_complete_all(clicon_handle h, * plugin 2, then the revert will be made in plugins 1 and 0. */ static int -plugin_transaction_revert_all(clicon_handle h, +plugin_transaction_revert_all(clicon_handle h, transaction_data_t *td, int nr) { int retval = 0; clixon_plugin_t *cp = NULL; trans_cb_t *fn; - + while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) { if ((fn = clixon_plugin_api_get(cp)->ca_trans_revert) == NULL) continue; if ((retval = fn(h, (transaction_data)td)) < 0){ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed", __FUNCTION__, clixon_plugin_name_get(cp)); - break; + break; } } return retval; /* ignore errors */ @@ -827,13 +831,13 @@ plugin_transaction_revert_all(clicon_handle h, */ int plugin_transaction_commit_one(clixon_plugin_t *cp, - clicon_handle h, + clicon_handle h, transaction_data_t *td) { int retval = -1; trans_cb_t *fn; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) @@ -842,7 +846,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -856,7 +860,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, /*! Call transaction_commit callbacks in all backend plugins * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK * @retval -1 Error: one of the plugin callbacks returned error @@ -865,18 +869,18 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, * and in reverse order. */ int -plugin_transaction_commit_all(clicon_handle h, +plugin_transaction_commit_all(clicon_handle h, transaction_data_t *td) { int retval = -1; clixon_plugin_t *cp = NULL; int i=0; - + while ((cp = clixon_plugin_each(h, cp)) != NULL) { i++; if (plugin_transaction_commit_one(cp, h, td) < 0){ /* Make an effort to revert transaction */ - plugin_transaction_revert_all(h, td, i-1); + plugin_transaction_revert_all(h, td, i-1); goto done; } } @@ -894,14 +898,14 @@ plugin_transaction_commit_all(clicon_handle h, * @retval -1 Error */ int -plugin_transaction_commit_done_one(clixon_plugin_t *cp, - clicon_handle h, +plugin_transaction_commit_done_one(clixon_plugin_t *cp, + clicon_handle h, transaction_data_t *td) { int retval = -1; trans_cb_t *fn; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit_done) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) @@ -910,7 +914,7 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -924,14 +928,14 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp, /*! Call transaction_commit_done callbacks in all backend plugins * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK * @retval -1 Error: one of the plugin callbacks returned error * @note no revert is done */ int -plugin_transaction_commit_done_all(clicon_handle h, +plugin_transaction_commit_done_all(clicon_handle h, transaction_data_t *td) { int retval = -1; @@ -955,14 +959,14 @@ plugin_transaction_commit_done_all(clicon_handle h, * @retval -1 Error */ int -plugin_transaction_end_one(clixon_plugin_t *cp, - clicon_handle h, +plugin_transaction_end_one(clixon_plugin_t *cp, + clicon_handle h, transaction_data_t *td) { int retval = -1; trans_cb_t *fn; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_trans_end) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) @@ -971,7 +975,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -985,7 +989,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp, /*! Call transaction_end() in all plugins after a successful commit. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK * @retval -1 Error @@ -997,7 +1001,7 @@ plugin_transaction_end_all(clicon_handle h, int retval = -1; clixon_plugin_t *cp = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (plugin_transaction_end_one(cp, h, td) < 0) goto done; @@ -1008,14 +1012,14 @@ plugin_transaction_end_all(clicon_handle h, } int -plugin_transaction_abort_one(clixon_plugin_t *cp, - clicon_handle h, +plugin_transaction_abort_one(clixon_plugin_t *cp, + clicon_handle h, transaction_data_t *td) { int retval = -1; trans_cb_t *fn; void *wh = NULL; - + if ((fn = clixon_plugin_api_get(cp)->ca_trans_abort) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) @@ -1024,7 +1028,7 @@ plugin_transaction_abort_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */ - clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", + clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -1038,19 +1042,19 @@ plugin_transaction_abort_one(clixon_plugin_t *cp, /*! Call transaction_abort() in all plugins after a failed validation/commit. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] td Transaction data * @retval 0 OK * @retval -1 Error */ int -plugin_transaction_abort_all(clicon_handle h, +plugin_transaction_abort_all(clicon_handle h, transaction_data_t *td) { int retval = -1; clixon_plugin_t *cp = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (plugin_transaction_abort_one(cp, h, td) < 0) ; /* dont abort on error */ diff --git a/apps/backend/backend_plugin_restconf.c b/apps/backend/backend_plugin_restconf.c index b43489f4..9c87c603 100644 --- a/apps/backend/backend_plugin_restconf.c +++ b/apps/backend/backend_plugin_restconf.c @@ -70,6 +70,8 @@ * is started. * @param[in] h Clixon backend * @param[in] xt XML target + * @retval 0 OK + * @retval -1 Error */ static int restconf_pseudo_set_log(clicon_handle h, @@ -78,8 +80,8 @@ restconf_pseudo_set_log(clicon_handle h, int retval = -1; char **argv; int argc; - int i; - char *log = NULL; + int i; + char *log = NULL; char *dbg = NULL; cxobj *xb; @@ -138,6 +140,8 @@ restconf_pseudo_set_log(clicon_handle h, * and insert it as a optimization to reading it from the backend. * @param[in] h Clixon backend * @param[in] xt XML target + * @retval 0 OK + * @retval -1 Error */ static int restconf_pseudo_set_inline(clicon_handle h, @@ -146,11 +150,11 @@ restconf_pseudo_set_inline(clicon_handle h, int retval = -1; char **argv; int argc; - int i; + int i; cxobj *xrestconf; cbuf *cb = NULL; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (clixon_process_argv_get(h, RESTCONF_PROCESS, &argv, &argc) < 0) goto done; if ((xrestconf = xpath_first(xt, NULL, "restconf")) != NULL) @@ -170,7 +174,7 @@ restconf_pseudo_set_inline(clicon_handle h, clicon_err(OE_XML, errno, "stdup"); goto done; } - clicon_debug(1, "%s str:%s", __FUNCTION__, str); + clixon_debug(CLIXON_DBG_DEFAULT, "%s str:%s", __FUNCTION__, str); if (argv[i+1]) free(argv[i+1]); argv[i+1] = str; @@ -186,6 +190,7 @@ restconf_pseudo_set_inline(clicon_handle h, } /*! Process rpc callback function + * * - if RPC op is start, if enable is true, start the service, if false, error or ignore it * - if RPC op is stop, stop the service * These rules give that if RPC op is start and enable is false -> change op to none @@ -197,14 +202,14 @@ restconf_rpc_wrapper(clicon_handle h, { int retval = -1; cxobj *xt = NULL; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); switch (*operation){ case PROC_OP_STOP: /* if RPC op is stop, stop the service */ break; case PROC_OP_START: - /* RPC op is start & enable is true, then start the service, + /* RPC op is start & enable is true, then start the service, & enable is false, error or ignore it */ if (xmldb_get(h, "running", NULL, "/restconf", &xt) < 0) goto done; @@ -235,7 +240,8 @@ restconf_rpc_wrapper(clicon_handle h, } /*! Enable process-control of restconf daemon, ie start/stop restconf by registering restconf process - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @note Could also look in clixon-restconf and start process if enable is true, but that needs to * be in start callback using a pseudo plugin. * - Debug flag inheritance only works if backend is started with debug. If debug is set later @@ -277,24 +283,24 @@ restconf_pseudo_process_control(clicon_handle h) cprintf(cb, "%s/clixon_restconf", dir0); pgm = cbuf_get(cb); if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */ - clicon_debug(1, "Found %s", pgm); + clixon_debug(CLIXON_DBG_DEFAULT, "Found %s", pgm); found++; } else - clicon_debug(1, "Not found: %s", pgm); + clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm); } if (!found && (dir1 = CLIXON_CONFIG_SBINDIR) != NULL){ cbuf_reset(cb); cprintf(cb, "%s/clixon_restconf", dir1); pgm = cbuf_get(cb); - clicon_debug(1, "Looking for %s", pgm); + clixon_debug(CLIXON_DBG_DEFAULT, "Looking for %s", pgm); if (stat(pgm, &fstat) == 0){ /* Sanity check: program exists */ - clicon_debug(1, "Found %s", pgm); + clixon_debug(CLIXON_DBG_DEFAULT, "Found %s", pgm); found++; } else - clicon_debug(1, "Not found: %s", pgm); + clixon_debug(CLIXON_DBG_DEFAULT, "Not found: %s", pgm); } if (!found){ clicon_err(OE_RESTCONF, 0, "clixon_restconf not found in neither CLICON_RESTCONF_INSTALLDIR(%s) nor CLIXON_CONFIG_SBINDIR(%s). Try overriding with CLICON_RESTCONF_INSTALLDIR", @@ -343,7 +349,7 @@ restconf_pseudo_process_validate(clicon_handle h, int retval = -1; cxobj *xtarget; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); xtarget = transaction_target(td); /* If ssl-enable is true and (at least a) socket has ssl, * then server-cert-path and server-key-path must exist */ @@ -374,8 +380,8 @@ restconf_pseudo_process_commit(clicon_handle h, cxobj *xsource; cxobj *cx; int enabled = 0; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); xtarget = transaction_target(td); xsource = transaction_src(td); if (xpath_first(xtarget, NULL, "/restconf[enable='true']") != NULL) @@ -425,13 +431,16 @@ restconf_pseudo_process_commit(clicon_handle h, } /*! Register start/stop restconf RPC and create pseudo-plugin to monitor enable flag + * * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error */ int backend_plugin_restconf_register(clicon_handle h, yang_stmt *yspec) { - int retval = -1; + int retval = -1; clixon_plugin_t *cp = NULL; if (clixon_pseudo_plugin(h, "restconf pseudo plugin", &cp) < 0) diff --git a/apps/backend/backend_socket.c b/apps/backend/backend_socket.c index 998f99cf..a7cb1adc 100644 --- a/apps/backend/backend_socket.c +++ b/apps/backend/backend_socket.c @@ -78,7 +78,7 @@ /*! Open an INET stream socket and bind it to a file descriptor * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] dst IPv4 address (see inet_pton(3)) * @retval s Socket file descriptor (see socket(2)) * @retval -1 Error @@ -111,7 +111,7 @@ config_socket_init_ipv4(clicon_handle h, clicon_err(OE_UNIX, errno, "bind"); goto err; } - clicon_debug(1, "Listen on server socket at %s:%hu", dst, port); + clixon_debug(CLIXON_DBG_DEFAULT, "Listen on server socket at %s:%hu", dst, port); if (listen(s, 5) < 0){ clicon_err(OE_UNIX, errno, "listen"); goto err; @@ -126,7 +126,7 @@ config_socket_init_ipv4(clicon_handle h, * * The socket is accessed via CLICON_SOCK option, has 770 permissions * and group according to CLICON_SOCK_GROUP option. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] sock Unix file-system path * @retval s Socket file descriptor (see socket(2)) * @retval -1 Error @@ -154,7 +154,7 @@ config_socket_init_unix(clicon_handle h, if (group_name2gid(config_group, &gid) < 0) return -1; #if 0 - if (gid == 0) + if (gid == 0) clicon_log(LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group); #endif /* create unix socket */ @@ -169,16 +169,16 @@ config_socket_init_unix(clicon_handle h, old_mask = umask(S_IRWXO | S_IXGRP | S_IXUSR); if (bind(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){ clicon_err(OE_UNIX, errno, "bind"); - umask(old_mask); + umask(old_mask); goto err; } - umask(old_mask); + umask(old_mask); /* change socket path file group */ if (lchown(sock, -1, gid) < 0){ clicon_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group); goto err; } - clicon_debug(1, "Listen on server socket at %s", addr.sun_path); + clixon_debug(CLIXON_DBG_DEFAULT, "Listen on server socket at %s", addr.sun_path); if (listen(s, 5) < 0){ clicon_err(OE_UNIX, errno, "listen"); goto err; @@ -190,8 +190,8 @@ config_socket_init_unix(clicon_handle h, } /*! Open backend socket, the one clients send requests to, either ip or unix - * - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @retval s Socket file descriptor (see socket(2)) * @retval -1 Error */ @@ -220,12 +220,15 @@ backend_socket_init(clicon_handle h) } /*! Accept new socket client + * * @param[in] fd Socket (unix or ip) * @param[in] arg typecast clicon_handle + * @retval 0 OK + * @retval -1 Error */ int backend_accept_client(int fd, - void *arg) + void *arg) { int retval = -1; clicon_handle h = (clicon_handle)arg; @@ -242,7 +245,7 @@ backend_accept_client(int fd, uid_t guid; #endif - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); len = sizeof(from); if ((s = accept(fd, &from, &len)) < 0){ clicon_err(OE_UNIX, errno, "accept"); @@ -251,7 +254,7 @@ backend_accept_client(int fd, if ((ce = backend_client_add(h, &from)) == NULL) goto done; - /* + /* * Get credentials of connected peer - only for unix socket */ switch (from.sa_family){ @@ -281,7 +284,7 @@ backend_accept_client(int fd, name = NULL; } break; - case AF_INET: + case AF_INET: break; case AF_INET6: default: diff --git a/apps/backend/backend_socket.h b/apps/backend/backend_socket.h index 82ebc2ea..edb5dfe4 100644 --- a/apps/backend/backend_socket.h +++ b/apps/backend/backend_socket.h @@ -41,7 +41,7 @@ /* * Prototypes - */ + */ int backend_socket_init(clicon_handle h); int backend_accept_client(int fd, void *arg); diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index fd2a2c63..0056ea53 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -85,7 +85,7 @@ db_merge(clicon_handle h, { int retval = -1; cxobj *xt = NULL; - + /* Get data as xml from db1 */ if (xmldb_get0(h, (char*)db1, YB_MODULE, NULL, NULL, 1, WITHDEFAULTS_EXPLICIT, &xt, NULL, NULL) < 0) goto done; @@ -138,7 +138,7 @@ startup_mode_startup(clicon_handle h, int ret = 0; int rollback_exists; yang_stmt *yspec = clicon_dbspec_yang(h); - + if (strcmp(db, "running")==0){ clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db); goto done; @@ -273,8 +273,6 @@ load_extraxml(clicon_handle h, * @retval 1 OK * @retval 0 Validation failed * @retval -1 Error - - running -----------------+----+------> reset loadfile / merge @@ -289,14 +287,14 @@ startup_extraxml(clicon_handle h, int retval = -1; char *tmp_db = "tmp"; int ret; - cxobj *xt0 = NULL; - cxobj *xt = NULL; - + cxobj *xt0 = NULL; + cxobj *xt = NULL; + /* Clear tmp db */ if (xmldb_db_reset(h, tmp_db) < 0) goto done; /* Application may define extra xml in its reset function */ - if (clixon_plugin_reset_all(h, tmp_db) < 0) + if (clixon_plugin_reset_all(h, tmp_db) < 0) goto done; /* Extra XML can also be added via file */ if (file){ @@ -306,7 +304,7 @@ startup_extraxml(clicon_handle h, if (ret == 0) goto fail; } - /* + /* * Check if tmp db is empty. * It should be empty if extra-xml is null and reset plugins did nothing * then skip validation. @@ -325,7 +323,7 @@ startup_extraxml(clicon_handle h, goto done; if (ret == 0) goto fail; - if (xt==NULL || xml_child_nr(xt)==0) + if (xt==NULL || xml_child_nr(xt)==0) goto ok; /* Merge tmp into running (no commit) */ if ((ret = db_merge(h, tmp_db, "running", cbret)) < 0) @@ -338,7 +336,7 @@ startup_extraxml(clicon_handle h, if (xt0) xml_free(xt0); xmldb_get0_free(h, &xt); - if (xmldb_delete(h, tmp_db) != 0 && errno != ENOENT) + if (xmldb_delete(h, tmp_db) != 0 && errno != ENOENT) return -1; return retval; fail: @@ -360,10 +358,10 @@ startup_module_state(clicon_handle h, int retval = -1; cxobj *x = NULL; int ret; - + if (!clicon_option_bool(h, "CLICON_XMLDB_MODSTATE")) goto ok; - /* Set up cache + /* Set up cache * Now, access brief module cache with clicon_modst_cache_get(h, 1) */ if ((ret = yang_modules_state_get(h, yspec, NULL, NULL, 1, &x)) < 0) goto done; diff --git a/apps/backend/backend_startup.h b/apps/backend/backend_startup.h index 7191f028..e233f96f 100644 --- a/apps/backend/backend_startup.h +++ b/apps/backend/backend_startup.h @@ -41,7 +41,7 @@ /* * Prototypes - */ + */ int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret); int startup_extraxml(clicon_handle h, char *file, cbuf *cbret); int startup_module_state(clicon_handle h, yang_stmt *yspec); diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c index df3fa2d9..cdcccb62 100644 --- a/apps/backend/clixon_backend_handle.c +++ b/apps/backend/clixon_backend_handle.c @@ -78,6 +78,7 @@ * entries in the struct below. */ /*! Backend specific handle added to header CLICON handle + * * This file should only contain access functions for the _specific_ * entries in the struct below. * @note The top part must be equivalent to struct clicon_handle in clixon_handle.c @@ -89,7 +90,7 @@ struct backend_handle { clicon_hash_t *bh_data; /* internal clicon data (HDR) */ clicon_hash_t *ch_db_elmnt; /* xml datastore element cache data */ event_stream_t *bh_stream; /* notification streams, see clixon_stream.[ch] */ - + /* ------ end of common handle ------ */ struct client_entry *bh_ce_list; /* The client list */ int bh_ce_nr; /* Number of clients, just increment */ @@ -104,7 +105,8 @@ backend_handle_init(void) } /*! Deallocates a backend handle, including all client structs - * @Note: handle 'h' cannot be used in calls after this + * + * @note: handle 'h' cannot be used in calls after this * @see backend_client_rm */ int @@ -125,13 +127,14 @@ backend_handle_exit(clicon_handle h) } /*! Add new client, typically frontend such as cli, netconf, restconf - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] addr Address of client * @retval ce Client entry * @retval NULL Error */ struct client_entry * -backend_client_add(clicon_handle h, +backend_client_add(clicon_handle h, struct sockaddr *addr) { struct backend_handle *bh = handle(h); @@ -158,7 +161,8 @@ backend_client_add(clicon_handle h, } /*! Return client list - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @retval ce_list Client entry list (all sessions) */ struct client_entry * @@ -170,7 +174,8 @@ backend_client_list(clicon_handle h) } /*! Actually remove client from client list - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] ce Client handle * @see backend_client_rm which is more high-level */ @@ -201,7 +206,8 @@ backend_client_delete(clicon_handle h, } /*! Debug print backend clients - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] f UNIX output stream */ int diff --git a/apps/backend/clixon_backend_plugin.h b/apps/backend/clixon_backend_plugin.h index b0adbb05..8a3d1206 100644 --- a/apps/backend/clixon_backend_plugin.h +++ b/apps/backend/clixon_backend_plugin.h @@ -43,6 +43,7 @@ */ /*! Transaction data describing a system transition from a src to target state + * * Clixon internal, presented as void* to app's callback in the 'transaction_data' * type in clicon_backend_api.h * The struct contains source and target XML tree (e.g. candidate/running) @@ -68,6 +69,7 @@ typedef struct { } transaction_data_t; /*! Pagination userdata + * * Pagination can use a lock/transaction mechanism * If locking is not used, the plugin cannot expect more pagination calls, and no state or * caching should be used @@ -104,7 +106,7 @@ int clixon_plugin_lockdb_all(clicon_handle h, char *db, int lock, int id); int clixon_pagination_cb_register(clicon_handle h, handler_function fn, char *path, void *arg); int clixon_pagination_cb_call(clicon_handle h, char *xpath, int locked, - uint32_t offset, uint32_t limit, + uint32_t offset, uint32_t limit, cxobj *xstate); int clixon_pagination_free(clicon_handle h); diff --git a/apps/backend/clixon_backend_transaction.c b/apps/backend/clixon_backend_transaction.c index b40c8652..e61c4110 100644 --- a/apps/backend/clixon_backend_transaction.c +++ b/apps/backend/clixon_backend_transaction.c @@ -69,6 +69,7 @@ * would give running in source and 'a' and candidate in 'target'. */ /*! Get transaction id + * * @param[in] td transaction_data * @retval id transaction id */ @@ -79,6 +80,7 @@ transaction_id(transaction_data td) } /*! Get plugin/application specific callback argument + * * @param[in] td transaction_data * @retval arg callback argument */ @@ -89,6 +91,7 @@ transaction_arg(transaction_data td) } /*! Set plugin/application specific callback argument + * * @param[in] td transaction_data * @param[in] arg callback argument */ @@ -101,6 +104,7 @@ transaction_arg_set(transaction_data td, } /*! Get source database xml tree + * * @param[in] td transaction_data * @retval src source xml tree containing original state */ @@ -111,6 +115,7 @@ transaction_src(transaction_data td) } /*! Get target database xml tree + * * @param[in] td transaction_data * @retval xml target xml tree containing wanted state */ @@ -121,6 +126,7 @@ transaction_target(transaction_data td) } /*! Get delete xml vector, ie vector of xml nodes that are deleted src->target + * * @param[in] td transaction_data * @retval vec Vector of xml nodes */ @@ -131,6 +137,7 @@ transaction_dvec(transaction_data td) } /*! Get length of delete xml vector + * * @param[in] td transaction_data * @retval len Length of vector of xml nodes * @see transaction_dvec @@ -142,6 +149,7 @@ transaction_dlen(transaction_data td) } /*! Get add xml vector, ie vector of xml nodes that are added src->target + * * @param[in] td transaction_data * @retval vec Vector of xml nodes */ @@ -152,6 +160,7 @@ transaction_avec(transaction_data td) } /*! Get length of add xml vector + * * @param[in] td transaction_data * @retval len Length of vector of xml nodes * @see transaction_avec @@ -163,6 +172,7 @@ transaction_alen(transaction_data td) } /*! Get source changed xml vector, ie vector of xml nodes that changed + * * @param[in] td transaction_data * @retval vec Vector of xml nodes * These are only nodes of type LEAF. @@ -177,6 +187,7 @@ transaction_scvec(transaction_data td) } /*! Get target changed xml vector, ie vector of xml nodes that changed + * * @param[in] td transaction_data * @retval vec Vector of xml nodes * These are only nodes of type LEAF. @@ -191,6 +202,7 @@ transaction_tcvec(transaction_data td) } /*! Get length of changed xml vector + * * @param[in] td transaction_data * @retval len Length of vector of xml nodes * This is the length of both the src change vector and the target change vector @@ -211,8 +223,8 @@ int transaction_print(FILE *f, transaction_data th) { - cxobj *xn; - int i; + cxobj *xn; + int i; transaction_data_t *td; td = (transaction_data_t *)th; @@ -267,7 +279,7 @@ transaction_dbg(clicon_handle h, goto done; } if (i) - clicon_debug(dbglevel, "%s %" PRIu64 " %s del: %s", + clixon_debug(dbglevel, "%s %" PRIu64 " %s del: %s", __FUNCTION__, td->td_id, msg, cbuf_get(cb)); cbuf_reset(cb); for (i=0; itd_alen; i++){ @@ -276,7 +288,7 @@ transaction_dbg(clicon_handle h, goto done; } if (i) - clicon_debug(dbglevel, "%s %" PRIu64 " %s add: %s", + clixon_debug(dbglevel, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, msg, cbuf_get(cb)); cbuf_reset(cb); for (i=0; itd_clen; i++){ @@ -290,7 +302,7 @@ transaction_dbg(clicon_handle h, goto done; } if (i) - clicon_debug(dbglevel, "%s %" PRIu64 " %s change: %s", + clixon_debug(dbglevel, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, msg, cbuf_get(cb)); done: if (cb) @@ -299,7 +311,6 @@ transaction_dbg(clicon_handle h, } /*! Log a transaction - * */ int transaction_log(clicon_handle h, diff --git a/apps/backend/clixon_backend_transaction.h b/apps/backend/clixon_backend_transaction.h index 6019ab54..e6344841 100644 --- a/apps/backend/clixon_backend_transaction.h +++ b/apps/backend/clixon_backend_transaction.h @@ -69,9 +69,9 @@ int transaction_log(clicon_handle h, transaction_data th, int level, const char /* Pagination callbacks * @see pagination_data_t internal structure */ -uint32_t pagination_offset(pagination_data pd); -uint32_t pagination_limit(pagination_data pd); -int pagination_locked(pagination_data pd); -cxobj *pagination_xstate(pagination_data pd); +uint32_t pagination_offset(pagination_data pd); +uint32_t pagination_limit(pagination_data pd); +int pagination_locked(pagination_data pd); +cxobj *pagination_xstate(pagination_data pd); #endif /* _CLIXON_BACKEND_TRANSACTION_H_ */ diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 5af4d9d5..c5467a98 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -86,7 +86,7 @@ co2apipath(cg_obj *co) cg_callback *cb; cvec *cvv; cg_var *cv; - + if (co == NULL) return NULL; if ((cb = co->co_callbacks) == NULL) @@ -121,7 +121,7 @@ cli_auto_edit(clicon_handle h, char *api_path_fmt; /* xml key format */ char *api_path = NULL; char *treename; - pt_head *ph; + pt_head *ph; cg_obj *co; cg_obj *coorig; cvec *cvv2 = NULL; /* cvv2 = cvv0 + cvv1 */ @@ -137,7 +137,7 @@ cli_auto_edit(clicon_handle h, str = cv_string_get(cvec_i(argv, argc++)); if (str && strncmp(str, "mtpoint:", strlen("mtpoint:")) == 0){ mtpoint = str + strlen("mtpoint:"); - clicon_debug(1, "%s mtpoint:%s", __FUNCTION__, mtpoint); + clixon_debug(CLIXON_DBG_DEFAULT, "%s mtpoint:%s", __FUNCTION__, mtpoint); treename = cv_string_get(cvec_i(argv, argc++)); } else @@ -181,7 +181,7 @@ cli_auto_edit(clicon_handle h, char *mtpoint2; if ((mtpoint2 = strdup(mtpoint)) == NULL){ clicon_err(OE_UNIX, errno, "strdup"); - goto done; + goto done; } if (clicon_data_set(h, "cli-edit-mtpoint", mtpoint2) < 0) goto done; @@ -205,9 +205,12 @@ cli_auto_edit(clicon_handle h, } /*! CLI callback: Working point tree up to parent + * * @param[in] h CLICON handle * @param[in] cvv Vector of variables from CLIgen command-line * @param[in] argv Vector of user-supplied keywords + * @retval 0 OK + * @retval -1 Error * Format of argv: * Name of generated cligen parse-tree, eg "datamodel" */ @@ -231,7 +234,7 @@ cli_auto_up(clicon_handle h, int j; size_t len; cvec *cvv_filter = NULL; - + if (cvec_len(argv) != 1){ clicon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__); goto done; @@ -283,7 +286,7 @@ cli_auto_up(clicon_handle h, cvv1 = cvec_new(0); for (i=0; i Name of generated cligen parse-tree, eg "datamodel" */ @@ -315,7 +321,7 @@ cli_auto_top(clicon_handle h, cg_var *cv; char *treename; pt_head *ph; - + cv = cvec_i(argv, 0); treename = cv_string_get(cv); if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ @@ -333,20 +339,23 @@ cli_auto_top(clicon_handle h, } /*! CLI callback: set auto db item - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error * Format of argv: * Generated */ -int +int cli_auto_set(clicon_handle h, cvec *cvv, cvec *argv) { int retval = -1; cvec *cvv2 = NULL; - + cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv); if (cli_dbxml(h, cvv2, argv, OP_REPLACE, NULL) < 0) goto done; @@ -358,18 +367,21 @@ cli_auto_set(clicon_handle h, } /*! Merge datastore xml entry - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_auto_merge(clicon_handle h, cvec *cvv, cvec *argv) { int retval = -1; cvec *cvv2 = NULL; - + cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv); if (cli_dbxml(h, cvv2, argv, OP_MERGE, NULL) < 0) goto done; @@ -381,18 +393,21 @@ cli_auto_merge(clicon_handle h, } /*! Create datastore xml entry - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_auto_create(clicon_handle h, cvec *cvv, cvec *argv) { - int retval = -1; + int retval = -1; cvec *cvv2 = NULL; - + cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv); if (cli_dbxml(h, cvv2, argv, OP_CREATE, NULL) < 0) goto done; @@ -404,18 +419,21 @@ cli_auto_create(clicon_handle h, } /*! Delete datastore xml - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_auto_del(clicon_handle h, cvec *cvv, cvec *argv) { int retval = -1; cvec *cvv2 = NULL; - + cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv); if (cli_dbxml(h, cvv2, argv, OP_REMOVE, NULL) < 0) goto done; @@ -438,7 +456,6 @@ struct findpt_arg{ * @param[in] arg Argument, cast to application-specific info * @retval 1 OK and return (abort iteration) * @retval 0 OK and continue - * @retval -1 Error: break and return */ static int cli_auto_findpt(cg_obj *co, @@ -456,9 +473,12 @@ cli_auto_findpt(cg_obj *co, } /*! Enter edit mode - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector of args to function in command. + * @retval 0 OK + * @retval -1 Error * Format of argv: * Generated API PATH FORMAT (print-like for variables) * * List of static variables that can be used as values for api_path_fmt @@ -471,7 +491,7 @@ cli_auto_findpt(cg_obj *co, * api_path: /a/b=42,99/c * @see cli_auto_edit */ -int +int cli_auto_sub_enter(clicon_handle h, cvec *cvv, cvec *argv) @@ -486,7 +506,7 @@ cli_auto_sub_enter(clicon_handle h, cg_var *cv = NULL; pt_head *ph; struct findpt_arg fa = {0,}; - + if (cvec_len(argv) < 2){ clicon_err(OE_PLUGIN, EINVAL, "Usage: %s( (,vars)*)", __FUNCTION__); goto done; @@ -506,7 +526,7 @@ cli_auto_sub_enter(clicon_handle h, * argv, but this can be done differently */ /* Create a cvv with variables to add to api-path */ - if ((cvv1 = cvec_new(0)) == NULL){ + if ((cvv1 = cvec_new(0)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_new"); goto done; } diff --git a/apps/cli/cli_autocli.c b/apps/cli/cli_autocli.c index d83cc73a..6e4f45bf 100644 --- a/apps/cli/cli_autocli.c +++ b/apps/cli/cli_autocli.c @@ -106,8 +106,8 @@ autocli_listkw_int2str(int listkw) * @param[in] h Clixon handle * @param[in] modname Name of YANG module, or NULL for ANY module (eg default) * @param[out] enablep Include this module in autocli - * @retval -1 Error * @retval 0 OK, and enablep set + * @retval -1 Error */ int autocli_module(clicon_handle h, @@ -171,7 +171,7 @@ autocli_module(clicon_handle h, } ok: *enablep = enable; - retval = 0; + retval = 0; done: return retval; } @@ -190,7 +190,7 @@ autocli_compress_extension(yang_stmt *ys, char *ns = NULL; int exist = 0; int ret; - + if (nodeid_split(body, &prefix, &id) < 0) goto done; if (prefix != NULL){ @@ -228,9 +228,8 @@ autocli_compress_extension(yang_stmt *ys, * * @param[in] h Clixon handle * @param[out] compress - * @retval -1 Error * @retval 0 OK, and compress set - + * @retval -1 Error * Canonical examples: The config and state containers are "compressed" out of the schema. + op=COMPRESS @@ -261,7 +260,7 @@ autocli_compress(clicon_handle h, char *keywstr; int match = 0; char *body; - + if (compress == NULL){ clicon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; @@ -346,8 +345,8 @@ autocli_compress(clicon_handle h, * Currently only returns list-keyword-default, could be extended to rules * @param[in] h Clixon handle * @param[out] completion Completion enabled - * @retval -1 Error * @retval 0 OK + * @retval -1 Error */ int autocli_completion(clicon_handle h, @@ -359,7 +358,7 @@ autocli_completion(clicon_handle h, char *reason = NULL; int ret; cxobj *xautocli; - + if (completion == NULL){ clicon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; @@ -377,7 +376,7 @@ autocli_completion(clicon_handle h, goto done; } *completion = val; - retval = 0; + retval = 0; done: if (reason) free(reason); @@ -389,8 +388,8 @@ autocli_completion(clicon_handle h, * When false replaces uses with grouping, when true use tree reference * @param[in] h Clixon handle * @param[out] treeref grouping using treerefs enabled - * @retval -1 Error * @retval 0 OK + * @retval -1 Error */ int autocli_grouping_treeref(clicon_handle h, @@ -402,7 +401,7 @@ autocli_grouping_treeref(clicon_handle h, char *reason = NULL; int ret; cxobj *xautocli; - + if (treeref == NULL){ clicon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; @@ -420,7 +419,7 @@ autocli_grouping_treeref(clicon_handle h, goto done; } *treeref = val; - retval = 0; + retval = 0; done: if (reason) free(reason); @@ -432,8 +431,8 @@ autocli_grouping_treeref(clicon_handle h, * Currently only returns list-keyword-default, could be extended to rules * @param[in] h Clixon handle * @param[out] listkw List keyword setting - * @retval -1 Error * @retval 0 OK + * @retval -1 Error */ int autocli_list_keyword(clicon_handle h, @@ -442,7 +441,7 @@ autocli_list_keyword(clicon_handle h, int retval = -1; char *str; cxobj *xautocli = NULL; - + if (listkw == NULL){ clicon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; @@ -456,7 +455,7 @@ autocli_list_keyword(clicon_handle h, goto done; } *listkw = autocli_listkw_str2int(str); - retval = 0; + retval = 0; done: return retval; } @@ -465,8 +464,8 @@ autocli_list_keyword(clicon_handle h, * * @param[in] h Clixon handle * @param[out] treeref_state If true, generate CLI from state - * @retval -1 Error * @retval 0 OK + * @retval -1 Error */ int autocli_treeref_state(clicon_handle h, @@ -478,7 +477,7 @@ autocli_treeref_state(clicon_handle h, char *reason = NULL; int ret; cxobj *xautocli; - + if (treeref_state == NULL){ clicon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; @@ -496,7 +495,7 @@ autocli_treeref_state(clicon_handle h, goto done; } *treeref_state = val; - retval = 0; + retval = 0; done: if (reason) free(reason); @@ -508,8 +507,8 @@ autocli_treeref_state(clicon_handle h, * @param[in] h Clixon handle * @param[in] keyw YANG keyword * @param[out] flag If 0 keyw is not a part of default edit-mode, if 1 it is. - * @retval -1 Error * @retval 0 OK, see result in keyw + * @retval -1 Error * @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined */ int @@ -524,7 +523,7 @@ autocli_edit_mode(clicon_handle h, int nvec; char *v; int i; - + if (flag == NULL){ clicon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; @@ -547,7 +546,7 @@ autocli_edit_mode(clicon_handle h, break; } } - retval = 0; + retval = 0; done: if (vec) free(vec); diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 0c1d2f94..81535b1b 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -72,20 +72,23 @@ #include "cli_common.h" /*! Register log notification stream - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] stream Event stream. CLICON is predefined, others are application-defined * @param[in] filter Filter. For xml notification ie xpath: .[name="kalle"] * @param[in] status 0 for stop, 1 to start * @param[in] fn Callback function called when notification occurs * @param[in] arg Argument to function note - * Note this calls cligen_regfd which may callback on cli command interpretator + * @retval 0 OK + * @retval -1 Error + * @note this calls cligen_regfd which may callback on cli command interpretator */ int -cli_notification_register(clicon_handle h, - char *stream, +cli_notification_register(clicon_handle h, + char *stream, enum format_enum format, - char *filter, - int status, + char *filter, + int status, int (*fn)(int, void*), void *arg) { @@ -101,7 +104,7 @@ cli_notification_register(clicon_handle h, if ((logname = malloc(len)) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; - } + } snprintf(logname, len, "log_socket_%s", stream); if ((p = clicon_hash_value(cdat, logname, &len)) != NULL) s_exist = *(int*)p; @@ -183,6 +186,11 @@ cli_signal_flush(clicon_handle h) } /*! Create body and add last CLI variable vector as value + * + * @param[in] xbot + * @param[in] cvv + * @retval 0 OK + * @retval -1 Error * Create and add an XML body as child of XML node xbot. Set its value to the last * CLI variable vector element. */ @@ -197,13 +205,13 @@ dbxml_body(cxobj *xbot, int len; len = cvec_len(cvv); - cval = cvec_i(cvv, len-1); + cval = cvec_i(cvv, len-1); if ((str = cv2str_dup(cval)) == NULL){ clicon_err(OE_UNIX, errno, "cv2str_dup"); goto done; } if ((xb = xml_new("body", xbot, CX_BODY)) == NULL) - goto done; + goto done; if (xml_value_set(xb, str) < 0) goto done; retval = 0; @@ -214,7 +222,12 @@ dbxml_body(cxobj *xbot, } /*! Special handling of identityref:s whose body may be: : + * * Ensure the namespace is declared if it exists in YANG + * @param[in] x + * @param[in] arg + * @retval 0 OK + * @retval -1 Error */ int identityref_add_ns(cxobj *x, @@ -234,7 +247,7 @@ identityref_add_ns(cxobj *x, yang_keyword_get(y) == Y_LEAF){ if (yang_type_get(y, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) goto done; - restype = yrestype?yang_argument_get(yrestype):NULL; + restype = yrestype?yang_argument_get(yrestype):NULL; if (strcmp(restype, "identityref") == 0){ if (nodeid_split(xml_body(x), &pf, NULL) < 0) goto done; @@ -249,7 +262,7 @@ identityref_add_ns(cxobj *x, goto done; } } - } + } } retval = 0; done: @@ -273,6 +286,8 @@ identityref_add_ns(cxobj *x, * @param[in] mtpoint Mount-point, generic: if there are several with same yang, any will do * @param[in] api_path_fmt1 Second part of api-path-fmt * @param[out] api_path_fmt01 Combined api-path-fmt + * @retval 0 OK + * @retval -1 Error */ int mtpoint_paths(yang_stmt *yspec0, @@ -290,7 +305,7 @@ mtpoint_paths(yang_stmt *yspec0, cxobj *xbot0 = NULL; cxobj *xtop0 = NULL; yang_stmt *yspec1; - + if (api_path_fmt01 == NULL){ clicon_err(OE_FATAL, EINVAL, "arg is NULL"); goto done; @@ -317,7 +332,7 @@ mtpoint_paths(yang_stmt *yspec0, if (xml_nsctx_yangspec(yspec0, &nsc0) < 0) goto done; if ((ret = xpath2xml(mtpoint, nsc0, xtop0, yspec0, &xbot0, &ybot0, NULL)) < 0) - goto done; + goto done; if (xbot0 == NULL){ clicon_err(OE_YANG, 0, "No xbot"); goto done; @@ -346,7 +361,7 @@ mtpoint_paths(yang_stmt *yspec0, /*! Modify xml datastore from a callback using xml key format strings * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Arguments given at the callback: * Generated API PATH (this is added implicitly, not actually given in the cvv) @@ -354,6 +369,8 @@ mtpoint_paths(yang_stmt *yspec0, * [] Optional YANG path-arg/xpath from mount-point * @param[in] op Operation to perform on database * @param[in] nsctx Namespace context for last value added + * @retval 0 OK + * @retval -1 Error * cvv first contains the complete cli string, and then a set of optional * instantiated variables. * If the last node is a leaf, the last cvv element is added as a value. This value @@ -369,9 +386,9 @@ mtpoint_paths(yang_stmt *yspec0, * generated by a function such as clixon_instance_id_bind() or other programmatically. */ int -cli_dbxml(clicon_handle h, - cvec *cvv, - cvec *argv, +cli_dbxml(clicon_handle h, + cvec *cvv, + cvec *argv, enum operation_type op, cvec *nsctx) { @@ -379,7 +396,7 @@ cli_dbxml(clicon_handle h, cbuf *api_path_fmt_cb = NULL; /* xml key format */ char *api_path_fmt; char *api_path_fmt01 = NULL; - char *api_path = NULL; + char *api_path = NULL; cbuf *cb = NULL; cxobj *xbot = NULL; /* xpath, NULL if datastore */ yang_stmt *y = NULL; /* yang spec of xpath */ @@ -407,7 +424,7 @@ cli_dbxml(clicon_handle h, goto done; api_path_fmt = cbuf_get(api_path_fmt_cb); argc = cvec_len(argv); - if (cvec_len(argv) > argc){ + if (cvec_len(argv) > argc){ cv = cvec_i(argv, argc++); str = cv_string_get(cv); if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){ @@ -419,7 +436,7 @@ cli_dbxml(clicon_handle h, /* Remove all keywords */ if (cvec_exclude_keys(cvv) < 0) goto done; - if (mtpoint){ + if (mtpoint){ /* Get and combined api-path01 */ if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0) goto done; @@ -505,18 +522,21 @@ cli_dbxml(clicon_handle h, if (cb) cbuf_free(cb); if (api_path) - free(api_path); + free(api_path); if (xtop) xml_free(xtop); return retval; } /*! Set datastore xml entry - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_set(clicon_handle h, cvec *cvv, cvec *argv) @@ -531,11 +551,14 @@ cli_set(clicon_handle h, } /*! Merge datastore xml entry - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_merge(clicon_handle h, cvec *cvv, cvec *argv) @@ -550,11 +573,14 @@ cli_merge(clicon_handle h, } /*! Create datastore xml entry - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_create(clicon_handle h, cvec *cvv, cvec *argv) @@ -567,13 +593,17 @@ cli_create(clicon_handle h, done: return retval; } + /*! Remove datastore xml entry - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error * @see cli_del */ -int +int cli_remove(clicon_handle h, cvec *cvv, cvec *argv) @@ -588,11 +618,14 @@ cli_remove(clicon_handle h, } /*! Delete datastore xml - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" + * @retval 0 OK + * @retval -1 Error */ -int +int cli_del(clicon_handle h, cvec *cvv, cvec *argv) @@ -607,22 +640,25 @@ cli_del(clicon_handle h, } /*! Set debug level on CLI client (not backend daemon) - * @param[in] h Clicon handle - * @param[in] vars If variable "level" exists, its integer value is used + * + * @param[in] h Clixon handle + * @param[in] cvv If variable "level" exists, its integer value is used * @param[in] arg Else use the integer value of argument + * @retval 0 OK + * @retval -1 Error * @note The level is either what is specified in arg as int argument. - * _or_ if a 'level' variable is present in vars use that value instead. + * _or_ if a 'level' variable is present in cvv use that value instead. */ int -cli_debug_cli(clicon_handle h, - cvec *vars, +cli_debug_cli(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; cg_var *cv; int level; - if ((cv = cvec_find_var(vars, "level")) == NULL){ + if ((cv = cvec_find_var(cvv, "level")) == NULL){ if (cvec_len(argv) != 1){ clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); goto done; @@ -631,29 +667,32 @@ cli_debug_cli(clicon_handle h, } level = cv_int32_get(cv); /* cli */ - clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ + clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ retval = 0; done: return retval; } /*! Set debug level on backend daemon (not CLI) - * @param[in] h Clicon handle - * @param[in] vars If variable "level" exists, its integer value is used + * + * @param[in] h Clixon handle + * @param[in] cvv If variable "level" exists, its integer value is used * @param[in] arg Else use the integer value of argument + * @retval 0 OK + * @retval -1 Error * @note The level is either what is specified in arg as int argument. - * _or_ if a 'level' variable is present in vars use that value instead. + * _or_ if a 'level' variable is present in cvv use that value instead. */ int -cli_debug_backend(clicon_handle h, - cvec *vars, +cli_debug_backend(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; cg_var *cv; int level; - if ((cv = cvec_find_var(vars, "level")) == NULL){ + if ((cv = cvec_find_var(cvv, "level")) == NULL){ if (cvec_len(argv) != 1){ clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); goto done; @@ -668,26 +707,29 @@ cli_debug_backend(clicon_handle h, } /*! Set debug level on restconf daemon - * @param[in] h Clicon handle - * @param[in] vars If variable "level" exists, its integer value is used + * + * @param[in] h Clixon handle + * @param[in] cvv If variable "level" exists, its integer value is used * @param[in] arg Else use the integer value of argument + * @retval 0 OK + * @retval -1 Error * @note The level is either what is specified in arg as int argument. - * _or_ if a 'level' variable is present in vars use that value instead. + * _or_ if a 'level' variable is present in cvv use that value instead. * @notes * 1. clixon-restconf.yang is used (so that debug config can be set) * 2. AND the XML is in running db not in clixon-config (so that restconf read the new config from backend) * 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf) */ int -cli_debug_restconf(clicon_handle h, - cvec *vars, +cli_debug_restconf(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; cg_var *cv; int level; - if ((cv = cvec_find_var(vars, "level")) == NULL){ + if ((cv = cvec_find_var(cvv, "level")) == NULL){ if (cvec_len(argv) != 1){ clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); goto done; @@ -703,10 +745,16 @@ cli_debug_restconf(clicon_handle h, /*! Set syntax mode + * + * @param[in] h Clixon handle + * @param[in] cvv + * @param[in] argv + * @retval 0 OK + * @retval -1 Error */ int -cli_set_mode(clicon_handle h, - cvec *vars, +cli_set_mode(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; @@ -724,25 +772,28 @@ cli_set_mode(clicon_handle h, } /*! Start bash from cli callback + * * Typical usage: shell("System Bash") , cli_start_shell(); * @param[in] h Clixon handle * @param[in] cvv Vector of command variables * @param[in] argv [], defaults to "sh" - */ + * @retval 0 OK + * @retval -1 Error + */ int -cli_start_shell(clicon_handle h, - cvec *vars, +cli_start_shell(clicon_handle h, + cvec *cvv, cvec *argv) { + int retval = -1; char *cmd; char *shcmd = "sh"; struct passwd *pw; - int retval = -1; char bcmd[128]; - cg_var *cv1 = cvec_i(vars, 1); + cg_var *cv1 = cvec_i(cvv, 1); sigset_t oldsigset; struct sigaction oldsigaction[32] = {{{0,},},}; - + if (cvec_len(argv) > 1){ clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: []", cvec_len(argv)); @@ -751,7 +802,7 @@ cli_start_shell(clicon_handle h, if (cvec_len(argv) == 1){ shcmd = cv_string_get(cvec_i(argv, 0)); } - cmd = (cvec_len(vars)>1 ? cv_string_get(cv1) : NULL); + cmd = (cvec_len(cvv)>1 ? cv_string_get(cv1) : NULL); if ((pw = getpwuid(getuid())) == NULL){ clicon_err(OE_UNIX, errno, "getpwuid"); goto done; @@ -798,10 +849,16 @@ cli_start_shell(clicon_handle h, } /*! Generic quit callback + * + * @param[in] h Clixon handle + * @param[in] cvv Vector of command variables + * @param[in] argv None expected + * @retval 0 OK + * @retval -1 Error */ -int -cli_quit(clicon_handle h, - cvec *vars, +int +cli_quit(clicon_handle h, + cvec *cvv, cvec *argv) { cligen_exiting_set(cli_cligen(h), 1); @@ -809,12 +866,17 @@ cli_quit(clicon_handle h, } /*! Generic commit callback + * + * @param[in] h Clixon handle + * @param[in] cvv Vector of command variables * @param[in] argv No arguments expected + * @retval 0 OK + * @retval -1 Error */ int -cli_commit(clicon_handle h, - cvec *vars, - cvec *argv) +cli_commit(clicon_handle h, + cvec *cvv, + cvec *argv) { int retval = -1; uint32_t timeout = 0; /* any non-zero value means "confirmed-commit" */ @@ -824,14 +886,14 @@ cli_commit(clicon_handle h, int confirmed; int cancel; - confirmed = (cvec_find_str(vars, "confirmed") != NULL); - cancel = (cvec_find_str(vars, "cancel") != NULL); - if ((timeout_var = cvec_find(vars, "timeout")) != NULL) { + confirmed = (cvec_find_str(cvv, "confirmed") != NULL); + cancel = (cvec_find_str(cvv, "cancel") != NULL); + if ((timeout_var = cvec_find(cvv, "timeout")) != NULL) { timeout = cv_uint32_get(timeout_var); - clicon_debug(1, "commit confirmed with timeout %ul", timeout); + clixon_debug(CLIXON_DBG_DEFAULT, "commit confirmed with timeout %ul", timeout); } - persist = cvec_find_str(vars, "persist-val"); - persist_id = cvec_find_str(vars, "persist-id-val"); + persist = cvec_find_str(cvv, "persist-val"); + persist_id = cvec_find_str(cvv, "persist-id-val"); if (clicon_rpc_commit(h, confirmed, cancel, timeout, persist, persist_id) < 1) goto done; retval = 0; @@ -840,10 +902,15 @@ cli_commit(clicon_handle h, } /*! Generic validate callback + * @param[in] h Clixon handle + * @param[in] cvv Vector of command variables + * @param[in] argv + * @retval 0 OK + * @retval -1 Error */ int -cli_validate(clicon_handle h, - cvec *vars, +cli_validate(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; @@ -861,9 +928,11 @@ cli_validate(clicon_handle h, * @param[in] format Output format * @param[in] db1 Name of first datastrore * @param[in] db2 Name of second datastrore + * @retval 0 OK + * @retval -1 Error */ int -compare_db_names(clicon_handle h, +compare_db_names(clicon_handle h, enum format_enum format, char *db1, char *db2) @@ -911,7 +980,7 @@ compare_db_names(clicon_handle h, case FORMAT_JSON: case FORMAT_CLI: if (clixon_compare_xmls(xc1, xc2, format) < 0) /* astext? */ - goto done; + goto done; default: break; } @@ -920,20 +989,23 @@ compare_db_names(clicon_handle h, if (cb) cbuf_free(cb); if (xc1) - xml_free(xc1); + xml_free(xc1); if (xc2) xml_free(xc2); return retval; } /*! Compare two dbs using XML. Write to file and run diff - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cvv * @param[in] argv + * @retval 0 OK + * @retval -1 Error */ int -compare_dbs(clicon_handle h, - cvec *cvv, +compare_dbs(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; @@ -961,14 +1033,17 @@ compare_dbs(clicon_handle h, } /*! Load a configuration file to candidate database + * * Utility function used by cligen spec file * Note that the CLI function makes no Validation of the XML sent to the backend - * @param[in] h CLICON handle + * @param[in] h Clixon handle * @param[in] cvv Vector of variables (where is found) * @param[in] argv A string: " []" * is name of a variable occuring in "cvv" containing filename * : merge or replace * "text"|"xml"|"json"|"cli"|"netconf" (see format_enum) + * @retval 0 OK + * @retval -1 Error * * @note that "filename" is local on client filesystem not backend. * @note file is assumed to have a dummy top-tag, eg @@ -978,9 +1053,9 @@ compare_dbs(clicon_handle h, * @endcode * @see save_config_file */ -int -load_config_file(clicon_handle h, - cvec *cvv, +int +load_config_file(clicon_handle h, + cvec *cvv, cvec *argv) { int ret = -1; @@ -997,7 +1072,7 @@ load_config_file(clicon_handle h, char *formatstr = NULL; enum format_enum format = FORMAT_XML; yang_stmt *yspec; - cxobj *xerr = NULL; + cxobj *xerr = NULL; char *lineptr = NULL; if (cvec_len(argv) < 2 || cvec_len(argv) > 4){ @@ -1018,16 +1093,16 @@ load_config_file(clicon_handle h, } varstr = cv_string_get(cvec_i(argv, 0)); opstr = cv_string_get(cvec_i(argv, 1)); - if (strcmp(opstr, "merge") == 0) + if (strcmp(opstr, "merge") == 0) replace = 0; - else if (strcmp(opstr, "replace") == 0) + else if (strcmp(opstr, "replace") == 0) replace = 1; else{ - clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr); + clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr); goto done; } if ((cv = cvec_find(cvv, varstr)) == NULL){ - clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); + clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); goto done; } filename = cv_string_get(cv); @@ -1085,7 +1160,7 @@ load_config_file(clicon_handle h, goto ok; /* eof, skip backend rpc since this is done by cli code */ } if (clicon_parse(h, lineptr, &mode, &result, &evalresult) < 0) - goto done; + goto done; if (result != 1) /* Not unique match */ goto done; if (evalresult < 0) @@ -1114,7 +1189,7 @@ load_config_file(clicon_handle h, if (clixon_xml2cbuf(cbxml, xt, 0, 0, NULL, -1, 1) < 0) goto done; if (clicon_rpc_edit_config(h, "candidate", - replace?OP_REPLACE:OP_MERGE, + replace?OP_REPLACE:OP_MERGE, cbuf_get(cbxml)) < 0) goto done; ok: @@ -1123,7 +1198,7 @@ load_config_file(clicon_handle h, if (cbxml) cbuf_free(cbxml); if (lineptr) - free(lineptr); + free(lineptr); if (xerr) xml_free(xerr); if (xt) @@ -1136,12 +1211,14 @@ load_config_file(clicon_handle h, /*! Copy database to local file as XMLn * * Utility function used by cligen spec file - * @param[in] h CLICON handle - * @param[in] cvv variable vector (containing ) - * @param[in] argv a string: " []" + * @param[in] h Clixon handle + * @param[in] cvv Variable vector (containing ) + * @param[in] argv A string: " []" * is running, candidate, or startup * is name of cligen variable in the "cvv" vector containing file name * "text"|"xml"|"json"|"cli"|"netconf" (see format_enum) + * @retval 0 OK + * @retval -1 Error * Note that "filename" is local on client filesystem not backend. * The function can run without a local database * @note The file is saved with dummy top-tag: clicon: @@ -1151,8 +1228,8 @@ load_config_file(clicon_handle h, * @see load_config_file */ int -save_config_file(clicon_handle h, - cvec *cvv, +save_config_file(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; @@ -1181,15 +1258,15 @@ save_config_file(clicon_handle h, } } dbstr = cv_string_get(cvec_i(argv, 0)); - if (strcmp(dbstr, "running") != 0 && + if (strcmp(dbstr, "running") != 0 && strcmp(dbstr, "candidate") != 0 && strcmp(dbstr, "startup") != 0) { - clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); + clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); goto done; } varstr = cv_string_get(cvec_i(argv, 1)); if ((cv = cvec_find(cvv, varstr)) == NULL){ - clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); + clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); goto done; } filename = cv_string_get(cv); @@ -1211,7 +1288,7 @@ save_config_file(clicon_handle h, if ((f = fopen(filename, "w")) == NULL){ clicon_err(OE_CFG, errno, "Creating file %s", filename); goto done; - } + } switch (format){ case FORMAT_XML: if (clixon_xml2file(f, xt, 0, pretty, NULL, fprintf, 0, 1) < 0) @@ -1249,11 +1326,17 @@ save_config_file(clicon_handle h, } /*! Delete all elements in a database + * * Utility function used by cligen spec file + * @param[in] h Clixon handle + * @param[in] cvv Vector of command variables + * @param[in] argv + * @retval 0 OK + * @retval -1 Error */ int -delete_all(clicon_handle h, - cvec *cvv, +delete_all(clicon_handle h, + cvec *cvv, cvec *argv) { char *dbstr; @@ -1264,10 +1347,10 @@ delete_all(clicon_handle h, goto done; } dbstr = cv_string_get(cvec_i(argv, 0)); - if (strcmp(dbstr, "running") != 0 && + if (strcmp(dbstr, "running") != 0 && strcmp(dbstr, "candidate") != 0 && strcmp(dbstr, "startup") != 0){ - clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); + clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); goto done; } if (clicon_rpc_delete_config(h, dbstr) < 0) @@ -1280,19 +1363,22 @@ delete_all(clicon_handle h, /*! Discard all changes in candidate and replace with running */ int -discard_changes(clicon_handle h, - cvec *cvv, +discard_changes(clicon_handle h, + cvec *cvv, cvec *argv) { return clicon_rpc_discard_changes(h); } /*! Copy from one database to another, eg running->startup + * * @param[in] argv a string: " " Copy from db1 to db2 + * @retval 0 OK + * @retval -1 Error and logged to syslog */ int -db_copy(clicon_handle h, - cvec *cvv, +db_copy(clicon_handle h, + cvec *cvv, cvec *argv) { char *db1; @@ -1304,11 +1390,14 @@ db_copy(clicon_handle h, } /*! This is the callback used by cli_setlog to print log message in CLI + * * param[in] s UNIX socket from backend where message should be read * param[in] arg format: txt, xml, xml2txt, xml2json + * @retval 0 OK + * @retval -1 Error */ static int -cli_notification_cb(int s, +cli_notification_cb(int s, void *arg) { int retval = -1; @@ -1317,7 +1406,7 @@ cli_notification_cb(int s, cxobj *xt = NULL; enum format_enum format = (enum format_enum)(uintptr_t)arg; int ret; - + /* get msg (this is the reason this function is called) */ if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0) goto done; @@ -1329,7 +1418,7 @@ cli_notification_cb(int s, goto done; } /* XXX pass yang_spec and use xerr*/ - if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0) + if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0) goto done; if (ret == 0){ /* will not happen since no yspec ^*/ clicon_err(OE_NETCONF, EFAULT, "Notification malformed"); @@ -1361,11 +1450,13 @@ cli_notification_cb(int s, /*! Make a notify subscription to backend and un/register callback for return messages. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Not used * @param[in] arg A string with [] * where is "0" or "1" * and is XXX + * @retval 0 OK + * @retval -1 Error * Example code: Start logging of mystream and show logs as xml * @code * cmd("comment"), cli_notify("mystream","1","xml"); @@ -1373,12 +1464,12 @@ cli_notification_cb(int s, * XXX: format is a memory leak */ int -cli_notify(clicon_handle h, - cvec *cvv, +cli_notify(clicon_handle h, + cvec *cvv, cvec *argv) { - char *stream = NULL; int retval = -1; + char *stream = NULL; int status; char *formatstr = NULL; enum format_enum format = FORMAT_TEXT; @@ -1393,12 +1484,12 @@ cli_notify(clicon_handle h, formatstr = cv_string_get(cvec_i(argv, 2)); format = format_str2int(formatstr); } - if (cli_notification_register(h, - stream, + if (cli_notification_register(h, + stream, format, - "", - status, - cli_notification_cb, + "", + status, + cli_notification_cb, (void*)format) < 0) goto done; @@ -1409,28 +1500,30 @@ cli_notify(clicon_handle h, /*! Lock database * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Not used * @param[in] arg A string with + * @retval 0 OK + * @retval -1 Error * @code * lock("comment"), cli_lock("running"); * @endcode * XXX: format is a memory leak */ int -cli_lock(clicon_handle h, - cvec *cvv, +cli_lock(clicon_handle h, + cvec *cvv, cvec *argv) { - char *db; int retval = -1; + char *db; if (cvec_len(argv) != 1){ clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: "); goto done; } db = cv_string_get(cvec_i(argv, 0)); - if (clicon_rpc_lock(h, db) < 0) + if (clicon_rpc_lock(h, db) < 0) goto done; retval = 0; done: @@ -1439,28 +1532,30 @@ cli_lock(clicon_handle h, /*! Unlock database * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Not used * @param[in] arg A string with + * @retval 0 OK + * @retval -1 Error * @code * lock("comment"), cli_lock("running"); * @endcode * XXX: format is a memory leak */ int -cli_unlock(clicon_handle h, - cvec *cvv, +cli_unlock(clicon_handle h, + cvec *cvv, cvec *argv) { - char *db; int retval = -1; + char *db; if (cvec_len(argv) != 1){ clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: "); goto done; } db = cv_string_get(cvec_i(argv, 0)); - if (clicon_rpc_unlock(h, db) < 0) + if (clicon_rpc_unlock(h, db) < 0) goto done; retval = 0; done: @@ -1474,13 +1569,15 @@ cli_unlock(clicon_handle h, * key name; * leaf name{... * - * @param[in] h CLICON handle + * @param[in] h Clixon handle * @param[in] cvv Vector of variables from CLIgen command-line * @param[in] argv Vector: , , , , + * @retval 0 OK + * @retval -1 Error * Explanation of argv fields: * db: Database name, eg candidate|tmp|startup - * xpath: XPATH expression with exactly two %s pointing to field and from name - * namespace: XPATH default namespace + * xpath: XPath expression with exactly two %s pointing to field and from name + * namespace: XPath default namespace * field: Name of list key, eg name * fromvar: Name of variable containing name of object to copy from (given by xpath) * tovar: Name of variable containing name of object to copy to. @@ -1492,14 +1589,14 @@ cli_unlock(clicon_handle h, * @endcode */ int -cli_copy_config(clicon_handle h, - cvec *cvv, +cli_copy_config(clicon_handle h, + cvec *cvv, cvec *argv) { int retval = -1; char *db; - cxobj *x1 = NULL; - cxobj *x2 = NULL; + cxobj *x1 = NULL; + cxobj *x2 = NULL; cxobj *x; char *xpath; char *namespace; @@ -1533,17 +1630,17 @@ cli_copy_config(clicon_handle h, fromvar = cv_string_get(cvec_i(argv, 4)); /* Fifth argv argument: to variable */ tovar = cv_string_get(cvec_i(argv, 5)); - + /* Get from variable -> cv -> from name */ if ((fromcv = cvec_find(cvv, fromvar)) == NULL){ - clicon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar); + clicon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar); goto done; } /* Get from name from cv */ fromname = cv_string_get(fromcv); /* Create xpath */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clicon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } /* Sanity check that xpath contains exactly two %s, ie [%s='%s'] */ @@ -1554,10 +1651,10 @@ cli_copy_config(clicon_handle h, j++; } if (j != 2){ - clicon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath); + clicon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath); goto done; } - cprintf(cb, xpath, keyname, fromname); + cprintf(cb, xpath, keyname, fromname); if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL) goto done; /* Get from object configuration and store in x1 */ @@ -1581,7 +1678,6 @@ cli_copy_config(clicon_handle h, goto done; xml_name_set(x2, NETCONF_INPUT_CONFIG); cprintf(cb, "/%s", keyname); - if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){ clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname); goto done; @@ -1608,8 +1704,18 @@ cli_copy_config(clicon_handle h, return retval; } +/*! CLI support function for printing comment/help string + * + * @param[in] h Clixon handle + * @param[in] cvv Not used + * @param[in] arg A string with + * @retval 0 OK + * @retval -1 Error + */ int -cli_help(clicon_handle h, cvec *vars, cvec *argv) +cli_help(clicon_handle h, + cvec *cvv, + cvec *argv) { cligen_handle ch = cli_cligen(h); parse_tree *pt; @@ -1620,17 +1726,19 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv) /*! CLI support function for restarting a plugin * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Not used * @param[in] arg A string with + * @retval 0 OK + * @retval -1 Error * @code * restart("comment") , cli_restart_plugin("myplugin", "restart"); * @endcode */ -int +int cli_restart_plugin(clicon_handle h, cvec *cvv, - cvec *argv) + cvec *argv) { int retval = -1; cg_var *cv; @@ -1644,7 +1752,7 @@ cli_restart_plugin(clicon_handle h, cv = cvec_i(argv, 0); } plugin = cv_string_get(cv); - retval = clicon_rpc_restart_plugin(h, plugin); + retval = clicon_rpc_restart_plugin(h, plugin); done: return retval; } @@ -1659,7 +1767,7 @@ cvec_append(cvec *cvv0, { cvec *cvv2 = NULL; cg_var *cv; - + if (cvv0 == NULL){ if ((cvv2 = cvec_dup(cvv1)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_dup"); @@ -1682,6 +1790,8 @@ cvec_append(cvec *cvv0, * * @param[in] cvv Input vector * @param[out] appstr Concatenated string as existing cbuf + * @retval 0 OK + * @retval -1 Error */ int cvec_concat_cb(cvec *cvv, @@ -1692,7 +1802,7 @@ cvec_concat_cb(cvec *cvv, cg_var *cv; char *str; int i; - + if (cb == NULL){ clicon_err(OE_PLUGIN, EINVAL, "cb is NULL"); goto done; @@ -1717,15 +1827,17 @@ cvec_concat_cb(cvec *cvv, /*! Process control as defined by clixon-lib API * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Not used * @param[in] arg Two strings: + * @retval 0 OK + * @retval -1 Error * @code * actions-daemon("Actions daemon operations") start, * cli_process_control("Action process", "start"); * @endcode */ -int +int cli_process_control(clicon_handle h, cvec *cvv, cvec *argv) @@ -1736,7 +1848,7 @@ cli_process_control(clicon_handle h, cbuf *cb = NULL; cxobj *xret = NULL; cxobj *xerr; - + if (cvec_len(argv) != 2){ clicon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation"); goto done; diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index 6d94ee12..4f665c45 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -122,8 +122,8 @@ You can see which CLISPEC it generates via clixon_cli -D 2: * @note XXX only fraction_digits handled,should also have mincv, maxcv, pattern */ static int -cli_expand_var_generate(clicon_handle h, - yang_stmt *ys, +cli_expand_var_generate(clicon_handle h, + yang_stmt *ys, const char *cvtypestr, int options, uint8_t fraction_digits, @@ -135,12 +135,12 @@ cli_expand_var_generate(clicon_handle h, int extvalue = 0; yang_stmt *yspec; cg_var *cv = NULL; - + if ((yspec = ys_spec(ys)) != NULL) cv = yang_cv_get(yspec); if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0) goto done; - if (extvalue || yang_find(ys, Y_STATUS, "deprecated") != NULL) + if (extvalue || yang_find(ys, Y_STATUS, "deprecated") != NULL) goto hide; if (yang2api_path_fmt(ys, 1, &api_path_fmt) < 0) goto done; @@ -167,15 +167,18 @@ cli_expand_var_generate(clicon_handle h, } /*! Create callback with api_path format string as argument + * * @param[in] h Clixon handle * @param[in] ys yang_stmt of the node at hand * @param[out] cb The string where the result format string is inserted. + * @retval 0 OK + * @retval -1 Error * @see cli_dbxml This is where the xmlkeyfmt string is used * @see pt_callback_reference in CLIgen where the actual callback overwrites the template */ static int -cli_callback_generate(clicon_handle h, - yang_stmt *ys, +cli_callback_generate(clicon_handle h, + yang_stmt *ys, cbuf *cb) { int retval = -1; @@ -200,6 +203,7 @@ cli_callback_generate(clicon_handle h, } /*! Print cligen help string as ("") + * * @param[in] cb CLIgen buf holding generated CLIspec * @param[in] helptext Help text */ @@ -243,10 +247,13 @@ yang2cli_print_alias(cbuf *cb, } /*! Generate identityref statements for CLI variables + * * @param[in] ys Yang statement * @param[in] ytype Resolved yang type. * @param[in] helptext CLI help text * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error * @see yang2cli_var_sub Its sub-function */ static int @@ -267,7 +274,7 @@ yang2cli_var_identityref(yang_stmt *ys, yang_stmt *ymod; yang_stmt *yprefix; yang_stmt *yspec; - + if ((ybaseref = yang_find(ytype, Y_BASE, NULL)) == NULL) goto ok; if ((ybaseid = yang_find_identity(ytype, yang_argument_get(ybaseref))) == NULL) @@ -316,10 +323,13 @@ yang2cli_var_identityref(yang_stmt *ys, } /*! Generate range check statements for CLI variables + * * @param[in] ys Yang statement * @param[in] options Flags field of optional values, eg YANG_OPTIONS_RANGE * @param[in] cvv Cvec with array of range_min/range_max cv:s (if YANG_OPTIONS_RANGE is set in options) * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error * @see yang2cli_var_sub which is the main function * In yang ranges are given as range 1 or range 1 .. 16, encoded in a cvv * 0 : range_min = x @@ -349,7 +359,7 @@ yang2cli_var_range(yang_stmt *ys, int i; cg_var *cv1; /* lower limit */ cg_var *cv2; /* upper limit */ - + /* Loop through range_min and range_min..range_max */ i = 0; while (i \" */ @@ -387,14 +400,14 @@ yang2cli_var_pattern(clicon_handle h, cvec *patterns, cbuf *cb) { - int retval = -1; + int retval = -1; enum regexp_mode mode; - cg_var *cvp; - char *pattern; - int invert; - char *posix = NULL; - int i; - + cg_var *cvp; + char *pattern; + int invert; + char *posix = NULL; + int i; + mode = clicon_yang_regexp(h); cvp = NULL; /* Loop over compiled regexps */ while ((cvp = cvec_each(patterns, cvp)) != NULL){ @@ -439,6 +452,7 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype, yang_stmt *ytype, char *helptext, cbuf *cb); /*! Generate CLI code for Yang leaf state ment to CLIgen variable of specific type + * * Check for completion (of already existent values), ranges (eg range[min:max]) and * patterns, (eg regexp:"[0.9]*"). * @param[in] h Clixon handle @@ -451,11 +465,13 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype, * @param[in] patterns Cvec of regexp patterns * @param[in] fraction for decimal64, how many digits after period * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error * @see yang_type_resolve for options and other arguments */ static int yang2cli_var_sub(clicon_handle h, - yang_stmt *ys, + yang_stmt *ys, yang_stmt *ytype, /* resolved type */ char *helptext, enum cv_type cvtype, @@ -481,7 +497,6 @@ yang2cli_var_sub(clicon_handle h, } type = ytype?yang_argument_get(ytype):NULL; cvtypestr = cv_type2str(cvtype); - if (type && strcmp(type, "identityref") == 0) cprintf(cb, "("); cprintf(cb, "<%s:%s", yang_argument_get(ys), cvtypestr); @@ -533,17 +548,20 @@ yang2cli_var_sub(clicon_handle h, } /*! Resolve a single Yang union and generate code + * * Part of generating CLI code for Yang leaf statement to CLIgen variable - * @param[in] h Clixon handle - * @param[in] ys Yang statement (caller of type) - * @param[in] origtype Name of original type in the call - * @param[in] ytsub Yang type invocation, a sub-type of a resolved union type - * @param[in] cb Buffer where cligen code is written + * @param[in] h Clixon handle + * @param[in] ys Yang statement (caller of type) + * @param[in] origtype Name of original type in the call + * @param[in] ytsub Yang type invocation, a sub-type of a resolved union type + * @param[in] cb Buffer where cligen code is written * @param[in] helptext CLI help text + * @retval 0 OK + * @retval -1 Error */ static int yang2cli_var_union_one(clicon_handle h, - yang_stmt *ys, + yang_stmt *ys, char *origtype, yang_stmt *ytsub, char *helptext, @@ -581,7 +599,7 @@ yang2cli_var_union_one(clicon_handle h, else { if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0) goto done; - if ((retval = yang2cli_var_sub(h, ys, ytype, helptext, cvtype, + if ((retval = yang2cli_var_sub(h, ys, ytype, helptext, cvtype, options, cvv, patterns, fraction_digits, cb)) < 0) goto done; } @@ -593,17 +611,20 @@ yang2cli_var_union_one(clicon_handle h, } /*! Loop over all sub-types of a Yang union + * * Part of generating CLI code for Yang leaf statement to CLIgen variable - * @param[in] h Clixon handle - * @param[in] ys Yang statement (caller) + * @param[in] h Clixon handle + * @param[in] ys Yang statement (caller) * @param[in] origtype Name of original type in the call - * @param[in] ytype Yang resolved type (a union in this case) - * @param[in] helptext CLI help text - * @param[out] cb Buffer where cligen code is written + * @param[in] ytype Yang resolved type (a union in this case) + * @param[in] helptext CLI help text + * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error */ static int yang2cli_var_union(clicon_handle h, - yang_stmt *ys, + yang_stmt *ys, char *origtype, yang_stmt *ytype, char *helptext, @@ -633,7 +654,7 @@ yang2cli_var_union(clicon_handle h, static int yang2cli_var_leafref(clicon_handle h, - yang_stmt *ys, + yang_stmt *ys, yang_stmt *yrestype, char *helptext, enum cv_type cvtype, @@ -669,11 +690,11 @@ yang2cli_var_leafref(clicon_handle h, if (completionp && regular_value) cprintf(cb, "("); if (regular_value) - if (yang2cli_var_sub(h, ys, yrestype, helptext, cvtype, + if (yang2cli_var_sub(h, ys, yrestype, helptext, cvtype, options, cvv, patterns, fraction_digits, cb) < 0) goto done; if (completionp){ - if ((ret = cli_expand_var_generate(h, ys, cvtypestr, + if ((ret = cli_expand_var_generate(h, ys, cvtypestr, options, fraction_digits, regular_value, cb)) < 0) goto done; @@ -688,11 +709,14 @@ yang2cli_var_leafref(clicon_handle h, } /*! Generate CLI code for Yang leaf statement to CLIgen variable + * * @param[in] h Clixon handle * @param[in] ys Yang statement of original leaf * @param[in] yreferred Yang statement of referred node for type (leafref) * @param[in] helptext CLI help text * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error * * Make a type lookup and complete a cligen variable expression such as . * One complication is yang union, that needs a recursion since it consists of @@ -707,7 +731,7 @@ yang2cli_var_leafref(clicon_handle h, static int yang2cli_var(clicon_handle h, yang_stmt *ys, - yang_stmt *yreferred, + yang_stmt *yreferred, char *helptext, cbuf *cb) { @@ -723,12 +747,12 @@ yang2cli_var(clicon_handle h, int options = 0; int completionp; int ret; - + if ((patterns = cvec_new(0)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_new"); goto done; } - if (yang_type_get(yreferred, &origtype, &yrestype, + if (yang_type_get(yreferred, &origtype, &yrestype, &options, &cvv, patterns, NULL, &fraction_digits) < 0) goto done; restype = yang_argument_get(yrestype); @@ -739,7 +763,7 @@ yang2cli_var(clicon_handle h, cvtypestr = cv_type2str(cvtype); /* Note restype can be NULL here for example with unresolved hardcoded uuid */ - if (strcmp(restype, "union") == 0){ + if (strcmp(restype, "union") == 0){ /* Union: loop over resolved type's sub-types (can also be recursive unions) */ cprintf(cb, "("); if (yang2cli_var_union(h, ys, origtype, yrestype, helptext, cb) < 0) @@ -747,7 +771,7 @@ yang2cli_var(clicon_handle h, if (autocli_completion(h, &completionp) < 0) goto done; if (completionp){ - if ((ret = cli_expand_var_generate(h, ys, cvtypestr, + if ((ret = cli_expand_var_generate(h, ys, cvtypestr, options, fraction_digits, 1, cb)) < 0) goto done; if (ret == 1) @@ -770,15 +794,15 @@ yang2cli_var(clicon_handle h, } if (yang_path_arg(yreferred, path_arg, &yref) < 0) goto done; - if (yref == NULL){ + if (yref == NULL){ /* Give up: use yreferred */ - if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options, + if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options, cvv, patterns, fraction_digits, cb) < 0) goto done; } else { - if (yreferred == yref){ + if (yreferred == yref){ clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg); goto done; } @@ -803,26 +827,29 @@ yang2cli_var(clicon_handle h, } /*! Generate CLI code for Yang leaf statement + * * @param[in] h Clixon handle * @param[in] ys Yang statement * @param[in] level Indentation level - * @param[in] callback If set, include a "; cli_set()" callback, otherwise not + * @param[in] callback If set, include a "; cli_set()" callback, otherwise not * @param[in] key_leaf 0: ordinary leaf, 1:prekey, 2: lastkey * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error * Some complexity in callback, key_leaf and extralevel logic. * If extralevel -> add extra { } level * + if callbacks add: cb();{} */ static int -yang2cli_leaf(clicon_handle h, - yang_stmt *ys, +yang2cli_leaf(clicon_handle h, + yang_stmt *ys, int level, int callback, int key_leaf, cbuf *cb) { - yang_stmt *yd; /* description */ int retval = -1; + yang_stmt *yd; /* description */ char *helptext = NULL; char *s; autocli_listkw_t listkw; @@ -841,7 +868,7 @@ yang2cli_leaf(clicon_handle h, } cprintf(cb, "%*s", level*3, ""); /* Called a second time in yang2cli_var, room for optimization */ - if (yang_type_get(ys, NULL, &yrestype, + if (yang_type_get(ys, NULL, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) goto done; if (key_leaf == 0 && strcmp(yang_argument_get(yrestype), "empty") != 0) @@ -905,27 +932,30 @@ yang2cli_leaf(clicon_handle h, } /*! Generate CLI code for Yang container statement + * * @param[in] h Clixon handle * @param[in] ys Yang statement * @param[in] level Indentation level - * @param[out] cb Buffer where cligen code is written + * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error */ static int -yang2cli_container(clicon_handle h, - yang_stmt *ys, +yang2cli_container(clicon_handle h, + yang_stmt *ys, int level, cbuf *cb) { + int retval = -1; yang_stmt *yc; yang_stmt *yd; - int retval = -1; char *helptext = NULL; char *s; int compress = 0; yang_stmt *ymod = NULL; int extvalue = 0; int ret; - + if (ys_real_module(ys, &ymod) < 0) goto done; /* If non-presence container && HIDE mode && only child is @@ -964,7 +994,7 @@ yang2cli_container(clicon_handle h, } } yc = NULL; - while ((yc = yn_each(ys, yc)) != NULL) + while ((yc = yn_each(ys, yc)) != NULL) if (yang2cli_stmt(h, yc, level+1, cb) < 0) goto done; if (!compress) @@ -977,24 +1007,27 @@ yang2cli_container(clicon_handle h, } /*! Generate CLI code for Yang list statement + * * @param[in] h Clixon handle * @param[in] ys Yang statement * @param[in] level Indentation level * @param[out] cb Buffer where cligen code is written + * @retval 0 OK + * @retval -1 Error */ static int yang2cli_list(clicon_handle h, - yang_stmt *ys, + yang_stmt *ys, int level, cbuf *cb) { + int retval = -1; yang_stmt *yc; yang_stmt *yd; yang_stmt *yleaf; cg_var *cvi; char *keyname; cvec *cvk = NULL; /* vector of index keys */ - int retval = -1; char *helptext = NULL; char *s; int last_key = 0; @@ -1023,7 +1056,7 @@ yang2cli_list(clicon_handle h, while ((cvi = cvec_each(cvk, cvi)) != NULL) { keyname = cv_string_get(cvi); if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){ - clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", + clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", yang_argument_get(ys), keyname); goto done; } @@ -1066,7 +1099,7 @@ yang2cli_list(clicon_handle h, } cprintf(cb, "%*s}\n", level*3, ""); /* Close with } for each key */ - while (keynr--) + while (keynr--) cprintf(cb, "%*s}\n", level*3, ""); retval = 0; done: @@ -1081,18 +1114,20 @@ yang2cli_list(clicon_handle h, * @param[in] ys Yang statement * @param[in] level Indentation level * @param[out] cb Buffer where cligen code is written -@example + * @retval 0 OK + * @retval -1 Error + * @code choice interface-type { container ethernet { ... } container fddi { ... } } -@example.end - @Note Removes 'meta-syntax' from cli syntax. They are not shown when xml is + * @code.end + @note Removes 'meta-syntax' from cli syntax. They are not shown when xml is translated to cli. and therefore input-syntax != output syntax. Which is bad */ static int -yang2cli_choice(clicon_handle h, - yang_stmt *ys, +yang2cli_choice(clicon_handle h, + yang_stmt *ys, int level, cbuf *cb) { @@ -1206,6 +1241,7 @@ yang2cli_uses(clicon_handle h, } /*! Generate CLI code for Yang statement + * * @param[in] h Clixon handle * @param[in] ys Yang statement * @param[in] level Indentation level @@ -1214,9 +1250,9 @@ yang2cli_uses(clicon_handle h, * @retval -1 Error */ static int -yang2cli_stmt(clicon_handle h, - yang_stmt *ys, - int level, +yang2cli_stmt(clicon_handle h, + yang_stmt *ys, + int level, cbuf *cb) { int retval = -1; @@ -1230,11 +1266,11 @@ yang2cli_stmt(clicon_handle h, goto done; } if (yang_find(ys, Y_STATUS, "obsolete") != NULL){ - clicon_debug(4, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); + clixon_debug(CLIXON_DBG_DETAIL, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); goto ok; } if (yang_find(ys, Y_STATUS, "deprecated") != NULL){ - clicon_debug(4, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); + clixon_debug(CLIXON_DBG_DETAIL, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); } /* Check if autocli skip */ if (yang_extension_value(ys, "skip", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0) @@ -1252,7 +1288,7 @@ yang2cli_stmt(clicon_handle h, #ifdef AUTOCLI_GROUPING_TOPLEVEL_SKIP cornercase = yang_keyword_get(yang_parent_get(ys)) == Y_MODULE || yang_keyword_get(yang_parent_get(ys)) == Y_SUBMODULE; #endif - if (yang_keyword_get(ys) != Y_USES && yang_flag_get(ys, YANG_FLAG_GROUPING) + if (yang_keyword_get(ys) != Y_USES && yang_flag_get(ys, YANG_FLAG_GROUPING) && !cornercase ) goto ok; @@ -1301,6 +1337,7 @@ yang2cli_stmt(clicon_handle h, } /*! Add cv with name to cvec + * * @param[in] cvv Either existing or NULL * @param[in] name Name of cv to add * @retval cvv Either same as in cvv parameter or new @@ -1310,7 +1347,7 @@ cvec_add_name(cvec *cvv, char *name) { cg_var *cv= NULL; - + if (cvv == NULL && (cvv = cvec_new(0)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_new"); @@ -1382,7 +1419,7 @@ yang2cli_post(clicon_handle h, char *name; cg_var *cv = NULL; int j=0; - + cv = NULL; while ((cv = cvec_each(cop->co_cvec, cv)) != NULL){ name = cv_name_get(cv); @@ -1480,7 +1517,7 @@ yang2cli_post(clicon_handle h, * XXX merge with yang2cli_yspec */ static int -yang2cli_grouping(clicon_handle h, +yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename) { @@ -1495,7 +1532,7 @@ yang2cli_grouping(clicon_handle h, cg_obj *co; int config; int i; - + if ((pt0 = pt_new()) == NULL){ clicon_err(OE_UNIX, errno, "pt_new"); goto done; @@ -1506,11 +1543,11 @@ yang2cli_grouping(clicon_handle h, } /* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */ if (yang_find(ys, Y_STATUS, "obsolete") != NULL){ - clicon_debug(4, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); + clixon_debug(CLIXON_DBG_DETAIL, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); goto empty; } if (yang_find(ys, Y_STATUS, "deprecated") != NULL){ - clicon_debug(4, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); + clixon_debug(CLIXON_DBG_DETAIL, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); } /* Only produce autocli for YANG non-config only if autocli-treeref-state is true */ if (autocli_treeref_state(h, &treeref_state) < 0) @@ -1539,12 +1576,12 @@ yang2cli_grouping(clicon_handle h, fprintf(stderr, "%s\n", cbuf_get(cb)); goto done; } - clicon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for grouping:%s", + clixon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for grouping:%s", __FUNCTION__, yang_argument_get(ys)); /* Add prefix: assume new are appended */ for (i=0; ico_command); co_prefix_set(co, prefix); } @@ -1562,7 +1599,7 @@ yang2cli_grouping(clicon_handle h, clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", __FUNCTION__, treename, cbuf_get(cb)); else - clicon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s", + clixon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s", __FUNCTION__, treename, cbuf_get(cb)); if (cligen_parsetree_merge(pt0, NULL, pt) < 0){ clicon_err(OE_YANG, errno, "cligen_parsetree_merge"); @@ -1614,7 +1651,7 @@ yang2cli_grouping(clicon_handle h, * @note Tie-break of same top-level symbol: prefix is NYI */ int -yang2cli_yspec(clicon_handle h, +yang2cli_yspec(clicon_handle h, yang_stmt *yspec, char *treename) { @@ -1629,7 +1666,7 @@ yang2cli_yspec(clicon_handle h, cg_obj *co; int i; int config; - + if ((pt0 = pt_new()) == NULL){ clicon_err(OE_UNIX, errno, "pt_new"); goto done; @@ -1669,12 +1706,12 @@ yang2cli_yspec(clicon_handle h, fprintf(stderr, "%s\n", cbuf_get(cb)); goto done; } - clicon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for module:%s", + clixon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for module:%s", __FUNCTION__, yang_argument_get(ymod)); /* Add prefix: assume new are appended */ for (i=0; ico_command); co_prefix_set(co, prefix); } @@ -1693,7 +1730,7 @@ yang2cli_yspec(clicon_handle h, clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", __FUNCTION__, treename, cbuf_get(cb)); else - clicon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s", + clixon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s", __FUNCTION__, treename, cbuf_get(cb)); if (cligen_parsetree_merge(pt0, NULL, pt) < 0){ clicon_err(OE_YANG, errno, "cligen_parsetree_merge"); diff --git a/apps/cli/cli_handle.c b/apps/cli/cli_handle.c index b8f2a3cf..e2e38c42 100644 --- a/apps/cli/cli_handle.c +++ b/apps/cli/cli_handle.c @@ -72,7 +72,8 @@ #define handle(h) (assert(clicon_handle_check(h)==0),(struct cli_handle *)(h)) #define cligen(h) (handle(h)->cl_cligen) -/*! CLI specific handle added to header CLICON handle +/*! CLI specific handle added to header Clixon handle + * * This file should only contain access functions for the _specific_ * entries in the struct below. * @note The top part must be equivalent to struct clicon_handle in clixon_handle.c @@ -115,6 +116,8 @@ cli_handle_init(void) } /*! Free clicon handle + * + * @param[in] h Clixon handle */ int cli_handle_exit(clicon_handle h) @@ -130,7 +133,10 @@ cli_handle_exit(clicon_handle h) * cli-specific handle access functions *----------------------------------------------------------*/ -/*! Return clicon handle */ +/*! Return clicon handle + * + * @param[in] h Clixon handle + */ cligen_handle cli_cligen(clicon_handle h) { @@ -156,8 +162,9 @@ cli_susp_hook(clicon_handle h, cligen_handle ch = cligen(h); /* This assume first arg of fn can be treated as void* */ - return cligen_susp_hook(ch, fn); + return cligen_susp_hook(ch, fn); } + int cli_interrupt_hook(clicon_handle h, cligen_interrupt_cb_t *fn) @@ -165,7 +172,7 @@ cli_interrupt_hook(clicon_handle h, cligen_handle ch = cligen(h); /* This assume first arg of fn can be treated as void* */ - return cligen_interrupt_hook(ch, fn); + return cligen_interrupt_hook(ch, fn); } int diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 6d109d1a..1dadc023 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -76,8 +76,11 @@ #define CLI_OPTS "+hD:f:E:l:C:F:1a:u:d:m:qp:GLy:c:U:o:" /*! Check if there is a CLI history file and if so dump the CLI histiry to it + * * Just log if file does not exist or is not readable - * @param[in] h CLICON handle + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error */ static int cli_history_load(clicon_handle h) @@ -121,8 +124,11 @@ cli_history_load(clicon_handle h) } /*! Start CLI history and load from file + * * Just log if file does not exist or is not readable - * @param[in] h CLICON handle + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error */ static int cli_history_save(clicon_handle h) @@ -157,6 +163,7 @@ cli_history_save(clicon_handle h) } /*! Clean and close all state of cli process (but dont exit). + * * Cannot use h after this * @param[in] h Clixon handle */ @@ -170,7 +177,7 @@ cli_terminate(clicon_handle h) if (clixon_exit_get() == 0) clixon_exit_set(1); if (clicon_data_get(h, "session-transport", NULL) == 0) - clicon_rpc_close_session(h); + clicon_rpc_close_session(h); if ((yspec = clicon_dbspec_yang(h)) != NULL) ys_free(yspec); if ((yspec = clicon_config_yang(h)) != NULL) @@ -195,11 +202,11 @@ cli_terminate(clicon_handle h) } /*! Unlink pidfile and quit -*/ + */ static void cli_sig_term(int arg) { - clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)", + clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)", __PROGRAM__, getpid(), arg); exit(1); } @@ -226,7 +233,8 @@ cli_signal_init (clicon_handle h) } /*! Interactive CLI command loop - * @param[in] h CLICON handle + * + * @param[in] h Clixon handle * @retval 0 * @retval -1 * @see cligen_loop @@ -269,6 +277,7 @@ cli_interactive(clicon_handle h) } /*! Create pre-5.5 tree-refs for backward compatibility + * * should probably be moved to clispec default */ static int @@ -382,8 +391,8 @@ autocli_start(clicon_handle h) int retval = -1; yang_stmt *yspec; int enable = 0; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); /* There is no single "enable-autocli" flag, * but set * false @@ -394,7 +403,7 @@ autocli_start(clicon_handle h) if (autocli_module(h, NULL, &enable) < 0) goto done; if (!enable){ - clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__); goto ok; } /* Init yang2cli */ @@ -404,7 +413,7 @@ autocli_start(clicon_handle h) /* The actual generating call from yang to clispec for the complete yang spec, @basemodel */ if (yang2cli_yspec(h, yspec, AUTOCLI_TREENAME) < 0) goto done; - /* XXX Create pre-5.5 tree-refs for backward compatibility */ + /* XXX Create pre-5.5 tree-refs for backward compatibility */ if (autocli_trees_default(h) < 0) goto done; ok: @@ -469,7 +478,7 @@ usage(clicon_handle h, fprintf(stderr, "usage:%s [options] [commands] [-- extra-options]\n" "where commands is a CLI command\n" - "and extra-options are app-dependent and passed to the plugin init function\n" + "and extra-options are app-dependent and passed to the plugin init function\n" "where options are\n" "\t-h \t\tHelp\n" "\t-D \tDebug level\n" @@ -525,7 +534,7 @@ main(int argc, int nr; int config_dump; enum format_enum config_dump_format = FORMAT_XML; - + /* Defaults */ once = 0; config_dump = 0; @@ -533,7 +542,7 @@ main(int argc, /* In the startup, logs to stderr & debug flag set later */ clicon_log_init(__PROGRAM__, LOG_INFO, logdst); - /* Initiate CLICON handle. CLIgen is also initialized */ + /* Initiate Clixon handle. CLIgen is also initialized */ if ((h = cli_handle_init()) == NULL) goto done; @@ -549,7 +558,7 @@ main(int argc, cligen_comment_set(cli_cligen(h), '#'); /* Default to handle #! clicon_cli scripts */ cligen_lexicalorder_set(cli_cligen(h), 1); - + /* * First-step command-line options for help, debug, config-file and log, */ @@ -588,11 +597,11 @@ main(int argc, goto done; break; } - /* + /* * Logs, error and debug to stderr or syslog, set debug level */ clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); yang_init(h); /* Find, read and parse configfile */ @@ -601,7 +610,7 @@ main(int argc, usage(h, argv[0]); goto done; } - /* Now rest of options */ + /* Now rest of options */ opterr = 0; optind = 1; while ((c = getopt(argc, argv, CLI_OPTS)) != -1){ @@ -698,7 +707,7 @@ main(int argc, /* Defer: Wait to the last minute to print help message */ if (help) usage(h, argv[0]); - + /* Split remaining argv/argc into and */ if (options_split(h, argv0, argc, argv, &restarg) < 0) goto done; @@ -713,7 +722,7 @@ main(int argc, nr = clicon_option_int(h, "CLICON_CLI_LINES_DEFAULT"); cligen_terminal_rows_set(cli_cligen(h), nr); } - + if (clicon_yang_regexp(h) == REGEXP_LIBXML2){ #ifdef HAVE_LIBXML2 /* Enable XSD libxml2 regex engine */ @@ -732,7 +741,7 @@ main(int argc, if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) clicon_log_string_limit_set(nr); - + /* Setup signal handlers */ if (cli_signal_init(h) < 0) goto done; @@ -757,7 +766,7 @@ main(int argc, goto done; } #endif - + /* Add (hardcoded) netconf features in case ietf-netconf loaded here * Otherwise it is loaded in netconf_module_load below */ @@ -772,7 +781,7 @@ main(int argc, if ((yspec = yspec_new()) == NULL) goto done; clicon_dbspec_yang_set(h, yspec); - + /* Load Yang modules * 1. Load a yang module as a specific absolute filename */ if ((str = clicon_yang_main_file(h)) != NULL){ @@ -802,7 +811,6 @@ main(int argc, /* Add netconf yang spec, used as internal protocol */ if (netconf_module_load(h) < 0) goto done; - /* Here all modules are loaded * Compute and set canonical namespace context */ @@ -868,7 +876,7 @@ main(int argc, clicon_option_dump(h, 1); cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING")); - /*! Start CLI history and load from file */ + /* Start CLI history and load from file */ if (cli_history_load(h) < 0) goto done; /* Experimental utf8 mode */ @@ -893,7 +901,7 @@ main(int argc, if (evalresult < 0) goto done; } - + /* Go into event-loop unless -1 command-line */ if (!once){ retval = cli_interactive(h); diff --git a/apps/cli/cli_pipe.c b/apps/cli/cli_pipe.c index 8b7a689c..07cfed19 100644 --- a/apps/cli/cli_pipe.c +++ b/apps/cli/cli_pipe.c @@ -92,7 +92,7 @@ pipe_arg_fn(clicon_handle h, struct stat fstat; char **argv = NULL; int i; - + if (cmd == NULL || strlen(cmd) == 0){ clicon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd); goto done; @@ -123,7 +123,7 @@ pipe_arg_fn(clicon_handle h, /* Grep pipe output function * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cvv Vector of cli string and instantiated variables * @param[in] argv String vector of options. Format: * @note May block on file I/O - * - * @retval 1 OK and valid - * @retval 0 Invalid (only if yang spec) w xerr set - * @retval -1 Error with clicon_err called - * * @see clixon_json_parse_string * @see RFC7951 */ @@ -1685,7 +1690,7 @@ clixon_json_parse_file(FILE *fp, } if (jsonbuf) free(jsonbuf); - return retval; + return retval; fail: retval = 0; goto done; diff --git a/lib/src/clixon_json_parse.h b/lib/src/clixon_json_parse.h index 839ccec4..e0cb3f91 100644 --- a/lib/src/clixon_json_parse.h +++ b/lib/src/clixon_json_parse.h @@ -40,7 +40,7 @@ * Types */ -struct clixon_json_yacc { +struct clixon_json_yacc { int jy_linenum; /* Number of \n in parsed buffer */ char *jy_parse_string; /* original (copy of) parse string */ void *jy_lexbuf; /* internal parse buffer from lex */ diff --git a/lib/src/clixon_json_parse.l b/lib/src/clixon_json_parse.l index f691b450..16c58205 100644 --- a/lib/src/clixon_json_parse.l +++ b/lib/src/clixon_json_parse.l @@ -70,7 +70,7 @@ #define _JY ((clixon_json_yacc *)_yy) #undef clixon_json_parsewrap -int +int clixon_json_parsewrap(void) { return 1; @@ -91,9 +91,9 @@ hex [A-Fa-f0-9] %% -[ \t] +[ \t] \n { _JY->jy_linenum++; } -\r +\r <> { return J_EOF; } \{ { return *yytext; } \} { return *yytext; } @@ -123,13 +123,13 @@ hex [A-Fa-f0-9] u { BEGIN(HEXDIG); } \n { return -1; } . { return -1; } -{hex}{hex}{hex}{hex} { +{hex}{hex}{hex}{hex} { char buf[5] = {0, }; - BEGIN(STRING); + BEGIN(STRING); if (clixon_unicode2utf8(yytext, buf, 5) < 0) return -1; strncpy(yytext, buf, 5); - clixon_json_parselval.string = yytext; + clixon_json_parselval.string = yytext; return J_STRING; } \n { return -1;} @@ -147,7 +147,7 @@ json_scan_init(clixon_json_yacc *jy) jy->jy_lexbuf = yy_scan_string (jy->jy_parse_string); #if 1 /* XXX: just to use unput to avoid warning */ if (0) - yyunput(0, ""); + yyunput(0, ""); #endif return 0; diff --git a/lib/src/clixon_json_parse.y b/lib/src/clixon_json_parse.y index 0170e2ea..ef48a27f 100644 --- a/lib/src/clixon_json_parse.y +++ b/lib/src/clixon_json_parse.y @@ -107,7 +107,7 @@ object. #define _YYERROR(msg) {clicon_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 +#define YY_(msgid) msgid #include "clixon_config.h" @@ -137,7 +137,7 @@ object. /* Enable for debugging, steals some cycles otherwise */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #else #define _PARSE_DEBUG(s) #endif @@ -148,14 +148,14 @@ extern int clixon_json_parseget_lineno (void); also called from yacc generated code * */ -void +void clixon_json_parseerror(void *_jy, - char *s) + char *s) { - clicon_err(OE_JSON, 0, "json_parse: line %d: %s at or before: '%s'", - _JY->jy_linenum , - s, - clixon_json_parsetext); + clicon_err(OE_JSON, 0, "json_parse: line %d: %s at or before: '%s'", + _JY->jy_linenum, + s, + clixon_json_parsetext); if (_JY->jy_cbuf_str) cbuf_free(_JY->jy_cbuf_str); return; @@ -164,7 +164,7 @@ clixon_json_parseerror(void *_jy, int json_parse_init(clixon_json_yacc *jy) { - // clicon_debug_init(2, NULL); + // clixon_debug_init(2, NULL); return 0; } @@ -173,8 +173,9 @@ json_parse_exit(clixon_json_yacc *jy) { return 0; } - + /*! Create xml object from json object name (eg "string") + * * Split name into prefix:name (extended JSON RFC7951) */ static int @@ -186,7 +187,7 @@ json_current_new(clixon_json_yacc *jy, char *prefix = NULL; char *id = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); /* Find colon separator and if found split into prefix:name */ if (nodeid_split(name, &prefix, &id) < 0) goto done; @@ -213,8 +214,8 @@ json_current_new(clixon_json_yacc *jy, static int json_current_pop(clixon_json_yacc *jy) { - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); - if (jy->jy_current) + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + if (jy->jy_current) jy->jy_current = xml_parent(jy->jy_current); return 0; } @@ -224,7 +225,7 @@ json_current_clone(clixon_json_yacc *jy) { cxobj *xn; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (jy->jy_current == NULL){ return -1; } @@ -243,7 +244,6 @@ json_current_clone(clixon_json_yacc *jy) maybe_prefixed_name = strdup(name); } json_current_new(jy, maybe_prefixed_name); - if (maybe_prefixed_name) free(maybe_prefixed_name); } @@ -251,31 +251,31 @@ json_current_clone(clixon_json_yacc *jy) } static int -json_current_body(clixon_json_yacc *jy, +json_current_body(clixon_json_yacc *jy, char *value) { int retval = -1; cxobj *xn; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if ((xn = xml_new("body", jy->jy_current, CX_BODY)) == NULL) - goto done; + goto done; if (value && xml_value_append(xn, value) < 0) - goto done; + goto done; retval = 0; done: return retval; } -%} - +%} + %% /* */ /* top: json -> value is also possible */ -json : value J_EOF { _PARSE_DEBUG("json->value"); YYACCEPT; } +json : value J_EOF { _PARSE_DEBUG("json->value"); YYACCEPT; } ; value : J_TRUE { json_current_body(_JY, "true"); _PARSE_DEBUG("value->TRUE");} @@ -296,7 +296,7 @@ objlist : pair { _PARSE_DEBUG("objlist->pair");} | objlist ',' pair { _PARSE_DEBUG("objlist->objlist , pair");} ; -pair : string { json_current_new(_JY, cbuf_get($1));cbuf_free($1); _JY->jy_cbuf_str = NULL;} ':' +pair : string { json_current_new(_JY, cbuf_get($1));cbuf_free($1); _JY->jy_cbuf_str = NULL;} ':' value { json_current_pop(_JY);}{ _PARSE_DEBUG("pair->string : value");} ; @@ -325,7 +325,7 @@ ustring : ustring J_STRING _JY->jy_cbuf_str = cb; cbuf_append_str(cb,$1); $$=cb; - } + } ; number : J_NUMBER { $$ = $1; } diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c index 9b860512..8d8538d3 100644 --- a/lib/src/clixon_log.c +++ b/lib/src/clixon_log.c @@ -80,7 +80,7 @@ static int _clixon_log_trunc = 0; * * 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 clicon_debug too + * Applies to clicon_err() and clixon_debug too * * @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)). @@ -92,15 +92,15 @@ static int _clixon_log_trunc = 0; * @endcode */ int -clicon_log_init(char *ident, - int upto, - int flags) +clicon_log_init(char *ident, + int upto, + int flags) { _logflags = flags; if (flags & CLICON_LOG_SYSLOG){ if (setlogmask(LOG_UPTO(upto)) < 0) /* Cant syslog here */ - fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno)); + 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 */ } return 0; @@ -116,9 +116,10 @@ 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 -1 No match * @retval 0 One of CLICON_LOG_SYSLOG|STDERR|STDOUT|FILE + * @retval -1 No match */ int clicon_log_opt(char c) @@ -143,15 +144,16 @@ clicon_log_opt(char c) break; default: break; - } + } return logdst; } /*! If log flags include CLICON_LOG_FILE, set the file + * * @param[in] filename File to log to * @retval 0 OK * @retval -1 Error - * @see clicon_debug_init where a strean + * @see clixon_debug_init where a strean */ int clicon_log_file(char *filename) @@ -198,7 +200,7 @@ flogtime(FILE *f) gettimeofday(&tv, NULL); localtime_r((time_t*)&tv.tv_sec, &tm); - fprintf(f, "%s %2d %02d:%02d:%02d: ", + fprintf(f, "%s %2d %02d:%02d:%02d: ", mon2name(tm.tm_mon), tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); return 0; @@ -223,7 +225,7 @@ slogtime(void) } gettimeofday(&tv, NULL); tm = localtime((time_t*)&tv.tv_sec); - snprintf(str, 18, "%s %2d %02d:%02d:%02d: ", + snprintf(str, 18, "%s %2d %02d:%02d:%02d: ", mon2name(tm->tm_mon), tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return str; @@ -236,11 +238,11 @@ slogtime(void) * @param[in] msg Message to print as argv. * This is the _only_ place the actual syslog (or stderr) logging is made in clicon,.. * @note syslog makes its own filtering, but if log to stderr we do it here - * @see clicon_debug + * @see clixon_debug */ int -clicon_log_str(int level, - char *msg) +clicon_log_str(int level, + char *msg) { if (_logflags & CLICON_LOG_SYSLOG) syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg); // XXX this may block @@ -262,7 +264,7 @@ clicon_log_str(int level, fprintf(_logfile, "%s\n", msg); fflush(_logfile); } - /* Enable this if you want syslog in a stream. But there are problems with + /* Enable this if you want syslog in a stream. But there are problems with * recursion */ done: @@ -271,9 +273,11 @@ 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. + * @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__); * @endcode @@ -281,13 +285,13 @@ clicon_log_str(int level, * @see clicon_log_xml */ int -clicon_log(int level, +clicon_log(int level, const char *format, ...) { + int retval = -1; va_list args; size_t len; char *msg = NULL; - int retval = -1; size_t trunc; /* first round: compute length of debug message */ @@ -325,9 +329,9 @@ clicon_log(int level, /*! Initialize debug messages. Set debug level. * - * Initialize debug module. The level is used together with clicon_debug(dbglevel) calls as follows: + * Initialize debug module. The level is used together with clixon_debug(dbglevel) calls as follows: * print message if level >= dbglevel. - * Example: clicon_debug_init(1) -> debug(1) is printed, but not debug(2). + * 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 @@ -341,11 +345,11 @@ clicon_log(int level, * @see clicon_log_file where a filename can be given */ int -clicon_debug_init(int dbglevel, +clixon_debug_init(int dbglevel, FILE *f) { _clixon_debug = dbglevel; /* Global variable */ - + if (f != NULL){ if (_logfile) fclose(_logfile); @@ -355,7 +359,7 @@ clicon_debug_init(int dbglevel, } int -clicon_debug_get(void) +clixon_debug_get(void) { return _clixon_debug; } @@ -363,27 +367,29 @@ clicon_debug_get(void) /*! 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 - * clicon_debug_init(level). That is, only print debug messages <= than what you want: + * 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. - * @see clicon_debug_xml Specialization for XML tree + * @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 -clicon_debug(int dbglevel, +clixon_debug(int dbglevel, const char *format, ...) { + int retval = -1; va_list args; size_t len; char *msg = NULL; - int retval = -1; size_t trunc; - + /* Mask debug level with global dbg variable */ - if ((dbglevel & clicon_debug_get()) == 0) + if ((dbglevel & clixon_debug_get()) == 0) return 0; /* first round: compute length of debug message */ va_start(args, format); @@ -393,7 +399,6 @@ clicon_debug(int dbglevel, /* 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"); @@ -416,6 +421,7 @@ clicon_debug(int dbglevel, } /*! Translate month number (0..11) to a three letter month name + * * @param[in] md month number, where 0 is january */ char * diff --git a/lib/src/clixon_nacm.c b/lib/src/clixon_nacm.c index 4abf8e06..9ac8b6f4 100644 --- a/lib/src/clixon_nacm.c +++ b/lib/src/clixon_nacm.c @@ -79,13 +79,14 @@ #define NACM_NS "urn:ietf:params:xml:ns:yang:ietf-netconf-acm" /*! Match nacm access operations according to RFC8341 3.4.4. + * * Incoming RPC Message Validation Step 7 (c) * The rule's "access-operations" leaf has the "exec" bit set or * has the special value "*". * @param[in] mode Primary mode, eg read, create, update, delete, exec * @param[in] mode2 Secondary mode, eg "write" - * @retval 0 No match - * @retval 1 Match + * @retval 1 Match + * @retval 0 No match * @note access_operations is bit-fields */ static int @@ -105,14 +106,15 @@ match_access(char *access_operations, } /*! Match nacm single rule. Either match with access or deny. Or not match. + * * @param[in] rpc rpc name * @param[in] module Yang module name * @param[in] xrule NACM rule XML tree * @param[out] cbret Cligen buffer result. Set to an error msg if retval=0. - * @retval -1 Error - * @retval 0 Matching rule AND Not access and cbret set - * @retval 1 Matching rule AND Access - * @retval 2 No matching rule Goto step 10 + * @retval 2 No matching rule Goto step 10 + * @retval 1 Matching rule AND Access + * @retval 0 Matching rule AND Not access and cbret set + * @retval -1 Error * @see RFC8341 3.4.4. Incoming RPC Message Validation 7.(cont) A rule matches if all of the following criteria are met: * The rule's "module-name" leaf is "*" or equals the name of @@ -135,7 +137,7 @@ nacm_rule_rpc(char *rpc, char *module_rule; /* rule module name */ char *rpc_rule; char *access_operations; - + /* 7a) The rule's "module-name" leaf is "*" or equals the name of the YANG module where the protocol operation is defined. */ if ((module_rule = xml_find_body(xrule, "module-name")) == NULL) @@ -166,14 +168,15 @@ nacm_rule_rpc(char *rpc, } /*! Process nacm incoming RPC message validation steps + * * @param[in] module Yang module name * @param[in] rpc rpc name * @param[in] username User name of requestor * @param[in] xnacm NACM xml tree - * @param[out] cbret Cligen buffer result. Set to an error msg if retval=0. - * @retval -1 Error - * @retval 0 Not access and cbret set - * @retval 1 Access + * @param[out] cbret Cligen buffer result. Set to an error msg if retval=0. + * @retval 1 Access + * @retval 0 Not access and cbret set + * @retval -1 Error * @see RFC8341 3.4.4. Incoming RPC Message Validation * @see nacm_datanode_write * @see nacm_datanode_read @@ -200,7 +203,7 @@ nacm_rpc(char *rpc, char *action; int match= 0; cvec *nsc = NULL; - + /* Create namespace context for with nacm namespace as default */ if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL) goto done; @@ -241,7 +244,7 @@ nacm_rpc(char *rpc, continue; /* 7. For each rule-list entry found, process all rules, in order, until a rule that matches the requested access operation is - found. + found. */ if (xpath_vec(rlist, nsc, "rule", &rvec, &rlen) < 0) goto done; @@ -295,7 +298,7 @@ nacm_rpc(char *rpc, permit: retval = 1; done: - clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval); if (nsc) xml_nsctx_free(nsc); if (gvec) @@ -354,11 +357,15 @@ prepvec_add(prepvec **pv_listp, } /*! Prepare datastructures before running through XML tree + * * Save rules in a "cache" * These rules match: * - user/group * - have read access-op, etc * Also make instance-id lookups on top object for each rule. Assume at most one result + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error */ static int nacm_datanode_prepare(clicon_handle h, @@ -378,7 +385,7 @@ nacm_datanode_prepare(clicon_handle h, int k; char *gname; cxobj **rvec = NULL; /* rules */ - size_t rlen; + size_t rlen; cxobj *xrule; cxobj *pathobj; char *access_operations; @@ -414,14 +421,14 @@ nacm_datanode_prepare(clicon_handle h, leaf has the "read" bit set or has the special value "*" */ access_operations = xml_find_body(xrule, "access-operations"); switch (access){ - case NACM_READ: + case NACM_READ: /* 6c) For a "read" access operation, the rule's "access-operations" leaf has the "read" bit set or has the special value "*" */ if (!match_access(access_operations, "read", NULL)) continue; break; case NACM_CREATE: - /* 6d) For a "create" access operation, the rule's "access-operations" + /* 6d) For a "create" access operation, the rule's "access-operations" leaf has the "create" bit set or has the special value "*". */ if (!match_access(access_operations, "create", "write")) continue; @@ -499,7 +506,7 @@ nacm_datanode_prepare(clicon_handle h, if (rvec){ free(rvec); rvec=NULL; - } + } } retval = 0; done: @@ -517,14 +524,15 @@ nacm_datanode_prepare(clicon_handle h, */ /*! Match specific rule to specific requested node + * * @param[in] xn XML node (requested node) * @param[in] xrule NACM rule * @param[in] xp Xpath match * @param[in] yspec YANG spec - * @retval -1 Error - * @retval 0 OK and rule does not match - * @retval 1 OK and rule matches deny * @retval 2 OK and rule matches permit + * @retval 1 OK and rule matches deny + * @retval 0 OK and rule does not match + * @retval -1 Error */ static int nacm_data_write_xrule_xml(cxobj *xn, @@ -583,7 +591,8 @@ nacm_data_write_xrule_xml(cxobj *xn, } /*! Recursive check for NACM write rules among all XML nodes - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xn XML node (requested node) * @param[in] rulevec Precomputed rules that apply to this user group * @param[in] xpathvec Precomputed xpath results that apply to this XML tree @@ -592,7 +601,7 @@ nacm_data_write_xrule_xml(cxobj *xn, * @param[out] cbret Error message if retval = 0 * @retval 1 OK and accept * @retval 0 Deny and cbret set - * @retval -1 Error + * @retval -1 Error * XXX differentiate between nomatch: default. or match deny, match accept * nomatch: check write-default rules, next v * accept: Hunky dory @@ -610,13 +619,13 @@ nacm_datanode_write_recurse(clicon_handle h, cxobj *x; int ret = 0; prepvec *pv; - + pv = pv_list; if (pv){ do { /* return values: -1:Error /0:no match /1: deny /2: permit */ - if ((ret = nacm_data_write_xrule_xml(xn, pv->pv_xrule, pv->pv_xpathvec, yspec)) < 0) + if ((ret = nacm_data_write_xrule_xml(xn, pv->pv_xrule, pv->pv_xpathvec, yspec)) < 0) goto done; switch(ret){ case 0: /* No match, continue with next rule */ @@ -658,6 +667,7 @@ nacm_datanode_write_recurse(clicon_handle h, } /*! Make nacm datanode and module rule write access validation + * * The operations of NACM are: create, read, update, delete, exec * where write is short-hand for create+delete+update * @param[in] h Clixon handle @@ -666,10 +676,10 @@ nacm_datanode_write_recurse(clicon_handle h, * @param[in] op NACM access of xreq * @param[in] username User making access * @param[in] xnacm NACM xml tree - * @param[out] cbret Cligen buffer result. Set to an error msg if retval=0. - * @retval -1 Error - * @retval 0 Not access and cbret set - * @retval 1 Access + * @param[out] cbret Cligen buffer result. Set to an error msg if retval=0. + * @retval 1 Access + * @retval 0 Not access and cbret set + * @retval -1 Error * @see RFC8341 3.4.5. Data Node Access Validation * @see nacm_datanode_read * @see nacm_rpc @@ -738,7 +748,7 @@ nacm_datanode_write(clicon_handle h, goto permit; /* 8. At this point, no matching rule was found in any rule-list entry. */ - step9: + step9: /* 10. For a "write" access operation, if the requested data node is defined in a YANG module advertised in the server capabilities and the data definition statement contains a @@ -759,7 +769,7 @@ nacm_datanode_write(clicon_handle h, permit: retval = 1; done: - clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval); if (pv_list) prepvec_free(pv_list); if (nsc) @@ -782,10 +792,12 @@ nacm_datanode_write(clicon_handle h, */ /*! Perform NACM action: mark if permit, del if deny + * * @param[in] xrule NACM rule * @param[in] xn XML node (requested node) - * @retval -1 Error * @retval 0 OK + * @retval -1 Error + */ static int nacm_data_read_action(cxobj *xrule, @@ -806,12 +818,13 @@ nacm_data_read_action(cxobj *xrule, } /*! Match specific rule to specific requested node + * * @param[in] xn XML node (requested node) * @param[in] xrule NACM rule * @param[in] yspec YANG spec - * @retval -1 Error - * @retval 0 OK and rule does not match - * @retval 1 OK and rule matches + * @retval 1 OK and rule matches + * @retval 0 OK and rule does not match + * @retval -1 Error * Two distinct cases: * (1) read_default is permit * mark all deny rules and remove them @@ -829,7 +842,7 @@ nacm_data_read_xrule_xml(cxobj *xn, char *module_pattern; /* rule module name */ cxobj *xp; int i; - + if ((module_pattern = xml_find_body(xrule, "module-name")) == NULL) goto nomatch; /* 6a) The rule's "module-name" leaf is "*" or equals the name of @@ -868,13 +881,14 @@ nacm_data_read_xrule_xml(cxobj *xn, } /*! Recursive check for NACM read rules among all XML nodes - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xn XML node (requested node) * @param[in] rulevec Precomputed rules that apply to this user group * @param[in] xpathvec Precomputed xpath results that apply to this XML tree * @param[in] yspec YANG spec - * @retval 0 OK - * @retval -1 Error + * @retval 0 OK + * @retval -1 Error */ static int nacm_datanode_read_recurse(clicon_handle h, @@ -887,7 +901,7 @@ nacm_datanode_read_recurse(clicon_handle h, cxobj *xprev; int ret; prepvec *pv; - + if (xml_spec(xn)){ /* Check this node */ pv = pv_list; if (pv){ @@ -895,15 +909,15 @@ nacm_datanode_read_recurse(clicon_handle h, if ((ret = nacm_data_read_xrule_xml(xn, pv->pv_xrule, pv->pv_xpathvec, - yspec)) < 0) - goto done; + yspec)) < 0) + goto done; if (ret == 1) - break; /* stop at first match */ + break; /* stop at first match */ pv = NEXTQ(prepvec *, pv); } while (pv && pv != pv_list); } -#if 0 /* 6(A) in algorithm +#if 0 /* 6(A) in algorithm * If N did not match any rule R, and default rule is deny, remove that subtree */ if (strcmp(read_default, "deny") == 0) if (xml_tree_prune_flagged_sub(xt, XML_FLAG_MARK, 1, NULL) < 0) @@ -932,16 +946,17 @@ nacm_datanode_read_recurse(clicon_handle h, } /*! Make nacm datanode and module rule read access validation + * * Just purge nodes that fail validation (dont send netconf error message) - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xt XML root tree with "config" label * @param[in] xrvec Vector of requested nodes (sub-part of xt) * @param[in] xrlen Length of requsted node vector * @param[in] username * @param[in] xnacm NACM xml tree - * @retval -1 Error - * @retval 0 Not access and cbret set - * @retval 1 Access + * @retval 1 Access + * @retval 0 Not access and cbret set + * @retval -1 Error * 3.2.4: and Operations * Data nodes to which the client does not have read access are silently * omitted, along with any descendants, from the message. @@ -983,7 +998,7 @@ int nacm_datanode_read(clicon_handle h, cxobj *xt, cxobj **xrvec, - size_t xrlen, + size_t xrlen, char *username, cxobj *xnacm) { @@ -996,7 +1011,7 @@ nacm_datanode_read(clicon_handle h, char *read_default = NULL; cvec *nsc = NULL; prepvec *pv_list = NULL; - + /* Create namespace context for with nacm namespace as default */ if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL) goto done; @@ -1059,7 +1074,7 @@ nacm_datanode_read(clicon_handle h, ok: retval = 0; done: - clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); if (pv_list) prepvec_free(pv_list); if (nsc) @@ -1077,15 +1092,16 @@ nacm_datanode_read(clicon_handle h, */ /*! NACM intial pre- access control enforcements + * * Initial NACM steps and common to all NACM access validation. * If retval=0 continue with next NACM step, eg rpc, module, * etc. If retval = 1 access is OK and skip next NACM step. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xnacm NACM XML tree, root should be "nacm" * @param[in] username User name of requestor - * @retval -1 Error - * @retval 0 OK but not validated. Need to do NACM step using xnacm - * @retval 1 OK permitted. You do not need to do next NACM step + * @retval 1 OK permitted. You do not need to do next NACM step + * @retval 0 OK but not validated. Need to do NACM step using xnacm + * @retval -1 Error * @code * if ((ret = nacm_access_check(h, mode, xnacm, peername, username)) < 0) * err; @@ -1109,9 +1125,9 @@ nacm_access_check(clicon_handle h, char *recovery_user; #ifdef WITH_RESTCONF char *wwwuser; -#endif +#endif - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL) goto done; /* Do initial nacm processing common to all access validation in @@ -1164,23 +1180,24 @@ nacm_access_check(clicon_handle h, done: if (nsc) xml_nsctx_free(nsc); - clicon_debug(1, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d (0:deny 1:permit)", __FUNCTION__, retval); return retval; permit: retval = 1; goto done; } -/*! NACM intial pre- access control enforcements +/*! NACM intial pre- access control enforcements + * * Initial NACM steps and common to all NACM access validation. * If retval=0 continue with next NACM step, eg rpc, module, * etc. If retval = 1 access is OK and skip next NACM step. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] username User name of requestor * @param[out] xncam NACM XML tree, set if retval=0. Free after use - * @retval -1 Error - * @retval 0 OK but not validated. Need to do NACM step using xnacm - * @retval 1 OK permitted. You do not need to do next NACM step. + * @retval 1 OK permitted. You do not need to do next NACM step. + * @retval 0 OK but not validated. Need to do NACM step using xnacm + * @retval -1 Error * @code * cxobj *xnacm = NULL; * if ((ret = nacm_access_pre(h, peername, username, &xnacm)) < 0) @@ -1204,7 +1221,7 @@ nacm_access_pre(clicon_handle h, cxobj *xnacm0 = NULL; cxobj *xnacm = NULL; cvec *nsc = NULL; - + /* Check clixon option: disabled, external tree or internal */ mode = clicon_option_str(h, "CLICON_NACM_MODE"); if (mode == NULL) @@ -1224,7 +1241,6 @@ nacm_access_pre(clicon_handle h, clicon_err(OE_XML, 0, "Invalid NACM mode: %s", mode); goto done; } - if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL) goto done; /* If config does not exist then the operation is permitted(?) */ @@ -1263,9 +1279,9 @@ nacm_access_pre(clicon_handle h, * @param[in] peername Peer username if any * @param[in] username username received in XML (eg for NACM) * @param[out] cbret Set with netconf error message if ret == 0 - * @retval -1 Error - * @retval 0 Not verified (cbret set) * @retval 1 Verified + * @retval 0 Not verified (cbret set) + * @retval -1 Error * Credentials OK if * - cred mode is NONE, * Otherwise both NACM user AND peer user must exist, and @@ -1287,7 +1303,7 @@ verify_nacm_user(clicon_handle h, cbuf *cbmsg = NULL; #ifdef WITH_RESTCONF char *wwwuser; -#endif +#endif if (cred == NC_NONE) return 1; @@ -1300,7 +1316,7 @@ verify_nacm_user(clicon_handle h, if (netconf_access_denied(cbret, "application", "No NACM available") < 0) goto done; goto fail; - } + } if (cred == NC_EXCEPT){ if (strcmp(peername, "root") == 0) goto ok; diff --git a/lib/src/clixon_netconf_input.c b/lib/src/clixon_netconf_input.c index 4163ed4e..60f1a61c 100644 --- a/lib/src/clixon_netconf_input.c +++ b/lib/src/clixon_netconf_input.c @@ -92,7 +92,7 @@ netconf_input_read2(int s, { int retval = -1; ssize_t len; - + memset(buf, 0, buflen); if ((len = read(s, buf, buflen)) < 0){ if (errno == ECONNRESET) @@ -102,14 +102,14 @@ netconf_input_read2(int s, goto done; } } /* read */ - clicon_debug(CLIXON_DBG_DETAIL, "%s len:%ld", __FUNCTION__, len); + clixon_debug(CLIXON_DBG_DETAIL, "%s len:%ld", __FUNCTION__, len); if (len == 0){ /* EOF */ - clicon_debug(CLIXON_DBG_DETAIL, "%s len==0, closing", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s len==0, closing", __FUNCTION__); *eof = 1; } retval = len; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); return retval; } @@ -146,7 +146,7 @@ netconf_input_msg2(unsigned char **bufp, size_t len; char ch; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); len = *lenp; for (i=0; i * @param[in,out] cberr Translation from netconf err to cbuf. * @retval 0 OK, with cberr set @@ -1830,9 +1905,12 @@ netconf_capabilites(clicon_handle h, } /*! Create Netconf server hello. Single cap and defer individual to querying modules - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cb Msg buffer * @param[in] session_id Id of client session + * @retval 0 OK + * @retval -1 Error * Lots of dependencies here. regarding the hello protocol. * RFC6241 NETCONF Protocol says: (8.1) * MUST send a element containing a list of that peer's capabilities @@ -1880,6 +1958,8 @@ netconf_hello_server(clicon_handle h, * @param[in] xerr Netconf error xml tree on the form: * @param[in] format Format string * @param[in] arg String argument to format (optional) + * @retval 0 OK + * @retval -1 Error * @see netconf_err2cb */ int @@ -1928,7 +2008,7 @@ clixon_netconf_error_fn(const char *fn, * @param[in] msg Error message * @param[in] arg Extra error message (consider stdarg?) * @retval 0 OK - * @retval -1 Error + * @retval -1 Error */ int clixon_netconf_internal_error(cxobj *xerr, @@ -2022,6 +2102,7 @@ netconf_parse_uint32(char *name, } /*! Parse string into uint32 and return netconf bad-element msg on error xml variant + * * @see netconf_parse_uint32_xml */ int @@ -2089,7 +2170,9 @@ netconf_message_id_next(clicon_handle h) /*! Add netconf xml postamble of message. I.e, xml after the body of the message. * * @param[in] framing Netconf framing - * @param[in,out] cb Netconf packet (cligen buffer) + * @param[in,out] cb Netconf packet (cligen buffer) + * @retval 0 OK + * @retval -1 Error * XXX: copies body */ int @@ -2140,6 +2223,7 @@ netconf_framing_postamble(netconf_framing_type framing, } /*! Send netconf message from cbuf on socket + * * @param[in] s * @param[in] cb Cligen buffer that contains the XML message * @param[in] msg Only for debug @@ -2156,7 +2240,7 @@ netconf_output(int s, char *buf = cbuf_get(cb); int len = cbuf_len(cb); - clicon_debug(CLIXON_DBG_MSG, "Send ext: %s", cbuf_get(cb)); + clixon_debug(CLIXON_DBG_MSG, "Send ext: %s", cbuf_get(cb)); #if 0 // Extra sanity check for debugging { cxobj *xt = NULL; @@ -2170,7 +2254,7 @@ netconf_output(int s, #endif if (write(s, buf, len) < 0){ if (errno == EPIPE) - clicon_debug(1, "%s write err SIGPIPE", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s write err SIGPIPE", __FUNCTION__); else clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno)); goto done; @@ -2252,7 +2336,7 @@ netconf_input_chunked_framing(char ch, { int retval = 0; - clicon_debug(CLIXON_DBG_DETAIL, "%s ch:%c(%d) state:%d size:%zu", __FUNCTION__, ch, ch, *state, *size); + clixon_debug(CLIXON_DBG_DETAIL, "%s ch:%c(%d) state:%d size:%zu", __FUNCTION__, ch, ch, *state, *size); switch (*state){ case 0: if (ch == '\n'){ @@ -2290,7 +2374,7 @@ netconf_input_chunked_framing(char ch, *size = (*size)*10 + ch-'0'; break; } - else if (ch == '\n'){ + else if (ch == '\n'){ (*state)++; break; } diff --git a/lib/src/clixon_netconf_monitoring.c b/lib/src/clixon_netconf_monitoring.c index aa22aabc..f109ad74 100644 --- a/lib/src/clixon_netconf_monitoring.c +++ b/lib/src/clixon_netconf_monitoring.c @@ -99,7 +99,7 @@ per_datastore(clicon_handle h, /*! Get netconf monitoring datastore state * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in,out] cb CLIgen buffer * @retval 0 OK @@ -130,7 +130,7 @@ netconf_monitoring_datastores(clicon_handle h, /*! Get netconf monitoring schema state * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in,out] cb CLIgen buffer * @retval 0 OK @@ -181,7 +181,7 @@ netconf_monitoring_schemas(clicon_handle h, /*! Get netconf monitoring statistics state * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in,out] cb CLIgen buffer * @retval 0 OK @@ -197,7 +197,7 @@ netconf_monitoring_statistics(clicon_handle h, char *str; cvec *cvv = NULL; cg_var *cv; - + cprintf(cb, ""); if (clicon_data_get(h, "netconf-start-time", &str) == 0 && str != NULL){ @@ -230,7 +230,7 @@ netconf_monitoring_statistics(clicon_handle h, * * Netconf monitoring state is: * capabilities, datastores, schemas, sessions, statistics - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in] xpath XML Xpath * @param[in] nsc XML Namespace context for xpath @@ -253,7 +253,7 @@ netconf_monitoring_state_get(clicon_handle h, int retval = -1; cbuf *cb = NULL; int ret; - + if ((cb = cbuf_new()) ==NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; @@ -276,7 +276,7 @@ netconf_monitoring_state_get(clicon_handle h, } retval = 1; done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); if (cb) cbuf_free(cb); return retval; @@ -289,6 +289,8 @@ netconf_monitoring_state_get(clicon_handle h, * * @param[in] cvv Cligen vector * @param[in] name Name of new counter + * @retval 0 OK + * @retval -1 Error */ static int stat_counter_add(cvec *cvv, @@ -310,7 +312,9 @@ stat_counter_add(cvec *cvv, /*! Init RFC6022 stats * - * @param[in] h Clicon handle + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error */ int netconf_monitoring_statistics_init(clicon_handle h) @@ -353,12 +357,12 @@ netconf_monitoring_statistics_init(clicon_handle h) * * @param[in] h Clixon handle * @param[in] name Name of counter + * @retval 0 OK */ int netconf_monitoring_counter_inc(clicon_handle h, char *name) { - int retval = -1; cvec *cvv = NULL; cg_var *cv; uint32_t u32; @@ -370,6 +374,5 @@ netconf_monitoring_counter_inc(clicon_handle h, cv_uint32_set(cv, u32); } } - retval = 0; - return retval; + return 0; } diff --git a/lib/src/clixon_netns.c b/lib/src/clixon_netns.c index 7329e5f9..66278e26 100644 --- a/lib/src/clixon_netns.c +++ b/lib/src/clixon_netns.c @@ -109,16 +109,19 @@ get_sock(int usock, #endif /* HAVE_SETNS */ /*! Create and bind stream socket + * * @param[in] sa Socketaddress * @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len * @param[in] backlog Listen backlog, queie of pending connections * @param[in] flags Socket flags Or:ed in with the socket(2) type parameter * @param[in] addrstr Address string for debug * @param[out] sock Server socket (bound for accept) + * @retval 0 OK + * @retval -1 Error */ static int create_socket(struct sockaddr *sa, - size_t sin_len, + size_t sin_len, int backlog, int flags, const char *addrstr, @@ -127,8 +130,8 @@ create_socket(struct sockaddr *sa, int retval = -1; int s = -1; int on = 1; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (sock == NULL){ clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter"); goto done; @@ -182,7 +185,7 @@ create_socket(struct sockaddr *sa, *sock = s; retval = 0; done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); if (retval != 0 && s != -1) close(s); return retval; @@ -198,11 +201,13 @@ create_socket(struct sockaddr *sa, * @param[in] flags Socket flags OR:ed in with the socket(2) type parameter * @param[in] addrstr Address string for debug * @param[out] sock Server socket (bound for accept) + * @retval 0 OK + * @retval -1 Error */ static int fork_netns_socket(const char *netns, struct sockaddr *sa, - size_t sin_len, + size_t sin_len, int backlog, int flags, const char *addrstr, @@ -221,7 +226,7 @@ fork_netns_socket(const char *netns, int sock_flags = SOCK_DGRAM | SOCK_CLOEXEC; #endif - clicon_debug(1, "%s %s", __FUNCTION__, 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"); goto done; @@ -240,7 +245,7 @@ fork_netns_socket(const char *netns, #endif /* Check namespace exists */ - sprintf(nspath,"/var/run/netns/%s", netns); + sprintf(nspath,"/var/run/netns/%s", netns); if (stat(nspath, &st) < 0){ clicon_err(OE_UNIX, errno, ": stat(%s)", nspath); goto done; @@ -288,19 +293,20 @@ fork_netns_socket(const char *netns, if(waitpid(child, &wstatus, 0) == child) ; // retval = WEXITSTATUS(status); /* Dont know what to do with status */ if (WEXITSTATUS(wstatus)){ - clicon_debug(1, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus)); *sock = -1; clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr); goto done; } retval = 0; done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); return retval; } #endif /* HAVE_SETNS */ /*! Create and bind stream socket in network namespace + * * @param[in] netns Network namespace * @param[in] sa Socketaddress * @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len @@ -308,19 +314,21 @@ fork_netns_socket(const char *netns, * @param[in] flags Socket flags OR:ed in with the socket(2) type parameter * @param[in] addrstr Address string for debug * @param[out] sock Server socket (bound for accept) + * @retval 0 OK + * @retval -1 Error */ int clixon_netns_socket(const char *netns, struct sockaddr *sa, - size_t sin_len, + size_t sin_len, int backlog, int flags, const char *addrstr, int *sock) { int retval = -1; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (netns == NULL){ if (create_socket(sa, sin_len, backlog, flags, addrstr, sock) < 0) goto done; @@ -332,12 +340,12 @@ clixon_netns_socket(const char *netns, goto done; #else clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns); - return -1; + return -1; #endif } ok: retval = 0; done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); return retval; } diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index e2b8a719..a8344e7f 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -89,29 +89,29 @@ /* Mapping between Clicon startup modes string <--> constants, see clixon-config.yang type startup_mode */ static const map_str2int startup_mode_map[] = { - {"none", SM_NONE}, - {"init", SM_INIT}, - {"running", SM_RUNNING}, + {"none", SM_NONE}, + {"init", SM_INIT}, + {"running", SM_RUNNING}, {"startup", SM_STARTUP}, - {"running-startup", SM_RUNNING_STARTUP}, + {"running-startup", SM_RUNNING_STARTUP}, {NULL, -1} }; /* Mapping between Clicon privileges modes string <--> constants, * see clixon-config.yang type priv_mode */ static const map_str2int priv_mode_map[] = { - {"none", PM_NONE}, - {"drop_perm", PM_DROP_PERM}, - {"drop_temp", PM_DROP_TEMP}, + {"none", PM_NONE}, + {"drop_perm", PM_DROP_PERM}, + {"drop_temp", PM_DROP_TEMP}, {NULL, -1} }; /* Mapping between Clicon nacm user credential string <--> constants, * see clixon-config.yang type nacm_cred_mode */ static const map_str2int nacm_credentials_map[] = { - {"none", NC_NONE}, - {"exact", NC_EXACT}, - {"except", NC_EXCEPT}, + {"none", NC_NONE}, + {"exact", NC_EXACT}, + {"except", NC_EXCEPT}, {NULL, -1} }; @@ -132,10 +132,9 @@ static const map_str2int yang_regexp_map[] = { {NULL, -1} }; - /*! Debug dump config options * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] dbglevel Debug level * @retval 0 OK * @retval -1 Error @@ -145,7 +144,7 @@ static const map_str2int yang_regexp_map[] = { * @see cli_show_options */ int -clicon_option_dump(clicon_handle h, +clicon_option_dump(clicon_handle h, int dbglevel) { int retval = -1; @@ -156,19 +155,19 @@ clicon_option_dump(clicon_handle h, size_t klen; size_t vlen; cxobj *x = NULL; - + if (clicon_hash_keys(hash, &keys, &klen) < 0) goto done; for(i = 0; i < klen; i++) { val = clicon_hash_value(hash, keys[i], &vlen); if (vlen){ if (((char*)val)[vlen-1]=='\0') /* assume string */ - clicon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val); + clixon_debug(dbglevel, "%s =\t \"%s\"", keys[i], (char*)val); else - clicon_debug(dbglevel, "%s =\t 0x%p , length %zu", keys[i], val, vlen); + clixon_debug(dbglevel, "%s =\t 0x%p , length %zu", keys[i], val, vlen); } else - clicon_debug(dbglevel, "%s = NULL", keys[i]); + clixon_debug(dbglevel, "%s = NULL", keys[i]); } /* Next print CLICON_FEATURE, CLICON_YANG_DIR and CLICON_SNMP_DIR from config tree * Since they are lists they are placed in the config tree. @@ -177,19 +176,19 @@ clicon_option_dump(clicon_handle h, while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) { if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0) continue; - clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x)); + clixon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x)); } x = NULL; while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) { if (strcmp(xml_name(x), "CLICON_FEATURE") != 0) continue; - clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x)); + clixon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x)); } x = NULL; while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) { if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0) continue; - clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x)); + clixon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x)); } retval = 0; done: @@ -200,7 +199,7 @@ clicon_option_dump(clicon_handle h, /*! Dump config options on stdio using output format * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] f Output file * @param[in] format Dump output format * @param[in] pretty Set if pretty-print xml and json @@ -209,7 +208,7 @@ clicon_option_dump(clicon_handle h, * @see clicon_option_dump for debug log */ int -clicon_option_dump1(clicon_handle h, +clicon_option_dump1(clicon_handle h, FILE *f, int format, int pretty) @@ -245,7 +244,9 @@ clicon_option_dump1(clicon_handle h, * * @param[in] filename * @param[in] yspec - * @param[out] xconfig Pointer to xml config tree. Should be freed by caller + * @param[out] xconfig Pointer to xml config tree. Should be freed by caller + * @retval 0 OK + * @retval -1 Error */ static int parse_configfile_one(const char *filename, @@ -264,7 +265,7 @@ parse_configfile_one(const char *filename, clicon_err(OE_UNIX, errno, "open configure file: %s", filename); return -1; } - clicon_debug(CLIXON_DBG_DETAIL, "%s: Reading config file %s", __FUNCTION__, filename); + 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){ @@ -296,7 +297,7 @@ parse_configfile_one(const char *filename, xt = NULL; retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s: Done w/ config file %s returning %d", __FUNCTION__, filename, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s: Done w/ config file %s returning %d", __FUNCTION__, filename, retval); if (xt) xml_free(xt); if (fp) @@ -383,7 +384,7 @@ merge_control_xml(clicon_handle h, static int parse_configfile(clicon_handle h, const char *filename, - char *extraconfdir0, + char *extraconfdir0, yang_stmt *yspec, cxobj **xconfig) { @@ -421,7 +422,7 @@ parse_configfile(clicon_handle h, goto done; } - clicon_debug(CLIXON_DBG_DETAIL, "%s: Reading config file %s", __FUNCTION__, filename); + clixon_debug(CLIXON_DBG_DETAIL, "%s: Reading config file %s", __FUNCTION__, filename); /* Parse main config file */ if (parse_configfile_one(filename, yspec, &xt) < 0) goto done; @@ -441,7 +442,7 @@ parse_configfile(clicon_handle h, if((ndp = clicon_file_dirent(extraconfdir, &dp, NULL, S_IFREG)) < 0) /* Read dir */ goto done; /* Loop through files */ - for (i = 0; i < ndp; i++){ + for (i = 0; i < ndp; i++){ snprintf(filename1, sizeof(filename1), "%s/%s", extraconfdir, dp[i].d_name); if (parse_configfile_one(filename1, yspec, &xe) < 0) goto done; @@ -465,7 +466,7 @@ parse_configfile(clicon_handle h, } } if (xml_default_recurse(xt, 0) < 0) - goto done; + goto done; if ((ret = xml_yang_validate_add(h, xt, &xerr)) < 0) goto done; if (ret == 0){ @@ -478,7 +479,7 @@ parse_configfile(clicon_handle h, clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret)); goto done; } - /* Add top-level hash options. + /* Add top-level hash options. * Hashed options are historical and could be replaced with xml, see eg clicon_option_str */ x = NULL; @@ -500,7 +501,7 @@ parse_configfile(clicon_handle h, continue; if (strcmp(name,"CLICON_SNMP_MIB")==0) continue; - if (clicon_hash_add(copt, + if (clicon_hash_add(copt, name, body, strlen(body)+1) == NULL) @@ -511,7 +512,7 @@ parse_configfile(clicon_handle h, *xconfig = xt; xt = NULL; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s: Done w/ config file %s returning %d", __FUNCTION__, filename, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s: Done w/ config file %s returning %d", __FUNCTION__, filename, retval); if (dp) free(dp); if (nsc) @@ -529,7 +530,7 @@ parse_configfile(clicon_handle h, * * Add to clicon_options hash, and to clicon_conf_xml tree * Assumes clicon_conf_xml_set has been called - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name Name of configuration option (see clixon-config.yang) * @param[in] value String value * @retval 0 OK @@ -559,7 +560,7 @@ clicon_option_add(clicon_handle h, } else{ /* Add/change hash */ - if (clicon_hash_add(copt, + if (clicon_hash_add(copt, name, value, strlen(value)+1) == NULL) @@ -582,8 +583,10 @@ clicon_option_add(clicon_handle h, * Set default options, Read config-file, Check that all values are set. * Parse clixon yang file and save in yspec. * Read clixon system config files - * @param[in] h clicon handle - * @param[in] yspec Yang spec of clixon config file + * @param[in] h clicon handle + * @param[in] yspec Yang spec of clixon config file + * @retval 0 OK + * @retval -1 Error * @note Due to Bug: Top-level Yang symbol cannot be called "config" in any * imported yang file, the config module needs to be isolated from all * other yang modules. @@ -607,13 +610,13 @@ clicon_options_main(clicon_handle h) /* * Set configure file if not set by command-line above */ - if (!clicon_hash_lookup(copt, "CLICON_CONFIGFILE")){ + if (!clicon_hash_lookup(copt, "CLICON_CONFIGFILE")){ clicon_option_str_set(h, "CLICON_CONFIGFILE", CLIXON_DEFAULT_CONFIG); } configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL); if (strlen(configfile) == 0) configfile = clicon_hash_value(copt, "CLICON_CONFIGFILE", NULL); - clicon_debug(1, "CLICON_CONFIGFILE=%s", configfile); + clixon_debug(CLIXON_DBG_DEFAULT, "CLICON_CONFIGFILE=%s", configfile); /* File must end with .xml */ if ((suffix = rindex(configfile, '.')) != NULL){ suffix++; @@ -623,7 +626,6 @@ clicon_options_main(clicon_handle h) clicon_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){ @@ -641,7 +643,6 @@ clicon_options_main(clicon_handle h) */ if (parse_configfile(h, configfile, extraconfdir, NULL, &xconfig) < 0) goto done; - clicon_conf_xml_set(h, xconfig); #ifdef WITH_RESTCONF_FCGI @@ -660,7 +661,7 @@ clicon_options_main(clicon_handle h) if (clicon_option_str(h, "CLICON_CONFIG_EXTEND") != NULL) yangspec = clicon_option_str(h, "CLICON_CONFIG_EXTEND"); if (yang_spec_parse_module(h, yangspec, NULL, yspec) < 0) - goto done; + goto done; clicon_conf_xml_set(h, NULL); if (xconfig){ xml_free(xconfig); @@ -718,7 +719,7 @@ clicon_option_exists(clicon_handle h, * clicon_option_exists() before the call */ char * -clicon_option_str(clicon_handle h, +clicon_option_str(clicon_handle h, const char *name) { clicon_hash_t *copt = clicon_options(h); @@ -737,8 +738,8 @@ clicon_option_str(clicon_handle h, * @retval -1 Error */ int -clicon_option_str_set(clicon_handle h, - const char *name, +clicon_option_str_set(clicon_handle h, + const char *name, char *val) { clicon_hash_t *copt = clicon_options(h); @@ -751,7 +752,7 @@ clicon_option_str_set(clicon_handle h, * @param[in] h clicon handle * @param[in] name name of option * @retval int An integer as a result of atoi - * @retval -1 If option does not exist + * @retval -1 If option does not exist * @code * if (clicon_option_exists(h, "X")) * return clicon_option_int(h, "X"); @@ -776,7 +777,7 @@ clicon_option_int(clicon_handle h, /*! Set option given as int. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name Name of option to set * @param[in] val Integer value */ @@ -786,7 +787,7 @@ clicon_option_int_set(clicon_handle h, int val) { char s[64]; - + if (snprintf(s, sizeof(s)-1, "%u", val) < 0) return -1; return clicon_option_str_set(h, name, s); @@ -794,10 +795,10 @@ clicon_option_int_set(clicon_handle h, /*! Get options as bool but stored as string * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name name of option - * @retval 0 false, or does not exist, or does not have a boolean value * @retval 1 true + * @retval 0 false, or does not exist, or does not have a boolean value * @code * if (clicon_option_exists(h, "X") * return clicon_option_bool(h, "X"); @@ -825,7 +826,7 @@ clicon_option_bool(clicon_handle h, /*! Set option given as bool * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name Name of option to set * @param[in] val Boolean value, 0 or 1 */ @@ -835,7 +836,7 @@ clicon_option_bool_set(clicon_handle h, int val) { char s[64]; - + if (val != 0 && val != 1){ clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val); return -1; @@ -849,7 +850,7 @@ clicon_option_bool_set(clicon_handle h, /*! Delete option * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name Name of option to delete */ int @@ -874,7 +875,7 @@ clicon_option_del(clicon_handle h, /*! Get "do not include keys in cvec" in cli vars callbacks * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval flag If set, get only vars * @see clixon-config@.yang CLICON_CLI_VARONLY */ @@ -892,7 +893,7 @@ clicon_cli_varonly(clicon_handle h) /*! Get family of backend socket: AF_UNIX, AF_INET or AF_INET6 * * @see clixon-config@.yang CLICON_SOCK_FAMILY - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval fam Socket family */ int @@ -914,7 +915,7 @@ clicon_sock_family(clicon_handle h) /*! Get port for backend socket in case of AF_INET or AF_INET6 * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval port Socket port * @see clixon-config@.yang CLICON_SOCK_PORT */ @@ -930,7 +931,7 @@ clicon_sock_port(clicon_handle h) /*! Set if all configuration changes are committed automatically * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval flag Autocommit (or not) */ int @@ -946,7 +947,7 @@ clicon_autocommit(clicon_handle h) /*! Which method to boot/start clicon backend * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval mode Startup mode */ int @@ -961,7 +962,7 @@ clicon_startup_mode(clicon_handle h) /*! Which privileges drop method to use for backend * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval mode Privileges mode */ enum priv_mode_t @@ -976,7 +977,7 @@ clicon_backend_privileges_mode(clicon_handle h) /*! Which privileges drop method to use for restconf * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval mode Privileges mode */ enum priv_mode_t @@ -991,7 +992,7 @@ clicon_restconf_privileges_mode(clicon_handle h) /*! Which privileges drop method to use * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval mode Privileges mode */ enum nacm_credentials_t @@ -1006,7 +1007,7 @@ clicon_nacm_credentials(clicon_handle h) /*! Which datastore cache method to use * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval method Datastore cache method * @see clixon-config@.yang CLICON_DATASTORE_CACHE */ @@ -1023,7 +1024,7 @@ clicon_datastore_cache(clicon_handle h) /*! Which Yang regexp/pattern engine to use * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval mode Regexp engine to use * @see clixon-config@.yang CLICON_YANG_REGEXP */ @@ -1046,7 +1047,7 @@ clicon_yang_regexp(clicon_handle h) /*! Get quiet mode eg -q option, do not print notifications on stdout * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval flag quiet mode on or off */ int @@ -1060,7 +1061,7 @@ clicon_quiet_mode(clicon_handle h) /*! Set quiet mode * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] val Flag value */ int diff --git a/lib/src/clixon_path.c b/lib/src/clixon_path.c index a595e5aa..d1156032 100644 --- a/lib/src/clixon_path.c +++ b/lib/src/clixon_path.c @@ -91,7 +91,7 @@ #include "clixon_err.h" #include "clixon_log.h" #include "clixon_options.h" -#include "clixon_yang.h" +#include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_nsctx.h" #include "clixon_xml_vec.h" @@ -131,7 +131,7 @@ api_path_parse(char *api_path, int retval = -1; clixon_api_path_yacc ay = {0,}; - clicon_debug(1, "%s api_path:%s", __FUNCTION__, api_path); + clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:%s", __FUNCTION__, api_path); ay.ay_parse_string = api_path; ay.ay_name = "api-path parser"; ay.ay_linenum = 1; @@ -176,7 +176,7 @@ instance_id_parse(char *path, int retval = -1; clixon_instance_id_yacc iy = {0,}; - clicon_debug(1, "%s path:%s", __FUNCTION__, path); + clixon_debug(CLIXON_DBG_DEFAULT, "%s path:%s", __FUNCTION__, path); iy.iy_parse_string = path; iy.iy_name = "instance-id parser"; iy.iy_linenum = 1; @@ -202,7 +202,7 @@ int clixon_path_free(clixon_path *cplist) { clixon_path *cp; - + while ((cp = cplist) != NULL){ DELQ(cp, cplist, clixon_path *); if (cp->cp_prefix) @@ -224,7 +224,7 @@ clixon_path_print(FILE *f, { clixon_path *cp; cg_var *cv; - + if ((cp = cplist) != NULL){ do { fprintf(f, "/"); @@ -244,7 +244,7 @@ clixon_path_print(FILE *f, fprintf(f, "]"); } } - cp = NEXTQ(clixon_path *, cp); + cp = NEXTQ(clixon_path *, cp); } while (cp && cp != cplist); } fprintf(f, "\n"); @@ -252,21 +252,22 @@ clixon_path_print(FILE *f, } /*! Given an XML node, return root node + * * A root node is an ancestor xr of x with one or both of the following properties * - its XML parent is NULL parent, * - its associated yang specification's parent is a yang module. * @param[in] x XML node * @param[out] xr XML root + * @retval 0 OK */ int xml_yang_root(cxobj *x, cxobj **xr) { - int retval = -1; cxobj *xp; yang_stmt *y; yang_stmt *yp; - + while ((xp = xml_parent(x)) != NULL){ if ((y = xml_spec(x)) != NULL && (yp = yang_parent_get(y)) != NULL) @@ -278,11 +279,11 @@ xml_yang_root(cxobj *x, x = xp; } *xr = x; - retval = 0; - return retval; + return 0; } /*! Construct an api-path key format from yang statement using wildcards for keys + * * Recursively construct it to the top. * Example: * yang: container a -> list b -> key c -> leaf d @@ -293,9 +294,9 @@ xml_yang_root(cxobj *x, * @retval 0 OK * @retval -1 Error * @see RFC8040 3.5.3 where "api-path" is defined as "URI-encoded path expression" - */ + */ static int -yang2api_path_fmt_1(yang_stmt *ys, +yang2api_path_fmt_1(yang_stmt *ys, int inclkey, cbuf *cb) { @@ -306,7 +307,7 @@ yang2api_path_fmt_1(yang_stmt *ys, cvec *cvk = NULL; /* vector of index keys */ int retval = -1; 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)); goto done; @@ -331,9 +332,9 @@ yang2api_path_fmt_1(yang_stmt *ys, * But in other cases (I think most), the / should be there, * so a patch is added in cli_show_auto instead. */ - if (yang_keyword_get(ys) == Y_LEAF && yp && - ypkeyw == Y_LIST && - yang_key_match(yp, ys->ys_argument, NULL) == 1) + if (yang_keyword_get(ys) == Y_LEAF && yp && + ypkeyw == Y_LIST && + yang_key_match(yp, ys->ys_argument, NULL) == 1) ; else #endif @@ -353,12 +354,12 @@ yang2api_path_fmt_1(yang_stmt *ys, cprintf(cb, "%s", yang_argument_get(ys)); } else{ - if (yang_keyword_get(ys) == Y_LEAF && yp && + if (yang_keyword_get(ys) == Y_LEAF && yp && ypkeyw == Y_LIST){ if (yang_key_match(yp, yang_argument_get(ys), NULL) == 0) cprintf(cb, "%s", yang_argument_get(ys)); /* Not if leaf and key */ } - else + else if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE) cprintf(cb, "%s", yang_argument_get(ys)); } @@ -398,9 +399,9 @@ yang2api_path_fmt_1(yang_stmt *ys, * @retval 0 OK * @retval -1 Error * "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 - */ + */ int -yang2api_path_fmt(yang_stmt *ys, +yang2api_path_fmt(yang_stmt *ys, int inclkey, char **api_path_fmt) { @@ -425,6 +426,7 @@ yang2api_path_fmt(yang_stmt *ys, } /*! Transform an xml key format and a vector of values to an XML key + * * Used for actual key, eg in clicon_rpc_change(), xmldb_put_xkey() * Example: * xmlkeyfmt: /interfaces/interface=%s/ipv4/address=%s @@ -438,7 +440,7 @@ yang2api_path_fmt(yang_stmt *ys, * @param[out] cvv_i 1..cvv-len. Index into cvv of last cvv entry used, For example, * if same as len of cvv, all were used, if < some entries were not * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * @note first and last elements of cvv are not used,.. * @see api_path_fmt2xpath * @example @@ -457,8 +459,8 @@ yang2api_path_fmt(yang_stmt *ys, * "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 */ int -api_path_fmt2api_path(const char *api_path_fmt, - cvec *cvv, +api_path_fmt2api_path(const char *api_path_fmt, + cvec *cvv, char **api_path, int *cvv_i) { @@ -472,7 +474,7 @@ api_path_fmt2api_path(const char *api_path_fmt, char *strenc=NULL; cg_var *cv; size_t len; - + if ((cb = cbuf_new()) == NULL){ clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; @@ -498,7 +500,7 @@ api_path_fmt2api_path(const char *api_path_fmt, } if (uri_percent_encode(&strenc, "%s", str) < 0) goto done; - cprintf(cb, "%s", strenc); + cprintf(cb, "%s", strenc); free(strenc); strenc = NULL; free(str); str = NULL; } @@ -518,7 +520,7 @@ api_path_fmt2api_path(const char *api_path_fmt, goto done; } if (cvv_i) /* Last entry in cvv used */ - *cvv_i = j; + *cvv_i = j; retval = 0; done: if (cb) @@ -527,10 +529,13 @@ api_path_fmt2api_path(const char *api_path_fmt, } /*! Transform an xml key format and a vector of values to an XML path + * * Used to input xmldb_get() * @param[in] api_path_fmt XML key format - * @param[in] cvv cligen variable vector, one for every wildchar in api_path_fmt - * @param[out] xpath XPATH + * @param[in] cvv cligen variable vector, one for every wildchar in api_path_fmt + * @param[out] xpath XPath + * @retval 0 OK + * @retval -1 Error * Add .* in last %s position. * @example * api_path_fmt: /interface/%s/address/%s @@ -548,10 +553,10 @@ api_path_fmt2api_path(const char *api_path_fmt, * api_path_fmt: /a:b/c * xpath : /b/c prefix:a * "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 - */ + */ int -api_path_fmt2xpath(char *api_path_fmt, - cvec *cvv, +api_path_fmt2xpath(char *api_path_fmt, + cvec *cvv, char **xpath) { int retval = -1; @@ -675,7 +680,7 @@ api_path2xpath_cvv(cvec *api_path, char *decval; int ret; int root; - + cprintf(xpath, "/"); /* Initialize namespace context */ if ((nsc = xml_nsctx_init(NULL, NULL)) == NULL) @@ -691,7 +696,7 @@ api_path2xpath_cvv(cvec *api_path, /* api-path: prefix points to module */ if (nodeid_split(nodeid, &prefix, &name) < 0) goto done; - clicon_debug(CLIXON_DBG_DETAIL, "%s [%d] cvname: %s:%s", + clixon_debug(CLIXON_DBG_DETAIL, "%s [%d] cvname: %s:%s", __FUNCTION__, i, prefix?prefix:"", name); /* top-node must have prefix */ if (i == offset && prefix == NULL){ @@ -725,8 +730,8 @@ api_path2xpath_cvv(cvec *api_path, */ if (xml_nsctx_get_prefix(nsc, namespace, &xprefix) == 0){ xprefix = yang_find_myprefix(y); - clicon_debug(CLIXON_DBG_DETAIL, "%s prefix not found add it %s", __FUNCTION__, xprefix); - /* not found, add it to nsc + clixon_debug(CLIXON_DBG_DETAIL, "%s prefix not found add it %s", __FUNCTION__, xprefix); + /* not found, add it to nsc * XXX: do we always have to add it? It could be default? */ // if (xml2prefix(x1, namespace, &pexisting)); @@ -809,7 +814,7 @@ api_path2xpath_cvv(cvec *api_path, if (ret == 1){ yang_stmt *y1 = NULL; if (xml_nsctx_yangspec(yspec, &nsc) < 0) - goto done; + goto done; if (yang_mount_get(y, cbuf_get(xpath), &y1) < 0) goto done; if (y1 == NULL || yang_keyword_get(y1) != Y_SPEC){ @@ -834,7 +839,7 @@ api_path2xpath_cvv(cvec *api_path, nsc = NULL; } done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); if (cberr) cbuf_free(cberr); if (valvec) @@ -852,6 +857,7 @@ api_path2xpath_cvv(cvec *api_path, } /*! Translate from restconf api-path to xml xpath and namespace + * * @param[in] api_path URI-encoded path expression" (RFC8040 3.5.3) * @param[in] yspec Yang spec * @param[out] xpath xpath (use free() to deallocate) @@ -1049,7 +1055,7 @@ api_path2xml_vec(char **vec, goto done; xml_spec_set(x, y); if ((xb = xml_new("body", x, CX_BODY)) == NULL) - goto done; + goto done; if (restval){ if (uri_percent_decode(restval, &val) < 0) goto done; @@ -1075,7 +1081,7 @@ api_path2xml_vec(char **vec, */ if ((valvec = clicon_strsep(restval, ",", &nvalvec)) == NULL) goto done; - if ((nvalvec != cvec_len(cvk)) && strict){ + if ((nvalvec != cvec_len(cvk)) && strict){ cprintf(cberr, "List key %s length mismatch", name); if (xerr && netconf_malformed_message_xml(xerr, cbuf_get(cberr)) < 0) @@ -1104,7 +1110,7 @@ api_path2xml_vec(char **vec, } if (x != NULL){ if ((xn = xml_new(keyname, x, CX_ELMNT)) == NULL) - goto done; + goto done; xml_spec_set(xn, ykey); if ((xb = xml_new("body", xn, CX_BODY)) == NULL) goto done; @@ -1151,7 +1157,7 @@ api_path2xml_vec(char **vec, if (ret == 1){ yang_stmt *y1 = NULL; if (xml_nsctx_yangspec(ys_spec(y), &nsc) < 0) - goto done; + goto done; if (xml2xpath(x, nsc, 0, 1, &xpath) < 0) // XXX should be canonical goto done; if (xpath == NULL){ @@ -1166,15 +1172,15 @@ api_path2xml_vec(char **vec, } y = y1; } - if ((retval = api_path2xml_vec(vec+1, nvec-1, - x, y, - nodeclass, strict, + if ((retval = api_path2xml_vec(vec+1, nvec-1, + x, y, + nodeclass, strict, xbotp, ybotp, xerr)) < 1) goto done; ok: retval = 1; /* OK */ done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); if (xpath) free(xpath); if (nsc) @@ -1243,7 +1249,7 @@ api_path2xml(char *api_path, cxobj *xroot; cbuf *cberr = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s api_path:%s", __FUNCTION__, 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"); goto done; @@ -1267,7 +1273,7 @@ api_path2xml(char *api_path, } nvec--; /* NULL-terminated */ if ((retval = api_path2xml_vec(vec+1, nvec, - xtop, yspec, nodeclass, strict, + xtop, yspec, nodeclass, strict, xbotp, ybotp, xerr)) < 1) goto done; /* Fix namespace */ @@ -1289,6 +1295,7 @@ api_path2xml(char *api_path, } /*! Construct an api_path from an XML node (single level not recursive) + * * @param[in] x XML node (need to be yang populated) * @param[out] cb api_path, must be initialized * @retval 0 OK @@ -1313,7 +1320,7 @@ xml2api_path_1(cxobj *x, char *enc; yang_stmt *ymod; cxobj *xp; - + if ((y = xml_spec(x)) == NULL){ cprintf(cb, "/%s", xml_name(x)); goto ok; @@ -1377,11 +1384,12 @@ xml2api_path_1(cxobj *x, } /*! Resolve api-path module:names to yang statements + * * @param[in] cplist Lisp of clixon-path * @param[in] yt Yang statement of top symbol (can be yang-spec if top-level) - * @retval -1 Error - * @retval 0 Fail * @retval 1 OK + * @retval 0 Fail + * @retval -1 Error * Reasons for fail (retval = 0) are: XXX * - Modulename in api-path does not correspond to existing module * - Modulename not defined for top-level id. @@ -1401,7 +1409,7 @@ api_path_resolve(clixon_path *cplist, cg_var *cva; cg_var *cvy; cvec *cvk; - + if ((cp = cplist) != NULL){ do { if (yang_keyword_get(yt) == Y_SPEC){ @@ -1464,11 +1472,12 @@ api_path_resolve(clixon_path *cplist, } /*! Resolve instance-id prefix:names to yang statements + * * @param[in] cplist Lisp of clixon-path * @param[in] yt Yang statement of top symbol (can be yang-spec if top-level) - * @retval -1 Error - * @retval 0 Fail error in xerr * @retval 1 OK + * @retval 0 Fail error in xerr + * @retval -1 Error * @note: The spec says: prefixes depend on the XML context in which the value occurs. * However, canonical prefixes/namespaces are used based on loaded yang modules. * This means that prefix=NULL is not allowed. @@ -1492,7 +1501,7 @@ instance_id_resolve(clixon_path *cplist, cg_var *cva; yang_stmt *yspec; char *kname; - + yspec = ys_spec(yt); if ((cp = cplist) != NULL){ do { @@ -1517,7 +1526,7 @@ instance_id_resolve(clixon_path *cplist, 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"); - goto fail; + goto fail; #endif break; } @@ -1537,7 +1546,6 @@ instance_id_resolve(clixon_path *cplist, } } else{ /* Assume index */ - } } break; @@ -1568,9 +1576,9 @@ instance_id_resolve(clixon_path *cplist, * @param[in] yt Yang statement of top symbol (can be yang-spec if top-level) * @param[in] cplist Lisp of clixon-path * @param[out] xvec Vector of xml-trees. Vector must be free():d after use - * @retval -1 Error - * @retval 0 Fail fail: eg no yang * @retval 1 OK with found xml nodes in xvec (if any) + * @retval 0 Fail fail: eg no yang + * @retval -1 Error */ static int clixon_path_search(cxobj *xt, @@ -1584,12 +1592,12 @@ clixon_path_search(cxobj *xt, clixon_xvec *xvecp = NULL; clixon_xvec *xvecc = NULL; yang_stmt *yc; - cxobj *xp; + cxobj *xp; int i; cg_var *cv; if ((xvecp = clixon_xvec_new()) == NULL) - goto done; + goto done; modns = NULL; if ((cp = cplist) != NULL){ if (clixon_xvec_append(xvecp, xt) < 0) @@ -1645,9 +1653,9 @@ clixon_path_search(cxobj *xt, * @param[in] yt Yang statement of top symbol (can be yang-spec if top-level) * @param[out] xvec Vector of xml-trees. Vector must be free():d after use * @param[in] format Format string for api-path syntax - * @retval -1 Error - * @retval 0 Non-fatal failure, yang bind failures, etc, * @retval 1 OK with found xml nodes in xvec (if any) (xvec contains matches) + * @retval 0 Non-fatal failure, yang bind failures, etc, + * @retval -1 Error * Reasons for nomatch (retval = 0) are: * - Modulename in api-path does not correspond to existing module * - Modulename not defined for top-level id. @@ -1666,7 +1674,7 @@ clixon_path_search(cxobj *xt, * @see clixon_xml_find_instance_id */ int -clixon_xml_find_api_path(cxobj *xt, +clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, int *xlen, @@ -1680,7 +1688,7 @@ clixon_xml_find_api_path(cxobj *xt, clixon_path *cplist = NULL; int ret; clixon_xvec *xv = NULL; - + va_start(ap, format); len = vsnprintf(NULL, 0, format, ap); va_end(ap); @@ -1700,7 +1708,7 @@ clixon_xml_find_api_path(cxobj *xt, /* Parse api-path string to structured clixon-path data */ if (api_path_parse(api_path, &cplist) < 0) goto done; - if (clicon_debug_get()) + if (clixon_debug_get()) clixon_path_print(stderr, cplist); /* Resolve module:name to yang-stmt, fail if not successful */ if ((ret = api_path_resolve(cplist, yt)) < 0) @@ -1737,9 +1745,9 @@ clixon_xml_find_api_path(cxobj *xt, * @param[out] xvec Vector of xml-trees. Vector must be free():d after use * @param[out] xlen Returns length of vector in return value * @param[in] format Format string for api-path syntax - * @retval -1 Error - * @retval 0 Non-fatal failure, yang bind failures, etc, * @retval 1 OK with found xml nodes in xvec (if any) + * @retval 0 Non-fatal failure, yang bind failures, etc, + * @retval -1 Error * Reasons for nomatch (retval = 0) are: * - Modulename in api-path does not correspond to existing module * - Modulename not defined for top-level id. @@ -1760,7 +1768,7 @@ clixon_xml_find_api_path(cxobj *xt, * @see RFC7950 Sec 9.13 */ int -clixon_xml_find_instance_id(cxobj *xt, +clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, int *xlen, @@ -1774,7 +1782,7 @@ clixon_xml_find_instance_id(cxobj *xt, clixon_path *cplist = NULL; int ret; clixon_xvec *xv = NULL; - + va_start(ap, format); len = vsnprintf(NULL, 0, format, ap); va_end(ap); @@ -1793,7 +1801,7 @@ clixon_xml_find_instance_id(cxobj *xt, va_end(ap); if (instance_id_parse(path, &cplist) < 0) goto done; - if (clicon_debug_get()) + if (clixon_debug_get()) clixon_path_print(stderr, cplist); /* Resolve module:name to pointer to yang-stmt, fail if not successful */ if ((ret = instance_id_resolve(cplist, yt)) < 0) @@ -1828,9 +1836,9 @@ clixon_xml_find_instance_id(cxobj *xt, * @param[in] yt Yang statement of top symbol (can be yang-spec if top-level) * @param[out] nsctx Namespace context (should be created on entry) * @param[in] format Format string for xpath syntax - * @retval -1 Error - * @retval 0 Non-fatal failure, yang bind failures, etc, * @retval 1 OK with found xml nodes in xvec (if any) + * @retval 0 Non-fatal failure, yang bind failures, etc, + * @retval -1 Error * Reasons for nomatch (retval = 0) are: * - Modulename in api-path does not correspond to existing module * - Modulename not defined for top-level id. @@ -1862,7 +1870,7 @@ clixon_instance_id_bind(yang_stmt *yt, clixon_path *cp; int ret; char *namespace; - + va_start(ap, format); len = vsnprintf(NULL, 0, format, ap); va_end(ap); @@ -1881,7 +1889,7 @@ clixon_instance_id_bind(yang_stmt *yt, va_end(ap); if (instance_id_parse(path, &cplist) < 0) goto done; - if (clicon_debug_get()) + if (clixon_debug_get()) clixon_path_print(stderr, cplist); /* Resolve module:name to pointer to yang-stmt, fail if not successful */ if ((ret = instance_id_resolve(cplist, yt)) < 0) @@ -1921,9 +1929,9 @@ clixon_instance_id_bind(yang_stmt *yt, * @param[out] cplistp Path parse-tree * @param[out] xerr Contains error if retval=0 * @param[in] format Format string for xpath syntax - * @retval -1 Error - * @retval 0 Non-fatal failure, yang bind failures, etc, * @retval 1 OK with found xml nodes in xvec (if any) + * @retval 0 Non-fatal failure, yang bind failures, etc, + * @retval -1 Error */ int clixon_instance_id_parse(yang_stmt *yt, @@ -1938,7 +1946,7 @@ clixon_instance_id_parse(yang_stmt *yt, char *path = NULL; clixon_path *cplist = NULL; int ret; - + va_start(ap, format); len = vsnprintf(NULL, 0, format, ap); va_end(ap); @@ -1957,7 +1965,7 @@ clixon_instance_id_parse(yang_stmt *yt, va_end(ap); if (instance_id_parse(path, &cplist) < 0) goto done; - if (clicon_debug_get()) + if (clixon_debug_get()) clixon_path_print(stderr, cplist); /* Resolve module:name to pointer to yang-stmt, fail if not successful */ if ((ret = instance_id_resolve(cplist, yt)) < 0) diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index eea3ddaf..e51b8a27 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -76,6 +76,7 @@ * Private types */ /*! Structure for checking status before and after a plugin call + * * Currently signal settings: blocked and handlers, and termios * @see plugin_context_check */ @@ -121,7 +122,8 @@ struct plugin_module_struct { typedef struct plugin_module_struct plugin_module_struct; /*! Get plugin handle containing plugin and callback lists - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle */ static plugin_module_struct * plugin_module_struct_get(clicon_handle h) @@ -136,8 +138,11 @@ plugin_module_struct_get(clicon_handle h) } /*! Set plugin handle containing plugin and callback lists - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] pl Clixon plugin handle + * @retval 0 OK + * @retval -1 Error */ static int plugin_module_struct_set(clicon_handle h, @@ -156,8 +161,9 @@ plugin_module_struct_set(clicon_handle h, /* Access functions */ /*! Get plugin api + * * @param[in] cp Clixon plugin handle - */ + */ clixon_plugin_api * clixon_plugin_api_get(clixon_plugin_t *cp) { @@ -165,8 +171,9 @@ clixon_plugin_api_get(clixon_plugin_t *cp) } /*! Get plugin name + * * @param[in] cp Clixon plugin handle - */ + */ char * clixon_plugin_name_get(clixon_plugin_t *cp) { @@ -174,8 +181,9 @@ clixon_plugin_name_get(clixon_plugin_t *cp) } /*! Get plugin handle + * * @param[in] cp Clixon plugin handle - */ + */ plghndl_t clixon_plugin_handle_get(clixon_plugin_t *cp) { @@ -187,7 +195,7 @@ clixon_plugin_handle_get(clixon_plugin_t *cp) * @note Never manipulate the plugin during operation or using the * same object recursively * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] plugin previous plugin, or NULL on init * @code * clicon_plugin *cp = NULL; @@ -201,7 +209,7 @@ clixon_plugin_t * clixon_plugin_each(clicon_handle h, clixon_plugin_t *cpprev) { - clixon_plugin_t *cpnext = NULL; + clixon_plugin_t *cpnext = NULL; plugin_module_struct *ms = plugin_module_struct_get(h); /* ms == NULL means plugins are not yet initialized */ @@ -222,7 +230,7 @@ clixon_plugin_each(clicon_handle h, * @note Never manipulate the plugin during operation or using the * same object recursively * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] plugin previous plugin, or NULL on init * @param[in] nr Start from this nr <= lngth of list * @code @@ -238,9 +246,9 @@ clixon_plugin_each_revert(clicon_handle h, clixon_plugin_t *cpprev, int nr) { - int i; - clixon_plugin_t *cpnext = NULL; + clixon_plugin_t *cpnext = NULL; plugin_module_struct *ms = plugin_module_struct_get(h); + int i; if (ms == NULL){ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); @@ -263,12 +271,13 @@ clixon_plugin_each_revert(clicon_handle h, cpnext = NULL; else cpnext = PREVQ(clixon_plugin_t *, cpprev); - } + } return cpnext; } /*! Find plugin by name - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] name Plugin name * @retval p Plugin if found * @retval NULL Not found @@ -300,7 +309,7 @@ clixon_plugin_find(clicon_handle h, /*! Load a dynamic plugin object and call its init-function * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] file Which plugin to load * @param[in] function Which function symbol to load and call * @param[in] dlflags See man(3) dlopen @@ -311,7 +320,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(clicon_handle h, char *file, /* note modified */ const char *function, int dlflags, @@ -327,7 +336,7 @@ plugin_load_one(clicon_handle h, char *p; void *wh = NULL; - clicon_debug(1, "%s file:%s function:%s", __FUNCTION__, file, function); + clixon_debug(CLIXON_DBG_DEFAULT, "%s file:%s function:%s", __FUNCTION__, file, function); dlerror(); /* Clear any existing error */ if ((handle = dlopen(file, dlflags)) == NULL) { error = (char*)dlerror(); @@ -382,7 +391,7 @@ plugin_load_one(clicon_handle h, } retval = 1; done: - clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); if (wh != NULL) free(wh); if (retval != 1 && handle) @@ -393,12 +402,13 @@ plugin_load_one(clicon_handle h, } /*! Load a set of plugin objects from a directory and and call their init-function - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] function Which function symbol to load and call (eg CLIXON_PLUGIN_INIT) * @param[in] dir Directory. .so files in this dir will be loaded. * @param[in] regexp Regexp for matching files in plugin directory. Default *.so. * @retval 0 OK - * @retval -1 Error + * @retval -1 Error */ int clixon_plugins_load(clicon_handle h, @@ -415,8 +425,8 @@ clixon_plugins_load(clicon_handle h, int ret; plugin_module_struct *ms = plugin_module_struct_get(h); int dlflags; - - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (ms == NULL){ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; @@ -427,7 +437,7 @@ clixon_plugins_load(clicon_handle h, /* Load all plugins */ for (i = 0; i < ndp; i++) { snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name); - clicon_debug(CLIXON_DBG_DEFAULT, "Loading plugin '%s'", filename); + clixon_debug(CLIXON_DBG_DEFAULT, "Loading plugin '%s'", filename); dlflags = RTLD_NOW; if (clicon_option_bool(h, "CLICON_PLUGIN_DLOPEN_GLOBAL")) dlflags |= RTLD_GLOBAL; @@ -447,7 +457,8 @@ done: } /*! Create a pseudo plugin so that a main function can register callbacks - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] name Plugin name * @param[out] cpp Clixon plugin structure (direct pointer) * @retval 0 OK, with cpp set @@ -468,7 +479,7 @@ clixon_pseudo_plugin(clicon_handle h, clixon_plugin_t *cp = NULL; plugin_module_struct *ms = plugin_module_struct_get(h); - clicon_debug(1, "%s %s", __FUNCTION__, name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name); if (ms == NULL){ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; @@ -492,6 +503,7 @@ done: } /*! Get system context, eg signal procmask (for blocking) and sigactions + * * Call this before a plugin * @retval pc Plugin context structure, use free() to deallocate * @retval NULL Error @@ -670,6 +682,7 @@ plugin_context_check(clicon_handle h, } /*! Call single plugin start callback + * * @param[in] cp Plugin handle * @param[in] h Clixon handle * @retval 0 OK @@ -688,7 +701,7 @@ 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) + 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", __FUNCTION__, cp->cp_name); goto done; @@ -702,7 +715,10 @@ clixon_plugin_start_one(clixon_plugin_t *cp, } /*! Call plugin_start in all plugins + * * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error * Call plugin start functions (if defined) * @note Start functions can use clicon_argv_get() to get -- command line options */ @@ -722,7 +738,8 @@ clixon_plugin_start_all(clicon_handle h) } /*! Unload all plugins: call exit function and close shared handle - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] cp Plugin handle * @param[in] h Clixon handle * @retval 0 OK @@ -736,13 +753,13 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, char *error; plgexit_t *fn; void *wh = NULL; - + if ((fn = cp->cp_api.ca_exit) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h) < 0) { - if (clicon_errno < 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", __FUNCTION__, cp->cp_name); goto done; @@ -760,6 +777,7 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, } /*! Unload all plugins: call exit function and close shared handle + * * @param[in] h Clixon handle * @retval 0 OK * @retval -1 Error @@ -784,8 +802,9 @@ clixon_plugin_exit_all(clicon_handle h) return retval; } -/*! Run the restconf user-defined credentials callback - * @param[in] h Clicon handle +/*! Run the restconf user-defined credentials callback + * + * @param[in] h Clixon handle * @param[in] req Per-message request www handle to use with restconf_api.h * @param[in] auth_type Authentication type: none, user-defined, or client-cert * @param[out] authp NULL: Credentials failed, no user set (401 returned). @@ -798,23 +817,23 @@ clixon_plugin_exit_all(clicon_handle h) * Or no callback was found. */ static int -clixon_plugin_auth_one(clixon_plugin_t *cp, - clicon_handle h, +clixon_plugin_auth_one(clixon_plugin_t *cp, + clicon_handle h, void *req, clixon_auth_type_t auth_type, char **authp) { - int retval = -1; + int retval = -1; plgauth_t *fn; /* Plugin auth */ void *wh = NULL; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((fn = cp->cp_api.ca_auth) != NULL){ wh = NULL; 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) + 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", __FUNCTION__, cp->cp_name); goto done; @@ -825,14 +844,15 @@ clixon_plugin_auth_one(clixon_plugin_t *cp, else retval = 0; /* Ignored / no callback */ done: - clicon_debug(1, "%s retval:%d auth:%s", __FUNCTION__, retval, *authp); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d auth:%s", __FUNCTION__, retval, *authp); return retval; } /*! Run the restconf user-defined credentials callback for all plugins + * * Find first authentication callback and call that, then return. * The callback is to set the authenticated user - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] req Per-message request www handle to use with restconf_api.h * @param[in] auth_type Authentication type: none, user-defined, or client-cert * @param[out] authp NULL: Credentials failed, no user set (401 returned). @@ -844,20 +864,20 @@ 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(clicon_handle h, void *req, clixon_auth_type_t auth_type, char **authp) { int retval = -1; clixon_plugin_t *cp = NULL; - int ret = 0; - - clicon_debug(1, "%s", __FUNCTION__); + int ret = 0; + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (authp == NULL){ clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL"); goto done; - } + } *authp = NULL; ret = 0; /* ignore */ while ((cp = clixon_plugin_each(h, cp)) != NULL) { @@ -869,11 +889,12 @@ clixon_plugin_auth_all(clicon_handle h, } retval = ret; done: - clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; } /*! Callback for a yang extension (unknown) statement single plugin + * * extension can be made. * @param[in] cp Plugin handle * @param[in] h Clixon handle @@ -884,20 +905,20 @@ clixon_plugin_auth_all(clicon_handle h, */ int clixon_plugin_extension_one(clixon_plugin_t *cp, - clicon_handle h, - yang_stmt *yext, - yang_stmt *ys) + clicon_handle h, + yang_stmt *yext, + yang_stmt *ys) { int retval = 1; plgextension_t *fn; /* Plugin extension fn */ void *wh = NULL; - + if ((fn = cp->cp_api.ca_extension) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, yext, ys) < 0) { - if (clicon_errno < 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", __FUNCTION__, cp->cp_name); goto done; @@ -911,6 +932,7 @@ clixon_plugin_extension_one(clixon_plugin_t *cp, } /*! Callback for a yang extension (unknown) statement in all plugins + * * Called at parsing of yang module containing a statement of an extension. * A plugin may identify the extension and perform actions * on the yang statement, such as transforming the yang. @@ -919,8 +941,8 @@ clixon_plugin_extension_one(clixon_plugin_t *cp, * @param[in] h Clixon handle * @param[in] yext Yang node of extension * @param[in] ys Yang node of (unknown) statement belonging to extension - * @retval 0 OK, all callbacks executed OK - * @retval -1 Error in one callback + * @retval 0 OK, all callbacks executed OK + * @retval -1 Error in one callback */ int clixon_plugin_extension_all(clicon_handle h, @@ -929,7 +951,7 @@ clixon_plugin_extension_all(clicon_handle h, { int retval = -1; clixon_plugin_t *cp = NULL; - + while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (clixon_plugin_extension_one(cp, h, yext, ys) < 0) goto done; @@ -942,12 +964,12 @@ clixon_plugin_extension_all(clicon_handle h, /*! Call plugin general-purpose datastore upgrade in one plugin * * @param[in] cp Plugin handle - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db Name of datastore, eg "running", "startup" or "tmp" * @param[in] xt XML tree. Upgrade this "in place" * @param[in] msd Module-state diff, info on datastore module-state - * @retval -1 Error * @retval 0 OK + * @retval -1 Error * Upgrade datastore on load before or as an alternative to module-specific upgrading mechanism */ int @@ -961,13 +983,13 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, int retval = -1; datastore_upgrade_t *fn; void *wh = NULL; - + if ((fn = cp->cp_api.ca_datastore_upgrade) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, db, xt, msd) < 0) { - if (clicon_errno < 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", __FUNCTION__, cp->cp_name); goto done; @@ -982,7 +1004,7 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, /*! Call plugin general-purpose datastore upgrade in all plugins * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] db Name of datastore, eg "running", "startup" or "tmp" * @param[in] xt XML tree. Upgrade this "in place" * @param[in] msd Module-state diff, info on datastore module-state @@ -998,7 +1020,7 @@ clixon_plugin_datastore_upgrade_all(clicon_handle h, { int retval = -1; clixon_plugin_t *cp = NULL; - + while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (clixon_plugin_datastore_upgrade_one(cp, h, db, xt, msd) < 0) goto done; @@ -1032,13 +1054,13 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp, int retval = -1; yang_mount_t *fn; void *wh = NULL; - + if ((fn = cp->cp_api.ca_yang_mount) != NULL){ wh = NULL; 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) + 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", __FUNCTION__, cp->cp_name); goto done; @@ -1070,7 +1092,7 @@ clixon_plugin_yang_mount_all(clicon_handle h, { int retval = -1; clixon_plugin_t *cp = NULL; - + while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (clixon_plugin_yang_mount_one(cp, h, xt, config, vl, yanglib) < 0) goto done; @@ -1085,7 +1107,6 @@ clixon_plugin_yang_mount_all(clicon_handle h, /*! Call plugin YANG schema patch * - * @param[in] cp Plugin handle * @param[in] h Clixon handle * @param[in] ymod YANG module @@ -1100,13 +1121,13 @@ clixon_plugin_yang_patch_one(clixon_plugin_t *cp, int retval = -1; yang_patch_t *fn; void *wh = NULL; - + if ((fn = cp->cp_api.ca_yang_patch) != NULL){ wh = NULL; if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, ymod) < 0) { - if (clicon_errno < 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", __FUNCTION__, cp->cp_name); goto done; @@ -1132,7 +1153,7 @@ clixon_plugin_yang_patch_all(clicon_handle h, { int retval = -1; clixon_plugin_t *cp = NULL; - + while ((cp = clixon_plugin_each(h, cp)) != NULL) { if (clixon_plugin_yang_patch_one(cp, h, ymod) < 0) goto done; @@ -1153,10 +1174,10 @@ rpc_callback_dump(clicon_handle h) rpc_callback_t *rc; plugin_module_struct *ms = plugin_module_struct_get(h); - clicon_debug(1, "%s--------------", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s--------------", __FUNCTION__); if ((rc = ms->ms_rpc_callbacks) != NULL) do { - clicon_debug(1, "%s %s", __FUNCTION__, rc->rc_name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, rc->rc_name); rc = NEXTQ(rpc_callback_t *, rc); } while (rc != ms->ms_rpc_callbacks); return 0; @@ -1177,14 +1198,14 @@ rpc_callback_dump(clicon_handle h) int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, - void *arg, + void *arg, const char *ns, const char *name) { rpc_callback_t *rc = NULL; plugin_module_struct *ms = plugin_module_struct_get(h); - clicon_debug(1, "%s %s", __FUNCTION__, name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name); if (ms == NULL){ clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; @@ -1252,7 +1273,7 @@ rpc_callback_delete_all(clicon_handle h) */ int rpc_callback_call(clicon_handle h, - cxobj *xe, + cxobj *xe, void *arg, int *nrp, cbuf *cbret) @@ -1283,7 +1304,7 @@ rpc_callback_call(clicon_handle h, if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0) goto done; if (rc->rc_callback(h, xe, cbret, arg, rc->rc_arg) < 0){ - clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Error in: %s", __FUNCTION__, rc->rc_name); if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0) goto done; goto done; @@ -1305,7 +1326,7 @@ rpc_callback_call(clicon_handle h, *nrp = nr; retval = 1; /* 0: none found, >0 nr of handlers called */ done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); return retval; fail: retval = 0; @@ -1318,6 +1339,7 @@ rpc_callback_call(clicon_handle h, */ /*! Register a RPC action callback by appending a new RPC to a yang action node + *Ä * @param[in] h clicon handle * @param[in] ys YANG node where action resides * @param[in] cb Callback @@ -1336,7 +1358,7 @@ action_callback_register(clicon_handle h, rpc_callback_t *rc = NULL; char *name; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (ya == NULL){ clicon_err(OE_DB, EINVAL, "yang node is NULL"); goto done; @@ -1375,7 +1397,7 @@ action_callback_register(clicon_handle h, */ int action_callback_call(clicon_handle h, - cxobj *xe, + cxobj *xe, cbuf *cbret, void *arg, void *regarg) @@ -1387,19 +1409,19 @@ action_callback_call(clicon_handle h, int nr = 0; /* How many callbacks */ void *wh = NULL; rpc_callback_t *rc; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (xml_find_action(xe, 1, &xa) < 0) goto done; if (xa == NULL){ if (netconf_operation_not_supported(cbret, "application", "Action not found") < 0) goto done; - goto ok; + goto ok; } if ((ya = xml_spec(xa)) == NULL){ if (netconf_operation_not_supported(cbret, "application", "Action spec not found") < 0) goto done; - goto ok; + goto ok; } name = xml_name(xa); /* Action callback */ @@ -1409,7 +1431,7 @@ action_callback_call(clicon_handle h, if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0) goto done; if (rc->rc_callback(h, xa, cbret, arg, rc->rc_arg) < 0){ - clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Error in: %s", __FUNCTION__, rc->rc_name); if (plugin_context_check(h, &wh, rc->rc_name, __FUNCTION__) < 0) goto done; goto done; @@ -1512,9 +1534,9 @@ upgrade_callback_delete_all(clicon_handle h) * @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) * @param[out] cbret Return XML (as string in CLIgen buffer), on invalid - * @retval 1 OK - * @retval 0 Invalid - cbret contains reason as netconf - * @retval -1 Error + * @retval 1 OK + * @retval 0 Invalid - cbret contains reason as netconf + * @retval -1 Error * @see upgrade_callback_reg_fn which registers the callbacks */ int @@ -1548,11 +1570,11 @@ upgrade_callback_call(clicon_handle h, */ if (uc->uc_namespace == NULL || strcmp(uc->uc_namespace, ns)==0){ if ((ret = uc->uc_callback(h, xt, ns, op, from, to, uc->uc_arg, cbret)) < 0){ - clicon_debug(1, "%s Error in: %s", __FUNCTION__, uc->uc_namespace); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Error in: %s", __FUNCTION__, uc->uc_namespace); goto done; } if (ret == 0){ - if (cbuf_len(cbret)==0){ + if (cbuf_len(cbret)==0){ clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set", uc->uc_fnstr, ns); goto done; @@ -1565,7 +1587,7 @@ upgrade_callback_call(clicon_handle h, } while (uc != ms->ms_upgrade_callbacks); retval = 1; done: - clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; fail: retval =0; @@ -1600,8 +1622,11 @@ clixon_auth_type_int2str(clixon_auth_type_t auth_type) } /*! Initialize plugin module by creating a handle holding plugin and callback lists + * * This should be called once at start by every application * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error * @see clixon_plugin_module_exit */ int @@ -1627,6 +1652,7 @@ clixon_plugin_module_init(clicon_handle h) } /*! Delete plugin module + * * This should be called once at exit by every application * @param[in] h Clixon handle */ diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index d7114eda..0ed01b1b 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -169,12 +169,13 @@ clixon_proc_sigint(int sig) } /*! Fork a child, exec a child and setup socket to child and return to caller + * * @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 * @param[out] sock Socket * @retval O OK - * @retval -1 Error. + * @retval -1 Error. * @see clixon_proc_socket_close close sockets, kill child and wait for child termination * @see for flags usage see man sockerpair(2) */ @@ -239,8 +240,7 @@ clixon_proc_socket(char **argv, clicon_err(OE_UNIX, errno, "dup2(STDOUT)"); return -1; } - close(sp[1]); - + close(sp[1]); if (execvp(argv[0], argv) < 0){ clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); return -1; @@ -248,7 +248,7 @@ clixon_proc_socket(char **argv, exit(-1); /* Shouldnt reach here */ } - clicon_debug(CLIXON_DBG_DEFAULT, "%s child %u sock %d", __FUNCTION__, child, sp[0]); + clixon_debug(CLIXON_DBG_DEFAULT, "%s child %u sock %d", __FUNCTION__, child, sp[0]); /* Parent */ close(sp[1]); *pid = child; @@ -262,7 +262,8 @@ clixon_proc_socket(char **argv, return retval; } -/*! +/*! Close socket + * * @see clixon_proc_socket which creates the child and sockets closed and killed here */ int @@ -272,7 +273,7 @@ clixon_proc_socket_close(pid_t pid, int retval = -1; int status; - clicon_debug(CLIXON_DBG_DEFAULT, "%s pid %u sock %d", __FUNCTION__, pid, sock); + clixon_debug(CLIXON_DBG_DEFAULT, "%s pid %u sock %d", __FUNCTION__, pid, sock); if (sock != -1) close(sock); /* usually kills */ @@ -280,7 +281,7 @@ clixon_proc_socket_close(pid_t pid, // usleep(100000); /* Wait for child to finish */ if(waitpid(pid, &status, 0) == pid){ retval = WEXITSTATUS(status); - clicon_debug(CLIXON_DBG_DEFAULT, "%s waitpid status %#x", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s waitpid status %#x", __FUNCTION__, retval); } return retval; } @@ -293,7 +294,7 @@ clixon_proc_socket_close(pid_t pid, * @param[in] fdkeep If -1 keep this filedes open * @param[out] pid Process id * @retval 0 OK - * @retval -1 Error. + * @retval -1 Error. */ static int clixon_proc_background(char **argv, @@ -313,7 +314,7 @@ clixon_proc_background(char **argv, char *flattened; unsigned argc; - clicon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (argv == NULL){ clicon_err(OE_UNIX, EINVAL, "argv is NULL"); goto quit; @@ -350,7 +351,7 @@ clixon_proc_background(char **argv, char nsfile[PATH_MAX]; int nsfd; #endif - clicon_debug(CLIXON_DBG_DEFAULT, "%s child", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s child", __FUNCTION__); clicon_signal_unblock(0); signal(SIGTSTP, SIG_IGN); if (chdir("/") < 0){ @@ -370,7 +371,7 @@ clixon_proc_background(char **argv, */ if (netns != NULL) { snprintf(nsfile, PATH_MAX, "/var/run/netns/%s", netns); /* see man setns / ip netns */ - clicon_debug(CLIXON_DBG_DEFAULT, "%s nsfile:%s", __FUNCTION__, nsfile); + 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"); @@ -409,7 +410,7 @@ clixon_proc_background(char **argv, *pid0 = child; retval = 0; quit: - clicon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d child:%u", __FUNCTION__, retval, child); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d child:%u", __FUNCTION__, retval, child); return retval; } @@ -504,7 +505,7 @@ clixon_process_register(clicon_handle h, int retval = -1; process_entry_t *pe = NULL; int i; - + if (name == NULL){ clicon_err(OE_DB, EINVAL, "name is NULL"); goto done; @@ -514,7 +515,7 @@ clixon_process_register(clicon_handle h, goto done; } - clicon_debug(CLIXON_DBG_DEFAULT, "%s name:%s (%s)", __FUNCTION__, name, argv[0]); + 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"); @@ -554,8 +555,8 @@ clixon_process_register(clicon_handle h, } } pe->pe_callback = callback; - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s ----> %s", __FUNCTION__, - pe->pe_name, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s ----> %s", __FUNCTION__, + pe->pe_name, clicon_int2str(proc_state_map, PROC_STATE_STOPPED) ); pe->pe_state = PROC_STATE_STOPPED; @@ -601,7 +602,7 @@ clixon_process_delete_all(clicon_handle h) return 0; } -/*! +/*! Run process */ static int proc_op_run(pid_t pid0, @@ -633,9 +634,9 @@ proc_op_run(pid_t pid0, } int -clixon_process_pid(clicon_handle h, - const char *name, - pid_t *pid) +clixon_process_pid(clicon_handle h, + const char *name, + pid_t *pid) { int retval = -1; process_entry_t *pe; @@ -671,8 +672,9 @@ done: * @param[in] name Name of process * @param[in] op0 start, stop, restart, status * @param[in] wrapit If set, call potential callback, if false, dont call it - * @retval -1 Error - * @retval 0 OK + * @retval 0 OK + * @retval -1 Error + * @see upgrade_callback_reg_fn which registers the callbacks * @note operations are not made directly but postponed by a scheduling the actions. * This is not really necessary for all operations (like start) but made for all @@ -691,8 +693,8 @@ clixon_process_operation(clicon_handle h, int sched = 0; /* If set, process action should be scheduled, register a timeout */ int isrunning = 0; int delay = 0; - - clicon_debug(CLIXON_DBG_DEFAULT, "%s name:%s op:%s", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s name:%s op:%s", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); if (_proc_entry_list == NULL) goto ok; if ((pe = _proc_entry_list) != NULL) @@ -705,7 +707,7 @@ clixon_process_operation(clicon_handle h, goto done; if (op == PROC_OP_START || op == PROC_OP_STOP || op == PROC_OP_RESTART){ pe->pe_operation = op; - clicon_debug(CLIXON_DBG_DEFAULT, "%s scheduling name: %s pid:%d op: %s", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s scheduling name: %s pid:%d op: %s", __FUNCTION__, name, pe->pe_pid, clicon_int2str(proc_operation_map, pe->pe_operation)); if (pe->pe_state==PROC_STATE_RUNNING && @@ -719,7 +721,7 @@ clixon_process_operation(clicon_handle h, kill(pe->pe_pid, SIGTERM); delay = 1; } - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), clicon_int2str(proc_operation_map, pe->pe_operation), @@ -730,7 +732,7 @@ clixon_process_operation(clicon_handle h, sched++;/* start: immediate stop/restart: not immediate: wait timeout */ } else{ - clicon_debug(CLIXON_DBG_DEFAULT, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); } break; /* hit break here */ } @@ -741,7 +743,7 @@ clixon_process_operation(clicon_handle h, ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; } @@ -750,8 +752,9 @@ clixon_process_operation(clicon_handle h, * @param[in] h clicon handle * @param[in] name Name of process * @param[out] cbret XML status string - * @retval -1 Error - * @retval 0 OK + * @retval 0 OK + * @retval -1 Error + */ int clixon_process_status(clicon_handle h, @@ -765,13 +768,13 @@ clixon_process_status(clicon_handle h, char timestr[28]; int match = 0; - clicon_debug(CLIXON_DBG_DEFAULT, "%s name:%s", __FUNCTION__, name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s name:%s", __FUNCTION__, name); if (_proc_entry_list != NULL){ pe = _proc_entry_list; do { if (strcmp(pe->pe_name, name) == 0){ - clicon_debug(CLIXON_DBG_DEFAULT, "%s found %s pid:%d", __FUNCTION__, name, pe->pe_pid); + clixon_debug(CLIXON_DBG_DEFAULT, "%s found %s pid:%d", __FUNCTION__, name, pe->pe_pid); /* Check if running */ run = 0; if (pe->pe_pid && proc_op_run(pe->pe_pid, &run) < 0) @@ -781,7 +784,7 @@ clixon_process_status(clicon_handle h, if (pe->pe_description) cprintf(cbret, "%s", CLIXON_LIB_NS, pe->pe_description); cprintf(cbret, "", CLIXON_LIB_NS); - /* The command may include any data, including XML (such as restconf -R + /* The command may include any data, including XML (such as restconf -R * command) and therefore needs explicit encoding */ for (i=0; ipe_argc-1; i++){ if (i) @@ -815,12 +818,15 @@ clixon_process_status(clicon_handle h, } retval = 0; done: - clicon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; } /*! Go through process list and start all processes that are enabled via config wrap function + * * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error * Commit rules should have done this, but there are some cases such as backend -s none mode * where commits are not made. */ @@ -832,7 +838,7 @@ clixon_process_start_all(clicon_handle h) proc_operation op; int sched = 0; /* If set, process action should be scheduled, register a timeout */ - clicon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (_proc_entry_list == NULL) goto ok; pe = _proc_entry_list; @@ -843,7 +849,7 @@ clixon_process_start_all(clicon_handle h) if (pe->pe_callback(h, pe, &op) < 0) goto done; if (op == PROC_OP_START){ - clicon_debug(CLIXON_DBG_DEFAULT, "%s name:%s start", __FUNCTION__, pe->pe_name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s name:%s start", __FUNCTION__, pe->pe_name); pe->pe_operation = op; sched++; /* Immediate dont delay for start */ } @@ -854,12 +860,15 @@ clixon_process_start_all(clicon_handle h) ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; } /*! Traverse all processes and check pending start/stop/restarts + * * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error * Typical cases where postponing process start/stop is necessary: * (1) at startup, if started before deamoninization, process will get as child of 1 * (2) edit changes or rpc restart especially of restconf where you may saw of your arm and terminate @@ -876,19 +885,19 @@ clixon_process_sched(int fd, int isrunning; /* Process is actually running */ int sched = 0; - clicon_debug(CLIXON_DBG_DEFAULT, "%s",__FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s",__FUNCTION__); if (_proc_entry_list == NULL) goto ok; pe = _proc_entry_list; do { - clicon_debug(CLIXON_DBG_DEFAULT, "%s name: %s pid:%d %s --op:%s-->", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s name: %s pid:%d %s --op:%s-->", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), clicon_int2str(proc_operation_map, pe->pe_operation)); /* Execute pending operations and not already exiting */ if (pe->pe_operation != PROC_OP_NONE){ switch (pe->pe_state){ case PROC_STATE_EXITING: switch (pe->pe_operation){ - case PROC_OP_STOP: + case PROC_OP_STOP: case PROC_OP_RESTART: /* Kill again */ isrunning = 0; if (proc_op_run(pe->pe_pid, &isrunning) < 0) @@ -916,7 +925,7 @@ clixon_process_sched(int fd, pe->pe_uid, pe->pe_gid, pe->pe_fdkeep, &pe->pe_pid) < 0) goto done; - clicon_debug(CLIXON_DBG_DEFAULT, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), @@ -944,7 +953,7 @@ clixon_process_sched(int fd, pe->pe_uid, pe->pe_gid, pe->pe_fdkeep, &pe->pe_pid) < 0) goto done; - clicon_debug(CLIXON_DBG_DEFAULT, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), @@ -968,7 +977,7 @@ clixon_process_sched(int fd, ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; } @@ -979,6 +988,8 @@ clixon_process_sched(int fd, * 2) A process is started, dont delay * @param[in] h Clixon handle * @param[in] delay If 0 dont add a delay, if 1 add a delay + * @retval 0 OK + * @retval -1 Error */ static int clixon_process_sched_register(clicon_handle h, @@ -988,7 +999,7 @@ clixon_process_sched_register(clicon_handle h, struct timeval t; struct timeval t1 = {0, 100000}; /* 100ms */ - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); gettimeofday(&t, NULL); if (delay) timeradd(&t, &t1, &t); @@ -996,14 +1007,18 @@ clixon_process_sched_register(clicon_handle h, goto done; retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); return retval; } /*! Go through processes and wait for child processes + * * Typically we know a child has been killed by SIGCHLD, but we do not know which process it is * Traverse all known processes and reap them, eg call waitpid() to avoid zombies. * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error + */ int clixon_process_waitpid(clicon_handle h) @@ -1013,12 +1028,12 @@ clixon_process_waitpid(clicon_handle h) int status = 0; pid_t wpid; - clicon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (_proc_entry_list == NULL) goto ok; if ((pe = _proc_entry_list) != NULL) do { - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s op:%s", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s op:%s", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), clicon_int2str(proc_operation_map, pe->pe_operation)); @@ -1026,15 +1041,15 @@ clixon_process_waitpid(clicon_handle h) && (pe->pe_state == PROC_STATE_RUNNING || pe->pe_state == PROC_STATE_EXITING) // && (pe->pe_operation == PROC_OP_STOP || pe->pe_operation == PROC_OP_RESTART) ){ - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s waitpid(%d)", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s waitpid(%d)", __FUNCTION__, pe->pe_name, pe->pe_pid); if ((wpid = waitpid(pe->pe_pid, &status, WNOHANG)) == pe->pe_pid){ - clicon_debug(CLIXON_DBG_DEFAULT, "%s waitpid(%d) waited", __FUNCTION__, pe->pe_pid); + clixon_debug(CLIXON_DBG_DEFAULT, "%s waitpid(%d) waited", __FUNCTION__, pe->pe_pid); pe->pe_exit_status = status; switch (pe->pe_operation){ case PROC_OP_NONE: /* Spontaneous / External termination */ case PROC_OP_STOP: - clicon_debug(CLIXON_DBG_DEFAULT, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), @@ -1053,7 +1068,7 @@ clixon_process_waitpid(clicon_handle h) &pe->pe_pid) < 0) goto done; gettimeofday(&pe->pe_starttime, NULL); - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s(%d) %s --%s--> %s", __FUNCTION__, pe->pe_name, pe->pe_pid, clicon_int2str(proc_state_map, pe->pe_state), clicon_int2str(proc_operation_map, pe->pe_operation), @@ -1069,7 +1084,7 @@ clixon_process_waitpid(clicon_handle h) break; /* pid is unique */ } else - clicon_debug(CLIXON_DBG_DEFAULT, "%s waitpid(%d) nomatch:%d", __FUNCTION__, + clixon_debug(CLIXON_DBG_DEFAULT, "%s waitpid(%d) nomatch:%d", __FUNCTION__, pe->pe_pid, wpid); } pe = NEXTQ(process_entry_t *, pe); @@ -1077,6 +1092,6 @@ clixon_process_waitpid(clicon_handle h) ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval; } diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 6f5f7816..3e5d404e 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -88,6 +88,7 @@ struct formatvec{ }; /*! Translate between int and string of tree formats + * * @see eum format_enum */ static struct formatvec _FORMATS[] = { @@ -164,7 +165,6 @@ clicon_msg_encode(uint32_t id, /* hdr */ msg->op_len = htonl(len); msg->op_id = htonl(id); - /* body */ va_start(args, format); vsnprintf(msg->op_body, xmllen, format, args); @@ -185,7 +185,7 @@ clicon_msg_encode(uint32_t id, * @retval -1 Error with clicon_err called. Includes parse error */ int -clicon_msg_decode(struct clicon_msg *msg, +clicon_msg_decode(struct clicon_msg *msg, yang_stmt *yspec, uint32_t *id, cxobj **xml, @@ -195,13 +195,13 @@ clicon_msg_decode(struct clicon_msg *msg, char *xmlstr; int ret; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); /* hdr */ if (id) *id = ntohl(msg->op_id); /* body */ xmlstr = msg->op_body; - // XXX clicon_debug(CLIXON_DBG_MSG, "Recv: %s", xmlstr); + // XXX clixon_debug(CLIXON_DBG_MSG, "Recv: %s", xmlstr); if ((ret = clixon_xml_parse_string(xmlstr, yspec?YB_RPC:YB_NONE, yspec, xml, xerr)) < 0) goto done; if (ret == 0) @@ -216,7 +216,7 @@ clicon_msg_decode(struct clicon_msg *msg, /*! Open local connection using unix domain sockets * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] sockpath Unix domain file path * @retval s Socket * @retval -1 Error @@ -237,11 +237,11 @@ clicon_connect_unix(clicon_handle h, addr.sun_family = AF_UNIX; strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path)-1); - clicon_debug(CLIXON_DBG_DETAIL, "%s: connecting to %s", __FUNCTION__, addr.sun_path); + 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. " - "Is user not member of group: \"%s\"?", + "Is user not member of group: \"%s\"?", sockpath, clicon_sock_group(h)); else clicon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath); @@ -267,9 +267,9 @@ atomicio_sig_handler(int arg) * @param[in] n Number of bytes to read/write, loop until done */ static ssize_t -atomicio(ssize_t (*fn) (int, void *, size_t), - int fd, - void *s0, +atomicio(ssize_t (*fn) (int, void *, size_t), + int fd, + void *s0, size_t n) { char *s = s0; @@ -307,6 +307,8 @@ atomicio(ssize_t (*fn) (int, void *, size_t), * @param[in] msg Byte stream * @param[in] len Length of byte stream * @param[in] file Calling file name + * @retval 0 OK + * @retval -1 Error */ static int msg_hex(int dbglevel, @@ -317,8 +319,8 @@ msg_hex(int dbglevel, int retval = -1; cbuf *cb = NULL; int i; - - if ((dbglevel & clicon_debug_get()) == 0) /* compare debug level with global variable */ + + 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"); @@ -328,7 +330,7 @@ msg_hex(int dbglevel, for (i=0; iop_len)); + clixon_debug(CLIXON_DBG_DETAIL, "%s: send msg len=%d", __FUNCTION__, ntohl(msg->op_len)); if (descr) - clicon_debug(CLIXON_DBG_MSG, "Send [%s]: %s", descr, msg->op_body); + clixon_debug(CLIXON_DBG_MSG, "Send [%s]: %s", descr, msg->op_body); else{ - clicon_debug(CLIXON_DBG_MSG, "Send: %s", msg->op_body); + clixon_debug(CLIXON_DBG_MSG, "Send: %s", msg->op_body); } msg_hex(CLIXON_DBG_EXTRA, (char*)msg, ntohl(msg->op_len), __FUNCTION__); - if (atomicio((ssize_t (*)(int, void *, size_t))write, + if (atomicio((ssize_t (*)(int, void *, size_t))write, s, msg, ntohl(msg->op_len)) < 0){ e = errno; clicon_err(OE_CFG, e, "atomicio"); @@ -408,7 +410,7 @@ clicon_msg_rcv(int s, int intr, struct clicon_msg **msg, int *eof) -{ +{ int retval = -1; struct clicon_msg hdr; int hlen; @@ -416,13 +418,13 @@ clicon_msg_rcv(int s, sigfn_t oldhandler; uint32_t mlen; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); *eof = 0; if (intr){ clicon_signal_unblock(SIGINT); set_signal_flags(SIGINT, 0, atomicio_sig_handler, &oldhandler); } - if ((hlen = atomicio(read, s, &hdr, sizeof(hdr))) < 0){ + if ((hlen = atomicio(read, s, &hdr, sizeof(hdr))) < 0){ if (intr && _atomicio_sig) ; else @@ -439,9 +441,9 @@ clicon_msg_rcv(int s, goto done; } mlen = ntohl(hdr.op_len); - clicon_debug(CLIXON_DBG_EXTRA, "op-len:%u op-id:%u", + clixon_debug(CLIXON_DBG_EXTRA, "op-len:%u op-id:%u", mlen, ntohl(hdr.op_id)); - clicon_debug(CLIXON_DBG_DETAIL, "%s: rcv msg len=%d", + 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); @@ -453,7 +455,7 @@ clicon_msg_rcv(int s, goto done; } memcpy(*msg, &hdr, hlen); - if ((len2 = atomicio(read, s, (*msg)->op_body, mlen - sizeof(hdr))) < 0){ + if ((len2 = atomicio(read, s, (*msg)->op_body, mlen - sizeof(hdr))) < 0){ clicon_err(OE_PROTO, errno, "read"); goto done; } @@ -470,13 +472,13 @@ clicon_msg_rcv(int s, goto ok; } if (descr) - clicon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, (*msg)->op_body); + clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, (*msg)->op_body); else - clicon_debug(CLIXON_DBG_MSG, "Recv: %s", (*msg)->op_body); + clixon_debug(CLIXON_DBG_MSG, "Recv: %s", (*msg)->op_body); ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); if (intr){ set_signal(SIGINT, oldhandler, NULL); clicon_signal_block(SIGINT); @@ -509,7 +511,7 @@ clicon_msg_rcv1(int s, int xml_state = 0; int poll; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); *eof = 0; memset(buf, 0, sizeof(buf)); while (1){ @@ -547,12 +549,12 @@ clicon_msg_rcv1(int s, } /* while */ ok: if (descr) - clicon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, cbuf_get(cb)); + clixon_debug(CLIXON_DBG_MSG, "Recv [%s]: %s", descr, cbuf_get(cb)); else - clicon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cb)); + clixon_debug(CLIXON_DBG_MSG, "Recv: %s", cbuf_get(cb)); retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s done", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s done", __FUNCTION__); return retval; } @@ -566,18 +568,18 @@ clicon_msg_rcv1(int s, * @see clicon_msg_send using internal IPC header */ int -clicon_msg_send1(int s, +clicon_msg_send1(int s, const char *descr, cbuf *cb) -{ +{ int retval = -1; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (descr) - clicon_debug(CLIXON_DBG_MSG, "Send [%s]: %s", descr, cbuf_get(cb)); + clixon_debug(CLIXON_DBG_MSG, "Send [%s]: %s", descr, cbuf_get(cb)); else - clicon_debug(CLIXON_DBG_MSG, "Send: %s", cbuf_get(cb)); - if (atomicio((ssize_t (*)(int, void *, size_t))write, + 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)); @@ -590,7 +592,7 @@ clicon_msg_send1(int s, /*! Connect to server, send a clicon_msg message and wait for result using unix socket * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] msg Internal msg data structure. It has fixed header and variable body. * @param[in] sockpath Unix domain file path * @param[out] retdata Returned data as string netconf xml tree. @@ -608,7 +610,7 @@ clicon_rpc_connect_unix(clicon_handle h, int s = -1; struct stat sb = {0,}; - clicon_debug(CLIXON_DBG_DETAIL, "Send msg on %s", sockpath); + clixon_debug(CLIXON_DBG_DETAIL, "Send msg on %s", sockpath); if (sock0 == NULL){ clicon_err(OE_NETCONF, EINVAL, "sock0 expected"); goto done; @@ -632,7 +634,7 @@ clicon_rpc_connect_unix(clicon_handle h, /*! Connect to server, send a clicon_msg message and wait for result using an inet socket * - * @param[in] h Clicon handle (not used) + * @param[in] h Clixon handle (not used) * @param[in] dst IPv4 address * @param[in] port TCP port * @param[out] retdata Returned data as string netconf xml tree. @@ -651,7 +653,7 @@ clicon_rpc_connect_inet(clicon_handle h, int s = -1; struct sockaddr_in addr; - clicon_debug(CLIXON_DBG_DETAIL, "Send msg to %s:%hu", dst, port); + clixon_debug(CLIXON_DBG_DETAIL, "Send msg to %s:%hu", dst, port); if (sock0 == NULL){ clicon_err(OE_NETCONF, EINVAL, "sock0 expected"); goto done; @@ -661,7 +663,6 @@ clicon_rpc_connect_inet(clicon_handle h, addr.sin_port = htons(port); if (inet_pton(addr.sin_family, dst, &addr.sin_addr) != 1) 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"); @@ -697,7 +698,7 @@ clicon_rpc_connect_inet(clicon_handle h, int clicon_rpc(int sock, const char *descr, - struct clicon_msg *msg, + struct clicon_msg *msg, char **ret, int *eof) { @@ -705,7 +706,7 @@ clicon_rpc(int sock, struct clicon_msg *reply = NULL; char *data = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (clicon_msg_send(sock, descr, msg) < 0) goto done; if (clicon_msg_rcv(sock, descr, 0, &reply, eof) < 0) @@ -721,7 +722,7 @@ clicon_rpc(int sock, ok: retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); if (reply) free(reply); return retval; @@ -748,7 +749,7 @@ clicon_rpc1(int sock, { int retval = -1; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (netconf_framing_preamble(NETCONF_SSH_CHUNKED, msg) < 0) goto done; if (netconf_framing_postamble(NETCONF_SSH_CHUNKED, msg) < 0) @@ -759,7 +760,7 @@ clicon_rpc1(int sock, goto done; retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); return retval; } @@ -772,10 +773,10 @@ clicon_rpc1(int sock, * @retval 0 OK * @retval -1 Error */ -int -send_msg_reply(int s, +int +send_msg_reply(int s, const char *descr, - char *data, + char *data, uint32_t datalen) { int retval = -1; @@ -809,8 +810,8 @@ send_msg_reply(int s, * @see send_msg_notify_xml */ static int -send_msg_notify(int s, - const char *descr, +send_msg_notify(int s, + const char *descr, char *event) { int retval = -1; @@ -829,7 +830,7 @@ send_msg_notify(int s, /*! Send a clicon_msg NOTIFY message asynchronously to client * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] s Socket to communicate with client * @param[in] descr Description of peer for logging * @param[in] xev Event as XML @@ -839,7 +840,7 @@ send_msg_notify(int s, */ int send_msg_notify_xml(clicon_handle h, - int s, + int s, const char *descr, cxobj *xev) { @@ -856,7 +857,7 @@ send_msg_notify_xml(clicon_handle h, goto done; retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval); if (cb) cbuf_free(cb); return retval; @@ -881,8 +882,8 @@ send_msg_notify_xml(clicon_handle h, * @endcode */ int -detect_endtag(char *tag, - char ch, +detect_endtag(char *tag, + char ch, int *state) { int retval = 0; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index d8583123..39423535 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -136,7 +136,7 @@ clicon_rpc_connect(clicon_handle h, done: return retval; } - + /*! Connect to backend or use cached socket and send RPC * * @param[in] h Clixon handle @@ -150,7 +150,7 @@ clicon_rpc_connect(clicon_handle h, */ static int clicon_rpc_msg_once(clicon_handle h, - struct clicon_msg *msg, + struct clicon_msg *msg, int cache, char **retdata, int *eof, @@ -158,7 +158,7 @@ clicon_rpc_msg_once(clicon_handle h, { int retval = -1; int s; - + if (cache){ if ((s = clicon_client_socket_get(h)) < 0){ if (clicon_rpc_connect(h, &s) < 0) @@ -195,8 +195,8 @@ clicon_rpc_msg_once(clicon_handle h, * @see clicon_rpc_close_session */ int -clicon_rpc_msg(clicon_handle h, - struct clicon_msg *msg, +clicon_rpc_msg(clicon_handle h, + struct clicon_msg *msg, cxobj **xret0) { int retval = -1; @@ -205,7 +205,7 @@ clicon_rpc_msg(clicon_handle h, int s = -1; int eof = 0; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); #ifdef RPC_USERNAME_ASSERT assert(strstr(msg->op_body, "username")!=NULL); /* XXX */ #endif @@ -225,7 +225,6 @@ 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."); goto done; } @@ -253,7 +252,7 @@ clicon_rpc_msg(clicon_handle h, } retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval); if (retdata) free(retdata); if (xret) @@ -273,8 +272,8 @@ 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, - struct clicon_msg *msg, +clicon_rpc_msg_persistent(clicon_handle h, + struct clicon_msg *msg, cxobj **xret0, int *sock0) { @@ -291,7 +290,7 @@ clicon_rpc_msg_persistent(clicon_handle h, #ifdef RPC_USERNAME_ASSERT assert(strstr(msg->op_body, "username")!=NULL); /* XXX */ #endif - clicon_debug(1, "%s request:%s", __FUNCTION__, msg->op_body); + clixon_debug(CLIXON_DBG_DEFAULT, "%s request:%s", __FUNCTION__, msg->op_body); /* Create a socket and connect to it, either UNIX, IPv4 or IPv6 per config options */ if (clicon_rpc_msg_once(h, msg, 0, &retdata, &eof, &s) < 0) goto done; @@ -306,7 +305,7 @@ clicon_rpc_msg_persistent(clicon_handle h, clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); goto done; } - clicon_debug(1, "%s retdata:%s", __FUNCTION__, retdata); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retdata:%s", __FUNCTION__, retdata); if (retdata){ /* Cannot populate xret here because need to know RPC name (eg "lock") in order to associate yang @@ -351,11 +350,11 @@ session_id_check(clicon_handle h, { int retval = -1; uint32_t id; - + if (clicon_session_id_get(h, &id) < 0){ /* Not set yet */ if (clicon_hello_req(h, NULL, NULL, &id) < 0) goto done; - clicon_session_id_set(h, id); + clicon_session_id_set(h, id); } retval = 0; *session_id = id; @@ -382,7 +381,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(clicon_handle h, char *xmlstr, cxobj **xret, int *sp) @@ -428,7 +427,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(clicon_handle h, cxobj *xml, cxobj **xret, int *sp) @@ -459,7 +458,7 @@ clicon_rpc_netconf_xml(clicon_handle h, xml_find_type(xreply, NULL, "rpc-error", CX_ELMNT) == NULL){ yspec = clicon_dbspec_yang(h); /* Here use rpc name to bind to yang */ - if ((ret = xml_bind_yang_rpc_reply(h, xreply, rpcname, yspec, &xerr)) < 0) + if ((ret = xml_bind_yang_rpc_reply(h, xreply, rpcname, yspec, &xerr)) < 0) goto done; if (ret == 0){ /* Replace reply with error */ @@ -513,9 +512,9 @@ 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(clicon_handle h, char *username, // XXX: why is this only rpc call with username parameter? - char *db, + char *db, char *xpath, cvec *nsc, char *defaults, @@ -525,13 +524,13 @@ clicon_rpc_get_config(clicon_handle h, struct clicon_msg *msg = NULL; cbuf *cb = NULL; cxobj *xret = NULL; - cxobj *xerr = NULL; + cxobj *xerr = NULL; cxobj *xd = NULL; uint32_t session_id; int ret; yang_stmt *yspec; cvec *nscd = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -628,14 +627,14 @@ clicon_rpc_get_config(clicon_handle h, * @retval -1 Error and logged to syslog * @note xml arg need to have as top element * @code - * if (clicon_rpc_edit_config(h, "running", OP_MERGE, + * if (clicon_rpc_edit_config(h, "running", OP_MERGE, * "4") < 0) * err; * @endcode */ int -clicon_rpc_edit_config(clicon_handle h, - char *db, +clicon_rpc_edit_config(clicon_handle h, + char *db, enum operation_type op, char *xmlstr) { @@ -646,7 +645,7 @@ clicon_rpc_edit_config(clicon_handle h, cxobj *xerr; char *username; uint32_t session_id; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -661,7 +660,7 @@ clicon_rpc_edit_config(clicon_handle h, } cprintf(cb, " %s", NETCONF_MESSAGE_ID_ATTR); /* XXX: use incrementing sequence */ cprintf(cb, "><%s/>", db); - cprintf(cb, "%s", + cprintf(cb, "%s", xml_operation2str(op)); if (xmlstr) cprintf(cb, "%s", xmlstr); @@ -700,8 +699,8 @@ clicon_rpc_edit_config(clicon_handle h, * @endcode */ int -clicon_rpc_copy_config(clicon_handle h, - char *db1, +clicon_rpc_copy_config(clicon_handle h, + char *db1, char *db2) { int retval = -1; @@ -710,7 +709,7 @@ clicon_rpc_copy_config(clicon_handle h, cxobj *xerr; char *username; uint32_t session_id; - cbuf *cb = NULL; + cbuf *cb = NULL; if (session_id_check(h, &session_id) < 0) goto done; @@ -759,7 +758,7 @@ clicon_rpc_copy_config(clicon_handle h, * @endcode */ int -clicon_rpc_delete_config(clicon_handle h, +clicon_rpc_delete_config(clicon_handle h, char *db) { int retval = -1; @@ -769,7 +768,7 @@ clicon_rpc_delete_config(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -813,7 +812,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(clicon_handle h, char *db) { int retval = -1; @@ -823,7 +822,7 @@ clicon_rpc_lock(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -867,7 +866,7 @@ clicon_rpc_lock(clicon_handle h, * @retval -1 Error and logged to syslog */ int -clicon_rpc_unlock(clicon_handle h, +clicon_rpc_unlock(clicon_handle h, char *db) { int retval = -1; @@ -877,7 +876,7 @@ clicon_rpc_unlock(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -915,7 +914,7 @@ clicon_rpc_unlock(clicon_handle h, /*! Get database configuration and state data * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xpath XPath in a filter stmt (or NULL/"" for no filter) * @param[in] namespace Namespace associated w xpath * @param[in] nsc Namespace context for filter @@ -963,7 +962,7 @@ clicon_rpc_get(clicon_handle h, /*! Get database configuration and state data (please use instead of clicon_rpc_get) * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xpath XPath in a filter stmt (or NULL/"" for no filter) * @param[in] namespace Namespace associated w xpath * @param[in] nsc Namespace context for filter @@ -1018,8 +1017,8 @@ clicon_rpc_get2(clicon_handle h, int ret; yang_stmt *yspec; cvec *nscd = NULL; - - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -1032,12 +1031,12 @@ clicon_rpc_get2(clicon_handle h, cprintf(cb, " %s:username=\"%s\"", CLIXON_LIB_PREFIX, username); cprintf(cb, " xmlns:%s=\"%s\"", CLIXON_LIB_PREFIX, CLIXON_LIB_NS); } - cprintf(cb, " message-id=\"%d\"", netconf_message_id_next(h)); + cprintf(cb, " message-id=\"%d\"", netconf_message_id_next(h)); cprintf(cb, "> */ @@ -1105,7 +1104,7 @@ clicon_rpc_get2(clicon_handle h, } retval = 0; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, retval); if (nscd) cvec_free(nscd); if (cb) @@ -1121,7 +1120,7 @@ clicon_rpc_get2(clicon_handle h, /*! Get database configuration and state data collection * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] xpath To identify a list/leaf-list * @param[in] namespace Namespace associated w xpath * @param[in] nsc Namespace context for filter @@ -1142,7 +1141,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(clicon_handle h, char *datastore, char *xpath, cvec *nsc, /* namespace context for xpath */ @@ -1167,7 +1166,7 @@ clicon_rpc_get_pageable_list(clicon_handle h, int ret; yang_stmt *yspec; cvec *nscd = NULL; - + if (datastore == NULL){ clicon_err(OE_XML, EINVAL, "datastore not given"); goto done; @@ -1190,13 +1189,13 @@ clicon_rpc_get_pageable_list(clicon_handle h, /* Clixon extension, content=all,config, or nonconfig */ if ((int)content != -1) cprintf(cb, " %s:content=\"%s\" xmlns:%s=\"%s\"", - CLIXON_LIB_PREFIX, + CLIXON_LIB_PREFIX, netconf_content_int2str(content), CLIXON_LIB_PREFIX, CLIXON_LIB_NS); /* Clixon extension, depth= */ if (depth != -1) cprintf(cb, " %s:depth=\"%d\" xmlns:%s=\"%s\"", - CLIXON_LIB_PREFIX, + CLIXON_LIB_PREFIX, depth, CLIXON_LIB_PREFIX, CLIXON_LIB_NS); /* declare lp prefix in get, so sub-elements dont need to */ @@ -1362,7 +1361,7 @@ clicon_rpc_kill_session(clicon_handle h, char *username; uint32_t my_session_id; /* Not the one to kill */ cbuf *cb = NULL; - + if (session_id_check(h, &my_session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -1408,7 +1407,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(clicon_handle h, char *db) { int retval = -1; @@ -1418,7 +1417,7 @@ clicon_rpc_validate(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -1442,7 +1441,7 @@ clicon_rpc_validate(clicon_handle h, if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){ clixon_netconf_error(xerr, CLIXON_ERRSTR_VALIDATE_FAILED, NULL); retval = 0; - goto done; + goto done; } retval = 1; done: @@ -1584,7 +1583,7 @@ clicon_rpc_discard_changes(clicon_handle h) char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -1622,7 +1621,7 @@ clicon_rpc_discard_changes(clicon_handle h) /*! Create a new notification subscription * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param{in] stream name of notificatio/log stream (CLICON is predefined) * @param{in] filter message filter, eg xpath for xml notifications * @param[out] s0 socket returned where notification mesages will appear @@ -1632,8 +1631,8 @@ clicon_rpc_discard_changes(clicon_handle h) */ int clicon_rpc_create_subscription(clicon_handle h, - char *stream, - char *filter, + char *stream, + char *filter, int *s0) { int retval = -1; @@ -1643,7 +1642,7 @@ clicon_rpc_create_subscription(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -1693,7 +1692,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(clicon_handle h, int level) { int retval = -1; @@ -1756,7 +1755,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(clicon_handle h, int level) { int retval = -1; @@ -1766,7 +1765,7 @@ clicon_rpc_restconf_debug(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ @@ -1890,7 +1889,7 @@ clicon_hello_req(clicon_handle h, } b = xml_body(x); if ((ret = parse_uint32(b, id, NULL)) <= 0){ - clicon_err(OE_XML, errno, "parse_uint32"); + clicon_err(OE_XML, errno, "parse_uint32"); goto done; } retval = 0; @@ -1912,7 +1911,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(clicon_handle h, char *plugin) { int retval = -1; @@ -1922,7 +1921,7 @@ clicon_rpc_restart_plugin(clicon_handle h, char *username; uint32_t session_id; cbuf *cb = NULL; - + if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ diff --git a/lib/src/clixon_regex.c b/lib/src/clixon_regex.c index db332f92..fd56a400 100644 --- a/lib/src/clixon_regex.c +++ b/lib/src/clixon_regex.c @@ -205,6 +205,7 @@ fail: } /*! Transform from XSD regex to posix ERE + * * The usecase is that Yang (RFC7950) supports XSD regular expressions but * CLIgen supports POSIX ERE * POSIX ERE regexps according to man regex(3). @@ -242,7 +243,7 @@ regexp_xsd2posix(char *xsd, int esc; int minus = 0; size_t len; - + if ((cb = cbuf_new()) == NULL){ clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; @@ -320,10 +321,10 @@ regexp_xsd2posix(char *xsd, break; case 'w': /* word */ //cprintf(cb, "[0-9a-zA-Z_\\\\-]") - cprintf(cb, "[[:alnum:]|_]"); + cprintf(cb, "[[:alnum:]|_]"); break; case 'W': /* inverse of \w */ - cprintf(cb, "[^[[:alnum:]|_]]"); + cprintf(cb, "[^[[:alnum:]|_]]"); break; case 'u': { int n; @@ -369,7 +370,8 @@ regexp_xsd2posix(char *xsd, /*-------------------------- Generic API functions ------------------------*/ /*! Compilation of regular expression / pattern - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] regexp Regular expression string in XSD regex format * @param[out] recomp Compiled regular expression (malloc:d, should be freed) * @retval 1 OK @@ -408,9 +410,12 @@ regex_compile(clicon_handle h, } /*! Execution of (pre-compiled) regular expression / pattern - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] recomp Compiled regular expression * @param[in] string Content string to match + * @retval 0 OK + * @retval -1 Error */ int regex_exec(clicon_handle h, @@ -437,8 +442,11 @@ regex_exec(clicon_handle h, } /*! Free of (pre-compiled) regular expression / pattern - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] recomp Compiled regular expression + * @retval 0 OK + * @retval -1 Error */ int regex_free(clicon_handle h, diff --git a/lib/src/clixon_sig.c b/lib/src/clixon_sig.c index 8580bb51..85a6b77f 100644 --- a/lib/src/clixon_sig.c +++ b/lib/src/clixon_sig.c @@ -57,13 +57,14 @@ #include "clixon_sig.h" /*! Set a signal handler. + * * @param[in] signo Signal number * @param[in] handler Function to call when signal occurs * @param[out] oldhandler Pointer to old handler */ int -set_signal(int signo, - void (*handler)(int), +set_signal(int signo, + void (*handler)(int), void (**oldhandler)(int)) { return set_signal_flags(signo, @@ -76,15 +77,16 @@ set_signal(int signo, } /*! Set a signal handler, but without SA_RESTART + * * @param[in] signo Signal number * @param[in] flags Flags (to sigaction) * @param[in] handler Function to call when signal occurs * @param[out] oldhandler Pointer to old handler */ int -set_signal_flags(int signo, +set_signal_flags(int signo, int flags, - void (*handler)(int), + void (*handler)(int), void (**oldhandler)(int)) { #if defined(HAVE_SIGACTION) @@ -106,39 +108,37 @@ set_signal_flags(int signo, } /*! Block signal. + * * @param[in] sig Signal number to block, If 0, block all signals */ void clicon_signal_block(int sig) { - sigset_t - set; + sigset_t set; - sigemptyset(&set); - if (sig) - sigaddset(&set, sig); - else - sigfillset(&set); - - sigprocmask(SIG_BLOCK, &set, NULL); + sigemptyset(&set); + if (sig) + sigaddset(&set, sig); + else + sigfillset(&set); + sigprocmask(SIG_BLOCK, &set, NULL); } /*! Unblock signal. + * * @param[in] sig Signal number to unblock. If 0, unblock all signals */ void clicon_signal_unblock(int sig) { - sigset_t - set; + sigset_t set; - sigemptyset(&set); - if (sig) - sigaddset(&set, sig); - else - sigfillset(&set); - - sigprocmask(SIG_UNBLOCK, &set, NULL); + sigemptyset(&set); + if (sig) + sigaddset(&set, sig); + else + sigfillset(&set); + sigprocmask(SIG_UNBLOCK, &set, NULL); } /*! Save complete signal context @@ -149,7 +149,7 @@ clixon_signal_save(sigset_t *sigset, { int retval = -1; int i; - + if (sigprocmask(0, NULL, sigset) < 0){ clicon_err(OE_UNIX, errno, "sigprocmask"); goto done; @@ -167,7 +167,9 @@ clixon_signal_save(sigset_t *sigset, /*! Restore complete signal context * - * Note: sigaction may not restore SIGKILL or SIGSTOP, which cannot be caught or ignored. + * @retval 0 OK + * @retval -1 Error + * @note: sigaction may not restore SIGKILL or SIGSTOP, which cannot be caught or ignored. */ int clixon_signal_restore(sigset_t *sigset, @@ -175,7 +177,7 @@ clixon_signal_restore(sigset_t *sigset, { int retval = -1; int i; - + if (sigprocmask(SIG_SETMASK, sigset, NULL) < 0){ clicon_err(OE_UNIX, errno, "sigprocmask"); goto done; @@ -197,8 +199,7 @@ clixon_signal_restore(sigset_t *sigset, * * @param[in] pidfile Name of pidfile * @param[out] pid Process id of (eventual) existing daemon process - * @retval 0 OK. if pid > 0 old process exists w that pid - * @retval -1 Error, and clicon_err() called + * @retval 0 OK. if pid > 0 old process exists w that pid */ int pidfile_get_fd(FILE *f, @@ -207,7 +208,7 @@ pidfile_get_fd(FILE *f, char *ptr; char buf[32]; pid_t pid; - + *pid0 = 0; ptr = fgets(buf, sizeof(buf), f); if (ptr != NULL && (pid = atoi(ptr)) > 1) { @@ -224,10 +225,9 @@ pidfile_get_fd(FILE *f, * @param[in] pidfile Name of pidfile * @param[out] pid Process id of (eventual) existing daemon process * @retval 0 OK. if pid > 0 old process exists w that pid - * @retval -1 Error, and clicon_err() called */ int -pidfile_get(char *pidfile, +pidfile_get(char *pidfile, pid_t *pid) { FILE *f; @@ -245,7 +245,7 @@ pidfile_get(char *pidfile, * * @param[in] pid Process id * @retval 0 Killed OK - * @retval -1 Could not kill. + * @retval -1 Could not kill. * Maybe should not belong to pidfile code,.. */ int @@ -274,13 +274,15 @@ pidfile_zapold(pid_t pid) /*! Write a pid-file * - * @param[in] pidfile Name of pidfile + * @param[in] pidfile Name of pidfile + * @retval 0 OK + * @retval -1 Error */ int pidfile_write(char *pidfile) { - FILE *f = NULL; int retval = -1; + FILE *f = NULL; /* Here, there should be no old agent and no pidfile */ if ((f = fopen(pidfile, "w")) == NULL){ @@ -289,12 +291,12 @@ pidfile_write(char *pidfile) else clicon_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); goto done; } - clicon_debug(1, "Opened pidfile %s with pid %d", pidfile, getpid()); + clixon_debug(CLIXON_DBG_DEFAULT, "Opened pidfile %s with pid %d", pidfile, getpid()); retval = 0; done: if (f != NULL) diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c index 62668da7..2ec84080 100644 --- a/lib/src/clixon_stream.c +++ b/lib/src/clixon_stream.c @@ -92,7 +92,7 @@ /*! Find an event notification stream given name * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name Name of stream * @retval es Event notification stream structure * @retval NULL Not found @@ -116,18 +116,20 @@ stream_find(clicon_handle h, /*! Add notification event stream * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] name Name of stream * @param[in] description Description of stream * @param[in] replay_enabled Set if replay possible in stream * @param[in] retention For replay buffer how much relative to save + * @retval 0 OK + * @retval -1 Error */ int stream_add(clicon_handle h, - const char *name, + const char *name, const char *description, const int replay_enabled, - struct timeval *retention) + struct timeval *retention) { int retval = -1; event_stream_t *es; @@ -159,8 +161,9 @@ stream_add(clicon_handle h, /*! Delete complete notification event stream list (not just single stream) * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] force Force deletion of + * @retval 0 OK */ int stream_delete_all(clicon_handle h, @@ -170,7 +173,7 @@ stream_delete_all(clicon_handle h, struct stream_subscription *ss; event_stream_t *es; event_stream_t *head = clicon_stream(h); - + while ((es = clicon_stream(h)) != NULL){ DELQ(es, head, event_stream_t *); clicon_stream_set(h, head); @@ -193,12 +196,12 @@ stream_delete_all(clicon_handle h, /*! Return stream definition state in XML supporting RFC 8040 and RFC5277 * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] access If set, include access/location * @param[out] cb Output buffer containing XML on exit * @retval 0 OK * @retval -1 Error - */ + */ int stream_get_xml(clicon_handle h, int access, @@ -222,7 +225,7 @@ stream_get_xml(clicon_handle h, cprintf(cb, "xml"); url_prefix = clicon_option_str(h, "CLICON_STREAM_URL"); stream_path = clicon_option_str(h, "CLICON_STREAM_PATH"); - cprintf(cb, "%s/%s/%s", + cprintf(cb, "%s/%s/%s", url_prefix, stream_path, es->es_name); cprintf(cb, ""); } @@ -237,7 +240,9 @@ stream_get_xml(clicon_handle h, /*! Check all stream subscription stop timers, set up new timer * * @param[in] fd No-op - * @param[in] arg Clicon handle + * @param[in] arg Clixon handle + * @retval 0 OK + * @retval -1 Error * @note format is given by clixon_event_reg_timeout callback function (fd not needed) */ int @@ -255,8 +260,8 @@ stream_timer_setup(int fd, struct stream_subscription *ss1; struct stream_replay *r; struct stream_replay *r1; - - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); /* Go thru callbacks and see if any have timed out, if so remove them * Could also be done by a separate timer. */ @@ -313,20 +318,9 @@ stream_timer_setup(int fd, return retval; } -#ifdef NYI -/*! Delete single notification event stream - * XXX notused - */ -int -stream_del() -{ - return 0; -} -#endif - /*! Add an event notification callback to a stream given a callback function * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] stream Name of stream * @param[in] xpath Filter selector - xpath * @param[in] startime If set, Make a replay @@ -348,7 +342,7 @@ stream_ss_add(clicon_handle h, event_stream_t *es; struct stream_subscription *ss = NULL; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((es = stream_find(h, stream)) == NULL){ clicon_err(OE_CFG, ENOENT, "Stream %s not found", stream); goto done; @@ -382,7 +376,7 @@ stream_ss_add(clicon_handle h, /*! Delete event stream subscription to a stream given a callback and arg * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] stream Name of stream or NULL for all streams * @param[in] fn Callback when event occurs * @param[in] arg Argument to use with callback. Also handle when deleting @@ -395,7 +389,7 @@ stream_ss_rm(clicon_handle h, struct stream_subscription *ss, int force) { - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); DELQ(ss, es->es_subscription, struct stream_subscription *); /* Remove from upper layers - close socket etc. */ (*ss->ss_fn)(h, 1, NULL, ss->ss_arg); @@ -406,7 +400,7 @@ stream_ss_rm(clicon_handle h, free(ss->ss_xpath); free(ss); } - clicon_debug(1, "%s retval: 0", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: 0", __FUNCTION__); return 0; } @@ -436,9 +430,11 @@ stream_ss_find(event_stream_t *es, /*! Remove stream subscription identified with fn and arg in all streams * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] fn Stream callback * @param[in] arg Argument - typically unique client handle + * @retval 0 OK + * @retval -1 Error * @see stream_ss_delete For single stream */ int @@ -458,7 +454,7 @@ stream_ss_delete_all(clicon_handle h, } es = NEXTQ(struct event_stream *, es); } while (es && es != clicon_stream(h)); - } + } retval = 0; done: return retval; @@ -466,6 +462,10 @@ stream_ss_delete_all(clicon_handle h, /*! Delete a single stream * + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error + * @see stream_ss_delete_all (merge with this?) */ int @@ -487,7 +487,7 @@ stream_ss_delete(clicon_handle h, } es = NEXTQ(struct event_stream *, es); } while (es && es != clicon_stream(h)); - } + } retval = 0; done: return retval; @@ -495,7 +495,7 @@ stream_ss_delete(clicon_handle h, /*! Stream notify event and distribute to all registered callbacks * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] stream Name of event stream. CLICON is predefined as LOG stream * @param[in] tv Timestamp. Dont notify if subscription has stoptimees_subscription) != NULL) do { @@ -542,7 +542,7 @@ stream_notify1(clicon_handle h, /*! Stream notify event and distribute to all registered callbacks * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @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 @@ -554,8 +554,8 @@ stream_notify1(clicon_handle h, * @see stream_notify1 Internal */ int -stream_notify(clicon_handle h, - char *stream, +stream_notify(clicon_handle h, + char *stream, const char *event, ...) { int retval = -1; @@ -569,7 +569,7 @@ stream_notify(clicon_handle h, struct timeval tv; event_stream_t *es; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if ((es = stream_find(h, stream)) == NULL) goto ok; va_start(args, event); @@ -624,7 +624,7 @@ stream_notify(clicon_handle h, /*! Backward compatible function * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @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 @@ -632,8 +632,8 @@ stream_notify(clicon_handle h, * @see stream_notify Should be merged with this */ int -stream_notify_xml(clicon_handle h, - char *stream, +stream_notify_xml(clicon_handle h, + char *stream, cxobj *xml) { int retval = -1; @@ -646,7 +646,7 @@ stream_notify_xml(clicon_handle h, struct timeval tv; event_stream_t *es; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if ((es = stream_find(h, stream)) == NULL) goto ok; if ((yspec = clicon_dbspec_yang(h)) == NULL){ @@ -763,6 +763,8 @@ stream_replay_notify(clicon_handle h, * @param[in] es Stream * @param[in] tv Timestamp * @param[in] xv XML + * @retval 0 OK + * @retval -1 Error */ int stream_replay_add(event_stream_t *es, @@ -799,6 +801,8 @@ struct replay_arg{ * * @param[in] fd Ignore * @param[in] arg tmp struct including clicon handle, stream and subscription + * @retval 0 OK + * @retval -1 Error */ static int stream_replay_cb(int fd, @@ -808,7 +812,7 @@ stream_replay_cb(int fd, struct replay_arg *ra= (struct replay_arg*)arg; event_stream_t *es; struct stream_subscription *ss; - + if (ra == NULL) goto ok; if (ra->ra_stream == NULL) @@ -836,6 +840,8 @@ stream_replay_cb(int fd, * @param[in] stream Name of stream * @param[in] fn Stream callback * @param[in] arg Argument - typically unique client handle + * @retval 0 OK + * @retval -1 Error */ int stream_replay_trigger(clicon_handle h, @@ -843,8 +849,8 @@ stream_replay_trigger(clicon_handle h, stream_fn_t fn, void *arg) { - int retval = -1; - struct timeval now; + int retval = -1; + struct timeval now; struct replay_arg *ra; if ((ra = malloc(sizeof(*ra))) == NULL){ @@ -890,10 +896,10 @@ struct curlbuf{ * realloc. Therefore, we append new data to the userdata buffer. */ static size_t -curl_get_cb(void *ptr, +curl_get_cb(void *ptr, size_t size, size_t nmemb, - void *userdata) + void *userdata) { struct curlbuf *buf = (struct curlbuf *)userdata; int len; @@ -917,8 +923,8 @@ curl_get_cb(void *ptr, * @see same function (url_post) in grideye_curl.c */ static int -url_post(char *url, - char *postfields, +url_post(char *url, + char *postfields, char **getdata) { int retval = -1; @@ -928,15 +934,15 @@ url_post(char *url, CURLcode errcode; /* Try it with curl -X PUT -d '*/ - clicon_debug(1, "%s: curl -X POST -d '%s' %s", + clixon_debug(CLIXON_DBG_DEFAULT, "%s: curl -X POST -d '%s' %s", __FUNCTION__, postfields, url); /* Set up curl for doing the communication with the controller */ if ((curl = curl_easy_init()) == NULL) { - clicon_debug(1, "curl_easy_init"); + clixon_debug(CLIXON_DBG_DEFAULT, "curl_easy_init"); goto done; } if ((err = malloc(CURL_ERROR_SIZE)) == NULL) { - clicon_debug(1, "%s: malloc", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s: malloc", __FUNCTION__); goto done; } curl_easy_setopt(curl, CURLOPT_URL, url); @@ -947,12 +953,12 @@ url_post(char *url, curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postfields)); - if (clicon_debug_get()) - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + if (clixon_debug_get()) + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); if ((errcode = curl_easy_perform(curl)) != CURLE_OK){ - clicon_debug(1, "%s: curl: %s(%d)", __FUNCTION__, err, errcode); + clixon_debug(CLIXON_DBG_DEFAULT, "%s: curl: %s(%d)", __FUNCTION__, err, errcode); retval = 0; - goto done; + goto done; } if (getdata && cb.b_buf){ *getdata = cb.b_buf; @@ -965,21 +971,23 @@ url_post(char *url, if (cb.b_buf) free(cb.b_buf); if (curl) - curl_easy_cleanup(curl); /* cleanup */ + curl_easy_cleanup(curl); /* cleanup */ return retval; } /*! Stream callback for example stream notification * * Push via curl_post to publish stream event - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] op Operation: 0 OK, 1 Close * @param[in] event Event as XML * @param[in] arg Extra argument provided in stream_ss_add + * @retval 0 OK + * @retval -1 Error * @see stream_ss_add */ -static int -stream_publish_cb(clicon_handle h, +static int +stream_publish_cb(clicon_handle h, int op, cxobj *event, void *arg) @@ -991,7 +999,7 @@ stream_publish_cb(clicon_handle h, char *result = NULL; char *stream = (char*)arg; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (op != 0) goto ok; /* Create pub url */ @@ -1016,7 +1024,7 @@ stream_publish_cb(clicon_handle h, &result) < 0) /* result as xml */ goto done; if (result) - clicon_debug(1, "%s: %s", __FUNCTION__, result); + clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s", __FUNCTION__, result); ok: retval = 0; done: @@ -1046,12 +1054,12 @@ stream_publish(clicon_handle h, 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); + clicon_log_init("xpath", LOG_WARNING, CLICON_LOG_STDERR); return 0; #endif } -int +int stream_publish_init() { #ifdef CLIXON_PUBLISH_STREAMS @@ -1060,7 +1068,7 @@ stream_publish_init() if (curl_global_init(CURL_GLOBAL_ALL) != 0){ clicon_err(OE_PLUGIN, errno, "curl_global_init"); goto done; - } + } retval = 0; done: return retval; @@ -1069,11 +1077,11 @@ stream_publish_init() #endif } -int +int stream_publish_exit() { #ifdef CLIXON_PUBLISH_STREAMS curl_global_cleanup(); -#endif +#endif return 0; } diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c index c6f686f4..db28a874 100644 --- a/lib/src/clixon_string.c +++ b/lib/src/clixon_string.c @@ -80,8 +80,8 @@ * @see clicon_strsplit */ char ** -clicon_strsep(char *string, - char *delim, +clicon_strsep(char *string, + char *delim, int *nvec0) { char **vec = NULL; @@ -92,7 +92,7 @@ clicon_strsep(char *string, size_t siz; char *s; char *d; - + if ((s = string)==NULL) goto done; while (*s){ @@ -103,9 +103,9 @@ 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"); + clicon_err(OE_UNIX, errno, "malloc"); goto done; - } + } memset(vec, 0, siz); ptr = (char*)vec + (nvec+1)* sizeof(char*); /* this is where ptr starts */ strcpy(ptr, string); @@ -119,14 +119,14 @@ clicon_strsep(char *string, /*! Concatenate elements of a string array into a string. * - * An optional delimiter string can be specified which will be inserted betwen + * An optional delimiter string can be specified which will be inserted between * each element. * @retval str Joined string. Free after use. * @retval NULL Failure */ char * -clicon_strjoin(int argc, - char **argv, +clicon_strjoin(int argc, + char **argv, char *delim) { int i; @@ -165,7 +165,7 @@ clixon_string_del_join(char *str1, { char *str; int len; - + if (str2 == NULL){ clicon_err(OE_UNIX, EINVAL, "str2 is NULL"); return NULL; @@ -212,7 +212,7 @@ clixon_strsplit(char *string, { int retval = -1; char *str; - + if ((str = strchr(string, delim)) == NULL){ if (suffix && (*suffix = strdup(string)) == NULL){ clicon_err(OE_YANG, errno, "strdup"); @@ -281,7 +281,7 @@ uri_unreserved(unsigned char in) * @see xml_chardata_encode */ int -uri_percent_encode(char **encp, +uri_percent_encode(char **encp, const char *fmt, ...) { int retval = -1; @@ -310,7 +310,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"); + clicon_err(OE_UNIX, errno, "malloc"); goto done; } memset(enc, 0, len); @@ -344,7 +344,7 @@ uri_percent_encode(char **encp, * @see uri_percent_encode */ int -uri_percent_decode(char *enc, +uri_percent_decode(char *enc, char **strp) { int retval = -1; @@ -353,7 +353,7 @@ uri_percent_decode(char *enc, char hstr[3]; size_t len; char *ptr; - + if (enc == NULL){ clicon_err(OE_UNIX, EINVAL, "enc is NULL"); goto done; @@ -361,14 +361,14 @@ uri_percent_decode(char *enc, /* This is max */ len = strlen(enc)+1; if ((str = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clicon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, len); len = strlen(enc); j = 0; for (i=0; i 2 && + if (enc[i] == '%' && strlen(enc)-i > 2 && isxdigit(enc[i+1]) && isxdigit(enc[i+2])){ hstr[0] = enc[i+1]; hstr[1] = enc[i+2]; @@ -429,7 +429,7 @@ xml_chardata_encode(char **escp, int cdata; /* when set, skip encoding */ va_list args; size_t slen; - + /* Two steps: (1) read in the complete format string */ va_start(args, fmt); /* dryrun */ fmtlen = vsnprintf(NULL, 0, fmt, args) + 1; @@ -477,7 +477,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"); + clicon_err(OE_UNIX, errno, "malloc"); goto done; } memset(esc, 0, len); @@ -613,7 +613,7 @@ xml_chardata_decode_ampersand(char *str, uint32_t code; cbuf *cb = NULL; int ret; - + if ((semi = index(str, ';')) == NULL) goto fail; *semi = '\0'; @@ -666,8 +666,10 @@ xml_chardata_decode_ampersand(char *str, /*! Decode escape characters according to XML definition * - * @param[out] decp Decoded malloced output string - * @param[in] fmt Encoded input string (stdarg format string) + * @param[out] decp Decoded malloced output string + * @param[in] fmt Encoded input string (stdarg format string) + * @retval 0 OK + * @retval -1 Error * @see xml_chardata_encode for encoding */ int @@ -703,7 +705,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"); + clicon_err(OE_UNIX, errno, "malloc"); goto done; } j = 0; @@ -758,9 +760,9 @@ xml_chardata_decode(char **decp, * XXX differentiate between error and null cvec. */ int -uri_str2cvec(char *string, - char delim1, - char delim2, +uri_str2cvec(char *string, + char delim1, + char delim2, int decode, cvec **cvp) { @@ -847,7 +849,7 @@ uri_str2cvec(char *string, * @note linear search */ const char * -clicon_int2str(const map_str2int *mstab, +clicon_int2str(const map_str2int *mstab, int i) { const struct map_str2int *ms; @@ -867,7 +869,7 @@ clicon_int2str(const map_str2int *mstab, * @see clicon_str2int_search for optimized lookup, but strings must be sorted */ int -clicon_str2int(const map_str2int *mstab, +clicon_str2int(const map_str2int *mstab, char *str) { const struct map_str2int *ms; @@ -891,7 +893,7 @@ clicon_str2int(const map_str2int *mstab, * @note Assumes sorted strings, tree search */ static int -str2int_search1(const map_str2int *mstab, +str2int_search1(const map_str2int *mstab, char *str, int low, int upper, @@ -928,13 +930,13 @@ str2int_search1(const map_str2int *mstab, * @note -1 can not be value */ int -clicon_str2int_search(const map_str2int *mstab, +clicon_str2int_search(const map_str2int *mstab, char *str, int len) { int found; - if (str2int_search1(mstab, str, 0, len, len, &found)) + if (str2int_search1(mstab, str, 0, len, len, &found)) return found; return -1; /* not found */ } @@ -947,7 +949,7 @@ clicon_str2int_search(const map_str2int *mstab, * @retval NULL Error, not found */ char* -clicon_str2str(const map_str2str *mstab, +clicon_str2str(const map_str2str *mstab, char *str) { const struct map_str2str *ms; @@ -984,7 +986,8 @@ nodeid_split(char *nodeid, return clixon_strsplit(nodeid, ':', prefix, id); } -/*! Trim blanks from front and end of a string, return new string +/*! Trim blanks from front and end of a string, return new string + * * @param[in] str * @retval s Pointer into existing str after trimming blanks */ @@ -1006,6 +1009,7 @@ clixon_trim(char *str) } /*! Trim blanks from front and end of a string, return new string + * * @param[in] str * @param[in] trims Characters to trim: a vector of characters * @retval s Pointer into existing str after trimming blanks @@ -1029,6 +1033,7 @@ clixon_trim2(char *str, } /*! check string equals (NULL is equal) + * * @param[in] s1 String 1 * @param[in] s2 String 2 * @retval 0 Equal @@ -1036,10 +1041,10 @@ clixon_trim2(char *str, * @retval >0 s1 is greater than s2 */ int -clicon_strcmp(char *s1, +clicon_strcmp(char *s1, char *s2) { - if (s1 == NULL && s2 == NULL) + if (s1 == NULL && s2 == NULL) return 0; if (s1 == NULL) /* empty string first */ return -1; @@ -1056,13 +1061,13 @@ clicon_strcmp(char *s1, * @retval 0 OK * @retval -1 Error */ -static int +static int clixon_unicode2utf8_one(uint16_t uc16, char *utfstr, size_t utflen) { int retval = -1; - + if (utflen < 5){ clicon_err(OE_UNIX, EINVAL, "Length of utfstr is not >=4"); goto done; @@ -1094,7 +1099,7 @@ clixon_unicode2utf8_one(uint16_t uc16, * @retval 0 OK * @retval -1 Error */ -int +int clixon_unicode2utf8(char *ucstr, char *utfstr, size_t utflen) @@ -1141,7 +1146,7 @@ clixon_unicode2utf8(char *ucstr, */ #ifndef HAVE_STRNDUP char * -clicon_strndup(const char *str, +clicon_strndup(const char *str, size_t len) { char *new; diff --git a/lib/src/clixon_text_syntax.c b/lib/src/clixon_text_syntax.c index 14a1d4d9..f6fbaf95 100644 --- a/lib/src/clixon_text_syntax.c +++ b/lib/src/clixon_text_syntax.c @@ -109,6 +109,8 @@ tleaf(cxobj *x) * @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow * @param[in,out] leafl Leaflist state for keeping track of when [] ends * @param[in,out] leaflname Leaflist state for [] + * @retval 0 OK + * @retval -1 Error * leaflist state: * 0: No leaflist * 1: In leaflist @@ -117,16 +119,16 @@ tleaf(cxobj *x) static int text2file(cxobj *xn, clicon_output_cb *fn, - FILE *f, + FILE *f, int level, int autocliext, int *leafl, char **leaflname) { + int retval = -1; cxobj *xc = NULL; int children=0; - int retval = -1; int exist = 0; yang_stmt *yn; char *value; @@ -171,7 +173,7 @@ text2file(cxobj *xn, } } } - if (*leafl && yn){ + if (*leafl && yn){ if (yang_keyword_get(yn) == Y_LEAF_LIST && strcmp(*leaflname, yang_argument_get(yn)) == 0) ; else{ @@ -300,6 +302,8 @@ get_prefix(yang_stmt *yn) * @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow * @param[in,out] leafl Leaflist state for keeping track of when [] ends * @param[in,out] leaflname Leaflist state for [] + * @retval 0 OK + * @retval -1 Error * leaflist state: * 0: No leaflist * 1: In leaflist @@ -313,11 +317,10 @@ text2cbuf(cbuf *cb, int autocliext, int *leafl, char **leaflname) - { + int retval = -1; cxobj *xc = NULL; int children=0; - int retval = -1; int exist = 0; yang_stmt *yn; char *value; @@ -351,7 +354,7 @@ text2cbuf(cbuf *cb, } } } - if (*leafl && yn){ + if (*leafl && yn){ if (yang_keyword_get(yn) == Y_LEAF_LIST && strcmp(*leaflname, yang_argument_get(yn)) == 0) ; else{ @@ -470,7 +473,7 @@ text2cbuf(cbuf *cb, */ int clixon_text2file(FILE *f, - cxobj *xn, + cxobj *xn, int level, clicon_output_cb *fn, int skiptop, @@ -505,10 +508,12 @@ clixon_text2file(FILE *f, * @param[in] level Print PRETTYPRINT_INDENT spaces per level in front of each line * @param[in] skiptop 0: Include top object 1: Skip top-object, only children, * @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow + * @retval 0 OK + * @retval -1 Error */ int clixon_text2cbuf(cbuf *cb, - cxobj *xn, + cxobj *xn, int level, int skiptop, int autocliext) @@ -549,7 +554,7 @@ text_diff_keys(cbuf *cb, cvk = yang_cvec_get(y); cvi = NULL; while ((cvi = cvec_each(cvk, cvi)) != NULL) { - keyname = cv_string_get(cvi); + keyname = cv_string_get(cvi); keyval = xml_find_body(x, keyname); cprintf(cb, " %s", keyval); } @@ -565,7 +570,7 @@ text_diff_keys(cbuf *cb, * @param[in] x1 Second XML tree * @param[in] level How many spaces to insert before each line * @param[in] skiptop 0: Include top object 1: Skip top-object, only children, - * @retval 0 Ok + * @retval 0 OK * @retval -1 Error * @cod * cbuf *cb = cbuf_new(); @@ -613,7 +618,7 @@ text_diff2cbuf(cbuf *cb, #endif } /* Traverse x0 and x1 in lock-step */ - x0c = x1c = NULL; + x0c = x1c = NULL; x0c = xml_child_each(x0, x0c, CX_ELMNT); x1c = xml_child_each(x1, x1c, CX_ELMNT); for (;;){ @@ -765,7 +770,9 @@ clixon_text_diff2cbuf(cbuf *cb, * (2) The reason against is of principal of making the parser design simpler in a bottom-up mode * The compromise between (1) and (2) is to first parse without YANG (2) and then call a special * function after YANG binding to populate key tags properly. - * @param[in] x XML node + * @param[in] xn XML node + * @retval 0 OK + * @retval -1 Error * @see text_mark_bodies where marking of bodies made transformed here */ static int @@ -809,7 +816,7 @@ text_populate_list(cxobj *xn) goto done; } xc = NULL; - while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL) { + while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL) { if (text_populate_list(xc) < 0) goto done; } @@ -833,8 +840,8 @@ text_populate_list(cxobj *xn) * @see _xml_parse for XML variant * @note Parsing requires YANG, which means yb must be YB_MODULE/_NEXT */ -static int -_text_syntax_parse(char *str, +static int +_text_syntax_parse(char *str, yang_bind yb, yang_stmt *yspec, cxobj *xt, @@ -847,8 +854,8 @@ _text_syntax_parse(char *str, cbuf *cberr = NULL; int failed = 0; /* yang assignment */ cxobj *xc; - - clicon_debug(1, "%s %d %s", __FUNCTION__, yb, 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"); return -1; @@ -868,7 +875,7 @@ _text_syntax_parse(char *str, x = NULL; while ((x = xml_child_each(ts.ts_xtop, x, CX_ELMNT)) != NULL) { - /* Populate, ie associate xml nodes with yang specs + /* Populate, ie associate xml nodes with yang specs */ switch (yb){ case YB_MODULE_NEXT: @@ -887,11 +894,11 @@ _text_syntax_parse(char *str, failed++; break; default: /* shouldnt happen */ - break; + break; } /* switch */ - /*! Look for YANG lists nodes and convert bodies to keys */ + /* Look for YANG lists nodes and convert bodies to keys */ xc = NULL; - while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) + while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) if (text_populate_list(xc) < 0) goto done; } @@ -905,11 +912,11 @@ _text_syntax_parse(char *str, goto done; retval = 1; done: - clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); if (cberr) cbuf_free(cberr); clixon_text_syntax_parsel_exit(&ts); - return retval; + return retval; fail: /* invalid */ retval = 0; goto done; @@ -925,7 +932,6 @@ _text_syntax_parse(char *str, * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) w xerr set * @retval -1 Error with clicon_err called - * * @code * cxobj *x = NULL; * if (clixon_text_syntax_parse_string(str, YB_MODULE, yspec, &x, &xerr) < 0) @@ -935,14 +941,14 @@ _text_syntax_parse(char *str, * @note you need to free the xml parse tree after use, using xml_free() * @see clixon_text_syntax_parse_file From a file */ -int -clixon_text_syntax_parse_string(char *str, +int +clixon_text_syntax_parse_string(char *str, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr) { - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (xt==NULL){ clicon_err(OE_XML, EINVAL, "xt is NULL"); return -1; @@ -966,6 +972,9 @@ clixon_text_syntax_parse_string(char *str, * @param[in] yspec Yang specification, or NULL * @param[in,out] xt Pointer to (XML) parse tree. If empty, create. * @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 * * @code * cxobj *xt = NULL; @@ -978,10 +987,6 @@ clixon_text_syntax_parse_string(char *str, * @note May block on file I/O * @note Parsing requires YANG, which means yb must be YB_MODULE/_NEXT * - * @retval 1 OK and valid - * @retval 0 Invalid (only if yang spec) w xerr set - * @retval -1 Error with clicon_err called - * * @see clixon_text_syntax_parse_string */ int @@ -1048,7 +1053,7 @@ clixon_text_syntax_parse_file(FILE *fp, } if (textbuf) free(textbuf); - return retval; + return retval; fail: retval = 0; goto done; diff --git a/lib/src/clixon_text_syntax_parse.h b/lib/src/clixon_text_syntax_parse.h index 4b0b6e47..d657fea7 100644 --- a/lib/src/clixon_text_syntax_parse.h +++ b/lib/src/clixon_text_syntax_parse.h @@ -39,7 +39,8 @@ /* * Types */ -/*! XML parser yacc handler struct */ +/*! XML parser yacc handler struct + */ struct clixon_text_syntax_parse_yacc { char *ts_parse_string; /* original (copy of) parse string */ int ts_linenum; /* Number of \n in parsed buffer */ diff --git a/lib/src/clixon_text_syntax_parse.l b/lib/src/clixon_text_syntax_parse.l index 70dd5ccf..f6388ac5 100644 --- a/lib/src/clixon_text_syntax_parse.l +++ b/lib/src/clixon_text_syntax_parse.l @@ -62,7 +62,7 @@ #define YY_NO_INPUT /* typecast macro */ -#define _TS ((clixon_text_syntax_yacc *)_ts) +#define _TS ((clixon_text_syntax_yacc *)_ts) #undef clixon_xml_parsewrap int clixon_text_syntax_parsewrap(void) diff --git a/lib/src/clixon_text_syntax_parse.y b/lib/src/clixon_text_syntax_parse.y index d1e90a57..f9297c5e 100644 --- a/lib/src/clixon_text_syntax_parse.y +++ b/lib/src/clixon_text_syntax_parse.y @@ -85,21 +85,21 @@ /* Enable for debugging, steals some cycles otherwise */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #else #define _PARSE_DEBUG(s) #endif - + void clixon_text_syntax_parseerror(void *arg, - char *s) + char *s) { 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", + clicon_err(OE_XML, XMLPARSE_ERRNO, "text_syntax_parse: line %d: %s: at or before: %s", ts->ts_linenum, s, - clixon_text_syntax_parsetext); + clixon_text_syntax_parsetext); return; } @@ -200,6 +200,7 @@ text_element_create(clixon_xvec *xvec0, } /*! Special mechanism to mark bodies so they will not be filtered as whitespace + * * @see strip_body_objects text_populate_list */ static int @@ -207,16 +208,16 @@ text_mark_bodies(clixon_xvec *xv) { int i; cxobj *xb; - + for (i=0; istmt"); @@ -229,7 +230,7 @@ stmts : stmts stmt { _PARSE_DEBUG("stmts->stmts stmt"); if (clixon_xvec_merge($1, $2) < 0) YYERROR; clixon_xvec_free($2); $$ = $1; - } + } | { _PARSE_DEBUG("stmts->stmt"); if (($$ = clixon_xvec_new()) == NULL) YYERROR; } @@ -292,7 +293,7 @@ value : TOKEN { _PARSE_DEBUG("value->TOKEN"); substr : substr TOKEN { _PARSE_DEBUG("substr->substr TOKEN"); $$ = strjoin($1, $2); free($2);} | { _PARSE_DEBUG("substr->"); - $$ = NULL; } + $$ = NULL; } ; %% diff --git a/lib/src/clixon_uid.c b/lib/src/clixon_uid.c index e7869b2f..0553d61d 100644 --- a/lib/src/clixon_uid.c +++ b/lib/src/clixon_uid.c @@ -43,7 +43,7 @@ #include #include #include -#define _GNU_SOURCE +#define _GNU_SOURCE #define __USE_GNU #include /* For setresuid */ #undef _GNU_SOURCE @@ -64,22 +64,23 @@ #include "clixon_uid.h" /*! Translate group name to gid. Return -1 if error or not found. + * * @param[in] name Name of group * @param[out] gid Group id - * @retval 0 OK - * @retval -1 Error. or not found + * @retval 0 OK + * @retval -1 Error. or not found */ int -group_name2gid(const char *name, +group_name2gid(const char *name, gid_t *gid) { int retval = -1; - char buf[1024]; + char buf[1024]; struct group g0; struct group *gr = &g0; struct group *gtmp; - - gr = &g0; + + 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); @@ -97,6 +98,7 @@ group_name2gid(const char *name, } /*! Translate user name to uid. Return -1 if error or not found. + * * @param[in] name Name of user * @param[out] uid User id * @retval 0 OK @@ -107,7 +109,7 @@ name2uid(const char *name, uid_t *uid) { int retval = -1; - char buf[1024]; + char buf[1024]; struct passwd pwbuf; struct passwd *pwbufp = NULL; @@ -127,20 +129,21 @@ name2uid(const char *name, } /*! Translate uid to user name + * * @param[in] uid User id * @param[out] name User name (Malloced, need to be freed) * @retval 0 OK - * @retval -1 Error. or not found + * @retval -1 Error. or not found */ int uid2name(const uid_t uid, char **name) { int retval = -1; - char buf[1024]; + char buf[1024]; struct passwd pwbuf = {0,}; struct passwd *pwbufp = NULL; - + if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){ clicon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid); goto done; @@ -164,17 +167,19 @@ uid2name(const uid_t uid, /* Privileges drop perm, temp and restore * @see https://www.usenix.org/legacy/events/sec02/full_papers/chen/chen.pdf */ - /*! Temporarily drop privileges +/*! Temporarily drop privileges + * * @param[in] new_uid + * @retval 0 OK + * @retval -1 Error */ int drop_priv_temp(uid_t new_uid) { #ifdef HAVE_GETRESUID int retval = -1; - - clicon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, 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"); @@ -188,24 +193,27 @@ drop_priv_temp(uid_t new_uid) done: return retval; #else - clicon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); return 0; #endif } -/*! Permanently drop privileges +/*! Permanently drop privileges + * * @param[in] new_uid + * @retval 0 OK + * @retval -1 Error */ int drop_priv_perm(uid_t new_uid) { #ifdef HAVE_GETRESUID - int retval = -1; + int retval = -1; uid_t ruid; uid_t euid; uid_t suid; - clicon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, 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"); @@ -225,7 +233,7 @@ drop_priv_perm(uid_t new_uid) done: return retval; #else - clicon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); return 0; #endif } @@ -240,7 +248,7 @@ restore_priv(void) uid_t euid; uid_t suid; - clicon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (getresuid(&ruid, &euid, &suid) < 0){ clicon_err(OE_UNIX, errno, "setresuid"); @@ -258,7 +266,7 @@ restore_priv(void) done: return retval; #else - clicon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); return 0; #endif } diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index b62550ab..174d5ac7 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -83,6 +83,7 @@ #include "clixon_validate.h" /*! Validate xml node of type leafref, ensure the value is one of that path's reference + * * @param[in] xt XML leaf node of type leafref * @param[in] ys Yang spec of leaf * @param[in] ytype Yang type statement belonging to the XML node @@ -135,11 +136,11 @@ validate_leafref(cxobj *xt, yang_stmt *ymod; cg_var *cv; int require_instance = 1; - + /* require instance */ if ((yreqi = yang_find(ytype, Y_REQUIRE_INSTANCE, NULL)) != NULL){ if ((cv = yang_cv_get(yreqi)) != NULL) /* shouldnt happen */ - require_instance = cv_bool_get(cv); + require_instance = cv_bool_get(cv); } /* Find referred XML instances */ if (require_instance == 0) @@ -164,7 +165,7 @@ validate_leafref(cxobj *xt, goto ok; if (xml_nsctx_yang(ys, &nsc) < 0) goto done; - if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, path_arg) < 0) + if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, path_arg) < 0) goto done; for (i = 0; i < xlen; i++) { x = xvec[i]; @@ -204,6 +205,7 @@ validate_leafref(cxobj *xt, } /*! Validate xml node of type identityref, ensure value is a defined identity + * * Check if a given node has value derived from base identity. This is * a run-time check necessary when validating eg netconf. * Valid values for an identityref are any identities derived from all @@ -242,13 +244,13 @@ validate_identityref(cxobj *xt, cbuf *cb = NULL; cvec *idrefvec; /* Derived identityref list: (module:id)**/ yang_stmt *ymod; - + if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Get idref value. Then see if this value is derived from ytype. @@ -280,7 +282,7 @@ validate_identityref(cxobj *xt, ymod = yang_find_module_by_prefix_yspec(ys_spec(ys), prefix); } if (ymod == NULL){ - cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d", + cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d", node, yang_argument_get(ybaseid), yang_argument_get(ys_module(ybaseid)), @@ -290,13 +292,13 @@ validate_identityref(cxobj *xt, goto fail; } cprintf(cb, "%s:%s", yang_argument_get(ymod), id); - idref = cbuf_get(cb); - /* Here check if node is in the derived node list of the base identity + idref = cbuf_get(cb); + /* Here check if node is in the derived node list of the base identity * The derived node list is a cvec computed XXX */ idrefvec = yang_cvec_get(ybaseid); if (cvec_find(idrefvec, idref) == NULL){ - cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d", + cprintf(cberr, "Identityref validation failed, %s not derived from %s in %s.yang:%d", node, yang_argument_get(ybaseid), yang_argument_get(ys_module(ybaseid)), @@ -322,7 +324,8 @@ validate_identityref(cxobj *xt, } /*! Validate an RPC node - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xrpc XML node to be validated * @param[in] expanddefault * @param[out] xret Error XML tree. Free with xml_free after use @@ -375,7 +378,7 @@ xml_yang_validate_rpc(clicon_handle h, char *rpcprefix; char *namespace = NULL; int ret; - + if (strcmp(xml_name(xrpc), "rpc")){ clicon_err(OE_XML, EINVAL, "Expected RPC"); goto done; @@ -397,7 +400,7 @@ xml_yang_validate_rpc(clicon_handle h, goto done; goto fail; } - if ((ret = xml_yang_validate_all(h, xn, xret)) < 0) + if ((ret = xml_yang_validate_all(h, xn, xret)) < 0) goto done; /* error or validation fail */ if (ret == 0) goto fail; @@ -430,7 +433,7 @@ xml_yang_validate_rpc_reply(clicon_handle h, char *rpcprefix; char *namespace = NULL; int ret; - + if (strcmp(xml_name(xrpc), "rpc-reply")){ clicon_err(OE_XML, EINVAL, "Expected RPC"); goto done; @@ -458,7 +461,7 @@ xml_yang_validate_rpc_reply(clicon_handle h, goto done; goto fail; } - if ((ret = xml_yang_validate_all(h, xn, xret)) < 0) + if ((ret = xml_yang_validate_all(h, xn, xret)) < 0) goto done; /* error or validation fail */ if (ret == 0) goto fail; @@ -496,10 +499,10 @@ xml_yang_validate_rpc_reply(clicon_handle h, * is present */ static int -check_choice(cxobj *xp, +check_choice(cxobj *xp, yang_stmt *ytchoice, yang_stmt *ytcase, - cxobj *xt, + cxobj *xt, yang_stmt *yt, cxobj **xret) { @@ -507,7 +510,7 @@ check_choice(cxobj *xp, cxobj *x; yang_stmt *y; yang_stmt *yp; - + x = NULL; /* Find a child with same yang spec */ while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) { if (x == xt) @@ -544,6 +547,7 @@ check_choice(cxobj *xp, } /*! Check if an xml node xt is a part of a choice and have >1 siblings + * * @param[in] xt XML node to be validated * @param[in] yt xt:s yang statement * @param[out] xret Error XML tree. Free with xml_free after use @@ -554,15 +558,14 @@ check_choice(cxobj *xp, * XXX does not check: xt is choice and has n children, but there exists a default child */ static int -check_choice_child(cxobj *xt, +check_choice_child(cxobj *xt, yang_stmt *yt, cxobj **xret) { int retval = -1; - yang_stmt *ytp; /* yt:s parent */ yang_stmt *ytcase = NULL; /* yt:s parent case if any */ - yang_stmt *ytchoice = NULL; + yang_stmt *ytchoice = NULL; int ret; cxobj *xp; #if 0 @@ -570,7 +573,7 @@ check_choice_child(cxobj *xt, yang_stmt *yp; yang_stmt *y; #endif - + if ((ytp = yang_parent_get(yt)) == NULL) goto ok; /* Return OK if xt is not choice */ @@ -632,6 +635,7 @@ check_choice_child(cxobj *xt, } /*! Check that an XML tree of type list has valid keys + * * @param[in] xt XML tree * @param[in] yt Yang spec of xt of type LIST which is a config true node. * @param[out] xret Error XML tree. Free with xml_free after use @@ -645,7 +649,7 @@ check_choice_child(cxobj *xt, * @see xml_yang_validate_list_key_only */ static int -check_list_key(cxobj *xt, +check_list_key(cxobj *xt, yang_stmt *yt, cxobj **xret) @@ -655,7 +659,7 @@ check_list_key(cxobj *xt, cvec *cvk = NULL; /* vector of index keys */ cg_var *cvi; 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"); goto done; @@ -668,7 +672,7 @@ check_list_key(cxobj *xt, cvk = yang_cvec_get(yt); /* Use Y_LIST cache, see ys_populate_list() */ cvi = NULL; while ((cvi = cvec_each(cvk, cvi)) != NULL) { - keyname = cv_string_get(cvi); + keyname = cv_string_get(cvi); if (xml_find_type(xt, NULL, keyname, CX_ELMNT) == NULL){ if (xret){ cbuf *cb = NULL; @@ -676,7 +680,7 @@ check_list_key(cxobj *xt, enum rfc_6020 keyw; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; } ymod = ys_module(yt); @@ -701,6 +705,7 @@ check_list_key(cxobj *xt, } /*! Go through all case:s children, ensure all mandatory nodes are marked, else error. Then clear + * * @retval 1 Validation OK * @retval 0 Validation failed (xret set) * @retval -1 Error @@ -750,6 +755,7 @@ choice_mandatory_check(cxobj *xt, /*! Find yang node which is ancestor of ys (or ys itself) and child of ytop + * * Assume tree: ytop ... ys * Return: ytop --- ymp --- ym ... ys * @retval: 0 No match @@ -765,7 +771,7 @@ yang_ancestor_child(yang_stmt *ys, yang_stmt *y; yang_stmt *yprev = NULL; yang_stmt *yp; - + y = ys; while (y != NULL){ yp = yang_parent_get(y); @@ -818,7 +824,7 @@ check_mandatory_case(cxobj *xt, yang_stmt *ycnew; yang_stmt *ycase; int ret; - + ycase = NULL; x = NULL; while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { @@ -830,7 +836,7 @@ check_mandatory_case(cxobj *xt, goto done; if (ret == 1){ if (yang_flag_get(ym, YANG_FLAG_MARK) != 0){ - clicon_debug(1, "%s Already marked, shouldnt happen", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Already marked, shouldnt happen", __FUNCTION__); } yang_flag_set(ym, YANG_FLAG_MARK); } @@ -872,6 +878,7 @@ check_mandatory_case(cxobj *xt, } /*! Check if an xml node lacks mandatory children + * * @param[in] xt XML node to be validated * @param[in] yt xt:s yang statement * @param[out] xret Error XML tree. Free with xml_free after use @@ -880,7 +887,7 @@ check_mandatory_case(cxobj *xt, * @retval -1 Error */ static int -check_mandatory(cxobj *xt, +check_mandatory(cxobj *xt, yang_stmt *yt, cxobj **xret) @@ -892,7 +899,7 @@ check_mandatory(cxobj *xt, yang_stmt *yp; cbuf *cb = NULL; int ret; - + if (yt == NULL || !yang_config(yt)){ clicon_err(OE_YANG, EINVAL, "yt is not config true"); goto done; @@ -906,7 +913,7 @@ check_mandatory(cxobj *xt, yc = NULL; while ((yc = yn_each(yt, yc)) != NULL) { /* Choice is more complex because of choice/case structure and possibly hierarchical */ - if (yang_keyword_get(yc) == Y_CHOICE){ + if (yang_keyword_get(yc) == Y_CHOICE){ if (yang_xml_mandatory(xt, yc)){ x = NULL; while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { @@ -924,7 +931,7 @@ check_mandatory(cxobj *xt, goto fail; } } - /*! Check mandatory nodes in case according to RFC7950 7.9.4 */ + /* Check mandatory nodes in case according to RFC7950 7.9.4 */ if ((ret = check_mandatory_case(xt, yc, xret)) < 0) goto done; if (ret == 0) @@ -938,8 +945,8 @@ check_mandatory(cxobj *xt, case Y_CONTAINER: case Y_ANYDATA: case Y_ANYXML: - case Y_LEAF: - if (yang_config(yc)==0) + case Y_LEAF: + if (yang_config(yc)==0) break; /* Find a child with the mandatory yang */ x = NULL; @@ -974,6 +981,7 @@ check_mandatory(cxobj *xt, } /*! Validate a single XML node with yang specification for added entry + * * 1. Check if mandatory leafs present as subs. * 2. Check leaf values, eg int ranges and string regexps. * @param[in] xt XML node to be validated @@ -995,7 +1003,7 @@ check_mandatory(cxobj *xt, */ int xml_yang_validate_add(clicon_handle h, - cxobj *xt, + cxobj *xt, cxobj **xret) { int retval = -1; @@ -1089,18 +1097,21 @@ xml_yang_validate_add(clicon_handle h, } /*! Some checks done only at edit_config, eg keys in lists + * * @param[in] xt XML tree * @param[out] xret Error XML tree. Free with xml_free after use + * @retval 0 OK + * @retval -1 Error */ int -xml_yang_validate_list_key_only(cxobj *xt, +xml_yang_validate_list_key_only(cxobj *xt, cxobj **xret) { int retval = -1; yang_stmt *yt; /* yang spec of xt going in */ int ret; cxobj *x; - + /* if not given by argument (override) use default link and !Node has a config sub-statement and it is false */ if ((yt = xml_spec(xt)) != NULL && @@ -1139,7 +1150,7 @@ xml_yang_validate_leaf_union(clicon_handle h, cxobj *xret1 = NULL; yang_stmt *ytype; /* resolved type */ char *restype; - + /* Enough that one is valid, eg returns 1,otherwise fail */ while ((ytsub = yn_each(yrestype, ytsub)) != NULL){ if (yang_keyword_get(ytsub) != Y_TYPE) @@ -1188,6 +1199,7 @@ xml_yang_validate_leaf_union(clicon_handle h, } /*! Validate a single XML node with yang specification for all (not only added) entries + * * 1. Check leafrefs. Eg you delete a leaf and a leafref references it. * @param[in] xt XML node to be validated * @param[out] xret Error XML tree (if retval=0). Free with xml_free after use @@ -1208,7 +1220,7 @@ xml_yang_validate_leaf_union(clicon_handle h, */ int xml_yang_validate_all(clicon_handle h, - cxobj *xt, + cxobj *xt, cxobj **xret) { int retval = -1; @@ -1269,7 +1281,7 @@ xml_yang_validate_all(clicon_handle h, xml_name(xt), yang_argument_get(ys_module(yt)), xpath); - if (xret && netconf_operation_failed_xml(xret, "application", + if (xret && netconf_operation_failed_xml(xret, "application", cbuf_get(cb)) < 0) goto done; goto fail; @@ -1338,7 +1350,7 @@ xml_yang_validate_all(clicon_handle h, } cprintf(cb, "Failed MUST xpath '%s' of '%s' in module %s", xpath, xml_name(xt), yang_argument_get(ys_module(yt))); - if (xret && netconf_operation_failed_xml(xret, "application", + if (xret && netconf_operation_failed_xml(xret, "application", ye?yang_argument_get(ye):cbuf_get(cb)) < 0) goto done; goto fail; @@ -1378,14 +1390,16 @@ xml_yang_validate_all(clicon_handle h, } /*! Validate a single XML node with yang specification - * @param[out] xret Error XML tree (if ret == 0). Free with xml_free after use - * @retval 1 Validation OK - * @retval 0 Validation failed (xret set) - * @retval -1 Error + * + * @param[in] h Clixon handle + * @param[out] xret Error XML tree (if ret == 0). Free with xml_free after use + * @retval 1 Validation OK + * @retval 0 Validation failed (xret set) + * @retval -1 Error */ int xml_yang_validate_all_top(clicon_handle h, - cxobj *xt, + cxobj *xt, cxobj **xret) { int ret; @@ -1405,6 +1419,8 @@ xml_yang_validate_all_top(clicon_handle h, * * Rewrite return message if errors * @param[in,out] cbret + * @retval 0 OK + * @retval -1 Error * @note Parses cbret which seems one time too many */ int @@ -1437,7 +1453,7 @@ rpc_reply_check(clicon_handle h, if ((ret = xml_bind_yang_rpc_reply(h, x, rpcname, yspec, &xret)) < 0) goto done; if (ret == 0){ - clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret)); cbuf_reset(cbret); if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; @@ -1446,7 +1462,7 @@ rpc_reply_check(clicon_handle h, if ((ret = xml_yang_validate_rpc_reply(h, x, &xret)) < 0) goto done; if (ret == 0){ - clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret)); cbuf_reset(cbret); if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; diff --git a/lib/src/clixon_validate_minmax.c b/lib/src/clixon_validate_minmax.c index 7268537d..1ea26911 100644 --- a/lib/src/clixon_validate_minmax.c +++ b/lib/src/clixon_validate_minmax.c @@ -80,6 +80,7 @@ #include "clixon_validate_minmax.h" /*! New element last in list, check if already exists if sp return -1 + * * @param[in] vec Vector of existing entries (new is last) * @param[in] i1 The new entry is placed at vec[i1] * @param[in] vlen Length of entry @@ -107,8 +108,8 @@ unique_search_xpath(cxobj *x, char *bi; /* Collect tuples */ - if (xpath_vec(x, nsc, "%s", &xvec, &xveclen, xpath) < 0) - goto done; + if (xpath_vec(x, nsc, "%s", &xvec, &xveclen, xpath) < 0) + goto done; for (i=0; i string */ static const map_str2int xsmap[] = { - {"error", CX_ERROR}, - {"element", CX_ELMNT}, - {"attr", CX_ATTR}, + {"error", CX_ERROR}, + {"element", CX_ELMNT}, + {"attr", CX_ATTR}, {"body", CX_BODY}, {NULL, -1} }; /*! Translate from xml type in enum form to string keyword + * * @param[in] type Xml type * @retval str String keyword */ @@ -247,6 +249,7 @@ xml_stats_global(uint64_t *nr) } /*! Return the alloced memory of a single XML obj + * * @param[in] x XML object * @param[out] szp Size of this XML obj * @retval 0 OK @@ -296,6 +299,7 @@ xml_stats_one(cxobj *x, } /*! Return statistics of an XML tree recursively + * * @param[in] xt XML object * @param[out] nrp Number of XML obj recursively * @param[out] szp Size of this XML obj recursively @@ -335,6 +339,7 @@ xml_stats(cxobj *xt, * Access functions */ /*! Get name of xnode + * * @param[in] xn xml node * @retval name of xml node */ @@ -348,13 +353,14 @@ xml_name(cxobj *xn) } /*! Set name of xnode, name is copied + * * @param[in] xn xml node * @param[in] name new name, null-terminated string, copied by function * @retval 0 OK - * @retval -1 on error with clicon-err set + * @retval -1 On error with clicon-err set */ int -xml_name_set(cxobj *xn, +xml_name_set(cxobj *xn, char *name) { if (xn->x_name){ @@ -371,6 +377,7 @@ xml_name_set(cxobj *xn, } /*! Get prefix of xnode + * * @param[in] xn xml node * @retval prefix of xml node */ @@ -381,13 +388,14 @@ xml_prefix(cxobj *xn) } /*! Set prefix of xnode, prefix is copied + * * @param[in] xn XML node * @param[in] prefix New prefix, null-terminated string, copied by function * @retval 0 OK - * @retval -1 Error with clicon-err set + * @retval -1 Error with clicon-err set */ int -xml_prefix_set(cxobj *xn, +xml_prefix_set(cxobj *xn, char *prefix) { if (xn->x_prefix){ @@ -404,6 +412,7 @@ xml_prefix_set(cxobj *xn, } /*! Get cached namespace (given prefix) + * * @param[in] x XML node * @param[in] prefix Namespace prefix, or NULL for default * @retval ns Cached namespace @@ -421,7 +430,8 @@ nscache_get(cxobj *x, return NULL; } -/*! Get cached prefix (given namespace) +/*! Get cached prefix (given namespace) + * * @param[in] x XML node * @param[in] namespace * @param[out] prefix @@ -441,6 +451,7 @@ nscache_get_prefix(cxobj *x, } /*! Dump whole namespace context cache of one xml node + * * @param[in] x XML node * @retval nsc Whole namespace context of x * @retval NULL Empty nsc @@ -455,6 +466,7 @@ nscache_get_all(cxobj *x) } /*! Set cached namespace for specific namespace. Replace if necessary + * * @param[in] x XML node * @param[in] prefix Namespace prefix, or NULL for default * @param[in] namespace Cached namespace to set (assume non-null?) @@ -475,7 +487,7 @@ nscache_set(cxobj *x, if ((x->x_ns_cache = xml_nsctx_init(prefix, namespace)) == NULL) goto done; } - else + else return xml_nsctx_add(x->x_ns_cache, prefix, namespace); retval = 0; done: @@ -483,6 +495,7 @@ nscache_set(cxobj *x, } /*! Set complete cached namespace context + * * @param[in] x XML node * @param[in] nsc Namespace context (note consumed, dont free) * @retval 0 OK @@ -508,6 +521,7 @@ nscache_replace(cxobj *x, } /*! Clear cached namespace context + * * Clear the whole namespace context, not just single cache lines * @param[in] x XML node * @retval 0 OK @@ -528,6 +542,7 @@ nscache_clear(cxobj *x) } /*! Get parent of xnode + * * @param[in] xn xml node * @retval parent xml node */ @@ -541,13 +556,14 @@ xml_parent(cxobj *xn) } /*! Set parent of xml node. + * * @param[in] xn xml node * @param[in] parent pointer to new parent xml node * @retval 0 OK * @see xml_child_rm remove child from parent */ int -xml_parent_set(cxobj *xn, +xml_parent_set(cxobj *xn, cxobj *parent) { xn->x_up = parent; @@ -556,6 +572,7 @@ xml_parent_set(cxobj *xn, #ifdef XML_PARENT_CANDIDATE /*! Get candidate parent of xnode + * * @param[in] xn xml node * @retval parent xml node */ @@ -569,12 +586,13 @@ xml_parent_candidate(cxobj *xn) } /*! Set candidate parent of xml node + * * @param[in] xn xml node * @param[in] parent pointer to candidate parent xml node * @retval 0 OK */ int -xml_parent_candidate_set(cxobj *xn, +xml_parent_candidate_set(cxobj *xn, cxobj *parent) { xn->x_up_candidate = parent; @@ -588,7 +606,7 @@ xml_parent_candidate_set(cxobj *xn, * @retval flag Flag value(s), see XML_FLAG_MARK et al */ uint16_t -xml_flag(cxobj *xn, +xml_flag(cxobj *xn, uint16_t flag) { return xn->x_flags&flag; @@ -600,7 +618,7 @@ xml_flag(cxobj *xn, * @param[in] flag Flag values to set, see XML_FLAG_MARK et al */ int -xml_flag_set(cxobj *xn, +xml_flag_set(cxobj *xn, uint16_t flag) { xn->x_flags |= flag; @@ -613,7 +631,7 @@ xml_flag_set(cxobj *xn, * @param[in] flag Flag value(s) to reset, see XML_FLAG_* */ int -xml_flag_reset(cxobj *xn, +xml_flag_reset(cxobj *xn, uint16_t flag) { xn->x_flags &= ~flag; @@ -633,7 +651,7 @@ xml_creator_add(cxobj *xn, { int retval = -1; cg_var *cv; - + if (!is_element(xn)) return 0; if (xn->x_creators == NULL){ @@ -642,7 +660,7 @@ xml_creator_add(cxobj *xn, goto done; } } - if ((cv = cvec_find(xn->x_creators, name)) == NULL) + if ((cv = cvec_find(xn->x_creators, name)) == NULL) cvec_add_string(xn->x_creators, name, NULL); retval = 0; done: @@ -661,7 +679,7 @@ xml_creator_rm(cxobj *xn, char *name) { cg_var *cv; - + if (!is_element(xn)) return 0; if ((cv = cvec_find(xn->x_creators, name)) == NULL) @@ -713,11 +731,11 @@ xml_creator_len(cxobj *xn) * @retval -1 Error */ int -xml_creator_copy(cxobj *x0, +xml_creator_copy(cxobj *x0, cxobj *x1) { int retval = -1; - + if (x0->x_creators) if ((x1->x_creators = cvec_dup(x0->x_creators)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_dup"); @@ -732,6 +750,7 @@ xml_creator_copy(cxobj *x0, * * @param[in] x XML tree * @param[in] arg FIle + * @retval see xml_apply */ static int creator_print_fn(cxobj *x, @@ -739,7 +758,7 @@ creator_print_fn(cxobj *x, { FILE *f = (FILE *)arg; cg_var *cv; - + if (x->x_creators == NULL) return 0; cv = NULL; @@ -764,6 +783,7 @@ xml_creator_print(FILE *f, } /*! Get value of xnode + * * @param[in] xn xml node * @retval value of xml node */ @@ -776,13 +796,14 @@ xml_value(cxobj *xn) } /*! Set value of xml node, value is copied + * * @param[in] xn xml node * @param[in] val new value, null-terminated string, copied by function * @retval 0 OK - * @retval -1 on error with clicon-err set + * @retval -1 On error with clicon-err set */ int -xml_value_set(cxobj *xn, +xml_value_set(cxobj *xn, char *val) { int retval = -1; @@ -810,13 +831,14 @@ xml_value_set(cxobj *xn, } /*! Append value of xnode, value is copied + * * @param[in] xn xml node * @param[in] val appended value, null-terminated string, copied by function * @retval new value * @retval NULL on error with clicon-err set, or if value is set to NULL */ int -xml_value_append(cxobj *xn, +xml_value_append(cxobj *xn, char *val) { int retval = -1; @@ -845,6 +867,7 @@ xml_value_append(cxobj *xn, } /*! Get type of xnode + * * @param[in] xn xml node * @retval type of xml node */ @@ -858,12 +881,13 @@ xml_type(cxobj *xn) } /*! Set type of xnode + * * @param[in] xn xml node * @param[in] type new type * @retval type old type */ -static enum cxobj_type -xml_type_set(cxobj *xn, +static enum cxobj_type +xml_type_set(cxobj *xn, enum cxobj_type type) { enum cxobj_type old = xn->x_type; @@ -873,12 +897,13 @@ xml_type_set(cxobj *xn, } /*! Get number of children + * * @param[in] xn xml node * @retval number of children in XML tree * @see xml_child_nr_type * @see xml_child_nr_notype */ -int +int xml_child_nr(cxobj *xn) { if (xn == NULL) { @@ -890,14 +915,15 @@ xml_child_nr(cxobj *xn) } /*! Get number of children of EXCEPT specific type + * * @param[in] xn xml node * @param[in] type XML type or -1 for all * @retval number of typed children in XML tree (except type) * @see xml_child_nr * @see xml_child_nr_type */ -int -xml_child_nr_notype(cxobj *xn, +int +xml_child_nr_notype(cxobj *xn, enum cxobj_type type) { cxobj *x = NULL; @@ -913,14 +939,15 @@ xml_child_nr_notype(cxobj *xn, } /*! Get number of children of specific type + * * @param[in] xn xml node * @param[in] type XML type or -1 for all * @retval number of typed children in XML tree * @see xml_child_nr * @see xml_child_nr_notype */ -int -xml_child_nr_type(cxobj *xn, +int +xml_child_nr_type(cxobj *xn, enum cxobj_type type) { cxobj *x = NULL; @@ -928,12 +955,13 @@ xml_child_nr_type(cxobj *xn, if (!is_element(xn)) return 0; - while ((x = xml_child_each(xn, x, type)) != NULL) + while ((x = xml_child_each(xn, x, type)) != NULL) len++; return len; } /*! Get a specific child + * * @param[in] xn xml node * @param[in] i the number of the child, eg order in children vector * @retval xml The child xml node @@ -942,7 +970,7 @@ xml_child_nr_type(cxobj *xn, * @see xml_child_order */ cxobj * -xml_child_i(cxobj *xn, +xml_child_i(cxobj *xn, int i) { if (xn == NULL || i < 0) { @@ -956,6 +984,7 @@ xml_child_i(cxobj *xn, } /*! Get a specific child of a specific type + * * @param[in] xn xml node * @param[in] i the number of the child of specific type * @param[in] type Child type @@ -963,13 +992,13 @@ xml_child_i(cxobj *xn, * @see xml_child_i */ cxobj * -xml_child_i_type(cxobj *xn, +xml_child_i_type(cxobj *xn, int i, enum cxobj_type type) { cxobj *x = NULL; int it = 0; - + if (!is_element(xn)) return NULL; while ((x = xml_child_each(xn, x, type)) != NULL) { @@ -980,14 +1009,15 @@ xml_child_i_type(cxobj *xn, } /*! Set specific child + * * @param[in] xn xml node * @param[in] i the number of the child, eg order in children vector * @param[in] xc The child to set at position i * @retval 0 OK */ cxobj * -xml_child_i_set(cxobj *xt, - int i, +xml_child_i_set(cxobj *xt, + int i, cxobj *xc) { if (!is_element(xt)) @@ -998,14 +1028,15 @@ xml_child_i_set(cxobj *xt, } /*! Get the order of child + * * @param[in] xp xml parent node * @param[in] xc the xml child to look for * @retval i The order of the child - * @retval -1 if no such child, or empty child + * @retval -1 if no such child, or empty child * @see xml_child_i */ int -xml_child_order(cxobj *xp, +xml_child_order(cxobj *xp, cxobj *xc) { cxobj *x = NULL; @@ -1056,12 +1087,12 @@ xml_child_order(cxobj *xp, * @see xml_child_each_attr hardcoded for sorted list and attributes */ cxobj * -xml_child_each(cxobj *xparent, - cxobj *xprev, +xml_child_each(cxobj *xparent, + cxobj *xprev, enum cxobj_type type) { int i; - cxobj *xn = NULL; + cxobj *xn = NULL; if (xparent == NULL) return NULL; @@ -1094,11 +1125,11 @@ xml_child_each(cxobj *xparent, * @see xml_child_each */ cxobj * -xml_child_each_attr(cxobj *xparent, - cxobj *xprev) +xml_child_each_attr(cxobj *xparent, + cxobj *xprev) { int i; - cxobj *xn = NULL; + cxobj *xn = NULL; if (xparent == NULL) return NULL; @@ -1121,6 +1152,7 @@ xml_child_each_attr(cxobj *xparent, } /*! Extend child vector with one and insert xml node there + * * @note does not do anything with child, you may need to set its parent, etc * @see xml_child_insert_pos * XXX could insert hint if we know this is a yang list and not a leaf to increase start. @@ -1166,7 +1198,7 @@ xml_child_insert_pos(cxobj *xp, int i) { size_t size; - + if (!is_element(xp)) return 0; xp->x_childvec_len++; @@ -1188,6 +1220,7 @@ xml_child_insert_pos(cxobj *xp, } /*! Set a childvec to a specific size, fill with children after + * * @code * xml_childvec_set(x, 2); * xml_child_i_set(x, 0, xc0) @@ -1195,7 +1228,7 @@ xml_child_insert_pos(cxobj *xp, * @endcode */ int -xml_childvec_set(cxobj *x, +xml_childvec_set(cxobj *x, int len) { if (!is_element(x)) @@ -1226,7 +1259,7 @@ xml_childvec_get(cxobj *x) * @param[in] x XML node * @param[in] xv Clixon xml vector * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * @note xv is not same type as x_childvec */ int @@ -1265,13 +1298,13 @@ clixon_child_xvec_append(cxobj *xn, * @see xml_sort_insert */ cxobj * -xml_new(char *name, +xml_new(char *name, cxobj *xp, enum cxobj_type type) { struct xml *x = NULL; size_t sz; - + switch (type){ case CX_ELMNT: sz = sizeof(struct xml); @@ -1295,7 +1328,7 @@ xml_new(char *name, return NULL; if (xp){ xml_parent_set(x, xp); - if (xml_child_append(xp, x) < 0) + if (xml_child_append(xp, x) < 0) return NULL; x->_x_i = xml_child_nr(xp)-1; } @@ -1341,6 +1374,7 @@ xml_new_body(char *name, /*! Return yang spec of node. + * * Not necessarily set. Either has not been set yet (by xml_spec_set( or anyxml. */ yang_stmt * @@ -1352,7 +1386,7 @@ xml_spec(cxobj *x) } int -xml_spec_set(cxobj *x, +xml_spec_set(cxobj *x, yang_stmt *spec) { if (!is_element(x)) @@ -1362,6 +1396,7 @@ xml_spec_set(cxobj *x, } /*! Return (cached) cligen variable value of xml node + * * @param[in] x XML node (body and leaf/leaf-list) * @retval cv CLIgen variable containing value of x body * @retval NULL @@ -1378,6 +1413,7 @@ xml_cv(cxobj *x) } /*! Set (cached) cligen variable value of xml node + * * @param[in] x XML node (body and leaf/leaf-list) * @param[in] cv CLIgen variable containing value of x body * @retval 0 OK @@ -1386,7 +1422,7 @@ xml_cv(cxobj *x) * @see xml_cv_cache */ int -xml_cv_set(cxobj *x, +xml_cv_set(cxobj *x, cg_var *cv) { if (!is_element(x)) @@ -1404,9 +1440,9 @@ xml_cv_set(cxobj *x, * * @param[in] xp Base XML object * @param[in] name Node name - * * @retval xmlobj if found. * @retval NULL if no such node found. + * * There are several issues with this function: * @note (1) Ignores prefix which means namespaces are ignored * @note (2) Does not differentiate between element,attributes and body. You usually want elements. @@ -1415,7 +1451,7 @@ xml_cv_set(cxobj *x, * @see xml_find_type A more generic function fixes (1) and (2) above */ cxobj * -xml_find(cxobj *xp, +xml_find(cxobj *xp, char *name) { cxobj *x = NULL; @@ -1425,24 +1461,25 @@ xml_find(cxobj *xp, } if (!is_element(xp)) return NULL; - while ((x = xml_child_each(xp, x, -1)) != NULL) + while ((x = xml_child_each(xp, x, -1)) != NULL) if (strcmp(name, xml_name(x)) == 0) break; /* x is set */ return x; } /*! Append xc as child to xp. Remove xc from previous parent. + * * @param[in] xp Parent xml node. If NULL just remove from old parent. * @param[in] xc Child xml node to insert under xp * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * @see xml_wrap * @see xml_insert * @note xc is not sorted correctly, need to call xml_sort on parent * @see xml_insert which is a higher layer function including yang and sorting */ int -xml_addsub(cxobj *xp, +xml_addsub(cxobj *xp, cxobj *xc) { int retval = -1; @@ -1467,7 +1504,7 @@ xml_addsub(cxobj *xp, goto done; /* Set new parent in child */ xml_parent_set(xc, xp); - /* Ensure default namespace is not duplicated + /* Ensure default namespace is not duplicated * here only remove duplicate default namespace, there may be more */ /* 1. Get parent default namespace */ if (xml2ns(xp, NULL, &pns) < 0) @@ -1479,7 +1516,7 @@ xml_addsub(cxobj *xp, (cns = xml_value(xa)) != NULL){ /* 3. check if same, if so remove child's */ if (strcmp(pns, cns) == 0) - xml_purge(xa); + xml_purge(xa); } /* clear namespace context cache of child */ nscache_clear(xc); @@ -1494,6 +1531,7 @@ xml_addsub(cxobj *xp, } /*! Wrap a new node between a parent xml node (xp) and all its children + * * Before: xp --> xc* * After: xp --> xw --> xc* * @param[in] xp Parent xml node @@ -1503,7 +1541,7 @@ xml_addsub(cxobj *xp, * @see xml_wrap (wrap s single node) */ cxobj * -xml_wrap_all(cxobj *xp, +xml_wrap_all(cxobj *xp, char *tag) { cxobj *xw; /* new wrap node */ @@ -1522,6 +1560,7 @@ xml_wrap_all(cxobj *xp, } /*! Wrap a new element above a single xml node (xc) with new tag + * * Before: xp --> xc # specific child (xp can be NULL) * After: xp --> xt(tag) --> xc * @param[in] xp Parent xml node @@ -1532,7 +1571,7 @@ xml_wrap_all(cxobj *xp, * @see xml_wrap_all (wrap all children of a node, not just one) */ cxobj * -xml_wrap(cxobj *xc, +xml_wrap(cxobj *xc, char *tag) { cxobj *xw; /* new wrap node */ @@ -1548,9 +1587,10 @@ xml_wrap(cxobj *xc, } /*! Remove and free an xml node child from xml parent - * @param[in] xc xml child node (to be removed and freed) - * @retval 0 OK - * @retval -1 + * + * @param[in] xc xml child node (to be removed and freed) + * @retval 0 OK + * @retval -1 Error * @note you cannot remove xchild in the loop (unless you keep track of xprev) * @note Linear complexity - use xml_child_rm if possible * @see xml_free Free, dont remove from parent @@ -1574,23 +1614,24 @@ xml_purge(cxobj *xc) if (xml_child_rm(xp, i) < 0) goto done; } - xml_free(xc); + xml_free(xc); retval = 0; done: - return retval; + return retval; } /*! Remove child xml node from parent xml node. No free and child is root + * * @param[in] xp xml parent node * @param[in] i Number of xml child node (to remove) * @retval 0 OK - * @retval -1 + * @retval -1 Error * @note you should not remove xchild in loop (unless you keep track of xprev) * @see xml_rootchild * @see xml_rm Remove the node itself from parent */ int -xml_child_rm(cxobj *xp, +xml_child_rm(cxobj *xp, int i) { int retval = -1; @@ -1620,9 +1661,10 @@ xml_child_rm(cxobj *xp, } /*! Remove this xml node from parent xml node. No freeing and node is new root + * * @param[in] xc xml child node to be removed * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * @note you should not remove xchild in loop (unless you keep track of xprev) * @see xml_child_rm Remove a child of a node */ @@ -1653,6 +1695,7 @@ xml_rm(cxobj *xc) } /*! Remove all children of specific type + * * @param[in] x XML node * @param[in] type Remove all children of xn of this type * @retval 0 OK @@ -1685,6 +1728,7 @@ xml_rm_children(cxobj *xp, /*! Remove top XML object and all children except a single child + * * Given a root xml node, and the i:th child, remove the child from its parent * and return it, remove the parent and all other children. (unwrap) * Before: xp-->[..xc..] @@ -1707,7 +1751,7 @@ xml_rm_children(cxobj *xp, * @see xml_rootchild_node where xc is explicitly given */ int -xml_rootchild(cxobj *xp, +xml_rootchild(cxobj *xp, int i, cxobj **xcp) { @@ -1735,6 +1779,7 @@ xml_rootchild(cxobj *xp, } /*! Remove top XML object and all children except a single (given) child + * * Given a root xml node, remove the child from its parent * , remove the parent and all other children. (unwrap) * Before: xp-->[..xc..] @@ -1746,7 +1791,7 @@ xml_rootchild(cxobj *xp, * @see xml_rootchild where an index is used to find xc */ int -xml_rootchild_node(cxobj *xp, +xml_rootchild_node(cxobj *xp, cxobj *xc) { int retval = -1; @@ -1775,6 +1820,7 @@ xml_rootchild_node(cxobj *xp, } /*! Help function to sorting: enumerate all children according to present order + * * This is so that the child itself know its present order in a list. * When sorting by "ordered by user", the order should remain in its present * state. @@ -1804,7 +1850,7 @@ int xml_enumerate_reset(cxobj *xp) { cxobj *x = NULL; - + if (!is_element(xp)) return 0; while ((x = xml_child_each(xp, x, -1)) != NULL) @@ -1813,6 +1859,7 @@ xml_enumerate_reset(cxobj *xp) } /*! Get the enumeration of a single child set by enumeration of parent + * * @see xml_children_enumerate * @note that it has to be called right after xml_children_enumerate. If not, * there are many cases where this info is stale. @@ -1827,6 +1874,7 @@ xml_enumerate_get(cxobj *x) } /*! Get the first sub-node which is an XML body. + * * @param[in] xn xml tree node * @retval The returned body as a pointer to the name string * @retval NULL if no such node or no body in found node @@ -1843,12 +1891,13 @@ xml_body(cxobj *xn) if (!is_element(xn)) return NULL; - while ((xb = xml_child_each(xn, xb, CX_BODY)) != NULL) + while ((xb = xml_child_each(xn, xb, CX_BODY)) != NULL) return xml_value(xb); return NULL; } /*! Get (first) body of xml node, note could be many + * * @param[in] xt xml tree node * Explaining picture: * xt --> xb (x_type=CX_BODY) @@ -1861,7 +1910,7 @@ xml_body_get(cxobj *xt) if (!is_element(xt)) return NULL; - while ((xb = xml_child_each(xt, xb, CX_BODY)) != NULL) + while ((xb = xml_child_each(xt, xb, CX_BODY)) != NULL) return xb; return NULL; } @@ -1882,7 +1931,7 @@ xml_body_get(cxobj *xt) * @see xml_find_value where a body can be found as well */ char * -xml_find_type_value(cxobj *xt, +xml_find_type_value(cxobj *xt, const char *prefix, const char *name, enum cxobj_type type) @@ -1912,7 +1961,7 @@ xml_find_type_value(cxobj *xt, * @see xml_find_value where a body can be found as well */ cxobj * -xml_find_type(cxobj *xt, +xml_find_type(cxobj *xt, const char *prefix, const char *name, enum cxobj_type type) @@ -1920,7 +1969,7 @@ xml_find_type(cxobj *xt, cxobj *x = NULL; int pmatch; /* prefix match */ char *xprefix; /* xprefix */ - + if (!is_element(xt)) return NULL; while ((x = xml_child_each(xt, x, type)) != NULL) { @@ -1952,24 +2001,25 @@ xml_find_type(cxobj *xt, * return x_value */ char * -xml_find_value(cxobj *xt, +xml_find_value(cxobj *xt, const char *name) { cxobj *x = NULL; - + if (!is_element(xt)) return NULL; - while ((x = xml_child_each(xt, x, -1)) != NULL) + while ((x = xml_child_each(xt, x, -1)) != NULL) if (strcmp(name, xml_name(x)) == 0) return xml_value(x); return NULL; } /*! Find and return a body (string) of a sub xml node - * @param[in] xn xml tree node - * @param[in] name name of xml tree node - * @retval The returned body as a pointer to the name string - * @retval NULL if no such node or no body in found node + * + * @param[in] xn xml tree node + * @param[in] name name of xml tree node + * @retval str The returned body as a pointer to the name string + * @retval NULL If no such node or no body in found node * @note, make a copy of the return value to use it properly * @see xml_find_value * Explaining picture: @@ -1977,14 +2027,14 @@ xml_find_value(cxobj *xt, * x_name=name return x_value */ char * -xml_find_body(cxobj *xt, +xml_find_body(cxobj *xt, const char *name) { cxobj *x=NULL; if (!is_element(xt)) return NULL; - while ((x = xml_child_each(xt, x, -1)) != NULL) + while ((x = xml_child_each(xt, x, -1)) != NULL) if (strcmp(name, xml_name(x)) == 0) return xml_body(x); return NULL; @@ -2005,7 +2055,7 @@ xml_find_body(cxobj *xt, * return x */ cxobj * -xml_find_body_obj(cxobj *xt, +xml_find_body_obj(cxobj *xt, const char *name, char *val) { @@ -2026,6 +2076,7 @@ xml_find_body_obj(cxobj *xt, } /*! Free an xl sub-tree recursively, but do not remove it from parent + * * @param[in] x the xml tree to be freed. * @see xml_purge where x is also removed from parent */ @@ -2065,7 +2116,7 @@ xml_free(cxobj *x) case CX_BODY: case CX_ATTR: if (x->x_value_cb) - cbuf_free(x->x_value_cb); + cbuf_free(x->x_value_cb); break; default: break; @@ -2076,18 +2127,19 @@ xml_free(cxobj *x) } /*! Copy single xml node from x0 to x1 without copying children + * * @param[in] x0 Source XML tree * @param[in] x1 Destination XML tree (must exist) * @retval 0 OK * @retval -1 Error */ int -xml_copy_one(cxobj *x0, +xml_copy_one(cxobj *x0, cxobj *x1) { int retval = -1; char *s; - + if (x0 == NULL || x1 == NULL){ clicon_err(OE_XML, EINVAL, "x0 or x1 is NULL"); goto done; @@ -2137,8 +2189,8 @@ xml_copy_one(cxobj *x0, * @endcode * @see xml_dup */ -int -xml_copy(cxobj *x0, +int +xml_copy(cxobj *x0, cxobj *x1) { int retval = -1; @@ -2182,6 +2234,7 @@ xml_dup(cxobj *x0) #if 1 /* XXX At some point migrate this code to the clixon_xml_vec.[ch] API */ /*! Append a new xml tree to an existing xml vector last in the list + * * @param[in] x XML tree (append this to vector) * @param[in,out] vec XML tree vector * @param[in,out] len Length of XML tree vector @@ -2201,8 +2254,8 @@ xml_dup(cxobj *x0) * @see clixon_xvec_append which is its own encapsulated xml vector datatype */ int -cxvec_append(cxobj *x, - cxobj ***vec, +cxvec_append(cxobj *x, + cxobj ***vec, int *len) { int retval = -1; @@ -2218,6 +2271,7 @@ cxvec_append(cxobj *x, } /*! Prepend a new xml tree to an existing xml vector first in the list + * * @param[in] x XML tree (append this to vector) * @param[in,out] vec XML tree vector * @param[in,out] len Length of XML tree vector @@ -2237,8 +2291,8 @@ cxvec_append(cxobj *x, * @see clixon_xvec_prepend which is its own encapsulated xml vector datatype */ int -cxvec_prepend(cxobj *x, - cxobj ***vec, +cxvec_prepend(cxobj *x, + cxobj ***vec, int *len) { int retval = -1; @@ -2285,9 +2339,9 @@ cxvec_prepend(cxobj *x, * @see xml_apply_ancestor for marking all parents recursively */ int -xml_apply(cxobj *xn, - enum cxobj_type type, - xml_applyfn_t fn, +xml_apply(cxobj *xn, + enum cxobj_type type, + xml_applyfn_t fn, void *arg) { int retval = -1; @@ -2315,10 +2369,11 @@ xml_apply(cxobj *xn, } retval = 0; done: - return retval; + return retval; } /*! Apply a function call on top object and all xml node children recursively + * * @param[in] xn XML node * @param[in] type Matching type or -1 for any * @param[in] fn Callback @@ -2329,9 +2384,9 @@ xml_apply(cxobj *xn, * @see xml_apply not including top object */ int -xml_apply0(cxobj *xn, - enum cxobj_type type, - xml_applyfn_t fn, +xml_apply0(cxobj *xn, + enum cxobj_type type, + xml_applyfn_t fn, void *arg) { int retval = -1; @@ -2346,10 +2401,11 @@ xml_apply0(cxobj *xn, else /* 0 */ retval = xml_apply(xn, type, fn, arg); done: - return retval; + return retval; } /*! Apply a function call recursively on all ancestors + * * Recursively traverse upwards to all ancestor nodes in a parse-tree and apply fn(arg) for * each object found. The function is called with the xml node and an * argument as args. @@ -2371,9 +2427,9 @@ xml_apply0(cxobj *xn, * @note It does not apply fn to the root node,.. */ int -xml_apply_ancestor(cxobj *xn, - xml_applyfn_t fn, - void *arg) +xml_apply_ancestor(cxobj *xn, + xml_applyfn_t fn, + void *arg) { int retval = -1; cxobj *xp = NULL; @@ -2390,10 +2446,11 @@ xml_apply_ancestor(cxobj *xn, } retval = 0; done: - return retval; + return retval; } /*! Is xpp ancestor of x? + * * @param[in] x XML node * @param[in] xpp Potential ancestor of x in XML tree * @retval 1 Yes, xpp is ancestor of x @@ -2416,6 +2473,7 @@ xml_isancestor(cxobj *x, } /*! Get ultimate root ancestor of an xml-node: top-level node without parent + * * @param[in] xn XML node * @retval xr XML root node (can be xn) */ @@ -2426,12 +2484,13 @@ xml_root(cxobj *xn) cxobj *x = NULL; x = xn; - while ((xp = xml_parent(x)) != NULL) + while ((xp = xml_parent(x)) != NULL) x = xp; return x; } /*! Map xml operation from string to enumeration + * * @param[in] opstr String, eg "merge" * @param[out] op Enumeration, eg OP_MERGE * @code @@ -2440,7 +2499,7 @@ xml_root(cxobj *xn) * @endcode */ int -xml_operation(char *opstr, +xml_operation(char *opstr, enum operation_type *op) { if (strcmp("merge", opstr) == 0) @@ -2463,6 +2522,7 @@ xml_operation(char *opstr, } /*! Map xml operation from enumeration to string + * * @param[in] op enumeration operation, eg OP_MERGE,... * @retval str String, eg "merge". Static string, no free necessary * @code @@ -2495,6 +2555,7 @@ xml_operation2str(enum operation_type op) } /*! Map xml insert attribute from string to enumeration + * * @param[in] instr String, eg "first" * @param[out] ins Enumeration, eg INS_FIRST * @code @@ -2503,7 +2564,7 @@ xml_operation2str(enum operation_type op) * @endcode */ int -xml_attr_insert2val(char *instr, +xml_attr_insert2val(char *instr, enum insert_type *ins) { if (strcmp("first", instr) == 0) @@ -2528,6 +2589,8 @@ xml_attr_insert2val(char *instr, * @param[in] value Attribute value * @param[in] prefix Attribute prefix, or NULL * @param[in] namespace Attribute prefix, if NULL do not add namespace mapping + * @retval 0 OK + * @retval -1 Error */ int xml_add_attr(cxobj *xn, @@ -2549,7 +2612,7 @@ xml_add_attr(cxobj *xn, if (namespace){ if (xml2ns(xn, prefix, &ns) < 0) goto done; - if (ns == NULL && xmlns_set(xn, prefix, namespace) < 0) + if (ns == NULL && xmlns_set(xn, prefix, namespace) < 0) goto done; } retval = 0; @@ -2563,18 +2626,20 @@ xml_add_attr(cxobj *xn, * @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. * @param[in] x XML tree that is logged without prettyprint * @param[in] format Message to print as argv. - * @see clicon_debug_xml which uses debug setting instead of direct syslog + * @retval 0 OK + * @retval -1 Error + * @see clixon_debug_xml which uses debug setting instead of direct syslog */ int -clicon_log_xml(int level, +clicon_log_xml(int level, cxobj *x, const char *format, ...) { + int retval = -1; va_list args; size_t len; char *msg = NULL; cbuf *cb = NULL; - int retval = -1; size_t trunc; /* Print xml as cbuf */ @@ -2588,7 +2653,6 @@ clicon_log_xml(int level, 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; @@ -2620,28 +2684,30 @@ clicon_log_xml(int level, return retval; } -/*! Specialization of clicon_debug with xml tree +/*! Specialization of clixon_debug with xml tree * * @param[in] dbglevel Mask of CLIXON_DBG_DEFAULT and other masks * @param[in] x XML tree that is logged without prettyprint * @param[in] format Message to print as argv. + * @retval 0 OK + * @retval -1 Error * @see clicon_log_xml For syslog - * @see clicon_debug base function and see CLIXON_DBG_* flags + * @see clixon_debug base function and see CLIXON_DBG_* flags */ int -clicon_debug_xml(int dbglevel, +clixon_debug_xml(int dbglevel, cxobj *x, const char *format, ...) { + int retval = -1; va_list args; size_t len; char *msg = NULL; cbuf *cb = NULL; - int retval = -1; size_t trunc; /* Mask debug level with global dbg variable */ - if ((dbglevel & clicon_debug_get()) == 0) + if ((dbglevel & clixon_debug_get()) == 0) return 0; /* Print xml as cbuf */ if ((cb = cbuf_new()) == NULL){ @@ -2654,7 +2720,6 @@ clicon_debug_xml(int dbglevel, 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; @@ -2675,7 +2740,7 @@ clicon_debug_xml(int dbglevel, va_end(args); /* Actually log it */ - clicon_debug(dbglevel, "%s: %s", msg, cbuf_get(cb)); + clixon_debug(dbglevel, "%s: %s", msg, cbuf_get(cb)); retval = 0; done: @@ -2687,11 +2752,8 @@ clicon_debug_xml(int dbglevel, } #ifdef XML_EXPLICIT_INDEX -/* - * - */ - /*! Is this XML object a search index, ie it is registered as a yang clixon cc:search_index + * * Is this xml node a search index and does it have a parent that is a list and a grandparent * where a search-vector can be placed * @param[in] x XML object @@ -2703,7 +2765,7 @@ xml_search_index_p(cxobj *x) { yang_stmt *y; cxobj *xp; - + /* The index variable has a yang spec */ if ((y = xml_spec(x)) == NULL) return 0; @@ -2724,6 +2786,7 @@ xml_search_index_p(cxobj *x) } /*! Free all search vector pairs of this XML node + * * @param[in] x XML object * @retval 0 OK * @retval -1 Error @@ -2745,6 +2808,7 @@ xml_search_index_free(cxobj *x) } /*! Add single search vector pair to this XML node + * * @param[in] x XML object * @param[in] name Name of index variable * @retval 0 OK @@ -2779,6 +2843,7 @@ xml_search_index_add(cxobj *x, } /*! Add single search vector pair to this XML node + * * @param[in] x XML object * @param[in] name Name of index variable * @retval 0 OK @@ -2806,6 +2871,7 @@ xml_search_index_get(cxobj *x, /*--------------------------------------------------*/ /*! Get sorted index vector for list for variable "name" + * * @param[in] xp XML parent object * @param[in] name Name of index variable * @param[out] xvec XML object search vector @@ -2832,8 +2898,11 @@ xml_search_vector_get(cxobj *xp, } /*! Insert a new cxobj into search index vector for list for variable "name" - * @param[in] xp XML parent object (the list element) - * @param[in] xi XML index object (that should be added) + * + * @param[in] xp XML parent object (the list element) + * @param[in] xi XML index object (that should be added) + * @retval 0 OK + * @retval -1 Error */ int xml_search_child_insert(cxobj *xp, @@ -2845,13 +2914,13 @@ xml_search_child_insert(cxobj *xp, cxobj *xpp; int i; int len; - + indexvar = xml_name(xi); if ((xpp = xml_parent(xp)) == NULL) goto ok; /* Find base vector in grandparent */ if ((si = xml_search_index_get(xpp, indexvar)) == NULL){ - /* If not found add base vector in grand-parent */ + /* If not found add base vector in grand-parent */ if ((si = xml_search_index_add(xpp, indexvar)) == NULL) goto done; } @@ -2864,13 +2933,16 @@ xml_search_child_insert(cxobj *xp, goto done; ok: retval = 0; - done: + done: return retval; } /*! Remove a single cxobj from search vector - * @param[in] xp XML parent object (the list element) - * @param[in] xi XML index object (that should be added) + * + * @param[in] xp XML parent object (the list element) + * @param[in] xi XML index object (that should be added) + * @retval 0 OK + * @retval -1 Error */ int xml_search_child_rm(cxobj *xp, @@ -2883,14 +2955,14 @@ xml_search_child_rm(cxobj *xp, int len; struct search_index *si; int eq = 0; - + indexvar = xml_name(xi); if ((xpp = xml_parent(xp)) == NULL) goto ok; /* Find base vector in grandparent */ if ((si = xml_search_index_get(xpp, indexvar)) == NULL) goto ok; - + /* Find element using binary search and then remove */ len = clixon_xvec_len(si->si_xvec); if ((i = xml_search_indexvar_binary_pos(xp, indexvar, si->si_xvec, 0, len, len, &eq)) < 0) @@ -2898,7 +2970,7 @@ xml_search_child_rm(cxobj *xp, // if (clixon_xvec_i(si->si_xvec, i) == xp) if (eq) if (clixon_xvec_rm_pos(si->si_xvec, i) < 0) - goto done; + goto done; ok: retval = 0; done: @@ -2925,15 +2997,15 @@ xml_search_child_rm(cxobj *xp, * If you need to delete a node you can do somethjing like: */ cxobj * -xml_child_index_each(cxobj *xparent, +xml_child_index_each(cxobj *xparent, char *name, - cxobj *xprev, + cxobj *xprev, enum cxobj_type type) { - cxobj *xn = NULL; + cxobj *xn = NULL; clixon_xvec *xv = NULL; int i; - + if (xparent == NULL) return NULL; if (!is_element(xparent)) diff --git a/lib/src/clixon_xml_bind.c b/lib/src/clixon_xml_bind.c index f8848e84..38029056 100644 --- a/lib/src/clixon_xml_bind.c +++ b/lib/src/clixon_xml_bind.c @@ -89,6 +89,7 @@ static int _yang_unknown_anydata = 0; static int _netconf_message_id_optional = 0; /*! Kludge to equate unknown XML with anydata + * * The problem with this is that its global and should be bound to a handle */ int @@ -99,6 +100,7 @@ xml_bind_yang_unknown_anydata(int val) } /*! Kludge to set message_id_optional + * * The problem with this is that its global and should be bound to a handle */ int @@ -109,6 +111,7 @@ xml_bind_netconf_message_id_optional(int val) } /*! After yang binding, bodies of containers and lists are stripped from XML bodies + * * May apply to other nodes? * Exception for bodies marked with XML_FLAG_BODYKEY, see text syntax parsing * @see text_mark_bodies @@ -119,7 +122,7 @@ strip_body_objects(cxobj *xt) yang_stmt *yt; enum rfc_6020 keyword; cxobj *xb; - + if ((yt = xml_spec(xt)) != NULL){ keyword = yang_keyword_get(yt); if (keyword == Y_LIST || keyword == Y_CONTAINER){ @@ -257,7 +260,7 @@ populate_self_parent(cxobj *xt, * @see populate_self_parent */ static int -populate_self_top(cxobj *xt, +populate_self_top(cxobj *xt, yang_stmt *yspec, cxobj **xerr) { @@ -374,7 +377,7 @@ populate_self_top(cxobj *xt, */ int xml_bind_yang(clicon_handle h, - cxobj *xt, + cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr) @@ -399,7 +402,7 @@ xml_bind_yang(clicon_handle h, goto done; } -/*! +/*! Bind yang opt * * @param[in] h Clixon handle (sometimes NULL) * @param[in] xt XML tree node @@ -413,7 +416,7 @@ xml_bind_yang(clicon_handle h, */ static int xml_bind_yang0_opt(clicon_handle h, - cxobj *xt, + cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj *xsibling, @@ -530,7 +533,7 @@ xml_bind_yang0_opt(clicon_handle h, */ int xml_bind_yang0(clicon_handle h, - cxobj *xt, + cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr) @@ -541,7 +544,7 @@ 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(xt, yspec, xerr)) < 0) goto done; break; case YB_PARENT: @@ -622,7 +625,7 @@ xml_bind_yang_rpc_rpc(clicon_handle h, /* xml_bind_yang need to have parent with yang spec for * recursive population to work. Therefore, assign input yang * to rpc level although not 100% intuitive */ - xml_spec_set(x, yi); + xml_spec_set(x, yi); if ((ret = xml_bind_yang(h, x, YB_PARENT, NULL, xerr)) < 0) goto done; if (ret == 0) @@ -681,7 +684,7 @@ xml_bind_yang_rpc_action(clicon_handle h, } /*! Find yang spec association of XML node for incoming RPC starting with - * + * * Incoming RPC has an "input" structure that is not taken care of by xml_bind_yang * @param[in] h Clixon handle * @param[in] xrpc XML rpc node @@ -713,9 +716,9 @@ xml_bind_yang_rpc(clicon_handle h, char *rpcname; /* RPC name */ char *name; cxobj *xc; - + opname = xml_name(xrpc); - if ((strcmp(opname, "hello")) == 0){ + if ((strcmp(opname, "hello")) == 0){ /* Hello: dont bind, dont appear in any yang spec, just ensure there is nothing apart from * session-id or capabilities/capability tags * If erro, just log, drop and close, rpc-error should not be sent since it is not rpc @@ -845,7 +848,7 @@ xml_bind_yang_rpc_reply(clicon_handle h, char *opname; cbuf *cberr = NULL; cxobj *xc; - + opname = xml_name(xrpc); if (strcmp(opname, "rpc-reply")){ if ((cberr = cbuf_new()) == NULL){ @@ -874,7 +877,7 @@ xml_bind_yang_rpc_reply(clicon_handle h, break; } if (yo != NULL){ - xml_spec_set(xrpc, yo); + xml_spec_set(xrpc, yo); /* Special case for ok and rpc-error */ if ((xc = xml_child_i_type(xrpc, 0, CX_ELMNT)) != NULL && (strcmp(xml_name(xc),"rpc-error") == 0 @@ -920,7 +923,7 @@ xml_bind_special(cxobj *xd, { int retval = -1; yang_stmt *yd; - + if (yang_abs_schema_nodeid(yspec, schema_nodeid, &yd) < 0) goto done; if (yd) diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index 44dddc26..f009e42e 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -88,7 +88,7 @@ changelog_rename(clicon_handle h, int retval = -1; xp_ctx *xctx = NULL; char *str = NULL; - + if (tag == NULL){ clicon_err(OE_XML, 0, "tag required"); goto done; @@ -160,7 +160,7 @@ changelog_insert(clicon_handle h, { int retval = -1; cxobj *x; - + if (xnew == NULL){ clicon_err(OE_XML, 0, "new required"); goto done; @@ -216,10 +216,12 @@ changelog_move(clicon_handle h, } /*! Perform a changelog operation - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xt XML to upgrade * @param[in] xi Changelog item - + * @retval 0 OK + * @retval -1 Error * @note XXX error handling! * @note XXX xn --> xt xpath may not match */ @@ -311,14 +313,17 @@ changelog_op(clicon_handle h, return retval; fail: retval = 0; - clicon_debug(1, "%s fail op:%s ", __FUNCTION__, op); + clixon_debug(CLIXON_DBG_DEFAULT, "%s fail op:%s ", __FUNCTION__, op); goto done; } /*! Iterate through one changelog item - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xt Changelog list * @param[in] xn XML to upgrade + * @retval 0 OK + * @retval -1 Error */ static int changelog_iterate(clicon_handle h, @@ -331,7 +336,7 @@ changelog_iterate(clicon_handle h, size_t veclen; int ret; int i; - + if (xpath_vec(xch, NULL, "step", &vec, &veclen) < 0) goto done; /* Iterate through changelog items */ @@ -343,7 +348,7 @@ changelog_iterate(clicon_handle h, } retval = 1; done: - clicon_debug(1, "%s retval: %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval: %d", __FUNCTION__, retval); if (vec) free(vec); return retval; @@ -353,7 +358,8 @@ changelog_iterate(clicon_handle h, } /*! Automatic upgrade using changelog - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xt Top-level XML tree to be updated (includes other ns as well) * @param[in] ns Namespace of module (for info) * @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE @@ -367,13 +373,13 @@ changelog_iterate(clicon_handle h, * @see upgrade_callback_register where this function should be registered */ int -xml_changelog_upgrade(clicon_handle h, - cxobj *xt, +xml_changelog_upgrade(clicon_handle h, + cxobj *xt, char *ns, uint16_t op, uint32_t from, uint32_t to, - void *arg, + void *arg, cbuf *cbret) { int retval = -1; @@ -398,7 +404,7 @@ xml_changelog_upgrade(clicon_handle h, * - find all changelogs in the interval: [from, to] * - note it t=0 then no changelog is applied */ - if (xpath_vec(xchlog, NULL, "changelog[namespace=\"%s\"]", + if (xpath_vec(xchlog, NULL, "changelog[namespace=\"%s\"]", &vec, &veclen, ns) < 0) goto done; /* Get all changelogs in the interval [from,to]*/ @@ -448,7 +454,7 @@ clixon_xml_changelog_init(clicon_handle h) if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; - } + } if (clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL) < 0) goto done; if (xml_rootchild(xt, 0, &xt) < 0) @@ -466,7 +472,7 @@ clixon_xml_changelog_init(clicon_handle h) goto done; clicon_err(OE_YANG, 0, "validation failed: %s", cbuf_get(cbret)); goto done; - } + } if (clicon_xml_changelog_set(h, xt) < 0) goto done; xt = NULL; @@ -485,11 +491,14 @@ 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] h Clixon handle * @param[in] xt Top-level XML tree, with children marked with namespaces * @param[in] ns The namespace to select * @param[out] vecp Vector containining XML nodes w namespace. Null-terminated. * @param[out] veclenp Length of vector + * @retval 0 OK + * @retval -1 Error * @note Need to free vec after use with free() * Example * xt ::= instead of : * Ie, no CX_BODY or CX_ELMNT child. */ - if (hasbody==0 && haselement==0) + if (hasbody==0 && haselement==0) (*fn)(f, "/>"); else{ (*fn)(f, ">"); @@ -234,9 +234,9 @@ xml2file_recurse(FILE *f, * for CLI calls, but not for others. */ int -clixon_xml2file(FILE *f, - cxobj *xn, - int level, +clixon_xml2file(FILE *f, + cxobj *xn, + int level, int pretty, char *prefix, clicon_output_cb *fn, @@ -272,7 +272,7 @@ clixon_xml2file(FILE *f, * @see clixon_xml2cbuf_cb print using a callback */ int -xml_print(FILE *f, +xml_print(FILE *f, cxobj *x) { return xml2file_recurse(f, x, 0, 1, NULL, fprintf, 0); @@ -281,12 +281,12 @@ xml_print(FILE *f, /*! Dump cxobj structure with pointers and flags for debugging, internal function */ static int -xml_dump1(FILE *f, +xml_dump1(FILE *f, cxobj *x, int indent) { cxobj *xc; - + if (xml_type(x) != CX_ELMNT) return 0; fprintf(stderr, "%*s %s(%s)", @@ -309,7 +309,7 @@ xml_dump1(FILE *f, } return 0; } - + /*! Dump cxobj structure with pointers and flags for debugging * * @param[in] f UNIX output stream @@ -317,7 +317,7 @@ xml_dump1(FILE *f, * @see xml_print */ int -xml_dump(FILE *f, +xml_dump(FILE *f, cxobj *x) { return xml_dump1(f, x, 0); @@ -331,10 +331,12 @@ xml_dump(FILE *f, * @param[in] pretty Insert \n and spaces to make the xml more readable. * @param[in] prefix Add string to beginning of each line (if pretty) * @param[in] depth Limit levels of child resources: -1 is all, 0 is none, 1 is node itself + * @retval 0 OK + * @retval -1 Error */ static int -clixon_xml2cbuf1(cbuf *cb, - cxobj *x, +clixon_xml2cbuf1(cbuf *cb, + cxobj *x, int level, int pretty, char *prefix, @@ -348,7 +350,7 @@ clixon_xml2cbuf1(cbuf *cb, char *namespace; char *val; int level1; - + if (depth == 0) goto ok; level1 = level*PRETTYPRINT_INDENT; @@ -388,7 +390,7 @@ clixon_xml2cbuf1(cbuf *cb, haselement = 0; xc = NULL; /* print attributes only */ - while ((xc = xml_child_each(x, xc, -1)) != NULL) + while ((xc = xml_child_each(x, xc, -1)) != NULL) switch (xml_type(xc)){ case CX_ATTR: if (clixon_xml2cbuf1(cb, xc, level+1, pretty, prefix, -1) < 0) @@ -404,14 +406,14 @@ clixon_xml2cbuf1(cbuf *cb, break; } /* Check for special case instead of */ - if (hasbody==0 && haselement==0) + if (hasbody==0 && haselement==0) cbuf_append_str(cb, "/>"); else{ cbuf_append_str(cb, ">"); if (pretty && hasbody == 0) cbuf_append_str(cb, "\n"); xc = NULL; - while ((xc = xml_child_each(x, xc, -1)) != NULL) + while ((xc = xml_child_each(x, xc, -1)) != NULL) if (xml_type(xc) != CX_ATTR) if (clixon_xml2cbuf1(cb, xc, level+1, pretty, prefix, depth-1) < 0) goto done; @@ -472,7 +474,7 @@ clixon_xml2cbuf(cbuf *cb, { int retval = -1; cxobj *xc; - + if (skiptop){ xc = NULL; while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL) @@ -489,12 +491,13 @@ clixon_xml2cbuf(cbuf *cb, } /*! Print actual xml tree datastructures (not xml), mainly for debugging + * * @param[in,out] cb Cligen buffer to write to * @param[in] xn Clicon xml tree * @param[in] level Indentation level */ int -xmltree2cbuf(cbuf *cb, +xmltree2cbuf(cbuf *cb, cxobj *x, int level) { @@ -517,7 +520,7 @@ xmltree2cbuf(cbuf *cb, cprintf(cb, " {"); cprintf(cb, "\n"); xc = NULL; - while ((xc = xml_child_each(x, xc, -1)) != NULL) + while ((xc = xml_child_each(x, xc, -1)) != NULL) xmltree2cbuf(cb, xc, level+1); if (xml_child_nr(x)){ for (i=0; i will be: * @note May block on file I/O */ -int -clixon_xml_parse_file(FILE *fp, +int +clixon_xml_parse_file(FILE *fp, yang_bind yb, yang_stmt *yspec, cxobj **xt, @@ -783,8 +786,8 @@ clixon_xml_parse_file(FILE *fp, * @note You need to free the xml parse tree after use, using xml_free() * @note If empty on entry, a new TOP xml will be created named "top" */ -int -clixon_xml_parse_string(const char *str, +int +clixon_xml_parse_string(const char *str, yang_bind yb, yang_stmt *yspec, cxobj **xt, @@ -808,7 +811,6 @@ clixon_xml_parse_string(const char *str, /*! Read XML from var-arg list and parse it into xml tree * * Utility function using stdarg instead of static string. - * @param[in] yb How to bind yang to XML top-level when parsing * @param[in] yspec Yang specification, or NULL * @param[in,out] xtop Top of XML parse tree. If it is NULL, top element @@ -829,9 +831,9 @@ clixon_xml_parse_string(const char *str, * @see clixon_xml_parse_file * @note If vararg list is empty, consider using clixon_xml_parse_string() */ -int +int clixon_xml_parse_va(yang_bind yb, - yang_stmt *yspec, + yang_stmt *yspec, cxobj **xtop, cxobj **xerr, const char *format, ...) @@ -852,7 +854,7 @@ clixon_xml_parse_va(yang_bind yb, va_start(args, format); len = vsnprintf(str, len, format, args) + 1; va_end(args); - retval = clixon_xml_parse_string(str, yb, yspec, xtop, xerr); + retval = clixon_xml_parse_string(str, yb, yspec, xtop, xerr); done: if (str) free(str); @@ -860,6 +862,7 @@ clixon_xml_parse_va(yang_bind yb, } /*! Copy an attribute value(eg message-id) from one xml (eg rpc input) to another xml (eg rpc outgoing) + * * @param[in] xin Get attr value from this XML * @param[in] xout Set attr value to this XML * @param[in] name Attribute name @@ -912,7 +915,7 @@ xml_diff_keys(cbuf *cb, cvk = yang_cvec_get(y); /* Use Y_LIST cache, see ys_populate_list() */ cvi = NULL; while ((cvi = cvec_each(cvk, cvi)) != NULL) { - keyname = cv_string_get(cvi); + keyname = cv_string_get(cvi); keyval = xml_find_body(x, keyname); cprintf(cb, "%*s<%s>%s\n", level, "", keyname, keyval, keyname); } @@ -930,7 +933,7 @@ xml_diff_context(cbuf *cb, int retval = -1; char *prefix; char *namespace = NULL; - + prefix = xml_prefix(xn); if (xml2ns(xn, prefix, &namespace) < 0) goto done; @@ -973,7 +976,7 @@ xml_diff_context(cbuf *cb, */ int xml_diff2cbuf(cbuf *cb, - cxobj *x0, + cxobj *x0, cxobj *x1, int level, int skiptop) @@ -993,7 +996,7 @@ xml_diff2cbuf(cbuf *cb, level1 = level*PRETTYPRINT_INDENT; y0 = xml_spec(x0); /* Traverse x0 and x1 in lock-step */ - x0c = x1c = NULL; + x0c = x1c = NULL; x0c = xml_child_each(x0, x0c, CX_ELMNT); x1c = xml_child_each(x1, x1c, CX_ELMNT); for (;;){ @@ -1117,7 +1120,7 @@ xml_diff2cbuf(cbuf *cb, */ int clixon_xml_diff2cbuf(cbuf *cb, - cxobj *x0, + cxobj *x0, cxobj *x1) { return xml_diff2cbuf(cb, x0, x1, 0, 1); diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 261c7066..b53ba230 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -110,6 +110,7 @@ isxmlns(cxobj *x) } /*! Translate a single xml node to a cligen variable vector. Note not recursive + * * @param[in] xt XML tree containing one top node * @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() @@ -132,8 +133,8 @@ isxmlns(cxobj *x) * @see cvec2xml */ int -xml2cvec(cxobj *xt, - yang_stmt *yt, +xml2cvec(cxobj *xt, + yang_stmt *yt, cvec **cvv0) { int retval = -1; @@ -158,7 +159,7 @@ xml2cvec(cxobj *xt, while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL){ name = xml_name(xc); if ((ys = yang_find_datanode(yt, name)) == NULL){ - clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s", + clixon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s", __FUNCTION__, name, yang_argument_get(yt)); if ((body = xml_body(xc)) != NULL){ if ((cv = cv_new(CGV_STRING)) == NULL){ @@ -172,7 +173,7 @@ xml2cvec(cxobj *xt, } /* 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); + clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason); if (reason) free(reason); } @@ -206,8 +207,8 @@ xml2cvec(cxobj *xt, } } } - if (clicon_debug_get() > 1){ - clicon_debug(CLIXON_DBG_DETAIL, "%s cvv:\n", __FUNCTION__); + if (clixon_debug_get() > 1){ + clixon_debug(CLIXON_DBG_DETAIL, "%s cvv:\n", __FUNCTION__); cvec_print(stderr, cvv); } *cvv0 = cvv; @@ -219,6 +220,7 @@ xml2cvec(cxobj *xt, } /*! Translate a cligen variable vector to an XML tree with depth one + * * @param[in] cvv CLIgen variable vector. Should be freed by cvec_free() * @param[in] toptag The XML tree in xt will have this XML tag * @param[in] xt Parent, or NULL @@ -229,8 +231,8 @@ xml2cvec(cxobj *xt, * @see cvec2xml This does more but has an internal xml2cvec translation */ int -cvec2xml_1(cvec *cvv, - char *toptag, +cvec2xml_1(cvec *cvv, + char *toptag, cxobj *xp, cxobj **xt0) { @@ -244,7 +246,7 @@ cvec2xml_1(cvec *cvv, int i; cv = NULL; - while ((cv = cvec_each(cvv, cv)) != NULL) + while ((cv = cvec_each(cvv, cv)) != NULL) len++; if ((xt = xml_new(toptag, xp, CX_ELMNT)) == NULL) goto err; @@ -275,6 +277,7 @@ cvec2xml_1(cvec *cvv, } /*! Recursive help function to compute differences between two xml trees + * * @param[in] x0 First XML tree * @param[in] x1 Second XML tree * @param[out] x0vec Pointervector to XML nodes existing in only first tree @@ -284,6 +287,8 @@ cvec2xml_1(cvec *cvv, * @param[out] changed_x0 Pointervector to XML nodes changed orig value * @param[out] changed_x1 Pointervector to XML nodes changed wanted value * @param[out] changedlen Length of changed vector + * @retval 0 Ok + * @retval -1 Error * Algorithm to compare two sorted lists A, B: * A 0 1 2 3 5 6 * B 0 2 4 5 6 @@ -299,7 +304,7 @@ cvec2xml_1(cvec *cvv, * @see xml_diff API function, this one is internal and recursive */ static int -xml_diff1(cxobj *x0, +xml_diff1(cxobj *x0, cxobj *x1, cxobj ***x0vec, int *x0veclen, @@ -319,20 +324,20 @@ xml_diff1(cxobj *x0, int eq; /* Traverse x0 and x1 in lock-step */ - x0c = x1c = NULL; + x0c = x1c = NULL; x0c = xml_child_each(x0, x0c, CX_ELMNT); x1c = xml_child_each(x1, x1c, CX_ELMNT); for (;;){ if (x0c == NULL && x1c == NULL) goto ok; else if (x0c == NULL){ - if (cxvec_append(x1c, x1vec, x1veclen) < 0) + if (cxvec_append(x1c, x1vec, x1veclen) < 0) goto done; x1c = xml_child_each(x1, x1c, CX_ELMNT); continue; } else if (x1c == NULL){ - if (cxvec_append(x0c, x0vec, x0veclen) < 0) + if (cxvec_append(x0c, x0vec, x0veclen) < 0) goto done; x0c = xml_child_each(x0, x0c, CX_ELMNT); continue; @@ -340,13 +345,13 @@ xml_diff1(cxobj *x0, /* Both x0c and x1c exists, check if they are yang-equal. */ eq = xml_cmp(x0c, x1c, 0, 0, NULL); if (eq < 0){ - if (cxvec_append(x0c, x0vec, x0veclen) < 0) + if (cxvec_append(x0c, x0vec, x0veclen) < 0) goto done; x0c = xml_child_each(x0, x0c, CX_ELMNT); continue; } else if (eq > 0){ - if (cxvec_append(x1c, x1vec, x1veclen) < 0) + if (cxvec_append(x1c, x1vec, x1veclen) < 0) goto done; x1c = xml_child_each(x1, x1c, CX_ELMNT); continue; @@ -358,9 +363,9 @@ xml_diff1(cxobj *x0, yc0 = xml_spec(x0c); yc1 = xml_spec(x1c); if (yc0 && yc1 && yc0 != yc1){ /* choice */ - if (cxvec_append(x0c, x0vec, x0veclen) < 0) + if (cxvec_append(x0c, x0vec, x0veclen) < 0) goto done; - if (cxvec_append(x1c, x1vec, x1veclen) < 0) + if (cxvec_append(x1c, x1vec, x1veclen) < 0) goto done; } else @@ -371,18 +376,18 @@ xml_diff1(cxobj *x0, if (b0 == NULL && b1 == NULL) ; else if (b0 == NULL || b1 == NULL - || strcmp(b0, b1) != 0 + || strcmp(b0, b1) != 0 ){ - if (cxvec_append(x0c, changed_x0, changedlen) < 0) + if (cxvec_append(x0c, changed_x0, changedlen) < 0) goto done; (*changedlen)--; /* append two vectors */ - if (cxvec_append(x1c, changed_x1, changedlen) < 0) + if (cxvec_append(x1c, changed_x1, changedlen) < 0) goto done; } } - else if (xml_diff1(x0c, x1c, - x0vec, x0veclen, - x1vec, x1veclen, + else if (xml_diff1(x0c, x1c, + x0vec, x0veclen, + x1vec, x1veclen, changed_x0, changed_x1, changedlen)< 0) goto done; } @@ -413,7 +418,7 @@ xml_diff1(cxobj *x0, * @see clixon_xml_diff_print same algorithm but print in +/- diff format */ int -xml_diff(cxobj *x0, +xml_diff(cxobj *x0, cxobj *x1, cxobj ***first, int *firstlen, @@ -426,23 +431,23 @@ xml_diff(cxobj *x0, int retval = -1; *firstlen = 0; - *secondlen = 0; + *secondlen = 0; *changedlen = 0; if (x0 == NULL && x1 == NULL) return 0; if (x1 == NULL){ - if (cxvec_append(x0, first, firstlen) < 0) + if (cxvec_append(x0, first, firstlen) < 0) goto done; goto ok; } if (x0 == NULL){ - if (cxvec_append(x0, second, secondlen) < 0) + if (cxvec_append(x0, second, secondlen) < 0) goto done; goto ok; } if (xml_diff1(x0, x1, - first, firstlen, - second, secondlen, + first, firstlen, + second, secondlen, changed_x0, changed_x1, changedlen) < 0) goto done; ok: @@ -460,7 +465,7 @@ xml_diff(cxobj *x0, * @see xml_diff which returns diff sets */ int -xml_tree_equal(cxobj *x0, +xml_tree_equal(cxobj *x0, cxobj *x1) { int retval = 1; /* Not equal */ @@ -471,9 +476,9 @@ xml_tree_equal(cxobj *x0, char *b1; cxobj *x0c = NULL; /* x0 child */ cxobj *x1c = NULL; /* x1 child */ - + /* Traverse x0 and x1 in lock-step */ - x0c = x1c = NULL; + x0c = x1c = NULL; x0c = xml_child_each(x0, x0c, CX_ELMNT); x1c = xml_child_each(x1, x1c, CX_ELMNT); for (;;){ @@ -510,7 +515,7 @@ xml_tree_equal(cxobj *x0, if (b0 == NULL && b1 == NULL) ; else if (b0 == NULL || b1 == NULL - || strcmp(b0, b1) != 0 + || strcmp(b0, b1) != 0 ){ goto done; } @@ -536,6 +541,8 @@ xml_tree_equal(cxobj *x0, * @param[in] flag Which flag to test for * @param[in] test 1: test that flag is set, 0: test that flag is not set * @param[out] upmark Set if a child (recursively) has marked set. + * @retval 0 OK + * @retval -1 Error * The function removes all branches that does not pass the test * Purge all nodes that dont have MARK flag set recursively. * Save all nodes that is MARK:ed or have at least one (grand*)child that is MARKed @@ -546,7 +553,7 @@ xml_tree_equal(cxobj *x0, * @see xml_tree_prune_flagged for a simpler variant */ int -xml_tree_prune_flagged_sub(cxobj *xt, +xml_tree_prune_flagged_sub(cxobj *xt, int flag, int test, int *upmark) @@ -607,7 +614,7 @@ xml_tree_prune_flagged_sub(cxobj *xt, goto done; x = xprev; } - xprev = x; + xprev = x; } } retval = 0; @@ -618,16 +625,19 @@ xml_tree_prune_flagged_sub(cxobj *xt, } /*! Prune everything that passes test + * * @param[in] xt XML tree with some node marked * @param[in] flag Which flag to test for * @param[in] test 1: test that flag is set, 0: test that flag is not set + * @retval 0 OK + * @retval -1 Error * The function removes all branches that does not pass test * @code * xml_tree_prune_flagged(xt, XML_FLAG_MARK, 1); * @endcode */ int -xml_tree_prune_flagged(cxobj *xt, +xml_tree_prune_flagged(cxobj *xt, int flag, int test) { @@ -642,7 +652,7 @@ xml_tree_prune_flagged(cxobj *xt, if (xml_purge(x) < 0) goto done; x = xprev; - continue; + continue; } if (xml_tree_prune_flagged(x, flag, test) < 0) goto done; @@ -654,9 +664,12 @@ xml_tree_prune_flagged(cxobj *xt, } /*! Prune everything that passes test + * * @param[in] xt XML tree with some node marked * @param[in] flags Flags set * @param[in] mask Which flags to test for + * @retval 0 OK + * @retval -1 Error * The function removes all branches that does pass test * @code * xml_tree_prune_flags(xt, XML_FLAG_MARK, XML_FLAG_MARK|XML_FLAG_DEFAULT); @@ -699,9 +712,9 @@ xml_tree_prune_flags(cxobj *xt, * @param -1 Error */ int -xml_namespace_change(cxobj *x, - char *ns, - char *prefix) +xml_namespace_change(cxobj *x, + char *ns, + char *prefix) { int retval = -1; char *ns0 = NULL; /* existing namespace */ @@ -712,7 +725,7 @@ xml_namespace_change(cxobj *x, if (xml2ns(x, xml_prefix(x), &ns0) < 0) goto done; if (ns0 && strcmp(ns0, ns) == 0) - goto ok; /* Already has right namespace */ + goto ok; /* Already has right namespace */ /* Is namespace already declared? */ if (xml2prefix(x, ns, &prefix0) == 1){ /* Yes it is declared and the prefix is prefix0 */ @@ -728,7 +741,7 @@ xml_namespace_change(cxobj *x, else xp = xml_parent(x); if (xml_add_namespace(x, xp, prefix, ns) < 0) - goto done; + goto done; /* Add prefix to x, if any */ if (prefix && xml_prefix_set(x, prefix) < 0) goto done; @@ -740,10 +753,15 @@ xml_namespace_change(cxobj *x, } /*! Sanitize an xml tree: xml node has matching yang_stmt pointer - * @param[in] xt XML top of tree + * + * @param[in] xt XML top of tree + * @param[in] arg Not used + * @retval 0 OK + * @retval -1 Error + */ int -xml_sanity(cxobj *xt, +xml_sanity(cxobj *xt, void *arg) { int retval = -1; @@ -756,7 +774,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'", + clicon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'", name, yang_argument_get(ys)); goto done; } @@ -766,23 +784,24 @@ xml_sanity(cxobj *xt, } /*! Detect state data: Either mark or break on first occurence and return xerror + * * @param[in] xt XML tree * @param[out] xerr If set return netconf error, abort and return if a state variable found - * @retval -1 Error - * @retval 0 Status node found and return xerror * @retval 1 OK + * @retval 0 Status node found and return xerror + * @retval -1 Error * Note that the behaviour is quite different if xerr is set or not,... */ int -xml_non_config_data(cxobj *xt, - cxobj **xerr) +xml_non_config_data(cxobj *xt, + cxobj **xerr) { int retval = -1; cxobj *x; yang_stmt *y; int ret; cbuf *cb = NULL; - + x = NULL; while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { if ((y = (yang_stmt*)xml_spec(x)) == NULL) @@ -817,7 +836,10 @@ xml_non_config_data(cxobj *xt, } /*! Check if the module tree x is in is assigned right XML namespace, assign if not + * * @param[in] x XML node + * @retval 0 OK + * @retval -1 Error *(0. You should probably find the XML root and apply this function to that.) * 1. Check which namespace x should have (via yang). This is correct namespace. * 2. Check which namespace x has via its XML tree @@ -862,10 +884,11 @@ xmlns_assign(cxobj *x) } /*! Given a src element node x0 and a target node x1, assign (optional) prefix and namespace + * * @param[in] x1 XML tree * @param[in] x1p XML tree parent * @retval 0 OK - * @retval -1 OK + * @retval -1 Error * @see assign_namespace_element this is a subroutine */ static int @@ -880,7 +903,7 @@ assign_namespace(cxobj *x1, /* target */ char *pexist = NULL; cvec *nsc0 = NULL; cvec *nsc = NULL; - + /* 2a. Detect if namespace is declared in x1 target parent */ if (xml2prefix(x1p, ns, &pexist) == 1){ /* Yes, and it has prefix pexist */ @@ -920,7 +943,7 @@ assign_namespace(cxobj *x1, /* target */ } goto ok; /* skip */ } - else { /* namespace does not exist in target x1, + else { /* namespace does not exist in target x1, */ if (isroot){ if (prefix0 && (prefix1 = strdup(prefix0)) == NULL){ @@ -929,7 +952,7 @@ assign_namespace(cxobj *x1, /* target */ } } else{ - if (prefix0 == NULL){ /* Use default namespace, may break use of previous default + if (prefix0 == NULL){ /* Use default namespace, may break use of previous default * somewhere in x1 */ prefix1 = NULL; @@ -939,7 +962,7 @@ assign_namespace(cxobj *x1, /* target */ if (xml_add_namespace(x1, x1, prefix1, ns) < 0) goto done; if (prefix1 && xml_prefix_set(x1, prefix1) < 0) - goto done; + goto done; } ok: /* 6. Ensure x1 cache is updated (I think it is done w xmlns_set above) */ @@ -951,11 +974,12 @@ assign_namespace(cxobj *x1, /* target */ } /*! Given a src element node x0 and a target node x1, assign (optional) prefix and namespace + * * @param[in] x0 Source XML tree * @param[in] x1 Target XML tree * @param[in] x1p Target XML tree parent * @retval 0 OK - * @retval -1 OK + * @retval -1 Error * 1. Find N=namespace(x0) * 2. Detect if N is declared in x1 parent * 3. If yes, assign prefix to x1 @@ -975,7 +999,7 @@ assign_namespace_element(cxobj *x0, /* source */ char *namespace = NULL; char *prefix0 = NULL;; int isroot; - + isroot = xml_parent(x1p)==NULL && xml_flag(x1p, XML_FLAG_TOP) && xml_prefix(x1p)==NULL; @@ -1007,6 +1031,8 @@ assign_namespace_element(cxobj *x0, /* source */ * * @param[in] x0 Source XML * @param[in] x1 Destination XML + * @retval 0 OK + * @retval -1 Error * @note "standard" namespaces, including clixon internal namespaces are removed */ int @@ -1017,10 +1043,10 @@ assign_namespace_body(cxobj *x0, /* source */ char *namespace = NULL; char *namespace1; char *name; - char *prefix0; - char *prefix1 = NULL; + char *prefix0; + char *prefix1 = NULL; cxobj *xa; - + xa = NULL; while ((xa = xml_child_each_attr(x0, xa)) != NULL) { prefix0 = xml_prefix(xa); @@ -1058,6 +1084,7 @@ assign_namespace_body(cxobj *x0, /* source */ } /*! Merge a base tree x0 with x1 with yang spec y + * * @param[in] x0 Base xml tree (can be NULL in add scenarios) * @param[in] y0 Yang spec corresponding to xml-node x0. NULL if x0 is NULL * @param[in] x0p Parent of x0 @@ -1092,7 +1119,7 @@ xml_merge1(cxobj *x0, /* the target */ char *ns; char *px; 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"); goto done; @@ -1131,13 +1158,13 @@ xml_merge1(cxobj *x0, /* the target */ if (x1bstr){ if ((x0b = xml_body_get(x0)) == NULL){ if ((x0b = xml_new("body", x0, CX_BODY)) == NULL) - goto done; + goto done; } if (xml_value_set(x0b, x1bstr) < 0) goto done; } if (xml_parent(x0) == NULL && - xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0) + xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0) goto done; if (assign_namespace_element(x1, x0, x0p) < 0) goto done; @@ -1200,7 +1227,7 @@ xml_merge1(cxobj *x0, /* the target */ goto fail; } if (xml_parent(x0) == NULL && - xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0) + xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0) goto done; } /* else Y_CONTAINER */ ok: @@ -1219,6 +1246,7 @@ xml_merge1(cxobj *x0, /* the target */ } /*! Merge XML trees x1 into x0 according to yang spec yspec + * * @param[in] x0 Base xml tree (can be NULL in add scenarios) * @param[in] x1 xml tree which modifies base * @param[in] yspec Yang spec @@ -1268,7 +1296,7 @@ xml_merge(cxobj *x0, clicon_err(OE_UNIX, errno, "strdup"); goto done; } - goto fail; + goto fail; } /* Get yang spec of the child */ if ((yc = yang_find_datanode(ymod, x1cname)) == NULL){ @@ -1331,6 +1359,8 @@ xml_merge(cxobj *x0, * @param[in] ytype YANG type noden * @param[in] valstr Integer string value * @param[out] enumstr Value of enum, dont free + * @retval 0 OK + * @retval -1 Error */ int yang_valstr2enum(yang_stmt *ytype, @@ -1365,7 +1395,7 @@ yang_valstr2enum(yang_stmt *ytype, * @param[out] valstr Corresponding string containing an int (direct pointer, dont free) * @retval 1 OK, result in valstr * @retval 0 Invalid, not found - * @retval -1 Error + * @retval -1 Error */ int yang_enum2valstr(yang_stmt *ytype, @@ -1373,8 +1403,8 @@ yang_enum2valstr(yang_stmt *ytype, char **valstr) { int retval = -1; - yang_stmt *yenum; - yang_stmt *yval; + yang_stmt *yenum; + yang_stmt *yval; if (valstr == NULL){ clicon_err(OE_UNIX, EINVAL, "valstr is NULL"); @@ -1395,6 +1425,7 @@ yang_enum2valstr(yang_stmt *ytype, } /*! Get integer value from xml node from yang enumeration + * * @param[in] node XML node in a tree * @param[out] val Integer value returned * @retval 0 OK, value parsed @@ -1408,7 +1439,7 @@ yang_enum2valstr(yang_stmt *ytype, * Thanks: Matthew Smith */ int -yang_enum_int_value(cxobj *node, +yang_enum_int_value(cxobj *node, int32_t *val) { int retval = -1; @@ -1427,7 +1458,7 @@ yang_enum_int_value(cxobj *node, goto done; if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL) goto done; - if (yang_type_resolve(ys, ys, ytype, &yrestype, + if (yang_type_resolve(ys, ys, ytype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) goto done; if (yrestype == NULL){ @@ -1447,17 +1478,21 @@ done: } /*! Given XML tree x0 with marked nodes, copy marked nodes to new tree x1 - * Two marks are used: XML_FLAG_MARK and XML_FLAG_CHANGE * + * Two marks are used: XML_FLAG_MARK and XML_FLAG_CHANGE * The algorithm works as following: * (1) Copy individual nodes marked with XML_FLAG_CHANGE * until nodes marked with XML_FLAG_MARK are reached, where * (2) the complete subtree of that node is copied. * (3) Special case: key nodes in lists are copied if any node in list is marked + * @param[in] x0 + * @param[in] x1 + * @retval 0 OK + * @retval -1 Error * @note you may want to check:!yang_config(ys) */ int -xml_copy_marked(cxobj *x0, +xml_copy_marked(cxobj *x0, cxobj *x1) { int retval = -1; @@ -1476,14 +1511,13 @@ xml_copy_marked(cxobj *x0, if ((prefix = xml_prefix(x0)) != NULL) if (xml_prefix_set(x1, prefix) < 0) goto done; - /* Copy all attributes */ x = NULL; while ((x = xml_child_each_attr(x0, x)) != NULL) { name = xml_name(x); if ((xcopy = xml_new(name, x1, CX_ATTR)) == NULL) goto done; - if (xml_copy(x, xcopy) < 0) + if (xml_copy(x, xcopy) < 0) goto done; } @@ -1506,9 +1540,9 @@ xml_copy_marked(cxobj *x0, /* (2) the complete subtree of that node is copied. */ if ((xcopy = xml_new(name, x1, CX_ELMNT)) == NULL) goto done; - if (xml_copy(x, xcopy) < 0) + if (xml_copy(x, xcopy) < 0) goto done; - continue; + continue; } if (xml_flag(x, XML_FLAG_CHANGE)){ /* Copy individual nodes marked with XML_FLAG_CHANGE */ @@ -1526,7 +1560,7 @@ xml_copy_marked(cxobj *x0, if (iskey){ if ((xcopy = xml_new(name, x1, CX_ELMNT)) == NULL) goto done; - if (xml_copy(x, xcopy) < 0) + if (xml_copy(x, xcopy) < 0) goto done; } } @@ -1545,7 +1579,7 @@ xml_copy_marked(cxobj *x0, * @param[out] nrp 1: when stmt evaluates to true * @param[out] xpathp when stmts xpath * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * First variants of WHEN: Augmented and uses when using special info in node * Second variant of when, actual "when" sub-node RFC 7950 Sec 7.21.5. Can only be one. */ @@ -1659,7 +1693,7 @@ yang_xml_mandatory(cxobj *xt, } /* 3) A container node without a "presence" statement and that has at * least one mandatory node as a child. */ - else if (keyw == Y_CONTAINER && + else if (keyw == Y_CONTAINER && yang_find(ys, Y_PRESENCE, NULL) == NULL){ yc = NULL; while ((yc = yn_each(ys, yc)) != NULL) { @@ -1680,6 +1714,7 @@ yang_xml_mandatory(cxobj *xt, } /*! Is XML node (ie under ) an action, ie name action and belong to YANG_XML_NAMESPACE? + * * @param[in] xn XML node * @retval 1 Yes, an action * @retval 0 No, not an action @@ -1706,6 +1741,7 @@ xml_rpc_isaction(cxobj *xn) } /*! Find innermost node under carrying the name of the defined action + * * Find innermost container or list contains an XML element * that carries the name of the defined action. * @param[in] xn XML node @@ -1744,12 +1780,15 @@ xml_find_action(cxobj *xn, } /*! Utility function: recursive traverse an XML tree and remove nodes based on attribute value + * * Conditionally remove attribute and node * @param[in] xn XML node * @param[in] ns Namespace of attribute * @param[in] name Attribute name * @param[in] value Attribute value * @param[in] keepnode 0: remove node associated with attribute; 1: keep node but remove attr + * @retval 0 OK + * @retval -1 Error */ int purge_tagged_nodes(cxobj *xn, @@ -1797,6 +1836,8 @@ purge_tagged_nodes(cxobj *xn, * @param[in] xc1 XML tree 1 * @param[in] xc2 XML tree 2 * @param[in] format "text"|"xml"|"json"|"cli"|"netconf" (see format_enum) + * @retval 0 OK + * @retval -1 Error * @see clixon_xml_diff2cbuf with better XML in-mem comparison but is YANG dependent */ int diff --git a/lib/src/clixon_xml_nsctx.c b/lib/src/clixon_xml_nsctx.c index c359b7ed..0170dbaf 100644 --- a/lib/src/clixon_xml_nsctx.c +++ b/lib/src/clixon_xml_nsctx.c @@ -79,13 +79,13 @@ * See rfc6241 3.1: urn:ietf:params:xml:ns:netconf:base:1.0. */ static int _USE_NAMESPACE_NETCONF_DEFAULT = 0; - + /*! Set if use internal default namespace mechanism or not * * This function shouldnt really be here, it sets a local variable from the value of the * option CLICON_NAMESPACE_NETCONF_DEFAULT, but the code where it is used is deep in the call * stack and cannot get the clicon handle currently. - * @param[in] h Clicon handle + * @param[in] h Clixon handle */ int xml_nsctx_namespace_netconf_default(clicon_handle h) @@ -155,7 +155,7 @@ xml_nsctx_get(cvec *cvv, char *prefix) { cg_var *cv; - + if ((cv = cvec_find(cvv, prefix)) != NULL) return cv_string_get(cv); return NULL; @@ -206,7 +206,7 @@ xml_nsctx_add(cvec *cvv, { int retval = -1; cg_var *cv; - + if ((cv = cvec_find(cvv, prefix)) != NULL) /* found, replace that */ cv_string_set(cv, ns); else /* cvec exists, but not prefix */ @@ -289,7 +289,7 @@ xml_nsctx_node(cxobj *xn, { int retval = -1; cvec *nc = NULL; - + if ((nc = cvec_new(0)) == NULL){ clicon_err(OE_XML, errno, "cvec_new"); goto done; @@ -339,7 +339,7 @@ xml_nsctx_yang(yang_stmt *yn, char *prefix; char *mynamespace; char *myprefix; - + if (yang_keyword_get(yn) == Y_SPEC){ clicon_err(OE_YANG, EINVAL, "yang spec node is invalid argument"); goto done; @@ -376,7 +376,7 @@ xml_nsctx_yang(yang_stmt *yn, if ((name = yang_argument_get(y)) == NULL) continue; /* Just skip - shouldnt happen) */ if ((yp = yang_find(y, Y_PREFIX, NULL)) == NULL) - continue; + continue; if ((prefix = yang_argument_get(yp)) == NULL) continue; if ((ym = yang_find(yspec, Y_MODULE, name)) == NULL) @@ -470,7 +470,7 @@ xml_nsctx_cbuf(cbuf *cb, { cg_var *cv = NULL; char *prefix; - + while ((cv = cvec_each(nsc, cv)) != NULL){ cprintf(cb, " xmlns"); if ((prefix = cv_name_get(cv))) @@ -493,7 +493,7 @@ xml_nsctx_cbuf(cbuf *cb, * err; * @endcode * @see xmlns_set cache is set - * @note, this function uses a cache. + * @note, this function uses a cache. */ int xml2ns(cxobj *x, @@ -503,7 +503,7 @@ xml2ns(cxobj *x, int retval = -1; char *ns = NULL; cxobj *xp; - + if ((ns = nscache_get(x, prefix)) != NULL) goto ok; if (prefix != NULL) /* xmlns:="" */ @@ -526,7 +526,7 @@ xml2ns(cxobj *x, } } /* Set default namespace cache (since code is at this point, - * no cache was found + * no cache was found * If not, this is devastating when populating deep yang structures */ if (ns && @@ -564,7 +564,7 @@ xml2ns_recurse(cxobj *xt) if (namespace == NULL){ clicon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x)); goto done; - } + } } if (xml2ns_recurse(x) < 0) goto done; @@ -618,6 +618,8 @@ xmlns_set(cxobj *x, * Check if already there * @param[in] x XML tree * @param[in] nsc Namespace context + * @retval 0 OK + * @retval -1 Error * @note you need to do an xml_sort(x) after the call */ int @@ -676,7 +678,7 @@ xml2prefix(cxobj *xn, xa = NULL; while ((xa = xml_child_each_attr(xn, xa)) != NULL) { /* xmlns=namespace */ - if (strcmp("xmlns", xml_name(xa)) == 0){ + if (strcmp("xmlns", xml_name(xa)) == 0){ if (strcmp(xml_value(xa), namespace) == 0){ if (nscache_set(xn, NULL, namespace) < 0) goto done; @@ -686,7 +688,7 @@ xml2prefix(cxobj *xn, } /* xmlns:prefix=namespace */ else if ((xaprefix=xml_prefix(xa)) != NULL && - strcmp("xmlns", xaprefix) == 0){ + strcmp("xmlns", xaprefix) == 0){ if (strcmp(xml_value(xa), namespace) == 0){ prefix = xml_name(xa); if (nscache_set(xn, prefix, namespace) < 0) @@ -720,6 +722,8 @@ xml2prefix(cxobj *xn, * @param[in] xp XML node where namespace attribute should be declared (can be same) * @param[in] prefix1 Use this prefix * @param[in] namespace Use this namespace + * @retval 0 OK + * @retval -1 Error * @note x and xp must be different if x is an attribute and may be different otherwise */ int @@ -730,7 +734,7 @@ xml_add_namespace(cxobj *x, { int retval = -1; cxobj *xa = NULL; - + /* Add binding to x1p. We add to parent due to heurestics, so we dont * end up in adding it to large number of siblings */ diff --git a/lib/src/clixon_xml_parse.l b/lib/src/clixon_xml_parse.l index 53901490..2dedcd60 100644 --- a/lib/src/clixon_xml_parse.l +++ b/lib/src/clixon_xml_parse.l @@ -68,7 +68,7 @@ #define YY_NO_INPUT /* typecast macro */ -#define _XY ((clixon_xml_yacc *)_xy) +#define _XY ((clixon_xml_yacc *)_xy) #undef clixon_xml_parsewrap int clixon_xml_parsewrap(void) @@ -120,7 +120,7 @@ ncname {namestart}{namechar}* "/>" { BEGIN(STATEA); return ESLASH; } "" { BEGIN(START); return ECOMMENT; } -. +. encoding return ENC; -version return VER; -standalone return SD; +version return VER; +standalone return SD; "=" { return *clixon_xml_parsetext; } "?>" { BEGIN(START);return EQMARK;} \" { _XY->xy_lex_state =TEXTDECL;BEGIN(STRDQ); return *clixon_xml_parsetext; } diff --git a/lib/src/clixon_xml_parse.y b/lib/src/clixon_xml_parse.y index 05d7af7a..30ff1df1 100644 --- a/lib/src/clixon_xml_parse.y +++ b/lib/src/clixon_xml_parse.y @@ -50,9 +50,9 @@ %token VER ENC SD %token BSLASH ESLASH %token BXMLDCL BQMARK EQMARK -%token BCOMMENT ECOMMENT +%token BCOMMENT ECOMMENT -%type attvalue +%type attvalue %lex-param {void *_xy} /* Add this argument to parse() and lex() function */ %parse-param {void *_xy} @@ -86,48 +86,52 @@ /* Enable for debugging, steals some cycles otherwise */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #else #define _PARSE_DEBUG(s) #endif - -void + +void clixon_xml_parseerror(void *_xy, - char *s) -{ - clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s", + char *s) +{ + clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s", _XY->xy_linenum, s, - clixon_xml_parsetext); + clixon_xml_parsetext); return; } /*! Parse XML content, eg chars between >...< + * * @param[in] xy * @param[in] encoded set if ampersand encoded - * @param[in] str Body string, direct pointer (copy before use, dont free) - * Note that we dont handle escaped characters correctly + * @param[in] str Body string, direct pointer (copy before use, dont free) + * @retval 0 OK + * @retval -1 Error + * Note that we dont handle escaped characters correctly * there may also be some leakage here on NULL return */ static int -xml_parse_content(clixon_xml_yacc *xy, +xml_parse_content(clixon_xml_yacc *xy, int encoded, char *str) { + int retval = -1; cxobj *xn = xy->xy_xelement; cxobj *xp = xy->xy_xparent; - int retval = -1; + xy->xy_xelement = NULL; /* init */ if (xn == NULL){ if ((xn = xml_new("body", xp, CX_BODY)) == NULL) - goto done; + goto done; } if (encoded) if (xml_value_append(xn, "&") < 0) - goto done; + goto done; if (xml_value_append(xn, str) < 0) - goto done; + goto done; xy->xy_xelement = xn; retval = 0; done: @@ -135,16 +139,19 @@ xml_parse_content(clixon_xml_yacc *xy, } /*! Add whitespace + * * If text, ie only body, keep as is. * But if there is an element, then skip all whitespace. + * @retval 0 OK + * @retval -1 Error */ static int xml_parse_whitespace(clixon_xml_yacc *xy, char *str) { + int retval = -1; cxobj *xn = xy->xy_xelement; cxobj *xp = xy->xy_xparent; - int retval = -1; int i; xy->xy_xelement = NULL; /* init */ @@ -160,17 +167,17 @@ xml_parse_whitespace(clixon_xml_yacc *xy, } if (xn == NULL){ if ((xn = xml_new("body", xp, CX_BODY)) == NULL) - goto done; + goto done; } if (xml_value_append(xn, str) < 0) - goto done; + goto done; xy->xy_xelement = xn; ok: retval = 0; done: return retval; } - + static int xml_parse_version(clixon_xml_yacc *xy, char *ver) @@ -186,6 +193,7 @@ xml_parse_version(clixon_xml_yacc *xy, } /*! Parse XML encoding + * * From under Encoding Declaration: * In an encoding declaration, the values UTF-8, UTF-16, ISO-10646-UCS-2, and ISO-10646-UCS-4 * SHOULD be used for the various encodings and transformations of Unicode / ISO/IEC 10646, the @@ -209,13 +217,15 @@ xml_parse_encoding(clixon_xml_yacc *xy, } return 0; } - + /*! Parse Qualified name -> (Un)PrefixedName * * This is where all (parsed) xml elements are created * @param[in] xy XML parser yacc handler struct * @param[in] prefix Prefix, namespace, or NULL * @param[in] localpart Name + * @retval 0 OK + * @retval -1 Error */ static int xml_parse_prefixed_name(clixon_xml_yacc *xy, @@ -224,10 +234,10 @@ xml_parse_prefixed_name(clixon_xml_yacc *xy, { int retval = -1; cxobj *x; - cxobj *xp; /* xml parent */ + cxobj *xp; /* xml parent */ xp = xy->xy_xparent; - if ((x = xml_new(name, xp, CX_ELMNT)) == NULL) + if ((x = xml_new(name, xp, CX_ELMNT)) == NULL) goto done; /* Cant check namespaces here since local xmlns attributes loaded after */ if (xml_prefix_set(x, prefix) < 0) @@ -282,9 +292,11 @@ xml_parse_endslash_post(clixon_xml_yacc *xy) * @param[in] xy XML parser yacc handler struct * @param[in] prefix * @param[in] name + * @retval 0 OK + * @retval -1 Error */ static int -xml_parse_bslash(clixon_xml_yacc *xy, +xml_parse_bslash(clixon_xml_yacc *xy, char *prefix, char *name) { @@ -298,9 +310,9 @@ xml_parse_bslash(clixon_xml_yacc *xy, prefix0 = xml_prefix(x); name0 = xml_name(x); /* 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", + 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", prefix0?prefix0:"", prefix0?":":"", name0, prefix?prefix:"", prefix?":":"", name); goto done; @@ -314,7 +326,7 @@ xml_parse_bslash(clixon_xml_yacc *xy, * be stripped, see xml_bind_yang() */ xc = NULL; - while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) + while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) break; if (xc != NULL){ /* at least one element */ if (xml_rm_children(x, CX_BODY) < 0) /* remove all bodies */ @@ -330,9 +342,12 @@ xml_parse_bslash(clixon_xml_yacc *xy, } /*! Parse XML attribute + * * Special cases: * - DefaultAttName: xmlns - * - PrefixedAttName: xmlns:NAME + * - PrefixedAttName: xmlns:NAME + * @retval 0 OK + * @retval -1 Error */ static int xml_parse_attr(clixon_xml_yacc *xy, @@ -341,7 +356,7 @@ xml_parse_attr(clixon_xml_yacc *xy, char *attval) { int retval = -1; - cxobj *xa = NULL; + cxobj *xa = NULL; if ((xa = xml_find_type(xy->xy_xelement, prefix, name, CX_ATTR)) == NULL){ if ((xa = xml_new(name, xy->xy_xelement, CX_ATTR)) == NULL) @@ -361,12 +376,12 @@ xml_parse_attr(clixon_xml_yacc *xy, return retval; } -%} - +%} + %% /* [1] document ::= prolog element Misc* */ document : prolog element misclist MY_EOF - { _PARSE_DEBUG("document->prolog element misc* ACCEPT"); + { _PARSE_DEBUG("document->prolog element misc* ACCEPT"); YYACCEPT; } | elist MY_EOF { _PARSE_DEBUG("document->elist ACCEPT"); /* internal exception*/ @@ -394,10 +409,10 @@ xmldcl : BXMLDCL verinfo encodingdecl sddecl EQMARK { _PARSE_DEBUG("xmldcl->verinfo encodingdecl? sddecl?"); } ; -verinfo : VER '=' '\"' STRING '\"' +verinfo : VER '=' '\"' STRING '\"' { if (xml_parse_version(_XY, $4) <0) YYABORT; _PARSE_DEBUG("verinfo->version=\"STRING\"");} - | VER '=' '\'' STRING '\'' + | VER '=' '\'' STRING '\'' { if (xml_parse_version(_XY, $4) <0) YYABORT; _PARSE_DEBUG("verinfo->version='STRING'");} ; @@ -416,30 +431,30 @@ sddecl : SD '=' '\"' STRING '\"' {if ($4)free($4);} | ; /* [39] element ::= EmptyElemTag | STag content ETag */ -element : '<' qname attrs element1 +element : '<' qname attrs element1 { _PARSE_DEBUG("element -> < qname attrs element1"); } ; -qname : NAME { if (xml_parse_prefixed_name(_XY, NULL, $1) < 0) YYABORT; +qname : NAME { if (xml_parse_prefixed_name(_XY, NULL, $1) < 0) YYABORT; _PARSE_DEBUG("qname -> NAME");} - | NAME ':' NAME { if (xml_parse_prefixed_name(_XY, $1, $3) < 0) YYABORT; + | NAME ':' NAME { if (xml_parse_prefixed_name(_XY, $1, $3) < 0) YYABORT; _PARSE_DEBUG("qname -> NAME : NAME");} ; -element1 : ESLASH {_XY->xy_xelement = NULL; - _PARSE_DEBUG("element1 -> />");} +element1 : ESLASH {_XY->xy_xelement = NULL; + _PARSE_DEBUG("element1 -> />");} | '>' { xml_parse_endslash_pre(_XY); } elist { xml_parse_endslash_mid(_XY); } - endtag { xml_parse_endslash_post(_XY); - _PARSE_DEBUG("element1 -> > elist endtag");} + endtag { xml_parse_endslash_post(_XY); + _PARSE_DEBUG("element1 -> > elist endtag");} ; -endtag : BSLASH NAME '>' +endtag : BSLASH NAME '>' { _PARSE_DEBUG("endtag -> < "); if (xml_parse_bslash(_XY, NULL, $2) < 0) YYABORT; } - | BSLASH NAME ':' NAME '>' - { if (xml_parse_bslash(_XY, $2, $4) < 0) YYABORT; + | BSLASH NAME ':' NAME '>' + { if (xml_parse_bslash(_XY, $2, $4) < 0) YYABORT; _PARSE_DEBUG("endtag -> < "); } ; @@ -451,11 +466,11 @@ elist : elist content { _PARSE_DEBUG("elist -> elist content"); } content : element { _PARSE_DEBUG("content -> element"); } | comment { _PARSE_DEBUG("content -> comment"); } | pi { _PARSE_DEBUG("content -> pi"); } - | CHARDATA { if (xml_parse_content(_XY, 0, $1) < 0) YYABORT; + | CHARDATA { if (xml_parse_content(_XY, 0, $1) < 0) YYABORT; _PARSE_DEBUG("content -> CHARDATA"); } - | ENCODED { if (xml_parse_content(_XY, 1, $1) < 0) YYABORT; + | ENCODED { if (xml_parse_content(_XY, 1, $1) < 0) YYABORT; _PARSE_DEBUG("content -> ENCODED"); } - | WHITESPACE { if (xml_parse_whitespace(_XY, $1) < 0) YYABORT; + | WHITESPACE { if (xml_parse_whitespace(_XY, $1) < 0) YYABORT; _PARSE_DEBUG("content -> WHITESPACE"); } | { _PARSE_DEBUG("content -> "); } ; diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index f27cdf75..6bac6f5c 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -74,6 +74,7 @@ #include "clixon_xml_sort.h" /*! Get xml body value as cligen variable + * * @param[in] x XML node (body and leaf/leaf-list) * @param[out] cvp Pointer to cligen variable containing value of x body * @retval 0 OK, cvp contains cv or NULL @@ -97,7 +98,7 @@ xml_cv_cache(cxobj *x, int options = 0; uint8_t fraction = 0; char *body; - + if ((body = xml_body(x)) == NULL) body=""; if ((cv = xml_cv(x)) != NULL) @@ -120,7 +121,6 @@ xml_cv_cache(cxobj *x, } 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"); goto done; @@ -158,6 +158,7 @@ xml_cv_cache_clear(cxobj *xt) } /*! Help function to qsort for sorting entries in xml child vector same parent + * * @param[in] x1 object 1 * @param[in] x2 object 2 * @param[in] same If set, x1 and x2 are member of same parent & enumeration @@ -212,7 +213,7 @@ xml_cmp(cxobj *x1, char *b1; char *b2; char *keyname; - cg_var *cv1 = NULL; + cg_var *cv1 = NULL; cg_var *cv2 = NULL; int nr1 = 0; int nr2 = 0; @@ -254,7 +255,7 @@ xml_cmp(cxobj *x1, equal = 1; goto done; } - if (y1 != y2){ + if (y1 != y2){ /* XXX handle errors */ yi1 = yang_order(y1); yi2 = yang_order(y2); @@ -384,26 +385,28 @@ xml_cmp(cxobj *x1, break; } /* switch */ done: - clicon_debug(CLIXON_DBG_EXTRA, "%s %s %s eq:%d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2); + clixon_debug(CLIXON_DBG_EXTRA, "%s %s %s eq:%d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2); return equal; } -/*! +/*! Sort xml + * * @note args are pointer to pointers, to fit into qsort cmp function */ static int -xml_cmp_qsort(const void* arg1, +xml_cmp_qsort(const void* arg1, const void* arg2) { return xml_cmp(*(struct xml**)arg1, *(struct xml**)arg2, 1, 0, NULL); } /*! Sort children of an XML node + * * Assume populated by yang spec. * @param[in] x0 XML node - * @retval -1 Error, aborted at first error encounter - * @retval 0 OK, all nodes traversed (subparts may have been skipped) * @retval 1 OK, aborted on first fn returned 1 + * @retval 0 OK, all nodes traversed (subparts may have been skipped) + * @retval -1 Error, aborted at first error encounter * @see xml_apply - typically called by recursive apply function * @see xml_sort_verify */ @@ -412,7 +415,7 @@ xml_sort(cxobj *x) { #ifndef STATE_ORDERED_BY_SYSTEM yang_stmt *ys; - + /* Abort sort if non-config (=state) data */ if ((ys = xml_spec(x)) != 0 && yang_config(ys)==0) return 1; @@ -423,7 +426,11 @@ xml_sort(cxobj *x) } /*! Recursively sort a tree + * * Alt to use xml_apply + * @param[in] xn XML node + * @retval 0 OK + * @retval -1 Error */ int xml_sort_recurse(cxobj *xn) @@ -431,7 +438,7 @@ xml_sort_recurse(cxobj *xn) int retval = -1; cxobj *x; int ret; - + ret = xml_sort_verify(xn, NULL); if (ret == 1) /* This node is not sortable */ goto ok; @@ -478,7 +485,7 @@ xml_find_keys_notsorted(cxobj *xp, cxobj *xc; yang_stmt *yc; int yi; - + for (i=mid+1; i=0; i--){ /* First decrement */ xc = childvec[i]; yc = xml_spec(xc); @@ -581,7 +589,7 @@ search_multi_equals_xvec(clixon_xvec *childvec, cxobj *xc; yang_stmt *yc; int yi; - + for (i=mid-1; i>=0; i--){ /* First decrement */ xc = clixon_xvec_i(childvec, i); yc = xml_spec(xc); @@ -612,6 +620,7 @@ search_multi_equals_xvec(clixon_xvec *childvec, } /*! Insert xi in vector sorted according to index variable xi + * * @param[in] x1 XML parent object (the list element) * @param[in] ivec Sorted index vector * @param[in] low Lower range limit @@ -627,7 +636,7 @@ int xml_search_indexvar_binary_pos(cxobj *x1, char *indexvar, clixon_xvec *ivec, - int low, + int low, int upper, int max, int *eq) @@ -636,9 +645,9 @@ xml_search_indexvar_binary_pos(cxobj *x1, int mid; int cmp; cxobj *xc; - + if (upper < low){ /* beyond range */ - clicon_err(OE_XML, 0, "low>upper %d %d", low, upper); + clicon_err(OE_XML, 0, "low>upper %d %d", low, upper); goto done; } if (low == upper){ @@ -647,7 +656,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); + clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper); goto done; } xc = clixon_xvec_i(ivec, mid); @@ -666,14 +675,14 @@ xml_search_indexvar_binary_pos(cxobj *x1, if (eq) /* No exact match */ *eq = 0; if (cmp < 0) /* return either 0 if cmp<0 or +1 if cmp>0 */ - retval = mid; + retval = mid; else - retval = mid+1; + retval = mid+1; goto done; } if (cmp < 0) return xml_search_indexvar_binary_pos(x1, indexvar, ivec, low, mid, max, eq); - else + else return xml_search_indexvar_binary_pos(x1, indexvar, ivec, mid+1, upper, max, eq); } done: @@ -684,7 +693,7 @@ static int xml_search_indexvar(cxobj *xp, cxobj *x1, int yangi, - int low, + int low, int upper, char *indexvar, clixon_xvec *xvec) @@ -722,6 +731,7 @@ xml_search_indexvar(cxobj *xp, #endif /* XML_EXPLICIT_INDEX */ /*! Find XML child under xp matching x1 using binary search + * * @param[in] xp Parent xml node. * @param[in] x1 Find this object among xp:s children * @param[in] sorted If x1 is ordered by user or statedata, the list is not sorted @@ -739,7 +749,7 @@ xml_search_binary(cxobj *xp, cxobj *x1, int sorted, int yangi, - int low, + int low, int upper, int skip1, char *indexvar, @@ -789,7 +799,7 @@ xml_search_binary(cxobj *xp, } else if (cmp < 0) xml_search_binary(xp, x1, sorted, yangi, low, mid-1, skip1, indexvar, xvec); - else + else xml_search_binary(xp, x1, sorted, yangi, mid+1, upper, skip1, indexvar, xvec); ok: retval = 0; @@ -827,7 +837,7 @@ xml_search_yang(cxobj *xp, int upper = xml_child_nr(xp); int sorted = 1; int yangi; - + if (xp == NULL){ clicon_err(OE_XML, EINVAL, "xp is NULL"); goto done; @@ -856,6 +866,7 @@ xml_search_yang(cxobj *xp, } /*! Insert xn in xp:s sorted child list (special case of ordered-by user) + * * @param[in] xp Parent xml node. If NULL just remove from old parent. * @param[in] xn Child xml node to insert under xp * @param[in] yn Yang stmt of xml child node @@ -920,22 +931,22 @@ xml_insert_userorder(cxobj *xp, 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); + clicon_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"); else - retval = (ins==INS_BEFORE)?i:i+1; + 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); + clicon_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"); else - retval = (ins==INS_BEFORE)?i:i+1; + retval = (ins==INS_BEFORE)?i:i+1; } break; default: @@ -949,6 +960,7 @@ xml_insert_userorder(cxobj *xp, } /*! Insert xn in xp:s sorted child list + * * Find a point in xp childvec with two adjacent nodes xi,xi+1 such that * xi<=xn<=xi+1 or xn<=x0 or xmax<=xn * @param[in] xp Parent xml node. If NULL just remove from old parent. @@ -973,7 +985,7 @@ xml_insert2(cxobj *xp, enum insert_type ins, char *key_val, cvec *nsc_key, - int low, + int low, int upper) { int retval = -1; @@ -982,9 +994,9 @@ xml_insert2(cxobj *xp, cxobj *xc; yang_stmt *yc; int yi; - + if (low > upper){ /* beyond range */ - clicon_err(OE_XML, 0, "low>upper %d %d", low, upper); + clicon_err(OE_XML, 0, "low>upper %d %d", low, upper); goto done; } if (low == upper){ @@ -993,7 +1005,7 @@ 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); + clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper); goto done; } xc = xml_child_i(xp, mid); @@ -1002,7 +1014,7 @@ xml_insert2(cxobj *xp, clicon_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)); + clicon_err(OE_XML, 0, "No spec found %s", xml_name(xc)); goto done; } if (yc == yn){ /* Same yang */ @@ -1017,7 +1029,7 @@ xml_insert2(cxobj *xp, if ((yi = yang_order(yc)) < -1) goto done; cmp = yni - yi; - /* One case is a choice where + /* One case is a choice where * xc = , xn = * same order but different yang spec */ @@ -1036,13 +1048,14 @@ xml_insert2(cxobj *xp, } else if (cmp < 0) return xml_insert2(xp, xn, yn, yni, userorder, ins, key_val, nsc_key, low, mid); - else + else return xml_insert2(xp, xn, yn, yni, userorder, ins, key_val, nsc_key, mid+1, upper); done: return retval; } /*! Insert xc as child to xp in sorted place. Remove xc from previous parent. + * * @param[in] xp Parent xml node. If NULL just remove from old parent. * @param[in] x Child xml node to insert under xp * @param[in] ins Insert operation (if ordered-by user) @@ -1112,6 +1125,7 @@ xml_insert(cxobj *xp, } /*! Verify all children of XML node are sorted according to xml_sort() + * * @param[in] x XML node. Check its children * @param[in] arg Dummy. Ensures xml_apply can be used with this fn * @retval 1 Not sortable @@ -1128,7 +1142,7 @@ xml_sort_verify(cxobj *x0, cxobj *xprev = NULL; #ifndef STATE_ORDERED_BY_SYSTEM yang_stmt *ys; - + /* Abort sort if non-config (=state) data */ if ((ys = xml_spec(x0)) != 0 && yang_config_ancestor(ys)==0){ retval = 1; @@ -1151,6 +1165,7 @@ xml_sort_verify(cxobj *x0, } /*! Given child tree x1c, find (first) matching child in base tree x0 and return as x0cp + * * @param[in] x0 Base tree node * @param[in] x1c Modification tree child * @param[in] yc Yang spec of tree child. If null revert to linear search. @@ -1161,7 +1176,7 @@ xml_sort_verify(cxobj *x0, * @see xml_cmp regarding what "match" means in this context (model-match not value-match) */ int -match_base_child(cxobj *x0, +match_base_child(cxobj *x0, cxobj *x1c, yang_stmt *yc, cxobj **x0cp) @@ -1172,10 +1187,10 @@ match_base_child(cxobj *x0, cxobj *xb; char *keyname; clixon_xvec *xvec = NULL; - + *x0cp = NULL; /* init return value */ /* Revert to simple xml lookup if no yang */ - if (yc == NULL){ + if (yc == NULL){ *x0cp = xml_find(x0, xml_name(x1c)); goto ok; } @@ -1189,7 +1204,7 @@ match_base_child(cxobj *x0, break; case Y_LIST: /* Match with key values */ cvk = yang_cvec_get(yc); /* Use Y_LIST cache, see ys_populate_list() */ - cvi = NULL; + cvi = NULL; while ((cvi = cvec_each(cvk, cvi)) != NULL) { keyname = cv_string_get(cvi); if ((xb = xml_find(x1c, keyname)) == NULL) @@ -1271,6 +1286,7 @@ xml_find_noyang_cvk(char *ns0, } /*! API for search in XML child list with no yang available + * * Fallback if no yang available. Only linear search for matching name, and eventual index match */ static int @@ -1323,7 +1339,7 @@ xml_find_noyang_name(cxobj *xp, * linear seacrh * - if yes, then construct a dummy search object and find it in the list of xp:s children * using binary search - * @param[in] xp Parent xml node. + * @param[in] xp Parent xml node. * @param[in] yc Yang spec of list child (preferred) See rule (2) above * @param[in] cvk List of keys and values as CLIgen vector on the form k1=foo, k2=bar * @param[out] xvec Array of found nodes @@ -1440,9 +1456,9 @@ xml_find_index_yang(cxobj *xp, 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)); - goto done; + goto done; } - if (xml_spec_set(xk, yk) < 0) + if (xml_spec_set(xk, yk) < 0) goto done; } if (xml_search_yang(xp, xc, yc, 1, indexvar, xvec) < 0) @@ -1522,7 +1538,7 @@ clixon_xml_find_index(cxobj *xp, int retval = -1; int ret; yang_stmt *yc = NULL; - + if (xvec == NULL){ clicon_err(OE_YANG, EINVAL, "xvec"); goto done; @@ -1542,7 +1558,7 @@ clixon_xml_find_index(cxobj *xp, if (yc){ if ((ret = xml_find_index_yang(xp, yc, cvk, xvec)) < 0) goto done; - if (ret == 0){ /* This means yang method did not work for some reason + 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, ns, name, cvk, xvec) < 0) @@ -1560,7 +1576,7 @@ clixon_xml_find_index(cxobj *xp, /*! Find positional parameter in xml child list, eg x/y[42]. Note, not optimized * * Create a temporary search object: a list (xc) with a key (xk) and call the binary search. - * @param[in] xp Parent xml node. + * @param[in] xp Parent xml node. * @param[in] yc Yang spec of list child * @param[in] pos Position * @param[out] xvec Array of found nodes diff --git a/lib/src/clixon_xml_vec.c b/lib/src/clixon_xml_vec.c index 875de3e9..cd3465db 100644 --- a/lib/src/clixon_xml_vec.c +++ b/lib/src/clixon_xml_vec.c @@ -71,15 +71,16 @@ #define XVEC_MAX_THRESHOLD 1024 /* exponential growth to here, then linear */ /*! Clixon xml vector concrete implementaion of the abstract clixon_xvec type + * * Contiguous vector (not linked list) so that binary search can be done by direct index access */ struct clixon_xml_vec { cxobj **xv_vec; /* Sorted vector of xml object pointers */ int xv_len; /* Length of vector */ - int xv_max; /* Vector allocation */ + int xv_max; /* Vector allocation */ }; -/*! Increment cxobj vector in an XML object vector +/*! Increment cxobj vector in an XML object vector * * Exponential growth to a threshold, then linear * @param[in] xv XML tree vector @@ -90,7 +91,7 @@ static int clixon_xvec_inc(clixon_xvec *xv) { int retval = -1; - + xv->xv_len++; if (xv->xv_len > xv->xv_max){ if (xv->xv_max < XVEC_MAX_DEFAULT) @@ -173,6 +174,7 @@ clixon_xvec_free(clixon_xvec *xv) } /*! Return length of XML object list + * * @param[in] xv XML tree vector * @retval len Length of XML object vector */ @@ -183,6 +185,7 @@ clixon_xvec_len(clixon_xvec *xv) } /*! Return i:th XML object in XML object vector + * * @param[in] xv XML tree vector * @retval x OK * @retval NULL Not found @@ -214,7 +217,7 @@ clixon_xvec_extract(clixon_xvec *xv, int *xmax) { int retval = -1; - + if (xv == NULL){ clicon_err(OE_XML, EINVAL, "xv is NULL"); goto done; @@ -248,7 +251,6 @@ clixon_xvec_extract(clixon_xvec *xv, int clixon_xvec_append(clixon_xvec *xv, cxobj *x) - { int retval = -1; @@ -332,7 +334,7 @@ clixon_xvec_insert_pos(clixon_xvec *xv, { int retval = -1; size_t size; - + if (clixon_xvec_inc(xv) < 0) goto done; size = (xv->xv_len - i -1)*sizeof(cxobj *); @@ -355,7 +357,7 @@ clixon_xvec_rm_pos(clixon_xvec *xv, int i) { size_t size; - + size = (xv->xv_len - i + 1)*sizeof(cxobj *); memmove(&xv->xv_vec[i], &xv->xv_vec[i+1], size); xv->xv_len--; @@ -367,14 +369,14 @@ clixon_xvec_rm_pos(clixon_xvec *xv, * @param[in] f UNIX output stream * @param[in] xv XML tree vector * @retval 0 OK - * @retval -1 Error + * @retval -1 Error */ int clixon_xvec_print(FILE *f, clixon_xvec *xv) { int i; - + for (i=0; ixv_len; i++) if (clixon_xml2file(f, xv->xv_vec[i], 0, 1, NULL, fprintf, 0, 0) < 0) return -1; diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c index bcff49f9..5737f0b9 100644 --- a/lib/src/clixon_xpath.c +++ b/lib/src/clixon_xpath.c @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * * Note on xcur parameter to most xpath functions: * The W3 standard defines the document root / element as the top-level. @@ -158,7 +158,7 @@ static const map_str2int axis_type_map[] = { /* - * XPATH parse tree type + * XPath parse tree type */ /*! Map from axis-type int to string @@ -183,7 +183,7 @@ xpath_tree_int2str(int nodetype) return (char*)clicon_int2str(xpath_tree_map, nodetype); } -/*! Print XPATH parse tree +/*! Print XPath parse tree * * @note uses "" instead of '' in printing literals, rule [29] in https://www.w3.org/TR/xpath-10 */ @@ -217,8 +217,9 @@ xpath_tree_print0(cbuf *cb, } /*! Print a xpath_tree to CLIgen buf + * * @param[out] cb CLIgen buffer - * @param[in] xs XPATH tree + * @param[in] xs XPath tree */ int xpath_tree_print_cb(cbuf *cb, @@ -229,8 +230,11 @@ xpath_tree_print_cb(cbuf *cb, } /*! Print a xpath_tree + * * @param[in] f UNIX output stream - * @param[in] xs XPATH tree + * @param[in] xs XPath tree + * @retval 0 OK + * @retval -1 Error * @see xpath_tree2str */ int @@ -253,7 +257,8 @@ xpath_tree_print(FILE *f, } /*! Create an xpath string from an xpath tree, ie "unparsing" - * @param[in] xs XPATH tree + * + * @param[in] xs XPath tree * @param[out] xpath XPath string as CLIgen buf * @retval 0 OK * @retval -1 Error @@ -389,9 +394,9 @@ xpath_tree_append(xpath_tree *xt, * @param[in] xt2 XPath parse 2 * @param[in,out] vec XPath tree vector * @param[in,out] len Length of XML XPath vector - * @retval -1 Error - * @retval 0 Not equal * @retval 1 Equal + * @retval 0 Not equal + * @retval -1 Error */ int xpath_tree_eq(xpath_tree *xt1, /* pattern */ @@ -411,7 +416,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */ (xt2->xs_type == XP_PRIME_NR || xt2->xs_type == XP_PRIME_STR)) #endif ){ - clicon_debug(CLIXON_DBG_DETAIL, "%s type %s vs %s\n", __FUNCTION__, + clixon_debug(CLIXON_DBG_DETAIL, "%s type %s vs %s\n", __FUNCTION__, xpath_tree_int2str(xt1->xs_type), xpath_tree_int2str(xt2->xs_type)); goto neq; @@ -423,19 +428,19 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */ goto eq; } if (xt1->xs_int != xt2->xs_int){ - clicon_debug(CLIXON_DBG_DETAIL, "%s int\n", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s int\n", __FUNCTION__); goto neq; } if (xt1->xs_double != xt2->xs_double){ - clicon_debug(CLIXON_DBG_DETAIL, "%s double\n", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s double\n", __FUNCTION__); goto neq; } if (clicon_strcmp(xt1->xs_s0, xt2->xs_s0)){ - clicon_debug(CLIXON_DBG_DETAIL, "%s s0\n", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s s0\n", __FUNCTION__); goto neq; } if (clicon_strcmp(xt1->xs_s1, xt2->xs_s1)){ - clicon_debug(CLIXON_DBG_DETAIL, "%s s1\n", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s s1\n", __FUNCTION__); goto neq; } xc1 = xt1->xs_c0; @@ -444,7 +449,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */ ; else{ if (xc1 == NULL || xc2 == NULL){ - clicon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__); goto neq; } if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0) @@ -458,7 +463,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */ ; else{ if (xc1 == NULL || xc2 == NULL){ - clicon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__); goto neq; } if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0) @@ -476,6 +481,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */ } /*! Traverse through an xpath-tree using indexes + * * @param[in] xt Start-tree * @param[in] i List of indexes terminated by -1: 0 means c0, 1 means c1 * @retval xc End-tree @@ -506,7 +512,8 @@ xpath_tree_traverse(xpath_tree *xt, } /*! Free a xpath_tree - * @param[in] xs XPATH tree + * + * @param[in] xs XPath tree * @see xpath_parse creates a xpath_tree */ int @@ -527,8 +534,9 @@ xpath_tree_free(xpath_tree *xs) } /*! Given xpath, parse it, and return structured xpath tree - * @param[in] xpath String with XPATH 1.0 syntax - * @param[out] xptree XPath-tree, parsed, structured XPATH, free:xpath_tree_free + * + * @param[in] xpath String with XPath 1.0 syntax + * @param[out] xptree XPath-tree, parsed, structured XPath, free:xpath_tree_free * @retval 0 OK * @retval -1 Error * @code @@ -549,7 +557,7 @@ xpath_parse(const char *xpath, clixon_xpath_yacc xpy = {0,}; cbuf *cb = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (xpath == NULL){ clicon_err(OE_XML, EINVAL, "XPath is NULL"); goto done; @@ -562,19 +570,19 @@ 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); + 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)"); + clicon_err(OE_XML, 0, "XPath parser error with no error code (should not happen)"); xpath_scan_exit(&xpy); goto done; } - if (clicon_debug_get() > 2){ + if (clixon_debug_get() > 2){ if ((cb = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; } xpath_tree_print_cb(cb, xpy.xpy_top); - clicon_debug(CLIXON_DBG_DETAIL, "xpath parse tree:\n%s", cbuf_get(cb)); + clixon_debug(CLIXON_DBG_DETAIL, "xpath parse tree:\n%s", cbuf_get(cb)); } xpath_parse_exit(&xpy); xpath_scan_exit(&xpy); @@ -592,13 +600,14 @@ xpath_parse(const char *xpath, } /*! Given XML tree and xpath, parse xpath, eval it and return xpath context, + * * This is a raw form of xpath where you can do type conversion of the return * value, etc, not just a nodeset. * @param[in] xcur XML-tree where to search * @param[in] nsc External XML namespace context, or NULL - * @param[in] xpath String with XPATH 1.0 syntax + * @param[in] xpath String with XPath 1.0 syntax * @param[in] localonly Skip prefix and namespace tests (non-standard) - * @param[out] xrp Return XPATH context + * @param[out] xrp Return XPath context * @retval 0 OK * @retval -1 Error * @code @@ -620,7 +629,7 @@ xpath_vec_ctx(cxobj *xcur, xpath_tree *xptree = NULL; xp_ctx xc = {0,}; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (xpath_parse(xpath, &xptree) < 0) goto done; xc.xc_type = XT_NODESET; @@ -645,7 +654,7 @@ xpath_vec_ctx(cxobj *xcur, * * @param[in] xcur XML tree where to search * @param[in] nsc External XML namespace context, or NULL - * @param[in] xpformat Format string for XPATH syntax + * @param[in] xpformat Format string for XPath syntax * @retval xml-tree XML tree of first match * @retval NULL Error or not found * @@ -706,7 +715,7 @@ xpath_first(cxobj *xcur, * * Reason for skipping prefix/namespace check may be with incomplete tree, for example. * @param[in] xcur XML tree where to search - * @param[in] xpformat Format string for XPATH syntax + * @param[in] xpformat Format string for XPath syntax * @retval xml-tree XML tree of first match * @retval NULL Error or not found * @@ -765,7 +774,7 @@ xpath_first_localonly(cxobj *xcur, * 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 - * @param[in] xpformat Format string for XPATH syntax + * @param[in] xpformat Format string for XPath syntax * @param[out] vec vector of xml-trees. Vector must be free():d after use * @param[out] veclen returns length of vector in return value * @retval 0 OK @@ -832,8 +841,9 @@ xpath_vec(cxobj *xcur, } /* XPath that returns a vector of matches (only nodes marked with flags) + * * @param[in] xcur xml-tree where to search - * @param[in] xpformat Format string for XPATH syntax + * @param[in] xpformat Format string for XPath syntax * @param[in] nsc External XML namespace context, or NULL * @param[in] flags Set of flags that return nodes must match (0 if all) * @param[out] vec vector of xml-trees. Vector must be free():d after use @@ -911,10 +921,11 @@ xpath_vec_flag(cxobj *xcur, } /*! Given XML tree and xpath, returns boolean + * * Returns true if the nodeset is non-empty * @param[in] xcur xml-tree where to search * @param[in] nsc External XML namespace context, or NULL - * @param[in] xpformat Format string for XPATH syntax + * @param[in] xpformat Format string for XPath syntax * @retval 1 True * @retval 0 False * @retval -1 Error @@ -1111,7 +1122,7 @@ xpath2canonical(const char *xpath0, cbuf *xcb = NULL; int ret; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); /* Parse input xpath into an xpath-tree */ if (xpath_parse(xpath0, &xpt) < 0) goto done; @@ -1160,8 +1171,10 @@ xpath2canonical(const char *xpath0, * * @param[in] xcur xml-tree where to search * @param[in] nsc External XML namespace context, or NULL - * @param[in] xpath XPATH syntax + * @param[in] xpath XPath syntax * @param[oit] count Nr of elements of xpath + * @retval 0 OK + * @retval -1 Error * @note This function is made for making optimizations in certain circumstances, such as a list */ int @@ -1465,7 +1478,7 @@ xpath2xml_traverse(xpath_tree *xs, } retval = 1; done: - clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval); return retval; fail: retval = 0; @@ -1502,7 +1515,7 @@ xpath2xml(char *xpath, cbuf *cberr = NULL; xpath_tree *xpt = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s xpath:%s", __FUNCTION__, xpath); + clixon_debug(CLIXON_DBG_DETAIL, "%s xpath:%s", __FUNCTION__, xpath); if ((cberr = cbuf_new()) == NULL){ clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; diff --git a/lib/src/clixon_xpath_ctx.c b/lib/src/clixon_xpath_ctx.c index df6d1a3e..2450bfab 100644 --- a/lib/src/clixon_xpath_ctx.c +++ b/lib/src/clixon_xpath_ctx.c @@ -33,8 +33,8 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 - * This file defines XPATH contexts used in traversing the XPATH parse tree. + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 + * This file defines XPath contexts used in traversing the XPath parse tree. */ #include #include @@ -70,7 +70,7 @@ const map_str2int ctxmap[] = { {"nodeset", XT_NODESET}, {"bool", XT_BOOL}, {"number", XT_NUMBER}, - {"string", XT_STRING}, + {"string", XT_STRING}, {NULL, -1} }; @@ -91,7 +91,7 @@ xp_ctx * ctx_dup(xp_ctx *xc0) { xp_ctx *xc = NULL; - + if ((xc = malloc(sizeof(*xc))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -114,9 +114,10 @@ ctx_dup(xp_ctx *xc0) return xc; } -/*! Print XPATH context to CLIgen buf +/*! Print XPath context to CLIgen buf + * * @param[in] cb CLIgen buf to print to - * @param[in] xc XPATH evaluation context + * @param[in] xc XPath evaluation context * @param[in] ind Indentation margin * @param[in] str Prefix string in printout */ @@ -155,10 +156,13 @@ ctx_print_cb(cbuf *cb, return 0; } -/*! Print XPATH context +/*! Print XPath context + * * @param[in] f File to print to - * @param[in] xc XPATH evaluation context + * @param[in] xc XPath evaluation context * @param[in] str Prefix string in printout + * @retval 0 OK + * @retval -1 Error */ int ctx_print(FILE *f, @@ -181,10 +185,11 @@ ctx_print(FILE *f, return retval; } -/*! Convert xpath context to boolean according to boolean() function in XPATH spec - * @param[in] xc XPATH context - * @retval 0 False +/*! Convert xpath context to boolean according to boolean() function in XPath spec + * + * @param[in] xc XPath context * @retval 1 True + * @retval 0 False * a number is true if and only if it is neither positive or negative zero nor NaN * a node-set is true if and only if it is non-empty * a string is true if and only if its length is non-zero @@ -212,8 +217,9 @@ ctx2boolean(xp_ctx *xc) return b; } -/*! Convert xpath context to string according to string() function in XPATH spec - * @param[in] xc XPATH context +/*! Convert xpath context to string according to string() function in XPath spec + * + * @param[in] xc XPath context * @param[out] str0 Malloced result string * @retval 0 OK * @retval -1 Error @@ -227,7 +233,7 @@ ctx2string(xp_ctx *xc, char *str = NULL; int len; char *b; - + switch (xc->xc_type){ case XT_NODESET: if (xc->xc_size && (b = xml_body(xc->xc_nodeset[0]))){ @@ -240,7 +246,7 @@ ctx2string(xp_ctx *xc, if ((str = strdup("")) == NULL){ clicon_err(OE_XML, errno, "strdup"); goto done; - } + } break; case XT_BOOL: if ((str = strdup(xc->xc_bool == 0?"false":"true")) == NULL){ @@ -270,8 +276,9 @@ ctx2string(xp_ctx *xc, return retval; } -/*! Convert xpath context to number according to number() function in XPATH spec - * @param[in] xc XPATH context +/*! Convert xpath context to number according to number() function in XPath spec + * + * @param[in] xc XPath context * @param[out] n0 Floating point or NAN * @retval 0 OK * @retval -1 Error @@ -283,7 +290,7 @@ ctx2number(xp_ctx *xc, int retval = -1; char *str = NULL; double n = NAN; - + switch (xc->xc_type){ case XT_NODESET: if (ctx2string(xc, &str) < 0) @@ -310,7 +317,7 @@ ctx2number(xp_ctx *xc, return retval; } -/*! Replace a nodeset of a XPATH context with a new nodeset +/*! Replace a nodeset of a XPath context with a new nodeset */ int ctx_nodeset_replace(xp_ctx *xc, diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index 48bbb1b0..22a5fd7f 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * * Some notes on namespace extensions in Netconf/Yang * RFC6241 8.9.1 @@ -90,7 +90,7 @@ #include "clixon_xpath_function.h" #include "clixon_xpath_eval.h" -/* Mapping between XPATH operator string <--> int */ +/* Mapping between XPath operator string <--> int */ const map_str2int xpopmap[] = { {"and", XO_AND}, {"or", XO_OR}, @@ -105,14 +105,15 @@ const map_str2int xpopmap[] = { {"<=", XO_LE}, {"<", XO_LT}, {">", XO_GT}, - {"|", XO_UNION}, + {"|", XO_UNION}, {NULL, -1} }; -/*! Eval an XPATH nodetest - * @retval -1 Error XXX: retval -1 not properly handled - * @retval 0 No match +/*! Eval an XPath nodetest + * * @retval 1 Match + * @retval 0 No match + * @retval -1 Error XXX: retval -1 not properly handled */ static int nodetest_eval_node(cxobj *x, @@ -140,7 +141,7 @@ nodetest_eval_node(cxobj *x, retval = 0; /* no match */ goto done; } - /* Here names are equal + /* Here names are equal * Now look for namespaces * 1) prefix1 and prefix2 point to same namespace <<-- try this first * 2) prefix1 is equal to prefix2 <<-- then try this @@ -156,7 +157,7 @@ nodetest_eval_node(cxobj *x, * This can happen in eg augments and ../foo, where foo is * augmented from another namespace */ - retval = 1; + retval = 1; } else retval = (nsxml == nsxpath); /* True only if both are NULL */ @@ -181,7 +182,8 @@ nodetest_eval_node(cxobj *x, return retval; } -/*! Eval an XPATH nodetest but skip prefix and namespace tests +/*! Eval an XPath nodetest but skip prefix and namespace tests + * * This is NOT according to standard */ static int @@ -210,13 +212,14 @@ nodetest_eval_node_localonly(cxobj *x, } /*! Make a nodetest + * * @param[in] x XML node - * @param[in] xs XPATH stack of type XP_NODE or XP_NODE_FN + * @param[in] xs XPath stack of type XP_NODE or XP_NODE_FN * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) - * @retval -1 Error - * @retval 0 No match * @retval 1 Match + * @retval 0 No match + * @retval -1 Error * - node() is true for any node of any type whatsoever. * - text() is true for any text node. */ @@ -248,18 +251,21 @@ nodetest_eval(cxobj *x, return retval; } -/*! +/*! test node recursive + * * @param[in] xn - * @param[in] nodetest XPATH stack + * @param[in] nodetest XPath stack * @param[in] node_type * @param[in] flags * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) * @param[out] vec0 * @param[out] vec0len + * @retval 0 OK + * @retval -1 Error */ int -nodetest_recursive(cxobj *xn, +nodetest_recursive(cxobj *xn, xpath_tree *nodetest, int node_type, uint16_t flags, @@ -269,14 +275,14 @@ nodetest_recursive(cxobj *xn, int *vec0len) { int retval = -1; - cxobj *xsub; + cxobj *xsub; cxobj **vec = *vec0; int veclen = *vec0len; xsub = NULL; while ((xsub = xml_child_each(xn, xsub, node_type)) != NULL) { if (nodetest_eval(xsub, nodetest, nsc, localonly) == 1){ - clicon_debug(CLIXON_DBG_DETAIL, "%s %x %x", __FUNCTION__, flags, xml_flag(xsub, flags)); + clixon_debug(CLIXON_DBG_DETAIL, "%s %x %x", __FUNCTION__, flags, xml_flag(xsub, flags)); if (flags==0x0 || xml_flag(xsub, flags)) if (cxvec_append(xsub, &vec, &veclen) < 0) goto done; @@ -294,11 +300,13 @@ nodetest_recursive(cxobj *xn, /*! Evaluate xpath step rule of an XML tree * - * @param[in] xc0 Incoming context - * @param[in] xs XPATH node tree - * @param[in] nsc XML Namespace context + * @param[in] xc0 Incoming context + * @param[in] xs XPath node tree + * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) - * @param[out] xrp Resulting context + * @param[out] xrp Resulting context + * @retval 0 OK + * @retval -1 Error * * - A node test that is a QName is true if and only if the type of the node (see [5 Data Model]) * is the principal node type and has an expanded-name equal to the expanded-name specified by the QName. @@ -323,7 +331,7 @@ xp_eval_step(xp_ctx *xc0, xpath_tree *nodetest = xs->xs_c0; xp_ctx *xc = NULL; int ret; - + /* Create new xc */ if ((xc = ctx_dup(xc0)) == NULL) goto done; @@ -344,9 +352,9 @@ xp_eval_step(xp_ctx *xc0, xc->xc_descendant = 0; } else{ - for (i=0; ixc_size; i++){ + for (i=0; ixc_size; i++){ xv = xc->xc_nodeset[i]; - x = NULL; + x = NULL; if ((ret = xpath_optimize_check(xs, xv, &vec, &veclen)) < 0) goto done; if (ret == 0){/* regular code, no optimization made */ @@ -358,7 +366,7 @@ xp_eval_step(xp_ctx *xc0, goto done; } } - } + } } } ctx_nodeset_replace(xc, vec, veclen); @@ -447,11 +455,13 @@ xp_eval_step(xp_ctx *xc0, /*! Evaluate xpath predicates rule * * pred -> pred expr - * @param[in] xc Incoming context - * @param[in] xs XPATH node tree - * @param[in] nsc XML Namespace context + * @param[in] xc Incoming context + * @param[in] xs XPath node tree + * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) - * @param[out] xrp Resulting context + * @param[out] xrp Resulting context + * @retval 0 OK + * @retval -1 Error * * A predicate filters a node-set with respect to an axis to produce a new * node-set. For each node in the node-set to be filtered, the PredicateExpr is @@ -482,10 +492,10 @@ xp_eval_predicate(xp_ctx *xc, int i; cxobj *x; xp_ctx *xcc = NULL; - + if (xs->xs_c0 != NULL){ /* eval previous predicates */ - if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) - goto done; + if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) + goto done; } else{ /* empty */ if ((xr0 = ctx_dup(xc)) == NULL) @@ -529,14 +539,14 @@ xp_eval_predicate(xp_ctx *xc, if the number is equal to the context position */ if ((int)xrc->xc_number == i) if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0) - goto done; + goto done; } else { - /* if PredicateExpr evaluates to true for that node, the node is + /* if PredicateExpr evaluates to true for that node, the node is included in the new node-set */ if (ctx2boolean(xrc)) if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0) - goto done; + goto done; } if (xrc) ctx_free(xrc); @@ -565,7 +575,8 @@ xp_eval_predicate(xp_ctx *xc, return retval; } -/*! Given two XPATH contexts, eval logical operations: or,and +/*! Given two XPath contexts, eval logical operations: or,and + * * The logical operators convert their operands to booleans * @param[in] xc1 Context of operand1 * @param[in] xc2 Context of operand2 @@ -584,7 +595,7 @@ xp_logop(xp_ctx *xc1, xp_ctx *xr = NULL; int b1; int b2; - + if ((xr = malloc(sizeof(*xr))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -614,7 +625,8 @@ xp_logop(xp_ctx *xc1, return retval; } -/*! Given two XPATH contexts, eval numeric operations: +-*,div,mod +/*! Given two XPath contexts, eval numeric operations: +-*,div,mod + * * The numeric operators convert their operands to numbers as if by * calling the number function. * @param[in] xc1 Context of operand1 @@ -634,7 +646,7 @@ xp_numop(xp_ctx *xc1, xp_ctx *xr = NULL; double n1; double n2; - + if ((xr = malloc(sizeof(*xr))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -677,6 +689,7 @@ xp_numop(xp_ctx *xc1, } /*! Get xml body value as cligen variable + * * @param[in] x XML node (body and leaf/leaf-list) * @param[out] cvp Pointer to cligen variable containing value of x body * @retval 0 OK, cvp contains cv or NULL @@ -700,7 +713,7 @@ xml_cv_cache(cxobj *x, int options = 0; uint8_t fraction = 0; char *body; - + if ((body = xml_body(x)) == NULL) body=""; if ((cv = xml_cv(x)) != NULL) @@ -723,7 +736,6 @@ xml_cv_cache(cxobj *x, } 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"); goto done; @@ -746,7 +758,8 @@ xml_cv_cache(cxobj *x, return retval; } -/*! Given two XPATH contexts, eval relational operations: <>= +/*! Given two XPath contexts, eval relational operations: <>= + * * A RelationalExpr is evaluated by comparing the objects that result from * evaluating the two operands. * This is covered: @@ -755,7 +768,7 @@ xml_cv_cache(cxobj *x, * (c) One is nodeset and other is INT or STRING. Result type is nodeset * (d) All others (eg two nodesets, BOOL+STRING) are not supported. * Op is = EQ - * From XPATH 1.0 standard, the evaluation has three variants: + * From XPath 1.0 standard, the evaluation has three variants: * (1) comparisons that involve node-sets are defined in terms of comparisons that * do not involve node-sets; this is defined uniformly for =, !=, <=, <, >= and >. * (2) comparisons that do not involve node-sets are defined for = and !=. @@ -788,7 +801,7 @@ xp_relop(xp_ctx *xc1, char *xb; cg_var *cv1, *cv2; int ret; - + if (xc1 == NULL || xc2 == NULL){ clicon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL"); goto done; @@ -1056,7 +1069,8 @@ xp_relop(xp_ctx *xc1, return retval; } -/*! Given two XPATH contexts, eval union operation +/*! Given two XPath contexts, eval union operation + * * Both operands must be nodesets, otherwise empty nodeset is returned * @param[in] xc1 Context of operand1 * @param[in] xc2 Context of operand2 @@ -1074,7 +1088,7 @@ xp_union(xp_ctx *xc1, int retval = -1; xp_ctx *xr = NULL; int i; - + if (op != XO_UNION){ clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context", __FUNCTION__, clicon_int2str(xpopmap,op)); @@ -1101,12 +1115,12 @@ xp_union(xp_ctx *xc1, return retval; } -/*! Evaluate an XPATH on an XML tree - +/*! Evaluate an XPath on an XML tree + * * The initial sequence of steps selects a set of nodes relative to a context node. * Each node in that set is used as a context node for the following step. * @param[in] xc Incoming context - * @param[in] xs XPATH node tree + * @param[in] xs XPath node tree * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) * @param[out] xrp Resulting context @@ -1126,7 +1140,7 @@ xp_eval(xp_ctx *xc, xp_ctx *xr1 = NULL; xp_ctx *xr2 = NULL; int use_xr0 = 0; /* In 2nd child use transitively result of 1st child */ - + // ctx_print(stderr, xc, xpath_tree_int2str(xs->xs_type)); /* Pre-actions before check first child c0 */ @@ -1231,7 +1245,7 @@ xp_eval(xp_ctx *xc, goto ok; break; default: - clicon_err(OE_XML, EFAULT, "XPATH function not implemented: %s", xs->xs_s0); + clicon_err(OE_XML, EFAULT, "XPath function not implemented: %s", xs->xs_s0); goto done; break; } @@ -1243,7 +1257,7 @@ xp_eval(xp_ctx *xc, /* Eval first child c0 */ if (xs->xs_c0){ - if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) + if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; } /* Actions between first and second child @@ -1327,7 +1341,7 @@ xp_eval(xp_ctx *xc, * Note, some operators like locationpath, need transitive context (use_xr0) */ if (xs->xs_c1){ - if (xp_eval(use_xr0?xr0:xc, xs->xs_c1, nsc, localonly, &xr1) < 0) + if (xp_eval(use_xr0?xr0:xc, xs->xs_c1, nsc, localonly, &xr1) < 0) goto done; /* Actions after second child */ diff --git a/lib/src/clixon_xpath_eval.h b/lib/src/clixon_xpath_eval.h index 8f3538f0..778807af 100644 --- a/lib/src/clixon_xpath_eval.h +++ b/lib/src/clixon_xpath_eval.h @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 */ #ifndef _CLIXON_XPATH_EVAL_H #define _CLIXON_XPATH_EVAL_H diff --git a/lib/src/clixon_xpath_function.c b/lib/src/clixon_xpath_function.c index 5d718496..71f293d6 100644 --- a/lib/src/clixon_xpath_function.c +++ b/lib/src/clixon_xpath_function.c @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * and rfc 7950 * */ @@ -74,12 +74,13 @@ #include "clixon_xpath_function.h" /*! xpath function translation table + * * @see enum clixon_xpath_function */ static const map_str2int xpath_fnname_map[] = { /* alphabetic order */ {"bit-is-set", XPATHFN_BIT_IS_SET}, {"boolean", XPATHFN_BOOLEAN}, - {"eiling", XPATHFN_CEILING}, + {"eiling", XPATHFN_CEILING}, {"comment", XPATHFN_COMMENT}, {"concat", XPATHFN_CONCAT}, {"contains", XPATHFN_CONTAINS}, @@ -144,7 +145,7 @@ xp_function_current(xp_ctx *xc0, cxobj **vec = NULL; int veclen = 0; xp_ctx *xc = NULL; - + if ((xc = ctx_dup(xc0)) == NULL) goto done; if (cxvec_append(xc->xc_initial, &vec, &veclen) < 0) @@ -177,7 +178,7 @@ xp_function_deref(xp_ctx *xc0, yang_stmt *yt; yang_stmt *ypath; char *path; - + /* Create new xc */ if ((xc = ctx_dup(xc0)) == NULL) goto done; @@ -210,6 +211,7 @@ xp_function_deref(xp_ctx *xc0, } /*! Helper function for derived-from(-and-self) - eval one node + * * @param[in] nsc XML Namespace context * @param[in] self If set, implements derived_from_or_self * @retval 1 OK and match @@ -279,7 +281,7 @@ derived_from_one(char *baseidentity, else { /* Allocate cbuf */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "%s:%s", yang_argument_get(ymod), id); @@ -303,8 +305,9 @@ derived_from_one(char *baseidentity, } /*! Eval xpath function derived-from(-and-self) + * * @param[in] xc Incoming context - * @param[in] xs XPATH node tree + * @param[in] xs XPath node tree * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) * @param[in] self If set, implements derived_from_or_self @@ -332,19 +335,19 @@ xp_function_derived_from(xp_ctx *xc, char *identity = NULL; int i; 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"); goto done; } /* contains two arguments in xs: boolean derived-from(node-set, string) */ /* This evolves to a set of (identityref) nodes */ - if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) + if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; if (xr0->xc_type != XT_NODESET) goto done; /* This evolves to a string identity */ - if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0) + if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0) goto done; if (ctx2string(xr1, &identity) < 0) goto done; @@ -385,7 +388,7 @@ xp_function_derived_from(xp_ctx *xc, * Signature: boolean bit-is-set(node-set nodes, string bit-name) * @param[in] xc Incoming context - * @param[in] xs XPATH node tree + * @param[in] xs XPath node tree * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) * @param[out] xrp Resulting context @@ -410,16 +413,16 @@ xp_function_bit_is_set(xp_ctx *xc, char *s1 = NULL; cxobj *x; 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"); goto done; } /* First node-set argument */ - if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) + if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; /* Second string argument */ - if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0) + if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0) goto done; if (ctx2string(xr1, &s1) < 0) goto done; @@ -454,7 +457,7 @@ xp_function_bit_is_set(xp_ctx *xc, * * Signature: number position(node-set) * @param[in] xc Incoming context - * @param[in] xs XPATH node tree + * @param[in] xs XPath node tree * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) * @param[out] xrp Resulting context @@ -470,7 +473,7 @@ xp_function_position(xp_ctx *xc, { int retval = -1; xp_ctx *xr = NULL; - + if ((xr = malloc(sizeof(*xr))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -499,12 +502,12 @@ xp_function_count(xp_ctx *xc, int retval = -1; xp_ctx *xr = NULL; xp_ctx *xr0 = NULL; - + if (xs == NULL || xs->xs_c0 == NULL){ clicon_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) + 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"); @@ -541,12 +544,12 @@ xp_function_name(xp_ctx *xc, char *s0 = NULL; int i; cxobj *x; - + if (xs == NULL || xs->xs_c0 == NULL){ clicon_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) + 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"); @@ -574,8 +577,9 @@ xp_function_name(xp_ctx *xc, } /*! Eval xpath function contains + * * @param[in] xc Incoming context - * @param[in] xs XPATH node tree + * @param[in] xs XPath node tree * @param[in] nsc XML Namespace context * @param[in] localonly Skip prefix and namespace tests (non-standard) * @param[out] xrp Resulting context @@ -602,11 +606,11 @@ xp_function_contains(xp_ctx *xc, goto done; } /* contains two arguments in xs: boolean contains(string, string) */ - if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) + if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; if (ctx2string(xr0, &s0) < 0) goto done; - if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0) + if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0) goto done; if (ctx2string(xr1, &s1) < 0) goto done; @@ -653,12 +657,12 @@ xp_function_boolean(xp_ctx *xc, xp_ctx *xr = NULL; xp_ctx *xr0 = NULL; int bool; - + if (xs == NULL || xs->xs_c0 == NULL){ clicon_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) + if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; bool = ctx2boolean(xr0); if ((xr = malloc(sizeof(*xr))) == NULL){ @@ -706,7 +710,7 @@ xp_function_true(xp_ctx *xc, { int retval = -1; xp_ctx *xr = NULL; - + if ((xr = malloc(sizeof(*xr))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -733,7 +737,7 @@ xp_function_false(xp_ctx *xc, { int retval = -1; xp_ctx *xr = NULL; - + if ((xr = malloc(sizeof(*xr))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; diff --git a/lib/src/clixon_xpath_function.h b/lib/src/clixon_xpath_function.h index e9980950..23f0774b 100644 --- a/lib/src/clixon_xpath_function.h +++ b/lib/src/clixon_xpath_function.h @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 (Base XML) + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 (Base XML) * and rfc 7950 (YANG-specific) */ #ifndef _CLIXON_XPATH_FUNCTION_H diff --git a/lib/src/clixon_xpath_optimize.c b/lib/src/clixon_xpath_optimize.c index a9647c66..d77d0f17 100644 --- a/lib/src/clixon_xpath_optimize.c +++ b/lib/src/clixon_xpath_optimize.c @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * See XPATH_LIST_OPTIMIZE */ @@ -89,6 +89,7 @@ xpath_list_optimize_stats(int *hits) } /*! Enable xpath optimize + * * Cant replace this with option since there is no handle in xpath functions,... */ int @@ -111,6 +112,7 @@ xpath_optimize_exit(void) #ifdef XPATH_LIST_OPTIMIZE /*! Initialize xpath module + * * XXX move to clixon_xpath.c * @see loop_preds */ @@ -120,10 +122,10 @@ xpath_optimize_init(xpath_tree **xm, { int retval = -1; xpath_tree *xs; - + if (_xm == NULL){ /* Initialize xpath-tree */ - if (xpath_parse("_x[_y='_z']", &_xmtop) < 0) + if (xpath_parse("_x[_y='_z']", &_xmtop) < 0) goto done; /* Go down two steps */ if ((_xm = xpath_tree_traverse(_xmtop, 0, 0, -1)) == NULL) @@ -161,9 +163,9 @@ xpath_optimize_init(xpath_tree **xm, * @param[in] xt XPath tree of type PRED * @param[in] xepat Pattern matching XPath tree of type EXPR * @param[out] cvk Vector of : pairs - * @retval -1 Error - * @retval 0 No match * @retval 1 Match + * @retval 0 No match + * @retval -1 Error * @see xpath_optimize_init */ static int @@ -177,7 +179,7 @@ loop_preds(xpath_tree *xt, xpath_tree **vec = NULL; size_t veclen = 0; cg_var *cvi; - + if (xt->xs_type == XP_PRED && xt->xs_c0){ if ((ret = loop_preds(xt->xs_c0, xepat, cvk)) < 0) goto done; @@ -192,7 +194,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"); + clicon_err(OE_XML, errno, "cvec_add"); goto done; } cv_name_set(cvi, vec[0]->xs_s1); @@ -219,9 +221,9 @@ loop_preds(xpath_tree *xt, * @param[out] xlen Len of xvec * @param[out] key * @param[out] keyval - * @retval -1 Error - * @retval 0 No match - use non-optimized lookup * @retval 1 Match + * @retval 0 No match - use non-optimized lookup + * @retval -1 Error * XPath: * y[k=3] # corresponds to: [=] */ @@ -245,7 +247,7 @@ xpath_list_optimize_fn(xpath_tree *xt, cg_var *cvi; int i; yang_stmt *ypp; - + /* revert to non-optimized if no yang */ if ((yp = xml_spec(xv)) == NULL) goto ok; @@ -277,13 +279,13 @@ xpath_list_optimize_fn(xpath_tree *xt, #ifdef NOTYET /* leaf-list is not detected by xpath optimize detection */ if ((yc = yang_find(yp, Y_LEAF_LIST, name)) == NULL) /* XXX */ #endif - goto ok; + goto ok; /* Validate keys */ if ((cvv = yang_cvec_get(yc)) == NULL) goto ok; xtp = vec[1]; if ((cvk = cvec_new(0)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_new"); + clicon_err(OE_YANG, errno, "cvec_new"); goto done; } if ((ret = loop_preds(xtp, xem, cvk)) < 0) @@ -316,23 +318,23 @@ xpath_list_optimize_fn(xpath_tree *xt, } #endif /* XPATH_LIST_OPTIMIZE */ -/*! Identify XPATH special cases and if match, use binary search. +/*! Identify XPath special cases and if match, use binary search. * - * @retval -1 Error - * @retval 0 Dont optimize: not special case, do normal processing * @retval 1 Optimization made, special case, use x (found if != NULL) + * @retval 0 Dont optimize: not special case, do normal processing + * @retval -1 Error * XXX Contains glue code between cxobj ** and clixon_xvec code */ int xpath_optimize_check(xpath_tree *xs, cxobj *xv, - cxobj ***xvec0, + cxobj ***xvec0, int *xlen0) { #ifdef XPATH_LIST_OPTIMIZE int ret; clixon_xvec *xvec = NULL; - + if (!_optimize_enable) return 0; /* use regular code */ if ((xvec = clixon_xvec_new()) == NULL) diff --git a/lib/src/clixon_xpath_parse.h b/lib/src/clixon_xpath_parse.h index 569edfa4..f2b0d722 100644 --- a/lib/src/clixon_xpath_parse.h +++ b/lib/src/clixon_xpath_parse.h @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 */ #ifndef _CLIXON_XPATH_PARSE_H_ #define _CLIXON_XPATH_PARSE_H_ @@ -40,7 +40,7 @@ /* * Types */ -struct clixon_xpath_yacc{ +struct clixon_xpath_yacc{ const char *xpy_name; /* Name of syntax (for error string) */ int xpy_linenum; /* Number of \n in parsed buffer */ const char *xpy_parse_string; /* original (copy of) parse string */ diff --git a/lib/src/clixon_xpath_parse.l b/lib/src/clixon_xpath_parse.l index 80e7adb0..3e81b4be 100644 --- a/lib/src/clixon_xpath_parse.l +++ b/lib/src/clixon_xpath_parse.l @@ -91,7 +91,7 @@ There are some special lexical rules in https://www.w3.org/TR/xpath-10 #define _XPY ((clixon_xpath_yacc *)_yy) #undef clixon_xpath_parsewrap -int +int clixon_xpath_parsewrap(void) { return 1; @@ -120,7 +120,7 @@ ncname {namestart}{namechar}* %s ALITERAL %% -[ \t] +[ \t] \n { _XPY->xpy_linenum++; } \r { } <> { return X_EOF; } @@ -147,11 +147,11 @@ ncname {namestart}{namechar}* {ncname} { /* See lexical rules 2 and 3 in the file header */ clixon_xpath_parselval.string = strdup(yytext); - return NCNAME; - } + return NCNAME; + } . { fprintf(stderr,"LEXICAL ERROR\n"); return -1; } -[ \t] +[ \t] \n { _XPY->xpy_linenum++; } \r { } <> { return X_EOF; } @@ -175,15 +175,15 @@ ncname {namestart}{namechar}* \' { BEGIN(TOKEN0); _XPY->xpy_lex_string_state=TOKEN2; BEGIN(ALITERAL); return APOST; } \-?({integer}|{real}) { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); return NUMBER; } -comment\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } -text\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } -processing-instructions\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } -node\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } +comment\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } +text\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } +processing-instructions\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } +node\( { BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); striplast(clixon_xpath_parselval.string); return NODETYPE; } {ncname} { /* See lexical rules 2 and 3 in the file header */ - BEGIN(TOKEN0); + BEGIN(TOKEN0); clixon_xpath_parselval.string = strdup(yytext); - return NCNAME; - } + return NCNAME; + } . { fprintf(stderr,"LEXICAL ERROR\n"); return -1; } \" { BEGIN(_XPY->xpy_lex_string_state); return QUOTE; } @@ -205,7 +205,7 @@ xpath_scan_init(clixon_xpath_yacc *xpy) xpy->xpy_lexbuf = yy_scan_string (xpy->xpy_parse_string); #if 1 /* XXX: just to use unput to avoid warning */ if (0) - yyunput(0, ""); + yyunput(0, ""); #endif return 0; diff --git a/lib/src/clixon_xpath_parse.y b/lib/src/clixon_xpath_parse.y index a17a86c3..9ffa2c35 100644 --- a/lib/src/clixon_xpath_parse.y +++ b/lib/src/clixon_xpath_parse.y @@ -32,7 +32,7 @@ ***** END LICENSE BLOCK ***** - * XPATH Parser + * XPath Parser * From https://www.w3.org/TR/xpath-10/ * The primary syntactic construct in XPath is the expression. * An expression matches the production Expr @@ -101,7 +101,7 @@ #define _YYERROR(msg) {clicon_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 +#define YY_(msgid) msgid #include "clixon_config.h" @@ -134,12 +134,12 @@ /* Best debugging is to enable PARSE_DEBUG below and add -d to the LEX compile statement in the Makefile * And then run the testcase with -D 1 - * Disable it to stop any calls to clicon_debug. Having it on by default would mean very large debug outputs. + * Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs. */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) -#define _PARSE_DEBUG1(s, s1) clicon_debug(1,(s), (s1)) -#define _PARSE_DEBUG2(s, s1, s2) clicon_debug(1,(s), (s1), (s2)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) +#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1)) +#define _PARSE_DEBUG2(s, s1, s2) clixon_debug(1,(s), (s1), (s2)) #else #define _PARSE_DEBUG(s) #define _PARSE_DEBUG1(s, s1) @@ -148,27 +148,27 @@ extern int clixon_xpath_parseget_lineno (void); /*XXX obsolete ? */ -/* +/* also called from yacc generated code * */ -void +void clixon_xpath_parseerror(void *_xpy, - char *s) -{ + 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 */ _XPY->xpy_name, - _XPY->xpy_linenum , - s, - clixon_xpath_parsetext); - return; + _XPY->xpy_linenum, + s, + clixon_xpath_parsetext); + return; } int xpath_parse_init(clixon_xpath_yacc *xpy) { - // clicon_debug_init(3, NULL); + // clixon_debug_init(3, NULL); return 0; } @@ -177,11 +177,11 @@ xpath_parse_exit(clixon_xpath_yacc *xpy) { return 0; } - + /*! Generic creator function for an xpath tree object * - * @param[in] type XPATH tree node type - * @param[in] i0 step-> axis_type + * @param[in] type XPath tree node type + * @param[in] i0 step-> axis_type * @param[in] numstr original string xs_double: numeric value * @param[in] s0 String 0 set if XP_PRIME_STR, XP_PRIME_FN, XP_NODE[_FN] PATHEXPRE prefix * @param[in] s1 String 1 set if XP_NODE NAME (or "*") @@ -198,7 +198,7 @@ xp_new(enum xp_type type, xpath_tree *c1) { xpath_tree *xs = NULL; - + if ((xs = malloc(sizeof(xpath_tree))) == NULL){ clicon_err(OE_XML, errno, "malloc"); goto done; @@ -239,7 +239,7 @@ xp_primary_function(clixon_xpath_yacc *xpy, enum clixon_xpath_function fn; cbuf *cb = NULL; int ret; - + if ((ret = xp_fnname_str2int(name)) < 0){ if ((cb = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); @@ -253,7 +253,7 @@ xp_primary_function(clixon_xpath_yacc *xpy, switch (fn){ case XPATHFN_RE_MATCH: /* Group of NOT IMPLEMENTED xpath functions */ case XPATHFN_ENUM_VALUE: - case XPATHFN_LAST: + case XPATHFN_LAST: case XPATHFN_ID: case XPATHFN_LOCAL_NAME: case XPATHFN_NAMESPACE_URI: @@ -276,7 +276,7 @@ xp_primary_function(clixon_xpath_yacc *xpy, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - cprintf(cb, "XPATH function \"%s\" is not implemented", name); + cprintf(cb, "XPath function \"%s\" is not implemented", name); clixon_xpath_parseerror(xpy, cbuf_get(cb)); goto done; break; @@ -294,14 +294,14 @@ xp_primary_function(clixon_xpath_yacc *xpy, case XPATHFN_TRUE: case XPATHFN_FALSE: break; - default: + default: if ((cb = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath function \"%s\"", name); clixon_xpath_parseerror(xpy, cbuf_get(cb)); - goto done; + goto done; break; } if (cb) @@ -349,21 +349,21 @@ xp_nodetest_function(clixon_xpath_yacc *xpy, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - cprintf(cb, "XPATH function \"%s\" is not implemented", name); + cprintf(cb, "XPath function \"%s\" is not implemented", name); clixon_xpath_parseerror(xpy, cbuf_get(cb)); goto done; break; case XPATHFN_TEXT: /* Group of implemented node functions */ - case XPATHFN_NODE: + case XPATHFN_NODE: break; - default: + default: if ((cb = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath nodetest function \"%s\"", name); clixon_xpath_parseerror(xpy, cbuf_get(cb)); - goto done; + goto done; break; } if (cb) @@ -404,63 +404,63 @@ xp_axisname_function(clixon_xpath_yacc *xpy, return fn; } -%} - +%} + %% /* */ -start : expr X_EOF { _XPY->xpy_top=$1;_PARSE_DEBUG("start->expr"); YYACCEPT; } - | locationpath X_EOF { _XPY->xpy_top=$1;_PARSE_DEBUG("start->locationpath"); YYACCEPT; } +start : expr X_EOF { _XPY->xpy_top=$1;_PARSE_DEBUG("start->expr"); YYACCEPT; } + | locationpath X_EOF { _XPY->xpy_top=$1;_PARSE_DEBUG("start->locationpath"); YYACCEPT; } ; -expr : expr LOGOP andexpr { $$=xp_new(XP_EXP,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$; _PARSE_DEBUG("expr->expr or andexpr"); } - | andexpr { $$=xp_new(XP_EXP,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("expr-> andexpr"); } +expr : expr LOGOP andexpr { $$=xp_new(XP_EXP,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$; _PARSE_DEBUG("expr->expr or andexpr"); } + | andexpr { $$=xp_new(XP_EXP,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("expr-> andexpr"); } ; -andexpr : andexpr LOGOP relexpr { $$=xp_new(XP_AND,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("andexpr-> andexpr and relexpr"); } - | relexpr { $$=xp_new(XP_AND,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("andexpr-> relexpr"); } +andexpr : andexpr LOGOP relexpr { $$=xp_new(XP_AND,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("andexpr-> andexpr and relexpr"); } + | relexpr { $$=xp_new(XP_AND,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("andexpr-> relexpr"); } ; -relexpr : relexpr RELOP addexpr { $$=xp_new(XP_RELEX,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("relexpr-> relexpr relop addexpr"); } - | addexpr { $$=xp_new(XP_RELEX,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("relexpr-> addexpr"); } +relexpr : relexpr RELOP addexpr { $$=xp_new(XP_RELEX,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("relexpr-> relexpr relop addexpr"); } + | addexpr { $$=xp_new(XP_RELEX,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("relexpr-> addexpr"); } ; -addexpr : addexpr ADDOP unionexpr { $$=xp_new(XP_ADD,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("addexpr-> addexpr ADDOP unionexpr"); } - | unionexpr { $$=xp_new(XP_ADD,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("addexpr-> unionexpr"); } +addexpr : addexpr ADDOP unionexpr { $$=xp_new(XP_ADD,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("addexpr-> addexpr ADDOP unionexpr"); } + | unionexpr { $$=xp_new(XP_ADD,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("addexpr-> unionexpr"); } ; /* node-set */ -unionexpr : unionexpr '|' pathexpr { $$=xp_new(XP_UNION,XO_UNION,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("unionexpr-> unionexpr | pathexpr"); } - | pathexpr { $$=xp_new(XP_UNION,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("unionexpr-> pathexpr"); } +unionexpr : unionexpr '|' pathexpr { $$=xp_new(XP_UNION,XO_UNION,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("unionexpr-> unionexpr | pathexpr"); } + | pathexpr { $$=xp_new(XP_UNION,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("unionexpr-> pathexpr"); } ; -pathexpr : locationpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> locationpath"); } +pathexpr : locationpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> locationpath"); } | filterexpr { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr"); } | filterexpr '/' rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("/"),NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr / rellocpath"); } - | filterexpr DOUBLESLASH rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("//"),NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr // rellocpath"); } + | filterexpr DOUBLESLASH rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("//"),NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr // rellocpath"); } ; /* */ -filterexpr : primaryexpr { $$=xp_new(XP_FILTEREXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("filterexpr-> primaryexpr"); } +filterexpr : primaryexpr { $$=xp_new(XP_FILTEREXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("filterexpr-> primaryexpr"); } /* Filterexpr predicate */ ; /* location path returns a node-set */ -locationpath : rellocpath { $$=xp_new(XP_LOCPATH,A_NAN,NULL,NULL,NULL,$1, NULL); _PARSE_DEBUG("locationpath-> rellocpath"); } - | abslocpath { $$=xp_new(XP_LOCPATH,A_NAN,NULL,NULL,NULL,$1, NULL); _PARSE_DEBUG("locationpath-> abslocpath"); } +locationpath : rellocpath { $$=xp_new(XP_LOCPATH,A_NAN,NULL,NULL,NULL,$1, NULL); _PARSE_DEBUG("locationpath-> rellocpath"); } + | abslocpath { $$=xp_new(XP_LOCPATH,A_NAN,NULL,NULL,NULL,$1, NULL); _PARSE_DEBUG("locationpath-> abslocpath"); } ; abslocpath : '/' { $$=xp_new(XP_ABSPATH,A_ROOT,NULL,NULL,NULL,NULL, NULL);_PARSE_DEBUG("abslocpath-> /"); } | '/' rellocpath { $$=xp_new(XP_ABSPATH,A_ROOT,NULL,NULL,NULL,$2, NULL);_PARSE_DEBUG("abslocpath->/ rellocpath");} /* // is short for /descendant-or-self::node()/ */ - | DOUBLESLASH rellocpath {$$=xp_new(XP_ABSPATH,A_DESCENDANT_OR_SELF,NULL,NULL,NULL,$2, NULL); _PARSE_DEBUG("abslocpath-> // rellocpath"); } + | DOUBLESLASH rellocpath {$$=xp_new(XP_ABSPATH,A_DESCENDANT_OR_SELF,NULL,NULL,NULL,$2, NULL); _PARSE_DEBUG("abslocpath-> // rellocpath"); } ; -rellocpath : step { $$=xp_new(XP_RELLOCPATH,A_NAN,NULL,NULL,NULL,$1, NULL); _PARSE_DEBUG("rellocpath-> step"); } - | rellocpath '/' step { $$=xp_new(XP_RELLOCPATH,A_NAN,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("rellocpath-> rellocpath / step"); } - | rellocpath DOUBLESLASH step { $$=xp_new(XP_RELLOCPATH,A_DESCENDANT_OR_SELF,NULL,NULL,NULL,$1, $3); _PARSE_DEBUG("rellocpath-> rellocpath // step"); } +rellocpath : step { $$=xp_new(XP_RELLOCPATH,A_NAN,NULL,NULL,NULL,$1, NULL); _PARSE_DEBUG("rellocpath-> step"); } + | rellocpath '/' step { $$=xp_new(XP_RELLOCPATH,A_NAN,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("rellocpath-> rellocpath / step"); } + | rellocpath DOUBLESLASH step { $$=xp_new(XP_RELLOCPATH,A_DESCENDANT_OR_SELF,NULL,NULL,NULL,$1, $3); _PARSE_DEBUG("rellocpath-> rellocpath // step"); } ; step : nodetest predicates @@ -472,8 +472,8 @@ step : nodetest predicates | abbreviatedstep { $$ = $1; } ; -abbreviatedstep : '.' predicates { $$=xp_new(XP_STEP,A_SELF, NULL,NULL, NULL, NULL, $2); _PARSE_DEBUG("step-> ."); } - | DOUBLEDOT predicates { $$=xp_new(XP_STEP, A_PARENT, NULL,NULL, NULL, NULL, $2); _PARSE_DEBUG("step-> .."); } +abbreviatedstep : '.' predicates { $$=xp_new(XP_STEP,A_SELF, NULL,NULL, NULL, NULL, $2); _PARSE_DEBUG("step-> ."); } + | DOUBLEDOT predicates { $$=xp_new(XP_STEP, A_PARENT, NULL,NULL, NULL, NULL, $2); _PARSE_DEBUG("step-> .."); } ; /* [5] AxisSpecifier::= AxisName '::' @@ -481,7 +481,7 @@ abbreviatedstep : '.' predicates { $$=xp_new(XP_STEP,A_SELF, NULL,NULL, NULL */ axisspec : NCNAME DOUBLECOLON { if (($$=xp_axisname_function(_XPY, $1)) < 0) YYERROR; - free($1); + free($1); _PARSE_DEBUG2("axisspec-> AXISNAME(%s -> %d) ::", $1, $$); } | abbreviatedaxisspec @@ -509,22 +509,22 @@ nametest : ADDOP _PARSE_DEBUG("nametest-> *"); } | NCNAME { $$=xp_new(XP_NODE,A_NAN,NULL, NULL, $1, NULL, NULL); - _PARSE_DEBUG1("nametest-> name[%s]",$1); } + _PARSE_DEBUG1("nametest-> name[%s]",$1); } | NCNAME ':' NCNAME { $$=xp_new(XP_NODE,A_NAN,NULL, $1, $3, NULL, NULL); - _PARSE_DEBUG2("nametest-> name[%s] : name[%s]", $1, $3); } + _PARSE_DEBUG2("nametest-> name[%s] : name[%s]", $1, $3); } | NCNAME ':' '*' { $$=xp_new(XP_NODE,A_NAN,NULL, $1, NULL, NULL, NULL); - _PARSE_DEBUG1("nametest-> name[%s] : *", $1); } + _PARSE_DEBUG1("nametest-> name[%s] : *", $1); } ; /* evaluates to boolean */ -predicates : predicates '[' expr ']' { $$=xp_new(XP_PRED,A_NAN,NULL, NULL, NULL, $1, $3); _PARSE_DEBUG("predicates-> [ expr ]"); } - | { $$=xp_new(XP_PRED,A_NAN,NULL, NULL, NULL, NULL, NULL); _PARSE_DEBUG("predicates->"); } +predicates : predicates '[' expr ']' { $$=xp_new(XP_PRED,A_NAN,NULL, NULL, NULL, $1, $3); _PARSE_DEBUG("predicates-> [ expr ]"); } + | { $$=xp_new(XP_PRED,A_NAN,NULL, NULL, NULL, NULL, NULL); _PARSE_DEBUG("predicates->"); } ; -primaryexpr : '(' expr ')' { $$=xp_new(XP_PRI0,A_NAN,NULL, NULL, NULL, $2, NULL); _PARSE_DEBUG("primaryexpr-> ( expr )"); } +primaryexpr : '(' expr ')' { $$=xp_new(XP_PRI0,A_NAN,NULL, NULL, NULL, $2, NULL); _PARSE_DEBUG("primaryexpr-> ( expr )"); } | literal { $$ = $1; } - | NUMBER { $$=xp_new(XP_PRIME_NR,A_NAN, $1, NULL, NULL, NULL, NULL);_PARSE_DEBUG1("primaryexpr-> NUMBER(%s)", $1); /*XXX*/} + | NUMBER { $$=xp_new(XP_PRIME_NR,A_NAN, $1, NULL, NULL, NULL, NULL);_PARSE_DEBUG1("primaryexpr-> NUMBER(%s)", $1); /*XXX*/} | functioncall { $$ = $1; } ; @@ -539,13 +539,13 @@ literal : QUOTE string QUOTE _PARSE_DEBUG("literal-> \" string \""); } | QUOTE QUOTE { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, strdup(""), NULL, NULL, NULL); - _PARSE_DEBUG("primaryexpr-> \" \""); } + _PARSE_DEBUG("primaryexpr-> \" \""); } | APOST string APOST { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, $2, NULL, NULL, NULL); _PARSE_DEBUG("primaryexpr-> ' string '"); } | APOST APOST { $$=xp_new(XP_PRIME_STR,A_NAN,NULL, strdup(""), NULL, NULL, NULL); - _PARSE_DEBUG("primaryexpr-> ' '"); } + _PARSE_DEBUG("primaryexpr-> ' '"); } ; functioncall : NCNAME '(' ')' @@ -554,17 +554,17 @@ functioncall : NCNAME '(' ')' _PARSE_DEBUG("primaryexpr-> functionname ()"); } | NCNAME '(' args ')' { if (($$ = xp_primary_function(_XPY, $1, $3)) == NULL) YYERROR; - _PARSE_DEBUG("primaryexpr-> functionname (arguments)"); } + _PARSE_DEBUG("primaryexpr-> functionname (arguments)"); } ; -string : string CHARS { +string : string CHARS { int len = strlen($1); - $$ = realloc($1, len+strlen($2) + 1); - sprintf($$+len, "%s", $2); + $$ = realloc($1, len+strlen($2) + 1); + sprintf($$+len, "%s", $2); free($2); _PARSE_DEBUG("string-> string CHAR"); } - | CHARS { _PARSE_DEBUG("string-> "); } + | CHARS { _PARSE_DEBUG("string-> "); } ; diff --git a/lib/src/clixon_xpath_yang.c b/lib/src/clixon_xpath_yang.c index 28ac909e..9f6c7068 100644 --- a/lib/src/clixon_xpath_yang.c +++ b/lib/src/clixon_xpath_yang.c @@ -32,9 +32,9 @@ ***** END LICENSE BLOCK ***** - * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 + * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * Note: for YANG which is constrained to path-arg as defined in rfc7950 - * See: clixon_xpath.[ch] for full XML XPATH implementation + * See: clixon_xpath.[ch] for full XML XPath implementation */ #ifdef HAVE_CONFIG_H #include "clixon_config.h" /* generated by config & autoconf */ @@ -86,7 +86,7 @@ xp_yang_ctx * xy_dup(xp_yang_ctx *xy0) { xp_yang_ctx *xy = NULL; - + if ((xy = malloc(sizeof(*xy))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -115,7 +115,7 @@ xp_yang_op_eq(xp_yang_ctx *xy1, { int retval = -1; xp_yang_ctx *xy = NULL; - + if ((xy = xy_dup(xy1)) == NULL) goto done; if (xy1 == NULL || xy2 == NULL || xy1->xy_node == NULL || xy2->xy_node == NULL){ @@ -134,7 +134,7 @@ xp_yang_op_eq(xp_yang_ctx *xy1, /*! Evaluate leafref PATH-ARG step rule on a YANG tree * * @param[in] xy0 Incoming context - * @param[in] xpath_tree XPATH parse-tree + * @param[in] xpath_tree XPath parse-tree * @param[out] xyr Resulting context * @retval 0 OK * @retval -1 Error @@ -157,7 +157,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0, goto done; ys = xy->xy_node; switch (xptree->xs_int){ - case A_CHILD: + case A_CHILD: if ((nodetest = xptree->xs_c0) == NULL){ clicon_err(OE_YANG, 0, "child step nodetest expected"); goto done; @@ -221,7 +221,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0, /*! Evaluate leafref PATH-ARG predicate rule on a YANG tree * * @param[in] xy Incoming context - * @param[in] xpath_tree XPATH parse-tree + * @param[in] xpath_tree XPath parse-tree * @param[out] xyr Resulting context * @retval 0 OK * @retval -1 Error @@ -237,7 +237,7 @@ xp_yang_eval_predicate(xp_yang_ctx *xy, xp_yang_ctx *xy1 = NULL; if (xptree->xs_c0 != NULL){ /* eval previous predicates */ - if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0) + if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0) goto done; } else{ /* empty */ @@ -270,7 +270,7 @@ xp_yang_eval_predicate(xp_yang_ctx *xy, /*! Evaluate leafref PATH-ARG on a YANG tree * * @param[in] xy Incoming context - * @param[in] xpath_tree XPATH parse-tree + * @param[in] xpath_tree XPath parse-tree * @param[out] xyr Resulting context * @retval 0 OK * @retval -1 Error @@ -358,7 +358,7 @@ xp_yang_eval(xp_yang_ctx *xy, /* Eval first child c0 */ if (xptree->xs_c0){ - if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0) + if (xp_yang_eval(xy, xptree->xs_c0, &xy0) < 0) goto done; } /* Actions between first and second child @@ -379,7 +379,7 @@ xp_yang_eval(xp_yang_ctx *xy, * Note, some operators like locationpath, need transitive context (use_xr0) */ if (xptree->xs_c1){ - if (xp_yang_eval(use_xy0?xy0:xy, xptree->xs_c1, &xy1) < 0) + if (xp_yang_eval(use_xy0?xy0:xy, xptree->xs_c1, &xy1) < 0) goto done; /* Actions after second child */ @@ -447,7 +447,7 @@ xp_yang_eval(xp_yang_ctx *xy, * @param[out] yref YANG referred node * @retval 0 OK * @retval -1 Error - * @note this function uses XPATH parser, which is (much too) general + * @note this function uses XPath parser, which is (much too) general * @code * yang_stmt *ys; // source / referring node * yang_stmt *yref = NULL; // target / referred node @@ -470,7 +470,7 @@ yang_path_arg(yang_stmt *ys, xp_yang_ctx *xyr = NULL; xp_yang_ctx *xy = NULL; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (path_arg == NULL){ clicon_err(OE_XML, EINVAL, "path-arg is NULL"); goto done; diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 012ed40d..c8d78f38 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -98,76 +98,76 @@ static int yang_search_index_extension(clicon_handle h, yang_stmt *yext, yang_st * Here is also the place where doc on some types store variables (cv) */ static const map_str2int ykmap[] = { - {"action", Y_ACTION}, - {"anydata", Y_ANYDATA}, - {"anyxml", Y_ANYXML}, - {"argument", Y_ARGUMENT}, - {"augment", Y_AUGMENT}, - {"base", Y_BASE}, - {"belongs-to", Y_BELONGS_TO}, - {"bit", Y_BIT}, - {"case", Y_CASE}, - {"choice", Y_CHOICE}, + {"action", Y_ACTION}, + {"anydata", Y_ANYDATA}, + {"anyxml", Y_ANYXML}, + {"argument", Y_ARGUMENT}, + {"augment", Y_AUGMENT}, + {"base", Y_BASE}, + {"belongs-to", Y_BELONGS_TO}, + {"bit", Y_BIT}, + {"case", Y_CASE}, + {"choice", Y_CHOICE}, {"config", Y_CONFIG}, /* cv: boolean config flag */ - {"contact", Y_CONTACT}, - {"container", Y_CONTAINER}, - {"default", Y_DEFAULT}, - {"description", Y_DESCRIPTION}, - {"deviate", Y_DEVIATE}, - {"deviation", Y_DEVIATION}, - {"enum", Y_ENUM}, - {"error-app-tag", Y_ERROR_APP_TAG}, - {"error_message", Y_ERROR_MESSAGE}, - {"extension", Y_EXTENSION}, + {"contact", Y_CONTACT}, + {"container", Y_CONTAINER}, + {"default", Y_DEFAULT}, + {"description", Y_DESCRIPTION}, + {"deviate", Y_DEVIATE}, + {"deviation", Y_DEVIATION}, + {"enum", Y_ENUM}, + {"error-app-tag", Y_ERROR_APP_TAG}, + {"error_message", Y_ERROR_MESSAGE}, + {"extension", Y_EXTENSION}, {"feature", Y_FEATURE}, /* cv: feature as boolean */ {"fraction-digits", Y_FRACTION_DIGITS}, /* cv: fraction-digits as uint8 */ - {"grouping", Y_GROUPING}, - {"identity", Y_IDENTITY}, - {"if-feature", Y_IF_FEATURE}, - {"import", Y_IMPORT}, - {"include", Y_INCLUDE}, - {"input", Y_INPUT}, - {"key", Y_KEY}, + {"grouping", Y_GROUPING}, + {"identity", Y_IDENTITY}, + {"if-feature", Y_IF_FEATURE}, + {"import", Y_IMPORT}, + {"include", Y_INCLUDE}, + {"input", Y_INPUT}, + {"key", Y_KEY}, {"leaf", Y_LEAF}, /* cv: store default value (if any)*/ {"leaf-list", Y_LEAF_LIST}, /* cv: store default value (if any)*/ - {"length", Y_LENGTH}, - {"list", Y_LIST}, + {"length", Y_LENGTH}, + {"list", Y_LIST}, {"mandatory", Y_MANDATORY}, /* cv: store mandatory boolean */ - {"max-elements", Y_MAX_ELEMENTS}, - {"min-elements", Y_MIN_ELEMENTS}, - {"modifier", Y_MODIFIER}, - {"module", Y_MODULE}, - {"must", Y_MUST}, - {"namespace", Y_NAMESPACE}, - {"notification", Y_NOTIFICATION}, - {"ordered-by", Y_ORDERED_BY}, - {"organization", Y_ORGANIZATION}, - {"output", Y_OUTPUT}, - {"path", Y_PATH}, - {"pattern", Y_PATTERN}, - {"position", Y_POSITION}, - {"prefix", Y_PREFIX}, - {"presence", Y_PRESENCE}, - {"range", Y_RANGE}, - {"reference", Y_REFERENCE}, - {"refine", Y_REFINE}, - {"require-instance", Y_REQUIRE_INSTANCE}, + {"max-elements", Y_MAX_ELEMENTS}, + {"min-elements", Y_MIN_ELEMENTS}, + {"modifier", Y_MODIFIER}, + {"module", Y_MODULE}, + {"must", Y_MUST}, + {"namespace", Y_NAMESPACE}, + {"notification", Y_NOTIFICATION}, + {"ordered-by", Y_ORDERED_BY}, + {"organization", Y_ORGANIZATION}, + {"output", Y_OUTPUT}, + {"path", Y_PATH}, + {"pattern", Y_PATTERN}, + {"position", Y_POSITION}, + {"prefix", Y_PREFIX}, + {"presence", Y_PRESENCE}, + {"range", Y_RANGE}, + {"reference", Y_REFERENCE}, + {"refine", Y_REFINE}, + {"require-instance", Y_REQUIRE_INSTANCE}, {"revision", Y_REVISION}, /* cv: YYYY-MM-DD as uint32 */ {"revision-date", Y_REVISION_DATE}, /* cv: YYYY-MM-DD as uint32 */ - {"rpc", Y_RPC}, - {"status", Y_STATUS}, - {"submodule", Y_SUBMODULE}, - {"type", Y_TYPE}, - {"typedef", Y_TYPEDEF}, - {"unique", Y_UNIQUE}, + {"rpc", Y_RPC}, + {"status", Y_STATUS}, + {"submodule", Y_SUBMODULE}, + {"type", Y_TYPE}, + {"typedef", Y_TYPEDEF}, + {"unique", Y_UNIQUE}, {"units", Y_UNITS}, {"unknown", Y_UNKNOWN}, /* cv: store extra string */ - {"uses", Y_USES}, - {"value", Y_VALUE}, - {"when", Y_WHEN}, - {"yang-version", Y_YANG_VERSION}, - {"yin-element", Y_YIN_ELEMENT}, - {"yang-specification", Y_SPEC}, /* XXX: NOTE NOT YANG STATEMENT, reserved + {"uses", Y_USES}, + {"value", Y_VALUE}, + {"when", Y_WHEN}, + {"yang-version", Y_YANG_VERSION}, + {"yin-element", Y_YIN_ELEMENT}, + {"yang-specification", Y_SPEC}, /* XXX: NOTE NOT YANG STATEMENT, reserved for top level spec */ {NULL, -1} }; @@ -326,7 +326,7 @@ yang_cvec_add(yang_stmt *ys, cvec *cvv; if ((cvv = yang_cvec_get(ys)) == NULL){ - if ((cvv = cvec_new(0)) == NULL){ + if ((cvv = cvec_new(0)) == NULL){ clicon_err(OE_YANG, errno, "cvec_new"); return NULL; } @@ -350,7 +350,7 @@ yang_cvec_add(yang_stmt *ys, * @retval value Flags value masked by "flag" parameter, see YANG_FLAG_* */ uint16_t -yang_flag_get(yang_stmt *ys, +yang_flag_get(yang_stmt *ys, uint16_t flag) { return ys->ys_flags&flag; @@ -362,7 +362,7 @@ yang_flag_get(yang_stmt *ys, * @param[in] flag Flag value(s) to set, see YANG_FLAG_* */ int -yang_flag_set(yang_stmt *ys, +yang_flag_set(yang_stmt *ys, uint16_t flag) { ys->ys_flags |= flag; @@ -375,7 +375,7 @@ yang_flag_set(yang_stmt *ys, * @param[in] flag Flag value(s) to reset, see YANG_FLAG_* */ int -yang_flag_reset(yang_stmt *ys, +yang_flag_reset(yang_stmt *ys, uint16_t flag) { ys->ys_flags &= ~flag; @@ -408,7 +408,7 @@ yang_when_xpath_get(yang_stmt *ys) * @retval -1 Error */ int -yang_when_xpath_set(yang_stmt *ys, +yang_when_xpath_set(yang_stmt *ys, char *xpath) { int retval = -1; @@ -420,7 +420,6 @@ yang_when_xpath_set(yang_stmt *ys, if ((ys->ys_when_xpath = strdup(xpath)) == NULL){ clicon_err(OE_YANG, errno, "strdup"); goto done; - } retval = 0; done: @@ -451,7 +450,7 @@ yang_when_nsc_get(yang_stmt *ys) * @retval -1 Error */ int -yang_when_nsc_set(yang_stmt *ys, +yang_when_nsc_set(yang_stmt *ys, cvec *nsc) { int retval = -1; @@ -480,7 +479,7 @@ yang_filename_get(yang_stmt *ys) /*! Set yang filename for error/debug purpose * * @param[in] ys Yang statement - * @param[in] filename + * @param[in] filename * @retval 0 OK * @retval -1 Error * @note there maye not always be a "filename" in case the yang is read from memory @@ -537,7 +536,7 @@ yang_stats_global(uint64_t *nr) return 0; } -/*! Return the alloced memory of a single YANG obj +/*! Return the alloced memory of a single YANG obj * * @param[in] y YANG object * @param[out] szp Size of this YANG obj @@ -550,7 +549,7 @@ yang_stats_one(yang_stmt *y, { size_t sz = 0; yang_type_cache *yc; - + sz += sizeof(struct yang_stmt); sz += y->ys_len*sizeof(struct yang_stmt*); if (y->ys_argument) @@ -620,7 +619,7 @@ yang_stats(yang_stmt *yt, /*! Create new yang specification * - * @retval yspec Free with ys_free() + * @retval yspec Free with ys_free() * @retval NULL Error */ yang_stmt * @@ -666,7 +665,7 @@ ys_new(enum rfc_6020 keyw) * @retval -1 Error * @see ys_free */ -int +int ys_free1(yang_stmt *ys, int self) { @@ -735,7 +734,7 @@ ys_prune(yang_stmt *yp, { size_t size; yang_stmt *yc = NULL; - + if (i >= yp->ys_len) goto done; yc = yp->ys_stmt[i]; @@ -794,9 +793,9 @@ ys_prune_self(yang_stmt *ys) static int ys_freechildren(yang_stmt *ys) { - int i; yang_stmt *yc; - + int i; + for (i=0; iys_len; i++){ if ((yc = ys->ys_stmt[i]) != NULL) ys_free(yc); @@ -815,7 +814,7 @@ ys_freechildren(yang_stmt *ys) * @note does not remove yang node from tree * @see ys_prune Remove from parent */ -int +int ys_free(yang_stmt *ys) { ys_freechildren(ys); @@ -825,7 +824,7 @@ ys_free(yang_stmt *ys) /*! Allocate larger yang statement vector adding empty field last */ -static int +static int yn_realloc(yang_stmt *yn) { yn->ys_len++; @@ -851,8 +850,8 @@ yn_realloc(yang_stmt *yn) * @endcode * @see ys_replace */ -int -ys_cp(yang_stmt *ynew, +int +ys_cp(yang_stmt *ynew, yang_stmt *yold) { int retval = -1; @@ -862,7 +861,7 @@ ys_cp(yang_stmt *ynew, cg_var *cvn; cg_var *cvo; - memcpy(ynew, yold, sizeof(*yold)); + memcpy(ynew, yold, sizeof(*yold)); ynew->ys_parent = NULL; if (yold->ys_stmt) if ((ynew->ys_stmt = calloc(yold->ys_len, sizeof(yang_stmt *))) == NULL){ @@ -968,7 +967,7 @@ ys_replace(yang_stmt *yorig, yp = yang_parent_get(yorig); /* Remove old yangs all children */ yc = NULL; - while ((yc = yn_each(yorig, yc)) != NULL) + while ((yc = yn_each(yorig, yc)) != NULL) ys_free(yc); if (yorig->ys_stmt){ free(yorig->ys_stmt); @@ -984,7 +983,7 @@ ys_replace(yang_stmt *yorig, return retval; } -/*! Append yang statement as child of a parent yang_statement, last in list +/*! Append yang statement as child of a parent yang_statement, last in list * * @param[in] ys_parent Add child to this parent * @param[in] ys_child Add this child @@ -994,7 +993,7 @@ ys_replace(yang_stmt *yorig, * @see ys_prune */ int -yn_insert(yang_stmt *ys_parent, +yn_insert(yang_stmt *ys_parent, yang_stmt *ys_child) { int pos = ys_parent->ys_len; @@ -1009,7 +1008,7 @@ yn_insert(yang_stmt *ys_parent, /*! Variant of yn_insert where parent is not set */ int -yn_insert1(yang_stmt *ys_parent, +yn_insert1(yang_stmt *ys_parent, yang_stmt *ys_child) { int pos = ys_parent->ys_len; @@ -1034,7 +1033,7 @@ yn_insert1(yang_stmt *ys_parent, * @note also does not work in recursive calls (to same node) */ yang_stmt * -yn_each(yang_stmt *yparent, +yn_each(yang_stmt *yparent, yang_stmt *yprev) { int i; @@ -1068,8 +1067,8 @@ yn_each(yang_stmt *yparent, * @see yang_match returns number of matches */ yang_stmt * -yang_find(yang_stmt *yn, - int keyword, +yang_find(yang_stmt *yn, + int keyword, const char *argument) { yang_stmt *ys = NULL; @@ -1119,8 +1118,8 @@ yang_find(yang_stmt *yn, * @see yang_find */ int -yang_match(yang_stmt *yn, - int keyword, +yang_match(yang_stmt *yn, + int keyword, char *argument) { yang_stmt *ys = NULL; @@ -1153,7 +1152,7 @@ yang_match(yang_stmt *yn, * XXX: differentiate between not found and error */ yang_stmt * -yang_find_datanode(yang_stmt *yn, +yang_find_datanode(yang_stmt *yn, char *argument) { yang_stmt *ys = NULL; @@ -1222,7 +1221,7 @@ yang_find_datanode(yang_stmt *yn, * @see yang_abs_schema_nodeid Top level function */ yang_stmt * -yang_find_schemanode(yang_stmt *yn, +yang_find_schemanode(yang_stmt *yn, char *argument) { yang_stmt *ys = NULL; @@ -1234,7 +1233,7 @@ yang_find_schemanode(yang_stmt *yn, for (i=0; iys_len; i++){ ys = yn->ys_stmt[i]; - if (yang_keyword_get(ys) == Y_CHOICE){ + if (yang_keyword_get(ys) == Y_CHOICE){ /* First check choice itself */ if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0){ ysmatch = ys; @@ -1386,9 +1385,9 @@ yang_find_prefix_by_namespace(yang_stmt *ys, yang_stmt *ymod; char *modname = NULL; yang_stmt *yimport; - yang_stmt *yprefix; + yang_stmt *yprefix; - clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (prefix == NULL){ clicon_err(OE_YANG, EINVAL, "prefix is NULL"); goto done; @@ -1448,7 +1447,7 @@ yang_find_namespace_by_prefix(yang_stmt *ys, char *prefix, char **ns) { - int retval = -1; + int retval = -1; yang_stmt *ym; if (ns == NULL){ @@ -1488,7 +1487,7 @@ yang_myroot(yang_stmt *ys) if (kw == Y_MODULE || kw == Y_SUBMODULE) return ys; ys = yp; - } + } return NULL; } @@ -1518,7 +1517,7 @@ choice_case_get(yang_stmt *yc, return 0; } -/*! If a given yang stmt has a choice/case as parent, return the choice statement +/*! If a given yang stmt has a choice/case as parent, return the choice statement */ yang_stmt * yang_choice(yang_stmt *y) @@ -1589,7 +1588,7 @@ yang_order1_choice(yang_stmt *yp, } else { max = 1; /* Shortcut, no case */ - if (yang_datanode(ys) && ys == y) + if (yang_datanode(ys) && ys == y) return 1; } } @@ -1613,7 +1612,7 @@ yang_order1(yang_stmt *yp, int retval = -1; yang_stmt *ys; int i; - + for (i=0; iys_len; i++){ ys = yp->ys_stmt[i]; if (ys->ys_keyword == Y_CHOICE){ @@ -1626,11 +1625,11 @@ yang_order1(yang_stmt *yp, continue; if (ys == y) break; - (*index)++; + (*index)++; } } if (i < yp->ys_len) /* break -> found */ - retval = 0; + retval = 0; else assert(0); // XXX return retval; @@ -1657,12 +1656,12 @@ yang_order(yang_stmt *y) int tot = 0; if (y == NULL){ - retval = -1; + retval = -1; goto done; } /* Some special handling if yp is choice (or case) * if so, the real parent (from an xml point of view) is the parents - * parent. + * parent. */ yp = yang_parent_get(y); while (yang_keyword_get(yp) == Y_CASE || yang_keyword_get(yp) == Y_CHOICE) @@ -1861,7 +1860,7 @@ ys_spec(yang_stmt *ys) return (yang_stmt*)ys; } -/*! String is quoted if it contains space or tab, needs double '' +/*! String is quoted if it contains space or tab, needs double '' */ static int inline quotedstring(char *s) @@ -1885,7 +1884,7 @@ quotedstring(char *s) * @see yang_print_cbuf */ int -yang_print_cb(FILE *f, +yang_print_cb(FILE *f, yang_stmt *yn, clicon_output_cb *fn) { @@ -1913,7 +1912,7 @@ yang_print_cb(FILE *f, * @see yang_print_cbuf */ int -yang_print(FILE *f, +yang_print(FILE *f, yang_stmt *yn) { return yang_print_cb(f, yn, fprintf); @@ -1926,12 +1925,12 @@ yang_print(FILE *f, * @see yang_print_cbuf */ int -yang_spec_print(FILE *f, +yang_spec_print(FILE *f, yang_stmt *yspec) { yang_stmt *ym = NULL; yang_stmt *yrev; - + if (yspec == NULL || yang_keyword_get(yspec) != Y_SPEC){ clicon_err(OE_YANG, EINVAL, "yspec is not of type YSPEC"); return -1; @@ -1972,7 +1971,7 @@ yang_spec_dump(yang_stmt *yspec, cprintf(cb, "@%u", cv_uint32_get(yang_cv_get(yrev))); } cprintf(cb, ".yang"); - clicon_debug(dbglevel, "%s", cbuf_get(cb)); + clixon_debug(dbglevel, "%s", cbuf_get(cb)); cbuf_reset(cb); } retval = 0; @@ -2059,7 +2058,9 @@ yang_print_cbuf(cbuf *cb, * Identify deviation target node, and go through all its deviate statements. * Features/if-feature must have run before * @param[in] ys The yang deviation to populate. - * @param[in] h Clicon handle + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error * @see RFC 7950 5.6.3 and 7.20.3 */ int @@ -2068,7 +2069,7 @@ yang_deviation(yang_stmt *ys, { int retval = -1; - char *nodeid; + char *nodeid; yang_stmt *ytarget = NULL; yang_stmt *yd; yang_stmt *yc; @@ -2090,16 +2091,16 @@ yang_deviation(yang_stmt *ys, /* 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); + if (ytarget == NULL){ + clicon_log(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); - goto done; + clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid); + goto done; */ } /* Go through deviates of deviation */ - yd = NULL; + yd = NULL; while ((yd = yn_each(ys, yd)) != NULL) { /* description / if-feature / reference */ if (yang_keyword_get(yd) != Y_DEVIATE) @@ -2113,7 +2114,7 @@ yang_deviation(yang_stmt *ys, goto ok; /* Target node removed, no other deviates possible */ } else if (strcmp(devop, "add") == 0){ - yc = NULL; + yc = NULL; while ((yc = yn_each(yd, yc)) != NULL) { /* If a property can only appear once, the property MUST NOT exist in the target node. */ kw = yang_keyword_get(yc); @@ -2175,7 +2176,7 @@ yang_deviation(yang_stmt *ys, else if (strcmp(devop, "delete") == 0){ yc = NULL; while ((yc = yn_each(yd, yc)) != NULL) { - /* The substatement's keyword MUST match a corresponding keyword in the target node, and the + /* The substatement's keyword MUST match a corresponding keyword in the target node, and the * argument's string MUST be equal to the corresponding keyword's argument string in the * target node. */ kw = yang_keyword_get(yc); @@ -2212,7 +2213,7 @@ yang_deviation(yang_stmt *ys, * 4. Check if leaf is part of list, if key exists mark leaf as key/unique * XXX: extend type search * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement to populate. * @retval 0 OK * @retval -1 Error with clicon_err called @@ -2223,8 +2224,8 @@ ys_populate_leaf(clicon_handle h, { int retval = -1; cg_var *cv = NULL; - yang_stmt *yparent; - yang_stmt *ydef; + yang_stmt *yparent; + yang_stmt *ydef; enum cv_type cvtype = CGV_ERR; int cvret; int ret; @@ -2245,14 +2246,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"); + clicon_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"); + clicon_err(OE_YANG, errno, "cv_name_set"); goto done; } /* get parent of where type is defined, can be original object */ @@ -2307,8 +2308,10 @@ ys_populate_leaf(clicon_handle h, /*! Populate list yang statement * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (type) to populate. + * @retval 0 OK + * @retval -1 Error */ static int ys_populate_list(clicon_handle h, @@ -2316,7 +2319,7 @@ ys_populate_list(clicon_handle h, { yang_stmt *ykey; cvec *cvv; - + if ((ykey = yang_find(ys, Y_KEY, NULL)) == NULL) return 0; @@ -2329,6 +2332,8 @@ ys_populate_list(clicon_handle h, /*! Set range or length boundary for built-in yang types * * Help functions to range and length statements + * @retval 0 OK + * @retval -1 Error */ static int bound_add(yang_stmt *ys, @@ -2369,6 +2374,9 @@ bound_add(yang_stmt *ys, } /*! Common range length parsing of "x .. y | z..w " statements + * + * @retval 0 OK + * @retval -1 Error */ static int range_parse(yang_stmt *ys, @@ -2408,8 +2416,10 @@ range_parse(yang_stmt *ys, /*! Populate string built-in range statement * * Create cvec variables "range_min" and "range_max". Assume parent is type. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (range) to populate. + * @retval 0 OK + * @retval -1 Error * Actually: bound[..bound] (| bound[..bound])* * where bound is integer, decimal or keywords 'min' or 'max. * RFC 7950 9.2.4: @@ -2434,10 +2444,10 @@ 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"); + clicon_err(OE_YANG, 0, "parent should be type"); goto done; } - if (yang_type_resolve(ys, ys, (yang_stmt*)yparent, &yrestype, + if (yang_type_resolve(ys, ys, (yang_stmt*)yparent, &yrestype, &options, NULL, NULL, NULL, &fraction_digits) < 0) goto done; if (yrestype == NULL){ @@ -2448,10 +2458,10 @@ ys_populate_range(clicon_handle h, if (nodeid_split(yang_argument_get(yparent), NULL, &origtype) < 0) goto done; /* This handles non-resolved also */ - if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0) + 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); + clicon_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) @@ -2466,8 +2476,10 @@ ys_populate_range(clicon_handle h, /*! Populate integer built-in length statement * * Create cvec variables "range_min" and "range_max". Assume parent is type. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (length) to populate. + * @retval 0 OK + * @retval -1 Error * * Actually: len[..len] (| len[..len])* * len is unsigned integer or keywords 'min' or 'max' @@ -2489,7 +2501,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"); + clicon_err(OE_YANG, 0, "parent should be type"); goto done; } cvtype = CGV_UINT64; @@ -2503,8 +2515,10 @@ ys_populate_length(clicon_handle h, /*! Sanity check yang type statement * * XXX: Replace with generic parent/child type-check - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (type) to populate. + * @retval 0 OK + * @retval -1 Error */ static int ys_populate_type(clicon_handle h, @@ -2543,14 +2557,16 @@ ys_populate_type(clicon_handle h, * Do this recursively * The derived identity list is a list of : pairs. Prefixes cannot * be used since they are local in scope. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang identity to populate. * @param[in] idref If set contains the derived identifier(NULL on top call) + * @retval 0 OK + * @retval -1 Error * @see validate_identityref which in runtime validates actual values */ static int ys_populate_identity(clicon_handle h, - yang_stmt *ys, + yang_stmt *ys, char *idref) { int retval = -1; @@ -2563,19 +2579,19 @@ ys_populate_identity(clicon_handle h, yang_stmt *ymod; cvec *idrefvec; /* Derived identityref list: (module:id)**/ - /* Top-call (no recursion) create idref + /* Top-call (no recursion) create idref * The idref is (here) in "canonical form": : */ 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"); + clicon_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"); + clicon_err(OE_YANG, ENOENT, "No module found"); goto done; } cprintf(cb, "%s:%s", yang_argument_get(ymod), id); @@ -2590,7 +2606,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); + clicon_err(OE_YANG, ENOENT, "No such identity: %s", baseid); goto done; } // continue; /* root identity */ @@ -2602,7 +2618,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"); + clicon_err(OE_UNIX, errno, "cv_new"); goto done; } /* Transitive to the root */ @@ -2649,8 +2665,10 @@ if_feature(yang_stmt *yspec, /*! Populate yang feature statement - set cv to 1 if enabled * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys Feature yang statement to populate. + * @retval 0 OK + * @retval -1 Error * Bootstrapping: A feature is enabled if found in clixon-config */ int @@ -2674,7 +2692,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"); + clicon_err(OE_YANG, 0, "module not found"); goto done; } module = ymod->ys_argument; @@ -2699,13 +2717,13 @@ ys_populate_feature(clicon_handle h, if (f) free(f); } if ((cv = cv_new(CGV_BOOL)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clicon_err(OE_YANG, errno, "cv_new"); goto done; } cv_name_set(cv, feature); cv_bool_set(cv, found); if (found) - clicon_debug(1, "%s %s:%s", __FUNCTION__, module, feature); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s:%s", __FUNCTION__, module, feature); yang_cv_set(ys, cv); ok: retval = 0; @@ -2715,8 +2733,10 @@ ys_populate_feature(clicon_handle h, /*! Populate the unique statement with a cvec * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (unique) to populate. + * @retval 0 OK + * @retval -1 Error */ static int ys_populate_unique(clicon_handle h, @@ -2732,7 +2752,7 @@ ys_populate_unique(clicon_handle h, /*! Populate unknown node with extension * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (unknown) to populate. * @retval 0 OK * @retval -1 Error @@ -2785,14 +2805,14 @@ 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); + clicon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument); goto done; } } #ifdef XML_EXPLICIT_INDEX /* Add explicit index extension */ if ((retval = yang_search_index_extension(h, yext, ys)) < 0) { - clicon_debug(1, "plugin_extension() failed"); + clixon_debug(CLIXON_DBG_DEFAULT, "plugin_extension() failed"); return -1; } #endif @@ -2821,8 +2841,10 @@ ys_populate_unknown(clicon_handle h, * * Check RFC 7950: 7.1.4: All prefixes, including the prefix for the module itself, * MUST be unique within the module or submodule. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] ys The yang statement (module/submodule) to populate. + * @retval 0 OK + * @retval -1 Error */ static int ys_populate_module_submodule(clicon_handle h, @@ -2872,7 +2894,9 @@ ys_populate_module_submodule(clicon_handle h, /*! Populate with cligen-variables, default values, etc. Sanity checks on complete tree. * * @param[in] ys Yang statement - * @param[in] arg Argument - in effect Clicon handle + * @param[in] arg Argument - in effect Clixon handle + * @retval 0 OK + * @retval -1 Error * Preferably run this command using yang_apply * Done in 2nd pass after complete parsing to be sure to have a complete * parse-tree @@ -2883,18 +2907,18 @@ ys_populate_module_submodule(clicon_handle h, * (there may be more functions (all?) that may be moved to ys_populate2) */ int -ys_populate(yang_stmt *ys, +ys_populate(yang_stmt *ys, void *arg) { int retval = -1; clicon_handle h = (clicon_handle)arg; - + switch(ys->ys_keyword){ case Y_IDENTITY: if (ys_populate_identity(h, ys, NULL) < 0) goto done; break; - case Y_LENGTH: + case Y_LENGTH: if (ys_populate_length(h, ys) < 0) goto done; break; @@ -2907,7 +2931,7 @@ ys_populate(yang_stmt *ys, if (ys_populate_module_submodule(h, ys) < 0) goto done; break; - case Y_RANGE: + case Y_RANGE: if (ys_populate_range(h, ys) < 0) goto done; break; @@ -2931,17 +2955,17 @@ ys_populate(yang_stmt *ys, return retval; } -/*! Run after grouping expand and augment +/*! Run after grouping expand and augment * * @see ys_populate run before grouping expand and augment */ int -ys_populate2(yang_stmt *ys, +ys_populate2(yang_stmt *ys, void *arg) { int retval = -1; clicon_handle h = (clicon_handle)arg; - + switch(ys->ys_keyword){ case Y_LEAF: case Y_LEAF_LIST: @@ -2951,7 +2975,7 @@ ys_populate2(yang_stmt *ys, case Y_MANDATORY: /* call yang_mandatory() to check if set */ case Y_CONFIG: case Y_REQUIRE_INSTANCE: - if (ys_parse(ys, CGV_BOOL) == NULL) + if (ys_parse(ys, CGV_BOOL) == NULL) goto done; break; default: @@ -2995,7 +3019,7 @@ yang_features(clicon_handle h, ret = 0; if (yang_subparse(yang_argument_get(ys), ys, YA_IF_FEATURE, mainfile, 1, &ret, h) < 0) goto done; - clicon_debug(CLIXON_DBG_DETAIL, "%s %s %d", __FUNCTION__, yang_argument_get(ys), ret); + clixon_debug(CLIXON_DBG_DETAIL, "%s %s %d", __FUNCTION__, yang_argument_get(ys), ret); if (ret == 0) goto disabled; } @@ -3033,7 +3057,7 @@ yang_features(clicon_handle h, retval = 1; done: return retval; - disabled: + disabled: retval = 0; /* feature not enabled */ goto done; } @@ -3063,9 +3087,9 @@ yang_features(clicon_handle h, * @note do not delete or move around any children during this function */ int -yang_apply(yang_stmt *yn, +yang_apply(yang_stmt *yn, enum rfc_6020 keyword, - yang_applyfn_t fn, + yang_applyfn_t fn, int depth, void *arg) { @@ -3096,7 +3120,7 @@ yang_apply(yang_stmt *yn, retval = 0; done: return retval; -} +} /*! Check if a node is a yang "data node" * @@ -3150,7 +3174,7 @@ schema_nodeid_iterate(yang_stmt *yn, int retval = -1; yang_stmt *ymod; char *prefix; /* node-identifier = [prefix ":"] identifier */ - char *id; + char *id; yang_stmt *ys; yang_stmt *yp; cg_var *cv; @@ -3158,11 +3182,11 @@ schema_nodeid_iterate(yang_stmt *yn, yp = yn; /* Iterate over node identifiers /prefix:id/... */ - cv = NULL; + cv = NULL; while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){ prefix = cv_name_get(cv); id = cv_string_get(cv); - /* Top level is repeated from abs case, but here this is done to match with + /* Top level is repeated from abs case, but here this is done to match with * matching module below * Get namespace */ if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){ @@ -3193,7 +3217,7 @@ schema_nodeid_iterate(yang_stmt *yn, goto done; } if (ys == NULL){ - clicon_debug(1, "%s: %s not found, last id found:%s", + clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s not found, last id found:%s", __FUNCTION__, id, yang_argument_get(yp)); goto ok; } @@ -3255,7 +3279,7 @@ yang_abs_schema_nodeid(yang_stmt *yn, if (cvec_len(nodeid_cvv) == 0) goto ok; /* If p0 is NULL an entry will be: [i0] which needs to be transformed to [NULL:i0] */ - cv = NULL; + cv = NULL; while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){ if (cv_type_get(cv) != CGV_STRING) cv_type_set(cv, CGV_STRING); @@ -3315,7 +3339,7 @@ yang_abs_schema_nodeid(yang_stmt *yn, * @see yang_abs_schema_nodeid */ int -yang_desc_schema_nodeid(yang_stmt *yn, +yang_desc_schema_nodeid(yang_stmt *yn, char *schema_nodeid, yang_stmt **yres) { @@ -3325,7 +3349,7 @@ yang_desc_schema_nodeid(yang_stmt *yn, char *str; yang_stmt *yspec; cvec *nsc = NULL; - + if (schema_nodeid == NULL || strlen(schema_nodeid) == 0){ clicon_err(OE_YANG, EINVAL, "nodeid is empty"); goto done; @@ -3347,7 +3371,7 @@ yang_desc_schema_nodeid(yang_stmt *yn, if (cvec_len(nodeid_cvv) == 0) goto ok; /* If p0 is NULL an entry will be: [i0] which needs to be transformed to [NULL:i0] */ - cv = NULL; + cv = NULL; while ((cv = cvec_each(nodeid_cvv, cv)) != NULL){ if (cv_type_get(cv) != CGV_STRING) cv_type_set(cv, CGV_STRING); @@ -3391,7 +3415,7 @@ yang_config(yang_stmt *ys) if ((ym = yang_find(ys, Y_CONFIG, NULL)) != NULL){ if (yang_cv_get(ym) == NULL) /* shouldnt happen */ - return 1; + return 1; return cv_bool_get(yang_cv_get(ym)); } return 1; @@ -3408,7 +3432,7 @@ int yang_config_ancestor(yang_stmt *ys) { yang_stmt *yp; - + yp = ys; do { #ifdef USE_CONFIG_FLAG_CACHE @@ -3455,7 +3479,7 @@ yang_config_ancestor(yang_stmt *ys) * @note must free return value after use w cvec_free */ cvec * -yang_arg2cvec(yang_stmt *ys, +yang_arg2cvec(yang_stmt *ys, char *delim) { char **vec = NULL; @@ -3467,14 +3491,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"); + clicon_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"); + clicon_err(OE_YANG, errno, "cv_string_set"); cvv = NULL; goto done; } @@ -3489,15 +3513,15 @@ yang_arg2cvec(yang_stmt *ys, /*! Check if yang node yn has key-stmt as child which matches name * * The function looks at the LIST argument string (not actual children) - * @param[in] yn Yang list node with sub-statements (look for a key child) - * @param[in] name Check if this name (eg "b") is a key in the yang key statement + * @param[in] yn Yang list node with sub-statements (look for a key child) + * @param[in] name Check if this name (eg "b") is a key in the yang key statement * @param[out] lastkey If 1 this is the last key in a multi-key list - * @retval 1 Yes match - * @retval 0 No match - * @retval -1 Error + * @retval 1 Yes match + * @retval 0 No match + * @retval -1 Error */ int -yang_key_match(yang_stmt *yn, +yang_key_match(yang_stmt *yn, char *name, int *lastkey) { @@ -3529,7 +3553,7 @@ yang_key_match(yang_stmt *yn, } } retval = 0; - done: + done: if (cvv) cvec_free(cvv); return retval; @@ -3538,13 +3562,15 @@ yang_key_match(yang_stmt *yn, /*! Set type cache for yang type * * @param[in] rxmode Kludge to know which regexp engine is used + * @retval 0 OK + * @retval -1 Error * @see yang_type_cache_regexp_set where cache is extended w compiled regexps */ int yang_type_cache_set(yang_stmt *ys, yang_stmt *resolved, - int options, - cvec *cvv, + int options, + cvec *cvv, cvec *patterns, uint8_t fraction) { @@ -3583,6 +3609,8 @@ yang_type_cache_set(yang_stmt *ys, * * Compiled Regexps are computed in validate code - after initial cache set * @param[in] regexps + * @retval 0 OK + * @retval -1 Error */ int yang_type_cache_regexp_set(yang_stmt *ytype, @@ -3616,8 +3644,8 @@ yang_type_cache_regexp_set(yang_stmt *ytype, int yang_type_cache_get(yang_stmt *ytype, yang_stmt **resolved, - int *options, - cvec **cvv, + int *options, + cvec **cvv, cvec *patterns, int *rxmode, cvec *regexps, @@ -3698,7 +3726,7 @@ yang_type_cache_free(yang_type_cache *ycache) { cg_var *cv; void *p; - + if (ycache->yc_cvv) cvec_free(ycache->yc_cvv); if (ycache->yc_patterns) @@ -3851,7 +3879,7 @@ yang_sort_subelements_fn(const void* arg1, yang_stmt *ys2 = *(yang_stmt **)arg2; int w1; /* ys1 has when substatement */ int w2; - + w1 = yang_find(ys1, Y_WHEN, NULL) != NULL; w2 = yang_find(ys2, Y_WHEN, NULL) != NULL; if (w1 == w2) @@ -3908,7 +3936,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"); + clicon_log(LOG_WARNING, "search_index should in a list"); goto ok; } yang_flag_set(ys, YANG_FLAG_INDEX); @@ -3927,7 +3955,7 @@ yang_list_index_add(yang_stmt *ys) * @retval -1 Error */ int -yang_search_index_extension(clicon_handle h, +yang_search_index_extension(clicon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -3936,13 +3964,13 @@ yang_search_index_extension(clicon_handle h, char *modname; yang_stmt *ymod; yang_stmt *yp; - + ymod = ys_module(yext); modname = yang_argument_get(ymod); extname = yang_argument_get(yext); if (strcmp(modname, "clixon-config") != 0 || strcmp(extname, "search_index") != 0) goto ok; - clicon_debug(1, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Enabled extension:%s:%s", __FUNCTION__, modname, extname); yp = yang_parent_get(ys); if (yang_list_index_add(yp) < 0) goto done; @@ -4026,7 +4054,7 @@ yang_action_cb_add(yang_stmt *ys, if (rc == NULL){ clicon_err(OE_YANG, EINVAL, "arg is NULL"); return -1; - } + } ADDQ(rc, ys->ys_action_cb); return 0; } diff --git a/lib/src/clixon_yang_cardinality.c b/lib/src/clixon_yang_cardinality.c index a37f7600..bacfb89e 100644 --- a/lib/src/clixon_yang_cardinality.c +++ b/lib/src/clixon_yang_cardinality.c @@ -459,7 +459,8 @@ static const struct ycard _yclist[] = { /* Search matrix for lookups */ static const struct ycard *_yc_search[Y_SPEC][Y_SPEC] = {{0,},{0,}}; -/* Set to 1 if exists in search +/*! Set to 1 if exists in search + * * Some yang statements are not explicitly given cardinalities in RFC7950, although they are * present in Section 14 BNF. * But since the table above is from the explicit cardinalities in the RFC the others are skipped @@ -469,9 +470,12 @@ static const struct ycard *_yc_search[Y_SPEC][Y_SPEC] = {{0,},{0,}}; static int _yc_exist[Y_SPEC] = {0,}; /*! Check cardinality, ie if each yang node has the expected nr of children - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] yt Yang statement * @param[in] modname Name of module (for debug message) + * @retval 0 OK + * @retval -1 Error * 1) For all children, if neither in 0..n, 0..1, 1 or 1..n ->ERROR * 2) For all in 1 and 1..n list, if 0 such children ->ERROR * 3) For all in 0..1 and 1 list, if >1 such children ->ERROR @@ -492,7 +496,7 @@ yang_cardinality(clicon_handle h, int order; yang_stmt *yprev = NULL; int nr; - + pk = yang_keyword_get(yt); if (_yc_exist[pk] == 0) goto ok; @@ -524,7 +528,7 @@ yang_cardinality(clicon_handle h, yang_argument_get(yt), yang_key2str(yang_keyword_get(yprev)), yang_argument_get(yprev)); - goto done; + goto done; } if (order < yc->yc_order) order = yc->yc_order; @@ -567,11 +571,13 @@ yang_cardinality(clicon_handle h, /*! Return cardinality interval [min,max] given yang parent and child keyword. * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] parent_key * @param[in] child_key * @param[out] minp 0 or 1 * @param[out] maxp 1 or NMAX (large number) + * @retval 0 OK + * @retval -1 Error */ int yang_cardinality_interval(clicon_handle h, @@ -582,7 +588,7 @@ yang_cardinality_interval(clicon_handle h, { int retval = -1; 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", parent_key, child_key); @@ -595,16 +601,18 @@ yang_cardinality_interval(clicon_handle h, return retval; } -/*! Init */ +/*! Init + * + * @param[in] h Clixon handle + */ int yang_cardinality_init(clicon_handle h) { const struct ycard *yc; - + for (yc = &_yclist[0]; (int)yc->yc_parent; yc++){ _yc_exist[yc->yc_parent] = 1; _yc_search[yc->yc_parent][yc->yc_child] = yc; } return 0; } - diff --git a/lib/src/clixon_yang_internal.h b/lib/src/clixon_yang_internal.h index a92328fc..8720f95d 100644 --- a/lib/src/clixon_yang_internal.h +++ b/lib/src/clixon_yang_internal.h @@ -42,6 +42,7 @@ #define _CLIXON_YANG_INTERNAL_H_ /*! Yang type cache. Yang type statements can cache all typedef info here + * * @note unions not cached */ struct yang_type_cache{ @@ -60,6 +61,7 @@ struct yang_type_cache{ typedef struct yang_type_cache yang_type_cache; /*! yang statement + * * This is an internal type, not exposed in the API * The external type is "yang_stmt" defined in clixon_yang.h */ @@ -69,7 +71,7 @@ struct yang_stmt{ struct yang_stmt *ys_parent; /* Backpointer to parent: yang-stmt or yang-spec */ enum rfc_6020 ys_keyword; /* */ - char *ys_argument; /* String / argument depending on keyword */ + char *ys_argument; /* String / argument depending on keyword */ uint16_t ys_flags; /* Flags according to YANG_FLAG_MARK and others */ yang_stmt *ys_mymodule; /* Shortcut to "my" module. Used by: 1) Augmented nodes "belong" to the module where the diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c index 57410b22..884a6ad3 100644 --- a/lib/src/clixon_yang_module.c +++ b/lib/src/clixon_yang_module.c @@ -83,6 +83,7 @@ #include "clixon_yang_parse_lib.h" /*! Force add ietf-yang-library@2019-01-04 on all mount-points + * * This is a limitation of of the current implementation */ #define YANG_SCHEMA_MOUNT_YANG_LIB_FORCE @@ -128,7 +129,7 @@ modstate_diff_free(modstate_diff_t *md) /*! Init the Yang module library * * Load RFC7895 yang spec, module-set-id, etc. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @retval 0 OK * @retval -1 Error * @see netconf_module_load @@ -139,7 +140,7 @@ yang_modules_init(clicon_handle h) int retval = -1; yang_stmt *yspec; - yspec = clicon_dbspec_yang(h); + yspec = clicon_dbspec_yang(h); if (!clicon_option_bool(h, "CLICON_YANG_LIBRARY")) goto ok; /* Ensure module-set-id is set */ @@ -162,7 +163,8 @@ yang_modules_init(clicon_handle h) } /*! Return RFC7895 revision (if parsed) - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @retval revision String (dont free) * @retval NULL Error: RFC7895 not loaded or revision not found */ @@ -287,7 +289,8 @@ yang_modules_state_build(clicon_handle h, } /*! Get modules state according to RFC 7895 - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in] xpath XML Xpath * @param[in] nsc XML Namespace context for xpath @@ -391,7 +394,7 @@ yang_modules_state_get(clicon_handle h, } retval = 1; done: - clicon_debug(1, "%s %d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, retval); if (xvec) free(xvec); if (cb) @@ -405,7 +408,8 @@ yang_modules_state_get(clicon_handle h, } /*! For single module state with namespace, get revisions and send upgrade callbacks - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xt Top-level XML tree to be updated (includes other ns as well) * @param[in] xmod XML module state diff (for one yang module) * @param[in] ns Namespace of module state we are looking for @@ -465,7 +469,8 @@ mod_ns_upgrade(clicon_handle h, } /*! Upgrade XML - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] xt XML tree (to upgrade) * @param[in] msd Modules-state differences of xt * @param[out] cbret Netconf error message if invalid @@ -514,6 +519,7 @@ clixon_module_upgrade(clicon_handle h, } /*! Given a yang statement and a prefix, return yang module to that relative prefix + * * Note, not the other module but the proxy import statement only * @param[in] ys A yang statement * @param[in] prefix prefix @@ -525,7 +531,7 @@ clixon_module_upgrade(clicon_handle h, * @see yang_find_namespace_by_prefix */ yang_stmt * -yang_find_module_by_prefix(yang_stmt *ys, +yang_find_module_by_prefix(yang_stmt *ys, char *prefix) { yang_stmt *yimport; @@ -561,8 +567,8 @@ 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", - prefix); + clicon_err(OE_YANG, 0, "No module or sub-module found with prefix %s", + prefix); yimport = NULL; goto done; /* unresolved */ } @@ -571,19 +577,20 @@ yang_find_module_by_prefix(yang_stmt *ys, return ymod; } -/* Get module from its own prefix +/*! Get module from its own prefix + * * This is really not a valid usecase, a kludge for the identityref derived * list workaround (IDENTITYREF_KLUDGE) * Actually, for canonical prefixes it is! - */ + */ yang_stmt * -yang_find_module_by_prefix_yspec(yang_stmt *yspec, +yang_find_module_by_prefix_yspec(yang_stmt *yspec, char *prefix) { yang_stmt *ymod = NULL; yang_stmt *yprefix; - - while ((ymod = yn_each(yspec, ymod)) != NULL) + + while ((ymod = yn_each(yspec, ymod)) != NULL) if (yang_keyword_get(ymod) == Y_MODULE && (yprefix = yang_find(ymod, Y_PREFIX, NULL)) != NULL && strcmp(yang_argument_get(yprefix), prefix) == 0) @@ -602,7 +609,7 @@ yang_find_module_by_prefix_yspec(yang_stmt *yspec, * @see yang_find_prefix_by_namespace */ yang_stmt * -yang_find_module_by_namespace(yang_stmt *yspec, +yang_find_module_by_namespace(yang_stmt *yspec, char *ns) { yang_stmt *ymod = NULL; @@ -628,7 +635,7 @@ yang_find_module_by_namespace(yang_stmt *yspec, * @note a module may have many revisions, but only the first is significant */ yang_stmt * -yang_find_module_by_namespace_revision(yang_stmt *yspec, +yang_find_module_by_namespace_revision(yang_stmt *yspec, const char *ns, const char *rev) { @@ -704,12 +711,12 @@ yang_find_module_by_name_revision(yang_stmt *yspec, * @see yang_find_module_by_prefix module-specific prefix */ yang_stmt * -yang_find_module_by_name(yang_stmt *yspec, +yang_find_module_by_name(yang_stmt *yspec, char *name) { yang_stmt *ymod = NULL; - - while ((ymod = yn_each(yspec, ymod)) != NULL) + + while ((ymod = yn_each(yspec, ymod)) != NULL) if ((yang_keyword_get(ymod) == Y_MODULE || yang_keyword_get(ymod) == Y_SUBMODULE) && strcmp(yang_argument_get(ymod), name)==0) return ymod; @@ -724,7 +731,10 @@ yang_find_module_by_name(yang_stmt *yspec, * YANG module that is implemented by the server. * Possibly add them to yang parsing, cardinality, etc? * as described in Section 3. - * Note this is called by the module using the extension md:annotate, not by + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error + * @note this is called by the module using the extension md:annotate, not by * ietf-yang-metadata.yang * @see yang_metadata_annotation_check */ @@ -738,14 +748,14 @@ ietf_yang_metadata_extension_cb(clicon_handle h, char *modname; yang_stmt *ymod; char *name; - + ymod = ys_module(yext); modname = yang_argument_get(ymod); extname = yang_argument_get(yext); if (strcmp(modname, "ietf-yang-metadata") != 0 || strcmp(extname, "annotation") != 0) goto ok; name = cv_string_get(yang_cv_get(ys)); - clicon_debug(1, "%s Enabled extension:%s:%s:%s", __FUNCTION__, modname, extname, name); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Enabled extension:%s:%s:%s", __FUNCTION__, modname, extname, name); /* XXX Nothing yet - this should signal that xml attribute annotations are allowed * Possibly, add an "annotation" YANG node. */ @@ -761,7 +771,7 @@ ietf_yang_metadata_extension_cb(clicon_handle h, * @param[in] ys YANG something * @param[out] ismeta Set to 1 if this is an annotation * @retval 0 OK - * @retval -1 Error + * @retval -1 Error * @see ietf_yang_metadata_extension_cb * XXX maybe a cache would be appropriate? * XXX: return type? @@ -775,9 +785,9 @@ yang_metadata_annotation_check(cxobj *xa, yang_stmt *yma = NULL; char *name; cg_var *cv; - + /* Loop through annotations */ - while ((yma = yn_each(ymod, yma)) != NULL){ + while ((yma = yn_each(ymod, yma)) != NULL){ /* Assume here md:annotation is written using canonical prefix */ if (yang_keyword_get(yma) != Y_UNKNOWN) continue; @@ -798,8 +808,12 @@ yang_metadata_annotation_check(cxobj *xa, } /*! In case ietf-yang-metadata is loaded by application, handle annotation extension + * * Consider moving fn * Must be called after clixon_plugin_module_init + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error */ int yang_metadata_init(clicon_handle h) @@ -823,7 +837,7 @@ yang_metadata_init(clicon_handle h) * Skip module if already loaded * This function is used where a yang-lib module-set is available to populate * an XML mount-point. - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] yanglib XML tree on the form ... * @param[in] yspec Will be populated with YANGs, is consumed * @retval 1 OK @@ -849,7 +863,7 @@ yang_lib2yspec(clicon_handle h, yang_stmt *yrev; int modmin = 0; - if (xpath_vec(yanglib, nsc, "module-set/module", &vec, &veclen) < 0) + if (xpath_vec(yanglib, nsc, "module-set/module", &vec, &veclen) < 0) goto done; for (i=0; i[ \t]+ <> { return MY_EOF; } \n { _YY->yy_linenum++; } -\r +\r "/*" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT1); } "//" { _YY->yy_lex_state = YYSTATE; BEGIN(COMMENT2); } @@ -264,18 +264,17 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]* [^'\n]+ { clixon_yang_parselval.string = strdup(yytext); return CHARS;} -[nt"\\] { BEGIN(_YY->yy_lex_state); - clixon_yang_parselval.string = strdup(yytext); +[nt"\\] { BEGIN(_YY->yy_lex_state); + clixon_yang_parselval.string = strdup(yytext); return CHARS; } [^nt"\\] { char *str = malloc(3); /* This is for Yang 1.0 double-quoted strings */ - BEGIN(_YY->yy_lex_state); + BEGIN(_YY->yy_lex_state); str[0] = '\\'; str[1] = yytext[0]; str[2] = '\0'; - clixon_yang_parselval.string = str; + clixon_yang_parselval.string = str; return CHARS; } - [^*\n]* /* eat anything that's not a '*' */ "*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ "*"+"/" BEGIN(_YY->yy_lex_state); @@ -295,7 +294,7 @@ yang_scan_init(clixon_yang_yacc *yy) yy->yy_lexbuf = yy_scan_string (yy->yy_parse_string); #if 1 /* XXX: just to use unput to avoid warning */ if (0) - yyunput(0, ""); + yyunput(0, ""); #endif return 0; diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y index 92012a94..3f962d95 100644 --- a/lib/src/clixon_yang_parse.y +++ b/lib/src/clixon_yang_parse.y @@ -55,7 +55,7 @@ char *string; } -%token MY_EOF +%token MY_EOF %token WS /* white space (at least one) */ %token CHARS %token ERRCHARS /* Error chars */ @@ -167,10 +167,10 @@ /* typecast macro */ #define _YY ((clixon_yang_yacc *)_yy) -#define _YYERROR(msg) {clicon_debug(1, "YYERROR %s '%s' %d", (msg), clixon_yang_parsetext, _YY->yy_linenum); YYERROR;} +#define _YYERROR(msg) {clixon_debug(CLIXON_DBG_DEFAULT, "YYERROR %s '%s' %d", (msg), clixon_yang_parsetext, _YY->yy_linenum); YYERROR;} /* add _yy to error parameters */ -#define YY_(msgid) msgid +#define YY_(msgid) msgid #include "clixon_config.h" @@ -199,31 +199,31 @@ /* Best debugging is to enable PARSE_DEBUG below and add -d to the LEX compile statement in the Makefile * And then run the testcase with -D 1 - * Disable it to stop any calls to clicon_debug. Having it on by default would mean very large debug outputs. + * Disable it to stop any calls to clixon_debug. Having it on by default would mean very large debug outputs. */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) -#define _PARSE_DEBUG1(s, s1) clicon_debug(1,(s), (s1)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) +#define _PARSE_DEBUG1(s, s1) clixon_debug(1,(s), (s1)) #else #define _PARSE_DEBUG(s) #define _PARSE_DEBUG1(s, s1) #endif - + extern int clixon_yang_parseget_lineno (void); -/* +/* clixon_yang_parseerror also called from yacc generated code * */ -void +void clixon_yang_parseerror(void *_yy, - char *s) -{ - clicon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'", + char *s) +{ + clicon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'", _YY->yy_name, - _YY->yy_linenum , - s, - clixon_yang_parsetext); + _YY->yy_linenum, + s, + clixon_yang_parsetext); return; } @@ -241,7 +241,10 @@ yang_parse_exit(clixon_yang_yacc *yy) } /*! Pop a yang parse context on stack - * @param[in] yy Yang yacc argument + * + * @param[in] yy Yang yacc argument + * @retval 0 OK + * @retval -1 Error */ int ystack_pop(clixon_yang_yacc *yy) @@ -260,6 +263,7 @@ ystack_pop(clixon_yang_yacc *yy) } /*! Push a yang parse context on stack + * * @param[in] yy Yang yacc argument * @param[in] yn Yang node to push */ @@ -267,7 +271,7 @@ struct ys_stack * ystack_push(clixon_yang_yacc *yy, yang_stmt *yn) { - struct ys_stack *ystack; + struct ys_stack *ystack; if ((ystack = malloc(sizeof(*ystack))) == NULL) { clicon_err(OE_YANG, errno, "malloc"); @@ -291,14 +295,14 @@ ystack_push(clixon_yang_yacc *yy, */ static yang_stmt * ysp_add(clixon_yang_yacc *yy, - enum rfc_6020 keyword, + enum rfc_6020 keyword, char *argument, char *extra) { struct ys_stack *ystack = yy->yy_stack; yang_stmt *ys = NULL; yang_stmt *yn; - + ystack = yy->yy_stack; if (ystack == NULL){ clicon_err(OE_YANG, errno, "No stack"); @@ -313,7 +317,7 @@ ysp_add(clixon_yang_yacc *yy, /* NOTE: does not make a copy of string, ie argument is 'consumed' here */ yang_argument_set(ys, argument); if (yn_insert(yn, ys) < 0) /* Insert into hierarchy */ - goto err; + goto err; yang_linenum_set(ys, yy->yy_linenum); /* For error/debugging */ if (ys_parse_sub(ys, yy->yy_name, extra) < 0) /* Check statement-specific syntax */ goto err2; /* dont free since part of tree */ @@ -334,7 +338,7 @@ ysp_add(clixon_yang_yacc *yy, */ static yang_stmt * ysp_add_push(clixon_yang_yacc *yy, - enum rfc_6020 keyword, + enum rfc_6020 keyword, char *argument, char *extra) { @@ -348,73 +352,73 @@ ysp_add_push(clixon_yang_yacc *yy, } -%} - +%} + %% /* - statement = keyword [argument] (";" / "{" *statement "}") + statement = keyword [argument] (";" / "{" *statement "}") The argument is a string recursion: right is wrong Let subststmt rules contain an empty rule, but not stmt rules */ file : module_stmt MY_EOF - { _PARSE_DEBUG("file->module-stmt"); YYACCEPT; } + { _PARSE_DEBUG("file->module-stmt"); YYACCEPT; } | submodule_stmt MY_EOF - { _PARSE_DEBUG("file->submodule-stmt"); YYACCEPT; } + { _PARSE_DEBUG("file->submodule-stmt"); YYACCEPT; } ; /* module identifier-arg-str */ -module_stmt : K_MODULE identifier_str +module_stmt : K_MODULE identifier_str { if ((_YY->yy_module = ysp_add_push(_yy, Y_MODULE, $2, NULL)) == NULL) _YYERROR("module_stmt"); - } - '{' module_substmts '}' + } + '{' module_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("module_stmt"); - _PARSE_DEBUG("module_stmt -> id-arg-str { module-substmts }");} + _PARSE_DEBUG("module_stmt -> id-arg-str { module-substmts }");} ; -module_substmts : module_substmts module_substmt - {_PARSE_DEBUG("module-substmts -> module-substmts module-substm");} - | module_substmt - { _PARSE_DEBUG("module-substmts ->");} +module_substmts : module_substmts module_substmt + {_PARSE_DEBUG("module-substmts -> module-substmts module-substm");} + | module_substmt + { _PARSE_DEBUG("module-substmts ->");} ; module_substmt : module_header_stmts { _PARSE_DEBUG("module-substmt -> module-header-stmts");} - | linkage_stmts { _PARSE_DEBUG("module-substmt -> linake-stmts");} - | meta_stmts { _PARSE_DEBUG("module-substmt -> meta-stmts");} - | revision_stmts { _PARSE_DEBUG("module-substmt -> revision-stmts");} - | body_stmts { _PARSE_DEBUG("module-substmt -> body-stmts");} - | unknown_stmt { _PARSE_DEBUG("module-substmt -> unknown-stmt");} - | { _PARSE_DEBUG("module-substmt ->");} + | linkage_stmts { _PARSE_DEBUG("module-substmt -> linake-stmts");} + | meta_stmts { _PARSE_DEBUG("module-substmt -> meta-stmts");} + | revision_stmts { _PARSE_DEBUG("module-substmt -> revision-stmts");} + | body_stmts { _PARSE_DEBUG("module-substmt -> body-stmts");} + | unknown_stmt { _PARSE_DEBUG("module-substmt -> unknown-stmt");} + | { _PARSE_DEBUG("module-substmt ->");} ; /* submodule */ -submodule_stmt : K_SUBMODULE identifier_str +submodule_stmt : K_SUBMODULE identifier_str { if ((_YY->yy_module = ysp_add_push(_yy, Y_SUBMODULE, $2, NULL)) == NULL) _YYERROR("submodule_stmt"); } '{' submodule_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("submodule_stmt"); - _PARSE_DEBUG("submodule_stmt -> id-arg-str { submodule-substmts }");} + _PARSE_DEBUG("submodule_stmt -> id-arg-str { submodule-substmts }");} ; -submodule_substmts : submodule_substmts submodule_substmt +submodule_substmts : submodule_substmts submodule_substmt { _PARSE_DEBUG("submodule-stmts -> submodule-substmts submodule-substmt"); } - | submodule_substmt + | submodule_substmt { _PARSE_DEBUG("submodule-stmts -> submodule-substmt"); } ; -submodule_substmt : submodule_header_stmts +submodule_substmt : submodule_header_stmts { _PARSE_DEBUG("submodule-substmt -> submodule-header-stmts"); } - | linkage_stmts { _PARSE_DEBUG("submodule-substmt -> linake-stmts");} - | meta_stmts { _PARSE_DEBUG("submodule-substmt -> meta-stmts");} - | revision_stmts { _PARSE_DEBUG("submodule-substmt -> revision-stmts");} + | linkage_stmts { _PARSE_DEBUG("submodule-substmt -> linake-stmts");} + | meta_stmts { _PARSE_DEBUG("submodule-substmt -> meta-stmts");} + | revision_stmts { _PARSE_DEBUG("submodule-substmt -> revision-stmts");} | body_stmts { _PARSE_DEBUG("submodule-stmt -> body-stmts"); } - | unknown_stmt { _PARSE_DEBUG("submodule-substmt -> unknown-stmt");} - | { _PARSE_DEBUG("submodule-substmt ->");} + | unknown_stmt { _PARSE_DEBUG("submodule-substmt -> unknown-stmt");} + | { _PARSE_DEBUG("submodule-substmt ->");} ; /* linkage */ -linkage_stmts : linkage_stmts linkage_stmt +linkage_stmts : linkage_stmts linkage_stmt { _PARSE_DEBUG("linkage-stmts -> linkage-stmts linkage-stmt"); } | linkage_stmt { _PARSE_DEBUG("linkage-stmts -> linkage-stmt"); } @@ -430,7 +434,7 @@ module_header_stmts : module_header_stmts module_header_stmt | module_header_stmt { _PARSE_DEBUG("module-header-stmts -> "); } ; -module_header_stmt : yang_version_stmt +module_header_stmt : yang_version_stmt { _PARSE_DEBUG("module-header-stmt -> yang-version-stmt"); } | namespace_stmt { _PARSE_DEBUG("module-header-stmt -> namespace-stmt"); } | prefix_stmt { _PARSE_DEBUG("module-header-stmt -> prefix-stmt"); } @@ -439,11 +443,11 @@ module_header_stmt : yang_version_stmt /* submodule-header */ submodule_header_stmts : submodule_header_stmts submodule_header_stmt { _PARSE_DEBUG("submodule-header-stmts -> submodule-header-stmts submodule-header-stmt"); } - | submodule_header_stmt + | submodule_header_stmt { _PARSE_DEBUG("submodule-header-stmts -> submodule-header-stmt"); } ; -submodule_header_stmt : yang_version_stmt +submodule_header_stmt : yang_version_stmt { _PARSE_DEBUG("submodule-header-stmt -> yang-version-stmt"); } | belongs_to_stmt { _PARSE_DEBUG("submodule-header-stmt -> belongs-to-stmt"); } ; @@ -457,15 +461,15 @@ yang_version_stmt : K_YANG_VERSION string stmtend /* import */ import_stmt : K_IMPORT identifier_str { if (ysp_add_push(_yy, Y_IMPORT, $2, NULL) == NULL) _YYERROR("import_stmt"); } - '{' import_substmts '}' + '{' import_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("import_stmt"); - _PARSE_DEBUG("import-stmt -> IMPORT id-arg-str { import-substmts }");} + _PARSE_DEBUG("import-stmt -> IMPORT id-arg-str { import-substmts }");} ; -import_substmts : import_substmts import_substmt - { _PARSE_DEBUG("import-substmts -> import-substmts import-substm");} - | import_substmt - { _PARSE_DEBUG("import-substmts ->");} +import_substmts : import_substmts import_substmt + { _PARSE_DEBUG("import-substmts -> import-substmts import-substm");} + | import_substmt + { _PARSE_DEBUG("import-substmts ->");} ; import_substmt : prefix_stmt { _PARSE_DEBUG("import-stmt -> prefix-stmt"); } @@ -475,7 +479,7 @@ import_substmt : prefix_stmt { _PARSE_DEBUG("import-stmt -> prefix-stmt") ; include_stmt : K_INCLUDE identifier_str ';' - { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("include_stmt"); + { if (ysp_add(_yy, Y_INCLUDE, $2, NULL)== NULL) _YYERROR("include_stmt"); _PARSE_DEBUG("include-stmt -> id-str"); } | K_INCLUDE identifier_str { if (ysp_add_push(_yy, Y_INCLUDE, $2, NULL) == NULL) _YYERROR("include_stmt"); } @@ -484,10 +488,10 @@ include_stmt : K_INCLUDE identifier_str ';' _PARSE_DEBUG("include-stmt -> id-str { include-substmts }"); } ; -include_substmts : include_substmts include_substmt - { _PARSE_DEBUG("include-substmts -> include-substmts include-substm");} - | include_substmt - { _PARSE_DEBUG("include-substmts ->");} +include_substmts : include_substmts include_substmt + { _PARSE_DEBUG("include-substmts -> include-substmts include-substm");} + | include_substmt + { _PARSE_DEBUG("include-substmts ->");} ; include_substmt : revision_date_stmt { _PARSE_DEBUG("include-stmt -> revision-date-stmt"); } @@ -497,19 +501,18 @@ include_substmt : revision_date_stmt { _PARSE_DEBUG("include-stmt -> revision-da /* namespace-stmt = namespace-keyword sep uri-str */ -namespace_stmt : K_NAMESPACE string stmtend - { if (ysp_add(_yy, Y_NAMESPACE, $2, NULL)== NULL) _YYERROR("namespace_stmt"); +namespace_stmt : K_NAMESPACE string stmtend + { if (ysp_add(_yy, Y_NAMESPACE, $2, NULL)== NULL) _YYERROR("namespace_stmt"); _PARSE_DEBUG("namespace-stmt -> NAMESPACE string"); } ; prefix_stmt : K_PREFIX identifier_str stmtend /* XXX prefix-arg-str */ - { if (ysp_add(_yy, Y_PREFIX, $2, NULL)== NULL) _YYERROR("prefix_stmt"); + { if (ysp_add(_yy, Y_PREFIX, $2, NULL)== NULL) _YYERROR("prefix_stmt"); _PARSE_DEBUG("prefix-stmt -> PREFIX string ;");} ; -belongs_to_stmt : K_BELONGS_TO identifier_str +belongs_to_stmt : K_BELONGS_TO identifier_str { if (ysp_add_push(_yy, Y_BELONGS_TO, $2, NULL) == NULL) _YYERROR("belongs_to_stmt"); } - '{' prefix_stmt '}' { if (ystack_pop(_yy) < 0) _YYERROR("belongs_to_stmt"); _PARSE_DEBUG("belongs-to-stmt -> BELONGS-TO id-arg-str { prefix-stmt } "); @@ -517,41 +520,41 @@ belongs_to_stmt : K_BELONGS_TO identifier_str ; organization_stmt: K_ORGANIZATION string stmtend - { if (ysp_add(_yy, Y_ORGANIZATION, $2, NULL)== NULL) _YYERROR("belongs_to_stmt"); + { if (ysp_add(_yy, Y_ORGANIZATION, $2, NULL)== NULL) _YYERROR("belongs_to_stmt"); _PARSE_DEBUG("organization-stmt -> ORGANIZATION string ;");} ; contact_stmt : K_CONTACT string stmtend - { if (ysp_add(_yy, Y_CONTACT, $2, NULL)== NULL) _YYERROR("contact_stmt"); + { if (ysp_add(_yy, Y_CONTACT, $2, NULL)== NULL) _YYERROR("contact_stmt"); _PARSE_DEBUG("contact-stmt -> CONTACT string"); } ; description_stmt : K_DESCRIPTION string stmtend - { if (ysp_add(_yy, Y_DESCRIPTION, $2, NULL)== NULL) _YYERROR("description_stmt"); + { if (ysp_add(_yy, Y_DESCRIPTION, $2, NULL)== NULL) _YYERROR("description_stmt"); _PARSE_DEBUG("description-stmt -> DESCRIPTION string ;");} ; reference_stmt : K_REFERENCE string stmtend - { if (ysp_add(_yy, Y_REFERENCE, $2, NULL)== NULL) _YYERROR("reference_stmt"); + { if (ysp_add(_yy, Y_REFERENCE, $2, NULL)== NULL) _YYERROR("reference_stmt"); _PARSE_DEBUG("reference-stmt -> REFERENCE string ;");} ; units_stmt : K_UNITS string ';' - { if (ysp_add(_yy, Y_UNITS, $2, NULL)== NULL) _YYERROR("units_stmt"); + { if (ysp_add(_yy, Y_UNITS, $2, NULL)== NULL) _YYERROR("units_stmt"); _PARSE_DEBUG("units-stmt -> UNITS string"); } ; revision_stmt : K_REVISION string ';' /* XXX date-arg-str */ - { if (ysp_add(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt"); + { if (ysp_add(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt"); _PARSE_DEBUG("revision-stmt -> date-arg-str ;"); } - | K_REVISION string + | K_REVISION string { if (ysp_add_push(_yy, Y_REVISION, $2, NULL) == NULL) _YYERROR("revision_stmt"); } '{' revision_substmts '}' /* XXX date-arg-str */ { if (ystack_pop(_yy) < 0) _YYERROR("revision_stmt"); _PARSE_DEBUG("revision-stmt -> date-arg-str { revision-substmts }"); } ; -revision_substmts : revision_substmts revision_substmt +revision_substmts : revision_substmts revision_substmt { _PARSE_DEBUG("revision-substmts -> revision-substmts revision-substmt }"); } | revision_substmt { _PARSE_DEBUG("revision-substmts -> }"); } @@ -559,37 +562,37 @@ revision_substmts : revision_substmts revision_substmt revision_substmt : description_stmt { _PARSE_DEBUG("revision-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("revision-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("revision-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("revision-substmt -> unknown-stmt");} | { _PARSE_DEBUG("revision-substmt -> "); } ; /* revision */ -revision_stmts : revision_stmts revision_stmt +revision_stmts : revision_stmts revision_stmt { _PARSE_DEBUG("revision-stmts -> revision-stmts revision-stmt"); } | revision_stmt { _PARSE_DEBUG("revision-stmts -> "); } ; revision_date_stmt : K_REVISION_DATE string stmtend /* XXX date-arg-str */ - { if (ysp_add(_yy, Y_REVISION_DATE, $2, NULL) == NULL) _YYERROR("revision_date_stmt"); + { if (ysp_add(_yy, Y_REVISION_DATE, $2, NULL) == NULL) _YYERROR("revision_date_stmt"); _PARSE_DEBUG("revision-date-stmt -> date;"); } ; -extension_stmt : K_EXTENSION identifier_str ';' +extension_stmt : K_EXTENSION identifier_str ';' { if (ysp_add(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("extension_stmt"); _PARSE_DEBUG("extenstion-stmt -> EXTENSION id-str ;"); } - | K_EXTENSION identifier_str + | K_EXTENSION identifier_str { if (ysp_add_push(_yy, Y_EXTENSION, $2, NULL) == NULL) _YYERROR("extension_stmt"); } - '{' extension_substmts '}' + '{' extension_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("extension_stmt"); _PARSE_DEBUG("extension-stmt -> EXTENSION id-str { extension-substmts }"); } ; /* extension substmts */ -extension_substmts : extension_substmts extension_substmt +extension_substmts : extension_substmts extension_substmt { _PARSE_DEBUG("extension-substmts -> extension-substmts extension-substmt"); } - | extension_substmt + | extension_substmt { _PARSE_DEBUG("extension-substmts -> extension-substmt"); } ; @@ -597,7 +600,7 @@ extension_substmt : argument_stmt { _PARSE_DEBUG("extension-substmt -> argume | status_stmt { _PARSE_DEBUG("extension-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("extension-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("extension-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("extension-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("extension-substmt -> unknown-stmt");} | { _PARSE_DEBUG("extension-substmt -> "); } ; @@ -612,9 +615,9 @@ argument_stmt : K_ARGUMENT identifier_str ';' ; /* argument substmts */ -argument_substmts : argument_substmts argument_substmt +argument_substmts : argument_substmts argument_substmt { _PARSE_DEBUG("argument-substmts -> argument-substmts argument-substmt"); } - | argument_substmt + | argument_substmt { _PARSE_DEBUG("argument-substmts -> argument-substmt"); } ; @@ -628,20 +631,20 @@ yin_element_stmt1 : K_YIN_ELEMENT bool_str stmtend {free($2);} ; /* Identity */ -identity_stmt : K_IDENTITY identifier_str ';' - { if (ysp_add(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("identity_stmt"); +identity_stmt : K_IDENTITY identifier_str ';' + { if (ysp_add(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("identity_stmt"); _PARSE_DEBUG("identity-stmt -> IDENTITY string ;"); } | K_IDENTITY identifier_str { if (ysp_add_push(_yy, Y_IDENTITY, $2, NULL) == NULL) _YYERROR("identity_stmt"); } - '{' identity_substmts '}' + '{' identity_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("identity_stmt"); _PARSE_DEBUG("identity-stmt -> IDENTITY string { identity-substmts }"); } ; -identity_substmts : identity_substmts identity_substmt +identity_substmts : identity_substmts identity_substmt { _PARSE_DEBUG("identity-substmts -> identity-substmts identity-substmt"); } - | identity_substmt + | identity_substmt { _PARSE_DEBUG("identity-substmts -> identity-substmt"); } ; @@ -650,30 +653,30 @@ identity_substmt : if_feature_stmt { _PARSE_DEBUG("identity-substmt -> if-feat | status_stmt { _PARSE_DEBUG("identity-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("identity-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("identity-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("identity-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("identity-substmt -> unknown-stmt");} | { _PARSE_DEBUG("identity-substmt -> "); } ; base_stmt : K_BASE identifier_ref_arg_str stmtend - { if (ysp_add(_yy, Y_BASE, $2, NULL)== NULL) _YYERROR("base_stmt"); + { if (ysp_add(_yy, Y_BASE, $2, NULL)== NULL) _YYERROR("base_stmt"); _PARSE_DEBUG("base-stmt -> BASE identifier-ref-arg-str"); } ; /* Feature */ -feature_stmt : K_FEATURE identifier_str ';' +feature_stmt : K_FEATURE identifier_str ';' { if (ysp_add(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("feature_stmt"); _PARSE_DEBUG("feature-stmt -> FEATURE id-arg-str ;"); } | K_FEATURE identifier_str { if (ysp_add_push(_yy, Y_FEATURE, $2, NULL) == NULL) _YYERROR("feature_stmt"); } - '{' feature_substmts '}' + '{' feature_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("feature_stmt"); _PARSE_DEBUG("feature-stmt -> FEATURE id-arg-str { feature-substmts }"); } ; /* feature substmts */ -feature_substmts : feature_substmts feature_substmt +feature_substmts : feature_substmts feature_substmt { _PARSE_DEBUG("feature-substmts -> feature-substmts feature-substmt"); } - | feature_substmt + | feature_substmt { _PARSE_DEBUG("feature-substmts -> feature-substmt"); } ; @@ -681,13 +684,13 @@ feature_substmt : if_feature_stmt { _PARSE_DEBUG("feature-substmt -> if-featu | status_stmt { _PARSE_DEBUG("feature-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("feature-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("feature-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("feature-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("feature-substmt -> unknown-stmt");} | { _PARSE_DEBUG("feature-substmt -> "); } ; /* if-feature-stmt = if-feature-keyword sep if-feature-expr-str */ -if_feature_stmt : K_IF_FEATURE if_feature_expr_str stmtend - { if (ysp_add(_yy, Y_IF_FEATURE, $2, NULL) == NULL) _YYERROR("if_feature_stmt"); +if_feature_stmt : K_IF_FEATURE if_feature_expr_str stmtend + { if (ysp_add(_yy, Y_IF_FEATURE, $2, NULL) == NULL) _YYERROR("if_feature_stmt"); _PARSE_DEBUG("if-feature-stmt -> IF-FEATURE if-feature-expr-str"); } ; @@ -701,16 +704,16 @@ if_feature_expr_str : string ; /* Typedef */ -typedef_stmt : K_TYPEDEF identifier_str +typedef_stmt : K_TYPEDEF identifier_str { if (ysp_add_push(_yy, Y_TYPEDEF, $2, NULL) == NULL) _YYERROR("typedef_stmt"); } - '{' typedef_substmts '}' + '{' typedef_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("typedef_stmt"); _PARSE_DEBUG("typedef-stmt -> TYPEDEF id-arg-str { typedef-substmts }"); } ; -typedef_substmts : typedef_substmts typedef_substmt +typedef_substmts : typedef_substmts typedef_substmt { _PARSE_DEBUG("typedef-substmts -> typedef-substmts typedef-substmt"); } - | typedef_substmt + | typedef_substmt { _PARSE_DEBUG("typedef-substmts -> typedef-substmt"); } ; @@ -720,16 +723,16 @@ typedef_substmt : type_stmt { _PARSE_DEBUG("typedef-substmt -> type-stm | status_stmt { _PARSE_DEBUG("typedef-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("typedef-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("typedef-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("typedef-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("typedef-substmt -> unknown-stmt");} | { _PARSE_DEBUG("typedef-substmt -> "); } ; /* Type */ -type_stmt : K_TYPE identifier_ref_arg_str ';' - { if (ysp_add(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt"); +type_stmt : K_TYPE identifier_ref_arg_str ';' + { if (ysp_add(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt"); _PARSE_DEBUG("type-stmt -> TYPE identifier-ref-arg-str ;");} | K_TYPE identifier_ref_arg_str - { if (ysp_add_push(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt"); + { if (ysp_add_push(_yy, Y_TYPE, $2, NULL) == NULL) _YYERROR("type_stmt"); } '{' type_body_stmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("type_stmt"); @@ -742,18 +745,18 @@ type_stmt : K_TYPE identifier_ref_arg_str ';' */ type_body_stmts : type_body_stmts type_body_stmt { _PARSE_DEBUG("type-body-stmts -> type-body-stmts type-body-stmt"); } - | + | { _PARSE_DEBUG("type-body-stmts -> "); } ; -type_body_stmt/* numerical-restrictions */ +type_body_stmt/* numerical-restrictions */ : range_stmt { _PARSE_DEBUG("type-body-stmt -> range-stmt"); } - /* decimal64-specification */ + /* decimal64-specification */ | fraction_digits_stmt { _PARSE_DEBUG("type-body-stmt -> fraction-digits-stmt"); } - /* string-restrictions */ + /* string-restrictions */ | length_stmt { _PARSE_DEBUG("type-body-stmt -> length-stmt"); } | pattern_stmt { _PARSE_DEBUG("type-body-stmt -> pattern-stmt"); } - /* enum-specification */ + /* enum-specification */ | enum_stmt { _PARSE_DEBUG("type-body-stmt -> enum-stmt"); } /* leafref-specifications */ | path_stmt { _PARSE_DEBUG("type-body-stmt -> path-stmt"); } @@ -766,37 +769,37 @@ type_body_stmt/* numerical-restrictions */ /* union-specification */ | type_stmt { _PARSE_DEBUG("type-body-stmt -> type-stmt"); } /* Cisco uses this (eg Cisco-IOS-XR-sysadmin-nto-misc-set-hostname.yang) but I dont see this is in the RFC */ - | unknown_stmt { _PARSE_DEBUG("type-body-stmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("type-body-stmt -> unknown-stmt");} ; /* range-stmt */ range_stmt : K_RANGE string ';' /* XXX range-arg-str */ - { if (ysp_add(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt"); + { if (ysp_add(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt"); _PARSE_DEBUG("range-stmt -> RANGE string ;"); } | K_RANGE string { if (ysp_add_push(_yy, Y_RANGE, $2, NULL) == NULL) _YYERROR("range_stmt"); } - '{' range_substmts '}' + '{' range_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("range_stmt"); _PARSE_DEBUG("range-stmt -> RANGE string { range-substmts }"); } ; -range_substmts : range_substmts range_substmt +range_substmts : range_substmts range_substmt { _PARSE_DEBUG("range-substmts -> range-substmts range-substmt"); } - | range_substmt + | range_substmt { _PARSE_DEBUG("range-substmts -> range-substmt"); } ; -range_substmt : error_message_stmt { _PARSE_DEBUG("range-substmt -> error-message-stmt");} +range_substmt : error_message_stmt { _PARSE_DEBUG("range-substmt -> error-message-stmt");} | description_stmt { _PARSE_DEBUG("range-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("range-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("range-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("range-substmt -> unknown-stmt");} | { _PARSE_DEBUG("range-substmt -> "); } ; /* fraction-digits-stmt = fraction-digits-keyword fraction-digits-arg-str */ -fraction_digits_stmt : K_FRACTION_DIGITS string stmtend - { if (ysp_add(_yy, Y_FRACTION_DIGITS, $2, NULL) == NULL) _YYERROR("fraction_digits_stmt"); +fraction_digits_stmt : K_FRACTION_DIGITS string stmtend + { if (ysp_add(_yy, Y_FRACTION_DIGITS, $2, NULL) == NULL) _YYERROR("fraction_digits_stmt"); _PARSE_DEBUG("fraction-digits-stmt -> FRACTION-DIGITS string"); } ; @@ -814,80 +817,80 @@ meta_stmt : organization_stmt { _PARSE_DEBUG("meta-stmt -> organization-s /* length-stmt */ length_stmt : K_LENGTH string ';' /* XXX length-arg-str */ - { if (ysp_add(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt"); + { if (ysp_add(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt"); _PARSE_DEBUG("length-stmt -> LENGTH string ;"); } | K_LENGTH string { if (ysp_add_push(_yy, Y_LENGTH, $2, NULL) == NULL) _YYERROR("length_stmt"); } - '{' length_substmts '}' + '{' length_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("length_stmt"); _PARSE_DEBUG("length-stmt -> LENGTH string { length-substmts }"); } ; -length_substmts : length_substmts length_substmt +length_substmts : length_substmts length_substmt { _PARSE_DEBUG("length-substmts -> length-substmts length-substmt"); } - | length_substmt + | length_substmt { _PARSE_DEBUG("length-substmts -> length-substmt"); } ; -length_substmt : error_message_stmt { _PARSE_DEBUG("length-substmt -> error-message-stmt");} +length_substmt : error_message_stmt { _PARSE_DEBUG("length-substmt -> error-message-stmt");} | description_stmt { _PARSE_DEBUG("length-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("length-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("length-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("length-substmt -> unknown-stmt");} | { _PARSE_DEBUG("length-substmt -> "); } ; /* Pattern */ -pattern_stmt : K_PATTERN string ';' - { if (ysp_add(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt"); +pattern_stmt : K_PATTERN string ';' + { if (ysp_add(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt"); _PARSE_DEBUG("pattern-stmt -> PATTERN string ;"); } | K_PATTERN string { if (ysp_add_push(_yy, Y_PATTERN, $2, NULL) == NULL) _YYERROR("pattern_stmt"); } - '{' pattern_substmts '}' + '{' pattern_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("pattern_stmt"); _PARSE_DEBUG("pattern-stmt -> PATTERN string { pattern-substmts }"); } ; -pattern_substmts : pattern_substmts pattern_substmt +pattern_substmts : pattern_substmts pattern_substmt { _PARSE_DEBUG("pattern-substmts -> pattern-substmts pattern-substmt"); } - | pattern_substmt + | pattern_substmt { _PARSE_DEBUG("pattern-substmts -> pattern-substmt"); } ; pattern_substmt : modifier_stmt { _PARSE_DEBUG("pattern-substmt -> modifier-stmt");} | error_message_stmt { _PARSE_DEBUG("pattern-substmt -> error-message-stmt");} - | error_app_tag_stmt { _PARSE_DEBUG("pattern-substmt -> error-app-tag-stmt");} + | error_app_tag_stmt { _PARSE_DEBUG("pattern-substmt -> error-app-tag-stmt");} | description_stmt { _PARSE_DEBUG("pattern-substmt -> description-stmt");} | reference_stmt { _PARSE_DEBUG("pattern-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("pattern-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("pattern-substmt -> unknown-stmt");} | { _PARSE_DEBUG("pattern-substmt -> "); } ; modifier_stmt : K_MODIFIER string stmtend - { if (ysp_add(_yy, Y_MODIFIER, $2, NULL)== NULL) _YYERROR("modifier_stmt"); + { if (ysp_add(_yy, Y_MODIFIER, $2, NULL)== NULL) _YYERROR("modifier_stmt"); _PARSE_DEBUG("modifier-stmt -> MODIFIER string"); } ; default_stmt : K_DEFAULT string stmtend - { if (ysp_add(_yy, Y_DEFAULT, $2, NULL)== NULL) _YYERROR("default_stmt"); + { if (ysp_add(_yy, Y_DEFAULT, $2, NULL)== NULL) _YYERROR("default_stmt"); _PARSE_DEBUG("default-stmt -> DEFAULT string"); } ; /* enum-stmt */ enum_stmt : K_ENUM string ';' - { if (ysp_add(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt"); + { if (ysp_add(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt"); _PARSE_DEBUG("enum-stmt -> ENUM string ;"); } | K_ENUM string { if (ysp_add_push(_yy, Y_ENUM, $2, NULL) == NULL) _YYERROR("enum_stmt"); } - '{' enum_substmts '}' + '{' enum_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("enum_stmt"); _PARSE_DEBUG("enum-stmt -> ENUM string { enum-substmts }"); } ; -enum_substmts : enum_substmts enum_substmt +enum_substmts : enum_substmts enum_substmt { _PARSE_DEBUG("enum-substmts -> enum-substmts enum-substmt"); } - | enum_substmt + | enum_substmt { _PARSE_DEBUG("enum-substmts -> enum-substmt"); } ; @@ -896,34 +899,34 @@ enum_substmt : if_feature_stmt { _PARSE_DEBUG("enum-substmt -> if-feature- | status_stmt { _PARSE_DEBUG("enum-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("enum-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("enum-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("enum-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("enum-substmt -> unknown-stmt");} | { _PARSE_DEBUG("enum-substmt -> "); } ; path_stmt : K_PATH string stmtend /* XXX: path-arg-str */ - { if (ysp_add(_yy, Y_PATH, $2, NULL)== NULL) _YYERROR("path_stmt"); + { if (ysp_add(_yy, Y_PATH, $2, NULL)== NULL) _YYERROR("path_stmt"); _PARSE_DEBUG("path-stmt -> PATH string"); } ; require_instance_stmt : K_REQUIRE_INSTANCE bool_str stmtend - { if (ysp_add(_yy, Y_REQUIRE_INSTANCE, $2, NULL)== NULL) _YYERROR("require_instance_stmt"); + { if (ysp_add(_yy, Y_REQUIRE_INSTANCE, $2, NULL)== NULL) _YYERROR("require_instance_stmt"); _PARSE_DEBUG("require-instance-stmt -> REQUIRE-INSTANCE string"); } ; /* bit-stmt */ bit_stmt : K_BIT identifier_str ';' - { if (ysp_add(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt"); + { if (ysp_add(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt"); _PARSE_DEBUG("bit-stmt -> BIT string ;"); } | K_BIT identifier_str { if (ysp_add_push(_yy, Y_BIT, $2, NULL) == NULL) _YYERROR("bit_stmt"); } - '{' bit_substmts '}' + '{' bit_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("bit_stmt"); _PARSE_DEBUG("bit-stmt -> BIT string { bit-substmts }"); } ; -bit_substmts : bit_substmts bit_substmt +bit_substmts : bit_substmts bit_substmt { _PARSE_DEBUG("bit-substmts -> bit-substmts bit-substmt"); } - | bit_substmt + | bit_substmt { _PARSE_DEBUG("bit-substmts -> bit-substmt"); } ; @@ -936,57 +939,57 @@ bit_substmt : if_feature_stmt { _PARSE_DEBUG("bit-substmt -> if-feature-s ; /* position-stmt = position-keyword position-value-arg-str */ -position_stmt : K_POSITION integer_value_str stmtend - { if (ysp_add(_yy, Y_POSITION, $2, NULL) == NULL) _YYERROR("position_stmt"); +position_stmt : K_POSITION integer_value_str stmtend + { if (ysp_add(_yy, Y_POSITION, $2, NULL) == NULL) _YYERROR("position_stmt"); _PARSE_DEBUG("position-stmt -> POSITION integer-value"); } ; /* status-stmt = status-keyword sep status-arg-str XXX: current-keyword*/ status_stmt : K_STATUS string stmtend - { if (ysp_add(_yy, Y_STATUS, $2, NULL) == NULL) _YYERROR("status_stmt"); + { if (ysp_add(_yy, Y_STATUS, $2, NULL) == NULL) _YYERROR("status_stmt"); _PARSE_DEBUG("status-stmt -> STATUS string"); } ; config_stmt : K_CONFIG bool_str stmtend - { if (ysp_add(_yy, Y_CONFIG, $2, NULL) == NULL) _YYERROR("config_stmt"); + { if (ysp_add(_yy, Y_CONFIG, $2, NULL) == NULL) _YYERROR("config_stmt"); _PARSE_DEBUG("config-stmt -> CONFIG config-arg-str"); } ; /* mandatory-stmt = mandatory-keyword mandatory-arg-str */ mandatory_stmt : K_MANDATORY bool_str stmtend { yang_stmt *ys; - if ((ys = ysp_add(_yy, Y_MANDATORY, $2, NULL))== NULL) _YYERROR("mandatory_stmt"); + if ((ys = ysp_add(_yy, Y_MANDATORY, $2, NULL))== NULL) _YYERROR("mandatory_stmt"); _PARSE_DEBUG("mandatory-stmt -> MANDATORY mandatory-arg-str ;");} ; presence_stmt : K_PRESENCE string stmtend { yang_stmt *ys; - if ((ys = ysp_add(_yy, Y_PRESENCE, $2, NULL))== NULL) _YYERROR("presence_stmt"); + if ((ys = ysp_add(_yy, Y_PRESENCE, $2, NULL))== NULL) _YYERROR("presence_stmt"); _PARSE_DEBUG("presence-stmt -> PRESENCE string ;");} ; /* ordered-by-stmt = ordered-by-keyword sep ordered-by-arg-str */ ordered_by_stmt : K_ORDERED_BY string stmtend { yang_stmt *ys; - if ((ys = ysp_add(_yy, Y_ORDERED_BY, $2, NULL))== NULL) _YYERROR("ordered_by_stmt"); + if ((ys = ysp_add(_yy, Y_ORDERED_BY, $2, NULL))== NULL) _YYERROR("ordered_by_stmt"); _PARSE_DEBUG("ordered-by-stmt -> ORDERED-BY ordered-by-arg ;");} ; /* must-stmt */ must_stmt : K_MUST string ';' - { if (ysp_add(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt"); + { if (ysp_add(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt"); _PARSE_DEBUG("must-stmt -> MUST string ;"); } | K_MUST string { if (ysp_add_push(_yy, Y_MUST, $2, NULL) == NULL) _YYERROR("must_stmt"); } - '{' must_substmts '}' + '{' must_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("must_stmt"); _PARSE_DEBUG("must-stmt -> MUST string { must-substmts }"); } ; -must_substmts : must_substmts must_substmt +must_substmts : must_substmts must_substmt { _PARSE_DEBUG("must-substmts -> must-substmts must-substmt"); } - | must_substmt + | must_substmt { _PARSE_DEBUG("must-substmts -> must-substmt"); } ; @@ -1010,7 +1013,7 @@ error_app_tag_stmt : K_ERROR_APP_TAG string stmtend /* min-elements-stmt = min-elements-keyword min-value-arg-str */ min_elements_stmt : K_MIN_ELEMENTS integer_value_str stmtend - { if (ysp_add(_yy, Y_MIN_ELEMENTS, $2, NULL)== NULL) _YYERROR("min_elements_stmt"); + { if (ysp_add(_yy, Y_MIN_ELEMENTS, $2, NULL)== NULL) _YYERROR("min_elements_stmt"); _PARSE_DEBUG("min-elements-stmt -> MIN-ELEMENTS integer ;");} ; @@ -1018,12 +1021,12 @@ min_elements_stmt : K_MIN_ELEMENTS integer_value_str stmtend * XXX cannot use integer-value */ max_elements_stmt : K_MAX_ELEMENTS string stmtend - { if (ysp_add(_yy, Y_MAX_ELEMENTS, $2, NULL)== NULL) _YYERROR("max_elements_stmt"); + { if (ysp_add(_yy, Y_MAX_ELEMENTS, $2, NULL)== NULL) _YYERROR("max_elements_stmt"); _PARSE_DEBUG("max-elements-stmt -> MIN-ELEMENTS integer ;");} ; value_stmt : K_VALUE integer_value_str stmtend - { if (ysp_add(_yy, Y_VALUE, $2, NULL) == NULL) _YYERROR("value_stmt"); + { if (ysp_add(_yy, Y_VALUE, $2, NULL) == NULL) _YYERROR("value_stmt"); _PARSE_DEBUG("value-stmt -> VALUE integer-value"); } ; @@ -1031,16 +1034,16 @@ value_stmt : K_VALUE integer_value_str stmtend grouping_stmt : K_GROUPING identifier_str ';' { if (ysp_add(_yy, Y_GROUPING, $2, NULL) == NULL) _YYERROR("grouping_stmt"); _PARSE_DEBUG("grouping-stmt -> GROUPING id-arg-str ;"); } - | K_GROUPING identifier_str + | K_GROUPING identifier_str { if (ysp_add_push(_yy, Y_GROUPING, $2, NULL) == NULL) _YYERROR("grouping_stmt"); } - '{' grouping_substmts '}' + '{' grouping_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("grouping_stmt"); _PARSE_DEBUG("grouping-stmt -> GROUPING id-arg-str { grouping-substmts }"); } ; -grouping_substmts : grouping_substmts grouping_substmt +grouping_substmts : grouping_substmts grouping_substmt { _PARSE_DEBUG("grouping-substmts -> grouping-substmts grouping-substmt"); } - | grouping_substmt + | grouping_substmt { _PARSE_DEBUG("grouping-substmts -> grouping-substmt"); } ; @@ -1052,24 +1055,24 @@ grouping_substmt : status_stmt { _PARSE_DEBUG("grouping-substmt -> status- | data_def_stmt { _PARSE_DEBUG("grouping-substmt -> data-def-stmt"); } | action_stmt { _PARSE_DEBUG("grouping-substmt -> action-stmt"); } | notification_stmt { _PARSE_DEBUG("grouping-substmt -> notification-stmt"); } - | unknown_stmt { _PARSE_DEBUG("container-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("container-substmt -> unknown-stmt");} | { _PARSE_DEBUG("grouping-substmt -> "); } ; /* container */ container_stmt : K_CONTAINER identifier_str ';' - { if (ysp_add(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt"); + { if (ysp_add(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt"); _PARSE_DEBUG("container-stmt -> CONTAINER id-arg-str ;");} - | K_CONTAINER identifier_str + | K_CONTAINER identifier_str { if (ysp_add_push(_yy, Y_CONTAINER, $2, NULL) == NULL) _YYERROR("container_stmt"); } '{' container_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("container_stmt"); _PARSE_DEBUG("container-stmt -> CONTAINER id-arg-str { container-substmts }");} ; -container_substmts : container_substmts container_substmt - | container_substmt +container_substmts : container_substmts container_substmt + | container_substmt ; container_substmt : when_stmt { _PARSE_DEBUG("container-substmt -> when-stmt"); } @@ -1078,23 +1081,23 @@ container_substmt : when_stmt { _PARSE_DEBUG("container-substmt -> when-st | presence_stmt { _PARSE_DEBUG("container-substmt -> presence-stmt"); } | config_stmt { _PARSE_DEBUG("container-substmt -> config-stmt"); } | status_stmt { _PARSE_DEBUG("container-substmt -> status-stmt"); } - | description_stmt { _PARSE_DEBUG("container-substmt -> description-stmt");} + | description_stmt { _PARSE_DEBUG("container-substmt -> description-stmt");} | reference_stmt { _PARSE_DEBUG("container-substmt -> reference-stmt"); } | typedef_stmt { _PARSE_DEBUG("container-substmt -> typedef-stmt"); } | grouping_stmt { _PARSE_DEBUG("container-substmt -> grouping-stmt"); } | data_def_stmt { _PARSE_DEBUG("container-substmt -> data-def-stmt");} - | action_stmt { _PARSE_DEBUG("container-substmt -> action-stmt");} - | notification_stmt { _PARSE_DEBUG("container-substmt -> notification-stmt");} - | unknown_stmt { _PARSE_DEBUG("container-substmt -> unknown-stmt");} - | { _PARSE_DEBUG("container-substmt ->");} + | action_stmt { _PARSE_DEBUG("container-substmt -> action-stmt");} + | notification_stmt { _PARSE_DEBUG("container-substmt -> notification-stmt");} + | unknown_stmt { _PARSE_DEBUG("container-substmt -> unknown-stmt");} + | { _PARSE_DEBUG("container-substmt ->");} ; leaf_stmt : K_LEAF identifier_str ';' - { if (ysp_add(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt"); + { if (ysp_add(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt"); _PARSE_DEBUG("leaf-stmt -> LEAF id-arg-str ;");} - | K_LEAF identifier_str + | K_LEAF identifier_str { if (ysp_add_push(_yy, Y_LEAF, $2, NULL) == NULL) _YYERROR("leaf_stmt"); } - '{' leaf_substmts '}' + '{' leaf_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("leaf_stmt"); _PARSE_DEBUG("leaf-stmt -> LEAF id-arg-str { lead-substmts }");} ; @@ -1114,13 +1117,13 @@ leaf_substmt : when_stmt { _PARSE_DEBUG("leaf-substmt -> when-stmt") | status_stmt { _PARSE_DEBUG("leaf-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("leaf-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("leaf-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("leaf-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("leaf-substmt -> unknown-stmt");} | { _PARSE_DEBUG("leaf-substmt ->"); } ; /* leaf-list */ leaf_list_stmt : K_LEAF_LIST identifier_str ';' - { if (ysp_add(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt"); + { if (ysp_add(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt"); _PARSE_DEBUG("leaf-list-stmt -> LEAF id-arg-str ;");} | K_LEAF_LIST identifier_str { if (ysp_add_push(_yy, Y_LEAF_LIST, $2, NULL) == NULL) _YYERROR("leaf_list_stmt"); } @@ -1133,7 +1136,7 @@ leaf_list_substmts : leaf_list_substmts leaf_list_substmt | leaf_list_substmt ; -leaf_list_substmt : when_stmt { _PARSE_DEBUG("leaf-list-substmt -> when-stmt"); } +leaf_list_substmt : when_stmt { _PARSE_DEBUG("leaf-list-substmt -> when-stmt"); } | if_feature_stmt { _PARSE_DEBUG("leaf-list-substmt -> if-feature-stmt"); } | type_stmt { _PARSE_DEBUG("leaf-list-substmt -> type-stmt"); } | units_stmt { _PARSE_DEBUG("leaf-list-substmt -> units-stmt"); } @@ -1146,23 +1149,23 @@ leaf_list_substmt : when_stmt { _PARSE_DEBUG("leaf-list-substmt -> when-s | status_stmt { _PARSE_DEBUG("leaf-list-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("leaf-list-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("leaf-list-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("leaf-list-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("leaf-list-substmt -> unknown-stmt");} | { _PARSE_DEBUG("leaf-list-stmt ->"); } ; -list_stmt : K_LIST identifier_str ';' - { if (ysp_add(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt"); +list_stmt : K_LIST identifier_str ';' + { if (ysp_add(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt"); _PARSE_DEBUG("list-stmt -> LIST id-arg-str ;"); } - | K_LIST identifier_str + | K_LIST identifier_str { if (ysp_add_push(_yy, Y_LIST, $2, NULL) == NULL) _YYERROR("list_stmt"); } - '{' list_substmts '}' + '{' list_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("list_stmt"); _PARSE_DEBUG("list-stmt -> LIST id-arg-str { list-substmts }"); } ; -list_substmts : list_substmts list_substmt +list_substmts : list_substmts list_substmt { _PARSE_DEBUG("list-substmts -> list-substmts list-substmt"); } - | list_substmt + | list_substmt { _PARSE_DEBUG("list-substmts -> list-substmt"); } ; @@ -1183,40 +1186,40 @@ list_substmt : when_stmt { _PARSE_DEBUG("list-substmt -> when-stmt") | data_def_stmt { _PARSE_DEBUG("list-substmt -> data-def-stmt"); } | action_stmt { _PARSE_DEBUG("list-substmt -> action-stmt"); } | notification_stmt { _PARSE_DEBUG("list-substmt -> notification-stmt"); } - | unknown_stmt { _PARSE_DEBUG("list-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("list-substmt -> unknown-stmt");} | { _PARSE_DEBUG("list-substmt -> "); } ; /* key-stmt = key-keyword sep key-arg-str */ key_stmt : K_KEY string stmtend - { if (ysp_add(_yy, Y_KEY, $2, NULL)== NULL) _YYERROR("key_stmt"); + { if (ysp_add(_yy, Y_KEY, $2, NULL)== NULL) _YYERROR("key_stmt"); _PARSE_DEBUG("key-stmt -> KEY id-arg-str ;");} ; /* unique-stmt = unique-keyword unique-arg-str */ unique_stmt : K_UNIQUE string stmtend - { if (ysp_add(_yy, Y_UNIQUE, $2, NULL)== NULL) _YYERROR("unique_stmt"); + { if (ysp_add(_yy, Y_UNIQUE, $2, NULL)== NULL) _YYERROR("unique_stmt"); _PARSE_DEBUG("key-stmt -> KEY id-arg-str ;");} ; /* choice */ -choice_stmt : K_CHOICE identifier_str ';' - { if (ysp_add(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt"); +choice_stmt : K_CHOICE identifier_str ';' + { if (ysp_add(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt"); _PARSE_DEBUG("choice-stmt -> CHOICE id-arg-str ;"); } | K_CHOICE identifier_str { if (ysp_add_push(_yy, Y_CHOICE, $2, NULL) == NULL) _YYERROR("choice_stmt"); } - '{' choice_substmts '}' + '{' choice_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("choice_stmt"); _PARSE_DEBUG("choice-stmt -> CHOICE id-arg-str { choice-substmts }"); } ; -choice_substmts : choice_substmts choice_substmt +choice_substmts : choice_substmts choice_substmt { _PARSE_DEBUG("choice-substmts -> choice-substmts choice-substmt"); } - | choice_substmt + | choice_substmt { _PARSE_DEBUG("choice-substmts -> choice-substmt"); } ; -choice_substmt : when_stmt { _PARSE_DEBUG("choice-substmt -> when-stmt"); } +choice_substmt : when_stmt { _PARSE_DEBUG("choice-substmt -> when-stmt"); } | if_feature_stmt { _PARSE_DEBUG("choice-substmt -> if-feature-stmt"); } | default_stmt { _PARSE_DEBUG("choice-substmt -> default-stmt"); } | config_stmt { _PARSE_DEBUG("choice-substmt -> config-stmt"); } @@ -1224,26 +1227,26 @@ choice_substmt : when_stmt { _PARSE_DEBUG("choice-substmt -> when-stmt | status_stmt { _PARSE_DEBUG("choice-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("choice-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("choice-substmt -> reference-stmt"); } - | short_case_stmt { _PARSE_DEBUG("choice-substmt -> short-case-stmt");} - | case_stmt { _PARSE_DEBUG("choice-substmt -> case-stmt");} - | unknown_stmt { _PARSE_DEBUG("choice-substmt -> unknown-stmt");} + | short_case_stmt { _PARSE_DEBUG("choice-substmt -> short-case-stmt");} + | case_stmt { _PARSE_DEBUG("choice-substmt -> case-stmt");} + | unknown_stmt { _PARSE_DEBUG("choice-substmt -> unknown-stmt");} | { _PARSE_DEBUG("choice-substmt -> "); } ; /* case */ -case_stmt : K_CASE identifier_str ';' - { if (ysp_add(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt"); +case_stmt : K_CASE identifier_str ';' + { if (ysp_add(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt"); _PARSE_DEBUG("case-stmt -> CASE id-arg-str ;"); } - | K_CASE identifier_str + | K_CASE identifier_str { if (ysp_add_push(_yy, Y_CASE, $2, NULL) == NULL) _YYERROR("case_stmt"); } - '{' case_substmts '}' + '{' case_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("case_stmt"); _PARSE_DEBUG("case-stmt -> CASE id-arg-str { case-substmts }"); } ; -case_substmts : case_substmts case_substmt +case_substmts : case_substmts case_substmt { _PARSE_DEBUG("case-substmts -> case-substmts case-substmt"); } - | case_substmt + | case_substmt { _PARSE_DEBUG("case-substmts -> case-substmt"); } ; @@ -1252,35 +1255,35 @@ case_substmt : when_stmt { _PARSE_DEBUG("case-substmt -> when-stmt") | status_stmt { _PARSE_DEBUG("case-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("case-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("case-substmt -> reference-stmt"); } - | data_def_stmt { _PARSE_DEBUG("case-substmt -> data-def-stmt");} - | unknown_stmt { _PARSE_DEBUG("case-substmt -> unknown-stmt");} + | data_def_stmt { _PARSE_DEBUG("case-substmt -> data-def-stmt");} + | unknown_stmt { _PARSE_DEBUG("case-substmt -> unknown-stmt");} | { _PARSE_DEBUG("case-substmt -> "); } ; -anydata_stmt : K_ANYDATA identifier_str ';' - { if (ysp_add(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt"); +anydata_stmt : K_ANYDATA identifier_str ';' + { if (ysp_add(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt"); _PARSE_DEBUG("anydata-stmt -> ANYDATA id-arg-str ;"); } | K_ANYDATA identifier_str { if (ysp_add_push(_yy, Y_ANYDATA, $2, NULL) == NULL) _YYERROR("anydata_stmt"); } - '{' anyxml_substmts '}' + '{' anyxml_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("anydata_stmt"); _PARSE_DEBUG("anydata-stmt -> ANYDATA id-arg-str { anyxml-substmts }"); } ; /* anyxml */ -anyxml_stmt : K_ANYXML identifier_str ';' - { if (ysp_add(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt"); +anyxml_stmt : K_ANYXML identifier_str ';' + { if (ysp_add(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt"); _PARSE_DEBUG("anyxml-stmt -> ANYXML id-arg-str ;"); } | K_ANYXML identifier_str { if (ysp_add_push(_yy, Y_ANYXML, $2, NULL) == NULL) _YYERROR("anyxml_stmt"); } - '{' anyxml_substmts '}' + '{' anyxml_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("anyxml_stmt"); _PARSE_DEBUG("anyxml-stmt -> ANYXML id-arg-str { anyxml-substmts }"); } ; -anyxml_substmts : anyxml_substmts anyxml_substmt +anyxml_substmts : anyxml_substmts anyxml_substmt { _PARSE_DEBUG("anyxml-substmts -> anyxml-substmts anyxml-substmt"); } - | anyxml_substmt + | anyxml_substmt { _PARSE_DEBUG("anyxml-substmts -> anyxml-substmt"); } ; @@ -1294,23 +1297,23 @@ anyxml_substmt : when_stmt { _PARSE_DEBUG("anyxml-substmt -> when-stmt | reference_stmt { _PARSE_DEBUG("anyxml-substmt -> reference-stmt"); } | ustring ':' ustring ';' { free($1); free($3); _PARSE_DEBUG("anyxml-substmt -> anyxml extension"); } - | unknown_stmt { _PARSE_DEBUG("anyxml-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("anyxml-substmt -> unknown-stmt");} ; /* uses-stmt = uses-keyword identifier-ref-arg-str */ -uses_stmt : K_USES identifier_ref_arg_str ';' - { if (ysp_add(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt"); +uses_stmt : K_USES identifier_ref_arg_str ';' + { if (ysp_add(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt"); _PARSE_DEBUG("uses-stmt -> USES identifier-ref-arg-str ;"); } | K_USES identifier_ref_arg_str { if (ysp_add_push(_yy, Y_USES, $2, NULL) == NULL) _YYERROR("uses_stmt"); } - '{' uses_substmts '}' + '{' uses_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("uses_stmt"); _PARSE_DEBUG("uses-stmt -> USES identifier-ref-arg-str { uses-substmts }"); } ; -uses_substmts : uses_substmts uses_substmt +uses_substmts : uses_substmts uses_substmt { _PARSE_DEBUG("uses-substmts -> uses-substmts uses-substmt"); } - | uses_substmt + | uses_substmt { _PARSE_DEBUG("uses-substmts -> uses-substmt"); } ; @@ -1321,24 +1324,24 @@ uses_substmt : when_stmt { _PARSE_DEBUG("uses-substmt -> when-stmt") | reference_stmt { _PARSE_DEBUG("uses-substmt -> reference-stmt"); } | refine_stmt { _PARSE_DEBUG("uses-substmt -> refine-stmt"); } | uses_augment_stmt { _PARSE_DEBUG("uses-substmt -> uses-augment-stmt"); } - | unknown_stmt { _PARSE_DEBUG("uses-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("uses-substmt -> unknown-stmt");} | { _PARSE_DEBUG("uses-substmt -> "); } ; /* refine-stmt = refine-keyword sep refine-arg-str */ -refine_stmt : K_REFINE refine_arg_str ';' - { if (ysp_add(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt"); +refine_stmt : K_REFINE refine_arg_str ';' + { if (ysp_add(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt"); _PARSE_DEBUG("refine-stmt -> REFINE id-arg-str ;"); } - | K_REFINE refine_arg_str '{' + | K_REFINE refine_arg_str '{' { if (ysp_add_push(_yy, Y_REFINE, $2, NULL) == NULL) _YYERROR("refine_stmt"); } - refine_substmts '}' + refine_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("refine_stmt"); _PARSE_DEBUG("refine-stmt -> REFINE id-arg-str { refine-substmts }"); } ; -refine_substmts : refine_substmts refine_substmt +refine_substmts : refine_substmts refine_substmt { _PARSE_DEBUG("refine-substmts -> refine-substmts refine-substmt"); } - | refine_substmt + | refine_substmt { _PARSE_DEBUG("refine-substmts -> refine-substmt"); } ; @@ -1352,7 +1355,7 @@ refine_substmt : if_feature_stmt { _PARSE_DEBUG("refine-substmt -> if-feature- | max_elements_stmt { _PARSE_DEBUG("refine-substmt -> max-elements-stmt"); } | description_stmt { _PARSE_DEBUG("refine-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("refine-substmt -> reference-stmt"); } - | unknown_stmt { _PARSE_DEBUG("refine-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("refine-substmt -> unknown-stmt");} | { _PARSE_DEBUG("refine-substmt -> "); } ; @@ -1367,39 +1370,39 @@ refine_arg_str : string /* uses-augment-stmt = augment-keyword uses-augment-arg-str * Same keyword as in augment-stmt, but here is sub of uses */ -uses_augment_stmt : K_AUGMENT uses_augment_arg_str +uses_augment_stmt : K_AUGMENT uses_augment_arg_str { if (ysp_add_push(_yy, Y_AUGMENT, $2, NULL) == NULL) _YYERROR("uses_augment_stmt"); } '{' augment_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("uses_augment_stmt"); _PARSE_DEBUG("uses-augment-stmt -> AUGMENT uses-augment-arg-str { augment-substmts }"); } - + /* augment-stmt = augment-keyword sep augment-arg-str * augment_stmt : K_AUGMENT abs_schema_nodeid_strs * Same keyword as in uses-augment-stmt, but here is sub of (sub)module */ -augment_stmt : K_AUGMENT augment_arg_str +augment_stmt : K_AUGMENT augment_arg_str { if (ysp_add_push(_yy, Y_AUGMENT, $2, NULL) == NULL) _YYERROR("augment_stmt"); } - '{' augment_substmts '}' + '{' augment_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("augment_stmt"); _PARSE_DEBUG("augment-stmt -> AUGMENT abs-schema-node-str { augment-substmts }"); } ; -augment_substmts : augment_substmts augment_substmt +augment_substmts : augment_substmts augment_substmt { _PARSE_DEBUG("augment-substmts -> augment-substmts augment-substmt"); } - | augment_substmt + | augment_substmt { _PARSE_DEBUG("augment-substmts -> augment-substmt"); } ; -augment_substmt : when_stmt { _PARSE_DEBUG("augment-substmt -> when-stmt"); } +augment_substmt : when_stmt { _PARSE_DEBUG("augment-substmt -> when-stmt"); } | if_feature_stmt { _PARSE_DEBUG("augment-substmt -> if-feature-stmt"); } | status_stmt { _PARSE_DEBUG("augment-substmt -> status-stmt"); } | description_stmt { _PARSE_DEBUG("augment-substmt -> description-stmt"); } | reference_stmt { _PARSE_DEBUG("augment-substmt -> reference-stmt"); } | data_def_stmt { _PARSE_DEBUG("augment-substmt -> data-def-stmt"); } | case_stmt { _PARSE_DEBUG("augment-substmt -> case-stmt");} - | action_stmt { _PARSE_DEBUG("augment-substmt -> action-stmt");} - | notification_stmt { _PARSE_DEBUG("augment-substmt -> notification-stmt");} - | unknown_stmt { _PARSE_DEBUG("augment-substmt -> unknown-stmt");} + | action_stmt { _PARSE_DEBUG("augment-substmt -> action-stmt");} + | notification_stmt { _PARSE_DEBUG("augment-substmt -> notification-stmt");} + | unknown_stmt { _PARSE_DEBUG("augment-substmt -> unknown-stmt");} | { _PARSE_DEBUG("augment-substmt -> "); } ; @@ -1420,19 +1423,19 @@ uses_augment_arg_str : string ; /* when */ -when_stmt : K_WHEN string ';' - { if (ysp_add(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt"); +when_stmt : K_WHEN string ';' + { if (ysp_add(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt"); _PARSE_DEBUG("when-stmt -> WHEN string ;"); } | K_WHEN string { if (ysp_add_push(_yy, Y_WHEN, $2, NULL) == NULL) _YYERROR("when_stmt"); } - '{' when_substmts '}' + '{' when_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("when_stmt"); _PARSE_DEBUG("when-stmt -> WHEN string { when-substmts }"); } ; -when_substmts : when_substmts when_substmt +when_substmts : when_substmts when_substmt { _PARSE_DEBUG("when-substmts -> when-substmts when-substmt"); } - | when_substmt + | when_substmt { _PARSE_DEBUG("when-substmts -> when-substmt"); } ; @@ -1442,19 +1445,19 @@ when_substmt : description_stmt { _PARSE_DEBUG("when-substmt -> description-stm ; /* rpc */ -rpc_stmt : K_RPC identifier_str ';' - { if (ysp_add(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt"); +rpc_stmt : K_RPC identifier_str ';' + { if (ysp_add(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt"); _PARSE_DEBUG("rpc-stmt -> RPC id-arg-str ;"); } | K_RPC identifier_str { if (ysp_add_push(_yy, Y_RPC, $2, NULL) == NULL) _YYERROR("rpc_stmt"); } - '{' rpc_substmts '}' + '{' rpc_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("rpc_stmt"); _PARSE_DEBUG("rpc-stmt -> RPC id-arg-str { rpc-substmts }"); } ; -rpc_substmts : rpc_substmts rpc_substmt +rpc_substmts : rpc_substmts rpc_substmt { _PARSE_DEBUG("rpc-substmts -> rpc-substmts rpc-substmt"); } - | rpc_substmt + | rpc_substmt { _PARSE_DEBUG("rpc-substmts -> rpc-substmt"); } ; @@ -1466,35 +1469,35 @@ rpc_substmt : if_feature_stmt { _PARSE_DEBUG("rpc-substmt -> if-feature-stmt" | grouping_stmt { _PARSE_DEBUG("rpc-substmt -> grouping-stmt"); } | input_stmt { _PARSE_DEBUG("rpc-substmt -> input-stmt"); } | output_stmt { _PARSE_DEBUG("rpc-substmt -> output-stmt"); } - | unknown_stmt { _PARSE_DEBUG("rpc-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("rpc-substmt -> unknown-stmt");} | { _PARSE_DEBUG("rpc-substmt -> "); } ; /* action */ -action_stmt : K_ACTION identifier_str ';' - { if (ysp_add(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt"); +action_stmt : K_ACTION identifier_str ';' + { if (ysp_add(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt"); _PARSE_DEBUG("action-stmt -> ACTION id-arg-str ;"); } | K_ACTION identifier_str { if (ysp_add_push(_yy, Y_ACTION, $2, NULL) == NULL) _YYERROR("action_stmt"); } - '{' rpc_substmts '}' + '{' rpc_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("action_stmt"); _PARSE_DEBUG("action-stmt -> ACTION id-arg-str { rpc-substmts }"); } ; /* notification */ -notification_stmt : K_NOTIFICATION identifier_str ';' - { if (ysp_add(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt"); +notification_stmt : K_NOTIFICATION identifier_str ';' + { if (ysp_add(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt"); _PARSE_DEBUG("notification-stmt -> NOTIFICATION id-arg-str ;"); } | K_NOTIFICATION identifier_str { if (ysp_add_push(_yy, Y_NOTIFICATION, $2, NULL) == NULL) _YYERROR("notification_stmt"); } - '{' notification_substmts '}' + '{' notification_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("notification_stmt"); _PARSE_DEBUG("notification-stmt -> NOTIFICATION id-arg-str { notification-substmts }"); } ; -notification_substmts : notification_substmts notification_substmt +notification_substmts : notification_substmts notification_substmt { _PARSE_DEBUG("notification-substmts -> notification-substmts notification-substmt"); } - | notification_substmt + | notification_substmt { _PARSE_DEBUG("notification-substmts -> notification-substmt"); } ; @@ -1506,20 +1509,20 @@ notification_substmt : if_feature_stmt { _PARSE_DEBUG("notification-substmt -> | typedef_stmt { _PARSE_DEBUG("notification-substmt -> typedef-stmt"); } | grouping_stmt { _PARSE_DEBUG("notification-substmt -> grouping-stmt"); } | data_def_stmt { _PARSE_DEBUG("notification-substmt -> data-def-stmt"); } - | unknown_stmt { _PARSE_DEBUG("notification-substmt -> unknown-stmt");} + | unknown_stmt { _PARSE_DEBUG("notification-substmt -> unknown-stmt");} | { _PARSE_DEBUG("notification-substmt -> "); } ; deviation_stmt : K_DEVIATION string { if (ysp_add_push(_yy, Y_DEVIATION, $2, NULL) == NULL) _YYERROR("deviation_stmt"); } - '{' deviation_substmts '}' + '{' deviation_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("deviation_stmt"); _PARSE_DEBUG("deviation-stmt -> DEVIATION id-arg-str { notification-substmts }"); } ; -deviation_substmts : deviation_substmts deviation_substmt +deviation_substmts : deviation_substmts deviation_substmt { _PARSE_DEBUG("deviation-substmts -> deviation-substmts deviation-substmt"); } - | deviation_substmt + | deviation_substmt { _PARSE_DEBUG("deviation-substmts -> deviation-substmt"); } ; @@ -1542,7 +1545,7 @@ deviate_not_supported_stmt _PARSE_DEBUG("deviate-not-supported-stmt -> DEVIATE not-supported ;"); } ; -add_keyword_str : D_ADD +add_keyword_str : D_ADD | '"' D_ADD '"' | '\'' D_ADD '\'' ; @@ -1552,16 +1555,17 @@ deviate_add_stmt : K_DEVIATE add_keyword_str ';' _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add ;"); } | K_DEVIATE add_keyword_str { if (ysp_add_push(_yy, Y_DEVIATE, strdup("add"), NULL) == NULL) _YYERROR("deviate_stmt"); } - '{' deviate_add_substmts '}' + '{' deviate_add_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt"); _PARSE_DEBUG("deviate-add-stmt -> DEVIATE add { deviate-substmts }"); } ; -deviate_add_substmts : deviate_add_substmts deviate_add_substmt +deviate_add_substmts : deviate_add_substmts deviate_add_substmt { _PARSE_DEBUG("deviate-add-substmts -> deviate-add-substmts deviate-add-substmt"); } - | deviate_add_substmt + | deviate_add_substmt { _PARSE_DEBUG("deviate-add-substmts -> deviate-add-substmt"); } ; + deviate_add_substmt : units_stmt { _PARSE_DEBUG("deviate-add-substmt -> units-stmt"); } | must_stmt { _PARSE_DEBUG("deviate-add-substmt -> must-stmt"); } | unique_stmt { _PARSE_DEBUG("deviate-add-substmt -> unique-stmt"); } @@ -1573,8 +1577,7 @@ deviate_add_substmt : units_stmt { _PARSE_DEBUG("deviate-add-substmt -> units | { _PARSE_DEBUG("deviate-add-substmt -> "); } ; - -delete_keyword_str : D_DELETE +delete_keyword_str : D_DELETE | '"' D_DELETE '"' | '\'' D_DELETE '\'' ; @@ -1584,14 +1587,14 @@ deviate_delete_stmt : K_DEVIATE delete_keyword_str ';' _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE delete ;"); } | K_DEVIATE delete_keyword_str { if (ysp_add_push(_yy, Y_DEVIATE, strdup("delete"), NULL) == NULL) _YYERROR("deviate_stmt"); } - '{' deviate_delete_substmts '}' + '{' deviate_delete_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt"); _PARSE_DEBUG("deviate-delete-stmt -> DEVIATE delete { deviate-delete-substmts }"); } ; -deviate_delete_substmts : deviate_delete_substmts deviate_delete_substmt +deviate_delete_substmts : deviate_delete_substmts deviate_delete_substmt { _PARSE_DEBUG("deviate-delete-substmts -> deviate-delete-substmts deviate-delete-substmt"); } - | deviate_delete_substmt + | deviate_delete_substmt { _PARSE_DEBUG("deviate-delete-substmts -> deviate-delete-substmt"); } ; deviate_delete_substmt : units_stmt { _PARSE_DEBUG("deviate-delete-substmt -> units-stmt"); } @@ -1601,7 +1604,7 @@ deviate_delete_substmt : units_stmt { _PARSE_DEBUG("deviate-delete-substmt -> un | { _PARSE_DEBUG("deviate-delete-substmt -> "); } ; -replace_keyword_str : D_REPLACE +replace_keyword_str : D_REPLACE | '"' D_REPLACE '"' | '\'' D_REPLACE '\'' ; @@ -1611,16 +1614,17 @@ deviate_replace_stmt : K_DEVIATE replace_keyword_str ';' _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE replace ;"); } | K_DEVIATE replace_keyword_str { if (ysp_add_push(_yy, Y_DEVIATE, strdup("replace"), NULL) == NULL) _YYERROR("deviate_stmt"); } - '{' deviate_replace_substmts '}' + '{' deviate_replace_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("deviate_stmt"); _PARSE_DEBUG("deviate-replace-stmt -> DEVIATE replace { deviate-replace-substmts }"); } ; -deviate_replace_substmts : deviate_replace_substmts deviate_replace_substmt +deviate_replace_substmts : deviate_replace_substmts deviate_replace_substmt { _PARSE_DEBUG("deviate-replace-substmts -> deviate-replace-substmts deviate-replace-substmt"); } - | deviate_replace_substmt + | deviate_replace_substmt { _PARSE_DEBUG("deviate-replace-substmts -> deviate-replace-substmt"); } ; + deviate_replace_substmt : type_stmt { _PARSE_DEBUG("deviate-replace-substmt -> type-stmt"); } | units_stmt { _PARSE_DEBUG("deviate-replace-substmt -> units-stmt"); } | default_stmt { _PARSE_DEBUG("deviate-replace-substmt -> default-stmt"); } @@ -1644,7 +1648,7 @@ unknown_stmt : ustring ':' ustring optsep ';' char *id; if ((id=clixon_string_del_join($1, ":", $3)) == NULL) _YYERROR("unknown_stmt"); free($3); - if (ysp_add(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("unknown_stmt"); + if (ysp_add(_yy, Y_UNKNOWN, id, NULL) == NULL) _YYERROR("unknown_stmt"); _PARSE_DEBUG("unknown-stmt -> ustring : ustring ;"); } | ustring ':' ustring sep string optsep ';' @@ -1675,9 +1679,9 @@ unknown_stmt : ustring ':' ustring optsep ';' _PARSE_DEBUG("unknown-stmt -> ustring : ustring string { yang-stmts }"); } ; -unknown_substmts : unknown_substmts unknown_substmt +unknown_substmts : unknown_substmts unknown_substmt { _PARSE_DEBUG("unknown-substmts -> unknown-substmts unknown-substmt"); } - | unknown_substmt + | unknown_substmt { _PARSE_DEBUG("unknown-substmts -> unknown-substmt"); } ; @@ -1759,7 +1763,7 @@ yang_stmt : action_stmt { _PARSE_DEBUG("yang-stmt -> action-stmt"); ; /* body */ -body_stmts : body_stmts body_stmt { _PARSE_DEBUG("body-stmts -> body-stmts body-stmt"); } +body_stmts : body_stmts body_stmt { _PARSE_DEBUG("body-stmts -> body-stmts body-stmt"); } | body_stmt { _PARSE_DEBUG("body-stmts -> body-stmt");} ; @@ -1795,16 +1799,16 @@ short_case_stmt : container_stmt { _PARSE_DEBUG("short-case-substmt -> contain ; /* input */ -input_stmt : K_INPUT +input_stmt : K_INPUT { if (ysp_add_push(_yy, Y_INPUT, NULL, NULL) == NULL) _YYERROR("input_stmt"); } - '{' input_substmts '}' + '{' input_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("input_stmt"); _PARSE_DEBUG("input-stmt -> INPUT { input-substmts }"); } ; -input_substmts : input_substmts input_substmt +input_substmts : input_substmts input_substmt { _PARSE_DEBUG("input-substmts -> input-substmts input-substmt"); } - | input_substmt + | input_substmt { _PARSE_DEBUG("input-substmts -> input-substmt"); } ; @@ -1817,41 +1821,41 @@ input_substmt : typedef_stmt { _PARSE_DEBUG("input-substmt -> typedef-st /* output */ output_stmt : K_OUTPUT /* XXX reuse input-substatements since they are same */ { if (ysp_add_push(_yy, Y_OUTPUT, NULL, NULL) == NULL) _YYERROR("output_stmt"); } - '{' input_substmts '}' + '{' input_substmts '}' { if (ystack_pop(_yy) < 0) _YYERROR("output_stmt"); _PARSE_DEBUG("output-stmt -> OUTPUT { input-substmts }"); } ; -/* XXX this is not the "string" rule in Section 14, rather it is the string as described in 6.1 +/* XXX this is not the "string" rule in Section 14, rather it is the string as described in 6.1 */ string : qstrings { $$=$1; - _PARSE_DEBUG("string -> qstrings"); } + _PARSE_DEBUG("string -> qstrings"); } | ustring { $$=$1; - _PARSE_DEBUG( "string -> ustring"); } - ; + _PARSE_DEBUG( "string -> ustring"); } + ; /* quoted string */ qstrings : qstrings '+' qstring { int len = strlen($1); - $$ = realloc($1, len + strlen($3) + 1); + $$ = realloc($1, len + strlen($3) + 1); sprintf($$+len, "%s", $3); - free($3); - _PARSE_DEBUG("qstrings-> qstrings '+' qstring"); + free($3); + _PARSE_DEBUG("qstrings-> qstrings '+' qstring"); } - | qstring + | qstring { $$=$1; - _PARSE_DEBUG("qstrings-> qstring"); } + _PARSE_DEBUG("qstrings-> qstring"); } ; qstring : '"' ustring '"' { $$=$2; _PARSE_DEBUG("qstring-> \" ustring \"");} | '"' '"' { $$=strdup(""); - _PARSE_DEBUG("qstring-> \" \"");} + _PARSE_DEBUG("qstring-> \" \"");} | '\'' ustring '\'' { $$=$2; _PARSE_DEBUG("qstring-> ' ustring '"); } | '\'' '\'' { $$=strdup(""); - _PARSE_DEBUG("qstring-> ' '");} + _PARSE_DEBUG("qstring-> ' '");} ; /* unquoted string */ @@ -1859,13 +1863,13 @@ ustring : ustring CHARS { int len = strlen($1); $$ = realloc($1, len+strlen($2) + 1); - sprintf($$+len, "%s", $2); - _PARSE_DEBUG1("ustring-> string + CHARS(%s)", $2); + sprintf($$+len, "%s", $2); + _PARSE_DEBUG1("ustring-> string + CHARS(%s)", $2); free($2); } - | CHARS - { _PARSE_DEBUG1("ustring-> CHARS(%s)", $1); $$=$1; } - | ERRCHARS + | CHARS + { _PARSE_DEBUG1("ustring-> CHARS(%s)", $1); $$=$1; } + | ERRCHARS { _PARSE_DEBUG1("ustring-> ERRCHARS(%s)", $1); _YYERROR("Invalid string chars"); } ; diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index 6a15fba3..9b9d157c 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -135,7 +135,7 @@ ys_grouping_module_resolve(yang_stmt *ymod, while ((yinc = yn_each(yrealmod, yinc)) != NULL){ if (yang_keyword_get(yinc) != Y_INCLUDE) continue; - submname = yang_argument_get(yinc); + submname = yang_argument_get(yinc); if ((ysubm = yang_find_module_by_name(yspec, submname)) == NULL) continue; if (ysubm == ymod) @@ -157,8 +157,8 @@ ys_grouping_module_resolve(yang_stmt *ymod, * @retval -1 Error, with clicon_err called */ int -ys_grouping_resolve(yang_stmt *yuses, - char *prefix, +ys_grouping_resolve(yang_stmt *yuses, + char *prefix, char *name, yang_stmt **ygrouping0) { @@ -176,7 +176,7 @@ ys_grouping_resolve(yang_stmt *yuses, if ((ymod = yang_find_module_by_prefix(yuses, prefix)) != NULL) ygrouping = ys_grouping_module_resolve(ymod, yspec, name); } - else { + else { ys = yuses; /* Check upwards in hierarchy for matching groupings */ while (1){ if (ys->ys_mymodule){ @@ -206,6 +206,8 @@ ys_grouping_resolve(yang_stmt *yuses, * * @param[in] h Clicon handle * @param[in] ys The augment statement + * @retval 0 OK + * @retval -1 Error * @see RFC7950 Sec 7.17 * The target node MUST be either a container, list, choice, case, input, * output, or notification node. @@ -215,9 +217,9 @@ ys_grouping_resolve(yang_stmt *yuses, * elements in the XML namespace of the module where the "augment" is * specified. * - * @note If the augment has a when statement, which is commonplace, the when statement is not copied as - * datanodes are, since it should not apply to the target node. Instead it is added as a special "when" - * struct to the yang statements being inserted. + * @note If the augment has a when statement, which is commonplace, the when statement is not + * copied as datanodes are, since it should not apply to the target node. Instead it is added as + * a special "when" struct to the yang statements being inserted. */ static int yang_augment_node(clicon_handle h, @@ -240,14 +242,14 @@ yang_augment_node(clicon_handle h, goto done; } schema_nodeid = yang_argument_get(ys); - clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, schema_nodeid); + clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, schema_nodeid); /* Find the target */ if (yang_abs_schema_nodeid(ys, schema_nodeid, &ytarget) < 0) goto done; if (ytarget == NULL){ if (clicon_option_bool(h, "CLICON_YANG_AUGMENT_ACCEPT_BROKEN")){ - /* Log a warning and proceed if augment target not found + /* 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", @@ -262,7 +264,7 @@ yang_augment_node(clicon_handle h, clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found", yang_argument_get(ys_module(ys)), schema_nodeid); - goto done; + goto done; } } /* The target node MUST be either a container, list, choice, case, input, output, or notification node. @@ -316,7 +318,7 @@ yang_augment_node(clicon_handle h, notification node, the "container", "leaf", "list", "leaf-list", "uses", and "choice" statements can be used within the "augment" statement. */ - if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST && + 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", @@ -365,9 +367,9 @@ yang_augment_node(clicon_handle h, * see xml_yang_validate_all */ if (ywhen){ - if (yang_when_xpath_set(yc, wxpath) < 0) + if (yang_when_xpath_set(yc, wxpath) < 0) goto done; - if (yang_when_nsc_set(yc, wnsc) < 0) + if (yang_when_nsc_set(yc, wnsc) < 0) goto done; } /* Note: ys_populate2 called as a special case here since the inserted child is @@ -425,6 +427,8 @@ yang_augment_module(clicon_handle h, * Most nodes will be replaced, but some are added * @param[in] yr Refine node * @param[in] yt Refine target node (will be modified) + * @retval 0 OK + * @retval -1 Error * @see RFC7950 Sec 7.13.2 * There may be some missed cornercases */ @@ -438,7 +442,7 @@ ys_do_refine(yang_stmt *yr, yang_stmt *ytc; /* target child */ enum rfc_6020 keyw; int i; - + /* Loop through refine node children. First if remove do that first * In some cases remove a set of nodes. */ @@ -467,7 +471,7 @@ ys_do_refine(yang_stmt *yr, } /* fall through and add if not found */ case Y_MUST: /* keep old, add new */ - case Y_IF_FEATURE: + case Y_IF_FEATURE: break; default: break; @@ -493,8 +497,8 @@ ys_do_refine(yang_stmt *yr, * Could be made to a generic function used elsewhere as well * @param[in] y Yang leaf * @param[in] yp Yang list parent - * @retval 0 No, y is not a key leaf in list yp * @retval 1 Yes, y is a key leaf in list yp + * @retval 0 No, y is not a key leaf in list yp */ static int ys_iskey(yang_stmt *y, @@ -502,7 +506,7 @@ ys_iskey(yang_stmt *y, { cvec *cvv; cg_var *cv; - char *name; + char *name; if (yang_keyword_get(y) != Y_LEAF) return 0; @@ -547,14 +551,14 @@ yang_expand_uses_node(yang_stmt *yn, yang_stmt *ywhen; char *wxpath = NULL; /* xpath of when statement */ cvec *wnsc = NULL; /* namespace context of when statement */ - + /* Split argument into prefix and name */ if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0) goto done; 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\"", + clicon_log(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; } @@ -570,7 +574,7 @@ yang_expand_uses_node(yang_stmt *yn, goto done; } } while((yp = yang_parent_get(yp)) != NULL); - if (yang_flag_get(ygrouping, YANG_FLAG_GROUPING) == 0){ + if (yang_flag_get(ygrouping, YANG_FLAG_GROUPING) == 0){ /* Check mark flag to see if this grouping has been expanded before, * here below in the traverse section * A mark could be completely normal (several uses) or it could be a recursion. @@ -642,7 +646,7 @@ yang_expand_uses_node(yang_stmt *yn, &yrt) < 0) goto done; /* Not found, try next */ - if (yrt == NULL) + if (yrt == NULL) continue; /* Refine ANYDATA does not make sense */ if (yang_keyword_get(yrt) == Y_ANYDATA || yang_keyword_get(yrt) == Y_ANYXML) @@ -672,16 +676,15 @@ 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", yang_argument_get(yg), yang_argument_get(ygrouping) ); goto done; } - if (yang_when_xpath_set(yg, wxpath) < 0) + if (yang_when_xpath_set(yg, wxpath) < 0) goto done; - if (yang_when_nsc_set(yg, wnsc) < 0) + if (yang_when_nsc_set(yg, wnsc) < 0) goto done; } /* This is for extensions that allow list keys to be optional, see restconf_main_extension_cb */ @@ -700,9 +703,9 @@ yang_expand_uses_node(yang_stmt *yn, if (wnsc) cvec_free(wnsc); if (prefix) - free(prefix); + free(prefix); if (id) - free(id); + free(id); return retval; } @@ -730,7 +733,7 @@ yang_expand_grouping(yang_stmt *yn) /* Cannot use yang_apply here since child-list is modified (is destructive) */ i = 0; while (i < yang_len_get(yn)){ - ys = yn->ys_stmt[i]; + ys = yn->ys_stmt[i]; switch (yang_keyword_get(ys)){ case Y_USES: if (yang_flag_get(ys, YANG_FLAG_GROUPING) == 0){ @@ -738,7 +741,7 @@ yang_expand_grouping(yang_stmt *yn) goto done; yang_flag_set(ys, YANG_FLAG_GROUPING); } - break; + break; default: break; } @@ -816,9 +819,9 @@ yang_parse_str(char *str, goto done; } if (yang_parse_exit(&yy) < 0) - goto done; + goto done; if (yang_scan_exit(&yy) < 0) - goto done; + goto done; } if ((ymod = yy.yy_module) == NULL){ clicon_err(OE_YANG, 0, "No module in YANG %s", name); @@ -873,7 +876,7 @@ yang_parse_file(FILE *fp, if ((buf = realloc(buf, 2*len)) == NULL){ clicon_err(OE_XML, errno, "realloc"); goto done; - } + } memset(buf+len, 0, len); len *= 2; } @@ -892,6 +895,8 @@ yang_parse_file(FILE *fp, * @param[in] filename Filename on the form: name [+ @rev ] + .yang * @param[out] basep "Base" filename, stripped: [+ @rev ] + .yang (malloced) * @param[out] revp Revision as YYYYMMDD (0 if not found) + * @retval 0 OK + * @retval -1 Error */ static int filename2revision(const char *filename, @@ -901,13 +906,13 @@ filename2revision(const char *filename, int retval = -1; char *base = NULL; char *p; - + /* base = module name [+ @rev ] + .yang */ if ((base = strdup(filename)) == NULL){ clicon_err(OE_UNIX, errno, "strdup"); goto done; } - clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, base); + clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, base); if ((p = rindex(base, '.')) != NULL) /* strip postfix .yang */ *p = '\0'; if ((p = index(base, '@')) != NULL){ /* extract revision date */ @@ -938,10 +943,10 @@ 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(clicon_handle h, const char *module, const char *revision, - cbuf *fbuf) + cbuf *fbuf) { int retval = -1; cbuf *regex = NULL; @@ -977,8 +982,8 @@ yang_file_find_match(clicon_handle h, dir = xml_body(xc); /* get all matching files in this directory */ - if ((ndp = clicon_file_dirent(dir, - &dp, + if ((ndp = clicon_file_dirent(dir, + &dp, cbuf_get(regex), S_IFREG)) < 0) goto done; @@ -1051,20 +1056,20 @@ done: */ yang_stmt * yang_parse_filename(clicon_handle h, - const char *filename, + const char *filename, yang_stmt *yspec) { yang_stmt *ymod = NULL; FILE *fp = NULL; struct stat st; - clicon_debug(1, "%s %s", __FUNCTION__, filename); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename); if (stat(filename, &st) < 0){ clicon_err(OE_YANG, errno, "%s not found", filename); goto done; } if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_YANG, errno, "fopen(%s)", filename); + clicon_err(OE_YANG, errno, "fopen(%s)", filename); goto done; } if ((ymod = yang_parse_file(fp, filename, yspec)) < 0) @@ -1094,8 +1099,8 @@ yang_parse_filename(clicon_handle h, */ yang_stmt * yang_parse_module(clicon_handle h, - const char *module, - const char *revision, + const char *module, + const char *revision, yang_stmt *yspec, char *origname) { @@ -1134,7 +1139,7 @@ yang_parse_module(clicon_handle h, goto done; /* Sanity check that requested module name matches loaded module * If this does not match, the filename and containing module do not match - * RFC 7950 Sec 5.2 + * 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", @@ -1153,8 +1158,8 @@ yang_parse_module(clicon_handle h, if (filename2revision(filename, NULL, &revf) < 0) 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); + 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); ymod = NULL; goto done; } @@ -1236,7 +1241,7 @@ yang_parse_recurse(clicon_handle h, } } retval = 0; - done: + done: return retval; /* top-level (sub)module */ } @@ -1244,12 +1249,14 @@ yang_parse_recurse(clicon_handle h, * * @param[in] h Clicon handle * @param[in] ys Yang statement + * @retval 0 OK + * @retval -1 Error * Verify the following rule: * RFC 7950 7.8.2: The "key" statement, which MUST be present if the list represents * configuration and MAY be present otherwise * Unless it is the "errors" rule of the ietf-restconf spec which seems to be a special case. */ -static int +static int ys_list_check(clicon_handle h, yang_stmt *ys) { @@ -1258,7 +1265,7 @@ ys_list_check(clicon_handle h, yang_stmt *yc = NULL; enum rfc_6020 keyw; yang_stmt *yroot; - + /* This node is state, not config */ if (yang_config_ancestor(ys) == 0) goto ok; @@ -1266,7 +1273,6 @@ ys_list_check(clicon_handle h, if ((yroot = yang_myroot(ys)) != NULL && yang_keyword_get(yroot) == Y_RPC) goto ok; - keyw = yang_keyword_get(ys); /* Check if list and if keys do not exist */ if (keyw == Y_LIST && @@ -1275,7 +1281,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)", + clicon_log(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) ); @@ -1316,7 +1322,7 @@ ys_visit(struct yang_stmt *yn, struct yang_stmt *yi; /* import / include */ struct yang_stmt *yspec; struct yang_stmt *ymod; - + if (yn == NULL || (yang_keyword_get(yn) != Y_MODULE && yang_keyword_get(yn) != Y_SUBMODULE)){ clicon_err(OE_YANG, EINVAL, "Expected module or submodule"); @@ -1374,6 +1380,8 @@ ys_visit(struct yang_stmt *yn, * @param[in] modmax End of interval * @param[out] ylist Result list of sorted nodes with "least significant" first * @param[out] ylen Length of ylist + * @retval 0 OK + * @retval -1 Error * see eg https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search */ static int @@ -1435,7 +1443,7 @@ yang_parse_post(clicon_handle h, int modmax; struct yang_stmt **ylist = NULL; /* Topology sorted modules */ int ylen = 0; /* Length of ylist */ - + if (modmin < 0){ clicon_err(OE_YANG, EINVAL, "modmin negative"); goto done; @@ -1446,7 +1454,6 @@ yang_parse_post(clicon_handle h, for (i=modmin; iys_stmt[i])) < 0) goto done; - /* 3: Check features/if-features: check if enabled and remove disabled features */ - for (i=modmin; imounted yspec */ if ((cvv = yang_cvec_get(yu)) != NULL && (cv = cvec_find(cvv, xpath)) != NULL && @@ -167,7 +167,7 @@ yang_mount_get(yang_stmt *yu, * @param[in] xpath Key for yspec on yu, in canonical form * @param[in] yspec Yangspec for this mount-point (consumed) * @retval 0 OK - * @retval -1 Error + * @retval -1 Error */ int yang_mount_set(yang_stmt *yu, @@ -179,7 +179,7 @@ yang_mount_set(yang_stmt *yu, cvec *cvv; cg_var *cv; cg_var *cv2; - + if ((cvv = yang_cvec_get(yu)) != NULL && (cv = cvec_find(cvv, xpath)) != NULL && (yspec0 = cv_void_get(cv)) != NULL){ @@ -191,11 +191,11 @@ yang_mount_set(yang_stmt *yu, else if ((cv = yang_cvec_add(yu, CGV_VOID, xpath)) == NULL) goto done; if ((cv2 = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clicon_err(OE_YANG, errno, "cv_new"); goto done; } if (cv_string_set(cv2, xpath) == NULL){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clicon_err(OE_UNIX, errno, "cv_string_set"); goto done; } /* tag yspec with key/xpath */ @@ -225,9 +225,9 @@ xml_yang_mount_get(clicon_handle h, int retval = -1; yang_stmt *y; yang_stmt *yu; - char *xpath = NULL; // XXX free it + char *xpath = NULL; // XXX free it int ret; - + if ((y = xml_spec(xt)) == NULL) goto fail; if ((ret = yang_schema_mount_point(y)) < 0) @@ -271,7 +271,7 @@ xml_yang_mount_set(cxobj *x, yang_stmt *y; yang_stmt *yu; char *xpath = NULL; - + if ((y = xml_spec(x)) == NULL || (yu = yang_find(y, Y_UNKNOWN, "yangmnt:mount-point")) == NULL){ goto done; @@ -297,8 +297,8 @@ xml_yang_mount_freeall(cvec *cvv) { cg_var *cv = NULL; yang_stmt *ys; - - cv = NULL; + + cv = NULL; while ((cv = cvec_each(cvv, cv)) != NULL){ if ((ys = cv_void_get(cv)) != NULL) ys_free(ys); @@ -323,7 +323,7 @@ find_schema_mounts(cxobj *x, yang_stmt *y; cvec *cvv = (cvec *)arg; cg_var *cv; - + if ((y = xml_spec(x)) == NULL) return 2; if (yang_config(y) == 0) @@ -339,7 +339,7 @@ find_schema_mounts(cxobj *x, cv_void_set(cv, x); return 0; } - + /*! Find mount-points and return yang-library state * * Brute force: traverse whole XML, match all x that have ymount as yspec @@ -506,6 +506,10 @@ yang_schema_mount_statedata(clicon_handle h, } /*! Statistics about mountpoints + * + * @param[in] h Clixon handle + * @retval 0 OK + * @retval -1 Error * @see yang_schema_mount_statedata */ int diff --git a/lib/src/clixon_yang_schemanode_parse.l b/lib/src/clixon_yang_schemanode_parse.l index eab18699..2fd929d8 100644 --- a/lib/src/clixon_yang_schemanode_parse.l +++ b/lib/src/clixon_yang_schemanode_parse.l @@ -63,7 +63,7 @@ #define YY_NO_INPUT /* typecast macro */ -#define _IF ((clixon_yang_schemanode_yacc *)_if) +#define _IF ((clixon_yang_schemanode_yacc *)_if) #undef clixon_xml_parsewrap int clixon_yang_schemanode_parsewrap(void) diff --git a/lib/src/clixon_yang_schemanode_parse.y b/lib/src/clixon_yang_schemanode_parse.y index a530b978..f27d71c0 100644 --- a/lib/src/clixon_yang_schemanode_parse.y +++ b/lib/src/clixon_yang_schemanode_parse.y @@ -62,11 +62,11 @@ %{ /* Here starts user C-code */ - + /* typecast macro */ #define _IF ((clixon_yang_schemanode_yacc *)_if) #define _YYERROR(msg) {clicon_err(OE_YANG, 0, "%s", (msg)); YYERROR;} - + #include #include #include @@ -95,28 +95,28 @@ /* Enable for debugging, steals some cycles otherwise */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #else #define _PARSE_DEBUG(s) #endif - -void + +void clixon_yang_schemanode_parseerror(void *arg, - char *s) + char *s) { 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", - ife->if_mainfile, - ife->if_linenum, - ife->if_parse_string, - s, - clixon_yang_schemanode_parsetext); + clicon_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, + s, + clixon_yang_schemanode_parsetext); return; } -%} - +%} + %% /* See RFC 7950 Sec 14 refine-arg-str / usage-augment-arg-str */ @@ -127,7 +127,7 @@ top : descendant_schema_nodeid MY_EOF YYACCEPT; } else{ - _YYERROR("descendant-schema-nodeid unexpected"); + _YYERROR("descendant-schema-nodeid unexpected"); } } | absolute_schema_nodeid MY_EOF @@ -137,7 +137,7 @@ top : descendant_schema_nodeid MY_EOF YYACCEPT; } else{ - _YYERROR("absolute-schema-nodeid unexpected"); + _YYERROR("absolute-schema-nodeid unexpected"); } } ; @@ -154,11 +154,11 @@ descendant_schema_nodeid ; absolute_schema_nodeid - : absolute_schema_nodeid '/' node_identifier + : absolute_schema_nodeid '/' node_identifier { _PARSE_DEBUG("absolute-schema-nodeid->absolute-schema-nodeid '/' node-identifier"); } - | '/' node_identifier + | '/' node_identifier { _PARSE_DEBUG("absolute-schema-nodeid->'/' node-identifier"); } diff --git a/lib/src/clixon_yang_sub_parse.c b/lib/src/clixon_yang_sub_parse.c index d4f5e4e2..53f24322 100644 --- a/lib/src/clixon_yang_sub_parse.c +++ b/lib/src/clixon_yang_sub_parse.c @@ -81,7 +81,7 @@ yang_subparse(char *str, int retval = -1; clixon_yang_sub_parse_yacc ife = {0,}; - clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, str); + clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, str); ife.if_parse_string = str; ife.if_linenum = linenum; if (enabled) @@ -123,7 +123,7 @@ yang_schema_nodeid_subparse(char *str, int retval = -1; clixon_yang_schemanode_yacc ife = {0,}; - clicon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, str); + clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, str); ife.if_parse_string = str; ife.if_linenum = linenum; ife.if_mainfile = mainfile; diff --git a/lib/src/clixon_yang_sub_parse.h b/lib/src/clixon_yang_sub_parse.h index e778b711..46536610 100644 --- a/lib/src/clixon_yang_sub_parse.h +++ b/lib/src/clixon_yang_sub_parse.h @@ -54,7 +54,7 @@ struct clixon_yang_sub_parse_yacc { int if_linenum; /* Number of \n in parsed buffer (in mainfile) */ void *if_lexbuf; /* Internal parse buffer from lex */ yang_stmt *if_ys; /* Yang statement, NULL if no check */ - enum yang_sub_parse_accept if_accept; /* Which sub-parse rule to accept */ + 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; }; diff --git a/lib/src/clixon_yang_sub_parse.l b/lib/src/clixon_yang_sub_parse.l index 5d9b2adf..98655122 100644 --- a/lib/src/clixon_yang_sub_parse.l +++ b/lib/src/clixon_yang_sub_parse.l @@ -62,7 +62,7 @@ #define YY_NO_INPUT /* typecast macro */ -#define _IF ((clixon_yang_sub_parse_yacc *)_if) +#define _IF ((clixon_yang_sub_parse_yacc *)_if) #undef clixon_xml_parsewrap int clixon_yang_sub_parsewrap(void) diff --git a/lib/src/clixon_yang_sub_parse.y b/lib/src/clixon_yang_sub_parse.y index 6950aef5..45223596 100644 --- a/lib/src/clixon_yang_sub_parse.y +++ b/lib/src/clixon_yang_sub_parse.y @@ -77,7 +77,7 @@ /* typecast macro */ #define _IF ((clixon_yang_sub_parse_yacc *)_if) #define _YYERROR(msg) {clicon_err(OE_YANG, 0, "%s", (msg)); YYERROR;} - + #include #include #include @@ -105,29 +105,32 @@ /* Enable for debugging, steals some cycles otherwise */ #if 0 -#define _PARSE_DEBUG(s) clicon_debug(1,(s)) +#define _PARSE_DEBUG(s) clixon_debug(1,(s)) #else #define _PARSE_DEBUG(s) #endif - + void clixon_yang_sub_parseerror(void *arg, - char *s) + char *s) { 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", - ife->if_mainfile, - ife->if_linenum, - ife->if_parse_string, - s, - clixon_yang_sub_parsetext); + clicon_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, + s, + clixon_yang_sub_parsetext); return; } /*! Check if feature "str" is enabled or not in context of yang node ys + * * @param[in] str feature str. * @param[in] ys If-feature type yang node + * @retval 0 OK + * @retval -1 Error */ static int if_feature_check(clixon_yang_sub_parse_yacc *ife, @@ -140,7 +143,7 @@ if_feature_check(clixon_yang_sub_parse_yacc *ife, yang_stmt *yfeat; /* feature yang node */ cg_var *cv; yang_stmt *ys; - + if ((ys = ife->if_ys) == NULL) return 0; if (nodeid_split(str, &prefix, &feature) < 0) @@ -179,9 +182,9 @@ if_feature_check(clixon_yang_sub_parse_yacc *ife, free(feature); return retval; } - -%} - + +%} + %% /* See RFC 7950 Sec 14 if-feature-expr-str */ @@ -193,7 +196,7 @@ top : if_feature_expr MY_EOF YYACCEPT; } else{ - _YYERROR("Expected if-feature-expr"); + _YYERROR("Expected if-feature-expr"); } } ; diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index 0a206c20..eb7a4b55 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -103,7 +103,7 @@ #include "clixon_options.h" #include "clixon_yang_type.h" -/* +/* * Local types and variables */ @@ -134,6 +134,7 @@ static const map_str2int ytmap[] = { }; /*! Mapping from yang string types --> cligen types + * * @note not 100% same as map_str2int since it has significant order AND * string->CGV_REST entry removed */ @@ -170,6 +171,7 @@ yang_builtin(char *type) } /*! Compile yang patterns in string form to regex compiled void* form + * * 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. @@ -219,14 +221,17 @@ compile_pattern2regexp(clicon_handle h, return retval; } -/*! Resolve types: populate type caches - * @param[in] ys This is a type statement - * @param[in] arg Not used +/*! Resolve types: populate type caches + * + * @param[in] ys This is a type statement + * @param[in] arg Not used + * @retval 0 OK + * @retval -1 Error * Typically only called once when loading the yang type system. * @note unions not cached */ int -ys_resolve_type(yang_stmt *ys, +ys_resolve_type(yang_stmt *ys, void *arg) { // clicon_handle h = (clicon_handle)arg; @@ -278,7 +283,7 @@ ys_resolve_type(yang_stmt *ys, * Return 0 if no match but set cv_type to CGV_ERR */ int -yang2cv_type(char *ytype, +yang2cv_type(char *ytype, enum cv_type *cv_type) { int ret; @@ -331,6 +336,7 @@ cv2yang_type(enum cv_type cv_type) } /*! Translate from yang type -> cligen type, after yang resolve has been made. + * * handle case where yang resolve did not succedd (rtype=NULL) and then try * to find special cligen types such as ipv4addr. * not true yang types @@ -338,11 +344,13 @@ cv2yang_type(enum cv_type cv_type) * @param[in] restype Resolved type. May be null, in that case origtype is used * @param[in] ys Yang stmt of original resolving node * @param[out] cvtype Translation from resolved type + * @retval 0 OK + * @retval -1 Error * @note Thereis a kludge for handling direct translations of native cligen types */ int -clicon_type2cv(char *origtype, - char *restype, +clicon_type2cv(char *origtype, + char *restype, yang_stmt *ys, enum cv_type *cvtype) { @@ -351,8 +359,8 @@ clicon_type2cv(char *origtype, *cvtype = CGV_ERR; ym = ys_module(ys); - if (restype == NULL){ - /* + if (restype == NULL){ + /* * Not resolved, but we can use special cligen types, eg ipv4addr * Note this is a kludge or at least if we intend of using rfc types */ @@ -378,12 +386,13 @@ clicon_type2cv(char *origtype, } /*! Validate CLIgen variable with pattern statements - * @param[in] h Clicon handle + * + * @param[in] h Clixon handle * @param[in] regexps Vector of compiled regexps * @param[out] reason If given, and return value is 0, contains malloced string - * @retval -1 Error (fatal), with errno set to indicate error - * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() - * @retval 1 Validation OK + * @retval 1 Validation OK + * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() + * @retval -1 Error (fatal), with errno set to indicate error */ static int cv_validate_pattern(clicon_handle h, @@ -410,7 +419,7 @@ cv_validate_pattern(clicon_handle h, str); goto fail; break; - } + } } retval = 1; /* match */ done: @@ -428,6 +437,7 @@ cv_validate_pattern(clicon_handle h, /*! Error messsage for int violating ranges + * * @note contains kludge - duplicate loop */ static int @@ -446,7 +456,7 @@ outofrange(cg_var *cv0, cprintf(cb, "Number "); cv2cbuf(cv0, cb); cprintf(cb, " out of range: "); - /* Kludge: need to repeat the same loop as in the main function in + /* Kludge: need to repeat the same loop as in the main function in cv_validate1 */ i = 0; while (i, str is NULL. + /* Note, if there is no value, eg , str is NULL. */ if (restype){ if (strcmp(restype, "enumeration") == 0){ @@ -753,7 +763,7 @@ ys_cv_validate_leafref(clicon_handle h, char *body, yang_stmt *ys, yang_stmt *yrestype, - yang_stmt **ysub, + yang_stmt **ysub, char **reason) { int retval = -1; @@ -773,7 +783,7 @@ ys_cv_validate_leafref(clicon_handle h, } if (yang_path_arg(ys, path_arg, &yref) < 0) goto done; - if (yref == NULL){ + if (yref == NULL){ clicon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", path_arg); goto done; } @@ -799,16 +809,17 @@ ys_cv_validate_leafref(clicon_handle h, goto done; } -/*! +/*! Validate union + * * @param[in] h Clixon handle * @param[in] ys Yang statement (union) * @param[out] reason If given, and return value is 0, contains malloced string * param[in] yt One of the types in the union * param[in] type Original type * @param[in] val Value to match - * @retval -1 Error (fatal), with errno set to indicate error - * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() * @retval 1 Validation OK + * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() + * @retval -1 Error (fatal), with errno set to indicate error */ static int ys_cv_validate_union_one(clicon_handle h, @@ -824,7 +835,7 @@ ys_cv_validate_union_one(clicon_handle h, cvec *cvv = NULL; cvec *regexps = NULL; cvec *patterns = NULL; - uint8_t fraction = 0; + uint8_t fraction = 0; char *restype; enum cv_type cvtype; cg_var *cvt=NULL; @@ -886,7 +897,7 @@ ys_cv_validate_union_one(clicon_handle h, regexps) < 0) goto done; } - if ((retval = cv_validate1(h, cvt, cvtype, options, cvv, + if ((retval = cv_validate1(h, cvt, cvtype, options, cvv, regexps, yrestype, restype, reason)) < 0) goto done; } @@ -901,6 +912,7 @@ ys_cv_validate_union_one(clicon_handle h, } /*! Validate union + * * @param[in] h Clixon handle * @param[in] ys Yang statement (union) * @param[out] reason If given, and return value is 0, contains malloced string @@ -908,16 +920,16 @@ ys_cv_validate_union_one(clicon_handle h, * param[in] type Original type * @param[in] val Value to match * @param[out] ysubp Sub-type of ys that matches val - * @retval -1 Error (fatal), with errno set to indicate error - * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() * @retval 1 Validation OK + * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() + * @retval -1 Error (fatal), with errno set to indicate error */ static int ys_cv_validate_union(clicon_handle h, yang_stmt *ys, char **reason, yang_stmt *yrestype, - char *type, + char *type, char *val, yang_stmt **ysubp) { @@ -959,27 +971,27 @@ ys_cv_validate_union(clicon_handle h, /*! Validate cligen variable cv using yang statement as spec * - * @param[in] h Clicon handle + * @param[in] h Clixon handle * @param[in] cv A cligen variable to validate. This is a correctly parsed cv. * @param[in] ys A yang statement, must be leaf or leaf-list. * @param[out] ysub Sub-type that matches val (in case of union, otherwise ys) * @param[out] reason If given, and if return value is 0, contains malloced * string describing reason why validation failed. - * @retval -1 Error (fatal), with errno set to indicate error - * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() - * @retval 1 Validation OK + * @retval 1 Validation OK + * @retval 0 Validation not OK, malloced reason is returned. Free reason with free() + * @retval -1 Error (fatal), with errno set to indicate error * See also cv_validate - the code is similar. * @note reason if given must be freed by caller */ int ys_cv_validate(clicon_handle h, - cg_var *cv, - yang_stmt *ys, - yang_stmt **ysub, + cg_var *cv, + yang_stmt *ys, + yang_stmt **ysub, char **reason) { - int retval = -1; - cg_var *ycv; /* cv of yang-statement */ + int retval = -1; + cg_var *ycv; /* cv of yang-statement */ int options = 0; cvec *cvv = NULL; cvec *patterns = NULL; @@ -988,7 +1000,7 @@ ys_cv_validate(clicon_handle h, char *origtype = NULL; /* orig type */ yang_stmt *yrestype; /* resolved type */ char *restype; - uint8_t fraction = 0; + uint8_t fraction = 0; int retval2; char *val; cg_var *cvt=NULL; @@ -1008,7 +1020,7 @@ ys_cv_validate(clicon_handle h, clicon_err(OE_UNIX, errno, "cvec_new"); goto done; } - if (yang_type_get(ys, &origtype, &yrestype, + if (yang_type_get(ys, &origtype, &yrestype, &options, &cvv, patterns, regexps, &fraction) < 0) @@ -1022,13 +1034,13 @@ 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", + clicon_err(OE_DB, 0, "Type mismatch data:%s != yang:%s", cv_type2str(cvtype), cv_type2str(cv_type_get(ycv))); goto done; } } /* Note restype can be NULL here for example with unresolved hardcoded uuid */ - if (restype && strcmp(restype, "union") == 0){ + 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); goto done; @@ -1136,7 +1148,7 @@ ys_typedef_up(yang_stmt *ys) * @see xml_find_identity */ yang_stmt * -yang_find_identity(yang_stmt *ys, +yang_find_identity(yang_stmt *ys, char *identity) { char *id = NULL; @@ -1189,7 +1201,7 @@ yang_find_identity(yang_stmt *ys, * @see xml_find_identity */ yang_stmt * -yang_find_identity_nsc(yang_stmt *yspec, +yang_find_identity_nsc(yang_stmt *yspec, char *identity, cvec *nsc) { @@ -1198,7 +1210,7 @@ yang_find_identity_nsc(yang_stmt *yspec, yang_stmt *ymodule; yang_stmt *yid = NULL; char *ns = NULL; - + if (nodeid_split(identity, &prefix, &id) < 0) goto done; if ((ns = xml_nsctx_get(nsc, prefix)) == NULL) @@ -1226,13 +1238,13 @@ yang_find_identity_nsc(yang_stmt *yspec, * If options&YANG_OPTIONS_RANGE or YANG_OPTIONS_LENGTH * @param[out] regexps Pointer to cvec of compiled patterns * @param[out] fraction For decimal64, how many digits after period + * @retval 0 OK * @retval -1 Error - * @retval 0 OK. */ static int yang_type_resolve_restrictions(yang_stmt *ytype, - int *options, - cvec **cvv, + int *options, + cvec **cvv, cvec *regexps, uint8_t *fraction) { @@ -1268,7 +1280,7 @@ yang_type_resolve_restrictions(yang_stmt *ytype, cv_string_set(cv, pattern); } } - if (options && fraction && + if (options && fraction && (ys = yang_find(ytype, Y_FRACTION_DIGITS, NULL)) != NULL){ *fraction = cv_uint8_get(yang_cv_get(ys)); *options |= YANG_OPTIONS_FRACTION_DIGITS; @@ -1279,6 +1291,7 @@ yang_type_resolve_restrictions(yang_stmt *ytype, } /*! Recursively resolve a yang type to built-in type with optional restrictions + * * @param[in] yorig (original) type yang-stmt where original search is based * @param[in] ys (transitive) yang-stmt where current search is based * @param[in] ytype yang-stmt object containing currently resolving type @@ -1291,8 +1304,8 @@ yang_type_resolve_restrictions(yang_stmt *ytype, * @param[out] regexps Initialized cvec of compiled regexps (if any) * @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 0 OK. Note yrestype may still be NULL. + * @retval -1 Error, clicon_err handles errors * 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 @@ -1301,13 +1314,13 @@ yang_type_resolve_restrictions(yang_stmt *ytype, * Note that the static output strings (type, pattern) should be copied if used asap. * Note also that for all pointer arguments, if NULL is given, no value is assigned. */ -int +int yang_type_resolve(yang_stmt *yorig, - yang_stmt *ys, - yang_stmt *ytype, - yang_stmt **yrestype, - int *options, - cvec **cvv, + yang_stmt *ys, + yang_stmt *ytype, + yang_stmt **yrestype, + int *options, + cvec **cvv, cvec *patterns, cvec *regexps, uint8_t *fraction) @@ -1344,7 +1357,7 @@ yang_type_resolve(yang_stmt *yorig, #endif /* Check if type is basic type. If so, return that */ if ((prefix == NULL && yang_builtin(type))){ - *yrestype = ytype; + *yrestype = ytype; if (yang_type_resolve_restrictions(ytype, options, cvv, patterns, fraction) < 0) goto done; goto ok; @@ -1384,7 +1397,7 @@ yang_type_resolve(yang_stmt *yorig, goto done; } /* recursively resolve this new type */ - if (yang_type_resolve(yorig, ys, rytype, yrestype, + if (yang_type_resolve(yorig, ys, rytype, yrestype, options, cvv, patterns, regexps, fraction) < 0) @@ -1443,8 +1456,8 @@ yang_type_resolve(yang_stmt *yorig, * @param[out] regexps Initialized cvec of compiled regexps (if any) * @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 0 OK, but note that restype==NULL means not resolved. + * @retval -1 Error, clicon_err handles errors * 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 @@ -1453,12 +1466,12 @@ yang_type_resolve(yang_stmt *yorig, * Note also that for all pointer arguments, if NULL is given, no value is assigned. * @See yang_type_resolve(). This function is really just a frontend to that. */ -int -yang_type_get(yang_stmt *ys, - char **origtype, - yang_stmt **yrestype, - int *options, - cvec **cvv, +int +yang_type_get(yang_stmt *ys, + char **origtype, + yang_stmt **yrestype, + int *options, + cvec **cvv, cvec *patterns, cvec *regexps, uint8_t *fraction @@ -1483,7 +1496,7 @@ yang_type_get(yang_stmt *ys, clicon_err(OE_XML, errno, "stdup"); goto done; } - if (yang_type_resolve(ys, ys, ytype, yrestype, + if (yang_type_resolve(ys, ys, ytype, yrestype, options, cvv, patterns, regexps, fraction) < 0) goto done; if (yrestype && *yrestype == NULL){ @@ -1498,6 +1511,7 @@ yang_type_get(yang_stmt *ys, } /*! Utility function to translate a leaf/leaf-list to its base CV-type only + * * @see yang_type_get Full leaf/list type api */ enum cv_type @@ -1507,7 +1521,7 @@ yang_type2cv(yang_stmt *ys) char *restype; /* resolved type */ char *origtype=NULL; /* original type */ enum cv_type cvtype = CGV_ERR; - + /* Find type specification */ if (yang_type_get(ys, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) diff --git a/util/clixon_netconf_ssh_callhome_client.c b/util/clixon_netconf_ssh_callhome_client.c index a4b610e0..40d7b0ce 100644 --- a/util/clixon_netconf_ssh_callhome_client.c +++ b/util/clixon_netconf_ssh_callhome_client.c @@ -150,21 +150,24 @@ fdpass(int nfd) } /*! Create and bind stream socket + * * @param[in] sa Socketaddress * @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len * @param[in] backlog Listen backlog, queie of pending connections * @param[out] sock Server socket (bound for accept) + * @retval 0 OK + * @retval -1 Error */ int callhome_bind(struct sockaddr *sa, - size_t sin_len, + size_t sin_len, int backlog, int *sock) { int retval = -1; int s = -1; int on = 1; - + if (sock == NULL){ errno = EINVAL; perror("sock"); @@ -274,7 +277,7 @@ main(int argc, sin6.sin6_port = htons(port); sin6.sin6_family = AF_INET6; inet_pton(AF_INET6, addr, &sin6.sin6_addr); - sa = (struct sockaddr *)&sin6; + sa = (struct sockaddr *)&sin6; } else if (strcmp(family, "ipv4") == 0){ sin_len = sizeof(struct sockaddr_in); @@ -288,7 +291,7 @@ main(int argc, goto done; } /* Bind port */ - if (callhome_bind(sa, sin_len, 1, &ss) < 0) + if (callhome_bind(sa, sin_len, 1, &ss) < 0) goto done; /* Wait until connect */ len = sizeof(from); diff --git a/util/clixon_restconf_callhome_client.c b/util/clixon_restconf_callhome_client.c index b4062522..ae4a75e4 100644 --- a/util/clixon_restconf_callhome_client.c +++ b/util/clixon_restconf_callhome_client.c @@ -136,21 +136,24 @@ static int _event_trace = 0; static FILE *_event_f = NULL; /* set to stdout in main */ /*! Create and bind stream socket + * * @param[in] sa Socketaddress * @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len * @param[in] backlog Listen backlog, queie of pending connections * @param[out] sock Server socket (bound for accept) + * @retval 0 OK + * @retval -1 Error */ int callhome_bind(struct sockaddr *sa, - size_t sin_len, + size_t sin_len, int backlog, int *sock) { int retval = -1; int s = -1; int on = 1; - + if (sock == NULL){ errno = EINVAL; perror("sock"); @@ -193,6 +196,7 @@ callhome_bind(struct sockaddr *sa, } /*! read data from file return a malloced buffer + * * Note same file is reread multiple times: same request/reply is made each iteration * Also, the file read is limited to 1024 bytes */ @@ -243,13 +247,13 @@ tls_write_file(FILE *fp, size_t len = 0; int ret; int sslerr; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (read_data_file(fp, &buf, &len) < 0) goto done; if ((ret = SSL_write(ssl, buf, len)) < 1){ sslerr = SSL_get_error(ssl, ret); - clicon_debug(1, "%s SSL_write() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr); + clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_write() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr); } retval = 0; done: @@ -259,12 +263,13 @@ tls_write_file(FILE *fp, } /*! Client data socket, receive reply from server + * * Print info on stdout * If keep_open = 0, then close socket directly after 1st reply (client close) * If keep_open = 1, then keep socket open (server close) */ static int -tls_server_reply_cb(int s, +tls_server_reply_cb(int s, void *arg) { int retval = -1; @@ -276,15 +281,15 @@ tls_server_reply_cb(int s, struct timeval now; struct timeval td; static int seq = 0; // from start - - // clicon_debug(1, "%s", __FUNCTION__); + + // clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); ssl = sd->sd_ssl; /* get reply & decrypt */ if ((n = SSL_read(ssl, buf, sizeof(buf))) < 0){ clicon_err(OE_XML, errno, "SSL_read"); goto done; } - clicon_debug(1, "%s n:%d", __FUNCTION__, n); + clixon_debug(CLIXON_DBG_DEFAULT, "%s n:%d", __FUNCTION__, n); gettimeofday(&now, NULL); timersub(&now, &sd->sd_t0, &td); /* from start of connection */ if (n == 0){ /* Server closed socket */ @@ -317,11 +322,10 @@ tls_server_reply_cb(int s, usleep(100000); /* XXX This is a blocking timeout */ /* Write HTTP request on socket */ if (tls_write_file(_input_file, sd->sd_ssl) < 0) - goto done; - + goto done; } else if (!_idle){ - clicon_debug(1, "%s idle", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s idle", __FUNCTION__); SSL_shutdown(ssl); SSL_free(ssl); clixon_event_unreg_fd(s, tls_server_reply_cb); @@ -331,7 +335,7 @@ tls_server_reply_cb(int s, if (_accepts == 0) ; else if (_accepts == 1){ - clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */ + clixon_exit_set(1); /* XXX more elaborate logic: 1) continue request, 2) close and accept new */ fprintf(_event_f, "Exit: %s idle\n", __FUNCTION__); } else @@ -343,7 +347,7 @@ tls_server_reply_cb(int s, done: if (expbuf) free(expbuf); - clicon_debug(1, "%s ret:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s ret:%d", __FUNCTION__, retval); return retval; } @@ -360,7 +364,7 @@ tls_ssl_init_connect(SSL_CTX *ctx, int ret; int verify; int sslerr; - + /* create new SSL connection state */ if ((ssl = SSL_new(ctx)) == NULL){ clicon_err(OE_SSL, 0, "SSL_new."); @@ -380,7 +384,7 @@ tls_ssl_init_connect(SSL_CTX *ctx, SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len); #endif - /* perform the connection + /* perform the connection TLSEXT_TYPE_application_layer_protocol_negotiation int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, unsigned int protos_len); @@ -389,7 +393,7 @@ tls_ssl_init_connect(SSL_CTX *ctx, */ if ((ret = SSL_connect(ssl)) < 1){ sslerr = SSL_get_error(ssl, ret); - clicon_debug(1, "%s SSL_read() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr); + clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_read() n:%d errno:%d sslerr:%d", __FUNCTION__, ret, errno, sslerr); switch (sslerr){ case SSL_ERROR_SSL: /* 1 */ @@ -453,7 +457,7 @@ tls_client_timeout(void *arg) /*! Callhome-server accept socket */ static int -tls_server_accept_cb(int ss, +tls_server_accept_cb(int ss, void *arg) { int retval = -1; @@ -464,17 +468,17 @@ tls_server_accept_cb(int ss, socklen_t len; SSL *ssl = NULL; struct timeval td; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); len = sizeof(from); if ((s = accept(ss, &from, &len)) < 0){ perror("accept"); goto done; } - clicon_debug(1, "accepted"); + clixon_debug(CLIXON_DBG_DEFAULT, "accepted"); if (tls_ssl_init_connect(ta->ta_ctx, s, &ssl) < 0) goto done; - clicon_debug(1, "connected"); + clixon_debug(CLIXON_DBG_DEFAULT, "connected"); if ((sd = malloc(sizeof(*sd))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -502,8 +506,7 @@ tls_server_accept_cb(int ss, return retval; } -/*! - * out must be set to point to the selected protocol (which may be within in). +/*! Out must be set to point to the selected protocol (which may be within in). */ static int tls_proto_select_cb(SSL *s, @@ -513,11 +516,12 @@ tls_proto_select_cb(SSL *s, unsigned int inlen, void *arg) { - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); return 0; } /*! Verify tls auth + * * @see tlsauth_verify_callback * This code needs a "X509 store", see X509_STORE_new() * crl_file / crl_dir @@ -535,7 +539,7 @@ tls_ctx_init(const char *cert_path, const char *ca_cert_path) { SSL_CTX *ctx = NULL; - + if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) { clicon_err(OE_SSL, 0, "SSL_CTX_new"); goto done; @@ -611,7 +615,7 @@ main(int argc, char *family = "inet:ipv4-address"; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); + clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); if ((h = clicon_handle_init()) == NULL) goto done; while ((c = getopt(argc, argv, UTIL_TLS_OPTS)) != -1) @@ -685,11 +689,11 @@ main(int argc, fprintf(stderr, "-c and -k -C are mandatory\n"); usage(argv[0]); } - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); if (input_filename){ if ((_input_file = fopen(input_filename, "r")) == NULL){ - clicon_err(OE_YANG, errno, "open(%s)", input_filename); + clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } } @@ -708,9 +712,9 @@ main(int argc, if (clixon_inet2sin(family, addr, port, sa, &sa_len) < 0) goto done; /* Bind port */ - if (callhome_bind(sa, sa_len, 1, &ss) < 0) + if (callhome_bind(sa, sa_len, 1, &ss) < 0) goto done; - clicon_debug(1, "callhome_bind %s:%hu", addr, port); + clixon_debug(CLIXON_DBG_DEFAULT, "callhome_bind %s:%hu", addr, port); if ((ta = malloc(sizeof(*ta))) == NULL){ clicon_err(OE_UNIX, errno, "malloc"); goto done; @@ -739,7 +743,7 @@ main(int argc, SSL_CTX_free(ctx); /* release context */ clicon_handle_exit(h); /* frees h and options (and streams) */ clixon_err_exit(); - clicon_debug(1, "clixon_restconf_callhome_client pid:%u done", getpid()); - clicon_log_exit(); /* Must be after last clicon_debug */ + clixon_debug(CLIXON_DBG_DEFAULT, "clixon_restconf_callhome_client pid:%u done", getpid()); + clicon_log_exit(); /* Must be after last clixon_debug */ return retval; } diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index 7d5827e7..5977bde5 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -180,8 +180,8 @@ main(int argc, char **argv) /* * Logs, error and debug to stderr, set debug level */ - clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR); - clicon_debug_init(dbg, NULL); + clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR); + clixon_debug_init(dbg, NULL); argc -= optind; argv += optind; diff --git a/util/clixon_util_dispatcher.c b/util/clixon_util_dispatcher.c index 1c77bd96..5b93f75d 100644 --- a/util/clixon_util_dispatcher.c +++ b/util/clixon_util_dispatcher.c @@ -141,10 +141,8 @@ main(int argc, * Logs, error and debug to stderr or syslog, set debug level */ clicon_log_init("xpath", dbg?LOG_DEBUG:LOG_INFO, logdst); - - clicon_debug_init(dbg, NULL); - - /* Now rest of options */ + clixon_debug_init(dbg, NULL); + /* Now rest of options */ opterr = 0; optind = 1; while ((c = getopt(argc, argv, DISPATCHER_OPTS)) != -1){ @@ -167,7 +165,7 @@ main(int argc, case 'r' :{ /* register callback based on -a/-i/-p*/ dispatcher_definition x = {regpath, fn, arg}; if (dispatcher_register_handler(&htable, &x) < 0) - goto done; + goto done; break; } case 'c':{ /* Execute a call using path */ diff --git a/util/clixon_util_grpc.c b/util/clixon_util_grpc.c index c4d1538c..f9e2418e 100644 --- a/util/clixon_util_grpc.c +++ b/util/clixon_util_grpc.c @@ -95,7 +95,7 @@ print_header(const uint8_t *name, const uint8_t *value, size_t valuelen) { - clicon_debug(1, "%s %s", name, value); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", name, value); } /* Print HTTP headers to |f|. Please note that this function does not @@ -107,7 +107,7 @@ print_headers(nghttp2_nv *nva, { size_t i; - for (i = 0; i < nvlen; ++i) + for (i = 0; i < nvlen; ++i) print_header(nva[i].name, nva[i].namelen, nva[i].value, nva[i].valuelen); } #endif /* DEBUG */ @@ -126,8 +126,7 @@ send_callback(nghttp2_session *session, session_data *sd = (session_data*)user_data; int ret; - - clicon_debug(1, "%s %zu:", __FUNCTION__, length); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %zu:", __FUNCTION__, length); #if 0 { int i; @@ -150,11 +149,11 @@ on_frame_recv_callback(nghttp2_session *session, void *user_data) { //session_data *sd = (session_data*)user_data; - - clicon_debug(1, "%s %d", __FUNCTION__, frame->hd.stream_id); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, frame->hd.stream_id); if (frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_RESPONSE) - clicon_debug(1, "All headers received %d", frame->hd.stream_id); + clixon_debug(CLIXON_DBG_DEFAULT, "All headers received %d", frame->hd.stream_id); return 0; } @@ -170,8 +169,8 @@ on_data_chunk_recv_callback(nghttp2_session *session, void *user_data) { session_data *sd = (session_data*)user_data; - - clicon_debug(1, "%s %d", __FUNCTION__, stream_id); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, stream_id); if (sd->sd_session == session && sd->sd_stream_id == stream_id) fwrite(data, 1, len, stdout); /* This is where data is printed */ @@ -187,8 +186,8 @@ on_stream_close_callback(nghttp2_session *session, void *user_data) { //session_data *sd = (session_data*)user_data; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); return 0; } @@ -205,10 +204,10 @@ on_header_callback(nghttp2_session *session, void *user_data) { // session_data *sd = (session_data*)user_data; - + if (frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_RESPONSE){ - clicon_debug(1, "%s %d:", __FUNCTION__, frame->hd.stream_id); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d:", __FUNCTION__, frame->hd.stream_id); print_header(name, namelen, value, valuelen); } return 0; @@ -225,7 +224,7 @@ on_begin_headers_callback(nghttp2_session *session, if (frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_RESPONSE) - clicon_debug(1, "%s Response headers %d", + clixon_debug(CLIXON_DBG_DEFAULT, "%s Response headers %d", __FUNCTION__, frame->hd.stream_id); return 0; } @@ -264,7 +263,7 @@ send_client_connection_header(nghttp2_session *session) {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}}; int rv; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); /* client 24 bytes magic string will be sent by nghttp2 library */ rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, ARRLEN(iv)); if (rv != 0) { @@ -277,8 +276,7 @@ send_client_connection_header(nghttp2_session *session) } -/*! - * Sets sd->sd_stream_id +/*! Sets sd->sd_stream_id */ static int submit_request(session_data *sd, @@ -294,7 +292,7 @@ submit_request(session_data *sd, MAKE_NV(":path", path, strlen(path)) }; - clicon_debug(1, "%s Request headers:", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Request headers:", __FUNCTION__); print_headers(hdrs, ARRLEN(hdrs)); if ((sd->sd_stream_id = nghttp2_submit_request(sd->sd_session, NULL, @@ -324,7 +322,7 @@ socket_connect_inet(char *hostname, struct hostent *host; int one = 1; - clicon_debug(1, "%s to %s:%hu", __FUNCTION__, hostname, port); + clixon_debug(CLIXON_DBG_DEFAULT, "%s to %s:%hu", __FUNCTION__, hostname, port); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); @@ -371,10 +369,10 @@ select_next_proto_cb(SSL *ssl, unsigned int inlen, void *arg) { - clicon_debug(1, "%s", __FUNCTION__); - if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) return -1; - clicon_debug(1, "%s out: %s in:%s", __FUNCTION__, *out, in); + clixon_debug(CLIXON_DBG_DEFAULT, "%s out: %s in:%s", __FUNCTION__, *out, in); return SSL_TLSEXT_ERR_OK; } @@ -384,7 +382,7 @@ InitCTX(void) { const SSL_METHOD *method; SSL_CTX *ctx; - + #if 1 method = SSLv23_client_method(); #else @@ -414,7 +412,7 @@ InitCTX(void) } static int -ssl_input_cb(int s, +ssl_input_cb(int s, void *arg) { int retval = -1; @@ -424,7 +422,7 @@ ssl_input_cb(int s, int n; nghttp2_session *session; int readlen; - + ssl = sd->sd_ssl; session = sd->sd_session; /* get reply & decrypt */ @@ -481,8 +479,7 @@ main(int argc, int dbg = 0; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); - + clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); if ((h = clicon_handle_init()) == NULL) goto done; while ((c = getopt(argc, argv, UTIL_GRPC_OPTS)) != -1) @@ -505,7 +502,7 @@ main(int argc, fprintf(stderr, "-H is mandatory\n"); usage(argv[0]); } - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); SSL_library_init(); if ((ctx = InitCTX()) == NULL) goto done; diff --git a/util/clixon_util_json.c b/util/clixon_util_json.c index 386c2b50..4f3c8aa3 100644 --- a/util/clixon_util_json.c +++ b/util/clixon_util_json.c @@ -99,7 +99,7 @@ main(int argc, int ret; int pretty = 0; int dbg = 0; - + optind = 1; opterr = 0; while ((c = getopt(argc, argv, "hD:jl:py:")) != -1) @@ -129,7 +129,7 @@ main(int argc, break; } clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); if (yang_filename){ if ((yspec = yspec_new()) == NULL) diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index d1ca2e0f..0f0c4dff 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -111,9 +111,9 @@ main(int argc, cxobj *xerr = NULL; /* malloced must be freed */ int nr = 1; int dbg = 0; - + /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init("api-path", LOG_DEBUG, CLICON_LOG_STDERR); + clicon_log_init("api-path", LOG_DEBUG, CLICON_LOG_STDERR); /* Initialize clixon handle */ if ((h = clicon_handle_init()) == NULL) goto done; @@ -122,7 +122,6 @@ main(int argc, goto done; if (clicon_conf_xml_set(h, xcfg) < 0) goto done; - optind = 1; opterr = 0; while ((c = getopt(argc, argv, UTIL_PATH_OPTS)) != -1) @@ -161,7 +160,7 @@ main(int argc, usage(argv[0]); break; } - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); yang_init(h); /* Parse yang */ @@ -191,7 +190,7 @@ main(int argc, } memset(buf, 0, len); i = 0; - while (1){ + while (1){ if ((ret = read(0, &c, 1)) < 0){ perror("read"); goto done; @@ -204,7 +203,7 @@ main(int argc, if ((buf = realloc(buf, 2*len)) == NULL){ fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno)); return -1; - } + } memset(buf+len, 0, len); len *= 2; } @@ -213,7 +212,7 @@ main(int argc, path = buf; } - /* + /* * If fp=stdin, then continue reading from stdin (after CR) * XXX Note 0 above, stdin here */ @@ -245,7 +244,7 @@ main(int argc, /* Add default values */ if (xml_default_recurse(x, 0) < 0) goto done; - if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0) + if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0) goto done; if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0) goto done; diff --git a/util/clixon_util_regexp.c b/util/clixon_util_regexp.c index 959df846..011b4549 100644 --- a/util/clixon_util_regexp.c +++ b/util/clixon_util_regexp.c @@ -60,10 +60,11 @@ #include "clixon/clixon.h" /*! libxml2 regex implementation + * * @see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028 - * @retval -1 Error - * @retval 0 Not match * @retval 1 Match + * @retval 0 Not match + * @retval -1 Error */ static int regex_libxml2(char *regexp0, @@ -110,7 +111,7 @@ regex_posix(char *regexp, if (regexp_xsd2posix(regexp, &posix) < 0) goto done; - clicon_debug(1, "posix: %s", posix); + clixon_debug(CLIXON_DBG_DEFAULT, "posix: %s", posix); len0 = strlen(posix); if (len0 > sizeof(pattern)-5){ fprintf(stderr, "pattern too long\n"); @@ -200,8 +201,8 @@ main(int argc, usage(argv[0]); break; } - clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR); - clicon_debug_init(dbg, NULL); + clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR); + clixon_debug_init(dbg, NULL); if (regexp == NULL){ fprintf(stderr, "-r mandatory\n"); @@ -215,8 +216,8 @@ main(int argc, fprintf(stderr, "Neither posix or libxml2 set\n"); usage(argv0); } - clicon_debug(1, "regexp:%s", regexp); - clicon_debug(1, "content:%s", content); + clixon_debug(CLIXON_DBG_DEFAULT, "regexp:%s", regexp); + clixon_debug(CLIXON_DBG_DEFAULT, "content:%s", content); if (mode == 0){ if ((ret = regex_posix(regexp, content, nr, dbg)) < 0) goto done; diff --git a/util/clixon_util_socket.c b/util/clixon_util_socket.c index 30c7b0cf..51ea89ca 100644 --- a/util/clixon_util_socket.c +++ b/util/clixon_util_socket.c @@ -103,11 +103,9 @@ main(int argc, int eof = 0; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); - + clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); if ((h = clicon_handle_init()) == NULL) goto done; - optind = 1; opterr = 0; while ((c = getopt(argc, argv, "hD:s:f:Ja:")) != -1) @@ -136,7 +134,7 @@ main(int argc, break; } clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); if (sockpath == NULL){ fprintf(stderr, "Mandatory option missing: -s \n"); @@ -144,7 +142,7 @@ main(int argc, } if (input_filename){ if ((fp = fopen(input_filename, "r")) == NULL){ - clicon_err(OE_YANG, errno, "open(%s)", input_filename); + clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } } diff --git a/util/clixon_util_ssl.c b/util/clixon_util_ssl.c index af4ae643..17d74fd3 100644 --- a/util/clixon_util_ssl.c +++ b/util/clixon_util_ssl.c @@ -96,7 +96,7 @@ print_header(const uint8_t *name, const uint8_t *value, size_t valuelen) { - clicon_debug(1, "%s %s", name, value); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", name, value); } /* Print HTTP headers to |f|. Please note that this function does not @@ -108,7 +108,7 @@ print_headers(nghttp2_nv *nva, { size_t i; - for (i = 0; i < nvlen; ++i) + for (i = 0; i < nvlen; ++i) print_header(nva[i].name, nva[i].namelen, nva[i].value, nva[i].valuelen); } #endif /* DEBUG */ @@ -126,8 +126,8 @@ send_callback(nghttp2_session *session, { session_data *sd = (session_data*)user_data; int ret; - - clicon_debug(1, "%s %zu:", __FUNCTION__, length); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s %zu:", __FUNCTION__, length); #if 0 { int i; @@ -150,11 +150,10 @@ on_frame_recv_callback(nghttp2_session *session, void *user_data) { //session_data *sd = (session_data*)user_data; - - clicon_debug(1, "%s %d", __FUNCTION__, frame->hd.stream_id); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, frame->hd.stream_id); if (frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_RESPONSE) - clicon_debug(1, "All headers received %d", frame->hd.stream_id); + clixon_debug(CLIXON_DBG_DEFAULT, "All headers received %d", frame->hd.stream_id); return 0; } @@ -170,8 +169,8 @@ on_data_chunk_recv_callback(nghttp2_session *session, void *user_data) { session_data *sd = (session_data*)user_data; - - clicon_debug(1, "%s %d", __FUNCTION__, stream_id); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, stream_id); if (sd->sd_session == session && sd->sd_stream_id == stream_id) fwrite(data, 1, len, stdout); /* This is where data is printed */ @@ -187,8 +186,8 @@ on_stream_close_callback(nghttp2_session *session, void *user_data) { //session_data *sd = (session_data*)user_data; - - clicon_debug(1, "%s", __FUNCTION__); + + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); return 0; } @@ -205,10 +204,10 @@ on_header_callback(nghttp2_session *session, void *user_data) { // session_data *sd = (session_data*)user_data; - + if (frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_RESPONSE){ - clicon_debug(1, "%s %d:", __FUNCTION__, frame->hd.stream_id); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %d:", __FUNCTION__, frame->hd.stream_id); print_header(name, namelen, value, valuelen); } return 0; @@ -225,7 +224,7 @@ on_begin_headers_callback(nghttp2_session *session, if (frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_RESPONSE) - clicon_debug(1, "%s Response headers %d", + clixon_debug(CLIXON_DBG_DEFAULT, "%s Response headers %d", __FUNCTION__, frame->hd.stream_id); return 0; } @@ -264,7 +263,7 @@ send_client_connection_header(nghttp2_session *session) {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}}; int rv; - clicon_debug(1, "%s", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); /* client 24 bytes magic string will be sent by nghttp2 library */ rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, ARRLEN(iv)); if (rv != 0) { @@ -277,8 +276,7 @@ send_client_connection_header(nghttp2_session *session) } -/*! - * Sets sd->sd_stream_id +/*! Sets sd->sd_stream_id */ static int submit_request(session_data *sd, @@ -294,7 +292,7 @@ submit_request(session_data *sd, MAKE_NV(":path", path, strlen(path)) }; - clicon_debug(1, "%s Request headers:", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Request headers:", __FUNCTION__); print_headers(hdrs, ARRLEN(hdrs)); if ((sd->sd_stream_id = nghttp2_submit_request(sd->sd_session, NULL, @@ -324,7 +322,7 @@ socket_connect_inet(char *hostname, struct hostent *host; int one = 1; - clicon_debug(1, "%s to %s:%hu", __FUNCTION__, hostname, port); + clixon_debug(CLIXON_DBG_DEFAULT, "%s to %s:%hu", __FUNCTION__, hostname, port); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); @@ -371,10 +369,10 @@ select_next_proto_cb(SSL *ssl, unsigned int inlen, void *arg) { - clicon_debug(1, "%s", __FUNCTION__); - if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) + clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) return -1; - clicon_debug(1, "%s out: %s in:%s", __FUNCTION__, *out, in); + clixon_debug(CLIXON_DBG_DEFAULT, "%s out: %s in:%s", __FUNCTION__, *out, in); return SSL_TLSEXT_ERR_OK; } @@ -384,7 +382,7 @@ InitCTX(void) { const SSL_METHOD *method; SSL_CTX *ctx; - + #if 1 method = SSLv23_client_method(); #else @@ -414,7 +412,7 @@ InitCTX(void) } static int -ssl_input_cb(int s, +ssl_input_cb(int s, void *arg) { int retval = -1; @@ -424,7 +422,7 @@ ssl_input_cb(int s, int n; nghttp2_session *session; int readlen; - + ssl = sd->sd_ssl; session = sd->sd_session; /* get reply & decrypt */ @@ -481,8 +479,7 @@ main(int argc, int dbg = 0; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); - + clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); if ((h = clicon_handle_init()) == NULL) goto done; while ((c = getopt(argc, argv, UTIL_SSL_OPTS)) != -1) @@ -505,7 +502,7 @@ main(int argc, fprintf(stderr, "-H is mandatory\n"); usage(argv[0]); } - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); SSL_library_init(); if ((ctx = InitCTX()) == NULL) goto done; diff --git a/util/clixon_util_stream.c b/util/clixon_util_stream.c index 4a26b395..a2e53edf 100644 --- a/util/clixon_util_stream.c +++ b/util/clixon_util_stream.c @@ -73,9 +73,9 @@ struct curlbuf{ * realloc. Therefore, we append new data to the userdata buffer. */ static size_t -curl_get_cb(void *ptr, - size_t size, - size_t nmemb, +curl_get_cb(void *ptr, + size_t size, + size_t nmemb, void *userdata) { struct curlbuf *buf = (struct curlbuf *)userdata; @@ -96,17 +96,17 @@ curl_get_cb(void *ptr, * If getdata is set, return the (malloced) data (which should be freed). * * @param[in] start 'start-time' parameter that will be URL-encoded - * @retval -1 fatal error * @retval 1 ok + * @retval -1 fatal error * * @note curl_easy_perform blocks * @note New handle is created every time, the handle can be re-used for * better TCP performance */ int -stream_url_get(char *url, +stream_url_get(char *url, char *start, - char *stop, + char *stop, int timeout, char **getdata) { @@ -119,7 +119,7 @@ stream_url_get(char *url, struct curl_slist *list = NULL; int ret; - clicon_debug(1, "%s: curl -G %s start-time=%s stop-time=%s", + clixon_debug(CLIXON_DBG_DEFAULT, "%s: curl -G %s start-time=%s stop-time=%s", __FUNCTION__, url, start?start:"", stop?stop:""); /* Set up curl for doing the communication with the controller */ if ((curl = curl_easy_init()) == NULL) { @@ -130,7 +130,7 @@ stream_url_get(char *url, goto done; if ((err = malloc(CURL_ERROR_SIZE)) == NULL) { - clicon_debug(1, "%s: malloc", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s: malloc", __FUNCTION__); goto done; } curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); @@ -139,7 +139,7 @@ stream_url_get(char *url, // list = curl_slist_append(list, "Cache-Control: no-cache"); // list = curl_slist_append(list, "Connection: keep-alive"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); - /* specify URL to get */ + /* specify URL to get */ cprintf(cbf, "%s", url); if (strlen(start)||strlen(stop)) cprintf(cbf, "?"); @@ -159,17 +159,16 @@ stream_url_get(char *url, curl_free(encoded); encoded = NULL; } - clicon_debug(1, "url: %s\n", cbuf_get(cbf)); + clixon_debug(CLIXON_DBG_DEFAULT, "url: %s\n", cbuf_get(cbf)); curl_easy_setopt(curl, CURLOPT_URL, cbuf_get(cbf)); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_get_cb); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cb); - - /* some servers don't like requests that are made without a user-agent - field, so we provide one */ + /* some servers don't like requests that are made without a user-agent + field, so we provide one */ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err); curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); ret = curl_easy_perform(curl); if (ret != CURLE_OPERATION_TIMEDOUT && ret != CURLE_OK){ fprintf(stderr, "curl: %s %d", err, ret); @@ -190,7 +189,7 @@ stream_url_get(char *url, if (cb.b_buf) free(cb.b_buf); if (curl) - curl_easy_cleanup(curl); /* cleanup */ + curl_easy_cleanup(curl); /* cleanup */ return retval; } @@ -224,7 +223,7 @@ main(int argc, char **argv) struct timeval now; int dbg = 0; - clicon_log_init("xpath", LOG_DEBUG, CLICON_LOG_STDERR); + clicon_log_init("xpath", LOG_DEBUG, CLICON_LOG_STDERR); gettimeofday(&now, NULL); optind = 1; opterr = 0; @@ -266,7 +265,7 @@ main(int argc, char **argv) usage(argv[0]); break; } - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); if (url == NULL) usage(argv[0]); curl_global_init(0); diff --git a/util/clixon_util_validate.c b/util/clixon_util_validate.c index acf924f7..6442fc82 100644 --- a/util/clixon_util_validate.c +++ b/util/clixon_util_validate.c @@ -101,7 +101,7 @@ main(int argc, cbuf *cb = NULL; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); + clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); /* Initialize clixon handle */ if ((h = clicon_handle_init()) == NULL) @@ -133,7 +133,7 @@ main(int argc, usage(argv[0]); break; } - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); yang_init(h); /* Find and read configfile */ if (clicon_options_main(h) < 0) @@ -172,7 +172,7 @@ main(int argc, /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ xml_nsctx_namespace_netconf_default(h); - + /* Add (hardcoded) netconf features in case ietf-netconf loaded here * Otherwise it is loaded in netconf_module_load below */ @@ -182,7 +182,7 @@ main(int argc, /* Create top-level yang spec and store as option */ if ((yspec = yspec_new()) == NULL) goto done; - clicon_dbspec_yang_set(h, yspec); + clicon_dbspec_yang_set(h, yspec); /* Load backend plugins before yangs are loaded (eg extension callbacks) */ if ((dir = clicon_backend_dir(h)) != NULL && clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, diff --git a/util/clixon_util_xml.c b/util/clixon_util_xml.c index c3a80e2a..00f2eb83 100644 --- a/util/clixon_util_xml.c +++ b/util/clixon_util_xml.c @@ -85,7 +85,7 @@ validate_tree(clicon_handle h, goto done; if (xml_apply(xt, -1, xml_sort_verify, h) < 0) clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__); - if ((ret = xml_yang_validate_all_top(h, xt, &xerr)) < 0) + if ((ret = xml_yang_validate_all_top(h, xt, &xerr)) < 0) goto done; if (ret > 0 && (ret = xml_yang_validate_add(h, xt, &xerr)) < 0) goto done; @@ -163,12 +163,12 @@ main(int argc, cxobj *xtop = NULL; /* Top tree if any */ char *top_path = NULL; cxobj *xbot; /* Place in xtop where base cxobj is parsed */ - cvec *nsc = NULL; + cvec *nsc = NULL; yang_bind yb; int dbg = 0; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); + clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR); /* Initialize clixon handle */ if ((h = clicon_handle_init()) == NULL) @@ -245,9 +245,8 @@ main(int argc, usage(argv[0]); } clicon_log_init(__FILE__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); yang_init(h); - /* 1. Parse yang */ if (yang_file_dir){ if ((yspec = yspec_new()) == NULL) @@ -271,7 +270,7 @@ main(int argc, */ if (top_input_filename){ if ((tfp = fopen(top_input_filename, "r")) == NULL){ - clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename); + clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename); goto done; } if ((ret = clixon_xml_parse_file(tfp, YB_MODULE, yspec, &xtop, &xerr)) < 0){ @@ -296,7 +295,7 @@ main(int argc, } if (input_filename){ if ((fp = fopen(input_filename, "r")) == NULL){ - clicon_err(OE_YANG, errno, "open(%s)", input_filename); + clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } } diff --git a/util/clixon_util_xml_mod.c b/util/clixon_util_xml_mod.c index b283d44e..d4f35a48 100644 --- a/util/clixon_util_xml_mod.c +++ b/util/clixon_util_xml_mod.c @@ -133,8 +133,8 @@ main(int argc, char **argv) char *reason = NULL; int dbg = 0; cxobj *xcfg = NULL; - - clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR); + + clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR); if ((h = clicon_handle_init()) == NULL) goto done; if ((xcfg = xml_new("clixon-config", NULL, CX_ELMNT)) == NULL) @@ -168,7 +168,7 @@ main(int argc, char **argv) case 'x': /* XML to insert */ x1str = optarg; break; - case 'p': /* XPATH base */ + case 'p': /* XPath base */ xpath = optarg; break; case 's': /* sort output after insert */ @@ -181,9 +181,9 @@ main(int argc, char **argv) /* Sanity check: check mandatory arguments */ if (x1str == NULL || x0str == NULL || yangfile == NULL) usage(argv0); - if (opx == OPX_ERROR) + if (opx == OPX_ERROR) usage(argv0); - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); if ((yspec = yspec_new()) == NULL) goto done; if (yang_spec_parse_file(h, yangfile, yspec) < 0) @@ -204,8 +204,8 @@ main(int argc, char **argv) clicon_err(OE_XML, 0, "xpath: %s not found in x0", xpath); goto done; } - if (clicon_debug_get()){ - clicon_debug(1, "xb:"); + if (clixon_debug_get()){ + clixon_debug(CLIXON_DBG_DEFAULT, "xb:"); xml_print(stderr, xb); } switch (opx){ @@ -236,7 +236,7 @@ main(int argc, char **argv) clicon_err(OE_XML, 0, "xpath: %s not found in xi", xpath); goto done; } - if ((ret = xml_merge(xb, xi, yspec, &reason)) < 0) + if ((ret = xml_merge(xb, xi, yspec, &reason)) < 0) goto done; if (ret == 0){ clicon_err(OE_XML, 0, "%s", reason); @@ -269,14 +269,14 @@ main(int argc, char **argv) /* Remove it from parent */ if (xml_rm(xi1) < 0) goto done; - if (xml_insert(xb, xi1, INS_LAST, NULL, NULL) < 0) + if (xml_insert(xb, xi1, INS_LAST, NULL, NULL) < 0) goto done; break; default: usage(argv0); } - if (clicon_debug_get()){ - clicon_debug(1, "x0:"); + if (clixon_debug_get()){ + clixon_debug(CLIXON_DBG_DEFAULT, "x0:"); xml_print(stderr, x0); } if (sort) diff --git a/util/clixon_util_xpath.c b/util/clixon_util_xpath.c index 42da5002..7af0f809 100644 --- a/util/clixon_util_xpath.c +++ b/util/clixon_util_xpath.c @@ -70,8 +70,8 @@ usage(char *argv0) "\t-h \t\tHelp\n" "\t-D \tDebug\n" "\t-f \tXML file\n" - "\t-p \tPrimary XPATH string\n" - "\t-i \t(optional) Initial XPATH string\n" + "\t-p \tPrimary XPath string\n" + "\t-i \t(optional) Initial XPath string\n" "\t-I \t\tCheck inverse, map back xml result to xpath and check if equal\n" "\t-n \tNamespace binding (pfx=NULL for default)\n" "\t-c \t\tMap xpath to canonical form\n" @@ -179,10 +179,10 @@ main(int argc, goto done; } break; - case 'p': /* Primary XPATH string */ + case 'p': /* Primary XPath string */ xpath = optarg; break; - case 'i': /* Optional initial XPATH string */ + case 'i': /* Optional initial XPath string */ xpath0 = optarg; break; case 'I': /* Check inverse */ @@ -234,10 +234,8 @@ main(int argc, * Logs, error and debug to stderr or syslog, set debug level */ clicon_log_init("xpath", dbg?LOG_DEBUG:LOG_INFO, logdst); - - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); yang_init(h); - /* Parse yang */ if (yang_file_dir){ if ((yspec = yspec_new()) == NULL) @@ -265,7 +263,7 @@ main(int argc, } memset(buf, 0, len); i = 0; - while (1){ + while (1){ if ((ret = read(0, &c, 1)) < 0){ perror("read"); goto done; @@ -278,7 +276,7 @@ main(int argc, if ((buf = realloc(buf, 2*len)) == NULL){ fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno)); return -1; - } + } memset(buf+len, 0, len); len *= 2; } @@ -292,7 +290,7 @@ main(int argc, char *xpath1 = NULL; cvec *nsc1 = NULL; cbuf *cbreason = NULL; - + if ((ret = xpath2canonical(xpath, nsc, yspec, &xpath1, &nsc1, &cbreason)) < 0) goto done; if (ret == 0){ @@ -309,7 +307,7 @@ main(int argc, cvec_print(stdout, nsc); goto ok; /* need a switch to continue, now just print and quit */ } - /* + /* * If fp=stdin, then continue reading from stdin (after CR) * XXX Note 0 above, stdin here */ @@ -342,7 +340,7 @@ main(int argc, goto done; if (xml_apply0(x0, -1, xml_sort_verify, h) < 0) clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__); - if ((ret = xml_yang_validate_all_top(h, x0, &xerr)) < 0) + if ((ret = xml_yang_validate_all_top(h, x0, &xerr)) < 0) goto done; if (ret > 0 && (ret = xml_yang_validate_add(h, x0, &xerr)) < 0) goto done; @@ -357,7 +355,6 @@ main(int argc, goto done; } } - /* If xpath0 given, position current x (ie somewhere else than root) */ if (xpath0){ if ((x = xpath_first(x0, NULL, "%s", xpath0)) == NULL){ diff --git a/util/clixon_util_yang.c b/util/clixon_util_yang.c index ae6cc3fa..1c305575 100644 --- a/util/clixon_util_yang.c +++ b/util/clixon_util_yang.c @@ -104,7 +104,7 @@ main(int argc, char **argv) break; } clicon_log_init("clixon_util_yang", dbg?LOG_DEBUG:LOG_INFO, logdst); - clicon_debug_init(dbg, NULL); + clixon_debug_init(dbg, NULL); if ((yspec = yspec_new()) == NULL) goto done; if (yang_parse_file(stdin, "yang test", yspec) == NULL){