diff options
Diffstat (limited to 'server/src/server.cc')
-rw-r--r-- | server/src/server.cc | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/server/src/server.cc b/server/src/server.cc index 3ddb795..924ad84 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -55,6 +55,7 @@ #include "xml_encode_decode.h" #include "macrolist.h" +#include "templatelist.h" #include "versionstr.h" static std::string error_box(std::string message) @@ -112,7 +113,8 @@ static std::string handleRequest(Transaction *transaction, TCPSocket &pentominos_socket, Database &db, JournalWriter &journalwriter, - MacroList ¯olist) + MacroList ¯olist, + TemplateList &templatelist) { std::string answer; @@ -124,7 +126,7 @@ static std::string handleRequest(Transaction *transaction, request.macro.c_str(), request.course.c_str()); // Read and parse the template file. - TemplateParser tp(request.course); + TemplateParser tp(templatelist.getLatestVersion(request.course)); tp.parse(); Template *templ = tp.getTemplate(); @@ -254,7 +256,8 @@ static std::string handleTransaction(Transaction *transaction, TCPSocket &pentominos_socket, Database &db, JournalWriter &journalwriter, - MacroList ¯olist) + MacroList ¯olist, + TemplateList &templatelist) { std::string answer; answer += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; @@ -268,7 +271,8 @@ static std::string handleTransaction(Transaction *transaction, } try { - answer += handleRequest(transaction, pentominos_socket, db, journalwriter, macrolist); + answer += handleRequest(transaction, pentominos_socket, db, journalwriter, + macrolist, templatelist); } catch( std::exception &e ) { PRACRO_ERR(server, "Request error: %s\n", e.what()); return error_box(xml_encode(e.what())); @@ -294,18 +298,7 @@ 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++; - } + TemplateList templatelist(Conf::xml_basedir + "/templates"); ssize_t size; char buf[4096]; @@ -332,7 +325,8 @@ 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, macrolist)); + socket->write(handleTransaction(transaction, pentominos_socket, + db, journalwriter, macrolist, templatelist)); size = size - parser->usedBytes(); if(size) { strcpy(buf, buf + parser->usedBytes()); |