]> code.citadel.org Git - citadel.git/blobdiff - webcit/downloads.c
* if we need the first urlpart, we musn't move it just left, but add another one...
[citadel.git] / webcit / downloads.c
index 4d17aa358d9d76c82cbb79c498e8c11ac7133893..d980ce1d330b674e33d08f4365a9311e6bf21fe0 100644 (file)
@@ -19,8 +19,8 @@ typedef struct _FileListStruct {
 
 int CompareFilelistByMime(const void *vFile1, const void *vFile2)
 {
-       FileListStruct *File1 = (FileListStruct*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) vFile2;
+       FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1);
+       FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2);
 
        if (File1->IsPic != File2->IsPic)
                return File1->IsPic > File2->IsPic;
@@ -28,8 +28,8 @@ int CompareFilelistByMime(const void *vFile1, const void *vFile2)
 }
 int CompareFilelistByMimeRev(const void *vFile1, const void *vFile2)
 {
-       FileListStruct *File1 = (FileListStruct*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) 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);
@@ -37,8 +37,8 @@ int CompareFilelistByMimeRev(const void *vFile1, const void *vFile2)
 
 int CompareFilelistBySize(const void *vFile1, const void *vFile2)
 {
-       FileListStruct *File1 = (FileListStruct*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) vFile2;
+       FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1);
+       FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2);
        if (File1->FileSize == File2->FileSize)
                return 0;
        return (File1->FileSize > File2->FileSize);
@@ -46,8 +46,8 @@ int CompareFilelistBySize(const void *vFile1, const void *vFile2)
 
 int CompareFilelistBySizeRev(const void *vFile1, const void *vFile2)
 {
-       FileListStruct *File1 = (FileListStruct*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) vFile2;
+       FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1);
+       FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2);
        if (File1->FileSize == File2->FileSize)
                return 0;
        return (File1->FileSize < File2->FileSize);
@@ -55,21 +55,21 @@ int CompareFilelistBySizeRev(const void *vFile1, const void *vFile2)
 
 int CompareFilelistByComment(const void *vFile1, const void *vFile2)
 {
-       FileListStruct *File1 = (FileListStruct*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) 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*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) 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*) vFile1;
-       FileListStruct *File2 = (FileListStruct*) vFile2;
+       FileListStruct *File1 = (FileListStruct*) GetSearchPayload(vFile1);
+       FileListStruct *File2 = (FileListStruct*) GetSearchPayload(vFile2);
        return (File2->Sequence >  File1->Sequence);
 }
 
@@ -225,9 +225,8 @@ void display_room_directory(void)
                "<table class=\"downloads_background\"><tr><td>\n");
 
 
-       if (havebstr("SortOrder"))
-               Order = ibstr("SortOrder");
-       else
+       Order = ibstr("SortOrder");
+       if (!havebstr("SortOrder") || Order > 2)
                Order = 2; /* <- Unsorted... */
        SortRow = ibstr("SortBy");
 
@@ -238,7 +237,7 @@ void display_room_directory(void)
                switch (SortDirections[i]) {
                default:
                case 0:
-                       Order = 1;
+                       Order = 2;
                        break;
                case 1:
                        Order = 0;
@@ -253,7 +252,7 @@ void display_room_directory(void)
                        "       <img src=\"%s\" border=\"0\"></a>\n"
                        "  </th>\n",
                        RowNames[i],
-                       i, Order, 
+                       Order, i,
                        SortIcons[SortDirections[i]]
                        );
 
@@ -280,7 +279,7 @@ void display_room_directory(void)
                        "name=\"upload_file_form\""
                        ">\n"
                );
-               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
 
                wprintf(_("Upload a file:"));
                wprintf("&nbsp;<input NAME=\"filename\" SIZE=16 TYPE=\"file\">&nbsp;\n");
@@ -382,7 +381,7 @@ void display_mime_icon(void)
 
 }
 
-void download_file(char *filename)
+void download_file(void)
 {
        char buf[256];
        off_t bytes;
@@ -392,7 +391,7 @@ void download_file(char *filename)
        /* Setting to nonzero forces a MIME type of application/octet-stream */
        int force_download = 1;
        
-       safestrncpy(buf, filename, sizeof buf);
+       safestrncpy(buf, ChrPtr(WC->UrlFragment2), sizeof buf);
        unescape_input(buf);
        serv_printf("OPEN %s", buf);
        serv_getln(buf, sizeof buf);
@@ -406,17 +405,17 @@ void download_file(char *filename)
                        extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
                }
                output_headers(0, 0, 0, 0, 0, 0);
-               read_server_binary(content, bytes);
+               read_server_binary(WC->WBuf, bytes);
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
-               http_transmit_thing(content, bytes, content_type, 0);
+               http_transmit_thing(content_type, 0);
                free(content);
        } else {
-               wprintf("HTTP/1.1 404 %s\n", &buf[4]);
+               hprintf("HTTP/1.1 404 %s\n", &buf[4]);
                output_headers(0, 0, 0, 0, 0, 0);
-               wprintf("Content-Type: text/plain\r\n");
-               wprintf("\r\n");
+               hprintf("Content-Type: text/plain\r\n");
                wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]);
+               end_burst();
        }
 
 }
@@ -463,3 +462,13 @@ void upload_file(void)
        strcpy(WCC->ImportantMessage, &buf[4]);
        display_room_directory();
 }
+
+void 
+InitModule_DOWNLOAD
+(void)
+{
+       WebcitAddUrlHandler(HKEY("display_room_directory"), display_room_directory, 0);
+       WebcitAddUrlHandler(HKEY("display_pictureview"), display_pictureview, 0);
+       WebcitAddUrlHandler(HKEY("download_file"), download_file, NEED_URL);
+       WebcitAddUrlHandler(HKEY("upload_file"), upload_file, 0);
+}