diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/Makefile.am | 2 | ||||
-rw-r--r-- | server/src/journal_commit.cc | 34 | ||||
-rw-r--r-- | server/src/journal_commit.h | 2 | ||||
-rw-r--r-- | server/src/macrotool_dump.cc | 26 | ||||
-rw-r--r-- | server/src/saxparser.cc | 8 | ||||
-rw-r--r-- | server/src/server.cc | 28 | ||||
-rw-r--r-- | server/src/template.h | 8 | ||||
-rw-r--r-- | server/src/templateheaderparser.cc | 2 | ||||
-rw-r--r-- | server/src/templateparser.cc | 33 | ||||
-rw-r--r-- | server/src/templateparser.h | 4 | ||||
-rw-r--r-- | server/src/transaction.h | 4 | ||||
-rw-r--r-- | server/src/transactionparser.cc | 10 |
12 files changed, 77 insertions, 84 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am index 5516458..c8e1c51 100644 --- a/server/src/Makefile.am +++ b/server/src/Makefile.am @@ -225,6 +225,8 @@ test_macroparser: $(TEST_MACROPARSER_FILES) TEST_SERVER_FILES = \ server.cc \ templateparser.cc \ + templatelist.cc \ + templateheaderparser.cc \ queryparser.cc \ queryhandlerpentominos.cc \ journal_commit.cc \ diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index 4992545..21d40c3 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -207,46 +207,46 @@ JournalWriter::JournalWriter(std::string host, unsigned short int port) } void JournalWriter::addEntry(Transaction &transaction, Commit &commit, - std::string resume, std::string course) + std::string resume, std::string templname) { - TemplateParser tp(course); + TemplateParser tp(templname); tp.parse(); Template *templ = tp.getTemplate(); size_t index = 0; - std::vector< Macro >::iterator i = templ->course.macros.begin(); - while(i != templ->course.macros.end()) { + std::vector< Macro >::iterator i = templ->macros.begin(); + while(i != templ->macros.end()) { Macro &m = *i; if(commit.macro == m.attributes["name"]) break; index++; i++; } - if(index >= templ->course.macros.size()) { - PRACRO_ERR(journal, "Could not find macro %s in course %s\n", - commit.macro.c_str(), course.c_str()); + if(index >= templ->macros.size()) { + PRACRO_ERR(journal, "Could not find macro %s in template %s\n", + commit.macro.c_str(), templname.c_str()); // return; } else { - PRACRO_DEBUG(journal, "Found macro %s as index %u in course %s\n", - commit.macro.c_str(), index, course.c_str()); + PRACRO_DEBUG(journal, "Found macro %s as index %u in template %s\n", + commit.macro.c_str(), index, templname.c_str()); } // First run - initialize username and cpr. if(currentuser == "" && entrylist.size() == 0) currentuser = transaction.user; if(currentcpr == "" && entrylist.size() == 0) currentcpr = transaction.cpr; - PRACRO_DEBUG(journal, "addEntry: course(%s)\n", course.c_str()); + PRACRO_DEBUG(journal, "addEntry: template(%s)\n", templname.c_str()); - // Add the course resume as the header (ie. first entry) of the journal entry. - if(entrylist.size() == 0 && course != "") { - std::string course_resume = templ->course.attributes["resume"]; + // Add the template resume as the header (ie. first entry) of the journal entry. + if(entrylist.size() == 0 && templname != "") { + std::string template_resume = templ->attributes["resume"]; - PRACRO_DEBUG(journal, "CourseResume: %s\n", course_resume.c_str()); + PRACRO_DEBUG(journal, "TemplateResume: %s\n", template_resume.c_str()); - if(course_resume != "") { + if(template_resume != "") { ResumeEntry re; - re.resume = course_resume; - re.macro = "course_header"; + re.resume = template_resume; + re.macro = "template_header"; entrylist[-1] = re; // Make sure it comes first. } } diff --git a/server/src/journal_commit.h b/server/src/journal_commit.h index 0565f34..9122703 100644 --- a/server/src/journal_commit.h +++ b/server/src/journal_commit.h @@ -43,7 +43,7 @@ public: JournalWriter(std::string host, unsigned short int port); void addEntry(Transaction &transaction, Commit &commit, - std::string resume, std::string course_resume); + std::string resume, std::string template_resume); void commit(); diff --git a/server/src/macrotool_dump.cc b/server/src/macrotool_dump.cc index 3f9cfd7..71bc690 100644 --- a/server/src/macrotool_dump.cc +++ b/server/src/macrotool_dump.cc @@ -89,14 +89,14 @@ static std::map<std::string, struct _macro> macroList() std::vector<std::string> templatefiles = getTemplates(); std::vector<std::string>::iterator tfs = templatefiles.begin(); while(tfs != templatefiles.end()) { - std::string course = tfs->substr(0, tfs->length() - 4); - TemplateParser parser(course); + std::string templ = tfs->substr(0, tfs->length() - 4); + TemplateParser parser(templ); parser.parse(); Template *t = parser.getTemplate(); - std::vector<Macro>::iterator ms = t->course.macros.begin(); - while(ms != t->course.macros.end()) { + std::vector<Macro>::iterator ms = t->macros.begin(); + while(ms != t->macros.end()) { if(ms->attributes.find("header") == ms->attributes.end()) - macros[ms->attributes["name"]].templates.insert(course); + macros[ms->attributes["name"]].templates.insert(templ); ms++; } tfs++; @@ -154,20 +154,20 @@ static std::map<std::string, struct _template> templateList() std::vector<std::string> templatefiles = getTemplates(); std::vector<std::string>::iterator tfs = templatefiles.begin(); while(tfs != templatefiles.end()) { - std::string course = tfs->substr(0, tfs->length() - 4); - TemplateParser parser(course); + std::string templ = tfs->substr(0, tfs->length() - 4); + TemplateParser parser(templ); parser.parse(); Template *t = parser.getTemplate(); - std::string key = t->course.attributes["name"]; + std::string key = t->attributes["name"]; templates[key].file = *tfs; - templates[key].name = t->course.attributes["name"]; - templates[key].title = t->course.attributes["title"]; - templates[key].version = t->course.attributes["version"]; + templates[key].name = t->attributes["name"]; + templates[key].title = t->attributes["title"]; + templates[key].version = t->attributes["version"]; - std::vector<Macro>::iterator ms = t->course.macros.begin(); - while(ms != t->course.macros.end()) { + std::vector<Macro>::iterator ms = t->macros.begin(); + while(ms != t->macros.end()) { if(ms->attributes.find("header") == ms->attributes.end()) templates[key].macros.push_back(ms->attributes["name"]); ms++; diff --git a/server/src/saxparser.cc b/server/src/saxparser.cc index ee03de1..8455593 100644 --- a/server/src/saxparser.cc +++ b/server/src/saxparser.cc @@ -182,7 +182,7 @@ unsigned int SAXParser::usedBytes() static char xml[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user=\"testuser\" cpr=\"1505050505\">\n" -" <commit version=\"\" macro=\"referral\" course=\"amd_forunders\">\n" +" <commit version=\"\" macro=\"referral\" template=\"amd_forunders\">\n" " <field value=\"Some docs\" name=\"referral.doctor\"/>\n" " <field value=\"DIMS\" name=\"referral.diagnosecode\"/>\n" " <field value=\"Avs\" name=\"referral.diagnose\"/>\n" @@ -193,7 +193,7 @@ static char xml[] = static char xml_notrailingwhitespace[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user=\"testuser\" cpr=\"1505050505\">\n" -" <commit version=\"\" macro=\"referral\" course=\"amd_forunders\">\n" +" <commit version=\"\" macro=\"referral\" template=\"amd_forunders\">\n" " <field value=\"Some docs\" name=\"referral.doctor\"/>\n" " <field value=\"DIMS\" name=\"referral.diagnosecode\"/>\n" " <field value=\"Avs\" name=\"referral.diagnose\"/>\n" @@ -204,14 +204,14 @@ static char xml_notrailingwhitespace[] = static char xml_fail[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user\"testuser\" cpr=\"1505050505\">\n" -" <request macro=\"test\" course=\"test\"/>\n" +" <request macro=\"test\" template=\"test\"/>\n" "</pracro>\n" ; static char xml_fail2[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user\"testuser\" cpr=\"1505050505\">\n" -" <request macro=\"test\" course=\"test\"/>\n" +" <request macro=\"test\" template=\"test\"/>\n" "</pracro>\n" "this is junk\n" ; diff --git a/server/src/server.cc b/server/src/server.cc index 924ad84..f75aeab 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -63,13 +63,13 @@ static std::string error_box(std::string message) std::string errorbox = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<pracro version=\"1.0\">\n" - " <course name=\"error\">\n" + " <template name=\"error\">\n" " <macro name=\"error\" static=\"true\">\n" " <window caption=\"ERROR!\" layout=\"vbox\" name=\"error\">\n" " <textedit name=\"errorlabel\" value=\"" + message + "\"/>\n" " </window>\n" " </macro>\n" - " </course>\n" + " </template>\n" "</pracro>\n"; return errorbox; } @@ -77,7 +77,7 @@ static std::string error_box(std::string message) class NotFoundException : public Exception { public: NotFoundException(Request &r) - : Exception("Macro " + r.macro + " not found in course " + r.course) {} + : Exception("Macro " + r.macro + " not found in template " + r.templ) {} }; @@ -99,7 +99,7 @@ static std::string handleCommits(Transaction *transaction, Database &db, db.commitTransaction(transaction->user, transaction->cpr, *macro, commit.fields); if(resume != "") { - journalwriter.addEntry(*transaction, commit, resume, commit.course); + journalwriter.addEntry(*transaction, commit, resume, commit.templ); } i++; @@ -122,26 +122,26 @@ static std::string handleRequest(Transaction *transaction, while(i != transaction->requests.end()) { Request &request = *i; - PRACRO_DEBUG(server, "Handling request - macro: %s, course: %s\n", - request.macro.c_str(), request.course.c_str()); + PRACRO_DEBUG(server, "Handling request - macro: %s, template: %s\n", + request.macro.c_str(), request.templ.c_str()); // Read and parse the template file. - TemplateParser tp(templatelist.getLatestVersion(request.course)); + TemplateParser tp(templatelist.getLatestVersion(request.templ)); tp.parse(); Template *templ = tp.getTemplate(); - answer += " <course name=\""; - answer += templ->course.attributes["name"]; + answer += " <template name=\""; + answer += templ->attributes["name"]; answer += "\" title=\""; - answer += templ->course.attributes["title"]; + answer += templ->attributes["title"]; answer += "\">\n"; bool foundmacro = false; // Generate the macro and return it to the client - std::vector< Macro >::iterator mi2 = templ->course.macros.begin(); - while(mi2 != templ->course.macros.end()) { + std::vector< Macro >::iterator mi2 = templ->macros.begin(); + while(mi2 != templ->macros.end()) { Macro ¯o = (*mi2); if(macro.isHeader) { @@ -244,7 +244,7 @@ static std::string handleRequest(Transaction *transaction, if(foundmacro == false && request.macro != "") throw NotFoundException(request); - answer += " </course>\n"; + answer += " </template>\n"; i++; } @@ -432,7 +432,7 @@ bool pracro_is_running = true; char request[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro cpr=\"2003791613\" version=\"1.0\">\n" - " <request macro=\"example\" course=\"example\"/>\n" + " <request macro=\"example\" template=\"example\"/>\n" "</pracro>\n"; int main() diff --git a/server/src/template.h b/server/src/template.h index ac5900f..c14577e 100644 --- a/server/src/template.h +++ b/server/src/template.h @@ -68,15 +68,9 @@ public: bool isHeader; }; -class Course { -public: - std::vector< Macro > macros; - std::map< std::string, std::string > attributes; -}; - class Template { public: - Course course; + std::vector< Macro > macros; std::map< std::string, std::string > attributes; }; diff --git a/server/src/templateheaderparser.cc b/server/src/templateheaderparser.cc index ee93381..8b0f162 100644 --- a/server/src/templateheaderparser.cc +++ b/server/src/templateheaderparser.cc @@ -95,7 +95,7 @@ TemplateHeaderParser::~TemplateHeaderParser() void TemplateHeaderParser::startTag(std::string name, std::map< std::string, std::string> attributes) { // Create template and enable parsing of queries, maps and window - if(name == "course") { + if(name == "template") { assert(!t); // A Template has already been allocated, cannot create template! t = new Template(); t->attributes = attributes; diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index 8ddf6d2..62be9c7 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -63,7 +63,7 @@ TemplateParser::TemplateParser(std::string templatefile) t = new Template(); current_macro = NULL; - file = templatefile;//Conf::xml_basedir + "/templates/" + course + ".xml"; + file = templatefile; PRACRO_DEBUG(macro, "Using template file: %s\n", file.c_str()); @@ -84,20 +84,20 @@ void TemplateParser::characterData(std::string &data) void TemplateParser::startTag(std::string name, std::map< std::string, std::string> attributes) { // Enable macro parsing - if(name == "course") { - if(state != UNDEFINED) error("course found not a root node."); - state = COURSE; + if(name == "template") { + if(state != UNDEFINED) error("Template found not a root node."); + state = TEMPLATE; - assert(t); // A Template has not yet been allocated, cannot create course! + assert(t); // A Template has not yet been allocated, cannot create template! - t->course.attributes = attributes; + t->attributes = attributes; return; } // Create macro and enable parsing of queries, maps and window if(name == "macro" || name == "header") { - if(state != COURSE) error("macro found outside course."); + if(state != TEMPLATE) error("macro found outside template."); state = MACRO; assert(t); // A Template has not yet been allocated, cannot create macro! @@ -105,8 +105,8 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri Macro m; m.attributes = attributes; m.isHeader = name == "header"; - t->course.macros.push_back(m); - current_macro = &(t->course.macros.back()); + t->macros.push_back(m); + current_macro = &(t->macros.back()); return; } @@ -116,10 +116,10 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri void TemplateParser::endTag(std::string name) { - if(name == "course") state = UNDEFINED; + if(name == "template") state = UNDEFINED; if(name == "macro" || name == "header") { current_macro = NULL; - state = COURSE; + state = TEMPLATE; } } @@ -173,16 +173,13 @@ int main() Template *t = parser.getTemplate(); - printf("[Template]:\n"); - print_attributes("\t-", t->attributes); - - printf("\t[Course]:\n"); - print_attributes("\t\t-", t->course.attributes); + printf("\t[Template]:\n"); + print_attributes("\t\t-", t->attributes); printf("\t\t[Macros]:\n"); - std::vector< Macro >::iterator i = t->course.macros.begin(); + std::vector< Macro >::iterator i = t->macros.begin(); - while(i != t->course.macros.end()) { + while(i != t->macros.end()) { printf("\t\t\t[Macro]:\n"); print_attributes("\t\t\t\t-", (*i).attributes); diff --git a/server/src/templateparser.h b/server/src/templateparser.h index 845e605..61f4d0b 100644 --- a/server/src/templateparser.h +++ b/server/src/templateparser.h @@ -32,13 +32,13 @@ typedef enum { UNDEFINED, - COURSE, + TEMPLATE, MACRO, } ParserState; class TemplateParser : public SAXParser { public: - TemplateParser(std::string course); + TemplateParser(std::string templ); ~TemplateParser(); void characterData(std::string &data); diff --git a/server/src/transaction.h b/server/src/transaction.h index 07f7e10..2cca49c 100644 --- a/server/src/transaction.h +++ b/server/src/transaction.h @@ -34,7 +34,7 @@ class Request { public: std::string macro; - std::string course; + std::string templ; }; typedef std::vector< Request > Requests; @@ -42,7 +42,7 @@ typedef std::map< std::string, std::string > Fields; class Commit { public: - std::string course; + std::string templ; std::string macro; std::string version; Fields fields; diff --git a/server/src/transactionparser.cc b/server/src/transactionparser.cc index 3135929..d4f7c76 100644 --- a/server/src/transactionparser.cc +++ b/server/src/transactionparser.cc @@ -78,14 +78,14 @@ void TransactionParser::startTag(std::string name, std::map< std::string, std::s if(name == "request") { Request r; - r.course = attributes["course"]; + r.templ = attributes["template"]; r.macro = attributes["macro"]; transaction->requests.push_back(r); } if(name == "commit") { Commit c; - c.course = attributes["course"]; + c.templ = attributes["template"]; c.macro = attributes["macro"]; c.version = attributes["version"]; transaction->commits.push_back(c); @@ -124,14 +124,14 @@ static char xml_minimal[] = static char xml_request[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user=\"testuser\" cpr=\"1505050505\">\n" -" <request macro=\"test\" course=\"test\"/>\n" +" <request macro=\"test\" template=\"test\"/>\n" "</pracro>\n" ; static char xml_commit[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user=\"testuser\" cpr=\"1505050505\">\n" -" <commit version=\"\" macro=\"referral\" course=\"amd_forunders\" >\n" +" <commit version=\"\" macro=\"referral\" template=\"amd_forunders\" >\n" " <field value=\"Some docs\" name=\"referral.doctor\"/>\n" " <field value=\"DIMS\" name=\"referral.diagnosecode\"/>\n" " <field value=\"Avs\" name=\"referral.diagnose\"/>\n" @@ -142,7 +142,7 @@ static char xml_commit[] = static char xml_fail[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user=\"testuser\" cpr=\"1505050505\">\n" -" <request macro=\"test course=\"test\"/>\n" +" <request macro=\"test template=\"test\"/>\n" "</pracro>\n" ; |