js/xpconnect/src/XPCLog.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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /* Debug Logging support. */
     9 #include "XPCLog.h"
    10 #include "prlog.h"
    11 #include "prprf.h"
    12 #include "mozilla/mozalloc.h"
    13 #include "mozilla/NullPtr.h"
    14 #include <string.h>
    15 #include <stdarg.h>
    17 // this all only works for DEBUG...
    18 #ifdef DEBUG
    20 #define SPACE_COUNT     200
    21 #define LINE_LEN        200
    22 #define INDENT_FACTOR   2
    24 #define CAN_RUN (g_InitState == 1 || (g_InitState == 0 && Init()))
    26 static char*    g_Spaces;
    27 static int      g_InitState = 0;
    28 static int      g_Indent = 0;
    29 static PRLogModuleInfo* g_LogMod = nullptr;
    31 static bool Init()
    32 {
    33     g_LogMod = PR_NewLogModule("xpclog");
    34     g_Spaces = new char[SPACE_COUNT+1];
    35     if (!g_LogMod || !g_Spaces || !PR_LOG_TEST(g_LogMod,1)) {
    36         g_InitState = 1;
    37         XPC_Log_Finish();
    38         return false;
    39     }
    40     memset(g_Spaces, ' ', SPACE_COUNT);
    41     g_Spaces[SPACE_COUNT] = 0;
    42     g_InitState = 1;
    43     return true;
    44 }
    46 void
    47 XPC_Log_Finish()
    48 {
    49     if (g_InitState == 1) {
    50         delete [] g_Spaces;
    51         // we'd like to properly cleanup the LogModule, but nspr owns that
    52         g_LogMod = nullptr;
    53     }
    54     g_InitState = -1;
    55 }
    57 void
    58 XPC_Log_print(const char *fmt, ...)
    59 {
    60     va_list ap;
    61     char line[LINE_LEN];
    63     va_start(ap, fmt);
    64     PR_vsnprintf(line, sizeof(line)-1, fmt, ap);
    65     va_end(ap);
    66     if (g_Indent)
    67         PR_LogPrint("%s%s",g_Spaces+SPACE_COUNT-(INDENT_FACTOR*g_Indent),line);
    68     else
    69         PR_LogPrint("%s",line);
    70 }
    72 bool
    73 XPC_Log_Check(int i)
    74 {
    75     return CAN_RUN && PR_LOG_TEST(g_LogMod,1);
    76 }
    78 void
    79 XPC_Log_Indent()
    80 {
    81     if (INDENT_FACTOR*(++g_Indent) > SPACE_COUNT)
    82         g_Indent-- ;
    83 }
    85 void
    86 XPC_Log_Outdent()
    87 {
    88     if (--g_Indent < 0)
    89         g_Indent++;
    90 }
    92 void
    93 XPC_Log_Clear_Indent()
    94 {
    95     g_Indent = 0;
    96 }
    98 #endif

mercurial