diff options
author | deva <deva> | 2008-09-30 12:49:34 +0000 |
---|---|---|
committer | deva <deva> | 2008-09-30 12:49:34 +0000 |
commit | e2120257dda4d91b48bb031a96edda810ce30dfb (patch) | |
tree | f83eadbbb6d84fd0d6fb7d7a4d3e342535854795 /server/src/queryhandler.cc | |
parent | a01f655935558e0f71253907fd8e4c57b0d2f64c (diff) |
Changed SAXParser parse method to take a buffer and a size instead of a c++ string. Made the queryhandler use a read loop, parsing on-the-fly to determine when the entire document has been read.
Diffstat (limited to 'server/src/queryhandler.cc')
-rw-r--r-- | server/src/queryhandler.cc | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/server/src/queryhandler.cc b/server/src/queryhandler.cc index 29e8fda..248f1e6 100644 --- a/server/src/queryhandler.cc +++ b/server/src/queryhandler.cc @@ -54,6 +54,8 @@ // For ioctl #include <sys/ioctl.h> +#include "queryparser.h" + typedef struct { in_addr_t ip; time_t time; @@ -138,12 +140,7 @@ QueryHandler::QueryHandler(TCPSocket *socket, std::string cpr) this->socket = socket; } -void QueryHandler::addQuery(Query &query) -{ - queries.push_back(query); -} - -std::string QueryHandler::exec() +QueryResult QueryHandler::exec(Query &query) { time_t timestamp = time(NULL); std::string uid = getUID("eth0"); @@ -186,56 +183,51 @@ std::string QueryHandler::exec() printf(buf); #endif/*WITH_DEBUG*/ - std::vector< Query >::iterator j = queries.begin(); - while(j != queries.end()) { - Query query = *j; - - sprintf(buf, " <pentominos:query format=\"pracroxml\"\n" - " device_id=\"%s\"\n" - " device_type=\"%s\"\n" - " filter=\"latest\"\n" - " location=\"all\"/>\n", - query.attributes["class"].c_str(), - query.attributes["class"].c_str()); - + sprintf(buf, " <pentominos:query format=\"pracroxml\"\n" + " device_id=\"%s\"\n" + " device_type=\"%s\"\n" + " filter=\"latest\"\n" + " location=\"all\"/>\n", + query.attributes["class"].c_str(), + query.attributes["class"].c_str()); + #ifndef WITHOUT_PENTOMINOS - socket->write(buf, strlen(buf)); + socket->write(buf, strlen(buf)); #endif/*WITHOUT_PENTOMINOS*/ #ifdef WITH_DEBUG - printf(buf); + printf(buf); #endif/*WITH_DEBUG*/ - j++; - } - - sprintf(buf, "</artefact>\n"); + sprintf(buf, "</artefact>"); #ifndef WITHOUT_PENTOMINOS socket->write(buf, strlen(buf)); - // Terminate - char term[] = "\0"; - socket->write(term, 1); #endif/*WITHOUT_PENTOMINOS*/ #ifdef WITH_DEBUG printf(buf); #endif/*WITH_DEBUG*/ - std::string answer; + QueryResult result; #ifndef WITHOUT_PENTOMINOS - // Wait for answer + QueryParser parser; + + int asize; char abuf[64]; - int res; - do { + memset(abuf, 0, sizeof(abuf)); + + // Read until we've got the entire result. + while((asize = socket->read(abuf, sizeof(abuf) - 1)) != -1 && + parser.parse(abuf, asize) == false) { memset(abuf, 0, sizeof(abuf)); - res = socket->read(abuf, sizeof(abuf) - 1); - answer += abuf; - } while(res); + } + + result = parser.result; #endif/*WITHOUT_PENTOMINOS*/ - return answer; + return result; } #ifdef TEST_QUERYHANDLER |