2000-07-01 10:25:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2000-07-01 10:25:25 +00:00
|
|
|
|
2000-06-16 17:53:22 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsSOCKSSocketProvider.h"
|
|
|
|
#include "nsSOCKSIOLayer.h"
|
2003-09-11 20:32:33 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2000-06-16 17:53:22 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-09-11 20:32:33 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsSOCKSSocketProvider, nsISocketProvider)
|
2000-06-16 17:53:22 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
nsresult
|
2003-09-11 20:32:33 +00:00
|
|
|
nsSOCKSSocketProvider::CreateV4(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
2000-06-16 17:53:22 +00:00
|
|
|
{
|
2003-09-11 20:32:33 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISocketProvider> inst =
|
|
|
|
new nsSOCKSSocketProvider(NS_SOCKS_VERSION_4);
|
|
|
|
if (!inst)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
else
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
2000-07-01 10:25:25 +00:00
|
|
|
return rv;
|
2000-06-16 17:53:22 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
nsresult
|
2003-09-11 20:32:33 +00:00
|
|
|
nsSOCKSSocketProvider::CreateV5(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
2000-06-16 17:53:22 +00:00
|
|
|
{
|
2000-07-01 10:25:25 +00:00
|
|
|
nsresult rv;
|
2003-09-11 20:32:33 +00:00
|
|
|
nsCOMPtr<nsISocketProvider> inst =
|
|
|
|
new nsSOCKSSocketProvider(NS_SOCKS_VERSION_5);
|
|
|
|
if (!inst)
|
2000-07-01 10:25:25 +00:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2003-09-11 20:32:33 +00:00
|
|
|
else
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
2000-07-01 10:25:25 +00:00
|
|
|
return rv;
|
2000-06-16 17:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSOCKSSocketProvider::NewSocket(int32_t family,
|
2003-09-11 20:32:33 +00:00
|
|
|
const char *host,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port,
|
2000-07-01 10:25:25 +00:00
|
|
|
const char *proxyHost,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t proxyPort,
|
|
|
|
uint32_t flags,
|
2012-06-30 14:34:17 +00:00
|
|
|
PRFileDesc **result,
|
2000-07-01 10:25:25 +00:00
|
|
|
nsISupports **socksInfo)
|
2000-06-16 17:53:22 +00:00
|
|
|
{
|
2003-09-11 20:32:33 +00:00
|
|
|
PRFileDesc *sock;
|
2000-07-01 10:25:25 +00:00
|
|
|
|
2003-09-11 20:32:33 +00:00
|
|
|
sock = PR_OpenTCPSocket(family);
|
|
|
|
if (!sock)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = nsSOCKSIOLayerAddToSocket(family,
|
|
|
|
host,
|
|
|
|
port,
|
|
|
|
proxyHost,
|
|
|
|
proxyPort,
|
|
|
|
mVersion,
|
2004-12-16 02:46:12 +00:00
|
|
|
flags,
|
2003-09-11 20:32:33 +00:00
|
|
|
sock,
|
|
|
|
socksInfo);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*result = sock;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_SOCKET_CREATE_FAILED;
|
2000-06-16 17:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSOCKSSocketProvider::AddToSocket(int32_t family,
|
2003-09-11 20:32:33 +00:00
|
|
|
const char *host,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port,
|
2000-07-01 10:25:25 +00:00
|
|
|
const char *proxyHost,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t proxyPort,
|
|
|
|
uint32_t flags,
|
2012-06-30 14:34:17 +00:00
|
|
|
PRFileDesc *sock,
|
2000-07-01 10:25:25 +00:00
|
|
|
nsISupports **socksInfo)
|
2000-06-16 17:53:22 +00:00
|
|
|
{
|
2003-09-11 20:32:33 +00:00
|
|
|
nsresult rv = nsSOCKSIOLayerAddToSocket(family,
|
|
|
|
host,
|
2000-07-01 10:25:25 +00:00
|
|
|
port,
|
|
|
|
proxyHost,
|
|
|
|
proxyPort,
|
2003-09-11 20:32:33 +00:00
|
|
|
mVersion,
|
2004-12-16 02:46:12 +00:00
|
|
|
flags,
|
2003-09-11 20:32:33 +00:00
|
|
|
sock,
|
2000-07-01 10:25:25 +00:00
|
|
|
socksInfo);
|
|
|
|
|
2003-09-11 20:32:33 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = NS_ERROR_SOCKET_CREATE_FAILED;
|
|
|
|
return rv;
|
2000-06-16 17:53:22 +00:00
|
|
|
}
|