gspamclient.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // ===
20 
21 #ifndef G_SMTP_SPAM_CLIENT_H
22 #define G_SMTP_SPAM_CLIENT_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gsmtp.h"
27 #include "gclient.h"
28 #include "gtimer.h"
29 #include "gpath.h"
30 #include "gslot.h"
31 #include "gexception.h"
32 #include "gmemory.h"
33 #include <fstream>
34 #include <vector>
35 
37 namespace GSmtp
38 {
39  class SpamClient ;
40 }
41 
48 {
49 public:
50  G_EXCEPTION( ProtocolError , "protocol error" ) ;
51 
52  SpamClient( const GNet::ResolverInfo & host_and_service ,
53  unsigned int connect_timeout , unsigned int response_timeout ) ;
55 
56  void request( const std::string & ) ;
64 
65  bool busy() const ;
68 
69 protected:
70  virtual ~SpamClient() ;
72 
73  virtual void onConnect() ;
75 
76  virtual bool onReceive( const std::string & ) ;
78 
79  virtual void onSendComplete() ;
81 
82  virtual void onDelete( const std::string & , bool ) ;
84 
85  virtual void onDeleteImp( const std::string & , bool ) ;
87 
88  virtual void onSecure( const std::string & ) ;
90 
91 private:
92  typedef GNet::Client Base ;
93  SpamClient( const SpamClient & ) ; // not implemented
94  void operator=( const SpamClient & ) ; // not implemented
95  void onTimeout() ;
96  void sendContent() ;
97  std::string headerResult() const ;
98  bool nextContentLine( std::string & ) ;
99  bool haveCompleteHeader() const ;
100  std::string headerLine( const std::string & , const std::string & = std::string() ) const ;
101  unsigned long headerBodyLength() const ;
102  void addHeader( const std::string & ) ;
103  void addBody( const std::string & ) ;
104  std::string part( const std::string & , unsigned int , const std::string & = std::string() ) const ;
105  void turnRound() ;
106 
107 private:
108  typedef std::vector<std::string> StringArray ;
109  std::string m_path ;
110  std::auto_ptr<std::ifstream> m_in ;
111  unsigned long m_in_size ;
112  unsigned long m_in_lines ;
113  std::auto_ptr<std::ofstream> m_out ;
114  unsigned long m_out_size ;
115  unsigned long m_out_lines ;
116  unsigned long m_n ;
117  unsigned int m_header_out_index ;
118  StringArray m_header_out ;
119  StringArray m_header_in ;
120  GNet::Timer<SpamClient> m_timer ;
121 } ;
122 
123 #endif
bool busy() const
Returns true after request() and before the subsequent event signal.
Definition: gspamclient.cpp:47
SMTP and message-store classes.
virtual bool onReceive(const std::string &)
Final override from GNet::Client.
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
virtual void onDeleteImp(const std::string &, bool)
Final override from GNet::Client.
Definition: gspamclient.cpp:56
virtual void onSendComplete()
Final override from GNet::BufferedClient.
void request(const std::string &)
Issues a request.
Definition: gspamclient.cpp:73
virtual ~SpamClient()
Destructor.
Definition: gspamclient.cpp:43
virtual void onConnect()
Final override from GNet::SimpleClient.
Definition: gspamclient.cpp:95
virtual void onDelete(const std::string &, bool)
Final override from GNet::HeapClient.
Definition: gspamclient.cpp:52
A client class that interacts with a remote process using a protocol somewhat similar to the spamassa...
Definition: gspamclient.h:47
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocol.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
SpamClient(const GNet::ResolverInfo &host_and_service, unsigned int connect_timeout, unsigned int response_timeout)
Constructor.
Definition: gspamclient.cpp:29
A timer class template in which the timeout is delivered to the specified method. ...
Definition: gtimer.h:103
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
Definition: gclient.h:51