Hello,
inserting a new node seems not to be possible through xpath operations
only, so I made a patch to be able to add new nodes (entries) -- see it
attached -- it is for devel version (master branch), hopefully it
applies clean to 3.1 if you are using that version.
There was no option to test it at all, I just made sure it compiles. Let
me know the results, if it runs but fails, send me the output with
debug=4. If all is ok, I will commit to git repository.
Cheers,
Daniel
On 9/7/11 3:21 PM, laura testi wrote:
Hi,
we have patch the xcap_misc.h with "#define XCAP_MAX_URI_SIZE 255"
which was 127, and extended the length of field doc_uri in the xcap
table to 256 from 128. Now the errror is gone.
After that we have done some test with curl, following are the results:
- DELETE an Entry from the list: OK
i.e.: curl -X DELETE
http://<ip>:5060/xcap-root/resource-lists/users/sip:user@domain/index/~~/resource-lists/list/entry%5b@uri=%22sip:u1@d1%22%5d
after this command, the contact u1@d1 is removed from the contact list.
- UPDATE an Entry from the list: OK
i.e.,
curl -T entry.xml -X PUT
http://<ip>:5060/xcap-root/resource-lists/users/sip:user@domain/index/~~/resource-lists/list%5b@name=%22RootGroup%22%5d/entry%5b@uri=%22sip:u2@d2%22%5d
if the sip:u2@d2 entry exists, the entry is replaced with the entry in
the entry.xml (<entry
uri="sip:u3@d3"><display-name>u3</display-name></entry>), which is
sip:u3@d3
if the sip:u2@d2 entry is not exists, the entry of u3@d3 is not added
to the list!!! follow the rfc4825, it should be added to the list if
the entry does not exits.
- Add an Entry from the list: KO
i.e.,
curl -T entry.xml -X PUT
http://<ip>:5060/xcap-root/resource-lists/users/sip:user@domain/index/~~/resource-lists/list%5b@name=%22RootGroup%22%5d/entry%5b@uri=%22sip:u2@d2%22%5d
the entry.xml is (<entry
uri="sip:u2@d2"><display-name>u2</display-name></entry>)
the entry sip:u2@d2 was not in the list before the command and is not
added after the command.
I think it's a bug of xcap server.
Many thanks!
Laura
On Wed, Sep 7, 2011 at 12:17 PM, Juha Heinanen<j...@tutpro.com> wrote:
Daniel-Constantin Mierla writes:
Feel free to do it, however I think it has to be reviewed where is used,
though -- it should be safe even size in db is longer as long as the
insert is done by kamailio itself, not sure we have affected cases when
the insert is done by external apps, so better double check...
every module that reads data from db should check size of received
string so that it is not longer than space reserved for it in data
structures. i hope that no module assumes that received data cannot be
bigger than what db schema says.
-- juha
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
--
Daniel-Constantin Mierla -- http://www.asipto.com
Kamailio Advanced Training, Oct 10-13, Berlin: http://asipto.com/u/kat
http://linkedin.com/in/miconda -- http://twitter.com/miconda
diff --git a/modules_k/xcap_server/xcap_misc.c
b/modules_k/xcap_server/xcap_misc.c
index 57abf3f..89ae3a1 100644
--- a/modules_k/xcap_server/xcap_misc.c
+++ b/modules_k/xcap_server/xcap_misc.c
@@ -433,13 +433,18 @@ int xcaps_xpath_set(str *inbuf, str *xpaths, str *val,
str *outbuf)
xmlNodePtr parent = NULL;
int size;
int i;
+ char *p;
doc = xmlParseMemory(inbuf->s, inbuf->len);
if(doc == NULL)
return -1;
if(val!=NULL)
+ {
newnode = xmlParseMemory(val->s, val->len);
+ if(newnode==NULL)
+ goto error;
+ }
outbuf->s = NULL;
outbuf->len = 0;
@@ -462,12 +467,53 @@ int xcaps_xpath_set(str *inbuf, str *xpaths, str *val,
str *outbuf)
nodes = xpathObj->nodesetval;
if(nodes==NULL)
{
+ /* no selection for xpath expression */
LM_DBG("no selection for xpath expression [%s]\n", xpaths->s);
- goto done;
- }
- size = nodes->nodeNr;
- if(val!=NULL)
- value = (const xmlChar*)val->s;
+ if(val==NULL)
+ goto done;
+ /* could be an insert - locate the selection of parent node */
+ p = strrchr(xpaths->s, '/');
+ if(p==NULL)
+ goto done;
+ /* evaluate xpath expression for parrent node */
+ *p = 0;
+ xpathObj = xmlXPathEvalExpression(
+ (const xmlChar*)xpaths->s, xpathCtx);
+ if(xpathObj == NULL)
+ {
+ LM_DBG("unable to evaluate xpath parent expression
[%s]\n",
+ xpaths->s);
+ *p = '/';
+ goto done;
+ }
+ *p = '/';
+ nodes = xpathObj->nodesetval;
+ if(nodes==NULL)
+ {
+ LM_DBG("no selection for xpath parent expression
[%s]\n",
+ xpaths->s);
+ goto done;
+ }
+ /* add the new content as child to first selected element node
*/
+ if(nodes->nodeTab[0]==NULL)
+ {
+ LM_DBG("selection for xpath parent expression has first
child"
+ " NULL [%s]\n", xpaths->s);
+ goto done;
+ }
+ if(nodes->nodeTab[0]->type==XML_ELEMENT_NODE)
+ {
+ xmlAddChild(nodes->nodeTab[0],
xmlCopyNode(newnode->children, 1));
+ } else {
+ LM_DBG("selection for xpath parent expression is not
element"
+ " node [%s]\n", xpaths->s);
+ goto done;
+ }
+ } else {
+ /* selection for xpath expression */
+ size = nodes->nodeNr;
+ if(val!=NULL)
+ value = (const xmlChar*)val->s;
/*
* NOTE: the nodes are processed in reverse order, i.e. reverse document
@@ -477,22 +523,22 @@ int xcaps_xpath_set(str *inbuf, str *xpaths, str *val,
str *outbuf)
* they get removed. Mixing XPath and modifications on a tree
must be
* done carefully !
*/
- for(i = size - 1; i >= 0; i--) {
- if(nodes->nodeTab[i]==NULL)
- continue;
-
- if(nodes->nodeTab[i]->type==XML_ELEMENT_NODE)
- {
- parent = nodes->nodeTab[i]->parent;
- xmlUnlinkNode(nodes->nodeTab[i]);
- if(val!=NULL && newnode!=NULL)
- xmlAddChild(parent,
xmlCopyNode(newnode->children, 1));
- } else {
- if(val!=NULL)
- xmlNodeSetContent(nodes->nodeTab[i], value);
- else
- xmlNodeSetContent(nodes->nodeTab[i], (const
xmlChar*)"");
- }
+ for(i = size - 1; i >= 0; i--) {
+ if(nodes->nodeTab[i]==NULL)
+ continue;
+
+ if(nodes->nodeTab[i]->type==XML_ELEMENT_NODE)
+ {
+ parent = nodes->nodeTab[i]->parent;
+ xmlUnlinkNode(nodes->nodeTab[i]);
+ if(val!=NULL && newnode!=NULL)
+ xmlAddChild(parent,
xmlCopyNode(newnode->children, 1));
+ } else {
+ if(val!=NULL)
+ xmlNodeSetContent(nodes->nodeTab[i],
value);
+ else
+ xmlNodeSetContent(nodes->nodeTab[i],
(const xmlChar*)"");
+ }
/*
* All the elements returned by an XPath query are pointers to
* elements from the tree *except* namespace nodes where the
XPath
@@ -510,8 +556,9 @@ int xcaps_xpath_set(str *inbuf, str *xpaths, str *val, str
*outbuf)
* - remove the reference to the modified nodes from the node
set
* as they are processed, if they are not namespace nodes.
*/
- if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL)
- nodes->nodeTab[i] = NULL;
+ if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL)
+ nodes->nodeTab[i] = NULL;
+ }
}
xmlDocDumpMemory(doc, &xmem, &size);
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users