4 * Handles GroupDAV GET requests.
14 * Fetch the entire contents of the room as one big ics file.
15 * This is for "webcal://" type access.
17 void groupdav_get_big_ics(void) {
20 serv_puts("ICAL getics");
21 serv_getln(buf, sizeof buf);
23 wprintf("HTTP/1.1 404 not found\r\n");
24 groupdav_common_headers();
26 "Content-Type: text/plain\r\n"
34 wprintf("HTTP/1.1 200 OK\r\n");
35 groupdav_common_headers();
36 wprintf("Content-type: text/calendar; charset=UTF-8\r\n");
38 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
39 wprintf("%s\r\n", buf);
46 * The pathname is always going to take one of two formats:
47 * /groupdav/room_name/euid (GroupDAV)
48 * /groupdav/room_name (webcal)
50 void groupdav_get(char *dav_pathname) {
51 char dav_roomname[1024];
53 long dav_msgnum = (-1);
56 int found_content_type = 0;
63 char content_type[128];
67 if (num_tokens(dav_pathname, '/') < 3) {
68 wprintf("HTTP/1.1 404 not found\r\n");
69 groupdav_common_headers();
71 "Content-Type: text/plain\r\n"
73 "The object you requested was not found.\r\n"
78 extract_token(dav_roomname, dav_pathname, 2, '/', sizeof dav_roomname);
79 extract_token(dav_uid, dav_pathname, 3, '/', sizeof dav_uid);
80 if ((!strcasecmp(dav_uid, "ics")) || (!strcasecmp(dav_uid, "calendar.ics"))) {
84 /* Go to the correct room. */
85 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
86 gotoroom(dav_roomname);
88 if (strcasecmp(WC->wc_roomname, dav_roomname)) {
89 wprintf("HTTP/1.1 404 not found\r\n");
90 groupdav_common_headers();
92 "Content-Type: text/plain\r\n"
94 "There is no folder called \"%s\" on this server.\r\n",
100 /** GET on the collection itself returns an ICS of the entire collection.
102 if (!strcasecmp(dav_uid, "")) {
103 groupdav_get_big_ics();
107 dav_msgnum = locate_message_by_uid(dav_uid);
108 serv_printf("MSG2 %ld", dav_msgnum);
109 serv_getln(buf, sizeof buf);
111 wprintf("HTTP/1.1 404 not found\r\n");
112 groupdav_common_headers();
114 "Content-Type: text/plain\r\n"
116 "Object \"%s\" was not found in the \"%s\" folder.\r\n",
123 /* We got it; a message is now arriving from the server. Read it in. */
126 found_content_type = 0;
127 strcpy(charset, "UTF-8");
128 strcpy(content_type, "text/plain");
130 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
131 linelen = strlen(buf);
133 /* Append it to the buffer */
134 if ((msglen + linelen + 3) > msgalloc) {
135 msgalloc = ( (msgalloc > 0) ? (msgalloc * 2) : 1024 );
136 msgtext = realloc(msgtext, msgalloc);
138 strcpy(&msgtext[msglen], buf);
140 strcpy(&msgtext[msglen], "\n");
143 /* Also learn some things about the message */
148 if (!strncasecmp(buf, "Date:", 5)) {
149 safestrncpy(date, &buf[5], sizeof date);
152 if (!strncasecmp(buf, "Content-type:", 13)) {
153 safestrncpy(content_type, &buf[13], sizeof content_type);
154 striplt(content_type);
155 ptr = bmstrcasestr(&buf[13], "charset=");
157 safestrncpy(charset, ptr+8, sizeof charset);
159 endptr = strchr(charset, ';');
160 if (endptr != NULL) strcpy(endptr, "");
162 endptr = strchr(content_type, ';');
163 if (endptr != NULL) strcpy(endptr, "");
168 lprintf(9, "CONTENT TYPE: '%s'\n", content_type);
169 lprintf(9, "CHARSET: '%s'\n", charset);
170 lprintf(9, "DATE: '%s'\n", date);
172 /* Now do something with it. FIXME boil it down to only the part we need */
175 endptr = &msgtext[msglen];
177 wprintf("HTTP/1.1 200 OK\r\n");
178 groupdav_common_headers();
179 wprintf("etag: \"%ld\"\r\n", dav_msgnum);
180 wprintf("Content-type: %s; charset=%s\r\n", content_type, charset);
181 wprintf("Date: %s\r\n", date);
185 ptr = memreadline(ptr, buf, sizeof buf);
188 wprintf("%s\r\n", buf);
190 else if ((strlen(buf) == 0) && (in_body == 0)) {
194 } while (ptr < endptr);