From 53c52a0b3e687964e5328f264ce83fb06c652d40 Mon Sep 17 00:00:00 2001 From: huangping Date: Tue, 28 Apr 2026 18:27:34 +0800 Subject: [PATCH] refactor(native): rename C API auth_* -> craft_* across header, core, JNI bridge, and smoke tests --- native/include/craftlabs_auth.h | 22 +++++++++++----------- native/src/craftlabs_auth.cpp | 18 +++++++++--------- native/tests/smoke_test.cpp | 10 +++++----- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/native/include/craftlabs_auth.h b/native/include/craftlabs_auth.h index 5403a1f..1b1fbae 100644 --- a/native/include/craftlabs_auth.h +++ b/native/include/craftlabs_auth.h @@ -15,10 +15,10 @@ * - 所有 `const char*` 均为 **UTF-8** 编码、以 `\0` 结尾。 * - `config_json`:UTF-8 JSON,语义与仓库 `schemas/craftlabs-auth-config.schema.json` 及 `examples/config/` * 一致;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.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,与本头文件字段一一对应)。 */ @@ -47,23 +47,23 @@ typedef struct { int32_t feature_count; } 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 } diff --git a/native/src/craftlabs_auth.cpp b/native/src/craftlabs_auth.cpp index bb346b5..3bf4020 100644 --- a/native/src/craftlabs_auth.cpp +++ b/native/src/craftlabs_auth.cpp @@ -39,14 +39,14 @@ void ensure_adapters_registered_once() { extern "C" { -CRAFTLABS_API AuthHandle auth_initialize(const char* /* config_json */) { +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 auth_activate(AuthHandle handle, const char* /* license_key */) { +CRAFTLABS_API AuthResult craft_activate(AuthHandle handle, const char* /* license_key */) { if (!handle) { return k_fail; } @@ -54,14 +54,14 @@ CRAFTLABS_API AuthResult auth_activate(AuthHandle handle, const char* /* license return k_ok; } -CRAFTLABS_API AuthResult auth_check_license(AuthHandle handle) { +CRAFTLABS_API AuthResult craft_check_license(AuthHandle handle) { if (!handle) { return k_fail; } return k_ok; } -CRAFTLABS_API LicenseInfo* auth_get_license_info(AuthHandle handle) { +CRAFTLABS_API LicenseInfo* craft_get_license_info(AuthHandle handle) { if (!handle) { return nullptr; } @@ -77,32 +77,32 @@ CRAFTLABS_API LicenseInfo* auth_get_license_info(AuthHandle handle) { return info; } -CRAFTLABS_API void auth_free_license_info(LicenseInfo* info) { +CRAFTLABS_API void craft_free_license_info(LicenseInfo* 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) { return 0; } return 1; } -CRAFTLABS_API AuthResult auth_release(AuthHandle handle) { +CRAFTLABS_API AuthResult craft_release(AuthHandle handle) { if (!handle) { return k_fail; } return k_ok; } -CRAFTLABS_API AuthResult auth_heartbeat(AuthHandle handle) { +CRAFTLABS_API AuthResult craft_heartbeat(AuthHandle handle) { if (!handle) { return k_fail; } return k_ok; } -CRAFTLABS_API void auth_destroy(AuthHandle handle) { +CRAFTLABS_API void craft_destroy(AuthHandle handle) { if (!handle) { return; } diff --git a/native/tests/smoke_test.cpp b/native/tests/smoke_test.cpp index e4cc45a..140839c 100644 --- a/native/tests/smoke_test.cpp +++ b/native/tests/smoke_test.cpp @@ -10,25 +10,25 @@ #include int main() { - AuthHandle h = auth_initialize("{}"); + AuthHandle h = craft_initialize("{}"); if (!h) { std::fprintf(stderr, "auth_initialize returned null\n"); return EXIT_FAILURE; } - AuthResult r = auth_check_license(h); + AuthResult r = craft_check_license(h); if (r.success == 0) { std::fprintf(stderr, "auth_check_license failed\n"); auth_destroy(h); return EXIT_FAILURE; } - LicenseInfo* info = auth_get_license_info(h); + LicenseInfo* info = craft_get_license_info(h); if (!info) { std::fprintf(stderr, "auth_get_license_info returned null\n"); auth_destroy(h); return EXIT_FAILURE; } - auth_free_license_info(info); - auth_destroy(h); + craft_free_license_info(info); + craft_destroy(h); std::printf("native smoke ok\n"); return EXIT_SUCCESS; }