diff options
author | deva <deva> | 2008-03-26 13:04:30 +0000 |
---|---|---|
committer | deva <deva> | 2008-03-26 13:04:30 +0000 |
commit | 6e76c4540e37280d0c161e7d7035e2e9022b18ce (patch) | |
tree | 97dffd6ddc732890c97ca41c7149cb1ac1afac6e /server/src/xmlparser.cc | |
parent | fdb7aadb054f233401a9f3dd882b79ac5ccd5191 (diff) |
Implemented a SAXPaser class, and made the macro and xml parsers use it.
Diffstat (limited to 'server/src/xmlparser.cc')
-rw-r--r-- | server/src/xmlparser.cc | 79 |
1 files changed, 12 insertions, 67 deletions
diff --git a/server/src/xmlparser.cc b/server/src/xmlparser.cc index 6ef7338..71bb753 100644 --- a/server/src/xmlparser.cc +++ b/server/src/xmlparser.cc @@ -35,33 +35,8 @@ static bool done = false; -static void start_hndl(void *p, const char *el, const char **attr) +void XMLParser::startTag(std::string name, std::map< std::string, std::string> attributes) { - Transaction *transaction = (Transaction*)XML_GetUserData(p); - - // printf("Start tag [%s]\n", el); - - // Convert to comfy C++ values... - std::string name = el; - std::map< std::string, std::string > attributes; - - while(*attr) { - std::string at_name = *attr; - attr++; - std::string at_value = *attr; - attr++; - - attributes.insert(make_pair(at_name, at_value)); - } - /* - std::map< std::string, std::string >::iterator i = attributes.begin(); - while(i != attributes.end()) { - printf("%s=%s\n", i->first.c_str(), i->second.c_str()); - i++; - } - */ - - // Do something reasonable with them... if(name == "pracro") { transaction->user = attributes["user"]; transaction->cpr = attributes["cpr"]; @@ -82,54 +57,24 @@ static void start_hndl(void *p, const char *el, const char **attr) } if(name == "field") { - // Field f; - // f.name = attributes["name"]; - // f.value = attributes["value"]; - // transaction->commits.back().fields.push_back(f); transaction->commits.back().fields[attributes["name"]] = attributes["value"]; - // printf("[%s]=[%s]\n", f.name.c_str(), f.value.c_str()); } - } -static void end_hndl(void *p, const char *el) +void XMLParser::endTag(std::string name) { - // printf("End tag [%s]\n", el); - if(!strcmp(el, "pracro")) done = true; + if(name == "pracro") done = true; } -void parse(TCPSocket &socket, Transaction &transaction) +int XMLParser::readData(char *data, size_t size) { + if(done) return 0; + return socket->read(data, size); +} - XML_Parser p = XML_ParserCreate(NULL); - if (! p) { - fprintf(stderr, "Couldn't allocate memory for parser\n"); - // throw Exception(...); - return; - } - - XML_SetUserData(p, &transaction); - XML_UseParserAsHandlerArg(p); - XML_SetElementHandler(p, start_hndl, end_hndl); - - while(!done) { - char buf[32]; - int len; - - memset(buf, 0, sizeof(buf)); - len = socket.read(buf, sizeof(buf) - 1); - - done = len == 0; - - if (! XML_Parse(p, buf, len, done)) { - fprintf(stderr, "Parse error at line %d:\n%s\n", - XML_GetCurrentLineNumber(p), - XML_ErrorString(XML_GetErrorCode(p))); - // throw Exception(...); - return; - } - } - - // printf("%d requests\n", transaction.requests.size()); - +XMLParser::XMLParser(TCPSocket &socket, Transaction &transaction) +{ + this->transaction = &transaction; + this->socket = &socket; + done = false; } |