graphics.c

00001 /*
00002  * $Id: graphics.c 5147 2007-05-08 15:36:22Z ajc $
00003  *
00004  * Handles HTTP upload of graphics files into the system.
00005  * \ingroup WebcitHttpServer
00006  */
00007 
00008 #include "webcit.h"
00009 
00010 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
00011 {
00012         char buf[SIZ];
00013 
00014         serv_puts(check_cmd);
00015         serv_getln(buf, sizeof buf);
00016         if (buf[0] != '2') {
00017                 strcpy(WC->ImportantMessage, &buf[4]);
00018                 display_main_menu();
00019                 return;
00020         }
00021         output_headers(1, 1, 0, 0, 0, 0);
00022 
00023         output_headers(1, 1, 2, 0, 0, 0);
00024         wprintf("<div id=\"banner\">\n"
00025                 "<TABLE class=\"graphics_banner\"><TR><TD>"
00026                 "<SPAN CLASS=\"titlebar\">");
00027         wprintf(_("Image upload"));
00028         wprintf("</SPAN>"
00029                 "</TD></TR></TABLE>\n"
00030                 "</div>\n<div id=\"content\">\n"
00031         );
00032 
00033         wprintf("<div class=\"fix_scrollbar_bug\">"
00034                 "<table class=\"graphics_background\"><tr><td>\n");
00035 
00036         wprintf("<CENTER>\n");
00037 
00038         wprintf("<FORM ENCTYPE=\"multipart/form-data\" action=\"%s\" "
00039                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
00040 
00041         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
00042         urlescputs(bstr("which_room"));
00043         wprintf("\">\n");
00044 
00045         wprintf(_("You can upload any image directly from your computer, "
00046                 "as long as it is in GIF format (JPEG, PNG, etc. won't "
00047                 "work)."));
00048         wprintf("<br /><br />\n");
00049 
00050         wprintf(_("Please select a file to upload:"));
00051         wprintf("<br /><br />\n");
00052         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
00053         wprintf("<br /><br />");
00054         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"upload_button\" VALUE=\"%s\">\n", _("Upload"));
00055         wprintf("&nbsp;");
00056         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"%s\">\n", _("Reset form"));
00057         wprintf("&nbsp;");
00058         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"cancel_button\" VALUE=\"%s\">\n", _("Cancel"));
00059         wprintf("</FORM>\n");
00060         wprintf("</CENTER>\n");
00061         wprintf("</td></tr></table></div>\n");
00062         wDumpContent(1);
00063 }
00064 
00065 void do_graphics_upload(char *upl_cmd)
00066 {
00067         char buf[SIZ];
00068         int bytes_remaining;
00069         int pos = 0;
00070         int thisblock;
00071 
00072         if (strlen(bstr("cancel_button")) > 0) {
00073                 strcpy(WC->ImportantMessage,
00074                         _("Graphics upload has been cancelled."));
00075                 display_main_menu();
00076                 return;
00077         }
00078 
00079         if (WC->upload_length == 0) {
00080                 strcpy(WC->ImportantMessage,
00081                         _("You didn't upload a file."));
00082                 display_main_menu();
00083                 return;
00084         }
00085         serv_puts(upl_cmd);
00086         serv_getln(buf, sizeof buf);
00087         if (buf[0] != '2') {
00088                 strcpy(WC->ImportantMessage, &buf[4]);
00089                 display_main_menu();
00090                 return;
00091         }
00092         bytes_remaining = WC->upload_length;
00093         while (bytes_remaining) {
00094                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
00095                 serv_printf("WRIT %d", thisblock);
00096                 serv_getln(buf, sizeof buf);
00097                 if (buf[0] != '7') {
00098                         strcpy(WC->ImportantMessage, &buf[4]);
00099                         serv_puts("UCLS 0");
00100                         serv_getln(buf, sizeof buf);
00101                         display_main_menu();
00102                         return;
00103                 }
00104                 thisblock = extract_int(&buf[4], 0);
00105                 serv_write(&WC->upload[pos], thisblock);
00106                 pos = pos + thisblock;
00107                 bytes_remaining = bytes_remaining - thisblock;
00108         }
00109 
00110         serv_puts("UCLS 1");
00111         serv_getln(buf, sizeof buf);
00112         if (buf[0] != 'x') {
00113                 display_success(&buf[4]);
00114                 return;
00115         }
00116 }

Generated on Wed Jun 20 23:13:08 2007 for webcit by  doxygen 1.5.2