]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add presence-probe-on-register sofia param to send a probe on register instead of...
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 25 Nov 2010 03:39:08 +0000 (21:39 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 25 Nov 2010 03:39:08 +0000 (21:39 -0600)
conf/sip_profiles/internal.xml
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index 93558a3584add2a6dc8ee44e023d37011d5f9c6b..3e756a85c0f962c32e2bc895deb2a773dce22e1b 100644 (file)
     <param name="record-template" value="${caller_id_number}.${target_domain}.${strftime(%Y-%m-%d-%H-%M-%S)}.wav"/>
     <!--enable to use presence -->
     <param name="manage-presence" value="true"/>
+    <!-- send a presence probe on each register to query devices to send presence instead of sending presence with less info -->
+    <!--<param name="presence-probe-on-register" value="true"/>-->
     <!--<param name="manage-shared-appearance" value="true"/>-->
     <!-- used to share presence info across sofia profiles -->
     <!-- Name of the db to use for this profile -->
index 3c8404dd6b7bc1c930c05b7a97fd9f3198592bd2..3bb926adf3cf573a71f56539dacb895a9145d3b9 100644 (file)
@@ -3936,7 +3936,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
                        dest_num = p + 5;
                }
        }
-#endif
+
 
        if (profile->pres_type) {
                char *sql;
@@ -3957,6 +3957,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
                sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
                switch_safe_free(sql);
        }
+#endif
 
        caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
 
index c1244c05f1322c3d9bafe54afb966ec028184ed3..6970a7ab05a6d3d3e9d1a370a142bbdf516d57a8 100644 (file)
@@ -224,6 +224,7 @@ typedef enum {
        PFLAG_IN_DIALOG_CHAT,
        PFLAG_DEL_SUBS_ON_REG,
        PFLAG_IGNORE_183NOSDP,
+       PFLAG_PRESENCE_PROBE_ON_REGISTER,
        /* No new flags below this line */
        PFLAG_MAX
 } PFLAGS;
index 4d9bd7fd7ba6a6a29b5002e3fadc291b3adf420f..e20d868548c4de88006025eb798084c65045667c 100644 (file)
@@ -2405,6 +2405,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile)
                                                } else {
                                                        sofia_clear_pflag(profile, PFLAG_IGNORE_183NOSDP);
                                                }
+                                       } else if (!strcasecmp(var, "presence-probe-on-register")) {
+                                               if (switch_true(val)) {
+                                                       sofia_set_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
+                                               } else {
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
+                                               }
                                        } else if (!strcasecmp(var, "cid-in-1xx")) {
                                                if (switch_true(val)) {
                                                        sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
@@ -3070,6 +3076,12 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                                } else {
                                                        sofia_clear_pflag(profile, PFLAG_IGNORE_183NOSDP);
                                                }
+                                       } else if (!strcasecmp(var, "presence-probe-on-register")) {
+                                               if (switch_true(val)) {
+                                                       sofia_set_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
+                                               } else {
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
+                                               }
                                        } else if (!strcasecmp(var, "cid-in-1xx")) {
                                                if (switch_true(val)) {
                                                        sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
@@ -4420,7 +4432,6 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
                                                                                 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);
 
                                        sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
@@ -6872,8 +6883,9 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
 
                        sql =
                                switch_mprintf
-                               ("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q' and call_id is not null",
-                                switch_str_nil(p), user, host);
+                               ("select call_id from sip_dialogs where call_info='%q' and ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
+                                "and call_id is not null",
+                                switch_str_nil(p), user, host, user, host);
 
                        if ((str = sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, cid, sizeof(cid)))) {
                                bnh = nua_handle_by_call_id(nua, str);
index 4b853de6b1e694559cf6b8350c94445aa48400eb..95ea913a61a6932f9d6a0d5e54f52413d086b17f 100644 (file)
@@ -567,7 +567,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                        }
 
                        if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
-                               sql = switch_mprintf("select status,rpid from sip_dialogs where sip_from_user='%q' and sip_from_host='%q'", probe_euser, probe_host);
+                               sql = switch_mprintf("select status,rpid from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q')", 
+                                                                        probe_euser, probe_host, probe_euser, probe_host);
                                sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
 
                                h.profile = profile;
@@ -591,9 +592,11 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                                         "'%q','%q' "
 
                                                                         "from sip_registrations left join sip_dialogs on "
-                                                                        "(sip_dialogs.sip_from_user = sip_registrations.sip_user "
-                                                                        "and (sip_dialogs.sip_from_host = sip_registrations.orig_server_host or "
-                                                                        "sip_dialogs.sip_from_host = sip_registrations.sip_host) ) "
+                                                                        "sip_dialogs.presence_id = sip_registrations.sip_user || '@' || sip_registrations.sip_host "
+
+
+                                                                        "or (sip_dialogs.sip_from_user = sip_registrations.sip_user "
+                                                                        "and sip_dialogs.sip_from_host = sip_registrations.sip_host) "
  
                                                                         "left join sip_presence on "
                                                                         "(sip_registrations.sip_user=sip_presence.sip_user and sip_registrations.orig_server_host=sip_presence.sip_host and "
@@ -601,7 +604,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                                         "where sip_dialogs.presence_id='%q@%q' or (sip_registrations.sip_user='%q' and "
                                                                         "(sip_registrations.orig_server_host='%q' or sip_registrations.sip_host='%q' "
                                                                         "or sip_registrations.presence_hosts like '%%%q%%'))",
-                                                                        dh.status, dh.rpid, probe_euser, probe_host,  probe_euser, probe_host, probe_host, probe_host);
+                                                                        dh.status, dh.rpid, 
+                                                                        probe_euser, probe_host,  probe_euser, probe_host, probe_host, probe_host);
                                switch_assert(sql);
                                
                                if (mod_sofia_globals.debug_presence > 0) {
@@ -711,9 +715,10 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                sql = switch_mprintf("update sip_dialogs set call_info='%q',call_info_state='%q' where hostname='%q' and uuid='%q'",
                                                                         call_info, call_info_state, mod_sofia_globals.hostname, uuid);
                        } else {
-                               sql = switch_mprintf("update sip_dialogs set call_info='%q', call_info_state='%q' where hostname='%q' and sip_dialogs.sip_from_user='%q' "
-                                                                        "and sip_dialogs.sip_from_host='%q' and call_info='%q'",
-                                                                        call_info, call_info_state, mod_sofia_globals.hostname, euser, host, call_info);
+                               sql = switch_mprintf("update sip_dialogs set call_info='%q', call_info_state='%q' where hostname='%q' and "
+                                                                        "((sip_dialogs.sip_from_user='%q' and sip_dialogs.sip_from_host='%q') or presence_id='%q@%q') and call_info='%q'",
+                                                                        
+                                                                        call_info, call_info_state, mod_sofia_globals.hostname, euser, host, euser, host, call_info);
 
                        }
 
@@ -737,7 +742,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                        sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
                }
 
-               sql = switch_mprintf("select status,rpid from sip_dialogs where sip_from_user='%q' and sip_from_host='%q'", euser, host);
+               sql = switch_mprintf("select status,rpid from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q')", 
+                                                        euser, host, euser, host);
                sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
                switch_safe_free(sql);
                
@@ -753,17 +759,20 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                                  "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
                                                                  "sip_subscriptions.profile_name=sip_presence.profile_name) "
                                                                  "left join sip_dialogs on "
+                                                                 
+                                                                 "sip_dialogs.presence_id = sip_subscriptions.sub_to_user || '@' || sip_subscriptions.sub_to_host or "
 
+                                                                 
                                                                  "(sip_dialogs.sip_from_user = sip_subscriptions.sub_to_user "
                                                                  "and sip_dialogs.sip_from_host = sip_subscriptions.sub_to_host) "
                                                                  
                                                                  "where sip_subscriptions.expires > -1 and "
-                                                                 "(event='%q' or event='%q') and (sub_to_user='%q' or sip_dialogs.presence_id like '%q@%%') "
+                                                                 "(event='%q' or event='%q') and sub_to_user='%q' "
                                                                  "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
                                                                  "and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host)",
                                                                  switch_str_nil(status), switch_str_nil(rpid), host, 
                                                                  dh.status,dh.rpid,
-                                                                 event_type, alt_event_type, euser, euser, host, host, profile->name))) {
+                                                                 event_type, alt_event_type, euser, host, host, profile->name))) {
                        
                        struct presence_helper helper = { 0 };                  
 
@@ -1918,7 +1927,8 @@ static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *
        switch_core_hash_init(&sh->hash, sh->pool);
 
        sql = switch_mprintf("select sip_from_user,sip_from_host,call_info,call_info_state,uuid from sip_dialogs "
-                                                "where hostname='%q' " "and sip_from_user='%q' and sip_from_host='%q' ", mod_sofia_globals.hostname, to_user, to_host);
+                                                "where hostname='%q' " "and ((sip_from_user='%q' and sip_from_host='%q) or presence_id='%q@%q')' ", 
+                                                mod_sofia_globals.hostname, to_user, to_host, to_user, to_host);
 
 
        if (mod_sofia_globals.debug_sla > 1) {
@@ -1954,7 +1964,8 @@ static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *
 
 
        if (clear) {
-               sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'", to_user, to_host);
+               sql = switch_mprintf("delete from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
+                                                        "and call_info_state='seized'", to_user, to_host, to_user, to_host);
 
 
                if (mod_sofia_globals.debug_sla > 1) {
@@ -2326,8 +2337,9 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CANCEL LINE SEIZE\n");
                                        }
 
-                                       sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
-                                                                                to_user, to_host);
+                                       sql = switch_mprintf("delete from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
+                                                                                "and call_info_state='seized'",
+                                                                                to_user, to_host, to_user, to_host);
 
 
                                        if (mod_sofia_globals.debug_sla > 1) {
@@ -2360,8 +2372,9 @@ void sofia_presence_handle_sip_i_subscribe(int status,
 
 
 
-                                       sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
-                                                                                to_user, to_host);
+                                       sql = switch_mprintf("delete from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') "
+                                                                                "and call_info_state='seized'",
+                                                                                to_user, to_host, to_user, to_host);
 
 
                                        if (mod_sofia_globals.debug_sla > 1) {
index 216f808e4f348dbabc997f38f5c130eb1b6ea2df..e93bdaac088b52196503a733620387dca11e29a1 100644 (file)
@@ -1445,27 +1445,27 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                }
                        }
 
-
-#if 0
-                       if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
-                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
-                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, sub_host);
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
-                               switch_event_fire(&s_event);
+                       if (sofia_test_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER)) {
+                               if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
+                                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
+                                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, sub_host);
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+                                       switch_event_fire(&s_event);
+                               }
+                       } else {
+                               if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
+                                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
+                                       switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", "Registered");
+                                       switch_event_fire(&s_event);
+                               }               
                        }
-#else
-                       if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
-                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
-                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", "Registered");
-                               switch_event_fire(&s_event);
-                       }                               
-#endif
+                       
                } else {
                        if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "profile-name", profile->name);