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

📄 osptrans.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 5 页
字号:
/**########################################################################*########################################################################*########################################################################*                                                               *   COPYRIGHT (c) 1998, 1999 by TransNexus, LLC                          * *   This software contains proprietary and confidential information  *   of TransNexus, LLC. Except as may be set forth in the license    *   agreement under which this software is supplied, use, disclosure, *   or reproduction is prohibited without the prior, express, written*   consent of TransNexus, LLC.                                      *                                     *******#########################################################################*#########################################################################*#########################################################################*//* * osptrans.cpp - Global functions for transaction object. */#include "osp.h"#include "osptrans.h"#include "ospprovider.h"#include "ospsecurity.h"#include "ospmime.h"#include "osputils.h"#include "ospmsgque.h"#include "ospmsginfo.h"#include "ospxml.h"#include "ospmsg.h"#include "ospcomm.h"#include "ospauthreq.h"#include "ospreauthreq.h"#include "ospauthcnf.h"#include "ospusagecnf.h"#include "ospfail.h"#include "ospaltinfo.h"/* Build a Reauthorisation Request and put in transaction */intOSPPTransactionBuildReauthRequest(    OSPTTRANS   *ospvTrans,    unsigned    ospvDuration){    int         errorcode   = OSPC_ERR_NO_ERROR;    OSPTTOKEN   *token      = OSPC_OSNULL,        *token1     = OSPC_OSNULL;    OSPTALTINFO *altinfo    = OSPC_OSNULL,        *altinfo2   = OSPC_OSNULL;    OSPTTIME    timestamp   = 0;    if(ospvTrans == OSPC_OSNULL)    {        errorcode = OSPC_ERR_TRAN_TRANSACTION_NOT_FOUND;    }    if(ospvTrans->ReauthReq == OSPC_OSNULL)    {        ospvTrans->ReauthReq = OSPPReauthReqNew();        if(ospvTrans->ReauthReq == OSPC_OSNULL)        {            errorcode = OSPC_ERR_TRAN_MALLOC_FAILED;        }    }    /* Set Role  = OSPC_SOURCE */    if(errorcode == OSPC_ERR_NO_ERROR)    {        /* Set Timestamp */        timestamp = time(NULL);        OSPPReauthReqSetTimestamp(ospvTrans->ReauthReq, timestamp);        OSPPReauthReqSetRole(ospvTrans->ReauthReq, OSPC_SOURCE);        /* Get Callid from trans->currdest->callid */        if(ospvTrans->CurrentDest != OSPC_OSNULL)        {            if(OSPPDestHasCallId(ospvTrans->CurrentDest))            {                OSPPReauthReqSetCallId(ospvTrans->ReauthReq,                     OSPPDestGetCallId(ospvTrans->CurrentDest));            }            else            {                errorcode = OSPC_ERR_TRAN_CALLID_NOT_FOUND;                OSPM_DBGERRORLOG(errorcode, "Callid not found");            }            if(errorcode == OSPC_ERR_NO_ERROR)            {                /* Get token from trans->currdest->token */                if(OSPPDestHasToken(ospvTrans->CurrentDest))                {                    /* add any tokens */                    for (token = (OSPTTOKEN *)OSPPDestFirstToken(ospvTrans->CurrentDest);                        (token != (OSPTTOKEN *)OSPC_OSNULL);                        token = (OSPTTOKEN *)OSPPDestNextToken(ospvTrans->CurrentDest, token))                    {                        token1 = OSPPTokenNew(token->ospmTokenLen, token->ospmTokenVal);                        if(token1 != OSPC_OSNULL)                        {                            OSPPReauthReqAddToken(ospvTrans->ReauthReq, token1);                        }                        token = OSPC_OSNULL;                        token1 = OSPC_OSNULL;                    }                }                else                {                    errorcode = OSPC_ERR_TRAN_TOKEN_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "Token not found");                }            }            if(errorcode == OSPC_ERR_NO_ERROR)            {                /* Get Duration for UsageDetail */                if(OSPPDestHasLimit(ospvTrans->CurrentDest))                {                    OSPPReauthReqSetDuration(ospvTrans->ReauthReq,                         ospvDuration);                }            }        }        else        {            errorcode = OSPC_ERR_TRAN_DEST_NOT_FOUND;        }    }    /* Get Calling number from trans->AuthReq->SourceNumber */    if(errorcode == OSPC_ERR_NO_ERROR)    {        if(ospvTrans->AuthReq != OSPC_OSNULL)        {            if(OSPPAuthReqHasSourceNumber(ospvTrans->AuthReq))            {                OSPPReauthReqSetSourceNumber(ospvTrans->ReauthReq,                     OSPPAuthReqGetSourceNumber(ospvTrans->AuthReq));            }            else            {                errorcode = OSPC_ERR_TRAN_SOURCE_NUMBER_NOT_FOUND;            }        }        else        {            errorcode = OSPC_ERR_TRAN_AUTH_REQ_NOT_FOUND;        }        if(errorcode == OSPC_ERR_NO_ERROR)        {            /* Get Called number from trans->AuthReq->DestinationNumber */            if(OSPPAuthReqHasDestNumber(ospvTrans->AuthReq))            {                OSPPReauthReqSetDestNumber(ospvTrans->ReauthReq,                     OSPPAuthReqGetDestNumber(ospvTrans->AuthReq));            }            else            {                errorcode = OSPC_ERR_TRAN_DEST_NUMBER_NOT_FOUND;            }        }        if(errorcode == OSPC_ERR_NO_ERROR)        {            /* Get SourceAlternates from trans->AuthReq->SourceAlternates */            if(OSPPAuthReqHasSourceAlt(ospvTrans->AuthReq))            {                for (altinfo = (OSPTALTINFO *)OSPPAuthReqFirstSourceAlt(ospvTrans->AuthReq);                    altinfo != (OSPTALTINFO *)OSPC_OSNULL;                    altinfo = (OSPTALTINFO *)OSPPAuthReqNextSourceAlt(ospvTrans->AuthReq, altinfo))                {                    altinfo2 = OSPPAltInfoNew(OSPPAltInfoGetSize(altinfo),                         OSPPAltInfoGetValue(altinfo),                         OSPPAltInfoGetType(altinfo));                    if(altinfo2 != OSPC_OSNULL)                    {                        OSPPReauthReqAddSourceAlt(ospvTrans->ReauthReq, altinfo2);                    }                    altinfo = OSPC_OSNULL;                    altinfo2 = OSPC_OSNULL;                }            }        }        if(errorcode == OSPC_ERR_NO_ERROR)        {            /* Get DestinationAlternates from trans->AuthReq->DestinationAlternates */            if(OSPPAuthReqHasDestinationAlt(ospvTrans->AuthReq))            {                for (altinfo = (OSPTALTINFO *)OSPPAuthReqFirstDestinationAlt(ospvTrans->AuthReq);                    altinfo != (OSPTALTINFO *)OSPC_OSNULL;                    altinfo = (OSPTALTINFO *)OSPPAuthReqNextDestinationAlt(ospvTrans->AuthReq, altinfo))                {                    altinfo2 = OSPPAltInfoNew(OSPPAltInfoGetSize(altinfo),                         OSPPAltInfoGetValue(altinfo),                         OSPPAltInfoGetType(altinfo));                    if(altinfo2 != OSPC_OSNULL)                    {                        OSPPReauthReqAddDestinationAlt(ospvTrans->ReauthReq, altinfo2);                    }                    altinfo = OSPC_OSNULL;                    altinfo2 = OSPC_OSNULL;                }            }        }    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        /* Get Transaction ID from trans->transactionID */        OSPPReauthReqSetTrxId(ospvTrans->ReauthReq, ospvTrans->TransactionID);    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        /* Get TNCustId from trans->provider->tncustid */        OSPPReauthReqSetTNCustId(ospvTrans->ReauthReq,             OSPPProviderGetTNCustId(ospvTrans->Provider));        /* Get TNDeviceID from trans->provider->tndeviceid */        OSPPReauthReqSetTNDeviceId(ospvTrans->ReauthReq,             OSPPProviderGetTNDeviceId(ospvTrans->Provider));    }    return errorcode;}/* Build a Usage Indication list */intOSPPTransactionBuildUsage(    OSPTTRANS           *ospvTrans, /* In - Pointer to transaction context */    OSPTUSAGEIND        **ospvUsage,/* In - Pointer to usage to be initialized*/    OSPTDEST            *ospvDest,  /* In - Pointer to dest associated w/usage*/    OSPE_MSG_DATATYPES  ospvType    /* In - Indicates what usage to build */    ){    int             errorcode   = OSPC_ERR_NO_ERROR;    unsigned char   *dest       = OSPC_OSNULL;    OSPTALTINFO     *altinfo    = OSPC_OSNULL;    *ospvUsage = OSPPUsageIndNew();    if(*ospvUsage != OSPC_OSNULL)    {        if(ospvType == OSPC_MSG_ARESP)        {            /* Originating */            OSPPUsageIndSetRole(*ospvUsage, OSPC_SOURCE);            /* Get CallId */            if(OSPPDestHasCallId(ospvDest))            {                OSPPUsageIndSetCallId(*ospvUsage,                     OSPPDestGetCallId(ospvDest));            }            else            {                errorcode = OSPC_ERR_TRAN_CALLID_NOT_FOUND;                OSPM_DBGERRORLOG(errorcode, "Callid not found");            }            if(errorcode == OSPC_ERR_NO_ERROR)            {                /* Get Source Number (Calling) */                if(OSPPAuthReqHasSourceNumber(ospvTrans->AuthReq))                {                    OSPPUsageIndSetSourceNumber(*ospvUsage,                         OSPPAuthReqGetSourceNumber(ospvTrans->AuthReq));                }                else                {                    errorcode = OSPC_ERR_TRAN_SOURCE_NUMBER_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "Source number not found");                }            }            /* Get Source Alternates (copying a pointer) */                if ((errorcode == OSPC_ERR_NO_ERROR) &&                 OSPPAuthReqHasSourceAlt(ospvTrans->AuthReq))            {                OSPPUsageIndCopySourceAlt(*ospvUsage,                     &((*ospvTrans->AuthReq).ospmAuthReqSourceAlternate));            }            /* Get Destination Number (Called) */            if(errorcode == OSPC_ERR_NO_ERROR)            {                if(OSPPAuthReqHasDestNumber(ospvTrans->AuthReq))                {                    OSPPUsageIndSetDestNumber(*ospvUsage,                         OSPPAuthReqGetDestNumber(ospvTrans->AuthReq));                }                else                {                    errorcode = OSPC_ERR_TRAN_DEST_NUMBER_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "Dest number not found");                }            }            /* add DestinationSignalAddress to DestinationAlternates for Usage */            if ((errorcode == OSPC_ERR_NO_ERROR) &&                OSPPDestHasAddr(ospvDest))            {                dest = OSPPDestGetAddr(ospvDest);                altinfo = OSPPAltInfoNew(strlen((const char *)dest),dest,ospeTransport);                OSPPUsageIndAddDestinationAlt(*ospvUsage, altinfo);                altinfo = OSPC_OSNULL;            }            /* Get Destination Alternates */            if ((errorcode == OSPC_ERR_NO_ERROR) &&                 OSPPAuthReqHasDestinationAlt(ospvTrans->AuthReq))            {                OSPPUsageIndMoveDestinationAlt(*ospvUsage,                     &(ospvTrans->AuthReq->ospmAuthReqDestinationAlternate));            /* Function above may be patterned after OSPPUsageIndMoveDestinationAlt */            }        }        else if(ospvType == OSPC_MSG_AIND)        {            /* Terminating */            OSPPUsageIndSetRole(*ospvUsage, OSPC_DESTINATION);            /* Get CallId */            if(OSPPAuthIndHasCallId(ospvTrans->AuthInd))            {                OSPPUsageIndSetCallId(*ospvUsage,                     OSPPAuthIndGetCallId(ospvTrans->AuthInd));            }            else            {                errorcode = OSPC_ERR_TRAN_CALLID_NOT_FOUND;                OSPM_DBGERRORLOG(errorcode, "Callid not found");            }            /* Source Number (Calling)*/            if(errorcode == OSPC_ERR_NO_ERROR)            {                if(OSPPAuthIndHasSourceNumber(ospvTrans->AuthInd))                {                    OSPPUsageIndSetSourceNumber(*ospvUsage,                         OSPPAuthIndGetSourceNumber(ospvTrans->AuthInd));                }                else                {                    errorcode = OSPC_ERR_TRAN_SOURCE_NUMBER_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "Source number not found");                }            }            /* Get Source Alternates */            if ((errorcode == OSPC_ERR_NO_ERROR) &&                 OSPPAuthIndHasSourceAlt(ospvTrans->AuthInd))            {                OSPPUsageIndMoveSourceAlt(*ospvUsage,                     &(ospvTrans->AuthInd->ospmAuthIndSourceAlternate));            }            /* Destination Number (CALLED) */            if(errorcode == OSPC_ERR_NO_ERROR)            {                if(OSPPAuthIndHasDestNumber(ospvTrans->AuthInd))                {                    OSPPUsageIndSetDestNumber(*ospvUsage,                         OSPPAuthIndGetDestNumber(ospvTrans->AuthInd));                }                else                {                    errorcode = OSPC_ERR_TRAN_DEST_NUMBER_NOT_FOUND;                    OSPM_DBGERRORLOG(errorcode, "Dest number not found");                }            }            /* Get Destination Alternates */            if ((errorcode == OSPC_ERR_NO_ERROR) &&                 OSPPAuthIndHasDestinationAlt(ospvTrans->AuthInd))            {                OSPPUsageIndMoveDestinationAlt(*ospvUsage,                     &(ospvTrans->AuthInd->ospmAuthIndDestinationAlternate));

⌨️ 快捷键说明

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