* We don't need no steenking workaround. Problem fixed. MIME parser not
[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=\"which_room\" VALUE=\"");
44         urlescputs(bstr("which_room"));
45         wprintf("\">\n");
46
47         wprintf("You can upload any image directly from your computer,\n");
48         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
49         wprintf("work).<BR><BR>\n");
50
51         wprintf("Please select a file to upload:<BR>\n");
52         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
53         wprintf("<BR>");
54         wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
55         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
56         wprintf("</FORM>\n");
57         wprintf("<A HREF=\"/display_main_menu\">Cancel</A>\n");
58         wprintf("</CENTER>\n");
59         wDumpContent(1);
60 }
61
62 void do_graphics_upload(char *upl_cmd)
63 {
64         char buf[SIZ];
65         int bytes_remaining;
66         int pos = 0;
67         int thisblock;
68
69         if (WC->upload_length == 0) {
70                 display_error("You didn't upload a file.\n");
71                 return;
72         }
73         serv_puts(upl_cmd);
74         serv_gets(buf);
75         if (buf[0] != '2') {
76                 display_error(&buf[4]);
77                 return;
78         }
79         bytes_remaining = WC->upload_length;
80         while (bytes_remaining) {
81                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
82                 serv_printf("WRIT %d", thisblock);
83                 serv_gets(buf);
84                 if (buf[0] != '7') {
85                         display_error(&buf[4]);
86                         serv_puts("UCLS 0");
87                         serv_gets(buf);
88                         return;
89                 }
90                 thisblock = extract_int(&buf[4], 0);
91                 serv_write(&WC->upload[pos], thisblock);
92                 pos = pos + thisblock;
93                 bytes_remaining = bytes_remaining - thisblock;
94         }
95
96         serv_puts("UCLS 1");
97         serv_gets(buf);
98         if (buf[0] != 'x') {
99                 display_success(&buf[4]);
100                 return;
101         }
102 }