| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include "connection.hh" |
|---|
| 20 | #include "lexutils.hh" |
|---|
| 21 | |
|---|
| 22 | #include "../db/db.hh" |
|---|
| 23 | |
|---|
| 24 | #include <boost/date_time/gregorian/gregorian.hpp> |
|---|
| 25 | #include <boost/date_time/posix_time/posix_time.hpp> |
|---|
| 26 | |
|---|
| 27 | namespace nntp { |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | class newgroups : public connection::command |
|---|
| 32 | { |
|---|
| 33 | public: |
|---|
| 34 | newgroups(std::string s) { |
|---|
| 35 | connection::register_command(s, this); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | connection::continuation::ptr |
|---|
| 39 | perform(connection::cb, const std::string [], size_t) const; |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | connection::continuation::ptr |
|---|
| 43 | newgroups::perform(connection::cb c, |
|---|
| 44 | const std::string args[], size_t nargs) |
|---|
| 45 | const |
|---|
| 46 | { |
|---|
| 47 | bool utc = false; |
|---|
| 48 | boost::posix_time::ptime stamp; |
|---|
| 49 | switch (nargs) |
|---|
| 50 | { |
|---|
| 51 | case 3: |
|---|
| 52 | { |
|---|
| 53 | std::string tmp = args[2]; |
|---|
| 54 | boost::to_upper(tmp); |
|---|
| 55 | if (tmp != "GMT") |
|---|
| 56 | { |
|---|
| 57 | c.send_line("501 malformed timezone"); |
|---|
| 58 | return c.dispatch(); |
|---|
| 59 | } |
|---|
| 60 | utc = true; |
|---|
| 61 | |
|---|
| 62 | } |
|---|
| 63 | case 2: |
|---|
| 64 | { |
|---|
| 65 | using namespace boost::gregorian; |
|---|
| 66 | std::string date_s; |
|---|
| 67 | switch (args[0].length()) |
|---|
| 68 | { |
|---|
| 69 | case 8: |
|---|
| 70 | date_s = args[0]; |
|---|
| 71 | break; |
|---|
| 72 | case 6: |
|---|
| 73 | { |
|---|
| 74 | if (!is_digit(args[0][0]) || |
|---|
| 75 | !is_digit(args[0][1])) |
|---|
| 76 | { |
|---|
| 77 | c.send_line("501 malformed date"); |
|---|
| 78 | return c.dispatch(); |
|---|
| 79 | } |
|---|
| 80 | int y = (int)(args[0][0]-'0')*10 + |
|---|
| 81 | (int)(args[0][1]-'0'); |
|---|
| 82 | date now = utc |
|---|
| 83 | ? day_clock::universal_day() |
|---|
| 84 | : day_clock::local_day(); |
|---|
| 85 | int century = y <= now.year() % 100 |
|---|
| 86 | ? now.year() / 100 |
|---|
| 87 | : now.year() / 100 - 1; |
|---|
| 88 | std::ostringstream ss; |
|---|
| 89 | ss << (char)((century / 10) + '0') |
|---|
| 90 | << (char)((century % 10) + '0') |
|---|
| 91 | << args[0]; |
|---|
| 92 | date_s = ss.str(); |
|---|
| 93 | break; |
|---|
| 94 | } |
|---|
| 95 | default: |
|---|
| 96 | c.send_line("501 malformed date"); |
|---|
| 97 | return c.dispatch(); |
|---|
| 98 | } |
|---|
| 99 | stamp = boost::posix_time::from_iso_string |
|---|
| 100 | (date_s + "T" + args[1]); |
|---|
| 101 | break; |
|---|
| 102 | } |
|---|
| 103 | default: |
|---|
| 104 | c.send_line("501 syntax error"); |
|---|
| 105 | return c.dispatch(); |
|---|
| 106 | } |
|---|
| 107 | c.send_line("231 groups created since " + |
|---|
| 108 | boost::posix_time::to_iso_extended_string(stamp)); |
|---|
| 109 | for (db::db::group_iterator it = c.dbase().groups_begin(); |
|---|
| 110 | it != c.dbase().groups_end(); it++) { |
|---|
| 111 | assert(it->second); |
|---|
| 112 | if (it->second->get_creation_time() <= stamp) |
|---|
| 113 | continue; |
|---|
| 114 | std::ostringstream os; |
|---|
| 115 | os << it->first |
|---|
| 116 | << " " << it->second->high_mark() |
|---|
| 117 | << " " << it->second->low_mark() |
|---|
| 118 | << " y"; |
|---|
| 119 | c.send_line(os.str()); |
|---|
| 120 | } |
|---|
| 121 | c.send_line("."); |
|---|
| 122 | return c.dispatch(); |
|---|
| 123 | } |
|---|
| 124 | }; |
|---|
| 125 | namespace { |
|---|
| 126 | nntp::newgroups newgroups("newgroups"); |
|---|
| 127 | } |
|---|