From a98b77122767a5ab63763b37715f2b8a5403de34 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 28 Feb 2007 22:51:59 +0000 Subject: [PATCH] Added commands to view a room's file directory and to download files contained within. --- webcit/Makefile.in | 3 +- webcit/downloads.c | 92 ++++++++++++++++++++++++++++++++++++++++ webcit/mainmenu.c | 10 +++++ webcit/static/webcit.css | 4 +- webcit/webcit.c | 4 ++ webcit/webcit.h | 2 + 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 webcit/downloads.c diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 259ac6701..96f11f3cd 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -52,6 +52,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \ groupdav_main.o groupdav_get.o groupdav_propfind.o fmt_date.o \ groupdav_options.o autocompletion.o gettext.o tabs.o sieve.o \ groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \ + downloads.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 \ @@ -63,7 +64,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \ groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \ groupdav_options.o autocompletion.o tabs.o smtpqueue.o sieve.o \ groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o \ - gettext.o \ + gettext.o downloads.o \ $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webserver .c.o: diff --git a/webcit/downloads.c b/webcit/downloads.c new file mode 100644 index 000000000..a1d2984c4 --- /dev/null +++ b/webcit/downloads.c @@ -0,0 +1,92 @@ +/* + * $Id: downloads.c 4849 2007-01-08 20:05:56Z ajc $ + */ +#include "webcit.h" + +void display_room_directory(void) +{ + char buf[1024]; + char filename[256]; + char filesize[256]; + char comment[512]; + int bg = 0; + char title[256]; + + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
\n" + "
" + ""); + snprintf(title, sizeof title, _("Files available for download in %s"), WC->wc_roomname); + escputs(title); + wprintf("" + "
\n" + "
\n
\n" + ); + + wprintf("
" + "\n", + _("Filename"), + _("Size"), + _("Description") + ); + + serv_puts("RDIR"); + serv_getln(buf, sizeof buf); + if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) + { + extract_token(filename, buf, 0, '|', sizeof filename); + extract_token(filesize, buf, 1, '|', sizeof filesize); + extract_token(comment, buf, 2, '|', sizeof comment); + bg = 1 - bg; + wprintf("", (bg ? "DDDDDD" : "FFFFFF")); + wprintf(""); + wprintf(""); + wprintf(""); + wprintf("\n"); + } + + wprintf("
\n"); + wprintf("
%s%s%s
" + "\n"); + escputs(filename); wprintf(""); escputs(filesize); wprintf(""); escputs(comment); wprintf("
\n"); + wDumpContent(1); +} + + +void download_file(char *filename) +{ + char buf[256]; + off_t bytes; + char content_type[256]; + char *content = NULL; + int force_download = 0; + + serv_printf("OPEN %s", filename); + serv_getln(buf, sizeof buf); + if (buf[0] == '2') { + bytes = extract_long(&buf[4], 0); + content = malloc(bytes + 2); + if (force_download) { + strcpy(content_type, "application/octet-stream"); + } + else { + extract_token(content_type, &buf[4], 3, '|', sizeof content_type); + } + output_headers(0, 0, 0, 0, 0, 0); + read_server_binary(content, bytes); + serv_puts("CLOS"); + serv_getln(buf, sizeof buf); + http_transmit_thing(content, bytes, content_type, 0); + free(content); + } else { + wprintf("HTTP/1.1 404 %s\n", &buf[4]); + output_headers(0, 0, 0, 0, 0, 0); + wprintf("Content-Type: text/plain\r\n"); + wprintf("\r\n"); + wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]); + } + +} + diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 556af35c6..c67efa414 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -87,6 +87,16 @@ void display_main_menu(void) wprintf(_("(post in this room)")); wprintf("\n"); + if (WC->room_flags & QR_VISDIR) { + wprintf("
" + ""); + wprintf(_("File library")); + wprintf("
" + ""); + wprintf(_("(List files available for download)")); + wprintf("\n"); + } + wprintf(""); /* start of third column */ wprintf("" diff --git a/webcit/static/webcit.css b/webcit/static/webcit.css index c8467a4d1..ffe31290e 100644 --- a/webcit/static/webcit.css +++ b/webcit/static/webcit.css @@ -705,7 +705,7 @@ div.auto_complete ul strong.highlight { background-color: #ffffff; } -.smtpqueue_background, .tabs_background, .useredit_background, .userlist_background, .vcard_edit_background, .who_background { +.smtpqueue_background, .tabs_background, .useredit_background, .userlist_background, .downloads_background, .vcard_edit_background, .who_background { border: 0; width: 100%; background-color: #ffffff; @@ -723,7 +723,7 @@ div.auto_complete ul strong.highlight { background-color: #444455; } -.smtpqueue_banner, .summary_banner, .useredit_banner, .userlist_banner, .vcard_edit_banner, .who_banner, .room_banner { +.smtpqueue_banner, .summary_banner, .useredit_banner, .userlist_banner, .downloads_banner, .vcard_edit_banner, .who_banner, .room_banner { border: 0; width: 100%; background-color: #444455; diff --git a/webcit/webcit.c b/webcit/webcit.c index 6e11ccfed..2d7187310 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -1656,6 +1656,10 @@ void session_loop(struct httprequest *req) wDumpContent(1); } else if (!strcasecmp(action, "updatenote")) { updatenote(); + } else if (!strcasecmp(action, "display_room_directory")) { + display_room_directory(); + } else if (!strcasecmp(action, "download_file")) { + download_file(index[1]); } /** When all else fais, display the main menu. */ diff --git a/webcit/webcit.h b/webcit/webcit.h index 3f8cf1602..116fc453e 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -641,6 +641,8 @@ void end_ajax_response(void); void initialize_viewdefs(void); void initialize_axdefs(void); void list_all_rooms_by_floor(char *viewpref); +void display_room_directory(void); +void download_file(char *); #ifdef WEBCIT_WITH_CALENDAR_SERVICE void display_edit_task(void); -- 2.30.2