squid-
cache.org
Optimising Web Delivery
Docs
Download
Donate
Support
About
Contact
Shop
Blog
src
LoadableModule.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3
*
4
* Squid software is distributed under GPLv2+ license and includes
5
* contributions from numerous individuals and organizations.
6
* Please see the COPYING and CONTRIBUTORS files for details.
7
*/
8
9
#include "
squid.h
"
10
#include "
base/TextException.h
"
11
#include "libltdl/ltdl.h"
/* generated file */
12
#include "
LoadableModule.h
"
13
14
// Note: We must use preprocessor instead of C ifs because if dlopen()
15
// is seen by the static linker, the linker will complain.
16
17
LoadableModule::LoadableModule
(
const
String
&aName): theName(aName), theHandle(0)
18
{
19
// Initialise preloaded symbol lookup table.
20
LTDL_SET_PRELOADED_SYMBOLS();
21
if
(lt_dlinit() != 0)
22
throw
TexcHere
(
"internal error: cannot initialize libtool module loader"
);
23
}
24
25
LoadableModule::~LoadableModule
()
26
{
27
if
(
loaded
())
28
unload
();
29
assert
(lt_dlexit() == 0);
// XXX: replace with a warning
30
}
31
32
bool
33
LoadableModule::loaded
()
const
34
{
35
return
theHandle
!= 0;
36
}
37
38
void
39
LoadableModule::load
()
40
{
41
if
(
loaded
())
42
throw
TexcHere
(
"internal error: reusing LoadableModule object"
);
43
44
theHandle
=
openModule
();
45
46
if
(!
loaded
())
47
throw
TexcHere
(
errorMsg
());
48
}
49
50
void
51
LoadableModule::unload
()
52
{
53
if
(!
loaded
())
54
throw
TexcHere
(
"internal error: unloading not loaded module"
);
55
56
if
(!
closeModule
())
57
throw
TexcHere
(
errorMsg
());
58
59
theHandle
= 0;
60
}
61
62
void
*
63
LoadableModule::openModule
()
64
{
65
return
lt_dlopen(
theName
.
termedBuf
());
66
}
67
68
bool
69
LoadableModule::closeModule
()
70
{
71
// we cast to avoid including ltdl.h in LoadableModule.h
72
return
lt_dlclose(
static_cast<
lt_dlhandle
>
(
theHandle
)) == 0;
73
}
74
75
const
char
*
76
LoadableModule::errorMsg
()
77
{
78
return
lt_dlerror();
79
}
80
LoadableModule::load
void load()
Definition:
LoadableModule.cc:39
LoadableModule::closeModule
bool closeModule()
Definition:
LoadableModule.cc:69
LoadableModule.h
TexcHere
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition:
TextException.h:59
LoadableModule::theHandle
void * theHandle
Definition:
LoadableModule.h:31
LoadableModule::loaded
bool loaded() const
Definition:
LoadableModule.cc:33
assert
#define assert(EX)
Definition:
assert.h:19
String
Definition:
SquidString.h:26
String::termedBuf
char const * termedBuf() const
Definition:
SquidString.h:92
LoadableModule::unload
void unload()
Definition:
LoadableModule.cc:51
LoadableModule::LoadableModule
LoadableModule(const String &aName)
Definition:
LoadableModule.cc:17
LoadableModule::errorMsg
const char * errorMsg()
Definition:
LoadableModule.cc:76
LoadableModule::theName
String theName
Definition:
LoadableModule.h:29
squid.h
TextException.h
LoadableModule::~LoadableModule
~LoadableModule()
Definition:
LoadableModule.cc:25
LoadableModule::openModule
void * openModule()
Definition:
LoadableModule.cc:63
Introduction
About Squid
Why Squid?
Squid Developers
How to Donate
How to Help Out
Getting Squid
Squid Source Packages
Squid Deployment Case-Studies
Squid Software Foundation
Documentation
Configuration:
Reference
Examples
FAQ
and
Wiki
Guide Books:
Beginners
Definitive
Non-English
More...
Support
Security Advisories
Bugzilla Database
Mailing lists
Contacting us
Commercial services
Project Sponsors
Squid-based products
Miscellaneous
Developer Resources
Related Writings
Related Software:
Authenticators
Ecap
Icap
Ident
Log Analysis
Monitor
Proxies
Redirectors
General
Squid Artwork
Web Site Translations
Japanese
Mirrors
Website:
gr
il
jp
pl
...
full list
FTP Package Archive