- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
50 class GPop::ServerProtocol
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 } ;
150 typedef G::StateMachine<ServerProtocol,State,Event> Fsm ;
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
212 class GPop::ServerProtocolText : public GPop::ServerProtocol::Text
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
GPop::ServerProtocol::Security::securityEnabled
virtual bool securityEnabled() const =0
GPop::Secrets
A simple interface to a store of secrets as used in authentication.
Definition: gpopsecrets.h:44
GPop::ServerProtocol
Implements the POP server-side protocol.
Definition: gpopserverprotocol.h:50
GPop::ServerProtocolText::quit
virtual std::string quit() const
Final override from GPop::ServerProtocol::Text.
Definition: gpopserverprotocol.cpp:595
GPop::ServerProtocolText::greeting
virtual std::string greeting() const
Final override from GPop::ServerProtocol::Text.
Definition: gpopserverprotocol.cpp:590
GPop::ServerProtocol::Text::quit
virtual std::string quit() const =0
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
GPop::ServerProtocolText::capa
virtual std::string capa() const
Final override from GPop::ServerProtocol::Text.
Definition: gpopserverprotocol.cpp:600
GPop::ServerProtocol::Security::~Security
virtual ~Security()
Definition: gpopserverprotocol.cpp:630
GPop::ServerProtocol::Text::greeting
virtual std::string greeting() const =0
gstatemachine.h
gpopstore.h
GPop::ServerProtocol::Text::user
virtual std::string user(const std::string &id) const =0
GPop::ServerProtocol::init
void init()
Starts the protocol.
Definition: gpopserverprotocol.cpp:71
GPop::ServerProtocol::~ServerProtocol
virtual ~ServerProtocol()
Destructor.
Definition: gpopserverprotocol.cpp:76
GPop::ServerProtocol::Sender
An interface used by ServerProtocol to send protocol replies.
Definition: gpopserverprotocol.h:55
GPop::Store
A message store.
Definition: gpopstore.h:46
GPop::ServerProtocol::Sender::protocolSend
virtual bool protocolSend(const std::string &s, size_t offset)=0
GPop::ServerProtocol::Security
An interface used by ServerProtocol to enable TLS.
Definition: gpopserverprotocol.h:78
GPop::ServerProtocolText::ServerProtocolText
ServerProtocolText(GNet::Address peer)
Constructor.
Definition: gpopserverprotocol.cpp:586
GPop::ServerProtocolText
A default implementation for the ServerProtocol::Text interface.
Definition: gpopserverprotocol.h:212
gtimer.h
GPop::ServerProtocol::Text
An interface used by ServerProtocol to provide response text strings.
Definition: gpopserverprotocol.h:62
GPop::ServerProtocolText::user
virtual std::string user(const std::string &id) const
Final override from GPop::ServerProtocol::Text.
Definition: gpopserverprotocol.cpp:605
gpopsecrets.h
GPop::ServerProtocol::Text::capa
virtual std::string capa() const =0
gpop.h
GPop::ServerProtocol::ServerProtocol
ServerProtocol(Sender &sender, Security &security, Store &store, const Secrets &secrets, const Text &text, GNet::Address peer_address, Config config)
Constructor.
Definition: gpopserverprotocol.cpp:31
GPop::ServerProtocol::Config
A structure containing configuration parameters for ServerProtocol. NOT USED.
Definition: gpopserverprotocol.h:72
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
GPop::ServerProtocol::Config::dummy
bool dummy
Definition: gpopserverprotocol.h:74
GPop::ServerProtocol::secure
void secure()
Called when the server connection becomes secure.
Definition: gpopserverprotocol.cpp:475
gaddress.h
GPop
POP3 classes.
gpopauth.h
gmemory.h
GPop::ServerProtocol::apply
void apply(const std::string &line)
Called on receipt of a string from the client.
Definition: gpopserverprotocol.cpp:110
GPop::ServerProtocol::Security::securityStart
virtual void securityStart()=0
G::StateMachine< ServerProtocol, State, Event >
GPop::ServerProtocol::resume
void resume()
Called when the Sender can send again.
Definition: gpopserverprotocol.cpp:155
GPop::ServerProtocol::Config::Config
Config()
Definition: gpopserverprotocol.cpp:624
GPop::ServerProtocol::Text::~Text
virtual ~Text()
Definition: gpopserverprotocol.cpp:612
GPop::ServerProtocol::Sender::~Sender
virtual ~Sender()
Definition: gpopserverprotocol.cpp:618