summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/database.cc11
-rw-r--r--server/src/database.h11
-rw-r--r--server/src/macroparser.cc18
-rw-r--r--server/src/macroparser.h1
-rw-r--r--server/src/server.cc20
-rw-r--r--server/src/template.h6
-rw-r--r--server/src/templateparser.h7
7 files changed, 49 insertions, 25 deletions
diff --git a/server/src/database.cc b/server/src/database.cc
index 2338bb6..371a870 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -142,11 +142,12 @@ void Database::commit(std::string user,
#endif/*0*/
}
-void Database::putJournal(std::string user,
- std::string cpr,
- Macro &_macro,
- std::string resume,
- time_t now)
+void Database::putResume(std::string user,
+ std::string cpr,
+ Macro &_macro,
+ std::string resume,
+ time_t now,
+ bool store_in_journal)
{
std::string version = _macro.attributes["version"];
std::string macro = _macro.attributes["name"];
diff --git a/server/src/database.h b/server/src/database.h
index 684cd6c..e311584 100644
--- a/server/src/database.h
+++ b/server/src/database.h
@@ -73,11 +73,12 @@ public:
time_t oldest = 0);
// Put an entry in the journal table
- void putJournal(std::string user,
- std::string cpr,
- Macro &_macro,
- std::string resume,
- time_t now);
+ void putResume(std::string user,
+ std::string cpr,
+ Macro &_macro,
+ std::string resume,
+ time_t now,
+ bool store_in_journal);
// Get latest resume of a given macro
std::string getResume(std::string cpr,
diff --git a/server/src/macroparser.cc b/server/src/macroparser.cc
index 356de1f..582c90c 100644
--- a/server/src/macroparser.cc
+++ b/server/src/macroparser.cc
@@ -86,6 +86,11 @@ MacroParser::~MacroParser()
void MacroParser::characterData(std::string &data)
{
+ if(state == RESUME) {
+ assert(m); // No macro present!
+ m->resume.attributes["format"].append(data);
+ }
+
if(state == MAP) {
assert(current_map); // No map present!
current_map->attributes["lua"].append(data);
@@ -112,6 +117,18 @@ void MacroParser::startTag(std::string name, std::map< std::string, std::string>
return;
}
+ // Enable resume parsing
+ if(name == "resume") {
+ if(state != MACRO) error("resume found outside macro.");
+ state = RESUME;
+
+ m->resume.attributes = attributes;
+
+ assert(m); // No macro is currently available, cannot create queries!
+
+ return;
+ }
+
// Enable Query parsing
if(name == "queries") {
if(state != MACRO) error("queries found outside macro.");
@@ -236,6 +253,7 @@ void MacroParser::endTag(std::string name)
if(name == "macro") {
state = UNDEFINED;
}
+ if(name == "resume") state = MACRO;
if(name == "queries") state = MACRO;
if(name == "query") state = QUERIES;
if(name == "maps") state = MACRO;
diff --git a/server/src/macroparser.h b/server/src/macroparser.h
index cbd36ba..843cb55 100644
--- a/server/src/macroparser.h
+++ b/server/src/macroparser.h
@@ -34,6 +34,7 @@ class MacroParser : public SAXParser {
typedef enum {
UNDEFINED,
MACRO,
+ RESUME,
QUERIES,
QUERY,
MAPS,
diff --git a/server/src/server.cc b/server/src/server.cc
index 92afbd0..2f2ee69 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -94,16 +94,20 @@ static std::string handleTransaction(Transaction *transaction,
db->commit(transaction->user, transaction->cpr, *macro, commit.fields);
- std::string resume = resume_parser(macro->attributes["resume"].c_str(), commit);
-
- // if(resume != "") {
+ std::string resume = resume_parser(macro->resume.attributes["format"].c_str(), commit);
+
+ bool store_in_journal =
+ macro->resume.attributes.find("store_in_journal") != macro->resume.attributes.end() &&
+ macro->resume.attributes["store_in_journal"] == "true";
+
+ if(resume != "" && store_in_journal) {
journal_commit(transaction->cpr.c_str(), transaction->user.c_str(),
Conf::journal_commit_addr.c_str(), Conf::journal_commit_port,
resume.c_str(), resume.length());
-
- db->putJournal(transaction->user, transaction->cpr,
- *macro, resume, time(NULL));
- // }
+ }
+
+ db->putResume(transaction->user, transaction->cpr,
+ *macro, resume, time(NULL), store_in_journal);
i++;
}
@@ -205,7 +209,7 @@ static std::string handleTransaction(Transaction *transaction,
if(completed) {
answer += " <resume>";
answer += db->getResume(transaction->cpr, macro.attributes["name"], time(NULL) - Conf::db_max_ttl);
- answer += " </resume>\n";
+ answer += "</resume>\n";
}
answer += " </macro>\n";
diff --git a/server/src/template.h b/server/src/template.h
index d047712..0e016d4 100644
--- a/server/src/template.h
+++ b/server/src/template.h
@@ -51,6 +51,11 @@ public:
std::map< std::string, std::string > attributes;
};
+class Resume {
+public:
+ std::map< std::string, std::string > attributes;
+};
+
class Macro {
public:
std::vector< Query > queries;
@@ -58,6 +63,7 @@ public:
std::vector< Script > scripts;
Widget window;
std::map< std::string, std::string > attributes;
+ Resume resume;
};
class Course {
diff --git a/server/src/templateparser.h b/server/src/templateparser.h
index f69009a..845e605 100644
--- a/server/src/templateparser.h
+++ b/server/src/templateparser.h
@@ -34,13 +34,6 @@ typedef enum {
UNDEFINED,
COURSE,
MACRO,
- QUERIES,
- QUERY,
- MAPS,
- MAP,
- WINDOW,
- LUAPROGRAMS,
- LUAPROGRAM
} ParserState;
class TemplateParser : public SAXParser {