Restructured error,debug anf log API

Renamed functions clicon->clixon, replaced global variables w access functions
Unified clicon_netconf_error with clixon_err()
This commit is contained in:
Olof hagsand 2023-11-13 10:12:52 +01:00
parent 261469be16
commit 24a4991ec8
199 changed files with 4668 additions and 4158 deletions

View file

@ -57,7 +57,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#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;