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

📄 ospxmlparse.c

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 C
📖 第 1 页 / 共 5 页
字号:
    {        ospvErrCode = OSPC_ERR_XML_INVALID_ARGS;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* the first character in a name has special restrictions */        ospvErrCode = OSPPXMLDocReadChar(ospvBfrAddr, ospvEncoding, &readChar);    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        if (!OSPPXMLIsName1(readChar))        {            ospvErrCode = OSPC_ERR_XML_BAD_NAME;        }    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        cnt = OSPPBfrWriteByte(ospvNameBfr, readChar);        if (cnt != 1)        {            ospvErrCode = OSPC_ERR_BUF_EMPTY;        }    }    /* now we can fall into a loop gathering the remaining characters */    while (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /*         * First let's get a peek at the next character in the document.         * We don't want to read it yet because it may not be part of         * the name.         */        OSPPXMLDocPeekCharN(ospvBfrAddr, ospvEncoding, 0,            &readChar, (int *)&ospvErrCode);        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            if (!OSPPXMLIsName(readChar))            {                /*                 * Indeed, the next character isn't a valid name                 * character, so we're done. Before we leave, though,                 * add the terminating NULL to the name buffer.                 */                cnt = OSPPBfrWriteByte(ospvNameBfr, '\0');                if (cnt != 1)                {                    ospvErrCode = OSPC_ERR_BUF_EMPTY;                }                break;            }            /* the character is legitimate, go ahead and read it */            ospvErrCode = OSPPXMLDocReadChar(ospvBfrAddr, ospvEncoding,                &readChar);            if (ospvErrCode == OSPC_ERR_NO_ERROR)            {                /* just a sanity check here */                /*                assert(OSPPXMLIsName(readChar)); */                /* put the character into the name buffer */                cnt = OSPPBfrWriteByte(ospvNameBfr, readChar);                if (cnt != 1)                {                    ospvErrCode = OSPC_ERR_BUF_EMPTY;                }            }        }    }    return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocSkipProlog() - skip the XML prolog *-----------------------------------------------------------------------*/unsigned                          /* returns error code */OSPPXMLDocSkipProlog(    OSPTBFR    **ospvBfrAddr,     /* buffer containing document */    OSPTXMLENC   ospvEncoding     /* character encoding for the document */){    unsigned ospvErrCode = OSPC_ERR_NO_ERROR;    /*     * An XML prolog consists of the XML declaration, following by zero     * or more miscellaneous items (comments or processing instructions),     * followed by zero or one document type definitions, and then     * followed by zero or more miscellaneous items.     */    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvEncoding == ospeXMLEncUnknown)    {        ospvErrCode = OSPC_ERR_XML_BAD_ENC;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* skip the XML declaration, if present */        ospvErrCode = OSPPXMLDocSkipDecl(ospvBfrAddr, ospvEncoding);    }    /* skip any misc items (comments or PIs) in the prolog */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocSkipAllMisc(ospvBfrAddr, ospvEncoding);    }    /* skip a document type declaration */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocSkipDTD(ospvBfrAddr, ospvEncoding);    }    /* skip any final misc items (comments or PIs) in the prolog */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocSkipAllMisc(ospvBfrAddr, ospvEncoding);    }    return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocSkipAllMisc() - skip miscellaneous components in prolog *-----------------------------------------------------------------------*/unsigned                          /* returns error code */OSPPXMLDocSkipAllMisc(    OSPTBFR    **ospvBfrAddr,     /* buffer containing document */    OSPTXMLENC   ospvEncoding     /* character encoding for the document */){    unsigned   ospvErrCode = OSPC_ERR_NO_ERROR;    unsigned   isComment = OSPC_FALSE;    unsigned   isPI = OSPC_FALSE;    /*     * Miscellaneous items can be either comments or processing instructions     * (or whitespace). Since this function skips ALL misc items, we loop     * looking for either of the two (and skipping over whitespace in the     * process). If we find one, we skip it.     */    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvEncoding == ospeXMLEncUnknown)    {        ospvErrCode = OSPC_ERR_XML_BAD_ENC;    }    /* now go into the loop looking for and skipping misc items */    while (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* first take care of any whitespace */        ospvErrCode = OSPPXMLDocSkipWhite(ospvBfrAddr, ospvEncoding);        /* Misc can be either comments ... */        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsComment(ospvBfrAddr, ospvEncoding,                &isComment);        }        /* ... or processing instructions */        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsPI(ospvBfrAddr, ospvEncoding,                &isPI);        }        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            if (isComment)            {                ospvErrCode = OSPPXMLDocSkipComment(ospvBfrAddr,                    ospvEncoding);            }            else if (isPI)            {                ospvErrCode = OSPPXMLDocSkipPI(ospvBfrAddr, ospvEncoding);            }            else            {                /*                 * If we didn't find a comment or PI, then we're done,                 * so break from the loop                 */                break;            }        }    }    return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocSkipDTD() - skip document type definition (if present) *-----------------------------------------------------------------------*/unsigned                          /* returns error code */OSPPXMLDocSkipDTD(    OSPTBFR    **ospvBfrAddr,     /* buffer containing document */    OSPTXMLENC   ospvEncoding     /* character encoding for the document */){    unsigned            ospvErrCode = OSPC_ERR_NO_ERROR;    unsigned char       readChar = '\0';    unsigned            isDTD = OSPC_FALSE;    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvEncoding == ospeXMLEncUnknown)    {        ospvErrCode = OSPC_ERR_XML_BAD_ENC;    }    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* skip any whitespace */        ospvErrCode = OSPPXMLDocSkipWhite(ospvBfrAddr, ospvEncoding);    }    /*     * The first thing we do is look for the beginning of a DTD     * declaration. If there's not one, we don't have any work to do.     */    if (ospvErrCode == OSPC_ERR_NO_ERROR)    {        ospvErrCode = OSPPXMLDocIsDTD(ospvBfrAddr, ospvEncoding, &isDTD);    }    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && isDTD)    {        /*         * We've got a match for the DTD tag, so we go into a loop         * that skips over all the stuff that could be stuck inside         * a DTD (unfortunately, that's a lot of stuff.         */        while (ospvErrCode == OSPC_ERR_NO_ERROR)        {            /*             * Either one of two things will happen now. If             * things are easy, we'll find the ending tag ('>')             * that marks the end of the DTD. If that happens,             * we're done. A more complicated possibility,             * though, is that we run across the square opening             * bracket ('['). If that's the case then what             * follows is the whole DTD included in the document.             * That's not really efficient in this application,             * but it is legal so we're prepared to deal with             * it.             */            ospvErrCode = OSPPXMLDocReadChar(ospvBfrAddr, ospvEncoding,                &readChar);            if (ospvErrCode == OSPC_ERR_NO_ERROR)            {                if (readChar == OSPC_XMLDOC_CLOSE)                {                    /*                     * Wow, that was easy. We're done so break from                     * the loop.                     */                    break;                }                else if (readChar == OSPC_XMLDOC_MARKUPDECLOPEN)                {                    /*                     * Oh well, we've got some markup declaration                     * here. The only thing to do is trudge through                     */                    ospvErrCode = OSPPXMLDocSkipMarkupDecl(ospvBfrAddr,                        ospvEncoding);                }            }        }    }    return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPXMLDocSkipMarkupDecl() - skip markup declarations in prolog *-----------------------------------------------------------------------*/unsigned                          /* returns error code */OSPPXMLDocSkipMarkupDecl(    OSPTBFR    **ospvBfrAddr,     /* buffer containing document */    OSPTXMLENC   ospvEncoding     /* character encoding for the document */){    unsigned      ospvErrCode = OSPC_ERR_NO_ERROR;    unsigned      isComment = OSPC_FALSE;    unsigned      isPI = OSPC_FALSE;    unsigned      isElementDecl = OSPC_FALSE;    unsigned      isAttlist = OSPC_FALSE;    unsigned      isEntityDecl = OSPC_FALSE;    unsigned char readChar = '\0';    /*     * What we're calling "markup declaration" here includes not only     * the XML markupdecl but also PEReference and whitespace. All of     * these can appear in the spot that markup declaration does in     * the prolog, and all of them we need to skip.     *     * What we're really going to do is look for the closing square     * bracket (']') that marks the end of the markup declaration.     * The complication, though, is that the bracket could also     * theoretically appear inside another element (such as a     * comment). That means we have to keep track of where we are     * and what we're looking at.     */    if (ospvBfrAddr  == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (*ospvBfrAddr == OSPC_OSNULL)    {        ospvErrCode = OSPC_ERR_BUF_EMPTY;    }    if (ospvEncoding == ospeXMLEncUnknown)    {        ospvErrCode = OSPC_ERR_XML_BAD_ENC;    }    /* now go into the loop looking for and skipping items */    while (ospvErrCode == OSPC_ERR_NO_ERROR)    {        /* first take care of any whitespace */        ospvErrCode = OSPPXMLDocSkipWhite(ospvBfrAddr, ospvEncoding);        /*         * Now take a peek at what's next. We need to handle several         * possibilities.         */        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsComment(ospvBfrAddr, ospvEncoding,                &isComment);        }        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsPI(ospvBfrAddr, ospvEncoding,                &isPI);        }        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsElementDecl(ospvBfrAddr, ospvEncoding,                &isElementDecl);        }        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsAttlist(ospvBfrAddr, ospvEncoding,                &isAttlist);        }        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            ospvErrCode = OSPPXMLDocIsEntityDecl(ospvBfrAddr, ospvEncoding,                &isEntityDecl);        }        /*         * Now that we've had a chance to see what's coming, we should         * know how to handle it.         */        if (ospvErrCode == OSPC_ERR_NO_ERROR)        {            if (isComment)            {                ospvErrCode = OSPPXMLDocSkipComment(ospvBfrAddr,                    ospvEncoding);            }            else if (isPI)            {                ospvErrCode = OSPPXMLDocSkipPI(ospvBfrAddr, ospvEncoding);            }            else if (isElementDecl)            {                ospvErrCode = OSPPXMLDocSkipElementDecl(ospvBfrAddr,                    ospvEncoding);            }            else if (isAttlist)            {                ospvErrCode = OSPPXMLDocSkipAttlist(ospvBfrAddr,

⌨️ 快捷键说明

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