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

📄 ospxmlenc.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 2 页
字号:
            if (ospvErrCode == OSPC_ERR_NO_ERROR)            {                ospvErrCode = OSPPXMLDocAddChar(ospvBfrAddr,                    OSPC_XMLDOC_TRAILER);            }            /* then the element name */            if (ospvErrCode == OSPC_ERR_NO_ERROR)            {                ospvErrCode = OSPPXMLDocAddElemName(ospvElem, ospvBfrAddr);            }            /* add the closing bracket */            if (ospvErrCode == OSPC_ERR_NO_ERROR)            {                ospvErrCode = OSPPXMLDocAddChar(ospvBfrAddr, OSPC_XMLDOC_CLOSE);                /* add newline for readability */                ospvErrCode = OSPPXMLDocAddChar(ospvBfrAddr, OSPC_XMLDOC_LF);            }        }    }    return (ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocAddElemName() - add an element name to a document *-----------------------------------------------------------------------*/int                                       /* returns error code */OSPPXMLDocAddElemName(    OSPTXMLELEM  *ospvElem,               /* element whose name to add */    OSPTBFR     **ospvBfrAddr             /* buffer to add to */){    int         ospvErrCode = OSPC_ERR_NO_ERROR;    unsigned    cnt;    const char  *name = OSPC_OSNULL;    unsigned    namelen;    if (ospvElem     == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;    }    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* get the name and its length */        name = OSPPXMLElemGetName(ospvElem);        namelen = OSPM_STRLEN(name);        /* actually write the name now */        cnt = OSPPBfrWriteBlock(ospvBfrAddr, (const void *)name, namelen);        /* finally, make sure that the name was added okay */        if (cnt == namelen)        {            ospvErrCode = OSPC_ERR_NO_ERROR;        }        else        {            ospvErrCode = OSPC_ERR_BUF_EMPTY;        }    }    return (ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocAddAttr() - add an attribute to a document *-----------------------------------------------------------------------*/int                                       /* returns error code */OSPPXMLDocAddAttr(    OSPTXMLATTR  *ospvAttr,               /* attribute to add */    OSPTBFR     **ospvBfrAddr             /* buffer to add to */){    int         ospvErrCode = OSPC_ERR_NO_ERROR;    const char  *val;    unsigned     vallen;    unsigned     cnt;    if (ospvAttr     == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_XML_NO_ATTR;    }    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* begin with the attribute name */        ospvErrCode = OSPPXMLDocAddAttrName(ospvAttr, ospvBfrAddr);    }    /* then the equals sign */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocAddChar(ospvBfrAddr, OSPC_XMLDOC_EQUALS);    }    /* and the quotation mark */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocAddChar(ospvBfrAddr, OSPC_XMLDOC_QUOTE);    }    /* the value itself */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* what is the value that we need to write? */        val = OSPPXMLAttrGetValue(ospvAttr);        if (val != OSPC_OSNULL)        {            vallen = OSPM_STRLEN(val);        }        else        {            vallen = 0;        }        /* make sure we've got something to actually write */        if (vallen > 0)        {            cnt = OSPPBfrWriteBlock(ospvBfrAddr, (const void *)val, vallen);            if (cnt != vallen)            {                /* if the write failed, note the error */                ospvErrCode = OSPC_ERR_BUF_EMPTY;            }        }    }    /* and the closing quotation mark */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocAddChar(ospvBfrAddr, OSPC_XMLDOC_QUOTE);    }    return (ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocAddAttrName() - add an attribute name to a document *-----------------------------------------------------------------------*/int                                  /* returns error code */OSPPXMLDocAddAttrName(    OSPTXMLATTR  *ospvAttr,               /* attribute whose name to add */    OSPTBFR     **ospvBfrAddr             /* buffer to add to */){    int         ospvErrCode = OSPC_ERR_NO_ERROR;    unsigned    cnt;    const char  *name = OSPC_OSNULL;    unsigned    namelen;    if (ospvAttr     == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_XML_NO_ATTR;    }    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /*         * First let's get the attribute tag and then use that to find the         * character name of the attribute.         */        /* get the name and its length */        name = OSPPXMLAttrGetName(ospvAttr);        /*        assert(name != OSPC_OSNULL); */        namelen = OSPM_STRLEN(name);        /* actually write the name */        cnt = OSPPBfrWriteBlock(ospvBfrAddr, (const void *)name, namelen);        /* make sure that the name was written okay */        if (cnt == namelen)        {            ospvErrCode = OSPC_ERR_NO_ERROR;        }        else        {            ospvErrCode = OSPC_ERR_BUF_EMPTY;        }    }    return (ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocAddChar() - add a single character to an XML document *-----------------------------------------------------------------------*/int                            /* returns error code */OSPPXMLDocAddChar(    OSPTBFR **ospvBfrAddr,     /* buffer in which to add */    char      ospvChar         /* character to add */){    int      ospvErrCode = OSPC_ERR_NO_ERROR;    unsigned cnt;    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /*         * This is really just a wrapper around the BFR function that         * writes a byte, but it does allow us to handle the error         * conditions in way that's consistent with the rest of the         * XML encoding routines.         */        cnt = OSPPBfrWriteByte(ospvBfrAddr, ospvChar);        if (cnt == 0)        {            ospvErrCode = OSPC_ERR_BUF_EMPTY;        }        else        {            ospvErrCode = OSPC_ERR_NO_ERROR;        }    }    return(ospvErrCode);}

⌨️ 快捷键说明

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