summaryrefslogtreecommitdiff
path: root/server/src/queryhandler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/queryhandler.cc')
-rw-r--r--server/src/queryhandler.cc62
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