* Added some HTTP Date: header output
authorArt Cancro <ajc@citadel.org>
Sun, 6 Feb 2005 03:59:33 +0000 (03:59 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 6 Feb 2005 03:59:33 +0000 (03:59 +0000)
webcit/ChangeLog
webcit/Makefile.in
webcit/groupdav_propfind.c
webcit/http_datestring.c [new file with mode: 0644]
webcit/webcit.h
webcit/webserver.c

index f52a1b48877b8527f7fd65e7873da8c06babb05e..e59568572931c98442f0bcfaea1c7934988cd912 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 528.45  2005/02/06 03:59:33  ajc
+* Added some HTTP Date: header output
+
 Revision 528.44  2005/02/05 22:58:46  ajc
 * All GroupDAV HTTP output is now \r\n instead of \n terminated.
 
@@ -2323,3 +2326,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 6d5bc54792c0b06c4b43721f29ddb42af4b85ef5..225d91817fed9c0284637fa6675482acb4bed232 100644 (file)
@@ -38,7 +38,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        calendar.o calendar_tools.o calendar_view.o event.o \
        availability.o iconbar.o crypto.o inetconf.o notes.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o \
-       groupdav_delete.o groupdav_put.o \
+       groupdav_delete.o groupdav_put.o http_datestring.o \
        $(LIBOBJS)
        $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \
        webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \
@@ -48,7 +48,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        summary.o calendar.o calendar_tools.o calendar_view.o event.o \
        availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \
-       groupdav_put.o \
+       groupdav_put.o http_datestring.o \
        $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webserver
 
 .c.o:
index d0f3f7f65bd6dcffd65c8a177ad084fd51f09cb9..c349086542008989d1862de6a19350e2a7495372 100644 (file)
@@ -62,6 +62,11 @@ void groupdav_folder_list(void) {
        char buf[SIZ];
        char roomname[SIZ];
        int view;
+       char datestring[SIZ];
+       time_t now;
+
+       now = time(NULL);
+       http_datestring(datestring, sizeof datestring, now);
 
        /*
         * Be rude.  Completely ignore the XML request and simply send them
@@ -69,12 +74,14 @@ void groupdav_folder_list(void) {
         */
        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");
+       wprintf("Content-encoding: identity\r\n");
 
        begin_burst();
 
-       wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
-               "<D:multistatus xmlns:D=\"DAV:\">\r\n"
+       wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+               "<D:multistatus xmlns:D=\"DAV:\">\n"
        );
 
        serv_puts("LKRA");
@@ -91,7 +98,7 @@ void groupdav_folder_list(void) {
                 */
                if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) {
 
-                       wprintf(" <D:response>\r\n");
+                       wprintf(" <D:response>\n");
 
                        wprintf("  <D:href>");
                        if (strlen(WC->http_host) > 0) {
@@ -101,35 +108,35 @@ void groupdav_folder_list(void) {
                        }
                        wprintf("/groupdav/");
                        urlescputs(roomname);
-                       wprintf("/</D:href>\r\n");
+                       wprintf("/</D:href>\n");
 
-                       wprintf("  <D:propstat>\r\n");
-                       wprintf("   <D:status>HTTP/1.1 200 OK</D:status>\r\n");
-                       wprintf("   <D:prop>\r\n");
+                       wprintf("  <D:propstat>\n");
+                       wprintf("   <D:status>HTTP/1.1 200 OK</D:status>\n");
+                       wprintf("   <D:prop>\n");
                        wprintf("    <D:displayname>");
                        escputs(                roomname);
-                       wprintf(                        "</D:displayname>\r\n");
+                       wprintf(                        "</D:displayname>\n");
                        wprintf("    <D:resourcetype><D:collection/>");
 
                        switch(view) {
                                case VIEW_CALENDAR:
-                                       wprintf("        <G:vevent-collection />\r\n");
+                                       wprintf("        <G:vevent-collection />\n");
                                        break;
                                case VIEW_TASKS:
-                                       wprintf("        <G:vtodo-collection />\r\n");
+                                       wprintf("        <G:vtodo-collection />\n");
                                        break;
                                case VIEW_ADDRESSBOOK:
-                                       wprintf("        <G:vcard-collection />\r\n");
+                                       wprintf("        <G:vcard-collection />\n");
                                        break;
                        }
 
-                       wprintf(                                "</D:resourcetype>\r\n");
-                       wprintf("   </D:prop>\r\n");
-                       wprintf("  </D:propstat>\r\n");
-                       wprintf(" </D:response>\r\n");
+                       wprintf(                                "</D:resourcetype>\n");
+                       wprintf("   </D:prop>\n");
+                       wprintf("  </D:propstat>\n");
+                       wprintf(" </D:response>\n");
                }
        }
-       wprintf("</D:multistatus>\r\n\r\n\r\n");
+       wprintf("</D:multistatus>\n\n\n");
 
        end_burst();
 }
@@ -148,6 +155,12 @@ void groupdav_propfind(char *dav_pathname) {
        long *msgs = NULL;
        int num_msgs = 0;
        int i;
+       char datestring[SIZ];
+       time_t now;
+
+       now = time(NULL);
+       http_datestring(datestring, sizeof datestring, now);
+
 
        /* First, break off the "/groupdav/" prefix */
        remove_token(dav_pathname, 0, '/');
@@ -176,6 +189,7 @@ void groupdav_propfind(char *dav_pathname) {
        if (strcasecmp(WC->wc_roomname, dav_roomname)) {
                wprintf("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"
@@ -192,12 +206,14 @@ void groupdav_propfind(char *dav_pathname) {
         */
        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");
+       wprintf("Content-encoding: identity\r\n");
 
        begin_burst();
 
-       wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
-               "<D:multistatus xmlns:D=\"DAV:\">\r\n"
+       wprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+               "<D:multistatus xmlns:D=\"DAV:\">\n"
        );
 
        serv_puts("MSGS ALL");
@@ -219,7 +235,7 @@ void groupdav_propfind(char *dav_pathname) {
                }
 
                if (strlen(uid) > 0) {
-                       wprintf(" <D:response>\r\n");
+                       wprintf(" <D:response>\n");
                        wprintf("  <D:href>");
                        if (strlen(WC->http_host) > 0) {
                                wprintf("%s://%s",
@@ -230,16 +246,16 @@ void groupdav_propfind(char *dav_pathname) {
                        urlescputs(WC->wc_roomname);
                        euid_escapize(encoded_uid, uid);
                        wprintf("/%s", encoded_uid);
-                       wprintf("</D:href>\r\n");
-                       wprintf("   <D:propstat>\r\n");
-                       wprintf("    <D:status>HTTP/1.1 200 OK</D:status>\r\n");
-                       wprintf("    <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\r\n", msgs[i]);
-                       wprintf("   </D:propstat>\r\n");
-                       wprintf(" </D:response>\r\n");
+                       wprintf("</D:href>\n");
+                       wprintf("   <D:propstat>\n");
+                       wprintf("    <D:status>HTTP/1.1 200 OK</D:status>\n");
+                       wprintf("    <D:prop><D:getetag>\"%ld\"</D:getetag></D:prop>\n", msgs[i]);
+                       wprintf("   </D:propstat>\n");
+                       wprintf(" </D:response>\n");
                }
        }
 
-       wprintf("</D:multistatus>\r\n\r\n\r\n");
+       wprintf("</D:multistatus>\n\n\n");
        end_burst();
 
        if (msgs != NULL) {
diff --git a/webcit/http_datestring.c b/webcit/http_datestring.c
new file mode 100644 (file)
index 0000000..da79733
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ *
+ * Function to generate HTTP-compliant textual time/date stamp
+ * (This module was lifted directly from the Citadel server source)
+ *
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+# include <time.h>
+
+static char *httpdate_months[] = {
+       "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static char *httpdate_weekdays[] = {
+       "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+
+/*
+ * Supplied with a unix timestamp, generate a textual time/date stamp
+ */
+void http_datestring(char *buf, size_t n, time_t xtime) {
+       struct tm t;
+
+       long offset;
+       char offsign;
+
+       localtime_r(&xtime, &t);
+
+       /* Convert "seconds west of GMT" to "hours/minutes offset" */
+#ifdef HAVE_STRUCT_TM_TM_GMTOFF
+       offset = t.tm_gmtoff;
+#else
+       offset = timezone;
+#endif
+       if (offset > 0) {
+               offsign = '+';
+       }
+       else {
+               offset = 0L - offset;
+               offsign = '-';
+       }
+       offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
+
+       snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
+               httpdate_weekdays[t.tm_wday],
+               t.tm_mday,
+               httpdate_months[t.tm_mon],
+               t.tm_year + 1900,
+               t.tm_hour,
+               t.tm_min,
+               t.tm_sec,
+               offsign, offset
+       );
+}
+
index 212a095f8ccef6d8c4a74e5fe332c999da05c5ff..6692c25ecc561aa6f187fa20d07fd2aeb1dc2502 100644 (file)
@@ -493,6 +493,7 @@ void begin_burst(void);
 void end_burst(void);
 
 extern char *ascmonths[];
+void http_datestring(char *buf, size_t n, time_t xtime);
 
 
 /* Views (from citadel.h) */
index 86d2a237a3293d4a4c8c9026e14939b2cd62cc80..d6f56d77312a440b951aaf3b6160c80fd0c48a93 100644 (file)
@@ -7,6 +7,11 @@
  *
  */
 
+/*
+ * Uncomment to dump an HTTP trace to stderr
+#define HTTP_TRACING 1
+ */
+
 #include <ctype.h>
 #include <stdlib.h>
 #ifdef HAVE_UNISTD_H
@@ -150,7 +155,12 @@ int client_read_to(int sock, char *buf, int bytes, int timeout)
                }
                len = len + rlen;
        }
-       /* write(2, buf, bytes); FIXME */
+
+#ifdef HTTP_TRACING
+       write(2, "\033[32m", 5);
+       write(2, buf, bytes);
+       write(2, "\033[30m", 5);
+#endif
        return (1);
 }
 
@@ -170,7 +180,11 @@ ssize_t client_write(const void *buf, size_t count) {
                return(count);
        }
 #endif
-       /* write(2, buf, count); FIXME */
+#ifdef HTTP_TRACING
+       write(2, "\033[34m", 5);
+       write(2, buf, count);
+       write(2, "\033[30m", 5);
+#endif
        return(write(WC->http_sock, buf, count));
 }