Browse code

pv: new transformation {uri.suri}

- get the simple routing uri - keep only transport parameter, if exists

Daniel-Constantin Mierla authored on 28/08/2020 18:42:15
Showing 2 changed files
... ...
@@ -1408,6 +1408,62 @@ int tr_eval_uri(struct sip_msg *msg, tr_param_t *tp, int subtype,
1408 1408
 		case TR_URI_PASSWD:
1409 1409
 			val->rs = (_tr_parsed_uri.passwd.s)?_tr_parsed_uri.passwd:_tr_empty;
1410 1410
 			break;
1411
+		case TR_URI_SURI:
1412
+			if(_tr_uri.len >= TR_BUFFER_SIZE) {
1413
+				LM_WARN("uri too long [%.*s] (%d)\n",
1414
+						_tr_uri.len, _tr_uri.s, _tr_uri.len);
1415
+				val->rs = _tr_empty;
1416
+				break;
1417
+			}
1418
+
1419
+			tr_set_crt_buffer();
1420
+			sv.s = _tr_uri.s;
1421
+			sv.len = 0;
1422
+			while(sv.len<_tr_uri.len) {
1423
+				if(_tr_uri.s[sv.len]==':') {
1424
+					break;
1425
+				}
1426
+				sv.len++;
1427
+			}
1428
+			if(_tr_uri.s[sv.len]!=':') {
1429
+				LM_WARN("uri schema not found [%.*s] (%d)\n",
1430
+						_tr_uri.len, _tr_uri.s, _tr_uri.len);
1431
+				val->rs = _tr_empty;
1432
+				break;
1433
+			}
1434
+			sv.len++;
1435
+			memcpy(_tr_buffer, sv.s, sv.len);
1436
+			sv.s = _tr_buffer;
1437
+			sv.len++;
1438
+			if(_tr_parsed_uri.user.len > 0) {
1439
+				memcpy(sv.s + sv.len, _tr_parsed_uri.user.s,
1440
+						_tr_parsed_uri.user.len);
1441
+				sv.len += _tr_parsed_uri.user.len;
1442
+				sv.s[sv.len] = '@';
1443
+				sv.len++;
1444
+			}
1445
+			if(_tr_parsed_uri.host.len > 0) {
1446
+				memcpy(sv.s + sv.len, _tr_parsed_uri.host.s,
1447
+						_tr_parsed_uri.host.len);
1448
+				sv.len += _tr_parsed_uri.host.len;
1449
+			}
1450
+			if(_tr_parsed_uri.port.len > 0) {
1451
+				sv.s[sv.len] = ':';
1452
+				sv.len++;
1453
+				memcpy(sv.s + sv.len, _tr_parsed_uri.port.s,
1454
+						_tr_parsed_uri.port.len);
1455
+				sv.len += _tr_parsed_uri.port.len;
1456
+			}
1457
+			if(_tr_parsed_uri.transport_val.len > 0) {
1458
+				memcpy(sv.s + sv.len, ";transport=", 11);
1459
+				sv.len += 11;
1460
+				memcpy(sv.s + sv.len, _tr_parsed_uri.transport_val.s,
1461
+						_tr_parsed_uri.transport_val.len);
1462
+				sv.len += _tr_parsed_uri.transport_val.len;
1463
+			}
1464
+			sv.s[sv.len] = '\0';
1465
+			val->rs = sv;
1466
+			break;
1411 1467
 		case TR_URI_PORT:
1412 1468
 			val->flags |= PV_TYPE_INT|PV_VAL_INT;
1413 1469
 			val->rs = (_tr_parsed_uri.port.s)?_tr_parsed_uri.port:_tr_empty;
... ...
@@ -2788,6 +2844,9 @@ char* tr_parse_uri(str* in, trans_t *t)
2788 2844
 	} else if(name.len==4 && strncasecmp(name.s, "port", 4)==0) {
2789 2845
 		t->subtype = TR_URI_PORT;
2790 2846
 		goto done;
2847
+	} else if(name.len==4 && strncasecmp(name.s, "suri", 4)==0) {
2848
+		t->subtype = TR_URI_SURI;
2849
+		goto done;
2791 2850
 	} else if(name.len==6 && strncasecmp(name.s, "params", 6)==0) {
2792 2851
 		t->subtype = TR_URI_PARAMS;
2793 2852
 		goto done;
... ...
@@ -50,7 +50,7 @@ enum _tr_uri_subtype {
50 50
 	TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,
51 51
 	TR_URI_PARAMS, TR_URI_PARAM, TR_URI_HEADERS, TR_URI_TRANSPORT, TR_URI_TTL,
52 52
 	TR_URI_UPARAM, TR_URI_MADDR, TR_URI_METHOD, TR_URI_LR,
53
-	TR_URI_R2, TR_URI_SCHEME, TR_URI_TOSOCKET
53
+	TR_URI_R2, TR_URI_SCHEME, TR_URI_TOSOCKET, TR_URI_SURI
54 54
 };
55 55
 enum _tr_param_subtype {
56 56
 	TR_PL_NONE=0, TR_PL_VALUE, TR_PL_VALUEAT, TR_PL_NAME, TR_PL_COUNT