michael@0: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsDebug.h" michael@0: #include "nsString.h" michael@0: #include "nsCUPSShim.h" michael@0: #include "mozilla/ArrayUtils.h" michael@0: #include "prlink.h" michael@0: michael@0: michael@0: // List of symbols to find in libcups. Must match symAddr[] defined in Init(). michael@0: // Making this an array of arrays instead of pointers allows storing the michael@0: // whole thing in read-only memory. michael@0: static const char gSymName[][sizeof("cupsPrintFile")] = { michael@0: { "cupsAddOption" }, michael@0: { "cupsFreeDests" }, michael@0: { "cupsGetDest" }, michael@0: { "cupsGetDests" }, michael@0: { "cupsPrintFile" }, michael@0: { "cupsTempFd" }, michael@0: }; michael@0: static const int gSymNameCt = mozilla::ArrayLength(gSymName); michael@0: michael@0: michael@0: bool michael@0: nsCUPSShim::Init() michael@0: { michael@0: mCupsLib = PR_LoadLibrary("libcups.so.2"); michael@0: if (!mCupsLib) michael@0: return false; michael@0: michael@0: // List of symbol pointers. Must match gSymName[] defined above. michael@0: void **symAddr[] = { michael@0: (void **)&mCupsAddOption, michael@0: (void **)&mCupsFreeDests, michael@0: (void **)&mCupsGetDest, michael@0: (void **)&mCupsGetDests, michael@0: (void **)&mCupsPrintFile, michael@0: (void **)&mCupsTempFd, michael@0: }; michael@0: michael@0: for (int i = gSymNameCt; i--; ) { michael@0: *(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]); michael@0: if (! *(symAddr[i])) { michael@0: #ifdef DEBUG michael@0: nsAutoCString msg(gSymName[i]); michael@0: msg.Append(" not found in CUPS library"); michael@0: NS_WARNING(msg.get()); michael@0: #endif michael@0: PR_UnloadLibrary(mCupsLib); michael@0: mCupsLib = nullptr; michael@0: return false; michael@0: } michael@0: } michael@0: return true; michael@0: }