~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/netwerk/socket/base/nsSOCKSSocketProvider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Mozilla Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/MPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is mozilla.org code.
 
14
 *
 
15
 * The Initial Developer of the Original Code is Netscape
 
16
 * Communications Corporation.  Portions created by Netscape are
 
17
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
18
 * Rights Reserved.
 
19
 *
 
20
 * Contributor(s):
 
21
 *   Justin Bradford <jab@atdot.org>
 
22
 *   Darin Fisher <darin@meer.net>
 
23
 */
 
24
 
 
25
#include "nsIServiceManager.h"
 
26
#include "nsSOCKSSocketProvider.h"
 
27
#include "nsSOCKSIOLayer.h"
 
28
#include "nsCOMPtr.h"
 
29
#include "nsNetError.h"
 
30
 
 
31
//////////////////////////////////////////////////////////////////////////
 
32
 
 
33
NS_IMPL_THREADSAFE_ISUPPORTS1(nsSOCKSSocketProvider, nsISocketProvider)
 
34
 
 
35
NS_METHOD
 
36
nsSOCKSSocketProvider::CreateV4(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 
37
{
 
38
    nsresult rv;
 
39
    nsCOMPtr<nsISocketProvider> inst =
 
40
            new nsSOCKSSocketProvider(NS_SOCKS_VERSION_4);
 
41
    if (!inst)
 
42
        rv = NS_ERROR_OUT_OF_MEMORY;
 
43
    else
 
44
        rv = inst->QueryInterface(aIID, aResult); 
 
45
    return rv;
 
46
}
 
47
 
 
48
NS_METHOD
 
49
nsSOCKSSocketProvider::CreateV5(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 
50
{
 
51
    nsresult rv;
 
52
    nsCOMPtr<nsISocketProvider> inst =
 
53
            new nsSOCKSSocketProvider(NS_SOCKS_VERSION_5);
 
54
    if (!inst)
 
55
        rv = NS_ERROR_OUT_OF_MEMORY;
 
56
    else
 
57
        rv = inst->QueryInterface(aIID, aResult); 
 
58
    return rv;
 
59
}
 
60
 
 
61
NS_IMETHODIMP
 
62
nsSOCKSSocketProvider::NewSocket(PRInt32 family,
 
63
                                 const char *host, 
 
64
                                 PRInt32 port,
 
65
                                 const char *proxyHost,
 
66
                                 PRInt32 proxyPort,
 
67
                                 PRFileDesc **result, 
 
68
                                 nsISupports **socksInfo)
 
69
{
 
70
    PRFileDesc *sock;
 
71
    
 
72
    sock = PR_OpenTCPSocket(family);
 
73
    if (!sock)
 
74
        return NS_ERROR_OUT_OF_MEMORY;
 
75
 
 
76
    nsresult rv = nsSOCKSIOLayerAddToSocket(family,
 
77
                                            host, 
 
78
                                            port,
 
79
                                            proxyHost,
 
80
                                            proxyPort,
 
81
                                            mVersion,
 
82
                                            sock, 
 
83
                                            socksInfo);
 
84
    if (NS_SUCCEEDED(rv)) {
 
85
        *result = sock;
 
86
        return NS_OK;
 
87
    }
 
88
 
 
89
    return NS_ERROR_SOCKET_CREATE_FAILED;
 
90
}
 
91
 
 
92
NS_IMETHODIMP
 
93
nsSOCKSSocketProvider::AddToSocket(PRInt32 family,
 
94
                                   const char *host,
 
95
                                   PRInt32 port,
 
96
                                   const char *proxyHost,
 
97
                                   PRInt32 proxyPort,
 
98
                                   PRFileDesc *sock, 
 
99
                                   nsISupports **socksInfo)
 
100
{
 
101
    nsresult rv = nsSOCKSIOLayerAddToSocket(family,
 
102
                                            host, 
 
103
                                            port,
 
104
                                            proxyHost,
 
105
                                            proxyPort,
 
106
                                            mVersion,
 
107
                                            sock, 
 
108
                                            socksInfo);
 
109
    
 
110
    if (NS_FAILED(rv))
 
111
        rv = NS_ERROR_SOCKET_CREATE_FAILED;
 
112
    return rv;
 
113
}