2000-07-01 14:25:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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 14:25:25 +04:00
|
|
|
|
2000-06-16 21:53:22 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2016-09-13 11:36:12 +03:00
|
|
|
#include "nsNamedPipeIOLayer.h"
|
2000-06-16 21:53:22 +04:00
|
|
|
#include "nsSOCKSSocketProvider.h"
|
|
|
|
#include "nsSOCKSIOLayer.h"
|
2003-09-12 00:32:33 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2000-06-16 21:53:22 +04:00
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
using mozilla::OriginAttributes;
|
2016-11-21 06:43:06 +03:00
|
|
|
|
2000-06-16 21:53:22 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSOCKSSocketProvider, nsISocketProvider)
|
2000-06-16 21:53:22 +04:00
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
nsresult
|
2003-09-12 00:32:33 +04:00
|
|
|
nsSOCKSSocketProvider::CreateV4(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
2000-06-16 21:53:22 +04:00
|
|
|
{
|
2003-09-12 00:32:33 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISocketProvider> inst =
|
|
|
|
new nsSOCKSSocketProvider(NS_SOCKS_VERSION_4);
|
|
|
|
if (!inst)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
else
|
2017-07-06 15:00:35 +03:00
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
2000-07-01 14:25:25 +04:00
|
|
|
return rv;
|
2000-06-16 21:53:22 +04:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
nsresult
|
2003-09-12 00:32:33 +04:00
|
|
|
nsSOCKSSocketProvider::CreateV5(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
2000-06-16 21:53:22 +04:00
|
|
|
{
|
2000-07-01 14:25:25 +04:00
|
|
|
nsresult rv;
|
2003-09-12 00:32:33 +04:00
|
|
|
nsCOMPtr<nsISocketProvider> inst =
|
|
|
|
new nsSOCKSSocketProvider(NS_SOCKS_VERSION_5);
|
|
|
|
if (!inst)
|
2000-07-01 14:25:25 +04:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2003-09-12 00:32:33 +04:00
|
|
|
else
|
2017-07-06 15:00:35 +03:00
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
2000-07-01 14:25:25 +04:00
|
|
|
return rv;
|
2000-06-16 21:53:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSOCKSSocketProvider::NewSocket(int32_t family,
|
2017-07-06 15:00:35 +03:00
|
|
|
const char *host,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port,
|
2015-11-25 00:56:00 +03:00
|
|
|
nsIProxyInfo *proxy,
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes &originAttributes,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags,
|
2017-08-16 22:41:16 +03:00
|
|
|
uint32_t tlsFlags,
|
2012-06-30 18:34:17 +04:00
|
|
|
PRFileDesc **result,
|
2000-07-01 14:25:25 +04:00
|
|
|
nsISupports **socksInfo)
|
2000-06-16 21:53:22 +04:00
|
|
|
{
|
2003-09-12 00:32:33 +04:00
|
|
|
PRFileDesc *sock;
|
2016-09-13 11:36:12 +03:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
nsAutoCString proxyHost;
|
|
|
|
proxy->GetHost(proxyHost);
|
|
|
|
if (IsNamedPipePath(proxyHost)) {
|
|
|
|
sock = CreateNamedPipeLayer();
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
sock = PR_OpenTCPSocket(family);
|
|
|
|
if (!sock) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
nsresult rv = nsSOCKSIOLayerAddToSocket(family,
|
2017-07-06 15:00:35 +03:00
|
|
|
host,
|
2003-09-12 00:32:33 +04:00
|
|
|
port,
|
2015-11-25 00:56:00 +03:00
|
|
|
proxy,
|
2003-09-12 00:32:33 +04:00
|
|
|
mVersion,
|
2004-12-16 05:46:12 +03:00
|
|
|
flags,
|
2017-08-16 22:41:16 +03:00
|
|
|
tlsFlags,
|
2017-07-06 15:00:35 +03:00
|
|
|
sock,
|
2003-09-12 00:32:33 +04:00
|
|
|
socksInfo);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*result = sock;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_SOCKET_CREATE_FAILED;
|
2000-06-16 21:53:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSOCKSSocketProvider::AddToSocket(int32_t family,
|
2003-09-12 00:32:33 +04:00
|
|
|
const char *host,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port,
|
2015-11-25 00:56:00 +03:00
|
|
|
nsIProxyInfo *proxy,
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes &originAttributes,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags,
|
2017-08-16 22:41:16 +03:00
|
|
|
uint32_t tlsFlags,
|
2012-06-30 18:34:17 +04:00
|
|
|
PRFileDesc *sock,
|
2000-07-01 14:25:25 +04:00
|
|
|
nsISupports **socksInfo)
|
2000-06-16 21:53:22 +04:00
|
|
|
{
|
2003-09-12 00:32:33 +04:00
|
|
|
nsresult rv = nsSOCKSIOLayerAddToSocket(family,
|
2017-07-06 15:00:35 +03:00
|
|
|
host,
|
2000-07-01 14:25:25 +04:00
|
|
|
port,
|
2015-11-25 00:56:00 +03:00
|
|
|
proxy,
|
2003-09-12 00:32:33 +04:00
|
|
|
mVersion,
|
2004-12-16 05:46:12 +03:00
|
|
|
flags,
|
2017-08-16 22:41:16 +03:00
|
|
|
tlsFlags,
|
2017-07-06 15:00:35 +03:00
|
|
|
sock,
|
2000-07-01 14:25:25 +04:00
|
|
|
socksInfo);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
rv = NS_ERROR_SOCKET_CREATE_FAILED;
|
|
|
|
return rv;
|
2000-06-16 21:53:22 +04:00
|
|
|
}
|