From a775f93b57d0682525188c01bb0e8d60ed972453 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 4 Jan 2012 11:03:24 -0500 Subject: [PATCH] Honor the 'Depth:' header in PROPFIND requests on a collection. Depth 0 only shows properties of the collection; Depth 1 enumerates the collection. --- webcit/dav_propfind.c | 203 ++++++++++++++++++++++++------------------ 1 file changed, 116 insertions(+), 87 deletions(-) diff --git a/webcit/dav_propfind.c b/webcit/dav_propfind.c index f9f2892e4..80efafca4 100644 --- a/webcit/dav_propfind.c +++ b/webcit/dav_propfind.c @@ -9,6 +9,26 @@ * --> XML is deliberately output with no whitespace/newlines between tags. * This makes it difficult to read, but we have discovered clients which * crash when you try to pretty it up. + * + * References: + * http://www.ietf.org/rfc/rfc4791.txt + * http://blogs.nologin.es/rickyepoderi/index.php?/archives/14-Introducing-CalDAV-Part-I.html + +Sample query: + +PROPFIND /groupdav/calendar/ HTTP/1.1 +Content-type: text/xml; charset=utf-8 +Content-length: 166 + + + + + + + + + + * * Copyright (c) 2005-2012 by the citadel.org team * @@ -425,11 +445,11 @@ void dav_collection_list(void) void propfind_xml_start(void *data, const char *supplied_el, const char **attr) { - syslog(LOG_DEBUG, "<%s>", supplied_el); + // syslog(LOG_DEBUG, "<%s>", supplied_el); } void propfind_xml_end(void *data, const char *supplied_el) { - syslog(LOG_DEBUG, "", supplied_el); + // syslog(LOG_DEBUG, "", supplied_el); } @@ -497,6 +517,10 @@ void dav_propfind(void) StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/'); StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/'); + syslog(LOG_DEBUG, "PROPFIND requested for '%s' at depth %d", + ChrPtr(dav_roomname), WCC->Hdr->HR.dav_depth + ); + /* * If the room name is blank, the client is requesting a folder list. */ @@ -592,13 +616,16 @@ void dav_propfind(void) /* - * We got to this point, which means that the client is requesting - * a 'collection' (i.e. a list of all items in the room). + * If we get to this point the client is performing a PROPFIND on the room itself. + * + * We call it a room; DAV calls it a "collection." We have to give it some properties + * of the room itself and then offer a list of all items contained therein. * * Be rude. Completely ignore the XML request and simply send them * everything we know about (which is going to simply be the ETag and * nothing else). Let the client-side parser sort it out. */ + //syslog(LOG_DEBUG, "BE RUDE AND IGNORE: \033[31m%s\033[0m", ChrPtr(WC->upload) ); hprintf("HTTP/1.0 207 Multi-Status\r\n"); dav_common_headers(); hprintf("Date: %s\r\n", datestring); @@ -609,36 +636,36 @@ void dav_propfind(void) begin_burst(); wc_printf("" - "" ); - /* Transmit the collection resource (FIXME check depth and starting point) */ - wc_printf(""); + /* Transmit the collection resource */ + wc_printf(""); - wc_printf(""); + wc_printf(""); dav_identify_host(); wc_printf("/groupdav/"); urlescputs(ChrPtr(WCC->CurRoom.name)); - wc_printf(""); + wc_printf(""); - wc_printf(""); - wc_printf("HTTP/1.1 200 OK"); - wc_printf(""); - wc_printf(""); + wc_printf(""); + wc_printf("HTTP/1.1 200 OK"); + wc_printf(""); + wc_printf(""); escputs(ChrPtr(WCC->CurRoom.name)); - wc_printf(""); + wc_printf(""); - wc_printf(""); /* empty owner ought to be legal; see rfc3744 section 5.1 */ + wc_printf(""); /* empty owner ought to be legal; see rfc3744 section 5.1 */ - wc_printf(""); + wc_printf(""); switch(WCC->CurRoom.defview) { case VIEW_CALENDAR: wc_printf(""); - wc_printf(""); + wc_printf(""); break; case VIEW_TASKS: wc_printf(""); @@ -647,90 +674,92 @@ void dav_propfind(void) wc_printf(""); break; } - wc_printf(""); + wc_printf(""); /* FIXME get the mtime - wc_printf(""); + wc_printf(""); escputs(datestring); - wc_printf(""); + wc_printf(""); */ - wc_printf(""); - wc_printf(""); - wc_printf(""); - - /* Transmit the collection listing (FIXME check depth and starting point) */ + wc_printf(""); + wc_printf(""); + wc_printf(""); - MsgNum = NewStrBuf(); - serv_puts("MSGS ALL"); + /* If a depth greater than zero was specified, transmit the collection listing */ - StrBuf_ServGetln(MsgNum); - if (GetServerStatus(MsgNum, NULL) == 1) - while (BufLen = StrBuf_ServGetln(MsgNum), - ((BufLen >= 0) && - ((BufLen != 3) || strcmp(ChrPtr(MsgNum), "000")) )) - { - msgs = realloc(msgs, ++num_msgs * sizeof(long)); - msgs[num_msgs-1] = StrTol(MsgNum); - } - - if (num_msgs > 0) for (i=0; iHdr->HR.dav_depth > 0) { + MsgNum = NewStrBuf(); + serv_puts("MSGS ALL"); + StrBuf_ServGetln(MsgNum); if (GetServerStatus(MsgNum, NULL) == 1) while (BufLen = StrBuf_ServGetln(MsgNum), - ((BufLen >= 0) && - ((BufLen != 3) || strcmp(ChrPtr(MsgNum), "000")) )) + ((BufLen >= 0) && + ((BufLen != 3) || strcmp(ChrPtr(MsgNum), "000")) )) { - if (!strncasecmp(ChrPtr(MsgNum), "exti=", 5)) { - strcpy(uid, &ChrPtr(MsgNum)[5]); - } - else if (!strncasecmp(ChrPtr(MsgNum), "time=", 5)) { - now = atol(&ChrPtr(MsgNum)[5]); + msgs = realloc(msgs, ++num_msgs * sizeof(long)); + msgs[num_msgs-1] = StrTol(MsgNum); } - } - - if (!IsEmptyStr(uid)) { - wc_printf(""); - wc_printf(""); - dav_identify_host(); - wc_printf("/groupdav/"); - urlescputs(ChrPtr(WCC->CurRoom.name)); - euid_escapize(encoded_uid, uid); - wc_printf("/%s", encoded_uid); - wc_printf(""); - switch(WCC->CurRoom.defview) { - case VIEW_CALENDAR: - wc_printf("text/x-ical"); - break; - case VIEW_TASKS: - wc_printf("text/x-ical"); - break; - case VIEW_ADDRESSBOOK: - wc_printf("text/x-vcard"); - break; + + if (num_msgs > 0) for (i=0; i= 0) && + ((BufLen != 3) || strcmp(ChrPtr(MsgNum), "000")) )) + { + if (!strncasecmp(ChrPtr(MsgNum), "exti=", 5)) { + strcpy(uid, &ChrPtr(MsgNum)[5]); + } + else if (!strncasecmp(ChrPtr(MsgNum), "time=", 5)) { + now = atol(&ChrPtr(MsgNum)[5]); } - wc_printf(""); - wc_printf("HTTP/1.1 200 OK"); - wc_printf(""); - wc_printf("\"%ld\"", msgs[i]); - if (now > 0L) { - http_datestring(datestring, sizeof datestring, now); - wc_printf(""); - escputs(datestring); - wc_printf(""); + } + + if (!IsEmptyStr(uid)) { + wc_printf(""); + wc_printf(""); + dav_identify_host(); + wc_printf("/groupdav/"); + urlescputs(ChrPtr(WCC->CurRoom.name)); + euid_escapize(encoded_uid, uid); + wc_printf("/%s", encoded_uid); + wc_printf(""); + switch(WCC->CurRoom.defview) { + case VIEW_CALENDAR: + wc_printf("text/x-ical"); + break; + case VIEW_TASKS: + wc_printf("text/x-ical"); + break; + case VIEW_ADDRESSBOOK: + wc_printf("text/x-vcard"); + break; } - wc_printf(""); - wc_printf(""); - wc_printf(""); + wc_printf(""); + wc_printf("HTTP/1.1 200 OK"); + wc_printf(""); + wc_printf("\"%ld\"", msgs[i]); + if (now > 0L) { + http_datestring(datestring, sizeof datestring, now); + wc_printf(""); + escputs(datestring); + wc_printf(""); + } + wc_printf(""); + wc_printf(""); + wc_printf(""); + } } + FreeStrBuf(&MsgNum); } - FreeStrBuf(&MsgNum); - wc_printf("\n"); + wc_printf("\n"); end_burst(); if (msgs != NULL) { -- 2.30.2