2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-06-28 23:11:18 +00:00
|
|
|
|
|
|
|
// OS/2 plugin-loading code.
|
|
|
|
|
|
|
|
#define INCL_DOS
|
|
|
|
#define INCL_DOSERRORS
|
|
|
|
#include <os2.h>
|
|
|
|
|
|
|
|
#include "nsPluginsDir.h"
|
|
|
|
#include "prlink.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prmem.h"
|
2008-07-25 00:08:33 +00:00
|
|
|
#include "prprf.h"
|
2009-09-17 01:30:26 +00:00
|
|
|
#include "npapi.h"
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2003-03-15 14:07:54 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-06-28 23:11:18 +00:00
|
|
|
/* Load a string stored as RCDATA in a resource segment */
|
|
|
|
/* Returned string needs to be PR_Free'd by caller */
|
|
|
|
static char *LoadRCDATAString( HMODULE hMod, ULONG resid)
|
|
|
|
{
|
|
|
|
APIRET rc;
|
|
|
|
ULONG ulSize = 0;
|
|
|
|
char *string = 0;
|
|
|
|
|
|
|
|
rc = DosQueryResourceSize( hMod, RT_RCDATA, resid, &ulSize);
|
|
|
|
|
|
|
|
if( rc == NO_ERROR)
|
|
|
|
{
|
|
|
|
char *readOnlyString = 0;
|
|
|
|
rc = DosGetResource( hMod, RT_RCDATA, resid, (void**) &readOnlyString);
|
|
|
|
|
|
|
|
/* allow for 0-termination if user hasn't got it right */
|
|
|
|
if( readOnlyString[ ulSize - 1] != '\0')
|
|
|
|
ulSize++;
|
|
|
|
|
|
|
|
if( rc == NO_ERROR)
|
|
|
|
{
|
|
|
|
/* copy string & zero-terminate */
|
|
|
|
string = (char*) PR_Malloc( ulSize);
|
|
|
|
memcpy( string, readOnlyString, ulSize - 1);
|
|
|
|
string[ ulSize - 1] = '\0';
|
|
|
|
|
|
|
|
DosFreeResource( readOnlyString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2008-07-19 18:06:47 +00:00
|
|
|
/* Load a version string stored as RCDATA in a resource segment */
|
|
|
|
/* Returned string needs to be PR_Free'd by caller */
|
|
|
|
static char *LoadRCDATAVersion(HMODULE hMod, ULONG resid)
|
|
|
|
{
|
|
|
|
APIRET rc;
|
|
|
|
ULONG ulSize = 0;
|
|
|
|
char *string = 0;
|
|
|
|
|
|
|
|
rc = DosQueryResourceSize(hMod, RT_RCDATA, resid, &ulSize);
|
|
|
|
|
|
|
|
// version info is should be 8 chars
|
|
|
|
if (rc == NO_ERROR && ulSize == 8)
|
|
|
|
{
|
|
|
|
char *version = NULL;
|
|
|
|
rc = DosGetResource(hMod, RT_RCDATA, resid, (void**) &version);
|
|
|
|
|
|
|
|
if (rc == NO_ERROR)
|
|
|
|
{
|
|
|
|
string = PR_smprintf("%d.%d.%d.%d\n",
|
|
|
|
version[0], version[2], version[4], version[6]);
|
|
|
|
|
|
|
|
DosFreeResource(version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2000-08-02 23:01:35 +00:00
|
|
|
static PRUint32 CalculateVariantCount(char* mimeTypes)
|
1999-06-28 23:11:18 +00:00
|
|
|
{
|
2000-10-30 21:06:11 +00:00
|
|
|
PRUint32 variants = 1;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(mimeTypes == nullptr)
|
2000-08-02 23:01:35 +00:00
|
|
|
return 0;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-10-30 21:06:11 +00:00
|
|
|
char* index = mimeTypes;
|
|
|
|
while (*index)
|
|
|
|
{
|
|
|
|
if (*index == '|')
|
|
|
|
variants++;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-10-30 21:06:11 +00:00
|
|
|
++index;
|
|
|
|
}
|
|
|
|
return variants;
|
2000-08-02 23:01:35 +00:00
|
|
|
}
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-08-02 23:01:35 +00:00
|
|
|
static char** MakeStringArray(PRUint32 variants, char* data)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
if((variants <= 0) || (data == nullptr))
|
|
|
|
return nullptr;
|
2000-08-02 23:01:35 +00:00
|
|
|
|
|
|
|
char ** array = (char **)PR_Calloc(variants, sizeof(char *));
|
2012-07-30 14:20:58 +00:00
|
|
|
if(array == nullptr)
|
|
|
|
return nullptr;
|
2000-08-02 23:01:35 +00:00
|
|
|
|
|
|
|
char * start = data;
|
|
|
|
for(PRUint32 i = 0; i < variants; i++)
|
|
|
|
{
|
|
|
|
char * p = PL_strchr(start, '|');
|
2012-07-30 14:20:58 +00:00
|
|
|
if(p != nullptr)
|
2000-08-02 23:01:35 +00:00
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
array[i] = PL_strdup(start);
|
|
|
|
start = ++p;
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-08-02 23:01:35 +00:00
|
|
|
static void FreeStringArray(PRUint32 variants, char ** array)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
if((variants == 0) || (array == nullptr))
|
2000-08-02 23:01:35 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for(PRUint32 i = 0; i < variants; i++)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
if(array[i] != nullptr)
|
2000-08-02 23:01:35 +00:00
|
|
|
{
|
|
|
|
PL_strfree(array[i]);
|
2012-07-30 14:20:58 +00:00
|
|
|
array[i] = nullptr;
|
2000-08-02 23:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
PR_Free(array);
|
1999-06-28 23:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsPluginsDir class
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsPluginsDir::IsPluginFile(nsIFile* file)
|
1999-06-28 23:11:18 +00:00
|
|
|
{
|
2003-03-15 01:04:32 +00:00
|
|
|
nsCAutoString leaf;
|
|
|
|
if (NS_FAILED(file->GetNativeLeafName(leaf)))
|
2011-09-30 06:02:59 +00:00
|
|
|
return false;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2003-03-15 01:04:32 +00:00
|
|
|
const char *leafname = leaf.get();
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if( nullptr != leafname)
|
2003-03-15 01:04:32 +00:00
|
|
|
{
|
1999-06-28 23:11:18 +00:00
|
|
|
int len = strlen( leafname);
|
|
|
|
if( len > 6 && // np*.dll
|
|
|
|
(0 == strnicmp( &(leafname[len - 4]), ".dll", 4)) &&
|
|
|
|
(0 == strnicmp( leafname, "np", 2)))
|
|
|
|
{
|
2011-09-30 06:02:59 +00:00
|
|
|
return true;
|
1999-06-28 23:11:18 +00:00
|
|
|
}
|
2003-03-15 01:04:32 +00:00
|
|
|
}
|
2011-09-30 06:02:59 +00:00
|
|
|
return false;
|
1999-06-28 23:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsPluginFile implementation
|
|
|
|
|
2003-03-15 14:07:54 +00:00
|
|
|
nsPluginFile::nsPluginFile(nsIFile* file)
|
|
|
|
: mPlugin(file)
|
1999-06-28 23:11:18 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
nsPluginFile::~nsPluginFile()
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Loads the plugin into memory using NSPR's shared-library loading
|
2010-08-18 00:05:48 +00:00
|
|
|
nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary)
|
1999-06-28 23:11:18 +00:00
|
|
|
{
|
2003-03-15 01:04:32 +00:00
|
|
|
if (!mPlugin)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCAutoString temp;
|
|
|
|
mPlugin->GetNativePath(temp);
|
|
|
|
|
2010-08-18 00:05:48 +00:00
|
|
|
*outLibrary = PR_LoadLibrary(temp.get());
|
2012-07-30 14:20:58 +00:00
|
|
|
return *outLibrary == nullptr ? NS_ERROR_FAILURE : NS_OK;
|
1999-06-28 23:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains all of the information currently available for this plugin.
|
2010-08-18 00:05:48 +00:00
|
|
|
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo &info, PRLibrary **outLibrary)
|
1999-06-28 23:11:18 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*outLibrary = nullptr;
|
2010-08-18 00:05:48 +00:00
|
|
|
|
2009-06-10 20:47:49 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
1999-06-28 23:11:18 +00:00
|
|
|
HMODULE hPlug = 0; // Need a HMODULE to query resource statements
|
|
|
|
char failure[ CCHMAXPATH] = "";
|
|
|
|
APIRET ret;
|
|
|
|
|
2009-06-10 20:47:49 +00:00
|
|
|
nsCAutoString path;
|
|
|
|
if (NS_FAILED(rv = mPlugin->GetNativePath(path)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCAutoString fileName;
|
|
|
|
if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
ret = DosLoadModule( failure, CCHMAXPATH, path.get(), &hPlug);
|
2012-07-30 14:20:58 +00:00
|
|
|
info.fVersion = nullptr;
|
2000-10-30 21:06:11 +00:00
|
|
|
|
1999-06-28 23:11:18 +00:00
|
|
|
while( ret == NO_ERROR)
|
|
|
|
{
|
2009-09-22 13:49:26 +00:00
|
|
|
info.fName = LoadRCDATAString( hPlug, NP_INFO_ProductName);
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2009-09-22 13:49:26 +00:00
|
|
|
info.fVersion = LoadRCDATAVersion( hPlug, NP_INFO_ProductVersion);
|
2008-07-19 18:06:47 +00:00
|
|
|
|
1999-06-28 23:11:18 +00:00
|
|
|
// get description (doesn't matter if it's missing)...
|
2009-09-22 13:49:26 +00:00
|
|
|
info.fDescription = LoadRCDATAString( hPlug, NP_INFO_FileDescription);
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2009-09-22 13:49:26 +00:00
|
|
|
char * mimeType = LoadRCDATAString( hPlug, NP_INFO_MIMEType);
|
2012-07-30 14:20:58 +00:00
|
|
|
if( nullptr == mimeType) break;
|
2000-08-02 23:01:35 +00:00
|
|
|
|
2009-09-22 13:49:26 +00:00
|
|
|
char * mimeDescription = LoadRCDATAString( hPlug, NP_INFO_FileOpenName);
|
2012-07-30 14:20:58 +00:00
|
|
|
if( nullptr == mimeDescription) break;
|
2000-08-02 23:01:35 +00:00
|
|
|
|
2009-09-22 13:49:26 +00:00
|
|
|
char * extensions = LoadRCDATAString( hPlug, NP_INFO_FileExtents);
|
2012-07-30 14:20:58 +00:00
|
|
|
if( nullptr == extensions) break;
|
2000-08-02 23:01:35 +00:00
|
|
|
|
|
|
|
info.fVariantCount = CalculateVariantCount(mimeType);
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-10-30 21:06:11 +00:00
|
|
|
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, mimeType);
|
2012-07-30 14:20:58 +00:00
|
|
|
if( info.fMimeTypeArray == nullptr) break;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-10-30 21:06:11 +00:00
|
|
|
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription);
|
2012-07-30 14:20:58 +00:00
|
|
|
if( nullptr == info.fMimeDescriptionArray) break;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2000-10-30 21:06:11 +00:00
|
|
|
info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions);
|
2012-07-30 14:20:58 +00:00
|
|
|
if( nullptr == info.fExtensionArray) break;
|
1999-06-28 23:11:18 +00:00
|
|
|
|
2009-06-10 20:47:49 +00:00
|
|
|
info.fFullPath = PL_strdup(path.get());
|
|
|
|
info.fFileName = PL_strdup(fileName.get());
|
2000-10-30 21:06:11 +00:00
|
|
|
|
2009-06-10 20:47:49 +00:00
|
|
|
rv = NS_OK;
|
1999-06-28 23:11:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 0 != hPlug)
|
|
|
|
DosFreeModule( hPlug);
|
|
|
|
|
2009-06-10 20:47:49 +00:00
|
|
|
return rv;
|
1999-06-28 23:11:18 +00:00
|
|
|
}
|
2000-05-30 14:36:43 +00:00
|
|
|
|
|
|
|
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fName != nullptr)
|
2000-05-30 14:36:43 +00:00
|
|
|
PL_strfree(info.fName);
|
2009-06-10 20:47:49 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fFullPath != nullptr)
|
2009-06-10 20:47:49 +00:00
|
|
|
PL_strfree(info.fFullPath);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fFileName != nullptr)
|
2008-07-15 10:50:42 +00:00
|
|
|
PL_strfree(info.fFileName);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fVersion != nullptr)
|
2008-07-19 11:08:19 +00:00
|
|
|
PL_strfree(info.fVersion);
|
2008-07-15 10:50:42 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fDescription != nullptr)
|
2000-05-30 14:36:43 +00:00
|
|
|
PL_strfree(info.fDescription);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fMimeTypeArray != nullptr)
|
2000-08-02 23:01:35 +00:00
|
|
|
FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
|
2000-05-30 14:36:43 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fMimeDescriptionArray != nullptr)
|
2000-08-02 23:01:35 +00:00
|
|
|
FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
|
2000-05-30 14:36:43 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if(info.fExtensionArray != nullptr)
|
2000-08-02 23:01:35 +00:00
|
|
|
FreeStringArray(info.fVariantCount, info.fExtensionArray);
|
2000-05-30 14:36:43 +00:00
|
|
|
|
|
|
|
memset((void *)&info, 0, sizeof(info));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|