feature: moved domain for opensearch to config

This commit is contained in:
frosty
2026-03-18 04:10:30 -04:00
parent e1ad06ea25
commit 9dc056dc40
5 changed files with 21 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
[server] [server]
host = 0.0.0.0 host = 0.0.0.0
port = 8087 port = 8087
domain = https://search.example.com
[proxy] [proxy]
# Single proxy (comment out to use list_file instead) # Single proxy (comment out to use list_file instead)

View File

@@ -63,6 +63,9 @@ int load_config(const char *filename, Config *config) {
config->host[sizeof(config->host) - 1] = '\0'; config->host[sizeof(config->host) - 1] = '\0';
} else if (strcmp(key, "port") == 0) { } else if (strcmp(key, "port") == 0) {
config->port = atoi(value); 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) { } else if (strcmp(section, "proxy") == 0) {
if (strcmp(key, "proxy") == 0) { if (strcmp(key, "proxy") == 0) {

View File

@@ -33,6 +33,7 @@
typedef struct { typedef struct {
char host[256]; char host[256];
int port; int port;
char domain[256];
char proxy[256]; char proxy[256];
char proxy_list_file[256]; char proxy_list_file[256];
int max_proxy_retries; int max_proxy_retries;

View File

@@ -15,10 +15,18 @@
#include "Routes/Search.h" #include "Routes/Search.h"
#include "Scraping/Scraping.h" #include "Scraping/Scraping.h"
Config global_config;
int handle_opensearch(UrlParams *params) { int handle_opensearch(UrlParams *params) {
(void)params; (void)params;
serve_static_file_with_mime("opensearch.xml", extern Config global_config;
"application/opensearchdescription+xml"); 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; return 0;
} }
@@ -35,6 +43,7 @@ int main() {
Config cfg = {.host = DEFAULT_HOST, Config cfg = {.host = DEFAULT_HOST,
.port = DEFAULT_PORT, .port = DEFAULT_PORT,
.domain = "",
.proxy = "", .proxy = "",
.proxy_list_file = "", .proxy_list_file = "",
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES, .max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
@@ -48,6 +57,8 @@ int main() {
fprintf(stderr, "[WARN] Could not load config file, using defaults\n"); fprintf(stderr, "[WARN] Could not load config file, using defaults\n");
} }
global_config = cfg;
if (cache_init(cfg.cache_dir) != 0) { if (cache_init(cfg.cache_dir) != 0) {
fprintf(stderr, fprintf(stderr,
"[WARN] Failed to initialize cache, continuing without caching\n"); "[WARN] Failed to initialize cache, continuing without caching\n");

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription <OpenSearchDescription
xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/"> xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>OmniSearch</ShortName> <ShortName>OmniSearch</ShortName>
<Description>Lightweight metasearch engine</Description> <Description>Lightweight metasearch engine</Description>
<Url type="text/html" method="get" template="https://search.bwaaa.monster/search?q={searchTerms}"/> <Url type="text/html" method="get" template="{{domain}}/search?q={searchTerms}"/>
<InputEncoding>UTF-8</InputEncoding> <InputEncoding>UTF-8</InputEncoding>
<OutputEncoding>UTF-8</OutputEncoding> <OutputEncoding>UTF-8</OutputEncoding>
<moz:SearchForm>https://search.bwaaa.monster/</moz:SearchForm> <moz:SearchForm>{{domain}}/</moz:SearchForm>
</OpenSearchDescription> </OpenSearchDescription>