Module: sip-router Branch: master Commit: 30e285d05fe32235c0befde9573fafd8a162a974 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=30e285d0...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Jun 12 11:19:37 2009 +0300
presence_xml: support to handle namespace prefixes
---
modules_k/presence_xml/presence_xml.c | 4 ++- modules_k/presence_xml/pv_xml.c | 54 +++++++++++++++++++++++++++++++++ modules_k/presence_xml/pv_xml.h | 3 ++ 3 files changed, 60 insertions(+), 1 deletions(-)
diff --git a/modules_k/presence_xml/presence_xml.c b/modules_k/presence_xml/presence_xml.c index 971449c..7cdbf64 100644 --- a/modules_k/presence_xml/presence_xml.c +++ b/modules_k/presence_xml/presence_xml.c @@ -112,7 +112,9 @@ static param_export_t params[]={ { "disable_presence", INT_PARAM, &disable_presence }, { "disable_winfo", INT_PARAM, &disable_winfo }, { "disable_bla", INT_PARAM, &disable_bla }, - { "passive_mode", INT_PARAM, &passive_mode }, { 0, 0, 0} + { "passive_mode", INT_PARAM, &passive_mode }, + { "xml_ns", STR_PARAM|USE_FUNC_PARAM, (void*)pv_xml_ns_param }, + { 0, 0, 0} };
static mi_export_t mi_cmds[] = { diff --git a/modules_k/presence_xml/pv_xml.c b/modules_k/presence_xml/pv_xml.c index d183bae..dcb5a19 100644 --- a/modules_k/presence_xml/pv_xml.c +++ b/modules_k/presence_xml/pv_xml.c @@ -30,6 +30,7 @@ #include <libxml/xpathInternals.h>
#include "../../mem/mem.h" +#include "../../parser/parse_param.h" #include "../../hashes.h" #include "../../dprint.h"
@@ -58,6 +59,8 @@ typedef struct _pv_xml_spec {
pv_xml_t *_pv_xml_root = NULL;
+param_t *_pv_xml_ns_root = NULL; + pv_xml_t *pv_xml_get_struct(str *name) { unsigned int docid; @@ -159,6 +162,7 @@ int pv_xpath_nodes_eval(pv_xml_t *xdoc) xdoc->outbuf.s[xdoc->outbuf.len] = '\0'; return 0; } + int pv_xpath_nodes_update(pv_xml_t *xdoc, str *val) { xmlNodeSetPtr nodes; @@ -222,6 +226,17 @@ int pv_xpath_nodes_update(pv_xml_t *xdoc, str *val) return 0; }
+void pv_xml_register_ns(xmlXPathContextPtr xpathCtx) +{ + param_t *ns; + ns = _pv_xml_ns_root; + while(ns) { + xmlXPathRegisterNs(xpathCtx, (xmlChar*)ns->name.s, + (xmlChar*)ns->body.s); + ns = ns->next; + } +} + int pv_get_xml(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { @@ -286,6 +301,7 @@ int pv_get_xml(struct sip_msg *msg, pv_param_t *param, } /* Evaluate xpath expression */ + pv_xml_register_ns(pxs->xdoc->xpathCtx); pxs->xdoc->xpathObj = xmlXPathEvalExpression( (const xmlChar*)xpaths.s, pxs->xdoc->xpathCtx); if(pxs->xdoc->xpathObj == NULL) @@ -494,3 +510,41 @@ error: return -1; }
+int pv_xml_ns_param(modparam_t type, void *val) +{ + char *p; + param_t *ns; + + if(val==NULL) + goto error; + ns = (param_t*)pkg_malloc(sizeof(param_t)); + + if(ns==NULL) + { + LM_ERR("no more pkg\n"); + goto error; + } + memset(ns, 0, sizeof(param_t)); + + p = strchr((const char*)val, '='); + if(p==NULL) + { + ns->name.s = ""; + ns->body.s = (char*)val; + ns->body.len = strlen(ns->body.s); + } else { + *p = 0; + p++; + ns->name.s = (char*)val; + ns->name.len = strlen(ns->name.s); + ns->body.s = p; + ns->body.len = strlen(ns->body.s); + } + ns->next = _pv_xml_ns_root; + _pv_xml_ns_root = ns; + return 0; +error: + return -1; + +} + diff --git a/modules_k/presence_xml/pv_xml.h b/modules_k/presence_xml/pv_xml.h index dc14e38..7db8689 100644 --- a/modules_k/presence_xml/pv_xml.h +++ b/modules_k/presence_xml/pv_xml.h @@ -23,6 +23,7 @@ #ifndef _PV_XML_H_ #define _PV_XML_H_
+#include "../../sr_module.h" #include "../../pvar.h"
int pv_get_xml(struct sip_msg *msg, pv_param_t *param, @@ -32,4 +33,6 @@ int pv_set_xml(struct sip_msg* msg, pv_param_t *param,
int pv_parse_xml_name(pv_spec_p sp, str *in);
+int pv_xml_ns_param(modparam_t type, void *val); + #endif