SWITCH_DECLARE(int) CoreSession::originate(CoreSession *a_leg_session, char *dest, int timeout, switch_state_handler_table_t *handlers) { switch_core_session_t *aleg_core_session = NULL; this_check(0); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; if (a_leg_session != NULL) { aleg_core_session = a_leg_session->session; } // this session has no valid switch_core_session_t at this point, and therefore // no valid channel. since the threadstate is stored in the channel, and there // is none, if we try to call begin_alllow_threads it will fail miserably. // use the 'a leg session' to do the thread swapping stuff. if (a_leg_session) a_leg_session->begin_allow_threads(); if (switch_ivr_originate(aleg_core_session, &session, &cause, dest, timeout, handlers, NULL, NULL, NULL, NULL, SOF_NONE, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error Creating Outgoing Channel! [%s]\n", dest); goto failed; } if (a_leg_session) a_leg_session->end_allow_threads(); channel = switch_core_session_get_channel(session); allocated = 1; switch_safe_free(uuid); uuid = strdup(switch_core_session_get_uuid(session)); switch_channel_set_state(switch_core_session_get_channel(session), CS_SOFT_EXECUTE); return SWITCH_STATUS_SUCCESS; failed: if (a_leg_session) a_leg_session->end_allow_threads(); return SWITCH_STATUS_FALSE; }
static int channelList_callback(void *pArg, int argc, char **argv, char **columnNames) { chan_entry_t *entry; netsnmp_tdata_row *row; switch_zmalloc(entry, sizeof(chan_entry_t)); row = netsnmp_tdata_create_row(); if (!row) { switch_safe_free(entry); return 0; } row->data = entry; entry->idx = idx++; strncpy(entry->uuid, switch_str_nil(argv[0]), sizeof(entry->uuid)); strncpy(entry->direction, switch_str_nil(argv[1]), sizeof(entry->direction)); entry->created_epoch = atoi(argv[3]); strncpy(entry->name, switch_str_nil(argv[4]), sizeof(entry->name)); strncpy(entry->state, switch_str_nil(argv[5]), sizeof(entry->state)); strncpy(entry->cid_name, switch_str_nil(argv[6]), sizeof(entry->cid_name)); strncpy(entry->cid_num, switch_str_nil(argv[7]), sizeof(entry->cid_num)); strncpy(entry->dest, switch_str_nil(argv[9]), sizeof(entry->dest)); strncpy(entry->application, switch_str_nil(argv[10]), sizeof(entry->application)); strncpy(entry->application_data, switch_str_nil(argv[11]), sizeof(entry->application_data)); strncpy(entry->dialplan, switch_str_nil(argv[12]), sizeof(entry->dialplan)); strncpy(entry->context, switch_str_nil(argv[13]), sizeof(entry->context)); strncpy(entry->read_codec, switch_str_nil(argv[14]), sizeof(entry->read_codec)); entry->read_rate = atoi(switch_str_nil(argv[15])); entry->read_bitrate = atoi(switch_str_nil(argv[16])); strncpy(entry->write_codec, switch_str_nil(argv[17]), sizeof(entry->write_codec)); entry->write_rate = atoi(switch_str_nil(argv[18])); entry->write_bitrate = atoi(switch_str_nil(argv[19])); memset(&entry->ip_addr, 0, sizeof(entry->ip_addr)); if (strchr(switch_str_nil(argv[8]), ':')) { switch_inet_pton(AF_INET6, switch_str_nil(argv[8]), &entry->ip_addr); entry->addr_family = AF_INET6; } else { switch_inet_pton(AF_INET, switch_str_nil(argv[8]), &entry->ip_addr); entry->addr_family = AF_INET; } netsnmp_tdata_row_add_index(row, ASN_INTEGER, &entry->idx, sizeof(entry->idx)); netsnmp_tdata_add_row(ch_table, row); return 0; }
SWITCH_DECLARE(const char *) API::executeString(const char *cmd) { char *arg; switch_stream_handle_t stream = { 0 }; char *mycmd = NULL; this_check(""); mycmd = strdup(cmd); switch_assert(mycmd); if ((arg = strchr(mycmd, ' '))) { *arg++ = '\0'; } switch_safe_free(last_data); SWITCH_STANDARD_STREAM(stream); switch_api_execute(mycmd, arg, session, &stream); last_data = (char *) stream.data; switch_safe_free(mycmd); return last_data; }
/** * Empties the entire cache * @param cache the cache to empty */ static void setup_dir(url_cache_t *cache) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting up %s\n", cache->location); switch_dir_make_recursive(cache->location, SWITCH_DEFAULT_DIR_PERMS, cache->pool); for (int i = 0x00; i <= 0xff; i++) { switch_dir_t *dir = NULL; char *dirname = switch_mprintf("%s%s%02x", cache->location, SWITCH_PATH_SEPARATOR, i); if (switch_dir_open(&dir, dirname, cache->pool) == SWITCH_STATUS_SUCCESS) { char filenamebuf[256] = { 0 }; const char *filename = NULL; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "deleting cache files in %s...\n", dirname); for(filename = switch_dir_next_file(dir, filenamebuf, sizeof(filenamebuf)); filename; filename = switch_dir_next_file(dir, filenamebuf, sizeof(filenamebuf))) { char *path = switch_mprintf("%s%s%s", dirname, SWITCH_PATH_SEPARATOR, filename); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "deleting: %s\n", path); switch_file_remove(path, cache->pool); switch_safe_free(path); } switch_dir_close(dir); } switch_safe_free(dirname); } }
/** * Close SSML document. * @param handle * @return SWITCH_STATUS_SUCCESS */ static switch_status_t rayo_file_close(switch_file_handle_t *handle) { struct rayo_file_context *context = (struct rayo_file_context *)handle->private_info; if (context && context->component) { struct output_component *output = OUTPUT_COMPONENT(context->component); /* send completion and destroy */ if (output->stop) { rayo_component_send_complete(context->component, COMPONENT_COMPLETE_STOP); } else { if (!strcmp(RAYO_ACTOR(context->component)->type, RAT_CALL_COMPONENT)) { /* call output... check for hangup */ switch_core_session_t *session = switch_core_session_locate(RAYO_ACTOR(context->component)->parent->id); if (session) { if (switch_channel_get_state(switch_core_session_get_channel(session)) >= CS_HANGUP) { rayo_component_send_complete(context->component, COMPONENT_COMPLETE_HANGUP); } else { rayo_component_send_complete(context->component, OUTPUT_FINISH); } switch_core_session_rwunlock(session); } else { /* session is gone */ rayo_component_send_complete(context->component, COMPONENT_COMPLETE_HANGUP); } } else { /* mixer output... finished */ rayo_component_send_complete(context->component, OUTPUT_FINISH); } } /* TODO timed out */ /* cleanup internals */ switch_safe_free(context->ssml); context->ssml = NULL; if (output->document) { iks_delete(output->document); output->document = NULL; } /* close SSML file */ if (switch_test_flag((&context->fh), SWITCH_FILE_OPEN)) { return switch_core_file_close(&context->fh); } } return SWITCH_STATUS_SUCCESS; }
static switch_status_t remove_fetch_handler(ei_node_t *ei_node, erlang_pid *from, switch_xml_binding_t *binding) { ei_xml_agent_t *agent; ei_xml_client_t *client; fetch_handler_t *fetch_handler, *prev = NULL; int found = 0; agent = (ei_xml_agent_t *)switch_xml_get_binding_user_data(binding); /* write-lock the agent */ switch_thread_rwlock_wrlock(agent->lock); if (!(client = find_xml_client(ei_node, agent))) { switch_thread_rwlock_unlock(agent->lock); return SWITCH_STATUS_SUCCESS; } fetch_handler = client->fetch_handlers; while (fetch_handler != NULL) { if (ei_compare_pids(&fetch_handler->pid, from) == SWITCH_STATUS_SUCCESS) { found = 1; break; } prev = fetch_handler; fetch_handler = fetch_handler->next; } if (found) { if (!prev) { client->fetch_handlers = fetch_handler->next; } else { prev->next = fetch_handler->next; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed %s XML handler %s <%d.%d.%d>\n" ,xml_section_to_string(agent->section) ,fetch_handler->pid.node ,fetch_handler->pid.creation ,fetch_handler->pid.num ,fetch_handler->pid.serial); switch_safe_free(fetch_handler); } switch_thread_rwlock_unlock(agent->lock); return SWITCH_STATUS_SUCCESS; }
static switch_status_t tts_commandline_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags) { switch_status_t ret=SWITCH_STATUS_SUCCESS; char *message, *tmp, *mtmp, *rate; tts_commandline_t *info = (tts_commandline_t *) sh->private_info; assert(info != NULL); if (switch_test_flag(info->fh, SWITCH_FILE_OPEN)) { switch_core_file_close(info->fh); unlink(info->file); } tmp = switch_util_quote_shell_arg(text); message = switch_string_replace(globals.command, "${text}", tmp); switch_safe_free(tmp); mtmp=message; tmp = switch_util_quote_shell_arg(info->voice_name); message = switch_string_replace(mtmp, "${voice}", tmp); switch_safe_free(tmp); switch_safe_free(mtmp); mtmp=message; rate = switch_core_sprintf(sh->memory_pool, "%d", info->rate); message = switch_string_replace(mtmp, "${rate}", rate); switch_safe_free(mtmp); mtmp=message; tmp = switch_util_quote_shell_arg(info->file); message = switch_string_replace(mtmp, "${file}", tmp); switch_safe_free(tmp); switch_safe_free(mtmp); mtmp=message; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing: %s\n", message); if (switch_system(message, SWITCH_TRUE) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute command: %s\n", message); ret = SWITCH_STATUS_FALSE; goto done; } if (switch_core_file_open(info->fh, info->file, 0, //number_of_channels, info->rate, //samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file: %s\n", info->file); ret = SWITCH_STATUS_FALSE; goto done; } sh->private_info = info; done: switch_safe_free(mtmp); return ret; }
static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData, void *const callInfo) { char *command = NULL, *arg = NULL; switch_stream_handle_t stream = { 0 }; xmlrpc_value *val = NULL; switch_bool_t freed = 0; /* Parse our argument array. */ xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg); if (envP->fault_occurred) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Request!\n"); return NULL; } if (!is_authorized((const TSession *) callInfo, command)) { val = xmlrpc_build_value(envP, "s", "UNAUTHORIZED!"); goto end; } if (switch_stristr("unload", command) && switch_stristr("mod_xml_rpc", arg)) { switch_safe_free(command); switch_safe_free(arg); freed = 1; command = "bgapi"; arg = "unload mod_xml_rpc"; } else if (switch_stristr("reload", command) && switch_stristr("mod_xml_rpc", arg)) { switch_safe_free(command); switch_safe_free(arg); freed = 1; command = "bgapi"; arg = "reload mod_xml_rpc"; } SWITCH_STANDARD_STREAM(stream); if (switch_api_execute(command, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) { /* Return our result. */ val = xmlrpc_build_value(envP, "s", stream.data); free(stream.data); } else { val = xmlrpc_build_value(envP, "s", "ERROR!"); } end: /* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */ if (!freed) { switch_safe_free(command); switch_safe_free(arg); } return val; }
/** * Start execution of mixer output component */ static iks *start_mixer_output_component(struct rayo_actor *mixer, struct rayo_message *msg, void *data) { iks *iq = msg->payload; struct rayo_component *component = NULL; iks *output = iks_find(iq, "output"); iks *document = NULL; switch_stream_handle_t stream = { 0 }; /* validate output attributes */ if (!VALIDATE_RAYO_OUTPUT(output)) { return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); } /* check if <document> exists */ document = iks_find(output, "document"); if (!document) { return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); } component = create_output_component(mixer, RAT_MIXER_COMPONENT, output, iks_find_attrib(iq, "from")); /* build conference command */ SWITCH_STANDARD_STREAM(stream); stream.write_function(&stream, "%s play ", rayo_mixer_get_name(RAYO_MIXER(mixer)), RAYO_ID(component)); stream.write_function(&stream, "{id=%s,pause=%s", RAYO_JID(component), OUTPUT_COMPONENT(component)->start_paused ? "true" : "false"); if (OUTPUT_COMPONENT(component)->max_time_ms > 0) { stream.write_function(&stream, ",timeout=%i", OUTPUT_COMPONENT(component)->max_time_ms); } if (OUTPUT_COMPONENT(component)->start_offset_ms > 0) { stream.write_function(&stream, ",start_offset_ms=%i", OUTPUT_COMPONENT(component)->start_offset_ms); } stream.write_function(&stream, "}fileman://rayo://%s", RAYO_JID(component)); /* acknowledge command */ rayo_component_send_start(component, iq); rayo_component_api_execute_async(component, "conference", stream.data); switch_safe_free(stream.data); RAYO_UNLOCK(component); return NULL; }
void utils_hupall(char *profile_name) { char cmd[128]; char arg[128]; switch_stream_handle_t mystream = { 0 }; switch_snprintf(cmd, sizeof(cmd),"hupall"); switch_snprintf(arg, sizeof(arg),"normal_clearing sofia_profile_name %s",profile_name); SWITCH_STANDARD_STREAM(mystream); if (switch_api_execute(cmd, arg, NULL, &mystream) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"cannot hupall for %s\n",profile_name); return; } switch_safe_free(mystream.data); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,"hupall for %s done\n",profile_name); return; }
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]; int type; int size; char *arg; switch_bool_t fail = SWITCH_FALSE; if (arity < 3) { fail = SWITCH_TRUE; } ei_get_type(buf->buff, &buf->index, &type, &size); if ((size > (sizeof(api_cmd) - 1)) || ei_decode_atom(buf->buff, &buf->index, api_cmd)) { fail = SWITCH_TRUE; } ei_get_type(buf->buff, &buf->index, &type, &size); arg = malloc(size + 1); if (ei_decode_string_or_binary(buf->buff, &buf->index, size, arg)) { fail = SWITCH_TRUE; } if (!fail) { struct api_command_struct acs = { 0 }; acs.listener = listener; acs.api_cmd = api_cmd; acs.arg = arg; acs.bg = 0; acs.pid = msg->from; api_exec(NULL, (void *) &acs); switch_safe_free(arg); /* don't reply */ return SWITCH_STATUS_FALSE; } else { ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "badarg"); return SWITCH_STATUS_SUCCESS; } }
switch_status_t skinny_session_walk_lines_by_call_id(skinny_profile_t *profile, uint32_t call_id, switch_core_db_callback_func_t callback, void *data) { char *sql; if ((sql = switch_mprintf( "SELECT skinny_lines.*, channel_uuid, call_id, call_state " "FROM skinny_active_lines " "INNER JOIN skinny_lines " "ON skinny_active_lines.device_name = skinny_lines.device_name " "AND skinny_active_lines.device_instance = skinny_lines.device_instance " "AND skinny_active_lines.line_instance = skinny_lines.line_instance " "WHERE call_id='%d'", call_id))) { skinny_execute_sql_callback(profile, profile->sql_mutex, sql, callback, data); switch_safe_free(sql); } return SWITCH_STATUS_SUCCESS; }
SWITCH_DECLARE(char *) CoreSession::getXMLCDR() { switch_xml_t cdr; this_check((char *)""); sanity_check((char *)""); switch_safe_free(xml_cdr_text); if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) { xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE); switch_xml_free(cdr); } return (char *) (xml_cdr_text ? xml_cdr_text : ""); }
/** * Request signals */ static void subscribe(const char *uuid, const char *signal_type, const char *jid) { char *key = switch_mprintf("%s:%s", uuid, signal_type); switch_mutex_lock(globals.subscribers_mutex); { switch_hash_t *signal_subscribers = switch_core_hash_find(globals.subscribers, key); switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Subscribe %s => %s\n", signal_type, jid); if (!signal_subscribers) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Create %s subscriber hash\n", signal_type); switch_core_hash_init(&signal_subscribers); switch_core_hash_insert(globals.subscribers, key, signal_subscribers); } switch_core_hash_insert(signal_subscribers, jid, "1"); } switch_mutex_unlock(globals.subscribers_mutex); switch_safe_free(key); }
switch_bool_t set_cache(switch_memory_pool_t *pool, char *number, cid_data_t *cid) { char *cmd; switch_bool_t success = SWITCH_TRUE; switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); cmd = switch_core_sprintf(pool, "set fs:cidlookup:name:%s '%s' %d", number, cid->name, globals.cache_expire); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "memcache: %s\n", cmd); if (switch_api_execute("memcache", cmd, NULL, &stream) == SWITCH_STATUS_SUCCESS) { if (strncmp("-ERR", stream.data, 4)) { success = SWITCH_TRUE; } else { success = SWITCH_FALSE; goto done; } } SWITCH_REWIND_STREAM(stream); cmd = switch_core_sprintf(pool, "set fs:cidlookup:area:%s '%s' %d", number, cid->area, globals.cache_expire); if (switch_api_execute("memcache", cmd, NULL, &stream) == SWITCH_STATUS_SUCCESS) { if (strncmp("-ERR", stream.data, 4)) { success = SWITCH_TRUE; } else { success = SWITCH_FALSE; goto done; } } SWITCH_REWIND_STREAM(stream); cmd = switch_core_sprintf(pool, "set fs:cidlookup:src:%s '%s' %d", number, cid->src, globals.cache_expire); if (switch_api_execute("memcache", cmd, NULL, &stream) == SWITCH_STATUS_SUCCESS) { if (strncmp("-ERR", stream.data, 4)) { success = SWITCH_TRUE; } else { success = SWITCH_FALSE; goto done; } } done: switch_safe_free(stream.data); return success; }
/** * Try to get file(s) from say module * @param parsed_data * @param to_say * @return 1 if successful */ static int get_file_from_macro(struct ssml_parser *parsed_data, char *to_say) { struct ssml_node *cur_node = parsed_data->cur_node; struct macro *say_macro = cur_node->say_macro; struct voice *say_voice = find_say_voice(cur_node); struct language *language; char *file_string = NULL; char *gender = NULL; switch_say_interface_t *si; /* voice is required */ if (!say_voice) { return 0; } language = switch_core_hash_find(globals.language_map, say_voice->language); /* language is required */ if (!language) { return 0; } /* TODO need to_say gender, not voice gender */ gender = "neuter"; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Trying macro: %s, %s, %s, %s, %s\n", language->language, to_say, say_macro->type, say_macro->method, gender); if ((si = switch_loadable_module_get_say_interface(language->say_module)) && si->say_string_function) { switch_say_args_t say_args = {0}; say_args.type = switch_ivr_get_say_type_by_name(say_macro->type); say_args.method = switch_ivr_get_say_method_by_name(say_macro->method); say_args.gender = switch_ivr_get_say_gender_by_name(gender); say_args.ext = "wav"; si->say_string_function(NULL, to_say, &say_args, &file_string); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding macro: \"%s\", prefix=\"%s\"\n", file_string, say_voice->prefix); if (!zstr(file_string)) { parsed_data->files[parsed_data->num_files].name = switch_core_strdup(parsed_data->pool, file_string); parsed_data->files[parsed_data->num_files++].prefix = switch_core_strdup(parsed_data->pool, say_voice->prefix); return 1; } switch_safe_free(file_string); return 0; }
char *sofia_media_get_multipart(switch_core_session_t *session, const char *prefix, const char *sdp, char **mp_type) { char *extra_headers = NULL; switch_stream_handle_t stream = { 0 }; switch_event_header_t *hi = NULL; int x = 0; switch_channel_t *channel = switch_core_session_get_channel(session); const char *boundary = switch_core_session_get_uuid(session); SWITCH_STANDARD_STREAM(stream); if ((hi = switch_channel_variable_first(channel))) { for (; hi; hi = hi->next) { const char *name = (char *) hi->name; char *value = (char *) hi->value; if (!strncasecmp(name, prefix, strlen(prefix))) { const char *hname = name + strlen(prefix); if (*value == '~') { stream.write_function(&stream, "--%s\nContent-Type: %s\nContent-Length: %d\n%s\n", boundary, hname, strlen(value), value + 1); } else { stream.write_function(&stream, "--%s\nContent-Type: %s\nContent-Length: %d\n\n%s\n", boundary, hname, strlen(value) + 1, value); } x++; } } switch_channel_variable_last(channel); } if (x) { *mp_type = switch_core_session_sprintf(session, "multipart/mixed; boundary=%s", boundary); if (sdp) { stream.write_function(&stream, "--%s\nContent-Type: application/sdp\nContent-Length: %d\n\n%s\n", boundary, strlen(sdp) + 1, sdp); } stream.write_function(&stream, "--%s--\n", boundary); } if (!zstr((char *) stream.data)) { extra_headers = stream.data; } else { switch_safe_free(stream.data); } return extra_headers; }
SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_send_query(switch_pgsql_handle_t *handle, const char* sql) { #ifdef SWITCH_HAVE_PGSQL char *err_str; switch_safe_free(handle->sql); handle->sql = strdup(sql); if (!PQsendQuery(handle->con, sql)) { err_str = switch_pgsql_handle_get_error(handle); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to send query (%s) to database: %s\n", sql, err_str); switch_pgsql_finish_results(handle); goto error; } return SWITCH_PGSQL_SUCCESS; error: #endif return SWITCH_PGSQL_FAIL; }
/*login是否成功 */ bool CBaseModule::isLoginSuc(string username, string userpwd) { //临时方案:目前根据文件读取 bool bRes = false; switch_xml_t x_NEs,x_ne; const char *errmsg[1]={ 0 }; const char *name=NULL; const char *pwd=NULL; char *nefile = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, CARI_CCP_OPUSER_XML_FILE ); if (!cari_common_isExistedFile(nefile)){ goto end; } //将内容转换成xml的结构(注意:中文字符问题) x_NEs = cari_common_parseXmlFromFile(nefile); if (!x_NEs){ goto end; } //遍历查找 x_ne = switch_xml_child(x_NEs, "opuser"); for (; x_ne; x_ne = x_ne->next) { name = switch_xml_attr(x_ne, "name"); pwd = switch_xml_attr(x_ne, "pwd"); if (isEqualStr(username.c_str(),name) && isEqualStr(userpwd.c_str(),pwd)){ bRes = true; break; } } end: switch_safe_free(nefile); return bRes; }
/*! function to close the asr interface */ static switch_status_t pocketsphinx_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags) { pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_mutex_lock(ps->flag_mutex); if (switch_test_flag(ps, PSFLAG_ALLOCATED)) { if (switch_test_flag(ps, PSFLAG_READY)) { ps_end_utt(ps->ps); } ps_free(ps->ps); ps->ps = NULL; } switch_safe_free(ps->grammar); switch_mutex_unlock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); switch_clear_flag(ps, PSFLAG_READY); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Port Closed.\n"); switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED); return SWITCH_STATUS_SUCCESS; }
SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_disconnect(switch_pgsql_handle_t *handle) { #ifdef SWITCH_HAVE_PGSQL if (!handle) { return SWITCH_PGSQL_FAIL; } if (handle->state == SWITCH_PGSQL_STATE_CONNECTED) { PQfinish(handle->con); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Disconnected from [%s]\n", handle->dsn); } switch_safe_free(handle->sql); handle->state = SWITCH_PGSQL_STATE_DOWN; return SWITCH_PGSQL_SUCCESS; #else return SWITCH_PGSQL_FAIL; #endif }
/** * Start execution of call output component * @param component to start * @param session the session to output to * @param output the output request * @param iq the original request */ static iks *start_call_output(struct rayo_component *component, switch_core_session_t *session, iks *output, iks *iq) { switch_stream_handle_t stream = { 0 }; /* acknowledge command */ rayo_component_send_start(component, iq); /* build playback command */ SWITCH_STANDARD_STREAM(stream); stream.write_function(&stream, "{id=%s,session=%s,pause=%s", RAYO_JID(component), switch_core_session_get_uuid(session), OUTPUT_COMPONENT(component)->start_paused ? "true" : "false"); if (OUTPUT_COMPONENT(component)->max_time_ms > 0) { stream.write_function(&stream, ",timeout=%i", OUTPUT_COMPONENT(component)->max_time_ms); } if (OUTPUT_COMPONENT(component)->start_offset_ms > 0) { stream.write_function(&stream, ",start_offset_ms=%i", OUTPUT_COMPONENT(component)->start_offset_ms); } stream.write_function(&stream, "}fileman://rayo://%s", RAYO_JID(component)); if (switch_ivr_displace_session(session, stream.data, 0, "m") == SWITCH_STATUS_SUCCESS) { RAYO_RELEASE(component); } else { if (component->complete) { /* component is already destroyed */ RAYO_RELEASE(component); } else { /* need to destroy component */ if (OUTPUT_COMPONENT(component)->document) { iks_delete(OUTPUT_COMPONENT(component)->document); } if (switch_channel_get_state(switch_core_session_get_channel(session)) >= CS_HANGUP) { rayo_component_send_complete(component, COMPONENT_COMPLETE_HANGUP); } else { rayo_component_send_complete(component, COMPONENT_COMPLETE_ERROR); } } } switch_safe_free(stream.data); return NULL; }
static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed) { switch_status_t status = SWITCH_STATUS_SUCCESS; switch_cache_db_handle_t *dbh = NULL; if (!switch_odbc_available()) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC is not compiled in. Do not configure odbc-dsn parameter!\n"); return SWITCH_STATUS_FALSE; } if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && changed) { if (zstr(newvalue)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No local database defined.\n"); } else { switch_safe_free(globals.odbc_dsn); globals.odbc_dsn = strdup(newvalue); if ((globals.odbc_user = strchr(globals.odbc_dsn, ':'))) { *globals.odbc_user++ = '\0'; if ((globals.odbc_pass = strchr(globals.odbc_user, ':'))) { *globals.odbc_pass++ = '\0'; } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting to dsn: %s\n", globals.odbc_dsn); if (!(dbh = cidlookup_get_db_handle())) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n"); switch_goto_status(SWITCH_STATUS_FALSE, done); } } } switch_goto_status(SWITCH_STATUS_SUCCESS, done); done: switch_cache_db_release_db_handle(&dbh); return status; }
SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool) { /* try free dynamic data structures prior to resetting to 0 */ FreeUPNPUrls(&nat_globals.urls); switch_safe_free(nat_globals.descURL); memset(&nat_globals, 0, sizeof(nat_globals)); if (first_init) { memset(&nat_globals_perm, 0, sizeof(nat_globals_perm)); nat_globals_perm.pool = pool; } switch_find_local_ip(nat_globals.pvt_addr, sizeof(nat_globals.pvt_addr), NULL, AF_INET); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Scanning for NAT\n"); init_pmp(); if (!nat_globals.nat_type) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPnP\n"); init_upnp(); } if (nat_globals.nat_type) { switch_core_set_variable("nat_public_addr", nat_globals.pub_addr); switch_core_set_variable("nat_private_addr", nat_globals.pvt_addr); switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s, ExtIP: '%s'\n", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", nat_globals.pub_addr); if (!nat_thread_p) { switch_nat_thread_start(); } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or UPnP NAT devices detected!\n"); } first_init = SWITCH_FALSE; initialized = SWITCH_TRUE; }
static switch_status_t cdr_mongo_authenticate() { switch_status_t status = SWITCH_STATUS_SUCCESS; mongo_error_t db_status; char *ns_tmp, *ns_split[2]; /* Split namespace db.collection into separate vars */ switch_strdup(ns_tmp, globals.mongo_namespace); switch_separate_string(ns_tmp, '.', ns_split, 2); db_status = mongo_cmd_authenticate(globals.mongo_conn, ns_split[0], globals.mongo_username, globals.mongo_password); if (db_status != MONGO_OK) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mongo_cmd_authenticate: authentication failed\n"); status = SWITCH_STATUS_FALSE; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Successfully authenticated %s@%s\n", globals.mongo_username, ns_split[0]); } switch_safe_free(ns_tmp); return status; }
/** * Stop receiving signals */ static void unsubscribe(const char *uuid, const char *signal_type, const char *jid) { char *key = switch_mprintf("%s:%s", uuid, signal_type); switch_mutex_lock(globals.subscribers_mutex); { switch_hash_t *signal_subscribers = switch_core_hash_find(globals.subscribers, key); if (signal_subscribers) { switch_core_hash_delete(signal_subscribers, jid); switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Unsubscribe %s => %s\n", signal_type, jid); /* clean up hash if empty */ if (!switch_core_hash_first(signal_subscribers)) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Destroy %s subscriber hash\n", signal_type); switch_core_hash_destroy(&signal_subscribers); switch_core_hash_delete(globals.subscribers, key); } } } switch_mutex_unlock(globals.subscribers_mutex); switch_safe_free(key); }
void jsonapi_populate_event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data) { switch_event_t *phrases_event = NULL; switch_stream_handle_t stream = { 0 }; switch_event_header_t *hp; switch_assert(apply_event); SWITCH_STANDARD_STREAM(stream); switch_api_execute(api, data, session, &stream); switch_event_create_json(&phrases_event, (char *) stream.data); switch_safe_free(stream.data); for (hp = phrases_event->headers; hp; hp = hp->next) { if (!strncasecmp(hp->name, "VM-", 3)) { switch_event_add_header(apply_event, SWITCH_STACK_BOTTOM, hp->name, "%s", hp->value); } } switch_event_destroy(&phrases_event); phrases_event = apply_event; return; }
/* PL */ static switch_status_t pl_say(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { switch_new_say_callback_t say_cb = NULL; char *string = NULL; switch_status_t status = SWITCH_STATUS_FALSE; say_cb = choose_callback(say_args); if (say_cb) { status = run_callback(say_cb, tosay, say_args, session, &string); if (session && string) { status = switch_ivr_play_file(session, NULL, string, args); } switch_safe_free(string); } return status; }
static double get_balance(const char *billaccount, switch_channel_t *channel) { char *dsql = NULL, *sql = NULL; nibblebill_results_t pdata; double balance = 0.0; if (!switch_odbc_available()) { return -1.0; } memset(&pdata, 0, sizeof(pdata)); if (globals.custom_sql_lookup) { if (switch_string_var_check_const(globals.custom_sql_lookup) || switch_string_has_escaped_data(globals.custom_sql_lookup)) { sql = switch_channel_expand_variables(channel, globals.custom_sql_lookup); if (sql != globals.custom_sql_lookup) dsql = sql; } else { sql = globals.custom_sql_lookup; } } else { sql = dsql = switch_mprintf("SELECT %s AS nibble_balance FROM %s WHERE %s='%s'", globals.db_column_cash, globals.db_table, globals.db_column_account, billaccount); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing lookup query\n[%s]\n", sql); if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, nibblebill_callback, &pdata, NULL) != SWITCH_ODBC_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error running this query: [%s]\n", sql); /* Return -1 for safety */ balance = -1.0; } else { /* Successfully retrieved! */ balance = pdata.balance; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Retrieved current balance for account %s (balance = %f)\n", billaccount, balance); } switch_safe_free(dsql); return balance; }
/** * Search for best voice based on attributes * @param cur_node the desired voice attributes * @param map the map to search * @param type "say" or "tts" * @param lang_required if true, language must match * @return the voice or NULL */ static struct voice *find_voice(struct ssml_node *cur_node, switch_hash_t *map, char *type, int lang_required) { switch_hash_index_t *hi = NULL; struct voice *voice = (struct voice *)switch_core_hash_find(map, cur_node->name); char *lang_name_gender = NULL; int best_score = 0; /* check cache */ lang_name_gender = switch_mprintf("%s-%s-%s-%s", type, cur_node->language, cur_node->name, cur_node->gender); voice = (struct voice *)switch_core_hash_find(globals.voice_cache, lang_name_gender); if (voice) { /* that was easy! */ goto done; } /* find best language, name, gender match */ for (hi = switch_hash_first(NULL, map); hi; hi = switch_hash_next(hi)) { const void *key; void *val; struct voice *candidate; int candidate_score = 0; switch_hash_this(hi, &key, NULL, &val); candidate = (struct voice *)val; candidate_score = score_voice(candidate, cur_node, lang_required); if (candidate_score > 0 && candidate_score > best_score) { voice = candidate; best_score = candidate_score; } } /* remember for next time */ if (voice) { switch_core_hash_insert(globals.voice_cache, lang_name_gender, voice); } done: switch_safe_free(lang_name_gender); return voice; }