diff options
| author | arf20 <aruizfernandez05@gmail.com> | 2025-12-08 02:43:09 +0100 |
|---|---|---|
| committer | arf20 <aruizfernandez05@gmail.com> | 2025-12-08 02:43:09 +0100 |
| commit | 6e467288fd41b72f867e7551daf3ee0e4b0a3173 (patch) | |
| tree | e52fa97ad2163304d76eadb02156019e47ddea73 | |
| parent | 0cd93eca491d9d5d402802bbf6d2fe6c529317ad (diff) | |
| download | arfnet2-search-6e467288fd41b72f867e7551daf3ee0e4b0a3173.tar.gz arfnet2-search-6e467288fd41b72f867e7551daf3ee0e4b0a3173.zip | |
app subdir
| -rw-r--r-- | config.c | 23 | ||||
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | main.c | 15 | ||||
| -rw-r--r-- | search.cfg | 20 | ||||
| -rw-r--r-- | search.cfg.example | 14 |
5 files changed, 44 insertions, 30 deletions
@@ -28,7 +28,8 @@ #include <errno.h> unsigned short port = 0; -char *tmpl_path = NULL, *root = NULL, *subdir = NULL; +char *tmpl_path = NULL, *root = NULL, *app_subdir = NULL, + *result_subdir = NULL; int magic_enable = 0, period = 86400; int @@ -75,10 +76,15 @@ config_load(const char *conf_path) root = strdup(value); printf("\troot: %s\n", root); } - else if (strcmp(line, "subdir") == 0) { + else if (strcmp(line, "app_subdir") == 0) { value[strlen(value) - 1] = '\0'; - subdir = strdup(value); - printf("\tsubdir: %s\n", subdir); + app_subdir = strdup(value); + printf("\tapp_subdir: %s\n", app_subdir); + } + else if (strcmp(line, "result_subdir") == 0) { + value[strlen(value) - 1] = '\0'; + result_subdir = strdup(value); + printf("\tresult_subdir: %s\n", result_subdir); } else if (strcmp(line, "magic") == 0) { value[strlen(value) - 1] = '\0'; @@ -113,8 +119,13 @@ config_load(const char *conf_path) return -1; } - if (!subdir) { - fprintf(stderr, "[config] E: no link subdirectory given\n"); + if (!app_subdir) { + fprintf(stderr, "[config] E: no application subdirectory given\n"); + return -1; + } + + if (!result_subdir) { + fprintf(stderr, "[config] E: no result link subdirectory given\n"); return -1; } @@ -31,7 +31,7 @@ /* config */ extern unsigned short port; -extern char *tmpl_path, *root, *subdir; +extern char *tmpl_path, *root, *app_subdir, *result_subdir; extern int magic_enable, period; @@ -129,7 +129,7 @@ generate_results_html(results_t *results) struct tm *tm_mtim = gmtime(&data->stat.st_mtime); strftime(timebuf, 256, "%b %d %Y", tm_mtim); - snprintf(urlbuf, 4096, "%s%s", subdir, data->path); + snprintf(urlbuf, 4096, "%s%s", result_subdir, data->path); pos += snprintf(pos, 1024, result_html_template, @@ -143,6 +143,13 @@ generate_results_html(results_t *results) return buff; } +const char * +subdir_endpoint(const char *endpoint) { + static char subdir_endpoint[256]; + snprintf(subdir_endpoint, 256, "%s%s", app_subdir, endpoint); + return subdir_endpoint; +} + enum MHD_Result answer_to_connection( void *cls, struct MHD_Connection *connection, const char *url, @@ -169,7 +176,7 @@ enum MHD_Result answer_to_connection( struct MHD_Response *response; int ret; - if (strcmp(method, "GET") == 0 && strcmp(url, "/") == 0) { + if (strcmp(method, "GET") == 0 && strcmp(url, subdir_endpoint("/")) == 0) { snprintf(buff, BUFF_SIZE, index_format_template, "", "", "", "", "", "", ""); @@ -180,7 +187,9 @@ enum MHD_Result answer_to_connection( ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); } - else if (strcmp(method, "GET") == 0 && strcmp(url, "/query") == 0) { + else if (strcmp(method, "GET") == 0 && strcmp(url, + subdir_endpoint("/query")) == 0) + { /* get query */ const char *query = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "q"); diff --git a/search.cfg b/search.cfg deleted file mode 100644 index 83aa8f1..0000000 --- a/search.cfg +++ /dev/null @@ -1,20 +0,0 @@ -# search config - -# listen port -port=8888 - -# html template path -template=index.htm.tmpl - -# root -root=/home/arf20/projects - -# read magic numbers (mime type) -magic=false - -# indexing period (seconds) -period=86400 - -# http subdirectory for file links -subdir=/files/ - diff --git a/search.cfg.example b/search.cfg.example index bb7e8ef..d21b334 100644 --- a/search.cfg.example +++ b/search.cfg.example @@ -6,4 +6,18 @@ port=8888 # html template path template=index.htm.tmpl +# app subdirectory for http server +app_subdir=/search/ + +# root +root=/home/arf20/projects + +# read magic numbers (mime type) +magic=false + +# indexing period (seconds) +period=86400 + +# http subdirectory for file links +result_subdir=/files/ |
