diff --git a/api/HTTPClient.h b/api/HTTPClient.h index 7d78bba..86342ad 100644 --- a/api/HTTPClient.h +++ b/api/HTTPClient.h @@ -18,7 +18,7 @@ public: HTTPClient(); public: - void get(const std::string& url, std::ostream& dstStream) throw (CouldNotConnectException); - void postJson(const std::string& url, std::istream& json, size_t length, std::ostream& dstStream) throw (CouldNotConnectException); - void postJson(const std::string& url, const std::string& json, std::ostream& dstStream) throw (CouldNotConnectException); + void get(const std::string& url, std::ostream& dstStream); + void postJson(const std::string& url, std::istream& json, size_t length, std::ostream& dstStream); + void postJson(const std::string& url, const std::string& json, std::ostream& dstStream); }; diff --git a/api/IModuleDatabase.h b/api/IModuleDatabase.h index 5b234a2..5c95577 100644 --- a/api/IModuleDatabase.h +++ b/api/IModuleDatabase.h @@ -22,6 +22,6 @@ public: virtual boost::optional findModule(const std::string& moduleId) = 0; virtual void storeModule(const Module& module) = 0; -protected: - ~IModuleDatabase() {} +public: + virtual ~IModuleDatabase() {} }; diff --git a/api/LicenseClient.h b/api/LicenseClient.h index cfcd5a3..e85b012 100644 --- a/api/LicenseClient.h +++ b/api/LicenseClient.h @@ -27,6 +27,7 @@ public: public: void init(); bool isActivated() const { return m_activationData.has_value(); } + std::optional activationNumber() const { return m_activationData.has_value() ? m_activationData->activationId : std::optional(); } bool tryPreactivate(HTTPClient &httpClient); bool activate(HTTPClient &httpClient, const std::string& licenseNumber ); auto licensedModules() { if (!isActivated()) { throw std::runtime_error("Not active"); } return m_activationData->licensedModules; } diff --git a/libLicenseClient.vcxproj b/libLicenseClient.vcxproj index dce4c93..e8cf53a 100644 --- a/libLicenseClient.vcxproj +++ b/libLicenseClient.vcxproj @@ -9,14 +9,6 @@ Release Win32 - - Debug - x64 - - - Release - x64 - 15.0 @@ -39,19 +31,6 @@ true MultiByte - - StaticLibrary - true - v141 - MultiByte - - - StaticLibrary - false - v141 - true - MultiByte - @@ -65,27 +44,13 @@ - - - - - - - - true - - true - false - - false - NotUsing @@ -101,21 +66,6 @@ true - - - NotUsing - Level3 - Disabled - true - _DEBUG;_LIB;%(PreprocessorDefinitions) - true - stdcpplatest - - - Windows - true - - NotUsing @@ -128,7 +78,6 @@ true stdcpplatest false - false None @@ -142,25 +91,6 @@ false - - - NotUsing - Level3 - MaxSpeed - true - true - true - NDEBUG;_LIB;%(PreprocessorDefinitions) - true - stdcpplatest - - - Windows - true - true - true - - diff --git a/project-common.props b/project-common.props index 99026f2..d764253 100644 --- a/project-common.props +++ b/project-common.props @@ -11,7 +11,7 @@ $(ProjectDir)api;%(AdditionalIncludeDirectories) - BOOST_EXCEPTION_DISABLE;%(PreprocessorDefinitions) + BOOST_EXCEPTION_DISABLE;%(PreprocessorDefinitions) %(AdditionalOptions) diff --git a/src/HTTPClient.cpp b/src/HTTPClient.cpp index 3eee61c..f723318 100644 --- a/src/HTTPClient.cpp +++ b/src/HTTPClient.cpp @@ -13,8 +13,6 @@ namespace void dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) { - size_t i; - size_t c; unsigned int width = 0x10; fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n", @@ -22,25 +20,6 @@ namespace fwrite(ptr, 1, size, stream); fputc('\n', stream); // newline -/* for (i = 0; i= 0x20 && ptr[i + c] < 0x80) ? ptr[i + c] : '.'; - fputc(x, stream); - } - - fputc('\n', stream); // newline - } */ } static @@ -92,7 +71,7 @@ static size_t reader(char *ptr, size_t size, size_t nmemb, std::istream *is) totalRead = is->gcount(); } - return totalRead; + return static_cast(totalRead); } static int writer(char *data, size_t size, size_t nmemb, std::ostream *os) @@ -195,8 +174,14 @@ DownloadSession initCurlRequest(const std::string& url, std::ostream &os) throw std::runtime_error(oss.str()); } - // DEBUG: +#ifndef NDEBUG code = curl_easy_setopt(conn.get(), CURLOPT_DEBUGFUNCTION, my_trace); + if (code != CURLE_OK) + { + std::ostringstream oss; + oss << "Failed to set debug function"; + throw std::runtime_error(oss.str()); + } code = curl_easy_setopt(conn.get(), CURLOPT_VERBOSE, 1); if (code != CURLE_OK) { @@ -204,6 +189,7 @@ DownloadSession initCurlRequest(const std::string& url, std::ostream &os) oss << "Failed to set verbose mode"; throw std::runtime_error(oss.str()); } +#endif // !NDEBUG result.conn = std::move(conn); diff --git a/src/SystemParamsProvider_win.cpp b/src/SystemParamsProvider_win.cpp index d5b6663..356e796 100644 --- a/src/SystemParamsProvider_win.cpp +++ b/src/SystemParamsProvider_win.cpp @@ -176,6 +176,40 @@ namespace const Fields_type m_fields; std::promise m_resultPromise; }; + + void initializeCOM() + { + // We need to initialize COM for SystemParamsProvider + HRESULT hres = 0; + + // Initialize COM. ------------------------------------------ + hres = CoInitializeEx(0, COINIT_MULTITHREADED); + if (FAILED(hres)) + { + std::ostringstream ostr; + ostr << "Failed to initialize COM library. Error code = 0x" << std::hex << hres; + throw std::runtime_error(ostr.str()); + } + + // Set general COM security levels -------------------------- + hres = CoInitializeSecurity(NULL, + -1, // COM authentication + NULL, // Authentication services + NULL, // Reserved + RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication + RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation + NULL, // Authentication info + EOAC_NONE, // Additional capabilities + NULL); // Reserved + + if (FAILED(hres) && hres != RPC_E_TOO_LATE) // Ignore error if the security has already been initialized + { + CoUninitialize(); + std::ostringstream ostr; + ostr << "Failed to initialize security. Error code = 0x" << std::hex << hres; + throw std::runtime_error(ostr.str()); + } + } } namespace detail @@ -187,33 +221,7 @@ namespace detail { HRESULT hres = 0; - // Initialize COM. ------------------------------------------ - hres = CoInitializeEx(0, COINIT_MULTITHREADED); - if (FAILED(hres)) - { - std::ostringstream ostr; - ostr << "Failed to initialize COM library. Error code = 0x" << std::hex << hres; - throw std::runtime_error(ostr.str()); - } - - // Set general COM security levels -------------------------- - hres = CoInitializeSecurity(NULL, - -1, // COM authentication - NULL, // Authentication services - NULL, // Reserved - RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication - RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation - NULL, // Authentication info - EOAC_NONE, // Additional capabilities - NULL); // Reserved - - if (FAILED(hres)) - { - CoUninitialize(); - std::ostringstream ostr; - ostr << "Failed to initialize security. Error code = 0x" << std::hex << hres; - throw std::runtime_error(ostr.str()); - } + initializeCOM(); // Obtain the initial locator to WMI ------------------------- hres = CoCreateInstance( diff --git a/test/libLicenseClientTest.vcxproj b/test/libLicenseClientTest.vcxproj index 1c4c6bd..f09632d 100644 --- a/test/libLicenseClientTest.vcxproj +++ b/test/libLicenseClientTest.vcxproj @@ -65,6 +65,9 @@ + + +