--- extensions/source/nsplugin/source/so_env.cxx.orig 2007-03-18 18:43:48.259831000 +0200 +++ extensions/source/nsplugin/source/so_env.cxx 2007-03-18 18:44:09.670316347 +0200 @@ -39,6 +39,7 @@ #ifdef UNIX #include #include +#include #if defined(SOLARIS) && !defined(__GNUC__) #include #else @@ -125,6 +126,82 @@ return 0; } +#ifdef UNIX +extern int nspluginOOoModuleHook (void** aResult); +int nspluginOOoModuleHook (void** aResult) +{ + void *dl_handle; + void *thisp; + + 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, }; + if(!dladdr((const 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] != '/') + { + strcpy (libFileName, cwdstr); + strcat (libFileName, "/"); + } + strcat (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); + if (len == -1) + { + fprintf (stderr, "Couldn't read link '%s'\n", libFileName); + return 1; + } + realFileName[len] = '\0'; + if (!(clobber = strstr (realFileName, "/program/libnpsoplug"))) + { + fprintf (stderr, "Couldn't find suffix in '%s'\n", realFileName); + return 1; + } + *clobber = '\0'; + } + else + { + *clobber = '\0'; + strcpy (realFileName, libFileName); + } + *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) { @@ -137,9 +214,22 @@ // Filename of lnk file, eg. "soffice" char lnkFileName[NPP_PATH_MAX] = {0}; char* pTempZero = NULL; + + /* try to fetch a 'self' pointer */ + if (!nspluginOOoModuleHook (aResult)) + return 0; + + /* .. now in $HOME */ sprintf(lnkFileName, "%s/.mozilla/plugins/libnpsoplugin%s", getenv("HOME"), SAL_DLLEXTENSION); - if ((0 > readlink(lnkFileName, realFileName, NPP_PATH_MAX)) || - (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION)))) + ssize_t len = readlink(lnkFileName, realFileName, NPP_PATH_MAX); + if (-1 == len) + { + *realFileName = 0; + return -1; + } + realFileName[len] = '\0'; + + if (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION))) { *realFileName = 0; return -1;