- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gfilestore.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_FILE_STORE_H
22 #define G_SMTP_FILE_STORE_H
23
24 #include "gdef.h"
25 #include "gsmtp.h"
26 #include "gmessagestore.h"
27 #include "gdatetime.h"
28 #include "gexception.h"
29 #include "gprocess.h"
30 #include "gnoncopyable.h"
31 #include "gslot.h"
32 #include "groot.h"
33 #include "gpath.h"
34 #include "gexecutable.h"
35 #include <memory>
36 #include <string>
37
39 namespace GSmtp
40 {
41 class FileStore ;
42 class FileReader ;
43 class FileWriter ;
44 class DirectoryReader ;
45 }
46
62 class GSmtp::FileStore : public GSmtp::MessageStore
63 {
64 public:
65 G_EXCEPTION( InvalidDirectory , "invalid spool directory" ) ;
66 G_EXCEPTION( GetError , "error reading specific message" ) ;
67
68 FileStore( const G::Path & dir , bool optimise = false , unsigned long max_size = 0UL ) ;
80
81 unsigned long newSeq() ;
83
84 std::auto_ptr<std::ostream> stream( const G::Path & path ) ;
86
87 G::Path contentPath( unsigned long seq ) const ;
89
90 G::Path envelopePath( unsigned long seq ) const ;
92
93 G::Path envelopeWorkingPath( unsigned long seq ) const ;
96
97 virtual bool empty() const ;
99
100 virtual std::auto_ptr<StoredMessage> get( unsigned long id ) ;
102
103 virtual MessageStore::Iterator iterator( bool lock ) ;
105
106 virtual MessageStore::Iterator failures() ;
108
109 virtual std::auto_ptr<NewMessage> newMessage( const std::string & from ) ;
111
112 static std::string x() ;
114
115 static std::string format() ;
118
119 static bool knownFormat( const std::string & format ) ;
122
123 virtual void repoll() ;
125
126 virtual void unfailAll() ;
128
129 virtual void updated() ;
131
132 virtual G::Signal1<bool> & signal() ;
134
135 private:
136 static void checkPath( const G::Path & dir ) ;
137 G::Path fullPath( const std::string & filename ) const ;
138 std::string filePrefix( unsigned long seq ) const ;
139 std::string getline( std::istream & ) const ;
140 std::string value( const std::string & ) const ;
141 static const std::string & crlf() ;
142 bool emptyCore() const ;
143
144 private:
145 unsigned long m_seq ;
146 G::Path m_dir ;
147 bool m_optimise ;
148 bool m_empty ; // mutable
149 bool m_repoll ;
150 unsigned long m_max_size ;
151 unsigned long m_pid_modifier ;
152 G::Signal1<bool> m_signal ;
153 } ;
154
161 class GSmtp::FileReader : private G::Root
162 {
163 public:
164 FileReader() ;
167
168 ~FileReader() ;
170 } ;
171
178 class GSmtp::DirectoryReader : private G::Root
179 {
180 public:
181 DirectoryReader() ;
184
185 ~DirectoryReader() ;
187 } ;
188
194 class GSmtp::FileWriter : private G::Root , private G::Process::Umask
195 {
196 public:
197 FileWriter() ;
200
201 ~FileWriter() ;
203 } ;
204
205 #endif
206
GSmtp::FileStore::format
static std::string format()
Returns an identifier for the storage format implemented by this class.
Definition: gfilestore.cpp:115
GSmtp::FileStore::contentPath
G::Path contentPath(unsigned long seq) const
Returns the path for a content file.
Definition: gfilestore.cpp:161
GSmtp
SMTP and message-store classes.
GSmtp::FileStore::x
static std::string x()
Returns the prefix for envelope header lines.
Definition: gfilestore.cpp:110
GSmtp::FileWriter::FileWriter
FileWriter()
Default constructor.
Definition: gfilestore.cpp:314
GSmtp::FileStore::unfailAll
virtual void unfailAll()
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:279
GSmtp::FileStore::signal
virtual G::Signal1< bool > & signal()
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:269
GSmtp::FileStore::newMessage
virtual std::auto_ptr< NewMessage > newMessage(const std::string &from)
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:255
GSmtp::FileStore::iterator
virtual MessageStore::Iterator iterator(bool lock)
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:222
GSmtp::DirectoryReader
Used by GSmtp::FileStore, GSmtp::NewFile and GSmtp::StoredFile to claim read permissions for reading ...
Definition: gfilestore.h:178
G::Root
A class which acquires the process's special privileges on construction and releases them on destruct...
Definition: groot.h:49
G::Process::Umask
Used to temporarily modify the process umask.
Definition: gprocess.h:64
G::Signal1< bool >
gslot.h
groot.h
GSmtp::FileWriter
Used by GSmtp::FileStore, GSmtp::NewFile and GSmtp::StoredFile to claim write permissions.
Definition: gfilestore.h:194
gexecutable.h
GSmtp::FileStore::stream
std::auto_ptr< std::ostream > stream(const G::Path &path)
Returns a stream to the given content.
Definition: gfilestore.cpp:152
GSmtp::DirectoryReader::~DirectoryReader
~DirectoryReader()
Destructor. Switches identity back.
Definition: gfilestore.cpp:308
GSmtp::MessageStore
A class which allows SMTP messages (envelope+content) to be stored and retrieved. ...
Definition: gmessagestore.h:45
GSmtp::FileStore::FileStore
FileStore(const G::Path &dir, bool optimise=false, unsigned long max_size=0UL)
Constructor.
Definition: gfilestore.cpp:98
GSmtp::FileStore::failures
virtual MessageStore::Iterator failures()
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:227
GSmtp::FileStore::empty
virtual bool empty() const
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:199
gprocess.h
gmessagestore.h
GSmtp::FileReader::~FileReader
~FileReader()
Destructor. Switches identity back.
Definition: gfilestore.cpp:298
gdatetime.h
gexception.h
gnoncopyable.h
GSmtp::FileWriter::~FileWriter
~FileWriter()
Destructor. Switches identity back.
Definition: gfilestore.cpp:320
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
gpath.h
GSmtp::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files and with an opti...
Definition: gfilestore.h:62
GSmtp::FileStore::envelopePath
G::Path envelopePath(unsigned long seq) const
Returns the path for an envelope file.
Definition: gfilestore.cpp:166
GSmtp::FileStore::updated
virtual void updated()
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:261
GSmtp::DirectoryReader::DirectoryReader
DirectoryReader()
Default constructor.
Definition: gfilestore.cpp:304
gsmtp.h
GSmtp::FileStore::knownFormat
static bool knownFormat(const std::string &format)
Returns true if the storage format string is recognised and supported for reading.
Definition: gfilestore.cpp:120
GSmtp::FileStore::newSeq
unsigned long newSeq()
Hands out a new non-zero sequence number.
Definition: gfilestore.cpp:191
GSmtp::FileReader
Used by GSmtp::FileStore, GSmtp::NewFile and GSmtp::StoredFile to claim read permissions for reading ...
Definition: gfilestore.h:161
GSmtp::FileStore::repoll
virtual void repoll()
Final override from GSmtp::MessageStore.
Definition: gfilestore.cpp:274
G::Path
A Path object represents a file system path.
Definition: gpath.h:44
GSmtp::FileReader::FileReader
FileReader()
Default constructor.
Definition: gfilestore.cpp:294
GSmtp::FileStore::envelopeWorkingPath
G::Path envelopeWorkingPath(unsigned long seq) const
Returns the path for an envelope file which is in the process of being written.
Definition: gfilestore.cpp:171
GSmtp::MessageStore::Iterator
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:62