removed a bunch of blank comment lines
[citadel.git] / webcit / graphics.c
1 /*
2  * Handles HTTP upload of graphics files into the system.
3  *
4  * Copyright (c) 1996-2012 by the citadel.org team
5  *
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.
8  *
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.
13  */
14
15 #include "webcit.h"
16
17 extern void output_static(const char* What);
18
19 void display_graphics_upload(char *filename)
20 {
21         StrBuf *Line;
22
23         Line = NewStrBuf();
24         serv_printf("UIMG 0||%s", filename);
25         StrBuf_ServGetln(Line);
26         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
27                 display_main_menu();
28                 return;
29         }
30         else
31         {
32                 output_headers(1, 0, 0, 0, 1, 0);
33                 do_template("files_graphicsupload");
34                 end_burst();
35         }
36         FreeStrBuf(&Line);
37 }
38
39 void do_graphics_upload(char *filename)
40 {
41         StrBuf *Line;
42         const char *MimeType;
43         wcsession *WCC = WC;
44         int bytes_remaining;
45         int pos = 0;
46         int thisblock;
47         bytes_remaining = WCC->upload_length;
48
49         if (havebstr("cancel_button")) {
50                 AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
51                 display_main_menu();
52                 return;
53         }
54
55         if (WCC->upload_length == 0) {
56                 AppendImportantMessage(_("You didn't upload a file."), -1);
57                 display_main_menu();
58                 return;
59         }
60         
61         MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
62         serv_printf("UIMG 1|%s|%s", MimeType, filename);
63
64         Line = NewStrBuf();
65         StrBuf_ServGetln(Line);
66         if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
67                 display_main_menu();
68                 FreeStrBuf(&Line);
69                 return;
70         }
71         while (bytes_remaining) {
72                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
73                 serv_printf("WRIT %d", thisblock);
74                 StrBuf_ServGetln(Line);
75                 if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
76                         serv_puts("UCLS 0");
77                         StrBuf_ServGetln(Line);
78                         display_main_menu();
79                         FreeStrBuf(&Line);
80                         return;
81                 }
82                 thisblock = extract_int(ChrPtr(Line) +4, 0);
83                 serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
84                 pos += thisblock;
85                 bytes_remaining -= thisblock;
86         }
87
88         serv_puts("UCLS 1");
89         StrBuf_ServGetln(Line);
90         if (*ChrPtr(Line) != 'x') {
91                 display_success(ChrPtr(Line) + 4);
92         
93         }
94         FreeStrBuf(&Line);
95
96 }
97
98
99 void edithellopic(void)    { do_graphics_upload("hello"); }
100 void editpic(void)         { do_graphics_upload("_userpic_"); }
101 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
102
103 /* The users photo display / upload facility */
104 void display_editpic(void) {
105         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_userpic_")));
106         putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
107         putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
108         display_graphics_upload("editpic");
109 }
110 /* room picture dispay / upload facility */
111 void display_editroompic(void) {
112         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_roompic_")));
113         putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
114         putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
115         display_graphics_upload("editroompic");
116 }
117
118 /* the greetingpage hello pic */
119 void display_edithello(void) {
120         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
121         putbstr("__PICDESC", NewStrBufPlain(_("the Greetingpicture for the login prompt"), -1));
122         putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
123         display_graphics_upload("edithellopic");
124 }
125
126 /* the logoff banner */
127 void display_editgoodbyepic(void) {
128         putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbuye")));
129         putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
130         putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbuyepic")));
131         display_graphics_upload("editgoodbuyepic");
132 }
133
134 void display_editfloorpic(void) {
135         StrBuf *PicAction;
136
137         PicAction = NewStrBuf();
138         StrBufPrintf(PicAction, "_floorpic_|%s", bstr("which_floor"));
139         putbstr("__WHICHPIC", PicAction);
140         putbstr("__PICDESC", NewStrBufPlain(_("the icon for this floor"), -1));
141         putbstr("__UPLURL", NewStrBufPlain(HKEY("editfloorpic")));
142         display_graphics_upload("editfloorpic");
143 }
144
145 void editroompic(void) {
146         char buf[SIZ];
147         snprintf(buf, SIZ, "_roompic_|%s",
148                  bstr("which_room"));
149         do_graphics_upload(buf);
150 }
151
152 void editfloorpic(void){
153         char buf[SIZ];
154         snprintf(buf, SIZ, "_floorpic_|%s",
155                  bstr("which_floor"));
156         do_graphics_upload(buf);
157 }
158
159 void 
160 InitModule_GRAPHICS
161 (void)
162 {
163         WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
164         WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
165         WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
166         WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
167         WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
168         WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
169         WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
170         WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
171         WebcitAddUrlHandler(HKEY("display_editfloorpic"), "", 0, display_editfloorpic, 0);
172         WebcitAddUrlHandler(HKEY("editfloorpic"), "", 0, editfloorpic, 0);
173 }