Browse Source

Move XML support into separate module.

pull/14/head
Rafal Kupiec 3 years ago
parent
commit
a00e81f4f8
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
9 changed files with 2805 additions and 2715 deletions
  1. +4
    -1
      Makefile
  2. +0
    -249
      constant.c
  3. +1022
    -0
      ext/xml/lib.c
  4. +143
    -0
      ext/xml/lib.h
  5. +1483
    -0
      ext/xml/xml.c
  6. +152
    -0
      ext/xml/xml.h
  7. +1
    -1058
      lib.c
  8. +0
    -96
      ph7int.h
  9. +0
    -1311
      vm.c

+ 4
- 1
Makefile View File

@ -44,7 +44,7 @@ ASTYLE_FLAGS =\
--lineend=linux
all: psharp dummy.lib json.lib
all: psharp dummy.lib json.lib xml.lib
clean:
rm -f psharp $(ENGINE_OBJS) *.lib
@ -63,3 +63,6 @@ dummy.lib: ext/dummy/dummy.c
json.lib: ext/json/json.c
$(CC) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o json.lib ext/json/json.c
xml.lib: ext/xml/xml.c
$(CC) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o xml.lib ext/xml/lib.c ext/xml/xml.c

+ 0
- 249
constant.c View File

@ -1258,225 +1258,6 @@ static void PH7_EXTR_PREFIX_IF_EXISTS_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, 0x40);
}
#ifndef PH7_DISABLE_BUILTIN_FUNC
/*
* XML_ERROR_NONE
* Expand the value of SXML_ERROR_NO_MEMORY defined in ph7Int.h
*/
static void PH7_XML_ERROR_NONE_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_NO_MEMORY);
}
/*
* XML_ERROR_NO_MEMORY
* Expand the value of SXML_ERROR_NONE defined in ph7Int.h
*/
static void PH7_XML_ERROR_NO_MEMORY_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_NO_MEMORY);
}
/*
* XML_ERROR_SYNTAX
* Expand the value of SXML_ERROR_SYNTAX defined in ph7Int.h
*/
static void PH7_XML_ERROR_SYNTAX_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_SYNTAX);
}
/*
* XML_ERROR_NO_ELEMENTS
* Expand the value of SXML_ERROR_NO_ELEMENTS defined in ph7Int.h
*/
static void PH7_XML_ERROR_NO_ELEMENTS_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_NO_ELEMENTS);
}
/*
* XML_ERROR_INVALID_TOKEN
* Expand the value of SXML_ERROR_INVALID_TOKEN defined in ph7Int.h
*/
static void PH7_XML_ERROR_INVALID_TOKEN_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_INVALID_TOKEN);
}
/*
* XML_ERROR_UNCLOSED_TOKEN
* Expand the value of SXML_ERROR_UNCLOSED_TOKEN defined in ph7Int.h
*/
static void PH7_XML_ERROR_UNCLOSED_TOKEN_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_UNCLOSED_TOKEN);
}
/*
* XML_ERROR_PARTIAL_CHAR
* Expand the value of SXML_ERROR_PARTIAL_CHAR defined in ph7Int.h
*/
static void PH7_XML_ERROR_PARTIAL_CHAR_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_PARTIAL_CHAR);
}
/*
* XML_ERROR_TAG_MISMATCH
* Expand the value of SXML_ERROR_TAG_MISMATCH defined in ph7Int.h
*/
static void PH7_XML_ERROR_TAG_MISMATCH_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_TAG_MISMATCH);
}
/*
* XML_ERROR_DUPLICATE_ATTRIBUTE
* Expand the value of SXML_ERROR_DUPLICATE_ATTRIBUTE defined in ph7Int.h
*/
static void PH7_XML_ERROR_DUPLICATE_ATTRIBUTE_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_DUPLICATE_ATTRIBUTE);
}
/*
* XML_ERROR_JUNK_AFTER_DOC_ELEMENT
* Expand the value of SXML_ERROR_JUNK_AFTER_DOC_ELEMENT defined in ph7Int.h
*/
static void PH7_XML_ERROR_JUNK_AFTER_DOC_ELEMENT_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_JUNK_AFTER_DOC_ELEMENT);
}
/*
* XML_ERROR_PARAM_ENTITY_REF
* Expand the value of SXML_ERROR_PARAM_ENTITY_REF defined in ph7Int.h
*/
static void PH7_XML_ERROR_PARAM_ENTITY_REF_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_PARAM_ENTITY_REF);
}
/*
* XML_ERROR_UNDEFINED_ENTITY
* Expand the value of SXML_ERROR_UNDEFINED_ENTITY defined in ph7Int.h
*/
static void PH7_XML_ERROR_UNDEFINED_ENTITY_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_UNDEFINED_ENTITY);
}
/*
* XML_ERROR_RECURSIVE_ENTITY_REF
* Expand the value of SXML_ERROR_RECURSIVE_ENTITY_REF defined in ph7Int.h
*/
static void PH7_XML_ERROR_RECURSIVE_ENTITY_REF_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_RECURSIVE_ENTITY_REF);
}
/*
* XML_ERROR_ASYNC_ENTITY
* Expand the value of SXML_ERROR_ASYNC_ENTITY defined in ph7Int.h
*/
static void PH7_XML_ERROR_ASYNC_ENTITY_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_ASYNC_ENTITY);
}
/*
* XML_ERROR_BAD_CHAR_REF
* Expand the value of SXML_ERROR_BAD_CHAR_REF defined in ph7Int.h
*/
static void PH7_XML_ERROR_BAD_CHAR_REF_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_BAD_CHAR_REF);
}
/*
* XML_ERROR_BINARY_ENTITY_REF
* Expand the value of SXML_ERROR_BINARY_ENTITY_REF defined in ph7Int.h
*/
static void PH7_XML_ERROR_BINARY_ENTITY_REF_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_BINARY_ENTITY_REF);
}
/*
* XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF
* Expand the value of SXML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF defined in ph7Int.h
*/
static void PH7_XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF);
}
/*
* XML_ERROR_MISPLACED_XML_PI
* Expand the value of SXML_ERROR_MISPLACED_XML_PI defined in ph7Int.h
*/
static void PH7_XML_ERROR_MISPLACED_XML_PI_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_MISPLACED_XML_PI);
}
/*
* XML_ERROR_UNKNOWN_ENCODING
* Expand the value of SXML_ERROR_UNKNOWN_ENCODING defined in ph7Int.h
*/
static void PH7_XML_ERROR_UNKNOWN_ENCODING_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_UNKNOWN_ENCODING);
}
/*
* XML_ERROR_INCORRECT_ENCODING
* Expand the value of SXML_ERROR_INCORRECT_ENCODING defined in ph7Int.h
*/
static void PH7_XML_ERROR_INCORRECT_ENCODING_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_INCORRECT_ENCODING);
}
/*
* XML_ERROR_UNCLOSED_CDATA_SECTION
* Expand the value of SXML_ERROR_UNCLOSED_CDATA_SECTION defined in ph7Int.h
*/
static void PH7_XML_ERROR_UNCLOSED_CDATA_SECTION_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_UNCLOSED_CDATA_SECTION);
}
/*
* XML_ERROR_EXTERNAL_ENTITY_HANDLING
* Expand the value of SXML_ERROR_EXTERNAL_ENTITY_HANDLING defined in ph7Int.h
*/
static void PH7_XML_ERROR_EXTERNAL_ENTITY_HANDLING_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_ERROR_EXTERNAL_ENTITY_HANDLING);
}
/*
* XML_OPTION_CASE_FOLDING
* Expand the value of SXML_OPTION_CASE_FOLDING defined in ph7Int.h.
*/
static void PH7_XML_OPTION_CASE_FOLDING_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_OPTION_CASE_FOLDING);
}
/*
* XML_OPTION_TARGET_ENCODING
* Expand the value of SXML_OPTION_TARGET_ENCODING defined in ph7Int.h.
*/
static void PH7_XML_OPTION_TARGET_ENCODING_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_OPTION_TARGET_ENCODING);
}
/*
* XML_OPTION_SKIP_TAGSTART
* Expand the value of SXML_OPTION_SKIP_TAGSTART defined in ph7Int.h.
*/
static void PH7_XML_OPTION_SKIP_TAGSTART_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_OPTION_SKIP_TAGSTART);
}
/*
* XML_OPTION_SKIP_WHITE
* Expand the value of SXML_OPTION_SKIP_TAGSTART defined in ph7Int.h.
*/
static void PH7_XML_OPTION_SKIP_WHITE_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_int(pVal, SXML_OPTION_SKIP_WHITE);
}
/*
* XML_SAX_IMPL.
* Expand the name of the underlying XML engine.
*/
static void PH7_XML_SAX_IMP_Const(ph7_value *pVal, void *pUserData) {
SXUNUSED(pUserData); /* cc warning */
ph7_value_string(pVal, "Symisc XML engine", (int)sizeof("Symisc XML engine") - 1);
}
#endif /* PH7_DISABLE_BUILTIN_FUNC */
/*
* static
* Expand the name of the current class. 'static' otherwise.
@ -1690,35 +1471,6 @@ static const ph7_builtin_constant aBuiltIn[] = {
{"EXTR_PREFIX_INVALID", PH7_EXTR_PREFIX_INVALID_Const },
{"EXTR_IF_EXISTS", PH7_EXTR_IF_EXISTS_Const },
{"EXTR_PREFIX_IF_EXISTS", PH7_EXTR_PREFIX_IF_EXISTS_Const},
#ifndef PH7_DISABLE_BUILTIN_FUNC
{"XML_ERROR_NONE", PH7_XML_ERROR_NONE_Const},
{"XML_ERROR_NO_MEMORY", PH7_XML_ERROR_NO_MEMORY_Const},
{"XML_ERROR_SYNTAX", PH7_XML_ERROR_SYNTAX_Const},
{"XML_ERROR_NO_ELEMENTS", PH7_XML_ERROR_NO_ELEMENTS_Const},
{"XML_ERROR_INVALID_TOKEN", PH7_XML_ERROR_INVALID_TOKEN_Const},
{"XML_ERROR_UNCLOSED_TOKEN", PH7_XML_ERROR_UNCLOSED_TOKEN_Const},
{"XML_ERROR_PARTIAL_CHAR", PH7_XML_ERROR_PARTIAL_CHAR_Const},
{"XML_ERROR_TAG_MISMATCH", PH7_XML_ERROR_TAG_MISMATCH_Const},
{"XML_ERROR_DUPLICATE_ATTRIBUTE", PH7_XML_ERROR_DUPLICATE_ATTRIBUTE_Const},
{"XML_ERROR_JUNK_AFTER_DOC_ELEMENT", PH7_XML_ERROR_JUNK_AFTER_DOC_ELEMENT_Const},
{"XML_ERROR_PARAM_ENTITY_REF", PH7_XML_ERROR_PARAM_ENTITY_REF_Const},
{"XML_ERROR_UNDEFINED_ENTITY", PH7_XML_ERROR_UNDEFINED_ENTITY_Const},
{"XML_ERROR_RECURSIVE_ENTITY_REF", PH7_XML_ERROR_RECURSIVE_ENTITY_REF_Const},
{"XML_ERROR_ASYNC_ENTITY", PH7_XML_ERROR_ASYNC_ENTITY_Const},
{"XML_ERROR_BAD_CHAR_REF", PH7_XML_ERROR_BAD_CHAR_REF_Const},
{"XML_ERROR_BINARY_ENTITY_REF", PH7_XML_ERROR_BINARY_ENTITY_REF_Const},
{"XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF", PH7_XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF_Const},
{"XML_ERROR_MISPLACED_XML_PI", PH7_XML_ERROR_MISPLACED_XML_PI_Const},
{"XML_ERROR_UNKNOWN_ENCODING", PH7_XML_ERROR_UNKNOWN_ENCODING_Const},
{"XML_ERROR_INCORRECT_ENCODING", PH7_XML_ERROR_INCORRECT_ENCODING_Const},
{"XML_ERROR_UNCLOSED_CDATA_SECTION", PH7_XML_ERROR_UNCLOSED_CDATA_SECTION_Const},
{"XML_ERROR_EXTERNAL_ENTITY_HANDLING", PH7_XML_ERROR_EXTERNAL_ENTITY_HANDLING_Const},
{"XML_OPTION_CASE_FOLDING", PH7_XML_OPTION_CASE_FOLDING_Const},
{"XML_OPTION_TARGET_ENCODING", PH7_XML_OPTION_TARGET_ENCODING_Const},
{"XML_OPTION_SKIP_TAGSTART", PH7_XML_OPTION_SKIP_TAGSTART_Const},
{"XML_OPTION_SKIP_WHITE", PH7_XML_OPTION_SKIP_WHITE_Const},
{"XML_SAX_IMPL", PH7_XML_SAX_IMP_Const},
#endif /* PH7_DISABLE_BUILTIN_FUNC */
{"static", PH7_static_Const },
{"self", PH7_self_Const },
{"__CLASS__", PH7_self_Const },
@ -1737,4 +1489,3 @@ PH7_PRIVATE void PH7_RegisterBuiltInConstant(ph7_vm *pVm) {
ph7_create_constant(&(*pVm), aBuiltIn[n].zName, aBuiltIn[n].xExpand, &(*pVm));
}
}
-

+ 1022
- 0
ext/xml/lib.c
File diff suppressed because it is too large
View File


+ 143
- 0
ext/xml/lib.h View File

@ -0,0 +1,143 @@
#ifndef __LIB_H__
#define __LIB_H__
#include "ph7.h"
#include "ph7int.h"
/*
* Lexer token codes
* The following set of constants are the token value recognized
* by the lexer when processing XML input.
*/
#define SXML_TOK_INVALID 0xFFFF /* Invalid Token */
#define SXML_TOK_COMMENT 0x01 /* Comment */
#define SXML_TOK_PI 0x02 /* Processing instruction */
#define SXML_TOK_DOCTYPE 0x04 /* Doctype directive */
#define SXML_TOK_RAW 0x08 /* Raw text */
#define SXML_TOK_START_TAG 0x10 /* Starting tag */
#define SXML_TOK_CDATA 0x20 /* CDATA */
#define SXML_TOK_END_TAG 0x40 /* Ending tag */
#define SXML_TOK_START_END 0x80 /* Tag */
#define SXML_TOK_SPACE 0x100 /* Spaces (including new lines) */
#define IS_XML_DIRTY(c) \
( c == '<' || c == '$'|| c == '"' || c == '\''|| c == '&'|| c == '(' || c == ')' || c == '*' ||\
c == '%' || c == '#' || c == '|' || c == '/'|| c == '~' || c == '{' || c == '}' ||\
c == '[' || c == ']' || c == '\\'|| c == ';'||c == '^' || c == '`' )
/* XML processing control flags */
#define SXML_ENABLE_NAMESPACE 0x01 /* Parse XML with namespace support enbaled */
#define SXML_ENABLE_QUERY 0x02 /* Not used */
#define SXML_OPTION_CASE_FOLDING 0x04 /* Controls whether case-folding is enabled for this XML parser */
#define SXML_OPTION_SKIP_TAGSTART 0x08 /* Specify how many characters should be skipped in the beginning of a tag name.*/
#define SXML_OPTION_SKIP_WHITE 0x10 /* Whether to skip values consisting of whitespace characters. */
#define SXML_OPTION_TARGET_ENCODING 0x20 /* Default encoding: UTF-8 */
/* XML error codes */
enum xml_err_code {
SXML_ERROR_NONE = 1,
SXML_ERROR_NO_MEMORY,
SXML_ERROR_SYNTAX,
SXML_ERROR_NO_ELEMENTS,
SXML_ERROR_INVALID_TOKEN,
SXML_ERROR_UNCLOSED_TOKEN,
SXML_ERROR_PARTIAL_CHAR,
SXML_ERROR_TAG_MISMATCH,
SXML_ERROR_DUPLICATE_ATTRIBUTE,
SXML_ERROR_JUNK_AFTER_DOC_ELEMENT,
SXML_ERROR_PARAM_ENTITY_REF,
SXML_ERROR_UNDEFINED_ENTITY,
SXML_ERROR_RECURSIVE_ENTITY_REF,
SXML_ERROR_ASYNC_ENTITY,
SXML_ERROR_BAD_CHAR_REF,
SXML_ERROR_BINARY_ENTITY_REF,
SXML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
SXML_ERROR_MISPLACED_XML_PI,
SXML_ERROR_UNKNOWN_ENCODING,
SXML_ERROR_INCORRECT_ENCODING,
SXML_ERROR_UNCLOSED_CDATA_SECTION,
SXML_ERROR_EXTERNAL_ENTITY_HANDLING
};
/*
* An XML raw text,CDATA,tag name and son is parsed out and stored
* in an instance of the following structure.
*/
typedef struct SyXMLRawStr SyXMLRawStr;
struct SyXMLRawStr {
const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */
sxu32 nByte; /* Text length */
sxu32 nLine; /* Line number this text occurs */
};
/*
* An XML raw text,CDATA,tag name is parsed out and stored
* in an instance of the following structure.
*/
typedef struct SyXMLRawStrNS SyXMLRawStrNS;
struct SyXMLRawStrNS {
/* Public field [Must match the SyXMLRawStr fields ] */
const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */
sxu32 nByte; /* Text length */
sxu32 nLine; /* Line number this text occurs */
/* Private fields */
SySet sNSset; /* Namespace entries */
};
/*
* Event callback signatures.
*/
typedef sxi32(*ProcXMLStartTagHandler)(SyXMLRawStr *, SyXMLRawStr *, sxu32, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLTextHandler)(SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLEndTagHandler)(SyXMLRawStr *, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLPIHandler)(SyXMLRawStr *, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLDoctypeHandler)(SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLSyntaxErrorHandler)(const char *, int, SyToken *, void *);
typedef sxi32(*ProcXMLStartDocument)(void *);
typedef sxi32(*ProcXMLNameSpaceStart)(SyXMLRawStr *, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLNameSpaceEnd)(SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLEndDocument)(void *);
/* Each active XML SAX parser is represented by an instance
* of the following structure.
*/
typedef struct SyXMLParser SyXMLParser;
struct SyXMLParser {
SyMemBackend *pAllocator; /* Memory backend */
void *pUserData; /* User private data forwarded varbatim by the XML parser
* as the last argument to the users callbacks.
*/
SyHash hns; /* Namespace hashtable */
SySet sToken; /* XML tokens */
SyLex sLex; /* Lexical analyzer */
sxi32 nFlags; /* Control flags */
/* User callbacks */
ProcXMLStartTagHandler xStartTag; /* Start element handler */
ProcXMLEndTagHandler xEndTag; /* End element handler */
ProcXMLTextHandler xRaw; /* Raw text/CDATA handler */
ProcXMLDoctypeHandler xDoctype; /* DOCTYPE handler */
ProcXMLPIHandler xPi; /* Processing instruction (PI) handler*/
ProcXMLSyntaxErrorHandler xError; /* Error handler */
ProcXMLStartDocument xStartDoc; /* StartDoc handler */
ProcXMLEndDocument xEndDoc; /* EndDoc handler */
ProcXMLNameSpaceStart xNameSpace; /* Namespace declaration handler */
ProcXMLNameSpaceEnd xNameSpaceEnd; /* End namespace declaration handler */
};
PH7_PRIVATE sxi32 SyXMLParserInit(SyXMLParser *pParser, SyMemBackend *pAllocator, sxi32 iFlags);
PH7_PRIVATE sxi32 SyXMLParserSetEventHandler(SyXMLParser *pParser,
void *pUserData,
ProcXMLStartTagHandler xStartTag,
ProcXMLTextHandler xRaw,
ProcXMLSyntaxErrorHandler xErr,
ProcXMLStartDocument xStartDoc,
ProcXMLEndTagHandler xEndTag,
ProcXMLPIHandler xPi,
ProcXMLEndDocument xEndDoc,
ProcXMLDoctypeHandler xDoctype,
ProcXMLNameSpaceStart xNameSpace,
ProcXMLNameSpaceEnd xNameSpaceEnd
);
PH7_PRIVATE sxi32 SyXMLProcess(SyXMLParser *pParser, const char *zInput, sxu32 nByte);
PH7_PRIVATE sxi32 SyXMLParserRelease(SyXMLParser *pParser);
#endif

+ 1483
- 0
ext/xml/xml.c
File diff suppressed because it is too large
View File


+ 152
- 0
ext/xml/xml.h View File

@ -0,0 +1,152 @@
#ifndef __XML_H__
#define __XML_H__
#include "ph7.h"
#include "ph7int.h"
#include "lib.h"
#define MODULE_DESC "XML Module"
#define MODULE_VER 1.0
#define XML_TOTAL_HANDLER (PH7_XML_NS_END + 1)
#define XML_ENGINE_MAGIC 0x851EFC52
#define IS_INVALID_XML_ENGINE(XML) (XML == 0 || (XML)->nMagic != XML_ENGINE_MAGIC)
enum ph7_xml_handler_id {
PH7_XML_START_TAG = 0, /* Start element handlers ID */
PH7_XML_END_TAG, /* End element handler ID*/
PH7_XML_CDATA, /* Character data handler ID*/
PH7_XML_PI, /* Processing instruction (PI) handler ID*/
PH7_XML_DEF, /* Default handler ID */
PH7_XML_UNPED, /* Unparsed entity declaration handler */
PH7_XML_ND, /* Notation declaration handler ID*/
PH7_XML_EER, /* External entity reference handler */
PH7_XML_NS_START, /* Start namespace declaration handler */
PH7_XML_NS_END /* End namespace declaration handler */
};
/* An instance of the following structure describe a working
* XML engine instance.
*/
typedef struct ph7_xml_engine ph7_xml_engine;
struct ph7_xml_engine {
ph7_vm *pVm; /* VM that own this instance */
ph7_context *pCtx; /* Call context */
SyXMLParser sParser; /* Underlying XML parser */
ph7_value aCB[XML_TOTAL_HANDLER]; /* User-defined callbacks */
ph7_value sParserValue; /* ph7_value holding this instance which is forwarded
* as the first argument to the user callbacks.
*/
int ns_sep; /* Namespace separator */
SyBlob sErr; /* Error message consumer */
sxi32 iErrCode; /* Last error code */
sxi32 iNest; /* Nesting level */
sxu32 nLine; /* Last processed line */
sxu32 nMagic; /* Magic number so that we avoid misuse */
};
static void PH7_XML_ERROR_NONE_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_NO_MEMORY_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_SYNTAX_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_NO_ELEMENTS_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_INVALID_TOKEN_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_UNCLOSED_TOKEN_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_PARTIAL_CHAR_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_TAG_MISMATCH_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_DUPLICATE_ATTRIBUTE_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_JUNK_AFTER_DOC_ELEMENT_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_PARAM_ENTITY_REF_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_UNDEFINED_ENTITY_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_RECURSIVE_ENTITY_REF_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_ASYNC_ENTITY_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_BAD_CHAR_REF_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_BINARY_ENTITY_REF_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_MISPLACED_XML_PI_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_UNKNOWN_ENCODING_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_INCORRECT_ENCODING_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_UNCLOSED_CDATA_SECTION_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_ERROR_EXTERNAL_ENTITY_HANDLING_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_OPTION_CASE_FOLDING_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_OPTION_TARGET_ENCODING_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_OPTION_SKIP_TAGSTART_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_OPTION_SKIP_WHITE_Const(ph7_value *pVal, void *pUserData);
static void PH7_XML_SAX_IMP_Const(ph7_value *pVal, void *pUserData);
static int vm_builtin_xml_parser_create(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_parser_create_ns(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_parser_free(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_element_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_character_data_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_default_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_end_namespace_decl_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_start_namespace_decl_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_processing_instruction_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_unparsed_entity_decl_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_notation_decl_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_external_entity_ref_handler(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_get_current_line_number(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_get_current_byte_index(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_set_object(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_get_current_column_number(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_get_error_code(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_parse(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_parser_set_option(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_parser_get_option(ph7_context *pCtx, int nArg, ph7_value **apArg);
static int vm_builtin_xml_error_string(ph7_context *pCtx, int nArg, ph7_value **apArg);
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc);
static const ph7_builtin_constant xmlConstList[] = {
{"XML_ERROR_NONE", PH7_XML_ERROR_NONE_Const},
{"XML_ERROR_NO_MEMORY", PH7_XML_ERROR_NO_MEMORY_Const},
{"XML_ERROR_SYNTAX", PH7_XML_ERROR_SYNTAX_Const},
{"XML_ERROR_NO_ELEMENTS", PH7_XML_ERROR_NO_ELEMENTS_Const},
{"XML_ERROR_INVALID_TOKEN", PH7_XML_ERROR_INVALID_TOKEN_Const},
{"XML_ERROR_UNCLOSED_TOKEN", PH7_XML_ERROR_UNCLOSED_TOKEN_Const},
{"XML_ERROR_PARTIAL_CHAR", PH7_XML_ERROR_PARTIAL_CHAR_Const},
{"XML_ERROR_TAG_MISMATCH", PH7_XML_ERROR_TAG_MISMATCH_Const},
{"XML_ERROR_DUPLICATE_ATTRIBUTE", PH7_XML_ERROR_DUPLICATE_ATTRIBUTE_Const},
{"XML_ERROR_JUNK_AFTER_DOC_ELEMENT", PH7_XML_ERROR_JUNK_AFTER_DOC_ELEMENT_Const},
{"XML_ERROR_PARAM_ENTITY_REF", PH7_XML_ERROR_PARAM_ENTITY_REF_Const},
{"XML_ERROR_UNDEFINED_ENTITY", PH7_XML_ERROR_UNDEFINED_ENTITY_Const},
{"XML_ERROR_RECURSIVE_ENTITY_REF", PH7_XML_ERROR_RECURSIVE_ENTITY_REF_Const},
{"XML_ERROR_ASYNC_ENTITY", PH7_XML_ERROR_ASYNC_ENTITY_Const},
{"XML_ERROR_BAD_CHAR_REF", PH7_XML_ERROR_BAD_CHAR_REF_Const},
{"XML_ERROR_BINARY_ENTITY_REF", PH7_XML_ERROR_BINARY_ENTITY_REF_Const},
{"XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF", PH7_XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF_Const},
{"XML_ERROR_MISPLACED_XML_PI", PH7_XML_ERROR_MISPLACED_XML_PI_Const},
{"XML_ERROR_UNKNOWN_ENCODING", PH7_XML_ERROR_UNKNOWN_ENCODING_Const},
{"XML_ERROR_INCORRECT_ENCODING", PH7_XML_ERROR_INCORRECT_ENCODING_Const},
{"XML_ERROR_UNCLOSED_CDATA_SECTION", PH7_XML_ERROR_UNCLOSED_CDATA_SECTION_Const},
{"XML_ERROR_EXTERNAL_ENTITY_HANDLING", PH7_XML_ERROR_EXTERNAL_ENTITY_HANDLING_Const},
{"XML_OPTION_CASE_FOLDING", PH7_XML_OPTION_CASE_FOLDING_Const},
{"XML_OPTION_TARGET_ENCODING", PH7_XML_OPTION_TARGET_ENCODING_Const},
{"XML_OPTION_SKIP_TAGSTART", PH7_XML_OPTION_SKIP_TAGSTART_Const},
{"XML_OPTION_SKIP_WHITE", PH7_XML_OPTION_SKIP_WHITE_Const},
{"XML_SAX_IMPL", PH7_XML_SAX_IMP_Const}
};
static const ph7_builtin_func xmlFuncList[] = {
{"xml_parser_create", vm_builtin_xml_parser_create },
{"xml_parser_create_ns", vm_builtin_xml_parser_create_ns},
{"xml_parser_free", vm_builtin_xml_parser_free },
{"xml_set_element_handler", vm_builtin_xml_set_element_handler},
{"xml_set_character_data_handler", vm_builtin_xml_set_character_data_handler},
{"xml_set_default_handler", vm_builtin_xml_set_default_handler },
{"xml_set_end_namespace_decl_handler", vm_builtin_xml_set_end_namespace_decl_handler},
{"xml_set_start_namespace_decl_handler", vm_builtin_xml_set_start_namespace_decl_handler},
{"xml_set_processing_instruction_handler", vm_builtin_xml_set_processing_instruction_handler},
{"xml_set_unparsed_entity_decl_handler", vm_builtin_xml_set_unparsed_entity_decl_handler},
{"xml_set_notation_decl_handler", vm_builtin_xml_set_notation_decl_handler},
{"xml_set_external_entity_ref_handler", vm_builtin_xml_set_external_entity_ref_handler},
{"xml_get_current_line_number", vm_builtin_xml_get_current_line_number},
{"xml_get_current_byte_index", vm_builtin_xml_get_current_byte_index },
{"xml_set_object", vm_builtin_xml_set_object},
{"xml_get_current_column_number", vm_builtin_xml_get_current_column_number},
{"xml_get_error_code", vm_builtin_xml_get_error_code },
{"xml_parse", vm_builtin_xml_parse },
{"xml_parser_set_option", vm_builtin_xml_parser_set_option},
{"xml_parser_get_option", vm_builtin_xml_parser_get_option},
{"xml_error_string", vm_builtin_xml_error_string }
};
#endif

+ 1
- 1058
lib.c
File diff suppressed because it is too large
View File


+ 0
- 96
ph7int.h View File

@ -527,86 +527,6 @@ struct SyLex {
(RAW)->nByte--;\
}
#ifndef PH7_DISABLE_BUILTIN_FUNC
/*
* An XML raw text,CDATA,tag name and son is parsed out and stored
* in an instance of the following structure.
*/
typedef struct SyXMLRawStr SyXMLRawStr;
struct SyXMLRawStr {
const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */
sxu32 nByte; /* Text length */
sxu32 nLine; /* Line number this text occurs */
};
/*
* Event callback signatures.
*/
typedef sxi32(*ProcXMLStartTagHandler)(SyXMLRawStr *, SyXMLRawStr *, sxu32, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLTextHandler)(SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLEndTagHandler)(SyXMLRawStr *, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLPIHandler)(SyXMLRawStr *, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLDoctypeHandler)(SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLSyntaxErrorHandler)(const char *, int, SyToken *, void *);
typedef sxi32(*ProcXMLStartDocument)(void *);
typedef sxi32(*ProcXMLNameSpaceStart)(SyXMLRawStr *, SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLNameSpaceEnd)(SyXMLRawStr *, void *);
typedef sxi32(*ProcXMLEndDocument)(void *);
/* XML processing control flags */
#define SXML_ENABLE_NAMESPACE 0x01 /* Parse XML with namespace support enbaled */
#define SXML_ENABLE_QUERY 0x02 /* Not used */
#define SXML_OPTION_CASE_FOLDING 0x04 /* Controls whether case-folding is enabled for this XML parser */
#define SXML_OPTION_SKIP_TAGSTART 0x08 /* Specify how many characters should be skipped in the beginning of a tag name.*/
#define SXML_OPTION_SKIP_WHITE 0x10 /* Whether to skip values consisting of whitespace characters. */
#define SXML_OPTION_TARGET_ENCODING 0x20 /* Default encoding: UTF-8 */
/* XML error codes */
enum xml_err_code {
SXML_ERROR_NONE = 1,
SXML_ERROR_NO_MEMORY,
SXML_ERROR_SYNTAX,
SXML_ERROR_NO_ELEMENTS,
SXML_ERROR_INVALID_TOKEN,
SXML_ERROR_UNCLOSED_TOKEN,
SXML_ERROR_PARTIAL_CHAR,
SXML_ERROR_TAG_MISMATCH,
SXML_ERROR_DUPLICATE_ATTRIBUTE,
SXML_ERROR_JUNK_AFTER_DOC_ELEMENT,
SXML_ERROR_PARAM_ENTITY_REF,
SXML_ERROR_UNDEFINED_ENTITY,
SXML_ERROR_RECURSIVE_ENTITY_REF,
SXML_ERROR_ASYNC_ENTITY,
SXML_ERROR_BAD_CHAR_REF,
SXML_ERROR_BINARY_ENTITY_REF,
SXML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
SXML_ERROR_MISPLACED_XML_PI,
SXML_ERROR_UNKNOWN_ENCODING,
SXML_ERROR_INCORRECT_ENCODING,
SXML_ERROR_UNCLOSED_CDATA_SECTION,
SXML_ERROR_EXTERNAL_ENTITY_HANDLING
};
/* Each active XML SAX parser is represented by an instance
* of the following structure.
*/
typedef struct SyXMLParser SyXMLParser;
struct SyXMLParser {
SyMemBackend *pAllocator; /* Memory backend */
void *pUserData; /* User private data forwarded varbatim by the XML parser
* as the last argument to the users callbacks.
*/
SyHash hns; /* Namespace hashtable */
SySet sToken; /* XML tokens */
SyLex sLex; /* Lexical analyzer */
sxi32 nFlags; /* Control flags */
/* User callbacks */
ProcXMLStartTagHandler xStartTag; /* Start element handler */
ProcXMLEndTagHandler xEndTag; /* End element handler */
ProcXMLTextHandler xRaw; /* Raw text/CDATA handler */
ProcXMLDoctypeHandler xDoctype; /* DOCTYPE handler */
ProcXMLPIHandler xPi; /* Processing instruction (PI) handler*/
ProcXMLSyntaxErrorHandler xError; /* Error handler */
ProcXMLStartDocument xStartDoc; /* StartDoc handler */
ProcXMLEndDocument xEndDoc; /* EndDoc handler */
ProcXMLNameSpaceStart xNameSpace; /* Namespace declaration handler */
ProcXMLNameSpaceEnd xNameSpaceEnd; /* End namespace declaration handler */
};
/*
* --------------
* Archive extractor:
@ -1810,22 +1730,6 @@ PH7_PRIVATE void *PH7_ExportStdout(ph7_vm *pVm);
PH7_PRIVATE void *PH7_ExportStderr(ph7_vm *pVm);
/* lib.c function prototypes */
#ifndef PH7_DISABLE_BUILTIN_FUNC
PH7_PRIVATE sxi32 SyXMLParserInit(SyXMLParser *pParser, SyMemBackend *pAllocator, sxi32 iFlags);
PH7_PRIVATE sxi32 SyXMLParserSetEventHandler(SyXMLParser *pParser,
void *pUserData,
ProcXMLStartTagHandler xStartTag,
ProcXMLTextHandler xRaw,
ProcXMLSyntaxErrorHandler xErr,
ProcXMLStartDocument xStartDoc,
ProcXMLEndTagHandler xEndTag,
ProcXMLPIHandler xPi,
ProcXMLEndDocument xEndDoc,
ProcXMLDoctypeHandler xDoctype,
ProcXMLNameSpaceStart xNameSpace,
ProcXMLNameSpaceEnd xNameSpaceEnd
);
PH7_PRIVATE sxi32 SyXMLProcess(SyXMLParser *pParser, const char *zInput, sxu32 nByte);
PH7_PRIVATE sxi32 SyXMLParserRelease(SyXMLParser *pParser);
PH7_PRIVATE sxi32 SyArchiveInit(SyArchive *pArch, SyMemBackend *pAllocator, ProcHash xHash, ProcRawStrCmp xCmp);
PH7_PRIVATE sxi32 SyArchiveRelease(SyArchive *pArch);
PH7_PRIVATE sxi32 SyArchiveResetLoopCursor(SyArchive *pArch);


+ 0
- 1311
vm.c
File diff suppressed because it is too large
View File


Loading…
Cancel
Save