Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsDogbertProfileMigrator.cpp File Reference
#include "nsMailProfileMigratorUtils.h"
#include "nsCRT.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIObserverService.h"
#include "nsIPasswordManagerInternal.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsDogbertProfileMigrator.h"
#include "nsIRelativeFilePref.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsVoidArray.h"
#include "prprf.h"
#include "prmem.h"
#include "prio.h"
#include "prenv.h"
#include "NSReg.h"
#include "nsICharsetConverterManager.h"
#include "nsIPlatformCharset.h"
#include "nsIPref.h"
#include "nsIFileSpec.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"

Go to the source code of this file.

Classes

struct  PrefBranchStruct
struct  PrefEnumerationClosure
union  PrefBranchStruct.__unnamed__

Defines

#define MIGRATION_PROPERTIES_URL   "chrome://messenger/locale/migration/migration.properties"
#define MAXPATHLEN   1024
#define PREF_FILE_NAME_IN_4x   "prefs.js"
#define IMAP_MAIL_FILTER_FILE_NAME_IN_4x   "rules.dat"
#define POP_MAIL_FILTER_FILE_NAME_IN_4x   "rules.dat"
#define MAIL_SUMMARY_SUFFIX_IN_4x   ".snm"
#define NEWS_SUMMARY_SUFFIX_IN_4x   ".snm"
#define OLDREG_NAME   "nsreg.dat"
#define OLDREG_DIR   NS_OS2_DIR
#define PSM_CERT7_DB   "cert7.db"
#define PSM_KEY3_DB   "key3.db"
#define PSM_SECMODULE_DB   "secmod.db"
#define SUMMARY_SUFFIX_IN_5x   ".msf"
#define IMAP_MAIL_FILTER_FILE_NAME_IN_5x   "rules.dat"
#define POP_MAIL_FILTER_FILE_NAME_IN_5x   "rules.dat"
#define POPSTATE_FILE_IN_5x   "popstate.dat"
#define PREMIGRATION_PREFIX   "premigration."
#define ADDRBOOK_FILE_EXTENSION_IN_4X   ".na2"
#define PREF_FILE_HEADER_STRING   "# Mozilla User Preferences "
#define MAX_PREF_LEN   1024
#define PREF_MIGRATION_MODE_FOR_MAIL   "mail.migration.copyMailFiles"
#define PREF_MAIL_DIRECTORY   "mail.directory"
#define PREF_NEWS_DIRECTORY   "news.directory"
#define PREF_MAIL_IMAP_ROOT_DIR   "mail.imap.root_dir"
#define PREF_NETWORK_HOSTS_POP_SERVER   "network.hosts.pop_server"
#define PREF_4X_NETWORK_HOSTS_IMAP_SERVER   "network.hosts.imap_servers"
#define PREF_MAIL_SERVER_TYPE   "mail.server_type"
#define PREF_BROWSER_CACHE_DIRECTORY   "browser.cache.directory"
#define POP_4X_MAIL_TYPE   0
#define IMAP_4X_MAIL_TYPE   1
#define OLD_MAIL_DIR_NAME   "Mail"
#define OLD_NEWS_DIR_NAME   "News"
#define OLD_IMAPMAIL_DIR_NAME   "ImapMail"
#define NEW_MAIL_DIR_NAME   "Mail"
#define NEW_NEWS_DIR_NAME   "News"
#define NEW_IMAPMAIL_DIR_NAME   "ImapMail"
#define NEW_LOCAL_MAIL_DIR_NAME   "Local Folders"
#define NEW_DIR_SUFFIX   "5"
#define PREF_FILE_NAME_IN_5x   "prefs.js"

Functions

static NS_DEFINE_CID (kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID)
static NS_DEFINE_CID (kPrefServiceCID, NS_PREF_CID)
static NS_DEFINE_CID (kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID)
static PRBool nsCStringEndsWith (nsCString &name, const char *ending)
static nsresult ConvertStringToUTF8 (const char *aCharset, const char *inString, char **outString)
nsresult ConvertPrefToUTF8 (const char *prefname, nsIPref *prefs, const char *charSet)
static PRBool charEndsWith (const char *str, const char *endStr)
static void fontPrefEnumerationFunction (const char *name, void *data)
static void ldapPrefEnumerationFunction (const char *name, void *data)
static void vCardPrefEnumerationFunction (const char *name, void *data)
PRBool convertPref (nsCString &aElement, void *aData)

Variables

static const char * prefsToConvert []

Class Documentation

struct PrefBranchStruct

Definition at line 216 of file nsDogbertProfileMigrator.cpp.

Class Members
union PrefBranchStruct __unnamed__
union PrefBranchStruct __unnamed__
char * prefName
PRInt32 type
struct PrefEnumerationClosure

Definition at line 2296 of file nsDogbertProfileMigrator.cpp.

Collaboration diagram for PrefEnumerationClosure:
Class Members
const char * charSet
nsIPref * prefs
union PrefBranchStruct.__unnamed__

Definition at line 219 of file nsDogbertProfileMigrator.cpp.

Class Members
PRBool boolValue
PRInt32 intValue
char * stringValue
PRUnichar * wstringValue

Define Documentation

Definition at line 146 of file nsDogbertProfileMigrator.cpp.

Definition at line 177 of file nsDogbertProfileMigrator.cpp.

Definition at line 117 of file nsDogbertProfileMigrator.cpp.

Definition at line 136 of file nsDogbertProfileMigrator.cpp.

Definition at line 119 of file nsDogbertProfileMigrator.cpp.

#define MAX_PREF_LEN   1024

Definition at line 148 of file nsDogbertProfileMigrator.cpp.

#define MAXPATHLEN   1024

Definition at line 82 of file nsDogbertProfileMigrator.cpp.

#define MIGRATION_PROPERTIES_URL   "chrome://messenger/locale/migration/migration.properties"

Definition at line 74 of file nsDogbertProfileMigrator.cpp.

Definition at line 205 of file nsDogbertProfileMigrator.cpp.

#define NEW_IMAPMAIL_DIR_NAME   "ImapMail"

Definition at line 202 of file nsDogbertProfileMigrator.cpp.

#define NEW_LOCAL_MAIL_DIR_NAME   "Local Folders"

Definition at line 203 of file nsDogbertProfileMigrator.cpp.

#define NEW_MAIL_DIR_NAME   "Mail"

Definition at line 200 of file nsDogbertProfileMigrator.cpp.

#define NEW_NEWS_DIR_NAME   "News"

Definition at line 201 of file nsDogbertProfileMigrator.cpp.

Definition at line 120 of file nsDogbertProfileMigrator.cpp.

#define OLD_IMAPMAIL_DIR_NAME   "ImapMail"

Definition at line 197 of file nsDogbertProfileMigrator.cpp.

#define OLD_MAIL_DIR_NAME   "Mail"

Definition at line 195 of file nsDogbertProfileMigrator.cpp.

#define OLD_NEWS_DIR_NAME   "News"

Definition at line 196 of file nsDogbertProfileMigrator.cpp.

#define OLDREG_DIR   NS_OS2_DIR

Definition at line 125 of file nsDogbertProfileMigrator.cpp.

#define OLDREG_NAME   "nsreg.dat"

Definition at line 121 of file nsDogbertProfileMigrator.cpp.

Definition at line 176 of file nsDogbertProfileMigrator.cpp.

Definition at line 118 of file nsDogbertProfileMigrator.cpp.

Definition at line 137 of file nsDogbertProfileMigrator.cpp.

#define POPSTATE_FILE_IN_5x   "popstate.dat"

Definition at line 138 of file nsDogbertProfileMigrator.cpp.

#define PREF_4X_NETWORK_HOSTS_IMAP_SERVER   "network.hosts.imap_servers"

Definition at line 173 of file nsDogbertProfileMigrator.cpp.

#define PREF_BROWSER_CACHE_DIRECTORY   "browser.cache.directory"

Definition at line 175 of file nsDogbertProfileMigrator.cpp.

#define PREF_FILE_HEADER_STRING   "# Mozilla User Preferences "

Definition at line 147 of file nsDogbertProfileMigrator.cpp.

#define PREF_FILE_NAME_IN_4x   "prefs.js"

Definition at line 116 of file nsDogbertProfileMigrator.cpp.

#define PREF_FILE_NAME_IN_5x   "prefs.js"

Definition at line 206 of file nsDogbertProfileMigrator.cpp.

#define PREF_MAIL_DIRECTORY   "mail.directory"

Definition at line 169 of file nsDogbertProfileMigrator.cpp.

#define PREF_MAIL_IMAP_ROOT_DIR   "mail.imap.root_dir"

Definition at line 171 of file nsDogbertProfileMigrator.cpp.

#define PREF_MAIL_SERVER_TYPE   "mail.server_type"

Definition at line 174 of file nsDogbertProfileMigrator.cpp.

#define PREF_MIGRATION_MODE_FOR_MAIL   "mail.migration.copyMailFiles"

Definition at line 168 of file nsDogbertProfileMigrator.cpp.

#define PREF_NETWORK_HOSTS_POP_SERVER   "network.hosts.pop_server"

Definition at line 172 of file nsDogbertProfileMigrator.cpp.

#define PREF_NEWS_DIRECTORY   "news.directory"

Definition at line 170 of file nsDogbertProfileMigrator.cpp.

#define PREMIGRATION_PREFIX   "premigration."

Definition at line 145 of file nsDogbertProfileMigrator.cpp.

#define PSM_CERT7_DB   "cert7.db"

Definition at line 130 of file nsDogbertProfileMigrator.cpp.

#define PSM_KEY3_DB   "key3.db"

Definition at line 131 of file nsDogbertProfileMigrator.cpp.

#define PSM_SECMODULE_DB   "secmod.db"

Definition at line 132 of file nsDogbertProfileMigrator.cpp.

Definition at line 135 of file nsDogbertProfileMigrator.cpp.


Function Documentation

static PRBool charEndsWith ( const char *  str,
const char *  endStr 
) [static]

Definition at line 2250 of file nsDogbertProfileMigrator.cpp.

{
  PRUint32 endStrLen = PL_strlen(endStr);
  PRUint32 strLen = PL_strlen(str);
    
  if (strLen < endStrLen) return PR_FALSE;

  PRUint32 pos = strLen - endStrLen;
  if (PL_strncmp(str + pos, endStr, endStrLen) == 0)
    return PR_TRUE;
  else 
    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool convertPref ( nsCString aElement,
void aData 
)

Definition at line 2301 of file nsDogbertProfileMigrator.cpp.

{
  PrefEnumerationClosure *closure;
  closure = (PrefEnumerationClosure *)aData;

  ConvertPrefToUTF8(aElement.get(), closure->prefs, closure->charSet);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult ConvertPrefToUTF8 ( const char *  prefname,
nsIPref prefs,
const char *  charSet 
)

Definition at line 2229 of file nsDogbertProfileMigrator.cpp.

{
  nsresult rv;

  if (!prefname || !prefs) return NS_ERROR_FAILURE;  
  nsXPIDLCString prefval;

  rv = prefs->CopyCharPref(prefname, getter_Copies(prefval));
  if (NS_FAILED(rv)) return rv;

  if (prefval.IsEmpty()) 
    return NS_OK;

  nsXPIDLCString outval;
  rv = ConvertStringToUTF8(charSet, (const char *)prefval, getter_Copies(outval));
  // only set the pref if the conversion worked, and it convert to something non null
  if (NS_SUCCEEDED(rv) && (const char *)outval && PL_strlen((const char *)outval)) 
    rv = prefs->SetCharPref(prefname, (const char *)outval);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ConvertStringToUTF8 ( const char *  aCharset,
const char *  inString,
char **  outString 
) [static]

Definition at line 2188 of file nsDogbertProfileMigrator.cpp.

{
  if (nsnull == outString)
    return NS_ERROR_NULL_POINTER;

  nsresult rv;
  // convert result to unicode
  nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(kCharsetConverterManagerCID, &rv);

  if(NS_SUCCEEDED(rv)) {
    nsCOMPtr <nsIUnicodeDecoder> decoder; // this may be cached

    rv = ccm->GetUnicodeDecoderRaw(aCharset, getter_AddRefs(decoder));
    if(NS_SUCCEEDED(rv) && decoder) {
      PRInt32 uniLength = 0;
      PRInt32 srcLength = strlen(inString);
      rv = decoder->GetMaxLength(inString, srcLength, &uniLength);
      if (NS_SUCCEEDED(rv)) {
        PRUnichar *unichars = new PRUnichar [uniLength];

        if (nsnull != unichars) {
          // convert to unicode
          rv = decoder->Convert(inString, &srcLength, unichars, &uniLength);
          if (NS_SUCCEEDED(rv)) {
            nsAutoString aString;
            aString.Assign(unichars, uniLength);
            // convert to UTF-8
            *outString = ToNewUTF8String(aString);
          }
          delete [] unichars;
        }
        else {
          rv = NS_ERROR_OUT_OF_MEMORY;
        }
      }
    }    
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void fontPrefEnumerationFunction ( const char *  name,
void data 
) [static]

Definition at line 2264 of file nsDogbertProfileMigrator.cpp.

{
  nsCStringArray *arr;
  arr = (nsCStringArray *)data;
  if (charEndsWith(name,".fixed_font") || charEndsWith(name,".prop_font")) {
    nsCString str(name);
    arr->AppendCString(str);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ldapPrefEnumerationFunction ( const char *  name,
void data 
) [static]

Definition at line 2274 of file nsDogbertProfileMigrator.cpp.

{
  nsCStringArray *arr;
  arr = (nsCStringArray *)data;
  // we only want to convert "ldap_2.servers.*.description"
  if (charEndsWith(name,".description")) {
    nsCString str(name);
    arr->AppendCString(str);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kCharsetConverterManagerCID  ,
NS_ICHARSETCONVERTERMANAGER_CID   
) [static]
static NS_DEFINE_CID ( kPrefServiceCID  ,
NS_PREF_CID   
) [static]
static NS_DEFINE_CID ( kStringBundleServiceCID  ,
NS_STRINGBUNDLESERVICE_CID   
) [static]
static PRBool nsCStringEndsWith ( nsCString name,
const char *  ending 
) [static]

Definition at line 2119 of file nsDogbertProfileMigrator.cpp.

{
  if (!ending) return PR_FALSE;

  PRInt32 len = name.Length();
  if (len == 0) return PR_FALSE;

  PRInt32 endingLen = PL_strlen(ending);
  if (len > endingLen && name.RFind(ending, PR_TRUE) == len - endingLen) {
        return PR_TRUE;
  }
  else {
        return PR_FALSE;
  }
}

Here is the caller graph for this function:

static void vCardPrefEnumerationFunction ( const char *  name,
void data 
) [static]

Definition at line 2285 of file nsDogbertProfileMigrator.cpp.

{
  nsCStringArray *arr;
  arr = (nsCStringArray *)data;

  // the 4.x vCard prefs might need converting
  nsCString str(name);
  arr->AppendCString(str);
}

Here is the caller graph for this function:


Variable Documentation

const char* prefsToConvert[] [static]
Initial value:
 {
      "li.server.ldap.userbase",
      "mail.identity.organization",
      "mail.identity.username",
      nsnull
}

Definition at line 2173 of file nsDogbertProfileMigrator.cpp.