Fix minor issues for Firefox on Windows.

This commit is contained in:
Jim Norman 2006-10-06 20:18:33 +00:00
parent 665c251e3b
commit 6655817073
4 changed files with 123 additions and 96 deletions

View File

@ -145,6 +145,22 @@ namespace Novell.CASA.DataEngines
Logger.DbgLog("A-D Lib:Failed to Connect to miCASA");
#endif
}
if (ffEngine != null)
{
XmlNode ffSecrets = ffEngine.Aggregate();
if( null != ffSecrets )
{
XmlNode ffImportedNode = ccf.ImportNode(ffSecrets,true);
ccf.DocumentElement.AppendChild(ffImportedNode);
}
else
{
#if LINUX
Logger.DbgLog("A-D Lib:Failed to Connect to Gnome FireFox");
#endif
}
}
#if LINUX
if (gkEngine != null)
@ -178,20 +194,6 @@ namespace Novell.CASA.DataEngines
}
}
if (ffEngine != null)
{
XmlNode ffSecrets = ffEngine.Aggregate();
if( null != ffSecrets )
{
XmlNode ffImportedNode = ccf.ImportNode(ffSecrets,true);
ccf.DocumentElement.AppendChild(ffImportedNode);
}
else
{
Logger.DbgLog("A-D Lib:Failed to Connect to Gnome FireFox");
}
}
else
Logger.DbgLog("A-D Lib:Could not aggregate Gnome FireFox since FireFoxEngine not instantiated");
@ -362,14 +364,15 @@ namespace Novell.CASA.DataEngines
{
if (StoreID == ConstStrings.CASA_STORE_MICASA)
return micasaengine.Remove(secret);
return micasaengine.Remove(secret);
if (StoreID == ConstStrings.CASA_STORE_FFOX)
return ffEngine.Remove(secret);
#if LINUX
if (StoreID == ConstStrings.CASA_STORE_KWALLET)
return kwEngine.Remove(secret);
if (StoreID == ConstStrings.CASA_STORE_GK)
return gkEngine.Remove(secret);
if (StoreID == ConstStrings.CASA_STORE_FFOX)
return ffEngine.Remove(secret);
#endif
return -1;
}

View File

@ -142,6 +142,7 @@ namespace Novell.CASA.DataEngines.FF
{
private static int MAX_PROFILES = 5; //FIXME:Maximum Profiles for Firefox - To be removed when done dynamically via a native api
private static int LOAD_PROFILE_ALWAYSFROM_FILE = 1;
private static int MAX_PROFILE_LEN = 260;
#if WIN32
private const string FF_LIB = "ad_ff.dll";
@ -152,6 +153,10 @@ namespace Novell.CASA.DataEngines.FF
//Initialization functions
[DllImport(FF_LIB)]
public static extern int FPM_GetDefaultProfileName([In, Out] byte[] profileName);
[DllImport(FF_LIB)]
public static extern int FPM_GetProfileList(out IntPtr[] profileList, out IntPtr[] profileFlag);
@ -216,6 +221,31 @@ namespace Novell.CASA.DataEngines.FF
// else null if not retrivable
//--------------------------------------------------------------
public static String GetDefaultProfileName()
{
byte[] baProfileName = new byte[MAX_PROFILE_LEN];
int profCount = FPM_GetDefaultProfileName(baProfileName);
if (profCount == 0)
return null;
else
{
string sName = System.Text.Encoding.Default.GetString(baProfileName);
char[] NullChars = new char[1];
NullChars[0] = '\0';
return sName.TrimEnd(NullChars);
}
}
//--------------------------------------------------------------
//GetDefaultProfileName
//@param None
//@return Default ProfileName on success
// else null if not retrivable
//--------------------------------------------------------------
public static String GetDefaultProfileNameEx()
{
IntPtr[] profileListIntPtr=new IntPtr[MAX_PROFILES];;

View File

@ -137,7 +137,36 @@ int CreateNewProfile(char *profilePath, char *profileDir)
return FPM_TRUE;
}
extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int *profileFlag[])
extern "C" APIEXPORT int FPM_GetDefaultProfileName(char *defaultProfileName)
{
int i = 0;
int profCount = MAX_PROFILE_COUNT;
Profile *profiles;
profiles = (Profile*)malloc(MAX_PROFILE_COUNT * sizeof(Profile));
profCount = FPM_GetProfileList(profiles, &profCount);
if (profCount > 0)
{
// find the default profile
for(i=0; i< profCount; i++)
{
if (profiles[i].isDefault == 1)
{
memcpy(defaultProfileName, profiles[i].profileName, profiles[i].nameLen);
}
}
}
// free the list
free(profiles);
return profCount;
}
extern "C" APIEXPORT int FPM_GetProfileList(Profile *profiles, int *count)
{
#ifdef WIN32
@ -288,91 +317,49 @@ extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int *profileFl
}
if( strstr(line, "name=") != NULL )
profileCount++;
{
// found one, copy it
char *temp = strchr(line,'=') + 1;
int len = strlen(temp) + 1;
// make sure the profile name length is not too long.
if (len < MAX_PATH)
{
// make sure we have room
if (*count > profileCount)
{
profiles[profileCount].nameLen = len;
memcpy(profiles[profileCount].profileName, temp,len);
profiles[profileCount].isDefault = 0;
}
profileCount++;
}
}
// check if the current profile is default
if( strstr(line, "default=1") != NULL )
{
if (*count > profileCount-1)
{
profiles[profileCount-1].isDefault = 1;
}
}
}
// if only one profile, set it default
if (profileCount == 1)
{
profiles[0].isDefault = 1;
}
PrintMessage(MESG_DEBUG, "\n GetProfileList : Total profiles found = %d ", profileCount);
if( profileCount == 0 )
{
fclose(profile);
return FPM_FALSE;
}
*profileList = ( char**) malloc(profileCount * sizeof (char *));
*profileFlag = ( int * ) malloc(profileCount * sizeof(int));
if( *profileList == NULL || *profileFlag == NULL )
{
PrintMessage(MESG_ERROR, "\n GetProfileList : Insufficient memory ");
fclose(profile);
return FPM_FALSE;
}
char **profList = *profileList;
int *profFlag = *profileFlag;
// Now read the profile names and store it..
fseek(profile, 0, SEEK_SET);
profileCount = 0;
while(fgets(line, 1024, profile))
{
// Remove trailing end of line character
line[strlen(line)-1]= 0;
// Convert to smaller case until "=" found....
for(i=0; i<strlen(line); i++)
{
if( line[i] == '=' )
break;
if( line[i] >=65 && line[i]<=90 )
line[i]+=32;
}
if( strstr(line, "name=") != NULL )
{
char *temp = strchr(line,'=') + 1;
profList[profileCount] = (char*) malloc(strlen(temp)+1);
if( profList[profileCount] == NULL )
{
PrintMessage(MESG_ERROR, "\n GetProfileList : Insufficient memory ");
fclose(profile);
return 0;
}
strcpy(profList[profileCount],temp);
profFlag[profileCount] = 0;
PrintMessage(MESG_DEBUG, "\n GetProfileList : Found profile = [%s]", profList[profileCount]);
profileCount++;
continue;
}
// check if the current profile is default
if( strstr(line, "default=1") != NULL )
{
profFlag[profileCount-1] = 1;
}
}
// all done
fclose(profile);
// if there is only one profile then set it default profile
if( profileCount == 1 )
{
**profileFlag = 1;
}
return profileCount;
}
/**
* Initializes the firefox library with the specified profile
*

View File

@ -110,6 +110,13 @@ typedef enum SECItemType
siGeneralizedTime = 12
};
typedef struct _profile
{
int nameLen;
char profileName[MAX_PATH];
int isDefault;
} Profile;
//typedef struct SECItemStr SECItem;
struct SECItem
@ -170,7 +177,7 @@ int CreateDirectory( char *path );
// Profile initiliazation functions
extern "C" APIEXPORT int FPM_IsStoreAvailable();
extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int **profileFlag);
extern "C" APIEXPORT int FPM_GetProfileList(Profile *profiles, int *count);
extern "C" APIEXPORT int FPM_FirefoxProfileInit(char *profileName);
extern "C" APIEXPORT int FPM_FirefoxProfileExit(char *profileName);