// // Copyright (c) 2014 ANSCENTER. All rights reserved. // #include "precomp.h" #include "base32.h" #include "base64.h" #include "sha1.h" #include "except.h" #include "bitstream.h" #include "template.h" #include "generator.h" #include "validator.h" #include "license.h" #include "licensevalidationargs.h" #include "licensevalidationresult.h" #include "licensingclient.h" #include "certificate.h" #include "uniconv.h" void * KeyGenerator_Create() { return new(std::nothrow) KeyGeneratorImpl(); } void KeyGenerator_Destroy(void * generator) { delete static_cast(generator); } int KeyGenerator_SetKeyTemplate(void * generator, const void * tmpl) { try { static_cast(generator)->SetKeyTemplate(static_cast(const_cast(tmpl))); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetKeyDataA(void * generator, const char * fieldName, const void * data, int len) { try { static_cast(generator)->SetKeyData(fieldName, data, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetKeyDataW(void * generator, const wchar_t * fieldName, const void * data, int len) { try { static_cast(generator)->SetKeyData(w2s(fieldName).c_str(), data, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetIntKeyDataA(void * generator, const char * fieldName, int data) { try { static_cast(generator)->SetKeyData(fieldName, data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetIntKeyDataW(void * generator, const wchar_t * fieldName, int data) { try { static_cast(generator)->SetKeyData(w2s(fieldName).c_str(), data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetDateKeyDataA(void * generator, const char * fieldName, int year, int month, int day) { try { static_cast(generator)->SetKeyData(fieldName, year, month, day); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetDateKeyDataW(void * generator, const wchar_t * fieldName, int year, int month, int day) { try { static_cast(generator)->SetKeyData(w2s(fieldName).c_str(), year, month, day); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetStringKeyDataA(void * generator, const char * fieldName, const char * data) { try { static_cast(generator)->SetKeyData(fieldName, data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetStringKeyDataW(void * generator, const wchar_t * fieldName, const wchar_t * data) { try { static_cast(generator)->SetKeyData(w2s(fieldName).c_str(), w2s(data).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetValidationDataA(void * generator, const char * fieldName, const void * buf, int len) { try { static_cast(generator)->SetValidationData(fieldName, buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetValidationDataW(void * generator, const wchar_t * fieldName, const void * buf, int len) { try { static_cast(generator)->SetValidationData(w2s(fieldName).c_str(), buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetIntValidationDataA(void * generator, const char * fieldName, int data) { try { static_cast(generator)->SetValidationData(fieldName, data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetIntValidationDataW(void * generator, const wchar_t * fieldName, int data) { try { static_cast(generator)->SetValidationData(w2s(fieldName).c_str(), data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetStringValidationDataA(void * generator, const char * fieldName, const char * data) { try { static_cast(generator)->SetValidationData(fieldName, data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_SetStringValidationDataW(void * generator, const wchar_t * fieldName, const wchar_t * data) { try { static_cast(generator)->SetValidationData(w2s(fieldName).c_str(), w2s(data).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_GenerateKeyA(void * generator, const char **key) { try { *key = static_cast(generator)->GenerateKey(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyGenerator_GenerateKeyW(void * generator, const wchar_t **key) { try { static wstring wstr1; wstr1 = s2w(static_cast(generator)->GenerateKey()); *key = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } void * KeyValidator_Create() { return new(std::nothrow) KeyValidatorImpl(); } void KeyValidator_Destroy(void * validator) { delete static_cast(validator); } int KeyValidator_SetKeyTemplate(void * validator, const void * tmpl) { try { static_cast(validator)->SetKeyTemplate(static_cast(const_cast(tmpl))); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetKeyA(void * validator, const char * key) { try { static_cast(validator)->SetKey(key); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetKeyW(void * validator, const wchar_t * key) { try { static_cast(validator)->SetKey(w2s(key).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetValidationDataA(void * validator, const char * fieldName, const void * buf, int len) { try { static_cast(validator)->SetValidationData(fieldName, buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetValidationDataW(void * validator, const wchar_t * fieldName, const void * buf, int len) { try { static_cast(validator)->SetValidationData(w2s(fieldName).c_str(), buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetIntValidationDataA(void * validator, const char * fieldName, int data) { try { static_cast(validator)->SetValidationData(fieldName, data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetIntValidationDataW(void * validator, const wchar_t * fieldName, int data) { try { static_cast(validator)->SetValidationData(w2s(fieldName).c_str(), data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetStringValidationDataA(void * validator, const char * fieldName, const char * data) { try { static_cast(validator)->SetValidationData(fieldName, data); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_SetStringValidationDataW(void * validator, const wchar_t * fieldName, const wchar_t * data) { try { static_cast(validator)->SetValidationData(w2s(fieldName).c_str(), w2s(data).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_IsKeyValid(void * validator) { int status = STATUS_SUCCESS; try { if (!static_cast(validator)->IsKeyValid()) status = STATUS_INVALID_LICENSE_KEY; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return status; } int KeyValidator_QueryKeyDataA(void * validator, const char * dataField, void * buf, int * len) { try { static_cast(validator)->QueryKeyData(dataField, buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryKeyDataW(void * validator, const wchar_t * dataField, void * buf, int * len) { try { static_cast(validator)->QueryKeyData(w2s(dataField).c_str(), buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryIntKeyDataA(void * validator, const char * dataField, int * data) { try { *data = static_cast(validator)->QueryIntKeyData(dataField); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryIntKeyDataW(void * validator, const wchar_t * dataField, int * data) { try { *data = static_cast(validator)->QueryIntKeyData(w2s(dataField).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryDateKeyDataA(void * validator, const char * dataField, int * year, int * month, int * day) { try { static_cast(validator)->QueryDateKeyData(dataField, year, month, day); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryDateKeyDataW(void * validator, const wchar_t * dataField, int * year, int * month, int * day) { try { static_cast(validator)->QueryDateKeyData(w2s(dataField).c_str(), year, month, day); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryValidationDataA(void * validator, const char * dataField, void * buf, int * len) { try { static_cast(validator)->QueryValidationData(dataField, buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyValidator_QueryValidationDataW(void * validator, const wchar_t * dataField, void * buf, int * len) { try { static_cast(validator)->QueryValidationData(w2s(dataField).c_str(), buf, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } void * LicenseTemplate_Create() { return new(std::nothrow) LicenseTemplateImpl(); } void LicenseTemplate_Destroy(void * tmpl) { delete static_cast(tmpl); } int LicenseTemplate_SetVersion(void * tmpl, int version) { try { static_cast(tmpl)->SetVersion(version); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetVersion(void * tmpl, int * version) { try { static_cast(tmpl)->GetVersion(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetNumberOfGroups(void * tmpl, int numGroups) { try { static_cast(tmpl)->SetNumberOfGroups(numGroups); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetNumberOfGroups(void * tmpl, int * numGroups) { try { *numGroups = static_cast(tmpl)->GetNumberOfGroups(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetCharactersPerGroup(void * tmpl, int charsPerGroup) { try { static_cast(tmpl)->SetCharactersPerGroup(charsPerGroup); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetCharactersPerGroup(void * tmpl, int * charsPerGroup) { try { *charsPerGroup = static_cast(tmpl)->GetCharactersPerGroup(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetGroupSeparatorA(void * tmpl, const char * groupSep) { try { static_cast(tmpl)->SetGroupSeparator(groupSep); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetGroupSeparatorW(void * tmpl, const wchar_t * groupSep) { try { static_cast(tmpl)->SetGroupSeparator(w2s(groupSep).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetGroupSeparatorA(void * tmpl, const char **groupSep) { try { *groupSep = static_cast(tmpl)->GetGroupSeparator(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetGroupSeparatorW(void * tmpl, const wchar_t **groupSep) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetGroupSeparator()); *groupSep = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetEncoding(void * tmpl, int encoding) { try { static_cast(tmpl)->SetEncoding(encoding); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetEncoding(void * tmpl, int * encoding) { try { *encoding = static_cast(tmpl)->GetEncoding(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetHeaderA(void * tmpl, const char * header) { try { static_cast(tmpl)->SetHeader(header); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetHeaderW(void * tmpl, const wchar_t * header) { try { static_cast(tmpl)->SetHeader(w2s(header).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetHeaderA(void * tmpl, const char ** header) { try { *header = static_cast(tmpl)->GetHeader(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetHeaderW(void * tmpl, const wchar_t ** header) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetHeader()); *header = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetFooterA(void * tmpl, const char * footer) { try { static_cast(tmpl)->SetFooter(footer); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetFooterW(void * tmpl, const wchar_t * footer) { try { static_cast(tmpl)->SetFooter(w2s(footer).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetFooterA(void * tmpl, const char **footer) { try { *footer = static_cast(tmpl)->GetFooter(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetFooterW(void * tmpl, const wchar_t **footer) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetFooter()); *footer = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetDataSize(void * tmpl, int sizeInBits) { try { static_cast(tmpl)->SetDataSize(sizeInBits); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetDataSize(void * tmpl, int * sizeInBits) { try { *sizeInBits = static_cast(tmpl)->GetDataSize(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_AddDataFieldA(void * tmpl, const char * fieldName, int fieldType, int fieldBitSize, int offset) { try { static_cast(tmpl)->AddDataField(fieldName, fieldType, fieldBitSize, offset); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_AddDataFieldW(void * tmpl, const wchar_t * fieldName, int fieldType, int fieldBitSize, int fieldOffset) { try { static_cast(tmpl)->AddDataField(w2s(fieldName).c_str(), fieldType, fieldBitSize, fieldOffset); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetDataFieldA(void *tmpl, const char *fieldName, int * fieldType, int *fieldSize, int *fieldOffset) { if (static_cast(tmpl)->GetDataField(fieldName, fieldType, fieldSize, fieldOffset)) return STATUS_SUCCESS; return STATUS_GENERIC_ERROR; } int LicenseTemplate_GetDataFieldW(void *tmpl, const wchar_t *fieldName, int * fieldType, int *fieldSize, int *fieldOffset) { if (static_cast(tmpl)->GetDataField(w2s(fieldName).c_str(), fieldType, fieldSize, fieldOffset)) return STATUS_SUCCESS; return STATUS_GENERIC_ERROR; } int LicenseTemplate_EnumDataFieldsA(void * tmpl, void **enumHandle, const char **fieldName, int * fieldType, int * fieldSize, int * fieldOffset) { int status = STATUS_SUCCESS; try { if (!static_cast(tmpl)->EnumDataFields(enumHandle, fieldName, fieldType, fieldSize, fieldOffset)) status = STATUS_GENERIC_ERROR; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return status; } int LicenseTemplate_EnumDataFieldsW(void * tmpl, void **enumHandle, const wchar_t **fieldName, int * fieldType, int * fieldSize, int * fieldOffset) { int status = STATUS_SUCCESS; try { const char* str1; if (static_cast(tmpl)->EnumDataFields(enumHandle, &str1, fieldType, fieldSize, fieldOffset)) { static wstring wstr1; wstr1 = s2w(str1); *fieldName = wstr1.c_str(); } else status = STATUS_GENERIC_ERROR; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return status; } int LicenseTemplate_SetValidationDataSize(void * tmpl, int sizeInBits) { try { static_cast(tmpl)->SetValidationDataSize(sizeInBits); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetValidationDataSize(void * tmpl, int * sizeInBits) { try { *sizeInBits = static_cast(tmpl)->GetValidationDataSize(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_AddValidationFieldA(void * tmpl, const char * fieldName, int fieldType, int fieldBitSize, int offset) { try { static_cast(tmpl)->AddValidationField(fieldName, fieldType, fieldBitSize, offset); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_AddValidationFieldW(void * tmpl, const wchar_t * fieldName, int fieldType, int fieldBitSize, int offset) { try { static_cast(tmpl)->AddValidationField(w2s(fieldName).c_str(), fieldType, fieldBitSize, offset); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetValidationFieldA(void *tmpl, const char *fieldName, int * fieldType, int *fieldSize, int *fieldOffset) { if (static_cast(tmpl)->GetValidationField(fieldName, fieldType, fieldSize, fieldOffset)) return STATUS_SUCCESS; return STATUS_GENERIC_ERROR; } int LicenseTemplate_GetValidationFieldW(void *tmpl, const wchar_t *fieldName, int * fieldType, int *fieldSize, int *fieldOffset) { if (static_cast(tmpl)->GetValidationField(w2s(fieldName).c_str(), fieldType, fieldSize, fieldOffset)) return STATUS_SUCCESS; return STATUS_GENERIC_ERROR; } int LicenseTemplate_EnumValidationFieldsA(void * tmpl, void **enumHandle, const char **fieldName, int * fieldType, int * fieldSize, int * fieldOffset) { int status = STATUS_SUCCESS; try { if (!static_cast(tmpl)->EnumValidationFields(enumHandle, fieldName, fieldType, fieldSize, fieldOffset)) status = STATUS_GENERIC_ERROR; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return status; } int LicenseTemplate_EnumValidationFieldsW(void * tmpl, void **enumHandle, const wchar_t **fieldName, int * fieldType, int * fieldSize, int * fieldOffset) { int status = STATUS_SUCCESS; try { const char* str1; if (static_cast(tmpl)->EnumValidationFields(enumHandle, &str1, fieldType, fieldSize, fieldOffset)) { static wstring wstr1; wstr1 = s2w(str1); *fieldName = wstr1.c_str(); } else status = STATUS_GENERIC_ERROR; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return status; } int LicenseTemplate_SetSignatureSize(void * tmpl, int signatureSize) { try { static_cast(tmpl)->SetSignatureSize(signatureSize); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetSignatureSize(void * tmpl, int * signatureSize) { try { *signatureSize = static_cast(tmpl)->GetSignatureSize(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_LoadXml(void * tmpl, const char * xmlTemplate) { try { static_cast(tmpl)->LoadXml(xmlTemplate); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SaveXml(void * tmpl, int savePrivateKey, const char **xmlTemplate) { try { *xmlTemplate = static_cast(tmpl)->SaveXml((savePrivateKey) ? true : false); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_LoadJson(void * tmpl, const char * jsonTemplate) { try { static_cast(tmpl)->LoadJson(jsonTemplate); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SaveJson(void * tmpl, int savePrivateKey, const char **jsonTemplate) { try { *jsonTemplate = static_cast(tmpl)->SaveJson((savePrivateKey) ? true : false); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetLicensingServiceUrlA(void * tmpl, const char * url) { try { static_cast(tmpl)->SetLicensingServiceUrl(url); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetLicensingServiceUrlW(void * tmpl, const wchar_t * url) { try { static_cast(tmpl)->SetLicensingServiceUrl(w2s(url).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetLicensingServiceUrlA(void * tmpl, const char **url) { try { *url = static_cast(tmpl)->GetLicensingServiceUrl(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetLicensingServiceUrlW(void * tmpl, const wchar_t **url) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetLicensingServiceUrl()); *url = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetTemplateIdA(void * tmpl, const char * templateId) { try { static_cast(tmpl)->SetTemplateId(templateId); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetTemplateIdW(void * tmpl, const wchar_t * templateId) { try { static_cast(tmpl)->SetTemplateId(w2s(templateId).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetTemplateIdA(void * tmpl, const char **templateId) { try { *templateId = static_cast(tmpl)->GetTemplateId(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetTemplateIdW(void * tmpl, const wchar_t **templateId) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetTemplateId()); *templateId = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } /* int LicenseTemplate_SetProductId(void * tmpl, int productId) { try { static_cast(tmpl)->SetProductId(productId); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetProductId(void * tmpl, int * productId) { try { *productId = static_cast(tmpl)->GetProductId(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } */ int KeyHelper_GetCurrentHardwareIdW(const wchar_t **hwid) { try { *hwid = KeyHelperT::GetCurrentHardwareId(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyHelper_GetCurrentHardwareIdA(const char **hwid) { try { *hwid = KeyHelperT::GetCurrentHardwareId(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyHelper_MatchCurrentHardwareIdW(const wchar_t *hwid) { try { if (!KeyHelperT::MatchCurrentHardwareId(hwid)) return STATUS_INVALID_LICENSE_KEY; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int KeyHelper_MatchCurrentHardwareIdA(const char *hwid) { try { if (!KeyHelperT::MatchCurrentHardwareId(hwid)) return STATUS_INVALID_LICENSE_KEY; } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int SDKRegistration_SetLicenseKeyA(const char * key) { try { SDKRegistrationT::SetLicenseKey(key); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int SDKRegistration_SetLicenseKeyW(const wchar_t * key) { try { SDKRegistrationT::SetLicenseKey(key); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetPublicKeyCertificateA(void * tmpl, const char **base64Certificate) { try { *base64Certificate = static_cast(tmpl)->GetPublicKeyCertificate(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetPublicKeyCertificateW(void * tmpl, const wchar_t **base64Certificate) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetPublicKeyCertificate()); *base64Certificate = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetPublicKeyCertificateA(void * tmpl, const char * base64Certificate) { try { static_cast(tmpl)->SetPublicKeyCertificate(base64Certificate); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetPublicKeyCertificateW(void * tmpl, const wchar_t * base64Certificate) { try { static_cast(tmpl)->SetPublicKeyCertificate(w2s(base64Certificate).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetPrivateKeyA(void * tmpl, const char **base64Key) { try { *base64Key = static_cast(tmpl)->GetPrivateKey(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetPrivateKeyW(void * tmpl, const wchar_t **base64Key) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetPrivateKey()); *base64Key = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetPrivateKeyA(void * tmpl, const char * base64Key) { try { static_cast(tmpl)->SetPrivateKey(base64Key); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetPrivateKeyW(void * tmpl, const wchar_t * base64Key) { try { static_cast(tmpl)->SetPrivateKey(w2s(base64Key).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GenerateSigningKeyPair(void * tmpl) { try { static_cast(tmpl)->GenerateSigningKeyPair(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetPropertyA(void * tmpl, const char * path, const char * name, const char * value) { try { static_cast(tmpl)->SetProperty(path, name, value); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_SetPropertyW(void * tmpl, const wchar_t * path, const wchar_t * name, const wchar_t * value) { try { static_cast(tmpl)->SetProperty(w2s(path).c_str(), w2s(name).c_str(), w2s(value).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetPropertyA(void * tmpl, const char * path, const char * name, const char **value) { try { *value = static_cast(tmpl)->GetProperty(path, name); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseTemplate_GetPropertyW(void *tmpl, const wchar_t * path, const wchar_t * name, const wchar_t **value) { try { static wstring wstr1; wstr1 = s2w(static_cast(tmpl)->GetProperty(w2s(path).c_str(), w2s(name).c_str())); *value = wstr1.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int Certificate_SignA(const char * csr, const char * privateKey, const char * signingPrivateKey, const char * signingCertificate, const char * certificateAuthorityUrl, int expYear, int expMonth, int expDay, const char **signedCert) { try { static std::string staticSignedCert; staticSignedCert = Certificate::Sign( csr, privateKey, signingPrivateKey, signingCertificate, certificateAuthorityUrl, expYear, expMonth, expDay); *signedCert = staticSignedCert.c_str(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } void * License_Create() { return new(std::nothrow) LicenseImpl(); } void License_Destroy(void * license) { delete (LicenseImpl *)license; } int License_LoadXml(void * license, const char * xml) { try { static_cast(license)->LoadXml(xml); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int License_SaveXml(void * license, const char ** xmlLicense) { try { *xmlLicense = static_cast(license)->SaveXml(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int License_LoadJson(void * license, const char * json) { try { static_cast(license)->LoadJson(json); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int License_SaveJson(void * license, const char ** jsonLicense) { try { *jsonLicense = static_cast(license)->SaveJson(); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } void * LicenseValidationArgs_CreateA(void * license, char * licenseKey) { LicenseValidationArgsImpl * args = new(std::nothrow) LicenseValidationArgsImpl(); if (license) args->SetLicense((LicenseImpl *)license); if (licenseKey) { args->SetLicenseKey(licenseKey); } return args; } void * LicenseValidationArgs_CreateW(void * license, wchar_t * licenseKey) { LicenseValidationArgsImpl * args = new(std::nothrow) LicenseValidationArgsImpl(); if (license) args->SetLicense((LicenseImpl *)license); if (licenseKey) { args->SetLicenseKey(w2s(licenseKey).c_str()); } return args; } void LicenseValidationArgs_Destroy(void* obj) { delete (LicenseValidationArgsImpl*)obj; } int LicenseValidationArgs_SetIntLicenseKeyValidationDataA(void * args, const char * fieldName, int fieldValue) { try { static_cast(args)->SetLicenseKeyValidationData(fieldName, fieldValue); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetIntLicenseKeyValidationDataW(void * args, const wchar_t * fieldName, int fieldValue) { try { static_cast(args)->SetLicenseKeyValidationData(w2s(fieldName).c_str(), fieldValue); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetStringLicenseKeyValidationDataA(void * args, const char * fieldName, const char * fieldValue) { try { static_cast(args)->SetLicenseKeyValidationData(fieldName, fieldValue); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetStringLicenseKeyValidationDataW(void * args, const wchar_t * fieldName, const wchar_t * fieldValue) { try { static_cast(args)->SetLicenseKeyValidationData(w2s(fieldName).c_str(), w2s(fieldValue).c_str()); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetDateLicenseKeyValidationDataA(void * args, const char * fieldName, int year, int month, int day) { try { static_cast(args)->SetLicenseKeyValidationData(fieldName, year, month, day); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetDateLicenseKeyValidationDataW(void * args, const wchar_t * fieldName, int year, int month, int day) { try { static_cast(args)->SetLicenseKeyValidationData(w2s(fieldName).c_str(), year, month, day); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetLicenseKeyValidationDataA(void * args, const char * fieldName, void * data, int len) { try { static_cast(args)->SetLicenseKeyValidationData(fieldName, data, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } int LicenseValidationArgs_SetLicenseKeyValidationDataW(void * args, const wchar_t * fieldName, void * data, int len) { try { static_cast(args)->SetLicenseKeyValidationData(w2s(fieldName).c_str(), data, len); } catch (Exception * ex) { int status = ex->GetCode(); ex->Destroy(); return status; } catch (...) { return STATUS_GENERIC_ERROR; } return STATUS_SUCCESS; } void * LicensingClient_Create(void * licenseTemplate) { LicensingClientImpl * licensingClient = new(std::nothrow) LicensingClientImpl(NULL, false); if (licensingClient) { licensingClient->SetLicenseTemplate((LicenseTemplateImpl *)licenseTemplate); } return licensingClient; } void LicensingClient_Destroy(void * client) { delete (LicensingClientImpl *)client; } int LicensingClient_SetLicenseTemplate(void * client, void * tmpl) { int result = STATUS_SUCCESS; try { ((LicensingClientImpl *)client)->SetLicenseTemplate((LicenseTemplateImpl *)tmpl); } catch (LicensingException * ex) { result = ex->GetCode(); ex->Destroy(); } catch (...) { result = STATUS_GENERIC_ERROR; } return result; } int LicensingClient_ValidateLicense(void* client, void* licenseValidationArgs, void** licenseValidationResult) { int result = STATUS_SUCCESS; try { *((LicenseValidationResultImpl **)licenseValidationResult) = &((LicensingClientImpl *)client)->ValidateLicense((LicenseValidationArgsImpl *)licenseValidationArgs); } catch (LicensingException * ex) { result = ex->GetCode(); ex->Destroy(); } catch (...) { result = STATUS_GENERIC_ERROR; } return result; } int LicenseValidationResult_GetLicense(void * resultObj, void **license) { int result = STATUS_SUCCESS; try { *((LicenseImpl **)license) = ((LicenseValidationResultImpl *)resultObj)->GetLicense(); } catch (LicensingException * ex) { result = ex->GetCode(); ex->Destroy(); } catch (...) { result = STATUS_GENERIC_ERROR; } return result; } int LicenseValidationResult_IsLicenseExpired(void * result) { return 0; } int LicenseValidationResult_IsPaymentRequired(void * result) { int status = STATUS_SUCCESS; try { ((LicenseValidationResultImpl *)result)->IsPaymentRequired(); } catch (LicensingException * ex) { status = ex->GetCode(); ex->Destroy(); } catch (...) { status = STATUS_GENERIC_ERROR; } return status; } int LicenseValidationResult_GetLicenseValidityDays(void * result, int * days) { int status = STATUS_SUCCESS; try { *days = ((LicenseValidationResultImpl *)result)->GetLicenseValidityDays(); } catch (LicensingException * ex) { status = ex->GetCode(); ex->Destroy(); } catch (...) { status = STATUS_GENERIC_ERROR; } return status; } int LicenseValidationResult_GetLicenseExpirationDate(void * result, int * year, int * month, int * day) { int status = STATUS_SUCCESS; try { ((LicenseValidationResultImpl *)result)->GetLicenseExpirationDate(year, month,day); } catch (LicensingException * ex) { status = ex->GetCode(); ex->Destroy(); } catch (...) { status = STATUS_GENERIC_ERROR; } return status; }