Browse code

pv: vars to get the length for o-uri/r-uri/f-uri/t-uri username

- $oUl, $rUl, $fUl. $tUl
- the length is already available in the str value, optimizing a bit by
no longer having to use {s.len}

Daniel-Constantin Mierla authored on 05/06/2020 07:37:53
Showing 2 changed files
... ...
@@ -272,6 +272,9 @@ static pv_export_t mod_pvs[] = {
272 272
 	{{"from.user", (sizeof("from.user")-1)}, /* */
273 273
 		PVT_OTHER, pv_get_from_attr, pv_set_from_username,
274 274
 		0, 0, pv_init_iname, 2},
275
+	{{"fUl", (sizeof("fUl")-1)}, /* */
276
+		PVT_OTHER, pv_get_from_attr, 0,
277
+		0, 0, pv_init_iname, 6},
275 278
 	{{"mb", (sizeof("mb")-1)}, /* */
276 279
 		PVT_OTHER, pv_get_msg_buf, 0,
277 280
 		0, 0, 0, 0},
... ...
@@ -314,6 +317,9 @@ static pv_export_t mod_pvs[] = {
314 317
 	{{"oU", (sizeof("oU")-1)}, /* */
315 318
 		PVT_OTHER, pv_get_ouri_attr, 0,
316 319
 		0, 0, pv_init_iname, 1},
320
+	{{"oUl", (sizeof("oUl")-1)}, /* */
321
+		PVT_OTHER, pv_get_ouri_attr, 0,
322
+		0, 0, pv_init_iname, 6},
317 323
 	{{"pd", (sizeof("pd")-1)}, /* */
318 324
 		PVT_OTHER, pv_get_ppi_attr, 0,
319 325
 		0, pv_parse_index, pv_init_iname, 3},
... ...
@@ -383,6 +389,9 @@ static pv_export_t mod_pvs[] = {
383 389
 	{{"ruri.user", (sizeof("ruri.user")-1)}, /* */
384 390
 		PVT_RURI_USERNAME, pv_get_ruri_attr, pv_set_ruri_user,
385 391
 		0, 0, pv_init_iname, 1},
392
+	{{"rUl", (sizeof("rUl")-1)}, /* */
393
+		PVT_RURI_USERNAME, pv_get_ruri_attr, 0,
394
+		0, 0, pv_init_iname, 6},
386 395
 	{{"rv", (sizeof("rv")-1)}, /* */
387 396
 		PVT_OTHER, pv_get_version, 0,
388 397
 		0, 0, 0, 0},
... ...
@@ -470,6 +479,9 @@ static pv_export_t mod_pvs[] = {
470 479
 	{{"to.user", (sizeof("to.user")-1)}, /* */
471 480
 		PVT_OTHER, pv_get_to_attr, pv_set_to_username,
472 481
 		0, 0, pv_init_iname, 2},
482
+	{{"tUl", (sizeof("tUl")-1)}, /* */
483
+		PVT_OTHER, pv_get_to_attr, pv_set_to_username,
484
+		0, 0, pv_init_iname, 6},
473 485
 	{{"true", (sizeof("true")-1)}, /* */
474 486
 		PVT_OTHER, pv_get_true, 0,
475 487
 		0, 0, 0, 0},
... ...
@@ -323,6 +323,10 @@ int pv_get_xuri_attr(struct sip_msg *msg, struct sip_uri *parsed_uri,
323 323
 	} else if(param->pvn.u.isname.name.n==5) /* uri scheme */ {
324 324
 		return pv_get_strintval(msg, param, res, &pv_uri_scheme[parsed_uri->type],
325 325
 				(int)parsed_uri->type);
326
+	} else if(param->pvn.u.isname.name.n==6) /* username length */ {
327
+		if(parsed_uri->user.s==NULL || parsed_uri->user.len<=0)
328
+			return pv_get_sintval(msg, param, res, 0);
329
+		return pv_get_sintval(msg, param, res, parsed_uri->user.len);
326 330
 	}
327 331
 	LM_ERR("unknown specifier\n");
328 332
 	return pv_get_null(msg, param, res);
... ...
@@ -452,6 +456,11 @@ int pv_get_xto_attr(struct sip_msg *msg, pv_param_t *param,
452 456
 			return pv_get_null(msg, param, res);
453 457
 		}
454 458
 		return pv_get_strval(msg, param, res, &uri->host);
459
+	} else if(param->pvn.u.isname.name.n==6) /* username length */ {
460
+		if(uri->user.s==NULL || uri->user.len<=0) {
461
+			return pv_get_sintval(msg, param, res, 0);
462
+		}
463
+		return pv_get_sintval(msg, param, res, uri->user.len);
455 464
 	}
456 465
 
457 466
 	LM_ERR("unknown specifier\n");