Browse code

modules/pv: added PVs to provide access to the user-agent string retrieved from usrloc

Peter Dunkley authored on 17/05/2013 23:14:07
Showing 4 changed files
... ...
@@ -416,6 +416,9 @@ static pv_export_t mod_pvs[] = {
416 416
 	{{"ruid", (sizeof("ruid")-1)}, /* */
417 417
 		PVT_OTHER, pv_get_ruid, 0,
418 418
 		0, 0, 0, 0},
419
+	{{"location_ua", (sizeof("location_ua")-1)}, /* */
420
+		PVT_OTHER, pv_get_location_ua, 0,
421
+		0, 0, 0, 0},
419 422
 
420 423
 	{ {"shv", (sizeof("shv")-1)}, PVT_OTHER, pv_get_shvar,
421 424
 		pv_set_shvar, pv_parse_shvar_name, 0, 0, 0},
... ...
@@ -41,6 +41,7 @@ int pv_get_branchx(struct sip_msg *msg, pv_param_t *param,
41 41
 	unsigned int fl = 0;
42 42
 	struct socket_info* fsocket = NULL;
43 43
 	str ruid;
44
+	str location_ua;
44 45
 
45 46
 	/* get the index */
46 47
 	if(pv_get_spec_index(msg, param, &idx, &idxf)!=0)
... ...
@@ -49,7 +50,7 @@ int pv_get_branchx(struct sip_msg *msg, pv_param_t *param,
49 49
 		return pv_get_null(msg, param, res);
50 50
 	}
51 51
 
52
-	uri.s = get_branch(idx, &uri.len, &lq, &duri, &path, &fl, &fsocket, &ruid, 0);
52
+	uri.s = get_branch(idx, &uri.len, &lq, &duri, &path, &fl, &fsocket, &ruid, 0, &location_ua);
53 53
 
54 54
 	/* branch(count) doesn't need a valid branch, everything else does */
55 55
 	if(uri.s == 0 && ( param->pvn.u.isname.name.n != 5/* count*/ ))
... ...
@@ -84,6 +85,10 @@ int pv_get_branchx(struct sip_msg *msg, pv_param_t *param,
84 84
 			if(ruid.len==0)
85 85
 				return pv_get_null(msg, param, res);
86 86
 			return pv_get_strval(msg, param, res, &ruid);
87
+		case 8: /* location_ua */
88
+			if(location_ua.len==0)
89
+				return pv_get_null(msg, param, res);
90
+			return pv_get_strval(msg, param, res, &location_ua);
87 91
 		default:
88 92
 			/* 0 - uri */
89 93
 			return pv_get_strval(msg, param, res, &uri);
... ...
@@ -253,6 +258,9 @@ int pv_set_branchx(struct sip_msg* msg, pv_param_t *param,
253 253
 		case 7: /* ruid */
254 254
 			/* do nothing - cannot set the ruid */
255 255
 		break;
256
+		case 8: /* location_ua */
257
+			/* do nothing - cannot set the location_ua */
258
+		break;
256 259
 		default:
257 260
 			/* 0 - uri */
258 261
 			if(val==NULL || (val->flags&PV_VAL_NULL))
... ...
@@ -316,6 +324,8 @@ int pv_parse_branchx_name(pv_spec_p sp, str *in)
316 316
 		case 11: 
317 317
 			if(strncmp(in->s, "send_socket", 11)==0)
318 318
 				sp->pvp.pvn.u.isname.name.n = 4;
319
+			else if(strncmp(in->s, "location_ua", 11)==0)
320
+				sp->pvp.pvn.u.isname.name.n = 8;
319 321
 			else goto error;
320 322
 		break;
321 323
 		case 5: 
... ...
@@ -1359,7 +1359,7 @@ int pv_get_branch(struct sip_msg *msg, pv_param_t *param,
1359 1359
 		return pv_get_null(msg, param, res);
1360 1360
 
1361 1361
 
1362
-	branch.s = get_branch(0, &branch.len, &q, 0, 0, 0, 0, 0, 0);
1362
+	branch.s = get_branch(0, &branch.len, &q, 0, 0, 0, 0, 0, 0, 0);
1363 1363
 	if (!branch.s) {
1364 1364
 		return pv_get_null(msg, param, res);
1365 1365
 	}
... ...
@@ -1388,7 +1388,7 @@ int pv_get_branches(struct sip_msg *msg, pv_param_t *param,
1388 1388
   
1389 1389
 	cnt = s.len = 0;
1390 1390
 
1391
-	while ((uri.s = get_branch(cnt, &uri.len, &q, 0, 0, 0, 0, 0, 0)))
1391
+	while ((uri.s = get_branch(cnt, &uri.len, &q, 0, 0, 0, 0, 0, 0, 0)))
1392 1392
 	{
1393 1393
 		cnt++;
1394 1394
 		s.len += uri.len;
... ...
@@ -1412,7 +1412,7 @@ int pv_get_branches(struct sip_msg *msg, pv_param_t *param,
1412 1412
 	i = 0;
1413 1413
 	p = pv_local_buf;
1414 1414
 
1415
-	while ((uri.s = get_branch(i, &uri.len, &q, 0, 0, 0, 0, 0, 0)))
1415
+	while ((uri.s = get_branch(i, &uri.len, &q, 0, 0, 0, 0, 0, 0, 0)))
1416 1416
 	{
1417 1417
 		if (i)
1418 1418
 		{
... ...
@@ -1823,6 +1823,24 @@ int pv_get_ruid(struct sip_msg *msg, pv_param_t *param,
1823 1823
 	return pv_get_strval(msg, param, res, &msg->ruid);
1824 1824
 }
1825 1825
 
1826
+int pv_get_location_ua(struct sip_msg *msg, pv_param_t *param,
1827
+		pv_value_t *res)
1828
+{
1829
+	if(msg==NULL)
1830
+		return -1;
1831
+
1832
+	if(msg->first_line.type == SIP_REPLY)
1833
+		return pv_get_null(msg, param, res);
1834
+
1835
+	if(msg->location_ua.len==0) 
1836
+	{
1837
+		LM_DBG("no location_ua\n");
1838
+		return pv_get_null(msg, param, res);
1839
+	}
1840
+	
1841
+	return pv_get_strval(msg, param, res, &msg->location_ua);
1842
+}
1843
+
1826 1844
 int pv_get_tcpconn_id(struct sip_msg *msg, pv_param_t *param,
1827 1845
 		pv_value_t *res)
1828 1846
 {
... ...
@@ -217,6 +217,9 @@ int pv_get_cnt(struct sip_msg *msg, pv_param_t *param,
217 217
 int pv_get_ruid(struct sip_msg *msg, pv_param_t *param,
218 218
 		pv_value_t *res);
219 219
 
220
+int pv_get_location_ua(struct sip_msg *msg, pv_param_t *param,
221
+		pv_value_t *res);
222
+
220 223
 int pv_get_tcpconn_id(struct sip_msg *msg, pv_param_t *param,
221 224
 		pv_value_t *res);
222 225