]> code.citadel.org Git - citadel.git/blobdiff - webcit/downloads.c
* fix file upload
[citadel.git] / webcit / downloads.c
index ed78c74c6bdfc07a188b45bbcea8440230d5ac6f..65ea69bb4040423f7935464645f23a906a9a29c6 100644 (file)
@@ -25,32 +25,32 @@ void FreeFiles(void *vFile)
 }
 
 /* -------------------------------------------------------------------------------- */
-void tmplput_FILE_NAME(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILE_NAME(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, F->Filename, 0);
+       FileListStruct *F = (FileListStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, F->Filename, 0);
 }
-void tmplput_FILE_SIZE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILE_SIZE(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
+       FileListStruct *F = (FileListStruct*) CTX;
        StrBufAppendPrintf(Target, "%ld", F->FileSize);
 }
-void tmplput_FILEMIMETYPE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILEMIMETYPE(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, F->MimeType, 0);
+       FileListStruct *F = (FileListStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, F->MimeType, 0);
 }
-void tmplput_FILE_COMMENT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_FILE_COMMENT(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, F->Comment, 0);
+       FileListStruct *F = (FileListStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, F->Comment, 0);
 }
 
 /* -------------------------------------------------------------------------------- */
 
-int Conditional_FILE_ISPIC(WCTemplateToken *Tokens, void *Context, int ContextType)
+int Conditional_FILE_ISPIC(StrBuf *Target, WCTemplputParams *TP)
 {
-       FileListStruct *F = (FileListStruct*) Context;
+       FileListStruct *F = (FileListStruct*) CTX;
        return F->IsPic;
 }
 
@@ -163,7 +163,7 @@ int GroupchangeFilelistBySequence(const void *vFile1, const void *vFile2)
 }
 
 /* -------------------------------------------------------------------------------- */
-HashList* LoadFileList(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList* LoadFileList(StrBuf *Target, WCTemplputParams *TP)
 {
        FileListStruct *Entry;
        StrBuf *Buf;
@@ -173,7 +173,9 @@ HashList* LoadFileList(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
        char buf[1024];
        CompareFunc SortIt;
        int HavePic;
+       WCTemplputParams SubTP;
 
+       memset(&TP, 0, sizeof(WCTemplputParams));
        serv_puts("RDIR");
        serv_getln(buf, sizeof buf);
        if (buf[0] != '1') return NULL;
@@ -208,7 +210,8 @@ HashList* LoadFileList(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
                }
                Put(Files, SKEY(Entry->Filename), Entry, FreeFiles);
        }
-       SortIt = RetrieveSort(CTX_FILELIST, NULL, HKEY("fileunsorted"), 0);
+       SubTP.Filter.ContextType = CTX_FILELIST;
+       SortIt = RetrieveSort(&SubTP, NULL, 0, HKEY("fileunsorted"), 0);
        if (SortIt != NULL)
                SortByPayload(Files, SortIt);
        else 
@@ -275,6 +278,27 @@ void download_file(void)
 
 
 
+void delete_file(void)
+{
+       StrBuf *Buf;
+       char buf[256];
+       
+       safestrncpy(buf, bstr("file"), sizeof buf);
+       unescape_input(buf);
+       serv_printf("DELF %s", buf);
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       GetServerStatus(Buf, NULL);
+       StrBufCutLeft(Buf, 4);
+       strcpy(WC->ImportantMessage, ChrPtr(Buf));
+       do_template("files", CTX_NONE);
+       output_headers(0, 0, 0, 0, 0, 0);
+       end_burst();
+       FreeStrBuf(&Buf);
+}
+
+
+
 void upload_file(void)
 {
        const char *MimeType;
@@ -290,6 +314,8 @@ void upload_file(void)
        {
                strcpy(WCC->ImportantMessage, &buf[4]);
                do_template("files", NULL);
+               output_headers(0, 0, 0, 0, 0, 0);
+               end_burst();
                return;
        }
 
@@ -314,6 +340,8 @@ void upload_file(void)
        serv_getln(buf, sizeof buf);
        strcpy(WCC->ImportantMessage, &buf[4]);
        do_template("files", CTX_NONE);
+       output_headers(0, 0, 0, 0, 0, 0);
+       end_burst();
 }
 
 
@@ -411,5 +439,6 @@ InitModule_DOWNLOAD
        WebcitAddUrlHandler(HKEY("image"), output_image, 0);
        WebcitAddUrlHandler(HKEY("display_mime_icon"), display_mime_icon , 0);
        WebcitAddUrlHandler(HKEY("download_file"), download_file, NEED_URL);
+       WebcitAddUrlHandler(HKEY("delete_file"), delete_file, NEED_URL);
        WebcitAddUrlHandler(HKEY("upload_file"), upload_file, 0);
 }