]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3771 --resolve
authorBrian West <brian@freeswitch.org>
Thu, 22 Dec 2011 20:03:32 +0000 (14:03 -0600)
committerBrian West <brian@freeswitch.org>
Thu, 22 Dec 2011 20:03:32 +0000 (14:03 -0600)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index acc640ba8fe0e6b60b54f3b1e69c24dd186b4379..984c80f39f3c5242a108ca1ab400fda1c04dee74 100644 (file)
@@ -645,6 +645,8 @@ struct sofia_profile {
        char *tls_passphrase;
        char *tls_verify_in_subjects_str;
        su_strlst_t *tls_verify_in_subjects;
+       uint32_t sip_force_expires;
+       uint32_t sip_expires_max_deviation;
 };
 
 struct private_object {
index 22a2428ccc0380b3b35673f01e585a88911b84c9..07ea5d2bbe691845ee569b601aca21248e81d3c8 100644 (file)
@@ -3439,6 +3439,20 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile)
                                                 } else {
                                                         sofia_clear_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY);
                                                 }
+                                       } else if (!strcasecmp(var, "sip-force-expires")) {
+                                               uint32_t sip_force_expires = atoi(val);
+                                               if (sip_force_expires >= 0) {
+                                                       profile->sip_force_expires = sip_force_expires;
+                                               } else {
+                                                       profile->sip_force_expires = 0;
+                                               }
+                                       } else if (!strcasecmp(var, "sip-expires-max-deviation")) {
+                                               uint32_t sip_expires_max_deviation = atoi(val);
+                                               if (sip_expires_max_deviation >= 0) {
+                                                       profile->sip_expires_max_deviation = sip_expires_max_deviation;
+                                               } else {
+                                                       profile->sip_expires_max_deviation = 0;
+                                               }
                                        }
                                }
                        }
@@ -3662,6 +3676,8 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                switch_thread_rwlock_create(&profile->rwlock, profile->pool);
                                switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
                                profile->dtmf_duration = 100;
+                               profile->sip_force_expires = 0;
+                               profile->sip_expires_max_deviation = 0;
                                profile->tls_version = 0;
                                profile->mflags = MFLAG_REFER | MFLAG_REGISTER;
                                profile->server_rport_level = 1;
@@ -4483,6 +4499,20 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                                 } else {
                                                         sofia_clear_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY);
                                                 }
+                                       } else if (!strcasecmp(var, "sip-force-expires")) {
+                                               uint32_t sip_force_expires = atoi(val);
+                                               if (sip_force_expires >= 0) {
+                                                       profile->sip_force_expires = sip_force_expires;
+                                               } else {
+                                                       profile->sip_force_expires = 0;
+                                               }
+                                       } else if (!strcasecmp(var, "sip-expires-max-deviation")) {
+                                               uint32_t sip_expires_max_deviation = atoi(val);
+                                               if (sip_expires_max_deviation >= 0) {
+                                                       profile->sip_expires_max_deviation = sip_expires_max_deviation;
+                                               } else {
+                                                       profile->sip_expires_max_deviation = 0;
+                                               }
                                        } else if (!strcasecmp(var, "reuse-connections")) {
                                                switch_bool_t value = switch_true(val);
                                                if (!value) {
index ea7ca0a6cfc20af258979a64049a8b7e12b973d2..57807950e69b0cb139bd79da2d891f537f547a96 100644 (file)
@@ -1270,7 +1270,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                }
 
                if (contact && exptime && v_event && *v_event) {
-                       char *exp_var;
+                       uint32_t exp_var;
+                       uint32_t exp_max_deviation_var;
                        char *allow_multireg = NULL;
                        int auto_connectile = 0;
 
@@ -1363,12 +1364,24 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                }
                        }
 
-                       if ((exp_var = switch_event_get_header(*v_event, "sip-force-expires"))) {
-                               int tmp = atoi(exp_var);
-                               if (tmp > 0) {
-                                       exptime = tmp;
+                       if ( (( exp_var = atoi(switch_event_get_header_nil(*v_event, "sip-force-expires")) )) ||
+                            (( exp_var = profile->sip_force_expires )) ) {
+                               if (exp_var > 0) {
+                                       exptime = exp_var;
                                }
                        }
+
+                       if ( (( exp_max_deviation_var = atoi(switch_event_get_header_nil(*v_event, "sip-expires-max-deviation")) )) ||
+                            (( exp_max_deviation_var = profile->sip_expires_max_deviation )) ) {
+                               if (exp_max_deviation_var > 0) {
+                                       int exp_deviation;
+                                       srand( (unsigned) ( (unsigned)(intptr_t)switch_thread_self() + switch_micro_time_now() ) );
+                                       /* random number between negative exp_max_deviation_var and positive exp_max_deviation_var: */
+                                       exp_deviation = ( rand() % ( exp_max_deviation_var * 2 ) ) - exp_max_deviation_var;
+                                       exptime += exp_deviation;
+                               }
+                       }
+
                }
 
                if (auth_res != AUTH_OK && auth_res != AUTH_RENEWED && !stale) {