* Cleaned up the rcs/cvs Id tags and leading comments at the top of some files
[citadel.git] / webcit / graphics.c
1 /*
2  * $Id$
3  *
4  * Handles HTTP upload of graphics files into the system.
5  */
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15 #include <sys/socket.h>
16 #include <sys/time.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27
28 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
29 {
30         char buf[SIZ];
31
32         serv_puts(check_cmd);
33         serv_gets(buf);
34         if (buf[0] != '2') {
35                 strcpy(WC->ImportantMessage, &buf[4]);
36                 display_main_menu();
37                 return;
38         }
39         output_headers(1, 1, 0, 0, 0, 0, 0);
40
41         svprintf("BOXTITLE", WCS_STRING, "Set/change your photo");
42         do_template("beginbox");
43
44         wprintf("<CENTER>\n");
45
46         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s\" "
47                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
48
49         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
50         urlescputs(bstr("which_room"));
51         wprintf("\">\n");
52
53         wprintf("You can upload any image directly from your computer,\n");
54         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
55         wprintf("work).<br /><br />\n");
56
57         wprintf("Please select a file to upload:<br /><br />\n");
58         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
59         wprintf("<br /><br />");
60         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Upload\">\n");
61         wprintf("&nbsp;");
62         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
63         wprintf("&nbsp;");
64         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Cancel\">\n");
65         wprintf("</FORM>\n");
66         wprintf("</CENTER>\n");
67         do_template("endbox");
68         wDumpContent(1);
69 }
70
71 void do_graphics_upload(char *upl_cmd)
72 {
73         char buf[SIZ];
74         int bytes_remaining;
75         int pos = 0;
76         int thisblock;
77
78         if (!strcasecmp(bstr("sc"), "Cancel")) {
79                 strcpy(WC->ImportantMessage,
80                         "Graphics upload cancelled.");
81                 display_main_menu();
82                 return;
83         }
84
85         if (WC->upload_length == 0) {
86                 strcpy(WC->ImportantMessage,
87                         "You didn't upload a file.");
88                 display_main_menu();
89                 return;
90         }
91         serv_puts(upl_cmd);
92         serv_gets(buf);
93         if (buf[0] != '2') {
94                 strcpy(WC->ImportantMessage, &buf[4]);
95                 display_main_menu();
96                 return;
97         }
98         bytes_remaining = WC->upload_length;
99         while (bytes_remaining) {
100                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
101                 serv_printf("WRIT %d", thisblock);
102                 serv_gets(buf);
103                 if (buf[0] != '7') {
104                         strcpy(WC->ImportantMessage, &buf[4]);
105                         serv_puts("UCLS 0");
106                         serv_gets(buf);
107                         display_main_menu();
108                         return;
109                 }
110                 thisblock = extract_int(&buf[4], 0);
111                 serv_write(&WC->upload[pos], thisblock);
112                 pos = pos + thisblock;
113                 bytes_remaining = bytes_remaining - thisblock;
114         }
115
116         serv_puts("UCLS 1");
117         serv_gets(buf);
118         if (buf[0] != 'x') {
119                 display_success(&buf[4]);
120                 return;
121         }
122 }