From c536a979f5a213188ac54f5669ddf4b4ff48c218 Mon Sep 17 00:00:00 2001
From: Gabriele Contini <contini.mailing@gmail.com>
Date: 周六, 07 9月 2019 22:13:32 +0800
Subject: [PATCH] Merge branch 'master' of https://github.com/open-license-manager/open-license-manager.git

---
 src/library/base/EventRegistry.cpp                |    2 +-
 src/library/LicenseReader.cpp                     |   18 +++++++++---------
 src/tools/license-generator/license-generator.cpp |    2 +-
 test/library/LicenseReader_test.cpp               |   10 +++++-----
 src/library/license++.cpp                         |    4 ++--
 src/tools/base_lib/win/CryptoHelperWindows.cpp    |   16 ++++++++--------
 CMakeLists.txt                                    |    4 +++-
 src/tools/bootstrap/bootstrap.cpp                 |    4 ++--
 8 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3cd2071..d8f75ac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,7 +96,9 @@
 	    include_directories(${DBUS_ARCH_INCLUDE_DIR})
 	    list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES})
 	endif(USE_DBUS_IDENTIFIER)    
-	list(APPEND EXTERNAL_LIBS dl)
+	if(NOT MINGW)
+	    list(APPEND EXTERNAL_LIBS dl)
+	endif(NOT MINGW)
 	list(APPEND EXTERNAL_LIBS "-Wl,-Bdynamic")
 endif(NOT MSVC)
 
diff --git a/src/library/LicenseReader.cpp b/src/library/LicenseReader.cpp
index 5ec8623..9927426 100644
--- a/src/library/LicenseReader.cpp
+++ b/src/library/LicenseReader.cpp
@@ -60,7 +60,7 @@
 		er.addEvent(LICENSE_CORRUPTED, SVRT_ERROR);
 	}
 	if (has_expiry) {
-		const time_t now = time(NULL);
+		const time_t now = time(nullptr);
 		if (expires_on() < now) {
 			er.addEvent(PRODUCT_EXPIRED, SVRT_ERROR, "");
 		}
@@ -80,7 +80,7 @@
 }
 
 void FullLicenseInfo::toLicenseInfo(LicenseInfo* license) const {
-	if (license != NULL) {
+	if (license != nullptr) {
 		strncpy(license->proprietary_data, extra_data.c_str(),
 		PROPRIETARY_DATA_SIZE);
 
@@ -93,7 +93,7 @@
 			strncpy(license->expiry_date, to_date.c_str(), 11);
 			const double secs = difftime(
 				seconds_from_epoch(to_date.c_str()),
-				time(NULL));
+				time(nullptr));
 			license->days_left = round(secs / (60 * 60 * 24));
 		}
 	}
@@ -141,10 +141,10 @@
 		 *  application_data = xxxxxxxxx (optional string 16)
 		 */
 		const char * license_signature = ini.GetValue(productNamePtr,
-				"license_signature", NULL);
-		const long license_version = ini.GetLongValue(productNamePtr,
+				"license_signature", nullptr);
+		long license_version = ini.GetLongValue(productNamePtr,
 				"license_version", -1);
-		if (license_signature != NULL && license_version > 0) {
+		if (license_signature != nullptr && license_version > 0) {
 			const string from_date = trim_copy(
 					ini.GetValue(productNamePtr, "from_date",
 							FullLicenseInfo::UNUSED_TIME));
@@ -188,7 +188,7 @@
 		EventRegistry& eventRegistry) {
 //bool hasFileLocation = false;
 	bool licenseFoundWithExplicitLocation = false;
-	if (licenseLocation.licenseFileLocation != NULL
+	if (licenseLocation.licenseFileLocation != nullptr
 			&& licenseLocation.licenseFileLocation[0] != '\0') {
 		//hasFileLocation = true;
 		const string varName(licenseLocation.licenseFileLocation);
@@ -213,13 +213,13 @@
 bool LicenseReader::findFileWithEnvironmentVariable(vector<string>& diskFiles,
 		EventRegistry& eventRegistry) {
 	bool licenseFileFoundWithEnvVariable = false;
-	if (licenseLocation.environmentVariableName != NULL
+	if (licenseLocation.environmentVariableName != nullptr
 			&& licenseLocation.environmentVariableName[0] != '\0') {
 		const string varName(licenseLocation.environmentVariableName);
 		if (varName.length() > 0) {
 			//var name is passed in by the calling application.
 			char* env_var_value = getenv(varName.c_str());
-			if (env_var_value != NULL && env_var_value[0] != '\0') {
+			if (env_var_value != nullptr && env_var_value[0] != '\0') {
 				const vector<string> declared_positions = splitLicensePositions(
 						string(env_var_value));
 				vector<string> existing_pos = filterExistingFiles(
diff --git a/src/library/base/EventRegistry.cpp b/src/library/base/EventRegistry.cpp
index 7c21d6f..cd3c58f 100644
--- a/src/library/base/EventRegistry.cpp
+++ b/src/library/base/EventRegistry.cpp
@@ -51,7 +51,7 @@
 }
 
 AuditEvent const * EventRegistry::getLastFailure() const {
-	const AuditEvent* result = NULL;
+	const AuditEvent* result = nullptr;
 	if (logs.size() == 0) {
 		return result;
 	}
diff --git a/src/library/license++.cpp b/src/library/license++.cpp
index fd07af8..f9cc7c7 100644
--- a/src/library/license++.cpp
+++ b/src/library/license++.cpp
@@ -23,7 +23,7 @@
 
 static void mergeLicenses(vector<license::FullLicenseInfo> licenses,
 		LicenseInfo* license) {
-	if (license != NULL) {
+	if (license != nullptr) {
 		time_t curLicense_exp = 0;
 		for (auto it = licenses.begin(); it != licenses.end(); it++) {
 			//choose the license that expires later...
@@ -68,7 +68,7 @@
 	} else {
 		result = er.getLastFailure()->event_type;
 	}
-	if (license != NULL) {
+	if (license != nullptr) {
 		er.exportLastEvents(license->status, 5);
 	}
 	return result;
diff --git a/src/tools/base_lib/win/CryptoHelperWindows.cpp b/src/tools/base_lib/win/CryptoHelperWindows.cpp
index 4cdb31d..7bf0ffb 100644
--- a/src/tools/base_lib/win/CryptoHelperWindows.cpp
+++ b/src/tools/base_lib/win/CryptoHelperWindows.cpp
@@ -73,7 +73,7 @@
 	HRESULT hr = S_OK;
 	DWORD dwErrCode;
 	DWORD dwBlobLen;
-	BYTE *pbKeyBlob = NULL;
+	BYTE *pbKeyBlob = nullptr;
 	stringstream ss;
 	// If the handle to key container is NULL, fail.
 	if (m_hCryptKey == NULL)
@@ -82,14 +82,14 @@
 	// blob.
 	if (!CryptExportKey(m_hCryptKey,
 	NULL, PUBLICKEYBLOB, 0,
-	NULL, &dwBlobLen)) {
+	nullptr, &dwBlobLen)) {
 		dwErrCode = GetLastError();
 		throw logic_error(
 				string("Error calculating size of public key ")
 						+ to_string(static_cast<long long>(dwErrCode)));
 	}
 	// Allocate memory for the pbKeyBlob.
-	if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
+	if ((pbKeyBlob = new BYTE[dwBlobLen]) == nullptr) {
 		throw logic_error(string("Out of memory exporting public key "));
 	}
 	// Do the actual exporting into the key BLOB.
@@ -142,14 +142,14 @@
 	// blob.
 	if (!CryptExportKey(m_hCryptKey,
 	NULL, PRIVATEKEYBLOB, 0,
-	NULL, &dwBlobLen)) {
+	nullptr, &dwBlobLen)) {
 		dwErrCode = GetLastError();
 		throw logic_error(
 				string("Error calculating size of private key ")
 						+ to_string(static_cast<long long>(dwErrCode)));
 	}
 	// Allocate memory for the pbKeyBlob.
-	if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
+	if ((pbKeyBlob = new BYTE[dwBlobLen]) == nullptr) {
 		throw logic_error(string("Out of memory exporting private key "));
 	}
 
@@ -243,7 +243,7 @@
 	// Determine the size of the signature and allocate memory.
 
 	dwSigLen = 0;
-	if (CryptSignHash(hHash, AT_SIGNATURE, NULL, 0, NULL, &dwSigLen)) {
+	if (CryptSignHash(hHash, AT_SIGNATURE, nullptr, 0, nullptr, &dwSigLen)) {
 		printf("Signature length %d found.\n", dwSigLen);
 	} else {
 		throw logic_error(string("Error during CryptSignHash."));
@@ -260,7 +260,7 @@
 	// Sign the hash object.
 
 	if (CryptSignHash(hHash, AT_SIGNATURE,
-	NULL, 0, pbSignature, &dwSigLen)) {
+	nullptr, 0, pbSignature, &dwSigLen)) {
 		printf("pbSignature is the signature length. %d\n", dwSigLen);
 	} else {
 		throw logic_error(string("Error during CryptSignHash."));
@@ -272,7 +272,7 @@
 	CryptDestroyKey(hKey);
 
 	CryptBinaryToString(pbSignature, dwSigLen,
-			CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &strLen);
+			CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &strLen);
 	vector<char> buffer(strLen);
 	CryptBinaryToString(pbSignature, dwSigLen,
 			CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, &buffer[0], &strLen);
diff --git a/src/tools/bootstrap/bootstrap.cpp b/src/tools/bootstrap/bootstrap.cpp
index 98ad6b0..e3647de 100644
--- a/src/tools/bootstrap/bootstrap.cpp
+++ b/src/tools/bootstrap/bootstrap.cpp
@@ -10,7 +10,7 @@
 
 void write_pubkey_file(const string& public_fname, const string& pbPublicKey) {
 	FILE* fp = fopen(public_fname.c_str(), "w");
-	if (fp == NULL) {
+	if (fp == nullptr) {
 		throw ios_base::failure(string("can't create :") + public_fname);
 	}
 	fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n");
@@ -26,7 +26,7 @@
 
 void write_privkey_file(const string& private_fname, const string& privateKey) {
 	FILE* fp = fopen(private_fname.c_str(), "w");
-	if (fp == NULL) {
+	if (fp == nullptr) {
 		throw ios_base::failure(string("can't create :") + private_fname);
 	}
 	fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n");
diff --git a/src/tools/license-generator/license-generator.cpp b/src/tools/license-generator/license-generator.cpp
index ab3b716..a2b70e5 100644
--- a/src/tools/license-generator/license-generator.cpp
+++ b/src/tools/license-generator/license-generator.cpp
@@ -84,7 +84,7 @@
 		try {
 			end_date = normalize_date(dt_end);
 			char curdate[20];
-			time_t curtime = time(NULL);
+			time_t curtime = time(nullptr);
 			strftime(curdate, 20, "%Y-%m-%d", localtime(&curtime));
 			begin_date.assign(curdate);
 		} catch (const invalid_argument &e) {
diff --git a/test/library/LicenseReader_test.cpp b/test/library/LicenseReader_test.cpp
index 193f0f8..6fa4f59 100644
--- a/test/library/LicenseReader_test.cpp
+++ b/test/library/LicenseReader_test.cpp
@@ -11,7 +11,7 @@
 BOOST_AUTO_TEST_CASE( read_single_file ) {
 	const char * licLocation =
 	PROJECT_TEST_SRC_DIR "/library/test_reader.ini";
-	const LicenseLocation location = { licLocation, NULL, false };
+	const LicenseLocation location = { licLocation, nullptr, false };
 	LicenseReader licenseReader(location);
 	vector<FullLicenseInfo> licenseInfos;
 	const EventRegistry registry = licenseReader.readLicenses("PrODUCT",
@@ -23,7 +23,7 @@
 BOOST_AUTO_TEST_CASE( product_not_licensed ) {
 	const char * licLocation =
 	PROJECT_TEST_SRC_DIR "/library/test_reader.ini";
-	const LicenseLocation location = { licLocation, NULL, false };
+	const LicenseLocation location = { licLocation, nullptr, false };
 	LicenseReader licenseReader(location);
 	vector<FullLicenseInfo> licenseInfos;
 	const EventRegistry registry = licenseReader.readLicenses("PRODUCT-NOT",
@@ -38,7 +38,7 @@
 BOOST_AUTO_TEST_CASE( file_not_found ) {
 	const char * licLocation = PROJECT_TEST_SRC_DIR "/library/not_found.ini";
 	//const char * envName = "MYVAR";
-	const LicenseLocation location = { licLocation, NULL, false };
+	const LicenseLocation location = { licLocation, nullptr, false };
 	LicenseReader licenseReader(location);
 	vector<FullLicenseInfo> licenseInfos;
 	const EventRegistry registry = licenseReader.readLicenses("PRODUCT",
@@ -52,7 +52,7 @@
 
 BOOST_AUTO_TEST_CASE( env_var_not_defined ) {
 	const char * envName = "MYVAR";
-	const LicenseLocation location = { NULL, envName, false };
+	const LicenseLocation location = {nullptr, envName, false };
 	LicenseReader licenseReader(location);
 	vector<FullLicenseInfo> licenseInfos;
 	const EventRegistry registry = licenseReader.readLicenses("PRODUCT",
@@ -68,7 +68,7 @@
 	char str[MAX_PATH];
 	strcpy(str,"LIC_VAR=" PROJECT_TEST_SRC_DIR "/library/test_reader.ini");
 	putenv(str);
-	const LicenseLocation location = { NULL, "LIC_VAR", false };
+	const LicenseLocation location = {nullptr, "LIC_VAR", false };
 	LicenseReader licenseReader(location);
 	vector<FullLicenseInfo> licenseInfos;
 	const EventRegistry registry = licenseReader.readLicenses("PrODUCT",

--
Gitblit v1.9.1