From 965506c3e9ab1dca32c7be51c0271af78721c821 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 30 Jul 2009 07:23:42 +0000 Subject: Updated the example template to contain new tags/attributes. --- server/src/server.cc | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'server/src/server.cc') 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 += "\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()); -- cgit v1.2.3