#include "asterisk.h"
#include <math.h>
#include <sys/wait.h>
#include <sys/time.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/ulaw.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/config.h"
#include "asterisk/localtime.h"
#include "asterisk/callerid.h"
#include "asterisk/astdb.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | event_node |
Defines | |
#define | ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" |
#define | ALMRCV_CONFIG "alarmreceiver.conf" |
Typedefs | |
typedef event_node | event_node_t |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | alarmreceiver_exec (struct ast_channel *chan, void *data) |
static void | database_increment (char *key) |
static int | load_config (void) |
static int | load_module (void) |
static int | log_events (struct ast_channel *chan, char *signalling_type, event_node_t *event) |
static void | make_tone_burst (unsigned char *data, float freq, float loudness, int len, int *x) |
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_dtmf_digits (struct ast_channel *chan, char *digit_string, int length, int fdto, int sdto) |
static int | send_tone_burst (struct ast_channel *chan, float freq, int duration, int tldn) |
static int | unload_module (void) |
static int | write_event (FILE *logfile, event_node_t *event) |
static int | write_metadata (FILE *logfile, char *signalling_type, struct ast_channel *chan) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Alarm Receiver for Asterisk" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static char * | app = "AlarmReceiver" |
static struct ast_module_info * | ast_module_info = &__mod_info |
static char | db_family [128] = {'\0'} |
static char * | descrip |
static char | event_app [128] = {'\0'} |
static char | event_file [14] = "/event-XXXXXX" |
static char | event_spool_dir [128] = {'\0'} |
static int | fdtimeout = 2000 |
static int | log_individual_events = 0 |
static int | sdtimeout = 200 |
static char * | synopsis = "Provide support for receiving alarm reports from a burglar or fire alarm panel" |
static char | time_stamp_format [128] = {"%a %b %d, %Y @ %H:%M:%S %Z"} |
static int | toneloudness = 4096 |
Use at your own risk. Please consult the GNU GPL license document included with Asterisk. *
*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
Definition in file app_alarmreceiver.c.
#define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" |
Definition at line 56 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), and receive_ademco_contact_id().
#define ALMRCV_CONFIG "alarmreceiver.conf" |
typedef struct event_node event_node_t |
Definition at line 63 of file app_alarmreceiver.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 718 of file app_alarmreceiver.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 718 of file app_alarmreceiver.c.
static int alarmreceiver_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 558 of file app_alarmreceiver.c.
References ast_channel::_state, ADEMCO_CONTACT_ID, ast_answer(), ast_copy_string(), ast_debug, AST_FORMAT_ULAW, ast_free, ast_log(), ast_safe_sleep(), ast_safe_system(), ast_set_read_format(), ast_set_write_format(), AST_STATE_UP, ast_strlen_zero(), ast_verb, chan, log_events(), LOG_WARNING, ast_channel::name, event_node::next, and receive_ademco_contact_id().
Referenced by load_module().
00559 { 00560 int res = 0; 00561 event_node_t *elp, *efree; 00562 char signalling_type[64] = ""; 00563 event_node_t *event_head = NULL; 00564 00565 /* Set write and read formats to ULAW */ 00566 ast_verb(4, "AlarmReceiver: Setting read and write formats to ULAW\n"); 00567 00568 if (ast_set_write_format(chan,AST_FORMAT_ULAW)) { 00569 ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",chan->name); 00570 return -1; 00571 } 00572 00573 if (ast_set_read_format(chan,AST_FORMAT_ULAW)) { 00574 ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",chan->name); 00575 return -1; 00576 } 00577 00578 /* Set default values for this invocation of the application */ 00579 ast_copy_string(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type)); 00580 00581 /* Answer the channel if it is not already */ 00582 ast_verb(4, "AlarmReceiver: Answering channel\n"); 00583 if (chan->_state != AST_STATE_UP) { 00584 if ((res = ast_answer(chan))) 00585 return -1; 00586 } 00587 00588 /* Wait for the connection to settle post-answer */ 00589 ast_verb(4, "AlarmReceiver: Waiting for connection to stabilize\n"); 00590 res = ast_safe_sleep(chan, 1250); 00591 00592 /* Attempt to receive the events */ 00593 if (!res) { 00594 /* Determine the protocol to receive in advance */ 00595 /* Note: Ademco contact is the only one supported at this time */ 00596 /* Others may be added later */ 00597 if(!strcmp(signalling_type, ADEMCO_CONTACT_ID)) 00598 receive_ademco_contact_id(chan, data, fdtimeout, sdtimeout, toneloudness, &event_head); 00599 else 00600 res = -1; 00601 } 00602 00603 /* Events queued by receiver, write them all out here if so configured */ 00604 if ((!res) && (log_individual_events == 0)) 00605 res = log_events(chan, signalling_type, event_head); 00606 00607 /* 00608 * Do we exec a command line at the end? 00609 */ 00610 if ((!res) && (!ast_strlen_zero(event_app)) && (event_head)) { 00611 ast_debug(1,"Alarmreceiver: executing: %s\n", event_app); 00612 ast_safe_system(event_app); 00613 } 00614 00615 /* 00616 * Free up the data allocated in our linked list 00617 */ 00618 for (elp = event_head; (elp != NULL);) { 00619 efree = elp; 00620 elp = elp->next; 00621 ast_free(efree); 00622 } 00623 00624 return 0; 00625 }
static void database_increment | ( | char * | key | ) | [static] |
Definition at line 99 of file app_alarmreceiver.c.
References ast_db_get(), ast_db_put(), ast_strlen_zero(), and ast_verb.
Referenced by receive_ademco_contact_id().
00100 { 00101 int res = 0; 00102 unsigned v; 00103 char value[16]; 00104 00105 00106 if (ast_strlen_zero(db_family)) 00107 return; /* If not defined, don't do anything */ 00108 00109 res = ast_db_get(db_family, key, value, sizeof(value) - 1); 00110 00111 if (res) { 00112 ast_verb(4, "AlarmReceiver: Creating database entry %s and setting to 1\n", key); 00113 /* Guess we have to create it */ 00114 res = ast_db_put(db_family, key, "1"); 00115 return; 00116 } 00117 00118 sscanf(value, "%30u", &v); 00119 v++; 00120 00121 ast_verb(4, "AlarmReceiver: New value for %s: %u\n", key, v); 00122 00123 snprintf(value, sizeof(value), "%u", v); 00124 00125 res = ast_db_put(db_family, key, value); 00126 00127 if (res) 00128 ast_verb(4, "AlarmReceiver: database_increment write error\n"); 00129 00130 return; 00131 }
static int load_config | ( | void | ) | [static] |
Definition at line 630 of file app_alarmreceiver.c.
References ALMRCV_CONFIG, ast_config_destroy(), ast_config_load, ast_copy_string(), ast_true(), ast_variable_retrieve(), ast_verb, and config_flags.
00631 { 00632 struct ast_config *cfg; 00633 const char *p; 00634 struct ast_flags config_flags = { 0 }; 00635 00636 /* Read in the config file */ 00637 cfg = ast_config_load(ALMRCV_CONFIG, config_flags); 00638 00639 if (!cfg) { 00640 ast_verb(4, "AlarmReceiver: No config file\n"); 00641 return 0; 00642 } else { 00643 p = ast_variable_retrieve(cfg, "general", "eventcmd"); 00644 if (p) { 00645 ast_copy_string(event_app, p, sizeof(event_app)); 00646 event_app[sizeof(event_app) - 1] = '\0'; 00647 } 00648 p = ast_variable_retrieve(cfg, "general", "loudness"); 00649 if (p) { 00650 toneloudness = atoi(p); 00651 if(toneloudness < 100) 00652 toneloudness = 100; 00653 if(toneloudness > 8192) 00654 toneloudness = 8192; 00655 } 00656 p = ast_variable_retrieve(cfg, "general", "fdtimeout"); 00657 if (p) { 00658 fdtimeout = atoi(p); 00659 if(fdtimeout < 1000) 00660 fdtimeout = 1000; 00661 if(fdtimeout > 10000) 00662 fdtimeout = 10000; 00663 } 00664 00665 p = ast_variable_retrieve(cfg, "general", "sdtimeout"); 00666 if (p) { 00667 sdtimeout = atoi(p); 00668 if(sdtimeout < 110) 00669 sdtimeout = 110; 00670 if(sdtimeout > 4000) 00671 sdtimeout = 4000; 00672 } 00673 00674 p = ast_variable_retrieve(cfg, "general", "logindividualevents"); 00675 if (p) 00676 log_individual_events = ast_true(p); 00677 00678 p = ast_variable_retrieve(cfg, "general", "eventspooldir"); 00679 if (p) { 00680 ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir)); 00681 event_spool_dir[sizeof(event_spool_dir) - 1] = '\0'; 00682 } 00683 00684 p = ast_variable_retrieve(cfg, "general", "timestampformat"); 00685 if (p) { 00686 ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format)); 00687 time_stamp_format[sizeof(time_stamp_format) - 1] = '\0'; 00688 } 00689 00690 p = ast_variable_retrieve(cfg, "general", "db-family"); 00691 if (p) { 00692 ast_copy_string(db_family, p, sizeof(db_family)); 00693 db_family[sizeof(db_family) - 1] = '\0'; 00694 } 00695 ast_config_destroy(cfg); 00696 } 00697 return 1; 00698 }
static int load_module | ( | void | ) | [static] |
Definition at line 708 of file app_alarmreceiver.c.
References alarmreceiver_exec(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_application, and load_config().
00709 { 00710 if (load_config()) { 00711 if (ast_register_application(app, alarmreceiver_exec, synopsis, descrip)) 00712 return AST_MODULE_LOAD_FAILURE; 00713 return AST_MODULE_LOAD_SUCCESS; 00714 } else 00715 return AST_MODULE_LOAD_DECLINE; 00716 }
static int log_events | ( | struct ast_channel * | chan, | |
char * | signalling_type, | |||
event_node_t * | event | |||
) | [static] |
Definition at line 355 of file app_alarmreceiver.c.
References ast_copy_string(), ast_debug, ast_strlen_zero(), ast_verb, chan, event_node::next, write_event(), and write_metadata().
Referenced by alarmreceiver_exec(), and receive_ademco_contact_id().
00356 { 00357 00358 int res = 0; 00359 char workstring[sizeof(event_spool_dir)+sizeof(event_file)] = ""; 00360 int fd; 00361 FILE *logfile; 00362 event_node_t *elp = event; 00363 00364 if (!ast_strlen_zero(event_spool_dir)) { 00365 00366 /* Make a template */ 00367 ast_copy_string(workstring, event_spool_dir, sizeof(workstring)); 00368 strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1); 00369 00370 /* Make the temporary file */ 00371 fd = mkstemp(workstring); 00372 00373 if (fd == -1) { 00374 ast_verb(3, "AlarmReceiver: can't make temporary file\n"); 00375 ast_debug(1,"AlarmReceiver: can't make temporary file\n"); 00376 res = -1; 00377 } 00378 00379 if (!res) { 00380 logfile = fdopen(fd, "w"); 00381 if (logfile) { 00382 /* Write the file */ 00383 res = write_metadata(logfile, signalling_type, chan); 00384 if (!res) 00385 while ((!res) && (elp != NULL)) { 00386 res = write_event(logfile, elp); 00387 elp = elp->next; 00388 } 00389 if (!res) { 00390 if (fflush(logfile) == EOF) 00391 res = -1; 00392 if (!res) { 00393 if (fclose(logfile) == EOF) 00394 res = -1; 00395 } 00396 } 00397 } else 00398 res = -1; 00399 } 00400 } 00401 00402 return res; 00403 }
static void make_tone_burst | ( | unsigned char * | data, | |
float | freq, | |||
float | loudness, | |||
int | len, | |||
int * | x | |||
) | [static] |
Definition at line 137 of file app_alarmreceiver.c.
References AST_LIN2MU.
Referenced by send_tone_burst().
00138 { 00139 int i; 00140 float val; 00141 00142 for (i = 0; i < len; i++) { 00143 val = loudness * sin((freq * 2.0 * M_PI * (*x)++)/8000.0); 00144 data[i] = AST_LIN2MU((int)val); 00145 } 00146 00147 /* wrap back around from 8000 */ 00148 00149 if (*x >= 8000) 00150 *x = 0; 00151 return; 00152 }
static int receive_ademco_contact_id | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | fdto, | |||
int | sdto, | |||
int | tldn, | |||
event_node_t ** | ehead | |||
) | [static] |
Definition at line 410 of file app_alarmreceiver.c.
References ADEMCO_CONTACT_ID, ast_calloc, ast_copy_string(), ast_debug, ast_safe_sleep(), ast_strlen_zero(), ast_verb, chan, database_increment(), log_events(), event_node::next, receive_dtmf_digits(), and send_tone_burst().
Referenced by alarmreceiver_exec().
00411 { 00412 int i, j; 00413 int res = 0; 00414 int checksum; 00415 char event[17]; 00416 event_node_t *enew, *elp; 00417 int got_some_digits = 0; 00418 int events_received = 0; 00419 int ack_retries = 0; 00420 00421 static char digit_map[15] = "0123456789*#ABC"; 00422 static unsigned char digit_weights[15] = {10,1,2,3,4,5,6,7,8,9,11,12,13,14,15}; 00423 00424 database_increment("calls-received"); 00425 00426 /* Wait for first event */ 00427 ast_verb(4, "AlarmReceiver: Waiting for first event from panel\n"); 00428 00429 while (res >= 0) { 00430 if (got_some_digits == 0) { 00431 /* Send ACK tone sequence */ 00432 ast_verb(4, "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n"); 00433 res = send_tone_burst(chan, 1400.0, 100, tldn); 00434 if (!res) 00435 res = ast_safe_sleep(chan, 100); 00436 if (!res) { 00437 ast_verb(4, "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n"); 00438 res = send_tone_burst(chan, 2300.0, 100, tldn); 00439 } 00440 } 00441 if ( res >= 0) 00442 res = receive_dtmf_digits(chan, event, sizeof(event) - 1, fdto, sdto); 00443 if (res < 0) { 00444 if (events_received == 0) { 00445 /* Hangup with no events received should be logged in the DB */ 00446 database_increment("no-events-received"); 00447 } else { 00448 if (ack_retries) { 00449 ast_verb(4, "AlarmReceiver: ACK retries during this call: %d\n", ack_retries); 00450 database_increment("ack-retries"); 00451 } 00452 } 00453 ast_verb(4, "AlarmReceiver: App exiting...\n"); 00454 res = -1; 00455 break; 00456 } 00457 00458 if (res != 0) { 00459 /* Didn't get all of the digits */ 00460 ast_verb(2, "AlarmReceiver: Incomplete string: %s, trying again...\n", event); 00461 00462 if (!got_some_digits) { 00463 got_some_digits = (!ast_strlen_zero(event)) ? 1 : 0; 00464 ack_retries++; 00465 } 00466 continue; 00467 } 00468 00469 got_some_digits = 1; 00470 00471 ast_verb(2, "AlarmReceiver: Received Event %s\n", event); 00472 ast_debug(1, "AlarmReceiver: Received event: %s\n", event); 00473 00474 /* Calculate checksum */ 00475 00476 for (j = 0, checksum = 0; j < 16; j++) { 00477 for (i = 0; i < sizeof(digit_map); i++) { 00478 if (digit_map[i] == event[j]) 00479 break; 00480 } 00481 00482 if (i == 16) 00483 break; 00484 00485 checksum += digit_weights[i]; 00486 } 00487 if (i == 16) { 00488 ast_verb(2, "AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]); 00489 continue; /* Bad character */ 00490 } 00491 00492 /* Checksum is mod(15) of the total */ 00493 00494 checksum = checksum % 15; 00495 00496 if (checksum) { 00497 database_increment("checksum-errors"); 00498 ast_verb(2, "AlarmReceiver: Nonzero checksum\n"); 00499 ast_debug(1, "AlarmReceiver: Nonzero checksum\n"); 00500 continue; 00501 } 00502 00503 /* Check the message type for correctness */ 00504 00505 if (strncmp(event + 4, "18", 2)) { 00506 if (strncmp(event + 4, "98", 2)) { 00507 database_increment("format-errors"); 00508 ast_verb(2, "AlarmReceiver: Wrong message type\n"); 00509 ast_debug(1, "AlarmReceiver: Wrong message type\n"); 00510 continue; 00511 } 00512 } 00513 00514 events_received++; 00515 00516 /* Queue the Event */ 00517 if (!(enew = ast_calloc(1, sizeof(*enew)))) { 00518 res = -1; 00519 break; 00520 } 00521 00522 enew->next = NULL; 00523 ast_copy_string(enew->data, event, sizeof(enew->data)); 00524 00525 /* 00526 * Insert event onto end of list 00527 */ 00528 if (*ehead == NULL) 00529 *ehead = enew; 00530 else { 00531 for(elp = *ehead; elp->next != NULL; elp = elp->next) 00532 ; 00533 elp->next = enew; 00534 } 00535 00536 if (res > 0) 00537 res = 0; 00538 00539 /* Let the user have the option of logging the single event before sending the kissoff tone */ 00540 if ((res == 0) && (log_individual_events)) 00541 res = log_events(chan, ADEMCO_CONTACT_ID, enew); 00542 /* Wait 200 msec before sending kissoff */ 00543 if (res == 0) 00544 res = ast_safe_sleep(chan, 200); 00545 00546 /* Send the kissoff tone */ 00547 if (res == 0) 00548 res = send_tone_burst(chan, 1400.0, 900, tldn); 00549 } 00550 00551 return res; 00552 }
static int receive_dtmf_digits | ( | struct ast_channel * | chan, | |
char * | digit_string, | |||
int | length, | |||
int | fdto, | |||
int | sdto | |||
) | [static] |
Definition at line 223 of file app_alarmreceiver.c.
References AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree, ast_read(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, ast_waitfor(), chan, f, ast_channel::hangupcause, and ast_channel::name.
Referenced by receive_ademco_contact_id().
00224 { 00225 int res = 0; 00226 int i = 0; 00227 int r; 00228 struct ast_frame *f; 00229 struct timeval lastdigittime; 00230 00231 lastdigittime = ast_tvnow(); 00232 for (;;) { 00233 /* if outa time, leave */ 00234 if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > ((i > 0) ? sdto : fdto)) { 00235 ast_verb(4, "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name); 00236 ast_debug(1,"AlarmReceiver: DTMF timeout on chan %s\n",chan->name); 00237 res = 1; 00238 break; 00239 } 00240 00241 if ((r = ast_waitfor(chan, -1) < 0)) { 00242 ast_debug(1, "Waitfor returned %d\n", r); 00243 continue; 00244 } 00245 00246 f = ast_read(chan); 00247 00248 if (f == NULL) { 00249 res = -1; 00250 break; 00251 } 00252 00253 /* If they hung up, leave */ 00254 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) { 00255 if (f->data.uint32) { 00256 chan->hangupcause = f->data.uint32; 00257 } 00258 ast_frfree(f); 00259 res = -1; 00260 break; 00261 } 00262 00263 /* if not DTMF, just do it again */ 00264 if (f->frametype != AST_FRAME_DTMF) { 00265 ast_frfree(f); 00266 continue; 00267 } 00268 00269 digit_string[i++] = f->subclass; /* save digit */ 00270 00271 ast_frfree(f); 00272 00273 /* If we have all the digits we expect, leave */ 00274 if(i >= length) 00275 break; 00276 00277 lastdigittime = ast_tvnow(); 00278 } 00279 00280 digit_string[i] = '\0'; /* Nul terminate the end of the digit string */ 00281 return res; 00282 }
static int send_tone_burst | ( | struct ast_channel * | chan, | |
float | freq, | |||
int | duration, | |||
int | tldn | |||
) | [static] |
Definition at line 158 of file app_alarmreceiver.c.
References AST_FORMAT_ULAW, AST_FRAME_VOICE, ast_frfree, AST_FRIENDLY_OFFSET, ast_log(), ast_read(), ast_verb, ast_waitfor(), ast_write(), buf, chan, ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, LOG_WARNING, make_tone_burst(), ast_frame::mallocd, ast_frame::offset, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.
Referenced by receive_ademco_contact_id().
00159 { 00160 int res = 0; 00161 int i = 0; 00162 int x = 0; 00163 struct ast_frame *f, wf; 00164 00165 struct { 00166 unsigned char offset[AST_FRIENDLY_OFFSET]; 00167 unsigned char buf[640]; 00168 } tone_block; 00169 00170 for (;;) { 00171 00172 if (ast_waitfor(chan, -1) < 0) { 00173 res = -1; 00174 break; 00175 } 00176 00177 f = ast_read(chan); 00178 if (!f) { 00179 res = -1; 00180 break; 00181 } 00182 00183 if (f->frametype == AST_FRAME_VOICE) { 00184 wf.frametype = AST_FRAME_VOICE; 00185 wf.subclass = AST_FORMAT_ULAW; 00186 wf.offset = AST_FRIENDLY_OFFSET; 00187 wf.mallocd = 0; 00188 wf.data.ptr = tone_block.buf; 00189 wf.datalen = f->datalen; 00190 wf.samples = wf.datalen; 00191 00192 make_tone_burst(tone_block.buf, freq, (float) tldn, wf.datalen, &x); 00193 00194 i += wf.datalen / 8; 00195 if (i > duration) { 00196 ast_frfree(f); 00197 break; 00198 } 00199 if (ast_write(chan, &wf)) { 00200 ast_verb(4, "AlarmReceiver: Failed to write frame on %s\n", chan->name); 00201 ast_log(LOG_WARNING, "AlarmReceiver Failed to write frame on %s\n",chan->name); 00202 res = -1; 00203 ast_frfree(f); 00204 break; 00205 } 00206 } 00207 00208 ast_frfree(f); 00209 } 00210 return res; 00211 }
static int unload_module | ( | void | ) | [static] |
Definition at line 703 of file app_alarmreceiver.c.
References ast_unregister_application().
00704 { 00705 return ast_unregister_application(app); 00706 }
static int write_event | ( | FILE * | logfile, | |
event_node_t * | event | |||
) | [static] |
Definition at line 341 of file app_alarmreceiver.c.
References event_node::data.
Referenced by log_events().
00342 { 00343 int res = 0; 00344 00345 if (fprintf(logfile, "%s\n", event->data) < 0) 00346 res = -1; 00347 00348 return res; 00349 }
static int write_metadata | ( | FILE * | logfile, | |
char * | signalling_type, | |||
struct ast_channel * | chan | |||
) | [static] |
Definition at line 287 of file app_alarmreceiver.c.
References ast_callerid_parse(), ast_copy_string(), ast_debug, ast_localtime(), ast_shrink_phone_number(), ast_strftime(), ast_tvnow(), ast_verb, chan, ast_channel::cid, and ast_callerid::cid_num.
Referenced by log_events().
00288 { 00289 int res = 0; 00290 struct timeval t; 00291 struct ast_tm now; 00292 char *cl,*cn; 00293 char workstring[80]; 00294 char timestamp[80]; 00295 00296 /* Extract the caller ID location */ 00297 if (chan->cid.cid_num) 00298 ast_copy_string(workstring, chan->cid.cid_num, sizeof(workstring)); 00299 workstring[sizeof(workstring) - 1] = '\0'; 00300 00301 ast_callerid_parse(workstring, &cn, &cl); 00302 if (cl) 00303 ast_shrink_phone_number(cl); 00304 00305 /* Get the current time */ 00306 t = ast_tvnow(); 00307 ast_localtime(&t, &now, NULL); 00308 00309 /* Format the time */ 00310 ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); 00311 00312 res = fprintf(logfile, "\n\n[metadata]\n\n"); 00313 00314 if (res >= 0) 00315 res = fprintf(logfile, "PROTOCOL=%s\n", signalling_type); 00316 00317 if (res >= 0) 00318 res = fprintf(logfile, "CALLINGFROM=%s\n", (!cl) ? "<unknown>" : cl); 00319 00320 if (res >- 0) 00321 res = fprintf(logfile, "CALLERNAME=%s\n", (!cn) ? "<unknown>" : cn); 00322 00323 if (res >= 0) 00324 res = fprintf(logfile, "TIMESTAMP=%s\n\n", timestamp); 00325 00326 if (res >= 0) 00327 res = fprintf(logfile, "[events]\n\n"); 00328 00329 if (res < 0) { 00330 ast_verb(3, "AlarmReceiver: can't write metadata\n"); 00331 ast_debug(1,"AlarmReceiver: can't write metadata\n"); 00332 } else 00333 res = 0; 00334 00335 return res; 00336 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Alarm Receiver for Asterisk" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 718 of file app_alarmreceiver.c.
char* app = "AlarmReceiver" [static] |
Definition at line 65 of file app_alarmreceiver.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 718 of file app_alarmreceiver.c.
char db_family[128] = {'\0'} [static] |
Definition at line 86 of file app_alarmreceiver.c.
char* descrip [static] |
Definition at line 68 of file app_alarmreceiver.c.
char event_app[128] = {'\0'} [static] |
Definition at line 85 of file app_alarmreceiver.c.
char event_file[14] = "/event-XXXXXX" [static] |
Definition at line 90 of file app_alarmreceiver.c.
char event_spool_dir[128] = {'\0'} [static] |
Definition at line 84 of file app_alarmreceiver.c.
int fdtimeout = 2000 [static] |
Definition at line 80 of file app_alarmreceiver.c.
int log_individual_events = 0 [static] |
Definition at line 83 of file app_alarmreceiver.c.
int sdtimeout = 200 [static] |
Definition at line 81 of file app_alarmreceiver.c.
char* synopsis = "Provide support for receiving alarm reports from a burglar or fire alarm panel" [static] |
Definition at line 67 of file app_alarmreceiver.c.
char time_stamp_format[128] = {"%a %b %d, %Y @ %H:%M:%S %Z"} [static] |
Definition at line 87 of file app_alarmreceiver.c.
int toneloudness = 4096 [static] |
Definition at line 82 of file app_alarmreceiver.c.