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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #if defined(XP_WIN)
     6 #include <windows.h>
     7 #endif
    10 #include <stdio.h>
    11 #include <string.h>
    12 #include <stdlib.h>
    13 #include <stdarg.h>
    15 #include "updatelogging.h"
    17 UpdateLog::UpdateLog() : logFP(nullptr)
    18 {
    19 }
    21 void UpdateLog::Init(NS_tchar* sourcePath,
    22                      const NS_tchar* fileName,
    23                      const NS_tchar* alternateFileName,
    24                      bool append)
    25 {
    26   if (logFP)
    27     return;
    29   this->sourcePath = sourcePath;
    30   NS_tchar logFile[MAXPATHLEN];
    31   NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
    32     NS_T("%s/%s"), sourcePath, fileName);
    34   if (alternateFileName && NS_taccess(logFile, F_OK)) {
    35     NS_tsnprintf(logFile, sizeof(logFile)/sizeof(logFile[0]),
    36       NS_T("%s/%s"), sourcePath, alternateFileName);
    37   }
    39   logFP = NS_tfopen(logFile, append ? NS_T("a") : NS_T("w"));
    40 }
    42 void UpdateLog::Finish()
    43 {
    44   if (!logFP)
    45     return;
    47   fclose(logFP);
    48   logFP = nullptr;
    49 }
    51 void UpdateLog::Flush()
    52 {
    53   if (!logFP)
    54     return;
    56   fflush(logFP);
    57 }
    59 void UpdateLog::Printf(const char *fmt, ... )
    60 {
    61   if (!logFP)
    62     return;
    64   va_list ap;
    65   va_start(ap, fmt);
    66   vfprintf(logFP, fmt, ap);
    67   fprintf(logFP, "\n");
    68   va_end(ap);
    69 }
    71 void UpdateLog::WarnPrintf(const char *fmt, ... )
    72 {
    73   if (!logFP)
    74     return;
    76   va_list ap;
    77   va_start(ap, fmt);
    78   fprintf(logFP, "*** Warning: ");
    79   vfprintf(logFP, fmt, ap);
    80   fprintf(logFP, "***\n");
    81   va_end(ap);
    82 }

mercurial