<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [
  <!ENTITY rfc2119 PUBLIC '' 'bibxml/reference.RFC.2119.xml'>
  <!ENTITY rfc2616 PUBLIC '' 'bibxml/reference.RFC.2616.xml'>
  <!ENTITY rfc4918 PUBLIC '' 'bibxml/reference.RFC.4918.xml'>
  <!ENTITY W3C.REC-xml-20081126 SYSTEM 'bibxml4/reference.W3C.REC-xml-20081126.xml'>
]>

<?rfc rfcedstyle="yes" ?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?><!-- default = 3 -->
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<!--<?rfc strict="yes"?> -->
<!--<?rfc comments="yes"?> -->
<!--<?rfc inline="yes"?> -->

<rfc  category="std" ipr='pre5378Trust200902' docName='draft-daboo-webdav-sync-01'>
  <front>
    <title abbrev="WebDAV Sync">Collection Synchronization for WebDAV</title>
	<author initials="C." surname="Daboo" fullname="Cyrus Daboo">
	<organization abbrev="Apple, Inc.">Apple Inc.</organization>
	<address>
	  <postal>
		<street>1 Infinite Loop</street>
		<city>Cupertino</city>
		<region>CA</region>
		<code>95014</code>
		<country>USA</country>
	  </postal>
	  <email>cyrus@daboo.name</email>
	  <uri>http://www.apple.com/</uri>
	</address>
	</author>
    <date />
    <area>
      Applications
    </area>
    <abstract>
      <t>
        This specification defines an extension to WebDAV that allows efficient synchronization of the contents of a WebDAV collection.
      </t>
    </abstract>
  </front>
  <middle>
    <section title='Introduction'>
      <t>
        WebDAV <xref target="RFC4918"/> defines the concept of 'collections' which are hierarchical groupings of WebDAV resources on an HTTP <xref target="RFC2616" /> server. Collections can be of arbitrary size and depth (i.e., collections within collections). WebDAV clients that cache resource content need a way to synchronize that data with the server (i.e., detect what has changed and update their cache). This can currently be done using a WebDAV PROPFIND request on a collection to list all members of a collection along with their HTTP ETag values, which allows the client to determine which resources were changed, added or deleted. However this does not scale well to large collections as the XML response to the PROPFIND response will grow with the collection size.
      </t>
      <t>
        This specification defines a new WebDAV REPORT that results in the server returning to the client only information about those resources which have changed, are new or were deleted since a previous execution of the REPORT on the collection.
      </t>
      <t>
        Additionally, a new property is added to collection resources that is used to convey a "synchronization token" that is guaranteed to change when the contents of the collection have changed.
      </t>
    </section>
    <section title='Conventions Used in This Document'>
      <t>
        The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <xref target='RFC2119' />.
      </t>
	  <t>
	  	This document uses XML DTD fragments (<xref target="W3C.REC-xml-20081126"/>, Section 3.2) as a purely notational convention.  WebDAV request and response bodies cannot be validated by a DTD due to the specific extensibility rules defined in Section 17 of [RFC4918] and due to the fact that all XML elements defined by this specification use the XML namespace name "DAV:".  In particular:
		<list style='numbers'>
			<t>element names use the "DAV:" namespace,</t>
			<t>element ordering is irrelevant unless explicitly stated,</t>
			<t>extension elements (elements not already defined as valid child elements) may be added anywhere, except when explicitly stated otherwise,</t>
			<t>extension attributes (attributes not already defined as valid for this element) may be added anywhere, except when explicitly stated otherwise.</t>
		</list>
	  </t>
	  <t>
	    When an XML element type in the "DAV:" namespace is referenced in this document outside of the context of an XML fragment, the string "DAV:" will be prefixed to the element type.
	  </t>
	  <t>
        This document inherits, and sometimes extends, DTD productions from Section 14 of <xref target="RFC4918"/>.
      </t>
    </section>
    <section title="Open Issues">
<?rfc compact="no" ?>
	  <t>	
      <list style='numbers'>
        <t>
          Should we try and discriminate between changes to the body of a resource and changes to the properties?
        </t>
        <t>
          If we indicate a property change, should we return the list of properties that changed on each resource (propnames NOT values)?
        </t>
        <t>
          Should we provide a way to indicate that a 'new' resource is new in the collection as a result of a COPY or MOVE from another location, as opposed to being created?
        </t>
        <t>
          Should we provide a way to indicate that a 'deleted' resource was removed from the collection as a result of a MOVE to another location, as opposed to being actually deleted?
        </t>
        <t>
          How should ACLs be handled? e.g. a resource is visible to a user at one point in time, then its &lt;read&gt; privilege is removed. Should the resource be marked as having been deleted when next synchronized?
        </t>
        <t>
          Do we want a special indicator for a resource that was deleted and then re-created, as opposed to just indicating that the resource was 'changed'?
        </t>
      </list>
      </t>
<?rfc compact="yes" ?>
    </section>
    <section title='WebDAV Synchronization REPORT' anchor='sync-collection'>
      <section title='Overview'>
        <t>
          One way to synchronize data between two entities is to use some form of synchronization token. This defines the state of the data being synchronized at a particular point in time. That token can then be used to determine what has changed since one point in time and another.
        </t>
        <t>
          HTTP already defines a synchronization token in the form of an entity tag which is attached to a resource. However, the entity tag is not always required to be 'strong' and thus cannot be relied on absolutely as a valid synchronization indicator. In addition, there is no concept of an entity tag for a collection's contents.
        </t>
        <t>
          The is specification defines a new WebDAV REPORT that is used to enable client-server collection synchronization.
        </t>
        <t>
          In order to synchronize the contents of a collection between a server and client, the server provides the client with a synchronization token each time the synchronization REPORT is executed. That token represents the state of the data being synchronized at that point in time. The client can then present that same token back to the server at some later time and the server will return only those items that are new, have changed or were deleted since that token was generated. The server also returns a new token representing the new state at the time the REPORT was run.
        </t>
        <t>
          Typically the first time a client connects to the server it will need to be informed of the entire state of the collection (i.e., a full list of all resources that are currently contained in the collection). That is done by the client sending an empty token value to the server. This indicates to the server that a full listing is required.
        </t>
        <t>
          In some cases a server may only wish to maintain a limited amount of history about changes to a collection. In that situation it will return an error to the client when the client presents a token that is "out of date". At that point the client has to fall back to synchronizing the entire collection by re-running the report request using an empty token value.
        </t>
      </section>
      <section title='REPORT defined'>
        <t>
          This specification defines the DAV:sync-collection REPORT.
        </t>
        <t>
          If this REPORT is implemented by a WebDAV server, then the server MUST list the REPORT in the "DAV:supported-report-set" property on any collection supporting synchronization. If the report is not available, clients MUST NOT attempt to execute one.
        </t>
        <t>
          To implement the behavior for this REPORT a server needs to keep track of changes to any resources in a collection. This includes noting the addition of new resources, changes to existing resources and removal of resources (where "removal" could be the result of a DELETE or MOVE WebDAV request). The server will track each change and provide a synchronization "token" to the client that describes the state of the server at a specific point in time. This "token" is returned as part of the response to the "sync-collection" report. Clients include the last token they got from the server in the next "sync-collection" report that they execute and the server provides the changes from the previous state represented by the token to the current state, represented by the new token returned.
        </t>
        <t>
          The synchronization token itself is an "opaque" string - i.e., the actual string data has no specific meaning or syntax. A simple implementation of such a token would be a numeric counter that counts each change as it occurs and relates that change to the specific object that changed.
        </t>
        <t>
          Marshalling:
          <list>
            <t>
              The request URI MUST be a collection. The "Depth" header MUST be ignored by the server and SHOULD NOT be sent by the client. The request body MUST be a DAV:sync-collection XML element (see
              <xref target="sync_collection_element" />, which MUST contain one DAV:sync-token XML element, and optionally a DAV:propstat XML element.
            </t>
            <t>
              The response body for a successful request MUST be a DAV:multistatus XML element, which MUST contain one DAV:sync-token element in addition to any DAV:sync-response elements.
            </t>
            <t>
              The response body for a successful DAV:sync-collection REPORT request MUST contain a DAV:sync-response element for each resource that was created, has changed or been deleted since the last synchronization operation as specified by the DAV:sync-token provided in the request.
            </t>
            <t>
              The DAV:status element in each DAV:sync-response element is used to indicate how the resource may have changed:
              <list>
                <t>
                  A status code of '201 Created' is used to indicate resources that are new.
                </t>
                <t>
                  A status code of '200 OK' is used to indicate resources that have changed.
                </t>
                <t>
                  A status code of '404 Not Found' is used to indicate resources that have been removed.
                </t>
              </list>
            </t>
          </list>
        </t>
        <t>
          Preconditions:
          <list>
            <t>
              (DAV:valid-sync-token): The DAV:sync-token element value MUST map to a valid token previously returned by the server;
            </t>
          </list>
        </t>
        <t>
          Postconditions:
          <list>
            <t>
              None.
            </t>
          </list>
        </t>
      </section>
      <section title="Example: Initial DAV:sync-collection REPORT">
        <t>
          In this example, the client is making its first synchronization request to the server, so the DAV:sync-token element in the request is empty, and it also asks for the DAV:getetag property. The server responds with the items currently in the targeted collection (indicating that they are 'new' via the '201 Created' status code). The current synchronization token is also returned.
        </t>
        <figure>
          <preamble>
            &gt;&gt; Request &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
REPORT /home/cyrusdaboo/ HTTP/1.1
Host: webdav.example.com
Content-Type: text/xml; charset="utf-8"
Content-Length: xxxx

<?xml version="1.0" encoding="utf-8" ?>
<D:sync-collection xmlns:D="DAV:">
  <D:sync-token/>
  <D:prop>
    <D:getetag/>
  </D:prop>
</D:sync-collection>
]]>
          </artwork>
        </figure>
        <figure>
          <preamble>
            &gt;&gt; Response &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
HTTP/1.1 207 Multi-Status
Content-Type: text/xml; charset="utf-8"
Content-Length: xxxx

<?xml version="1.0" encoding="utf-8" ?>
<D:multistatus xmlns:D="DAV:">
  <D:sync-response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/test.doc</D:href>
  <D:status>HTTP/1.1 201 Created</D:status>
  <D:propstat>
    <D:prop>
      <D:getetag>"00001-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:sync-response>
  <D:sync-response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/vcard.vcf</D:href>
  <D:status>HTTP/1.1 201 Created</D:status>
  <D:propstat>
    <D:prop>
      <D:getetag>"00002-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:sync-response>
  <D:sync-response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/calendar.ics</D:href>
  <D:status>HTTP/1.1 201 Created</D:status>
  <D:propstat>
    <D:prop>
      <D:getetag>"00003-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:sync-response>
  <D:sync-token>1234</D:sync-token>
</D:multistatus>
]]>
          </artwork>
        </figure>
      </section>
      <section title="Example: DAV:sync-collection Report with token">
        <t>
          In this example, the client is making a synchronization request to the server and is using the DAV:sync-token element returned from the last report it ran on this collection. The server responds listing the items that have been added, changed or removed. The (new) current synchronization token is also returned.
        </t>
        <figure>
          <preamble>
            &gt;&gt; Request &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
REPORT /home/cyrusdaboo/ HTTP/1.1
Host: webdav.example.com
Content-Type: text/xml; charset="utf-8"
Content-Length: xxxx

<?xml version="1.0" encoding="utf-8" ?>
<D:sync-collection xmlns:D="DAV:">
  <D:sync-token>1234</D:sync-token>
  <D:prop>
    <D:getetag/>
  </D:prop>
</D:sync-collection>
]]>
          </artwork>
        </figure>
        <figure>
          <preamble>
            &gt;&gt; Response &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
HTTP/1.1 207 Multi-Status
Content-Type: text/xml; charset="utf-8"
Content-Length: xxxx

<?xml version="1.0" encoding="utf-8" ?>
<D:multistatus xmlns:D="DAV:">
  <D:sync-response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/file.xml</D:href>
  <D:status>HTTP/1.1 201 Created</D:status>
  <D:propstat>
    <D:prop>
      <D:getetag>"00004-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:sync-response>
  <D:sync-response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/vcard.vcf</D:href>
  <D:status>HTTP/1.1 200 OK</D:status>
  <D:propstat>
    <D:prop>
      <D:getetag>"00002-abcd2"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:sync-response>
  <D:sync-response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/test.doc</D:href>
  <D:status>HTTP/1.1 404 Not Found</D:status>
  </D:sync-response>
  <D:sync-token>1238</D:sync-token>
</D:multistatus>
]]>
          </artwork>
        </figure>
      </section>
    </section>
    <section title="XML Element Definitions">
      <section title="DAV:sync-collection XML Element" anchor="sync_collection_element">
        <t>
          <list style="hanging">
            <t hangText="Name:">
              sync-collection
            </t>
            <t hangText="Namespace:">
              DAV:
            </t>
            <t hangText="Purpose:">
              WebDAV report used to synchronize data between client and server.
            </t>
            <t hangText="Description:">
              See <xref target="sync-collection" />.
            </t>
          </list>
        </t>
        <figure>
          <artwork>
<![CDATA[
<!ELEMENT sync-collection (sync-token, DAV:prop?)>
]]>
          </artwork>
        </figure>
        <section title="DAV:sync-token XML Element" anchor="sync_token_element">
          <t>
            <list style="hanging">
              <t hangText="Name:">
                sync-token
              </t>
              <t hangText="Namespace:">
                DAV:
              </t>
              <t hangText="Purpose:">
                The synchronization token provided by the server and returned by the client.
              </t>
              <t hangText="Description:">
                See <xref target="sync-collection" />.
              </t>
            </list>
          </t>
          <figure>
            <artwork>
<![CDATA[
<!ELEMENT sync-token CDATA>
]]>
            </artwork>
          </figure>
        </section>
        <section title="DAV:multistatus XML Element" anchor="multistatus_element">
          <t>
            <list style="hanging">
              <t hangText="Name:">
                multistatus
              </t>
              <t hangText="Namespace:">
                DAV:
              </t>
              <t hangText="Purpose:">
                Extends the DAV:multistatus element to include synchronization details.
              </t>
              <t hangText="Description:">
                See <xref target="sync-collection" />.
              </t>
            </list>
          </t>
          <figure>
            <artwork>
<![CDATA[
<!ELEMENT multistatus ((DAV:response*, DAV:responsedescription?) |
             (DAV:sync-response*, DAV:sync-token,
              DAV:responsedescription?))>
]]>
            </artwork>
          </figure>
        </section>
        <section title="DAV:sync-response XML Element" anchor="sync_response_element">
          <t>
            <list style="hanging">
              <t hangText="Name:">
                sync-response
              </t>
              <t hangText="Namespace:">
                DAV:
              </t>
              <t hangText="Purpose:">
                Contains the synchronization results returned by the server.
              </t>
              <t hangText="Description:">
                See <xref target="sync-collection" />.
              </t>
            </list>
          </t>
          <figure>
            <artwork>
<![CDATA[
<!ELEMENT sync-response (DAV:href, DAV:status, DAV:propstat?)>
]]>
            </artwork>
          </figure>
        </section>
      </section>
    </section>
    <section title='Security Considerations'>
      <t>
        This extension does not introduce any new security concerns than those already described in HTTP and WebDAV.
      </t>
    </section>
    <section title='IANA Considerations'>
      <t>
        This document does not require any actions on the part of IANA.
      </t>
    </section>
    <section title='Acknowledgments'>
	  <t>
		The following individuals contributed their ideas and support for writing this specification: Bernard Desruisseaux, Mike Douglass, Arnaud Quillaud, and Julian Reschke.
	  </t>
    </section>
  </middle>
  <back>
    <references title='Normative References'>
      &rfc2119;
      &rfc2616;
      &rfc4918;
      &W3C.REC-xml-20081126;
    </references>
    <!--<references title='Informative References'>
    </references>-->

<section title='Change History (to be removed prior to publication as an RFC)'>

<t>Changes in -01:
<list style='numbers'>
<t>Updated to 4918 reference.</t>
<t>Fixed examples to properly include DAV:status in DAV:propstat</t>
<t>Switch to using XML conventions text from RFC5323.</t>
</list>
</t>

</section>

  </back>
</rfc>
