root/http/grouplist.cc

Revision cc0a570a9262613f7046938be649f27646987cb8, 2.6 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 2 years ago)

Add support for Atom feeds, and implement a group feed

Partially addresses #8

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
20#include "authn.hh"
21#include "request.hh"
22#include "templated_resource.hh"
23
24#include "../db/db.hh"
25#include "../html/util.hh"
26#include "../server.hh"
27#include "../tlate/group_value.hh"
28#include "../tlate/list_value.hh"
29#include "../tlate/tlate.hh"
30
31namespace http
32{
33        class grouplist : public templated_resource
34        {
35        public:
36                grouplist(server::conn_cb cb)
37                        : templated_resource(cb, "index.html")
38                        {}
39        protected:
40                void set_attributes(boost::shared_ptr<request>,
41                                    tlate::data_model::ptr);
42        };
43
44        void grouplist::set_attributes(boost::shared_ptr<request> req,
45                                       tlate::data_model::ptr am)
46        {
47                boost::shared_ptr<db::user> u = req->get_user();
48                using html::quote;
49                tlate::list_value::ptr sv(new tlate::list_value);
50                for (db::db::group_iterator git = cb.dbase().groups_begin();
51                     git != cb.dbase().groups_end(); git++)
52                {
53                        boost::shared_ptr<db::group> gr = git->second;
54                        tlate::group_value::ptr grv
55                                (new tlate::group_value(gr, u));
56                        sv->push_back(grv);
57                }
58                am->insert("groups", sv);
59        }
60
61};
62
63namespace
64{
65        class factory : public server::http_resource_factory
66        {
67        public:
68                factory() {
69                        server::register_http_resource("/", this);
70                }
71                boost::shared_ptr<http::resource> operator()
72                (server::conn_cb cb, std::string) {
73                        boost::shared_ptr<http::resource> rv
74                                (new http::grouplist(cb));
75                        return rv;
76                }
77        };
78        factory f;
79}
Note: See TracBrowser for help on using the browser.