root/nntp/last.cc

Revision 1a970cd0640f976f152341597a5249ec22acbba7, 2.6 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 21 months ago)

[msg::msg] Separate out db::msg and let msg::entity handle the rest

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, 2010 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
20#include "connection.hh"
21
22#include "../db/group.hh"
23#include "../db/msg.hh"
24
25namespace nntp
26{
27        class last : public connection::command
28        {
29        public:
30                last(const char *s) {
31                        connection::register_command(s, this);
32                }
33
34                connection::continuation::ptr
35                perform(connection::cb, const std::string [],  size_t) const;
36        };
37
38        connection::continuation::ptr
39        last::perform(connection::cb c, const std::string[], size_t nargs) const
40        {
41                if (nargs > 0) {
42                        c.send_line("501 syntax error");
43                        return c.dispatch();
44                }
45                if (!c.current_group()) {
46                        c.send_line("412 no group selected");
47                        return c.dispatch();
48                }
49                db::group::number low = c.current_group()->low_mark();
50                if (c.current_article() < low ||
51                    c.current_article() > c.current_group()->high_mark()) {
52                        c.send_line("420 no current article");
53                        return c.dispatch();
54                }
55               
56                db::group::number n = c.current_article();
57                do --n; while (n >= low && !c.current_group()->is_article(n));
58
59                if (!c.current_group()->is_article(n)) {
60                        c.send_line("422 already at the first article");
61                        return c.dispatch();
62                }
63                std::ostringstream ss;
64                ss << "223 "
65                   << n
66                   << ' '
67                   << c.current_group()->get_article(n)->msgid()
68                   << " selected";
69                c.current_article() = n;
70                c.send_line(ss.str());
71                return c.dispatch();
72        }
73}
74namespace {
75        nntp::last last("last");
76}
Note: See TracBrowser for help on using the browser.