#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/manager.h"
Include dependency graph for app_userevent.c:
Go to the source code of this file.
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
static int | userevent_exec (struct ast_channel *chan, void *data) |
Variables | |
static char * | app = "UserEvent" |
static char * | descrip |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Send an arbitrary event to the manager interface" |
static char * | tdesc = "Custom User Event Application" |
Definition in file app_userevent.c.
|
Provides a description of the module.
Definition at line 122 of file app_userevent.c. References tdesc. 00123 { 00124 return tdesc; 00125 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 134 of file app_userevent.c. References ASTERISK_GPL_KEY. 00135 { 00136 return ASTERISK_GPL_KEY; 00137 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 117 of file app_userevent.c. References app, ast_register_application(), descrip, synopsis, and userevent_exec(). 00118 { 00119 return ast_register_application(app, userevent_exec, synopsis, descrip); 00120 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 106 of file app_userevent.c. References app, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00107 { 00108 int res; 00109 00110 res = ast_unregister_application(app); 00111 00112 STANDARD_HANGUP_LOCALUSERS; 00113 00114 return res; 00115 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 127 of file app_userevent.c. References STANDARD_USECOUNT. 00128 { 00129 int res; 00130 STANDARD_USECOUNT(res); 00131 return res; 00132 }
|
|
Definition at line 63 of file app_userevent.c. References ast_log(), ast_strdupa, ast_strlen_zero(), EVENT_FLAG_USER, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_WARNING, manager_event(), ast_channel::name, and ast_channel::uniqueid. Referenced by load_module(). 00064 { 00065 struct localuser *u; 00066 char *info; 00067 char eventname[512]; 00068 char *eventbody; 00069 00070 if (ast_strlen_zero(data)) { 00071 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n"); 00072 return -1; 00073 } 00074 00075 LOCAL_USER_ADD(u); 00076 00077 info = ast_strdupa(data); 00078 if (!info) { 00079 ast_log(LOG_ERROR, "Out of memory\n"); 00080 LOCAL_USER_REMOVE(u); 00081 return -1; 00082 } 00083 00084 snprintf(eventname, sizeof(eventname), "UserEvent%s", info); 00085 eventbody = strchr(eventname, '|'); 00086 if (eventbody) { 00087 *eventbody = '\0'; 00088 eventbody++; 00089 } 00090 00091 if(eventbody) { 00092 ast_log(LOG_DEBUG, "Sending user event: %s, %s\n", eventname, eventbody); 00093 manager_event(EVENT_FLAG_USER, eventname, 00094 "Channel: %s\r\nUniqueid: %s\r\n%s\r\n", 00095 chan->name, chan->uniqueid, eventbody); 00096 } else { 00097 ast_log(LOG_DEBUG, "Sending user event: %s\n", eventname); 00098 manager_event(EVENT_FLAG_USER, eventname, 00099 "Channel: %s\r\nUniqueid: %s\r\n", chan->name, chan->uniqueid); 00100 } 00101 00102 LOCAL_USER_REMOVE(u); 00103 return 0; 00104 }
|
|
Definition at line 44 of file app_userevent.c. |
|
Definition at line 48 of file app_userevent.c. |
|
Definition at line 61 of file app_userevent.c. |
|
Definition at line 59 of file app_userevent.c. |
|
Definition at line 46 of file app_userevent.c. |
|
Definition at line 42 of file app_userevent.c. |