| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef GUARD_DB_GROUP_HH |
|---|
| 21 | #define GUARD_DB_GROUP_HH |
|---|
| 22 | |
|---|
| 23 | #include "article_number_type.hh" |
|---|
| 24 | #include "no_such_article.hh" |
|---|
| 25 | |
|---|
| 26 | #include "../server.hh" |
|---|
| 27 | |
|---|
| 28 | #include <boost/date_time/posix_time/posix_time.hpp> |
|---|
| 29 | #include <boost/enable_shared_from_this.hpp> |
|---|
| 30 | #include <boost/noncopyable.hpp> |
|---|
| 31 | #include <boost/shared_ptr.hpp> |
|---|
| 32 | #include <set> |
|---|
| 33 | #include <string> |
|---|
| 34 | #include <vector> |
|---|
| 35 | |
|---|
| 36 | namespace db |
|---|
| 37 | { |
|---|
| 38 | class db; |
|---|
| 39 | class msg; |
|---|
| 40 | class role; |
|---|
| 41 | class threaded_group; |
|---|
| 42 | class thread_node; |
|---|
| 43 | class user; |
|---|
| 44 | class group : private boost::noncopyable |
|---|
| 45 | , public boost::enable_shared_from_this<group> |
|---|
| 46 | { |
|---|
| 47 | public: |
|---|
| 48 | typedef boost::shared_ptr<group> ptr; |
|---|
| 49 | typedef boost::shared_ptr<const group> const_ptr; |
|---|
| 50 | |
|---|
| 51 | typedef article_number_type number; |
|---|
| 52 | enum { number_max = 2147483647UL }; |
|---|
| 53 | |
|---|
| 54 | group(std::string name, |
|---|
| 55 | boost::shared_ptr<db> dbase, |
|---|
| 56 | boost::posix_time::ptime stamp, |
|---|
| 57 | bool reading_restricted, std::string descr); |
|---|
| 58 | |
|---|
| 59 | boost::posix_time::ptime get_creation_time() const { |
|---|
| 60 | return stamp; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | number low_mark() const { return displacement; } |
|---|
| 64 | number high_mark() const { |
|---|
| 65 | return displacement + msgs.size() - 1; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | std::string name() const { return the_name; } |
|---|
| 69 | std::string one_line_description() const { return descr; } |
|---|
| 70 | |
|---|
| 71 | bool is_article(number n) const { return retrieve(n); } |
|---|
| 72 | |
|---|
| 73 | boost::shared_ptr<msg> get_article(number n) const { |
|---|
| 74 | boost::shared_ptr<msg> rv = retrieve(n); |
|---|
| 75 | if (!rv) throw no_such_article(); |
|---|
| 76 | return rv; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | number file(boost::shared_ptr<msg> m, server::conn_cb); |
|---|
| 80 | |
|---|
| 81 | void file(boost::shared_ptr<msg> m, number n); |
|---|
| 82 | |
|---|
| 83 | number get_count() const { return count; } |
|---|
| 84 | |
|---|
| 85 | const std::set<boost::shared_ptr<role> > &get_readers() const { |
|---|
| 86 | return readers; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | void add_reader(boost::shared_ptr<role> r) { |
|---|
| 90 | readers.insert(r); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | bool reading_authz(boost::shared_ptr<const user> u) const { |
|---|
| 94 | return authz(u, readers); |
|---|
| 95 | } |
|---|
| 96 | bool posting_authz(boost::shared_ptr<const user> u) const { |
|---|
| 97 | return authz(u, posters); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void add_subscriber(boost::shared_ptr<user> u, |
|---|
| 101 | server::conn_cb cb, |
|---|
| 102 | boost::asio::ip::address peer); |
|---|
| 103 | void delete_subscriber(boost::shared_ptr<user> u, |
|---|
| 104 | server::conn_cb cb); |
|---|
| 105 | bool is_subscriber(boost::shared_ptr<const user> u); |
|---|
| 106 | private: |
|---|
| 107 | std::string the_name; |
|---|
| 108 | boost::posix_time::ptime stamp; |
|---|
| 109 | std::string descr; |
|---|
| 110 | boost::shared_ptr<db> dbase; |
|---|
| 111 | boost::shared_ptr<role> subscriber_role; |
|---|
| 112 | |
|---|
| 113 | void ensure_subscriber_role(); |
|---|
| 114 | |
|---|
| 115 | number count; |
|---|
| 116 | |
|---|
| 117 | size_t displacement; |
|---|
| 118 | std::vector<boost::shared_ptr<msg> > msgs; |
|---|
| 119 | |
|---|
| 120 | std::set<boost::shared_ptr<role> > readers; |
|---|
| 121 | std::set<boost::shared_ptr<role> > posters; |
|---|
| 122 | |
|---|
| 123 | static bool authz(boost::shared_ptr<const user> u, |
|---|
| 124 | const std::set<boost::shared_ptr<role> > &); |
|---|
| 125 | |
|---|
| 126 | void send_submail(boost::shared_ptr<const user> u, |
|---|
| 127 | const char *tln, |
|---|
| 128 | server::conn_cb cb); |
|---|
| 129 | |
|---|
| 130 | boost::shared_ptr<msg> retrieve(number n) const { |
|---|
| 131 | static boost::shared_ptr<msg> null; |
|---|
| 132 | if (n < displacement) return null; |
|---|
| 133 | if (n - displacement >= msgs.size()) return null; |
|---|
| 134 | return msgs[n - displacement]; |
|---|
| 135 | } |
|---|
| 136 | }; |
|---|
| 137 | |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | #endif |
|---|