config file options to define phone parameters
This commit is contained in:
23
yasnd.c
23
yasnd.c
@ -17,6 +17,9 @@ host_decl* hosts=NULL; // structure with hosts' definitions
|
||||
int hosts_count=0; // count of hosts
|
||||
int debug_flag=0;
|
||||
bool sms_send_enable=false; // send or not send alerts via SMS
|
||||
char* phone_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0"
|
||||
char* phone_model=NULL; // gammu phone model, for example: "at"
|
||||
char* phone_connection=NULL; // gammu phone connection type, for example: "at"
|
||||
char* recipient_number=NULL; // recipient of sms alerts
|
||||
|
||||
void log_debug(const char *message,int verbosity)
|
||||
@ -48,6 +51,9 @@ void init()
|
||||
CFG_STR_LIST("hosts", "{}", CFGF_NONE),
|
||||
CFG_SIMPLE_INT("debug", &debug_flag),
|
||||
CFG_SIMPLE_BOOL("sms_send_enable", &sms_send_enable),
|
||||
CFG_SIMPLE_STR("phone_device", &phone_device),
|
||||
CFG_SIMPLE_STR("phone_model", &phone_connection),
|
||||
CFG_SIMPLE_STR("phone_connection", &phone_model),
|
||||
CFG_SIMPLE_STR("sms_recipient", &recipient_number),
|
||||
CFG_END()
|
||||
};
|
||||
@ -58,9 +64,24 @@ void init()
|
||||
log_event("Error parsing config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// if SMS sending is enabled, recipient address must also be defined
|
||||
// if SMS sending is enabled, all of phone parameters must be explicitly defined
|
||||
if (sms_send_enable)
|
||||
{
|
||||
if (phone_model==NULL)
|
||||
{
|
||||
log_event("Error: phone model is not defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (phone_connection==NULL)
|
||||
{
|
||||
log_event("Error: phone connection type is not defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (phone_device==NULL)
|
||||
{
|
||||
log_event("Error: phone device is not defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (recipient_number==NULL)
|
||||
{
|
||||
log_event("Error: no recipient for sms alerts defined in config file");
|
||||
|
Reference in New Issue
Block a user