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