From 4b0298038089d130e3058840cef533c29c29bfbf Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Mon, 28 Oct 2019 01:45:13 +0000 Subject: [PATCH] Added --config flag, updated CHANGELOG.md --- CHANGELOG.md | 5 ++++ README.md | 69 ++++++++++++++++++++++++++++++--------------------- src/main.c | 45 ++++++++++++++++++++++----------- src/network.c | 4 --- src/sonic.c | 1 - 5 files changed, 77 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a6d2f..6ffc99f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Subsonic server support - this is dedicated to my Debian package maintainer Jerome Charaoui +- You can now specify which configuration file to use by using the ``--config`` +flag. +- Added support for turning off TLS certificate check. +- Now check for server's support for HTTP range request, which can be turned off +using the ``--no-range-check`` flag. ### Changed - Wrapped all calloc() calls with error handling functions. diff --git a/README.md b/README.md index e1340cf..d08f3f5 100644 --- a/README.md +++ b/README.md @@ -73,31 +73,6 @@ FUSE options: -f foreground operation -s disable multi-threaded operation -## Permanent cache system -You can cache all the files you have looked at permanently on your hard drive by -using the ``--cache`` flag. The file it caches persist across sessions. - -By default, the cache files are stored under ``${XDG_CACHE_HOME}/httpdirfs``, -which by default is ``${HOME}/.cache/httpdirfs``. Each HTTP directory gets its -own cache folder, they are named using the escaped URL of the HTTP directory. - -Once a segment of the file has been downloaded once, it won't be downloaded -again. - -Please note that due to the way the permanent cache system is implemented. The -maximum download speed is around 15MiB/s, as measured using my localhost as the -web server. However after you have accessed a file once, accessing it again will -be the same speed as accessing your hard drive. - -If you have any patches to make the initial download go faster, please submit a -pull request. - -The permanent cache system relies on sparse allocation. Please make sure your -filesystem supports it. Otherwise your hard drive / SSD will get heavy I/O from -cache file creation. For a list of filesystem that supports sparse allocation, -please refer to -[Wikipedia](https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies). - ## Airsonic / Subsonic server support This is a new feature to 1.2.0. Now you can mount the music collection on your Airsonic / Subsonic server (*sonic), and browse them using your favourite file browser. @@ -128,11 +103,45 @@ ID3 mode, please use the ``--sonic-id3`` flag. Please note that the cache feature is unaffected by how you mount your *sonic server. If you mounted your server in index mode, the cache is still valid in -ID3 mode, and vice versa. +ID3 mode, and vice versa. + +HTTPDirFS is also known to work with the following applications, which implement +some or all of Subsonic API: + +- [Funkwhale](https://funkwhale.audio/) (requires ``--sonic-id3`` and +``--no-range-check``) +- [LMS](https://github.com/epoupon/lms) (requires ``--sonic-insecure`` and +``--no-range-check``. To mount the [demo instance](https://lms.demo.poupon.io/), +you might also need ``--insecure-tls`` + +## Permanent cache system +You can cache all the files you have looked at permanently on your hard drive by +using the ``--cache`` flag. The file it caches persist across sessions. + +By default, the cache files are stored under ``${XDG_CACHE_HOME}/httpdirfs``, +which by default is ``${HOME}/.cache/httpdirfs``. Each HTTP directory gets its +own cache folder, they are named using the escaped URL of the HTTP directory. + +Once a segment of the file has been downloaded once, it won't be downloaded +again. + +Please note that due to the way the permanent cache system is implemented. The +maximum download speed is around 15MiB/s, as measured using my localhost as the +web server. However after you have accessed a file once, accessing it again will +be the same speed as accessing your hard drive. + +If you have any patches to make the initial download go faster, please submit a +pull request. + +The permanent cache system relies on sparse allocation. Please make sure your +filesystem supports it. Otherwise your hard drive / SSD will get heavy I/O from +cache file creation. For a list of filesystem that supports sparse allocation, +please refer to +[Wikipedia](https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies). ## Configuration file support -This program has basic support for using a configuration file. The configuration -file that the program reads is ``${XDG_CONFIG_HOME}/httpdirfs/config``, which by +This program has basic support for using a configuration file. By default, the configuration file which the program reads is +``${XDG_CONFIG_HOME}/httpdirfs/config``, which by default is at ``${HOME}/.config/httpdirfs/config``. You will have to create the sub-directory and the configuration file yourself. In the configuration file, please supply one option per line. For example: @@ -141,6 +150,9 @@ please supply one option per line. For example: --password test -f +Alternatively, you can specify your own configuration file by using the +``--config`` option. + ## Compilation ### Debian 10 "Buster" and newer versions Under Debian 10 "Buster" and newer versions, you need the following packages: @@ -163,6 +175,7 @@ the header files for OpenSSL 1.1. The header files for OpenSSL 1.0.2 link in additional mutex related callback functions, whereas the header files for OpenSSL 1.1 do not. +You can check your SSL engine version using the ``--version`` flag. ### Debugging Mutexes By default the debugging output associated with mutexes are not compiled. To diff --git a/src/main.c b/src/main.c index f326d4e..154f052 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,8 @@ static int parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc); void parse_config_file(char ***argv, int *argc); +static char *config_path = NULL; + int main(int argc, char **argv) { /* Automatically print help if not enough arguments are supplied */ @@ -41,14 +43,17 @@ int main(int argc, char **argv) /* initialise network subsystem */ NetworkSystem_init(); - /* parse the config file, if it exists, store it in all_argv and all_argc */ - parse_config_file(&all_argv, &all_argc); - /* Copy the command line argument list to the combined argument list */ for (int i = 1; i < argc; i++) { add_arg(&all_argv, &all_argc, argv[i]); + if (!strcmp(argv[i], "--config")) { + config_path = strdup(argv[i+1]); + } } + /* parse the config file, if it exists, store it in all_argv and all_argc */ + parse_config_file(&all_argv, &all_argc); + /* parse the combined argument list */ if (parse_arg_list(all_argc, all_argv, &fuse_argv, &fuse_argc)) { /* @@ -90,13 +95,18 @@ activate Sonic mode.\n"); void parse_config_file(char ***argv, int *argc) { - char *xdg_config_home = getenv("XDG_CONFIG_HOME"); - if (!xdg_config_home) { - char *home = getenv("HOME"); - char *xdg_config_home_default = "/.config"; - xdg_config_home = path_append(home, xdg_config_home_default); + char *full_path; + if (!config_path) { + char *xdg_config_home = getenv("XDG_CONFIG_HOME"); + if (!xdg_config_home) { + char *home = getenv("HOME"); + char *xdg_config_home_default = "/.config"; + xdg_config_home = path_append(home, xdg_config_home_default); + } + full_path = path_append(xdg_config_home, "/httpdirfs/config"); + } else { + full_path = config_path; } - char *full_path = path_append(xdg_config_home, "/httpdirfs/config"); /* The buffer has to be able to fit a URL */ int buf_len = MAX_PATH_LEN; @@ -155,6 +165,7 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) {"no-range-check", no_argument, NULL, 'L'}, /* 18 */ {"sonic-insecure", no_argument, NULL, 'L'}, /* 19 */ {"insecure-tls", no_argument, NULL, 'L'}, /* 20 */ + {"config", required_argument, NULL, 'L'}, /* 21 */ {0, 0, 0, 0} }; while ((c = @@ -240,6 +251,9 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) case 20: CONFIG.insecure_tls = 1; break; + case 21: + /* This is for --config, we don't need to do anything */ + break; default: fprintf(stderr, "see httpdirfs -h for usage\n"); return 1; @@ -276,8 +290,10 @@ static void print_help(char *program_name, int long_help) static void print_version() { - fprintf(stderr, - "HTTPDirFS version " VERSION "\n"); + fprintf(stderr, "HTTPDirFS version " VERSION "\n"); + /* --------- Print off SSL engine version --------- */ + curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); + fprintf(stderr, "libcurl SSL engine: %s\n", data->ssl_version); } static void print_long_help() @@ -285,9 +301,10 @@ static void print_long_help() fprintf(stderr, "\n\ general options:\n\ - -o opt,[opt...] mount options\n\ - -h --help print help\n\ - -V --version print version\n\ + --config Specify a configuration file \n\ + -o opt,[opt...] Mount options\n\ + -h --help Print help\n\ + -V --version Print version\n\ \n\ HTTPDirFS options:\n\ -u --username HTTP authentication username\n\ diff --git a/src/network.c b/src/network.c index b84bc74..51762d0 100644 --- a/src/network.c +++ b/src/network.c @@ -276,10 +276,6 @@ void NetworkSystem_init(void) * https://curl.haxx.se/libcurl/c/threaded-ssl.html */ crypto_lock_init(); - - /* --------- Print off SSL engine version stream --------- */ - curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); - fprintf(stderr, "libcurl SSL engine: %s\n", data->ssl_version); } void transfer_blocking(CURL *curl) diff --git a/src/sonic.c b/src/sonic.c index db882ad..5b5f5b3 100644 --- a/src/sonic.c +++ b/src/sonic.c @@ -298,7 +298,6 @@ LinkTable *sonic_LinkTable_new_index(const char *id) } else { url = sonic_gen_url_first_part("getIndexes"); } - puts(url); LinkTable *linktbl = sonic_url_to_LinkTable(url, XML_parser_index, 0); free(url); return linktbl;