source: box/trunk/lib/backupstore/BackupStoreFilename.h @ 2945

Revision 2945, 3.2 KB checked in by chris, 13 months ago (diff)

Major refactoring to make lib/backupclient depend on lib/backupstore rather
than the other way around. This is needed to allow clients to have all the
code that they'd need to implement local backups (using the Local protocol)
in subsequent commits.

  • Property svn:eol-style set to native
Line 
1// --------------------------------------------------------------------------
2//
3// File
4//              Name:    BackupStoreFilename.h
5//              Purpose: Filename for the backup store
6//              Created: 2003/08/26
7//
8// --------------------------------------------------------------------------
9
10#ifndef BACKUPSTOREFILENAME__H
11#define BACKUPSTOREFILENAME__H
12
13#include <string>
14
15class Protocol;
16class IOStream;
17
18// #define BACKUPSTOREFILEAME_MALLOC_ALLOC_BASE_TYPE
19// don't define this -- the problem of memory usage still appears without this.
20// It's just that this class really showed up the problem. Instead, malloc allocation
21// is globally defined in BoxPlatform.h, for troublesome libraries.
22
23#ifdef BACKUPSTOREFILEAME_MALLOC_ALLOC_BASE_TYPE
24        // Use a malloc_allocated string, because the STL default allocators really screw up with
25        // memory allocation, particularly with this class.
26        // Makes a few things a bit messy and inefficient with conversions.
27        // Given up using this, and use global malloc allocation instead, but thought it
28        // worth leaving this code in just in case it's useful for the future.
29        typedef std::basic_string<char, std::string_char_traits<char>, std::malloc_alloc> BackupStoreFilename_base;
30        // If this is changed, change GetClearFilename() back to returning a reference.
31#else
32        typedef std::string BackupStoreFilename_base;
33#endif
34
35// --------------------------------------------------------------------------
36//
37// Class
38//              Name:    BackupStoreFilename
39//              Purpose: Filename for the backup store
40//              Created: 2003/08/26
41//
42// --------------------------------------------------------------------------
43class BackupStoreFilename /* : public BackupStoreFilename_base */
44{
45private:
46        std::string mEncryptedName;
47
48public:
49        BackupStoreFilename();
50        BackupStoreFilename(const BackupStoreFilename &rToCopy);
51        virtual ~BackupStoreFilename();
52
53        bool CheckValid(bool ExceptionIfInvalid = true) const;
54       
55        void ReadFromProtocol(Protocol &rProtocol);
56        void WriteToProtocol(Protocol &rProtocol) const;
57       
58        void ReadFromStream(IOStream &rStream, int Timeout);
59        void WriteToStream(IOStream &rStream) const;
60
61        void SetAsClearFilename(const char *Clear);
62
63        // Check that it's encrypted
64        bool IsEncrypted() const;
65       
66        // These enumerated types belong in the base class so
67        // the CheckValid() function can make sure that the encoding
68        // is a valid encoding
69        enum
70        {
71                Encoding_Min = 1,
72                Encoding_Clear = 1,
73                Encoding_Blowfish = 2,
74                Encoding_Max = 2
75        };
76
77        const std::string& GetEncodedFilename() const
78        {
79                return mEncryptedName;
80        }
81
82        bool operator==(const BackupStoreFilename& rOther) const
83        {
84                return mEncryptedName == rOther.mEncryptedName;
85        }
86
87        bool operator!=(const BackupStoreFilename& rOther) const
88        {
89                return mEncryptedName != rOther.mEncryptedName;
90        }
91
92protected:
93        virtual void EncodedFilenameChanged();
94        void SetEncodedFilename(const std::string &rEncoded)
95        {
96                mEncryptedName = rEncoded;
97        }
98};
99
100// On the wire utilities for class and derived class
101#define BACKUPSTOREFILENAME_GET_SIZE(hdr)               (( ((uint8_t)((hdr)[0])) | ( ((uint8_t)((hdr)[1])) << 8)) >> 2)
102#define BACKUPSTOREFILENAME_GET_ENCODING(hdr)   (((hdr)[0]) & 0x3)
103
104#define BACKUPSTOREFILENAME_MAKE_HDR(hdr, size, encoding)               {uint16_t h = (((uint16_t)size) << 2) | (encoding); ((hdr)[0]) = h & 0xff; ((hdr)[1]) = h >> 8;}
105
106#endif // BACKUPSTOREFILENAME__H
107
Note: See TracBrowser for help on using the repository browser.