]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-6806 #resolve
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 8 Sep 2014 19:09:31 +0000 (00:09 +0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 8 Sep 2014 19:25:30 +0000 (00:25 +0500)
Conflicts:
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c

src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_presence.c

index 8f6b5fafc398b1271b7427b8cf7a1a837f6d9deb..8b3f07561240f59ca91c96e12af45e9da876b521 100644 (file)
@@ -5963,8 +5963,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
        switch_management_interface_t *management_interface;
        switch_application_interface_t *app_interface;
        struct in_addr in;
-       struct tm tm = {0};
-       time_t now;
 
        memset(&mod_sofia_globals, 0, sizeof(mod_sofia_globals));
        mod_sofia_globals.destroy_private.destroy_nh = 1;
@@ -5973,11 +5971,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
        mod_sofia_globals.pool = pool;
        switch_mutex_init(&mod_sofia_globals.mutex, SWITCH_MUTEX_NESTED, mod_sofia_globals.pool);
 
-       now = switch_epoch_time_now(NULL);
-       tm = *(localtime(&now));
-
-       mod_sofia_globals.presence_epoch = now - (tm.tm_yday * 86400);
-
        switch_find_local_ip(mod_sofia_globals.guess_ip, sizeof(mod_sofia_globals.guess_ip), &mod_sofia_globals.guess_mask, AF_INET);
        in.s_addr = mod_sofia_globals.guess_mask;
        switch_set_string(mod_sofia_globals.guess_mask_str, inet_ntoa(in));
index 04397a63dff5484d53a9fc80a2cfc99322f44291..b66008695e7997b698cbd7f20c05000c36c97676 100644 (file)
@@ -403,6 +403,7 @@ struct mod_sofia_globals {
        switch_thread_t *presence_thread;
        uint32_t max_reg_threads;
        time_t presence_epoch;
+       int presence_year;
 };
 extern struct mod_sofia_globals mod_sofia_globals;
 
index 39d86ca83ef0683efa65f0e4e654e4bc9afcc930..f866985a66165b2cfe900b530902817f97077360 100644 (file)
@@ -2097,17 +2097,44 @@ static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char *
        return 0;
 }
 
+#define SOFIA_PRESENCE_COLLISION_DELTA 50
+#define SOFIA_PRESENCE_ROLLOVER_YEAR (86400 * 365 * SOFIA_PRESENCE_COLLISION_DELTA)
+static uint32_t check_presence_epoch(void)
+{
+       struct tm tm = {0};
+       time_t now = switch_epoch_time_now(NULL);
+       uint32_t callsequence = (now - mod_sofia_globals.presence_epoch) * SOFIA_PRESENCE_COLLISION_DELTA;
+
+       if (!mod_sofia_globals.presence_year || callsequence >= SOFIA_PRESENCE_ROLLOVER_YEAR) {
+               switch_mutex_lock(mod_sofia_globals.mutex);
+               tm = *(localtime(&now));
+
+               if (tm.tm_year != mod_sofia_globals.presence_year) {
+                       mod_sofia_globals.presence_epoch = (uint32_t)now - (tm.tm_yday * 86400) - (tm.tm_hour * 60 * 60) - (tm.tm_min * 60) - tm.tm_sec;
+                       mod_sofia_globals.presence_year = tm.tm_year;
+                       callsequence = ((uint32_t)now - mod_sofia_globals.presence_epoch) * SOFIA_PRESENCE_COLLISION_DELTA;
+               }
+
+               switch_mutex_unlock(mod_sofia_globals.mutex);
+       }
+
+       return callsequence;
+}
+
 static uint32_t sofia_presence_get_cseq(sofia_profile_t *profile)
 {
        uint32_t callsequence;
-       uint32_t now = (uint32_t) switch_epoch_time_now(NULL);
+       int diff = 0;
 
        switch_mutex_lock(profile->ireg_mutex);
 
-       callsequence = (now - mod_sofia_globals.presence_epoch) * 100;
+       callsequence = check_presence_epoch();
 
-       if (profile->last_cseq && callsequence <= profile->last_cseq) {
-               callsequence = ++profile->last_cseq;
+       if (profile->last_cseq) {
+               diff = callsequence - profile->last_cseq;
+               if (diff < 0 && diff > -100000) {
+                       callsequence = ++profile->last_cseq;
+               }
        }
 
        profile->last_cseq = callsequence;