Added commands to view a room's file directory and to
authorArt Cancro <ajc@citadel.org>
Wed, 28 Feb 2007 22:51:59 +0000 (22:51 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 28 Feb 2007 22:51:59 +0000 (22:51 +0000)
download files contained within.

webcit/Makefile.in
webcit/downloads.c [new file with mode: 0644]
webcit/mainmenu.c
webcit/static/webcit.css
webcit/webcit.c
webcit/webcit.h

index 259ac670129546ac84170e1db84adc40e669ae6e..96f11f3cd0c2e3e65467e0f7f13c31980af6f45d 100644 (file)
@@ -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 (file)
index 0000000..a1d2984
--- /dev/null
@@ -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("<div id=\"banner\">\n"
+               "<table class=\"downloads_banner\"><tr><td>"
+               "<span class=\"titlebar\">");
+       snprintf(title, sizeof title, _("Files available for download in %s"), WC->wc_roomname);
+       escputs(title);
+       wprintf("</span>"
+               "</td></tr></table>\n"
+               "</div>\n<div id=\"content\">\n"
+       );
+
+       wprintf("<div class=\"fix_scrollbar_bug\">"
+               "<table class=\"downloads_background\"><tr><td>\n");
+       wprintf("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\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("<tr bgcolor=\"#%s\">", (bg ? "DDDDDD" : "FFFFFF"));
+               wprintf("<td>"
+                       "<a href=\"download_file/");
+               urlescputs(filename);
+               wprintf("\"><img src=\"static/diskette_24x.gif\" border=0 align=middle>\n");
+                                       escputs(filename);      wprintf("</a></td>");
+               wprintf("<td>");        escputs(filesize);      wprintf("</td>");
+               wprintf("<td>");        escputs(comment);       wprintf("</td>");
+               wprintf("</tr>\n");
+       }
+
+       wprintf("</table></div>\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]);
+       }
+
+}
+
index 556af35c6bf80560e36f46b13fa9f58d3d910afc..c67efa414508e654d02b4114b074c68cabdc0984 100644 (file)
@@ -87,6 +87,16 @@ void display_main_menu(void)
        wprintf(_("(post in this room)"));
        wprintf("</span>\n");
 
+       if (WC->room_flags & QR_VISDIR) {
+               wprintf("<br /><a href=\"display_room_directory\">"
+                       "<span class=\"mainmenu\">");
+               wprintf(_("File library"));
+               wprintf("</span></A><br />"
+                       "<span class=\"menudesc\">");
+               wprintf(_("(List files available for download)"));
+               wprintf("</span>\n");
+       }
+
        wprintf("</TD><TD>");   /* start of third column */
 
        wprintf("<a href=\"summary\">"
index c8467a4d1b56555825218a13c6e00584737fc4c7..ffe31290e0d65117a0c38006e06f79c570a23881 100644 (file)
@@ -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;
index 6e11ccfed3d3bf818bfd18ddec3a4ed0f468b714..2d71873103ec54593a602ed73f64c083fd8f0f9c 100644 (file)
@@ -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. */
index 3f8cf1602798bd2314fca7c36d50e75c64ca57d4..116fc453e66bedf2104bb5c4a5bcdc592ea7447a 100644 (file)
@@ -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);