2
* The contents of this file are subject to the Mozilla Public License
3
* Version 1.1 (the "License"); you may not use this file except in
4
* compliance with the License. You may obtain a copy of the License at
5
* http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS IS"
8
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9
* License for the specific language governing rights and limitations
12
* The Original Code is the Mozilla OS/2 libraries.
14
* The Initial Developer of the Original Code is John Fairhurst,
15
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
16
* Copyright (C) 1998 John Fairhurst. All Rights Reserved.
22
// OS/2 plugin-loading code.
25
#define INCL_DOSERRORS
28
#include "nsPluginsDir.h"
32
#include "nsPluginDefs.h"
36
/* Load a string stored as RCDATA in a resource segment */
37
/* Returned string needs to be PR_Free'd by caller */
38
static char *LoadRCDATAString( HMODULE hMod, ULONG resid)
44
rc = DosQueryResourceSize( hMod, RT_RCDATA, resid, &ulSize);
48
char *readOnlyString = 0;
49
rc = DosGetResource( hMod, RT_RCDATA, resid, (void**) &readOnlyString);
51
/* allow for 0-termination if user hasn't got it right */
52
if( readOnlyString[ ulSize - 1] != '\0')
57
/* copy string & zero-terminate */
58
string = (char*) PR_Malloc( ulSize);
59
memcpy( string, readOnlyString, ulSize - 1);
60
string[ ulSize - 1] = '\0';
62
DosFreeResource( readOnlyString);
69
static PRUint32 CalculateVariantCount(char* mimeTypes)
71
PRUint32 variants = 1;
73
if(mimeTypes == nsnull)
76
char* index = mimeTypes;
87
static char** MakeStringArray(PRUint32 variants, char* data)
89
if((variants <= 0) || (data == nsnull))
92
char ** array = (char **)PR_Calloc(variants, sizeof(char *));
97
for(PRUint32 i = 0; i < variants; i++)
99
char * p = PL_strchr(start, '|');
103
array[i] = PL_strdup(start);
109
static void FreeStringArray(PRUint32 variants, char ** array)
111
if((variants == 0) || (array == nsnull))
114
for(PRUint32 i = 0; i < variants; i++)
116
if(array[i] != nsnull)
118
PL_strfree(array[i]);
125
// nsPluginsDir class
127
PRBool nsPluginsDir::IsPluginFile(nsIFile* file)
130
if (NS_FAILED(file->GetNativeLeafName(leaf)))
133
const char *leafname = leaf.get();
135
if( nsnull != leafname)
137
int len = strlen( leafname);
138
if( len > 6 && // np*.dll
139
(0 == strnicmp( &(leafname[len - 4]), ".dll", 4)) &&
140
(0 == strnicmp( leafname, "np", 2)))
148
// nsPluginFile implementation
150
nsPluginFile::nsPluginFile(nsIFile* file)
154
nsPluginFile::~nsPluginFile()
157
// Loads the plugin into memory using NSPR's shared-library loading
158
nsresult nsPluginFile::LoadPlugin( PRLibrary *&outLibrary)
161
return NS_ERROR_NULL_POINTER;
164
mPlugin->GetNativePath(temp);
166
outLibrary = PR_LoadLibrary(temp.get());
167
return outLibrary == nsnull ? NS_ERROR_FAILURE : NS_OK;
170
// Obtains all of the information currently available for this plugin.
171
nsresult nsPluginFile::GetPluginInfo( nsPluginInfo &info)
173
nsresult rc = NS_ERROR_FAILURE;
174
HMODULE hPlug = 0; // Need a HMODULE to query resource statements
175
char failure[ CCHMAXPATH] = "";
180
mPlugin->GetNativePath(temp);
182
ret = DosLoadModule( failure, CCHMAXPATH, path, &hPlug);
184
while( ret == NO_ERROR)
186
info.fPluginInfoSize = sizeof( nsPluginInfo);
188
info.fName = LoadRCDATAString( hPlug, NS_INFO_ProductName);
190
// get description (doesn't matter if it's missing)...
191
info.fDescription = LoadRCDATAString( hPlug, NS_INFO_FileDescription);
193
char * mimeType = LoadRCDATAString( hPlug, NS_INFO_MIMEType);
194
if( nsnull == mimeType) break;
196
char * mimeDescription = LoadRCDATAString( hPlug, NS_INFO_FileOpenName);
197
if( nsnull == mimeDescription) break;
199
char * extensions = LoadRCDATAString( hPlug, NS_INFO_FileExtents);
200
if( nsnull == extensions) break;
202
info.fVariantCount = CalculateVariantCount(mimeType);
204
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, mimeType);
205
if( info.fMimeTypeArray == nsnull) break;
207
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription);
208
if( nsnull == info.fMimeDescriptionArray) break;
210
info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions);
211
if( nsnull == info.fExtensionArray) break;
213
info.fFileName = PL_strdup(path);
220
DosFreeModule( hPlug);
225
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
227
if(info.fName != nsnull)
228
PL_strfree(info.fName);
230
if(info.fDescription != nsnull)
231
PL_strfree(info.fDescription);
233
if(info.fMimeTypeArray != nsnull)
234
FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
236
if(info.fMimeDescriptionArray != nsnull)
237
FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
239
if(info.fExtensionArray != nsnull)
240
FreeStringArray(info.fVariantCount, info.fExtensionArray);
242
memset((void *)&info, 0, sizeof(info));