{"thread":{"id":"2109","subject":"[PATCH] Use config file settings for http","startedAt":"2005-10-14T18:51:18Z","lastAt":"2005-10-14T18:51:18Z","messageCount":1,"participants":["Nick Hengeveld"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"10113","messageId":"20051014185118.GA5509@reactrix.com","threadId":"2109","inReplyTo":null,"subject":"[PATCH] Use config file settings for http","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-10-14T18:51:18Z","receivedAt":"2005-10-14T18:51:18Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"Use \"http.\" config file settings if they exist.  Environment variables\nstill work, and they will override config file settings.\n\nSigned-off-by: Nick Hengeveld <nickh@reactrix.com>\n\n\n---\n\n http-fetch.c |  109 +++++++++++++++++++++++++++++++++++++++++++++++-----------\n 1 files changed, 88 insertions(+), 21 deletions(-)\n\ne1564121cae5272fbac9710a61ac182ddb9d421c\ndiff --git a/http-fetch.c b/http-fetch.c\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -25,7 +25,7 @@ static int active_requests = 0;\n static int data_received;\n \n #ifdef USE_CURL_MULTI\n-static int max_requests = DEFAULT_MAX_REQUESTS;\n+static int max_requests = -1;\n static CURLM *curlm;\n #endif\n static CURL *curl_default;\n@@ -85,11 +85,11 @@ struct active_request_slot\n static struct transfer_request *request_queue_head = NULL;\n static struct active_request_slot *active_queue_head = NULL;\n \n-static int curl_ssl_verify;\n-static char *ssl_cert;\n-static char *ssl_key;\n-static char *ssl_capath;\n-static char *ssl_cainfo;\n+static int curl_ssl_verify = -1;\n+static char *ssl_cert = NULL;\n+static char *ssl_key = NULL;\n+static char *ssl_capath = NULL;\n+static char *ssl_cainfo = NULL;\n \n struct buffer\n {\n@@ -98,6 +98,60 @@ struct buffer\n         void *buffer;\n };\n \n+static int http_options(const char *var, const char *value)\n+{\n+\tif (!strcmp(\"http.sslverify\", var)) {\n+\t\tif (curl_ssl_verify == -1) {\n+\t\t\tcurl_ssl_verify = git_config_bool(var, value);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(\"http.sslcert\", var)) {\n+\t\tif (ssl_cert == NULL) {\n+\t\t\tssl_cert = xmalloc(strlen(value)+1);\n+\t\t\tstrcpy(ssl_cert, value);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+#if LIBCURL_VERSION_NUM >= 0x070902\n+\tif (!strcmp(\"http.sslkey\", var)) {\n+\t\tif (ssl_key == NULL) {\n+\t\t\tssl_key = xmalloc(strlen(value)+1);\n+\t\t\tstrcpy(ssl_key, value);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+#endif\n+#if LIBCURL_VERSION_NUM >= 0x070908\n+\tif (!strcmp(\"http.sslcapath\", var)) {\n+\t\tif (ssl_capath == NULL) {\n+\t\t\tssl_capath = xmalloc(strlen(value)+1);\n+\t\t\tstrcpy(ssl_capath, value);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+#endif\n+\tif (!strcmp(\"http.sslcainfo\", var)) {\n+\t\tif (ssl_cainfo == NULL) {\n+\t\t\tssl_cainfo = xmalloc(strlen(value)+1);\n+\t\t\tstrcpy(ssl_cainfo, value);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\n+#ifdef USE_CURL_MULTI\t\n+\tif (!strcmp(\"http.maxrequests\", var)) {\n+\t\tif (max_requests == -1)\n+\t\t\tmax_requests = git_config_int(var, value);\n+\t\treturn 0;\n+\t}\n+#endif\n+\n+\t/* Fall back on the default ones */\n+\treturn git_default_config(var, value);\n+}\n+\n static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,\n                             struct buffer *buffer)\n {\n@@ -1114,8 +1168,6 @@ int main(int argc, char **argv)\n \tchar *http_max_requests = getenv(\"GIT_HTTP_MAX_REQUESTS\");\n \tif (http_max_requests != NULL)\n \t\tmax_requests = atoi(http_max_requests);\n-\tif (max_requests < 1)\n-\t\tmax_requests = DEFAULT_MAX_REQUESTS;\n \n \tcurlm = curl_multi_init();\n \tif (curlm == NULL) {\n@@ -1123,34 +1175,49 @@ int main(int argc, char **argv)\n \t\treturn 1;\n \t}\n #endif\n+\n+\tif (getenv(\"GIT_SSL_NO_VERIFY\"))\n+\t\tcurl_ssl_verify = 0;\n+\n+\tssl_cert = getenv(\"GIT_SSL_CERT\");\n+#if LIBCURL_VERSION_NUM >= 0x070902\n+\tssl_key = getenv(\"GIT_SSL_KEY\");\n+#endif\n+#if LIBCURL_VERSION_NUM >= 0x070908\n+\tssl_capath = getenv(\"GIT_SSL_CAPATH\");\n+#endif\n+\tssl_cainfo = getenv(\"GIT_SSL_CAINFO\");\n+\n+\tgit_config(http_options);\n+\n+\tif (curl_ssl_verify == -1)\n+\t\tcurl_ssl_verify = 1;\n+\n+#ifdef USE_CURL_MULTI\n+\tif (max_requests < 1)\n+\t\tmax_requests = DEFAULT_MAX_REQUESTS;\n+#endif\n+\n \tpragma_header = curl_slist_append(pragma_header, \"Pragma: no-cache\");\n \tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n \tno_range_header = curl_slist_append(no_range_header, \"Range:\");\n \n \tcurl_default = curl_easy_init();\n \n-\tcurl_ssl_verify = getenv(\"GIT_SSL_NO_VERIFY\") ? 0 : 1;\n \tcurl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);\n #if LIBCURL_VERSION_NUM >= 0x070907\n \tcurl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);\n #endif\n \n-\tif ((ssl_cert = getenv(\"GIT_SSL_CERT\")) != NULL) {\n+\tif (ssl_cert != NULL)\n \t\tcurl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);\n-\t}\n-#if LIBCURL_VERSION_NUM >= 0x070902\n-\tif ((ssl_key = getenv(\"GIT_SSL_KEY\")) != NULL) {\n+\tif (ssl_key != NULL)\n \t\tcurl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);\n-\t}\n-#endif\n-#if LIBCURL_VERSION_NUM >= 0x070908\n-\tif ((ssl_capath = getenv(\"GIT_SSL_CAPATH\")) != NULL) {\n+\tif (ssl_capath != NULL)\n \t\tcurl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);\n-\t}\n-#endif\n-\tif ((ssl_cainfo = getenv(\"GIT_SSL_CAINFO\")) != NULL) {\n+\tif (ssl_cainfo != NULL)\n \t\tcurl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);\n-\t}\n+\n \tcurl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);\n \n \talt = xmalloc(sizeof(*alt));\n"}]}