2 * plugin-entry.cpp: MoonLight browser plugin.
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2007 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
18 #include "moonlight.h"
21 #include <mono/metadata/assembly.h>
22 #include <mono/metadata/mono-config.h>
25 typedef NPError (*np_initialize_func
) (void *a
, void *b
);
26 typedef NPError (*np_shutdown_func
) ();
27 typedef NPError (*np_getvalue_func
) (void *, NPPVariable var
, void *avalue
);
28 typedef char * (*np_getmime_func
) ();
30 static np_initialize_func initialize
;
31 static np_getvalue_func getvalue
;
32 static np_shutdown_func shutdown
;
33 static np_getmime_func getmime
;
42 if (dladdr((void *) &load
, &dlinfo
) == 0) {
43 fprintf (stderr
, "Unable to find the location of libmoonloaderxpi %s\n", dlerror ());
47 if (strstr(dlinfo
.dli_fname
, "libmoonloaderxpi.so")) {
49 fprintf (stdout
, "Attempting to load libmoonloaderxpi \n");
51 plugin_dir
= g_build_filename (g_path_get_dirname(dlinfo
.dli_fname
), "moonlight", NULL
);
53 plugin_path
= g_build_filename (plugin_dir
, "libmoonpluginxpi.so", NULL
);
57 char *avutil_path
= g_build_filename (plugin_dir
, "libavutil.so", NULL
);
58 void *real_avutil
= dlopen (avutil_path
, RTLD_LAZY
| RTLD_GLOBAL
);
59 if (real_avutil
== NULL
){
60 fprintf (stderr
, "Unable to load the libavutil %s\n", dlerror ());
67 char *swscale_path
= g_build_filename (plugin_dir
, "libswscale.so", NULL
);
68 void *real_swscale
= dlopen (swscale_path
, RTLD_LAZY
| RTLD_GLOBAL
);
69 if (real_swscale
== NULL
){
70 fprintf (stderr
, "Unable to load the libswscale %s\n", dlerror ());
73 g_free (swscale_path
);
77 char *avcodec_path
= g_build_filename (plugin_dir
, "libavcodec.so", NULL
);
78 void *real_avcodec
= dlopen (avcodec_path
, RTLD_LAZY
| RTLD_GLOBAL
);
79 if (real_avcodec
== NULL
){
80 fprintf (stderr
, "Unable to load the libavcodec %s\n", dlerror ());
83 g_free (avcodec_path
);
88 char *mono_path
= g_build_filename (plugin_dir
, "libmono.so", NULL
);
89 void *real_mono
= dlopen (mono_path
, RTLD_LAZY
| RTLD_GLOBAL
);
90 if (real_mono
== NULL
){
91 fprintf (stderr
, "Unable to load the libmono %s\n", dlerror ());
94 mono_set_dirs (plugin_dir
, plugin_dir
);
99 char *moon_path
= g_build_filename (plugin_dir
, "libmoonxpi.so", NULL
);
100 void *real_moon
= dlopen (moon_path
, RTLD_LAZY
| RTLD_GLOBAL
);
101 if (real_moon
== NULL
){
102 fprintf (stderr
, "Unable to load the libmoonxpi %s\n", dlerror ());
106 char* moon_config
= g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><configuration><dllmap dll=\"moon\" target=\"%s\" /></configuration>",moon_path
);
107 mono_config_parse_memory(moon_config
);
108 g_free (moon_config
);
115 fprintf (stdout
, "Attempting to load the system libmoon \n");
116 const gchar
*moon_plugin_dir
= g_getenv("MOON_PLUGIN_DIR");
117 if (moon_plugin_dir
== NULL
) {
118 plugin_path
= g_build_filename (PLUGIN_DIR
, "plugin", "libmoonplugin.so", NULL
);
120 plugin_path
= g_build_filename (moon_plugin_dir
, "libmoonplugin.so", NULL
);
124 void *real_plugin
= dlopen (plugin_path
, RTLD_LAZY
| RTLD_GLOBAL
);
126 if (real_plugin
== NULL
){
127 fprintf (stderr
, "Unable to load the real plugin %s\n", dlerror ());
128 fprintf (stderr
, "plugin_path is %s\n", plugin_path
);
132 // Must dllmap moonplugin, otherwise it doesn't know where to get it
133 char* plugin_config
= g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><configuration><dllmap dll=\"moonplugin\" target=\"%s\" /></configuration>",plugin_path
);
134 mono_config_parse_memory(plugin_config
);
135 g_free (plugin_config
);
137 g_free (plugin_path
);
139 initialize
= (np_initialize_func
) dlsym (real_plugin
, LOADER_RENAMED_NAME(NP_Initialize
));
140 if (initialize
== NULL
){
141 fprintf (stderr
, "NP_Initialize not found %s\n", dlerror ());
146 getvalue
= (np_getvalue_func
) dlsym (real_plugin
, LOADER_RENAMED_NAME(NP_GetValue
));
147 if (getvalue
== NULL
){
148 fprintf (stderr
, "NP_GetValue not found %s\n", dlerror ());
152 getmime
= (np_getmime_func
) dlsym (real_plugin
, LOADER_RENAMED_NAME(NP_GetMIMEDescription
));
153 if (getmime
== NULL
){
154 fprintf (stderr
, "NP_GetMIMEDescription not found %s\n", dlerror ());
158 shutdown
= (np_shutdown_func
) dlsym (real_plugin
, LOADER_RENAMED_NAME(NP_Shutdown
));
159 if (shutdown
== NULL
){
160 fprintf (stderr
, "NP_Shutdown not found %s\n", dlerror ());
168 NP_GetMIMEDescription (void)
173 if (getmime
!= NULL
){
180 NP_GetValue (void *future
, NPPVariable variable
, void *value
)
182 if (getvalue
== NULL
)
185 if (getvalue
!= NULL
)
186 return (*getvalue
) (future
, variable
, value
);
188 return NPERR_GENERIC_ERROR
;
192 NP_Initialize (NPNetscapeFuncs
*mozilla_funcs
, NPPluginFuncs
*plugin_funcs
)
194 if (initialize
== NULL
)
197 if (initialize
== NULL
)
198 return NPERR_GENERIC_ERROR
;
203 res
= (*initialize
) (mozilla_funcs
, plugin_funcs
);
205 res
= (*initialize
) (mozilla_funcs
);
213 if (shutdown
== NULL
)
215 if (shutdown
!= NULL
)
216 return (*shutdown
) ();
217 return NPERR_GENERIC_ERROR
;