Compare commits
3 Commits
05cb1387f4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 95a10c5f9b | |||
| 78e458f2b1 | |||
| 403256f546 |
@@ -10,9 +10,11 @@ Create a config.ini, there is an example included in the root. Or if you install
|
||||
|
||||
## Dependencies
|
||||
- libxml2
|
||||
- libcurl (may be replaced in the future with curl-impersonate)
|
||||
- curl-impersonate (or libcurl; build with `-DOMNISEARCH_USE_CURL_IMPERSONATE` and link `-lcurl-impersonate` to enable browser impersonation)
|
||||
- beaker [(source)](https://git.bwaaa.space/beaker/)
|
||||
|
||||
The included Nix flake and NixOS module build against curl-impersonate automatically. Set `OMNISEARCH_IMPERSONATE_TARGET` to override the impersonated browser profile (default: `chrome136`).
|
||||
|
||||
## First Setup
|
||||
Depending on your system, you may first need to install libcurl and libxml2.
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ port = 8087
|
||||
[engines]
|
||||
# Use * for all engines, or specify comma-separated list (e.g., ddg,yahoo)
|
||||
# Use *,-engine to exclude specific engines (e.g., *,-startpage)
|
||||
# Available engines: ddg, startpage, yahoo, mojeek, yacy
|
||||
# Available engines: ddg, startpage, yahoo, mojeek, bing, yacy
|
||||
engines="*"
|
||||
# YaCy instance to use for the yacy engine (optional, default: http://127.0.0.1:8090)
|
||||
# Requires "yacy" to be in the engines list above.
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
|
||||
buildInputs = [
|
||||
pkgs.libxml2.dev
|
||||
pkgs.curl.dev
|
||||
pkgs.curl-impersonate
|
||||
pkgs.curl-impersonate.dev
|
||||
pkgs.openssl
|
||||
beaker
|
||||
];
|
||||
@@ -48,8 +49,8 @@
|
||||
preBuild = ''
|
||||
makeFlagsArray+=(
|
||||
"PREFIX=$out"
|
||||
"CFLAGS=-Wall -Wextra -O2 -Isrc -I${pkgs.libxml2.dev}/include/libxml2"
|
||||
"LIBS=-lbeaker -lcurl -lxml2 -lpthread -lm -lssl -lcrypto"
|
||||
"CFLAGS=-Wall -Wextra -O2 -Isrc -I${pkgs.libxml2.dev}/include/libxml2 -I${pkgs.curl-impersonate.dev}/include -DOMNISEARCH_USE_CURL_IMPERSONATE"
|
||||
"LIBS=-lbeaker -lcurl-impersonate -lxml2 -lpthread -lm -lssl -lcrypto"
|
||||
)
|
||||
'';
|
||||
|
||||
|
||||
137
module.nix
Normal file
137
module.nix
Normal file
@@ -0,0 +1,137 @@
|
||||
self: {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
cfg = config.services.omnisearch;
|
||||
pkg = cfg.package;
|
||||
|
||||
finalConfigFile =
|
||||
if cfg.configFile != null
|
||||
then cfg.configFile
|
||||
else
|
||||
pkgs.writeText "omnisearch.ini" ''
|
||||
[server]
|
||||
host = ${cfg.settings.server.host}
|
||||
port = ${toString cfg.settings.server.port}
|
||||
domain = ${cfg.settings.server.domain}
|
||||
${lib.optionalString (cfg.settings.server.locale != null) "locale = ${cfg.settings.server.locale}"}
|
||||
|
||||
[proxy]
|
||||
${lib.optionalString (cfg.settings.proxy.proxy != null) "proxy = \"${cfg.settings.proxy.proxy}\""}
|
||||
${lib.optionalString (
|
||||
cfg.settings.proxy.list_file != null
|
||||
) "list_file = ${cfg.settings.proxy.list_file}"}
|
||||
max_retries = ${toString cfg.settings.proxy.max_retries}
|
||||
randomize_username = ${lib.boolToString cfg.settings.proxy.randomize_username}
|
||||
randomize_password = ${lib.boolToString cfg.settings.proxy.randomize_password}
|
||||
|
||||
[cache]
|
||||
dir = ${cfg.settings.cache.dir}
|
||||
ttl_search = ${toString cfg.settings.cache.ttl_search}
|
||||
ttl_infobox = ${toString cfg.settings.cache.ttl_infobox}
|
||||
'';
|
||||
in {
|
||||
options.services.omnisearch = {
|
||||
enable = lib.mkEnableOption "OmniSearch metasearch engine";
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||
description = "The omnisearch package to use.";
|
||||
};
|
||||
|
||||
configFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = "Path to a custom config.ini. Overrides 'settings'.";
|
||||
};
|
||||
|
||||
settings = {
|
||||
server = {
|
||||
host = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "0.0.0.0";
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8087;
|
||||
};
|
||||
domain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http://localhost:${toString cfg.settings.server.port}";
|
||||
};
|
||||
locale = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
proxy = {
|
||||
proxy = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
list_file = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
max_retries = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 3;
|
||||
};
|
||||
randomize_username = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
randomize_password = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
cache = {
|
||||
dir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/cache/omnisearch";
|
||||
};
|
||||
ttl_search = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 3600;
|
||||
};
|
||||
ttl_infobox = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 86400;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.omnisearch = {
|
||||
description = "OmniSearch Service";
|
||||
after = ["network.target"];
|
||||
wantedBy = ["multi-user.target"];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkg}/bin/omnisearch";
|
||||
|
||||
WorkingDirectory = "/var/lib/omnisearch";
|
||||
StateDirectory = "omnisearch";
|
||||
CacheDirectory = "omnisearch";
|
||||
|
||||
BindReadOnlyPaths = [
|
||||
"${pkg}/share/omnisearch/templates:/var/lib/omnisearch/templates"
|
||||
"${pkg}/share/omnisearch/static:/var/lib/omnisearch/static"
|
||||
"${pkg}/share/omnisearch/locales:/var/lib/omnisearch/locales"
|
||||
"${finalConfigFile}:/var/lib/omnisearch/config.ini"
|
||||
];
|
||||
|
||||
DynamicUser = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
PrivateTmp = true;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -25,9 +25,15 @@
|
||||
#define INFOBOX_FIELD_COUNT 5
|
||||
#define MAX_RESULTS_PER_ENGINE 10
|
||||
|
||||
#define CURL_TIMEOUT_SECS 15L
|
||||
#define CURL_TIMEOUT_SECS 8L
|
||||
#define CURL_CONNECT_TIMEOUT_SECS 5L
|
||||
#define CURL_DNS_TIMEOUT_SECS 300L
|
||||
|
||||
/* Upper bound for a whole search, even if one engine hangs. */
|
||||
#define SCRAPE_DEADLINE_MS 8000
|
||||
|
||||
#define DEFAULT_IMPERSONATE_TARGET "chrome136"
|
||||
|
||||
#define BING_IMAGE_URL "https://www.bing.com/images/search"
|
||||
#define IMAGE_RESULTS_PER_PAGE 32
|
||||
#define IMAGE_RESULT_FIELDS 4
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -66,13 +66,11 @@ void configure_yacy_engine(const char *instance);
|
||||
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||
void *userp);
|
||||
const char *get_random_user_agent(void);
|
||||
const char *get_first_user_agent(void);
|
||||
void configure_curl_handle(CURL *curl, const char *full_url,
|
||||
MemoryBuffer *chunk, struct curl_slist *headers);
|
||||
char *build_search_url(const char *base_url, const char *page_param,
|
||||
int page_multiplier, int page_base,
|
||||
const char *encoded_query, int page);
|
||||
char *build_ddg_next_page_data(const char *html, size_t size);
|
||||
struct curl_slist *build_request_headers(const char *host_header,
|
||||
const char *referer);
|
||||
void http_delay(void);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../Proxy/Proxy.h"
|
||||
#include "../Utility/HttpClient.h"
|
||||
#include "Config.h"
|
||||
#include "Scraping.h"
|
||||
#include <curl/curl.h>
|
||||
@@ -53,25 +54,30 @@ const char *get_random_user_agent(void) {
|
||||
return USER_AGENTS[rand() % USER_AGENT_COUNT];
|
||||
}
|
||||
|
||||
const char *get_first_user_agent(void) { return USER_AGENTS[0]; }
|
||||
|
||||
void configure_curl_handle(CURL *curl, const char *full_url,
|
||||
MemoryBuffer *chunk, struct curl_slist *headers) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, full_url);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)chunk);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, get_random_user_agent());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||
curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, CURL_DNS_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CURL_CONNECT_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
|
||||
|
||||
apply_proxy_settings(curl);
|
||||
|
||||
#ifdef OMNISEARCH_USE_CURL_IMPERSONATE
|
||||
http_apply_browser_impersonation(curl);
|
||||
#else
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, get_random_user_agent());
|
||||
/* Yahoo currently answers plain HTTP/2 requests with a 500 error. */
|
||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *build_search_url(const char *base_url, const char *page_param,
|
||||
@@ -87,69 +93,6 @@ char *build_search_url(const char *base_url, const char *page_param,
|
||||
return url;
|
||||
}
|
||||
|
||||
char *build_ddg_next_page_data(const char *html, size_t size) {
|
||||
htmlDocPtr doc = htmlReadMemory(html, size, NULL, NULL,
|
||||
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR |
|
||||
HTML_PARSE_NOWARNING);
|
||||
if (!doc)
|
||||
return NULL;
|
||||
|
||||
xmlXPathContextPtr ctx = create_xpath_context(doc);
|
||||
if (!ctx) {
|
||||
xmlFreeDoc(doc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmlXPathObjectPtr inputs = xmlXPathEvalExpression(
|
||||
(const xmlChar *)"(//form[.//input[@name='s'] and "
|
||||
".//input[@name='vqd' and string-length(@value)>0] and "
|
||||
"(.//input[@type='submit' and contains(@value, 'Next')] or "
|
||||
".//button[contains(., 'Next')])])[1]"
|
||||
"//input[@name and not(@disabled) and "
|
||||
"(not(@type) or @type='hidden')]",
|
||||
ctx);
|
||||
|
||||
if (!inputs || !inputs->nodesetval) {
|
||||
free_xpath_objects(ctx, inputs);
|
||||
xmlFreeDoc(doc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *data = NULL;
|
||||
size_t length = 0;
|
||||
int failed = 0;
|
||||
for (int i = 0; i < inputs->nodesetval->nodeNr; i++) {
|
||||
xmlNodePtr node = inputs->nodesetval->nodeTab[i];
|
||||
xmlChar *name = xmlGetProp(node, (const xmlChar *)"name");
|
||||
xmlChar *value = xmlGetProp(node, (const xmlChar *)"value");
|
||||
char *key = curl_easy_escape(NULL, (const char *)name, 0);
|
||||
char *val = curl_easy_escape(NULL, value ? (const char *)value : "", 0);
|
||||
size_t needed = key && val ? strlen(key) + strlen(val) + 2 : 0;
|
||||
char *expanded = needed ? realloc(data, length + needed + 1) : NULL;
|
||||
if (expanded) {
|
||||
data = expanded;
|
||||
length += snprintf(data + length, needed + 1, "%s%s=%s",
|
||||
length ? "&" : "", key, val);
|
||||
} else {
|
||||
failed = 1;
|
||||
}
|
||||
curl_free(key);
|
||||
curl_free(val);
|
||||
xmlFree(name);
|
||||
xmlFree(value);
|
||||
if (failed)
|
||||
break;
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
free(data);
|
||||
data = NULL;
|
||||
}
|
||||
free_xpath_objects(ctx, inputs);
|
||||
xmlFreeDoc(doc);
|
||||
return data;
|
||||
}
|
||||
|
||||
struct curl_slist *build_request_headers(const char *host_header,
|
||||
const char *referer) {
|
||||
struct curl_slist *headers = NULL;
|
||||
@@ -163,12 +106,15 @@ struct curl_slist *build_request_headers(const char *host_header,
|
||||
snprintf(ref_buf, sizeof(ref_buf), "Referer: %s", referer);
|
||||
headers = curl_slist_append(headers, ref_buf);
|
||||
}
|
||||
|
||||
#ifndef OMNISEARCH_USE_CURL_IMPERSONATE
|
||||
headers = curl_slist_append(
|
||||
headers,
|
||||
"Accept: "
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
headers = curl_slist_append(headers, "Accept-Language: en-US,en;q=0.5");
|
||||
headers = curl_slist_append(headers, "DNT: 1");
|
||||
#endif
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,70 @@ void free_xml_node_list(char *title, char *url, char *snippet) {
|
||||
xmlFree(snippet);
|
||||
}
|
||||
|
||||
static int parse_ddg_html(const char *engine_name, xmlDocPtr doc,
|
||||
SearchResult **out_results, int max_results) {
|
||||
(void)engine_name;
|
||||
int found_count = 0;
|
||||
|
||||
xmlXPathContextPtr ctx = create_xpath_context(doc);
|
||||
if (!ctx)
|
||||
return 0;
|
||||
|
||||
xmlXPathObjectPtr obj = xml_xpath_eval(ctx, "//a[@class='result__a']");
|
||||
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
||||
free_xpath_objects(ctx, obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int num_links = obj->nodesetval->nodeNr;
|
||||
*out_results = alloc_results_array(num_links, max_results);
|
||||
if (!*out_results) {
|
||||
free_xpath_objects(ctx, obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_links && found_count < max_results; i++) {
|
||||
xmlNodePtr link_node = obj->nodesetval->nodeTab[i];
|
||||
char *title = xml_node_content(link_node);
|
||||
char *url = (char *)xmlGetProp(link_node, (xmlChar *)"href");
|
||||
char *snippet_text = NULL;
|
||||
|
||||
xmlNodePtr result_node = link_node->parent;
|
||||
while (result_node) {
|
||||
if (result_node->type == XML_ELEMENT_NODE &&
|
||||
xmlStrcasecmp(result_node->name, (const xmlChar *)"div") == 0) {
|
||||
xmlChar *class_name =
|
||||
xmlGetProp(result_node, (const xmlChar *)"class");
|
||||
int is_result =
|
||||
class_name && strstr((const char *)class_name, "result") != NULL;
|
||||
xmlFree(class_name);
|
||||
if (is_result)
|
||||
break;
|
||||
}
|
||||
result_node = result_node->parent;
|
||||
}
|
||||
|
||||
if (result_node) {
|
||||
ctx->node = result_node;
|
||||
xmlXPathObjectPtr snippet_obj =
|
||||
xml_xpath_eval(ctx, ".//a[contains(@class, 'result__snippet')]");
|
||||
if (snippet_obj && snippet_obj->nodesetval &&
|
||||
snippet_obj->nodesetval->nodeNr > 0)
|
||||
snippet_text = xml_node_content(snippet_obj->nodesetval->nodeTab[0]);
|
||||
if (snippet_obj)
|
||||
xmlXPathFreeObject(snippet_obj);
|
||||
ctx->node = NULL;
|
||||
}
|
||||
|
||||
assign_result(&(*out_results)[found_count], url, title, snippet_text, 1);
|
||||
free_xml_node_list(title, url, snippet_text);
|
||||
found_count++;
|
||||
}
|
||||
|
||||
free_xpath_objects(ctx, obj);
|
||||
return found_count;
|
||||
}
|
||||
|
||||
static int parse_ddg_lite(const char *engine_name, xmlDocPtr doc,
|
||||
SearchResult **out_results, int max_results) {
|
||||
(void)engine_name;
|
||||
@@ -54,7 +118,7 @@ static int parse_ddg_lite(const char *engine_name, xmlDocPtr doc,
|
||||
|
||||
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
||||
free_xpath_objects(ctx, obj);
|
||||
return 0;
|
||||
return parse_ddg_html(engine_name, doc, out_results, max_results);
|
||||
}
|
||||
|
||||
int num_links = obj->nodesetval->nodeNr;
|
||||
@@ -309,7 +373,7 @@ static int parse_yahoo(const char *engine_name, xmlDocPtr doc,
|
||||
static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
||||
SearchResult **out_results, int max_results);
|
||||
|
||||
static int parse_yacy(const char *engine_name, xmlDocPtr doc,
|
||||
static int parse_rss(const char *engine_name, xmlDocPtr doc,
|
||||
SearchResult **out_results, int max_results) {
|
||||
(void)engine_name;
|
||||
int found_count = 0;
|
||||
@@ -434,6 +498,17 @@ SearchEngine ENGINE_REGISTRY[] = {
|
||||
.page_base = 1,
|
||||
.parser = parse_mojeek,
|
||||
.enabled = 1},
|
||||
{.id = "bing",
|
||||
.name = "Bing",
|
||||
.base_url = "https://www.bing.com/search?format=rss&q=",
|
||||
.host_header = "www.bing.com",
|
||||
.referer = "https://www.bing.com/",
|
||||
.page_param = "first",
|
||||
.page_multiplier = 10,
|
||||
.page_base = 1,
|
||||
.parser = parse_rss,
|
||||
.enabled = 1,
|
||||
.is_xml = 1},
|
||||
{.id = "yacy",
|
||||
.name = "YaCy",
|
||||
.base_url = "",
|
||||
@@ -442,7 +517,7 @@ SearchEngine ENGINE_REGISTRY[] = {
|
||||
.page_param = "startRecord",
|
||||
.page_multiplier = 10,
|
||||
.page_base = 0,
|
||||
.parser = parse_yacy,
|
||||
.parser = parse_rss,
|
||||
.enabled = 0,
|
||||
.is_xml = 1}};
|
||||
|
||||
|
||||
@@ -2,9 +2,27 @@
|
||||
#include "../Cache/Cache.h"
|
||||
#include "../Proxy/Proxy.h"
|
||||
#include "Config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void http_apply_browser_impersonation(CURL *curl) {
|
||||
#ifdef OMNISEARCH_USE_CURL_IMPERSONATE
|
||||
const char *target = getenv("OMNISEARCH_IMPERSONATE_TARGET");
|
||||
if (!target || target[0] == '\0')
|
||||
target = DEFAULT_IMPERSONATE_TARGET;
|
||||
|
||||
CURLcode result = curl_easy_impersonate(curl, target, 1);
|
||||
if (result != CURLE_OK) {
|
||||
fprintf(stderr,
|
||||
"[WARN] curl-impersonate target '%s' failed: %s; using defaults\n",
|
||||
target, curl_easy_strerror(result));
|
||||
}
|
||||
#else
|
||||
(void)curl;
|
||||
#endif
|
||||
}
|
||||
|
||||
static size_t write_callback(void *contents, size_t size, size_t nmemb,
|
||||
void *userp) {
|
||||
size_t realsize = size * nmemb;
|
||||
@@ -32,6 +50,10 @@ static size_t write_callback(void *contents, size_t size, size_t nmemb,
|
||||
}
|
||||
|
||||
static struct curl_slist *build_http_headers(void) {
|
||||
#ifdef OMNISEARCH_USE_CURL_IMPERSONATE
|
||||
/* curl-impersonate supplies a complete, browser-consistent header set. */
|
||||
return NULL;
|
||||
#else
|
||||
struct curl_slist *headers = NULL;
|
||||
headers = curl_slist_append(
|
||||
headers,
|
||||
@@ -40,6 +62,7 @@ static struct curl_slist *build_http_headers(void) {
|
||||
headers = curl_slist_append(headers, "Accept-Language: en-US,en;q=0.5");
|
||||
headers = curl_slist_append(headers, "DNT: 1");
|
||||
return headers;
|
||||
#endif
|
||||
}
|
||||
|
||||
HttpResponse http_get(const char *url, const char *user_agent) {
|
||||
@@ -68,16 +91,23 @@ HttpResponse http_get(const char *url, const char *user_agent) {
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
||||
user_agent ? user_agent : "libcurl-agent/1.0");
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CURL_CONNECT_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||
curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, CURL_DNS_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
apply_proxy_settings(curl);
|
||||
|
||||
#ifdef OMNISEARCH_USE_CURL_IMPERSONATE
|
||||
(void)user_agent;
|
||||
http_apply_browser_impersonation(curl);
|
||||
#else
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
||||
user_agent ? user_agent : "libcurl-agent/1.0");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||
#endif
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
@@ -15,6 +15,9 @@ typedef struct {
|
||||
HttpResponse http_get(const char *url, const char *user_agent);
|
||||
void http_response_free(HttpResponse *resp);
|
||||
|
||||
/* Apply a browser TLS/HTTP fingerprint when built against curl-impersonate. */
|
||||
void http_apply_browser_impersonation(CURL *curl);
|
||||
|
||||
typedef xmlDocPtr (*XmlParserFn)(const char *data, size_t size,
|
||||
const char *url);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user