1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "net_http_probe_result.h" 17 18 namespace OHOS { 19 namespace NetManagerStandard { 20 namespace { 21 constexpr int32_t SUCCESS_CODE = 204; 22 constexpr int32_t PORTAL_CODE_MIN = 200; 23 constexpr int32_t PORTAL_CODE_MAX = 399; 24 } // namespace NetHttpProbeResult(int32_t code,const std::string & redirectUrl)25NetHttpProbeResult::NetHttpProbeResult(int32_t code, const std::string &redirectUrl) 26 : responseCode_(code), redirectUrl_(redirectUrl) 27 { 28 } 29 GetCode() const30int32_t NetHttpProbeResult::GetCode() const 31 { 32 return responseCode_; 33 } 34 GetRedirectUrl() const35std::string NetHttpProbeResult::GetRedirectUrl() const 36 { 37 return redirectUrl_; 38 } 39 IsSuccessful() const40bool NetHttpProbeResult::IsSuccessful() const 41 { 42 return (responseCode_ == SUCCESS_CODE); 43 } 44 IsNeedPortal() const45bool NetHttpProbeResult::IsNeedPortal() const 46 { 47 return (responseCode_ >= PORTAL_CODE_MIN && responseCode_ <= PORTAL_CODE_MAX) && (responseCode_ != SUCCESS_CODE); 48 } 49 IsFailed() const50bool NetHttpProbeResult::IsFailed() const 51 { 52 return !IsSuccessful() && !IsNeedPortal(); 53 } 54 operator ==(const NetHttpProbeResult & result) const55bool NetHttpProbeResult::operator==(const NetHttpProbeResult &result) const 56 { 57 if (IsSuccessful() && result.IsSuccessful()) { 58 return true; 59 } 60 if (IsNeedPortal() && result.IsNeedPortal() && (redirectUrl_ == result.redirectUrl_)) { 61 return true; 62 } 63 if (IsFailed() && result.IsFailed()) { 64 return true; 65 } 66 return false; 67 } 68 operator !=(const NetHttpProbeResult & result) const69bool NetHttpProbeResult::operator!=(const NetHttpProbeResult &result) const 70 { 71 return !(*this == result); 72 } 73 operator =(const NetHttpProbeResult & result)74NetHttpProbeResult &NetHttpProbeResult::operator=(const NetHttpProbeResult &result) 75 { 76 responseCode_ = result.responseCode_; 77 redirectUrl_ = result.redirectUrl_; 78 return *this; 79 } 80 } // namespace NetManagerStandard 81 } // namespace OHOS 82