FS-6806 #resolve

Conflicts:
	src/mod/endpoints/mod_sofia/mod_sofia.c
	src/mod/endpoints/mod_sofia/sofia_presence.c
This commit is contained in:
Anthony Minessale 2014-09-09 00:09:31 +05:00
parent 51f4742087
commit 1c697be17c
3 changed files with 32 additions and 11 deletions

View 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));

View 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;

View 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;