toolkit/components/maintenanceservice/servicebase.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "servicebase.h"
michael@0 6 #include "nsWindowsHelpers.h"
michael@0 7
michael@0 8 // Shared code between applications and updater.exe
michael@0 9 #include "nsWindowsRestart.cpp"
michael@0 10
michael@0 11 /**
michael@0 12 * Verifies if 2 files are byte for byte equivalent.
michael@0 13 *
michael@0 14 * @param file1Path The first file to verify.
michael@0 15 * @param file2Path The second file to verify.
michael@0 16 * @param sameContent Out parameter, TRUE if the files are equal
michael@0 17 * @return TRUE If there was no error checking the files.
michael@0 18 */
michael@0 19 BOOL
michael@0 20 VerifySameFiles(LPCWSTR file1Path, LPCWSTR file2Path, BOOL &sameContent)
michael@0 21 {
michael@0 22 sameContent = FALSE;
michael@0 23 nsAutoHandle file1(CreateFileW(file1Path, GENERIC_READ, FILE_SHARE_READ,
michael@0 24 nullptr, OPEN_EXISTING, 0, nullptr));
michael@0 25 if (INVALID_HANDLE_VALUE == file1) {
michael@0 26 return FALSE;
michael@0 27 }
michael@0 28 nsAutoHandle file2(CreateFileW(file2Path, GENERIC_READ, FILE_SHARE_READ,
michael@0 29 nullptr, OPEN_EXISTING, 0, nullptr));
michael@0 30 if (INVALID_HANDLE_VALUE == file2) {
michael@0 31 return FALSE;
michael@0 32 }
michael@0 33
michael@0 34 DWORD fileSize1 = GetFileSize(file1, nullptr);
michael@0 35 DWORD fileSize2 = GetFileSize(file2, nullptr);
michael@0 36 if (INVALID_FILE_SIZE == fileSize1 || INVALID_FILE_SIZE == fileSize2) {
michael@0 37 return FALSE;
michael@0 38 }
michael@0 39
michael@0 40 if (fileSize1 != fileSize2) {
michael@0 41 // sameContent is already set to FALSE
michael@0 42 return TRUE;
michael@0 43 }
michael@0 44
michael@0 45 char buf1[COMPARE_BLOCKSIZE];
michael@0 46 char buf2[COMPARE_BLOCKSIZE];
michael@0 47 DWORD numBlocks = fileSize1 / COMPARE_BLOCKSIZE;
michael@0 48 DWORD leftOver = fileSize1 % COMPARE_BLOCKSIZE;
michael@0 49 DWORD readAmount;
michael@0 50 for (DWORD i = 0; i < numBlocks; i++) {
michael@0 51 if (!ReadFile(file1, buf1, COMPARE_BLOCKSIZE, &readAmount, nullptr) ||
michael@0 52 readAmount != COMPARE_BLOCKSIZE) {
michael@0 53 return FALSE;
michael@0 54 }
michael@0 55
michael@0 56 if (!ReadFile(file2, buf2, COMPARE_BLOCKSIZE, &readAmount, nullptr) ||
michael@0 57 readAmount != COMPARE_BLOCKSIZE) {
michael@0 58 return FALSE;
michael@0 59 }
michael@0 60
michael@0 61 if (memcmp(buf1, buf2, COMPARE_BLOCKSIZE)) {
michael@0 62 // sameContent is already set to FALSE
michael@0 63 return TRUE;
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 if (leftOver) {
michael@0 68 if (!ReadFile(file1, buf1, leftOver, &readAmount, nullptr) ||
michael@0 69 readAmount != leftOver) {
michael@0 70 return FALSE;
michael@0 71 }
michael@0 72
michael@0 73 if (!ReadFile(file2, buf2, leftOver, &readAmount, nullptr) ||
michael@0 74 readAmount != leftOver) {
michael@0 75 return FALSE;
michael@0 76 }
michael@0 77
michael@0 78 if (memcmp(buf1, buf2, leftOver)) {
michael@0 79 // sameContent is already set to FALSE
michael@0 80 return TRUE;
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 sameContent = TRUE;
michael@0 85 return TRUE;
michael@0 86 }

mercurial