SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping_internal(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t * external_port, switch_bool_t sticky, switch_bool_t publish) { switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; switch (nat_globals.nat_type) { case SWITCH_NAT_TYPE_PMP: status = switch_nat_add_mapping_pmp(port, proto, external_port); break; case SWITCH_NAT_TYPE_UPNP: if ((status = switch_nat_add_mapping_upnp(port, proto)) == SWITCH_STATUS_SUCCESS) { if (external_port) { *external_port = port; } } break; default: break; } if (publish && status == SWITCH_STATUS_SUCCESS) { switch_event_create(&event, SWITCH_EVENT_NAT); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "op", "add"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "port", "%d", port); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "%d", proto); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sticky", (sticky ? "true" : "false")); switch_event_fire(&event); } return status; }
bool WSClientParser::ws_disconnect() { switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event; if ( (status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, WS_EVENT_MAINT)) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "User", mpUser); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Domain", mpDomain); status = switch_event_fire(&event); } if( status != SWITCH_STATUS_SUCCESS ) { switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->uuid), SWITCH_LOG_ERROR, "WSClientParser::ws_disconnect( " "[Send event Fail], " "this : %p, " "user : '******', " "domain : '%s' " ") \n", this, mpUser, mpDomain ); } return status == SWITCH_STATUS_SUCCESS; }
static switch_status_t http_sendfile_test_file_open(http_sendfile_data_t *http_data, switch_event_t *event) { switch_status_t retval = switch_file_open(&http_data->file_handle, http_data->filename_element, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD,http_data->pool); if(retval != SWITCH_STATUS_SUCCESS) { if(switch_test_flag(http_data, CSO_EVENT)) { if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, HTTP_SENDFILE_ACK_EVENT) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Command-Execution-Identifier", http_data->identifier_str); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Filename", http_data->filename_element); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "File-Access", "Failure"); switch_event_fire(&event); switch_event_destroy(&event); } else switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create event to notify of failure to open file %s\n", http_data->filename_element); } if((switch_test_flag(http_data, CSO_STREAM) || switch_test_flag(http_data, CSO_NONE)) && http_data->stream) http_data->stream->write_function(http_data->stream, "-Err Unable to open file %s\n", http_data->filename_element); if(switch_test_flag(http_data, CSO_NONE) && !http_data->stream) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "curl_sendfile: Unable to open file %s\n", http_data->filename_element); } return retval; }
static void send_report(switch_event_t *event, const char * Status) { switch_event_t *report = NULL; switch_event_header_t *header; if (switch_event_create_subclass(&report, SWITCH_EVENT_CUSTOM, MY_EVENT_DELIVERY_REPORT) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(report, SWITCH_STACK_BOTTOM, "Status", Status); for (header = event->headers; header; header = header->next) { if (!strcmp(header->name, "Event-Subclass")) { continue; } if (!strcmp(header->name, "Event-Name")) { continue; } if (header->idx) { int i; for (i = 0; i < header->idx; i++) { switch_event_add_header_string(report, SWITCH_STACK_PUSH, header->name, header->array[i]); } } else { switch_event_add_header_string(report, SWITCH_STACK_BOTTOM, header->name, header->value); } } switch_event_fire(&report); } }
SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_group(const char *group) { switch_scheduler_task_container_t *tp; switch_event_t *event; uint32_t delcnt = 0; switch_mutex_lock(globals.task_mutex); for (tp = globals.task_list; tp; tp = tp->next) { if (!zstr(group) && !strcmp(tp->task.group, group)) { if (switch_test_flag(tp, SSHF_NO_DEL)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeletable task #%u (group %s)\n", tp->task.task_id, group); continue; } if (switch_event_create(&event, SWITCH_EVENT_DEL_SCHEDULE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Desc", tp->desc); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Group", switch_str_nil(tp->task.group)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime); switch_event_fire(&event); } tp->destroyed++; delcnt++; } } switch_mutex_unlock(globals.task_mutex); return delcnt; }
/* send a message to every member of the conference */ void conference_event_chat_message_broadcast(conference_obj_t *conference, switch_event_t *event) { conference_member_t *member = NULL; switch_event_t *processed; switch_assert(conference != NULL); switch_event_create(&processed, SWITCH_EVENT_CHANNEL_DATA); switch_mutex_lock(conference->member_mutex); for (member = conference->members; member; member = member->next) { if (member->session && !conference_utils_member_test_flag(member, MFLAG_NOCHANNEL)) { const char *presence_id = switch_channel_get_variable(member->channel, "presence_id"); const char *chat_proto = switch_channel_get_variable(member->channel, "chat_proto"); switch_event_t *reply = NULL; if (presence_id && chat_proto) { if (switch_event_get_header(processed, presence_id)) { continue; } switch_event_dup(&reply, event); switch_event_add_header_string(reply, SWITCH_STACK_BOTTOM, "to", presence_id); switch_event_add_header_string(reply, SWITCH_STACK_BOTTOM, "conference_name", conference->name); switch_event_add_header_string(reply, SWITCH_STACK_BOTTOM, "conference_domain", conference->domain); switch_event_set_body(reply, switch_event_get_body(event)); switch_core_chat_deliver(chat_proto, &reply); switch_event_add_header_string(processed, SWITCH_STACK_BOTTOM, presence_id, "true"); } } } switch_event_destroy(&processed); switch_mutex_unlock(conference->member_mutex); }
static void switch_scheduler_execute(switch_scheduler_task_container_t *tp) { switch_event_t *event; //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing task %u %s (%s)\n", tp->task.task_id, tp->desc, switch_str_nil(tp->task.group)); tp->func(&tp->task); if (tp->task.repeat) { tp->task.runtime = switch_epoch_time_now(NULL) + tp->task.repeat; } if (tp->task.runtime > tp->executed) { tp->executed = 0; if (switch_event_create(&event, SWITCH_EVENT_RE_SCHEDULE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Desc", tp->desc); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Group", switch_str_nil(tp->task.group)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime); switch_queue_push(globals.event_queue, event); event = NULL; } } else { tp->destroyed = 1; } }
void conference_loop_exec_app(conference_member_t *member, caller_control_action_t *action) { char *app = NULL; char *arg = ""; char *argv[2] = { 0 }; int argc; char *mydata = NULL; switch_event_t *event = NULL; switch_channel_t *channel = NULL; if (!action->expanded_data) return; if (test_eflag(member->conference, EFLAG_DTMF) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_member_add_event_data(member, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "execute_app"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", action->expanded_data); switch_event_fire(&event); } mydata = strdup(action->expanded_data); switch_assert(mydata); if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { if (argc > 0) { app = argv[0]; } if (argc > 1) { arg = argv[1]; } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Empty execute app string [%s]\n", (char *) action->expanded_data); goto done; } if (!app) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Unable to find application.\n"); goto done; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_INFO, "Execute app: %s, %s\n", app, arg); channel = switch_core_session_get_channel(member->session); switch_channel_set_app_flag(channel, CF_APP_TAGGED); switch_core_session_set_read_codec(member->session, NULL); switch_core_session_execute_application(member->session, app, arg); switch_core_session_set_read_codec(member->session, &member->read_codec); switch_channel_clear_app_flag(channel, CF_APP_TAGGED); done: switch_safe_free(mydata); return; }
/** * Process a buffer of audio data for call progress tones * * @param bug the session's media bug * @param user_data the detector * @param type the type of data available from the bug * @return SWITCH_TRUE */ static switch_bool_t callprogress_detector_process_buffer(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type) { uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; switch_frame_t frame = { 0 }; tone_detector_t *detector = (tone_detector_t *)user_data; switch_core_session_t *session = switch_core_media_bug_get_session(bug); switch_channel_t *channel = switch_core_session_get_channel(session); frame.data = data; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch(type) { case SWITCH_ABC_TYPE_INIT: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) initializing tone detector\n", switch_channel_get_name(channel)); tone_detector_init(detector); break; case SWITCH_ABC_TYPE_READ: { const char *detected_tone = NULL; if (!detector->spandsp_detector) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) detector is destroyed\n", switch_channel_get_name(channel)); return SWITCH_FALSE; } if (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) error reading frame\n", switch_channel_get_name(channel)); return SWITCH_FALSE; } tone_detector_process_buffer(detector, frame.data, frame.samples, &detected_tone); if (detected_tone) { switch_event_t *event = NULL; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) DETECTED TONE: %s\n", switch_channel_get_name(channel), detected_tone); if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", detected_tone); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session)); switch_event_fire(&event); } } break; } case SWITCH_ABC_TYPE_WRITE: break; case SWITCH_ABC_TYPE_WRITE_REPLACE: break; case SWITCH_ABC_TYPE_READ_REPLACE: break; case SWITCH_ABC_TYPE_READ_PING: break; case SWITCH_ABC_TYPE_CLOSE: if (detector->spandsp_detector) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) destroying tone detector\n", switch_channel_get_name(channel)); tone_detector_destroy(detector); } break; } return SWITCH_TRUE; }
bool WSClientParser::Login() { switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->uuid), SWITCH_LOG_INFO, "WSClientParser::Login( " "this : %p, " "user : '******', " "domain : '%s', " "site : '%s', " "custom : '%s' " ") \n", this, mpUser, mpDomain, mpSite, mpCustom ); bool bFlag = true; // 暂时不做PHP验证 switch_event_t *locate_params; switch_xml_t xml = NULL; switch_event_create(&locate_params, SWITCH_EVENT_GENERAL); switch_assert(locate_params); switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "source", "mod_ws"); switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "site", mpSite); switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "custom", mpCustom); /* Locate user */ if (switch_xml_locate_user_merged("id", mpUser, mpDomain, NULL, &xml, locate_params) != SWITCH_STATUS_SUCCESS) { switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->uuid), SWITCH_LOG_ERROR, "WSClientParser::Login( " "[Fail], " "this : %p, " "user : '******', " "domain : '%s' ", this, mpUser, mpDomain ); bFlag = false; } switch_event_destroy(&locate_params); // 发送登录成功事件 ws_login(); return bFlag; }
SWITCH_DECLARE(uint32_t) switch_scheduler_add_task(time_t task_runtime, switch_scheduler_func_t func, const char *desc, const char *group, uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags) { switch_scheduler_task_container_t *container, *tp; switch_event_t *event; switch_time_t now = switch_epoch_time_now(NULL); switch_ssize_t hlen = -1; switch_mutex_lock(globals.task_mutex); switch_zmalloc(container, sizeof(*container)); switch_assert(func); if (task_runtime < now) { container->task.repeat = (uint32_t)task_runtime; task_runtime += now; } container->func = func; container->task.created = now; container->task.runtime = task_runtime; container->task.group = strdup(group ? group : "none"); container->task.cmd_id = cmd_id; container->task.cmd_arg = cmd_arg; container->flags = flags; container->desc = strdup(desc ? desc : "none"); container->task.hash = switch_ci_hashfunc_default(container->task.group, &hlen); for (tp = globals.task_list; tp && tp->next; tp = tp->next); if (tp) { tp->next = container; } else { globals.task_list = container; } for (container->task.task_id = 0; !container->task.task_id; container->task.task_id = ++globals.task_id); switch_mutex_unlock(globals.task_mutex); tp = container; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Added task %u %s (%s) to run at %" SWITCH_INT64_T_FMT "\n", tp->task.task_id, tp->desc, switch_str_nil(tp->task.group), tp->task.runtime); if (switch_event_create(&event, SWITCH_EVENT_ADD_SCHEDULE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Desc", tp->desc); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Group", switch_str_nil(tp->task.group)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime); switch_queue_push(globals.event_queue, event); event = NULL; } return container->task.task_id; }
void conference_loop_event(conference_member_t *member, caller_control_action_t *action) { switch_event_t *event; if (test_eflag(member->conference, EFLAG_DTMF) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_member_add_event_data(member, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "dtmf"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "DTMF-Key", action->binded_dtmf); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Data", action->expanded_data); switch_event_fire(&event); } }
switch_status_t conference_event_add_data(conference_obj_t *conference, switch_event_t *event) { switch_status_t status = SWITCH_STATUS_SUCCESS; switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Size", "%u", conference->count); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Ghosts", "%u", conference->count_ghosts); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Profile-Name", conference->profile_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Unique-ID", conference->uuid_str); return status; }
cc_status_t cc_agent_get(const char *key, const char *agent, char *ret_result, size_t ret_result_size) { cc_status_t result = CC_STATUS_SUCCESS; char *sql; switch_event_t *event; char res[256]; /* Check to see if agent already exists */ sql = switch_mprintf("SELECT count(*) FROM agents WHERE name = '%q'", agent); cc_execute_sql2str(NULL, NULL, sql, res, sizeof(res)); switch_safe_free(sql); if (atoi(res) == 0) { result = CC_STATUS_AGENT_NOT_FOUND; goto done; } if (!strcasecmp(key, "status") || !strcasecmp(key, "state") || !strcasecmp(key, "uuid") ) { /* Check to see if agent already exists */ sql = switch_mprintf("SELECT %q FROM agents WHERE name = '%q'", key, agent); cc_execute_sql2str(NULL, NULL, sql, res, sizeof(res)); switch_safe_free(sql); switch_snprintf(ret_result, ret_result_size, "%s", res); result = CC_STATUS_SUCCESS; if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CALLCENTER_EVENT) == SWITCH_STATUS_SUCCESS) { char tmpname[256]; if (!strcasecmp(key, "uuid")) { switch_snprintf(tmpname, sizeof(tmpname), "CC-Agent-UUID"); } else { switch_snprintf(tmpname, sizeof(tmpname), "CC-Agent-%c%s", (char) switch_toupper(key[0]), key+1); } switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Agent", agent); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "CC-Action", "agent-%s-get", key); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, tmpname, res); switch_event_fire(&event); } } else { result = CC_STATUS_INVALID_KEY; goto done; } done: if (result == CC_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Get Info Agent %s %s = %s\n", agent, key, res); } return result; }
/* * chiedo alla patch tutte le chiamate. Probabilmente ritorna una una insert con tutte le chiamate da inserire. * usata all'avvio di un nuovo nodo che deve ricostrurie lo stato delle chiamate in corso alla sua accensione. */ void utils_send_request_all(char *profile_name) { switch_event_t *event = NULL; if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "sofia::recovery_recv") == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "profile_name", profile_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "request_all","true"); switch_event_fire(&event); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "request_all sent to sofia\n"); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "request_all not sent to sofia\n"); } }
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *fmt, ...) { char *data = NULL; int ret = 0; va_list ap; FILE *handle = switch_core_data_channel(channel); const char *filep = switch_cut_path(file); char date[80] = ""; switch_size_t retsize; switch_time_exp_t tm; switch_event_t *event; va_start(ap, fmt); ret = switch_vasprintf(&data, fmt, ap); va_end(ap); if (ret == -1) { fprintf(stderr, "Memory Error\n"); goto done; } if (channel == SWITCH_CHANNEL_ID_LOG_CLEAN) { fprintf(handle, "%s", data); goto done; } switch_time_exp_lt(&tm, switch_micro_time_now()); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); if (channel == SWITCH_CHANNEL_ID_LOG) { fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data); goto done; } if (channel == SWITCH_CHANNEL_ID_EVENT && switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Log-Data", data); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Log-File", filep); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Log-Function", func); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line); switch_event_fire(&event); } done: if (data) { free(data); } fflush(handle); }
SWITCH_DECLARE(void) switch_limit_fire_event(const char *backend, const char *realm, const char *key, uint32_t usage, uint32_t rate, uint32_t max, uint32_t ratemax) { switch_event_t *event; if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, LIMIT_EVENT_USAGE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "backend", backend); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "realm", realm); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", key); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "usage", "%d", usage); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rate", "%d", rate); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "max", "%d", max); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "ratemax", "%d", ratemax); switch_event_fire(&event); } }
void append_event_message(switch_core_session_t *session, vmivr_profile_t *profile, switch_event_t *phrase_params, switch_event_t *msg_list_event, size_t current_msg) { char *varname; char *apicmd; char *total_msg = NULL; if (!msg_list_event || !(total_msg = switch_event_get_header(msg_list_event, "VM-List-Count")) || current_msg > atoi(total_msg)) { /* TODO Error MSG */ return; } varname = switch_mprintf("VM-List-Message-%" SWITCH_SIZE_T_FMT "-UUID", current_msg); apicmd = switch_mprintf("json %s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(msg_list_event, varname)); switch_safe_free(varname); jsonapi2event(session, phrase_params, profile->api_msg_get, apicmd); /* TODO Set these 2 header correctly */ switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Message-Type", "%s", "new"); switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Message-Number", "%"SWITCH_SIZE_T_FMT, current_msg); switch_event_add_header_string(phrase_params, SWITCH_STACK_BOTTOM, "VM-Message-Private-Local-Copy", "False"); switch_safe_free(apicmd); }
void conference_loop_energy_dn(conference_member_t *member, caller_control_action_t *action) { char msg[512], str[30] = "", *p; switch_event_t *event; if (member == NULL) return; member->energy_level -= 200; if (member->energy_level < 0) { member->energy_level = 0; } if (test_eflag(member->conference, EFLAG_ENERGY_LEVEL) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_member_add_event_data(member, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "energy-level"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level); switch_event_fire(&event); } //switch_snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level); //conference_member_say(member, msg, 0); switch_snprintf(str, sizeof(str), "%d", abs(member->energy_level) / 200); for (p = str; p && *p; p++) { switch_snprintf(msg, sizeof(msg), "digits/%c.wav", *p); conference_member_play_file(member, msg, 0, SWITCH_TRUE); } }
void conference_loop_volume_listen_dn(conference_member_t *member, caller_control_action_t *action) { char msg[512]; switch_event_t *event; if (member == NULL) return; member->volume_in_level--; switch_normalize_volume(member->volume_in_level); if (test_eflag(member->conference, EFLAG_GAIN_LEVEL) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_member_add_event_data(member, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "gain-level"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level); switch_event_fire(&event); } //switch_snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level); //conference_member_say(member, msg, 0); if (member->volume_in_level < 0) { switch_snprintf(msg, sizeof(msg), "currency/negative.wav", member->volume_in_level); conference_member_play_file(member, msg, 0, SWITCH_TRUE); } switch_snprintf(msg, sizeof(msg), "digits/%d.wav", abs(member->volume_in_level)); conference_member_play_file(member, msg, 0, SWITCH_TRUE); }
SWITCH_DECLARE(switch_status_t) switch_nat_del_mapping(switch_port_t port, switch_nat_ip_proto_t proto) { switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; switch (nat_globals.nat_type) { case SWITCH_NAT_TYPE_PMP: status = switch_nat_del_mapping_pmp(port, proto); break; case SWITCH_NAT_TYPE_UPNP: status = switch_nat_del_mapping_upnp(port, proto); break; default: break; } if (status == SWITCH_STATUS_SUCCESS) { switch_event_create(&event, SWITCH_EVENT_NAT); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "op", "del"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "port", "%d", port); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "%d", proto); switch_event_fire(&event); } return status; }
/** * Execute function for each subscriber */ static void subscriber_execute(const char *uuid, const char *signal_type, subscriber_execute_fn callback, void *user_data) { switch_event_t *subscriber_list = NULL; switch_event_header_t *subscriber = NULL; /* fetch list of subscribers */ char *key = switch_mprintf("%s:%s", uuid, signal_type); switch_event_create_subclass(&subscriber_list, SWITCH_EVENT_CLONE, NULL); switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Subscriber execute %s\n", signal_type); switch_mutex_lock(globals.subscribers_mutex); { switch_hash_index_t *hi = NULL; switch_hash_t *signal_subscribers = switch_core_hash_find(globals.subscribers, key); if (signal_subscribers) { for (hi = switch_core_hash_first(signal_subscribers); hi; hi = switch_core_hash_next(hi)) { const void *jid; void *dont_care; switch_core_hash_this(hi, &jid, NULL, &dont_care); switch_event_add_header_string(subscriber_list, SWITCH_STACK_BOTTOM, "execute", (const char *)jid); } } else { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "No subscribers for %s\n", signal_type); } } switch_mutex_unlock(globals.subscribers_mutex); switch_safe_free(key); /* execute function for each subscriber */ for (subscriber = subscriber_list->headers; subscriber; subscriber = subscriber->next) { callback(subscriber->value, user_data); } switch_event_destroy(&subscriber_list); }
SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(switch_core_session_t *session, switch_codec_t *codec) { switch_event_t *event; switch_channel_t *channel = switch_core_session_get_channel(session); char tmp[30]; switch_status_t status = SWITCH_STATUS_SUCCESS; if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) { if (session->video_write_codec) { session->video_write_codec = NULL; status = SWITCH_STATUS_SUCCESS; goto end; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n"); status = SWITCH_STATUS_FALSE; goto end; } if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(session->channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-name", codec->implementation->iananame); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-rate", "%d", codec->implementation->actual_samples_per_second); switch_event_fire(&event); } switch_channel_set_variable(channel, "video_write_codec", codec->implementation->iananame); switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second); switch_channel_set_variable(channel, "video_write_rate", tmp); session->video_write_codec = codec; session->video_write_impl = *codec->implementation; end: return status; }
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData) { switch_hash_index_t *hi = NULL; switch_event_t *event = NULL; switch_event_header_t *header = NULL; switch_status_t status = SWITCH_STATUS_GENERR; switch_event_create_subclass(&event, SWITCH_EVENT_CLONE, NULL); switch_assert(event); /* iterate through the hash, call callback, if callback returns NULL or true, put the key on the list (event) When done, iterate through the list deleting hash entries */ for (hi = switch_hash_first(NULL, hash); hi; hi = switch_hash_next(hi)) { const void *key; void *val; switch_hash_this(hi, &key, NULL, &val); if (!callback || callback(key, val, pData)) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delete", (const char *) key); } } /* now delete them */ for (header = event->headers; header; header = header->next) { if (switch_core_hash_delete(hash, header->value) == SWITCH_STATUS_SUCCESS) { status = SWITCH_STATUS_SUCCESS; } } switch_event_destroy(&event); return status; }
static switch_status_t http_stream_write(switch_stream_handle_t *handle, const char *fmt, ...) { TSession *r = (TSession *) handle->data; int ret = 1; char *data; switch_event_t *evnt = handle->param_event; va_list ap; va_start(ap, fmt); ret = switch_vasprintf(&data, fmt, ap); va_end(ap); if (data) { /* Stream Content-Type (http header) to the xmlrpc (web) client, if fs api command did not do it yet. */ /* If (Content-Type in event) then the header was already replied. */ /* If fs api command is not "web aware", this will set the Content-Type to "text/plain". */ const char *http_refresh = NULL; const char *ct = NULL; const char *refresh = NULL; if (evnt && !(ct = switch_event_get_header(evnt, "Content-Type"))){ const char *val = switch_stristr("Content-Type", data); if (!val) { val = "Content-Type: text/plain\r\n\r\n"; ret = HTTPWrite(r, val, (uint32_t) strlen(val)); } /* flag to prevent running this more than once per http reply */ switch_event_add_header_string(evnt, SWITCH_STACK_BOTTOM, "Content-Type", strstr(val,":")+2); ct = switch_event_get_header(evnt, "Content-Type"); } if (ret) { ret = HTTPWrite(r, data, (uint32_t) strlen(data)); } switch_safe_free(data); /* e.g. "http://www.cluecon.fs/api/show?calls &refresh=5" */ /* fs api command can set event header "HTTP-REFRESH" so that the web page will automagically refresh, if */ /* "refresh=xxx" was part of the http query kv pairs */ if (ret && ct && *ct && (http_refresh = switch_event_get_header(evnt, "HTTP-REFRESH")) && (refresh = switch_event_get_header(evnt, "refresh")) && !strstr("text/html", ct) && (atoi(refresh) > 0 )) { const char *query = switch_event_get_header(evnt, "HTTP-QUERY"); const char *uri = switch_event_get_header(evnt, "HTTP-URI"); if (uri && query && *uri && *query) { char *buf = switch_mprintf("<META HTTP-EQUIV=REFRESH CONTENT=\"%s; URL=%s?%s\">\n", refresh, uri, query); ret = HTTPWrite(r, buf, (uint32_t) strlen(buf)); switch_safe_free(buf); } } /* only one refresh meta header per reply */ if (http_refresh) { switch_event_del_header(evnt, "HTTP-REFRESH"); } } return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS; }
void conference_loop_transfer(conference_member_t *member, caller_control_action_t *action) { char *exten = NULL; char *dialplan = "XML"; char *context = "default"; char *argv[3] = { 0 }; int argc; char *mydata = NULL; switch_event_t *event; if (test_eflag(member->conference, EFLAG_DTMF) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_member_add_event_data(member, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "transfer"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Dialplan", action->expanded_data); switch_event_fire(&event); } conference_utils_member_clear_flag_locked(member, MFLAG_RUNNING); if ((mydata = switch_core_session_strdup(member->session, action->expanded_data))) { if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { if (argc > 0) { exten = argv[0]; } if (argc > 1) { dialplan = argv[1]; } if (argc > 2) { context = argv[2]; } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Empty transfer string [%s]\n", (char *) action->expanded_data); goto done; } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Unable to allocate memory to duplicate transfer data.\n"); goto done; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_INFO, "Transfering to: %s, %s, %s\n", exten, dialplan, context); switch_ivr_session_transfer(member->session, exten, dialplan, context); done: return; }
/** * Process a buffer of audio data for call progress tones * * @param bug the session's media bug * @param user_data the detector * @param type the type of data available from the bug * @return SWITCH_TRUE */ static switch_bool_t callprogress_detector_process_buffer(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type) { tone_detector_t *detector = (tone_detector_t *)user_data; switch_core_session_t *session = detector->session; switch(type) { case SWITCH_ABC_TYPE_INIT: switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "initializing tone detector\n"); tone_detector_init(detector); break; case SWITCH_ABC_TYPE_READ_REPLACE: { switch_frame_t *frame; const char *detected_tone = NULL; if (!detector->spandsp_detector) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "detector is destroyed\n"); return SWITCH_FALSE; } if (!(frame = switch_core_media_bug_get_read_replace_frame(bug))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "error reading frame\n"); return SWITCH_FALSE; } tone_detector_process_buffer(detector, frame->data, frame->samples, &detected_tone); if (detected_tone) { switch_event_t *event = NULL; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "DETECTED TONE: %s\n", detected_tone); if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", detected_tone); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session)); switch_event_fire(&event); } } break; } case SWITCH_ABC_TYPE_CLOSE: if (detector->spandsp_detector) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "destroying tone detector\n"); tone_detector_destroy(detector); } break; default: break; } return SWITCH_TRUE; }
static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf) { char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1]; int headerlength; if (ei_decode_string_or_binary(buf->buff, &buf->index, SWITCH_UUID_FORMATTED_LENGTH, uuid) || ei_decode_list_header(buf->buff, &buf->index, &headerlength)) { ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "badarg"); } else { switch_core_session_t *session; if (!zstr_buf(uuid) && (session = switch_core_session_locate(uuid))) { switch_event_t *event; if (switch_event_create(&event, SWITCH_EVENT_SEND_MESSAGE) == SWITCH_STATUS_SUCCESS) { char key[1024]; char value[1024]; int i = 0; switch_bool_t fail = SWITCH_FALSE; while (!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) { i++; if (ei_decode_string(buf->buff, &buf->index, key) || ei_decode_string(buf->buff, &buf->index, value)) { fail = SWITCH_TRUE; break; } switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, key, value); } if (headerlength != i || fail) { ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "badarg"); } else { if (switch_core_session_queue_private_event(session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { 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, "badmem"); } } } /* release the lock returned by session locate */ switch_core_session_rwunlock(session); } else { ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "nosession"); } } return SWITCH_STATUS_SUCCESS; }
static void put_text_msg(void *user_data, const uint8_t *msg, int len) { switch_tdd_t *pvt = (switch_tdd_t *) user_data; switch_event_t *event, *clone; switch_channel_t *channel = switch_core_session_get_channel(pvt->session); switch_core_session_t *other_session; switch_channel_add_variable_var_check(channel, "tdd_messages", (char *)msg, SWITCH_FALSE, SWITCH_STACK_PUSH); if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_TDD_RECV_MESSAGE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", "mod_spandsp"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "tdd"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "TDD MESSAGE"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "TDD-Data", (char *)msg); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(pvt->session)); switch_event_add_body(event, "%s\n\n", (char *)msg); if (switch_core_session_get_partner(pvt->session, &other_session) == SWITCH_STATUS_SUCCESS) { if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { switch_core_session_receive_event(other_session, &clone); } if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { switch_core_session_queue_event(other_session, &clone); } switch_core_session_rwunlock(other_session); } switch_event_fire(&event); } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "%s got TDD Message [%s]\n", switch_channel_get_name(channel), (char *)msg); }
SWITCH_DECLARE(bool) Event::addHeader(const char *header_name, const char *value) { this_check(false); if (event) { return switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, value) == SWITCH_STATUS_SUCCESS ? true : false; } else { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to addHeader an event that does not exist!\n"); } return false; }