/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

interface nsILDAPOperation;
interface nsILDAPMessageListener;
interface nsILDAPURL;

%{C++
#define NS_LDAPCONNECTION_CONTRACTID "@mozilla.org/network/ldap-connection;1" 
%}

[scriptable, uuid(360c1ff7-15e3-4ffe-b4b8-0eda72ebc096)]
interface nsILDAPConnection : nsISupports
{
    /**
     * the string version of lderrno
     */
    readonly attribute wstring errorString;

    /**
     * DN to bind as.  use the init() method to set this.
     *
     * @exception NS_ERROR_OUT_OF_MEMORY
     */
    readonly attribute AUTF8String bindName;
    
    /**
     * private parameter (anything caller desires)
     */
    attribute nsISupports closure;

    /** 
     * Set up the connection.  Note that init() must be called on a thread
     * that already has an nsIEventQueue.
     *
     * @param aUrl              A URL for the ldap server. The host, port and
     *                          ssl connection type will be extracted from this
     * @param aBindName         DN to bind as
     * @param aMessageListener  Callback for DNS resolution completion
     * @param aClosure          private parameter (anything caller desires)
     * @param aVersion          LDAP version to use (currently VERSION2 or 
     *                          VERSION3)
     *
     * @exception NS_ERROR_ILLEGAL_VALUE        null pointer or invalid version
     * @exception NS_ERROR_OUT_OF_MEMORY        ran out of memory
     * @exception NS_ERROR_OFFLINE              we are in off-line mode
     * @exception NS_ERROR_FAILURE              
     * @exception NS_ERROR_UNEXPECTED           internal error
     */
    void init(in nsILDAPURL aUrl,
              in AUTF8String aBindName,
              in nsILDAPMessageListener aMessageListener,
              in nsISupports aClosure, in unsigned long aVersion);

    const unsigned long VERSION2 = 2;
    const unsigned long VERSION3 = 3;

    /**
     * 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 AUTF8String matched, out AUTF8String s);
};
