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) {
|
if (!curl) {
|
||||||
fprintf(stderr, "Link_to_curl(): curl_easy_init() failed!\n");
|
fprintf(stderr, "Link_to_curl(): curl_easy_init() failed!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set up some basic curl stuff */
|
/* set up some basic curl stuff */
|
||||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "HTTPDirFS");
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "HTTPDirFS");
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
|
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_TCP_KEEPALIVE, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
|
||||||
curl_easy_setopt(curl, CURLOPT_SHARE, CURL_SHARE);
|
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);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback);
|
||||||
|
|
||||||
if (NETWORK_CONFIG.username) {
|
if (NETWORK_CONFIG.username) {
|
||||||
|
@ -105,6 +100,20 @@ static CURL *Link_to_curl(Link *link)
|
||||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, NETWORK_CONFIG.password);
|
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;
|
return curl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
53
main.c
53
main.c
|
@ -28,19 +28,22 @@ int main(int argc, char **argv)
|
||||||
network_config_init();
|
network_config_init();
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
int opts_index = 0;
|
int long_index = 0;
|
||||||
const char *short_opts = "o:hVdfsp:u:";
|
const char *short_opts = "o:hVdfsp:u:P:";
|
||||||
const struct option long_opts[] = {
|
const struct option long_opts[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'}, /* 0 */
|
||||||
{"version", no_argument, NULL, 'V'},
|
{"version", no_argument, NULL, 'V'}, /* 1 */
|
||||||
{"debug", no_argument, NULL, 'd'},
|
{"debug", no_argument, NULL, 'd'}, /* 2 */
|
||||||
{"username", required_argument, NULL, 'u'},
|
{"user", required_argument, NULL, 'u'}, /* 3 */
|
||||||
{"password", required_argument, NULL, 'p'},
|
{"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}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
while ((c =
|
while ((c =
|
||||||
getopt_long(argc, argv, short_opts, long_opts,
|
getopt_long(argc, argv, short_opts, long_opts,
|
||||||
&opts_index)) != -1) {
|
&long_index)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'o':
|
case 'o':
|
||||||
add_arg(&fuse_argv, &fuse_argc, "-o");
|
add_arg(&fuse_argv, &fuse_argc, "-o");
|
||||||
|
@ -69,10 +72,33 @@ int main(int argc, char **argv)
|
||||||
case 'u':
|
case 'u':
|
||||||
NETWORK_CONFIG.password = strndup(optarg, ARG_LEN_MAX);
|
NETWORK_CONFIG.password = strndup(optarg, ARG_LEN_MAX);
|
||||||
break;
|
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");
|
fprintf(stderr, "Error: Invalid option\n");
|
||||||
add_arg(&fuse_argv, &fuse_argc, "--help");
|
add_arg(&fuse_argv, &fuse_argc, "--help");
|
||||||
goto fuse_start;
|
goto fuse_start;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -123,7 +149,12 @@ static void print_http_options()
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"HTTP options:\n\
|
"HTTP options:\n\
|
||||||
-u --username HTTP authentication username\n\
|
-u --user HTTP authentication username\n\
|
||||||
-p --password HTTP authentication password\n\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");
|
libfuse options:\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,9 +194,9 @@ void network_config_init()
|
||||||
{
|
{
|
||||||
NETWORK_CONFIG.username = NULL;
|
NETWORK_CONFIG.username = NULL;
|
||||||
NETWORK_CONFIG.password = NULL;
|
NETWORK_CONFIG.password = NULL;
|
||||||
NETWORK_CONFIG.proxy_url = NULL;
|
NETWORK_CONFIG.proxy = NULL;
|
||||||
NETWORK_CONFIG.proxy_password = NULL;
|
NETWORK_CONFIG.proxy_user = NULL;
|
||||||
NETWORK_CONFIG.proxy_password = NULL;
|
NETWORK_CONFIG.proxy_pass = NULL;
|
||||||
NETWORK_CONFIG.max_conns = NETWORK_MAX_CONNS;
|
NETWORK_CONFIG.max_conns = NETWORK_MAX_CONNS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *username;
|
char *username;
|
||||||
char *password;
|
char *password;
|
||||||
char *proxy_url;
|
char *proxy;
|
||||||
char *proxy_username;
|
char *proxy_user;
|
||||||
char *proxy_password;
|
char *proxy_pass;
|
||||||
long max_conns;
|
long max_conns;
|
||||||
} NetworkConfigStruct;
|
} NetworkConfigStruct;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue