From 2695752f624aa7dc3f91672c6fbeb894c22eaa47 Mon Sep 17 00:00:00 2001
From: Gabriele Contini <contini.mailing@gmail.com>
Date: 周六, 11 1月 2020 15:24:46 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/develop' into feature/pc_identifiers

---
 src/library/limits/license_verifier.cpp    |    2 +-
 src/library/licensecc.cpp                  |    8 ++++----
 src/inspector/inspector.cpp                |    4 ++--
 include/licensecc/datatypes.h              |   27 ++++++++++++++++-----------
 include/licensecc/licensecc.h              |   15 +++++++--------
 src/library/pc_identifier/pc-identifiers.h |    2 +-
 6 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/include/licensecc/datatypes.h b/include/licensecc/datatypes.h
index 6f6760c..3355876 100644
--- a/include/licensecc/datatypes.h
+++ b/include/licensecc/datatypes.h
@@ -22,12 +22,17 @@
 #define DllExport __declspec(dllexport)
 #endif
 
-// define api structure sizes
-#define PC_IDENTIFIER_SIZE 19
-#define PROPRIETARY_DATA_SIZE 16
-#define AUDIT_EVENT_NUM 5
 #define API_LICENSE_DATA_LENGTH 1024 * 4
-#define API_VERSION_LENGTH 16
+
+// define api structure sizes
+#define API_PC_IDENTIFIER_SIZE 19
+#define API_PROPRIETARY_DATA_SIZE 16
+#define API_AUDIT_EVENT_NUM 5
+#define API_AUDIT_EVENT_PARAM2 255
+#define API_VERSION_LENGTH 15
+#define API_PROJECT_NAME_SIZE 15
+#define API_EXPIRY_DATE_SIZE 10
+#define API_ERROR_BUFFER_SIZE 256
 
 typedef enum {
 	LICENSE_OK = 0,  // OK
@@ -61,7 +66,7 @@
 	 * License file name or location where the license is stored.
 	 */
 	char license_reference[MAX_PATH];
-	char param2[256];
+	char param2[API_AUDIT_EVENT_PARAM2 + 1];
 } AuditEvent;
 
 typedef enum {
@@ -96,8 +101,8 @@
  * Informations on the software requiring the license
  */
 typedef struct {
-	char version[API_VERSION_LENGTH];  // software version in format xxxx[.xxxx.xxxx] //TODO
-	char project_name[16];  // name of the project (must correspond to the name in the license)
+	char version[API_VERSION_LENGTH + 1];  // software version in format xxxx[.xxxx.xxxx] //TODO
+	char project_name[API_PROJECT_NAME_SIZE + 1];  // name of the project (must correspond to the name in the license)
 	/**
 	 * this number passed in by the application must correspond to the magic number used when compiling the library.
 	 * See cmake parameter -DLCC_PROJECT_MAGIC_NUM and licensecc_properties.h macro VERIFY_MAGIC
@@ -111,12 +116,12 @@
 	 * multiple (for instance, license expired and signature not verified).
 	 * Only the last AUDIT_EVENT_NUM are reported.
 	 */
-	AuditEvent status[AUDIT_EVENT_NUM];
+	AuditEvent status[API_AUDIT_EVENT_NUM];
 	/**
 	 * Eventual expiration date of the software,
 	 * can be '\0' if the software don't expire
 	 * */
-	char expiry_date[11];
+	char expiry_date[API_EXPIRY_DATE_SIZE + 1];
 	unsigned int days_left;
 	bool has_expiry;
 	bool linked_to_pc;
@@ -124,7 +129,7 @@
 	/* A string of character inserted into the license understood
 	 * by the calling application.
 	 * '\0' if the application didn't specify one */
-	char proprietary_data[PROPRIETARY_DATA_SIZE + 1];
+	char proprietary_data[API_PROPRIETARY_DATA_SIZE + 1];
 	int license_version;  // license file version
 } LicenseInfo;
 
diff --git a/include/licensecc/licensecc.h b/include/licensecc/licensecc.h
index 749cf7b..9397613 100644
--- a/include/licensecc/licensecc.h
+++ b/include/licensecc/licensecc.h
@@ -12,13 +12,14 @@
 
 /*
  * Method used to convert the LicenseInfo into a human readable
- * representation.
+ * representation. //not yet implemented
  */
-void print_error(char out_buffer[256], LicenseInfo* licenseInfo);
+void print_error(char out_buffer[API_ERROR_BUFFER_SIZE], LicenseInfo* licenseInfo);
 
 /**
- * This method calculate the pc identifier. The string has to be shown
- * to the user in order to calculate the license.
+ * This method calculates the pc identifier. The string need to be shown to the user and given back to the software
+ * editor when issuing a license.
+ *  pc_id_method = STRATEGY_DEFAULT usually works.
  */
 bool identify_pc(IDENTIFICATION_STRATEGY pc_id_method, char* identifier_out, size_t* bufSize);
 
@@ -43,13 +44,11 @@
  * Should be called from time to time to confirm we're still using the
  * license.
  */
-EVENT_TYPE confirm_license(char * featureName,
-		LicenseLocation* licenseLocation);
+EVENT_TYPE confirm_license(char* featureName, LicenseLocation* licenseLocation);
 /**
  * Do nothing for now, useful for network licenses.
  */
-EVENT_TYPE release_license(char * featureName,
-		LicenseLocation licenseLocation);
+EVENT_TYPE release_license(char* featureName, LicenseLocation licenseLocation);
 
 #ifdef __cplusplus
 }
diff --git a/src/inspector/inspector.cpp b/src/inspector/inspector.cpp
index 7cb15f3..9a994bf 100644
--- a/src/inspector/inspector.cpp
+++ b/src/inspector/inspector.cpp
@@ -42,8 +42,8 @@
 	cout << "Virtual machine:" << cpu.cpu_virtual() << endl;
 	cout << "Cpu model      : 0x" << std::hex << ((long)cpu.model()) << std::dec << endl;
 
-	char pc_identifier[PC_IDENTIFIER_SIZE + 1];
-	size_t bufSize = PC_IDENTIFIER_SIZE + 1;
+	char pc_identifier[API_PC_IDENTIFIER_SIZE + 1];
+	size_t bufSize = API_PC_IDENTIFIER_SIZE + 1;
 	for (const auto& x : stringByStrategyId) {
 		if (identify_pc(x.first, pc_identifier, &bufSize)) {
 			std::cout << x.second << ':' << pc_identifier << std::endl;
diff --git a/src/library/licensecc.cpp b/src/library/licensecc.cpp
index 964f362..9b5f5ca 100644
--- a/src/library/licensecc.cpp
+++ b/src/library/licensecc.cpp
@@ -1,5 +1,5 @@
 //============================================================================
-// Name        : license-manager-cpp.cpp
+// Name        : licensecc.cpp
 // Author      :
 // Version     :
 // Copyright   : BSD
@@ -23,10 +23,10 @@
 #include "LicenseReader.hpp"
 
 using namespace std;
-void print_error(char out_buffer[256], LicenseInfo* licenseInfo) {}
+
+void print_error(char out_buffer[API_ERROR_BUFFER_SIZE], LicenseInfo* licenseInfo) {}
 
 bool identify_pc(IDENTIFICATION_STRATEGY pc_id_method, char* chbuffer, size_t* bufSize) {
-	FUNCTION_RETURN result = FUNC_RET_BUFFER_TOO_SMALL;
 	string pc_id = license::PcIdentifierFacade::generate_user_pc_signature(pc_id_method);
 	if (*bufSize >= pc_id.size() + 1) {
 		strncpy(chbuffer, pc_id.c_str(), *bufSize);
@@ -109,7 +109,7 @@
 #endif
 
 	if (license_out != nullptr) {
-		er.exportLastEvents(license_out->status, AUDIT_EVENT_NUM);
+		er.exportLastEvents(license_out->status, API_AUDIT_EVENT_NUM);
 	}
 	return result;
 }
diff --git a/src/library/limits/license_verifier.cpp b/src/library/limits/license_verifier.cpp
index 0edbbb3..bd2ed22 100644
--- a/src/library/limits/license_verifier.cpp
+++ b/src/library/limits/license_verifier.cpp
@@ -89,7 +89,7 @@
 
 	const auto proprietary_data = fullLicInfo.m_limits.find(PARAM_EXTRA_DATA);
 	if (proprietary_data != fullLicInfo.m_limits.end()) {
-		strncpy(info.proprietary_data, proprietary_data->second.c_str(), PROPRIETARY_DATA_SIZE);
+		strncpy(info.proprietary_data, proprietary_data->second.c_str(), API_PROPRIETARY_DATA_SIZE);
 	}
 	return info;
 }
diff --git a/src/library/pc_identifier/pc-identifiers.h b/src/library/pc_identifier/pc-identifiers.h
index f245096..4c4c86f 100644
--- a/src/library/pc_identifier/pc-identifiers.h
+++ b/src/library/pc_identifier/pc-identifiers.h
@@ -16,7 +16,7 @@
 #include "../base/base.h"
 
 typedef unsigned char PcIdentifier[6];
-typedef char PcSignature[PC_IDENTIFIER_SIZE + 1];
+typedef char PcSignature[API_PC_IDENTIFIER_SIZE + 1];
 
 FUNCTION_RETURN generate_pc_id(PcIdentifier * identifiers, unsigned int * array_size,
 		IDENTIFICATION_STRATEGY strategy);

--
Gitblit v1.9.1