From e4391381466983458442b375d7292fb8162548e8 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Mon, 19 Aug 2013 22:57:59 +0200 Subject: [PATCH] Show upload form directly in directory listing --- include/templates.h | 14 -------------- src/dirlisting.c | 12 +++++++++++- src/main.c | 17 +---------------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/include/templates.h b/include/templates.h index 1971f15..0742c2c 100644 --- a/include/templates.h +++ b/include/templates.h @@ -89,18 +89,4 @@ " " \ FOOTER -#define UPLOAD_FORM \ - HEADER1 \ - " Upload" \ - HEADER2 \ - "

Upload

" \ - "

You can upload a file to the current directory here.

" \ - "

" \ - "

" \ - " " \ - " " \ - "
" \ - "

" \ - FOOTER - #endif // TEMPLATES_H diff --git a/src/dirlisting.c b/src/dirlisting.c index a5117a3..4624290 100644 --- a/src/dirlisting.c +++ b/src/dirlisting.c @@ -201,11 +201,21 @@ char* gen_html(const char *url, struct Entry *entries, size_t numentries, int up if(uploadEnabled) { strcat(result, "

Upload

"); - strcat(result, "

Upload a file to this directory

"); + strcat(result, "

Upload a file to this directory:

"); + strcat(result, + "

" + "

" + " " + " " + "
" + "

" + ); } strcat(result, FOOTER); + LOG(LVL_DEBUG, "result string (files) usage: %lu/%lu bytes", strlen(result), allocated); + return result; } diff --git a/src/main.c b/src/main.c index c8ab643..124170c 100644 --- a/src/main.c +++ b/src/main.c @@ -49,7 +49,6 @@ struct MHD_Response *error403Response; struct MHD_Response *error404Response; struct MHD_Response *error500Response; struct MHD_Response *faviconResponse; -struct MHD_Response *uploadFormResponse; #ifdef HAVE_MAGIC magic_t magicCookie; @@ -466,11 +465,7 @@ static int connection_handler(void * cls, if(S_ISREG(connstate->targetStat.st_mode)) { return serv_regular_file(connection, connstate); } else if(S_ISDIR(connstate->targetStat.st_mode)) { - if(uploadEnabled && connstate->uploadRequest) { - return MHD_queue_response(connection, MHD_HTTP_OK, uploadFormResponse); - } else { - return serv_directory(connection, connstate); - } + return serv_directory(connection, connstate); } else { LOG(LVL_WARN, "%s is neither a directory nor a regular file. Don't allow the access.", @@ -704,15 +699,6 @@ int main(int argc, char ** argv) { MHD_add_response_header(error404Response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html"); MHD_add_response_header(error500Response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html"); - // static response for upload form - uploadFormResponse = MHD_create_response_from_data( - strlen(UPLOAD_FORM), - (void*) UPLOAD_FORM, - MHD_NO, - MHD_NO); - - MHD_add_response_header(uploadFormResponse, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html"); - // static response for favicon faviconResponse = create_favicon_response(); @@ -763,7 +749,6 @@ int main(int argc, char ** argv) { MHD_destroy_response(error404Response); MHD_destroy_response(error500Response); MHD_destroy_response(faviconResponse); - MHD_destroy_response(uploadFormResponse); #ifdef HAVE_MAGIC magic_close(magicCookie);