• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "config.h"
26 #include "ProtectionSpace.h"
27 
28 #if USE(CFNETWORK) && !PLATFORM(MAC)
29 #include "AuthenticationCF.h"
30 #include <CFNetwork/CFURLProtectionSpacePriv.h>
31 #include <wtf/RetainPtr.h>
32 #endif
33 
34 namespace WebCore {
35 
36 // Need to enforce empty, non-null strings due to the pickiness of the String == String operator
37 // combined with the semantics of the String(NSString*) constructor
ProtectionSpace()38 ProtectionSpace::ProtectionSpace()
39     : m_host("")
40     , m_realm("")
41 {
42 }
43 
44 // Need to enforce empty, non-null strings due to the pickiness of the String == String operator
45 // combined with the semantics of the String(NSString*) constructor
ProtectionSpace(const String & host,int port,ProtectionSpaceServerType serverType,const String & realm,ProtectionSpaceAuthenticationScheme authenticationScheme)46 ProtectionSpace::ProtectionSpace(const String& host, int port, ProtectionSpaceServerType serverType, const String& realm, ProtectionSpaceAuthenticationScheme authenticationScheme)
47     : m_host(host.length() ? host : "")
48     , m_port(port)
49     , m_serverType(serverType)
50     , m_realm(realm.length() ? realm : "")
51     , m_authenticationScheme(authenticationScheme)
52 {
53 }
54 
host() const55 const String& ProtectionSpace::host() const
56 {
57     return m_host;
58 }
59 
port() const60 int ProtectionSpace::port() const
61 {
62     return m_port;
63 }
64 
serverType() const65 ProtectionSpaceServerType ProtectionSpace::serverType() const
66 {
67     return m_serverType;
68 }
69 
isProxy() const70 bool ProtectionSpace::isProxy() const
71 {
72     return (m_serverType == ProtectionSpaceProxyHTTP ||
73             m_serverType == ProtectionSpaceProxyHTTPS ||
74             m_serverType == ProtectionSpaceProxyFTP ||
75             m_serverType == ProtectionSpaceProxySOCKS);
76 }
77 
realm() const78 const String& ProtectionSpace::realm() const
79 {
80     return m_realm;
81 }
82 
authenticationScheme() const83 ProtectionSpaceAuthenticationScheme ProtectionSpace::authenticationScheme() const
84 {
85     return m_authenticationScheme;
86 }
87 
receivesCredentialSecurely() const88 bool ProtectionSpace::receivesCredentialSecurely() const
89 {
90 #if USE(CFNETWORK) && !PLATFORM(MAC)
91     RetainPtr<CFURLProtectionSpaceRef> cfSpace(AdoptCF, createCF(*this));
92     return cfSpace && CFURLProtectionSpaceReceivesCredentialSecurely(cfSpace.get());
93 #else
94     return (m_serverType == ProtectionSpaceServerHTTPS ||
95             m_serverType == ProtectionSpaceServerFTPS ||
96             m_serverType == ProtectionSpaceProxyHTTPS ||
97             m_authenticationScheme == ProtectionSpaceAuthenticationSchemeHTTPDigest);
98 #endif
99 }
100 
operator ==(const ProtectionSpace & a,const ProtectionSpace & b)101 bool operator==(const ProtectionSpace& a, const ProtectionSpace& b)
102 {
103     if (a.host() != b.host())
104         return false;
105     if (a.port() != b.port())
106         return false;
107     if (a.serverType() != b.serverType())
108         return false;
109     if (a.realm() != b.realm())
110         return false;
111     if (a.authenticationScheme() != b.authenticationScheme())
112         return false;
113 
114     return true;
115 }
116 
117 }
118 
119 
120