summaryrefslogtreecommitdiff
path: root/extensions/source/nsplugin/source/so_env.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/source/nsplugin/source/so_env.cxx')
-rw-r--r--extensions/source/nsplugin/source/so_env.cxx132
1 files changed, 131 insertions, 1 deletions
diff --git a/extensions/source/nsplugin/source/so_env.cxx b/extensions/source/nsplugin/source/so_env.cxx
index 36a2b3f3abec..4cce0f98cd4f 100644
--- a/extensions/source/nsplugin/source/so_env.cxx
+++ b/extensions/source/nsplugin/source/so_env.cxx
@@ -31,6 +31,9 @@
#ifdef UNIX
#include <sys/types.h>
#include <strings.h>
+#ifdef LINUX
+#include <dlfcn.h>
+#endif
#include <stdarg.h>
// For vsnprintf()
#define NSP_vsnprintf vsnprintf
@@ -119,6 +122,113 @@ restoreUTF8(char *pPath)
return 0;
}
+#ifdef LINUX
+extern int nspluginOOoModuleHook (void** aResult);
+int nspluginOOoModuleHook (void** aResult)
+{
+ void *dl_handle;
+
+ dl_handle = dlopen(NULL, RTLD_NOW);
+ if (!dl_handle)
+ {
+ fprintf (stderr, "Can't open myself '%s'\n", dlerror());
+ return 1;
+ }
+
+ Dl_info dl_info = { 0,0,0,0 };
+ if(!dladdr((void *)nspluginOOoModuleHook, &dl_info))
+ {
+ fprintf (stderr, "Can't find my own address '%s'\n", dlerror());
+ return 1;
+ }
+
+ if (!dl_info.dli_fname)
+ {
+ fprintf (stderr, "Can't find my own file name\n");
+ return 1;
+ }
+
+ char cwdstr[NPP_PATH_MAX];
+ if (!getcwd (cwdstr, sizeof(cwdstr)))
+ {
+ fprintf (stderr, "Can't get cwd\n");
+ return 1;
+ }
+
+ char libFileName[NPP_PATH_MAX];
+
+ if (dl_info.dli_fname[0] != '/')
+ {
+ if ((strlen(cwdstr) + 1 + strlen(dl_info.dli_fname)) >= NPP_PATH_MAX)
+ {
+ fprintf (stderr, "Plugin path too long\n");
+ return 1;
+ }
+ strcpy (libFileName, cwdstr);
+ strcat (libFileName, "/");
+ strcat (libFileName, dl_info.dli_fname);
+ }
+ else
+ {
+ if (strlen(dl_info.dli_fname) >= NPP_PATH_MAX)
+ {
+ fprintf (stderr, "Plugin path too long\n");
+ return 1;
+ }
+ strcpy (libFileName, dl_info.dli_fname);
+ }
+
+ char *clobber;
+ static char realFileName[NPP_PATH_MAX] = {0};
+# define SEARCH_SUFFIX "/program/libnpsoplug"
+
+ if (!(clobber = strstr (libFileName, SEARCH_SUFFIX)))
+ {
+ ssize_t len = readlink(libFileName, realFileName, NPP_PATH_MAX-1);
+ if (len == -1)
+ {
+ fprintf (stderr, "Couldn't read link '%s'\n", libFileName);
+ return 1;
+ }
+ realFileName[len] = '\0';
+ if (!(clobber = strstr (realFileName, SEARCH_SUFFIX)))
+ {
+ fprintf (stderr, "Couldn't find suffix in '%s'\n", realFileName);
+ return 1;
+ }
+ *clobber = '\0';
+ }
+ else
+ {
+ *clobber = '\0';
+ strcpy (realFileName, libFileName);
+ }
+
+ fprintf (stderr, "OpenOffice path before fixup is '%s'\n", realFileName);
+
+ if (realFileName[0] != '/') {
+ /* a relative sym-link and we need to get an absolute path */
+ char scratch[NPP_PATH_MAX] = {0};
+ if (strlen (realFileName) + strlen (libFileName) + 2 >= NPP_PATH_MAX - 1)
+ {
+ fprintf (stderr, "Paths too long to fix up.\n");
+ return 1;
+ }
+ strcpy (scratch, libFileName);
+ if (strrchr (scratch, '/')) /* remove the last element */
+ *(strrchr (scratch, '/') + 1) = '\0';
+ strcat (scratch, realFileName);
+ strcpy (realFileName, scratch);
+ }
+
+ *aResult = realFileName;
+
+ fprintf (stderr, "OpenOffice path is '%s'\n", realFileName);
+
+ return 0;
+}
+#endif
+
// *aResult points the static string holding "/opt/staroffice8"
int findReadSversion(void** aResult, int /*bWnt*/, const char* /*tag*/, const char* /*entry*/)
{
@@ -131,9 +241,29 @@ int findReadSversion(void** aResult, int /*bWnt*/, const char* /*tag*/, const ch
// Filename of lnk file, eg. "soffice"
char lnkFileName[NPP_PATH_MAX] = {0};
char* pTempZero = NULL;
+
+#ifdef LINUX
+ /* try to fetch a 'self' pointer */
+ if (!nspluginOOoModuleHook (aResult))
+ return 0;
+
+ /* .. now in $HOME */
+#endif
sprintf(lnkFileName, "%s/.mozilla/plugins/libnpsoplugin%s", getenv("HOME"), SAL_DLLEXTENSION);
+#ifdef LINUX
+ ssize_t len = readlink(lnkFileName, realFileName, NPP_PATH_MAX-1);
+ if (-1 == len)
+ {
+ *realFileName = 0;
+ return -1;
+ }
+ realFileName[len] = '\0';
+
+ if (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION)))
+#else
if ((0 > readlink(lnkFileName, realFileName, NPP_PATH_MAX)) ||
- (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION))))
+ (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION))))
+#endif
{
*realFileName = 0;
return -1;