@@ -138,9 +138,20 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
138138 }
139139}
140140
141+ // A wrapper function that actually takes a bool argument
142+ static int tox_config_lookup_bool (const config_t * config , const char * path , bool * bool_value )
143+ {
144+ int int_value = 0 ;
145+ if (config_lookup_bool (config , path , & int_value ) == CONFIG_FALSE ) {
146+ return CONFIG_FALSE ;
147+ }
148+ * bool_value = int_value != 0 ;
149+ return CONFIG_TRUE ;
150+ }
151+
141152bool get_general_config (const char * cfg_file_path , char * * pid_file_path , char * * keys_file_path , int * port ,
142- int * enable_ipv6 , int * enable_ipv4_fallback , int * enable_lan_discovery , int * enable_tcp_relay ,
143- uint16_t * * tcp_relay_ports , int * tcp_relay_port_count , int * enable_motd , char * * motd )
153+ bool * enable_ipv6 , bool * enable_ipv4_fallback , bool * enable_lan_discovery , bool * enable_tcp_relay ,
154+ uint16_t * * tcp_relay_ports , int * tcp_relay_port_count , bool * enable_motd , char * * motd )
144155{
145156 config_t cfg ;
146157
@@ -207,51 +218,51 @@ bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **
207218 memcpy (* keys_file_path , tmp_keys_file , keys_file_path_len );
208219
209220 // Get IPv6 option
210- if (config_lookup_bool (& cfg , NAME_ENABLE_IPV6 , enable_ipv6 ) == CONFIG_FALSE ) {
221+ if (tox_config_lookup_bool (& cfg , NAME_ENABLE_IPV6 , enable_ipv6 ) == CONFIG_FALSE ) {
211222 log_write (LOG_LEVEL_WARNING , "No '%s' setting in configuration file.\n" , NAME_ENABLE_IPV6 );
212223 log_write (LOG_LEVEL_WARNING , "Using default '%s': %s\n" , NAME_ENABLE_IPV6 , DEFAULT_ENABLE_IPV6 ? "true" : "false" );
213224 * enable_ipv6 = DEFAULT_ENABLE_IPV6 ;
214225 }
215226
216227 // Get IPv4 fallback option
217- if (config_lookup_bool (& cfg , NAME_ENABLE_IPV4_FALLBACK , enable_ipv4_fallback ) == CONFIG_FALSE ) {
228+ if (tox_config_lookup_bool (& cfg , NAME_ENABLE_IPV4_FALLBACK , enable_ipv4_fallback ) == CONFIG_FALSE ) {
218229 log_write (LOG_LEVEL_WARNING , "No '%s' setting in configuration file.\n" , NAME_ENABLE_IPV4_FALLBACK );
219230 log_write (LOG_LEVEL_WARNING , "Using default '%s': %s\n" , NAME_ENABLE_IPV4_FALLBACK ,
220231 DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false" );
221232 * enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK ;
222233 }
223234
224235 // Get LAN discovery option
225- if (config_lookup_bool (& cfg , NAME_ENABLE_LAN_DISCOVERY , enable_lan_discovery ) == CONFIG_FALSE ) {
236+ if (tox_config_lookup_bool (& cfg , NAME_ENABLE_LAN_DISCOVERY , enable_lan_discovery ) == CONFIG_FALSE ) {
226237 log_write (LOG_LEVEL_WARNING , "No '%s' setting in configuration file.\n" , NAME_ENABLE_LAN_DISCOVERY );
227238 log_write (LOG_LEVEL_WARNING , "Using default '%s': %s\n" , NAME_ENABLE_LAN_DISCOVERY ,
228239 DEFAULT_ENABLE_LAN_DISCOVERY ? "true" : "false" );
229240 * enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY ;
230241 }
231242
232243 // Get TCP relay option
233- if (config_lookup_bool (& cfg , NAME_ENABLE_TCP_RELAY , enable_tcp_relay ) == CONFIG_FALSE ) {
244+ if (tox_config_lookup_bool (& cfg , NAME_ENABLE_TCP_RELAY , enable_tcp_relay ) == CONFIG_FALSE ) {
234245 log_write (LOG_LEVEL_WARNING , "No '%s' setting in configuration file.\n" , NAME_ENABLE_TCP_RELAY );
235246 log_write (LOG_LEVEL_WARNING , "Using default '%s': %s\n" , NAME_ENABLE_TCP_RELAY ,
236247 DEFAULT_ENABLE_TCP_RELAY ? "true" : "false" );
237248 * enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY ;
238249 }
239250
240- if (* enable_tcp_relay != 0 ) {
251+ if (* enable_tcp_relay ) {
241252 parse_tcp_relay_ports_config (& cfg , tcp_relay_ports , tcp_relay_port_count );
242253 } else {
243254 * tcp_relay_port_count = 0 ;
244255 }
245256
246257 // Get MOTD option
247- if (config_lookup_bool (& cfg , NAME_ENABLE_MOTD , enable_motd ) == CONFIG_FALSE ) {
258+ if (tox_config_lookup_bool (& cfg , NAME_ENABLE_MOTD , enable_motd ) == CONFIG_FALSE ) {
248259 log_write (LOG_LEVEL_WARNING , "No '%s' setting in configuration file.\n" , NAME_ENABLE_MOTD );
249260 log_write (LOG_LEVEL_WARNING , "Using default '%s': %s\n" , NAME_ENABLE_MOTD ,
250261 DEFAULT_ENABLE_MOTD ? "true" : "false" );
251262 * enable_motd = DEFAULT_ENABLE_MOTD ;
252263 }
253264
254- if (* enable_motd != 0 ) {
265+ if (* enable_motd ) {
255266 // Get MOTD
256267 const char * tmp_motd ;
257268
@@ -273,14 +284,14 @@ bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **
273284 log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_PID_FILE_PATH , * pid_file_path );
274285 log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_KEYS_FILE_PATH , * keys_file_path );
275286 log_write (LOG_LEVEL_INFO , "'%s': %d\n" , NAME_PORT , * port );
276- log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_IPV6 , * enable_ipv6 != 0 ? "true" : "false" );
277- log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_IPV4_FALLBACK , * enable_ipv4_fallback != 0 ? "true" : "false" );
278- log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_LAN_DISCOVERY , * enable_lan_discovery != 0 ? "true" : "false" );
287+ log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_IPV6 , * enable_ipv6 ? "true" : "false" );
288+ log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_IPV4_FALLBACK , * enable_ipv4_fallback ? "true" : "false" );
289+ log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_LAN_DISCOVERY , * enable_lan_discovery ? "true" : "false" );
279290
280- log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_TCP_RELAY , * enable_tcp_relay != 0 ? "true" : "false" );
291+ log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_TCP_RELAY , * enable_tcp_relay ? "true" : "false" );
281292
282293 // Show info about tcp ports only if tcp relay is enabled
283- if (* enable_tcp_relay != 0 ) {
294+ if (* enable_tcp_relay ) {
284295 if (* tcp_relay_port_count == 0 ) {
285296 log_write (LOG_LEVEL_ERROR , "No TCP ports could be read.\n" );
286297 } else {
@@ -292,9 +303,9 @@ bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **
292303 }
293304 }
294305
295- log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_MOTD , * enable_motd != 0 ? "true" : "false" );
306+ log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_ENABLE_MOTD , * enable_motd ? "true" : "false" );
296307
297- if (* enable_motd != 0 ) {
308+ if (* enable_motd ) {
298309 log_write (LOG_LEVEL_INFO , "'%s': %s\n" , NAME_MOTD , * motd );
299310 }
300311
0 commit comments