Переглянути джерело

modules_k/rr: added feature to set custom username for Record-Route URI
- this is an AVP param that can be used to customise the default
username (Request-URI) added to the Record-Route URI before
calling record_route.

Jason Penton 12 роки тому
батько
коміт
ead52752c9
4 змінених файлів з 523 додано та 487 видалено
  1. 468 481
      modules_k/rr/doc/rr_admin.xml
  2. 37 5
      modules_k/rr/record.c
  3. 3 1
      modules_k/rr/record.h
  4. 15 0
      modules_k/rr/rr_mod.c

Різницю між файлами не показано, бо вона завелика
+ 468 - 481
modules_k/rr/doc/rr_admin.xml


+ 37 - 5
modules_k/rr/record.c

@@ -75,6 +75,35 @@ static char rr_param_buf_ptr[RR_PARAM_BUF_SIZE];
 static str rr_param_buf = {rr_param_buf_ptr,0};
 static unsigned int rr_param_msg;
 
+static pv_spec_t *custom_user_avp;		/*!< AVP for custom_user setting */
+
+
+void init_custom_user(pv_spec_t *custom_user_avp_p)
+{
+    custom_user_avp = custom_user_avp_p;
+}
+
+/*!
+ * \brief Return the custom_user for a record route
+ * \param req SIP message
+ * \param custom_user to be returned
+ * \return <0 for failure
+ */
+inline static int get_custom_user(struct sip_msg *req, str *custom_user) {
+	pv_value_t pv_val;
+
+	if (custom_user_avp) {
+		if ((pv_get_spec_value(req, custom_user_avp, &pv_val) == 0)
+				&& (pv_val.flags & PV_VAL_STR) && (pv_val.rs.len > 0)) {
+			custom_user->s = pv_val.rs.s;
+			custom_user->len = pv_val.rs.len;
+			return 0;
+		}
+		LM_DBG("invalid AVP value, using default user from RURI\n");
+	}
+
+	return -1;
+}
 
 /*!
  * \brief Extract username from the Request URI
@@ -89,7 +118,7 @@ static inline int get_username(struct sip_msg* _m, str* _user)
 {
 	struct sip_uri puri;
 
-	     /* first try to look at r-uri for a username */
+	/* first try to look at r-uri for a username */
 	if (parse_uri(_m->first_line.u.request.uri.s, _m->first_line.u.request.uri.len, &puri) < 0) {
 		LM_ERR("failed to parse R-URI\n");
 		return -1;
@@ -104,7 +133,7 @@ static inline int get_username(struct sip_msg* _m, str* _user)
 		if (parse_uri(_m->new_uri.s, _m->new_uri.len, &puri) < 0) {
 			LM_ERR("failed to parse new_uri\n");
 			return -2;
-	        }
+		}
 	}
 
 	_user->s = puri.user.s;
@@ -286,9 +315,12 @@ int record_route(struct sip_msg* _m, str *params)
 	user.len = 0;
 	
 	if (add_username) {
-		if (get_username(_m, &user) < 0) {
-			LM_ERR("failed to extract username\n");
-			return -1;
+		/* check if there is a custom user set */
+		if (get_custom_user(_m, &user) < 0) {
+			if (get_username(_m, &user) < 0) {
+				LM_ERR("failed to extract username\n");
+				return -1;
+			}
 		}
 	} else if (use_ob) {
 		if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) {

+ 3 - 1
modules_k/rr/record.h

@@ -31,7 +31,7 @@
 
 #include "../../parser/msg_parser.h"
 #include "../../str.h"
-
+#include "../../pvar.h"
 
 /*!
  * \brief Insert a new Record-Route header field with lr parameter
@@ -82,5 +82,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data);
  */
 int add_rr_param(struct sip_msg* msg, str* rr_param);
 
+void init_custom_user(pv_spec_t *custom_user_avp);
+
 
 #endif /* RECORD_H */

+ 15 - 0
modules_k/rr/rr_mod.c

@@ -58,6 +58,8 @@ int enable_double_rr = 1;	/*!< enable using of 2 RR by default */
 int enable_full_lr = 0;		/*!< compatibilty mode disabled by default */
 int add_username = 0;	 	/*!< do not add username by default */
 int enable_socket_mismatch_warning = 1; /*!< enable socket mismatch warning */
+static str custom_user_spec = {NULL, 0};
+pv_spec_t custom_user_avp;
 
 static unsigned int last_rr_msg;
 ob_api_t rr_obb;
@@ -117,6 +119,7 @@ static param_export_t params[] ={
 #endif
 	{"add_username",		INT_PARAM, &add_username},
 	{"enable_socket_mismatch_warning",INT_PARAM,&enable_socket_mismatch_warning},
+	{"custom_user_avp",           STR_PARAM, &custom_user_spec.s},
 	{0, 0, 0 }
 };
 
@@ -181,6 +184,18 @@ static int mod_init(void)
 		return -1;
 	}
 
+	if (custom_user_spec.s) {
+		custom_user_spec.len = strlen(custom_user_spec.s);
+		if (pv_parse_spec(&custom_user_spec, &custom_user_avp) == 0
+				&& (custom_user_avp.type != PVT_AVP)) {
+			LM_ERR("malformed or non AVP custom_user "
+					"AVP definition in '%.*s'\n", custom_user_spec.len,custom_user_spec.s);
+			return -1;
+		}
+	}
+
+	init_custom_user(custom_user_spec.s ? &custom_user_avp : 0);
+
 	return 0;
 }
 

Деякі файли не було показано, через те що забагато файлів було змінено