diff --git a/src/gui/opkg_manager.cpp b/src/gui/opkg_manager.cpp index a76c49cc7..eef74c55b 100644 --- a/src/gui/opkg_manager.cpp +++ b/src/gui/opkg_manager.cpp @@ -76,6 +76,7 @@ #endif #define OPKG_BAD_PATTERN_LIST_FILE CONFIGDIR "/bad_package_pattern.list" +#define OPKG_GOOD_PATTERN_LIST_FILE CONFIGDIR "/good_package_pattern.list" #if 0 #define OPKG_CONFIG_FILE "/etc/opkg/opkg.conf" #else @@ -150,6 +151,7 @@ void COPKGManager::init(int wizard_mode) expert_mode = false; local_dir = &g_settings.update_dir_opkg; v_bad_pattern = getBadPackagePatternList(); + v_good_pattern = getGoodPackagePatternList(); CFileHelpers::createDir(OPKG_TMP_DIR); silent = false; num_updates = 0; @@ -376,48 +378,75 @@ static const struct button_label COPKGManagerFooterButtonsExpert[COPKGManagerFoo vector COPKGManager::getBadPackagePatternList() { - vector v_ret; + return COPKGManager::getPackagePatternList(OPKG_BAD_LIST); +} - ifstream in (OPKG_BAD_PATTERN_LIST_FILE, ios::in); +vector COPKGManager::getGoodPackagePatternList() +{ + return COPKGManager::getPackagePatternList(OPKG_GOOD_LIST); +} + +vector COPKGManager::getPackagePatternList(opkg_pattern_list_t type) +{ + vector v_ret; + std::string list_file = OPKG_BAD_PATTERN_LIST_FILE; + + if (type == OPKG_GOOD_LIST) + list_file = OPKG_GOOD_PATTERN_LIST_FILE; + + ifstream in (list_file, ios::in); if (!in){ dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] can't open %s, %s\n", __func__, __LINE__, OPKG_BAD_PATTERN_LIST_FILE, strerror(errno)); return v_ret; } string line; - while(getline(in, line)){ + while(getline(in, line)) v_ret.push_back(line); - } + in.close(); return v_ret; } -bool COPKGManager::isBadPackage(std::string &s) +bool COPKGManager::isFilteredPackage(std::string &package_name, opkg_pattern_list_t type) { - if(v_bad_pattern.empty()) + std::vector v_patterns; + + if (type == OPKG_BAD_LIST) + v_patterns = v_bad_pattern; + else if (type == OPKG_GOOD_LIST) + v_patterns = v_good_pattern; + + if(v_patterns.empty()) return false; size_t i; string st = ""; - for (i = 0; i < v_bad_pattern.size(); i++) + for (i = 0; i < v_patterns.size(); i++) { - string p = v_bad_pattern[i]; + string p = v_patterns[i]; if (p.empty()) continue; size_t patlen = p.length() - 1; bool res = false; + /* poor man's regex :-) only supported are "^" and "$" */ - if (p.substr(patlen, 1) == "$") { /* match at end */ - size_t pos = s.rfind(p.substr(0, patlen)); /* s.len-patlen can be -1 == npos */ - if (pos != string::npos && pos == (s.length() - patlen)) + if (p.substr(patlen, 1) == "$") + { /* match at end */ + size_t pos = package_name.rfind(p.substr(0, patlen)); /* package_name.len-patlen can be -1 == npos */ + if (pos != string::npos && pos == (package_name.length() - patlen)) res = true; - } else if (p.substr(0, 1) == "^") { /* match at beginning */ - if (s.find(p.substr(1)) == 0) + } + else if (p.substr(0, 1) == "^") + { /* match at beginning */ + if (package_name.find(p.substr(1)) == 0) res = true; - } else { /* match everywhere */ - if (s.find(p) != string::npos) + } + else + { /* match everywhere */ + if (package_name.find(p) != string::npos) res = true; } if (res) @@ -425,13 +454,41 @@ bool COPKGManager::isBadPackage(std::string &s) } if (!st.empty()){ - dprintf(DEBUG_INFO, "[%s] filtered '%s' pattern(s) '%s'\n", __func__, s.c_str(), st.c_str()); + dprintf(DEBUG_DEBUG, "[%s] filtered '%s' pattern(s) '%s'\n", __func__, package_name.c_str(), st.c_str()); return true; } return false; } +bool COPKGManager::isBadPackage(std::string &package_name) +{ + return isFilteredPackage(package_name, OPKG_BAD_LIST); +} + +bool COPKGManager::isGoodPackage(std::string &package_name) +{ + return isFilteredPackage(package_name, OPKG_GOOD_LIST); +} + +bool COPKGManager::isPermittedPackage(std::string &package_name) +{ + bool ret = (!isBadPackage(package_name)); + + if (isBadPackage(package_name) && !isGoodPackage(package_name)) + ret = false; + +// if (isGoodPackage(package_name)) +// ret = true; + + if (isBadPackage(package_name) && isGoodPackage(package_name)) + ret = true; + + + return ret; +} + + void COPKGManager::updateMenu() { bool upgradesAvailable = false; @@ -439,8 +496,9 @@ void COPKGManager::updateMenu() getPkgData(CMD_LIST_UPGRADEABLE); for (map::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it) { /* this should no longer trigger at all */ - if (isBadPackage(it->second.name)) + if (!isPermittedPackage(it->second.name)) continue; + it->second.forwarder->iconName_Info_right = ""; it->second.forwarder->setActive(true); if (it->second.upgradable) { @@ -659,8 +717,9 @@ int COPKGManager::showMenu() pkg_vec.clear(); for (map::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it) { /* this should no longer trigger at all */ - if (isBadPackage(it->second.name)) + if (!isPermittedPackage(it->second.name)) continue; + it->second.forwarder = new CMenuForwarder(it->second.desc, true, NULL , this, it->second.name.c_str()); it->second.forwarder->setHint("", it->second.desc); menu->addItem(it->second.forwarder); @@ -858,8 +917,9 @@ void COPKGManager::getPkgData(const int pkg_content_id) switch (pkg_content_id) { case CMD_LIST: { /* do not even put "bad" packages into the list to save memory */ - if (isBadPackage(name)) + if (!isPermittedPackage(name)) continue; + pkg_map[name] = pkg(name, line, line); map::iterator it = pkg_map.find(name); if (it != pkg_map.end()) diff --git a/src/gui/opkg_manager.h b/src/gui/opkg_manager.h index 62466bb38..7a47c1264 100644 --- a/src/gui/opkg_manager.h +++ b/src/gui/opkg_manager.h @@ -5,7 +5,7 @@ OPKG-Manager Class for Neutrino-GUI Implementation: - Copyright (C) 2012-2020 T. Graf 'dbt' + Copyright (C) 2012-2021 T. Graf 'dbt' www.dbox2-tuning.net Adaptions: @@ -71,7 +71,7 @@ class COPKGManager : public CMenuTarget std::vector config_dest; //filter - std::vector v_bad_pattern; + std::vector v_bad_pattern, v_good_pattern; CMenuWidget *menu; CMenuForwarder *upgrade_forwarder; @@ -144,12 +144,23 @@ class COPKGManager : public CMenuTarget void updateMenu(); void refreshMenu(); - //!Returns a vector with possible filter entries from OPKG_BAD_PATTERN_LIST_FILE + typedef enum + { + OPKG_BAD_LIST = 0, + OPKG_GOOD_LIST = 1 + }opkg_pattern_list_t; + + static std::vector getPackagePatternList(opkg_pattern_list_t type); + + //!Returns a vector with possible filter entries from OPKG_BAD_PATTERN_LIST_FILE or OPKG_GOOD_PATTERN_LIST_FILE static std::vector getBadPackagePatternList(); + static std::vector getGoodPackagePatternList(); + + bool isFilteredPackage(std::string &package_name, opkg_pattern_list_t type); /*! * Returns true if found a ''bad'' package, Parameter: package name as std::string by rev * To detect bad packages, it must be exist a matching pattern list file. - * Path is defined in OPKG_BAD_PATTERN_LIST_FILE. + * Path is defined in OPKG_X_PATTERN_LIST_FILE. * This provides the option to filter some unwanted entries in the package list menue. * This makes sense eg. to hinder that the user could change important system packages. * NOTE: a sample file you should find here as : "/var/tuxbox/config/bad_package_pattern.list.sample" @@ -160,7 +171,12 @@ class COPKGManager : public CMenuTarget * Also a few place holders should work, see the isBadPackage() function, but this * can be inaccurately because it could filter innocent packages. */ - bool isBadPackage(std::string &s); + bool isBadPackage(std::string &package_name); + /*! + The same like isBadPackage() but as whitlist + */ + bool isGoodPackage(std::string &package_name); + bool isPermittedPackage(std::string &package_name); void showError(const char* local_msg, char* err_msg = NULL, const std::string& additional_text = std::string()); int doUpdate();