netwerk/socket/nsSOCKSSocketProvider.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsIServiceManager.h"
michael@0 8 #include "nsSOCKSSocketProvider.h"
michael@0 9 #include "nsSOCKSIOLayer.h"
michael@0 10 #include "nsCOMPtr.h"
michael@0 11 #include "nsError.h"
michael@0 12
michael@0 13 //////////////////////////////////////////////////////////////////////////
michael@0 14
michael@0 15 NS_IMPL_ISUPPORTS(nsSOCKSSocketProvider, nsISocketProvider)
michael@0 16
michael@0 17 nsresult
michael@0 18 nsSOCKSSocketProvider::CreateV4(nsISupports *aOuter, REFNSIID aIID, void **aResult)
michael@0 19 {
michael@0 20 nsresult rv;
michael@0 21 nsCOMPtr<nsISocketProvider> inst =
michael@0 22 new nsSOCKSSocketProvider(NS_SOCKS_VERSION_4);
michael@0 23 if (!inst)
michael@0 24 rv = NS_ERROR_OUT_OF_MEMORY;
michael@0 25 else
michael@0 26 rv = inst->QueryInterface(aIID, aResult);
michael@0 27 return rv;
michael@0 28 }
michael@0 29
michael@0 30 nsresult
michael@0 31 nsSOCKSSocketProvider::CreateV5(nsISupports *aOuter, REFNSIID aIID, void **aResult)
michael@0 32 {
michael@0 33 nsresult rv;
michael@0 34 nsCOMPtr<nsISocketProvider> inst =
michael@0 35 new nsSOCKSSocketProvider(NS_SOCKS_VERSION_5);
michael@0 36 if (!inst)
michael@0 37 rv = NS_ERROR_OUT_OF_MEMORY;
michael@0 38 else
michael@0 39 rv = inst->QueryInterface(aIID, aResult);
michael@0 40 return rv;
michael@0 41 }
michael@0 42
michael@0 43 NS_IMETHODIMP
michael@0 44 nsSOCKSSocketProvider::NewSocket(int32_t family,
michael@0 45 const char *host,
michael@0 46 int32_t port,
michael@0 47 nsIProxyInfo *proxy,
michael@0 48 uint32_t flags,
michael@0 49 PRFileDesc **result,
michael@0 50 nsISupports **socksInfo)
michael@0 51 {
michael@0 52 PRFileDesc *sock;
michael@0 53
michael@0 54 sock = PR_OpenTCPSocket(family);
michael@0 55 if (!sock)
michael@0 56 return NS_ERROR_OUT_OF_MEMORY;
michael@0 57
michael@0 58 nsresult rv = nsSOCKSIOLayerAddToSocket(family,
michael@0 59 host,
michael@0 60 port,
michael@0 61 proxy,
michael@0 62 mVersion,
michael@0 63 flags,
michael@0 64 sock,
michael@0 65 socksInfo);
michael@0 66 if (NS_SUCCEEDED(rv)) {
michael@0 67 *result = sock;
michael@0 68 return NS_OK;
michael@0 69 }
michael@0 70
michael@0 71 return NS_ERROR_SOCKET_CREATE_FAILED;
michael@0 72 }
michael@0 73
michael@0 74 NS_IMETHODIMP
michael@0 75 nsSOCKSSocketProvider::AddToSocket(int32_t family,
michael@0 76 const char *host,
michael@0 77 int32_t port,
michael@0 78 nsIProxyInfo *proxy,
michael@0 79 uint32_t flags,
michael@0 80 PRFileDesc *sock,
michael@0 81 nsISupports **socksInfo)
michael@0 82 {
michael@0 83 nsresult rv = nsSOCKSIOLayerAddToSocket(family,
michael@0 84 host,
michael@0 85 port,
michael@0 86 proxy,
michael@0 87 mVersion,
michael@0 88 flags,
michael@0 89 sock,
michael@0 90 socksInfo);
michael@0 91
michael@0 92 if (NS_FAILED(rv))
michael@0 93 rv = NS_ERROR_SOCKET_CREATE_FAILED;
michael@0 94 return rv;
michael@0 95 }

mercurial