Browse code

pv: add missing implementation for documented acc user pv (GH #2056)

- add missing implementation for documented acc user pseudo-variable
- it was documented as $Au, but it works differently since a long time
- as discussed in issue GH #2056 add a new pv $AU that works like intended

Henning Westerholt authored on 06/09/2019 07:19:59
Showing 3 changed files
... ...
@@ -141,6 +141,9 @@ static pv_export_t mod_pvs[] = {
141 141
 	{{"Au", (sizeof("Au")-1)}, /* */
142 142
 		PVT_OTHER, pv_get_acc_username, 0,
143 143
 		0, 0, pv_init_iname, 1},
144
+	{{"AU", (sizeof("AU")-1)}, /* */
145
+		PVT_OTHER, pv_get_acc_user, 0,
146
+		0, 0, pv_init_iname, 1},
144 147
 	{{"bf", (sizeof("bf")-1)}, /* */
145 148
 		PVT_CONTEXT, pv_get_bflags, pv_set_bflags,
146 149
 		0, 0, 0, 0},
... ...
@@ -1572,6 +1572,37 @@ static inline str *cred_realm(struct sip_msg *rq)
1572 1572
 	return realm;
1573 1573
 }
1574 1574
 
1575
+
1576
+int pv_get_acc_user(struct sip_msg *msg, pv_param_t *param,
1577
+		pv_value_t *res)
1578
+{
1579
+	str* user;
1580
+	struct sip_uri puri;
1581
+	struct to_body* from;
1582
+
1583
+	/* try to take it from credentials */
1584
+	user = cred_user(msg);
1585
+	if (user) {
1586
+		return pv_get_strval(msg, param, res, user);
1587
+	}
1588
+
1589
+	/* from from uri */
1590
+	if(parse_from_header(msg)<0)
1591
+	{
1592
+		LM_ERR("cannot parse FROM header\n");
1593
+		return pv_get_null(msg, param, res);
1594
+	}
1595
+	if (msg->from && (from=get_from(msg)) && from->uri.len) {
1596
+		if (parse_uri(from->uri.s, from->uri.len, &puri) < 0 ) {
1597
+			LM_ERR("bad From URI\n");
1598
+			return pv_get_null(msg, param, res);
1599
+		}
1600
+		return pv_get_strval(msg, param, res, &(puri.user));
1601
+	}
1602
+	return pv_get_null(msg, param, res);
1603
+}
1604
+
1605
+
1575 1606
 int pv_get_acc_username(struct sip_msg *msg, pv_param_t *param,
1576 1607
 		pv_value_t *res)
1577 1608
 {
... ...
@@ -223,6 +223,9 @@ int pv_get_body_size(struct sip_msg *msg, pv_param_t *param,
223 223
 int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
224 224
 		pv_value_t *res);
225 225
 
226
+int pv_get_acc_user(struct sip_msg *msg, pv_param_t *param,
227
+		pv_value_t *res);
228
+
226 229
 int pv_get_acc_username(struct sip_msg *msg, pv_param_t *param,
227 230
 		pv_value_t *res);
228 231