From: "liheavy" Date: Fir, 26 Nov 2022 09:45:38 +0800 Subject: [PATCH] Adaptation for depend of dsoftbus --- diff -Nur a/BUILD.gn b/BUILD.gn --- a/BUILD.gn 1970-01-01 08:00:00.000000000 +0800 +++ b/BUILD.gn 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1,59 @@ +import("//build/ohos.gni") + +config("hilog_config") { + include_dirs = [ + "hilog/include", + "//third_party/bounds_checking_function/include", + ] +} + +ohos_shared_library("libhilog") { + public_configs = [ ":hilog_config" ] + sources = [ + "hilog/hilog.c", + ] + deps = [ + "//third_party/bounds_checking_function:libsec_shared", + ] +} + +group("system_ability_fwk") { +} + +group("samgr_proxy") { +} + +group("libpermissionsdk_standard") { +} + +group("cesfwk_innerkits") { +} + +group("want") { +} + +group("appexecfwk_core") { +} + +group("libaccesstoken_sdk") { +} + +config("syspara_config") { + include_dirs = [ + "syspara/include", + ] +} + +ohos_shared_library("syspara") { + include_dirs = [ + "syspara/include", + ] + sources = [ + "syspara/syspara.c", + ] + public_configs = [ ":syspara_config" ] + deps = [ + "//third_party/bounds_checking_function:libsec_shared", + "//third_party/mbedtls:mbedtls_shared", + ] +} diff -Nur a/hilog/hilog.c b/hilog/hilog.c --- a/hilog/hilog.c 1970-01-01 08:00:00.000000000 +0800 +++ b/hilog/hilog.c 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include "securec.h" +#include "hilog_base/log_base.h" + +#ifndef LOG_PRINT_MAX_LEN +#define LOG_PRINT_MAX_LEN 256 +#endif + +char *adapterStrForPrintfFormat(const char *fmt) { + char *left, *right; + char *buffer = (char *)malloc(LOG_PRINT_MAX_LEN * sizeof(char)); + (void)memset_s(buffer, LOG_PRINT_MAX_LEN * sizeof(char), 0, LOG_PRINT_MAX_LEN * sizeof(char)); + strcpy_s(buffer, LOG_PRINT_MAX_LEN * sizeof(char), fmt); + while (strstr(buffer, "{")) { + left = strstr(buffer, "{"); + right = strstr(buffer, "}"); + right++; + while (*right != '\0') { + *left = *right; + left++; + right++; + } + *left = '\0'; + } + return buffer; +} + +void printfAdapter(const char *fmt, ...) { + char *buffer; + buffer = adapterStrForPrintfFormat(fmt); + va_list ap; + va_start(ap, fmt); + vprintf(buffer, ap); + va_end(ap); + free(buffer); +} diff -Nur a/hilog/include/hilog/log.h b/hilog/include/hilog/log.h --- a/hilog/include/hilog/log.h 1970-01-01 08:00:00.000000000 +0800 +++ b/hilog/include/hilog/log.h 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1,37 @@ +#ifndef _HILOG_H +#define _HILOG_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +// Log type +typedef enum { + LOG_TYPE_MIN = 0, + LOG_APP = 0, + // Log to kmsg, only used by init phase. + LOG_INIT = 1, + // Used by core service, framework. + LOG_CORE = 3, + LOG_TYPE_MAX +} LogType; + +char *adapterStrForPrintfFormat(const char *fmt); +void printfAdapter(const char *fmt, ...); + +#define HILOG_DEBUG(type, fmt, ...) printfAdapter(fmt"\n", ##__VA_ARGS__) +#define HILOG_INFO(type, fmt, ...) printfAdapter(fmt"\n", ##__VA_ARGS__) +#define HILOG_WARN(type, fmt, ...) printfAdapter(fmt"\n", ##__VA_ARGS__) +#define HILOG_ERROR(type, fmt, ...) printfAdapter(fmt"\n", ##__VA_ARGS__) +#define HiLogPrint(type, level, domain, tag, fmt, ...) printf(fmt"\n", ##__VA_ARGS__) +#define HiLogBasePrint(type, level, domain, tag, fmt, ...) printfAdapter(fmt"\n", ##__VA_ARGS__) + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff -Nur a/hilog/include/hilog_base/log_base.h b/hilog/include/hilog_base/log_base.h --- a/hilog/include/hilog_base/log_base.h 1970-01-01 08:00:00.000000000 +0800 +++ b/hilog/include/hilog_base/log_base.h 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1 @@ +#include diff -Nur a/ohos.build b/ohos.build --- a/ohos.build 1970-01-01 08:00:00.000000000 +0800 +++ b/ohos.build 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1,114 @@ +{ + "subsystem": "depend", + "parts": { + "hiviewdfx_hilog_native": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:libhilog", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "ces_standard": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:cesfwk_innerkits", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "aafwk_standard": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:want", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "appexecfwk_standard": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:appexecfwk_core", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "permission_standard": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:libpermissionsdk_standard", + "header": { + "header_files": [ ], + "header_base":"//depend" + } + } + ] + }, + "safwk": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:system_ability_fwk", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "samgr_L2": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:samgr_proxy", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "samgr_standard": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:samgr_proxy", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + }, + "access_token": { + "module_list": [ ], + "inner_kits": [ + { + "name": "//depend:libaccesstoken_sdk", + "header": { + "header_files": [ ], + "header_base": "//depend" + } + } + ] + } + } +} + diff -Nur a/syspara/include/parameter.h b/syspara/include/parameter.h --- a/syspara/include/parameter.h 1970-01-01 08:00:00.000000000 +0800 +++ b/syspara/include/parameter.h 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1,20 @@ +#ifndef SYSPARA_PARAMETER_H +#define SYSPARA_PARAMETER_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int GetDevUdid(char *udid, int size); + +char * GetDeviceType(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* SYSPARA_PARAMETER_H */ diff -Nur a/syspara/syspara.c b/syspara/syspara.c --- a/syspara/syspara.c 1970-01-01 08:00:00.000000000 +0800 +++ b/syspara/syspara.c 2022-09-28 10:28:40.000000000 +0800 @@ -0,0 +1,86 @@ +#include +#include "securec.h" +#include "parameter.h" +#include "sha256.h" + +#define SN_FILE "/etc/SN" +#define SN_LEN 65 +#define UDID_LEN 65 +#define DEV_BUF_LENGTH 3 +#define HASH_LENGTH 32 +static char *deviceType = "UNKNOWN"; + +static int GetHash(const char *input, char *output, int size) +{ + char buf[DEV_BUF_LENGTH] = { 0 }; + unsigned char hash[HASH_LENGTH] = { 0 }; + mbedtls_sha256_context context; + + mbedtls_sha256_init(&context); + mbedtls_sha256_starts_ret(&context, 0); + mbedtls_sha256_update_ret(&context, (const unsigned char*)input, strlen(input)); + mbedtls_sha256_finish_ret(&context, hash); + + for (size_t i = 0; i < HASH_LENGTH; i++) { + unsigned char value = hash[i]; + memset_s(buf, DEV_BUF_LENGTH, 0, DEV_BUF_LENGTH); + sprintf_s(buf, sizeof(buf), "%02X", value); + if (strcat_s(output, size, buf) != 0) { + return -1; + } + } + return 0; +} + +int GetDevUdid(char *udid, int size) +{ + FILE *fp; + char *realPath = NULL; + char sn[SN_LEN] = {0}; + char out[UDID_LEN] = {0}; + int ret; + + realPath = realpath(SN_FILE, NULL); + if (realPath == NULL) { + printf("realpath fail.\n"); + goto err_realpath; + } + + fp = fopen(realPath, "r"); + if (fp == NULL) { + printf("open SN fail.\n"); + goto err_fopen; + } + + ret = fscanf_s(fp, "%s", sn, SN_LEN); + if (ret < 1) { + printf("get sn fail.\n"); + goto err_out; + } + + ret = GetHash(sn, out, UDID_LEN); + if (ret < 0) { + printf("get hash fail.\n"); + goto err_out; + } + + ret = sprintf_s(udid, size, "%s", out); + if (ret <= 0) { + printf("sprintf_s error.\n"); + goto err_out; + } + + fclose(fp); + return 0; +err_out: + fclose(fp); +err_fopen: + free(realPath); +err_realpath: + return -1; +} + +char * GetDeviceType(void) +{ + return deviceType; +}