void ei_encode_switch_event_headers(ei_x_buff * ebuf, switch_event_t *event) { int i; char *uuid = switch_event_get_header(event, "unique-id"); switch_event_header_t *hp; for (i = 0, hp = event->headers; hp; hp = hp->next, i++); if (event->body) i++; ei_x_encode_list_header(ebuf, i + 1); if (uuid) { _ei_x_encode_string(ebuf, switch_event_get_header(event, "unique-id")); } else { ei_x_encode_atom(ebuf, "undefined"); } for (hp = event->headers; hp; hp = hp->next) { ei_x_encode_tuple_header(ebuf, 2); _ei_x_encode_string(ebuf, hp->name); switch_url_decode(hp->value); _ei_x_encode_string(ebuf, hp->value); } if (event->body) { ei_x_encode_tuple_header(ebuf, 2); _ei_x_encode_string(ebuf, "body"); _ei_x_encode_string(ebuf, event->body); } ei_x_encode_empty_list(ebuf); }
/*重启服务的通知 */ int cari_net_ne_reboot(int notifyCode, //通知码 switch_event_t *event) //事件 { inner_ResultResponse_Frame *inner_respFrame = NULL; char *result = NULL; char *cmdCode = NULL; char *cmdName = NULL; result = switch_event_get_header(event, CARICCP_RESULTDESC); cmdCode = switch_event_get_header(event, CARICCP_CMDCODE); cmdName = switch_event_get_header(event, CARICCP_CMDNAME); //new响应帧 inner_respFrame = CARI_CCP_VOS_NEW(inner_ResultResponse_Frame); //初始化"内部响应帧"结构体 memset(inner_respFrame, 0, sizeof(inner_ResultResponse_Frame)); //初始化赋值,设置了"通知类型的标识"和"通知码" initInnerResponseFrame(inner_respFrame, event); //将通知类型的事件发送给所有客户端 CMsgProcess::getInstance()->notifyResult(inner_respFrame); //销毁"响应帧" CARI_CCP_VOS_DEL(inner_respFrame); return CARICCP_SUCCESS_STATE_CODE; }
static void event_handler(switch_event_t *event) { const char *dest_proto = switch_event_get_header(event, "dest_proto"); const char *check_failure = switch_event_get_header(event, "Delivery-Failure"); const char *check_nonblocking = switch_event_get_header(event, "Nonblocking-Delivery"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "skip_global_process", "true"); if (switch_true(check_failure)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Delivery Failure\n"); DUMP_EVENT(event); send_report(event, "Failure"); return; } else if ( check_failure && switch_false(check_failure) ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SMS Delivery Success\n"); send_report(event, "Success"); return; } else if ( check_nonblocking && switch_true(check_nonblocking) ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SMS Delivery assumed successful due to being sent in non-blocking manner\n"); send_report(event, "Accepted"); return; } switch_core_chat_send(dest_proto, event); }
/* You can turn on session heartbeat on a channel to have us check billing more often */ static void event_handler(switch_event_t *event) { switch_core_session_t *session; char *uuid; if (!event) { /* We should never get here - it means an event came in without the event info */ return; } /* Make sure everything is sane */ if (!(uuid = switch_event_get_header(event, "Unique-ID"))) { /* Donde esta channel? */ return; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received request via %s!\n", switch_event_name(event->event_id)); /* Display debugging info */ if (switch_event_get_header(event, "nibble_debug")) { debug_event_handler(event); } /* Get session var */ if (!(session = switch_core_session_locate(uuid))) { return; } /* Go bill */ do_billing(session); switch_core_session_rwunlock(session); }
void xpass_encode_switch_event_headers(char *ebuf, int buf_len, switch_event_t *event) { switch_event_header_t *hp; char *uuid = switch_event_get_header(event, "unique-id"); int i; int left_buf_len = buf_len; char * tmp = ebuf; for (i = 0, hp = event->headers; hp; hp = hp->next, i++); if (event->body) i++; if (uuid) { char *unique_id = switch_event_get_header(event, "unique-id"); tmp = encode_data(tmp, unique_id, strlen(unique_id)); } else { tmp = encode_data(tmp, "undefined", 9); } tmp = encode_data(tmp, "\r\n", 2); for (hp = event->headers; hp; hp = hp->next) { tmp = encode_data(tmp, hp->name, strlen(hp->name)); tmp = encode_data(tmp, ":", 1); switch_url_decode(hp->value); tmp = encode_data(tmp, hp->value, strlen(hp->value)); tmp = encode_data(tmp, "\r\n", 2); } tmp = encode_data(tmp, "\r\n", 2); if (event->body) { tmp = encode_data(tmp, event->body, strlen(event->body)); } }
void do_index(switch_stream_handle_t *stream) { switch_cache_db_handle_t *db; const char *sql = "select * from channels"; struct holder holder; char *errmsg; if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) { return; } holder.host = switch_event_get_header(stream->param_event, "http-host"); holder.port = switch_event_get_header(stream->param_event, "http-port"); holder.uri = switch_event_get_header(stream->param_event, "http-uri"); holder.stream = stream; stream->write_function(stream, "Content-type: text/html\r\n\r\n"); stream->write_function(stream, "<table align=center border=1 cellpadding=6 cellspacing=0>" "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", "Created", "CID Name", "CID Num", "Ext", "App", "Data", "Codec", "Rate", "Listen"); switch_cache_db_execute_sql_callback(db, sql, web_callback, &holder, &errmsg); stream->write_function(stream, "</table>"); if (errmsg) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s]\n", errmsg); switch_safe_free(errmsg); } }
void mtvm_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); int retry; vmivr_menu_profile_t menu = { "std_preference" }; /* Initialize Menu Configs */ populate_profile_menu_event(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); return; } for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { dtmf_ss_t loc; char *dtmfa[16] = { 0 }; switch_event_t *phrase_params = NULL; switch_event_create(&phrase_params, SWITCH_EVENT_REQUEST_PARAMS); append_event_profile(phrase_params, profile, menu); populate_dtmfa_from_event(phrase_params, profile, menu, dtmfa); captureMenuInitialize(&loc, dtmfa); captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT); if (loc.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ } else if (loc.result == RES_INVALID) { /* TODO Say invalid option, and ask for the prompt again IF retry != 0 */ } else if (loc.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, loc.dtmf_stored); /* Reset the try count */ retry = MAX_ATTEMPT; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = mtvm_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } switch_event_destroy(&phrase_params); } free_profile_menu_event(&menu); }
void vmivr_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); int retry; vmivr_menu_t menu = { "std_preference" }; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); goto end; } for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); ivre_init(&menu.ivre_d, menu.dtmfa); ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ retry = menu.ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } menu_instance_free(&menu); } end: menu_free(&menu); }
char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_t *menu, const char *input_mask) { char *result = NULL; int retry; const char *terminate_key = NULL; switch_channel_t *channel = switch_core_session_get_channel(session); if (!menu->event_keys_dtmf || !menu->event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu->name); goto end; } terminate_key = switch_event_get_header(menu->event_keys_action, "ivrengine:terminate_entry"); for (retry = menu->ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { int i; menu_instance_init(menu); switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); /* Find the last entry and append this one to it */ for (i=0; i < 16 && menu->dtmfa[i]; i++){ } menu->dtmfa[i] = (char *) input_mask; ivre_init(&menu->ivre_d, menu->dtmfa); if (terminate_key) { menu->ivre_d.terminate_key = terminate_key[0]; } ivre_playback(session, &menu->ivre_d, switch_event_get_header(menu->event_phrases, "instructions"), NULL, menu->phrase_params, NULL, menu->ivr_entry_timeout); if (menu->ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu->event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu->ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu->event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu->ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ /* Reset the try count */ retry = menu->ivr_maximum_attempts; if (!strncasecmp(menu->ivre_d.completeMatch, input_mask, 1)) { result = switch_core_session_strdup(session, menu->ivre_d.dtmf_stored); retry = -1; } } menu_instance_free(menu); } end: return result; }
/** * Forward CPA signal to client */ static void rayo_cpa_detector_event(const char *jid, void *user_data) { struct rayo_actor *component = RAYO_LOCATE(jid); if (component) { if (CPA_COMPONENT(component)->ready) { switch_event_t *event = (switch_event_t *)user_data; const char *signal_type = switch_event_get_header(event, "signal-type"); struct cpa_signal *cpa_signal = switch_core_hash_find(CPA_COMPONENT(component)->signals, signal_type); switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_COMPONENT(component)->parent->id), SWITCH_LOG_DEBUG, "Handling CPA event\n"); if (cpa_signal) { const char *value = switch_event_get_header(event, "value"); const char *duration = switch_event_get_header(event, "duration"); if (cpa_signal->terminate) { iks *complete_event; iks *signal_xml; stop_cpa_detectors(CPA_COMPONENT(component)); /* send complete event to client */ complete_event = rayo_component_create_complete_event(RAYO_COMPONENT(component), "signal", RAYO_CPA_NS); signal_xml = iks_find(complete_event, "complete"); signal_xml = iks_find(signal_xml, "signal"); iks_insert_attrib(signal_xml, "type", signal_type); if (!zstr(value)) { iks_insert_attrib(signal_xml, "value", value); } if (!zstr(duration)) { iks_insert_attrib(signal_xml, "duration", duration); } rayo_component_send_complete_event(RAYO_COMPONENT(component), complete_event); } else { /* send event to client */ iks *signal_event = iks_new_presence("signal", RAYO_CPA_NS, RAYO_JID(component), RAYO_COMPONENT(component)->client_jid); iks *signal_xml = iks_find(signal_event, "signal"); iks_insert_attrib(signal_xml, "type", signal_type); if (!zstr(value)) { iks_insert_attrib(signal_xml, "value", value); } if (!zstr(duration)) { iks_insert_attrib(signal_xml, "duration", duration); } RAYO_SEND_REPLY(component, RAYO_COMPONENT(component)->client_jid, signal_event); } } } else { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_COMPONENT(component)->parent->id), SWITCH_LOG_DEBUG, "Skipping CPA event\n"); } RAYO_UNLOCK(component); } }
void eventpipe_events_handler(switch_event_t *event) { struct eventpipe_call *current = NULL; const char *uuid1 = ""; const char *uuid2 = ""; switch_assert(event != NULL); if ((event->event_id != SWITCH_EVENT_CUSTOM) && (event->event_id != SWITCH_EVENT_DTMF)) { return; } uuid1 = switch_event_get_header(event, "unique-id"); if (zstr(uuid1)) { return; } switch_mutex_lock(globals.eventpipe_call_list_mutex); if (!head) { goto eventpipe_events_handler_done; } if (!head->session) { goto eventpipe_events_handler_done; } current = head; while (current) { if (current->session) { uuid2 = ""; uuid2 = switch_core_session_get_uuid(current->session); /* check if event unique-id is matching a call uuid in eventpipe */ if ((uuid2) && (!zstr(uuid2) && (!strcmp(uuid1, uuid2)))) { /* conference event case */ if (event->event_id == SWITCH_EVENT_CUSTOM) { const char *event_subclass = switch_str_nil(switch_event_get_header(event, "event-subclass")); if (!strcmp(event_subclass, PLIVO_EVENT_CONFERENCE)) { eventpipe_events_on_conference(current->session, event); } /* dtmf event case */ } else if (event->event_id == SWITCH_EVENT_DTMF) { eventpipe_events_on_dtmf(current->session, event); } goto eventpipe_events_handler_done; } } current = current->next; } eventpipe_events_handler_done: switch_mutex_unlock(globals.eventpipe_call_list_mutex); }
void vmivr_menu_authenticate(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); vmivr_menu_t menu = { "std_authenticate" }; int retry; const char *auth_var = NULL; /* Initialize Menu Configs */ menu_init(profile, &menu); if (profile->id && (auth_var = switch_channel_get_variable(channel, "voicemail_authorized")) && switch_true(auth_var)) { profile->authorized = SWITCH_TRUE; } for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0 && profile->authorized == SWITCH_FALSE; retry--) { const char *id = profile->id, *password = NULL; char *cmd = NULL; const char *password_mask = switch_event_get_header(menu.event_settings, "Password-Mask"); const char *user_mask = switch_event_get_header(menu.event_settings, "User-Mask"); if (!id) { vmivr_menu_t sub_menu = { "std_authenticate_ask_user" }; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); switch_event_add_header(sub_menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); id = vmivr_menu_get_input_set(session, profile, &sub_menu, user_mask); menu_free(&sub_menu); } if (!password) { vmivr_menu_t sub_menu = { "std_authenticate_ask_password" }; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); switch_event_add_header(sub_menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); password = vmivr_menu_get_input_set(session, profile, &sub_menu, password_mask); menu_free(&sub_menu); } cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, id, password); if (vmivr_api_execute(session, profile->api_auth_login, cmd) == SWITCH_STATUS_SUCCESS) { profile->id = id; profile->authorized = SWITCH_TRUE; } else { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "fail_auth"), NULL, NULL, NULL, 0); } } menu_free(&menu); }
void print_result(char const *addr, char const *port, char const *tport, double weight, unsigned preference, switch_stream_handle_t *stream) { int xml = switch_true(switch_event_get_header(stream->param_event, "xml")); if (!port || !port[0]) port = transport_is_secure(tport) ? "5061" : "5060"; if (xml) { stream->write_function(stream, " <route>\n" " <preference>%u</preference>\n" " <weight>%.3f</weight>\n" " <transport>%s</transport>\n" " <port>%s</port>\n" " <address>%s</address>\n" " </route>\n", preference, weight, tport, port, addr); } else { stream->write_function(stream, "%10u\t%10.3f\t%10s\t%10s\t%10s\n", preference, weight, tport, port, addr); } }
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); }
static void event_handler(switch_event_t *event) { const char *sig = switch_event_get_header(event, "Trapped-Signal"); switch_hash_index_t *hi; void *val; cdr_fd_t *fd; if (globals.shutdown) { return; } if (sig && !strcmp(sig, "HUP")) { for (hi = switch_hash_first(NULL, globals.fd_hash); hi; hi = switch_hash_next(hi)) { switch_hash_this(hi, NULL, NULL, &val); fd = (cdr_fd_t *) val; switch_mutex_lock(fd->mutex); do_rotate(fd); switch_mutex_unlock(fd->mutex); } if (globals.db_online) { PQfinish(globals.db_connection); globals.db_online = 0; } } }
/* 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 event_handler(switch_event_t *event) { if (process_event(event) != SWITCH_STATUS_SUCCESS) { const char *peer_uuid = switch_event_get_header(event, "variable_signal_bond"); switch_core_session_t *peer_session = NULL; switch_channel_t *peer_channel = NULL; switch_event_t *peer_event = NULL; if (!peer_uuid) { return; } if (!(peer_session = switch_core_session_locate(peer_uuid))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cant locate peer session for uuid %s\n", peer_uuid); return; } peer_channel = switch_core_session_get_channel(peer_session); if (switch_event_create(&peer_event, SWITCH_EVENT_CHANNEL_BRIDGE) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cant create bridge event for peer channel %s\n", peer_uuid); goto end; } switch_channel_event_set_data(peer_channel, peer_event); end: switch_core_session_rwunlock(peer_session); if (peer_event) { process_event(peer_event); switch_event_destroy(&peer_event); } } }
static void event_handler(switch_event_t *event) { const char *sig = switch_event_get_header(event, "Trapped-Signal"); switch_hash_index_t *hi; void *val; const void *var; logfile_profile_t *profile; if (sig && !strcmp(sig, "HUP")) { if (globals.rotate) { for (hi = switch_core_hash_first(profile_hash); hi; hi = switch_core_hash_next(&hi)) { switch_core_hash_this(hi, &var, NULL, &val); profile = val; mod_logfile_rotate(profile); } } else { switch_mutex_lock(globals.mutex); for (hi = switch_core_hash_first(profile_hash); hi; hi = switch_core_hash_next(&hi)) { switch_core_hash_this(hi, &var, NULL, &val); profile = val; switch_file_close(profile->log_afd); if (mod_logfile_openlogfile(profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Re-opening Log!\n"); } } switch_mutex_unlock(globals.mutex); } } }
static switch_xml_t mod_xml_radius_directory_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data) { char *event_buf = NULL; switch_xml_t xml = NULL; char *auth_method = switch_event_get_header(params,"sip_auth_method"); if ( GLOBAL_DEBUG ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting authentication\n"); switch_event_serialize(params, &event_buf, SWITCH_TRUE); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event: %s \n", event_buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Section: %s \nTag: %s\nKey_name: %s\nKey_value: %s\n", section, tag_name, key_name, key_value); } if ( auth_method == NULL) { return NULL; } if ( strncmp( "INVITE", auth_method, 6) == 0) { xml = mod_xml_radius_auth_invite(params); } else if ( strncmp( "REGISTER", auth_method, 8) == 0) { xml = mod_xml_radius_auth_reg(params); } else { xml = NULL; } return xml; }
static void event_handler(switch_event_t *event) { const char *sig = switch_event_get_header(event, "Trapped-Signal"); if (sig && !strcmp(sig, "HUP")) { do_rotate_all(); } }
SWITCH_DECLARE(int)Event::chat_send(const char *dest_proto) { if (zstr(dest_proto)) { dest_proto = switch_event_get_header(event, "dest_proto"); } return (int) switch_core_chat_send(dest_proto, event); }
void eventpipe_events_on_conference(switch_core_session_t *session, switch_event_t *event) { char args[8192]; char record_args[8192]; const char *action = switch_str_nil(switch_event_get_header(event, "action")); const char *member_id = switch_str_nil(switch_event_get_header(event, "member-id")); const char *conf_room = switch_str_nil(switch_event_get_header(event, "conference-name")); const char *calluuid = switch_core_session_get_uuid(session); switch_channel_t *channel = switch_core_session_get_channel(session); if (!channel) { return; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Event-Name: %s, Event-Subclass: %s, Conference-Name: %s, Action: %s, Member-ID: %s, Unique-ID: %s\n", switch_str_nil(switch_event_get_header(event, "event-name")), switch_str_nil(switch_event_get_header(event, "event-subclass")), conf_room, action, member_id, calluuid); if (!strcmp(action, "add-member")) { const char *enter_sound = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_enter_sound")); const char *record_file = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_record_file")); switch_channel_set_variable(channel, "eventpipe_conference_member_id", member_id); switch_channel_set_variable(channel, "eventpipe_conference_room", conf_room); if (!zstr(enter_sound)) { switch_snprintf(args, sizeof(args), "%s play %s async", conf_room, enter_sound); eventpipe_execute_api(session, "conference", args); } if (!zstr(record_file)) { switch_snprintf(record_args, sizeof(record_args), "%s record %s", conf_room, record_file); eventpipe_execute_api(session, "conference", record_args); } } else if (!strcmp(action, "del-member")) { const char *exit_sound = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_exit_sound")); switch_channel_set_variable(channel, "eventpipe_conference_member_id", ""); switch_channel_set_variable(channel, "eventpipe_conference_room", ""); switch_channel_set_variable(channel, "eventpipe_conference_record_file", ""); if (!zstr(exit_sound)) { switch_snprintf(args, sizeof(args), "conference %s play %s async", conf_room, exit_sound); eventpipe_execute_api(session, "conference", args); } } }
void vmivr_menu_record_greeting_with_slot(switch_core_session_t *session, vmivr_profile_t *profile) { vmivr_menu_t menu = { "std_record_greeting_with_slot" }; const char *result; int gnum = -1; /* Initialize Menu Configs */ menu_init(profile, &menu); result = vmivr_menu_get_input_set(session, profile, &menu, "X"); if (result) gnum = atoi(result); /* If user entered 0, we don't accept it */ if (gnum > 0) { vmivr_menu_t sub_menu = { "std_record_greeting" }; char *tmp_filepath = NULL; const char *record_format = NULL; switch_status_t status; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); record_format = switch_event_get_header(menu.event_settings, "Record-Format"); tmp_filepath = generate_random_file_name(session, "voicemail_ivr", record_format); status = vmivr_menu_record(session, profile, &sub_menu, tmp_filepath); if (status == SWITCH_STATUS_SUCCESS) { char *cmd = switch_core_session_sprintf(session, "%s %s %s %d %s", profile->api_profile, profile->domain, profile->id, gnum, tmp_filepath); char *str_num = switch_core_session_sprintf(session, "%d", gnum); vmivr_api_execute(session, profile->api_pref_greeting_set, cmd); ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "selected_slot"), str_num, NULL, NULL, 0); } menu_free(&sub_menu); } menu_free(&menu); }
static switch_status_t process_event(switch_event_t *event) { switch_core_session_t *session = NULL; switch_channel_t *channel; char *username[3] = { 0 }; char *domain[3] = { 0 }; char key[512]; char *uuid = NULL, *my_uuid = NULL; int i; switch_thread_rwlock_rdlock(globals.spy_hash_lock); if (!globals.spy_count) { goto done; } username[0] = switch_event_get_header(event, "Caller-Username"); domain[0] = switch_event_get_header(event, "variable_domain_name"); domain[1] = switch_event_get_header(event, "variable_dialed_domain"); username[1] = switch_event_get_header(event, "variable_dialed_user"); username[2] = switch_event_get_header(event, "variable_user_name"); domain[2] = switch_event_get_header(event, "variable_domain_name"); for (i = 0; i < 3; i++) { if (username[i] && domain[i]) { switch_snprintf(key, sizeof(key), "%[email protected]%s", username[i], domain[i]); if ((uuid = switch_core_hash_find(globals.spy_hash, key))) { break; } } } done: switch_thread_rwlock_unlock(globals.spy_hash_lock); if (!uuid) { return SWITCH_STATUS_FALSE; } session = switch_core_session_locate(uuid); channel = switch_core_session_get_channel(session); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "UserSpy retrieved uuid %s for key %s, activating eavesdrop \n", uuid, key); my_uuid = switch_event_get_header(event, "Unique-ID"); switch_channel_set_variable(channel, "spy_uuid", my_uuid); switch_channel_set_state(channel, CS_EXCHANGE_MEDIA); switch_channel_set_flag(channel, CF_BREAK); switch_core_session_rwunlock(session); return SWITCH_STATUS_SUCCESS; }
/** * Handle conference events from FreeSWITCH. * @param event received from FreeSWITCH core. It will be destroyed by the core after this function returns. */ static void on_mixer_record_event(switch_event_t *event) { const char *file_path = switch_event_get_header(event, "Path"); const char *action = switch_event_get_header(event, "Action"); struct rayo_component *component = RAYO_COMPONENT_LOCATE(file_path); if (component) { struct record_component *record = RECORD_COMPONENT(component); if (!strcmp("stop-recording", action)) { record->duration_ms += (switch_micro_time_now() - record->start_time) / 1000; if (record->stop) { complete_record(component, COMPONENT_COMPLETE_STOP); } else { /* TODO assume final timeout, for now */ complete_record(component, RECORD_COMPLETE_FINAL_TIMEOUT); } } } }
static switch_bool_t compare_var(switch_event_t *event, switch_channel_t *channel, const char *varname) { const char *chan_val = switch_channel_get_variable_dup(channel, varname, SWITCH_FALSE, -1); const char *event_val = switch_event_get_header(event, varname); if (zstr(chan_val) || zstr(event_val)) { return 1; } return strcasecmp(chan_val, event_val); }
SWITCH_DECLARE(const char *)Event::getHeader(const char *header_name) { this_check(""); if (event) { return switch_event_get_header(event, header_name); } else { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getHeader an event that does not exist!\n"); } return NULL; }
char *mtvm_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *input_mask, const char *terminate_key) { char *result = NULL; int retry; switch_channel_t *channel = switch_core_session_get_channel(session); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys : %s\n", menu.name); return result; } for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { dtmf_ss_t loc; char *dtmfa[16] = { 0 }; int i; switch_event_t *phrase_params = NULL; switch_event_create(&phrase_params, SWITCH_EVENT_REQUEST_PARAMS); append_event_profile(phrase_params, profile, menu); populate_dtmfa_from_event(phrase_params, profile, menu, dtmfa); /* Find the last entry and append this one to it */ for (i=0; dtmfa[i] && i < 16; i++){ } dtmfa[i] = (char *) input_mask; captureMenuInitialize(&loc, dtmfa); if (terminate_key) loc.terminate_key = terminate_key[0]; /* TODO Make this load from the configuration */ captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "instructions"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT); if (loc.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ } else if (loc.result == RES_INVALID) { /* TODO Say invalid option, and ask for the prompt again IF retry != 0 */ } else if (loc.result == RES_FOUND) { /* Matching DTMF Key Pressed */ /* Reset the try count */ retry = MAX_ATTEMPT; if (!strncasecmp(loc.completeMatch, input_mask, 1)) { result = switch_core_session_strdup(session, loc.dtmf_stored); retry = -1; } } switch_event_destroy(&phrase_params); } return result; }
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; }
/** * Add fax metadata to result * @param event source of metadata * @param name of metadata * @param result to add metadata to */ static void insert_fax_metadata(switch_event_t *event, const char *name, iks *result) { char actual_name[256]; const char *value; snprintf(actual_name, sizeof(actual_name), "variable_%s", name); actual_name[sizeof(actual_name) - 1] = '\0'; value = switch_event_get_header(event, actual_name); if (!zstr(value)) { iks *metadata = iks_insert(result, "metadata"); iks_insert_attrib(metadata, "xmlns", RAYO_FAX_COMPLETE_NS); iks_insert_attrib(metadata, "name", name); iks_insert_attrib(metadata, "value", value); } }