summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2015-05-09 01:00:13 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2015-07-10 00:06:24 +0200
commit51a118f1ef0c524aef823b42bca3bf5a4ff8ae59 (patch)
tree1ab4a8a8ab68d81a99ea9c160fe0209c6053c82d /lib
parentUpdated expat (diff)
downloadcuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.tar
cuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.tar.gz
cuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.tar.bz2
cuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.tar.lz
cuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.tar.xz
cuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.tar.zst
cuberite-51a118f1ef0c524aef823b42bca3bf5a4ff8ae59.zip
Diffstat (limited to 'lib')
-rw-r--r--lib/luaexpat/lxplib.c37
-rw-r--r--lib/luaexpat/lxplib.h1
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/luaexpat/lxplib.c b/lib/luaexpat/lxplib.c
index 1a36104a8..ff62ed83e 100644
--- a/lib/luaexpat/lxplib.c
+++ b/lib/luaexpat/lxplib.c
@@ -38,6 +38,7 @@ struct lxp_userdata {
int tableref; /* table with callbacks for this parser */
enum XPState state;
luaL_Buffer *b; /* to concatenate sequences of cdata pieces */
+ int bufferCharData; /* whether to buffer cdata pieces */
};
typedef struct lxp_userdata lxp_userdata;
@@ -152,8 +153,13 @@ static void f_CharData (void *ud, const char *s, int len) {
lxp_userdata *xpu = (lxp_userdata *)ud;
if (xpu->state == XPSok) {
if (getHandle(xpu, CharDataKey) == 0) return; /* no handle */
- xpu->state = XPSstring;
- luaL_buffinit(xpu->L, xpu->b);
+ if(xpu->bufferCharData != 0) {
+ xpu->state = XPSstring;
+ luaL_buffinit(xpu->L, xpu->b);
+ } else {
+ lua_pushlstring(xpu->L, s, len);
+ docall(xpu, 1, 0);
+ }
}
if (xpu->state == XPSstring)
luaL_addlstring(xpu->b, s, len);
@@ -326,6 +332,16 @@ static void f_StartDoctypeDecl (void *ud, const XML_Char *doctypeName,
docall(xpu, 4, 0);
}
+static void f_XmlDecl (void *ud, const XML_Char *version,
+ const XML_Char *encoding,
+ int standalone) {
+ lxp_userdata *xpu = (lxp_userdata *)ud;
+ if (getHandle(xpu, XmlDeclKey) == 0) return; /* no handle */
+ lua_pushstring(xpu->L, version);
+ lua_pushstring(xpu->L, encoding);
+ lua_pushboolean(xpu->L, standalone);
+ docall(xpu, 3, 0);
+}
/* }====================================================== */
@@ -346,7 +362,7 @@ static void checkcallbacks (lua_State *L) {
"Default", "DefaultExpand", "StartElement", "EndElement",
"ExternalEntityRef", "StartNamespaceDecl", "EndNamespaceDecl",
"NotationDecl", "NotStandalone", "ProcessingInstruction",
- "UnparsedEntityDecl", "StartDoctypeDecl", NULL};
+ "UnparsedEntityDecl", "StartDoctypeDecl", "XmlDecl", NULL};
if (hasfield(L, "_nonstrict")) return;
lua_pushnil(L);
while (lua_next(L, 1)) {
@@ -364,8 +380,10 @@ static void checkcallbacks (lua_State *L) {
static int lxp_make_parser (lua_State *L) {
XML_Parser p;
+ int bufferCharData = (lua_type(L, 3) != LUA_TBOOLEAN) || (lua_toboolean(L, 3) != 0);
char sep = *luaL_optstring(L, 2, "");
lxp_userdata *xpu = createlxp(L);
+ xpu->bufferCharData = bufferCharData;
p = xpu->parser = (sep == '\0') ? XML_ParserCreate(NULL) :
XML_ParserCreateNS(NULL, sep);
if (!p)
@@ -401,6 +419,8 @@ static int lxp_make_parser (lua_State *L) {
XML_SetUnparsedEntityDeclHandler(p, f_UnparsedEntityDecl);
if (hasfield(L, StartDoctypeDeclKey))
XML_SetStartDoctypeDeclHandler(p, f_StartDoctypeDecl);
+ if (hasfield(L, XmlDeclKey))
+ XML_SetXmlDeclHandler(p, f_XmlDecl);
return 1;
}
@@ -524,11 +544,18 @@ static int lxp_stop (lua_State *L) {
#define luaL_Reg luaL_reg
#endif
+static int lxp_getcurrentbytecount (lua_State* L) {
+ lxp_userdata *xpu = checkparser(L, 1);
+ lua_pushinteger(L, XML_GetCurrentByteCount(xpu->parser));
+ return 1;
+}
+
static const struct luaL_Reg lxp_meths[] = {
{"parse", lxp_parse},
{"close", lxp_close},
{"__gc", parser_gc},
{"pos", lxp_pos},
+ {"getcurrentbytecount", lxp_getcurrentbytecount},
{"setencoding", lxp_setencoding},
{"getcallbacks", getcallbacks},
{"getbase", getbase},
@@ -588,12 +615,8 @@ int luaopen_lxp (lua_State *L) {
luaL_setfuncs (L, lxp_meths, 0);
lua_pop (L, 1); /* remove metatable */
- // _X 2013_04_09: Modified to allow embedding
- luaL_openlib (L, "lxp", lxp_funcs, 0);
- /*
lua_newtable (L);
luaL_setfuncs (L, lxp_funcs, 0);
- */
set_info (L);
return 1;
}
diff --git a/lib/luaexpat/lxplib.h b/lib/luaexpat/lxplib.h
index 9c0be4f78..4c7084c46 100644
--- a/lib/luaexpat/lxplib.h
+++ b/lib/luaexpat/lxplib.h
@@ -20,5 +20,6 @@
#define ProcessingInstructionKey "ProcessingInstruction"
#define UnparsedEntityDeclKey "UnparsedEntityDecl"
#define StartDoctypeDeclKey "StartDoctypeDecl"
+#define XmlDeclKey "XmlDecl"
int luaopen_lxp (lua_State *L);