* if not found.
*
*/
-long locate_message_by_uid(char *uid) {
+long locate_message_by_uid(const char *uid) {
char buf[256];
char decoded_uid[1024];
long retval = (-1L);
- /* Decode the uid */
+ /* decode the UID */
euid_unescapize(decoded_uid, uid);
-/************** THE NEW WAY ***********************/
+ /* ask Citadel if we have this one */
serv_printf("EUID %s", decoded_uid);
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
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);
}
* List rooms (or "collections" in DAV terminology) which contain
* interesting groupware objects.
*/
-void groupdav_collection_list(char *dav_pathname, int dav_depth)
+void groupdav_collection_list(const char *dav_pathname, int dav_depth)
{
char buf[256];
char roomname[256];
* Be rude. Completely ignore the XML request and simply send them
* everything we know about. Let the client sort it out.
*/
- wprintf("HTTP/1.0 207 Multi-Status\r\n");
+ hprintf("HTTP/1.0 207 Multi-Status\r\n");
groupdav_common_headers();
- wprintf("Date: %s\r\n", datestring);
- wprintf("Content-type: text/xml\r\n");
- wprintf("Content-encoding: identity\r\n");
+ hprintf("Date: %s\r\n", datestring);
+ hprintf("Content-type: text/xml\r\n");
+ hprintf("Content-encoding: identity\r\n");
begin_burst();
/*
* The pathname is always going to be /groupdav/room_name/msg_num
*/
-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];
+void groupdav_propfind(StrBuf *dav_pathname, int dav_depth, StrBuf *dav_content_type, StrBuf *dav_content, int offset) {
+ StrBuf *dav_roomname;
+ StrBuf *dav_uid;
+ StrBuf *MsgNum;
+ long BufLen;
long dav_msgnum = (-1);
- char buf[256];
char uid[256];
char encoded_uid[256];
long *msgs = NULL;
now = time(NULL);
http_datestring(datestring, sizeof datestring, now);
- extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
- extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
+ dav_roomname = NewStrBuf();
+ dav_uid = NewStrBuf();
+ StrBufExtract_token(dav_roomname, dav_pathname, 2, '/');
+ StrBufExtract_token(dav_uid, dav_pathname, 3, '/');
/*
* If the room name is blank, the client is requesting a
* folder list.
*/
- if (strlen(dav_roomname) == 0) {
- groupdav_collection_list(dav_pathname, dav_depth);
+ if (StrLength(dav_roomname) == 0) {
+ groupdav_collection_list(ChrPtr(dav_pathname), dav_depth);
+ FreeStrBuf(&dav_roomname);
+ FreeStrBuf(&dav_uid);
return;
}
/* Go to the correct room. */
- if (strcasecmp(WC->wc_roomname, dav_roomname)) {
+ if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
gotoroom(dav_roomname);
}
- if (strcasecmp(WC->wc_roomname, dav_roomname)) {
- wprintf("HTTP/1.1 404 not found\r\n");
+ if (strcasecmp(ChrPtr(WC->wc_roomname), ChrPtr(dav_roomname))) {
+ hprintf("HTTP/1.1 404 not found\r\n");
groupdav_common_headers();
- wprintf("Date: %s\r\n", datestring);
- wprintf(
- "Content-Type: text/plain\r\n"
- "\r\n"
- "There is no folder called \"%s\" on this server.\r\n",
- dav_roomname
+ hprintf("Date: %s\r\n", datestring);
+ hprintf("Content-Type: text/plain\r\n");
+ wprintf("There is no folder called \"%s\" on this server.\r\n",
+ ChrPtr(dav_roomname)
);
+ end_burst();
+ FreeStrBuf(&dav_roomname);
+ FreeStrBuf(&dav_uid);
return;
}
* a specific item in the room. This is not valid GroupDAV, but
* it is valid WebDAV.
*/
- if (strlen(dav_uid) > 0) {
+ if (StrLength(dav_uid) != 0) {
- dav_msgnum = locate_message_by_uid(dav_uid);
+ dav_msgnum = locate_message_by_uid(ChrPtr(dav_uid));
if (dav_msgnum < 0) {
- wprintf("HTTP/1.1 404 not found\r\n");
+ hprintf("HTTP/1.1 404 not found\r\n");
groupdav_common_headers();
- wprintf(
- "Content-Type: text/plain\r\n"
- "\r\n"
- "Object \"%s\" was not found in the \"%s\" folder.\r\n",
- dav_uid,
- dav_roomname
+ hprintf("Content-Type: text/plain\r\n");
+ wprintf("Object \"%s\" was not found in the \"%s\" folder.\r\n",
+ ChrPtr(dav_uid),
+ ChrPtr(dav_roomname)
);
+ end_burst();
+ FreeStrBuf(&dav_roomname);
+ FreeStrBuf(&dav_uid);
return;
}
* 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.0 207 Multi-Status\r\n");
+ hprintf("HTTP/1.0 207 Multi-Status\r\n");
groupdav_common_headers();
- wprintf("Date: %s\r\n", datestring);
- wprintf("Content-type: text/xml\r\n");
- wprintf("Content-encoding: identity\r\n");
+ hprintf("Date: %s\r\n", datestring);
+ hprintf("Content-type: text/xml\r\n");
+ hprintf("Content-encoding: identity\r\n");
begin_burst();
wprintf("<href>");
groupdav_identify_host();
wprintf("/groupdav/");
- urlescputs(WC->wc_roomname);
- euid_escapize(encoded_uid, dav_uid);
+ urlescputs(ChrPtr(WC->wc_roomname));
+ euid_escapize(encoded_uid, ChrPtr(dav_uid));
wprintf("/%s", encoded_uid);
wprintf("</href>");
wprintf("<propstat>");
wprintf("<status>HTTP/1.1 200 OK</status>");
- wprintf("<prop><getetag>\"%ld\"</getetag></prop>", dav_msgnum);
+ wprintf("<prop>");
+ wprintf("<getetag>\"%ld\"</getetag>", dav_msgnum);
+ wprintf("<getlastmodified>");
+ escputs(datestring);
+ wprintf("</getlastmodified>");
+ wprintf("</prop>");
wprintf("</propstat>");
wprintf("</response>\n");
wprintf("</multistatus>\n");
end_burst();
+ FreeStrBuf(&dav_roomname);
+ FreeStrBuf(&dav_uid);
return;
}
+ FreeStrBuf(&dav_roomname);
+ FreeStrBuf(&dav_uid);
/*
* 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.0 207 Multi-Status\r\n");
+ hprintf("HTTP/1.0 207 Multi-Status\r\n");
groupdav_common_headers();
- wprintf("Date: %s\r\n", datestring);
- wprintf("Content-type: text/xml\r\n");
- wprintf("Content-encoding: identity\r\n");
+ hprintf("Date: %s\r\n", datestring);
+ hprintf("Content-type: text/xml\r\n");
+ hprintf("Content-encoding: identity\r\n");
begin_burst();
wprintf("<href>");
groupdav_identify_host();
wprintf("/groupdav/");
- urlescputs(WC->wc_roomname);
+ urlescputs(ChrPtr(WC->wc_roomname));
wprintf("</href>");
wprintf("<propstat>");
wprintf("<status>HTTP/1.1 200 OK</status>");
wprintf("<prop>");
wprintf("<displayname>");
- escputs(WC->wc_roomname);
+ escputs(ChrPtr(WC->wc_roomname));
wprintf("</displayname>");
wprintf("<resourcetype><collection/>");
/** Transmit the collection listing (FIXME check depth and starting point) */
+ MsgNum = NewStrBuf ();
serv_puts("MSGS ALL");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') while (serv_getln(msgnum, sizeof msgnum), strcmp(msgnum, "000")) {
- msgs = realloc(msgs, ++num_msgs * sizeof(long));
- msgs[num_msgs-1] = atol(msgnum);
- }
+
+ StrBuf_ServGetln(MsgNum);
+ if (GetServerStatus(MsgNum, NULL) == 1)
+ while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000")) {
+ msgs = realloc(msgs, ++num_msgs * sizeof(long));
+ msgs[num_msgs-1] = StrTol(MsgNum);
+ }
if (num_msgs > 0) for (i=0; i<num_msgs; ++i) {
strcpy(uid, "");
+ now = (-1);
serv_printf("MSG0 %ld|3", msgs[i]);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- if (!strncasecmp(buf, "exti=", 5)) {
- strcpy(uid, &buf[5]);
+ StrBuf_ServGetln(MsgNum);
+ if (GetServerStatus(MsgNum, NULL) == 1)
+ while (BufLen = StrBuf_ServGetln(MsgNum), 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]);
}
}
- if (strlen(uid) > 0) {
+ if (!IsEmptyStr(uid)) {
wprintf("<response>");
wprintf("<href>");
groupdav_identify_host();
wprintf("/groupdav/");
- urlescputs(WC->wc_roomname);
+ urlescputs(ChrPtr(WC->wc_roomname));
euid_escapize(encoded_uid, uid);
wprintf("/%s", encoded_uid);
wprintf("</href>");
wprintf("<status>HTTP/1.1 200 OK</status>");
wprintf("<prop>");
wprintf("<getetag>\"%ld\"</getetag>", msgs[i]);
+ if (now > 0L) {
+ http_datestring(datestring, sizeof datestring, now);
+ wprintf("<getlastmodified>");
+ escputs(datestring);
+ wprintf("</getlastmodified>");
+ }
wprintf("</prop>");
wprintf("</propstat>");
wprintf("</response>");
}
}
+ FreeStrBuf(&MsgNum);
wprintf("</multistatus>\n");
end_burst();