зеркало из https://github.com/mozilla/gecko-dev.git
Make LDAP attributes used by the addressbook customizable via preferences (bug 119291). r=bienvenu@nventure.com, sr+a=shaver@mozilla.org
This commit is contained in:
Родитель
f7cb6fa18f
Коммит
32b9b7c267
|
@ -44,3 +44,8 @@
|
||||||
#ifdef PR_LOGGING
|
#ifdef PR_LOGGING
|
||||||
extern PRLogModuleInfo *gLDAPLogModule; // defn in nsLDAPProtocolModule.cpp
|
extern PRLogModuleInfo *gLDAPLogModule; // defn in nsLDAPProtocolModule.cpp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define NS_LDAPCONNECTION_CONTRACTID "@mozilla.org/network/ldap-connection;1"
|
||||||
|
#define NS_LDAPOPERATION_CONTRACTID "@mozilla.org/network/ldap-operation;1"
|
||||||
|
#define NS_LDAPMESSAGE_CONTRACTID "@mozilla.org/network/ldap-message;1"
|
||||||
|
#define NS_LDAPURL_CONTRACTID "@mozilla.org/network/ldap-url;1"
|
||||||
|
|
|
@ -70,6 +70,7 @@ defaults\profile\US\mimeTypes.rdf
|
||||||
components\mozldap.dll
|
components\mozldap.dll
|
||||||
components\mozldap.xpt
|
components\mozldap.xpt
|
||||||
components\nsLDAPPrefsService.js
|
components\nsLDAPPrefsService.js
|
||||||
|
components\nsAbLDAPAttributeMap.js
|
||||||
ldap50.dll
|
ldap50.dll
|
||||||
prldap50.dll
|
prldap50.dll
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ defaults/isp/movemail.rdf
|
||||||
components/libmozldap.so
|
components/libmozldap.so
|
||||||
components/mozldap.xpt
|
components/mozldap.xpt
|
||||||
components/nsLDAPPrefsService.js
|
components/nsLDAPPrefsService.js
|
||||||
|
components/nsAbLDAPAttributeMap.js
|
||||||
libldap50.so
|
libldap50.so
|
||||||
libprldap50.so
|
libprldap50.so
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,7 @@ bin\greprefs\
|
||||||
; LDAP components
|
; LDAP components
|
||||||
bin\components\mozldap.xpt
|
bin\components\mozldap.xpt
|
||||||
bin\components\nsLDAPPrefsService.js
|
bin\components\nsLDAPPrefsService.js
|
||||||
|
bin\components\nsAbLDAPAttributeMap.js
|
||||||
bin\nsldap32v50.dll
|
bin\nsldap32v50.dll
|
||||||
bin\nsldappr32v50.dll
|
bin\nsldappr32v50.dll
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
# the Initial Developer. All Rights Reserved.
|
# the Initial Developer. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Contributor(s):
|
# Contributor(s):
|
||||||
|
# Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
#
|
#
|
||||||
# Alternatively, the contents of this file may be used under the terms of
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -44,7 +45,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
ifdef MOZ_LDAP_XPCOM
|
ifdef MOZ_LDAP_XPCOM
|
||||||
REQUIRES += mozldap necko
|
REQUIRES += mozldap necko
|
||||||
EXTRA_COMPONENTS += src/nsLDAPPrefsService.js
|
EXTRA_COMPONENTS += src/nsLDAPPrefsService.js src/nsAbLDAPAttributeMap.js
|
||||||
endif
|
endif
|
||||||
|
|
||||||
DIRS = public src
|
DIRS = public src
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
# the Initial Developer. All Rights Reserved.
|
# the Initial Developer. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Contributor(s):
|
# Contributor(s):
|
||||||
|
# Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
#
|
#
|
||||||
# Alternatively, the contents of this file may be used under the terms of
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -76,8 +77,8 @@ XPIDLSRCS += \
|
||||||
nsIAbLDAPReplicationService.idl \
|
nsIAbLDAPReplicationService.idl \
|
||||||
nsIAbLDAPReplicationQuery.idl \
|
nsIAbLDAPReplicationQuery.idl \
|
||||||
nsIAbLDAPReplicationData.idl \
|
nsIAbLDAPReplicationData.idl \
|
||||||
|
nsIAbLDAPAttributeMap.idl \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -77,6 +78,13 @@ interface nsIAbDirectoryQueryArguments : nsISupports
|
||||||
void getReturnProperties (out unsigned long returnPropertiesSize,
|
void getReturnProperties (out unsigned long returnPropertiesSize,
|
||||||
[retval, array, size_is(returnPropertiesSize)]
|
[retval, array, size_is(returnPropertiesSize)]
|
||||||
out string returnPropertiesArray);
|
out string returnPropertiesArray);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A parameter which can be used to pass in data specific to a particular
|
||||||
|
* type of addressbook. In particular, the LDAP addressbook will be
|
||||||
|
* passing in an nsIAbLDAPAttributeMap this way.
|
||||||
|
*/
|
||||||
|
attribute nsISupports typeSpecificArg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,216 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 addressbook code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Oracle Corporation.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
|
interface nsISimpleEnumerator;
|
||||||
|
interface nsILDAPMessage;
|
||||||
|
interface nsIAbCard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mapping between addressbook properties and ldap attributes.
|
||||||
|
*
|
||||||
|
* Each addressbook property can map to one or more attributes. If
|
||||||
|
* there is no entry in preferences for a field, the getters generally
|
||||||
|
* return null; empty strings are passed through as usual. The intent is
|
||||||
|
* that properties with a non-zero number of attributes can be overridden for
|
||||||
|
* a specific server by supplying a zero-length string. For this to work,
|
||||||
|
* most callers are likely to want to check for both success and a
|
||||||
|
* non-empty string.
|
||||||
|
*
|
||||||
|
* Note that the one exception to this pattern is getAttributes, which
|
||||||
|
* throws NS_ERROR_FAILURE for non-existent property entries, since
|
||||||
|
* XPConnect doesn't like returning null arrays.
|
||||||
|
*
|
||||||
|
* Note that each LDAP attribute can map to at most one addressbook
|
||||||
|
* property. The checkState method is a useful tool in enforcing
|
||||||
|
* this. Failure to enforce it may make it impossible to guarantee
|
||||||
|
* that getProperty will do something consistent and reasonable.
|
||||||
|
*
|
||||||
|
* Maybe someday once we support ldap autoconfig stuff (ie
|
||||||
|
* draft-joslin-config-schema-11.txt), we can simplify this and other
|
||||||
|
* code and only allow a property to map to a single attribute.
|
||||||
|
*/
|
||||||
|
[scriptable, uuid(2ba46eae-9141-4d79-af90-3c7ecf2dc357)]
|
||||||
|
interface nsIAbLDAPAttributeMap : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get all the LDAP attributes associated with a given property
|
||||||
|
* name, in order of precedence (highest to lowest).
|
||||||
|
*
|
||||||
|
* @param aProperty the address book property to return attrs for
|
||||||
|
*
|
||||||
|
* @return a comma-separated list of attributes, null if no entry is
|
||||||
|
* present
|
||||||
|
*/
|
||||||
|
ACString getAttributeList(in ACString aProperty);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the LDAP attributes associated with a given property name, in
|
||||||
|
* order of precedence (highest to lowest).
|
||||||
|
*
|
||||||
|
* @param aProperty the address book property to return attrs for
|
||||||
|
*
|
||||||
|
* @return an array of attributes
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE if there is no entry for this property
|
||||||
|
*/
|
||||||
|
void getAttributes(in ACString aProperty, out unsigned long aCount,
|
||||||
|
[retval, array, size_is(aCount)] out string aAttrs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the first (canonical) LDAP attribute associated with a given property
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @param aProperty the address book property to return attrs for
|
||||||
|
*
|
||||||
|
* @return the first attribute associated with a given property,
|
||||||
|
* null if there is no entry for this property
|
||||||
|
*/
|
||||||
|
ACString getFirstAttribute(in ACString aProperty);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an existing mapping to the comma-separated list of attributes.
|
||||||
|
*
|
||||||
|
* @param aProperty the mozilla addressbook property name
|
||||||
|
*
|
||||||
|
* @param aAttributeList a comma-separated list of attributes in
|
||||||
|
* order of precedence from high to low
|
||||||
|
*
|
||||||
|
* @param aAllowInconsistencies allow changes that would result in
|
||||||
|
* a map with an LDAP attribute associated
|
||||||
|
* with more than one property. Useful for
|
||||||
|
* doing a bunch of sets at once, and
|
||||||
|
* calling checkState at the end.
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE making this change would result in a map
|
||||||
|
* with an LDAP attribute pointing to more
|
||||||
|
* than one property
|
||||||
|
*/
|
||||||
|
void setAttributeList(in ACString aProperty, in ACString aAttributeList,
|
||||||
|
in boolean allowInconsistencies);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the Mozilla addressbook property name that this attribute should
|
||||||
|
* map to.
|
||||||
|
*
|
||||||
|
* @return the addressbook property name, null if it's not used in the map
|
||||||
|
*/
|
||||||
|
ACString getProperty(in ACString aAttribute);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all attributes that may be used in an addressbook card via this
|
||||||
|
* property map (used for passing to to an LDAP search when you want
|
||||||
|
* everything that could be in a card returned).
|
||||||
|
*
|
||||||
|
* @return a comma-separated list of attribute names
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE there are no attributes in this property map
|
||||||
|
*/
|
||||||
|
ACString getAllCardAttributes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that no LDAP attributes are listed in more than one property.
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE one or more LDAP attributes are listed
|
||||||
|
* multiple times. The object is now in an
|
||||||
|
* inconsistent state, and should be either
|
||||||
|
* manually repaired or discarded.
|
||||||
|
*/
|
||||||
|
void checkState();
|
||||||
|
|
||||||
|
/* These last two methods are really just for the convenience of the caller
|
||||||
|
* and to avoid tons of unnecessary crossing of the XPConnect boundary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set any attributes specified in the given prefbranch on this object.
|
||||||
|
*
|
||||||
|
* @param aPrefBranchName the pref branch containing all the
|
||||||
|
* property names
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE one or more LDAP attributes are listed
|
||||||
|
* multiple times. The object is now in an
|
||||||
|
* inconsistent state, and should be either
|
||||||
|
* manually repaired or discarded.
|
||||||
|
*/
|
||||||
|
void setFromPrefs(in ACString aPrefBranchName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the properties on an addressbook card from the given LDAP message
|
||||||
|
* using the map in this object.
|
||||||
|
*
|
||||||
|
* @param aCard is the card object whose values are to be set
|
||||||
|
* @param aMessage is the LDAP message to get the values from
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE is thrown if no addressbook properties
|
||||||
|
* are found in the message
|
||||||
|
*/
|
||||||
|
void setCardPropertiesFromLDAPMessage(in nsILDAPMessage aMessage,
|
||||||
|
in nsIAbCard aCard);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The nsIAbLDAPAttributeMapService is used to build and hold a cache
|
||||||
|
* of maps.
|
||||||
|
*/
|
||||||
|
[scriptable, uuid(12e2d589-3c2a-48e4-8c82-b1e6464a0dfd)]
|
||||||
|
interface nsIAbLDAPAttributeMapService : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Accessor to construct or return a cached copy of the attribute
|
||||||
|
* map for a given preference branch. The map is constructed by
|
||||||
|
* first taking the default map (as specified by the
|
||||||
|
* "ldap_2.servers.default.attrmap" prefbranch), and then having any
|
||||||
|
* preferences specified by aPrefBranchName override the defaults.
|
||||||
|
* LDIF import and export code should use the default map.
|
||||||
|
*
|
||||||
|
* @return the requested map
|
||||||
|
*
|
||||||
|
* @exception NS_ERROR_FAILURE error constructing the map;
|
||||||
|
* possibly because of a failure
|
||||||
|
* from checkState()
|
||||||
|
*/
|
||||||
|
nsIAbLDAPAttributeMap getMapForPrefBranch(in ACString aPrefBranchName);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
%{C++
|
||||||
|
// test whether one of the getters has actually found an attribute
|
||||||
|
#define ATTRMAP_FOUND_ATTR(rv, str) (NS_SUCCEEDED(rv) && !(str).IsEmpty())
|
||||||
|
%}
|
|
@ -20,6 +20,7 @@
|
||||||
# the Initial Developer. All Rights Reserved.
|
# the Initial Developer. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Contributor(s):
|
# Contributor(s):
|
||||||
|
# Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
#
|
#
|
||||||
# Alternatively, the contents of this file may be used under the terms of
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -138,7 +139,6 @@ REQUIRES += mozldap \
|
||||||
CPPSRCS += nsAbLDAPDirectory.cpp \
|
CPPSRCS += nsAbLDAPDirectory.cpp \
|
||||||
nsAbLDAPDirFactory.cpp \
|
nsAbLDAPDirFactory.cpp \
|
||||||
nsAbLDAPCard.cpp \
|
nsAbLDAPCard.cpp \
|
||||||
nsAbLDAPProperties.cpp \
|
|
||||||
nsAbLDAPDirectoryQuery.cpp \
|
nsAbLDAPDirectoryQuery.cpp \
|
||||||
nsAbBoolExprToLDAPFilter.cpp \
|
nsAbBoolExprToLDAPFilter.cpp \
|
||||||
nsAbLDAPAutoCompFormatter.cpp \
|
nsAbLDAPAutoCompFormatter.cpp \
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -36,14 +37,15 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#include "nsIAbLDAPAttributeMap.h"
|
||||||
#include "nsAbBoolExprToLDAPFilter.h"
|
#include "nsAbBoolExprToLDAPFilter.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
#include "nsXPIDLString.h"
|
#include "nsXPIDLString.h"
|
||||||
|
|
||||||
const int nsAbBoolExprToLDAPFilter::TRANSLATE_CARD_PROPERTY = 1 << 0 ;
|
const int nsAbBoolExprToLDAPFilter::TRANSLATE_CARD_PROPERTY = 1 << 0 ;
|
||||||
const int nsAbBoolExprToLDAPFilter::ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1 ;
|
const int nsAbBoolExprToLDAPFilter::ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1 ;
|
||||||
|
|
||||||
nsresult nsAbBoolExprToLDAPFilter::Convert (
|
nsresult nsAbBoolExprToLDAPFilter::Convert (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsIAbBooleanExpression* expression,
|
nsIAbBooleanExpression* expression,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags)
|
int flags)
|
||||||
|
@ -51,7 +53,7 @@ nsresult nsAbBoolExprToLDAPFilter::Convert (
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
nsCString f;
|
nsCString f;
|
||||||
rv = FilterExpression (expression, f, flags);
|
rv = FilterExpression (map, expression, f, flags);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
filter = f;
|
filter = f;
|
||||||
|
@ -59,6 +61,7 @@ nsresult nsAbBoolExprToLDAPFilter::Convert (
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsAbBoolExprToLDAPFilter::FilterExpression (
|
nsresult nsAbBoolExprToLDAPFilter::FilterExpression (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsIAbBooleanExpression* expression,
|
nsIAbBooleanExpression* expression,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags)
|
int flags)
|
||||||
|
@ -114,17 +117,17 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpression (
|
||||||
{
|
{
|
||||||
case nsIAbBooleanOperationTypes::AND:
|
case nsIAbBooleanOperationTypes::AND:
|
||||||
filter.AppendLiteral("&");
|
filter.AppendLiteral("&");
|
||||||
rv = FilterExpressions (childExpressions, filter, flags);
|
rv = FilterExpressions (map, childExpressions, filter, flags);
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanOperationTypes::OR:
|
case nsIAbBooleanOperationTypes::OR:
|
||||||
filter.AppendLiteral("|");
|
filter.AppendLiteral("|");
|
||||||
rv = FilterExpressions (childExpressions, filter, flags);
|
rv = FilterExpressions (map, childExpressions, filter, flags);
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanOperationTypes::NOT:
|
case nsIAbBooleanOperationTypes::NOT:
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
filter.AppendLiteral("!");
|
filter.AppendLiteral("!");
|
||||||
rv = FilterExpressions (childExpressions, filter, flags);
|
rv = FilterExpressions (map, childExpressions, filter, flags);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -135,6 +138,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpression (
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsAbBoolExprToLDAPFilter::FilterExpressions (
|
nsresult nsAbBoolExprToLDAPFilter::FilterExpressions (
|
||||||
|
nsIAbLDAPAttributeMap *map,
|
||||||
nsISupportsArray* expressions,
|
nsISupportsArray* expressions,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags)
|
int flags)
|
||||||
|
@ -154,7 +158,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpressions (
|
||||||
nsCOMPtr<nsIAbBooleanConditionString> childCondition(do_QueryInterface(item, &rv));
|
nsCOMPtr<nsIAbBooleanConditionString> childCondition(do_QueryInterface(item, &rv));
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
rv = FilterCondition (childCondition, filter, flags);
|
rv = FilterCondition (map, childCondition, filter, flags);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +166,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpressions (
|
||||||
nsCOMPtr<nsIAbBooleanExpression> childExpression(do_QueryInterface(item, &rv));
|
nsCOMPtr<nsIAbBooleanExpression> childExpression(do_QueryInterface(item, &rv));
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
rv = FilterExpression (childExpression, filter, flags);
|
rv = FilterExpression (map, childExpression, filter, flags);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -172,6 +176,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpressions (
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsAbBoolExprToLDAPFilter::FilterCondition (
|
nsresult nsAbBoolExprToLDAPFilter::FilterCondition (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsIAbBooleanConditionString* condition,
|
nsIAbBooleanConditionString* condition,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags)
|
int flags)
|
||||||
|
@ -186,14 +191,12 @@ nsresult nsAbBoolExprToLDAPFilter::FilterCondition (
|
||||||
rv = condition->GetName (getter_Copies (name));
|
rv = condition->GetName (getter_Copies (name));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
const char* ldapProperty = name.get ();
|
nsCAutoString ldapAttr(name);
|
||||||
if (flags & TRANSLATE_CARD_PROPERTY)
|
if (flags & TRANSLATE_CARD_PROPERTY)
|
||||||
{
|
{
|
||||||
const MozillaLdapPropertyRelation* p =
|
rv = map->GetFirstAttribute (name, ldapAttr);
|
||||||
MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ());
|
if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY) &&
|
||||||
if (p)
|
!ATTRMAP_FOUND_ATTR(rv, ldapAttr))
|
||||||
ldapProperty = p->ldapProperty;
|
|
||||||
else if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY))
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,73 +209,73 @@ nsresult nsAbBoolExprToLDAPFilter::FilterCondition (
|
||||||
{
|
{
|
||||||
case nsIAbBooleanConditionTypes::DoesNotExist:
|
case nsIAbBooleanConditionTypes::DoesNotExist:
|
||||||
filter += NS_LITERAL_CSTRING("(!(") +
|
filter += NS_LITERAL_CSTRING("(!(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=*))");
|
NS_LITERAL_CSTRING("=*))");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::Exists:
|
case nsIAbBooleanConditionTypes::Exists:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=*)");
|
NS_LITERAL_CSTRING("=*)");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::Contains:
|
case nsIAbBooleanConditionTypes::Contains:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=*") +
|
NS_LITERAL_CSTRING("=*") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING("*)");
|
NS_LITERAL_CSTRING("*)");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::DoesNotContain:
|
case nsIAbBooleanConditionTypes::DoesNotContain:
|
||||||
filter += NS_LITERAL_CSTRING("(!(") +
|
filter += NS_LITERAL_CSTRING("(!(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=*") +
|
NS_LITERAL_CSTRING("=*") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING("*))");
|
NS_LITERAL_CSTRING("*))");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::Is:
|
case nsIAbBooleanConditionTypes::Is:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=") +
|
NS_LITERAL_CSTRING("=") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING(")");
|
NS_LITERAL_CSTRING(")");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::IsNot:
|
case nsIAbBooleanConditionTypes::IsNot:
|
||||||
filter += NS_LITERAL_CSTRING("(!(") +
|
filter += NS_LITERAL_CSTRING("(!(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=") +
|
NS_LITERAL_CSTRING("=") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING("))");
|
NS_LITERAL_CSTRING("))");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::BeginsWith:
|
case nsIAbBooleanConditionTypes::BeginsWith:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=") +
|
NS_LITERAL_CSTRING("=") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING("*)");
|
NS_LITERAL_CSTRING("*)");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::EndsWith:
|
case nsIAbBooleanConditionTypes::EndsWith:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("=*") +
|
NS_LITERAL_CSTRING("=*") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING(")");
|
NS_LITERAL_CSTRING(")");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::LessThan:
|
case nsIAbBooleanConditionTypes::LessThan:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("<=") +
|
NS_LITERAL_CSTRING("<=") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING(")");
|
NS_LITERAL_CSTRING(")");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::GreaterThan:
|
case nsIAbBooleanConditionTypes::GreaterThan:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING(">=") +
|
NS_LITERAL_CSTRING(">=") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING(")");
|
NS_LITERAL_CSTRING(")");
|
||||||
break;
|
break;
|
||||||
case nsIAbBooleanConditionTypes::SoundsLike:
|
case nsIAbBooleanConditionTypes::SoundsLike:
|
||||||
filter += NS_LITERAL_CSTRING("(") +
|
filter += NS_LITERAL_CSTRING("(") +
|
||||||
nsDependentCString(ldapProperty) +
|
ldapAttr +
|
||||||
NS_LITERAL_CSTRING("~=") +
|
NS_LITERAL_CSTRING("~=") +
|
||||||
vUTF8 +
|
vUTF8 +
|
||||||
NS_LITERAL_CSTRING(")");
|
NS_LITERAL_CSTRING(")");
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -43,6 +44,8 @@
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
|
||||||
|
class nsIAbLDAPAttributeMap;
|
||||||
|
|
||||||
class nsAbBoolExprToLDAPFilter
|
class nsAbBoolExprToLDAPFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -50,20 +53,24 @@ public:
|
||||||
static const int ALLOW_NON_CONVERTABLE_CARD_PROPERTY ;
|
static const int ALLOW_NON_CONVERTABLE_CARD_PROPERTY ;
|
||||||
|
|
||||||
static nsresult Convert (
|
static nsresult Convert (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsIAbBooleanExpression* expression,
|
nsIAbBooleanExpression* expression,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags = TRANSLATE_CARD_PROPERTY);
|
int flags = TRANSLATE_CARD_PROPERTY);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static nsresult FilterExpression (
|
static nsresult FilterExpression (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsIAbBooleanExpression* expression,
|
nsIAbBooleanExpression* expression,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags);
|
int flags);
|
||||||
static nsresult FilterExpressions (
|
static nsresult FilterExpressions (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsISupportsArray* expressions,
|
nsISupportsArray* expressions,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags);
|
int flags);
|
||||||
static nsresult FilterCondition (
|
static nsresult FilterCondition (
|
||||||
|
nsIAbLDAPAttributeMap* map,
|
||||||
nsIAbBooleanConditionString* condition,
|
nsIAbBooleanConditionString* condition,
|
||||||
nsCString& filter,
|
nsCString& filter,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -206,6 +207,21 @@ NS_IMETHODIMP nsAbDirectoryQueryArguments::GetReturnProperties(PRUint32* returnP
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsAbDirectoryQueryArguments::GetTypeSpecificArg(nsISupports** aArg)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aArg);
|
||||||
|
|
||||||
|
NS_IF_ADDREF(*aArg = mTypeSpecificArg);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsAbDirectoryQueryArguments::SetTypeSpecificArg(nsISupports* aArg)
|
||||||
|
{
|
||||||
|
mTypeSpecificArg = aArg;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbDirectoryQueryPropertyValue, nsIAbDirectoryQueryPropertyValue)
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsAbDirectoryQueryPropertyValue, nsIAbDirectoryQueryPropertyValue)
|
||||||
|
|
||||||
nsAbDirectoryQueryPropertyValue::nsAbDirectoryQueryPropertyValue()
|
nsAbDirectoryQueryPropertyValue::nsAbDirectoryQueryPropertyValue()
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -70,6 +71,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsCOMPtr<nsISupports> mExpression;
|
nsCOMPtr<nsISupports> mExpression;
|
||||||
|
nsCOMPtr<nsISupports> mTypeSpecificArg;
|
||||||
PRBool mQuerySubDirectories;
|
PRBool mQuerySubDirectories;
|
||||||
nsCStringArray mReturnProperties;
|
nsCStringArray mReturnProperties;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,347 @@
|
||||||
|
/* -*- Mode: Javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* Oracle Corporation.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
const NS_ABLDAPATTRIBUTEMAP_CID = Components.ID(
|
||||||
|
"{127b341a-bdda-4270-85e1-edff569a9b85}");
|
||||||
|
const NS_ABLDAPATTRIBUTEMAPSERVICE_CID = Components.ID(
|
||||||
|
"{4ed7d5e1-8800-40da-9e78-c4f509d7ac5e}");
|
||||||
|
|
||||||
|
function nsAbLDAPAttributeMap() {}
|
||||||
|
|
||||||
|
nsAbLDAPAttributeMap.prototype = {
|
||||||
|
mPropertyMap: {},
|
||||||
|
mAttrMap: {},
|
||||||
|
|
||||||
|
getAttributeList: function getAttributeList(aProperty) {
|
||||||
|
|
||||||
|
if (!(aProperty in this.mPropertyMap)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the joined list
|
||||||
|
return this.mPropertyMap[aProperty].join(",");
|
||||||
|
},
|
||||||
|
|
||||||
|
getAttributes: function getAttributes(aProperty, aCount, aAttrs) {
|
||||||
|
|
||||||
|
// fail if no entry for this
|
||||||
|
if (!(aProperty in this.mPropertyMap)) {
|
||||||
|
throw Components.results.NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
aAttrs = this.mPropertyMap[aProperty];
|
||||||
|
aCount = aAttrs.length;
|
||||||
|
return aAttrs;
|
||||||
|
},
|
||||||
|
|
||||||
|
getFirstAttribute: function getFirstAttribute(aProperty) {
|
||||||
|
|
||||||
|
// fail if no entry for this
|
||||||
|
if (!(aProperty in this.mPropertyMap)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.mPropertyMap[aProperty][0];
|
||||||
|
},
|
||||||
|
|
||||||
|
setAttributeList: function setAttributeList(aProperty, aAttributeList,
|
||||||
|
aAllowInconsistencies) {
|
||||||
|
|
||||||
|
var attrs = aAttributeList.split(",");
|
||||||
|
|
||||||
|
// check to make sure this call won't allow multiple mappings to be
|
||||||
|
// created, if requested
|
||||||
|
if (!aAllowInconsistencies) {
|
||||||
|
for each (var attr in attrs) {
|
||||||
|
if (attr in this.mAttrMap && this.mAttrMap[attr] != aProperty) {
|
||||||
|
throw Components.results.NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete any attr mappings created by the existing property map entry
|
||||||
|
for each (attr in this.mPropertyMap[aProperty]) {
|
||||||
|
delete this.mAttrMap[attr];
|
||||||
|
}
|
||||||
|
|
||||||
|
// add these attrs to the attrmap
|
||||||
|
for each (attr in attrs) {
|
||||||
|
this.mAttrMap[attr] = aProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add them to the property map
|
||||||
|
this.mPropertyMap[aProperty] = attrs;
|
||||||
|
},
|
||||||
|
|
||||||
|
getProperty: function getProperty(aAttribute) {
|
||||||
|
|
||||||
|
if (!(aAttribute in this.mAttrMap)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.mAttrMap[aAttribute];
|
||||||
|
},
|
||||||
|
|
||||||
|
getAllCardAttributes: function getAllCardAttributes() {
|
||||||
|
var attrs = [];
|
||||||
|
for each (var prop in this.mPropertyMap) {
|
||||||
|
attrs.push(prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!attrs.length) {
|
||||||
|
throw Components.results.NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return attrs.join(",");
|
||||||
|
},
|
||||||
|
|
||||||
|
setFromPrefs: function setFromPrefs(aPrefBranchName) {
|
||||||
|
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
|
||||||
|
getService(Components.interfaces.nsIPrefService);
|
||||||
|
|
||||||
|
// get the right pref branch
|
||||||
|
var branch = prefSvc.getBranch(aPrefBranchName + ".");
|
||||||
|
|
||||||
|
// get the list of children
|
||||||
|
var childCount = {};
|
||||||
|
var children = branch.getChildList("", childCount);
|
||||||
|
|
||||||
|
// do the actual sets
|
||||||
|
for each (var child in children) {
|
||||||
|
this.setAttributeList(child, branch.getCharPref(child), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure that everything is kosher
|
||||||
|
this.checkState();
|
||||||
|
},
|
||||||
|
|
||||||
|
setCardPropertiesFromLDAPMessage: function
|
||||||
|
setCardPropertiesFromLDAPMessage(aMessage, aCard) {
|
||||||
|
|
||||||
|
var cardValueWasSet = false;
|
||||||
|
|
||||||
|
var msgAttrCount = {};
|
||||||
|
var msgAttrs = aMessage.getAttributes(msgAttrCount);
|
||||||
|
|
||||||
|
// downcase the array for comparison
|
||||||
|
function toLower(a) { return a.toLowerCase(); }
|
||||||
|
msgAttrs = msgAttrs.map(toLower);
|
||||||
|
|
||||||
|
// deal with each addressbook property
|
||||||
|
for (var prop in this.mPropertyMap) {
|
||||||
|
|
||||||
|
// go through the list of possible attrs in precedence order
|
||||||
|
for each (var attr in this.mPropertyMap[prop]) {
|
||||||
|
|
||||||
|
// find the first attr that exists in this message
|
||||||
|
if (msgAttrs.indexOf(attr) != -1) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
var values = aMessage.getValues(attr, {});
|
||||||
|
aCard.setCardValue(prop, values[0]);
|
||||||
|
|
||||||
|
cardValueWasSet = true;
|
||||||
|
} catch (ex) {
|
||||||
|
// ignore any errors getting message values or setting card values
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cardValueWasSet) {
|
||||||
|
throw Components.results.NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
|
||||||
|
checkState: function checkState() {
|
||||||
|
|
||||||
|
var attrsSeen = [];
|
||||||
|
|
||||||
|
for each (var attrArray in this.mPropertyMap) {
|
||||||
|
|
||||||
|
for each (var attr in attrArray) {
|
||||||
|
|
||||||
|
// if we've seen this before, there's a problem
|
||||||
|
if (attrsSeen.indexOf(attr) != -1) {
|
||||||
|
throw Components.results.NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remember that we've seen it now
|
||||||
|
attrsSeen.push(attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
|
||||||
|
QueryInterface: function QueryInterface(iid) {
|
||||||
|
if (!iid.equals(Components.interfaces.nsIAbLDAPAttributeMap) &&
|
||||||
|
!iid.equals(Components.interfaces.nsISupports)) {
|
||||||
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function nsAbLDAPAttributeMapService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAbLDAPAttributeMapService.prototype = {
|
||||||
|
|
||||||
|
mAttrMaps: {},
|
||||||
|
|
||||||
|
getMapForPrefBranch: function getMapForPrefBranch(aPrefBranchName) {
|
||||||
|
|
||||||
|
// if we've already got this map, return it
|
||||||
|
if (aPrefBranchName in this.mAttrMaps) {
|
||||||
|
return this.mAttrMaps[aPrefBranchName];
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise, try and create it
|
||||||
|
var attrMap = new nsAbLDAPAttributeMap();
|
||||||
|
attrMap.setFromPrefs("ldap_2.servers.default.attrmap");
|
||||||
|
attrMap.setFromPrefs(aPrefBranchName + ".attrmap");
|
||||||
|
|
||||||
|
// cache
|
||||||
|
this.mAttrMaps[aPrefBranchName] = attrMap;
|
||||||
|
|
||||||
|
// and return
|
||||||
|
return attrMap;
|
||||||
|
},
|
||||||
|
|
||||||
|
QueryInterface: function (iid) {
|
||||||
|
if (iid.equals(Components.interfaces.nsIAbLDAPAttributeMapService) ||
|
||||||
|
iid.equals(Components.interfaces.nsISupports))
|
||||||
|
return this;
|
||||||
|
|
||||||
|
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var nsAbLDAPAttributeMapModule = {
|
||||||
|
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||||
|
debug("*** Registering Addressbook LDAP Attribute Map components\n");
|
||||||
|
compMgr = compMgr.QueryInterface(
|
||||||
|
Components.interfaces.nsIComponentRegistrar);
|
||||||
|
|
||||||
|
compMgr.registerFactoryLocation(
|
||||||
|
NS_ABLDAPATTRIBUTEMAP_CID,
|
||||||
|
"Addressbook LDAP Attribute Map Component",
|
||||||
|
"@mozilla.org/addressbook/ldap-attribute-map;1",
|
||||||
|
fileSpec, location, type);
|
||||||
|
|
||||||
|
compMgr.registerFactoryLocation(
|
||||||
|
NS_ABLDAPATTRIBUTEMAPSERVICE_CID,
|
||||||
|
"Addressbook LDAP Attribute Map Service",
|
||||||
|
"@mozilla.org/addressbook/ldap-attribute-map-service;1",
|
||||||
|
fileSpec, location, type);
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The GetClassObject method is responsible for producing Factory objects
|
||||||
|
*/
|
||||||
|
getClassObject: function (compMgr, cid, iid) {
|
||||||
|
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||||
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
|
if (cid.equals(NS_ABLDAPATTRIBUTEMAP_CID)) {
|
||||||
|
return this.nsAbLDAPAttributeMapFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cid.equals(NS_ABLDAPATTRIBUTEMAPSERVICE_CID)) {
|
||||||
|
return this.nsAbLDAPAttributeMapServiceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* factory objects */
|
||||||
|
nsAbLDAPAttributeMapFactory: {
|
||||||
|
/*
|
||||||
|
* Construct an instance of the interface specified by iid, possibly
|
||||||
|
* aggregating it with the provided outer. (If you don't know what
|
||||||
|
* aggregation is all about, you don't need to. It reduces even the
|
||||||
|
* mightiest of XPCOM warriors to snivelling cowards.)
|
||||||
|
*/
|
||||||
|
createInstance: function (outer, iid) {
|
||||||
|
if (outer != null)
|
||||||
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||||
|
|
||||||
|
return (new nsAbLdapAttributeMap()).QueryInterface(iid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
nsAbLDAPAttributeMapServiceFactory: {
|
||||||
|
/*
|
||||||
|
* Construct an instance of the interface specified by iid, possibly
|
||||||
|
* aggregating it with the provided outer. (If you don't know what
|
||||||
|
* aggregation is all about, you don't need to. It reduces even the
|
||||||
|
* mightiest of XPCOM warriors to snivelling cowards.)
|
||||||
|
*/
|
||||||
|
createInstance: function (outer, iid) {
|
||||||
|
if (outer != null)
|
||||||
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||||
|
|
||||||
|
return (new nsAbLDAPAttributeMapService()).QueryInterface(iid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The canUnload method signals that the component is about to be unloaded.
|
||||||
|
* C++ components can return false to indicate that they don't wish to be
|
||||||
|
* unloaded, but the return value from JS components' canUnload is ignored:
|
||||||
|
* mark-and-sweep will keep everything around until it's no longer in use,
|
||||||
|
* making unconditional ``unload'' safe.
|
||||||
|
*
|
||||||
|
* You still need to provide a (likely useless) canUnload method, though:
|
||||||
|
* it's part of the nsIModule interface contract, and the JS loader _will_
|
||||||
|
* call it.
|
||||||
|
*/
|
||||||
|
canUnload: function(compMgr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function NSGetModule(compMgr, fileSpec) {
|
||||||
|
return nsAbLDAPAttributeMapModule;
|
||||||
|
}
|
|
@ -20,6 +20,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Rajiv Dayal <rdayal@netscape.com>
|
* Rajiv Dayal <rdayal@netscape.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -38,13 +39,13 @@
|
||||||
#include "nsAbLDAPChangeLogData.h"
|
#include "nsAbLDAPChangeLogData.h"
|
||||||
#include "nsAbLDAPChangeLogQuery.h"
|
#include "nsAbLDAPChangeLogQuery.h"
|
||||||
#include "nsLDAP.h"
|
#include "nsLDAP.h"
|
||||||
|
#include "nsILDAPMessage.h"
|
||||||
#include "nsIAbCard.h"
|
#include "nsIAbCard.h"
|
||||||
#include "nsIAddrBookSession.h"
|
#include "nsIAddrBookSession.h"
|
||||||
#include "nsAbBaseCID.h"
|
#include "nsAbBaseCID.h"
|
||||||
#include "nsAbUtils.h"
|
#include "nsAbUtils.h"
|
||||||
#include "nsAbMDBCard.h"
|
#include "nsAbMDBCard.h"
|
||||||
#include "nsAbLDAPCard.h"
|
#include "nsAbLDAPCard.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
#include "nsProxiedService.h"
|
#include "nsProxiedService.h"
|
||||||
#include "nsAutoLock.h"
|
#include "nsAutoLock.h"
|
||||||
#include "nsIAuthPrompt.h"
|
#include "nsIAuthPrompt.h"
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Rajiv Dayal <rdayal@netscape.com>
|
* Rajiv Dayal <rdayal@netscape.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
@ -41,7 +43,6 @@
|
||||||
#include "nsAbLDAPChangeLogQuery.h"
|
#include "nsAbLDAPChangeLogQuery.h"
|
||||||
#include "nsAbLDAPReplicationService.h"
|
#include "nsAbLDAPReplicationService.h"
|
||||||
#include "nsAbLDAPChangeLogData.h"
|
#include "nsAbLDAPChangeLogData.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
#include "nsAutoLock.h"
|
#include "nsAutoLock.h"
|
||||||
#include "nsAbUtils.h"
|
#include "nsAbUtils.h"
|
||||||
#include "prprf.h"
|
#include "prprf.h"
|
||||||
|
@ -50,6 +51,22 @@
|
||||||
#include "nsPrintfCString.h"
|
#include "nsPrintfCString.h"
|
||||||
|
|
||||||
|
|
||||||
|
// The tables below were originally in nsAbLDAPProperties.cpp, which has since
|
||||||
|
// gone away.
|
||||||
|
static const char * sChangeLogRootDSEAttribs[] =
|
||||||
|
{
|
||||||
|
"changelog",
|
||||||
|
"firstChangeNumber",
|
||||||
|
"lastChangeNumber",
|
||||||
|
"dataVersion"
|
||||||
|
};
|
||||||
|
static const char * sChangeLogEntryAttribs[] =
|
||||||
|
{
|
||||||
|
"targetdn",
|
||||||
|
"changetype"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS_INHERITED1(nsAbLDAPChangeLogQuery, nsAbLDAPReplicationQuery, nsIAbLDAPChangeLogQuery)
|
NS_IMPL_ISUPPORTS_INHERITED1(nsAbLDAPChangeLogQuery, nsAbLDAPReplicationQuery, nsIAbLDAPChangeLogQuery)
|
||||||
|
|
||||||
nsAbLDAPChangeLogQuery::nsAbLDAPChangeLogQuery()
|
nsAbLDAPChangeLogQuery::nsAbLDAPChangeLogQuery()
|
||||||
|
@ -137,10 +154,9 @@ NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryRootDSE()
|
||||||
nsresult rv = CreateNewLDAPOperation();
|
nsresult rv = CreateNewLDAPOperation();
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return mOperation->SearchExt(EmptyCString(), nsILDAPURL::SCOPE_BASE,
|
return mOperation->SearchExt(EmptyCString(), nsILDAPURL::SCOPE_BASE,
|
||||||
NS_LITERAL_CSTRING("objectclass=*"),
|
NS_LITERAL_CSTRING("objectclass=*"),
|
||||||
MozillaLdapPropertyRelator::rootDSEAttribCount,
|
sizeof(sChangeLogRootDSEAttribs),
|
||||||
MozillaLdapPropertyRelator::changeLogRootDSEAttribs,
|
sChangeLogRootDSEAttribs, 0, 0);
|
||||||
0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangeLog(const nsACString & aChangeLogDN, PRInt32 aLastChangeNo)
|
NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangeLog(const nsACString & aChangeLogDN, PRInt32 aLastChangeNo)
|
||||||
|
@ -159,12 +175,9 @@ NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangeLog(const nsACString & aChangeL
|
||||||
nsresult rv = CreateNewLDAPOperation();
|
nsresult rv = CreateNewLDAPOperation();
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
return mOperation->SearchExt(aChangeLogDN,
|
return mOperation->SearchExt(aChangeLogDN, nsILDAPURL::SCOPE_ONELEVEL, filter,
|
||||||
nsILDAPURL::SCOPE_ONELEVEL,
|
sizeof(sChangeLogEntryAttribs),
|
||||||
filter,
|
sChangeLogEntryAttribs, 0, 0);
|
||||||
MozillaLdapPropertyRelator::changeLogEntryAttribCount,
|
|
||||||
MozillaLdapPropertyRelator::changeLogEntryAttribs,
|
|
||||||
0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangedEntries(const nsACString & aChangedEntryDN)
|
NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangedEntries(const nsACString & aChangedEntryDN)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
@ -20,6 +22,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Rajiv Dayal <rdayal@netscape.com>
|
* Rajiv Dayal <rdayal@netscape.com>
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -55,5 +58,4 @@ public :
|
||||||
NS_IMETHOD Init(const nsACString & aPrefName, nsIWebProgressListener *aProgressListener);
|
NS_IMETHOD Init(const nsACString & aPrefName, nsIWebProgressListener *aProgressListener);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // nsAbLDAPChangeLogQuery_h__
|
#endif // nsAbLDAPChangeLogQuery_h__
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#include "nsAbLDAPDirectory.h"
|
#include "nsAbLDAPDirectory.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
|
|
||||||
#include "nsAbQueryStringToExpression.h"
|
#include "nsAbQueryStringToExpression.h"
|
||||||
|
|
||||||
|
@ -58,6 +57,8 @@
|
||||||
#include "nsIPrefBranch.h"
|
#include "nsIPrefBranch.h"
|
||||||
#include "nsCOMArray.h"
|
#include "nsCOMArray.h"
|
||||||
#include "nsArrayEnumerator.h"
|
#include "nsArrayEnumerator.h"
|
||||||
|
#include "nsLDAP.h"
|
||||||
|
#include "nsIAbLDAPAttributeMap.h"
|
||||||
|
|
||||||
nsAbLDAPDirectory::nsAbLDAPDirectory() :
|
nsAbLDAPDirectory::nsAbLDAPDirectory() :
|
||||||
nsAbDirectoryRDFResource(),
|
nsAbDirectoryRDFResource(),
|
||||||
|
@ -387,6 +388,23 @@ NS_IMETHODIMP nsAbLDAPDirectory::StartSearch ()
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
maxHits = 100;
|
maxHits = 100;
|
||||||
|
|
||||||
|
// get the appropriate ldap attribute map, and pass it in via the
|
||||||
|
// TypeSpecificArgument
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMapService> mapSvc =
|
||||||
|
do_GetService("@mozilla.org/addressbook/ldap-attribute-map-service;1", &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMap> attrMap;
|
||||||
|
rv = mapSvc->GetMapForPrefBranch(prefName, getter_AddRefs(attrMap));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsISupports> typeSpecificArg = do_QueryInterface(attrMap, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = arguments->SetTypeSpecificArg(attrMap);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
|
||||||
// Perform the query
|
// Perform the query
|
||||||
rv = DoQuery(arguments, queryListener, maxHits, 0, &mContext);
|
rv = DoQuery(arguments, queryListener, maxHits, 0, &mContext);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
|
@ -40,10 +40,12 @@
|
||||||
|
|
||||||
#include "nsAbLDAPDirectoryQuery.h"
|
#include "nsAbLDAPDirectoryQuery.h"
|
||||||
#include "nsAbBoolExprToLDAPFilter.h"
|
#include "nsAbBoolExprToLDAPFilter.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
#include "nsILDAPMessage.h"
|
||||||
#include "nsILDAPErrors.h"
|
#include "nsILDAPErrors.h"
|
||||||
#include "nsILDAPOperation.h"
|
#include "nsILDAPOperation.h"
|
||||||
|
#include "nsIAbLDAPAttributeMap.h"
|
||||||
#include "nsAbUtils.h"
|
#include "nsAbUtils.h"
|
||||||
|
#include "nsLDAP.h"
|
||||||
|
|
||||||
#include "nsIAuthPrompt.h"
|
#include "nsIAuthPrompt.h"
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
|
@ -224,8 +226,8 @@ NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPMessage(nsILDAPMessage *aMessa
|
||||||
case nsILDAPMessage::RES_SEARCH_ENTRY:
|
case nsILDAPMessage::RES_SEARCH_ENTRY:
|
||||||
if (!mFinished && !mWaitingForPrevQueryToFinish)
|
if (!mFinished && !mWaitingForPrevQueryToFinish)
|
||||||
{
|
{
|
||||||
rv = OnLDAPMessageSearchEntry (aMessage, getter_AddRefs (queryResult));
|
rv = OnLDAPMessageSearchEntry (aMessage,
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
getter_AddRefs (queryResult));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case nsILDAPMessage::RES_SEARCH_RESULT:
|
case nsILDAPMessage::RES_SEARCH_RESULT:
|
||||||
|
@ -507,106 +509,82 @@ nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchEntry (nsILDAPMessage
|
||||||
nsIAbDirectoryQueryResult** result)
|
nsIAbDirectoryQueryResult** result)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsISupportsArray> propertyValues;
|
|
||||||
|
|
||||||
|
// the address book fields that we'll be asking for
|
||||||
CharPtrArrayGuard properties;
|
CharPtrArrayGuard properties;
|
||||||
rv = mQueryArguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr());
|
rv = mQueryArguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr());
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
CharPtrArrayGuard attrs;
|
// the map for translating between LDAP attrs <-> addrbook fields
|
||||||
rv = aMessage->GetAttributes(attrs.GetSizeAddr(), attrs.GetArrayAddr());
|
nsCOMPtr<nsISupports> iSupportsMap;
|
||||||
|
rv = mQueryArguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMap> map = do_QueryInterface(iSupportsMap, &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCAutoString propertyName;
|
// set up variables for handling the property values to be returned
|
||||||
for (PRUint32 i = 0; i < properties.GetSize(); i++)
|
nsCOMPtr<nsISupportsArray> propertyValues;
|
||||||
{
|
nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue;
|
||||||
propertyName.Assign (properties[i]);
|
rv = NS_NewISupportsArray(getter_AddRefs(propertyValues));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
if (!strcmp(properties[0], "card:nsIAbCard")) {
|
||||||
|
// Meta property
|
||||||
|
nsCAutoString dn;
|
||||||
|
rv = aMessage->GetDn (dn);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsAbDirectoryQueryPropertyValue* _propertyValue = 0;
|
nsCOMPtr<nsIAbCard> card;
|
||||||
if (propertyName.Equals("card:nsIAbCard"))
|
rv = mDirectoryQuery->CreateCard (mUrl, dn.get(), getter_AddRefs (card));
|
||||||
{
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
// Meta property
|
|
||||||
nsCAutoString dn;
|
|
||||||
rv = aMessage->GetDn (dn);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIAbCard> card;
|
rv = map->SetCardPropertiesFromLDAPMessage(aMessage, card);
|
||||||
rv = mDirectoryQuery->CreateCard (mUrl, dn.get(), getter_AddRefs (card));
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
PRBool hasSetCardProperty = PR_FALSE;
|
propertyValue = new nsAbDirectoryQueryPropertyValue(properties[0], card);
|
||||||
rv = MozillaLdapPropertyRelator::createCardPropertyFromLDAPMessage (aMessage,
|
if (!propertyValue)
|
||||||
card,
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
&hasSetCardProperty);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (!hasSetCardProperty)
|
rv = propertyValues->AppendElement(propertyValue);
|
||||||
continue;
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
} else {
|
||||||
|
|
||||||
_propertyValue = new nsAbDirectoryQueryPropertyValue(propertyName.get (), card);
|
for (PRUint32 i = 0; i < properties.GetSize(); i++)
|
||||||
if (_propertyValue == NULL)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (propertyName.get ()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const MozillaLdapPropertyRelation* relation ;
|
|
||||||
|
|
||||||
for (PRUint32 j = 0; j < attrs.GetSize(); j++)
|
|
||||||
{
|
{
|
||||||
relation = MozillaLdapPropertyRelator::findMozillaPropertyFromLdap (attrs[j]);
|
// this is the precedence order list of attrs for this property
|
||||||
if (!relation)
|
CharPtrArrayGuard attrs;
|
||||||
|
rv = map->GetAttributes(nsDependentCString(properties[i]),
|
||||||
|
attrs.GetSizeAddr(),
|
||||||
|
attrs.GetArrayAddr());
|
||||||
|
|
||||||
|
// if there are no attrs for this property, just move on
|
||||||
|
if (NS_FAILED(rv) || !strlen(attrs[0])) {
|
||||||
continue;
|
continue;
|
||||||
/*
|
}
|
||||||
* This change is necessary due to a side effect of #124022. The list of
|
|
||||||
* requested attributes is created in reverse order than how they appear
|
|
||||||
* in nsAbLDAPProperties.cpp. Thus while "surname" and "sn" both map to
|
|
||||||
* LastName, "sn" will be returned by findLdapPropertyFromMozilla() as it
|
|
||||||
* appears first in the hash table but "surname" will be returned by the
|
|
||||||
* request.
|
|
||||||
*
|
|
||||||
* Rather than simply reversing the order, an alternative is to compare
|
|
||||||
* the mapped Mozilla attributes where a one to one match exists.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (nsCRT::strcasecmp (relation->mozillaProperty, propertyName.get()) == 0)
|
// iterate through list, until first property found
|
||||||
{
|
for (PRUint32 j=0; j < attrs.GetSize(); j++) {
|
||||||
|
|
||||||
|
// try and get the values for this ldap attribute
|
||||||
PRUnicharPtrArrayGuard vals;
|
PRUnicharPtrArrayGuard vals;
|
||||||
rv = aMessage->GetValues (attrs[j], vals.GetSizeAddr(), vals.GetArrayAddr());
|
rv = aMessage->GetValues(attrs[j], vals.GetSizeAddr(),
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
vals.GetArrayAddr());
|
||||||
|
|
||||||
if (vals.GetSize() == 0)
|
if (NS_SUCCEEDED(rv) && vals.GetSize()) {
|
||||||
|
propertyValue = new nsAbDirectoryQueryPropertyValue(
|
||||||
|
properties[i], vals[0]);
|
||||||
|
if (!propertyValue) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)propertyValues->AppendElement (propertyValue);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
_propertyValue = new nsAbDirectoryQueryPropertyValue(propertyName.get (), vals[0]);
|
|
||||||
if (_propertyValue == NULL)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_propertyValue)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue;
|
|
||||||
propertyValue = _propertyValue;
|
|
||||||
|
|
||||||
if (!propertyValues)
|
|
||||||
{
|
|
||||||
NS_NewISupportsArray(getter_AddRefs(propertyValues));
|
|
||||||
}
|
|
||||||
|
|
||||||
propertyValues->AppendElement (propertyValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!propertyValues)
|
return QueryResultStatus (propertyValues, result, nsIAbDirectoryQueryResult::queryResultMatch);
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
return QueryResultStatus (propertyValues, result,nsIAbDirectoryQueryResult::queryResultMatch);
|
|
||||||
}
|
}
|
||||||
nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchResult (nsILDAPMessage *aMessage,
|
nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchResult (nsILDAPMessage *aMessage,
|
||||||
nsIAbDirectoryQueryResult** result)
|
nsIAbDirectoryQueryResult** result)
|
||||||
|
@ -704,7 +682,17 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::DoQuery(nsIAbDirectoryQueryArguments* argu
|
||||||
|
|
||||||
nsCOMPtr<nsIAbBooleanExpression> expression (do_QueryInterface (supportsExpression, &rv));
|
nsCOMPtr<nsIAbBooleanExpression> expression (do_QueryInterface (supportsExpression, &rv));
|
||||||
nsCAutoString filter;
|
nsCAutoString filter;
|
||||||
rv = nsAbBoolExprToLDAPFilter::Convert (expression, filter);
|
|
||||||
|
// figure out how we map attribute names to addressbook fields for this
|
||||||
|
// query
|
||||||
|
nsCOMPtr<nsISupports> iSupportsMap;
|
||||||
|
rv = arguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMap> map = do_QueryInterface(iSupportsMap, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = nsAbBoolExprToLDAPFilter::Convert (map, expression, filter);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -863,33 +851,51 @@ nsresult nsAbLDAPDirectoryQuery::getLdapReturnAttributes (
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
CharPtrArrayGuard properties;
|
CharPtrArrayGuard properties;
|
||||||
rv = arguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr());
|
rv = arguments->GetReturnProperties(properties.GetSizeAddr(),
|
||||||
|
properties.GetArrayAddr());
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCAutoString propertyName;
|
// figure out how we map attribute names to addressbook fields for this
|
||||||
|
// query
|
||||||
|
nsCOMPtr<nsISupports> iSupportsMap;
|
||||||
|
rv = arguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMap> map = do_QueryInterface(iSupportsMap, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
if (!strcmp(properties[0], "card:nsIAbCard")) {
|
||||||
|
// Meta property
|
||||||
|
// require all attributes
|
||||||
|
//
|
||||||
|
rv = map->GetAllCardAttributes(returnAttributes);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetAllSupportedAttributes failed");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool needComma = PR_FALSE;
|
||||||
for (PRUint32 i = 0; i < properties.GetSize(); i++)
|
for (PRUint32 i = 0; i < properties.GetSize(); i++)
|
||||||
{
|
{
|
||||||
propertyName.Assign (properties[i]);
|
nsCAutoString attrs;
|
||||||
|
|
||||||
if (propertyName.Equals("card:nsIAbCard"))
|
// get all the attributes for this property
|
||||||
{
|
rv = map->GetAttributeList(nsDependentCString(properties[i]), attrs);
|
||||||
// Meta property
|
|
||||||
// require all attributes
|
// if there weren't any attrs, just keep going
|
||||||
//
|
if (NS_FAILED(rv) || attrs.IsEmpty()) {
|
||||||
rv = MozillaLdapPropertyRelator::GetAllSupportedLDAPAttributes(returnAttributes);
|
continue;
|
||||||
NS_ASSERTION(NS_SUCCEEDED(rv), "GetAllSupportedLDAPAttributes failed");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MozillaLdapPropertyRelation* tableEntry=
|
// add a comma, if necessary
|
||||||
MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (propertyName.get ());
|
if (needComma) {
|
||||||
if (!tableEntry)
|
returnAttributes.Append(PRUnichar (','));
|
||||||
continue;
|
}
|
||||||
|
|
||||||
if (i)
|
returnAttributes.Append(attrs);
|
||||||
returnAttributes.Append (PRUnichar (','));
|
|
||||||
|
|
||||||
returnAttributes.Append (tableEntry->ldapProperty);
|
// since we've added attrs, we definitely need a comma next time
|
||||||
|
// we're here
|
||||||
|
needComma = PR_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|
|
@ -1,291 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* Sun Microsystems, Inc.
|
|
||||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
||||||
* the Initial Developer. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
|
||||||
*
|
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
||||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
||||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
||||||
* of those above. If you wish to allow use of your version of this file only
|
|
||||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
||||||
* use your version of this file under the terms of the MPL, indicate your
|
|
||||||
* decision by deleting the provisions above and replace them with the notice
|
|
||||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
||||||
* the provisions above, a recipient may use your version of this file under
|
|
||||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
|
|
||||||
#include "nsAbUtils.h"
|
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsString.h"
|
|
||||||
#include "nsReadableUtils.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Table defining the relationship between
|
|
||||||
mozilla card properties and corresponding
|
|
||||||
ldap properties.
|
|
||||||
|
|
||||||
Multiple entries for a mozilla property define
|
|
||||||
there is a many to one relationship between
|
|
||||||
ldap properties and the mozilla counterpart.
|
|
||||||
|
|
||||||
There is a one to one relationship between
|
|
||||||
a mozilla property and the ldap counterpart.
|
|
||||||
If there are multiple entries for a mozilla
|
|
||||||
property the first takes precedence.
|
|
||||||
|
|
||||||
This ensures that
|
|
||||||
|
|
||||||
1) Generality is maintained when mapping from
|
|
||||||
ldap properties to mozilla.
|
|
||||||
2) Consistent round tripping when editing
|
|
||||||
mozilla properties which are stored on
|
|
||||||
an ldap server
|
|
||||||
|
|
||||||
Ldap properties were obtained from existing
|
|
||||||
mozilla code that imported from ldif files,
|
|
||||||
comments above each table row indicate which
|
|
||||||
class of ldap object the property belongs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static MozillaLdapPropertyRelation mozillaLdapPropertyTable[] =
|
|
||||||
{
|
|
||||||
// inetOrgPerson
|
|
||||||
{MozillaProperty_String, "FirstName", "givenname"},
|
|
||||||
// person
|
|
||||||
{MozillaProperty_String, "LastName", "sn"},
|
|
||||||
// person
|
|
||||||
{MozillaProperty_String, "LastName", "surname"},
|
|
||||||
// person
|
|
||||||
{MozillaProperty_String, "DisplayName", "cn"},
|
|
||||||
// person
|
|
||||||
{MozillaProperty_String, "DisplayName", "commonname"},
|
|
||||||
// inetOrfPerson
|
|
||||||
{MozillaProperty_String, "DisplayName", "displayname"},
|
|
||||||
// mozilla specific
|
|
||||||
{MozillaProperty_String, "NickName", "xmozillanickname"},
|
|
||||||
// inetOrfPerson
|
|
||||||
{MozillaProperty_String, "PrimaryEmail", "mail"},
|
|
||||||
// mozilla specific
|
|
||||||
{MozillaProperty_String, "SecondEmail", "xmozillasecondemail"},
|
|
||||||
// person
|
|
||||||
{MozillaProperty_String, "WorkPhone", "telephonenumber"},
|
|
||||||
// inetOrgPerson
|
|
||||||
{MozillaProperty_String, "HomePhone", "homephone"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "FaxNumber", "fax"},
|
|
||||||
// organizationalPerson
|
|
||||||
{MozillaProperty_String, "FaxNumber", "facsimiletelephonenumber"},
|
|
||||||
// inetOrgPerson
|
|
||||||
{MozillaProperty_String, "PagerNumber", "pager"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "PagerNumber", "pagerphone"},
|
|
||||||
// inetOrgPerson
|
|
||||||
{MozillaProperty_String, "CellularNumber", "mobile"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "CellularNumber", "cellphone"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "CellularNumber", "carphone"},
|
|
||||||
|
|
||||||
// No Home* properties defined yet
|
|
||||||
|
|
||||||
// organizationalPerson
|
|
||||||
{MozillaProperty_String, "WorkAddress", "postofficebox"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkAddress", "streetaddress"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkCity", "l"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkCity", "locality"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkState", "st"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkState", "region"},
|
|
||||||
// organizationalPerson
|
|
||||||
{MozillaProperty_String, "WorkZipCode", "postalcode"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkZipCode", "zip"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkCountry", "countryname"},
|
|
||||||
|
|
||||||
// organizationalPerson
|
|
||||||
{MozillaProperty_String, "JobTitle", "title"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Department", "ou"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Department", "orgunit"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Department", "department"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Department", "departmentnumber"},
|
|
||||||
// inetOrgPerson
|
|
||||||
{MozillaProperty_String, "Company", "o"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Company", "company"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WorkCountry", "countryname"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "_AimScreenName", "nscpaimscreenname"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WebPage1", "workurl"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "WebPage2", "homeurl"},
|
|
||||||
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "BirthYear", "birthyear"},
|
|
||||||
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Custom1", "custom1"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Custom2", "custom2"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Custom3", "custom3"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Custom4", "custom4"},
|
|
||||||
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_String, "Notes", "notes"},
|
|
||||||
// person
|
|
||||||
{MozillaProperty_String, "Notes", "description"},
|
|
||||||
|
|
||||||
// mozilla specfic
|
|
||||||
{MozillaProperty_Int, "PreferMailFormat", "xmozillausehtmlmail"},
|
|
||||||
// ?
|
|
||||||
{MozillaProperty_Int, "LastModifiedDate", "modifytimestamp"}
|
|
||||||
};
|
|
||||||
|
|
||||||
const MozillaLdapPropertyRelation* MozillaLdapPropertyRelator::table = mozillaLdapPropertyTable;
|
|
||||||
const int MozillaLdapPropertyRelator::tableSize = sizeof (mozillaLdapPropertyTable) / sizeof (MozillaLdapPropertyRelation);
|
|
||||||
|
|
||||||
static const char * sLDAPChangeLogRootDSEAttribs[] =
|
|
||||||
{
|
|
||||||
"changelog",
|
|
||||||
"firstChangeNumber",
|
|
||||||
"lastChangeNumber",
|
|
||||||
"dataVersion"
|
|
||||||
};
|
|
||||||
static const char * sLDAPChangeLogEntryAttribs[] =
|
|
||||||
{
|
|
||||||
"targetdn",
|
|
||||||
"changetype"
|
|
||||||
};
|
|
||||||
|
|
||||||
const char ** MozillaLdapPropertyRelator::changeLogRootDSEAttribs = sLDAPChangeLogRootDSEAttribs;
|
|
||||||
const int MozillaLdapPropertyRelator::rootDSEAttribCount = sizeof(sLDAPChangeLogRootDSEAttribs)/sizeof(char**);
|
|
||||||
const char ** MozillaLdapPropertyRelator::changeLogEntryAttribs = sLDAPChangeLogEntryAttribs;
|
|
||||||
const int MozillaLdapPropertyRelator::changeLogEntryAttribCount = sizeof(sLDAPChangeLogEntryAttribs)/sizeof(char**);
|
|
||||||
|
|
||||||
PRBool MozillaLdapPropertyRelator::IsInitialized = PR_FALSE ;
|
|
||||||
nsHashtable MozillaLdapPropertyRelator::mMozillaToLdap;
|
|
||||||
nsHashtable MozillaLdapPropertyRelator::mLdapToMozilla;
|
|
||||||
|
|
||||||
void MozillaLdapPropertyRelator::Initialize(void)
|
|
||||||
{
|
|
||||||
if (IsInitialized) { return ; }
|
|
||||||
|
|
||||||
for (int i = tableSize - 1 ; i >= 0 ; -- i) {
|
|
||||||
nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
|
|
||||||
nsCStringKey keyLdap (table [i].ldapProperty, -1, nsCStringKey::NEVER_OWN);
|
|
||||||
|
|
||||||
mLdapToMozilla.Put(&keyLdap, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
|
|
||||||
mMozillaToLdap.Put(&keyMozilla, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
|
|
||||||
}
|
|
||||||
IsInitialized = PR_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult MozillaLdapPropertyRelator::GetAllSupportedLDAPAttributes(nsCString &aResult)
|
|
||||||
{
|
|
||||||
if (tableSize < 1)
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
|
||||||
|
|
||||||
for (int i = tableSize - 1 ; i != 0 ; i--)
|
|
||||||
aResult += nsDependentCString(table[i].ldapProperty) + NS_LITERAL_CSTRING(",");
|
|
||||||
|
|
||||||
aResult += table[0].ldapProperty;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MozillaLdapPropertyRelation* MozillaLdapPropertyRelator::findMozillaPropertyFromLdap (const char* ldapProperty)
|
|
||||||
{
|
|
||||||
Initialize();
|
|
||||||
// ensure that we always do a case insensitive comparison
|
|
||||||
// against the incoming ldap attributes.
|
|
||||||
nsCAutoString lowercasedProp(ldapProperty);
|
|
||||||
ToLowerCase(nsDependentCString(ldapProperty), lowercasedProp);
|
|
||||||
nsCStringKey key(lowercasedProp);
|
|
||||||
|
|
||||||
return NS_REINTERPRET_CAST(const MozillaLdapPropertyRelation *, mLdapToMozilla.Get(&key)) ;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const MozillaLdapPropertyRelation* MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (const char* mozillaProperty)
|
|
||||||
{
|
|
||||||
Initialize();
|
|
||||||
nsCStringKey key (mozillaProperty) ;
|
|
||||||
|
|
||||||
return NS_REINTERPRET_CAST(const MozillaLdapPropertyRelation *, mMozillaToLdap.Get(&key)) ;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult MozillaLdapPropertyRelator::createCardPropertyFromLDAPMessage (nsILDAPMessage* message,
|
|
||||||
nsIAbCard* card,
|
|
||||||
PRBool* hasSetCardProperty)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
CharPtrArrayGuard attrs;
|
|
||||||
|
|
||||||
rv = message->GetAttributes(attrs.GetSizeAddr(), attrs.GetArrayAddr());
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
*hasSetCardProperty = PR_FALSE;
|
|
||||||
for (PRUint32 i = 0; i < attrs.GetSize(); i++)
|
|
||||||
{
|
|
||||||
const MozillaLdapPropertyRelation* property = findMozillaPropertyFromLdap (attrs[i]);
|
|
||||||
if (!property)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
PRUnicharPtrArrayGuard vals;
|
|
||||||
rv = message->GetValues(attrs.GetArray()[i], vals.GetSizeAddr(), vals.GetArrayAddr());
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (vals.GetSize())
|
|
||||||
{
|
|
||||||
rv = card->SetCardValue (property->mozillaProperty, vals[0]);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
*hasSetCardProperty = PR_TRUE;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rv = NS_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
|
@ -1,90 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* Sun Microsystems, Inc.
|
|
||||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
||||||
* the Initial Developer. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
* Created by: Paul Sandoz <paul.sandoz@sun.com>
|
|
||||||
*
|
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
||||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
||||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
||||||
* of those above. If you wish to allow use of your version of this file only
|
|
||||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
||||||
* use your version of this file under the terms of the MPL, indicate your
|
|
||||||
* decision by deleting the provisions above and replace them with the notice
|
|
||||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
||||||
* the provisions above, a recipient may use your version of this file under
|
|
||||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
#ifndef nsAbLDAPProperties_h__
|
|
||||||
#define nsAbLDAPProperties_h__
|
|
||||||
|
|
||||||
#include "nsILDAPMessage.h"
|
|
||||||
#include "nsIAbCard.h"
|
|
||||||
#include "nsHashtable.h"
|
|
||||||
|
|
||||||
#define NS_LDAPCONNECTION_CONTRACTID "@mozilla.org/network/ldap-connection;1"
|
|
||||||
#define NS_LDAPOPERATION_CONTRACTID "@mozilla.org/network/ldap-operation;1"
|
|
||||||
#define NS_LDAPMESSAGE_CONTRACTID "@mozilla.org/network/ldap-message;1"
|
|
||||||
#define NS_LDAPURL_CONTRACTID "@mozilla.org/network/ldap-url;1"
|
|
||||||
|
|
||||||
enum MozillaPropertyType
|
|
||||||
{
|
|
||||||
MozillaProperty_String,
|
|
||||||
MozillaProperty_Boolean,
|
|
||||||
MozillaProperty_Int
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MozillaLdapPropertyRelation
|
|
||||||
{
|
|
||||||
MozillaPropertyType mozillaPropertyType;
|
|
||||||
const char* mozillaProperty;
|
|
||||||
const char* ldapProperty;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MozillaLdapPropertyRelator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const MozillaLdapPropertyRelation* table;
|
|
||||||
static const int tableSize;
|
|
||||||
static nsHashtable mLdapToMozilla ;
|
|
||||||
static nsHashtable mMozillaToLdap ;
|
|
||||||
static PRBool IsInitialized;
|
|
||||||
|
|
||||||
static const char ** changeLogRootDSEAttribs;
|
|
||||||
static const char ** changeLogEntryAttribs;
|
|
||||||
|
|
||||||
static const int rootDSEAttribCount;
|
|
||||||
static const int changeLogEntryAttribCount;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const MozillaLdapPropertyRelation* findMozillaPropertyFromLdap (const char* ldapProperty);
|
|
||||||
static const MozillaLdapPropertyRelation* findLdapPropertyFromMozilla (const char* mozillaProperty);
|
|
||||||
static void Initialize(void);
|
|
||||||
static nsresult GetAllSupportedLDAPAttributes(nsCString &aResult);
|
|
||||||
static nsresult createCardPropertyFromLDAPMessage (nsILDAPMessage* message,
|
|
||||||
nsIAbCard* card,
|
|
||||||
PRBool* hasSetCardProperty);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -21,6 +21,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
@ -36,7 +37,7 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#include "nsILDAPMessage.h"
|
||||||
#include "nsAbLDAPReplicationData.h"
|
#include "nsAbLDAPReplicationData.h"
|
||||||
#include "nsLDAP.h"
|
#include "nsLDAP.h"
|
||||||
#include "nsIAbCard.h"
|
#include "nsIAbCard.h"
|
||||||
|
@ -45,7 +46,6 @@
|
||||||
#include "nsAbUtils.h"
|
#include "nsAbUtils.h"
|
||||||
#include "nsAbMDBCard.h"
|
#include "nsAbMDBCard.h"
|
||||||
#include "nsAbLDAPCard.h"
|
#include "nsAbLDAPCard.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
#include "nsAbLDAPReplicationQuery.h"
|
#include "nsAbLDAPReplicationQuery.h"
|
||||||
#include "nsProxiedService.h"
|
#include "nsProxiedService.h"
|
||||||
#include "nsCPasswordManager.h"
|
#include "nsCPasswordManager.h"
|
||||||
|
@ -90,6 +90,15 @@ NS_IMETHODIMP nsAbLDAPProcessReplicationData::Init(nsIAbLDAPReplicationQuery *qu
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMapService> mapSvc =
|
||||||
|
do_GetService("@mozilla.org/addressbook/ldap-attribute-map-service;1",
|
||||||
|
&rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = mapSvc->GetMapForPrefBranch(
|
||||||
|
nsDependentCString(mDirServerInfo->prefName), getter_AddRefs(mAttrMap));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
mListener = progressListener;
|
mListener = progressListener;
|
||||||
|
|
||||||
mInitialized = PR_TRUE;
|
mInitialized = PR_TRUE;
|
||||||
|
@ -326,19 +335,12 @@ nsresult nsAbLDAPProcessReplicationData::OnLDAPSearchEntry(nsILDAPMessage *aMess
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
nsAbLDAPCard card;
|
nsAbLDAPCard card;
|
||||||
PRBool hasSetCardProperty = PR_FALSE;
|
|
||||||
|
|
||||||
nsresult rv = MozillaLdapPropertyRelator::createCardPropertyFromLDAPMessage(aMessage,
|
nsresult rv = mAttrMap->SetCardPropertiesFromLDAPMessage(aMessage, &card);
|
||||||
&card, &hasSetCardProperty);
|
if (NS_FAILED(rv))
|
||||||
if(NS_FAILED(rv)) {
|
|
||||||
Abort();
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hasSetCardProperty == PR_FALSE)
|
|
||||||
{
|
{
|
||||||
NS_WARNING("nsAbLDAPProcessReplicationData::OnLDAPSearchEntry"
|
NS_WARNING("nsAbLDAPProcessReplicationData::OnLDAPSearchEntry"
|
||||||
"No card Properties found and set");
|
"No card properties could be set");
|
||||||
// if some entries are bogus for us, continue with next one
|
// if some entries are bogus for us, continue with next one
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
#include "nsIAddrDatabase.h"
|
#include "nsIAddrDatabase.h"
|
||||||
#include "nsILocalFile.h"
|
#include "nsILocalFile.h"
|
||||||
#include "nsDirPrefs.h"
|
#include "nsDirPrefs.h"
|
||||||
|
#include "nsIAbLDAPAttributeMap.h"
|
||||||
|
|
||||||
class nsAbLDAPProcessReplicationData : public nsIAbLDAPProcessReplicationData
|
class nsAbLDAPProcessReplicationData : public nsIAbLDAPProcessReplicationData
|
||||||
{
|
{
|
||||||
|
@ -76,6 +78,7 @@ protected :
|
||||||
DIR_Server * mDirServerInfo;
|
DIR_Server * mDirServerInfo;
|
||||||
nsCString mAuthDN; // authDN of the user
|
nsCString mAuthDN; // authDN of the user
|
||||||
nsCString mAuthPswd; // pswd of the authDN user
|
nsCString mAuthPswd; // pswd of the authDN user
|
||||||
|
nsCOMPtr<nsIAbLDAPAttributeMap> mAttrMap; // maps ab properties to ldap attrs
|
||||||
|
|
||||||
virtual nsresult OnLDAPBind(nsILDAPMessage *aMessage);
|
virtual nsresult OnLDAPBind(nsILDAPMessage *aMessage);
|
||||||
virtual nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage);
|
virtual nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage);
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include "nsAbLDAPReplicationData.h"
|
#include "nsAbLDAPReplicationData.h"
|
||||||
#include "nsILDAPURL.h"
|
#include "nsILDAPURL.h"
|
||||||
#include "nsAbBaseCID.h"
|
#include "nsAbBaseCID.h"
|
||||||
#include "nsAbLDAPProperties.h"
|
|
||||||
#include "nsProxiedService.h"
|
#include "nsProxiedService.h"
|
||||||
#include "nsLDAP.h"
|
#include "nsLDAP.h"
|
||||||
#include "nsAbUtils.h"
|
#include "nsAbUtils.h"
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
|
* Dan Mosedale <dan.mosedale@oracle.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
|
@ -274,6 +275,37 @@ pref("ldap_2.servers.history.description", "chrome://messenger/locale/addre
|
||||||
pref("ldap_2.servers.history.dirType", 2);
|
pref("ldap_2.servers.history.dirType", 2);
|
||||||
pref("ldap_2.servers.history.isOffline", false);
|
pref("ldap_2.servers.history.isOffline", false);
|
||||||
|
|
||||||
|
// default mapping of addressbook properties to ldap attributes
|
||||||
|
pref("ldap_2.servers.default.attrmap.FirstName", "givenname");
|
||||||
|
pref("ldap_2.servers.default.attrmap.LastName", "sn,surname");
|
||||||
|
pref("ldap_2.servers.default.attrmap.DisplayName", "displayname,cn,commonname");
|
||||||
|
pref("ldap_2.servers.default.attrmap.NickName", "xmozillanickname");
|
||||||
|
pref("ldap_2.servers.default.attrmap.PrimaryEmail", "mail");
|
||||||
|
pref("ldap_2.servers.default.attrmap.SecondEmail", "xmozillasecondemail");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WorkPhone", "telephonenumber");
|
||||||
|
pref("ldap_2.servers.default.attrmap.HomePhone", "homephone");
|
||||||
|
pref("ldap_2.servers.default.attrmap.FaxNumber", "fax,facsimiletelephonenumber");
|
||||||
|
pref("ldap_2.servers.default.attrmap.PagerNumber", "pager,pagerphone");
|
||||||
|
pref("ldap_2.servers.default.attrmap.CellularNumber", "mobile,cellphone,carphone");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WorkAddress", "streetaddress,postofficebox");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WorkCity", "l,locality");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WorkState", "st,region");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WorkZipCode", "zip,postalcode");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WorkCountry", "countryname");
|
||||||
|
pref("ldap_2.servers.default.attrmap.JobTitle", "title");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Department", "department,departmentnumber,ou,orgunit");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Company", "company,o");
|
||||||
|
pref("ldap_2.servers.default.attrmap._AimScreenName", "nscpaimscreenname");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WebPage1", "workurl");
|
||||||
|
pref("ldap_2.servers.default.attrmap.WebPage2", "homeurl");
|
||||||
|
pref("ldap_2.servers.default.attrmap.BirthYear", "birthyear");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Custom1", "custom1");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Custom2", "custom2");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Custom3", "custom3");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Custom4", "custom4");
|
||||||
|
pref("ldap_2.servers.default.attrmap.Notes", "notes,description");
|
||||||
|
pref("ldap_2.servers.default.attrmap.PreferMailFormat", "xmozillausehtmlmail");
|
||||||
|
pref("ldap_2.servers.default.attrmap.LastModifiedDate", "modifytimestamp");
|
||||||
|
|
||||||
// A position of zero is a special value that indicates the directory is deleted.
|
// A position of zero is a special value that indicates the directory is deleted.
|
||||||
// These entries are provided to keep the (obsolete) Four11 directory and the
|
// These entries are provided to keep the (obsolete) Four11 directory and the
|
||||||
|
|
Загрузка…
Ссылка в новой задаче