3 * Handles HTTP upload of graphics files into the system.
5 * Copyright (c) 1996-2016 by the citadel.org team
7 * This program is open source software. You can redistribute it and/or
8 * modify it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 extern void output_static(const char *What);
21 // display the picture (icon, photo, whatever) associated with the current room
22 void display_roompic(void) {
24 StrBuf *Buf = NewStrBuf();
26 StrBuf_ServGetln(Buf);
27 if (GetServerStatus(Buf, NULL) == 6) {
28 StrBufCutLeft(Buf, 4);
29 bytes = StrBufExtract_long(Buf, 0, '|');
30 StrBuf *content_type = NewStrBuf();
31 StrBufExtract_token(content_type, Buf, 3, '|');
32 WC->WBuf = NewStrBuf();
33 StrBuf_ServGetBLOBBuffered(WC->WBuf, bytes);
34 http_transmit_thing(ChrPtr(content_type), 0);
35 FreeStrBuf(&content_type);
38 output_error_pic("", "");
44 // upload the picture (icon, photo, whatever) associated with the current room
45 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) {
75 common_code_for_editroompic_and_editpic("ULRI");
79 // upload the picture (icon, photo, whatever) associated with the current user
81 common_code_for_editroompic_and_editpic("ULUI");
85 // display the screen for uploading graphics to the server
86 void display_graphics_upload(char *filename) {
90 serv_printf("UIMG 0||%s", filename);
91 StrBuf_ServGetln(Line);
92 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
97 output_headers(1, 0, 0, 0, 1, 0);
98 do_template("files_graphicsupload");
105 void do_graphics_upload(char *filename) {
107 const char *MimeType;
112 bytes_remaining = WCC->upload_length;
114 if (havebstr("cancel_button")) {
115 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
120 if (WCC->upload_length == 0) {
121 AppendImportantMessage(_("You didn't upload a file."), -1);
126 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
127 serv_printf("UIMG 1|%s|%s", MimeType, filename);
130 StrBuf_ServGetln(Line);
131 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
136 while (bytes_remaining) {
137 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
138 serv_printf("WRIT %d", thisblock);
139 StrBuf_ServGetln(Line);
140 if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
142 StrBuf_ServGetln(Line);
147 thisblock = extract_int(ChrPtr(Line) + 4, 0);
148 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
150 bytes_remaining -= thisblock;
154 StrBuf_ServGetln(Line);
155 if (*ChrPtr(Line) != 'x') {
156 display_success(ChrPtr(Line) + 4);
164 void edithellopic(void) {
165 do_graphics_upload("hello");
167 void editgoodbuyepic(void) {
168 do_graphics_upload("UIMG 1|%s|goodbuye");
171 /* The users photo display / upload facility */
172 void display_editpic(void) {
173 putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
174 putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
175 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");
202 void InitModule_GRAPHICS(void) {
203 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
204 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
205 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
206 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
207 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
208 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
209 WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
210 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
211 WebcitAddUrlHandler(HKEY("roompic"), "", 0, display_roompic, 0);