aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarf20 <aruizfernandez05@gmail.com>2025-12-08 00:31:59 +0100
committerarf20 <aruizfernandez05@gmail.com>2025-12-08 00:31:59 +0100
commitc2977c08c4778d0dff74ca92441bc33789687947 (patch)
treed40430de2b8fa9a92c230fe98ddafcd8bd6eee59
parent0159795be5aa8423e8d223d057912e2d152efb4f (diff)
downloadarfnet2-search-c2977c08c4778d0dff74ca92441bc33789687947.tar.gz
arfnet2-search-c2977c08c4778d0dff74ca92441bc33789687947.zip
periodic reindexing
-rw-r--r--config.c28
-rw-r--r--config.h1
-rw-r--r--main.c31
-rw-r--r--search.cfg6
4 files changed, 48 insertions, 18 deletions
diff --git a/config.c b/config.c
index 8d05eab..fdb6380 100644
--- a/config.c
+++ b/config.c
@@ -29,6 +29,7 @@
unsigned short port = 0;
char *tmpl_path = NULL, *root = NULL, *subdir = NULL;
+int magic_enable = 0, period = 86400;
int
config_load(const char *conf_path)
@@ -63,19 +64,33 @@ config_load(const char *conf_path)
fprintf(stderr, "[config] invalid port: %s\n", line);
return -1;
}
- } else if (strcmp(line, "template") == 0) {
+ }
+ else if (strcmp(line, "template") == 0) {
value[strlen(value) - 1] = '\0';
tmpl_path = strdup(value);
printf("\ttemplate: %s\n", tmpl_path);
- } else if (strcmp(line, "root") == 0) {
+ }
+ else if (strcmp(line, "root") == 0) {
value[strlen(value) - 1] = '\0';
root = strdup(value);
printf("\troot: %s\n", root);
- } else if (strcmp(line, "subdir") == 0) {
+ }
+ else if (strcmp(line, "subdir") == 0) {
value[strlen(value) - 1] = '\0';
subdir = strdup(value);
printf("\tsubdir: %s\n", subdir);
- } else {
+ }
+ else if (strcmp(line, "magic") == 0) {
+ value[strlen(value) - 1] = '\0';
+ magic_enable = (strcmp(value, "true") == 0);
+ printf("\tmagic: %d\n", magic_enable);
+ }
+ else if (strcmp(line, "period") == 0) {
+ value[strlen(value) - 1] = '\0';
+ period = atoi(value);
+ printf("\tperiod: %d\n", period);
+ }
+ else {
fprintf(stderr, "[config] unknown key: %s\n", line);
continue;
}
@@ -98,6 +113,11 @@ config_load(const char *conf_path)
return -1;
}
+ if (!subdir) {
+ fprintf(stderr, "[config] E: no link subdirectory given\n");
+ return -1;
+ }
+
return 0;
}
diff --git a/config.h b/config.h
index aeb74d5..f9364b8 100644
--- a/config.h
+++ b/config.h
@@ -32,6 +32,7 @@
/* config */
extern unsigned short port;
extern char *tmpl_path, *root, *subdir;
+extern int magic_enable, period;
int config_load(const char *conf_path);
diff --git a/main.c b/main.c
index 4716c97..d4e0a14 100644
--- a/main.c
+++ b/main.c
@@ -347,27 +347,30 @@ int main() {
return 1;
}
- /* begin indexing */
if (index_init() < 0)
return 1;
- time_t time_now = time(NULL);
- struct tm *tm_now = gmtime(&time_now);
- static char timestr[256];
- strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now);
+ /* index loop */
+ do {
+ time_t time_now = time(NULL);
+ struct tm *tm_now = gmtime(&time_now);
+ static char timestr[256];
+ strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now);
- printf("[%s] [index] indexeding started...\n", timestr);
+ printf("[%s] [index] indexeding started...\n", timestr);
- g_index = index_new(INIT_MAP_CAPACITY, root, 1);
+ if (g_index)
+ index_destroy(g_index);
- time_now = time(NULL);
- tm_now = gmtime(&time_now);
- strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now);
+ g_index = index_new(INIT_MAP_CAPACITY, root, magic_enable);
- printf("[%s] [index] indexed finished\n", timestr);
+ time_now = time(NULL);
+ tm_now = gmtime(&time_now);
+ strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now);
- while (1) {
- sleep(1000);
- }
+ printf("[%s] [index] indexed finished\n", timestr);
+
+ sleep(period);
+ } while (1);
}
diff --git a/search.cfg b/search.cfg
index b0eaed8..9d0baba 100644
--- a/search.cfg
+++ b/search.cfg
@@ -9,6 +9,12 @@ template=index.htm.tmpl
# root
root=/home/arf20/projects/arfminesweeper
+# read magic numbers (mime type)
+magic=false
+
+# indexing period (seconds)
+period=86400
+
# http subdirectory for file links
subdir=/files/