From c96a2e557f0a9322c9369a06041e894cc2f11e93 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 18 Jan 2010 14:27:41 +0000 Subject: Make use of libartefact. Not yet tested... --- server/configure.in | 67 +++++++++++++++++++++++++++++------- server/src/Makefile.am | 4 +-- server/src/artefact.cc | 62 +++++++++++++++++++++++++++++++-- server/src/artefact.h | 14 ++++++-- server/src/configuration.cc | 1 + server/src/configuration.h | 1 + server/src/configurationparser.cc | 6 ++++ server/src/queryhandlerpentominos.cc | 17 ++++++--- server/src/queryhandlerpentominos.h | 7 ++-- server/src/transactionhandler.cc | 5 +-- 10 files changed, 154 insertions(+), 30 deletions(-) (limited to 'server') diff --git a/server/configure.in b/server/configure.in index cd5b937..23a7172 100644 --- a/server/configure.in +++ b/server/configure.in @@ -17,15 +17,17 @@ if test x$with_debug == xyes; then fi dnl ====================== -dnl Compile without pentominos support +dnl Compile with artefact support dnl ====================== -AC_ARG_WITH(pentominos, - [ --with-pentominos build with pentominos support (default=yes)], +AC_ARG_WITH(artefact, + [ --with-artefact build with artefact support (default=yes)], [], - [with_pentominos=yes]) -if test x$with_pentominos == xno; then - AC_MSG_WARN([*** Building without pentominos support!]) - AC_DEFINE_UNQUOTED(WITHOUT_PENTOMINOS, , [The project is configured not to use pentomimos]) + [with_artefact=yes]) +if test x$with_artefact == xyes; then + PKG_CHECK_MODULES(ATF, libartefact >= 0.0.2) +else + AC_MSG_WARN([*** Building without artefact support!]) + AC_DEFINE_UNQUOTED(WITHOUT_ARTEFACT, , [The project is configured not to use artefact]) fi dnl ====================== @@ -150,13 +152,52 @@ PKG_CHECK_MODULES(HTTPD, libmicrohttpd >= 0.4.4) dnl ====================== dnl Check for eXpat library dnl ====================== +tmp_CXXFLAGS="$CXXFLAGS" +tmp_CPPFLAGS="$CPPFLAGS" +tmp_CFLAGS="$CFLAGS" +tmp_LDFLAGS="$LDFLAGS" +tmp_LIBS="$LIBS" +CXXFLAGS="" +CPPFLAGS="" +CFLAGS="" +LDFLAGS="" +LIBS="" AC_CHECK_HEADER(expat.h, , AC_MSG_ERROR([*** eXpat header file not found!])) -AC_CHECK_LIB(expat, XML_ParserCreate, , AC_MSG_ERROR([*** eXpat library not found!])) - -AC_SUBST(CFLAGS) -AC_SUBST(CPPFLAGS) -AC_SUBST(CXXFLAGS) -AC_SUBST(LDFLAGS) +AC_CHECK_LIB(expat, XML_ParserCreate, , AC_MSG_ERROR([*** eXpat library not found!])) +EXPAT_CFLAGS="$CXXFLAGS $CPPFLAGS $CFLAGS" +EXPAT_LIBS="$LDFLAGS $LIBS" +CXXFLAGS="$tmp_CXXFLAGS" +CPPFLAGS="$tmp_CPPFLAGS" +CFLAGS="$tmp_CFLAGS" +LDFLAGS="$tmp_LDFLAGS" +LIBS="$tmp_LIBS" +AC_SUBST(EXPAT_CFLAGS) +AC_SUBST(EXPAT_LIBS) + +dnl ====================== +dnl Check for the pthread library +dnl ====================== +tmp_CXXFLAGS="$CXXFLAGS" +tmp_CPPFLAGS="$CPPFLAGS" +tmp_CFLAGS="$CFLAGS" +tmp_LDFLAGS="$LDFLAGS" +tmp_LIBS="$LIBS" +CXXFLAGS="" +CPPFLAGS="" +CFLAGS="" +LDFLAGS="" +LIBS="" +AC_CHECK_HEADER(pthread.h, , AC_MSG_ERROR([*** pthread header file not found!])) +AC_CHECK_LIB(pthread, pthread_mutex_init, , AC_MSG_ERROR([*** pthread library not found!])) +PTHREAD_CFLAGS="$CXXFLAGS $CPPFLAGS $CFLAGS" +PTHREAD_LIBS="$LDFLAGS $LIBS" +CXXFLAGS="$tmp_CXXFLAGS" +CPPFLAGS="$tmp_CPPFLAGS" +CFLAGS="$tmp_CFLAGS" +LDFLAGS="$tmp_LDFLAGS" +LIBS="$tmp_LIBS" +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_LIBS) AC_OUTPUT( Makefile 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 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 @@ -104,6 +104,12 @@ void ConfigurationParser::reload() } catch( ... ) { } + try { + bool b = lookup("artefact_use_ssl"); + Conf::artefact_use_ssl = b; + } catch( ... ) { + } + try { int i = lookup("artefact_poolsize"); Conf::artefact_poolsize = i; 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" -- cgit v1.2.3