diff options
Diffstat (limited to 'server/src')
| -rw-r--r-- | server/src/Makefile.am | 2 | ||||
| -rw-r--r-- | server/src/database.cc | 62 | ||||
| -rw-r--r-- | server/src/database.h | 2 | ||||
| -rw-r--r-- | server/src/macro.h | 1 | ||||
| -rw-r--r-- | server/src/resumeparser.cc | 97 | ||||
| -rw-r--r-- | server/src/resumeparser.h | 35 | ||||
| -rw-r--r-- | server/src/server.cc | 42 | ||||
| -rw-r--r-- | server/src/transaction.h | 7 | ||||
| -rw-r--r-- | server/src/xmlparser.cc | 10 | 
9 files changed, 201 insertions, 57 deletions
| diff --git a/server/src/Makefile.am b/server/src/Makefile.am index 43fa560..4cee6cf 100644 --- a/server/src/Makefile.am +++ b/server/src/Makefile.am @@ -12,6 +12,7 @@ pracrod_SOURCES = \  	exception.cc \  	log.cc \  	macro_parser.cc \ +	resumeparser.cc \  	server.cc \  	tcpsocket.cc \  	tostring.cc \ @@ -26,6 +27,7 @@ EXTRA_DIST = \  	log.h \  	macro.h \  	macro_parser.h \ +	resumeparser.h \  	server.h \  	tcpsocket.h \  	tostring.h \ diff --git a/server/src/database.cc b/server/src/database.cc index 1a48925..ad6bbe0 100644 --- a/server/src/database.cc +++ b/server/src/database.cc @@ -26,9 +26,8 @@   */  #include "database.h" -#include "tostring.h" +//#include "tostring.h"  #include "uid.h" -#include <time.h>  Database::Database(std::string hostname, std::string user, std::string password)    : c("host=" + hostname + @@ -42,47 +41,44 @@ Database::~Database()  {  } -int Database::post(Transaction &transaction) +int Database::post(std::string &user, std::string &cpr, std::string &time, Commit &commit)  {    UID uid; -  std::string now = toString((unsigned int)time(NULL));  	try {  		pqxx::work W(c); -    Commits::iterator i = transaction.commits.begin(); -    while(i != transaction.commits.end()) { -      Commit &commit = *i; -      //      std::string transid = transidbase + toString(idx); - -      // Insert transaction entry -      std::string sql = "INSERT INTO transactions VALUES('" +  -        transaction.cpr + "', '" +  +    //      std::string transid = transidbase + toString(idx); + +    // Insert transaction entry +    std::string sql = "INSERT INTO transactions VALUES('" +  +      cpr + "', '" +  +      uid.toString() + "', '" +  +      commit.macro + "', '" +  +      commit.version + "', '" +  +      time + "', '" +  +      user + "')"; +    W.exec(sql); +     +    // Insert field entries +    Fields::iterator j = commit.fields.begin(); +    while(j != commit.fields.end()) { +      //      std::string name = j->first; +      //      std::string value = j->second; + +      sql = "INSERT INTO fields VALUES('" +           uid.toString() + "', '" +  -        commit.macro + "', '" +  -        commit.version + "', '" +  -        now + "', '" +  -        transaction.user + "')"; +        j->first + "', '" +  +        j->second + "')"; +      //        name + "', '" +  +      //        value + "')";        W.exec(sql); - -      // Insert field entries -      Fields::iterator j = commit.fields.begin(); -      while(j != commit.fields.end()) { -        Field &field = *j; - -        sql = "INSERT INTO fields VALUES('" +  -          uid.toString() + "', '" +  -          field.name + "', '" +  -          field.value + "')"; -        W.exec(sql); - -        j++; -      } - -      uid++; -      i++; +       +      j++;      } +    uid++; +      		W.commit();  	}	catch(const std::exception &e) {      //		throw PostgreSQLException(e.what()); diff --git a/server/src/database.h b/server/src/database.h index 9659eda..a841188 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -38,7 +38,7 @@ public:             std::string password = "pracro");    ~Database(); -  int post(Transaction &transaction); +  int post(std::string &user, std::string &cpr, std::string &time, Commit &commit);  private:    pqxx::connection c; diff --git a/server/src/macro.h b/server/src/macro.h index af9749d..2252d90 100644 --- a/server/src/macro.h +++ b/server/src/macro.h @@ -51,6 +51,7 @@ class Macro {  public:    std::string name;    std::string version; +  std::string format;    WidgetList widgets;  }; diff --git a/server/src/resumeparser.cc b/server/src/resumeparser.cc new file mode 100644 index 0000000..769bb25 --- /dev/null +++ b/server/src/resumeparser.cc @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            resumeparser.cc + * + *  Mon Oct  1 11:17:35 CEST 2007 + *  Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + *  deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + *  This file is part of Pracro. + * + *  Pracro is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  Pracro is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Pracro; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#include "resumeparser.h" + +#include <string.h> + +std::string resume_parser(const char *format, Commit &commit) +{ +  std::string resume; +  std::string var; + +  const char *p = format; +  const char *theend = p + strlen(format); +  while(p < theend) { +    switch(*p) { +    case '$': +      p++; +      switch(*p) { +      case '$': +        resume.append(1, *p); +        break; + +      case '{': +        p++; +        var = ""; +        // Parser +        while(p < theend && *p != '}') { +          var.append(1, *p); +          p++; +        } +        //        p++; +        printf("[%s]\n", var.c_str()); +        //        resume += "var(" + var + ")"; +        resume += commit.fields[var]; +        break; + +      default: +        resume.append(1, *p); +       //       printf("Illigal $ command\n"); +        break; +      } +      p++; +      break; + +    case '\\': +      p++; +      switch(*p) { +      case 't': +        resume.append(1, '\t'); +        break; +      case 'n': +        resume.append(1, '\n'); +        break; +      case 'r': +        resume.append(1, '\r'); +        break; +      case '\\': +      default: +        resume.append(1, *p); +        break; +      } +      p++; +     break; + +    default: +      resume.append(1, *p); +      p++; +      break; +    } +  } + +  return resume; +} diff --git a/server/src/resumeparser.h b/server/src/resumeparser.h new file mode 100644 index 0000000..991f106 --- /dev/null +++ b/server/src/resumeparser.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + *            resumeparser.h + * + *  Mon Oct  1 11:17:35 CEST 2007 + *  Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup + *  deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk + ****************************************************************************/ + +/* + *  This file is part of Pracro. + * + *  Pracro is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  Pracro is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Pracro; if not, write to the Free Software + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. + */ +#ifndef __PRACRO_RESUMEPARSER_H__ +#define __PRACRO_RESUMEPARSER_H__ + +#include <string> +#include "transaction.h" + +std::string resume_parser(const char *format, Commit &commit); + +#endif/*__PRACRO_RESUMEPARSER_H__*/ diff --git a/server/src/server.cc b/server/src/server.cc index 064d8b9..815f0db 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -45,6 +45,11 @@  #include "macro.h"  #include "macro_parser.h" +#include "resumeparser.h" + +#include "tostring.h" +#include <time.h> +  static void send_macro_widget(Widget &widget, TCPSocket &socket, std::string tabs)  {    socket.write(tabs + "<" + widget.type); @@ -97,26 +102,29 @@ static void connection(TCPSocket &socket)    // Handle commits    if(transaction.commits.size() > 0) { -    Database db; -    db.post(transaction); -  } +    std::string now = toString((unsigned int)time(NULL)); -  /* -  Commits::iterator j = transaction.commits.begin(); -  while(j != transaction.commits.end()) { -    Commit &commit = *j; -    printf("Commit %s\n", commit.macro.c_str()); - -    Fields::iterator k = commit.fields.begin(); -    while(k != commit.fields.end()) { -      Field &val = *k; -      printf("\t%s=%s\n", val.name.c_str(), val.value.c_str()); -      k++; -    } +    Commits::iterator i = transaction.commits.begin(); +    while(i != transaction.commits.end()) { +      Commit &commit = *i; + +      Database db; +      db.post(transaction.user, transaction.cpr, now, commit); -    j++; +      Macro macro; +      parse_macro(commit.macro, macro); +      //parse_macro("example", macro); + +      macro.format = "Det koster 50$$\\n\\tLinse: ${linse}D\\n" +        "\\y${combo}\\\\\\nHævelse: ${radio}\\n\\n${spl_note}"; + +      std::string resume = resume_parser(macro.format.c_str(), commit); + +      printf("%s\n", resume.c_str()); + +      i++; +    }    } -  */    socket.write("</pracro>\n"); diff --git a/server/src/transaction.h b/server/src/transaction.h index 97bb556..daf0de3 100644 --- a/server/src/transaction.h +++ b/server/src/transaction.h @@ -29,7 +29,7 @@  #include <string>  #include <vector> - +#include <map>  class Request {  public: @@ -38,12 +38,15 @@ public:  typedef std::vector< Request > Requests; +/*  class Field {  public:    std::string name;    std::string value;  }; -typedef std::vector< Field > Fields; +*/ +//typedef std::vector< Field > Fields; +typedef std::map< std::string, std::string > Fields;  class Commit { diff --git a/server/src/xmlparser.cc b/server/src/xmlparser.cc index 31ffbed..6ef7338 100644 --- a/server/src/xmlparser.cc +++ b/server/src/xmlparser.cc @@ -82,10 +82,12 @@ static void start_hndl(void *p, const char *el, const char **attr)    }    if(name == "field") { -    Field f; -    f.name = attributes["name"]; -    f.value = attributes["value"]; -    transaction->commits.back().fields.push_back(f); +    //    Field f; +    //    f.name = attributes["name"]; +    //    f.value = attributes["value"]; +    //    transaction->commits.back().fields.push_back(f); +    transaction->commits.back().fields[attributes["name"]] = attributes["value"]; +    //    printf("[%s]=[%s]\n", f.name.c_str(), f.value.c_str());    }  } | 
