Browse code

topos_redis: use also stored record to get uuid for branch replies

Daniel-Constantin Mierla authored on 01/05/2021 11:25:59
Showing 1 changed files
... ...
@@ -302,7 +302,7 @@ int tps_redis_clean_dialogs(void)
302 302
 /**
303 303
  *
304 304
  */
305
-int tps_redis_insert_initial_method_branch(tps_data_t *td)
305
+int tps_redis_insert_initial_method_branch(tps_data_t *md, tps_data_t *sd)
306 306
 {
307 307
 	char* argv[TPS_REDIS_NR_KEYS];
308 308
 	size_t argvlen[TPS_REDIS_NR_KEYS];
... ...
@@ -316,7 +316,7 @@ int tps_redis_insert_initial_method_branch(tps_data_t *td)
316 316
 	unsigned long lval = 0;
317 317
 	str xuuid = str_init("");
318 318
 
319
-	if(td->x_vbranch1.len<=0) {
319
+	if(md->x_vbranch1.len<=0) {
320 320
 		LM_INFO("no via branch for this message\n");
321 321
 		return -1;
322 322
 	}
... ...
@@ -332,21 +332,27 @@ int tps_redis_insert_initial_method_branch(tps_data_t *td)
332 332
 	memset(argvlen, 0, TPS_REDIS_NR_KEYS * sizeof(size_t));
333 333
 	argc = 0;
334 334
 
335
-	if(td->a_uuid.len>1) {
336
-		xuuid.s = td->a_uuid.s + 1;
337
-		xuuid.len = td->a_uuid.len - 1;
338
-	} else if(td->b_uuid.len>1) {
339
-		xuuid.s = td->b_uuid.s + 1;
340
-		xuuid.len = td->b_uuid.len - 1;
335
+	if(md->a_uuid.len>1) {
336
+		xuuid.s = md->a_uuid.s + 1;
337
+		xuuid.len = md->a_uuid.len - 1;
338
+	} else if(md->b_uuid.len>1) {
339
+		xuuid.s = md->b_uuid.s + 1;
340
+		xuuid.len = md->b_uuid.len - 1;
341
+	} else if(sd->a_uuid.len>1) {
342
+		xuuid.s = sd->a_uuid.s + 1;
343
+		xuuid.len = sd->a_uuid.len - 1;
344
+	} else if(sd->b_uuid.len>1) {
345
+		xuuid.s = sd->b_uuid.s + 1;
346
+		xuuid.len = sd->b_uuid.len - 1;
341 347
 	}
342 348
 
343 349
 	rp = _tps_redis_cbuf;
344 350
 	rkey.len = snprintf(rp, TPS_REDIS_DATA_SIZE-128,
345 351
 					"%.*s%.*s:%.*s:%.*s:x%.*s",
346 352
 					_tps_redis_bprefix.len, _tps_redis_bprefix.s,
347
-					td->s_method.len, td->s_method.s,
348
-					td->a_callid.len, td->a_callid.s,
349
-					td->b_tag.len, td->b_tag.s,
353
+					md->s_method.len, md->s_method.s,
354
+					md->a_callid.len, md->a_callid.s,
355
+					md->b_tag.len, md->b_tag.s,
350 356
 					xuuid.len, xuuid.s);
351 357
 	if(rkey.len<0 || rkey.len>=TPS_REDIS_DATA_SIZE-128) {
352 358
 		LM_ERR("error or insufficient buffer size: %d\n", rkey.len);
... ...
@@ -366,7 +372,7 @@ int tps_redis_insert_initial_method_branch(tps_data_t *td)
366 372
 	lval = (unsigned long)time(NULL);
367 373
 	TPS_REDIS_SET_ARGN(lval, rp, &rval, argc, &tt_key_rectime,
368 374
 			argv, argvlen);
369
-	TPS_REDIS_SET_ARGS(&td->x_vbranch1, argc, &tt_key_x_vbranch, argv, argvlen);
375
+	TPS_REDIS_SET_ARGS(&md->x_vbranch1, argc, &tt_key_x_vbranch, argv, argvlen);
370 376
 
371 377
 	rrpl = _tps_redis_api.exec_argv(rsrv, argc, (const char **)argv, argvlen);
372 378
 	if(rrpl==NULL) {
... ...
@@ -376,8 +382,8 @@ int tps_redis_insert_initial_method_branch(tps_data_t *td)
376 382
 		}
377 383
 		return -1;
378 384
 	}
379
-	LM_DBG("inserting %.*s branch record for [%.*s] with argc %d\n",
380
-			td->s_method.len, td->s_method.s,rkey.len, rkey.s, argc);
385
+	LM_DBG("inserting initial %.*s branch record for [%.*s] with argc %d\n",
386
+			md->s_method.len, md->s_method.s,rkey.len, rkey.s, argc);
381 387
 
382 388
 	freeReplyObject(rrpl);
383 389
 
... ...
@@ -608,6 +614,12 @@ int tps_redis_load_initial_method_branch(sip_msg_t *msg, tps_data_t *md, tps_dat
608 614
 	} else if(md->b_uuid.len>1) {
609 615
 		xuuid.s = md->b_uuid.s + 1;
610 616
 		xuuid.len = md->b_uuid.len - 1;
617
+	} else if(sd->a_uuid.len>1) {
618
+		xuuid.s = sd->a_uuid.s + 1;
619
+		xuuid.len = sd->a_uuid.len - 1;
620
+	} else if(sd->b_uuid.len>1) {
621
+		xuuid.s = sd->b_uuid.s + 1;
622
+		xuuid.len = sd->b_uuid.len - 1;
611 623
 	}
612 624
 
613 625
 	rp = _tps_redis_cbuf;
... ...
@@ -634,7 +646,8 @@ int tps_redis_load_initial_method_branch(sip_msg_t *msg, tps_data_t *md, tps_dat
634 646
 	argvlen[argc] = rkey.len;
635 647
 	argc++;
636 648
 
637
-	LM_DBG("loading invite branch record for [%.*s]\n", rkey.len, rkey.s);
649
+	LM_DBG("loading initial %.*s branch record for [%.*s]\n",
650
+			md->s_method.len, md->s_method.s, rkey.len, rkey.s);
638 651
 
639 652
 	rrpl = _tps_redis_api.exec_argv(rsrv, argc, (const char **)argv, argvlen);
640 653
 	if(rrpl==NULL) {
... ...
@@ -1149,13 +1162,13 @@ int tps_redis_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
1149 1162
 	}
1150 1163
 
1151 1164
 	if(md->s_method.len==6 && strncmp(md->s_method.s, "INVITE", 6)==0) {
1152
-		if(tps_redis_insert_initial_method_branch(md)<0) {
1165
+		if(tps_redis_insert_initial_method_branch(md, sd)<0) {
1153 1166
 			LM_ERR("failed to insert INVITE extra branch data\n");
1154 1167
 			return -1;
1155 1168
 		}
1156 1169
 	}
1157 1170
 	if(md->s_method.len==9 && strncmp(md->s_method.s, "SUBSCRIBE", 9)==0) {
1158
-		if(tps_redis_insert_initial_method_branch(md)<0) {
1171
+		if(tps_redis_insert_initial_method_branch(md, sd)<0) {
1159 1172
 			LM_ERR("failed to insert SUBSCRIBE extra branch data\n");
1160 1173
 			return -1;
1161 1174
 		}