forked from manio/vdr-plugin-dvbapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdll.cpp
More file actions
159 lines (146 loc) · 3.67 KB
/
dll.cpp
File metadata and controls
159 lines (146 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* vdr-plugin-dvbapi - softcam dvbapi plugin for VDR
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dll.h"
#include "Log.h"
// --- cScDll ------------------------------------------------------------------
cScDll::cScDll(const char *FileName)
{
fileName = strdup(FileName);
handle = 0;
}
cScDll::~cScDll()
{
if (handle)
dlclose(handle);
free(fileName);
}
bool cScDll::Load(bool check)
{
char *base = rindex(fileName, '/');
if (base)
base++;
else
base = fileName;
INFOLOG("loading library: %s", base);
if (!handle)
{
handle = dlopen(fileName, RTLD_NOW | (check ? RTLD_LOCAL : RTLD_GLOBAL));
if (handle)
return true;
else
ERRORLOG("dload: %s: %s", base, dlerror());
}
return false;
}
// --- cScDlls -----------------------------------------------------------------
cScDlls::cScDlls(void)
{
handle = 0;
}
cScDlls::~cScDlls()
{
Clear();
if (handle)
dlclose(handle);
DEBUGLOG("unload done");
}
bool cScDlls::Load(void)
{
Dl_info info;
static int marker = 0;
if (!dladdr((void *) &marker, &info))
{
ERRORLOG("dladdr: %s", dlerror());
return false;
}
// we have to re-dlopen our selfs as VDR doesn't use RTLD_GLOBAL
// but our symbols have to be available to the sub libs.
handle = dlopen(info.dli_fname, RTLD_NOW | RTLD_GLOBAL);
if (!handle)
{
ERRORLOG("dlopen myself: %s", dlerror());
return false;
}
char *path = strdup(info.dli_fname);
char *p;
if ((p = rindex(path, '/')))
*p = 0;
DEBUGLOG("library path %s", path);
char pat[64];
#ifdef WITH_SDDVB
{
snprintf(pat, sizeof(pat), "%s%s%s%s", LIBVDR_PREFIX, "dvbsddevice", SO_INDICATOR, APIVERSION);
cScDll *dll = new cScDll(AddDirectory(path, pat));
if (dll)
{
if (dll->Load(false))
{
INFOLOG("VDR dvbsddevice plugin loaded as subplugin");
}
Ins(dll);
}
}
#endif //WITH_SDDVB
#ifdef WITH_HDDVB
{
snprintf(pat, sizeof(pat), "%s%s%s%s", LIBVDR_PREFIX, "dvbhddevice", SO_INDICATOR, APIVERSION);
cScDll *dll = new cScDll(AddDirectory(path, pat));
if (dll)
{
if (dll->Load(false))
{
INFOLOG("VDR dvbhddevice plugin loaded as subplugin");
}
Ins(dll);
}
}
#endif //WITH_HDDVB
#ifdef WITH_UFS9XX
{
snprintf(pat, sizeof(pat), "%s%s%s%s", LIBVDR_PREFIX, "dvbufs9xx", SO_INDICATOR, APIVERSION);
cScDll *dll = new cScDll(AddDirectory(path, pat));
if (dll)
{
if (dll->Load(false))
{
INFOLOG("VDR dvbufs9xx plugin loaded as subplugin");
}
Ins(dll);
}
}
#endif //WITH_UFS9XX
snprintf(pat, sizeof(pat), "%s*%s%s", LIBDVBAPI_PREFIX, SO_INDICATOR, APIVERSION);
bool res = true;
cReadDir dir(path);
struct dirent *e;
while ((e = dir.Next()))
{
if (!fnmatch(pat, e->d_name, FNM_PATHNAME | FNM_NOESCAPE))
{
cScDll *dll = new cScDll(AddDirectory(path, e->d_name));
if (dll)
{
if (!dll->Load(true))
res = false;
Ins(dll);
}
}
}
free(path);
return res;
}