⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aaatransceiver.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
            //Failed to talk to billing server            //if Billing is manadatory, no call should go through            if(B2bConfig::instance().getStr(B2bConfig::PP_OPTIONS) == B2bConfig::PP_MANDATORY)            {                //TODO - Should log it locally for later consolidation            }        }    }}voidAAATransceiver::cleanUp(u_int8_t rId){    if(myRetransMap[rId] == 0)    {        return;    }    Sptr<RadiusPayload> rPayload = myRetransMap[rId];    myRetransMap[rId] = 0;    //Stop the retransmission    rPayload->retransCount = 0;     //Cancel the retransmission event also    mySendFifo.cancel(rPayload->myRetransId);}voidAAATransceiver::udpSend(Sptr<AAAEvent> aaaEvent){    Sptr<RadiusPayload> rPayload =0;    u_int8_t rId;    myMutex.lock();    rId = aaaEvent->getReqId();    if(myRetransMap[rId] == 0)    {        cpLog(LOG_DEBUG, "Radius ID (%d) not in database, ignoring..", rId);        myMutex.unlock();        return;    }    rPayload = myRetransMap[rId];    myMutex.unlock();    if(rPayload->rMsg == 0) return;    //Send it now    //Get Radius Auth Host/Port    B2bConfig& bc = B2bConfig::instance();    RadiusPacketType rType = rPayload->rMsg->type();    Sptr<NetworkAddress> dest = 0;     if(rType == RP_ACCESS_REQUEST)    {        dest = new NetworkAddress (bc.getStr(B2bConfig::RAD_BILLING_ADDR),                        bc.getInt(B2bConfig::RAD_BILLING_AUTH_PORT));    }    else    {        dest = new NetworkAddress (bc.getStr(B2bConfig::RAD_BILLING_ADDR),                        bc.getInt(B2bConfig::RAD_BILLING_ACCT_PORT));    }    cpLog(LOG_DEBUG, "Sending request for Radius id(%d), to %s:%d", rId,                       dest->getIpName().c_str(), dest->getPort());    RawMessage udpMsg( rPayload->rMsg->data() );    //Hack, I hate it    const char* c = reinterpret_cast<const char*>(udpMsg.buffer);    myUdpStack->transmitTo(c, ntohs(udpMsg.msgHdr.length), dest.getPtr());}voidAAATransceiver::buildThePayload(Sptr<AAAEvent> aaaEvent,                                 u_int8_t type, u_int8_t subType){    cpLog(LOG_DEBUG, "AAATransceiver::buildThePayload for type %d", type);    Sptr<RadiusPayload> rPayload = new RadiusPayload();    u_int8_t rId = getNextId();    aaaEvent->setReqId(rId);    switch(type)    {        case RP_ACCESS_REQUEST:        {            rPayload->rMsg = new RadiusMessage(RP_ACCESS_REQUEST);            fillAAAData(aaaEvent, rPayload->rMsg);        }        break;        case RP_ACCOUNTING_REQUEST:        {            rPayload->rMsg = new RadiusMessage(RP_ACCOUNTING_REQUEST);            if(subType == RAS_START)            {                fillAccountStartData(aaaEvent, rPayload->rMsg);            }            else if(subType == RAS_STOP)            {                fillAccountStopData(aaaEvent, rPayload->rMsg);            }            else if(subType == RAS_INTERIM)            {                fillInterimAccountData(aaaEvent, rPayload->rMsg);            }        }        break;        default:            cpLog(LOG_WARNING, "Can not handle the type %d, ignoring", type);            return;        break;    }    rPayload->aEvent = aaaEvent;    rPayload->rMsg->setIdentifier(rId);    const char* secret = B2bConfig::instance().getStr(B2bConfig::RAD_BILLING_PASSWD).c_str();            rPayload->rMsg->calcAuthenticator( secret );    myMutex.lock();    myRetransMap[rId] = rPayload;    myMutex.unlock();}void AAATransceiver::sendAuthRequest(Sptr<AAAEvent> aaaEvent){    cpLog(LOG_DEBUG, "AAATransceiver::sendAuthRequest");    buildThePayload(aaaEvent, RP_ACCESS_REQUEST, 0);    mySendFifo.add(aaaEvent);}void AAATransceiver::sendAcctStart(Sptr<AAAEvent> aaaEvent){    cpLog(LOG_DEBUG, "AAATransceiver::sendAcctStart");    buildThePayload(aaaEvent, RP_ACCOUNTING_REQUEST, RAS_START);    mySendFifo.add(aaaEvent);}void AAATransceiver::sendAcctInterim(Sptr<AAAEvent> aaaEvent){    cpLog(LOG_DEBUG, "AAATransceiver::sendAcctInterim");    buildThePayload(aaaEvent, RP_ACCOUNTING_REQUEST, RAS_INTERIM);    mySendFifo.add(aaaEvent);}void AAATransceiver::sendAcctStop(Sptr<AAAEvent> aaaEvent){    cpLog(LOG_DEBUG, "AAATransceiver::sendAcctStop");    buildThePayload(aaaEvent, RP_ACCOUNTING_REQUEST, RAS_STOP);    mySendFifo.add(aaaEvent);}voidAAATransceiver::fillAAAData(Sptr<AAAEvent> aEvent,                             Sptr<RadiusMessage> rMsg) const{    Sptr<BasicAAAData> aData = aEvent->getAuthAgent()->getAAAData();    //Set the user name, PUID    const string& uId = aData->getUserName();    RadiusData valUserName(uId.c_str(), uId.length());    RadiusAttribute attrUserName( RA_USER_NAME, valUserName );    rMsg->add( attrUserName );    if(rMsg->type() == RP_ACCESS_REQUEST)    {        Sptr<AuthData> authData;        authData.dynamicCast(aData);        const string& userPasswd = authData->getUserPasswd();        RadiusData valUserPassword( userPasswd.c_str() , userPasswd.length() );        RadiusAttribute attrUserPassword( RA_USER_PASSWORD, valUserPassword );        rMsg->add( attrUserPassword );    }    //NAS-IP    u_int32_t ip = inet_addr(aData->getIp().c_str());    RadiusData valNasIpAddress( &ip , sizeof(ip) );    RadiusAttribute attrNasIpAddress( RA_NAS_IP_ADDRESS, valNasIpAddress );    rMsg->add( attrNasIpAddress );    ///Fixed port for a given server- Arbitrarily choosen    u_int32_t port( htonl(1000));    RadiusData valNasPort( &port , sizeof(port) );    RadiusAttribute attrNasPort( RA_NAS_PORT, valNasPort );    rMsg->add( attrNasPort );    const string& calledId = aData->getCalledId();    RadiusData valCallee( calledId.c_str(), calledId.length());    RadiusAttribute attrCallee( RA_CALLED_STATION_ID, valCallee );    rMsg->add( attrCallee );    const string& callingId = aData->getCallingId();     RadiusData valCaller( callingId.c_str(),callingId.length());    RadiusAttribute attrCaller( RA_CALLING_STATION_ID, valCaller );    rMsg->add( attrCaller );}voidAAATransceiver::fillAccountStartData(Sptr<AAAEvent> aEvent,                                      Sptr<RadiusMessage> rMsg) const{    fillAAAData(aEvent, rMsg);    Sptr<BillingData> aData;    aData.dynamicCast(aEvent->getAuthAgent()->getAAAData());    assert(aData != 0);    u_int32_t acctType( htonl(RAS_START) );    RadiusData valAcctStatus( &acctType, sizeof(acctType) );    RadiusAttribute attrAcctStatus( RA_ACCT_STATUS_TYPE, valAcctStatus );    rMsg->add( attrAcctStatus );    const string& sId = aData->getSessionId();    RadiusData valAcctSessionId( sId.c_str(), sId.length() );    RadiusAttribute attrAcctSessionId( RA_ACCT_SESSION_ID, valAcctSessionId );    rMsg->add( attrAcctSessionId );}voidAAATransceiver::fillInterimAccountData(Sptr<AAAEvent> aEvent,                                   Sptr<RadiusMessage> rMsg) const{    fillAAAData(aEvent, rMsg);    Sptr<BillingData> aData;    aData.dynamicCast(aEvent->getAuthAgent()->getAAAData());    assert(aData != 0);    u_int32_t acctType = htonl(RAS_INTERIM);    RadiusData valAcctStatus2( &acctType, sizeof(acctType) );    RadiusAttribute attrAcctStatus2( RA_ACCT_STATUS_TYPE, valAcctStatus2 );    rMsg->add( attrAcctStatus2 );    const string& sId = aData->getSessionId();    RadiusData valAcctSessionId( sId.c_str(), sId.length() );    RadiusAttribute attrAcctSessionId( RA_ACCT_SESSION_ID, valAcctSessionId );    rMsg->add( attrAcctSessionId );    u_int32_t setupDelay( htonl(aData->getSetupDelay() ));    RadiusData valSetupDelay( &setupDelay, sizeof(setupDelay) );    RadiusAttribute attrSetupDelay( RA_ACCT_DELAY_TIME, valSetupDelay );    rMsg->add( attrSetupDelay );}voidAAATransceiver::fillAccountStopData(Sptr<AAAEvent> aEvent,                                      Sptr<RadiusMessage> rMsg) const{    fillAAAData(aEvent, rMsg);    Sptr<BillingData> aData;    aData.dynamicCast(aEvent->getAuthAgent()->getAAAData());    assert(aData != 0);    u_int32_t acctType( htonl(RAS_STOP) );    RadiusData valAcctStatus( &acctType, sizeof(acctType) );    RadiusAttribute attrAcctStatus( RA_ACCT_STATUS_TYPE, valAcctStatus );    rMsg->add( attrAcctStatus ) ;    const string& sId = aData->getSessionId();    RadiusData valAcctSessionId( sId.c_str(), sId.length() );    RadiusAttribute attrAcctSessionId( RA_ACCT_SESSION_ID, valAcctSessionId );    rMsg->add( attrAcctSessionId ) ;    u_int32_t duration( htonl(aData->getDuration()));    RadiusData valAcctSessionTime( &duration, sizeof(duration) );    RadiusAttribute attrAcctSessionTime( RA_ACCT_SESSION_TIME, valAcctSessionTime );    rMsg->add( attrAcctSessionTime );    u_int32_t cause;    if(aData->getTermCause() == BT_SESSION_TIMEOUT)    {         cause = ( htonl(RATC_SESSION_TIMEOUT) );    }    else    {        cause = ( htonl(RATC_USER_REQUEST) );    }        RadiusData valAcctTerminateCause( &cause, sizeof(cause) );    RadiusAttribute attrAcctTerminateCause( RA_ACCT_TERMINATE_CAUSE, valAcctTerminateCause );    rMsg->add( attrAcctTerminateCause );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -