|
1 | 1 | #include "netlicensing/netlicensing.h" |
2 | 2 | #include "netlicensing/service.h" |
3 | 3 | #include "netlicensing/validation_parameters.h" |
| 4 | +#include <ctype.h> |
4 | 5 |
|
5 | 6 | namespace netlicensing { |
6 | 7 | /** |
@@ -94,34 +95,36 @@ namespace netlicensing { |
94 | 95 | } |
95 | 96 |
|
96 | 97 | /** |
97 | | - * Validates active licenses of the licensee. See NetLicensingAPI for details: |
98 | | - * https://www.labs64.de/confluence/display/NLICPUB/Licensee+Services#LicenseeServices-Validatelicensee |
99 | | - */ |
| 98 | + * Validates active licenses of the licensee. See NetLicensingAPI for details: |
| 99 | + * https://www.labs64.de/confluence/display/NLICPUB/Licensee+Services#LicenseeServices-Validatelicensee |
| 100 | + */ |
100 | 101 | ValidationResult LicenseeService::validate(Context& ctx, |
101 | 102 | const std::string& licenseeNumber, |
102 | 103 | const std::string& productNumber/* = std::string()*/, |
103 | 104 | const std::string& licenseeName/* = std::string()*/, |
104 | 105 | const parameters_type& validationParameters) { |
| 106 | + std::string endpoint = "licensee/" + escape_string(licenseeNumber) + "/validate"; |
| 107 | + parameters_type params; |
| 108 | + if (!productNumber.empty()) params.push_back(std::make_pair("productNumber", escape_string(productNumber))); |
| 109 | + if (!licenseeName.empty()) params.push_back(std::make_pair("licenseeName", escape_string(licenseeName))); |
| 110 | + |
| 111 | + // Add licensing model specific validation parameters |
| 112 | + for (parameters_type::const_iterator paramIt = validationParameters.begin(); |
| 113 | + paramIt != validationParameters.end(); ++paramIt) { |
| 114 | + params.push_back(std::make_pair(escape_string(paramIt->first), escape_string(paramIt->second))); |
| 115 | + } |
| 116 | + |
| 117 | + long http_code; |
| 118 | + std::string res = ctx.post(endpoint, params, http_code); |
| 119 | + ValidationResult validationResult; |
| 120 | + ValidationResultMapper vrm(validationResult); |
| 121 | + traverse(vrm, res); |
105 | 122 |
|
106 | | - ValidationParameters vParams = ValidationParameters(); |
107 | | - if (!productNumber.empty()) { |
108 | | - vParams.setProductNumber(productNumber); |
109 | | - } |
110 | | - if (!licenseeName.empty()) { |
111 | | - vParams.setLicenseeName(licenseeName); |
112 | | - } |
113 | | - |
114 | | - for (parameters_type::const_iterator paramIt = validationParameters.begin(); |
115 | | - paramIt != validationParameters.end(); ++paramIt) { |
116 | | - |
117 | | - if (escape_string(paramIt->first) == "licenseeSecret") { |
118 | | - vParams.setLicenseeSecret(escape_string(paramIt->second)); |
119 | | - } else { |
120 | | - vParams.setCustomParameter(escape_string(paramIt->first), escape_string(paramIt->second)); |
| 123 | + if (http_code != 200) { |
| 124 | + throw RestException(vrm.getInfos(), http_code); |
121 | 125 | } |
122 | | - } |
123 | 126 |
|
124 | | - return LicenseeService::validate(ctx, licenseeNumber, vParams); |
| 127 | + return validationResult; |
125 | 128 | } |
126 | 129 |
|
127 | 130 | /** |
@@ -158,11 +161,6 @@ namespace netlicensing { |
158 | 161 | paramIt++; |
159 | 162 | } |
160 | 163 |
|
161 | | - // Add licensing model specific validation parameters |
162 | | - for(auto const &ent3 : validationParameters.getCustomParameters()) { |
163 | | - params.push_back(std::make_pair(escape_string(ent3.first), escape_string(ent3.second))); |
164 | | - } |
165 | | - |
166 | 164 | long http_code; |
167 | 165 | std::string res = ctx.post(endpoint, params, http_code); |
168 | 166 | ValidationResult validationResult; |
|
0 commit comments