From 66558170735022e8583adf8b4d83da702c1a223e Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Fri, 6 Oct 2006 20:18:33 +0000 Subject: [PATCH] Fix minor issues for Firefox on Windows. --- CASA/adlib/AD_Facade.cs | 37 ++--- CASA/adlib/ad_ff/FireFox.cs | 30 ++++ .../ad_ff/native/FirefoxPasswordManager.cpp | 143 ++++++++---------- .../ad_ff/native/FirefoxPasswordManager.h | 9 +- 4 files changed, 123 insertions(+), 96 deletions(-) diff --git a/CASA/adlib/AD_Facade.cs b/CASA/adlib/AD_Facade.cs index 91e61600..d7156e78 100644 --- a/CASA/adlib/AD_Facade.cs +++ b/CASA/adlib/AD_Facade.cs @@ -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; } diff --git a/CASA/adlib/ad_ff/FireFox.cs b/CASA/adlib/ad_ff/FireFox.cs index 583c9e4d..4e58412e 100644 --- a/CASA/adlib/ad_ff/FireFox.cs +++ b/CASA/adlib/ad_ff/FireFox.cs @@ -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];; diff --git a/CASA/adlib/ad_ff/native/FirefoxPasswordManager.cpp b/CASA/adlib/ad_ff/native/FirefoxPasswordManager.cpp index 95e9e704..5e6071de 100644 --- a/CASA/adlib/ad_ff/native/FirefoxPasswordManager.cpp +++ b/CASA/adlib/ad_ff/native/FirefoxPasswordManager.cpp @@ -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