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
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);
#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
#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,
SWITCH_EVENT_ANSWER_CHAN,
SWITCH_EVENT_HANGUP_CHAN,
SWITCH_EVENT_STARTUP,
- SWITCH_EVENT_EVENT_SHUTDOWN,
SWITCH_EVENT_SHUTDOWN,
SWITCH_EVENT_ALL
} switch_event_t;
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) \
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);
}
{
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) {
}
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);
}
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);
}
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
}
+
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);
}
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];
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);
}
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
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);
"ANSWER_CHAN",
"HANGUP_CHAN",
"STARTUP",
- "EVENT_SHUTDOWN",
"SHUTDOWN",
"ALL"
};
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) {
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];
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;
}
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;
}
}
- 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);
}
- 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;
}
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);
*/
#include <switch_utils.h>
+SWITCH_DECLARE(char *) switch_cut_path(char *in)\r
+{\r
+ char *p, *ret = in;\r
+ char delims[] = "/\\";\r
+ char *i;\r
+\r
+ for(i = delims; *i; i++) {\r
+ p = in;\r
+ while((p = strchr(p, *i))) {\r
+ ret = ++p;\r
+ }\r
+ }\r
+ return ret;\r
+}\r
+
+
SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len)
{
int i;