event cleanup from windows perspective

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@204 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2005-12-23 21:09:36 +00:00
parent 3643ad3037
commit f3d711ccae
13 changed files with 102 additions and 100 deletions

View File

@ -92,6 +92,7 @@ extern "C" {
SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_session *session,
switch_caller_profile *tocopy);
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, switch_event *event);
#ifdef __cplusplus

View File

@ -75,7 +75,7 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void);
SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool);
SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, char *subclass_name);
SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header_name);
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char *header_name, char *fmt, ...);
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...);
SWITCH_DECLARE(void) switch_event_destroy(switch_event **event);
SWITCH_DECLARE(switch_status) switch_event_dup(switch_event **event, switch_event *todup);
SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event, void *user_data);
@ -90,5 +90,4 @@ SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *f
#define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
#define switch_event_fire(event) switch_event_fire_detailed(__FILE__, (char * )__FUNCTION__, __LINE__, event, NULL)
#define switch_event_fire_data(event, data) switch_event_fire_detailed(__FILE__, (char * )__FUNCTION__, __LINE__, event, data)
#endif

View File

@ -40,6 +40,11 @@ extern "C" {
#define SWITCH_GLOBAL_VERSION "1"
#define SWITCH_MAX_CODECS 30
typedef enum {
SWITCH_STACK_BOTTOM,
SWITCH_STACK_TOP
} switch_stack_t;
typedef enum {
SWITCH_STATUS_SUCCESS,
SWITCH_STATUS_FALSE,
@ -132,7 +137,6 @@ typedef enum {
SWITCH_EVENT_ANSWER_CHAN,
SWITCH_EVENT_HANGUP_CHAN,
SWITCH_EVENT_STARTUP,
SWITCH_EVENT_EVENT_SHUTDOWN,
SWITCH_EVENT_SHUTDOWN,
SWITCH_EVENT_ALL
} switch_event_t;

View File

@ -69,6 +69,7 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char
SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, unsigned int flags, switch_memory_pool *pool);
SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms);
SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len);
SWITCH_DECLARE(char *) switch_cut_path(char *in);
#if !defined(switch_strdupa) && defined(__GNUC__)
# define switch_strdupa(s) \

View File

@ -271,7 +271,7 @@ static switch_status channel_on_transmit(switch_core_session *session)
snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", buf);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf);
switch_event_fire(&event);
}

View File

@ -62,9 +62,14 @@ static void event_handler (switch_event *event)
{
char buf[1024];
iks *msg;
int loops = 0;
if (!globals.session.authorized) {
return;
while (!globals.session.authorized) {
switch_yield(100000);
if (loops++ > 5) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Nothing to do with this Event!\n");
return;
}
}
switch(event->event_id) {

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
}
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Ready");
switch_event_fire(&event);
}
@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
switch_console_loop();
if (switch_event_create(&event, SWITCH_EVENT_SHUTDOWN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Shutting Down");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Event-Info", "System Shutting Down");
switch_event_fire(&event);
}

View File

@ -75,6 +75,33 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_
return profile;
}
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, switch_event *event)
{
if (caller_profile->dialplan) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Dialplan", caller_profile->dialplan);
}
if (caller_profile->caller_id_name) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Caller-ID-Name", caller_profile->caller_id_name);
}
if (caller_profile->caller_id_number) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Caller-ID-Number", caller_profile->caller_id_number);
}
if (caller_profile->network_addr) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Network-Addr", caller_profile->network_addr);
}
if (caller_profile->ani) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-ANI", caller_profile->ani);
}
if (caller_profile->ani2) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-ANI2", caller_profile->ani2);
}
if (caller_profile->destination_number) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Destination-Number", caller_profile->destination_number);
}
}
SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_core_session *session,
char *extension_name,
char *extension_number
@ -117,3 +144,4 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session
}

View File

@ -153,7 +153,7 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d
if (bytes && switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header(event, "dtmf_string", dtmf);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-String", dtmf);
switch_event_fire(&event);
}
@ -405,59 +405,21 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
caller_profile = switch_channel_get_caller_profile(channel);
originator_caller_profile = switch_channel_get_originator_caller_profile(channel);
switch_event_add_header(event, "channel_state", (char *) switch_channel_state_name(channel->state));
switch_event_add_header(event, "channel_name", switch_channel_get_name(channel));
switch_event_add_header(event, "unique_id", switch_core_session_get_uuid(channel->session));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
/* Index Caller's Profile */
if (caller_profile) {
if (caller_profile->dialplan) {
switch_event_add_header(event, "channel_dialplan", caller_profile->dialplan);
}
if (caller_profile->caller_id_name) {
switch_event_add_header(event, "channel_caller_id_name", caller_profile->caller_id_name);
}
if (caller_profile->caller_id_number) {
switch_event_add_header(event, "channel_caller_id_number", caller_profile->caller_id_number);
}
if (caller_profile->network_addr) {
switch_event_add_header(event, "channel_network_addr", caller_profile->network_addr);
}
if (caller_profile->ani) {
switch_event_add_header(event, "channel_ani", caller_profile->ani);
}
if (caller_profile->ani2) {
switch_event_add_header(event, "channel_ani2", caller_profile->ani2);
}
if (caller_profile->destination_number) {
switch_event_add_header(event, "channel_destination_number", caller_profile->destination_number);
}
switch_caller_profile_event_set_data(caller_profile, event);
}
/* Index Originator's Profile */
if (originator_caller_profile) {
if (originator_caller_profile->dialplan) {
switch_event_add_header(event, "channel_dialplan", originator_caller_profile->dialplan);
}
if (originator_caller_profile->caller_id_name) {
switch_event_add_header(event, "channel_caller_id_name", originator_caller_profile->caller_id_name);
}
if (originator_caller_profile->caller_id_number) {
switch_event_add_header(event, "channel_caller_id_number", originator_caller_profile->caller_id_number);
}
if (originator_caller_profile->network_addr) {
switch_event_add_header(event, "channel_network_addr", originator_caller_profile->network_addr);
}
if (originator_caller_profile->ani) {
switch_event_add_header(event, "channel_ani", originator_caller_profile->ani);
}
if (originator_caller_profile->ani2) {
switch_event_add_header(event, "channel_ani2", originator_caller_profile->ani2);
}
if (originator_caller_profile->destination_number) {
switch_event_add_header(event, "channel_destination_number", originator_caller_profile->destination_number);
}
switch_caller_profile_event_set_data(originator_caller_profile, event);
}
/* Index Variables */
for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) {
char buf[1024];
@ -465,7 +427,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
switch_hash_this(hi, &var, NULL, &val);
subclass = val;
snprintf(buf, sizeof(buf), "variable_%s", (char *) var);
switch_event_add_header(event, buf, (char *) val);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, buf, (char *) val);
}

View File

@ -87,19 +87,12 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
int ret = 0;
va_list ap;
FILE *handle;
char *filep = file, *p;
char *filep = switch_cut_path(file);
va_start(ap, fmt);
handle = switch_core_data_channel(channel);
while((p = strchr(filep, '/'))) {
filep = p + 1;
}
while((p = strchr(filep, '\\'))) {
filep = p + 1;
}
#ifdef HAVE_VASPRINTF
ret = vasprintf(&data, fmt, ap);
#else
@ -129,10 +122,10 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
switch_event_running() == SWITCH_STATUS_SUCCESS &&
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "log_data", "%s", data);
switch_event_add_header(event, "log_file", "%s", filep);
switch_event_add_header(event, "log_function", "%s", func);
switch_event_add_header(event, "log_line", "%d", line);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_fire(&event);
}
free(data);

View File

@ -97,7 +97,6 @@ static char *EVENT_NAMES[] = {
"ANSWER_CHAN",
"HANGUP_CHAN",
"STARTUP",
"EVENT_SHUTDOWN",
"SHUTDOWN",
"ALL"
};
@ -234,13 +233,6 @@ SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner
SWITCH_DECLARE(switch_status) switch_event_shutdown(void)
{
switch_event *event;
if (switch_event_create(&event, SWITCH_EVENT_EVENT_SHUTDOWN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "Event System Shutting Down");
switch_event_fire(&event);
}
THREAD_RUNNING = -1;
while(THREAD_RUNNING) {
@ -327,7 +319,7 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
return NULL;
}
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char *header_name, char *fmt, ...)
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...)
{
int ret = 0;
char data[2048];
@ -351,15 +343,18 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char
header->name = DUP(header_name);
header->value = DUP(data);
for (hp = event->headers; hp && hp->next; hp = hp->next);
if (hp) {
hp->next = header;
} else {
if (stack = SWITCH_STACK_TOP) {
header->next = event->headers;
event->headers = header;
}
} else {
for (hp = event->headers; hp && hp->next; hp = hp->next);
if (hp) {
hp->next = header;
} else {
event->headers = header;
}
}
return SWITCH_STATUS_SUCCESS;
}
@ -444,7 +439,7 @@ SWITCH_DECLARE(switch_status) switch_event_dup(switch_event **event, switch_even
SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *buf, size_t buflen, char *fmt, ...)
{
size_t len;
size_t len = 0;
switch_event_header *hp;
char *data = NULL, *body = NULL;
int ret = 0;
@ -464,12 +459,6 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
}
snprintf(buf, buflen, "event_name: %s\n", switch_event_name(event->event_id));
len = strlen(buf);
if (event->subclass) {
snprintf(buf+len, buflen-len, "subclass-name: %s\nowner: %s", event->subclass->name, event->subclass->owner);
}
len = strlen(buf);
for (hp = event->headers; hp; hp = hp->next) {
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
len = strlen(buf);
@ -518,17 +507,21 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func,
}
switch_rfc822_date(date, switch_time_now());
switch_event_add_header(*event, "event_date_gmt", date);
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Line-Number", "%d", line);
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-Function", func);
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Calling-File", switch_cut_path(file));
switch_time_exp_lt(&tm, switch_time_now());
switch_strftime(date, &retsize, sizeof(date), "%a, %d-%b-%Y %X", &tm);
switch_event_add_header(*event, "event_date_local", date);
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-Local", date);
switch_rfc822_date(date, switch_time_now());
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Date-GMT", date);
if ((*event)->subclass) {
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass", (*event)->subclass->name);
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Subclass-Owner", (*event)->subclass->owner);
}
switch_event_add_header(*event, SWITCH_STACK_TOP, "Event-Name", switch_event_name((*event)->event_id));
switch_event_add_header(*event, "event_file", file);
switch_event_add_header(*event, "event_function", func);
switch_event_add_header(*event, "event_line_number", "%d", line);
if (user_data) {
(*event)->event_user_data = user_data;
}

View File

@ -422,10 +422,10 @@ SWITCH_DECLARE(switch_status) switch_api_execute(char *cmd, char *arg, char *ret
if (switch_event_create(&event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
if (cmd) {
switch_event_add_header(event, "re_command", cmd);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "API-Command", cmd);
}
if (arg) {
switch_event_add_header(event, "re_command_arg", arg);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "API-Command-Arguement", arg);
}
switch_event_add_body(event, retbuf);
switch_event_fire(&event);

View File

@ -31,6 +31,22 @@
*/
#include <switch_utils.h>
SWITCH_DECLARE(char *) switch_cut_path(char *in)
{
char *p, *ret = in;
char delims[] = "/\\";
char *i;
for(i = delims; *i; i++) {
p = in;
while((p = strchr(p, *i))) {
ret = ++p;
}
}
return ret;
}
SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len)
{
int i;