Browse Source

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 6 years ago
parent
commit
e3774a8e40
3 changed files with 37 additions and 0 deletions
  1. 3 0
      src/modules/pv/pv.c
  2. 31 0
      src/modules/pv/pv_core.c
  3. 3 0
      src/modules/pv/pv_core.h

+ 3 - 0
src/modules/pv/pv.c

@@ -141,6 +141,9 @@ static pv_export_t mod_pvs[] = {
 	{{"Au", (sizeof("Au")-1)}, /* */
 		PVT_OTHER, pv_get_acc_username, 0,
 		0, 0, pv_init_iname, 1},
+	{{"AU", (sizeof("AU")-1)}, /* */
+		PVT_OTHER, pv_get_acc_user, 0,
+		0, 0, pv_init_iname, 1},
 	{{"bf", (sizeof("bf")-1)}, /* */
 		PVT_CONTEXT, pv_get_bflags, pv_set_bflags,
 		0, 0, 0, 0},

+ 31 - 0
src/modules/pv/pv_core.c

@@ -1572,6 +1572,37 @@ static inline str *cred_realm(struct sip_msg *rq)
 	return realm;
 }
 
+
+int pv_get_acc_user(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	str* user;
+	struct sip_uri puri;
+	struct to_body* from;
+
+	/* try to take it from credentials */
+	user = cred_user(msg);
+	if (user) {
+		return pv_get_strval(msg, param, res, user);
+	}
+
+	/* from from uri */
+	if(parse_from_header(msg)<0)
+	{
+		LM_ERR("cannot parse FROM header\n");
+		return pv_get_null(msg, param, res);
+	}
+	if (msg->from && (from=get_from(msg)) && from->uri.len) {
+		if (parse_uri(from->uri.s, from->uri.len, &puri) < 0 ) {
+			LM_ERR("bad From URI\n");
+			return pv_get_null(msg, param, res);
+		}
+		return pv_get_strval(msg, param, res, &(puri.user));
+	}
+	return pv_get_null(msg, param, res);
+}
+
+
 int pv_get_acc_username(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 {

+ 3 - 0
src/modules/pv/pv_core.h

@@ -223,6 +223,9 @@ int pv_get_body_size(struct sip_msg *msg, pv_param_t *param,
 int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 
+int pv_get_acc_user(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res);
+
 int pv_get_acc_username(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);