add proxy support
This commit is contained in:
parent
8c4e2b0c81
commit
bde7eb7e3b
19
link.c
19
link.c
|
@ -80,7 +80,6 @@ static CURL *Link_to_curl(Link *link)
|
|||
if (!curl) {
|
||||
fprintf(stderr, "Link_to_curl(): curl_easy_init() failed!\n");
|
||||
}
|
||||
|
||||
/* set up some basic curl stuff */
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "HTTPDirFS");
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
|
||||
|
@ -91,10 +90,6 @@ static CURL *Link_to_curl(Link *link)
|
|||
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_easy_setopt(curl, CURLOPT_SHARE, CURL_SHARE);
|
||||
/*
|
||||
* The write back function pointer has to be set at curl handle creation,
|
||||
* for thread safety
|
||||
*/
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback);
|
||||
|
||||
if (NETWORK_CONFIG.username) {
|
||||
|
@ -105,6 +100,20 @@ static CURL *Link_to_curl(Link *link)
|
|||
curl_easy_setopt(curl, CURLOPT_PASSWORD, NETWORK_CONFIG.password);
|
||||
}
|
||||
|
||||
if (NETWORK_CONFIG.proxy) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, NETWORK_CONFIG.proxy);
|
||||
}
|
||||
|
||||
if (NETWORK_CONFIG.proxy_user) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME,
|
||||
NETWORK_CONFIG.proxy_user);
|
||||
}
|
||||
|
||||
if (NETWORK_CONFIG.proxy_pass) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD,
|
||||
NETWORK_CONFIG.proxy_pass);
|
||||
}
|
||||
|
||||
return curl;
|
||||
}
|
||||
|
||||
|
|
53
main.c
53
main.c
|
@ -28,19 +28,22 @@ int main(int argc, char **argv)
|
|||
network_config_init();
|
||||
|
||||
char c;
|
||||
int opts_index = 0;
|
||||
const char *short_opts = "o:hVdfsp:u:";
|
||||
int long_index = 0;
|
||||
const char *short_opts = "o:hVdfsp:u:P:";
|
||||
const struct option long_opts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{"debug", no_argument, NULL, 'd'},
|
||||
{"username", required_argument, NULL, 'u'},
|
||||
{"password", required_argument, NULL, 'p'},
|
||||
{"help", no_argument, NULL, 'h'}, /* 0 */
|
||||
{"version", no_argument, NULL, 'V'}, /* 1 */
|
||||
{"debug", no_argument, NULL, 'd'}, /* 2 */
|
||||
{"user", required_argument, NULL, 'u'}, /* 3 */
|
||||
{"password", required_argument, NULL, 'p'}, /* 4 */
|
||||
{"proxy", required_argument, NULL, 'P'}, /* 5 */
|
||||
{"proxy-user", required_argument, NULL, 'L'}, /* 6 */
|
||||
{"proxy-pass", required_argument, NULL, 'L'}, /* 7 */
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
while ((c =
|
||||
getopt_long(argc, argv, short_opts, long_opts,
|
||||
&opts_index)) != -1) {
|
||||
&long_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'o':
|
||||
add_arg(&fuse_argv, &fuse_argc, "-o");
|
||||
|
@ -69,10 +72,33 @@ int main(int argc, char **argv)
|
|||
case 'u':
|
||||
NETWORK_CONFIG.password = strndup(optarg, ARG_LEN_MAX);
|
||||
break;
|
||||
case '?':
|
||||
case 'P':
|
||||
NETWORK_CONFIG.proxy = strndup(optarg, URL_LEN_MAX);
|
||||
break;
|
||||
case 'L':
|
||||
switch (long_index) {
|
||||
case 6:
|
||||
NETWORK_CONFIG.proxy_user = strndup(optarg,
|
||||
ARG_LEN_MAX);
|
||||
printf("proxy_user: %s\n", optarg);
|
||||
break;
|
||||
case 7:
|
||||
NETWORK_CONFIG.proxy_pass = strndup(optarg,
|
||||
ARG_LEN_MAX);
|
||||
printf("proxy_pass: %s\n", optarg);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Error: Invalid option\n");
|
||||
add_arg(&fuse_argv, &fuse_argc, "--help");
|
||||
goto fuse_start;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Error: Invalid option\n");
|
||||
add_arg(&fuse_argv, &fuse_argc, "--help");
|
||||
goto fuse_start;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -123,7 +149,12 @@ static void print_http_options()
|
|||
{
|
||||
fprintf(stderr,
|
||||
"HTTP options:\n\
|
||||
-u --username HTTP authentication username\n\
|
||||
-p --password HTTP authentication password\n\n\
|
||||
-u --user HTTP authentication username\n\
|
||||
-p --password HTTP authentication password\n\
|
||||
-P --proxy Proxy for libcurl, for details refer to\n\
|
||||
https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html\n\
|
||||
--proxy-user Username for the proxy\n\
|
||||
--proxy-pass Password for the proxy\n\
|
||||
\n\
|
||||
libfuse options:\n");
|
||||
}
|
||||
|
|
|
@ -194,9 +194,9 @@ void network_config_init()
|
|||
{
|
||||
NETWORK_CONFIG.username = NULL;
|
||||
NETWORK_CONFIG.password = NULL;
|
||||
NETWORK_CONFIG.proxy_url = NULL;
|
||||
NETWORK_CONFIG.proxy_password = NULL;
|
||||
NETWORK_CONFIG.proxy_password = NULL;
|
||||
NETWORK_CONFIG.proxy = NULL;
|
||||
NETWORK_CONFIG.proxy_user = NULL;
|
||||
NETWORK_CONFIG.proxy_pass = NULL;
|
||||
NETWORK_CONFIG.max_conns = NETWORK_MAX_CONNS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue