X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=06c979dbab94eb13a2d5663c831d55e3b0a965d5;hb=fef3094bcfb4fae0b7409bb5270ec260b1c6ddee;hp=4bdfb9e25918f52dbee7becb0843162fba0c7d2a;hpb=b309ccfdfd4593f3aecbdf1dafaed2f2c9d4a779;p=dockapps%2Fwmnotify.git diff --git a/src/configfile.c b/src/configfile.c index 4bdfb9e..06c979d 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -10,6 +10,7 @@ #include #include #include +#include #if STDC_HEADERS # include @@ -120,19 +121,19 @@ ParseCommand( char *line, /*@out@*/ char *argv[] ) static char * -GetArguments( char *parameter, int number_of_arguments ) +GetArguments( char *parameter, bool single_argument ) { char *token; - if( number_of_arguments > 1 ) { + if( single_argument ) { + token = strtok( NULL, delimiter_single_arg ); + } + else { /* We search for a string terminated by either a '#' character (the rest of the line is then a comment, which is simply ignored ), or the end of line character '\n'. */ token = strtok( NULL, delimiter_multiple_arg ); } - else { - token = strtok( NULL, delimiter_single_arg ); - } if( token == NULL ) { fprintf( stderr, "%s: Missing argument for \"%s\" parameter in " @@ -164,17 +165,17 @@ ParseConfigurationFile( FILE *file ) { char line[LINE_BUFFER_LEN]; char *token; - bool protocol_found = FALSE; - bool server_found = FALSE; - bool username_found = FALSE; - bool password_found = FALSE; + bool protocol_found = false; + bool server_found = false; + bool username_found = false; + bool password_found = false; const char *err_string = NULL; /* Default values for optional parameters. */ wmnotify_infos.port = 110; wmnotify_infos.mail_check_interval = 60; /* 1 minute interval. */ - wmnotify_infos.audible_notification = FALSE; /* Disabled. */ - wmnotify_infos.use_ssl = FALSE; /* Disabled. */ + wmnotify_infos.audible_notification = false; /* Disabled. */ + wmnotify_infos.use_ssl = false; /* Disabled. */ wmnotify_infos.mail_client_argv[0] = NULL; /* No default command. */ wmnotify_infos.audiofile[0] = '\0'; /* No default audio file. */ wmnotify_infos.volume = 100; /* 100% volume. */ @@ -192,11 +193,11 @@ ParseConfigurationFile( FILE *file ) } if( STREQ( token, "protocol" ) ) { - token = GetArguments( "protocol", 1 ); - if( STREQ( token, "POP3" ) == TRUE ) { + token = GetArguments( "protocol", true ); + if( STREQ( token, "POP3" ) == true ) { wmnotify_infos.protocol = POP3_PROTOCOL; } - else if( STREQ( token, "IMAP4" ) == TRUE ) { + else if( STREQ( token, "IMAP4" ) == true ) { wmnotify_infos.protocol = IMAP4_PROTOCOL; } else { @@ -204,18 +205,18 @@ ParseConfigurationFile( FILE *file ) exit( EXIT_FAILURE ); } - protocol_found = TRUE; + protocol_found = true; } else if( STREQ( token, "use_ssl" ) ){ int number; - token = GetArguments( "use_ssl", 1 ); + token = GetArguments( "use_ssl", true ); number = GetNumber( token, "use_ssl" ); if( number == 0 ) { - wmnotify_infos.use_ssl = FALSE; + wmnotify_infos.use_ssl = false; } else if( number == 1 ) { - wmnotify_infos.use_ssl = TRUE; + wmnotify_infos.use_ssl = true; } else { fprintf( stderr, "%s: Invalid value for for parameter 'enablebeep' in\n" \ @@ -224,29 +225,29 @@ ParseConfigurationFile( FILE *file ) } } else if( STREQ( token, "server" ) ) { - token = GetArguments( "server", 1 ); + token = GetArguments( "server", true ); strncpy( wmnotify_infos.server_name, token, MAX_STR_LEN ); - server_found = TRUE; + server_found = true; } else if( STREQ( token, "port" ) ) { - token = GetArguments( "port", 1 ); + token = GetArguments( "port", true ); wmnotify_infos.port = (u_int16_t) GetNumber( token, "port" ); } else if( STREQ( token, "username" ) ) { - token = GetArguments( "username", 1 ); + token = GetArguments( "username", true ); strncpy( wmnotify_infos.username, token, MAX_STR_LEN ); - username_found = TRUE; + username_found = true; } else if( STREQ( token, "password" ) ) { - token = GetArguments( "password", 1 ); + token = GetArguments( "password", true ); strncpy( wmnotify_infos.password, token, MAX_STR_LEN ); - password_found = TRUE; + password_found = true; } else if( STREQ( token, "mailcheckdelay" ) ) { int delay; /* delay in minutes. */ - token = GetArguments( "mailcheckdelay", 1 ); + token = GetArguments( "mailcheckdelay", true ); /* GetNumber() will exit if a negative number is entered. */ delay = GetNumber( token, "mailcheckdelay" ); if( delay == 0 ) { @@ -257,7 +258,7 @@ ParseConfigurationFile( FILE *file ) wmnotify_infos.mail_check_interval = (unsigned int) delay * 60; } else if( STREQ( token, "mailclient" ) ) { - token = GetArguments( "mailclient", 2 ); /* Multiple arguments */ + token = GetArguments( "mailclient", false ); /* Multiple arguments */ strcpy( wmnotify_infos.mail_client_command, token ); ParseCommand( wmnotify_infos.mail_client_command, wmnotify_infos.mail_client_argv ); @@ -265,13 +266,13 @@ ParseConfigurationFile( FILE *file ) else if( STREQ( token, "enablebeep" ) ){ int number; - token = GetArguments( "enablebeep", 1 ); + token = GetArguments( "enablebeep", true ); number = GetNumber( token, "enablebeep" ); if( number == 0 ) { - wmnotify_infos.audible_notification = FALSE; + wmnotify_infos.audible_notification = false; } else if( number == 1 ) { - wmnotify_infos.audible_notification = TRUE; + wmnotify_infos.audible_notification = true; } else { fprintf( stderr, "%s: Invalid value for for parameter 'enablebeep' in\n" \ @@ -280,12 +281,12 @@ ParseConfigurationFile( FILE *file ) } } else if( STREQ( token, "audiofile" ) ) { - token = GetArguments( "audiofile", 1 ); + token = GetArguments( "audiofile", true ); /* Should check size before using strcpy(), or use strncopy() instead. */ strcpy( wmnotify_infos.audiofile, token ); } else if( STREQ( token, "volume" ) ) { - token = GetArguments( "volume", 1 ); + token = GetArguments( "volume", true ); wmnotify_infos.volume = GetNumber( token, "volume" ); } else { @@ -302,16 +303,16 @@ ParseConfigurationFile( FILE *file ) } } - if( protocol_found == FALSE ) { + if( protocol_found == false ) { err_string = "protocol"; } - else if( server_found == FALSE ) { + else if( server_found == false ) { err_string = "server"; } - else if( username_found == FALSE ) { + else if( username_found == false ) { err_string = "username"; } - else if( password_found == FALSE ) { + else if( password_found == false ) { err_string = "password"; } else {