/* * CraftLabs 授权 SDK — 核心 C API 实现(含桩逻辑与各适配器注册)。 * * 版权所有 © 广州创飞人工智能技术有限公司 * 开发者:huangping@craftlabs.cn */ #include "craftlabs_auth.h" #include #include #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(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 craft_initialize(const char* /* config_json */) { ensure_adapters_registered_once(); auto* ctx = new AuthContext{}; ctx->dummy = 1; return reinterpret_cast(ctx); } CRAFTLABS_API AuthResult craft_activate(AuthHandle handle, const char* /* license_key */) { if (!handle) { return k_fail; } (void)as_ctx(handle); return k_ok; } CRAFTLABS_API AuthResult craft_check_license(AuthHandle handle) { if (!handle) { return k_fail; } return k_ok; } CRAFTLABS_API LicenseInfo* craft_get_license_info(AuthHandle handle) { if (!handle) { return nullptr; } auto* info = static_cast(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 craft_free_license_info(LicenseInfo* info) { std::free(info); } CRAFTLABS_API int32_t craft_has_feature(AuthHandle handle, const char* /* feature_name */) { if (!handle) { return 0; } return 1; } CRAFTLABS_API AuthResult craft_release(AuthHandle handle) { if (!handle) { return k_fail; } return k_ok; } CRAFTLABS_API AuthResult craft_heartbeat(AuthHandle handle) { if (!handle) { return k_fail; } return k_ok; } CRAFTLABS_API void craft_destroy(AuthHandle handle) { if (!handle) { return; } delete as_ctx(handle); } }