]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add send-presence-on-register (true|false|first-only) param to sofia and api command...
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 14 Jan 2011 19:57:58 +0000 (13:57 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 14 Jan 2011 19:58:21 +0000 (13:58 -0600)
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_reg.c

index 85b233d5f30dd08a83d2ae94ddc69d2e102093be..8f012904072b8ddfdeaa578613a0a521bfd88eda 100644 (file)
@@ -3695,11 +3695,39 @@ SWITCH_STANDARD_API(sofia_function)
                int wdon = -1;
 
                if (argc > 1) {
+                       if (!strcasecmp(argv[1], "debug")) {
+
+                               if (argc > 2) {
+                                       if (strstr(argv[2], "presence")) {
+                                               mod_sofia_globals.debug_presence = 1;
+                                               stream->write_function(stream, "+OK Debugging presence\n");
+                                       }
+                                       
+                                       if (strstr(argv[2], "sla")) {
+                                               mod_sofia_globals.debug_sla = 1;
+                                               stream->write_function(stream, "+OK Debugging sla\n");
+                                       }
+                                       
+                                       if (strstr(argv[2], "none")) {
+                                               stream->write_function(stream, "+OK Debugging nothing\n");
+                                               mod_sofia_globals.debug_presence = 0;
+                                               mod_sofia_globals.debug_sla = 0;
+                                       }
+                               }
+
+                               stream->write_function(stream, "+OK Debugging summary: presence: %s sla: %s\n", 
+                                                                          mod_sofia_globals.debug_presence ? "on" : "off",
+                                                                          mod_sofia_globals.debug_sla ? "on" : "off");
+                               
+                               goto done;
+                       }
+                       
                        if (!strcasecmp(argv[1], "siptrace")) {
                                if (argc > 2) {
                                        ston = switch_true(argv[2]);
                                }
                        }
+
                        if (!strcasecmp(argv[1], "watchdog")) {
                                if (argc > 2) {
                                        wdon = switch_true(argv[2]);
@@ -3714,7 +3742,7 @@ SWITCH_STANDARD_API(sofia_function)
                        sofia_glue_global_watchdog(wdon);
                        stream->write_function(stream, "+OK Global watchdog %s", wdon ? "on" : "off");
                } else {
-                       stream->write_function(stream, "-ERR Usage: siptrace <on|off>|watchdog <on|off>");
+                       stream->write_function(stream, "-ERR Usage: siptrace <on|off>|watchdog <on|off>|debug <sla|presence|none");
                }
                
                goto done;
@@ -4838,6 +4866,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
        switch_console_set_complete("add sofia global siptrace ::[on:off");
        switch_console_set_complete("add sofia global watchdog ::[on:off");
 
+       switch_console_set_complete("add sofia global debug ::[presence:sla:none");
+
+
        switch_console_set_complete("add sofia profile");
        switch_console_set_complete("add sofia profile restart all");
 
index b6ce97dac6993143bdeff9190c8874fed067b5e4..12148c0f1bdb106491aa36d34ef5ca7c7edef9bb 100644 (file)
@@ -225,6 +225,8 @@ typedef enum {
        PFLAG_DEL_SUBS_ON_REG,
        PFLAG_IGNORE_183NOSDP,
        PFLAG_PRESENCE_PROBE_ON_REGISTER,
+       PFLAG_PRESENCE_ON_REGISTER,
+       PFLAG_PRESENCE_ON_FIRST_REGISTER,
        PFLAG_NO_CONNECTION_REUSE,
        /* No new flags below this line */
        PFLAG_MAX
index 1d8d6a9a212b2a68affa839276d01ce26cceaa04..643b3dd81418b61ba2c4be8599f6118dfb0cb7fe 100644 (file)
@@ -2419,6 +2419,17 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile)
                                                } else {
                                                        sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
                                                }
+
+                                       } else if (!strcasecmp(var, "send-presence-on-register")) {
+                                               if (switch_true(val)) {
+                                                       sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
+                                               } else if (!strcasecmp(val, "first-only")) {
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
+                                                       sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
+                                               } else {
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
+                                               }
                                        } else if (!strcasecmp(var, "cid-in-1xx")) {
                                                if (switch_true(val)) {
                                                        sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
@@ -3008,6 +3019,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
                                sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
                                sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
+                               sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
                                profile->shutdown_type = "false";
                                profile->local_network = "localnet.auto";
                                sofia_set_flag(profile, TFLAG_ENABLE_SOA);
@@ -3090,6 +3102,16 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                                } else {
                                                        sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
                                                }
+                                       } else if (!strcasecmp(var, "send-presence-on-register")) {
+                                               if (switch_true(val)) {
+                                                       sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
+                                               } else if (!strcasecmp(val, "first-only")) {
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
+                                                       sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
+                                               } else {
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
+                                                       sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
+                                               }
                                        } else if (!strcasecmp(var, "cid-in-1xx")) {
                                                if (switch_true(val)) {
                                                        sofia_set_pflag(profile, PFLAG_CID_IN_1XX);
index 288191807cecd34b3a38abc5b25bf962fd855052..344e51774d113b61491d0777dafd562e105f3221 100644 (file)
@@ -875,9 +875,19 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        long reg_count = 0;
        int delete_subs;
        const char *agent = "unknown";
-               
+       const char *pres_on_reg = NULL;
+       int send_pres = 0;
+
        delete_subs = sofia_test_pflag(profile, PFLAG_DEL_SUBS_ON_REG);
 
+       if (v_event && *v_event) pres_on_reg = switch_event_get_header(*v_event, "send-presence-on-register");
+
+       if (!(send_pres = switch_true(pres_on_reg))) {
+               if (pres_on_reg && !strcasecmp(pres_on_reg, "first-only")) {
+                       send_pres = 2;
+               }
+       }
+
        /* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
        switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
 
@@ -1405,7 +1415,6 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        }
                }
 
-               
                if (send && switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
@@ -1493,27 +1502,31 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                }
                        }
 
-                       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);
+                       if (sofia_test_pflag(profile, PFLAG_PRESENCE_ON_REGISTER) || 
+                               (reg_count == 1 && sofia_test_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER)) 
+                               || send_pres == 1 || (reg_count == 1 && send_pres == 2)) {
+                               
+                               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);
-                               }               
                        }
-                       
                } 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);