2 * Handles HTTP upload of graphics files into the system.
4 * Copyright (c) 1996-2012 by the citadel.org team
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.
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.
17 extern void output_static(const char* What);
21 void display_roompic(void) {
23 StrBuf *Buf = NewStrBuf();
25 StrBuf_ServGetln(Buf);
26 if (GetServerStatus(Buf, NULL) == 6) {
27 StrBufCutLeft(Buf, 4);
28 bytes = StrBufExtract_long(Buf, 0, '|');
29 StrBuf *content_type = NewStrBuf();
30 StrBufExtract_token(content_type, Buf, 3, '|');
31 WC->WBuf = NewStrBuf();
32 StrBuf_ServGetBLOBBuffered(WC->WBuf, bytes);
33 http_transmit_thing(ChrPtr(content_type), 0);
34 FreeStrBuf(&content_type);
37 output_error_pic("", "");
46 if (havebstr("cancel_button")) {
47 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
52 if (WC->upload_length == 0) {
53 AppendImportantMessage(_("You didn't upload a file."), -1);
58 serv_printf("ULUI %ld|%s", (long)WC->upload_length, GuessMimeType(ChrPtr(WC->upload), WC->upload_length));
59 StrBuf *Line = NewStrBuf();
60 StrBuf_ServGetln(Line);
61 if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) {
62 serv_write(ChrPtr(WC->upload), WC->upload_length);
63 display_success(ChrPtr(Line) + 4);
66 AppendImportantMessage((ChrPtr(Line) + 4), -1);
73 void display_graphics_upload(char *filename)
78 serv_printf("UIMG 0||%s", filename);
79 StrBuf_ServGetln(Line);
80 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
86 output_headers(1, 0, 0, 0, 1, 0);
87 do_template("files_graphicsupload");
93 void do_graphics_upload(char *filename)
101 bytes_remaining = WCC->upload_length;
103 if (havebstr("cancel_button")) {
104 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
109 if (WCC->upload_length == 0) {
110 AppendImportantMessage(_("You didn't upload a file."), -1);
115 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
116 serv_printf("UIMG 1|%s|%s", MimeType, filename);
119 StrBuf_ServGetln(Line);
120 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
125 while (bytes_remaining) {
126 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
127 serv_printf("WRIT %d", thisblock);
128 StrBuf_ServGetln(Line);
129 if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
131 StrBuf_ServGetln(Line);
136 thisblock = extract_int(ChrPtr(Line) +4, 0);
137 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
139 bytes_remaining -= thisblock;
143 StrBuf_ServGetln(Line);
144 if (*ChrPtr(Line) != 'x') {
145 display_success(ChrPtr(Line) + 4);
153 void edithellopic(void) { do_graphics_upload("hello"); }
154 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
156 /* The users photo display / upload facility */
157 void display_editpic(void) {
158 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_userpic_")));
159 putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
160 putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
161 display_graphics_upload("editpic");
163 /* room picture dispay / upload facility */
164 void display_editroompic(void) {
165 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_roompic_")));
166 putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
167 putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
168 display_graphics_upload("editroompic");
171 /* the greetingpage hello pic */
172 void display_edithello(void) {
173 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
174 putbstr("__PICDESC", NewStrBufPlain(_("the Greetingpicture for the login prompt"), -1));
175 putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
176 display_graphics_upload("edithellopic");
179 /* the logoff banner */
180 void display_editgoodbyepic(void) {
181 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbuye")));
182 putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
183 putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbuyepic")));
184 display_graphics_upload("editgoodbuyepic");
187 void editroompic(void) {
189 snprintf(buf, SIZ, "_roompic_|%s",
191 do_graphics_upload(buf);
198 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
199 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
200 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
201 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
202 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
203 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
204 WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
205 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
206 WebcitAddUrlHandler(HKEY("roompic"), "", 0, display_roompic, 0);