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