* Buncha cosmetic changes
[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
35         svprintf("BOXTITLE", WCS_STRING, "Set/change your photo");
36         do_template("beginbox");
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><BR>\n");
52         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
53         wprintf("<BR><BR>");
54         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Upload\">\n");
55         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
56         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Cancel\">\n");
57         wprintf("</FORM>\n");
58         wprintf("</CENTER>\n");
59         do_template("endbox");
60         wDumpContent(1);
61 }
62
63 void do_graphics_upload(char *upl_cmd)
64 {
65         char buf[SIZ];
66         int bytes_remaining;
67         int pos = 0;
68         int thisblock;
69
70         if (!strcasecmp(bstr("sc"), "Cancel")) {
71                 display_main_menu();
72                 return;
73         }
74
75         if (WC->upload_length == 0) {
76                 display_error("You didn't upload a file.\n");
77                 return;
78         }
79         serv_puts(upl_cmd);
80         serv_gets(buf);
81         if (buf[0] != '2') {
82                 display_error(&buf[4]);
83                 return;
84         }
85         bytes_remaining = WC->upload_length;
86         while (bytes_remaining) {
87                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
88                 serv_printf("WRIT %d", thisblock);
89                 serv_gets(buf);
90                 if (buf[0] != '7') {
91                         display_error(&buf[4]);
92                         serv_puts("UCLS 0");
93                         serv_gets(buf);
94                         return;
95                 }
96                 thisblock = extract_int(&buf[4], 0);
97                 serv_write(&WC->upload[pos], thisblock);
98                 pos = pos + thisblock;
99                 bytes_remaining = bytes_remaining - thisblock;
100         }
101
102         serv_puts("UCLS 1");
103         serv_gets(buf);
104         if (buf[0] != 'x') {
105                 display_success(&buf[4]);
106                 return;
107         }
108 }