* Rewrote the HTTP engine and application coupling to run in a worker thread
[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[256];
26
27         serv_puts(check_cmd);
28         serv_gets(buf);
29         if (buf[0] != '2') {
30                 display_error(&buf[4]);
31                 return;
32         }
33         wprintf("HTTP/1.0 200 OK\n");
34         output_headers(1);
35         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
36         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
37         wprintf("<B>Set/change %s</B>\n", description);
38         wprintf("</FONT></TD></TR></TABLE>\n");
39
40         wprintf("<CENTER>\n");
41
42         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s&which_room=%s\" METHOD=\"POST\">\n", uplurl, bstr("which_room"));
43
44         wprintf("You can upload any image directly from your computer,\n");
45         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
46         wprintf("work).<BR><BR>\n");
47
48         wprintf("Please select a file to upload:<BR>\n");
49         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
50         wprintf("<BR>");
51         wprintf("<INPUT TYPE=\"SUBMIT\" VALUE=\"Upload\">\n");
52         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
53         wprintf("</FORM>\n");
54         wprintf("<A HREF=\"/display_main_menu\">Cancel</A>\n");
55         wprintf("</CENTER>\n");
56         wDumpContent(1);
57 }
58
59 void do_graphics_upload(char *upl_cmd)
60 {
61         char buf[256];
62         int bytes_remaining;
63         int pos = 0;
64         int thisblock;
65
66         if (WC->upload_length == 0) {
67                 display_error("You didn't upload a file.\n");
68                 return;
69         }
70         serv_puts(upl_cmd);
71         serv_gets(buf);
72         if (buf[0] != '2') {
73                 display_error(&buf[4]);
74                 return;
75         }
76         bytes_remaining = WC->upload_length;
77         while (bytes_remaining) {
78                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
79                 serv_printf("WRIT %d", thisblock);
80                 serv_gets(buf);
81                 if (buf[0] != '7') {
82                         display_error(&buf[4]);
83                         serv_puts("UCLS 0");
84                         serv_gets(buf);
85                         return;
86                 }
87                 thisblock = extract_int(&buf[4], 0);
88                 serv_write(&WC->upload[pos], thisblock);
89                 pos = pos + thisblock;
90                 bytes_remaining = bytes_remaining - thisblock;
91         }
92
93         serv_puts("UCLS 1");
94         serv_gets(buf);
95         if (buf[0] != 'x') {
96                 display_success(&buf[4]);
97                 return;
98         }
99 }
100
101
102
103 void select_floor_to_edit_pic(void)
104 {
105         int a;
106
107         wprintf("HTTP/1.0 200 OK\n");
108         output_headers(1);
109
110         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
111         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
112         wprintf("<B>Select floor to edit label graphic</B>\n");
113         wprintf("</FONT></TD></TR></TABLE>\n");
114
115         load_floorlist();
116         for (a = 0; a < 128; ++a)
117                 if (strlen(floorlist[a]) > 0) {
118                         wprintf("<A HREF=\"/display_editfloorpic&which_floor=%d\">", a);
119                         escputs(floorlist[a]);
120                         wprintf("</A>\n");
121                 }
122         wDumpContent(1);
123 }