From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- comm/mailnews/addrbook/modules/LDAPConnection.jsm | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 comm/mailnews/addrbook/modules/LDAPConnection.jsm (limited to 'comm/mailnews/addrbook/modules/LDAPConnection.jsm') diff --git a/comm/mailnews/addrbook/modules/LDAPConnection.jsm b/comm/mailnews/addrbook/modules/LDAPConnection.jsm new file mode 100644 index 0000000000..f9a66f47a7 --- /dev/null +++ b/comm/mailnews/addrbook/modules/LDAPConnection.jsm @@ -0,0 +1,53 @@ +/* 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/. */ + +const EXPORTED_SYMBOLS = ["LDAPConnection"]; + +const lazy = {}; + +ChromeUtils.defineModuleGetter( + lazy, + "LDAPClient", + "resource:///modules/LDAPClient.jsm" +); + +/** + * A module to manage LDAP connection. + * + * @implements {nsILDAPConnection} + */ +class LDAPConnection { + QueryInterface = ChromeUtils.generateQI(["nsILDAPConnection"]); + + get bindName() { + return this._bindName; + } + + init(url, bindName, listener, closure, version) { + let useSecureTransport = url.scheme == "ldaps"; + let port = url.port; + if (port == -1) { + // -1 corresponds to the protocol's default port. + port = useSecureTransport ? 636 : 389; + } + this.client = new lazy.LDAPClient(url.host, port, useSecureTransport); + this._url = url; + this._bindName = bindName; + this.client.onOpen = () => { + listener.onLDAPInit(); + }; + this.client.onError = (status, secInfo) => { + listener.onLDAPError(status, secInfo, `${url.host}:${port}`); + }; + this.client.connect(); + } + + get wrappedJSObject() { + return this; + } +} + +LDAPConnection.prototype.classID = Components.ID( + "{f87b71b5-2a0f-4b37-8e4f-3c899f6b8432}" +); -- cgit v1.2.3