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

📄 parser.c

📁 SIP 1.5.0源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}    } else if  ((RAW == '&') && (NXT(1) == '#')) {	SKIP(2);	while (RAW != ';') {	    if ((RAW >= '0') && (RAW <= '9')) 	        val = val * 10 + (CUR - '0');	    else {		ctxt->errNo = XML_ERR_INVALID_DEC_CHARREF;	        if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, 		         "xmlParseCharRef: invalid decimal value\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		val = 0;		break;	    }	    NEXT;	}	if (RAW == ';') {	    /* on purpose to avoid reentrancy problems with NEXT and SKIP */	    ctxt->nbChars ++;	    ctxt->input->cur++;	}    } else {	ctxt->errNo = XML_ERR_INVALID_CHARREF;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData,	       "xmlParseCharRef: invalid value\n");	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;    }    /*     * [ WFC: Legal Character ]     * Characters referred to using character references must match the     * production for Char.      */    if (IS_CHAR(val)) {        return(val);    } else {	ctxt->errNo = XML_ERR_INVALID_CHAR;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, "CharRef: invalid xmlChar value %d\n",	                     val);	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;    }    return(0);}/** * xmlParseStringCharRef: * @ctxt:  an XML parser context * @str:  a pointer to an index in the string * * parse Reference declarations, variant parsing from a string rather * than an an input flow. * * [66] CharRef ::= '&#' [0-9]+ ';' | *                  '&#x' [0-9a-fA-F]+ ';' * * [ WFC: Legal Character ] * Characters referred to using character references must match the * production for Char.  * * Returns the value parsed (as an int), 0 in case of error, str will be *         updated to the current value of the index */intxmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str) {    const xmlChar *ptr;    xmlChar cur;    int val = 0;    if ((str == NULL) || (*str == NULL)) return(0);    ptr = *str;    cur = *ptr;    if ((cur == '&') && (ptr[1] == '#') && (ptr[2] == 'x')) {	ptr += 3;	cur = *ptr;	while (cur != ';') {	    if ((cur >= '0') && (cur <= '9')) 	        val = val * 16 + (cur - '0');	    else if ((cur >= 'a') && (cur <= 'f'))	        val = val * 16 + (cur - 'a') + 10;	    else if ((cur >= 'A') && (cur <= 'F'))	        val = val * 16 + (cur - 'A') + 10;	    else {		ctxt->errNo = XML_ERR_INVALID_HEX_CHARREF;	        if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, 		         "xmlParseCharRef: invalid hexadecimal value\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		val = 0;		break;	    }	    ptr++;	    cur = *ptr;	}	if (cur == ';')	    ptr++;    } else if  ((cur == '&') && (ptr[1] == '#')){	ptr += 2;	cur = *ptr;	while (cur != ';') {	    if ((cur >= '0') && (cur <= '9')) 	        val = val * 10 + (cur - '0');	    else {		ctxt->errNo = XML_ERR_INVALID_DEC_CHARREF;	        if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, 		         "xmlParseCharRef: invalid decimal value\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		val = 0;		break;	    }	    ptr++;	    cur = *ptr;	}	if (cur == ';')	    ptr++;    } else {	ctxt->errNo = XML_ERR_INVALID_CHARREF;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData,	       "xmlParseCharRef: invalid value\n");	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;	return(0);    }    *str = ptr;    /*     * [ WFC: Legal Character ]     * Characters referred to using character references must match the     * production for Char.      */    if (IS_CHAR(val)) {        return(val);    } else {	ctxt->errNo = XML_ERR_INVALID_CHAR;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData,		             "CharRef: invalid xmlChar value %d\n", val);	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;    }    return(0);}/** * xmlParserHandleReference: * @ctxt:  the parser context *  * [67] Reference ::= EntityRef | CharRef * * [68] EntityRef ::= '&' Name ';' * * [ WFC: Entity Declared ] * the Name given in the entity reference must match that in an entity * declaration, except that well-formed documents need not declare any * of the following entities: amp, lt, gt, apos, quot.  * * [ WFC: Parsed Entity ] * An entity reference must not contain the name of an unparsed entity * * [66] CharRef ::= '&#' [0-9]+ ';' | *                  '&#x' [0-9a-fA-F]+ ';' * * A PEReference may have been detectect in the current input stream * the handling is done accordingly to  *      http://www.w3.org/TR/REC-xml#entproc */voidxmlParserHandleReference(xmlParserCtxtPtr ctxt) {    xmlParserInputPtr input;    xmlChar *name;    xmlEntityPtr ent = NULL;    if (ctxt->token != 0) {        return;    }	    if (RAW != '&') return;    GROW;    if ((RAW == '&') && (NXT(1) == '#')) {	switch(ctxt->instate) {	    case XML_PARSER_ENTITY_DECL:	    case XML_PARSER_PI:	    case XML_PARSER_CDATA_SECTION:	    case XML_PARSER_COMMENT:	    case XML_PARSER_SYSTEM_LITERAL:		/* we just ignore it there */		return;	    case XML_PARSER_START_TAG:		return;	    case XML_PARSER_END_TAG:		return;	    case XML_PARSER_EOF:		ctxt->errNo = XML_ERR_CHARREF_AT_EOF;		if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, "CharRef at EOF\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		return;	    case XML_PARSER_PROLOG:	    case XML_PARSER_START:	    case XML_PARSER_MISC:		ctxt->errNo = XML_ERR_CHARREF_IN_PROLOG;		if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, "CharRef in prolog!\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		return;	    case XML_PARSER_EPILOG:		ctxt->errNo = XML_ERR_CHARREF_IN_EPILOG;		if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, "CharRef in epilog!\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		return;	    case XML_PARSER_DTD:		ctxt->errNo = XML_ERR_CHARREF_IN_DTD;		if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		    ctxt->sax->error(ctxt->userData, 		           "CharRef are forbiden in DTDs!\n");		ctxt->wellFormed = 0;		ctxt->disableSAX = 1;		return;	    case XML_PARSER_ENTITY_VALUE:	        /*		 * NOTE: in the case of entity values, we don't do the		 *       substitution here since we need the literal		 *       entity value to be able to save the internal		 *       subset of the document.		 *       This will be handled by xmlDecodeEntities		 */		return;	    case XML_PARSER_CONTENT:	    case XML_PARSER_ATTRIBUTE_VALUE:		ctxt->token = xmlParseCharRef(ctxt);		return;	}	return;    }    switch(ctxt->instate) {	case XML_PARSER_CDATA_SECTION:	    return;	case XML_PARSER_PI:        case XML_PARSER_COMMENT:	case XML_PARSER_SYSTEM_LITERAL:        case XML_PARSER_CONTENT:	    return;	case XML_PARSER_START_TAG:	    return;	case XML_PARSER_END_TAG:	    return;        case XML_PARSER_EOF:	    ctxt->errNo = XML_ERR_ENTITYREF_AT_EOF;	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	        ctxt->sax->error(ctxt->userData, "Reference at EOF\n");	    ctxt->wellFormed = 0;	    ctxt->disableSAX = 1;	    return;        case XML_PARSER_PROLOG:	case XML_PARSER_START:	case XML_PARSER_MISC:	    ctxt->errNo = XML_ERR_ENTITYREF_IN_PROLOG;	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	        ctxt->sax->error(ctxt->userData, "Reference in prolog!\n");	    ctxt->wellFormed = 0;	    ctxt->disableSAX = 1;	    return;        case XML_PARSER_EPILOG:	    ctxt->errNo = XML_ERR_ENTITYREF_IN_EPILOG;	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	        ctxt->sax->error(ctxt->userData, "Reference in epilog!\n");	    ctxt->wellFormed = 0;	    ctxt->disableSAX = 1;	    return;	case XML_PARSER_ENTITY_VALUE:	    /*	     * NOTE: in the case of entity values, we don't do the	     *       substitution here since we need the literal	     *       entity value to be able to save the internal	     *       subset of the document.	     *       This will be handled by xmlDecodeEntities	     */	    return;        case XML_PARSER_ATTRIBUTE_VALUE:	    /*	     * NOTE: in the case of attributes values, we don't do the	     *       substitution here unless we are in a mode where	     *       the parser is explicitely asked to substitute	     *       entities. The SAX callback is called with values	     *       without entity substitution.	     *       This will then be handled by xmlDecodeEntities	     */	    return;	case XML_PARSER_ENTITY_DECL:	    /*	     * we just ignore it there	     * the substitution will be done once the entity is referenced	     */	    return;        case XML_PARSER_DTD:	    ctxt->errNo = XML_ERR_ENTITYREF_IN_DTD;	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))		ctxt->sax->error(ctxt->userData, 		       "Entity references are forbiden in DTDs!\n");	    ctxt->wellFormed = 0;	    ctxt->disableSAX = 1;	    return;    }    NEXT;    name = xmlScanName(ctxt);    if (name == NULL) {	ctxt->errNo = XML_ERR_ENTITYREF_NO_NAME;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, "Entity reference: no name\n");	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;	ctxt->token = '&';	return;    }    if (NXT(xmlStrlen(name)) != ';') {	ctxt->errNo = XML_ERR_ENTITYREF_SEMICOL_MISSING;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 	                     "Entity reference: ';' expected\n");	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;	ctxt->token = '&';	xmlFree(name);	return;    }    SKIP(xmlStrlen(name) + 1);    if (ctxt->sax != NULL) {	if (ctxt->sax->getEntity != NULL)	    ent = ctxt->sax->getEntity(ctxt->userData, name);    }    /*     * [ WFC: Entity Declared ]     * the Name given in the entity reference must match that in an entity     * declaration, except that well-formed documents need not declare any     * of the following entities: amp, lt, gt, apos, quot.      */    if (ent == NULL)	ent = xmlGetPredefinedEntity(name);    if (ent == NULL) {        ctxt->errNo = XML_ERR_UNDECLARED_ENTITY;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 			     "Entity reference: entity %s not declared\n",			     name);	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;	xmlFree(name);	return;    }    /*     * [ WFC: Parsed Entity ]     * An entity reference must not contain the name of an unparsed entity     */    if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {        ctxt->errNo = XML_ERR_UNPARSED_ENTITY;	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	    ctxt->sax->error(ctxt->userData, 			 "Entity reference to unparsed entity %s\n", name);	ctxt->wellFormed = 0;	ctxt->disableSAX = 1;    }    if (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY) {        ctxt->token = ent->content[0];	xmlFree(name);	return;    }    input = xmlNewEntityInputStream(ctxt, ent);    xmlPushInput(ctxt, input);    xmlFree(name);    return;}/** * xmlParserHandlePEReference: * @ctxt:  the parser context *  * [69] PEReference ::= '%' Name ';' * * [ WFC: No Recursion ] * TODO A parsed entity must not contain a recursive * reference to itself, either directly or indirectly.  * * [ WFC: Entity Declared ] * In a document without any DTD, a document with only an internal DTD * subset which contains no parameter entity references, or a document * with "standalone='yes'", ...  ... The declaration of a parameter * entity must precede any reference to it... * * [ VC: Entity Declared ] * In a document with an external subset or external parameter entities * with "standalone='no'", ...  ... The declaration of a parameter entity * must precede any reference to it... * * [ WFC: In DTD ] * Parameter-entity references may only appear in the DTD. * NOTE: misleading but this is handled. * * A PEReference may have been detected in the current input stream * the handling is done accordingly to  *      http://www.w3.org/TR/REC-xml#entproc * i.e.  *   - Included in literal in entity values *   - Included as Paraemeter Entity reference within DTDs */voidxmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {    xmlChar *name;    xmlEntityPtr entity = NULL;    xmlParserInputPtr input;    if (ctxt->token != 0) {        return;    }	    if (RAW != '%') return;    switch(ctxt->instate) {	case XML_PARSER_CDATA_SECTION:	    return;        case XML_PARSER_COMMENT:	    return;	case XML_PARSER_START_TAG:	    return;	case XML_PARSER_END_TAG:	    return;        case XML_PARSER_EOF:	    ctxt->errNo = XML_ERR_PEREF_AT_EOF;	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	        ctxt->sax->error(ctxt->userData, "PEReference at EOF\n");	    ctxt->wellFormed = 0;	    ctxt->disableSAX = 1;	    return;        case XML_PARSER_PROLOG:	case XML_PARSER_START:	case XML_PARSER_MISC:	    ctxt->errNo = XML_ERR_PEREF_IN_PROLOG;	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))	        ctxt->sax->error(ctxt->userData, "PEReference in prolog!\n");	    ctxt->wellFormed = 0;	    ctxt->disableSAX = 1;	    return;	case XML_PARSER_ENTITY_DECL:        case XML_PARSER_CONTENT:

⌨️ 快捷键说明

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