From 9f2cd561286784fd000eb8a00f1f80db3185062c Mon Sep 17 00:00:00 2001 From: frosty Date: Fri, 27 Feb 2026 18:32:23 -0500 Subject: added proxying --- src/Main.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/Main.c') diff --git a/src/Main.c b/src/Main.c index b1fd113..4475c5d 100644 --- a/src/Main.c +++ b/src/Main.c @@ -1,10 +1,13 @@ #include #include #include +#include #include #include #include "Config.h" +#include "Proxy/Proxy.h" +#include "Scraping/Scraping.h" #include "Routes/Home.h" #include "Routes/Images.h" #include "Routes/ImageProxy.h" @@ -17,17 +20,45 @@ int handle_opensearch(UrlParams *params) { } int main() { + sigset_t mask; + sigemptyset(&mask); + sigaddset(&mask, SIGPIPE); + pthread_sigmask(SIG_BLOCK, &mask, NULL); + LIBXML_TEST_VERSION xmlInitParser(); curl_global_init(CURL_GLOBAL_DEFAULT); - Config config = {.host = "0.0.0.0", .port = 5000}; + Config config = { + .host = "0.0.0.0", + .port = 5000, + .proxy = "", + .proxy_list_file = "", + .max_proxy_retries = 3, + .randomize_username = 0, + .randomize_password = 0 + }; if (load_config("config.ini", &config) != 0) { fprintf(stderr, "Warning: Could not load config file, using defaults\n"); } + if (config.proxy_list_file[0] != '\0') { + if (load_proxy_list(config.proxy_list_file) < 0) { + fprintf(stderr, "Warning: Failed to load proxy list, continuing without proxies\n"); + } + } + + max_proxy_retries = config.max_proxy_retries; + set_proxy_config(config.proxy, config.randomize_username, config.randomize_password); + + if (proxy_url[0] != '\0') { + fprintf(stderr, "Using proxy: %s\n", proxy_url); + } else if (proxy_count > 0) { + fprintf(stderr, "Using %d proxies from %s\n", proxy_count, config.proxy_list_file); + } + set_handler("/", home_handler); set_handler("/opensearch.xml", handle_opensearch); set_handler("/search", results_handler); @@ -47,5 +78,6 @@ int main() { curl_global_cleanup(); xmlCleanupParser(); + free_proxy_list(); return EXIT_SUCCESS; } \ No newline at end of file -- cgit v1.2.3