diff options
-rw-r--r-- | server/src/journal_commit.cc | 38 | ||||
-rw-r--r-- | server/src/journal_commit.h | 7 | ||||
-rw-r--r-- | server/src/server.cc | 9 | ||||
-rw-r--r-- | server/src/template.h | 2 | ||||
-rw-r--r-- | server/src/templateparser.cc | 10 |
5 files changed, 44 insertions, 22 deletions
diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index accf839..f74e54e 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -200,6 +200,28 @@ JournalWriter::JournalWriter(std::string host, unsigned short int port) void JournalWriter::addEntry(Transaction &transaction, Commit &commit, std::string resume, std::string course) { + TemplateParser tp(course); + 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()) { + 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()); + // return; + } else { + PRACRO_DEBUG(journal, "Found macro %s as index %u in course %s\n", + commit.macro.c_str(), index, course.c_str()); + } + // First run - initialize username and cpr. if(currentuser == "" && entrylist.size() == 0) currentuser = transaction.user; if(currentcpr == "" && entrylist.size() == 0) currentcpr = transaction.cpr; @@ -208,9 +230,6 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit, // Add the course resume as the header (ie. first entry) of the journal entry. if(entrylist.size() == 0 && course != "") { - TemplateParser tp(course); - tp.parse(); - Template *templ = tp.getTemplate(); std::string course_resume = templ->course.attributes["resume"]; PRACRO_DEBUG(journal, "CourseResume: %s\n", course_resume.c_str()); @@ -219,7 +238,7 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit, ResumeEntry re; re.resume = course_resume; re.macro = "course_header"; - entrylist.push_back(re); + entrylist[-1] = re; // Make sure it comes first. } } @@ -233,6 +252,7 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit, std::string r = stripTrailingWhitepace(addNewlines(resume, 60)); std::string m = commit.macro; + /* // If macro already exists, overwrite with this entry, otherwise, just add it int idx = -1; std::vector< ResumeEntry >::iterator i = entrylist.begin(); @@ -252,6 +272,12 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit, re.macro = m; entrylist.push_back(re); } + */ + + ResumeEntry re; + re.resume = r; + re.macro = m; + entrylist[index] = re; } void JournalWriter::commit() @@ -259,11 +285,11 @@ void JournalWriter::commit() std::string resume; // Iterate through all resumes, and create a string containing them all. - std::vector< ResumeEntry >::iterator i = entrylist.begin(); + std::map< int, ResumeEntry >::iterator i = entrylist.begin(); while(i != entrylist.end()) { if(resume != "") resume += "\n\n"; // resume += i->macro + "\n"; - resume += i->resume; + resume += i->second.resume; i++; } diff --git a/server/src/journal_commit.h b/server/src/journal_commit.h index 0f8ae57..0565f34 100644 --- a/server/src/journal_commit.h +++ b/server/src/journal_commit.h @@ -28,7 +28,7 @@ #define __PRACRO_JOURNAL_COMMIT_H__ #include <string> -#include <vector> +#include <map> #include "transaction.h" @@ -42,7 +42,8 @@ class JournalWriter { public: JournalWriter(std::string host, unsigned short int port); - void addEntry(Transaction &transaction, Commit &commit, std::string resume, std::string course_resume); + void addEntry(Transaction &transaction, Commit &commit, + std::string resume, std::string course_resume); void commit(); @@ -53,7 +54,7 @@ private: std::string currentuser; std::string currentcpr; - std::vector< ResumeEntry > entrylist; + std::map< int, ResumeEntry > entrylist; }; #endif/*__PRACRO_JOURNAL_COMMIT_H__*/ diff --git a/server/src/server.cc b/server/src/server.cc index a0dbaa4..2641b8a 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -109,11 +109,6 @@ static std::string handleTransaction(Transaction *transaction, if(resume != "" && store_in_journal) { journalwriter.addEntry(*transaction, commit, resume, commit.course); - /* - 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()); - */ } i++; @@ -145,8 +140,8 @@ static std::string handleTransaction(Transaction *transaction, bool foundmacro = false; // Generate the macro and return it to the client - std::vector< Macro >::iterator mi2 = templ->course.macroes.begin(); - while(mi2 != templ->course.macroes.end()) { + std::vector< Macro >::iterator mi2 = templ->course.macros.begin(); + while(mi2 != templ->course.macros.end()) { Macro ¯o = (*mi2); // FIXME: This is to be made in some other way in a later version. diff --git a/server/src/template.h b/server/src/template.h index c6d40a6..f39baac 100644 --- a/server/src/template.h +++ b/server/src/template.h @@ -69,7 +69,7 @@ public: class Course { public: - std::vector< Macro > macroes; + std::vector< Macro > macros; std::map< std::string, std::string > attributes; }; diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index 140051e..d40bc1e 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -123,8 +123,8 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri Macro m; m.attributes = attributes; - t->course.macroes.push_back(m); - current_macro = &(t->course.macroes.back()); + t->course.macros.push_back(m); + current_macro = &(t->course.macros.back()); return; } @@ -194,10 +194,10 @@ int main() printf("\t[Course]:\n"); print_attributes("\t\t-", t->course.attributes); - printf("\t\t[Macroes]:\n"); - std::vector< Macro >::iterator i = t->course.macroes.begin(); + printf("\t\t[Macros]:\n"); + std::vector< Macro >::iterator i = t->course.macros.begin(); - while(i != t->course.macroes.end()) { + while(i != t->course.macros.end()) { printf("\t\t\t[Macro]:\n"); print_attributes("\t\t\t\t-", (*i).attributes); |