aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--index.c5
-rw-r--r--index.htm.tmpl10
-rw-r--r--main.c41
-rw-r--r--search.cfg.example2
5 files changed, 37 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index 06d845c..80e029e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
search
+search.cfg
diff --git a/index.c b/index.c
index 3840549..6d00ee5 100644
--- a/index.c
+++ b/index.c
@@ -301,7 +301,7 @@ index_lookup_substr_caseinsensitive(map_t *index, const char *query,
if (strcasestr(node->data->name, query))
results_insert(results, node->data);
if (node->child)
- index_lookup_substr(node->child, query, results);
+ index_lookup_substr_caseinsensitive(node->child, query, results);
}
}
}
@@ -317,7 +317,7 @@ index_lookup_exact(map_t *index, const char *query, results_t *results)
if (strcmp(node->data->name, query) == 0)
results_insert(results, node->data);
if (node->child)
- index_lookup_substr(node->child, query, results);
+ index_lookup_exact(node->child, query, results);
}
}
}
@@ -347,7 +347,6 @@ index_lookup(map_t *index, lookup_type_t type, const char *query)
case LOOKUP_REGEX:
index_lookup_regex(index, query, results);
break;
-
}
return results;
diff --git a/index.htm.tmpl b/index.htm.tmpl
index 84d1de9..37728de 100644
--- a/index.htm.tmpl
+++ b/index.htm.tmpl
@@ -113,7 +113,7 @@
<main>
<h2 class="center">Search</h2>
<p>Search all of the ARFNET content fast</p>
- <form class="searchform" action="/query" method="get">
+ <form class="searchform" action="/search/query" method="get">
<div class="box form-inline">
<input class="input" type="text" name="q" value="%s">
<button type="submit">Search</button><br>
@@ -123,13 +123,13 @@
<summary class="collapse-title">Advanced</summary>
<p>
<label class="label">Search type</label>
- <input type="radio" id="substr" name="t" value="s" checked="checked">
+ <input type="radio" id="substr" name="t" value="s" %s>
<label for="substr">substring</label>
- <input type="radio" id="substr_nocase" name="t" value="i">
+ <input type="radio" id="substr_nocase" name="t" value="i" %s>
<label for="substr_nocase">case insensitive substring</label>
- <input type="radio" id="exact" name="t" value="e">
+ <input type="radio" id="exact" name="t" value="e" %s>
<label for="exact">exact</label>
- <input type="radio" id="regex" name="t" value="r">
+ <input type="radio" id="regex" name="t" value="r" %s>
<label for="regex">regex</label>
</p>
<p>
diff --git a/main.c b/main.c
index 820d169..f981252 100644
--- a/main.c
+++ b/main.c
@@ -123,6 +123,8 @@ generate_results_html(results_t *results)
char *buff = malloc(1024 * results->size); /* alloc 1K per result */
char *pos = buff;
+
+ *pos = '\0';
for (int i = 0; i < results->size; i++) {
const node_data_t *data = results->results[i];
@@ -159,8 +161,6 @@ enum MHD_Result answer_to_connection(
size_t *upload_data_size,
void **ptr
) {
- char buff[BUFF_SIZE];
-
const struct sockaddr_in **coninfo =
(const struct sockaddr_in**)MHD_get_connection_info(
connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS);
@@ -177,11 +177,12 @@ enum MHD_Result answer_to_connection(
int ret;
if (strcmp(method, "GET") == 0 && strcmp(url, subdir_endpoint("/")) == 0) {
- snprintf(buff, BUFF_SIZE, index_format_template, "", "", "", "", "", "",
- "");
+ char resp_buff[4096];
+ snprintf(resp_buff, 16384, index_format_template, "",
+ "checked=\"checked\"", "", "", "", "", "", "", "", "", "");
- response = MHD_create_response_from_buffer(strlen(buff), (void*)buff,
- MHD_RESPMEM_PERSISTENT);
+ response = MHD_create_response_from_buffer(strlen(resp_buff),
+ (void*)resp_buff, MHD_RESPMEM_PERSISTENT);
MHD_add_response_header(response, "Content-Type", "text/html");
@@ -293,10 +294,19 @@ enum MHD_Result answer_to_connection(
float lookup_time = (finish.tv_sec + (0.000000001 * finish.tv_nsec)) -
(start.tv_sec + (0.000000001 * start.tv_nsec));
- char *results_html = NULL;
+ char *results_html = NULL, *resp_buff = NULL;
+ size_t resp_buff_size = 0;
if (query && results) {
results_html = generate_results_html(results);
- snprintf(buff, BUFF_SIZE, index_format_template, query,
+ resp_buff_size = strlen(results_html) + 16384;
+ resp_buff = malloc(resp_buff_size);
+ resp_buff_size = snprintf(resp_buff, resp_buff_size,
+ index_format_template,
+ query,
+ query_type == LOOKUP_SUBSTR ? "checked=\"checked\"" : "",
+ query_type == LOOKUP_SUBSTR_CASEINSENSITIVE ? "checked=\"checked\"" : "",
+ query_type == LOOKUP_EXACT ? "checked=\"checked\"" : "",
+ query_type == LOOKUP_REGEX ? "checked=\"checked\"" : "",
filter_time_low ? filter_time_low : "",
filter_time_high ? filter_time_high : "",
filter_size_low ? filter_size_low : "",
@@ -305,13 +315,17 @@ enum MHD_Result answer_to_connection(
sort_order, results->size, lookup_time),
results_html);
}
- else
- snprintf(buff, BUFF_SIZE, index_format_template, "", "",
- "", "", "", "", "indexing in progress... try again later");
+ else {
+ resp_buff_size = 16384;
+ resp_buff = malloc(resp_buff_size);
+ resp_buff_size = snprintf(resp_buff, 16384, index_format_template,
+ "checked=\"checked\"", "", "", "", "", "", "", "", "", "",
+ "indexing in progress... try again later");
+ }
/* send it */
- response = MHD_create_response_from_buffer(strlen(buff), (void*)buff,
- MHD_RESPMEM_PERSISTENT);
+ response = MHD_create_response_from_buffer(resp_buff_size,
+ (void*)resp_buff, MHD_RESPMEM_PERSISTENT);
MHD_add_response_header(response, "Content-Type", "text/html");
@@ -323,6 +337,7 @@ enum MHD_Result answer_to_connection(
ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response(response);
free(results_html);
+ free(resp_buff);
}
else {
response = MHD_create_response_from_buffer(0, (void*)NULL, 0);
diff --git a/search.cfg.example b/search.cfg.example
index d21b334..71997ca 100644
--- a/search.cfg.example
+++ b/search.cfg.example
@@ -7,7 +7,7 @@ port=8888
template=index.htm.tmpl
# app subdirectory for http server
-app_subdir=/search/
+app_subdir=/search
# root
root=/home/arf20/projects