• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 #include <vector>
39 
40 #include "xp.h"
41 #include "logger.h"
42 
43 extern Logger * logger;
44 
GetPluginsDir(char * path,DWORD maxsize)45 DWORD GetPluginsDir(char * path, DWORD maxsize)
46 {
47   if(!path)
48     return 0;
49 
50   path[0] = '\0';
51 
52 #ifdef XP_WIN
53 
54   DWORD res = GetModuleFileName(NULL, path, maxsize);
55   if(res == 0)
56     return 0;
57 
58   if(path[strlen(path) - 1] == '\\')
59     path[lstrlen(path) - 1] = '\0';
60 
61   char *p = strrchr(path, '\\');
62 
63   if(p)
64     *p = '\0';
65 
66   strcat(path, "\\plugins");
67 
68 #endif
69 
70 #ifdef XP_UNIX
71   // Implement UNIX version
72 #endif
73 
74 #ifdef XP_MAC
75   // Implement Mac version
76 #endif
77 
78   res = strlen(path);
79   return res;
80 }
81 
LoadRealPlugin(char * mimetype)82 XP_HLIB LoadRealPlugin(char * mimetype)
83 {
84   if(!mimetype || !strlen(mimetype))
85     return NULL;
86 
87 #ifdef XP_WIN
88 
89   BOOL bDone = FALSE;
90   WIN32_FIND_DATA ffdataStruct;
91 
92   char szPath[_MAX_PATH];
93   char szFileName[_MAX_PATH];
94 
95   // DebugBreak();
96 
97   GetPluginsDir(szPath, _MAX_PATH);
98 
99   if(logger) {
100       char msg[512];
101       sprintf(msg, "LoadRealPlugin Path: %s\r\n", szPath);
102       logger->logMessage(msg);
103   }
104 
105   strcpy(szFileName, szPath);
106 
107   std::vector<std::string> directories;
108 
109   directories.push_back(szFileName);
110   directories.push_back("C:\\Windows\\System32\\Macromed\\Flash");
111   directories.push_back("C:\\Windows\\SysWOW64\\Macromed\\Flash");
112 
113   for (size_t i = 0; i < directories.size(); ++i) {
114     std::string search_path = directories[i];
115     search_path = search_path.append("\\np*.dll");
116     HANDLE handle = FindFirstFile(search_path.c_str(), &ffdataStruct);
117     if(handle == INVALID_HANDLE_VALUE)
118     {
119       FindClose(handle);
120       continue;
121     }
122 
123     DWORD versize = 0L;
124     DWORD zero = 0L;
125     char * verbuf = NULL;
126 
127     do
128     {
129       std::string cur_file = directories[i];
130       cur_file = cur_file.append("\\");
131       cur_file = cur_file.append(ffdataStruct.cFileName);
132       if(!(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
133          strstr(cur_file.c_str(), "npspy.dll") == NULL)
134       {
135         versize = GetFileVersionInfoSize(cur_file.c_str(), &zero);
136 	      if (versize > 0)
137 		      verbuf = new char[versize];
138         else
139           continue;
140 
141         if(!verbuf)
142 		      continue;
143 
144         GetFileVersionInfo(cur_file.c_str(), NULL, versize, verbuf);
145 
146         char *mimetypes = NULL;
147         UINT len = 0;
148 
149         if(!VerQueryValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType", (void **)&mimetypes, &len)
150            || !mimetypes || !len)
151         {
152           delete [] verbuf;
153           continue;
154         }
155 
156         // browse through a string of mimetypes
157         mimetypes[len] = '\0';
158         char * type = mimetypes;
159 
160         BOOL more = TRUE;
161         while(more)
162         {
163           char * p = strchr(type, '|');
164           if(p)
165             *p = '\0';
166           else
167             more = FALSE;
168 
169           if(0 == _stricmp(mimetype, type))
170           {
171             // this is it!
172             delete [] verbuf;
173             FindClose(handle);
174             HINSTANCE hLib = LoadLibrary(cur_file.c_str());
175             return hLib;
176           }
177 
178           type = p;
179           type++;
180         }
181 
182         delete [] verbuf;
183       }
184 
185     } while(FindNextFile(handle, &ffdataStruct));
186 
187     FindClose(handle);
188   }
189 
190 #endif
191 
192 #ifdef XP_UNIX
193   // Implement UNIX version
194 #endif
195 
196 #ifdef XP_MAC
197   // Implement Mac version
198 #endif
199 
200   return NULL;
201 }
202 
UnloadRealPlugin(XP_HLIB hLib)203 void UnloadRealPlugin(XP_HLIB hLib)
204 {
205 #ifdef XP_WIN
206   if(!hLib)
207     FreeLibrary(hLib);
208 #endif
209 
210 #ifdef XP_UNIX
211   // Implement UNIX version
212 #endif
213 
214 #ifdef XP_MAC
215   // Implement Mac version
216 #endif
217 }
218