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