Back to index

lightning-sunbird  0.9+nobinonly
nsLDAPServer.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 component.
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  *   Leif Hedstrom <leif@netscape.com>
00025  *   Dan Mosedale <dmose@mozilla.org>
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 "nsLDAPServer.h"
00042 #include "nsReadableUtils.h"
00043 
00044 NS_IMPL_THREADSAFE_ISUPPORTS1(nsLDAPServer, nsILDAPServer)
00045 
00046 nsLDAPServer::nsLDAPServer()
00047     : mSizeLimit(0),
00048       mProtocolVersion(nsILDAPConnection::VERSION3)
00049 {
00050 }
00051 
00052 nsLDAPServer::~nsLDAPServer()
00053 {
00054 }
00055 
00056 // attribute wstring key;
00057 NS_IMETHODIMP nsLDAPServer::GetKey(PRUnichar **_retval)
00058 {
00059     if (!_retval) {
00060         NS_ERROR("nsLDAPServer::GetKey: null pointer ");
00061         return NS_ERROR_NULL_POINTER;
00062     }
00063 
00064     *_retval = ToNewUnicode(mKey);
00065     if (!*_retval) {
00066         return NS_ERROR_OUT_OF_MEMORY;
00067     }
00068 
00069     return NS_OK;
00070 }
00071 NS_IMETHODIMP nsLDAPServer::SetKey(const PRUnichar *aKey)
00072 {
00073     mKey = aKey;
00074     return NS_OK;
00075 }
00076 
00077 // attribute AUTF8String username;
00078 NS_IMETHODIMP nsLDAPServer::GetUsername(nsACString& _retval)
00079 {
00080     _retval.Assign(mUsername);
00081     return NS_OK;
00082 }
00083 NS_IMETHODIMP nsLDAPServer::SetUsername(const nsACString& aUsername)
00084 {
00085     mUsername.Assign(aUsername);
00086     return NS_OK;
00087 }
00088 
00089 // attribute AUTF8String password;
00090 NS_IMETHODIMP nsLDAPServer::GetPassword(nsACString& _retval)
00091 {
00092     _retval.Assign(mPassword);
00093     return NS_OK;
00094 }
00095 NS_IMETHODIMP nsLDAPServer::SetPassword(const nsACString& aPassword)
00096 {
00097     mPassword.Assign(aPassword);
00098     return NS_OK;
00099 }
00100 
00101 // attribute AUTF8String binddn;
00102 NS_IMETHODIMP nsLDAPServer::GetBinddn(nsACString& _retval)
00103 {
00104     _retval.Assign(mBindDN);
00105     return NS_OK;
00106 }
00107 NS_IMETHODIMP nsLDAPServer::SetBinddn(const nsACString& aBindDN)
00108 {
00109     mBindDN.Assign(aBindDN);
00110     return NS_OK;
00111 }
00112 
00113 // attribute unsigned long sizelimit;
00114 NS_IMETHODIMP nsLDAPServer::GetSizelimit(PRUint32 *_retval)
00115 {
00116     if (!_retval) {
00117         NS_ERROR("nsLDAPServer::GetSizelimit: null pointer ");
00118         return NS_ERROR_NULL_POINTER;
00119     }
00120 
00121     *_retval = mSizeLimit;
00122     return NS_OK;
00123 }
00124 NS_IMETHODIMP nsLDAPServer::SetSizelimit(PRUint32 aSizeLimit)
00125 {
00126     mSizeLimit = aSizeLimit;
00127     return NS_OK;
00128 }
00129 
00130 // attribute nsILDAPURL url;
00131 NS_IMETHODIMP nsLDAPServer::GetUrl(nsILDAPURL **_retval)
00132 {
00133     if (!_retval) {
00134         NS_ERROR("nsLDAPServer::GetUrl: null pointer ");
00135         return NS_ERROR_NULL_POINTER;
00136     }
00137 
00138     NS_IF_ADDREF(*_retval = mURL);
00139     return NS_OK;
00140 }
00141 NS_IMETHODIMP nsLDAPServer::SetUrl(nsILDAPURL *aURL)
00142 {
00143     mURL = aURL;
00144     return NS_OK;
00145 }
00146 
00147 // attribute long protocolVersion
00148 NS_IMETHODIMP nsLDAPServer::GetProtocolVersion(PRUint32 *_retval)
00149 {
00150     if (!_retval) {
00151         NS_ERROR("nsLDAPServer::GetProtocolVersion: null pointer ");
00152         return NS_ERROR_NULL_POINTER;
00153     }
00154 
00155     *_retval = mProtocolVersion;
00156     return NS_OK;
00157 }
00158 NS_IMETHODIMP nsLDAPServer::SetProtocolVersion(PRUint32 aVersion)
00159 {
00160     if (aVersion != nsILDAPConnection::VERSION2 &&
00161         aVersion != nsILDAPConnection::VERSION3) {
00162         NS_ERROR("nsLDAPServer::SetProtocolVersion: invalid version");
00163         return NS_ERROR_INVALID_ARG;
00164     }
00165 
00166     mProtocolVersion = aVersion;
00167     return NS_OK;
00168 }