00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <string.h>
00028 #include <unistd.h>
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00033
00034 #include "asterisk/lock.h"
00035 #include "asterisk/file.h"
00036 #include "asterisk/logger.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/manager.h"
00041
00042 static char *tdesc = "Custom User Event Application";
00043
00044 static char *app = "UserEvent";
00045
00046 static char *synopsis = "Send an arbitrary event to the manager interface";
00047
00048 static char *descrip =
00049 " UserEvent(eventname[|body]): Sends an arbitrary event to the\n"
00050 "manager interface, with an optional body representing additional\n"
00051 "arguments. The format of the event will be:\n"
00052 " Event: UserEvent<specified event name>\n"
00053 " Channel: <channel name>\n"
00054 " Uniqueid: <call uniqueid>\n"
00055 " [body]\n"
00056 "If the body is not specified, only Event, Channel, and Uniqueid fields\n"
00057 "will be present. Returns 0.";
00058
00059 STANDARD_LOCAL_USER;
00060
00061 LOCAL_USER_DECL;
00062
00063 static int userevent_exec(struct ast_channel *chan, void *data)
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 }
00105
00106 int unload_module(void)
00107 {
00108 int res;
00109
00110 res = ast_unregister_application(app);
00111
00112 STANDARD_HANGUP_LOCALUSERS;
00113
00114 return res;
00115 }
00116
00117 int load_module(void)
00118 {
00119 return ast_register_application(app, userevent_exec, synopsis, descrip);
00120 }
00121
00122 char *description(void)
00123 {
00124 return tdesc;
00125 }
00126
00127 int usecount(void)
00128 {
00129 int res;
00130 STANDARD_USECOUNT(res);
00131 return res;
00132 }
00133
00134 char *key()
00135 {
00136 return ASTERISK_GPL_KEY;
00137 }