X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fdownloads.c;h=60783c5685cad880b94c1f877dc821c473891218;hb=fb6f6fa4ec4e3277e30d84326d48e6850822d318;hp=d980ce1d330b674e33d08f4365a9311e6bf21fe0;hpb=749c2a7e25006217b60af84c3854760454f1f013;p=citadel.git diff --git a/webcit/downloads.c b/webcit/downloads.c index d980ce1d3..60783c568 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -1,22 +1,71 @@ /* - * $Id$ + * 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" +extern void output_static(const char* What); + +extern char* static_dirs[]; + typedef struct _FileListStruct { - char Filename[256]; - int FilenameLen; + StrBuf *Filename; long FileSize; - char MimeType[64]; - int MimeTypeLen; - char Comment[512]; - int CommentLen; + StrBuf *MimeType; + StrBuf *Comment; int IsPic; int Sequence; -}FileListStruct; +} FileListStruct; + +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; + StrBufAppendTemplate(Target, TP, F->Filename, 0); +} +void tmplput_FILE_SIZE(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX; + StrBufAppendPrintf(Target, "%ld", F->FileSize); +} +void tmplput_FILEMIMETYPE(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX; + StrBufAppendTemplate(Target, TP, F->MimeType, 0); +} +void tmplput_FILE_COMMENT(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX; + StrBufAppendTemplate(Target, TP, F->Comment, 0); +} + +/* -------------------------------------------------------------------------------- */ + +int Conditional_FILE_ISPIC(StrBuf *Target, WCTemplputParams *TP) +{ + FileListStruct *F = (FileListStruct*) CTX; + return F->IsPic; +} +/* -------------------------------------------------------------------------------- */ int CompareFilelistByMime(const void *vFile1, const void *vFile2) { FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); @@ -24,7 +73,7 @@ int CompareFilelistByMime(const void *vFile1, const void *vFile2) if (File1->IsPic != File2->IsPic) return File1->IsPic > File2->IsPic; - return strcasecmp(File1->MimeType, File2->MimeType); + return strcasecmp(ChrPtr(File1->MimeType), ChrPtr(File2->MimeType)); } int CompareFilelistByMimeRev(const void *vFile1, const void *vFile2) { @@ -32,9 +81,45 @@ int CompareFilelistByMimeRev(const void *vFile1, const void *vFile2) FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); if (File1->IsPic != File2->IsPic) return File1->IsPic < File2->IsPic; - return strcasecmp(File2->MimeType, File1->MimeType); + 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); @@ -43,7 +128,6 @@ int CompareFilelistBySize(const void *vFile1, const void *vFile2) return 0; return (File1->FileSize > File2->FileSize); } - int CompareFilelistBySizeRev(const void *vFile1, const void *vFile2) { FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); @@ -52,19 +136,31 @@ int CompareFilelistBySizeRev(const void *vFile1, const void *vFile2) 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(File1->Comment, File2->Comment); + 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(File2->Comment, File1->Comment); + 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) { @@ -72,297 +168,71 @@ int CompareFilelistBySequence(const void *vFile1, const void *vFile2) FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); return (File2->Sequence > File1->Sequence); } +int GroupchangeFilelistBySequence(const void *vFile1, const void *vFile2) +{ + return 0; +} -HashList* LoadFileList(int *HavePic) +/* -------------------------------------------------------------------------------- */ +HashList* LoadFileList(StrBuf *Target, WCTemplputParams *TP) { FileListStruct *Entry; + StrBuf *Buf; HashList *Files; - int HavePics = 0; - int Order; + int Done = 0; int sequence = 0; char buf[1024]; + CompareFunc SortIt; + int HavePic = 0; + WCTemplputParams SubTP; + memset(&SubTP, 0, sizeof(WCTemplputParams)); serv_puts("RDIR"); serv_getln(buf, sizeof buf); - if (buf[0] == '1') { - Files = NewHash(1, NULL); - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) - { - Entry = (FileListStruct*) malloc(sizeof (FileListStruct)); - - Entry->FilenameLen = extract_token( - Entry->Filename, buf, 0, '|', - sizeof(Entry->Filename)); - Entry->FileSize = extract_long(buf, 1); - Entry->MimeTypeLen = extract_token( - Entry->MimeType, buf, 2, '|', - sizeof(Entry->MimeType)); - Entry->CommentLen = extract_token( - Entry->Comment, buf, 3, '|', - sizeof(Entry->Comment)); - - Entry->Sequence = sequence++; - Entry->IsPic = (strstr(Entry->MimeType, "image") != NULL); - if (!HavePics && Entry->IsPic) { - HavePics = 1; - *HavePic = 1; - } - Put(Files, Entry->Filename, - Entry->FilenameLen, - Entry, NULL); - } - Order = ibstr("SortOrder"); - switch (ibstr("SortBy")){ - case 1: /*NAME*/ - SortByHashKey(Files,Order); - break; - case 2: /* SIZE*/ - SortByPayload(Files, (Order)? - CompareFilelistBySize: - CompareFilelistBySizeRev); - break; - case 3: /*MIME*/ - SortByPayload(Files, (Order)? - CompareFilelistByMime: - CompareFilelistByMimeRev); - break; - case 4: /*COMM*/ - SortByPayload(Files, (Order)? - CompareFilelistByComment: - CompareFilelistByCommentRev); - break; - default: - SortByPayload(Files, CompareFilelistBySequence); - } - return Files; - } - else - return NULL; -} + if (buf[0] != '1') return NULL; -void FilePrintEntry(const char *FileName, void *vFile, int odd) -{ - FileListStruct *File = (FileListStruct*) vFile; - - wprintf("