mech: common convenience library, currently only XML debug fns

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-03-16 06:37:56 +01:00
parent d01617a79e
commit d130011f96
7 changed files with 90 additions and 3 deletions
+1
View File
@@ -3,6 +3,7 @@ include $(top_srcdir)/common.am
SUBDIRS = src yang
DISTCLEANFILES = *~ *.d
ACLOCAL_AMFLAGS = -I m4
noinst_HEADERS += include/common.h
sysconf_DATA = clixon.xml
EXTRA_DIST = NOTICE
+3 -2
View File
@@ -1,5 +1,5 @@
CFLAGS = -Wall -Wextra -Werror -Wno-unused-parameter
CPPFLAGS = -I $(top_srcdir)/include/
CPPFLAGS = -I$(top_srcdir)/include/
clixonlibdir = $(libdir)/clixon
backenddir = $(clixonlibdir)/backend
@@ -9,6 +9,7 @@ yangdir = $(datarootdir)/clixon
backend_LTLIBRARIES =
cli_LTLIBRARIES =
noinst_HEADERS =
clispec_DATA =
yang_DATA =
@@ -16,6 +17,6 @@ cli_libadd = -lclixon -lclixon_cli
cli_ldflags = -module -avoid-version -shared
backend_cflags = $(CFLAGS) $(augeas_CFLAGS)
backend_libadd = $(augeas_LIBS) -lclixon -lclixon_backend
backend_libadd = $(augeas_LIBS) -lclixon -lclixon_backend ../common/common.la
backend_ldflags = -module -avoid-version -shared
+1
View File
@@ -10,6 +10,7 @@ AC_CONFIG_FILES([
clixon.xml
Makefile
src/Makefile
src/common/Makefile
src/core/Makefile
src/ietf-system/Makefile
yang/Makefile
+17
View File
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: Apache-2.0 */
#ifndef MECH_COMMON_H_
#define MECH_COMMON_H_
#include <stdbool.h>
#include <cligen/cligen.h>
#include <clixon/clixon.h>
#include <clixon/clixon_backend.h>
/* debug.c */
void show_xml_node (char *tag, cxobj *node);
void show_xml_node_vec (char *tag, cxobj **node_vec, size_t len);
void show_transaction (char *tag, transaction_data td, bool show_data);
#endif /* MECH_COMMON_H_ */
+1 -1
View File
@@ -1,6 +1,6 @@
include $(top_srcdir)/common.am
SUBDIRS = core ietf-system
SUBDIRS = common core ietf-system
install-exec-hook:
find $(DESTDIR)$(clixonlibdir) -name '*.la' -delete
+6
View File
@@ -0,0 +1,6 @@
include $(top_srcdir)/common.am
noinst_LTLIBRARIES = common.la
common_la_LDFLAGS = $(cli_ldflags)
common_la_LIBADD = $(cli_libadd)
common_la_SOURCES = common-debug.c
+61
View File
@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: Apache-2.0 */
#include <syslog.h>
#include "common.h"
#define MAX_INDENT 128
static char* indent_str(size_t indent)
{
static char str[MAX_INDENT + 1];
for (size_t i = 0; i < indent; i++)
str[i] = ' ';
str[indent] = '\0';
return str;
}
static void show_indented_xml_node(char *tag, cxobj *node, size_t indent)
{
cxobj *child = NULL;
if (!xml_body_get(node))
clicon_log(LOG_DEBUG, "%s: %s%s", tag, indent_str(indent), xml_name(node));
else
clicon_log(LOG_DEBUG, "%s: %s%s = %s", tag, indent_str(indent), xml_name(node), xml_body(node));
while ((child = xml_child_each(node, child, CX_ELMNT)))
show_indented_xml_node(tag, child, indent + 2);
}
void show_xml_node(char *tag, cxobj *node)
{
show_indented_xml_node(tag, node, 4);
}
void show_xml_node_vec(char *tag, cxobj **node_vec, size_t len)
{
for (size_t i = 0; i < len; i++)
show_indented_xml_node(tag, node_vec[i], 4);
}
void show_transaction(char *tag, transaction_data td, bool show_data)
{
clicon_log(LOG_DEBUG, "%s: transaction ID = %lu", tag, transaction_id(td));
if (show_data) {
clicon_log(LOG_DEBUG, "%s: transaction source:", tag);
show_xml_node(tag, transaction_src(td));
clicon_log(LOG_DEBUG, "%s: transaction target:", tag);
show_xml_node(tag, transaction_target(td));
clicon_log(LOG_DEBUG, "%s: transaction deleted:", tag);
show_xml_node_vec(tag, transaction_dvec(td), transaction_dlen(td));
clicon_log(LOG_DEBUG, "%s: transaction added:", tag);
show_xml_node_vec(tag, transaction_avec(td), transaction_alen(td));
clicon_log(LOG_DEBUG, "%s: transaction changed source:", tag);
show_xml_node_vec(tag, transaction_scvec(td), transaction_clen(td));
clicon_log(LOG_DEBUG, "%s: transaction changed target:", tag);
show_xml_node_vec(tag, transaction_tcvec(td), transaction_clen(td));
}
}