X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fdownloads.c;h=6e6c9b981b5ebf0acf8bc46dc664fc9630956acd;hb=ed4e4918cc03352a056f097ea9e8d24918c49158;hp=a1d2984c459615e8e0ef53f453f92f9527cdc60e;hpb=a98b77122767a5ab63763b37715f2b8a5403de34;p=citadel.git diff --git a/webcit/downloads.c b/webcit/downloads.c index a1d2984c4..6e6c9b981 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -1,92 +1,477 @@ /* - * $Id: downloads.c 4849 2007-01-08 20:05:56Z ajc $ + * Copyright (c) 1996-2012 by the citadel.org team + * + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ + #include "webcit.h" +#include "webserver.h" + +CtxType CTX_FILELIST = CTX_NONE; + +extern void output_static(const char* What); + +extern char* static_dirs[]; + +typedef struct _FileListStruct { + StrBuf *Filename; + long FileSize; + StrBuf *MimeType; + StrBuf *Comment; + int IsPic; + int Sequence; +} FileListStruct; -void display_room_directory(void) +void FreeFiles(void *vFile) { + FileListStruct *F = (FileListStruct*) vFile; + FreeStrBuf(&F->Filename); + FreeStrBuf(&F->MimeType); + FreeStrBuf(&F->Comment); + free(F); +} + +/* -------------------------------------------------------------------------------- */ +void tmplput_FILE_NAME(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); + StrBufAppendTemplate(Target, TP, F->Filename, 0); +} +void tmplput_FILE_SIZE(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); + StrBufAppendPrintf(Target, "%ld", F->FileSize); +} +void tmplput_FILEMIMETYPE(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); + StrBufAppendTemplate(Target, TP, F->MimeType, 0); +} +void tmplput_FILE_COMMENT(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); + StrBufAppendTemplate(Target, TP, F->Comment, 0); +} + +/* -------------------------------------------------------------------------------- */ + +int Conditional_FILE_ISPIC(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX(CTX_FILELIST); + return F->IsPic; +} + +/* -------------------------------------------------------------------------------- */ +int CompareFilelistByMime(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + + if (File1->IsPic != File2->IsPic) + return File1->IsPic > File2->IsPic; + return strcasecmp(ChrPtr(File1->MimeType), ChrPtr(File2->MimeType)); +} +int CompareFilelistByMimeRev(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + if (File1->IsPic != File2->IsPic) + return File1->IsPic < File2->IsPic; + return strcasecmp(ChrPtr(File2->MimeType), ChrPtr(File1->MimeType)); +} +int GroupchangeFilelistByMime(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) vFile1; + FileListStruct *File2 = (FileListStruct*) vFile2; + + if (File1->IsPic != File2->IsPic) + return File1->IsPic > File2->IsPic; + return strcasecmp(ChrPtr(File1->MimeType), ChrPtr(File2->MimeType)) != 0; +} + + +int CompareFilelistByName(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + + if (File1->IsPic != File2->IsPic) + return File1->IsPic > File2->IsPic; + return strcasecmp(ChrPtr(File1->Filename), ChrPtr(File2->Filename)); +} +int CompareFilelistByNameRev(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + if (File1->IsPic != File2->IsPic) + return File1->IsPic < File2->IsPic; + return strcasecmp(ChrPtr(File2->Filename), ChrPtr(File1->Filename)); +} +int GroupchangeFilelistByName(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) vFile1; + FileListStruct *File2 = (FileListStruct*) vFile2; + + return ChrPtr(File1->Filename)[0] != ChrPtr(File2->Filename)[0]; +} + + +int CompareFilelistBySize(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + if (File1->FileSize == File2->FileSize) + return 0; + return (File1->FileSize > File2->FileSize); +} +int CompareFilelistBySizeRev(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + if (File1->FileSize == File2->FileSize) + return 0; + return (File1->FileSize < File2->FileSize); +} +int GroupchangeFilelistBySize(const void *vFile1, const void *vFile2) +{ + return 0; +} + + +int CompareFilelistByComment(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + return strcasecmp(ChrPtr(File1->Comment), ChrPtr(File2->Comment)); +} +int CompareFilelistByCommentRev(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + return strcasecmp(ChrPtr(File2->Comment), ChrPtr(File1->Comment)); +} +int GroupchangeFilelistByComment(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) vFile1; + FileListStruct *File2 = (FileListStruct*) vFile2; + return ChrPtr(File1->Comment)[9] != ChrPtr(File2->Comment)[0]; +} + + +int CompareFilelistBySequence(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + return (File2->Sequence > File1->Sequence); +} +int GroupchangeFilelistBySequence(const void *vFile1, const void *vFile2) +{ + return 0; +} + +/* -------------------------------------------------------------------------------- */ +HashList* LoadFileList(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *Entry; + StrBuf *Buf; + HashList *Files; + int Done = 0; + int sequence = 0; char buf[1024]; - char filename[256]; - char filesize[256]; - char comment[512]; - int bg = 0; - char title[256]; - - output_headers(1, 1, 2, 0, 0, 0); - wprintf("
\n