E-MailRelay

grequestclient.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file grequestclient.h
19///
20
21#ifndef G_REQUEST_CLIENT_H
22#define G_REQUEST_CLIENT_H
23
24#include "gdef.h"
25#include "gclient.h"
26#include "gtimer.h"
27#include "gpath.h"
28#include "gslot.h"
29#include "gexception.h"
30
31 namespace GSmtp
32{
33 class RequestClient ;
34}
35
36//| \class GSmtp::RequestClient
37/// A network client class that interacts with a remote server using a
38/// stateless line-based request/response protocol.
39///
40/// Line buffering uses newline as end-of-line, and trailing carriage-returns
41/// are trimmed from the input.
42///
43/// The received network responses are delivered via the GNet::Client
44/// class's event signal.
45///
46 class GSmtp::RequestClient : public GNet::Client
47{
48 public:
49 G_EXCEPTION( ProtocolError , "protocol error" ) ;
50
51 RequestClient( GNet::ExceptionSink , const std::string & key , const std::string & ok ,
52 const GNet::Location & host_and_service , unsigned int connect_timeout ,
53 unsigned int response_timeout ) ;
54 ///< Constructor. The 'key' parameter is used in the callback
55 ///< signal. The 'ok' parameter is a response string that is
56 ///< converted to the empty string.
57
58 void request( const std::string & ) ;
59 ///< Issues a request. A newline is added to the request string,
60 ///< so append a carriage-return if required.
61 ///<
62 ///< If not currently connected then the request is queued up until
63 ///< the connection is made.
64 ///<
65 ///< The base class's "event" signal will be emitted when processing
66 ///< is complete. In this case the first signal parameter will be the
67 ///< "key" string specified in the constructor call and the second
68 ///< will be the parsed response.
69 ///<
70 ///< See also GNet::Client::eventSignal().
71 ///<
72 ///< Every request will get a single response as long as this method
73 ///< is not called re-entrantly from within the previous request's
74 ///< response signal.
75
76 bool busy() const ;
77 ///< Returns true after request() and before the subsequent
78 ///< event signal.
79
80 private: // overrides
81 bool onReceive( const char * , std::size_t , std::size_t , std::size_t , char ) override ; // Override from GNet::Client.
82 void onSendComplete() override ; // Override from GNet::BufferedClient.
83 void onDelete( const std::string & ) override ; // Override from GNet::Client.
84 void onSecure( const std::string & , const std::string & , const std::string & ) override ; // Override from GNet::SocketProtocolSink.
85 void onConnect() override ; // Override from GNet::SimpleClient.
86
87 public:
88 ~RequestClient() override = default ;
89 RequestClient( const RequestClient & ) = delete ;
90 RequestClient( RequestClient && ) = delete ;
91 void operator=( const RequestClient & ) = delete ;
92 void operator=( RequestClient && ) = delete ;
93
94 private:
95 void onTimeout() ;
96 std::string requestLine( const std::string & ) const ;
97 std::string result( std::string ) const ;
98 static GNet::Client::Config netConfig( unsigned int connection_timeout , unsigned int response_timeout ) ;
99
100 private:
101 std::string m_eol ;
102 std::string m_key ;
103 std::string m_ok ;
104 std::string m_request ;
105 GNet::Timer<RequestClient> m_timer ;
106} ;
107
108#endif
GNet::Client
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
Definition: gclient.h:75
GNet::ExceptionSink
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
Definition: gexceptionsink.h:100
GNet::Location
A class that represents the remote target for out-going client connections.
Definition: glocation.h:71
GNet::Timer
A timer class template in which the timeout is delivered to the specified method.
Definition: gtimer.h:129
GSmtp::RequestClient
A network client class that interacts with a remote server using a stateless line-based request/respo...
Definition: grequestclient.h:47
GSmtp::RequestClient::busy
bool busy() const
Returns true after request() and before the subsequent event signal.
Definition: grequestclient.cpp:73
GSmtp::RequestClient::RequestClient
RequestClient(GNet::ExceptionSink, const std::string &key, const std::string &ok, const GNet::Location &host_and_service, unsigned int connect_timeout, unsigned int response_timeout)
Constructor.
Definition: grequestclient.cpp:25
GSmtp::RequestClient::request
void request(const std::string &)
Issues a request.
Definition: grequestclient.cpp:52
gclient.h
gexception.h
gpath.h
gslot.h
gtimer.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
GNet::Client::Config
A structure containing GNet::Client configuration parameters.
Definition: gclient.h:84