diff --git a/mozilla/directory/xpcom/Makefile.in b/mozilla/directory/xpcom/Makefile.in index 07ed272f79c..b8f4680391b 100644 --- a/mozilla/directory/xpcom/Makefile.in +++ b/mozilla/directory/xpcom/Makefile.in @@ -9,7 +9,7 @@ # implied. See the License for the specific language governing # rights and limitations under the License. # -# The Original Code is the mozilla.org LDAP XPCOM component. +# The Original Code is the mozilla.org LDAP XPCOM SDK. # # The Initial Developer of the Original Code is Netscape # Communications Corporation. Portions created by Netscape are diff --git a/mozilla/directory/xpcom/TODO.txt b/mozilla/directory/xpcom/TODO.txt index 258f9acc24b..ff70c2bcda0 100644 --- a/mozilla/directory/xpcom/TODO.txt +++ b/mozilla/directory/xpcom/TODO.txt @@ -39,6 +39,8 @@ items blocked waiting for other work GetStatus to return OK, and asserts when it doesn't. (blocked waiting on insight from Warren about nsSocketTransport's use of mCancelStatus). +* ensure that multiple calls to Cancel don't do the wrong thing + * move the ldap_unbind() call out of the nsLDAPConnection destructor, since nsLDAPConnection will soon go back to being callable from the UI thread, and ldap_unbind() is actually synchronous. additionally, @@ -66,6 +68,9 @@ misc nsLDAPMessage::Init(), this is probably no longer an issue there at least. Need to confirm. +* replace instances of (obsolete) |static NS_DEFINE_IID| variables + with direct calls to NS_GET_IID in the code. + * investigate use of DNS in LDAP sdk. I think sync functions used in the wrong places (eg they end up getting called from Mozilla on the UI thread)? diff --git a/mozilla/directory/xpcom/base/Makefile.in b/mozilla/directory/xpcom/base/Makefile.in index dbc8ecb26be..f452979d3e7 100644 --- a/mozilla/directory/xpcom/base/Makefile.in +++ b/mozilla/directory/xpcom/base/Makefile.in @@ -9,7 +9,7 @@ # implied. See the License for the specific language governing # rights and limitations under the License. # -# The Original Code is the mozilla.org LDAP XPCOM component. +# The Original Code is the mozilla.org LDAP XPCOM SDK. # # The Initial Developer of the Original Code is Netscape # Communications Corporation. Portions created by Netscape are diff --git a/mozilla/directory/xpcom/base/public/MANIFEST_IDL b/mozilla/directory/xpcom/base/public/MANIFEST_IDL index 776b6a29a69..01f74eeb4d5 100644 --- a/mozilla/directory/xpcom/base/public/MANIFEST_IDL +++ b/mozilla/directory/xpcom/base/public/MANIFEST_IDL @@ -3,3 +3,4 @@ nsILDAPOperation.idl nsILDAPMessage.idl nsILDAPURL.idl nsILDAPMessageListener.idl +nsILDAPErrors.idl diff --git a/mozilla/directory/xpcom/base/public/Makefile.in b/mozilla/directory/xpcom/base/public/Makefile.in index b1621c168b7..6371e57cece 100644 --- a/mozilla/directory/xpcom/base/public/Makefile.in +++ b/mozilla/directory/xpcom/base/public/Makefile.in @@ -9,7 +9,7 @@ # implied. See the License for the specific language governing # rights and limitations under the License. # -# The Original Code is the mozilla.org LDAP XPCOM component. +# The Original Code is the mozilla.org LDAP XPCOM SDK. # # The Initial Developer of the Original Code is Netscape # Communications Corporation. Portions created by Netscape are @@ -46,6 +46,7 @@ XPIDLSRCS = nsILDAPConnection.idl \ nsILDAPMessage.idl \ nsILDAPMessageListener.idl \ nsILDAPURL.idl \ + nsILDAPErrors.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/directory/xpcom/base/public/makefile.win b/mozilla/directory/xpcom/base/public/makefile.win index f66cb29d14f..a8d5439eaab 100644 --- a/mozilla/directory/xpcom/base/public/makefile.win +++ b/mozilla/directory/xpcom/base/public/makefile.win @@ -30,6 +30,7 @@ XPIDLSRCS= .\nsILDAPConnection.idl \ .\nsILDAPMessage.idl \ .\nsILDAPURL.idl \ .\nsILDAPMessageListener.idl \ + .\nsILDAPErrors.idl \ $(NULL) include <$(DEPTH)\config\rules.mak> \ No newline at end of file diff --git a/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl b/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl index 703bb8c4e44..5c92cca2820 100644 --- a/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl +++ b/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,11 +10,11 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is part of the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are - * Copyright (C) 2000 Netscape Communications Corporation. All + * Copyright (C) 2000, 2001 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): Dan Mosedale @@ -33,14 +34,6 @@ #include "nsISupports.idl" -// for the ldapPtr typedef -// -%{C++ -#include "ldap.h" -%} - -[ptr] native ldapConnectionHandle(LDAP); - interface nsILDAPOperation; [scriptable, uuid(337ad2fe-1dd2-11b2-89f8-aae1221ec86c)] @@ -61,52 +54,33 @@ interface nsILDAPConnection : nsISupports /** * set up the connection. * - * @param aHost server name for ldap_init() - * @param aPort server port number for ldap_init() + * @param aHost server name for ldap_init() + * @param aPort server port number for ldap_init() * 0 == default port (389) - * @param aBindName DN to bind as + * @param aBindName DN to bind as * - * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in - * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory - * @exception NS_ERROR_NOT_AVAILABLE Couldn't create thread. - * @exception NS_ERROR_FAILURE - * @exception NS_ERROR_UNEXPECTED internal error + * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in + * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory + * @exception NS_ERROR_NOT_AVAILABLE Couldn't create thread. + * @exception NS_ERROR_FAILURE + * @exception NS_ERROR_UNEXPECTED internal error */ void init(in string aHost, in short aPort, in string aBindName); - // wrapper for ldap_get_lderrno() + /** + * Get information about the last error that occured on this connection. + * + * @param matched if the server is returning LDAP_NO_SUCH_OBJECT, + * LDAP_ALIAS_PROBLEM, LDAP_INVALID_DN_SYNTAX, + * or LDAP_ALIAS_DEREF_PROBLEM, this will contain + * the portion of DN that matches the entry that is + * closest to the requested entry + * + * @param s additional error information from the server + * + * @return the error code, as defined in nsILDAPErrors.idl + */ long getLdErrno(out string matched, out string s); - /** - * really only for the internal use of nsLDAPOperation and friends - * - * @exception NS_ERROR_ILLEGAL_VALUE pointer passed in was NULL - */ - [noscript] readonly attribute ldapConnectionHandle connectionHandle; - - /** - * Add an nsILDAPOperation to the list of operations pending on - * this connection. This is also mainly intended for use by the - * nsLDAPOperation code. Used so that the thread waiting on messages - * for this connection has an operation to callback to. - * - * @param aOperation operation to add - * @exception NS_ERROR_ILLEGAL_VALUE aOperation was NULL - * @exception NS_ERROR_UNEXPECTED this operation's msgId was not - * unique to this connection - * @exception NS_ERROR_OUT_OF_MEMORY out of memory - */ - void addPendingOperation(in nsILDAPOperation aOperation); - - /** - * Remove an nsILDAPOperation from the list of operations pending on this - * connection. Mainly intended for use by the nsLDAPOperation code. - * - * @param aOperation operation to add - * @exception NS_ERROR_INVALID_POINTER aOperation was NULL - * @exception NS_ERROR_OUT_OF_MEMORY out of memory - * @exception NS_ERROR_FAILURE could not delete the operation - */ - void removePendingOperation(in nsILDAPOperation aOperation); }; diff --git a/mozilla/directory/xpcom/base/public/nsILDAPErrors.idl b/mozilla/directory/xpcom/base/public/nsILDAPErrors.idl new file mode 100644 index 00000000000..badd4a1ef27 --- /dev/null +++ b/mozilla/directory/xpcom/base/public/nsILDAPErrors.idl @@ -0,0 +1,229 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is part of the mozilla.org LDAP XPCOM SDK. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): Dan Mosedale (Original Author) + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU General Public License Version 2 or later (the + * "GPL"), in which case the provisions of the GPL are applicable + * instead of those above. If you wish to allow use of your + * version of this file only under the terms of the GPL and not to + * allow others to use your version of this file under the MPL, + * indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by + * the GPL. If you do not delete the provisions above, a recipient + * may use your version of this file under either the MPL or the + * GPL. + */ + +#include "nsISupports.idl" + +/** + * Error codes used in the LDAP XPCOM SDK. + * + * Taken from the Mozilla C SDK's ldap.h include file, these should be + * the same as those specified in the draft-ietf-ldapext-ldap-c-api-04.txt + * Internet Draft. + * + * The only good documentation I'm aware of for these error codes is + * at . + * Unfortunately, this does not currently seem to be available under any + * open source license, so I can't include that documentation here as + * doxygen comments. + * + */ +[scriptable, uuid(f9ac10fa-1dd1-11b2-9798-8d5cbda95d74)] +interface nsILDAPErrors : nsISupports +{ + + const long SUCCESS = 0x00; + + const long OPERATIONS_ERROR = 0x01; + + const long PROTOCOL_ERROR = 0x02; + + const long TIMELIMIT_EXCEEDED = 0x03; + + const long SIZELIMIT_EXCEEDED = 0x04; + + const long COMPARE_FALSE = 0x05; + + const long COMPARE_TRUE = 0x06; + + const long STRONG_AUTH_NOT_SUPPORTED = 0x07; + + const long STRONG_AUTH_REQUIRED = 0x08; + + + /** + * UMich LDAPv2 extension + */ + const long PARTIAL_RESULTS = 0x09; + + /** + * new in LDAPv3 + */ + const long REFERRAL = 0x0a; + + /** + * new in LDAPv3 + */ + const long ADMINLIMIT_EXCEEDED = 0x0b; + + /** + * new in LDAPv3 + */ + const long UNAVAILABLE_CRITICAL_EXTENSION = 0x0c; + + /** + * new in LDAPv3 + */ + const long CONFIDENTIALITY_REQUIRED = 0x0d; + + /** + * new in LDAPv3 + */ + const long SASL_BIND_IN_PROGRESS = 0x0e; + + const long NO_SUCH_ATTRIBUTE = 0x10; + + const long UNDEFINED_TYPE = 0x11; + + const long INAPPROPRIATE_MATCHING = 0x12; + + const long CONSTRAINT_VIOLATION = 0x13; + + const long TYPE_OR_VALUE_EXISTS = 0x14; + + const long INVALID_SYNTAX = 0x15; + + const long NO_SUCH_OBJECT = 0x20; + + const long ALIAS_PROBLEM = 0x21; + + const long INVALID_DN_SYNTAX = 0x22; + + /** + * not used in LDAPv3 + */ + const long IS_LEAF = 0x23; + + const long ALIAS_DEREF_PROBLEM = 0x24; + + const long INAPPROPRIATE_AUTH = 0x30; + + const long INVALID_CREDENTIALS = 0x31; + + const long INSUFFICIENT_ACCESS = 0x32; + + const long BUSY = 0x33; + + const long UNAVAILABLE = 0x34; + + const long UNWILLING_TO_PERFORM = 0x35; + + const long LOOP_DETECT = 0x36; + + /** + * server side sort extension + */ + const long SORT_CONTROL_MISSING = 0x3C; + + /** + * VLV extension + */ + const long INDEX_RANGE_ERROR = 0x3D; + + const long NAMING_VIOLATION = 0x40; + + const long OBJECT_CLASS_VIOLATION = 0x41; + + const long NOT_ALLOWED_ON_NONLEAF = 0x42; + + const long NOT_ALLOWED_ON_RDN = 0x43; + + const long ALREADY_EXISTS = 0x44; + + const long NO_OBJECT_CLASS_MODS = 0x45; + + /** + * reserved CLDAP + */ + const long RESULTS_TOO_LARGE = 0x46; + + /** + * new in LDAPv3 + */ + const long AFFECTS_MULTIPLE_DSAS = 0x47; + + const long OTHER = 0x50; + + const long SERVER_DOWN = 0x51; + + const long LOCAL_ERROR = 0x52; + + const long ENCODING_ERROR = 0x53; + + const long DECODING_ERROR = 0x54; + + const long TIMEOUT = 0x55; + + const long AUTH_UNKNOWN = 0x56; + + const long FILTER_ERROR = 0x57; + + const long USER_CANCELLED = 0x58; + + const long PARAM_ERROR = 0x59; + + const long NO_MEMORY = 0x5a; + + const long CONNECT_ERROR = 0x5b; + + /** + * new in LDAPv3 + */ + const long NOT_SUPPORTED = 0x5c; + + /** + * new in LDAPv3 + */ + const long CONTROL_NOT_FOUND = 0x5d; + + /** + * new in LDAPv3 + */ + const long NO_RESULTS_RETURNED = 0x5e; + + /** + * new in LDAPv3 + */ + const long MORE_RESULTS_TO_RETURN = 0x5f; + + /** + * new in LDAPv3 + */ + const long CLIENT_LOOP = 0x60; + + /** + * new in LDAPv3 + */ + const long REFERRAL_LIMIT_EXCEEDED = 0x61; +}; + diff --git a/mozilla/directory/xpcom/base/public/nsILDAPMessage.idl b/mozilla/directory/xpcom/base/public/nsILDAPMessage.idl index ecd0edad709..01abc5108aa 100644 --- a/mozilla/directory/xpcom/base/public/nsILDAPMessage.idl +++ b/mozilla/directory/xpcom/base/public/nsILDAPMessage.idl @@ -10,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -35,34 +35,11 @@ #include "nsISupports.idl" #include "nsILDAPOperation.idl" -// for the ldapMsgHandle typedef -// -%{C++ -#include "ldap.h" -%} - -[ptr] native ldapMsgHandle(LDAPMessage); - [scriptable, uuid(973ff50f-2002-4f0c-b57d-2242156139a2)] interface nsILDAPMessage : nsISupports { - /** - * Initializes a message. - * - * @param aConnection The connection this message lives on. - * @param aMsgHandle The native LDAPMessage to be wrapped. - * - * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in - * @exception NS_ERROR_UNEXPECTED internal err; shouldn't happen - * @exception NS_ERROR_LDAP_DECODING_ERROR problem during BER decoding - * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory - */ - [noscript] void init(in nsILDAPConnection aConnection, - in ldapMsgHandle aMsgHandle); - /** * The Distinguished Name of the entry associated with this message. - * Wrapper for ldap_get_dn(). * * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in @@ -72,7 +49,7 @@ interface nsILDAPMessage : nsISupports readonly attribute string dn; /** - * wrapper for ldap_{first,next}_attribute() + * Get all the attributes in this message. * * @exception NS_ERROR_OUT_OF_MEMORY * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in @@ -85,7 +62,7 @@ interface nsILDAPMessage : nsISupports [retval, array, size_is(count)] out string aAttributes); /** - * wrapper for ldap_get_values() + * Get an array of all the attribute values in this message. * * @param attr The attribute whose values are to be returned * @param count Number of values in the outbound array. @@ -100,30 +77,81 @@ interface nsILDAPMessage : nsISupports [retval, array, size_is(count)] out string values); /** - * The result code (ie lderrno) for this message. + * The result code (aka lderrno) for this message. * - * XXXdmose these codes are defined in ldap.h; presumably need to reexport - * these as IDL constants (or somehow map to nsresults?) + * IDL definitions for these constants live in nsILDAPErrors.idl. * * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in */ readonly attribute long errorCode; /** - * Wrapper for ldap_msgtype() - * - * XXXdmose the message types are defined in ldap.h; presumably need - * to reexport these as IDL constants + * The result type of this message. Possible types listed below, the + * values chosen are taken from the draft-ietf-ldapext-ldap-c-api-04.txt + * and are the same ones used in the ldap.h include file from the Mozilla + * LDAP C SDK. * * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in * @exception NS_ERROR_UNEXPECTED internal error (possible memory * corruption) - * */ readonly attribute long type; - // returns an LDIF-like string representation of this message - // XXXdmose - should use wstring here - // - string toString(); + /** + * Result of a bind operation + */ + const long RES_BIND = 0x61; + + /** + * An entry found in an search operation. + */ + const long RES_SEARCH_ENTRY = 0x64; + + /** + * An LDAPv3 search reference (a referral to another server) + */ + const long RES_SEARCH_REFERENCE = 0x73; + + /** + * The result of a search operation (i.e. the search is done; no more + * entries to follow). + */ + const long RES_SEARCH_RESULT = 0x65; + + /** + * The result of a modify operation. + */ + const long RES_MODIFY = 0x67; + + /** + * The result of an add operation + */ + const long RES_ADD = 0x69; + + /** + * The result of a delete operation + */ + const long RES_DELETE = 0x6B; + + /** + * The result of an modify DN operation + */ + const long RES_MODDN = 0x6D; + + /** + * The result of a compare operation + */ + const long RES_COMPARE = 0x6F; + + /** + * The result of an LDAPv3 extended operation + */ + const long RES_EXTENDED = 0x78; + + /** + * get an LDIF-like string representation of this message + * + * @return unicode encoded string representation. + */ + wstring toUnicode(); }; diff --git a/mozilla/directory/xpcom/base/public/nsILDAPMessageListener.idl b/mozilla/directory/xpcom/base/public/nsILDAPMessageListener.idl index 9e56d14e5d6..872397f6fc5 100644 --- a/mozilla/directory/xpcom/base/public/nsILDAPMessageListener.idl +++ b/mozilla/directory/xpcom/base/public/nsILDAPMessageListener.idl @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -34,10 +35,11 @@ #include "nsISupports.idl" #include "nsILDAPMessage.idl" -// a callback interface to be implemented by any objects that want to -// receive results from an nsILDAPOperation (ie nsILDAPMessages) as they -// come in. -// +/** + * A callback interface to be implemented by any objects that want to + * receive results from an nsILDAPOperation (ie nsILDAPMessages) as they + * come in. + */ [scriptable, uuid(dc721d4b-3ff2-4387-a80c-5e29545f774a)] interface nsILDAPMessageListener : nsISupports { diff --git a/mozilla/directory/xpcom/base/public/nsILDAPOperation.idl b/mozilla/directory/xpcom/base/public/nsILDAPOperation.idl index 6d184fc8a80..46862c8fdda 100644 --- a/mozilla/directory/xpcom/base/public/nsILDAPOperation.idl +++ b/mozilla/directory/xpcom/base/public/nsILDAPOperation.idl @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -45,7 +46,7 @@ interface nsILDAPOperation : nsISupports /** * The connection this operation is on. * - * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in + * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in */ readonly attribute nsILDAPConnection connection; @@ -54,16 +55,16 @@ interface nsILDAPOperation : nsISupports * by the init() method). This is actually an nsISupports proxy object, * as the callback will happen from another thread. * - * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in + * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in */ readonly attribute nsILDAPMessageListener messageListener; /** * The message-id associated with this operation. * - * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in + * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in */ - readonly attribute long messageId; + readonly attribute long messageID; /** * Initializes this operation. Must be called prior to initiating @@ -75,40 +76,33 @@ interface nsILDAPOperation : nsISupports * @param aConnection connection this operation should use * @param aMessageListener interface used to call back the results. * - * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in - * @exception NS_ERROR_UNEXPECTED failed to get connection handle + * @exception NS_ERROR_ILLEGAL_VALUE a NULL pointer was passed in + * @exception NS_ERROR_UNEXPECTED failed to get connection handle */ void init(in nsILDAPConnection aConnection, in nsILDAPMessageListener aMessageListener); /** - * wrapper for ldap_simple_bind() + * Asynchronously authenticate to the LDAP server. * * @param passwd the password used for binding; NULL for anon-binds * - * @exception NS_ERROR_LDAP_ENCODING_ERROR problem encoding bind request - * @exception NS_ERROR_FAILURE server down (XXX rebinds?) - * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory - * @exception NS_ERROR_UNEXPECTED internal error + * @exception NS_ERROR_LDAP_ENCODING_ERROR problem encoding bind request + * @exception NS_ERROR_FAILURE server down (XXX rebinds?) + * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory + * @exception NS_ERROR_UNEXPECTED internal error * */ void simpleBind(in string passwd); - // wrapper for ldap_search_url() - // XXX this doesn't currently work right, because the connection has - // doesn't know what result came for whom. also, the it calls - // a synchronous bind function under the hood - // - // XXXdmose should probably get rid of this method, due to it's - // synchronity, and since we have other classes to - // - void urlSearch(in string url, in boolean attrsonly); - /** - * wrapper for ldap_search_ext(): kicks off an async search request. + * Kicks off an asynchronous search request. The "ext" stands for + * "extensions", and is intended to convey that this method will + * eventually support the extensions described in the + * draft-ietf-ldapext-ldap-c-api-04.txt Internet Draft. * * @param aBaseDn Base DN to search - * @param aScope One of LDAP_SCOPE_{BASE,ONELEVEL,SUBTREE} + * @param aScope One of SCOPE_{BASE,ONELEVEL,SUBTREE} * @param aFilter Search filter * @param aTimeOut How long to wait * @param aSizeLimit Maximum number of entries to return. @@ -117,6 +111,7 @@ interface nsILDAPOperation : nsISupports * @exception NS_ERROR_LDAP_ENCODING_ERROR * @exception NS_ERROR_LDAP_SERVER_DOWN * @exception NS_ERROR_OUT_OF_MEMORY + * @exception NS_ERROR_INVALID_ARG * @exception NS_ERROR_LDAP_NOT_SUPPORTED * * XXX doesn't currently handle LDAPControl params @@ -126,16 +121,16 @@ interface nsILDAPOperation : nsISupports in PRInt32 aSizeLimit); /** - * wrapper for ldap_abandon_ext() with NULL LDAPControl - * parameters, equivalent to old-style ldap_abandon(), thus the name. + * Cancels an async operation that is in progress. * - * @exception NS_ERROR_NOT_INITIALIZED operation not initialized + * @exception NS_ERROR_NOT_INITIALIZED operation not initialized * @exception NS_ERROR_LDAP_ENCODING_ERROR error during BER-encoding - * @exception NS_ERROR_LDAP_SERVER_DOWN the LDAP server did not - * receive the request or the - * connection was lost - * @exception NS_ERROR_OUT_OF_MEMORY out of memory - * @exception NS_ERROR_UNEXPECTED internal error + * @exception NS_ERROR_LDAP_SERVER_DOWN the LDAP server did not + * receive the request or the + * connection was lost + * @exception NS_ERROR_OUT_OF_MEMORY out of memory + * @exception NS_ERROR_INVALID_ARG invalid argument + * @exception NS_ERROR_UNEXPECTED internal error */ void abandon(); }; diff --git a/mozilla/directory/xpcom/base/public/nsILDAPURL.idl b/mozilla/directory/xpcom/base/public/nsILDAPURL.idl index fa1419a5200..b84c141add4 100644 --- a/mozilla/directory/xpcom/base/public/nsILDAPURL.idl +++ b/mozilla/directory/xpcom/base/public/nsILDAPURL.idl @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -45,9 +46,9 @@ interface nsILDAPURL : nsIURI { * * for the getter: * - * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in - * @exception NS_ERROR_NOT_INITIALIZED URL spec not set - * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory + * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in + * @exception NS_ERROR_NOT_INITIALIZED URL spec not set + * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory */ attribute string dn; @@ -57,7 +58,7 @@ interface nsILDAPURL : nsIURI { * XXXdmose - there should be a setter for this too */ void getAttributes(out unsigned long count, - [retval, array, size_is(count)] out string values); + [retval, array, size_is(count)] out string values); /** * the scope of the search. defaults to NS_LDAP_SCOPE_BASE. @@ -67,17 +68,17 @@ interface nsILDAPURL : nsIURI { /** * search just the base object */ - const long NS_LDAP_SCOPE_BASE = 0; + const long SCOPE_BASE = 0; /** * search only the children of the base object */ - const long NS_LDAP_SCOPE_ONELEVEL = 1; + const long SCOPE_ONELEVEL = 1; /** * search the entire subtree under and including the base object */ - const long NS_LDAP_SCOPE_SUBTREE = 2; + const long SCOPE_SUBTREE = 2; /** * the search filter. "(objectClass=*)" is the default. diff --git a/mozilla/directory/xpcom/base/public/nsLDAP.h b/mozilla/directory/xpcom/base/public/nsLDAP.h index 363fe412283..298a26e75b9 100644 --- a/mozilla/directory/xpcom/base/public/nsLDAP.h +++ b/mozilla/directory/xpcom/base/public/nsLDAP.h @@ -1,22 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the mozilla.org LDAP XPCOM SDK. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): Dan Mosedale + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU General Public License Version 2 or later (the + * "GPL"), in which case the provisions of the GPL are applicable + * instead of those above. If you wish to allow use of your + * version of this file only under the terms of the GPL and not to + * allow others to use your version of this file under the MPL, + * indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by + * the GPL. If you do not delete the provisions above, a recipient + * may use your version of this file under either the MPL or the + * GPL. + */ #include "nsError.h" #include "nspr.h" #define NS_ERROR_LDAP_OPERATIONS_ERROR \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_OPERATIONS_ERROR) + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_OPERATIONS_ERROR) #define NS_ERROR_LDAP_ENCODING_ERROR \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_ENCODING_ERROR) + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_ENCODING_ERROR) #define NS_ERROR_LDAP_SERVER_DOWN \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_SERVER_DOWN) + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_SERVER_DOWN) #define NS_ERROR_LDAP_NOT_SUPPORTED \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_NOT_SUPPORTED) + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_NOT_SUPPORTED) #define NS_ERROR_LDAP_DECODING_ERROR \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_DECODING_ERROR) + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, LDAP_DECODING_ERROR) -#ifdef DEBUG +#ifdef PR_LOGGING extern PRLogModuleInfo *gLDAPLogModule; // defn in nsLDAPProtocolModule.cpp #endif diff --git a/mozilla/directory/xpcom/base/src/Makefile.in b/mozilla/directory/xpcom/base/src/Makefile.in index f07139e9138..fb2a00d262b 100644 --- a/mozilla/directory/xpcom/base/src/Makefile.in +++ b/mozilla/directory/xpcom/base/src/Makefile.in @@ -9,7 +9,7 @@ # implied. See the License for the specific language governing # rights and limitations under the License. # -# The Original Code is the mozilla.org LDAP XPCOM component. +# The Original Code is the mozilla.org LDAP XPCOM SDK. # # The Initial Developer of the Original Code is Netscape # Communications Corporation. Portions created by Netscape are diff --git a/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp b/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp index 1c3b4e36fb5..c0ef357ca7d 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPChannel.cpp @@ -10,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -18,7 +18,7 @@ * Rights Reserved. * * Contributor(s): Dan Mosedale - * Warren Harris + * Warren Harris * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the @@ -56,7 +56,7 @@ static NS_DEFINE_IID(kIProgressEventSink, NS_IPROGRESSEVENTSINK_IID); NS_IMPL_THREADSAFE_ISUPPORTS3(nsLDAPChannel, nsIChannel, - nsIRequest, + nsIRequest, nsILDAPMessageListener); nsLDAPChannel::nsLDAPChannel() @@ -123,7 +123,7 @@ nsLDAPChannel::Init(nsIURI *uri) return NS_ERROR_FAILURE; } -#else +#else mCallback = this; #endif @@ -141,7 +141,7 @@ nsLDAPChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) return NS_ERROR_NO_AGGREGATION; nsLDAPChannel* ldapChannel = new nsLDAPChannel(); - if (ldapChannel == nsnull) + if (!ldapChannel) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(ldapChannel); @@ -215,7 +215,7 @@ nsLDAPChannel::Cancel(nsresult aStatus) // if (mLoadGroup) { rv = mLoadGroup->RemoveRequest(this, mResponseContext, aStatus, - nsnull); + 0); if (NS_FAILED(rv)) return rv; } @@ -223,7 +223,7 @@ nsLDAPChannel::Cancel(nsresult aStatus) // call listener's onstoprequest // if (mUnproxiedListener) { - rv = mListener->OnStopRequest(this, mResponseContext, aStatus, nsnull); + rv = mListener->OnStopRequest(this, mResponseContext, aStatus, 0); if (NS_FAILED(rv)) return rv; } @@ -585,7 +585,7 @@ nsLDAPChannel::AsyncOpen(nsIStreamListener* aListener, getter_AddRefs(mReadPipeOut), NS_PIPE_DEFAULT_SEGMENT_SIZE, NS_PIPE_DEFAULT_BUFFER_SIZE, - PR_TRUE, PR_FALSE, nsnull); + PR_TRUE, PR_FALSE, 0); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::AsyncRead(): unable to create new pipe"); return NS_ERROR_FAILURE; @@ -620,7 +620,7 @@ nsLDAPChannel::AsyncOpen(nsIStreamListener* aListener, // initialize it with the defaults // XXXdmose - need to deal with bind name // - rv = mConnection->Init(host, port, NULL); + rv = mConnection->Init(host, port, 0); switch (rv) { case NS_OK: break; @@ -636,7 +636,7 @@ nsLDAPChannel::AsyncOpen(nsIStreamListener* aListener, } // create and initialize an LDAP operation (to be used for the bind) - // + // mCurrentOperation = do_CreateInstance( "@mozilla.org/network/ldap-operation;1", &rv); if (NS_FAILED(rv)) { @@ -652,7 +652,7 @@ nsLDAPChannel::AsyncOpen(nsIStreamListener* aListener, // kick off a bind operation // PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("initiating SimpleBind\n")); - rv = mCurrentOperation->SimpleBind(NULL); + rv = mCurrentOperation->SimpleBind(0); if (NS_FAILED(rv)) { // XXXdmose better error handling / passthrough; deal with password @@ -667,7 +667,7 @@ nsLDAPChannel::AsyncOpen(nsIStreamListener* aListener, /** * Messages received are passed back via this function. * - * @arg aMessage The message that was returned, NULL if none was. + * @arg aMessage The message that was returned, 0 if none was. * * void OnLDAPMessage (in nsILDAPMessage aMessage) */ @@ -704,7 +704,7 @@ nsLDAPChannel::OnLDAPMessage(nsILDAPMessage *aMessage) case LDAP_RES_SEARCH_RESULT: // the search is finished; we're all done - // + // return OnLDAPSearchResult(aMessage); break; @@ -745,10 +745,10 @@ nsLDAPChannel::OnLDAPBind(nsILDAPMessage *aMessage) // XXX should call ldap_parse_result() here - mCurrentOperation = 0; // done with bind op; make nsCOMPtr release it + mCurrentOperation = 0; // done with bind op; make nsCOMPtr release it // create and initialize an LDAP operation (to be used for the search - // + // mCurrentOperation = do_CreateInstance( "@mozilla.org/network/ldap-operation;1", &rv); if (NS_FAILED(rv)) { @@ -803,7 +803,7 @@ nsLDAPChannel::OnLDAPBind(nsILDAPMessage *aMessage) nsresult nsLDAPChannel::OnLDAPSearchResult(nsILDAPMessage *aMessage) { - PRInt32 errorCode; // the LDAP error code + PRInt32 errorCode; // the LDAP error code nsresult rv; PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("result returned\n")); @@ -812,9 +812,7 @@ nsLDAPChannel::OnLDAPSearchResult(nsILDAPMessage *aMessage) // rv = aMessage->GetErrorCode(&errorCode); if ( NS_FAILED(rv) ) { -#ifdef DEBUG - PR_fprintf(PR_STDERR, " %s\n", ldap_err2string(errorCode)); -#endif + NS_ERROR(ldap_err2string(errorCode)); return NS_ERROR_FAILURE; } @@ -838,7 +836,7 @@ nsLDAPChannel::OnLDAPSearchResult(nsILDAPMessage *aMessage) // remove self from loadgroup to stop the throbber // if (mLoadGroup) { - rv = mLoadGroup->RemoveRequest(this, mResponseContext, NS_OK, nsnull); + rv = mLoadGroup->RemoveRequest(this, mResponseContext, NS_OK, 0); if (NS_FAILED(rv)) { NS_WARNING("nsLDAPChannel::OnSearchResult(): " "mLoadGroup->RemoveChannel() failed"); @@ -849,7 +847,7 @@ nsLDAPChannel::OnLDAPSearchResult(nsILDAPMessage *aMessage) // call listener's onstoprequest // if (mListener) { - rv = mListener->OnStopRequest(this, mResponseContext, NS_OK, nsnull); + rv = mListener->OnStopRequest(this, mResponseContext, NS_OK, 0); if (NS_FAILED(rv)) { NS_WARNING("nsLDAPChannel::OnSearchResult(): " "mListener->OnStopRequest failed\n"); @@ -912,7 +910,7 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage) if (NS_FAILED(rv)) { NS_WARNING("nsLDAPChannel:OnLDAPSearchEntry(): " "aMessage->GetValues() failed\n"); - NSLDAP_FREE_XPIDL_ARRAY(attrCount, attrs, nsMemory::Free); + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(attrCount, attrs); return rv;; } @@ -924,17 +922,16 @@ nsLDAPChannel::OnLDAPSearchEntry(nsILDAPMessage *aMessage) entry.Append(vals[j]); entry.Append("\n"); } - NSLDAP_FREE_XPIDL_ARRAY(valueCount, vals, nsMemory::Free); + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(valueCount, vals); } - NSLDAP_FREE_XPIDL_ARRAY(attrCount, attrs, nsMemory::Free); + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(attrCount, attrs); // XXXdmose better error handling // if (NS_FAILED(rv)) { -#ifdef DEBUG - PR_fprintf(PR_STDERR, "aMessage: error getting attribute\n"); -#endif + PR_LOG(gLDAPLogModule, PR_LOG_ERROR, + ("aMessage: error getting attribute\n")); return rv; } diff --git a/mozilla/directory/xpcom/base/src/nsLDAPChannel.h b/mozilla/directory/xpcom/base/src/nsLDAPChannel.h index 415ec0a7deb..dee4302726a 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPChannel.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPChannel.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -53,59 +54,58 @@ // #define INVOKE_LDAP_CALLBACKS_ON_MAIN_THREAD 0 -/* Header file */ class nsLDAPChannel : public nsIChannel, public nsILDAPMessageListener { -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIREQUEST - NS_DECL_NSICHANNEL - NS_DECL_NSILDAPMESSAGELISTENER + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIREQUEST + NS_DECL_NSICHANNEL + NS_DECL_NSILDAPMESSAGELISTENER - nsLDAPChannel(); - virtual ~nsLDAPChannel(); + nsLDAPChannel(); + virtual ~nsLDAPChannel(); - nsresult Init(nsIURI *uri); + nsresult Init(nsIURI *uri); - // this actually only gets called by nsLDAPHandler::NewChannel() - // - static NS_METHOD - Create(nsISupports* aOuter, REFNSIID aIID, void **aResult); + // this actually only gets called by nsLDAPHandler::NewChannel() + // + static NS_METHOD + Create(nsISupports* aOuter, REFNSIID aIID, void **aResult); -protected: + protected: - // these are internal functions, called by the dispatcher function - // OnLDAPMessage() - // - nsresult OnLDAPSearchResult(nsILDAPMessage *aMessage); - nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage); - nsresult OnLDAPBind(nsILDAPMessage *aMessage); + // these are internal functions, called by the dispatcher function + // OnLDAPMessage() + // + nsresult OnLDAPSearchResult(nsILDAPMessage *aMessage); + nsresult OnLDAPSearchEntry(nsILDAPMessage *aMessage); + nsresult OnLDAPBind(nsILDAPMessage *aMessage); - // instance vars for read/write nsIChannel attributes - // - nsresult mStatus; - nsCOMPtr mURI; // the URI we're processing - nsCOMPtr mUnproxiedLoadGroup; // the load group we belong to - nsCOMPtr mCallbacks; - nsCOMPtr mOriginalURI; // the URI we started prcessing - nsLoadFlags mLoadAttributes; // load attributes for this channel - nsCOMPtr mOwner; // entity responsible for this channel + // instance vars for read/write nsIChannel attributes + // + nsresult mStatus; + nsCOMPtr mURI; // the URI we're processing + nsCOMPtr mUnproxiedLoadGroup; // the load group we belong to + nsCOMPtr mCallbacks; + nsCOMPtr mOriginalURI; // the URI we started prcessing + nsLoadFlags mLoadAttributes; // load attributes for this channel + nsCOMPtr mOwner; // entity responsible for this channel - // various other instance vars - // - nsCOMPtr mUnproxiedListener; // for calls on main thread - nsCOMPtr mLoadGroup; // possibly an nsISupports proxy - nsCOMPtr mConnection; // LDAP connection for this channel - nsCOMPtr mListener; // for calls on LDAP callback thread - // which _might_ be the main thread - nsCOMPtr mResponseContext; - nsCOMPtr mReadPipeIn; // this end given to the listener - nsCOMPtr mReadPipeOut; // for writes from the channel - nsCOMPtr mCurrentOperation; // current ldap operation - PRUint32 mReadPipeOffset; // how many bytes written so far? - PRBool mReadPipeClosed; // has the pipe already been closed? - nsCOMPtr mCallback; // callback - nsCOMPtr mEventSink; // fire status against this + // various other instance vars + // + nsCOMPtr mUnproxiedListener; // for calls on main thread + nsCOMPtr mLoadGroup; // possibly an nsISupports proxy + nsCOMPtr mConnection; // LDAP connection + nsCOMPtr mListener; // for calls on LDAP callback thread + // which _might_ be the main thread + nsCOMPtr mResponseContext; + nsCOMPtr mReadPipeIn; // this end given to the listener + nsCOMPtr mReadPipeOut; // for writes from the channel + nsCOMPtr mCurrentOperation; // current ldap operation + PRUint32 mReadPipeOffset; // how many bytes written so far? + PRBool mReadPipeClosed; // has the pipe already been closed? + nsCOMPtr mCallback; // callback + nsCOMPtr mEventSink; // fire status against this }; diff --git a/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp b/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp index 544b2773a42..04a2877fde7 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp @@ -10,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -61,7 +61,7 @@ nsLDAPConnection::~nsLDAPConnection() PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("unbinding\n")); - rc = ldap_unbind_s(this->mConnectionHandle); + rc = ldap_unbind_s(mConnectionHandle); if (rc != LDAP_SUCCESS) { PR_LOG(gLDAPLogModule, PR_LOG_WARNING, ("nsLDAPConnection::~nsLDAPConnection: %s\n", @@ -92,7 +92,7 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, const char *aBindName) return NS_ERROR_ILLEGAL_VALUE; } -#ifdef DEBUG +#ifdef PR_LOGGING // initialize logging, if it hasn't been already // if (!gLDAPLogModule) { @@ -113,17 +113,21 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, const char *aBindName) return NS_ERROR_OUT_OF_MEMORY; } } else { - mBindName = NULL; + mBindName = 0; } - this->mConnectionHandle = ldap_init(aHost, aPort ? aPort : LDAP_PORT); - if ( this->mConnectionHandle == NULL ) { + // initialize the connection + // + // XXX buglet: port = -1 fails + // + mConnectionHandle = ldap_init(aHost, aPort ? aPort : LDAP_PORT); + if ( !mConnectionHandle ) { return NS_ERROR_FAILURE; // the LDAP C SDK API gives no useful error } // initialize the threading functions for this connection // - if (!nsLDAPThreadFuncsInit(this->mConnectionHandle)) { + if (!nsLDAPThreadFuncsInit(mConnectionHandle)) { return NS_ERROR_UNEXPECTED; } @@ -145,8 +149,8 @@ nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, const char *aBindName) #ifdef DEBUG_dmose const int lDebug = 0; - ldap_set_option(this->mConnectionHandle, LDAP_OPT_DEBUG_LEVEL, &lDebug); - ldap_set_option(this->mConnectionHandle, LDAP_OPT_ASYNC_CONNECT, + ldap_set_option(mConnectionHandle, LDAP_OPT_DEBUG_LEVEL, &lDebug); + ldap_set_option(mConnectionHandle, LDAP_OPT_ASYNC_CONNECT, NS_REINTERPRET_CAST(void *, 0)); #endif @@ -172,7 +176,7 @@ nsLDAPConnection::GetBindName(char **_retval) // check for NULL (meaning bind anonymously) // if (!mBindName) { - *_retval = nsnull; + *_retval = 0; } else { // otherwise, hand out a copy of the bind name @@ -195,7 +199,7 @@ nsLDAPConnection::GetLdErrno(char **matched, char **errString, { NS_ENSURE_ARG_POINTER(_retval); - *_retval = ldap_get_lderrno(this->mConnectionHandle, matched, errString); + *_retval = ldap_get_lderrno(mConnectionHandle, matched, errString); return NS_OK; } @@ -204,32 +208,26 @@ nsLDAPConnection::GetLdErrno(char **matched, char **errString, // // XXX - deal with optional params // XXX - how does ldap_perror know to look at the global errno? -// XXX - should copy before returning // NS_IMETHODIMP nsLDAPConnection::GetErrorString(char **_retval) { NS_ENSURE_ARG_POINTER(_retval); - *_retval = ldap_err2string(ldap_get_lderrno(this->mConnectionHandle, - NULL, NULL)); - return NS_OK; -} - -// really only for the internal use of nsLDAPOperation and friends -// -// [ptr] native ldapPtr(LDAP); -// [noscript] readonly attribute ldapPtr connection; -// -NS_IMETHODIMP -nsLDAPConnection::GetConnectionHandle(LDAP* *aConnectionHandle) -{ - if (!aConnectionHandle) { - NS_ERROR("nsLDAPConnection::GetConnectionHandle(): null pointer " - "passed in"); + // get the error string + // + char *rv = ldap_err2string(ldap_get_lderrno(mConnectionHandle, 0, 0)); + if (!rv) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // make a copy using the XPCOM shared allocator + // + *_retval = nsCRT::strdup(rv); + if (!*_retval) { + return NS_ERROR_OUT_OF_MEMORY; } - *aConnectionHandle = mConnectionHandle; return NS_OK; } @@ -238,10 +236,10 @@ nsLDAPConnection::GetConnectionHandle(LDAP* *aConnectionHandle) * this connection. This is also mainly intended for use by the * nsLDAPOperation code. */ -NS_IMETHODIMP +nsresult nsLDAPConnection::AddPendingOperation(nsILDAPOperation *aOperation) { - PRInt32 msgId; + PRInt32 msgID; if (!aOperation) { return NS_ERROR_ILLEGAL_VALUE; @@ -249,14 +247,14 @@ nsLDAPConnection::AddPendingOperation(nsILDAPOperation *aOperation) // find the message id // - aOperation->GetMessageId(&msgId); + aOperation->GetMessageID(&msgID); // turn it into an nsVoidKey. note that this is another spot that // assumes that sizeof(void*) >= sizeof(PRInt32). // // XXXdmose should really create an nsPRInt32Key. // - nsVoidKey *key = new nsVoidKey(NS_REINTERPRET_CAST(void *, msgId)); + nsVoidKey *key = new nsVoidKey(NS_REINTERPRET_CAST(void *, msgID)); if (!key) { return NS_ERROR_OUT_OF_MEMORY; } @@ -291,17 +289,17 @@ nsLDAPConnection::AddPendingOperation(nsILDAPOperation *aOperation) * * void removePendingOperation(in nsILDAPOperation aOperation); */ -NS_IMETHODIMP +nsresult nsLDAPConnection::RemovePendingOperation(nsILDAPOperation *aOperation) { nsresult rv; - PRInt32 msgId; + PRInt32 msgID; NS_ENSURE_ARG_POINTER(aOperation); // find the message id // - rv = aOperation->GetMessageId(&msgId); + rv = aOperation->GetMessageID(&msgID); NS_ENSURE_SUCCESS(rv, rv); // turn it into an nsVoidKey. note that this is another spot that @@ -309,20 +307,19 @@ nsLDAPConnection::RemovePendingOperation(nsILDAPOperation *aOperation) // // XXXdmose should really create an nsPRInt32Key. // - nsVoidKey *key = new nsVoidKey(NS_REINTERPRET_CAST(void *, msgId)); + nsVoidKey *key = new nsVoidKey(NS_REINTERPRET_CAST(void *, msgID)); if (!key) { return NS_ERROR_OUT_OF_MEMORY; } if (!mPendingOperations->Remove(key)) { -#ifdef DEBUG - PR_fprintf(PR_STDERR, "nsLDAPConnection::RemovePendingOperation was\n" - " unable to remove the requested item from the pending\n" - " operations queue. This probably means that the item\n" - " in question didn't exist in the queue, which in turn\n" - " probably means that you have found a bug in the code\n" - " that calls this function.\n"); -#endif + + NS_ERROR("nsLDAPConnection::RemovePendingOperation was\n" + " unable to remove the requested item from the pending\n" + " operations queue. This probably means that the item\n" + " in question didn't exist in the queue, which in turn\n" + " probably means that you have found a bug in the code\n" + " that calls this function.\n"); delete key; return NS_ERROR_FAILURE; @@ -402,8 +399,6 @@ nsLDAPConnection::Run(void) PR_Sleep(2000); // XXXdmose - reasonable timeslice? continue; - break; - case -1: // something went wrong lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0); @@ -454,15 +449,19 @@ nsLDAPConnection::Run(void) // we want nsLDAPMessage specifically, not a compatible, since // we're sharing native objects used by the LDAP C SDK // - msg = new nsLDAPMessage(); - if (!msg) { + nsLDAPMessage *rawMsg = new nsLDAPMessage(); + if (!rawMsg) { consoleSvc->LogStringMessage( NS_LITERAL_STRING("LDAP: ERROR: couldn't allocate memory for new LDAP message; search entry dropped").get()); // punt and hope things work out better next time around break; } - rv = msg->Init(this, msgHandle); + // initialize the message, using a protected method not available + // through nsILDAPMessage (which is why we need the raw pointer) + // + rv = rawMsg->Init(this, msgHandle); + switch (rv) { case NS_OK: @@ -474,14 +473,12 @@ nsLDAPConnection::Run(void) NS_WARNING("nsLDAPConnection::Run(): ldaperrno = " "LDAP_DECODING_ERROR after ldap_result()"); continue; - break; case NS_ERROR_OUT_OF_MEMORY: consoleSvc->LogStringMessage( NS_LITERAL_STRING("LDAP: ERROR: couldn't allocate memory for new LDAP message; search entry dropped").get()); // punt and hope things work out better next time around continue; - break; case NS_ERROR_ILLEGAL_VALUE: case NS_ERROR_UNEXPECTED: @@ -495,9 +492,13 @@ nsLDAPConnection::Run(void) // punt and hope things work out better next time around continue; - break; } + // now let the scoping mechanisms provided by nsCOMPtr manage + // the reference for us. + // + msg = rawMsg; + // invoke the callback on the nsILDAPOperation corresponding to // this message // @@ -508,7 +509,6 @@ nsLDAPConnection::Run(void) NS_ERROR("LDAP: ERROR: problem invoking message callback"); // punt and hope things work out better next time around continue; - break; } #if 0 @@ -562,7 +562,7 @@ nsLDAPConnection::InvokeMessageCallback(LDAPMessage *aMsgHandle, // find the operation in question // nsISupports *data = mPendingOperations->Get(key); - if (data == nsnull) { + if (!data) { PR_LOG(gLDAPLogModule, PR_LOG_WARNING, ("Warning: InvokeMessageCallback(): couldn't find " diff --git a/mozilla/directory/xpcom/base/src/nsLDAPConnection.h b/mozilla/directory/xpcom/base/src/nsLDAPConnection.h index 3f731d5a3d6..a355ffdff00 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPConnection.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPConnection.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -71,14 +72,39 @@ class nsLDAPConnection : public nsILDAPConnection, nsIRunnable // delete it from the connection queue // nsresult InvokeMessageCallback(LDAPMessage *aMsgHandle, - nsILDAPMessage *aMsg, - PRBool aRemoveOpFromConnQ); + nsILDAPMessage *aMsg, + PRBool aRemoveOpFromConnQ); + /** + * Add an nsILDAPOperation to the list of operations pending on + * this connection. This is mainly intended for use by the + * nsLDAPOperation code. Used so that the thread waiting on messages + * for this connection has an operation to callback to. + * + * @param aOperation operation to add + * @exception NS_ERROR_ILLEGAL_VALUE aOperation was NULL + * @exception NS_ERROR_UNEXPECTED this operation's msgId was not + * unique to this connection + * @exception NS_ERROR_OUT_OF_MEMORY out of memory + */ + nsresult AddPendingOperation(nsILDAPOperation *aOperation); - LDAP *mConnectionHandle; // the LDAP C SDK's connection object - nsCString *mBindName; // who to bind as - nsCOMPtr mThread; // thread which marshals results + /** + * Remove an nsILDAPOperation from the list of operations pending on this + * connection. Mainly intended for use by the nsLDAPOperation code. + * + * @param aOperation operation to add + * @exception NS_ERROR_INVALID_POINTER aOperation was NULL + * @exception NS_ERROR_OUT_OF_MEMORY out of memory + * @exception NS_ERROR_FAILURE could not delete the operation + */ + nsresult RemovePendingOperation(nsILDAPOperation *aOperation); + + + LDAP *mConnectionHandle; // the LDAP C SDK's connection object + nsCString *mBindName; // who to bind as + nsCOMPtr mThread; // thread which marshals results nsSupportsHashtable *mPendingOperations; // keep these around for callbacks }; -#endif /* _nsLDAPConnection_h_ */ +#endif // _nsLDAPConnection_h_ diff --git a/mozilla/directory/xpcom/base/src/nsLDAPConnectionCallbacks.c b/mozilla/directory/xpcom/base/src/nsLDAPConnectionCallbacks.c index 46d88e1e827..ca24e9f9208 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPConnectionCallbacks.c +++ b/mozilla/directory/xpcom/base/src/nsLDAPConnectionCallbacks.c @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -33,7 +34,7 @@ #include "nspr.h" #include "ldap.h" -// XXXdmose errno.h should go away, probably after ldap C SDK 4.1 lands +/* XXXdmose errno.h should go away, probably after ldap C SDK 4.1 lands */ #include "errno.h" /* one of these exists per thread */ @@ -62,12 +63,12 @@ nsLDAPThreadDataInit(void) if (kLDAPErrnoData == 0) { if (PR_NewThreadPrivateIndex(&kLDAPErrnoData, &PR_Free) - != PR_SUCCESS) { + != PR_SUCCESS) { #ifdef DEBUG - PR_fprintf(PR_STDERR, "nsLDAPThreadDataInit(): error " - "allocating kLDAPErrorData thread-private index.\n"); + PR_fprintf(PR_STDERR, "nsLDAPThreadDataInit(): error " + "allocating kLDAPErrorData thread-private index.\n"); #endif - return 0; + return 0; } } @@ -91,7 +92,7 @@ nsLDAPThreadDataInit(void) if ( PR_SetThreadPrivate(kLDAPErrnoData, errnoData) != PR_SUCCESS ) { #ifdef DEBUG PR_fprintf(PR_STDERR, "nsLDAPThreadDataInit(): PR_SetThreadPrivate " - "failed\n"); + "failed\n"); #endif return 0; } @@ -110,18 +111,18 @@ nsLDAPSetLderrno(int aErrno, char *aMatched, char *aErrMsg, void *aDummy) nle = PR_GetThreadPrivate(kLDAPErrnoData); if (!nle) { -#ifdef DEBUG - PR_fprintf(PR_STDERR, "nsLDAPSetLDAPErrno(): PR_GetThreadPrivate " - "failed\n"); +#ifdef DEBUG + PR_fprintf(PR_STDERR, "nsLDAPSetLDAPErrno(): PR_GetThreadPrivate " + "failed\n"); #endif - return; + return; } nle->mErrno = aErrno; /* free any previous setting and replace it with the new one */ if ( nle->mMatched != NULL ) { - ldap_memfree( nle->mMatched ); + ldap_memfree( nle->mMatched ); } nle->mMatched = aMatched; @@ -144,7 +145,7 @@ nsLDAPGetLderrno( char **aMatched, char **aErrMsg, void *aDummy ) if (!nle) { #ifdef DEBUG PR_fprintf(PR_STDERR, "nsLDAPSetLDAPErrno(): PR_GetThreadPrivate " - "failed\n"); + "failed\n"); #endif return LDAP_OTHER; } @@ -196,11 +197,9 @@ nsLDAPThreadFuncsInit(LDAP *aLDAP) kLDAPThreadFuncs.ltf_lderrno_arg = NULL; if (ldap_set_option(aLDAP, LDAP_OPT_THREAD_FN_PTRS, - (void *)&kLDAPThreadFuncs) != 0) { - return 0; + (void *)&kLDAPThreadFuncs) != 0) { + return 0; } return 1; } - - diff --git a/mozilla/directory/xpcom/base/src/nsLDAPInternal.h b/mozilla/directory/xpcom/base/src/nsLDAPInternal.h index 1234d5d2f5d..67cc9caa0c8 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPInternal.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPInternal.h @@ -1,21 +1,39 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the mozilla.org LDAP XPCOM SDK. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): Dan Mosedale + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU General Public License Version 2 or later (the + * "GPL"), in which case the provisions of the GPL are applicable + * instead of those above. If you wish to allow use of your + * version of this file only under the terms of the GPL and not to + * allow others to use your version of this file under the MPL, + * indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by + * the GPL. If you do not delete the provisions above, a recipient + * may use your version of this file under either the MPL or the + * GPL. */ #include "nsLDAP.h" #include "nspr.h" -// frees all elements of an XPIDL out array of a given size using -// freeFunc(), then frees the array itself using nsMemory::Free(). -// Thanks to for suggesting this form, which can be -// used to NS_RELEASE entire arrays before freeing as well. -// -#define NSLDAP_FREE_XPIDL_ARRAY(size, array, freeFunc) \ - for ( PRUint32 __iter__ = (size) ; __iter__ > 0 ; ) \ - freeFunc((array)[--__iter__]); \ - nsMemory::Free(array); - -// XXXdmose should this really be DEBUG-only? -// -#ifdef DEBUG -extern PRLogModuleInfo *gLDAPLogModule; // defn in nsLDAPProtocolModule.cpp +#ifdef PR_LOGGING +extern PRLogModuleInfo *gLDAPLogModule; // defn in nsLDAPProtocolModule.cpp #endif diff --git a/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp b/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp index 56e9f8e96f1..10dfb9cc12a 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp @@ -10,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -37,34 +37,30 @@ #include "nspr.h" #include "nsDebug.h" #include "nsCRT.h" +#include "nsLDAPConnection.h" NS_IMPL_THREADSAFE_ISUPPORTS1(nsLDAPMessage, nsILDAPMessage); // constructor // -nsLDAPMessage::nsLDAPMessage() +nsLDAPMessage::nsLDAPMessage() + : mMsgHandle(0), + mMatchedDn(0), + mErrorMessage(0), + mReferrals(0), + mServerControls(0) { NS_INIT_ISUPPORTS(); - - mMsgHandle = 0; - mConnectionHandle = 0; - - // stuff returned by ldap_parse_result - // - mMatchedDn = 0; - mErrorMessage = 0; - mReferrals = 0; - mServerControls = 0; } // destructor // nsLDAPMessage::~nsLDAPMessage(void) { - int rc; + if (mMsgHandle) { - rc = ldap_msgfree(mMsgHandle); + int rc = ldap_msgfree(mMsgHandle); switch(rc) { case LDAP_RES_BIND: @@ -115,9 +111,18 @@ nsLDAPMessage::~nsLDAPMessage(void) } -// associate this message with an existing operation -// -NS_IMETHODIMP +/** + * Initializes a message. + * + * @param aConnection The nsLDAPConnection this message is on + * @param aMsgHandle The native LDAPMessage to be wrapped. + * + * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in + * @exception NS_ERROR_UNEXPECTED internal err; shouldn't happen + * @exception NS_ERROR_LDAP_DECODING_ERROR problem during BER decoding + * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory + */ +nsresult nsLDAPMessage::Init(nsILDAPConnection *aConnection, LDAPMessage *aMsgHandle) { int parseResult; @@ -132,14 +137,12 @@ nsLDAPMessage::Init(nsILDAPConnection *aConnection, LDAPMessage *aMsgHandle) mConnection = aConnection; mMsgHandle = aMsgHandle; - // cache the connection handle associated with this operation + // cache the connection handle. we're violating the XPCOM type-system + // here since we're a friend of the connection class and in the + // same module. // - nsresult rv = mConnection->GetConnectionHandle(&mConnectionHandle); - if (NS_FAILED(rv)) { - NS_WARNING("nsLDAPMessage::Init(): mConnection->GetConnectionHandle() " - "failed"); - return NS_ERROR_UNEXPECTED; - } + mConnectionHandle = NS_STATIC_CAST(nsLDAPConnection *, + aConnection)->mConnectionHandle; // do any useful message parsing // @@ -170,8 +173,8 @@ nsLDAPMessage::Init(nsILDAPConnection *aConnection, LDAPMessage *aMsgHandle) case LDAP_RES_DELETE: case LDAP_RES_MODRDN: case LDAP_RES_COMPARE: - parseResult = ldap_parse_result(mConnectionHandle, mMsgHandle, - &mErrorCode, &mMatchedDn, + parseResult = ldap_parse_result(mConnectionHandle, + mMsgHandle, &mErrorCode, &mMatchedDn, &mErrorMessage,&mReferrals, &mServerControls, 0); switch (parseResult) { @@ -183,13 +186,11 @@ nsLDAPMessage::Init(nsILDAPConnection *aConnection, LDAPMessage *aMsgHandle) NS_WARNING("nsLDAPMessage::Init(): ldap_parse_result() hit a " "decoding error"); return NS_ERROR_LDAP_DECODING_ERROR; - break; case LDAP_NO_MEMORY: NS_WARNING("nsLDAPMessage::Init(): ldap_parse_result() ran out " "of memory"); return NS_ERROR_OUT_OF_MEMORY; - break; case LDAP_PARAM_ERROR: case LDAP_MORE_RESULTS_TO_RETURN: @@ -198,7 +199,6 @@ nsLDAPMessage::Init(nsILDAPConnection *aConnection, LDAPMessage *aMsgHandle) NS_ERROR("nsLDAPMessage::Init(): ldap_parse_result returned " "unexpected return code"); return NS_ERROR_UNEXPECTED; - break; } break; @@ -206,7 +206,6 @@ nsLDAPMessage::Init(nsILDAPConnection *aConnection, LDAPMessage *aMsgHandle) default: NS_ERROR("nsLDAPMessage::Init(): unexpected message type"); return NS_ERROR_UNEXPECTED; - break; } return NS_OK; @@ -256,7 +255,7 @@ nsLDAPMessage::IterateAttrErrHandler(PRInt32 aLderrno, PRUint32 *aAttrCount, // if necessary, free the position holder used by // ldap_{first,next}_attribute() // - if (position != nsnull) { + if (position) { ldap_ber_free(position, 0); } @@ -264,7 +263,7 @@ nsLDAPMessage::IterateAttrErrHandler(PRInt32 aLderrno, PRUint32 *aAttrCount, // the array itself // if (*aAttributes) { - NSLDAP_FREE_XPIDL_ARRAY(*aAttrCount, *aAttributes, nsMemory::Free); + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(*aAttrCount, *aAttributes); } // possibly spit out a debugging message, then return an appropriate @@ -279,7 +278,7 @@ nsLDAPMessage::IterateAttrErrHandler(PRInt32 aLderrno, PRUint32 *aAttrCount, break; case LDAP_DECODING_ERROR: - NS_WARNING("nsLDAPMessage::IterateAttributes(): decoding error"); + NS_WARNING("nsLDAPMessage::IterateAttributes(): decoding error"); return NS_ERROR_LDAP_DECODING_ERROR; break; @@ -311,12 +310,12 @@ nsLDAPMessage::GetAttributes(PRUint32 *aAttrCount, char** *aAttributes) // nsresult nsLDAPMessage::IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes, - PRBool getP) + PRBool getP) { BerElement *position; nsresult rv; - if (aAttrCount == nsnull || aAttributes == nsnull ) { + if (!aAttrCount || !aAttributes ) { return NS_ERROR_INVALID_POINTER; } @@ -324,7 +323,7 @@ nsLDAPMessage::IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes, // count the elements in this message. // if (getP) { - *aAttributes = nsnull; + *aAttributes = 0; *aAttrCount = 0; rv = IterateAttributes(aAttrCount, aAttributes, PR_FALSE); @@ -343,11 +342,11 @@ nsLDAPMessage::IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes, // get the first attribute // - char *attr = ldap_first_attribute(mConnectionHandle, mMsgHandle, + char *attr = ldap_first_attribute(mConnectionHandle, + mMsgHandle, &position); - if (attr == nsnull) { - return IterateAttrErrHandler(ldap_get_lderrno(mConnectionHandle, - NULL, NULL), + if (!attr) { + return IterateAttrErrHandler(ldap_get_lderrno(mConnectionHandle, 0, 0), aAttrCount, aAttributes, position); } @@ -375,18 +374,18 @@ nsLDAPMessage::IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes, ldap_memfree(attr); while (1) { - + // get the next attribute // attr = ldap_next_attribute(mConnectionHandle, mMsgHandle, position); // check to see if there is an error, or if we're just done iterating // - if (attr == nsnull) { + if (!attr) { // bail out if there's an error // - PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, NULL, NULL); + PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0); if (lderrno != LDAP_SUCCESS) { return IterateAttrErrHandler(lderrno, aAttrCount, aAttributes, position); @@ -420,49 +419,36 @@ nsLDAPMessage::IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes, // free the position pointer, if necessary // - if (position != nsnull) { + if (!position) { ldap_ber_free(position, 0); } return NS_OK; } -/* - * Wrapper for ldap_get_dn(). Returns the Distinguished Name of the - * entry associated with this message. - * - * @exception NS_ERROR_OUT_OF_MEMORY ran out of memory - * @exception NS_ERROR_ILLEGAL_VALUE null pointer passed in - * @exception NS_ERROR_LDAP_DECODING_ERROR problem during BER-decoding - * @exception NS_ERROR_UNEXPECTED bug or memory corruption hit - * - * readonly attribute string dn; - */ NS_IMETHODIMP nsLDAPMessage::GetDn(char* *aDN) { - if (aDN == nsnull) { + if (!aDN) { return NS_ERROR_ILLEGAL_VALUE; } char *dn = ldap_get_dn(mConnectionHandle, mMsgHandle); if (!dn) { - PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, NULL, NULL); + PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0); - switch (lderrno) { + switch (lderrno) { - case LDAP_DECODING_ERROR: - NS_WARNING("nsLDAPMessage::GetDn(): ldap decoding error"); - return NS_ERROR_LDAP_DECODING_ERROR; - break; + case LDAP_DECODING_ERROR: + NS_WARNING("nsLDAPMessage::GetDn(): ldap decoding error"); + return NS_ERROR_LDAP_DECODING_ERROR; - case LDAP_PARAM_ERROR: - default: - NS_ERROR("nsLDAPMessage::GetDn(): internal error"); - return NS_ERROR_UNEXPECTED; - break; - } + case LDAP_PARAM_ERROR: + default: + NS_ERROR("nsLDAPMessage::GetDn(): internal error"); + return NS_ERROR_UNEXPECTED; + } } // get a copy made with the shared allocator, and dispose of the original @@ -490,7 +476,7 @@ nsLDAPMessage::GetValues(const char *aAttr, PRUint32 *aCount, // bail out if there was a problem // if (!values) { - PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, NULL, NULL); + PRInt32 lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0); if ( lderrno == LDAP_DECODING_ERROR ) { NS_WARNING("nsLDAPMessage::GetValues(): Error decoding values"); @@ -524,8 +510,8 @@ nsLDAPMessage::GetValues(const char *aAttr, PRUint32 *aCount, PRUint32 i; for ( i = 0 ; i < numVals ; i++ ) { (*aValues)[i] = nsCRT::strdup(values[i]); - if ((*aValues)[i] == nsnull ) { - NSLDAP_FREE_XPIDL_ARRAY(i, aValues, nsMemory::Free); + if ( ! (*aValues)[i] ) { + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, aValues); return NS_ERROR_OUT_OF_MEMORY; } } @@ -534,12 +520,8 @@ nsLDAPMessage::GetValues(const char *aAttr, PRUint32 *aCount, return NS_OK; } -// returns an LDIF-like string representation of this message -// -// string toString(); -// NS_IMETHODIMP -nsLDAPMessage::ToString(char* *aString) +nsLDAPMessage::ToUnicode(PRUnichar* *aString) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/directory/xpcom/base/src/nsLDAPMessage.h b/mozilla/directory/xpcom/base/src/nsLDAPMessage.h index a19d444f32b..98ce28e9a13 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPMessage.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPMessage.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -37,7 +38,6 @@ #include "ldap.h" #include "nsILDAPMessage.h" #include "nsILDAPOperation.h" -#include "nsILDAPConnection.h" #include "nsCOMPtr.h" // 76e061ad-a59f-43b6-b812-ee6e8e69423f @@ -49,8 +49,9 @@ class nsLDAPMessage : public nsILDAPMessage { friend class nsLDAPOperation; + friend class nsLDAPConnection; - public: + public: NS_DECL_ISUPPORTS NS_DECL_NSILDAPMESSAGE @@ -62,13 +63,21 @@ class nsLDAPMessage : public nsILDAPMessage protected: nsresult IterateAttrErrHandler(PRInt32 aLderrno, PRUint32 *aAttrCount, - char** *aAttributes, BerElement *position); + char** *aAttributes, BerElement *position); nsresult IterateAttributes(PRUint32 *aAttrCount, char** *aAttributes, - PRBool getP); + PRBool getP); + nsresult Init(nsILDAPConnection *aConnection, + LDAPMessage *aMsgHandle); LDAPMessage *mMsgHandle; // the message we're wrapping nsCOMPtr mOperation; // operation this msg relates to - nsCOMPtr mConnection; // cached connection this op is on - LDAP *mConnectionHandle; // cached connection handle + + LDAP *mConnectionHandle; // cached connection this op is on + + // since we're caching the connection handle (above), we need to + // hold an owning ref to the relevant nsLDAPConnection object as long + // as we're around + // + nsCOMPtr mConnection; // the next five member vars are returned by ldap_parse_result() // @@ -79,4 +88,4 @@ class nsLDAPMessage : public nsILDAPMessage LDAPControl **mServerControls; }; -#endif /* _nsLDAPMessage_h */ +#endif // _nsLDAPMessage_h diff --git a/mozilla/directory/xpcom/base/src/nsLDAPOperation.cpp b/mozilla/directory/xpcom/base/src/nsLDAPOperation.cpp index 72edcdf0af1..0ebe4d4e9b0 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPOperation.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPOperation.cpp @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -33,6 +34,7 @@ #include "nsLDAP.h" #include "nsLDAPOperation.h" +#include "nsLDAPConnection.h" #include "nsILDAPMessage.h" #include "nsIComponentManager.h" #include "nsXPIDLString.h" @@ -59,27 +61,26 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsLDAPOperation, nsILDAPOperation); */ NS_IMETHODIMP nsLDAPOperation::Init(nsILDAPConnection *aConnection, - nsILDAPMessageListener *aMessageListener) + nsILDAPMessageListener *aMessageListener) { if (!aConnection) { - return NS_ERROR_ILLEGAL_VALUE; + return NS_ERROR_ILLEGAL_VALUE; } // so we know that the operation is not yet running (and therefore don't // try and call ldap_abandon_ext() on it) or remove it from the queue. // - mMsgId = 0; + mMsgID = 0; // set the member vars // mConnection = aConnection; mMessageListener = aMessageListener; - // get and cache the connection handle - // - nsresult rv = mConnection->GetConnectionHandle(&mConnectionHandle); - if (NS_FAILED(rv)) - return NS_ERROR_UNEXPECTED; + // cache the connection handle + // + mConnectionHandle = + NS_STATIC_CAST(nsLDAPConnection *, aConnection)->mConnectionHandle; return NS_OK; } @@ -88,7 +89,7 @@ NS_IMETHODIMP nsLDAPOperation::GetConnection(nsILDAPConnection* *aConnection) { if (!aConnection) { - return NS_ERROR_ILLEGAL_VALUE; + return NS_ERROR_ILLEGAL_VALUE; } *aConnection = mConnection; @@ -101,7 +102,7 @@ NS_IMETHODIMP nsLDAPOperation::GetMessageListener(nsILDAPMessageListener **aMessageListener) { if (!aMessageListener) { - return NS_ERROR_ILLEGAL_VALUE; + return NS_ERROR_ILLEGAL_VALUE; } *aMessageListener = mMessageListener; @@ -120,54 +121,56 @@ nsLDAPOperation::SimpleBind(const char *passwd) NS_PRECONDITION(mMessageListener != 0, "MessageListener not set"); - rv = this->mConnection->GetBindName(getter_Copies(bindName)); + rv = mConnection->GetBindName(getter_Copies(bindName)); if (NS_FAILED(rv)) - return rv; + return rv; - this->mMsgId = ldap_simple_bind(this->mConnectionHandle, bindName, passwd); + mMsgID = ldap_simple_bind(mConnectionHandle, bindName, passwd); - if (this->mMsgId == -1) { - const int lderrno = ldap_get_lderrno(this->mConnectionHandle, 0, 0); - - switch (lderrno) { + if (mMsgID == -1) { + const int lderrno = ldap_get_lderrno(mConnectionHandle, 0, 0); + + switch (lderrno) { - case LDAP_ENCODING_ERROR: - return NS_ERROR_LDAP_ENCODING_ERROR; + case LDAP_ENCODING_ERROR: + return NS_ERROR_LDAP_ENCODING_ERROR; - case LDAP_SERVER_DOWN: - // XXXdmose rebind here? - return NS_ERROR_FAILURE; + case LDAP_SERVER_DOWN: + // XXXdmose rebind here? + return NS_ERROR_FAILURE; - case LDAP_NO_MEMORY: - return NS_ERROR_OUT_OF_MEMORY; + case LDAP_NO_MEMORY: + return NS_ERROR_OUT_OF_MEMORY; - default: - return NS_ERROR_UNEXPECTED; - } + default: + return NS_ERROR_UNEXPECTED; + } } // make sure the connection knows where to call back once the messages // for this operation start coming in // - rv = mConnection->AddPendingOperation(this); + rv = NS_STATIC_CAST(nsLDAPConnection *, + NS_STATIC_CAST(nsILDAPConnection *, + mConnection.get()))->AddPendingOperation(this); switch (rv) { case NS_OK: - break; + break; - // note that the return value of ldap_abandon_ext() is ignored, as - // there's nothing useful to do with it + // note that the return value of ldap_abandon_ext() is ignored, as + // there's nothing useful to do with it case NS_ERROR_OUT_OF_MEMORY: - (void *)ldap_abandon_ext(mConnectionHandle, mMsgId, 0, 0); - return NS_ERROR_OUT_OF_MEMORY; - break; + (void *)ldap_abandon_ext(mConnectionHandle, mMsgID, 0, 0); + return NS_ERROR_OUT_OF_MEMORY; + break; case NS_ERROR_UNEXPECTED: case NS_ERROR_ILLEGAL_VALUE: default: - (void *)ldap_abandon_ext(mConnectionHandle, mMsgId, 0, 0); - return NS_ERROR_UNEXPECTED; + (void *)ldap_abandon_ext(mConnectionHandle, mMsgID, 0, 0); + return NS_ERROR_UNEXPECTED; } return NS_OK; @@ -177,143 +180,107 @@ nsLDAPOperation::SimpleBind(const char *passwd) // int nsLDAPOperation::SearchExt(const char *base, // base DN to search - int scope, // LDAP_SCOPE_{BASE,ONELEVEL,SUBTREE} - const char* filter, // search filter - char **attrs, // attribute types to be returned - int attrsOnly, // attrs only, or values too? - LDAPControl **serverctrls, - LDAPControl **clientctrls, - struct timeval *timeoutp, // how long to wait - int sizelimit) // max # of entries to return + int scope, // SCOPE_{BASE,ONELEVEL,SUBTREE} + const char* filter, // search filter + char **attrs, // attribute types to be returned + int attrsOnly, // attrs only, or values too? + LDAPControl **serverctrls, + LDAPControl **clientctrls, + struct timeval *timeoutp, // how long to wait + int sizelimit) // max # of entries to return { if (mMessageListener == 0) { - NS_ERROR("nsLDAPOperation::SearchExt(): mMessageListener not set"); - return NS_ERROR_NOT_INITIALIZED; + NS_ERROR("nsLDAPOperation::SearchExt(): mMessageListener not set"); + return NS_ERROR_NOT_INITIALIZED; } - return ldap_search_ext(this->mConnectionHandle, base, scope, - filter, attrs, attrsOnly, serverctrls, - clientctrls, timeoutp, sizelimit, - &(this->mMsgId)); + return ldap_search_ext(mConnectionHandle, base, scope, + filter, attrs, attrsOnly, serverctrls, + clientctrls, timeoutp, sizelimit, + &mMsgID); } /** * wrapper for ldap_search_ext(): kicks off an async search request. * - * @param aBaseDn Base DN to search - * @param aScope One of LDAP_SCOPE_{BASE,ONELEVEL,SUBTREE} - * @param aFilter Search filter - * @param aTimeOut How long to wait - * @param aSizeLimit Maximum number of entries to return. + * @param aBaseDn Base DN to search + * @param aScope One of SCOPE_{BASE,ONELEVEL,SUBTREE} + * @param aFilter Search filter + * @param aTimeOut How long to wait + * @param aSizeLimit Maximum number of entries to return. * * XXX doesn't currently handle LDAPControl params * * void searchExt(in string aBaseDn, in PRInt32 aScope, - * in string aFilter, in PRIntervalTime aTimeOut, - * in PRInt32 aSizeLimit); + * in string aFilter, in PRIntervalTime aTimeOut, + * in PRInt32 aSizeLimit); */ NS_IMETHODIMP nsLDAPOperation::SearchExt(const char *aBaseDn, PRInt32 aScope, - const char *aFilter, PRIntervalTime aTimeOut, - PRInt32 aSizeLimit) + const char *aFilter, PRIntervalTime aTimeOut, + PRInt32 aSizeLimit) { // XXX deal with timeouts // - int retVal = nsLDAPOperation::SearchExt(aBaseDn, aScope, aFilter, NULL, 0, - NULL, NULL, NULL, aSizeLimit); + int retVal = SearchExt(aBaseDn, aScope, aFilter, 0, 0, + 0, 0, 0, aSizeLimit); switch (retVal) { case LDAP_SUCCESS: - break; + break; case LDAP_ENCODING_ERROR: - return NS_ERROR_LDAP_ENCODING_ERROR; - break; + return NS_ERROR_LDAP_ENCODING_ERROR; case LDAP_SERVER_DOWN: - return NS_ERROR_LDAP_SERVER_DOWN; - break; + return NS_ERROR_LDAP_SERVER_DOWN; case LDAP_NO_MEMORY: - return NS_ERROR_OUT_OF_MEMORY; - break; + return NS_ERROR_OUT_OF_MEMORY; case LDAP_NOT_SUPPORTED: - return NS_ERROR_LDAP_NOT_SUPPORTED; - break; + return NS_ERROR_LDAP_NOT_SUPPORTED; case LDAP_PARAM_ERROR: + return NS_ERROR_INVALID_ARG; + default: - NS_ERROR("nsLDAPOperation::SearchExt(): unexpected return value"); - return NS_ERROR_UNEXPECTED; + NS_ERROR("nsLDAPOperation::SearchExt(): unexpected return value"); + return NS_ERROR_UNEXPECTED; } // make sure the connection knows where to call back once the messages // for this operation start coming in // - nsresult rv = mConnection->AddPendingOperation(this); + nsresult rv = NS_STATIC_CAST(nsLDAPConnection *, NS_STATIC_CAST( + nsILDAPConnection *, mConnection.get()))->AddPendingOperation(this); if (NS_FAILED(rv)) { - switch (rv) { - case NS_ERROR_OUT_OF_MEMORY: - (void *)ldap_abandon_ext(mConnectionHandle, mMsgId, 0, 0); - return NS_ERROR_OUT_OF_MEMORY; - break; + switch (rv) { + case NS_ERROR_OUT_OF_MEMORY: + (void *)ldap_abandon_ext(mConnectionHandle, mMsgID, 0, 0); + return NS_ERROR_OUT_OF_MEMORY; - default: - (void *)ldap_abandon_ext(mConnectionHandle, mMsgId, 0, 0); - NS_ERROR("nsLDAPOperation::SearchExt(): unexpected error in " - "mConnection->AddPendingOperation"); - return NS_ERROR_UNEXPECTED; - break; - } + default: + (void *)ldap_abandon_ext(mConnectionHandle, mMsgID, 0, 0); + NS_ERROR("nsLDAPOperation::SearchExt(): unexpected error in " + "mConnection->AddPendingOperation"); + return NS_ERROR_UNEXPECTED; + } } return NS_OK; } -// wrapper for ldap_url_search -// NS_IMETHODIMP -nsLDAPOperation::UrlSearch(const char *aURL, // the search URL - PRBool aAttrsOnly) // skip attribute names? +nsLDAPOperation::GetMessageID(PRInt32 *aMsgID) { - NS_ENSURE_ARG(aURL); - NS_PRECONDITION(mMessageListener != 0, "MessageListener not set"); - - this->mMsgId = ldap_url_search(this->mConnectionHandle, aURL, - aAttrsOnly); - if (this->mMsgId == -1) { - // XXX - PR_Abort(); -#ifdef DEBUG - char *s; - - (void)this->mConnection->GetErrorString(&s); - PR_fprintf(PR_STDERR, "UrlSearch failed: %s\n", s); - ldap_memfree(s); -#endif - return NS_ERROR_FAILURE; + if (!aMsgID) { + return NS_ERROR_ILLEGAL_VALUE; } - // make sure the connection knows where to call back once the messages - // for this operation start coming in - // XXX should abandon operation if this fails - nsresult rv = mConnection->AddPendingOperation(this); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -NS_IMETHODIMP -nsLDAPOperation::GetMessageId(PRInt32 *aMsgId) -{ - if (!aMsgId) { - return NS_ERROR_ILLEGAL_VALUE; - } - - *aMsgId = this->mMsgId; + *aMsgID = mMsgID; return NS_OK; } @@ -323,41 +290,40 @@ nsLDAPOperation::GetMessageId(PRInt32 *aMsgId) // nsresult nsLDAPOperation::AbandonExt(LDAPControl **serverctrls, - LDAPControl **clientctrls) + LDAPControl **clientctrls) { nsresult rv; int retVal; - if ( mMessageListener == 0 || mMsgId == 0 ) { - NS_ERROR("nsLDAPOperation::AbandonExt(): mMessageListener or " - "mMsgId not initialized"); - return NS_ERROR_NOT_INITIALIZED; + if ( mMessageListener == 0 || mMsgID == 0 ) { + NS_ERROR("nsLDAPOperation::AbandonExt(): mMessageListener or " + "mMsgId not initialized"); + return NS_ERROR_NOT_INITIALIZED; } - retVal = ldap_abandon_ext(mConnectionHandle, mMsgId, serverctrls, - clientctrls); + retVal = ldap_abandon_ext(mConnectionHandle, mMsgID, serverctrls, + clientctrls); switch (retVal) { case LDAP_SUCCESS: - break; + break; case LDAP_ENCODING_ERROR: - return NS_ERROR_LDAP_ENCODING_ERROR; - break; + return NS_ERROR_LDAP_ENCODING_ERROR; case LDAP_SERVER_DOWN: - return NS_ERROR_LDAP_SERVER_DOWN; - break; + return NS_ERROR_LDAP_SERVER_DOWN; case LDAP_NO_MEMORY: - return NS_ERROR_OUT_OF_MEMORY; - break; + return NS_ERROR_OUT_OF_MEMORY; case LDAP_PARAM_ERROR: + return NS_ERROR_INVALID_ARG; + default: - NS_ERROR("nsLDAPOperation::AbandonExt(): unexpected return value from " - "ldap_abandon_ext"); - return NS_ERROR_UNEXPECTED; + NS_ERROR("nsLDAPOperation::AbandonExt(): unexpected return value from " + "ldap_abandon_ext"); + return NS_ERROR_UNEXPECTED; } // try to remove it from the pendingOperations queue, if it's there. @@ -365,15 +331,17 @@ nsLDAPOperation::AbandonExt(LDAPControl **serverctrls, // succeeded (and there's nothing else the caller can reasonably do), // so we only pay attention to this in debug builds. // - rv = mConnection->RemovePendingOperation(this); + rv = NS_STATIC_CAST(nsLDAPConnection *, NS_STATIC_CAST( + nsILDAPConnection *, mConnection.get()))->RemovePendingOperation(this); + if (NS_FAILED(rv)) { - // XXXdmose should we use keep Abandon from happening on multiple - // threads at the same time? that's when this condition is most - // likely to occur. i _think_ the LDAP C SDK is ok with this; need - // to verify. - // - NS_WARNING("nsLDAPOperation::AbandonExt: " - "mConnection->RemovePendingOperation(this) failed."); + // XXXdmose should we use keep Abandon from happening on multiple + // threads at the same time? that's when this condition is most + // likely to occur. i _think_ the LDAP C SDK is ok with this; need + // to verify. + // + NS_WARNING("nsLDAPOperation::AbandonExt: " + "mConnection->RemovePendingOperation(this) failed."); } return NS_OK; @@ -382,5 +350,5 @@ nsLDAPOperation::AbandonExt(LDAPControl **serverctrls, NS_IMETHODIMP nsLDAPOperation::Abandon(void) { - return nsLDAPOperation::AbandonExt(NULL, NULL); + return nsLDAPOperation::AbandonExt(0, 0); } diff --git a/mozilla/directory/xpcom/base/src/nsLDAPOperation.h b/mozilla/directory/xpcom/base/src/nsLDAPOperation.h index ca1f86d024d..a1c1b19fcd0 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPOperation.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPOperation.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -64,14 +65,14 @@ class nsLDAPOperation : public nsILDAPOperation * XXX should move to idl, once LDAPControls have an IDL representation */ int SearchExt(const char *base, // base DN to search - int scope, // LDAP_SCOPE_{BASE,ONELEVEL,SUBTREE} - const char* filter, // search filter - char **attrs, // attribute types to be returned - int attrsOnly, // attrs only, or values too? - LDAPControl **serverctrls, - LDAPControl **clientctrls, - struct timeval *timeoutp, // how long to wait - int sizelimit); // max # of entries to return + int scope, // SCOPE_{BASE,ONELEVEL,SUBTREE} + const char* filter, // search filter + char **attrs, // attribute types to be returned + int attrsOnly, // attrs only, or values too? + LDAPControl **serverctrls, + LDAPControl **clientctrls, + struct timeval *timeoutp, // how long to wait + int sizelimit); // max # of entries to return /** * wrapper for ldap_abandon_ext(). @@ -80,10 +81,14 @@ class nsLDAPOperation : public nsILDAPOperation */ nsresult AbandonExt(LDAPControl **serverctrls, LDAPControl **clientctrls); - nsCOMPtr mConnection; // connection this op is on + nsCOMPtr mMessageListener; // results go here - PRInt32 mMsgId; // opaque handle to outbound message for this op - LDAP *mConnectionHandle; // cached from mConnection->GetConnectionHandle() + + nsCOMPtr mConnection; // connection this op is on + + LDAP *mConnectionHandle; // cache connection handle + + PRInt32 mMsgID; // opaque handle to outbound message for this op }; -#endif /* _nsLDAPOperation_h */ +#endif // _nsLDAPOperation_h diff --git a/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.cpp b/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.cpp index 3bdc8b1f605..233bf24869b 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.cpp @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -17,7 +18,7 @@ * Rights Reserved. * * Contributor(s): Dan Mosedale - * Brian Ryner + * Brian Ryner * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the @@ -47,12 +48,10 @@ NS_IMPL_ISUPPORTS1(nsLDAPProtocolHandler, nsIProtocolHandler) nsLDAPProtocolHandler::nsLDAPProtocolHandler() { NS_INIT_ISUPPORTS(); - /* member initializers and constructor code */ } nsLDAPProtocolHandler::~nsLDAPProtocolHandler() { - /* destructor code */ } // nsIProtocolHandler methods @@ -63,7 +62,7 @@ NS_IMETHODIMP nsLDAPProtocolHandler::GetScheme(char **result) { *result = nsCRT::strdup("ldap"); - if ( *result == nsnull ) + if ( ! *result ) return NS_ERROR_OUT_OF_MEMORY; else return NS_OK; @@ -82,7 +81,7 @@ nsLDAPProtocolHandler::GetDefaultPort(PRInt32 *result) // NS_IMETHODIMP nsLDAPProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, - nsIURI **result) + nsIURI **result) { nsCOMPtr url; nsresult rv; @@ -108,24 +107,24 @@ nsLDAPProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, NS_IMETHODIMP nsLDAPProtocolHandler::NewChannel(nsIURI* uri, - nsIChannel* *result) + nsIChannel* *result) { - nsresult rv; - nsLDAPChannel *channel; + nsresult rv; + nsLDAPChannel *channel; - rv = nsLDAPChannel::Create(nsnull, NS_GET_IID(nsIChannel), - NS_REINTERPRET_CAST(void **, &channel)); - NS_ENSURE_SUCCESS(rv, rv); + rv = nsLDAPChannel::Create(0, NS_GET_IID(nsIChannel), + NS_REINTERPRET_CAST(void **, &channel)); + NS_ENSURE_SUCCESS(rv, rv); - rv = channel->Init(uri); - if (NS_FAILED(rv)) { - NS_RELEASE(channel); - return rv; - } - // the channel was already AddRefed for us, and since this function itself - // is a getter, there's no need to release it here. - // - *result = channel; + rv = channel->Init(uri); + if (NS_FAILED(rv)) { + NS_RELEASE(channel); + return rv; + } + // the channel was already AddRefed for us, and since this function itself + // is a getter, there's no need to release it here. + // + *result = channel; - return NS_OK; + return NS_OK; } diff --git a/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.h b/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.h index 47cd9bfc3a1..88a5a389d9d 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPProtocolHandler.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -44,12 +45,12 @@ class nsLDAPProtocolHandler : public nsIProtocolHandler { -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIPROTOCOLHANDLER + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPROTOCOLHANDLER - nsLDAPProtocolHandler(); - virtual ~nsLDAPProtocolHandler(); + nsLDAPProtocolHandler(); + virtual ~nsLDAPProtocolHandler(); }; #endif // nsLDAPProtocolHandler_h__ diff --git a/mozilla/directory/xpcom/base/src/nsLDAPProtocolModule.cpp b/mozilla/directory/xpcom/base/src/nsLDAPProtocolModule.cpp index 0e88e50a017..2eb380d0378 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPProtocolModule.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPProtocolModule.cpp @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -54,18 +55,18 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPURL); static nsModuleComponentInfo components[] = { { "LDAP Protocol Handler", NS_LDAPPROTOCOLHANDLER_CID, - NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ldap", - nsLDAPProtocolHandlerConstructor }, + NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ldap", + nsLDAPProtocolHandlerConstructor }, { "LDAP Service", NS_LDAPSERVICE_CID, - "@mozilla.org/network/ldap-service;1", nsLDAPServiceConstructor }, + "@mozilla.org/network/ldap-service;1", nsLDAPServiceConstructor }, { "LDAP Connection", NS_LDAPCONNECTION_CID, - "@mozilla.org/network/ldap-connection;1", - nsLDAPConnectionConstructor }, + "@mozilla.org/network/ldap-connection;1", + nsLDAPConnectionConstructor }, { "LDAP Operation", NS_LDAPOPERATION_CID, - "@mozilla.org/network/ldap-operation;1", - nsLDAPOperationConstructor }, + "@mozilla.org/network/ldap-operation;1", + nsLDAPOperationConstructor }, { "LDAP Message", NS_LDAPMESSAGE_CID, - "@mozilla.org/network/ldap-message;1", nsLDAPMessageConstructor }, + "@mozilla.org/network/ldap-message;1", nsLDAPMessageConstructor }, { "LDAP URL", NS_LDAPURL_CID, "@mozilla.org/network/ldap-url;1", nsLDAPURLConstructor } }; @@ -74,6 +75,6 @@ static nsModuleComponentInfo components[] = // NS_IMPL_NSGETMODULE("nsLDAPProtocolModule", components); -#ifdef DEBUG +#ifdef PR_LOGGING PRLogModuleInfo *gLDAPLogModule = 0; #endif diff --git a/mozilla/directory/xpcom/base/src/nsLDAPService.cpp b/mozilla/directory/xpcom/base/src/nsLDAPService.cpp index cd486a5489c..acc7d2e3d7c 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPService.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPService.cpp @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -38,7 +39,7 @@ // nsLDAPService::nsLDAPService() { - NS_INIT_ISUPPORTS(); + NS_INIT_ISUPPORTS(); } // destructor @@ -55,15 +56,15 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsLDAPService,nsIRunnable); NS_IMETHODIMP nsLDAPService::Init(void) { - nsresult rv; + nsresult rv; - NS_ASSERTION(!mThread, "nsLDAPService already initialized!"); + NS_ASSERTION(!mThread, "nsLDAPService already initialized!"); - rv = NS_NewThread(getter_AddRefs(mThread), - this, 0, PR_JOINABLE_THREAD); - NS_ENSURE_SUCCESS(rv, rv); + rv = NS_NewThread(getter_AddRefs(mThread), + this, 0, PR_JOINABLE_THREAD); + NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; + return NS_OK; } // for nsIRunnable. all the processing work happens here. @@ -71,14 +72,14 @@ nsLDAPService::Init(void) NS_IMETHODIMP nsLDAPService::Run(void) { - PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("nsLDAPService::Run() entered\n")); + PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("nsLDAPService::Run() entered\n")); - // XXX - should use mThreadRunning here - // - while (1) { + // XXX - should use mThreadRunning here + // + while (1) { + + } - } - - return NS_OK; + return NS_OK; } diff --git a/mozilla/directory/xpcom/base/src/nsLDAPService.h b/mozilla/directory/xpcom/base/src/nsLDAPService.h index 9cfa808b3dd..45028337d76 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPService.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPService.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -48,25 +49,25 @@ class nsLDAPService : public nsIRunnable { - public: - // interface decls - // - NS_DECL_ISUPPORTS - NS_DECL_NSIRUNNABLE + public: + // interface decls + // + NS_DECL_ISUPPORTS + NS_DECL_NSIRUNNABLE - // constructor and destructor - // - nsLDAPService(); - virtual ~nsLDAPService(); + // constructor and destructor + // + nsLDAPService(); + virtual ~nsLDAPService(); - // initialize; should only be called by the generic - // constructor after creation - // - NS_METHOD Init(void); + // initialize; should only be called by the generic + // constructor after creation + // + NS_METHOD Init(void); - protected: - nsCOMPtr mThread; - PRBool mThreadRunning; + protected: + nsCOMPtr mThread; + PRBool mThreadRunning; }; diff --git a/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp b/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp index 25d4f7a3d4f..ac195361b33 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -45,7 +46,7 @@ nsLDAPURL::~nsLDAPURL() ldap_free_urldesc(mDesc); } -const char *kEmptyString = ""; +static const char *kEmptyString = ""; // A string representation of the URI. Setting the spec // causes the new spec to be parsed, initializing the URI. Setting @@ -58,17 +59,16 @@ NS_IMETHODIMP nsLDAPURL::GetSpec(char* *aSpec) { NS_ENSURE_ARG_POINTER(aSpec); - NS_ENSURE_FALSE(mSpec.IsEmpty(), NS_ERROR_NOT_INITIALIZED); // copy it out // *aSpec = mSpec.ToNewCString(); // XXXdmose - presumably this is the right thing. nsString.h doesn't - // document whether there can be a NULL return code. + // document whether there can be a 0 return code. // - if (*aSpec == nsnull) { - return NS_ERROR_OUT_OF_MEMORY; + if ( ! *aSpec ) { + return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; @@ -86,22 +86,22 @@ nsLDAPURL::SetSpec(const char * aSpec) switch (rc) { case LDAP_SUCCESS: - return NS_OK; - break; + return NS_OK; + break; case LDAP_URL_ERR_NOTLDAP: case LDAP_URL_ERR_NODN: case LDAP_URL_ERR_BADSCOPE: - return NS_ERROR_MALFORMED_URI; - break; + return NS_ERROR_MALFORMED_URI; + break; case LDAP_URL_ERR_MEM: - return NS_ERROR_OUT_OF_MEMORY; - break; + return NS_ERROR_OUT_OF_MEMORY; + break; case LDAP_URL_ERR_PARAM: - return NS_ERROR_INVALID_POINTER; - break; + return NS_ERROR_INVALID_POINTER; + break; } // this shouldn't happen @@ -109,7 +109,8 @@ nsLDAPURL::SetSpec(const char * aSpec) return NS_ERROR_UNEXPECTED; } -/* attribute string prePath; */ +// attribute string prePath; +// NS_IMETHODIMP nsLDAPURL::GetPrePath(char * *aPrePath) { return NS_ERROR_NOT_IMPLEMENTED; @@ -119,14 +120,15 @@ NS_IMETHODIMP nsLDAPURL::SetPrePath(const char * aPrePath) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string scheme; */ +// attribute string scheme; +// NS_IMETHODIMP nsLDAPURL::GetScheme(char * *aScheme) { // need to deal with ldaps here too? // char *scheme = nsCRT::strdup("ldap"); - if (scheme == nsnull) { - return NS_ERROR_OUT_OF_MEMORY; + if (!scheme) { + return NS_ERROR_OUT_OF_MEMORY; } *aScheme = scheme; @@ -137,7 +139,8 @@ NS_IMETHODIMP nsLDAPURL::SetScheme(const char * aScheme) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string preHost; */ +// attribute string preHost; +// NS_IMETHODIMP nsLDAPURL::GetPreHost(char * *aPreHost) { @@ -149,7 +152,8 @@ nsLDAPURL::SetPreHost(const char * aPreHost) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string username; */ +// attribute string username +// NS_IMETHODIMP nsLDAPURL::GetUsername(char * *aUsername) { @@ -161,7 +165,8 @@ nsLDAPURL::SetUsername(const char * aUsername) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string password; */ +// attribute string password; +// NS_IMETHODIMP nsLDAPURL::GetPassword(char * *aPassword) { @@ -173,20 +178,23 @@ nsLDAPURL::SetPassword(const char * aPassword) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string host; */ +// attribute string host; +// NS_IMETHODIMP nsLDAPURL::GetHost(char * *aHost) { - NS_ENSURE_FALSE(mDesc == nsnull, NS_ERROR_NOT_INITIALIZED); + NS_ENSURE_TRUE(mDesc, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_ARG_POINTER(aHost); - if ( mDesc->lud_host == nsnull ) { - *aHost = nsCRT::strdup(kEmptyString); - } else - *aHost = nsCRT::strdup(mDesc->lud_host); + if ( ! mDesc->lud_host ) { + *aHost = nsCRT::strdup(kEmptyString); + } else { + *aHost = nsCRT::strdup(mDesc->lud_host); + } - if (*aHost == nsnull) - return NS_ERROR_OUT_OF_MEMORY; + if ( ! *aHost ) { + return NS_ERROR_OUT_OF_MEMORY; + } return NS_OK; } @@ -196,17 +204,19 @@ nsLDAPURL::SetHost(const char * aHost) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute long port; */ +// attribute long port; +// NS_IMETHODIMP nsLDAPURL::GetPort(PRInt32 *aPort) { NS_ENSURE_ARG_POINTER(aPort); - NS_ENSURE_FALSE(mDesc == nsnull, NS_ERROR_NOT_INITIALIZED); + NS_ENSURE_TRUE(mDesc, NS_ERROR_NOT_INITIALIZED); - if ( mDesc->lud_port ) - *aPort = mDesc->lud_port; - else - *aPort = -1; + if ( mDesc->lud_port ) { + *aPort = mDesc->lud_port; + } else { + *aPort = -1; + } return NS_OK; } @@ -216,7 +226,8 @@ nsLDAPURL::SetPort(PRInt32 aPort) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string path; */ +// attribute string path; +// NS_IMETHODIMP nsLDAPURL::GetPath(char * *aPath) { return NS_ERROR_NOT_IMPLEMENTED; @@ -226,13 +237,15 @@ NS_IMETHODIMP nsLDAPURL::SetPath(const char * aPath) return NS_ERROR_NOT_IMPLEMENTED; } -/* boolean equals (in nsIURI other); */ +// boolean equals (in nsIURI other) +// NS_IMETHODIMP nsLDAPURL::Equals(nsIURI *other, PRBool *_retval) { return NS_ERROR_NOT_IMPLEMENTED; } -/* boolean schemeIs(in PRUint32 scheme); */ +// boolean schemeIs(in PRUint32 scheme); +// NS_IMETHODIMP nsLDAPURL::SchemeIs(PRUint32 i_Scheme, PRBool *o_Equals) { *o_Equals = (i_Scheme == nsIURI::LDAP); @@ -240,39 +253,43 @@ NS_IMETHODIMP nsLDAPURL::SchemeIs(PRUint32 i_Scheme, PRBool *o_Equals) return NS_OK; } -/* nsIURI clone (); */ +// nsIURI clone (); +// NS_IMETHODIMP nsLDAPURL::Clone(nsIURI **_retval) { return NS_ERROR_NOT_IMPLEMENTED; } -/* string resolve (in string relativePath); */ +// string resolve (in string relativePath); +// NS_IMETHODIMP nsLDAPURL::Resolve(const char *relativePath, char **_retval) { return NS_ERROR_NOT_IMPLEMENTED; } -/* the following attributes come from nsILDAPURL */ +// the following attributes come from nsILDAPURL -/* attribute string dn; */ +// attribute string dn; +// NS_IMETHODIMP nsLDAPURL::GetDn(char * *aDn) { if (!aDn) { - return NS_ERROR_ILLEGAL_VALUE; + return NS_ERROR_ILLEGAL_VALUE; } if (!mDesc) { - return NS_ERROR_NOT_INITIALIZED; + return NS_ERROR_NOT_INITIALIZED; } - if ( mDesc->lud_dn == NULL ) { - *aDn = nsCRT::strdup(kEmptyString); + if ( mDesc->lud_dn == 0 ) { + *aDn = nsCRT::strdup(kEmptyString); } else { - *aDn = nsCRT::strdup(mDesc->lud_dn); + *aDn = nsCRT::strdup(mDesc->lud_dn); } - if ( *aDn == nsnull ) - return NS_ERROR_OUT_OF_MEMORY; + if ( ! *aDn ) { + return NS_ERROR_OUT_OF_MEMORY; + } return NS_OK; } @@ -281,17 +298,20 @@ NS_IMETHODIMP nsLDAPURL::SetDn(const char * aDn) return NS_ERROR_NOT_IMPLEMENTED; } -/* void getAttributes (out unsigned long count, [array, size_is (count), retval] out string values); */ +// void getAttributes (out unsigned long count, +// [array, size_is (count), retval] out string values); +// NS_IMETHODIMP nsLDAPURL::GetAttributes(PRUint32 *count, char ***values) { return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute long scope; */ +// attribute long scope; +// NS_IMETHODIMP nsLDAPURL::GetScope(PRInt32 *aScope) { NS_ENSURE_ARG_POINTER(aScope); - NS_ENSURE_FALSE(mDesc == nsnull, NS_ERROR_NOT_INITIALIZED); + NS_ENSURE_TRUE(mDesc, NS_ERROR_NOT_INITIALIZED); *aScope = mDesc->lud_scope; @@ -302,22 +322,25 @@ NS_IMETHODIMP nsLDAPURL::SetScope(PRInt32 aScope) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute string filter; */ +// attribute string filter; +// NS_IMETHODIMP nsLDAPURL::GetFilter(char * *aFilter) { NS_ENSURE_ARG_POINTER(aFilter); - NS_ENSURE_FALSE(mDesc == nsnull, NS_ERROR_NOT_INITIALIZED); + NS_ENSURE_TRUE(mDesc, NS_ERROR_NOT_INITIALIZED); // if these aren't set, insert the defaults. // - if ((mDesc->lud_filter == NULL) || (nsCRT::strlen(mDesc->lud_filter) == 0)) - *aFilter = nsCRT::strdup("objectClass=*"); - else - *aFilter = nsCRT::strdup(mDesc->lud_filter); + if ( ! (mDesc->lud_filter && mDesc->lud_filter[0] ) ) { + *aFilter = nsCRT::strdup("objectClass=*"); + } else { + *aFilter = nsCRT::strdup(mDesc->lud_filter); + } + + if ( ! *aFilter ) { + return NS_ERROR_OUT_OF_MEMORY; + } - if (*aFilter == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; } NS_IMETHODIMP nsLDAPURL::SetFilter(const char * aFilter) @@ -325,7 +348,8 @@ NS_IMETHODIMP nsLDAPURL::SetFilter(const char * aFilter) return NS_ERROR_NOT_IMPLEMENTED; } -/* attribute unsigned long options; */ +// attribute unsigned long options; +// NS_IMETHODIMP nsLDAPURL::GetOptions(PRUint32 *aOptions) { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/mozilla/directory/xpcom/base/src/nsLDAPURL.h b/mozilla/directory/xpcom/base/src/nsLDAPURL.h index f254667a8ca..f8383610caf 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPURL.h +++ b/mozilla/directory/xpcom/base/src/nsLDAPURL.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -9,7 +10,7 @@ * implied. See the License for the specific language governing * rights and limitations under the License. * - * The Original Code is the mozilla.org LDAP XPCOM component. + * The Original Code is the mozilla.org LDAP XPCOM SDK. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are @@ -31,12 +32,6 @@ * GPL. */ -// so g++ doesn't whine about one of the files included by ldap.h -// -#ifdef linux -#define __STRICT_ANSI__ -#endif - #include "nsLDAP.h" #include "ldap.h" #include "nsILDAPURL.h" @@ -58,6 +53,6 @@ class nsLDAPURL : public nsILDAPURL virtual ~nsLDAPURL(); protected: - LDAPURLDesc *mDesc; // the URL descriptor we're wrapping - nsCString mSpec; // string representation + LDAPURLDesc *mDesc; // the URL descriptor we're wrapping + nsCString mSpec; // string representation }; diff --git a/mozilla/directory/xpcom/datasource/Makefile.in b/mozilla/directory/xpcom/datasource/Makefile.in index 39c67c66e9c..bda8e408113 100644 --- a/mozilla/directory/xpcom/datasource/Makefile.in +++ b/mozilla/directory/xpcom/datasource/Makefile.in @@ -9,7 +9,7 @@ # implied. See the License for the specific language governing # rights and limitations under the License. # -# The Original Code is the mozilla.org LDAP RDF datasource +# The Original Code is the mozilla.org LDAP XPCOM SDK. # # The Initial Developer of the Original Code is Netscape # Communications Corporation. Portions created by Netscape are diff --git a/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js b/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js index d16940b426d..b551136f81f 100644 --- a/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js +++ b/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js @@ -1,4 +1,5 @@ /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -49,14 +50,6 @@ const NS_RDF_NO_VALUE = NS_ERROR_RDF_BASE + 2; const NS_RDF_ASSERTION_ACCEPTED = Components.results.NS_OK; const NS_RDF_ASSERTION_REJECTED = NS_ERROR_RDF_BASE + 3; -// some stuff from ldap.h -// -const LDAP_RES_BIND = 0x61; -const LDAP_RES_SEARCH_ENTRY = 0x64; -const LDAP_RES_SEARCH_RESULT = 0x65; - -const NS_LDAP_SCOPE_BASE = 0; - // ArrayEnumerator courtesy of Brendan Eich // function ArrayEnumerator(array) { @@ -816,7 +809,7 @@ nsLDAPMessageRDFDelegateFactory.prototype = // XXX how do we deal with this in release builds? // XXX deal with already bound case // - if (aMessage.type != LDAP_RES_BIND) { + if (aMessage.type != aMessage.RES_BIND) { dump("bind failed\n"); } @@ -859,7 +852,7 @@ nsLDAPMessageRDFDelegateFactory.prototype = var listHash; - if (aMessage.type == LDAP_RES_SEARCH_ENTRY) { + if (aMessage.type == aMessage.RES_SEARCH_ENTRY) { if (DEBUG) { dump("getTargetsSearchCallback() called with " + "message " + aMessage.dn + " for " + @@ -926,7 +919,7 @@ nsLDAPMessageRDFDelegateFactory.prototype = } } } - else if (aMessage.type == LDAP_RES_SEARCH_RESULT) { + else if (aMessage.type == aMessage.RES_SEARCH_RESULT) { listHash = this.callerObject.mMessagesListHash; if (listHash.hasOwnProperty(this.outer.Value) && (listHash[this.outer.Value].Count() == 1) @@ -987,7 +980,7 @@ nsLDAPMessageRDFDelegateFactory.prototype = // make sure that this if this URL is for a messagelist, it // represents something other than a base search // - if ((aKey == "messagelist.ldap") && (url.scope == NS_LDAP_SCOPE_BASE)) { + if ((aKey == "messagelist.ldap") && (url.scope == url.SCOPE_BASE)) { throw Components.results.NS_ERROR_FAILURE; } diff --git a/mozilla/directory/xpcom/macbuild/mozldapIDL.mcp b/mozilla/directory/xpcom/macbuild/mozldapIDL.mcp index 68ffd4847ce..e8dbd04f9e0 100644 Binary files a/mozilla/directory/xpcom/macbuild/mozldapIDL.mcp and b/mozilla/directory/xpcom/macbuild/mozldapIDL.mcp differ diff --git a/mozilla/directory/xpcom/tests/example.xul b/mozilla/directory/xpcom/tests/example.xul index 6daa8546826..c5169d2e82f 100644 --- a/mozilla/directory/xpcom/tests/example.xul +++ b/mozilla/directory/xpcom/tests/example.xul @@ -5,7 +5,8 @@ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + flex="2" id="testTree" + ref="ldap://alpha.dante.org.uk:389/dc=dante,dc=org,dc=uk??sub?drink=*"> - - + + - - + +