- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gpopstore.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_STORE_H
22 #define G_POP_STORE_H
23
24 #include "gdef.h"
25 #include "gpop.h"
26 #include "gpath.h"
27 #include "gexception.h"
28 #include <string>
29 #include <iostream>
30 #include <set>
31 #include <list>
32
34 namespace GPop
35 {
36 class Store ;
37 class StoreLock ;
38 class StoreLockEntry ;
39 }
40
46 class GPop::Store
47 {
48 public:
49 G_EXCEPTION( InvalidDirectory , "invalid spool directory" ) ;
50
51 Store( G::Path spool_dir , bool by_name , bool allow_delete ) ;
53
54 G::Path dir() const ;
56
57 bool allowDelete() const ;
59
60 bool byName() const ;
63
64 private:
65 Store( const Store & ) ;
66 void operator=( const Store & ) ;
67 static void checkPath( G::Path , bool , bool ) ;
68 static bool valid( G::Path , bool ) ;
69
70 private:
71 G::Path m_path ;
72 bool m_by_name ;
73 bool m_allow_delete ;
74 } ;
75
80 class GPop::StoreLockEntry
81 {
82 public:
83 int id ;
84 typedef unsigned long Size ;
85 Size size ;
86 std::string uidl ;
87 StoreLockEntry( int id_ , Size size_ , const std::string & uidl_ ) :
88 id(id_) ,
89 size(size_) ,
90 uidl(uidl_)
91 {
92 }
93 } ;
94
99 class GPop::StoreLock
100 {
101 public:
102 G_EXCEPTION( CannotDelete , "cannot delete message file" ) ;
103 G_EXCEPTION( CannotRead , "cannot read message file" ) ;
104 typedef StoreLockEntry::Size Size ;
105 typedef StoreLockEntry Entry ;
106 typedef std::list<Entry> List ;
107 typedef void (*Fn)(std::ostream&,const std::string&) ;
108
109 explicit StoreLock( Store & store ) ;
113
114 void lock( const std::string & user ) ;
119
120 bool locked() const ;
122
123 ~StoreLock() ;
125
126 Size messageCount() const ;
128
129 Size totalByteCount() const ;
131
132 Size byteCount( int id ) const ;
134
135 std::string uidl( int id ) const ;
137
138 bool valid( int id ) const ;
140
141 List list( int id = -1 ) const ;
143
144 std::auto_ptr<std::istream> get( int id ) const ;
146
147 void remove( int ) ;
149
150 void rollback() ;
155
156 void commit() ;
159
160 private:
162 struct File
163 {
164 std::string name ; // content name
165 StoreLockEntry::Size size ;
166 explicit File( const G::Path & ) ;
167 File( const std::string & name_ , const std::string & size_string ) ;
168 bool operator<( const File & ) const ;
169 static StoreLockEntry::Size toSize( const std::string & s ) ;
170 } ;
171 typedef std::set<File> Set ;
172
173 private:
174 StoreLock( const StoreLock & ) ; // not implemented
175 void operator=( const StoreLock & ) ; // not implemented
176 Set::iterator find( const std::string & ) ;
177 Set::const_iterator find( int id ) const ;
178 Set::iterator find( int id ) ;
179 void doCommit( Store & ) const ;
180 G::Path path( int id ) const ;
181 G::Path path( const std::string & , bool fallback ) const ;
182 std::string envelopeName( const std::string & ) const ;
183 std::string contentName( const std::string & ) const ;
184 G::Path contentPath( const std::string & ) const ;
185 G::Path contentPath( const File & ) const ;
186 G::Path envelopePath( const File & ) const ;
187 void deleteFile( const G::Path & , bool & ) const ;
188 bool unlinked( Store & , const File & ) const ;
189
190 private:
191 Store * m_store ;
192 G::Path m_dir ;
193 std::string m_user ;
194 Set m_initial ;
195 Set m_current ;
196 Set m_deleted ;
197 } ;
198
199 #endif
GPop::StoreLockEntry::uidl
std::string uidl
Definition: gpopstore.h:86
GPop::Store::dir
G::Path dir() const
Returns the spool directory path.
Definition: gpopstore.cpp:77
GPop::StoreLockEntry::id
int id
Definition: gpopstore.h:83
GPop::StoreLock::rollback
void rollback()
Rolls back remove()als but retains the lock.
Definition: gpopstore.cpp:437
GPop::StoreLock::locked
bool locked() const
Returns true if locked.
Definition: gpopstore.cpp:224
GPop::StoreLock::Size
StoreLockEntry::Size Size
Definition: gpopstore.h:102
GPop::Store::Store
Store(G::Path spool_dir, bool by_name, bool allow_delete)
Constructor.
Definition: gpopstore.cpp:69
GPop::StoreLockEntry::StoreLockEntry
StoreLockEntry(int id_, Size size_, const std::string &uidl_)
Definition: gpopstore.h:87
GPop::StoreLock::messageCount
Size messageCount() const
Returns the store's message count.
Definition: gpopstore.cpp:233
GPop::StoreLockEntry
Represents a file in the GPop::Store.
Definition: gpopstore.h:80
GPop::Store::allowDelete
bool allowDelete() const
Returns true if files can be deleted.
Definition: gpopstore.cpp:82
GPop::Store
A message store.
Definition: gpopstore.h:46
GPop::StoreLock::totalByteCount
Size totalByteCount() const
Returns the store's total byte count.
Definition: gpopstore.cpp:239
GPop::StoreLock::Entry
StoreLockEntry Entry
Definition: gpopstore.h:105
GPop::StoreLock
Represents an exclusive lock on the message store.
Definition: gpopstore.h:99
GPop::StoreLock::~StoreLock
~StoreLock()
Destructor.
Definition: gpopstore.cpp:229
gpop.h
GPop::StoreLock::List
std::list< Entry > List
Definition: gpopstore.h:106
GPop::StoreLock::lock
void lock(const std::string &user)
Initialisation.
Definition: gpopstore.cpp:183
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::StoreLock::byteCount
Size byteCount(int id) const
Returns a message size.
Definition: gpopstore.cpp:281
GPop::StoreLock::commit
void commit()
Commits remove()als.
Definition: gpopstore.cpp:333
gpath.h
GPop::Store::byName
bool byName() const
Returns true if the spool directory is affected by the user name.
Definition: gpopstore.cpp:87
GPop::StoreLock::valid
bool valid(int id) const
Validates a message number.
Definition: gpopstore.cpp:248
GPop::StoreLockEntry::Size
unsigned long Size
Definition: gpopstore.h:84
GPop
POP3 classes.
GPop::StoreLock::StoreLock
StoreLock(Store &store)
Constructor.
Definition: gpopstore.cpp:178
GPop::StoreLock::Fn
void(* Fn)(std::ostream &, const std::string &)
Definition: gpopstore.h:107
G::Path
A Path object represents a file system path.
Definition: gpath.h:44
GPop::StoreLock::list
List list(int id=-1) const
Lists messages in the store.
Definition: gpopstore.cpp:287
GPop::StoreLockEntry::size
Size size
Definition: gpopstore.h:85
GPop::StoreLock::uidl
std::string uidl(int id) const
Returns a message's unique id.
Definition: gpopstore.cpp:377