Updated GetArguments() to explicitely indicate that it can extract a single argument or a full line, but not in-between
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <errno.h>
#if STDC_HEADERS
# define EXIT_FAILURE 1
#endif
-typedef int bool;
-#ifndef FALSE
-# define FALSE 0
-# define TRUE 1
-#endif
-
-
/* Returns TRUE if the strings 'a' and 'b' are equal. */
#define STREQ(a, b) (strcmp((a), (b)) == 0)
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
+#include <stdbool.h>
#if STDC_HEADERS
# include <string.h>
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 "
{
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. */
}
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 {
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" \
}
}
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 ) {
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 );
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" \
}
}
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 {
}
}
- 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 {
color.pixel = 0;
res = (bool) XParseColor( dockapp.display, attributes.colormap, name,
&color );
- if( res == FALSE ) {
+ if( res == false ) {
fprintf( stderr, "%s: Can't parse %s.\n", PACKAGE, name );
ErrorLocation( __FILE__, __LINE__ );
exit( EXIT_FAILURE );
}
res = (bool) XAllocColor( dockapp.display, attributes.colormap, &color );
- if( res == FALSE ) {
+ if( res == false ) {
fprintf( stderr, "%s: Can't allocate %s.\n", PACKAGE, name );
ErrorLocation( __FILE__, __LINE__ );
exit( EXIT_FAILURE );
flush_expose( Window win )
{
XEvent dummy;
- bool res = TRUE;
+ bool res = true;
- while( res != FALSE ) {
+ while( res != false ) {
res = (bool) XCheckTypedWindowEvent( dockapp.display, win, Expose, &dummy );
}
}
/* We suppose that, if a partial response packet was sent, it is not broken in the middle
of a line (to confirm). Normally, each string is terminated by CRLF. */
- if( STREQ_LEN( &rx_buffer[ len - 2 ], IMAP4_ENDL, 2 ) == FALSE ) {
+ if( STREQ_LEN( &rx_buffer[ len - 2 ], IMAP4_ENDL, 2 ) == false ) {
/* No CRLF found at the end of the buffer --> not handled by wmnotify. */
ErrorLocation( __FILE__, __LINE__ );
fprintf( stderr, "Response buffer doesn't contain CRLF at the end.\n" );
if( token[0] == '*' ) {
/* Untagged response. If there is a space after the SEARCH response, it means
* at least 1 message is unseen. */
- if( STREQ_LEN( token, IMAP4_RSP_SEARCH_UNSEEN, strlen(IMAP4_RSP_SEARCH_UNSEEN) ) == TRUE ) {
- unseen_string_found = TRUE;
+ if( STREQ_LEN( token, IMAP4_RSP_SEARCH_UNSEEN, strlen(IMAP4_RSP_SEARCH_UNSEEN) ) == true ) {
+ unseen_string_found = true;
}
}
else {
/* Must be the status... */
/* We check for the correct transaction label plus a space. */
- if( STREQ_LEN( token, tx_buffer, tlabel_len + 1 ) == TRUE ) {
+ if( STREQ_LEN( token, tx_buffer, tlabel_len + 1 ) == true ) {
token += tlabel_len + 1;
- if( STREQ_LEN( token, IMAP4_RSP_SUCCESS, strlen(IMAP4_RSP_SUCCESS) ) == TRUE ) {
+ if( STREQ_LEN( token, IMAP4_RSP_SUCCESS, strlen(IMAP4_RSP_SUCCESS) ) == true ) {
goto end; /* OK, no errors. */
}
- else if( STREQ_LEN( token, IMAP4_RSP_PROTOCOL_ERR, strlen(IMAP4_RSP_PROTOCOL_ERR) ) == TRUE ) {
+ else if( STREQ_LEN( token, IMAP4_RSP_PROTOCOL_ERR, strlen(IMAP4_RSP_PROTOCOL_ERR) ) == true ) {
fprintf( stderr, "%s: Protocol error (%s).\n", PACKAGE, token );
goto error;
}
- else if( STREQ_LEN( token, IMAP4_RSP_FAILURE, strlen(IMAP4_RSP_FAILURE) ) == TRUE ) {
+ else if( STREQ_LEN( token, IMAP4_RSP_FAILURE, strlen(IMAP4_RSP_FAILURE) ) == true ) {
fprintf( stderr, "%s: Failure (%s).\n", PACKAGE, token );
goto error;
}
* and UNSEEN will have entries. But if we recheck again later, RECENT will report zero.
* RECENT, when set, simply means that there are new messages since our last visit.
But, on the other hand, when using EXAMINE, no messages should lose their RECENT flag. */
- unseen_string_found = FALSE;
+ unseen_string_found = false;
argv[0] = IMAP4_CMD_SEARCH_UNSEEN;
argv[1] = "";
status = IMAP4_SendCommand( 1, argv );
goto imap4_logout;
}
- if( unseen_string_found == TRUE ) {
+ if( unseen_string_found == true ) {
new_messages = 1;
}
}
#if HAVE_SSL
- if( wmnotify_infos.use_ssl == TRUE ) {
+ if( wmnotify_infos.use_ssl == true ) {
int status;
status = InitSSL( wmnotify_infos.sock_fd );
if( status != EXIT_SUCCESS ) {
ConnectionTerminate( void )
{
#if HAVE_SSL
- if( wmnotify_infos.use_ssl == TRUE ) {
+ if( wmnotify_infos.use_ssl == true ) {
SSL_free( ssl_infos.ssl ); /* release connection state */
}
#endif
close( wmnotify_infos.sock_fd ); /* close socket */
#if HAVE_SSL
- if( wmnotify_infos.use_ssl == TRUE ) {
+ if( wmnotify_infos.use_ssl == true ) {
SSL_CTX_free( ssl_infos.ctx ); /* release context */
}
#endif
int len;
#if HAVE_SSL
- if( wmnotify_infos.use_ssl == TRUE ) {
+ if( wmnotify_infos.use_ssl == true ) {
len = SSL_write( ssl_infos.ssl, buffer, size ); /* Encrypt & send message */
if( len <= 0 ) {
SSL_get_error( ssl_infos.ssl, len );
int len;
#if HAVE_SSL
- if( wmnotify_infos.use_ssl == TRUE ) {
+ if( wmnotify_infos.use_ssl == true ) {
len = SSL_read( ssl_infos.ssl, buffer, max_size ); /* Get reply & decrypt. */
switch( SSL_get_error( ssl_infos.ssl, len ) ) {
case SSL_ERROR_NONE:
{
int i;
char *token;
- bool config_file_on = FALSE;
- bool display_on = FALSE;
- bool geometry_on = FALSE;
+ bool config_file_on = false;
+ bool display_on = false;
+ bool geometry_on = false;
/* Default values. */
- wmnotify_infos.debug = FALSE;
+ wmnotify_infos.debug = false;
for( i = 1; i < argc; i++ ) {
token = argv[i];
switch( token[1] ) {
case 'c':
if( strlen( &token[1] ) == 1 ) {
- config_file_on = TRUE;
+ config_file_on = true;
}
else {
InvalidOption( "invalid option", token );
break;
case 'd':
if( STREQ( "display", &token[1] ) ) {
- display_on = TRUE;
+ display_on = true;
}
else if( strlen( &token[1] ) == 1 ) {
- wmnotify_infos.debug = TRUE;
+ wmnotify_infos.debug = true;
}
break;
case 'g':
if( STREQ( "geometry", &token[1] ) ) {
- geometry_on = TRUE;
+ geometry_on = true;
}
else {
InvalidOption( "invalid option", token );
break;
default:
/* Processing options arguments */
- if( config_file_on != FALSE ) {
+ if( config_file_on != false ) {
wmnotify_infos.optional_config_file = token;
/*strcpy( config_file_name, token );*/
- config_file_on = FALSE;
+ config_file_on = false;
}
- else if( display_on != FALSE ) {
- display_on = FALSE;
+ else if( display_on != false ) {
+ display_on = false;
wmnotify_infos.display_arg = token;
}
- else if( geometry_on != FALSE ) {
- geometry_on = FALSE;
+ else if( geometry_on != false ) {
+ geometry_on = false;
wmnotify_infos.geometry_arg = token;
}
else {
} /* end switch( token[0] ) */
} /* end for */
- if( config_file_on != FALSE ) {
+ if( config_file_on != false ) {
InvalidOption( "missing configuration file parameter", NULL );
}
- else if( display_on != FALSE ) {
+ else if( display_on != false ) {
InvalidOption( "missing display parameter", NULL );
}
- else if( geometry_on != FALSE ) {
+ else if( geometry_on != false ) {
InvalidOption( "missing geometry parameter", NULL );
}
}
/* Check the status indicator returned by the POP3 server.
There are currently two status indicators: positive ("+OK") and negative
("-ERR"). Servers MUST send the status indicators in upper case. */
- if( STREQ_LEN( rx_buffer, POP3_RSP_SUCCESS, strlen(POP3_RSP_SUCCESS) ) == FALSE ) {
+ if( STREQ_LEN( rx_buffer, POP3_RSP_SUCCESS, strlen(POP3_RSP_SUCCESS) ) == false ) {
fprintf( stderr, "%s: Error, POP3 server responded:\n \"%s\"\n", PACKAGE, rx_buffer );
len = -1;
}
/* Set in DoubleClick() to stop the new mail animation when the mail client is
opened. */
-static bool animation_stop = FALSE;
+static bool animation_stop = false;
static int animation_image = MAILBOX_FULL;
-/* Set in response to signal sent by SingleClick() to force mail check. Also set to TRUE at
+/* Set in response to signal sent by SingleClick() to force mail check. Also set to true at
* startup to force initial check. */
-static bool manual_check = TRUE;
+static bool manual_check = true;
/* Used to signal TimerThread to quit. Inactive for now. */
-static bool quit = FALSE;
+static bool quit = false;
-static int double_click_notif = FALSE;
+static int double_click_notif = false;
/* TimerThread ID */
static pthread_t timer_thread;
/* Starting external mail client. */
ExecuteCommand( wmnotify_infos.mail_client_argv );
- double_click_notif = TRUE;
+ double_click_notif = true;
/* Sending a signal to awake the TimerThread() thread. This was previously
done with a mutex variable (animation_stop), but this caused a bug when the
displayed.
This was because setting the mutex variable 'animation_stop' didn't
awakened the TimerThread(), but single-clicking awakened it. Since the
- 'animation_stop' variable was still set to TRUE, no animation occured. */
+ 'animation_stop' variable was still set to true, no animation occured. */
status = pthread_kill( timer_thread, SIGUSR2 );
if( status != EXIT_SUCCESS ) {
fprintf( stderr, "%s: pthread_kill() error (%d)\n", PACKAGE, status );
sleep(1);
DisplayClosedMailbox();
- double_click_notif = FALSE;
+ double_click_notif = false;
}
else {
fprintf( stderr, "%s: Warning: No email-client defined.\n", PACKAGE );
switch( signal ) {
case SIGUSR1:
/* Catching the signal sent by the SingleClick() function. */
- manual_check = TRUE;
+ manual_check = true;
break;
case SIGUSR2:
/* Catching the signal sent by the DoubleClick() function. */
- animation_stop = TRUE;
+ animation_stop = true;
break;
default:
fprintf( stderr, "%s: CatchTimerSignal(): unknown signal (%d)\n", PACKAGE,
{
int new_messages;
- if( manual_check == TRUE ) {
+ if( manual_check == true ) {
DisplayOpenedEmptyMailbox();
}
exit( EXIT_FAILURE );
}
- if( ( manual_check == TRUE ) && ( new_messages > 0 ) ) {
+ if( ( manual_check == true ) && ( new_messages > 0 ) ) {
animation_image = MAILBOX_FULL;
}
{
int new_messages = 0;
int counter = -1;
- bool animation_running = FALSE;
+ bool animation_running = false;
/* For catching the signal SIGUSR1. This signal is sent by the main program thread when the
* user is issuing a single-click to manually check for new mails. */
* user is issuing a double-click to start ther external mail client. */
(void) signal( SIGUSR2, CatchTimerSignal );
- while( quit == FALSE ) {
+ while( quit == false ) {
if( wmnotify_infos.debug ) {
printf( "%s: Timer thread iteration.\n", PACKAGE );
}
- if( ( manual_check == TRUE ) || ( counter == 0 ) ) {
+ if( ( manual_check == true ) || ( counter == 0 ) ) {
new_messages = CheckForNewMail( manual_check );
- manual_check = FALSE;
+ manual_check = false;
if( wmnotify_infos.debug ) {
printf( "%s: new messages = %d.\n", PACKAGE, new_messages );
if( new_messages > 0 ) {
/* Checking if audio notification was already produced. */
- if( animation_running == FALSE ) {
+ if( animation_running == false ) {
/* Audible notification, if requested in configuration file. */
- if( wmnotify_infos.audible_notification != FALSE ) {
+ if( wmnotify_infos.audible_notification != false ) {
if( strlen( wmnotify_infos.audiofile ) != 0 ) {
#if defined(HAVE_SNDFILE)
PlayAudioFile( wmnotify_infos.audiofile, wmnotify_infos.volume );
}
}
- animation_running = TRUE;
+ animation_running = true;
}
/* Number of times to execute timer loop before checking again for new mails when the
* animation is running (when the animation is running, we sleep for
}
}
- if( ( animation_stop == TRUE ) || ( new_messages <= 0 ) ) {
+ if( ( animation_stop == true ) || ( new_messages <= 0 ) ) {
if( wmnotify_infos.debug ) {
- if( animation_stop != FALSE ) {
- printf( "%s: animation_stop is TRUE\n", PACKAGE );
+ if( animation_stop != false ) {
+ printf( "%s: animation_stop is true\n", PACKAGE );
}
}
- animation_running = FALSE;
- animation_stop = FALSE;
- if( double_click_notif == FALSE ) {
+ animation_running = false;
+ animation_stop = false;
+ if( double_click_notif == false ) {
/* Before exiting, be sure to put NO MAIL image back in place... */
DisplayClosedMailbox();
}
* return value will be the "unslept" amount (the requested time minus the time actually
* slept) in seconds. */
- if( animation_running == FALSE ) {
+ if( animation_running == false ) {
(void) sleep( wmnotify_infos.mail_check_interval );
counter = 0;
}
printf( "%s: Error, TimerThread() exited abnormally\n", PACKAGE );
}
- /* This code is never reached for now, because quit is always FALSE. */
+ /* This code is never reached for now, because quit is always false. */
pthread_exit( NULL );
}
#define WMNOTIFY_H 1
+
#define POP3_PROTOCOL 0
#define IMAP4_PROTOCOL 1
void
ProcessXlibEvents( void )
{
- bool quit = FALSE;
- bool button1_pressed = FALSE;
- bool check_for_double_click = FALSE;
+ bool quit = false;
+ bool button1_pressed = false;
+ bool check_for_double_click = false;
XEvent Event;
- while( quit == FALSE ) {
- if( ( check_for_double_click != FALSE ) &&
+ while( quit == false ) {
+ if( ( check_for_double_click != false ) &&
( XPending( dockapp.display ) == 0 ) ) {
/* If no other button 1 events are received after the delay, then it is a
single-click mouse event. */
(*SingleClickCallback)();
}
- check_for_double_click = FALSE;
+ check_for_double_click = false;
}
/* XNextEvent is a blocking call: it will return only when an event is
ready to be processed, thus freeing the CPU for other tasks when no
/* Window was killed... */
/* Is this necessary ? */
(void) XCloseDisplay( dockapp.display );
- quit = TRUE;
+ quit = true;
break;
case ClientMessage:
/* Doesn't seem to work... */
case ButtonPress:
if( Event.xbutton.button == Button1 ) {
/* Mouse LEFT button pressed. */
- button1_pressed = TRUE;
+ button1_pressed = true;
}
break;
case ButtonRelease:
if( Event.xbutton.button == Button1 ) {
/* Mouse LEFT button released. */
- if( button1_pressed != FALSE ) {
+ if( button1_pressed != false ) {
/* We act only when the button is released */
- if( check_for_double_click != FALSE ) {
+ if( check_for_double_click != false ) {
/* Double-click */
if( DoubleClickCallback != NULL ) {
(*DoubleClickCallback)();
}
- check_for_double_click = FALSE;
+ check_for_double_click = false;
}
else {
(void) usleep( DOUBLE_CLICK_MAX_INTERVAL_MS * 1000 );
- check_for_double_click = TRUE;
+ check_for_double_click = true;
}
}
}