root/nntp/newgroups.cc

Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 4.9 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago)

Update the project blurb

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
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
27namespace nntp {
28
29        // FIXME local time handling
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                        /* passthrough */
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};
125namespace {
126        nntp::newgroups newgroups("newgroups");
127}
Note: See TracBrowser for help on using the browser.