refactor(native): rename C API auth_* -> craft_* across header, core, JNI bridge, and smoke tests

This commit is contained in:
2026-04-28 18:27:34 +08:00
parent 5073a4193f
commit 53c52a0b3e
3 changed files with 25 additions and 25 deletions
+11 -11
View File
@@ -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
}
+9 -9
View File
@@ -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<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) {
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;
}
+5 -5
View File
@@ -10,25 +10,25 @@
#include <cstdlib>
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;
}