gpopserverprotocol.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_POP_SERVER_PROTOCOL_H
22 #define G_POP_SERVER_PROTOCOL_H
23 
24 #include "gdef.h"
25 #include "gpop.h"
26 #include "gaddress.h"
27 #include "gstatemachine.h"
28 #include "gpopsecrets.h"
29 #include "gpopstore.h"
30 #include "gpopauth.h"
31 #include "gmemory.h"
32 #include "gtimer.h"
33 #include "gexception.h"
34 
36 namespace GPop
37 {
38  class ServerProtocol ;
39  class ServerProtocolText ;
40 }
41 
51 {
52 public:
53  G_EXCEPTION( ProtocolDone , "pop protocol done" ) ;
55  class Sender
56  {
57  public: virtual bool protocolSend( const std::string & s , size_t offset ) = 0 ;
58  public: virtual ~Sender() ;
59  private: void operator=( const Sender & ) ; // not implemented
60  } ;
62  class Text
63  {
64  public: virtual std::string greeting() const = 0 ;
65  public: virtual std::string quit() const = 0 ;
66  public: virtual std::string capa() const = 0 ;
67  public: virtual std::string user( const std::string & id ) const = 0 ;
68  public: virtual ~Text() ;
69  private: void operator=( const Text & ) ; // not implemented
70  } ;
72  struct Config
73  {
74  bool dummy ;
75  Config() ;
76  } ;
78  class Security
79  {
80  public: virtual bool securityEnabled() const = 0 ;
81  public: virtual void securityStart() = 0 ;
82  public: virtual ~Security() ;
83  private: void operator=( const Security & ) ; // not implemented
84  } ;
85 
86  ServerProtocol( Sender & sender , Security & security , Store & store , const Secrets & secrets ,
87  const Text & text , GNet::Address peer_address , Config config ) ;
97 
98  virtual ~ServerProtocol() ;
100 
101  void init() ;
103 
104  void apply( const std::string & line ) ;
108 
109  void resume() ;
113 
114  void secure() ;
116 
117 private:
118  enum Event
119  {
120  eApop ,
121  eAuth ,
122  eAuthData ,
123  eCapa ,
124  eDele ,
125  eList ,
126  eNoop ,
127  ePass ,
128  eQuit ,
129  eRetr ,
130  eRset ,
131  eSent ,
132  eStat ,
133  eTop ,
134  eUidl ,
135  eUser ,
136  eStls ,
137  eSecure ,
138  eUnknown
139  } ;
140  enum State
141  {
142  sStart ,
143  sEnd ,
144  sActive ,
145  sData ,
146  sAuth ,
147  s_Any ,
148  s_Same
149  } ;
151 
152 private:
153  ServerProtocol( const ServerProtocol & ) ; // not implemented
154  void operator=( const ServerProtocol & ) ; // not implemented
155  void doQuit( const std::string & line , bool & ) ;
156  void doQuitEarly( const std::string & line , bool & ) ;
157  void doStat( const std::string & line , bool & ) ;
158  void doList( const std::string & line , bool & ) ;
159  void doRetr( const std::string & line , bool & ) ;
160  void doDele( const std::string & line , bool & ) ;
161  void doRset( const std::string & line , bool & ) ;
162  void doUser( const std::string & line , bool & ) ;
163  void doPass( const std::string & line , bool & ) ;
164  void doNoop( const std::string & line , bool & ) ;
165  void doNothing( const std::string & line , bool & ) ;
166  void doApop( const std::string & line , bool & ) ;
167  void doTop( const std::string & line , bool & ) ;
168  void doCapa( const std::string & line , bool & ) ;
169  void doStls( const std::string & line , bool & ) ;
170  void doAuth( const std::string & line , bool & ) ;
171  void doAuthData( const std::string & line , bool & ) ;
172  void doUidl( const std::string & line , bool & ) ;
173  void sendInit() ;
174  void sendError() ;
175  void sendError( const std::string & ) ;
176  void sendOk() ;
177  static const std::string & crlf() ;
178  Event commandEvent( const std::string & ) const ;
179  int commandNumber( const std::string & , int , size_t index = 1U ) const ;
180  void sendList( const std::string & , bool ) ;
181  std::string commandWord( const std::string & ) const ;
182  std::string commandParameter( const std::string & , size_t index = 1U ) const ;
183  std::string commandPart( const std::string & , size_t index ) const ;
184  void sendContent() ;
185  bool sendContentLine( std::string & , bool & ) ;
186  void send( std::string ) ;
187  void lockStore() ;
188  std::string mechanismsWithoutLogin() const ;
189  bool mechanismsIncludePlain() const ;
190 
191 private:
192  const Text & m_text ;
193  Sender & m_sender ;
194  Security & m_security ;
195  Store & m_store ;
196  StoreLock m_store_lock ;
197  const Secrets & m_secrets ;
198  Auth m_auth ;
199  GNet::Address m_peer_address ;
200  Fsm m_fsm ;
201  std::string m_user ;
202  std::auto_ptr<std::istream> m_content ;
203  long m_body_limit ;
204  bool m_in_body ;
205  bool m_secure ;
206 } ;
207 
213 {
214 public:
215  explicit ServerProtocolText( GNet::Address peer ) ;
217 
218  virtual std::string greeting() const ;
220 
221  virtual std::string quit() const ;
223 
224  virtual std::string capa() const ;
226 
227  virtual std::string user( const std::string & id ) const ;
229 } ;
230 
231 #endif
virtual bool securityEnabled() const =0
A simple interface to a store of secrets as used in authentication.
Definition: gpopsecrets.h:44
Implements the POP server-side protocol.
virtual std::string quit() const
Final override from GPop::ServerProtocol::Text.
virtual std::string greeting() const
Final override from GPop::ServerProtocol::Text.
virtual std::string quit() const =0
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
virtual std::string capa() const
Final override from GPop::ServerProtocol::Text.
virtual std::string greeting() const =0
virtual std::string user(const std::string &id) const =0
void init()
Starts the protocol.
virtual ~ServerProtocol()
Destructor.
An interface used by ServerProtocol to send protocol replies.
A message store.
Definition: gpopstore.h:46
virtual bool protocolSend(const std::string &s, size_t offset)=0
An interface used by ServerProtocol to enable TLS.
ServerProtocolText(GNet::Address peer)
Constructor.
A default implementation for the ServerProtocol::Text interface.
An interface used by ServerProtocol to provide response text strings.
virtual std::string user(const std::string &id) const
Final override from GPop::ServerProtocol::Text.
virtual std::string capa() const =0
ServerProtocol(Sender &sender, Security &security, Store &store, const Secrets &secrets, const Text &text, GNet::Address peer_address, Config config)
Constructor.
A structure containing configuration parameters for ServerProtocol. NOT USED.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
void secure()
Called when the server connection becomes secure.
POP3 classes.
void apply(const std::string &line)
Called on receipt of a string from the client.
virtual void securityStart()=0
void resume()
Called when the Sender can send again.