Module: sip-router Branch: master Commit: 5605e1fc7d0dab50f444d9c24edc8d50d8ae3eb4 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5605e1fc...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Jun 12 00:31:39 2009 +0300
presence_xml: safety checks for null node set
- print string reprezentation of the node if it has no cdata value
---
modules_k/presence_xml/pv_xml.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/modules_k/presence_xml/pv_xml.c b/modules_k/presence_xml/pv_xml.c index 0fd0620..d183bae 100644 --- a/modules_k/presence_xml/pv_xml.c +++ b/modules_k/presence_xml/pv_xml.c @@ -101,12 +101,20 @@ int pv_xpath_nodes_eval(pv_xml_t *xdoc) int i; xmlNodeSetPtr nodes; char *p; + xmlChar *keyword; + xmlBufferPtr psBuf;
if(xdoc==NULL || xdoc->doc==NULL || xdoc->xpathCtx==NULL || xdoc->xpathObj==NULL) return -1;
nodes = xdoc->xpathObj->nodesetval; + if(nodes==NULL) + { + xdoc->outbuf.len = 0; + xdoc->outbuf.s[xdoc->outbuf.len] = '\0'; + return 0; + } size = nodes->nodeNr; p = xdoc->outbuf.s; for(i = 0; i < size; ++i) @@ -118,10 +126,33 @@ int pv_xpath_nodes_eval(pv_xml_t *xdoc) *p = ','; p++; } - if(nodes->nodeTab[i]->content!=NULL) + if(nodes->nodeTab[i]->type == XML_ATTRIBUTE_NODE) { - strcpy(p, (char*)nodes->nodeTab[i]->content); - p += strlen((char*)nodes->nodeTab[i]->content); + keyword = xmlNodeListGetString(xdoc->doc, + nodes->nodeTab[i]->children, 0); + if(keyword != NULL) + { + strcpy(p, (char*)keyword); + p += strlen((char*)keyword); + xmlFree(keyword); + keyword = NULL; + } + } else { + if(nodes->nodeTab[i]->content!=NULL) + { + strcpy(p, (char*)nodes->nodeTab[i]->content); + p += strlen((char*)nodes->nodeTab[i]->content); + } else { + psBuf = xmlBufferCreate(); + if(psBuf != NULL && xmlNodeDump(psBuf, xdoc->doc, + nodes->nodeTab[i], 0, 0)>0) + { + strcpy(p, (char*)xmlBufferContent(psBuf)); + p += strlen((char*)xmlBufferContent(psBuf)); + } + if(psBuf != NULL) xmlBufferFree(psBuf); + psBuf = NULL; + } } } xdoc->outbuf.len = p - xdoc->outbuf.s; @@ -144,6 +175,8 @@ int pv_xpath_nodes_update(pv_xml_t *xdoc, str *val) return -1; } nodes = xdoc->xpathObj->nodesetval; + if(nodes==NULL) + return 0; size = nodes->nodeNr;
value = (const xmlChar*)xdoc->outbuf.s;