return SWITCH_STATUS_SUCCESS;
}
+static switch_status_t handle_msg_session_event(listener_t *listener, erlang_msg *msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
+{
+ char atom[MAXATOMLEN];
+
+ if (arity == 1) {
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "badarg");
+ } else {
+ session_elem_t *session;
+ if ((session = find_session_elem_by_pid(listener, &msg->from))) {
+
+ int custom = 0;
+ switch_event_types_t type;
+ int i = 0;
+
+ for (i = 1; i < arity; i++) {
+ if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
+
+ if (custom) {
+ switch_core_hash_insert(session->event_hash, atom, MARKER);
+ } else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
+ if (type == SWITCH_EVENT_ALL) {
+ uint32_t x = 0;
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ALL events enabled for %s\n", session->uuid_str);
+ for (x = 0; x < SWITCH_EVENT_ALL; x++) {
+ session->event_list[x] = 1;
+ }
+ }
+ if (type <= SWITCH_EVENT_ALL) {
+ session->event_list[type] = 1;
+ }
+ if (type == SWITCH_EVENT_CUSTOM) {
+ custom++;
+ }
+
+ }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "enable event %s for session %s\n", atom, session->uuid_str);
+ }
+ }
+ ei_x_encode_atom(rbuf, "ok");
+ } else {
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "notlistening");
+ }
+ }
+ return SWITCH_STATUS_SUCCESS;
+}
+
static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char atom[MAXATOMLEN];
return SWITCH_STATUS_SUCCESS;
}
+static switch_status_t handle_msg_session_nixevent(listener_t *listener, erlang_msg *msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
+{
+ char atom[MAXATOMLEN];
+
+ if (arity == 1) {
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "badarg");
+ } else {
+ session_elem_t *session;
+ if ((session = find_session_elem_by_pid(listener, &msg->from))) {
+ int custom = 0;
+ int i = 0;
+ switch_event_types_t type;
+
+ for (i = 1; i < arity; i++) {
+ if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
+
+ if (custom) {
+ switch_core_hash_delete(session->event_hash, atom);
+ } else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
+ uint32_t x = 0;
+
+ if (type == SWITCH_EVENT_CUSTOM) {
+ custom++;
+ } else if (type == SWITCH_EVENT_ALL) {
+ for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
+ session->event_list[x] = 0;
+ }
+ } else {
+ if (session->event_list[SWITCH_EVENT_ALL]) {
+ session->event_list[SWITCH_EVENT_ALL] = 0;
+ for (x = 0; x < SWITCH_EVENT_ALL; x++) {
+ session->event_list[x] = 1;
+ }
+ }
+ session->event_list[type] = 0;
+ }
+ }
+ }
+ }
+ ei_x_encode_atom(rbuf, "ok");
+ } else { /* no session for this pid */
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "notlistening");
+ }
+ }
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
static switch_status_t handle_msg_api(listener_t *listener, erlang_msg * msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char api_cmd[MAXATOMLEN];
ret = handle_msg_set_log_level(listener, arity, buf, rbuf);
} else if (!strncmp(tupletag, "event", MAXATOMLEN)) {
ret = handle_msg_event(listener, arity, buf, rbuf);
+ } else if (!strncmp(tupletag, "session_event", MAXATOMLEN)) {
+ ret = handle_msg_session_event(listener, msg, arity, buf, rbuf);
} else if (!strncmp(tupletag, "nixevent", MAXATOMLEN)) {
ret = handle_msg_nixevent(listener, arity, buf, rbuf);
+ } else if (!strncmp(tupletag, "session_nixevent", MAXATOMLEN)) {
+ ret = handle_msg_session_nixevent(listener, msg, arity, buf, rbuf);
} else if (!strncmp(tupletag, "api", MAXATOMLEN)) {
ret = handle_msg_api(listener, msg, arity, buf, rbuf);
} else if (!strncmp(tupletag, "bgapi", MAXATOMLEN)) {
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "notlistening");
}
+ } else if (!strncmp(atom, "session_noevents", MAXATOMLEN)) {
+ session_elem_t *session;
+ if ((session = find_session_elem_by_pid(listener, &msg->from))) {
+ void *pop;
+ uint8_t x = 0;
+
+ /*purge the event queue */
+ while (switch_queue_trypop(session->event_queue, &pop) == SWITCH_STATUS_SUCCESS);
+ for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
+ session->event_list[x] = 0;
+ }
+ /* wipe the hash */
+ switch_core_hash_destroy(&session->event_hash);
+ switch_core_hash_init(&session->event_hash, session->pool);
+ ei_x_encode_atom(rbuf, "ok");
+ } else {
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "notlistening");
+ }
} else if (!strncmp(atom, "exit", MAXATOMLEN)) {
ei_x_encode_atom(rbuf, "ok");
ret = SWITCH_STATUS_TERM;
}
if ((s = (session_elem_t*)switch_core_hash_find(listener->sessions, uuid))) {
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Sending event %s to attached session %s\n",
- switch_event_name(event->event_id), s->uuid_str);
- if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
- /* add the event to the queue for this session */
- if (switch_queue_trypush(s->event_queue, clone) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_ERROR, "Lost event!\n");
- switch_event_destroy(&clone);
+ int send = 0;
+ if (s->event_list[SWITCH_EVENT_ALL]) {
+ send = 1;
+ } else if ((s->event_list[event->event_id])) {
+ if (event->event_id != SWITCH_EVENT_CUSTOM || !event->subclass_name || (switch_core_hash_find(s->event_hash, event->subclass_name))) {
+ send = 1;
+ }
+ }
+
+ if (send) {
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Sending event %s to attached session %s\n",
+ switch_event_name(event->event_id), s->uuid_str);
+ if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
+ /* add the event to the queue for this session */
+ if (switch_queue_trypush(s->event_queue, clone) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_ERROR, "Lost event!\n");
+ switch_event_destroy(&clone);
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_ERROR, "Memory Error!\n");
}
} else {
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_ERROR, "Memory Error!\n");
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Ignoring event %s for attached session %s\n",
+ switch_event_name(event->event_id), s->uuid_str);
}
}
}