@@ -218,7 +218,7 @@ b2b_dlg_t* b2b_search_htable(b2b_table table, unsigned int hash_index,
218
218
219
219
/* this is only called by server new */
220
220
str * b2b_htable_insert (b2b_table table , b2b_dlg_t * dlg , int hash_index ,
221
- time_t timestamp , int src , int safe , int db_insert , unsigned int ua_timeout )
221
+ str * init_b2b_key , int src , int safe , int db_insert , unsigned int ua_timeout )
222
222
{
223
223
b2b_dlg_t * it , * prev_it = NULL ;
224
224
str * b2b_key ;
@@ -243,14 +243,18 @@ str* b2b_htable_insert(b2b_table table, b2b_dlg_t* dlg, int hash_index,
243
243
prev_it -> next = dlg ;
244
244
dlg -> prev = prev_it ;
245
245
}
246
- /* if an insert in server_htable -> copy the b2b_key in the to_tag */
247
- b2b_key = b2b_generate_key (hash_index , dlg -> id , timestamp );
248
- if (b2b_key == NULL )
249
- {
250
- if (!safe )
251
- B2BE_LOCK_RELEASE (table , hash_index );
252
- LM_ERR ("Failed to generate b2b key\n" );
253
- return NULL ;
246
+ if (!init_b2b_key ) {
247
+ /* if an insert in server_htable -> copy the b2b_key in the to_tag */
248
+ b2b_key = b2b_generate_key (hash_index , dlg -> id );
249
+ if (b2b_key == NULL )
250
+ {
251
+ if (!safe )
252
+ B2BE_LOCK_RELEASE (table , hash_index );
253
+ LM_ERR ("Failed to generate b2b key\n" );
254
+ return NULL ;
255
+ }
256
+ } else {
257
+ b2b_key = init_b2b_key ;
254
258
}
255
259
256
260
if (src == B2B_SERVER )
@@ -261,8 +265,7 @@ str* b2b_htable_insert(b2b_table table, b2b_dlg_t* dlg, int hash_index,
261
265
LM_ERR ("No more shared memory\n" );
262
266
if (!safe )
263
267
B2BE_LOCK_RELEASE (table , hash_index );
264
- pkg_free (b2b_key );
265
- return 0 ;
268
+ goto err_free ;
266
269
}
267
270
memcpy (dlg -> tag [CALLEE_LEG ].s , b2b_key -> s , b2b_key -> len );
268
271
dlg -> tag [CALLEE_LEG ].len = b2b_key -> len ;
@@ -276,8 +279,7 @@ str* b2b_htable_insert(b2b_table table, b2b_dlg_t* dlg, int hash_index,
276
279
LM_ERR ("Failed to insert into timer list\n" );
277
280
if (!safe )
278
281
B2BE_LOCK_RELEASE (table , hash_index );
279
- pkg_free (b2b_key );
280
- return 0 ;
282
+ goto err_free ;
281
283
}
282
284
}
283
285
@@ -288,13 +290,16 @@ str* b2b_htable_insert(b2b_table table, b2b_dlg_t* dlg, int hash_index,
288
290
B2BE_LOCK_RELEASE (table , hash_index );
289
291
290
292
return b2b_key ;
293
+ err_free :
294
+ if (!init_b2b_key )
295
+ pkg_free (b2b_key );
296
+ return NULL ;
291
297
}
292
298
293
299
/* key format : B2B.hash_index.local_index.timestamp.random *
294
300
*/
295
301
296
- int b2b_parse_key (str * key , unsigned int * hash_index , unsigned int * local_index ,
297
- uint64_t * timestamp )
302
+ int b2b_parse_key (str * key , unsigned int * hash_index , unsigned int * local_index )
298
303
{
299
304
char * p ;
300
305
str s ;
@@ -340,40 +345,20 @@ int b2b_parse_key(str* key, unsigned int* hash_index, unsigned int* local_index,
340
345
return -1 ;
341
346
}
342
347
343
- if (timestamp ) {
344
- s .s = p + 1 ;
345
- // There might be a random number after timestamp, we want to ignore it.
346
- p = strchr (s .s , '.' );
347
- if (p != NULL ) {
348
- s .len = p - s .s ;
349
- } else {
350
- s .len = key -> len - (s .s - key -> s );
351
- }
352
- if (str2int64 (& s , timestamp ) < 0 )
353
- {
354
- LM_DBG ("Could not extract timestamp [%.*s] from key [%.*s]\n" , s .len , s .s , key -> len , key -> s );
355
- return -1 ;
356
- }
357
-
358
- LM_DBG ("hash_index = [%d] - local_index = [%d] - timestamp = %ld\n" ,
359
- * hash_index , * local_index , (time_t )* timestamp );
360
- } else {
361
- /* we do not really care about the third part of the key */
362
- LM_DBG ("hash_index = [%d] - local_index= [%d]\n" , * hash_index , * local_index );
363
- }
348
+ /* we do not really care about the last parts of the key */
349
+ LM_DBG ("hash_index = [%d] - local_index= [%d]\n" , * hash_index , * local_index );
364
350
365
351
return 0 ;
366
352
}
367
353
368
- str * b2b_generate_key (unsigned int hash_index , unsigned int local_index ,
369
- time_t timestamp )
354
+ str * b2b_generate_key (unsigned int hash_index , unsigned int local_index )
370
355
{
371
356
char buf [B2B_MAX_KEY_SIZE ];
372
357
str * b2b_key ;
373
358
int len ;
374
359
375
360
len = sprintf (buf , "%s.%d.%d.%ld.%d" , b2b_key_prefix .s , hash_index , local_index ,
376
- timestamp ? timestamp : startup_time + get_ticks (), rand ());
361
+ startup_time + get_ticks (), rand ());
377
362
378
363
b2b_key = (str * )pkg_malloc (sizeof (str )+ len );
379
364
if (b2b_key == NULL )
@@ -959,7 +944,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam)
959
944
b2b_key = to_tag ;
960
945
/* check if the to tag has the b2b key format -> meaning
961
946
* that it is a server request */
962
- if (b2b_key .s && b2b_parse_key (& b2b_key , & hash_index , & local_index , NULL )>=0 )
947
+ if (b2b_key .s && b2b_parse_key (& b2b_key , & hash_index , & local_index )>=0 )
963
948
{
964
949
LM_DBG ("Received a b2b server request [%.*s]\n" ,
965
950
msg -> first_line .u .request .method .len ,
@@ -971,7 +956,7 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam)
971
956
/* check if the callid is in b2b format -> meaning
972
957
* that this is a client request */
973
958
b2b_key = msg -> callid -> body ;
974
- if (b2b_parse_key (& b2b_key , & hash_index , & local_index , NULL ) >= 0 )
959
+ if (b2b_parse_key (& b2b_key , & hash_index , & local_index ) >= 0 )
975
960
{
976
961
LM_DBG ("received a b2b client request [%.*s]\n" ,
977
962
msg -> first_line .u .request .method .len ,
@@ -1670,7 +1655,7 @@ int _b2b_send_reply(b2b_dlg_t* dlg, b2b_rpl_data_t* rpl_data)
1670
1655
}
1671
1656
1672
1657
/* parse the key and find the position in hash table */
1673
- if (b2b_parse_key (b2b_key , & hash_index , & local_index , NULL ) < 0 )
1658
+ if (b2b_parse_key (b2b_key , & hash_index , & local_index ) < 0 )
1674
1659
{
1675
1660
LM_ERR ("Wrong format for b2b key\n" );
1676
1661
return -1 ;
@@ -1999,7 +1984,7 @@ void b2b_entity_delete(enum b2b_entity_type et, str* b2b_key,
1999
1984
table = client_htable ;
2000
1985
2001
1986
/* parse the key and find the position in hash table */
2002
- if (b2b_parse_key (b2b_key , & hash_index , & local_index , NULL ) < 0 )
1987
+ if (b2b_parse_key (b2b_key , & hash_index , & local_index ) < 0 )
2003
1988
{
2004
1989
LM_ERR ("Wrong format for b2b key\n" );
2005
1990
return ;
@@ -2079,7 +2064,7 @@ int b2b_entity_exists(enum b2b_entity_type et, str* b2b_key)
2079
2064
table = client_htable ;
2080
2065
2081
2066
/* parse the key and find the position in hash table */
2082
- if (b2b_parse_key (b2b_key , & hash_index , & local_index , NULL ) < 0 )
2067
+ if (b2b_parse_key (b2b_key , & hash_index , & local_index ) < 0 )
2083
2068
{
2084
2069
LM_ERR ("Wrong format for b2b key\n" );
2085
2070
return 0 ;
@@ -2266,7 +2251,7 @@ int _b2b_send_request(b2b_dlg_t* dlg, b2b_req_data_t* req_data)
2266
2251
}
2267
2252
2268
2253
/* parse the key and find the position in hash table */
2269
- if (b2b_parse_key (b2b_key , & hash_index , & local_index , NULL ) < 0 )
2254
+ if (b2b_parse_key (b2b_key , & hash_index , & local_index ) < 0 )
2270
2255
{
2271
2256
LM_ERR ("Wrong format for b2b key [%.*s]\n" , b2b_key -> len , b2b_key -> s );
2272
2257
return -1 ;
@@ -2834,7 +2819,7 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
2834
2819
msg = ps -> rpl ;
2835
2820
b2b_key = (str * )* ps -> param ;
2836
2821
2837
- if (b2b_parse_key (b2b_key , & hash_index , & local_index , NULL )< 0 )
2822
+ if (b2b_parse_key (b2b_key , & hash_index , & local_index )< 0 )
2838
2823
{
2839
2824
LM_ERR ("Failed to parse b2b logic key [%.*s]\n" ,b2b_key -> len ,b2b_key -> s );
2840
2825
return ;
0 commit comments