toolkit/mozapps/update/common/updatelogging.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 #if defined(XP_WIN)
michael@0 6 #include <windows.h>
michael@0 7 #endif
michael@0 8
michael@0 9
michael@0 10 #include <stdio.h>
michael@0 11 #include <string.h>
michael@0 12 #include <stdlib.h>
michael@0 13 #include <stdarg.h>
michael@0 14
michael@0 15 #include "updatelogging.h"
michael@0 16
michael@0 17 UpdateLog::UpdateLog() : logFP(nullptr)
michael@0 18 {
michael@0 19 }
michael@0 20
michael@0 21 void UpdateLog::Init(NS_tchar* sourcePath,
michael@0 22 const NS_tchar* fileName,
michael@0 23 const NS_tchar* alternateFileName,
michael@0 24 bool append)
michael@0 25 {
michael@0 26 if (logFP)
michael@0 27 return;
michael@0 28
michael@0 29 this->sourcePath = sourcePath;
michael@0 30 NS_tchar logFile[MAXPATHLEN];
michael@0 31 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
michael@0 32 NS_T("%s/%s"), sourcePath, fileName);
michael@0 33
michael@0 34 if (alternateFileName && NS_taccess(logFile, F_OK)) {
michael@0 35 NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
michael@0 36 NS_T("%s/%s"), sourcePath, alternateFileName);
michael@0 37 }
michael@0 38
michael@0 39 logFP = NS_tfopen(logFile, append ? NS_T("a") : NS_T("w"));
michael@0 40 }
michael@0 41
michael@0 42 void UpdateLog::Finish()
michael@0 43 {
michael@0 44 if (!logFP)
michael@0 45 return;
michael@0 46
michael@0 47 fclose(logFP);
michael@0 48 logFP = nullptr;
michael@0 49 }
michael@0 50
michael@0 51 void UpdateLog::Flush()
michael@0 52 {
michael@0 53 if (!logFP)
michael@0 54 return;
michael@0 55
michael@0 56 fflush(logFP);
michael@0 57 }
michael@0 58
michael@0 59 void UpdateLog::Printf(const char *fmt, ... )
michael@0 60 {
michael@0 61 if (!logFP)
michael@0 62 return;
michael@0 63
michael@0 64 va_list ap;
michael@0 65 va_start(ap, fmt);
michael@0 66 vfprintf(logFP, fmt, ap);
michael@0 67 fprintf(logFP, "\n");
michael@0 68 va_end(ap);
michael@0 69 }
michael@0 70
michael@0 71 void UpdateLog::WarnPrintf(const char *fmt, ... )
michael@0 72 {
michael@0 73 if (!logFP)
michael@0 74 return;
michael@0 75
michael@0 76 va_list ap;
michael@0 77 va_start(ap, fmt);
michael@0 78 fprintf(logFP, "*** Warning: ");
michael@0 79 vfprintf(logFP, fmt, ap);
michael@0 80 fprintf(logFP, "***\n");
michael@0 81 va_end(ap);
michael@0 82 }

mercurial