]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-598
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 18 Jun 2010 18:39:55 +0000 (13:39 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 18 Jun 2010 18:40:10 +0000 (13:40 -0500)
src/include/switch_channel.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/switch_channel.c

index a983121ba37e6fb9937c2d8e63f497d7d890e914..cffab0245f4d66393fbe8d6f877818b6ad145a2a 100644 (file)
@@ -162,8 +162,9 @@ SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, s
   \param status the status message
   \param id presence id
 */
-SWITCH_DECLARE(void) switch_channel_presence(switch_channel_t *channel, const char *rpid, const char *status, const char *id);
-
+SWITCH_DECLARE(void) switch_channel_perform_presence(switch_channel_t *channel, const char *rpid, const char *status, const char *id,
+                                                                                        const char *file, const char *func, int line);
+#define switch_channel_presence(_a, _b, _c, _d) switch_channel_perform_presence(_a, _b, _c, _d, __FILE__, __SWITCH_FUNC__, __LINE__)
 /*!
   \brief Uninitalize a channel
   \param channel the channel to uninit
index aa8516b016faaa4d99afbe6323dc31dd7b4502cf..fb206cf0301e2a15828799511a27010caa6326ee 100644 (file)
@@ -3857,8 +3857,28 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
        }
 #endif
 
-       caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
+       if (profile->pres_type) {
+               char *sql;
+               const char *presence_id = switch_channel_get_variable(nchannel, "presence_id");
+               const char *presence_data = switch_channel_get_variable(nchannel, "presence_data");
+
+               if (zstr(presence_id)) {
+                       presence_id = switch_event_get_header(var_event, "presence_id");
+               }
+
+               if (zstr(presence_data)) {
+                       presence_data = switch_event_get_header(var_event, "presence_data");
+               }
 
+               sql = switch_mprintf("insert into sip_dialogs (uuid,presence_id,presence_data,profile_name,hostname) "
+                                                        "values ('%q', '%q', '%q', '%q', '%q')", switch_core_session_get_uuid(nsession), 
+                                                        switch_str_nil(presence_id), switch_str_nil(presence_data), profile->name, mod_sofia_globals.hostname);
+               sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+               switch_safe_free(sql);
+       }
+       
+       caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
+       
 
        caller_profile->destination_number = switch_sanitize_number(caller_profile->destination_number);
        not_const = (char *) caller_profile->caller_id_name;
index 22f8fc23ad6cdecdc076a920aedf47ccb500d04b..a2291b4698574388c3e47d6ddb56edd2566355a0 100644 (file)
@@ -3859,7 +3859,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
                                switch_channel_t *a_channel;
 
                                const char *sip_redirect_profile, *sip_redirect_context, *sip_redirect_dialplan, *sip_redirect_fork;
-
+                               
                                if ((a_session = switch_core_session_locate(br)) && (a_channel = switch_core_session_get_channel(a_session))) {
                                        switch_stream_handle_t stream = { 0 };
                                        char separator[2] = "|";
@@ -4090,7 +4090,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
 
                                if (profile->pres_type) {
                                        const char *presence_data = switch_channel_get_variable(channel, "presence_data");
-                                       const char *presence_id = switch_channel_get_variable(channel, "presence_id");
+                                       //const char *presence_id = switch_channel_get_variable(channel, "presence_id");
                                        char *full_contact = "";
                                        char *p = NULL;
 
@@ -4101,18 +4101,26 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
                                        if (call_info && (p = strchr(call_info, ';'))) {
                                                p++;
                                        }
-                                       sql = switch_mprintf("insert into sip_dialogs "
-                                                                                "(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user,"
-                                                                                "contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info) "
-                                                                                "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+
+                                       sql = switch_mprintf("update sip_dialogs set "
+                                                                                "call_id='%q', "
+                                                                                "sip_to_user='%q', "
+                                                                                "sip_to_host='%q', "
+                                                                                "sip_from_user='%q', "
+                                                                                "sip_from_host='%q', "
+                                                                                "contact_user='%q', "
+                                                                                "contact_host='%q', "
+                                                                                "state='%q', "
+                                                                                "user_agent='%q', "
+                                                                                "contact='%q', "
+                                                                                "presence_data='%q', "
+                                                                                "call_info='%q' where uuid='%q'",
+
                                                                                 call_id,
-                                                                                switch_core_session_get_uuid(session),
                                                                                 to_user, to_host, from_user, from_host, contact_user,
-                                                                                contact_host, astate, "outbound", user_agent,
-                                                                                profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
-                                                                                switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
-
-                                       switch_assert(sql);
+                                                                                contact_host, astate, user_agent,
+                                                                                switch_str_nil(full_contact),
+                                                                                switch_str_nil(presence_data), switch_str_nil(p), switch_core_session_get_uuid(session));
 
                                        sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
                                        switch_safe_free(sql);
index daacf9efa662393707b2ec6b63af4c21e523b4a8..87294c1e62d06861ea3c62ffc0ad5bbad5c88626 100644 (file)
@@ -583,6 +583,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
        if (!mod_sofia_globals.profile_hash)
                goto done;
 
+
        switch_mutex_lock(mod_sofia_globals.hash_mutex);
        for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
                switch_hash_this(hi, &var, NULL, &val);
@@ -602,10 +603,10 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                        continue;
                }
 
+
                if (call_info) {
                        const char *uuid = switch_event_get_header(event, "unique-id");
 
-
 #if 0
                        if (mod_sofia_globals.debug_sla > 1) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n");
@@ -635,9 +636,24 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                        }
 
                        sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE);
-               }
-
+               } else {
+                       char count_buf[128] = "";
+                       int count = 0;
+                       const char *state = switch_event_get_header(event, "channel-state");
+                       
+                       sql = switch_mprintf("select count(*) from sip_dialogs "
+                                                                "where hostname='%q' and presence_id='%q@%q'", mod_sofia_globals.hostname, euser, host);
+                       sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, count_buf, sizeof(count_buf));
 
+                       count = atoi(count_buf);
+                       
+                       switch_safe_free(sql);
+                       
+                       if (count > 1 || (count > 0 && switch_stristr("hangup", state))) {
+                               continue;
+                       }
+               }
+               
                if ((sql = switch_mprintf("select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
                                                                  "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
                                                                  "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
index 36a4989a0aa26d2a039c97b1b1ad005074b04935..df7601199ea6b65e2dcb49b64e40c82d9bf2b19f 100644 (file)
@@ -552,7 +552,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, s
        return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(void) switch_channel_presence(switch_channel_t *channel, const char *rpid, const char *status, const char *id)
+SWITCH_DECLARE(void) switch_channel_perform_presence(switch_channel_t *channel, const char *rpid, const char *status, const char *id,
+                                                                                                        const char *file, const char *func, int line)
 {
        switch_event_t *event;
        switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
@@ -611,8 +612,11 @@ SWITCH_DECLARE(void) switch_channel_presence(switch_channel_t *channel, const ch
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction",
                                                                           channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
 
-
+               
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", channel->event_count++);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Calling-File", file);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Calling-Function", func);
+               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Presence-Calling-Line", "%d", line);
                switch_event_fire(&event);
        }
 }