Removed the _floorpic_ infrastructure entirely -- we don't use those anymore.
[citadel.git] / webcit / graphics.c
1 /*
2  * Handles HTTP upload of graphics files into the system.
3  *
4  * Copyright (c) 1996-2012 by the citadel.org team
5  *
6  * This program is open source software.  You can redistribute it and/or
7  * modify it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include "webcit.h"
16
17 extern void output_static(const char* What);
18
19
20 // upload your photo
21 void editpic(void)
22 {
23         if (havebstr("cancel_button")) {
24                 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
25                 display_main_menu();
26                 return;
27         }
28
29         if (WC->upload_length == 0) {
30                 AppendImportantMessage(_("You didn't upload a file."), -1);
31                 display_main_menu();
32                 return;
33         }
34         
35         serv_printf("ULUI %ld|%s", (long)WC->upload_length, GuessMimeType(ChrPtr(WC->upload), WC->upload_length));
36         StrBuf *Line = NewStrBuf();
37         StrBuf_ServGetln(Line);
38         if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) {
39                 serv_write(ChrPtr(WC->upload), WC->upload_length);
40                 display_success(ChrPtr(Line) + 4);
41         }
42         else {
43                 AppendImportantMessage((ChrPtr(Line) + 4), -1);
44                 display_main_menu();
45         }
46         FreeStrBuf(&Line);
47 }
48
49
50 void display_graphics_upload(char *filename)
51 {
52         StrBuf *Line;
53
54         Line = NewStrBuf();
55         serv_printf("UIMG 0||%s", filename);
56         StrBuf_ServGetln(Line);
57         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
58                 display_main_menu();
59                 return;
60         }
61         else
62         {
63                 output_headers(1, 0, 0, 0, 1, 0);
64                 do_template("files_graphicsupload");
65                 end_burst();
66         }
67         FreeStrBuf(&Line);
68 }
69
70 void do_graphics_upload(char *filename)
71 {
72         StrBuf *Line;
73         const char *MimeType;
74         wcsession *WCC = WC;
75         int bytes_remaining;
76         int pos = 0;
77         int thisblock;
78         bytes_remaining = WCC->upload_length;
79
80         if (havebstr("cancel_button")) {
81                 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
82                 display_main_menu();
83                 return;
84         }
85
86         if (WCC->upload_length == 0) {
87                 AppendImportantMessage(_("You didn't upload a file."), -1);
88                 display_main_menu();
89                 return;
90         }
91         
92         MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
93         serv_printf("UIMG 1|%s|%s", MimeType, filename);
94
95         Line = NewStrBuf();
96         StrBuf_ServGetln(Line);
97         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
98                 display_main_menu();
99                 FreeStrBuf(&Line);
100                 return;
101         }
102         while (bytes_remaining) {
103                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
104                 serv_printf("WRIT %d", thisblock);
105                 StrBuf_ServGetln(Line);
106                 if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
107                         serv_puts("UCLS 0");
108                         StrBuf_ServGetln(Line);
109                         display_main_menu();
110                         FreeStrBuf(&Line);
111                         return;
112                 }
113                 thisblock = extract_int(ChrPtr(Line) +4, 0);
114                 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
115                 pos += thisblock;
116                 bytes_remaining -= thisblock;
117         }
118
119         serv_puts("UCLS 1");
120         StrBuf_ServGetln(Line);
121         if (*ChrPtr(Line) != 'x') {
122                 display_success(ChrPtr(Line) + 4);
123         
124         }
125         FreeStrBuf(&Line);
126
127 }
128
129
130 void edithellopic(void)    { do_graphics_upload("hello"); }
131 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
132
133 /* The users photo display / upload facility */
134 void display_editpic(void) {
135         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_userpic_")));
136         putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
137         putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
138         display_graphics_upload("editpic");
139 }
140 /* room picture dispay / upload facility */
141 void display_editroompic(void) {
142         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_roompic_")));
143         putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
144         putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
145         display_graphics_upload("editroompic");
146 }
147
148 /* the greetingpage hello pic */
149 void display_edithello(void) {
150         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
151         putbstr("__PICDESC", NewStrBufPlain(_("the Greetingpicture for the login prompt"), -1));
152         putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
153         display_graphics_upload("edithellopic");
154 }
155
156 /* the logoff banner */
157 void display_editgoodbyepic(void) {
158         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbuye")));
159         putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
160         putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbuyepic")));
161         display_graphics_upload("editgoodbuyepic");
162 }
163
164 void editroompic(void) {
165         char buf[SIZ];
166         snprintf(buf, SIZ, "_roompic_|%s",
167                  bstr("which_room"));
168         do_graphics_upload(buf);
169 }
170
171 void 
172 InitModule_GRAPHICS
173 (void)
174 {
175         WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
176         WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
177         WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
178         WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
179         WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
180         WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
181         WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
182         WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
183 }