From 9a1aca5366802ca5ac76297f877f7ff8739e81ba Mon Sep 17 00:00:00 2001
From: Jan Willamowius <jan@willamowius.de>
Date: 周三, 17 4月 2019 21:01:48 +0800
Subject: [PATCH] must check pc signature in example

---
 example/example.cpp |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/example/example.cpp b/example/example.cpp
index d8af95f..173d733 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -2,6 +2,7 @@
 #include <map>
 #include "api/license++.h"
 #include "pc-identifiers.h"
+#include "../../src/library/ini/SimpleIni.h"
 
 using namespace std;
 
@@ -15,11 +16,11 @@
     stringByEventType[FILE_FORMAT_NOT_RECOGNIZED      ] = "license file has invalid format (not .ini file) ";
     stringByEventType[LICENSE_MALFORMED               ] = "some mandatory field are missing, or data can't be fully read. ";
     stringByEventType[PRODUCT_NOT_LICENSED            ] = "this product was not licensed ";
-    stringByEventType[PRODUCT_EXPIRED                 ] = "licence expired ";
+    stringByEventType[PRODUCT_EXPIRED                 ] = "license expired ";
     stringByEventType[LICENSE_CORRUPTED               ] = "license signature didn't match with current license ";
     stringByEventType[IDENTIFIERS_MISMATCH            ] = "Calculated identifier and the one provided in license didn't match";
-    stringByEventType[LICENSE_FILE_FOUND              ] = "licence file not found ";
-    stringByEventType[LICENSE_VERIFIED                ] = "licence verified ";
+    stringByEventType[LICENSE_FILE_FOUND              ] = "license file not found ";
+    stringByEventType[LICENSE_VERIFIED                ] = "license verified ";
     
     const string licLocation("example.lic");
     
@@ -29,16 +30,27 @@
     licenseLocation.licenseFileLocation = licLocation.c_str();
     licenseLocation.environmentVariableName = "";
     EVENT_TYPE result = acquire_license("example", licenseLocation, &licenseInfo);
-    
-    if (result != LICENSE_OK){
-        PcSignature signature;
-        FUNCTION_RETURN generate_ok = generate_user_pc_signature(signature, ETHERNET);
-        
+    PcSignature signature;
+    FUNCTION_RETURN generate_ok = generate_user_pc_signature(signature, ETHERNET);
+
+	if (result == LICENSE_OK && licenseInfo.linked_to_pc) {
+        CSimpleIniA ini;
+    	SI_Error rc = ini.LoadFile(licLocation.c_str());
+        string IDinLicense = ini.GetValue("example", "client_signature", "");
+		if (IDinLicense == "") {
+            cout << "No client signature in license file, generate license with -s <id>";
+			result = IDENTIFIERS_MISMATCH;
+		} else if (IDinLicense != signature) {
+			result = IDENTIFIERS_MISMATCH;
+		}
+	}
+
+    if (result != LICENSE_OK) {
         cout << "license ERROR :" << endl;
         cout << "    " << stringByEventType[result].c_str() << endl;
         cout << "the pc signature is :" << endl;
         cout << "    " << signature << endl;
     }
     else
-        cout << "licence OK" << endl;
+        cout << "license OK" << endl;
 }

--
Gitblit v1.9.1