From: Alberto Leiva Popper Date: Fri, 16 May 2025 16:52:20 +0000 (-0600) Subject: Add --http.proxy X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fissue160;p=thirdparty%2FFORT-validator.git Add --http.proxy Attempt to fix #160. --- diff --git a/src/config.c b/src/config.c index e3e807c9..86a6d63d 100644 --- a/src/config.c +++ b/src/config.c @@ -125,6 +125,8 @@ struct rpki_config { curl_off_t max_file_size; /* Directory where CA certs to verify peers are found */ char *ca_path; + /* See CURLOPT_PROXY */ + char *proxy; } http; struct { @@ -591,6 +593,14 @@ static const struct option_field options[] = { .doc = "Directory where CA certificates are found, used to verify the peer", .arg_doc = "", .json_null_allowed = false, + }, { + .id = 9013, + .name = "http.proxy", + .type = >_string, + .offset = offsetof(struct rpki_config, http.proxy), + .doc = "Name of proxy to use", + .arg_doc = "", + .json_null_allowed = true, }, /* Logging fields */ @@ -980,6 +990,7 @@ set_default_values(void) rpki_config.http.low_speed_time = 10; rpki_config.http.max_file_size = 2000000000; rpki_config.http.ca_path = NULL; /* Use system default */ + rpki_config.http.proxy = NULL; rpki_config.log.enabled = true; rpki_config.log.tag = NULL; @@ -1013,6 +1024,8 @@ set_default_values(void) static int validate_config(void) { + char const *proxy; + if (rpki_config.mode == PRINT_FILE) return 0; @@ -1040,6 +1053,14 @@ validate_config(void) if (rpki_config.slurm != NULL && !valid_file_or_dir(rpki_config.slurm, true)) return pr_op_err("Invalid slurm location."); + if (rpki_config.http.proxy == NULL) { + proxy = curl_getenv("https_proxy"); + if (proxy == NULL) + proxy = curl_getenv("HTTPS_PROXY"); + if (proxy != NULL && proxy[0] != '\0') + rpki_config.http.proxy = pstrdup(proxy); + } + return 0; } @@ -1402,6 +1423,12 @@ config_get_http_retry_interval(void) return rpki_config.http.retry.interval; } +char const * +config_get_http_proxy(void) +{ + return rpki_config.http.proxy; +} + char const * config_get_http_user_agent(void) { diff --git a/src/config.h b/src/config.h index a40f0f15..30e5de15 100644 --- a/src/config.h +++ b/src/config.h @@ -52,6 +52,7 @@ bool config_get_http_enabled(void); unsigned int config_get_http_priority(void); unsigned int config_get_http_retry_count(void); unsigned int config_get_http_retry_interval(void); +char const *config_get_http_proxy(void); char const *config_get_output_roa(void); char const *config_get_output_bgpsec(void); enum output_format config_get_output_format(void); diff --git a/src/http/http.c b/src/http/http.c index 5ab96d55..2bd31519 100644 --- a/src/http/http.c +++ b/src/http/http.c @@ -213,6 +213,9 @@ http_easy_init(struct http_handler *handler, curl_off_t ims) CURL_TIMECOND_IFMODSINCE); } + if (config_get_http_proxy()) + setopt_str(result, CURLOPT_PROXY, config_get_http_proxy()); + handler->curl = result; return 0; }