E-MailRelay
grequestclient.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 "gsmtp.h"
26 #include "gclient.h"
27 #include "gtimer.h"
28 #include "gpath.h"
29 #include "gslot.h"
30 #include "gexception.h"
31 
32 namespace GSmtp
33 {
34  class RequestClient ;
35 }
36 
37 /// \class GSmtp::RequestClient
38 /// A network client class that interacts with a remote server using a
39 /// stateless line-based request/response protocol.
40 ///
41 /// Line buffering uses newline as end-of-line, and trailing carriage-returns
42 /// are trimmed from the input.
43 ///
45 {
46 public:
47  G_EXCEPTION( ProtocolError , "protocol error" ) ;
48 
49  RequestClient( const std::string & key , const std::string & ok ,
50  const GNet::Location & host_and_service , unsigned int connect_timeout ,
51  unsigned int response_timeout ) ;
52  ///< Constructor. The 'key' parameter is used in the callback
53  ///< signal. The 'ok' parameter is a response string that is
54  ///< converted to the empty string.
55 
56  void request( const std::string & ) ;
57  ///< Issues a request. A newline is added to the request string,
58  ///< so append a carriage-return if required.
59  ///<
60  ///< If not currently connected then the request is queued up until
61  ///< the connection is made.
62  ///<
63  ///< The base class's "event" signal will be emitted when processing
64  ///< is complete. In this case the first signal parameter will be the
65  ///< "key" string specified in the constructor call and the second
66  ///< will be the parsed response.
67  ///<
68  ///< See also GNet::Client::eventSignal().
69  ///<
70  ///< Every request will get a single response as long as this method
71  ///< is not called re-entrantly from within the previous request's
72  ///< response signal.
73 
74  bool busy() const ;
75  ///< Returns true after request() and before the subsequent
76  ///< event signal.
77 
78 protected:
79  virtual ~RequestClient() ;
80  ///< Destructor.
81 
82  virtual void onConnect() override ;
83  ///< Override from GNet::SimpleClient.
84 
85  virtual bool onReceive( const char * , size_t , size_t ) override ;
86  ///< Override from GNet::Client.
87 
88  virtual void onSendComplete() override ;
89  ///< Override from GNet::BufferedClient.
90 
91  virtual void onDelete( const std::string & ) override ;
92  ///< Override from GNet::HeapClient.
93 
94  virtual void onDeleteImp( const std::string & ) override ;
95  ///< Override from GNet::Client.
96 
97  virtual void onSecure( const std::string & ) override ;
98  ///< Override from GNet::SocketProtocolSink.
99 
100 private:
101  RequestClient( const RequestClient & ) ;
102  void operator=( const RequestClient & ) ;
103  void onTimeout() ;
104  std::string requestLine( const std::string & ) const ;
105  std::string result( std::string ) const ;
106  static GNet::LineBufferConfig config() ;
107 
108 private:
109  std::string m_eol ;
110  std::string m_key ;
111  std::string m_ok ;
112  std::string m_request ;
114 } ;
115 
116 #endif
SMTP and message-store classes.
Definition: gadminserver.h:39
virtual void onConnect() override
Override from GNet::SimpleClient.
virtual ~RequestClient()
Destructor.
virtual void onDeleteImp(const std::string &) override
Override from GNet::Client.
virtual bool onReceive(const char *, size_t, size_t) override
Override from GNet::Client.
A class that holds a host/service name pair and the preferred address family (if any), and also the results of a name-to-address lookup, ie.
Definition: glocation.h:50
A configuration structure for GNet::LineBuffer.
Definition: glinebuffer.h:174
virtual void onSecure(const std::string &) override
Override from GNet::SocketProtocolSink.
virtual void onSendComplete() override
Override from GNet::BufferedClient.
void request(const std::string &)
Issues a request.
bool busy() const
Returns true after request() and before the subsequent event signal.
virtual void onDelete(const std::string &) override
Override from GNet::HeapClient.
RequestClient(const std::string &key, const std::string &ok, const GNet::Location &host_and_service, unsigned int connect_timeout, unsigned int response_timeout)
Constructor.
A timer class template in which the timeout is delivered to the specified method. ...
Definition: gtimer.h:115
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
Definition: gclient.h:48
A network client class that interacts with a remote server using a stateless line-based request/respo...