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

📄 osptrans.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 5 页
字号:
                else                {                    if (ospvSizeOfDestinationDevice < strlen((const char *)sigaddr)+1)                    {                        errorcode = OSPC_ERR_TRAN_NOT_ENOUGH_SPACE_FOR_COPY;                        OSPM_DBGERRORLOG(errorcode,                             "not enough space for device addr");                    }                    else                    {                        /*                         * Get the signal address (DestinationDevice)                          */                        OSPM_MEMCPY(ospvDestinationDevice,                             sigaddr,                            strlen((const char *)sigaddr)+1);                    }                }            }        }        if (errorcode == OSPC_ERR_NO_ERROR)        {            if (!OSPPDestHasToken(dest))            {                errorcode = OSPC_ERR_TRAN_TOKEN_INVALID;                OSPM_DBGERRORLOG(errorcode,                     "null pointer for token.");            }            else            {                token =(OSPTTOKEN *)OSPPDestFirstToken(dest);                if (token == (OSPTTOKEN *)OSPC_OSNULL)                {                    errorcode = OSPC_ERR_TRAN_TOKEN_INVALID;                    OSPM_DBGERRORLOG(errorcode,                         "null pointer for token.");                }                else                {                    if (*ospvSizeOfToken < (unsigned) OSPPTokenGetSize(token))                    {                        errorcode = OSPC_ERR_TRAN_NOT_ENOUGH_SPACE_FOR_COPY;                        OSPM_DBGERRORLOG(errorcode,                             "not enough space for token");                    }                    else                    {                        /*                         * Get the token                         */                        OSPM_MEMCPY(ospvToken,                             OSPPTokenGetValue(token),                            OSPPTokenGetSize(token));                    }                    *ospvSizeOfToken = OSPPTokenGetSize(token);                }            }        }    }    return errorcode;}/* * get new transaction handle. * * returns OSPC_ERR_NO_ERROR if successful, otherwise error code. */intOSPPTransactionGetNewContext(    OSPTPROVHANDLE      ospvProvider,       /* In - Provider handle */    OSPTTRANHANDLE      *ospvTransaction)   /* Out - Transaction handle */{    int                 errorcode    = OSPC_ERR_NO_ERROR;    unsigned char       transallowed = OSPC_FALSE;    OSPTPROVIDER        *prov        = OSPC_OSNULL;    OSPTTRANCOLLECTION  *trancoll    = OSPC_OSNULL;    prov = OSPPProviderGetContext(ospvProvider, &errorcode);    if (prov != (OSPTPROVIDER *)OSPC_OSNULL)     {        OSPPProviderGetNewTransactionAllowed(prov, &transallowed);        if (transallowed == OSPC_TRUE)         {            errorcode = OSPPProviderGetTransactionCollection(prov, &trancoll);            if (errorcode == OSPC_ERR_NO_ERROR)             {                OSPM_MUTEX_LOCK(trancoll->TransactionMutex,errorcode);                if (errorcode == OSPC_ERR_NO_ERROR)                {                    *ospvTransaction = OSPPTransactionCollectionGetNewItem(                    ospvProvider, trancoll, &errorcode);                    if (errorcode == OSPC_ERR_NO_ERROR)                        trancoll->NumberOfTrans++;                    OSPM_MUTEX_UNLOCK(trancoll->TransactionMutex,errorcode);                }            }        }        else         {            errorcode = OSPC_ERR_TRAN_TRANSACTION_NOT_ALLOWED;            OSPM_DBGERRORLOG(errorcode, "new transaction not allowed.");        }        if ((errorcode == OSPC_ERR_NO_ERROR) &&             (*ospvTransaction == OSPC_TRAN_HANDLE_INVALID))         {            errorcode = OSPC_ERR_TRAN_HANDLE_INVALID;            OSPM_DBGERRORLOG(errorcode, "new transaction handle not found.");        }    }    return errorcode;}voidOSPPTransactionGetReportUsageAllowed(    OSPTTRANS   *ospvTrans,     OSPTBOOL    *ospvReportUsageAllowed){    switch(ospvTrans->State)    {                case    OSPC_REPORT_USAGE_SUCCESS:        *ospvReportUsageAllowed = OSPC_FALSE;        break;        case    OSPC_TRANSNEW:        case    OSPC_AUTH_REQUEST_FAIL:        case    OSPC_AUTH_REQUEST_SUCCESS:        case    OSPC_GET_DEST_FAIL:        case    OSPC_REPORT_USAGE_BLOCK:        case    OSPC_VALIDATE_AUTH_FAIL:        case    OSPC_INITIALIZE_FAIL:        case    OSPC_REINITIALIZE_FAIL:        case    OSPC_AUTH_REQUEST_BLOCK:        case    OSPC_VALIDATE_AUTH_SUCCESS:        case    OSPC_GET_DEST_SUCCESS:        case    OSPC_REPORT_USAGE_FAIL:        case    OSPC_INITIALIZE_SUCCESS:        case    OSPC_REINITIALIZE_SUCCESS:        case    OSPC_ACCUMULATE_SUCCESS:        case    OSPC_ACCUMULATE_FAIL:        *ospvReportUsageAllowed = OSPC_TRUE;        break;        default:        /* unknown state */        *ospvReportUsageAllowed = OSPC_FALSE;    }}/* * get transaction state. * * returns void. */voidOSPPTransactionGetState(    OSPTTRANS               *ospvTrans,      /* In - Transaction pointer */    OSPE_TRANS_STATE        *ospvState      /* Out - State pointer */    ){    if (ospvTrans != (OSPTTRANS *)OSPC_OSNULL)    {        *ospvState =  ospvTrans->State;    }    return;}/* Get copy of stats from transaction.  */voidOSPPTransactionGetStatistics(    OSPTTRANS           *ospvTrans,     /* In- pointer to transaction */    OSPTSTATISTICS      *ospvStats      /* In - pointer to stats struct */){    if((ospvTrans != OSPC_OSNULL) && (ospvStats != OSPC_OSNULL))    {        if(OSPPTransactionHasStatistics(ospvTrans))        {            OSPM_MEMCPY(ospvStats,                 ospvTrans->TNStatistics,                 sizeof(OSPTSTATISTICS));        }    }    return;}/* Does transaction have statistics? */OSPTBOOL    OSPPTransactionHasStatistics(    OSPTTRANS *ospvTrans    ){    OSPTBOOL    hasstats = OSPC_FALSE;    if(ospvTrans != OSPC_OSNULL)    {        if(ospvTrans->TNStatistics != OSPC_OSNULL)        {            hasstats = OSPC_TRUE;           }    }    return hasstats;}/* * get message ready to go out and place on queue. * * If new transactions allowed for this Provider, create the SMIME signature,  * create the MIME multipart message, put into msginfo structure and place * msginfo structure on queue. * * returns OSPC_ERR_NO_ERROR if successful, otherwise error code. */intOSPPTransactionPrepareAndQueMessage(    OSPTTRANS      *ospvTrans,       /* In - Pointer to transaction structure */    unsigned char  *ospvXMLDoc,      /* In - Pointer to form data */    unsigned       ospvSizeOfXMLDoc, /* In - Size of form data */    OSPTMSGINFO    **ospvMsgInfo)    /* In - Pointer to msginfo structure */{    int             errorcode        = OSPC_ERR_NO_ERROR;    unsigned char   *signature       = OSPC_OSNULL;    unsigned        sizeofsignature  = 0;    unsigned char   *outgoingmessage = OSPC_OSNULL;    unsigned        sizeofoutmsg     = 0;    OSPTSEC         *security        = OSPC_OSNULL;    OSPTPROVIDER    *provider        = OSPC_OSNULL;    errorcode = OSPPTransactionGetProvider(ospvTrans, &provider);    if (errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPProviderGetSecurity(provider, &security);    }#ifdef ENABLESMIME    if (errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPSecSignatureCreate( security,             ospvXMLDoc, ospvSizeOfXMLDoc,             &signature, &sizeofsignature,            OSPC_SEC_SIGNATURE_ONLY);        if((errorcode == OSPC_ERR_NO_ERROR) && (signature == OSPC_OSNULL))        {            OSPM_MALLOC(signature,unsigned char,64);            if(signature!=OSPC_OSNULL)            {                OSPM_STRCPY((char *)signature,"Signature placeholder");                sizeofsignature=OSPM_STRLEN((char *)signature);            }            else            {                errorcode=OSPC_ERR_SEC_NO_MEMORY;            }        }    }#endif    if (errorcode == OSPC_ERR_NO_ERROR)    {        errorcode = OSPPMimeMessageCreate(            ospvXMLDoc, ospvSizeOfXMLDoc,            signature, sizeofsignature,             (unsigned char **)&outgoingmessage,             &sizeofoutmsg);        if(errorcode == OSPC_ERR_NO_ERROR)        {            if (*ospvMsgInfo != (OSPTMSGINFO *)OSPC_OSNULL)            {                /* set the content type depending on the presence                  * or absence of a signature                 */                if(signature != OSPC_OSNULL)                {                    OSPM_MALLOC((*ospvMsgInfo)->ContentType,                                  unsigned char,                                  strlen(OSPC_COMM_MULTI_MSG)+1);                    if((*ospvMsgInfo)->ContentType != OSPC_OSNULL)                    {                        OSPM_MEMSET((*ospvMsgInfo)->ContentType,                                     0,                                     strlen(OSPC_COMM_MULTI_MSG)+1);                        OSPM_MEMCPY((*ospvMsgInfo)->ContentType,                                     OSPC_COMM_MULTI_MSG,                                     strlen(OSPC_COMM_MULTI_MSG));                    }                }                else                {                    OSPM_MALLOC((*ospvMsgInfo)->ContentType,                                  unsigned char,                                  strlen(OSPC_COMM_TEXT_MSG)+1);                    if((*ospvMsgInfo)->ContentType != OSPC_OSNULL)                    {                        OSPM_MEMSET((*ospvMsgInfo)->ContentType,                                     0,                                     strlen(OSPC_COMM_TEXT_MSG)+1);                        OSPM_MEMCPY((*ospvMsgInfo)->ContentType,                                     OSPC_COMM_TEXT_MSG,                                     strlen(OSPC_COMM_TEXT_MSG));                    }                }            }            else            {                errorcode = OSPC_ERR_TRAN_INVALID_ENTRY;            }        }        else        {            fprintf(stderr, "Create Mime failed\n");        }        if (errorcode == OSPC_ERR_NO_ERROR)        {              OSPPMsgInfoAssignRequestMsg(*ospvMsgInfo,                outgoingmessage, sizeofoutmsg);            errorcode = OSPPCommAddTransaction(ospvTrans->Provider->Comm,                *ospvMsgInfo);            if (errorcode == OSPC_ERR_NO_ERROR)            {                errorcode = (*ospvMsgInfo)->ErrorCode;            }        }    }    if (signature != (unsigned char *)OSPC_OSNULL)    {        OSPM_FREE(signature);        signature = OSPC_OSNULL;    }    return errorcode;}/* * verifies signature and calls parser to retrieve data from returned message. * * Extract data and signature from MIME message, verify SMIME signature,  * parse data out of message. * * returns OSPC_ERR_NO_ERROR if successful, otherwise error code. */intOSPPTransactionProcessReturn(    OSPTTRANS         *ospvTrans,   /* In - Pointer to transaction */    OSPTMSGINFO       *ospvMsgInfo) /* In - Pointer to pointer to msginfo structure */{    int                errorcode          = OSPC_ERR_NO_ERROR;    unsigned char      *incomingmsg       = OSPC_OSNULL;    unsigned char      *incomingsignature = OSPC_OSNULL;    unsigned           sizeofmsg          = 0;    unsigned           sizeofsig          = 0;    void               *resultrsp         = OSPC_OSNULL;    OSPE_MSG_DATATYPES msgtype            = OSPC_MSG_LOWER_BOUND;    OSPTAUDIT          *audit             = OSPC_OSNULL;    OSPTUSAGECNF       *usagecnf          = OSPC_OSNULL;#ifdef ENABLESMIME    OSPTPROVIDER        *provider           = OSPC_OSNULL;    OSPTSEC             *security           = OSPC_OSNULL;#endif    if((ospvTrans == (OSPTTRANS *)OSPC_OSNULL) ||        (ospvMsgInfo == (OSPTMSGINFO *)OSPC_OSNULL))    {        errorcode = OSPC_ERR_TRAN_INVALID_ENTRY;        OSPM_DBGERRORLOG(errorcode, "invalid args");    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        audit = ospvTrans->Provider->Audit;        /*         * Parse the incoming message into its MIME components,         * XML doc and Signature         */        errorcode = OSPPMimeMessageParse(            ospvMsgInfo->ResponseMsg,             ospvMsgInfo->ResponseSz,            ospvMsgInfo->ContentType,             ospvMsgInfo->ContentSz,            &incomingmsg, &sizeofmsg,            &incomingsignature, &sizeofsig);    }#ifdef ENABLESMIME    /*     * Validate the S/MIME signature     */    if (errorcode == OSPC_ERR_NO_ERROR)

⌨️ 快捷键说明

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