Debian Codegraph @

src/config.c

raw symbols SCIP
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 /**
25 * \file config.c
26 * \brief Configuration options parsing implementation
27 */
28
29 #include "config.h"
30
31 #include "log.h"
32 #include "util.h"
33 #include <stddef.h>
34 #include <stdlib.h>
35
36
37 ConfigStruct CONFIG;
38
39 void Config_init(void)
40 {
41 CONFIG.mode = NORMAL;
42
43 CONFIG.log_type = log_level_init();
44
45 /*---------------- Network related --------------*/
46 CONFIG.http_username = NULL;
47
48 CONFIG.http_password = NULL;
49
50 CONFIG.proxy = NULL;
51
52 CONFIG.proxy_username = NULL;
53
54 CONFIG.proxy_password = NULL;
55
56 CONFIG.proxy_cafile = NULL;
57
58 CONFIG.proxy_capath = NULL;
59
60 CONFIG.max_conns = DEFAULT_NETWORK_MAX_CONNS;
61
62 CONFIG.user_agent = DEFAULT_USER_AGENT;
63
64 CONFIG.http_wait_sec = DEFAULT_HTTP_WAIT_SEC;
65
66 CONFIG.http_headers = NULL;
67
68 CONFIG.no_range_check = 0;
69
70 CONFIG.zero_len_is_dir = 0;
71
72 CONFIG.insecure_tls = 0;
73
74 CONFIG.cafile = NULL;
75
76 CONFIG.capath = NULL;
77
78 CONFIG.refresh_timeout = DEFAULT_REFRESH_TIMEOUT;
79
80 CONFIG.invalid_refresh = 0;
81
82 /*--------------- Cache related ---------------*/
83 CONFIG.cache_enabled = 0;
84
85 CONFIG.cache_dir = NULL;
86
87 CONFIG.data_blksz = DEFAULT_DATA_BLKSZ;
88
89 CONFIG.cache_min_size = -1;
90 CONFIG.cache_max_size = -1;
91
92 /*-------------- Sonic related -------------*/
93 CONFIG.sonic_username = NULL;
94
95 CONFIG.sonic_password = NULL;
96
97 CONFIG.sonic_id3 = 0;
98
99 CONFIG.sonic_insecure = 0;
100 atexit(mem_cleanup);
101 }
102
103 void Config_cleanup(void)
104 {
105 FREE(CONFIG.http_username);
106 FREE(CONFIG.http_password);
107 FREE(CONFIG.proxy);
108 FREE(CONFIG.proxy_username);
109 FREE(CONFIG.proxy_password);
110 FREE(CONFIG.proxy_cafile);
111 FREE(CONFIG.proxy_capath);
112 if (CONFIG.user_agent
113 && strcmp(CONFIG.user_agent, DEFAULT_USER_AGENT) != 0) {
114 FREE(CONFIG.user_agent);
115 }
116 FREE(CONFIG.cafile);
117 FREE(CONFIG.capath);
118 FREE(CONFIG.cache_dir);
119 FREE(CONFIG.sonic_username);
120 FREE(CONFIG.sonic_password);
121 }