summaryrefslogtreecommitdiff
path: root/server/src/server.cc
diff options
context:
space:
mode:
authordeva <deva>2008-06-04 08:16:12 +0000
committerdeva <deva>2008-06-04 08:16:12 +0000
commit39bd5c058ea842db10fc56ee153ec338e0d24f0f (patch)
treeee5acf43b7bc2c00908ed8715fbfc74cdb0ea15d /server/src/server.cc
parent0febf6ea9cbd1a6e04e41339fc46d2e6b07da5e7 (diff)
Introduced the errorbox to communicate server errors to the client.
Diffstat (limited to 'server/src/server.cc')
-rw-r--r--server/src/server.cc256
1 files changed, 139 insertions, 117 deletions
diff --git a/server/src/server.cc b/server/src/server.cc
index f74c2b0..a896102 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -47,140 +47,162 @@
#include "resumeparser.h"
#include "journal_commit.h"
-static void connection(TCPSocket &socket)
+static std::string error_box(std::string message)
{
- Transaction transaction;
- TransactionParser parser(socket, transaction);
- parser.parse();
+ std::string errorbox;
+
+ errorbox += " <course name=\"error\">\n";
+ errorbox += " <macro name=\"error\">\n";
+ errorbox += " <window caption=\"ERROR!\" height=\"240\" layout=\"vbox\" "
+ "name=\"err\" width=\"320\">\n";
+ errorbox += " <textedit name=\"errorlabel\" value=\"";
+ errorbox += message;
+ errorbox += "\"/>\n";
+ errorbox += " <button action=\"cancel\" caption=\"Luk\" name=\"cancel\"/>\n";
+ errorbox += " </window>\n";
+ errorbox += " </macro>\n";
+ errorbox += " </course>\n";
+
+ return errorbox;
+}
+static void connection(TCPSocket &socket)
+{
socket.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
socket.write("<pracro version=\"1.0\">\n");
- Database db;
-
- //
- // Handle commits
- //
- if(transaction.commits.size() > 0) {
- Commits::iterator i = transaction.commits.begin();
- while(i != transaction.commits.end()) {
- Commit &commit = *i;
-
- /*
- Macro macro;
- MacroParser parser(commit.macro, macro);
- parser.parse();
- */
-
-
- Macro macro;
- macro.attributes["name"] = commit.macro;
- macro.attributes["version"] = "1.0";//commit.version;
-
- db.commit(transaction.user, transaction.cpr, macro, commit.fields);
-
- /*
- std::string resume = resume_parser(macro.format.c_str(), commit);
-
- std::string journal_commit_addr = config()->lookup("journal_commit_addr");
- int journal_commit_port = config()->lookup("journal_commit_port");
-
- journal_commit(transaction.cpr.c_str(), transaction.user.c_str(),
- journal_commit_addr.c_str(), journal_commit_port,
- resume.c_str(), resume.length());
- */
- i++;
+ try {
+ Transaction transaction;
+ TransactionParser parser(socket, transaction);
+ parser.parse();
+
+ Database db;
+
+ //
+ // Handle commits
+ //
+ if(transaction.commits.size() > 0) {
+ Commits::iterator i = transaction.commits.begin();
+ while(i != transaction.commits.end()) {
+ Commit &commit = *i;
+
+ /*
+ Macro macro;
+ MacroParser parser(commit.macro, macro);
+ parser.parse();
+ */
+
+ Macro macro;
+ macro.attributes["name"] = commit.macro;
+ macro.attributes["version"] = "1.0";//commit.version;
+
+ db.commit(transaction.user, transaction.cpr, macro, commit.fields);
+
+ /*
+ std::string resume = resume_parser(macro.format.c_str(), commit);
+
+ std::string journal_commit_addr = config()->lookup("journal_commit_addr");
+ int journal_commit_port = config()->lookup("journal_commit_port");
+
+ journal_commit(transaction.cpr.c_str(), transaction.user.c_str(),
+ journal_commit_addr.c_str(), journal_commit_port,
+ resume.c_str(), resume.length());
+ */
+ i++;
+ }
}
- }
-
- //
- // Handle requests
- //
- Requests::iterator i = transaction.requests.begin();
- while(i != transaction.requests.end()) {
- Request &request = *i;
-
- printf("Handling request - macro: %s, course: %s\n", request.macro.c_str(), request.course.c_str());
-
- // Read and parse the template file.
- TemplateParser tp(request.course);
- tp.parse();
-
- Template *templ = tp.getTemplate();
-
- // Send the queries to Pentominos (if any)
- TCPSocket s;
- s.connect("localhost", 11108);
- QueryHandler qh(&s, transaction.cpr);
- std::vector< Macro >::iterator mi = templ->course.macroes.begin();
- while(mi != templ->course.macroes.end()) {
- Macro &macro = (*mi);
- if(macro.attributes["name"] == request.macro) {
- std::vector< Query >::iterator qi = macro.queries.begin();
- while(qi != macro.queries.end()) {
- qh.addQuery(*qi);
+ //
+ // Handle requests
+ //
+ Requests::iterator i = transaction.requests.begin();
+ while(i != transaction.requests.end()) {
+ Request &request = *i;
+
+ printf("Handling request - macro: %s, course: %s\n", request.macro.c_str(), request.course.c_str());
+
+ // Read and parse the template file.
+ TemplateParser tp(request.course);
+ tp.parse();
+
+ Template *templ = tp.getTemplate();
+
+ // Send the queries to Pentominos (if any)
+ TCPSocket s;
+ s.connect("localhost", 11108);
+ QueryHandler qh(&s, transaction.cpr);
+
+ std::vector< Macro >::iterator mi = templ->course.macroes.begin();
+ while(mi != templ->course.macroes.end()) {
+ Macro &macro = (*mi);
+ if(macro.attributes["name"] == request.macro) {
+ std::vector< Query >::iterator qi = macro.queries.begin();
+ while(qi != macro.queries.end()) {
+ qh.addQuery(*qi);
qi++;
+ }
}
- }
mi++;
- }
- std::string result = qh.exec();
-
- printf("Got result: [%s]\n", result.c_str());
-
- // Parse the result from the queries to pentominos
- QueryParser qp(result);
- qp.parse();
-
- // Map the results
- LUAQueryMapper lqm(qp.result);
-
- socket.write(" <course name=\"");
- socket.write(templ->course.attributes["name"]);
- socket.write("\">\n");
-
- // Generate the macro and return it to the client
- std::vector< Macro >::iterator mi2 = templ->course.macroes.begin();
- while(mi2 != templ->course.macroes.end()) {
- Macro &macro = (*mi2);
-
- socket.write(" <macro name=\"");
- socket.write(macro.attributes["name"]);
+ }
+ std::string result = qh.exec();
+
+ printf("Got result: [%s]\n", result.c_str());
+
+ // Parse the result from the queries to pentominos
+ QueryParser qp(result);
+ qp.parse();
+
+ // Map the results
+ LUAQueryMapper lqm(qp.result);
+
+ socket.write(" <course name=\"");
+ socket.write(templ->course.attributes["name"]);
socket.write("\">\n");
-
- if(macro.attributes["name"] == request.macro) {
- // Handle lua programs
- if(macro.luaprograms.size()) {
- socket.write(" <luaprograms>\n");
-
- std::vector< LUAProgram >::iterator lpi = macro.luaprograms.begin();
- while(lpi != macro.luaprograms.end()) {
- socket.write(" <luaprogram name=\"");
- socket.write(lpi->attributes["name"]);
- socket.write("\">\n");
+
+ // Generate the macro and return it to the client
+ std::vector< Macro >::iterator mi2 = templ->course.macroes.begin();
+ while(mi2 != templ->course.macroes.end()) {
+ Macro &macro = (*mi2);
+
+ socket.write(" <macro name=\"");
+ socket.write(macro.attributes["name"]);
+ socket.write("\">\n");
+
+ if(macro.attributes["name"] == request.macro) {
+ // Handle lua programs
+ if(macro.luaprograms.size()) {
+ socket.write(" <luaprograms>\n");
- socket.write(lpi->attributes["lua"]);
-
- socket.write("\n </luaprogram>\n");
-
- lpi++;
+ std::vector< LUAProgram >::iterator lpi = macro.luaprograms.begin();
+ while(lpi != macro.luaprograms.end()) {
+ socket.write(" <luaprogram name=\"");
+ socket.write(lpi->attributes["name"]);
+ socket.write("\">\n");
+
+ socket.write(lpi->attributes["lua"]);
+
+ socket.write("\n </luaprogram>\n");
+
+ lpi++;
+ }
+
+ socket.write(" </luaprograms>\n");
}
-
- socket.write(" </luaprograms>\n");
+
+ widgetgenerator(socket, macro, lqm, db);
}
- widgetgenerator(socket, macro, lqm, db);
+ socket.write(" </macro>\n");
+
+ mi2++;
}
-
- socket.write(" </macro>\n");
-
- mi2++;
+
+ socket.write(" </course>\n");
+
+ i++;
}
-
- socket.write(" </course>\n");
-
- i++;
+ } catch(std::exception &e) {
+ socket.write(error_box( e.what()));
}
socket.write("</pracro>\n");