mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
adding some inter channel communication and other code for real-world usage (not totally done)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@646 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -63,7 +63,8 @@ typedef enum {
|
||||
TFLAG_USING_CODEC = (1 << 6),
|
||||
TFLAG_RTP = (1 << 7),
|
||||
TFLAG_BYE = (1 << 8),
|
||||
TFLAG_ANS = (1 << 9)
|
||||
TFLAG_ANS = (1 << 9),
|
||||
TFLAG_EARLY_MEDIA = (1 << 10)
|
||||
} TFLAGS;
|
||||
|
||||
|
||||
@@ -465,7 +466,7 @@ static switch_status exosip_answer_channel(switch_core_session *session)
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
assert(tech_pvt != NULL);
|
||||
|
||||
if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_channel_test_flag(channel, CF_OUTBOUND)) {
|
||||
if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_channel_test_flag(channel, CF_OUTBOUND) ) {
|
||||
char *buf = NULL;
|
||||
osip_message_t *answer = NULL;
|
||||
|
||||
@@ -666,6 +667,54 @@ static switch_status exosip_waitfor_write(switch_core_session *session, int ms,
|
||||
|
||||
}
|
||||
|
||||
static switch_status exosip_send_dtmf(switch_core_session *session, char *digits)
|
||||
{
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
static switch_status exosip_receive_message(switch_core_session *session, switch_core_session_message *msg)
|
||||
{
|
||||
|
||||
switch (msg->message_id) {
|
||||
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
||||
if (msg) {
|
||||
struct private_object *tech_pvt;
|
||||
switch_channel *channel = NULL;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
assert(tech_pvt != NULL);
|
||||
|
||||
if (!switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
|
||||
char *buf = NULL;
|
||||
osip_message_t *progress = NULL;
|
||||
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Asked to send early media by %s\n", msg->from);
|
||||
|
||||
/* Transmit 183 Progress with SDP */
|
||||
eXosip_lock();
|
||||
eXosip_call_build_answer(tech_pvt->tid, 183, &progress);
|
||||
sdp_message_to_str(tech_pvt->local_sdp, &buf);
|
||||
osip_message_set_body(progress, buf, strlen(buf));
|
||||
osip_message_set_content_type(progress, "application/sdp");
|
||||
free(buf);
|
||||
eXosip_call_send_answer(tech_pvt->tid, 183, progress);
|
||||
eXosip_unlock();
|
||||
switch_set_flag(tech_pvt, TFLAG_EARLY_MEDIA);
|
||||
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static const switch_io_routines exosip_io_routines = {
|
||||
/*.outgoing_channel */ exosip_outgoing_channel,
|
||||
/*.answer_channel */ exosip_answer_channel,
|
||||
@@ -673,7 +722,9 @@ static const switch_io_routines exosip_io_routines = {
|
||||
/*.write_frame */ exosip_write_frame,
|
||||
/*.kill_channel */ exosip_kill_channel,
|
||||
/*.waitfor_read */ exosip_waitfor_read,
|
||||
/*.waitfor_read */ exosip_waitfor_write
|
||||
/*.waitfor_read */ exosip_waitfor_write,
|
||||
/*.send_dtmf*/ exosip_send_dtmf,
|
||||
/*.receive_message*/ exosip_receive_message
|
||||
};
|
||||
|
||||
static const switch_state_handler_table exosip_event_handlers = {
|
||||
@@ -725,13 +776,15 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc
|
||||
|
||||
if (outbound_profile) {
|
||||
char name[128];
|
||||
switch_caller_profile *caller_profile;
|
||||
switch_caller_profile *caller_profile = NULL;
|
||||
|
||||
snprintf(name, sizeof(name), "Exosip/%s-%04x", outbound_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
|
||||
|
||||
switch_channel_set_caller_profile(channel, caller_profile);
|
||||
tech_pvt->caller_profile = caller_profile;
|
||||
snprintf(name, sizeof(name), "Exosip/%s-%04x", caller_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Doh! no caller profile\n");
|
||||
switch_core_session_destroy(new_session);
|
||||
@@ -806,6 +859,9 @@ static switch_status exosip_create_call(eXosip_event_t * event)
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
}
|
||||
|
||||
snprintf(name, sizeof(name), "Exosip/%s-%04x", event->request->from->url->username, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
|
||||
globals.dialplan,
|
||||
event->request->from->displayname,
|
||||
@@ -820,8 +876,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
|
||||
tech_pvt->cid = event->cid;
|
||||
tech_pvt->tid = event->tid;
|
||||
|
||||
snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
|
||||
if ((remote_sdp = eXosip_get_sdp_info(event->request)) == 0) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n");
|
||||
|
||||
@@ -733,11 +733,13 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
|
||||
|
||||
if (outbound_profile) {
|
||||
char name[128];
|
||||
|
||||
snprintf(name, sizeof(name), "IAX/%s-%04x", outbound_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
|
||||
switch_channel_set_caller_profile(channel, caller_profile);
|
||||
tech_pvt->caller_profile = caller_profile;
|
||||
snprintf(name, sizeof(name), "IAX/%s-%04x", caller_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Doh! no caller profile\n");
|
||||
switch_core_session_destroy(new_session);
|
||||
@@ -983,10 +985,11 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
|
||||
iaxevent->ies.calling_ani,
|
||||
NULL, iaxevent->ies.called_number)) != 0) {
|
||||
char name[128];
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||
snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number,
|
||||
rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||
|
||||
}
|
||||
|
||||
if (iax_set_codec(tech_pvt, iaxevent->session,
|
||||
|
||||
@@ -498,13 +498,14 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
|
||||
|
||||
if (outbound_profile) {
|
||||
char name[128];
|
||||
snprintf(name, sizeof(name), "PortAudio/%s-%04x",
|
||||
caller_profile->destination_number ? outbound_profile->destination_number : modname,
|
||||
rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
|
||||
switch_channel_set_caller_profile(channel, caller_profile);
|
||||
tech_pvt->caller_profile = caller_profile;
|
||||
snprintf(name, sizeof(name), "PortAudio/%s-%04x",
|
||||
caller_profile->destination_number ? caller_profile->destination_number : modname,
|
||||
rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Doh! no caller profile\n");
|
||||
switch_core_session_destroy(new_session);
|
||||
@@ -812,11 +813,12 @@ static switch_status place_call(char *dest, char *out, size_t outlen)
|
||||
globals.cid_name,
|
||||
globals.cid_num, NULL, NULL, NULL, dest)) != 0) {
|
||||
char name[128];
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||
snprintf(name, sizeof(name), "PortAudio/%s-%04x",
|
||||
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->
|
||||
destination_number : modname, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||
}
|
||||
tech_pvt->session = session;
|
||||
if ((status = engage_device(tech_pvt)) == SWITCH_STATUS_SUCCESS) {
|
||||
|
||||
@@ -381,11 +381,12 @@ static switch_status wanpipe_outgoing_channel(switch_core_session *session, swit
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
snprintf(name, sizeof(name), "WanPipe/%s-%04x", caller_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
switch_channel_set_caller_profile(channel, caller_profile);
|
||||
tech_pvt->caller_profile = caller_profile;
|
||||
snprintf(name, sizeof(name), "WanPipe/%s-%04x", caller_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
|
||||
do {
|
||||
if ((spri = &SPANS[span]->spri)) {
|
||||
@@ -704,6 +705,43 @@ static int on_answer(struct sangoma_pri *spri, sangoma_pri_event_t event_type, p
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
|
||||
{
|
||||
switch_core_session *session;
|
||||
switch_channel *channel;
|
||||
struct channel_map *chanmap;
|
||||
|
||||
chanmap = spri->private;
|
||||
|
||||
if ((session = chanmap->map[event->proceeding.channel])) {
|
||||
switch_caller_profile *originator;
|
||||
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Proceeding on channel %d\n", event->proceeding.channel);
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
if ((originator = switch_channel_get_originator_caller_profile(channel))) {
|
||||
switch_core_session_message msg;
|
||||
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Passing progress to Originator %s\n", originator->chan_name);
|
||||
|
||||
msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
|
||||
msg.from = switch_channel_get_name(channel);
|
||||
|
||||
switch_core_session_message_send(originator->uuid, &msg);
|
||||
|
||||
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
|
||||
}
|
||||
|
||||
//switch_channel_answer(channel);
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Proceeding on channel %d but it's not in use?\n", event->proceeding.channel);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
|
||||
{
|
||||
switch_core_session *session;
|
||||
@@ -770,6 +808,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
|
||||
switch_core_session_set_private(session, tech_pvt);
|
||||
sprintf(name, "w%dg%d", spri->span, event->ring.channel);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n");
|
||||
switch_core_session_destroy(&session);
|
||||
@@ -867,8 +906,10 @@ static void *pri_thread_run(switch_thread *thread, void *obj)
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RING, on_ring);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RINGING, on_ringing);
|
||||
//SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_SETUP_ACK, on_ringing);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_PROCEEDING, on_proceed);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_ANSWER, on_answer);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_HANGUP_REQ, on_hangup);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_HANGUP, on_hangup);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_INFO_RECEIVED, on_info);
|
||||
SANGOMA_MAP_PRI_EVENT((*spri), SANGOMA_PRI_EVENT_RESTART, on_restart);
|
||||
|
||||
|
||||
@@ -490,11 +490,12 @@ static switch_status woomerachan_outgoing_channel(switch_core_session *session,
|
||||
char name[128];
|
||||
switch_caller_profile *caller_profile;
|
||||
|
||||
snprintf(name, sizeof(name), "Woomera/%s-%04x", outbound_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
|
||||
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
|
||||
switch_channel_set_caller_profile(channel, caller_profile);
|
||||
tech_pvt->caller_profile = caller_profile;
|
||||
snprintf(name, sizeof(name), "Woomera/%s-%04x", caller_profile->destination_number, rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Doh! no caller profile\n");
|
||||
switch_core_session_destroy(new_session);
|
||||
@@ -1067,10 +1068,11 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
|
||||
tech_pvt->profile->dialplan,
|
||||
cid_name, cid_num, ip, NULL, NULL, exten)) != 0) {
|
||||
char name[128];
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||
snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number,
|
||||
rand() & 0xffff);
|
||||
switch_channel_set_name(channel, name);
|
||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||
|
||||
}
|
||||
|
||||
woomera_printf(tech_pvt->profile, tech_pvt->command_channel,
|
||||
|
||||
Reference in New Issue
Block a user