| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: BackupClientContext.h |
|---|
| 5 | // Purpose: Keep track of context |
|---|
| 6 | // Created: 2003/10/08 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef BACKUPCLIENTCONTEXT__H |
|---|
| 11 | #define BACKUPCLIENTCONTEXT__H |
|---|
| 12 | |
|---|
| 13 | #include "BoxTime.h" |
|---|
| 14 | #include "BackupClientDeleteList.h" |
|---|
| 15 | #include "BackupClientDirectoryRecord.h" |
|---|
| 16 | #include "BackupDaemonInterface.h" |
|---|
| 17 | #include "BackupStoreFile.h" |
|---|
| 18 | #include "ExcludeList.h" |
|---|
| 19 | #include "TcpNice.h" |
|---|
| 20 | #include "Timer.h" |
|---|
| 21 | |
|---|
| 22 | class TLSContext; |
|---|
| 23 | class BackupProtocolClient; |
|---|
| 24 | class SocketStreamTLS; |
|---|
| 25 | class BackupClientInodeToIDMap; |
|---|
| 26 | class BackupDaemon; |
|---|
| 27 | class BackupStoreFilenameClear; |
|---|
| 28 | |
|---|
| 29 | #include <string> |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | // -------------------------------------------------------------------------- |
|---|
| 33 | // |
|---|
| 34 | // Class |
|---|
| 35 | // Name: BackupClientContext |
|---|
| 36 | // Purpose: |
|---|
| 37 | // Created: 2003/10/08 |
|---|
| 38 | // |
|---|
| 39 | // -------------------------------------------------------------------------- |
|---|
| 40 | class BackupClientContext : public DiffTimer |
|---|
| 41 | { |
|---|
| 42 | public: |
|---|
| 43 | BackupClientContext |
|---|
| 44 | ( |
|---|
| 45 | LocationResolver &rResolver, |
|---|
| 46 | TLSContext &rTLSContext, |
|---|
| 47 | const std::string &rHostname, |
|---|
| 48 | int32_t Port, |
|---|
| 49 | uint32_t AccountNumber, |
|---|
| 50 | bool ExtendedLogging, |
|---|
| 51 | bool ExtendedLogToFile, |
|---|
| 52 | std::string ExtendedLogFile, |
|---|
| 53 | ProgressNotifier &rProgressNotifier, |
|---|
| 54 | bool TcpNiceMode |
|---|
| 55 | ); |
|---|
| 56 | virtual ~BackupClientContext(); |
|---|
| 57 | private: |
|---|
| 58 | BackupClientContext(const BackupClientContext &); |
|---|
| 59 | public: |
|---|
| 60 | |
|---|
| 61 | BackupProtocolClient &GetConnection(); |
|---|
| 62 | |
|---|
| 63 | void CloseAnyOpenConnection(); |
|---|
| 64 | |
|---|
| 65 | int GetTimeout() const; |
|---|
| 66 | |
|---|
| 67 | BackupClientDeleteList &GetDeleteList(); |
|---|
| 68 | void PerformDeletions(); |
|---|
| 69 | |
|---|
| 70 | enum |
|---|
| 71 | { |
|---|
| 72 | ClientStoreMarker_NotKnown = 0 |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | void SetClientStoreMarker(int64_t ClientStoreMarker) {mClientStoreMarker = ClientStoreMarker;} |
|---|
| 76 | int64_t GetClientStoreMarker() const {return mClientStoreMarker;} |
|---|
| 77 | |
|---|
| 78 | bool StorageLimitExceeded() {return mStorageLimitExceeded;} |
|---|
| 79 | void SetStorageLimitExceeded() {mStorageLimitExceeded = true;} |
|---|
| 80 | |
|---|
| 81 | // -------------------------------------------------------------------------- |
|---|
| 82 | // |
|---|
| 83 | // Function |
|---|
| 84 | // Name: BackupClientContext::SetIDMaps(const BackupClientInodeToIDMap *, BackupClientInodeToIDMap *) |
|---|
| 85 | // Purpose: Store pointers to the Current and New ID maps |
|---|
| 86 | // Created: 11/11/03 |
|---|
| 87 | // |
|---|
| 88 | // -------------------------------------------------------------------------- |
|---|
| 89 | void SetIDMaps(const BackupClientInodeToIDMap *pCurrent, BackupClientInodeToIDMap *pNew) |
|---|
| 90 | { |
|---|
| 91 | ASSERT(pCurrent != 0); |
|---|
| 92 | ASSERT(pNew != 0); |
|---|
| 93 | mpCurrentIDMap = pCurrent; |
|---|
| 94 | mpNewIDMap = pNew; |
|---|
| 95 | } |
|---|
| 96 | const BackupClientInodeToIDMap &GetCurrentIDMap() const; |
|---|
| 97 | BackupClientInodeToIDMap &GetNewIDMap() const; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | // -------------------------------------------------------------------------- |
|---|
| 101 | // |
|---|
| 102 | // Function |
|---|
| 103 | // Name: BackupClientContext::SetExcludeLists(ExcludeList *, ExcludeList *) |
|---|
| 104 | // Purpose: Sets the exclude lists for the operation. Can be 0. |
|---|
| 105 | // Created: 28/1/04 |
|---|
| 106 | // |
|---|
| 107 | // -------------------------------------------------------------------------- |
|---|
| 108 | void SetExcludeLists(ExcludeList *pExcludeFiles, ExcludeList *pExcludeDirs) |
|---|
| 109 | { |
|---|
| 110 | mpExcludeFiles = pExcludeFiles; |
|---|
| 111 | mpExcludeDirs = pExcludeDirs; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | // -------------------------------------------------------------------------- |
|---|
| 115 | // |
|---|
| 116 | // Function |
|---|
| 117 | // Name: BackupClientContext::ExcludeFile(const std::string &) |
|---|
| 118 | // Purpose: Returns true is this file should be excluded from the backup |
|---|
| 119 | // Created: 28/1/04 |
|---|
| 120 | // |
|---|
| 121 | // -------------------------------------------------------------------------- |
|---|
| 122 | inline bool ExcludeFile(const std::string &rFullFilename) |
|---|
| 123 | { |
|---|
| 124 | if(mpExcludeFiles != 0) |
|---|
| 125 | { |
|---|
| 126 | return mpExcludeFiles->IsExcluded(rFullFilename); |
|---|
| 127 | } |
|---|
| 128 | // If no list, don't exclude anything |
|---|
| 129 | return false; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | // -------------------------------------------------------------------------- |
|---|
| 133 | // |
|---|
| 134 | // Function |
|---|
| 135 | // Name: BackupClientContext::ExcludeDir(const std::string &) |
|---|
| 136 | // Purpose: Returns true is this directory should be excluded from the backup |
|---|
| 137 | // Created: 28/1/04 |
|---|
| 138 | // |
|---|
| 139 | // -------------------------------------------------------------------------- |
|---|
| 140 | inline bool ExcludeDir(const std::string &rFullDirName) |
|---|
| 141 | { |
|---|
| 142 | if(mpExcludeDirs != 0) |
|---|
| 143 | { |
|---|
| 144 | return mpExcludeDirs->IsExcluded(rFullDirName); |
|---|
| 145 | } |
|---|
| 146 | // If no list, don't exclude anything |
|---|
| 147 | return false; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // Utility functions -- may do a lot of work |
|---|
| 151 | bool FindFilename(int64_t ObjectID, int64_t ContainingDirectory, std::string &rPathOut, bool &rIsDirectoryOut, |
|---|
| 152 | bool &rIsCurrentVersionOut, box_time_t *pModTimeOnServer = 0, box_time_t *pAttributesHashOnServer = 0, |
|---|
| 153 | BackupStoreFilenameClear *pLeafname = 0); // not const as may connect to server |
|---|
| 154 | |
|---|
| 155 | // -------------------------------------------------------------------------- |
|---|
| 156 | // |
|---|
| 157 | // Function |
|---|
| 158 | // Name: BackupClientContext::SetMaximumDiffingTime() |
|---|
| 159 | // Purpose: Sets the maximum time that will be spent diffing a file |
|---|
| 160 | // Created: 04/19/2005 |
|---|
| 161 | // |
|---|
| 162 | // -------------------------------------------------------------------------- |
|---|
| 163 | void SetMaximumDiffingTime(int iSeconds); |
|---|
| 164 | |
|---|
| 165 | // -------------------------------------------------------------------------- |
|---|
| 166 | // |
|---|
| 167 | // Function |
|---|
| 168 | // Name: BackupClientContext::SetKeepAliveTime() |
|---|
| 169 | // Purpose: Sets the time interval for repetitive keep-alive operation |
|---|
| 170 | // Created: 04/19/2005 |
|---|
| 171 | // |
|---|
| 172 | // -------------------------------------------------------------------------- |
|---|
| 173 | void SetKeepAliveTime(int iSeconds); |
|---|
| 174 | |
|---|
| 175 | // -------------------------------------------------------------------------- |
|---|
| 176 | // |
|---|
| 177 | // Function |
|---|
| 178 | // Name: BackupClientContext::ManageDiffProcess() |
|---|
| 179 | // Purpose: Initiates an SSL connection/session keep-alive process |
|---|
| 180 | // Created: 04/19/2005 |
|---|
| 181 | // |
|---|
| 182 | // -------------------------------------------------------------------------- |
|---|
| 183 | void ManageDiffProcess(); |
|---|
| 184 | |
|---|
| 185 | // -------------------------------------------------------------------------- |
|---|
| 186 | // |
|---|
| 187 | // Function |
|---|
| 188 | // Name: BackupClientContext::UnManageDiffProcess() |
|---|
| 189 | // Purpose: Suspends an SSL connection/session keep-alive process |
|---|
| 190 | // Created: 04/19/2005 |
|---|
| 191 | // |
|---|
| 192 | // -------------------------------------------------------------------------- |
|---|
| 193 | void UnManageDiffProcess(); |
|---|
| 194 | |
|---|
| 195 | // ------------------------------------------------------------------- |
|---|
| 196 | // |
|---|
| 197 | // Function |
|---|
| 198 | // Name: BackupClientContext::DoKeepAlive() |
|---|
| 199 | // Purpose: Check whether it's time to send a KeepAlive |
|---|
| 200 | // message over the SSL link, and if so, send it. |
|---|
| 201 | // Created: 04/19/2005 |
|---|
| 202 | // |
|---|
| 203 | // ------------------------------------------------------------------- |
|---|
| 204 | virtual void DoKeepAlive(); |
|---|
| 205 | virtual int GetMaximumDiffingTime(); |
|---|
| 206 | virtual bool IsManaged() { return mbIsManaged; } |
|---|
| 207 | |
|---|
| 208 | ProgressNotifier& GetProgressNotifier() const |
|---|
| 209 | { |
|---|
| 210 | return mrProgressNotifier; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | void SetNiceMode(bool enabled) |
|---|
| 214 | { |
|---|
| 215 | if(mTcpNiceMode) |
|---|
| 216 | { |
|---|
| 217 | mapNice->SetEnabled(enabled); |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | private: |
|---|
| 222 | LocationResolver &mrResolver; |
|---|
| 223 | TLSContext &mrTLSContext; |
|---|
| 224 | std::string mHostname; |
|---|
| 225 | int mPort; |
|---|
| 226 | uint32_t mAccountNumber; |
|---|
| 227 | std::auto_ptr<SocketStream> mapSocket; |
|---|
| 228 | std::auto_ptr<NiceSocketStream> mapNice; |
|---|
| 229 | std::auto_ptr<BackupProtocolClient> mapConnection; |
|---|
| 230 | bool mExtendedLogging; |
|---|
| 231 | bool mExtendedLogToFile; |
|---|
| 232 | std::string mExtendedLogFile; |
|---|
| 233 | FILE* mpExtendedLogFileHandle; |
|---|
| 234 | int64_t mClientStoreMarker; |
|---|
| 235 | BackupClientDeleteList *mpDeleteList; |
|---|
| 236 | const BackupClientInodeToIDMap *mpCurrentIDMap; |
|---|
| 237 | BackupClientInodeToIDMap *mpNewIDMap; |
|---|
| 238 | bool mStorageLimitExceeded; |
|---|
| 239 | ExcludeList *mpExcludeFiles; |
|---|
| 240 | ExcludeList *mpExcludeDirs; |
|---|
| 241 | Timer mKeepAliveTimer; |
|---|
| 242 | bool mbIsManaged; |
|---|
| 243 | int mKeepAliveTime; |
|---|
| 244 | int mMaximumDiffingTime; |
|---|
| 245 | ProgressNotifier &mrProgressNotifier; |
|---|
| 246 | bool mTcpNiceMode; |
|---|
| 247 | }; |
|---|
| 248 | |
|---|
| 249 | #endif // BACKUPCLIENTCONTEXT__H |
|---|