diff options
| author | David Sommerseth <davids@redhat.com> | 2009-10-12 15:44:17 +0200 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2009-10-12 15:44:17 +0200 |
| commit | 25d8bb2e5baeb4a14a2f0435e9229ce043a5528a (patch) | |
| tree | 11563d03ad5287bb0f111029f6758a7c6f38daa0 /server/parser/xmlparser.c | |
| parent | d85d7cb2e0992fc6f62bb9519a5058750350c287 (diff) | |
Refactored sqldataGetFid() and sqldataGetValue() functions
sqldataGetFid() now takes xmlNode instead of xmlDoc, and
sqldataGetValue() takes field name instead of numeric field id (fid) to
simpilfy the API.
Fixed a double-free bug caused by a missing strdup() in sqldataValueHas().
Diffstat (limited to 'server/parser/xmlparser.c')
| -rw-r--r-- | server/parser/xmlparser.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/server/parser/xmlparser.c b/server/parser/xmlparser.c index 281ab7f..8977e99 100644 --- a/server/parser/xmlparser.c +++ b/server/parser/xmlparser.c @@ -127,7 +127,7 @@ char *sqldataValueHash(xmlNode *sql_n) { hash = xmlGetAttrValue(sql_n->properties, "hash"); if( !hash ) { // If no hash attribute is found, just use the raw data - ret = xmlExtractContent(sql_n); + ret = strdup(xmlExtractContent(sql_n)); } else if( strcasecmp(hash, "sha1") == 0 ) { const char *indata = xmlExtractContent(sql_n); // SHA1 hashing requested @@ -172,16 +172,15 @@ char *sqldataExtractContent(xmlNode *sql_n) { } -int sqldataGetFid(xmlDoc *sqld, const char *fname) { +int sqldataGetFid(xmlNode *sql_n, const char *fname) { xmlNode *f_n = NULL; - f_n = xmlDocGetRootElement(sqld); - if( !f_n || (xmlStrcmp(f_n->name, (xmlChar *) "sqldata") != 0) ) { + if( !sql_n || (xmlStrcmp(sql_n->name, (xmlChar *) "sqldata") != 0) ) { fprintf(stderr, "** ERROR ** Input XML document is not a valid sqldata document\n"); return -2; } - f_n = xmlFindNode(f_n, "fields"); + f_n = xmlFindNode(sql_n, "fields"); if( !f_n || !f_n->children ) { fprintf(stderr, "** ERROR ** Input XML document does not contain a fields section\n"); return -2; @@ -207,12 +206,12 @@ int sqldataGetFid(xmlDoc *sqld, const char *fname) { } -char *sqldataGetValue(xmlDoc *sqld, int fid, int recid ) { +char *sqldataGetValue(xmlDoc *sqld, const char *fname, int recid ) { xmlNode *r_n = NULL; - int rc = 0; + int fid = -3, rc = 0; - if( (fid < 0) || (recid < 0) ) { - fprintf(stderr, "** ERROR ** sqldataGetValue() :: Invalid fid or recid\n"); + if( recid < 0 ) { + fprintf(stderr, "** ERROR ** sqldataGetValue() :: Invalid recid\n"); return NULL; } @@ -222,6 +221,11 @@ char *sqldataGetValue(xmlDoc *sqld, int fid, int recid ) { return NULL; } + fid = sqldataGetFid(r_n, fname); + if( fid < 0 ) { + return NULL; + } + r_n = xmlFindNode(r_n, "records"); if( !r_n || !r_n->children ) { fprintf(stderr, "** ERROR ** Input XML document does not contain a records section\n"); |
