Changed ca_errmsg callback to a more generic variant
Includes all error, log and debug messages See [Customized NETCONF error message](https://github.com/clicon/clixon/issues/454)
This commit is contained in:
parent
798a9fbfcb
commit
9e54f0602f
83 changed files with 739 additions and 616 deletions
|
|
@ -71,17 +71,17 @@ extern "C" {
|
|||
#include <clixon/clixon_queue.h>
|
||||
#include <clixon/clixon_hash.h>
|
||||
#include <clixon/clixon_handle.h>
|
||||
#include <clixon/clixon_yang.h>
|
||||
#include <clixon/clixon_xml.h>
|
||||
#include <clixon/clixon_err.h>
|
||||
#include <clixon/clixon_log.h>
|
||||
#include <clixon/clixon_debug.h>
|
||||
#include <clixon/clixon_netns.h>
|
||||
#include <clixon/clixon_yang.h>
|
||||
#include <clixon/clixon_yang_type.h>
|
||||
#include <clixon/clixon_event.h>
|
||||
#include <clixon/clixon_string.h>
|
||||
#include <clixon/clixon_proc.h>
|
||||
#include <clixon/clixon_file.h>
|
||||
#include <clixon/clixon_xml.h>
|
||||
#include <clixon/clixon_xml_sort.h>
|
||||
#include <clixon/clixon_yang_parse_lib.h>
|
||||
#include <clixon/clixon_yang_module.h>
|
||||
|
|
|
|||
|
|
@ -50,11 +50,17 @@
|
|||
#define CLIXON_DBG_DETAIL 4 /* Details: traces, parse trees, etc */
|
||||
#define CLIXON_DBG_EXTRA 8 /* Extra Detailed logs */
|
||||
|
||||
/*
|
||||
* Macros
|
||||
*/
|
||||
#define clixon_debug(l, _fmt, args...) clixon_debug_fn(NULL, (l), NULL, _fmt , ##args)
|
||||
#define clixon_debug_xml(l, x, _fmt, args...) clixon_debug_fn(NULL, (l), (x), _fmt , ##args)
|
||||
|
||||
/*
|
||||
* 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);
|
||||
int clixon_debug_fn(clixon_handle h, int dbglevel, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 4, 5)));
|
||||
|
||||
#endif /* _CLIXON_DEBUG_H_ */
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ typedef int (clixon_cat_log_cb)(void *handle, int suberr, cbuf *cb);
|
|||
/*
|
||||
* Macros
|
||||
*/
|
||||
#define clixon_err(e,s,_fmt, args...) clixon_err_fn(__FUNCTION__, __LINE__, (e), (s), _fmt , ##args)
|
||||
#define clixon_err(c,s,_fmt, args...) clixon_err_fn(NULL, __FUNCTION__, __LINE__, (c), (s), NULL, _fmt , ##args)
|
||||
#define clixon_err_netconf(h,c,s,x,_fmt, args...) clixon_err_fn((h), __FUNCTION__, __LINE__, (c), (s), (x), _fmt , ##args)
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
|
|
@ -105,8 +106,8 @@ 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)));
|
||||
int clixon_err_fn(clixon_handle h, const char *fn, const int line, int category, int suberr, cxobj *xerr, const char *format, ...) __attribute__ ((format (printf, 7, 8)));
|
||||
int netconf_err2cb(clixon_handle h, cxobj *xerr, cbuf *cberr);
|
||||
|
||||
void *clixon_err_save(void);
|
||||
int clixon_err_restore(void *handle);
|
||||
|
|
@ -114,12 +115,16 @@ int clixon_err_cat_reg(enum clixon_err category, void *handle, clixon_cat_log_
|
|||
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(c,s,_fmt, args...) clixon_err_fn(NULL, __FUNCTION__, __LINE__, (c), (s), NULL, _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()
|
||||
|
||||
/* doesnt work if arg != NULL */
|
||||
#define clixon_netconf_error(h, x, f, a) clixon_err_fn((h), __FUNCTION__, __LINE__, OE_XML, 0,(x), (f) , NULL)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _CLIXON_ERR_H_ */
|
||||
|
|
|
|||
|
|
@ -49,6 +49,19 @@
|
|||
#define CLIXON_LOG_STDOUT 4 /* print logs on stdout */
|
||||
#define CLIXON_LOG_FILE 8 /* print logs on clicon_log_filename */
|
||||
|
||||
/* What kind of log (only for customizable error/logs) */
|
||||
enum clixon_log_type{
|
||||
LOG_TYPE_LOG,
|
||||
LOG_TYPE_ERR,
|
||||
LOG_TYPE_DEBUG
|
||||
};
|
||||
|
||||
/*
|
||||
* Macros
|
||||
*/
|
||||
#define clixon_log(h, l, _fmt, args...) clixon_log_fn((h), 1, (l), NULL, _fmt , ##args)
|
||||
#define clixon_log_xml(h, l, x, _fmt, args...) clixon_log_fn((h), 1, (l), x, _fmt , ##args)
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
|
|
@ -60,8 +73,7 @@ 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);
|
||||
int clixon_log_fn(clixon_handle h, int user, int level, cxobj *x, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
|
||||
#if 1 /* COMPAT_6_5 */
|
||||
#define CLICON_LOG_SYSLOG CLIXON_LOG_SYSLOG
|
||||
|
|
|
|||
|
|
@ -206,16 +206,4 @@ 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 */
|
||||
|
|
|
|||
|
|
@ -314,15 +314,27 @@ typedef int (yang_mount_t)(clixon_handle h, cxobj *xt, int *config,
|
|||
*/
|
||||
typedef int (yang_patch_t)(clixon_handle h, yang_stmt *ymod);
|
||||
|
||||
/*! Callback to customize Netconf error message
|
||||
/*! Callback to customize log, error, or debug message
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xerr Netconf error message on the level: <rpc-error>
|
||||
* @param[out] cberr Translation from netconf err to cbuf.
|
||||
* @retval 0 OK, with cberr set
|
||||
* @retval -1 Error
|
||||
* @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] type Log message type
|
||||
* @param[in,out] category Clixon error category, See enum clixon_err
|
||||
* @param[in,out] suberr Error number, typically errno
|
||||
* @param[in] xerr Netconf error xml tree on the form: <rpc-error>
|
||||
* @param[in] format Format string
|
||||
* @param[in] ap Variable argument list
|
||||
* @param[out] cbmsg Log string as cbuf, if set bypass ordinary logging
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* When cbmsg is set by a plugin, no other plugins are called. category and suberr
|
||||
* can be rewritten by any plugin.
|
||||
*/
|
||||
typedef int (netconf_errmsg_t)(clixon_handle, cxobj *xerr, cbuf *cberr);
|
||||
typedef int (errmsg_t)(clixon_handle h, const char *fn, const int line,
|
||||
enum clixon_log_type type,
|
||||
int *category, int *suberr, cxobj *xerr,
|
||||
const char *format, va_list ap, cbuf **cbmsg);
|
||||
|
||||
/*! Callback for printing version output and exit
|
||||
*
|
||||
|
|
@ -366,7 +378,7 @@ struct clixon_plugin_api{
|
|||
plgextension_t *ca_extension; /* Yang extension/unknown handler */
|
||||
yang_mount_t *ca_yang_mount; /* RFC 8528 schema mount */
|
||||
yang_patch_t *ca_yang_patch; /* Patch yang after parse */
|
||||
netconf_errmsg_t *ca_errmsg; /* Customize error message callback */
|
||||
errmsg_t *ca_errmsg; /* Customize log/error/debug callback */
|
||||
plgversion_t *ca_version; /* Output a customized version message */
|
||||
union {
|
||||
struct { /* cli-specific */
|
||||
|
|
@ -497,8 +509,16 @@ int clixon_plugin_yang_mount_all(clixon_handle h, cxobj *xt, int *config, valida
|
|||
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, clixon_handle h, cxobj *xerr, cbuf *cberr);
|
||||
int clixon_plugin_netconf_errmsg_all(clixon_handle h, cxobj *xerr, cbuf *cberr);
|
||||
int clixon_plugin_errmsg_one(clixon_plugin_t *cp, clixon_handle h,
|
||||
const char *fn, const int line,
|
||||
enum clixon_log_type type,
|
||||
int *category, int *suberr, cxobj *xerr,
|
||||
const char *format, va_list ap, cbuf **cbmsg);
|
||||
int clixon_plugin_errmsg_all(clixon_handle h,
|
||||
const char *fn, const int line,
|
||||
enum clixon_log_type type,
|
||||
int *category, int *suberr, cxobj *xerr,
|
||||
const char *format, va_list ap, cbuf **cbmsg);
|
||||
|
||||
int clixon_plugin_version_one(clixon_plugin_t *cp, clixon_handle h, FILE *f);
|
||||
int clixon_plugin_version_all(clixon_handle h, FILE *f);
|
||||
|
|
|
|||
|
|
@ -307,9 +307,6 @@ 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 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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue