From b03ac3497b4d75f8abdf9e7b7337c7dc9c5d846c Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 21 Jun 2009 09:52:22 +0000 Subject: [PATCH] Add a generic binary protocol configuration file analyser that outputs the relevant parts of a generic binary protocol configuration --- utils/xmlgrep/Makefile.am | 16 +++- utils/xmlgrep/generic-config-analyse.c | 119 +++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 utils/xmlgrep/generic-config-analyse.c diff --git a/utils/xmlgrep/Makefile.am b/utils/xmlgrep/Makefile.am index 084efb4ee..0a883bc9f 100644 --- a/utils/xmlgrep/Makefile.am +++ b/utils/xmlgrep/Makefile.am @@ -4,18 +4,26 @@ noinst_LIBRARIES = libxmlconf.a libxmlconf_a_SOURCES = xml_cache.c xml.c -noinst_PROGRAMS = testxml printxml xmlgrep +noinst_PROGRAMS = \ + testxml \ + printxml \ + xmlgrep \ + printtree \ + generic_config_analyse testxml_SOURCES = testxml.c testxml_LDADD = libxmlconf.a -printxml_SOURCES = $(xml_SOURCE) printxml.c +printxml_SOURCES = printxml.c printxml_LDADD = libxmlconf.a -printtree_SOURCES = $(xml_SOURCE) printtree.c +printtree_SOURCES = printtree.c printtree_LDADD = libxmlconf.a -xmlgrep_SOURCES = $(xml_SOURCE) xmlgrep.c xml.c xml.h +xmlgrep_SOURCES = xmlgrep.c xmlgrep_LDADD = libxmlconf.a +generic_config_analyse_SOURCES = generic-config-analyse.c +generic_config_analyse_LDADD = libxmlconf.a + INCLUDES = -DSRC_DIR=\"$(top_srcdir)/utils/xmlgrep\" -DXML_USE_NODECACHE diff --git a/utils/xmlgrep/generic-config-analyse.c b/utils/xmlgrep/generic-config-analyse.c new file mode 100644 index 000000000..1e8ffeb47 --- /dev/null +++ b/utils/xmlgrep/generic-config-analyse.c @@ -0,0 +1,119 @@ +#include +#include +#include +#include +#include +#include "xml.h" + +#define ROOTNODE "/PropertyList/generic" +#define BUFLEN 4096 + +#define PRINT_ERROR_AND_EXIT(id) \ + if (xmlErrorGetNo(id, 0) != XML_NO_ERROR) { \ + const char *errstr = xmlErrorGetString(id, 0); \ + size_t column = xmlErrorGetColumnNo(id, 0); \ + size_t lineno = xmlErrorGetLineNo(id, 1); \ + printf("Error at line %i, column %i: %s\n", lineno, column, errstr); \ + exit(-1); \ + } + +void print_binary_protocol(void *, char *, char *); + +int main(int argc, char **argv) +{ + void *root_id, *protocol_id = 0; + char *filename; + + if (argc != 2) + { + printf("Usage: %s \n", argv[0]); + exit(-1); + } + + filename = argv[1]; + root_id = xmlOpen(filename); + if (root_id) protocol_id = xmlNodeGet(root_id, ROOTNODE); + + if (protocol_id) + { + void *dir_id; + + dir_id = xmlNodeGet(protocol_id, "input"); + if (dir_id) + { + if (!xmlNodeCompareString(dir_id, "binary_mode", "true")) { + print_binary_protocol(dir_id, filename, "input"); + } else { + printf("Only binary mode support is implemented at the moment.\n"); + } + free(dir_id); + } + + dir_id = xmlNodeGet(protocol_id, "output"); + if (dir_id) + { + if (!xmlNodeCompareString(dir_id, "binary_mode", "true")) { + print_binary_protocol(dir_id, filename, "output"); + } else { + printf("Only binary mode support is implemented at the moment.\n"); + } + free(dir_id); + } + + free(protocol_id); + } + + if (root_id) + { + xmlClose(root_id); + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ + +void print_binary_protocol(void *id, char *filename, char *dir) +{ + unsigned int i, num, pos = 0; + void *xid; + + printf("\n%s\n", filename); + printf("Generic binary %s protocol packet descriptopn:\n\n", dir); + printf(" pos | size | type | factor | description\n"); + printf("-----|------|--------|------------|------------------------\n"); + xid = xmlMarkId(id); + num = xmlNodeGetNum(xid, "chunk"); + for (i=0; i