Browse code

pv: handle missing fields (otcid, instance) for $banch() and $sbranch()

(cherry picked from commit 0c4becd70428ef15be76fb0aa53932e5803c6bd0)
(cherry picked from commit 50e9db0cd53381cec5e522777556adbb6bf1a039)

Daniel-Constantin Mierla authored on 09/03/2021 10:38:26 • Henning Westerholt committed on 22/10/2021 11:22:49
Showing 1 changed files
... ...
@@ -93,6 +93,12 @@ int pv_get_branchx_helper(sip_msg_t *msg, pv_param_t *param,
93 93
 			if(br->location_ua_len==0)
94 94
 				return pv_get_null(msg, param, res);
95 95
 			return pv_get_strlval(msg, param, res, br->location_ua, br->location_ua_len);
96
+		case 9: /* otcpid */
97
+			return pv_get_uintval(msg, param, res, br->otcpid);
98
+		case 10: /* instance */
99
+			if(br->instance_len==0)
100
+				return pv_get_null(msg, param, res);
101
+			return pv_get_strlval(msg, param, res, br->instance, br->instance_len);
96 102
 		default:
97 103
 			/* 0 - uri */
98 104
 			return pv_get_strlval(msg, param, res, br->uri, br->len);
... ...
@@ -284,6 +290,22 @@ int pv_set_branchx_helper(sip_msg_t *msg, pv_param_t *param,
284 290
 		case 8: /* location_ua */
285 291
 			/* do nothing - cannot set the location_ua */
286 292
 		break;
293
+		case 9: /* otcpid */
294
+			if(val==NULL || (val->flags&PV_VAL_NULL))
295
+			{
296
+				br->otcpid = 0;
297
+				break;
298
+			}
299
+			if(!(val->flags&PV_VAL_INT))
300
+			{
301
+				LM_ERR("int value required to set branch flags\n");
302
+				return -1;
303
+			}
304
+			br->otcpid = val->ri;
305
+		break;
306
+		case 10: /* instance */
307
+			/* do nothing - cannot set the instance */
308
+		break;
287 309
 		default:
288 310
 			/* 0 - uri */
289 311
 			if(val==NULL || (val->flags&PV_VAL_NULL))
... ...
@@ -336,42 +358,53 @@ int pv_parse_branchx_name(pv_spec_p sp, str *in)
336 358
 
337 359
 	switch(in->len)
338 360
 	{
339
-		case 3: 
340
-			if(strncmp(in->s, "uri", 3)==0)
341
-				sp->pvp.pvn.u.isname.name.n = 0;
361
+		case 1:
362
+			if(*in->s=='q' || *in->s=='Q')
363
+				sp->pvp.pvn.u.isname.name.n = 3;
342 364
 			else goto error;
343 365
 		break;
344
-		case 7: 
345
-			if(strncmp(in->s, "dst_uri", 7)==0)
346
-				sp->pvp.pvn.u.isname.name.n = 1;
366
+		case 3:
367
+			if(strncmp(in->s, "uri", 3)==0)
368
+				sp->pvp.pvn.u.isname.name.n = 0;
347 369
 			else goto error;
348 370
 		break;
349
-		case 4: 
371
+		case 4:
350 372
 			if(strncmp(in->s, "path", 4)==0)
351 373
 				sp->pvp.pvn.u.isname.name.n = 2;
352 374
 			else if (strncmp(in->s, "ruid", 4)==0)
353 375
 				sp->pvp.pvn.u.isname.name.n = 7;
354 376
 			else goto error;
355 377
 		break;
356
-		case 1: 
357
-			if(*in->s=='q' || *in->s=='Q')
358
-				sp->pvp.pvn.u.isname.name.n = 3;
378
+		case 5:
379
+			if(strncmp(in->s, "count", 5)==0)
380
+				sp->pvp.pvn.u.isname.name.n = 5;
381
+			else if(strncmp(in->s, "flags", 5)==0)
382
+				sp->pvp.pvn.u.isname.name.n = 6;
383
+			else goto error;
384
+		break;
385
+		case 6:
386
+			if(strncmp(in->s, "otcpid", 6)==0)
387
+				sp->pvp.pvn.u.isname.name.n = 9;
388
+			else goto error;
389
+		break;
390
+		case 7:
391
+			if(strncmp(in->s, "dst_uri", 7)==0)
392
+				sp->pvp.pvn.u.isname.name.n = 1;
393
+			else goto error;
394
+		break;
395
+		case 8:
396
+			if(strncmp(in->s, "instance", 8)==0)
397
+				sp->pvp.pvn.u.isname.name.n = 10;
359 398
 			else goto error;
360 399
 		break;
361
-		case 11: 
400
+		case 11:
362 401
 			if(strncmp(in->s, "send_socket", 11)==0)
363 402
 				sp->pvp.pvn.u.isname.name.n = 4;
364 403
 			else if(strncmp(in->s, "location_ua", 11)==0)
365 404
 				sp->pvp.pvn.u.isname.name.n = 8;
366 405
 			else goto error;
367 406
 		break;
368
-		case 5: 
369
-			if(strncmp(in->s, "count", 5)==0)
370
-				sp->pvp.pvn.u.isname.name.n = 5;
371
-			else if(strncmp(in->s, "flags", 5)==0)
372
-				sp->pvp.pvn.u.isname.name.n = 6;
373
-			else goto error;
374
-		break;
407
+
375 408
 		default:
376 409
 			goto error;
377 410
 	}
... ...
@@ -805,6 +838,7 @@ int sbranch_set_ruri(sip_msg_t *msg)
805 838
 		set_force_socket(msg, br->force_send_socket);
806 839
 
807 840
 	msg->reg_id = br->reg_id;
841
+	msg->otcpid = br->otcpid;
808 842
 	set_ruri_q(br->q);
809 843
 	old_bflags = 0;
810 844
 	getbflagsval(0, &old_bflags);
... ...
@@ -825,7 +859,9 @@ int sbranch_append(sip_msg_t *msg)
825 859
 	str path = {0};
826 860
 	str ruid = {0};
827 861
 	str location_ua = {0};
862
+	str instance = {0};
828 863
 	branch_t *br;
864
+	branch_t *newbr;
829 865
 
830 866
 	br = &_pv_sbranch;
831 867
 	if(br->len==0)
... ...
@@ -850,14 +886,19 @@ int sbranch_append(sip_msg_t *msg)
850 886
 		location_ua.s = br->location_ua;
851 887
 		location_ua.len = br->location_ua_len;
852 888
 	}
889
+	if(br->instance_len) {
890
+		instance.s = br->instance;
891
+		instance.len = br->instance_len;
892
+	}
853 893
 
854
-	if (append_branch(msg, &uri, &duri, &path, br->q, br->flags,
855
-					  br->force_send_socket, 0 /*instance*/, br->reg_id,
856
-					  &ruid, &location_ua)
857
-			    == -1) {
894
+	newbr = ksr_push_branch(msg, &uri, &duri, &path, br->q, br->flags,
895
+					  br->force_send_socket, &instance, br->reg_id,
896
+					  &ruid, &location_ua);
897
+	if(newbr==NULL) {
858 898
 		LM_ERR("failed to append static branch\n");
859 899
 		return -1;
860 900
 	}
901
+	newbr->otcpid = br->otcpid;
861 902
 	return 0;
862 903
 }
863 904