Changeset 7ccc366e52cc1e51e123b39fccaf56267361ca58
- Timestamp:
- 08/25/10 18:30:39 (18 months ago)
- Children:
- 43f521291669f483d361949fa6c886c0fbd94daf
- Parents:
- 7eb42bed950e3f81ef9f0d39432e07c55f12cc22
- git-committer:
- Antti-Juhani Kaijanaho <antti-juhani@…> (08/25/10 18:30:39)
- Location:
- db
- Files:
-
- 3 added
- 2 modified
-
db.cc (modified) (2 diffs)
-
db.hh (modified) (3 diffs)
-
db_reader.hh (added)
-
illformed_db.hh (added)
-
role_exists.hh (added)
Legend:
- Unmodified
- Added
- Removed
-
db/db.cc
r050d01b r7ccc366 19 19 20 20 #include "db.hh" 21 #include "db_reader.hh" 21 22 #include "role.hh" 23 #include "role_exists.hh" 22 24 #include "user.hh" 23 25 #include "user_exists.hh" … … 33 35 #include <fstream> 34 36 35 // TODO: Decouple record parsing by an "event" mechanism.36 37 namespace db_detail38 {39 class illformed_db : public std::exception40 {41 const std::string s;42 public:43 illformed_db(std::string s) : s("illformed db: " + s) {}44 ~illformed_db() throw() {}45 const char *what() const throw() { return s.c_str(); }46 };47 48 class role_exists : public std::exception49 {50 const std::string s;51 public:52 role_exists(std::string name) : s(name + " exists") {}53 ~role_exists() throw() {}54 const char *what() const throw() { return s.c_str(); }55 };56 57 class rollback {};58 59 class db_reader : public boost::noncopyable60 {61 std::istream &dbfile;62 public:63 db_reader(std::istream &is) : dbfile(is) {}64 void readline(std::string &line) {65 std::getline(dbfile, line);66 if (line.substr(0, 7) == ".BEGIN ") throw rollback();67 }68 69 std::string readline(std::string &line, std::string cmd){70 readline(line);71 util::strip(line);72 if (line.substr(0, cmd.length()+1) != cmd + " ")73 throw illformed_db(cmd + " missing");74 return line.substr(cmd.length()+1);75 }76 77 void endrec(std::string &line) {78 std::getline(dbfile, line);79 if (!dbfile || line.substr(0, 7) == ".BEGIN ")80 throw rollback();81 util::strip(line);82 if (line != ".END") throw illformed_db(".END missing");83 }84 bool valid() { return dbfile; }85 };86 87 }88 89 37 namespace db 90 38 { 91 using namespace db_detail;92 93 39 db::db() 94 40 : dbname(config["db-file"].as<std::string>()) -
db/db.hh
r5d836bd r7ccc366 37 37 namespace msg { class msg; } 38 38 39 namespace db_detail { class db_reader; }40 41 39 namespace db 42 40 { 43 41 class user; 44 42 class password_handler; 43 class db_reader; 45 44 46 45 class db : private boost::noncopyable … … 114 113 115 114 void add_record(std::string record); 116 117 115 private: 118 116 mutable boost::recursive_mutex mt; … … 133 131 boost::random_device rand; 134 132 135 void do_newgroup(db_ detail::db_reader &, std::string,133 void do_newgroup(db_reader &, std::string, 136 134 boost::posix_time::ptime); 137 void do_user(db_detail::db_reader &, std::string); 138 void do_article(db_detail::db_reader &, std::string); 139 void do_role(db_detail::db_reader &, std::string); 140 void read_record(db_detail::db_reader &dr, 141 boost::posix_time::ptime); 135 void do_user(db_reader &, std::string); 136 void do_article(db_reader &, std::string); 137 void do_role(db_reader &, std::string); 138 void read_record(db_reader &dr, boost::posix_time::ptime); 142 139 void register_role(boost::shared_ptr<role>); 143 140 };
