146debc2cSopenharmony_ci/* 246debc2cSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 346debc2cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 446debc2cSopenharmony_ci * you may not use this file except in compliance with the License. 546debc2cSopenharmony_ci * You may obtain a copy of the License at 646debc2cSopenharmony_ci * 746debc2cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 846debc2cSopenharmony_ci * 946debc2cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1046debc2cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1146debc2cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1246debc2cSopenharmony_ci * See the License for the specific language governing permissions and 1346debc2cSopenharmony_ci * limitations under the License. 1446debc2cSopenharmony_ci */ 1546debc2cSopenharmony_ci 1646debc2cSopenharmony_ci#ifndef PRINT_SECURITY_GUARD_UTIL_H 1746debc2cSopenharmony_ci#define PRINT_SECURITY_GUARD_UTIL_H 1846debc2cSopenharmony_ci 1946debc2cSopenharmony_ci#include "print_util.h" 2046debc2cSopenharmony_ci 2146debc2cSopenharmony_cinamespace OHOS::Print { 2246debc2cSopenharmony_cienum PrinterFoundType { 2346debc2cSopenharmony_ci FROM_P2P = 0, 2446debc2cSopenharmony_ci FROM_EPRINT = 1, 2546debc2cSopenharmony_ci FROM_LOCAL_NET = 2, 2646debc2cSopenharmony_ci FROM_USB = 3 2746debc2cSopenharmony_ci}; 2846debc2cSopenharmony_ci 2946debc2cSopenharmony_ciclass PrintSecurityGuardUtil { 3046debc2cSopenharmony_cipublic: 3146debc2cSopenharmony_ci static int32_t GetPrinterType(const std::string& des); 3246debc2cSopenharmony_ci}; 3346debc2cSopenharmony_ci 3446debc2cSopenharmony_ciinline int32_t PrintSecurityGuardUtil::GetPrinterType(const std::string& des) 3546debc2cSopenharmony_ci{ 3646debc2cSopenharmony_ci std::string upper = PrintUtil::ToUpper(des); 3746debc2cSopenharmony_ci std::map<std::string, int32_t> typeMap; 3846debc2cSopenharmony_ci typeMap.insert({"P2P", FROM_P2P}); 3946debc2cSopenharmony_ci typeMap.insert({"EPRINT", FROM_EPRINT}); 4046debc2cSopenharmony_ci typeMap.insert({"USB", FROM_USB}); 4146debc2cSopenharmony_ci 4246debc2cSopenharmony_ci for (auto iter = typeMap.begin(); iter != typeMap.end(); iter++) { 4346debc2cSopenharmony_ci std::string key = iter->first; 4446debc2cSopenharmony_ci if (PrintUtil::CheckContains(upper, key)) { 4546debc2cSopenharmony_ci return iter->second; 4646debc2cSopenharmony_ci } 4746debc2cSopenharmony_ci } 4846debc2cSopenharmony_ci return FROM_LOCAL_NET; 4946debc2cSopenharmony_ci} 5046debc2cSopenharmony_ci} // namespace OHOS::Print 5146debc2cSopenharmony_ci 5246debc2cSopenharmony_ci#endif // PRINT_SECURITY_GUARD_UTIL_H