2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCUPSShim.h"
|
2014-01-30 10:26:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2007-03-22 10:30:00 -07: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")] = {
|
|
|
|
{ "cupsAddOption" },
|
|
|
|
{ "cupsFreeDests" },
|
|
|
|
{ "cupsGetDest" },
|
|
|
|
{ "cupsGetDests" },
|
|
|
|
{ "cupsPrintFile" },
|
|
|
|
{ "cupsTempFd" },
|
|
|
|
};
|
2014-01-30 10:26:54 -08:00
|
|
|
static const int gSymNameCt = mozilla::ArrayLength(gSymName);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCUPSShim::Init()
|
|
|
|
{
|
|
|
|
mCupsLib = PR_LoadLibrary("libcups.so.2");
|
|
|
|
if (!mCupsLib)
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// List of symbol pointers. Must match gSymName[] defined above.
|
|
|
|
void **symAddr[] = {
|
|
|
|
(void **)&mCupsAddOption,
|
|
|
|
(void **)&mCupsFreeDests,
|
|
|
|
(void **)&mCupsGetDest,
|
|
|
|
(void **)&mCupsGetDests,
|
|
|
|
(void **)&mCupsPrintFile,
|
|
|
|
(void **)&mCupsTempFd,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = gSymNameCt; i--; ) {
|
|
|
|
*(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
|
|
|
|
if (! *(symAddr[i])) {
|
|
|
|
#ifdef DEBUG
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString msg(gSymName[i]);
|
2014-05-21 20:48:51 -07:00
|
|
|
msg.AppendLiteral(" not found in CUPS library");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_WARNING(msg.get());
|
|
|
|
#endif
|
|
|
|
PR_UnloadLibrary(mCupsLib);
|
2012-07-30 07:20:58 -07:00
|
|
|
mCupsLib = nullptr;
|
2011-10-03 00:56:21 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-03 00:56:21 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|