]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Allow setting late margin on register expirations
authorTravis Cross <tc@traviscross.com>
Thu, 20 Feb 2014 15:59:38 +0000 (15:59 +0000)
committerTravis Cross <tc@traviscross.com>
Thu, 20 Feb 2014 16:07:53 +0000 (16:07 +0000)
When an endpoint registers to us we internally mark the expiration as
some seconds longer than the actual registration.  Previously this
value was fixed at 60 seconds.

Some people need this value to be shorter so they can meet their SLA
by taking a different action when a device doesn't re-register when
expected.

This commit adds a SIP profile parameter sip-expires-late-margin which
allows setting the margin value we apply here.

FS-6101 --resolve

Thanks-to: Emmanuel Schmidbauer <e.schmidbauer@gmail.com>
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index 966301001d8de9cc98b428fedbd4840096f1932f..b600822bd3ea6fcda83161f044067e50f2d4679a 100644 (file)
@@ -685,6 +685,7 @@ struct sofia_profile {
        su_strlst_t *tls_verify_in_subjects;
        uint32_t sip_force_expires;
        uint32_t sip_expires_max_deviation;
+       uint32_t sip_expires_late_margin;
        uint32_t sip_subscription_max_deviation;
        int ireg_seconds;
        sofia_paid_type_t paid_type;
index 499c718a85fe9885ef2b50eea04dc6fdfe473956..a3db892176756e46e0a76bce7d943ed00dea480c 100644 (file)
@@ -3765,6 +3765,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
                                        profile->rtp_digit_delay = 40;
                                        profile->sip_force_expires = 0;
                                        profile->sip_expires_max_deviation = 0;
+                                       profile->sip_expires_late_margin = 60;
                                        profile->sip_subscription_max_deviation = 0;
                                        profile->tls_ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH";
                                        profile->tls_version = SOFIA_TLS_VERSION_TLSv1;
@@ -4769,6 +4770,13 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
                                                                                                } else {
                                                                                                                sofia_clear_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY);
                                                                                                }
+                                       } else if (!strcasecmp(var, "sip-expires-late-margin")) {
+                                               int32_t sip_expires_late_margin = atoi(val);
+                                               if (sip_expires_late_margin >= 0) {
+                                                       profile->sip_expires_late_margin = sip_expires_late_margin;
+                                               } else {
+                                                       profile->sip_expires_late_margin = 60;
+                                               }
                                        } else if (!strcasecmp(var, "sip-force-expires")) {
                                                int32_t sip_force_expires = atoi(val);
                                                if (sip_force_expires >= 0) {
index a4048767c841bc6ef2a8a96fc6f479d001f5f50f..5f600aca0014162c56e33b691482cf580a7f1057 100644 (file)
@@ -1731,7 +1731,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                contact = sofia_glue_get_url_from_contact(contact_str, 1);
                url = switch_mprintf("sofia/%q/%s:%q", profile->name, proto, sofia_glue_strip_proto(contact));
                
-               switch_core_add_registration(to_user, reg_host, call_id, url, (long) reg_time + (long) exptime + 60,
+               switch_core_add_registration(to_user, reg_host, call_id, url, (long) reg_time + (long) exptime + profile->sip_expires_late_margin,
                                                                         network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta);
 
                switch_safe_free(url);
@@ -1777,7 +1777,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                        "mwi_user,mwi_host, orig_server_host, orig_hostname, sub_host) "
                                        "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q','%q','%q','%q','%q','%q')", 
                                        call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : "", 
-                                       contact_str, reg_desc, rpid, (long) reg_time + (long) exptime + 60, 
+                                       contact_str, reg_desc, rpid, (long) reg_time + (long) exptime + profile->sip_expires_late_margin,
                                        agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm, 
                                                                 mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname, sub_host);
                } else {
@@ -1789,7 +1789,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                                                 call_id, sub_host, network_ip, network_port_c,
                                                                 profile->presence_hosts ? profile->presence_hosts : "", guess_ip4, guess_ip4,
                                                                  mod_sofia_globals.hostname, mod_sofia_globals.hostname,
-                                                                (long) reg_time + (long) exptime + 60, 
+                                                                (long) reg_time + (long) exptime + profile->sip_expires_late_margin,
                                                                 to_user, username, reg_host, contact_str);
                }                                
 
@@ -1808,9 +1808,9 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
 
                if (multi_reg) {
                        if (multi_reg_contact) {
-                               sql = switch_mprintf("delete from sip_registrations where contact='%q' and expires!=%ld", contact_str, (long) reg_time + (long) exptime + 60);
+                               sql = switch_mprintf("delete from sip_registrations where contact='%q' and expires!=%ld", contact_str, (long) reg_time + (long) exptime + profile->sip_expires_late_margin);
                        } else {
-                               sql = switch_mprintf("delete from sip_registrations where call_id='%q' and expires!=%ld", call_id, (long) reg_time + (long) exptime + 60);
+                               sql = switch_mprintf("delete from sip_registrations where call_id='%q' and expires!=%ld", call_id, (long) reg_time + (long) exptime + profile->sip_expires_late_margin);
                        }
                        
                        sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);