From 7e349e2789a633a6014baea63aeb7932e024c917 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 22 Jul 2009 15:00:29 +0000 Subject: Changed the way the macros are looked up in the filesystem (now they are parsed and indexed using version numbers). Updated all unit tests, to compile and run again. --- server/src/server.cc | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'server/src/server.cc') diff --git a/server/src/server.cc b/server/src/server.cc index 2641b8a..6e480ed 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -54,6 +54,9 @@ #include "journal_commit.h" #include "xml_encode_decode.h" +#include "macrolist.h" +#include "version.h" + static std::string error_box(std::string message) { std::string errorbox = @@ -79,7 +82,8 @@ public: static std::string handleTransaction(Transaction *transaction, TCPSocket *pentominos_socket, Database *db, - JournalWriter &journalwriter) + JournalWriter &journalwriter, + MacroList ¯olist) { std::string answer; answer += "\n"; @@ -93,8 +97,8 @@ static std::string handleTransaction(Transaction *transaction, Commits::iterator i = transaction->commits.begin(); while(i != transaction->commits.end()) { Commit &commit = *i; - - MacroParser mp(commit.macro); + + MacroParser mp(macrolist.getLatestVersion(commit.macro)); mp.parse(); Macro *macro = mp.getMacro(); @@ -173,7 +177,7 @@ static std::string handleTransaction(Transaction *transaction, ) { foundmacro = true; - MacroParser mp(macro.attributes["name"]); + MacroParser mp(macrolist.getLatestVersion(macro.attributes["name"])); mp.parse(); Macro *m = mp.getMacro(); answer += " caption=\"" + m->window.attributes["caption"] + "\""; @@ -225,7 +229,7 @@ static std::string handleTransaction(Transaction *transaction, answer += widgetgenerator(transaction->cpr, *m, lqm, db); } else { // only find macro title - MacroParser mp(macro.attributes["name"]); + MacroParser mp(macrolist.getLatestVersion(macro.attributes["name"])); mp.parse(); Macro *m = mp.getMacro(); answer += " caption=\"" + m->window.attributes["caption"] + "\""; @@ -275,6 +279,21 @@ static void handleConnection(TCPSocket *socket) JournalWriter journalwriter(Conf::journal_commit_addr.c_str(), Conf::journal_commit_port); + MacroList macrolist(Conf::xml_basedir + "/macros"); + + MacroList::iterator i = macrolist.begin(); + while(i != macrolist.end()) { + MacroListItem::iterator j = i->second.begin(); + while(j != i->second.end()) { + PRACRO_DEBUG(server, "%s - v%s file: %s\n", + i->first.c_str(), + ((std::string)j->first).c_str(), + j->second.c_str()); + j++; + } + i++; + } + ssize_t size; char buf[4096]; @@ -300,7 +319,7 @@ static void handleConnection(TCPSocket *socket) if(parser->parse(buf, size)) { PRACRO_DEBUG(server, "Got complete XML document %d bytes used, %d bytes in current buffer.\n", parser->usedBytes(), size); - socket->write(handleTransaction(transaction, &pentominos_socket, db, journalwriter)); + socket->write(handleTransaction(transaction, &pentominos_socket, db, journalwriter, macrolist)); size = size - parser->usedBytes(); delete transaction; transaction = NULL; @@ -398,6 +417,8 @@ void server() #ifdef TEST_SERVER +bool pracro_is_running = true; + char request[] = "\n" "\n" @@ -406,9 +427,6 @@ char request[] = int main() { - Configuration conf("../etc/pracrod.conf"); - initConfig(&conf); - switch(fork()) { case -1: // error return 1; @@ -420,13 +438,12 @@ int main() default: // parent { TCPSocket socket; - int port = config()->lookup("port"); - socket.connect("localhost", port); + socket.connect("localhost", Conf::server_port); socket.write(request); char buf[32]; memset(buf, 0, sizeof(buf)); - while(socket.read(buf, 31)) { + while(socket.read(buf, 31, 1000)) { printf(buf); fflush(stdout); memset(buf, 0, sizeof(buf)); } -- cgit v1.2.3