mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 21:18:35 +00:00
Fixing 45895, r=waterson
This commit is contained in:
parent
4d4f67aa29
commit
a371acfc89
@ -58,9 +58,6 @@ struct nsPluginInfo {
|
||||
PRUint32 fPluginInfoSize; // indicates how large the structure is currently.
|
||||
char* fName; // name of the plugin
|
||||
char* fDescription; // etc.
|
||||
char* fMimeType;
|
||||
char* fMimeDescription;
|
||||
char* fExtensions;
|
||||
PRUint32 fVariantCount;
|
||||
char** fMimeTypeArray;
|
||||
char** fMimeDescriptionArray;
|
||||
|
@ -206,12 +206,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n", mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
#endif
|
||||
|
||||
if(i==0) {
|
||||
info.fMimeType = mtype ? mtype : (char *)"";
|
||||
info.fMimeDescription = descr ? descr : (char *)"";
|
||||
info.fExtensions = exten ? exten : (char *)"";
|
||||
}
|
||||
|
||||
if(!*mtype && !descr && !exten) {
|
||||
i--;
|
||||
info.fVariantCount--;
|
||||
@ -229,4 +223,3 @@ nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,9 @@ static char* GetPluginString(short id, short index)
|
||||
*/
|
||||
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
// need to open the plugin's resource file and read some resources.
|
||||
nsCRT::memset(&info, 0, sizeof(info));
|
||||
|
||||
// need to open the plugin's resource file and read some resources.
|
||||
FSSpec spec = *this;
|
||||
Boolean targetIsFolder, wasAliased;
|
||||
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
|
||||
@ -141,15 +143,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
// 'STR#', 126, 1 => plugin description.
|
||||
info.fDescription = GetPluginString(126, 1);
|
||||
|
||||
// 'STR#', 128, 1 => MIME type.
|
||||
info.fMimeType = GetPluginString(128, 1);
|
||||
|
||||
// 'STR#', 127, 1 => MIME description.
|
||||
info.fMimeDescription = GetPluginString(127, 1);
|
||||
|
||||
// 'STR#', 128, 2 => extensions.
|
||||
info.fExtensions = GetPluginString(128, 2);
|
||||
|
||||
// Determine how many 'STR#' resource for all MIME types/extensions.
|
||||
Handle typeList = ::Get1Resource('STR#', 128);
|
||||
if (typeList != NULL) {
|
||||
@ -179,5 +172,21 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if (info.fPluginInfoSize <= sizeof(nsPluginInfo))
|
||||
{
|
||||
delete[] info.fName;
|
||||
delete[] info.fDescription;
|
||||
int variantCount = info.fVariantCount;
|
||||
for (int i = 0; i < variantCount; i++)
|
||||
{
|
||||
delete[] info.fMimeTypeArray[i];
|
||||
delete[] info.fExtensionArray[i];
|
||||
delete[] info.fMimeDescriptionArray[i];
|
||||
}
|
||||
delete[] info.fMimeTypeArray;
|
||||
delete[] info.fMimeDescriptionArray;
|
||||
delete[] info.fExtensionArray;
|
||||
delete[] info.fFileName;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -65,44 +65,60 @@ static char *LoadRCDATAString( HMODULE hMod, ULONG resid)
|
||||
return string;
|
||||
}
|
||||
|
||||
/* Take a string of the form "foo|bar|baz" and return an */
|
||||
/* array of pointers *into that string* to foo, bar, baz. */
|
||||
/* There may be embedded nulls after | characters, thanks */
|
||||
/* to the way the resource compiler works. Technically */
|
||||
/* the flat string ought to end with a double null, but */
|
||||
/* I'm not checking here. */
|
||||
/* The 'flat' string is altered, ['\0'/'|'] */
|
||||
/* The array returned needs to be PR_Free'd. */
|
||||
/* Also return the size of the array! */
|
||||
static char **BuildStringArray( char *aFlat, PRUint32 &aSize)
|
||||
static PRUint32 CalculateVariantCount(char* mimeTypes)
|
||||
{
|
||||
char **array = 0;
|
||||
PRUint32 variants = 1;
|
||||
|
||||
aSize = 1;
|
||||
/* make two passes through the string 'cos I'm lazy */
|
||||
char *c = aFlat;
|
||||
while( 0 != (c = PL_strchr( c, '|')))
|
||||
{
|
||||
/* skip past <= 1 null char */
|
||||
c++; if( !*c) c++;
|
||||
aSize++;
|
||||
}
|
||||
if(mimeTypes == nsnull)
|
||||
return 0;
|
||||
|
||||
PRInt32 index = 0;
|
||||
char* index = mimeTypes;
|
||||
while (*index)
|
||||
{
|
||||
if (*index == '|')
|
||||
variants++;
|
||||
|
||||
array = (char**) PR_Malloc( aSize * sizeof( char *));
|
||||
++index;
|
||||
}
|
||||
return variants;
|
||||
}
|
||||
|
||||
c = aFlat;
|
||||
static char** MakeStringArray(PRUint32 variants, char* data)
|
||||
{
|
||||
if((variants <= 0) || (data == nsnull))
|
||||
return nsnull;
|
||||
|
||||
for(;;) // do-while-do
|
||||
{
|
||||
array[ index++] = c;
|
||||
c = PL_strchr( c, '|');
|
||||
if( !c) break;
|
||||
*c++ = '\0';
|
||||
}
|
||||
char ** array = (char **)PR_Calloc(variants, sizeof(char *));
|
||||
if(array == nsnull)
|
||||
return nsnull;
|
||||
|
||||
return array;
|
||||
char * start = data;
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
char * p = PL_strchr(start, '|');
|
||||
if(p != nsnull)
|
||||
*p = 0;
|
||||
|
||||
array[i] = PL_strdup(start);
|
||||
start = ++p;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static void FreeStringArray(PRUint32 variants, char ** array)
|
||||
{
|
||||
if((variants == 0) || (array == nsnull))
|
||||
return;
|
||||
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
if(array[i] != nsnull)
|
||||
{
|
||||
PL_strfree(array[i]);
|
||||
array[i] = nsnull;
|
||||
}
|
||||
}
|
||||
PR_Free(array);
|
||||
}
|
||||
|
||||
// nsPluginsDir class
|
||||
@ -188,29 +204,25 @@ nsresult nsPluginFile::GetPluginInfo( nsPluginInfo &info)
|
||||
|
||||
PRUint32 variants = 0;
|
||||
|
||||
// ...mime types...
|
||||
info.fMimeType = LoadRCDATAString( hPlug, NS_INFO_MIMEType);
|
||||
if( nsnull == info.fMimeType) break;
|
||||
info.fMimeTypeArray = BuildStringArray( info.fMimeType, variants);
|
||||
char * mimeType = LoadRCDATAString( hPlug, NS_INFO_MIMEType);
|
||||
if( nsnull == mimeType) break;
|
||||
|
||||
char * mimeDescription = LoadRCDATAString( hPlug, NS_INFO_FileOpenName);
|
||||
if( nsnull == mimeDescription) break;
|
||||
|
||||
char * extensions = LoadRCDATAString( hPlug, NS_INFO_FileExtents);
|
||||
if( nsnull == extensions) break;
|
||||
|
||||
info.fVariantCount = CalculateVariantCount(mimeType);
|
||||
|
||||
info.fMimeTypeArray = MakeStringArray(variants, mimeType);
|
||||
if( info.fMimeTypeArray == nsnull) break;
|
||||
|
||||
// (other lists must be same length as this one)
|
||||
info.fVariantCount = variants;
|
||||
|
||||
// ...bizarre `description' thingy...
|
||||
info.fMimeDescription = LoadRCDATAString( hPlug, NS_INFO_FileOpenName);
|
||||
if( nsnull == info.fMimeDescription) break;
|
||||
info.fMimeDescriptionArray =
|
||||
BuildStringArray( info.fMimeDescription, variants);
|
||||
info.fMimeDescriptionArray = MakeStringArray(variants, mimeDescription);
|
||||
if( nsnull == info.fMimeDescriptionArray) break;
|
||||
if( variants != info.fVariantCount) break;
|
||||
|
||||
// ...file extensions...
|
||||
info.fExtensions = LoadRCDATAString( hPlug, NS_INFO_FileExtents);
|
||||
if( nsnull == info.fExtensions) break;
|
||||
info.fExtensionArray = BuildStringArray( info.fExtensions, variants);
|
||||
if( nsnull == info.fExtensionArray) break;
|
||||
if( variants != info.fVariantCount) break;
|
||||
info.fExtensionArray = MakeStringArray(variants, extensions);
|
||||
if( nsnull == extensionArray) break;
|
||||
|
||||
rc = NS_OK;
|
||||
break;
|
||||
@ -230,23 +242,14 @@ nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
if(info.fMimeType != nsnull)
|
||||
PL_strfree(info.fMimeType);
|
||||
|
||||
if(info.fMimeDescription != nsnull)
|
||||
PL_strfree(info.fMimeDescription);
|
||||
|
||||
if(info.fExtensions != nsnull)
|
||||
PL_strfree(info.fExtensions);
|
||||
|
||||
if(info.fMimeTypeArray != nsnull)
|
||||
PR_Free(info.fMimeTypeArray);
|
||||
FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
|
||||
|
||||
if(info.fMimeDescriptionArray != nsnull)
|
||||
PR_Free(info.fMimeDescriptionArray);
|
||||
FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
|
||||
|
||||
if(info.fExtensionArray != nsnull)
|
||||
PR_Free(info.fExtensionArray);
|
||||
FreeStringArray(info.fVariantCount, info.fExtensionArray);
|
||||
|
||||
memset((void *)&info, 0, sizeof(info));
|
||||
|
||||
|
@ -158,7 +158,7 @@ nsresult nsPluginFile::LoadPlugin(PRLibrary* &outLibrary)
|
||||
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
nsresult rv;
|
||||
const char* mimedescr;
|
||||
const char* mimedescr, *name, *description;
|
||||
char *mdesc,*start,*nexttoc,*mtype,*exten,*descr;
|
||||
int i,num;
|
||||
|
||||
@ -192,14 +192,18 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
}
|
||||
|
||||
if (plugin) {
|
||||
plugin->GetValue(nsPluginVariable_NameString, &info.fName);
|
||||
plugin->GetValue(nsPluginVariable_DescriptionString, &info.fDescription);
|
||||
plugin->GetValue(nsPluginVariable_NameString, &name);
|
||||
info.fName = PL_strdup(name);
|
||||
|
||||
plugin->GetValue(nsPluginVariable_DescriptionString, &description);
|
||||
info.fDescription = PL_strdup(description);
|
||||
|
||||
plugin->GetMIMEDescription(&mimedescr);
|
||||
}
|
||||
else {
|
||||
info.fName = PL_strdup(this->GetCString()); // XXXwaterson LEAK
|
||||
info.fDescription = "";
|
||||
info.fMimeDescription = "";
|
||||
info.fName = PL_strdup(this->GetCString());
|
||||
info.fDescription = PL_strdup("");
|
||||
info.fMimeDescription = PL_strdup("");
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
@ -246,29 +250,41 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n", mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
#endif
|
||||
|
||||
if(i==0) {
|
||||
info.fMimeType = mtype ? mtype : (char *)"";
|
||||
info.fMimeDescription = descr ? descr : (char *)"";
|
||||
info.fExtensions = exten ? exten : (char *)"";
|
||||
}
|
||||
|
||||
if(!*mtype && !descr && !exten) {
|
||||
i--;
|
||||
info.fVariantCount--;
|
||||
} else {
|
||||
info.fMimeTypeArray[i] = mtype ? mtype : (char *)"";
|
||||
info.fMimeDescriptionArray[i] = descr ? descr : (char *)"";
|
||||
info.fExtensionArray[i] = exten ? exten : (char *)"";
|
||||
info.fMimeTypeArray[i] = mtype ? PL_strdup(mtype) : PL_strdup("");
|
||||
info.fMimeDescriptionArray[i] = descr ? PL_strdup(descr) : PL_strdup("");
|
||||
info.fExtensionArray[i] = exten ? PL_strdup(exten) : PL_strdup("");
|
||||
}
|
||||
start=nexttoc;
|
||||
}
|
||||
|
||||
PR_Free(mdesc);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if(info.fName != nsnull)
|
||||
PL_strfree(info.fName);
|
||||
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
for(PRUint32 i = 0; i < info.fVariantCount; i++)
|
||||
{
|
||||
if(info.fMimeTypeArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeTypeArray[i]);
|
||||
|
||||
if(info.fMimeDescriptionArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeDescriptionArray[i]);
|
||||
|
||||
if(info.fExtensionArray[i] != nsnull)
|
||||
PL_strfree(info.fExtensionArray[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -93,32 +93,41 @@ static PRUint32 CalculateVariantCount(char* mimeTypes)
|
||||
|
||||
static char** MakeStringArray(PRUint32 variants, char* data)
|
||||
{
|
||||
char** buffer = NULL;
|
||||
char* index = data;
|
||||
PRUint32 count = 0;
|
||||
|
||||
if((variants == 0) || (data == NULL))
|
||||
if((variants <= 0) || (data == NULL))
|
||||
return NULL;
|
||||
|
||||
buffer = (char **)PR_Calloc(variants, sizeof(char *));
|
||||
if(!buffer)
|
||||
return NULL;
|
||||
buffer[count] = index;
|
||||
++count;
|
||||
char ** array = (char **)PR_Calloc(variants, sizeof(char *));
|
||||
if(array == NULL)
|
||||
return NULL;
|
||||
|
||||
while (*index && count<variants)
|
||||
{
|
||||
if (*index == '|')
|
||||
{
|
||||
buffer[count] = index + 1;
|
||||
++count;
|
||||
*index = 0;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return buffer;
|
||||
char * start = data;
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
char * p = PL_strchr(start, '|');
|
||||
if(p != NULL)
|
||||
*p = 0;
|
||||
|
||||
array[i] = PL_strdup(start);
|
||||
start = ++p;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static void FreeStringArray(PRUint32 variants, char ** array)
|
||||
{
|
||||
if((variants == 0) || (array == NULL))
|
||||
return;
|
||||
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
if(array[i] != NULL)
|
||||
{
|
||||
PL_strfree(array[i]);
|
||||
array[i] = NULL;
|
||||
}
|
||||
}
|
||||
PR_Free(array);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* nsPluginsDir implementation */
|
||||
@ -294,15 +303,19 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
info.fName = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\ProductName");
|
||||
info.fDescription = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileDescription");
|
||||
|
||||
info.fMimeType = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType");
|
||||
info.fMimeDescription = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileOpenName");
|
||||
info.fExtensions = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileExtents");
|
||||
char *mimeType = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType");
|
||||
char *mimeDescription = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileOpenName");
|
||||
char *extensions = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileExtents");
|
||||
|
||||
info.fVariantCount = CalculateVariantCount(info.fMimeType);
|
||||
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, info.fMimeType);
|
||||
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, info.fMimeDescription);
|
||||
info.fExtensionArray = MakeStringArray(info.fVariantCount, info.fExtensions);
|
||||
info.fVariantCount = CalculateVariantCount(mimeType);
|
||||
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, mimeType);
|
||||
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription);
|
||||
info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions);
|
||||
info.fFileName = PL_strdup(path);
|
||||
|
||||
PL_strfree(mimeType);
|
||||
PL_strfree(mimeDescription);
|
||||
PL_strfree(extensions);
|
||||
}
|
||||
else
|
||||
res = NS_ERROR_FAILURE;
|
||||
@ -315,29 +328,23 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if(info.fName != nsnull)
|
||||
if(info.fName != NULL)
|
||||
PL_strfree(info.fName);
|
||||
|
||||
if(info.fDescription != nsnull)
|
||||
if(info.fDescription != NULL)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
if(info.fMimeType != nsnull)
|
||||
PL_strfree(info.fMimeType);
|
||||
if(info.fMimeTypeArray != NULL)
|
||||
FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
|
||||
|
||||
if(info.fMimeDescription != nsnull)
|
||||
PL_strfree(info.fMimeDescription);
|
||||
if(info.fMimeDescriptionArray != NULL)
|
||||
FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
|
||||
|
||||
if(info.fExtensions != nsnull)
|
||||
PL_strfree(info.fExtensions);
|
||||
if(info.fExtensionArray != NULL)
|
||||
FreeStringArray(info.fVariantCount, info.fExtensionArray);
|
||||
|
||||
if(info.fMimeTypeArray != nsnull)
|
||||
PR_Free(info.fMimeTypeArray);
|
||||
|
||||
if(info.fMimeDescriptionArray != nsnull)
|
||||
PR_Free(info.fMimeDescriptionArray);
|
||||
|
||||
if(info.fExtensionArray != nsnull)
|
||||
PR_Free(info.fExtensionArray);
|
||||
if(info.fFileName != NULL)
|
||||
PL_strfree(info.fFileName);
|
||||
|
||||
ZeroMemory((void *)&info, sizeof(info));
|
||||
|
||||
|
@ -58,9 +58,6 @@ struct nsPluginInfo {
|
||||
PRUint32 fPluginInfoSize; // indicates how large the structure is currently.
|
||||
char* fName; // name of the plugin
|
||||
char* fDescription; // etc.
|
||||
char* fMimeType;
|
||||
char* fMimeDescription;
|
||||
char* fExtensions;
|
||||
PRUint32 fVariantCount;
|
||||
char** fMimeTypeArray;
|
||||
char** fMimeDescriptionArray;
|
||||
|
@ -206,12 +206,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n", mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
#endif
|
||||
|
||||
if(i==0) {
|
||||
info.fMimeType = mtype ? mtype : (char *)"";
|
||||
info.fMimeDescription = descr ? descr : (char *)"";
|
||||
info.fExtensions = exten ? exten : (char *)"";
|
||||
}
|
||||
|
||||
if(!*mtype && !descr && !exten) {
|
||||
i--;
|
||||
info.fVariantCount--;
|
||||
@ -229,4 +223,3 @@ nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,9 @@ static char* GetPluginString(short id, short index)
|
||||
*/
|
||||
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
// need to open the plugin's resource file and read some resources.
|
||||
nsCRT::memset(&info, 0, sizeof(info));
|
||||
|
||||
// need to open the plugin's resource file and read some resources.
|
||||
FSSpec spec = *this;
|
||||
Boolean targetIsFolder, wasAliased;
|
||||
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
|
||||
@ -141,15 +143,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
// 'STR#', 126, 1 => plugin description.
|
||||
info.fDescription = GetPluginString(126, 1);
|
||||
|
||||
// 'STR#', 128, 1 => MIME type.
|
||||
info.fMimeType = GetPluginString(128, 1);
|
||||
|
||||
// 'STR#', 127, 1 => MIME description.
|
||||
info.fMimeDescription = GetPluginString(127, 1);
|
||||
|
||||
// 'STR#', 128, 2 => extensions.
|
||||
info.fExtensions = GetPluginString(128, 2);
|
||||
|
||||
// Determine how many 'STR#' resource for all MIME types/extensions.
|
||||
Handle typeList = ::Get1Resource('STR#', 128);
|
||||
if (typeList != NULL) {
|
||||
@ -179,5 +172,21 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if (info.fPluginInfoSize <= sizeof(nsPluginInfo))
|
||||
{
|
||||
delete[] info.fName;
|
||||
delete[] info.fDescription;
|
||||
int variantCount = info.fVariantCount;
|
||||
for (int i = 0; i < variantCount; i++)
|
||||
{
|
||||
delete[] info.fMimeTypeArray[i];
|
||||
delete[] info.fExtensionArray[i];
|
||||
delete[] info.fMimeDescriptionArray[i];
|
||||
}
|
||||
delete[] info.fMimeTypeArray;
|
||||
delete[] info.fMimeDescriptionArray;
|
||||
delete[] info.fExtensionArray;
|
||||
delete[] info.fFileName;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -65,44 +65,60 @@ static char *LoadRCDATAString( HMODULE hMod, ULONG resid)
|
||||
return string;
|
||||
}
|
||||
|
||||
/* Take a string of the form "foo|bar|baz" and return an */
|
||||
/* array of pointers *into that string* to foo, bar, baz. */
|
||||
/* There may be embedded nulls after | characters, thanks */
|
||||
/* to the way the resource compiler works. Technically */
|
||||
/* the flat string ought to end with a double null, but */
|
||||
/* I'm not checking here. */
|
||||
/* The 'flat' string is altered, ['\0'/'|'] */
|
||||
/* The array returned needs to be PR_Free'd. */
|
||||
/* Also return the size of the array! */
|
||||
static char **BuildStringArray( char *aFlat, PRUint32 &aSize)
|
||||
static PRUint32 CalculateVariantCount(char* mimeTypes)
|
||||
{
|
||||
char **array = 0;
|
||||
PRUint32 variants = 1;
|
||||
|
||||
aSize = 1;
|
||||
/* make two passes through the string 'cos I'm lazy */
|
||||
char *c = aFlat;
|
||||
while( 0 != (c = PL_strchr( c, '|')))
|
||||
{
|
||||
/* skip past <= 1 null char */
|
||||
c++; if( !*c) c++;
|
||||
aSize++;
|
||||
}
|
||||
if(mimeTypes == nsnull)
|
||||
return 0;
|
||||
|
||||
PRInt32 index = 0;
|
||||
char* index = mimeTypes;
|
||||
while (*index)
|
||||
{
|
||||
if (*index == '|')
|
||||
variants++;
|
||||
|
||||
array = (char**) PR_Malloc( aSize * sizeof( char *));
|
||||
++index;
|
||||
}
|
||||
return variants;
|
||||
}
|
||||
|
||||
c = aFlat;
|
||||
static char** MakeStringArray(PRUint32 variants, char* data)
|
||||
{
|
||||
if((variants <= 0) || (data == nsnull))
|
||||
return nsnull;
|
||||
|
||||
for(;;) // do-while-do
|
||||
{
|
||||
array[ index++] = c;
|
||||
c = PL_strchr( c, '|');
|
||||
if( !c) break;
|
||||
*c++ = '\0';
|
||||
}
|
||||
char ** array = (char **)PR_Calloc(variants, sizeof(char *));
|
||||
if(array == nsnull)
|
||||
return nsnull;
|
||||
|
||||
return array;
|
||||
char * start = data;
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
char * p = PL_strchr(start, '|');
|
||||
if(p != nsnull)
|
||||
*p = 0;
|
||||
|
||||
array[i] = PL_strdup(start);
|
||||
start = ++p;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static void FreeStringArray(PRUint32 variants, char ** array)
|
||||
{
|
||||
if((variants == 0) || (array == nsnull))
|
||||
return;
|
||||
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
if(array[i] != nsnull)
|
||||
{
|
||||
PL_strfree(array[i]);
|
||||
array[i] = nsnull;
|
||||
}
|
||||
}
|
||||
PR_Free(array);
|
||||
}
|
||||
|
||||
// nsPluginsDir class
|
||||
@ -188,29 +204,25 @@ nsresult nsPluginFile::GetPluginInfo( nsPluginInfo &info)
|
||||
|
||||
PRUint32 variants = 0;
|
||||
|
||||
// ...mime types...
|
||||
info.fMimeType = LoadRCDATAString( hPlug, NS_INFO_MIMEType);
|
||||
if( nsnull == info.fMimeType) break;
|
||||
info.fMimeTypeArray = BuildStringArray( info.fMimeType, variants);
|
||||
char * mimeType = LoadRCDATAString( hPlug, NS_INFO_MIMEType);
|
||||
if( nsnull == mimeType) break;
|
||||
|
||||
char * mimeDescription = LoadRCDATAString( hPlug, NS_INFO_FileOpenName);
|
||||
if( nsnull == mimeDescription) break;
|
||||
|
||||
char * extensions = LoadRCDATAString( hPlug, NS_INFO_FileExtents);
|
||||
if( nsnull == extensions) break;
|
||||
|
||||
info.fVariantCount = CalculateVariantCount(mimeType);
|
||||
|
||||
info.fMimeTypeArray = MakeStringArray(variants, mimeType);
|
||||
if( info.fMimeTypeArray == nsnull) break;
|
||||
|
||||
// (other lists must be same length as this one)
|
||||
info.fVariantCount = variants;
|
||||
|
||||
// ...bizarre `description' thingy...
|
||||
info.fMimeDescription = LoadRCDATAString( hPlug, NS_INFO_FileOpenName);
|
||||
if( nsnull == info.fMimeDescription) break;
|
||||
info.fMimeDescriptionArray =
|
||||
BuildStringArray( info.fMimeDescription, variants);
|
||||
info.fMimeDescriptionArray = MakeStringArray(variants, mimeDescription);
|
||||
if( nsnull == info.fMimeDescriptionArray) break;
|
||||
if( variants != info.fVariantCount) break;
|
||||
|
||||
// ...file extensions...
|
||||
info.fExtensions = LoadRCDATAString( hPlug, NS_INFO_FileExtents);
|
||||
if( nsnull == info.fExtensions) break;
|
||||
info.fExtensionArray = BuildStringArray( info.fExtensions, variants);
|
||||
if( nsnull == info.fExtensionArray) break;
|
||||
if( variants != info.fVariantCount) break;
|
||||
info.fExtensionArray = MakeStringArray(variants, extensions);
|
||||
if( nsnull == extensionArray) break;
|
||||
|
||||
rc = NS_OK;
|
||||
break;
|
||||
@ -230,23 +242,14 @@ nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
if(info.fMimeType != nsnull)
|
||||
PL_strfree(info.fMimeType);
|
||||
|
||||
if(info.fMimeDescription != nsnull)
|
||||
PL_strfree(info.fMimeDescription);
|
||||
|
||||
if(info.fExtensions != nsnull)
|
||||
PL_strfree(info.fExtensions);
|
||||
|
||||
if(info.fMimeTypeArray != nsnull)
|
||||
PR_Free(info.fMimeTypeArray);
|
||||
FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
|
||||
|
||||
if(info.fMimeDescriptionArray != nsnull)
|
||||
PR_Free(info.fMimeDescriptionArray);
|
||||
FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
|
||||
|
||||
if(info.fExtensionArray != nsnull)
|
||||
PR_Free(info.fExtensionArray);
|
||||
FreeStringArray(info.fVariantCount, info.fExtensionArray);
|
||||
|
||||
memset((void *)&info, 0, sizeof(info));
|
||||
|
||||
|
@ -158,7 +158,7 @@ nsresult nsPluginFile::LoadPlugin(PRLibrary* &outLibrary)
|
||||
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
nsresult rv;
|
||||
const char* mimedescr;
|
||||
const char* mimedescr, *name, *description;
|
||||
char *mdesc,*start,*nexttoc,*mtype,*exten,*descr;
|
||||
int i,num;
|
||||
|
||||
@ -192,14 +192,18 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
}
|
||||
|
||||
if (plugin) {
|
||||
plugin->GetValue(nsPluginVariable_NameString, &info.fName);
|
||||
plugin->GetValue(nsPluginVariable_DescriptionString, &info.fDescription);
|
||||
plugin->GetValue(nsPluginVariable_NameString, &name);
|
||||
info.fName = PL_strdup(name);
|
||||
|
||||
plugin->GetValue(nsPluginVariable_DescriptionString, &description);
|
||||
info.fDescription = PL_strdup(description);
|
||||
|
||||
plugin->GetMIMEDescription(&mimedescr);
|
||||
}
|
||||
else {
|
||||
info.fName = PL_strdup(this->GetCString()); // XXXwaterson LEAK
|
||||
info.fDescription = "";
|
||||
info.fMimeDescription = "";
|
||||
info.fName = PL_strdup(this->GetCString());
|
||||
info.fDescription = PL_strdup("");
|
||||
info.fMimeDescription = PL_strdup("");
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
@ -246,29 +250,41 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n", mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
#endif
|
||||
|
||||
if(i==0) {
|
||||
info.fMimeType = mtype ? mtype : (char *)"";
|
||||
info.fMimeDescription = descr ? descr : (char *)"";
|
||||
info.fExtensions = exten ? exten : (char *)"";
|
||||
}
|
||||
|
||||
if(!*mtype && !descr && !exten) {
|
||||
i--;
|
||||
info.fVariantCount--;
|
||||
} else {
|
||||
info.fMimeTypeArray[i] = mtype ? mtype : (char *)"";
|
||||
info.fMimeDescriptionArray[i] = descr ? descr : (char *)"";
|
||||
info.fExtensionArray[i] = exten ? exten : (char *)"";
|
||||
info.fMimeTypeArray[i] = mtype ? PL_strdup(mtype) : PL_strdup("");
|
||||
info.fMimeDescriptionArray[i] = descr ? PL_strdup(descr) : PL_strdup("");
|
||||
info.fExtensionArray[i] = exten ? PL_strdup(exten) : PL_strdup("");
|
||||
}
|
||||
start=nexttoc;
|
||||
}
|
||||
|
||||
PR_Free(mdesc);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if(info.fName != nsnull)
|
||||
PL_strfree(info.fName);
|
||||
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
for(PRUint32 i = 0; i < info.fVariantCount; i++)
|
||||
{
|
||||
if(info.fMimeTypeArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeTypeArray[i]);
|
||||
|
||||
if(info.fMimeDescriptionArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeDescriptionArray[i]);
|
||||
|
||||
if(info.fExtensionArray[i] != nsnull)
|
||||
PL_strfree(info.fExtensionArray[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -93,32 +93,41 @@ static PRUint32 CalculateVariantCount(char* mimeTypes)
|
||||
|
||||
static char** MakeStringArray(PRUint32 variants, char* data)
|
||||
{
|
||||
char** buffer = NULL;
|
||||
char* index = data;
|
||||
PRUint32 count = 0;
|
||||
|
||||
if((variants == 0) || (data == NULL))
|
||||
if((variants <= 0) || (data == NULL))
|
||||
return NULL;
|
||||
|
||||
buffer = (char **)PR_Calloc(variants, sizeof(char *));
|
||||
if(!buffer)
|
||||
return NULL;
|
||||
buffer[count] = index;
|
||||
++count;
|
||||
char ** array = (char **)PR_Calloc(variants, sizeof(char *));
|
||||
if(array == NULL)
|
||||
return NULL;
|
||||
|
||||
while (*index && count<variants)
|
||||
{
|
||||
if (*index == '|')
|
||||
{
|
||||
buffer[count] = index + 1;
|
||||
++count;
|
||||
*index = 0;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return buffer;
|
||||
char * start = data;
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
char * p = PL_strchr(start, '|');
|
||||
if(p != NULL)
|
||||
*p = 0;
|
||||
|
||||
array[i] = PL_strdup(start);
|
||||
start = ++p;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static void FreeStringArray(PRUint32 variants, char ** array)
|
||||
{
|
||||
if((variants == 0) || (array == NULL))
|
||||
return;
|
||||
|
||||
for(PRUint32 i = 0; i < variants; i++)
|
||||
{
|
||||
if(array[i] != NULL)
|
||||
{
|
||||
PL_strfree(array[i]);
|
||||
array[i] = NULL;
|
||||
}
|
||||
}
|
||||
PR_Free(array);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* nsPluginsDir implementation */
|
||||
@ -294,15 +303,19 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
info.fName = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\ProductName");
|
||||
info.fDescription = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileDescription");
|
||||
|
||||
info.fMimeType = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType");
|
||||
info.fMimeDescription = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileOpenName");
|
||||
info.fExtensions = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileExtents");
|
||||
char *mimeType = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType");
|
||||
char *mimeDescription = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileOpenName");
|
||||
char *extensions = GetKeyValue(verbuf, "\\StringFileInfo\\040904E4\\FileExtents");
|
||||
|
||||
info.fVariantCount = CalculateVariantCount(info.fMimeType);
|
||||
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, info.fMimeType);
|
||||
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, info.fMimeDescription);
|
||||
info.fExtensionArray = MakeStringArray(info.fVariantCount, info.fExtensions);
|
||||
info.fVariantCount = CalculateVariantCount(mimeType);
|
||||
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, mimeType);
|
||||
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, mimeDescription);
|
||||
info.fExtensionArray = MakeStringArray(info.fVariantCount, extensions);
|
||||
info.fFileName = PL_strdup(path);
|
||||
|
||||
PL_strfree(mimeType);
|
||||
PL_strfree(mimeDescription);
|
||||
PL_strfree(extensions);
|
||||
}
|
||||
else
|
||||
res = NS_ERROR_FAILURE;
|
||||
@ -315,29 +328,23 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if(info.fName != nsnull)
|
||||
if(info.fName != NULL)
|
||||
PL_strfree(info.fName);
|
||||
|
||||
if(info.fDescription != nsnull)
|
||||
if(info.fDescription != NULL)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
if(info.fMimeType != nsnull)
|
||||
PL_strfree(info.fMimeType);
|
||||
if(info.fMimeTypeArray != NULL)
|
||||
FreeStringArray(info.fVariantCount, info.fMimeTypeArray);
|
||||
|
||||
if(info.fMimeDescription != nsnull)
|
||||
PL_strfree(info.fMimeDescription);
|
||||
if(info.fMimeDescriptionArray != NULL)
|
||||
FreeStringArray(info.fVariantCount, info.fMimeDescriptionArray);
|
||||
|
||||
if(info.fExtensions != nsnull)
|
||||
PL_strfree(info.fExtensions);
|
||||
if(info.fExtensionArray != NULL)
|
||||
FreeStringArray(info.fVariantCount, info.fExtensionArray);
|
||||
|
||||
if(info.fMimeTypeArray != nsnull)
|
||||
PR_Free(info.fMimeTypeArray);
|
||||
|
||||
if(info.fMimeDescriptionArray != nsnull)
|
||||
PR_Free(info.fMimeDescriptionArray);
|
||||
|
||||
if(info.fExtensionArray != nsnull)
|
||||
PR_Free(info.fExtensionArray);
|
||||
if(info.fFileName != NULL)
|
||||
PL_strfree(info.fFileName);
|
||||
|
||||
ZeroMemory((void *)&info, sizeof(info));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user