2004-09-07 21:55:27 +04: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 15:12:37 +04: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 21:55:27 +04:00
|
|
|
|
|
|
|
#include "nsDebug.h"
|
2005-05-08 19:01:20 +04:00
|
|
|
#include "nsString.h"
|
2004-09-07 21:55:27 +04:00
|
|
|
#include "nsCUPSShim.h"
|
|
|
|
#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 19:01:20 +04:00
|
|
|
{ "cupsAddOption" },
|
|
|
|
{ "cupsFreeDests" },
|
2005-03-20 19:28:58 +03:00
|
|
|
{ "cupsGetDest" },
|
2004-09-07 21:55:27 +04:00
|
|
|
{ "cupsGetDests" },
|
|
|
|
{ "cupsPrintFile" },
|
|
|
|
{ "cupsTempFd" },
|
|
|
|
};
|
2011-05-22 00:04:44 +04:00
|
|
|
static const int gSymNameCt = NS_ARRAY_LENGTH(gSymName);
|
2004-09-07 21:55:27 +04:00
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-09-07 21:55:27 +04:00
|
|
|
nsCUPSShim::Init()
|
|
|
|
{
|
|
|
|
mCupsLib = PR_LoadLibrary("libcups.so.2");
|
|
|
|
if (!mCupsLib)
|
2011-10-03 11:56:21 +04:00
|
|
|
return false;
|
2004-09-07 21:55:27 +04:00
|
|
|
|
|
|
|
// List of symbol pointers. Must match gSymName[] defined above.
|
|
|
|
void **symAddr[] = {
|
2005-05-08 19:01:20 +04:00
|
|
|
(void **)&mCupsAddOption,
|
|
|
|
(void **)&mCupsFreeDests,
|
2005-03-20 19:28:58 +03:00
|
|
|
(void **)&mCupsGetDest,
|
2004-09-07 21:55:27 +04:00
|
|
|
(void **)&mCupsGetDests,
|
|
|
|
(void **)&mCupsPrintFile,
|
|
|
|
(void **)&mCupsTempFd,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = gSymNameCt; i--; ) {
|
|
|
|
*(symAddr[i]) = PR_FindSymbol(mCupsLib, gSymName[i]);
|
|
|
|
if (! *(symAddr[i])) {
|
2005-05-08 19:01:20 +04:00
|
|
|
#ifdef DEBUG
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString msg(gSymName[i]);
|
2005-05-08 19:01:20 +04:00
|
|
|
msg.Append(" not found in CUPS library");
|
|
|
|
NS_WARNING(msg.get());
|
|
|
|
#endif
|
2004-09-07 21:55:27 +04:00
|
|
|
PR_UnloadLibrary(mCupsLib);
|
2012-07-30 18:20:58 +04:00
|
|
|
mCupsLib = nullptr;
|
2011-10-03 11:56:21 +04:00
|
|
|
return false;
|
2004-09-07 21:55:27 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-03 11:56:21 +04:00
|
|
|
return true;
|
2004-09-07 21:55:27 +04:00
|
|
|
}
|