From 97c6a5d184b8e8c14689ddb99951ad4d71204002 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 5 Dec 2011 10:50:07 +0100 Subject: Change how script code is stored to the Script objects. The std::string code member is there for a reason you know... --- server/src/transactionhandler.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/src/transactionhandler.cc') diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index 5203ee2..ef112ee 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -244,7 +244,7 @@ static std::string handleRequest(Request &request, Environment &env, answer +="\n-- END INCLUDE: '"+spi->attributes["src"]+"'\n"; } } else { - answer += xml_encode(spi->attributes["code"]); + answer += xml_encode(spi->code); } answer += "\n"; spi++; -- cgit v1.2.3 From 8f00317567dab4c825a0eca76a9cae7951edd11f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 6 Dec 2011 14:15:52 +0100 Subject: Clean up the way connections are handled. --- server/src/transactionhandler.cc | 47 ++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'server/src/transactionhandler.cc') diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index ef112ee..7ec38f8 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -40,6 +40,14 @@ #include "widgetgenerator.h" #include "journal.h" +#include "exception.h" + +class NotFoundException : public Exception { +public: + NotFoundException(Request &r) + : Exception("Macro " + r.macro + " not found in template " + r.templ) {} +}; + static std::string error_box(std::string message) { std::string errorbox = @@ -55,31 +63,28 @@ static std::string handleCommits(Transaction &transaction, Environment &env, { std::string answer; - if(transaction.commits.size() > 0) { - - Commits::iterator i = transaction.commits.begin(); - while(i != transaction.commits.end()) { - Commit &commit = *i; - - MacroParser mp(env.macrolist.getLatestVersion(commit.macro)); - mp.parse(); - Macro *macro = mp.getMacro(); - - std::string resume = resume_parser(*macro, commit); - commit.fields["journal.resume"] = resume; - session.commitMacro(transaction, commit, *macro); + Commits::iterator i = transaction.commits.begin(); + while(i != transaction.commits.end()) { + Commit &commit = *i; + + MacroParser mp(env.macrolist.getLatestVersion(commit.macro)); + mp.parse(); + Macro *macro = mp.getMacro(); + + std::string resume = resume_parser(*macro, commit); + commit.fields["journal.resume"] = resume; + session.commitMacro(transaction, commit, *macro); - if(resume != "") { + if(resume != "") { - TemplateParser tp(env.templatelist.getLatestVersion(commit.templ)); - tp.parse(); - Template *templ = tp.getTemplate(); + TemplateParser tp(env.templatelist.getLatestVersion(commit.templ)); + tp.parse(); + Template *templ = tp.getTemplate(); - session.journal()->addEntry(transaction, commit, resume, templ); - } - - i++; + session.journal()->addEntry(transaction, commit, resume, templ); } + + i++; } return answer; -- cgit v1.2.3 From 4edae3f518353bb21a02fcda2dfcff83c5a72fc3 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 26 Jan 2012 12:08:39 +0100 Subject: New onCommit scripting system. --- server/src/transactionhandler.cc | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'server/src/transactionhandler.cc') diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index 7ec38f8..a52dd50 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -28,12 +28,13 @@ #include "transactionhandler.h" #include "macroparser.h" -#include "resumeparser.h" #include "templateparser.h" #include "templateheaderparser.h" #include "courseparser.h" #include "configuration.h" #include "luaquerymapper.h" +#include "luaresume.h" +#include "luaoncommit.h" #include "queryhandlerpentominos.h" #include "queryhandlerpracro.h" #include "xml_encode_decode.h" @@ -60,6 +61,7 @@ static std::string error_box(std::string message) static std::string handleCommits(Transaction &transaction, Environment &env, Session &session) + throw(LUAScript::Exception) { std::string answer; @@ -71,19 +73,32 @@ static std::string handleCommits(Transaction &transaction, Environment &env, mp.parse(); Macro *macro = mp.getMacro(); - std::string resume = resume_parser(*macro, commit); - commit.fields["journal.resume"] = resume; - session.commitMacro(transaction, commit, *macro); + std::string resume; + try { + LUAResume luaresume(transaction, commit); + luaresume.addScripts(macro->resume_scripts); + luaresume.run(); + resume = luaresume.resultString(); + commit.fields["journal.resume"] = resume; + session.commitMacro(transaction, commit, *macro); + } catch(LUAScript::Exception &e) { + throw e; + } - if(resume != "") { - + LUAOnCommit *oncommit = NULL; + if(macro->commit_scripts.size() != 0) { + oncommit = new LUAOnCommit(transaction, commit); + oncommit->addScripts(macro->commit_scripts); + } + + if(resume != "" || oncommit != NULL) { TemplateParser tp(env.templatelist.getLatestVersion(commit.templ)); tp.parse(); Template *templ = tp.getTemplate(); - - session.journal()->addEntry(transaction, commit, resume, templ); - } + session.journal()->addEntry(transaction, commit, resume, templ, oncommit); + } + i++; } @@ -92,6 +107,7 @@ static std::string handleCommits(Transaction &transaction, Environment &env, static std::string handleRequest(Request &request, Environment &env, Session &session) + throw(NotFoundException) { std::string answer; @@ -321,9 +337,9 @@ std::string handleTransaction(Request &request, try { answer += handleCommits(transaction, env, session); - } catch( std::exception &e ) { - ERR(server, "Commit error: %s\n", e.what()); - return error_box(xml_encode(e.what())); + } catch( LUAScript::Exception &e ) { + ERR(server, "Commit error: %s\n", e.msg.c_str()); + return error_box(xml_encode(e.msg)); } try { -- cgit v1.2.3 From b3692e651d97285bab2a175846bca3a23a34311c Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 16 Feb 2012 10:20:51 +0100 Subject: Fix uncaught Exception. --- server/src/transactionhandler.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'server/src/transactionhandler.cc') diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index a52dd50..fd4705a 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -344,6 +344,9 @@ std::string handleTransaction(Request &request, try { answer += handleRequest(request, env, session); + } catch( Exception &e ) { + ERR(server, "Request error: %s\n", e.what()); + return error_box(xml_encode(e.what())); } catch( std::exception &e ) { ERR(server, "Request error: %s\n", e.what()); return error_box(xml_encode(e.what())); -- cgit v1.2.3 From c5cfc6d194ab81cc6d1f1143ebfb8b6f93dddede Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 16 Feb 2012 10:26:21 +0100 Subject: Fix uncaught Exception. --- server/src/transactionhandler.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/src/transactionhandler.cc') diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index fd4705a..d167029 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -344,12 +344,12 @@ std::string handleTransaction(Request &request, try { answer += handleRequest(request, env, session); - } catch( Exception &e ) { - ERR(server, "Request error: %s\n", e.what()); - return error_box(xml_encode(e.what())); } catch( std::exception &e ) { ERR(server, "Request error: %s\n", e.what()); return error_box(xml_encode(e.what())); + } catch( ... ) { + ERR(server, "Unknown exception in handleRequest\n"); + return error_box(xml_encode("Unknown exception in handleRequest.")); } answer += "\n"; -- cgit v1.2.3 From ef0f64024a6ceec6d7a6411bcfaa614f94b03130 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 16 Feb 2012 10:29:14 +0100 Subject: Fix uncaught Exception. --- server/src/transactionhandler.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'server/src/transactionhandler.cc') diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index d167029..6ab3d89 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -107,7 +107,7 @@ static std::string handleCommits(Transaction &transaction, Environment &env, static std::string handleRequest(Request &request, Environment &env, Session &session) - throw(NotFoundException) + throw(NotFoundException, Exception) { std::string answer; @@ -347,9 +347,6 @@ std::string handleTransaction(Request &request, } catch( std::exception &e ) { ERR(server, "Request error: %s\n", e.what()); return error_box(xml_encode(e.what())); - } catch( ... ) { - ERR(server, "Unknown exception in handleRequest\n"); - return error_box(xml_encode("Unknown exception in handleRequest.")); } answer += "\n"; -- cgit v1.2.3