diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-06-05 09:47:24 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-06-05 09:49:27 -0400 |
| commit | ad949a452fb9ec6290adb8ec14a04171233a8426 (patch) | |
| tree | 02f89ccd8db37b975c0eff93343f487e506accb3 /src/Main.c | |
| parent | 24f9909badd4e7aa1f3aeef717b93e9b71c20a4e (diff) | |
| parent | b8fd03344d1550cce1d13c753c400d00c2c11b97 (diff) | |
| download | omnisearch-ad949a452fb9ec6290adb8ec14a04171233a8426.tar.gz | |
chore: merge indev into master
Diffstat (limited to 'src/Main.c')
| -rw-r--r-- | src/Main.c | 34 |
1 files changed, 28 insertions, 6 deletions
@@ -19,17 +19,38 @@ #include "Utility/Utility.h" Config global_config; - + int handle_opensearch(UrlParams *params) { (void)params; - extern Config global_config; TemplateContext ctx = new_context(); - context_set(&ctx, "domain", global_config.domain); + + const char *http_host = beaker_get_header("Host"); + if (http_host == NULL) { + http_host = "localhost"; + } + + const char *req_scheme = + "https"; // not sure if it's a good idea to just assume https, but you + // should probably be using https for anything other than testing + // or local network anyways. + + if (strncmp(http_host, "localhost", 9) == 0 || + strncmp(http_host, "127.", 4) == 0 || + strncmp(http_host, "192.168.", 8) == 0 || + strncmp(http_host, "10.", 3) == 0) { + req_scheme = "http"; + } + + context_set(&ctx, "domain", http_host); + context_set(&ctx, "scheme", req_scheme); + char *rendered = render_template("opensearch.xml", &ctx); - serve_data(rendered, strlen(rendered), "application/opensearchdescription+xml"); + serve_data(rendered, strlen(rendered), + "application/opensearchdescription+xml"); free(rendered); free_context(&ctx); + return 0; } @@ -46,7 +67,6 @@ int main() { Config cfg = {.host = DEFAULT_HOST, .port = DEFAULT_PORT, - .domain = "", .default_locale = "en_gb", .proxy = "", .proxy_list_file = "", @@ -68,6 +88,7 @@ int main() { } set_default_locale(cfg.default_locale); + init_themes("static"); global_config = cfg; @@ -75,7 +96,8 @@ int main() { if (loaded > 0) { fprintf(stderr, "[INFO] Loaded %d locales\n", loaded); } else { - fprintf(stderr, "[WARN] No locales loaded (make sure to run from omnisearch directory)\n"); + fprintf(stderr, "[WARN] No locales loaded (make sure to run from " + "omnisearch directory)\n"); } apply_engines_config(cfg.engines); |
