added command line switch to configure user agent and the maximum number of network connections allowed

This commit is contained in:
Fufu Fang 2019-04-26 11:39:03 +01:00
parent f4fd419528
commit 85d66adf6c
5 changed files with 29 additions and 27 deletions

View File

@ -1,4 +1,4 @@
VERSION=1.1.4 VERSION=1.1.3
CFLAGS+= -g -O2 -Wall -Wextra -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\" \ CFLAGS+= -g -O2 -Wall -Wextra -D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\" \
`pkg-config --cflags-only-I gumbo libcurl fuse` `pkg-config --cflags-only-I gumbo libcurl fuse`

View File

@ -101,7 +101,7 @@ static CURL *Link_to_curl(Link *link)
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, NETWORK_CONFIG.user_agent);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
/* for following directories without the '/' */ /* for following directories without the '/' */

View File

@ -7,8 +7,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define ARG_LEN_MAX 64
void add_arg(char ***fuse_argv_ptr, int *fuse_argc, char *opt_string); void add_arg(char ***fuse_argv_ptr, int *fuse_argc, char *opt_string);
static void print_help(char *program_name, int long_help); static void print_help(char *program_name, int long_help);
static void print_version(); static void print_version();
@ -133,17 +131,18 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
const char *short_opts = "o:hVdfsp:u:P:"; const char *short_opts = "o:hVdfsp:u:P:";
const struct option long_opts[] = { const struct option long_opts[] = {
/* Note that 'L' is returned for long options */ /* Note that 'L' is returned for long options */
{"help", no_argument, NULL, 'h'}, /* 0 */ {"help", no_argument, NULL, 'h'}, /* 0 */
{"version", no_argument, NULL, 'V'}, /* 1 */ {"version", no_argument, NULL, 'V'}, /* 1 */
{"debug", no_argument, NULL, 'd'}, /* 2 */ {"debug", no_argument, NULL, 'd'}, /* 2 */
{"username", required_argument, NULL, 'u'}, /* 3 */ {"username", required_argument, NULL, 'u'}, /* 3 */
{"password", required_argument, NULL, 'p'}, /* 4 */ {"password", required_argument, NULL, 'p'}, /* 4 */
{"proxy", required_argument, NULL, 'P'}, /* 5 */ {"proxy", required_argument, NULL, 'P'}, /* 5 */
{"proxy-username", required_argument, NULL, 'L'}, /* 6 */ {"proxy-username", required_argument, NULL, 'L'}, /* 6 */
{"proxy-password", required_argument, NULL, 'L'}, /* 7 */ {"proxy-password", required_argument, NULL, 'L'}, /* 7 */
{"cache", required_argument, NULL, 'L'}, /* 8 */ {"cache", required_argument, NULL, 'L'}, /* 8 */
{"dl-seg-size", required_argument, NULL, 'L'}, /* 9 */ {"dl-seg-size", required_argument, NULL, 'L'}, /* 9 */
{"max-conns", required_argument, NULL, 'L'}, /* 10 */ {"max-conns", required_argument, NULL, 'L'}, /* 10 */
{"user-agent", required_argument, NULL, 'L'}, /* 11 */
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
while ((c = while ((c =
@ -173,24 +172,22 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
add_arg(fuse_argv, fuse_argc, "-s"); add_arg(fuse_argv, fuse_argc, "-s");
break; break;
case 'u': case 'u':
NETWORK_CONFIG.username = strndup(optarg, ARG_LEN_MAX); NETWORK_CONFIG.username = strdup(optarg);
break; break;
case 'p': case 'p':
NETWORK_CONFIG.password = strndup(optarg, ARG_LEN_MAX); NETWORK_CONFIG.password = strdup(optarg);
break; break;
case 'P': case 'P':
NETWORK_CONFIG.proxy = strndup(optarg, MAX_PATH_LEN); NETWORK_CONFIG.proxy = strdup(optarg);
break; break;
case 'L': case 'L':
/* Long options */ /* Long options */
switch (long_index) { switch (long_index) {
case 6: case 6:
NETWORK_CONFIG.proxy_user = strndup(optarg, NETWORK_CONFIG.proxy_user = strdup(optarg);
ARG_LEN_MAX);
break; break;
case 7: case 7:
NETWORK_CONFIG.proxy_pass = strndup(optarg, NETWORK_CONFIG.proxy_pass = strdup(optarg);
ARG_LEN_MAX);
break; break;
case 8: case 8:
CacheSystem_init(optarg); CacheSystem_init(optarg);
@ -201,6 +198,8 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
case 10: case 10:
NETWORK_CONFIG.max_conns = atoi(optarg); NETWORK_CONFIG.max_conns = atoi(optarg);
break; break;
case 11:
NETWORK_CONFIG.user_agent = strdup(optarg);
default: 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");
@ -225,7 +224,7 @@ void add_arg(char ***fuse_argv_ptr, int *fuse_argc, char *opt_string)
(*fuse_argc)++; (*fuse_argc)++;
*fuse_argv_ptr = realloc(*fuse_argv_ptr, *fuse_argc * sizeof(char *)); *fuse_argv_ptr = realloc(*fuse_argv_ptr, *fuse_argc * sizeof(char *));
char **fuse_argv = *fuse_argv_ptr; char **fuse_argv = *fuse_argv_ptr;
fuse_argv[*fuse_argc - 1] = strndup(opt_string, ARG_LEN_MAX); fuse_argv[*fuse_argc - 1] = strdup(opt_string);
} }
static void print_help(char *program_name, int long_help) static void print_help(char *program_name, int long_help)
@ -253,11 +252,12 @@ static void print_http_options()
https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html\n\ https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html\n\
--proxy-username Username for the proxy\n\ --proxy-username Username for the proxy\n\
--proxy-password Password for the proxy\n\ --proxy-password Password for the proxy\n\
--cache Set the cache folder\n\ --cache Set a cache folder, by default this is disabled\n\
--dl-seg-size Set the size of each download segment in MB, \n\ --dl-seg-size The size of each download segment in MB, \n\
default to 8MB\n\ default to 8MB.\n\
--max-conns The maximum number of network connections that\ --max-conns The maximum number of network connections that\
libcurl is allowed to make.\ libcurl is allowed to make, default to 10.\
--user-agent The user agent string, default to \"HTTPDirFS\".\
\n\ \n\
libfuse options:\n"); libfuse options:\n");
} }

View File

@ -206,6 +206,7 @@ void network_config_init()
NETWORK_CONFIG.proxy_user = NULL; NETWORK_CONFIG.proxy_user = NULL;
NETWORK_CONFIG.proxy_pass = NULL; NETWORK_CONFIG.proxy_pass = NULL;
NETWORK_CONFIG.max_conns = DEFAULT_NETWORK_MAX_CONNS; NETWORK_CONFIG.max_conns = DEFAULT_NETWORK_MAX_CONNS;
NETWORK_CONFIG.user_agent = "HTTPDirFS";
} }
LinkTable *network_init(const char *url) LinkTable *network_init(const char *url)

View File

@ -26,6 +26,7 @@ typedef struct {
char *proxy_user; char *proxy_user;
char *proxy_pass; char *proxy_pass;
long max_conns; long max_conns;
char *user_agent;
} NetworkConfigStruct; } NetworkConfigStruct;
/** \brief CURL configuration */ /** \brief CURL configuration */