From 9dc056dc405ec2c23b3e802624c5596f518608d3 Mon Sep 17 00:00:00 2001 From: frosty Date: Wed, 18 Mar 2026 04:10:30 -0400 Subject: feature: moved domain for opensearch to config --- example-config.ini | 1 + src/Config.c | 3 +++ src/Config.h | 1 + src/Main.c | 15 +++++++++++++-- static/opensearch.xml | 11 ----------- templates/opensearch.xml | 11 +++++++++++ 6 files changed, 29 insertions(+), 13 deletions(-) delete mode 100644 static/opensearch.xml create mode 100644 templates/opensearch.xml diff --git a/example-config.ini b/example-config.ini index 956970c..e0f1f02 100644 --- a/example-config.ini +++ b/example-config.ini @@ -1,6 +1,7 @@ [server] host = 0.0.0.0 port = 8087 +domain = https://search.example.com [proxy] # Single proxy (comment out to use list_file instead) diff --git a/src/Config.c b/src/Config.c index 490d069..b4a0f21 100644 --- a/src/Config.c +++ b/src/Config.c @@ -63,6 +63,9 @@ int load_config(const char *filename, Config *config) { config->host[sizeof(config->host) - 1] = '\0'; } else if (strcmp(key, "port") == 0) { config->port = atoi(value); + } else if (strcmp(key, "domain") == 0) { + strncpy(config->domain, value, sizeof(config->domain) - 1); + config->domain[sizeof(config->domain) - 1] = '\0'; } } else if (strcmp(section, "proxy") == 0) { if (strcmp(key, "proxy") == 0) { diff --git a/src/Config.h b/src/Config.h index e0e242c..33ff527 100644 --- a/src/Config.h +++ b/src/Config.h @@ -33,6 +33,7 @@ typedef struct { char host[256]; int port; + char domain[256]; char proxy[256]; char proxy_list_file[256]; int max_proxy_retries; diff --git a/src/Main.c b/src/Main.c index 9cdd0ad..be5080b 100644 --- a/src/Main.c +++ b/src/Main.c @@ -15,10 +15,18 @@ #include "Routes/Search.h" #include "Scraping/Scraping.h" +Config global_config; + int handle_opensearch(UrlParams *params) { (void)params; - serve_static_file_with_mime("opensearch.xml", - "application/opensearchdescription+xml"); + extern Config global_config; + TemplateContext ctx = new_context(); + context_set(&ctx, "domain", global_config.domain); + char *rendered = render_template("opensearch.xml", &ctx); + serve_data(rendered, strlen(rendered), "application/opensearchdescription+xml"); + + free(rendered); + free_context(&ctx); return 0; } @@ -35,6 +43,7 @@ int main() { Config cfg = {.host = DEFAULT_HOST, .port = DEFAULT_PORT, + .domain = "", .proxy = "", .proxy_list_file = "", .max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES, @@ -48,6 +57,8 @@ int main() { fprintf(stderr, "[WARN] Could not load config file, using defaults\n"); } + global_config = cfg; + if (cache_init(cfg.cache_dir) != 0) { fprintf(stderr, "[WARN] Failed to initialize cache, continuing without caching\n"); diff --git a/static/opensearch.xml b/static/opensearch.xml deleted file mode 100644 index 22853dd..0000000 --- a/static/opensearch.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - OmniSearch - Lightweight metasearch engine - - UTF-8 - UTF-8 - https://search.bwaaa.monster/ - diff --git a/templates/opensearch.xml b/templates/opensearch.xml new file mode 100644 index 0000000..8544b09 --- /dev/null +++ b/templates/opensearch.xml @@ -0,0 +1,11 @@ + + + OmniSearch + Lightweight metasearch engine + + UTF-8 + UTF-8 + {{domain}}/ + -- cgit v1.2.3