mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
refactor(native): rename C API auth_* -> craft_* across header, core, JNI bridge, and smoke tests
This commit is contained in:
@@ -15,10 +15,10 @@
|
|||||||
* - 所有 `const char*` 均为 **UTF-8** 编码、以 `\0` 结尾。
|
* - 所有 `const char*` 均为 **UTF-8** 编码、以 `\0` 结尾。
|
||||||
* - `config_json`:UTF-8 JSON,语义与仓库 `schemas/craftlabs-auth-config.schema.json` 及 `examples/config/`
|
* - `config_json`:UTF-8 JSON,语义与仓库 `schemas/craftlabs-auth-config.schema.json` 及 `examples/config/`
|
||||||
* 一致;Java 侧可先经 `cn.craftlabs.auth.config.AuthConfigs` 校验后再序列化传入。
|
* 一致;Java 侧可先经 `cn.craftlabs.auth.config.AuthConfigs` 校验后再序列化传入。
|
||||||
* - `AuthHandle`:不透明指针,仅由本库函数产生与销毁(`auth_initialize` / `auth_destroy`)。
|
* - `AuthHandle`:不透明指针,仅由本库函数产生与销毁(`craft_initialize` / `craft_destroy`)。
|
||||||
* - `AuthResult`、`LicenseInfo` 使用 `stdint` 定宽字段,避免 `time_t`/`int` 宽度随平台变化导致 Python 侧 Structure 布局错误。
|
* - `AuthResult`、`LicenseInfo` 使用 `stdint` 定宽字段,避免 `time_t`/`int` 宽度随平台变化导致 Python 侧 Structure 布局错误。
|
||||||
* - `AuthResult.message`:指向 **由本库管理的静态或内部只读缓冲区**,调用方不得 `free`;在任意后续对本库的再次调用之后视为可能失效(与其它 FFI 语言惯例一致)。
|
* - `AuthResult.message`:指向 **由本库管理的静态或内部只读缓冲区**,调用方不得 `free`;在任意后续对本库的再次调用之后视为可能失效(与其它 FFI 语言惯例一致)。
|
||||||
* - `auth_get_license_info` 返回的 `LicenseInfo*`(及其中 `feature_names` / `feature_values` 指向的数组)须通过 `auth_free_license_info` 释放;释放后不得再读指针成员。
|
* - `craft_get_license_info` 返回的 `LicenseInfo*`(及其中 `feature_names` / `feature_values` 指向的数组)须通过 `craft_free_license_info` 释放;释放后不得再读指针成员。
|
||||||
* - 官方 Python 绑定见仓库 `python/craftlabs_auth/`(ctypes,与本头文件字段一一对应)。
|
* - 官方 Python 绑定见仓库 `python/craftlabs_auth/`(ctypes,与本头文件字段一一对应)。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -47,23 +47,23 @@ typedef struct {
|
|||||||
int32_t feature_count;
|
int32_t feature_count;
|
||||||
} LicenseInfo;
|
} LicenseInfo;
|
||||||
|
|
||||||
CRAFTLABS_API AuthHandle auth_initialize(const char* config_json);
|
CRAFTLABS_API AuthHandle craft_initialize(const char* config_json);
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_activate(AuthHandle handle, const char* license_key);
|
CRAFTLABS_API AuthResult craft_activate(AuthHandle handle, const char* license_key);
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_check_license(AuthHandle handle);
|
CRAFTLABS_API AuthResult craft_check_license(AuthHandle handle);
|
||||||
|
|
||||||
CRAFTLABS_API LicenseInfo* auth_get_license_info(AuthHandle handle);
|
CRAFTLABS_API LicenseInfo* craft_get_license_info(AuthHandle handle);
|
||||||
|
|
||||||
CRAFTLABS_API void auth_free_license_info(LicenseInfo* info);
|
CRAFTLABS_API void craft_free_license_info(LicenseInfo* info);
|
||||||
|
|
||||||
CRAFTLABS_API int32_t auth_has_feature(AuthHandle handle, const char* feature_name);
|
CRAFTLABS_API int32_t craft_has_feature(AuthHandle handle, const char* feature_name);
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_release(AuthHandle handle);
|
CRAFTLABS_API AuthResult craft_release(AuthHandle handle);
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_heartbeat(AuthHandle handle);
|
CRAFTLABS_API AuthResult craft_heartbeat(AuthHandle handle);
|
||||||
|
|
||||||
CRAFTLABS_API void auth_destroy(AuthHandle handle);
|
CRAFTLABS_API void craft_destroy(AuthHandle handle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ void ensure_adapters_registered_once() {
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
CRAFTLABS_API AuthHandle auth_initialize(const char* /* config_json */) {
|
CRAFTLABS_API AuthHandle craft_initialize(const char* /* config_json */) {
|
||||||
ensure_adapters_registered_once();
|
ensure_adapters_registered_once();
|
||||||
auto* ctx = new AuthContext{};
|
auto* ctx = new AuthContext{};
|
||||||
ctx->dummy = 1;
|
ctx->dummy = 1;
|
||||||
return reinterpret_cast<AuthHandle>(ctx);
|
return reinterpret_cast<AuthHandle>(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_activate(AuthHandle handle, const char* /* license_key */) {
|
CRAFTLABS_API AuthResult craft_activate(AuthHandle handle, const char* /* license_key */) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return k_fail;
|
return k_fail;
|
||||||
}
|
}
|
||||||
@@ -54,14 +54,14 @@ CRAFTLABS_API AuthResult auth_activate(AuthHandle handle, const char* /* license
|
|||||||
return k_ok;
|
return k_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_check_license(AuthHandle handle) {
|
CRAFTLABS_API AuthResult craft_check_license(AuthHandle handle) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return k_fail;
|
return k_fail;
|
||||||
}
|
}
|
||||||
return k_ok;
|
return k_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API LicenseInfo* auth_get_license_info(AuthHandle handle) {
|
CRAFTLABS_API LicenseInfo* craft_get_license_info(AuthHandle handle) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -77,32 +77,32 @@ CRAFTLABS_API LicenseInfo* auth_get_license_info(AuthHandle handle) {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API void auth_free_license_info(LicenseInfo* info) {
|
CRAFTLABS_API void craft_free_license_info(LicenseInfo* info) {
|
||||||
std::free(info);
|
std::free(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API int32_t auth_has_feature(AuthHandle handle, const char* /* feature_name */) {
|
CRAFTLABS_API int32_t craft_has_feature(AuthHandle handle, const char* /* feature_name */) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_release(AuthHandle handle) {
|
CRAFTLABS_API AuthResult craft_release(AuthHandle handle) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return k_fail;
|
return k_fail;
|
||||||
}
|
}
|
||||||
return k_ok;
|
return k_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API AuthResult auth_heartbeat(AuthHandle handle) {
|
CRAFTLABS_API AuthResult craft_heartbeat(AuthHandle handle) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return k_fail;
|
return k_fail;
|
||||||
}
|
}
|
||||||
return k_ok;
|
return k_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRAFTLABS_API void auth_destroy(AuthHandle handle) {
|
CRAFTLABS_API void craft_destroy(AuthHandle handle) {
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,25 +10,25 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
AuthHandle h = auth_initialize("{}");
|
AuthHandle h = craft_initialize("{}");
|
||||||
if (!h) {
|
if (!h) {
|
||||||
std::fprintf(stderr, "auth_initialize returned null\n");
|
std::fprintf(stderr, "auth_initialize returned null\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
AuthResult r = auth_check_license(h);
|
AuthResult r = craft_check_license(h);
|
||||||
if (r.success == 0) {
|
if (r.success == 0) {
|
||||||
std::fprintf(stderr, "auth_check_license failed\n");
|
std::fprintf(stderr, "auth_check_license failed\n");
|
||||||
auth_destroy(h);
|
auth_destroy(h);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
LicenseInfo* info = auth_get_license_info(h);
|
LicenseInfo* info = craft_get_license_info(h);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
std::fprintf(stderr, "auth_get_license_info returned null\n");
|
std::fprintf(stderr, "auth_get_license_info returned null\n");
|
||||||
auth_destroy(h);
|
auth_destroy(h);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
auth_free_license_info(info);
|
craft_free_license_info(info);
|
||||||
auth_destroy(h);
|
craft_destroy(h);
|
||||||
std::printf("native smoke ok\n");
|
std::printf("native smoke ok\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user