Bug 1501589 - Port
bug 1501404 (part 6): Replace use of NS_STARTTLSSOCKETPROVIDER_CONTRACTID. r=jorgk
--- a/ldap/xpcom/src/nsLDAPSecurityGlue.cpp
+++ b/ldap/xpcom/src/nsLDAPSecurityGlue.cpp
@@ -3,27 +3,31 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Only build this code if PSM is being built also
//
#include "nsLDAPInternal.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestor.h"
-#include "nsNetCID.h"
+#include "nsISocketProviderService.h"
+#include "nsSocketProviderService.h"
#include "nsISocketProvider.h"
#include "nsISSLSocketControl.h"
#include "nsString.h"
#include "nsMemory.h"
#include "plstr.h"
#include "ldap.h"
#include "ldappr.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
+using namespace mozilla;
+using namespace net;
+
// LDAP per-session data structure.
//
typedef struct {
char *hostname;
LDAP_X_EXTIOF_CLOSE_CALLBACK *realClose;
LDAP_X_EXTIOF_CONNECT_CALLBACK *realConnect;
LDAP_X_EXTIOF_DISPOSEHANDLE_CALLBACK *realDisposeHandle;
} nsLDAPSSLSessionClosure;
@@ -90,19 +94,20 @@ nsLDAPSSLConnect(const char *hostlist, i
struct lextiof_session_private *sessionarg,
struct lextiof_socket_private **socketargp)
{
PRLDAPSocketInfo socketInfo;
PRLDAPSessionInfo sessionInfo;
nsLDAPSSLSocketClosure *socketClosure = nullptr;
nsLDAPSSLSessionClosure *sessionClosure;
int intfd = -1;
- nsCOMPtr <nsISupports> securityInfo;
- nsCOMPtr <nsISocketProvider> tlsSocketProvider;
- nsCOMPtr <nsISSLSocketControl> sslSocketControl;
+ nsCOMPtr<nsISupports> securityInfo;
+ nsCOMPtr<nsISocketProvider> tlsSocketProvider;
+ nsCOMPtr<nsISSLSocketControl> sslSocketControl;
+ nsCOMPtr<nsISocketProviderService> sps;
nsresult rv;
// Ensure secure option is set. Also, clear secure bit in options
// the we pass to the standard connect() function (since it doesn't know
// how to handle the secure option).
//
NS_ASSERTION(options & LDAP_X_EXTIOF_OPT_SECURE,
"nsLDAPSSLConnect(): called for non-secure connection");
@@ -148,22 +153,22 @@ nsLDAPSSLConnect(const char *hostlist, i
if (!socketClosure) {
NS_WARNING("nsLDAPSSLConnect(): unable to allocate socket closure");
goto close_socket_and_exit_with_error;
}
memset(socketClosure, 0, sizeof(nsLDAPSSLSocketClosure));
socketClosure->sessionClosure = sessionClosure;
// Add the NSPR layer for SSL provided by PSM to this socket.
- //
- tlsSocketProvider = do_GetService(NS_STARTTLSSOCKETPROVIDER_CONTRACTID, &rv);
- if (NS_FAILED(rv)) {
- NS_ERROR("nsLDAPSSLConnect(): unable to get socket provider service");
- goto close_socket_and_exit_with_error;
+ sps = nsSocketProviderService::GetOrCreate();
+ if (!sps || NS_FAILED(sps->GetSocketProvider("starttls", getter_AddRefs(tlsSocketProvider)))) {
+ NS_ERROR("nsLDAPSSLConnect(): unable to get starttls socket provider");
+ goto close_socket_and_exit_with_error;
}
+
// XXXdmose: Note that hostlist can be a list of hosts (in the
// current XPCOM SDK code, it will always be a list of IP
// addresses). Because of this, we need to use
// sessionClosure->hostname which was passed in separately to tell
// AddToSocket what to match the name in the certificate against.
// What exactly happen will happen when this is used with some IP
// address in the list other than the first one is not entirely
// clear, and I suspect it may depend on the format of the name in