Browse code

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

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