X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fdownloads.c;h=8ec1137380154abe0b9ac4074137b8d12b29de22;hb=8c321fbcc2a64f0d0627562fdf5651442e525ab1;hp=a208e51b7dc317fb4248c7dbe94bcab4ca32344e;hpb=9f145319b92b196662aa51cb2e3d7c392629965e;p=citadel.git diff --git a/webcit/downloads.c b/webcit/downloads.c index a208e51b7..8ec113738 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -4,17 +4,213 @@ #include "webcit.h" #include "webserver.h" -void display_room_directory(void) +typedef struct _FileListStruct { + char Filename[256]; + int FilenameLen; + long FileSize; + char MimeType[64]; + int MimeTypeLen; + char Comment[512]; + int CommentLen; + int IsPic; + int Sequence; +}FileListStruct; + + +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(File1->MimeType, 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(File2->MimeType, File1->MimeType); +} + +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 CompareFilelistByComment(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + return strcasecmp(File1->Comment, 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); +} + +int CompareFilelistBySequence(const void *vFile1, const void *vFile2) +{ + FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1); + FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2); + return (File2->Sequence > File1->Sequence); +} + +HashList* LoadFileList(int *HavePic) +{ + FileListStruct *Entry; + HashList *Files; + int HavePics = 0; + int Order; + int sequence = 0; char buf[1024]; - char filename[256]; - char filesize[256]; - char mimetype[64]; - char comment[512]; - int bg = 0; + + 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; +} + +void FilePrintEntry(const char *FileName, void *vFile, int odd) +{ + FileListStruct *File = (FileListStruct*) vFile; + + wprintf("