Now reading SMTP related settings from the config file

Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely POLONKAI 2012-05-17 23:05:23 +02:00
parent 743cb3c5ad
commit ea0f6e8af2
3 changed files with 80 additions and 1 deletions

View File

@ -41,3 +41,23 @@ trainable abilities = true
# If set to true, characters can choose to die, and reborn in a new body if
# they are old enough (80% of the racial maximum age)
reborn = true
# SMTP related settings go here. SMTP is required to send out initially
# generated passwords
[smtp]
# The SMTP server's address
smtp server = smtp.gmail.com
# Set to true if the SMTP server provides or requires TLS connections
smtp tls = true
# The username to use to send e-mails
smtp username = wmud
# The password to use to send e-mails
smtp password = wmudPassWD1
# The sender's e-mail address. This will appear in all sent e-mails. Should be
# in the form Name <e-mail@address>, where Name can be omitted
smtp sender = wMUD <polesz@w00d5t0ck.info>

View File

@ -61,6 +61,18 @@ wmud_configdata_free(ConfigData **config_data)
if ((*config_data)->database_file)
g_free((*config_data)->database_file);
if ((*config_data)->smtp_server)
g_free((*config_data)->smtp_server);
if ((*config_data)->smtp_username)
g_free((*config_data)->smtp_username);
if ((*config_data)->smtp_password)
g_free((*config_data)->smtp_password);
if ((*config_data)->smtp_sender)
g_free((*config_data)->smtp_sender);
g_free(*config_data);
*config_data = NULL;
}
@ -110,6 +122,15 @@ wmud_config_init(ConfigData **config_data, GError **err)
return FALSE;
}
if (!g_key_file_has_group(config, "smtp"))
{
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTP, "Config file (%s) does not contain an [smtp] group", config_file->str);
g_key_file_free(config);
g_string_free(config_file, TRUE);
return FALSE;
}
g_clear_error(&in_err);
(*config_data)->port = g_key_file_get_integer(config, "global", "port", &in_err);
if (in_err)
@ -161,6 +182,36 @@ wmud_config_init(ConfigData **config_data, GError **err)
}
}
g_clear_error(&in_err);
(*config_data)->smtp_server = g_key_file_get_string(config, "smtp", "smtp server", &in_err);
if (in_err)
{
if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
{
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTPSERVER, "Config file (%s) does not contain an smtp server address", config_file->str);
g_key_file_free(config);
g_string_free(config_file, TRUE);
wmud_configdata_free(config_data);
return FALSE;
}
}
g_clear_error(&in_err);
(*config_data)->smtp_sender = g_key_file_get_string(config, "smtp", "smtp sender", &in_err);
if (in_err)
{
if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
{
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTPSENDER, "Config file (%s) does not contain an smtp sender name", config_file->str);
g_key_file_free(config);
g_string_free(config_file, TRUE);
wmud_configdata_free(config_data);
return FALSE;
}
}
g_key_file_free(config);
g_string_free(config_file, TRUE);

View File

@ -26,7 +26,10 @@ typedef enum {
WMUD_CONFIG_ERROR_BADPORT,
WMUD_CONFIG_ERROR_NOWORLD,
WMUD_CONFIG_ERROR_NOEMAIL,
WMUD_CONFIG_ERROR_REUSE
WMUD_CONFIG_ERROR_REUSE,
WMUD_CONFIG_ERROR_NOSMTP,
WMUD_CONFIG_ERROR_NOSMTPSERVER,
WMUD_CONFIG_ERROR_NOSMTPSENDER
} wmudConfigError;
/**
@ -40,6 +43,11 @@ typedef struct _ConfigData {
guint port;
gchar *database_file;
gchar *admin_email;
gchar *smtp_server;
gboolean smtp_tls;
gchar *smtp_username;
gchar *smtp_password;
gchar *smtp_sender;
} ConfigData;
extern ConfigData *active_config;