diff options
author | David Sommerseth <davids@redhat.com> | 2011-10-07 14:22:03 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2011-10-07 18:11:06 +0200 |
commit | 5ce546f047f30d40b52ac647a5012a7f09b7e30d (patch) | |
tree | c3672c9fc64cf8d8a9fc21c7a32190560573cd04 | |
parent | a5e7518839e3054cfb05c9b12094c5a27b199e56 (diff) | |
download | rteval-5ce546f047f30d40b52ac647a5012a7f09b7e30d.tar.gz rteval-5ce546f047f30d40b52ac647a5012a7f09b7e30d.tar.xz rteval-5ce546f047f30d40b52ac647a5012a7f09b7e30d.zip |
Introduce init_xmlparser() process
This is the first step towards moving PostgreSQL specific parts out of xmlparser.c
to make the xmlparser database backend agnostic.
Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r-- | server/parser/xmlparser.c | 41 | ||||
-rw-r--r-- | server/parser/xmlparser.h | 9 |
2 files changed, 50 insertions, 0 deletions
diff --git a/server/parser/xmlparser.c b/server/parser/xmlparser.c index b6eb44d..0d6e837 100644 --- a/server/parser/xmlparser.c +++ b/server/parser/xmlparser.c @@ -42,6 +42,8 @@ #include <sha1.h> #include <log.h> +static dbhelper_func const * xmlparser_dbhelpers = NULL; + /** * Simple strdup() function which encapsulates the string in single quotes, * which is needed for XSLT parameter values @@ -102,6 +104,15 @@ int isNumber(const char * str) } /** + * Initialise the XML parser, setting some global variables + */ +void init_xmlparser(dbhelper_func const * dbhelpers) +{ + xmlparser_dbhelpers = dbhelpers; +} + + +/** * Parses any XML input document into a sqldata XML format which can be used by pgsql_INSERT(). * The transformation must be defined in the input XSLT template. * @@ -118,6 +129,11 @@ xmlDoc *parseToSQLdata(LogContext *log, xsltStylesheet *xslt, xmlDoc *indata_d, unsigned int idx = 0, idx_table = 0, idx_submid = 0, idx_syskey = 0, idx_rterid = 0, idx_repfname = 0; + if( xmlparser_dbhelpers == NULL ) { + writelog(log, LOG_ERR, "Programming error: xmlparser is not initialised"); + return NULL; + } + if( params->table == NULL ) { writelog(log, LOG_ERR, "Table is not defined"); return NULL; @@ -309,6 +325,11 @@ static char * sqldataValueArray(LogContext *log, xmlNode *sql_n) char *sqldataExtractContent(LogContext *log, xmlNode *sql_n) { const char *valtype = xmlGetAttrValue(sql_n->properties, "type"); + if( xmlparser_dbhelpers == NULL ) { + writelog(log, LOG_ERR, "Programming error: xmlparser is not initialised"); + return NULL; + } + if( !sql_n || (xmlStrcmp(sql_n->name, (xmlChar *) "value") != 0) || (xmlStrcmp(sql_n->parent->name, (xmlChar *) "record") != 0) ) { return NULL; @@ -344,6 +365,11 @@ char *sqldataExtractContent(LogContext *log, xmlNode *sql_n) { int sqldataGetFid(LogContext *log, xmlNode *sql_n, const char *fname) { xmlNode *f_n = NULL; + if( xmlparser_dbhelpers == NULL ) { + writelog(log, LOG_ERR, "Programming error: xmlparser is not initialised"); + return NULL; + } + if( !sql_n || (xmlStrcmp(sql_n->name, (xmlChar *) "sqldata") != 0) ) { writelog(log, LOG_ERR, "sqldataGetFid: Input XML document is not a valid sqldata document"); @@ -395,6 +421,11 @@ char *sqldataGetValue(LogContext *log, xmlDoc *sqld, const char *fname, int reci xmlNode *r_n = NULL; int fid = -3, rc = 0; + if( xmlparser_dbhelpers == NULL ) { + writelog(log, LOG_ERR, "Programming error: xmlparser is not initialised"); + return NULL; + } + if( recid < 0 ) { writelog(log, LOG_ERR, "sqldataGetValue: Invalid recid"); return NULL; @@ -469,6 +500,11 @@ xmlDoc *sqldataGetHostInfo(LogContext *log, xsltStylesheet *xslt, xmlDoc *summar xmlDoc *hostinfo_d = NULL; parseParams prms; + if( xmlparser_dbhelpers == NULL ) { + writelog(log, LOG_ERR, "Programming error: xmlparser is not initialised"); + return NULL; + } + memset(&prms, 0, sizeof(parseParams)); prms.table = "systems_hostname"; prms.syskey = syskey; @@ -508,6 +544,11 @@ int sqldataGetRequiredSchemaVer(LogContext *log, xmlNode *sqldata_root) char *schver = NULL, *cp = NULL, *ptr = NULL; int majv = 0, minv = 0; + if( xmlparser_dbhelpers == NULL ) { + writelog(log, LOG_ERR, "Programming error: xmlparser is not initialised"); + return NULL; + } + if( !sqldata_root || (xmlStrcmp(sqldata_root->name, (xmlChar *) "sqldata") != 0) ) { writelog(log, LOG_ERR, "sqldataGetRequiredSchemaVer: Invalid document node"); return -1; diff --git a/server/parser/xmlparser.h b/server/parser/xmlparser.h index f903037..f2ce057 100644 --- a/server/parser/xmlparser.h +++ b/server/parser/xmlparser.h @@ -39,6 +39,15 @@ typedef struct { unsigned int rterid; /**< References rtevalruns.rterid */ } parseParams; + +/** + * Database specific helper functions + */ +typedef struct { + const char *(*dbh_FormatArray)(LogContext *log, xmlNode *sql_n); /** Formats data as arrays */ +} dbhelper_func; + +void init_xmlparser(dbhelper_func const * dbhelpers); xmlDoc *parseToSQLdata(LogContext *log, xsltStylesheet *xslt, xmlDoc *indata_d, parseParams *params); char *sqldataExtractContent(LogContext *log, xmlNode *sql_n); int sqldataGetFid(LogContext *log, xmlNode *sqld, const char *fname); |