Changeset 2481
- Timestamp:
- 29/03/2009 13:51:24 (18 months ago)
- Location:
- box/trunk
- Files:
-
- 8 modified
-
bin/bbackupd/BackupClientDirectoryRecord.cpp (modified) (1 diff)
-
bin/bbstored/HousekeepStoreAccount.cpp (modified) (3 diffs)
-
lib/backupclient/BackupStoreFilename.cpp (modified) (12 diffs)
-
lib/backupclient/BackupStoreFilename.h (modified) (2 diffs)
-
lib/backupclient/BackupStoreFilenameClear.cpp (modified) (5 diffs)
-
lib/backupclient/BackupStoreObjectDump.cpp (modified) (5 diffs)
-
lib/backupstore/BackupStoreCheck2.cpp (modified) (3 diffs)
-
test/backupstore/testbackupstore.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
r2460 r2481 1387 1387 BackupClientDeleteList &rdel(rContext.GetDeleteList()); 1388 1388 1389 BackupStoreFilenameClear clear(en->GetName()); 1389 1390 std::string localName = MakeFullPath(rLocalPath, 1390 en->GetName());1391 clear.GetClearFilename()); 1391 1392 1392 1393 // Delete this entry -- file or directory? -
box/trunk/bin/bbstored/HousekeepStoreAccount.cpp
r2176 r2481 350 350 351 351 // map to count the distance from the mark 352 std::map<std::pair<BackupStoreFilename, int32_t>, int32_t> markVersionAges; 352 typedef std::pair<std::string, int32_t> version_t; 353 std::map<version_t, int32_t> markVersionAges; 353 354 // map of pair (filename, mark number) -> version age 354 355 … … 368 369 // Work out ages of this version from the last mark 369 370 int32_t enVersionAge = 0; 370 std::map<std::pair<BackupStoreFilename, int32_t>, int32_t>::iterator enVersionAgeI(markVersionAges.find(std::pair<BackupStoreFilename, int32_t>(en->GetName(), en->GetMarkNumber()))); 371 std::map<version_t, int32_t>::iterator enVersionAgeI( 372 markVersionAges.find( 373 version_t(en->GetName().GetEncodedFilename(), 374 en->GetMarkNumber()))); 371 375 if(enVersionAgeI != markVersionAges.end()) 372 376 { … … 376 380 else 377 381 { 378 markVersionAges[ std::pair<BackupStoreFilename, int32_t>(en->GetName(), en->GetMarkNumber())] = enVersionAge;382 markVersionAges[version_t(en->GetName().GetEncodedFilename(), en->GetMarkNumber())] = enVersionAge; 379 383 } 380 384 // enVersionAge is now the age of this version. -
box/trunk/lib/backupclient/BackupStoreFilename.cpp
r217 r2481 38 38 // -------------------------------------------------------------------------- 39 39 BackupStoreFilename::BackupStoreFilename(const BackupStoreFilename &rToCopy) 40 : BackupStoreFilename_base(rToCopy)40 : mEncryptedName(rToCopy.mEncryptedName) 41 41 { 42 42 } … … 66 66 bool ok = true; 67 67 68 if( size() < 2)68 if(mEncryptedName.size() < 2) 69 69 { 70 70 // Isn't long enough to have a header … … 74 74 { 75 75 // Check size is consistent 76 unsigned int dsize = BACKUPSTOREFILENAME_GET_SIZE( *this);77 if(dsize != size())76 unsigned int dsize = BACKUPSTOREFILENAME_GET_SIZE(this->mEncryptedName); 77 if(dsize != mEncryptedName.size()) 78 78 { 79 79 ok = false; … … 81 81 82 82 // And encoding is an accepted value 83 unsigned int encoding = BACKUPSTOREFILENAME_GET_ENCODING( *this);83 unsigned int encoding = BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName); 84 84 if(encoding < Encoding_Min || encoding > Encoding_Max) 85 85 { … … 120 120 121 121 // assign to this string, storing the header and the extra data 122 assign(hdr, 2);123 append(data.c_str(), data.size());122 mEncryptedName.assign(hdr, 2); 123 mEncryptedName.append(data.c_str(), data.size()); 124 124 125 125 // Check it … … 142 142 CheckValid(); 143 143 144 rProtocol.Write( c_str(),size());144 rProtocol.Write(mEncryptedName.c_str(), mEncryptedName.size()); 145 145 } 146 146 … … 178 178 179 179 // assign to this string, storing the header and the extra data 180 assign(buf, dsize);180 mEncryptedName.assign(buf, dsize); 181 181 } 182 182 else … … 195 195 196 196 // assign to this string, storing the header and the extra data 197 assign(data, dsize);197 mEncryptedName.assign(data, dsize); 198 198 } 199 199 … … 217 217 CheckValid(); 218 218 219 rStream.Write( c_str(),size());219 rStream.Write(mEncryptedName.c_str(), mEncryptedName.size()); 220 220 } 221 221 … … 243 243 bool BackupStoreFilename::IsEncrypted() const 244 244 { 245 return BACKUPSTOREFILENAME_GET_ENCODING(*this) != Encoding_Clear; 245 return BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName) != 246 Encoding_Clear; 246 247 } 247 248 … … 251 252 // Function 252 253 // Name: BackupStoreFilename::SetAsClearFilename(const char *) 253 // Purpose: Sets this object to be a valid filename, but with a filename in the clear. 254 // Used on the server to create filenames when there's no way of encrypting it. 254 // Purpose: Sets this object to be a valid filename, but with a 255 // filename in the clear. Used on the server to create 256 // filenames when there's no way of encrypting it. 255 257 // Created: 22/4/04 256 258 // … … 269 271 270 272 // Store the encoded string 271 assign(encoded);273 mEncryptedName.assign(encoded); 272 274 273 275 // Stuff which must be done -
box/trunk/lib/backupclient/BackupStoreFilename.h
r217 r2481 41 41 // 42 42 // -------------------------------------------------------------------------- 43 class BackupStoreFilename : public BackupStoreFilename_base43 class BackupStoreFilename /* : public BackupStoreFilename_base */ 44 44 { 45 private: 46 std::string mEncryptedName; 47 45 48 public: 46 49 BackupStoreFilename(); … … 72 75 }; 73 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 74 92 protected: 75 93 virtual void EncodedFilenameChanged(); 94 void SetEncodedFilename(const std::string &rEncoded) 95 { 96 mEncryptedName = rEncoded; 97 } 76 98 }; 77 99 -
box/trunk/lib/backupclient/BackupStoreFilenameClear.cpp
r2127 r2481 161 161 162 162 // Decode the header 163 int size = BACKUPSTOREFILENAME_GET_SIZE( *this);164 int encoding = BACKUPSTOREFILENAME_GET_ENCODING( *this);163 int size = BACKUPSTOREFILENAME_GET_SIZE(GetEncodedFilename()); 164 int encoding = BACKUPSTOREFILENAME_GET_ENCODING(GetEncodedFilename()); 165 165 166 166 // Decode based on encoding given in the header … … 170 170 BOX_TRACE("**** BackupStoreFilename encoded with " 171 171 "Clear encoding ****"); 172 mClearFilename.assign(c_str() + 2, size - 2); 172 mClearFilename.assign(GetEncodedFilename().c_str() + 2, 173 size - 2); 173 174 break; 174 175 … … 245 246 246 247 // Store the encoded string 247 assign((char*)buffer, encSize);248 SetEncodedFilename(std::string((char*)buffer, encSize)); 248 249 } 249 250 … … 259 260 void BackupStoreFilenameClear::DecryptEncoded(CipherContext &rCipherContext) const 260 261 { 262 const std::string& rEncoded = GetEncodedFilename(); 263 261 264 // Work out max size 262 int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize( size()) + 4;265 int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rEncoded.size()) + 4; 263 266 264 267 // Make sure encode/decode buffer has enough space … … 269 272 270 273 // Decrypt 271 const char *str = c_str() + 2;272 int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, size() - 2);274 const char *str = rEncoded.c_str() + 2; 275 int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, rEncoded.size() - 2); 273 276 274 277 // Assign to this -
box/trunk/lib/backupclient/BackupStoreObjectDump.cpp
r2127 r2481 71 71 72 72 // So repeated filenames can be illustrated, even though they can't be decoded 73 std::map< BackupStoreFilename, int> nameNum;73 std::map<std::string, int> nameNum; 74 74 int nameNumI = 0; 75 75 … … 79 79 { 80 80 // Choose file name index number for this file 81 std::map< BackupStoreFilename, int>::iterator nn(nameNum.find((*i)->GetName()));81 std::map<std::string, int>::iterator nn(nameNum.find((*i)->GetName().GetEncodedFilename())); 82 82 int ni = nameNumI; 83 83 if(nn != nameNum.end()) … … 87 87 else 88 88 { 89 nameNum[(*i)->GetName() ] = nameNumI;89 nameNum[(*i)->GetName().GetEncodedFilename()] = nameNumI; 90 90 ++nameNumI; 91 91 } … … 125 125 (*i)->GetAttributesHash(), 126 126 (*i)->GetAttributes().GetSize(), 127 (*i)->GetName(). size(),127 (*i)->GetName().GetEncodedFilename().size(), 128 128 ni, 129 129 ((f & BackupStoreDirectory::Entry::Flags_File)?" file":""), … … 174 174 BackupStoreFilename fn; 175 175 fn.ReadFromStream(rFile, IOStream::TimeOutInfinite); 176 OutputLine(file, ToTrace, "Filename size: %d\n", fn.size()); 176 OutputLine(file, ToTrace, "Filename size: %d\n", 177 fn.GetEncodedFilename().size()); 177 178 178 179 BackupClientFileAttributes attr; -
box/trunk/lib/backupstore/BackupStoreCheck2.cpp
r2160 r2481 751 751 // Records of things seen 752 752 std::set<int64_t> idsEncountered; 753 std::set< BackupStoreFilename> filenamesEncountered;753 std::set<std::string> filenamesEncountered; 754 754 755 755 do … … 793 793 // Check to see if the name has already been encountered -- if not, then it 794 794 // needs to have the old version flag set 795 if(filenamesEncountered.find((*i)->GetName() ) != filenamesEncountered.end())795 if(filenamesEncountered.find((*i)->GetName().GetEncodedFilename()) != filenamesEncountered.end()) 796 796 { 797 797 // Seen before -- check old version flag set … … 819 819 820 820 // Remember filename 821 filenamesEncountered.insert((*i)->GetName() );821 filenamesEncountered.insert((*i)->GetName().GetEncodedFilename()); 822 822 } 823 823 } -
box/trunk/test/backupstore/testbackupstore.cpp
r2355 r2481 233 233 234 234 // Check that it's been encrypted 235 TEST_THAT(fn2.find("name") == fn2.npos); 235 std::string name(fn2.GetEncodedFilename()); 236 TEST_THAT(name.find("name") == name.npos); 236 237 237 238 // Bung it in a stream, get it out in a Clear filename
