summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/addrbook/modules/LDAPConnection.jsm
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mailnews/addrbook/modules/LDAPConnection.jsm')
-rw-r--r--comm/mailnews/addrbook/modules/LDAPConnection.jsm53
1 files changed, 53 insertions, 0 deletions
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}"
+);