2 * Handles HTTP upload of graphics files into the system.
4 * Copyright (c) 1996-2016 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);
20 // display the picture (icon, photo, whatever) associated with the current room
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("", "");
43 // upload the picture (icon, photo, whatever) associated with the current room
44 void common_code_for_editroompic_and_editpic(char *servcmd)
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("%s %ld|%s", servcmd, (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 // upload the picture (icon, photo, whatever) associated with the current room
74 void editroompic(void)
76 common_code_for_editroompic_and_editpic("ULRI");
80 // upload the picture (icon, photo, whatever) associated with the current user
83 common_code_for_editroompic_and_editpic("ULUI");
87 // display the screen for uploading graphics to the server
88 void display_graphics_upload(char *filename)
93 serv_printf("UIMG 0||%s", filename);
94 StrBuf_ServGetln(Line);
95 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
101 output_headers(1, 0, 0, 0, 1, 0);
102 do_template("files_graphicsupload");
109 void do_graphics_upload(char *filename)
112 const char *MimeType;
117 bytes_remaining = WCC->upload_length;
119 if (havebstr("cancel_button")) {
120 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
125 if (WCC->upload_length == 0) {
126 AppendImportantMessage(_("You didn't upload a file."), -1);
131 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
132 serv_printf("UIMG 1|%s|%s", MimeType, filename);
135 StrBuf_ServGetln(Line);
136 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
141 while (bytes_remaining) {
142 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
143 serv_printf("WRIT %d", thisblock);
144 StrBuf_ServGetln(Line);
145 if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
147 StrBuf_ServGetln(Line);
152 thisblock = extract_int(ChrPtr(Line) +4, 0);
153 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
155 bytes_remaining -= thisblock;
159 StrBuf_ServGetln(Line);
160 if (*ChrPtr(Line) != 'x') {
161 display_success(ChrPtr(Line) + 4);
169 void edithellopic(void) { do_graphics_upload("hello"); }
170 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
172 /* The users photo display / upload facility */
173 void display_editpic(void) {
174 putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
175 putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
176 display_graphics_upload("editpic");
178 /* room picture dispay / upload facility */
179 void display_editroompic(void) {
180 putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
181 putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
182 display_graphics_upload("editroompic");
185 /* the greetingpage hello pic */
186 void display_edithello(void) {
187 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
188 putbstr("__PICDESC", NewStrBufPlain(_("the Greetingpicture for the login prompt"), -1));
189 putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
190 display_graphics_upload("edithellopic");
193 /* the logoff banner */
194 void display_editgoodbyepic(void) {
195 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbuye")));
196 putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
197 putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbuyepic")));
198 display_graphics_upload("editgoodbuyepic");
206 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
207 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
208 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
209 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
210 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
211 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
212 WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
213 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
214 WebcitAddUrlHandler(HKEY("roompic"), "", 0, display_roompic, 0);