Back to index

lightning-sunbird  0.9+nobinonly
nsLDAPProtocolModule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * 
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the mozilla.org LDAP XPCOM SDK.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2000
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Dan Mosedale <dmose@mozilla.org>
00025  *   Leif Hedstrom <leif@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "nsLDAPInternal.h"
00042 #include "nsLDAPURL.h"
00043 #include "nsIGenericFactory.h"
00044 #include "nsLDAPConnection.h"
00045 #include "nsLDAPOperation.h"
00046 #include "nsLDAPMessage.h"
00047 #include "nsLDAPServer.h"
00048 #include "nsLDAPService.h"
00049 #include "nsLDAPBERValue.h"
00050 #include "nsLDAPBERElement.h"
00051 #include "nsLDAPControl.h"
00052 
00053 #include "ldappr.h"
00054 
00055 #ifdef MOZ_LDAP_XPCOM_EXPERIMENTAL
00056 #include "nsLDAPProtocolHandler.h"
00057 #include "nsLDAPChannel.h"
00058 #endif
00059 
00060 // use the default constructor
00061 //
00062 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPConnection)
00063 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPOperation)
00064 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPMessage)
00065 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPServer)
00066 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsLDAPURL, Init)
00067 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsLDAPService, Init)
00068 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPBERValue)
00069 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPBERElement)
00070 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPControl)
00071 
00072 #ifdef MOZ_LDAP_XPCOM_EXPERIMENTAL
00073 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPProtocolHandler)
00074 #endif
00075 
00076 NS_DECL_CLASSINFO(nsLDAPMessage)
00077 NS_DECL_CLASSINFO(nsLDAPOperation)
00078 NS_DECL_CLASSINFO(nsLDAPConnection)
00079 
00080 // a table of the CIDs implemented by this module
00081 //
00082 static const nsModuleComponentInfo components[] =
00083 {
00084     { "LDAP Connection", NS_LDAPCONNECTION_CID,
00085       "@mozilla.org/network/ldap-connection;1", nsLDAPConnectionConstructor,
00086       nsnull, // no registration callback
00087       nsnull, // no unregistration callback
00088       nsnull, // no destruction callback
00089       NS_CI_INTERFACE_GETTER_NAME(nsLDAPConnection),
00090       nsnull, // no language helper
00091       &NS_CLASSINFO_NAME(nsLDAPConnection),
00092       nsIClassInfo::THREADSAFE},
00093     { "LDAP Operation", NS_LDAPOPERATION_CID,
00094       "@mozilla.org/network/ldap-operation;1", nsLDAPOperationConstructor,
00095       nsnull, // no registration callback
00096       nsnull, // no unregistration callback
00097       nsnull, // no destruction callback
00098       NS_CI_INTERFACE_GETTER_NAME(nsLDAPOperation),
00099       nsnull, // no language helper
00100       &NS_CLASSINFO_NAME(nsLDAPOperation),
00101       nsIClassInfo::THREADSAFE},
00102     { "LDAP Message", NS_LDAPMESSAGE_CID,
00103       "@mozilla.org/network/ldap-message;1", nsLDAPMessageConstructor,
00104       nsnull, // no registration callback
00105       nsnull, // no unregistration callback
00106       nsnull, // no destruction callback
00107       NS_CI_INTERFACE_GETTER_NAME(nsLDAPMessage),
00108       nsnull, // no language helper
00109       &NS_CLASSINFO_NAME(nsLDAPMessage),
00110       nsIClassInfo::THREADSAFE },
00111     { "LDAP Server", NS_LDAPSERVER_CID,
00112           "@mozilla.org/network/ldap-server;1", nsLDAPServerConstructor },
00113     { "LDAP Service", NS_LDAPSERVICE_CID,
00114           "@mozilla.org/network/ldap-service;1", nsLDAPServiceConstructor },
00115 #ifdef MOZ_LDAP_XPCOM_EXPERIMENTAL    
00116     { "LDAP Protocol Handler", NS_LDAPPROTOCOLHANDLER_CID, 
00117           NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "ldap", 
00118           nsLDAPProtocolHandlerConstructor },   
00119 #endif
00120     { "LDAP URL", NS_LDAPURL_CID,
00121           "@mozilla.org/network/ldap-url;1", nsLDAPURLConstructor },
00122     { "LDAP BER Value", NS_LDAPBERVALUE_CID,
00123       "@mozilla.org/network/ldap-ber-value;1", nsLDAPBERValueConstructor },
00124     { "LDAP BER Element", NS_LDAPBERELEMENT_CID,
00125       "@mozilla.org/network/ldap-ber-element;1", nsLDAPBERElementConstructor },
00126     { "LDAP Control", NS_LDAPCONTROL_CID,
00127       "@mozilla.org/network/ldap-control;1", nsLDAPControlConstructor}
00128 };
00129 
00130 PR_STATIC_CALLBACK(nsresult)
00131 nsLDAPInitialize(nsIModule *aSelf)
00132 {
00133 #ifdef PR_LOGGING
00134     gLDAPLogModule = PR_NewLogModule("ldap");
00135     if (!gLDAPLogModule) {
00136         PR_fprintf(PR_STDERR, 
00137                    "nsLDAP_Initialize(): PR_NewLogModule() failed\n");
00138         return NS_ERROR_NOT_AVAILABLE;
00139     }
00140 #endif
00141 
00142     // use NSPR under the hood for all networking
00143     //
00144     int rv = prldap_install_routines( NULL, 1 /* shared */ );
00145 
00146     if (rv != LDAP_SUCCESS) {
00147         PR_LOG(gLDAPLogModule, PR_LOG_ERROR,
00148                ("nsLDAPInitialize(): pr_ldap_install_routines() failed: %s\n",
00149                ldap_err2string(rv)));
00150         return NS_ERROR_FAILURE;
00151     }
00152 
00153     // Never block for more than 10000 milliseconds (ie 10 seconds) doing any 
00154     // sort of I/O operation.
00155     //
00156     rv = prldap_set_session_option(0, 0, PRLDAP_OPT_IO_MAX_TIMEOUT, 
00157                                    10000);
00158     if (rv != LDAP_SUCCESS) {
00159         PR_LOG(gLDAPLogModule, PR_LOG_ERROR,
00160                ("nsLDAPInitialize(): error setting PRLDAP_OPT_IO_MAX_TIMEOUT:"
00161                 " %s\n", ldap_err2string(rv)));
00162         return NS_ERROR_FAILURE;
00163     }
00164 
00165     return NS_OK;
00166 }
00167 
00168 // implement the NSGetModule() exported function
00169 //
00170 NS_IMPL_NSGETMODULE_WITH_CTOR(nsLDAPProtocolModule, components, 
00171                               nsLDAPInitialize)
00172 
00173 #ifdef PR_LOGGING
00174 PRLogModuleInfo *gLDAPLogModule = 0;
00175 #endif