Răsfoiți Sursa

modules/ims_charging: use cscf_get_public_identity_from_requri instead of msg->first_line.u.request.uri in mod.c and ims_charging.c
When getting public identity from Req URI use ims_getters method instead of reading directly from message
This allows ims_charging to identify subscribers to charge even when clients add extra info
(e.g. phone context) after the identity in the request URI

Richard Good 11 ani în urmă
părinte
comite
871ca61d1f
2 a modificat fișierele cu 31 adăugiri și 12 ștergeri
  1. 5 1
      modules/ims_charging/ims_ro.c
  2. 26 11
      modules/ims_charging/mod.c

+ 5 - 1
modules/ims_charging/ims_ro.c

@@ -944,6 +944,7 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, str* charge_
     
     
     int cc_event_number = 0;						//According to IOT tests this should start at 0
     int cc_event_number = 0;						//According to IOT tests this should start at 0
     int cc_event_type = RO_CC_START;
     int cc_event_type = RO_CC_START;
+    int free_called_asserted_identity = 0;
 
 
     //getting asserted identity
     //getting asserted identity
     if ((asserted_identity = cscf_get_asserted_identity(msg, 0)).len == 0) {
     if ((asserted_identity = cscf_get_asserted_identity(msg, 0)).len == 0) {
@@ -955,7 +956,8 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, str* charge_
     //getting called asserted identity
     //getting called asserted identity
     if ((called_asserted_identity = cscf_get_called_party_id(msg, &h)).len == 0) {
     if ((called_asserted_identity = cscf_get_called_party_id(msg, &h)).len == 0) {
 	    LM_DBG("No P-Called-Identity hdr found. Using request URI for called_asserted_identity");
 	    LM_DBG("No P-Called-Identity hdr found. Using request URI for called_asserted_identity");
-	    called_asserted_identity	= msg->first_line.u.request.uri;
+	    called_asserted_identity = cscf_get_public_identity_from_requri(msg);
+	    free_called_asserted_identity = 1;
     }
     }
     
     
     if (dir == RO_ORIG_DIRECTION) {
     if (dir == RO_ORIG_DIRECTION) {
@@ -1066,9 +1068,11 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, str* charge_
 
 
     update_stat(initial_ccrs, 1);
     update_stat(initial_ccrs, 1);
 
 
+    if(free_called_asserted_identity)  shm_free(called_asserted_identity.s);// shm_malloc in cscf_get_public_identity_from_requri	
     return RO_RETURN_BREAK;
     return RO_RETURN_BREAK;
 
 
 error:
 error:
+    if(free_called_asserted_identity)  shm_free(called_asserted_identity.s);// shm_malloc in cscf_get_public_identity_from_requri	
     Ro_free_CCR(ro_ccr_data);
     Ro_free_CCR(ro_ccr_data);
     if (cc_acc_session) {
     if (cc_acc_session) {
         	cdpb.AAASessionsUnlock(cc_acc_session->hash);
         	cdpb.AAASessionsUnlock(cc_acc_session->hash);

+ 26 - 11
modules/ims_charging/mod.c

@@ -324,6 +324,7 @@ static int w_ro_ccr(struct sip_msg *msg, str* route_name, str* direction, str* c
 	struct dlg_cell* dlg;
 	struct dlg_cell* dlg;
 	unsigned int len;
 	unsigned int len;
 	struct ro_session *ro_session = 0;
 	struct ro_session *ro_session = 0;
+	int free_contact = 0;
 	
 	
 	LM_DBG("Ro CCR initiated: direction:%.*s, charge_type:%.*s, unit_type:%.*s, reservation_units:%i, route_name:%.*s",
 	LM_DBG("Ro CCR initiated: direction:%.*s, charge_type:%.*s, unit_type:%.*s, reservation_units:%i, route_name:%.*s",
 			direction->len, direction->s,
 			direction->len, direction->s,
@@ -366,19 +367,24 @@ static int w_ro_ccr(struct sip_msg *msg, str* route_name, str* direction, str* c
 			goto send_ccr;
 			goto send_ccr;
 		}
 		}
 		//get callee contact from request URI
 		//get callee contact from request URI
-		contact	= msg->first_line.u.request.uri;
+		contact = cscf_get_public_identity_from_requri(msg);
+		free_contact = 1;
 	    
 	    
 	} else {
 	} else {
 	    LM_CRIT("don't know what to do in unknown mode - should we even get here\n");
 	    LM_CRIT("don't know what to do in unknown mode - should we even get here\n");
-	    return RO_RETURN_ERROR;
+	    ret = RO_RETURN_ERROR;
+	    goto done;
 	}
 	}
 	
 	
+	LM_DBG("IMPU data to pass to usrloc:  contact <%.*s> identity <%.*s>\n", contact.len, contact.s, identity.len, identity.s);
+	
 	//create impu_data_parcel
 	//create impu_data_parcel
 	len = identity.len + contact.len +  sizeof (struct impu_data);
 	len = identity.len + contact.len +  sizeof (struct impu_data);
 	impu_data = (struct impu_data*) shm_malloc(len);
 	impu_data = (struct impu_data*) shm_malloc(len);
 	if (!impu_data) {
 	if (!impu_data) {
 	    LM_ERR("Unable to allocate memory for impu_data, trying to send CCR\n");
 	    LM_ERR("Unable to allocate memory for impu_data, trying to send CCR\n");
-	    return RO_RETURN_ERROR;
+	    ret = RO_RETURN_ERROR;
+	    goto done;
 	}
 	}
 	memset(impu_data, 0, len);
 	memset(impu_data, 0, len);
 	
 	
@@ -398,19 +404,22 @@ static int w_ro_ccr(struct sip_msg *msg, str* route_name, str* direction, str* c
 	if (p != (((char*) impu_data) + len)) {
 	if (p != (((char*) impu_data) + len)) {
 	    LM_ERR("buffer overflow creating impu data, trying to send CCR\n");
 	    LM_ERR("buffer overflow creating impu data, trying to send CCR\n");
 	    shm_free(impu_data);
 	    shm_free(impu_data);
-	    return RO_RETURN_ERROR;
+	    ret = RO_RETURN_ERROR;
+	    goto done;
 	}
 	}
 	
 	
 	
 	
 	//reg for callbacks on confirmed and terminated
 	//reg for callbacks on confirmed and terminated
 	if (dlgb.register_dlgcb(dlg, /* DLGCB_RESPONSE_FWDED */ DLGCB_CONFIRMED, add_dlg_data_to_contact, (void*)impu_data ,NULL ) != 0) {
 	if (dlgb.register_dlgcb(dlg, /* DLGCB_RESPONSE_FWDED */ DLGCB_CONFIRMED, add_dlg_data_to_contact, (void*)impu_data ,NULL ) != 0) {
 	    LM_CRIT("cannot register callback for dialog confirmation\n");
 	    LM_CRIT("cannot register callback for dialog confirmation\n");
-	    return RO_RETURN_ERROR;
+	    ret = RO_RETURN_ERROR;
+	    goto done;
 	}
 	}
 
 
 	if (dlgb.register_dlgcb(dlg, DLGCB_TERMINATED | DLGCB_FAILED | DLGCB_EXPIRED /*| DLGCB_DESTROY */, remove_dlg_data_from_contact, (void*)impu_data, NULL ) != 0) {
 	if (dlgb.register_dlgcb(dlg, DLGCB_TERMINATED | DLGCB_FAILED | DLGCB_EXPIRED /*| DLGCB_DESTROY */, remove_dlg_data_from_contact, (void*)impu_data, NULL ) != 0) {
 	    LM_CRIT("cannot register callback for dialog termination\n");
 	    LM_CRIT("cannot register callback for dialog termination\n");
-	    return RO_RETURN_ERROR;
+	    ret = RO_RETURN_ERROR;
+	    goto done;
 	}
 	}
 	
 	
 send_ccr:
 send_ccr:
@@ -429,13 +438,15 @@ send_ccr:
 	int ri = route_get(&main_rt, route_name->s);
 	int ri = route_get(&main_rt, route_name->s);
 	if (ri < 0) {
 	if (ri < 0) {
 		LM_ERR("unable to find route block [%.*s]\n", route_name->len, route_name->s);
 		LM_ERR("unable to find route block [%.*s]\n", route_name->len, route_name->s);
-		return RO_RETURN_ERROR;
+		ret = RO_RETURN_ERROR;
+		goto done;
 	}
 	}
 	
 	
 	cfg_action = main_rt.rlist[ri];
 	cfg_action = main_rt.rlist[ri];
 	if (!cfg_action) {
 	if (!cfg_action) {
 		LM_ERR("empty action lists in route block [%.*s]\n", route_name->len, route_name->s);
 		LM_ERR("empty action lists in route block [%.*s]\n", route_name->len, route_name->s);
-		return RO_RETURN_ERROR;
+		ret = RO_RETURN_ERROR;
+		goto done;
 	}
 	}
 
 
 	//before we send lets suspend the transaction
 	//before we send lets suspend the transaction
@@ -443,19 +454,22 @@ send_ccr:
 	if (t == NULL || t == T_UNDEFINED) {
 	if (t == NULL || t == T_UNDEFINED) {
 		if (tmb.t_newtran(msg) < 0) {
 		if (tmb.t_newtran(msg) < 0) {
 			LM_ERR("cannot create the transaction for CCR async\n");
 			LM_ERR("cannot create the transaction for CCR async\n");
-			return RO_RETURN_ERROR;
+			ret = RO_RETURN_ERROR;
+			goto done;
 		}
 		}
 		t = tmb.t_gett();
 		t = tmb.t_gett();
 		if (t == NULL || t == T_UNDEFINED) {
 		if (t == NULL || t == T_UNDEFINED) {
 			LM_ERR("cannot lookup the transaction\n");
 			LM_ERR("cannot lookup the transaction\n");
-			return RO_RETURN_ERROR;
+			ret = RO_RETURN_ERROR;
+			goto done;
 		}
 		}
 	}
 	}
 
 
 	LM_DBG("Suspending SIP TM transaction\n");
 	LM_DBG("Suspending SIP TM transaction\n");
 	if (tmb.t_suspend(msg, &tindex, &tlabel) < 0) {
 	if (tmb.t_suspend(msg, &tindex, &tlabel) < 0) {
 		LM_ERR("failed to suspend the TM processing\n");
 		LM_ERR("failed to suspend the TM processing\n");
-		return RO_RETURN_ERROR;
+		ret =  RO_RETURN_ERROR;
+		goto done;
 	}
 	}
 	
 	
 	ret = Ro_Send_CCR(msg, dlg, dir, charge_type, unit_type, reservation_units, cfg_action, tindex, tlabel);
 	ret = Ro_Send_CCR(msg, dlg, dir, charge_type, unit_type, reservation_units, cfg_action, tindex, tlabel);
@@ -466,6 +480,7 @@ send_ccr:
 	}
 	}
     
     
 done:
 done:
+	if(free_contact)  shm_free(contact.s);// shm_malloc in cscf_get_public_identity_from_requri	
 	return ret;
 	return ret;
 }
 }