3179d580f01bb33c789f2e3c7628b40f868ec4d7
[citadel.git] / webcit / graphics.c
1 /*
2  * $Id$
3  *
4  * Handles HTTP upload of graphics files into the system.
5  * \ingroup WebcitHttpServer
6  */
7
8 #include "webcit.h"
9
10 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
11 {
12         char buf[SIZ];
13
14         serv_puts(check_cmd);
15         serv_getln(buf, sizeof buf);
16         if (buf[0] != '2') {
17                 strcpy(WC->ImportantMessage, &buf[4]);
18                 display_main_menu();
19                 return;
20         }
21         output_headers(1, 1, 0, 0, 0, 0);
22
23         output_headers(1, 1, 1, 0, 0, 0);
24
25         svprintf("BOXTITLE", WCS_STRING, _("Image upload"));
26         do_template("beginbox");
27
28         wprintf("<form enctype=\"multipart/form-data\" action=\"%s\" "
29                 "method=\"post\" name=\"graphicsupload\">\n", uplurl);
30
31         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
32         wprintf("<input type=\"hidden\" name=\"which_room\" value=\"");
33         urlescputs(bstr("which_room"));
34         wprintf("\">\n");
35
36         wprintf(_("You can upload any image directly from your computer, "
37                   "as long as it is in GIF, JPEG or PNG"));
38         wprintf("<br /><br />\n");
39
40         wprintf(_("Please select a file to upload:"));
41         wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
42         wprintf("<div class=\"buttons\">");
43         wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
44         wprintf("&nbsp;");
45         wprintf("<input type=\"reset\" value=\"%s\">\n", _("Reset form"));
46         wprintf("&nbsp;");
47         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
48         wprintf("</div>\n");
49         wprintf("</form>\n");
50
51         do_template("endbox");
52
53         wDumpContent(1);
54 }
55
56 void do_graphics_upload(char *upl_cmd)
57 {
58         char buf[SIZ];
59         int bytes_remaining;
60         int pos = 0;
61         int thisblock;
62
63         if (!IsEmptyStr(bstr("cancel_button"))) {
64                 strcpy(WC->ImportantMessage,
65                         _("Graphics upload has been cancelled."));
66                 display_main_menu();
67                 return;
68         }
69
70         if (WC->upload_length == 0) {
71                 strcpy(WC->ImportantMessage,
72                         _("You didn't upload a file."));
73                 display_main_menu();
74                 return;
75         }
76         serv_puts(upl_cmd);
77         serv_getln(buf, sizeof buf);
78         if (buf[0] != '2') {
79                 strcpy(WC->ImportantMessage, &buf[4]);
80                 display_main_menu();
81                 return;
82         }
83         bytes_remaining = WC->upload_length;
84         while (bytes_remaining) {
85                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
86                 serv_printf("WRIT %d", thisblock);
87                 serv_getln(buf, sizeof buf);
88                 if (buf[0] != '7') {
89                         strcpy(WC->ImportantMessage, &buf[4]);
90                         serv_puts("UCLS 0");
91                         serv_getln(buf, sizeof buf);
92                         display_main_menu();
93                         return;
94                 }
95                 thisblock = extract_int(&buf[4], 0);
96                 serv_write(&WC->upload[pos], thisblock);
97                 pos = pos + thisblock;
98                 bytes_remaining = bytes_remaining - thisblock;
99         }
100
101         serv_puts("UCLS 1");
102         serv_getln(buf, sizeof buf);
103         if (buf[0] != 'x') {
104                 display_success(&buf[4]);
105                 return;
106         }
107 }