]>
Commit | Line | Data |
---|---|---|
34c213d1 ER |
1 | Index: extensions/source/nsplugin/source/so_env.cxx |
2 | =================================================================== | |
3 | RCS file: /cvs/util/extensions/source/nsplugin/source/so_env.cxx,v | |
4 | retrieving revision 1.6 | |
5 | diff -u -p -u -r1.6 so_env.cxx | |
6 | --- extensions/source/nsplugin/source/so_env.cxx 8 Sep 2005 19:40:59 -0000 1.6 | |
7 | +++ extensions/source/nsplugin/source/so_env.cxx 20 Oct 2005 12:32:16 -0000 | |
8 | @@ -36,6 +36,7 @@ | |
9 | #ifdef UNIX | |
10 | #include <sys/types.h> | |
11 | #include <strings.h> | |
12 | +#include <dlfcn.h> | |
13 | #if defined(SOLARIS) && !defined(__GNUC__) | |
14 | #include <varargs.h> | |
15 | #else | |
16 | @@ -122,6 +123,80 @@ restoreUTF8(char *pPath) | |
17 | return 0; | |
18 | } | |
19 | ||
20 | +#ifdef UNIX | |
21 | +extern int nspluginOOoModuleHook (void** aResult); | |
22 | +int nspluginOOoModuleHook (void** aResult) | |
23 | +{ | |
24 | + void *dl_handle; | |
25 | + void *thisp; | |
26 | + | |
27 | + dl_handle = dlopen(NULL, RTLD_NOW); | |
28 | + if (!dl_handle) | |
29 | + { | |
30 | + fprintf (stderr, "Can't open myself '%s'\n", dlerror()); | |
31 | + return 1; | |
32 | + } | |
33 | + | |
34 | + Dl_info dl_info = { 0, }; | |
35 | + if(!dladdr((const void *)nspluginOOoModuleHook, &dl_info)) | |
36 | + { | |
37 | + fprintf (stderr, "Can't find my own address '%s'\n", dlerror()); | |
38 | + return 1; | |
39 | + } | |
40 | + | |
41 | + if (!dl_info.dli_fname) | |
42 | + { | |
43 | + fprintf (stderr, "Can't find my own file name\n"); | |
44 | + return 1; | |
45 | + } | |
46 | + | |
47 | + char cwdstr[NPP_PATH_MAX]; | |
48 | + if (!getcwd (cwdstr, sizeof(cwdstr))) | |
49 | + { | |
50 | + fprintf (stderr, "Can't get cwd\n"); | |
51 | + return 1; | |
52 | + } | |
53 | + | |
54 | + char libFileName[NPP_PATH_MAX]; | |
55 | + | |
56 | + if (dl_info.dli_fname[0] != '/') | |
57 | + { | |
58 | + strcpy (libFileName, cwdstr); | |
59 | + strcat (libFileName, "/"); | |
60 | + } | |
61 | + strcat (libFileName, dl_info.dli_fname); | |
62 | + | |
63 | + char *clobber; | |
64 | + static char realFileName[NPP_PATH_MAX] = {0}; | |
65 | +# define SEARCH_SUFFIX "/program/libnpsoplug" | |
66 | + | |
67 | + if (!(clobber = strstr (libFileName, SEARCH_SUFFIX))) | |
68 | + { | |
69 | + if (readlink(libFileName, realFileName, NPP_PATH_MAX) != 0) | |
70 | + { | |
71 | + fprintf (stderr, "Couldn't read link '%s'\n", libFileName); | |
72 | + return 1; | |
73 | + } | |
74 | + if (!(clobber = strstr (realFileName, "/program/libnpsoplug"))) | |
75 | + { | |
76 | + fprintf (stderr, "Couldn't find suffix in '%s'\n", realFileName); | |
77 | + return 1; | |
78 | + } | |
79 | + *clobber = '\0'; | |
80 | + } | |
81 | + else | |
82 | + { | |
83 | + *clobber = '\0'; | |
84 | + strcpy (realFileName, libFileName); | |
85 | + } | |
86 | + *aResult = realFileName; | |
87 | + | |
88 | + fprintf (stderr, "OpenOffice path is '%s'\n", realFileName); | |
89 | + | |
90 | + return 0; | |
91 | +} | |
92 | +#endif | |
93 | + | |
94 | // *aResult points the static string holding "/opt/staroffice8" | |
95 | int findReadSversion(void** aResult, int bWnt, const char* tag, const char* entry) | |
96 | { | |
97 | @@ -134,6 +209,12 @@ int findReadSversion(void** aResult, int | |
98 | // Filename of lnk file, eg. "soffice" | |
99 | char lnkFileName[NPP_PATH_MAX] = {0}; | |
100 | char* pTempZero = NULL; | |
101 | + | |
102 | + /* try to fetch a 'self' pointer */ | |
103 | + if (!nspluginOOoModuleHook (aResult)) | |
104 | + return 0; | |
105 | + | |
106 | + /* .. now in $HOME */ | |
107 | sprintf(lnkFileName, "%s/.mozilla/plugins/libnpsoplugin%s", getenv("HOME"), SAL_DLLEXTENSION); | |
108 | if ((0 > readlink(lnkFileName, realFileName, NPP_PATH_MAX)) || | |
109 | (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin" SAL_DLLEXTENSION)))) | |
110 |