forked from mono/moon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-proxy.cpp
More file actions
177 lines (144 loc) · 4.65 KB
/
plugin-proxy.cpp
File metadata and controls
177 lines (144 loc) · 4.65 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* plugin-entry.cpp: MoonLight browser plugin.
*
* Contact:
* Moonlight List (moonlight-list@lists.ximian.com)
*
* Copyright 2007 Novell, Inc. (http://www.novell.com)
*
* See the LICENSE file included with the distribution for details.
*
*/
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <config.h>
#include "moonlight.h"
typedef NPError (*np_initialize_func) (void *a, void *b);
typedef NPError (*np_shutdown_func) ();
typedef NPError (*np_getvalue_func) (void *, NPPVariable var, void *avalue);
typedef void (*config_parse_memory_func) (const char *buffer);
static np_initialize_func initialize;
static np_getvalue_func getvalue;
static np_shutdown_func shutdown;
static NPError
load (void)
{
char *plugin_path;
#if DEBUG
printf ("Moonlight: " PACKAGE_VERSION "\n");
#endif
Dl_info dlinfo;
if (dladdr((void *) &load, &dlinfo) == 0) {
fprintf (stderr, "Moonlight: Unable to find the location of libmoonloaderxpi %s\n", dlerror ());
return FALSE;
}
if (strstr(dlinfo.dli_fname, "libmoonloaderxpi.so")) {
fprintf (stdout, "Moonlight: Attempting to load libmoonloaderxpi \n");
char *plugin_dir;
plugin_dir = g_build_filename (g_path_get_dirname(dlinfo.dli_fname), "moonlight", NULL);
plugin_path = g_build_filename (plugin_dir, "libmoonpluginxpi.so", NULL);
#if INCLUDE_FFMPEG
// load libavutil
char *avutil_path = g_build_filename (plugin_dir, "libavutil.so", NULL);
void *real_avutil = dlopen (avutil_path, RTLD_LAZY | RTLD_GLOBAL);
if (real_avutil == NULL){
fprintf (stderr, "Moonlight: Unable to load the libavutil %s\n", dlerror ());
return FALSE;
}
g_free (avutil_path);
// load libavcodec
char *avcodec_path = g_build_filename (plugin_dir, "libavcodec.so", NULL);
void *real_avcodec = dlopen (avcodec_path, RTLD_LAZY | RTLD_GLOBAL);
if (real_avcodec == NULL){
fprintf (stderr, "Moonlight: Unable to load the libavcodec %s\n", dlerror ());
return FALSE;
}
g_free (avcodec_path);
#endif
g_free (plugin_dir);
} else {
const gchar *moon_plugin_dir = g_getenv("MOON_PLUGIN_DIR");
if (moon_plugin_dir == NULL) {
plugin_path = g_build_filename (PLUGIN_DIR, "plugin", "libmoonplugin.so", NULL);
} else {
plugin_path = g_build_filename (moon_plugin_dir, "libmoonplugin.so", NULL);
}
fprintf (stdout, "Moonlight: Attempting to load libmoonplugin from: %s\n", plugin_path);
}
void *real_plugin = dlopen (plugin_path, RTLD_LAZY | RTLD_GLOBAL);
if (real_plugin == NULL){
fprintf (stderr, "Moonlight: Unable to load the real plugin %s\n", dlerror ());
fprintf (stderr, "Moonlight: plugin_path is %s\n", plugin_path);
return FALSE;
}
config_parse_memory_func mono_config_parse_memory = (config_parse_memory_func) dlsym (real_plugin, "mono_config_parse_memory");
if (mono_config_parse_memory == NULL){
fprintf (stderr, "Moonlight: mono_config_parse_memory not found. %s\n", dlerror ());
return FALSE;
}
// Must dllmap moon and moonplugin, otherwise it doesn't know where to get it
char* plugin_config = g_strdup_printf(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<configuration>"
"<dllmap dll=\"moonplugin\" target=\"%s\" />"
"<dllmap dll=\"moon\" target=\"%s\" />"
"</configuration>", plugin_path, plugin_path);
mono_config_parse_memory(plugin_config);
g_free (plugin_config);
g_free (plugin_path);
initialize = (np_initialize_func) dlsym (real_plugin, LOADER_RENAMED_NAME(NP_Initialize));
if (initialize == NULL){
fprintf (stderr, "Moonlight: NP_Initialize not found %s\n", dlerror ());
return FALSE;
}
getvalue = (np_getvalue_func) dlsym (real_plugin, LOADER_RENAMED_NAME(NP_GetValue));
if (getvalue == NULL){
fprintf (stderr, "Moonlight: NP_GetValue not found %s\n", dlerror ());
return FALSE;
}
shutdown = (np_shutdown_func) dlsym (real_plugin, LOADER_RENAMED_NAME(NP_Shutdown));
if (shutdown == NULL){
fprintf (stderr, "Moonlight: NP_Shutdown not found %s\n", dlerror ());
return FALSE;
}
return TRUE;
}
char*
NP_GetMIMEDescription (void)
{
return (char *) (MIME_TYPES_HANDLED);
}
NPError
NP_GetValue (void *future, NPPVariable variable, void *value)
{
if (getvalue == NULL)
load ();
if (getvalue != NULL)
return (*getvalue) (future, variable, value);
return NPERR_GENERIC_ERROR;
}
NPError OSCALL
NP_Initialize (NPNetscapeFuncs *mozilla_funcs, NPPluginFuncs *plugin_funcs)
{
if (initialize == NULL)
load ();
if (initialize == NULL)
return NPERR_GENERIC_ERROR;
NPError res;
#ifdef XP_UNIX
res = (*initialize) (mozilla_funcs, plugin_funcs);
#else
res = (*initialize) (mozilla_funcs);
#endif
return res;
}
NPError OSCALL
NP_Shutdown (void)
{
if (shutdown == NULL)
load ();
if (shutdown != NULL)
return (*shutdown) ();
return NPERR_GENERIC_ERROR;
}