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

📄 ospaudit.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 3 页
字号:
/**########################################################################*########################################################################*########################################################################*                                                               *   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.                                      *                                     *******#########################################################################*#########################################################################*#########################################################################*//* * ospaudit.c - OSP audit functions */#include "osp.h"#include "ospaudit.h"#include "ospconfig.h"#include "ospmime.h"#include "ospxml.h"#include "ospxmldoc.h"#include "osputils.h"/* copy message data into audit buffer */intOSPPAuditAddMessageToBuffer(    OSPTAUDIT       *ospvAudit,     unsigned char   *ospvAuditData,    unsigned        ospvAuditDataSz){    int             errorcode       = OSPC_ERR_NO_ERROR;    unsigned        numbyteswritten = 0;    unsigned char   *dataptr        = ospvAuditData;    unsigned char   *endptr         = OSPC_OSNULL;    unsigned char   *begptr         = OSPC_OSNULL;    OSPTCOMPONENTID *compid         = OSPC_OSNULL;    if((ospvAudit != OSPC_OSNULL) && (dataptr != OSPC_OSNULL) && (ospvAuditDataSz > 0))    {        /* Clean buffer up */        if(OSPM_STRSTR((const char *)dataptr, OSPC_AUDIT_XML_HEADER) != OSPC_OSNULL)        {            dataptr += OSPC_AUDIT_XML_HDR_LEN;            ospvAuditDataSz -= OSPC_AUDIT_XML_HDR_LEN;        }        if(OSPM_STRSTR((const char *)dataptr, OSPC_AUDIT_MSG_HEADER) != OSPC_OSNULL)        {            dataptr += OSPC_AUDIT_MSG_HDR_LEN;            ospvAuditDataSz -= OSPC_AUDIT_MSG_HDR_LEN;                        }        if((endptr = (unsigned char *)OSPM_STRSTR((const char *)dataptr, "<")) != OSPC_OSNULL)        {            ospvAuditDataSz -= (endptr - dataptr);            dataptr = endptr;        }        if((endptr = (unsigned char *)OSPM_STRSTR((const char *)dataptr, OSPC_AUDIT_BFR_END)) != OSPC_OSNULL)        {            ospvAuditDataSz -= (OSPC_AUDIT_BFR_END_LEN + 1);        }        /* get access to buffer */        OSPM_MUTEX_LOCK(ospvAudit->ospmAuditAccessMutex, errorcode);        if(errorcode == OSPC_ERR_NO_ERROR)        {            if(((ospvAudit->ospmAuditUsedSpace + ospvAuditDataSz) <=                                                ospvAudit->ospmAuditMaxSpace) &&                ((ospvAudit->ospmAuditNumMessages + 1) <= ospvAudit->ospmAuditMaxMessages))            {                if(errorcode == OSPC_ERR_NO_ERROR)                {                    /* add data to buffer */                    numbyteswritten = OSPPBfrWriteBlock(&(ospvAudit->ospmAuditStorage),                                                        dataptr, ospvAuditDataSz);                    /* increment used space */                    OSPPAuditIncrementUsedSpace(ospvAudit, numbyteswritten);                    /* increment nummessages */                    ospvAudit->ospmAuditNumMessages++;                    /* Find componentId and save it */                    if((endptr = (unsigned char *)OSPM_STRSTR((const char *)dataptr, "componentId")) != OSPC_OSNULL)                    {                        if((endptr = (unsigned char *)OSPM_STRSTR((const char *)endptr, "=")) != OSPC_OSNULL)                        {                            begptr = endptr+1;                            while(!isalnum(*begptr) && ispunct(*begptr))                                begptr++;                            if((endptr = (unsigned char *)OSPM_STRSTR((const char *)begptr, "\"")) != OSPC_OSNULL)                            {                                compid = OSPPAuditComponentIdNew(begptr, (endptr -begptr));                                if(compid != OSPC_OSNULL)                                {                                    OSPPListAppend(&(ospvAudit)->ospmAuditComponentIdList,                                                     compid);                                }                            }                        }                    }                }            }            else            {                /* signal worker thread to flush buffer */                OSPM_MUTEX_LOCK(ospvAudit->ospmAuditWorkerMutex, errorcode);                if(errorcode == OSPC_ERR_NO_ERROR)                {                    /* signal condvar to send data */                    ospvAudit->ospmAuditFlags |= OSPC_AUDIT_FLUSH_BUFFER_NOW;                    OSPM_CONDVAR_SIGNAL(ospvAudit->ospmAuditWorkerCondVar, errorcode);                    OSPM_MUTEX_UNLOCK(ospvAudit->ospmAuditWorkerMutex, errorcode);                }            }            /* release mutex */            OSPM_MUTEX_UNLOCK(ospvAudit->ospmAuditAccessMutex, errorcode);        }    }    return errorcode;}/* * check audit structure. If new data found, replace data in audit structure. * If state indicates some action, start that action. If some error occurs, just  * produce some debug. */void            OSPPAuditCheck(    OSPTAUDIT           *ospvAudit,    void                *ospvResponse,     OSPE_MSG_DATATYPES  ospvMsgType){    OSPTTNAUDIT     *tnaudit    = OSPC_OSNULL;    int             errorcode   = OSPC_ERR_NO_ERROR;    OSPTCSAUDIT     *csaudit    = OSPC_OSNULL;    unsigned char   *trigger    = OSPC_OSNULL;    if((ospvAudit != OSPC_OSNULL) && (ospvResponse != OSPC_OSNULL))    {        /* set up audit structure pointer */        switch(ospvMsgType)        {            case OSPC_MSG_ARESP:                if(((OSPTAUTHRSP *)ospvResponse)->ospmAuthRspTNAudit != OSPC_OSNULL)                {                    tnaudit = OSPPAuthRspGetTNAudit((OSPTAUTHRSP *)ospvResponse);                }                                if(((OSPTAUTHRSP *)ospvResponse)->ospmAuthRspCSAudit != OSPC_OSNULL)                {                    csaudit = OSPPAuthRspGetCSAudit((OSPTAUTHRSP *)ospvResponse);                }            break;            case OSPC_MSG_UCNF:                if(((OSPTUSAGECNF *)ospvResponse)->ospmUsageCnfTNAudit != OSPC_OSNULL)                {                    tnaudit = OSPPUsageCnfGetTNAudit((OSPTUSAGECNF *)ospvResponse);                }                if(((OSPTUSAGECNF *)ospvResponse)->ospmUsageCnfCSAudit != OSPC_OSNULL)                {                    csaudit = OSPPUsageCnfGetCSAudit((OSPTUSAGECNF *)ospvResponse);                }            break;            case OSPC_MSG_REARESP:                if(((OSPTREAUTHRSP *)ospvResponse)->ospmReauthRspTNAudit != OSPC_OSNULL)                {                    tnaudit = OSPPReauthRspGetTNAudit((OSPTREAUTHRSP *)ospvResponse);                }/*               if(((OSPTREAUTHRSP *)ospvResponse)->ospmReauthRspCSAudit != OSPC_OSNULL)                {                    csaudit = OSPPReauthRspGetCSAudit((OSPTREAUTHRSP *)ospvResponse);                }                */            break;            default:            break;        }        /* check data in structure so we know what to do */        if(tnaudit != OSPC_OSNULL)        {            if(OSPPTNAuditHasURL(tnaudit))            {                OSPPAuditSetURL(ospvAudit, (const char *)OSPPTNAuditGetURL(tnaudit));                OSPPCommSetAuditURL(ospvAudit->ospmAuditComm, (const char *)OSPPTNAuditGetURL(tnaudit));            }            if(OSPPTNAuditHasTimeLimit(tnaudit))            {                OSPPAuditSetMaxTime(ospvAudit, OSPPTNAuditGetTimeLimit(tnaudit));            }            if(OSPPTNAuditHasMaxMessages(tnaudit))            {                OSPPAuditSetMaxMessages(ospvAudit, OSPPTNAuditGetMaxMessages(tnaudit));            }            if(OSPPTNAuditHasState(tnaudit))            {                switch(OSPPTNAuditGetState(tnaudit))                {                    case OSPC_AUDIT_INIT:                        /* If already on, don't turn on again */                        if(!(ospvAudit->ospmAuditComm->Flags & OSPC_COMM_AUDIT_ON))                        {                            errorcode = OSPPAuditInit(ospvAudit);                            OSPPCommSetAuditFlag(ospvAudit->ospmAuditComm, OSPC_COMM_AUDIT_ON);                        }                    break;                    case OSPC_AUDIT_FLUSH_BUFFER:                        /* signal worker thread to flush buffer */                        OSPM_MUTEX_LOCK(ospvAudit->ospmAuditWorkerMutex, errorcode);                        if(errorcode == OSPC_ERR_NO_ERROR)                        {                            /* signal condvar to send data */                            ospvAudit->ospmAuditFlags |= OSPC_AUDIT_FLUSH_BUFFER_NOW;                            OSPM_CONDVAR_SIGNAL(ospvAudit->ospmAuditWorkerCondVar, errorcode);                            OSPM_MUTEX_UNLOCK(ospvAudit->ospmAuditWorkerMutex, errorcode);                        }                    break;                    default:                    break;                }            }        }        if(csaudit != OSPC_OSNULL)        {            if(OSPPCSAuditHasTrigger(csaudit))            {                trigger = OSPPCSAuditGetTrigger(csaudit);                if(OSPM_STRCMP((const char *)trigger, "stop") == 0)                {                    /* Unset auditing flag */                    OSPPCommSetAuditFlag(ospvAudit->ospmAuditComm, OSPC_COMM_AUDIT_OFF);                    /* Check for stuff in buffer */                    if(!(ospvAudit->ospmAuditFlags & OSPC_AUDIT_BUFFER_IS_EMPTY))                    {                        /* signal worker thread to flush buffer */                        OSPM_MUTEX_LOCK(ospvAudit->ospmAuditWorkerMutex, errorcode);                        if(errorcode == OSPC_ERR_NO_ERROR)                        {                            /* signal condvar to send data */                            ospvAudit->ospmAuditFlags |= OSPC_AUDIT_FLUSH_BUFFER_NOW;                            OSPM_CONDVAR_SIGNAL(ospvAudit->ospmAuditWorkerCondVar, errorcode);                            OSPM_MUTEX_UNLOCK(ospvAudit->ospmAuditWorkerMutex, errorcode);                        }                        }                }                else if(OSPM_STRCMP((const char *)trigger, "start") == 0)                {                    /* If already on, don't turn on again */                    if(!(ospvAudit->ospmAuditComm->Flags & OSPC_COMM_AUDIT_ON))                    {                        /* Make sure buffer is clear */                        if(ospvAudit->ospmAuditFlags & OSPC_AUDIT_BUFFER_IS_EMPTY)                        {                            errorcode = OSPPAuditInit(ospvAudit);                            OSPPCommSetAuditFlag(ospvAudit->ospmAuditComm, OSPC_COMM_AUDIT_ON);                        }                    }                }            }        }    }    return;}/* Delete component id list */voidOSPPAuditComponentIdDelete(    OSPTAUDIT   *ospvAudit){    OSPTCOMPONENTID *compid = OSPC_OSNULL;    if(ospvAudit != OSPC_OSNULL)    {        if(ospvAudit->ospmAuditComponentIdList != OSPC_OSNULL)        {            while(!OSPPListEmpty(&(ospvAudit->ospmAuditComponentIdList)))            {                compid = (OSPTCOMPONENTID *)OSPPListRemove(&(ospvAudit->ospmAuditComponentIdList));                if(compid->ospmComponentId != OSPC_OSNULL)                {                    OSPM_FREE(compid->ospmComponentId);                }                if(compid != OSPC_OSNULL)                {                    OSPM_FREE(compid);                }            }              OSPPListDelete(&(ospvAudit->ospmAuditComponentIdList));        }    }    return;}/* Create new component id item */OSPTCOMPONENTID *OSPPAuditComponentIdNew(    unsigned char *ospvComponentId,     int           ospvComponentIdLen){    OSPTCOMPONENTID *compid = OSPC_OSNULL;    if( ospvComponentId != OSPC_OSNULL)    {        OSPM_MALLOC(compid, OSPTCOMPONENTID, sizeof(OSPTCOMPONENTID));        if (compid != OSPC_OSNULL)        {            OSPPListLinkNew (&(compid->ospmComponentIdLink));            OSPM_MALLOC(compid->ospmComponentId, unsigned char, ospvComponentIdLen + 1);            OSPM_MEMSET(compid->ospmComponentId, 0, ospvComponentIdLen + 1);            OSPM_MEMCPY(compid->ospmComponentId, ospvComponentId, ospvComponentIdLen);        }    }    return compid;}/* delete audit object and all space allocated within it */intOSPPAuditDelete(    OSPTAUDIT	**ospvAudit){    int         errorcode = OSPC_ERR_NO_ERROR;    if(*ospvAudit != OSPC_OSNULL)    {                if((*ospvAudit)->ospmAuditStorage != OSPC_OSNULL)        {            OSPPBfrDelete(&((*ospvAudit)->ospmAuditStorage));        }        /* free url pointer */        if((*ospvAudit)->ospmAuditURL != OSPC_OSNULL)        {            OSPM_FREE((*ospvAudit)->ospmAuditURL);        }        /* destroy mutexes and conditional vars */        if((*ospvAudit)->ospmAuditAccessHasMutex)        {            OSPM_CONDVAR_DESTROY((*ospvAudit)->ospmAuditAccessCondVar, errorcode);            OSPM_MUTEX_DESTROY((*ospvAudit)->ospmAuditAccessMutex, errorcode);        }        if((*ospvAudit)->ospmAuditWorkerHasMutex)        {            OSPM_CONDVAR_DESTROY((*ospvAudit)->ospmAuditWorkerCondVar, errorcode);            OSPM_MUTEX_DESTROY((*ospvAudit)->ospmAuditWorkerMutex, errorcode);        }        /* Clean out componentId list */        OSPPAuditComponentIdDelete(*ospvAudit);        if(*ospvAudit != OSPC_OSNULL)        {            /* free audit block */            OSPM_FREE(*ospvAudit);        }    }    return errorcode;}/* Get buffer access conditional variable */OSPTCONDVAR OSPPAuditGetAccessCondVar(    OSPTAUDIT *ospvAudit){    OSPTCONDVAR condvar;    OSPM_MEMSET(&condvar, 0, sizeof(OSPTCONDVAR));    if(ospvAudit != OSPC_OSNULL)    {        return ospvAudit->ospmAuditAccessCondVar;    }    else    {        return condvar;    }}unsigned    OSPPAuditGetMaxMessages(    OSPTAUDIT *ospvAudit){    if(ospvAudit != OSPC_OSNULL)    {        return ospvAudit->ospmAuditMaxMessages;    }    else    {        return 0;    }}unsigned    OSPPAuditGetMaxSpace(    OSPTAUDIT *ospvAudit){    if(ospvAudit != OSPC_OSNULL)    {        return ospvAudit->ospmAuditMaxSpace;    }    else    {        return 0;    }}

⌨️ 快捷键说明

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