mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 18:10:30 +08:00
feat: add native/Java auth SDK, docs, CI, and examples
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* CraftLabs 授权 SDK — 核心 C API 实现(含桩逻辑与各适配器注册)。
|
||||
*
|
||||
* 版权所有 © 广州创飞人工智能技术有限公司
|
||||
* 开发者:huangping@craftlabs.cn
|
||||
*/
|
||||
#include "craftlabs_auth.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "bitanswer/bitanswer_adapter.h"
|
||||
#include "selfhosted/selfhosted_adapter.h"
|
||||
|
||||
namespace {
|
||||
|
||||
/** 不透明句柄对应的内部状态;后续可扩展为供应商特定字段。 */
|
||||
struct AuthContext {
|
||||
int dummy;
|
||||
};
|
||||
|
||||
static const AuthResult k_ok = {1, "stub"};
|
||||
static const AuthResult k_fail = {0, "stub failure"};
|
||||
|
||||
AuthContext* as_ctx(AuthHandle h) {
|
||||
return reinterpret_cast<AuthContext*>(h);
|
||||
}
|
||||
|
||||
void ensure_adapters_registered_once() {
|
||||
static bool once = false;
|
||||
if (!once) {
|
||||
bitanswer_adapter_register();
|
||||
selfhosted_adapter_register();
|
||||
once = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
CRAFTLABS_API AuthHandle auth_initialize(const char* /* config_json */) {
|
||||
ensure_adapters_registered_once();
|
||||
auto* ctx = new AuthContext{};
|
||||
ctx->dummy = 1;
|
||||
return reinterpret_cast<AuthHandle>(ctx);
|
||||
}
|
||||
|
||||
CRAFTLABS_API AuthResult auth_activate(AuthHandle handle, const char* /* license_key */) {
|
||||
if (!handle) {
|
||||
return k_fail;
|
||||
}
|
||||
(void)as_ctx(handle);
|
||||
return k_ok;
|
||||
}
|
||||
|
||||
CRAFTLABS_API AuthResult auth_check_license(AuthHandle handle) {
|
||||
if (!handle) {
|
||||
return k_fail;
|
||||
}
|
||||
return k_ok;
|
||||
}
|
||||
|
||||
CRAFTLABS_API LicenseInfo* auth_get_license_info(AuthHandle handle) {
|
||||
if (!handle) {
|
||||
return nullptr;
|
||||
}
|
||||
auto* info = static_cast<LicenseInfo*>(std::malloc(sizeof(LicenseInfo)));
|
||||
if (!info) {
|
||||
return nullptr;
|
||||
}
|
||||
info->is_licensed = 1;
|
||||
info->expiration_date = 0;
|
||||
info->feature_names = nullptr;
|
||||
info->feature_values = nullptr;
|
||||
info->feature_count = 0;
|
||||
return info;
|
||||
}
|
||||
|
||||
CRAFTLABS_API void auth_free_license_info(LicenseInfo* info) {
|
||||
std::free(info);
|
||||
}
|
||||
|
||||
CRAFTLABS_API int32_t auth_has_feature(AuthHandle handle, const char* /* feature_name */) {
|
||||
if (!handle) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
CRAFTLABS_API AuthResult auth_release(AuthHandle handle) {
|
||||
if (!handle) {
|
||||
return k_fail;
|
||||
}
|
||||
return k_ok;
|
||||
}
|
||||
|
||||
CRAFTLABS_API AuthResult auth_heartbeat(AuthHandle handle) {
|
||||
if (!handle) {
|
||||
return k_fail;
|
||||
}
|
||||
return k_ok;
|
||||
}
|
||||
|
||||
CRAFTLABS_API void auth_destroy(AuthHandle handle) {
|
||||
if (!handle) {
|
||||
return;
|
||||
}
|
||||
delete as_ctx(handle);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user