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);
23 if (havebstr("cancel_button")) {
24 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
29 if (WC->upload_length == 0) {
30 AppendImportantMessage(_("You didn't upload a file."), -1);
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);
43 AppendImportantMessage((ChrPtr(Line) + 4), -1);
50 void display_graphics_upload(char *filename)
55 serv_printf("UIMG 0||%s", filename);
56 StrBuf_ServGetln(Line);
57 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
63 output_headers(1, 0, 0, 0, 1, 0);
64 do_template("files_graphicsupload");
70 void do_graphics_upload(char *filename)
78 bytes_remaining = WCC->upload_length;
80 if (havebstr("cancel_button")) {
81 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
86 if (WCC->upload_length == 0) {
87 AppendImportantMessage(_("You didn't upload a file."), -1);
92 MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
93 serv_printf("UIMG 1|%s|%s", MimeType, filename);
96 StrBuf_ServGetln(Line);
97 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
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) {
108 StrBuf_ServGetln(Line);
113 thisblock = extract_int(ChrPtr(Line) +4, 0);
114 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
116 bytes_remaining -= thisblock;
120 StrBuf_ServGetln(Line);
121 if (*ChrPtr(Line) != 'x') {
122 display_success(ChrPtr(Line) + 4);
130 void edithellopic(void) { do_graphics_upload("hello"); }
131 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
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");
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");
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");
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");
164 void display_editfloorpic(void) {
167 PicAction = NewStrBuf();
168 StrBufPrintf(PicAction, "_floorpic_|%s", bstr("which_floor"));
169 putbstr("__WHICHPIC", PicAction);
170 putbstr("__PICDESC", NewStrBufPlain(_("the icon for this floor"), -1));
171 putbstr("__UPLURL", NewStrBufPlain(HKEY("editfloorpic")));
172 display_graphics_upload("editfloorpic");
175 void editroompic(void) {
177 snprintf(buf, SIZ, "_roompic_|%s",
179 do_graphics_upload(buf);
182 void editfloorpic(void){
184 snprintf(buf, SIZ, "_floorpic_|%s",
185 bstr("which_floor"));
186 do_graphics_upload(buf);
193 WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
194 WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
195 WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
196 WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
197 WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
198 WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
199 WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
200 WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
201 WebcitAddUrlHandler(HKEY("display_editfloorpic"), "", 0, display_editfloorpic, 0);
202 WebcitAddUrlHandler(HKEY("editfloorpic"), "", 0, editfloorpic, 0);