Skip to content

Commit

Permalink
dialog: Fix incorrect replicated dialog ids
Browse files Browse the repository at this point in the history
Also improve code readability with regards to dialog id handling

Issue reported by Dawid Mielnik

(cherry picked from commit 00be97f)
  • Loading branch information
liviuchircu committed Nov 3, 2016
1 parent 9eb177d commit a13bfe3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
15 changes: 7 additions & 8 deletions modules/dialog/dlg_db_handler.c
Expand Up @@ -496,7 +496,6 @@ static int load_dialog_info_from_db(int dlg_hash_size)
struct dlg_cell *dlg;
str callid, from_uri, to_uri, from_tag, to_tag;
str cseq1,cseq2,contact1,contact2,rroute1,rroute2,mangled_fu,mangled_tu;
unsigned int next_id;
int no_rows = 10;
struct socket_info *caller_sock,*callee_sock;
int found_ended_dlgs=0;
Expand Down Expand Up @@ -573,10 +572,10 @@ static int load_dialog_info_from_db(int dlg_hash_size)
link_dlg(dlg, 0);

dlg->h_id = hash_id;
next_id = d_table->entries[dlg->h_entry].next_id;

d_table->entries[dlg->h_entry].next_id =
(next_id <= dlg->h_id) ? (dlg->h_id+1) : next_id;
/* next_id follows the max value of all loaded ids */
if (d_table->entries[dlg->h_entry].next_id <= dlg->h_id)
d_table->entries[dlg->h_entry].next_id = dlg->h_id + 1;

GET_STR_VALUE(to_tag, values, 5, 1, 1);

Expand Down Expand Up @@ -1484,7 +1483,7 @@ static int sync_dlg_db_mem(void)
db_row_t * rows;
struct dlg_entry *d_entry;
struct dlg_cell *it,*known_dlg,*dlg=NULL;
int i, nr_rows,callee_leg_idx,next_id,db_timeout;
int i, nr_rows,callee_leg_idx,db_timeout;
int no_rows = 10;
unsigned int db_caller_cseq = 0, db_callee_cseq = 0;
unsigned int dlg_caller_cseq = 0, dlg_callee_cseq = 0;
Expand Down Expand Up @@ -1590,10 +1589,10 @@ static int sync_dlg_db_mem(void)
link_dlg(dlg, 0);

dlg->h_id = hash_id;
next_id = d_table->entries[dlg->h_entry].next_id;

d_table->entries[dlg->h_entry].next_id =
(next_id <= dlg->h_id) ? (dlg->h_id+1) : next_id;
/* next_id follows the max value of all loaded ids */
if (d_table->entries[dlg->h_entry].next_id <= dlg->h_id)
d_table->entries[dlg->h_entry].next_id = dlg->h_id + 1;

dlg->start_ts = VAL_INT(values+6);

Expand Down
10 changes: 4 additions & 6 deletions modules/dialog/dlg_replication.c
Expand Up @@ -84,7 +84,7 @@ static struct socket_info * fetch_socket_info(str *addr)
*/
int dlg_replicated_create(struct dlg_cell *cell, str *ftag, str *ttag, int safe)
{
int next_id, h_entry;
int h_entry;
unsigned int dir, dst_leg;
str callid, from_uri, to_uri, from_tag, to_tag;
str cseq1, cseq2, contact1, contact2, rroute1, rroute2, mangled_fu, mangled_tu;
Expand Down Expand Up @@ -140,10 +140,9 @@ int dlg_replicated_create(struct dlg_cell *cell, str *ftag, str *ttag, int safe)
bin_pop_int(&dlg->start_ts);
bin_pop_int(&dlg->state);

next_id = d_table->entries[dlg->h_entry].next_id;

d_table->entries[dlg->h_entry].next_id =
(next_id <= dlg->h_id) ? (dlg->h_id + 1) : next_id;
/* next_id follows the max value of all replicated ids */
if (d_table->entries[dlg->h_entry].next_id <= dlg->h_id)
d_table->entries[dlg->h_entry].next_id = dlg->h_id + 1;

if (bin_pop_str(&sock))
goto pre_linking_error;
Expand Down Expand Up @@ -182,7 +181,6 @@ int dlg_replicated_create(struct dlg_cell *cell, str *ftag, str *ttag, int safe)
dlg->legs_no[DLG_LEG_200OK] = DLG_FIRST_CALLEE_LEG;

/* link the dialog into the hash */
dlg->h_id = d_entry->next_id++;
if (!d_entry->first)
d_entry->first = d_entry->last = dlg;
else {
Expand Down

0 comments on commit a13bfe3

Please sign in to comment.