Fix for bug 79252. This fixes the migration from 4.x format to mozilla format. r=dmose, sr=sspitzer, a=dbaron

git-svn-id: svn://10.0.0.236/trunk@97582 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
srilatha%netscape.com 2001-06-20 06:51:37 +00:00
parent b539354e4b
commit b207e98e6f
14 changed files with 332 additions and 59 deletions

View File

@ -1908,6 +1908,7 @@ sub BuildMailNewsProjects()
# $D becomes a suffix to target names for selecting either the debug or non-debug target of a project
my($D) = $main::DEBUG ? "Debug" : "";
my($dist_dir) = GetBinDirectory();
StartBuildModule("mailnews");
@ -1928,6 +1929,8 @@ sub BuildMailNewsProjects()
BuildOneProject(":mozilla:mailnews:import:macbuild:msgImport.mcp", "msgImport$D.shlb", 1, $main::ALIAS_SYM_FILES, 1);
BuildOneProject(":mozilla:mailnews:import:text:macbuild:msgImportText.mcp", "msgImportText$D.shlb", 1, $main::ALIAS_SYM_FILES, 1);
BuildOneProject(":mozilla:mailnews:import:eudora:macbuild:msgImportEudora.mcp", "msgImportEudora$D.shlb", 1, $main::ALIAS_SYM_FILES, 1);
InstallResources(":mozilla:mailnews:addrbook:src:MANIFEST_COMPONENTS", "${dist_dir}Components");
EndBuildModule("mailnews");
}

View File

@ -26,6 +26,12 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef MOZ_LDAP_XPCOM
REQUIRES += mozldap necko
install::
$(INSTALL) ./src/nsLDAPPrefsService.js $(DIST)/bin/components
endif
DIRS = public src build
include $(topsrcdir)/config/rules.mk

View File

@ -23,6 +23,11 @@ DEPTH=..\..
include <$(DEPTH)\config\config.mak>
!if !defined(DISABLE_LDAP)
install::
$(MAKE_INSTALL) .\src\nsLDAPPrefsService.js $(DIST)\bin\components
!endif
DIRS=public src prefs build
include <$(DEPTH)\config\rules.mak>

View File

@ -9,6 +9,11 @@ var gFromGlobalPref = false;
var gUpdate = false;
var gDeletedDirectories = new Array();
var gLDAPPrefsService = Components.classes[
"@mozilla.org/ldapprefs-service;1"].getService();
gLDAPPrefsService = gLDAPPrefsService.QueryInterface(
Components.interfaces.nsILDAPPrefsService);
function onEditDirectories()
{
var args = {fromGlobalPref: gFromGlobalPref};
@ -87,63 +92,6 @@ function createDirectoriesList(flag)
}
}
function migrate(pref_string)
{
if (!gPrefInt) {
try {
gPrefInt = Components.classes["@mozilla.org/preferences;1"];
gPrefInt = gPrefInt.getService(Components.interfaces.nsIPref);
}
catch (ex) {
gPrefInt = null;
}
}
try{
var migrated = gPrefInt.GetBoolPref("ldap_2.prefs_migrated");
}
catch(ex){
migrated = false;
}
if (!migrated) {
try {
var ldapUrl = Components.classes["@mozilla.org/network/ldap-url;1"];
ldapUrl = ldapUrl.getService(Components.interfaces.nsILDAPURL);
}
catch (ex) {
ldapUrl = null;
}
try {
var ldapService = Components.classes[
"@mozilla.org/network/ldap-service;1"].
getService(Components.interfaces.nsILDAPService);
}
catch (ex)
{
dump("failed to get ldapService \n");
ldapService = null;
}
try{
ldapUrl.host = gPrefInt.CopyCharPref(pref_string + ".serverName");
if(ldapService) {
var base = gPrefInt.CopyUnicharPref(pref_string + ".searchBase");
ldapUrl.dn = ldapService.UCS2toUTF8(base);
}
}
catch(ex) {
}
try {
var port = gPrefInt.CopyCharPref(pref_string + ".port");
}
catch(ex) {
port = 389;
}
ldapUrl.port = port;
ldapUrl.scope = 0;
gPrefInt.SetUnicharPref(pref_string + ".uri", ldapUrl.spec);
gPrefInt.SetBoolPref("ldap_2.prefs_migrated", true);
}
}
function LoadDirectories(popup)
{
var children;
@ -198,7 +146,6 @@ function LoadDirectories(popup)
item.setAttribute("value", arrayOfDirectories[i]);
popup.appendChild(item);
}
migrate(arrayOfDirectories[i]);
gAvailDirectories[j] = new Array(2);
gAvailDirectories[j][0] = arrayOfDirectories[i];
gAvailDirectories[j][1] = description;

View File

@ -45,6 +45,10 @@ XPIDLSRCS = \
nsIAbUpgrader.idl \
nsIAddbookUrl.idl \
$(NULL)
ifdef MOZ_LDAP_XPCOM
XPIDLSRCS += nsILDAPPrefsService.idl \
endif
include $(topsrcdir)/config/rules.mk

View File

@ -38,6 +38,9 @@ XPIDLSRCS = \
.\nsIAbAddressCollecter.idl \
.\nsIAbUpgrader.idl \
.\nsIAddbookUrl.idl \
!if !defined(DISABLE_LDAP)
.\nsILDAPPrefsService.idl \
!endif
$(NULL)

View File

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*
* nsILDAPPrefsService.idl
*/
#include "nsISupports.idl"
#include "nsILDAPURL.idl"
#include "nsILDAPService.idl"
/**
* this service implements migrating ldap prefs from 4.x format
* to mozilla format.
*/
[scriptable, uuid(5a4911e0-44cd-11d5-9074-0010a4b26cda)]
interface nsILDAPPrefsService: nsISupports {
/**
* Convert 4.x ldap prefs to mozilla format
* hostname, dn, scope, port are converted to uri
* Also converts the autocompletion preference from 4.x format
* (ldap_2.servers.<server-name>.autocomplete.enabled)
* to mozilla format (ldap_2.servers.directoryServer)
*/
void migrate();
};

View File

@ -0,0 +1 @@
nsLDAPPrefsService.js

View File

@ -0,0 +1,250 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Srilatha Moturi <srilatha@netscape.com>
*/
/* components defined in this file */
const NS_LDAPPREFSSERVICE_CONTRACTID =
"@mozilla.org/ldapprefs-service;1";
const NS_LDAPPREFSSERVICE_CID =
Components.ID("{5a4911e0-44cd-11d5-9074-0010a4b26cda}");
const NS_LDAPPREFSSERVICE_IID = Components.interfaces.nsILDAPPrefsService;
/* interfaces used in this file */
const nsISupports = Components.interfaces.nsISupports;
const nsIPref = Components.interfaces.nsIPref;
const nsILDAPURL = Components.interfaces.nsILDAPURL;
const nsILDAPService = Components.interfaces.nsILDAPService;
/* nsLDAPPrefs service */
function nsLDAPPrefsService() {
var arrayOfDirectories = null;
var j = 0;
try {
gPrefInt = Components.classes["@mozilla.org/preferences;1"];
gPrefInt = gPrefInt.getService(nsIPref);
}
catch (ex) {
dump("failed to get prefs service!\n");
return;
}
/* generate the list of directory servers from preferences */
var children = gPrefInt.CreateChildList("ldap_2.servers");
if(children) {
arrayOfDirectories = children.split(';');
this.availDirectories = new Array();
var position;
var description;
for (var i=0; i<arrayOfDirectories.length; i++)
{
if ((arrayOfDirectories[i] != "ldap_2.servers.pab") &&
(arrayOfDirectories[i] != "ldap_2.servers.history")) {
try{
position = gPrefInt.GetIntPref(arrayOfDirectories[i]+".position");
}
catch(ex){
position = 1;
}
try{
dirType = gPrefInt.GetIntPref(arrayOfDirectories[i]+".dirType");
}
catch(ex){
dirType = 1;
}
if ((position != 0) && (dirType == 1)) {
try{
description = gPrefInt.CopyUnicharPref(arrayOfDirectories[i]+".description");
}
catch(ex){
description = null;
}
if (description) {
this.availDirectories[j] = new Array(2);
this.availDirectories[j][0] = arrayOfDirectories[i];
this.availDirectories[j][1] = description;
j++;
}
}
}
}
}
this.migrate();
}
nsLDAPPrefsService.prototype.prefs_migrated = false;
nsLDAPPrefsService.prototype.availDirectories = null;
nsLDAPPrefsService.prototype.QueryInterface =
function (iid) {
if (!iid.equals(nsISupports) &&
!iid.equals(NS_LDAPPREFSSERVICE_IID))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
/* migrate 4.x ldap prefs to mozilla format.
Converts hostname, basedn, port to uri (nsLDAPURL).
*/
nsLDAPPrefsService.prototype.migrate =
function () {
var pref_string;
var ldapUrl=null;
var enable = false;
if (this.prefs_migrated) return;
var gPrefInt = null;
var host;
var dn;
try {
gPrefInt = Components.classes["@mozilla.org/preferences;1"];
gPrefInt = gPrefInt.getService(Components.interfaces.nsIPref);
}
catch (ex) {
dump("failed to get prefs service!\n");
return;
}
var migrated = false;
try{
migrated = gPrefInt.GetBoolPref("ldap_2.prefs_migrated");
}
catch(ex){}
if (migrated){
this.prefs_migrated = true;
return;
}
try{
var useDirectory = gPrefInt.GetBoolPref("ldap_2.servers.useDirectory");
}
catch(ex) {}
try {
var ldapService = Components.classes[
"@mozilla.org/network/ldap-service;1"].
getService(Components.interfaces.nsILDAPService);
}
catch (ex)
{
dump("failed to get ldap service!\n");
ldapService = null;
}
for (var i=0; i < this.availDirectories.length; i++) {
pref_string = this.availDirectories[i][0];
try{
host = gPrefInt.CopyCharPref(pref_string + ".serverName");
}
catch (ex) {
host = null;
}
if (host) {
try {
ldapUrl = Components.classes["@mozilla.org/network/ldap-url;1"];
ldapUrl = ldapUrl.createInstance().QueryInterface(nsILDAPURL);
}
catch (ex) {
dump("failed to get ldap url!\n");
return;
}
ldapUrl.host = host;
try{
dn = gPrefInt.CopyUnicharPref(pref_string + ".searchBase");
}
catch (ex) {
dn = null;
}
if (dn && ldapService)
ldapUrl.dn = ldapService.UCS2toUTF8(dn);
try {
var port = gPrefInt.GetIntPref(pref_string + ".port");
}
catch(ex) {
port = 389;
}
ldapUrl.port = port;
ldapUrl.scope = 2;
gPrefInt.SetUnicharPref(pref_string + ".uri", ldapUrl.spec);
/* is this server selected for autocompletion?
if yes, convert the preference to mozilla format.
Atmost one server is selected for autocompletion.
*/
if (useDirectory && !enable){
try {
enable = gPrefInt.GetBoolPref(pref_string + ".autocomplete.enabled");
}
catch(ex) {}
if (enable) {
gPrefInt.SetCharPref("ldap_2.servers.directoryServer", pref_string);
}
}
}
}
gPrefInt.SetBoolPref("ldap_2.prefs_migrated", true);
gPrefInt.SavePrefFile(null);
this.prefs_migrated = true;
}
/* factory for nsLDAPPrefs service (nsLDAPPrefsService) */
var nsLDAPPrefsFactory = new Object();
nsLDAPPrefsFactory.createInstance =
function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
if (!iid.equals(nsISupports))
throw Components.results.NS_ERROR_INVALID_ARG;
return new nsLDAPPrefsService();
}
var nsLDAPPrefsModule = new Object();
nsLDAPPrefsModule.registerSelf =
function (compMgr, fileSpec, location, type)
{
compMgr.registerComponentWithType(NS_LDAPPREFSSERVICE_CID,
"nsLDAPPrefs Service",
NS_LDAPPREFSSERVICE_CONTRACTID, fileSpec,
location, true, true, type);
}
nsLDAPPrefsModule.unregisterSelf =
function(compMgr, fileSpec, location)
{
compMgr.unregisterComponentSpec(NS_LDAPPREFSSERVICE_CID, fileSpec);
}
nsLDAPPrefsModule.getClassObject =
function (compMgr, cid, iid) {
if (cid.equals(NS_LDAPPREFSSERVICE_CID))
return nsLDAPPrefsFactory;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
nsLDAPPrefsModule.canUnload =
function(compMgr)
{
return true;
}
/* entrypoint */
function NSGetModule(compMgr, fileSpec) {
return nsLDAPPrefsModule;
}

View File

@ -42,6 +42,12 @@ msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMs
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
//This migrates the LDAPServer Preferences from 4.x to mozilla format.
var LDAPPrefsService = Components.classes[
"@mozilla.org/ldapprefs-service;1"].getService();
LDAPPrefsService = LDAPPrefsService.QueryInterface(
Components.interfaces.nsILDAPPrefsService);
var msgCompose = null;
var MAX_RECIPIENTS = 0;
var currentAttachment = null;

View File

@ -303,7 +303,8 @@ viewer:Components:msgImport.xpt
viewer:Components:msgImportText.shlb
viewer:Components:msgImportEudora.shlb
viewer:Components:AbSyncSvc.shlb
viewer:Components:AbSyncSvc.xpt
viewer:Components:AbSyncSvc.xpt
viewer:Components:nsLDAPPrefsService.js
viewer:Components:mozldap.shlb
viewer:Components:mozldap.xpt
viewer:Components:ldapAutoComplete.xpt

View File

@ -319,6 +319,7 @@ bin/components/msgimap.xpt
bin/components/msglocal.xpt
bin/components/msgnews.xpt
bin/components/msgsearch.xpt
bin/components/nsLDAPPrefsService.js
bin/components/txmgr.xpt
bin/components/import.xpt
bin/components/absync.xpt

View File

@ -330,6 +330,7 @@ bin\components\impEudra.dll
bin\components\impText.dll
bin\components\absyncsv.dll
bin\components\absync.xpt
bin\components\nsLDAPPrefsService.js
bin\components\mozldap.dll
bin\components\mozldap.xpt
bin\nsldap32v40.dll