From 7f0f81d33cd430fd9ca72b934c28d76542183999 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 6 Feb 2005 03:59:33 +0000 Subject: [PATCH] * Added some HTTP Date: header output --- webcit/ChangeLog | 4 +++ webcit/Makefile.in | 4 +-- webcit/groupdav_propfind.c | 68 +++++++++++++++++++++++--------------- webcit/http_datestring.c | 62 ++++++++++++++++++++++++++++++++++ webcit/webcit.h | 1 + webcit/webserver.c | 18 ++++++++-- 6 files changed, 127 insertions(+), 30 deletions(-) create mode 100644 webcit/http_datestring.c diff --git a/webcit/ChangeLog b/webcit/ChangeLog index f52a1b488..e59568572 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -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 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 6d5bc5479..225d91817 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -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: diff --git a/webcit/groupdav_propfind.c b/webcit/groupdav_propfind.c index d0f3f7f65..c34908654 100644 --- a/webcit/groupdav_propfind.c +++ b/webcit/groupdav_propfind.c @@ -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("\r\n" - "\r\n" + wprintf("\n" + "\n" ); serv_puts("LKRA"); @@ -91,7 +98,7 @@ void groupdav_folder_list(void) { */ if ((view == VIEW_CALENDAR) || (view == VIEW_TASKS) || (view == VIEW_ADDRESSBOOK) ) { - wprintf(" \r\n"); + wprintf(" \n"); wprintf(" "); if (strlen(WC->http_host) > 0) { @@ -101,35 +108,35 @@ void groupdav_folder_list(void) { } wprintf("/groupdav/"); urlescputs(roomname); - wprintf("/\r\n"); + wprintf("/\n"); - wprintf(" \r\n"); - wprintf(" HTTP/1.1 200 OK\r\n"); - wprintf(" \r\n"); + wprintf(" \n"); + wprintf(" HTTP/1.1 200 OK\n"); + wprintf(" \n"); wprintf(" "); escputs( roomname); - wprintf( "\r\n"); + wprintf( "\n"); wprintf(" "); switch(view) { case VIEW_CALENDAR: - wprintf(" \r\n"); + wprintf(" \n"); break; case VIEW_TASKS: - wprintf(" \r\n"); + wprintf(" \n"); break; case VIEW_ADDRESSBOOK: - wprintf(" \r\n"); + wprintf(" \n"); break; } - wprintf( "\r\n"); - wprintf(" \r\n"); - wprintf(" \r\n"); - wprintf(" \r\n"); + wprintf( "\n"); + wprintf(" \n"); + wprintf(" \n"); + wprintf(" \n"); } } - wprintf("\r\n\r\n\r\n"); + wprintf("\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("\r\n" - "\r\n" + wprintf("\n" + "\n" ); serv_puts("MSGS ALL"); @@ -219,7 +235,7 @@ void groupdav_propfind(char *dav_pathname) { } if (strlen(uid) > 0) { - wprintf(" \r\n"); + wprintf(" \n"); wprintf(" "); 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("\r\n"); - wprintf(" \r\n"); - wprintf(" HTTP/1.1 200 OK\r\n"); - wprintf(" \"%ld\"\r\n", msgs[i]); - wprintf(" \r\n"); - wprintf(" \r\n"); + wprintf("\n"); + wprintf(" \n"); + wprintf(" HTTP/1.1 200 OK\n"); + wprintf(" \"%ld\"\n", msgs[i]); + wprintf(" \n"); + wprintf(" \n"); } } - wprintf("\r\n\r\n\r\n"); + wprintf("\n\n\n"); end_burst(); if (msgs != NULL) { diff --git a/webcit/http_datestring.c b/webcit/http_datestring.c new file mode 100644 index 000000000..da79733ce --- /dev/null +++ b/webcit/http_datestring.c @@ -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 +#include +#include +#include +# include + +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 + ); +} + diff --git a/webcit/webcit.h b/webcit/webcit.h index 212a095f8..6692c25ec 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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) */ diff --git a/webcit/webserver.c b/webcit/webserver.c index 86d2a237a..d6f56d773 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -7,6 +7,11 @@ * */ +/* + * Uncomment to dump an HTTP trace to stderr +#define HTTP_TRACING 1 + */ + #include #include #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)); } -- 2.30.2