src/library/LicenseReader.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/licensecc.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/ApplicationFolder.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/ApplicationFolder.hpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/EnvironmentVarData.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/EnvironmentVarData.hpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/EnvironmentVarLocation.hpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/locate/LocatorStrategy.hpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/date_test.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/library/test_reader.ini | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/library/LicenseReader.cpp
@@ -54,6 +54,8 @@ } bool atLeastOneLicenseComplete = false; const string product_up = toupper_copy(product); const char *productNamePtr = product_up.c_str(); for (unique_ptr<locate::LocatorStrategy> &locator : locator_strategies) { vector<string> licenseLocations = locator->license_locations(eventRegistry); if (licenseLocations.size() == 0) { @@ -68,7 +70,6 @@ eventRegistry.addEvent(FILE_FORMAT_NOT_RECOGNIZED, *it); continue; } const char *productNamePtr = product.c_str(); const int sectionSize = ini.GetSectionSize(productNamePtr); if (sectionSize <= 0) { eventRegistry.addEvent(PRODUCT_NOT_LICENSED, *it); @@ -85,8 +86,8 @@ * sig = XXXXXXXXXX (mandatory, 1024) * application_data = xxxxxxxxx (optional string 16) */ const char *license_signature = ini.GetValue(productNamePtr, "sig", nullptr); long license_version = ini.GetLongValue(productNamePtr, "lic_ver", -1); const char *license_signature = ini.GetValue(productNamePtr, LICENSE_SIGNATURE, nullptr); long license_version = ini.GetLongValue(productNamePtr, LICENSE_VERSION, -1); if (license_signature != nullptr && license_version == 200) { CSimpleIniA::TNamesDepend keys; ini.GetAllKeys(productNamePtr, keys); src/library/licensecc.cpp
@@ -24,13 +24,13 @@ static void mergeLicenses(const vector<LicenseInfo>& licenses, LicenseInfo* license_out) { if (license_out != nullptr) { int days_left = -1; int days_left = INT_MIN; for (auto it = licenses.begin(); it != licenses.end(); it++) { // choose the license that expires later... if (!it->has_expiry) { *license_out = *it; break; } else if (days_left < it->days_left) { } else if (days_left < (int)it->days_left) { *license_out = *it; days_left = it->days_left; } src/library/locate/ApplicationFolder.cpp
@@ -22,17 +22,13 @@ namespace locate { using namespace std; ApplicationFolder::ApplicationFolder() : LocatorStrategy("ApplicationFolder") { } ApplicationFolder::ApplicationFolder() : LocatorStrategy("ApplicationFolder") {} ApplicationFolder::~ApplicationFolder() { } ApplicationFolder::~ApplicationFolder() {} const vector<string> ApplicationFolder::license_locations( EventRegistry &eventRegistry) { const vector<string> ApplicationFolder::license_locations(EventRegistry &eventRegistry) { vector<string> diskFiles; char fname[MAX_PATH] = { 0 }; char fname[MAX_PATH] = {0}; const FUNCTION_RETURN fret = getModuleName(fname); if (fret == FUNC_RET_OK) { const string module_name = remove_extension(fname); @@ -51,5 +47,5 @@ return diskFiles; } } } // namespace locate } /* namespace license */ src/library/locate/ApplicationFolder.hpp
@@ -15,14 +15,14 @@ namespace license { namespace locate { class ApplicationFolder: public LocatorStrategy { class ApplicationFolder : public LocatorStrategy { public: ApplicationFolder(); virtual const std::vector<std::string> license_locations(EventRegistry& eventRegistry); const virtual std::vector<std::string> license_locations(EventRegistry& eventRegistry); virtual ~ApplicationFolder(); }; } } // namespace locate } /* namespace license */ #endif /* SRC_LIBRARY_RETRIEVERS_APPLICATIONFOLDER_H_ */ src/library/locate/EnvironmentVarData.cpp
@@ -23,15 +23,11 @@ using namespace std; EnvironmentVarData::EnvironmentVarData() : LocatorStrategy("EnvironmentVarData") { } EnvironmentVarData::EnvironmentVarData() : LocatorStrategy("EnvironmentVarData") {} EnvironmentVarData::~EnvironmentVarData() { } EnvironmentVarData::~EnvironmentVarData() {} const vector<string> EnvironmentVarData::license_locations( EventRegistry &eventRegistry) { const vector<string> EnvironmentVarData::license_locations(EventRegistry &eventRegistry) { vector<string> diskFiles; char *env_var_value = getenv(LICENSE_DATA_ENV_VAR); if (env_var_value != nullptr && env_var_value[0] != '\0') { @@ -44,24 +40,22 @@ isBase64 = (licenseFormat == BASE64); } } else { eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED, LICENSE_LOCATION_ENV_VAR); eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED, LICENSE_LOCATION_ENV_VAR); } return diskFiles; } const std::string EnvironmentVarData::retrieve_license_content( const std::string &licenseLocation) const { const std::string EnvironmentVarData::retrieve_license_content(const std::string &licenseLocation) const { string tmpVal = getenv(LICENSE_LOCATION_ENV_VAR); if (isBase64) { int flen = 0; unsigned char *raw = unbase64(tmpVal.c_str(), tmpVal.length(), &flen); string str = string(reinterpret_cast<char*>(raw)); string str = string(reinterpret_cast<char *>(raw)); free(raw); return str; } return tmpVal; } } } } // namespace locate } // namespace license src/library/locate/EnvironmentVarData.hpp
@@ -12,18 +12,18 @@ namespace license { namespace locate { class EnvironmentVarData: public LocatorStrategy { class EnvironmentVarData : public LocatorStrategy { private: bool isBase64 = false; public: EnvironmentVarData(); virtual const std::vector<std::string> license_locations(EventRegistry& eventRegistr); virtual const std::string retrieve_license_content(const std::string &licenseLocation) const; const virtual std::vector<std::string> license_locations(EventRegistry& eventRegistr); const virtual std::string retrieve_license_content(const std::string& licenseLocation) const; virtual ~EnvironmentVarData(); }; } } } // namespace locate } // namespace license #endif src/library/locate/EnvironmentVarLocation.hpp
@@ -13,15 +13,14 @@ namespace license { namespace locate { class EnvironmentVarLocation: public LocatorStrategy { class EnvironmentVarLocation : public LocatorStrategy { public: EnvironmentVarLocation(); virtual const std::vector<std::string> license_locations(EventRegistry& eventRegistry); const virtual std::vector<std::string> license_locations(EventRegistry& eventRegistry); virtual ~EnvironmentVarLocation(); }; } } } // namespace locate } // namespace license #endif /* SRC_LIBRARY_LOCATE_ENVIRONMENTVARLOCATION_H_ */ src/library/locate/LocatorStrategy.hpp
@@ -16,29 +16,25 @@ * * Usage: * <ol> * <li> call licenseLocations to get a list of available locations (the returned format is defined by the class, it's usually the file name)</li> * <li> iterate over the returned vector and call retrieveLicense to get the content of the license</li> * <li> call licenseLocations to get a list of available locations (the returned format is defined by the class, it's * usually the file name)</li> <li> iterate over the returned vector and call retrieveLicense to get the content of the * license</li> * </ol> */ class LocatorStrategy { protected: const std::string m_strategy_name; inline LocatorStrategy(const std::string &strategyName) : m_strategy_name(strategyName) { } public: inline LocatorStrategy(const std::string &strategyName) : m_strategy_name(strategyName) {} virtual const std::string get_strategy_name() const { return m_strategy_name; } public: const virtual std::string get_strategy_name() const { return m_strategy_name; } /** * Try to find licenses * @param eventRegistry * @return * A list of identifiers for call retrieve_license_content. */ virtual const std::vector<std::string> license_locations( EventRegistry &eventRegistry) = 0; const virtual std::vector<std::string> license_locations(EventRegistry &eventRegistry) = 0; /** * Default implementation is to retrieve the license from file. @@ -49,12 +45,10 @@ * @return * a string containing the license data in INI format. */ virtual const std::string retrieve_license_content( const std::string &licenseLocationId) const; inline virtual ~LocatorStrategy() { } const virtual std::string retrieve_license_content(const std::string &licenseLocationId) const; inline virtual ~LocatorStrategy() {} }; } } } // namespace locate } // namespace license #endif test/functional/date_test.cpp
@@ -1,4 +1,4 @@ #define BOOST_TEST_MODULE date_test #define BOOST_TEST_MODULE test_date #include <boost/test/unit_test.hpp> #include <boost/filesystem.hpp> @@ -18,11 +18,10 @@ namespace test { BOOST_AUTO_TEST_CASE(license_not_expired) { const string licLocation(PROJECT_TEST_TEMP_DIR "/not_expired.lic"); vector<string> extraArgs; extraArgs.push_back("-e"); extraArgs.push_back("2050-10-10"); generate_license(licLocation, extraArgs); const string licLocation = generate_license("not_expired.lic", extraArgs); /* */ LicenseInfo license; LicenseLocation licenseLocation; @@ -32,15 +31,14 @@ BOOST_CHECK_EQUAL(result, LICENSE_OK); BOOST_CHECK_EQUAL(license.has_expiry, true); BOOST_CHECK_EQUAL(license.linked_to_pc, false); BOOST_CHECK_GT(license.days_left, 0); } BOOST_AUTO_TEST_CASE(license_expired) { const string licLocation(PROJECT_TEST_TEMP_DIR "/expired.lic"); remove(licLocation.c_str()); vector<string> extraArgs; extraArgs.push_back("-e"); extraArgs.push_back("2013-10-10"); generate_license(licLocation, extraArgs); const string licLocation = generate_license("expired", extraArgs); /* */ LicenseInfo license; LicenseLocation licenseLocation; @@ -51,6 +49,7 @@ BOOST_CHECK_EQUAL(result, PRODUCT_EXPIRED); BOOST_CHECK_EQUAL(license.has_expiry, true); BOOST_CHECK_EQUAL(license.linked_to_pc, false); BOOST_CHECK_EQUAL(license.days_left, 0); } } // namespace test test/library/test_reader.ini
@@ -1,3 +1,3 @@ [PRODUCT] license_version = 100 license_signature = qAz lic_ver = 200 sig = qAz