瀏覽代碼

ims_charging: Add a custom_user_avp parameter, to allow a custom from user in Diameter rather than PAI/From

Carsten Bock 8 年之前
父節點
當前提交
ba3556a80a

+ 1 - 1
src/modules/ims_charging/doc/ims_charging.xml

@@ -40,7 +40,7 @@
       <holder>Smile Communications</holder>
     </copyright>
     <copyright>
-      <year>2013</year>
+      <year>2013-2017</year>
       <holder>ng-voice GmbH</holder>
     </copyright>
   </bookinfo>

+ 25 - 0
src/modules/ims_charging/doc/ims_charging_admin.xml

@@ -726,6 +726,31 @@ modparam("ims_charging", "service_context_id_mcc", "262")
         <programlisting format="linespecific">
 ...
 modparam("ims_charging", "service_context_id_release", "262")
+...
+        </programlisting>
+      </example>
+    </section>
+
+    <section>
+      <title><varname>custom_user_avp</varname> (avp string)</title>
+
+      <para>When this parameter is set and the contents of the AVP is not
+      empty, the User-AVP in the Ro-Charging-Request will be based on the 
+      this parameter rather than on the P-Asserted or From-Header.</para>
+      <para>
+      This parameter allows you to setup an AVP with which you can customise
+      the user to be used in the Diameter-Request.</para>
+
+      <para><emphasis> Default value: if not set, P-Asserted-Identity with a
+      fallback to the From-Header is used. </emphasis></para>
+
+      <example>
+        <title><varname>custom_user_avp</varname>parameter
+        usage</title>
+
+        <programlisting format="linespecific">
+...
+modparam("ims_charging", "custom_user_avp", "$avp(from_user)")
 ...
         </programlisting>
       </example>

+ 15 - 0
src/modules/ims_charging/ims_charging_mod.c

@@ -61,6 +61,9 @@ client_ro_cfg cfg = { str_init(""),
     0
 };
 
+static str custom_user_spec = {NULL, 0};
+pv_spec_t custom_user_avp;
+
 extern struct ims_charging_counters_h ims_charging_cnts_h;
 struct cdp_binds cdpb;
 ims_dlg_api_t dlgb;
@@ -130,6 +133,7 @@ static param_export_t params[] = {
 		{ "db_update_period",		INT_PARAM,			&db_update_period		},
 		{ "vendor_specific_chargeinfo",		INT_PARAM,	&vendor_specific_chargeinfo		}, /* VSI for extra charing info in Ro */
 		{ "vendor_specific_id",		INT_PARAM,			&vendor_specific_id		}, /* VSI for extra charing info in Ro */
+		{ "custom_user_avp",		PARAM_STR,			&custom_user_spec},
 		{ 0, 0, 0 }
 };
 
@@ -173,6 +177,17 @@ int fix_parameters() {
 		return 0;
 	}
 
+	if (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 1;
 }
 

+ 37 - 6
src/modules/ims_charging/ims_ro.c

@@ -34,6 +34,8 @@
 #include "ro_db_handler.h"
 #include "ims_charging_stats.h"
 
+static pv_spec_t *custom_user_avp;		/*!< AVP for custom_user setting */
+
 extern struct tm_binds tmb;
 extern struct cdp_binds cdpb;
 extern client_ro_cfg cfg;
@@ -70,6 +72,33 @@ static void resume_on_interim_ccr(int is_timeout, void *param, AAAMessage *cca,
 static void resume_on_termination_ccr(int is_timeout, void *param, AAAMessage *cca, long elapsed_msecs);
 static int get_mac_avp_value(struct sip_msg *msg, str *value);
 
+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 P-Asserted-Identity/From-Header\n");
+	}
+
+	return -1;
+}
+
 void credit_control_session_callback(int event, void* session) {
     switch (event) {
         case AUTH_EV_SESSION_DROP:
@@ -349,13 +378,15 @@ int get_sip_header_info(struct sip_msg * req,
     *expires = cscf_get_expires_hdr(req, 0);
     *callid = cscf_get_call_id(req, NULL);
 
-    if ((*asserted_id_uri = cscf_get_asserted_identity(req, 0)).len == 0) {
-        LM_DBG("No P-Asserted-Identity hdr found. Using From hdr");
+    if (get_custom_user(req, asserted_id_uri) == -1) {
+	    if ((*asserted_id_uri = cscf_get_asserted_identity(req, 0)).len == 0) {
+		LM_DBG("No P-Asserted-Identity hdr found. Using From hdr");
 
-        if (!cscf_get_from_uri(req, asserted_id_uri)) {
-            LM_ERR("Error assigning P-Asserted-Identity using From hdr");
-            goto error;
-        }
+		if (!cscf_get_from_uri(req, asserted_id_uri)) {
+		    LM_ERR("Error assigning P-Asserted-Identity using From hdr");
+		    goto error;
+		}
+	    }
     }
 
     *to_uri = req->first_line.u.request.uri;

+ 2 - 0
src/modules/ims_charging/ims_ro.h

@@ -27,4 +27,6 @@ void send_ccr_interim(struct ro_session* ro_session, unsigned int used, unsigned
 void send_ccr_stop_with_param(struct ro_session *ro_session, unsigned int code, str* reason);
 int get_direction_as_int(str* direction);
 
+void init_custom_user(pv_spec_t *custom_user_avp);
+
 #endif /* CLIENT_RF_IMS_RO_H */