* Minor workaround in web forms to handle mime parser problem in uploads
[citadel.git] / webcit / graphics.c
1
2 #include <ctype.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <signal.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <sys/socket.h>
11 #include <sys/time.h>
12 #include <limits.h>
13 #include <netinet/in.h>
14 #include <netdb.h>
15 #include <string.h>
16 #include <pwd.h>
17 #include <errno.h>
18 #include <stdarg.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include "webcit.h"
22
23 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
24 {
25         char buf[SIZ];
26
27         serv_puts(check_cmd);
28         serv_gets(buf);
29         if (buf[0] != '2') {
30                 display_error(&buf[4]);
31                 return;
32         }
33         output_headers(3);
34         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
35         wprintf("<SPAN CLASS=\"titlebar\">Set/change %s</SPAN>\n", description);
36         wprintf("</TD></TR></TABLE>\n");
37
38         wprintf("<CENTER>\n");
39
40         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s\" "
41                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
42
43         wprintf("<INPUT TYPE=\"hidden\" NAME=\"foo\" VALUE=\"bar\">\n");
44
45         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
46         urlescputs(bstr("which_room"));
47         wprintf("\">\n");
48
49         wprintf("You can upload any image directly from your computer,\n");
50         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
51         wprintf("work).<BR><BR>\n");
52
53         wprintf("Please select a file to upload:<BR>\n");
54         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
55         wprintf("<BR>");
56         wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
57         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
58         wprintf("<INPUT TYPE=\"hidden\" NAME=\"baz\" VALUE=\"eek\">\n");
59         wprintf("</FORM>\n");
60         wprintf("<A HREF=\"/display_main_menu\">Cancel</A>\n");
61         wprintf("</CENTER>\n");
62         wDumpContent(1);
63 }
64
65 void do_graphics_upload(char *upl_cmd)
66 {
67         char buf[SIZ];
68         int bytes_remaining;
69         int pos = 0;
70         int thisblock;
71
72         if (WC->upload_length == 0) {
73                 display_error("You didn't upload a file.\n");
74                 return;
75         }
76         serv_puts(upl_cmd);
77         serv_gets(buf);
78         if (buf[0] != '2') {
79                 display_error(&buf[4]);
80                 return;
81         }
82         bytes_remaining = WC->upload_length;
83         while (bytes_remaining) {
84                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
85                 serv_printf("WRIT %d", thisblock);
86                 serv_gets(buf);
87                 if (buf[0] != '7') {
88                         display_error(&buf[4]);
89                         serv_puts("UCLS 0");
90                         serv_gets(buf);
91                         return;
92                 }
93                 thisblock = extract_int(&buf[4], 0);
94                 serv_write(&WC->upload[pos], thisblock);
95                 pos = pos + thisblock;
96                 bytes_remaining = bytes_remaining - thisblock;
97         }
98
99         serv_puts("UCLS 1");
100         serv_gets(buf);
101         if (buf[0] != 'x') {
102                 display_success(&buf[4]);
103                 return;
104         }
105 }