Back to index

webcit  8.12-dfsg
graphics.c
Go to the documentation of this file.
00001 /*
00002  * Handles HTTP upload of graphics files into the system.
00003  *
00004  * Copyright (c) 1996-2012 by the citadel.org team
00005  *
00006  * This program is open source software.  You can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 
00017 extern void output_static(const char* What);
00018 
00019 void display_graphics_upload(char *filename)
00020 {
00021        StrBuf *Line;
00022 
00023        Line = NewStrBuf();
00024        serv_printf("UIMG 0||%s", filename);
00025        StrBuf_ServGetln(Line);
00026        if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
00027               display_main_menu();
00028               return;
00029        }
00030        else
00031        {
00032               output_headers(1, 0, 0, 0, 1, 0);
00033               do_template("files_graphicsupload");
00034               end_burst();
00035        }
00036        FreeStrBuf(&Line);
00037 }
00038 
00039 void do_graphics_upload(char *filename)
00040 {
00041        StrBuf *Line;
00042        const char *MimeType;
00043        wcsession *WCC = WC;
00044        int bytes_remaining;
00045        int pos = 0;
00046        int thisblock;
00047        bytes_remaining = WCC->upload_length;
00048 
00049        if (havebstr("cancel_button")) {
00050               AppendImportantMessage(_("Graphics upload has been cancelled."), -1);
00051               display_main_menu();
00052               return;
00053        }
00054 
00055        if (WCC->upload_length == 0) {
00056               AppendImportantMessage(_("You didn't upload a file."), -1);
00057               display_main_menu();
00058               return;
00059        }
00060        
00061        MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
00062        serv_printf("UIMG 1|%s|%s", MimeType, filename);
00063 
00064        Line = NewStrBuf();
00065        StrBuf_ServGetln(Line);
00066        if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
00067               display_main_menu();
00068               FreeStrBuf(&Line);
00069               return;
00070        }
00071        while (bytes_remaining) {
00072               thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
00073               serv_printf("WRIT %d", thisblock);
00074               StrBuf_ServGetln(Line);
00075               if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) {
00076                      serv_puts("UCLS 0");
00077                      StrBuf_ServGetln(Line);
00078                      display_main_menu();
00079                      FreeStrBuf(&Line);
00080                      return;
00081               }
00082               thisblock = extract_int(ChrPtr(Line) +4, 0);
00083               serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
00084               pos += thisblock;
00085               bytes_remaining -= thisblock;
00086        }
00087 
00088        serv_puts("UCLS 1");
00089        StrBuf_ServGetln(Line);
00090        if (*ChrPtr(Line) != 'x') {
00091               display_success(ChrPtr(Line) + 4);
00092        
00093        }
00094        FreeStrBuf(&Line);
00095 
00096 }
00097 
00098 
00099 void edithellopic(void)    { do_graphics_upload("hello"); }
00100 void editpic(void)         { do_graphics_upload("_userpic_"); }
00101 void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); }
00102 
00103 /* The users photo display / upload facility */
00104 void display_editpic(void) {
00105        putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_userpic_")));
00106        putbstr("__PICDESC", NewStrBufPlain(_("your photo"), -1));
00107        putbstr("__UPLURL", NewStrBufPlain(HKEY("editpic")));
00108        display_graphics_upload("editpic");
00109 }
00110 /* room picture dispay / upload facility */
00111 void display_editroompic(void) {
00112        putbstr("__WHICHPIC", NewStrBufPlain(HKEY("_roompic_")));
00113        putbstr("__PICDESC", NewStrBufPlain(_("the icon for this room"), -1));
00114        putbstr("__UPLURL", NewStrBufPlain(HKEY("editroompic")));
00115        display_graphics_upload("editroompic");
00116 }
00117 
00118 /* the greetingpage hello pic */
00119 void display_edithello(void) {
00120        putbstr("__WHICHPIC", NewStrBufPlain(HKEY("hello")));
00121        putbstr("__PICDESC", NewStrBufPlain(_("the Greetingpicture for the login prompt"), -1));
00122        putbstr("__UPLURL", NewStrBufPlain(HKEY("edithellopic")));
00123        display_graphics_upload("edithellopic");
00124 }
00125 
00126 /* the logoff banner */
00127 void display_editgoodbyepic(void) {
00128        putbstr("__WHICHPIC", NewStrBufPlain(HKEY("UIMG 0|%s|goodbuye")));
00129        putbstr("__PICDESC", NewStrBufPlain(_("the Logoff banner picture"), -1));
00130        putbstr("__UPLURL", NewStrBufPlain(HKEY("editgoodbuyepic")));
00131        display_graphics_upload("editgoodbuyepic");
00132 }
00133 
00134 void display_editfloorpic(void) {
00135        StrBuf *PicAction;
00136 
00137        PicAction = NewStrBuf();
00138        StrBufPrintf(PicAction, "_floorpic_|%s", bstr("which_floor"));
00139        putbstr("__WHICHPIC", PicAction);
00140        putbstr("__PICDESC", NewStrBufPlain(_("the icon for this floor"), -1));
00141        putbstr("__UPLURL", NewStrBufPlain(HKEY("editfloorpic")));
00142        display_graphics_upload("editfloorpic");
00143 }
00144 
00145 void editroompic(void) {
00146        char buf[SIZ];
00147        snprintf(buf, SIZ, "_roompic_|%s",
00148                bstr("which_room"));
00149        do_graphics_upload(buf);
00150 }
00151 
00152 void editfloorpic(void){
00153        char buf[SIZ];
00154        snprintf(buf, SIZ, "_floorpic_|%s",
00155                bstr("which_floor"));
00156        do_graphics_upload(buf);
00157 }
00158 
00159 void 
00160 InitModule_GRAPHICS
00161 (void)
00162 {
00163        WebcitAddUrlHandler(HKEY("display_editpic"), "", 0, display_editpic, 0);
00164        WebcitAddUrlHandler(HKEY("editpic"), "", 0, editpic, 0);
00165        WebcitAddUrlHandler(HKEY("display_editroompic"), "", 0, display_editroompic, 0);
00166        WebcitAddUrlHandler(HKEY("editroompic"), "", 0, editroompic, 0);
00167        WebcitAddUrlHandler(HKEY("display_edithello"), "", 0, display_edithello, 0);
00168        WebcitAddUrlHandler(HKEY("edithellopic"), "", 0, edithellopic, 0);
00169        WebcitAddUrlHandler(HKEY("display_editgoodbuye"), "", 0, display_editgoodbyepic, 0);
00170        WebcitAddUrlHandler(HKEY("editgoodbuyepic"), "", 0, editgoodbuyepic, 0);
00171        WebcitAddUrlHandler(HKEY("display_editfloorpic"), "", 0, display_editfloorpic, 0);
00172        WebcitAddUrlHandler(HKEY("editfloorpic"), "", 0, editfloorpic, 0);
00173 }