From 32b9b7c267726d2df1a6398261ac8a2df432f7a2 Mon Sep 17 00:00:00 2001 From: "dmose%mozilla.org" Date: Wed, 11 May 2005 04:16:54 +0000 Subject: [PATCH] Make LDAP attributes used by the addressbook customizable via preferences (bug 119291). r=bienvenu@nventure.com, sr+a=shaver@mozilla.org --- directory/xpcom/base/public/nsLDAP.h | 5 + mail/config/basemail-os2 | 1 + mail/config/basemail-unix | 1 + mail/installer/windows/basemail-win | 1 + mailnews/addrbook/Makefile.in | 3 +- mailnews/addrbook/public/Makefile.in | 3 +- .../addrbook/public/nsIAbDirectoryQuery.idl | 8 + .../addrbook/public/nsIAbLDAPAttributeMap.idl | 216 +++++++++++ mailnews/addrbook/src/Makefile.in | 2 +- .../addrbook/src/nsAbBoolExprToLDAPFilter.cpp | 51 +-- .../addrbook/src/nsAbBoolExprToLDAPFilter.h | 7 + mailnews/addrbook/src/nsAbDirectoryQuery.cpp | 16 + mailnews/addrbook/src/nsAbDirectoryQuery.h | 2 + mailnews/addrbook/src/nsAbLDAPAttributeMap.js | 347 ++++++++++++++++++ .../addrbook/src/nsAbLDAPChangeLogData.cpp | 3 +- mailnews/addrbook/src/nsAbLDAPChangeLogData.h | 1 + .../addrbook/src/nsAbLDAPChangeLogQuery.cpp | 37 +- .../addrbook/src/nsAbLDAPChangeLogQuery.h | 6 +- mailnews/addrbook/src/nsAbLDAPDirectory.cpp | 20 +- .../addrbook/src/nsAbLDAPDirectoryQuery.cpp | 206 ++++++----- mailnews/addrbook/src/nsAbLDAPProperties.cpp | 291 --------------- mailnews/addrbook/src/nsAbLDAPProperties.h | 90 ----- .../addrbook/src/nsAbLDAPReplicationData.cpp | 26 +- .../addrbook/src/nsAbLDAPReplicationData.h | 3 + .../addrbook/src/nsAbLDAPReplicationQuery.cpp | 1 - mailnews/mailnews.js | 32 ++ 26 files changed, 842 insertions(+), 537 deletions(-) create mode 100644 mailnews/addrbook/public/nsIAbLDAPAttributeMap.idl create mode 100644 mailnews/addrbook/src/nsAbLDAPAttributeMap.js delete mode 100644 mailnews/addrbook/src/nsAbLDAPProperties.cpp delete mode 100644 mailnews/addrbook/src/nsAbLDAPProperties.h diff --git a/directory/xpcom/base/public/nsLDAP.h b/directory/xpcom/base/public/nsLDAP.h index 5a5f670dca9f..66aacbacaa72 100644 --- a/directory/xpcom/base/public/nsLDAP.h +++ b/directory/xpcom/base/public/nsLDAP.h @@ -44,3 +44,8 @@ #ifdef PR_LOGGING extern PRLogModuleInfo *gLDAPLogModule; // defn in nsLDAPProtocolModule.cpp #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" diff --git a/mail/config/basemail-os2 b/mail/config/basemail-os2 index 427659d4c54a..8d996d0b407f 100644 --- a/mail/config/basemail-os2 +++ b/mail/config/basemail-os2 @@ -70,6 +70,7 @@ defaults\profile\US\mimeTypes.rdf components\mozldap.dll components\mozldap.xpt components\nsLDAPPrefsService.js +components\nsAbLDAPAttributeMap.js ldap50.dll prldap50.dll diff --git a/mail/config/basemail-unix b/mail/config/basemail-unix index f7d7909b9d33..d0cbe760bff0 100644 --- a/mail/config/basemail-unix +++ b/mail/config/basemail-unix @@ -76,6 +76,7 @@ defaults/isp/movemail.rdf components/libmozldap.so components/mozldap.xpt components/nsLDAPPrefsService.js +components/nsAbLDAPAttributeMap.js libldap50.so libprldap50.so diff --git a/mail/installer/windows/basemail-win b/mail/installer/windows/basemail-win index 50ddb6dd7baa..69ee3f82e782 100644 --- a/mail/installer/windows/basemail-win +++ b/mail/installer/windows/basemail-win @@ -129,6 +129,7 @@ bin\greprefs\ ; LDAP components bin\components\mozldap.xpt bin\components\nsLDAPPrefsService.js +bin\components\nsAbLDAPAttributeMap.js bin\nsldap32v50.dll bin\nsldappr32v50.dll diff --git a/mailnews/addrbook/Makefile.in b/mailnews/addrbook/Makefile.in index 04e53d745589..10e7407a65a4 100644 --- a/mailnews/addrbook/Makefile.in +++ b/mailnews/addrbook/Makefile.in @@ -20,6 +20,7 @@ # the Initial Developer. All Rights Reserved. # # Contributor(s): +# Dan Mosedale # # 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"), @@ -44,7 +45,7 @@ include $(DEPTH)/config/autoconf.mk ifdef MOZ_LDAP_XPCOM REQUIRES += mozldap necko -EXTRA_COMPONENTS += src/nsLDAPPrefsService.js +EXTRA_COMPONENTS += src/nsLDAPPrefsService.js src/nsAbLDAPAttributeMap.js endif DIRS = public src diff --git a/mailnews/addrbook/public/Makefile.in b/mailnews/addrbook/public/Makefile.in index d021377da527..c952c452c4c2 100644 --- a/mailnews/addrbook/public/Makefile.in +++ b/mailnews/addrbook/public/Makefile.in @@ -20,6 +20,7 @@ # the Initial Developer. All Rights Reserved. # # Contributor(s): +# Dan Mosedale # # 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"), @@ -76,8 +77,8 @@ XPIDLSRCS += \ nsIAbLDAPReplicationService.idl \ nsIAbLDAPReplicationQuery.idl \ nsIAbLDAPReplicationData.idl \ + nsIAbLDAPAttributeMap.idl \ $(NULL) endif include $(topsrcdir)/config/rules.mk - diff --git a/mailnews/addrbook/public/nsIAbDirectoryQuery.idl b/mailnews/addrbook/public/nsIAbDirectoryQuery.idl index ddcc91ea809e..5d783732c613 100644 --- a/mailnews/addrbook/public/nsIAbDirectoryQuery.idl +++ b/mailnews/addrbook/public/nsIAbDirectoryQuery.idl @@ -21,6 +21,7 @@ * * Contributor(s): * Created by: Paul Sandoz + * Dan Mosedale * * 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"), @@ -77,6 +78,13 @@ interface nsIAbDirectoryQueryArguments : nsISupports void getReturnProperties (out unsigned long returnPropertiesSize, [retval, array, size_is(returnPropertiesSize)] 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; }; diff --git a/mailnews/addrbook/public/nsIAbLDAPAttributeMap.idl b/mailnews/addrbook/public/nsIAbLDAPAttributeMap.idl new file mode 100644 index 000000000000..ab745ddd2cf0 --- /dev/null +++ b/mailnews/addrbook/public/nsIAbLDAPAttributeMap.idl @@ -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 + * + * 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()) +%} diff --git a/mailnews/addrbook/src/Makefile.in b/mailnews/addrbook/src/Makefile.in index b996f49017d6..24d1892d72f4 100644 --- a/mailnews/addrbook/src/Makefile.in +++ b/mailnews/addrbook/src/Makefile.in @@ -20,6 +20,7 @@ # the Initial Developer. All Rights Reserved. # # Contributor(s): +# Dan Mosedale # # 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"), @@ -138,7 +139,6 @@ REQUIRES += mozldap \ CPPSRCS += nsAbLDAPDirectory.cpp \ nsAbLDAPDirFactory.cpp \ nsAbLDAPCard.cpp \ - nsAbLDAPProperties.cpp \ nsAbLDAPDirectoryQuery.cpp \ nsAbBoolExprToLDAPFilter.cpp \ nsAbLDAPAutoCompFormatter.cpp \ diff --git a/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp b/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp index e4ba9c59d03e..6137f99e741f 100644 --- a/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp +++ b/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Created by: Paul Sandoz + * Dan Mosedale * * 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"), @@ -36,14 +37,15 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIAbLDAPAttributeMap.h" #include "nsAbBoolExprToLDAPFilter.h" -#include "nsAbLDAPProperties.h" #include "nsXPIDLString.h" const int nsAbBoolExprToLDAPFilter::TRANSLATE_CARD_PROPERTY = 1 << 0 ; const int nsAbBoolExprToLDAPFilter::ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1 ; nsresult nsAbBoolExprToLDAPFilter::Convert ( + nsIAbLDAPAttributeMap* map, nsIAbBooleanExpression* expression, nsCString& filter, int flags) @@ -51,7 +53,7 @@ nsresult nsAbBoolExprToLDAPFilter::Convert ( nsresult rv; nsCString f; - rv = FilterExpression (expression, f, flags); + rv = FilterExpression (map, expression, f, flags); NS_ENSURE_SUCCESS(rv, rv); filter = f; @@ -59,6 +61,7 @@ nsresult nsAbBoolExprToLDAPFilter::Convert ( } nsresult nsAbBoolExprToLDAPFilter::FilterExpression ( + nsIAbLDAPAttributeMap* map, nsIAbBooleanExpression* expression, nsCString& filter, int flags) @@ -114,17 +117,17 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpression ( { case nsIAbBooleanOperationTypes::AND: filter.AppendLiteral("&"); - rv = FilterExpressions (childExpressions, filter, flags); + rv = FilterExpressions (map, childExpressions, filter, flags); break; case nsIAbBooleanOperationTypes::OR: filter.AppendLiteral("|"); - rv = FilterExpressions (childExpressions, filter, flags); + rv = FilterExpressions (map, childExpressions, filter, flags); break; case nsIAbBooleanOperationTypes::NOT: if (count > 1) return NS_ERROR_FAILURE; filter.AppendLiteral("!"); - rv = FilterExpressions (childExpressions, filter, flags); + rv = FilterExpressions (map, childExpressions, filter, flags); break; default: break; @@ -135,6 +138,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpression ( } nsresult nsAbBoolExprToLDAPFilter::FilterExpressions ( + nsIAbLDAPAttributeMap *map, nsISupportsArray* expressions, nsCString& filter, int flags) @@ -154,7 +158,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpressions ( nsCOMPtr childCondition(do_QueryInterface(item, &rv)); if (NS_SUCCEEDED(rv)) { - rv = FilterCondition (childCondition, filter, flags); + rv = FilterCondition (map, childCondition, filter, flags); NS_ENSURE_SUCCESS(rv, rv); continue; } @@ -162,7 +166,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpressions ( nsCOMPtr childExpression(do_QueryInterface(item, &rv)); if (NS_SUCCEEDED(rv)) { - rv = FilterExpression (childExpression, filter, flags); + rv = FilterExpression (map, childExpression, filter, flags); NS_ENSURE_SUCCESS(rv, rv); continue; } @@ -172,6 +176,7 @@ nsresult nsAbBoolExprToLDAPFilter::FilterExpressions ( } nsresult nsAbBoolExprToLDAPFilter::FilterCondition ( + nsIAbLDAPAttributeMap* map, nsIAbBooleanConditionString* condition, nsCString& filter, int flags) @@ -186,14 +191,12 @@ nsresult nsAbBoolExprToLDAPFilter::FilterCondition ( rv = condition->GetName (getter_Copies (name)); NS_ENSURE_SUCCESS(rv, rv); - const char* ldapProperty = name.get (); + nsCAutoString ldapAttr(name); if (flags & TRANSLATE_CARD_PROPERTY) { - const MozillaLdapPropertyRelation* p = - MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ()); - if (p) - ldapProperty = p->ldapProperty; - else if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY)) + rv = map->GetFirstAttribute (name, ldapAttr); + if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY) && + !ATTRMAP_FOUND_ATTR(rv, ldapAttr)) return NS_OK; } @@ -206,73 +209,73 @@ nsresult nsAbBoolExprToLDAPFilter::FilterCondition ( { case nsIAbBooleanConditionTypes::DoesNotExist: filter += NS_LITERAL_CSTRING("(!(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=*))"); break; case nsIAbBooleanConditionTypes::Exists: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=*)"); break; case nsIAbBooleanConditionTypes::Contains: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=*") + vUTF8 + NS_LITERAL_CSTRING("*)"); break; case nsIAbBooleanConditionTypes::DoesNotContain: filter += NS_LITERAL_CSTRING("(!(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=*") + vUTF8 + NS_LITERAL_CSTRING("*))"); break; case nsIAbBooleanConditionTypes::Is: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=") + vUTF8 + NS_LITERAL_CSTRING(")"); break; case nsIAbBooleanConditionTypes::IsNot: filter += NS_LITERAL_CSTRING("(!(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=") + vUTF8 + NS_LITERAL_CSTRING("))"); break; case nsIAbBooleanConditionTypes::BeginsWith: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=") + vUTF8 + NS_LITERAL_CSTRING("*)"); break; case nsIAbBooleanConditionTypes::EndsWith: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("=*") + vUTF8 + NS_LITERAL_CSTRING(")"); break; case nsIAbBooleanConditionTypes::LessThan: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("<=") + vUTF8 + NS_LITERAL_CSTRING(")"); break; case nsIAbBooleanConditionTypes::GreaterThan: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING(">=") + vUTF8 + NS_LITERAL_CSTRING(")"); break; case nsIAbBooleanConditionTypes::SoundsLike: filter += NS_LITERAL_CSTRING("(") + - nsDependentCString(ldapProperty) + + ldapAttr + NS_LITERAL_CSTRING("~=") + vUTF8 + NS_LITERAL_CSTRING(")"); diff --git a/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h b/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h index 42f5a063264a..d3e6c36ef09d 100644 --- a/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h +++ b/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h @@ -21,6 +21,7 @@ * * Contributor(s): * Created by: Paul Sandoz + * Dan Mosedale * * 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"), @@ -43,6 +44,8 @@ #include "nsCOMPtr.h" #include "nsString.h" +class nsIAbLDAPAttributeMap; + class nsAbBoolExprToLDAPFilter { public: @@ -50,20 +53,24 @@ public: static const int ALLOW_NON_CONVERTABLE_CARD_PROPERTY ; static nsresult Convert ( + nsIAbLDAPAttributeMap* map, nsIAbBooleanExpression* expression, nsCString& filter, int flags = TRANSLATE_CARD_PROPERTY); protected: static nsresult FilterExpression ( + nsIAbLDAPAttributeMap* map, nsIAbBooleanExpression* expression, nsCString& filter, int flags); static nsresult FilterExpressions ( + nsIAbLDAPAttributeMap* map, nsISupportsArray* expressions, nsCString& filter, int flags); static nsresult FilterCondition ( + nsIAbLDAPAttributeMap* map, nsIAbBooleanConditionString* condition, nsCString& filter, int flags); diff --git a/mailnews/addrbook/src/nsAbDirectoryQuery.cpp b/mailnews/addrbook/src/nsAbDirectoryQuery.cpp index 480c1d6ce98e..c3ee891b1109 100644 --- a/mailnews/addrbook/src/nsAbDirectoryQuery.cpp +++ b/mailnews/addrbook/src/nsAbDirectoryQuery.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Created by: Paul Sandoz + * Dan Mosedale * * 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"), @@ -206,6 +207,21 @@ NS_IMETHODIMP nsAbDirectoryQueryArguments::GetReturnProperties(PRUint32* returnP 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) nsAbDirectoryQueryPropertyValue::nsAbDirectoryQueryPropertyValue() diff --git a/mailnews/addrbook/src/nsAbDirectoryQuery.h b/mailnews/addrbook/src/nsAbDirectoryQuery.h index ee6ace45473e..89e521f0783a 100644 --- a/mailnews/addrbook/src/nsAbDirectoryQuery.h +++ b/mailnews/addrbook/src/nsAbDirectoryQuery.h @@ -21,6 +21,7 @@ * * Contributor(s): * Created by: Paul Sandoz + * Dan Mosedale * * 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"), @@ -70,6 +71,7 @@ public: protected: nsCOMPtr mExpression; + nsCOMPtr mTypeSpecificArg; PRBool mQuerySubDirectories; nsCStringArray mReturnProperties; }; diff --git a/mailnews/addrbook/src/nsAbLDAPAttributeMap.js b/mailnews/addrbook/src/nsAbLDAPAttributeMap.js new file mode 100644 index 000000000000..804e079973e8 --- /dev/null +++ b/mailnews/addrbook/src/nsAbLDAPAttributeMap.js @@ -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 + * + * 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; +} diff --git a/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp b/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp index bdaee6132fe0..2d3177c9cf46 100644 --- a/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp +++ b/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp @@ -20,6 +20,7 @@ * * Contributor(s): * Rajiv Dayal + * Dan Mosedale * * 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"), @@ -38,13 +39,13 @@ #include "nsAbLDAPChangeLogData.h" #include "nsAbLDAPChangeLogQuery.h" #include "nsLDAP.h" +#include "nsILDAPMessage.h" #include "nsIAbCard.h" #include "nsIAddrBookSession.h" #include "nsAbBaseCID.h" #include "nsAbUtils.h" #include "nsAbMDBCard.h" #include "nsAbLDAPCard.h" -#include "nsAbLDAPProperties.h" #include "nsProxiedService.h" #include "nsAutoLock.h" #include "nsIAuthPrompt.h" diff --git a/mailnews/addrbook/src/nsAbLDAPChangeLogData.h b/mailnews/addrbook/src/nsAbLDAPChangeLogData.h index 79909132f24e..f57bedf68721 100644 --- a/mailnews/addrbook/src/nsAbLDAPChangeLogData.h +++ b/mailnews/addrbook/src/nsAbLDAPChangeLogData.h @@ -20,6 +20,7 @@ * * Contributor(s): * Rajiv Dayal + * Dan Mosedale * * 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"), diff --git a/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp b/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp index c9fc8c8e0e03..0f6a38ee0aca 100644 --- a/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp +++ b/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.cpp @@ -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 * * The contents of this file are subject to the Mozilla Public License Version @@ -41,7 +43,6 @@ #include "nsAbLDAPChangeLogQuery.h" #include "nsAbLDAPReplicationService.h" #include "nsAbLDAPChangeLogData.h" -#include "nsAbLDAPProperties.h" #include "nsAutoLock.h" #include "nsAbUtils.h" #include "prprf.h" @@ -50,6 +51,22 @@ #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) nsAbLDAPChangeLogQuery::nsAbLDAPChangeLogQuery() @@ -137,10 +154,9 @@ NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryRootDSE() nsresult rv = CreateNewLDAPOperation(); NS_ENSURE_SUCCESS(rv, rv); return mOperation->SearchExt(EmptyCString(), nsILDAPURL::SCOPE_BASE, - NS_LITERAL_CSTRING("objectclass=*"), - MozillaLdapPropertyRelator::rootDSEAttribCount, - MozillaLdapPropertyRelator::changeLogRootDSEAttribs, - 0, 0); + NS_LITERAL_CSTRING("objectclass=*"), + sizeof(sChangeLogRootDSEAttribs), + sChangeLogRootDSEAttribs, 0, 0); } NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangeLog(const nsACString & aChangeLogDN, PRInt32 aLastChangeNo) @@ -159,12 +175,9 @@ NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangeLog(const nsACString & aChangeL nsresult rv = CreateNewLDAPOperation(); NS_ENSURE_SUCCESS(rv, rv); - return mOperation->SearchExt(aChangeLogDN, - nsILDAPURL::SCOPE_ONELEVEL, - filter, - MozillaLdapPropertyRelator::changeLogEntryAttribCount, - MozillaLdapPropertyRelator::changeLogEntryAttribs, - 0, 0); + return mOperation->SearchExt(aChangeLogDN, nsILDAPURL::SCOPE_ONELEVEL, filter, + sizeof(sChangeLogEntryAttribs), + sChangeLogEntryAttribs, 0, 0); } NS_IMETHODIMP nsAbLDAPChangeLogQuery::QueryChangedEntries(const nsACString & aChangedEntryDN) diff --git a/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.h b/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.h index 3470cc713f25..9b914eda522b 100644 --- a/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.h +++ b/mailnews/addrbook/src/nsAbLDAPChangeLogQuery.h @@ -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 * * The contents of this file are subject to the Mozilla Public License Version @@ -20,6 +22,7 @@ * * Contributor(s): * Rajiv Dayal + * Dan Mosedale * * 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"), @@ -55,5 +58,4 @@ public : NS_IMETHOD Init(const nsACString & aPrefName, nsIWebProgressListener *aProgressListener); }; - #endif // nsAbLDAPChangeLogQuery_h__ diff --git a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp index 3e37ee8560e6..79d4d6b638f3 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp +++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp @@ -39,7 +39,6 @@ * ***** END LICENSE BLOCK ***** */ #include "nsAbLDAPDirectory.h" -#include "nsAbLDAPProperties.h" #include "nsAbQueryStringToExpression.h" @@ -58,6 +57,8 @@ #include "nsIPrefBranch.h" #include "nsCOMArray.h" #include "nsArrayEnumerator.h" +#include "nsLDAP.h" +#include "nsIAbLDAPAttributeMap.h" nsAbLDAPDirectory::nsAbLDAPDirectory() : nsAbDirectoryRDFResource(), @@ -387,6 +388,23 @@ NS_IMETHODIMP nsAbLDAPDirectory::StartSearch () if (NS_FAILED(rv)) maxHits = 100; + // get the appropriate ldap attribute map, and pass it in via the + // TypeSpecificArgument + nsCOMPtr mapSvc = + do_GetService("@mozilla.org/addressbook/ldap-attribute-map-service;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr attrMap; + rv = mapSvc->GetMapForPrefBranch(prefName, getter_AddRefs(attrMap)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr typeSpecificArg = do_QueryInterface(attrMap, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + rv = arguments->SetTypeSpecificArg(attrMap); + NS_ENSURE_SUCCESS(rv, rv); + + // Perform the query rv = DoQuery(arguments, queryListener, maxHits, 0, &mContext); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp b/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp index af7f4ba2a6b4..22b32d2cca0c 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp +++ b/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp @@ -40,10 +40,12 @@ #include "nsAbLDAPDirectoryQuery.h" #include "nsAbBoolExprToLDAPFilter.h" -#include "nsAbLDAPProperties.h" +#include "nsILDAPMessage.h" #include "nsILDAPErrors.h" #include "nsILDAPOperation.h" +#include "nsIAbLDAPAttributeMap.h" #include "nsAbUtils.h" +#include "nsLDAP.h" #include "nsIAuthPrompt.h" #include "nsIStringBundle.h" @@ -224,8 +226,8 @@ NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPMessage(nsILDAPMessage *aMessa case nsILDAPMessage::RES_SEARCH_ENTRY: if (!mFinished && !mWaitingForPrevQueryToFinish) { - rv = OnLDAPMessageSearchEntry (aMessage, getter_AddRefs (queryResult)); - NS_ENSURE_SUCCESS(rv, rv); + rv = OnLDAPMessageSearchEntry (aMessage, + getter_AddRefs (queryResult)); } break; case nsILDAPMessage::RES_SEARCH_RESULT: @@ -507,106 +509,82 @@ nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchEntry (nsILDAPMessage nsIAbDirectoryQueryResult** result) { nsresult rv; - nsCOMPtr propertyValues; + // the address book fields that we'll be asking for CharPtrArrayGuard properties; rv = mQueryArguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr()); NS_ENSURE_SUCCESS(rv, rv); - CharPtrArrayGuard attrs; - rv = aMessage->GetAttributes(attrs.GetSizeAddr(), attrs.GetArrayAddr()); + // the map for translating between LDAP attrs <-> addrbook fields + nsCOMPtr iSupportsMap; + rv = mQueryArguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr map = do_QueryInterface(iSupportsMap, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCAutoString propertyName; - for (PRUint32 i = 0; i < properties.GetSize(); i++) - { - propertyName.Assign (properties[i]); + // set up variables for handling the property values to be returned + nsCOMPtr propertyValues; + nsCOMPtr propertyValue; + 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; - if (propertyName.Equals("card:nsIAbCard")) - { - // Meta property - nsCAutoString dn; - rv = aMessage->GetDn (dn); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr card; + rv = mDirectoryQuery->CreateCard (mUrl, dn.get(), getter_AddRefs (card)); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr card; - rv = mDirectoryQuery->CreateCard (mUrl, dn.get(), getter_AddRefs (card)); - NS_ENSURE_SUCCESS(rv, rv); + rv = map->SetCardPropertiesFromLDAPMessage(aMessage, card); + NS_ENSURE_SUCCESS(rv, rv); - PRBool hasSetCardProperty = PR_FALSE; - rv = MozillaLdapPropertyRelator::createCardPropertyFromLDAPMessage (aMessage, - card, - &hasSetCardProperty); - NS_ENSURE_SUCCESS(rv, rv); + propertyValue = new nsAbDirectoryQueryPropertyValue(properties[0], card); + if (!propertyValue) + return NS_ERROR_OUT_OF_MEMORY; - if (!hasSetCardProperty) - continue; + rv = propertyValues->AppendElement(propertyValue); + NS_ENSURE_SUCCESS(rv, rv); + } else { - _propertyValue = new nsAbDirectoryQueryPropertyValue(propertyName.get (), card); - 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++) + for (PRUint32 i = 0; i < properties.GetSize(); i++) { - relation = MozillaLdapPropertyRelator::findMozillaPropertyFromLdap (attrs[j]); - if (!relation) + // this is the precedence order list of attrs for this property + 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; - /* - * 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; - rv = aMessage->GetValues (attrs[j], vals.GetSizeAddr(), vals.GetArrayAddr()); - NS_ENSURE_SUCCESS(rv, rv); + rv = aMessage->GetValues(attrs[j], vals.GetSizeAddr(), + 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; - - _propertyValue = new nsAbDirectoryQueryPropertyValue(propertyName.get (), vals[0]); - if (_propertyValue == NULL) - return NS_ERROR_OUT_OF_MEMORY; - break; + } } } - } - - if (_propertyValue) - { - nsCOMPtr propertyValue; - propertyValue = _propertyValue; - - if (!propertyValues) - { - NS_NewISupportsArray(getter_AddRefs(propertyValues)); - } - - propertyValues->AppendElement (propertyValue); - } } - if (!propertyValues) - return NS_OK; - - return QueryResultStatus (propertyValues, result,nsIAbDirectoryQueryResult::queryResultMatch); + return QueryResultStatus (propertyValues, result, nsIAbDirectoryQueryResult::queryResultMatch); } nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchResult (nsILDAPMessage *aMessage, nsIAbDirectoryQueryResult** result) @@ -704,7 +682,17 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::DoQuery(nsIAbDirectoryQueryArguments* argu nsCOMPtr expression (do_QueryInterface (supportsExpression, &rv)); nsCAutoString filter; - rv = nsAbBoolExprToLDAPFilter::Convert (expression, filter); + + // figure out how we map attribute names to addressbook fields for this + // query + nsCOMPtr iSupportsMap; + rv = arguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr map = do_QueryInterface(iSupportsMap, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + rv = nsAbBoolExprToLDAPFilter::Convert (map, expression, filter); NS_ENSURE_SUCCESS(rv, rv); /* @@ -863,33 +851,51 @@ nsresult nsAbLDAPDirectoryQuery::getLdapReturnAttributes ( nsresult rv; CharPtrArrayGuard properties; - rv = arguments->GetReturnProperties (properties.GetSizeAddr(), properties.GetArrayAddr()); + rv = arguments->GetReturnProperties(properties.GetSizeAddr(), + properties.GetArrayAddr()); NS_ENSURE_SUCCESS(rv, rv); - nsCAutoString propertyName; + // figure out how we map attribute names to addressbook fields for this + // query + nsCOMPtr iSupportsMap; + rv = arguments->GetTypeSpecificArg(getter_AddRefs(iSupportsMap)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr 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++) { - propertyName.Assign (properties[i]); + nsCAutoString attrs; - if (propertyName.Equals("card:nsIAbCard")) - { - // Meta property - // require all attributes - // - rv = MozillaLdapPropertyRelator::GetAllSupportedLDAPAttributes(returnAttributes); - NS_ASSERTION(NS_SUCCEEDED(rv), "GetAllSupportedLDAPAttributes failed"); - break; + // get all the attributes for this property + rv = map->GetAttributeList(nsDependentCString(properties[i]), attrs); + + // if there weren't any attrs, just keep going + if (NS_FAILED(rv) || attrs.IsEmpty()) { + continue; } - const MozillaLdapPropertyRelation* tableEntry= - MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (propertyName.get ()); - if (!tableEntry) - continue; + // add a comma, if necessary + if (needComma) { + returnAttributes.Append(PRUnichar (',')); + } - if (i) - returnAttributes.Append (PRUnichar (',')); + returnAttributes.Append(attrs); - returnAttributes.Append (tableEntry->ldapProperty); + // since we've added attrs, we definitely need a comma next time + // we're here + needComma = PR_TRUE; } return rv; diff --git a/mailnews/addrbook/src/nsAbLDAPProperties.cpp b/mailnews/addrbook/src/nsAbLDAPProperties.cpp deleted file mode 100644 index 28cc85c3da05..000000000000 --- a/mailnews/addrbook/src/nsAbLDAPProperties.cpp +++ /dev/null @@ -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 - * - * 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; -} diff --git a/mailnews/addrbook/src/nsAbLDAPProperties.h b/mailnews/addrbook/src/nsAbLDAPProperties.h deleted file mode 100644 index 2bdd8bd5f790..000000000000 --- a/mailnews/addrbook/src/nsAbLDAPProperties.h +++ /dev/null @@ -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 - * - * 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 diff --git a/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp b/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp index 7996ae378607..a41350528b97 100644 --- a/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp +++ b/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp @@ -21,6 +21,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Dan Mosedale * * 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 @@ -36,7 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ - +#include "nsILDAPMessage.h" #include "nsAbLDAPReplicationData.h" #include "nsLDAP.h" #include "nsIAbCard.h" @@ -45,7 +46,6 @@ #include "nsAbUtils.h" #include "nsAbMDBCard.h" #include "nsAbLDAPCard.h" -#include "nsAbLDAPProperties.h" #include "nsAbLDAPReplicationQuery.h" #include "nsProxiedService.h" #include "nsCPasswordManager.h" @@ -90,6 +90,15 @@ NS_IMETHODIMP nsAbLDAPProcessReplicationData::Init(nsIAbLDAPReplicationQuery *qu return NS_ERROR_FAILURE; } + nsCOMPtr 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; mInitialized = PR_TRUE; @@ -326,19 +335,12 @@ nsresult nsAbLDAPProcessReplicationData::OnLDAPSearchEntry(nsILDAPMessage *aMess return NS_ERROR_FAILURE; nsAbLDAPCard card; - PRBool hasSetCardProperty = PR_FALSE; - nsresult rv = MozillaLdapPropertyRelator::createCardPropertyFromLDAPMessage(aMessage, - &card, &hasSetCardProperty); - if(NS_FAILED(rv)) { - Abort(); - return rv; - } - - if(hasSetCardProperty == PR_FALSE) + nsresult rv = mAttrMap->SetCardPropertiesFromLDAPMessage(aMessage, &card); + if (NS_FAILED(rv)) { 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 return NS_OK; } diff --git a/mailnews/addrbook/src/nsAbLDAPReplicationData.h b/mailnews/addrbook/src/nsAbLDAPReplicationData.h index ffdc1e6ae887..ff3bef3c87d2 100644 --- a/mailnews/addrbook/src/nsAbLDAPReplicationData.h +++ b/mailnews/addrbook/src/nsAbLDAPReplicationData.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Dan Mosedale * * 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 @@ -45,6 +46,7 @@ #include "nsIAddrDatabase.h" #include "nsILocalFile.h" #include "nsDirPrefs.h" +#include "nsIAbLDAPAttributeMap.h" class nsAbLDAPProcessReplicationData : public nsIAbLDAPProcessReplicationData { @@ -76,6 +78,7 @@ protected : DIR_Server * mDirServerInfo; nsCString mAuthDN; // authDN of the user nsCString mAuthPswd; // pswd of the authDN user + nsCOMPtr mAttrMap; // maps ab properties to ldap attrs virtual nsresult OnLDAPBind(nsILDAPMessage *aMessage); virtual nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage); diff --git a/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp b/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp index 4e53ff5b7688..caf568098937 100644 --- a/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp +++ b/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp @@ -44,7 +44,6 @@ #include "nsAbLDAPReplicationData.h" #include "nsILDAPURL.h" #include "nsAbBaseCID.h" -#include "nsAbLDAPProperties.h" #include "nsProxiedService.h" #include "nsLDAP.h" #include "nsAbUtils.h" diff --git a/mailnews/mailnews.js b/mailnews/mailnews.js index 7a6b5d215b9e..ddb1d93a91c9 100644 --- a/mailnews/mailnews.js +++ b/mailnews/mailnews.js @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Dan Mosedale * * 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"), @@ -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.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. // These entries are provided to keep the (obsolete) Four11 directory and the