зеркало из https://github.com/mozilla/gecko-dev.git
created an nsILDAPConnection interface, and set up nsLDAPConnection to implement it so that we can use XPCOM proxies for cross-thread marshalling, and so we get JS access as well
This commit is contained in:
Родитель
cb59429f00
Коммит
6b38a9662c
|
@ -1,5 +1,10 @@
|
|||
implementation
|
||||
--------------
|
||||
|
||||
* finish XPCOMifying nsLDAP{Message,Connection,Operation} in order to allow
|
||||
XPCOM proxies to be used for thread-crossing operations (side benefit: also
|
||||
exposes more LDAPy goodness to JS) (in progres: dmose)
|
||||
|
||||
* make AsyncRead actually be asynchronous (and probably cause ldapSearch.cpp
|
||||
to be split and moved) by factoring out the lowlevel stuff into another
|
||||
thread (in progress: dmose)
|
||||
|
@ -17,6 +22,13 @@ housecleaning
|
|||
|
||||
* implement nsLDAPChannel::Cancel()
|
||||
|
||||
* should nsILDAPOperation subclass nsIRequest? why do some
|
||||
non-nsIChannel things in the mozilla code base implement nsIRequest?
|
||||
|
||||
* implement shutdown for nsLDAPService (probably analogous to the way
|
||||
nsSocketTransportService shuts down. but how does
|
||||
nsIShutdownListener fit in here? and CanUnload?)
|
||||
|
||||
* get rid of unixy, non-NSPR/XPCOM includes, functions, and error handling
|
||||
from nsLDAP{Connection,Operation,Message}.[ch]
|
||||
|
||||
|
@ -68,9 +80,6 @@ housecleaning
|
|||
features
|
||||
--------
|
||||
|
||||
* finish XPCOMifying nsLDAP{Message,Connection,Operation} (allowing
|
||||
for use from JS)
|
||||
|
||||
* i18n / l10n
|
||||
|
||||
* use a rebind_proc?
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
nsILDAPURI.idl
|
||||
nsILDAPConnection.idl
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ include $(DEPTH)/config/autoconf.mk
|
|||
MODULE = mozldap
|
||||
XPIDL_MODULE = mozldap
|
||||
|
||||
XPIDLSRCS = nsILDAPURI.idl \
|
||||
XPIDLSRCS = nsILDAPConnection.idl \
|
||||
nsILDAPURI.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 component.
|
||||
*
|
||||
* 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 <dmose@mozilla.org>
|
||||
*
|
||||
* 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"
|
||||
|
||||
[scriptable, uuid(337ad2fe-1dd2-11b2-89f8-aae1221ec86c)]
|
||||
interface nsILDAPConnection : nsISupports
|
||||
{
|
||||
// return the string version of lderrno
|
||||
readonly attribute string errorString;
|
||||
|
||||
// wrapper for ldap_init()
|
||||
void Init(in string defhost, in short defport);
|
||||
|
||||
// wrapper for ldap_get_lderrno()
|
||||
short GetLdErrno(out string matched, out string s);
|
||||
};
|
||||
|
|
@ -50,8 +50,8 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
// struct timeval timeout = {10,0};
|
||||
int returnCode;
|
||||
char *errString;
|
||||
// url = "ldap://memberdir.netscape.com:389/ou=member_directory,
|
||||
// o=netcenter.com??sub?(sn=Mosedale)"
|
||||
PRInt16 lden;
|
||||
|
||||
myConnection = new nsLDAPConnection();
|
||||
if ( !myConnection->Init("nsdirectory.netscape.com", LDAP_PORT) ) {
|
||||
fprintf(stderr, "main: nsLDAPConnection::Init failed\n");
|
||||
|
@ -65,8 +65,8 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
fflush(stderr);
|
||||
|
||||
if ( !myOperation->SimpleBind(NULL, NULL) ) {
|
||||
char *errstring = myConnection->GetErrorString();
|
||||
fprintf(stderr, "ldap_simple_bind: %s\n", errstring);
|
||||
(void)myConnection->GetErrorString(&errString);
|
||||
fprintf(stderr, "ldap_simple_bind: %s\n", errString);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
// success
|
||||
break;
|
||||
case -1:
|
||||
errString = myConnection->GetErrorString();
|
||||
(void)myConnection->GetErrorString(&errString);
|
||||
fprintf(stderr,
|
||||
"myOperation->Result() [myOperation->SimpleBind]: %s: errno=%d\n",
|
||||
errString, errno);
|
||||
|
@ -137,7 +137,7 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
|
||||
switch (returnCode) {
|
||||
case -1: // something went wrong
|
||||
errString = myConnection->GetErrorString();
|
||||
(void)myConnection->GetErrorString(&errString);
|
||||
fprintf(stderr,
|
||||
"\nmyOperation->Result() [URLSearch]: %s: errno=%d\n",
|
||||
errString, errno);
|
||||
|
@ -152,8 +152,9 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
// get the DN
|
||||
dn = myMessage->GetDN();
|
||||
if (!dn) {
|
||||
fprintf(stderr, "myMessage->GetDN(): %s\n",
|
||||
myConnection->GetErrorString());
|
||||
(void)myConnection->GetErrorString(&errString);
|
||||
fprintf(stderr, "myMessage->GetDN(): %s\n", errString);
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
chan->pipeWrite("dn: ");
|
||||
|
@ -173,8 +174,9 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
// get the values of this attribute
|
||||
vals = myMessage->GetValues(attr);
|
||||
if (vals == NULL) {
|
||||
fprintf(stderr, "myMessage->GetValues: %s\n",
|
||||
myConnection->GetErrorString());
|
||||
(void)myConnection->GetErrorString(&errString);
|
||||
fprintf(stderr, "myMessage->GetValues: %s\n", errString);
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -191,9 +193,13 @@ lds(class nsLDAPChannel *chan, const char *url)
|
|||
}
|
||||
|
||||
// did we reach this statement because of an error?
|
||||
if ( myConnection->GetLdErrno(NULL, NULL) != LDAP_SUCCESS ) {
|
||||
(void)myConnection->GetLdErrno(NULL, NULL, &lden);
|
||||
if ( lden != LDAP_SUCCESS ) {
|
||||
|
||||
(void)myConnection->GetErrorString(&errString);
|
||||
fprintf(stderr, "myMessage: error getting attribute: %s\n",
|
||||
myConnection->GetErrorString());
|
||||
errString);
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,10 +34,13 @@
|
|||
#include <stdio.h>
|
||||
#include "nsLDAPConnection.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsLDAPConnection, nsILDAPConnection);
|
||||
|
||||
// constructor
|
||||
//
|
||||
nsLDAPConnection::nsLDAPConnection()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
@ -56,19 +59,21 @@ nsLDAPConnection::~nsLDAPConnection()
|
|||
|
||||
// wrapper for ldap_init()
|
||||
//
|
||||
bool
|
||||
nsLDAPConnection::Init(const char *defhost, const int defport)
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::Init(const char *defhost, PRInt16 defport)
|
||||
{
|
||||
this->connectionHandle = ldap_init(defhost, defport);
|
||||
return (this->connectionHandle == NULL ? false : true);
|
||||
return (this->connectionHandle == NULL ? NS_ERROR_FAILURE : NS_OK);
|
||||
}
|
||||
|
||||
// wrapper for ldap_get_lderrno
|
||||
//
|
||||
int
|
||||
nsLDAPConnection::GetLdErrno(char **matched, char **string)
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::GetLdErrno(char **matched, char **errString,
|
||||
PRInt16 *_retval)
|
||||
{
|
||||
return ldap_get_lderrno(this->connectionHandle, matched, string);
|
||||
*_retval = ldap_get_lderrno(this->connectionHandle, matched, errString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// return the error string corresponding to GetLdErrno.
|
||||
|
@ -76,8 +81,10 @@ nsLDAPConnection::GetLdErrno(char **matched, char **string)
|
|||
//
|
||||
// XXX - deal with optional params
|
||||
// XXX - how does ldap_perror know to look at the global errno?
|
||||
char *
|
||||
nsLDAPConnection::GetErrorString(void)
|
||||
NS_IMETHODIMP
|
||||
nsLDAPConnection::GetErrorString(char **_retval)
|
||||
{
|
||||
return ldap_err2string(this->GetLdErrno(NULL, NULL));
|
||||
*_retval = ldap_err2string(ldap_get_lderrno(this->connectionHandle,
|
||||
NULL, NULL));
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -34,29 +34,22 @@
|
|||
#ifndef _nsLDAPConnection_h_
|
||||
#define _nsLDAPConnection_h_
|
||||
|
||||
#include "nsILDAPConnection.h"
|
||||
#include "ldap.h"
|
||||
|
||||
class nsLDAPConnection {
|
||||
class nsLDAPConnection : public nsILDAPConnection {
|
||||
|
||||
friend class nsLDAPOperation;
|
||||
friend class nsLDAPMessage;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS;
|
||||
NS_DECL_NSILDAPCONNECTION;
|
||||
|
||||
// constructor
|
||||
// constructor & destructor
|
||||
//
|
||||
nsLDAPConnection();
|
||||
|
||||
// destructor
|
||||
~nsLDAPConnection();
|
||||
|
||||
// wrapper for ldap_init()
|
||||
bool Init(const char *defhost, const int defport);
|
||||
|
||||
// wrapper for ldap_get_lderrno()
|
||||
int GetLdErrno(char **matched, char **string);
|
||||
|
||||
// construct the string version of GetLdErrno
|
||||
char *GetErrorString(void);
|
||||
virtual ~nsLDAPConnection();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче