From 3af93e2b8362305a8a78ca4079f4535e8995edba Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 18 Dec 2007 03:12:51 +0000 Subject: [PATCH] blinking lights for xmas presence(3rd time's a charm) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6855 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- conf/autoload_configs/conference.conf.xml | 2 +- src/mod/endpoints/mod_sofia/sofia.c | 6 +-- src/mod/endpoints/mod_sofia/sofia_presence.c | 40 +++++++++++++------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/conf/autoload_configs/conference.conf.xml b/conf/autoload_configs/conference.conf.xml index 430b095b9a..8e28c11020 100644 --- a/conf/autoload_configs/conference.conf.xml +++ b/conf/autoload_configs/conference.conf.xml @@ -64,7 +64,7 @@ - + diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 67045ee7c5..587eacc74a 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1160,10 +1160,10 @@ void sofia_event_callback(nua_event_t event, if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) && !switch_channel_test_flag(channel, CF_RING_READY)) { - const char *to_user = switch_str_nil(sip->sip_to->a_url->url_user); - const char *to_host = switch_str_nil(sip->sip_to->a_url->url_host); - const char *from_user = switch_str_nil(sip->sip_from->a_url->url_user); + const char *from_user = switch_str_nil(sip->sip_to->a_url->url_user); const char *from_host = switch_str_nil(sip->sip_from->a_url->url_host); + const char *to_user = switch_str_nil(sip->sip_from->a_url->url_user); + const char *to_host = switch_str_nil(sip->sip_from->a_url->url_host); const char *contact_user = switch_str_nil(sip->sip_contact->m_url->url_user); const char *contact_host = switch_str_nil(sip->sip_contact->m_url->url_host); const char *user_agent = switch_str_nil(sip->sip_user_agent->g_string); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index f2975d08db..4d715c31e6 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -398,10 +398,8 @@ void sofia_presence_event_handler(switch_event_t *event) sql = switch_mprintf("select sip_registrations.sip_user, sip_registrations.sip_host, sip_registrations.status, " "sip_registrations.rpid,'', sip_dialogs.uuid, sip_dialogs.state, sip_dialogs.direction " "from sip_registrations left join sip_dialogs on " - "(sip_dialogs.contact_user = sip_registrations.sip_user or " - "sip_dialogs.sip_from_user = sip_registrations.sip_user or " - "sip_dialogs.sip_to_user = sip_registrations.sip_user) " - "and sip_dialogs.sip_to_host = sip_registrations.sip_host " + "(sip_dialogs.sip_from_user = sip_registrations.sip_user) " + "and sip_dialogs.sip_from_host = sip_registrations.sip_host " "where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'", probe_euser, probe_host); switch_assert(sql); @@ -536,7 +534,6 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char switch_event_add_header(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", 0); - if (switch_strlen_zero(state)) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", SOFIA_CHAT_PROTO); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", "CS_HANGUP"); @@ -545,6 +542,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", "CS_RING"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", uuid); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", state); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "astate", "%s", state); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", direction); } @@ -659,11 +657,11 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char * const char *uuid = switch_str_nil(switch_event_get_header(helper->event, "unique-id")); const char *state = switch_str_nil(switch_event_get_header(helper->event, "channel-state")); const char *event_status = switch_str_nil(switch_event_get_header(helper->event, "status")); - const char *astate = switch_str_nil(switch_event_get_header(helper->event, "answer-state")); + const char *astate = switch_str_nil(switch_event_get_header(helper->event, "astate")); const char *dft_state; SWITCH_STANDARD_STREAM(stream); - + if (!strcasecmp(direction, "outbound")) { direction = "recipient"; dft_state = "early"; @@ -671,21 +669,35 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char * direction = "initiator"; dft_state = "confirmed"; } - + if (!strcasecmp(state, "cs_execute")) { goto end; - } if (!strcasecmp(state, "cs_hangup")) { + } else if (!strcasecmp(state, "cs_hangup")) { astate = "terminated"; - } else if (!strcasecmp(astate, "answered")) { - astate = "confirmed"; - } else { - astate = dft_state; - } + } else if (switch_strlen_zero(astate)) { + astate = switch_str_nil(switch_event_get_header(helper->event, "answer-state")); + if (switch_strlen_zero(astate)) { + astate = dft_state; + } + } if (!strcasecmp(event_status, "hold")) { astate = "early"; } + if (!strcasecmp(astate, "answered")) { + astate = "confirmed"; + } + + if (!strcasecmp(astate, "ringing")) { + if (!strcasecmp(direction, "recipient")) { + astate = "early"; + } else { + astate = "confirmed"; + } + } + + stream.write_function(&stream, "\n" "