root/smtp_client/smtp_client.hh

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

[nntp::connection::tick] Kill idle connections (timeout at 2 hours)

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#ifndef GUARD_SMTP_CLIENT_SMTP_CLIENT_HH
21#define GUARD_SMTP_CLIENT_SMTP_CLIENT_HH
22
23#include <boost/asio.hpp>
24#include <boost/thread/mutex.hpp>
25#include <boost/enable_shared_from_this.hpp>
26#include <boost/noncopyable.hpp>
27#include <list>
28#include <string>
29
30namespace smtp_client
31{
32        class smtp_client : private boost::noncopyable
33                          , public boost::enable_shared_from_this<smtp_client>
34        {
35                struct envelope
36                {
37                        std::string sender;
38                        std::string recipient;
39                        std::string data;
40                };
41
42                class connection : private boost::noncopyable
43                {
44                public:
45                        typedef boost::shared_ptr<connection> ptr;
46                        connection(boost::shared_ptr<smtp_client>);
47                        static void start(ptr);
48                private:
49                        boost::shared_ptr<smtp_client> sc;
50
51                        boost::asio::ip::tcp::resolver res;
52                        boost::asio::ip::tcp::resolver::query que;
53                        boost::asio::ip::tcp::socket serv;
54
55                        enum state_type { BANNER,
56                                          EHLO,
57                                          HELO,
58                                          RSET,
59                                          MAIL_FROM,
60                                          RCPT_TO,
61                                          DATA,
62                                          DATA_354,
63                                          QUIT
64                        } state;
65                        boost::shared_ptr<envelope> cur;
66
67                        boost::asio::streambuf readbuf;
68
69                        static void resolved(
70                                ptr,
71                                boost::system::error_code,
72                                boost::asio::ip::tcp::resolver::iterator);
73                        static void connected(
74                                ptr self,
75                                boost::asio::ip::tcp::resolver::iterator,
76                                boost::system::error_code ec);
77                        static void async_read_response(ptr self);
78                        static void got_response(ptr self,
79                                                 std::string resp,
80                                                 boost::system::error_code ec,
81                                                 size_t bytes);
82                        static void send_line(ptr self, std::string line);
83                        static void send_raw(ptr self, std::string raw);
84                        static void send_raw_no_log(ptr self, std::string raw);
85                        static void sent(
86                                ptr self,
87                                boost::shared_ptr<boost::asio::const_buffers_1>,
88                                boost::system::error_code ec,
89                                size_t);
90                };
91
92                boost::asio::io_service &ios;
93                boost::shared_ptr<connection> active_connection;
94
95                boost::mutex m;
96                std::list<boost::shared_ptr<envelope> > ready;
97                std::list<boost::shared_ptr<envelope> > deferred;
98
99                void async_run_queue();
100        public:
101                smtp_client(boost::asio::io_service &ios)
102                        : ios(ios)
103                        {}
104
105                void send_mail(const std::list<std::string> &recipients,
106                               std::string message);
107                void tick(bool);
108        };
109}
110
111#endif /* GUARD_SMTP_CLIENT_SMTP_CLIENT_HH */
Note: See TracBrowser for help on using the browser.