void Send_STR(cdp_session_t* s, AAAMessage* msg)
{
	AAAMessage *str=0;
	AAA_AVP *avp=0;
	peer *p=0;
	char x[4];
	LOG(L_DBG, "sending STR\n");
	//if (msg) LOG(L_DBG,"Send_STR() : sending STR for %d, flags %#1x endtoend %u hopbyhop %u\n",msg->commandCode,msg->flags,msg->endtoendId,msg->hopbyhopId);
	//else LOG(L_DBG,"Send_STR() called from AAATerminateAuthSession or some other event\n");
	str = AAACreateRequest(s->application_id,IMS_STR,Flag_Proxyable,s);
	
	if (!str) {
		LOG(L_ERR,"ERR:Send_STR(): error creating STR!\n");
		return;
	}
	if(!dup_routing_avps(msg, str)){
		LOG(L_ERR,"ERR:Send_STR(): error duplicating routing AVPs!\n");
		AAAFreeMessage(&str);
		return;
	}
	if(s->vendor_id!=0 && !add_vendor_specific_application_id_group(str,s->vendor_id,s->application_id)){ 
		LOG(L_ERR,"ERR:Send_STR(): error adding Vendor-Id-Specific-Application-Id Group!\n");
		AAAFreeMessage(&str);
		return;
	}
	
	set_4bytes(x,s->application_id);
	avp = AAACreateAVP(AVP_Auth_Application_Id,AAA_AVP_FLAG_MANDATORY,0,x,4,AVP_DUPLICATE_DATA);
	AAAAddAVPToMessage(str,avp,str->avpList.tail);
	
	set_4bytes(x,4); // Diameter_administrative
	avp = AAACreateAVP(AVP_Termination_Cause,AAA_AVP_FLAG_MANDATORY,0,x,4,AVP_DUPLICATE_DATA);
	AAAAddAVPToMessage(str,avp,str->avpList.tail);
	//todo - add all the other avps

	p = get_routing_peer(str);
	if (!p) {
		LOG(L_ERR,"unable to get routing peer in Send_STR \n");
		if (str) AAAFreeMessage(&str); //needed in frequency
		return;
	}
	//if (str) LOG(L_CRIT,"Send_STR() : sending STR  %d, flags %#1x endtoend %u hopbyhop %u\n",str->commandCode,str->flags,str->endtoendId,str->hopbyhopId);
	if (!peer_send_msg(p,str))
	{
		LOG(L_DBG,"Send_STR peer_send_msg return error!\n");
		if (str) AAAFreeMessage(&str); //needed in frequency	
	} else { 
		LOG(L_DBG,"success sending STR\n");
	}
}
Example #2
0
void Send_STR(cdp_session_t* s, AAAMessage* msg) {
    AAAMessage *str = 0;
    AAA_AVP *avp = 0;
    peer *p = 0;
    char x[4];
    LM_DBG("sending STR\n");
    //if (msg) LM_DBG("Send_STR() : sending STR for %d, flags %#1x endtoend %u hopbyhop %u\n",msg->commandCode,msg->flags,msg->endtoendId,msg->hopbyhopId);
    //else LM_DBG("Send_STR() called from AAATerminateAuthSession or some other event\n");
    str = AAACreateRequest(s->application_id, IMS_STR, Flag_Proxyable, s);

    if (!str) {
        LM_ERR("Send_STR(): error creating STR!\n");
        return;
    }
    if (!dup_routing_avps(msg, str)) {
        LM_ERR("Send_STR(): error duplicating routing AVPs!\n");
        AAAFreeMessage(&str);
        return;
    }
    if (s->vendor_id != 0 && !add_vendor_specific_application_id_group(str, s->vendor_id, s->application_id)) {
        LM_ERR("Send_STR(): error adding Vendor-Id-Specific-Application-Id Group!\n");
        AAAFreeMessage(&str);
        return;
    }

    //Richard added this - if timers expire dest realm is not here!
    LM_DBG("Adding dest realm if not there already...\n");
    LM_DBG("Destination realm: [%.*s] \n", s->dest_realm.len, s->dest_realm.s);
    /* Add Destination-Realm AVP, if not already there */
    avp = AAAFindMatchingAVP(str, str->avpList.head, AVP_Destination_Realm, 0, AAA_FORWARD_SEARCH);
    if (!avp) {
        avp = AAACreateAVP(AVP_Destination_Realm, AAA_AVP_FLAG_MANDATORY, 0,
                s->dest_realm.s, s->dest_realm.len, AVP_DUPLICATE_DATA);
        AAAAddAVPToMessage(str, avp, str->avpList.tail);
    }




    set_4bytes(x, s->application_id);
    avp = AAACreateAVP(AVP_Auth_Application_Id, AAA_AVP_FLAG_MANDATORY, 0, x, 4, AVP_DUPLICATE_DATA);
    AAAAddAVPToMessage(str, avp, str->avpList.tail);

    set_4bytes(x, 4); // Diameter_administrative
    avp = AAACreateAVP(AVP_Termination_Cause, AAA_AVP_FLAG_MANDATORY, 0, x, 4, AVP_DUPLICATE_DATA);
    AAAAddAVPToMessage(str, avp, str->avpList.tail);
    //todo - add all the other avps

    /* we are already locked on the auth session*/
    p = get_routing_peer(s, str);

    if (!p) {
        LM_ERR("unable to get routing peer in Send_STR \n");
        if (str) AAAFreeMessage(&str); //needed in frequency
        return;
    }
    //if (str) LM_CRIT("Send_STR() : sending STR  %d, flags %#1x endtoend %u hopbyhop %u\n",str->commandCode,str->flags,str->endtoendId,str->hopbyhopId);
    if (!peer_send_msg(p, str)) {
        LM_DBG("Send_STR peer_send_msg return error!\n");
        if (str) AAAFreeMessage(&str); //needed in frequency
    } else {
        LM_DBG("success sending STR\n");
    }
}