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 "AuthenticationChallenge.h"
27
28 #include "ResourceHandle.h"
29
30 namespace WebCore {
31
AuthenticationChallengeBase()32 AuthenticationChallengeBase::AuthenticationChallengeBase()
33 : m_isNull(true)
34 , m_previousFailureCount(0)
35 {
36 }
37
AuthenticationChallengeBase(const ProtectionSpace & protectionSpace,const Credential & proposedCredential,unsigned previousFailureCount,const ResourceResponse & response,const ResourceError & error)38 AuthenticationChallengeBase::AuthenticationChallengeBase(const ProtectionSpace& protectionSpace,
39 const Credential& proposedCredential,
40 unsigned previousFailureCount,
41 const ResourceResponse& response,
42 const ResourceError& error)
43 : m_isNull(false)
44 , m_protectionSpace(protectionSpace)
45 , m_proposedCredential(proposedCredential)
46 , m_previousFailureCount(previousFailureCount)
47 , m_failureResponse(response)
48 , m_error(error)
49 {
50 }
51
previousFailureCount() const52 unsigned AuthenticationChallengeBase::previousFailureCount() const
53 {
54 return m_previousFailureCount;
55 }
56
proposedCredential() const57 const Credential& AuthenticationChallengeBase::proposedCredential() const
58 {
59 return m_proposedCredential;
60 }
61
protectionSpace() const62 const ProtectionSpace& AuthenticationChallengeBase::protectionSpace() const
63 {
64 return m_protectionSpace;
65 }
66
failureResponse() const67 const ResourceResponse& AuthenticationChallengeBase::failureResponse() const
68 {
69 return m_failureResponse;
70 }
71
error() const72 const ResourceError& AuthenticationChallengeBase::error() const
73 {
74 return m_error;
75 }
76
isNull() const77 bool AuthenticationChallengeBase::isNull() const
78 {
79 return m_isNull;
80 }
81
nullify()82 void AuthenticationChallengeBase::nullify()
83 {
84 m_isNull = true;
85 }
86
compare(const AuthenticationChallenge & a,const AuthenticationChallenge & b)87 bool AuthenticationChallengeBase::compare(const AuthenticationChallenge& a, const AuthenticationChallenge& b)
88 {
89 if (a.isNull() && b.isNull())
90 return true;
91
92 if (a.isNull() || b.isNull())
93 return false;
94
95 if (a.protectionSpace() != b.protectionSpace())
96 return false;
97
98 if (a.proposedCredential() != b.proposedCredential())
99 return false;
100
101 if (a.previousFailureCount() != b.previousFailureCount())
102 return false;
103
104 if (a.failureResponse() != b.failureResponse())
105 return false;
106
107 if (a.error() != b.error())
108 return false;
109
110 return AuthenticationChallenge::platformCompare(a, b);
111 }
112
113 }
114