mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-18 15:49:56 +00:00
There she goes! First commit from me to trunk \o/
Make app_alarmreceiver honor code guidelines and fix whitespace errors. No functional changes. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@102906 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -77,7 +77,6 @@ static char *descrip =
|
|||||||
"tones.\n";
|
"tones.\n";
|
||||||
|
|
||||||
/* Config Variables */
|
/* Config Variables */
|
||||||
|
|
||||||
static int fdtimeout = 2000;
|
static int fdtimeout = 2000;
|
||||||
static int sdtimeout = 200;
|
static int sdtimeout = 200;
|
||||||
static int toneloudness = 4096;
|
static int toneloudness = 4096;
|
||||||
@@ -88,7 +87,6 @@ static char db_family[128] = {'\0'};
|
|||||||
static char time_stamp_format[128] = {"%a %b %d, %Y @ %H:%M:%S %Z"};
|
static char time_stamp_format[128] = {"%a %b %d, %Y @ %H:%M:%S %Z"};
|
||||||
|
|
||||||
/* Misc variables */
|
/* Misc variables */
|
||||||
|
|
||||||
static char event_file[14] = "/event-XXXXXX";
|
static char event_file[14] = "/event-XXXXXX";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -98,7 +96,6 @@ static char event_file[14] = "/event-XXXXXX";
|
|||||||
* in this family if it is defined. If the new key doesn't exist in the
|
* in this family if it is defined. If the new key doesn't exist in the
|
||||||
* family, then create it and set its value to 1.
|
* family, then create it and set its value to 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void database_increment( char *key )
|
static void database_increment( char *key )
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -137,7 +134,6 @@ static void database_increment( char *key )
|
|||||||
/*
|
/*
|
||||||
* Build a MuLaw data block for a single frequency tone
|
* Build a MuLaw data block for a single frequency tone
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x)
|
static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -150,7 +146,8 @@ static void make_tone_burst(unsigned char *data, float freq, float loudness, int
|
|||||||
|
|
||||||
/* wrap back around from 8000 */
|
/* wrap back around from 8000 */
|
||||||
|
|
||||||
if (*x >= 8000) *x = 0;
|
if (*x >= 8000)
|
||||||
|
*x = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +155,6 @@ static void make_tone_burst(unsigned char *data, float freq, float loudness, int
|
|||||||
* Send a single tone burst for a specifed duration and frequency.
|
* Send a single tone burst for a specifed duration and frequency.
|
||||||
* Returns 0 if successful
|
* Returns 0 if successful
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn)
|
static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -171,8 +167,7 @@ static int send_tone_burst(struct ast_channel *chan, float freq, int duration, i
|
|||||||
unsigned char buf[640];
|
unsigned char buf[640];
|
||||||
} tone_block;
|
} tone_block;
|
||||||
|
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
|
|
||||||
if (ast_waitfor(chan, -1) < 0) {
|
if (ast_waitfor(chan, -1) < 0) {
|
||||||
res = -1;
|
res = -1;
|
||||||
@@ -225,7 +220,6 @@ static int send_tone_burst(struct ast_channel *chan, float freq, int duration, i
|
|||||||
* Returns -1 if the caller hung up or there was a channel error.
|
* Returns -1 if the caller hung up or there was a channel error.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int length, int fdto, int sdto)
|
static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int length, int fdto, int sdto)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -237,12 +231,9 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int
|
|||||||
lastdigittime = ast_tvnow();
|
lastdigittime = ast_tvnow();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* if outa time, leave */
|
/* if outa time, leave */
|
||||||
if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
|
if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > ((i > 0) ? sdto : fdto)) {
|
||||||
((i > 0) ? sdto : fdto)){
|
|
||||||
ast_verb(4, "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name);
|
ast_verb(4, "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name);
|
||||||
|
|
||||||
ast_debug(1,"AlarmReceiver: DTMF timeout on chan %s\n",chan->name);
|
ast_debug(1,"AlarmReceiver: DTMF timeout on chan %s\n",chan->name);
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -260,8 +251,7 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If they hung up, leave */
|
/* If they hung up, leave */
|
||||||
if ((f->frametype == AST_FRAME_CONTROL) &&
|
if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
|
||||||
(f->subclass == AST_CONTROL_HANGUP)){
|
|
||||||
ast_frfree(f);
|
ast_frfree(f);
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
@@ -286,13 +276,11 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int
|
|||||||
|
|
||||||
digit_string[i] = '\0'; /* Nul terminate the end of the digit string */
|
digit_string[i] = '\0'; /* Nul terminate the end of the digit string */
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the metadata to the log file
|
* Write the metadata to the log file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
|
static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -311,17 +299,13 @@ static int write_metadata( FILE *logfile, char *signalling_type, struct ast_chan
|
|||||||
if (cl)
|
if (cl)
|
||||||
ast_shrink_phone_number(cl);
|
ast_shrink_phone_number(cl);
|
||||||
|
|
||||||
|
|
||||||
/* Get the current time */
|
/* Get the current time */
|
||||||
|
|
||||||
t = ast_tvnow();
|
t = ast_tvnow();
|
||||||
ast_localtime(&t, &now, NULL);
|
ast_localtime(&t, &now, NULL);
|
||||||
|
|
||||||
/* Format the time */
|
/* Format the time */
|
||||||
|
|
||||||
ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
|
ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
|
||||||
|
|
||||||
|
|
||||||
res = fprintf(logfile, "\n\n[metadata]\n\n");
|
res = fprintf(logfile, "\n\n[metadata]\n\n");
|
||||||
|
|
||||||
if (res >= 0)
|
if (res >= 0)
|
||||||
@@ -341,10 +325,8 @@ static int write_metadata( FILE *logfile, char *signalling_type, struct ast_chan
|
|||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
ast_verb(3, "AlarmReceiver: can't write metadata\n");
|
ast_verb(3, "AlarmReceiver: can't write metadata\n");
|
||||||
|
|
||||||
ast_debug(1,"AlarmReceiver: can't write metadata\n");
|
ast_debug(1,"AlarmReceiver: can't write metadata\n");
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -353,7 +335,6 @@ static int write_metadata( FILE *logfile, char *signalling_type, struct ast_chan
|
|||||||
/*
|
/*
|
||||||
* Write a single event to the log file
|
* Write a single event to the log file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int write_event( FILE *logfile, event_node_t *event)
|
static int write_event( FILE *logfile, event_node_t *event)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -364,12 +345,10 @@ static int write_event( FILE *logfile, event_node_t *event)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are configured to log events, do so here.
|
* If we are configured to log events, do so here.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int log_events(struct ast_channel *chan, char *signalling_type, event_node_t *event)
|
static int log_events(struct ast_channel *chan, char *signalling_type, event_node_t *event)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -382,12 +361,10 @@ static int log_events(struct ast_channel *chan, char *signalling_type, event_no
|
|||||||
if (!ast_strlen_zero(event_spool_dir)) {
|
if (!ast_strlen_zero(event_spool_dir)) {
|
||||||
|
|
||||||
/* Make a template */
|
/* Make a template */
|
||||||
|
|
||||||
ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
|
ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
|
||||||
strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
|
strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
|
||||||
|
|
||||||
/* Make the temporary file */
|
/* Make the temporary file */
|
||||||
|
|
||||||
fd = mkstemp(workstring);
|
fd = mkstemp(workstring);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@@ -414,8 +391,7 @@ static int log_events(struct ast_channel *chan, char *signalling_type, event_no
|
|||||||
res = -1;
|
res = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
res = -1;
|
res = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,7 +404,6 @@ static int log_events(struct ast_channel *chan, char *signalling_type, event_no
|
|||||||
*
|
*
|
||||||
* The function will return 0 when the caller hangs up, else a -1 if there was a problem.
|
* The function will return 0 when the caller hangs up, else a -1 if there was a problem.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int fdto, int sdto, int tldn, event_node_t **ehead)
|
static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int fdto, int sdto, int tldn, event_node_t **ehead)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
@@ -446,44 +421,29 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int
|
|||||||
database_increment("calls-received");
|
database_increment("calls-received");
|
||||||
|
|
||||||
/* Wait for first event */
|
/* Wait for first event */
|
||||||
|
|
||||||
ast_verb(4, "AlarmReceiver: Waiting for first event from panel\n");
|
ast_verb(4, "AlarmReceiver: Waiting for first event from panel\n");
|
||||||
|
|
||||||
while (res >= 0) {
|
while (res >= 0) {
|
||||||
|
|
||||||
if (got_some_digits == 0) {
|
if (got_some_digits == 0) {
|
||||||
|
|
||||||
/* Send ACK tone sequence */
|
/* Send ACK tone sequence */
|
||||||
|
|
||||||
|
|
||||||
ast_verb(4, "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
|
ast_verb(4, "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
|
||||||
|
|
||||||
|
|
||||||
res = send_tone_burst(chan, 1400.0, 100, tldn);
|
res = send_tone_burst(chan, 1400.0, 100, tldn);
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
res = ast_safe_sleep(chan, 100);
|
res = ast_safe_sleep(chan, 100);
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
ast_verb(4, "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
|
ast_verb(4, "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
|
||||||
|
|
||||||
res = send_tone_burst(chan, 2300.0, 100, tldn);
|
res = send_tone_burst(chan, 2300.0, 100, tldn);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( res >= 0)
|
if ( res >= 0)
|
||||||
res = receive_dtmf_digits(chan, event, sizeof(event) - 1, fdto, sdto);
|
res = receive_dtmf_digits(chan, event, sizeof(event) - 1, fdto, sdto);
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
if (events_received == 0) {
|
||||||
if(events_received == 0)
|
|
||||||
/* Hangup with no events received should be logged in the DB */
|
/* Hangup with no events received should be logged in the DB */
|
||||||
database_increment("no-events-received");
|
database_increment("no-events-received");
|
||||||
else{
|
} else {
|
||||||
if (ack_retries) {
|
if (ack_retries) {
|
||||||
ast_verb(4, "AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
|
ast_verb(4, "AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
|
||||||
|
|
||||||
database_increment("ack-retries");
|
database_increment("ack-retries");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -521,7 +481,6 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int
|
|||||||
|
|
||||||
checksum += digit_weights[i];
|
checksum += digit_weights[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 16) {
|
if (i == 16) {
|
||||||
ast_verb(2, "AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]);
|
ast_verb(2, "AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]);
|
||||||
continue; /* Bad character */
|
continue; /* Bad character */
|
||||||
@@ -563,14 +522,11 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int
|
|||||||
/*
|
/*
|
||||||
* Insert event onto end of list
|
* Insert event onto end of list
|
||||||
*/
|
*/
|
||||||
|
if (*ehead == NULL)
|
||||||
if(*ehead == NULL){
|
|
||||||
*ehead = enew;
|
*ehead = enew;
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
for(elp = *ehead; elp->next != NULL; elp = elp->next)
|
for(elp = *ehead; elp->next != NULL; elp = elp->next)
|
||||||
;
|
;
|
||||||
|
|
||||||
elp->next = enew;
|
elp->next = enew;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,41 +534,32 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int
|
|||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
/* Let the user have the option of logging the single event before sending the kissoff tone */
|
/* Let the user have the option of logging the single event before sending the kissoff tone */
|
||||||
|
|
||||||
if ((res == 0) && (log_individual_events))
|
if ((res == 0) && (log_individual_events))
|
||||||
res = log_events(chan, ADEMCO_CONTACT_ID, enew);
|
res = log_events(chan, ADEMCO_CONTACT_ID, enew);
|
||||||
|
|
||||||
/* Wait 200 msec before sending kissoff */
|
/* Wait 200 msec before sending kissoff */
|
||||||
|
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
res = ast_safe_sleep(chan, 200);
|
res = ast_safe_sleep(chan, 200);
|
||||||
|
|
||||||
/* Send the kissoff tone */
|
/* Send the kissoff tone */
|
||||||
|
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
res = send_tone_burst(chan, 1400.0, 900, tldn);
|
res = send_tone_burst(chan, 1400.0, 900, tldn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the main function called by Asterisk Core whenever the App is invoked in the extension logic.
|
* This is the main function called by Asterisk Core whenever the App is invoked in the extension logic.
|
||||||
* This function will always return 0.
|
* This function will always return 0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int alarmreceiver_exec(struct ast_channel *chan, void *data)
|
static int alarmreceiver_exec(struct ast_channel *chan, void *data)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
event_node_t *elp, *efree;
|
event_node_t *elp, *efree;
|
||||||
char signalling_type[64] = "";
|
char signalling_type[64] = "";
|
||||||
|
|
||||||
event_node_t *event_head = NULL;
|
event_node_t *event_head = NULL;
|
||||||
|
|
||||||
/* Set write and read formats to ULAW */
|
/* Set write and read formats to ULAW */
|
||||||
|
|
||||||
ast_verb(4, "AlarmReceiver: Setting read and write formats to ULAW\n");
|
ast_verb(4, "AlarmReceiver: Setting read and write formats to ULAW\n");
|
||||||
|
|
||||||
if (ast_set_write_format(chan,AST_FORMAT_ULAW)) {
|
if (ast_set_write_format(chan,AST_FORMAT_ULAW)) {
|
||||||
@@ -626,52 +573,37 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set default values for this invocation of the application */
|
/* Set default values for this invocation of the application */
|
||||||
|
|
||||||
ast_copy_string(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type));
|
ast_copy_string(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type));
|
||||||
|
|
||||||
|
|
||||||
/* Answer the channel if it is not already */
|
/* Answer the channel if it is not already */
|
||||||
|
|
||||||
ast_verb(4, "AlarmReceiver: Answering channel\n");
|
ast_verb(4, "AlarmReceiver: Answering channel\n");
|
||||||
|
|
||||||
if (chan->_state != AST_STATE_UP) {
|
if (chan->_state != AST_STATE_UP) {
|
||||||
if ((res = ast_answer(chan)))
|
if ((res = ast_answer(chan)))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for the connection to settle post-answer */
|
/* Wait for the connection to settle post-answer */
|
||||||
|
|
||||||
ast_verb(4, "AlarmReceiver: Waiting for connection to stabilize\n");
|
ast_verb(4, "AlarmReceiver: Waiting for connection to stabilize\n");
|
||||||
|
|
||||||
res = ast_safe_sleep(chan, 1250);
|
res = ast_safe_sleep(chan, 1250);
|
||||||
|
|
||||||
/* Attempt to receive the events */
|
/* Attempt to receive the events */
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
|
||||||
/* Determine the protocol to receive in advance */
|
/* Determine the protocol to receive in advance */
|
||||||
/* Note: Ademco contact is the only one supported at this time */
|
/* Note: Ademco contact is the only one supported at this time */
|
||||||
/* Others may be added later */
|
/* Others may be added later */
|
||||||
|
|
||||||
if(!strcmp(signalling_type, ADEMCO_CONTACT_ID))
|
if(!strcmp(signalling_type, ADEMCO_CONTACT_ID))
|
||||||
receive_ademco_contact_id(chan, data, fdtimeout, sdtimeout, toneloudness, &event_head);
|
receive_ademco_contact_id(chan, data, fdtimeout, sdtimeout, toneloudness, &event_head);
|
||||||
else
|
else
|
||||||
res = -1;
|
res = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Events queued by receiver, write them all out here if so configured */
|
/* Events queued by receiver, write them all out here if so configured */
|
||||||
|
if ((!res) && (log_individual_events == 0))
|
||||||
if((!res) && (log_individual_events == 0)){
|
|
||||||
res = log_events(chan, signalling_type, event_head);
|
res = log_events(chan, signalling_type, event_head);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do we exec a command line at the end?
|
* Do we exec a command line at the end?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((!res) && (!ast_strlen_zero(event_app)) && (event_head)) {
|
if ((!res) && (!ast_strlen_zero(event_app)) && (event_head)) {
|
||||||
ast_debug(1,"Alarmreceiver: executing: %s\n", event_app);
|
ast_debug(1,"Alarmreceiver: executing: %s\n", event_app);
|
||||||
ast_safe_system(event_app);
|
ast_safe_system(event_app);
|
||||||
@@ -680,7 +612,6 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data)
|
|||||||
/*
|
/*
|
||||||
* Free up the data allocated in our linked list
|
* Free up the data allocated in our linked list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (elp = event_head; (elp != NULL);) {
|
for (elp = event_head; (elp != NULL);) {
|
||||||
efree = elp;
|
efree = elp;
|
||||||
elp = elp->next;
|
elp = elp->next;
|
||||||
@@ -693,7 +624,6 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data)
|
|||||||
/*
|
/*
|
||||||
* Load the configuration from the configuration file
|
* Load the configuration from the configuration file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int load_config(void)
|
static int load_config(void)
|
||||||
{
|
{
|
||||||
struct ast_config *cfg;
|
struct ast_config *cfg;
|
||||||
@@ -701,24 +631,17 @@ static int load_config(void)
|
|||||||
struct ast_flags config_flags = { 0 };
|
struct ast_flags config_flags = { 0 };
|
||||||
|
|
||||||
/* Read in the config file */
|
/* Read in the config file */
|
||||||
|
|
||||||
cfg = ast_config_load(ALMRCV_CONFIG, config_flags);
|
cfg = ast_config_load(ALMRCV_CONFIG, config_flags);
|
||||||
|
|
||||||
if (!cfg) {
|
if (!cfg) {
|
||||||
|
|
||||||
ast_verb(4, "AlarmReceiver: No config file\n");
|
ast_verb(4, "AlarmReceiver: No config file\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
|
|
||||||
|
|
||||||
p = ast_variable_retrieve(cfg, "general", "eventcmd");
|
p = ast_variable_retrieve(cfg, "general", "eventcmd");
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
ast_copy_string(event_app, p, sizeof(event_app));
|
ast_copy_string(event_app, p, sizeof(event_app));
|
||||||
event_app[sizeof(event_app) - 1] = '\0';
|
event_app[sizeof(event_app) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ast_variable_retrieve(cfg, "general", "loudness");
|
p = ast_variable_retrieve(cfg, "general", "loudness");
|
||||||
if (p) {
|
if (p) {
|
||||||
toneloudness = atoi(p);
|
toneloudness = atoi(p);
|
||||||
@@ -743,31 +666,25 @@ static int load_config(void)
|
|||||||
sdtimeout = 110;
|
sdtimeout = 110;
|
||||||
if(sdtimeout > 4000)
|
if(sdtimeout > 4000)
|
||||||
sdtimeout = 4000;
|
sdtimeout = 4000;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ast_variable_retrieve(cfg, "general", "logindividualevents");
|
p = ast_variable_retrieve(cfg, "general", "logindividualevents");
|
||||||
if(p){
|
if (p)
|
||||||
log_individual_events = ast_true(p);
|
log_individual_events = ast_true(p);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
p = ast_variable_retrieve(cfg, "general", "eventspooldir");
|
p = ast_variable_retrieve(cfg, "general", "eventspooldir");
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir));
|
ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir));
|
||||||
event_spool_dir[sizeof(event_spool_dir) - 1] = '\0';
|
event_spool_dir[sizeof(event_spool_dir) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ast_variable_retrieve(cfg, "general", "timestampformat");
|
p = ast_variable_retrieve(cfg, "general", "timestampformat");
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format));
|
ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format));
|
||||||
time_stamp_format[sizeof(time_stamp_format) - 1] = '\0';
|
time_stamp_format[sizeof(time_stamp_format) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ast_variable_retrieve(cfg, "general", "db-family");
|
p = ast_variable_retrieve(cfg, "general", "db-family");
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
ast_copy_string(db_family, p, sizeof(db_family));
|
ast_copy_string(db_family, p, sizeof(db_family));
|
||||||
db_family[sizeof(db_family) - 1] = '\0';
|
db_family[sizeof(db_family) - 1] = '\0';
|
||||||
@@ -775,14 +692,11 @@ static int load_config(void)
|
|||||||
ast_config_destroy(cfg);
|
ast_config_destroy(cfg);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These functions are required to implement an Asterisk App.
|
* These functions are required to implement an Asterisk App.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static int unload_module(void)
|
static int unload_module(void)
|
||||||
{
|
{
|
||||||
return ast_unregister_application(app);
|
return ast_unregister_application(app);
|
||||||
@@ -794,8 +708,7 @@ static int load_module(void)
|
|||||||
if (ast_register_application(app, alarmreceiver_exec, synopsis, descrip))
|
if (ast_register_application(app, alarmreceiver_exec, synopsis, descrip))
|
||||||
return AST_MODULE_LOAD_FAILURE;
|
return AST_MODULE_LOAD_FAILURE;
|
||||||
return AST_MODULE_LOAD_SUCCESS;
|
return AST_MODULE_LOAD_SUCCESS;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return AST_MODULE_LOAD_DECLINE;
|
return AST_MODULE_LOAD_DECLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user