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 FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H 17 #define FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <unordered_set> 22 23 namespace { 24 constexpr int32_t EXTENSION_TYPE_UNSPECIFIED = 255; 25 } 26 27 /** 28 * @brief Module load checker. check whether module can be loaded 29 * 30 */ 31 class ModuleLoadChecker { 32 public: 33 ModuleLoadChecker() = default; 34 virtual ~ModuleLoadChecker() = default; 35 36 /** 37 * @brief Set the module blocklist, module in the blocklist will prevent loading 38 * 39 * @param blocklist module blocklist 40 */ 41 void SetModuleBlocklist(std::unordered_map<int32_t, std::unordered_set<std::string>>&& blocklist); 42 43 /** 44 * @brief Set the process extension type 45 * 46 * @param extensionType extension type 47 */ 48 void SetProcessExtensionType(int32_t extensionType); 49 50 /** 51 * @brief Get the process extension type 52 * 53 * @return The extension type 54 */ 55 int32_t GetProcessExtensionType(); 56 57 /** 58 * @brief Check whether the module is allowed to be loaded 59 * 60 * @param moduleName module name 61 * @return true The module can be loaded 62 * @return false The module cannot be loaded 63 */ 64 bool CheckModuleLoadable(const char* moduleName); 65 66 private: 67 std::unordered_map<int32_t, std::unordered_set<std::string>> moduleBlocklist_; 68 int32_t processExtensionType_{EXTENSION_TYPE_UNSPECIFIED}; 69 }; 70 71 #endif /* FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H */ 72