From 0e819eb42b4d680a99ae7b04702bfc9510495aee Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 6 Jan 2010 07:47:58 +0000 Subject: New artefact connection class (to later wrap libartefact). New environment class to hold all global resources. Made ConnectionPool a template class. Split journal code up into two files (class from commit code). --- server/src/journal_commit.cc | 97 ++------------------------------------------ 1 file changed, 3 insertions(+), 94 deletions(-) (limited to 'server/src/journal_commit.cc') diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index 414fa20..bc47fce 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -52,6 +52,7 @@ #include "template.h" #include "templateparser.h" +#if 0 static inline bool iswhitespace(char c) { return c == ' ' || c == '\n' || c == '\t'; @@ -109,6 +110,7 @@ static std::string addNewlines(std::string str, size_t width) return output; } +#endif static int mwrite(int sock, const char *fmt, ...) { @@ -184,7 +186,7 @@ int journal_commit(const char *cpr, const char *user, mwrite(sock, "charset: utf8\r\n"); mwrite(sock, "\r\n"); - std::string resume = stripTrailingWhitepace(addNewlines(buf, 60)); + std::string resume = buf;//stripTrailingWhitepace(addNewlines(buf, 60)); // send body if(sock != -1 && write(sock, resume.c_str(), resume.size()) != (ssize_t)resume.size()) { @@ -200,103 +202,10 @@ int journal_commit(const char *cpr, const char *user, return 0; } -JournalWriter::JournalWriter(std::string host, unsigned short int port) -{ - this->host = host; - this->port = port; -} - -void JournalWriter::addEntry(Transaction &transaction, Commit &commit, - std::string resume, Template *templ) -{ - size_t index = 0; - 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->macros.size()) { - PRACRO_ERR(journal, "Could not find macro %s in template %s\n", - commit.macro.c_str(), templ->attributes["name"].c_str()); - // return; - } else { - PRACRO_DEBUG(journal, "Found macro %s as index %u in template %s\n", - commit.macro.c_str(), index, templ->attributes["name"].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: template(%s)\n", templ->attributes["name"].c_str()); - - // Add the template resume as the header (ie. first entry) of the journal entry. - if(entrylist.size() == 0 && templ->attributes["name"] != "") { - std::string template_resume = templ->attributes["resume"]; - - PRACRO_DEBUG(journal, "TemplateResume: %s\n", template_resume.c_str()); - - if(template_resume != "") { - ResumeEntry re; - re.resume = template_resume; - re.macro = "template_header"; - entrylist[-1] = re; // Make sure it comes first. - } - } - - // Test if the username or the cpr has changed... if so, commit and clear the list. - if(currentuser != transaction.user || currentcpr != transaction.cpr) { - this->commit(); - entrylist.clear(); - } - - // Strip trailing whitespace, and add newlines. - std::string r = stripTrailingWhitepace(addNewlines(resume, 60)); - std::string m = commit.macro; - - ResumeEntry re; - re.resume = r; - re.macro = m; - entrylist[index] = re; -} - -void JournalWriter::commit() -{ - std::string resume; - - // Iterate through all resumes, and create a string containing them all. - std::map< int, ResumeEntry >::iterator i = entrylist.begin(); - while(i != entrylist.end()) { - if(resume != "") resume += "\n\n"; - // resume += i->macro + "\n"; - resume += i->second.resume; - i++; - } - - if(resume == "") return; - - // Connect to praxisuploadserver and commit all resumes in one bulk. - journal_commit(currentcpr.c_str(), currentuser.c_str(), - host.c_str(), port, - resume.c_str(), resume.size()); -} - - #ifdef TEST_JOURNAL_COMMIT int main() { - std::string text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do\neiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \n\n \t"; - - std::string resume = stripTrailingWhitepace(addNewlines(text, 60)); - printf("[%s]\n", resume.c_str()); - - resume = stripTrailingWhitepace(addNewlines("", 60)); - printf("[%s]\n", resume.c_str()); - return 0; } -- cgit v1.2.3