From 24a4991ec8bb35d5e8c2f8308149e20e57695cb2 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 13 Nov 2023 10:12:52 +0100 Subject: [PATCH] Restructured error,debug anf log API Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err() --- CHANGELOG.md | 33 +++ CONTRIBUTING.md | 2 +- apps/backend/backend_client.c | 147 +++++----- apps/backend/backend_client.h | 6 +- apps/backend/backend_commit.c | 72 ++--- apps/backend/backend_confirm.c | 96 +++---- apps/backend/backend_get.c | 86 +++--- apps/backend/backend_get.h | 6 +- apps/backend/backend_handle.h | 12 +- apps/backend/backend_main.c | 119 +++++---- apps/backend/backend_plugin.c | 116 ++++---- apps/backend/backend_plugin_restconf.c | 36 +-- apps/backend/backend_plugin_restconf.h | 2 +- apps/backend/backend_socket.c | 44 +-- apps/backend/backend_socket.h | 2 +- apps/backend/backend_startup.c | 19 +- apps/backend/backend_startup.h | 6 +- apps/backend/clixon_backend_client.h | 2 +- apps/backend/clixon_backend_commit.h | 38 +-- apps/backend/clixon_backend_handle.c | 36 +-- apps/backend/clixon_backend_plugin.h | 46 ++-- apps/backend/clixon_backend_transaction.c | 16 +- apps/backend/clixon_backend_transaction.h | 4 +- apps/cli/cli_auto.c | 46 ++-- apps/cli/cli_autocli.c | 58 ++-- apps/cli/cli_autocli.h | 14 +- apps/cli/cli_common.c | 242 ++++++++++------- apps/cli/cli_common.h | 4 +- apps/cli/cli_generate.c | 108 ++++---- apps/cli/cli_generate.h | 4 +- apps/cli/cli_handle.c | 34 +-- apps/cli/cli_handle.h | 10 +- apps/cli/cli_main.c | 88 +++--- apps/cli/cli_pipe.c | 32 +-- apps/cli/cli_plugin.c | 80 +++--- apps/cli/cli_plugin.h | 8 +- apps/cli/cli_show.c | 111 ++++---- apps/cli/clixon_cli.h | 6 +- apps/cli/clixon_cli_api.h | 114 ++++---- apps/netconf/netconf_filter.c | 2 +- apps/netconf/netconf_main.c | 85 +++--- apps/netconf/netconf_rpc.c | 34 +-- apps/netconf/netconf_rpc.h | 2 +- apps/restconf/clixon_http1_parse.h | 2 +- apps/restconf/clixon_http1_parse.y | 10 +- apps/restconf/clixon_http_data.c | 34 +-- apps/restconf/clixon_http_data.h | 4 +- apps/restconf/clixon_restconf.h | 8 +- apps/restconf/restconf_api.c | 2 +- apps/restconf/restconf_api_fcgi.c | 14 +- apps/restconf/restconf_api_native.c | 16 +- apps/restconf/restconf_err.c | 26 +- apps/restconf/restconf_err.h | 12 +- apps/restconf/restconf_handle.c | 46 ++-- apps/restconf/restconf_handle.h | 26 +- apps/restconf/restconf_http1.c | 48 ++-- apps/restconf/restconf_http1.h | 12 +- apps/restconf/restconf_lib.c | 50 ++-- apps/restconf/restconf_lib.h | 16 +- apps/restconf/restconf_main_fcgi.c | 81 +++--- apps/restconf/restconf_main_native.c | 111 ++++---- apps/restconf/restconf_methods.c | 20 +- apps/restconf/restconf_methods.h | 10 +- apps/restconf/restconf_methods_get.c | 40 +-- apps/restconf/restconf_methods_get.h | 6 +- apps/restconf/restconf_methods_patch.c | 60 ++--- apps/restconf/restconf_methods_patch.h | 2 +- apps/restconf/restconf_methods_post.c | 36 +-- apps/restconf/restconf_methods_post.h | 4 +- apps/restconf/restconf_native.c | 164 ++++++------ apps/restconf/restconf_native.h | 16 +- apps/restconf/restconf_nghttp2.c | 38 +-- apps/restconf/restconf_root.c | 26 +- apps/restconf/restconf_root.h | 6 +- apps/restconf/restconf_stream.h | 8 +- apps/restconf/restconf_stream_fcgi.c | 22 +- apps/snmp/snmp_handler.c | 101 +++---- apps/snmp/snmp_lib.c | 72 ++--- apps/snmp/snmp_lib.h | 2 +- apps/snmp/snmp_main.c | 77 +++--- apps/snmp/snmp_register.c | 58 ++-- apps/snmp/snmp_register.h | 4 +- doc/FAQ.md | 18 +- example/main/README.md | 6 +- example/main/example_backend.c | 98 +++---- example/main/example_backend_nacm.c | 32 +-- example/main/example_cli.c | 26 +- example/main/example_netconf.c | 14 +- example/main/example_restconf.c | 28 +- include/clixon_custom.h | 7 + lib/clixon/clixon.h.in | 3 +- lib/clixon/clixon_data.h | 98 +++---- lib/clixon/clixon_datastore.h | 52 ++-- lib/clixon/clixon_debug.h | 60 +++++ lib/clixon/clixon_err.h | 45 ++-- lib/clixon/clixon_event.h | 2 +- lib/clixon/clixon_handle.h | 28 +- lib/clixon/clixon_log.h | 60 ++--- lib/clixon/clixon_nacm.h | 8 +- lib/clixon/clixon_netconf_lib.h | 34 +-- lib/clixon/clixon_netconf_monitoring.h | 6 +- lib/clixon/clixon_options.h | 84 +++--- lib/clixon/clixon_plugin.h | 96 +++---- lib/clixon/clixon_proc.h | 20 +- lib/clixon/clixon_proto.h | 8 +- lib/clixon/clixon_proto_client.h | 48 ++-- lib/clixon/clixon_regex.h | 6 +- lib/clixon/clixon_stream.h | 26 +- lib/clixon/clixon_validate.h | 12 +- lib/clixon/clixon_xml.h | 9 +- lib/clixon/clixon_xml_bind.h | 8 +- lib/clixon/clixon_xml_changelog.h | 6 +- lib/clixon/clixon_xml_default.h | 2 +- lib/clixon/clixon_xml_nsctx.h | 2 +- lib/clixon/clixon_yang.h | 6 +- lib/clixon/clixon_yang_module.h | 14 +- lib/clixon/clixon_yang_parse_lib.h | 14 +- lib/clixon/clixon_yang_schema_mount.h | 12 +- lib/clixon/clixon_yang_type.h | 2 +- lib/src/Makefile.in | 2 +- lib/src/clixon_api_path_parse.l | 1 + lib/src/clixon_api_path_parse.y | 26 +- lib/src/clixon_client.c | 89 +++--- lib/src/clixon_data.c | 111 ++++---- lib/src/clixon_datastore.c | 65 ++--- lib/src/clixon_datastore_read.c | 84 +++--- lib/src/clixon_datastore_read.h | 2 +- lib/src/clixon_datastore_write.c | 51 ++-- lib/src/clixon_datastore_write.h | 2 +- lib/src/clixon_debug.c | 165 ++++++++++++ lib/src/clixon_err.c | 306 +++++++++++++-------- lib/src/clixon_event.c | 19 +- lib/src/clixon_file.c | 37 +-- lib/src/clixon_handle.c | 71 ++--- lib/src/clixon_hash.c | 23 +- lib/src/clixon_instance_id_parse.l | 1 + lib/src/clixon_instance_id_parse.y | 31 +-- lib/src/clixon_json.c | 39 +-- lib/src/clixon_json_parse.l | 1 + lib/src/clixon_json_parse.y | 13 +- lib/src/clixon_log.c | 303 ++++++++------------- lib/src/clixon_nacm.c | 35 +-- lib/src/clixon_netconf_input.c | 15 +- lib/src/clixon_netconf_lib.c | 312 ++++++++++++---------- lib/src/clixon_netconf_monitoring.c | 29 +- lib/src/clixon_netns.c | 42 +-- lib/src/clixon_options.c | 116 ++++---- lib/src/clixon_path.c | 107 ++++---- lib/src/clixon_plugin.c | 196 +++++++------- lib/src/clixon_proc.c | 125 ++++----- lib/src/clixon_proto.c | 67 ++--- lib/src/clixon_proto_client.c | 201 +++++++++----- lib/src/clixon_regex.c | 19 +- lib/src/clixon_sig.c | 26 +- lib/src/clixon_stream.c | 97 +++---- lib/src/clixon_string.c | 64 ++--- lib/src/clixon_text_syntax.c | 43 +-- lib/src/clixon_text_syntax_parse.l | 2 +- lib/src/clixon_text_syntax_parse.y | 15 +- lib/src/clixon_uid.c | 34 +-- lib/src/clixon_validate.c | 54 ++-- lib/src/clixon_validate_minmax.c | 12 +- lib/src/clixon_xml.c | 85 +++--- lib/src/clixon_xml_bind.c | 72 ++--- lib/src/clixon_xml_changelog.c | 45 ++-- lib/src/clixon_xml_default.c | 18 +- lib/src/clixon_xml_io.c | 33 +-- lib/src/clixon_xml_map.c | 74 ++--- lib/src/clixon_xml_nsctx.c | 23 +- lib/src/clixon_xml_parse.l | 2 +- lib/src/clixon_xml_parse.y | 16 +- lib/src/clixon_xml_sort.c | 63 ++--- lib/src/clixon_xml_vec.c | 11 +- lib/src/clixon_xpath.c | 70 ++--- lib/src/clixon_xpath_ctx.c | 25 +- lib/src/clixon_xpath_eval.c | 69 ++--- lib/src/clixon_xpath_function.c | 41 +-- lib/src/clixon_xpath_optimize.c | 11 +- lib/src/clixon_xpath_parse.l | 1 + lib/src/clixon_xpath_parse.y | 30 +-- lib/src/clixon_xpath_yang.c | 27 +- lib/src/clixon_yang.c | 231 ++++++++-------- lib/src/clixon_yang_cardinality.c | 18 +- lib/src/clixon_yang_cardinality.h | 6 +- lib/src/clixon_yang_module.c | 53 ++-- lib/src/clixon_yang_parse.y | 11 +- lib/src/clixon_yang_parse_lib.c | 153 +++++------ lib/src/clixon_yang_schema_mount.c | 43 +-- lib/src/clixon_yang_schemanode_parse.l | 2 +- lib/src/clixon_yang_schemanode_parse.y | 11 +- lib/src/clixon_yang_sub_parse.c | 17 +- lib/src/clixon_yang_sub_parse.h | 4 +- lib/src/clixon_yang_sub_parse.l | 2 +- lib/src/clixon_yang_sub_parse.y | 13 +- lib/src/clixon_yang_type.c | 98 ++++--- test/lib.sh | 5 +- test/test_api.sh | 36 +-- test/test_c++.sh | 26 +- test/test_client.sh | 10 +- 199 files changed, 4668 insertions(+), 4158 deletions(-) create mode 100644 lib/clixon/clixon_debug.h create mode 100644 lib/src/clixon_debug.c diff --git a/CHANGELOG.md b/CHANGELOG.md index 8351b410..6d568f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,39 @@ Expected: February 2024 * Added reference count for shared yang-specs (schema mounts) * Allowed for sharing yspec+modules between several mountpoints +### C/CLI-API changes on existing features +Developers may need to change their code + +* Refactoring basic clixon modules and some API changes + * Changes marked in code with `COMPAT_6_5` + * Most common functions have backward compatible macros through the 6.6 release + * Handle API + * Renamed `clicon_handle` -> `clixon_handle` + * `clicon_handle_init()` -> `clixon_handle_init() + * `clicon_handle_exit()` -> `clixon_handle_exit() + * Log/Debug API + * Changed function names. You need to rename as follows: + * `clicon_log_init()` -> `clixon_log_init(h,)` NOTE added "clixon_handle h" + * `clicon_log()` -> `clixon_log(h,)` NOTE added "clixon_handle h" + * `clixon_debug_init(d, f)` -> `clixon_debug_init(h, )` NOTE h added, f removed + * `clicon_log_xml()` -> `clixon_debug_xml(h,)` NOTE added "clixon_handle h" + * `clixon_debug_xml()` -> `clixon_debug_xml(h,)` NOTE added "clixon_handle h" + * Error API: + * Added `clixon_err_init(h)` function + * Renaming, make the following changes: + * `clicon_err()` -> `clixon_err()` + * `clicon_err_reset()` -> `clixon_err_reset()` + * `clicon_strerror(int)` -> `clixon_err_str()` + * `clicon_netconf_error(h, x, fmt)` -> clixon_err_netconf(h, OE_XML, 0, x, fmt)` + * `netconf_err2cb(...)` --> `netconf_err2cb(h, ...)` + * Likewise for some other minor functions: `clicon_err_*` -> `clixon_err_*` + * Replaced global variables with access functions. Replace variables with functions as follows: + * `clicon_errno` -> `clixon_err_category()` + * `clicon_suberrno` -> `clixon_err_subnr()` + * `clicon_err_reason` -> `clixon_err_reason()` + * Changed process API: + * `clixon_proc_socket(...)` --> `clixon_proc_socket(h, ...)` + ### Corrected Bugs * Fixed: [Using the characters '<' and '>' might cause an invalid diff](https://github.com/clicon/clixon-controller/issues/73) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bae174ca..2ee40c5a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,7 +51,7 @@ is identified, exit as soon as possible and with an explicit error log. Errors are typically declared as follows: ``` if (myfn(0) < 0){ - clicon_err(OE_UNIX, EINVAL, "myfn"); + clixon_err(OE_UNIX, EINVAL, "myfn"); goto done; } ``` diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 0b4d8df1..f39a9616 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -62,7 +62,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_client.h" @@ -105,11 +105,11 @@ ce_client_descr(struct client_entry *ce, char *id = NULL; if (ce == NULL || cbp == NULL){ - clicon_err(OE_UNIX, EINVAL, "ce or cbp is NULL"); + clixon_err(OE_UNIX, EINVAL, "ce or cbp is NULL"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (ce->ce_transport){ @@ -137,7 +137,7 @@ ce_client_descr(struct client_entry *ce, * @see stream_ss_add */ int -ce_event_cb(clicon_handle h, +ce_event_cb(clixon_handle h, int op, cxobj *event, void *arg) @@ -158,7 +158,7 @@ ce_event_cb(clicon_handle h, goto done; if (send_msg_notify_xml(h, ce->ce_s, cbuf_get(cbce), event) < 0){ if (errno == ECONNRESET || errno == EPIPE){ - clicon_log(LOG_WARNING, "client %d reset", ce->ce_nr); + clixon_log(h, LOG_WARNING, "client %d reset", ce->ce_nr); } break; } @@ -179,7 +179,7 @@ ce_event_cb(clicon_handle h, * @see xmldb_unlock_all unlocks, but does not call user callbacks which is a backend thing */ static int -release_all_dbs(clicon_handle h, +release_all_dbs(clixon_handle h, uint32_t id) { int retval = -1; @@ -224,7 +224,7 @@ release_all_dbs(clicon_handle h, * @see RFC 6022 */ int -backend_monitoring_state_get(clicon_handle h, +backend_monitoring_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, @@ -238,7 +238,7 @@ backend_monitoring_state_get(clicon_handle h, int ret; if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "", NETCONF_MONITORING_NAMESPACE); @@ -248,7 +248,7 @@ backend_monitoring_state_get(clicon_handle h, cprintf(cb, "%u", ce->ce_id); if (ce->ce_transport == NULL){ #ifdef NOTYET // XXX: too strict, race conditions in clixon_snmp - clicon_err(OE_XML, 0, "Mandatory element transport missing"); + clixon_err(OE_XML, 0, "Mandatory element transport missing"); goto done; #else cprintf(cb, "cl:netconf", @@ -264,7 +264,7 @@ backend_monitoring_state_get(clicon_handle h, cprintf(cb, "%s", ce->ce_source_host); if (ce->ce_time.tv_sec != 0){ if (time2str(&ce->ce_time, timestr, sizeof(timestr)) < 0){ - clicon_err(OE_UNIX, errno, "time2str"); + clixon_err(OE_UNIX, errno, "time2str"); goto done; } cprintf(cb, "%s", timestr); @@ -304,7 +304,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(clixon_handle h, struct client_entry *ce) { struct client_entry *c; @@ -316,7 +316,7 @@ backend_client_rm(clicon_handle h, /* If the confirmed-commit feature is enabled, rollback any ephemeral commit originated by this client */ if ((yspec = clicon_dbspec_yang(h)) == NULL) { - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { @@ -326,7 +326,7 @@ backend_client_rm(clicon_handle h, if (myid == confirmed_commit_session_id_get(h)) { clixon_debug(CLIXON_DBG_DEFAULT, "ok, rolling back"); - clicon_log(LOG_NOTICE, "a client with an active ephemeral confirmed-commit has disconnected; rolling back"); + clixon_log(h, 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 * ignored here. @@ -369,7 +369,7 @@ backend_client_rm(clicon_handle h, * @retval -1 Error */ static int -clixon_stats_datastore_get(clicon_handle h, +clixon_stats_datastore_get(clixon_handle h, char *dbname, cbuf *cb) { @@ -412,7 +412,7 @@ clixon_stats_datastore_get(clicon_handle h, * @retval -1 Error */ static int -clixon_stats_module_get(clicon_handle h, +clixon_stats_module_get(clixon_handle h, yang_stmt *ys, cbuf *cb) { @@ -452,7 +452,7 @@ clixon_stats_module_get(clicon_handle h, * But this could discard other previous changes to candidate. */ static int -from_client_edit_config(clicon_handle h, +from_client_edit_config(clixon_handle h, cxobj *xn, cbuf *cbret, void *arg, @@ -480,7 +480,7 @@ from_client_edit_config(clicon_handle h, username = clicon_username_get(h); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec9"); + clixon_err(OE_YANG, ENOENT, "No yang spec9"); goto done; } if ((target = netconf_db_find(xn, "target")) == NULL){ @@ -489,7 +489,7 @@ from_client_edit_config(clicon_handle h, goto ok; } if ((cbx = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } /* Check if target locked by other client */ @@ -572,7 +572,7 @@ from_client_edit_config(clicon_handle h, if (xml_sort_recurse(xc) < 0) goto done; if ((ret = xmldb_put(h, target, operation, xc, username, cbret)) < 0){ - if (netconf_operation_failed(cbret, "protocol", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "protocol", clixon_err_reason())< 0) goto done; goto ok; } @@ -614,14 +614,14 @@ from_client_edit_config(clicon_handle h, } } if ((ret = candidate_commit(h, NULL, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */ - if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; xmldb_copy(h, "running", "candidate"); goto ok; } if (ret == 0){ /* discard */ if (xmldb_copy(h, "running", "candidate") < 0){ - if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; goto ok; } @@ -632,13 +632,13 @@ from_client_edit_config(clicon_handle h, if ((attr = xml_find_value(xn, "copystartup")) != NULL && strcmp(attr,"true") == 0){ if (xmldb_copy(h, "running", "startup") < 0){ - if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; goto ok; } } if (cbuf_len(cbret) != 0){ - clicon_err(OE_NETCONF, EINVAL, "Internal error: cbret is not empty"); + clixon_err(OE_NETCONF, EINVAL, "Internal error: cbret is not empty"); goto done; } cprintf(cbret, " */ static int -from_client_create_subscription(clicon_handle h, +from_client_create_subscription(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1163,7 +1163,7 @@ from_client_create_subscription(clicon_handle h, * @see RFC6022, ietf-netconf-monitoring.yang */ static int -from_client_get_schema(clicon_handle h, +from_client_get_schema(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1184,7 +1184,7 @@ from_client_get_schema(clicon_handle h, const char *filename; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } if ((nsc = xml_nsctx_init(NULL, NETCONF_MONITORING_NAMESPACE)) == NULL) @@ -1229,7 +1229,7 @@ from_client_get_schema(clicon_handle h, } if (ymatch == NULL){ if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (version) @@ -1242,7 +1242,7 @@ from_client_get_schema(clicon_handle h, } if (format && strcmp(format, "yang") != 0){ if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cbmsg, "Format not supported: %s", format); @@ -1253,7 +1253,7 @@ from_client_get_schema(clicon_handle h, cprintf(cbret, "", NETCONF_BASE_NAMESPACE, NETCONF_MONITORING_NAMESPACE); if ((cbyang = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((filename = yang_filename_get(ymatch)) != NULL){ @@ -1285,7 +1285,7 @@ from_client_get_schema(clicon_handle h, * @retval -1 Error */ static int -from_client_debug(clicon_handle h, +from_client_debug(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1302,9 +1302,9 @@ from_client_debug(clicon_handle h, } level = atoi(valstr); - clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ + clixon_debug_init(h, level); /* 0: dont debug, 1:debug */ setlogmask(LOG_UPTO(level?LOG_DEBUG:LOG_INFO)); /* for syslog */ - clicon_log(LOG_NOTICE, "%s debug:%d", __FUNCTION__, clixon_debug_get()); + clixon_log(h, LOG_NOTICE, "%s debug:%d", __FUNCTION__, clixon_debug_get()); cprintf(cbret, "", NETCONF_BASE_NAMESPACE); ok: retval = 0; @@ -1323,7 +1323,7 @@ from_client_debug(clicon_handle h, * @retval -1 Error */ static int -from_client_ping(clicon_handle h, +from_client_ping(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1344,7 +1344,7 @@ from_client_ping(clicon_handle h, * @retval -1 Error */ static int -from_client_stats(clicon_handle h, +from_client_stats(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1437,7 +1437,7 @@ from_client_stats(clicon_handle h, * @retval -1 Error */ static int -from_client_restart_plugin(clicon_handle h, +from_client_restart_plugin(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1485,7 +1485,7 @@ from_client_restart_plugin(clicon_handle h, * @retval -1 Error */ static int -from_client_process_control(clicon_handle h, +from_client_process_control(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1529,7 +1529,7 @@ from_client_process_control(clicon_handle h, * @retval -1 Error */ static int -from_client_hello(clicon_handle h, +from_client_hello(clixon_handle h, cxobj *x, struct client_entry *ce, cbuf *cbret) @@ -1539,13 +1539,13 @@ from_client_hello(clicon_handle h, if ((val = xml_find_type_value(x, "cl", "transport", CX_ATTR)) != NULL){ if ((ce->ce_transport = strdup(val)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } if ((val = xml_find_type_value(x, "cl", "source-host", CX_ATTR)) != NULL){ if ((ce->ce_source_host = strdup(val)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1566,7 +1566,7 @@ from_client_hello(clicon_handle h, * propagated back to client. */ static int -from_client_msg(clicon_handle h, +from_client_msg(clixon_handle h, struct client_entry *ce, struct clicon_msg *msg) { @@ -1598,7 +1598,7 @@ from_client_msg(clicon_handle h, * as wither rpc-error or by positive response. */ if ((cbret = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } /* Decode msg from client -> xml top (ct) and session id @@ -1627,7 +1627,7 @@ from_client_msg(clicon_handle h, goto reply; } if ((x = xml_child_i_type(xt, 0, CX_ELMNT)) == NULL){ /* Shouldnt happen */ - clicon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)"); + clixon_err(OE_XML, EFAULT, "No xml req (shouldnt happen)"); goto done; } rpcname = xml_name(x); @@ -1647,7 +1647,7 @@ from_client_msg(clicon_handle h, (ce0 = ce_find_byid(backend_client_list(h), op_id)) != NULL && ce0->ce_transport){ if ((ce->ce_transport = strdup(ce0->ce_transport)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1665,7 +1665,7 @@ from_client_msg(clicon_handle h, else if (strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){ cbuf *cbmsg = NULL; if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cbmsg, "No appropriate namespace found for: %s %s", rpcprefix, rpcname); @@ -1724,7 +1724,7 @@ from_client_msg(clicon_handle h, goto reply; } if ((ymod = ys_module(ye)) == NULL){ - clicon_err(OE_XML, ENOENT, "rpc yang does not have module"); + clixon_err(OE_XML, ENOENT, "rpc yang does not have module"); goto done; } module = yang_argument_get(ymod); @@ -1762,11 +1762,11 @@ from_client_msg(clicon_handle h, goto reply; } } - clicon_err_reset(); + clixon_err_reset(); if ((ret = rpc_callback_call(h, xe, ce, &nr, cbret)) < 0){ - if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; - clicon_log(LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe)); + clixon_log(h, LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe)); ce->ce_out_rpc_errors++; netconf_monitoring_counter_inc(h, "out-rpc-errors"); goto reply; /* Dont quit here on user callbacks */ @@ -1792,7 +1792,8 @@ from_client_msg(clicon_handle h, } /* while */ reply: if (cbuf_len(cbret) == 0) - if (netconf_operation_failed(cbret, "application", clicon_errno?clicon_err_reason:"unknown")< 0) + if (netconf_operation_failed(cbret, "application", + clixon_err_category()?clixon_err_reason():"unknown")< 0) goto done; // XXX clixon_debug(CLIXON_DBG_MSG, "Reply:%s", cbuf_get(cbret)); /* XXX problem here is that cbret has not been parsed so may contain @@ -1810,7 +1811,7 @@ from_client_msg(clicon_handle h, * the (UNIX domain) socket. */ case ECONNRESET: - clicon_log(LOG_WARNING, "client rpc reset"); + clixon_log(h, LOG_WARNING, "client rpc reset"); break; default: goto done; @@ -1833,9 +1834,9 @@ from_client_msg(clicon_handle h, cbuf_free(cbce); if (cbret) cbuf_free(cbret); - /* Sanity: log if clicon_err() is not called ! */ - if (retval < 0 && clicon_errno < 0) - clicon_log(LOG_NOTICE, "%s: Internal error: No clicon_err call on RPC error (message: %s)", + /* Sanity: log if clixon_err() is not called ! */ + if (retval < 0 && clixon_err_category() < 0) + clixon_log(h, LOG_NOTICE, "%s: Internal error: No clixon_err call on RPC error (message: %s)", __FUNCTION__, rpc?rpc:""); // clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); return retval;// -1 here terminates backend @@ -1856,13 +1857,13 @@ from_client(int s, int retval = -1; struct clicon_msg *msg = NULL; struct client_entry *ce = (struct client_entry *)arg; - clicon_handle h = ce->ce_handle; + clixon_handle h = ce->ce_handle; int eof = 0; cbuf *cbce = NULL; clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (s != ce->ce_s){ - clicon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s"); + clixon_err(OE_NETCONF, EINVAL, "Internal error: s != ce->ce_s"); goto done; } if (ce_client_descr(ce, &cbce) < 0) @@ -1894,7 +1895,7 @@ from_client(int s, * @see ietf-netconf@2011-06-01.yang */ int -backend_rpc_init(clicon_handle h) +backend_rpc_init(clixon_handle h) { int retval = -1; diff --git a/apps/backend/backend_client.h b/apps/backend/backend_client.h index 5d2547c9..41927117 100644 --- a/apps/backend/backend_client.h +++ b/apps/backend/backend_client.h @@ -40,9 +40,9 @@ /* * 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 backend_monitoring_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); +int backend_client_rm(clixon_handle h, struct client_entry *ce); int from_client(int fd, void *arg); -int backend_rpc_init(clicon_handle h); +int backend_rpc_init(clixon_handle h); #endif /* _BACKEND_CLIENT_H_ */ diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index b1d8b8d0..fa11b3b7 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -62,7 +62,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -90,7 +90,7 @@ * @retval -1 Error */ static int -generic_validate(clicon_handle h, +generic_validate(clixon_handle h, yang_stmt *yspec, transaction_data_t *td, cxobj **xret) @@ -158,7 +158,7 @@ generic_validate(clicon_handle h, * @see validate_common for incoming validate/commit */ static int -startup_common(clicon_handle h, +startup_common(clixon_handle h, char *db, transaction_data_t *td, cbuf *cbret) @@ -189,7 +189,7 @@ startup_common(clicon_handle h, /* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */ if (clicon_quit_upgrade_get(h) == 1){ xml_print(stderr, xerr); - clicon_err(OE_XML, 0, "invalid configuration before upgrade"); + clixon_err(OE_XML, 0, "invalid configuration before upgrade"); exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding * See similar clause below */ @@ -205,12 +205,12 @@ startup_common(clicon_handle h, } 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" + clixon_log(h, 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" "It may also be normal bootstrapping since module state will be written on next datastore save"); } if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, 0, "Yang spec not set"); + clixon_err(OE_YANG, 0, "Yang spec not set"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "Reading startup config done"); @@ -237,16 +237,16 @@ startup_common(clicon_handle h, if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xret)) < 1){ if (ret == 0){ /* invalid */ - clicon_err(OE_XML, EFAULT, "invalid configuration"); + clixon_err(OE_XML, EFAULT, "invalid configuration"); } else { /* error */ xml_print(stderr, xret); - clicon_err(OE_XML, 0, "%s: YANG binding error", __func__); + clixon_err(OE_XML, 0, "%s: YANG binding error", __func__); } } /* sort yang */ else if (xml_sort_recurse(xt) < 0) { - clicon_err(OE_XML, EFAULT, "Yang sort error"); + clixon_err(OE_XML, EFAULT, "Yang sort error"); } if (xmldb_dump(h, stdout, xt) < 0) goto done; @@ -345,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(clixon_handle h, char *db, cxobj **xtr, cbuf *cbret) @@ -396,7 +396,7 @@ startup_validate(clicon_handle h, * Only called from startup_mode_startup */ int -startup_commit(clicon_handle h, +startup_commit(clixon_handle h, char *db, cbuf *cbret) { @@ -405,7 +405,7 @@ startup_commit(clicon_handle h, transaction_data_t *td = NULL; if (strcmp(db,"running")==0){ - clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db); + clixon_err(OE_FATAL, 0, "Invalid startup db: %s", db); goto done; } /* Handcraft a transition with only target and add trees */ @@ -479,7 +479,7 @@ startup_commit(clicon_handle h, * @see startup_common for startup scenario */ static int -validate_common(clicon_handle h, +validate_common(clixon_handle h, char *db, transaction_data_t *td, cxobj **xret) @@ -491,7 +491,7 @@ validate_common(clicon_handle h, int ret; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } /* This is the state we are going to */ @@ -581,7 +581,7 @@ validate_common(clicon_handle h, * @retval -1 Error - or validation failed */ int -candidate_validate(clicon_handle h, +candidate_validate(clixon_handle h, char *db, cbuf *cbret) { @@ -592,7 +592,7 @@ candidate_validate(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (db == NULL || cbret == NULL){ - clicon_err(OE_CFG, EINVAL, "db or cbret is NULL"); + clixon_err(OE_CFG, EINVAL, "db or cbret is NULL"); goto done; } /* 1. Start transaction */ @@ -602,23 +602,23 @@ candidate_validate(clicon_handle h, if ((ret = validate_common(h, db, td, &xret)) < 0){ /* A little complex due to several sources of validation fails or errors. * (1) xerr is set -> translate to cbret; (2) cbret set use that; otherwise - * use clicon_err. + * use clixon_err. * TODO: -1 return should be fatal error, not failed validation */ if (!cbuf_len(cbret) && - netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; goto fail; } if (ret == 0){ if (xret == NULL){ - clicon_err(OE_CFG, EINVAL, "xret is NULL"); + clixon_err(OE_CFG, EINVAL, "xret is NULL"); goto done; } if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (!cbuf_len(cbret) && - netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; goto fail; } @@ -660,7 +660,7 @@ candidate_validate(clicon_handle h, * @retval -1 Error - or validation failed */ int -candidate_commit(clicon_handle h, +candidate_commit(clixon_handle h, cxobj *xe, char *db, uint32_t myid, @@ -694,7 +694,7 @@ candidate_commit(clicon_handle h, * to activate it. */ if ((yspec = clicon_dbspec_yang(h)) == NULL) { - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } @@ -786,7 +786,7 @@ candidate_commit(clicon_handle h, * candidate_commit() method. */ int -from_client_commit(clicon_handle h, +from_client_commit(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -801,7 +801,7 @@ from_client_commit(clicon_handle h, yang_stmt *yspec; if ((yspec = clicon_dbspec_yang(h)) == NULL) { - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { @@ -814,7 +814,7 @@ from_client_commit(clicon_handle h, iddb = xmldb_islocked(h, "running"); if (iddb && myid != iddb){ if ((cbx = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (netconf_in_use(cbret, "protocol", "Operation failed, lock is already held") < 0) @@ -824,7 +824,7 @@ from_client_commit(clicon_handle h, if ((ret = candidate_commit(h, xe, "candidate", myid, 0, cbret)) < 0){ /* Assume validation fail, nofatal */ clixon_debug(CLIXON_DBG_DEFAULT, "Commit candidate failed"); if (ret < 0) - if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; goto ok; } @@ -852,7 +852,7 @@ from_client_commit(clicon_handle h, * NACM: No datastore permissions are needed. */ int -from_client_discard_changes(clicon_handle h, +from_client_discard_changes(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -868,7 +868,7 @@ from_client_discard_changes(clicon_handle h, iddb = xmldb_islocked(h, "candidate"); if (iddb && myid != iddb){ if ((cbx = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cbx, "%u", iddb); @@ -877,7 +877,7 @@ from_client_discard_changes(clicon_handle h, goto ok; } if (xmldb_copy(h, "running", "candidate") < 0){ - if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) + if (netconf_operation_failed(cbret, "application", clixon_err_reason())< 0) goto done; goto ok; } @@ -903,7 +903,7 @@ from_client_discard_changes(clicon_handle h, * @retval -1 Error */ int -from_client_validate(clicon_handle h, +from_client_validate(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -935,7 +935,7 @@ from_client_validate(clicon_handle h, * difficult in the general case. */ int -from_client_restart_one(clicon_handle h, +from_client_restart_one(clixon_handle h, clixon_plugin_t *cp, cbuf *cbret) { @@ -1065,7 +1065,7 @@ running ----|-------+---------------> RUNNING FAILSAFE tmp |----------------------> */ int -load_failsafe(clicon_handle h, +load_failsafe(clixon_handle h, char *phase) { int retval = -1; @@ -1076,13 +1076,13 @@ load_failsafe(clicon_handle h, phase = phase == NULL ? "(unknown)" : phase; if ((cbret = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if ((ret = xmldb_exists(h, db)) < 0) goto done; if (ret == 0){ /* No it does not exist, fail */ - clicon_err(OE_DB, 0, "%s failed and no Failsafe database found, exiting", phase); + clixon_err(OE_DB, 0, "%s failed and no Failsafe database found, exiting", phase); goto done; } /* Copy original running to tmp as backup (restore if error) */ @@ -1097,10 +1097,10 @@ load_failsafe(clicon_handle h, if (ret < 0) goto done; if (ret == 0){ - clicon_err(OE_DB, 0, "%s failed, Failsafe database validation failed %s", phase, cbuf_get(cbret)); + clixon_err(OE_DB, 0, "%s failed, Failsafe database validation failed %s", phase, cbuf_get(cbret)); goto done; } - clicon_log(LOG_NOTICE, "%s failed, Failsafe database loaded ", phase); + clixon_log(h, LOG_NOTICE, "%s failed, Failsafe database loaded ", phase); retval = 0; done: if (cbret) diff --git a/apps/backend/backend_confirm.c b/apps/backend/backend_confirm.c index e539b3d9..b7654450 100644 --- a/apps/backend/backend_confirm.c +++ b/apps/backend/backend_confirm.c @@ -62,7 +62,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -83,17 +83,17 @@ struct confirmed_commit { char *cc_persist_id; /* a value given by a client in the confirmed-commit */ uint32_t cc_session_id; /* the session_id of the client that gave no value */ int (*cc_fn)(int, void*); /* function pointer for rollback event (rollback_fn()) */ - void *cc_arg; /* clicon_handle that will be passed to rollback_fn() */ + void *cc_arg; /* clixon_handle that will be passed to rollback_fn() */ }; int -confirmed_commit_init(clicon_handle h) +confirmed_commit_init(clixon_handle h) { int retval = -1; struct confirmed_commit *cc = NULL; if ((cc = calloc(1, sizeof(*cc))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } cc->cc_state = INACTIVE; @@ -110,7 +110,7 @@ confirmed_commit_init(clicon_handle h) * @retval 0 OK */ int -confirmed_commit_free(clicon_handle h) +confirmed_commit_free(clixon_handle h) { struct confirmed_commit *cc = NULL; @@ -128,7 +128,7 @@ confirmed_commit_free(clicon_handle h) * Accessor functions */ enum confirmed_commit_state -confirmed_commit_state_get(clicon_handle h) +confirmed_commit_state_get(clixon_handle h) { struct confirmed_commit *cc = NULL; @@ -137,7 +137,7 @@ confirmed_commit_state_get(clicon_handle h) } static int -confirmed_commit_state_set(clicon_handle h, +confirmed_commit_state_set(clixon_handle h, enum confirmed_commit_state state) { struct confirmed_commit *cc = NULL; @@ -148,7 +148,7 @@ confirmed_commit_state_set(clicon_handle h, } char * -confirmed_commit_persist_id_get(clicon_handle h) +confirmed_commit_persist_id_get(clixon_handle h) { struct confirmed_commit *cc = NULL; @@ -157,7 +157,7 @@ confirmed_commit_persist_id_get(clicon_handle h) } static int -confirmed_commit_persist_id_set(clicon_handle h, +confirmed_commit_persist_id_set(clixon_handle h, char *persist_id) { struct confirmed_commit *cc = NULL; @@ -167,7 +167,7 @@ confirmed_commit_persist_id_set(clicon_handle h, free(cc->cc_persist_id); if (persist_id){ if ((cc->cc_persist_id = strdup4(persist_id)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup4"); + clixon_err(OE_UNIX, errno, "strdup4"); return -1; } } @@ -177,7 +177,7 @@ confirmed_commit_persist_id_set(clicon_handle h, } uint32_t -confirmed_commit_session_id_get(clicon_handle h) +confirmed_commit_session_id_get(clixon_handle h) { struct confirmed_commit *cc = NULL; @@ -186,7 +186,7 @@ confirmed_commit_session_id_get(clicon_handle h) } static int -confirmed_commit_session_id_set(clicon_handle h, +confirmed_commit_session_id_set(clixon_handle h, uint32_t session_id) { struct confirmed_commit *cc = NULL; @@ -197,7 +197,7 @@ confirmed_commit_session_id_set(clicon_handle h, } static int -confirmed_commit_fn_arg_get(clicon_handle h, +confirmed_commit_fn_arg_get(clixon_handle h, int (**fn)(int, void*), void **arg) { @@ -210,7 +210,7 @@ confirmed_commit_fn_arg_get(clicon_handle h, } static int -confirmed_commit_fn_arg_set(clicon_handle h, +confirmed_commit_fn_arg_set(clixon_handle h, int (*fn)(int, void*), void *arg) { @@ -300,7 +300,7 @@ xe_timeout(cxobj *xe) * @retval -1 No Rollback event was found */ int -cancel_rollback_event(clicon_handle h) +cancel_rollback_event(clixon_handle h) { int retval; int (*fn)(int, void*) = NULL; @@ -308,9 +308,9 @@ cancel_rollback_event(clicon_handle h) confirmed_commit_fn_arg_get(h, &fn, &arg); if ((retval = clixon_event_unreg_timeout(fn, arg)) == 0) { - clicon_log(LOG_INFO, "a scheduled rollback event has been cancelled"); + clixon_log(h, LOG_INFO, "a scheduled rollback event has been cancelled"); } else { - clicon_log(LOG_WARNING, "the specified scheduled rollback event was not found"); + clixon_log(h, LOG_WARNING, "the specified scheduled rollback event was not found"); } return retval; @@ -319,7 +319,7 @@ cancel_rollback_event(clicon_handle h) /*! Apply the rollback configuration upon expiration of the confirm-timeout * * @param[in] fd a dummy argument per the event callback semantics - * @param[in] arg a void pointer to a clicon_handle + * @param[in] arg a void pointer to a clixon_handle * @retval 0 the rollback was successful * @retval -1 the rollback failed * @see do_rollback() @@ -328,9 +328,9 @@ static int rollback_fn(int fd, void *arg) { - clicon_handle h = arg; + clixon_handle h = arg; - clicon_log(LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back"); + clixon_log(NULL, LOG_CRIT, "a confirming-commit was not received before the confirm-timeout expired; rolling back"); return do_rollback(h, NULL); } @@ -344,7 +344,7 @@ rollback_fn(int fd, * @retval -1 Rollback event was not scheduled */ static int -schedule_rollback_event(clicon_handle h, +schedule_rollback_event(clixon_handle h, uint32_t timeout) { int retval = -1; @@ -352,7 +352,7 @@ schedule_rollback_event(clicon_handle h, // register a new scheduled event struct timeval t, t1; if (gettimeofday(&t, NULL) < 0) { - clicon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno)); + clixon_err(OE_UNIX, 0, "failed to get time of day: %s", strerror(errno)); goto done; }; t1.tv_sec = timeout; t1.tv_usec = 0; @@ -383,7 +383,7 @@ schedule_rollback_event(clicon_handle h, * @retval 0 OK */ int -cancel_confirmed_commit(clicon_handle h) +cancel_confirmed_commit(clixon_handle h) { cancel_rollback_event(h); @@ -395,7 +395,7 @@ cancel_confirmed_commit(clicon_handle h) confirmed_commit_state_set(h, INACTIVE); if (xmldb_delete(h, "rollback") < 0) - clicon_err(OE_DB, 0, "Error deleting the rollback configuration"); + clixon_err(OE_DB, 0, "Error deleting the rollback configuration"); return 0; } @@ -414,7 +414,7 @@ cancel_confirmed_commit(clicon_handle h) * @retval -1 Error */ static int -check_valid_confirming_commit(clicon_handle h, +check_valid_confirming_commit(clixon_handle h, cxobj *xe, uint32_t myid) { @@ -422,7 +422,7 @@ check_valid_confirming_commit(clicon_handle h, char *persist_id = NULL; if (xe == NULL){ - clicon_err(OE_CFG, EINVAL, "xe is NULL"); + clixon_err(OE_CFG, EINVAL, "xe is NULL"); goto done; } if (myid == 0) @@ -435,13 +435,13 @@ check_valid_confirming_commit(clicon_handle h, break; // valid } else { - clicon_log(LOG_INFO, + clixon_log(h, LOG_INFO, "a persistent confirmed-commit is in progress but the client issued a " "confirming-commit with an incorrect persist-id"); goto invalid; } } else { - clicon_log(LOG_INFO, + clixon_log(h, LOG_INFO, "a persistent confirmed-commit is in progress but the client issued a confirming-commit" "without a persist-id"); goto invalid; @@ -453,7 +453,7 @@ check_valid_confirming_commit(clicon_handle h, */ break; // valid } - clicon_log(LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was" + clixon_log(h, LOG_DEBUG, "an ephemeral confirmed-commit is in progress, but there confirming-commit was" "not issued on the same session as the confirmed-commit"); goto invalid; default: @@ -485,7 +485,7 @@ check_valid_confirming_commit(clicon_handle h, * actually occur, and if so, if they are correctly handled. The calls are from do_rollback() and load_failsafe() */ int -handle_confirmed_commit(clicon_handle h, +handle_confirmed_commit(clixon_handle h, cxobj *xe, uint32_t myid) { @@ -496,7 +496,7 @@ handle_confirmed_commit(clicon_handle h, int db_exists; if (xe == NULL){ - clicon_err(OE_CFG, EINVAL, "xe is NULL"); + clixon_err(OE_CFG, EINVAL, "xe is NULL"); goto done; } if (myid == 0) @@ -509,7 +509,7 @@ handle_confirmed_commit(clicon_handle h, cc_valid = check_valid_confirming_commit(h, xe, myid); if (cc_valid) { if (cancel_rollback_event(h) < 0) { - clicon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found"); + clixon_err(OE_DAEMON, 0, "A valid confirming-commit was received, but the corresponding rollback event was not found"); } if (confirmed_commit_state_get(h) == PERSISTENT && @@ -537,7 +537,7 @@ handle_confirmed_commit(clicon_handle h, * */ confirmed_commit_state_set(h, PERSISTENT); - clicon_log(LOG_INFO, + clixon_log(h, LOG_INFO, "a persistent confirmed-commit has been requested with persist id of '%s' and a timeout of %lu seconds", confirmed_commit_persist_id_get(h), confirm_timeout); } @@ -549,7 +549,7 @@ handle_confirmed_commit(clicon_handle h, confirmed_commit_session_id_set(h, myid); confirmed_commit_state_set(h, EPHEMERAL); - clicon_log(LOG_INFO, + clixon_log(h, LOG_INFO, "an ephemeral confirmed-commit has been requested by session-id %u and a timeout of %lu seconds", confirmed_commit_session_id_get(h), confirm_timeout); @@ -586,18 +586,18 @@ handle_confirmed_commit(clicon_handle h, db_exists = xmldb_exists(h, "rollback"); if (db_exists == -1) { - clicon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database"); + clixon_err(OE_DAEMON, 0, "there was an error while checking existence of the rollback database"); goto done; } else if (db_exists == 0) { // db does not yet exists if (xmldb_copy(h, "running", "rollback") < 0) { - clicon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database."); + clixon_err(OE_DAEMON, 0, "there was an error while copying the running configuration to rollback database."); goto done; }; } if (schedule_rollback_event(h, confirm_timeout) < 0) { - clicon_err(OE_DAEMON, 0, "the rollback event could not be scheduled"); + clixon_err(OE_DAEMON, 0, "the rollback event could not be scheduled"); goto done; }; @@ -607,7 +607,7 @@ handle_confirmed_commit(clicon_handle h, * The new configuration is already committed to running and the rollback database can now be deleted */ if (xmldb_delete(h, "rollback") < 0) { - clicon_err(OE_DB, 0, "Error deleting the rollback configuration"); + clixon_err(OE_DB, 0, "Error deleting the rollback configuration"); goto done; } } @@ -635,7 +635,7 @@ handle_confirmed_commit(clicon_handle h, * @see rollback_fn() */ int -do_rollback(clicon_handle h, +do_rollback(clixon_handle h, uint8_t *errs) { int retval = -1; @@ -643,13 +643,13 @@ do_rollback(clicon_handle h, cbuf *cbret; if ((cbret = cbuf_new()) == NULL) { - clicon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno)); + clixon_err(OE_DAEMON, 0, "rollback was not performed. (cbuf_new: %s)", strerror(errno)); /* the rollback_db won't be deleted, so one can try recovery by: * load rollback running * restart the backend, which will try to load the rollback_db, and delete it if successful * (otherwise it will load the failsafe) */ - clicon_log(LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted."); + clixon_log(h, LOG_CRIT, "An error occurred during rollback and the rollback_db wasn't deleted."); errstate |= ROLLBACK_NOT_APPLIED | ROLLBACK_DB_NOT_DELETED; goto done; } @@ -663,19 +663,19 @@ do_rollback(clicon_handle h, /* theoretically, this should never error, since the rollback database was previously active and therefore * had itself been previously and successfully committed. */ - clicon_log(LOG_CRIT, "An error occurred committing the rollback database."); + clixon_log(h, LOG_CRIT, "An error occurred committing the rollback database."); errstate |= ROLLBACK_NOT_APPLIED; /* Rename the errored rollback database */ if (xmldb_rename(h, "rollback", NULL, ".error") < 0) { - clicon_log(LOG_CRIT, "An error occurred renaming the rollback database."); + clixon_log(h, LOG_CRIT, "An error occurred renaming the rollback database."); errstate |= ROLLBACK_DB_NOT_DELETED; } /* Attempt to load the failsafe config */ if (load_failsafe(h, "Rollback") < 0) { - clicon_log(LOG_CRIT, "An error occurred committing the failsafe database. Exiting."); + clixon_log(h, LOG_CRIT, "An error occurred committing the failsafe database. Exiting."); /* Invoke our own signal handler to exit */ raise(SIGINT); @@ -688,7 +688,7 @@ do_rollback(clicon_handle h, cbuf_free(cbret); if (xmldb_delete(h, "rollback") < 0) { - clicon_log(LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted."); + clixon_log(h, LOG_WARNING, "A rollback occurred but the rollback_db wasn't deleted."); errstate |= ROLLBACK_DB_NOT_DELETED; goto done; }; @@ -717,7 +717,7 @@ do_rollback(clicon_handle h, * @see RFC 6241 Sec 8.4 */ int -from_client_cancel_commit(clicon_handle h, +from_client_cancel_commit(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -775,7 +775,7 @@ from_client_cancel_commit(clicon_handle h, if (do_rollback(h, NULL) < 0) goto done; cprintf(cbret, "", NETCONF_BASE_NAMESPACE); - clicon_log(LOG_INFO, "a confirmed-commit has been cancelled by client request"); + clixon_log(h, LOG_INFO, "a confirmed-commit has been cancelled by client request"); } retval = 0; done: @@ -793,7 +793,7 @@ from_client_cancel_commit(clicon_handle h, * @retval -1 Error */ int -from_client_confirmed_commit(clicon_handle h, +from_client_confirmed_commit(clixon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret) diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c index 39bece86..15be8bcc 100644 --- a/apps/backend/backend_get.c +++ b/apps/backend/backend_get.c @@ -62,7 +62,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_client.h" @@ -85,7 +85,7 @@ * @see rfc8040 Sections 9.1 */ static int -restconf_client_get_capabilities(clicon_handle h, +restconf_client_get_capabilities(clixon_handle h, yang_stmt *yspec, char *xpath, cxobj **xret) @@ -95,11 +95,11 @@ restconf_client_get_capabilities(clicon_handle h, cbuf *cb = NULL; if ((xrstate = xpath_first(*xret, NULL, "restconf-state")) == NULL){ - clicon_err(OE_YANG, ENOENT, "restconf-state not found in config node"); + clixon_err(OE_YANG, ENOENT, "restconf-state not found in config node"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, ""); @@ -129,7 +129,7 @@ restconf_client_get_capabilities(clicon_handle h, * @retval -1 Error (fatal) */ static int -client_get_streams(clicon_handle h, +client_get_streams(clixon_handle h, yang_stmt *yspec, char *xpath, yang_stmt *ymod, @@ -143,11 +143,11 @@ client_get_streams(clicon_handle h, int ret; if ((yns = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "%s yang namespace not found", yang_argument_get(ymod)); + clixon_err(OE_YANG, 0, "%s yang namespace not found", yang_argument_get(ymod)); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "<%s xmlns=\"%s\">", top, yang_argument_get(yns)); @@ -159,7 +159,7 @@ client_get_streams(clicon_handle h, cprintf(cb,"", top); if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){ - if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0) + if (xret && netconf_operation_failed_xml(xret, "protocol", clixon_err_reason())< 0) goto done; goto fail; } @@ -203,7 +203,7 @@ client_get_streams(clicon_handle h, * */ static int -get_statedata(clicon_handle h, +get_statedata(clixon_handle h, char *xpath, cvec *nsc, withdefaults_type wdef, @@ -220,20 +220,20 @@ get_statedata(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC5277")){ if ((ymod = yang_find_module_by_name(yspec, "clixon-rfc5277")) == NULL){ - clicon_err(OE_YANG, ENOENT, "yang module clixon-rfc5277 not found"); + clixon_err(OE_YANG, ENOENT, "yang module clixon-rfc5277 not found"); goto done; } if ((namespace = yang_find_mynamespace(ymod)) == NULL){ - clicon_err(OE_YANG, ENOENT, "clixon-rfc5277 namespace not found"); + clixon_err(OE_YANG, ENOENT, "clixon-rfc5277 namespace not found"); goto done; } cprintf(cb, "", namespace); @@ -246,11 +246,11 @@ get_statedata(clicon_handle h, } if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040")){ if ((ymod = yang_find_module_by_name(yspec, "ietf-restconf-monitoring")) == NULL){ - clicon_err(OE_YANG, ENOENT, "yang module ietf-restconf-monitoring not found"); + clixon_err(OE_YANG, ENOENT, "yang module ietf-restconf-monitoring not found"); goto done; } if ((namespace = yang_find_mynamespace(ymod)) == NULL){ - clicon_err(OE_YANG, ENOENT, "ietf-restconf-monitoring namespace not found"); + clixon_err(OE_YANG, ENOENT, "ietf-restconf-monitoring namespace not found"); goto done; } cbuf_reset(cb); @@ -406,7 +406,7 @@ get_statedata(clicon_handle h, * @retval -1 Error */ static int -filter_xpath_again(clicon_handle h, +filter_xpath_again(clixon_handle h, yang_stmt *yspec, cxobj *xret, cxobj **xvec, @@ -418,7 +418,7 @@ filter_xpath_again(clicon_handle h, int i; if (xret == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "xret is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "xret is NULL"); goto done; } /* If vectors are specified then mark the nodes found and @@ -456,7 +456,7 @@ filter_xpath_again(clicon_handle h, * @retval -1 Error */ static int -get_nacm_and_reply(clicon_handle h, +get_nacm_and_reply(clixon_handle h, cxobj *xret, cxobj **xvec, size_t xlen, @@ -505,7 +505,7 @@ get_nacm_and_reply(clicon_handle h, * @retval -1 Error */ static int -element2value(clicon_handle h, +element2value(clixon_handle h, cxobj *xe, char *name, char *defaultstr, @@ -535,7 +535,7 @@ element2value(clicon_handle h, * @retval -1 Error */ static int -list_pagination_hdr(clicon_handle h, +list_pagination_hdr(clixon_handle h, cxobj *xe, uint32_t *offset, uint32_t *limit, @@ -576,7 +576,7 @@ list_pagination_hdr(clicon_handle h, * XXX Lots of this code (in particular at the end) is copy of get_common */ static int -get_list_pagination(clicon_handle h, +get_list_pagination(clixon_handle h, struct client_entry *ce, cxobj *xe, netconf_content content, @@ -614,7 +614,7 @@ get_list_pagination(clicon_handle h, #endif if (cbret == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "cbret is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "cbret is NULL"); goto done; } /* Check if list/leaf-list */ @@ -622,10 +622,10 @@ get_list_pagination(clicon_handle h, goto done; if (ylist == NULL){ if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - /* error reason should be in clicon_err_reason */ + /* error reason should be in clixon_err_reason() */ cprintf(cbmsg, "Netconf get list-pagination: \"%s\" not found", xpath); if (netconf_invalid_value(cbret, "application", cbuf_get(cbmsg)) < 0) goto done; @@ -686,7 +686,7 @@ get_list_pagination(clicon_handle h, * relational operators <>. */ if ((cbpath = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* This uses xpath. Maybe limit should use parameters */ @@ -712,10 +712,10 @@ get_list_pagination(clicon_handle h, /* specific xpath */ if (xmldb_get0(h, db, YB_MODULE, nsc, xpath2?xpath2:"/", 1, wdef, &xret, NULL, NULL) < 0) { if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); + cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason()); if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) goto done; goto ok; @@ -752,12 +752,12 @@ get_list_pagination(clicon_handle h, goto done; if (ret == 0){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - /* error reason should be in clicon_err_reason */ + /* error reason should be in clixon_err_reason */ cprintf(cberr, "Internal error, pagination state callback invalid return : %s", - clicon_err_reason); + clixon_err_reason()); if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) goto done; if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) @@ -794,7 +794,7 @@ get_list_pagination(clicon_handle h, /* Add remaining attribute */ if ((cba = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cba, "%u", remaining); @@ -838,7 +838,7 @@ get_list_pagination(clicon_handle h, * @see from_client_get_config */ static int -get_common(clicon_handle h, +get_common(clixon_handle h, struct client_entry *ce, cxobj *xe, netconf_content content, @@ -875,7 +875,7 @@ get_common(clicon_handle h, 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"); + clixon_err(OE_YANG, ENOENT, "No yang spec9"); goto done; } if ((xfilter = xml_find(xe, "filter")) != NULL){ @@ -900,7 +900,7 @@ get_common(clicon_handle h, /* Clixon extensions: depth */ if ((attr = xml_find_value(xe, "depth")) != NULL){ if ((ret = parse_int32(attr, &depth, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_int32"); + clixon_err(OE_XML, errno, "parse_int32"); goto done; } if (ret == 0){ @@ -946,10 +946,10 @@ get_common(clicon_handle h, /* specific xpath */ if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, wdef, &xret, NULL, NULL) < 0) { if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); + cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason()); if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) goto done; goto ok; @@ -961,10 +961,10 @@ get_common(clicon_handle h, /* Whole config tree, for validate debug */ if (xmldb_get0(h, "running", YB_MODULE, nsc, NULL, 1, wdef, &xret, NULL, NULL) < 0) { if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); + cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason()); if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) goto done; goto ok; @@ -974,10 +974,10 @@ get_common(clicon_handle h, /* specific xpath */ if (xmldb_get0(h, db, YB_MODULE, nsc, xpath?xpath:"/", 1, wdef, &xret, NULL, NULL) < 0) { if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - cprintf(cbmsg, "Get %s datastore: %s", db, clicon_err_reason); + cprintf(cbmsg, "Get %s datastore: %s", db, clixon_err_reason()); if (netconf_operation_failed(cbret, "application", cbuf_get(cbmsg)) < 0) goto done; goto ok; @@ -1083,7 +1083,7 @@ get_common(clicon_handle h, * @see from_client_get */ int -from_client_get_config(clicon_handle h, +from_client_get_config(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1094,7 +1094,7 @@ from_client_get_config(clicon_handle h, struct client_entry *ce = (struct client_entry *)arg; if ((db = netconf_db_find(xe, "source")) == NULL){ - clicon_err(OE_XML, 0, "db not found"); + clixon_err(OE_XML, 0, "db not found"); goto done; } retval = get_common(h, ce, xe, CONTENT_CONFIG, db, cbret); @@ -1115,7 +1115,7 @@ from_client_get_config(clicon_handle h, * @see from_client_get_config */ int -from_client_get(clicon_handle h, +from_client_get(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, diff --git a/apps/backend/backend_get.h b/apps/backend/backend_get.h index 6cae9f27..e159392e 100644 --- a/apps/backend/backend_get.h +++ b/apps/backend/backend_get.h @@ -40,8 +40,8 @@ /* * Prototypes */ -int from_client_get_config(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); -int from_client_get(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); -int from_client_get_pageable_list(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); /* XXX */ +int from_client_get_config(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int from_client_get(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int from_client_get_pageable_list(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); /* XXX */ #endif /* _BACKEND_GET_H_ */ diff --git a/apps/backend/backend_handle.h b/apps/backend/backend_handle.h index 7a6db927..82baaff3 100644 --- a/apps/backend/backend_handle.h +++ b/apps/backend/backend_handle.h @@ -43,16 +43,16 @@ * Prototypes * not exported. */ -clicon_handle backend_handle_init(void); +clixon_handle backend_handle_init(void); -int backend_handle_exit(clicon_handle h); +int backend_handle_exit(clixon_handle h); -struct client_entry *backend_client_add(clicon_handle h, struct sockaddr *addr); +struct client_entry *backend_client_add(clixon_handle h, struct sockaddr *addr); -struct client_entry *backend_client_list(clicon_handle h); +struct client_entry *backend_client_list(clixon_handle h); -int backend_client_delete(clicon_handle h, struct client_entry *ce); +int backend_client_delete(clixon_handle h, struct client_entry *ce); -int backend_client_print(clicon_handle h, FILE *f); +int backend_client_print(clixon_handle h, FILE *f); #endif /* _BACKEND_HANDLE_H_ */ diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 2a017654..4d1e485c 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -65,7 +65,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -89,7 +89,7 @@ * @param[in] h Clixon handle */ static int -backend_terminate(clicon_handle h) +backend_terminate(clixon_handle h) { yang_stmt *yspec; char *pidfile = clicon_backend_pidfile(h); @@ -145,7 +145,7 @@ backend_terminate(clicon_handle h) clixon_event_exit(); clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__); clixon_err_exit(); - clicon_log_exit(); + clixon_log_exit(); return 0; } @@ -157,7 +157,7 @@ backend_sig_term(int arg) static int i=0; if (i++ == 0) - clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", + clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d", __PROGRAM__, __FUNCTION__, getpid(), arg); else exit(1); @@ -183,7 +183,7 @@ backend_sig_child(int arg) * @retval -1 Error */ static int -backend_server_socket(clicon_handle h) +backend_server_socket(clixon_handle h) { int ss; @@ -202,7 +202,7 @@ backend_server_socket(clicon_handle h) /*! Load external NACM file */ static int -nacm_load_external(clicon_handle h) +nacm_load_external(clixon_handle h) { int retval = -1; char *filename; /* NACM config file */ @@ -213,19 +213,19 @@ nacm_load_external(clicon_handle h) filename = clicon_option_str(h, "CLICON_NACM_FILE"); if (filename == NULL || strlen(filename)==0){ - clicon_err(OE_UNIX, errno, "CLICON_NACM_FILE not set in NACM external mode"); + clixon_err(OE_UNIX, errno, "CLICON_NACM_FILE not set in NACM external mode"); goto done; } if (stat(filename, &st) < 0){ - clicon_err(OE_UNIX, errno, "%s", filename); + clixon_err(OE_UNIX, errno, "%s", filename); goto done; } if (!S_ISREG(st.st_mode)){ - clicon_err(OE_UNIX, 0, "%s is not a regular file", filename); + clixon_err(OE_UNIX, 0, "%s is not a regular file", filename); goto done; } if ((f = fopen(filename, "r")) == NULL) { - clicon_err(OE_UNIX, errno, "configure file: %s", filename); + clixon_err(OE_UNIX, errno, "configure file: %s", filename); return -1; } if ((yspec = yspec_new()) == NULL) @@ -236,7 +236,7 @@ nacm_load_external(clicon_handle h) if (clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, NULL) < 0) goto done; if (xt == NULL){ - clicon_err(OE_XML, 0, "No xml tree in %s", filename); + clixon_err(OE_XML, 0, "No xml tree in %s", filename); goto done; } if (clicon_nacm_ext_yang_set(h, yspec) < 0) @@ -252,7 +252,7 @@ nacm_load_external(clicon_handle h) } static int -xmldb_drop_priv(clicon_handle h, +xmldb_drop_priv(clixon_handle h, const char *db, uid_t uid, gid_t gid) @@ -263,7 +263,7 @@ xmldb_drop_priv(clicon_handle h, if (xmldb_db2file(h, db, &filename) < 0) goto done; if (chown(filename, uid, gid) < 0){ - clicon_err(OE_UNIX, errno, "chown"); + clixon_err(OE_UNIX, errno, "chown"); goto done; } retval = 0; @@ -287,7 +287,7 @@ xmldb_drop_priv(clicon_handle h, * @retval -1 Error */ static int -check_drop_priv(clicon_handle h, +check_drop_priv(clixon_handle h, gid_t gid, yang_stmt *yspec) { @@ -304,19 +304,19 @@ check_drop_priv(clicon_handle h, /* From here, drop privileges */ /* Check backend user exists */ if ((backend_user = clicon_backend_user(h)) == NULL){ - clicon_err(OE_DAEMON, EPERM, "Privileges cannot be dropped without specifying CLICON_BACKEND_USER\n"); + clixon_err(OE_DAEMON, EPERM, "Privileges cannot be dropped without specifying CLICON_BACKEND_USER\n"); goto done; } /* Get (wanted) new backend user id */ if (name2uid(backend_user, &newuid) < 0){ - clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", backend_user); + clixon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", backend_user); goto done; } /* get current backend userid, if already at this level OK */ if ((uid = getuid()) == newuid) goto ok; if (uid != 0){ - clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid); + clixon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid); goto done; } /* When dropping privileges, datastores are created if they do not exist. @@ -348,7 +348,7 @@ check_drop_priv(clicon_handle h, goto done; } if (setgid(gid) == -1) { - clicon_err(OE_DAEMON, errno, "setgid %d", gid); + clixon_err(OE_DAEMON, errno, "setgid %d", gid); goto done; } switch (priv_mode){ @@ -357,7 +357,7 @@ check_drop_priv(clicon_handle h, goto done; /* Verify you cannot regain root privileges */ if (setuid(0) != -1){ - clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges"); + clixon_err(OE_DAEMON, EPERM, "Could regain root privilieges"); goto done; } break; @@ -381,8 +381,8 @@ check_drop_priv(clicon_handle h, * @retval 0 OK, status set * @retval -1 Fatal error outside scope of startup_status * Transformation rules: - * 1) retval -1 assume clicon_errno/suberrno set. Special case from xml parser - * is clicon_suberrno = XMLPARSE_ERRNO which assumes an XML (non-fatal) parse + * 1) retval -1 assume clixon_err_category/subnr set. Special case from xml parser + * is clixon_err_subnr = XMLPARSE_ERRNO which assumes an XML (non-fatal) parse * error which translates to -> STARTUP_ERR * All other error cases translates to fatal error * 2) retval 0 is xml validation fails -> STARTUP_INVALID @@ -397,9 +397,9 @@ ret2status(int ret, switch (ret){ case -1: - if (clicon_suberrno != XMLPARSE_ERRNO) + if (clixon_err_subnr() != XMLPARSE_ERRNO) goto done; - clicon_err_reset(); + clixon_err_reset(); *status = STARTUP_ERR; break; case 0: @@ -409,7 +409,7 @@ ret2status(int ret, *status = STARTUP_OK; break; default: - clicon_err(OE_CFG, EINVAL, "No such retval %d", retval); + clixon_err(OE_CFG, EINVAL, "No such retval %d", retval); } /* switch */ retval = 0; done: @@ -423,7 +423,7 @@ backend_timer_setup(int fd, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; struct timeval now; struct timeval t; struct timeval t1 = {10, 0}; @@ -451,7 +451,7 @@ backend_timer_setup(int fd, /*! usage */ static void -usage(clicon_handle h, +usage(clixon_handle h, char *argv0) { char *plgdir = clicon_backend_dir(h); @@ -510,14 +510,14 @@ main(int argc, char *backend_group = NULL; char *argv0 = argv[0]; struct stat st; - clicon_handle h; + clixon_handle h; int help = 0; int pid; char *pidfile; char *sock; int sockfamily; char *nacm_mode; - int logdst = CLICON_LOG_SYSLOG|CLICON_LOG_STDERR; + int logdst = CLIXON_LOG_SYSLOG|CLIXON_LOG_STDERR; yang_stmt *yspec = NULL; char *str; int ss = -1; /* server socket */ @@ -535,11 +535,14 @@ main(int argc, enum format_enum config_dump_format = FORMAT_XML; int print_version = 0; - /* In the startup, logs to stderr & syslog and debug flag set later */ - clicon_log_init(__PROGRAM__, LOG_INFO, logdst); /* Initiate CLICON handle */ if ((h = backend_handle_init()) == NULL) return -1; + /* In the startup, logs to stderr & syslog and debug flag set later */ + if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0) + goto done; + if (clixon_err_init(h) < 0) + goto done; foreground = 0; once = 0; zap = 0; @@ -581,11 +584,11 @@ main(int argc, clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); break; case 'l': /* Log destination: s|e|o */ - if ((logdst = clicon_log_opt(optarg[0])) < 0) + if ((logdst = clixon_log_opt(optarg[0])) < 0) usage(h, argv[0]); - if (logdst == CLICON_LOG_FILE && + if (logdst == CLIXON_LOG_FILE && strlen(optarg)>1 && - clicon_log_file(optarg+1) < 0) + clixon_log_file(optarg+1) < 0) goto done; break; } @@ -596,8 +599,8 @@ main(int argc, * XXX: if started in a start-daemon script, there will be irritating * double syslogs until fork below. */ - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clixon_debug_init(dbg, NULL); + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); + clixon_debug_init(h, dbg); yang_init(h); /* Find and read configfile */ @@ -718,8 +721,8 @@ main(int argc, /* Access the remaining argv/argc options (after --) w clicon-argv_get() */ clicon_argv_set(h, argv0, argc, argv); - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); - + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); + /* Defer: Wait to the last minute to print help message */ if (help) usage(h, argv[0]); @@ -730,22 +733,22 @@ main(int argc, cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) - clicon_log_string_limit_set(sz); + clixon_log_string_limit_set(sz); #ifndef HAVE_LIBXML2 if (clicon_yang_regexp(h) == REGEXP_LIBXML2){ - clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); + clixon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); goto done; } #endif /* Check pid-file, if zap kil the old daemon, else return here */ if ((pidfile = clicon_backend_pidfile(h)) == NULL){ - clicon_err(OE_FATAL, 0, "pidfile not set"); + clixon_err(OE_FATAL, 0, "pidfile not set"); goto done; } sockfamily = clicon_sock_family(h); if ((sock = clicon_sock_str(h)) == NULL){ - clicon_err(OE_FATAL, 0, "sock not set"); + clixon_err(OE_FATAL, 0, "sock not set"); goto done; } if (pidfile_get(pidfile, &pid) < 0) @@ -762,7 +765,7 @@ main(int argc, } else if (pid){ - clicon_err(OE_DAEMON, 0, "Daemon already running with pid %d\n(Try killing it with %s -z)", + clixon_err(OE_DAEMON, 0, "Daemon already running with pid %d\n(Try killing it with %s -z)", pid, argv0); return -1; /* goto done deletes pidfile */ } @@ -777,11 +780,11 @@ main(int argc, /* Sanity check: backend group exists */ if ((backend_group = clicon_sock_group(h)) == NULL){ - clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); + clixon_err(OE_FATAL, 0, "clicon_sock_group option not set"); return -1; } if (group_name2gid(backend_group, &gid) < 0){ - clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */ + clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */ "The config daemon requires a valid group to create a server UNIX socket\n" "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n" "or create the group and add the user to it. Check documentation for how to do this on your platform", @@ -899,13 +902,13 @@ main(int argc, /* Startup mode needs to be defined, */ startup_mode = clicon_startup_mode(h); if ((int)startup_mode == -1){ - clicon_log(LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend."); + clixon_log(h, LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend."); goto done; } /* Check that netconf :startup is enabled */ if ((startup_mode == SM_STARTUP || startup_mode == SM_RUNNING_STARTUP) && !if_feature(yspec, "ietf-netconf", "startup")){ - clicon_log(LOG_ERR, "Startup mode selected but Netconf :startup feature is not enabled. Enable with option: ietf-netconf:startup"); + clixon_log(h, LOG_ERR, "Startup mode selected but Netconf :startup feature is not enabled. Enable with option: ietf-netconf:startup"); goto done; } @@ -924,7 +927,7 @@ main(int argc, xmldb_delete(h, "candidate"); /* If startup fails, lib functions report invalidation info in a cbuf */ if ((cbret = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } switch (startup_mode){ @@ -1003,7 +1006,7 @@ main(int argc, } if (status != STARTUP_OK){ if (cbuf_len(cbret)) - clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret)); + clixon_log(h, LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret)); if (load_failsafe(h, "Startup") < 0){ goto done; } @@ -1022,7 +1025,7 @@ main(int argc, goto done; if (status == STARTUP_INVALID && cbuf_len(cbret)) - clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret)); + clixon_log(h, LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret)); /* Call backend plugin_start with user -- options */ if (clixon_plugin_start_all(h) < 0) @@ -1044,13 +1047,13 @@ main(int argc, daemonized errors OK. Before this stage, errors are logged on stderr also */ if (foreground==0){ - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, - logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG); + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, + logdst==CLIXON_LOG_FILE?CLIXON_LOG_FILE:CLIXON_LOG_SYSLOG); /* Call plugin callbacks just before fork/daemonization */ if (clixon_plugin_pre_daemon_all(h) < 0) goto done; if (daemon(0, 0) < 0){ - clicon_err(OE_UNIX, errno, "daemon"); + clixon_err(OE_UNIX, errno, "daemon"); exit(-1); } } @@ -1065,21 +1068,21 @@ main(int argc, goto done; if (set_signal(SIGTERM, backend_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGINT, backend_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } /* This is in case restconf daemon forked using process-control API */ if (set_signal(SIGCHLD, backend_sig_child, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } /* Client exit in the middle of a transaction, handled in clicon_msg_send */ if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } /* Initialize server socket and save it to handle */ @@ -1106,7 +1109,7 @@ main(int argc, /* Just before event-loop, after socket bind/listen */ if (netconf_monitoring_statistics_init(h) < 0) goto done; - clicon_log(LOG_NOTICE, "%s: %u Started", __PROGRAM__, getpid()); + clixon_log(h, LOG_NOTICE, "%s: %u Started", __PROGRAM__, getpid()); if (clixon_event_loop(h) < 0) goto done; ok: @@ -1114,7 +1117,7 @@ main(int argc, done: if (cbret) cbuf_free(cbret); - clicon_log(LOG_NOTICE, "%s: %u Terminated retval:%d", __PROGRAM__, getpid(), retval); + clixon_log(h, LOG_NOTICE, "%s: %u Terminated retval:%d", __PROGRAM__, getpid(), retval); backend_terminate(h); /* Cannot use h after this */ return retval; diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index d8960e3c..647a410e 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -57,7 +57,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -75,7 +75,7 @@ */ int clixon_plugin_reset_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, char *db) { int retval = -1; @@ -89,8 +89,8 @@ clixon_plugin_reset_one(clixon_plugin_t *cp, if (fn(h, db) < 0) { if (plugin_context_check(h, &wh, clixon_plugin_name_get(cp), __FUNCTION__) < 0) goto done; - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Reset callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Reset callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -111,7 +111,7 @@ clixon_plugin_reset_one(clixon_plugin_t *cp, * @retval -1 Error */ int -clixon_plugin_reset_all(clicon_handle h, +clixon_plugin_reset_all(clixon_handle h, char *db) { int retval = -1; @@ -137,7 +137,7 @@ clixon_plugin_reset_all(clicon_handle h, */ static int clixon_plugin_pre_daemon_one(clixon_plugin_t *cp, - clicon_handle h) + clixon_handle h) { int retval = -1; plgdaemon_t *fn; /* Daemonize plugin callback function */ @@ -150,9 +150,9 @@ clixon_plugin_pre_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) - clicon_log(LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\ - %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\ + %s returned -1 but did not make a clixon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -174,7 +174,7 @@ clixon_plugin_pre_daemon_one(clixon_plugin_t *cp, * @retval -1 Error */ int -clixon_plugin_pre_daemon_all(clicon_handle h) +clixon_plugin_pre_daemon_all(clixon_handle h) { int retval = -1; clixon_plugin_t *cp = NULL; @@ -199,7 +199,7 @@ clixon_plugin_pre_daemon_all(clicon_handle h) */ static int clixon_plugin_daemon_one(clixon_plugin_t *cp, - clicon_handle h) + clixon_handle h) { int retval = -1; plgdaemon_t *fn; /* Daemonize plugin callback function */ @@ -212,8 +212,8 @@ 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) - clicon_log(LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -237,7 +237,7 @@ clixon_plugin_daemon_one(clixon_plugin_t *cp, * @note Also called for non-background mode */ int -clixon_plugin_daemon_all(clicon_handle h) +clixon_plugin_daemon_all(clixon_handle h) { int retval = -1; clixon_plugin_t *cp = NULL; @@ -280,7 +280,7 @@ clixon_plugin_daemon_all(clicon_handle h) */ static int clixon_plugin_statedata_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, cvec *nsc, char *xpath, cxobj **xp) @@ -299,8 +299,8 @@ 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) - clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, clixon_plugin_name_get(cp)); goto fail; /* Dont quit here on user callbacks */ } @@ -333,7 +333,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp, * @note xret can be replaced in this function */ int -clixon_plugin_statedata_all(clicon_handle h, +clixon_plugin_statedata_all(clixon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath, @@ -353,12 +353,12 @@ clixon_plugin_statedata_all(clicon_handle h, goto done; if (ret == 0){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - /* error reason should be in clicon_err_reason */ + /* error reason should be in clixon_err_reason */ cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s", - clixon_plugin_name_get(cp), clicon_err_reason); + clixon_plugin_name_get(cp), clixon_err_reason()); if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) goto done; xml_free(*xret); @@ -430,7 +430,7 @@ clixon_plugin_statedata_all(clicon_handle h, */ static int clixon_plugin_lockdb_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, char *db, int lock, int id) @@ -463,7 +463,7 @@ clixon_plugin_lockdb_one(clixon_plugin_t *cp, * @retval -1 Fatal error */ int -clixon_plugin_lockdb_all(clicon_handle h, +clixon_plugin_lockdb_all(clixon_handle h, char *db, int lock, int id @@ -491,7 +491,7 @@ clixon_plugin_lockdb_all(clicon_handle h, * @retval -1 Error */ int -clixon_pagination_cb_call(clicon_handle h, +clixon_pagination_cb_call(clixon_handle h, char *xpath, int locked, uint32_t offset, @@ -524,7 +524,7 @@ clixon_pagination_cb_call(clicon_handle h, * @retval -1 Error */ int -clixon_pagination_cb_register(clicon_handle h, +clixon_pagination_cb_register(clixon_handle h, handler_function fn, char *xpath, void *arg) @@ -535,7 +535,7 @@ clixon_pagination_cb_register(clicon_handle h, clicon_ptr_get(h, "pagination-entries", (void**)&htable); if (dispatcher_register_handler(&htable, &x) < 0){ - clicon_err(OE_PLUGIN, errno, "dispatcher"); + clixon_err(OE_PLUGIN, errno, "dispatcher"); goto done; } if (clicon_ptr_set(h, "pagination-entries", htable) < 0) @@ -550,7 +550,7 @@ clixon_pagination_cb_register(clicon_handle h, * @param[in] h Clixon handle */ int -clixon_pagination_free(clicon_handle h) +clixon_pagination_free(clixon_handle h) { dispatcher_entry_t *htable = NULL; @@ -573,7 +573,7 @@ transaction_new(void) static uint64_t id = 0; /* Global transaction id */ if ((td = malloc(sizeof(*td))) == NULL){ - clicon_err(OE_CFG, errno, "malloc"); + clixon_err(OE_CFG, errno, "malloc"); return NULL; } memset(td, 0, sizeof(*td)); @@ -614,7 +614,7 @@ transaction_free(transaction_data_t *td) */ int plugin_transaction_begin_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -628,8 +628,8 @@ plugin_transaction_begin_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -651,7 +651,7 @@ plugin_transaction_begin_one(clixon_plugin_t *cp, * @retval -1 Error: one of the plugin callbacks returned error */ int -plugin_transaction_begin_all(clicon_handle h, +plugin_transaction_begin_all(clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -677,7 +677,7 @@ plugin_transaction_begin_all(clicon_handle h, */ int plugin_transaction_validate_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -691,8 +691,8 @@ plugin_transaction_validate_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; @@ -713,7 +713,7 @@ plugin_transaction_validate_one(clixon_plugin_t *cp, * @retval -1 Error: one of the plugin callbacks returned validation fail */ int -plugin_transaction_validate_all(clicon_handle h, +plugin_transaction_validate_all(clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -739,7 +739,7 @@ plugin_transaction_validate_all(clicon_handle h, */ int plugin_transaction_complete_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -753,8 +753,8 @@ plugin_transaction_complete_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -776,7 +776,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(clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -802,7 +802,7 @@ 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(clixon_handle h, transaction_data_t *td, int nr) { @@ -814,7 +814,7 @@ plugin_transaction_revert_all(clicon_handle h, 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", + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed", __FUNCTION__, clixon_plugin_name_get(cp)); break; } @@ -833,7 +833,7 @@ plugin_transaction_revert_all(clicon_handle h, */ int plugin_transaction_commit_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -847,8 +847,8 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -871,7 +871,7 @@ plugin_transaction_commit_one(clixon_plugin_t *cp, * and in reverse order. */ int -plugin_transaction_commit_all(clicon_handle h, +plugin_transaction_commit_all(clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -901,7 +901,7 @@ plugin_transaction_commit_all(clicon_handle h, */ int plugin_transaction_commit_done_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -915,8 +915,8 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -937,7 +937,7 @@ plugin_transaction_commit_done_one(clixon_plugin_t *cp, * @note no revert is done */ int -plugin_transaction_commit_done_all(clicon_handle h, +plugin_transaction_commit_done_all(clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -962,7 +962,7 @@ plugin_transaction_commit_done_all(clicon_handle h, */ int plugin_transaction_end_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -976,8 +976,8 @@ plugin_transaction_end_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -997,7 +997,7 @@ plugin_transaction_end_one(clixon_plugin_t *cp, * @retval -1 Error */ int -plugin_transaction_end_all(clicon_handle h, +plugin_transaction_end_all(clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -1015,7 +1015,7 @@ plugin_transaction_end_all(clicon_handle h, int plugin_transaction_abort_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, transaction_data_t *td) { int retval = -1; @@ -1029,8 +1029,8 @@ plugin_transaction_abort_one(clixon_plugin_t *cp, if (fn(h, (transaction_data)td) < 0){ 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", + if (!clixon_err_category()) /* sanity: log if clixon_err() is not called ! */ + clixon_log(h, LOG_NOTICE, "%s: Plugin '%s' callback does not make clixon_err call on error", __FUNCTION__, clixon_plugin_name_get(cp)); goto done; } @@ -1050,7 +1050,7 @@ plugin_transaction_abort_one(clixon_plugin_t *cp, * @retval -1 Error */ int -plugin_transaction_abort_all(clicon_handle h, +plugin_transaction_abort_all(clixon_handle h, transaction_data_t *td) { int retval = -1; diff --git a/apps/backend/backend_plugin_restconf.c b/apps/backend/backend_plugin_restconf.c index 9c87c603..6ee231a2 100644 --- a/apps/backend/backend_plugin_restconf.c +++ b/apps/backend/backend_plugin_restconf.c @@ -51,7 +51,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -74,7 +74,7 @@ * @retval -1 Error */ static int -restconf_pseudo_set_log(clicon_handle h, +restconf_pseudo_set_log(clixon_handle h, cxobj *xt) { int retval = -1; @@ -102,7 +102,7 @@ restconf_pseudo_set_log(clicon_handle h, if (argv[i+1]) free(argv[i+1]); if ((argv[i+1] = strdup("s")) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -110,7 +110,7 @@ restconf_pseudo_set_log(clicon_handle h, if (argv[i+1]) free(argv[i+1]); if ((argv[i+1] = strdup("f/var/log/clixon_restconf.log")) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -121,7 +121,7 @@ restconf_pseudo_set_log(clicon_handle h, if (dbg){ free(argv[i+1]); if ((argv[i+1] = strdup(dbg)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -144,7 +144,7 @@ restconf_pseudo_set_log(clicon_handle h, * @retval -1 Error */ static int -restconf_pseudo_set_inline(clicon_handle h, +restconf_pseudo_set_inline(clixon_handle h, cxobj *xt) { int retval = -1; @@ -165,13 +165,13 @@ restconf_pseudo_set_inline(clicon_handle h, char *str; if (strcmp(argv[i], "-R") == 0 && argc > i+1 && argv[i+1]){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(cb, xrestconf, 0, 0, NULL, -1, 0) < 0) goto done; if ((str = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_XML, errno, "stdup"); + clixon_err(OE_XML, errno, "stdup"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s str:%s", __FUNCTION__, str); @@ -196,7 +196,7 @@ restconf_pseudo_set_inline(clicon_handle h, * These rules give that if RPC op is start and enable is false -> change op to none */ int -restconf_rpc_wrapper(clicon_handle h, +restconf_rpc_wrapper(clixon_handle h, process_entry_t *pe, proc_operation *operation) { @@ -248,7 +248,7 @@ restconf_rpc_wrapper(clicon_handle h, * this is ignored. */ static int -restconf_pseudo_process_control(clicon_handle h) +restconf_pseudo_process_control(clixon_handle h) { int retval = -1; char **argv = NULL; @@ -266,12 +266,12 @@ restconf_pseudo_process_control(clicon_handle h) nr += 2; #endif if ((argv = calloc(nr, sizeof(char *))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } i = 0; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Try to figure out where clixon_restconf is installed @@ -303,7 +303,7 @@ restconf_pseudo_process_control(clicon_handle h) 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", + clixon_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", dir0, dir1); goto done; } @@ -343,7 +343,7 @@ restconf_pseudo_process_control(clicon_handle h) /*! Restconf pseudo-plugin process validate */ static int -restconf_pseudo_process_validate(clicon_handle h, +restconf_pseudo_process_validate(clixon_handle h, transaction_data td) { int retval = -1; @@ -357,11 +357,11 @@ restconf_pseudo_process_validate(clicon_handle h, xpath_first(xtarget, NULL, "restconf/socket[ssl='true']")){ /* Should filepath be checked? One could claim this is a runtime system,... */ if (xpath_first(xtarget, 0, "restconf/server-cert-path") == NULL){ - clicon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set"); + clixon_err(OE_CFG, 0, "SSL enabled but server-cert-path not set"); return -1; /* induce fail */ } if (xpath_first(xtarget, 0, "restconf/server-key-path") == NULL){ - clicon_err(OE_CFG, 0, "SSL enabled but server-key-path not set"); + clixon_err(OE_CFG, 0, "SSL enabled but server-key-path not set"); return -1; /* induce fail */ } } @@ -372,7 +372,7 @@ restconf_pseudo_process_validate(clicon_handle h, /*! Restconf pseduo-plugin process commit */ static int -restconf_pseudo_process_commit(clicon_handle h, +restconf_pseudo_process_commit(clixon_handle h, transaction_data td) { int retval = -1; @@ -437,7 +437,7 @@ restconf_pseudo_process_commit(clicon_handle h, * @retval -1 Error */ int -backend_plugin_restconf_register(clicon_handle h, +backend_plugin_restconf_register(clixon_handle h, yang_stmt *yspec) { int retval = -1; diff --git a/apps/backend/backend_plugin_restconf.h b/apps/backend/backend_plugin_restconf.h index c897a401..183aaf9a 100644 --- a/apps/backend/backend_plugin_restconf.h +++ b/apps/backend/backend_plugin_restconf.h @@ -38,6 +38,6 @@ #ifndef _BACKEND_PLUGIN_RESTCONF_H_ #define _BACKEND_PLUGIN_RESTCONF_H_ -int backend_plugin_restconf_register(clicon_handle h, yang_stmt *yspec); +int backend_plugin_restconf_register(clixon_handle h, yang_stmt *yspec); #endif /* _BACKEND_PLUGIN_RESTCONF_H_ */ diff --git a/apps/backend/backend_socket.c b/apps/backend/backend_socket.c index a7cb1adc..27b68cba 100644 --- a/apps/backend/backend_socket.c +++ b/apps/backend/backend_socket.c @@ -68,7 +68,7 @@ #include -/* clicon */ +/* clixon */ #include #include "backend_socket.h" @@ -84,7 +84,7 @@ * @retval -1 Error */ static int -config_socket_init_ipv4(clicon_handle h, +config_socket_init_ipv4(clixon_handle h, char *dst) { int s; @@ -96,7 +96,7 @@ config_socket_init_ipv4(clicon_handle h, /* create inet socket */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - clicon_err(OE_UNIX, errno, "socket"); + clixon_err(OE_UNIX, errno, "socket"); return -1; } setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one)); @@ -104,16 +104,16 @@ config_socket_init_ipv4(clicon_handle h, addr.sin_family = AF_INET; addr.sin_port = htons(port); if (inet_pton(addr.sin_family, dst, &addr.sin_addr) != 1){ - clicon_err(OE_UNIX, errno, "inet_pton: %s (Expected IPv4 address. Check settings of CLICON_SOCK_FAMILY and CLICON_SOCK)", dst); + clixon_err(OE_UNIX, errno, "inet_pton: %s (Expected IPv4 address. Check settings of CLICON_SOCK_FAMILY and CLICON_SOCK)", dst); goto err; /* Could check getaddrinfo */ } if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0){ - clicon_err(OE_UNIX, errno, "bind"); + clixon_err(OE_UNIX, errno, "bind"); goto err; } 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"); + clixon_err(OE_UNIX, errno, "listen"); goto err; } return s; @@ -132,7 +132,7 @@ config_socket_init_ipv4(clicon_handle h, * @retval -1 Error */ static int -config_socket_init_unix(clicon_handle h, +config_socket_init_unix(clixon_handle h, char *sock) { int s; @@ -143,23 +143,23 @@ config_socket_init_unix(clicon_handle h, struct stat st; if (lstat(sock, &st) == 0 && unlink(sock) < 0){ - clicon_err(OE_UNIX, errno, "unlink(%s)", sock); + clixon_err(OE_UNIX, errno, "unlink(%s)", sock); return -1; } /* then find configuration group (for clients) and find its groupid */ if ((config_group = clicon_sock_group(h)) == NULL){ - clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); + clixon_err(OE_FATAL, 0, "clicon_sock_group option not set"); return -1; } if (group_name2gid(config_group, &gid) < 0) return -1; #if 0 if (gid == 0) - clicon_log(LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group); + clixon_log(h, LOG_WARNING, "%s: No such group: %s", __FUNCTION__, config_group); #endif /* create unix socket */ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - clicon_err(OE_UNIX, errno, "socket"); + clixon_err(OE_UNIX, errno, "socket"); return -1; } // setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one)); @@ -168,19 +168,19 @@ config_socket_init_unix(clicon_handle h, strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1); 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"); + clixon_err(OE_UNIX, errno, "bind"); umask(old_mask); goto err; } 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); + clixon_err(OE_UNIX, errno, "lchown(%s, %s)", sock, config_group); goto err; } 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"); + clixon_err(OE_UNIX, errno, "listen"); goto err; } return s; @@ -196,12 +196,12 @@ config_socket_init_unix(clicon_handle h, * @retval -1 Error */ int -backend_socket_init(clicon_handle h) +backend_socket_init(clixon_handle h) { char *sock; /* unix path or ip address string */ if ((sock = clicon_sock_str(h)) == NULL){ - clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); + clixon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); return -1; } switch (clicon_sock_family(h)){ @@ -212,7 +212,7 @@ backend_socket_init(clicon_handle h) return config_socket_init_ipv4(h, sock); break; default: - clicon_err(OE_UNIX, EINVAL, "No such address family: %d", + clixon_err(OE_UNIX, EINVAL, "No such address family: %d", clicon_sock_family(h)); break; } @@ -222,7 +222,7 @@ backend_socket_init(clicon_handle h) /*! Accept new socket client * * @param[in] fd Socket (unix or ip) - * @param[in] arg typecast clicon_handle + * @param[in] arg typecast clixon_handle * @retval 0 OK * @retval -1 Error */ @@ -231,7 +231,7 @@ backend_accept_client(int fd, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; int s; struct sockaddr from = {0,}; socklen_t len; @@ -248,7 +248,7 @@ backend_accept_client(int fd, clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); len = sizeof(from); if ((s = accept(fd, &from, &len)) < 0){ - clicon_err(OE_UNIX, errno, "accept"); + clixon_err(OE_UNIX, errno, "accept"); goto done; } if ((ce = backend_client_add(h, &from)) == NULL) @@ -262,7 +262,7 @@ backend_accept_client(int fd, #if defined(HAVE_SO_PEERCRED) clen = sizeof(cr); if(getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &clen) < 0){ - clicon_err(OE_UNIX, errno, "getsockopt"); + clixon_err(OE_UNIX, errno, "getsockopt"); goto done; } if (uid2name(cr.uid, &name) < 0) @@ -277,7 +277,7 @@ backend_accept_client(int fd, #endif if (name != NULL){ if ((ce->ce_username = name) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); name = NULL; goto done; } diff --git a/apps/backend/backend_socket.h b/apps/backend/backend_socket.h index edb5dfe4..91fcb4ea 100644 --- a/apps/backend/backend_socket.h +++ b/apps/backend/backend_socket.h @@ -42,7 +42,7 @@ /* * Prototypes */ -int backend_socket_init(clicon_handle h); +int backend_socket_init(clixon_handle h); int backend_accept_client(int fd, void *arg); #endif /* _BACKEND_SOCKET_H_ */ diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index 4687efc0..637f2d85 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -62,7 +62,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -78,7 +78,7 @@ * @retval -1 Error */ static int -db_merge(clicon_handle h, +db_merge(clixon_handle h, const char *db1, const char *db2, cbuf *cbret) @@ -130,7 +130,7 @@ startup --+-------------------------------------> BROKEN XML * @note: if commit fails, copy factory to running */ int -startup_mode_startup(clicon_handle h, +startup_mode_startup(clixon_handle h, char *db, cbuf *cbret) { @@ -140,7 +140,7 @@ startup_mode_startup(clicon_handle h, yang_stmt *yspec = clicon_dbspec_yang(h); if (strcmp(db, "running")==0){ - clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db); + clixon_err(OE_FATAL, 0, "Invalid startup db: %s", db); goto done; } /* If startup does not exist, create it empty */ @@ -158,7 +158,7 @@ startup_mode_startup(clicon_handle h, */ if (if_feature(yspec, "ietf-netconf", "confirmed-commit")) { if ((rollback_exists = xmldb_exists(h, "rollback")) < 0) { - clicon_err(OE_DAEMON, 0, "Error checking for the existence of the rollback database"); + clixon_err(OE_DAEMON, 0, "Error checking for the existence of the rollback database"); goto done; } if (rollback_exists == 1) { @@ -211,7 +211,7 @@ startup_mode_startup(clicon_handle h, * @retval -1 Error */ static int -load_extraxml(clicon_handle h, +load_extraxml(clixon_handle h, char *filename, const char *db, cbuf *cbret) @@ -226,7 +226,7 @@ load_extraxml(clicon_handle h, if (filename == NULL) return 1; if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "open(%s)", filename); + clixon_err(OE_UNIX, errno, "open(%s)", filename); goto done; } yspec = clicon_dbspec_yang(h); @@ -248,7 +248,6 @@ load_extraxml(clicon_handle h, retval = 0; goto done; } - /* Merge user reset state */ retval = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret); done: @@ -280,7 +279,7 @@ tmp |-------+-----+-----+ reset extrafile */ int -startup_extraxml(clicon_handle h, +startup_extraxml(clixon_handle h, char *file, cbuf *cbret) { @@ -352,7 +351,7 @@ startup_extraxml(clicon_handle h, * @retval -1 Error */ int -startup_module_state(clicon_handle h, +startup_module_state(clixon_handle h, yang_stmt *yspec) { int retval = -1; diff --git a/apps/backend/backend_startup.h b/apps/backend/backend_startup.h index e233f96f..7023b5b9 100644 --- a/apps/backend/backend_startup.h +++ b/apps/backend/backend_startup.h @@ -42,8 +42,8 @@ /* * 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); +int startup_mode_startup(clixon_handle h, char *db, cbuf *cbret); +int startup_extraxml(clixon_handle h, char *file, cbuf *cbret); +int startup_module_state(clixon_handle h, yang_stmt *yspec); #endif /* _BACKEND_STARTUP_H_ */ diff --git a/apps/backend/clixon_backend_client.h b/apps/backend/clixon_backend_client.h index bc31befa..80c178df 100644 --- a/apps/backend/clixon_backend_client.h +++ b/apps/backend/clixon_backend_client.h @@ -62,7 +62,7 @@ struct client_entry{ int ce_nr; /* Client number (for dbg/tracing) */ uint32_t ce_id; /* Session id, accessor functions: clicon_session_id_get/set */ char *ce_username;/* Translated from peer user cred */ - clicon_handle ce_handle; /* clicon config handle (all clients have same?) */ + clixon_handle ce_handle; /* clicon config handle (all clients have same?) */ char *ce_transport; /* Identifies the transport for each session. Clixon-lib.yang extends these values by prefixing with "cl:", where cl is ensured to be declared ie by diff --git a/apps/backend/clixon_backend_commit.h b/apps/backend/clixon_backend_commit.h index c274c974..8e053db1 100644 --- a/apps/backend/clixon_backend_commit.h +++ b/apps/backend/clixon_backend_commit.h @@ -56,28 +56,28 @@ enum confirmed_commit_state { * Prototypes */ /* backend_confirm.c */ -int confirmed_commit_init(clicon_handle h); -int confirmed_commit_free(clicon_handle h); -enum confirmed_commit_state confirmed_commit_state_get(clicon_handle h); -uint32_t confirmed_commit_session_id_get(clicon_handle h); -int cancel_rollback_event(clicon_handle h); -int cancel_confirmed_commit(clicon_handle h); -int handle_confirmed_commit(clicon_handle h, cxobj *xe, uint32_t myid); -int do_rollback(clicon_handle h, uint8_t *errs); -int from_client_cancel_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); -int from_client_confirmed_commit(clicon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret); +int confirmed_commit_init(clixon_handle h); +int confirmed_commit_free(clixon_handle h); +enum confirmed_commit_state confirmed_commit_state_get(clixon_handle h); +uint32_t confirmed_commit_session_id_get(clixon_handle h); +int cancel_rollback_event(clixon_handle h); +int cancel_confirmed_commit(clixon_handle h); +int handle_confirmed_commit(clixon_handle h, cxobj *xe, uint32_t myid); +int do_rollback(clixon_handle h, uint8_t *errs); +int from_client_cancel_commit(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int from_client_confirmed_commit(clixon_handle h, cxobj *xe, uint32_t myid, cbuf *cbret); /* backend_commit.c */ -int startup_validate(clicon_handle h, char *db, cxobj **xtr, cbuf *cbret); -int startup_commit(clicon_handle h, char *db, cbuf *cbret); -int candidate_validate(clicon_handle h, char *db, cbuf *cbret); -int candidate_commit(clicon_handle h, cxobj *xe, char *db, uint32_t myid, +int startup_validate(clixon_handle h, char *db, cxobj **xtr, cbuf *cbret); +int startup_commit(clixon_handle h, char *db, cbuf *cbret); +int candidate_validate(clixon_handle h, char *db, cbuf *cbret); +int candidate_commit(clixon_handle h, cxobj *xe, char *db, uint32_t myid, validate_level vlev, cbuf *cbret); -int from_client_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); -int from_client_discard_changes(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); -int from_client_validate(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); -int from_client_restart_one(clicon_handle h, clixon_plugin_t *cp, cbuf *cbret); -int load_failsafe(clicon_handle h, char *phase); +int from_client_commit(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int from_client_discard_changes(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int from_client_validate(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int from_client_restart_one(clixon_handle h, clixon_plugin_t *cp, cbuf *cbret); +int load_failsafe(clixon_handle h, char *phase); #endif /* _CLIXON_BACKEND_COMMIT_H_ */ diff --git a/apps/backend/clixon_backend_handle.c b/apps/backend/clixon_backend_handle.c index 65f41c8a..f228e76d 100644 --- a/apps/backend/clixon_backend_handle.c +++ b/apps/backend/clixon_backend_handle.c @@ -58,21 +58,21 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_client.h" #include "backend_client.h" #include "backend_handle.h" -/* header part is copied from struct clicon_handle in lib/src/clicon_handle.c */ +/* header part is copied from struct clixon_handle in lib/src/clixon_handle.c */ #define CLICON_MAGIC 0x99aafabe -#define handle(h) (assert(clicon_handle_check(h)==0),(struct backend_handle *)(h)) +#define handle(h) (assert(clixon_handle_check(h)==0),(struct backend_handle *)(h)) -/* Clicon_handle for backends. - * First part of this is header, same for clicon_handle and cli_handle. +/* Clixon_handle for backends. + * First part of this is header, same for clixon_handle and cli_handle. * Access functions for common fields are found in clicon lib: clicon_options.[ch] * This file should only contain access functions for the _specific_ * entries in the struct below. @@ -81,8 +81,8 @@ * * 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 - * @see struct clicon_handle, struct cli_handle + * @note The top part must be equivalent to struct clixon_handle in clixon_handle.c + * @see struct clixon_handle, struct cli_handle */ struct backend_handle { int bh_magic; /* magic (HDR)*/ @@ -98,14 +98,14 @@ struct backend_handle { /*! Creates and returns a clicon config handle for other CLICON API calls */ -clicon_handle +clixon_handle backend_handle_init(void) { struct backend_handle *bh; - bh = (struct backend_handle *)clicon_handle_init0(sizeof(struct backend_handle)); + bh = (struct backend_handle *)clixon_handle_init0(sizeof(struct backend_handle)); bh->bh_ce_nr = 1; /* To align with session-id */ - return (clicon_handle)bh; + return (clixon_handle)bh; } /*! Deallocates a backend handle, including all client structs @@ -114,7 +114,7 @@ backend_handle_init(void) * @see backend_client_rm */ int -backend_handle_exit(clicon_handle h) +backend_handle_exit(clixon_handle h) { struct client_entry *ce; @@ -126,7 +126,7 @@ backend_handle_exit(clicon_handle h) } backend_client_delete(h, ce); } - clicon_handle_exit(h); /* frees h and options (and streams) */ + clixon_handle_exit(h); /* frees h and options (and streams) */ return 0; } @@ -138,14 +138,14 @@ backend_handle_exit(clicon_handle h) * @retval NULL Error */ struct client_entry * -backend_client_add(clicon_handle h, +backend_client_add(clixon_handle h, struct sockaddr *addr) { struct backend_handle *bh = handle(h); struct client_entry *ce; if ((ce = (struct client_entry *)malloc(sizeof(*ce))) == NULL){ - clicon_err(OE_PLUGIN, errno, "malloc"); + clixon_err(OE_PLUGIN, errno, "malloc"); return NULL; } memset(ce, 0, sizeof(*ce)); @@ -154,7 +154,7 @@ backend_client_add(clicon_handle h, ce->ce_next = bh->bh_ce_list; ce->ce_handle = h; if (clicon_session_id_get(h, &ce->ce_id) < 0){ - clicon_err(OE_NETCONF, ENOENT, "session_id not set"); + clixon_err(OE_NETCONF, ENOENT, "session_id not set"); return NULL; } clicon_session_id_set(h, ce->ce_id + 1); @@ -170,7 +170,7 @@ backend_client_add(clicon_handle h, * @retval ce_list Client entry list (all sessions) */ struct client_entry * -backend_client_list(clicon_handle h) +backend_client_list(clixon_handle h) { struct backend_handle *bh = handle(h); @@ -184,7 +184,7 @@ backend_client_list(clicon_handle h) * @see backend_client_rm which is more high-level */ int -backend_client_delete(clicon_handle h, +backend_client_delete(clixon_handle h, struct client_entry *ce) { struct client_entry *c; @@ -215,7 +215,7 @@ backend_client_delete(clicon_handle h, * @param[in] f UNIX output stream */ int -backend_client_print(clicon_handle h, +backend_client_print(clixon_handle h, FILE *f) { struct backend_handle *bh = handle(h); diff --git a/apps/backend/clixon_backend_plugin.h b/apps/backend/clixon_backend_plugin.h index 8a3d1206..0834f2bd 100644 --- a/apps/backend/clixon_backend_plugin.h +++ b/apps/backend/clixon_backend_plugin.h @@ -94,44 +94,44 @@ typedef struct { /* * Prototypes */ -int clixon_plugin_reset_one(clixon_plugin_t *cp, clicon_handle h, char *db); -int clixon_plugin_reset_all(clicon_handle h, char *db); +int clixon_plugin_reset_one(clixon_plugin_t *cp, clixon_handle h, char *db); +int clixon_plugin_reset_all(clixon_handle h, char *db); -int clixon_plugin_pre_daemon_all(clicon_handle h); -int clixon_plugin_daemon_all(clicon_handle h); +int clixon_plugin_pre_daemon_all(clixon_handle h); +int clixon_plugin_daemon_all(clixon_handle h); -int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath, +int clixon_plugin_statedata_all(clixon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath, withdefaults_type wdef, cxobj **xtop); -int clixon_plugin_lockdb_all(clicon_handle h, char *db, int lock, int id); +int clixon_plugin_lockdb_all(clixon_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, +int clixon_pagination_cb_register(clixon_handle h, handler_function fn, char *path, void *arg); +int clixon_pagination_cb_call(clixon_handle h, char *xpath, int locked, uint32_t offset, uint32_t limit, cxobj *xstate); -int clixon_pagination_free(clicon_handle h); +int clixon_pagination_free(clixon_handle h); transaction_data_t * transaction_new(void); int transaction_free(transaction_data_t *); -int plugin_transaction_begin_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_begin_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_begin_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_begin_all(clixon_handle h, transaction_data_t *td); -int plugin_transaction_validate_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_validate_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_validate_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_validate_all(clixon_handle h, transaction_data_t *td); -int plugin_transaction_complete_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_complete_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_complete_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_complete_all(clixon_handle h, transaction_data_t *td); -int plugin_transaction_commit_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_commit_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_commit_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_commit_all(clixon_handle h, transaction_data_t *td); -int plugin_transaction_commit_done_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_commit_done_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_commit_done_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_commit_done_all(clixon_handle h, transaction_data_t *td); -int plugin_transaction_end_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_end_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_end_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_end_all(clixon_handle h, transaction_data_t *td); -int plugin_transaction_abort_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td); -int plugin_transaction_abort_all(clicon_handle h, transaction_data_t *td); +int plugin_transaction_abort_one(clixon_plugin_t *cp, clixon_handle h, transaction_data_t *td); +int plugin_transaction_abort_all(clixon_handle h, transaction_data_t *td); #endif /* _CLIXON_BACKEND_PLUGIN_H_ */ diff --git a/apps/backend/clixon_backend_transaction.c b/apps/backend/clixon_backend_transaction.c index e61c4110..225dd521 100644 --- a/apps/backend/clixon_backend_transaction.c +++ b/apps/backend/clixon_backend_transaction.c @@ -57,7 +57,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_backend_transaction.h" @@ -258,7 +258,7 @@ transaction_print(FILE *f, * @param[in] msg Debug msg tag */ int -transaction_dbg(clicon_handle h, +transaction_dbg(clixon_handle h, int dbglevel, transaction_data th, const char *msg) @@ -270,7 +270,7 @@ transaction_dbg(clicon_handle h, td = (transaction_data_t *)th; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_CFG, errno, "cbuf_new"); + clixon_err(OE_CFG, errno, "cbuf_new"); goto done; } for (i=0; itd_dlen; i++){ @@ -313,7 +313,7 @@ transaction_dbg(clicon_handle h, /*! Log a transaction */ int -transaction_log(clicon_handle h, +transaction_log(clixon_handle h, transaction_data th, int level, const char *op) @@ -325,7 +325,7 @@ transaction_log(clicon_handle h, td = (transaction_data_t *)th; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_CFG, errno, "cbuf_new"); + clixon_err(OE_CFG, errno, "cbuf_new"); goto done; } for (i=0; itd_dlen; i++){ @@ -334,7 +334,7 @@ transaction_log(clicon_handle h, goto done; } if (i) - clicon_log(level, "%s %" PRIu64 " %s del: %s", + clixon_log(h, level, "%s %" PRIu64 " %s del: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); cbuf_reset(cb); for (i=0; itd_alen; i++){ @@ -343,7 +343,7 @@ transaction_log(clicon_handle h, goto done; } if (i) - clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); + clixon_log(h, level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); cbuf_reset(cb); for (i=0; itd_clen; i++){ if (td->td_scvec){ @@ -356,7 +356,7 @@ transaction_log(clicon_handle h, goto done; } if (i) - clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); + clixon_log(h, level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb)); done: if (cb) cbuf_free(cb); diff --git a/apps/backend/clixon_backend_transaction.h b/apps/backend/clixon_backend_transaction.h index e6344841..91349c27 100644 --- a/apps/backend/clixon_backend_transaction.h +++ b/apps/backend/clixon_backend_transaction.h @@ -62,8 +62,8 @@ cxobj **transaction_tcvec(transaction_data td); size_t transaction_clen(transaction_data td); int transaction_print(FILE *f, transaction_data th); -int transaction_dbg(clicon_handle h, int dbglevel, transaction_data th, const char *msg); -int transaction_log(clicon_handle h, transaction_data th, int level, const char *op); +int transaction_dbg(clixon_handle h, int dbglevel, transaction_data th, const char *msg); +int transaction_log(clixon_handle h, transaction_data th, int level, const char *op); /* Pagination callbacks diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index c5467a98..4ef7428e 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -70,7 +70,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_cli_api.h" @@ -113,7 +113,7 @@ co2apipath(cg_obj *co) * code */ int -cli_auto_edit(clicon_handle h, +cli_auto_edit(clixon_handle h, cvec *cvv1, cvec *argv) { @@ -130,7 +130,7 @@ cli_auto_edit(clicon_handle h, char *mtpoint = NULL; if (cvec_len(argv) != 2 && cvec_len(argv) != 3){ - clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, )", __FUNCTION__); + clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, )", __FUNCTION__); goto done; } api_path_fmt = cv_string_get(cvec_i(argv, argc++)); @@ -144,7 +144,7 @@ cli_auto_edit(clicon_handle h, treename = str; /* Find current cligen tree */ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); + clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); goto done; } /* Find the matching cligen object @@ -156,19 +156,19 @@ cli_auto_edit(clicon_handle h, (coorig = co->co_ref) != NULL) cligen_ph_workpoint_set(ph, coorig); else { - clicon_err(OE_YANG, EINVAL, "No workpoint found"); + clixon_err(OE_YANG, EINVAL, "No workpoint found"); goto done; } } else{ - clicon_err(OE_YANG, EINVAL, "No workpoint found"); + clixon_err(OE_YANG, EINVAL, "No workpoint found"); goto done; } if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL) goto done; /* API_path format */ if ((api_path_fmt = co2apipath(coorig)) == NULL){ - clicon_err(OE_YANG, EINVAL, "No apipath found"); + clixon_err(OE_YANG, EINVAL, "No apipath found"); goto done; } /* get api-path and xpath */ @@ -180,7 +180,7 @@ cli_auto_edit(clicon_handle h, if (mtpoint){ char *mtpoint2; if ((mtpoint2 = strdup(mtpoint)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if (clicon_data_set(h, "cli-edit-mtpoint", mtpoint2) < 0) @@ -191,7 +191,7 @@ cli_auto_edit(clicon_handle h, if (co->co_filter){ cvec *cvv3; if ((cvv3 = cvec_dup(co->co_filter)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_dup"); + clixon_err(OE_YANG, errno, "cvec_dup"); goto done; } if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0) @@ -215,7 +215,7 @@ cli_auto_edit(clicon_handle h, * Name of generated cligen parse-tree, eg "datamodel" */ int -cli_auto_up(clicon_handle h, +cli_auto_up(clixon_handle h, cvec *cvv, cvec *argv) { @@ -236,13 +236,13 @@ cli_auto_up(clicon_handle h, cvec *cvv_filter = NULL; if (cvec_len(argv) != 1){ - clicon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__); + clixon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__); goto done; } cv = cvec_i(argv, 0); treename = cv_string_get(cv); if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); + clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); goto done; } if ((co0 = cligen_ph_workpoint_get(ph)) == NULL) @@ -313,7 +313,7 @@ cli_auto_up(clicon_handle h, * Name of generated cligen parse-tree, eg "datamodel" */ int -cli_auto_top(clicon_handle h, +cli_auto_top(clixon_handle h, cvec *cvv, cvec *argv) { @@ -325,7 +325,7 @@ cli_auto_top(clicon_handle h, cv = cvec_i(argv, 0); treename = cv_string_get(cv); if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); + clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); goto done; } cligen_ph_workpoint_set(ph, NULL); @@ -349,7 +349,7 @@ cli_auto_top(clicon_handle h, * Generated */ int -cli_auto_set(clicon_handle h, +cli_auto_set(clixon_handle h, cvec *cvv, cvec *argv) { @@ -375,7 +375,7 @@ cli_auto_set(clicon_handle h, * @retval -1 Error */ int -cli_auto_merge(clicon_handle h, +cli_auto_merge(clixon_handle h, cvec *cvv, cvec *argv) { @@ -401,7 +401,7 @@ cli_auto_merge(clicon_handle h, * @retval -1 Error */ int -cli_auto_create(clicon_handle h, +cli_auto_create(clixon_handle h, cvec *cvv, cvec *argv) { @@ -427,7 +427,7 @@ cli_auto_create(clicon_handle h, * @retval -1 Error */ int -cli_auto_del(clicon_handle h, +cli_auto_del(clixon_handle h, cvec *cvv, cvec *argv) { @@ -492,7 +492,7 @@ cli_auto_findpt(cg_obj *co, * @see cli_auto_edit */ int -cli_auto_sub_enter(clicon_handle h, +cli_auto_sub_enter(clixon_handle h, cvec *cvv, cvec *argv) { @@ -508,7 +508,7 @@ cli_auto_sub_enter(clicon_handle h, struct findpt_arg fa = {0,}; if (cvec_len(argv) < 2){ - clicon_err(OE_PLUGIN, EINVAL, "Usage: %s( (,vars)*)", __FUNCTION__); + clixon_err(OE_PLUGIN, EINVAL, "Usage: %s( (,vars)*)", __FUNCTION__); goto done; } /* First argv argument: treename */ @@ -527,7 +527,7 @@ cli_auto_sub_enter(clicon_handle h, */ /* Create a cvv with variables to add to api-path */ if ((cvv1 = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } /* Append static variables (skip first treename) */ @@ -552,7 +552,7 @@ cli_auto_sub_enter(clicon_handle h, goto done; /* Find current cligen tree */ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename); + clixon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename); goto done; } /* Find the point in the generated clispec tree where workpoint should be set */ @@ -560,7 +560,7 @@ cli_auto_sub_enter(clicon_handle h, if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, INT32_MAX, &fa) < 0) goto done; if (fa.fa_co == NULL){ - clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path); + clixon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path); goto done; } cligen_ph_workpoint_set(ph, fa.fa_co); diff --git a/apps/cli/cli_autocli.c b/apps/cli/cli_autocli.c index 6e4f45bf..8252c514 100644 --- a/apps/cli/cli_autocli.c +++ b/apps/cli/cli_autocli.c @@ -110,7 +110,7 @@ autocli_listkw_int2str(int listkw) * @retval -1 Error */ int -autocli_module(clicon_handle h, +autocli_module(clixon_handle h, char *modname, int *enablep) { @@ -124,7 +124,7 @@ autocli_module(clicon_handle h, char *body; if (enablep == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } enable = 0; @@ -132,7 +132,7 @@ autocli_module(clicon_handle h, goto ok; /* Default rule */ if ((str = xml_find_body(xautocli, "module-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No module-default rule"); + clixon_err(OE_XML, EINVAL, "No module-default rule"); goto done; } enable = strcmp(str, "true") == 0; @@ -243,7 +243,7 @@ The surrounding container entities are removed from list nodes. - Only one child + Child keyword is LIST */ int -autocli_compress(clicon_handle h, +autocli_compress(clixon_handle h, yang_stmt *ys, int *compress) { @@ -262,11 +262,11 @@ autocli_compress(clicon_handle h, char *body; if (compress == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } if ((xautocli = clicon_conf_autocli(h)) == NULL){ - clicon_err(OE_YANG, 0, "No clixon-autocli"); + clixon_err(OE_YANG, 0, "No clixon-autocli"); goto done; } ymod = ys_module(ys); @@ -349,7 +349,7 @@ autocli_compress(clicon_handle h, * @retval -1 Error */ int -autocli_completion(clicon_handle h, +autocli_completion(clixon_handle h, int *completion) { int retval = -1; @@ -360,19 +360,19 @@ autocli_completion(clicon_handle h, cxobj *xautocli; if (completion == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } if ((xautocli = clicon_conf_autocli(h)) == NULL){ - clicon_err(OE_YANG, 0, "No clixon-autocli"); + clixon_err(OE_YANG, 0, "No clixon-autocli"); goto done; } if ((str = xml_find_body(xautocli, "completion-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No completion-default rule"); + clixon_err(OE_XML, EINVAL, "No completion-default rule"); goto done; } if ((ret = parse_bool(str, &val, &reason)) < 0){ - clicon_err(OE_CFG, errno, "parse_bool"); + clixon_err(OE_CFG, errno, "parse_bool"); goto done; } *completion = val; @@ -392,7 +392,7 @@ autocli_completion(clicon_handle h, * @retval -1 Error */ int -autocli_grouping_treeref(clicon_handle h, +autocli_grouping_treeref(clixon_handle h, int *treeref) { int retval = -1; @@ -403,19 +403,19 @@ autocli_grouping_treeref(clicon_handle h, cxobj *xautocli; if (treeref == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } if ((xautocli = clicon_conf_autocli(h)) == NULL){ - clicon_err(OE_YANG, 0, "No clixon-autocli"); + clixon_err(OE_YANG, 0, "No clixon-autocli"); goto done; } if ((str = xml_find_body(xautocli, "grouping-treeref")) == NULL){ - clicon_err(OE_XML, EINVAL, "No grouping-treeref rule"); + clixon_err(OE_XML, EINVAL, "No grouping-treeref rule"); goto done; } if ((ret = parse_bool(str, &val, &reason)) < 0){ - clicon_err(OE_CFG, errno, "parse_bool"); + clixon_err(OE_CFG, errno, "parse_bool"); goto done; } *treeref = val; @@ -435,7 +435,7 @@ autocli_grouping_treeref(clicon_handle h, * @retval -1 Error */ int -autocli_list_keyword(clicon_handle h, +autocli_list_keyword(clixon_handle h, autocli_listkw_t *listkw) { int retval = -1; @@ -443,15 +443,15 @@ autocli_list_keyword(clicon_handle h, cxobj *xautocli = NULL; if (listkw == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } if ((xautocli = clicon_conf_autocli(h)) == NULL){ - clicon_err(OE_YANG, 0, "No clixon-autocli"); + clixon_err(OE_YANG, 0, "No clixon-autocli"); goto done; } if ((str = xml_find_body(xautocli, "list-keyword-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No list-keyword-default rule"); + clixon_err(OE_XML, EINVAL, "No list-keyword-default rule"); goto done; } *listkw = autocli_listkw_str2int(str); @@ -468,7 +468,7 @@ autocli_list_keyword(clicon_handle h, * @retval -1 Error */ int -autocli_treeref_state(clicon_handle h, +autocli_treeref_state(clixon_handle h, int *treeref_state) { int retval = -1; @@ -479,19 +479,19 @@ autocli_treeref_state(clicon_handle h, cxobj *xautocli; if (treeref_state == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } if ((xautocli = clicon_conf_autocli(h)) == NULL){ - clicon_err(OE_YANG, 0, "No clixon-autocli"); + clixon_err(OE_YANG, 0, "No clixon-autocli"); goto done; } if ((str = xml_find_body(xautocli, "treeref-state-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No treeref-state-default rule"); + clixon_err(OE_XML, EINVAL, "No treeref-state-default rule"); goto done; } if ((ret = parse_bool(str, &val, &reason)) < 0){ - clicon_err(OE_CFG, errno, "parse_bool"); + clixon_err(OE_CFG, errno, "parse_bool"); goto done; } *treeref_state = val; @@ -512,7 +512,7 @@ autocli_treeref_state(clicon_handle h, * @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined */ int -autocli_edit_mode(clicon_handle h, +autocli_edit_mode(clixon_handle h, char *keyw, int *flag) { @@ -525,16 +525,16 @@ autocli_edit_mode(clicon_handle h, int i; if (flag == NULL){ - clicon_err(OE_YANG, EINVAL, "Argument is NULL"); + clixon_err(OE_YANG, EINVAL, "Argument is NULL"); goto done; } *flag = 0; if ((xautocli = clicon_conf_autocli(h)) == NULL){ - clicon_err(OE_YANG, 0, "No clixon-autocli"); + clixon_err(OE_YANG, 0, "No clixon-autocli"); goto done; } if ((str = xml_find_body(xautocli, "edit-mode-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No edit-mode-default rule"); + clixon_err(OE_XML, EINVAL, "No edit-mode-default rule"); goto done; } if ((vec = clicon_strsep(str, " ", &nvec)) == NULL) diff --git a/apps/cli/cli_autocli.h b/apps/cli/cli_autocli.h index bbd197c9..ac687f97 100644 --- a/apps/cli/cli_autocli.h +++ b/apps/cli/cli_autocli.h @@ -50,12 +50,12 @@ enum autocli_op{ /* * Prototypes */ -int autocli_module(clicon_handle h, char *modname, int *enable); -int autocli_completion(clicon_handle h, int *completion); -int autocli_grouping_treeref(clicon_handle h, int *grouping_treeref); -int autocli_list_keyword(clicon_handle h, autocli_listkw_t *listkw); -int autocli_compress(clicon_handle h, yang_stmt *ys, int *compress); -int autocli_treeref_state(clicon_handle h, int *treeref_state); -int autocli_edit_mode(clicon_handle h, char *keyw, int *flag); +int autocli_module(clixon_handle h, char *modname, int *enable); +int autocli_completion(clixon_handle h, int *completion); +int autocli_grouping_treeref(clixon_handle h, int *grouping_treeref); +int autocli_list_keyword(clixon_handle h, autocli_listkw_t *listkw); +int autocli_compress(clixon_handle h, yang_stmt *ys, int *compress); +int autocli_treeref_state(clixon_handle h, int *treeref_state); +int autocli_edit_mode(clixon_handle h, char *keyw, int *flag); #endif /* _CLI_AUTOCLI_H_ */ diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 38edfe9e..4bc85d16 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -64,7 +64,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_cli_api.h" @@ -84,7 +84,7 @@ * @note this calls cligen_regfd which may callback on cli command interpretator */ int -cli_notification_register(clicon_handle h, +cli_notification_register(clixon_handle h, char *stream, enum format_enum format, char *filter, @@ -102,7 +102,7 @@ cli_notification_register(clicon_handle h, len = strlen("log_socket_") + strlen(stream) + 1; if ((logname = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } snprintf(logname, len, "log_socket_%s", stream); @@ -111,7 +111,7 @@ cli_notification_register(clicon_handle h, if (status){ /* start */ if (s_exist!=-1){ - clicon_err(OE_PLUGIN, 0, "Result log socket already exists"); + clixon_err(OE_PLUGIN, 0, "Result log socket already exists"); goto done; } if (clicon_rpc_create_subscription(h, stream, filter, &s) < 0) @@ -142,7 +142,7 @@ cli_notification_register(clicon_handle h, * This is for CLIgen to handle these signals, eg ^Ĉ means abort command, not program */ void -cli_signal_block(clicon_handle h) +cli_signal_block(clixon_handle h) { clicon_signal_block (SIGTSTP); clicon_signal_block (SIGQUIT); @@ -152,7 +152,7 @@ cli_signal_block(clicon_handle h) } void -cli_signal_unblock(clicon_handle h) +cli_signal_unblock(clixon_handle h) { clicon_signal_unblock (SIGTSTP); clicon_signal_unblock (SIGQUIT); @@ -164,7 +164,7 @@ cli_signal_unblock(clicon_handle h) * Flush pending signals for a given signal type */ void -cli_signal_flush(clicon_handle h) +cli_signal_flush(clixon_handle h) { /* XXX A bit rough. Use sigpending() and more clever logic ?? */ @@ -207,7 +207,7 @@ dbxml_body(cxobj *xbot, len = cvec_len(cvv); cval = cvec_i(cvv, len-1); if ((str = cv2str_dup(cval)) == NULL){ - clicon_err(OE_UNIX, errno, "cv2str_dup"); + clixon_err(OE_UNIX, errno, "cv2str_dup"); goto done; } if ((xb = xml_new("body", xbot, CX_BODY)) == NULL) @@ -307,25 +307,25 @@ mtpoint_paths(yang_stmt *yspec0, yang_stmt *yspec1; if (api_path_fmt01 == NULL){ - clicon_err(OE_FATAL, EINVAL, "arg is NULL"); + clixon_err(OE_FATAL, EINVAL, "arg is NULL"); goto done; } if ((xtop0 = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL) goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (yang_path_arg(yspec0, mtpoint, &yu) < 0) goto done; if (yu == NULL){ - clicon_err(OE_FATAL, 0, "yu not found"); + clixon_err(OE_FATAL, 0, "yu not found"); goto done; } if (yang_mount_get(yu, mtpoint, &yspec1) < 0) goto done; if (yspec1 == NULL){ - clicon_err(OE_FATAL, 0, "yspec1 not found"); + clixon_err(OE_FATAL, 0, "yspec1 not found"); goto done; } xbot0 = xtop0; @@ -334,18 +334,18 @@ mtpoint_paths(yang_stmt *yspec0, if ((ret = xpath2xml(mtpoint, nsc0, xtop0, yspec0, &xbot0, &ybot0, NULL)) < 0) goto done; if (xbot0 == NULL){ - clicon_err(OE_YANG, 0, "No xbot"); + clixon_err(OE_YANG, 0, "No xbot"); goto done; } if (yang2api_path_fmt(ybot0, 0, &api_path_fmt0) < 0) goto done; if (api_path_fmt0 == NULL){ - clicon_err(OE_YANG, 0, "No api_path_fmt0"); + clixon_err(OE_YANG, 0, "No api_path_fmt0"); goto done; } cprintf(cb, "%s%s", api_path_fmt0, api_path_fmt1); if ((*api_path_fmt01 = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } retval = 0; @@ -386,7 +386,7 @@ mtpoint_paths(yang_stmt *yspec0, * generated by a function such as clixon_instance_id_bind() or other programmatically. */ int -cli_dbxml(clicon_handle h, +cli_dbxml(clixon_handle h, cvec *cvv, cvec *argv, enum operation_type op, @@ -412,11 +412,11 @@ cli_dbxml(clicon_handle h, /* Top-level yspec */ if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } if ((api_path_fmt_cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Concatenate all argv strings to a single string */ @@ -428,7 +428,7 @@ cli_dbxml(clicon_handle h, cv = cvec_i(argv, argc++); str = cv_string_get(cv); if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){ - clicon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'"); + clixon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'"); goto done; } mtpoint = str + strlen("mtpoint:"); @@ -463,13 +463,12 @@ cli_dbxml(clicon_handle h, goto done; if (ret == 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - cprintf(cb, "api-path syntax error \"%s\": ", api_path_fmt); if (netconf_err2cb(h, xerr, cb) < 0) goto done; - clicon_err(OE_CFG, EINVAL, "%s", cbuf_get(cb)); + clixon_err(OE_CFG, EINVAL, "api-path syntax error \"%s\": %s", api_path_fmt, cbuf_get(cb)); goto done; } } @@ -504,7 +503,7 @@ cli_dbxml(clicon_handle h, if ((ret = xml_apply0(xbot, CX_ELMNT, identityref_add_ns, yspec0)) < 0) goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) @@ -537,7 +536,7 @@ cli_dbxml(clicon_handle h, * @retval -1 Error */ int -cli_set(clicon_handle h, +cli_set(clixon_handle h, cvec *cvv, cvec *argv) { @@ -559,7 +558,7 @@ cli_set(clicon_handle h, * @retval -1 Error */ int -cli_merge(clicon_handle h, +cli_merge(clixon_handle h, cvec *cvv, cvec *argv) { @@ -581,7 +580,7 @@ cli_merge(clicon_handle h, * @retval -1 Error */ int -cli_create(clicon_handle h, +cli_create(clixon_handle h, cvec *cvv, cvec *argv) { @@ -604,7 +603,7 @@ cli_create(clicon_handle h, * @see cli_del */ int -cli_remove(clicon_handle h, +cli_remove(clixon_handle h, cvec *cvv, cvec *argv) { @@ -626,7 +625,7 @@ cli_remove(clicon_handle h, * @retval -1 Error */ int -cli_del(clicon_handle h, +cli_del(clixon_handle h, cvec *cvv, cvec *argv) { @@ -650,7 +649,7 @@ cli_del(clicon_handle h, * _or_ if a 'level' variable is present in cvv use that value instead. */ int -cli_debug_cli(clicon_handle h, +cli_debug_cli(clixon_handle h, cvec *cvv, cvec *argv) { @@ -660,14 +659,14 @@ cli_debug_cli(clicon_handle h, 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"); + clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); goto done; } cv = cvec_i(argv, 0); } level = cv_int32_get(cv); /* cli */ - clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ + clixon_debug_init(h, level); /* 0: dont debug, 1:debug */ retval = 0; done: return retval; @@ -684,7 +683,7 @@ cli_debug_cli(clicon_handle h, * _or_ if a 'level' variable is present in cvv use that value instead. */ int -cli_debug_backend(clicon_handle h, +cli_debug_backend(clixon_handle h, cvec *cvv, cvec *argv) { @@ -694,7 +693,7 @@ cli_debug_backend(clicon_handle h, 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"); + clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); goto done; } cv = cvec_i(argv, 0); @@ -721,7 +720,7 @@ cli_debug_backend(clicon_handle h, * 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf) */ int -cli_debug_restconf(clicon_handle h, +cli_debug_restconf(clixon_handle h, cvec *cvv, cvec *argv) { @@ -731,7 +730,7 @@ cli_debug_restconf(clicon_handle h, 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"); + clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1"); goto done; } cv = cvec_i(argv, 0); @@ -753,7 +752,7 @@ cli_debug_restconf(clicon_handle h, * @retval -1 Error */ int -cli_set_mode(clicon_handle h, +cli_set_mode(clixon_handle h, cvec *cvv, cvec *argv) { @@ -761,7 +760,7 @@ cli_set_mode(clicon_handle h, char *str = NULL; if (cvec_len(argv) != 1){ - clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode"); + clixon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode"); goto done; } str = cv_string_get(cvec_i(argv, 0)); @@ -781,7 +780,7 @@ cli_set_mode(clicon_handle h, * @retval -1 Error */ int -cli_start_shell(clicon_handle h, +cli_start_shell(clixon_handle h, cvec *cvv, cvec *argv) { @@ -795,7 +794,7 @@ cli_start_shell(clicon_handle h, struct sigaction oldsigaction[32] = {{{0,},},}; if (cvec_len(argv) > 1){ - clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: []", + clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: []", cvec_len(argv)); goto done; } @@ -804,11 +803,11 @@ cli_start_shell(clicon_handle h, } cmd = (cvec_len(cvv)>1 ? cv_string_get(cv1) : NULL); if ((pw = getpwuid(getuid())) == NULL){ - clicon_err(OE_UNIX, errno, "getpwuid"); + clixon_err(OE_UNIX, errno, "getpwuid"); goto done; } if (chdir(pw->pw_dir) < 0){ - clicon_err(OE_UNIX, errno, "chdir"); + clixon_err(OE_UNIX, errno, "chdir"); endpwent(); goto done; } @@ -822,7 +821,7 @@ cli_start_shell(clicon_handle h, snprintf(bcmd, 128, "%s -c \"%s\"", shcmd, cmd); if (system(bcmd) < 0){ cli_signal_block(h); - clicon_err(OE_UNIX, errno, "system(bash -c)"); + clixon_err(OE_UNIX, errno, "system(bash -c)"); goto done; } } @@ -830,14 +829,14 @@ cli_start_shell(clicon_handle h, snprintf(bcmd, 128, "%s ", shcmd); /* -l (login shell) but is applicable to bash only */ if (system(bcmd) < 0){ cli_signal_block(h); - clicon_err(OE_UNIX, errno, "system(bash)"); + clixon_err(OE_UNIX, errno, "system(bash)"); goto done; } } cli_signal_block(h); #if 0 /* Allow errcodes from bash */ if (retval != 0){ - clicon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval); + clixon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval); goto done; } #endif @@ -857,7 +856,7 @@ cli_start_shell(clicon_handle h, * @retval -1 Error */ int -cli_quit(clicon_handle h, +cli_quit(clixon_handle h, cvec *cvv, cvec *argv) { @@ -874,7 +873,7 @@ cli_quit(clicon_handle h, * @retval -1 Error */ int -cli_commit(clicon_handle h, +cli_commit(clixon_handle h, cvec *cvv, cvec *argv) { @@ -909,7 +908,7 @@ cli_commit(clicon_handle h, * @retval -1 Error */ int -cli_validate(clicon_handle h, +cli_validate(clixon_handle h, cvec *cvv, cvec *argv) { @@ -932,7 +931,7 @@ cli_validate(clicon_handle h, * @retval -1 Error */ int -compare_db_names(clicon_handle h, +compare_db_names(clixon_handle h, enum format_enum format, char *db1, char *db2) @@ -946,13 +945,23 @@ compare_db_names(clicon_handle h, if (clicon_rpc_get_config(h, NULL, db1, "/", NULL, NULL, &xc1) < 0) goto done; if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Get configuration", NULL); +#endif goto done; } if (clicon_rpc_get_config(h, NULL, db2, "/", NULL, NULL, &xc2) < 0) goto done; if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Get configuration", NULL); +#endif goto done; } /* Note that XML and TEXT uses a (new) structured in-mem algorithm while @@ -961,7 +970,7 @@ compare_db_names(clicon_handle h, switch (format){ case FORMAT_XML: if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (clixon_xml_diff2cbuf(cb, xc1, xc2) < 0) @@ -970,7 +979,7 @@ compare_db_names(clicon_handle h, break; case FORMAT_TEXT: if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (clixon_text_diff2cbuf(cb, xc1, xc2) < 0) @@ -1004,7 +1013,7 @@ compare_db_names(clicon_handle h, * @retval -1 Error */ int -compare_dbs(clicon_handle h, +compare_dbs(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1015,14 +1024,14 @@ compare_dbs(clicon_handle h, char *formatstr; if (cvec_len(argv) != 3){ - clicon_err(OE_PLUGIN, EINVAL, "Expected arguments: "); + clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: "); goto done; } db1 = cv_string_get(cvec_i(argv, 0)); db2 = cv_string_get(cvec_i(argv, 1)); formatstr = cv_string_get(cvec_i(argv, 2)); if ((format = format_str2int(formatstr)) < 0){ - clicon_err(OE_XML, 0, "format not found %s", formatstr); + clixon_err(OE_XML, 0, "format not found %s", formatstr); goto done; } if (compare_db_names(h, format, db1, db2) < 0) @@ -1054,7 +1063,7 @@ compare_dbs(clicon_handle h, * @see save_config_file */ int -load_config_file(clicon_handle h, +load_config_file(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1076,18 +1085,18 @@ load_config_file(clicon_handle h, char *lineptr = NULL; if (cvec_len(argv) < 2 || cvec_len(argv) > 4){ - clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]", + clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]", cvec_len(argv)); goto done; } if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } if (cvec_len(argv) > 2){ formatstr = cv_string_get(cvec_i(argv, 2)); if ((int)(format = format_str2int(formatstr)) < 0){ - clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); + clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); goto done; } } @@ -1098,21 +1107,21 @@ load_config_file(clicon_handle h, else if (strcmp(opstr, "replace") == 0) replace = 1; else{ - clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr); + clixon_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); + clixon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); goto done; } filename = cv_string_get(cv); if (stat(filename, &st) < 0){ - clicon_err(OE_UNIX, errno, "load_config: stat(%s)", filename); + clixon_err(OE_UNIX, errno, "load_config: stat(%s)", filename); goto done; } /* Open and parse local file into xml */ if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "fopen(%s)", filename); + clixon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; } switch (format){ @@ -1120,7 +1129,12 @@ load_config_file(clicon_handle h, if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Loading", filename); +#endif goto done; } break; @@ -1128,7 +1142,12 @@ load_config_file(clicon_handle h, if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Loading", filename); +#endif goto done; } break; @@ -1139,7 +1158,12 @@ load_config_file(clicon_handle h, if ((ret = clixon_text_syntax_parse_file(fp, YB_MODULE_NEXT, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Loading", filename); +#endif goto done; } break; @@ -1154,7 +1178,7 @@ load_config_file(clicon_handle h, lineptr = NULL; n = 0; if (getline(&lineptr, &n, fp) < 0){ if (errno){ - clicon_err(OE_UNIX, errno, "getline"); + clixon_err(OE_UNIX, errno, "getline"); goto done; } goto ok; /* eof, skip backend rpc since this is done by cli code */ @@ -1173,16 +1197,18 @@ load_config_file(clicon_handle h, break; } default: - clicon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr); + clixon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr); goto done; break; } if (xt == NULL) goto done; - if ((cbxml = cbuf_new()) == NULL) + if ((cbxml = cbuf_new()) == NULL){ + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; + } x = NULL; - while ((x = xml_child_each(xt, x, -1)) != NULL) { + while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { /* Read as datastore-top but transformed into an edit-config "config" */ xml_name_set(x, NETCONF_INPUT_CONFIG); } @@ -1228,7 +1254,7 @@ load_config_file(clicon_handle h, * @see load_config_file */ int -save_config_file(clicon_handle h, +save_config_file(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1246,14 +1272,14 @@ save_config_file(clicon_handle h, int pretty = 1; /* XXX hardcoded */ if (cvec_len(argv) < 2 || cvec_len(argv) > 4){ - clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]", + clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ,[,]", cvec_len(argv)); goto done; } if (cvec_len(argv) > 2){ formatstr = cv_string_get(cvec_i(argv, 2)); if ((int)(format = format_str2int(formatstr)) < 0){ - clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); + clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr); goto done; } } @@ -1261,23 +1287,28 @@ save_config_file(clicon_handle h, if (strcmp(dbstr, "running") != 0 && strcmp(dbstr, "candidate") != 0 && strcmp(dbstr, "startup") != 0) { - clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); + clixon_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); + clixon_err(OE_PLUGIN, 0, "No such var name: %s", varstr); goto done; } filename = cv_string_get(cv); if (clicon_rpc_get_config(h, NULL, dbstr,"/", NULL, NULL, &xt) < 0) goto done; if (xt == NULL){ - clicon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */ + clixon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */ goto done; } if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Get configuration", NULL); +#endif goto done; } /* get-config returns a tree. Save as tree so it can be used @@ -1286,7 +1317,7 @@ save_config_file(clicon_handle h, if (xml_name_set(xt, DATASTORE_TOP_SYMBOL) < 0) goto done; if ((f = fopen(filename, "w")) == NULL){ - clicon_err(OE_CFG, errno, "Creating file %s", filename); + clixon_err(OE_CFG, errno, "Creating file %s", filename); goto done; } switch (format){ @@ -1335,7 +1366,7 @@ save_config_file(clicon_handle h, * @retval -1 Error */ int -delete_all(clicon_handle h, +delete_all(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1343,14 +1374,14 @@ delete_all(clicon_handle h, int retval = -1; if (cvec_len(argv) != 1){ - clicon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname"); + clixon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname"); goto done; } dbstr = cv_string_get(cvec_i(argv, 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); + clixon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr); goto done; } if (clicon_rpc_delete_config(h, dbstr) < 0) @@ -1363,7 +1394,7 @@ delete_all(clicon_handle h, /*! Discard all changes in candidate and replace with running */ int -discard_changes(clicon_handle h, +discard_changes(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1377,7 +1408,7 @@ discard_changes(clicon_handle h, * @retval -1 Error and logged to syslog */ int -db_copy(clicon_handle h, +db_copy(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1411,7 +1442,7 @@ cli_notification_cb(int s, if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0) goto done; if (eof){ - clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); + clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); close(s); errno = ESHUTDOWN; clixon_event_unreg_fd(s, cli_notification_cb); @@ -1421,7 +1452,7 @@ cli_notification_cb(int s, 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"); + clixon_err(OE_NETCONF, EFAULT, "Notification malformed"); goto done; } switch (format){ @@ -1464,7 +1495,7 @@ cli_notification_cb(int s, * XXX: format is a memory leak */ int -cli_notify(clicon_handle h, +cli_notify(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1475,7 +1506,7 @@ cli_notify(clicon_handle h, enum format_enum format = FORMAT_TEXT; if (cvec_len(argv) != 2 && cvec_len(argv) != 3){ - clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: []"); + clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: []"); goto done; } stream = cv_string_get(cvec_i(argv, 0)); @@ -1511,7 +1542,7 @@ cli_notify(clicon_handle h, * XXX: format is a memory leak */ int -cli_lock(clicon_handle h, +cli_lock(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1519,7 +1550,7 @@ cli_lock(clicon_handle h, char *db; if (cvec_len(argv) != 1){ - clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: "); + clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: "); goto done; } db = cv_string_get(cvec_i(argv, 0)); @@ -1543,7 +1574,7 @@ cli_lock(clicon_handle h, * XXX: format is a memory leak */ int -cli_unlock(clicon_handle h, +cli_unlock(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1551,7 +1582,7 @@ cli_unlock(clicon_handle h, char *db; if (cvec_len(argv) != 1){ - clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: "); + clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: "); goto done; } db = cv_string_get(cvec_i(argv, 0)); @@ -1589,7 +1620,7 @@ cli_unlock(clicon_handle h, * @endcode */ int -cli_copy_config(clicon_handle h, +cli_copy_config(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1615,7 +1646,7 @@ cli_copy_config(clicon_handle h, size_t len; if (cvec_len(argv) != 6){ - clicon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: "); + clixon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: "); goto done; } /* First argv argument: Database */ @@ -1633,14 +1664,14 @@ cli_copy_config(clicon_handle h, /* 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); + clixon_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"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } /* Sanity check that xpath contains exactly two %s, ie [%s='%s'] */ @@ -1651,7 +1682,7 @@ cli_copy_config(clicon_handle h, j++; } if (j != 2){ - clicon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath); + clixon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath); goto done; } cprintf(cb, xpath, keyname, fromname); @@ -1661,13 +1692,18 @@ cli_copy_config(clicon_handle h, if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cb), nsc, NULL, &x1) < 0) goto done; if ((xerr = xpath_first(x1, NULL, "/rpc-error")) != NULL){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Get configuration", NULL); +#endif goto done; } /* Get to variable -> cv -> to name */ if ((tocv = cvec_find(cvv, tovar)) == NULL){ - clicon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar); + clixon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar); goto done; } toname = cv_string_get(tocv); @@ -1679,7 +1715,7 @@ cli_copy_config(clicon_handle h, 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); + clixon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname); goto done; } x = xml_find(x, "body"); @@ -1713,7 +1749,7 @@ cli_copy_config(clicon_handle h, * @retval -1 Error */ int -cli_help(clicon_handle h, +cli_help(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1736,7 +1772,7 @@ cli_help(clicon_handle h, * @endcode */ int -cli_restart_plugin(clicon_handle h, +cli_restart_plugin(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1746,7 +1782,7 @@ cli_restart_plugin(clicon_handle h, if ((cv = cvec_find_var(cvv, "plugin")) == NULL){ if (cvec_len(argv) != 1){ - clicon_err(OE_PLUGIN, EINVAL, "Requires plugin variable"); + clixon_err(OE_PLUGIN, EINVAL, "Requires plugin variable"); goto done; } cv = cvec_i(argv, 0); @@ -1770,13 +1806,13 @@ cvec_append(cvec *cvv0, if (cvv0 == NULL){ if ((cvv2 = cvec_dup(cvv1)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); return NULL; } } else{ if ((cvv2 = cvec_dup(cvv0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); return NULL; } cv = NULL; /* Append cvv1 to cvv2 */ @@ -1804,7 +1840,7 @@ cvec_concat_cb(cvec *cvv, int i; if (cb == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "cb is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "cb is NULL"); goto done; } /* Iterate through all api_path_fmt:s, assume they start with / */ @@ -1838,7 +1874,7 @@ cvec_concat_cb(cvec *cvv, * @endcode */ int -cli_process_control(clicon_handle h, +cli_process_control(clixon_handle h, cvec *cvv, cvec *argv) { @@ -1850,17 +1886,17 @@ cli_process_control(clicon_handle h, cxobj *xerr; if (cvec_len(argv) != 2){ - clicon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation"); + clixon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation"); goto done; } name = cv_string_get(cvec_i(argv, 0)); opstr = cv_string_get(cvec_i(argv, 1)); if (clixon_process_op_str2int(opstr) == -1){ - clicon_err(OE_UNIX, 0, "No such process op: %s", opstr); + clixon_err(OE_UNIX, 0, "No such process op: %s", opstr); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, " \" */ static int -yang2cli_var_pattern(clicon_handle h, +yang2cli_var_pattern(clixon_handle h, cvec *patterns, cbuf *cb) { @@ -446,9 +446,9 @@ yang2cli_var_pattern(clicon_handle h, } /* Forward */ -static int yang2cli_stmt(clicon_handle h, yang_stmt *ys, int level, cbuf *cb); +static int yang2cli_stmt(clixon_handle h, yang_stmt *ys, int level, cbuf *cb); -static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype, +static int yang2cli_var_union(clixon_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 @@ -470,7 +470,7 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype, * @see yang_type_resolve for options and other arguments */ static int -yang2cli_var_sub(clicon_handle h, +yang2cli_var_sub(clixon_handle h, yang_stmt *ys, yang_stmt *ytype, /* resolved type */ char *helptext, @@ -560,7 +560,7 @@ yang2cli_var_sub(clicon_handle h, * @retval -1 Error */ static int -yang2cli_var_union_one(clicon_handle h, +yang2cli_var_union_one(clixon_handle h, yang_stmt *ys, char *origtype, yang_stmt *ytsub, @@ -577,7 +577,7 @@ yang2cli_var_union_one(clicon_handle h, char *restype; if ((patterns = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } /* Resolve the sub-union type to a resolved type */ @@ -586,7 +586,7 @@ yang2cli_var_union_one(clicon_handle h, &cvv, patterns, NULL, &fraction_digits) < 0) goto done; if (ytype == NULL){ - clicon_err(OE_YANG, 0, "result-type should not be NULL"); + clixon_err(OE_YANG, 0, "result-type should not be NULL"); goto done; } restype = ytype?yang_argument_get(ytype):NULL; @@ -623,7 +623,7 @@ yang2cli_var_union_one(clicon_handle h, * @retval -1 Error */ static int -yang2cli_var_union(clicon_handle h, +yang2cli_var_union(clixon_handle h, yang_stmt *ys, char *origtype, yang_stmt *ytype, @@ -653,7 +653,7 @@ yang2cli_var_union(clicon_handle h, } static int -yang2cli_var_leafref(clicon_handle h, +yang2cli_var_leafref(clixon_handle h, yang_stmt *ys, yang_stmt *yrestype, char *helptext, @@ -729,7 +729,7 @@ yang2cli_var_leafref(clicon_handle h, * and thus its type. */ static int -yang2cli_var(clicon_handle h, +yang2cli_var(clixon_handle h, yang_stmt *ys, yang_stmt *yreferred, char *helptext, @@ -749,7 +749,7 @@ yang2cli_var(clicon_handle h, int ret; if ((patterns = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (yang_type_get(yreferred, &origtype, &yrestype, @@ -785,11 +785,11 @@ yang2cli_var(clicon_handle h, yang_stmt *yref = NULL; if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "No Y_PATH for leafref"); + clixon_err(OE_YANG, 0, "No Y_PATH for leafref"); goto done; } if ((path_arg = yang_argument_get(ypath)) == NULL){ - clicon_err(OE_YANG, 0, "No argument for Y_PATH"); + clixon_err(OE_YANG, 0, "No argument for Y_PATH"); goto done; } if (yang_path_arg(yreferred, path_arg, &yref) < 0) @@ -803,7 +803,7 @@ yang2cli_var(clicon_handle h, } else { if (yreferred == yref){ - clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg); + clixon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg); goto done; } /* recurse call with new referred node */ @@ -841,7 +841,7 @@ yang2cli_var(clicon_handle h, * + if callbacks add: cb();{} */ static int -yang2cli_leaf(clicon_handle h, +yang2cli_leaf(clixon_handle h, yang_stmt *ys, int level, int callback, @@ -860,7 +860,7 @@ yang2cli_leaf(clicon_handle h, /* description */ if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if ((s = strstr(helptext, "\n\n")) != NULL) @@ -941,7 +941,7 @@ yang2cli_leaf(clicon_handle h, * @retval -1 Error */ static int -yang2cli_container(clicon_handle h, +yang2cli_container(clixon_handle h, yang_stmt *ys, int level, cbuf *cb) @@ -968,7 +968,7 @@ yang2cli_container(clicon_handle h, cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys)); if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if ((s = strstr(helptext, "\n\n")) != NULL) @@ -1016,7 +1016,7 @@ yang2cli_container(clicon_handle h, * @retval -1 Error */ static int -yang2cli_list(clicon_handle h, +yang2cli_list(clixon_handle h, yang_stmt *ys, int level, cbuf *cb) @@ -1037,7 +1037,7 @@ yang2cli_list(clicon_handle h, cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys)); if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if ((s = strstr(helptext, "\n\n")) != NULL) @@ -1056,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\"", + clixon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", yang_argument_get(ys), keyname); goto done; } @@ -1126,7 +1126,7 @@ yang2cli_list(clicon_handle h, translated to cli. and therefore input-syntax != output syntax. Which is bad */ static int -yang2cli_choice(clicon_handle h, +yang2cli_choice(clixon_handle h, yang_stmt *ys, int level, cbuf *cb) @@ -1168,7 +1168,7 @@ yang2cli_choice(clicon_handle h, * @note Tie-break of same top-level symbol: prefix is NYI * @see yang2cli_yspec for original */ -static int yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename); +static int yang2cli_grouping(clixon_handle h, yang_stmt *ys, char *treename); /*! Generate CLI code for Yang uses statement * @@ -1180,7 +1180,7 @@ static int yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename); * @retval -1 Error */ static int -yang2cli_uses(clicon_handle h, +yang2cli_uses(clixon_handle h, yang_stmt *ys, int level, cbuf *cb) @@ -1200,11 +1200,11 @@ yang2cli_uses(clicon_handle h, if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0) goto done; if (ygrouping == NULL){ - clicon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys)); + clixon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys)); goto done; } if ((cbtree = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } /* prefix is not globally unique, need namespace */ @@ -1250,7 +1250,7 @@ yang2cli_uses(clicon_handle h, * @retval -1 Error */ static int -yang2cli_stmt(clicon_handle h, +yang2cli_stmt(clixon_handle h, yang_stmt *ys, int level, cbuf *cb) @@ -1262,7 +1262,7 @@ yang2cli_stmt(clicon_handle h, int extvalue = 0; if (ys == NULL){ - clicon_err(OE_YANG, EINVAL, "No yang spec"); + clixon_err(OE_YANG, EINVAL, "No yang spec"); goto done; } if (yang_find(ys, Y_STATUS, "obsolete") != NULL){ @@ -1350,11 +1350,11 @@ cvec_add_name(cvec *cvv, if (cvv == NULL && (cvv = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); return NULL; } if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); return NULL; } /* Filter out state data, use "nonconfig" as defined in RFC8040 4.8.1 @@ -1392,7 +1392,7 @@ cvec_add_name(cvec *cvv, * (2) rewrite yang2cli code to create pt directly instead of via a cbuf. */ static int -yang2cli_post(clicon_handle h, +yang2cli_post(clixon_handle h, cg_obj *cop, parse_tree *pt, int i0, @@ -1412,7 +1412,7 @@ yang2cli_post(clicon_handle h, ypkeyword = yang_keyword_get(yp); for (i = i0; ico_type == CO_EMPTY){ @@ -1517,7 +1517,7 @@ yang2cli_post(clicon_handle h, * XXX merge with yang2cli_yspec */ static int -yang2cli_grouping(clicon_handle h, +yang2cli_grouping(clixon_handle h, yang_stmt *ys, char *treename) { @@ -1534,11 +1534,11 @@ yang2cli_grouping(clicon_handle h, int i; if ((pt0 = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } /* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */ @@ -1564,11 +1564,11 @@ yang2cli_grouping(clicon_handle h, * Needs to move cligen_parse_str() call here instead of later */ if ((prefix = yang_find_myprefix(ys)) == NULL){ - clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ys)); /* shouldnt happen */ + clixon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ys)); /* shouldnt happen */ goto done; } if ((pt = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } /* Parse the buffer using cligen parser. load cli syntax */ @@ -1596,13 +1596,13 @@ yang2cli_grouping(clicon_handle h, goto done; } if (clicon_data_int_get(h, "autocli-print-debug") == 1) - clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", + clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", __FUNCTION__, treename, cbuf_get(cb)); else 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"); + clixon_err(OE_YANG, errno, "cligen_parsetree_merge"); goto done; } pt_free(pt, 1); @@ -1617,11 +1617,11 @@ yang2cli_grouping(clicon_handle h, goto done; /* Append cligen tree and name it */ if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_UNIX, 0, "cligen_ph_add"); + clixon_err(OE_UNIX, 0, "cligen_ph_add"); goto done; } if (cligen_ph_parsetree_set(ph, pt0) < 0){ - clicon_err(OE_UNIX, 0, "cligen_ph_parsetree_set"); + clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set"); goto done; } pt0 = NULL; @@ -1651,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(clixon_handle h, yang_stmt *yspec, char *treename) { @@ -1668,11 +1668,11 @@ yang2cli_yspec(clicon_handle h, int config; if ((pt0 = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } /* Traverse YANG, loop through all modules and generate CLI */ @@ -1694,11 +1694,11 @@ yang2cli_yspec(clicon_handle h, * Needs to move cligen_parse_str() call here instead of later */ if ((prefix = yang_find_myprefix(ymod)) == NULL){ - clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */ + clixon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */ goto done; } if ((pt = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } /* Parse the buffer using cligen parser. load cli syntax */ @@ -1727,13 +1727,13 @@ yang2cli_yspec(clicon_handle h, } // pt_print(stderr,pt); if (clicon_data_int_get(h, "autocli-print-debug") == 1) - clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", + clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s", __FUNCTION__, treename, cbuf_get(cb)); else 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"); + clixon_err(OE_YANG, errno, "cligen_parsetree_merge"); goto done; } pt_free(pt, 1); @@ -1748,17 +1748,17 @@ yang2cli_yspec(clicon_handle h, goto done; /* Append cligen tree and name it */ if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_UNIX, 0, "cligen_ph_add"); + clixon_err(OE_UNIX, 0, "cligen_ph_add"); goto done; } if (cligen_ph_parsetree_set(ph, pt0) < 0){ - clicon_err(OE_UNIX, 0, "cligen_ph_parsetree_set"); + clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set"); goto done; } pt0 = NULL; #if 0 if (clicon_data_int_get(h, "autocli-print-debug") == 1){ - clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename); + clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename); pt_print1(stderr, pt0, 0); } #endif @@ -1781,7 +1781,7 @@ yang2cli_yspec(clicon_handle h, * @param[in] h Clixon handle */ int -yang2cli_init(clicon_handle h) +yang2cli_init(clixon_handle h) { return 0; } diff --git a/apps/cli/cli_generate.h b/apps/cli/cli_generate.h index 69014df2..3f1f07e9 100644 --- a/apps/cli/cli_generate.h +++ b/apps/cli/cli_generate.h @@ -61,7 +61,7 @@ /* * Prototypes */ -int yang2cli_yspec(clicon_handle h, yang_stmt *yspec, char *treename); -int yang2cli_init(clicon_handle h); +int yang2cli_yspec(clixon_handle h, yang_stmt *yspec, char *treename); +int yang2cli_init(clixon_handle h); #endif /* _CLI_GENERATE_H_ */ diff --git a/apps/cli/cli_handle.c b/apps/cli/cli_handle.c index e2e38c42..2c46c702 100644 --- a/apps/cli/cli_handle.c +++ b/apps/cli/cli_handle.c @@ -60,7 +60,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_cli_api.h" @@ -69,15 +69,15 @@ #define CLICON_MAGIC 0x99aafabe -#define handle(h) (assert(clicon_handle_check(h)==0),(struct cli_handle *)(h)) +#define handle(h) (assert(clixon_handle_check(h)==0),(struct cli_handle *)(h)) #define cligen(h) (handle(h)->cl_cligen) /*! 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 - * @see struct clicon_handle, struct backend_handle + * @note The top part must be equivalent to struct clixon_handle in clixon_handle.c + * @see struct clixon_handle, struct backend_handle */ struct cli_handle { int cl_magic; /* magic (HDR)*/ @@ -92,25 +92,25 @@ struct cli_handle { /*! Return a clicon handle for other CLICON API calls */ -clicon_handle +clixon_handle cli_handle_init(void) { struct cli_handle *cl; cligen_handle clih = NULL; - clicon_handle h = NULL; + clixon_handle h = NULL; - if ((cl = (struct cli_handle *)clicon_handle_init0(sizeof(struct cli_handle))) == NULL) + if ((cl = (struct cli_handle *)clixon_handle_init0(sizeof(struct cli_handle))) == NULL) return NULL; if ((clih = cligen_init()) == NULL){ - clicon_handle_exit((clicon_handle)cl); + clixon_handle_exit((clixon_handle)cl); goto done; } cligen_userhandle_set(clih, cl); cligen_eval_wrap_fn_set(clih, plugin_context_check, cl); cl->cl_cligen = clih; - h = (clicon_handle)cl; + h = (clixon_handle)cl; done: return h; } @@ -120,11 +120,11 @@ cli_handle_init(void) * @param[in] h Clixon handle */ int -cli_handle_exit(clicon_handle h) +cli_handle_exit(clixon_handle h) { cligen_handle ch = cligen(h); - clicon_handle_exit(h); /* frees h and options */ + clixon_handle_exit(h); /* frees h and options */ cligen_exit(ch); return 0; } @@ -138,13 +138,13 @@ cli_handle_exit(clicon_handle h) * @param[in] h Clixon handle */ cligen_handle -cli_cligen(clicon_handle h) +cli_cligen(clixon_handle h) { return cligen(h); } int -cli_parse_file(clicon_handle h, +cli_parse_file(clixon_handle h, FILE *f, char *name, /* just for errs */ parse_tree *pt, @@ -156,7 +156,7 @@ cli_parse_file(clicon_handle h, } int -cli_susp_hook(clicon_handle h, +cli_susp_hook(clixon_handle h, cligen_susp_cb_t *fn) { cligen_handle ch = cligen(h); @@ -166,7 +166,7 @@ cli_susp_hook(clicon_handle h, } int -cli_interrupt_hook(clicon_handle h, +cli_interrupt_hook(clixon_handle h, cligen_interrupt_cb_t *fn) { cligen_handle ch = cligen(h); @@ -176,7 +176,7 @@ cli_interrupt_hook(clicon_handle h, } int -cli_prompt_set(clicon_handle h, +cli_prompt_set(clixon_handle h, char *prompt) { cligen_handle ch = cligen(h); @@ -184,7 +184,7 @@ cli_prompt_set(clicon_handle h, } int -cli_logsyntax_set(clicon_handle h, +cli_logsyntax_set(clixon_handle h, int status) { cligen_handle ch = cligen(h); diff --git a/apps/cli/cli_handle.h b/apps/cli/cli_handle.h index 4370b7aa..418cad22 100644 --- a/apps/cli/cli_handle.h +++ b/apps/cli/cli_handle.h @@ -43,18 +43,18 @@ * Prototypes * Internal prototypes. For exported functions see clixon_cli_api.h */ -int cli_parse_file(clicon_handle h, +int cli_parse_file(clixon_handle h, FILE *f, char *name, /* just for errs */ parse_tree *pt, cvec *globals); -int cli_susp_hook(clicon_handle h, cligen_susp_cb_t *fn); +int cli_susp_hook(clixon_handle h, cligen_susp_cb_t *fn); -int cli_interrupt_hook(clicon_handle h, cligen_interrupt_cb_t *fn); +int cli_interrupt_hook(clixon_handle h, cligen_interrupt_cb_t *fn); -int cli_prompt_set(clicon_handle h, char *prompt); +int cli_prompt_set(clixon_handle h, char *prompt); -int cli_logsyntax_set(clicon_handle h, int status); +int cli_logsyntax_set(clixon_handle h, int status); #endif /* _CLI_HANDLE_H_ */ diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 1eb53060..e7937581 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -61,7 +61,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_cli_api.h" @@ -82,7 +82,7 @@ * @retval -1 Error */ static int -cli_history_load(clicon_handle h) +cli_history_load(clixon_handle h) { int retval = -1; int lines; @@ -101,16 +101,16 @@ cli_history_load(clicon_handle h) if ((filename = clicon_option_str(h,"CLICON_CLI_HIST_FILE")) == NULL) goto ok; /* ignore */ if (wordexp(filename, &result, 0) < 0){ - clicon_err(OE_UNIX, errno, "wordexp"); + clixon_err(OE_UNIX, errno, "wordexp"); goto done; } if ((f = fopen(result.we_wordv[0], "r")) == NULL){ - clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s", + clixon_log(h, LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s", result.we_wordv[0], strerror(errno)); goto ok; } if (cligen_hist_file_load(cli_cligen(h), f) < 0){ - clicon_err(OE_UNIX, errno, "cligen_hist_file_load"); + clixon_err(OE_UNIX, errno, "cligen_hist_file_load"); goto done; } ok: @@ -130,7 +130,7 @@ cli_history_load(clicon_handle h) * @retval -1 Error */ static int -cli_history_save(clicon_handle h) +cli_history_save(clixon_handle h) { int retval = -1; char *filename; @@ -140,16 +140,16 @@ cli_history_save(clicon_handle h) if ((filename = clicon_option_str(h, "CLICON_CLI_HIST_FILE")) == NULL) goto ok; /* ignore */ if (wordexp(filename, &result, 0) < 0){ - clicon_err(OE_UNIX, errno, "wordexp"); + clixon_err(OE_UNIX, errno, "wordexp"); goto done; } if ((f = fopen(result.we_wordv[0], "w+")) == NULL){ - clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s", + clixon_log(h, LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s", result.we_wordv[0], strerror(errno)); goto ok; } if (cligen_hist_file_save(cli_cligen(h), f) < 0){ - clicon_err(OE_UNIX, errno, "cligen_hist_file_save"); + clixon_err(OE_UNIX, errno, "cligen_hist_file_save"); goto done; } ok: @@ -167,7 +167,7 @@ cli_history_save(clicon_handle h) * @param[in] h Clixon handle */ static int -cli_terminate(clicon_handle h) +cli_terminate(clixon_handle h) { yang_stmt *yspec; cvec *nsctx; @@ -196,7 +196,7 @@ cli_terminate(clicon_handle h) cli_history_save(h); cli_handle_exit(h); clixon_err_exit(); - clicon_log_exit(); + clixon_log_exit(); return 0; } @@ -205,7 +205,7 @@ cli_terminate(clicon_handle h) static void cli_sig_term(int arg) { - clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)", + clixon_log(NULL, LOG_NOTICE, "%s: %u Terminated (killed by sig %d)", __PROGRAM__, getpid(), arg); exit(1); } @@ -213,17 +213,17 @@ cli_sig_term(int arg) /*! Setup signal handlers */ static int -cli_signal_init (clicon_handle h) +cli_signal_init (clixon_handle h) { int retval = -1; cli_signal_block(h); if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){ - clicon_err(OE_UNIX, errno, "Setting SIGTERM signal"); + clixon_err(OE_UNIX, errno, "Setting SIGTERM signal"); goto done; } if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ - clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal"); + clixon_err(OE_UNIX, errno, "Setting DIGPIPE signal"); goto done; } retval = 0; @@ -239,7 +239,7 @@ cli_signal_init (clicon_handle h) * @see cligen_loop */ static int -cli_interactive(clicon_handle h) +cli_interactive(clixon_handle h) { int retval = -1; char *cmd; @@ -251,7 +251,7 @@ cli_interactive(clicon_handle h) /* Loop through all commands */ while(!cligen_exiting(cli_cligen(h))) { if ((ph = cligen_pt_head_active_get(cli_cligen(h))) == NULL){ - clicon_err(OE_UNIX, 0, "active tree not found"); + clixon_err(OE_UNIX, 0, "active tree not found"); goto done; } new_mode = cligen_ph_name_get(ph); @@ -280,7 +280,7 @@ cli_interactive(clicon_handle h) * should probably be moved to clispec default */ static int -autocli_trees_default(clicon_handle h) +autocli_trees_default(clixon_handle h) { int retval = -1; cbuf *cb = NULL; @@ -292,7 +292,7 @@ autocli_trees_default(clicon_handle h) if ((ph = cligen_ph_add(cli_cligen(h), "datamodel")) == NULL) goto done; if ((pt = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } if (clispec_parse_str(cli_cligen(h), @@ -306,7 +306,7 @@ autocli_trees_default(clicon_handle h) if ((ph = cligen_ph_add(cli_cligen(h), "datamodelshow")) == NULL) goto done; if ((pt = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } if (clispec_parse_str(cli_cligen(h), @@ -319,7 +319,7 @@ autocli_trees_default(clicon_handle h) if ((ph = cligen_ph_add(cli_cligen(h), "datamodelstate")) == NULL) goto done; if ((pt = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } if (clispec_parse_str(cli_cligen(h), @@ -333,11 +333,11 @@ autocli_trees_default(clicon_handle h) if ((ph = cligen_ph_add(cli_cligen(h), "datamodelmode")) == NULL) goto done; if ((pt = pt_new()) == NULL){ - clicon_err(OE_UNIX, errno, "pt_new"); + clixon_err(OE_UNIX, errno, "pt_new"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "@basemodel, @remove:act-prekey, @remove:act-leafconst, @remove:ac-state"); @@ -385,7 +385,7 @@ autocli_trees_default(clicon_handle h) * @retval -1 Error */ static int -autocli_start(clicon_handle h) +autocli_start(clixon_handle h) { int retval = -1; yang_stmt *yspec; @@ -435,7 +435,7 @@ autocli_start(clicon_handle h) * @retval -1 Error */ static int -options_split(clicon_handle h, +options_split(clixon_handle h, char *argv0, int argc, char **argv, @@ -470,7 +470,7 @@ options_split(clicon_handle h, } static void -usage(clicon_handle h, +usage(clixon_handle h, char *argv0) { char *plgdir = clicon_cli_dir(h); @@ -518,10 +518,10 @@ main(int argc, int once; char *tmp; char *argv0 = argv[0]; - clicon_handle h; + clixon_handle h; int logclisyntax = 0; int help = 0; - int logdst = CLICON_LOG_STDERR; + int logdst = CLIXON_LOG_STDERR; char *restarg = NULL; /* what remains after options */ yang_stmt *yspec; struct passwd *pw; @@ -540,18 +540,20 @@ main(int argc, once = 0; config_dump = 0; - /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__PROGRAM__, LOG_INFO, logdst); - /* Initiate Clixon handle. CLIgen is also initialized */ if ((h = cli_handle_init()) == NULL) goto done; + /* In the startup, logs to stderr & debug flag set later */ + if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0) + goto done; + if (clixon_err_init(h) < 0) + goto done; /* Set username to clicon handle. Use in all communication to backend * Note, can be overridden by -U */ if ((pw = getpwuid(getuid())) == NULL){ - clicon_err(OE_UNIX, errno, "getpwuid"); + clixon_err(OE_UNIX, errno, "getpwuid"); goto done; } if (clicon_username_set(h, pw->pw_name) < 0) @@ -594,19 +596,19 @@ main(int argc, clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); break; case 'l': /* Log destination: s|e|o|f */ - if ((logdst = clicon_log_opt(optarg[0])) < 0) + if ((logdst = clixon_log_opt(optarg[0])) < 0) usage(h, argv[0]); - if (logdst == CLICON_LOG_FILE && + if (logdst == CLIXON_LOG_FILE && strlen(optarg)>1 && - clicon_log_file(optarg+1) < 0) + clixon_log_file(optarg+1) < 0) goto done; break; } /* * Logs, error and debug to stderr or syslog, set debug level */ - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clixon_debug_init(dbg, NULL); + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); + clixon_debug_init(h, dbg); yang_init(h); /* Find, read and parse configfile */ @@ -734,7 +736,7 @@ main(int argc, /* Enable XSD libxml2 regex engine */ cligen_regex_xsd_set(cli_cligen(h), 1); #else - clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); + clixon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))"); goto done; #endif } @@ -746,7 +748,7 @@ main(int argc, cligen_helpstring_lines_set(cli_cligen(h), nr); if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) - clicon_log_string_limit_set(nr); + clixon_log_string_limit_set(nr); /* Setup signal handlers */ if (cli_signal_init(h) < 0) @@ -852,7 +854,7 @@ main(int argc, goto done; } if (cligen_ph_find(cli_cligen(h), cli_syntax_mode(h)) == NULL) - clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m on command line", cli_syntax_mode(h)); + clixon_log(h, LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m on command line", cli_syntax_mode(h)); /* CLIgen tab mode, ie how s behave */ if ((tabmode = clicon_cli_tab_mode(h)) < 0){ fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n"); @@ -922,9 +924,9 @@ main(int argc, done: if (restarg) free(restarg); - // Gets in your face if we log on stderr - clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ - clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); +// Gets in your face if we log on stderr + clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ + clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); if (h) cli_terminate(h); return retval; diff --git a/apps/cli/cli_pipe.c b/apps/cli/cli_pipe.c index cdee5bd0..5e7cbb43 100644 --- a/apps/cli/cli_pipe.c +++ b/apps/cli/cli_pipe.c @@ -67,7 +67,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "clixon_cli_api.h" @@ -83,7 +83,7 @@ * @endcode */ int -pipe_arg_fn(clicon_handle h, +pipe_arg_fn(clixon_handle h, char *cmd, char *option, char *value) @@ -94,19 +94,19 @@ pipe_arg_fn(clicon_handle h, int i; if (cmd == NULL || strlen(cmd) == 0){ - clicon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd); + clixon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd); goto done; } if (stat(cmd, &fstat) < 0) { - clicon_err(OE_UNIX, errno, "stat(%s)", cmd); + clixon_err(OE_UNIX, errno, "stat(%s)", cmd); goto done; } if (!S_ISREG(fstat.st_mode)){ - clicon_err(OE_UNIX, errno, "%s is not a regular file", cmd); + clixon_err(OE_UNIX, errno, "%s is not a regular file", cmd); goto done; } if ((argv = calloc(4, sizeof(char *))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } i = 0; @@ -129,7 +129,7 @@ pipe_arg_fn(clicon_handle h, * @note Any vertical bar (|] in the patterns field is quoted for OR function */ int -pipe_grep_fn(clicon_handle h, +pipe_grep_fn(clixon_handle h, cvec *cvv, cvec *argv) { @@ -144,7 +144,7 @@ pipe_grep_fn(clicon_handle h, char c; if (cvec_len(argv) != 2){ - clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: ]]>]]> */ static int -netconf_get(clicon_handle h, +netconf_get(clixon_handle h, cxobj *xn, cxobj **xret) { @@ -453,7 +453,7 @@ netconf_notification_cb(int s, cbuf *cb = NULL; cxobj *xn = NULL; /* event xml */ cxobj *xt = NULL; /* top xml */ - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; yang_stmt *yspec = NULL; cvec *nsc = NULL; int ret; @@ -465,7 +465,7 @@ netconf_notification_cb(int s, goto done; /* handle close from remote end: this will exit the client */ if (eof){ - clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); + clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); close(s); errno = ESHUTDOWN; clixon_event_unreg_fd(s, netconf_notification_cb); @@ -475,7 +475,7 @@ netconf_notification_cb(int s, if ((ret = clicon_msg_decode(reply, yspec, NULL, &xt, &xerr)) < 0) goto done; if (ret == 0){ /* XXX use xerr */ - clicon_err(OE_NETCONF, EFAULT, "Notification malformed"); + clixon_err(OE_NETCONF, EFAULT, "Notification malformed"); goto done; } if ((nsc = xml_nsctx_init(NULL, NETCONF_NOTIFICATION_NAMESPACE)) == NULL) @@ -484,7 +484,7 @@ netconf_notification_cb(int s, goto ok; /* create netconf message */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) @@ -494,7 +494,7 @@ netconf_notification_cb(int s, goto done; } if (netconf_output(1, cb, "notification") < 0){ - clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); + clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); close(s); errno = ESHUTDOWN; clixon_event_unreg_fd(s, netconf_notification_cb); @@ -532,7 +532,7 @@ netconf_notification_cb(int s, * @see netconf_notification_cb for asynchronous stream notifications */ static int -netconf_create_subscription(clicon_handle h, +netconf_create_subscription(clixon_handle h, cxobj *xn, cxobj **xret) { @@ -585,7 +585,7 @@ netconf_create_subscription(clicon_handle h, * @see netconf_input_packet Assume bind and validation made there */ static int -netconf_application_rpc(clicon_handle h, +netconf_application_rpc(clixon_handle h, cxobj *xn, cxobj **xret) { @@ -603,17 +603,17 @@ netconf_application_rpc(clicon_handle h, /* First check system / netconf RPC:s */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, 0, "cbuf_new"); + clixon_err(OE_UNIX, 0, "cbuf_new"); goto done; } if ((cbret = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, 0, "cbuf_new"); + clixon_err(OE_UNIX, 0, "cbuf_new"); goto done; } /* Find yang rpc statement, return yang rpc statement if found Check application RPC */ if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } cbuf_reset(cb); @@ -666,7 +666,7 @@ netconf_application_rpc(clicon_handle h, if (ret == 0){ if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; - clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret)); + clixon_log(h, LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret)); goto ok; } } @@ -697,7 +697,7 @@ netconf_application_rpc(clicon_handle h, * @retval -1 Error, fatal */ int -netconf_rpc_dispatch(clicon_handle h, +netconf_rpc_dispatch(clixon_handle h, cxobj *xn, cxobj **xret, int *eof) diff --git a/apps/netconf/netconf_rpc.h b/apps/netconf/netconf_rpc.h index cda97886..235300df 100644 --- a/apps/netconf/netconf_rpc.h +++ b/apps/netconf/netconf_rpc.h @@ -43,7 +43,7 @@ * Prototypes */ int -netconf_rpc_dispatch(clicon_handle h, +netconf_rpc_dispatch(clixon_handle h, cxobj *xn, cxobj **xret, int *eof); diff --git a/apps/restconf/clixon_http1_parse.h b/apps/restconf/clixon_http1_parse.h index dd4a4024..b925591c 100644 --- a/apps/restconf/clixon_http1_parse.h +++ b/apps/restconf/clixon_http1_parse.h @@ -41,7 +41,7 @@ */ struct clixon_http1_yacc { const char *hy_name; /* Name of syntax (for error string) */ - clicon_handle hy_h; /* Clixon handle */ + clixon_handle hy_h; /* Clixon handle */ restconf_conn *hy_rc; /* Connection handle */ int hy_linenum; /* Number of \n in parsed buffer */ char *hy_parse_string; /* original (copy of) parse string */ diff --git a/apps/restconf/clixon_http1_parse.y b/apps/restconf/clixon_http1_parse.y index 0ab929e0..c1bcc76a 100644 --- a/apps/restconf/clixon_http1_parse.y +++ b/apps/restconf/clixon_http1_parse.y @@ -78,7 +78,7 @@ /* typecast macro */ #define _HY ((clixon_http1_yacc *)_hy) -#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_http1_parsetext, _HY->hy_linenum); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_http1_parsetext, _HY->hy_linenum); YYERROR;} /* add _yy to error parameters */ #define YY_(msgid) msgid @@ -124,7 +124,7 @@ void clixon_http1_parseerror(void *_hy, char *s) { - clicon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'", + clixon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'", _HY->hy_name, _HY->hy_linenum, s, @@ -153,7 +153,7 @@ http1_parse_query(clixon_http1_yacc *hy, clixon_debug(CLIXON_DBG_DEFAULT, "%s: ?%s ", __FUNCTION__, query); if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){ - clicon_err(OE_RESTCONF, 0, "stream 0 not found"); + clixon_err(OE_RESTCONF, 0, "stream 0 not found"); goto done; } if (uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0) @@ -172,11 +172,11 @@ http1_body(clixon_http1_yacc *hy, clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s ", __FUNCTION__, body); if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){ - clicon_err(OE_RESTCONF, 0, "stream 0 not found"); + clixon_err(OE_RESTCONF, 0, "stream 0 not found"); goto done; } if (cbuf_append_buf(sd->sd_indata, body, strlen(body)) < 0){ - clicon_err(OE_RESTCONF, errno, "cbuf_append_buf"); + clixon_err(OE_RESTCONF, errno, "cbuf_append_buf"); goto done; } retval = 0; diff --git a/apps/restconf/clixon_http_data.c b/apps/restconf/clixon_http_data.c index 735d4d23..95475eb9 100644 --- a/apps/restconf/clixon_http_data.c +++ b/apps/restconf/clixon_http_data.c @@ -58,7 +58,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include /* restconf */ @@ -91,7 +91,7 @@ static const map_str2str mime_map[] = { * @retval 0 No, not a data path, or not enabled */ int -api_path_is_data(clicon_handle h) +api_path_is_data(clixon_handle h) { int retval = 0; char *path = NULL; @@ -124,7 +124,7 @@ api_path_is_data(clicon_handle h) * @see api_return_err */ static int -api_http_data_err(clicon_handle h, +api_http_data_err(clixon_handle h, void *req, int code) { @@ -133,7 +133,7 @@ api_http_data_err(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (restconf_reply_header(req, "Content-Type", "text/html") < 0) @@ -173,7 +173,7 @@ api_http_data_err(clicon_handle h, * @retval -1 Error */ static int -http_data_check_file_path(clicon_handle h, +http_data_check_file_path(clixon_handle h, void *req, char *prefix, cbuf *cbpath, @@ -188,13 +188,13 @@ http_data_check_file_path(clicon_handle h, FILE *f; if (prefix == NULL || cbpath == NULL || fp == NULL){ - clicon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL"); + clixon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL"); goto done; } p = cbuf_get(cbpath); clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, p); if (strncmp(prefix, p, strlen(prefix)) != 0){ - clicon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath"); + clixon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath"); goto done; } for (i=strlen(prefix); i -/* clicon */ +/* clixon */ #include /* restconf */ diff --git a/apps/restconf/restconf_api_fcgi.c b/apps/restconf/restconf_api_fcgi.c index ca4b6021..30bdc2d4 100644 --- a/apps/restconf/restconf_api_fcgi.c +++ b/apps/restconf/restconf_api_fcgi.c @@ -59,7 +59,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include /* Need to be after clixon_xml-h due to attribute format */ @@ -108,7 +108,7 @@ restconf_reply_header(void *req0, va_list ap; if (req == NULL || name == NULL || vfmt == NULL){ - clicon_err(OE_CFG, EINVAL, "req, name or value is NULL"); + clixon_err(OE_CFG, EINVAL, "req, name or value is NULL"); return -1; } va_start(ap, vfmt); @@ -116,13 +116,13 @@ restconf_reply_header(void *req0, va_end(ap); /* allocate value string exactly fitting */ if ((value = malloc(vlen+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: compute actual value */ va_start(ap, vfmt); if (vsnprintf(value, vlen+1, vfmt, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -158,7 +158,7 @@ restconf_reply_body_add(void *req0, va_list ap; if (req == NULL || bfmt == NULL){ - clicon_err(OE_CFG, EINVAL, "req or body is NULL"); + clixon_err(OE_CFG, EINVAL, "req or body is NULL"); return -1; } va_start(ap, bfmt); @@ -166,13 +166,13 @@ restconf_reply_body_add(void *req0, va_end(ap); /* allocate body string exactly fitting */ if ((body = malloc(blen+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: compute actual body */ va_start(ap, bfmt); if (vsnprintf(body, blen+1, bfmt, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } diff --git a/apps/restconf/restconf_api_native.c b/apps/restconf/restconf_api_native.c index f9244942..3cd6643a 100644 --- a/apps/restconf/restconf_api_native.c +++ b/apps/restconf/restconf_api_native.c @@ -57,7 +57,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" @@ -88,11 +88,11 @@ restconf_reply_header(void *req0, clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name); if (sd == NULL || name == NULL || vfmt == NULL){ - clicon_err(OE_CFG, EINVAL, "sd, name or value is NULL"); + clixon_err(OE_CFG, EINVAL, "sd, name or value is NULL"); goto done; } if ((rc = sd->sd_conn) == NULL){ - clicon_err(OE_CFG, EINVAL, "rc is NULL"); + clixon_err(OE_CFG, EINVAL, "rc is NULL"); goto done; } /* First round: compute vlen and allocate value */ @@ -101,19 +101,19 @@ restconf_reply_header(void *req0, va_end(ap); /* allocate value string exactly fitting */ if ((value = malloc(vlen+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* Second round: compute actual value */ va_start(ap, vfmt); if (vsnprintf(value, vlen+1, vfmt, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } va_end(ap); if (cvec_add_string(sd->sd_outp_hdrs, (char*)name, value) < 0){ - clicon_err(OE_RESTCONF, errno, "cvec_add_string"); + clixon_err(OE_RESTCONF, errno, "cvec_add_string"); goto done; } retval = 0; @@ -144,7 +144,7 @@ restconf_reply_send(void *req0, clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code); if (sd == NULL){ - clicon_err(OE_CFG, EINVAL, "sd is NULL"); + clixon_err(OE_CFG, EINVAL, "sd is NULL"); goto done; } sd->sd_code = code; @@ -183,7 +183,7 @@ restconf_get_indata(void *req0) cbuf *cb = NULL; if (sd == NULL){ - clicon_err(OE_CFG, EINVAL, "sd is NULL"); + clixon_err(OE_CFG, EINVAL, "sd is NULL"); goto done; } cb = sd->sd_indata; diff --git a/apps/restconf/restconf_err.c b/apps/restconf/restconf_err.c index df2efb4f..d0a24821 100644 --- a/apps/restconf/restconf_err.c +++ b/apps/restconf/restconf_err.c @@ -62,7 +62,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" @@ -79,7 +79,7 @@ * @retval -1 Error */ int -restconf_method_notallowed(clicon_handle h, +restconf_method_notallowed(clixon_handle h, void *req, char *allow, int pretty, @@ -112,7 +112,7 @@ restconf_method_notallowed(clicon_handle h, * return an error response with a "415 Unsupported Media Type" status-line */ int -restconf_unsupported_media(clicon_handle h, +restconf_unsupported_media(clixon_handle h, void *req, int pretty, restconf_media media) @@ -142,7 +142,7 @@ restconf_unsupported_media(clicon_handle h, * return an error response with a "406 Not Acceptable" status-line. */ int -restconf_not_acceptable(clicon_handle h, +restconf_not_acceptable(clixon_handle h, void *req, int pretty, restconf_media media) @@ -166,7 +166,7 @@ restconf_not_acceptable(clicon_handle h, * @param[in] req Generic http handle */ int -restconf_notimplemented(clicon_handle h, +restconf_notimplemented(clixon_handle h, void *req, int pretty, restconf_media media) @@ -201,7 +201,7 @@ restconf_notimplemented(clicon_handle h, * @note there are special cases see code */ int -api_return_err(clicon_handle h, +api_return_err(clixon_handle h, void *req, cxobj *xerr, int pretty, @@ -220,7 +220,7 @@ api_return_err(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* A well-formed error message when entering here should look like: @@ -230,7 +230,7 @@ api_return_err(clicon_handle h, if (strcmp(xml_name(xerr), "rpc-error") != 0 || (xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "Internal error, system returned invalid error message: "); @@ -240,11 +240,11 @@ api_return_err(clicon_handle h, cbuf_get(cberr)) < 0) goto done; if ((xerr = xpath_first(xerr2, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, 0, "Internal error, shouldnt happen"); + clixon_err(OE_XML, 0, "Internal error, shouldnt happen"); goto done; } if ((xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){ - clicon_err(OE_XML, 0, "Internal error, shouldnt happen"); + clixon_err(OE_XML, 0, "Internal error, shouldnt happen"); goto done; } } @@ -318,7 +318,7 @@ api_return_err(clicon_handle h, } break; default: /* Just ignore the body so that there is a reply */ - clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media); + clixon_err(OE_YANG, EINVAL, "Invalid media type %d", media); goto done; break; } /* switch media */ @@ -353,7 +353,7 @@ api_return_err(clicon_handle h, * @see api_return_err where top level is expected to be */ int -api_return_err0(clicon_handle h, +api_return_err0(clixon_handle h, void *req, cxobj *xerr, int pretty, @@ -364,7 +364,7 @@ api_return_err0(clicon_handle h, cxobj *xe; if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, EINVAL, "Expected xml on the form .."); + clixon_err(OE_XML, EINVAL, "Expected xml on the form .."); goto done; } if (api_return_err(h, req, xe, pretty, media, code) < 0) diff --git a/apps/restconf/restconf_err.h b/apps/restconf/restconf_err.h index 1c837f1b..454690d5 100644 --- a/apps/restconf/restconf_err.h +++ b/apps/restconf/restconf_err.h @@ -43,13 +43,13 @@ * Prototypes */ -int restconf_method_notallowed(clicon_handle h, void *req, char *allow, int pretty, restconf_media media); -int restconf_unsupported_media(clicon_handle h, void *req, int pretty, restconf_media media); -int restconf_not_acceptable(clicon_handle h, void *req, int pretty, restconf_media media); -int restconf_notimplemented(clicon_handle h, void *req, int pretty, restconf_media media); +int restconf_method_notallowed(clixon_handle h, void *req, char *allow, int pretty, restconf_media media); +int restconf_unsupported_media(clixon_handle h, void *req, int pretty, restconf_media media); +int restconf_not_acceptable(clixon_handle h, void *req, int pretty, restconf_media media); +int restconf_notimplemented(clixon_handle h, void *req, int pretty, restconf_media media); -int api_return_err(clicon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0); -int api_return_err0(clicon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0); +int api_return_err(clixon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0); +int api_return_err0(clixon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0); #endif /* _RESTCONF_ERR_H_ */ diff --git a/apps/restconf/restconf_handle.c b/apps/restconf/restconf_handle.c index 26dc3f8b..9b514fe4 100644 --- a/apps/restconf/restconf_handle.c +++ b/apps/restconf/restconf_handle.c @@ -58,20 +58,20 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" #include "restconf_handle.h" -/* header part is copied from struct clicon_handle in lib/src/clixon_handle.c */ +/* header part is copied from struct clixon_handle in lib/src/clixon_handle.c */ #define CLICON_MAGIC 0x99aafabe -#define handle(h) (assert(clicon_handle_check(h)==0),(struct restconf_handle *)(h)) +#define handle(h) (assert(clixon_handle_check(h)==0),(struct restconf_handle *)(h)) -/* Clicon_handle for backends. - * First part of this is header, same for clicon_handle and cli_handle. +/* Clixon_handle for backends. + * First part of this is header, same for clixon_handle and cli_handle. * Access functions for common fields are found in clicon lib: clicon_options.[ch] * This file should only contain access functions for the _specific_ * entries in the struct below. @@ -80,8 +80,8 @@ * * 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 - * @see struct clicon_handle, struct cli_handle + * @note The top part must be equivalent to struct clixon_handle in clixon_handle.c + * @see struct clixon_handle, struct cli_handle */ struct restconf_handle { int rh_magic; /* magic (HDR)*/ @@ -100,12 +100,12 @@ struct restconf_handle { /*! Creates and returns a clicon config handle for other CLICON API calls */ -clicon_handle +clixon_handle restconf_handle_init(void) { struct restconf_handle *rh; - rh = clicon_handle_init0(sizeof(struct restconf_handle)); + rh = clixon_handle_init0(sizeof(struct restconf_handle)); rh->rh_pretty = 1; /* clixon-restconf.yang : pretty is default true*/ return rh; } @@ -116,13 +116,13 @@ restconf_handle_init(void) * @see backend_client_rm */ int -restconf_handle_exit(clicon_handle h) +restconf_handle_exit(clixon_handle h) { struct restconf_handle *rh = handle(h); if (rh->rh_fcgi_socket) free(rh->rh_fcgi_socket); - clicon_handle_exit(h); /* frees h and options (and streams) */ + clixon_handle_exit(h); /* frees h and options (and streams) */ return 0; } @@ -134,7 +134,7 @@ restconf_handle_exit(clicon_handle h) * Currently using clixon runtime data but there is risk for colliding names */ char * -restconf_param_get(clicon_handle h, +restconf_param_get(clixon_handle h, const char *param) { struct restconf_handle *rh = handle(h); @@ -154,7 +154,7 @@ restconf_param_get(clicon_handle h, * Currently using clixon runtime data but there is risk for colliding names */ int -restconf_param_set(clicon_handle h, +restconf_param_set(clixon_handle h, const char *param, char *val) { @@ -176,7 +176,7 @@ restconf_param_set(clicon_handle h, * Currently using clixon runtime data but there is risk for colliding names */ int -restconf_param_del_all(clicon_handle h) +restconf_param_del_all(clixon_handle h) { int retval = -1; struct restconf_handle *rh = handle(h); @@ -197,7 +197,7 @@ restconf_param_del_all(clicon_handle h) * @retval auth_type */ clixon_auth_type_t -restconf_auth_type_get(clicon_handle h) +restconf_auth_type_get(clixon_handle h) { struct restconf_handle *rh = handle(h); @@ -214,7 +214,7 @@ restconf_auth_type_get(clicon_handle h) * Currently using clixon runtime data but there is risk for colliding names */ int -restconf_auth_type_set(clicon_handle h, +restconf_auth_type_set(clixon_handle h, clixon_auth_type_t type) { struct restconf_handle *rh = handle(h); @@ -229,7 +229,7 @@ restconf_auth_type_set(clicon_handle h, * @retval pretty */ int -restconf_pretty_get(clicon_handle h) +restconf_pretty_get(clixon_handle h) { struct restconf_handle *rh = handle(h); @@ -244,7 +244,7 @@ restconf_pretty_get(clicon_handle h) * @retval -1 Error */ int -restconf_pretty_set(clicon_handle h, +restconf_pretty_set(clixon_handle h, int pretty) { struct restconf_handle *rh = handle(h); @@ -260,7 +260,7 @@ restconf_pretty_set(clicon_handle h, * @retval 1 No, http-data disabled */ int -restconf_http_data_get(clicon_handle h) +restconf_http_data_get(clixon_handle h) { struct restconf_handle *rh = handle(h); @@ -274,7 +274,7 @@ restconf_http_data_get(clicon_handle h) * @retval -1 Error */ int -restconf_http_data_set(clicon_handle h, +restconf_http_data_set(clixon_handle h, int http_data) { struct restconf_handle *rh = handle(h); @@ -289,7 +289,7 @@ restconf_http_data_set(clicon_handle h, * @retval socketpath */ char* -restconf_fcgi_socket_get(clicon_handle h) +restconf_fcgi_socket_get(clixon_handle h) { struct restconf_handle *rh = handle(h); @@ -306,13 +306,13 @@ restconf_fcgi_socket_get(clicon_handle h) * Currently using clixon runtime data but there is risk for colliding names */ int -restconf_fcgi_socket_set(clicon_handle h, +restconf_fcgi_socket_set(clixon_handle h, char *socketpath) { struct restconf_handle *rh = handle(h); if ((rh->rh_fcgi_socket = strdup(socketpath)) == NULL){ - clicon_err(OE_RESTCONF, errno, "strdup"); + clixon_err(OE_RESTCONF, errno, "strdup"); return -1; } return 0; diff --git a/apps/restconf/restconf_handle.h b/apps/restconf/restconf_handle.h index 9dee70be..04c6046b 100644 --- a/apps/restconf/restconf_handle.h +++ b/apps/restconf/restconf_handle.h @@ -42,18 +42,18 @@ /* * Prototypes */ -clicon_handle restconf_handle_init(void); -int restconf_handle_exit(clicon_handle h); -char *restconf_param_get(clicon_handle h, const char *param); -int restconf_param_set(clicon_handle h, const char *param, char *val); -int restconf_param_del_all(clicon_handle h); -clixon_auth_type_t restconf_auth_type_get(clicon_handle h); -int restconf_auth_type_set(clicon_handle h, clixon_auth_type_t type); -int restconf_pretty_get(clicon_handle h); -int restconf_pretty_set(clicon_handle h, int pretty); -int restconf_http_data_get(clicon_handle h); -int restconf_http_data_set(clicon_handle h, int http_data); -char *restconf_fcgi_socket_get(clicon_handle h); -int restconf_fcgi_socket_set(clicon_handle h, char *socketpath); +clixon_handle restconf_handle_init(void); +int restconf_handle_exit(clixon_handle h); +char *restconf_param_get(clixon_handle h, const char *param); +int restconf_param_set(clixon_handle h, const char *param, char *val); +int restconf_param_del_all(clixon_handle h); +clixon_auth_type_t restconf_auth_type_get(clixon_handle h); +int restconf_auth_type_set(clixon_handle h, clixon_auth_type_t type); +int restconf_pretty_get(clixon_handle h); +int restconf_pretty_set(clixon_handle h, int pretty); +int restconf_http_data_get(clixon_handle h); +int restconf_http_data_set(clixon_handle h, int http_data); +char *restconf_fcgi_socket_get(clixon_handle h); +int restconf_fcgi_socket_set(clixon_handle h, char *socketpath); #endif /* _RESTCONF_HANDLE_H_ */ diff --git a/apps/restconf/restconf_http1.c b/apps/restconf/restconf_http1.c index e549808c..e879e640 100644 --- a/apps/restconf/restconf_http1.c +++ b/apps/restconf/restconf_http1.c @@ -78,10 +78,10 @@ * @param[in] str Pointer to string containing HTTP/1 * @param[in] filename Debug string identifying file or connection * @retval 0 Parse OK - * @retval -1 Error with clicon_err called. + * @retval -1 Error */ static int -_http1_parse(clicon_handle h, +_http1_parse(clixon_handle h, restconf_conn *rc, char *str, const char *filename) @@ -109,11 +109,11 @@ _http1_parse(clicon_handle h, http1_scan_exit(&hy); if (ret != 0){ if (filename) - clicon_log(LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename); + clixon_log(h, LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename); else - clicon_log(LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum); - if (clicon_errno == 0) - clicon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)"); + clixon_log(h, LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)"); goto done; } ok: @@ -130,10 +130,10 @@ _http1_parse(clicon_handle h, * @param[in] f A file descriptor containing HTTP/1 (as ASCII characters) * @param[in] filename Debug string identifying file or connection * @retval 0 Parse OK - * @retval -1 Error with clicon_err called. + * @retval -1 Error */ int -clixon_http1_parse_file(clicon_handle h, +clixon_http1_parse_file(clixon_handle h, restconf_conn *rc, FILE *f, const char *filename) @@ -149,18 +149,18 @@ clixon_http1_parse_file(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename); if (f == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "f is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "f is NULL"); goto done; } if ((buf = malloc(buflen)) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(buf, 0, buflen); ptr = buf; while (1){ if ((ret = fread(&ch, 1, 1, f)) < 0){ - clicon_err(OE_XML, errno, "read"); + clixon_err(OE_XML, errno, "read"); break; } if (ret != 0){ @@ -175,7 +175,7 @@ clixon_http1_parse_file(clicon_handle h, oldbuflen = buflen; buflen *= 2; if ((buf = realloc(buf, buflen)) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } memset(buf+oldbuflen, 0, buflen-oldbuflen); @@ -195,10 +195,10 @@ clixon_http1_parse_file(clicon_handle h, * @param[in] rc Restconf connection * @param[in] str HTTP/1 string * @retval 0 Parse OK - * @retval -1 Error with clicon_err called. + * @retval -1 Error */ int -clixon_http1_parse_string(clicon_handle h, +clixon_http1_parse_string(clixon_handle h, restconf_conn *rc, char *str) { @@ -213,12 +213,12 @@ clixon_http1_parse_string(clicon_handle h, * @param[in] buf HTTP/1 buffer * @param[in] n Length of buffer * @retval 0 Parse OK - * @retval -1 Error with clicon_err called. + * @retval -1 Error * @note Had preferred to do this without copying, OR * input flex with a non-null terminated string */ int -clixon_http1_parse_buf(clicon_handle h, +clixon_http1_parse_buf(clixon_handle h, restconf_conn *rc, char *buf, size_t n) @@ -227,7 +227,7 @@ clixon_http1_parse_buf(clicon_handle h, int ret; if ((str = malloc(n+1)) == NULL){ - clicon_err(OE_RESTCONF, errno, "malloc"); + clixon_err(OE_RESTCONF, errno, "malloc"); return -1; } memcpy(str, buf, n); @@ -250,7 +250,7 @@ clixon_http1_parse_buf(clicon_handle h, * runtime config option */ static int -http1_upgrade_http2(clicon_handle h, +http1_upgrade_http2(clixon_handle h, restconf_stream_data *sd) { int retval = -1; @@ -280,7 +280,7 @@ http1_upgrade_http2(clicon_handle h, sd->sd_upgrade2 = 1; if ((settings = restconf_param_get(h, "HTTP_HTTP2_Settings")) != NULL && (sd->sd_settings2 = (uint8_t*)strdup(settings)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -332,7 +332,7 @@ restconf_http1_reply(restconf_conn *rc, /* Write a body */ if (sd->sd_body){ if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){ - clicon_err(OE_RESTCONF, errno, "cbuf_append_buf"); + clixon_err(OE_RESTCONF, errno, "cbuf_append_buf"); goto done; } cbuf_free(sd->sd_body); @@ -351,7 +351,7 @@ restconf_http1_reply(restconf_conn *rc, * @retval -1 Error */ int -restconf_http1_path_root(clicon_handle h, +restconf_http1_path_root(clixon_handle h, restconf_conn *rc) { int retval = -1; @@ -368,7 +368,7 @@ restconf_http1_path_root(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "------------"); pretty = restconf_pretty_get(h); if ((sd = restconf_stream_find(rc, 0)) == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "No stream_data"); + clixon_err(OE_RESTCONF, EINVAL, "No stream_data"); goto done; } /* Sanity check */ @@ -484,7 +484,7 @@ restconf_http1_path_root(clicon_handle h, * @see rfc7231 Sec 5.1.1 */ int -http1_check_expect(clicon_handle h, +http1_check_expect(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd) { @@ -518,7 +518,7 @@ http1_check_expect(clicon_handle h, * @retval -1 Error */ int -http1_check_content_length(clicon_handle h, +http1_check_content_length(clixon_handle h, restconf_stream_data *sd, int *status) { diff --git a/apps/restconf/restconf_http1.h b/apps/restconf/restconf_http1.h index 8606ad99..2ff90edf 100644 --- a/apps/restconf/restconf_http1.h +++ b/apps/restconf/restconf_http1.h @@ -39,11 +39,11 @@ /* * Prototypes */ -int clixon_http1_parse_file(clicon_handle h, restconf_conn *rc, FILE *f, const char *filename); -int clixon_http1_parse_string(clicon_handle h, restconf_conn *rc, char *str); -int clixon_http1_parse_buf(clicon_handle h, restconf_conn *rc, char *buf, size_t n); -int restconf_http1_path_root(clicon_handle h, restconf_conn *rc); -int http1_check_expect(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd); -int http1_check_content_length(clicon_handle h, restconf_stream_data *sd, int *status); +int clixon_http1_parse_file(clixon_handle h, restconf_conn *rc, FILE *f, const char *filename); +int clixon_http1_parse_string(clixon_handle h, restconf_conn *rc, char *str); +int clixon_http1_parse_buf(clixon_handle h, restconf_conn *rc, char *buf, size_t n); +int restconf_http1_path_root(clixon_handle h, restconf_conn *rc); +int http1_check_expect(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd); +int http1_check_content_length(clixon_handle h, restconf_stream_data *sd, int *status); #endif /* _RESTCONF_HTTP1_H_ */ diff --git a/apps/restconf/restconf_lib.c b/apps/restconf/restconf_lib.c index def540b1..ba74be22 100644 --- a/apps/restconf/restconf_lib.c +++ b/apps/restconf/restconf_lib.c @@ -61,7 +61,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_api.h" @@ -265,7 +265,7 @@ restconf_proto2str(int proto) * */ restconf_media -restconf_content_type(clicon_handle h) +restconf_content_type(clixon_handle h) { char *str = NULL; restconf_media m; @@ -282,7 +282,7 @@ restconf_content_type(clicon_handle h) * Example: Host -> HTTP_HOST */ int -restconf_convert_hdr(clicon_handle h, +restconf_convert_hdr(clixon_handle h, char *name, char *val) { @@ -293,7 +293,7 @@ restconf_convert_hdr(clicon_handle h, size_t len; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* convert key name */ @@ -353,7 +353,7 @@ get_user_cookie(char *cookiestr, * @param[in] h Clixon handle */ int -restconf_terminate(clicon_handle h) +restconf_terminate(clixon_handle h) { yang_stmt *yspec; cvec *nsctx; @@ -379,7 +379,7 @@ restconf_terminate(clicon_handle h) restconf_handle_exit(h); clixon_err_exit(); clixon_debug(CLIXON_DBG_DEFAULT, "%s pid:%u done", __FUNCTION__, getpid()); - clicon_log_exit(); /* Must be after last clixon_debug */ + clixon_log_exit(); /* Must be after last clixon_debug */ return 0; } @@ -432,7 +432,7 @@ restconf_insert_attributes(cxobj *xdata, } if ((pstr = cvec_find_str(qvec, "point")) != NULL){ if (y == NULL){ - clicon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata)); + clixon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata)); goto done; } if (yang_keyword_get(y) == Y_LIST) @@ -443,7 +443,7 @@ restconf_insert_attributes(cxobj *xdata, if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0) goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (yang_keyword_get(y) == Y_LIST){ @@ -456,12 +456,12 @@ restconf_insert_attributes(cxobj *xdata, else{ /* LEAF_LIST */ /* translate /../x[.='x'] --> x */ if ((p = rindex(xpath,'\'')) == NULL){ - clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath); + clixon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath); goto done; } *p = '\0'; if ((p = rindex(xpath,'\'')) == NULL){ - clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath); + clixon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath); goto done; } p++; @@ -508,7 +508,7 @@ restconf_insert_attributes(cxobj *xdata, * @see ietf-restconf.yang */ int -restconf_main_extension_cb(clicon_handle h, +restconf_main_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -547,18 +547,18 @@ restconf_main_extension_cb(clicon_handle h, * @retval path malloced, need free */ char * -restconf_uripath(clicon_handle h) +restconf_uripath(clixon_handle h) { char *path = NULL; char *path2 = NULL; char *q; if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){ - clicon_err(OE_RESTCONF, 0, "No REQUEST_URI"); + clixon_err(OE_RESTCONF, 0, "No REQUEST_URI"); return NULL; } if ((path2 = strdup(path)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); return NULL; } if ((q = index(path2, '?')) != NULL) @@ -574,7 +574,7 @@ restconf_uripath(clicon_handle h) * Group set to CLICON_SOCK_GROUP to communicate with backend */ int -restconf_drop_privileges(clicon_handle h) +restconf_drop_privileges(clixon_handle h) { int retval = -1; uid_t newuid = -1; @@ -587,11 +587,11 @@ restconf_drop_privileges(clicon_handle h) clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); /* Sanity check: backend group exists */ if ((group = clicon_sock_group(h)) == NULL){ - clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); + clixon_err(OE_FATAL, 0, "clicon_sock_group option not set"); return -1; } if (group_name2gid(group, &gid) < 0){ - clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */ + clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */ "The config daemon requires a valid group to create a server UNIX socket\n" "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n" "or create the group and add the user to it. Check documentation for how to do this on your platform", @@ -608,18 +608,18 @@ restconf_drop_privileges(clicon_handle h) /* Get (wanted) new www user id */ if (name2uid(user, &newuid) < 0){ - clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user); + clixon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user); goto done; } /* get current userid, if already at this level OK */ if ((uid = getuid()) == newuid) goto ok; if (uid != 0){ - clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid); + clixon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid); goto done; } if (setgid(gid) == -1) { - clicon_err(OE_DAEMON, errno, "setgid %d", gid); + clixon_err(OE_DAEMON, errno, "setgid %d", gid); goto done; } switch (priv_mode){ @@ -628,7 +628,7 @@ restconf_drop_privileges(clicon_handle h) goto done; /* Verify you cannot regain root privileges */ if (setuid(0) != -1){ - clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges"); + clixon_err(OE_DAEMON, EPERM, "Could regain root privilieges"); goto done; } break; @@ -658,7 +658,7 @@ restconf_drop_privileges(clicon_handle h) * @retval -1 Error */ int -restconf_authentication_cb(clicon_handle h, +restconf_authentication_cb(clixon_handle h, void *req, int pretty, restconf_media media_out) @@ -746,7 +746,7 @@ restconf_authentication_cb(clicon_handle h, * @retval -1 Error */ int -restconf_config_init(clicon_handle h, +restconf_config_init(clixon_handle h, cxobj *xrestconf) { int retval = -1; @@ -759,7 +759,7 @@ restconf_config_init(clicon_handle h, yang_stmt *y; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } /* Apply default values (removed in clear function) */ @@ -776,7 +776,7 @@ restconf_config_init(clicon_handle h, if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL && (bstr = xml_body(x)) != NULL){ if ((auth_type = clixon_auth_type_str2int(bstr)) < 0){ - clicon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr); + clixon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr); goto done; } restconf_auth_type_set(h, auth_type); diff --git a/apps/restconf/restconf_lib.h b/apps/restconf/restconf_lib.h index fccbee96..3644da0c 100644 --- a/apps/restconf/restconf_lib.h +++ b/apps/restconf/restconf_lib.h @@ -87,16 +87,16 @@ const restconf_media restconf_media_str2int(char *media); const char *restconf_media_int2str(restconf_media media); int restconf_str2proto(char *str); const char *restconf_proto2str(int proto); -restconf_media restconf_content_type(clicon_handle h); -int restconf_convert_hdr(clicon_handle h, char *name, char *val); +restconf_media restconf_content_type(clixon_handle h); +int restconf_convert_hdr(clixon_handle h, char *name, char *val); int get_user_cookie(char *cookiestr, char *attribute, char **val); -int restconf_terminate(clicon_handle h); +int restconf_terminate(clixon_handle h); int restconf_insert_attributes(cxobj *xdata, cvec *qvec); -int restconf_main_extension_cb(clicon_handle h, yang_stmt *yext, yang_stmt *ys); -char *restconf_uripath(clicon_handle h); -int restconf_drop_privileges(clicon_handle h); -int restconf_authentication_cb(clicon_handle h, void *req, int pretty, restconf_media media_out); -int restconf_config_init(clicon_handle h, cxobj *xrestconf); +int restconf_main_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys); +char *restconf_uripath(clixon_handle h); +int restconf_drop_privileges(clixon_handle h); +int restconf_authentication_cb(clixon_handle h, void *req, int pretty, restconf_media media_out); +int restconf_config_init(clixon_handle h, cxobj *xrestconf); int restconf_socket_init(const char *netns0, const char *addrstr, const char *addrtype, uint16_t port, int backlog, int flags, int *ss); #endif /* _RESTCONF_LIB_H_ */ diff --git a/apps/restconf/restconf_main_fcgi.c b/apps/restconf/restconf_main_fcgi.c index b983de10..3c7bd78c 100644 --- a/apps/restconf/restconf_main_fcgi.c +++ b/apps/restconf/restconf_main_fcgi.c @@ -71,7 +71,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include /* Need to be after clixon_xml.h due to attribute format */ @@ -99,7 +99,7 @@ * @see https://nginx.org/en/docs/http/ngx_http_core_module.html#var_https */ static int -fcgi_params_set(clicon_handle h, +fcgi_params_set(clixon_handle h, char **envp) { int retval = -1; @@ -131,7 +131,7 @@ fcgi_params_set(clicon_handle h, /*! Try to get config: inline, config-file or query backend */ static int -restconf_main_config(clicon_handle h, +restconf_main_config(clixon_handle h, yang_stmt *yspec, const char *inline_config) { @@ -151,7 +151,12 @@ restconf_main_config(clicon_handle h, if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0) goto done; if (ret == 0){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Inline restconf config") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Inline restconf config", NULL); +#endif goto done; } /* Replace parent w first child */ @@ -172,7 +177,7 @@ restconf_main_config(clicon_handle h, sleep(1); continue; } - clicon_err(OE_UNIX, errno, "clicon_session_id_get"); + clixon_err(OE_UNIX, errno, "clicon_session_id_get"); goto done; } clicon_session_id_set(h, id); @@ -181,13 +186,13 @@ restconf_main_config(clicon_handle h, if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL) goto done; if ((pw = getpwuid(getuid())) == NULL){ - clicon_err(OE_UNIX, errno, "getpwuid"); + clixon_err(OE_UNIX, errno, "getpwuid"); goto done; } if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0) goto done; if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){ - clixon_netconf_error(h, xerr, "Get backend restconf config", NULL); + clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config"); goto done; } /* Extract restconf configuration */ @@ -198,7 +203,7 @@ restconf_main_config(clicon_handle h, (configure_done = restconf_config_init(h, xrestconf)) < 0) goto done; if (!configure_done){ /* Query backend of config. */ - clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled"); + clixon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled"); goto done; } retval = 0; @@ -214,7 +219,7 @@ restconf_main_config(clicon_handle h, /* XXX Need global variable to for SIGCHLD signal handler */ -static clicon_handle _CLICON_HANDLE = NULL; +static clixon_handle _CLIXON_HANDLE = NULL; /* XXX Need global variable to break FCGI accept loop from signal handler see FCGX_Accept_r(req) */ @@ -229,7 +234,7 @@ restconf_sig_term(int arg) clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (i++ == 0) - clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", + clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d", __PROGRAM__, __FUNCTION__, getpid(), arg); else{ clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__); @@ -255,7 +260,7 @@ restconf_sig_child(int arg) int pid; if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status)) - stream_child_free(_CLICON_HANDLE, pid); + stream_child_free(_CLIXON_HANDLE, pid); } /*! Usage help routine @@ -264,7 +269,7 @@ restconf_sig_child(int arg) * @param[in] argv0 command line */ static void -usage(clicon_handle h, +usage(clixon_handle h, char *argv0) { fprintf(stderr, "usage:%s [options]\n" @@ -303,9 +308,9 @@ main(int argc, int c; char *sockpath = NULL; char *path; - clicon_handle h; + clixon_handle h; char *dir; - int logdst = CLICON_LOG_SYSLOG; + int logdst = CLIXON_LOG_SYSLOG; yang_stmt *yspec = NULL; char *query; cvec *qvec; @@ -324,14 +329,16 @@ main(int argc, enum format_enum config_dump_format = FORMAT_XML; int print_version = 0; - /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__PROGRAM__, LOG_INFO, logdst); - /* Create handle */ if ((h = restconf_handle_init()) == NULL) goto done; + /* In the startup, logs to stderr & debug flag set later */ + if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0) + goto done; + if (clixon_err_init(h) < 0) + goto done; - _CLICON_HANDLE = h; /* for termination handling */ + _CLIXON_HANDLE = h; /* for termination handling */ while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1) switch (c) { @@ -357,11 +364,11 @@ main(int argc, clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); break; case 'l': /* Log destination: s|e|o */ - if ((logdst = clicon_log_opt(optarg[0])) < 0) + if ((logdst = clixon_log_opt(optarg[0])) < 0) usage(h, argv[0]); - if (logdst == CLICON_LOG_FILE && + if (logdst == CLIXON_LOG_FILE && strlen(optarg)>1 && - clicon_log_file(optarg+1) < 0) + clixon_log_file(optarg+1) < 0) goto done; break; } /* switch getopt */ @@ -369,20 +376,20 @@ main(int argc, /* * Logs, error and debug to stderr or syslog, set debug level */ - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clixon_debug_init(dbg, NULL); - clicon_log(LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid()); + clixon_debug_init(h, dbg); + clixon_log(h, LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid()); if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGCHLD, restconf_sig_child, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } @@ -460,8 +467,8 @@ main(int argc, cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD"); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); - if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) - clicon_log_string_limit_set(sz); + if ((sz = clicon_option_int(h, "CLIXON_LOG_STRING_LIMIT")) != 0) + clixon_log_string_limit_set(sz); /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ xml_nsctx_namespace_netconf_default(h); @@ -572,16 +579,16 @@ main(int argc, if (restconf_main_config(h, yspec, inline_config) < 0) goto done; if ((sockpath = restconf_fcgi_socket_get(h)) == NULL){ - clicon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)"); + clixon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)"); goto done; } if (FCGX_Init() != 0){ /* How to cleanup memory after this? */ - clicon_err(OE_CFG, errno, "FCGX_Init"); + clixon_err(OE_CFG, errno, "FCGX_Init"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "restconf_main: Opening FCGX socket: %s", sockpath); if ((sock = FCGX_OpenSocket(sockpath, 10)) < 0){ - clicon_err(OE_CFG, errno, "FCGX_OpenSocket"); + clixon_err(OE_CFG, errno, "FCGX_OpenSocket"); goto done; } _MYSOCK = sock; @@ -590,18 +597,18 @@ main(int argc, gid_t wgid = -1; wwwuser = clicon_option_str(h, "CLICON_RESTCONF_USER"); if (group_name2gid(wwwuser, &wgid) < 0){ - clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser); + clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser); goto done; } if (chown(sockpath, -1, wgid) < 0){ - clicon_err(OE_CFG, errno, "chown"); + clixon_err(OE_CFG, errno, "chown"); goto done; } if (clicon_socket_set(h, sock) < 0) goto done; /* umask settings may interfer: we want group to write: this is 774 */ if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){ - clicon_err(OE_UNIX, errno, "chmod"); + clixon_err(OE_UNIX, errno, "chmod"); goto done; } @@ -616,14 +623,14 @@ main(int argc, clicon_data_set(h, "session-transport", "cl:restconf"); if (FCGX_InitRequest(req, sock, 0) != 0){ - clicon_err(OE_CFG, errno, "FCGX_InitRequest"); + clixon_err(OE_CFG, errno, "FCGX_InitRequest"); goto done; } while (1) { finish = 1; /* If zero, dont finish request, initiate new */ if (FCGX_Accept_r(req) < 0) { - clicon_err(OE_CFG, errno, "FCGX_Accept_r"); + clixon_err(OE_CFG, errno, "FCGX_Accept_r"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "------------"); @@ -692,7 +699,7 @@ main(int argc, else{ /* A handler is forked so we initiate a new request after instead of finishing the old */ if (FCGX_InitRequest(req, sock, 0) != 0){ - clicon_err(OE_CFG, errno, "FCGX_InitRequest"); + clixon_err(OE_CFG, errno, "FCGX_InitRequest"); goto done; } } diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index ad1d3850..7b386b12 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -36,7 +36,7 @@ * Data structures: * 1 1 * +--------------------+ restconf_handle_get +--------------------+ - * | rn restconf_native | <--------------------- | h clicon_handle | + * | rn restconf_native | <--------------------- | h clixon_handle | * | _handle | +--------------------+ * +--------------------+ ^ * common SSL config \ | @@ -186,7 +186,7 @@ static int session_id_context = 1; * @retval -1 Error */ static int -restconf_native_handle_set(clicon_handle h, +restconf_native_handle_set(clixon_handle h, restconf_native_handle *rh) { clicon_hash_t *cdat = clicon_data(h); @@ -235,7 +235,7 @@ init_openssl(void) /* This isn't strictly necessary... OpenSSL performs RAND_poll * automatically on first use of random number generator. */ if (RAND_poll() != 1) { - clicon_err(OE_SSL, errno, "Random generator has not been seeded with enough data"); + clixon_err(OE_SSL, errno, "Random generator has not been seeded with enough data"); goto done; } retval = 0; @@ -260,7 +260,7 @@ restconf_verify_certs(int preverify_ok, int err; int depth; // SSL *ssl; - // clicon_handle h; + // clixon_handle h; err_cert = X509_STORE_CTX_get_current_cert(store); err = X509_STORE_CTX_get_error(store); depth = X509_STORE_CTX_get_error_depth(store); @@ -361,7 +361,7 @@ alpn_select_proto_cb(SSL *ssl, /* */ static SSL_CTX * -restconf_ssl_context_create(clicon_handle h) +restconf_ssl_context_create(clixon_handle h) { const SSL_METHOD *method; SSL_CTX *ctx = NULL; @@ -369,7 +369,7 @@ restconf_ssl_context_create(clicon_handle h) method = TLS_server_method(); if ((ctx = SSL_CTX_new(method)) == NULL) { - clicon_err(OE_SSL, 0, "SSL_CTX_new"); + clixon_err(OE_SSL, 0, "SSL_CTX_new"); goto done; } /* Options @@ -414,7 +414,7 @@ restconf_ssl_context_configure(clixon_handle h, */ if (server_ca_cert_path){ if (SSL_CTX_load_verify_locations(ctx, server_ca_cert_path, NULL) != 1){ - clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path); + clixon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path); goto done; } SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER /*| SSL_VERIFY_FAIL_IF_NO_PEER_CERT */, @@ -496,15 +496,15 @@ restconf_checkcert_file(cxobj *xrestconf, char *filename; if ((x = xpath_first(xrestconf, nsc, "%s", name)) == NULL){ - clicon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name); + clixon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name); goto done; } if ((filename = xml_body(x)) == NULL){ - clicon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name); + clixon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name); goto done; } if (stat(filename, &fstat) < 0) { - clicon_err(OE_FATAL, errno, "cert '%s'", filename); + clixon_err(OE_FATAL, errno, "cert '%s'", filename); goto done; } *var = filename; @@ -516,7 +516,7 @@ restconf_checkcert_file(cxobj *xrestconf, /*! Accept new socket client * * @param[in] fd Socket (unix or ip) - * @param[in] arg typecast clicon_handle + * @param[in] arg typecast clixon_handle * @retval 0 OK * @retval -1 Error * @see openssl_init_socket where this callback is registered @@ -527,7 +527,7 @@ restconf_accept_client(int fd, { int retval = -1; restconf_socket *rsock; - clicon_handle h; + clixon_handle h; int s; struct sockaddr from = {0,}; socklen_t len; @@ -536,13 +536,13 @@ restconf_accept_client(int fd, clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, fd); if ((rsock = (restconf_socket *)arg) == NULL){ - clicon_err(OE_YANG, EINVAL, "rsock is NULL"); + clixon_err(OE_YANG, EINVAL, "rsock is NULL"); goto done; } h = rsock->rs_h; len = sizeof(from); if ((s = accept(rsock->rs_ss, &from, &len)) < 0){ - clicon_err(OE_UNIX, errno, "accept"); + clixon_err(OE_UNIX, errno, "accept"); goto done; } switch (from.sa_family){ @@ -565,7 +565,7 @@ restconf_accept_client(int fd, rsock->rs_from_addr = NULL; } if ((rsock->rs_from_addr = calloc(INET6_ADDRSTRLEN, 1)) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) < 0) @@ -590,7 +590,7 @@ restconf_accept_client(int fd, /*! */ static int -restconf_native_terminate(clicon_handle h) +restconf_native_terminate(clixon_handle h) { restconf_native_handle *rn; restconf_socket *rsock; @@ -643,7 +643,7 @@ restconf_native_terminate(clicon_handle h) * @retval -1 Error */ static int -restconf_clixon_backend(clicon_handle h, +restconf_clixon_backend(clixon_handle h, cxobj **xrestconfp) { int retval = -1; @@ -659,11 +659,11 @@ restconf_clixon_backend(clicon_handle h, while (1){ if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){ if (errno == ENOENT){ - clicon_err(OE_UNIX, errno, "waiting"); + clixon_err(OE_UNIX, errno, "waiting"); sleep(1); continue; } - clicon_err(OE_UNIX, errno, "clicon_session_id_get"); + clixon_err(OE_UNIX, errno, "clicon_session_id_get"); goto done; } clicon_session_id_set(h, id); @@ -672,14 +672,19 @@ restconf_clixon_backend(clicon_handle h, if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL) goto done; if ((pw = getpwuid(getuid())) == NULL){ - clicon_err(OE_UNIX, errno, "getpwuid"); + clixon_err(OE_UNIX, errno, "getpwuid"); goto done; } /* XXX xconfig leaked */ if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0) goto done; if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "Get backend restconf config", NULL); +#endif goto done; } /* Extract restconf configuration */ @@ -713,7 +718,7 @@ restconf_clixon_backend(clicon_handle h, * @retval -1 Error */ static int -openssl_init_socket(clicon_handle h, +openssl_init_socket(clixon_handle h, cxobj *xs, cvec *nsc) { @@ -733,7 +738,7 @@ openssl_init_socket(clicon_handle h, * See restconf_native_terminate for freeing */ if ((rsock = malloc(sizeof *rsock)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(rsock, 0, sizeof *rsock); @@ -745,7 +750,7 @@ openssl_init_socket(clicon_handle h, goto done; if (rsock->rs_callhome){ if (!rsock->rs_ssl){ - clicon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL"); + clixon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL"); goto done; } } @@ -763,15 +768,15 @@ openssl_init_socket(clicon_handle h, goto done; } if ((rn = restconf_native_handle_get(h)) == NULL){ - clicon_err(OE_XML, EFAULT, "No openssl handle"); + clixon_err(OE_XML, EFAULT, "No openssl handle"); goto done; } if ((rsock->rs_addrstr = strdup(address)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if ((rsock->rs_addrtype = strdup(addrtype)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } rsock->rs_port = port; @@ -804,7 +809,7 @@ openssl_init_socket(clicon_handle h, * @retval -1 Error */ int -restconf_openssl_init(clicon_handle h, +restconf_openssl_init(clixon_handle h, int dbg0, cxobj *xrestconf) { @@ -834,7 +839,7 @@ restconf_openssl_init(clicon_handle h, (x = xpath_first(xrestconf, nsc, "debug")) != NULL && (bstr = xml_body(x)) != NULL){ dbg = atoi(bstr); - clixon_debug_init(dbg, NULL); + clixon_debug_init(h, dbg); /* If debug was enabled here from config and not initially, * print clixn options and loaded yang files */ @@ -852,7 +857,7 @@ restconf_openssl_init(clicon_handle h, } int status = setrlimit(RLIMIT_CORE, &rlp); if (status != 0) { - clicon_log(LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno)); + clixon_log(h, LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno)); } } @@ -880,8 +885,8 @@ restconf_openssl_init(clicon_handle h, for (i=0; i 0) /* Allow one sigterm before proper exit */ exit(-1); @@ -1103,7 +1108,7 @@ restconf_sig_term(int arg) * @param[in] h Clixon handle */ static void -usage(clicon_handle h, +usage(clixon_handle h, char *argv0) { fprintf(stderr, "usage:%s [options]\n" @@ -1138,9 +1143,9 @@ main(int argc, int retval = -1; char *argv0 = argv[0]; int c; - clicon_handle h; + clixon_handle h; int dbg = 0; - int logdst = CLICON_LOG_SYSLOG; + int logdst = CLIXON_LOG_SYSLOG; restconf_native_handle *rn = NULL; int ret; cxobj *xrestconf = NULL; @@ -1149,12 +1154,14 @@ main(int argc, enum format_enum config_dump_format = FORMAT_XML; int print_version = 0; - /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__PROGRAM__, LOG_INFO, logdst); - /* Create handle */ if ((h = restconf_handle_init()) == NULL) goto done; + /* In the startup, logs to stderr & debug flag set later */ + if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0) + goto done; + if (clixon_err_init(h) < 0) + goto done; while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1) switch (c) { @@ -1180,11 +1187,11 @@ main(int argc, clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg); break; case 'l': /* Log destination: s|e|o */ - if ((logdst = clicon_log_opt(optarg[0])) < 0) + if ((logdst = clixon_log_opt(optarg[0])) < 0) usage(h, argv0); - if (logdst == CLICON_LOG_FILE && + if (logdst == CLIXON_LOG_FILE && strlen(optarg)>1 && - clicon_log_file(optarg+1) < 0) + clixon_log_file(optarg+1) < 0) goto done; break; } /* switch getopt */ @@ -1192,7 +1199,7 @@ main(int argc, /* * Logs, error and debug to stderr or syslog, set debug level */ - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); /* * Register error category and error/log callbacks for openssl special error handling @@ -1212,18 +1219,18 @@ main(int argc, ) < 0) goto done; #endif - clixon_debug_init(dbg, NULL); - clicon_log(LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid()); + clixon_debug_init(h, dbg); + clixon_log(h, LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid()); if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } yang_init(h); @@ -1317,13 +1324,13 @@ main(int argc, if ((ret = restconf_clixon_init(h, inline_config, print_version, &xrestconf)) < 0) goto done; if (ret == 0){ /* restconf disabled */ - clicon_log(LOG_INFO, "restconf configuration not found or disabled"); + clixon_log(h, LOG_INFO, "restconf configuration not found or disabled"); retval = 0; goto done; } /* Create and stroe global openssl handle */ if ((rn = malloc(sizeof *rn)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(rn, 0, sizeof *rn); diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index 49e3e35b..913e8229 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -66,7 +66,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" @@ -93,7 +93,7 @@ * @see RFC5789 PATCH Method for HTTP Section 3.2 */ int -api_data_options(clicon_handle h, +api_data_options(clixon_handle h, void *req) { int retval = -1; @@ -194,7 +194,7 @@ match_list_keys(yang_stmt *y, * @retval -1 Error */ int -api_data_write(clicon_handle h, +api_data_write(clixon_handle h, void *req, char *api_path0, int pi, @@ -239,7 +239,7 @@ api_data_write(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0); clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } api_path=api_path0; @@ -328,7 +328,7 @@ api_data_write(clicon_handle h, switch (media_in){ case YANG_DATA_XML: if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){ - if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) + if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -342,7 +342,7 @@ api_data_write(clicon_handle h, break; case YANG_DATA_JSON: if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xdata0, &xerr)) < 0){ - if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) + if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -620,7 +620,7 @@ api_data_write(clicon_handle h, * --> Best solution and applied here */ int -api_data_put(clicon_handle h, +api_data_put(clixon_handle h, void *req, char *api_path0, int pi, @@ -658,7 +658,7 @@ api_data_put(clicon_handle h, * create it. (CANT BE DONE WITH NETCONF) */ int -api_data_patch(clicon_handle h, +api_data_patch(clixon_handle h, void *req, char *api_path0, int pi, @@ -712,7 +712,7 @@ api_data_patch(clicon_handle h, * Netconf: (nc:operation="delete") */ int -api_data_delete(clicon_handle h, +api_data_delete(clixon_handle h, void *req, char *api_path, int pi, @@ -739,7 +739,7 @@ api_data_delete(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:%s", __FUNCTION__, api_path); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } for (i=0; i -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" @@ -64,7 +64,7 @@ #include "restconf_methods_get.h" /* Forward */ -static int api_data_pagination(clicon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out); +static int api_data_pagination(clixon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out); /*! Generic GET (both HEAD and GET) * According to restconf @@ -97,7 +97,7 @@ static int api_data_pagination(clicon_handle h, void *req, char *api_path, int p * @note there is an ad-hoc method to determine json pagination request instead of regular GET */ static int -api_data_get2(clicon_handle h, +api_data_get2(clixon_handle h, void *req, char *api_path, int pi, @@ -130,7 +130,7 @@ api_data_get2(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } /* strip /... from start */ @@ -184,7 +184,7 @@ api_data_get2(clicon_handle h, if (strcmp(attr, "unbounded") != 0){ char *reason = NULL; if ((ret = parse_int32(attr, &depth, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_int32"); + clixon_err(OE_XML, errno, "parse_int32"); goto done; } if (ret==0){ @@ -206,7 +206,7 @@ api_data_get2(clicon_handle h, ret = clicon_rpc_get(h, xpath, nsc, content, depth, defaults, &xret); if (ret < 0){ - if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0) + if (netconf_operation_failed_xml(&xerr, "protocol", clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -227,7 +227,7 @@ api_data_get2(clicon_handle h, } /* Normal return, no error */ if ((cbx = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */ @@ -246,7 +246,7 @@ api_data_get2(clicon_handle h, } else{ if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0){ - if (netconf_operation_failed_xml(&xerr, "application", clicon_err_reason) < 0) + if (netconf_operation_failed_xml(&xerr, "application", clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -345,7 +345,7 @@ api_data_get2(clicon_handle h, * @see draft-ietf-netconf-restconf-collection-00.txt */ static int -api_data_pagination(clicon_handle h, +api_data_pagination(clixon_handle h, void *req, char *api_path, int pi, @@ -383,7 +383,7 @@ api_data_pagination(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } /* strip /... from start */ @@ -406,7 +406,7 @@ api_data_pagination(clicon_handle h, goto done; if (ret == 0){ /* validation failed */ if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); + clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); goto done; } if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) @@ -419,7 +419,7 @@ api_data_pagination(clicon_handle h, "Element is not list or leaf-list which is required for GET paginate") < 0) goto done; if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); + clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); goto done; } if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) @@ -436,7 +436,7 @@ api_data_pagination(clicon_handle h, "content", "Unrecognized value of content attribute") < 0) goto done; if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); + clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); goto done; } if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) @@ -446,7 +446,7 @@ api_data_pagination(clicon_handle h, } clixon_debug(CLIXON_DBG_DEFAULT, "%s path:%s", __FUNCTION__, xpath); if (content != CONTENT_CONFIG && content != CONTENT_NONCONFIG && content != CONTENT_ALL){ - clicon_err(OE_XML, EINVAL, "Invalid content attribute %d", content); + clixon_err(OE_XML, EINVAL, "Invalid content attribute %d", content); goto done; } /* Clixon extensions and collection attributes */ @@ -456,7 +456,7 @@ api_data_pagination(clicon_handle h, if (strcmp(attr, "unbounded") != 0){ char *reason = NULL; if ((ret = parse_int32(attr, &depth, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_int32"); + clixon_err(OE_XML, errno, "parse_int32"); goto done; } if (ret==0){ @@ -493,10 +493,10 @@ api_data_pagination(clicon_handle h, if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc, content, depth, NULL, offset, limit, direction, sort, where, &xret) < 0){ - if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0) + if (netconf_operation_failed_xml(&xerr, "protocol", clixon_err_reason()) < 0) goto done; if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); + clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)"); goto done; } if (api_return_err(h, req, xe, pretty, media_out, 0) < 0) @@ -607,7 +607,7 @@ api_data_pagination(clicon_handle h, * @retval -1 Error */ int -api_data_head(clicon_handle h, +api_data_head(clixon_handle h, void *req, char *api_path, int pi, @@ -648,7 +648,7 @@ api_data_head(clicon_handle h, * Netconf: , */ int -api_data_get(clicon_handle h, +api_data_get(clixon_handle h, void *req, char *api_path, int pi, @@ -703,7 +703,7 @@ api_data_get(clicon_handle h, * { 'ietf-system:system-restart' : [null] } */ int -api_operations_get(clicon_handle h, +api_operations_get(clixon_handle h, void *req, char *path, int pi, diff --git a/apps/restconf/restconf_methods_get.h b/apps/restconf/restconf_methods_get.h index ca746986..85747c9e 100644 --- a/apps/restconf/restconf_methods_get.h +++ b/apps/restconf/restconf_methods_get.h @@ -41,11 +41,11 @@ /* * Prototypes */ -int api_data_head(clicon_handle h, void *req, char *api_path, int pi, +int api_data_head(clixon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds); -int api_data_get(clicon_handle h, void *req, char *api_path, int pi, +int api_data_get(clixon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds); -int api_operations_get(clicon_handle h, void *req, +int api_operations_get(clixon_handle h, void *req, char *api_path, int pi, cvec *qvec, char *data, int pretty, restconf_media media_out); diff --git a/apps/restconf/restconf_methods_patch.c b/apps/restconf/restconf_methods_patch.c index a1102f68..abbe0fcf 100644 --- a/apps/restconf/restconf_methods_patch.c +++ b/apps/restconf/restconf_methods_patch.c @@ -56,7 +56,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" @@ -205,7 +205,7 @@ yang_patch_strip_after_last_slash(char* val) * @retval -1 Error */ static int -yang_patch_do_replace(clicon_handle h, +yang_patch_do_replace(clixon_handle h, void *req, int pi, cvec *qvec, @@ -226,23 +226,23 @@ yang_patch_do_replace(clicon_handle h, cbuf *json_simple_patch = NULL; if ((delete_req_uri = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((json_simple_patch = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } // Make delete_req_uri something like "/restconf/data/ietf-interfaces:interfaces" if (cbuf_append_str(delete_req_uri, cbuf_get(simple_patch_request_uri)) < 0){ - clicon_err(OE_UNIX, errno, "cbuf_append_str"); + clixon_err(OE_UNIX, errno, "cbuf_append_str"); goto done; } // Add the target to delete_req_uri, // so it's something like "/restconf/data/ietf-interfaces:interfaces/interface=eth2" if (cbuf_append_str(delete_req_uri, target_val) < 0){ - clicon_err(OE_UNIX, errno, "cbuf_append_str"); + clixon_err(OE_UNIX, errno, "cbuf_append_str"); goto done; } @@ -259,7 +259,7 @@ yang_patch_do_replace(clicon_handle h, // Make post_req_uri something like "/restconf/data/ietf-interfaces:interfaces" if (cbuf_append_str(simple_patch_request_uri, cbuf_get(post_req_uri)) < 0){ - clicon_err(OE_UNIX, errno, "cbuf_append_str"); + clixon_err(OE_UNIX, errno, "cbuf_append_str"); goto done; } // Now insert the new values into the data @@ -307,7 +307,7 @@ yang_patch_do_replace(clicon_handle h, * @retval -1 Error */ static int -yang_patch_do_create(clicon_handle h, +yang_patch_do_create(clixon_handle h, void *req, int pi, cvec *qvec, @@ -326,7 +326,7 @@ yang_patch_do_create(clicon_handle h, // Send the POST request if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } for (int k = 0; k < value_vec_len; k++) { @@ -368,7 +368,7 @@ yang_patch_do_create(clicon_handle h, * @retval -1 Error */ static int -yang_patch_do_insert(clicon_handle h, +yang_patch_do_insert(clixon_handle h, void *req, int pi, int pretty, @@ -391,11 +391,11 @@ yang_patch_do_insert(clicon_handle h, cvec *qvec_tmp = NULL; if ((point_str = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((qvec_tmp = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } // Loop through the XML, and get each value @@ -410,7 +410,7 @@ yang_patch_do_insert(clicon_handle h, // Set the insert attributes if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); goto done; } cv_name_set(cv, "insert"); @@ -420,7 +420,7 @@ yang_patch_do_insert(clicon_handle h, if (point_val) cbuf_append_str(point_str, point_val); if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); goto done; } cv_name_set(cv, "point"); @@ -459,7 +459,7 @@ yang_patch_do_insert(clicon_handle h, * @retval -1 Error */ static int -yang_patch_do_merge(clicon_handle h, +yang_patch_do_merge(clixon_handle h, void *req, int pi, cvec *qvec, @@ -479,7 +479,7 @@ yang_patch_do_merge(clicon_handle h, cbuf *json_simple_patch = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (key_xn != NULL) @@ -521,7 +521,7 @@ yang_patch_do_merge(clicon_handle h, * @retval -1 Error */ static int -yang_patch_do_value(clicon_handle h, +yang_patch_do_value(clixon_handle h, void *req, int pi, cvec *qvec, @@ -551,7 +551,7 @@ yang_patch_do_value(clicon_handle h, key_node_id = xml_name(*values_child_vec); /* Create cbufs:s */ if ((patch_header = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(patch_header, "%s:%s", modname, key_node_id); @@ -601,7 +601,7 @@ yang_patch_do_value(clicon_handle h, * @retval -1 Error */ static int -yang_patch_do_edit(clicon_handle h, +yang_patch_do_edit(clixon_handle h, void *req, int pi, cvec *qvec, @@ -638,26 +638,26 @@ yang_patch_do_edit(clicon_handle h, clixon_debug_xml(1, xn, "%s %d xn:", __FUNCTION__, __LINE__); /* Create cbufs:s */ if ((simple_patch_request_uri = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((api_path_target = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((x = xpath_first(xn, NULL, "target")) == NULL){ - clicon_err(OE_YANG, 0, "target mandatory element not found"); + clixon_err(OE_YANG, 0, "target mandatory element not found"); goto done; } target_val = xml_body(x); if ((x = xpath_first(xn, NULL, "operation")) == NULL){ - clicon_err(OE_YANG, 0, "operation mandatory element not found"); + clixon_err(OE_YANG, 0, "operation mandatory element not found"); goto done; } operation = yang_patch_op2int(xml_body(x)); /* target and operation are mandatory */ if (target_val == NULL){ - clicon_err(OE_YANG, 0, "operation/target: mandatory element not found"); + clixon_err(OE_YANG, 0, "operation/target: mandatory element not found"); goto done; } if (operation == YANG_PATCH_OP_INSERT){ @@ -666,7 +666,7 @@ yang_patch_do_edit(clicon_handle h, if ((x = xpath_first(xn, NULL, "where")) != NULL) where_val = xml_body(x); if (point_val == NULL || where_val == NULL){ - clicon_err(OE_YANG, 0, "point/where: expected element not found"); + clixon_err(OE_YANG, 0, "point/where: expected element not found"); goto done; } } @@ -756,7 +756,7 @@ yang_patch_do_edit(clicon_handle h, * Currently "move" not supported */ int -api_data_yang_patch(clicon_handle h, +api_data_yang_patch(clixon_handle h, void *req, char *api_path0, int pi, @@ -780,7 +780,7 @@ api_data_yang_patch(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } api_path=api_path0; @@ -808,7 +808,7 @@ api_data_yang_patch(clicon_handle h, } /* Common error handling for json/xml parsing above */ if (ret < 0){ - if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) + if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -860,7 +860,7 @@ api_data_yang_patch(clicon_handle h, #else // CLIXON_YANG_PATCH int -api_data_yang_patch(clicon_handle h, +api_data_yang_patch(clixon_handle h, void *req, char *api_path0, int pi, @@ -871,7 +871,7 @@ api_data_yang_patch(clicon_handle h, restconf_media media_out, ietf_ds_t ds) { - clicon_err(OE_RESTCONF, 0, "Not implemented"); + clixon_err(OE_RESTCONF, 0, "Not implemented"); return -1; } #endif // CLIXON_YANG_PATCH diff --git a/apps/restconf/restconf_methods_patch.h b/apps/restconf/restconf_methods_patch.h index 2cf02a31..2e43b148 100644 --- a/apps/restconf/restconf_methods_patch.h +++ b/apps/restconf/restconf_methods_patch.h @@ -43,7 +43,7 @@ /* * Prototypes */ -int api_data_yang_patch(clicon_handle h, void *req, char *api_path0, +int api_data_yang_patch(clixon_handle h, void *req, char *api_path0, int pi, cvec *qvec, char *data, int pretty, restconf_media media_in, restconf_media media_out, diff --git a/apps/restconf/restconf_methods_post.c b/apps/restconf/restconf_methods_post.c index 6bdf1c25..b368b302 100644 --- a/apps/restconf/restconf_methods_post.c +++ b/apps/restconf/restconf_methods_post.c @@ -56,7 +56,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "restconf_lib.h" @@ -75,7 +75,7 @@ * @note ports are ignored */ static int -http_location_header(clicon_handle h, +http_location_header(clixon_handle h, void *req, cxobj *xobj) { @@ -91,7 +91,7 @@ http_location_header(clicon_handle h, goto done; if (xobj != NULL){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, 0, "cbuf_new"); + clixon_err(OE_UNIX, 0, "cbuf_new"); goto done; } if (xml2api_path_1(xobj, cb) < 0) @@ -155,7 +155,7 @@ http_location_header(clicon_handle h, * @see api_data_put */ int -api_data_post(clicon_handle h, +api_data_post(clixon_handle h, void *req, char *api_path, int pi, @@ -192,7 +192,7 @@ api_data_post(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path); clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } for (i=0; i and has no proper yang binding * support */ if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){ - if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) + if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -469,7 +469,7 @@ api_operations_post_input(clicon_handle h, /* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding * support */ if ((ret = clixon_json_parse_string(data, 1, YB_NONE, yspec, &xdata, &xerr)) < 0){ - if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0) + if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0) goto done; if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0) goto done; @@ -545,11 +545,11 @@ api_operations_post_input(clicon_handle h, * @param[out] xoutputp Restconf JSON/XML output * @retval 1 OK * @retval 0 Fail, Error message sent - * @retval -1 Fatal error, clicon_err called + * @retval -1 Fatal error * xret should like: 0 */ static int -api_operations_post_output(clicon_handle h, +api_operations_post_output(clixon_handle h, void *req, cxobj *xret, yang_stmt *yspec, @@ -691,7 +691,7 @@ api_operations_post_output(clicon_handle h, * 10. Validate and send reply to originator */ int -api_operations_post(clicon_handle h, +api_operations_post(clixon_handle h, void *req, char *api_path, int pi, @@ -725,11 +725,11 @@ api_operations_post(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s json:\"%s\" path:\"%s\"", __FUNCTION__, data, api_path); /* 1. Initialize */ if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } if ((cbret = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, 0, "cbuf_new"); + clixon_err(OE_UNIX, 0, "cbuf_new"); goto done; } for (i=0; isd_stream_id = stream_id; sd->sd_fd = -1; if ((sd->sd_inbuf = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); return NULL; } if ((sd->sd_indata = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); return NULL; } if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); return NULL; } if ((sd->sd_outp_buf = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); return NULL; } sd->sd_conn = rc; @@ -176,14 +176,14 @@ restconf_stream_free(restconf_stream_data *sd) * @see restconf_conn_free */ restconf_conn * -restconf_conn_new(clicon_handle h, +restconf_conn_new(clixon_handle h, int s, restconf_socket *rsock) { restconf_conn *rc; if ((rc = (restconf_conn*)malloc(sizeof(restconf_conn))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(rc, 0, sizeof(restconf_conn)); @@ -210,7 +210,7 @@ restconf_conn_free(restconf_conn *rc) clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (rc == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "rc is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "rc is NULL"); goto done; } #ifdef HAVE_LIBNGHTTP2 @@ -257,7 +257,7 @@ ssl_x509_name_oneline(SSL *ssl, X509_NAME *name; if (ssl == NULL || oneline == NULL) { - clicon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL"); goto done; } #if OPENSSL_VERSION_NUMBER < 0x30000000L @@ -272,7 +272,7 @@ ssl_x509_name_oneline(SSL *ssl, if ((p = X509_NAME_oneline(name, NULL, 0)) == NULL) goto ok; if ((*oneline = strdup(p)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } ok: @@ -303,7 +303,7 @@ ssl_x509_name_oneline(SSL *ssl, * @see restconf_accept_client where connection can be exited at an earlier stage */ int -restconf_connection_sanity(clicon_handle h, +restconf_connection_sanity(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd) { @@ -339,12 +339,12 @@ restconf_connection_sanity(clicon_handle h, if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0) goto done; if (oneline) - clicon_log(LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code)); + clixon_log(h, LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code)); else - clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code)); + clixon_log(h, LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code)); /* Send return error message */ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "HTTP cert verification failed: %s[%ld]", @@ -385,7 +385,7 @@ restconf_connection_sanity(clicon_handle h, * @retval -1 Error */ static int -native_buf_write(clicon_handle h, +native_buf_write(clixon_handle h, char *buf, size_t buflen, restconf_conn *rc, @@ -398,7 +398,7 @@ native_buf_write(clicon_handle h, SSL *ssl; if (rc == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "rc is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "rc is NULL"); goto done; } ssl = rc->rc_ssl; @@ -411,7 +411,7 @@ native_buf_write(clicon_handle h, size_t sz; sz = buflen>256?256:buflen; /* Truncate to 256 */ if ((dbgstr = malloc(sz+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memcpy(dbgstr, buf, sz); @@ -435,12 +435,12 @@ native_buf_write(clicon_handle h, continue; } else{ - clicon_err(OE_RESTCONF, er, "SSL_write %d", er); + clixon_err(OE_RESTCONF, er, "SSL_write %d", er); goto done; } break; default: - clicon_err(OE_SSL, 0, "SSL_write"); + clixon_err(OE_SSL, 0, "SSL_write"); goto done; break; } @@ -461,7 +461,7 @@ native_buf_write(clicon_handle h, goto closed; /* Close socket and ssl */ break; default: - clicon_err(OE_UNIX, errno, "write %d", errno); + clixon_err(OE_UNIX, errno, "write %d", errno); goto done; break; } @@ -490,7 +490,7 @@ native_buf_write(clicon_handle h, * @see restconf_badrequest which can only be called in a request context */ static int -native_send_badrequest(clicon_handle h, +native_send_badrequest(clixon_handle h, char *media, char *body, restconf_conn *rc) @@ -500,7 +500,7 @@ native_send_badrequest(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n"); @@ -530,7 +530,7 @@ native_send_badrequest(clicon_handle h, * @retval -1 Error */ static int -http1_native_clear_input(clicon_handle h, +http1_native_clear_input(clixon_handle h, restconf_stream_data *sd) { int retval = -1; @@ -586,7 +586,7 @@ read_ssl(restconf_conn *rc, *np = 0; /* should already be zero */ break; default: - clicon_log(LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr); + clixon_log(rc->rc_h, LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr); *np = 0; break; } /* switch */ @@ -635,7 +635,7 @@ read_regular(restconf_conn *rc, *again = 1; break; default:; - clicon_err(OE_XML, errno, "read"); + clixon_err(OE_XML, errno, "read"); goto done; break; } @@ -665,14 +665,14 @@ restconf_http1_process(restconf_conn *rc, { int retval = -1; restconf_stream_data *sd; - clicon_handle h; + clixon_handle h; int ret; int status; cbuf *cberr = NULL; h = rc->rc_h; if ((sd = restconf_stream_find(rc, 0)) == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found"); + clixon_err(OE_RESTCONF, EINVAL, "restconf stream not found"); goto done; } /* Two states for reading: @@ -691,7 +691,7 @@ restconf_http1_process(restconf_conn *rc, goto done; if (status == 1){ /* Next read: keep header state and only append inbody */ if (cbuf_append_buf(sd->sd_indata, buf, n) < 0){ - clicon_err(OE_UNIX, errno, "cbuf_append"); + clixon_err(OE_UNIX, errno, "cbuf_append"); goto done; } } @@ -700,7 +700,7 @@ restconf_http1_process(restconf_conn *rc, * This is different from sd_indata that it is before and includes headers */ if (cbuf_append_buf(sd->sd_inbuf, buf, n) < 0){ - clicon_err(OE_UNIX, errno, "cbuf_append"); + clixon_err(OE_UNIX, errno, "cbuf_append"); goto done; } if (clixon_http1_parse_string(h, rc, cbuf_get(sd->sd_inbuf)) < 0){ @@ -720,10 +720,10 @@ restconf_http1_process(restconf_conn *rc, * timeout here. */ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - cprintf(cberr, "protocolmalformed-message%s", clicon_err_reason); + cprintf(cberr, "protocolmalformed-message%s", clixon_err_reason()); if ((ret = native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc)) < 0) goto done; if (http1_native_clear_input(h, sd) < 0) @@ -812,7 +812,7 @@ restconf_http2_upgrade(restconf_conn *rc) restconf_stream_data *sd; if ((sd = restconf_stream_find(rc, 0)) == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found"); + clixon_err(OE_RESTCONF, EINVAL, "restconf stream not found"); goto done; } if (sd->sd_upgrade2){ @@ -836,7 +836,7 @@ restconf_http2_upgrade(restconf_conn *rc) sd->sd_settings2?strlen((const char*)sd->sd_settings2):0, 0, /* XXX: 1 if HEAD */ NULL)) < 0){ - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2"); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2"); goto done; } if (http2_send_server_connection(rc) < 0){ @@ -889,7 +889,7 @@ restconf_http2_process(restconf_conn *rc, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (rc->rc_exit){ /* Server-initiated exit for http/2 */ if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){ - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr); goto done; // XXX not here in original? } } @@ -924,7 +924,7 @@ restconf_http2_process(restconf_conn *rc, * @retval rn Restconf native handle */ restconf_native_handle * -restconf_native_handle_get(clicon_handle h) +restconf_native_handle_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); size_t len; @@ -963,11 +963,11 @@ restconf_connection(int s, clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, s); if ((rc = (restconf_conn*)arg) == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "arg is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "arg is NULL"); goto done; } if (s != rc->rc_s){ - clicon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s"); + clixon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s"); goto done; } gettimeofday(&rc->rc_t, NULL); /* activity timer */ @@ -1049,13 +1049,13 @@ restconf_connection_close1(restconf_conn *rc) restconf_socket *rsock; if (rc == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "rc is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "rc is NULL"); goto done; } rsock = rc->rc_socket; clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); if (close(rc->rc_s) < 0){ - clicon_err(OE_UNIX, errno, "close"); + clixon_err(OE_UNIX, errno, "close"); goto done; } clixon_event_unreg_fd(rc->rc_s, restconf_connection); @@ -1113,7 +1113,7 @@ restconf_close_ssl_socket(restconf_conn *rc, else{ /* To avoid close again in restconf_native_terminate */ rc->rc_s = -1; - clicon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er); + clixon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er); goto done; } } @@ -1141,7 +1141,7 @@ restconf_close_ssl_socket(restconf_conn *rc, * @retval -1 Error */ static int -ssl_alpn_check(clicon_handle h, +ssl_alpn_check(clixon_handle h, const unsigned char *alpn, unsigned int alpnlen, restconf_conn *rc, @@ -1162,12 +1162,12 @@ ssl_alpn_check(clicon_handle h, #endif else { if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (alpn != NULL){ cprintf(cberr, "protocolmalformed-messageALPN: protocol not recognized: %s", alpn); - clicon_log(LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr)); + clixon_log(h, LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr)); if (native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc) < 0) @@ -1186,7 +1186,7 @@ ssl_alpn_check(clicon_handle h, if (pstr) p = restconf_str2proto(pstr); if (pstr == NULL || p == -1){ - clicon_log(LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__); + clixon_log(h, LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__); if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0) goto done; goto fail; @@ -1223,7 +1223,7 @@ ssl_alpn_check(clicon_handle h, * @see openssl_init_socket where this callback is registered */ int -restconf_ssl_accept_client(clicon_handle h, +restconf_ssl_accept_client(clixon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp) @@ -1247,7 +1247,7 @@ restconf_ssl_accept_client(clicon_handle h, #endif #endif if ((rn = restconf_native_handle_get(h)) == NULL){ - clicon_err(OE_XML, EFAULT, "No openssl handle"); + clixon_err(OE_XML, EFAULT, "No openssl handle"); goto done; } /* @@ -1258,7 +1258,7 @@ restconf_ssl_accept_client(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s s:%d", __FUNCTION__, rc->rc_s); if (rsock->rs_ssl){ if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){ - clicon_err(OE_SSL, 0, "SSL_new"); + clixon_err(OE_SSL, 0, "SSL_new"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl); @@ -1279,16 +1279,16 @@ restconf_ssl_accept_client(clicon_handle h, emailAddress = olof@hagsand.se */ if (SSL_set1_host(rc->rc_ssl, "andy") != 1) { /* for peer cert */ - clicon_err(OE_SSL, 0, "SSL_set1_host"); + clixon_err(OE_SSL, 0, "SSL_set1_host"); goto done; } if (SSL_add1_host(rc->rc_ssl, "olof") != 1) { /* for peer cert */ - clicon_err(OE_SSL, 0, "SSL_set1_host"); + clixon_err(OE_SSL, 0, "SSL_set1_host"); goto done; } #endif if (SSL_set_fd(rc->rc_ssl, rc->rc_s) != 1){ - clicon_err(OE_SSL, 0, "SSL_set_fd"); + clixon_err(OE_SSL, 0, "SSL_set_fd"); goto done; } readmore = 1; @@ -1348,7 +1348,7 @@ restconf_ssl_accept_client(clicon_handle h, case SSL_ERROR_WANT_CLIENT_HELLO_CB: /* 11 */ #endif default: - clicon_err(OE_SSL, 0, "SSL_accept:%d", e); + clixon_err(OE_SSL, 0, "SSL_accept:%d", e); goto done; break; } @@ -1409,7 +1409,7 @@ restconf_ssl_accept_client(clicon_handle h, } #if 0 else{ - clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret)); + clixon_log(h, LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret)); /* Maybe should return already here, but to get proper return message need to * continue to http/1 or http/2 handling * @see restconf_connection_sanity @@ -1436,12 +1436,12 @@ restconf_ssl_accept_client(clicon_handle h, case HTTP_2:{ if (http2_session_init(rc) < 0){ restconf_close_ssl_socket(rc, __FUNCTION__, 0); - clicon_err_reset(); + clixon_err_reset(); goto closed; } if (http2_send_server_connection(rc) < 0){ restconf_close_ssl_socket(rc, __FUNCTION__, 0); - clicon_err_reset(); + clixon_err_reset(); goto closed; } break; @@ -1475,7 +1475,7 @@ restconf_idle_timer_set(struct timeval t, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "restconf idle timer %s", descr); @@ -1521,11 +1521,11 @@ restconf_idle_cb(int fd, struct timeval to = {0,}; if ((rc = (restconf_conn *)arg) == NULL){ - clicon_err(OE_YANG, EINVAL, "rc is NULL"); + clixon_err(OE_YANG, EINVAL, "rc is NULL"); goto done; } if ((rsock = rc->rc_socket) == NULL){ - clicon_err(OE_YANG, EINVAL, "rsock is NULL"); + clixon_err(OE_YANG, EINVAL, "rsock is NULL"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); @@ -1577,12 +1577,12 @@ restconf_idle_timer(restconf_conn *rc) restconf_socket *rsock; if (rc == NULL || !rc->rc_callhome){ - clicon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome"); + clixon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome"); goto done; } rsock = rc->rc_socket; if (rsock == NULL || !rsock->rs_periodic || rsock->rs_idle_timeout==0){ - clicon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic"); + clixon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" register", __FUNCTION__, rsock->rs_description); @@ -1609,7 +1609,7 @@ restconf_callhome_cb(int fd, void *arg) { int retval = -1; - clicon_handle h; + clixon_handle h; restconf_socket *rsock = NULL; struct sockaddr_in6 sin6 = {0,}; // because its larger than sin and sa struct sockaddr *sa = (struct sockaddr *)&sin6; @@ -1620,7 +1620,7 @@ restconf_callhome_cb(int fd, rsock = (restconf_socket *)arg; if (rsock == NULL || !rsock->rs_callhome){ - clicon_err(OE_YANG, EINVAL, "rsock is NULL"); + clixon_err(OE_YANG, EINVAL, "rsock is NULL"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); @@ -1629,7 +1629,7 @@ restconf_callhome_cb(int fd, if (clixon_inet2sin(rsock->rs_addrtype, rsock->rs_addrstr, rsock->rs_port, sa, &sa_len) < 0) goto done; if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) { - clicon_err(OE_UNIX, errno, "socket"); + clixon_err(OE_UNIX, errno, "socket"); goto done; } if (connect(s, sa, sa_len) < 0){ @@ -1683,7 +1683,7 @@ restconf_callhome_timer(restconf_socket *rsock, cbuf *cb = NULL; if (rsock == NULL || !rsock->rs_callhome){ - clicon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome"); + clixon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description); @@ -1709,7 +1709,7 @@ restconf_callhome_timer(restconf_socket *rsock, timeradd(&now, &t1, &t); } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "restconf callhome timer %s", rsock->rs_description); @@ -1745,7 +1745,7 @@ restconf_callhome_timer(restconf_socket *rsock, * @retval -1 Error */ int -restconf_socket_extract(clicon_handle h, +restconf_socket_extract(clixon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock, @@ -1765,18 +1765,18 @@ restconf_socket_extract(clicon_handle h, yang_stmt *ysub = NULL; if ((x = xpath_first(xs, nsc, "namespace")) == NULL){ - clicon_err(OE_XML, EINVAL, "Mandatory namespace not given"); + clixon_err(OE_XML, EINVAL, "Mandatory namespace not given"); goto done; } *namespace = xml_body(x); if ((x = xpath_first(xs, nsc, "description")) != NULL){ if ((rsock->rs_description = strdup(xml_body(x))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } if ((x = xpath_first(xs, nsc, "address")) == NULL){ - clicon_err(OE_XML, EINVAL, "Mandatory address not given"); + clixon_err(OE_XML, EINVAL, "Mandatory address not given"); goto done; } /* address is a union type and needs a special investigation to see which type (ipv4 or ipv6) @@ -1785,25 +1785,25 @@ restconf_socket_extract(clicon_handle h, body = xml_body(x); y = xml_spec(x); if ((cv = cv_dup(yang_cv_get(y))) == NULL){ - clicon_err(OE_UNIX, errno, "cv_dup"); + clixon_err(OE_UNIX, errno, "cv_dup"); goto done; } if ((ret = cv_parse1(body, cv, &reason)) < 0){ - clicon_err(OE_XML, errno, "cv_parse1"); + clixon_err(OE_XML, errno, "cv_parse1"); goto done; } if (ret == 0){ - clicon_err(OE_XML, EFAULT, "%s", reason); + clixon_err(OE_XML, EFAULT, "%s", reason); goto done; } if ((ret = ys_cv_validate(h, cv, y, &ysub, &reason)) < 0) goto done; if (ret == 0){ - clicon_err(OE_XML, EFAULT, "Validation os address: %s", reason); + clixon_err(OE_XML, EFAULT, "Validation os address: %s", reason); goto done; } if (ysub == NULL){ - clicon_err(OE_XML, EFAULT, "No address union type"); + clixon_err(OE_XML, EFAULT, "No address union type"); goto done; } *address = body; @@ -1818,11 +1818,11 @@ restconf_socket_extract(clicon_handle h, if ((x = xpath_first(xs, nsc, "port")) != NULL && (str = xml_body(x)) != NULL){ if ((ret = parse_uint16(str, port, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_uint16"); + clixon_err(OE_XML, errno, "parse_uint16"); goto done; } if (ret == 0){ - clicon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str); + clixon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str); goto done; } } @@ -1834,7 +1834,7 @@ restconf_socket_extract(clicon_handle h, else if (strcmp(str, "true") == 0) rsock->rs_ssl = 1; else { - clicon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str); + clixon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str); goto done; } } @@ -1848,22 +1848,22 @@ restconf_socket_extract(clicon_handle h, if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/period")) != NULL && (str = xml_body(x)) != NULL){ if ((ret = parse_uint32(str, &rsock->rs_period, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_uint16"); + clixon_err(OE_XML, errno, "parse_uint16"); goto done; } if (ret == 0){ - clicon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str); + clixon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str); goto done; } } if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/idle-timeout")) != NULL && (str = xml_body(x)) != NULL){ if ((ret = parse_uint16(str, &rsock->rs_idle_timeout, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_uint16"); + clixon_err(OE_XML, errno, "parse_uint16"); goto done; } if (ret == 0){ - clicon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str); + clixon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str); goto done; } } @@ -1871,11 +1871,11 @@ restconf_socket_extract(clicon_handle h, if ((x = xpath_first(xs, nsc, "call-home/reconnect-strategy/max-attempts")) != NULL && (str = xml_body(x)) != NULL){ if ((ret = parse_uint8(str, &rsock->rs_max_attempts, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_uint8"); + clixon_err(OE_XML, errno, "parse_uint8"); goto done; } if (ret == 0){ - clicon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str); + clixon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str); goto done; } } diff --git a/apps/restconf/restconf_native.h b/apps/restconf/restconf_native.h index c1b3d9aa..001e6e93 100644 --- a/apps/restconf/restconf_native.h +++ b/apps/restconf/restconf_native.h @@ -35,7 +35,7 @@ * Data structures: * 1 1 * +--------------------+ restconf_handle_get +--------------------+ - * | rn restconf_native | <--------------------- | h clicon_handle | + * | rn restconf_native | <--------------------- | h clixon_handle | * | _handle | +--------------------+ * +--------------------+ ^ * common SSL config \ | @@ -109,7 +109,7 @@ typedef struct restconf_conn { int rc_proto_d1; /* parsed version digit 1 */ int rc_proto_d2; /* parsed version digit 2 */ int rc_s; /* Connection socket */ - clicon_handle rc_h; /* Clixon handle */ + clixon_handle rc_h; /* Clixon handle */ SSL *rc_ssl; /* Structure for SSL connection */ restconf_stream_data *rc_streams; /* List of http/2 session streams */ int rc_exit; /* Set to close socket server-side */ @@ -132,7 +132,7 @@ typedef struct restconf_conn { */ typedef struct restconf_socket{ qelem_t rs_qelem; /* List header */ - clicon_handle rs_h; /* Clixon handle */ + clixon_handle rs_h; /* Clixon handle */ char *rs_description; /* Description */ int rs_callhome; /* 0: listen, 1: callhome */ int rs_ss; /* Listen: Server socket, ready for accept @@ -174,19 +174,19 @@ typedef struct { restconf_stream_data *restconf_stream_data_new(restconf_conn *rc, int32_t stream_id); restconf_stream_data *restconf_stream_find(restconf_conn *rc, int32_t id); int restconf_stream_free(restconf_stream_data *sd); -restconf_conn *restconf_conn_new(clicon_handle h, int s, restconf_socket *socket); +restconf_conn *restconf_conn_new(clixon_handle h, int s, restconf_socket *socket); int ssl_x509_name_oneline(SSL *ssl, char **oneline); int restconf_close_ssl_socket(restconf_conn *rc, const char *callfn, int sslerr0); -int restconf_connection_sanity(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd); -restconf_native_handle *restconf_native_handle_get(clicon_handle h); +int restconf_connection_sanity(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd); +restconf_native_handle *restconf_native_handle_get(clixon_handle h); int restconf_connection(int s, void *arg); -int restconf_ssl_accept_client(clicon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp); +int restconf_ssl_accept_client(clixon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp); int restconf_idle_timer_unreg(restconf_conn *rc); int restconf_idle_timer(restconf_conn *rc); int restconf_callhome_timer_unreg(restconf_socket *rsock); int restconf_callhome_timer(restconf_socket *rsock, int status); -int restconf_socket_extract(clicon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock, +int restconf_socket_extract(clixon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock, char **namespace, char **address, char **addrtype, uint16_t *port); #endif /* _RESTCONF_NATIVE_H_ */ diff --git a/apps/restconf/restconf_nghttp2.c b/apps/restconf/restconf_nghttp2.c index 16316f08..a304cdb2 100644 --- a/apps/restconf/restconf_nghttp2.c +++ b/apps/restconf/restconf_nghttp2.c @@ -71,7 +71,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #ifdef HAVE_LIBNGHTTP2 @@ -210,12 +210,12 @@ session_send_callback(nghttp2_session *session, continue; } else{ - clicon_err(OE_RESTCONF, er, "SSL_write %d", sslerr); + clixon_err(OE_RESTCONF, er, "SSL_write %d", sslerr); goto done; } break; default: - clicon_err(OE_SSL, 0, "SSL_write"); + clixon_err(OE_SSL, 0, "SSL_write"); goto done; break; } @@ -240,7 +240,7 @@ session_send_callback(nghttp2_session *session, } #endif else{ - clicon_err(OE_UNIX, errno, "write"); + clixon_err(OE_UNIX, errno, "write"); goto done; } } @@ -288,7 +288,7 @@ static int restconf_nghttp2_path(restconf_stream_data *sd) { int retval = -1; - clicon_handle h; + clixon_handle h; restconf_conn *rc; char *oneline = NULL; cvec *cvv = NULL; @@ -297,7 +297,7 @@ restconf_nghttp2_path(restconf_stream_data *sd) clixon_debug(CLIXON_DBG_DEFAULT, "------------"); rc = sd->sd_conn; if ((h = rc->rc_h) == NULL){ - clicon_err(OE_RESTCONF, EINVAL, "arg is NULL"); + clixon_err(OE_RESTCONF, EINVAL, "arg is NULL"); goto done; } if (rc->rc_ssl != NULL){ @@ -428,7 +428,7 @@ restconf_submit_response(nghttp2_session *session, data_prd.source.ptr = sd; data_prd.read_callback = restconf_sd_read; if ((hdrs = (nghttp2_nv*)calloc(1+cvec_len(sd->sd_outp_hdrs), sizeof(nghttp2_nv))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } hdr = &hdrs[i++]; @@ -454,7 +454,7 @@ restconf_submit_response(nghttp2_session *session, stream_id, hdrs, i, (data_prd.source.ptr != NULL)?&data_prd:NULL)) < 0){ - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response"); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response"); goto done; } retval = 0; @@ -682,7 +682,7 @@ on_begin_headers_callback(nghttp2_session *session, * Both |name| and |value| are guaranteed to be NULL-terminated. */ static int -nghttp2_hdr2clixon(clicon_handle h, +nghttp2_hdr2clixon(clixon_handle h, char *name, char *value) { @@ -882,7 +882,7 @@ error_callback2(nghttp2_session *session, { // restconf_conn *rc = (restconf_conn *)user_data; clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); - clicon_err(OE_NGHTTP2, lib_error_code, "%s", msg); + clixon_err(OE_NGHTTP2, lib_error_code, "%s", msg); return 0; } #endif @@ -907,7 +907,7 @@ http2_recv(restconf_conn *rc, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (rc->rc_ngsession == NULL){ /* http2_session_init not called */ - clicon_err(OE_RESTCONF, EINVAL, "No nghttp2 session"); + clixon_err(OE_RESTCONF, EINVAL, "No nghttp2 session"); goto done; } /* may make additional pending frames */ @@ -918,13 +918,13 @@ http2_recv(restconf_conn *rc, * when |session| was configured as server and * `nghttp2_option_set_no_recv_client_magic()` is not used with * nonzero value. */ - clicon_log(LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__); + clixon_log(NULL, LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__); /* unsure if this does anything, byt does not seem to hurt */ if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, ngerr)) < 0) - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr); goto fail; } - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv"); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv"); goto done; } /* sends highest prio frame from outbound queue to remote peer. It does this as @@ -932,9 +932,9 @@ http2_recv(restconf_conn *rc, * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty. * @see session_send_callback() */ - clicon_err_reset(); + clixon_err_reset(); if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){ - if (clicon_errno) + if (clixon_err_category()) goto done; else goto fail; /* Not fatal error */ @@ -963,11 +963,11 @@ http2_send_server_connection(restconf_conn *rc) NGHTTP2_FLAG_NONE, iv, ARRLEN(iv))) != 0){ - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings"); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings"); goto done; } if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){ - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send"); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send"); goto done; } retval = 0; @@ -1017,7 +1017,7 @@ http2_session_init(restconf_conn *rc) /* Create session for server use, register callbacks */ if ((ngerr = nghttp2_session_server_new3(&session, callbacks, rc, NULL, NULL)) < 0){ - clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new"); + clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new"); goto done; } nghttp2_session_callbacks_del(callbacks); diff --git a/apps/restconf/restconf_root.c b/apps/restconf/restconf_root.c index 9a2e9ac3..ac8ca94a 100644 --- a/apps/restconf/restconf_root.c +++ b/apps/restconf/restconf_root.c @@ -57,7 +57,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include /* restconf */ @@ -76,7 +76,7 @@ * @retval 1 Yes, a restconf path */ int -api_path_is_restconf(clicon_handle h) +api_path_is_restconf(clixon_handle h) { int retval = 0; char *path = NULL; @@ -108,7 +108,7 @@ api_path_is_restconf(clicon_handle h) * enables deployments to specify where the RESTCONF API is located. */ int -api_well_known(clicon_handle h, +api_well_known(clixon_handle h, void *req) { int retval = -1; @@ -134,7 +134,7 @@ api_well_known(clicon_handle h, goto done; /* Create body */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "\n"); @@ -166,7 +166,7 @@ api_well_known(clicon_handle h, * @see api_root_restconf for accessing /restconf/ * */ static int -api_root_restconf_exact(clicon_handle h, +api_root_restconf_exact(clixon_handle h, void *req, char *request_method, int pretty, @@ -187,7 +187,7 @@ api_root_restconf_exact(clicon_handle h, goto ok; } if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0) @@ -201,7 +201,7 @@ api_root_restconf_exact(clicon_handle h, goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (xml_rootchild(xt, 0, &xt) < 0) @@ -241,7 +241,7 @@ api_root_restconf_exact(clicon_handle h, * @param[in] media_out Restconf output media */ static int -api_operational_state(clicon_handle h, +api_operational_state(clixon_handle h, void *req, char *request_method, int pretty, @@ -264,7 +264,7 @@ api_operational_state(clicon_handle h, * @retval -1 Error */ static int -api_yang_library_version(clicon_handle h, +api_yang_library_version(clixon_handle h, void *req, int pretty, restconf_media media_out) @@ -289,7 +289,7 @@ api_yang_library_version(clicon_handle h, if (xml_bind_special(xt, yspec, "/rc:restconf/yang-library-version") < 0) goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } switch (media_out){ @@ -333,7 +333,7 @@ api_yang_library_version(clicon_handle h, * @retval -1 Error */ static int -api_data(clicon_handle h, +api_data(clixon_handle h, void *req, char *api_path, cvec *pcvec, @@ -421,7 +421,7 @@ api_data(clicon_handle h, * @retval -1 Error */ static int -api_operations(clicon_handle h, +api_operations(clixon_handle h, void *req, char *request_method, char *path, @@ -462,7 +462,7 @@ api_operations(clicon_handle h, * @see api_root_restconf_exact for accessing /restconf/ exact */ int -api_root_restconf(clicon_handle h, +api_root_restconf(clixon_handle h, void *req, cvec *qvec) { diff --git a/apps/restconf/restconf_root.h b/apps/restconf/restconf_root.h index 85e4f1bf..67c3d44f 100644 --- a/apps/restconf/restconf_root.h +++ b/apps/restconf/restconf_root.h @@ -52,8 +52,8 @@ /* * Prototypes */ -int api_path_is_restconf(clicon_handle h); -int api_well_known(clicon_handle h, void *req); -int api_root_restconf(clicon_handle h, void *req, cvec *qvec); +int api_path_is_restconf(clixon_handle h); +int api_well_known(clixon_handle h, void *req); +int api_root_restconf(clixon_handle h, void *req, cvec *qvec); #endif /* _RESTCONF_ROOT_H_ */ diff --git a/apps/restconf/restconf_stream.h b/apps/restconf/restconf_stream.h index c4ad9a1c..e11cb856 100644 --- a/apps/restconf/restconf_stream.h +++ b/apps/restconf/restconf_stream.h @@ -40,9 +40,9 @@ /* * Prototypes */ -int api_path_is_stream(clicon_handle h); -int stream_child_free(clicon_handle h, int pid); -int stream_child_freeall(clicon_handle h); -int api_stream(clicon_handle h, void *req, cvec *qvec, int *finish); +int api_path_is_stream(clixon_handle h); +int stream_child_free(clixon_handle h, int pid); +int stream_child_freeall(clixon_handle h); +int api_stream(clixon_handle h, void *req, cvec *qvec, int *finish); #endif /* _RESTCONF_STREAM_H_ */ diff --git a/apps/restconf/restconf_stream_fcgi.c b/apps/restconf/restconf_stream_fcgi.c index 8ed7ca6a..dfe0a91c 100644 --- a/apps/restconf/restconf_stream_fcgi.c +++ b/apps/restconf/restconf_stream_fcgi.c @@ -86,7 +86,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include /* Need to be after clixon_xml.h due to attribute format */ @@ -124,7 +124,7 @@ static struct stream_child *STREAM_CHILD = NULL; * @retval 0 No, not a stream path */ int -api_path_is_stream(clicon_handle h) +api_path_is_stream(clixon_handle h) { int retval = 0; char *path = NULL; @@ -156,7 +156,7 @@ api_path_is_stream(clicon_handle h) * @note could hang STREAM_CHILD list on clicon handle instead. */ int -stream_child_free(clicon_handle h, +stream_child_free(clixon_handle h, int pid) { struct stream_child *sc; @@ -181,7 +181,7 @@ stream_child_free(clicon_handle h, * Typically called on restconf exit */ int -stream_child_freeall(clicon_handle h) +stream_child_freeall(clixon_handle h) { struct stream_child *sc; @@ -225,7 +225,7 @@ restconf_stream_cb(int s, /* handle close from remote end: this will exit the client */ if (eof){ clixon_debug(CLIXON_DBG_DEFAULT, "%s eof", __FUNCTION__); - clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); + clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close"); errno = ESHUTDOWN; FCGX_FPrintF(r->out, "SHUTDOWN\r\n"); FCGX_FPrintF(r->out, "\r\n"); @@ -236,12 +236,12 @@ restconf_stream_cb(int s, if ((ret = clicon_msg_decode(reply, NULL, NULL, &xtop, NULL)) < 0) /* XXX pass yang_spec */ goto done; if (ret == 0){ - clicon_err(OE_XML, EFAULT, "Invalid notification"); + clixon_err(OE_XML, EFAULT, "Invalid notification"); goto done; } /* create event */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } if ((xn = xpath_first(xtop, NULL, "notification")) == NULL) @@ -289,7 +289,7 @@ restconf_stream_cb(int s, * @retval -1 Error */ static int -restconf_stream(clicon_handle h, +restconf_stream(clixon_handle h, void *req, char *name, cvec *qvec, @@ -309,7 +309,7 @@ restconf_stream(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); *sp = -1; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "%s", @@ -416,7 +416,7 @@ stream_timeout(int s, * @retval -1 Error */ int -api_stream(clicon_handle h, +api_stream(clixon_handle h, void *req, cvec *qvec, int *finish) @@ -548,7 +548,7 @@ api_stream(clicon_handle h, * killed, call FCGX_Free */ if ((sc = malloc(sizeof(struct stream_child))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(sc, 0, sizeof(struct stream_child)); diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index d2b6454a..dc703296 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -53,7 +53,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "snmp_lib.h" @@ -85,16 +85,16 @@ snmp_common_handler(netsnmp_mib_handler *handler, cbuf *cb = NULL; if (request == NULL || shp == NULL){ - clicon_err(OE_XML, EINVAL, "request or shp is null"); + clixon_err(OE_XML, EINVAL, "request or shp is null"); goto done; } requestvb = request->requestvb; if ((*shp = (clixon_snmp_handle*)handler->myvoid) == NULL){ - clicon_err(OE_XML, 0, "No myvoid handler"); + clixon_err(OE_XML, 0, "No myvoid handler"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } oid_cbuf(cb, (*shp)->sh_oid, (*shp)->sh_oidlen); @@ -157,7 +157,7 @@ snmp_scalar_return(cxobj *xs, goto done; if (ret == 0){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto ok; @@ -165,13 +165,13 @@ snmp_scalar_return(cxobj *xs, } else if (defaultval != NULL){ if ((xmlstr = strdup(defaultval)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } else{ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto ok; @@ -183,7 +183,7 @@ snmp_scalar_return(cxobj *xs, if (ret == 0){ clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, reason); if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto ok; @@ -191,11 +191,11 @@ snmp_scalar_return(cxobj *xs, /* see snmplib/snmp_client. somewhat indirect */ if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value"); + clixon_err(OE_SNMP, ret, "snmp_set_var_typed_value"); goto done; } if ((ret = snmp_set_var_objid(requestvb, oidc, oidclen)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "snmp_set_var_objid"); + clixon_err(OE_SNMP, ret, "snmp_set_var_objid"); goto done; } ok: @@ -223,7 +223,7 @@ snmp_scalar_return(cxobj *xs, * @retval -1 Error */ static int -snmp_scalar_get(clicon_handle h, +snmp_scalar_get(clixon_handle h, yang_stmt *ys, cvec *cvk, char *defaultval, @@ -263,7 +263,12 @@ snmp_scalar_get(clicon_handle h, goto done; /* Detect error XXX Error handling could improve */ if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ +#if 1 + if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0) + goto done; +#else clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL); +#endif goto done; } x = xpath_first(xt, nsc, "%s", xpath); @@ -278,7 +283,7 @@ snmp_scalar_get(clicon_handle h, goto done; if (ret == 0){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto ok; @@ -286,13 +291,13 @@ snmp_scalar_get(clicon_handle h, } else if (defaultval != NULL){ if ((xmlstr = strdup(defaultval)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } else{ if ((ret = netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto ok; @@ -302,7 +307,7 @@ snmp_scalar_get(clicon_handle h, if (ret == 0){ clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, reason); if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto ok; @@ -310,7 +315,7 @@ snmp_scalar_get(clicon_handle h, /* see snmplib/snmp_client. somewhat indirect */ if ((ret = snmp_set_var_typed_value(requestvb, asn1type, snmpval, snmplen)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "snmp_set_var_typed_value"); + clixon_err(OE_SNMP, ret, "snmp_set_var_typed_value"); goto done; } ok: @@ -352,7 +357,7 @@ snmp_yang2xml(cxobj *xtop, goto done; /* Need to prepend an element to fit api_path_fmt2api_path cvv parameter */ if ((cvk1 = cvec_new(1)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } for (i=0; itype != asn1_type){ clixon_debug(CLIXON_DBG_DEFAULT, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type); if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto ok; } } @@ -846,7 +851,7 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler, * @retval -1 Error */ static int -snmp_table_get(clicon_handle h, +snmp_table_get(clixon_handle h, yang_stmt *yt, oid *oidt, size_t oidtlen, @@ -899,11 +904,11 @@ snmp_table_get(clicon_handle h, * Inverse of snmp_str2oid */ if ((cvk_orig = yang_cvec_get(yt)) == NULL){ - clicon_err(OE_YANG, 0, "No keys"); + clixon_err(OE_YANG, 0, "No keys"); goto done; } if ((cvk_val = cvec_dup(cvk_orig)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } /* read through keys and create cvk */ @@ -913,14 +918,14 @@ snmp_table_get(clicon_handle h, for (i=0; itype != asn1_type){ clixon_debug(CLIXON_DBG_DEFAULT, "%s Expected type:%d, got: %d", __FUNCTION__, requestvb->type, asn1_type); if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto ok; } } @@ -1063,11 +1068,11 @@ snmp_table_set(clicon_handle h, * Inverse of snmp_str2oid */ if ((cvk_orig = yang_cvec_get(yt)) == NULL){ - clicon_err(OE_YANG, 0, "No keys"); + clixon_err(OE_YANG, 0, "No keys"); goto done; } if ((cvk_val = cvec_dup(cvk_orig)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } /* read through keys and create cvk */ @@ -1077,14 +1082,14 @@ snmp_table_set(clicon_handle h, for (i=0; i -/* clicon */ +/* clixon */ #include #include "snmp_lib.h" @@ -277,7 +277,7 @@ oid_append(const oid *objid0, dst = (void*)objid0; dst += (*objid0len)*sizeof(*objid0); if (memcpy(dst, objid1, objid1len*sizeof(*objid0)) < 0){ - clicon_err(OE_UNIX, errno, "memcpy"); + clixon_err(OE_UNIX, errno, "memcpy"); return -1; } *objid0len += objid1len; @@ -309,7 +309,7 @@ oid_print(FILE *f, cbuf *cb; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } oid_cbuf(cb, objid, objidlen); @@ -351,13 +351,13 @@ snmp_yang_type_get(yang_stmt *ys, restype2 = restype; if (strcmp(restype2, "leafref")==0){ if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "No path in leafref"); + clixon_err(OE_YANG, 0, "No path in leafref"); goto done; } if (yang_path_arg(ys, yang_argument_get(ypath), &yref) < 0) goto done; if (yref == NULL){ - clicon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", yang_argument_get(ypath)); + clixon_err(OE_YANG, 0, "No referred YANG node found for leafref path %s", yang_argument_get(ypath)); goto done; } if (origtype){ @@ -414,7 +414,7 @@ yang_extension_value_opt(yang_stmt *ys, cg_var *cv; if (ys == NULL){ - clicon_err(OE_YANG, EINVAL, "ys is NULL"); + clixon_err(OE_YANG, EINVAL, "ys is NULL"); goto done; } if (exist) @@ -474,7 +474,7 @@ yangext_oid_get(yang_stmt *yn, goto fail; } if (snmp_parse_oid(oidstr, objid, objidlen) == NULL){ - clicon_err(OE_XML, errno, "snmp_parse_oid"); + clixon_err(OE_XML, errno, "snmp_parse_oid"); goto done; } if (objidstrp) @@ -525,13 +525,13 @@ snmp_handle_clone(void *arg) if (sh0 == NULL) return NULL; if ((sh1 = malloc(sizeof(*sh1))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(sh1, 0, sizeof(*sh1)); if (sh0->sh_cvk_orig && (sh1->sh_cvk_orig = cvec_dup(sh0->sh_cvk_orig)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); return NULL; } return (void*)sh1; @@ -594,7 +594,7 @@ type_yang2asn1(yang_stmt *ys, } /* Then try fully resolved type */ else if ((at = clicon_str2int(snmp_type_map, restype)) < 0){ - clicon_err(OE_YANG, 0, "No snmp translation for YANG %s type:%s", + clixon_err(OE_YANG, 0, "No snmp translation for YANG %s type:%s", yang_argument_get(ys), restype); goto done; } @@ -651,11 +651,11 @@ type_snmp2xml(yang_stmt *ys, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (valstr == NULL){ - clicon_err(OE_UNIX, EINVAL, "valstr is NULL"); + clixon_err(OE_UNIX, EINVAL, "valstr is NULL"); goto done; } if ((cvstr = (char*)clicon_int2str(snmp_type_map, requestvb->type)) == NULL){ - clicon_err(OE_XML, 0, "No mapping for snmp type %d", requestvb->type); + clixon_err(OE_XML, 0, "No mapping for snmp type %d", requestvb->type); goto done; } /* Get yang type of leaf and trasnslate to ASN.1 */ @@ -668,7 +668,7 @@ type_snmp2xml(yang_stmt *ys, cvstr = "string"; cvtype = cv_str2type(cvstr); if ((cv = cv_new(cvtype)) == NULL){ - clicon_err(OE_UNIX, errno, "cv_new"); + clixon_err(OE_UNIX, errno, "cv_new"); goto done; } switch (*asn1type){ @@ -683,7 +683,7 @@ type_snmp2xml(yang_stmt *ys, if (strcmp(restype, "enumeration") == 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "%ld", *requestvb->val.integer); @@ -735,14 +735,14 @@ type_snmp2xml(yang_stmt *ys, assert(0); // XXX clixon_debug(CLIXON_DBG_DEFAULT, "%s %s not supported", __FUNCTION__, cv_type2str(cvtype)); if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_request_set_error"); + clixon_err(OE_SNMP, ret, "netsnmp_request_set_error"); goto done; } goto fail; break; } if ((*valstr = cv2str_dup(cv)) == NULL){ - clicon_err(OE_UNIX, errno, "cv2str_dup"); + clixon_err(OE_UNIX, errno, "cv2str_dup"); goto done; } retval = 1; @@ -784,7 +784,7 @@ type_xml2snmp_pre(char *xmlstr0, cbuf *cb = NULL; if (xmlstr0 == NULL || xmlstr1 == NULL){ - clicon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL"); + clixon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL"); goto done; } /* Get yang type of leaf and trasnslate to ASN.1 */ @@ -814,7 +814,7 @@ type_xml2snmp_pre(char *xmlstr0, int64_t num; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((ret = parse_dec64(xmlstr0, cv_dec64_n_get(cv), &num, NULL)) < 0) @@ -831,7 +831,7 @@ type_xml2snmp_pre(char *xmlstr0, str = xmlstr0; } if ((*xmlstr1 = strdup(str)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 1; @@ -869,7 +869,7 @@ type_xml2snmp(char *snmpstr, int ret; if (snmpval == NULL || snmplen == NULL){ - clicon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL"); + clixon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL"); goto done; } switch (*asn1type){ @@ -879,7 +879,7 @@ type_xml2snmp(char *snmpstr, case ASN_INTEGER: // 2 *snmplen = 4; if ((*snmpval = malloc(*snmplen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } if ((ret = parse_int32(snmpstr, (int32_t*)*snmpval, reason)) < 0) @@ -892,7 +892,7 @@ type_xml2snmp(char *snmpstr, case ASN_GAUGE: // 0x42 *snmplen = 4; if ((*snmpval = malloc(*snmplen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } if ((ret = parse_uint32(snmpstr, (uint32_t*)*snmpval, reason)) < 0) @@ -910,7 +910,7 @@ type_xml2snmp(char *snmpstr, } *snmplen = sizeof(oid)*sz1; if ((*snmpval = malloc(*snmplen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memcpy(*snmpval, oid1, *snmplen); @@ -919,7 +919,7 @@ type_xml2snmp(char *snmpstr, case ASN_OCTET_STR: // 4 *snmplen = strlen(snmpstr)+1; if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } break; @@ -928,7 +928,7 @@ type_xml2snmp(char *snmpstr, struct counter64 *c64; *snmplen = sizeof(struct counter64); // 16! if ((*snmpval = malloc(*snmplen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(*snmpval, 0, *snmplen); @@ -945,7 +945,7 @@ type_xml2snmp(char *snmpstr, in_addr_t saddr; *snmplen = 4; if ((*snmpval = malloc(*snmplen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } saddr = (int32_t)inet_addr(snmpstr); @@ -956,7 +956,7 @@ type_xml2snmp(char *snmpstr, struct ether_addr *eaddr; *snmplen = sizeof(*eaddr); if ((*snmpval = malloc(*snmplen + 1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(*snmpval, 0, *snmplen + 1); @@ -971,7 +971,7 @@ type_xml2snmp(char *snmpstr, case CLIXON_ASN_FIXED_STRING: /* OCTET-STRING with decrement length */ *snmplen = strlen(snmpstr); if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } *asn1type = ASN_OCTET_STR; @@ -1010,7 +1010,7 @@ snmp_yang2xpath_cb(yang_stmt *ys, char *prefix = NULL; if ((yp = yang_parent_get(ys)) == NULL){ - clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys)); + clixon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys)); goto done; } if (yp != NULL && /* XXX rm */ @@ -1075,13 +1075,13 @@ snmp_yang2xpath(yang_stmt *ys, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (snmp_yang2xpath_cb(ys, keyvec, cb) < 0) goto done; if (xpath && (*xpath = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 0; @@ -1167,7 +1167,7 @@ snmp_oid2str(oid **oidi, if (type_yang2asn1(yk, &asn1_type, 1) < 0) goto done; if ((enc = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } switch (asn1_type){ @@ -1196,7 +1196,7 @@ snmp_oid2str(oid **oidi, } if (cbuf_len(enc)){ if (cv_string_set(cv, cbuf_get(enc)) < 0){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); goto done; } } @@ -1296,12 +1296,12 @@ snmp_xmlkey2val_oid(cxobj *xentry, if (*cvk_val){ cvec_free(*cvk_val); if ((*cvk_val = cvec_dup(cvk_name)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } } else if ((*cvk_val = cvec_dup(cvk_name)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } } @@ -1312,7 +1312,7 @@ snmp_xmlkey2val_oid(cxobj *xentry, if (cvk_val){ cv = cvec_i(*cvk_val, i); if (cv_string_set(cv, xml_body(xi)) < 0){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); goto done; } } diff --git a/apps/snmp/snmp_lib.h b/apps/snmp/snmp_lib.h index 3b4e4d83..406f94c9 100644 --- a/apps/snmp/snmp_lib.h +++ b/apps/snmp/snmp_lib.h @@ -65,7 +65,7 @@ extern "C" { /* Userdata to pass around in netsmp callbacks */ struct clixon_snmp_handle { - clicon_handle sh_h; + clixon_handle sh_h; yang_stmt *sh_ys; /* Leaf for scalar, list for table */ oid sh_oid[MAX_OID_LEN]; /* OID of registered table (list) */ size_t sh_oidlen; diff --git a/apps/snmp/snmp_main.c b/apps/snmp/snmp_main.c index 7f2fbbc3..739747f9 100644 --- a/apps/snmp/snmp_main.c +++ b/apps/snmp/snmp_main.c @@ -63,7 +63,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "snmp_lib.h" @@ -78,7 +78,7 @@ static int clixon_snmp_input_cb(int s, void *arg); /*! Return (hardcoded) pid file */ static char* -clicon_snmp_pidfile(clicon_handle h) +clicon_snmp_pidfile(clixon_handle h) { return "/var/tmp/clixon_snmp.pid"; } @@ -90,7 +90,7 @@ clicon_snmp_pidfile(clicon_handle h) static void clixon_snmp_sig_term(int arg) { - clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", + clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d", __PROGRAM__, __FUNCTION__, getpid(), arg); /* This should ensure no more accepts or incoming packets are processed because next time eventloop * is entered, it will terminate. @@ -105,7 +105,7 @@ clixon_snmp_sig_term(int arg) * @param[in] h Clixon handle */ static int -snmp_terminate(clicon_handle h) +snmp_terminate(clixon_handle h) { yang_stmt *yspec; cvec *nsctx; @@ -130,9 +130,9 @@ snmp_terminate(clicon_handle h) xml_free(x); xpath_optimize_exit(); clixon_event_exit(); - clicon_handle_exit(h); + clixon_handle_exit(h); clixon_err_exit(); - clicon_log_exit(); + clixon_log_exit(); if (pidfile) unlink(pidfile); return 0; @@ -151,7 +151,7 @@ snmp_terminate(clicon_handle h) * @see clixon_snmp_input_cb */ static int -clixon_snmp_fdset_register(clicon_handle h, +clixon_snmp_fdset_register(clixon_handle h, int regfd) { int retval = -1; @@ -164,7 +164,7 @@ clixon_snmp_fdset_register(clicon_handle h, FD_ZERO(&readfds); if ((nr = snmp_sess_select_info(NULL, &numfds, &readfds, &timeout, &block)) < 0){ - clicon_err(OE_XML, errno, "snmp_select_error"); + clixon_err(OE_XML, errno, "snmp_select_error"); goto done; } /* eg 4, 6, 8 */ @@ -202,7 +202,7 @@ clixon_snmp_input_cb(int s, { int retval = -1; fd_set readfds; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; int ret; clixon_debug(CLIXON_DBG_DETAIL, "%s %d", __FUNCTION__, s); @@ -211,7 +211,7 @@ clixon_snmp_input_cb(int s, (void)snmp_read(&readfds); if (clixon_event_poll(s) < 0){ if (errno == EBADF){ - clicon_err_reset(); + clixon_err_reset(); /* Close the active socket */ if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0) goto done; @@ -220,7 +220,7 @@ clixon_snmp_input_cb(int s, if (clixon_snmp_fdset_register(h, 0) < 0) goto done; if ((ret = snmp_close_sessions()) != 1){ - clicon_err(OE_SNMP, ret, "snmp_close_sessions"); + clixon_err(OE_SNMP, ret, "snmp_close_sessions"); goto done; } /* Signal normal exit to upper layers (=event handling) @@ -229,7 +229,7 @@ clixon_snmp_input_cb(int s, clixon_exit_set(1); } else { - clicon_err(OE_UNIX, errno, "poll"); + clixon_err(OE_UNIX, errno, "poll"); goto done; } } @@ -247,14 +247,14 @@ clixon_snmp_input_cb(int s, * @see snmp_terminate */ static int -clixon_snmp_init_subagent(clicon_handle h, +clixon_snmp_init_subagent(clixon_handle h, int logdst) { int retval = -1; char *sockpath = NULL; clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); - if (logdst == CLICON_LOG_SYSLOG) + if (logdst == CLIXON_LOG_SYSLOG) snmp_enable_calllog(); else snmp_enable_stderrlog(); @@ -271,7 +271,7 @@ clixon_snmp_init_subagent(clicon_handle h, netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1); if ((sockpath = clicon_option_str(h, "CLICON_SNMP_AGENT_SOCK")) == NULL){ - clicon_err(OE_XML, 0, "CLICON_SNMP_AGENT_SOCK not set"); + clixon_err(OE_XML, 0, "CLICON_SNMP_AGENT_SOCK not set"); goto done; } /* XXX: This should be configurable. */ @@ -284,19 +284,19 @@ clixon_snmp_init_subagent(clicon_handle h, init_snmp(__PROGRAM__); if (!clixon_snmp_api_agent_check()){ - clicon_err(OE_DAEMON, 0, "Connection to SNMP agent failed"); + clixon_err(OE_DAEMON, 0, "Connection to SNMP agent failed"); goto done; } if (set_signal(SIGTERM, clixon_snmp_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGINT, clixon_snmp_sig_term, NULL) < 0){ - clicon_err(OE_DAEMON, errno, "Setting signal"); + clixon_err(OE_DAEMON, errno, "Setting signal"); goto done; } if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ - clicon_err(OE_UNIX, errno, "Setting SIGPIPE signal"); + clixon_err(OE_UNIX, errno, "Setting SIGPIPE signal"); goto done; } /* Workaround for netsnmps API use of fdset:s instead of sockets */ @@ -313,7 +313,7 @@ clixon_snmp_init_subagent(clicon_handle h, * @param[in] argv0 command line */ static void -usage(clicon_handle h, +usage(clixon_handle h, char *argv0) { fprintf(stderr, "usage:%s\n" @@ -338,8 +338,8 @@ main(int argc, int retval = -1; int c; char *argv0 = argv[0]; - clicon_handle h; - int logdst = CLICON_LOG_STDERR; + clixon_handle h; + int logdst = CLIXON_LOG_STDERR; struct passwd *pw; yang_stmt *yspec = NULL; char *str; @@ -357,14 +357,17 @@ main(int argc, enum format_enum config_dump_format = FORMAT_XML; /* Create handle */ - if ((h = clicon_handle_init()) == NULL) + if ((h = clixon_handle_init()) == NULL) return -1; /* In the startup, logs to stderr & debug flag set later */ - clicon_log_init(__PROGRAM__, LOG_INFO, logdst); + if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0) + goto done; + if (clixon_err_init(h) < 0) + goto done; /* Set username to clixon handle. Use in all communication to backend */ if ((pw = getpwuid(getuid())) == NULL){ - clicon_err(OE_UNIX, errno, "getpwuid"); + clixon_err(OE_UNIX, errno, "getpwuid"); goto done; } if (clicon_username_set(h, pw->pw_name) < 0) @@ -387,12 +390,12 @@ main(int argc, usage(h, argv[0]); clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg); break; - case 'l': /* Log destination: s|e|o */ - if ((logdst = clicon_log_opt(optarg[0])) < 0) + case 'l': /* Log destination: s|e|o */ + if ((logdst = clixon_log_opt(optarg[0])) < 0) usage(h, argv[0]); - if (logdst == CLICON_LOG_FILE && + if (logdst == CLIXON_LOG_FILE && strlen(optarg)>1 && - clicon_log_file(optarg+1) < 0) + clixon_log_file(optarg+1) < 0) goto done; break; } @@ -400,8 +403,8 @@ main(int argc, /* * Logs, error and debug to stderr or syslog, set debug level */ - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); - clixon_debug_init(dbg, NULL); + clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst); + clixon_debug_init(h, dbg); /* This is netsnmplib debugging which is quite extensive + only if compiled w debug */ if (dbg > 1) snmp_set_do_debugging(1); @@ -458,7 +461,7 @@ main(int argc, /* Check pid-file, if zap kill the old daemon, else return here */ if ((pidfile = clicon_snmp_pidfile(h)) == NULL){ - clicon_err(OE_FATAL, 0, "pidfile not set"); + clixon_err(OE_FATAL, 0, "pidfile not set"); goto done; } if (pidfile_get(pidfile, &pid) < 0) @@ -472,7 +475,7 @@ main(int argc, exit(0); /* OK */ } else if (pid){ - clicon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)", + clixon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)", pid, argv0); return -1; /* goto done deletes pidfile */ } @@ -485,8 +488,8 @@ main(int argc, cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD"); cbuf_alloc_set(cligen_buflen, cligen_bufthreshold); - if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0) - clicon_log_string_limit_set(sz); + if ((sz = clicon_option_int(h, "CLIXON_LOG_STRING_LIMIT")) != 0) + clixon_log_string_limit_set(sz); /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ xml_nsctx_namespace_netconf_default(h); @@ -570,7 +573,7 @@ main(int argc, retval = 0; done: snmp_terminate(h); - clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ - clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); + clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */ + clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid()); return retval; } diff --git a/apps/snmp/snmp_register.c b/apps/snmp/snmp_register.c index edd41689..9b488ede 100644 --- a/apps/snmp/snmp_register.c +++ b/apps/snmp/snmp_register.c @@ -72,7 +72,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include "snmp_lib.h" @@ -95,7 +95,7 @@ * netsnmp_subtree_find(oid1,sz1, 0, 0) */ static int -mibyang_leaf_register(clicon_handle h, +mibyang_leaf_register(clixon_handle h, yang_stmt *ys, cvec *cvk_val, oid *oidk, @@ -115,7 +115,7 @@ mibyang_leaf_register(clicon_handle h, cbuf *cboid = NULL; if ((cboid = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((ret = yangext_oid_get(ys, oid1, &oid1len, NULL)) < 0) @@ -146,7 +146,7 @@ mibyang_leaf_register(clicon_handle h, name = yang_argument_get(ys); /* Stateless function, just returns ptr */ if ((handler = netsnmp_create_handler(name, clixon_snmp_scalar_handler)) == NULL){ - clicon_err(OE_XML, errno, "netsnmp_create_handler"); + clixon_err(OE_XML, errno, "netsnmp_create_handler"); goto done; } @@ -154,7 +154,7 @@ mibyang_leaf_register(clicon_handle h, * XXX: not deallocated */ if ((sh = malloc(sizeof(*sh))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(sh, 0, sizeof(*sh)); @@ -165,14 +165,14 @@ mibyang_leaf_register(clicon_handle h, sh->sh_default = default_str; if (cvk_val && (sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } /* Stateless function, just returns ptr */ if ((nhreg = netsnmp_handler_registration_create(name, handler, oid1, oid1len, modes)) == NULL){ - clicon_err(OE_XML, errno, "netsnmp_handler_registration_create"); + clixon_err(OE_XML, errno, "netsnmp_handler_registration_create"); netsnmp_handler_free(handler); goto done; } @@ -186,7 +186,7 @@ mibyang_leaf_register(clicon_handle h, */ if ((ret = netsnmp_register_instance(nhreg)) != SNMPERR_SUCCESS){ /* Note MIB_ errors, not regular SNMPERR_ */ - clicon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance"); + clixon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance"); goto done; } oid_cbuf(cboid, oid1, oid1len); @@ -216,7 +216,7 @@ mibyang_leaf_register(clicon_handle h, * @retval -1 Error */ static int -mibyang_table_register(clicon_handle h, +mibyang_table_register(clixon_handle h, yang_stmt *ylist, oid *oid1, size_t oid1len, @@ -240,7 +240,7 @@ mibyang_table_register(clicon_handle h, if ((ys = yang_parent_get(ylist)) == NULL || yang_keyword_get(ys) != Y_CONTAINER){ - clicon_err(OE_YANG, EINVAL, "ylist parent is not list"); + clixon_err(OE_YANG, EINVAL, "ylist parent is not list"); goto done; } /* Note: This is wrong for augmented nodes where name is the original list, not the @@ -253,7 +253,7 @@ mibyang_table_register(clicon_handle h, * XXX: not deallocated */ if ((sh = malloc(sizeof(*sh))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(sh, 0, sizeof(*sh)); @@ -265,13 +265,13 @@ mibyang_table_register(clicon_handle h, sh->sh_oid2len = oid2len; if ((handler = netsnmp_create_handler(name, clixon_snmp_table_handler)) == NULL){ - clicon_err(OE_XML, errno, "netsnmp_create_handler"); + clixon_err(OE_XML, errno, "netsnmp_create_handler"); goto done; } if ((nhreg = netsnmp_handler_registration_create(name, handler, oid1, oid1len, HANDLER_CAN_RWRITE)) == NULL){ - clicon_err(OE_XML, errno, "netsnmp_handler_registration_create"); + clixon_err(OE_XML, errno, "netsnmp_handler_registration_create"); netsnmp_handler_free(handler); goto done; } @@ -282,12 +282,12 @@ mibyang_table_register(clicon_handle h, /* See netsnmp_register_table_data_set */ if ((table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL){ - clicon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF"); + clixon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF"); goto done; } /* Keys, go through keys */ if ((cvk = yang_cvec_get(ylist)) == NULL){ - clicon_err(OE_YANG, 0, "No keys"); + clixon_err(OE_YANG, 0, "No keys"); goto done; } cvi = NULL; @@ -295,7 +295,7 @@ mibyang_table_register(clicon_handle h, while ((cvi = cvec_each(cvk, cvi)) != NULL) { keyname = cv_string_get(cvi); if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){ - clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", + clixon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", yang_argument_get(ylist), keyname); goto done; } @@ -308,7 +308,7 @@ mibyang_table_register(clicon_handle h, asn1type, NULL, // value 0) == NULL){ - clicon_err(OE_XML, errno, "snmp_varlist_add_variable"); + clixon_err(OE_XML, errno, "snmp_varlist_add_variable"); goto done; } } @@ -323,7 +323,7 @@ mibyang_table_register(clicon_handle h, table_info->max_column++; } if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){ - clicon_err(OE_SNMP, ret, "netsnmp_register_table"); + clixon_err(OE_SNMP, ret, "netsnmp_register_table"); goto done; } sh->sh_table_info = table_info; /* Keep to free at exit */ @@ -350,7 +350,7 @@ mibyang_table_register(clicon_handle h, * @see mibyang_augment_register */ static int -mibyang_list_register(clicon_handle h, +mibyang_list_register(clixon_handle h, yang_stmt *ylist) { int retval = -1; @@ -364,7 +364,7 @@ mibyang_list_register(clicon_handle h, if ((yc = yang_parent_get(ylist)) == NULL || yang_keyword_get(yc) != Y_CONTAINER){ - clicon_err(OE_YANG, EINVAL, "ylist parent is not container"); + clixon_err(OE_YANG, EINVAL, "ylist parent is not container"); goto done; } if ((ret = yangext_oid_get(ylist, oid2, &oid2len, NULL)) < 0) @@ -405,7 +405,7 @@ mibyang_list_register(clicon_handle h, * @see mibyang_list_register */ static int -mibyang_augment_register(clicon_handle h, +mibyang_augment_register(clixon_handle h, yang_stmt *yaug) { int retval = -1; @@ -459,7 +459,7 @@ mibyang_augment_register(clicon_handle h, * @retval -1 Error */ int -mibyang_table_poll(clicon_handle h, +mibyang_table_poll(clixon_handle h, yang_stmt *ylist) { int retval = -1; @@ -481,7 +481,7 @@ mibyang_table_poll(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((ys = yang_parent_get(ylist)) == NULL || yang_keyword_get(ys) != Y_CONTAINER){ - clicon_err(OE_YANG, EINVAL, "ylist parent is not list"); + clixon_err(OE_YANG, EINVAL, "ylist parent is not list"); goto done; } if (xml_nsctx_yang(ys, &nsc) < 0) @@ -491,13 +491,13 @@ mibyang_table_poll(clicon_handle h, if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, NULL, &xt) < 0) goto done; if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ - clixon_netconf_error(h, xerr, "clicon_rpc_get", NULL); + clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration"); goto done; } if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) { /* Make a clone of key-list, but replace names with values */ if ((cvk_name = yang_cvec_get(ylist)) == NULL){ - clicon_err(OE_YANG, 0, "No keys"); + clixon_err(OE_YANG, 0, "No keys"); goto done; } xrow = NULL; @@ -550,7 +550,7 @@ mibyang_table_poll(clicon_handle h, * @retval -1 Error, aborted at first error encounter */ static int -mibyang_traverse(clicon_handle h, +mibyang_traverse(clixon_handle h, yang_stmt *yn) { int retval = -1; @@ -611,7 +611,7 @@ mibyang_traverse(clicon_handle h, * @retval -1 Error */ int -clixon_snmp_traverse_mibyangs(clicon_handle h) +clixon_snmp_traverse_mibyangs(clixon_handle h) { int retval = -1; char *modname; @@ -620,7 +620,7 @@ clixon_snmp_traverse_mibyangs(clicon_handle h) yang_stmt *ymod; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } /* Loop over clixon configuration file to find all CLICON_SNMP_MIB, and @@ -640,7 +640,7 @@ clixon_snmp_traverse_mibyangs(clicon_handle h) * What happens if backend has not loaded it? */ if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){ - clicon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname); + clixon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname); goto done; } /* Recursively traverse the mib-yang to find extensions */ diff --git a/apps/snmp/snmp_register.h b/apps/snmp/snmp_register.h index 38f155bf..1b9c9746 100644 --- a/apps/snmp/snmp_register.h +++ b/apps/snmp/snmp_register.h @@ -44,8 +44,8 @@ extern "C" { /* * Prototypes */ -int mibyang_table_poll(clicon_handle h, yang_stmt *ylist); -int clixon_snmp_traverse_mibyangs(clicon_handle h); +int mibyang_table_poll(clixon_handle h, yang_stmt *ylist); +int clixon_snmp_traverse_mibyangs(clixon_handle h); #endif /* _SNMP_REGISTER_H_ */ diff --git a/doc/FAQ.md b/doc/FAQ.md index 41169476..55b3f8be 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -473,7 +473,7 @@ Each plugin is initiated with an API struct followed by a plugin init function a ... /* more functions here */ } clixon_plugin_api * - clixon_plugin_init(clicon_handle h) + clixon_plugin_init(clixon_handle h) { ... return &api; /* Return NULL on error */ @@ -515,7 +515,7 @@ More are found in the doxygen reference. 1. You add an entry in example_cli.cli > example("This is a comment") ("This is a variable"), mycallback("myarg"); 2. Then define a function in example_cli.c -> mycallback(clicon_handle h, cvec *cvv, cvec *arv) +> mycallback(clixon_handle h, cvec *cvv, cvec *arv) where 'cvv' contains the value of the variable 'var' and 'argv' contains the string "myarg". The 'cvv' datatype is a 'CLIgen variable vector'. @@ -523,9 +523,9 @@ They are documented in [CLIgen tutorial](https://github.com/clicon/cligen/blob/m ## How do I write a validation function? Similar to a commit function, but instead write the transaction_validate() function. -Check for inconsistencies in the XML trees and if they fail, make an clicon_err() call. +Check for inconsistencies in the XML trees and if they fail, make an clixon_err() call. ``` - clicon_err(OE_PLUGIN, 0, "Route %s lacks ipv4 addr", name); + clixon_err(OE_PLUGIN, 0, "Route %s lacks ipv4 addr", name); return -1; ``` The validation or commit will then be aborted. @@ -560,7 +560,7 @@ implement the RFC, you need to register an RPC callback in the backend plugin: Example: ``` int -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { ... rpc_callback_register(h, example_rpc, NULL, "urn:example:my", "example-rpc"); @@ -570,7 +570,7 @@ clixon_plugin_init(clicon_handle h) And then define the callback itself: ``` static int -example_rpc(clicon_handle h, /* Clicon handle */ +example_rpc(clixon_handle h, /* Clicon handle */ cxobj *xe, /* Request: */ cbuf *cbret, /* Reply eg ... */ void *arg, /* Client session */ @@ -592,7 +592,7 @@ The following example shows how `my_copy` can be called right after the system ( the original operation: ``` static int -my_copy(clicon_handle h, /* Clicon handle */ +my_copy(clixon_handle h, /* Clicon handle */ cxobj *xe, /* Request: */ cbuf *cbret, /* Reply eg ... */ void *arg, /* Client session */ @@ -602,7 +602,7 @@ my_copy(clicon_handle h, /* Clicon handle */ return 0; } int -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { ... rpc_callback_register(h, my_copy, NULL, "urn:ietf:params:xml:ns:netconf:base:1.0", "copy-config"); @@ -616,7 +616,7 @@ A restconf call may need to be authenticated. You can specify an authentication callback for restconf as follows: ``` int -plugin_credentials(clicon_handle h, +plugin_credentials(clixon_handle h, void *arg) { FCGX_Request *r = (FCGX_Request *)arg; diff --git a/example/main/README.md b/example/main/README.md index c57727c1..86f6fd05 100644 --- a/example/main/README.md +++ b/example/main/README.md @@ -326,7 +326,7 @@ In the CLI a netconf rpc call is constructed and sent to the backend: See `examp The clixon backend plugin [example_backend.c] reveives the netconf call and replies. This is made byregistering a callback handling handling the RPC: ``` static int -example_rpc(clicon_handle h, +example_rpc(clixon_handle h, cxobj *xe, /* Request: */ cbuf *cbret, /* Reply eg ... */ void *arg, /* Client session */ @@ -336,7 +336,7 @@ example_rpc(clicon_handle h, return 0; } int -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { ... rpc_callback_register(h, example_rpc, NULL, "example"); @@ -426,7 +426,7 @@ static clixon_plugin_api api = { }; clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { /* Optional callback registration for RPC calls */ rpc_callback_register(h, example_rpc, NULL, "example"); diff --git a/example/main/example_backend.c b/example/main/example_backend.c index 008a16f3..ece6b192 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -60,10 +60,10 @@ #include #include -/* clicon */ +/* cligen */ #include -/* Clicon library functions. */ +/* Clixon library functions. */ #include /* These include signatures for plugin and transaction callbacks. */ @@ -182,10 +182,10 @@ static char *_validate_fail_xpath = NULL; static int _validate_fail_toggle = 0; /* fail at validate and commit */ /* forward */ -static int example_stream_timer_setup(clicon_handle h); +static int example_stream_timer_setup(clixon_handle h); int -main_begin(clicon_handle h, +main_begin(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -196,7 +196,7 @@ main_begin(clicon_handle h, /*! This is called on validate (and commit). Check validity of candidate */ int -main_validate(clicon_handle h, +main_validate(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -205,7 +205,7 @@ main_validate(clicon_handle h, if (_validate_fail_toggle==0 && xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ _validate_fail_toggle = 1; /* toggle if triggered */ - clicon_err(OE_XML, 0, "User error"); + clixon_err(OE_XML, 0, "User error"); return -1; /* induce fail */ } } @@ -213,7 +213,7 @@ main_validate(clicon_handle h, } int -main_complete(clicon_handle h, +main_complete(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -224,7 +224,7 @@ main_complete(clicon_handle h, /*! This is called on commit. Identify modifications and adjust machine state */ int -main_commit(clicon_handle h, +main_commit(clixon_handle h, transaction_data td) { cxobj *target = transaction_target(td); /* wanted XML tree */ @@ -239,7 +239,7 @@ main_commit(clicon_handle h, if (_validate_fail_toggle==1 && xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ _validate_fail_toggle = 0; /* toggle if triggered */ - clicon_err(OE_XML, 0, "User error"); + clixon_err(OE_XML, 0, "User error"); return -1; /* induce fail */ } } @@ -263,7 +263,7 @@ main_commit(clicon_handle h, } int -main_commit_done(clicon_handle h, +main_commit_done(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -272,7 +272,7 @@ main_commit_done(clicon_handle h, } int -main_revert(clicon_handle h, +main_revert(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -281,7 +281,7 @@ main_revert(clicon_handle h, } int -main_end(clicon_handle h, +main_end(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -290,7 +290,7 @@ main_end(clicon_handle h, } int -main_abort(clicon_handle h, +main_abort(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -305,7 +305,7 @@ example_stream_timer(int fd, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; /* XXX Change to actual netconf notifications and namespace */ if (stream_notify(h, "EXAMPLE", "faultEthernet0major") < 0) @@ -320,7 +320,7 @@ example_stream_timer(int fd, /*! Set up example stream notification timer */ static int -example_stream_timer_setup(clicon_handle h) +example_stream_timer_setup(clixon_handle h) { struct timeval t, t1; @@ -338,7 +338,7 @@ example_stream_timer_setup(clicon_handle h) * in [RFC6241]. */ static int -empty_rpc(clicon_handle h, /* Clixon handle */ +empty_rpc(clixon_handle h, /* Clixon handle */ cxobj *xe, /* Request: */ cbuf *cbret, /* Reply eg ... */ void *arg, /* client_entry */ @@ -353,7 +353,7 @@ empty_rpc(clicon_handle h, /* Clixon handle */ * The RPC returns the incoming parameters */ static int -example_rpc(clicon_handle h, /* Clixon handle */ +example_rpc(clixon_handle h, /* Clixon handle */ cxobj *xe, /* Request: */ cbuf *cbret, /* Reply eg ... */ void *arg, /* client_entry */ @@ -367,7 +367,7 @@ example_rpc(clicon_handle h, /* Clixon handle */ /* get namespace from rpc name, return back in each output parameter */ if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ - clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); + clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); goto done; } cprintf(cbret, " */ cbuf *cbret, /* Reply eg ... */ void *arg, /* client_entry */ @@ -414,7 +414,7 @@ example_copy_extra(clicon_handle h, /* Clixon handle */ * @note callback is hardcoded C, while registration is controlled by -- -a option */ static int -example_action_reset(clicon_handle h, /* Clixon handle */ +example_action_reset(clixon_handle h, /* Clixon handle */ cxobj *xe, /* Request: */ cbuf *cbret, /* Reply eg ... */ void *arg, /* client_entry */ @@ -453,7 +453,7 @@ example_action_reset(clicon_handle h, /* Clixon handle */ * @see example_statefile where state is read from file and also pagination */ int -example_statedata(clicon_handle h, +example_statedata(clixon_handle h, cvec *nsc, char *xpath, cxobj *xstate) @@ -471,7 +471,7 @@ example_statedata(clicon_handle h, if (!_state) goto ok; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } yspec = clicon_dbspec_yang(h); @@ -549,7 +549,7 @@ example_statedata(clicon_handle h, * @see example_statefile where state is programmatically added */ int -example_statefile(clicon_handle h, +example_statefile(clixon_handle h, cvec *nsc, char *xpath, cxobj *xstate) @@ -574,7 +574,7 @@ example_statefile(clicon_handle h, if (_state_file_cached == 0 || _state_xml_cache == NULL){ if ((fp = fopen(_state_file, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "open(%s)", _state_file); + clixon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) @@ -641,7 +641,7 @@ example_pagination(void *h0, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)h0; + clixon_handle h = (clixon_handle)h0; int locked; uint32_t offset; uint32_t limit; @@ -675,7 +675,7 @@ example_pagination(void *h0, if (_state_file_cached == 0 || _state_xml_cache == NULL){ if ((fp = fopen(_state_file, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "open(%s)", _state_file); + clixon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) @@ -745,7 +745,7 @@ example_pagination(void *h0, * @retval -1 Fatal error */ int -example_lockdb(clicon_handle h, +example_lockdb(clixon_handle h, char *db, int lock, int id) @@ -777,7 +777,7 @@ example_lockdb(clicon_handle h, * @retval -1 Error in one callback */ int -example_extension(clicon_handle h, +example_extension(clixon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -841,7 +841,7 @@ static const map_str2str namespace_map[] = { * @retval -1 Error */ int -example_upgrade(clicon_handle h, +example_upgrade(clixon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd) @@ -891,7 +891,7 @@ example_upgrade(clicon_handle h, mypath = ms->ms_s0; mynamespace = ms->ms_s1; if (xml_nsctx_get_prefix(nsc, mynamespace, &myprefix) == 0){ - clicon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map", + clixon_err(OE_XML, ENOENT, "Namespace %s not found in canonical namespace map", mynamespace); goto done; } @@ -933,7 +933,7 @@ example_upgrade(clicon_handle h, * @see RFC 8528 */ int -main_yang_mount(clicon_handle h, +main_yang_mount(clixon_handle h, cxobj *xt, int *config, validate_level *vl, @@ -948,7 +948,7 @@ main_yang_mount(clicon_handle h, *vl = VL_FULL; if (yanglib && _mount_yang){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, ""); @@ -999,7 +999,7 @@ main_yang_mount(clicon_handle h, * - Rename /interfaces/interface/description to descr */ static int -upgrade_2014_to_2016(clicon_handle h, +upgrade_2014_to_2016(clixon_handle h, cxobj *xt, char *ns, uint16_t op, @@ -1103,7 +1103,7 @@ upgrade_2014_to_2016(clicon_handle h, * fraction-digits 3 and divide all values with 1000 */ static int -upgrade_2016_to_2018(clicon_handle h, +upgrade_2016_to_2018(clixon_handle h, cxobj *xt, char *ns, uint16_t op, @@ -1159,7 +1159,7 @@ upgrade_2016_to_2018(clicon_handle h, cbuf *cb; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } @@ -1204,7 +1204,7 @@ upgrade_2016_to_2018(clicon_handle h, * - Rename /interfaces/interface/description to descr */ static int -upgrade_interfaces(clicon_handle h, +upgrade_interfaces(clixon_handle h, cxobj *xt, char *ns, uint16_t op, @@ -1216,7 +1216,7 @@ upgrade_interfaces(clicon_handle h, int retval = -1; if (_module_upgrade) /* For testing */ - clicon_log(LOG_NOTICE, "%s %s op:%s from:%d to:%d", + clixon_log(h, LOG_NOTICE, "%s %s op:%s from:%d to:%d", __FUNCTION__, ns, (op&XML_FLAG_ADD)?"ADD":(op&XML_FLAG_DEL)?"DEL":"CHANGE", from, to); @@ -1254,7 +1254,7 @@ upgrade_interfaces(clicon_handle h, * In this example, a loopback parameter is added */ int -example_reset(clicon_handle h, +example_reset(clixon_handle h, const char *db) { int retval = -1; @@ -1279,14 +1279,14 @@ example_reset(clicon_handle h, /* xmldb_put requires modification tree to be: ... */ xml_name_set(xt, "config"); if ((cbret = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Merge user reset state */ if ((ret = xmldb_put(h, (char*)db, OP_MERGE, xt, clicon_username_get(h), cbret)) < 0) goto done; if (ret == 0){ - clicon_err(OE_XML, 0, "Error when writing to XML database: %s", + clixon_err(OE_XML, 0, "Error when writing to XML database: %s", cbuf_get(cbret)); goto done; } @@ -1312,7 +1312,7 @@ example_reset(clicon_handle h, * @retval -1 Error */ int -example_start(clicon_handle h) +example_start(clixon_handle h) { int retval = -1; yang_stmt *yspec; @@ -1326,7 +1326,7 @@ example_start(clicon_handle h) */ if (_action_instanceid){ if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_FATAL, 0, "No DB_SPEC"); + clixon_err(OE_FATAL, 0, "No DB_SPEC"); goto done; } if (yang_abs_schema_nodeid(yspec, _action_instanceid, &ya) == 0){ @@ -1348,7 +1348,7 @@ example_start(clicon_handle h) * the main event loop is entered. */ int -example_daemon(clicon_handle h) +example_daemon(clixon_handle h) { int retval = -1; int ret; @@ -1360,7 +1360,7 @@ example_daemon(clicon_handle h) if (_state && _state_file && _state_file_cached){ yspec = clicon_dbspec_yang(h); if ((fp = fopen(_state_file, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "open(%s)", _state_file); + clixon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } /* Need to be yang bound for eg xml_copy_marked() in example_pagination @@ -1382,7 +1382,7 @@ example_daemon(clicon_handle h) } int -example_exit(clicon_handle h) +example_exit(clixon_handle h) { if (_state_xml_cache){ xml_free(_state_xml_cache); @@ -1392,7 +1392,7 @@ example_exit(clicon_handle h) } /* Forward declaration */ -clixon_plugin_api *clixon_plugin_init(clicon_handle h); +clixon_plugin_api *clixon_plugin_init(clixon_handle h); static clixon_plugin_api api = { "example", /* name */ @@ -1419,13 +1419,13 @@ static clixon_plugin_api api = { /*! Backend plugin initialization * * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL Error * @retval api Pointer to API struct * In this example, you can pass -r, -s, -u to control the behaviour, mainly * for use in the test suites. */ clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { struct timeval retention = {0,0}; int argc; /* command-line options (after --) */ @@ -1482,7 +1482,7 @@ clixon_plugin_init(clicon_handle h) break; } if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){ - clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); + clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); goto done; } if (_state_file){ diff --git a/example/main/example_backend_nacm.c b/example/main/example_backend_nacm.c index e7e2568d..ee3bc3b9 100644 --- a/example/main/example_backend_nacm.c +++ b/example/main/example_backend_nacm.c @@ -49,7 +49,7 @@ #include #include -/* clicon */ +/* cligen */ #include /* Clicon library functions. */ @@ -84,7 +84,7 @@ static char *_validate_fail_xpath = NULL; static int _validate_fail_toggle = 0; /* fail at validate and commit */ int -nacm_begin(clicon_handle h, +nacm_begin(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -94,7 +94,7 @@ nacm_begin(clicon_handle h, /*! This is called on validate (and commit). Check validity of candidate */ int -nacm_validate(clicon_handle h, +nacm_validate(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -103,7 +103,7 @@ nacm_validate(clicon_handle h, if (_validate_fail_toggle==0 && xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ _validate_fail_toggle = 1; /* toggle if triggered */ - clicon_err(OE_XML, 0, "User error"); + clixon_err(OE_XML, 0, "User error"); return -1; /* induce fail */ } } @@ -111,7 +111,7 @@ nacm_validate(clicon_handle h, } int -nacm_complete(clicon_handle h, +nacm_complete(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -122,7 +122,7 @@ nacm_complete(clicon_handle h, /*! This is called on commit. Identify modifications and adjust machine state */ int -nacm_commit(clicon_handle h, +nacm_commit(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -131,7 +131,7 @@ nacm_commit(clicon_handle h, if (_validate_fail_toggle==1 && xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ _validate_fail_toggle = 0; /* toggle if triggered */ - clicon_err(OE_XML, 0, "User error"); + clixon_err(OE_XML, 0, "User error"); return -1; /* induce fail */ } } @@ -139,7 +139,7 @@ nacm_commit(clicon_handle h, } int -nacm_commit_done(clicon_handle h, +nacm_commit_done(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -148,7 +148,7 @@ nacm_commit_done(clicon_handle h, } int -nacm_revert(clicon_handle h, +nacm_revert(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -157,7 +157,7 @@ nacm_revert(clicon_handle h, } int -nacm_end(clicon_handle h, +nacm_end(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -166,7 +166,7 @@ nacm_end(clicon_handle h, } int -nacm_abort(clicon_handle h, +nacm_abort(clixon_handle h, transaction_data td) { if (_transaction_log) @@ -187,7 +187,7 @@ nacm_abort(clicon_handle h, * Real code would poll state */ int -nacm_statedata(clicon_handle h, +nacm_statedata(clixon_handle h, cvec *nsc, char *xpath, cxobj *xstate) @@ -209,7 +209,7 @@ nacm_statedata(clicon_handle h, return retval; } -clixon_plugin_api *clixon_plugin_init(clicon_handle h); +clixon_plugin_api *clixon_plugin_init(clixon_handle h); static clixon_plugin_api api = { "nacm", /* name */ /*--- Common fields. ---*/ @@ -230,11 +230,11 @@ static clixon_plugin_api api = { /*! Backend plugin initialization * * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL Error * @retval api Pointer to API struct */ clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { char *nacm_mode; int argc; /* command-line options (after --) */ @@ -259,7 +259,7 @@ clixon_plugin_init(clicon_handle h) nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE"); if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){ - clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__); + clixon_log(h, LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__); /* Skip nacm module if not enabled _unless_ we use transaction tests */ if (_transaction_log == 0) return NULL; diff --git a/example/main/example_cli.c b/example/main/example_cli.c index 705bf0b0..a6acb246 100644 --- a/example/main/example_cli.c +++ b/example/main/example_cli.c @@ -50,7 +50,7 @@ #include #include /* matching strings */ -/* clicon */ +/* clixon */ #include #include #include @@ -67,7 +67,9 @@ static char *_mount_namespace = NULL; /*! Example cli function */ int -mycallback(clicon_handle h, cvec *cvv, cvec *argv) +mycallback(clixon_handle h, + cvec *cvv, + cvec *argv) { int retval = -1; cxobj *xret = NULL; @@ -101,7 +103,7 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv) /*! Example "downcall", ie initiate an RPC to the backend */ int -example_client_rpc(clicon_handle h, +example_client_rpc(clixon_handle h, cvec *cvv, cvec *argv) { @@ -129,7 +131,7 @@ example_client_rpc(clicon_handle h, if (clicon_rpc_netconf_xml(h, xrpc, &xret, NULL) < 0) goto done; if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){ - clixon_netconf_error(h, xerr, "Get configuration", NULL); + clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration"); goto done; } /* Print result */ @@ -168,7 +170,7 @@ cli_incstr(cligen_handle h, if (cv == NULL || cv_type_get(cv) != CGV_STRING) return 0; if ((str = cv_string_get(cv)) == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "cv string is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "cv string is NULL"); return -1; } for (i=0; i"); @@ -242,7 +244,7 @@ example_cli_yang_mount(clicon_handle h, * @see netconf_err2cb this errmsg is the same as the default */ int -example_cli_errmsg(clicon_handle h, +example_cli_errmsg(clixon_handle h, cxobj *xerr, cbuf *cberr) { @@ -281,7 +283,7 @@ example_cli_errmsg(clicon_handle h, * @retval -1 Error */ int -example_version(clicon_handle h, +example_version(clixon_handle h, FILE *f) { cligen_output(f, "Clixon main example version 0\n"); @@ -302,11 +304,11 @@ static clixon_plugin_api api = { /*! CLI plugin initialization * * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL Error * @retval api Pointer to API struct */ clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { struct timeval tv; int c; @@ -330,7 +332,7 @@ clixon_plugin_init(clicon_handle h) break; } if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){ - clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); + clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); goto done; } /* XXX Not implemented: CLI completion for mountpoints, see clixon-controller diff --git a/example/main/example_netconf.c b/example/main/example_netconf.c index f0ee7b00..f355c337 100644 --- a/example/main/example_netconf.c +++ b/example/main/example_netconf.c @@ -55,13 +55,13 @@ * @param[in] h Clixon handle */ int -plugin_start(clicon_handle h) +plugin_start(clixon_handle h) { return 0; } int -plugin_exit(clicon_handle h) +plugin_exit(clixon_handle h) { return 0; } @@ -69,7 +69,7 @@ plugin_exit(clicon_handle h) /*! Local example netconf rpc callback */ int -netconf_client_rpc(clicon_handle h, +netconf_client_rpc(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -81,7 +81,7 @@ netconf_client_rpc(clicon_handle h, /* get namespace from rpc name, return back in each output parameter */ if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ - clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); + clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); goto done; } cprintf(cbret, "", NETCONF_BASE_NAMESPACE); @@ -103,7 +103,7 @@ netconf_client_rpc(clicon_handle h, return 0; } -clixon_plugin_api * clixon_plugin_init(clicon_handle h); +clixon_plugin_api * clixon_plugin_init(clixon_handle h); static struct clixon_plugin_api api = { "example", /* name */ @@ -115,11 +115,11 @@ static struct clixon_plugin_api api = { /*! Netconf plugin initialization * * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL Error * @retval api Pointer to API struct */ clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { clixon_debug(CLIXON_DBG_DEFAULT, "%s restconf", __FUNCTION__); /* Register local netconf rpc client (note not backend rpc client) */ diff --git a/example/main/example_restconf.c b/example/main/example_restconf.c index 317d8b33..bafbaec8 100644 --- a/example/main/example_restconf.c +++ b/example/main/example_restconf.c @@ -45,7 +45,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include #include /* minor use */ @@ -206,7 +206,7 @@ b64_decode(const char *src, * @note: Three hardwired users: andy, wilma, guest w password "bar". */ static int -example_basic_auth(clicon_handle h, +example_basic_auth(clixon_handle h, void *req, char **authp) { @@ -222,7 +222,7 @@ example_basic_auth(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (authp == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL"); goto done; } /* At this point in the code we must use HTTP basic authentication */ @@ -235,7 +235,7 @@ example_basic_auth(clicon_handle h, auth += strlen("Basic "); authlen = strlen(auth)*2; if ((user = malloc(authlen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(user, 0, authlen); @@ -289,7 +289,7 @@ example_basic_auth(clicon_handle h, * @note authp should be malloced */ int -example_restconf_credentials(clicon_handle h, +example_restconf_credentials(clixon_handle h, void *req, clixon_auth_type_t auth_type, char **authp) @@ -317,7 +317,7 @@ example_restconf_credentials(clicon_handle h, /*! Local example restconf rpc callback */ int -restconf_client_rpc(clicon_handle h, +restconf_client_rpc(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -329,7 +329,7 @@ restconf_client_rpc(clicon_handle h, /* get namespace from rpc name, return back in each output parameter */ if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ - clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); + clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); goto done; } cprintf(cbret, "", NETCONF_BASE_NAMESPACE); @@ -352,7 +352,7 @@ restconf_client_rpc(clicon_handle h, /*! Start example restonf plugin. Set authentication method */ int -example_restconf_start(clicon_handle h) +example_restconf_start(clixon_handle h) { clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); return 0; @@ -372,7 +372,7 @@ example_restconf_start(clicon_handle h) * @see RFC 8528 */ int -restconf_yang_mount(clicon_handle h, +restconf_yang_mount(clixon_handle h, cxobj *xt, int *config, validate_level *vl, @@ -387,7 +387,7 @@ restconf_yang_mount(clicon_handle h, *vl = VL_FULL; if (yanglib && _mount_yang){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, ""); @@ -414,7 +414,7 @@ restconf_yang_mount(clicon_handle h, return retval; } -clixon_plugin_api * clixon_plugin_init(clicon_handle h); +clixon_plugin_api * clixon_plugin_init(clixon_handle h); static clixon_plugin_api api = { "example", /* name */ @@ -428,12 +428,12 @@ static clixon_plugin_api api = { /*! Restconf plugin initialization * * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL Error * @retval api Pointer to API struct * Arguments are argc/argv after -- */ clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { int argc; /* command-line options (after --) */ char **argv = NULL; @@ -457,7 +457,7 @@ clixon_plugin_init(clicon_handle h) break; } if ((_mount_yang && !_mount_namespace) || (!_mount_yang && _mount_namespace)){ - clicon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); + clixon_err(OE_PLUGIN, EINVAL, "Both -m and -M must be given for mounts"); goto done; } /* Register local netconf rpc client (note not backend rpc client) */ diff --git a/include/clixon_custom.h b/include/clixon_custom.h index 866ca45e..19c56d8d 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -203,3 +203,10 @@ * Plan is to remove this (undef:d) in next release */ #undef RESTCONF_INLINE + +/*! Backward compatible with 6.5 + * + * Note: many(most) not covered by this constant need to GREP + * This includes lots of clicon->clixon namechanges, see CHANGELOG for whole list + */ +#define COMPAT_6_5 diff --git a/lib/clixon/clixon.h.in b/lib/clixon/clixon.h.in index ab9df9d4..d83575cc 100644 --- a/lib/clixon/clixon.h.in +++ b/lib/clixon/clixon.h.in @@ -68,11 +68,12 @@ extern "C" { #include #include -#include #include #include #include +#include #include +#include #include #include #include diff --git a/lib/clixon/clixon_data.h b/lib/clixon/clixon_data.h index 0fbd078c..00e0ae6b 100644 --- a/lib/clixon/clixon_data.h +++ b/lib/clixon/clixon_data.h @@ -63,87 +63,87 @@ typedef struct { * Prototypes */ /* Generic clixon data API the form = where is string */ -int clicon_data_get(clicon_handle h, const char *name, char **val); -int clicon_data_set(clicon_handle h, const char *name, char *val); -int clicon_data_del(clicon_handle h, const char *name); +int clicon_data_get(clixon_handle h, const char *name, char **val); +int clicon_data_set(clixon_handle h, const char *name, char *val); +int clicon_data_del(clixon_handle h, const char *name); /* Get generic clixon data on the form = where is void* */ -int clicon_ptr_get(clicon_handle h, const char *name, void **ptr); -int clicon_ptr_set(clicon_handle h, const char *name, void *ptr); -int clicon_ptr_del(clicon_handle h, const char *name); +int clicon_ptr_get(clixon_handle h, const char *name, void **ptr); +int clicon_ptr_set(clixon_handle h, const char *name, void *ptr); +int clicon_ptr_del(clixon_handle h, const char *name); -cvec *clicon_data_cvec_get(clicon_handle h, const char *name); -int clicon_data_cvec_set(clicon_handle h, const char *name, cvec *cvv); -int clicon_data_cvec_del(clicon_handle h, const char *name); +cvec *clicon_data_cvec_get(clixon_handle h, const char *name); +int clicon_data_cvec_set(clixon_handle h, const char *name, cvec *cvv); +int clicon_data_cvec_del(clixon_handle h, const char *name); /* String options, default NULL */ -int clicon_data_int_get(clicon_handle h, const char *name); -int clicon_data_int_set(clicon_handle h, const char *name, int val); -int clicon_data_int_del(clicon_handle h, const char *name); +int clicon_data_int_get(clixon_handle h, const char *name); +int clicon_data_int_set(clixon_handle h, const char *name, int val); +int clicon_data_int_del(clixon_handle h, const char *name); -yang_stmt * clicon_dbspec_yang(clicon_handle h); -int clicon_dbspec_yang_set(clicon_handle h, yang_stmt *ys); +yang_stmt * clicon_dbspec_yang(clixon_handle h); +int clicon_dbspec_yang_set(clixon_handle h, yang_stmt *ys); -yang_stmt * clicon_config_yang(clicon_handle h); -int clicon_config_yang_set(clicon_handle h, yang_stmt *ys); +yang_stmt * clicon_config_yang(clixon_handle h); +int clicon_config_yang_set(clixon_handle h, yang_stmt *ys); -yang_stmt * clicon_nacm_ext_yang(clicon_handle h); -int clicon_nacm_ext_yang_set(clicon_handle h, yang_stmt *ys); +yang_stmt * clicon_nacm_ext_yang(clixon_handle h); +int clicon_nacm_ext_yang_set(clixon_handle h, yang_stmt *ys); -cvec *clicon_nsctx_global_get(clicon_handle h); -int clicon_nsctx_global_set(clicon_handle h, cvec *nsctx); +cvec *clicon_nsctx_global_get(clixon_handle h); +int clicon_nsctx_global_set(clixon_handle h, cvec *nsctx); -cxobj * clicon_nacm_ext(clicon_handle h); -int clicon_nacm_ext_set(clicon_handle h, cxobj *xn); +cxobj * clicon_nacm_ext(clixon_handle h); +int clicon_nacm_ext_set(clixon_handle h, cxobj *xn); -cxobj *clicon_nacm_cache(clicon_handle h); -int clicon_nacm_cache_set(clicon_handle h, cxobj *xn); +cxobj *clicon_nacm_cache(clixon_handle h); +int clicon_nacm_cache_set(clixon_handle h, cxobj *xn); -cxobj *clicon_conf_xml(clicon_handle h); -int clicon_conf_xml_set(clicon_handle h, cxobj *x); +cxobj *clicon_conf_xml(clixon_handle h); +int clicon_conf_xml_set(clixon_handle h, cxobj *x); -cxobj *clicon_conf_restconf(clicon_handle h); -cxobj *clicon_conf_autocli(clicon_handle h); +cxobj *clicon_conf_restconf(clixon_handle h); +cxobj *clicon_conf_autocli(clixon_handle h); -db_elmnt *clicon_db_elmnt_get(clicon_handle h, const char *db); -int clicon_db_elmnt_set(clicon_handle h, const char *db, db_elmnt *xc); +db_elmnt *clicon_db_elmnt_get(clixon_handle h, const char *db); +int clicon_db_elmnt_set(clixon_handle h, const char *db, db_elmnt *xc); /**/ /* Set and get authorized user name */ -char *clicon_username_get(clicon_handle h); -int clicon_username_set(clicon_handle h, void *username); +char *clicon_username_get(clixon_handle h); +int clicon_username_set(clixon_handle h, void *username); /* Set and get startup status */ -enum startup_status clicon_startup_status_get(clicon_handle h); -int clicon_startup_status_set(clicon_handle h, enum startup_status status); +enum startup_status clicon_startup_status_get(clixon_handle h); +int clicon_startup_status_set(clixon_handle h, enum startup_status status); /* Set and get server socket fd (ie backend server socket / restconf fcgi socket */ -int clicon_socket_get(clicon_handle h); -int clicon_socket_set(clicon_handle h, int s); +int clicon_socket_get(clixon_handle h); +int clicon_socket_set(clixon_handle h, int s); /* Set and get client socket fd (ie client cli / netconf / restconf / client-api socket */ -int clicon_client_socket_get(clicon_handle h); -int clicon_client_socket_set(clicon_handle h, int s); +int clicon_client_socket_get(clixon_handle h); +int clicon_client_socket_set(clixon_handle h, int s); /* Set and get module state full and brief cached tree */ -cxobj *clicon_modst_cache_get(clicon_handle h, int brief); -int clicon_modst_cache_set(clicon_handle h, int brief, cxobj *xms); +cxobj *clicon_modst_cache_get(clixon_handle h, int brief); +int clicon_modst_cache_set(clixon_handle h, int brief, cxobj *xms); /* Set and get yang/xml module revision changelog */ -cxobj *clicon_xml_changelog_get(clicon_handle h); -int clicon_xml_changelog_set(clicon_handle h, cxobj *xchlog); +cxobj *clicon_xml_changelog_get(clixon_handle h); +int clicon_xml_changelog_set(clixon_handle h, cxobj *xchlog); /* Set and get user command-line options (after --) */ -int clicon_argv_get(clicon_handle h, int *argc, char ***argv); -int clicon_argv_set(clicon_handle h, char *argv0, int argc, char **argv); +int clicon_argv_get(clixon_handle h, int *argc, char ***argv); +int clicon_argv_set(clixon_handle h, char *argv0, int argc, char **argv); /* Set and get (client/backend) session id */ -int clicon_session_id_set(clicon_handle h, uint32_t id); -int clicon_session_id_get(clicon_handle h, uint32_t *id); -int clicon_session_id_del(clicon_handle h); +int clicon_session_id_set(clixon_handle h, uint32_t id); +int clicon_session_id_get(clixon_handle h, uint32_t *id); +int clicon_session_id_del(clixon_handle h); /* If set, quit startup directly after upgrade */ -int clicon_quit_upgrade_get(clicon_handle h); -int clicon_quit_upgrade_set(clicon_handle h, int val); +int clicon_quit_upgrade_get(clixon_handle h); +int clicon_quit_upgrade_set(clixon_handle h, int val); #endif /* _CLIXON_DATA_H_ */ diff --git a/lib/clixon/clixon_datastore.h b/lib/clixon/clixon_datastore.h index 139b007a..096d18d1 100644 --- a/lib/clixon/clixon_datastore.h +++ b/lib/clixon/clixon_datastore.h @@ -43,39 +43,39 @@ * API */ /* Internal functions */ -int xmldb_db2file(clicon_handle h, const char *db, char **filename); +int xmldb_db2file(clixon_handle h, const char *db, char **filename); /* API */ -int xmldb_connect(clicon_handle h); -int xmldb_disconnect(clicon_handle h); +int xmldb_connect(clixon_handle h); +int xmldb_disconnect(clixon_handle h); /* in clixon_datastore_read.[ch] */ -int xmldb_get(clicon_handle h, const char *db, cvec *nsc, char *xpath, cxobj **xtop); -int xmldb_get0(clicon_handle h, const char *db, yang_bind yb, +int xmldb_get(clixon_handle h, const char *db, cvec *nsc, char *xpath, cxobj **xtop); +int xmldb_get0(clixon_handle h, const char *db, yang_bind yb, cvec *nsc, const char *xpath, int copy, withdefaults_type wdef, cxobj **xtop, modstate_diff_t *msd, cxobj **xerr); -int xmldb_get0_clear(clicon_handle h, cxobj *x); -int xmldb_get0_free(clicon_handle h, cxobj **xp); -int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); /* in clixon_datastore_write.[ch] */ -int xmldb_copy(clicon_handle h, const char *from, const char *to); -int xmldb_lock(clicon_handle h, const char *db, uint32_t id); -int xmldb_unlock(clicon_handle h, const char *db); -int xmldb_unlock_all(clicon_handle h, uint32_t id); -uint32_t xmldb_islocked(clicon_handle h, const char *db); -int xmldb_lock_timestamp(clicon_handle h, const char *db, struct timeval *tv); -int xmldb_exists(clicon_handle h, const char *db); -int xmldb_clear(clicon_handle h, const char *db); -int xmldb_delete(clicon_handle h, const char *db); -int xmldb_create(clicon_handle h, const char *db); +int xmldb_get0_clear(clixon_handle h, cxobj *x); +int xmldb_get0_free(clixon_handle h, cxobj **xp); +int xmldb_put(clixon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); /* in clixon_datastore_write.[ch] */ +int xmldb_copy(clixon_handle h, const char *from, const char *to); +int xmldb_lock(clixon_handle h, const char *db, uint32_t id); +int xmldb_unlock(clixon_handle h, const char *db); +int xmldb_unlock_all(clixon_handle h, uint32_t id); +uint32_t xmldb_islocked(clixon_handle h, const char *db); +int xmldb_lock_timestamp(clixon_handle h, const char *db, struct timeval *tv); +int xmldb_exists(clixon_handle h, const char *db); +int xmldb_clear(clixon_handle h, const char *db); +int xmldb_delete(clixon_handle h, const char *db); +int xmldb_create(clixon_handle h, const char *db); /* utility functions */ -int xmldb_db_reset(clicon_handle h, const char *db); +int xmldb_db_reset(clixon_handle h, const char *db); -cxobj *xmldb_cache_get(clicon_handle h, const char *db); +cxobj *xmldb_cache_get(clixon_handle h, const char *db); -int xmldb_modified_get(clicon_handle h, const char *db); -int xmldb_modified_set(clicon_handle h, const char *db, int value); -int xmldb_empty_get(clicon_handle h, const char *db); -int xmldb_dump(clicon_handle h, FILE *f, cxobj *xt); -int xmldb_print(clicon_handle h, FILE *f); -int xmldb_rename(clicon_handle h, const char *db, const char *newdb, const char *suffix); +int xmldb_modified_get(clixon_handle h, const char *db); +int xmldb_modified_set(clixon_handle h, const char *db, int value); +int xmldb_empty_get(clixon_handle h, const char *db); +int xmldb_dump(clixon_handle h, FILE *f, cxobj *xt); +int xmldb_print(clixon_handle h, FILE *f); +int xmldb_rename(clixon_handle h, const char *db, const char *newdb, const char *suffix); #endif /* _CLIXON_DATASTORE_H */ diff --git a/lib/clixon/clixon_debug.h b/lib/clixon/clixon_debug.h new file mode 100644 index 00000000..e33501d0 --- /dev/null +++ b/lib/clixon/clixon_debug.h @@ -0,0 +1,60 @@ +/* + * + ***** BEGIN LICENSE BLOCK ***** + + Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren + Copyright (C) 2017-2019 Olof Hagsand + Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC (Netgate) + + This file is part of CLIXON. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Alternatively, the contents of this file may be used under the terms of + the GNU General Public License Version 3 or later (the "GPL"), + in which case the provisions of the GPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of the GPL, and not to allow others to + use your version of this file under the terms of Apache License version 2, + indicate your decision by deleting the provisions above and replace them with + the notice and other provisions required by the GPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the Apache License version 2 or the GPL. + + ***** END LICENSE BLOCK ***** + + * + * Clixon debugging + */ + +#ifndef _CLIXON_DEBUG_H_ +#define _CLIXON_DEBUG_H_ + +/* + * Constants + */ + +/* Debug-level masks */ +#define CLIXON_DBG_DEFAULT 1 /* Default logs */ +#define CLIXON_DBG_MSG 2 /* In/out messages and datastore reads */ +#define CLIXON_DBG_DETAIL 4 /* Details: traces, parse trees, etc */ +#define CLIXON_DBG_EXTRA 8 /* Extra Detailed logs */ + +/* + * Prototypes + */ +int clixon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3))); +int clixon_debug_init(clixon_handle h, int dbglevel); +int clixon_debug_get(void); + +#endif /* _CLIXON_DEBUG_H_ */ diff --git a/lib/clixon/clixon_err.h b/lib/clixon/clixon_err.h index a8c800f6..92a207d3 100644 --- a/lib/clixon/clixon_err.h +++ b/lib/clixon/clixon_err.h @@ -35,9 +35,9 @@ * * Errors may be syslogged using LOG_ERR, and printed to stderr, as controlled by - * clicon_log_init - * global error variables are set: - * clicon_errno, clicon_suberrno, clicon_err_reason. + * clixon_log_init + * Details about the errors may be retreievd by access functions + * clixon_err_reason(), clixon_err_subnr(), etc */ #ifndef _CLIXON_ERR_H_ @@ -58,7 +58,7 @@ * Add error category here, * @see EV variable in clixon_err.c but must also add an entry there */ -enum clicon_err{ +enum clixon_err{ /* 0 means error not set) */ OE_DB = 1, /* database registries */ OE_DAEMON, /* daemons: pidfiles, etc */ @@ -91,28 +91,35 @@ enum clicon_err{ */ typedef int (clixon_cat_log_cb)(void *handle, int suberr, cbuf *cb); -/* - * Variables - * XXX: should not be global - */ -extern int clicon_errno; /* CLICON errors (see clicon_err) */ -extern int clicon_suberrno; /* Eg orig errno */ -extern char clicon_err_reason[ERR_STRLEN]; - /* * Macros */ -#define clicon_err(e,s,_fmt, args...) clicon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args) +#define clixon_err(e,s,_fmt, args...) clixon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args) /* * Prototypes */ -int clicon_err_reset(void); -int clicon_err_fn(const char *fn, const int line, int category, int err, const char *format, ...) __attribute__ ((format (printf, 5, 6))); -char *clicon_strerror(int err); -void *clicon_err_save(void); -int clicon_err_restore(void *handle); -int clixon_err_cat_reg(enum clicon_err category, void *handle, clixon_cat_log_cb logfn); +int clixon_err_init(clixon_handle h); +int clixon_err_category(void); +int clixon_err_subnr(void); +char *clixon_err_reason(void); +char *clixon_err_str(void); +int clixon_err_reset(void); +int clixon_err_args(clixon_handle h, const char *fn, const int line, int category, int suberr, char *msg); +int clixon_err_fn(const char *fn, const int line, int category, int err, const char *format, ...) __attribute__ ((format (printf, 5, 6))); + +void *clixon_err_save(void); +int clixon_err_restore(void *handle); +int clixon_err_cat_reg(enum clixon_err category, void *handle, clixon_cat_log_cb logfn); int clixon_err_exit(void); +#if 1 /* COMPAT_6_5 */ +#define clicon_err(e,s,_fmt, args...) clixon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args) +#define clicon_err_reset() clixon_err_reset() + +#define clicon_errno clixon_err_category() +#define clicon_suberrno clixon_err_subnr() +#define clicon_err_reason clixon_err_reason() +#endif + #endif /* _CLIXON_ERR_H_ */ diff --git a/lib/clixon/clixon_event.h b/lib/clixon/clixon_event.h index 490c33cc..4ca7b11e 100644 --- a/lib/clixon/clixon_event.h +++ b/lib/clixon/clixon_event.h @@ -66,7 +66,7 @@ int clixon_event_unreg_timeout(int (*fn)(int, void*), void *arg); int clixon_event_poll(int fd); -int clixon_event_loop(clicon_handle h); +int clixon_event_loop(clixon_handle h); int clixon_event_exit(void); diff --git a/lib/clixon/clixon_handle.h b/lib/clixon/clixon_handle.h index 5e235f29..0a81409e 100644 --- a/lib/clixon/clixon_handle.h +++ b/lib/clixon/clixon_handle.h @@ -47,7 +47,6 @@ cli/backend/netconf or other plugin. But this is hidden under-the-hood. */ typedef void *clixon_handle; -typedef void *clicon_handle; /* The dynamicically loadable plugin object handle (should be in clixon_plugin.h) */ typedef void *plghndl_t; @@ -67,30 +66,37 @@ typedef int (clicon_output_cb)( * Prototypes */ /* Basic CLICON init functions returning a handle for API access. */ -clicon_handle clicon_handle_init(void); +clixon_handle clixon_handle_init(void); /* Internal call to allocate a CLICON handle. */ -clicon_handle clicon_handle_init0(int size); +clixon_handle clixon_handle_init0(int size); /* Deallocate handle */ -int clicon_handle_exit(clicon_handle h); +int clixon_handle_exit(clixon_handle h); /* Check struct magic number for sanity checks */ -int clicon_handle_check(clicon_handle h); +int clixon_handle_check(clixon_handle h); /* Return clicon options (hash-array) given a handle.*/ -clicon_hash_t *clicon_options(clicon_handle h); +clicon_hash_t *clicon_options(clixon_handle h); /* Return internal clicon data (hash-array) given a handle.*/ -clicon_hash_t *clicon_data(clicon_handle h); +clicon_hash_t *clicon_data(clixon_handle h); /* Return internal clicon db_elmnt (hash-array) given a handle.*/ -clicon_hash_t *clicon_db_elmnt(clicon_handle h); +clicon_hash_t *clicon_db_elmnt(clixon_handle h); /* Return internal stream hash-array given a handle.*/ -struct event_stream *clicon_stream(clicon_handle h); +struct event_stream *clicon_stream(clixon_handle h); struct event_stream; -int clicon_stream_set(clicon_handle h, struct event_stream *es); -int clicon_stream_append(clicon_handle h, struct event_stream *es); +int clicon_stream_set(clixon_handle h, struct event_stream *es); +int clicon_stream_append(clixon_handle h, struct event_stream *es); + +/* COMPAT_6_5 */ +#if 1 +typedef void *clicon_handle; +#define clicon_handle_init() clixon_handle_init() +#define clicon_handle_exit(h) clixon_handle_exit(h) +#endif #endif /* _CLIXON_HANDLE_H_ */ diff --git a/lib/clixon/clixon_log.h b/lib/clixon/clixon_log.h index 9e495ddb..67778314 100644 --- a/lib/clixon/clixon_log.h +++ b/lib/clixon/clixon_log.h @@ -34,7 +34,7 @@ ***** END LICENSE BLOCK ***** * - * Regular logging and debugging. Syslog using levels. + * Regular logging, syslog using levels. */ #ifndef _CLIXON_LOG_H_ @@ -44,38 +44,38 @@ * Constants */ /* Where to log (masks) */ -#define CLICON_LOG_SYSLOG 1 /* print logs on syslog */ -#define CLICON_LOG_STDERR 2 /* print logs on stderr */ -#define CLICON_LOG_STDOUT 4 /* print logs on stdout */ -#define CLICON_LOG_FILE 8 /* print logs on clicon_log_filename */ - -/* Debug-level masks */ -#define CLIXON_DBG_DEFAULT 1 /* Default logs */ -#define CLIXON_DBG_MSG 2 /* In/out messages and datastore reads */ -#define CLIXON_DBG_DETAIL 4 /* Details: traces, parse trees, etc */ -#define CLIXON_DBG_EXTRA 8 /* Extra Detailed logs */ +#define CLIXON_LOG_SYSLOG 1 /* print logs on syslog */ +#define CLIXON_LOG_STDERR 2 /* print logs on stderr */ +#define CLIXON_LOG_STDOUT 4 /* print logs on stdout */ +#define CLIXON_LOG_FILE 8 /* print logs on clicon_log_filename */ /* * Prototypes */ -int clicon_log_init(char *ident, int upto, int flags); -int clicon_log_exit(void); -int clicon_log_opt(char c); -int clicon_log_file(char *filename); -int clicon_log_string_limit_set(size_t sz); -size_t clicon_log_string_limit_get(void); -int clicon_get_logflags(void); -int clicon_log_str(int level, char *msg); -int clicon_log(int level, const char *format, ...) __attribute__ ((format (printf, 2, 3))); -int clixon_debug(int dbglevel, const char *format, ...) __attribute__ ((format (printf, 2, 3))); -int clixon_debug_init(int dbglevel, FILE *f); -int clixon_debug_get(void); -char *mon2name(int md); +int clixon_log_init(clixon_handle h, char *ident, int upto, int flags); +int clixon_log_exit(void); +int clixon_log_opt(char c); +int clixon_log_file(char *filename); +int clixon_log_string_limit_set(size_t sz); +size_t clixon_log_string_limit_get(void); +int clixon_get_logflags(void); +int clixon_log_str(int level, char *msg); +int clixon_log(clixon_handle h, int level, const char *format, ...) __attribute__ ((format (printf, 3, 4))); +char *clixon_log_mon2name(int md); + +#if 1 /* COMPAT_6_5 */ +#define CLICON_LOG_SYSLOG CLIXON_LOG_SYSLOG +#define CLICON_LOG_STDERR CLIXON_LOG_STDERR +#define CLICON_LOG_STDOUT CLIXON_LOG_STDOUT +#define CLICON_LOG_FILE CLIXON_LOG_FILE + +#define clicon_log(l, f, args...) clixon_log(NULL, (l), (f), ##args) +#define clicon_log_exit() clixon_log_exit() +#define clicon_log_opt(c) clixon_log_opt((c)) +#define clicon_log_file(f) clixon_log_file((f)) + +int clicon_log_init(char *ident, int upto, int flags); + +#endif /* COMPAT_6_5 */ -/* 6.4 backward compatability */ -#if 1 -#define clicon_debug clixon_debug -#define clicon_debug_init clixon_debug_init -#define clicon_debug_get clixon_debug_get -#endif #endif /* _CLIXON_LOG_H_ */ diff --git a/lib/clixon/clixon_nacm.h b/lib/clixon/clixon_nacm.h index 8e00d135..c4b0b352 100644 --- a/lib/clixon/clixon_nacm.h +++ b/lib/clixon/clixon_nacm.h @@ -57,12 +57,12 @@ enum nacm_access{ * Prototypes */ int nacm_rpc(char *rpc, char *module, char *username, cxobj *xnacm, cbuf *cbret); -int nacm_datanode_read(clicon_handle h, cxobj *xt, cxobj **xvec, size_t xlen, char *username, +int nacm_datanode_read(clixon_handle h, cxobj *xt, cxobj **xvec, size_t xlen, char *username, cxobj *nacm_xtree); -int nacm_datanode_write(clicon_handle h, cxobj *xr, cxobj *xt, +int nacm_datanode_write(clixon_handle h, cxobj *xr, cxobj *xt, enum nacm_access access, char *username, cxobj *xnacm, cbuf *cbret); -int nacm_access_pre(clicon_handle h, char *peername, char *username, cxobj **xnacmp); -int verify_nacm_user(clicon_handle h, enum nacm_credentials_t cred, char *peername, char *nacmname, cbuf *cbret); +int nacm_access_pre(clixon_handle h, char *peername, char *username, cxobj **xnacmp); +int verify_nacm_user(clixon_handle h, enum nacm_credentials_t cred, char *peername, char *nacmname, cbuf *cbret); #endif /* _CLIXON_NACM_H */ diff --git a/lib/clixon/clixon_netconf_lib.h b/lib/clixon/clixon_netconf_lib.h index 0b44b0bc..4213acde 100644 --- a/lib/clixon/clixon_netconf_lib.h +++ b/lib/clixon/clixon_netconf_lib.h @@ -147,14 +147,6 @@ typedef enum withdefaults_type withdefaults_type; /* * Macros */ -/*! Generate textual error log from Netconf error message - * - * @param[in] xerr Netconf error xml tree on the form: - * @param[in] format Format string - * @param[in] arg String argument to format (optional) - */ -#define clixon_netconf_error(h, x, f, a) clixon_netconf_error_fn((h), __FUNCTION__, __LINE__, (x), (f), (a)) - /* * Prototypes */ @@ -196,24 +188,34 @@ int netconf_data_not_unique(cbuf *cb, cxobj *x, cvec *cvk); int netconf_data_not_unique_xml(cxobj **xret, cxobj *x, cvec *cvk); int netconf_minmax_elements_xml(cxobj **xret, cxobj *xp, char *name, int max); int netconf_trymerge(cxobj *x, yang_stmt *yspec, cxobj **xret); -int netconf_module_features(clicon_handle h); -int netconf_module_load(clicon_handle h); +int netconf_module_features(clixon_handle h); +int netconf_module_load(clixon_handle h); char *netconf_db_find(cxobj *xn, char *name); -int netconf_err2cb(clicon_handle h, cxobj *xerr, cbuf *cberr); const netconf_content netconf_content_str2int(char *str); const char *netconf_content_int2str(netconf_content nr); -int netconf_capabilites(clicon_handle h, cbuf *cb); -int netconf_hello_server(clicon_handle h, cbuf *cb, uint32_t session_id); -int netconf_hello_req(clicon_handle h, cbuf *cb); -int clixon_netconf_error_fn(clicon_handle h, const char *fn, const int line, cxobj *xerr, const char *fmt, const char *arg); +int netconf_capabilites(clixon_handle h, cbuf *cb); +int netconf_hello_server(clixon_handle h, cbuf *cb, uint32_t session_id); +int netconf_hello_req(clixon_handle h, cbuf *cb); int clixon_netconf_internal_error(cxobj *xerr, char *msg, char *arg); int netconf_parse_uint32(char *name, char *valstr, char *defaultstr, uint32_t defaultval, cbuf *cbret, uint32_t *value); int netconf_parse_uint32_xml(char *name, char *valstr, char *defaultstr, uint32_t defaultval, cxobj **xerr, uint32_t *value); -int netconf_message_id_next(clicon_handle h); +int netconf_message_id_next(clixon_handle h); int netconf_framing_preamble(netconf_framing_type framing, cbuf *cb); int netconf_framing_postamble(netconf_framing_type framing, cbuf *cb); int netconf_output(int s, cbuf *xf, char *msg); int netconf_output_encap(netconf_framing_type framing, cbuf *cb); int netconf_input_chunked_framing(char ch, int *state, size_t *size); +/* Netconf error handling */ +#define clixon_err_netconf(h,c,s,x,_fmt, args...) clixon_err_netconf_fn((h), __FUNCTION__, __LINE__, (c), (s), (x), _fmt , ##args) + +int netconf_err2cb(clixon_handle h, cxobj *xerr, cbuf *cberr); +int clixon_err_netconf_fn(clixon_handle h, const char *fn, const int line, int category, + int suberr, cxobj *xerr, const char *format, ...) __attribute__ ((format (printf, 7, 8)));; + +#if 1 /* COMPAT_6_5 */ +/* doesnt work if arg != NULL */ +#define clixon_netconf_error(h, x, f, a) clixon_err_netconf_fn((h), __FUNCTION__, __LINE__, OE_XML, 0,(x), (f) , NULL) +#endif + #endif /* _CLIXON_NETCONF_LIB_H */ diff --git a/lib/clixon/clixon_netconf_monitoring.h b/lib/clixon/clixon_netconf_monitoring.h index be1d36db..433917c8 100644 --- a/lib/clixon/clixon_netconf_monitoring.h +++ b/lib/clixon/clixon_netconf_monitoring.h @@ -41,8 +41,8 @@ /* * Prototypes */ -int netconf_monitoring_state_get(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); -int netconf_monitoring_statistics_init(clicon_handle h); -int netconf_monitoring_counter_inc(clicon_handle h, char *name); +int netconf_monitoring_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); +int netconf_monitoring_statistics_init(clixon_handle h); +int netconf_monitoring_counter_inc(clixon_handle h, char *name); #endif /* _CLIXON_NETCONF_MONITORING_H_ */ diff --git a/lib/clixon/clixon_options.h b/lib/clixon/clixon_options.h index 93f467f7..89969c19 100644 --- a/lib/clixon/clixon_options.h +++ b/lib/clixon/clixon_options.h @@ -109,105 +109,105 @@ enum regexp_mode{ */ /* Debug dump config options */ -int clicon_option_dump(clicon_handle h, int dblevel); +int clicon_option_dump(clixon_handle h, int dblevel); /*! Dump config options on stdio using output format */ -int clicon_option_dump1(clicon_handle h, FILE *f, int format, int pretty); +int clicon_option_dump1(clixon_handle h, FILE *f, int format, int pretty); /* Add a clicon options overriding file setting */ -int clicon_option_add(clicon_handle h, const char *name, char *value); +int clicon_option_add(clixon_handle h, const char *name, char *value); /* Initialize options: set defaults, read config-file, etc */ -int clicon_options_main(clicon_handle h); +int clicon_options_main(clixon_handle h); /*! Check if a clicon option has a value */ -int clicon_option_exists(clicon_handle h, const char *name); +int clicon_option_exists(clixon_handle h, const char *name); /* String options, default NULL */ -char *clicon_option_str(clicon_handle h, const char *name); -int clicon_option_str_set(clicon_handle h, const char *name, char *val); +char *clicon_option_str(clixon_handle h, const char *name); +int clicon_option_str_set(clixon_handle h, const char *name, char *val); /* Option values gixen as int, default -1 */ -int clicon_option_int(clicon_handle h, const char *name); -int clicon_option_int_set(clicon_handle h, const char *name, int val); +int clicon_option_int(clixon_handle h, const char *name); +int clicon_option_int_set(clixon_handle h, const char *name, int val); /* Option values gixen as bool, default false */ -int clicon_option_bool(clicon_handle h, const char *name); -int clicon_option_bool_set(clicon_handle h, const char *name, int val); +int clicon_option_bool(clixon_handle h, const char *name); +int clicon_option_bool_set(clixon_handle h, const char *name, int val); /* Delete a single option via handle */ -int clicon_option_del(clicon_handle h, const char *name); +int clicon_option_del(clixon_handle h, const char *name); /*-- Standard option access functions for YANG options --*/ -static inline char *clicon_configfile(clicon_handle h){ +static inline char *clicon_configfile(clixon_handle h){ return clicon_option_str(h, "CLICON_CONFIGFILE"); } -static inline char *clicon_yang_main_file(clicon_handle h){ +static inline char *clicon_yang_main_file(clixon_handle h){ return clicon_option_str(h, "CLICON_YANG_MAIN_FILE"); } -static inline char *clicon_yang_main_dir(clicon_handle h){ +static inline char *clicon_yang_main_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_YANG_MAIN_DIR"); } -static inline char *clicon_yang_module_main(clicon_handle h){ +static inline char *clicon_yang_module_main(clixon_handle h){ return clicon_option_str(h, "CLICON_YANG_MODULE_MAIN"); } -static inline char *clicon_yang_module_revision(clicon_handle h){ +static inline char *clicon_yang_module_revision(clixon_handle h){ return clicon_option_str(h, "CLICON_YANG_MODULE_REVISION"); } -static inline char *clicon_backend_dir(clicon_handle h){ +static inline char *clicon_backend_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_BACKEND_DIR"); } -static inline char *clicon_netconf_dir(clicon_handle h){ +static inline char *clicon_netconf_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_NETCONF_DIR"); } -static inline char *clicon_restconf_dir(clicon_handle h){ +static inline char *clicon_restconf_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_RESTCONF_DIR"); } -static inline char *clicon_cli_dir(clicon_handle h){ +static inline char *clicon_cli_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_CLI_DIR"); } -static inline char *clicon_clispec_dir(clicon_handle h){ +static inline char *clicon_clispec_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_CLISPEC_DIR"); } -static inline char *clicon_cli_mode(clicon_handle h){ +static inline char *clicon_cli_mode(clixon_handle h){ return clicon_option_str(h, "CLICON_CLI_MODE"); } -static inline int clicon_cli_tab_mode(clicon_handle h){ +static inline int clicon_cli_tab_mode(clixon_handle h){ return clicon_option_int(h, "CLICON_CLI_TAB_MODE"); } -static inline char *clicon_sock_str(clicon_handle h){ +static inline char *clicon_sock_str(clixon_handle h){ return clicon_option_str(h, "CLICON_SOCK"); } -static inline char *clicon_sock_group(clicon_handle h){ +static inline char *clicon_sock_group(clixon_handle h){ return clicon_option_str(h, "CLICON_SOCK_GROUP"); } -static inline char *clicon_backend_user(clicon_handle h){ +static inline char *clicon_backend_user(clixon_handle h){ return clicon_option_str(h, "CLICON_BACKEND_USER"); } -static inline char *clicon_backend_pidfile(clicon_handle h){ +static inline char *clicon_backend_pidfile(clixon_handle h){ return clicon_option_str(h, "CLICON_BACKEND_PIDFILE"); } -static inline char *clicon_xmldb_dir(clicon_handle h){ +static inline char *clicon_xmldb_dir(clixon_handle h){ return clicon_option_str(h, "CLICON_XMLDB_DIR"); } -static inline char *clicon_nacm_recovery_user(clicon_handle h){ +static inline char *clicon_nacm_recovery_user(clixon_handle h){ return clicon_option_str(h, "CLICON_NACM_RECOVERY_USER"); } /*-- Specific option access functions for YANG options w type conversion--*/ -int clicon_cli_varonly(clicon_handle h); -int clicon_sock_family(clicon_handle h); -int clicon_sock_port(clicon_handle h); -int clicon_autocommit(clicon_handle h); -int clicon_startup_mode(clicon_handle h); -enum priv_mode_t clicon_backend_privileges_mode(clicon_handle h); -enum priv_mode_t clicon_restconf_privileges_mode(clicon_handle h); -enum nacm_credentials_t clicon_nacm_credentials(clicon_handle h); +int clicon_cli_varonly(clixon_handle h); +int clicon_sock_family(clixon_handle h); +int clicon_sock_port(clixon_handle h); +int clicon_autocommit(clixon_handle h); +int clicon_startup_mode(clixon_handle h); +enum priv_mode_t clicon_backend_privileges_mode(clixon_handle h); +enum priv_mode_t clicon_restconf_privileges_mode(clixon_handle h); +enum nacm_credentials_t clicon_nacm_credentials(clixon_handle h); -enum datastore_cache clicon_datastore_cache(clicon_handle h); -enum regexp_mode clicon_yang_regexp(clicon_handle h); +enum datastore_cache clicon_datastore_cache(clixon_handle h); +enum regexp_mode clicon_yang_regexp(clixon_handle h); /*-- Specific option access functions for non-yang options --*/ -int clicon_quiet_mode(clicon_handle h); -int clicon_quiet_mode_set(clicon_handle h, int val); +int clicon_quiet_mode(clixon_handle h); +int clicon_quiet_mode_set(clixon_handle h, int val); #endif /* _CLIXON_OPTIONS_H_ */ diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index e6abaeda..b03d53ce 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -62,7 +62,7 @@ * @retval -1 Error */ typedef int (*clicon_rpc_cb)( - clicon_handle h, + clixon_handle h, cxobj *xn, cbuf *cbret, void *arg, @@ -84,7 +84,7 @@ typedef int (*clicon_rpc_cb)( * @retval -1 Error */ typedef int (*clicon_upgrade_cb)( - clicon_handle h, + clixon_handle h, cxobj *xn, char *ns, uint16_t op, @@ -121,19 +121,19 @@ typedef enum clixon_auth_type clixon_auth_type_t; * this callback is called *before* privileges are dropped. * @param[in] h Clixon handle */ -typedef int (plgstart_t)(clicon_handle); /* Plugin start */ +typedef int (plgstart_t)(clixon_handle); /* Plugin start */ /* Called just before or after a server has "daemonized", ie put in background. * Backend: If daemon privileges are dropped this callback is called *before* privileges are dropped. * If daemon is started in foreground (-F): pre-daemon is not called, but daemon called * @param[in] h Clixon handle */ -typedef int (plgdaemon_t)(clicon_handle); /* Plugin pre/post daemonized */ +typedef int (plgdaemon_t)(clixon_handle); /* Plugin pre/post daemonized */ /* Called just before plugin unloaded. * @param[in] h Clixon handle */ -typedef int (plgexit_t)(clicon_handle); /* Plugin exit */ +typedef int (plgexit_t)(clixon_handle); /* Plugin exit */ /* For yang extension/unknown handling. * Called at parsing of yang module containing an unknown statement of an extension. @@ -147,7 +147,7 @@ typedef int (plgexit_t)(clicon_handle); /* Plugin exit */ * @retval 0 OK, all callbacks executed OK * @retval -1 Error in one callback */ -typedef int (plgextension_t)(clicon_handle h, yang_stmt *yext, yang_stmt *ys); +typedef int (plgextension_t)(clixon_handle h, yang_stmt *yext, yang_stmt *ys); /*! Called by restconf on each incoming request to check credentials and return username */ @@ -188,7 +188,7 @@ typedef int (plgextension_t)(clicon_handle h, yang_stmt *yext, yang_stmt *ys); * * @note user should be freed by caller */ -typedef int (plgauth_t)(clicon_handle h, void *req, clixon_auth_type_t auth_type, char **authp); +typedef int (plgauth_t)(clixon_handle h, void *req, clixon_auth_type_t auth_type, char **authp); /*! Reset system status * @@ -204,7 +204,7 @@ typedef int (plgauth_t)(clicon_handle h, void *req, clixon_auth_type_t auth_type * @retval 0 OK * @retval -1 Fatal error */ -typedef int (plgreset_t)(clicon_handle h, const char *db); +typedef int (plgreset_t)(clixon_handle h, const char *db); /* Provide state data from plugin * @@ -225,7 +225,7 @@ typedef int (plgreset_t)(clicon_handle h, const char *db); * @note The system does not validate the xml, unless CLICON_VALIDATE_STATE_XML is set * @see clixon_pagination_cb_register for special paginated state data callback */ -typedef int (plgstatedata_t)(clicon_handle h, cvec *nsc, char *xpath, cxobj *xtop); +typedef int (plgstatedata_t)(clixon_handle h, cvec *nsc, char *xpath, cxobj *xtop); /*! Pagination-data type * @@ -243,7 +243,7 @@ typedef void *pagination_data; * @retval 0 OK * @retval -1 Fatal error */ -typedef int (plglockdb_t)(clicon_handle h, char *db, int lock, int id); +typedef int (plglockdb_t)(clixon_handle h, char *db, int lock, int id); /*! Transaction-data type * @@ -252,7 +252,7 @@ typedef int (plglockdb_t)(clicon_handle h, char *db, int lock, int id); typedef void *transaction_data; /* Transaction callback */ -typedef int (trans_cb_t)(clicon_handle h, transaction_data td); +typedef int (trans_cb_t)(clixon_handle h, transaction_data td); /*! Hook to override default prompt with explicit function * @@ -261,7 +261,7 @@ typedef int (trans_cb_t)(clicon_handle h, transaction_data td); * @param[in] mode Cligen syntax mode * @retval prompt Prompt to prepend all CLigen command lines */ -typedef char *(cli_prompthook_t)(clicon_handle, char *mode); +typedef char *(cli_prompthook_t)(clixon_handle, char *mode); /*! General-purpose datastore upgrade callback called once on startupo * @@ -274,7 +274,7 @@ typedef char *(cli_prompthook_t)(clicon_handle, char *mode); * @retval 0 OK * @retval -1 Error */ -typedef int (datastore_upgrade_t)(clicon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd); +typedef int (datastore_upgrade_t)(clixon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd); /*! YANG schema mount * @@ -298,7 +298,7 @@ typedef int (datastore_upgrade_t)(clicon_handle h, const char *db, cxobj *xt, mo * at proper parse-time, but this is not visible in the yanglib return * @see RFC 8528 (schema-mount) and RFC 8525 (yang-lib) */ -typedef int (yang_mount_t)(clicon_handle h, cxobj *xt, int *config, +typedef int (yang_mount_t)(clixon_handle h, cxobj *xt, int *config, validate_level *vl, cxobj **yanglib); /*! YANG module patch @@ -312,7 +312,7 @@ typedef int (yang_mount_t)(clicon_handle h, cxobj *xt, int *config, * @retval 0 OK * @retval -1 Error */ -typedef int (yang_patch_t)(clicon_handle h, yang_stmt *ymod); +typedef int (yang_patch_t)(clixon_handle h, yang_stmt *ymod); /*! Callback to customize Netconf error message * @@ -322,7 +322,7 @@ typedef int (yang_patch_t)(clicon_handle h, yang_stmt *ymod); * @retval 0 OK, with cberr set * @retval -1 Error */ -typedef int (netconf_errmsg_t)(clicon_handle, cxobj *xerr, cbuf *cberr); +typedef int (netconf_errmsg_t)(clixon_handle, cxobj *xerr, cbuf *cberr); /*! Callback for printing version output and exit * @@ -335,7 +335,7 @@ typedef int (netconf_errmsg_t)(clicon_handle, cxobj *xerr, cbuf *cberr); * @retval 0 OK * @retval -1 Error */ -typedef int (plgversion_t)(clicon_handle, FILE*); +typedef int (plgversion_t)(clixon_handle, FILE*); /*! Startup status for use in startup-callback * @@ -355,7 +355,7 @@ enum startup_status{ * Note: Implicit init function */ struct clixon_plugin_api; -typedef struct clixon_plugin_api* (plginit_t)(clicon_handle); /* Clixon plugin Init */ +typedef struct clixon_plugin_api* (plginit_t)(clixon_handle); /* Clixon plugin Init */ struct clixon_plugin_api{ /*--- Common fields. ---*/ @@ -464,62 +464,62 @@ typedef struct { * @retval NULL Failure (if clixon_err() called), module disabled otherwise. * @see CLIXON_PLUGIN_INIT default symbol */ -clixon_plugin_api *clixon_plugin_init(clicon_handle h); +clixon_plugin_api *clixon_plugin_init(clixon_handle h); clixon_plugin_api *clixon_plugin_api_get(clixon_plugin_t *cp); char *clixon_plugin_name_get(clixon_plugin_t *cp); plghndl_t clixon_plugin_handle_get(clixon_plugin_t *cp); -clixon_plugin_t *clixon_plugin_each(clicon_handle h, clixon_plugin_t *cpprev); +clixon_plugin_t *clixon_plugin_each(clixon_handle h, clixon_plugin_t *cpprev); -clixon_plugin_t *clixon_plugin_each_revert(clicon_handle h, clixon_plugin_t *cpprev, int nr); +clixon_plugin_t *clixon_plugin_each_revert(clixon_handle h, clixon_plugin_t *cpprev, int nr); -clixon_plugin_t *clixon_plugin_find(clicon_handle h, const char *name); +clixon_plugin_t *clixon_plugin_find(clixon_handle h, const char *name); -int clixon_plugins_load(clicon_handle h, const char *function, const char *dir, const char *regexp); +int clixon_plugins_load(clixon_handle h, const char *function, const char *dir, const char *regexp); -int clixon_pseudo_plugin(clicon_handle h, const char *name, clixon_plugin_t **cpp); +int clixon_pseudo_plugin(clixon_handle h, const char *name, clixon_plugin_t **cpp); -int plugin_context_check(clicon_handle h, void **wh, const char *name, const char *fn); +int plugin_context_check(clixon_handle h, void **wh, const char *name, const char *fn); -int clixon_plugin_start_one(clixon_plugin_t *cp, clicon_handle h); -int clixon_plugin_start_all(clicon_handle h); +int clixon_plugin_start_one(clixon_plugin_t *cp, clixon_handle h); +int clixon_plugin_start_all(clixon_handle h); -int clixon_plugin_auth_all(clicon_handle h, void *req, clixon_auth_type_t auth_type, char **authp); +int clixon_plugin_auth_all(clixon_handle h, void *req, clixon_auth_type_t auth_type, char **authp); -int clixon_plugin_extension_one(clixon_plugin_t *cp, clicon_handle h, yang_stmt *yext, yang_stmt *ys); -int clixon_plugin_extension_all(clicon_handle h, yang_stmt *yext, yang_stmt *ys); +int clixon_plugin_extension_one(clixon_plugin_t *cp, clixon_handle h, yang_stmt *yext, yang_stmt *ys); +int clixon_plugin_extension_all(clixon_handle h, yang_stmt *yext, yang_stmt *ys); -int clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, clicon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd); -int clixon_plugin_datastore_upgrade_all(clicon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd); +int clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, clixon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd); +int clixon_plugin_datastore_upgrade_all(clixon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd); -int clixon_plugin_yang_mount_one(clixon_plugin_t *cp, clicon_handle h, cxobj *xt, int *config, validate_level *vl, cxobj **yanglib); -int clixon_plugin_yang_mount_all(clicon_handle h, cxobj *xt, int *config, validate_level *vl, cxobj **yanglib); +int clixon_plugin_yang_mount_one(clixon_plugin_t *cp, clixon_handle h, cxobj *xt, int *config, validate_level *vl, cxobj **yanglib); +int clixon_plugin_yang_mount_all(clixon_handle h, cxobj *xt, int *config, validate_level *vl, cxobj **yanglib); -int clixon_plugin_yang_patch_one(clixon_plugin_t *cp, clicon_handle h, yang_stmt *ymod); -int clixon_plugin_yang_patch_all(clicon_handle h, yang_stmt *ymod); +int clixon_plugin_yang_patch_one(clixon_plugin_t *cp, clixon_handle h, yang_stmt *ymod); +int clixon_plugin_yang_patch_all(clixon_handle h, yang_stmt *ymod); -int clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp, clicon_handle h, cxobj *xerr, cbuf *cberr); -int clixon_plugin_netconf_errmsg_all(clicon_handle h, cxobj *xerr, cbuf *cberr); +int clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp, clixon_handle h, cxobj *xerr, cbuf *cberr); +int clixon_plugin_netconf_errmsg_all(clixon_handle h, cxobj *xerr, cbuf *cberr); -int clixon_plugin_version_one(clixon_plugin_t *cp, clicon_handle h, FILE *f); -int clixon_plugin_version_all(clicon_handle h, FILE *f); +int clixon_plugin_version_one(clixon_plugin_t *cp, clixon_handle h, FILE *f); +int clixon_plugin_version_all(clixon_handle h, FILE *f); /* rpc callback API */ -int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, const char *ns, const char *name); -int rpc_callback_call(clicon_handle h, cxobj *xe, void *arg, int *nrp, cbuf *cbret); +int rpc_callback_register(clixon_handle h, clicon_rpc_cb cb, void *arg, const char *ns, const char *name); +int rpc_callback_call(clixon_handle h, cxobj *xe, void *arg, int *nrp, cbuf *cbret); /* action callback API */ -int action_callback_register(clicon_handle h, yang_stmt *ya, clicon_rpc_cb cb, void *arg); -int action_callback_call(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); +int action_callback_register(clixon_handle h, yang_stmt *ya, clicon_rpc_cb cb, void *arg); +int action_callback_call(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg); /* upgrade callback API */ -int upgrade_callback_reg_fn(clicon_handle h, clicon_upgrade_cb cb, const char *strfn, const char *ns, void *arg); -int upgrade_callback_call(clicon_handle h, cxobj *xt, char *ns, uint16_t op, uint32_t from, uint32_t to, cbuf *cbret); +int upgrade_callback_reg_fn(clixon_handle h, clicon_upgrade_cb cb, const char *strfn, const char *ns, void *arg); +int upgrade_callback_call(clixon_handle h, cxobj *xt, char *ns, uint16_t op, uint32_t from, uint32_t to, cbuf *cbret); const int clixon_auth_type_str2int(char *auth_type); const char *clixon_auth_type_int2str(clixon_auth_type_t auth_type); -int clixon_plugin_module_init(clicon_handle h); -int clixon_plugin_module_exit(clicon_handle h); +int clixon_plugin_module_init(clixon_handle h); +int clixon_plugin_module_exit(clixon_handle h); #endif /* _CLIXON_PLUGIN_H_ */ diff --git a/lib/clixon/clixon_proc.h b/lib/clixon/clixon_proc.h index 0149a972..99bfc33f 100644 --- a/lib/clixon/clixon_proc.h +++ b/lib/clixon/clixon_proc.h @@ -58,23 +58,23 @@ typedef enum proc_operation { * @param[in] pe Process entry * @param[in,out] op Process operation */ -typedef int (proc_cb_t)(clicon_handle h, +typedef int (proc_cb_t)(clixon_handle h, process_entry_t *pe, proc_operation *operation); /* * Prototypes */ -int clixon_proc_socket(char **argv, int sock_flags, pid_t *pid, int *sock); +int clixon_proc_socket(clixon_handle h, char **argv, int sock_flags, pid_t *pid, int *sock); int clixon_proc_socket_close(pid_t pid, int sock); -int clixon_process_pid(clicon_handle h, const char *name, pid_t *pid); +int clixon_process_pid(clixon_handle h, const char *name, pid_t *pid); proc_operation clixon_process_op_str2int(char *opstr); -int clixon_process_argv_get(clicon_handle h, const char *name, char ***argv, int *argc); -int clixon_process_register(clicon_handle h, const char *name, const char *descr, const char *netns, uid_t uid, gid_t gid, int fdkeep, proc_cb_t *callback, char **argv, int argc); -int clixon_process_delete_all(clicon_handle h); -int clixon_process_operation(clicon_handle h, const char *name, proc_operation op, const int wrapit); -int clixon_process_status(clicon_handle h, const char *name, cbuf *cbret); -int clixon_process_start_all(clicon_handle h); -int clixon_process_waitpid(clicon_handle h); +int clixon_process_argv_get(clixon_handle h, const char *name, char ***argv, int *argc); +int clixon_process_register(clixon_handle h, const char *name, const char *descr, const char *netns, uid_t uid, gid_t gid, int fdkeep, proc_cb_t *callback, char **argv, int argc); +int clixon_process_delete_all(clixon_handle h); +int clixon_process_operation(clixon_handle h, const char *name, proc_operation op, const int wrapit); +int clixon_process_status(clixon_handle h, const char *name, cbuf *cbret); +int clixon_process_start_all(clixon_handle h); +int clixon_process_waitpid(clixon_handle h); #endif /* _CLIXON_PROC_H_ */ diff --git a/lib/clixon/clixon_proto.h b/lib/clixon/clixon_proto.h index 8f975b1b..7c1c1dd5 100644 --- a/lib/clixon/clixon_proto.h +++ b/lib/clixon/clixon_proto.h @@ -60,14 +60,14 @@ enum format_enum format_str2int(char *str); struct clicon_msg *clicon_msg_encode(uint32_t id, const char *format, ...) __attribute__ ((format (printf, 2, 3))); int clicon_msg_decode(struct clicon_msg *msg, yang_stmt *yspec, uint32_t *id, cxobj **xml, cxobj **xerr); -int clicon_connect_unix(clicon_handle h, char *sockpath); +int clicon_connect_unix(clixon_handle h, char *sockpath); -int clicon_rpc_connect_unix(clicon_handle h, +int clicon_rpc_connect_unix(clixon_handle h, char *sockpath, int *sock0); -int clicon_rpc_connect_inet(clicon_handle h, +int clicon_rpc_connect_inet(clixon_handle h, char *dst, uint16_t port, int *sock0); @@ -84,7 +84,7 @@ int clicon_msg_rcv(int s, const char *descr, int intr, struct clicon_msg **msg, int clicon_msg_rcv1(int s, const char *descr, cbuf *cb, int *eof); -int send_msg_notify_xml(clicon_handle h, int s, const char *descr, cxobj *xev); +int send_msg_notify_xml(clixon_handle h, int s, const char *descr, cxobj *xev); int send_msg_reply(int s, const char *descr, char *data, uint32_t datalen); diff --git a/lib/clixon/clixon_proto_client.h b/lib/clixon/clixon_proto_client.h index bf2fdf6f..2e89aaea 100644 --- a/lib/clixon/clixon_proto_client.h +++ b/lib/clixon/clixon_proto_client.h @@ -42,34 +42,34 @@ #ifndef _CLIXON_PROTO_CLIENT_H_ #define _CLIXON_PROTO_CLIENT_H_ -int clicon_rpc_connect(clicon_handle h, int *sock0); -int clicon_rpc_msg(clicon_handle h, struct clicon_msg *msg, cxobj **xret0); -int clicon_rpc_msg_persistent(clicon_handle h, struct clicon_msg *msg, cxobj **xret0, int *sock0); -int clicon_rpc_netconf(clicon_handle h, char *xmlst, cxobj **xret, int *sp); -int clicon_rpc_netconf_xml(clicon_handle h, cxobj *xml, cxobj **xret, int *sp); -int clicon_rpc_get_config(clicon_handle h, char *username, char *db, char *xpath, cvec *nsc, char *defaults, cxobj **xret); -int clicon_rpc_edit_config(clicon_handle h, char *db, enum operation_type op, +int clicon_rpc_connect(clixon_handle h, int *sock0); +int clicon_rpc_msg(clixon_handle h, struct clicon_msg *msg, cxobj **xret0); +int clicon_rpc_msg_persistent(clixon_handle h, struct clicon_msg *msg, cxobj **xret0, int *sock0); +int clicon_rpc_netconf(clixon_handle h, char *xmlst, cxobj **xret, int *sp); +int clicon_rpc_netconf_xml(clixon_handle h, cxobj *xml, cxobj **xret, int *sp); +int clicon_rpc_get_config(clixon_handle h, char *username, char *db, char *xpath, cvec *nsc, char *defaults, cxobj **xret); +int clicon_rpc_edit_config(clixon_handle h, char *db, enum operation_type op, char *xml); -int clicon_rpc_copy_config(clicon_handle h, char *db1, char *db2); -int clicon_rpc_delete_config(clicon_handle h, char *db); -int clicon_rpc_lock(clicon_handle h, char *db); -int clicon_rpc_unlock(clicon_handle h, char *db); -int clicon_rpc_get2(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, int bind, cxobj **xret); -int clicon_rpc_get(clicon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, cxobj **xret); -int clicon_rpc_get_pageable_list(clicon_handle h, char *datastore, char *xpath, +int clicon_rpc_copy_config(clixon_handle h, char *db1, char *db2); +int clicon_rpc_delete_config(clixon_handle h, char *db); +int clicon_rpc_lock(clixon_handle h, char *db); +int clicon_rpc_unlock(clixon_handle h, char *db); +int clicon_rpc_get2(clixon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, int bind, cxobj **xret); +int clicon_rpc_get(clixon_handle h, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, cxobj **xret); +int clicon_rpc_get_pageable_list(clixon_handle h, char *datastore, char *xpath, cvec *nsc, netconf_content content, int32_t depth, char *defaults, uint32_t offset, uint32_t limit, char *direction, char *sort, char *where, cxobj **xt); -int clicon_rpc_close_session(clicon_handle h); -int clicon_rpc_kill_session(clicon_handle h, uint32_t session_id); -int clicon_rpc_validate(clicon_handle h, char *db); -int clicon_rpc_commit(clicon_handle h, int confirmed, int cancel, uint32_t timeout, char *persist, char *persist_id); -int clicon_rpc_discard_changes(clicon_handle h); -int clicon_rpc_create_subscription(clicon_handle h, char *stream, char *filter, int *s); -int clicon_rpc_debug(clicon_handle h, int level); -int clicon_rpc_restconf_debug(clicon_handle h, int level); -int clicon_hello_req(clicon_handle h, char *transport, char *source_host, uint32_t *id); -int clicon_rpc_restart_plugin(clicon_handle h, char *plugin); +int clicon_rpc_close_session(clixon_handle h); +int clicon_rpc_kill_session(clixon_handle h, uint32_t session_id); +int clicon_rpc_validate(clixon_handle h, char *db); +int clicon_rpc_commit(clixon_handle h, int confirmed, int cancel, uint32_t timeout, char *persist, char *persist_id); +int clicon_rpc_discard_changes(clixon_handle h); +int clicon_rpc_create_subscription(clixon_handle h, char *stream, char *filter, int *s); +int clicon_rpc_debug(clixon_handle h, int level); +int clicon_rpc_restconf_debug(clixon_handle h, int level); +int clicon_hello_req(clixon_handle h, char *transport, char *source_host, uint32_t *id); +int clicon_rpc_restart_plugin(clixon_handle h, char *plugin); #endif /* _CLIXON_PROTO_CLIENT_H_ */ diff --git a/lib/clixon/clixon_regex.h b/lib/clixon/clixon_regex.h index eb105261..8fce7363 100644 --- a/lib/clixon/clixon_regex.h +++ b/lib/clixon/clixon_regex.h @@ -42,8 +42,8 @@ * Prototypes */ int regexp_xsd2posix(char *xsd, char **posix); -int regex_compile(clicon_handle h, char *regexp, void **recomp); -int regex_exec(clicon_handle h, void *recomp, char *string); -int regex_free(clicon_handle h, void *recomp); +int regex_compile(clixon_handle h, char *regexp, void **recomp); +int regex_exec(clixon_handle h, void *recomp, char *string); +int regex_free(clixon_handle h, void *recomp); #endif /* _CLIXON_REGEX_H_ */ diff --git a/lib/clixon/clixon_stream.h b/lib/clixon/clixon_stream.h index 9aab1963..b5d125e0 100644 --- a/lib/clixon/clixon_stream.h +++ b/lib/clixon/clixon_stream.h @@ -53,7 +53,7 @@ * @param[in] arg Extra argument provided in stream_ss_add * @see stream_ss_add */ -typedef int (*stream_fn_t)(clicon_handle h, int op, cxobj *event, void *arg); +typedef int (*stream_fn_t)(clixon_handle h, int op, cxobj *event, void *arg); struct stream_subscription{ qelem_t ss_q; /* queue header */ @@ -89,30 +89,30 @@ typedef struct event_stream event_stream_t; /* * Prototypes */ -event_stream_t *stream_find(clicon_handle h, const char *name); -int stream_add(clicon_handle h, const char *name, const char *description, int replay_enabled, struct timeval *retention); -int stream_delete_all(clicon_handle h, int force); -int stream_get_xml(clicon_handle h, int access, cbuf *cb); +event_stream_t *stream_find(clixon_handle h, const char *name); +int stream_add(clixon_handle h, const char *name, const char *description, int replay_enabled, struct timeval *retention); +int stream_delete_all(clixon_handle h, int force); +int stream_get_xml(clixon_handle h, int access, cbuf *cb); int stream_timer_setup(int fd, void *arg); /* Subscriptions */ -struct stream_subscription *stream_ss_add(clicon_handle h, char *stream, +struct stream_subscription *stream_ss_add(clixon_handle h, char *stream, char *xpath, struct timeval *start, struct timeval *stop, stream_fn_t fn, void *arg); -int stream_ss_rm(clicon_handle h, event_stream_t *es, struct stream_subscription *ss, int force); +int stream_ss_rm(clixon_handle h, event_stream_t *es, struct stream_subscription *ss, int force); struct stream_subscription *stream_ss_find(event_stream_t *es, stream_fn_t fn, void *arg); -int stream_ss_delete_all(clicon_handle h, stream_fn_t fn, void *arg); -int stream_ss_delete(clicon_handle h, char *name, stream_fn_t fn, void *arg); +int stream_ss_delete_all(clixon_handle h, stream_fn_t fn, void *arg); +int stream_ss_delete(clixon_handle h, char *name, stream_fn_t fn, void *arg); -int stream_notify_xml(clicon_handle h, char *stream, cxobj *xml); -int stream_notify(clicon_handle h, char *stream, const char *event, ...) __attribute__ ((format (printf, 3, 4))); +int stream_notify_xml(clixon_handle h, char *stream, cxobj *xml); +int stream_notify(clixon_handle h, char *stream, const char *event, ...) __attribute__ ((format (printf, 3, 4))); /* Replay */ int stream_replay_add(event_stream_t *es, struct timeval *tv, cxobj *xv); -int stream_replay_trigger(clicon_handle h, char *stream, stream_fn_t fn, void *arg); +int stream_replay_trigger(clixon_handle h, char *stream, stream_fn_t fn, void *arg); /* Experimental publish streams using SSE. CLIXON_PUBLISH_STREAMS should be set */ -int stream_publish(clicon_handle h, char *stream); +int stream_publish(clixon_handle h, char *stream); int stream_publish_init(); int stream_publish_exit(); diff --git a/lib/clixon/clixon_validate.h b/lib/clixon/clixon_validate.h index 0f6483cc..5e660ba3 100644 --- a/lib/clixon/clixon_validate.h +++ b/lib/clixon/clixon_validate.h @@ -43,12 +43,12 @@ /* * Prototypes */ -int xml_yang_validate_rpc(clicon_handle h, cxobj *xrpc, int expanddefault, cxobj **xret); -int xml_yang_validate_rpc_reply(clicon_handle h, cxobj *xrpc, cxobj **xret); -int xml_yang_validate_add(clicon_handle h, cxobj *xt, cxobj **xret); +int xml_yang_validate_rpc(clixon_handle h, cxobj *xrpc, int expanddefault, cxobj **xret); +int xml_yang_validate_rpc_reply(clixon_handle h, cxobj *xrpc, cxobj **xret); +int xml_yang_validate_add(clixon_handle h, cxobj *xt, cxobj **xret); int xml_yang_validate_list_key_only(cxobj *xt, cxobj **xret); -int xml_yang_validate_all(clicon_handle h, cxobj *xt, cxobj **xret); -int xml_yang_validate_all_top(clicon_handle h, cxobj *xt, cxobj **xret); -int rpc_reply_check(clicon_handle h, char *rpcname, cbuf *cbret); +int xml_yang_validate_all(clixon_handle h, cxobj *xt, cxobj **xret); +int xml_yang_validate_all_top(clixon_handle h, cxobj *xt, cxobj **xret); +int rpc_reply_check(clixon_handle h, char *rpcname, cbuf *cbret); #endif /* _CLIXON_VALIDATE_H_ */ diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 71417713..073afb2d 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -39,6 +39,7 @@ * Canonical XML version (just for info) * https://www.w3.org/TR/xml-c14n */ + #ifndef _CLIXON_XML_H #define _CLIXON_XML_H @@ -306,12 +307,11 @@ int xml_operation(char *opstr, enum operation_type *op); char *xml_operation2str(enum operation_type op); int xml_attr_insert2val(char *instr, enum insert_type *ins); cxobj *xml_add_attr(cxobj *xn, char *name, char *value, char *prefix, char *ns); -int clicon_log_xml(int level, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 3, 4))); +int clixon_log_xml(clixon_handle h, int level, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 4, 5))); int clixon_debug_xml(int dbglevel, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 3, 4))); #ifdef XML_EXPLICIT_INDEX int xml_search_index_p(cxobj *x); - int xml_search_vector_get(cxobj *x, char *name, clixon_xvec **xvec); int xml_search_child_insert(cxobj *xp, cxobj *x); int xml_search_child_rm(cxobj *xp, cxobj *x); @@ -319,9 +319,4 @@ cxobj *xml_child_index_each(cxobj *xparent, char *name, cxobj *xprev, enum cx #endif -/* 6.4 backward compatability */ -#if 1 -#define clicon_debug_xml clixon_debug_xml -#endif - #endif /* _CLIXON_XML_H */ diff --git a/lib/clixon/clixon_xml_bind.h b/lib/clixon/clixon_xml_bind.h index 02b4c8cb..9b02c96a 100644 --- a/lib/clixon/clixon_xml_bind.h +++ b/lib/clixon/clixon_xml_bind.h @@ -45,10 +45,10 @@ */ int xml_bind_yang_unknown_anydata(int val); int xml_bind_netconf_message_id_optional(int val); -int xml_bind_yang_rpc(clicon_handle h, cxobj *xrpc, yang_stmt *yspec, cxobj **xerr); -int xml_bind_yang_rpc_reply(clicon_handle h, cxobj *xrpc, char *name, yang_stmt *yspec, cxobj **xerr); -int xml_bind_yang0(clicon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); -int xml_bind_yang(clicon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang_rpc(clixon_handle h, cxobj *xrpc, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang_rpc_reply(clixon_handle h, cxobj *xrpc, char *name, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang0(clixon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); +int xml_bind_yang(clixon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, cxobj **xerr); int xml_bind_special(cxobj *xd, yang_stmt *yspec, char *schema_nodeid); #endif /* _CLIXON_XML_BIND_H_ */ diff --git a/lib/clixon/clixon_xml_changelog.h b/lib/clixon/clixon_xml_changelog.h index 3b4ae91d..d9137cd8 100644 --- a/lib/clixon/clixon_xml_changelog.h +++ b/lib/clixon/clixon_xml_changelog.h @@ -41,8 +41,8 @@ /* * Prototypes */ -int xml_changelog_upgrade(clicon_handle h, cxobj *xn, char *ns, uint16_t op, uint32_t from, uint32_t to, void *arg, cbuf *cbret); -int clixon_xml_changelog_init(clicon_handle h); -int xml_namespace_vec(clicon_handle h, cxobj *xt, char *ns, cxobj ***vec, size_t *veclen); +int xml_changelog_upgrade(clixon_handle h, cxobj *xn, char *ns, uint16_t op, uint32_t from, uint32_t to, void *arg, cbuf *cbret); +int clixon_xml_changelog_init(clixon_handle h); +int xml_namespace_vec(clixon_handle h, cxobj *xt, char *ns, cxobj ***vec, size_t *veclen); #endif /* _CLIXON_XML_CHANGELOG_H */ diff --git a/lib/clixon/clixon_xml_default.h b/lib/clixon/clixon_xml_default.h index eed447c9..00f5f4fb 100644 --- a/lib/clixon/clixon_xml_default.h +++ b/lib/clixon/clixon_xml_default.h @@ -50,7 +50,7 @@ typedef enum yang_class yang_class; * Prototypes */ int xml_default_recurse(cxobj *xn, int state); -int xml_global_defaults(clicon_handle h, cxobj *xn, cvec *nsc, const char *xpath, yang_stmt *yspec, int state); +int xml_global_defaults(clixon_handle h, cxobj *xn, cvec *nsc, const char *xpath, yang_stmt *yspec, int state); int xml_defaults_nopresence(cxobj *xn, int purge); int xml_add_default_tag(cxobj *x, uint16_t flags); int xml_flag_state_default_value(cxobj *x, uint16_t flag); diff --git a/lib/clixon/clixon_xml_nsctx.h b/lib/clixon/clixon_xml_nsctx.h index f40d3b63..8e69e96a 100644 --- a/lib/clixon/clixon_xml_nsctx.h +++ b/lib/clixon/clixon_xml_nsctx.h @@ -50,7 +50,7 @@ /* * Prototypes */ -int xml_nsctx_namespace_netconf_default(clicon_handle h); +int xml_nsctx_namespace_netconf_default(clixon_handle h); cvec *xml_nsctx_init(char *prefix, char *ns); int xml_nsctx_free(cvec *nsc); char *xml_nsctx_get(cvec *nsc, char *prefix); diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index b48ea23a..da1b31da 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -311,7 +311,7 @@ int yang_abs_schema_nodeid(yang_stmt *ys, char *schema_nodeid, yang_stmt int yang_desc_schema_nodeid(yang_stmt *yn, char *schema_nodeid, yang_stmt **yres); int yang_config(yang_stmt *ys); int yang_config_ancestor(yang_stmt *ys); -int yang_features(clicon_handle h, yang_stmt *yt); +int yang_features(clixon_handle h, yang_stmt *yt); cvec *yang_arg2cvec(yang_stmt *ys, char *delimi); int yang_key_match(yang_stmt *yn, char *name, int *lastkey); int yang_type_cache_regexp_set(yang_stmt *ytype, int rxmode, cvec *regexps); @@ -322,10 +322,10 @@ int yang_type_cache_set(yang_stmt *ys, yang_stmt *resolved, int options, yang_stmt *yang_anydata_add(yang_stmt *yp, char *name); int yang_extension_value(yang_stmt *ys, char *name, char *ns, int *exist, char **value); int yang_sort_subelements(yang_stmt *ys); -int yang_init(clicon_handle h); +int yang_init(clixon_handle h); int yang_single_child_type(yang_stmt *ys, enum rfc_6020 subkeyw); void *yang_action_cb_get(yang_stmt *ys); int yang_action_cb_add(yang_stmt *ys, void *rc); -int ys_populate_feature(clicon_handle h, yang_stmt *ys); +int ys_populate_feature(clixon_handle h, yang_stmt *ys); #endif /* _CLIXON_YANG_H_ */ diff --git a/lib/clixon/clixon_yang_module.h b/lib/clixon/clixon_yang_module.h index 22ceab2b..e55e14b6 100644 --- a/lib/clixon/clixon_yang_module.h +++ b/lib/clixon/clixon_yang_module.h @@ -65,12 +65,12 @@ typedef struct { modstate_diff_t * modstate_diff_new(void); int modstate_diff_free(modstate_diff_t *); -int yang_modules_init(clicon_handle h); -char *yang_modules_revision(clicon_handle h); -int yang_modules_state_build(clicon_handle h, yang_stmt *yspec, char *msid, int brief, cbuf *cb); -int yang_modules_state_get(clicon_handle h, yang_stmt *yspec, char *xpath, +int yang_modules_init(clixon_handle h); +char *yang_modules_revision(clixon_handle h); +int yang_modules_state_build(clixon_handle h, yang_stmt *yspec, char *msid, int brief, cbuf *cb); +int yang_modules_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, int brief, cxobj **xret); -int clixon_module_upgrade(clicon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb); +int clixon_module_upgrade(clixon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb); yang_stmt *yang_find_module_by_prefix(yang_stmt *ys, char *prefix); yang_stmt *yang_find_module_by_prefix_yspec(yang_stmt *yspec, char *prefix); yang_stmt *yang_find_module_by_namespace(yang_stmt *yspec, char *ns); @@ -78,7 +78,7 @@ yang_stmt *yang_find_module_by_namespace_revision(yang_stmt *yspec, const char * yang_stmt *yang_find_module_by_name_revision(yang_stmt *yspec, const char *name, const char *revision); yang_stmt *yang_find_module_by_name(yang_stmt *yspec, char *name); int yang_metadata_annotation_check(cxobj *x, yang_stmt *ymod, int *ismeta); -int yang_metadata_init(clicon_handle h); -int yang_lib2yspec(clicon_handle h, cxobj *yanglib,yang_stmt *yspec); +int yang_metadata_init(clixon_handle h); +int yang_lib2yspec(clixon_handle h, cxobj *yanglib,yang_stmt *yspec); #endif /* _CLIXON_YANG_MODULE_H_ */ diff --git a/lib/clixon/clixon_yang_parse_lib.h b/lib/clixon/clixon_yang_parse_lib.h index 335f839a..3b7de9b9 100644 --- a/lib/clixon/clixon_yang_parse_lib.h +++ b/lib/clixon/clixon_yang_parse_lib.h @@ -53,15 +53,15 @@ */ int ys_grouping_resolve(yang_stmt *yuses, char *prefix, char *name, yang_stmt **ygrouping0); yang_stmt *yang_parse_file(FILE *fp, const char *name, yang_stmt *ysp); -int yang_file_find_match(clicon_handle h, const char *module, const char *revision, cbuf *fbuf); -yang_stmt *yang_parse_filename(clicon_handle h, const char *filename, yang_stmt *ysp); -yang_stmt *yang_parse_module(clicon_handle h, const char *module, const char *revision, yang_stmt *yspec, char *origname); -int yang_parse_post(clicon_handle h, yang_stmt *yspec, int modmin); -int yang_spec_parse_module(clicon_handle h, const char *module, +int yang_file_find_match(clixon_handle h, const char *module, const char *revision, cbuf *fbuf); +yang_stmt *yang_parse_filename(clixon_handle h, const char *filename, yang_stmt *ysp); +yang_stmt *yang_parse_module(clixon_handle h, const char *module, const char *revision, yang_stmt *yspec, char *origname); +int yang_parse_post(clixon_handle h, yang_stmt *yspec, int modmin); +int yang_spec_parse_module(clixon_handle h, const char *module, const char *revision, yang_stmt *yspec); yang_stmt *yang_parse_str(char *str, const char *name, yang_stmt *yspec); -int yang_spec_parse_file(clicon_handle h, char *filename, yang_stmt *yspec); -int yang_spec_load_dir(clicon_handle h, char *dir, yang_stmt *yspec); +int yang_spec_parse_file(clixon_handle h, char *filename, yang_stmt *yspec); +int yang_spec_load_dir(clixon_handle h, char *dir, yang_stmt *yspec); int ys_parse_date_arg(char *datearg, uint32_t *dateint); cg_var *ys_parse(yang_stmt *ys, enum cv_type cvtype); int ys_parse_sub(yang_stmt *ys, const char *filename, char *extra); diff --git a/lib/clixon/clixon_yang_schema_mount.h b/lib/clixon/clixon_yang_schema_mount.h index 2568be45..4020abc6 100644 --- a/lib/clixon/clixon_yang_schema_mount.h +++ b/lib/clixon/clixon_yang_schema_mount.h @@ -58,13 +58,13 @@ int yang_schema_mount_point0(yang_stmt *y); int yang_schema_mount_point(yang_stmt *y); int yang_mount_get(yang_stmt *yu, char *xpath, yang_stmt **yspec); int yang_mount_set(yang_stmt *yu, char *xpath, yang_stmt *yspec); -int xml_yang_mount_get(clicon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec); -int xml_yang_mount_set(clicon_handle h, cxobj *x, yang_stmt *yspec); +int xml_yang_mount_get(clixon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec); +int xml_yang_mount_set(clixon_handle h, cxobj *x, yang_stmt *yspec); int yang_mount_get_yspec_any(yang_stmt *y, yang_stmt **yspec); int yang_mount_freeall(cvec *cvv); -int yang_schema_mount_statedata(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); -int yang_schema_mount_statistics(clicon_handle h, cxobj *xt, int modules, cbuf *cb); -int yang_schema_yanglib_parse_mount(clicon_handle h, cxobj *xt); -int yang_schema_get_child(clicon_handle h, cxobj *x1, cxobj *x1c, yang_stmt **yc); +int yang_schema_mount_statedata(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr); +int yang_schema_mount_statistics(clixon_handle h, cxobj *xt, int modules, cbuf *cb); +int yang_schema_yanglib_parse_mount(clixon_handle h, cxobj *xt); +int yang_schema_get_child(clixon_handle h, cxobj *x1, cxobj *x1c, yang_stmt **yc); #endif /* _CLIXON_YANG_SCHEMA_MOUNT_H_ */ diff --git a/lib/clixon/clixon_yang_type.h b/lib/clixon/clixon_yang_type.h index 7f8154b4..05d65399 100644 --- a/lib/clixon/clixon_yang_type.h +++ b/lib/clixon/clixon_yang_type.h @@ -60,7 +60,7 @@ int yang2cv_type(char *ytype, enum cv_type *cv_type); char *cv2yang_type(enum cv_type cv_type); yang_stmt *yang_find_identity(yang_stmt *ys, char *identity); yang_stmt *yang_find_identity_nsc(yang_stmt *yspec, char *identity, cvec *nsc); -int ys_cv_validate(clicon_handle h, cg_var *cv, yang_stmt *ys, yang_stmt **ysub, char **reason); +int ys_cv_validate(clixon_handle h, cg_var *cv, yang_stmt *ys, yang_stmt **ysub, char **reason); int clicon_type2cv(char *type, char *rtype, yang_stmt *ys, enum cv_type *cvtype); int yang_type_get(yang_stmt *ys, char **otype, yang_stmt **restype, int *options, cvec **cvv, diff --git a/lib/src/Makefile.in b/lib/src/Makefile.in index f1dc2962..66acdab1 100644 --- a/lib/src/Makefile.in +++ b/lib/src/Makefile.in @@ -78,7 +78,7 @@ CPPFLAGS = @CPPFLAGS@ INCLUDES = -I. @INCLUDES@ -I$(top_srcdir)/lib/clixon -I$(top_srcdir)/include -I$(top_srcdir) -SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_err.c clixon_event.c \ +SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_debug.c clixon_err.c clixon_event.c \ clixon_string.c clixon_regex.c clixon_handle.c clixon_file.c \ clixon_xml.c clixon_xml_io.c clixon_xml_sort.c clixon_xml_map.c clixon_xml_vec.c \ clixon_xml_default.c clixon_xml_bind.c clixon_json.c clixon_proc.c \ diff --git a/lib/src/clixon_api_path_parse.l b/lib/src/clixon_api_path_parse.l index de78e57b..473f915c 100644 --- a/lib/src/clixon_api_path_parse.l +++ b/lib/src/clixon_api_path_parse.l @@ -68,6 +68,7 @@ #include "clixon_handle.h" #include "clixon_yang.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_string.h" #include "clixon_xml.h" #include "clixon_path.h" diff --git a/lib/src/clixon_api_path_parse.y b/lib/src/clixon_api_path_parse.y index c45af879..053128db 100644 --- a/lib/src/clixon_api_path_parse.y +++ b/lib/src/clixon_api_path_parse.y @@ -83,7 +83,7 @@ /* typecast macro */ #define _AY ((clixon_api_path_yacc *)_ay) -#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_api_path_parsetext, _AY->ay_linenum); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_api_path_parsetext, _AY->ay_linenum); YYERROR;} /* add _yy to error parameters */ #define YY_(msgid) msgid @@ -103,12 +103,14 @@ #include -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_string.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_path.h" @@ -133,7 +135,7 @@ void clixon_api_path_parseerror(void *_ay, char *s) { - clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", + clixon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", _AY->ay_name, _AY->ay_linenum, s, @@ -186,17 +188,17 @@ path_new(char *module_name, clixon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, module_name, id); if ((cp = malloc(sizeof(*cp))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(cp, 0, sizeof(*cp)); if (module_name) if ((cp->cp_prefix = strdup(module_name)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if ((cp->cp_id = strdup(id)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } return cp; @@ -220,11 +222,11 @@ keyval_add(cvec *cvv, goto done; if (cvv == NULL && (cvv = cvec_new(0)) == NULL) { - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (cvec_append_var(cvv, cv) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_append_var"); + clixon_err(OE_UNIX, errno, "cvec_append_var"); cvv = NULL; goto done; } @@ -243,16 +245,16 @@ keyval_set(char *name, clixon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name?name:"NULL", val); if ((cv = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_UNIX, errno, "cv_new"); + clixon_err(OE_UNIX, errno, "cv_new"); goto done; } if (name && cv_name_set(cv, name) == NULL){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); cv = NULL; goto done; } if (cv_string_set(cv, val) == NULL){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); cv = NULL; goto done; } diff --git a/lib/src/clixon_client.c b/lib/src/clixon_client.c index 3134c342..c6c089e3 100644 --- a/lib/src/clixon_client.c +++ b/lib/src/clixon_client.c @@ -54,6 +54,7 @@ #include "clixon_hash.h" #include "clixon_handle.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_err.h" #include "clixon_yang.h" #include "clixon_options.h" @@ -84,7 +85,7 @@ */ struct clixon_client_handle{ uint32_t cch_magic; /* magic number */ - clicon_handle cch_h; /* Clixon handle */ + clixon_handle cch_h; /* Clixon handle */ clixon_client_type cch_type; /* Clixon socket type */ int cch_socket; /* Input/output socket */ char *cch_descr; /* Description of socket / peer for logging XXX NYI */ @@ -117,11 +118,11 @@ clixon_client_handle_check(clixon_client_handle ch) clixon_handle clixon_client_init(const char *config_file) { - clicon_handle h; + clixon_handle h; clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); /* Initiate CLICON handle. CLIgen is also initialized */ - if ((h = clicon_handle_init()) == NULL) + if ((h = clixon_handle_init()) == NULL) return NULL; /* Set clixon config file - reuse the one in the main installation */ clicon_option_str_set(h, "CLICON_CONFIGFILE", @@ -138,10 +139,10 @@ clixon_client_init(const char *config_file) * @see clixon_client_init */ int -clixon_client_terminate(clicon_handle h) +clixon_client_terminate(clixon_handle h) { clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); - clicon_handle_exit(h); + clixon_handle_exit(h); return 0; } @@ -171,15 +172,15 @@ clixon_client_lock(clixon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (db == NULL){ - clicon_err(OE_XML, EINVAL, "Expected db"); + clixon_err(OE_XML, EINVAL, "Expected db"); goto done; } if ((msg = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } if ((msgret = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } cprintf(msg, "" @@ -191,14 +192,14 @@ clixon_client_lock(clixon_handle h, goto done; if (eof){ close(sock); - clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); + clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); goto done; } if (clixon_xml_parse_string(cbuf_get(msgret), YB_NONE, NULL, &xret, NULL) < 0) goto done; if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL){ xd = xml_parent(xd); /* point to rpc-reply */ - clixon_netconf_error(h, xd, "Get config", NULL); + clixon_err_netconf(h, OE_NETCONF, 0, xd, "Get configuration"); goto done; /* Not fatal */ } retval = 0; @@ -231,7 +232,7 @@ clixon_client_hello(int sock, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((msg = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } // cprintf(msg, "\n"); @@ -254,7 +255,7 @@ clixon_client_hello(int sock, /*! */ static int -clixon_client_connect_netconf(clicon_handle h, +clixon_client_connect_netconf(clixon_handle h, struct clixon_client_handle *cch) { int retval = -1; @@ -269,14 +270,14 @@ clixon_client_connect_netconf(clicon_handle h, if (clixon_debug_get() != 0) nr += 2; if ((argv = calloc(nr, sizeof(char *))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } i = 0; if ((netconf_bin = getenv("CLIXON_NETCONF_BIN")) == NULL) netconf_bin = CLIXON_NETCONF_BIN; if (stat(netconf_bin, &st) < 0){ - clicon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=", + clixon_err(OE_NETCONF, errno, "netconf binary %s. Set with CLIXON_NETCONF_BIN=", netconf_bin); goto done; } @@ -293,7 +294,7 @@ clixon_client_connect_netconf(clicon_handle h, } argv[i++] = NULL; assert(i==nr); - if (clixon_proc_socket(argv, SOCK_DGRAM, &cch->cch_pid, &cch->cch_socket) < 0){ + if (clixon_proc_socket(h, argv, SOCK_DGRAM, &cch->cch_pid, &cch->cch_socket) < 0){ goto done; } retval = 0; @@ -304,7 +305,7 @@ clixon_client_connect_netconf(clicon_handle h, /*! */ static int -clixon_client_connect_ssh(clicon_handle h, +clixon_client_connect_ssh(clixon_handle h, struct clixon_client_handle *cch, const char *dest) { @@ -318,12 +319,12 @@ clixon_client_connect_ssh(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); nr = 5; if ((argv = calloc(nr, sizeof(char *))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } i = 0; if (stat(ssh_bin, &st) < 0){ - clicon_err(OE_NETCONF, errno, "ssh binary %s", ssh_bin); + clixon_err(OE_NETCONF, errno, "ssh binary %s", ssh_bin); goto done; } argv[i++] = ssh_bin; @@ -334,7 +335,7 @@ clixon_client_connect_ssh(clicon_handle h, assert(i==nr); for (i=0;icch_pid, &cch->cch_socket) < 0){ + if (clixon_proc_socket(h, argv, SOCK_STREAM, &cch->cch_pid, &cch->cch_socket) < 0){ goto done; } retval = 0; @@ -352,7 +353,7 @@ clixon_client_connect_ssh(clicon_handle h, * @see clixon_client_disconnect Close the socket returned here */ clixon_client_handle -clixon_client_connect(clicon_handle h, +clixon_client_connect(clixon_handle h, clixon_client_type socktype, const char *dest) { @@ -361,7 +362,7 @@ clixon_client_connect(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((cch = malloc(sz)) == NULL){ - clicon_err(OE_NETCONF, errno, "malloc"); + clixon_err(OE_NETCONF, errno, "malloc"); goto done; } memset(cch, 0, sz); @@ -382,7 +383,7 @@ clixon_client_connect(clicon_handle h, if (clixon_client_connect_ssh(h, cch, dest) < 0) goto err; #else - clicon_err(OE_UNIX, 0, "No ssh bin"); + clixon_err(OE_UNIX, 0, "No ssh bin"); goto done; #endif break; @@ -413,7 +414,7 @@ clixon_client_disconnect(clixon_client_handle ch) clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (cch == NULL){ - clicon_err(OE_XML, EINVAL, "Expected cch handle"); + clixon_err(OE_XML, EINVAL, "Expected cch handle"); goto done; } /* unlock (if locked) */ @@ -484,7 +485,7 @@ clixon_xml_bottom(cxobj *xtop, * @note configurable netconf framing type, now hardwired to 0 */ static int -clixon_client_get_xdata(clicon_handle h, +clixon_client_get_xdata(clixon_handle h, int sock, const char *descr, const char *namespace, @@ -502,11 +503,11 @@ clixon_client_get_xdata(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((msg = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } if ((msgret = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } cprintf(msg, " -/* clicon */ -#include "clixon_err.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_sort.h" @@ -87,7 +88,7 @@ * @see clicon_option_str */ int -clicon_data_get(clicon_handle h, +clicon_data_get(clixon_handle h, const char *name, char **val) { @@ -110,7 +111,7 @@ clicon_data_get(clicon_handle h, * @see clicon_option_str_set */ int -clicon_data_set(clicon_handle h, +clicon_data_set(clixon_handle h, const char *name, char *val) { @@ -128,7 +129,7 @@ clicon_data_set(clicon_handle h, * @see clicon_option_del */ int -clicon_data_del(clicon_handle h, +clicon_data_del(clixon_handle h, const char *name) { clicon_hash_t *cdat = clicon_data(h); @@ -146,7 +147,7 @@ clicon_data_del(clicon_handle h, * @see clicon_option_str */ int -clicon_ptr_get(clicon_handle h, +clicon_ptr_get(clixon_handle h, const char *name, void **ptr) { @@ -173,7 +174,7 @@ clicon_ptr_get(clicon_handle h, * @see clicon_option_str_set */ int -clicon_ptr_set(clicon_handle h, +clicon_ptr_set(clixon_handle h, const char *name, void *ptr) { @@ -191,7 +192,7 @@ clicon_ptr_set(clicon_handle h, * @see clicon_option_del */ int -clicon_ptr_del(clicon_handle h, +clicon_ptr_del(clixon_handle h, const char *name) { clicon_hash_t *cdat = clicon_data(h); @@ -212,7 +213,7 @@ clicon_ptr_del(clicon_handle h, * @endcode */ cvec * -clicon_data_cvec_get(clicon_handle h, +clicon_data_cvec_get(clixon_handle h, const char *name) { cvec *cvv = NULL; @@ -229,7 +230,7 @@ clicon_data_cvec_get(clicon_handle h, * @param[in] cvv CLIgen variable vector (cvv) (malloced) */ int -clicon_data_cvec_set(clicon_handle h, +clicon_data_cvec_set(clixon_handle h, const char *name, cvec *cvv) { @@ -247,7 +248,7 @@ clicon_data_cvec_set(clicon_handle h, * @param[in] name Name */ int -clicon_data_cvec_del(clicon_handle h, +clicon_data_cvec_del(clixon_handle h, const char *name) { cvec *cvv = NULL; @@ -260,7 +261,7 @@ clicon_data_cvec_del(clicon_handle h, /*! Get data option as integer but store as string * - * @param[in] h clicon_handle + * @param[in] h clixon_handle * @param[in] name option name * @retval int An integer as a result of atoi * @retval -1 If option does not exist @@ -268,7 +269,7 @@ clicon_data_cvec_del(clicon_handle h, * @see clicon_option_int for values in clixon config file */ int -clicon_data_int_get(clicon_handle h, +clicon_data_int_get(clixon_handle h, const char *name) { clicon_hash_t *cdat = clicon_data(h); @@ -282,14 +283,14 @@ clicon_data_int_get(clicon_handle h, /*! Set a single string data via handle * - * @param[in] h clicon_handle + * @param[in] h clixon_handle * @param[in] name option name * @param[in] val option value, must be null-terminated string * @retval 0 OK * @retval -1 Error */ int -clicon_data_int_set(clicon_handle h, +clicon_data_int_set(clixon_handle h, const char *name, int val) { @@ -303,13 +304,13 @@ clicon_data_int_set(clicon_handle h, /*! Delete single int data via handle * - * @param[in] h clicon_handle + * @param[in] h clixon_handle * @param[in] name option name * @retval 0 OK * @retval -1 Error */ int -clicon_data_int_del(clicon_handle h, +clicon_data_int_del(clixon_handle h, const char *name) { clicon_hash_t *cdat = clicon_data(h); @@ -324,7 +325,7 @@ clicon_data_int_del(clicon_handle h, * @see clicon_config_yang for the configuration yang */ yang_stmt * -clicon_dbspec_yang(clicon_handle h) +clicon_dbspec_yang(clixon_handle h) { yang_stmt *ys = NULL; @@ -340,7 +341,7 @@ clicon_dbspec_yang(clicon_handle h) * @see clicon_config_yang_set for the configuration yang */ int -clicon_dbspec_yang_set(clicon_handle h, +clicon_dbspec_yang_set(clixon_handle h, yang_stmt *ys) { return clicon_ptr_set(h, "dbspec_yang", ys); @@ -353,7 +354,7 @@ clicon_dbspec_yang_set(clicon_handle h, * @see clicon_dbspec_yang for the application specs */ yang_stmt * -clicon_config_yang(clicon_handle h) +clicon_config_yang(clixon_handle h) { yang_stmt *ys = NULL; @@ -369,7 +370,7 @@ clicon_config_yang(clicon_handle h) * @see clicon_dbspec_yang_set for the application specs */ int -clicon_config_yang_set(clicon_handle h, +clicon_config_yang_set(clixon_handle h, yang_stmt *ys) { return clicon_ptr_set(h, "control_yang", ys); @@ -382,7 +383,7 @@ clicon_config_yang_set(clicon_handle h, * @see clicon_nacm_ext for external NACM XML */ yang_stmt * -clicon_nacm_ext_yang(clicon_handle h) +clicon_nacm_ext_yang(clixon_handle h) { yang_stmt *ys = NULL; @@ -398,7 +399,7 @@ clicon_nacm_ext_yang(clicon_handle h) * @see clicon_nacm_ext_set for external NACM XML */ int -clicon_nacm_ext_yang_set(clicon_handle h, +clicon_nacm_ext_yang_set(clixon_handle h, yang_stmt *ys) { return clicon_ptr_set(h, "nacm_ext_yang", ys); @@ -415,7 +416,7 @@ clicon_nacm_ext_yang_set(clicon_handle h, * @endcode */ cvec * -clicon_nsctx_global_get(clicon_handle h) +clicon_nsctx_global_get(clixon_handle h) { cvec *cvv = NULL; @@ -431,7 +432,7 @@ clicon_nsctx_global_get(clicon_handle h) * @param[in] nsctx Namespace context (malloced) */ int -clicon_nsctx_global_set(clicon_handle h, +clicon_nsctx_global_set(clixon_handle h, cvec *nsctx) { return clicon_ptr_set(h, "nsctx_global", nsctx); @@ -445,7 +446,7 @@ clicon_nsctx_global_set(clicon_handle h, * @see clicon_nacm_ext_set */ cxobj * -clicon_nacm_ext(clicon_handle h) +clicon_nacm_ext(clixon_handle h) { cxobj *x = NULL; @@ -462,7 +463,7 @@ clicon_nacm_ext(clicon_handle h) * @see clicon_nacm_ext */ int -clicon_nacm_ext_set(clicon_handle h, +clicon_nacm_ext_set(clixon_handle h, cxobj *x) { cxobj *x0 = NULL; @@ -480,7 +481,7 @@ clicon_nacm_ext_set(clicon_handle h, * @see from_client_msg */ cxobj * -clicon_nacm_cache(clicon_handle h) +clicon_nacm_cache(clixon_handle h) { cxobj *x = NULL; @@ -497,7 +498,7 @@ clicon_nacm_cache(clicon_handle h) * @see from_client_msg */ int -clicon_nacm_cache_set(clicon_handle h, +clicon_nacm_cache_set(clixon_handle h, cxobj *xn) { return clicon_ptr_set(h, "nacm_cache", xn); @@ -516,7 +517,7 @@ clicon_nacm_cache_set(clicon_handle h, * @endcode */ cxobj * -clicon_conf_xml(clicon_handle h) +clicon_conf_xml(clixon_handle h) { cxobj *x = NULL; @@ -530,7 +531,7 @@ clicon_conf_xml(clicon_handle h) * ys must be a malloced pointer */ int -clicon_conf_xml_set(clicon_handle h, +clicon_conf_xml_set(clixon_handle h, cxobj *x) { return clicon_ptr_set(h, "clixon_conf", x); @@ -548,7 +549,7 @@ clicon_conf_xml_set(clicon_handle h, * CLICON_BACKEND_RESTCONF_PROCESS is true */ cxobj * -clicon_conf_restconf(clicon_handle h) +clicon_conf_restconf(clixon_handle h) { cxobj *xconfig = NULL; @@ -567,7 +568,7 @@ clicon_conf_restconf(clicon_handle h) * @endcode */ cxobj * -clicon_conf_autocli(clicon_handle h) +clicon_conf_autocli(clixon_handle h) { cxobj *xconfig = NULL; @@ -582,7 +583,7 @@ clicon_conf_autocli(clicon_handle h) * @retval username */ char * -clicon_username_get(clicon_handle h) +clicon_username_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); @@ -596,7 +597,7 @@ clicon_username_get(clicon_handle h) * @note Just keep note of it, dont allocate it or so. */ int -clicon_username_set(clicon_handle h, +clicon_username_set(clixon_handle h, void *username) { clicon_hash_t *cdat = clicon_data(h); @@ -612,7 +613,7 @@ clicon_username_set(clicon_handle h, * @retval status Startup status */ enum startup_status -clicon_startup_status_get(clicon_handle h) +clicon_startup_status_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); void *p; @@ -630,7 +631,7 @@ clicon_startup_status_get(clicon_handle h) * @retval -1 Error (when setting value) */ int -clicon_startup_status_set(clicon_handle h, +clicon_startup_status_set(clixon_handle h, enum startup_status status) { clicon_hash_t *cdat = clicon_data(h); @@ -646,7 +647,7 @@ clicon_startup_status_set(clicon_handle h, * @retval -1 No open socket */ int -clicon_socket_get(clicon_handle h) +clicon_socket_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); void *p; @@ -664,7 +665,7 @@ clicon_socket_get(clicon_handle h) * @retval -1 Error */ int -clicon_socket_set(clicon_handle h, +clicon_socket_set(clixon_handle h, int s) { clicon_hash_t *cdat = clicon_data(h); @@ -681,7 +682,7 @@ clicon_socket_set(clicon_handle h, * @retval -1 No open socket */ int -clicon_client_socket_get(clicon_handle h) +clicon_client_socket_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); void *p; @@ -699,7 +700,7 @@ clicon_client_socket_get(clicon_handle h) * @retval -1 Error */ int -clicon_client_socket_set(clicon_handle h, +clicon_client_socket_set(clixon_handle h, int s) { clicon_hash_t *cdat = clicon_data(h); @@ -717,7 +718,7 @@ clicon_client_socket_set(clicon_handle h, * xms is on the form: ... */ cxobj * -clicon_modst_cache_get(clicon_handle h, +clicon_modst_cache_get(clixon_handle h, int brief) { clicon_hash_t *cdat = clicon_data(h); @@ -737,7 +738,7 @@ clicon_modst_cache_get(clicon_handle h, * @retval -1 Error */ int -clicon_modst_cache_set(clicon_handle h, +clicon_modst_cache_set(clixon_handle h, int brief, cxobj *xms) { @@ -763,7 +764,7 @@ clicon_modst_cache_set(clicon_handle h, * @see draft-wang-netmod-module-revision-management-01 */ cxobj * -clicon_xml_changelog_get(clicon_handle h) +clicon_xml_changelog_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); void *p; @@ -782,7 +783,7 @@ clicon_xml_changelog_get(clicon_handle h) * @see draft-wang-netmod-module-revision-management-01 */ int -clicon_xml_changelog_set(clicon_handle h, +clicon_xml_changelog_set(clixon_handle h, cxobj *xchlog) { clicon_hash_t *cdat = clicon_data(h); @@ -801,7 +802,7 @@ clicon_xml_changelog_set(clicon_handle h, * @retval -1 Error */ int -clicon_argv_get(clicon_handle h, +clicon_argv_get(clixon_handle h, int *argc, char ***argv) { @@ -832,7 +833,7 @@ clicon_argv_get(clicon_handle h, * @note If argv=NULL deallocate allocated argv vector if exists. */ int -clicon_argv_set(clicon_handle h, +clicon_argv_set(clixon_handle h, char *prgm, int argc, char **argv) @@ -845,7 +846,7 @@ clicon_argv_set(clicon_handle h, /* add space for null-termination and argv[0] program name */ len = argc+2; if ((argvv = calloc(len, sizeof(char*))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } memcpy(argvv+1, argv, argc*sizeof(char*)); @@ -871,7 +872,7 @@ clicon_argv_set(clicon_handle h, * @retval NULL None found */ db_elmnt * -clicon_db_elmnt_get(clicon_handle h, +clicon_db_elmnt_get(clixon_handle h, const char *db) { clicon_hash_t *cdat = clicon_db_elmnt(h); @@ -892,7 +893,7 @@ clicon_db_elmnt_get(clicon_handle h, * @see xmldb_disconnect */ int -clicon_db_elmnt_set(clicon_handle h, +clicon_db_elmnt_set(clixon_handle h, const char *db, db_elmnt *de) { @@ -916,7 +917,7 @@ clicon_db_elmnt_set(clicon_handle h, * A backend getting a session-id of an ongoing session should use ce->ce_id */ int -clicon_session_id_get(clicon_handle h, +clicon_session_id_get(clixon_handle h, uint32_t *id) { clicon_hash_t *cdat = clicon_data(h); @@ -931,7 +932,7 @@ clicon_session_id_get(clicon_handle h, /*! Delete session id */ int -clicon_session_id_del(clicon_handle h) +clicon_session_id_del(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); @@ -947,7 +948,7 @@ clicon_session_id_del(clicon_handle h) * Session-ids survive TCP sessions that are created for each message sent to the backend. */ int -clicon_session_id_set(clicon_handle h, +clicon_session_id_set(clixon_handle h, uint32_t id) { clicon_hash_t *cdat = clicon_data(h); @@ -964,7 +965,7 @@ clicon_session_id_set(clicon_handle h, * If set, quit startup directly after upgrade */ int -clicon_quit_upgrade_get(clicon_handle h) +clicon_quit_upgrade_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); void *p; @@ -983,7 +984,7 @@ clicon_quit_upgrade_get(clicon_handle h) * If set, quit startup directly after upgrade */ int -clicon_quit_upgrade_set(clicon_handle h, +clicon_quit_upgrade_set(clixon_handle h, int val) { clicon_hash_t *cdat = clicon_data(h); diff --git a/lib/src/clixon_datastore.c b/lib/src/clixon_datastore.c index 3be279c2..ec11ba79 100644 --- a/lib/src/clixon_datastore.c +++ b/lib/src/clixon_datastore.c @@ -62,11 +62,12 @@ #include /* clixon */ -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_string.h" #include "clixon_file.h" #include "clixon_yang.h" @@ -94,7 +95,7 @@ * The filename reside in CLICON_XMLDB_DIR option */ int -xmldb_db2file(clicon_handle h, +xmldb_db2file(clixon_handle h, const char *db, char **filename) { @@ -103,16 +104,16 @@ xmldb_db2file(clicon_handle h, char *dir; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if ((dir = clicon_xmldb_dir(h)) == NULL){ - clicon_err(OE_XML, errno, "dbdir not set"); + clixon_err(OE_XML, errno, "dbdir not set"); goto done; } cprintf(cb, "%s/%s_db", dir, db); if ((*filename = strdup4(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 0; @@ -129,7 +130,7 @@ xmldb_db2file(clicon_handle h, * @retval -1 Error */ int -xmldb_connect(clicon_handle h) +xmldb_connect(clixon_handle h) { return 0; } @@ -141,7 +142,7 @@ xmldb_connect(clicon_handle h) * @retval -1 Error */ int -xmldb_disconnect(clicon_handle h) +xmldb_disconnect(clixon_handle h) { int retval = -1; char **keys = NULL; @@ -174,7 +175,7 @@ xmldb_disconnect(clicon_handle h) * @retval -1 Error */ int -xmldb_copy(clicon_handle h, +xmldb_copy(clixon_handle h, const char *from, const char *to) { @@ -252,7 +253,7 @@ xmldb_copy(clicon_handle h, * @retval -1 Error */ int -xmldb_lock(clicon_handle h, +xmldb_lock(clixon_handle h, const char *db, uint32_t id) { @@ -277,7 +278,7 @@ xmldb_lock(clicon_handle h, * Assume all sanity checks have been made */ int -xmldb_unlock(clicon_handle h, +xmldb_unlock(clixon_handle h, const char *db) { db_elmnt *de = NULL; @@ -298,7 +299,7 @@ xmldb_unlock(clicon_handle h, * @retval -1 Error */ int -xmldb_unlock_all(clicon_handle h, +xmldb_unlock_all(clixon_handle h, uint32_t id) { int retval = -1; @@ -335,7 +336,7 @@ xmldb_unlock_all(clicon_handle h, * @retval -1 Error */ uint32_t -xmldb_islocked(clicon_handle h, +xmldb_islocked(clixon_handle h, const char *db) { db_elmnt *de; @@ -354,7 +355,7 @@ xmldb_islocked(clicon_handle h, * @retval -1 No timestamp / not locked */ int -xmldb_lock_timestamp(clicon_handle h, +xmldb_lock_timestamp(clixon_handle h, const char *db, struct timeval *tv) { @@ -376,7 +377,7 @@ xmldb_lock_timestamp(clicon_handle h, * @note An empty datastore is treated as not existent so that a backend after dropping priviliges can re-create it */ int -xmldb_exists(clicon_handle h, +xmldb_exists(clixon_handle h, const char *db) { int retval = -1; @@ -409,7 +410,7 @@ xmldb_exists(clicon_handle h, * @retval -1 Error */ int -xmldb_clear(clicon_handle h, +xmldb_clear(clixon_handle h, const char *db) { cxobj *xt = NULL; @@ -434,7 +435,7 @@ xmldb_clear(clicon_handle h, * @note Datastore is not actually deleted so that a backend after dropping priviliges can re-create it */ int -xmldb_delete(clicon_handle h, +xmldb_delete(clixon_handle h, const char *db) { int retval = -1; @@ -448,7 +449,7 @@ xmldb_delete(clicon_handle h, goto done; if (lstat(filename, &sb) == 0) if (truncate(filename, 0) < 0){ - clicon_err(OE_DB, errno, "truncate %s", filename); + clixon_err(OE_DB, errno, "truncate %s", filename); goto done; } retval = 0; @@ -466,7 +467,7 @@ xmldb_delete(clicon_handle h, * @retval -1 Error */ int -xmldb_create(clicon_handle h, +xmldb_create(clixon_handle h, const char *db) { int retval = -1; @@ -485,7 +486,7 @@ xmldb_create(clicon_handle h, if (xmldb_db2file(h, db, &filename) < 0) goto done; if ((fd = open(filename, O_CREAT|O_WRONLY, S_IRWXU)) == -1) { - clicon_err(OE_UNIX, errno, "open(%s)", filename); + clixon_err(OE_UNIX, errno, "open(%s)", filename); goto done; } retval = 0; @@ -506,7 +507,7 @@ xmldb_create(clicon_handle h, * @retval -1 Error */ int -xmldb_db_reset(clicon_handle h, +xmldb_db_reset(clixon_handle h, const char *db) { if (xmldb_exists(h, db) == 1){ @@ -525,7 +526,7 @@ xmldb_db_reset(clicon_handle h, * @retval xml XML cached tree or NULL */ cxobj * -xmldb_cache_get(clicon_handle h, +xmldb_cache_get(clixon_handle h, const char *db) { db_elmnt *de; @@ -546,13 +547,13 @@ xmldb_cache_get(clicon_handle h, * @note This only works if db cache is used,... */ int -xmldb_modified_get(clicon_handle h, +xmldb_modified_get(clixon_handle h, const char *db) { db_elmnt *de; if ((de = clicon_db_elmnt_get(h, db)) == NULL){ - clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db); + clixon_err(OE_CFG, EFAULT, "datastore %s does not exist", db); return -1; } return de->de_modified; @@ -567,13 +568,13 @@ xmldb_modified_get(clicon_handle h, * @retval -1 Error (datastore does not exist) */ int -xmldb_empty_get(clicon_handle h, +xmldb_empty_get(clixon_handle h, const char *db) { db_elmnt *de; if ((de = clicon_db_elmnt_get(h, db)) == NULL){ - clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db); + clixon_err(OE_CFG, EFAULT, "datastore %s does not exist", db); return -1; } return de->de_empty; @@ -590,14 +591,14 @@ xmldb_empty_get(clicon_handle h, * @note This only works if db cache is used,... */ int -xmldb_modified_set(clicon_handle h, +xmldb_modified_set(clixon_handle h, const char *db, int value) { db_elmnt *de; if ((de = clicon_db_elmnt_get(h, db)) == NULL){ - clicon_err(OE_CFG, EFAULT, "datastore %s does not exist", db); + clixon_err(OE_CFG, EFAULT, "datastore %s does not exist", db); return -1; } de->de_modified = value; @@ -607,7 +608,7 @@ xmldb_modified_set(clicon_handle h, /* Print the datastore meta-info to file */ int -xmldb_print(clicon_handle h, +xmldb_print(clixon_handle h, FILE *f) { int retval = -1; @@ -644,7 +645,7 @@ xmldb_print(clicon_handle h, * @note if newdb and suffix are null, OK is returned as it is a no-op */ int -xmldb_rename(clicon_handle h, +xmldb_rename(clixon_handle h, const char *db, const char *newdb, const char *suffix) @@ -659,7 +660,7 @@ xmldb_rename(clicon_handle h, if (newdb == NULL && suffix == NULL) // no-op goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "%s", newdb == NULL ? old : newdb); @@ -667,7 +668,7 @@ xmldb_rename(clicon_handle h, cprintf(cb, "%s", suffix); fname = cbuf_get(cb); if ((rename(old, fname)) < 0) { - clicon_err(OE_UNIX, errno, "rename: %s", strerror(errno)); + clixon_err(OE_UNIX, errno, "rename: %s", strerror(errno)); goto done; }; retval = 0; diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 4d10dd78..58731f88 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -56,12 +56,13 @@ #include /* clixon */ -#include "clixon_err.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_file.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -89,8 +90,7 @@ /*! Ensure that xt only has a single sub-element and that is "config" * * @retval 0 There exists a single "config" sub-element - * @retval -1 Top element not "config" or "config" element not unique or - * other error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error: Top element not "config" or "config" element not unique or other */ static int singleconfigroot(cxobj *xt, @@ -105,13 +105,13 @@ singleconfigroot(cxobj *xt, while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL){ i++; if (strcmp(xml_name(x), DATASTORE_TOP_SYMBOL)){ - clicon_err(OE_DB, ENOENT, "Wrong top-element %s expected %s", + clixon_err(OE_DB, ENOENT, "Wrong top-element %s expected %s", xml_name(x), DATASTORE_TOP_SYMBOL); goto done; } } if (i != 1){ - clicon_err(OE_DB, ENOENT, "Top-element is not unique, expecting single config"); + clixon_err(OE_DB, ENOENT, "Top-element is not unique, expecting single config"); goto done; } x = NULL; @@ -131,7 +131,7 @@ singleconfigroot(cxobj *xt, /*! Recurse up from x0 up to x0t then create objects from x1t down to new object x1 * * @retval 0 OK - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 OK */ static int xml_copy_bottom_recurse(cxobj *x0t, @@ -157,7 +157,7 @@ xml_copy_bottom_recurse(cxobj *x0t, goto ok; } if ((x0p = xml_parent(x0)) == NULL){ - clicon_err(OE_XML, EFAULT, "Reached top of tree"); + clixon_err(OE_XML, EFAULT, "Reached top of tree"); goto done; } if (xml_copy_bottom_recurse(x0t, x0p, x1t, &x1p) < 0) @@ -210,7 +210,7 @@ xml_copy_bottom_recurse(cxobj *x0t, /*! Copy an XML tree bottom-up * * @retval 0 OK - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 OK */ static int xml_copy_from_bottom(cxobj *x0t, @@ -252,7 +252,7 @@ xml_copy_from_bottom(cxobj *x0t, * @param[in] xt XML tree * @param[out] msdiff Modules-state differences * @retval 0 OK - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * * The modstate difference contains: * - if there is a modstate @@ -273,7 +273,7 @@ xml_copy_from_bottom(cxobj *x0t, * 4a) If there is no such module in the file -> add to list mark as ADD */ static int -text_read_modstate(clicon_handle h, +text_read_modstate(clixon_handle h, yang_stmt *yspec, cxobj *xt, modstate_diff_t *msdiff) @@ -315,7 +315,7 @@ text_read_modstate(clicon_handle h, if (!rfc7895){ if ((xf = xpath_first(xt, NULL, "yang-library/content-id")) != NULL){ if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -326,7 +326,7 @@ text_read_modstate(clicon_handle h, if (rfc7895){ if (strcmp(xml_name(xf), "module-set-id") == 0){ if (xml_body(xf) && (msdiff->md_content_id = strdup(xml_body(xf))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } continue; @@ -400,7 +400,7 @@ text_read_modstate(clicon_handle h, * @param[in] xt Top-level XML * @param[in] yspec YANG spec * @retval 0 OK - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error */ static int disable_nacm_on_empty(cxobj *xt, @@ -457,7 +457,7 @@ disable_nacm_on_empty(cxobj *xt, * @see xml_creator_metadata_write */ static int -xml_creator_metadata_read(clicon_handle h, +xml_creator_metadata_read(clixon_handle h, cxobj *xn) { int retval = -1; @@ -504,13 +504,13 @@ xml_creator_metadata_read(clicon_handle h, * @param[out] xerr XML error if retval is 0 * @retval 1 OK * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note Use of 1 for OK * @note retval 0 is NYI because calling functions cannot handle it yet * XXX if this code pass tests this code can be rewritten, esp the modstate stuff */ int -xmldb_readfile(clicon_handle h, +xmldb_readfile(clixon_handle h, const char *db, yang_bind yb, yang_stmt *yspec, @@ -537,23 +537,23 @@ xmldb_readfile(clicon_handle h, yang_stmt *yspec1 = NULL; if (yb != YB_MODULE && yb != YB_NONE){ - clicon_err(OE_XML, EINVAL, "yb is %d but should be module or none", yb); + clixon_err(OE_XML, EINVAL, "yb is %d but should be module or none", yb); goto done; } if (xmldb_db2file(h, db, &dbfile) < 0) goto done; if (dbfile==NULL){ - clicon_err(OE_XML, 0, "dbfile NULL"); + clixon_err(OE_XML, 0, "dbfile NULL"); goto done; } if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){ - clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); + clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "Reading datastore %s using %s", dbfile, format); /* Parse file into internal XML tree from different formats */ if ((fp = fopen(dbfile, "r")) == NULL) { - clicon_err(OE_UNIX, errno, "open(%s)", dbfile); + clixon_err(OE_UNIX, errno, "open(%s)", dbfile); goto done; } /* Read whole datastore file on the form: @@ -646,14 +646,14 @@ xmldb_readfile(clicon_handle h, /* YANG Module not found, look for it and append if found */ if (yang_spec_parse_module(h, name, rev, yspec) < 0){ /* Special case: file-not-found errors */ - if (clicon_suberrno == ENOENT){ + if (clixon_err_subnr() == ENOENT){ cbuf *cberr = NULL; if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } - cprintf(cberr, "Internal error: %s", clicon_err_reason); - clicon_err_reset(); + cprintf(cberr, "Internal error: %s", clixon_err_reason()); + clixon_err_reset(); if (xerr && netconf_operation_failed_xml(xerr, "application", cbuf_get(cberr))< 0) goto done; cbuf_free(cberr); @@ -739,12 +739,12 @@ xmldb_readfile(clicon_handle h, * @param[out] xerr XML error if retval is 0 * @retval 1 OK * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note Use of 1 for OK * @see xmldb_get the generic API function */ static int -xmldb_get_nocache(clicon_handle h, +xmldb_get_nocache(clixon_handle h, const char *db, yang_bind yb, cvec *nsc, @@ -766,7 +766,7 @@ xmldb_get_nocache(clicon_handle h, db_elmnt de0 = {0,}; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } /* xml looks like: ... where "x" is a top-level symbol in a module */ @@ -861,7 +861,7 @@ xmldb_get_nocache(clicon_handle h, } #if 0 /* debug */ if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0) - clicon_log(LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__); + clixon_log(h, LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__); #endif if (clixon_debug_get()>1) if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0) @@ -898,12 +898,12 @@ xmldb_get_nocache(clicon_handle h, * @param[out] xerr XML error if retval is 0 * @retval 1 OK * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note Use of 1 for OK * @see xmldb_get the generic API function */ static int -xmldb_get_cache(clicon_handle h, +xmldb_get_cache(clixon_handle h, const char *db, yang_bind yb, cvec *nsc, @@ -927,7 +927,7 @@ xmldb_get_cache(clicon_handle h, int ret; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } de = clicon_db_elmnt_get(h, db); @@ -1086,11 +1086,11 @@ xmldb_get_cache(clicon_handle h, * @param[out] xerr XML error if retval is 0 * @retval 1 OK * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note Use of 1 for OK */ static int -xmldb_get_zerocopy(clicon_handle h, +xmldb_get_zerocopy(clixon_handle h, const char *db, yang_bind yb, cvec *nsc, @@ -1113,7 +1113,7 @@ xmldb_get_zerocopy(clicon_handle h, int ret; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } de = clicon_db_elmnt_get(h, db); @@ -1231,7 +1231,7 @@ xmldb_get_zerocopy(clicon_handle h, * @param[out] xret Single return XML tree. Free with xml_free() * @retval 1 OK * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note Use of 1 for OK * @code * if (xmldb_get(xh, "running", NULL, "/interfaces/interface[name="eth"]", &xt) < 0) @@ -1241,7 +1241,7 @@ xmldb_get_zerocopy(clicon_handle h, * @see xmldb_get0 Underlying more capable API for enabling zero-copy */ int -xmldb_get(clicon_handle h, +xmldb_get(clixon_handle h, const char *db, cvec *nsc, char *xpath, @@ -1270,7 +1270,7 @@ xmldb_get(clicon_handle h, * @param[out] xerr XML error if retval is 0 * @retval 1 OK * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note Use of 1 for OK * @code * cxobj *xt; @@ -1302,7 +1302,7 @@ xmldb_get(clicon_handle h, * 0 */ int -xmldb_get0(clicon_handle h, +xmldb_get0(clixon_handle h, const char *db, yang_bind yb, cvec *nsc, @@ -1316,7 +1316,7 @@ xmldb_get0(clicon_handle h, int retval = -1; if (xret == NULL){ - clicon_err(OE_DB, EINVAL, "xret is NULL"); + clixon_err(OE_DB, EINVAL, "xret is NULL"); goto done; } switch (clicon_datastore_cache(h)){ @@ -1354,12 +1354,12 @@ xmldb_get0(clicon_handle h, * @param[in] h Clixon handle * @param[in] db Name of datastore * @retval 0 OK - * @retval -1 General error, check specific clicon_errno, clicon_suberrno + * @retval -1 Error * @note "Clear" an xml tree means removing default values and resetting all flags. * @see xmldb_get0 */ int -xmldb_get0_clear(clicon_handle h, +xmldb_get0_clear(clixon_handle h, cxobj *x) { int retval = -1; @@ -1389,7 +1389,7 @@ xmldb_get0_clear(clicon_handle h, * @see xmldb_get0 */ int -xmldb_get0_free(clicon_handle h, +xmldb_get0_free(clixon_handle h, cxobj **xp) { if (*xp == NULL) diff --git a/lib/src/clixon_datastore_read.h b/lib/src/clixon_datastore_read.h index ea3c948a..de353f25 100644 --- a/lib/src/clixon_datastore_read.h +++ b/lib/src/clixon_datastore_read.h @@ -41,7 +41,7 @@ /* * Prototypes */ -int xmldb_readfile(clicon_handle h, const char *db, yang_bind yb, yang_stmt *yspec, +int xmldb_readfile(clixon_handle h, const char *db, yang_bind yb, yang_stmt *yspec, cxobj **xp, db_elmnt *de, modstate_diff_t *msd, cxobj **xerr); #endif /* _CLIXON_DATASTORE_READ_H */ diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 524f3036..f2cfb032 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -56,12 +56,13 @@ #include /* clixon */ -#include "clixon_err.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_file.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -126,7 +127,7 @@ attr_ns_value(cxobj *x, if (ns == NULL || strcmp(ans, ns) == 0){ if ((val = strdup(xml_value(xa))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } xml_purge(xa); @@ -257,7 +258,7 @@ check_body_namespace(cxobj *x0, * XXX return netconf error instead bad-attribue? */ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "identityref: \"%s\": namespace collision %s vs %s", x1bstr, ns0, ns1); @@ -303,7 +304,7 @@ check_body_namespace(cxobj *x0, } #else if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "identityref: \"%s\": prefix \"%s\" has no associated namespace", x1bstr, prefix); @@ -371,7 +372,7 @@ check_when_condition(cxobj *x0p, goto done; if (nr == 0){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "Node '%s' tagged with 'when' condition '%s' in module '%s' evaluates to false in edit-config operation (see RFC 7950 Sec 8.3.2)", @@ -519,7 +520,7 @@ choice_delete_other(cxobj *x0, * in the list the entry is inserted. */ static int -text_modify(clicon_handle h, +text_modify(clixon_handle h, cxobj *x0, cxobj *x0p, cxobj *x0t, @@ -559,7 +560,7 @@ text_modify(clicon_handle h, char *creator = NULL; if (x1 == NULL){ - clicon_err(OE_XML, EINVAL, "x1 is missing"); + clixon_err(OE_XML, EINVAL, "x1 is missing"); goto done; } if ((ret = check_when_condition(x0p, x1, y0, cbret)) < 0) @@ -708,7 +709,7 @@ text_modify(clicon_handle h, if (yang_type_get(y0, NULL, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) goto done; if (yrestype == NULL){ - clicon_err(OE_CFG, EFAULT, "No restype (internal error)"); + clixon_err(OE_CFG, EFAULT, "No restype (internal error)"); goto done; } restype = yang_argument_get(yrestype); @@ -940,7 +941,7 @@ text_modify(clicon_handle h, * collect matching nodes from x0 in x0vec (no changes to x0 children) */ if ((x0vec = calloc(xml_child_nr_type(x1, CX_ELMNT), sizeof(x1))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } x1c = NULL; @@ -957,7 +958,7 @@ text_modify(clicon_handle h, if ((yc = yang_anydata_add(y0, x1cname)) < 0) goto done; xml_spec_set(x1c, yc); - clicon_log(LOG_WARNING, + clixon_log(h, LOG_WARNING, "%s: %d: No YANG spec for %s, anydata used", __FUNCTION__, __LINE__, x1cname); } @@ -973,7 +974,7 @@ text_modify(clicon_handle h, * As an alternative, return in populate where this is detected first time. */ if (yc != xml_spec(x1c)){ - clicon_err(OE_YANG, errno, "XML node \"%s\" not in namespace %s", + clixon_err(OE_YANG, errno, "XML node \"%s\" not in namespace %s", x1cname, yang_find_mynamespace(y0)); goto done; } @@ -1101,7 +1102,7 @@ text_modify(clicon_handle h, * @see text_modify */ static int -text_modify_top(clicon_handle h, +text_modify_top(clixon_handle h, cxobj *x0t, cxobj *x1t, yang_stmt *yspec, @@ -1210,7 +1211,7 @@ text_modify_top(clicon_handle h, if ((yc = yang_anydata_add(ymod, x1cname)) < 0) goto done; xml_spec_set(x1c, yc); - clicon_log(LOG_WARNING, + clixon_log(h, LOG_WARNING, "%s: %d: No YANG spec for %s, anydata used", __FUNCTION__, __LINE__, x1cname); } @@ -1275,7 +1276,7 @@ text_modify_top(clicon_handle h, * @note if xret is non-null, it may contain error message */ int -xmldb_put(clicon_handle h, +xmldb_put(clixon_handle h, const char *db, enum operation_type op, cxobj *x1, @@ -1302,15 +1303,15 @@ xmldb_put(clicon_handle h, cxobj *xmeta = NULL; if (cbret == NULL){ - clicon_err(OE_XML, EINVAL, "cbret is NULL"); + clixon_err(OE_XML, EINVAL, "cbret is NULL"); goto done; } if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec"); + clixon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } if (x1 && strcmp(xml_name(x1), NETCONF_INPUT_CONFIG) != 0){ - clicon_err(OE_XML, 0, "Top-level symbol of modification tree is %s, expected \"%s\"", + clixon_err(OE_XML, 0, "Top-level symbol of modification tree is %s, expected \"%s\"", xml_name(x1), NETCONF_INPUT_CONFIG); goto done; } @@ -1329,7 +1330,7 @@ xmldb_put(clicon_handle h, } if (strcmp(xml_name(x0), DATASTORE_TOP_SYMBOL) !=0 || xml_flag(x0, XML_FLAG_TOP) == 0){ - clicon_err(OE_XML, 0, "Top-level symbol is %s, expected \"%s\"", + clixon_err(OE_XML, 0, "Top-level symbol is %s, expected \"%s\"", xml_name(x0), DATASTORE_TOP_SYMBOL); goto done; } @@ -1346,7 +1347,7 @@ xmldb_put(clicon_handle h, /* Here x0 looks like: ... */ #if 0 /* debug */ if (xml_apply0(x1, -1, xml_sort_verify, NULL) < 0) - clicon_log(LOG_NOTICE, "%s: verify failed #1", __FUNCTION__); + clixon_log(h, LOG_NOTICE, "%s: verify failed #1", __FUNCTION__); #endif xnacm = clicon_nacm_cache(h); permit = (xnacm==NULL); @@ -1380,7 +1381,7 @@ xmldb_put(clicon_handle h, goto done; #if 0 /* debug */ if (xml_apply0(x0, -1, xml_sort_verify, NULL) < 0) - clicon_log(LOG_NOTICE, "%s: verify failed #3", __FUNCTION__); + clixon_log(h, LOG_NOTICE, "%s: verify failed #3", __FUNCTION__); #endif /* Write back to datastore cache if first time */ if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){ @@ -1395,7 +1396,7 @@ xmldb_put(clicon_handle h, if (xmldb_db2file(h, db, &dbfile) < 0) goto done; if (dbfile==NULL){ - clicon_err(OE_XML, 0, "dbfile NULL"); + clixon_err(OE_XML, 0, "dbfile NULL"); goto done; } /* Add module revision info before writing to file) @@ -1408,11 +1409,11 @@ xmldb_put(clicon_handle h, goto done; } if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){ - clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); + clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); goto done; } if ((f = fopen(dbfile, "w")) == NULL){ - clicon_err(OE_CFG, errno, "Creating file %s", dbfile); + clixon_err(OE_CFG, errno, "Creating file %s", dbfile); goto done; } pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY"); @@ -1466,7 +1467,7 @@ xmldb_put(clicon_handle h, /* Dump a datastore to file including modstate */ int -xmldb_dump(clicon_handle h, +xmldb_dump(clixon_handle h, FILE *f, cxobj *xt) { @@ -1487,7 +1488,7 @@ xmldb_dump(clicon_handle h, goto done; } if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){ - clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); + clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); goto done; } pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY"); diff --git a/lib/src/clixon_datastore_write.h b/lib/src/clixon_datastore_write.h index 1edf523a..b7bfd9f5 100644 --- a/lib/src/clixon_datastore_write.h +++ b/lib/src/clixon_datastore_write.h @@ -45,6 +45,6 @@ /* * Prototypes */ -int xmldb_put(clicon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); +int xmldb_put(clixon_handle h, const char *db, enum operation_type op, cxobj *xt, char *username, cbuf *cbret); #endif /* _CLIXON_DATASTORE_WRITE_H */ diff --git a/lib/src/clixon_debug.c b/lib/src/clixon_debug.c new file mode 100644 index 00000000..da152226 --- /dev/null +++ b/lib/src/clixon_debug.c @@ -0,0 +1,165 @@ + /* + * + ***** BEGIN LICENSE BLOCK ***** + + Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren + Copyright (C) 2017-2019 Olof Hagsand + Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate) + + This file is part of CLIXON. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Alternatively, the contents of this file may be used under the terms of + the GNU General Public License Version 3 or later (the "GPL"), + in which case the provisions of the GPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of the GPL, and not to allow others to + use your version of this file under the terms of Apache License version 2, + indicate your decision by deleting the provisions above and replace them with + the notice and other provisions required by the GPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the Apache License version 2 or the GPL. + + ***** END LICENSE BLOCK ***** + + * + * Regular logging and debugging. Syslog using levels. + */ + +#ifdef HAVE_CONFIG_H +#include "clixon_config.h" /* generated by config & autoconf */ +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* cligen */ +#include + +/* clixon */ +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" + +/* + * Local Variables + */ + +/*! The global debug level. 0 means no debug + * + * @note There are pros and cons in having the debug state as a global variable. The + * alternative to bind it to the clicon handle (h) was considered but it limits its + * usefulness, since not all functions have h + */ +static int _debug_level = 0; + +/*! Initialize debug messages. Set debug level. + * + * Initialize debug module. The level is used together with clixon_debug(dbglevel) calls as follows: + * print message if level >= dbglevel. + * Example: clixon_debug_init(1) -> debug(1) is printed, but not debug(2). + * Normally, debug messages are sent to clixon_log() which in turn can be sent to syslog and/or stderr. + * But you can also override this with a specific debug file so that debug messages are written on the file + * independently of log or errors. This is to ensure that a syslog of normal logs is unpolluted by extensive + * debugging. + * + * @param[in] h Clixon handle + * @param[in] dbglevel 0 is show no debug messages, 1 is normal, 2.. is high debug. + * Note this is _not_ level from syslog(3) + * @param[in] f Debug-file. Open file where debug messages are directed. + * @see clixon_log_file For specifying a debug-file + */ +int +clixon_debug_init(clixon_handle h, + int dbglevel) +{ + _debug_level = dbglevel; /* Global variable */ + return 0; +} + +/*! Get debug level + */ +int +clixon_debug_get(void) +{ + return _debug_level; +} + +/*! Print a debug message with debug-level. Settings determine where msg appears. + * + * If the dbglevel passed in the function is equal to or lower than the one set by + * clixon_debug_init(level). That is, only print debug messages <= than what you want: + * print message if level >= dbglevel. + * The message is sent to clixon_log. EIther to syslog, stderr or both, depending on + * clixon_log_init() setting + * @param[in] dbglevel Mask of CLIXON_DBG_DEFAULT and other masks + * @param[in] format Message to print as argv. + * @retval 0 OK + * @retval -1 Error + * @see clixon_debug_xml Specialization for XML tree + * @see CLIXON_DBG_DEFAULT and other flags + */ +int +clixon_debug(int dbglevel, + const char *format, ...) +{ + int retval = -1; + va_list args; + size_t len; + char *msg = NULL; + size_t trunc; + + /* Mask debug level with global dbg variable */ + if ((dbglevel & clixon_debug_get()) == 0) + return 0; + /* first round: compute length of debug message */ + va_start(args, format); + len = vsnprintf(NULL, 0, format, args); + va_end(args); + + /* Truncate long debug strings */ + if ((trunc = clixon_log_string_limit_get()) && trunc < len) + len = trunc; + /* allocate a message string exactly fitting the message length */ + if ((msg = malloc(len+1)) == NULL){ + clixon_err(OE_UNIX, errno, "malloc"); + goto done; + } + /* second round: compute write message from format and args */ + va_start(args, format); + if (vsnprintf(msg, len+1, format, args) < 0){ + va_end(args); + clixon_err(OE_UNIX, errno, "vsnprintf"); + goto done; + } + va_end(args); + clixon_log_str(LOG_DEBUG, msg); + retval = 0; + done: + if (msg) + free(msg); + return retval; +} diff --git a/lib/src/clixon_err.c b/lib/src/clixon_err.c index d79ccf0f..70fddf14 100644 --- a/lib/src/clixon_err.c +++ b/lib/src/clixon_err.c @@ -35,9 +35,7 @@ * * Errors may be syslogged using LOG_ERR, and printed to stderr, as controlled - * by clicon_log_init - * global error variables are set: - * clicon_errno, clicon_suberrno, clicon_err_reason. + * by clixon_log_init */ #ifdef HAVE_CONFIG_H @@ -61,8 +59,11 @@ #include /* clixon */ -#include "clixon_log.h" #include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_err.h" /* @@ -74,8 +75,8 @@ struct errvec{ }; struct err_state{ - int es_errno; - int es_suberrno; + int es_category; + int es_subnr; char es_reason[ERR_STRLEN]; }; @@ -85,21 +86,29 @@ struct err_state{ */ struct clixon_err_cats { qelem_t cec_qelem; /* List header */ - enum clicon_err cec_category; + enum clixon_err cec_category; void *cec_handle; clixon_cat_log_cb *cec_logfn; }; typedef struct clixon_err_cats clixon_err_cats; +/* + * Local Variables + */ + +/* Cache handle since some error calls does not have handle access */ +static clixon_handle _err_clixon_h = NULL; /* Internal global list of category callbacks */ static clixon_err_cats *_err_cat_list = NULL; -/* - * Variables - */ -int clicon_errno = 0; /* See enum clicon_err XXX: hide this and change to err_category */ -int clicon_suberrno = 0; /* Corresponds to errno.h XXX: change to errno */ -char clicon_err_reason[ERR_STRLEN] = {0, }; +/* See enum clixon_err XXX: hide this and change to err_category */ +static int _err_category = 0; + +/* Corresponds to errno.h XXX: change to errno */ +static int _err_subnr = 0; + +/* Clixon error reason */ +static char _err_reason[ERR_STRLEN] = {0, }; /* * Error descriptions. Must stop with NULL element. @@ -129,8 +138,59 @@ static struct errvec EV[] = { {NULL, -1} }; +/*! Initialize clixon errors + * + * Mainly to cache handle since many clixon_err calls may not have access to a handle + * @param[in] h Clixon handle + * @see clixon_log_init inits log + */ +int +clixon_err_init(clixon_handle h) +{ + if (h == NULL){ + errno = EINVAL; + return -1; + } + _err_clixon_h = h; + return 0; +} + +/*! Access function: return clixon category of last error + * + * @retval category Clixon error category + * @see clixon_err_save + */ +int +clixon_err_category(void) +{ + return _err_category; +} + +/*! Access function: return clixon errno of last error + * + * @retval errno Clixon sub error number + * @see clixon_err_save + */ +int +clixon_err_subnr(void) +{ + return _err_subnr; +} + +/*! Access function: return clixon error reason string of last error (direct pointer) + * + * @retval reason Pointer to static string + * Consider copy or malloc instead of pointer to static string? + * @see clixon_err_save + */ +char * +clixon_err_reason(void) +{ + return _err_reason; +} + static char * -clicon_strerror1(int err, +clixon_strerror1(int err, struct errvec vec[]) { struct errvec *ev; @@ -138,7 +198,15 @@ clicon_strerror1(int err, for (ev=vec; ev->ev_err != -1; ev++) if (ev->ev_err == err) break; - return ev?(ev->ev_str?ev->ev_str:"unknown"):"CLICON unknown error"; + return ev?(ev->ev_str?ev->ev_str:"unknown"):"Clixon unknown error"; +} + +/*! Translate from numeric error to string representation + */ +char * +clixon_err_str(void) +{ + return clixon_strerror1(_err_category, EV); } /*! Clear error state and continue. @@ -146,11 +214,11 @@ clicon_strerror1(int err, * Clear error state and get on with it, typically non-fatal error and you wish to continue. */ int -clicon_err_reset(void) +clixon_err_reset(void) { - clicon_errno = 0; - clicon_suberrno = 0; - memset(clicon_err_reason, 0, ERR_STRLEN); + _err_category = 0; + _err_subnr = 0; + memset(_err_reason, 0, ERR_STRLEN); return 0; } @@ -178,162 +246,182 @@ find_category(int category) return found?cec:NULL; } -/*! Report an error. +/*! Report an error, constant args variant, see clixon_err() for most common function * - * Library routines should call this function when an error occurs. - * The function does he following: - * - Logs to syslog with LOG_ERR - * - Set global error variable name clicon_errno - * - Set global reason string clicon_err_reason - * Typically a call to clicon_err() is followed by a return -1 (or NULL) that signals - * a fatal error that fails early and loud. - * However there are some cases where such an error does not cause an exit. This includes - * CLI operations of callbacks and expand functions. The reason is that user-defined errors - * should just signal an error and not terminate. To override this one can set a suberr to - * ESHUTDOWN. - * - * @note: err direction (syslog and/or stderr) controlled by clicon_log_init() - * - * @param[in] fn Inline function name (when called from clicon_err() macro) - * @param[in] line Inline file line number (when called from clicon_err() macro) - * @param[in] category Clixon error category, See enum clicon_err + * @param[in] h Clixon handle + * @param[in] fn Inline function name (when called from clixon_err() macro) + * @param[in] line Inline file line number (when called from clixon_err() macro) + * @param[in] category Clixon error category, See enum clixon_err * @param[in] suberr Error number, typically errno - * @param[in] format Error string, format with argv + * @param[in] msg Error string * @retval 0 OK * @retval -1 Error - * @see clicon_err_reset Reset the global error variables. + * @see clixon_err_fn for a variable-argument variant */ int -clicon_err_fn(const char *fn, - const int line, - int category, - int suberr, - const char *format, ...) +clixon_err_args(clixon_handle h, + const char *fn, + const int line, + int category, + int suberr, + char *msg) { - int retval = -1; - va_list args; - int len; - char *msg = NULL; + int retval = -1; struct clixon_err_cats *cec; - + cbuf *cb = NULL; + /* Set the global variables */ - clicon_errno = category; - clicon_suberrno = suberr; - - /* first round: compute length of error message */ - va_start(args, format); - len = vsnprintf(NULL, 0, format, args); - va_end(args); - - /* allocate a message string exactly fitting the message length */ - if ((msg = malloc(len+1)) == NULL){ - fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ - goto done; - } - - /* second round: compute write message from format and args */ - va_start(args, format); - if (vsnprintf(msg, len+1, format, args) < 0){ - va_end(args); - fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ - goto done; - } - va_end(args); - strncpy(clicon_err_reason, msg, ERR_STRLEN-1); + strncpy(_err_reason, msg, ERR_STRLEN-1); + _err_category = category; + _err_subnr = suberr; /* Check category callbacks as defined in clixon_err_cat_reg */ if ((cec = find_category(category)) != NULL && cec->cec_logfn){ - cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } if (cec->cec_logfn(cec->cec_handle, suberr, cb) < 0) goto done; /* Here we could take care of specific errno, like application-defined errors */ if (fn) - clicon_log(LOG_ERR, "%s: %d: %s: %s: %s", + clixon_log(h, LOG_ERR, "%s: %d: %s: %s: %s", fn, line, - clicon_strerror(category), + clixon_strerror1(category, EV), cbuf_get(cb), msg); else - clicon_log(LOG_ERR, "%s: %s: %s", - clicon_strerror(category), + clixon_log(h, LOG_ERR, "%s: %s: %s", + clixon_strerror1(category, EV), cbuf_get(cb), msg); - if (cb) - cbuf_free(cb); } else if (suberr){ /* Actually log it */ /* Here we could take care of specific errno, like application-defined errors */ if (fn) - clicon_log(LOG_ERR, "%s: %d: %s: %s: %s", + clixon_log(h, LOG_ERR, "%s: %d: %s: %s: %s", fn, line, - clicon_strerror(category), + clixon_strerror1(category, EV), msg, suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr)); else - clicon_log(LOG_ERR, "%s: %s: %s", - clicon_strerror(category), + clixon_log(h, LOG_ERR, "%s: %s: %s", + clixon_strerror1(category, EV), msg, suberr==XMLPARSE_ERRNO?"XML parse error":strerror(suberr)); } else{ if (fn) - clicon_log(LOG_ERR, "%s: %d: %s: %s", + clixon_log(h, LOG_ERR, "%s: %d: %s: %s", fn, line, - clicon_strerror(category), + clixon_strerror1(category, EV), msg); else - clicon_log(LOG_ERR, "%s: %s", - clicon_strerror(category), + clixon_log(h, LOG_ERR, "%s: %s", + clixon_strerror1(category, EV), msg); } retval = 0; + done: + if (cb) + cbuf_free(cb); + return retval; +} + +/*! Report an error. + * + * Library routines should call this function when an error occurs. + * The function does he following: + * - Logs to syslog with LOG_ERR + * - Set global error variable name clixon_errno + * - Set global reason string clixon_err_reason + * Typically a call to clixon_err() is followed by a return -1 (or NULL) that signals + * a fatal error that fails early and loud. + * However there are some cases where such an error does not cause an exit. This includes + * CLI operations of callbacks and expand functions. The reason is that user-defined errors + * should just signal an error and not terminate. To override this one can set a suberr to + * ESHUTDOWN. + * + * @note: err direction (syslog and/or stderr) controlled by clixon_log_init() + * + * @param[in] fn Inline function name (when called from clixon_err() macro) + * @param[in] line Inline file line number (when called from clixon_err() macro) + * @param[in] category Clixon error category, See enum clixon_err + * @param[in] suberr Error number, typically errno + * @param[in] format Error string, format with argv + * @retval 0 OK + * @retval -1 Error + * @see clixon_err_netconf For variant with netconf error message + */ +int +clixon_err_fn(const char *fn, + const int line, + int category, + int suberr, + const char *format, ...) +{ + int retval = -1; + va_list args; + int len; + char *msg = NULL; + + /* first round: compute length of error message */ + va_start(args, format); + len = vsnprintf(NULL, 0, format, args); + va_end(args); + /* allocate a message string exactly fitting the message length */ + if ((msg = malloc(len+1)) == NULL){ + fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ + goto done; + } + /* second round: compute write message from format and args */ + va_start(args, format); + if (vsnprintf(msg, len+1, format, args) < 0){ + va_end(args); + fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ + goto done; + } + va_end(args); + if (clixon_err_args(_err_clixon_h, fn, line, category, suberr, msg) < 0) + goto done; + retval = 0; done: if (msg) free(msg); return retval; } -/*! Translate from numeric error to string representation - */ -char * -clicon_strerror(int err) -{ - return clicon_strerror1(err, EV); -} - /*! Push an error state, if recursive error handling + * + * @see clixon_err_vars */ void* -clicon_err_save(void) +clixon_err_save(void) { struct err_state *es; if ((es = malloc(sizeof(*es))) == NULL) return NULL; - es->es_errno = clicon_errno; - es->es_suberrno = clicon_suberrno; - strncpy(es->es_reason, clicon_err_reason, ERR_STRLEN); + es->es_category = _err_category; + es->es_subnr = _err_subnr; + strncpy(es->es_reason, _err_reason, ERR_STRLEN); return (void*)es; } /*! Pop an error state, if recursive error handling */ int -clicon_err_restore(void* handle) +clixon_err_restore(void* handle) { struct err_state *es; if ((es = (struct err_state *)handle) != NULL){ - clicon_errno = es->es_errno; - clicon_suberrno = es->es_suberrno; - strncpy(clicon_err_reason, es->es_reason, ERR_STRLEN); + _err_category = es->es_category; + _err_subnr = es->es_subnr; + strncpy(_err_reason, es->es_reason, ERR_STRLEN); free(es); } return 0; @@ -341,18 +429,18 @@ clicon_err_restore(void* handle) /*! Register error categories for application-based error handling * - * @param[in] category Applies for this category (first arg to clicon_err()) + * @param[in] category Applies for this category (first arg to clixon_err()) * @param[in] logfn Call att error for generating application-defined errstring */ int -clixon_err_cat_reg(enum clicon_err category, - void *handle, - clixon_cat_log_cb logfn) +clixon_err_cat_reg(enum clixon_err category, + void *handle, + clixon_cat_log_cb logfn) { clixon_err_cats *cec; if ((cec = malloc(sizeof *cec)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return -1; } memset(cec, 0, sizeof *cec); diff --git a/lib/src/clixon_event.c b/lib/src/clixon_event.c index b5820d67..8c6cbba7 100644 --- a/lib/src/clixon_event.c +++ b/lib/src/clixon_event.c @@ -56,9 +56,10 @@ #include #include "clixon_queue.h" -#include "clixon_log.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_err.h" #include "clixon_sig.h" #include "clixon_proc.h" @@ -184,7 +185,7 @@ clixon_event_reg_fd(int fd, struct event_data *e; if ((e = (struct event_data *)malloc(sizeof(struct event_data))) == NULL){ - clicon_err(OE_EVENTS, errno, "malloc"); + clixon_err(OE_EVENTS, errno, "malloc"); return -1; } memset(e, 0, sizeof(struct event_data)); @@ -267,11 +268,11 @@ clixon_event_reg_timeout(struct timeval t, struct event_data **e_prev; if (str == NULL || fn == NULL){ - clicon_err(OE_CFG, EINVAL, "str or fn is NULL"); + clixon_err(OE_CFG, EINVAL, "str or fn is NULL"); goto done; } if ((e = (struct event_data *)malloc(sizeof(struct event_data))) == NULL){ - clicon_err(OE_EVENTS, errno, "malloc"); + clixon_err(OE_EVENTS, errno, "malloc"); return -1; } memset(e, 0, sizeof(struct event_data)); @@ -344,7 +345,7 @@ clixon_event_poll(int fd) FD_ZERO(&fdset); FD_SET(fd, &fdset); if ((retval = select(FD_SETSIZE, &fdset, NULL, NULL, &tnull)) < 0) - clicon_err(OE_EVENTS, errno, "select"); + clixon_err(OE_EVENTS, errno, "select"); return retval; } @@ -358,7 +359,7 @@ clixon_event_poll(int fd) * One could try to poll the file descriptors after a timeout? */ int -clixon_event_loop(clicon_handle h) +clixon_event_loop(clixon_handle h) { struct event_data *e; struct event_data *e_next; @@ -407,7 +408,7 @@ clixon_event_loop(clicon_handle h) */ clixon_debug(CLIXON_DBG_DEFAULT, "%s select: %s", __FUNCTION__, strerror(errno)); if (clixon_exit_get() == 1){ - clicon_err(OE_EVENTS, errno, "select"); + clixon_err(OE_EVENTS, errno, "select"); retval = 0; } else if (clicon_sig_child_get()){ @@ -422,10 +423,10 @@ clixon_event_loop(clicon_handle h) continue; } else - clicon_err(OE_EVENTS, errno, "select"); + clixon_err(OE_EVENTS, errno, "select"); } else - clicon_err(OE_EVENTS, errno, "select"); + clixon_err(OE_EVENTS, errno, "select"); goto err; } if (n==0){ /* Timeout */ diff --git a/lib/src/clixon_file.c b/lib/src/clixon_file.c index 0c334c90..41b2e693 100644 --- a/lib/src/clixon_file.c +++ b/lib/src/clixon_file.c @@ -55,11 +55,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" +/* clixon */ #include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_string.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_file.h" /*! qsort "compar" for directory alphabetically sorting, see qsort(3) @@ -91,7 +94,7 @@ clicon_files_recursive1(const char *dir, struct stat st; if (dir == NULL){ - clicon_err(OE_UNIX, EINVAL, "Requires dir != NULL"); + clixon_err(OE_UNIX, EINVAL, "Requires dir != NULL"); goto done; } if ((dirp = opendir(dir)) != NULL) @@ -115,13 +118,13 @@ clicon_files_recursive1(const char *dir, continue; snprintf(path, MAXPATHLEN-1, "%s/%s", dir, dent->d_name); if ((res = lstat(path, &st)) != 0){ - clicon_err(OE_UNIX, errno, "lstat"); + clixon_err(OE_UNIX, errno, "lstat"); goto done; } if ((st.st_mode & S_IFREG) == 0) continue; if (cvec_add_string(cvv, dent->d_name, path) < 0){ - clicon_err(OE_UNIX, errno, "cvec_add_string"); + clixon_err(OE_UNIX, errno, "cvec_add_string"); goto done; } } @@ -148,7 +151,7 @@ clicon_files_recursive(const char *dir, clixon_debug(CLIXON_DBG_DETAIL, "%s dir:%s", __FUNCTION__, dir); if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) { regerror(res, &re, errbuf, sizeof(errbuf)); - clicon_err(OE_DB, 0, "regcomp: %s", errbuf); + clixon_err(OE_DB, 0, "regcomp: %s", errbuf); goto done; } if (clicon_files_recursive1(dir, &re, cvv) < 0) @@ -206,14 +209,14 @@ clicon_file_dirent(const char *dir, nent = 0; if (regexp && (res = regcomp(&re, regexp, REG_EXTENDED)) != 0) { regerror(res, &re, errbuf, sizeof(errbuf)); - clicon_err(OE_DB, 0, "regcomp: %s", errbuf); + clixon_err(OE_DB, 0, "regcomp: %s", errbuf); return -1; } if ((dirp = opendir(dir)) == NULL) { if (errno == ENOENT) /* Dir does not exist -> return 0 matches */ retval = 0; else - clicon_err(OE_UNIX, errno, "opendir(%s)", dir); + clixon_err(OE_UNIX, errno, "opendir(%s)", dir); goto quit; } while((dent = readdir(dirp)) != NULL) { @@ -227,7 +230,7 @@ clicon_file_dirent(const char *dir, snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dent->d_name); res = lstat(filename, &st); if (res != 0) { - clicon_err(OE_UNIX, errno, "lstat"); + clixon_err(OE_UNIX, errno, "lstat"); goto quit; } if ((type & st.st_mode) == 0) @@ -235,7 +238,7 @@ clicon_file_dirent(const char *dir, } direntStructSize = offsetof(struct dirent, d_name) + strlen(dent->d_name) + 1; if ((new = realloc(new, (nent+1)*sizeof(struct dirent))) == NULL) { - clicon_err(OE_UNIX, errno, "realloc"); + clixon_err(OE_UNIX, errno, "realloc"); goto quit; } /* realloc */ clixon_debug(CLIXON_DBG_DETAIL, "%s memcpy(%p %p %u", __FUNCTION__, &new[nent], dent, direntStructSize); @@ -280,21 +283,21 @@ clicon_file_copy(char *src, struct stat st; if (stat(src, &st) != 0){ - clicon_err(OE_UNIX, errno, "stat"); + clixon_err(OE_UNIX, errno, "stat"); return -1; } if((inF = open(src, O_RDONLY)) == -1) { - clicon_err(OE_UNIX, errno, "open(%s) for read", src); + clixon_err(OE_UNIX, errno, "open(%s) for read", src); return -1; } if((ouF = open(target, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode)) == -1) { - clicon_err(OE_UNIX, errno, "open(%s) for write", target); + clixon_err(OE_UNIX, errno, "open(%s) for write", target); err = errno; goto error; } while((bytes = read(inF, line, sizeof(line))) > 0) if (write(ouF, line, bytes) < 0){ - clicon_err(OE_UNIX, errno, "write(%s)", src); + clixon_err(OE_UNIX, errno, "write(%s)", src); err = errno; goto error; } @@ -327,16 +330,16 @@ clicon_file_cbuf(const char *filename, struct stat st; if (stat(filename, &st) != 0){ - clicon_err(OE_UNIX, errno, "stat"); + clixon_err(OE_UNIX, errno, "stat"); return -1; } if ((fd = open(filename, O_RDONLY)) == -1) { - clicon_err(OE_UNIX, errno, "open(%s) for read", filename); + clixon_err(OE_UNIX, errno, "open(%s) for read", filename); return -1; } while((bytes = read(fd, line, sizeof(line))) > 0) if (cbuf_append_buf(cb, line, bytes) < 0){ - clicon_err(OE_UNIX, errno, "cbuf_append_buf(%s)", filename); + clixon_err(OE_UNIX, errno, "cbuf_append_buf(%s)", filename); err = errno; goto error; } diff --git a/lib/src/clixon_handle.c b/lib/src/clixon_handle.c index fa16524f..e7703dad 100644 --- a/lib/src/clixon_handle.c +++ b/lib/src/clixon_handle.c @@ -49,11 +49,12 @@ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_err.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -61,15 +62,15 @@ #include "clixon_data.h" #include "clixon_options.h" -#define CLICON_MAGIC 0x99aafabe +#define CLIXON_MAGIC 0x99aafabe -#define handle(h) (assert(clicon_handle_check(h)==0),(struct clicon_handle *)(h)) +#define handle(h) (assert(clixon_handle_check(h)==0),(struct clixon_handle *)(h)) /*! Internal structure of basic handle. Also header of all other handles. * * @note If you change here, you must also change the structs below: * This is the internal definition of a "Clixon handle" which in its external - * form is "clicon_handle" and is used in most Clixon API calls. + * form is "clixon_handle" and is used in most Clixon API calls. * Some details: * 1) the internal structure contains a header (defined here) whereas higher * order libs (eg cli and backend) introduce more fields appended to this @@ -86,7 +87,7 @@ * @see struct backend_handle * @see struct restconf_handle */ -struct clicon_handle { +struct clixon_handle { int ch_magic; /* magic (HDR) */ clicon_hash_t *ch_copt; /* clicon option list (HDR) */ clicon_hash_t *ch_data; /* internal clicon data (HDR) */ @@ -103,31 +104,31 @@ struct clicon_handle { * So far the only common options is a MAGIC cookie for sanity checks and * CLICON options */ -clicon_handle -clicon_handle_init0(int size) +clixon_handle +clixon_handle_init0(int size) { - struct clicon_handle *ch; - clicon_handle h = NULL; + struct clixon_handle *ch; + clixon_handle h = NULL; if ((ch = malloc(size)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(ch, 0, size); - ch->ch_magic = CLICON_MAGIC; + ch->ch_magic = CLIXON_MAGIC; if ((ch->ch_copt = clicon_hash_init()) == NULL){ - clicon_handle_exit((clicon_handle)ch); + clixon_handle_exit((clixon_handle)ch); goto done; } if ((ch->ch_data = clicon_hash_init()) == NULL){ - clicon_handle_exit((clicon_handle)ch); + clixon_handle_exit((clixon_handle)ch); goto done; } if ((ch->ch_db_elmnt = clicon_hash_init()) == NULL){ - clicon_handle_exit((clicon_handle)ch); + clixon_handle_exit((clixon_handle)ch); goto done; } - h = (clicon_handle)ch; + h = (clixon_handle)ch; done: return h; } @@ -140,10 +141,10 @@ clicon_handle_init0(int size) * elaborate applications (cli/backend/netconf). This should be used by the most * basic applications that use CLICON lib directly. */ -clicon_handle -clicon_handle_init(void) +clixon_handle +clixon_handle_init(void) { - return clicon_handle_init0(sizeof(struct clicon_handle)); + return clixon_handle_init0(sizeof(struct clixon_handle)); } /*! Deallocate clicon handle, including freeing handle data. @@ -154,10 +155,10 @@ clicon_handle_init(void) * @note: handle 'h' cannot be used in calls after this */ int -clicon_handle_exit(clicon_handle h) +clixon_handle_exit(clixon_handle h) { int retval = -1; - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); clicon_hash_t *ha; if ((ha = clicon_options(h)) != NULL) @@ -179,12 +180,12 @@ clicon_handle_exit(clicon_handle h) * @retval -1 Sanity check failed */ int -clicon_handle_check(clicon_handle h) +clixon_handle_check(clixon_handle h) { /* Dont use handle macro to avoid recursion */ - struct clicon_handle *ch = (struct clicon_handle *)(h); + struct clixon_handle *ch = (struct clixon_handle *)(h); - return ch->ch_magic == CLICON_MAGIC ? 0 : -1; + return ch->ch_magic == CLIXON_MAGIC ? 0 : -1; } /*! Return clicon options (hash-array) given a handle. @@ -192,9 +193,9 @@ clicon_handle_check(clicon_handle h) * @param[in] h Clixon handle */ clicon_hash_t * -clicon_options(clicon_handle h) +clicon_options(clixon_handle h) { - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); return ch->ch_copt; } @@ -204,9 +205,9 @@ clicon_options(clicon_handle h) * @param[in] h Clixon handle */ clicon_hash_t * -clicon_data(clicon_handle h) +clicon_data(clixon_handle h) { - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); return ch->ch_data; } @@ -216,9 +217,9 @@ clicon_data(clicon_handle h) * @param[in] h Clixon handle */ clicon_hash_t * -clicon_db_elmnt(clicon_handle h) +clicon_db_elmnt(clixon_handle h) { - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); return ch->ch_db_elmnt; } @@ -228,28 +229,28 @@ clicon_db_elmnt(clicon_handle h) * @param[in] h Clixon handle */ event_stream_t * -clicon_stream(clicon_handle h) +clicon_stream(clixon_handle h) { - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); return ch->ch_stream; } int -clicon_stream_set(clicon_handle h, +clicon_stream_set(clixon_handle h, event_stream_t *es) { - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); ch->ch_stream = es; return 0; } int -clicon_stream_append(clicon_handle h, +clicon_stream_append(clixon_handle h, event_stream_t *es) { - struct clicon_handle *ch = handle(h); + struct clixon_handle *ch = handle(h); ADDQ(es, ch->ch_stream); return 0; diff --git a/lib/src/clixon_hash.c b/lib/src/clixon_hash.c index d3a26240..0805a3b3 100644 --- a/lib/src/clixon_hash.c +++ b/lib/src/clixon_hash.c @@ -95,8 +95,9 @@ /* clixon */ #include "clixon_queue.h" -#include "clixon_err.h" #include "clixon_hash.h" +#include "clixon_handle.h" +#include "clixon_err.h" #define HASH_SIZE 1031 /* Number of hash buckets. Should be a prime */ #define align4(s) (((s)/4)*4 + 4) @@ -125,7 +126,7 @@ clicon_hash_init(void) clicon_hash_t *hash; if ((hash = (clicon_hash_t *)malloc(sizeof(clicon_hash_t) * HASH_SIZE)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(hash, 0, sizeof(clicon_hash_t)*HASH_SIZE); @@ -197,7 +198,7 @@ clicon_hash_value(clicon_hash_t *hash, clicon_hash_t h; if (hash == NULL){ - clicon_err(OE_UNIX, EINVAL, "hash is NULL"); + clixon_err(OE_UNIX, EINVAL, "hash is NULL"); return NULL; } h = clicon_hash_lookup(hash, key); @@ -230,26 +231,26 @@ clicon_hash_add(clicon_hash_t *hash, clicon_hash_t new = NULL; if (hash == NULL){ - clicon_err(OE_UNIX, EINVAL, "hash is NULL"); + clixon_err(OE_UNIX, EINVAL, "hash is NULL"); return NULL; } /* Check NULL case */ if ((val == NULL && vlen != 0) || (val != NULL && vlen == 0)){ - clicon_err(OE_UNIX, EINVAL, "Mismatch in value and length, only one is zero"); + clixon_err(OE_UNIX, EINVAL, "Mismatch in value and length, only one is zero"); goto catch; } /* If variable exist, don't allocate a new. just replace value */ h = clicon_hash_lookup(hash, key); if (h == NULL) { if ((new = (clicon_hash_t)malloc(sizeof(*new))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto catch; } memset(new, 0, sizeof(*new)); new->h_key = strdup(key); if (new->h_key == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto catch; } h = new; @@ -258,7 +259,7 @@ clicon_hash_add(clicon_hash_t *hash, /* Make copy of value. aligned */ newval = malloc(align4(vlen+3)); if (newval == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto catch; } memcpy(newval, val, vlen); @@ -299,7 +300,7 @@ clicon_hash_del(clicon_hash_t *hash, clicon_hash_t h; if (hash == NULL){ - clicon_err(OE_UNIX, EINVAL, "hash is NULL"); + clixon_err(OE_UNIX, EINVAL, "hash is NULL"); return -1; } h = clicon_hash_lookup(hash, key); @@ -334,7 +335,7 @@ clicon_hash_keys(clicon_hash_t *hash, char **keys = NULL; if (hash == NULL){ - clicon_err(OE_UNIX, EINVAL, "hash is NULL"); + clixon_err(OE_UNIX, EINVAL, "hash is NULL"); return -1; } *nkeys = 0; @@ -345,7 +346,7 @@ clicon_hash_keys(clicon_hash_t *hash, break; tmp = realloc(keys, ((*nkeys)+1) * sizeof(char *)); if (tmp == NULL){ - clicon_err(OE_UNIX, errno, "realloc"); + clixon_err(OE_UNIX, errno, "realloc"); goto catch; } keys = tmp; diff --git a/lib/src/clixon_instance_id_parse.l b/lib/src/clixon_instance_id_parse.l index fcf22773..6a1e72a6 100644 --- a/lib/src/clixon_instance_id_parse.l +++ b/lib/src/clixon_instance_id_parse.l @@ -65,6 +65,7 @@ #include "clixon_handle.h" #include "clixon_yang.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_string.h" #include "clixon_xml.h" #include "clixon_path.h" diff --git a/lib/src/clixon_instance_id_parse.y b/lib/src/clixon_instance_id_parse.y index 045e5baa..4e8e7c46 100644 --- a/lib/src/clixon_instance_id_parse.y +++ b/lib/src/clixon_instance_id_parse.y @@ -95,7 +95,7 @@ /* typecast macro */ #define _IY ((clixon_instance_id_yacc *)_iy) -#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_instance_id_parsetext, _IY->iy_linenum); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_instance_id_parsetext, _IY->iy_linenum); YYERROR;} /* add _yy to error parameters */ #define YY_(msgid) msgid @@ -115,12 +115,13 @@ #include -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_queue.h" #include "clixon_string.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_path.h" @@ -140,7 +141,7 @@ void clixon_instance_id_parseerror(void *_iy, char *s) { - clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", + clixon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", _IY->iy_name, _IY->iy_linenum , s, @@ -198,17 +199,17 @@ path_new(char *prefix, clixon_debug(CLIXON_DBG_DETAIL, "%s(%s,%s)", __FUNCTION__, prefix, id); if ((cp = malloc(sizeof(*cp))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(cp, 0, sizeof(*cp)); if (prefix) if ((cp->cp_prefix = strdup(prefix)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if ((cp->cp_id = strdup(id)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } return cp; @@ -228,18 +229,18 @@ keyval_pos(char *uint) clixon_debug(CLIXON_DBG_DETAIL, "%s(%s)", __FUNCTION__, uint); if ((cvv = cvec_new(1)) == NULL) { - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } cv = cvec_i(cvv, 0); cv_type_set(cv, CGV_UINT32); if ((ret = cv_parse1(uint, cv, &reason)) < 0){ - clicon_err(OE_UNIX, errno, "cv_parse1"); + clixon_err(OE_UNIX, errno, "cv_parse1"); cvv = NULL; goto done; } if (ret == 0){ - clicon_err(OE_UNIX, errno, "cv_parse1: %s", reason); + clixon_err(OE_UNIX, errno, "cv_parse1: %s", reason); cvv = NULL; goto done; } @@ -265,11 +266,11 @@ keyval_add(cvec *cvv, goto done; if (cvv == NULL && (cvv = cvec_new(0)) == NULL) { - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (cvec_append_var(cvv, cv) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_append_var"); + clixon_err(OE_UNIX, errno, "cvec_append_var"); cvv = NULL; goto done; } @@ -288,16 +289,16 @@ keyval_set(char *name, clixon_debug(CLIXON_DBG_DETAIL, "%s(%s=%s)", __FUNCTION__, name, val); if ((cv = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_UNIX, errno, "cv_new"); + clixon_err(OE_UNIX, errno, "cv_new"); goto done; } if (name && cv_name_set(cv, name) == NULL){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); cv = NULL; goto done; } if (cv_string_set(cv, val) == NULL){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); cv = NULL; goto done; } diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index ae7f68ae..7b5770e6 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -58,12 +58,13 @@ #include /* clixon */ -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_queue.h" #include "clixon_string.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_options.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -355,7 +356,7 @@ json2xml_decode_identityref(cxobj *x, /* Here prefix2 is valid and can be NULL Change body prefix to prefix2:id */ if ((cbv = cbuf_new()) == NULL){ - clicon_err(OE_JSON, errno, "cbuf_new"); + clixon_err(OE_JSON, errno, "cbuf_new"); goto done; } if (prefix2) @@ -540,7 +541,7 @@ xml2json_encode_leafs(cxobj *xb, cbuf *cb = NULL; /* the variable itself */ if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } body = xb?xml_value(xb):NULL; @@ -953,7 +954,7 @@ xml2json1_cbuf(cbuf *cb, break; } if ((metacbc = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Check for typed sub-body if: @@ -1282,7 +1283,7 @@ clixon_json2file(FILE *f, if (fn == NULL) fn = fprintf; if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (clixon_json2cbuf(cb, xn, pretty, skiptop, autocliext) < 0) @@ -1335,7 +1336,7 @@ xml2json_vec(FILE *f, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (xml2json_cbuf_vec(cb, vec, veclen, pretty, skiptop) < 0) @@ -1428,7 +1429,7 @@ json_xmlns_translate(yang_stmt *yspec, * @param[out] xerr Reason for invalid returned as netconf err msg * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) - * @retval -1 Error with clicon_err called + * @retval -1 Error * * @see _xml_parse for XML variant * @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf @@ -1460,9 +1461,9 @@ _json_parse(char *str, if (json_parse_init(&jy) < 0) goto done; if (clixon_json_parseparse(&jy) != 0) { /* yacc returns 1 on error */ - clicon_log(LOG_NOTICE, "JSON error: line %d", jy.jy_linenum); - if (clicon_errno == 0) - clicon_err(OE_JSON, 0, "JSON parser error with no error code (should not happen)"); + clixon_log(NULL, LOG_NOTICE, "JSON error: line %d", jy.jy_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_JSON, 0, "JSON parser error with no error code (should not happen)"); goto done; } /* Traverse new objects */ @@ -1475,7 +1476,7 @@ _json_parse(char *str, /* XXX: For top-level config file: */ if (yb != YB_NONE || strcmp(xml_name(x),DATASTORE_TOP_SYMBOL)!=0){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "Top-level JSON object %s is not qualified with namespace which is a MUST according to RFC 7951", xml_name(x)); @@ -1559,7 +1560,7 @@ _json_parse(char *str, * @param[out] xerr Reason for invalid returned as netconf err msg * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) w xerr set - * @retval -1 Error with clicon_err called + * @retval -1 Error * * @code * cxobj *x = NULL; @@ -1581,7 +1582,7 @@ clixon_json_parse_string(char *str, { clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (xt==NULL){ - clicon_err(OE_JSON, EINVAL, "xt is NULL"); + clixon_err(OE_JSON, EINVAL, "xt is NULL"); return -1; } if (*xt == NULL){ @@ -1611,7 +1612,7 @@ clixon_json_parse_string(char *str, * @param[out] xerr Reason for invalid returned as netconf err msg * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) w xerr set - * @retval -1 Error with clicon_err called + * @retval -1 Error * * @code * cxobj *xt = NULL; @@ -1643,18 +1644,18 @@ clixon_json_parse_file(FILE *fp, int len = 0; if (xt==NULL){ - clicon_err(OE_JSON, EINVAL, "xt is NULL"); + clixon_err(OE_JSON, EINVAL, "xt is NULL"); return -1; } if ((jsonbuf = malloc(jsonbuflen)) == NULL){ - clicon_err(OE_JSON, errno, "malloc"); + clixon_err(OE_JSON, errno, "malloc"); goto done; } memset(jsonbuf, 0, jsonbuflen); ptr = jsonbuf; while (1){ if ((ret = fread(&ch, 1, 1, fp)) < 0){ - clicon_err(OE_JSON, errno, "read"); + clixon_err(OE_JSON, errno, "read"); break; } if (ret != 0) @@ -1675,7 +1676,7 @@ clixon_json_parse_file(FILE *fp, oldjsonbuflen = jsonbuflen; jsonbuflen *= 2; if ((jsonbuf = realloc(jsonbuf, jsonbuflen)) == NULL){ - clicon_err(OE_JSON, errno, "realloc"); + clixon_err(OE_JSON, errno, "realloc"); goto done; } memset(jsonbuf+oldjsonbuflen, 0, jsonbuflen-oldjsonbuflen); diff --git a/lib/src/clixon_json_parse.l b/lib/src/clixon_json_parse.l index 16c58205..15d73d1d 100644 --- a/lib/src/clixon_json_parse.l +++ b/lib/src/clixon_json_parse.l @@ -57,6 +57,7 @@ #include "clixon_string.h" #include "clixon_yang.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_xml.h" #include "clixon_json_parse.h" diff --git a/lib/src/clixon_json_parse.y b/lib/src/clixon_json_parse.y index ef48a27f..344202d2 100644 --- a/lib/src/clixon_json_parse.y +++ b/lib/src/clixon_json_parse.y @@ -104,7 +104,7 @@ object. /* typecast macro */ #define _JY ((clixon_json_yacc *)_jy) -#define _YYERROR(msg) {clicon_err(OE_JSON, 0, "YYERROR %s '%s' %d", (msg), clixon_json_parsetext, _JY->jy_linenum); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_JSON, 0, "YYERROR %s '%s' %d", (msg), clixon_json_parsetext, _JY->jy_linenum); YYERROR;} /* add _yy to error parameters */ #define YY_(msgid) msgid @@ -124,12 +124,14 @@ object. #include +/* clixon */ +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" -#include "clixon_queue.h" +#include "clixon_debug.h" #include "clixon_string.h" -#include "clixon_hash.h" -#include "clixon_handle.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -152,7 +154,7 @@ void clixon_json_parseerror(void *_jy, char *s) { - clicon_err(OE_JSON, 0, "json_parse: line %d: %s at or before: '%s'", + clixon_err(OE_JSON, 0, "json_parse: line %d: %s at or before: '%s'", _JY->jy_linenum, s, clixon_json_parsetext); @@ -164,7 +166,6 @@ clixon_json_parseerror(void *_jy, int json_parse_init(clixon_json_yacc *jy) { - // clixon_debug_init(2, NULL); return 0; } diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c index 8d8538d3..547d5bea 100644 --- a/lib/src/clixon_log.c +++ b/lib/src/clixon_log.c @@ -1,4 +1,4 @@ -/* + /* * ***** BEGIN LICENSE BLOCK ***** @@ -56,61 +56,86 @@ /* cligen */ #include -/* clicon */ +/* clixon */ +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_err.h" +#include "clixon_debug.h" #include "clixon_log.h" -/* The global debug level. 0 means no debug - * @note There are pros and cons in having the debug state as a global variable. The - * alternative to bind it to the clicon handle (h) was considered but it limits its - * usefulness, since not all functions have h +/* + * Local Variables */ -static int _clixon_debug = 0; -/* Bitmask whether to log to syslog or stderr: CLICON_LOG_STDERR | CLICON_LOG_SYSLOG */ -static int _logflags = 0x0; +/* Cache handle since some error calls does not have handle access */ +static clixon_handle _log_clixon_h = NULL; + +/* Bitmask whether to log to syslog or stderr: CLIXON_LOG_STDERR | CLIXON_LOG_SYSLOG */ +static int _log_flags = 0x0; /* Set to open file to write debug messages directly to file */ -static FILE *_logfile = NULL; +static FILE *_log_file = NULL; /* Truncate debug strings to this length. 0 means unlimited */ -static int _clixon_log_trunc = 0; +static int _log_trunc = 0; /*! Initialize system logger. * * Make syslog(3) calls with specified ident and gates calls of level upto specified level (upto). * May also print to stderr, if err is set. - * Applies to clicon_err() and clixon_debug too + * Applies to clixon_err() and clixon_debug too * + * @param[in] h Clixon handle * @param[in] ident prefix that appears on syslog (eg 'cli') * @param[in] upto log priority, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG (see syslog(3)). - * @param[in] flags bitmask: if CLICON_LOG_STDERR, then print logs to stderr - * if CLICON_LOG_SYSLOG, then print logs to syslog + * @param[in] flags bitmask: if CLIXON_LOG_STDERR, then print logs to stderr + * if CLIXON_LOG_SYSLOG, then print logs to syslog * You can do a combination of both + * @retval 0 OK * @code - * clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR); + * clixon_log_init(__PROGRAM__, LOG_INFO, CLIXON_LOG_STDERR); * @endcode */ int -clicon_log_init(char *ident, - int upto, - int flags) +clixon_log_init(clixon_handle h, + char *ident, + int upto, + int flags) { - _logflags = flags; - if (flags & CLICON_LOG_SYSLOG){ + if (h == NULL){ + errno = EINVAL; + return -1; + } + _log_clixon_h = h; + _log_flags = flags; + if (flags & CLIXON_LOG_SYSLOG){ if (setlogmask(LOG_UPTO(upto)) < 0) /* Cant syslog here */ fprintf(stderr, "%s: setlogmask: %s\n", __FUNCTION__, strerror(errno)); - openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clicon_log */ + openlog(ident, LOG_PID, LOG_USER); /* LOG_PUSER is achieved by direct stderr logs in clixon_log */ } return 0; } +#ifdef COMPAT_6_5 +/* Required for clixon-example autoconf + */ int -clicon_log_exit(void) +clicon_log_init(char *ident, + int upto, + int flags) { - if (_logfile) - fclose(_logfile); + return clixon_log_init(NULL, ident, upto, flags); +} + +#endif + +int +clixon_log_exit(void) +{ + if (_log_file) + fclose(_log_file); closelog(); /* optional */ return 0; } @@ -118,26 +143,26 @@ clicon_log_exit(void) /*! Utility function to set log destination/flag using command-line option * * @param[in] c Log option,one of s,f,e,o - * @retval 0 One of CLICON_LOG_SYSLOG|STDERR|STDOUT|FILE + * @retval 0 One of CLIXON_LOG_SYSLOG|STDERR|STDOUT|FILE * @retval -1 No match */ int -clicon_log_opt(char c) +clixon_log_opt(char c) { int logdst = -1; switch (c){ case 's': - logdst = CLICON_LOG_SYSLOG; + logdst = CLIXON_LOG_SYSLOG; break; case 'e': - logdst = CLICON_LOG_STDERR; + logdst = CLIXON_LOG_STDERR; break; case 'o': - logdst = CLICON_LOG_STDOUT; + logdst = CLIXON_LOG_STDOUT; break; case 'f': - logdst = CLICON_LOG_FILE; + logdst = CLIXON_LOG_FILE; break; case 'n': logdst = 0; @@ -148,7 +173,7 @@ clicon_log_opt(char c) return logdst; } -/*! If log flags include CLICON_LOG_FILE, set the file +/*! If log flags include CLIXON_LOG_FILE, set the file * * @param[in] filename File to log to * @retval 0 OK @@ -156,38 +181,64 @@ clicon_log_opt(char c) * @see clixon_debug_init where a strean */ int -clicon_log_file(char *filename) +clixon_log_file(char *filename) { - if (_logfile) - fclose(_logfile); - if ((_logfile = fopen(filename, "a")) == NULL){ - fprintf(stderr, "fopen: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + if (_log_file) + fclose(_log_file); + if ((_log_file = fopen(filename, "a")) == NULL){ + fprintf(stderr, "fopen: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ return -1; } return 0; } int -clicon_get_logflags(void) +clixon_get_logflags(void) { - return _logflags; + return _log_flags; } /*! Truncate log/debug string length */ int -clicon_log_string_limit_set(size_t sz) +clixon_log_string_limit_set(size_t sz) { - _clixon_log_trunc = sz; + _log_trunc = sz; return 0; } /*! Get truncate log/debug string length */ size_t -clicon_log_string_limit_get(void) +clixon_log_string_limit_get(void) { - return _clixon_log_trunc; + return _log_trunc; +} + +/*! Translate month number (0..11) to a three letter month name + * + * @param[in] md month number, where 0 is january + */ +static char * +mon2name(int md) +{ + switch(md){ + case 0: return "Jan"; + case 1: return "Feb"; + case 2: return "Mar"; + case 3: return "Apr"; + case 4: return "May"; + case 5: return "Jun"; + case 6: return "Jul"; + case 7: return "Aug"; + case 8: return "Sep"; + case 9: return "Oct"; + case 10: return "Nov"; + case 11: return "Dec"; + default: + break; + } + return NULL; } /*! Mimic syslog and print a time on file f @@ -241,28 +292,28 @@ slogtime(void) * @see clixon_debug */ int -clicon_log_str(int level, +clixon_log_str(int level, char *msg) { - if (_logflags & CLICON_LOG_SYSLOG) + if (_log_flags & CLIXON_LOG_SYSLOG) syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg); // XXX this may block /* syslog makes own filtering, we do it here: * if normal (not debug) then filter loglevels >= debug */ - if (_clixon_debug == 0 && level >= LOG_DEBUG) + if (clixon_debug_get() == 0 && level >= LOG_DEBUG) goto done; - if (_logflags & CLICON_LOG_STDERR){ + if (_log_flags & CLIXON_LOG_STDERR){ flogtime(stderr); fprintf(stderr, "%s\n", msg); } - if (_logflags & CLICON_LOG_STDOUT){ + if (_log_flags & CLIXON_LOG_STDOUT){ flogtime(stdout); fprintf(stdout, "%s\n", msg); } - if ((_logflags & CLICON_LOG_FILE) && _logfile){ - flogtime(_logfile); - fprintf(_logfile, "%s\n", msg); - fflush(_logfile); + if ((_log_flags & CLIXON_LOG_FILE) && _log_file){ + flogtime(_log_file); + fprintf(_log_file, "%s\n", msg); + fflush(_log_file); } /* Enable this if you want syslog in a stream. But there are problems with * recursion @@ -273,20 +324,22 @@ clicon_log_str(int level, /*! Make a logging call to syslog using variable arg syntax. * - * @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. This - * is OR:d with facility == LOG_USER - * @param[in] format Message to print as argv. - * @retval 0 OK - * @retval -1 Error + * @param[in] h Clixon handle (may be NULL) + * @param[in] level Log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. This + * is OR:d with facility == LOG_USER + * @param[in] format Message to print as argv. + * @retval 0 OK + * @retval -1 Error * @code - clicon_log(LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__); + clixon_log(h, LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__); * @endcode - * @see clicon_log_init clicon_log_str - * @see clicon_log_xml + * @see clixon_log_init clixon_log_str + * @see clixon_log_xml */ int -clicon_log(int level, - const char *format, ...) +clixon_log(clixon_handle h, + int level, + const char *format, ...) { int retval = -1; va_list args; @@ -300,12 +353,12 @@ clicon_log(int level, va_end(args); /* Truncate long debug strings */ - if ((trunc = clicon_log_string_limit_get()) && trunc < len) + if ((trunc = clixon_log_string_limit_get()) && trunc < len) len = trunc; /* allocate a message string exactly fitting the message length */ if ((msg = malloc(len+1)) == NULL){ - fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } @@ -313,12 +366,12 @@ clicon_log(int level, va_start(args, format); if (vsnprintf(msg, len+1, format, args) < 0){ va_end(args); - fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } va_end(args); /* Actually log it */ - clicon_log_str(level, msg); + clixon_log_str(level, msg); retval = 0; done: @@ -326,123 +379,3 @@ clicon_log(int level, free(msg); return retval; } - -/*! Initialize debug messages. Set debug level. - * - * Initialize debug module. The level is used together with clixon_debug(dbglevel) calls as follows: - * print message if level >= dbglevel. - * Example: clixon_debug_init(1) -> debug(1) is printed, but not debug(2). - * Normally, debug messages are sent to clicon_log() which in turn can be sent to syslog and/or stderr. - * But you can also override this with a specific debug file so that debug messages are written on the file - * independently of log or errors. This is to ensure that a syslog of normal logs is unpolluted by extensive - * debugging. - * - * @param[in] dbglevel 0 is show no debug messages, 1 is normal, 2.. is high debug. - * Note this is _not_ level from syslog(3) - * @param[in] f Debug-file. Open file where debug messages are directed. - * If not NULL, it overrides the clicon_log settings which is otherwise - * where debug messages are directed. - * @see clicon_log_file where a filename can be given - */ -int -clixon_debug_init(int dbglevel, - FILE *f) -{ - _clixon_debug = dbglevel; /* Global variable */ - - if (f != NULL){ - if (_logfile) - fclose(_logfile); - _logfile = f; - } - return 0; -} - -int -clixon_debug_get(void) -{ - return _clixon_debug; -} - -/*! Print a debug message with debug-level. Settings determine where msg appears. - * - * If the dbglevel passed in the function is equal to or lower than the one set by - * clixon_debug_init(level). That is, only print debug messages <= than what you want: - * print message if level >= dbglevel. - * The message is sent to clicon_log. EIther to syslog, stderr or both, depending on - * clicon_log_init() setting - * @param[in] dbglevel Mask of CLIXON_DBG_DEFAULT and other masks - * @param[in] format Message to print as argv. - * @retval 0 OK - * @retval -1 Error - * @see clixon_debug_xml Specialization for XML tree - * @see CLIXON_DBG_DEFAULT and other flags - */ -int -clixon_debug(int dbglevel, - const char *format, ...) -{ - int retval = -1; - va_list args; - size_t len; - char *msg = NULL; - size_t trunc; - - /* Mask debug level with global dbg variable */ - if ((dbglevel & clixon_debug_get()) == 0) - return 0; - /* first round: compute length of debug message */ - va_start(args, format); - len = vsnprintf(NULL, 0, format, args); - va_end(args); - - /* Truncate long debug strings */ - if ((trunc = clicon_log_string_limit_get()) && trunc < len) - len = trunc; - /* allocate a message string exactly fitting the message length */ - if ((msg = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); - goto done; - } - /* second round: compute write message from format and args */ - va_start(args, format); - if (vsnprintf(msg, len+1, format, args) < 0){ - va_end(args); - clicon_err(OE_UNIX, errno, "vsnprintf"); - goto done; - } - va_end(args); - clicon_log_str(LOG_DEBUG, msg); - retval = 0; - done: - if (msg) - free(msg); - return retval; -} - -/*! Translate month number (0..11) to a three letter month name - * - * @param[in] md month number, where 0 is january - */ -char * -mon2name(int md) -{ - switch(md){ - case 0: return "Jan"; - case 1: return "Feb"; - case 2: return "Mar"; - case 3: return "Apr"; - case 4: return "May"; - case 5: return "Jun"; - case 6: return "Jul"; - case 7: return "Aug"; - case 8: return "Sep"; - case 9: return "Oct"; - case 10: return "Nov"; - case 11: return "Dec"; - default: - break; - } - return NULL; -} - diff --git a/lib/src/clixon_nacm.c b/lib/src/clixon_nacm.c index 9ac8b6f4..9555c6f2 100644 --- a/lib/src/clixon_nacm.c +++ b/lib/src/clixon_nacm.c @@ -56,10 +56,11 @@ /* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_string.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_options.h" @@ -345,7 +346,7 @@ prepvec_add(prepvec **pv_listp, prepvec *pv; if ((pv = malloc(sizeof(*pv))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(pv, 0, sizeof(*pv)); @@ -368,7 +369,7 @@ prepvec_add(prepvec **pv_listp, * @retval -1 Error */ static int -nacm_datanode_prepare(clicon_handle h, +nacm_datanode_prepare(clixon_handle h, cxobj *xt, enum nacm_access access, cxobj **gvec, @@ -446,7 +447,7 @@ nacm_datanode_prepare(clicon_handle h, continue; break; default: - clicon_err(OE_XML, EINVAL, "Access %d unupported (shouldnt happen)", access); + clixon_err(OE_XML, EINVAL, "Access %d unupported (shouldnt happen)", access); goto done; break; } @@ -464,7 +465,7 @@ nacm_datanode_prepare(clicon_handle h, path0 = clixon_trim2(xml_body(pathobj), " \t\n"); /* Get canonical namespace context for nacm paths */ if ((path = strdup(path0)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } #if 0 @@ -608,7 +609,7 @@ nacm_data_write_xrule_xml(cxobj *xn, * deny: Send error message */ static int -nacm_datanode_write_recurse(clicon_handle h, +nacm_datanode_write_recurse(clixon_handle h, cxobj *xn, prepvec *pv_list, int defpermit, @@ -685,7 +686,7 @@ nacm_datanode_write_recurse(clicon_handle h, * @see nacm_rpc */ int -nacm_datanode_write(clicon_handle h, +nacm_datanode_write(clixon_handle h, cxobj *xreq, cxobj *xt, enum nacm_access access, @@ -711,7 +712,7 @@ nacm_datanode_write(clicon_handle h, goto permit; /* write-default (create, update, or delete) has default deny so should never be NULL */ if ((write_default = xml_find_body(xnacm, "write-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No nacm write-default rule"); + clixon_err(OE_XML, EINVAL, "No nacm write-default rule"); goto done; } /* 3. Check all the "group" entries to see if any of them contain a @@ -891,7 +892,7 @@ nacm_data_read_xrule_xml(cxobj *xn, * @retval -1 Error */ static int -nacm_datanode_read_recurse(clicon_handle h, +nacm_datanode_read_recurse(clixon_handle h, cxobj *xn, prepvec *pv_list, yang_stmt *yspec) @@ -995,7 +996,7 @@ nacm_datanode_read_recurse(clicon_handle h, * @see nacm_rpc */ int -nacm_datanode_read(clicon_handle h, +nacm_datanode_read(clixon_handle h, cxobj *xt, cxobj **xrvec, size_t xrlen, @@ -1035,7 +1036,7 @@ nacm_datanode_read(clicon_handle h, goto done; /* read-default has default permit so should never be NULL */ if ((read_default = xml_find_body(xnacm, "read-default")) == NULL){ - clicon_err(OE_XML, EINVAL, "No nacm read-default rule"); + clixon_err(OE_XML, EINVAL, "No nacm read-default rule"); goto done; } /* First run through rules and cache rules as well as lookup objects in xt. @@ -1113,7 +1114,7 @@ nacm_datanode_read(clicon_handle h, * @see RFC8341 3.4 Access Control Enforcement Procedures */ static int -nacm_access_check(clicon_handle h, +nacm_access_check(clixon_handle h, cxobj *xnacm, char *peername, char *username) @@ -1210,7 +1211,7 @@ nacm_access_check(clicon_handle h, * @see RFC8341 3.4 Access Control Enforcement Procedures */ int -nacm_access_pre(clicon_handle h, +nacm_access_pre(clixon_handle h, char *peername, char *username, cxobj **xnacmp) @@ -1238,7 +1239,7 @@ nacm_access_pre(clicon_handle h, goto done; } else{ - clicon_err(OE_XML, 0, "Invalid NACM mode: %s", mode); + clixon_err(OE_XML, 0, "Invalid NACM mode: %s", mode); goto done; } if ((nsc = xml_nsctx_init(NULL, NACM_NS)) == NULL) @@ -1293,7 +1294,7 @@ nacm_access_pre(clicon_handle h, * - peer user is www (can be any NACM user) */ int -verify_nacm_user(clicon_handle h, +verify_nacm_user(clixon_handle h, enum nacm_credentials_t cred, char *peername, char *nacmname, @@ -1328,7 +1329,7 @@ verify_nacm_user(clicon_handle h, } if (strcmp(peername, nacmname) != 0){ if ((cbmsg = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cbmsg, "User %s credential not matching NACM user %s", peername, nacmname); diff --git a/lib/src/clixon_netconf_input.c b/lib/src/clixon_netconf_input.c index 60f1a61c..61ce9900 100644 --- a/lib/src/clixon_netconf_input.c +++ b/lib/src/clixon_netconf_input.c @@ -58,17 +58,18 @@ #include #include -/* clicon */ +/* cligen */ #include -/* Local includes */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_string.h" -#include "clixon_err.h" #include "clixon_handle.h" -#include "clixon_yang.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_io.h" #include "clixon_proto.h" @@ -98,7 +99,7 @@ netconf_input_read2(int s, if (errno == ECONNRESET) len = 0; /* emulate EOF */ else{ - clicon_log(LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno)); + clixon_log(NULL, LOG_ERR, "%s: read: %s", __FUNCTION__, strerror(errno)); goto done; } } /* read */ @@ -219,7 +220,7 @@ netconf_input_frame2(cbuf *cb, clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (xrecv == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "xrecv is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "xrecv is NULL"); goto done; } str = cbuf_get(cb); @@ -232,7 +233,7 @@ netconf_input_frame2(cbuf *cb, /* Fix to distinguish RPC and REPLIES */ if ((ret = clixon_xml_parse_string(str, yb, yspec, &xtop, xerr)) < 0){ /* XXX possibly should quit on -1? */ - if (netconf_operation_failed_xml(xerr, "rpc", clicon_err_reason)< 0) + if (netconf_operation_failed_xml(xerr, "rpc", clixon_err_reason())< 0) goto done; goto failed; } diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index ce87d80c..660ad497 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -59,10 +59,11 @@ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_string.h" -#include "clixon_err.h" #include "clixon_handle.h" -#include "clixon_yang.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_options.h" #include "clixon_data.h" @@ -146,7 +147,7 @@ netconf_in_use(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -169,7 +170,7 @@ netconf_invalid_value_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -268,7 +269,7 @@ netconf_too_big(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -293,7 +294,7 @@ netconf_missing_attribute_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -409,7 +410,7 @@ netconf_bad_attribute_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -481,7 +482,7 @@ netconf_unknown_attribute(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -508,7 +509,7 @@ netconf_common_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -780,7 +781,7 @@ netconf_access_denied_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -850,7 +851,7 @@ netconf_lock_denied(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -891,7 +892,7 @@ netconf_resource_denied(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -933,7 +934,7 @@ netconf_rollback_failed(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -974,7 +975,7 @@ netconf_data_exists(cbuf *cb, free(encstr); return retval; err: - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } @@ -1025,7 +1026,7 @@ netconf_data_missing_xml(cxobj **xret, cxobj *xerr; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1084,7 +1085,7 @@ netconf_missing_choice_xml(cxobj **xret, char *encpath = NULL; if (xret == NULL || name == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret or name is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret or name is NULL"); goto done; } if (*xret == NULL){ @@ -1158,7 +1159,7 @@ netconf_operation_not_supported_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1276,7 +1277,7 @@ netconf_operation_failed_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1365,7 +1366,7 @@ netconf_malformed_message_xml(cxobj **xret, char *encstr = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1451,7 +1452,7 @@ netconf_data_not_unique_xml(cxobj **xret, char *encpath = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1522,7 +1523,7 @@ netconf_minmax_elements_xml(cxobj **xret, char *encpath = NULL; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1578,7 +1579,7 @@ netconf_trymerge(cxobj *x, cxobj *xc; if (xret == NULL){ - clicon_err(OE_NETCONF, EINVAL, "xret is NULL"); + clixon_err(OE_NETCONF, EINVAL, "xret is NULL"); goto done; } if (*xret == NULL){ @@ -1621,13 +1622,13 @@ netconf_trymerge(cxobj *x, * @see netconf_module_load that is called later */ int -netconf_module_features(clicon_handle h) +netconf_module_features(clixon_handle h) { int retval = -1; cxobj *xc; if ((xc = clicon_conf_xml(h)) == NULL){ - clicon_err(OE_CFG, ENOENT, "Clicon configuration not loaded"); + clixon_err(OE_CFG, ENOENT, "Clicon configuration not loaded"); goto done; } /* Enable features (hardcoded here) */ @@ -1653,7 +1654,7 @@ netconf_module_features(clicon_handle h) * @see netconf_module_feature should be called before any yang modules */ int -netconf_module_load(clicon_handle h) +netconf_module_load(clixon_handle h) { int retval = -1; yang_stmt *yspec; @@ -1747,61 +1748,6 @@ netconf_db_find(cxobj *xn, return db; } -/*! Generate netconf error msg to cbuf using callback to use in string printout or logs - * - * If no callback is registered, a default error message is genereated - * @param[in] xerr Netconf error message on the level: - * @param[out] cberr Translation from netconf err to cbuf. - * @retval 0 OK, with cberr set - * @retval -1 Error - * @code - * cbuf *cb = NULL; - * if ((cb = cbuf_new()) ==NULL){ - * err; - * if (netconf_err2cb(h, xerr, cb) < 0) - * err; - * printf("%s", cbuf_get(cb)); - * cbuf_free(cb); - * @endcode - * @see clixon_netconf_error_fn - */ -int -netconf_err2cb(clicon_handle h, - cxobj *xerr, - cbuf *cberr) -{ - int retval = -1; - cxobj *x; - size_t len; - - // XXX: some calls are , change calls instead - if (strcmp(xml_name(xerr), "rpc-error") != 0) - xerr = xml_child_i_type(xerr, 0, CX_ELMNT); - len = cbuf_len(cberr); - if (clixon_plugin_netconf_errmsg_all(h, xerr, cberr) < 0) - goto done; - if (cbuf_len(cberr) == len){ /* Same as on-entry, use default */ - if ((x = xml_find_type(xerr, NULL, "error-type", CX_ELMNT)) != NULL) - cprintf(cberr, "%s ", xml_body(x)); - if ((x = xml_find_type(xerr, NULL, "error-tag", CX_ELMNT)) != NULL) - cprintf(cberr, "%s ", xml_body(x)); - if ((x = xml_find_type(xerr, NULL, "error-message", CX_ELMNT)) != NULL) - cprintf(cberr, "%s ", xml_body(x)); - if ((x = xml_find_type(xerr, NULL, "error-info", CX_ELMNT)) != NULL && - xml_child_nr(x) > 0){ - if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0) - goto done; - } - if ((x = xml_find_type(xerr, NULL, "error-app-tag", CX_ELMNT)) != NULL) - cprintf(cberr, ": %s ", xml_body(x)); - if ((x = xml_find_type(xerr, NULL, "error-path", CX_ELMNT)) != NULL) - cprintf(cberr, ": %s ", xml_body(x)); - } - retval = 0; - done: - return retval; -} - /* See RFC 8040 4.8.1 * @see netconf_content_str2int */ @@ -1848,7 +1794,7 @@ netconf_content_int2str(netconf_content nr) * urn:ietf:params:netconf:capability:notification:1.0 (RFC5277) */ int -netconf_capabilites(clicon_handle h, +netconf_capabilites(clixon_handle h, cbuf *cb) { int retval = -1; @@ -1942,7 +1888,7 @@ netconf_capabilites(clicon_handle h, * @see netconf_module_load */ int -netconf_hello_server(clicon_handle h, +netconf_hello_server(clixon_handle h, cbuf *cb, uint32_t session_id) { @@ -1959,56 +1905,6 @@ netconf_hello_server(clicon_handle h, return retval; } -/*! Generate and print textual error log from Netconf error message - * - * Get a text error message from netconf error message and generate error on the form: - * : "": or : - * @param[in] h Clixon handle - * @param[in] fn Inline function name (when called from clicon_err() macro) - * @param[in] line Inline file line number (when called from clicon_err() macro) - * @param[in] xerr Netconf error xml tree on the form: - * @param[in] format Format string - * @param[in] arg String argument to format (optional) - * @retval 0 OK - * @retval -1 Error - * @see netconf_err2cb - * ßee clixon_netconf_error macro - */ -int -clixon_netconf_error_fn(clicon_handle h, - const char *fn, - const int line, - cxobj *xerr, - const char *msg, - const char *arg) -{ - int retval = -1; - cbuf *cb = NULL; - - if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); - goto done; - } - if (msg){ - cprintf(cb, "%s", msg); - if (arg) - cprintf(cb, " \"%s\" ", arg); - - cprintf(cb, ": "); - } - if (netconf_err2cb(h, xerr, cb) < 0) - goto done; -#if 0 /* More verbose output for debugging */ - clicon_log(LOG_ERR, "%s: %d: %s", fn, line, cbuf_get(cb)); -#else - clicon_log(LOG_ERR, "%s", cbuf_get(cb)); -#endif - retval = 0; - done: - if (cb) - cbuf_free(cb); - return retval; -} /*! Add internal error info to existing netconf error message by rewriting * @@ -2087,14 +1983,14 @@ netconf_parse_uint32(char *name, char *reason = NULL; if (valstr == NULL){ - clicon_err(OE_NETCONF, EINVAL, "valstr is NULL"); + clixon_err(OE_NETCONF, EINVAL, "valstr is NULL"); goto done; } if (defaultstr && strcmp(valstr, defaultstr) == 0) *value = defaultvalue; else { if ((ret = parse_uint32(valstr, value, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_uint32"); + clixon_err(OE_XML, errno, "parse_uint32"); goto done; } if (ret == 0){ @@ -2131,14 +2027,14 @@ netconf_parse_uint32_xml(char *name, char *reason = NULL; if (valstr == NULL){ - clicon_err(OE_NETCONF, EINVAL, "valstr is NULL"); + clixon_err(OE_NETCONF, EINVAL, "valstr is NULL"); goto done; } if (defaultstr && strcmp(valstr, defaultstr) == 0) *value = defaultvalue; else { if ((ret = parse_uint32(valstr, value, &reason)) < 0){ - clicon_err(OE_XML, errno, "parse_uint32"); + clixon_err(OE_XML, errno, "parse_uint32"); goto done; } if (ret == 0){ @@ -2164,7 +2060,7 @@ netconf_parse_uint32_xml(char *name, * @retval msgid Next message id */ int -netconf_message_id_next(clicon_handle h) +netconf_message_id_next(clixon_handle h) { int msgid; @@ -2200,7 +2096,7 @@ netconf_framing_preamble(netconf_framing_type framing, break; case NETCONF_SSH_CHUNKED: if ((body = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } cbuf_reset(cb); @@ -2269,7 +2165,7 @@ netconf_output(int s, if (errno == EPIPE) clixon_debug(CLIXON_DBG_DEFAULT, "%s write err SIGPIPE", __FUNCTION__); else - clicon_log(LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno)); + clixon_log(NULL, LOG_ERR, "%s: write: %s", __FUNCTION__, strerror(errno)); goto done; } retval = 0; @@ -2356,7 +2252,7 @@ netconf_input_chunked_framing(char ch, (*state)++; break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected \\n but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected \\n but received %c (state:%d)", ch, *state); goto err; break; case 1: @@ -2365,7 +2261,7 @@ netconf_input_chunked_framing(char ch, (*state)++; break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state); goto err; break; case 2: @@ -2379,7 +2275,7 @@ netconf_input_chunked_framing(char ch, *size = ch-'0'; break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected 1-9 or # but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-start: expected 1-9 or # but received %c (state:%d)", ch, *state); goto err; break; case 3: @@ -2391,7 +2287,7 @@ netconf_input_chunked_framing(char ch, (*state)++; break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-size: expected 0-9 or \\n but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-size: expected 0-9 or \\n but received %c (state:%d)", ch, *state); goto err; break; case 4: @@ -2404,7 +2300,7 @@ netconf_input_chunked_framing(char ch, (*state)++; break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state); goto err; break; case 6: @@ -2417,7 +2313,7 @@ netconf_input_chunked_framing(char ch, *size = ch-'0'; break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error: expected # but received %c (state:%d)", ch, *state); goto err; break; case 7: @@ -2426,11 +2322,11 @@ netconf_input_chunked_framing(char ch, retval = 2; /* end of frame */ break; } - clicon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error chunk-end: expected \\n but received %c (state:%d)", ch, *state); goto err; break; default: - clicon_err(OE_NETCONF, 0, "NETCONF framing error %c , invalid state:%d", ch, *state); + clixon_err(OE_NETCONF, 0, "NETCONF framing error %c , invalid state:%d", ch, *state); goto err; break; } @@ -2442,3 +2338,125 @@ netconf_input_chunked_framing(char ch, goto done; } +/*! Generate netconf error msg to cbuf using callback to use in string printout or logs + * + * If no callback is registered, a default error message is genereated + * @param[in] xerr Netconf error message on the level: + * @param[out] cberr Translation from netconf err to cbuf. + * @retval 0 OK, with cberr set + * @retval -1 Error + * @code + * cbuf *cb = NULL; + * if ((cb = cbuf_new()) ==NULL){ + * err; + * if (netconf_err2cb(h, xerr, cb) < 0) + * err; + * printf("%s", cbuf_get(cb)); + * cbuf_free(cb); + * @endcode + * @see clixon_netconf_error_fn + */ +int +netconf_err2cb(clixon_handle h, + cxobj *xerr, + cbuf *cberr) +{ + int retval = -1; + cxobj *x; + size_t len; + + // XXX: some calls are , change calls instead + if (strcmp(xml_name(xerr), "rpc-error") != 0) + xerr = xml_child_i_type(xerr, 0, CX_ELMNT); + len = cbuf_len(cberr); + if (clixon_plugin_netconf_errmsg_all(h, xerr, cberr) < 0) + goto done; + if (cbuf_len(cberr) == len){ /* Same as on-entry, use default */ + if ((x=xpath_first(xerr, NULL, "//error-type"))!=NULL) + cprintf(cberr, "%s ", xml_body(x)); + if ((x=xpath_first(xerr, NULL, "//error-tag"))!=NULL) + cprintf(cberr, "%s ", xml_body(x)); + if ((x=xpath_first(xerr, NULL, "//error-message"))!=NULL) + cprintf(cberr, "%s ", xml_body(x)); + if ((x=xpath_first(xerr, NULL, "//error-info")) != NULL && + xml_child_nr(x) > 0){ + if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0) + goto done; + } + if ((x=xpath_first(xerr, NULL, "//error-app-tag"))!=NULL) + cprintf(cberr, ": %s ", xml_body(x)); + if ((x=xpath_first(xerr, NULL, "//error-path"))!=NULL) + cprintf(cberr, ": %s ", xml_body(x)); + } + retval = 0; + done: + return retval; +} + +/*! Generate and print textual error log from Netconf error message + * + * Get a text error message from netconf error message and generate error logmsg: + * : "": or : + * + * @param[in] h Clixon handle + * @param[in] fn Inline function name (when called from clixon_err() macro) + * @param[in] line Inline file line number (when called from clixon_err() macro) + * @param[in] xerr Netconf error xml tree on the form: + * @param[in] format Format string + * @param[in] arg String argument to format (optional) + * @retval 0 OK + * @retval -1 Error + * @see netconf_err2cb + * @see clixon_netconf_error macro + */ +int +clixon_err_netconf_fn(clixon_handle h, + const char *fn, + const int line, + int category, + int suberr, + cxobj *xerr, + const char *format, ...) +{ + int retval = -1; + va_list args; + int len; + char *msg = NULL; + cbuf *cb = NULL; + + /* first round: compute length of error message */ + va_start(args, format); + len = vsnprintf(NULL, 0, format, args); + va_end(args); + + /* allocate a message string exactly fitting the message length */ + if ((msg = malloc(len+1)) == NULL){ + fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ + goto done; + } + /* second round: compute write message from format and args */ + va_start(args, format); + if (vsnprintf(msg, len+1, format, args) < 0){ + va_end(args); + fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ + goto done; + } + va_end(args); + if ((cb = cbuf_new()) == NULL){ + clixon_err(OE_XML, errno, "cbuf_new"); + goto done; + } + cprintf(cb, "%s: ", msg); + /* Translate netconf error to string */ + if (netconf_err2cb(h, xerr, cb) < 0) + goto done; + if (clixon_err_args(h, fn, line, category, suberr, cbuf_get(cb)) < 0) + goto done; + retval = 0; + done: + if (msg) + free(msg); + if (cb) + cbuf_free(cb); + return retval; +} diff --git a/lib/src/clixon_netconf_monitoring.c b/lib/src/clixon_netconf_monitoring.c index f109ad74..cf6664a5 100644 --- a/lib/src/clixon_netconf_monitoring.c +++ b/lib/src/clixon_netconf_monitoring.c @@ -51,24 +51,25 @@ /* cligen */ #include -/* clicon */ -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_yang_module.h" #include "clixon_xml_io.h" #include "clixon_netconf_lib.h" #include "clixon_options.h" -#include "clixon_err.h" #include "clixon_data.h" #include "clixon_datastore.h" #include "clixon_netconf_monitoring.h" static int -per_datastore(clicon_handle h, +per_datastore(clixon_handle h, cbuf *cb, const char *db) { @@ -84,7 +85,7 @@ per_datastore(clicon_handle h, cprintf(cb, "%u", sid); xmldb_lock_timestamp(h, db, &tv); if (time2str(&tv, timestr, sizeof(timestr)) < 0){ - clicon_err(OE_UNIX, errno, "time2str"); + clixon_err(OE_UNIX, errno, "time2str"); goto done; } cprintf(cb, "%s", timestr); @@ -107,7 +108,7 @@ per_datastore(clicon_handle h, * @see RFC 6022 Section 2.1.2 */ static int -netconf_monitoring_datastores(clicon_handle h, +netconf_monitoring_datastores(clixon_handle h, yang_stmt *yspec, cbuf *cb) { @@ -138,7 +139,7 @@ netconf_monitoring_datastores(clicon_handle h, * @see RFC 6022 Section 2.1.3 */ static int -netconf_monitoring_schemas(clicon_handle h, +netconf_monitoring_schemas(clixon_handle h, yang_stmt *yspec, cbuf *cb) { @@ -189,7 +190,7 @@ netconf_monitoring_schemas(clicon_handle h, * @see RFC 6022 Section 2.1.5 */ static int -netconf_monitoring_statistics(clicon_handle h, +netconf_monitoring_statistics(clixon_handle h, yang_stmt *yspec, cbuf *cb) { @@ -243,7 +244,7 @@ netconf_monitoring_statistics(clicon_handle h, * @see RFC 6022 */ int -netconf_monitoring_state_get(clicon_handle h, +netconf_monitoring_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, @@ -255,7 +256,7 @@ netconf_monitoring_state_get(clicon_handle h, int ret; if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "", NETCONF_MONITORING_NAMESPACE); @@ -300,7 +301,7 @@ stat_counter_add(cvec *cvv, cg_var *cv; if ((cv = cvec_add(cvv, CGV_UINT32)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); goto done; } cv_name_set(cv, name); @@ -317,7 +318,7 @@ stat_counter_add(cvec *cvv, * @retval -1 Error */ int -netconf_monitoring_statistics_init(clicon_handle h) +netconf_monitoring_statistics_init(clixon_handle h) { int retval = -1; struct timeval tv; @@ -329,7 +330,7 @@ netconf_monitoring_statistics_init(clicon_handle h) goto done; clicon_data_set(h, "netconf-start-time", timestr); /* RFC 6022 */ if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (clicon_data_cvec_set(h, "netconf-statistics", cvv) < 0) @@ -360,7 +361,7 @@ netconf_monitoring_statistics_init(clicon_handle h) * @retval 0 OK */ int -netconf_monitoring_counter_inc(clicon_handle h, +netconf_monitoring_counter_inc(clixon_handle h, char *name) { cvec *cvv = NULL; diff --git a/lib/src/clixon_netns.c b/lib/src/clixon_netns.c index 66278e26..1eb17fae 100644 --- a/lib/src/clixon_netns.c +++ b/lib/src/clixon_netns.c @@ -41,8 +41,12 @@ #include /* clixon */ +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_netns.h" #ifdef HAVE_SETNS @@ -70,7 +74,7 @@ send_sock(int usock, memcpy(fdptr,&fd,sizeof(fd)); msg.msg_controllen=CMSG_SPACE(sizeof(fd)); if (sendmsg(usock, &msg, 0) < 0){ - clicon_err(OE_UNIX, errno, "sendmsg"); + clixon_err(OE_UNIX, errno, "sendmsg"); goto done; } retval = 0; @@ -96,7 +100,7 @@ get_sock(int usock, msg.msg_controllen=sizeof(buf); /* Block here */ if (recvmsg(usock, &msg, 0) < 0){ - clicon_err(OE_UNIX, errno, "recvmsg"); + clixon_err(OE_UNIX, errno, "recvmsg"); goto done; } cmsg=CMSG_FIRSTHDR(&msg); @@ -133,7 +137,7 @@ create_socket(struct sockaddr *sa, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (sock == NULL){ - clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter"); + clixon_err(OE_PROTO, EINVAL, "Requires socket output parameter"); goto done; } /* create inet socket */ @@ -146,39 +150,39 @@ create_socket(struct sockaddr *sa, if ((s = socket(sa->sa_family, flags, 0)) < 0) { - clicon_err(OE_UNIX, errno, "socket"); + clixon_err(OE_UNIX, errno, "socket"); goto done; } #ifdef __APPLE__ if (fcntl(s, O_CLOEXEC)) { - clicon_err(OE_UNIX, errno, "fcntl"); + clixon_err(OE_UNIX, errno, "fcntl"); goto done; } #endif if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) == -1) { - clicon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE"); + clixon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE"); goto done; } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) == -1) { - clicon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR"); + clixon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR"); goto done; } /* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */ if (sa->sa_family == AF_INET6 && setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) { - clicon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6"); + clixon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6"); goto done; } if (bind(s, sa, sin_len) == -1) { /* Note may be ignored in upper layer by checking for EADDRNOTAVAIL, see eg restconf_openssl_init */ - clicon_err(OE_UNIX, errno, "bind(%s)", addrstr); + clixon_err(OE_UNIX, errno, "bind(%s)", addrstr); goto done; } if (listen(s, backlog ) < 0){ - clicon_err(OE_UNIX, errno, "listen"); + clixon_err(OE_UNIX, errno, "listen"); goto done; } if (sock) @@ -228,18 +232,18 @@ fork_netns_socket(const char *netns, clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, netns); if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){ - clicon_err(OE_UNIX, errno, "socketpair"); + clixon_err(OE_UNIX, errno, "socketpair"); goto done; } #ifdef __APPLE__ if (fcntl(sp[0], O_CLOEXEC)) { - clicon_err(OE_UNIX, errno, "fcntl, sp[0]"); + clixon_err(OE_UNIX, errno, "fcntl, sp[0]"); goto done; } if (fcntl(sp[1], O_CLOEXEC)) { - clicon_err(OE_UNIX, errno, "fcntl, sp[1]"); + clixon_err(OE_UNIX, errno, "fcntl, sp[1]"); goto done; } #endif @@ -247,11 +251,11 @@ fork_netns_socket(const char *netns, /* Check namespace exists */ sprintf(nspath,"/var/run/netns/%s", netns); if (stat(nspath, &st) < 0){ - clicon_err(OE_UNIX, errno, ": stat(%s)", nspath); + clixon_err(OE_UNIX, errno, ": stat(%s)", nspath); goto done; } if ((child = fork()) < 0) { - clicon_err(OE_UNIX, errno, "fork"); + clixon_err(OE_UNIX, errno, "fork"); goto done; } if (child == 0) { /* Child */ @@ -261,13 +265,13 @@ fork_netns_socket(const char *netns, close(sp[0]); /* Switch to namespace */ if ((fd=open(nspath, O_RDONLY)) < 0) { - clicon_err(OE_UNIX, errno, "open(%s)", nspath); + clixon_err(OE_UNIX, errno, "open(%s)", nspath); send_sock(sp[1], sp[1]); /* Dummy to wake parent */ exit(1); /* Dont do return here, need to exit child */ } #ifdef HAVE_SETNS if (setns(fd, CLONE_NEWNET) < 0){ - clicon_err(OE_UNIX, errno, "setns(%s)", netns); + clixon_err(OE_UNIX, errno, "setns(%s)", netns); send_sock(sp[1], sp[1]); /* Dummy to wake parent */ exit(1); /* Dont do return here, need to exit child */ } @@ -295,7 +299,7 @@ fork_netns_socket(const char *netns, if (WEXITSTATUS(wstatus)){ clixon_debug(CLIXON_DBG_DEFAULT, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus)); *sock = -1; - clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr); + clixon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr); goto done; } retval = 0; @@ -339,7 +343,7 @@ clixon_netns_socket(const char *netns, if (fork_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, sock) < 0) goto done; #else - clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns); + clixon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns); return -1; #endif } diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 950bebfc..de304782 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -62,13 +62,15 @@ #include /* clixon */ -#include "clixon_err.h" -#include "clixon_string.h" + #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" -#include "clixon_file.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_string.h" +#include "clixon_file.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_sort.h" @@ -144,7 +146,7 @@ static const map_str2int yang_regexp_map[] = { * @see cli_show_options */ int -clicon_option_dump(clicon_handle h, +clicon_option_dump(clixon_handle h, int dbglevel) { int retval = -1; @@ -208,7 +210,7 @@ clicon_option_dump(clicon_handle h, * @see clicon_option_dump for debug log */ int -clicon_option_dump1(clicon_handle h, +clicon_option_dump1(clixon_handle h, FILE *f, int format, int pretty) @@ -231,7 +233,7 @@ clicon_option_dump1(clicon_handle h, goto done; break; default: - clicon_err(OE_XML, EINVAL, "%s not supported", format_int2str(format)); + clixon_err(OE_XML, EINVAL, "%s not supported", format_int2str(format)); goto done; break; } @@ -250,7 +252,7 @@ clicon_option_dump1(clicon_handle h, * @retval -1 Error */ static int -parse_configfile_one(clicon_handle h, +parse_configfile_one(clixon_handle h, const char *filename, yang_stmt *yspec, cxobj **xconfig) @@ -260,30 +262,22 @@ parse_configfile_one(clicon_handle h, cxobj *xt = NULL; cxobj *xerr = NULL; cxobj *xa; - cbuf *cbret = NULL; int ret; if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "open configure file: %s", filename); + clixon_err(OE_UNIX, errno, "open configure file: %s", filename); return -1; } clixon_debug(CLIXON_DBG_DETAIL, "%s: Reading config file %s", __FUNCTION__, filename); if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ - if ((cbret = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); - goto done; - } - if (netconf_err2cb(h, xerr, cbret) < 0) - goto done; - /* Here one could make it more relaxing to not quit on unrecognized option? */ - clixon_netconf_error(h, xerr, NULL, NULL); + clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Config file: %s", filename); goto done; } /* Ensure a single root */ if (xt == NULL || xml_child_nr(xt) != 1){ - clicon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename); + clixon_err(OE_CFG, 0, "Config file %s: Lacks single top element", filename); goto done; } if (xml_rootchild(xt, 0, &xt) < 0) @@ -292,7 +286,7 @@ parse_configfile_one(clicon_handle h, if (strcmp(xml_name(xt), "clixon-config") != 0 || (xa = xml_find_type(xt, NULL, "xmlns", CX_ATTR)) == NULL || strcmp(xml_value(xa), CLIXON_CONF_NS) != 0){ - clicon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: ", filename, CLIXON_CONF_NS); + clixon_err(OE_CFG, 0, "Config file %s: Lacks top-level \"clixon-config\" element\nClixon config files should begin with: ", filename, CLIXON_CONF_NS); goto done; } *xconfig = xt; @@ -304,8 +298,6 @@ parse_configfile_one(clicon_handle h, xml_free(xt); if (fp) fclose(fp); - if (cbret) - cbuf_free(cbret); if (xerr) xml_free(xerr); return retval; @@ -314,7 +306,7 @@ parse_configfile_one(clicon_handle h, /*! Merge XML sub config file into main config-file */ static int -merge_control_xml(clicon_handle h, +merge_control_xml(clixon_handle h, cxobj *xt, cxobj *xe) { @@ -384,7 +376,7 @@ merge_control_xml(clicon_handle h, * @retval -1 Error */ static int -parse_configfile(clicon_handle h, +parse_configfile(clixon_handle h, const char *filename, char *extraconfdir0, yang_stmt *yspec, @@ -412,15 +404,15 @@ parse_configfile(clicon_handle h, DIR *dirp; if (filename == NULL || !strlen(filename)){ - clicon_err(OE_UNIX, 0, "Not specified"); + clixon_err(OE_UNIX, 0, "Not specified"); goto done; } if (stat(filename, &st) < 0){ - clicon_err(OE_UNIX, errno, "%s", filename); + clixon_err(OE_UNIX, errno, "%s", filename); goto done; } if (!S_ISREG(st.st_mode)){ - clicon_err(OE_UNIX, 0, "%s is not a regular file", filename); + clixon_err(OE_UNIX, 0, "%s is not a regular file", filename); goto done; } @@ -437,7 +429,7 @@ parse_configfile(clicon_handle h, if (extraconfdir){ /* If extra dir, parse extra config files */ /* A check it exists (also done in clicon_file_dirent) */ if ((dirp = opendir(extraconfdir)) == NULL) { - clicon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir); + clixon_err(OE_UNIX, errno, "CLICON_CONFIGDIR: %s opendir", extraconfdir); goto done; } closedir(dirp); @@ -461,7 +453,7 @@ parse_configfile(clicon_handle h, while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { if ((y = xml_spec(x)) != NULL){ if ((yang_find(y, Y_STATUS, "obsolete")) != NULL){ - clicon_err(OE_CFG, 0, "Clixon option %s is obsolete but given in the config file which is considered an error", + clixon_err(OE_CFG, 0, "Clixon option %s is obsolete but given in the config file which is considered an error", xml_name(x)); goto done; } @@ -473,12 +465,10 @@ parse_configfile(clicon_handle h, goto done; if (ret == 0){ if ((cbret = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (netconf_err2cb(h, xerr, cbret) < 0) - goto done; - clicon_err(OE_CFG, 0, "Config file validation: %s", cbuf_get(cbret)); + clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Config file validation"); goto done; } /* Add top-level hash options. @@ -540,7 +530,7 @@ parse_configfile(clicon_handle h, * @see clicon_options_main For loading options from file */ int -clicon_option_add(clicon_handle h, +clicon_option_add(clixon_handle h, const char *name, char *value) { @@ -550,7 +540,7 @@ clicon_option_add(clicon_handle h, cxobj *xopt; if ((xconfig = clicon_conf_xml(h)) == NULL){ - clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name); + clixon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name); goto done; } if (strcmp(name, "CLICON_FEATURE")==0 || @@ -594,7 +584,7 @@ clicon_option_add(clicon_handle h, * other yang modules. */ int -clicon_options_main(clicon_handle h) +clicon_options_main(clixon_handle h) { int retval = -1; char *configfile; @@ -625,13 +615,13 @@ clicon_options_main(clicon_handle h) xml = strcmp(suffix, "xml") == 0; } if (xml == 0){ - clicon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix); + clixon_err(OE_CFG, 0, "%s: suffix %s not recognized", configfile, suffix); goto done; } /* Override extraconfdir */ if (clicon_option_str(h, "CLICON_CONFIGDIR") && (extraconfdir = strdup(clicon_option_str(h, "CLICON_CONFIGDIR"))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } @@ -673,7 +663,7 @@ clicon_options_main(clicon_handle h) if (parse_configfile(h, configfile, extraconfdir, yspec, &xconfig) < 0) goto done; if (xml_spec(xconfig) == NULL){ - clicon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: or clixon-config.yang not found?", configfile, CLIXON_CONF_NS); + clixon_err(OE_CFG, 0, "Config file %s: did not find corresponding Yang specification\nHint: File does not begin with: or clixon-config.yang not found?", configfile, CLIXON_CONF_NS); goto done; } /* Set yang config spec (must store to free at exit, since conf_xml below uses it) */ @@ -696,13 +686,13 @@ clicon_options_main(clicon_handle h) /*! Check if a clicon option has a value * - * @param[in] h clicon_handle + * @param[in] h clixon_handle * @param[in] name option name * @retval !=0 option exists * @retval 0 option does not exist */ int -clicon_option_exists(clicon_handle h, +clicon_option_exists(clixon_handle h, const char *name) { clicon_hash_t *copt = clicon_options(h); @@ -712,7 +702,7 @@ clicon_option_exists(clicon_handle h, /*! Get a single string option string via handle * - * @param[in] h clicon_handle + * @param[in] h clixon_handle * @param[in] name option name * @retval string value of option if found * @retval NULL If option not found, or value of option is NULL @@ -721,7 +711,7 @@ clicon_option_exists(clicon_handle h, * clicon_option_exists() before the call */ char * -clicon_option_str(clicon_handle h, +clicon_option_str(clixon_handle h, const char *name) { clicon_hash_t *copt = clicon_options(h); @@ -733,14 +723,14 @@ clicon_option_str(clicon_handle h, /*! Set a single string option via handle * - * @param[in] h clicon_handle + * @param[in] h clixon_handle * @param[in] name option name * @param[in] val option value, must be null-terminated string * @retval 0 OK * @retval -1 Error */ int -clicon_option_str_set(clicon_handle h, +clicon_option_str_set(clixon_handle h, const char *name, char *val) { @@ -767,7 +757,7 @@ clicon_option_str_set(clicon_handle h, * @see clicon_data_int_get for transient values (not clixon config file) */ int -clicon_option_int(clicon_handle h, +clicon_option_int(clixon_handle h, const char *name) { char *s; @@ -784,7 +774,7 @@ clicon_option_int(clicon_handle h, * @param[in] val Integer value */ int -clicon_option_int_set(clicon_handle h, +clicon_option_int_set(clixon_handle h, const char *name, int val) { @@ -812,7 +802,7 @@ clicon_option_int_set(clicon_handle h, * supply a default value as shown in the example. */ int -clicon_option_bool(clicon_handle h, +clicon_option_bool(clixon_handle h, const char *name) { char *s; @@ -833,18 +823,18 @@ clicon_option_bool(clicon_handle h, * @param[in] val Boolean value, 0 or 1 */ int -clicon_option_bool_set(clicon_handle h, +clicon_option_bool_set(clixon_handle h, const char *name, int val) { char s[64]; if (val != 0 && val != 1){ - clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val); + clixon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val); return -1; } if (snprintf(s, sizeof(s)-1, "%s", val?"true":"false") < 0){ - clicon_err(OE_CFG, errno, "snprintf"); + clixon_err(OE_CFG, errno, "snprintf"); return -1; } return clicon_option_str_set(h, name, s); @@ -856,7 +846,7 @@ clicon_option_bool_set(clicon_handle h, * @param[in] name Name of option to delete */ int -clicon_option_del(clicon_handle h, +clicon_option_del(clixon_handle h, const char *name) { clicon_hash_t *copt = clicon_options(h); @@ -882,7 +872,7 @@ clicon_option_del(clicon_handle h, * @see clixon-config@.yang CLICON_CLI_VARONLY */ int -clicon_cli_varonly(clicon_handle h) +clicon_cli_varonly(clixon_handle h) { char const *opt = "CLICON_CLI_VARONLY"; @@ -899,7 +889,7 @@ clicon_cli_varonly(clicon_handle h) * @retval fam Socket family */ int -clicon_sock_family(clicon_handle h) +clicon_sock_family(clixon_handle h) { char *s; @@ -922,7 +912,7 @@ clicon_sock_family(clicon_handle h) * @see clixon-config@.yang CLICON_SOCK_PORT */ int -clicon_sock_port(clicon_handle h) +clicon_sock_port(clixon_handle h) { char *s; @@ -937,7 +927,7 @@ clicon_sock_port(clicon_handle h) * @retval flag Autocommit (or not) */ int -clicon_autocommit(clicon_handle h) +clicon_autocommit(clixon_handle h) { char const *opt = "CLICON_AUTOCOMMIT"; @@ -953,7 +943,7 @@ clicon_autocommit(clicon_handle h) * @retval mode Startup mode */ int -clicon_startup_mode(clicon_handle h) +clicon_startup_mode(clixon_handle h) { char *mode; @@ -968,7 +958,7 @@ clicon_startup_mode(clicon_handle h) * @retval mode Privileges mode */ enum priv_mode_t -clicon_backend_privileges_mode(clicon_handle h) +clicon_backend_privileges_mode(clixon_handle h) { char *mode; @@ -983,7 +973,7 @@ clicon_backend_privileges_mode(clicon_handle h) * @retval mode Privileges mode */ enum priv_mode_t -clicon_restconf_privileges_mode(clicon_handle h) +clicon_restconf_privileges_mode(clixon_handle h) { char *mode; @@ -998,7 +988,7 @@ clicon_restconf_privileges_mode(clicon_handle h) * @retval mode Privileges mode */ enum nacm_credentials_t -clicon_nacm_credentials(clicon_handle h) +clicon_nacm_credentials(clixon_handle h) { char *mode; @@ -1014,7 +1004,7 @@ clicon_nacm_credentials(clicon_handle h) * @see clixon-config@.yang CLICON_DATASTORE_CACHE */ enum datastore_cache -clicon_datastore_cache(clicon_handle h) +clicon_datastore_cache(clixon_handle h) { char *str; @@ -1031,7 +1021,7 @@ clicon_datastore_cache(clicon_handle h) * @see clixon-config@.yang CLICON_YANG_REGEXP */ enum regexp_mode -clicon_yang_regexp(clicon_handle h) +clicon_yang_regexp(clixon_handle h) { char *str; @@ -1053,7 +1043,7 @@ clicon_yang_regexp(clicon_handle h) * @retval flag quiet mode on or off */ int -clicon_quiet_mode(clicon_handle h) +clicon_quiet_mode(clixon_handle h) { char *s; if ((s = clicon_option_str(h, "CLICON_QUIET")) == NULL) @@ -1067,7 +1057,7 @@ clicon_quiet_mode(clicon_handle h) * @param[in] val Flag value */ int -clicon_quiet_mode_set(clicon_handle h, +clicon_quiet_mode_set(clixon_handle h, int val) { return clicon_option_int_set(h, "CLICON_QUIET", val); diff --git a/lib/src/clixon_path.c b/lib/src/clixon_path.c index b126a1d3..c03d3ea8 100644 --- a/lib/src/clixon_path.c +++ b/lib/src/clixon_path.c @@ -90,6 +90,7 @@ #include "clixon_string.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_options.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -140,9 +141,9 @@ api_path_parse(char *api_path, if (api_path_parse_init(&ay) < 0) goto done; if (clixon_api_path_parseparse(&ay) != 0) { /* yacc returns 1 on error */ - clicon_log(LOG_NOTICE, "API-PATH error: on line %d", ay.ay_linenum); - if (clicon_errno == 0) - clicon_err(OE_XML, 0, "API-PATH parser error with no error code (should not happen)"); + clixon_log(NULL, LOG_NOTICE, "API-PATH error: on line %d", ay.ay_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_XML, 0, "API-PATH parser error with no error code (should not happen)"); goto done; } api_path_parse_exit(&ay); @@ -185,9 +186,9 @@ instance_id_parse(char *path, if (instance_id_parse_init(&iy) < 0) goto done; if (clixon_instance_id_parseparse(&iy) != 0) { /* yacc returns 1 on error */ - clicon_log(LOG_NOTICE, "Instance-id error: on line %d", iy.iy_linenum); - if (clicon_errno == 0) - clicon_err(OE_XML, 0, "Instance-id parser error with no error code (should not happen)"); + clixon_log(NULL, LOG_NOTICE, "Instance-id error: on line %d", iy.iy_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_XML, 0, "Instance-id parser error with no error code (should not happen)"); goto done; } instance_id_parse_exit(&iy); @@ -309,7 +310,7 @@ yang2api_path_fmt_1(yang_stmt *ys, enum rfc_6020 ypkeyw = -1; if ((yp = yang_parent_get(ys)) == NULL){ - clicon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys)); + clixon_err(OE_YANG, EINVAL, "yang expected parent %s", yang_argument_get(ys)); goto done; } if (yp) @@ -409,13 +410,13 @@ yang2api_path_fmt(yang_stmt *ys, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (yang2api_path_fmt_1(ys, inclkey, cb) < 0) goto done; if ((*api_path_fmt = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 0; @@ -476,7 +477,7 @@ api_path_fmt2api_path(const char *api_path_fmt, size_t len; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } j = 1; /* j==0 is cli string */ @@ -491,11 +492,11 @@ api_path_fmt2api_path(const char *api_path_fmt, ; else{ if ((cv = cvec_i(cvv, j++)) == NULL){ - clicon_err(OE_XML, 0, "Number of elements in cvv does not match api_path_fmt string"); + clixon_err(OE_XML, 0, "Number of elements in cvv does not match api_path_fmt string"); goto done; } if ((str = cv2str_dup(cv)) == NULL){ - clicon_err(OE_UNIX, errno, "cv2str_dup"); + clixon_err(OE_UNIX, errno, "cv2str_dup"); goto done; } if (uri_percent_encode(&strenc, "%s", str) < 0) @@ -516,7 +517,7 @@ api_path_fmt2api_path(const char *api_path_fmt, } } if ((*api_path = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } if (cvv_i) /* Last entry in cvv used */ @@ -570,7 +571,7 @@ api_path_fmt2xpath(char *api_path_fmt, size_t len; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } j = 1; /* j==0 is cli string */ @@ -586,7 +587,7 @@ api_path_fmt2xpath(char *api_path_fmt, else{ cv = cvec_i(cvv, j++); if ((str = cv2str_dup(cv)) == NULL){ - clicon_err(OE_UNIX, errno, "cv2str_dup"); + clixon_err(OE_UNIX, errno, "cv2str_dup"); goto done; } cprintf(cb, "[%s='%s']", cv_name_get(cv), str); @@ -604,7 +605,7 @@ api_path_fmt2xpath(char *api_path_fmt, } } if ((*xpath = strdup4(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 0; @@ -624,7 +625,7 @@ api_path_fmt2xpath(char *api_path_fmt, * @param[out] xerr Netconf error message * @retval 1 OK * @retval 0 Invalid api_path or associated XML, netconf error xml set - * @retval -1 Fatal error, clicon_err called + * @retval -1 Fatal error * * @code * cbuf *xpath = cbuf_new(); @@ -645,7 +646,7 @@ api_path_fmt2xpath(char *api_path_fmt, * ["www.foo.com" "restconf" "a" "b=c"] * which means the api-path is ["a" "b=c"] corresponding to "a/b=c" * @note "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 - * @note retval -1 sets clicon_err, retval 0 sets netconf xml msg + * @note retval -1 sets clixon_err, retval 0 sets netconf xml msg * @note Not proper namespace translation from api-path 2 xpath!!! * @see api_path2xml For api-path to xml tree * @see api_path2xpath Using strings as parameters @@ -687,7 +688,7 @@ api_path2xpath_cvv(cvec *api_path, if ((nsc = xml_nsctx_init(NULL, NULL)) == NULL) goto done; if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } root = 1; /* root or mountpoint */ @@ -865,7 +866,7 @@ api_path2xpath_cvv(cvec *api_path, * @param[out] xerr Netconf error message * @retval 1 OK * @retval 0 Invalid api_path or associated XML, netconf called - * @retval -1 Fatal error, clicon_err called + * @retval -1 Fatal error * @code * char *xpath = NULL; * cvec *nsc = NULL; @@ -892,7 +893,7 @@ api_path2xpath(char *api_path, int ret; if (api_path == NULL){ - clicon_err(OE_XML, EINVAL, "api_path is NULL"); + clixon_err(OE_XML, EINVAL, "api_path is NULL"); goto done; } /* Special case: "//" is not handled proerly by uri_str2cvec @@ -916,7 +917,7 @@ api_path2xpath(char *api_path, /* prepare output xpath parameter */ if (xpathp) if ((*xpathp = strdup(cbuf_get(xpath))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 1; @@ -944,9 +945,9 @@ api_path2xpath(char *api_path, * @param[out] xerr Netconf error message (if retval=0) * @retval 1 OK * @retval 0 Invalid api_path or associated XML, netconf error - * @retval -1 Fatal error, clicon_err called + * @retval -1 Fatal error * - * @note both retval -1 set clicon_err, retval 0 set xerr netconf xml + * @note both retval -1 set clixon_err, retval 0 set xerr netconf xml * @see api_path2xpath For api-path to xml xpath translation * @see api_path2xml */ @@ -994,7 +995,7 @@ api_path2xml_vec(char **vec, goto ok; } /* E.g "x=1,2" -> nodeid:x restval=1,2 */ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* restval is RFC 3896 encoded */ @@ -1046,7 +1047,7 @@ api_path2xml_vec(char **vec, case Y_LEAF_LIST: #if 0 if (restval==NULL){ - clicon_err(OE_XML, 0, "malformed key, expected '=restval'"); + clixon_err(OE_XML, 0, "malformed key, expected '=restval'"); goto done; } #endif @@ -1162,7 +1163,7 @@ api_path2xml_vec(char **vec, if (xml2xpath(x, nsc, 0, 1, &xpath) < 0) // XXX should be canonical goto done; if (xpath == NULL){ - clicon_err(OE_YANG, 0, "No xpath from xml"); + clixon_err(OE_YANG, 0, "No xpath from xml"); goto done; } /* cf xml_bind_yang0_opt/xml_yang_mount_get */ @@ -1214,8 +1215,8 @@ api_path2xml_vec(char **vec, * @param[out] xerr Netconf error message (if retval=0) * @retval 1 OK * @retval 0 Invalid api_path or associated XML, netconf error - * @retval -1 Fatal error, clicon_err called - * @note both retval -1 set clicon_err, retval 0 set xerr netconf xml + * @retval -1 Fatal error + * @note both retval -1 set clixon_err, retval 0 set xerr netconf xml * @example * api_path: /subif-entry=foo/subid * xtop[in] @@ -1250,7 +1251,7 @@ api_path2xml(char *api_path, clixon_debug(CLIXON_DBG_DETAIL, "%s api_path:%s", __FUNCTION__, api_path); if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (*api_path != '/'){ @@ -1413,16 +1414,16 @@ api_path_resolve(clixon_path *cplist, do { if (yang_keyword_get(yt) == Y_SPEC){ if (cp->cp_prefix == NULL){ - clicon_err(OE_YANG, ENOENT, "Modulename not defined for top-level id."); + clixon_err(OE_YANG, ENOENT, "Modulename not defined for top-level id."); goto fail; } if ((yt = yang_find_module_by_name(yt, cp->cp_prefix)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Modulename in api-path does not correspond to existing module"); + clixon_err(OE_YANG, ENOENT, "Modulename in api-path does not correspond to existing module"); goto fail; } } if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Corresponding yang node for id not found"); + clixon_err(OE_YANG, ENOENT, "Corresponding yang node for id not found"); goto fail; } cp->cp_yang = yc; @@ -1438,14 +1439,14 @@ api_path_resolve(clixon_path *cplist, else if (yang_keyword_get(yc) == Y_LIST){ cvk = yang_cvec_get(yc); if (cvec_len(cp->cp_cvk) > cvec_len(cvk)){ - clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list"); + clixon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list"); goto fail; } i = 0; cva = NULL; while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) { if (cv_name_get(cva) != NULL){ - clicon_err(OE_YANG, ENOENT, "Unexpected named key %s (shouldnt happen)", + clixon_err(OE_YANG, ENOENT, "Unexpected named key %s (shouldnt happen)", cv_name_get(cva)); goto fail; } @@ -1454,7 +1455,7 @@ api_path_resolve(clixon_path *cplist, } } else{ - clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list"); + clixon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list"); goto fail; } } @@ -1507,12 +1508,12 @@ instance_id_resolve(clixon_path *cplist, if ((cp = cplist) != NULL){ do { if (cp->cp_prefix == NULL){ - clicon_err(OE_YANG, ENOENT, "No prefix of identifier (keynames may omit prefix)"); + clixon_err(OE_YANG, ENOENT, "No prefix of identifier (keynames may omit prefix)"); goto fail; } if (yang_keyword_get(yt) == Y_SPEC){ if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix); + clixon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix); goto fail; } } @@ -1521,13 +1522,13 @@ instance_id_resolve(clixon_path *cplist, if (ret == 1){ if (yang_mount_get_yspec_any(yt, &yspec) == 1){ if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix); + clixon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix); goto fail; } } } if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node", + clixon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node", cp->cp_id); goto fail; } @@ -1536,14 +1537,14 @@ instance_id_resolve(clixon_path *cplist, case Y_LIST: if (cp->cp_cvk == NULL){ #if 0 /* see key-value presence in lists note above */ - clicon_err(OE_YANG, ENOENT, "key-values mandatory for lists"); + clixon_err(OE_YANG, ENOENT, "key-values mandatory for lists"); goto fail; #endif break; } #if 0 /* see key-value presence in lists note above */ if (cvec_len(cp->cp_cvk) > cvec_len(yang_cvec_get(yc))){ - clicon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list "); + clixon_err(OE_YANG, ENOENT, "Number of keys in key-value list does not match Yang list "); goto fail; } #endif @@ -1551,7 +1552,7 @@ instance_id_resolve(clixon_path *cplist, while ((cva = cvec_each(cp->cp_cvk, cva)) != NULL) { if ((kname = cv_name_get(cva)) != NULL){ /* Check var exists */ if (yang_find(yc, 0, kname) == NULL){ - clicon_err(OE_YANG, ENOENT, "Index variable %s used in path is not child of Yang node %s", + clixon_err(OE_YANG, ENOENT, "Index variable %s used in path is not child of Yang node %s", kname, yang_argument_get(yc)); goto fail; } @@ -1564,7 +1565,7 @@ instance_id_resolve(clixon_path *cplist, break; default: if (cp->cp_cvk != NULL){ - clicon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list"); + clixon_err(OE_YANG, ENOENT, "key-values only defined for list or leaf-list"); goto fail; } break; @@ -1705,13 +1706,13 @@ clixon_xml_find_api_path(cxobj *xt, va_end(ap); /* allocate an api-path string exactly fitting the length */ if ((api_path = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: actually compute api-path string content */ va_start(ap, format); if (vsnprintf(api_path, len+1, format, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -1799,13 +1800,13 @@ clixon_xml_find_instance_id(cxobj *xt, va_end(ap); /* allocate a path string exactly fitting the length */ if ((path = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: actually compute api-path string content */ va_start(ap, format); if (vsnprintf(path, len+1, format, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -1887,13 +1888,13 @@ clixon_instance_id_bind(yang_stmt *yt, va_end(ap); /* allocate a path string exactly fitting the length */ if ((path = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: actually compute api-path string content */ va_start(ap, format); if (vsnprintf(path, len+1, format, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -1963,13 +1964,13 @@ clixon_instance_id_parse(yang_stmt *yt, va_end(ap); /* allocate a path string exactly fitting the length */ if ((path = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: actually compute api-path string content */ va_start(ap, format); if (vsnprintf(path, len+1, format, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -1982,7 +1983,7 @@ clixon_instance_id_parse(yang_stmt *yt, if ((ret = instance_id_resolve(cplist, yt)) < 0) goto done; if (ret == 0){ - if (xerr && netconf_invalid_value_xml(xerr, "application", clicon_err_reason) < 0) + if (xerr && netconf_invalid_value_xml(xerr, "application", clixon_err_reason()) < 0) goto done; goto fail; } diff --git a/lib/src/clixon_plugin.c b/lib/src/clixon_plugin.c index 34592b01..17a03275 100644 --- a/lib/src/clixon_plugin.c +++ b/lib/src/clixon_plugin.c @@ -55,13 +55,15 @@ /* cligen */ #include -#include "clixon_err.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_string.h" #include "clixon_hash.h" -#include "clixon_log.h" -#include "clixon_file.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_file.h" #include "clixon_yang.h" #include "clixon_options.h" #include "clixon_xml.h" @@ -126,7 +128,7 @@ typedef struct plugin_module_struct plugin_module_struct; * @param[in] h Clixon handle */ static plugin_module_struct * -plugin_module_struct_get(clicon_handle h) +plugin_module_struct_get(clixon_handle h) { clicon_hash_t *cdat = clicon_data(h); size_t len; @@ -145,7 +147,7 @@ plugin_module_struct_get(clicon_handle h) * @retval -1 Error */ static int -plugin_module_struct_set(clicon_handle h, +plugin_module_struct_set(clixon_handle h, plugin_module_struct *ms) { clicon_hash_t *cdat = clicon_data(h); @@ -206,7 +208,7 @@ clixon_plugin_handle_get(clixon_plugin_t *cp) * @note Not optimized, always iterates from the start of the list */ clixon_plugin_t * -clixon_plugin_each(clicon_handle h, +clixon_plugin_each(clixon_handle h, clixon_plugin_t *cpprev) { clixon_plugin_t *cpnext = NULL; @@ -242,7 +244,7 @@ clixon_plugin_each(clicon_handle h, * @note Not optimized, always iterates from the start of the list */ clixon_plugin_t * -clixon_plugin_each_revert(clicon_handle h, +clixon_plugin_each_revert(clixon_handle h, clixon_plugin_t *cpprev, int nr) { @@ -251,7 +253,7 @@ clixon_plugin_each_revert(clicon_handle h, int i; if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); return NULL; } if (ms->ms_plugin_list == NULL) @@ -287,14 +289,14 @@ clixon_plugin_each_revert(clicon_handle h, * @endcode */ clixon_plugin_t * -clixon_plugin_find(clicon_handle h, +clixon_plugin_find(clixon_handle h, const char *name) { clixon_plugin_t *cp = NULL; plugin_module_struct *ms = plugin_module_struct_get(h); if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); return NULL; } if ((cp = ms->ms_plugin_list) != NULL){ @@ -320,7 +322,7 @@ clixon_plugin_find(clicon_handle h, * @see clixon_plugins_load Load all plugins */ static int -plugin_load_one(clicon_handle h, +plugin_load_one(clixon_handle h, char *file, /* note modified */ const char *function, int dlflags, @@ -340,30 +342,30 @@ plugin_load_one(clicon_handle h, dlerror(); /* Clear any existing error */ if ((handle = dlopen(file, dlflags)) == NULL) { error = (char*)dlerror(); - clicon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error"); + clixon_err(OE_PLUGIN, errno, "dlopen(%s): %s", file, error ? error : "Unknown error"); goto done; } /* call plugin_init() if defined, eg CLIXON_PLUGIN_INIT or CLIXON_BACKEND_INIT */ if ((initfn = dlsym(handle, function)) == NULL){ - clicon_err(OE_PLUGIN, errno, "Failed to find %s when loading clixon plugin %s", CLIXON_PLUGIN_INIT, file); + clixon_err(OE_PLUGIN, errno, "Failed to find %s when loading clixon plugin %s", CLIXON_PLUGIN_INIT, file); goto done; } if ((error = (char*)dlerror()) != NULL) { - clicon_err(OE_UNIX, 0, "dlsym: %s: %s", file, error); + clixon_err(OE_UNIX, 0, "dlsym: %s: %s", file, error); goto done; } - clicon_err_reset(); + clixon_err_reset(); wh = NULL; if (plugin_context_check(h, &wh, file, __FUNCTION__) < 0) goto done; if ((api = initfn(h)) == NULL) { - if (!clicon_errno){ /* if clicon_err() is not called then log and continue */ - clicon_log(LOG_DEBUG, "Warning: failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file); + if (!clixon_err_category()){ /* if clixon_err() is not called then log and continue */ + clixon_log(h, LOG_DEBUG, "Warning: failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file); retval = 0; goto done; } else{ - clicon_err(OE_PLUGIN, errno, "Failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file); + clixon_err(OE_PLUGIN, errno, "Failed to initiate %s", strrchr(file,'/')?strchr(file, '/'):file); goto done; } } @@ -372,7 +374,7 @@ plugin_load_one(clicon_handle h, /* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */ if ((cp = (clixon_plugin_t *)malloc(sizeof(struct clixon_plugin))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(cp, 0, sizeof(struct clixon_plugin)); @@ -411,7 +413,7 @@ plugin_load_one(clicon_handle h, * @retval -1 Error */ int -clixon_plugins_load(clicon_handle h, +clixon_plugins_load(clixon_handle h, const char *function, const char *dir, const char *regexp) @@ -428,7 +430,7 @@ clixon_plugins_load(clicon_handle h, clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; } /* Get plugin objects names from plugin directory */ @@ -471,7 +473,7 @@ done: * @endcode */ int -clixon_pseudo_plugin(clicon_handle h, +clixon_pseudo_plugin(clixon_handle h, const char *name, clixon_plugin_t **cpp) { @@ -481,13 +483,13 @@ clixon_pseudo_plugin(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name); if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; } /* Create a pseudo plugins */ /* Note: sizeof clixon_plugin_api which is largest of clixon_plugin_api:s */ if ((cp = (clixon_plugin_t *)malloc(sizeof(struct clixon_plugin))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(cp, 0, sizeof(struct clixon_plugin)); @@ -516,17 +518,17 @@ plugin_context_get(void) struct plugin_context *pc = NULL; if ((pc = malloc(sizeof(*pc))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(pc, 0, sizeof(*pc)); if (sigprocmask(0, NULL, &pc->pc_sigset) < 0){ - clicon_err(OE_UNIX, errno, "sigprocmask"); + clixon_err(OE_UNIX, errno, "sigprocmask"); goto done; } for (i=1; i<32; i++){ if (sigaction(i, NULL, &pc->pc_sigaction_vec[i]) < 0){ - clicon_err(OE_UNIX, errno, "sigaction"); + clixon_err(OE_UNIX, errno, "sigaction"); goto done; } /* Mask SA_RESTORER: Not intended for application use. @@ -539,7 +541,7 @@ plugin_context_get(void) #endif } if (isatty(0) && tcgetattr(0, &pc->pc_termios) < 0){ - clicon_err(OE_UNIX, errno, "tcgetattr %d", errno); + clixon_err(OE_UNIX, errno, "tcgetattr %d", errno); goto done; } return pc; @@ -573,7 +575,7 @@ plugin_context_get(void) * @see CLICON_PLUGIN_CALLBACK_CHECK Enable to activate these checks */ int -plugin_context_check(clicon_handle h, +plugin_context_check(clixon_handle h, void **wh, const char *name, const char *fn) @@ -605,28 +607,28 @@ plugin_context_check(clicon_handle h, if ((newpc = plugin_context_get()) == NULL) goto done; if (oldpc->pc_termios.c_iflag != newpc->pc_termios.c_iflag){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios input modes from 0x%x to 0x%x", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios input modes from 0x%x to 0x%x", __FUNCTION__, name, fn, oldpc->pc_termios.c_iflag, newpc->pc_termios.c_iflag); failed++; } if (oldpc->pc_termios.c_oflag != newpc->pc_termios.c_oflag){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios output modes from 0x%x to 0x%x", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios output modes from 0x%x to 0x%x", __FUNCTION__, name, fn, oldpc->pc_termios.c_oflag, newpc->pc_termios.c_oflag); failed++; } if (oldpc->pc_termios.c_cflag != newpc->pc_termios.c_cflag){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios control modes from 0x%x to 0x%x", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios control modes from 0x%x to 0x%x", __FUNCTION__, name, fn, oldpc->pc_termios.c_cflag, newpc->pc_termios.c_cflag); failed++; } if (oldpc->pc_termios.c_lflag != newpc->pc_termios.c_lflag){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed termios local modes from 0x%x to 0x%x", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed termios local modes from 0x%x to 0x%x", __FUNCTION__, name, fn, oldpc->pc_termios.c_lflag, newpc->pc_termios.c_lflag); @@ -639,7 +641,7 @@ plugin_context_check(clicon_handle h, abort(); for (i=1; i<32; i++){ if (sigismember(&oldpc->pc_sigset, i) != sigismember(&newpc->pc_sigset, i)){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed blocking of signal %s(%d) from %d to %d", __FUNCTION__, name, fn, strsignal(i), i, sigismember(&oldpc->pc_sigset, i), sigismember(&newpc->pc_sigset, i) @@ -647,14 +649,14 @@ plugin_context_check(clicon_handle h, failed++; } if (oldpc->pc_sigaction_vec[i].sa_flags != newpc->pc_sigaction_vec[i].sa_flags){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed flags of signal %s(%d) from 0x%x to 0x%x", __FUNCTION__, name, fn, strsignal(i), i, oldpc->pc_sigaction_vec[i].sa_flags, newpc->pc_sigaction_vec[i].sa_flags);; failed++; } if (oldpc->pc_sigaction_vec[i].sa_sigaction != newpc->pc_sigaction_vec[i].sa_sigaction){ - clicon_log(LOG_WARNING, "%s Plugin context %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__, + clixon_log(h, LOG_WARNING, "%s Plugin context %s %s: Changed action of signal %s(%d) from %p to %p", __FUNCTION__, name, fn, strsignal(i), i, oldpc->pc_sigaction_vec[i].sa_sigaction, newpc->pc_sigaction_vec[i].sa_sigaction); @@ -690,7 +692,7 @@ plugin_context_check(clicon_handle h, */ int clixon_plugin_start_one(clixon_plugin_t *cp, - clicon_handle h) + clixon_handle h) { int retval = -1; plgstart_t *fn; /* Plugin start */ @@ -701,8 +703,8 @@ clixon_plugin_start_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Start callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Start callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -723,7 +725,7 @@ clixon_plugin_start_one(clixon_plugin_t *cp, * @note Start functions can use clicon_argv_get() to get -- command line options */ int -clixon_plugin_start_all(clicon_handle h) +clixon_plugin_start_all(clixon_handle h) { int retval = -1; clixon_plugin_t *cp = NULL; @@ -747,7 +749,7 @@ clixon_plugin_start_all(clicon_handle h) */ static int clixon_plugin_exit_one(clixon_plugin_t *cp, - clicon_handle h) + clixon_handle h) { int retval = -1; char *error; @@ -759,8 +761,8 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Exit callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Exit callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -768,7 +770,7 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, goto done; if (dlclose(cp->cp_handle) != 0) { error = (char*)dlerror(); - clicon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error"); + clixon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error"); } } retval = 0; @@ -783,7 +785,7 @@ clixon_plugin_exit_one(clixon_plugin_t *cp, * @retval -1 Error */ static int -clixon_plugin_exit_all(clicon_handle h) +clixon_plugin_exit_all(clixon_handle h) { int retval = -1; clixon_plugin_t *cp = NULL; @@ -819,7 +821,7 @@ clixon_plugin_exit_all(clicon_handle h) */ static int clixon_plugin_auth_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, void *req, clixon_auth_type_t auth_type, char **authp) @@ -834,8 +836,8 @@ clixon_plugin_auth_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if ((retval = fn(h, req, auth_type, authp)) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Auth callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Auth callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -865,7 +867,7 @@ clixon_plugin_auth_one(clixon_plugin_t *cp, * @note If authp returns string, it should be malloced */ int -clixon_plugin_auth_all(clicon_handle h, +clixon_plugin_auth_all(clixon_handle h, void *req, clixon_auth_type_t auth_type, char **authp) @@ -876,7 +878,7 @@ clixon_plugin_auth_all(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (authp == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL"); + clixon_err(OE_PLUGIN, EINVAL, "Authp output parameter is NULL"); goto done; } *authp = NULL; @@ -906,7 +908,7 @@ clixon_plugin_auth_all(clicon_handle h, */ int clixon_plugin_extension_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -919,8 +921,8 @@ clixon_plugin_extension_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, yext, ys) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Extension callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Extension callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -946,7 +948,7 @@ clixon_plugin_extension_one(clixon_plugin_t *cp, * @retval -1 Error in one callback */ int -clixon_plugin_extension_all(clicon_handle h, +clixon_plugin_extension_all(clixon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -975,7 +977,7 @@ clixon_plugin_extension_all(clicon_handle h, */ int clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd) @@ -990,8 +992,8 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, db, xt, msd) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Datastore upgrade callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Datastore upgrade callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -1014,7 +1016,7 @@ clixon_plugin_datastore_upgrade_one(clixon_plugin_t *cp, * Upgrade datastore on load before or as an alternative to module-specific upgrading mechanism */ int -clixon_plugin_datastore_upgrade_all(clicon_handle h, +clixon_plugin_datastore_upgrade_all(clixon_handle h, const char *db, cxobj *xt, modstate_diff_t *msd) @@ -1046,7 +1048,7 @@ clixon_plugin_datastore_upgrade_all(clicon_handle h, */ int clixon_plugin_yang_mount_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, cxobj *xt, int *config, validate_level *vl, @@ -1061,8 +1063,8 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, xt, config, vl, yanglib) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Yang mount callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Yang mount callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -1085,7 +1087,7 @@ clixon_plugin_yang_mount_one(clixon_plugin_t *cp, * @retval -1 Error */ int -clixon_plugin_yang_mount_all(clicon_handle h, +clixon_plugin_yang_mount_all(clixon_handle h, cxobj *xt, int *config, validate_level *vl, @@ -1116,7 +1118,7 @@ clixon_plugin_yang_mount_all(clicon_handle h, */ int clixon_plugin_yang_patch_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, yang_stmt *ymod) { int retval = -1; @@ -1128,8 +1130,8 @@ clixon_plugin_yang_patch_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, ymod) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Yang patch callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Yang patch callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -1149,7 +1151,7 @@ clixon_plugin_yang_patch_one(clixon_plugin_t *cp, * @retval -1 Error */ int -clixon_plugin_yang_patch_all(clicon_handle h, +clixon_plugin_yang_patch_all(clixon_handle h, yang_stmt *ymod) { int retval = -1; @@ -1175,7 +1177,7 @@ clixon_plugin_yang_patch_all(clicon_handle h, */ int clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, cxobj *xerr, cbuf *cberr) { @@ -1188,8 +1190,8 @@ clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, xerr, cberr) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: Netconf err callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: Netconf err callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -1210,7 +1212,7 @@ clixon_plugin_netconf_errmsg_one(clixon_plugin_t *cp, * @retval -1 Error */ int -clixon_plugin_netconf_errmsg_all(clicon_handle h, +clixon_plugin_netconf_errmsg_all(clixon_handle h, cxobj *xerr, cbuf *cberr) { @@ -1236,7 +1238,7 @@ clixon_plugin_netconf_errmsg_all(clicon_handle h, */ int clixon_plugin_version_one(clixon_plugin_t *cp, - clicon_handle h, + clixon_handle h, FILE *f) { int retval = -1; @@ -1248,8 +1250,8 @@ clixon_plugin_version_one(clixon_plugin_t *cp, if (plugin_context_check(h, &wh, cp->cp_name, __FUNCTION__) < 0) goto done; if (fn(h, f) < 0) { - if (clicon_errno < 0) - clicon_log(LOG_WARNING, "%s: Internal error: version callback in plugin: %s returned -1 but did not make a clicon_err call", + if (clixon_err_category() < 0) + clixon_log(h, LOG_WARNING, "%s: Internal error: version callback in plugin: %s returned -1 but did not make a clixon_err call", __FUNCTION__, cp->cp_name); goto done; } @@ -1269,7 +1271,7 @@ clixon_plugin_version_one(clixon_plugin_t *cp, * @retval -1 Error */ int -clixon_plugin_version_all(clicon_handle h, +clixon_plugin_version_all(clixon_handle h, FILE *f) { int retval = -1; @@ -1290,7 +1292,7 @@ clixon_plugin_version_all(clicon_handle h, #if 0 /* Debugging */ static int -rpc_callback_dump(clicon_handle h) +rpc_callback_dump(clixon_handle h) { rpc_callback_t *rc; plugin_module_struct *ms = plugin_module_struct_get(h); @@ -1317,7 +1319,7 @@ rpc_callback_dump(clicon_handle h) * @see rpc_callback_call which makes the actual callback */ int -rpc_callback_register(clicon_handle h, +rpc_callback_register(clixon_handle h, clicon_rpc_cb cb, void *arg, const char *ns, @@ -1328,15 +1330,15 @@ rpc_callback_register(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name); if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; } if (name == NULL || ns == NULL){ - clicon_err(OE_DB, EINVAL, "name or namespace NULL"); + clixon_err(OE_DB, EINVAL, "name or namespace NULL"); goto done; } if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc"); + clixon_err(OE_DB, errno, "malloc"); goto done; } memset(rc, 0, sizeof(*rc)); @@ -1360,7 +1362,7 @@ rpc_callback_register(clicon_handle h, /*! Delete all RPC callbacks */ static int -rpc_callback_delete_all(clicon_handle h) +rpc_callback_delete_all(clixon_handle h) { rpc_callback_t *rc; plugin_module_struct *ms = plugin_module_struct_get(h); @@ -1393,7 +1395,7 @@ rpc_callback_delete_all(clicon_handle h) * leaving it, replacing it or amending it. */ int -rpc_callback_call(clicon_handle h, +rpc_callback_call(clixon_handle h, cxobj *xe, void *arg, int *nrp, @@ -1410,7 +1412,7 @@ rpc_callback_call(clicon_handle h, int ret; if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; } name = xml_name(xe); @@ -1470,7 +1472,7 @@ rpc_callback_call(clicon_handle h, * @see rpc_callback_register which registers global callbacks */ int -action_callback_register(clicon_handle h, +action_callback_register(clixon_handle h, yang_stmt *ya, clicon_rpc_cb cb, void *arg) @@ -1481,12 +1483,12 @@ action_callback_register(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (ya == NULL){ - clicon_err(OE_DB, EINVAL, "yang node is NULL"); + clixon_err(OE_DB, EINVAL, "yang node is NULL"); goto done; } name = yang_argument_get(ya); if ((rc = malloc(sizeof(rpc_callback_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc"); + clixon_err(OE_DB, errno, "malloc"); goto done; } memset(rc, 0, sizeof(*rc)); @@ -1517,7 +1519,7 @@ action_callback_register(clicon_handle h, * leaving it, replacing it or amending it. */ int -action_callback_call(clicon_handle h, +action_callback_call(clixon_handle h, cxobj *xe, cbuf *cbret, void *arg, @@ -1594,7 +1596,7 @@ action_callback_call(clicon_handle h, * @see upgrade_callback_call which makes the actual callback */ int -upgrade_callback_reg_fn(clicon_handle h, +upgrade_callback_reg_fn(clixon_handle h, clicon_upgrade_cb cb, const char *fnstr, const char *ns, @@ -1604,11 +1606,11 @@ upgrade_callback_reg_fn(clicon_handle h, plugin_module_struct *ms = plugin_module_struct_get(h); if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; } if ((uc = malloc(sizeof(upgrade_callback_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc"); + clixon_err(OE_DB, errno, "malloc"); goto done; } memset(uc, 0, sizeof(*uc)); @@ -1631,7 +1633,7 @@ upgrade_callback_reg_fn(clicon_handle h, /*! Delete all Upgrade callbacks */ static int -upgrade_callback_delete_all(clicon_handle h) +upgrade_callback_delete_all(clixon_handle h) { upgrade_callback_t *uc; plugin_module_struct *ms = plugin_module_struct_get(h); @@ -1661,7 +1663,7 @@ upgrade_callback_delete_all(clicon_handle h) * @see upgrade_callback_reg_fn which registers the callbacks */ int -upgrade_callback_call(clicon_handle h, +upgrade_callback_call(clixon_handle h, cxobj *xt, char *ns, uint16_t op, @@ -1676,7 +1678,7 @@ upgrade_callback_call(clicon_handle h, plugin_module_struct *ms = plugin_module_struct_get(h); if (ms == NULL){ - clicon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); + clixon_err(OE_PLUGIN, EINVAL, "plugin module not initialized"); goto done; } if ((uc = ms->ms_upgrade_callbacks) != NULL) @@ -1696,7 +1698,7 @@ upgrade_callback_call(clicon_handle h, } if (ret == 0){ if (cbuf_len(cbret)==0){ - clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set", + clixon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set", uc->uc_fnstr, ns); goto done; } @@ -1751,17 +1753,17 @@ clixon_auth_type_int2str(clixon_auth_type_t auth_type) * @see clixon_plugin_module_exit */ int -clixon_plugin_module_init(clicon_handle h) +clixon_plugin_module_init(clixon_handle h) { int retval = -1; struct plugin_module_struct *ph; if (plugin_module_struct_get(h) != NULL){ - clicon_err(OE_PLUGIN, EFAULT, "Already initialized"); + clixon_err(OE_PLUGIN, EFAULT, "Already initialized"); goto done; } if ((ph = malloc(sizeof(*ph))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(ph, 0, sizeof(*ph)); @@ -1778,7 +1780,7 @@ clixon_plugin_module_init(clicon_handle h) * @param[in] h Clixon handle */ int -clixon_plugin_module_exit(clicon_handle h) +clixon_plugin_module_exit(clixon_handle h) { struct plugin_module_struct *ph; diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index 0ed01b1b..08d34cb0 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -110,12 +110,13 @@ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_options.h" #include "clixon_uid.h" #include "clixon_event.h" @@ -159,7 +160,7 @@ struct process_entry_t { }; /* Forward declaration */ -static int clixon_process_sched_register(clicon_handle h, int delay); +static int clixon_process_sched_register(clixon_handle h, int delay); static int clixon_process_delete_only(process_entry_t *pe); static void @@ -170,6 +171,7 @@ clixon_proc_sigint(int sig) /*! Fork a child, exec a child and setup socket to child and return to caller * + * @param[in] h Clixon handle * @param[in] argv NULL-terminated Argument vector * @param[in] sock_flags Socket type/flags, typically SOCK_DGRAM or SOCK_STREAM, see * @param[out] pid Process-id of child @@ -180,10 +182,11 @@ clixon_proc_sigint(int sig) * @see for flags usage see man sockerpair(2) */ int -clixon_proc_socket(char **argv, - int sock_flags, - pid_t *pid, - int *sock) +clixon_proc_socket(clixon_handle h, + char **argv, + int sock_flags, + pid_t *pid, + int *sock) { int retval = -1; int sp[2] = {-1, -1}; @@ -195,25 +198,25 @@ clixon_proc_socket(char **argv, char *flattened; if (argv == NULL){ - clicon_err(OE_UNIX, EINVAL, "argv is NULL"); + clixon_err(OE_UNIX, EINVAL, "argv is NULL"); goto done; } if (argv[0] == NULL){ - clicon_err(OE_UNIX, EINVAL, "argv[0] is NULL"); + clixon_err(OE_UNIX, EINVAL, "argv[0] is NULL"); goto done; } for (argc = 0; argv[argc] != NULL; ++argc) ; if ((flattened = clicon_strjoin(argc, argv, "', '")) == NULL){ - clicon_err(OE_UNIX, ENOMEM, "clicon_strjoin"); + clixon_err(OE_UNIX, ENOMEM, "clicon_strjoin"); goto done; } - clicon_log(LOG_INFO, "%s '%s'", __FUNCTION__, flattened); + clixon_log(h, LOG_INFO, "%s '%s'", __FUNCTION__, flattened); free(flattened); if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){ - clicon_err(OE_UNIX, errno, "socketpair"); + clixon_err(OE_UNIX, errno, "socketpair"); goto done; } @@ -221,7 +224,7 @@ clixon_proc_socket(char **argv, set_signal(SIGINT, clixon_proc_sigint, &oldhandler); sig++; if ((child = fork()) < 0) { - clicon_err(OE_UNIX, errno, "fork"); + clixon_err(OE_UNIX, errno, "fork"); goto done; } if (child == 0) { /* Child */ @@ -232,17 +235,17 @@ clixon_proc_socket(char **argv, close(sp[0]); close(0); if (dup2(sp[1], STDIN_FILENO) < 0){ - clicon_err(OE_UNIX, errno, "dup2(STDIN)"); + clixon_err(OE_UNIX, errno, "dup2(STDIN)"); return -1; } close(1); if (dup2(sp[1], STDOUT_FILENO) < 0){ - clicon_err(OE_UNIX, errno, "dup2(STDOUT)"); + clixon_err(OE_UNIX, errno, "dup2(STDOUT)"); return -1; } close(sp[1]); if (execvp(argv[0], argv) < 0){ - clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); + clixon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); return -1; } exit(-1); /* Shouldnt reach here */ @@ -288,6 +291,7 @@ clixon_proc_socket_close(pid_t pid, /*! Fork and exec a sub-process, let it run and return pid * + * @param[in] h Clixon handle * @param[in] argv NULL-terminated Argument vector * @param[in] netns Network namespace (or NULL) * @param[in] uid User-id or -1 to keep existing @@ -297,12 +301,13 @@ clixon_proc_socket_close(pid_t pid, * @retval -1 Error. */ static int -clixon_proc_background(char **argv, - const char *netns, - uid_t uid, - gid_t gid, - int fdkeep, - pid_t *pid0) +clixon_proc_background(clixon_handle h, + char **argv, + const char *netns, + uid_t uid, + gid_t gid, + int fdkeep, + pid_t *pid0) { int retval = -1; pid_t child = 0; @@ -316,26 +321,26 @@ clixon_proc_background(char **argv, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (argv == NULL){ - clicon_err(OE_UNIX, EINVAL, "argv is NULL"); + clixon_err(OE_UNIX, EINVAL, "argv is NULL"); goto quit; } if (argv[0] == NULL){ - clicon_err(OE_UNIX, EINVAL, "argv[0] is NULL"); + clixon_err(OE_UNIX, EINVAL, "argv[0] is NULL"); goto quit; } for (argc = 0; argv[argc] != NULL; ++argc) ; if ((flattened = clicon_strjoin(argc, argv, "', '")) == NULL){ - clicon_err(OE_UNIX, ENOMEM, "clicon_strjoin"); + clixon_err(OE_UNIX, ENOMEM, "clicon_strjoin"); goto quit; } - clicon_log(LOG_INFO, "%s '%s'", __FUNCTION__, flattened); + clixon_log(h, LOG_INFO, "%s '%s'", __FUNCTION__, flattened); free(flattened); /* Sanity check: program exists */ if (stat(argv[0], &fstat) < 0) { - clicon_err(OE_FATAL, errno, "%s", argv[0]); + clixon_err(OE_FATAL, errno, "%s", argv[0]); goto quit; } /* Before here call quit on error */ @@ -343,7 +348,7 @@ clixon_proc_background(char **argv, set_signal(SIGINT, clixon_proc_sigint, &oldhandler); /* Now call done on error */ if ((child = fork()) < 0) { - clicon_err(OE_UNIX, errno, "fork"); + clixon_err(OE_UNIX, errno, "fork"); goto done; } if (child == 0) { /* Child */ @@ -355,7 +360,7 @@ clixon_proc_background(char **argv, clicon_signal_unblock(0); signal(SIGTSTP, SIG_IGN); if (chdir("/") < 0){ - clicon_err(OE_UNIX, errno, "chdir"); + clixon_err(OE_UNIX, errno, "chdir"); exit(1); } /* Close open descriptors */ @@ -374,23 +379,23 @@ clixon_proc_background(char **argv, clixon_debug(CLIXON_DBG_DEFAULT, "%s nsfile:%s", __FUNCTION__, nsfile); /* Change network namespace */ if ((nsfd = open(nsfile, O_RDONLY | O_CLOEXEC)) < 0){ - clicon_err(OE_UNIX, errno, "open"); + clixon_err(OE_UNIX, errno, "open"); exit(1); } if (setns(nsfd, 0) < 0){ /* Join that namespace */ - clicon_err(OE_UNIX, errno, "setns"); + clixon_err(OE_UNIX, errno, "setns"); exit(1); } close(nsfd); if (unshare(CLONE_NEWNS) < 0){ - clicon_err(OE_UNIX, errno, "unshare"); + clixon_err(OE_UNIX, errno, "unshare"); exit(1); } } #endif /* HAVE_SETNS */ if (gid != -1){ if (setgid(gid) == -1) { - clicon_err(OE_DAEMON, errno, "setgid %d", gid); + clixon_err(OE_DAEMON, errno, "setgid %d", gid); goto done; } } @@ -399,7 +404,7 @@ clixon_proc_background(char **argv, goto done; } if (execvp(argv[0], argv) < 0) { - clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); + clixon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); exit(1); } /* Not reached */ @@ -456,7 +461,7 @@ clixon_process_op_str2int(char *opstr) * itself, but its elements can be freed and re-alloced. */ int -clixon_process_argv_get(clicon_handle h, +clixon_process_argv_get(clixon_handle h, const char *name, char ***argv, int *argc) @@ -491,7 +496,7 @@ clixon_process_argv_get(clicon_handle h, * @note name, netns, argv and its elements are all copied / re-alloced. */ int -clixon_process_register(clicon_handle h, +clixon_process_register(clixon_handle h, const char *name, const char *description, const char *netns, @@ -507,33 +512,33 @@ clixon_process_register(clicon_handle h, int i; if (name == NULL){ - clicon_err(OE_DB, EINVAL, "name is NULL"); + clixon_err(OE_DB, EINVAL, "name is NULL"); goto done; } if (argv == NULL){ - clicon_err(OE_DB, EINVAL, "argv is NULL"); + clixon_err(OE_DB, EINVAL, "argv is NULL"); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s name:%s (%s)", __FUNCTION__, name, argv[0]); if ((pe = malloc(sizeof(process_entry_t))) == NULL) { - clicon_err(OE_DB, errno, "malloc"); + clixon_err(OE_DB, errno, "malloc"); goto done; } memset(pe, 0, sizeof(*pe)); if ((pe->pe_name = strdup(name)) == NULL){ - clicon_err(OE_DB, errno, "strdup name"); + clixon_err(OE_DB, errno, "strdup name"); free(pe); goto done; } if (description && (pe->pe_description = strdup(description)) == NULL){ - clicon_err(OE_DB, errno, "strdup description"); + clixon_err(OE_DB, errno, "strdup description"); clixon_process_delete_only(pe); goto done; } if (netns && (pe->pe_netns = strdup(netns)) == NULL){ - clicon_err(OE_DB, errno, "strdup netns"); + clixon_err(OE_DB, errno, "strdup netns"); clixon_process_delete_only(pe); goto done; } @@ -542,14 +547,14 @@ clixon_process_register(clicon_handle h, pe->pe_fdkeep = fdkeep; pe->pe_argc = argc; if ((pe->pe_argv = calloc(argc, sizeof(char *))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); clixon_process_delete_only(pe); goto done; } for (i=0; ipe_argv[i] = strdup(argv[i])) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); clixon_process_delete_only(pe); goto done; } @@ -591,7 +596,7 @@ clixon_process_delete_only(process_entry_t *pe) /*! Delete all Upgrade callbacks */ int -clixon_process_delete_all(clicon_handle h) +clixon_process_delete_all(clixon_handle h) { process_entry_t *pe; @@ -621,7 +626,7 @@ proc_op_run(pid_t pid0, run = 0; } else{ - clicon_err(OE_UNIX, errno, "kill(%d)", pid); + clixon_err(OE_UNIX, errno, "kill(%d)", pid); goto done; } } @@ -634,7 +639,7 @@ proc_op_run(pid_t pid0, } int -clixon_process_pid(clicon_handle h, +clixon_process_pid(clixon_handle h, const char *name, pid_t *pid) { @@ -682,7 +687,7 @@ done: * @see clixon_process_sched where operations are actually executed */ int -clixon_process_operation(clicon_handle h, +clixon_process_operation(clixon_handle h, const char *name, proc_operation op0, int wrapit) @@ -716,7 +721,7 @@ clixon_process_operation(clicon_handle h, if (proc_op_run(pe->pe_pid, &isrunning) < 0) goto done; if (isrunning) { - clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d", + clixon_log(h, LOG_NOTICE, "Killing old process %s with pid: %d", pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */ kill(pe->pe_pid, SIGTERM); delay = 1; @@ -757,7 +762,7 @@ clixon_process_operation(clicon_handle h, */ int -clixon_process_status(clicon_handle h, +clixon_process_status(clixon_handle h, const char *name, cbuf *cbret) { @@ -798,7 +803,7 @@ clixon_process_status(clicon_handle h, clicon_int2str(proc_state_map, pe->pe_state)); if (timerisset(&pe->pe_starttime)){ if (time2str(&pe->pe_starttime, timestr, sizeof(timestr)) < 0){ - clicon_err(OE_UNIX, errno, "time2str"); + clixon_err(OE_UNIX, errno, "time2str"); goto done; } cprintf(cbret, "%s", CLIXON_LIB_NS, timestr); @@ -831,7 +836,7 @@ clixon_process_status(clicon_handle h, * where commits are not made. */ int -clixon_process_start_all(clicon_handle h) +clixon_process_start_all(clixon_handle h) { int retval = -1; process_entry_t *pe; @@ -878,7 +883,7 @@ clixon_process_start_all(clicon_handle h) */ static int clixon_process_sched(int fd, - clicon_handle h) + clixon_handle h) { int retval = -1; process_entry_t *pe; @@ -903,7 +908,7 @@ clixon_process_sched(int fd, if (proc_op_run(pe->pe_pid, &isrunning) < 0) goto done; if (isrunning) { - clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d", + clixon_log(h, LOG_NOTICE, "Killing old process %s with pid: %d", pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */ kill(pe->pe_pid, SIGTERM); sched++; /* Not immediate: wait timeout */ @@ -921,7 +926,7 @@ clixon_process_sched(int fd, if (proc_op_run(pe->pe_pid, &isrunning) < 0) goto done; if (!isrunning) - if (clixon_proc_background(pe->pe_argv, pe->pe_netns, + if (clixon_proc_background(h, pe->pe_argv, pe->pe_netns, pe->pe_uid, pe->pe_gid, pe->pe_fdkeep, &pe->pe_pid) < 0) goto done; @@ -949,7 +954,7 @@ clixon_process_sched(int fd, case PROC_OP_START: if (isrunning) /* Already runs */ break; - if (clixon_proc_background(pe->pe_argv, pe->pe_netns, + if (clixon_proc_background(h, pe->pe_argv, pe->pe_netns, pe->pe_uid, pe->pe_gid, pe->pe_fdkeep, &pe->pe_pid) < 0) goto done; @@ -992,7 +997,7 @@ clixon_process_sched(int fd, * @retval -1 Error */ static int -clixon_process_sched_register(clicon_handle h, +clixon_process_sched_register(clixon_handle h, int delay) { int retval = -1; @@ -1021,7 +1026,7 @@ clixon_process_sched_register(clicon_handle h, */ int -clixon_process_waitpid(clicon_handle h) +clixon_process_waitpid(clixon_handle h) { int retval = -1; process_entry_t *pe; @@ -1063,7 +1068,7 @@ clixon_process_waitpid(clicon_handle h) case PROC_OP_RESTART: /* This is the case where there is an existing process running. * it was killed above but still runs and needs to be reaped */ - if (clixon_proc_background(pe->pe_argv, pe->pe_netns, + if (clixon_proc_background(h, pe->pe_argv, pe->pe_netns, pe->pe_uid, pe->pe_gid, pe->pe_fdkeep, &pe->pe_pid) < 0) goto done; diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 8d67cd7d..d3d929fd 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -63,13 +63,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" #include "clixon_event.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_sig.h" #include "clixon_xml.h" @@ -158,7 +159,7 @@ clicon_msg_encode(uint32_t id, len = hdrlen + xmllen; if ((msg = (struct clicon_msg *)malloc(len)) == NULL){ - clicon_err(OE_PROTO, errno, "malloc"); + clixon_err(OE_PROTO, errno, "malloc"); return NULL; } memset(msg, 0, len); @@ -182,7 +183,7 @@ clicon_msg_encode(uint32_t id, * @param[out] xerr Reason for failure (yang assignment not made) if retval =0 * @retval 1 Parse OK and all yang assignment made * @retval 0 Parse OK but yang assigment not made (or only partial) - * @retval -1 Error with clicon_err called. Includes parse error + * @retval -1 Error with clixon_err called. Includes parse error */ int clicon_msg_decode(struct clicon_msg *msg, @@ -222,7 +223,7 @@ clicon_msg_decode(struct clicon_msg *msg, * @retval -1 Error */ int -clicon_connect_unix(clicon_handle h, +clicon_connect_unix(clixon_handle h, char *sockpath) { struct sockaddr_un addr; @@ -230,7 +231,7 @@ clicon_connect_unix(clicon_handle h, int s; if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - clicon_err(OE_CFG, errno, "socket"); + clixon_err(OE_CFG, errno, "socket"); return -1; } memset(&addr, 0, sizeof(addr)); @@ -240,11 +241,11 @@ clicon_connect_unix(clicon_handle h, clixon_debug(CLIXON_DBG_DETAIL, "%s: connecting to %s", __FUNCTION__, addr.sun_path); if (connect(s, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0){ if (errno == EACCES) - clicon_err(OE_CFG, errno, "connecting unix socket: %s. " + clixon_err(OE_CFG, errno, "connecting unix socket: %s. " "Is user not member of group: \"%s\"?", sockpath, clicon_sock_group(h)); else - clicon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath); + clixon_err(OE_CFG, errno, "connecting unix socket: %s", sockpath); close(s); goto done; } @@ -323,7 +324,7 @@ msg_hex(int dbglevel, if ((dbglevel & clixon_debug_get()) == 0) /* compare debug level with global variable */ goto ok; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_CFG, errno, "cbuf_new"); + clixon_err(OE_CFG, errno, "cbuf_new"); goto done; } cprintf(cb, "%s:", file); @@ -374,8 +375,8 @@ clicon_msg_send(int s, if (atomicio((ssize_t (*)(int, void *, size_t))write, s, msg, ntohl(msg->op_len)) < 0){ e = errno; - clicon_err(OE_CFG, e, "atomicio"); - clicon_log(LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__, + clixon_err(OE_CFG, e, "atomicio"); + clixon_log(NULL, LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__, strerror(e), ntohs(msg->op_len), msg->op_body); goto done; } @@ -428,7 +429,7 @@ clicon_msg_rcv(int s, if (intr && _atomicio_sig) ; else - clicon_err(OE_CFG, errno, "atomicio"); + clixon_err(OE_CFG, errno, "atomicio"); goto done; } msg_hex(CLIXON_DBG_EXTRA, (char*)&hdr, hlen, __FUNCTION__); @@ -437,7 +438,7 @@ clicon_msg_rcv(int s, goto ok; } if (hlen != sizeof(hdr)){ - clicon_err(OE_PROTO, errno, "header too short (%d)", hlen); + clixon_err(OE_PROTO, errno, "header too short (%d)", hlen); goto done; } mlen = ntohl(hdr.op_len); @@ -446,28 +447,28 @@ clicon_msg_rcv(int s, clixon_debug(CLIXON_DBG_DETAIL, "%s: rcv msg len=%d", __FUNCTION__, mlen); if (mlen <= sizeof(hdr)){ - clicon_err(OE_PROTO, 0, "op_len:%u too short", mlen); + clixon_err(OE_PROTO, 0, "op_len:%u too short", mlen); *eof = 1; goto ok; } if ((*msg = (struct clicon_msg *)malloc(mlen+1)) == NULL){ - clicon_err(OE_PROTO, errno, "malloc"); + clixon_err(OE_PROTO, errno, "malloc"); goto done; } memcpy(*msg, &hdr, hlen); if ((len2 = atomicio(read, s, (*msg)->op_body, mlen - sizeof(hdr))) < 0){ - clicon_err(OE_PROTO, errno, "read"); + clixon_err(OE_PROTO, errno, "read"); goto done; } if (len2) msg_hex(CLIXON_DBG_EXTRA, (*msg)->op_body, len2, __FUNCTION__); if (len2 != mlen - sizeof(hdr)){ - clicon_err(OE_PROTO, 0, "body too short"); + clixon_err(OE_PROTO, 0, "body too short"); *eof = 1; goto ok; } if (((char*)*msg)[mlen-1] != '\0'){ - clicon_err(OE_PROTO, 0, "body not NULL terminated"); + clixon_err(OE_PROTO, 0, "body not NULL terminated"); *eof = 1; goto ok; } @@ -519,7 +520,7 @@ clicon_msg_rcv1(int s, if (errno == ECONNRESET) len = 0; /* emulate EOF */ else{ - clicon_log(LOG_ERR, "%s: read: %s errno:%d", __FUNCTION__, strerror(errno), errno); + clixon_log(NULL, LOG_ERR, "%s: read: %s errno:%d", __FUNCTION__, strerror(errno), errno); goto done; } } /* read */ @@ -581,8 +582,8 @@ clicon_msg_send1(int s, clixon_debug(CLIXON_DBG_MSG, "Send: %s", cbuf_get(cb)); if (atomicio((ssize_t (*)(int, void *, size_t))write, s, cbuf_get(cb), cbuf_len(cb)) < 0){ - clicon_err(OE_CFG, errno, "atomicio"); - clicon_log(LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno)); + clixon_err(OE_CFG, errno, "atomicio"); + clixon_log(NULL, LOG_WARNING, "%s: write: %s", __FUNCTION__, strerror(errno)); goto done; } retval = 0; @@ -602,7 +603,7 @@ clicon_msg_send1(int s, * @see clicon_rpc But this is one-shot rpc: open, send, get reply and close. */ int -clicon_rpc_connect_unix(clicon_handle h, +clicon_rpc_connect_unix(clixon_handle h, char *sockpath, int *sock0) { @@ -612,16 +613,16 @@ clicon_rpc_connect_unix(clicon_handle h, clixon_debug(CLIXON_DBG_DETAIL, "Send msg on %s", sockpath); if (sock0 == NULL){ - clicon_err(OE_NETCONF, EINVAL, "sock0 expected"); + clixon_err(OE_NETCONF, EINVAL, "sock0 expected"); goto done; } /* special error handling to get understandable messages (otherwise ENOENT) */ if (stat(sockpath, &sb) < 0){ - clicon_err(OE_PROTO, errno, "%s: config daemon not running?", sockpath); + clixon_err(OE_PROTO, errno, "%s: config daemon not running?", sockpath); goto done; } if (!S_ISSOCK(sb.st_mode)){ - clicon_err(OE_PROTO, EIO, "%s: Not unix socket", sockpath); + clixon_err(OE_PROTO, EIO, "%s: Not unix socket", sockpath); goto done; } if ((s = clicon_connect_unix(h, sockpath)) < 0) @@ -644,7 +645,7 @@ clicon_rpc_connect_unix(clicon_handle h, * @see clicon_rpc But this is one-shot rpc: open, send, get reply and close. */ int -clicon_rpc_connect_inet(clicon_handle h, +clicon_rpc_connect_inet(clixon_handle h, char *dst, uint16_t port, int *sock0) @@ -655,7 +656,7 @@ clicon_rpc_connect_inet(clicon_handle h, clixon_debug(CLIXON_DBG_DETAIL, "Send msg to %s:%hu", dst, port); if (sock0 == NULL){ - clicon_err(OE_NETCONF, EINVAL, "sock0 expected"); + clixon_err(OE_NETCONF, EINVAL, "sock0 expected"); goto done; } memset(&addr, 0, sizeof(addr)); @@ -665,11 +666,11 @@ clicon_rpc_connect_inet(clicon_handle h, goto done; /* Could check getaddrinfo */ /* special error handling to get understandable messages (otherwise ENOENT) */ if ((s = socket(addr.sin_family, SOCK_STREAM, 0)) < 0) { - clicon_err(OE_CFG, errno, "socket"); + clixon_err(OE_CFG, errno, "socket"); return -1; } if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) < 0){ - clicon_err(OE_CFG, errno, "connecting socket inet4"); + clixon_err(OE_CFG, errno, "connecting socket inet4"); close(s); goto done; } @@ -716,7 +717,7 @@ clicon_rpc(int sock, data = reply->op_body; /* assume string */ if (ret && data) if ((*ret = strdup(data)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } ok: @@ -839,7 +840,7 @@ send_msg_notify(int s, * @see send_msg_notify */ int -send_msg_notify_xml(clicon_handle h, +send_msg_notify_xml(clixon_handle h, int s, const char *descr, cxobj *xev) @@ -848,7 +849,7 @@ send_msg_notify_xml(clicon_handle h, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_PLUGIN, errno, "cbuf_new"); + clixon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(cb, xev, 0, 0, NULL, -1, 0) < 0) @@ -941,7 +942,7 @@ clixon_inet2sin(const char *addrtype, sin->sin_addr.s_addr = inet_addr(addrstr); } else{ - clicon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype); + clixon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype); return -1; } return 0; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 54b310c7..2746d171 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -57,11 +57,13 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_options.h" @@ -72,7 +74,6 @@ #include "clixon_xpath_ctx.h" #include "clixon_xpath.h" #include "clixon_proto.h" -#include "clixon_err.h" #include "clixon_event.h" #include "clixon_stream.h" #include "clixon_err_string.h" @@ -95,7 +96,7 @@ * @retval -1 Error */ int -clicon_rpc_connect(clicon_handle h, +clicon_rpc_connect(clixon_handle h, int *sockp) { int retval = -1; @@ -103,7 +104,7 @@ clicon_rpc_connect(clicon_handle h, int port; if ((sockstr = clicon_sock_str(h)) == NULL){ - clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); + clixon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); goto done; } /* What to do if inet socket? */ @@ -121,11 +122,11 @@ clicon_rpc_connect(clicon_handle h, break; case AF_INET: if ((port = clicon_sock_port(h)) < 0){ - clicon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); + clixon_err(OE_FATAL, 0, "CLICON_SOCK option not set"); goto done; } if (port < 0){ - clicon_err(OE_FATAL, 0, "CLICON_SOCK_PORT not set"); + clixon_err(OE_FATAL, 0, "CLICON_SOCK_PORT not set"); goto done; } if (clicon_rpc_connect_inet(h, sockstr, port, sockp) < 0) @@ -149,7 +150,7 @@ clicon_rpc_connect(clicon_handle h, * @retval -1 Error */ static int -clicon_rpc_msg_once(clicon_handle h, +clicon_rpc_msg_once(clixon_handle h, struct clicon_msg *msg, int cache, char **retdata, @@ -195,7 +196,7 @@ clicon_rpc_msg_once(clicon_handle h, * @see clicon_rpc_close_session */ int -clicon_rpc_msg(clicon_handle h, +clicon_rpc_msg(clixon_handle h, struct clicon_msg *msg, cxobj **xret0) { @@ -225,16 +226,16 @@ clicon_rpc_msg(clicon_handle h, close(s); s = -1; clicon_client_socket_set(h, -1); - clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); + clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); goto done; } /* To disable this restart, unset PROTO_RESTART_RECONNECT */ clicon_session_id_del(h); - clicon_log(LOG_WARNING, "The backend was probably restarted and the client has reconnected to the backend. Any locks or candidate edits are lost."); + clixon_log(h, LOG_WARNING, "The backend was probably restarted and the client has reconnected to the backend. Any locks or candidate edits are lost."); } #else - clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); + clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); goto done; #endif } @@ -272,7 +273,7 @@ clicon_rpc_msg(clicon_handle h, * @note xret is populated with yangspec according to standard handle yangspec */ int -clicon_rpc_msg_persistent(clicon_handle h, +clicon_rpc_msg_persistent(clixon_handle h, struct clicon_msg *msg, cxobj **xret0, int *sock0) @@ -284,7 +285,7 @@ clicon_rpc_msg_persistent(clicon_handle h, int eof = 0; if (sock0 == NULL){ - clicon_err(OE_NETCONF, EINVAL, "Missing socket pointer"); + clixon_err(OE_NETCONF, EINVAL, "Missing socket pointer"); goto done; } #ifdef RPC_USERNAME_ASSERT @@ -302,7 +303,7 @@ clicon_rpc_msg_persistent(clicon_handle h, /* Note here one could try a restart as done in clicon_rpc_msg, but seems not * right since if backend is restarted, the notification stream is gone. */ - clicon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); + clixon_err(OE_PROTO, ESHUTDOWN, "Unexpected close of CLICON_SOCK. Clixon backend daemon may have crashed."); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "%s retdata:%s", __FUNCTION__, retdata); @@ -345,7 +346,7 @@ clicon_rpc_msg_persistent(clicon_handle h, * @note This function may send a synchronous(blocking) HELLO request to the backend as a side-effect */ static int -session_id_check(clicon_handle h, +session_id_check(clixon_handle h, uint32_t *session_id) { int retval = -1; @@ -381,7 +382,7 @@ session_id_check(clicon_handle h, * @see clicon_rpc_netconf_xml xml as tree instead of string */ int -clicon_rpc_netconf(clicon_handle h, +clicon_rpc_netconf(clixon_handle h, char *xmlstr, cxobj **xret, int *sp) @@ -427,7 +428,7 @@ clicon_rpc_netconf(clicon_handle h, * @see clicon_rpc_netconf xml as string instead of tree */ int -clicon_rpc_netconf_xml(clicon_handle h, +clicon_rpc_netconf_xml(clixon_handle h, cxobj *xml, cxobj **xret, int *sp) @@ -442,11 +443,11 @@ clicon_rpc_netconf_xml(clicon_handle h, int ret; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if ((xname = xml_child_i_type(xml, 0, 0)) == NULL){ - clicon_err(OE_NETCONF, EINVAL, "Missing rpc name"); + clixon_err(OE_NETCONF, EINVAL, "Missing rpc name"); goto done; } rpcname = xml_name(xname); /* Store rpc name and use in yang binding after reply */ @@ -512,7 +513,7 @@ clicon_rpc_netconf_xml(clicon_handle h, * @note the netconf return message is yang populated, as well as the return data */ int -clicon_rpc_get_config(clicon_handle h, +clicon_rpc_get_config(clixon_handle h, char *username, // XXX: why is this only rpc call with username parameter? char *db, char *xpath, @@ -534,7 +535,7 @@ clicon_rpc_get_config(clicon_handle h, if (session_id_check(h, &session_id) < 0) goto done; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, " -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_options.h" #include "clixon_regex.h" @@ -245,7 +246,7 @@ regexp_xsd2posix(char *xsd, size_t len; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } esc=0; @@ -357,7 +358,7 @@ regexp_xsd2posix(char *xsd, cprintf(cb, "%c", x); } if ((*posix = strdup(cbuf_get(cb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } retval = 0; @@ -382,7 +383,7 @@ regexp_xsd2posix(char *xsd, * translate from XSD to POSIX. */ int -regex_compile(clicon_handle h, +regex_compile(clixon_handle h, char *regexp, void **recomp) { @@ -399,7 +400,7 @@ regex_compile(clicon_handle h, retval = cligen_regex_libxml2_compile(regexp, recomp); break; default: - clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h)); + clixon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h)); break; } /* retval from fns above */ @@ -418,7 +419,7 @@ regex_compile(clicon_handle h, * @retval -1 Error */ int -regex_exec(clicon_handle h, +regex_exec(clixon_handle h, void *recomp, char *string) { @@ -432,7 +433,7 @@ regex_exec(clicon_handle h, retval = cligen_regex_libxml2_exec(recomp, string); break; default: - clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", + clixon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h)); goto done; } @@ -449,7 +450,7 @@ regex_exec(clicon_handle h, * @retval -1 Error */ int -regex_free(clicon_handle h, +regex_free(clixon_handle h, void *recomp) { int retval = -1; @@ -462,7 +463,7 @@ regex_free(clicon_handle h, retval = cligen_regex_libxml2_free(recomp); break; default: - clicon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h)); + clixon_err(OE_CFG, 0, "clicon_yang_regexp invalid value: %d", clicon_yang_regexp(h)); goto done; } /* retval from fns above */ diff --git a/lib/src/clixon_sig.c b/lib/src/clixon_sig.c index 85a6b77f..ce8cdc79 100644 --- a/lib/src/clixon_sig.c +++ b/lib/src/clixon_sig.c @@ -52,8 +52,12 @@ #include /* clixon */ +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_sig.h" /*! Set a signal handler. @@ -96,7 +100,7 @@ set_signal_flags(int signo, sigemptyset(&snew.sa_mask); snew.sa_flags = flags; if (sigaction(signo, &snew, &sold) < 0){ - clicon_err(OE_UNIX, errno, "sigaction"); + clixon_err(OE_UNIX, errno, "sigaction"); return -1; } if (oldhandler) @@ -151,12 +155,12 @@ clixon_signal_save(sigset_t *sigset, int i; if (sigprocmask(0, NULL, sigset) < 0){ - clicon_err(OE_UNIX, errno, "sigprocmask"); + clixon_err(OE_UNIX, errno, "sigprocmask"); goto done; } for (i=1; i<32; i++){ if (sigaction(i, NULL, &sigaction_vec[i]) < 0){ - clicon_err(OE_UNIX, errno, "sigaction"); + clixon_err(OE_UNIX, errno, "sigaction"); goto done; } } @@ -179,14 +183,14 @@ clixon_signal_restore(sigset_t *sigset, int i; if (sigprocmask(SIG_SETMASK, sigset, NULL) < 0){ - clicon_err(OE_UNIX, errno, "sigprocmask"); + clixon_err(OE_UNIX, errno, "sigprocmask"); goto done; } for (i=1; i<32; i++){ if (i == SIGKILL || i == SIGSTOP) continue; if (sigaction(i, &sigaction_vec[i], NULL) < 0){ - clicon_err(OE_UNIX, errno, "sigaction"); + clixon_err(OE_UNIX, errno, "sigaction"); goto done; } } @@ -253,17 +257,17 @@ pidfile_zapold(pid_t pid) { int retval = -1; - clicon_log(LOG_NOTICE, "Killing old daemon with pid: %d", pid); + clixon_log(NULL, LOG_NOTICE, "Killing old daemon with pid: %d", pid); killpg(pid, SIGTERM); kill(pid, SIGTERM); /* Need to sleep process properly and then check again */ if (usleep(100000) < 0){ - clicon_err(OE_UNIX, errno, "usleep"); + clixon_err(OE_UNIX, errno, "usleep"); goto done; } if ((kill(pid, 0)) < 0){ if (errno != ESRCH){ - clicon_err(OE_DAEMON, errno, "Killing old daemon"); + clixon_err(OE_DAEMON, errno, "Killing old daemon"); goto done; } } @@ -287,13 +291,13 @@ pidfile_write(char *pidfile) /* Here, there should be no old agent and no pidfile */ if ((f = fopen(pidfile, "w")) == NULL){ if (errno == EACCES) - clicon_err(OE_DAEMON, errno, "Creating pid-file %s (Try run as root?)", pidfile); + clixon_err(OE_DAEMON, errno, "Creating pid-file %s (Try run as root?)", pidfile); else - clicon_err(OE_DAEMON, errno, "Creating pid-file %s", pidfile); + clixon_err(OE_DAEMON, errno, "Creating pid-file %s", pidfile); goto done; } if ((retval = fprintf(f, "%ld\n", (long) getpid())) < 1){ - clicon_err(OE_DAEMON, errno, "Could not write pid to %s", pidfile); + clixon_err(OE_DAEMON, errno, "Could not write pid to %s", pidfile); goto done; } clixon_debug(CLIXON_DBG_DEFAULT, "Opened pidfile %s with pid %d", pidfile, getpid()); diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c index 2ec84080..3c58afbf 100644 --- a/lib/src/clixon_stream.c +++ b/lib/src/clixon_stream.c @@ -46,7 +46,7 @@ * +---------------+ +-->| subscription | * / +---------------+ * +---------------+ * +---------------+ - * | clicon_handle |--------->| event_stream | + * | clixon_handle |--------->| event_stream | * +---------------+ +---------------+ * \ * +---------------+ * +-->| replay | @@ -69,13 +69,14 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_string.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_event.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -98,7 +99,7 @@ * @retval NULL Not found */ event_stream_t * -stream_find(clicon_handle h, +stream_find(clixon_handle h, const char *name) { event_stream_t *es0; @@ -125,7 +126,7 @@ stream_find(clicon_handle h, * @retval -1 Error */ int -stream_add(clicon_handle h, +stream_add(clixon_handle h, const char *name, const char *description, const int replay_enabled, @@ -137,16 +138,16 @@ stream_add(clicon_handle h, if ((es = stream_find(h, name)) != NULL) goto ok; if ((es = malloc(sizeof(event_stream_t))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(es, 0, sizeof(event_stream_t)); if ((es->es_name = strdup(name)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); goto done; } if ((es->es_description = strdup(description)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); goto done; } es->es_replay_enabled = replay_enabled; @@ -166,7 +167,7 @@ stream_add(clicon_handle h, * @retval 0 OK */ int -stream_delete_all(clicon_handle h, +stream_delete_all(clixon_handle h, int force) { struct stream_replay *r; @@ -203,7 +204,7 @@ stream_delete_all(clicon_handle h, * @retval -1 Error */ int -stream_get_xml(clicon_handle h, +stream_get_xml(clixon_handle h, int access, cbuf *cb) { @@ -250,7 +251,7 @@ stream_timer_setup(int fd, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; struct timeval now; struct timeval t; struct timeval t1 = {STREAM_TIMER_TIMEOUT_S, 0}; @@ -331,7 +332,7 @@ stream_timer_setup(int fd, * @retval -1 Error, ie no such stream */ struct stream_subscription * -stream_ss_add(clicon_handle h, +stream_ss_add(clixon_handle h, char *stream, char *xpath, struct timeval *starttime, @@ -344,16 +345,16 @@ stream_ss_add(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if ((es = stream_find(h, stream)) == NULL){ - clicon_err(OE_CFG, ENOENT, "Stream %s not found", stream); + clixon_err(OE_CFG, ENOENT, "Stream %s not found", stream); goto done; } if ((ss = malloc(sizeof(*ss))) == NULL){ - clicon_err(OE_CFG, errno, "malloc"); + clixon_err(OE_CFG, errno, "malloc"); goto done; } memset(ss, 0, sizeof(*ss)); if ((ss->ss_stream = strdup(stream)) == NULL){ - clicon_err(OE_CFG, errno, "strdup"); + clixon_err(OE_CFG, errno, "strdup"); goto done; } if (stoptime) @@ -361,7 +362,7 @@ stream_ss_add(clicon_handle h, if (starttime) ss->ss_starttime = *starttime; if (xpath && (ss->ss_xpath = strdup(xpath)) == NULL){ - clicon_err(OE_CFG, errno, "strdup"); + clixon_err(OE_CFG, errno, "strdup"); goto done; } ss->ss_fn = fn; @@ -384,7 +385,7 @@ stream_ss_add(clicon_handle h, * @retval -1 Error */ int -stream_ss_rm(clicon_handle h, +stream_ss_rm(clixon_handle h, event_stream_t *es, struct stream_subscription *ss, int force) @@ -438,7 +439,7 @@ stream_ss_find(event_stream_t *es, * @see stream_ss_delete For single stream */ int -stream_ss_delete_all(clicon_handle h, +stream_ss_delete_all(clixon_handle h, stream_fn_t fn, void *arg) { @@ -469,7 +470,7 @@ stream_ss_delete_all(clicon_handle h, * @see stream_ss_delete_all (merge with this?) */ int -stream_ss_delete(clicon_handle h, +stream_ss_delete(clixon_handle h, char *name, stream_fn_t fn, void *arg) @@ -500,12 +501,12 @@ stream_ss_delete(clicon_handle h, * @param[in] tv Timestamp. Dont notify if subscription has stoptimefaultEthernet0major") < 0) * err; @@ -554,7 +555,7 @@ stream_notify1(clicon_handle h, * @see stream_notify1 Internal */ int -stream_notify(clicon_handle h, +stream_notify(clixon_handle h, char *stream, const char *event, ...) { @@ -576,7 +577,7 @@ stream_notify(clicon_handle h, len = vsnprintf(NULL, 0, event, args) + 1; va_end(args); if ((str = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, len); @@ -584,16 +585,16 @@ stream_notify(clicon_handle h, len = vsnprintf(str, len, event, args) + 1; va_end(args); if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, 0, "No yang spec"); + clixon_err(OE_YANG, 0, "No yang spec"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } gettimeofday(&tv, NULL); if (time2str(&tv, timestr, sizeof(timestr)) < 0){ - clicon_err(OE_UNIX, errno, "time2str"); + clixon_err(OE_UNIX, errno, "time2str"); goto done; } /* From RFC5277 */ @@ -628,11 +629,11 @@ stream_notify(clicon_handle h, * @param[in] stream Name of event stream. CLICON is predefined as LOG stream * @param[in] xml Notification as XML stream. Is copied. * @retval 0 OK - * @retval -1 Error with clicon_err called + * @retval -1 Error * @see stream_notify Should be merged with this */ int -stream_notify_xml(clicon_handle h, +stream_notify_xml(clixon_handle h, char *stream, cxobj *xml) { @@ -650,16 +651,16 @@ stream_notify_xml(clicon_handle h, if ((es = stream_find(h, stream)) == NULL) goto ok; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, 0, "No yang spec"); + clixon_err(OE_YANG, 0, "No yang spec"); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } gettimeofday(&tv, NULL); if (time2str(&tv, timestr, sizeof(timestr)) < 0){ - clicon_err(OE_UNIX, errno, "time2str"); + clixon_err(OE_UNIX, errno, "time2str"); goto done; } cprintf(cb, "%sNULL", @@ -720,7 +721,7 @@ stream_notify_xml(clicon_handle h, * Assume no future sample timestamps. */ static int -stream_replay_notify(clicon_handle h, +stream_replay_notify(clixon_handle h, event_stream_t *es, struct stream_subscription *ss) { @@ -775,7 +776,7 @@ stream_replay_add(event_stream_t *es, struct stream_replay *new; if ((new = malloc(sizeof *new)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(new, 0, (sizeof *new)); @@ -791,7 +792,7 @@ stream_replay_add(event_stream_t *es, * stream and subscription */ struct replay_arg{ - clicon_handle ra_h; + clixon_handle ra_h; char *ra_stream; /* Name of stream - malloced: free by cb */ stream_fn_t ra_fn; /* Stream callback */ void *ra_arg; /* Argument - typically unique client handle */ @@ -844,7 +845,7 @@ stream_replay_cb(int fd, * @retval -1 Error */ int -stream_replay_trigger(clicon_handle h, +stream_replay_trigger(clixon_handle h, char *stream, stream_fn_t fn, void *arg) @@ -854,13 +855,13 @@ stream_replay_trigger(clicon_handle h, struct replay_arg *ra; if ((ra = malloc(sizeof(*ra))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(ra, 0, sizeof(*ra)); ra->ra_h = h; if ((ra->ra_stream = strdup(stream)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } ra->ra_fn = fn; @@ -987,7 +988,7 @@ url_post(char *url, * @see stream_ss_add */ static int -stream_publish_cb(clicon_handle h, +stream_publish_cb(clixon_handle h, int op, cxobj *event, void *arg) @@ -1004,17 +1005,17 @@ stream_publish_cb(clicon_handle h, goto ok; /* Create pub url */ if ((u = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if ((pub_prefix = clicon_option_str(h, "CLICON_STREAM_PUB")) == NULL){ - clicon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined"); + clixon_err(OE_CFG, ENOENT, "CLICON_STREAM_PUB not defined"); goto done; } cprintf(u, "%s/%s", pub_prefix, stream); /* Create XML data as string */ if ((d = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(d, event, 0, 0, NULL, -1, 0) < 0) @@ -1041,7 +1042,7 @@ stream_publish_cb(clicon_handle h, /*! Publish all streams on a pubsub channel, eg using SSE */ int -stream_publish(clicon_handle h, +stream_publish(clixon_handle h, char *stream) { #ifdef CLIXON_PUBLISH_STREAMS @@ -1053,9 +1054,9 @@ stream_publish(clicon_handle h, done: return retval; #else - clicon_log(LOG_WARNING, "%s called but CLIXON_PUBLISH_STREAMS not enabled (enable with configure --enable-publish)", __FUNCTION__); - clicon_log_init("xpath", LOG_WARNING, CLICON_LOG_STDERR); - return 0; + clixon_log(h, LOG_WARNING, "%s called but CLIXON_PUBLISH_STREAMS not enabled (enable with configure --enable-publish)", __FUNCTION__); + clixon_log_init(h, "xpath", LOG_WARNING, CLIXON_LOG_STDERR); + return 0; #endif } @@ -1066,7 +1067,7 @@ stream_publish_init() int retval = -1; if (curl_global_init(CURL_GLOBAL_ALL) != 0){ - clicon_err(OE_PLUGIN, errno, "curl_global_init"); + clixon_err(OE_PLUGIN, errno, "curl_global_init"); goto done; } retval = 0; diff --git a/lib/src/clixon_string.c b/lib/src/clixon_string.c index db28a874..a6fb5668 100644 --- a/lib/src/clixon_string.c +++ b/lib/src/clixon_string.c @@ -47,8 +47,10 @@ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_string.h" #include "clixon_err.h" @@ -103,7 +105,7 @@ clicon_strsep(char *string, /* alloc vector and append copy of string */ siz = (nvec+1)* sizeof(char*) + strlen(string)+1; if ((vec = (char**)malloc(siz)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(vec, 0, siz); @@ -167,7 +169,7 @@ clixon_string_del_join(char *str1, int len; if (str2 == NULL){ - clicon_err(OE_UNIX, EINVAL, "str2 is NULL"); + clixon_err(OE_UNIX, EINVAL, "str2 is NULL"); return NULL; } len = strlen(str2) + 1; @@ -175,7 +177,7 @@ clixon_string_del_join(char *str1, len += strlen(str1); len += strlen(del); if ((str = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return NULL; } snprintf(str, len, "%s%s%s", (str1 ? str1 : ""), del, str2); @@ -215,21 +217,21 @@ clixon_strsplit(char *string, if ((str = strchr(string, delim)) == NULL){ if (suffix && (*suffix = strdup(string)) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } } else { if (prefix){ if ((*prefix = strdup(string)) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } (*prefix)[str-string] = '\0'; } str++; if (suffix && (*suffix = strdup(str)) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } } @@ -297,7 +299,7 @@ uri_percent_encode(char **encp, fmtlen = vsnprintf(NULL, 0, fmt, args) + 1; va_end(args); if ((str = malloc(fmtlen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, fmtlen); @@ -310,7 +312,7 @@ uri_percent_encode(char **encp, /* This is max */ len = strlen(str)*3+1; if ((enc = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(enc, 0, len); @@ -355,13 +357,13 @@ uri_percent_decode(char *enc, char *ptr; if (enc == NULL){ - clicon_err(OE_UNIX, EINVAL, "enc is NULL"); + clixon_err(OE_UNIX, EINVAL, "enc is NULL"); goto done; } /* This is max */ len = strlen(enc)+1; if ((str = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, len); @@ -435,7 +437,7 @@ xml_chardata_encode(char **escp, fmtlen = vsnprintf(NULL, 0, fmt, args) + 1; va_end(args); if ((str = malloc(fmtlen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, fmtlen); @@ -477,7 +479,7 @@ xml_chardata_encode(char **escp, len++; /* trailing \0 */ /* We know length, allocate encoding buffer */ if ((esc = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(esc, 0, len); @@ -498,7 +500,7 @@ xml_chardata_encode(char **escp, switch (str[i]){ case '&': if ((l=snprintf(&esc[j], 6, "&")) < 0){ - clicon_err(OE_UNIX, errno, "snprintf"); + clixon_err(OE_UNIX, errno, "snprintf"); goto done; } j += l; @@ -510,14 +512,14 @@ xml_chardata_encode(char **escp, break; } if ((l=snprintf(&esc[j], 5, "<")) < 0){ - clicon_err(OE_UNIX, errno, "snprintf"); + clixon_err(OE_UNIX, errno, "snprintf"); goto done; } j += l; break; case '>': if ((l=snprintf(&esc[j], 5, ">")) < 0){ - clicon_err(OE_UNIX, errno, "snprintf"); + clixon_err(OE_UNIX, errno, "snprintf"); goto done; } j += l; @@ -632,7 +634,7 @@ xml_chardata_decode_ampersand(char *str, else if (len > 0 && *p == '#'){ p++; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "parse_uint32"); + clixon_err(OE_UNIX, errno, "parse_uint32"); goto done; } if (len > 1 && *p == 'x'){ @@ -641,7 +643,7 @@ xml_chardata_decode_ampersand(char *str, } cprintf(cb, "%s", p); if ((ret = parse_uint32(cbuf_get(cb), &code, NULL)) < 0){ - clicon_err(OE_UNIX, errno, "parse_uint32"); + clixon_err(OE_UNIX, errno, "parse_uint32"); goto done; } if (ret == 0){ @@ -692,7 +694,7 @@ xml_chardata_decode(char **decp, fmtlen = vsnprintf(NULL, 0, fmt, args) + 1; va_end(args); if ((str = malloc(fmtlen)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, fmtlen); @@ -705,7 +707,7 @@ xml_chardata_decode(char **decp, * First allocate decoded string, encoded is always >= larger */ slen = strlen(str); if ((dec = malloc(slen+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } j = 0; @@ -776,12 +778,12 @@ uri_str2cvec(char *string, cg_var *cv; if ((s0 = strdup(string)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto err; } s = s0; if ((cvv = cvec_new(0)) ==NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto err; } while (s != NULL) { @@ -802,11 +804,11 @@ uri_str2cvec(char *string, } else if ((valu = strdup(val)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto err; } if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); goto err; } while ((strlen(s) > 0) && isblank(*s)) @@ -818,7 +820,7 @@ uri_str2cvec(char *string, else{ if (strlen(s)){ if ((cv = cvec_add(cvv, CGV_EMPTY)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); goto err; } cv_name_set(cv, s); @@ -1069,7 +1071,7 @@ clixon_unicode2utf8_one(uint16_t uc16, int retval = -1; if (utflen < 5){ - clicon_err(OE_UNIX, EINVAL, "Length of utfstr is not >=4"); + clixon_err(OE_UNIX, EINVAL, "Length of utfstr is not >=4"); goto done; } if (uc16<0x80) @@ -1079,11 +1081,11 @@ clixon_unicode2utf8_one(uint16_t uc16, *utfstr++=128+uc16%64; } else if (uc16-0xd800u<0x800){ - clicon_err(OE_UNIX, EINVAL, "unicode2utf error"); + clixon_err(OE_UNIX, EINVAL, "unicode2utf error"); goto done; } else{ - clicon_err(OE_UNIX, EINVAL, "unicode2utf error"); + clixon_err(OE_UNIX, EINVAL, "unicode2utf error"); goto done; } *utfstr++=0; @@ -1112,11 +1114,11 @@ clixon_unicode2utf8(char *ucstr, uint16_t uc16 = 0; if (ucstr == NULL || utfstr == NULL){ - clicon_err(OE_UNIX, EINVAL, "input param is NULL"); + clixon_err(OE_UNIX, EINVAL, "input param is NULL"); goto done; } if ((len = strlen(ucstr)) != 4){ - clicon_err(OE_UNIX, EINVAL, "Length of ucstr is not 4"); + clixon_err(OE_UNIX, EINVAL, "Length of ucstr is not 4"); goto done; } for (i=0; i /* clixon */ -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_queue.h" #include "clixon_string.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_options.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -142,7 +143,7 @@ text2file(cxobj *xn, char *prefix = NULL; #endif if (xn == NULL || fn == NULL){ - clicon_err(OE_XML, EINVAL, "xn or fn is NULL"); + clixon_err(OE_XML, EINVAL, "xn or fn is NULL"); goto done; } if ((yn = xml_spec(xn)) != NULL){ @@ -168,7 +169,7 @@ text2file(cxobj *xn, #endif if (yang_keyword_get(yn) == Y_LIST){ if ((cvk = yang_cvec_get(yn)) == NULL){ - clicon_err(OE_YANG, 0, "No keys"); + clixon_err(OE_YANG, 0, "No keys"); goto done; } } @@ -190,7 +191,7 @@ text2file(cxobj *xn, switch (xml_type(xn)){ case CX_BODY:{ if ((cbb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } value = xml_value(xn); @@ -331,7 +332,7 @@ text2cbuf(cbuf *cb, char *prefix = NULL; if (xn == NULL || cb == NULL){ - clicon_err(OE_XML, EINVAL, "xn or cb is NULL"); + clixon_err(OE_XML, EINVAL, "xn or cb is NULL"); goto done; } level1 = level*PRETTYPRINT_INDENT; @@ -349,7 +350,7 @@ text2cbuf(cbuf *cb, #endif if (yang_keyword_get(yn) == Y_LIST){ if ((cvk = yang_cvec_get(yn)) == NULL){ - clicon_err(OE_YANG, 0, "No keys"); + clixon_err(OE_YANG, 0, "No keys"); goto done; } } @@ -373,7 +374,7 @@ text2cbuf(cbuf *cb, switch (xml_type(xn)){ case CX_BODY:{ if ((cbb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } value = xml_value(xn); @@ -800,7 +801,7 @@ text_populate_list(cxobj *xn) continue; xml_flag_reset(xb, XML_FLAG_BODYKEY); if ((cvi = cvec_next(cvk, cvi)) == NULL){ - clicon_err(OE_XML, 0, "text parser, key and body mismatch"); + clixon_err(OE_XML, 0, "text parser, key and body mismatch"); goto done; } namei = cv_string_get(cvi); @@ -836,7 +837,7 @@ text_populate_list(cxobj *xn) * @param[out] xerr Reason for invalid returned as netconf err msg * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) - * @retval -1 Error with clicon_err called + * @retval -1 Error * @see _xml_parse for XML variant * @note Parsing requires YANG, which means yb must be YB_MODULE/_NEXT */ @@ -857,7 +858,7 @@ _text_syntax_parse(char *str, clixon_debug(CLIXON_DBG_DEFAULT, "%s %d %s", __FUNCTION__, yb, str); if (yb != YB_MODULE && yb != YB_MODULE_NEXT){ - clicon_err(OE_YANG, EINVAL, "yb must be YB_MODULE or YB_MODULE_NEXT"); + clixon_err(OE_YANG, EINVAL, "yb must be YB_MODULE or YB_MODULE_NEXT"); return -1; } ts.ts_parse_string = str; @@ -867,9 +868,9 @@ _text_syntax_parse(char *str, if (clixon_text_syntax_parsel_init(&ts) < 0) goto done; if (clixon_text_syntax_parseparse(&ts) != 0) { /* yacc returns 1 on error */ - clicon_log(LOG_NOTICE, "TEXT SYNTAX error: line %d", ts.ts_linenum); - if (clicon_errno == 0) - clicon_err(OE_JSON, 0, "TEXT SYNTAX parser error with no error code (should not happen)"); + clixon_log(NULL, LOG_NOTICE, "TEXT SYNTAX error: line %d", ts.ts_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_JSON, 0, "TEXT SYNTAX parser error with no error code (should not happen)"); goto done; } @@ -931,7 +932,7 @@ _text_syntax_parse(char *str, * @param[out] xerr Reason for invalid returned as netconf err msg * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) w xerr set - * @retval -1 Error with clicon_err called + * @retval -1 Error * @code * cxobj *x = NULL; * if (clixon_text_syntax_parse_string(str, YB_MODULE, yspec, &x, &xerr) < 0) @@ -950,7 +951,7 @@ clixon_text_syntax_parse_string(char *str, { clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (xt==NULL){ - clicon_err(OE_XML, EINVAL, "xt is NULL"); + clixon_err(OE_XML, EINVAL, "xt is NULL"); return -1; } if (*xt == NULL){ @@ -974,7 +975,7 @@ clixon_text_syntax_parse_string(char *str, * @param[out] xerr Reason for invalid returned as netconf err msg * @retval 1 OK and valid * @retval 0 Invalid (only if yang spec) w xerr set - * @retval -1 Error with clicon_err called + * @retval -1 Error * * @code * cxobj *xt = NULL; @@ -1006,18 +1007,18 @@ clixon_text_syntax_parse_file(FILE *fp, int len = 0; if (xt == NULL){ - clicon_err(OE_XML, EINVAL, "xt is NULL"); + clixon_err(OE_XML, EINVAL, "xt is NULL"); return -1; } if ((textbuf = malloc(textbuflen)) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(textbuf, 0, textbuflen); ptr = textbuf; while (1){ if ((ret = fread(&ch, 1, 1, fp)) < 0){ - clicon_err(OE_XML, errno, "read"); + clixon_err(OE_XML, errno, "read"); break; } if (ret != 0) @@ -1038,7 +1039,7 @@ clixon_text_syntax_parse_file(FILE *fp, oldtextbuflen = textbuflen; textbuflen *= 2; if ((textbuf = realloc(textbuf, textbuflen)) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } memset(textbuf+oldtextbuflen, 0, textbuflen-oldtextbuflen); diff --git a/lib/src/clixon_text_syntax_parse.l b/lib/src/clixon_text_syntax_parse.l index f6388ac5..eaf64c34 100644 --- a/lib/src/clixon_text_syntax_parse.l +++ b/lib/src/clixon_text_syntax_parse.l @@ -47,7 +47,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" diff --git a/lib/src/clixon_text_syntax_parse.y b/lib/src/clixon_text_syntax_parse.y index f9297c5e..f0e9e70a 100644 --- a/lib/src/clixon_text_syntax_parse.y +++ b/lib/src/clixon_text_syntax_parse.y @@ -69,13 +69,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" -#include "clixon_string.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_string.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_nsctx.h" @@ -96,7 +97,7 @@ clixon_text_syntax_parseerror(void *arg, { clixon_text_syntax_yacc *ts = (clixon_text_syntax_yacc *)arg; - clicon_err(OE_XML, XMLPARSE_ERRNO, "text_syntax_parse: line %d: %s: at or before: %s", + clixon_err(OE_XML, XMLPARSE_ERRNO, "text_syntax_parse: line %d: %s: at or before: %s", ts->ts_linenum, s, clixon_text_syntax_parsetext); @@ -140,7 +141,7 @@ text_create_node(clixon_text_syntax_yacc *ts, /* Silently ignore if module name not found */ if ((ymod = yang_find(ts->ts_yspec, Y_MODULE, prefix)) != NULL){ if ((ns = yang_find_mynamespace(ymod)) == NULL){ - clicon_err(OE_YANG, 0, "No namespace"); + clixon_err(OE_YANG, 0, "No namespace"); goto done; } /* Set default namespace */ @@ -166,7 +167,7 @@ strjoin(char *str0, len0 = str0?strlen(str0):0; len = len0 + strlen(str1) + 1; if ((str0 = realloc(str0, len)) == NULL){ - clicon_err(OE_YANG, errno, "realloc"); + clixon_err(OE_YANG, errno, "realloc"); return NULL; } strcpy(str0+len0, str1); diff --git a/lib/src/clixon_uid.c b/lib/src/clixon_uid.c index 0553d61d..27b5835a 100644 --- a/lib/src/clixon_uid.c +++ b/lib/src/clixon_uid.c @@ -59,8 +59,12 @@ #include /* clixon */ +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_uid.h" /*! Translate group name to gid. Return -1 if error or not found. @@ -83,11 +87,11 @@ group_name2gid(const char *name, gr = &g0; /* This leaks memory in ubuntu */ if (getgrnam_r(name, gr, buf, sizeof(buf), >mp) < 0){ - clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name); + clixon_err(OE_UNIX, errno, "getgrnam_r(%s)", name); goto done; } if (gtmp == NULL){ - clicon_err(OE_UNIX, 0, "No such group: %s", name); + clixon_err(OE_UNIX, 0, "No such group: %s", name); goto done; } if (gid) @@ -114,11 +118,11 @@ name2uid(const char *name, struct passwd *pwbufp = NULL; if (getpwnam_r(name, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){ - clicon_err(OE_UNIX, errno, "getpwnam_r(%s)", name); + clixon_err(OE_UNIX, errno, "getpwnam_r(%s)", name); goto done; } if (pwbufp == NULL){ - clicon_err(OE_UNIX, 0, "No such user: %s", name); + clixon_err(OE_UNIX, 0, "No such user: %s", name); goto done; } if (uid) @@ -145,17 +149,17 @@ uid2name(const uid_t uid, struct passwd *pwbufp = NULL; if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){ - clicon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid); + clixon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid); goto done; } if (pwbufp == NULL){ - clicon_err(OE_UNIX, ENOENT, "No such user: %u", uid); + clixon_err(OE_UNIX, ENOENT, "No such user: %u", uid); goto done; } if (name){ if ((*name = strdup(pwbufp->pw_name)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -182,11 +186,11 @@ drop_priv_temp(uid_t new_uid) clixon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid); /* XXX: implicit declaration of function 'setresuid' on travis */ if (setresuid(-1, new_uid, geteuid()) < 0){ - clicon_err(OE_UNIX, errno, "setresuid"); + clixon_err(OE_UNIX, errno, "setresuid"); goto done; } if (geteuid() != new_uid){ - clicon_err(OE_UNIX, errno, "geteuid"); + clixon_err(OE_UNIX, errno, "geteuid"); goto done; } retval = 0; @@ -216,17 +220,17 @@ drop_priv_perm(uid_t new_uid) clixon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid); if (setresuid(new_uid, new_uid, new_uid) < 0){ - clicon_err(OE_UNIX, errno, "setresuid"); + clixon_err(OE_UNIX, errno, "setresuid"); goto done; } if (getresuid(&ruid, &euid, &suid) < 0){ - clicon_err(OE_UNIX, errno, "getresuid"); + clixon_err(OE_UNIX, errno, "getresuid"); goto done; } if (ruid != new_uid || euid != new_uid || suid != new_uid){ - clicon_err(OE_UNIX, EINVAL, "Non-matching uid"); + clixon_err(OE_UNIX, EINVAL, "Non-matching uid"); goto done; } retval = 0; @@ -251,15 +255,15 @@ restore_priv(void) clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); if (getresuid(&ruid, &euid, &suid) < 0){ - clicon_err(OE_UNIX, errno, "setresuid"); + clixon_err(OE_UNIX, errno, "setresuid"); goto done; } if (setresuid(-1, suid, -1) < 0){ - clicon_err(OE_UNIX, errno, "setresuid"); + clixon_err(OE_UNIX, errno, "setresuid"); goto done; } if (geteuid() != suid){ - clicon_err(OE_UNIX, EINVAL, "Non-matching uid"); + clixon_err(OE_UNIX, EINVAL, "Non-matching uid"); goto done; } retval = 0; diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index 174d5ac7..9bbaee83 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -55,8 +55,7 @@ /* cligen */ #include -/* clicon */ - +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" @@ -64,6 +63,7 @@ #include "clixon_string.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_data.h" @@ -147,7 +147,7 @@ validate_leafref(cxobj *xt, goto ok; if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "Leafref requires path statement"); @@ -158,7 +158,7 @@ validate_leafref(cxobj *xt, goto fail; } if ((path_arg = yang_argument_get(ypath)) == NULL){ - clicon_err(OE_YANG, 0, "No argument for Y_PATH"); + clixon_err(OE_YANG, 0, "No argument for Y_PATH"); goto done; } if ((leafrefbody = xml_body(xt)) == NULL) @@ -176,7 +176,7 @@ validate_leafref(cxobj *xt, } if (i==xlen){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } ymod = ys_module(ys); @@ -246,11 +246,11 @@ validate_identityref(cxobj *xt, yang_stmt *ymod; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Get idref value. Then see if this value is derived from ytype. @@ -368,7 +368,7 @@ validate_identityref(cxobj *xt, * @note Should need a variant accepting cxobj **xret */ int -xml_yang_validate_rpc(clicon_handle h, +xml_yang_validate_rpc(clixon_handle h, cxobj *xrpc, int expanddefault, cxobj **xret) @@ -380,7 +380,7 @@ xml_yang_validate_rpc(clicon_handle h, int ret; if (strcmp(xml_name(xrpc), "rpc")){ - clicon_err(OE_XML, EINVAL, "Expected RPC"); + clixon_err(OE_XML, EINVAL, "Expected RPC"); goto done; } rpcprefix = xml_prefix(xrpc); @@ -423,7 +423,7 @@ xml_yang_validate_rpc(clicon_handle h, } int -xml_yang_validate_rpc_reply(clicon_handle h, +xml_yang_validate_rpc_reply(clixon_handle h, cxobj *xrpc, cxobj **xret) { @@ -435,7 +435,7 @@ xml_yang_validate_rpc_reply(clicon_handle h, int ret; if (strcmp(xml_name(xrpc), "rpc-reply")){ - clicon_err(OE_XML, EINVAL, "Expected RPC"); + clixon_err(OE_XML, EINVAL, "Expected RPC"); goto done; } rpcprefix = xml_prefix(xrpc); @@ -661,7 +661,7 @@ check_list_key(cxobj *xt, char *keyname; if (yt == NULL || !yang_config(yt) || yang_keyword_get(yt) != Y_LIST){ - clicon_err(OE_YANG, EINVAL, "yt is not a config true list node"); + clixon_err(OE_YANG, EINVAL, "yt is not a config true list node"); goto done; } yc = NULL; @@ -680,7 +680,7 @@ check_list_key(cxobj *xt, enum rfc_6020 keyw; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } ymod = ys_module(yt); @@ -731,7 +731,7 @@ choice_mandatory_check(cxobj *xt, fail++; if (xret){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Mandatory variable %s in module %s", @@ -901,7 +901,7 @@ check_mandatory(cxobj *xt, int ret; if (yt == NULL || !yang_config(yt)){ - clicon_err(OE_YANG, EINVAL, "yt is not config true"); + clixon_err(OE_YANG, EINVAL, "yt is not config true"); goto done; } if (yang_keyword_get(yt) == Y_LIST){ @@ -957,7 +957,7 @@ check_mandatory(cxobj *xt, } if (x == NULL){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Mandatory variable of %s in module %s", xml_name(xt), yang_argument_get(ys_module(yc))); @@ -1002,7 +1002,7 @@ check_mandatory(cxobj *xt, * @note Should need a variant accepting cxobj **xret */ int -xml_yang_validate_add(clicon_handle h, +xml_yang_validate_add(clixon_handle h, cxobj *xt, cxobj **xret) { @@ -1040,7 +1040,7 @@ xml_yang_validate_add(clicon_handle h, if ((cv0 = yang_cv_get(yt)) == NULL) break; if ((cv = cv_dup(cv0)) == NULL){ - clicon_err(OE_UNIX, errno, "cv_dup"); + clixon_err(OE_UNIX, errno, "cv_dup"); goto done; } /* In the union and leafref case, value is parsed as generic REST type, @@ -1138,7 +1138,7 @@ xml_yang_validate_list_key_only(cxobj *xt, } static int -xml_yang_validate_leaf_union(clicon_handle h, +xml_yang_validate_leaf_union(clixon_handle h, cxobj *xt, yang_stmt *yt, yang_stmt *yrestype, @@ -1219,7 +1219,7 @@ xml_yang_validate_leaf_union(clicon_handle h, * @see xml_yang_validate_rpc */ int -xml_yang_validate_all(clicon_handle h, +xml_yang_validate_all(clixon_handle h, cxobj *xt, cxobj **xret) { @@ -1249,13 +1249,13 @@ xml_yang_validate_all(clicon_handle h, and !Node has a config sub-statement and it is false */ if ((yt = xml_spec(xt)) == NULL){ if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1) { - clicon_log(LOG_WARNING, + clixon_log(h, LOG_WARNING, "%s: %d: No YANG spec for %s, validation skipped", __FUNCTION__, __LINE__, xml_name(xt)); goto ok; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Failed to find YANG spec of XML node: %s", xml_name(xt)); @@ -1274,7 +1274,7 @@ xml_yang_validate_all(clicon_handle h, goto done; if (hit && nr == 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Failed WHEN condition of %s in module %s (WHEN xpath is %s)", @@ -1345,7 +1345,7 @@ xml_yang_validate_all(clicon_handle h, if (!nr){ ye = yang_find(yc, Y_ERROR_MESSAGE, NULL); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Failed MUST xpath '%s' of '%s' in module %s", @@ -1398,7 +1398,7 @@ xml_yang_validate_all(clicon_handle h, * @retval -1 Error */ int -xml_yang_validate_all_top(clicon_handle h, +xml_yang_validate_all_top(clixon_handle h, cxobj *xt, cxobj **xret) { @@ -1424,7 +1424,7 @@ xml_yang_validate_all_top(clicon_handle h, * @note Parses cbret which seems one time too many */ int -rpc_reply_check(clicon_handle h, +rpc_reply_check(clixon_handle h, char *rpcname, cbuf *cbret) { @@ -1435,7 +1435,7 @@ rpc_reply_check(clicon_handle h, yang_stmt *yspec; if ((yspec = clicon_dbspec_yang(h)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No yang spec9"); + clixon_err(OE_YANG, ENOENT, "No yang spec9"); goto done; } /* Validate outgoing RPC */ diff --git a/lib/src/clixon_validate_minmax.c b/lib/src/clixon_validate_minmax.c index 1ea26911..a158dbd9 100644 --- a/lib/src/clixon_validate_minmax.c +++ b/lib/src/clixon_validate_minmax.c @@ -55,8 +55,7 @@ /* cligen */ #include -/* clicon */ - +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" @@ -64,6 +63,7 @@ #include "clixon_string.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_data.h" @@ -124,7 +124,7 @@ unique_search_xpath(cxobj *x, } (*slen) ++; if (((*svec) = realloc((*svec), (*slen)*sizeof(char*))) == NULL){ - clicon_err(OE_UNIX, errno, "realloc"); + clixon_err(OE_UNIX, errno, "realloc"); goto done; } (*svec)[(*slen)-1] = bi; @@ -242,7 +242,7 @@ check_unique_list_direct(cxobj *x, goto ok; } if ((vec = calloc(clen*xml_child_nr(xt), sizeof(char*))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } /* A vector is built with key-values, for each iteration check "backward" in the vector @@ -258,7 +258,7 @@ check_unique_list_direct(cxobj *x, * referenced leafs are not taken into account */ str = cv_string_get(cvi); if (index(str, '/') != NULL){ - clicon_err(OE_YANG, 0, "Multiple descendant nodes not allowed (w /)"); + clixon_err(OE_YANG, 0, "Multiple descendant nodes not allowed (w /)"); goto done; } if ((xi = xml_find(x, str)) == NULL) @@ -340,7 +340,7 @@ check_unique_list(cxobj *x, } cvi = cvec_i(cvk, 0); if (cvi == NULL || (xpath0 = cv_string_get(cvi)) == NULL){ - clicon_err(OE_YANG, 0, "No descendant schemanode"); + clixon_err(OE_YANG, 0, "No descendant schemanode"); goto done; } /* Check if direct schmeanode-id , ie not xpath */ diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index d5e696bd..25b6f5d2 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -58,12 +58,13 @@ #include /* clixon */ -#include "clixon_err.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_options.h" /* xml_bind_yang */ @@ -317,7 +318,7 @@ xml_stats(cxobj *xt, cxobj *xc; if (xt == NULL){ - clicon_err(OE_XML, EINVAL, "xml node is NULL"); + clixon_err(OE_XML, EINVAL, "xml node is NULL"); goto done; } *nrp += 1; @@ -370,7 +371,7 @@ xml_name_set(cxobj *xn, } if (name){ if ((xn->x_name = strdup(name)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); return -1; } } @@ -405,7 +406,7 @@ xml_prefix_set(cxobj *xn, } if (prefix){ if ((xn->x_prefix = strdup(prefix)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); return -1; } } @@ -657,7 +658,7 @@ xml_creator_add(cxobj *xn, goto ok; if (xn->x_creators == NULL){ if ((xn->x_creators = cvec_new(0)) == NULL){ - clicon_err(OE_XML, errno, "cvec_new"); + clixon_err(OE_XML, errno, "cvec_new"); goto done; } } @@ -750,7 +751,7 @@ xml_creator_copy_one(cxobj *x0, if (x0->x_creators) if ((x1->x_creators = cvec_dup(x0->x_creators)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } retval = 0; @@ -884,13 +885,13 @@ xml_value_set(cxobj *xn, if (!is_bodyattr(xn)) return 0; if (val == NULL){ - clicon_err(OE_XML, EINVAL, "value is NULL"); + clixon_err(OE_XML, EINVAL, "value is NULL"); goto done; } sz = strlen(val)+1; if (xn->x_value_cb == NULL){ if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } } @@ -919,18 +920,18 @@ xml_value_append(cxobj *xn, if (!is_bodyattr(xn)) return 0; if (val == NULL){ - clicon_err(OE_XML, EINVAL, "value is NULL"); + clixon_err(OE_XML, EINVAL, "value is NULL"); goto done; } sz = strlen(val)+1; if (xn->x_value_cb == NULL){ if ((xn->x_value_cb = cbuf_new_alloc(sz)) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } } if (cbuf_append_str(xn->x_value_cb, val) < 0){ - clicon_err(OE_XML, errno, "cprintf"); + clixon_err(OE_XML, errno, "cprintf"); goto done; } retval = 0; @@ -1251,7 +1252,7 @@ xml_child_append(cxobj *xp, xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD; xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*)); if (xp->x_childvec == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); return -1; } } @@ -1281,7 +1282,7 @@ xml_child_insert_pos(cxobj *xp, xp->x_childvec_max += XML_CHILDVEC_SIZE_THRESHOLD; xp->x_childvec = realloc(xp->x_childvec, xp->x_childvec_max*sizeof(cxobj*)); if (xp->x_childvec == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); return -1; } } @@ -1310,7 +1311,7 @@ xml_childvec_set(cxobj *x, if (x->x_childvec) free(x->x_childvec); if ((x->x_childvec = calloc(len, sizeof(cxobj*))) == NULL){ - clicon_err(OE_XML, errno, "calloc"); + clixon_err(OE_XML, errno, "calloc"); return -1; } return 0; @@ -1358,7 +1359,7 @@ clixon_child_xvec_append(cxobj *xn, * @param[in] xp The parent where the new xml node will be appended * @param[in] type XML type * @retval xml Created xml object if successful. Free with xml_free() - * @retval NULL Error and clicon_err() called + * @retval NULL Error and clixon_err() called * @code * cxobj *x; * if ((x = xml_new(name, xparent, CX_ELMNT)) == NULL) @@ -1386,12 +1387,12 @@ xml_new(char *name, sz = sizeof(struct xmlbody); break; default: - clicon_err(OE_XML, EINVAL, "Invalid type: %d", type); + clixon_err(OE_XML, EINVAL, "Invalid type: %d", type); return NULL; break; } if ((x = malloc(sz)) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); return NULL; } memset(x, 0, sz); @@ -1712,7 +1713,7 @@ xml_child_rm(cxobj *xp, if (!is_element(xp)) return 0; if ((xc = xml_child_i(xp, i)) == NULL){ - clicon_err(OE_XML, 0, "Child not found"); + clixon_err(OE_XML, 0, "Child not found"); goto done; } xml_parent_set(xc, NULL); @@ -1833,11 +1834,11 @@ xml_rootchild(cxobj *xp, if (!is_element(xp)) return 0; if (xml_parent(xp) != NULL){ - clicon_err(OE_XML, 0, "Parent is not root"); + clixon_err(OE_XML, 0, "Parent is not root"); goto done; } if ((xc = xml_child_i(xp, i)) == NULL){ - clicon_err(OE_XML, ENOENT, "Child %d of parent %s not found", i, xml_name(xp)); + clixon_err(OE_XML, ENOENT, "Child %d of parent %s not found", i, xml_name(xp)); goto done; } if (xml_child_rm(xp, i) < 0) @@ -1873,7 +1874,7 @@ xml_rootchild_node(cxobj *xp, if (!is_element(xp)) return 0; if (xml_parent(xp) != NULL){ - clicon_err(OE_XML, 0, "Parent is not root"); + clixon_err(OE_XML, 0, "Parent is not root"); goto done; } x = NULL; i = 0; @@ -2213,7 +2214,7 @@ xml_copy_one(cxobj *x0, char *s; if (x0 == NULL || x1 == NULL){ - clicon_err(OE_XML, EINVAL, "x0 or x1 is NULL"); + clixon_err(OE_XML, EINVAL, "x0 or x1 is NULL"); goto done; } xml_type_set(x1, xml_type(x0)); @@ -2333,7 +2334,7 @@ cxvec_append(cxobj *x, int retval = -1; if ((*vec = realloc(*vec, sizeof(cxobj *) * (*len+1))) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } (*vec)[(*len)++] = x; @@ -2370,7 +2371,7 @@ cxvec_prepend(cxobj *x, int retval = -1; if ((*vec = realloc(*vec, sizeof(cxobj *) * (*len+1))) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } memmove(&(*vec)[1], &(*vec)[0], sizeof(cxobj *) * (*len)); @@ -2587,7 +2588,7 @@ xml_operation(char *opstr, else if (strcmp("none", opstr) == 0) *op = OP_NONE; else{ - clicon_err(OE_XML, 0, "Bad-attribute operation: %s", opstr); + clixon_err(OE_XML, 0, "Bad-attribute operation: %s", opstr); return -1; } return 0; @@ -2648,7 +2649,7 @@ xml_attr_insert2val(char *instr, else if (strcmp("after", instr) == 0) *ins = INS_AFTER; else{ - clicon_err(OE_XML, 0, "Bad-attribute operation: %s", instr); + clixon_err(OE_XML, 0, "Bad-attribute operation: %s", instr); return -1; } return 0; @@ -2698,8 +2699,9 @@ xml_add_attr(cxobj *xn, goto ret; } -/*! Specialization of clicon_log with xml tree +/*! Specialization of clixon_log with xml tree * + * @param[in] h Clixon handle * @param[in] dbglevel * @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. * @param[in] x XML tree that is logged without prettyprint @@ -2709,9 +2711,10 @@ xml_add_attr(cxobj *xn, * @see clixon_debug_xml which uses debug setting instead of direct syslog */ int -clicon_log_xml(int level, - cxobj *x, - const char *format, ...) +clixon_log_xml(clixon_handle h, + int level, + cxobj *x, + const char *format, ...) { int retval = -1; va_list args; @@ -2722,7 +2725,7 @@ clicon_log_xml(int level, /* Print xml as cbuf */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(cb, x, 0, 0, NULL, -1, 0) < 0) @@ -2732,12 +2735,12 @@ clicon_log_xml(int level, len = vsnprintf(NULL, 0, format, args); va_end(args); /* Truncate long debug strings */ - if ((trunc = clicon_log_string_limit_get()) && trunc < len) + if ((trunc = clixon_log_string_limit_get()) && trunc < len) len = trunc; /* allocate a message string exactly fitting the message length */ if ((msg = malloc(len+1)) == NULL){ - fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } @@ -2745,13 +2748,13 @@ clicon_log_xml(int level, va_start(args, format); if (vsnprintf(msg, len+1, format, args) < 0){ va_end(args); - fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } va_end(args); /* Actually log it */ - clicon_log(level, "%s: %s", msg, cbuf_get(cb)); + clixon_log(h, level, "%s: %s", msg, cbuf_get(cb)); retval = 0; done: @@ -2789,7 +2792,7 @@ clixon_debug_xml(int dbglevel, return 0; /* Print xml as cbuf */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (clixon_xml2cbuf(cb, x, 0, 0, NULL, -1, 0) < 0) @@ -2799,12 +2802,12 @@ clixon_debug_xml(int dbglevel, len = vsnprintf(NULL, 0, format, args); va_end(args); /* Truncate long debug strings */ - if ((trunc = clicon_log_string_limit_get()) && trunc < len) + if ((trunc = clixon_log_string_limit_get()) && trunc < len) len = trunc; /* allocate a message string exactly fitting the message length */ if ((msg = malloc(len+1)) == NULL){ - fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "malloc: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } @@ -2812,7 +2815,7 @@ clixon_debug_xml(int dbglevel, va_start(args, format); if (vsnprintf(msg, len+1, format, args) < 0){ va_end(args); - fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */ + fprintf(stderr, "vsnprintf: %s\n", strerror(errno)); /* dont use clixon_err here due to recursion */ goto done; } va_end(args); @@ -2899,12 +2902,12 @@ xml_search_index_add(cxobj *x, struct search_index *si = NULL; if ((si = malloc(sizeof(struct search_index))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(si, 0, sizeof(struct search_index)); if ((si->si_name = strdup(name)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); free(si); si = NULL; goto done; diff --git a/lib/src/clixon_xml_bind.c b/lib/src/clixon_xml_bind.c index 0c8b97f3..5ab094f6 100644 --- a/lib/src/clixon_xml_bind.c +++ b/lib/src/clixon_xml_bind.c @@ -56,12 +56,14 @@ /* cligen */ #include -/* clicon */ - +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_err.h" #include "clixon_string.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -73,8 +75,6 @@ #include "clixon_xml_nsctx.h" #include "clixon_xpath_ctx.h" #include "clixon_xpath.h" -#include "clixon_log.h" -#include "clixon_err.h" #include "clixon_netconf_lib.h" #include "clixon_plugin.h" #include "clixon_xml_sort.h" @@ -140,6 +140,7 @@ strip_body_objects(cxobj *xt) /*! Associate XML node x with x:s parents yang:s matching child * + * @param[in] h Clixon handle * @param[in] xt XML tree node * @param[in] xsibling * @param[in] yspec Top-level YANG spec / mount-point @@ -152,10 +153,11 @@ strip_body_objects(cxobj *xt) * @see populate_self_top */ static int -populate_self_parent(cxobj *xt, - cxobj *xsibling, - yang_stmt *yspec, - cxobj **xerr) +populate_self_parent(clixon_handle h, + cxobj *xt, + cxobj *xsibling, + yang_stmt *yspec, + cxobj **xerr) { int retval = -1; yang_stmt *y = NULL; /* yang node */ @@ -200,13 +202,13 @@ populate_self_parent(cxobj *xt, goto done; xml_spec_set(xt, y); retval = 2; /* treat as anydata */ - clicon_log(LOG_WARNING, + clixon_log(h, LOG_WARNING, "%s: %d: No YANG spec for %s, anydata used", __FUNCTION__, __LINE__, name); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Failed to find YANG spec of XML node: %s", name); @@ -228,7 +230,7 @@ populate_self_parent(cxobj *xt, /* Assign spec only if namespaces match */ if (strcmp(ns, nsy) != 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Namespace mismatch: %s in XML does not match %s in yang", ns, nsy); @@ -255,6 +257,7 @@ populate_self_parent(cxobj *xt, /*! Associate XML node x with yang spec y by going through all top-level modules and finding match * + * @param[in] h Clixon handle * @param[in] xt XML tree node * @param[in] yspec Yang spec * @param[out] xerr Reason for failure, or NULL @@ -264,9 +267,10 @@ populate_self_parent(cxobj *xt, * @see populate_self_parent */ static int -populate_self_top(cxobj *xt, - yang_stmt *yspec, - cxobj **xerr) +populate_self_top(clixon_handle h, + cxobj *xt, + yang_stmt *yspec, + cxobj **xerr) { int retval = -1; yang_stmt *y = NULL; /* yang node */ @@ -292,7 +296,7 @@ populate_self_top(cxobj *xt, if (ymod == NULL){ if (xerr){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Failed to find YANG spec of XML node: %s", name); @@ -313,13 +317,13 @@ populate_self_top(cxobj *xt, goto done; xml_spec_set(xt, y); retval = 2; /* treat as anydata */ - clicon_log(LOG_WARNING, + clixon_log(h, LOG_WARNING, "%s: %d: No YANG spec for %s, anydata used", __FUNCTION__, __LINE__, name); goto done; } if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Failed to find YANG spec of XML node: %s", name); @@ -380,7 +384,7 @@ populate_self_top(cxobj *xt, * @note For subs to anyxml nodes will not have spec set */ int -xml_bind_yang(clicon_handle h, +xml_bind_yang(clixon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, @@ -419,7 +423,7 @@ xml_bind_yang(clicon_handle h, * @retval -1 Error */ static int -xml_bind_yang0_opt(clicon_handle h, +xml_bind_yang0_opt(clixon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, @@ -441,15 +445,15 @@ xml_bind_yang0_opt(clicon_handle h, switch (yb){ case YB_MODULE: - if ((ret = populate_self_top(xt, yspec, xerr)) < 0) + if ((ret = populate_self_top(h, xt, yspec, xerr)) < 0) goto done; break; case YB_PARENT: - if ((ret = populate_self_parent(xt, xsibling, yspec, xerr)) < 0) + if ((ret = populate_self_parent(h, xt, xsibling, yspec, xerr)) < 0) goto done; break; default: - clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb); + clixon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb); goto done; break; } @@ -538,7 +542,7 @@ xml_bind_yang0_opt(clicon_handle h, * @see xml_bind_yang If only children of xt should be populated, not xt itself */ int -xml_bind_yang0(clicon_handle h, +xml_bind_yang0(clixon_handle h, cxobj *xt, yang_bind yb, yang_stmt *yspec, @@ -550,18 +554,18 @@ xml_bind_yang0(clicon_handle h, switch (yb){ case YB_MODULE: - if ((ret = populate_self_top(xt, yspec, xerr)) < 0) + if ((ret = populate_self_top(h, xt, yspec, xerr)) < 0) goto done; break; case YB_PARENT: - if ((ret = populate_self_parent(xt, NULL, yspec, xerr)) < 0) + if ((ret = populate_self_parent(h, xt, NULL, yspec, xerr)) < 0) goto done; break; case YB_NONE: ret = 1; break; default: - clicon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb); + clixon_err(OE_XML, EINVAL, "Invalid yang binding: %d", yb); goto done; break; } @@ -597,7 +601,7 @@ xml_bind_yang0(clicon_handle h, * @retval -1 Error */ static int -xml_bind_yang_rpc_rpc(clicon_handle h, +xml_bind_yang_rpc_rpc(clixon_handle h, cxobj *x, yang_stmt *yrpc, char *rpcname, @@ -617,7 +621,7 @@ xml_bind_yang_rpc_rpc(clicon_handle h, xc = xml_child_i_type(x, 0, CX_ELMNT); /* Pick first */ name = xml_name(xc); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "Unrecognized parameter: %s in rpc: %s", name, rpcname); @@ -662,7 +666,7 @@ xml_bind_yang_rpc_rpc(clicon_handle h, * XXX if not more action, consider folding into calling function */ static int -xml_bind_yang_rpc_action(clicon_handle h, +xml_bind_yang_rpc_action(clixon_handle h, cxobj *xn, yang_stmt *yspec, cxobj **xerr) @@ -708,7 +712,7 @@ xml_bind_yang_rpc_action(clicon_handle h, * @see xml_bind_yang_rpc_reply */ int -xml_bind_yang_rpc(clicon_handle h, +xml_bind_yang_rpc(clixon_handle h, cxobj *xrpc, yang_stmt *yspec, cxobj **xerr) @@ -752,7 +756,7 @@ xml_bind_yang_rpc(clicon_handle h, if (xerr && netconf_unknown_element_xml(xerr, "protocol", name, "Unrecognized hello element") < 0) goto done; - clicon_err(OE_XML, EFAULT, "Unrecognized hello element: %s", name); + clixon_err(OE_XML, EFAULT, "Unrecognized hello element: %s", name); goto fail; } } @@ -838,7 +842,7 @@ xml_bind_yang_rpc(clicon_handle h, * @see xml_bind_yang For other generic cases */ int -xml_bind_yang_rpc_reply(clicon_handle h, +xml_bind_yang_rpc_reply(clixon_handle h, cxobj *xrpc, char *name, yang_stmt *yspec, @@ -858,7 +862,7 @@ xml_bind_yang_rpc_reply(clicon_handle h, opname = xml_name(xrpc); if (strcmp(opname, "rpc-reply")){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "Internal error, unrecognized netconf operation in backend reply, expected rpc-reply but received: %s", opname); @@ -896,7 +900,7 @@ xml_bind_yang_rpc_reply(clicon_handle h, goto done; if (ret == 0){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "Internal error in backend reply: "); diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index e0da821f..d6c61301 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -60,10 +60,11 @@ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_string.h" -#include "clixon_err.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_yang.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_xml.h" #include "clixon_options.h" #include "clixon_data.h" @@ -79,7 +80,7 @@ #include "clixon_xpath.h" static int -changelog_rename(clicon_handle h, +changelog_rename(clixon_handle h, cxobj *xt, cxobj *xw, cvec *nsc, @@ -90,7 +91,7 @@ changelog_rename(clicon_handle h, char *str = NULL; if (tag == NULL){ - clicon_err(OE_XML, 0, "tag required"); + clixon_err(OE_XML, 0, "tag required"); goto done; } if (xpath_vec_ctx(xw, nsc, tag, 0, &xctx) < 0) @@ -98,7 +99,7 @@ changelog_rename(clicon_handle h, if (ctx2string(xctx, &str) < 0) goto done; if (!strlen(str)){ - clicon_err(OE_XML, 0, "invalid rename tag: \"%s\"", str); + clixon_err(OE_XML, 0, "invalid rename tag: \"%s\"", str); goto done; } if (xml_name_set(xw, str) < 0) @@ -118,7 +119,7 @@ changelog_rename(clicon_handle h, /* replace target XML */ static int -changelog_replace(clicon_handle h, +changelog_replace(clixon_handle h, cxobj *xt, cxobj *xw, cxobj *xnew) @@ -129,7 +130,7 @@ changelog_replace(clicon_handle h, /* create a new node by parsing fttransform string and insert it at target */ if (xnew == NULL){ - clicon_err(OE_XML, 0, "new required"); + clixon_err(OE_XML, 0, "new required"); goto done; } /* replace: remove all children of target */ @@ -138,7 +139,7 @@ changelog_replace(clicon_handle h, goto done; /* replace: first single node under */ if (xml_child_nr(xnew) != 1){ - clicon_err(OE_XML, 0, "Single child to required"); + clixon_err(OE_XML, 0, "Single child to required"); goto done; } x = xml_child_i(xnew, 0); @@ -153,7 +154,7 @@ changelog_replace(clicon_handle h, /* create a new node by parsing "new" and insert it at target */ static int -changelog_insert(clicon_handle h, +changelog_insert(clixon_handle h, cxobj *xt, cxobj *xw, cxobj *xnew) @@ -162,7 +163,7 @@ changelog_insert(clicon_handle h, cxobj *x; if (xnew == NULL){ - clicon_err(OE_XML, 0, "new required"); + clixon_err(OE_XML, 0, "new required"); goto done; } /* replace: add all new children to target */ @@ -180,7 +181,7 @@ changelog_insert(clicon_handle h, /* delete target */ static int -changelog_delete(clicon_handle h, +changelog_delete(clixon_handle h, cxobj *xt, cxobj *xw) { @@ -195,7 +196,7 @@ changelog_delete(clicon_handle h, /* Move target node to location */ static int -changelog_move(clicon_handle h, +changelog_move(clixon_handle h, cxobj *xt, cxobj *xw, cvec *nsc, @@ -205,7 +206,7 @@ changelog_move(clicon_handle h, cxobj *xp; /* destination parent node */ if ((xp = xpath_first(xt, nsc, "%s", dst)) == NULL){ - clicon_err(OE_XML, 0, "path required"); + clixon_err(OE_XML, 0, "path required"); goto done; } if (xml_addsub(xp, xw) < 0) @@ -226,7 +227,7 @@ changelog_move(clicon_handle h, * @note XXX xn --> xt xpath may not match */ static int -changelog_op(clicon_handle h, +changelog_op(clixon_handle h, cxobj *xt, cxobj *xi) @@ -293,7 +294,7 @@ changelog_op(clicon_handle h, ret = changelog_move(h, xt, xw, nsc, dst); } else{ - clicon_err(OE_XML, 0, "Unknown operation: %s", op); + clixon_err(OE_XML, 0, "Unknown operation: %s", op); goto done; } if (ret < 0) @@ -326,7 +327,7 @@ changelog_op(clicon_handle h, * @retval -1 Error */ static int -changelog_iterate(clicon_handle h, +changelog_iterate(clixon_handle h, cxobj *xt, cxobj *xch) @@ -373,7 +374,7 @@ changelog_iterate(clicon_handle h, * @see upgrade_callback_register where this function should be registered */ int -xml_changelog_upgrade(clicon_handle h, +xml_changelog_upgrade(clixon_handle h, cxobj *xt, char *ns, uint16_t op, @@ -438,7 +439,7 @@ xml_changelog_upgrade(clicon_handle h, /*! Initialize module revision. read changelog, etc */ int -clixon_xml_changelog_init(clicon_handle h) +clixon_xml_changelog_init(clixon_handle h) { int retval = -1; char *filename; @@ -452,7 +453,7 @@ clixon_xml_changelog_init(clicon_handle h) yspec = clicon_dbspec_yang(h); if ((filename = clicon_option_str(h, "CLICON_XML_CHANGELOG_FILE")) != NULL){ if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_UNIX, errno, "fopen(%s)", filename); + clixon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; } if (clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL) < 0) @@ -465,12 +466,12 @@ clixon_xml_changelog_init(clicon_handle h) goto done; if (ret == 0){ /* validation failed */ if ((cbret = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (netconf_err2cb(h, xret, cbret) < 0) goto done; - clicon_err(OE_YANG, 0, "validation failed: %s", cbuf_get(cbret)); + clixon_err(OE_YANG, 0, "validation failed: %s", cbuf_get(cbret)); goto done; } if (clicon_xml_changelog_set(h, xt) < 0) @@ -507,7 +508,7 @@ clixon_xml_changelog_init(clicon_handle h) * vec ::= [, , NULL] */ int -xml_namespace_vec(clicon_handle h, +xml_namespace_vec(clixon_handle h, cxobj *xt, char *ns, cxobj ***vecp, @@ -525,7 +526,7 @@ xml_namespace_vec(clicon_handle h, */ xlen = xml_child_nr_type(xt, CX_ELMNT)+1; if ((xvec = calloc(xlen, sizeof(cxobj*))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } /* Iterate and find xml nodes with assoctaed namespace */ diff --git a/lib/src/clixon_xml_default.c b/lib/src/clixon_xml_default.c index 944b5afc..509f21de 100644 --- a/lib/src/clixon_xml_default.c +++ b/lib/src/clixon_xml_default.c @@ -55,13 +55,13 @@ /* cligen */ #include -/* clicon */ - +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_string.h" #include "clixon_handle.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_err.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -143,11 +143,11 @@ xml_default_create(yang_stmt *y, if ((xb = xml_new("body", xc, CX_BODY)) == NULL) goto done; if ((cv = yang_cv_get(y)) == NULL){ - clicon_err(OE_UNIX, ENOENT, "No yang cv of %s", yang_argument_get(y)); + clixon_err(OE_UNIX, ENOENT, "No yang cv of %s", yang_argument_get(y)); goto done; } if ((str = cv2str_dup(cv)) == NULL){ - clicon_err(OE_UNIX, errno, "cv2str_dup"); + clixon_err(OE_UNIX, errno, "cv2str_dup"); goto done; } if (xml_value_set(xb, str) < 0) @@ -225,7 +225,7 @@ xml_nopresence_try(yang_stmt *yt, yang_stmt *ydef; if (yt == NULL || yang_keyword_get(yt) != Y_CONTAINER){ - clicon_err(OE_XML, EINVAL, "yt argument is not container"); + clixon_err(OE_XML, EINVAL, "yt argument is not container"); goto done; } *createp = 0; @@ -298,7 +298,7 @@ xml_default(yang_stmt *yt, cg_var *cv; if (xt == NULL){ /* No xml */ - clicon_err(OE_XML, EINVAL, "No XML argument"); + clixon_err(OE_XML, EINVAL, "No XML argument"); goto done; } switch (yang_keyword_get(yt)){ @@ -321,7 +321,7 @@ xml_default(yang_stmt *yt, if (state && yang_config_ancestor(yc)) break; if ((cv = yang_cv_get(yc)) == NULL){ - clicon_err(OE_YANG,0, "Internal error: yang leaf %s not populated with cv as it should", + clixon_err(OE_YANG,0, "Internal error: yang leaf %s not populated with cv as it should", yang_argument_get(yc)); goto done; } @@ -437,7 +437,7 @@ xml_global_defaults_create(cxobj *xt, yang_stmt *ymod = NULL; if (yspec == NULL || yang_keyword_get(yspec) != Y_SPEC){ - clicon_err(OE_XML, EINVAL, "yspec argument is not yang spec"); + clixon_err(OE_XML, EINVAL, "yspec argument is not yang spec"); goto done; } while ((ymod = yn_each(yspec, ymod)) != NULL) @@ -462,7 +462,7 @@ xml_global_defaults_create(cxobj *xt, * @see xml_default_recurse */ int -xml_global_defaults(clicon_handle h, +xml_global_defaults(clixon_handle h, cxobj *xt, cvec *nsc, const char *xpath, diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 99063b03..53fd455a 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -57,12 +57,13 @@ #include /* clixon */ -#include "clixon_err.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_options.h" @@ -543,7 +544,7 @@ xmltree2cbuf(cbuf *cb, * @param[out] xerr Reason for failure (yang assignment not made) * @retval 1 Parse OK and all yang assignment made * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 Error with clicon_err called. Includes parse error + * @retval -1 Error * @see clixon_xml_parse_file * @see clixon_xml_parse_string * @see _json_parse @@ -578,11 +579,11 @@ _xml_parse(const char *str, return 1; /* OK */ } if (xt == NULL){ - clicon_err(OE_XML, errno, "Unexpected NULL XML"); + clixon_err(OE_XML, errno, "Unexpected NULL XML"); return -1; } if ((xy.xy_parse_string = strdup(str)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); return -1; } xy.xy_xtop = xt; @@ -672,7 +673,7 @@ _xml_parse(const char *str, * @param[out] xerr Pointer to XML error tree, if retval is 0 * @retval 1 Parse OK and all yang assignment made * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set - * @retval -1 Error with clicon_err called. Includes parse error + * @retval -1 Error * * @code * cxobj *xt = NULL; @@ -707,22 +708,22 @@ clixon_xml_parse_file(FILE *fp, int failed = 0; if (xt==NULL || fp == NULL){ - clicon_err(OE_XML, EINVAL, "arg is NULL"); + clixon_err(OE_XML, EINVAL, "arg is NULL"); return -1; } if (yb == YB_MODULE && yspec == NULL){ - clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE"); + clixon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE"); return -1; } if ((xmlbuf = malloc(xmlbuflen)) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(xmlbuf, 0, xmlbuflen); ptr = xmlbuf; while (1){ if ((ret = fread(&ch, 1, 1, fp)) < 0){ - clicon_err(OE_XML, errno, "read"); + clixon_err(OE_XML, errno, "read"); break; } if (ret != 0){ @@ -742,7 +743,7 @@ clixon_xml_parse_file(FILE *fp, oldxmlbuflen = xmlbuflen; xmlbuflen *= 2; if ((xmlbuf = realloc(xmlbuf, xmlbuflen)) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } memset(xmlbuf+oldxmlbuflen, 0, xmlbuflen-oldxmlbuflen); @@ -769,7 +770,7 @@ clixon_xml_parse_file(FILE *fp, * @param[out] xerr Reason for failure (yang assignment not made) if retval = 0 * @retval 1 Parse OK and all yang assignment made * @retval 0 Parse OK but yang assigment not made (or only partial), xerr is set - * @retval -1 Error with clicon_err called. Includes parse error + * @retval -1 Error * * @code * cxobj *xt = NULL; @@ -794,11 +795,11 @@ clixon_xml_parse_string(const char *str, cxobj **xerr) { if (xt==NULL){ - clicon_err(OE_XML, EINVAL, "xt is NULL"); + clixon_err(OE_XML, EINVAL, "xt is NULL"); return -1; } if (yb == YB_MODULE && yspec == NULL){ - clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE"); + clixon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE"); return -1; } if (*xt == NULL){ @@ -819,7 +820,7 @@ clixon_xml_parse_string(const char *str, * @param[in] format Format string for stdarg according to printf(3) * @retval 1 Parse OK and all yang assignment made * @retval 0 Parse OK but yang assigment not made (or only partial) - * @retval -1 Error with clicon_err called. Includes parse error + * @retval -1 Error * * @code * cxobj *xt = NULL; @@ -847,7 +848,7 @@ clixon_xml_parse_va(yang_bind yb, len = vsnprintf(NULL, 0, format, args) + 1; va_end(args); if ((str = malloc(len)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(str, 0, len); @@ -884,7 +885,7 @@ clixon_xml_attr_copy(cxobj *xin, cxobj *xa; if (xin == NULL || xout == NULL){ - clicon_err(OE_XML, EINVAL, "xin or xout NULL"); + clixon_err(OE_XML, EINVAL, "xin or xout NULL"); goto done; } if ((msgid = xml_find_value(xin, name)) != NULL){ diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index dd0bdcf1..f70e4e16 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -56,12 +56,14 @@ /* cligen */ #include -/* clicon */ - +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_err.h" #include "clixon_string.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -72,8 +74,6 @@ #include "clixon_xml_nsctx.h" #include "clixon_xpath_ctx.h" #include "clixon_xpath.h" -#include "clixon_log.h" -#include "clixon_err.h" #include "clixon_netconf_lib.h" #include "clixon_xml_sort.h" #include "clixon_yang_type.h" @@ -115,7 +115,7 @@ isxmlns(cxobj *x) * @param[in] ys Yang spec containing type specification of top-node of xt * @param[out] cvv CLIgen variable vector. Should be freed by cvec_free() * @retval 0 Everything OK, cvv allocated and set - * @retval -1 Something wrong, clicon_err() called to set error. No cvv returned + * @retval -1 Something wrong, clixon_err() called to set error. No cvv returned * @note cvv Should be freed by cvec_free() after use. * 'Not recursive' means that only one level of XML bodies is translated to cvec:s. * If range is wriong (eg 1000 for uint8) a warning is logged, the value is @@ -151,7 +151,7 @@ xml2cvec(cxobj *xt, xc = NULL; /* Tried to allocate whole cvv here, but some cg_vars may be invalid */ if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto err; } xc = NULL; @@ -163,17 +163,17 @@ xml2cvec(cxobj *xt, __FUNCTION__, name, yang_argument_get(yt)); if ((body = xml_body(xc)) != NULL){ if ((cv = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_PLUGIN, errno, "cv_new"); + clixon_err(OE_PLUGIN, errno, "cv_new"); goto err; } cv_name_set(cv, name); if ((ret = cv_parse1(body, cv, &reason)) < 0){ - clicon_err(OE_PLUGIN, errno, "cv_parse %s",name); + clixon_err(OE_PLUGIN, errno, "cv_parse %s",name); goto err; } /* If value is out-of-range, log and skip value, and continue */ if (ret == 0){ - clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason); + clixon_log(NULL, LOG_WARNING, "cv_parse %s: %s", name, reason); if (reason) free(reason); } @@ -185,19 +185,19 @@ xml2cvec(cxobj *xt, else if ((ycv = yang_cv_get(ys)) != NULL){ if ((body = xml_body(xc)) != NULL){ if ((cv = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_PLUGIN, errno, "cv_new"); + clixon_err(OE_PLUGIN, errno, "cv_new"); goto err; } if (cv_cp(cv, ycv) < 0){ - clicon_err(OE_PLUGIN, errno, "cv_cp"); + clixon_err(OE_PLUGIN, errno, "cv_cp"); goto err; } if ((ret = cv_parse1(body, cv, &reason)) < 0){ - clicon_err(OE_PLUGIN, errno, "cv_parse: %s", name); + clixon_err(OE_PLUGIN, errno, "cv_parse: %s", name); goto err; } if (ret == 0){ - clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason); + clixon_log(NULL, LOG_WARNING, "cv_parse %s: %s", name, reason); if (reason) free(reason); } @@ -226,7 +226,7 @@ xml2cvec(cxobj *xt, * @param[in] xt Parent, or NULL * @param[out] xt Pointer to XML tree containing one top node. Should be freed with xml_free * @retval 0 Everything OK, cvv allocated and set - * @retval -1 Something wrong, clicon_err() called to set error. No xt returned + * @retval -1 Something wrong, clixon_err() called to set error. No xt returned * @see xml2cvec * @see cvec2xml This does more but has an internal xml2cvec translation */ @@ -789,7 +789,7 @@ xml_sanity(cxobj *xt, } name = xml_name(xt); if (strstr(yang_argument_get(ys), name)==NULL){ - clicon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'", + clixon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'", name, yang_argument_get(ys)); goto done; } @@ -824,7 +824,7 @@ xml_non_config_data(cxobj *xt, if (!yang_config(y)){ /* config == false means state data */ if (xerr){ /* behaviour 1: return on error */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "module %s: state data node unexpected", yang_argument_get(ys_module(y))); @@ -875,12 +875,12 @@ xmlns_assign(cxobj *x) char *ns_xml; /* may be null or incorrect */ if ((y = xml_spec(x)) == NULL){ - clicon_err(OE_YANG, ENOENT, "XML %s does not have yang spec", xml_name(x)); + clixon_err(OE_YANG, ENOENT, "XML %s does not have yang spec", xml_name(x)); goto done; } /* 1. Check which namespace x should have (via yang). This is correct namespace. */ if ((ns_correct = yang_find_mynamespace(y)) == NULL){ - clicon_err(OE_YANG, ENOENT, "yang node %s does not have namespace", yang_argument_get(y)); + clixon_err(OE_YANG, ENOENT, "yang node %s does not have namespace", yang_argument_get(y)); goto done; } /* 2. Check which namespace x has via its XML tree */ @@ -924,7 +924,7 @@ assign_namespace(cxobj *x1, /* target */ /* Yes, and it has prefix pexist */ if (pexist){ if ((prefix1 = strdup(pexist)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -936,7 +936,7 @@ assign_namespace(cxobj *x1, /* target */ /* And copy namespace context from parent to child */ if ((nsc0 = nscache_get_all(x1p)) != NULL){ if ((nsc = cvec_dup(nsc0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } nscache_replace(x1, nsc); @@ -962,7 +962,7 @@ assign_namespace(cxobj *x1, /* target */ */ if (isroot){ if (prefix0 && (prefix1 = strdup(prefix0)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1023,7 +1023,7 @@ assign_namespace_element(cxobj *x0, /* source */ if (xml2ns(x0, prefix0, &namespace) < 0) goto done; if (namespace == NULL){ - clicon_err(OE_XML, ENOENT, "No namespace found for prefix:%s", + clixon_err(OE_XML, ENOENT, "No namespace found for prefix:%s", prefix0?prefix0:"NULL"); goto done; } @@ -1136,7 +1136,7 @@ xml_merge1(cxobj *x0, /* the target */ char *pxe; if (x1 == NULL || xml_type(x1) != CX_ELMNT || y0 == NULL){ - clicon_err(OE_XML, EINVAL, "x1 is NULL or not XML element, or lacks yang spec"); + clixon_err(OE_XML, EINVAL, "x1 is NULL or not XML element, or lacks yang spec"); goto done; } if (x0 == NULL){ @@ -1189,7 +1189,7 @@ xml_merge1(cxobj *x0, /* the target */ goto done; twophase_len = xml_child_nr(x1); if ((twophase = calloc(twophase_len, sizeof(*twophase))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } i = 0; @@ -1201,12 +1201,12 @@ xml_merge1(cxobj *x0, /* the target */ if ((yc = yang_find_datanode(y0, x1cname)) == NULL){ if (reason){ if ((cbr = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cbr, "XML node %s/%s has no corresponding yang specification (Invalid XML or wrong Yang spec?", xml_name(x1), x1cname); if ((*reason = strdup(cbuf_get(cbr))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1290,12 +1290,12 @@ xml_merge(cxobj *x0, int ret; if (x0 == NULL || x1 == NULL){ - clicon_err(OE_UNIX, EINVAL, "parameters x0 or x1 is NULL"); + clixon_err(OE_UNIX, EINVAL, "parameters x0 or x1 is NULL"); goto done; } twophase_len = xml_child_nr(x1); if ((twophase = calloc(twophase_len, sizeof(*twophase))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } /* Loop through children of the modification tree */ @@ -1308,7 +1308,7 @@ xml_merge(cxobj *x0, if (ymod == NULL){ if (reason && (*reason = strdup("Namespace not found or yang spec not loaded")) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } goto fail; @@ -1317,12 +1317,12 @@ xml_merge(cxobj *x0, if ((yc = yang_find_datanode(ymod, x1cname)) == NULL){ if (reason){ if ((cbr = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cbr, "XML node %s/%s has no corresponding yang specification (Invalid XML or wrong Yang spec?)", xml_name(x1), x1cname); if ((*reason = strdup(cbuf_get(cbr))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1387,7 +1387,7 @@ yang_valstr2enum(yang_stmt *ytype, yang_stmt *yval; if (enumstr == NULL){ - clicon_err(OE_UNIX, EINVAL, "str is NULL"); + clixon_err(OE_UNIX, EINVAL, "str is NULL"); goto done; } while ((yenum = yn_each(ytype, yenum)) != NULL) { @@ -1422,7 +1422,7 @@ yang_enum2valstr(yang_stmt *ytype, yang_stmt *yval; if (valstr == NULL){ - clicon_err(OE_UNIX, EINVAL, "valstr is NULL"); + clixon_err(OE_UNIX, EINVAL, "valstr is NULL"); goto done; } if ((yenum = yang_find(ytype, Y_ENUM, enumstr)) == NULL) @@ -1477,7 +1477,7 @@ yang_enum_int_value(cxobj *node, NULL, NULL, NULL, NULL, NULL) < 0) goto done; if (yrestype == NULL){ - clicon_err(OE_YANG, 0, "result-type should not be NULL"); + clixon_err(OE_YANG, 0, "result-type should not be NULL"); goto done; } if (yrestype==NULL || strcmp(yang_argument_get(yrestype), "enumeration")) @@ -1870,7 +1870,7 @@ clixon_compare_xmls(cxobj *xc1, snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX"); snprintf(filename2, sizeof(filename2), "/tmp/cliconXXXXXX"); if ((fd = mkstemp(filename1)) < 0){ - clicon_err(OE_UNDEF, errno, "tmpfile"); + clixon_err(OE_UNDEF, errno, "tmpfile"); goto done; } if ((f = fdopen(fd, "w")) == NULL) @@ -1890,7 +1890,7 @@ clixon_compare_xmls(cxobj *xc1, close(fd); if ((fd = mkstemp(filename2)) < 0){ - clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno)); + clixon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno)); goto done; } if ((f = fdopen(fd, "w")) == NULL) @@ -1911,7 +1911,7 @@ clixon_compare_xmls(cxobj *xc1, close(fd); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_CFG, errno, "cbuf_new"); + clixon_err(OE_CFG, errno, "cbuf_new"); goto done; } cprintf(cb, "diff -dU 1 %s %s | grep -v @@ | sed 1,2d", diff --git a/lib/src/clixon_xml_nsctx.c b/lib/src/clixon_xml_nsctx.c index 0170dbaf..02c8953f 100644 --- a/lib/src/clixon_xml_nsctx.c +++ b/lib/src/clixon_xml_nsctx.c @@ -58,12 +58,13 @@ #include /* clixon */ -#include "clixon_err.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_options.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -88,7 +89,7 @@ static int _USE_NAMESPACE_NETCONF_DEFAULT = 0; * @param[in] h Clixon handle */ int -xml_nsctx_namespace_netconf_default(clicon_handle h) +xml_nsctx_namespace_netconf_default(clixon_handle h) { _USE_NAMESPACE_NETCONF_DEFAULT = clicon_option_bool(h, "CLICON_NAMESPACE_NETCONF_DEFAULT"); return 0; @@ -117,7 +118,7 @@ xml_nsctx_init(char *prefix, cvec *cvv = NULL; if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_XML, errno, "cvec_new"); + clixon_err(OE_XML, errno, "cvec_new"); goto done; } if (ns && xml_nsctx_add(cvv, prefix, ns) < 0) @@ -291,7 +292,7 @@ xml_nsctx_node(cxobj *xn, cvec *nc = NULL; if ((nc = cvec_new(0)) == NULL){ - clicon_err(OE_XML, errno, "cvec_new"); + clixon_err(OE_XML, errno, "cvec_new"); goto done; } if (xml_nsctx_node1(xn, nc) < 0) @@ -341,19 +342,19 @@ xml_nsctx_yang(yang_stmt *yn, char *myprefix; if (yang_keyword_get(yn) == Y_SPEC){ - clicon_err(OE_YANG, EINVAL, "yang spec node is invalid argument"); + clixon_err(OE_YANG, EINVAL, "yang spec node is invalid argument"); goto done; } if ((nc = cvec_new(0)) == NULL){ - clicon_err(OE_XML, errno, "cvec_new"); + clixon_err(OE_XML, errno, "cvec_new"); goto done; } if ((myprefix = yang_find_myprefix(yn)) == NULL){ - clicon_err(OE_YANG, ENOENT, "My yang prefix not found"); + clixon_err(OE_YANG, ENOENT, "My yang prefix not found"); goto done; } if ((mynamespace = yang_find_mynamespace(yn)) == NULL){ - clicon_err(OE_YANG, ENOENT, "My yang namespace not found"); + clixon_err(OE_YANG, ENOENT, "My yang namespace not found"); goto done; } /* Add my prefix and default namespace (from real module) */ @@ -363,7 +364,7 @@ xml_nsctx_yang(yang_stmt *yn, goto done; /* Find top-most module or sub-module and get prefixes from that */ if ((ymod = ys_module(yn)) == NULL){ - clicon_err(OE_YANG, ENOENT, "My yang module not found"); + clixon_err(OE_YANG, ENOENT, "My yang module not found"); goto done; } yspec = yang_parent_get(ymod); /* Assume yspec exists */ @@ -427,7 +428,7 @@ xml_nsctx_yangspec(yang_stmt *yspec, if (ncp && *ncp) nc = *ncp; else if ((nc = cvec_new(0)) == NULL){ - clicon_err(OE_XML, errno, "cvec_new"); + clixon_err(OE_XML, errno, "cvec_new"); goto done; } ymod = NULL; @@ -562,7 +563,7 @@ xml2ns_recurse(cxobj *xt) if (xml2ns(x, prefix, &namespace) < 0) goto done; if (namespace == NULL){ - clicon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x)); + clixon_err(OE_XML, ENOENT, "No namespace associated with %s:%s", prefix, xml_name(x)); goto done; } } diff --git a/lib/src/clixon_xml_parse.l b/lib/src/clixon_xml_parse.l index 2dedcd60..590a8924 100644 --- a/lib/src/clixon_xml_parse.l +++ b/lib/src/clixon_xml_parse.l @@ -53,7 +53,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" diff --git a/lib/src/clixon_xml_parse.y b/lib/src/clixon_xml_parse.y index 0cbe564e..6cc31384 100644 --- a/lib/src/clixon_xml_parse.y +++ b/lib/src/clixon_xml_parse.y @@ -72,11 +72,13 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" +#include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_string.h" #include "clixon_handle.h" #include "clixon_yang.h" @@ -95,7 +97,7 @@ void clixon_xml_parseerror(void *_xy, char *s) { - clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s", + clixon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s", _XY->xy_linenum, s, clixon_xml_parsetext); @@ -183,7 +185,7 @@ xml_parse_version(clixon_xml_yacc *xy, char *ver) { if(strcmp(ver, "1.0")){ - clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML version: %s expected 1.0", ver); + clixon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML version: %s expected 1.0", ver); free(ver); return -1; } @@ -211,7 +213,7 @@ xml_parse_encoding(clixon_xml_yacc *xy, char *enc) { if(strcasecmp(enc, "UTF-8")){ - clicon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML encoding: %s expected UTF-8", enc); + clixon_err(OE_XML, XMLPARSE_ERRNO, "Unsupported XML encoding: %s expected UTF-8", enc); free(enc); return -1; } @@ -312,7 +314,7 @@ xml_parse_bslash(clixon_xml_yacc *xy, /* Check name or prerix unequal from begin-tag */ if (clicon_strcmp(name0, name) || clicon_strcmp(prefix0, prefix)){ - clicon_err(OE_XML, XMLPARSE_ERRNO, "Sanity check failed: %s%s%s vs %s%s%s", + clixon_err(OE_XML, XMLPARSE_ERRNO, "Sanity check failed: %s%s%s vs %s%s%s", prefix0?prefix0:"", prefix0?":":"", name0, prefix?prefix:"", prefix?":":"", name); goto done; diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index 45e7bfdb..1ab8385c 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -54,12 +54,13 @@ #include /* clixon */ -#include "clixon_err.h" -#include "clixon_log.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_nsctx.h" @@ -104,29 +105,29 @@ xml_cv_cache(cxobj *x, if ((cv = xml_cv(x)) != NULL) goto ok; if ((y = xml_spec(x)) == NULL){ - clicon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body); + clixon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body); goto done; } if (yang_type_get(y, NULL, &yrestype, &options, NULL, NULL, NULL, &fraction) < 0) goto done; yang2cv_type(yang_argument_get(yrestype), &cvtype); if (cvtype==CGV_ERR){ - clicon_err(OE_YANG, errno, "yang->cligen type %s mapping failed", + clixon_err(OE_YANG, errno, "yang->cligen type %s mapping failed", yang_argument_get(yrestype)); goto done; } if ((cv = cv_new(cvtype)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } if (cvtype == CGV_DEC64) cv_dec64_n_set(cv, fraction); if ((ret = cv_parse1(body, cv, &reason)) < 0){ - clicon_err(OE_YANG, errno, "cv_parse1"); + clixon_err(OE_YANG, errno, "cv_parse1"); goto done; } if (ret == 0){ - clicon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason); + clixon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason); goto done; } if (xml_cv_set(x, cv) < 0) @@ -647,7 +648,7 @@ xml_search_indexvar_binary_pos(cxobj *x1, cxobj *xc; if (upper < low){ /* beyond range */ - clicon_err(OE_XML, 0, "low>upper %d %d", low, upper); + clixon_err(OE_XML, 0, "low>upper %d %d", low, upper); goto done; } if (low == upper){ @@ -656,7 +657,7 @@ xml_search_indexvar_binary_pos(cxobj *x1, } mid = (low + upper) / 2; if (mid >= max){ /* beyond range */ - clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper); + clixon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper); goto done; } xc = clixon_xvec_i(ivec, mid); @@ -839,7 +840,7 @@ xml_search_yang(cxobj *xp, int yangi; if (xp == NULL){ - clicon_err(OE_XML, EINVAL, "xp is NULL"); + clixon_err(OE_XML, EINVAL, "xp is NULL"); goto done; } upper = xml_child_nr(xp); @@ -926,31 +927,31 @@ xml_insert_userorder(cxobj *xp, case INS_AFTER: /* see retval handling different between before and after */ if (key_val == NULL) /* shouldnt happen */ - clicon_err(OE_YANG, 0, "Missing key/value attribute when insert is before"); + clixon_err(OE_YANG, 0, "Missing key/value attribute when insert is before"); else{ switch (yang_keyword_get(yn)){ case Y_LEAF_LIST: if ((xc = xpath_first(xp, nsc_key, "%s[.='%s']", xml_name(xn), key_val)) == NULL) - clicon_err(OE_YANG, 0, "bad-attribute: value, missing-instance: %s", key_val); + clixon_err(OE_YANG, 0, "bad-attribute: value, missing-instance: %s", key_val); else { if ((i = xml_child_order(xp, xc)) < 0) - clicon_err(OE_YANG, 0, "internal error xpath found but not in child list"); + clixon_err(OE_YANG, 0, "internal error xpath found but not in child list"); else retval = (ins==INS_BEFORE)?i:i+1; } break; case Y_LIST: if ((xc = xpath_first(xp, nsc_key, "%s%s", xml_name(xn), key_val)) == NULL) - clicon_err(OE_YANG, 0, "bad-attribute: key, missing-instance: %s", key_val); + clixon_err(OE_YANG, 0, "bad-attribute: key, missing-instance: %s", key_val); else { if ((i = xml_child_order(xp, xc)) < 0) - clicon_err(OE_YANG, 0, "internal error xpath found but not in child list"); + clixon_err(OE_YANG, 0, "internal error xpath found but not in child list"); else retval = (ins==INS_BEFORE)?i:i+1; } break; default: - clicon_err(OE_YANG, 0, "insert only for leaf or leaf-list"); + clixon_err(OE_YANG, 0, "insert only for leaf or leaf-list"); break; } /* switch */ } @@ -996,7 +997,7 @@ xml_insert2(cxobj *xp, int yi; if (low > upper){ /* beyond range */ - clicon_err(OE_XML, 0, "low>upper %d %d", low, upper); + clixon_err(OE_XML, 0, "low>upper %d %d", low, upper); goto done; } if (low == upper){ @@ -1005,16 +1006,16 @@ xml_insert2(cxobj *xp, } mid = (low + upper) / 2; if (mid >= xml_child_nr(xp)){ /* beyond range */ - clicon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper); + clixon_err(OE_XML, 0, "Beyond range %d %d %d", low, mid, upper); goto done; } xc = xml_child_i(xp, mid); if ((yc = xml_spec(xc)) == NULL){ if (xml_type(xc) != CX_ELMNT) - clicon_err(OE_XML, 0, "No spec found %s (wrong xml type:%s)", + clixon_err(OE_XML, 0, "No spec found %s (wrong xml type:%s)", xml_name(xc), xml_type2str(xml_type(xc))); else - clicon_err(OE_XML, 0, "No spec found %s", xml_name(xc)); + clixon_err(OE_XML, 0, "No spec found %s", xml_name(xc)); goto done; } if (yc == yn){ /* Same yang */ @@ -1086,11 +1087,11 @@ xml_insert(cxobj *xp, * added as a child */ if (xml_parent(xi) != NULL){ - clicon_err(OE_XML, 0, "XML node %s should not have parent", xml_name(xi)); + clixon_err(OE_XML, 0, "XML node %s should not have parent", xml_name(xi)); goto done; } if ((y = xml_spec(xi)) == NULL){ - clicon_err(OE_XML, 0, "No spec found %s", xml_name(xi)); + clixon_err(OE_XML, 0, "No spec found %s", xml_name(xi)); goto done; } upper = xml_child_nr(xp); @@ -1302,7 +1303,7 @@ xml_find_noyang_name(cxobj *xp, char *ns; if (name == NULL || ns0 == NULL){ - clicon_err(OE_XML, EINVAL, "name and namespace required"); + clixon_err(OE_XML, EINVAL, "name and namespace required"); goto done; } /* Go through children linearly */ @@ -1369,12 +1370,12 @@ xml_find_index_yang(cxobj *xp, char *indexvar = NULL; if (xp == NULL){ - clicon_err(OE_XML, EINVAL, "xp is NULL"); + clixon_err(OE_XML, EINVAL, "xp is NULL"); goto done; } name = yang_argument_get(yc); if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } switch (yang_keyword_get(yc)){ @@ -1389,7 +1390,7 @@ xml_find_index_yang(cxobj *xp, i = 0; while ((cvi = cvec_each(cvk, cvi)) != NULL) { if ((kname = cv_name_get(cvi)) == NULL){ - clicon_err(OE_YANG, ENOENT, "missing yang key name in cvk"); + clixon_err(OE_YANG, ENOENT, "missing yang key name in cvk"); goto done; } /* Parameter in cvk is not key or not in right key order, then we cannot call @@ -1411,7 +1412,7 @@ xml_find_index_yang(cxobj *xp, break; case Y_LEAF_LIST: if (cvec_len(cvk) != 1){ - clicon_err(OE_YANG, ENOENT, "expected exactly one leaf-list key"); + clixon_err(OE_YANG, ENOENT, "expected exactly one leaf-list key"); goto done; } cvi = cvec_i(cvk, 0); @@ -1455,7 +1456,7 @@ xml_find_index_yang(cxobj *xp, xk = NULL; while ((xk = xml_child_each(xc, xk, CX_ELMNT)) != NULL) { if ((yk = yang_find(yc, Y_LEAF, xml_name(xk))) == NULL){ - clicon_err(OE_YANG, ENOENT, "yang spec of key %s not found", xml_name(xk)); + clixon_err(OE_YANG, ENOENT, "yang spec of key %s not found", xml_name(xk)); goto done; } if (xml_spec_set(xk, yk) < 0) @@ -1540,11 +1541,11 @@ clixon_xml_find_index(cxobj *xp, yang_stmt *yc = NULL; if (xvec == NULL){ - clicon_err(OE_YANG, EINVAL, "xvec"); + clixon_err(OE_YANG, EINVAL, "xvec"); goto done; } if (name == NULL){ - clicon_err(OE_YANG, EINVAL, "name"); + clixon_err(OE_YANG, EINVAL, "name"); goto done; } if (yp == NULL) @@ -1595,7 +1596,7 @@ clixon_xml_find_pos(cxobj *xp, uint32_t u; if (yc == NULL){ - clicon_err(OE_YANG, ENOENT, "yang spec not found"); + clixon_err(OE_YANG, ENOENT, "yang spec not found"); goto done; } name = yang_argument_get(yc); diff --git a/lib/src/clixon_xml_vec.c b/lib/src/clixon_xml_vec.c index cd3465db..564e4e62 100644 --- a/lib/src/clixon_xml_vec.c +++ b/lib/src/clixon_xml_vec.c @@ -53,12 +53,13 @@ #include /* clixon */ -#include "clixon_err.h" #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_io.h" @@ -101,7 +102,7 @@ clixon_xvec_inc(clixon_xvec *xv) else xv->xv_max += XVEC_MAX_THRESHOLD; /* Add - linear growth */ if ((xv->xv_vec = realloc(xv->xv_vec, sizeof(cxobj *) * xv->xv_max)) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } } @@ -123,7 +124,7 @@ clixon_xvec_new(void) clixon_xvec *xv = NULL; if ((xv = malloc(sizeof(*xv))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xv, 0, sizeof(*xv)); @@ -151,7 +152,7 @@ clixon_xvec_dup(clixon_xvec *xv0) xv1->xv_vec = NULL; if (xv1->xv_max && (xv1->xv_vec = calloc(xv1->xv_max, sizeof(cxobj*))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); free(xv1); xv1 = NULL; goto done; @@ -219,7 +220,7 @@ clixon_xvec_extract(clixon_xvec *xv, int retval = -1; if (xv == NULL){ - clicon_err(OE_XML, EINVAL, "xv is NULL"); + clixon_err(OE_XML, EINVAL, "xv is NULL"); goto done; } *xvec = xv->xv_vec; diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c index 782482ac..e3f3caad 100644 --- a/lib/src/clixon_xpath.c +++ b/lib/src/clixon_xpath.c @@ -80,13 +80,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_nsctx.h" @@ -245,7 +246,7 @@ xpath_tree_print(FILE *f, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (xpath_tree_print0(cb, xs, 0) < 0) @@ -379,7 +380,7 @@ xpath_tree_append(xpath_tree *xt, int retval = -1; if ((*vec = realloc(*vec, sizeof(xpath_tree *) * (*len+1))) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } (*vec)[(*len)++] = xt; @@ -559,7 +560,7 @@ xpath_parse(const char *xpath, clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (xpath == NULL){ - clicon_err(OE_XML, EINVAL, "XPath is NULL"); + clixon_err(OE_XML, EINVAL, "XPath is NULL"); goto done; } xpy.xpy_parse_string = xpath; @@ -570,15 +571,15 @@ xpath_parse(const char *xpath, if (xpath_parse_init(&xpy) < 0) goto done; if (clixon_xpath_parseparse(&xpy) != 0) { /* yacc returns 1 on error */ - clicon_log(LOG_NOTICE, "XPath error: on line %d", xpy.xpy_linenum); - if (clicon_errno == 0) - clicon_err(OE_XML, 0, "XPath parser error with no error code (should not happen)"); + clixon_log(NULL, LOG_NOTICE, "XPath error: on line %d", xpy.xpy_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_XML, 0, "XPath parser error with no error code (should not happen)"); xpath_scan_exit(&xpy); goto done; } if (clixon_debug_get() > 2){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } xpath_tree_print_cb(cb, xpy.xpy_top); @@ -688,13 +689,13 @@ xpath_first(cxobj *xcur, va_end(ap); /* allocate a message string exactly fitting the message length */ if ((xpath = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: compute write message from reason and args */ va_start(ap, xpformat); if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -747,13 +748,13 @@ xpath_first_localonly(cxobj *xcur, va_end(ap); /* allocate a message string exactly fitting the message length */ if ((xpath = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: compute write message from reason and args */ va_start(ap, xpformat); if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -771,6 +772,7 @@ xpath_first_localonly(cxobj *xcur, } /*! Given XML tree and xpath, returns nodeset as xml node vector + * * If result is not nodeset, return empty nodeset * @param[in] xcur xml-tree where to search * @param[in] nsc External XML namespace context, or NULL @@ -811,13 +813,13 @@ xpath_vec(cxobj *xcur, va_end(ap); /* allocate an xpath string exactly fitting the length */ if ((xpath = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: actually compute xpath string content */ va_start(ap, veclen); if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -888,13 +890,13 @@ xpath_vec_flag(cxobj *xcur, va_end(ap); /* allocate a message string exactly fitting the message length */ if ((xpath = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: compute write message from reason and args */ va_start(ap, veclen); if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -947,13 +949,13 @@ xpath_vec_bool(cxobj *xcur, va_end(ap); /* allocate a message string exactly fitting the message length */ if ((xpath = malloc(len+1)) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } /* second round: compute write message from reason and args */ va_start(ap, xpformat); if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ - clicon_err(OE_UNIX, errno, "vsnprintf"); + clixon_err(OE_UNIX, errno, "vsnprintf"); va_end(ap); goto done; } @@ -1006,7 +1008,7 @@ xpath_traverse_canonical(xpath_tree *xs, // name = xs->xs_s1; if ((namespace = xml_nsctx_get(nsc0, prefix0)) == NULL){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "No namespace found for prefix: %s", prefix0); @@ -1017,7 +1019,7 @@ xpath_traverse_canonical(xpath_tree *xs, if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){ #if 0 /* Just accept it, see note in xpath2canonical */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "No yang found for namespace: %s", namespace); @@ -1031,7 +1033,7 @@ xpath_traverse_canonical(xpath_tree *xs, else if ((prefix1 = yang_find_myprefix(ymod)) == NULL){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "No prefix found in module: %s", yang_argument_get(ymod)); @@ -1046,7 +1048,7 @@ xpath_traverse_canonical(xpath_tree *xs, if (xs->xs_s0) free(xs->xs_s0); if ((xs->xs_s0 = strdup(prefix1)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1139,14 +1141,14 @@ xpath2canonical(const char *xpath0, goto fail; /* Print tree with new prefixes */ if ((xcb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (xpath_tree2cbuf(xpt, xcb) < 0) goto done; if (xpath1){ if ((*xpath1 = strdup(cbuf_get(xcb))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } } @@ -1189,7 +1191,7 @@ xpath_count(cxobj *xcur, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "count(%s)", xpath); @@ -1292,7 +1294,7 @@ xml2xpath1(cxobj *x, while ((cvi = cvec_each(cvk, cvi)) != NULL) { keyname = cv_string_get(cvi); if ((xkey = xml_find(x, keyname)) == NULL){ - clicon_err(OE_XML, 0, "No key %s in list %s", keyname, xml_name(x)); + clixon_err(OE_XML, 0, "No key %s in list %s", keyname, xml_name(x)); goto done; } if ((xb = xml_find(x, keyname)) == NULL) @@ -1358,7 +1360,7 @@ xml2xpath(cxobj *x, char *xpath = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } if (xml2xpath1(x, nsc, spec, apostrophe, cb) < 0) @@ -1367,7 +1369,7 @@ xml2xpath(cxobj *x, xpath = cbuf_get(cb); if (xpathp){ if ((*xpathp = strdup(xpath)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } xpath = NULL; @@ -1388,7 +1390,7 @@ xml2xpath(cxobj *x, * @param[out] xerr Netconf error message (if retval=0) * @retval 1 OK * @retval 0 Invalid xpath - * @retval -1 Fatal error, clicon_err called + * @retval -1 Fatal error, clixon_err called * @see xpath_traverse_canonical */ static int @@ -1419,7 +1421,7 @@ xpath2xml_traverse(xpath_tree *xs, name = xs->xs_s1; if ((namespace = xml_nsctx_get(nsc, prefix)) == NULL){ if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cberr, "No namespace found for prefix: %s", prefix); @@ -1498,7 +1500,7 @@ xpath2xml_traverse(xpath_tree *xs, * @param[out] xerr Netconf error message (if retval=0) * @retval 1 OK * @retval 0 Invalid xpath - * @retval -1 Fatal error, clicon_err called + * @retval -1 Fatal error, clixon_err called * @see api_path2xml * @see xml2xpath * @note xpath is restricted to absolute paths, and simple expressions, eg as "node-identifier" @@ -1518,7 +1520,7 @@ xpath2xml(char *xpath, clixon_debug(CLIXON_DBG_DETAIL, "%s xpath:%s", __FUNCTION__, xpath); if ((cberr = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (*xpath != '/'){ diff --git a/lib/src/clixon_xpath_ctx.c b/lib/src/clixon_xpath_ctx.c index 2450bfab..0f6548cc 100644 --- a/lib/src/clixon_xpath_ctx.c +++ b/lib/src/clixon_xpath_ctx.c @@ -50,13 +50,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xpath_ctx.h" @@ -93,21 +94,21 @@ ctx_dup(xp_ctx *xc0) xp_ctx *xc = NULL; if ((xc = malloc(sizeof(*xc))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xc, 0, sizeof(*xc)); *xc = *xc0; if (xc0->xc_size){ if ((xc->xc_nodeset = calloc(xc0->xc_size, sizeof(cxobj*))) == NULL){ - clicon_err(OE_UNIX, errno, "calloc"); + clixon_err(OE_UNIX, errno, "calloc"); goto done; } memcpy(xc->xc_nodeset, xc0->xc_nodeset, xc->xc_size*sizeof(cxobj*)); } if (xc0->xc_string) if ((xc->xc_string = strdup(xc0->xc_string)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } done: @@ -173,7 +174,7 @@ ctx_print(FILE *f, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } ctx_print_cb(cb, xc, 0, str); @@ -238,19 +239,19 @@ ctx2string(xp_ctx *xc, case XT_NODESET: if (xc->xc_size && (b = xml_body(xc->xc_nodeset[0]))){ if ((str = strdup(b)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); goto done; } } else if ((str = strdup("")) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); goto done; } break; case XT_BOOL: if ((str = strdup(xc->xc_bool == 0?"false":"true")) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); goto done; } break; @@ -258,14 +259,14 @@ ctx2string(xp_ctx *xc, len = snprintf(NULL, 0, "%0lf", xc->xc_number); len++; if ((str = malloc(len)) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } snprintf(str, len, "%0lf", xc->xc_number); break; case XT_STRING: if ((str = strdup(xc->xc_string)) == NULL){ - clicon_err(OE_XML, errno, "strdup"); + clixon_err(OE_XML, errno, "strdup"); goto done; } break; diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index 22a5fd7f..c99c090f 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -72,13 +72,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_yang_type.h" #include "clixon_xml.h" @@ -429,7 +430,7 @@ xp_eval_step(xp_ctx *xc0, case A_SELF: break; default: - clicon_err(OE_XML, 0, "No such axisname: %d", xs->xs_int); + clixon_err(OE_XML, 0, "No such axisname: %d", xs->xs_int); goto done; break; } @@ -442,7 +443,7 @@ xp_eval_step(xp_ctx *xc0, xc = NULL; } if (*xrp == NULL){ - clicon_err(OE_XML, 0, "Internal error xrp is NULL"); + clixon_err(OE_XML, 0, "Internal error xrp is NULL"); goto done; } retval = 0; @@ -507,7 +508,7 @@ xp_eval_predicate(xp_ctx *xc, * XXX: alt to check xr0 is nodeset: set new var nodeset to NULL */ if ((xr1 = malloc(sizeof(*xr1))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr1, 0, sizeof(*xr1)); @@ -518,7 +519,7 @@ xp_eval_predicate(xp_ctx *xc, x = xr0->xc_nodeset[i]; /* Create new context */ if ((xcc = malloc(sizeof(*xcc))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(xcc, 0, sizeof(*xcc)); @@ -553,7 +554,7 @@ xp_eval_predicate(xp_ctx *xc, } } if (xr0 == NULL && xr1 == NULL){ - clicon_err(OE_XML, EFAULT, "Internal error: no result produced"); + clixon_err(OE_XML, EFAULT, "Internal error: no result produced"); goto done; } if (xr1){ @@ -597,7 +598,7 @@ xp_logop(xp_ctx *xc1, int b2; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -615,7 +616,7 @@ xp_logop(xp_ctx *xc1, xr->xc_bool = b1 || b2; break; default: - clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context", + clixon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context", __FUNCTION__, clicon_int2str(xpopmap,op)); goto done; } @@ -648,7 +649,7 @@ xp_numop(xp_ctx *xc1, double n2; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -678,7 +679,7 @@ xp_numop(xp_ctx *xc1, xr->xc_number = n1-n2; break; default: - clicon_err(OE_UNIX, errno, "Invalid operator %s in this context", + clixon_err(OE_UNIX, errno, "Invalid operator %s in this context", clicon_int2str(xpopmap,op)); goto done; } @@ -719,29 +720,29 @@ xml_cv_cache(cxobj *x, if ((cv = xml_cv(x)) != NULL) goto ok; if ((y = xml_spec(x)) == NULL){ - clicon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body); + clixon_err(OE_XML, EFAULT, "Yang binding missing for xml symbol %s, body:%s", xml_name(x), body); goto done; } if (yang_type_get(y, NULL, &yrestype, &options, NULL, NULL, NULL, &fraction) < 0) goto done; yang2cv_type(yang_argument_get(yrestype), &cvtype); if (cvtype==CGV_ERR){ - clicon_err(OE_YANG, errno, "yang->cligen type %s mapping failed", + clixon_err(OE_YANG, errno, "yang->cligen type %s mapping failed", yang_argument_get(yrestype)); goto done; } if ((cv = cv_new(cvtype)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } if (cvtype == CGV_DEC64) cv_dec64_n_set(cv, fraction); if ((ret = cv_parse1(body, cv, &reason)) < 0){ - clicon_err(OE_YANG, errno, "cv_parse1"); + clixon_err(OE_YANG, errno, "cv_parse1"); goto done; } if (ret == 0){ - clicon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason); + clixon_err(OE_YANG, EINVAL, "cv parse error: %s\n", reason); goto done; } if (xml_cv_set(x, cv) < 0) @@ -803,11 +804,11 @@ xp_relop(xp_ctx *xc1, int ret; if (xc1 == NULL || xc2 == NULL){ - clicon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL"); + clixon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL"); goto done; } if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -865,7 +866,7 @@ xp_relop(xp_ctx *xc1, xr->xc_bool = (ret > 0); break; default: - clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op)); + clixon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op)); goto done; break; } @@ -891,7 +892,7 @@ xp_relop(xp_ctx *xc1, xr->xc_bool = (strcmp(s1, s2)>0); break; default: - clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op)); + clixon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op)); goto done; break; } @@ -927,7 +928,7 @@ xp_relop(xp_ctx *xc1, xr->xc_bool = (xc1->xc_number > xc2->xc_number); break; default: - clicon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op)); + clixon_err(OE_XML, 0, "Operator %s not supported for nodeset/nodeset comparison", clicon_int2str(xpopmap,op)); goto done; break; } @@ -939,7 +940,7 @@ xp_relop(xp_ctx *xc1, } else if (xc1->xc_type != XT_NODESET && xc2->xc_type != XT_NODESET){ - clicon_err(OE_XML, 0, "Mixed types not supported, %d %d", xc1->xc_type, xc2->xc_type); + clixon_err(OE_XML, 0, "Mixed types not supported, %d %d", xc1->xc_type, xc2->xc_type); goto done; } else{ /* one is nodeset, ie (1) above */ @@ -964,7 +965,7 @@ xp_relop(xp_ctx *xc1, xr->xc_bool = (b != xc2->xc_bool); break; default: - clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and bool", clicon_int2str(xpopmap,op)); + clixon_err(OE_XML, 0, "Operator %s not supported for nodeset and bool", clicon_int2str(xpopmap,op)); goto done; break; } /* switch op */ @@ -1008,7 +1009,7 @@ xp_relop(xp_ctx *xc1, xr->xc_bool = (strcmp(s1, s2)); break; default: - clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and string", clicon_int2str(xpopmap,op)); + clixon_err(OE_XML, 0, "Operator %s not supported for nodeset and string", clicon_int2str(xpopmap,op)); goto done; break; } @@ -1044,7 +1045,7 @@ xp_relop(xp_ctx *xc1, xr->xc_bool = reverse?(n2 > n1):(n1 > n2); break; default: - clicon_err(OE_XML, 0, "Operator %s not supported for nodeset and number", clicon_int2str(xpopmap,op)); + clixon_err(OE_XML, 0, "Operator %s not supported for nodeset and number", clicon_int2str(xpopmap,op)); goto done; break; } @@ -1053,7 +1054,7 @@ xp_relop(xp_ctx *xc1, } break; default: - clicon_err(OE_XML, 0, "Type %d not supported", xc2->xc_type); + clixon_err(OE_XML, 0, "Type %d not supported", xc2->xc_type); } /* switch type */ } ok: @@ -1090,12 +1091,12 @@ xp_union(xp_ctx *xc1, int i; if (op != XO_UNION){ - clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context", + clixon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context", __FUNCTION__, clicon_int2str(xpopmap,op)); goto done; } if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -1245,7 +1246,7 @@ xp_eval(xp_ctx *xc, goto ok; break; default: - clicon_err(OE_XML, EFAULT, "XPath function not implemented: %s", xs->xs_s0); + clixon_err(OE_XML, EFAULT, "XPath function not implemented: %s", xs->xs_s0); goto done; break; } @@ -1286,7 +1287,7 @@ xp_eval(xp_ctx *xc, /* Special case, no c0 or c1, single "/" */ if (xs->xs_c0 == NULL){ if ((xr0 = malloc(sizeof(*xr0))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr0, 0, sizeof(*xr0)); @@ -1316,7 +1317,7 @@ xp_eval(xp_ctx *xc, break; case XP_PRIME_NR: /* primaryexpr -> [] */ if ((xr0 = malloc(sizeof(*xr0))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr0, 0, sizeof(*xr0)); @@ -1326,7 +1327,7 @@ xp_eval(xp_ctx *xc, break; case XP_PRIME_STR: if ((xr0 = malloc(sizeof(*xr0))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr0, 0, sizeof(*xr0)); @@ -1370,7 +1371,7 @@ xp_eval(xp_ctx *xc, else xc->xc_descendant = 0; if (xr0 == NULL && xr1 == NULL && xr2 == NULL){ - clicon_err(OE_XML, EFAULT, "Internal error: no result produced"); + clixon_err(OE_XML, EFAULT, "Internal error: no result produced"); goto done; } if (xr2){ diff --git a/lib/src/clixon_xpath_function.c b/lib/src/clixon_xpath_function.c index 71f293d6..28c6e4ec 100644 --- a/lib/src/clixon_xpath_function.c +++ b/lib/src/clixon_xpath_function.c @@ -54,13 +54,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_options.h" #include "clixon_yang.h" #include "clixon_yang_type.h" @@ -281,7 +282,7 @@ derived_from_one(char *baseidentity, else { /* Allocate cbuf */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "%s:%s", yang_argument_get(ymod), id); @@ -337,7 +338,7 @@ xp_function_derived_from(xp_ctx *xc, int ret = 0; if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){ - clicon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments"); + clixon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments"); goto done; } /* contains two arguments in xs: boolean derived-from(node-set, string) */ @@ -353,7 +354,7 @@ xp_function_derived_from(xp_ctx *xc, goto done; /* Allocate a return struct of type boolean */ if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -415,7 +416,7 @@ xp_function_bit_is_set(xp_ctx *xc, char *body; if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){ - clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments"); + clixon_err(OE_XML, EINVAL, "contains expects but did not get two arguments"); goto done; } /* First node-set argument */ @@ -427,7 +428,7 @@ xp_function_bit_is_set(xp_ctx *xc, if (ctx2string(xr1, &s1) < 0) goto done; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -475,7 +476,7 @@ xp_function_position(xp_ctx *xc, xp_ctx *xr = NULL; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -504,13 +505,13 @@ xp_function_count(xp_ctx *xc, xp_ctx *xr0 = NULL; if (xs == NULL || xs->xs_c0 == NULL){ - clicon_err(OE_XML, EINVAL, "count expects but did not get one argument"); + clixon_err(OE_XML, EINVAL, "count expects but did not get one argument"); goto done; } if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -546,13 +547,13 @@ xp_function_name(xp_ctx *xc, cxobj *x; if (xs == NULL || xs->xs_c0 == NULL){ - clicon_err(OE_XML, EINVAL, "not expects but did not get one argument"); + clixon_err(OE_XML, EINVAL, "not expects but did not get one argument"); goto done; } if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -561,7 +562,7 @@ xp_function_name(xp_ctx *xc, if ((x = xr0->xc_nodeset[i]) == NULL) continue; if ((xr->xc_string = strdup(xml_name(x))) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } break; @@ -602,7 +603,7 @@ xp_function_contains(xp_ctx *xc, char *s1 = NULL; if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){ - clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments"); + clixon_err(OE_XML, EINVAL, "contains expects but did not get two arguments"); goto done; } /* contains two arguments in xs: boolean contains(string, string) */ @@ -615,7 +616,7 @@ xp_function_contains(xp_ctx *xc, if (ctx2string(xr1, &s1) < 0) goto done; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -659,14 +660,14 @@ xp_function_boolean(xp_ctx *xc, int bool; if (xs == NULL || xs->xs_c0 == NULL){ - clicon_err(OE_XML, EINVAL, "not expects but did not get one argument"); + clixon_err(OE_XML, EINVAL, "not expects but did not get one argument"); goto done; } if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0) goto done; bool = ctx2boolean(xr0); if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -712,7 +713,7 @@ xp_function_true(xp_ctx *xc, xp_ctx *xr = NULL; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); @@ -739,7 +740,7 @@ xp_function_false(xp_ctx *xc, xp_ctx *xr = NULL; if ((xr = malloc(sizeof(*xr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xr, 0, sizeof(*xr)); diff --git a/lib/src/clixon_xpath_optimize.c b/lib/src/clixon_xpath_optimize.c index d77d0f17..901eccba 100644 --- a/lib/src/clixon_xpath_optimize.c +++ b/lib/src/clixon_xpath_optimize.c @@ -54,13 +54,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_vec.h" @@ -194,7 +195,7 @@ loop_preds(xpath_tree *xt, if (veclen != 2) goto ok; if ((cvi = cvec_add(cvk, CGV_STRING)) == NULL){ - clicon_err(OE_XML, errno, "cvec_add"); + clixon_err(OE_XML, errno, "cvec_add"); goto done; } cv_name_set(cvi, vec[0]->xs_s1); @@ -285,7 +286,7 @@ xpath_list_optimize_fn(xpath_tree *xt, goto ok; xtp = vec[1]; if ((cvk = cvec_new(0)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_new"); + clixon_err(OE_YANG, errno, "cvec_new"); goto done; } if ((ret = loop_preds(xtp, xem, cvk)) < 0) diff --git a/lib/src/clixon_xpath_parse.l b/lib/src/clixon_xpath_parse.l index 3e81b4be..6fb08176 100644 --- a/lib/src/clixon_xpath_parse.l +++ b/lib/src/clixon_xpath_parse.l @@ -73,6 +73,7 @@ There are some special lexical rules in https://www.w3.org/TR/xpath-10 #include "clixon_handle.h" #include "clixon_yang.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_string.h" #include "clixon_xml.h" #include "clixon_xpath_ctx.h" diff --git a/lib/src/clixon_xpath_parse.y b/lib/src/clixon_xpath_parse.y index 9ffa2c35..772d43e0 100644 --- a/lib/src/clixon_xpath_parse.y +++ b/lib/src/clixon_xpath_parse.y @@ -98,7 +98,7 @@ /* typecast macro */ #define _XPY ((clixon_xpath_yacc *)_xpy) -#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_xpath_parsetext, _XPY->xpy_linenum); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_xpath_parsetext, _XPY->xpy_linenum); YYERROR;} /* add _yy to error parameters */ #define YY_(msgid) msgid @@ -118,12 +118,13 @@ #include +#include "clixon_queue.h" +#include "clixon_hash.h" +#include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" -#include "clixon_queue.h" +#include "clixon_debug.h" #include "clixon_string.h" -#include "clixon_hash.h" -#include "clixon_handle.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xpath_ctx.h" @@ -157,7 +158,7 @@ clixon_xpath_parseerror(void *_xpy, char *s) { errno = 0; - clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", /* Note lineno here is xpath, not yang */ + clixon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", /* Note lineno here is xpath, not yang */ _XPY->xpy_name, _XPY->xpy_linenum, s, @@ -168,7 +169,6 @@ clixon_xpath_parseerror(void *_xpy, int xpath_parse_init(clixon_xpath_yacc *xpy) { - // clixon_debug_init(3, NULL); return 0; } @@ -200,7 +200,7 @@ xp_new(enum xp_type type, xpath_tree *xs = NULL; if ((xs = malloc(sizeof(xpath_tree))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(xs, 0, sizeof(*xs)); @@ -209,7 +209,7 @@ xp_new(enum xp_type type, if (numstr){ xs->xs_strnr = numstr; if (sscanf(numstr, "%lf", &xs->xs_double) == EOF){ - clicon_err(OE_XML, errno, "sscanf"); + clixon_err(OE_XML, errno, "sscanf"); goto done; } } @@ -242,7 +242,7 @@ xp_primary_function(clixon_xpath_yacc *xpy, if ((ret = xp_fnname_str2int(name)) < 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath function \"%s\"", name); @@ -273,7 +273,7 @@ xp_primary_function(clixon_xpath_yacc *xpy, case XPATHFN_CEILING: case XPATHFN_ROUND: if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "XPath function \"%s\" is not implemented", name); @@ -296,7 +296,7 @@ xp_primary_function(clixon_xpath_yacc *xpy, break; default: if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath function \"%s\"", name); @@ -334,7 +334,7 @@ xp_nodetest_function(clixon_xpath_yacc *xpy, if ((ret = xp_fnname_str2int(name)) < 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath function \"%s\"", name); @@ -346,7 +346,7 @@ xp_nodetest_function(clixon_xpath_yacc *xpy, case XPATHFN_COMMENT: /* Group of not implemented node functions */ case XPATHFN_PROCESSING_INSTRUCTIONS: if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "XPath function \"%s\" is not implemented", name); @@ -358,7 +358,7 @@ xp_nodetest_function(clixon_xpath_yacc *xpy, break; default: if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath nodetest function \"%s\"", name); @@ -391,7 +391,7 @@ xp_axisname_function(clixon_xpath_yacc *xpy, if ((fn = axis_type_str2int(name)) < 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "Unknown xpath axisname \"%s\"", name); diff --git a/lib/src/clixon_xpath_yang.c b/lib/src/clixon_xpath_yang.c index 9f6c7068..2744ccad 100644 --- a/lib/src/clixon_xpath_yang.c +++ b/lib/src/clixon_xpath_yang.c @@ -53,13 +53,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_nsctx.h" @@ -88,7 +89,7 @@ xy_dup(xp_yang_ctx *xy0) xp_yang_ctx *xy = NULL; if ((xy = malloc(sizeof(*xy))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } memset(xy, 0, sizeof(*xy)); @@ -159,7 +160,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0, switch (xptree->xs_int){ case A_CHILD: if ((nodetest = xptree->xs_c0) == NULL){ - clicon_err(OE_YANG, 0, "child step nodetest expected"); + clixon_err(OE_YANG, 0, "child step nodetest expected"); goto done; } switch (nodetest->xs_type){ @@ -187,7 +188,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0, case XP_NODE_FN: break; default: - clicon_err(OE_YANG, 0, "Invalid xpath-tree nodetest: %s", + clixon_err(OE_YANG, 0, "Invalid xpath-tree nodetest: %s", xpath_tree_int2str(nodetest->xs_type)); goto done; break; @@ -197,7 +198,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0, xy->xy_node = yang_parent_get(ys); break; default: - clicon_err(OE_YANG, 0, "Invalid path-arg step: %s", + clixon_err(OE_YANG, 0, "Invalid path-arg step: %s", axis_type_int2str(xptree->xs_int)); goto done; break; @@ -298,7 +299,7 @@ xp_yang_eval(xp_yang_ctx *xy, case XP_ADD: case XP_UNION: if (xptree->xs_c1 != NULL){ - clicon_err(OE_XML, 0, "Function %s having two args is invalid for path-arg", xptree->xs_s0); + clixon_err(OE_XML, 0, "Function %s having two args is invalid for path-arg", xptree->xs_s0); goto done; } break; @@ -322,7 +323,7 @@ xp_yang_eval(xp_yang_ctx *xy, goto ok; break; default: - clicon_err(OE_XML, 0, "Function %s invalid for path-arg", xptree->xs_s0); + clixon_err(OE_XML, 0, "Function %s invalid for path-arg", xptree->xs_s0); goto done; } } @@ -350,7 +351,7 @@ xp_yang_eval(xp_yang_ctx *xy, goto ok; /* Skip generic child traverse */ break; default: /* Here we explicitly fail on node types for those not appearing in path-arg */ - clicon_err(OE_YANG, 0, "Invalid xpath-tree node name: %s", + clixon_err(OE_YANG, 0, "Invalid xpath-tree node name: %s", xpath_tree_int2str(xptree->xs_type)); goto done; break; @@ -387,7 +388,7 @@ xp_yang_eval(xp_yang_ctx *xy, case XP_RELEX: /* relexpr --> addexpr | relexpr relop addexpr */ /* Check op: only EQ allowed in path-arg */ if (xptree->xs_int != XO_EQ){ - clicon_err(OE_YANG, 0, "Invalid xpath-tree relational operator: %d, only eq allowed", + clixon_err(OE_YANG, 0, "Invalid xpath-tree relational operator: %d, only eq allowed", xptree->xs_int); goto done; } @@ -404,7 +405,7 @@ xp_yang_eval(xp_yang_ctx *xy, goto done; } else { - clicon_err(OE_XML, EFAULT, "Internal error: no result produced"); + clixon_err(OE_XML, EFAULT, "Internal error: no result produced"); goto done; } } @@ -472,7 +473,7 @@ yang_path_arg(yang_stmt *ys, clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (path_arg == NULL){ - clicon_err(OE_XML, EINVAL, "path-arg is NULL"); + clixon_err(OE_XML, EINVAL, "path-arg is NULL"); goto done; } if (xpath_parse(path_arg, &xptree) < 0) diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index d071ed4e..2976e5c1 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -63,13 +63,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_log.h" -#include "clixon_err.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_err.h" #include "clixon_file.h" #include "clixon_yang.h" #include "clixon_hash.h" @@ -88,7 +89,7 @@ #include "clixon_yang_internal.h" /* internal included by this file only, not API*/ #ifdef XML_EXPLICIT_INDEX -static int yang_search_index_extension(clicon_handle h, yang_stmt *yext, yang_stmt *ys); +static int yang_search_index_extension(clixon_handle h, yang_stmt *yext, yang_stmt *ys); #endif /* @@ -329,17 +330,17 @@ yang_cvec_add(yang_stmt *ys, if ((cvv = yang_cvec_get(ys)) == NULL){ if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_new"); + clixon_err(OE_YANG, errno, "cvec_new"); return NULL; } yang_cvec_set(ys, cvv); } if ((cv = cvec_add(cvv, type)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_add"); + clixon_err(OE_YANG, errno, "cvec_add"); return NULL; } if (cv_name_set(cv, name) == NULL){ - clicon_err(OE_YANG, errno, "cv_name_set(%s)", name); + clixon_err(OE_YANG, errno, "cv_name_set(%s)", name); return NULL; } return cv; @@ -380,7 +381,7 @@ yang_ref_dec(yang_stmt *ys) int retval = -1; if (ys->ys_ref <= 0){ - clicon_err(OE_YANG, 0, "reference count is %d cannot decrement", ys->ys_ref); + clixon_err(OE_YANG, 0, "reference count is %d cannot decrement", ys->ys_ref); goto done; } ys->ys_ref--; @@ -460,11 +461,11 @@ yang_when_xpath_set(yang_stmt *ys, int retval = -1; if (xpath == NULL){ - clicon_err(OE_YANG, EINVAL, "xpath is NULL"); + clixon_err(OE_YANG, EINVAL, "xpath is NULL"); goto done; } if ((ys->ys_when_xpath = strdup(xpath)) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } retval = 0; @@ -502,7 +503,7 @@ yang_when_nsc_set(yang_stmt *ys, int retval = -1; if (nsc && (ys->ys_when_nsc = cvec_dup(nsc)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_dup"); + clixon_err(OE_YANG, errno, "cvec_dup"); goto done; } retval = 0; @@ -535,7 +536,7 @@ yang_filename_set(yang_stmt *ys, const char *filename) { if ((ys->ys_filename = strdup(filename)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); return -1; } return 0; @@ -642,7 +643,7 @@ yang_stats(yang_stmt *yt, yang_stmt *ys; if (yt == NULL){ - clicon_err(OE_XML, EINVAL, "yang spec is NULL"); + clixon_err(OE_XML, EINVAL, "yang spec is NULL"); goto done; } *nrp += 1; @@ -674,7 +675,7 @@ yspec_new(void) yang_stmt *yspec; if ((yspec = malloc(sizeof(*yspec))) == NULL){ - clicon_err(OE_YANG, errno, "malloc"); + clixon_err(OE_YANG, errno, "malloc"); return NULL; } memset(yspec, 0, sizeof(*yspec)); @@ -694,7 +695,7 @@ ys_new(enum rfc_6020 keyw) yang_stmt *ys; if ((ys = malloc(sizeof(*ys))) == NULL){ - clicon_err(OE_YANG, errno, "malloc"); + clixon_err(OE_YANG, errno, "malloc"); return NULL; } memset(ys, 0, sizeof(*ys)); @@ -881,7 +882,7 @@ yn_realloc(yang_stmt *yn) yn->ys_len++; if ((yn->ys_stmt = realloc(yn->ys_stmt, (yn->ys_len)*sizeof(yang_stmt *))) == 0){ - clicon_err(OE_YANG, errno, "realloc"); + clixon_err(OE_YANG, errno, "realloc"); return -1; } yn->ys_stmt[yn->ys_len - 1] = NULL; /* init field */ @@ -916,25 +917,25 @@ ys_cp(yang_stmt *ynew, ynew->ys_parent = NULL; if (yold->ys_stmt) if ((ynew->ys_stmt = calloc(yold->ys_len, sizeof(yang_stmt *))) == NULL){ - clicon_err(OE_YANG, errno, "calloc"); + clixon_err(OE_YANG, errno, "calloc"); goto done; } if (yold->ys_argument) if ((ynew->ys_argument = strdup(yold->ys_argument)) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } yang_cv_set(ynew, NULL); if ((cvo = yang_cv_get(yold)) != NULL){ if ((cvn = cv_dup(cvo)) == NULL){ - clicon_err(OE_YANG, errno, "cv_dup"); + clixon_err(OE_YANG, errno, "cv_dup"); goto done; } yang_cv_set(ynew, cvn); } if (yold->ys_cvec) if ((ynew->ys_cvec = cvec_dup(yold->ys_cvec)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_dup"); + clixon_err(OE_YANG, errno, "cvec_dup"); goto done; } if (yold->ys_typecache){ @@ -944,12 +945,12 @@ ys_cp(yang_stmt *ynew, } if (yold->ys_when_xpath) if ((ynew->ys_when_xpath = strdup(yold->ys_when_xpath)) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } if (yold->ys_when_nsc){ if ((ynew->ys_when_nsc = cvec_dup(yold->ys_when_nsc)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_dup"); + clixon_err(OE_YANG, errno, "cvec_dup"); goto done; } } @@ -1364,11 +1365,11 @@ yang_find_myprefix(yang_stmt *ys) if (ys_real_module(ys, &ymod) < 0) goto done; if (ymod == NULL){ - clicon_err(OE_YANG, ENOENT, "Internal error: no module"); + clixon_err(OE_YANG, ENOENT, "Internal error: no module"); goto done; } if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod)); + clixon_err(OE_YANG, ENOENT, "No prefix found for module %s", yang_argument_get(ymod)); goto done; } prefix = yang_argument_get(yprefix); @@ -1396,7 +1397,7 @@ yang_find_mynamespace(yang_stmt *ys) if (ys_real_module(ys, &ymod) < 0) goto done; if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod)); + clixon_err(OE_YANG, ENOENT, "No namespace found for module %s", yang_argument_get(ymod)); goto done; } ns = yang_argument_get(ynamespace); @@ -1441,7 +1442,7 @@ yang_find_prefix_by_namespace(yang_stmt *ys, clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__); if (prefix == NULL){ - clicon_err(OE_YANG, EINVAL, "prefix is NULL"); + clixon_err(OE_YANG, EINVAL, "prefix is NULL"); goto done; } /* First check if namespace is my own module */ @@ -1503,7 +1504,7 @@ yang_find_namespace_by_prefix(yang_stmt *ys, yang_stmt *ym; if (ns == NULL){ - clicon_err(OE_YANG, EINVAL, "ns is NULL"); + clixon_err(OE_YANG, EINVAL, "ns is NULL"); goto done; } if ((ym = yang_find_module_by_prefix(ys, prefix)) == NULL) @@ -1735,7 +1736,7 @@ yang_order(yang_stmt *y) } } if (yang_order1(yp, y, &j) < 0){ - clicon_err(OE_YANG, 0, "YANG node %s not ordered: not found", yang_argument_get(y)); + clixon_err(OE_YANG, 0, "YANG node %s not ordered: not found", yang_argument_get(y)); goto done; } retval = tot + j; @@ -1863,22 +1864,22 @@ ys_real_module(yang_stmt *ys, yang_stmt *yspec; if (ymod == NULL){ - clicon_err(OE_YANG, EINVAL, "ymod is NULL"); + clixon_err(OE_YANG, EINVAL, "ymod is NULL"); goto done; } if ((ym = ys_module(ys)) != NULL){ yspec = ys_spec(ym); while (ym && yang_keyword_get(ym) == Y_SUBMODULE){ if ((yb = yang_find(ym, Y_BELONGS_TO, NULL)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */ + clixon_err(OE_YANG, ENOENT, "No belongs-to statement of submodule %s", yang_argument_get(ym)); /* shouldnt happen */ goto done; } if ((name = yang_argument_get(yb)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */ + clixon_err(OE_YANG, ENOENT, "Belongs-to statement of submodule %s has no argument", yang_argument_get(ym)); /* shouldnt happen */ goto done; } if ((ysubm = yang_find_module_by_name(yspec, name)) == NULL){ - clicon_err(OE_YANG, ENOENT, "submodule %s references non-existent module %s in its belongs-to statement", + clixon_err(OE_YANG, ENOENT, "submodule %s references non-existent module %s in its belongs-to statement", yang_argument_get(ym), name); goto done; } @@ -1944,7 +1945,7 @@ yang_print_cb(FILE *f, cbuf *cb = NULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_YANG, errno, "cbuf_new"); + clixon_err(OE_YANG, errno, "cbuf_new"); goto done; } if (yang_print_cbuf(cb, yn, 0, 1) < 0) @@ -1984,7 +1985,7 @@ yang_spec_print(FILE *f, yang_stmt *yrev; if (yspec == NULL || yang_keyword_get(yspec) != Y_SPEC){ - clicon_err(OE_YANG, EINVAL, "yspec is not of type YSPEC"); + clixon_err(OE_YANG, EINVAL, "yspec is not of type YSPEC"); return -1; } while ((ym = yn_each(yspec, ym)) != NULL) { @@ -2013,7 +2014,7 @@ yang_spec_dump(yang_stmt *yspec, cbuf *cb = NULL; if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_YANG, errno, "cbuf_new"); + clixon_err(OE_YANG, errno, "cbuf_new"); goto done; } while ((ym = yn_each(yspec, ym)) != NULL) { @@ -2060,7 +2061,7 @@ yang_print_cbuf(cbuf *cb, char *arg; if (yn == NULL || cb == NULL){ - clicon_err(OE_YANG, EINVAL, "cb or yn is NULL"); + clixon_err(OE_YANG, EINVAL, "cb or yn is NULL"); goto done; } keyw = yang_keyword_get(yn); @@ -2128,7 +2129,7 @@ yang_deviation(yang_stmt *ys, yang_stmt *yc1; yang_stmt *ytc; char *devop; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; enum rfc_6020 kw; int min; int max; @@ -2137,17 +2138,17 @@ yang_deviation(yang_stmt *ys, goto ok; /* Absolute schema node identifier identifying target node */ if ((nodeid = yang_argument_get(ys)) == NULL){ - clicon_err(OE_YANG, EINVAL, "No argument to deviation"); + clixon_err(OE_YANG, EINVAL, "No argument to deviation"); goto done; } /* Get target node */ if (yang_abs_schema_nodeid(ys, nodeid, &ytarget) < 0) goto done; if (ytarget == NULL){ - clicon_log(LOG_WARNING, "deviation %s: target not found", nodeid); + clixon_log(h, LOG_WARNING, "deviation %s: target not found", nodeid); goto ok; /* The RFC does not explicitly say the target node MUST exist - clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid); + clixon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid); goto done; */ } @@ -2178,7 +2179,7 @@ yang_deviation(yang_stmt *ys, &max) < 0) goto done; if (max == 1){ - clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" added but node already exist in target %s", + clixon_err(OE_YANG, 0, "deviation %s: \"%s %s\" added but node already exist in target %s", nodeid, yang_key2str(kw), yang_argument_get(yc), yang_argument_get(ytarget)); @@ -2203,7 +2204,7 @@ yang_deviation(yang_stmt *ys, break; default: if (ytc == NULL){ - clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s", + clixon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s", nodeid, yang_key2str(kw), yang_argument_get(yc), yang_argument_get(ytarget)); @@ -2233,7 +2234,7 @@ yang_deviation(yang_stmt *ys, * target node. */ kw = yang_keyword_get(yc); if ((ytc = yang_find(ytarget, kw, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s", + clixon_err(OE_YANG, 0, "deviation %s: \"%s %s\" replaced but node does not exist in target %s", nodeid, yang_key2str(kw), yang_argument_get(yc), yang_argument_get(ytarget)); @@ -2246,7 +2247,7 @@ yang_deviation(yang_stmt *ys, } } else{ /* Shouldnt happen, lex/yacc takes it */ - clicon_err(OE_YANG, EINVAL, "%s: invalid deviate operator", devop); + clixon_err(OE_YANG, EINVAL, "%s: invalid deviate operator", devop); goto done; } } @@ -2268,10 +2269,10 @@ yang_deviation(yang_stmt *ys, * @param[in] h Clixon handle * @param[in] ys The yang statement to populate. * @retval 0 OK - * @retval -1 Error with clicon_err called + * @retval -1 Error with clixon_err called */ static int -ys_populate_leaf(clicon_handle h, +ys_populate_leaf(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -2298,14 +2299,14 @@ ys_populate_leaf(clicon_handle h, goto done; /* 2. Create the CV using cvtype and name it */ if ((cv = cv_new(cvtype)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } if (options & YANG_OPTIONS_FRACTION_DIGITS && cvtype == CGV_DEC64) /* XXX: Seems misplaced? / too specific */ cv_dec64_n_set(cv, fraction_digits); if (cv_name_set(cv, ys->ys_argument) == NULL){ - clicon_err(OE_YANG, errno, "cv_name_set"); + clixon_err(OE_YANG, errno, "cv_name_set"); goto done; } /* get parent of where type is defined, can be original object */ @@ -2317,11 +2318,11 @@ ys_populate_leaf(clicon_handle h, */ if ((ydef = yang_find(ys, Y_DEFAULT, NULL)) != NULL){ if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */ - clicon_err(OE_YANG, errno, "parsing cv"); + clixon_err(OE_YANG, errno, "parsing cv"); goto done; } if (cvret == 0){ /* parsing failed */ - clicon_err(OE_YANG, errno, "Parsing CV: %s", reason); + clixon_err(OE_YANG, errno, "Parsing CV: %s", reason); free(reason); goto done; } @@ -2330,11 +2331,11 @@ ys_populate_leaf(clicon_handle h, else if (ytypedef != ys && (ydef = yang_find(ytypedef, Y_DEFAULT, NULL)) != NULL) { if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */ - clicon_err(OE_YANG, errno, "parsing cv"); + clixon_err(OE_YANG, errno, "parsing cv"); goto done; } if (cvret == 0){ /* parsing failed */ - clicon_err(OE_YANG, errno, "Parsing CV: %s", reason); + clixon_err(OE_YANG, errno, "Parsing CV: %s", reason); free(reason); goto done; } @@ -2366,7 +2367,7 @@ ys_populate_leaf(clicon_handle h, * @retval -1 Error */ static int -ys_populate_list(clicon_handle h, +ys_populate_list(clixon_handle h, yang_stmt *ys) { yang_stmt *ykey; @@ -2400,7 +2401,7 @@ bound_add(yang_stmt *ys, int ret = 1; if (ys == NULL){ - clicon_err(OE_YANG, EINVAL, "ys is NULL"); + clixon_err(OE_YANG, EINVAL, "ys is NULL"); goto done; } if ((cv = yang_cvec_add(ys, cvtype, name)) == NULL) @@ -2412,11 +2413,11 @@ bound_add(yang_stmt *ys, else if (strcmp(val, "max") == 0) cv_max_set(cv); else if ((ret = cv_parse1(val, cv, &reason)) < 0){ - clicon_err(OE_YANG, errno, "cv_parse1"); + clixon_err(OE_YANG, errno, "cv_parse1"); goto done; } if (ret == 0){ /* parsing failed */ - clicon_err(OE_YANG, errno, "range statement %s: %s", val, reason); + clixon_err(OE_YANG, errno, "range statement %s: %s", val, reason); free(reason); goto done; } @@ -2482,7 +2483,7 @@ range_parse(yang_stmt *ys, * ascending order */ static int -ys_populate_range(clicon_handle h, +ys_populate_range(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -2496,14 +2497,14 @@ ys_populate_range(clicon_handle h, yparent = ys->ys_parent; /* Find parent: type */ if (yparent->ys_keyword != Y_TYPE){ - clicon_err(OE_YANG, 0, "parent should be type"); + clixon_err(OE_YANG, 0, "parent should be type"); goto done; } if (yang_type_resolve(ys, ys, (yang_stmt*)yparent, &yrestype, &options, NULL, NULL, NULL, &fraction_digits) < 0) goto done; if (yrestype == NULL){ - clicon_err(OE_YANG, 0, "result-type should not be NULL"); + clixon_err(OE_YANG, 0, "result-type should not be NULL"); goto done; } restype = yrestype?yrestype->ys_argument:NULL; @@ -2513,7 +2514,7 @@ ys_populate_range(clicon_handle h, if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0) goto done; if (!cv_isint(cvtype) && cvtype != CGV_DEC64){ - clicon_err(OE_YANG, 0, "The range substatement only applies to int types, not to type: %s", origtype); + clixon_err(OE_YANG, 0, "The range substatement only applies to int types, not to type: %s", origtype); goto done; } if (range_parse(ys, cvtype, fraction_digits) < 0) @@ -2544,7 +2545,7 @@ ys_populate_range(clicon_handle h, * be disjoint and MUST be in ascending order. */ static int -ys_populate_length(clicon_handle h, +ys_populate_length(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -2553,7 +2554,7 @@ ys_populate_length(clicon_handle h, yparent = ys->ys_parent; /* Find parent: type */ if (yparent->ys_keyword != Y_TYPE){ - clicon_err(OE_YANG, 0, "parent should be type"); + clixon_err(OE_YANG, 0, "parent should be type"); goto done; } cvtype = CGV_UINT64; @@ -2573,7 +2574,7 @@ ys_populate_length(clicon_handle h, * @retval -1 Error */ static int -ys_populate_type(clicon_handle h, +ys_populate_type(clixon_handle h, yang_stmt *ys) { @@ -2582,18 +2583,18 @@ ys_populate_type(clicon_handle h, if (strcmp(ys->ys_argument, "decimal64") == 0){ if (yang_find(ys, Y_FRACTION_DIGITS, NULL) == NULL){ - clicon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement"); + clixon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement"); goto done; } } else if (strcmp(ys->ys_argument, "identityref") == 0){ if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "identityref type requires base sub-statement"); + clixon_err(OE_YANG, 0, "identityref type requires base sub-statement"); goto done; } if ((yang_find_identity(ys, ybase->ys_argument)) == NULL){ - clicon_err(OE_YANG, 0, "Identity %s not found (base type of %s)", + clixon_err(OE_YANG, 0, "Identity %s not found (base type of %s)", ybase->ys_argument, ys->ys_argument); goto done; } @@ -2617,7 +2618,7 @@ ys_populate_type(clicon_handle h, * @see validate_identityref which in runtime validates actual values */ static int -ys_populate_identity(clicon_handle h, +ys_populate_identity(clixon_handle h, yang_stmt *ys, char *idref) { @@ -2637,13 +2638,13 @@ ys_populate_identity(clicon_handle h, if (idref == NULL){ /* Create derived identity through prefix:id if not recursively called*/ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0) goto done; if ((ymod = ys_module(ys)) == NULL){ - clicon_err(OE_YANG, ENOENT, "No module found"); + clixon_err(OE_YANG, ENOENT, "No module found"); goto done; } cprintf(cb, "%s:%s", yang_argument_get(ymod), id); @@ -2658,7 +2659,7 @@ ys_populate_identity(clicon_handle h, continue; baseid = yang_argument_get(yc); /* on the form: prefix:id */ if (((ybaseid = yang_find_identity(ys, baseid))) == NULL){ - clicon_err(OE_YANG, ENOENT, "No such identity: %s", baseid); + clixon_err(OE_YANG, ENOENT, "No such identity: %s", baseid); goto done; } // continue; /* root identity */ @@ -2670,7 +2671,7 @@ ys_populate_identity(clicon_handle h, continue; /* Add derived id to ybaseid */ if (yang_cvec_add(ybaseid, CGV_STRING, idref) == NULL){ - clicon_err(OE_UNIX, errno, "cv_new"); + clixon_err(OE_UNIX, errno, "cv_new"); goto done; } /* Transitive to the root */ @@ -2724,7 +2725,7 @@ if_feature(yang_stmt *yspec, * Bootstrapping: A feature is enabled if found in clixon-config */ int -ys_populate_feature(clicon_handle h, +ys_populate_feature(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -2744,7 +2745,7 @@ ys_populate_feature(clicon_handle h, if ((x = clicon_conf_xml(h)) == NULL) goto ok; if ((ymod = ys_module(ys)) == NULL){ - clicon_err(OE_YANG, 0, "module not found"); + clixon_err(OE_YANG, 0, "module not found"); goto done; } module = ymod->ys_argument; @@ -2769,7 +2770,7 @@ ys_populate_feature(clicon_handle h, if (f) free(f); } if ((cv = cv_new(CGV_BOOL)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } cv_name_set(cv, feature); @@ -2791,7 +2792,7 @@ ys_populate_feature(clicon_handle h, * @retval -1 Error */ static int -ys_populate_unique(clicon_handle h, +ys_populate_unique(clixon_handle h, yang_stmt *ys) { cvec *cvv; @@ -2827,7 +2828,7 @@ ys_populate_unique(clicon_handle h, * @see yang_extension_value Called on expanded YANG, eg in context of (y2) */ static int -ys_populate_unknown(clicon_handle h, +ys_populate_unknown(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -2843,13 +2844,13 @@ ys_populate_unknown(clicon_handle h, if (nodeid_split(yang_argument_get(ys), &prefix, &id) < 0) goto done; if ((ymod = yang_find_module_by_prefix(ys, prefix)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id); + clixon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id); goto done; } /* To find right binding eg after grouping/uses */ ys->ys_mymodule = ys_module(ys); if ((yext = yang_find(ymod, Y_EXTENSION, id)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id); + clixon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id); goto done; } /* Optional argument (only if "argument") - save it in ys_cv */ @@ -2857,7 +2858,7 @@ ys_populate_unknown(clicon_handle h, (argument = cv_string_get(cv)) != NULL){ if (yang_find(yext, Y_ARGUMENT, NULL) == NULL && argument != NULL){ - clicon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument); + clixon_err(OE_YANG, 0, "No argument specified in extension %s, but argument %s present when used", yang_argument_get(ys), argument); goto done; } } @@ -2899,7 +2900,7 @@ ys_populate_unknown(clicon_handle h, * @retval -1 Error */ static int -ys_populate_module_submodule(clicon_handle h, +ys_populate_module_submodule(clixon_handle h, yang_stmt *ym) { int retval = -1; @@ -2920,7 +2921,7 @@ ys_populate_module_submodule(clicon_handle h, yp = yang_find(yi, Y_PREFIX, NULL); pi = yang_argument_get(yp); if (p0 && strcmp(p0, pi) == 0){ /* Check top-level */ - clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)", + clixon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)", pi, yang_argument_get(ym)); goto done; } @@ -2932,7 +2933,7 @@ ys_populate_module_submodule(clicon_handle h, yp = yang_find(yi2, Y_PREFIX, NULL); pi2 = yang_argument_get(yp); if (strcmp(pi2, pi) == 0){ - clicon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)", + clixon_err(OE_YANG, EFAULT, "Prefix %s in module %s is not unique but should be (see RFC 7950 7.1.4)", pi, yang_argument_get(ym)); goto done; } @@ -2963,7 +2964,7 @@ ys_populate(yang_stmt *ys, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; switch(ys->ys_keyword){ case Y_IDENTITY: @@ -3016,7 +3017,7 @@ ys_populate2(yang_stmt *ys, void *arg) { int retval = -1; - clicon_handle h = (clicon_handle)arg; + clixon_handle h = (clixon_handle)arg; int ret; switch(ys->ys_keyword){ @@ -3056,7 +3057,7 @@ ys_populate2(yang_stmt *ys, * @note if-features is parsed in full context here, previous restricted pass in ys_parse_sub */ int -yang_features(clicon_handle h, +yang_features(clixon_handle h, yang_stmt *yt) { int retval = -1; @@ -3212,7 +3213,7 @@ yang_datanode(yang_stmt *ys) * @param[in] nsc Namespace context from yang for the prefixes (names) of cvv * @param[out] yres Result yang statement node, or NULL if not found * @retval 0 OK - * @retval -1 Error, with clicon_err called + * @retval -1 Error, with clixon_err called * A schema node identifier consists of a path of identifiers, separated by slashes ("/"). * References to identifiers defined in external modules MUST be * qualified with appropriate prefixes, and references to identifiers @@ -3248,14 +3249,14 @@ schema_nodeid_iterate(yang_stmt *yn, * matching module below * Get namespace */ if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){ - clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier in module %s", + clixon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier in module %s", prefix, yang_argument_get(ys_module(yn))); goto done; } /* Get yang module */ if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){ - clicon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns); + clixon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns); goto done; } ys = yang_find_schemanode(yp, id); @@ -3296,7 +3297,7 @@ schema_nodeid_iterate(yang_stmt *yn, * @param[in] schema_nodeid Absolute schema-node-id, ie /a/b * @param[out] yres Result yang statement node, or NULL if not found * @retval 0 OK , with result in yres - * @retval -1 Error, with clicon_err called + * @retval -1 Error, with clixon_err called * Assume schema nodeid:s have prefixes, (actually the first). * @see RFC7950 6.5 * o schema node: A node in the schema tree. One of action, container, @@ -3321,13 +3322,13 @@ yang_abs_schema_nodeid(yang_stmt *yn, char *str; if ((yspec = ys_spec(yn)) == NULL){ - clicon_err(OE_YANG, EINVAL, "No yang spec"); + clixon_err(OE_YANG, EINVAL, "No yang spec"); goto done; } *yres = NULL; /* check absolute schema_nodeid */ if (schema_nodeid[0] != '/'){ - clicon_err(OE_YANG, EINVAL, "absolute schema nodeid should start with /"); + clixon_err(OE_YANG, EINVAL, "absolute schema nodeid should start with /"); goto done; } /* Split nodeid on the form /p0:i0/p1:i1 to a cvec with [name:p0 value:i0][...] @@ -3343,7 +3344,7 @@ yang_abs_schema_nodeid(yang_stmt *yn, cv_type_set(cv, CGV_STRING); if ((str = cv_string_get(cv)) == NULL || !strlen(str)){ if (cv_string_set(cv, cv_name_get(cv)) < 0){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); goto done; } cv_name_set(cv, NULL); @@ -3361,13 +3362,13 @@ yang_abs_schema_nodeid(yang_stmt *yn, cv = cvec_i(nodeid_cvv, 0); prefix = cv_name_get(cv); if ((ns = xml_nsctx_get(nsc, prefix)) == NULL){ - clicon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier: %s", + clixon_err(OE_YANG, EFAULT, "No namespace for prefix: %s in schema node identifier: %s", prefix, schema_nodeid); goto done; } /* Get yang module */ if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL){ - clicon_err(OE_YANG, EFAULT, "No module for namespace: %s in schema node identifier: %s", + clixon_err(OE_YANG, EFAULT, "No module for namespace: %s in schema node identifier: %s", ns, schema_nodeid); goto done; } @@ -3392,7 +3393,7 @@ yang_abs_schema_nodeid(yang_stmt *yn, * @param[in] ns Namespace context * @param[out] yres First yang node matching schema nodeid * @retval 0 OK - * @retval -1 Error, with clicon_err called + * @retval -1 Error, with clixon_err called * Used in yang: unique, refine, uses augment * @see yang_abs_schema_nodeid */ @@ -3409,17 +3410,17 @@ yang_desc_schema_nodeid(yang_stmt *yn, cvec *nsc = NULL; if (schema_nodeid == NULL || strlen(schema_nodeid) == 0){ - clicon_err(OE_YANG, EINVAL, "nodeid is empty"); + clixon_err(OE_YANG, EINVAL, "nodeid is empty"); goto done; } if ((yspec = ys_spec(yn)) == NULL){ - clicon_err(OE_YANG, EINVAL, "No yang spec"); + clixon_err(OE_YANG, EINVAL, "No yang spec"); goto done; } *yres = NULL; /* check absolute schema_nodeid */ if (schema_nodeid[0] == '/'){ - clicon_err(OE_YANG, EINVAL, "descendant schema nodeid should not start with /"); + clixon_err(OE_YANG, EINVAL, "descendant schema nodeid should not start with /"); goto done; } /* Split nodeid on the form /p0:i0/p1:i1 to a cvec with [name:p0 value:i0][...] @@ -3435,7 +3436,7 @@ yang_desc_schema_nodeid(yang_stmt *yn, cv_type_set(cv, CGV_STRING); if ((str = cv_string_get(cv)) == NULL || !strlen(str)){ if (cv_string_set(cv, cv_name_get(cv)) < 0){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); goto done; } cv_name_set(cv, NULL); @@ -3549,14 +3550,14 @@ yang_arg2cvec(yang_stmt *ys, if ((vec = clicon_strsep(ys->ys_argument, " ", &nvec)) == NULL) goto done; if ((cvv = cvec_new(nvec)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_new"); + clixon_err(OE_YANG, errno, "cvec_new"); goto done; } for (i = 0; i < nvec; i++) { cv = cvec_i(cvv, i); cv_type_set(cv, CGV_STRING); if ((cv_string_set(cv, vec[i])) == NULL){ - clicon_err(OE_YANG, errno, "cv_string_set"); + clixon_err(OE_YANG, errno, "cv_string_set"); cvv = NULL; goto done; } @@ -3636,11 +3637,11 @@ yang_type_cache_set(yang_stmt *ys, yang_type_cache *ycache; if (ys->ys_typecache != NULL){ - clicon_err(OE_YANG, EEXIST, "yang type cache"); + clixon_err(OE_YANG, EEXIST, "yang type cache"); goto done; } if ((ys->ys_typecache = (yang_type_cache *)malloc(sizeof(*ycache))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); goto done; } ycache = ys->ys_typecache; @@ -3649,12 +3650,12 @@ yang_type_cache_set(yang_stmt *ys, ycache->yc_options = options; if (cvv){ if ((ycache->yc_cvv = cvec_dup(cvv)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } } if (patterns && (ycache->yc_patterns = cvec_dup(patterns)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } ycache->yc_fraction = fraction; @@ -3684,7 +3685,7 @@ yang_type_cache_regexp_set(yang_stmt *ytype, assert(ycache->yc_regexps == NULL); ycache->yc_rxmode = rxmode; if ((ycache->yc_regexps = cvec_dup(regexps)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_dup"); + clixon_err(OE_UNIX, errno, "cvec_dup"); goto done; } retval = 0; @@ -3758,7 +3759,7 @@ yang_type_cache_cp(yang_stmt *ynew, int ret; if ((patterns = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } /* Note, regexps are not copied since they are voids, if they were, they @@ -3792,7 +3793,7 @@ yang_type_cache_free(yang_type_cache *ycache) if (ycache->yc_regexps){ cv = NULL; while ((cv = cvec_each(ycache->yc_regexps, cv)) != NULL){ - /* need to store mode since clicon_handle is not available */ + /* need to store mode since clixon_handle is not available */ switch (ycache->yc_rxmode){ case REGEXP_POSIX: cligen_regex_posix_free(cv_void_get(cv)); @@ -3838,7 +3839,7 @@ yang_anydata_add(yang_stmt *yp, if ((ys = ys_new(Y_ANYDATA)) == NULL) goto done; if ((name = strdup(name0)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } yang_argument_set(ys, name); @@ -3887,13 +3888,13 @@ yang_extension_value(yang_stmt *ys, int ret; if (ys == NULL){ - clicon_err(OE_YANG, EINVAL, "ys is NULL"); + clixon_err(OE_YANG, EINVAL, "ys is NULL"); goto done; } if (exist) *exist = 0; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } yext = NULL; /* This loop gets complicated in the case the extension is augmented */ @@ -3973,7 +3974,7 @@ yang_sort_subelements(yang_stmt *ys) } int -yang_init(clicon_handle h) +yang_init(clixon_handle h) { return yang_cardinality_init(h); } @@ -3992,7 +3993,7 @@ yang_list_index_add(yang_stmt *ys) if ((yp = yang_parent_get(ys)) == NULL || yang_keyword_get(yp) != Y_LIST){ - clicon_log(LOG_WARNING, "search_index should in a list"); + clixon_log(NULL, LOG_WARNING, "search_index should in a list"); goto ok; } yang_flag_set(ys, YANG_FLAG_INDEX); @@ -4011,7 +4012,7 @@ yang_list_index_add(yang_stmt *ys) * @retval -1 Error */ int -yang_search_index_extension(clicon_handle h, +yang_search_index_extension(clixon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -4108,7 +4109,7 @@ yang_action_cb_add(yang_stmt *ys, rpc_callback_t *rc = (rpc_callback_t *)arg; if (rc == NULL){ - clicon_err(OE_YANG, EINVAL, "arg is NULL"); + clixon_err(OE_YANG, EINVAL, "arg is NULL"); return -1; } ADDQ(rc, ys->ys_action_cb); diff --git a/lib/src/clixon_yang_cardinality.c b/lib/src/clixon_yang_cardinality.c index bacfb89e..b55fe875 100644 --- a/lib/src/clixon_yang_cardinality.c +++ b/lib/src/clixon_yang_cardinality.c @@ -59,7 +59,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" @@ -483,7 +483,7 @@ static int _yc_exist[Y_SPEC] = {0,}; * @note always accept UNKNOWN (due to extension) */ int -yang_cardinality(clicon_handle h, +yang_cardinality(clixon_handle h, yang_stmt *yt, char *modname) { @@ -511,7 +511,7 @@ yang_cardinality(clicon_handle h, continue; /* Find entry in yang cardinality table from parent/child keyword pair */ if ((yc = _yc_search[pk][ck]) == NULL){ - clicon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be", + clixon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be", modname, yang_key2str(ck), yang_argument_get(ys), @@ -520,7 +520,7 @@ yang_cardinality(clicon_handle h, goto done; } if (order > yc->yc_order){ - clicon_err(OE_YANG, 0, "%s: yang node \"%s\"(%s) which is child of \"%s\"(%s) is not in correct order (should not be after \"%s\"(%s))", + clixon_err(OE_YANG, 0, "%s: yang node \"%s\"(%s) which is child of \"%s\"(%s) is not in correct order (should not be after \"%s\"(%s))", modname, yang_key2str(ck), yang_argument_get(ys), @@ -541,13 +541,13 @@ yang_cardinality(clicon_handle h, continue; if (yc->yc_min && yang_find(yt, yc->yc_child, NULL) == NULL){ - clicon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"", + clixon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"", modname, yang_key2str(yc->yc_child), yang_key2str(pk)); goto done; } if (yc->yc_maxyc_child, NULL)) > yc->yc_max){ - clicon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed", + clixon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed", modname, yang_key2str(pk), nr, @@ -580,7 +580,7 @@ yang_cardinality(clicon_handle h, * @retval -1 Error */ int -yang_cardinality_interval(clicon_handle h, +yang_cardinality_interval(clixon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, @@ -590,7 +590,7 @@ yang_cardinality_interval(clicon_handle h, const struct ycard *ycplist; /* ycard parent table*/ if ((ycplist = _yc_search[parent_key][child_key]) == NULL){ - clicon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality", + clixon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality", parent_key, child_key); goto done; } @@ -606,7 +606,7 @@ yang_cardinality_interval(clicon_handle h, * @param[in] h Clixon handle */ int -yang_cardinality_init(clicon_handle h) +yang_cardinality_init(clixon_handle h) { const struct ycard *yc; diff --git a/lib/src/clixon_yang_cardinality.h b/lib/src/clixon_yang_cardinality.h index 4ef3c7ef..bec502d5 100644 --- a/lib/src/clixon_yang_cardinality.h +++ b/lib/src/clixon_yang_cardinality.h @@ -38,8 +38,8 @@ /* * Prototypes */ -int yang_cardinality(clicon_handle h, yang_stmt *yt, char *modname); -int yang_cardinality_interval(clicon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, int *max); -int yang_cardinality_init(clicon_handle h); +int yang_cardinality(clixon_handle h, yang_stmt *yt, char *modname); +int yang_cardinality_interval(clixon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, int *max); +int yang_cardinality_init(clixon_handle h); #endif /* _CLIXON_YANG_CARDINALITY_H_ */ diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c index 52530546..f6087cb2 100644 --- a/lib/src/clixon_yang_module.c +++ b/lib/src/clixon_yang_module.c @@ -1,4 +1,4 @@ -/* + /* * ***** BEGIN LICENSE BLOCK ***** @@ -60,13 +60,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_log.h" -#include "clixon_err.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_err.h" #include "clixon_file.h" #include "clixon_yang.h" #include "clixon_xml.h" @@ -100,7 +101,7 @@ modstate_diff_new(void) modstate_diff_t *md; if ((md = malloc(sizeof(modstate_diff_t))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); + clixon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(md, 0, sizeof(modstate_diff_t)); @@ -135,7 +136,7 @@ modstate_diff_free(modstate_diff_t *md) * @see netconf_module_load */ int -yang_modules_init(clicon_handle h) +yang_modules_init(clixon_handle h) { int retval = -1; yang_stmt *yspec; @@ -145,7 +146,7 @@ yang_modules_init(clicon_handle h) goto ok; /* Ensure module-set-id is set */ if (!clicon_option_exists(h, "CLICON_MODULE_SET_ID")){ - clicon_err(OE_CFG, ENOENT, "CLICON_MODULE_SET_ID must be defined when CLICON_YANG_LIBRARY is enabled"); + clixon_err(OE_CFG, ENOENT, "CLICON_MODULE_SET_ID must be defined when CLICON_YANG_LIBRARY is enabled"); goto done; } /* Ensure revision exists is set */ @@ -153,7 +154,7 @@ yang_modules_init(clicon_handle h) goto done; /* Find revision */ if (yang_modules_revision(h) == NULL){ - clicon_err(OE_CFG, ENOENT, "Yang client library yang spec has no revision"); + clixon_err(OE_CFG, ENOENT, "Yang client library yang spec has no revision"); goto done; } ok: @@ -169,7 +170,7 @@ yang_modules_init(clicon_handle h) * @retval NULL Error: RFC7895 not loaded or revision not found */ char * -yang_modules_revision(clicon_handle h) +yang_modules_revision(clixon_handle h) { yang_stmt *yspec; yang_stmt *ymod; @@ -199,7 +200,7 @@ yang_modules_revision(clicon_handle h) * @see RFC8525 */ int -yang_modules_state_build(clicon_handle h, +yang_modules_state_build(clixon_handle h, yang_stmt *yspec, char *msid, int brief, @@ -220,11 +221,11 @@ yang_modules_state_build(clicon_handle h, if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL /* && (ylib = yang_find(yspec0, Y_SUBMODULE, module)) == NULL */ ){ - clicon_err(OE_YANG, 0, "%s not found", module); + clixon_err(OE_YANG, 0, "%s not found", module); goto done; } if ((yns = yang_find(ylib, Y_NAMESPACE, NULL)) == NULL){ - clicon_err(OE_YANG, 0, "%s yang namespace not found", module); + clixon_err(OE_YANG, 0, "%s yang namespace not found", module); goto done; } /* RFC 8525 */ @@ -319,7 +320,7 @@ x +--ro namespace inet:uri * @see netconf_hello_server */ int -yang_modules_state_get(clicon_handle h, +yang_modules_state_get(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, @@ -353,7 +354,7 @@ yang_modules_state_get(clicon_handle h, } else { /* No cache -> build the tree */ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, 0, "clicon buffer"); + clixon_err(OE_UNIX, 0, "clicon buffer"); goto done; } /* Build a cb string: ... */ @@ -363,7 +364,7 @@ yang_modules_state_get(clicon_handle h, * Note, list is not sorted since it is state (should not be) */ if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){ - if (xret && netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0) + if (xret && netconf_operation_failed_xml(xret, "protocol", clixon_err_reason())< 0) goto done; goto fail; } @@ -419,7 +420,7 @@ yang_modules_state_get(clicon_handle h, * @retval -1 Error */ static int -mod_ns_upgrade(clicon_handle h, +mod_ns_upgrade(clixon_handle h, cxobj *xt, cxobj *xmod, char *ns, @@ -479,7 +480,7 @@ mod_ns_upgrade(clicon_handle h, * @retval -1 Error */ int -clixon_module_upgrade(clicon_handle h, +clixon_module_upgrade(clixon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cbret) @@ -490,7 +491,7 @@ clixon_module_upgrade(clicon_handle h, int ret; if (msd == NULL){ - clicon_err(OE_CFG, EINVAL, "No modstate"); + clixon_err(OE_CFG, EINVAL, "No modstate"); goto done; } if (msd->md_status == 0) /* No modstate in startup */ @@ -542,12 +543,12 @@ yang_find_module_by_prefix(yang_stmt *ys, char *myprefix; if ((yspec = ys_spec(ys)) == NULL){ - clicon_err(OE_YANG, 0, "My yang spec not found"); + clixon_err(OE_YANG, 0, "My yang spec not found"); goto done; } /* First try own module */ if ((my_ymod = ys_module(ys)) == NULL){ - clicon_err(OE_YANG, 0, "My yang module not found"); + clixon_err(OE_YANG, 0, "My yang module not found"); goto done; } myprefix = yang_find_myprefix(ys); @@ -567,7 +568,7 @@ yang_find_module_by_prefix(yang_stmt *ys, } if (yimport){ if ((ymod = yang_find(yspec, Y_MODULE, yang_argument_get(yimport))) == NULL){ - clicon_err(OE_YANG, 0, "No module or sub-module found with prefix %s", + clixon_err(OE_YANG, 0, "No module or sub-module found with prefix %s", prefix); yimport = NULL; goto done; /* unresolved */ @@ -644,7 +645,7 @@ yang_find_module_by_namespace_revision(yang_stmt *yspec, char *rev1; if (ns == NULL || rev == NULL){ - clicon_err(OE_CFG, EINVAL, "No ns or rev"); + clixon_err(OE_CFG, EINVAL, "No ns or rev"); goto done; } while ((ymod = yn_each(yspec, ymod)) != NULL) { @@ -680,7 +681,7 @@ yang_find_module_by_name_revision(yang_stmt *yspec, char *rev1; if (name == NULL){ - clicon_err(OE_CFG, EINVAL, "No ns or rev"); + clixon_err(OE_CFG, EINVAL, "No ns or rev"); goto done; } while ((ymod = yn_each(yspec, ymod)) != NULL) { @@ -739,7 +740,7 @@ yang_find_module_by_name(yang_stmt *yspec, * @see yang_metadata_annotation_check */ static int -ietf_yang_metadata_extension_cb(clicon_handle h, +ietf_yang_metadata_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys) { @@ -816,7 +817,7 @@ yang_metadata_annotation_check(cxobj *xa, * @retval -1 Error */ int -yang_metadata_init(clicon_handle h) +yang_metadata_init(clixon_handle h) { int retval = -1; clixon_plugin_t *cp = NULL; @@ -847,7 +848,7 @@ yang_metadata_init(clicon_handle h) * XXX: Ensure yang-lib is always there otherwise get state dont work for mountpoint */ int -yang_lib2yspec(clicon_handle h, +yang_lib2yspec(clixon_handle h, cxobj *xyanglib, yang_stmt *yspec) { diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y index 3f962d95..9383aa4c 100644 --- a/lib/src/clixon_yang_parse.y +++ b/lib/src/clixon_yang_parse.y @@ -193,6 +193,7 @@ #include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_yang_parse_lib.h" #include "clixon_yang_parse.h" @@ -219,7 +220,7 @@ void clixon_yang_parseerror(void *_yy, char *s) { - clicon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'", + clixon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'", _YY->yy_name, _YY->yy_linenum, s, @@ -252,7 +253,7 @@ ystack_pop(clixon_yang_yacc *yy) struct ys_stack *ystack; if ((ystack = yy->yy_stack) == NULL){ - clicon_err(OE_YANG, 0, "ystack is NULL"); + clixon_err(OE_YANG, 0, "ystack is NULL"); return -1; } if (yang_sort_subelements(ystack->ys_node) < 0) @@ -274,7 +275,7 @@ ystack_push(clixon_yang_yacc *yy, struct ys_stack *ystack; if ((ystack = malloc(sizeof(*ystack))) == NULL) { - clicon_err(OE_YANG, errno, "malloc"); + clixon_err(OE_YANG, errno, "malloc"); return NULL; } memset(ystack, 0, sizeof(*ystack)); @@ -305,11 +306,11 @@ ysp_add(clixon_yang_yacc *yy, ystack = yy->yy_stack; if (ystack == NULL){ - clicon_err(OE_YANG, errno, "No stack"); + clixon_err(OE_YANG, errno, "No stack"); goto err; } if ((yn = ystack->ys_node) == NULL){ - clicon_err(OE_YANG, errno, "No ys_node"); + clixon_err(OE_YANG, errno, "No ys_node"); goto err; } if ((ys = ys_new(keyword)) == NULL) diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index 320094e4..d42bd7ce 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -74,13 +74,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_log.h" -#include "clixon_err.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_err.h" #include "clixon_file.h" #include "clixon_yang.h" #include "clixon_hash.h" @@ -154,7 +155,7 @@ ys_grouping_module_resolve(yang_stmt *ymod, * @param[in] name Name of grouping to look for * @param[out] ygrouping0 A found grouping yang structure as result * @retval 0 OK, ygrouping may be NULL - * @retval -1 Error, with clicon_err called + * @retval -1 Error, with clixon_err called */ int ys_grouping_resolve(yang_stmt *yuses, @@ -222,7 +223,7 @@ ys_grouping_resolve(yang_stmt *yuses, * a special "when" struct to the yang statements being inserted. */ static int -yang_augment_node(clicon_handle h, +yang_augment_node(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -238,7 +239,7 @@ yang_augment_node(clicon_handle h, enum rfc_6020 childkey; if ((ymod = ys_module(ys)) == NULL){ - clicon_err(OE_YANG, 0, "My yang module not found"); + clixon_err(OE_YANG, 0, "My yang module not found"); goto done; } schema_nodeid = yang_argument_get(ys); @@ -252,7 +253,7 @@ yang_augment_node(clicon_handle h, /* Log a warning and proceed if augment target not found * This may be necessary with some broken models */ - clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found", + clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found", yang_argument_get(ys_module(ys)), schema_nodeid); goto ok; @@ -261,7 +262,7 @@ yang_augment_node(clicon_handle h, /* Fail with fatal error if augment target not found * This is "correct" */ - clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found", + clixon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found", yang_argument_get(ys_module(ys)), schema_nodeid); goto done; @@ -302,7 +303,7 @@ yang_augment_node(clicon_handle h, /* Special case if yc0 is disabled by if-feature=false, then it is transformed to ANYDATA */ if (yang_flag_get(yc0, YANG_FLAG_DISABLED) == 0) - clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)", + clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)", yang_argument_get(ys_module(ys)), yang_argument_get(yc0), yang_key2str(childkey), @@ -321,7 +322,7 @@ yang_augment_node(clicon_handle h, if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST && childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE && childkey != Y_UNKNOWN){ - clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s", + clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s", yang_argument_get(ys_module(ys)), yang_key2str(childkey), childkey, @@ -342,7 +343,7 @@ yang_augment_node(clicon_handle h, childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST && childkey != Y_LEAF_LIST){ - clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s", + clixon_log(h, LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s", yang_argument_get(ys_module(ys)), yang_key2str(childkey), childkey, @@ -398,7 +399,7 @@ yang_augment_node(clicon_handle h, * another module not yet augmented. */ static int -yang_augment_module(clicon_handle h, +yang_augment_module(clixon_handle h, yang_stmt *ymod) { @@ -558,7 +559,7 @@ yang_expand_uses_node(yang_stmt *yn, if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0) goto done; if (ygrouping == NULL){ - clicon_log(LOG_NOTICE, "%s: Yang error : grouping \"%s\" not found in module \"%s\"", + clixon_log(NULL, LOG_NOTICE, "%s: Yang error : grouping \"%s\" not found in module \"%s\"", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys))); goto done; } @@ -567,7 +568,7 @@ yang_expand_uses_node(yang_stmt *yn, yp = yn; do { if (yp == ygrouping){ - clicon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself", + clixon_err(OE_YANG, EFAULT, "Yang use of grouping %s in module %s is defined inside the grouping (recursion), see RFC 7950 Sec 7.12: A grouping MUST NOT reference itself", yang_argument_get(ys), yang_argument_get(ys_module(yn)) ); @@ -609,7 +610,7 @@ yang_expand_uses_node(yang_stmt *yn, size = (yang_len_get(yn) - i - 1)*sizeof(struct yang_stmt *); yn->ys_len += glen; if ((yn->ys_stmt = realloc(yn->ys_stmt, (yang_len_get(yn))*sizeof(yang_stmt *))) == 0){ - clicon_err(OE_YANG, errno, "realloc"); + clixon_err(OE_YANG, errno, "realloc"); goto done; } /* Here, glen last elements are not initialized. @@ -676,7 +677,7 @@ yang_expand_uses_node(yang_stmt *yn, * If a key leaf is defined in a grouping that is used in a list, the * "uses" statement MUST NOT have a "when" statement. */ - clicon_err(OE_YANG, 0, "Key leaf '%s' defined in grouping '%s' is used in a 'uses' statement, This is not allowed according to RFC 7950 Sec 7.21.5", + clixon_err(OE_YANG, 0, "Key leaf '%s' defined in grouping '%s' is used in a 'uses' statement, This is not allowed according to RFC 7950 Sec 7.21.5", yang_argument_get(yg), yang_argument_get(ygrouping) ); @@ -795,7 +796,7 @@ yang_parse_str(char *str, yang_stmt *ymod = NULL; if (yspec == NULL){ - clicon_err(OE_YANG, 0, "Yang parse need top level yang spec"); + clixon_err(OE_YANG, 0, "Yang parse need top level yang spec"); goto done; } yy.yy_name = (char*)name; @@ -811,9 +812,9 @@ yang_parse_str(char *str, if (yang_parse_init(&yy) < 0) goto done; if (clixon_yang_parseparse(&yy) != 0) { /* yacc returns 1 on error */ - clicon_log(LOG_NOTICE, "Yang error: %s on line %d", name, yy.yy_linenum); - if (clicon_errno == 0) - clicon_err(OE_YANG, 0, "yang parser error with no error code (should not happen)"); + clixon_log(NULL, LOG_NOTICE, "Yang error: %s on line %d", name, yy.yy_linenum); + if (clixon_err_category() == 0) + clixon_err(OE_YANG, 0, "yang parser error with no error code (should not happen)"); yang_parse_exit(&yy); yang_scan_exit(&yy); goto done; @@ -824,7 +825,7 @@ yang_parse_str(char *str, goto done; } if ((ymod = yy.yy_module) == NULL){ - clicon_err(OE_YANG, 0, "No module in YANG %s", name); + clixon_err(OE_YANG, 0, "No module in YANG %s", name); goto done; } /* Add filename for debugging and errors, see also ys_linenum on (each symbol?) */ @@ -860,21 +861,21 @@ yang_parse_file(FILE *fp, len = BUFLEN; /* any number is fine */ if ((buf = malloc(len)) == NULL){ - clicon_err(OE_XML, errno, "malloc"); + clixon_err(OE_XML, errno, "malloc"); goto done; } memset(buf, 0, len); i = 0; /* position in buf */ while (1){ /* read the whole file */ if ((ret = fread(&c, 1, 1, fp)) < 0){ - clicon_err(OE_XML, errno, "read"); + clixon_err(OE_XML, errno, "read"); break; } if (ret == 0) break; /* eof */ if (i == len-1){ if ((buf = realloc(buf, 2*len)) == NULL){ - clicon_err(OE_XML, errno, "realloc"); + clixon_err(OE_XML, errno, "realloc"); goto done; } memset(buf+len, 0, len); @@ -909,7 +910,7 @@ filename2revision(const char *filename, /* base = module name [+ @rev ] + .yang */ if ((base = strdup(filename)) == NULL){ - clicon_err(OE_UNIX, errno, "strdup"); + clixon_err(OE_UNIX, errno, "strdup"); goto done; } clixon_debug(CLIXON_DBG_DETAIL, "%s %s", __FUNCTION__, base); @@ -943,7 +944,7 @@ filename2revision(const char *filename, * @note for bootstrapping, dir may have to be set. */ int -yang_file_find_match(clicon_handle h, +yang_file_find_match(clixon_handle h, const char *module, const char *revision, cbuf *fbuf) @@ -961,7 +962,7 @@ yang_file_find_match(clicon_handle h, if ((x = clicon_conf_xml(h)) == NULL) goto ok; if ((regex = cbuf_new()) == NULL){ - clicon_err(OE_YANG, errno, "cbuf_new"); + clixon_err(OE_YANG, errno, "cbuf_new"); goto done; } /* RFC 6020: The name of the file SHOULD be of the form: @@ -1004,7 +1005,7 @@ yang_file_find_match(clicon_handle h, (dir = xml_body(xc)) != NULL){ /* get all matching files in this directory recursively */ if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (clicon_files_recursive(dir, cbuf_get(regex), cvv) < 0) @@ -1055,7 +1056,7 @@ done: * See top of file for diagram of calling order */ yang_stmt * -yang_parse_filename(clicon_handle h, +yang_parse_filename(clixon_handle h, const char *filename, yang_stmt *yspec) { @@ -1065,11 +1066,11 @@ yang_parse_filename(clicon_handle h, clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename); if (stat(filename, &st) < 0){ - clicon_err(OE_YANG, errno, "%s not found", filename); + clixon_err(OE_YANG, errno, "%s not found", filename); goto done; } if ((fp = fopen(filename, "r")) == NULL){ - clicon_err(OE_YANG, errno, "fopen(%s)", filename); + clixon_err(OE_YANG, errno, "fopen(%s)", filename); goto done; } if ((ymod = yang_parse_file(fp, filename, yspec)) < 0) @@ -1098,7 +1099,7 @@ yang_parse_filename(clicon_handle h, * @note does not check wether the module is already loaded */ yang_stmt * -yang_parse_module(clicon_handle h, +yang_parse_module(clixon_handle h, const char *module, const char *revision, yang_stmt *yspec, @@ -1114,7 +1115,7 @@ yang_parse_module(clicon_handle h, cbuf *cb = NULL; if ((fbuf = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } /* Match a yang file with or without revision in yang-dir list */ @@ -1122,16 +1123,16 @@ yang_parse_module(clicon_handle h, goto done; if (nr == 0){ if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, errno, "cbuf_new"); + clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; } cprintf(cb, "%s", module); if (revision) cprintf(cb, "@%s", revision); if (origname) - clicon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs when loading %s.yang", cbuf_get(cb), origname); + clixon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs when loading %s.yang", cbuf_get(cb), origname); else - clicon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs", cbuf_get(cb)); + clixon_err(OE_YANG, ENOENT, "Yang \"%s\" not found in the list of CLICON_YANG_DIRs", cbuf_get(cb)); goto done; } filename = cbuf_get(fbuf); @@ -1142,7 +1143,7 @@ yang_parse_module(clicon_handle h, * RFC 7950 Sec 5.2 */ if (strcmp(yang_argument_get(ymod), module) != 0){ - clicon_err(OE_YANG, EINVAL, "File %s contains yang module \"%s\" which does not match expected module %s", + clixon_err(OE_YANG, EINVAL, "File %s contains yang module \"%s\" which does not match expected module %s", filename, yang_argument_get(ymod), module); @@ -1159,7 +1160,7 @@ yang_parse_module(clicon_handle h, goto done; /* Sanity check that file revision does not match internal rev stmt */ if (revf && revm && revm != revf){ - clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s vs %u", filename, revm); + clixon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s vs %u", filename, revm); ymod = NULL; goto done; } @@ -1183,7 +1184,7 @@ yang_parse_module(clicon_handle h, * See top of file for diagram of calling order */ static int -yang_parse_recurse(clicon_handle h, +yang_parse_recurse(clixon_handle h, yang_stmt *ymod, yang_stmt *ysp) { @@ -1222,11 +1223,11 @@ yang_parse_recurse(clicon_handle h, if (keyw == Y_INCLUDE){ ybelongto = yang_find(subymod, Y_BELONGS_TO, NULL); if (ybelongto == NULL){ - clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" does not have a belongs-to statement", submodule); /* shouldnt happen */ + clixon_err(OE_YANG, ENOENT, "Sub-module \"%s\" does not have a belongs-to statement", submodule); /* shouldnt happen */ goto done; } if (strcmp(yang_argument_get(ybelongto), yang_argument_get(yrealmod)) != 0){ - clicon_err(OE_YANG, ENOENT, "Sub-module \"%s\" references module \"%s\" in its belongs-to statement but should reference \"%s\"", + clixon_err(OE_YANG, ENOENT, "Sub-module \"%s\" references module \"%s\" in its belongs-to statement but should reference \"%s\"", submodule, yang_argument_get(ybelongto), yang_argument_get(yrealmod)); @@ -1257,7 +1258,7 @@ yang_parse_recurse(clicon_handle h, * Unless it is the "errors" rule of the ietf-restconf spec which seems to be a special case. */ static int -ys_list_check(clicon_handle h, +ys_list_check(clixon_handle h, yang_stmt *ys) { int retval = -1; @@ -1281,7 +1282,7 @@ ys_list_check(clicon_handle h, /* Except nokey exceptions such as rrc 8040 yang-data */ if (!yang_flag_get(yroot, YANG_FLAG_NOKEY)){ /* Note obsolete */ - clicon_log(LOG_ERR, "Error: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)", + clixon_log(h, LOG_ERR, "Error: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)", yang_argument_get(ys), yang_argument_get(ymod) ); @@ -1325,7 +1326,7 @@ ys_visit(struct yang_stmt *yn, if (yn == NULL || (yang_keyword_get(yn) != Y_MODULE && yang_keyword_get(yn) != Y_SUBMODULE)){ - clicon_err(OE_YANG, EINVAL, "Expected module or submodule"); + clixon_err(OE_YANG, EINVAL, "Expected module or submodule"); goto done; } yspec = ys_spec(yn); @@ -1334,7 +1335,7 @@ ys_visit(struct yang_stmt *yn, return 0; /* if n has a temporary mark then stop (not a DAG) */ if (yang_flag_get(yn, YANG_FLAG_TMP)){ - clicon_err(OE_YANG, EFAULT, "Yang module %s import/include is circular", yang_argument_get(yn)); + clixon_err(OE_YANG, EFAULT, "Yang module %s import/include is circular", yang_argument_get(yn)); goto done; } /* mark n with a temporary mark */ @@ -1349,7 +1350,7 @@ ys_visit(struct yang_stmt *yn, continue; if ((ymod = yang_find(yspec, Y_MODULE, yang_argument_get(yi))) == NULL && (ymod = yang_find(yspec, Y_SUBMODULE, yang_argument_get(yi))) == NULL){ - clicon_err(OE_YANG, EFAULT, "Yang module %s import/include not found", + clixon_err(OE_YANG, EFAULT, "Yang module %s import/include not found", yang_argument_get(yi)); /* shouldnt happen */ goto done; } @@ -1363,7 +1364,7 @@ ys_visit(struct yang_stmt *yn, /* add n to head of L. NB reversed */ (*ylen)++; if ((*ylist = realloc(*ylist, (*ylen)*sizeof(yang_stmt *))) == 0){ - clicon_err(OE_YANG, errno, "realloc"); + clixon_err(OE_YANG, errno, "realloc"); goto done; } (*ylist)[*ylen - 1] = yn; @@ -1404,7 +1405,7 @@ yang_sort_modules(yang_stmt *yspec, } } if (*ylen != modmax-modmin){ - clicon_err(OE_YANG, EFAULT, "Internal error: mismatch sort vector lengths"); + clixon_err(OE_YANG, EFAULT, "Internal error: mismatch sort vector lengths"); } retval = 0; done: @@ -1434,7 +1435,7 @@ yang_sort_modules(yang_stmt *yspec, * @retval -1 Error encountered */ int -yang_parse_post(clicon_handle h, +yang_parse_post(clixon_handle h, yang_stmt *yspec, int modmin) { @@ -1445,7 +1446,7 @@ yang_parse_post(clicon_handle h, int ylen = 0; /* Length of ylist */ if (modmin < 0){ - clicon_err(OE_YANG, EINVAL, "modmin negative"); + clixon_err(OE_YANG, EINVAL, "modmin negative"); goto done; } /* 1: Parse from text to yang parse-tree. @@ -1555,7 +1556,7 @@ yang_parse_post(clicon_handle h, * @see yang_spec_parse_file */ int -yang_spec_parse_module(clicon_handle h, +yang_spec_parse_module(clixon_handle h, const char *name, const char *revision, yang_stmt *yspec) @@ -1565,11 +1566,11 @@ yang_spec_parse_module(clicon_handle h, char *base = NULL;; if (yspec == NULL){ - clicon_err(OE_YANG, EINVAL, "yang spec is NULL"); + clixon_err(OE_YANG, EINVAL, "yang spec is NULL"); goto done; } if (name == NULL){ - clicon_err(OE_YANG, EINVAL, "yang module not set"); + clixon_err(OE_YANG, EINVAL, "yang module not set"); goto done; } /* Apply steps 2.. on new modules, ie ones after modmin. */ @@ -1602,7 +1603,7 @@ yang_spec_parse_module(clicon_handle h, * @see yang_spec_load_dir For loading all files in a directory */ int -yang_spec_parse_file(clicon_handle h, +yang_spec_parse_file(clixon_handle h, char *filename, yang_stmt *yspec) { @@ -1614,11 +1615,11 @@ yang_spec_parse_file(clicon_handle h, modmin = yang_len_get(yspec); /* Find module, and do not load file if module already exists */ if (basename(filename) == NULL){ - clicon_err(OE_YANG, errno, "No basename"); + clixon_err(OE_YANG, errno, "No basename"); goto done; } if ((base = strdup(basename(filename))) == NULL){ - clicon_err(OE_YANG, errno, "strdup"); + clixon_err(OE_YANG, errno, "strdup"); goto done; } if (index(base, '@') != NULL) @@ -1654,7 +1655,7 @@ yang_spec_parse_file(clicon_handle h, * the oldest module if 1-3 for some reason fails. */ int -yang_spec_load_dir(clicon_handle h, +yang_spec_load_dir(clixon_handle h, char *dir, yang_stmt *yspec) { @@ -1737,7 +1738,7 @@ yang_spec_load_dir(clicon_handle h, revm = cv_uint32_get(yang_cv_get(yrev)); /* Sanity check that file revision does not match internal rev stmt */ if (revf && revm && revm != revf){ /* XXX */ - clicon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s(%u) vs %u", filename, revf, revm); + clixon_err(OE_YANG, EINVAL, "Yang module file revision and in yang does not match: %s(%u) vs %u", filename, revf, revm); goto done; } /* If ym0 and ym exists, delete the yang with oldest revision @@ -1783,21 +1784,21 @@ ys_parse_date_arg(char *datearg, uint32_t d = 0; if (strlen(datearg) != 10 || datearg[4] != '-' || datearg[7] != '-'){ - clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); + clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); goto done; } if ((i = cligen_tonum(4, datearg)) < 0){ - clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); + clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); goto done; } d = i*10000; /* year */ if ((i = cligen_tonum(2, &datearg[5])) < 0){ - clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); + clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); goto done; } d += i*100; /* month */ if ((i = cligen_tonum(2, &datearg[8])) < 0){ - clicon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); + clixon_err(OE_YANG, EINVAL, "Revision date %s, but expected: YYYY-MM-DD", datearg); goto done; } d += i; /* day */ @@ -1827,15 +1828,15 @@ ys_parse(yang_stmt *ys, yang_cv_set(ys, NULL); } if ((cv = cv_new(cvtype)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } if ((cvret = cv_parse1(yang_argument_get(ys), cv, &reason)) < 0){ /* error */ - clicon_err(OE_YANG, errno, "parsing cv"); + clixon_err(OE_YANG, errno, "parsing cv"); goto done; } if (cvret == 0){ /* parsing failed */ - clicon_err(OE_YANG, errno, "Parsing CV: %s", reason); + clixon_err(OE_YANG, errno, "Parsing CV: %s", reason); goto done; } yang_cv_set(ys, cv); @@ -1895,12 +1896,12 @@ ys_parse_sub(yang_stmt *ys, if (ys_parse(ys, CGV_UINT8) == NULL) goto done; if ((cv = yang_cv_get(ys)) == NULL){ - clicon_err(OE_YANG, ENOENT, "Unexpected NULL cv"); + clixon_err(OE_YANG, ENOENT, "Unexpected NULL cv"); goto done; } fd = cv_uint8_get(cv); if (fd < 1 || fd > 18){ - clicon_err(OE_YANG, errno, "%u: Out of range, should be [1:18]", fd); + clixon_err(OE_YANG, errno, "%u: Out of range, should be [1:18]", fd); goto done; } break; @@ -1914,7 +1915,7 @@ ys_parse_sub(yang_stmt *ys, if (ys_parse_date_arg(arg, &date) < 0) goto done; if ((cv = cv_new(CGV_UINT32)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } yang_cv_set(ys, cv); @@ -1924,7 +1925,7 @@ ys_parse_sub(yang_stmt *ys, if (strcmp(arg, "current") && strcmp(arg, "deprecated") && strcmp(arg, "obsolete")){ - clicon_err(OE_YANG, errno, "Invalid status: \"%s\", expected current, deprecated, or obsolete", arg); + clixon_err(OE_YANG, errno, "Invalid status: \"%s\", expected current, deprecated, or obsolete", arg); goto done; } @@ -1932,7 +1933,7 @@ ys_parse_sub(yang_stmt *ys, case Y_MAX_ELEMENTS: case Y_MIN_ELEMENTS: if ((cv = cv_new(CGV_UINT32)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } yang_cv_set(ys, cv); @@ -1941,11 +1942,11 @@ ys_parse_sub(yang_stmt *ys, cv_uint32_set(cv, 0); /* 0 means unbounded for max */ else{ if ((ret = parse_uint32(arg, &minmax, &reason)) < 0){ - clicon_err(OE_YANG, errno, "parse_uint32"); + clixon_err(OE_YANG, errno, "parse_uint32"); goto done; } if (ret == 0){ - clicon_err(OE_YANG, EINVAL, "element-min/max parse error: %s", reason); + clixon_err(OE_YANG, EINVAL, "element-min/max parse error: %s", reason); if (reason) free(reason); goto done; @@ -1955,7 +1956,7 @@ ys_parse_sub(yang_stmt *ys, break; case Y_MODIFIER: if (strcmp(yang_argument_get(ys), "invert-match")){ - clicon_err(OE_YANG, EINVAL, "modifier %s, expected invert-match", yang_argument_get(ys)); + clixon_err(OE_YANG, EINVAL, "modifier %s, expected invert-match", yang_argument_get(ys)); goto done; } break; @@ -1987,16 +1988,16 @@ ys_parse_sub(yang_stmt *ys, if (extra == NULL) break; if ((cv = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } yang_cv_set(ys, cv); if ((ret = cv_parse1(extra, cv, &reason)) < 0){ /* error */ - clicon_err(OE_YANG, errno, "parsing cv"); + clixon_err(OE_YANG, errno, "parsing cv"); goto done; } if (ret == 0){ /* parsing failed */ - clicon_err(OE_YANG, errno, "Parsing CV: %s", reason); + clixon_err(OE_YANG, errno, "Parsing CV: %s", reason); goto done; } break; diff --git a/lib/src/clixon_yang_schema_mount.c b/lib/src/clixon_yang_schema_mount.c index 68f94354..2003d531 100644 --- a/lib/src/clixon_yang_schema_mount.c +++ b/lib/src/clixon_yang_schema_mount.c @@ -73,6 +73,7 @@ #include "clixon_handle.h" #include "clixon_err.h" #include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_io.h" @@ -110,7 +111,7 @@ yang_schema_mount_point0(yang_stmt *y) char *value = NULL; if (y == NULL){ - clicon_err(OE_YANG, EINVAL, "y is NULL"); + clixon_err(OE_YANG, EINVAL, "y is NULL"); goto done; } keyw = yang_keyword_get(y); @@ -160,7 +161,7 @@ yang_mount_get(yang_stmt *y, cvec *cvv; cg_var *cv; - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y); /* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */ if ((cvv = yang_cvec_get(y)) != NULL && (cv = cvec_find(cvv, xpath)) != NULL && @@ -192,7 +193,7 @@ yang_mount_set(yang_stmt *y, cg_var *cv; cg_var *cv2; - clicon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y); + clixon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y); if ((cvv = yang_cvec_get(y)) != NULL && (cv = cvec_find(cvv, xpath)) != NULL && (yspec0 = cv_void_get(cv)) != NULL){ @@ -204,11 +205,11 @@ yang_mount_set(yang_stmt *y, else if ((cv = yang_cvec_add(y, CGV_VOID, xpath)) == NULL) goto done; if ((cv2 = cv_new(CGV_STRING)) == NULL){ - clicon_err(OE_YANG, errno, "cv_new"); + clixon_err(OE_YANG, errno, "cv_new"); goto done; } if (cv_string_set(cv2, xpath) == NULL){ - clicon_err(OE_UNIX, errno, "cv_string_set"); + clixon_err(OE_UNIX, errno, "cv_string_set"); goto done; } /* tag yspec with key/xpath */ @@ -231,7 +232,7 @@ yang_mount_set(yang_stmt *y, * @retval -1 Error */ int -xml_yang_mount_get(clicon_handle h, +xml_yang_mount_get(clixon_handle h, cxobj *xt, validate_level *vl, yang_stmt **yspec) @@ -293,7 +294,7 @@ xml_yang_mount_get(clicon_handle h, * @retval -1 Error */ int -xml_yang_mount_set(clicon_handle h, +xml_yang_mount_set(clixon_handle h, cxobj *x, yang_stmt *yspec) { @@ -308,7 +309,7 @@ xml_yang_mount_set(clicon_handle h, int ret; if ((y = xml_spec(x)) == NULL){ - clicon_err(OE_YANG, 0, "No yang-spec"); + clixon_err(OE_YANG, 0, "No yang-spec"); goto done; } if (xml2xpath(x, NULL, 1, 0, &xpath0) < 0) @@ -319,7 +320,7 @@ xml_yang_mount_set(clicon_handle h, if ((ret = xpath2canonical(xpath0, nsc0, yspec0, &xpath1, &nsc1, &reason)) < 0) goto done; if (ret == 0){ - clicon_err(OE_YANG, 0, "%s", cbuf_get(reason)); + clixon_err(OE_YANG, 0, "%s", cbuf_get(reason)); goto done; } if (yang_mount_set(y, xpath1, yspec) < 0) @@ -413,7 +414,7 @@ find_schema_mounts(cxobj *x, if (ret == 0) return 0; if ((cv = cvec_add(cvv, CGV_VOID)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); return -1; } cv_void_set(cv, x); @@ -442,7 +443,7 @@ find_schema_mounts(cxobj *x, * @note: Mountpoints must exist in xret on entry */ static int -yang_schema_mount_statedata_yanglib(clicon_handle h, +yang_schema_mount_statedata_yanglib(clixon_handle h, char *xpath, cvec *nsc, cxobj **xret, @@ -460,11 +461,11 @@ yang_schema_mount_statedata_yanglib(clicon_handle h, validate_level vl = VL_FULL; if ((cb = cbuf_new()) == NULL){ - clicon_err(OE_UNIX, 0, "clicon buffer"); + clixon_err(OE_UNIX, 0, "clicon buffer"); goto done; } if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (xml_apply(*xret, CX_ELMNT, find_schema_mounts, cvv) < 0) @@ -513,7 +514,7 @@ yang_schema_mount_statedata_yanglib(clicon_handle h, * @note Only "inline" specification of mounted schema supported, not "shared schema" */ int -yang_schema_mount_statedata(clicon_handle h, +yang_schema_mount_statedata(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, @@ -536,12 +537,12 @@ yang_schema_mount_statedata(clicon_handle h, if ((ymodext = yang_find(yspec, Y_MODULE, "ietf-yang-schema-mount")) == NULL || (yext = yang_find(ymodext, Y_EXTENSION, "mount-point")) == NULL){ goto ok; - // clicon_err(OE_YANG, 0, "yang schema mount-point extension not found"); + // clixon_err(OE_YANG, 0, "yang schema mount-point extension not found"); // goto done; } if ((cvv = yang_cvec_get(yext)) != NULL){ if ((cb = cbuf_new()) ==NULL){ - clicon_err(OE_XML, errno, "cbuf_new"); + clixon_err(OE_XML, errno, "cbuf_new"); goto done; } cprintf(cb, "", YANG_SCHEMA_MOUNT_NAMESPACE); // XXX only if hit @@ -550,7 +551,7 @@ yang_schema_mount_statedata(clicon_handle h, ymount = (yang_stmt*)cv_void_get(cv); ymod = ys_module(ymount); if ((cv1 = yang_cv_get(ymount)) == NULL){ - clicon_err(OE_YANG, 0, "mount-point extension must have label"); + clixon_err(OE_YANG, 0, "mount-point extension must have label"); goto done; } label = cv_string_get(cv1); @@ -596,7 +597,7 @@ yang_schema_mount_statedata(clicon_handle h, * @see yang_schema_mount_statedata */ int -yang_schema_mount_statistics(clicon_handle h, +yang_schema_mount_statistics(clixon_handle h, cxobj *xt, int modules, cbuf *cb) @@ -613,7 +614,7 @@ yang_schema_mount_statistics(clicon_handle h, size_t sz; if ((cvv = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } if (xml_apply(xt, CX_ELMNT, find_schema_mounts, cvv) < 0) @@ -670,7 +671,7 @@ yang_schema_mount_statistics(clicon_handle h, * @retval -1 Error */ int -yang_schema_yanglib_parse_mount(clicon_handle h, +yang_schema_yanglib_parse_mount(clixon_handle h, cxobj *xt) { int retval = -1; @@ -718,7 +719,7 @@ yang_schema_yanglib_parse_mount(clicon_handle h, * XXX maybe not needed */ int -yang_schema_get_child(clicon_handle h, +yang_schema_get_child(clixon_handle h, cxobj *x1, cxobj *x1c, yang_stmt **yc) diff --git a/lib/src/clixon_yang_schemanode_parse.l b/lib/src/clixon_yang_schemanode_parse.l index 2fd929d8..0560999b 100644 --- a/lib/src/clixon_yang_schemanode_parse.l +++ b/lib/src/clixon_yang_schemanode_parse.l @@ -47,7 +47,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" diff --git a/lib/src/clixon_yang_schemanode_parse.y b/lib/src/clixon_yang_schemanode_parse.y index f27d71c0..e2456819 100644 --- a/lib/src/clixon_yang_schemanode_parse.y +++ b/lib/src/clixon_yang_schemanode_parse.y @@ -65,7 +65,7 @@ /* typecast macro */ #define _IF ((clixon_yang_schemanode_yacc *)_if) -#define _YYERROR(msg) {clicon_err(OE_YANG, 0, "%s", (msg)); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_YANG, 0, "%s", (msg)); YYERROR;} #include #include @@ -78,13 +78,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_string.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_yang_module.h" @@ -106,7 +107,7 @@ clixon_yang_schemanode_parseerror(void *arg, { clixon_yang_schemanode_yacc *ife = (clixon_yang_schemanode_yacc *)arg; - clicon_err_fn(NULL, 0, OE_YANG, 0, "yang_schemanode_parse: file:%s:%d \"%s\" %s: at or before: %s", + clixon_err_fn(NULL, 0, OE_YANG, 0, "yang_schemanode_parse: file:%s:%d \"%s\" %s: at or before: %s", ife->if_mainfile, ife->if_linenum, ife->if_parse_string, diff --git a/lib/src/clixon_yang_sub_parse.c b/lib/src/clixon_yang_sub_parse.c index 53f24322..4edc6a53 100644 --- a/lib/src/clixon_yang_sub_parse.c +++ b/lib/src/clixon_yang_sub_parse.c @@ -47,12 +47,13 @@ /* cligen */ #include -/* clicon */ -#include "clixon_log.h" -#include "clixon_err.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" +#include "clixon_log.h" +#include "clixon_debug.h" +#include "clixon_err.h" #include "clixon_yang.h" #include "clixon_yang_sub_parse.h" #include "clixon_yang_schemanode_parse.h" @@ -76,7 +77,7 @@ yang_subparse(char *str, const char *mainfile, int linenum, int *enabled, - clicon_handle h) + clixon_handle h) { int retval = -1; clixon_yang_sub_parse_yacc ife = {0,}; @@ -92,8 +93,8 @@ yang_subparse(char *str, if (clixon_yang_sub_parsel_init(&ife) < 0) goto done; if (clixon_yang_sub_parseparse(&ife) != 0) { /* yacc returns 1 on error */ - if (clicon_errno == 0) - clicon_err(OE_YANG, 0, "If-feature parser error with no error code (should not happen)"); + if (clixon_err_category() == 0) + clixon_err(OE_YANG, 0, "If-feature parser error with no error code (should not happen)"); goto done; } if (enabled) @@ -131,8 +132,8 @@ yang_schema_nodeid_subparse(char *str, if (clixon_yang_schemanode_parsel_init(&ife) < 0) goto done; if (clixon_yang_schemanode_parseparse(&ife) != 0) { /* yacc returns 1 on error */ - if (clicon_errno == 0) - clicon_err(OE_YANG, 0, "descendant-schema-nodeid parser error with no error code (should not happen)"); + if (clixon_err_category() == 0) + clixon_err(OE_YANG, 0, "descendant-schema-nodeid parser error with no error code (should not happen)"); goto done; } retval = 0; diff --git a/lib/src/clixon_yang_sub_parse.h b/lib/src/clixon_yang_sub_parse.h index 46536610..bd3c7e08 100644 --- a/lib/src/clixon_yang_sub_parse.h +++ b/lib/src/clixon_yang_sub_parse.h @@ -56,7 +56,7 @@ struct clixon_yang_sub_parse_yacc { yang_stmt *if_ys; /* Yang statement, NULL if no check */ enum yang_sub_parse_accept if_accept; /* Which sub-parse rule to accept */ int if_enabled; /* Result: 0: feature disabled, 1: enabled */ - clicon_handle h; + clixon_handle h; }; typedef struct clixon_yang_sub_parse_yacc clixon_yang_sub_parse_yacc; @@ -74,7 +74,7 @@ int clixon_yang_sub_parsel_linenr(void); int clixon_yang_sub_parselex(void *); int clixon_yang_sub_parseparse(void *); -int yang_subparse(char *str, yang_stmt *ys, enum yang_sub_parse_accept accept, const char *mainfile, int linenum, int *enabled, clicon_handle h); +int yang_subparse(char *str, yang_stmt *ys, enum yang_sub_parse_accept accept, const char *mainfile, int linenum, int *enabled, clixon_handle h); int yang_schema_nodeid_subparse(char *str, enum yang_sub_parse_accept accept, const char *mainfile, int linenum); #endif /* _CLIXON_YANG_SUB_PARSER_H_ */ diff --git a/lib/src/clixon_yang_sub_parse.l b/lib/src/clixon_yang_sub_parse.l index 98655122..18bdd8bb 100644 --- a/lib/src/clixon_yang_sub_parse.l +++ b/lib/src/clixon_yang_sub_parse.l @@ -47,7 +47,7 @@ /* cligen */ #include -/* clicon */ +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" diff --git a/lib/src/clixon_yang_sub_parse.y b/lib/src/clixon_yang_sub_parse.y index 45223596..23e0704d 100644 --- a/lib/src/clixon_yang_sub_parse.y +++ b/lib/src/clixon_yang_sub_parse.y @@ -76,7 +76,7 @@ /* typecast macro */ #define _IF ((clixon_yang_sub_parse_yacc *)_if) -#define _YYERROR(msg) {clicon_err(OE_YANG, 0, "%s", (msg)); YYERROR;} +#define _YYERROR(msg) {clixon_err(OE_YANG, 0, "%s", (msg)); YYERROR;} #include #include @@ -89,13 +89,14 @@ /* cligen */ #include -/* clicon */ -#include "clixon_err.h" -#include "clixon_log.h" +/* clixon */ #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_string.h" #include "clixon_handle.h" +#include "clixon_err.h" +#include "clixon_log.h" +#include "clixon_debug.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_yang_module.h" @@ -116,7 +117,7 @@ clixon_yang_sub_parseerror(void *arg, { clixon_yang_sub_parse_yacc *ife = (clixon_yang_sub_parse_yacc *)arg; - clicon_err_fn(NULL, 0, OE_YANG, 0, "yang_sub_parse: file:%s:%d \"%s\" %s: at or before: %s", + clixon_err_fn(NULL, 0, OE_YANG, 0, "yang_sub_parse: file:%s:%d \"%s\" %s: at or before: %s", ife->if_mainfile, ife->if_linenum, ife->if_parse_string, @@ -157,7 +158,7 @@ if_feature_check(clixon_yang_sub_parse_yacc *ife, goto done; /* Check if feature exists, and is set, otherwise remove */ if ((yfeat = yang_find(ymod, Y_FEATURE, feature)) == NULL){ - clicon_err(OE_YANG, EINVAL, "Yang module %s has IF_FEATURE %s, but no such FEATURE statement exists", + clixon_err(OE_YANG, EINVAL, "Yang module %s has IF_FEATURE %s, but no such FEATURE statement exists", ymod?yang_argument_get(ymod):"none", feature); goto done; diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index eb7a4b55..edd782b2 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -83,15 +83,13 @@ /* cligen */ #include -/* clicon */ -#include "clixon_log.h" -#include "clixon_err.h" +/* clixon */ #include "clixon_string.h" #include "clixon_queue.h" #include "clixon_hash.h" #include "clixon_handle.h" #include "clixon_regex.h" -#include "clixon_hash.h" +#include "clixon_err.h" #include "clixon_yang.h" #include "clixon_xml.h" #include "clixon_xml_nsctx.h" @@ -174,7 +172,7 @@ yang_builtin(char *type) * * and re-store into "patterns" cvec. * This is done here instead of deep in resolve code (resolve_restrictions) - * since it id dependent on clicon_handle. + * since it id dependent on clixon_handle. * The downside is that all accesses to "patterns" must pass via the cache. * If calls to yang_type_resolve is made without the cache is set, will be * wrong. @@ -182,7 +180,7 @@ yang_builtin(char *type) * @see yang_type_resolve_restrictions where patterns is set */ static int -compile_pattern2regexp(clicon_handle h, +compile_pattern2regexp(clixon_handle h, cvec *patterns, cvec *regexps) { @@ -200,13 +198,13 @@ compile_pattern2regexp(clicon_handle h, if ((ret = regex_compile(h, pattern, &re)) < 0) goto done; if (ret == 0){ - clicon_err(OE_YANG, errno, "regexp compile fail: \"%s\"", + clixon_err(OE_YANG, errno, "regexp compile fail: \"%s\"", pattern); goto done; break; } if ((rcv = cvec_add(regexps, CGV_VOID)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_add"); + clixon_err(OE_UNIX, errno, "cvec_add"); goto done; } if (re != NULL) @@ -234,7 +232,7 @@ int ys_resolve_type(yang_stmt *ys, void *arg) { - // clicon_handle h = (clicon_handle)arg; + // clixon_handle h = (clixon_handle)arg; int retval = -1; int options = 0x0; cvec *cvv = NULL; @@ -243,11 +241,11 @@ ys_resolve_type(yang_stmt *ys, yang_stmt *resolved = NULL; if (yang_keyword_get(ys) != Y_TYPE){ - clicon_err(OE_YANG, EINVAL, "Expected Y_TYPE"); + clixon_err(OE_YANG, EINVAL, "Expected Y_TYPE"); goto done; } if ((patterns = cvec_new(0)) == NULL){ - clicon_err(OE_UNIX, errno, "cvec_new"); + clixon_err(OE_UNIX, errno, "cvec_new"); goto done; } /* Recursively resolve ys -> resolve with restrictions(options, etc) @@ -258,11 +256,11 @@ ys_resolve_type(yang_stmt *ys, &options, &cvv, patterns, NULL, &fraction) < 0) goto done; if (resolved == NULL){ - clicon_err(OE_YANG, 0, "result-type should not be NULL"); + clixon_err(OE_YANG, 0, "result-type should not be NULL"); goto done; } /* Cache the type resolving locally. Only place where this is done. - * Why not do it in yang_type_resolve? (compile regexps needs clicon_handle) + * Why not do it in yang_type_resolve? (compile regexps needs clixon_handle) */ if (yang_type_cache_set(ys, resolved, options, cvv, patterns, fraction) < 0) @@ -366,7 +364,7 @@ clicon_type2cv(char *origtype, */ yang2cv_type(origtype, cvtype); if (*cvtype == CGV_ERR){ - clicon_err(OE_YANG, 0, "%s:\"%s\": type not resolved", + clixon_err(OE_YANG, 0, "%s:\"%s\": type not resolved", yang_argument_get(ym), origtype); goto done; } @@ -374,7 +372,7 @@ clicon_type2cv(char *origtype, else { yang2cv_type(restype, cvtype); if (*cvtype == CGV_ERR){ - clicon_err(OE_YANG, 0, "%s: \"%s\" type not translated", + clixon_err(OE_YANG, 0, "%s: \"%s\" type not translated", yang_argument_get(ym), restype); goto done; } @@ -395,7 +393,7 @@ clicon_type2cv(char *origtype, * @retval -1 Error (fatal), with errno set to indicate error */ static int -cv_validate_pattern(clicon_handle h, +cv_validate_pattern(clixon_handle h, cvec *regexps, yang_stmt *yrestype, char *str, @@ -462,7 +460,7 @@ outofrange(cg_var *cv0, while (i cvv is set containing * array of range_min, range_max cv:s @@ -1366,7 +1364,7 @@ yang_type_resolve(yang_stmt *yorig, /* Not basic type. Now check if prefix which means we look in other module */ if (prefix){ /* Go to top and find import that matches */ if ((yrmod = yang_find_module_by_prefix(ytype, prefix)) == NULL){ - clicon_err(OE_DB, 0, "Type not resolved: \"%s:%s\" in module %s", + clixon_err(OE_DB, 0, "Type not resolved: \"%s:%s\" in module %s", prefix, type, yang_argument_get(ys_module(yorig))); goto done; } @@ -1393,7 +1391,7 @@ yang_type_resolve(yang_stmt *yorig, if (rytypedef != NULL){ /* We have found a typedef */ /* Find associated type statement */ if ((rytype = yang_find(rytypedef, Y_TYPE, NULL)) == NULL){ - clicon_err(OE_DB, 0, "mandatory type object is not found"); + clixon_err(OE_DB, 0, "mandatory type object is not found"); goto done; } /* recursively resolve this new type */ @@ -1403,7 +1401,7 @@ yang_type_resolve(yang_stmt *yorig, fraction) < 0) goto done; if (yrestype && *yrestype == NULL){ - clicon_err(OE_YANG, 0, "result-type should not be NULL"); + clixon_err(OE_YANG, 0, "result-type should not be NULL"); goto done; } /* appends patterns, overwrites others if any */ @@ -1415,7 +1413,7 @@ yang_type_resolve(yang_stmt *yorig, done: #if 1 if (retval == 0 && yrestype != NULL && *yrestype == NULL){ - clicon_err(OE_YANG, 0, "No such type: \"%s\"", type); + clixon_err(OE_YANG, 0, "No such type: \"%s\"", type); retval = -1; } #endif @@ -1457,7 +1455,7 @@ yang_type_resolve(yang_stmt *yorig, * @param[out] fraction for decimal64, how many digits after period * Present if options&YANG_OPTIONS_FRACTION_DIGITS * @retval 0 OK, but note that restype==NULL means not resolved. - * @retval -1 Error, clicon_err handles errors + * @retval -1 Error * The setting of the options argument has the following semantics: * options&YANG_OPTIONS_RANGE or YANG_OPTIONS_LENGTH --> cvv is set containing * array of range_min, range_max cv:s @@ -1485,7 +1483,7 @@ yang_type_get(yang_stmt *ys, *options = 0x0; /* Find mandatory type */ if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){ - clicon_err(OE_DB, ENOENT, "mandatory type object is not found"); + clixon_err(OE_DB, ENOENT, "mandatory type object is not found"); goto done; } /* XXX: here we seem to have some problems if type is union */ @@ -1493,14 +1491,14 @@ yang_type_get(yang_stmt *ys, goto done; if (origtype && (*origtype = strdup(type)) == NULL){ - clicon_err(OE_XML, errno, "stdup"); + clixon_err(OE_XML, errno, "stdup"); goto done; } if (yang_type_resolve(ys, ys, ytype, yrestype, options, cvv, patterns, regexps, fraction) < 0) goto done; if (yrestype && *yrestype == NULL){ - clicon_err(OE_YANG, 0, "result-type should not be NULL"); + clixon_err(OE_YANG, 0, "result-type should not be NULL"); goto done; } retval = 0; diff --git a/test/lib.sh b/test/lib.sh index 0a5d5222..92a33ee7 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -452,6 +452,7 @@ fi function err(){ expect=$1 ret=$2 + stty $STTYSETTINGS >/dev/null echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Expected" @@ -470,6 +471,7 @@ function err(){ # Don't print diffs function err1(){ + stty $STTYSETTINGS >/dev/null echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Expected: $1" @@ -601,9 +603,10 @@ function wait_backend(){ # Start restconf daemon # @see wait_restconf function start_restconf(){ + # remove -g local clixon_restconf_="${clixon_restconf#sudo -g * }" # Start in background -# echo "sudo -u $wwwstartuser $clixon_restconf_ $RCLOG -D $DBG $*" +# echo "sudo -u $wwwstartuser ${clixon_restconf_} $RCLOG -D $DBG $*" sudo -u $wwwstartuser $clixon_restconf_ $RCLOG -D $DBG $* /dev/null & if [ $? -ne 0 ]; then err1 "expected 0" "$?" diff --git a/test/test_api.sh b/test/test_api.sh index 56f9dffe..7a43b884 100755 --- a/test/test_api.sh +++ b/test/test_api.sh @@ -96,21 +96,21 @@ cat< $cfile #include #include -/* clicon */ +/* cligen */ #include -/* Clicon library functions. */ +/* Clixon */ #include /* These include signatures for plugin and transaction callbacks. */ #include static int -trigger_rpc(clicon_handle h, /* Clicon handle */ - cxobj *xe, /* Request: */ - cbuf *cbret, /* Reply eg ... */ - void *arg, /* client_entry */ - void *regarg) /* Argument given at register */ +trigger_rpc(clixon_handle h, /* Clicon handle */ + cxobj *xe, /* Request: */ + cbuf *cbret, /* Reply eg ... */ + void *arg, /* client_entry */ + void *regarg) /* Argument given at register */ { int retval = -1; cxobj *xret = NULL; @@ -124,9 +124,9 @@ trigger_rpc(clicon_handle h, /* Clicon handle */ if (xmldb_get(h, "running", NULL, "/c", &xret) < 0) goto done; - clicon_debug(1, "%s xret:%s", __FUNCTION__, xml_name(xret)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s xret:%s", __FUNCTION__, xml_name(xret)); xc = xpath_first(xret, NULL, "/c"); - clicon_debug(1, "%s xc:%s", __FUNCTION__, xml_name(xc)); + clixon_debug(CLIXON_DBG_DEFAULT, "%s xc:%s", __FUNCTION__, xml_name(xc)); /* Method 1 loop */ x = NULL; @@ -140,19 +140,19 @@ trigger_rpc(clicon_handle h, /* Clicon handle */ break; } } - clicon_debug(1, "%s Method 1: val:%s", __FUNCTION__, val?val:"null"); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Method 1: val:%s", __FUNCTION__, val?val:"null"); /* Method 2 xpath */ val = NULL; if ((x = xpath_first(xc, NULL, "y3[k=5]")) != NULL) val = xml_find_body(x, "val"); - clicon_debug(1, "%s Method 2: val:%s", __FUNCTION__, val?val:"null"); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Method 2: val:%s", __FUNCTION__, val?val:"null"); /* Method 3 binsearch */ val = NULL; /* Add key/value vector */ if ((cvk = cvec_new(0)) == NULL){ - clicon_err(OE_YANG, errno, "cvec_new"); + clixon_err(OE_YANG, errno, "cvec_new"); goto done; } if ((cv = cvec_add(cvk, CGV_STRING)) == NULL) @@ -168,12 +168,12 @@ trigger_rpc(clicon_handle h, /* Clicon handle */ val = xml_find_body(clixon_xvec_i(xv,0), "val"); else val = NULL; - clicon_debug(1, "%s Method 3: val:%s", __FUNCTION__, val?val:"null"); + clixon_debug(CLIXON_DBG_DEFAULT, "%s Method 3: val:%s", __FUNCTION__, val?val:"null"); cprintf(cbret, "", NETCONF_BASE_NAMESPACE); retval = 0; done: - clicon_debug(1, "%s retval:%d", __FUNCTION__, retval); + clixon_debug(CLIXON_DBG_DEFAULT, "%s retval:%d", __FUNCTION__, retval); if (cvk) cvec_free(cvk); if (xret) @@ -183,7 +183,7 @@ trigger_rpc(clicon_handle h, /* Clicon handle */ return retval; } -clixon_plugin_api *clixon_plugin_init(clicon_handle h); +clixon_plugin_api *clixon_plugin_init(clixon_handle h); static clixon_plugin_api api = { "order", /* name */ /*--- Common fields. ---*/ @@ -192,13 +192,13 @@ static clixon_plugin_api api = { /*! Backend plugin initialization * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL * @retval api Pointer to API struct */ clixon_plugin_api * -clixon_plugin_init(clicon_handle h) +clixon_plugin_init(clixon_handle h) { - clicon_debug(1, "%s test-order", __FUNCTION__); + clixon_debug(CLIXON_DBG_DEFAULT, "%s test-order", __FUNCTION__); /* From example.yang (clicon) */ if (rpc_callback_register(h, trigger_rpc, diff --git a/test/test_c++.sh b/test/test_c++.sh index 72d67020..b1dc0eda 100755 --- a/test/test_c++.sh +++ b/test/test_c++.sh @@ -85,14 +85,14 @@ cat< $cfile * the main event loop is entered. */ -clixon_plugin_api * clixon_plugin_init(clicon_handle h); +clixon_plugin_api * clixon_plugin_init(clixon_handle h); -int plugin_start(clicon_handle h) +int plugin_start(clixon_handle h) { return 0; } -int plugin_exit(clicon_handle h) +int plugin_exit(clixon_handle h) { return 0; } @@ -103,7 +103,7 @@ private: struct clixon_plugin_api api; public: - netconf_test(plginit2_t* init, plgstart_t* start, plgexit_t* exit, const char* str = "c++ netconf test") : api() + netconf_test(plginit_t* init, plgstart_t* start, plgexit_t* exit, const char* str = "c++ netconf test") : api() { strcpy(api.ca_name, str); api.ca_init = clixon_plugin_init; @@ -121,11 +121,11 @@ static netconf_test api(clixon_plugin_init, plugin_start, plugin_exit); /*! Local example netconf rpc callback */ -int example_rpc(clicon_handle h, - cxobj *xe, - cbuf *cbret, - void *arg, - void *regarg) +int example_rpc(clixon_handle h, + cxobj *xe, + cbuf *cbret, + void *arg, + void *regarg) { int retval = -1; cxobj *x = NULL; @@ -134,7 +134,7 @@ int example_rpc(clicon_handle h, /* get namespace from rpc name, return back in each output parameter */ if ((ns = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL) { - clicon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); + clixon_err(OE_XML, ENOENT, "No namespace given in rpc %s", xml_name(xe)); goto done; } cprintf(cbret, "", NETCONF_BASE_NAMESPACE); @@ -157,12 +157,12 @@ int example_rpc(clicon_handle h, /*! Netconf plugin initialization * @param[in] h Clixon handle - * @retval NULL Error with clicon_err set + * @retval NULL Error * @retval api Pointer to API struct */ -clixon_plugin_api* clixon_plugin_init(clicon_handle h) +clixon_plugin_api* clixon_plugin_init(clixon_handle h) { - clicon_debug(1, "%s netconf", __FUNCTION__); + clixon_debug(1, "%s netconf", __FUNCTION__); /* Register local netconf rpc client (note not backend rpc client) */ if (rpc_callback_register(h, example_rpc, NULL, "urn:example:clixon", "example") < 0) return NULL; diff --git a/test/test_client.sh b/test/test_client.sh index 9f3c6757..43b093f1 100755 --- a/test/test_client.sh +++ b/test/test_client.sh @@ -77,6 +77,9 @@ cat< $cfile #include #include // debug +#include +#include +#include #include // debug #include @@ -89,12 +92,13 @@ main(int argc, clixon_client_handle ch = NULL; /* clixon client handle */ int s; - clicon_log_init("client", LOG_DEBUG, CLICON_LOG_STDERR); // debug - clicon_debug_init($debug, NULL); // debug - /* Provide a clixon config-file, get a clixon handle */ if ((h = clixon_client_init("$cfg")) == NULL) return -1; + clixon_log_init(h, "client", LOG_DEBUG, CLIXON_LOG_STDERR); + clixon_err_init(h); + clixon_debug_init(h, $debug, NULL); + /* Make a connection over netconf or ssh/netconf */ if ((ch = clixon_client_connect(h, CLIXON_CLIENT_NETCONF, NULL)) == NULL) return -1;