13个文件已修改
1个文件已添加
7 文件已重命名
2个文件已删除
| | |
| | | </builder> |
| | | <tool id="cdt.managedbuild.tool.gnu.archiver.base.1063978701" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> |
| | | <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"> |
| | | <option id="gnu.cpp.compiler.option.preprocessor.def.1664583179" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols"> |
| | | <option id="gnu.cpp.compiler.option.preprocessor.def.1664583179" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols"> |
| | | <listOptionValue builtIn="false" value="__GXX_EXPERIMENTAL_CXX0X__"/> |
| | | </option> |
| | | <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.18539696" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> |
| | |
| | | add_subdirectory("os/linux") |
| | | ENDIF(WIN32) |
| | | add_subdirectory("base") |
| | | add_subdirectory("reader") |
| | | add_subdirectory("ini") |
| | | |
| | | ADD_LIBRARY(license++_static STATIC |
| | | license++.cpp |
| | | LicenseReader.cpp |
| | | ) |
| | | |
| | | target_link_libraries( |
| | | license++_static |
| | | reader |
| | | ini |
| | | os |
| | | ) |
| | | |
File was renamed from src/library/reader/LicenseReader.cpp |
| | |
| | | * Author: devel |
| | | */ |
| | | |
| | | #include "LicenseReader.h" |
| | | #include "../base/StringUtils.h" |
| | | #include "../base/public-key.h" |
| | | #include <build_properties.h> |
| | | #define SI_SUPPORT_IOSTREAMS |
| | | #include "SimpleIni.h" |
| | | #ifdef _WIN32 |
| | | # pragma warning(disable: 4786) |
| | | #else |
| | | # include <unistd.h> |
| | | #endif |
| | | #include <cstring> |
| | | #include <ctime> |
| | | #include <vector> |
| | |
| | | #include <fstream> |
| | | #include <sstream> |
| | | #include <stdlib.h> |
| | | #include "LicenseReader.h" |
| | | #include "base/StringUtils.h" |
| | | #include "base/public-key.h" |
| | | #include <build_properties.h> |
| | | |
| | | #ifdef _WIN32 |
| | | # pragma warning(disable: 4786) |
| | | #else |
| | | # include <unistd.h> |
| | | #endif |
| | | |
| | | #define SI_SUPPORT_IOSTREAMS |
| | | #include "SimpleIni.h" |
| | | #include "../os/os.hpp" |
| | | #include "os/os.hpp" |
| | | |
| | | namespace license { |
| | | |
| | | FullLicenseInfo::FullLicenseInfo(const string& source, const string& product, |
| | | const string& license_signature, int licenseVersion, time_t from_date, |
| | | time_t to_date, // |
| | | const string& license_signature, int licenseVersion, // |
| | | time_t from_date, time_t to_date, // |
| | | const string& client_signature, unsigned int from_sw_version, |
| | | unsigned int to_sw_version, const string& extra_data) : |
| | | source(source), product(product), // |
| | |
| | | } else { |
| | | er.addEvent(LICENSE_CORRUPTED, SEVERITY_ERROR); |
| | | } |
| | | if(has_expiry){ |
| | | if (has_expiry) { |
| | | time_t now = time(NULL); |
| | | if(this->to_date<now){ |
| | | if (this->to_date < now) { |
| | | er.addEvent(PRODUCT_EXPIRED, SEVERITY_ERROR, ""); |
| | | } |
| | | if(this->from_date>now){ |
| | | if (this->from_date > now) { |
| | | er.addEvent(PRODUCT_EXPIRED, SEVERITY_ERROR); |
| | | } |
| | | } |
| | |
| | | LicenseReader::LicenseReader(const LicenseLocation& licenseLocation) : |
| | | licenseLocation(licenseLocation) { |
| | | |
| | | } |
| | | |
| | | time_t LicenseReader::read_date(const char * productName, const char * ini_key, |
| | | const CSimpleIniA& ini) const { |
| | | string from_date_str = ini.GetValue(productName, ini_key); |
| | | time_t from_date = FullLicenseInfo::UNUSED_TIME; |
| | | if (from_date_str.length() > 0) { |
| | | from_date = seconds_from_epoch(from_date_str.c_str()); |
| | | } |
| | | return from_date; |
| | | } |
| | | |
| | | EventRegistry LicenseReader::readLicenses(const string &product, |
| | |
| | | long license_version = ini.GetLongValue(productNamePtr, |
| | | "license_version", -1); |
| | | if (license_signature != NULL && license_version > 0) { |
| | | time_t from_date = read_date(productNamePtr, "from_date", ini); |
| | | time_t to_date = read_date(productNamePtr, "to_date", ini); |
| | | FullLicenseInfo licInfo(*it, product, license_signature, |
| | | (int) license_version); |
| | | (int) license_version, from_date, to_date); |
| | | licenseInfoOut.push_back(licInfo); |
| | | atLeastOneLicenseComplete = true; |
| | | } else { |
| | |
| | | strftime(buff, 20, "%Y-%m-%d", localtime(&this->from_date)); |
| | | ini.SetValue(product.c_str(), "from_date", buff); |
| | | } |
| | | char buff2[20]; |
| | | if (this->to_date != UNUSED_TIME) { |
| | | strftime(buff, 20, "%Y-%m-%d", localtime(&this->to_date)); |
| | | ini.SetValue(product.c_str(), "to_date", buff); |
| | | strftime(buff2, 20, "%Y-%m-%d", localtime(&this->to_date)); |
| | | ini.SetValue(product.c_str(), "to_date", buff2); |
| | | } |
| | | if (this->extra_data.length() > 0) { |
| | | ini.SetValue(product.c_str(), "extra_data", this->extra_data.c_str()); |
File was renamed from src/library/reader/LicenseReader.h |
| | |
| | | #ifndef LICENSEREADER_H_ |
| | | #define LICENSEREADER_H_ |
| | | |
| | | #include "../api/datatypes.h" |
| | | #include "../base/EventRegistry.h" |
| | | #include "../os/os.hpp" |
| | | #include "api/datatypes.h" |
| | | #include "base/EventRegistry.h" |
| | | #include "os/os.hpp" |
| | | #define SI_SUPPORT_IOSTREAMS |
| | | #include "ini/SimpleIni.h" |
| | | #include <string> |
| | | #include <ctime> |
| | | namespace license { |
| | |
| | | FullLicenseInfo(const string& source, const string& product, |
| | | const string& license_signature, int licenseVersion, |
| | | time_t from_date = UNUSED_TIME, |
| | | time_t tp_date = UNUSED_TIME, // |
| | | time_t to_date = UNUSED_TIME, // |
| | | const string& client_signature = "", // |
| | | unsigned int from_sw_version = UNUSED_SOFTWARE_VERSION, |
| | | unsigned int to_sw_version = UNUSED_SOFTWARE_VERSION, |
| | |
| | | */ |
| | | class LicenseReader { |
| | | private: |
| | | time_t read_date(const char * productName, const char * ini_key, |
| | | const CSimpleIniA& ini) const; |
| | | const LicenseLocation licenseLocation; |
| | | EventRegistry getLicenseDiskFiles(vector<string>& diskFiles); |
| | | vector<string> filterExistingFiles(vector<string> licensePositions); |
| | |
| | | * @param license[out] optional, can be NULL. |
| | | */ |
| | | |
| | | DllExport EVENT_TYPE acquire_license(char * productName, |
| | | DllExport EVENT_TYPE acquire_license(const char * productName, |
| | | LicenseLocation licenseLocation, LicenseInfo* license); |
| | | |
| | | /** |
| | |
| | | #include "StringUtils.h" |
| | | #include <iostream> |
| | | #include <string> |
| | | #include <cstring> |
| | | #include <algorithm> |
| | | |
| | | namespace license { |
| | |
| | | |
| | | string toupper_copy(const string& lowercase) { |
| | | string cp(lowercase); |
| | | std::transform(cp.begin(), cp.end(), cp.begin(), (int(*)(int))toupper); |
| | | std::transform(cp.begin(), cp.end(), cp.begin(), (int (*)(int))toupper); |
| | | return cp; |
| | | } |
| | | |
| | | time_t seconds_from_epoch(const char* timeString) { |
| | | int year, month, day; |
| | | tm tm; |
| | | if (strlen(timeString) == 8) { |
| | | int nfield = sscanf(timeString, "%4d%2d%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | | } else if (strlen(timeString) == 10) { |
| | | int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | int nfield = sscanf(timeString, "%4d/%2d/%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | | } |
| | | } else{ |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | | tm.tm_isdst = -1; |
| | | tm.tm_year = year - 1900; |
| | | tm.tm_mon = month - 1; |
| | | tm.tm_mday = day; |
| | | tm.tm_hour = 0; |
| | | tm.tm_min = 0; |
| | | tm.tm_sec = 0; |
| | | tm.tm_yday = -1; |
| | | tm.tm_wday = -1; |
| | | return mktime(&tm); |
| | | } |
| | | } /* namespace license */ |
| | |
| | | |
| | | string toupper_copy(const string& lowercase); |
| | | |
| | | time_t seconds_from_epoch(const char* s); |
| | | } /* namespace license */ |
| | | |
| | | #endif /* STRINGUTILS_H_ */ |
New file |
| | |
| | | |
| | | ADD_LIBRARY(ini STATIC |
| | | ConvertUTF.c |
| | | ) |
| | | |
| | | target_link_libraries( |
| | | ini |
| | | ) |
| | | |
| | |
| | | #include <stdlib.h> |
| | | #include <cstring> |
| | | #include "api/license++.h" |
| | | #include "reader/LicenseReader.h" |
| | | #include "LicenseReader.h" |
| | | |
| | | using namespace std; |
| | | DllExport void print_error(char out_buffer[256], LicenseInfo* licenseInfo) { |
| | |
| | | } |
| | | } |
| | | |
| | | EVENT_TYPE acquire_license(char * product, LicenseLocation licenseLocation, |
| | | LicenseInfo* license) { |
| | | EVENT_TYPE acquire_license(const char * product, |
| | | LicenseLocation licenseLocation, LicenseInfo* license) { |
| | | license::LicenseReader lr = license::LicenseReader(licenseLocation); |
| | | vector<license::FullLicenseInfo> licenses; |
| | | license::EventRegistry er = lr.readLicenses(string(product), licenses); |
| | |
| | | vector<license::FullLicenseInfo> licenses_ok; |
| | | for (auto it = licenses.begin(); it != licenses.end(); it++) { |
| | | license::EventRegistry validation_er = it->validate(0); |
| | | if (er.isGood()) { |
| | | if (validation_er.isGood()) { |
| | | licenses_ok.push_back(*it); |
| | | } else { |
| | | licenses_with_errors.push_back(*it); |
| | |
| | | #ifndef LICENSESIGNER_H_ |
| | | #define LICENSESIGNER_H_ |
| | | |
| | | #include "../library/reader/LicenseReader.h" |
| | | #include "../library/LicenseReader.h" |
| | | |
| | | namespace license { |
| | | |
| | |
| | | #include <build_properties.h> |
| | | #include "LicenseSigner.h" |
| | | #include "license-generator.h" |
| | | #include "../library/base/StringUtils.h" |
| | | #include <stdlib.h> |
| | | #include <stdio.h> |
| | | #include <iostream> |
| | |
| | | if (vm.count("end_date")) { |
| | | const std::string dt_end = vm["end_date"].as<string>(); |
| | | try { |
| | | end_date = seconds_from_epoch(dt_end); |
| | | end_date = seconds_from_epoch(dt_end.c_str()); |
| | | begin_date = time(NULL); |
| | | } catch (invalid_argument &e) { |
| | | cerr << endl << "End date not recognized: " << dt_end |
| | |
| | | if (vm.count("begin_date")) { |
| | | const std::string begin_date_str = vm["begin_date"].as<string>(); |
| | | try { |
| | | begin_date = seconds_from_epoch(begin_date_str); |
| | | begin_date = seconds_from_epoch(begin_date_str.c_str()); |
| | | } catch (invalid_argument &e) { |
| | | cerr << endl << "Begin date not recognized: " << begin_date_str |
| | | << " Please enter a valid date in format YYYYMMDD" << endl; |
| | |
| | | if (vm.count("extra_data")) { |
| | | extra_data = vm["extra_data"].as<string>(); |
| | | } |
| | | unsigned int from_sw_version = end_date = vm["start_version"].as< |
| | | unsigned int from_sw_version = vm["start_version"].as< |
| | | unsigned int>(); |
| | | unsigned int to_sw_version = end_date = |
| | | unsigned int to_sw_version = |
| | | vm["end_version"].as<unsigned int>(); |
| | | if (vm.count("product") == 0) { |
| | | cerr << endl << "Parameter [product] not found. " << endl; |
| | |
| | | return 0; |
| | | } |
| | | |
| | | const std::locale formats[] = { std::locale(std::locale::classic(), |
| | | new bt::time_input_facet("%Y-%m-%d")), // |
| | | std::locale(std::locale::classic(), new bt::time_input_facet("%Y/%m/%d")), // |
| | | std::locale(std::locale::classic(), new bt::time_input_facet("%Y%m%d")) }; |
| | | const size_t formats_n = sizeof(formats) / sizeof(formats[0]); |
| | | |
| | | time_t LicenseGenerator::seconds_from_epoch(const std::string& s) { |
| | | bt::ptime pt; |
| | | for (size_t i = 0; i < formats_n; ++i) { |
| | | std::istringstream is(s); |
| | | is.imbue(formats[i]); |
| | | is >> pt; |
| | | if (pt != bt::ptime()) { |
| | | break; |
| | | } |
| | | } |
| | | if (pt == bt::ptime()) { |
| | | throw invalid_argument(string("Date not regognized") + s); |
| | | } |
| | | bt::ptime timet_start(boost::gregorian::date(1970, 1, 1)); |
| | | bt::time_duration diff = pt - timet_start; |
| | | return diff.ticks() / bt::time_duration::rep_type::ticks_per_second; |
| | | } |
| | | |
| | | } |
| | |
| | | #define LICENSE_GENERATOR_H_ |
| | | |
| | | #include <boost/program_options.hpp> |
| | | #include "../library/reader/LicenseReader.h" |
| | | #include "../library/LicenseReader.h" |
| | | |
| | | namespace license { |
| | | |
| | |
| | | LicenseGenerator(); |
| | | static void printHelp(const char* prog_name, const po::options_description& options); |
| | | static po::options_description configureProgramOptions(); |
| | | static time_t seconds_from_epoch(const std::string& s); |
| | | static vector<FullLicenseInfo> parseLicenseInfo(po::variables_map vm); |
| | | static void generateAndOutptuLicenses(const po::variables_map& vm, |
| | | ostream& outputFile); |
| | |
| | | ADD_LIBRARY(license_generator_snippet STATIC |
| | | generate-license.cpp |
| | | ) |
| | | target_link_libraries( |
| | | license_generator_snippet |
| | | license_generator_lib |
| | | ) |
| | | |
| | | add_executable( |
| | | standard_license_test |
| | | standard-license_test.cpp |
| | | ) |
| | | |
| | | target_link_libraries( |
| | | standard_license_test |
| | | license++_static |
| | | license_generator_lib |
| | | license_generator_snippet |
| | | ) |
| | | |
| | | SET_TARGET_PROPERTIES(standard_license_test PROPERTIES LINK_SEARCH_START_STATIC ON) |
| | | |
| | | add_executable( |
| | | date_test |
| | | date_test.cpp |
| | | ) |
| | | target_link_libraries( |
| | | date_test |
| | | license++_static |
| | | license_generator_snippet |
| | | ) |
| | | SET_TARGET_PROPERTIES(date_test PROPERTIES LINK_SEARCH_START_STATIC ON) |
| | | |
| | | ADD_TEST(standard_license_test ${EXECUTABLE_OUTPUT_PATH}/standard_license_test) |
| | | ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/date_test) |
| | |
| | | #include "../../../src/library/api/license++.h" |
| | | #include <build_properties.h> |
| | | #include <boost/filesystem.hpp> |
| | | #include "../../src/library/reader/SimpleIni.h" |
| | | |
| | | #include "../../src/library/ini/SimpleIni.h" |
| | | #include "generate-license.h" |
| | | |
| | | namespace fs = boost::filesystem; |
| | | using namespace license; |
| | | using namespace std; |
| | | |
| | | void generate_license(const string& prod_name, const string& fname) { |
| | | int argc = 4; |
| | | const char** argv = new const char*[argc + 1]; |
| | | argv[0] = "lic-generator"; |
| | | argv[1] = "-o"; |
| | | argv[2] = fname.c_str(); |
| | | argv[3] = "test"; |
| | | int retCode = LicenseGenerator::generateLicense(argc, argv); |
| | | delete (argv); |
| | | BOOST_CHECK_EQUAL(retCode, 0); |
| | | BOOST_ASSERT(fs::exists(fname)); |
| | | CSimpleIniA ini; |
| | | SI_Error rc = ini.LoadFile(fname.c_str()); |
| | | BOOST_CHECK_GE(rc,0); |
| | | int sectionSize = ini.GetSectionSize(prod_name.c_str()); |
| | | BOOST_CHECK_GT(sectionSize,0); |
| | | } |
| | | |
| | | BOOST_AUTO_TEST_CASE( standard_lic_file ) { |
| | | const string licLocation(PROJECT_TEST_TEMP_DIR "/standard_license.lic"); |
| | | generate_license(string("TEST"), licLocation); |
| | | vector<string> extraArgs; |
| | | generate_license(licLocation, extraArgs); |
| | | /* */ |
| | | LicenseInfo license; |
| | | LicenseLocation licenseLocation; |
| | |
| | | BOOST_CHECK_EQUAL(license.linked_to_pc, false); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | add_subdirectory(reader) |
| | | link_directories ( ${Boost_LIBRARY_DIRS} ) |
| | | |
| | | add_executable( |
| | | license_reader_test |
| | | LicenseReader_test.cpp |
| | | ) |
| | | |
| | | target_link_libraries( |
| | | license_reader_test |
| | | license++_static |
| | | ${Boost_LIBRARIES} |
| | | ) |
| | | |
| | | SET_TARGET_PROPERTIES(license_reader_test PROPERTIES LINK_SEARCH_START_STATIC ON) |
| | | ADD_TEST(license_reader_test ${EXECUTABLE_OUTPUT_PATH}/LicenseReader_test) |
File was renamed from test/library/reader/LicenseReader_test.cpp |
| | |
| | | //#define BOOST_TEST_MAIN |
| | | #define BOOST_TEST_DYN_LINK |
| | | #include <boost/test/unit_test.hpp> |
| | | #include "../../../src/library/reader/LicenseReader.h" |
| | | #include "../../src/library/LicenseReader.h" |
| | | #include <build_properties.h> |
| | | |
| | | using namespace license; |
| | |
| | | #include "../../../src/license-generator/license-generator.h" |
| | | #include <build_properties.h> |
| | | #include <boost/filesystem.hpp> |
| | | #include "../../src/library/reader/SimpleIni.h" |
| | | #include "../../src/library/ini/SimpleIni.h" |
| | | |
| | | namespace fs = boost::filesystem; |
| | | using namespace license; |