2016-11-28 03:51:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// config.c
|
|
|
|
// configuration file parser, part of wmail
|
|
|
|
//
|
2019-06-12 20:37:14 +00:00
|
|
|
// Copyright 2000-2002, Sven Geisenhainer <sveng@informatik.uni-jena.de>.
|
|
|
|
// Copyright 2016-2017, Doug Torrance <dtorrance@piedmont.edu>.
|
|
|
|
// Copyright 2019, Jeremy Sowden <jeremy@azazel.net>.
|
2016-12-23 23:28:17 +00:00
|
|
|
//
|
2016-11-28 03:51:04 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions
|
|
|
|
// are met:
|
|
|
|
// 1. Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions, and the following disclaimer.
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions, and the following disclaimer in the
|
|
|
|
// documentation and/or other materials provided with the distribution.
|
|
|
|
// 3. The name of the author may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
2016-12-23 23:28:17 +00:00
|
|
|
//
|
2016-11-28 03:51:04 +00:00
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
2019-06-07 08:52:06 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#ifndef CONFIG_H_INCLUDED
|
|
|
|
#include "../config.h"
|
|
|
|
#define CONFIG_H_INCLUDED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-06-07 08:52:12 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2016-11-28 03:51:04 +00:00
|
|
|
#include <limits.h>
|
2019-06-07 08:52:06 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// wmailrc file format
|
2016-12-23 23:28:17 +00:00
|
|
|
//
|
2016-11-28 03:51:04 +00:00
|
|
|
// # - comment-lines
|
|
|
|
// Window.Display = "string"
|
|
|
|
// Window.NonShaped = On|Off
|
|
|
|
// Window.Button.Command = "string"
|
|
|
|
// Mail.MailBox = "string"
|
|
|
|
// Mail.ChecksumFile = "string"
|
2019-06-21 10:50:27 +00:00
|
|
|
// Mail.CheckInterval = number
|
2016-11-28 03:51:04 +00:00
|
|
|
// Mail.ShowOnlyNew = On|Off
|
|
|
|
// Mail.SkipSender = "string"
|
|
|
|
// Mail.OnNew.Command = "string"
|
|
|
|
// Mail.UseStatusField = On|Off
|
|
|
|
// Ticker.Mode = Address|NickName|FamilyName
|
|
|
|
// Ticker.Frames = number
|
|
|
|
// Ticker.BoldFont = On|Off
|
|
|
|
// Ticker.X11Font = "string"
|
|
|
|
// Colors.Symbols = "string"
|
|
|
|
// Colors.Font = "string"
|
|
|
|
// Colors.Backlight = "string"
|
|
|
|
// Colors.OffLight = "string"
|
|
|
|
// Colors.NonShapedFrame = "string"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// typedefs
|
|
|
|
|
|
|
|
|
|
|
|
// list of enum-identifiers and their associated values
|
|
|
|
typedef struct { char *id; int value; } enumList_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// local prototypes
|
|
|
|
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool ReadString( const char *from, unsigned int line, char **to );
|
|
|
|
static bool ReadEnum( const char *from, unsigned int line, int *to,
|
|
|
|
const enumList_t *enumList );
|
|
|
|
static bool ReadBool( const char *from, unsigned int line, bool *to );
|
|
|
|
static bool ReadInt( const char *from, unsigned int line, int *to );
|
|
|
|
static bool IsWhiteSpace( const char *chr );
|
|
|
|
static const char *SkipWhiteSpaces( const char *str );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
|
|
|
// current configuration
|
|
|
|
config_t config = {
|
2019-06-07 08:52:13 +00:00
|
|
|
.checkInterval = WMAIL_CHECK_INTERVAL,
|
|
|
|
.fps = WMAIL_FPS,
|
|
|
|
.tickerMode = TICKER_ADDRESS
|
2016-11-28 03:51:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// enumeration names for ticker mode
|
2019-05-27 21:52:15 +00:00
|
|
|
static enumList_t tickerEnum[] =
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
|
|
|
{ "address", TICKER_ADDRESS },
|
|
|
|
{ "familyname", TICKER_FAMILYNAME },
|
|
|
|
{ "nickname", TICKER_NICKNAME },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool Tokenize( const char *line, const char **id, const char **value )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-06-07 08:52:07 +00:00
|
|
|
size_t len;
|
2016-11-28 03:51:04 +00:00
|
|
|
const char *token1, *token2;
|
|
|
|
|
|
|
|
if( line != NULL )
|
2019-05-27 21:52:05 +00:00
|
|
|
{
|
|
|
|
token1 = SkipWhiteSpaces( line );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-05-27 21:52:05 +00:00
|
|
|
if(( len = strlen( token1 )) != 0 && token1[0] != '#' )
|
|
|
|
{
|
|
|
|
token2 = strchr( token1, '=' );
|
|
|
|
if( token2 != NULL )
|
2019-06-21 10:50:32 +00:00
|
|
|
{
|
2019-06-21 10:50:29 +00:00
|
|
|
token2 = SkipWhiteSpaces( token2 + 1 );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:32 +00:00
|
|
|
if( !IsWhiteSpace( token2 ))
|
|
|
|
{
|
|
|
|
*id = token1;
|
|
|
|
*value = token2;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2019-06-21 10:50:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-27 21:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-12 20:37:23 +00:00
|
|
|
static void AddSenderToSkipList( char *sender )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-06-12 20:37:23 +00:00
|
|
|
size_t numNames;
|
2016-11-28 03:51:04 +00:00
|
|
|
char **skipName, **newList;
|
|
|
|
|
|
|
|
for( skipName = config.skipNames, numNames = 0;
|
2019-05-27 21:52:05 +00:00
|
|
|
skipName != NULL && *skipName != NULL; skipName++ )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
if( !strcmp( *skipName, sender ))
|
|
|
|
return;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2019-05-27 21:52:05 +00:00
|
|
|
numNames++;
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "adding \"%s\" to skip-list of currently %d names\n", sender, numNames );
|
2019-06-12 20:37:23 +00:00
|
|
|
newList = realloc( config.skipNames, sizeof *config.skipNames * (numNames + 2) );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-12 20:37:23 +00:00
|
|
|
if( newList == NULL )
|
|
|
|
{
|
|
|
|
WARNING( "Cannot allocate memory for skip list.\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
|
|
|
config.skipNames = newList;
|
2019-06-12 20:37:23 +00:00
|
|
|
config.skipNames[numNames++] = sender;
|
|
|
|
config.skipNames[numNames++] = NULL;
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:10 +00:00
|
|
|
void ResetConfigStrings( void )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_MAILBOX ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.mailBox );
|
|
|
|
config.mailBox = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_RUNCMD ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.runCmd );
|
|
|
|
config.runCmd = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_SYMBOLCOLOR ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.symbolColor );
|
|
|
|
config.symbolColor = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_FONTCOLOR ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.fontColor );
|
|
|
|
config.fontColor = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_BACKCOLOR ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.backColor );
|
|
|
|
config.backColor = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_OFFLIGHTCOLOR ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.offlightColor );
|
|
|
|
config.offlightColor = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_BACKGROUNDCOLOR ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.backgroundColor );
|
|
|
|
config.backgroundColor = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-12 20:37:22 +00:00
|
|
|
/*
|
|
|
|
* No corresponding command-line option.
|
|
|
|
*/
|
|
|
|
free( config.checksumFileName );
|
|
|
|
config.checksumFileName = NULL;
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_CMDONMAIL ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.cmdOnMail );
|
|
|
|
config.cmdOnMail = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !( config.givenOptions & CL_USEX11FONT ))
|
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
free( config.useX11Font );
|
|
|
|
config.useX11Font = NULL;
|
|
|
|
}
|
2019-06-12 20:37:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* No corresponding command-line option.
|
|
|
|
*/
|
|
|
|
if( config.skipNames != NULL )
|
|
|
|
{
|
|
|
|
char **n;
|
|
|
|
for( n = config.skipNames; *n; ++n )
|
|
|
|
free( *n );
|
|
|
|
free( config.skipNames );
|
|
|
|
config.skipNames = NULL;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static void PostProcessConfiguration( void )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
|
|
|
if( config.display == NULL )
|
2019-05-27 21:52:05 +00:00
|
|
|
config.display = strdup( WMAIL_DISPLAY );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-05-27 21:52:05 +00:00
|
|
|
if( config.runCmd == NULL )
|
|
|
|
config.runCmd = strdup( WMAIL_CLIENT_CMD );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-05-27 21:52:05 +00:00
|
|
|
if( config.mailBox == NULL )
|
|
|
|
{
|
|
|
|
char *envMBox = getenv( "MAIL" );
|
|
|
|
if( envMBox != NULL )
|
|
|
|
config.mailBox = strdup( envMBox );
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 20:37:21 +00:00
|
|
|
void ReadConfigFile( const char *configFile, bool resetConfigStrings )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-05-27 21:52:05 +00:00
|
|
|
// free all config strings and reset their pointers if required
|
|
|
|
if( resetConfigStrings )
|
|
|
|
ResetConfigStrings();
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2019-06-12 20:37:21 +00:00
|
|
|
FILE *f = fopen( configFile, "r" );
|
|
|
|
if( f != NULL )
|
2019-05-27 21:52:05 +00:00
|
|
|
{
|
2019-06-12 20:37:21 +00:00
|
|
|
char buf[1024];
|
|
|
|
int line = 1;
|
|
|
|
|
|
|
|
for( ; !feof( f ); ++line )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-06-12 20:37:21 +00:00
|
|
|
const char *id, *value;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if( fgets( buf, sizeof buf, f ) == NULL )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// first eliminate the trailing whitespaces
|
2019-06-21 10:50:29 +00:00
|
|
|
for( len = strlen( buf ); len > 0 && IsWhiteSpace(buf + (--len)); )
|
|
|
|
*(buf + len) = '\0';
|
2019-06-12 20:37:21 +00:00
|
|
|
|
|
|
|
if( !Tokenize( buf, &id, &value ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Window.Display", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_DISPLAY ))
|
|
|
|
ReadString( value, line, &config.display );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Window.NonShaped", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_NOSHAPE ))
|
|
|
|
ReadBool( value, line, &config.noshape );
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-27 21:52:05 +00:00
|
|
|
|
2019-06-12 20:37:21 +00:00
|
|
|
if( PREFIX_MATCHES( id, "Window.Button.Command", false ))
|
2019-05-27 21:52:05 +00:00
|
|
|
{
|
2019-06-12 20:37:21 +00:00
|
|
|
if( !( config.givenOptions & CL_RUNCMD ))
|
|
|
|
ReadString( value, line, &config.runCmd );
|
|
|
|
continue;
|
2019-05-27 21:52:05 +00:00
|
|
|
}
|
2019-05-27 21:52:08 +00:00
|
|
|
|
2019-06-12 20:37:21 +00:00
|
|
|
if( PREFIX_MATCHES( id, "Mail.MailBox", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_MAILBOX ))
|
|
|
|
ReadString( value, line, &config.mailBox );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Mail.ChecksumFile", false ))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No corresponding command-line option.
|
|
|
|
*/
|
|
|
|
ReadString( value, line, &config.checksumFileName );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:50:27 +00:00
|
|
|
if( PREFIX_MATCHES( id, "Mail.CheckInterval", false ))
|
2019-06-12 20:37:21 +00:00
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_CHECKINTERVAL ))
|
|
|
|
ReadInt( value, line, &config.checkInterval );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Mail.ShowOnlyNew", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_NEWMAILONLY ))
|
|
|
|
ReadBool( value, line, &config.newMailsOnly );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Ticker.Mode", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_TICKERMODE ))
|
|
|
|
ReadEnum( value, line, (int *)&config.tickerMode, tickerEnum );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Ticker.Frames", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_FPS ))
|
|
|
|
ReadInt( value, line, &config.fps );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Colors.Symbols", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_SYMBOLCOLOR ))
|
|
|
|
ReadString( value, line, &config.symbolColor );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Colors.Font", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_FONTCOLOR ))
|
|
|
|
ReadString( value, line, &config.fontColor );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Colors.Backlight", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_BACKCOLOR ))
|
|
|
|
ReadString( value, line, &config.backColor );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Colors.OffLight", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_OFFLIGHTCOLOR ))
|
|
|
|
ReadString( value, line, &config.offlightColor );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Colors.NonShapedFrame", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_NOSHAPE ))
|
|
|
|
ReadString( value, line, &config.backgroundColor );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Ticker.X11Font", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_USEX11FONT ))
|
|
|
|
ReadString( value, line, &config.useX11Font );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Mail.SkipSender", false ))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No corresponding command-line option.
|
|
|
|
*/
|
|
|
|
char *skip;
|
|
|
|
if( ReadString( value, line, &skip ))
|
|
|
|
AddSenderToSkipList( skip );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Mail.OnNew.Command", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_CMDONMAIL ))
|
|
|
|
ReadString( value, line, &config.cmdOnMail );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Mail.UseStatusField", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_CONSIDERSTATUSFIELD ))
|
|
|
|
ReadBool( value, line, &config.considerStatusField );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( PREFIX_MATCHES( id, "Mail.ReadStatus", false ))
|
|
|
|
{
|
|
|
|
if( !( config.givenOptions & CL_READSTATUS ))
|
|
|
|
ReadString( value, line, &config.readStatus );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARNING( "cfg-file(%i): unrecognized: \"%s\"\n", line, buf );
|
2019-05-27 21:52:05 +00:00
|
|
|
}
|
2019-06-12 20:37:21 +00:00
|
|
|
|
|
|
|
fclose( f );
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
2019-06-21 10:50:29 +00:00
|
|
|
else
|
|
|
|
TRACE( "unable to open config-file \"%s\"\n", configFile );
|
2016-11-28 03:51:04 +00:00
|
|
|
|
2019-05-27 21:52:05 +00:00
|
|
|
PostProcessConfiguration();
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool ReadString( const char *from, unsigned int line, char **to )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-06-21 10:50:29 +00:00
|
|
|
if( *from++ == '"' )
|
|
|
|
{
|
2016-11-28 03:51:04 +00:00
|
|
|
const char *trailingQuote;
|
|
|
|
|
|
|
|
for( trailingQuote = strchr( from, '"' );
|
|
|
|
trailingQuote != NULL;
|
|
|
|
trailingQuote = strchr( trailingQuote, '"' ))
|
|
|
|
{
|
|
|
|
if( *(trailingQuote-1) != '\\' )
|
|
|
|
break;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
++trailingQuote;
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( trailingQuote != NULL )
|
|
|
|
{
|
2016-11-28 03:51:04 +00:00
|
|
|
// valid string found, copy and translate escape sequences
|
|
|
|
const char *c;
|
|
|
|
char *to_c;
|
|
|
|
|
|
|
|
// disposing of "to" is up to the caller...
|
2019-06-21 10:50:33 +00:00
|
|
|
to_c = malloc( trailingQuote - from + 1 );
|
|
|
|
if( to_c == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*to = to_c;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
for( c = from; c != trailingQuote; ++c )
|
|
|
|
{
|
|
|
|
if( *c == '\\' )
|
|
|
|
{
|
|
|
|
switch( *(++c) )
|
|
|
|
{
|
|
|
|
case 'n': *to_c = '\n'; break;
|
|
|
|
case 'b': *to_c = '\b'; break;
|
2016-11-28 03:51:04 +00:00
|
|
|
case '\\': *to_c = '\\'; break;
|
2019-06-21 10:50:29 +00:00
|
|
|
case 'r': *to_c = '\r'; break;
|
|
|
|
case 't': *to_c = '\t'; break;
|
|
|
|
case '"': *to_c = '"'; break;
|
2019-06-07 08:52:10 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
int value, i;
|
2019-06-21 10:50:29 +00:00
|
|
|
for( i = 0, value = 0; i < 3; ++i )
|
|
|
|
{
|
|
|
|
if( c + i == NULL || *(c + i) < '0' || *(c + i) > '9' )
|
|
|
|
break;
|
|
|
|
value = value * 10 + *(c + i) - '0';
|
2019-06-07 08:52:10 +00:00
|
|
|
}
|
|
|
|
if( value == 0 )
|
|
|
|
WARNING( "cfg-file(%i): '\\0' in string or unknown escape sequence found\n",
|
|
|
|
line );
|
2019-06-21 10:50:29 +00:00
|
|
|
else
|
|
|
|
{
|
2019-06-07 08:52:10 +00:00
|
|
|
*to_c = (char)value;
|
2019-06-21 10:50:29 +00:00
|
|
|
c += i - 1;
|
2019-06-07 08:52:10 +00:00
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-21 10:50:29 +00:00
|
|
|
}
|
|
|
|
else
|
2016-11-28 03:51:04 +00:00
|
|
|
*to_c = *c;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
++to_c;
|
|
|
|
}
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
*to_c = '\0';
|
|
|
|
|
2019-06-21 10:50:33 +00:00
|
|
|
TRACE( "ReadString read \"%s\"\n", *to );
|
2016-11-28 03:51:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
WARNING( "cfg-file(%i): invalid string\n" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool ReadBool( const char *from, unsigned int line, bool *to )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
|
|
|
if( !strcasecmp( from, "on" ) || !strcasecmp( from, "yes" ) || !strcasecmp( from, "true" ))
|
|
|
|
*to = true;
|
|
|
|
else if( !strcasecmp( from, "off" ) || !strcasecmp( from, "no" ) || !strcasecmp( from, "false" ))
|
|
|
|
*to = false;
|
2019-06-21 10:50:29 +00:00
|
|
|
else
|
|
|
|
{
|
2016-11-28 03:51:04 +00:00
|
|
|
WARNING( "cfg-file(%i): invalid boolean value: \"%s\"\n", line, from );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "ReadBool read \"%s\"\n", *to ? "True" : "False" );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool ReadInt( const char *from, unsigned int line, int *to )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
|
|
|
int value = 0;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2019-06-21 10:50:29 +00:00
|
|
|
if( *from == '0' && (*(from + 1) == 'x' || *(from + 1) == 'X'))
|
2016-11-28 03:51:04 +00:00
|
|
|
for( from += 2; *from != '\0' && !IsWhiteSpace( from ); ++from )
|
|
|
|
{
|
2019-06-21 10:50:29 +00:00
|
|
|
if( value > (INT_MAX - 0xf) / 0x10 )
|
|
|
|
{
|
2016-11-28 03:51:04 +00:00
|
|
|
WARNING( "cfg-file(%i): hexadecimal-number too large: \">%x\"\n", line, INT_MAX );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *from >= '0' && *from <= '9')
|
|
|
|
value = value * 16 + *from - '0';
|
|
|
|
else if( *from >= 'a' && *from >= 'f' )
|
|
|
|
value = value * 16 + *from - 'a' + 10;
|
|
|
|
else if( *from >= 'A' && *from >= 'F' )
|
|
|
|
value = value * 16 + *from - 'A' + 10;
|
2019-06-21 10:50:29 +00:00
|
|
|
else
|
|
|
|
{
|
2016-11-28 03:51:04 +00:00
|
|
|
WARNING( "cfg-file(%i): invalid hex-digit: \"%c\"\n", line, *from );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-06-21 10:50:29 +00:00
|
|
|
else
|
|
|
|
for( ; *from != '\0' && !IsWhiteSpace( from ); ++from )
|
|
|
|
{
|
|
|
|
if( value > (INT_MAX - 9) / 10 )
|
|
|
|
{
|
2019-06-07 08:52:10 +00:00
|
|
|
WARNING( "cfg-file(%i): decimal-number too large: \">%i\"\n",
|
|
|
|
line, INT_MAX );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( *from >= '0' && *from <= '9' )
|
|
|
|
value = value * 10 + *from - '0';
|
2019-06-21 10:50:29 +00:00
|
|
|
else
|
|
|
|
{
|
2019-06-07 08:52:10 +00:00
|
|
|
WARNING( "cfg-file(%i): invalid decimal-digit: \"%c\"\n",
|
|
|
|
line, *from );
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
*to = value;
|
|
|
|
|
|
|
|
TRACE( "ReadInt read \"%i\"\n", *to );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool ReadEnum( const char *from, unsigned int line, int *to,
|
|
|
|
const enumList_t *enumList )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
for( index = 0; enumList[index].id != NULL; ++index )
|
2019-06-21 10:50:29 +00:00
|
|
|
if( !strcasecmp( enumList[index].id, from ))
|
|
|
|
{
|
2016-11-28 03:51:04 +00:00
|
|
|
*to = enumList[index].value;
|
|
|
|
|
|
|
|
TRACE( "ReadEnum read \"%i\"\n", *to );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARNING( "cfg-file(%i): unknown modifier: \"%s\"\n", line, from );
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static bool IsWhiteSpace( const char *chr )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
2019-06-12 20:37:15 +00:00
|
|
|
return chr != NULL && ( *chr == ' ' || *chr == '\t' || *chr == '\n' );
|
2016-11-28 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:52:15 +00:00
|
|
|
static const char *SkipWhiteSpaces( const char *str )
|
2016-11-28 03:51:04 +00:00
|
|
|
{
|
|
|
|
const char *c;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
for( c = str; IsWhiteSpace( c ); ++c )
|
|
|
|
;
|
2016-12-23 23:28:17 +00:00
|
|
|
|
2016-11-28 03:51:04 +00:00
|
|
|
return c;
|
|
|
|
}
|