widget/gtk/nsCUPSShim.cpp

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsDebug.h"
michael@0 8 #include "nsString.h"
michael@0 9 #include "nsCUPSShim.h"
michael@0 10 #include "mozilla/ArrayUtils.h"
michael@0 11 #include "prlink.h"
michael@0 12
michael@0 13
michael@0 14 // List of symbols to find in libcups. Must match symAddr[] defined in Init().
michael@0 15 // Making this an array of arrays instead of pointers allows storing the
michael@0 16 // whole thing in read-only memory.
michael@0 17 static const char gSymName[][sizeof("cupsPrintFile")] = {
michael@0 18 { "cupsAddOption" },
michael@0 19 { "cupsFreeDests" },
michael@0 20 { "cupsGetDest" },
michael@0 21 { "cupsGetDests" },
michael@0 22 { "cupsPrintFile" },
michael@0 23 { "cupsTempFd" },
michael@0 24 };
michael@0 25 static const int gSymNameCt = mozilla::ArrayLength(gSymName);
michael@0 26
michael@0 27
michael@0 28 bool
michael@0 29 nsCUPSShim::Init()
michael@0 30 {
michael@0 31 mCupsLib = PR_LoadLibrary("libcups.so.2");
michael@0 32 if (!mCupsLib)
michael@0 33 return false;
michael@0 34
michael@0 35 // List of symbol pointers. Must match gSymName[] defined above.
michael@0 36 void **symAddr[] = {
michael@0 37 (void **)&mCupsAddOption,
michael@0 38 (void **)&mCupsFreeDests,
michael@0 39 (void **)&mCupsGetDest,
michael@0 40 (void **)&mCupsGetDests,
michael@0 41 (void **)&mCupsPrintFile,
michael@0 42 (void **)&mCupsTempFd,
michael@0 43 };
michael@0 44
michael@0 45 for (int i = gSymNameCt; i--; ) {
michael@0 46 *(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
michael@0 47 if (! *(symAddr[i])) {
michael@0 48 #ifdef DEBUG
michael@0 49 nsAutoCString msg(gSymName[i]);
michael@0 50 msg.Append(" not found in CUPS library");
michael@0 51 NS_WARNING(msg.get());
michael@0 52 #endif
michael@0 53 PR_UnloadLibrary(mCupsLib);
michael@0 54 mCupsLib = nullptr;
michael@0 55 return false;
michael@0 56 }
michael@0 57 }
michael@0 58 return true;
michael@0 59 }

mercurial