summaryrefslogtreecommitdiff
path: root/server/src/saxparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/saxparser.cc')
-rw-r--r--server/src/saxparser.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/server/src/saxparser.cc b/server/src/saxparser.cc
index 43b6ba3..be7a541 100644
--- a/server/src/saxparser.cc
+++ b/server/src/saxparser.cc
@@ -51,6 +51,8 @@ static void start_hndl(void *p, const char *el, const char **attr)
attributes.insert(make_pair(at_name, at_value));
}
+ if(parser->outertag == "") parser->outertag = name;
+
parser->startTag(name, attributes);
}
@@ -58,6 +60,9 @@ static void end_hndl(void *p, const char *el)
{
SAXParser *parser = (SAXParser*)XML_GetUserData(p);
std::string name = el;
+
+ if(name == parser->outertag) parser->done = true;
+
parser->endTag(name);
}
@@ -75,6 +80,11 @@ SAXParser::SAXParser()
XML_UseParserAsHandlerArg(p);
XML_SetElementHandler(p, start_hndl, end_hndl);
XML_SetCharacterDataHandler(p, character_hndl);
+
+ bufferbytes = 0;
+ totalbytes = 0;
+ done = false;
+
}
SAXParser::~SAXParser()
@@ -100,6 +110,30 @@ int SAXParser::parse()
return 0;
}
+bool SAXParser::parse(char *data, size_t size)
+{
+ bufferbytes = size;
+ totalbytes += bufferbytes;
+
+ if(! XML_Parse(p, data, size, false) ) {
+ if(XML_GetErrorCode(p) == XML_ERROR_JUNK_AFTER_DOC_ELEMENT) return true;
+ parseError(data, size, XML_ErrorString(XML_GetErrorCode(p)), (int)XML_GetCurrentLineNumber(p));
+ return false;
+ }
+
+ if(done) {
+ if(! XML_Parse(p, data, 0, true) ) {
+ if(XML_GetErrorCode(p) == XML_ERROR_JUNK_AFTER_DOC_ELEMENT) return true;
+ parseError(data, 0, XML_ErrorString(XML_GetErrorCode(p)), (int)XML_GetCurrentLineNumber(p));
+ return false;
+ }
+ }
+
+ printf("Got END_OF_DOCUMENT [%s] at %ld\n", outertag.c_str(), XML_GetCurrentByteIndex(p));
+
+ return done;
+}
+
void SAXParser::parseError(char *buf, size_t len, std::string error, int lineno)
{
fprintf(stderr, "SAXParser error at line %d: %s\n", lineno, error.c_str());
@@ -109,6 +143,11 @@ void SAXParser::parseError(char *buf, size_t len, std::string error, int lineno)
fflush(stderr);
}
+unsigned int SAXParser::usedBytes()
+{
+ return bufferbytes + (XML_GetCurrentByteIndex(p) - totalbytes);
+}
+
#ifdef TEST_SAXPARSER
/**