Portable-WebDAV-Library icon indicating copy to clipboard operation
Portable-WebDAV-Library copied to clipboard

owner element should allow any content

Open fubar-coder opened this issue 9 years ago • 18 comments

According to RFC 4918, Section 14.17, the owner element "MAY be extended with child elements, mixed content, text content or attributes".

fubar-coder avatar Feb 20 '17 19:02 fubar-coder

I guess, that the best way to support this would be converting owner to an XElement and adding a [XmlAnyElement(Name = WebDavConstants.Owner, Namespace = "DAV:")] attribute.

fubar-coder avatar Feb 21 '17 07:02 fubar-coder

Wouldn't this be a so called dead property?

DecaTec avatar Feb 21 '17 07:02 DecaTec

This is what the spec says: The value provided MUST be treated as a dead property in terms of XML Information Item preservation.

IOW: It must be treated like a dead property, but it isn't one.

fubar-coder avatar Feb 21 '17 07:02 fubar-coder

Another possibility would be to use an ExtensionDataObject in the class OwnerHref, see here: http://stackoverflow.com/questions/8520228/using-xmlanyelement

Then, any unknown content is stored in a special property.

DecaTec avatar Feb 21 '17 07:02 DecaTec

Does this work with mixed content and attributes too?

fubar-coder avatar Feb 21 '17 08:02 fubar-coder

I'll try to get a unit test in place. If I get this right, the server returns (as as example):

Content-Type: text/xml; charset="utf-8" 
Content-Length: xxx 

<?xml version="1.0" encoding="utf-8" ?> 
<D:multistatus xmlns:D="DAV:">  
  <D:response>  
    <D:href>http://www.example.com/papers/</D:href> 
    <D:propstat> 
      <D:prop> 
        <D:owner>
			<D:href>http://www.example.com/users/jd</D:href>     
			<x:author xmlns:x='http://example.com/ns'>
			  <x:name>Jane Doe</x:name>
			  <!-- Jane's contact info -->
			  <x:uri type='email' added='2005-11-26'>mailto:[email protected]</x:uri>
			  <x:uri type='web' added='2005-11-27'>http://www.example.com</x:uri>
			  <x:notes xmlns:h='http://www.w3.org/1999/xhtml'>
				Jane has been working way <h:em>too</h:em> long on the  
				long-awaited revision of <![CDATA[<RFC2518>]]>.
			  </x:notes>
			</x:author>
        </D:owner> 
      </D:prop> 
      <D:status>HTTP/1.1 200 OK</D:status> 
    </D:propstat> 
  </D:response> 
</D:multistatus>```

DecaTec avatar Feb 21 '17 08:02 DecaTec

The server may also return

<D:owner xmlns:x='urn:other-schema-provider:other-schema' x:myattr='test-attr'>
  Test
  <x:whatever>test</x:whatever>
</D:owner>

fubar-coder avatar Feb 21 '17 08:02 fubar-coder

I didn't have much time today, but I've tried to implement it (sorry, it's a bit quick & dirty): See branch: https://github.com/DecaTec/Portable-WebDAV-Library/tree/owner-element-with-any-content

A unit test can be found in the NetFX part: \netfx\unittests\decatec.webdav.netfx.unittest\unittestwebdavresponsecontentparser.cs

Now an OwnerHref instance can contain any content (next to the Href, this will stay). But due to being an XElement, it more or less raw XML.

Could you please have a look? Do you have any special use case where you'll need that feature?

DecaTec avatar Feb 21 '17 19:02 DecaTec

It's slightly better, but it still doesn't allow the owner content I posted in my previous comment. It might be OK for most users and I only see one situation where your current solution isn't good enough:

When you do a lockdiscovery and get the owner of an active lock of a different user using a different WebDAV client that stores the owner like this: <D:owner>owner-name</D:owner>.

TBH: I'd really break compatibility and scrap the owner object and replace it with a single XElement. Breaking compatibility at a version <1.0 shouldn't be a huge problem.

fubar-coder avatar Feb 21 '17 21:02 fubar-coder

I've tried to provide the owner as XElement, but ran into another problem: The main reason for introducing the "object model" was that the client won't have to fiddle around with raw XML. By the need of specifying the owner as XElement, this solution wasn't straightforward in the first place.

My next approach: On LockInfo and ActiveLock, there are two properties now:

  • OwnerHref: This is treated like the "old" OwnerHref, i.e. an owner can be specified by href (e.g. e mail address), this is only a string value
  • OwnerRaw: This gives you the raw XElement with all its contents (to be used with mixed content, etc.)

You can find the changes in the "owner branch": https://github.com/DecaTec/Portable-WebDAV-Library/tree/owner-element-with-any-content

I've also put up some unit tests for testing the examples from this issue. The only drawback is when getting the OwnerRaw, the namespace prefixes for "DAV:" are missing ("D:").

But this way you should get all the information needed. Would you mind to take another look if this solution will fit your needs?

Edit: Unit tests for the new implementation can be found in UnitTestWebDavResponseContentParser.cs (NetFx and UWP)

DecaTec avatar Feb 23 '17 18:02 DecaTec

@fubar-coder: Do the changes fit your needs or is there still something missing?

DecaTec avatar Mar 01 '17 18:03 DecaTec

I wasn't able to test the changes yet, sorry.

fubar-coder avatar Mar 01 '17 21:03 fubar-coder

I have just tested this version with our code and this suits our needs. :shipit:

TomGroeneboer avatar Mar 06 '17 10:03 TomGroeneboer

Setting OwnerHref doesn't work. It fails with the following exception: System.Xml.XmlException : The ':' character, hexadecimal value 0x3A, cannot be included in a name.. I tried to set it with:

new LockInfo()
{
	LockScope = LockScope.CreateExclusiveLockScope(),
	LockType = LockType.CreateWriteLockType(),
	OwnerHref = "http://localhost/uri-owner",
}

fubar-coder avatar Mar 06 '17 13:03 fubar-coder

OK, I'll fix the exception with invalid chars and prepare a new version then.

DecaTec avatar Mar 06 '17 13:03 DecaTec

Just created a PR to fix this issue.

fubar-coder avatar Mar 06 '17 13:03 fubar-coder

Thanks for contributing! I've merged all into the main branch and will put together a new version of the lib tomorrow.

DecaTec avatar Mar 06 '17 19:03 DecaTec

Prepared and released update. NuGet package should be available soon.

DecaTec avatar Mar 07 '17 18:03 DecaTec