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/sessionparser.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'server/src/sessionparser.cc') diff --git a/server/src/sessionparser.cc b/server/src/sessionparser.cc index 6b3653e..8913e3c 100644 --- a/server/src/sessionparser.cc +++ b/server/src/sessionparser.cc @@ -37,6 +37,9 @@ SessionParser::SessionParser() totalbytes = 0; inresume = false; indatabase = false; + invalue = false; + inscript = false; + inenv = false; } SessionParser::~SessionParser() @@ -49,6 +52,26 @@ void SessionParser::characterData(std::string &data) entries[entries.size()-1].resume += data; } + if(inscript) { + Entry &e = entries[entries.size() - 1]; + LUAOnCommit *oncommit = e.oncommit; + std::pair &val = + oncommit->scripts[oncommit->scripts.size() - 1]; + val.first += data; + } + + if(invalue) { + Entry &e = entries[entries.size() - 1]; + LUAOnCommit *oncommit = e.oncommit; + oncommit->values[valuename] += data; + } + + if(inenv) { + Entry &e = entries[entries.size() - 1]; + LUAOnCommit *oncommit = e.oncommit; + oncommit->_env[envid] += data; + } + if(indatabase) { database += data; } @@ -80,12 +103,51 @@ void SessionParser::startTag(std::string name, attributes_t &attr) e.index = atoi(attr["index"].c_str()); e.macro = attr["macro"]; e.user = attr["user"]; + e.oncommit = NULL; entries.push_back(e); } if(name == "resume") { inresume = true; } + + if(name == "oncommit") { + Entry &e = entries[entries.size() - 1]; + if(e.oncommit != NULL) { + ERR(sessionparser, "Multiple oncommit tags in journal!\n"); + return; + } + e.oncommit = new LUAOnCommit(); + } + if(name == "envs") { } + + if(name == "env") { + if(attr["id"] == "ENV_PATIENTID") envid = LUAScript::ENV_PATIENTID; + else if(attr["id"] == "ENV_TEMPLATE") envid = LUAScript::ENV_TEMPLATE; + else if(attr["id"] == "ENV_MACRO") envid = LUAScript::ENV_MACRO; + else if(attr["id"] == "ENV_USER") envid = LUAScript::ENV_USER; + else { + // Unknown env id + return; + } + inenv = true; + } + + if(name == "values") { } + + if(name == "value") { + valuename = attr["name"]; + invalue = true; + } + + if(name == "scripts") {} + + if(name == "script") { + Entry &e = entries[entries.size() - 1]; + LUAOnCommit *oncommit = e.oncommit; + oncommit->addCode("", attr["name"]); + inscript = true; + } } void SessionParser::endTag(std::string name) @@ -96,6 +158,15 @@ void SessionParser::endTag(std::string name) if(name == "database") { indatabase = false; } + if(name == "env") { + inenv = false; + } + if(name == "value") { + invalue = false; + } + if(name == "script") { + inscript = false; + } } void SessionParser::parseError(const char *buf, size_t len, -- cgit v1.2.3