From ceffe31b113bd282c3bdce392d9239b698388bf1 Mon Sep 17 00:00:00 2001 From: zjucx Date: Mon, 24 Jan 2022 17:07:01 +0800 Subject: [PATCH] modify warning Signed-off-by: zjucx --- samgr_endpoint/BUILD.gn | 7 +++++-- samgr_endpoint/source/endpoint.c | 27 ++++++++++++--------------- samgr_endpoint/source/endpoint.h | 11 +++++++++++ samgr_server/source/samgr_server.c | 15 +++++++++------ 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/samgr_endpoint/BUILD.gn b/samgr_endpoint/BUILD.gn index 48c8b74..9d7cbcc 100644 --- a/samgr_endpoint/BUILD.gn +++ b/samgr_endpoint/BUILD.gn @@ -19,7 +19,7 @@ config("endpoint_public") { "//utils/native/lite/include", "//foundation/communication/ipc_lite/interfaces/kits", "//third_party/bounds_checking_function/include", - "//base/security/permission/services/permission_lite/ipc_auth/include" + "//base/security/permission/services/permission_lite/ipc_auth/include", ] } @@ -41,7 +41,10 @@ source_set("endpoint_source") { ] if (ohos_kernel_type == "linux") { - defines = [ "LITE_LINUX_BINDER_IPC" ] + defines = [ + "_GNU_SOURCE", + "LITE_LINUX_BINDER_IPC", + ] } configs += [ ":endpoint_internal" ] diff --git a/samgr_endpoint/source/endpoint.c b/samgr_endpoint/source/endpoint.c index 371a0cb..1a3472c 100755 --- a/samgr_endpoint/source/endpoint.c +++ b/samgr_endpoint/source/endpoint.c @@ -13,11 +13,15 @@ * limitations under the License. */ #include "endpoint.h" + #include #include +#include + #include #include #include + #include "policy_define.h" #include "iproxy_server.h" #include "memory_adapter.h" @@ -49,13 +53,6 @@ #define MAX_BURST_RATE (MAX_BUCKET_RATE + (MAX_BUCKET_RATE >> 1)) #endif -#ifndef MAX_SYSCAP_NUM -#define MAX_SYSCAP_NUM 512 -#endif - -#ifndef MAX_SYSCAP_NAME_LEN -#define MAX_SYSCAP_NAME_LEN 64 -#endif #define SAMGR_SERVICE "samgr" typedef struct Router { @@ -166,7 +163,7 @@ int32 SAMGR_AddSysCap(const Endpoint *endpoint, const char *sysCap, BOOL isReg) } if (replyBuf != NULL) { - FreeBuffer(endpoint, replyBuf); + FreeBuffer(endpoint->context, replyBuf); } HILOG_DEBUG(HILOG_MODULE_SAMGR, "SAMGR_AddSysCap ret = %d", ret); @@ -200,7 +197,7 @@ int32 SAMGR_GetSysCap(const Endpoint *endpoint, const char *sysCap, BOOL *isReg) *isReg = IpcIoPopBool(&reply); } if (replyBuf != NULL) { - FreeBuffer(endpoint, replyBuf); + FreeBuffer(endpoint->context, replyBuf); } HILOG_DEBUG(HILOG_MODULE_SAMGR, "SAMGR_GetSysCap ret = %d", ret); return ret; @@ -235,7 +232,7 @@ static int32 ParseGetAllSysCapsReply(IpcIo *reply, char sysCaps[MAX_SYSCAP_NUM][ size = ((size > MAX_SYSCAP_NUM) ? MAX_SYSCAP_NUM : size); int cnt = *sysCapNum; for (uint32 i = 0; i < size; i++) { - int len = 0; + uint32 len = 0; char *sysCap = (char *)IpcIoPopString(reply, &len); if (sysCap == NULL || len == 0) { continue; @@ -263,7 +260,7 @@ int32 SAMGR_GetSystemCapabilities(const Endpoint *endpoint, HILOG_DEBUG(HILOG_MODULE_SAMGR, "SAMGR_GetSystemCapabilities begin"); IpcIo reply; void *replyBuf = NULL; - int startIdx = 0; + uint32 startIdx = 0; BOOL isEnd = TRUE; int ret; do { @@ -272,7 +269,7 @@ int32 SAMGR_GetSystemCapabilities(const Endpoint *endpoint, ret = ParseGetAllSysCapsReply(&reply, sysCaps, sysCapNum, &isEnd, &startIdx); } if (replyBuf != NULL) { - FreeBuffer(endpoint, replyBuf); + FreeBuffer(endpoint->context, replyBuf); } } while (isEnd == FALSE && ret == EC_SUCCESS); HILOG_DEBUG(HILOG_MODULE_SAMGR, "SAMGR_GetSystemCapabilities ret = %d", ret); @@ -362,7 +359,7 @@ static void *Receive(void *argv) } int ret = EC_INVALID; - uint8 retry = 0; + uint32 retry = 0; while (retry < MAX_RETRY_TIMES) { ret = endpoint->registerEP(endpoint->context, &endpoint->identity); if (ret == EC_SUCCESS) { @@ -513,7 +510,7 @@ static int RegisterIdentity(const IpcContext *context, const SaName *saName, Svc ret = IpcIoPopInt32(&reply); } if (ret == EC_SUCCESS) { - saInfo = IpcIoPopSvc(&reply); + IpcIoPopSvc(&reply); GetRemotePolicy(&reply, policy, policyNum); } if (replyBuf != NULL) { @@ -554,7 +551,7 @@ static int RegisterRemoteEndpoint(const IpcContext *context, SvcIdentity *identi IpcIoInit(&req, data, MAX_DATA_LEN, 0); IpcIoPushUint32(&req, RES_ENDPOINT); IpcIoPushUint32(&req, OP_POST); - uint8 retry = 0; + uint32 retry = 0; while (retry < MAX_RETRY_TIMES) { ++retry; IpcIo reply; diff --git a/samgr_endpoint/source/endpoint.h b/samgr_endpoint/source/endpoint.h index 07dca6e..1a55d12 100755 --- a/samgr_endpoint/source/endpoint.h +++ b/samgr_endpoint/source/endpoint.h @@ -32,6 +32,13 @@ extern "C" { #define SAMGR_COOKIE 0 #define MAX_DATA_LEN 0x100 #define MIN_DATA_LEN 0x40 +#ifndef MAX_SYSCAP_NUM +#define MAX_SYSCAP_NUM 512 +#endif + +#ifndef MAX_SYSCAP_NAME_LEN +#define MAX_SYSCAP_NAME_LEN 64 +#endif typedef enum ResourceID { RES_ENDPOINT, @@ -64,6 +71,10 @@ struct Endpoint { Endpoint *SAMGR_CreateEndpoint(const char *name, RegisterEndpoint registry); int SAMGR_AddRouter(Endpoint *endpoint, const SaName *saName, const Identity *id, IUnknown *proxy); int SAMGR_ProcPolicy(const Endpoint *endpoint, const SaName *saName, int token); +int32 SAMGR_AddSysCap(const Endpoint *endpoint, const char *sysCap, BOOL isReg); +int32 SAMGR_GetSysCap(const Endpoint *endpoint, const char *sysCap, BOOL *isReg); +int32 SAMGR_GetSystemCapabilities(const Endpoint *endpoint, + char sysCaps[MAX_SYSCAP_NUM][MAX_SYSCAP_NAME_LEN], int32 *sysCapNum); #ifdef __cplusplus #if __cplusplus diff --git a/samgr_server/source/samgr_server.c b/samgr_server/source/samgr_server.c index bda54ec..d7fdf57 100644 --- a/samgr_server/source/samgr_server.c +++ b/samgr_server/source/samgr_server.c @@ -17,18 +17,21 @@ #include #include #include + #include #include #include #include #include #include + #include "cJSON.h" +#include "default_client.h" #include "policy_define.h" #include "samgr_lite.h" -#include "memory_adapter.h" +#include "securec.h" #include "thread_adapter.h" -#include "default_client.h" +#include "memory_adapter.h" #undef LOG_TAG #undef LOG_DOMAIN @@ -380,7 +383,7 @@ static int32 ProcAddSysCap(SamgrServer *server, IpcIo *req) return EC_FAILURE; } SysCapImpl *serviceImpl = (SysCapImpl *)VECTOR_At(sysCapablitys, pos); - if (serviceImpl == NULL || serviceImpl->name == NULL) { + if (serviceImpl == NULL) { MUTEX_Unlock(server->sysCapMtx); return EC_FAILURE; } @@ -389,7 +392,7 @@ static int32 ProcAddSysCap(SamgrServer *server, IpcIo *req) return EC_SUCCESS; } -static BOOL ProcGetSysCap(const SamgrServer *server, IpcIo *req) +static BOOL ProcGetSysCap(SamgrServer *server, IpcIo *req) { size_t len = 0; char *sysCap = (char *)IpcIoPopString(req, &len); @@ -415,7 +418,7 @@ static BOOL ProcGetSysCap(const SamgrServer *server, IpcIo *req) return res; } -static int32 GetReplyNumAndNextReqIdx(const Vector *sysCapablitys, int32 startIdx, int32 *nextRequestIdx) +static int32 GetReplyNumAndNextReqIdx(Vector *sysCapablitys, int32 startIdx, int32 *nextRequestIdx) { int32 registerNum = 0; int32 size = VECTOR_Num(sysCapablitys); @@ -431,7 +434,7 @@ static int32 GetReplyNumAndNextReqIdx(const Vector *sysCapablitys, int32 startId return registerNum; } -void ProcGetAllSysCap(const SamgrServer *server, IpcIo *req, IpcIo *reply) +void ProcGetAllSysCap(SamgrServer *server, IpcIo *req, IpcIo *reply) { uint32_t startIdx = IpcIoPopUint32(req); MUTEX_Lock(server->sysCapMtx);