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 #ifndef PRINT_SECURITY_GUARD_UTIL_H
17 #define PRINT_SECURITY_GUARD_UTIL_H
18 
19 #include "print_util.h"
20 
21 namespace OHOS::Print {
22 enum PrinterFoundType {
23     FROM_P2P = 0,
24     FROM_EPRINT = 1,
25     FROM_LOCAL_NET = 2,
26     FROM_USB = 3
27 };
28 
29 class PrintSecurityGuardUtil {
30 public:
31     static int32_t GetPrinterType(const std::string& des);
32 };
33 
GetPrinterType(const std::string & des)34 inline int32_t PrintSecurityGuardUtil::GetPrinterType(const std::string& des)
35 {
36     std::string upper = PrintUtil::ToUpper(des);
37     std::map<std::string, int32_t> typeMap;
38     typeMap.insert({"P2P", FROM_P2P});
39     typeMap.insert({"EPRINT", FROM_EPRINT});
40     typeMap.insert({"USB", FROM_USB});
41 
42     for (auto iter = typeMap.begin(); iter != typeMap.end(); iter++) {
43         std::string key = iter->first;
44         if (PrintUtil::CheckContains(upper, key)) {
45             return iter->second;
46         }
47     }
48     return FROM_LOCAL_NET;
49 }
50 } // namespace OHOS::Print
51 
52 #endif // PRINT_SECURITY_GUARD_UTIL_H