@matheusbsbs / matheus-bagliano / commits / d402d5566f
Fork 0

Use config file settings for http

Use "http." config file settings if they exist. Environment variables still work, and they will override config file settings. Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nick Hengeveld committed Oct 14, 2005 at 17:16 UTC d402d5566fdf226697a386dfb9858e5d954e9b91
1 file changed +88 -21
http-fetch.c
+88 -21
@@ -25,7 +25,7 @@ static int active_requests = 0;
25 static int data_received;
26
27 #ifdef USE_CURL_MULTI
28 -static int max_requests = DEFAULT_MAX_REQUESTS;
28 +static int max_requests = -1;
29 static CURLM *curlm;
30 #endif
31 static CURL *curl_default;
@@ -85,11 +85,11 @@ struct active_request_slot
85 static struct transfer_request *request_queue_head = NULL;
86 static struct active_request_slot *active_queue_head = NULL;
87
88 -static int curl_ssl_verify;
89 -static char *ssl_cert;
90 -static char *ssl_key;
91 -static char *ssl_capath;
92 -static char *ssl_cainfo;
88 +static int curl_ssl_verify = -1;
89 +static char *ssl_cert = NULL;
90 +static char *ssl_key = NULL;
91 +static char *ssl_capath = NULL;
92 +static char *ssl_cainfo = NULL;
93
94 struct buffer
95 {
@@ -98,6 +98,60 @@ struct buffer
98 void *buffer;
99 };
100
101 +static int http_options(const char *var, const char *value)
102 +{
103 + if (!strcmp("http.sslverify", var)) {
104 + if (curl_ssl_verify == -1) {
105 + curl_ssl_verify = git_config_bool(var, value);
106 + }
107 + return 0;
108 + }
109 +
110 + if (!strcmp("http.sslcert", var)) {
111 + if (ssl_cert == NULL) {
112 + ssl_cert = xmalloc(strlen(value)+1);
113 + strcpy(ssl_cert, value);
114 + }
115 + return 0;
116 + }
117 +#if LIBCURL_VERSION_NUM >= 0x070902
118 + if (!strcmp("http.sslkey", var)) {
119 + if (ssl_key == NULL) {
120 + ssl_key = xmalloc(strlen(value)+1);
121 + strcpy(ssl_key, value);
122 + }
123 + return 0;
124 + }
125 +#endif
126 +#if LIBCURL_VERSION_NUM >= 0x070908
127 + if (!strcmp("http.sslcapath", var)) {
128 + if (ssl_capath == NULL) {
129 + ssl_capath = xmalloc(strlen(value)+1);
130 + strcpy(ssl_capath, value);
131 + }
132 + return 0;
133 + }
134 +#endif
135 + if (!strcmp("http.sslcainfo", var)) {
136 + if (ssl_cainfo == NULL) {
137 + ssl_cainfo = xmalloc(strlen(value)+1);
138 + strcpy(ssl_cainfo, value);
139 + }
140 + return 0;
141 + }
142 +
143 +#ifdef USE_CURL_MULTI
144 + if (!strcmp("http.maxrequests", var)) {
145 + if (max_requests == -1)
146 + max_requests = git_config_int(var, value);
147 + return 0;
148 + }
149 +#endif
150 +
151 + /* Fall back on the default ones */
152 + return git_default_config(var, value);
153 +}
154 +
155 static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,
156 struct buffer *buffer)
157 {
@@ -1114,8 +1168,6 @@ int main(int argc, char **argv)
1168 char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
1169 if (http_max_requests != NULL)
1170 max_requests = atoi(http_max_requests);
1117 - if (max_requests < 1)
1118 - max_requests = DEFAULT_MAX_REQUESTS;
1171
1172 curlm = curl_multi_init();
1173 if (curlm == NULL) {
@@ -1123,34 +1175,49 @@ int main(int argc, char **argv)
1175 return 1;
1176 }
1177 #endif
1178 +
1179 + if (getenv("GIT_SSL_NO_VERIFY"))
1180 + curl_ssl_verify = 0;
1181 +
1182 + ssl_cert = getenv("GIT_SSL_CERT");
1183 +#if LIBCURL_VERSION_NUM >= 0x070902
1184 + ssl_key = getenv("GIT_SSL_KEY");
1185 +#endif
1186 +#if LIBCURL_VERSION_NUM >= 0x070908
1187 + ssl_capath = getenv("GIT_SSL_CAPATH");
1188 +#endif
1189 + ssl_cainfo = getenv("GIT_SSL_CAINFO");
1190 +
1191 + git_config(http_options);
1192 +
1193 + if (curl_ssl_verify == -1)
1194 + curl_ssl_verify = 1;
1195 +
1196 +#ifdef USE_CURL_MULTI
1197 + if (max_requests < 1)
1198 + max_requests = DEFAULT_MAX_REQUESTS;
1199 +#endif
1200 +
1201 pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
1202 no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
1203 no_range_header = curl_slist_append(no_range_header, "Range:");
1204
1205 curl_default = curl_easy_init();
1206
1132 - curl_ssl_verify = getenv("GIT_SSL_NO_VERIFY") ? 0 : 1;
1207 curl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
1208 #if LIBCURL_VERSION_NUM >= 0x070907
1209 curl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
1210 #endif
1211
1138 - if ((ssl_cert = getenv("GIT_SSL_CERT")) != NULL) {
1212 + if (ssl_cert != NULL)
1213 curl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);
1140 - }
1141 -#if LIBCURL_VERSION_NUM >= 0x070902
1142 - if ((ssl_key = getenv("GIT_SSL_KEY")) != NULL) {
1214 + if (ssl_key != NULL)
1215 curl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);
1144 - }
1145 -#endif
1146 -#if LIBCURL_VERSION_NUM >= 0x070908
1147 - if ((ssl_capath = getenv("GIT_SSL_CAPATH")) != NULL) {
1216 + if (ssl_capath != NULL)
1217 curl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);
1149 - }
1150 -#endif
1151 - if ((ssl_cainfo = getenv("GIT_SSL_CAINFO")) != NULL) {
1218 + if (ssl_cainfo != NULL)
1219 curl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);
1153 - }
1220 +
1221 curl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);
1222
1223 alt = xmalloc(sizeof(*alt));