- char line[LINE_BUFFER_LEN];
- char *token;
- 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.mail_client_argv[0] = NULL; /* No default command. */
- wmnotify_infos.audiofile[0] = '\0'; /* No default audio file. */
- wmnotify_infos.volume = 100; /* 100% volume. */
-
- /* Reading one line of data from the configuration file. */
- /* char *fgets(char *s, int size, FILE *stream);
- Reading stops after an EOF or a newline. If a newline is read, it is
- stored into the buffer. A '\0' is stored after the last character in
- the buffer. */
- while( fgets( line, LINE_BUFFER_LEN, file ) != NULL ) {
- token = strtok( line, delimiter_single_arg );
-
- if( ( token == NULL ) || ( token[0] == '#' ) ) {
- continue; /* Next iteration of the while() loop (next line). */
- }
-
- if( STREQ( token, "protocol" ) ) {
- token = GetArguments( "protocol", 1 );
- if( STREQ( token, "POP3" ) == TRUE ) {
- wmnotify_infos.protocol = POP3_PROTOCOL;
- }
- else if( STREQ( token, "IMAP4" ) == TRUE ) {
- wmnotify_infos.protocol = IMAP4_PROTOCOL;
- }
- else {
- fprintf( stderr, "%s: protocol must be POP3 or IMAP4.\n", PACKAGE );
- exit( EXIT_FAILURE );
- }
-
- protocol_found = TRUE;
- }
- else if( STREQ( token, "use_ssl" ) ){
- int number;
-
- token = GetArguments( "use_ssl", 1 );
- number = GetNumber( token, "use_ssl" );
- if( number == 0 ) {
- wmnotify_infos.use_ssl = FALSE;
- }
- else if( number == 1 ) {
- wmnotify_infos.use_ssl = TRUE;
- }
- else {
- fprintf( stderr, "%s: Invalid value for for parameter 'enablebeep' in\n" \
- "configuration file (must be 0 or 1): %d\n", PACKAGE, number );
- exit( EXIT_FAILURE );
- }
- }
- else if( STREQ( token, "server" ) ) {
- token = GetArguments( "server", 1 );
- strncpy( wmnotify_infos.server_name, token, MAX_STR_LEN );
- server_found = TRUE;
- }
- else if( STREQ( token, "port" ) ) {
- token = GetArguments( "port", 1 );
- wmnotify_infos.port = (u_int16_t) GetNumber( token, "port" );
- }
-
- else if( STREQ( token, "username" ) ) {
- token = GetArguments( "username", 1 );
- strncpy( wmnotify_infos.username, token, MAX_STR_LEN );
- username_found = TRUE;
- }
- else if( STREQ( token, "password" ) ) {
- token = GetArguments( "password", 1 );
- strncpy( wmnotify_infos.password, token, MAX_STR_LEN );
- password_found = TRUE;
- }
- else if( STREQ( token, "mailcheckdelay" ) ) {
- int delay; /* delay in minutes. */
-
- token = GetArguments( "mailcheckdelay", 1 );
- /* GetNumber() will exit if a negative number is entered. */
- delay = GetNumber( token, "mailcheckdelay" );
- if( delay == 0 ) {
- fprintf( stderr, "%s: Mail check interval must be greater than '0'\n",
- PACKAGE );
- exit( EXIT_FAILURE );
- }
- wmnotify_infos.mail_check_interval = (unsigned int) delay * 60;
- }
- else if( STREQ( token, "mailclient" ) ) {
- token = GetArguments( "mailclient", 2 ); /* Multiple arguments */
- strcpy( wmnotify_infos.mail_client_command, token );
- ParseCommand( wmnotify_infos.mail_client_command,
- wmnotify_infos.mail_client_argv );
- }
- else if( STREQ( token, "enablebeep" ) ){
- int number;
-
- token = GetArguments( "enablebeep", 1 );
- number = GetNumber( token, "enablebeep" );
- if( number == 0 ) {
- wmnotify_infos.audible_notification = FALSE;
- }
- else if( number == 1 ) {
- wmnotify_infos.audible_notification = TRUE;
- }
- else {
- fprintf( stderr, "%s: Invalid value for for parameter 'enablebeep' in\n" \
- "configuration file (must be 0 or 1): %d\n", PACKAGE, number );
- exit( EXIT_FAILURE );
- }
- }
- else if( STREQ( token, "audiofile" ) ) {
- token = GetArguments( "audiofile", 1 );
- /* Should check size before using strcpy(), or use strncopy() instead. */
- strcpy( wmnotify_infos.audiofile, token );
- }
- else if( STREQ( token, "volume" ) ) {
- token = GetArguments( "volume", 1 );
- wmnotify_infos.volume = GetNumber( token, "volume" );
- }
- else {
- fprintf( stderr, "%s: invalid parameter in configuration file: %s\n", PACKAGE,
- token );
- exit( EXIT_FAILURE );
- }
-
- token = strtok( NULL, delimiter_single_arg );
- if( ( token != NULL ) && ( token[0] != '#' ) ) {
- fprintf( stderr, "%s: Garbage at end of line in configuration file: %s\n", PACKAGE,
- token );
- exit( EXIT_FAILURE );
- }
- }
-
- if( protocol_found == FALSE ) {
- err_string = "protocol";
- }
- else if( server_found == FALSE ) {
- err_string = "server";
- }
- else if( username_found == FALSE ) {
- err_string = "username";
- }
- else if( password_found == FALSE ) {
- err_string = "password";
- }
- else {
- return; /* success */
- }
-
- /* Failure. */
- fprintf( stderr, "%s: Mandatory parameter \"%s\" missing from configuration "
- "file.\n", PACKAGE, err_string );
- exit( EXIT_FAILURE );
+ char line[LINE_BUFFER_LEN];
+ char *token;
+ 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. */
+ strcpy(wmnotify_infos.imap_folder, "INBOX"); /* Default IMAP folder. */
+ 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.mail_client_argv[0] = NULL; /* No default command. */
+ wmnotify_infos.audiofile[0] = '\0'; /* No default audio file. */
+ wmnotify_infos.volume = 100; /* 100% volume. */
+
+ /*
+ * Reading one line of data from the configuration file.
+ * char *fgets(char *s, int size, FILE *stream);
+ * Reading stops after an EOF or a newline. If a newline is read, it is
+ * stored into the buffer. A '\0' is stored after the last character
+ * in the buffer.
+ */
+ while (fgets(line, LINE_BUFFER_LEN, file) != NULL) {
+ token = strtok(line, delimiter_single_arg);
+
+ if ((token == NULL) || (token[0] == '#')) {
+ continue; /*
+ * Next iteration of the while() loop (next
+ * line).
+ */
+ }
+
+ if (STREQ(token, "protocol")) {
+ token = GetArguments("protocol", true);
+ if (STREQ(token, "POP3") == true) {
+ wmnotify_infos.protocol = POP3_PROTOCOL;
+ } else if (STREQ(token, "IMAP4") == true) {
+ wmnotify_infos.protocol = IMAP4_PROTOCOL;
+ } else {
+ fprintf(stderr,
+ "%s: protocol must be POP3 or IMAP4.\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+
+ protocol_found = true;
+ } else if (STREQ(token, "imap_folder")) {
+ token = GetArguments("imap_folder", true);
+ /*
+ * Should check size before using strcpy(), or use
+ * strncopy() instead.
+ */
+ strcpy(wmnotify_infos.imap_folder, token);
+ } else if (STREQ(token, "use_ssl")) {
+ int number;
+
+ token = GetArguments("use_ssl", true);
+ number = GetNumber(token, "use_ssl");
+ if (number == 0) {
+ wmnotify_infos.use_ssl = false;
+ } else if (number == 1) {
+#if HAVE_SSL
+ wmnotify_infos.use_ssl = true;
+#else
+ fprintf(stderr,
+ "%s error: You must compile %s with SSL support to\n"
+ "set parameter 'use_ssl' to true in configuration file\n",
+ PACKAGE, PACKAGE);
+ exit(EXIT_FAILURE);
+#endif
+ } else {
+ fprintf(stderr,
+ "%s: Invalid value for parameter 'use_ssl' in\n"
+ "configuration file (must be 0 or 1): %d\n",
+ PACKAGE, number);
+ exit(EXIT_FAILURE);
+ }
+ } else if (STREQ(token, "server")) {
+ token = GetArguments("server", true);
+ strncpy(wmnotify_infos.server_name, token,
+ MAX_STR_LEN);
+ server_found = true;
+ } else if (STREQ(token, "port")) {
+ token = GetArguments("port", true);
+ wmnotify_infos.port =
+ (u_int16_t) GetNumber(token, "port");
+ }
+
+ else if (STREQ(token, "username")) {
+ token = GetArguments("username", true);
+ strncpy(wmnotify_infos.username, token,
+ MAX_STR_LEN);
+ username_found = true;
+ } else if (STREQ(token, "password")) {
+ token = GetArguments("password", true);
+ strncpy(wmnotify_infos.password, token,
+ MAX_STR_LEN);
+ password_found = true;
+ } else if (STREQ(token, "mailcheckdelay")) {
+ int delay; /* delay in minutes. */
+
+ token = GetArguments("mailcheckdelay", true);
+ /*
+ * GetNumber() will exit if a negative number is
+ * entered.
+ */
+ delay = GetNumber(token, "mailcheckdelay");
+ if (delay == 0) {
+ fprintf(stderr,
+ "%s: Mail check interval must be greater than '0'\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ wmnotify_infos.mail_check_interval =
+ (unsigned int)delay * 60;
+ } else if (STREQ(token, "mailclient")) {
+ /* Multiple arguments */
+ token = GetArguments("mailclient", false);
+ strcpy(wmnotify_infos.mail_client_command, token);
+ ParseCommand(wmnotify_infos.mail_client_command,
+ wmnotify_infos.mail_client_argv);
+ } else if (STREQ(token, "enablebeep")) {
+ int number;
+
+ token = GetArguments("enablebeep", true);
+ number = GetNumber(token, "enablebeep");
+ if (number == 0) {
+ wmnotify_infos.audible_notification =
+ false;
+ } else if (number == 1) {
+ wmnotify_infos.audible_notification = true;
+ } else {
+ fprintf(stderr,
+ "%s: Invalid value for for parameter 'enablebeep' in\n"
+ "configuration file (must be 0 or 1): %d\n",
+ PACKAGE, number);
+ exit(EXIT_FAILURE);
+ }
+ } else if (STREQ(token, "audiofile")) {
+ 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", true);
+ wmnotify_infos.volume = GetNumber(token, "volume");
+ } else {
+ fprintf(stderr,
+ "%s: invalid parameter in configuration file: %s\n",
+ PACKAGE, token);
+ exit(EXIT_FAILURE);
+ }
+
+ token = strtok(NULL, delimiter_single_arg);
+ if ((token != NULL) && (token[0] != '#')) {
+ fprintf(stderr,
+ "%s: Garbage at end of line in configuration file: %s\n",
+ PACKAGE, token);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (protocol_found == false)
+ err_string = "protocol";
+ else if (server_found == false)
+ err_string = "server";
+ else if (username_found == false)
+ err_string = "username";
+ else if (password_found == false)
+ err_string = "password";
+ else
+ return; /* success */
+
+ /* Failure. */
+ fprintf(stderr,
+ "%s: Mandatory parameter \"%s\" missing from configuration "
+ "file.\n", PACKAGE, err_string);
+ exit(EXIT_FAILURE);