summaryrefslogtreecommitdiffstats
path: root/ldap/xpcom/src/nsLDAPModification.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-03 00:17:46 -0400
committerMatt A. Tobin <email@mattatobin.com>2019-11-03 00:17:46 -0400
commit302bf1b523012e11b60425d6eee1221ebc2724eb (patch)
treeb191a895f8716efcbe42f454f37597a545a6f421 /ldap/xpcom/src/nsLDAPModification.cpp
parent21b3f6247403c06f85e1f45d219f87549862198f (diff)
downloadUXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.gz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.lz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.tar.xz
UXP-302bf1b523012e11b60425d6eee1221ebc2724eb.zip
Issue #1258 - Part 1: Import mailnews, ldap, and mork from comm-esr52.9.1
Diffstat (limited to 'ldap/xpcom/src/nsLDAPModification.cpp')
-rw-r--r--ldap/xpcom/src/nsLDAPModification.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/ldap/xpcom/src/nsLDAPModification.cpp b/ldap/xpcom/src/nsLDAPModification.cpp
new file mode 100644
index 000000000..77253835a
--- /dev/null
+++ b/ldap/xpcom/src/nsLDAPModification.cpp
@@ -0,0 +1,158 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "nsLDAPModification.h"
+#include "nsILDAPBERValue.h"
+#include "nsISimpleEnumerator.h"
+#include "nsServiceManagerUtils.h"
+#include "nsComponentManagerUtils.h"
+
+using namespace mozilla;
+
+NS_IMPL_ISUPPORTS(nsLDAPModification, nsILDAPModification)
+
+// constructor
+//
+nsLDAPModification::nsLDAPModification()
+ : mValuesLock("nsLDAPModification.mValuesLock")
+{
+}
+
+// destructor
+//
+nsLDAPModification::~nsLDAPModification()
+{
+}
+
+nsresult
+nsLDAPModification::Init()
+{
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::GetOperation(int32_t *aOperation)
+{
+ NS_ENSURE_ARG_POINTER(aOperation);
+
+ *aOperation = mOperation;
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsLDAPModification::SetOperation(int32_t aOperation)
+{
+ mOperation = aOperation;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::GetType(nsACString& aType)
+{
+ aType.Assign(mType);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::SetType(const nsACString& aType)
+{
+ mType.Assign(aType);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::GetValues(nsIArray** aResult)
+{
+ NS_ENSURE_ARG_POINTER(aResult);
+
+ MutexAutoLock lock(mValuesLock);
+
+ if (!mValues)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ NS_ADDREF(*aResult = mValues);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::SetValues(nsIArray* aValues)
+{
+ NS_ENSURE_ARG_POINTER(aValues);
+
+ MutexAutoLock lock(mValuesLock);
+ nsresult rv;
+
+ if (!mValues)
+ mValues = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+ else
+ rv = mValues->Clear();
+
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ nsCOMPtr<nsISimpleEnumerator> enumerator;
+ rv = aValues->Enumerate(getter_AddRefs(enumerator));
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ bool hasMoreElements;
+ rv = enumerator->HasMoreElements(&hasMoreElements);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ nsCOMPtr<nsISupports> value;
+
+ while (hasMoreElements)
+ {
+ rv = enumerator->GetNext(getter_AddRefs(value));
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ rv = mValues->AppendElement(value, false);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ rv = enumerator->HasMoreElements(&hasMoreElements);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::SetUpModification(int32_t aOperation,
+ const nsACString &aType,
+ nsIArray *aValues)
+{
+ // Set the values using our local function before entering lock
+ // to avoid deadlocks due to holding the same lock twice.
+ nsresult rv = SetValues(aValues);
+
+ MutexAutoLock lock(mValuesLock);
+
+ mOperation = aOperation;
+ mType.Assign(aType);
+
+ return rv;
+}
+
+NS_IMETHODIMP
+nsLDAPModification::SetUpModificationOneValue(int32_t aOperation,
+ const nsACString &aType,
+ nsILDAPBERValue *aValue)
+{
+ NS_ENSURE_ARG_POINTER(aValue);
+
+ MutexAutoLock lock(mValuesLock);
+
+ mOperation = aOperation;
+ mType.Assign(aType);
+
+ nsresult rv;
+
+ if (!mValues)
+ mValues = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+ else
+ rv = mValues->Clear();
+
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ return mValues->AppendElement(aValue, false);
+}