2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-09-07 17:55:27 +00:00
|
|
|
/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-09-07 17:55:27 +00:00
|
|
|
|
|
|
|
#include "nsDebug.h"
|
2005-05-08 15:01:20 +00:00
|
|
|
#include "nsString.h"
|
2004-09-07 17:55:27 +00:00
|
|
|
#include "nsCUPSShim.h"
|
2014-01-30 18:26:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2004-09-07 17:55:27 +00:00
|
|
|
#include "prlink.h"
|
|
|
|
|
|
|
|
// List of symbols to find in libcups. Must match symAddr[] defined in Init().
|
|
|
|
// Making this an array of arrays instead of pointers allows storing the
|
|
|
|
// whole thing in read-only memory.
|
|
|
|
static const char gSymName[][sizeof("cupsPrintFile")] = {
|
2005-05-08 15:01:20 +00:00
|
|
|
{"cupsAddOption"}, {"cupsFreeDests"}, {"cupsGetDest"},
|
2004-09-07 17:55:27 +00:00
|
|
|
{"cupsGetDests"}, {"cupsPrintFile"}, {"cupsTempFd"},
|
|
|
|
};
|
2014-01-30 18:26:54 +00:00
|
|
|
static const int gSymNameCt = mozilla::ArrayLength(gSymName);
|
2004-09-07 17:55:27 +00:00
|
|
|
|
|
|
|
bool nsCUPSShim::Init() {
|
|
|
|
mCupsLib = PR_LoadLibrary("libcups.so.2");
|
|
|
|
if (!mCupsLib) return false;
|
|
|
|
|
|
|
|
// List of symbol pointers. Must match gSymName[] defined above.
|
2019-05-01 08:47:10 +00:00
|
|
|
void** symAddr[] = {
|
|
|
|
(void**)&mCupsAddOption, (void**)&mCupsFreeDests, (void**)&mCupsGetDest,
|
|
|
|
(void**)&mCupsGetDests, (void**)&mCupsPrintFile, (void**)&mCupsTempFd,
|
2004-09-07 17:55:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = gSymNameCt; i--;) {
|
|
|
|
*(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
|
|
|
|
if (!*(symAddr[i])) {
|
2005-05-08 15:01:20 +00:00
|
|
|
#ifdef DEBUG
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString msg(gSymName[i]);
|
2014-05-22 03:48:51 +00:00
|
|
|
msg.AppendLiteral(" not found in CUPS library");
|
2005-05-08 15:01:20 +00:00
|
|
|
NS_WARNING(msg.get());
|
|
|
|
#endif
|
2004-09-07 17:55:27 +00:00
|
|
|
PR_UnloadLibrary(mCupsLib);
|
2012-07-30 14:20:58 +00:00
|
|
|
mCupsLib = nullptr;
|
2011-10-03 07:56:21 +00:00
|
|
|
return false;
|
2004-09-07 17:55:27 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2011-10-03 07:56:21 +00:00
|
|
|
return true;
|
2004-09-07 17:55:27 +00:00
|
|
|
}
|