Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _FILE_H
00034 #define _FILE_H
00035
00036 #ifdef HAVE_CONFIG_H
00037 # include <config.h>
00038 #endif
00039
00040 #ifdef HAVE_ASSERT_H
00041 # include <assert.h>
00042 #endif
00043
00044 #ifdef HAVE_STRING
00045 # include <string>
00046 #endif
00047
00048 #ifdef HAVE_LIST
00049 # include <list>
00050 #endif
00051
00052 #include "yapetexception.h"
00053
00054 #include "bdbuffer.h"
00055 #include "structs.h"
00056 #include "key.h"
00057 #include "partdec.h"
00058
00059 namespace YAPET {
00193 class File {
00194 private:
00200 int fd;
00206 std::string filename;
00218 int64_t mtime;
00219
00232 bool usefsecurity;
00233
00235 void checkFileSecurity() throw (YAPETException);
00237 void setFileSecurity() throw (YAPETException);
00238
00240 void openCreate() throw (YAPETException);
00242 void openNoCreate() throw (YAPETException);
00244 int64_t lastModified() const throw (YAPETException);
00246 void seekCurr (off_t offset) const throw (YAPETException);
00248 void seekAbs (off_t offset) const throw (YAPETException);
00250 void preparePWSave() throw (YAPETException);
00251
00252 protected:
00253 template <class t>
00254 union ENDIAN {
00260 t value;
00261 uint8_t fields[sizeof(t)];
00262 };
00263
00264 #ifndef WORDS_BIGENDIAN
00265
00275 template<class t>
00276 t int_to_disk (t le) const {
00277 ENDIAN<t> in;
00278 ENDIAN<t> out;
00279 in.value = le;
00280 out.value = 0;
00281 for (register unsigned int i=0; i < sizeof(t); i++)
00282 out.fields[(sizeof(t)-1)-i] = in.fields[i];
00283 return out.value;
00284 }
00295 template<class t>
00296 t int_from_disk (t i) const {
00297 return int_to_disk<t>(i);
00298 }
00299 #else
00300
00311 template<class t>
00312 t int_to_disk (t i) const {
00313 return i;
00314 }
00327 template<class t>
00328 t int_from_disk (t i) const {
00329 return i;
00330 }
00331 #endif // WORDS_BIGENDIAN
00332
00335 void seekDataSection() const throw (YAPETException);
00336
00338 BDBuffer* read() const throw (YAPETException);
00340 void write (const BDBuffer& buff,
00341 bool forceappend = false,
00342 bool forcewrite = false)
00343 throw (YAPETException, YAPETRetryException);
00345 bool isempty() const throw (YAPETException);
00347 void initFile (const Key& key) throw (YAPETException);
00349 void writeHeader (const Record<FileHeader_64>& header,
00350 const Key& key)
00351 throw (YAPETException);
00353 void writeHeader (const BDBuffer& enc_header) throw (YAPETException);
00355 BDBuffer* readHeader() const throw (YAPETException);
00357 void readHeader(const Key& key, Record<FileHeader_32>** ptr32, Record<FileHeader_64>** ptr64) const throw(YAPETException);
00359 void validateKey (const Key& key)
00360 throw (YAPETException, YAPETInvalidPasswordException);
00361
00362 public:
00364 File (const std::string& fn,
00365 const Key& key,
00366 bool create = false,
00367 bool secure = true)
00368 throw (YAPETException);
00369 File (const File& f) throw (YAPETException);
00370 ~File();
00371
00373 void save (std::list<PartDec>& records) throw (YAPETException);
00375 std::list<PartDec> read (const Key& key) const throw (YAPETException);
00377 std::string getFilename() const {
00378 return filename;
00379 }
00381 void setNewKey (const Key& oldkey, const Key& newkey) throw (YAPETException);
00382 int64_t getMasterPWSet (const Key& key) const throw (YAPETException, YAPETInvalidPasswordException);
00384 FILE_VERSION getFileVersion(const Key& key) const throw (YAPETException, YAPETInvalidPasswordException);
00386 const File& operator= (const File& f) throw (YAPETException);
00387
00389 bool filesecurityEnabled() const {
00390 return usefsecurity;
00391 }
00393 void setFilesecurity (bool secure) {
00394 usefsecurity = secure;
00395 }
00396 };
00397 }
00398 #endif // _FILE_H