| | |
| | | namespace locate { |
| | | using namespace std; |
| | | |
| | | ExternalDefinition::ExternalDefinition(const LicenseLocation *location) : |
| | | LocatorStrategy("ExternalDefinition"), m_location(location) { |
| | | } |
| | | ExternalDefinition::ExternalDefinition(const LicenseLocation *location) |
| | | : LocatorStrategy("ExternalDefinition"), m_location(location) {} |
| | | |
| | | ExternalDefinition::~ExternalDefinition() { |
| | | } |
| | | ExternalDefinition::~ExternalDefinition() {} |
| | | |
| | | const std::vector<std::string> ExternalDefinition::license_locations( |
| | | EventRegistry &eventRegistry) { |
| | | const std::vector<std::string> ExternalDefinition::license_locations(EventRegistry &eventRegistry) { |
| | | vector<string> existing_pos; |
| | | if (m_location->licenseData != nullptr |
| | | && m_location->licenseData[0] != '\0') { |
| | | if (m_location->licenseData[0] != '\0') { |
| | | eventRegistry.addEvent(LICENSE_SPECIFIED, get_strategy_name()); |
| | | FILE_FORMAT licenseFormat = identify_format(m_location->licenseData); |
| | | |
| | | if (licenseFormat == UNKNOWN) { |
| | | eventRegistry.addEvent(LICENSE_MALFORMED, get_strategy_name()); |
| | | } else { |
| | | existing_pos.push_back(get_strategy_name()); |
| | | licenseDataIsBase64 = (licenseFormat == BASE64); |
| | | switch (m_location->license_data_type) { |
| | | case LICENSE_PATH: { |
| | | string licData(m_location->licenseData, mstrnlen_s(m_location->licenseData, API_LICENSE_DATA_LENGTH)); |
| | | const vector<string> declared_positions = license::split_string(licData, ';'); |
| | | existing_pos = |
| | | license::filter_existing_files(declared_positions, eventRegistry, get_strategy_name().c_str()); |
| | | } break; |
| | | case LICENSE_ENCODED: |
| | | case LICENSE_PLAIN_DATA: |
| | | existing_pos.push_back(get_strategy_name()); |
| | | break; |
| | | default: |
| | | throw logic_error("license type not supported "); |
| | | } |
| | | } |
| | | if (m_location->licenseFileLocation != nullptr |
| | | && strlen(m_location->licenseFileLocation) > 0) { |
| | | const vector<string> declared_positions = license::split_string( |
| | | m_location->licenseFileLocation, ';'); |
| | | existing_pos = license::filter_existing_files(declared_positions, |
| | | eventRegistry, get_strategy_name().c_str()); |
| | | } |
| | | return existing_pos; |
| | | } |
| | | |
| | | const std::string ExternalDefinition::retrieve_license_content( |
| | | const std::string &licenseLocation) const { |
| | | const std::string ExternalDefinition::retrieve_license_content(const std::string &licenseLocation) const { |
| | | if (licenseLocation == get_strategy_name()) { |
| | | if (licenseDataIsBase64) { |
| | | string licData(m_location->licenseData, mstrnlen_s(m_location->licenseData, API_LICENSE_DATA_LENGTH)); |
| | | if (m_location->license_data_type == LICENSE_ENCODED) { |
| | | int flen = 0; |
| | | unsigned char *raw = unbase64(m_location->licenseData, |
| | | strlen(m_location->licenseData), &flen); |
| | | string str = string(reinterpret_cast<char*>(raw)); |
| | | unsigned char *raw = unbase64(licData.c_str(), licData.length(), &flen); |
| | | string str = string(reinterpret_cast<char *>(raw)); |
| | | free(raw); |
| | | return str; |
| | | } else { |
| | | return m_location->licenseData; |
| | | return licData; |
| | | } |
| | | } else { |
| | | return LocatorStrategy::retrieve_license_content(licenseLocation); |