| 1 | /* |
| 2 | * HTTPDirFS - HTTP Directory Filesystem |
| 3 | * |
| 4 | * Copyright (C) 2020-2026 Fufu Fang <[email protected]> |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * In addition, as a special exception, the copyright holders give |
| 20 | * permission to link the code of portions of this program with the OpenSSL |
| 21 | * library. |
| 22 | */ |
| 23 | |
| 24 | #ifndef CONFIG_H |
| 25 | #define CONFIG_H |
| 26 | /** |
| 27 | * \file config.h |
| 28 | * \brief Configuration options and defaults header |
| 29 | */ |
| 30 | |
| 31 | #include <limits.h> |
| 32 | #include <sys/types.h> |
| 33 | |
| 34 | /** |
| 35 | * \brief the default user agent string |
| 36 | */ |
| 37 | #define DEFAULT_USER_AGENT "HTTPDirFS-" VERSION |
| 38 | |
| 39 | /** |
| 40 | * \brief The default maximum number of network connections |
| 41 | */ |
| 42 | #define DEFAULT_NETWORK_MAX_CONNS 6 |
| 43 | |
| 44 | /** |
| 45 | * \brief The default refresh_timeout |
| 46 | */ |
| 47 | #define DEFAULT_REFRESH_TIMEOUT 3600 |
| 48 | |
| 49 | /** |
| 50 | * \brief The default HTTP 429 (too many requests) wait time |
| 51 | */ |
| 52 | #define DEFAULT_HTTP_WAIT_SEC 5 |
| 53 | |
| 54 | /** |
| 55 | * \brief Data file block size in MB |
| 56 | */ |
| 57 | #define DEFAULT_DATA_BLKSZ_MB 8 |
| 58 | |
| 59 | /** |
| 60 | * \brief Data file block size |
| 61 | * \details We set it to 1024*1024*8 = 8MiB |
| 62 | */ |
| 63 | #define DEFAULT_DATA_BLKSZ (DEFAULT_DATA_BLKSZ_MB * 1024 * 1024) |
| 64 | |
| 65 | #define STR(x) #x |
| 66 | #define XSTR(x) STR(x) |
| 67 | |
| 68 | /** |
| 69 | * \brief Operation modes |
| 70 | */ |
| 71 | typedef enum { |
| 72 | NORMAL = 1, |
| 73 | SONIC = 2, |
| 74 | SINGLE = 3, |
| 75 | } OperationMode; |
| 76 | |
| 77 | typedef struct { |
| 78 | /** \brief Operation Mode */ |
| 79 | OperationMode mode; |
| 80 | /** \brief Current log level */ |
| 81 | int log_type; |
| 82 | /*---------------- Network related --------------*/ |
| 83 | /** \brief HTTP username */ |
| 84 | char *http_username; |
| 85 | /** \brief HTTP password */ |
| 86 | char *http_password; |
| 87 | /** \brief HTTP proxy URL */ |
| 88 | char *proxy; |
| 89 | /** \brief HTTP proxy username */ |
| 90 | char *proxy_username; |
| 91 | /** \brief HTTP proxy password */ |
| 92 | char *proxy_password; |
| 93 | /** \brief HTTP proxy certificate file */ |
| 94 | char *proxy_cafile; |
| 95 | /** \brief HTTP proxy certificate directory */ |
| 96 | char *proxy_capath; |
| 97 | /** \brief HTTP maximum connection count */ |
| 98 | long max_conns; |
| 99 | /** \brief HTTP user agent*/ |
| 100 | char *user_agent; |
| 101 | /** \brief The waiting time after getting HTTP 429 (too many requests) */ |
| 102 | int http_wait_sec; |
| 103 | /** \brief Set HTTP headers */ |
| 104 | struct curl_slist *http_headers; |
| 105 | /** \brief Disable check for the server's support of HTTP range request */ |
| 106 | int no_range_check; |
| 107 | /** \brief Treat zero length file as directory */ |
| 108 | int zero_len_is_dir; |
| 109 | /** \brief Disable TLS certificate verification */ |
| 110 | int insecure_tls; |
| 111 | /** \brief Server certificate file */ |
| 112 | char *cafile; |
| 113 | /** \brief Server certificate directory */ |
| 114 | char *capath; |
| 115 | /** \brief Refresh directory listing after refresh_timeout seconds */ |
| 116 | int refresh_timeout; |
| 117 | /** \brief Try refreshing invalid links when reading a directory */ |
| 118 | int invalid_refresh; |
| 119 | /** \brief Include external (cross-origin) links from directory listings */ |
| 120 | int external_links; |
| 121 | /*--------------- Cache related ---------------*/ |
| 122 | /** \brief Whether cache mode is enabled */ |
| 123 | int cache_enabled; |
| 124 | /** \brief The cache location*/ |
| 125 | char *cache_dir; |
| 126 | /** \brief The size of each download segment for cache mode */ |
| 127 | int data_blksz; |
| 128 | /** \brief The maximum segment count for a single cache file */ |
| 129 | int max_segbc; |
| 130 | /** \brief The minimum file size threshold for caching */ |
| 131 | off_t cache_min_size; |
| 132 | /** \brief The maximum file size threshold for caching */ |
| 133 | off_t cache_max_size; |
| 134 | /*-------------- Sonic related -------------*/ |
| 135 | /** \brief The Sonic server username */ |
| 136 | char *sonic_username; |
| 137 | /** \brief The Sonic server password */ |
| 138 | char *sonic_password; |
| 139 | /** \brief Whether we are using sonic mode ID3 extension */ |
| 140 | int sonic_id3; |
| 141 | /** \brief Whether we use the legacy sonic authentication mode */ |
| 142 | int sonic_insecure; |
| 143 | } ConfigStruct; |
| 144 | |
| 145 | /** |
| 146 | * \brief The Configuration data structure |
| 147 | */ |
| 148 | extern ConfigStruct CONFIG; |
| 149 | |
| 150 | /** |
| 151 | * \brief Free any heap-allocated configuration options |
| 152 | */ |
| 153 | void Config_cleanup(void); |
| 154 | |
| 155 | #endif |