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

📄 ospauthrsp.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 2 页
字号:
OSPPAuthRspDelete(OSPTAUTHRSP **ospvAuthRsp){    OSPTDEST *dest  = OSPC_OSNULL;    if (*ospvAuthRsp != OSPC_OSNULL)    {        /* first remove the status */        if ((*ospvAuthRsp)->ospmAuthRspStatus != OSPC_OSNULL)        {            OSPPStatusDelete(&((*ospvAuthRsp)->ospmAuthRspStatus));        }        /* remove tnaudit */        if ((*ospvAuthRsp)->ospmAuthRspTNAudit != OSPC_OSNULL)        {            OSPPTNAuditDelete(&((*ospvAuthRsp)->ospmAuthRspTNAudit));        }        /* remove csaudit */        if ((*ospvAuthRsp)->ospmAuthRspCSAudit != OSPC_OSNULL)        {            OSPPCSAuditDelete(&((*ospvAuthRsp)->ospmAuthRspCSAudit));        }        /* remove messageId */        if(OSPPAuthRspHasMessageId(*ospvAuthRsp))        {            OSPM_FREE((*ospvAuthRsp)->ospmAuthRspMessageId);            (*ospvAuthRsp)->ospmAuthRspMessageId = OSPC_OSNULL;        }        /* remove componentId */        if(OSPPAuthRspHasComponentId(*ospvAuthRsp))        {            OSPM_FREE((*ospvAuthRsp)->ospmAuthRspComponentId);            (*ospvAuthRsp)->ospmAuthRspComponentId = OSPC_OSNULL;        }        /* now remove any attached dests -- this means following the chain */        while (!OSPPListEmpty(&((*ospvAuthRsp)->ospmAuthRspDest)))        {            dest = (OSPTDEST *)OSPPListRemove(&((*ospvAuthRsp)->ospmAuthRspDest));            if (dest != OSPC_OSNULL)            {                OSPPDestDelete(&dest);                dest = OSPC_OSNULL;            }        }        /* now delete the authrsp itself */        OSPM_FREE(*ospvAuthRsp);        *ospvAuthRsp = OSPC_OSNULL;    }}/**//*-----------------------------------------------------------------------* * OSPPAuthRspAddDest() - add a destination to authrsp. If ospvDest is NULL, * adds a new, empty destination. * Returns: pointer to added dest for manipulation *-----------------------------------------------------------------------*/OSPTDEST *                                /* returns ptr to new destination */    OSPPAuthRspAddDest(    OSPTAUTHRSP *ospvAuthRsp,    OSPTDEST *ospvDest    ){    OSPTDEST *ospvAddedDest = OSPC_OSNULL;    if (ospvAuthRsp != OSPC_OSNULL)     {        /* if this is called with a null destination, create a new         * empty destination and add it to the list.         */        if (ospvDest == OSPC_OSNULL)         {            ospvAddedDest = OSPPDestNew();        }        else        {            ospvAddedDest = ospvDest;        }        if (ospvAddedDest != OSPC_OSNULL)        {            /*             OSPM_MEMCPY(ospvAddedDest, ospvDest, sizeof(OSPTDEST));             ospvAddedDest->ospmDestCallId =              OSPPCallIdNew(                 OSPPCallIdGetSize(ospvDest->ospmDestCallId),                 OSPPCallIdGetValue(ospvDest->ospmDestCallId));            */            OSPPListAppend(&(ospvAuthRsp->ospmAuthRspDest), ospvAddedDest);        }    }    return(ospvAddedDest);}/**//*-----------------------------------------------------------------------* * OSPPAuthRspFromElement() - get authorisation response from an XML element *-----------------------------------------------------------------------*/unsigned                          /* returns error code */OSPPAuthRspFromElement(    OSPTXMLELEM *ospvElem,        /* input is XML element */    OSPTAUTHRSP   **ospvAuthRsp   /* where to put authorisation response pointer */){    unsigned      ospvErrCode   = OSPC_ERR_NO_ERROR;    OSPTXMLELEM  *elem          = OSPC_OSNULL;    OSPTAUTHRSP  *authrsp       = OSPC_OSNULL;    OSPTDEST     *dest          = OSPC_OSNULL;    OSPTTIME      t             = 0L;    OSPTTRXID     transid       = 0L;    int           len           = 0;    unsigned long delaylimit    = 0L;    unsigned long delaypref     = 0L;    unsigned char *compid       = OSPC_OSNULL;    OSPTXMLELEM   *ospvParent   = OSPC_OSNULL;    unsigned char *messageId    = OSPC_OSNULL;    if (ospvElem == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* create the authorisation response object */        authrsp = OSPPAuthRspNew();        if (authrsp == OSPC_OSNULL)        {            ospvErrCode = OSPC_ERR_DATA_NO_AUTHRSP;        }        else        {            if (OSPPMsgGetElemPart(OSPPXMLElemGetName(ospvElem))==ospeElemMessage)            {                OSPPAuthRspMessageIdFromElement(ospvElem, &messageId);                if(messageId != OSPC_OSNULL)                {                    OSPPAuthRspSetMessageId(authrsp, messageId);                }                /* ospvElem is pointing to the Message element.                  * The first child contains the Component element.                  * The following two lines of code change ospvElem from                  * pointing to the Message element to the Component element.                 */                ospvParent = ospvElem;                ospvElem = (OSPTXMLELEM *)OSPPXMLElemFirstChild(ospvParent);            }            OSPPAuthRspComponentIdFromElement(ospvElem, &compid);            if(compid != OSPC_OSNULL)            {                OSPPAuthRspSetComponentId(authrsp, compid);            }        }        /*         * The Authorisation Rsp element should consist of several         * child elements. We'll run through what's there and pick out         * the information we need.         */        for (elem = (OSPTXMLELEM *)OSPPXMLElemFirstChild(ospvElem);            (elem != (OSPTXMLELEM *)OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR);            elem = (OSPTXMLELEM *)OSPPXMLElemNextChild(ospvElem, elem))        {            switch (OSPPMsgGetElemPart(OSPPXMLElemGetName(elem)))            {                case ospeElemMessage:                    OSPPAuthRspMessageIdFromElement(elem, &messageId);                    if(messageId != OSPC_OSNULL)                    {                        OSPPAuthRspSetMessageId(authrsp, messageId);                    }                break;                /*                ** ospeElemAuthRzp -- OSP Stds spell Authorization not Authorisation                */                case ospeElemAuthRzp:                case ospeElemAuthRsp:                    OSPPAuthRspComponentIdFromElement(elem, &compid);                    if(compid != OSPC_OSNULL)                    {                        OSPPAuthRspSetComponentId(authrsp, compid);                    }                break;                case ospeElemTimestamp:                ospvErrCode = OSPPMsgTimeFromElement(elem, &t);                if (ospvErrCode == OSPC_ERR_NO_ERROR)                {                    OSPPAuthRspSetTimestamp(authrsp,t);                }                break;                case ospeElemStatus:                if (authrsp->ospmAuthRspStatus != OSPC_OSNULL)                {                    OSPPStatusDelete(&(authrsp->ospmAuthRspStatus));                }                ospvErrCode = OSPPStatusFromElement(elem, &(authrsp->ospmAuthRspStatus));                break;                case ospeElemTransId:                len = sizeof(OSPTTRXID);                ospvErrCode = OSPPMsgTXFromElement(elem, &transid);                OSPPAuthRspSetTrxId(authrsp, transid);                break;                case ospeElemTNDelayLimit:                ospvErrCode = OSPPMsgNumFromElement(elem, &delaylimit);                OSPPAuthRspSetTNDelayLimit(authrsp, (unsigned)delaylimit);                break;                case ospeElemTNAudit:                ospvErrCode = OSPPTNAuditFromElement(elem, &(authrsp->ospmAuthRspTNAudit));                break;                case ospeElemCSAuditTrigger:                    ospvErrCode = OSPPCSAuditFromElement(elem, &(authrsp->ospmAuthRspCSAudit));                break;                case ospeElemTNDelayPref:                ospvErrCode = OSPPMsgNumFromElement(elem, &delaypref);                OSPPAuthRspSetTNDelayPref(authrsp, (unsigned)delaypref);                break;                case ospeElemDest:                ospvErrCode = OSPPDestFromElement(elem, &dest);                if (ospvErrCode == OSPC_ERR_NO_ERROR)                {                    if(dest != OSPC_OSNULL)                    {                        OSPPAuthRspAddDest(authrsp,dest);                        OSPPAuthRspIncNumDests(authrsp);                        dest = OSPC_OSNULL;                    }                }                break;                default:                /*                   * This is an element we don't understand. If it's                   * critical, then we have to report an error.                   * Otherwise we can ignore it.                       */                if (OSPPMsgElemIsCritical(elem))                {                    ospvErrCode = OSPC_ERR_XML_BAD_ELEMENT;                }                break;            }        }        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            *ospvAuthRsp = authrsp;        }    }    return(ospvErrCode);}OSPTCSAUDIT *OSPPAuthRspGetCSAudit(    OSPTAUTHRSP *ospvAuthRsp){    if(ospvAuthRsp != OSPC_OSNULL)    {        if(ospvAuthRsp->ospmAuthRspCSAudit != OSPC_OSNULL)        {            return ospvAuthRsp->ospmAuthRspCSAudit;        }    }    return (OSPTCSAUDIT *)OSPC_OSNULL;}int        OSPPAuthRspHasCSAudit(    OSPTAUTHRSP *ospvAuthRsp){    return ospvAuthRsp->ospmAuthRspCSAudit != (OSPTCSAUDIT *)OSPC_OSNULL;}/*-----------------------------------------------------------------------* * OSPPAuthRspHasMessageId() - is the message id set ? *-----------------------------------------------------------------------*/unsigned                   /* returns non-zero if message id is set */OSPPAuthRspHasMessageId(    OSPTAUTHRSP *ospvAuthRsp){  return (ospvAuthRsp->ospmAuthRspMessageId != OSPC_OSNULL);}/*-----------------------------------------------------------------------* * OSPPAuthRspSetMessageId() - creates space and copies in the string. *-----------------------------------------------------------------------*/void      OSPPAuthRspSetMessageId(    OSPTAUTHRSP  *ospvAuthRsp,    /* In - pointer to Usage Indication struct */    unsigned char *ospvMessageId  /* In - pointer to message id string */    ){    int len = OSPM_STRLEN((const char *)ospvMessageId);    if(ospvAuthRsp != OSPC_OSNULL)    {        if(ospvAuthRsp->ospmAuthRspMessageId != OSPC_OSNULL)        {            OSPM_FREE(ospvAuthRsp->ospmAuthRspMessageId);            }        OSPM_MALLOC(ospvAuthRsp->ospmAuthRspMessageId, unsigned char, len + 1);        OSPM_MEMSET(ospvAuthRsp->ospmAuthRspMessageId, 0, len + 1);        OSPM_MEMCPY(ospvAuthRsp->ospmAuthRspMessageId, ospvMessageId, len);    }    return;}/* -----------------------------------------------------------------------------* * OSPPAuthRspMessageIdFromElement() - Get message id attribute from element. * -----------------------------------------------------------------------------*/void   OSPPAuthRspMessageIdFromElement(    OSPTXMLELEM *ospvElemIn,     unsigned char **ospvMessageId){    OSPTXMLATTR *attr = (OSPTXMLATTR *)OSPC_OSNULL;    /* look for the message id attribute */    for (attr = (OSPTXMLATTR *)OSPPXMLElemFirstAttr(ospvElemIn);        (attr != (OSPTXMLATTR *)OSPC_OSNULL);        attr = (OSPTXMLATTR *)OSPPXMLElemNextAttr(ospvElemIn, attr))    {        if (OSPPMsgGetAttrPart(OSPPXMLAttrGetName(attr)) == ospeAttrMessageId)        {            /* we found the message attribute. Get the value */            *ospvMessageId = (unsigned char *)OSPPXMLAttrGetValue(attr);            break;        }    }}/* -----------------------------------------------------------------------------* * OSPPAuthRspComponentIdFromElement() - Get component id attribute from element. * -----------------------------------------------------------------------------*/void   OSPPAuthRspComponentIdFromElement(    OSPTXMLELEM *ospvElemIn,     unsigned char **ospvComponentId){    OSPTXMLATTR *attr = (OSPTXMLATTR *)OSPC_OSNULL;    /* look for the component id attribute */    for (attr = (OSPTXMLATTR *)OSPPXMLElemFirstAttr(ospvElemIn);        (attr != (OSPTXMLATTR *)OSPC_OSNULL);        attr = (OSPTXMLATTR *)OSPPXMLElemNextAttr(ospvElemIn, attr))    {        if (OSPPMsgGetAttrPart(OSPPXMLAttrGetName(attr)) == ospeAttrComponentId)        {            /* we found the component attribute. Get the value */            *ospvComponentId = (unsigned char *)OSPPXMLAttrGetValue(attr);            break;        }    }}

⌨️ 快捷键说明

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