/*
* $Id$
- */
-/**
- * \defgroup GroupdavPropfind Handles GroupDAV PROPFIND requests.
+ *
+ * Handles GroupDAV PROPFIND requests.
*
* A few notes about our XML output:
*
* This makes it difficult to read, but we have discovered clients which
* crash when you try to pretty it up.
*
- * \ingroup WebcitHttpServerGDav
*/
#include "webcit.h"
#include "webserver.h"
#include "groupdav.h"
-
-/**
- * \brief get all messages of this user
+/*
* Given an encoded UID, translate that to an unencoded Citadel EUID and
* then search for it in the current room. Return a message number or -1
* if not found.
*
- * NOTE: this function relies on the Citadel server's brute-force search.
- * There's got to be a way to optimize this better.
- * \param uid the user to get the data for...
*/
long locate_message_by_uid(char *uid) {
- char buf[SIZ];
- char decoded_uid[SIZ];
+ char buf[256];
+ char decoded_uid[1024];
long retval = (-1L);
/* Decode the uid */
euid_unescapize(decoded_uid, uid);
+/************** THE NEW WAY ***********************/
serv_printf("EUID %s", decoded_uid);
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
- retval = extract_long(&buf[4], 0);
+ retval = atol(&buf[4]);
}
+/***************************************************/
+
+/************** THE OLD WAY ***********************
+ serv_puts("MSGS ALL|0|1");
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '8') {
+ serv_printf("exti|%s", decoded_uid);
+ serv_puts("000");
+ while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+ retval = atol(buf);
+ }
+ }
+ ***************************************************/
+
return(retval);
}
-/**
- * \brief List folders containing interesting groupware objects
+
+/*
+ * List rooms (or "collections" in DAV terminology) which contain
+ * interesting groupware objects.
*/
-void groupdav_folder_list(void) {
- char buf[SIZ];
- char roomname[SIZ];
+void groupdav_collection_list(char *dav_pathname, int dav_depth)
+{
+ char buf[256];
+ char roomname[256];
int view;
- char datestring[SIZ];
+ char datestring[256];
time_t now;
+ time_t mtime;
+ int is_groupware_collection = 0;
+ int starting_point = 1; /**< 0 for /, 1 for /groupdav/ */
+
+ if (!strcmp(dav_pathname, "/")) {
+ starting_point = 0;
+ }
+ else if (!strcasecmp(dav_pathname, "/groupdav")) {
+ starting_point = 1;
+ }
+ else if (!strcasecmp(dav_pathname, "/groupdav/")) {
+ starting_point = 1;
+ }
+ else if ( (!strncasecmp(dav_pathname, "/groupdav/", 10)) && (strlen(dav_pathname) > 10) ) {
+ starting_point = 2;
+ }
now = time(NULL);
http_datestring(datestring, sizeof datestring, now);
* Be rude. Completely ignore the XML request and simply send them
* everything we know about. Let the client sort it out.
*/
- wprintf("HTTP/1.1 207 Multi-Status\r\n");
+ wprintf("HTTP/1.0 207 Multi-Status\r\n");
groupdav_common_headers();
wprintf("Date: %s\r\n", datestring);
wprintf("Content-type: text/xml\r\n");
begin_burst();
wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
+ "<multistatus xmlns=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
);
+ /**
+ * If the client is requesting the root, show a root node.
+ */
+ if (starting_point == 0) {
+ wprintf("<response>");
+ wprintf("<href>");
+ groupdav_identify_host();
+ wprintf("/");
+ wprintf("</href>");
+ wprintf("<propstat>");
+ wprintf("<status>HTTP/1.1 200 OK</status>");
+ wprintf("<prop>");
+ wprintf("<displayname>/</displayname>");
+ wprintf("<resourcetype><collection/></resourcetype>");
+ wprintf("<getlastmodified>");
+ escputs(datestring);
+ wprintf("</getlastmodified>");
+ wprintf("</prop>");
+ wprintf("</propstat>");
+ wprintf("</response>");
+ }
+
+ /**
+ * If the client is requesting "/groupdav", show a /groupdav subdirectory.
+ */
+ if ((starting_point + dav_depth) >= 1) {
+ wprintf("<response>");
+ wprintf("<href>");
+ groupdav_identify_host();
+ wprintf("/groupdav");
+ wprintf("</href>");
+ wprintf("<propstat>");
+ wprintf("<status>HTTP/1.1 200 OK</status>");
+ wprintf("<prop>");
+ wprintf("<displayname>GroupDAV</displayname>");
+ wprintf("<resourcetype><collection/></resourcetype>");
+ wprintf("<getlastmodified>");
+ escputs(datestring);
+ wprintf("</getlastmodified>");
+ wprintf("</prop>");
+ wprintf("</propstat>");
+ wprintf("</response>");
+ }
+
+ /**
+ * Now go through the list and make it look like a DAV collection
+ */
serv_puts("LKRA");
serv_getln(buf, sizeof buf);
if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
extract_token(roomname, buf, 0, '|', sizeof roomname);
- view = extract_int(buf, 6);
+ view = extract_int(buf, 7);
+ mtime = extract_long(buf, 8);
+ http_datestring(datestring, sizeof datestring, mtime);
- /**
+ /*
* For now, only list rooms that we know a GroupDAV client
* might be interested in. In the future we may add
* the rest.
+ *
+ * We determine the type of objects which are stored in each
+ * room by looking at the *default* view for the room. This
+ * allows, for example, a Calendar room to appear as a
+ * GroupDAV calendar even if the user has switched it to a
+ * Calendar List view.
*/
- if ((view == VIEW_CALENDAR)
- || (view == VIEW_TASKS)
- || (view == VIEW_ADDRESSBOOK) ) {
+ if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
+ is_groupware_collection = 1;
+ }
+ else {
+ is_groupware_collection = 0;
+ }
- wprintf("<D:response>");
+ if ( (is_groupware_collection) && ((starting_point + dav_depth) >= 2) ) {
+ wprintf("<response>");
- wprintf("<D:href>");
-/*
- if (strlen(WC->http_host) > 0) {
- wprintf("%s://%s",
- (is_https ? "https" : "http"),
- WC->http_host);
- }
- */
+ wprintf("<href>");
+ groupdav_identify_host();
wprintf("/groupdav/");
urlescputs(roomname);
- wprintf("/</D:href>");
+ wprintf("/</href>");
- wprintf("<D:propstat>");
- wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
- wprintf("<D:prop>");
- wprintf("<D:fullname>");
+ wprintf("<propstat>");
+ wprintf("<status>HTTP/1.1 200 OK</status>");
+ wprintf("<prop>");
+ wprintf("<displayname>");
escputs(roomname);
- wprintf("</D:fullname>");
- wprintf("<D:resourcetype><D:collection/>");
+ wprintf("</displayname>");
+ wprintf("<resourcetype><collection/>");
switch(view) {
case VIEW_CALENDAR:
break;
}
- wprintf("</D:resourcetype>");
- wprintf("</D:prop>");
- wprintf("</D:propstat>");
- wprintf("</D:response>");
+ wprintf("</resourcetype>");
+ wprintf("<getlastmodified>");
+ escputs(datestring);
+ wprintf("</getlastmodified>");
+ wprintf("</prop>");
+ wprintf("</propstat>");
+ wprintf("</response>");
}
}
- wprintf("</D:multistatus>\n");
+ wprintf("</multistatus>\n");
end_burst();
}
-/**
- * \brief Search though a davname
- * \param dav_pathname The pathname is always going to be /groupdav/room_name/msg_num
+/*
+ * The pathname is always going to be /groupdav/room_name/msg_num
*/
-void groupdav_propfind(char *dav_pathname) {
+void groupdav_propfind(char *dav_pathname, int dav_depth, char *dav_content_type, char *dav_content) {
char dav_roomname[256];
char dav_uid[256];
char msgnum[256];
extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
/*
- lprintf(9, "dav_pathname: %s\n", dav_pathname);
- lprintf(9, "dav_roomname: %s\n", dav_roomname);
- lprintf(9, " dav_uid: %s\n", dav_uid);
- */
-
- /**
* If the room name is blank, the client is requesting a
* folder list.
*/
if (strlen(dav_roomname) == 0) {
- groupdav_folder_list();
+ groupdav_collection_list(dav_pathname, dav_depth);
return;
}
return;
}
- /**
- * If dav_uid is non-empty, client is requesting a PROPFIND on
+ /* If dav_uid is non-empty, client is requesting a PROPFIND on
* a specific item in the room. This is not valid GroupDAV, but
- * we try to honor it anyway because some clients are expecting
- * it to work...
+ * it is valid WebDAV.
*/
if (strlen(dav_uid) > 0) {
return;
}
- /**
- * Be rude. Completely ignore the XML request and simply send them
+ /* 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.
*/
- wprintf("HTTP/1.1 207 Multi-Status\r\n");
+ wprintf("HTTP/1.0 207 Multi-Status\r\n");
groupdav_common_headers();
wprintf("Date: %s\r\n", datestring);
wprintf("Content-type: text/xml\r\n");
begin_burst();
wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
+ "<multistatus xmlns=\"DAV:\">"
);
- wprintf("<D:response>");
+ wprintf("<response>");
- wprintf("<D:href>");
-/*
- if (strlen(WC->http_host) > 0) {
- wprintf("%s://%s",
- (is_https ? "https" : "http"),
- WC->http_host);
- }
- */
+ wprintf("<href>");
+ groupdav_identify_host();
wprintf("/groupdav/");
urlescputs(WC->wc_roomname);
euid_escapize(encoded_uid, dav_uid);
wprintf("/%s", encoded_uid);
- wprintf("</D:href>");
- wprintf("<D:propstat>");
- wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
- wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", dav_msgnum);
- wprintf("</D:propstat>");
-
- wprintf("</D:response>\n");
- wprintf("</D:multistatus>\n");
+ wprintf("</href>");
+ wprintf("<propstat>");
+ wprintf("<status>HTTP/1.1 200 OK</status>");
+ wprintf("<prop><getetag>\"%ld\"</getetag></prop>", dav_msgnum);
+ wprintf("</propstat>");
+
+ wprintf("</response>\n");
+ wprintf("</multistatus>\n");
end_burst();
return;
}
- /**
+ /*
* We got to this point, which means that the client is requesting
* a 'collection' (i.e. a list of all items in the room).
*
* everything we know about (which is going to simply be the ETag and
* nothing else). Let the client-side parser sort it out.
*/
- wprintf("HTTP/1.1 207 Multi-Status\r\n");
+ wprintf("HTTP/1.0 207 Multi-Status\r\n");
groupdav_common_headers();
wprintf("Date: %s\r\n", datestring);
wprintf("Content-type: text/xml\r\n");
begin_burst();
wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- "<D:multistatus xmlns:D=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
+ "<multistatus xmlns=\"DAV:\" xmlns:G=\"http://groupdav.org/\">"
);
+
+ /** Transmit the collection resource (FIXME check depth and starting point) */
+ wprintf("<response>");
+
+ wprintf("<href>");
+ groupdav_identify_host();
+ wprintf("/groupdav/");
+ urlescputs(WC->wc_roomname);
+ wprintf("</href>");
+
+ wprintf("<propstat>");
+ wprintf("<status>HTTP/1.1 200 OK</status>");
+ wprintf("<prop>");
+ wprintf("<displayname>");
+ escputs(WC->wc_roomname);
+ wprintf("</displayname>");
+ wprintf("<resourcetype><collection/>");
+
+ switch(WC->wc_default_view) {
+ case VIEW_CALENDAR:
+ wprintf("<G:vevent-collection />");
+ break;
+ case VIEW_TASKS:
+ wprintf("<G:vtodo-collection />");
+ break;
+ case VIEW_ADDRESSBOOK:
+ wprintf("<G:vcard-collection />");
+ break;
+ }
+
+ wprintf("</resourcetype>");
+ /* FIXME get the mtime
+ wprintf("<getlastmodified>");
+ escputs(datestring);
+ wprintf("</getlastmodified>");
+ */
+ wprintf("</prop>");
+ wprintf("</propstat>");
+ wprintf("</response>");
+
+ /** Transmit the collection listing (FIXME check depth and starting point) */
+
serv_puts("MSGS ALL");
serv_getln(buf, sizeof buf);
if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
}
if (strlen(uid) > 0) {
- wprintf("<D:response>");
- wprintf("<D:href>");
-/*
- if (strlen(WC->http_host) > 0) {
- wprintf("%s://%s",
- (is_https ? "https" : "http"),
- WC->http_host);
- }
- */
- wprintf("/groupdav/");
- urlescputs(WC->wc_roomname);
- euid_escapize(encoded_uid, uid);
- wprintf("/%s", encoded_uid);
- wprintf("</D:href>");
- wprintf("<D:propstat>");
- wprintf("<D:status>HTTP/1.1 200 OK</D:status>");
- wprintf("<D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>", msgs[i]);
- wprintf("</D:propstat>");
- wprintf("</D:response>");
+ wprintf("<response>");
+ wprintf("<href>");
+ groupdav_identify_host();
+ wprintf("/groupdav/");
+ urlescputs(WC->wc_roomname);
+ euid_escapize(encoded_uid, uid);
+ wprintf("/%s", encoded_uid);
+ wprintf("</href>");
+ wprintf("<propstat>");
+ wprintf("<status>HTTP/1.1 200 OK</status>");
+ wprintf("<prop>");
+ wprintf("<getetag>\"%ld\"</getetag>", msgs[i]);
+ wprintf("</prop>");
+ wprintf("</propstat>");
+ wprintf("</response>");
}
}
- wprintf("</D:multistatus>\n");
+ wprintf("</multistatus>\n");
end_burst();
if (msgs != NULL) {
free(msgs);
}
}
-
-/*@}*/