summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authordeva <deva>2010-01-18 14:27:41 +0000
committerdeva <deva>2010-01-18 14:27:41 +0000
commitc96a2e557f0a9322c9369a06041e894cc2f11e93 (patch)
tree090048d431aa41b26de0332f120d48c8225c4abf /server/src
parent2f38783e005e43efd66727371fb0607ca9dfee29 (diff)
Make use of libartefact. Not yet tested...
Diffstat (limited to 'server/src')
-rw-r--r--server/src/Makefile.am4
-rw-r--r--server/src/artefact.cc62
-rw-r--r--server/src/artefact.h14
-rw-r--r--server/src/configuration.cc1
-rw-r--r--server/src/configuration.h1
-rw-r--r--server/src/configurationparser.cc6
-rw-r--r--server/src/queryhandlerpentominos.cc17
-rw-r--r--server/src/queryhandlerpentominos.h7
-rw-r--r--server/src/transactionhandler.cc5
9 files changed, 100 insertions, 17 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index 66ee4cc..1ff8a3a 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -3,11 +3,11 @@ bin_PROGRAMS = pracrod macrotool
pracrod_LDADD = $(LD_EFENCE) $(PQXX_LIBS) $(CONFIG_LIBS) \
$(LUA_LIBS) $(HTTPD_LIBS) $(PTHREAD_LIBS) \
- $(EXPAT_LIBS)
+ $(EXPAT_LIBS) $(ATF_LIBS)
pracrod_CXXFLAGS = $(PQXX_CXXFLAGS) $(CONFIG_CXXFLAGS) \
$(LUA_CXXFLAGS) $(HTTPD_CFLAGS) $(EXPAT_CFLAGS) \
- $(PTHREAD_CFLAGS)
+ $(PTHREAD_CFLAGS) $(ATF_CFLAGS)
pracrod_SOURCES = \
pracrod.cc \
diff --git a/server/src/artefact.cc b/server/src/artefact.cc
index 836e5a9..cc29b77 100644
--- a/server/src/artefact.cc
+++ b/server/src/artefact.cc
@@ -30,13 +30,71 @@
#include "debug.h"
#include "configuration.h"
+#include "queryparser.h"
+
Artefact::Artefact()
{
#ifndef WITHOUT_PENTOMINOS
PRACRO_DEBUG(artefact, "Creating artefact connection %s : %d",
- Conf::artefact_addr.c_str(), Conf::artefact_port)
- socket.connect(Conf::artefact_addr, Conf::artefact_port);
+ Conf::artefact_addr.c_str(), Conf::artefact_port);
#endif/*WITHOUT_PENTOMINOS*/
+
+ atfh = atf_init();
+ if(!atfh) PRACRO_ERR(artefact, "Out of memory!\n");
+
+ conn = atf_connect(atfh,
+ Conf::artefact_addr.c_str(),
+ Conf::artefact_port,
+ Conf::artefact_use_ssl);
+}
+
+Artefact::~Artefact()
+{
+ atf_disconnect(conn);
+ atf_close(atfh);
+}
+
+QueryResult Artefact::exec(Query &query,
+ std::string patientid,
+ std::string user)
+{
+ QueryParser parser;
+
+ atf_transaction_t *trans = atf_new_transaction(conn, patientid.c_str());
+ atf_querylist_t *qlist = atf_new_querylist(trans, user.c_str());
+
+ atf_id id = atf_add_query(qlist,
+ query.attributes["class"].c_str(),
+ 0/*oldest*/, "xml"/*replyformat*/);
+
+ atf_reply_t *reply = atf_commit(trans, NULL, qlist);
+
+ atf_status_t status = atf_get_reply_status(reply, id);
+
+ switch(status) {
+ case ATF_STATUS_OK:
+ {
+ size_t bufsize = atf_get_reply_size(reply, id);
+ char *buf = new char[bufsize];
+
+ ssize_t size = atf_get_reply_data(reply, id, buf, size);
+ parser.parse(buf, size);
+
+ delete[] buf;
+ }
+ break;
+
+ case ATF_STATUS_ERROR:
+ PRACRO_ERR(artefact, "Error in artefact query.\n");
+ break;
+ }
+
+ atf_free_reply(reply);
+
+ atf_free_querylist(qlist);
+ atf_free_transaction(trans);
+
+ return parser.result;
}
diff --git a/server/src/artefact.h b/server/src/artefact.h
index 15dcaa0..7eb1a6b 100644
--- a/server/src/artefact.h
+++ b/server/src/artefact.h
@@ -28,15 +28,23 @@
#ifndef __PRACRO_ARTEFACT_H__
#define __PRACRO_ARTEFACT_H__
-// TODO: use libartefact here...
+#include "template.h"
+#include "queryresult.h"
-#include "tcpsocket.h"
+#include <libartefact.h>
class Artefact {
public:
Artefact();
+ ~Artefact();
- TCPSocket socket;
+ QueryResult exec(Query &query,
+ std::string patientid,
+ std::string user);
+
+private:
+ atf_handle_t *atfh;
+ atf_connection_t *conn;
};
#endif/*__PRACRO_ARTEFACT_H__*/
diff --git a/server/src/configuration.cc b/server/src/configuration.cc
index 4d61079..ace07e7 100644
--- a/server/src/configuration.cc
+++ b/server/src/configuration.cc
@@ -40,6 +40,7 @@ time_t Conf::pentominos_max_ttl = 7 * 60 * 60 * 24;
std::string Conf::artefact_addr = "localhost";
port_t Conf::artefact_port = 11108;
+bool Conf::artefact_use_ssl = false;
int Conf::artefact_poolsize = 1;
diff --git a/server/src/configuration.h b/server/src/configuration.h
index 4b5cf09..d077806 100644
--- a/server/src/configuration.h
+++ b/server/src/configuration.h
@@ -47,6 +47,7 @@ namespace Conf {
extern std::string artefact_addr;
extern port_t artefact_port;
+ extern bool artefact_use_ssl;
extern int artefact_poolsize;
diff --git a/server/src/configurationparser.cc b/server/src/configurationparser.cc
index d16920f..3823ee9 100644
--- a/server/src/configurationparser.cc
+++ b/server/src/configurationparser.cc
@@ -105,6 +105,12 @@ void ConfigurationParser::reload()
}
try {
+ bool b = lookup("artefact_use_ssl");
+ Conf::artefact_use_ssl = b;
+ } catch( ... ) {
+ }
+
+ try {
int i = lookup("artefact_poolsize");
Conf::artefact_poolsize = i;
} catch( ... ) {
diff --git a/server/src/queryhandlerpentominos.cc b/server/src/queryhandlerpentominos.cc
index 4abf5da..b67f731 100644
--- a/server/src/queryhandlerpentominos.cc
+++ b/server/src/queryhandlerpentominos.cc
@@ -66,7 +66,7 @@ typedef struct {
} UID;
#define SIOCGIFCONF 0x8912 // get iface list
-
+/*
static in_addr_t getIP(const char *interface)
{
in_addr_t ret = 0;
@@ -116,6 +116,7 @@ static unsigned short getCounter()
return counter++;
}
+
static UID uid = {0,0,0,0};
static std::string getUID(const char *interface)
{
@@ -133,16 +134,22 @@ static std::string getUID(const char *interface)
sprintf(buf, "%08x%08x%04x%04x", uid.ip, (unsigned int)uid.time, uid.pid, uid.count);
return std::string(buf);
}
+*/
-
-QueryHandlerPentominos::QueryHandlerPentominos(Artefact &atf, std::string cpr)
+QueryHandlerPentominos::QueryHandlerPentominos(Artefact &atf,
+ std::string patientid,
+ std::string user)
: QueryHandler(), artefact(atf)
{
- this->cpr = cpr;
+ this->patientid = patientid;
+ this->user = user;
}
QueryResult QueryHandlerPentominos::exec(Query &query)
{
+ return artefact.exec(query, patientid, user);
+
+#if 0
time_t timestamp = time(NULL);
std::string uid = getUID("eth0");
@@ -225,6 +232,8 @@ QueryResult QueryHandlerPentominos::exec(Query &query)
result.print();
return result;
+#endif
+ return QueryResult();
}
#ifdef TEST_QUERYHANDLERPENTOMINOS
diff --git a/server/src/queryhandlerpentominos.h b/server/src/queryhandlerpentominos.h
index 4c5e932..b96c097 100644
--- a/server/src/queryhandlerpentominos.h
+++ b/server/src/queryhandlerpentominos.h
@@ -41,7 +41,9 @@
*/
class QueryHandlerPentominos : public QueryHandler {
public:
- QueryHandlerPentominos(Artefact &artefact, std::string cpr);
+ QueryHandlerPentominos(Artefact &artefact,
+ std::string patientid,
+ std::string user);
~QueryHandlerPentominos() {}
// Execute all queries.
@@ -49,7 +51,8 @@ public:
private:
Artefact &artefact;
- std::string cpr;
+ std::string patientid;
+ std::string user;
};
#endif/*__PRACRO_QUERYHANDLERPENTOMINOS_H__*/
diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc
index 65da013..a042a6b 100644
--- a/server/src/transactionhandler.cc
+++ b/server/src/transactionhandler.cc
@@ -167,7 +167,7 @@ static std::string handleRequest(Transaction &transaction, Environment &env, Ses
if(service == "pentominos") {
// Send the queries to Pentominos (if any)
- QueryHandlerPentominos qh(*atf, transaction.cpr);
+ QueryHandlerPentominos qh(*atf, transaction.cpr, "pracrod");
QueryResult queryresult = qh.exec(*qi);
lqm.addQueryResult(queryresult);
@@ -263,11 +263,8 @@ std::string handleTransaction(Transaction &transaction, Environment &env, Sessio
}
#ifdef TEST_TRANSACTIONHANDLER
-//Additional dependency files
//deps:
-//Required cflags (autoconf vars may be used)
//cflags: -I..
-//Required link options (autoconf vars may be used)
//libs:
#include "test.h"