WSChannel* WSClientParser::CreateCall( switch_core_session_t *session, const char *profileName, const char *profileContext, const char *profileDialplan, const char* ip ) { WSChannel *wsChannel = NULL; switch_memory_pool_t *pool = NULL; switch_channel_t* channel = NULL; switch_caller_profile_t *caller_profile = NULL; char *user = mpUser; char *domain = mpDomain; const char *destNumber = mpDestNumber; const char *context = NULL; const char *dialplan = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->GetUUID()), SWITCH_LOG_INFO, "WSClientParser::CreateCall( " "this : %p, " "profileName : '%s', " "profileContext : '%s', " "profileDialplan : '%s', " "ip : '%s' " ") \n", this, profileName, profileContext, profileDialplan, ip ); // 参数不能为空 if ( !user || !domain || !destNumber ) { status = SWITCH_STATUS_FALSE; } // 不允许一个连接创建多个会话 if( status == SWITCH_STATUS_SUCCESS && mpChannel ) { status = SWITCH_STATUS_FALSE; } if( status == SWITCH_STATUS_SUCCESS ) { pool = switch_core_session_get_pool(session); channel = switch_core_session_get_channel(session); switch_channel_set_name( channel, switch_core_session_sprintf(session, "ws/%s/%s/%s", profileName, user, destNumber) ); } // if ( status == SWITCH_STATUS_SUCCESS && !zstr(user) && !zstr(domain)) { // // 拨号不做验证 // const char *ivrUser = switch_core_session_sprintf(session, "%s@%s", user, domain); // status = switch_ivr_set_user(session, ivrUser); // } if( status == SWITCH_STATUS_SUCCESS ) { if (!(context = switch_channel_get_variable(channel, "user_context"))) { if (!(context = profileContext)) { context = "public"; } } if (!(dialplan = switch_channel_get_variable(channel, "inbound_dialplan"))) { if (!(dialplan = profileDialplan)) { dialplan = "LUA"; } } // switch_log_printf( // SWITCH_CHANNEL_SESSION_LOG(session), // SWITCH_LOG_NOTICE, // "WSClientParser::CreateCall( " // "context : %s, " // "dialplan : %s " // ") \n", // context, // dialplan // ); // 设置主叫 caller_profile = switch_caller_profile_new( pool, switch_str_nil(user), dialplan, SWITCH_DEFAULT_CLID_NAME, !zstr(user) ? user : SWITCH_DEFAULT_CLID_NUMBER, ip /* net addr */, NULL /* ani */, NULL /* anii */, NULL /* rdnis */, "mod_ws", context, destNumber ); switch_channel_set_caller_profile(channel, caller_profile); switch_core_session_add_stream(session, NULL); switch_channel_set_variable(channel, "caller", user); switch_channel_set_state(channel, CS_INIT); wsChannel = CreateChannel(session); } if( wsChannel ) { switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->GetUUID()), SWITCH_LOG_INFO, "WSClientParser::CreateCall( " "[Success], " "this : %p, " "wsChannel : %p, " "profileName : '%s', " "profileContext : '%s', " "profileDialplan : '%s', " "ip : '%s' " ") \n", this, wsChannel, profileName, profileContext, profileDialplan, ip ); } else { switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->GetUUID()), SWITCH_LOG_ERROR, "WSClientParser::CreateCall( " "[Fail], " "this : %p " ") \n", this, profileName, profileContext, profileDialplan, ip ); } return wsChannel; }
static switch_status_t create_session(switch_core_session_t **new_session, modem_t *modem) { switch_status_t status = SWITCH_STATUS_FALSE; switch_core_session_t *session; switch_channel_t *channel; private_t *tech_pvt = NULL; char name[1024]; switch_caller_profile_t *caller_profile; char *ani = NULL, *p, *digits = NULL; if (!(session = switch_core_session_request(modem_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, SOF_NONE, NULL))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Failure.\n"); goto end; } switch_core_session_add_stream(session, NULL); channel = switch_core_session_get_channel(session); tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(*tech_pvt)); p = switch_core_session_strdup(session, modem->digits); if (*p == '*') { ani = p + 1; if ((digits = strchr(ani, '*'))) { *digits++ = '\0'; } else { ani = NULL; } } if (zstr(digits)) { digits = p; } if (zstr(ani)) { ani = modem->devlink + 5; } switch_snprintf(name, sizeof(name), "modem/%d/%s", modem->slot, digits); switch_channel_set_name(channel, name); if (tech_init(tech_pvt, session) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_core_session_destroy(&session); goto end; } caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), modem->devlink, spandsp_globals.modem_dialplan, "FSModem", ani, NULL, ani, NULL, NULL, "mod_spandsp", spandsp_globals.modem_context, digits); caller_profile->source = switch_core_strdup(caller_profile->pool, "mod_spandsp"); switch_channel_set_caller_profile(channel, caller_profile); tech_pvt->caller_profile = caller_profile; switch_channel_set_state(channel, CS_INIT); if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error spawning thread\n"); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); goto end; } status = SWITCH_STATUS_SUCCESS; tech_attach(tech_pvt, modem); *new_session = session; end: return status; }