1 // Handles HTTP upload of graphics files into the system.
3 // Copyright (c) 1996-2022 by the citadel.org team
5 // This program is open source software. You can redistribute it and/or
6 // modify it under the terms of the GNU General Public License, version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
15 extern void output_static(const char* What);
18 // display the picture (icon, photo, whatever) associated with the current room
19 void display_roompic(void) {
21 StrBuf *Buf = NewStrBuf();
23 StrBuf_ServGetln(Buf);
24 if (GetServerStatus(Buf, NULL) == 6) {
25 StrBufCutLeft(Buf, 4);
26 bytes = StrBufExtract_long(Buf, 0, '|');
27 StrBuf *content_type = NewStrBuf();
28 StrBufExtract_token(content_type, Buf, 3, '|');
29 WC->WBuf = NewStrBuf();
30 StrBuf_ServGetBLOBBuffered(WC->WBuf, bytes);
31 http_transmit_thing(ChrPtr(content_type), 0);
32 FreeStrBuf(&content_type);
35 output_error_pic("", "");
41 // upload the picture (icon, photo, whatever) associated with the current room
42 void common_code_for_editroompic_and_editpic(char *servcmd) {
43 if (havebstr("cancel_button")) {
44 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
49 if (WC->upload_length == 0) {
50 AppendImportantMessage(_("You didn't upload a file."), -1);
55 serv_printf("%s %ld|%s", servcmd, (long)WC->upload_length, GuessMimeType(ChrPtr(WC->upload), WC->upload_length));
56 StrBuf *Line = NewStrBuf();
57 StrBuf_ServGetln(Line);
58 if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) {
59 serv_write(ChrPtr(WC->upload), WC->upload_length);
60 display_success(ChrPtr(Line) + 4);
63 AppendImportantMessage((ChrPtr(Line) + 4), -1);
70 // upload the picture (icon, photo, whatever) associated with the current room
71 void editroompic(void) {
72 common_code_for_editroompic_and_editpic("ULRI");
76 // upload the picture (icon, photo, whatever) associated with the current user
78 common_code_for_editroompic_and_editpic("ULUI");
82 // display the screen for uploading graphics to the server
83 void display_graphics_upload(char *filename) {
84 output_headers(1, 0, 0, 0, 1, 0);
85 do_template("files_graphicsupload");
90 void do_graphics_upload(char *filename) {
97 bytes_remaining = WCC->upload_length;
99 if (havebstr("cancel_button")) {
100 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
105 if (WCC->upload_length == 0) {
106 AppendImportantMessage(_("You didn't upload a file."), -1);
111 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
112 serv_printf("UIMG 1|%s|%s", MimeType, filename);
115 StrBuf_ServGetln(Line);
116 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
121 while (bytes_remaining) {
122 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
123 serv_printf("WRIT %d", thisblock);
124 StrBuf_ServGetln(Line);
125 if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
127 StrBuf_ServGetln(Line);
132 thisblock = extract_int(ChrPtr(Line) +4, 0);
133 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
135 bytes_remaining -= thisblock;
139 StrBuf_ServGetln(Line);
140 if (*ChrPtr(Line) != 'x') {
141 display_success(ChrPtr(Line) + 4);
149 void edithellopic(void) { do_graphics_upload("hello"); }
150 void editgoodbyepic(void) { do_graphics_upload("UIMG 1|%s|goodbye"); }
152 // The user's photo display / upload facility
153 void display_editpic(void) {
154 putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
155 putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
156 display_graphics_upload("editpic");
159 // room picture dispay / upload facility
160 void display_editroompic(void) {
161 putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
162 putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
163 display_graphics_upload("editroompic");
166 // the login page graphics
167 void display_edithello(void) {
168 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
169 putbstr("__PICDESC", NewStrBufPlain(_("graphics to be displayed on the login screen"), -1));
170 putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
171 display_graphics_upload("edithellopic");
175 void display_editgoodbyepic(void) {
176 putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbye")));
177 putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
178 putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbyepic")));
179 display_graphics_upload("editgoodbyepic");
187 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
188 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
189 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
190 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
191 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
192 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
193 WebcitAddUrlHandler(HKEY("display_editgoodbye"), "", 0, display_editgoodbyepic, 0);
194 WebcitAddUrlHandler(HKEY("editgoodbyepic"), "", 0, editgoodbyepic, 0);
195 WebcitAddUrlHandler(HKEY("roompic"), "", 0, display_roompic, 0);