Ticket #46 (closed Defect: To be investigated)

Opened 8 months ago

Last modified 7 months ago

PUT new element

Reported by: raf_n Owned by: Mircea Amarascu
Priority: Minor Milestone:
Component: XCAP protocol Version:
Severity: Non-critical Keywords:
Cc:

Description

When trying to put a new element in an xml document we receive an exception. Problem is in xcap/appusage/init.py line 125: def _create_element(self, parent, terminal_selector, elem):

left = target.find('[')

variable target is not global, parameter terminal_selector should be renamed to target.

The testcases don't cover this scenario, they only replace existing elements (function _replace_element).

After fixing this issue i tried to put an element in a presence-document, but i still couldn't get it to work... No exception and response is 200 OK...

Existing xml document:

<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns="urn:ietf:params:xml:ns:common-policy" xmlns:pr="urn:ietf:params:xml:ns:pres-rules" xmlns:cp="www.counterpath.com/privacy-lists">

<rule id="bleh"/>

</ruleset>

PUT [url]/pres-rules/users/test01@domain.com/pres_rules/~ ~/cp:ruleset/cp:rule[1]/?xmlns(pr=urn:ietf:params:xml:ns:pres-rules)?xmlns(cp=urn:ietf:params:xml:ns:common-policy)

body = <rule id="pres_whitelist"> <conditions> <identity> <one id="sip:2233350608@sip2sip.info"/> <one id="sip:31208005164@ag-projects.com"/> </identity> </conditions> <actions> <pr:sub-handling>allow</pr:sub-handling> </actions> <transformations> <pr:provide-services> <pr:all-services/> </pr:provide-services> <pr:provide-persons> <pr:all-persons/> </pr:provide-persons> <pr:provide-devices> <pr:all-devices/> </pr:provide-devices> <pr:provide-all-attributes/> </transformations> </rule>

Content-Type: application/xcap-el+xml

response = 409

Change History

follow-up: ↓ 2   Changed 8 months ago by admin

  • status changed from new to closed

This is a known issue and will be addressed as soon as possible. There are no clients to test this with yet. If you could add a patch that fixes it and a test case it would be great. Thanks.

in reply to: ↑ 1   Changed 7 months ago by raf_n

This is a known issue and will be addressed as soon as possible. There are no clients to test this with yet.

You can always test these queries with curl:

curl [url]/pres-rules/users/test01@domain.com/pres_rules/~ ~/cp:ruleset/cp:rule[1]/?xmlns(pr=urn:ietf:params:xml:ns:pres-rules)?xmlns(cp=urn:ietf:params:xml:ns:common-policy) -h "Content-Type: application/xcap-el+xml" -T [path-to-file-with-presence-rule]

If you could add a patch that fixes it and a test case it would be great. Thanks.

Unfortunately i dont have a fix for this issue, i only changed the obvious mistake in parameter name...

  Changed 7 months ago by raf_n

Patch for this issue + issue http://openxcap.org/ticket/46 is pasted below.

Renaming the parameter did fix the issue, but i forgot to put namespaces in my xml-element...

So the correct query is:

PUT [url]/pres-rules/users/test01@domain.com/pres_rules/~ ~/cp:ruleset/cp:rule[@id="rule9"]/?xmlns(pr=urn:ietf:params:xml:ns:pres-rules)?xmlns(cp=urn:ietf:params:xml:ns:common-policy)

body = <rule id="rule9" xmlns="urn:ietf:params:xml:ns:common-policy" xmlns:pr="urn:ietf:parmas:xml:ns:pres-rules">

<conditions>

<identity> <one id="sip:test@domain.com"/> </identity>

</conditions> <actions> <pr:sub-handling>allow</pr:sub-handling> </actions> <transformations/>

</rule>

Content-Type: application/xcap-el+xml

Patch:

--- C:\development\xcap\openxcap-0.9.9\openxcap-0.9.9\xcap\appusage\init.py 2007-10-17 16:28:12.000000000 +-0200 +++ C:\development\xcap\openxcap-0.9.9\openxcap-0.9.9\xcap\appusage\init-new.py 2008-04-15 16:35:49.000000000 +-0200 @@ -16,11 +18,13 @@

from twisted.internet import defer from twisted.python import failure

from xcap.errors import * from xcap.interfaces.backend import StatusResponse

+import traceback

supported_applications = ('xcap-caps', 'pres-rules', 'org.openmobilealliance.pres-rules',

'resource-lists', 'pidf-manipulation', 'watchers')

class EnabledApplications(StringList):

def new(typ, value):

@@ -119,13 +123,13 @@

def delete_document(self, uri, check_etag):

return self.storage.delete_document(uri, check_etag)

## Element management

- def _create_element(self, parent, terminal_selector, elem): + def _create_element(self, parent, target, elem):

left = target.find('[') if left == -1:

name = target position = None

else:

name = target[:left]

@@ -202,17 +206,27 @@

"""This is called when the document that relates to the element is retreived."""

if response.code == 404:

raise ResourceNotFound

document = response.data

+ #document = '<?xml version="1.0" encoding="UTF-8"?> <foo xmlns="urn:ietf:params:xml:ns:common-policy" xmlns:pr="urn:ietf:params:xml:ns:pres-rules" xmlns:cp="www.counterpath.com/privacy-lists" ><bar></bar></foo>'

xml_doc = etree.parse(StringIO(document)) node_selector = uri.node_selector application = getApplicationForURI(uri)

ns_dict = node_selector.get_xpath_ns_bindings(application.default_ns) try:

- selector = node_selector.element_selector + '/' + node_selector.terminal_selector + selector = node_selector.element_selector + if node_selector.terminal_selector != None: + selector += '/' + node_selector.terminal_selector

elem = xml_doc.xpath(selector, ns_dict)

- except: + except Exception, e: + print traceback.format_exc()

raise ResourceNotFound

if not elem:

raise ResourceNotFound

# TODO # The server MUST NOT add namespace bindings representing namespaces

Note: See TracTickets for help on using tickets.