<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../rfc2629.xslt"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [
  <!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
  <!ENTITY rfc2616 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2616.xml'>
  <!ENTITY rfc3744 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3744.xml'>
  <!ENTITY rfc4791 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4791.xml'>
  <!ENTITY rfc4918 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4918.xml'>
  <!ENTITY rfc5323 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5323.xml'>
  <!ENTITY webdavbind PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-webdav-bind.xml'>
  <!ENTITY carddav PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-vcarddav-carddav.xml'>
  <!ENTITY W3C.REC-xml-20081126 SYSTEM 'http://xml.resource.org/public/rfc/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-03' xmlns:x='http://purl.org/net/xml2rfc/ext'>
  <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>
    <author initials="A." surname="Quillaud" fullname="Arnaud Quillaud">
    <organization abbrev="Sun Microsystems">Sun Microsystems</organization>
    <address>
      <postal>
        <street>180, Avenue de l'Europe</street>
        <city>Saint Ismier cedex</city>
        <region></region>
        <code>38334</code>
        <country>France</country>
      </postal>
      <email>arnaud.quillaud@sun.com</email>
      <uri>http://www.sun.com/</uri>
    </address>
    </author>
    <date year="2010" month="March" day="8" />
    <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>
    <note title="Editorial Note (To be removed by RFC Editor before publication)">
      <t>
        Please send comments to the
        Distributed Authoring and Versioning (WebDAV) working group at <eref target="mailto:w3c-dist-auth@w3.org"/>, which may be joined by sending a message with subject
        "subscribe" to <eref target="mailto:w3c-dist-auth-request@w3.org"/>.
        Discussions of the WEBDAV working group are archived at
        <eref target="http://lists.w3.org/Archives/Public/w3c-dist-auth/"/>.
      </t>
    </note>
  </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 DAV:getetag property 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 request 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 resources within 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='WebDAV Synchronization' anchor='sync-collection'>
      <section title='Overview'>
        <t>
          One way to synchronize data between two entities is to use some form of synchronization token. The token defines
          the state of the data being synchronized at a particular point in time. It can then be used to determine what has
          changed since one point in time and another.
        </t>
        <t>
          This specification defines a new WebDAV report that is used to enable client-server collection synchronization based on such a token.
        </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>
          As an alternative, the client may choose to do its first synchronization using some other mechanism on the collection (e.g. some other
          form of batch resource information retrieval such as PROPFIND, SEARCH <xref target="RFC5323"/>, or specialized REPORTs such as those defined in
          CalDAV <xref target="RFC4791"/> and CardDAV <xref target="I-D.ietf-vcarddav-carddav"/>) and ask for the DAV:sync-token property to be returned.
          This property (defined in <xref target="sync_property" />) contains the same token that can
          be used later on to issue a DAV:sync-collection report.
        </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='DAV:sync-collection Report'>
        <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.
        </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.
          Only internal members of the collection (as defined in <xref target="RFC4918" x:fmt="of" x:sec="3"/>) are to be considered.
          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 identify a collection. 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 one DAV:prop XML element.
            </t>
            <t>
                The request MUST include a Depth header with a value of "1".
            </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 one DAV: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.
              A given resource MUST appear only once in the response.
            </t>
            <t>
              The content of each DAV:response element differs depending on how the resource was altered:
              <list>
                <t>
                  For resources that have changed (i.e. are new or have been modified) the DAV:response MUST contain at least one
                  DAV:propstat element and MUST NOT contain any DAV:status element.
                </t>
                <t>
                  For resources that have been removed, the DAV:response MUST contain one DAV:status with a value set to '404 Not Found'
                  and MUST NOT contain any DAV:propstat element.
                </t>
              </list>
            </t>
            <t>
                The conditions under which each type of change may occur is further described in <xref target="change-types" />.
            </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. A token
              may become invalid as the result of being "out of date" (out of the range of change history maintained by the server), or for
              other reasons (e.g. collection deleted, then recreated, ACL changes, etc...).
            </t>
          </list>
        </t>
        <t>
          Postconditions:
          <list>
            <t>
				(DAV:number-of-matches-within-limits): The number of changes reported in the response must fall within the client specified limit. This condition might be triggered if a client requests a limit on the number of responses (as per <xref target="limits"/>) but the server is unable to truncate the result set at or below that limit. 
            </t>
          </list>
        </t>
      </section>
      <section title="Types of Changes Reported on Initial Synchronization">
          <t>
              When the DAV:sync-collection request does not contain a sync-token, the server MUST return
              all internal members of the collection and it MUST NOT return any removed resource.
          </t>
      </section>
      <section title="Types of Changes Reported on Subsequent Synchronizations" anchor='change-types'>
          <t>
              When the DAV:sync-collection request contains a valid sync-token, two types
              of resource state changes can be returned (changed or removed).
              This section defines what triggers each of these to be returned. It also clarifies the case where a resource
              may have undergone multiple changes in between two synchronizations.
          </t>
          <section title="Changed Resource">
              <t>
                A resource MUST be reported as changed if it has been mapped directly under the target collection since the request sync token was generated.
                This includes resources that have been mapped as the result of a COPY, MOVE or BIND (<xref target="I-D.ietf-webdav-bind"/>) operation.
                This also includes collection resources that have been created.
              </t>
              <t>
                In the case where a mapping between a resource and the target collection was removed,
                then a new mapping with the same URI created, the new resource MUST be reported as changed
                while the old resource MUST NOT be reported as removed.
                For example, if a resource was deleted, then recreated using the same URI, it should be reported as a changed resource only.
              </t>
              <t>
                  A resource MUST be reported as changed if its entity tag value
                  (defined in <xref target="RFC2616" x:fmt="of" x:sec="3.11"/>) has changed since the request sync token
                  was  generated.
              </t>
              <t>
                  A resource MAY be reported as changed if the user issuing the request was granted access
                  to this resource, due to access control changes.
              </t>
              <t>
                  Collection resources MUST NOT be returned as changed, except in the case stated above. Instead clients are expected to synchronize
                  changes in child collection resources on an individual basis.
              </t>
          </section>
          <section title="Removed Resource">
              <t>
                  A resource MUST be reported as removed if its mapping under the target collection has been removed
                  since the request sync token was generated, and it has not been re-mapped since it was removed.  This
                  includes resources that have been unmapped as the result of a MOVE or UNBIND (<xref target="I-D.ietf-webdav-bind"/>) operation.
                  This also includes collection resources that have been removed.
              </t>
              <t>
                  If a resource was created (and possibly modified), then removed in between two synchronizations,
                  it MUST be reported as removed.
              </t>
              <t>
                  A resource MAY be reported as removed if the user issuing the request no longer has access to this resource,
                  due to access control changes.
              </t>
          </section>
      </section>
      <section title="Truncation of Results">
          <t>
              A server MAY limit the number of resources in a response, for example, to limit the amount of work expended in processing a request, or as the result of an explicit limit set by the client. If the result set is truncated, the response MUST use status code 207, return a DAV:multistatus response body, and indicate a status of 507 (Insufficient Storage) for the request URI. That DAV:response element SHOULD include a DAV:error element with the DAV:number-of-matches-within-limits precondition, as defined in <xref target="RFC3744"/> (Section 9.2). DAV:response elements for all the changes being reported are also included.
          </t>
          <t>
              When truncation occurs, the DAV:sync-token value returned in the response MUST represent the correct state for the partial set of changes returned. That allows the client to use the returned DAV:sync-token to fetch the next set of changes. In this way the client can effectively "page" through the entire set of changes in a consistent manner.
          </t>
          <t>
              Clients MUST handle the 507 status on the request-URI in the response to the report.
          </t>
          <t>
              For example, consider a server that records changes using a monotonically increasing integer to represent a "revision number" and uses that quantity as the DAV:sync-token value. Assume the last DAV:sync-token used by the client was "10", and since then 20 additional changes have occurred. If the client executes a DAV:sync-collection request with a DAV:sync-token of "10", without a limit the server would return 20 DAV:response elements and a DAV:sync-token with value "30". But if the server choose to limit responses to at most 10 changes, then it would return only 10 DAV:response elements and a DAV:sync-token with value "20", together with an addition DAV:response element for the request-URI with a status code of 507. Subsequently, the client can re-issue the request with the DAV:sync-token value returned from the server and fetch the remaining 10 changes.
          </t>
      </section>
      <section title="Limiting Results" anchor="limits">
          <t>
              A client can limit the number of results returned by the server through use of the DAV:limit element (<xref target="RFC5323"/>, Section 5.17) in the request body. This is useful when clients have limited space or bandwidth for the results. If a server is unable to truncate the result at or below the requested number, then it MUST fail the request with a DAV:number-of-matches-within-limits post-condition error. When the results can be correctly limited by the server, the server MUST follow the rules above for indicating a result set truncation to the client.
          </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. It also asks for the DAV:getetag property and for a proprietary property.
          The server responds with the items currently in the targeted collection. 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
Depth: 1
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 xmlns:R="urn:ns.example.com:boxschema">
    <D:getetag/>
    <R:bigbox/>
  </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:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/test.doc</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00001-abcd1"</D:getetag>
      <R:bigbox xmlns:R="urn:ns.example.com:boxschema">
        <R:BoxType>Box type A</R:BoxType>
      </R:bigbox>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:response>
  <D:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/vcard.vcf</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00002-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  <D:propstat>
    <D:prop>
      <R:bigbox xmlns:R="urn:ns.example.com:boxschema"/>
    </D:prop>
    <D:status>HTTP/1.1 404 Not Found</D:status>
  </D:propstat>
  </D:response>
  <D:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/calendar.ics</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00003-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  <D:propstat>
    <D:prop>
      <R:bigbox xmlns:R="urn:ns.example.com:boxschema"/>
    </D:prop>
    <D:status>HTTP/1.1 404 Not Found</D:status>
  </D:propstat>
  </D: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
Depth: 1
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 xmlns:R="urn:ns.example.com:boxschema">
    <D:getetag/>
    <R:bigbox/>
  </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:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/file.xml</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00004-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  <D:propstat>
    <D:prop>
      <R:bigbox xmlns:R="urn:ns.example.com:boxschema"/>
    </D:prop>
    <D:status>HTTP/1.1 404 Not Found</D:status>
  </D:propstat>
  </D:response>
  <D:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/vcard.vcf</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00002-abcd2"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  <D:propstat>
    <D:prop>
      <R:bigbox xmlns:R="urn:ns.example.com:boxschema"/>
    </D:prop>
    <D:status>HTTP/1.1 404 Not Found</D:status>
  </D:propstat>
  </D:response>
  <D:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/test.doc</D:href>
  <D:status>HTTP/1.1 404 Not Found</D:status>
  </D:response>
  <D:sync-token>1238</D:sync-token>
</D:multistatus>
]]>
          </artwork>
        </figure>
      </section>
      <section title="Example: Initial DAV:sync-collection Report with Truncation">
        <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. It also asks for the DAV:getetag property.
          The server responds with the items currently in the targeted collection, but truncated at two items. The synchronization token for the truncated result set is returned.
        </t>
        <figure>
          <preamble>
            &gt;&gt; Request &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
REPORT /home/cyrusdaboo/ HTTP/1.1
Host: webdav.example.com
Depth: 1
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:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/test.doc</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00001-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:response>
  <D:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/vcard.vcf</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00002-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:response>
  <D:response>
    <D:href
>http://webdav.example.com/home/cyrusdaboo/</D:href>
    <D:status>HTTP/1.1 507 Insufficient Storage</D:status>
  </D:response>
  <D:sync-token>1233</D:sync-token>
</D:multistatus>
]]>
          </artwork>
        </figure>
      </section>
      <section title="Example: Initial DAV:sync-collection Report with Limit">
        <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. It requests a limit of 1 for the responses returned by the server. It also asks for the DAV:getetag property.
          The server responds with the items currently in the targeted collection, but truncated at one item. The synchronization token for the truncated result set is returned.
        </t>
        <figure>
          <preamble>
            &gt;&gt; Request &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
REPORT /home/cyrusdaboo/ HTTP/1.1
Host: webdav.example.com
Depth: 1
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:limit>
    <D:nresults>1</D:nresults>
  </D:limit>
  <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:response>
  <D:href
>http://webdav.example.com/home/cyrusdaboo/test.doc</D:href>
  <D:propstat>
    <D:prop>
      <D:getetag>"00001-abcd1"</D:getetag>
    </D:prop>
    <D:status>HTTP/1.1 200 OK</D:status>
  </D:propstat>
  </D:response>
  <D:response>
    <D:href
>http://webdav.example.com/home/cyrusdaboo/</D:href>
    <D:status>HTTP/1.1 507 Insufficient Storage</D:status>
  </D:response>
  <D:sync-token>1232</D:sync-token>
</D:multistatus>
]]>
          </artwork>
        </figure>
      </section>
      <section title="Example: DAV:sync-collection Report with Unsupported Limit">
        <t>
          In this example, the client is making a synchronization request to the server with a valid DAV:sync-token element value. It requests a limit of 100 for the responses returned by the server. It also asks for the DAV:getetag property.
          The server is unable to limit the results to the maximum specified by the client, so it responds with a 507 status code and appropriate post-condition error code.
        </t>
        <figure>
          <preamble>
            &gt;&gt; Request &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
REPORT /home/cyrusdaboo/ HTTP/1.1
Host: webdav.example.com
Depth: 1
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>1232</D:sync-token>
  <D:limit>
    <D:nresults>100</D:nresults>
  </D:limit>
  <D:prop>
    <D:getetag/>
  </D:prop>
</D:sync-collection>
]]>
          </artwork>
        </figure>
        <figure>
          <preamble>
            &gt;&gt; Response &lt;&lt;
          </preamble>
          <artwork>
<![CDATA[
HTTP/1.1 507 Insufficient Storage
Content-Type: text/xml; charset="utf-8"
Content-Length: xxxx

<?xml version="1.0" encoding="utf-8" ?>
<D:error xmlns:D="DAV:">
  <D:number-of-matches-within-limits/>
</D:error>
]]>
          </artwork>
        </figure>
      </section>
    </section>
    <section title="DAV:sync-token Property" anchor="sync_property">
        <t>
            <list style="hanging">
                <t hangText="Name:">
                    sync-token
                </t>
                <t hangText="Namespace:">
                    DAV:
                </t>
                <t hangText="Purpose:">
                  Contains the value of the synchronization token as it would be returned by a DAV:sync-collection report.
                </t>
                <t hangText="Value:">
                    Any text.
                </t>
                <t hangText="Protected:">
                    MUST be protected because this value is created and controlled by the server.
                </t>
                <t hangText="COPY/MOVE behavior:">
                    This property value is dependent on the final state of the destination resource, not the value of the property on the source resource.
                </t>
                <t hangText="Description:">
                    The DAV:sync-token property MUST be defined on all resources that support the DAV:sync-collection report.
                    It contains the value of the synchronization token as it would be returned by a DAV:sync-collection report on that resource at the same point in time.
                    It SHOULD NOT be returned by a PROPFIND DAV:allprop request (as defined in <xref target="RFC4918" x:fmt="of" x:sec="14.2"/>).
                </t>
                <t hangText="Definition:">
                    <figure>
                        <artwork align="left">
<![CDATA[
<!ELEMENT sync-token #PCDATA>
]]>
                        </artwork>
                    </figure>
                </t>
            </list>
        </t>
    </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:limit?, DAV:prop)>

<!-- DAV:limit defined in RFC 5323, Section 5.17 -->
<!-- DAV:prop defined in RFC 4918, Section 14.18 -->
]]>
          </artwork>
        </figure>
      </section>
      <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?,
                       sync-token?) >

<!-- DAV:multistatus originally defined in RFC 4918, Section 14.16
     but overridden here to add the DAV:sync-token element -->
<!-- DAV:response defined in RFC 4918, Section 14.24 -->
<!-- DAV:responsedescription defined in RFC 4918, Section 14.25 -->
]]>
            </artwork>
          </figure>
      </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,
        Ciny Joy, Andrew McMillan, Julian Reschke, and Wilfredo Sanchez. We would like to thank the Calendaring and Scheduling Consortium for facilitating interoperability testing for early implementations of this specification.
      </t>
    </section>
  </middle>
  <back>
    <references title='Normative References'>
      &rfc2119;
      &rfc2616;
      &rfc3744;
      &rfc4918;
      &rfc5323;
      &W3C.REC-xml-20081126;
    </references>
    <references title='Informative References'>
        &rfc4791;
        &webdavbind;
        &carddav;
    </references>

<section title='Change History (to be removed prior to publication as an RFC)'>

<t>Changes in -03:
<list style='numbers'>
<t>Changed D:propstat to D:prop in marshalling.</t>
<t>Added request for dead property in examples.</t>
<t>Made D:prop mandatory in request so that D:response always contains at least one D:propstat
 as per WebDAV definition.</t>
<t>Removed DAV:status from response when resource is created/modified, thus allowing to get rid of
 DAV:sync-response in favor of a regular DAV:response. As a consequence, there is no longer any
 difference in the report between created and modified resources.</t>
 <t>Resource created, then removed between 2 sync MUST be returned as removed.</t>
 <t>Added ability for server to truncate results and indicate such to the client.</t>
 <t>Added ability for client to request the server to limit the result set.</t>
</list>
</t>

<t>Changes in -02:
<list style='numbers'>
<t>Added definition of sync-token WebDAV property.</t>
<t>Added references to SEARCH, CalDAV, CardDAV as alternative ways to first synchronize a collection.</t>
<t>Added section defining under which condition each state change (new, modified, removed) should be reported. Added reference to BIND.</t>
<t>Incorporated feedback from Julian Reschke and Ciny Joy.</t>
<t>More details on the use of the DAV:valid-sync-token precondition.</t>
</list>
</t>

<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>
