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