diff --git a/core/authentication/interface/auth_interface.h b/core/authentication/interface/auth_interface.h index ab87682a035f58567afd1b6d1030af035c7efc1d..75bcb7605b672c6b85a1053e987c3a1286325fcb 100644 --- a/core/authentication/interface/auth_interface.h +++ b/core/authentication/interface/auth_interface.h @@ -303,6 +303,16 @@ int32_t AuthSetP2pMac(int64_t authId, const char *mac); */ int32_t AuthGetConnectOptionByP2pMac(const char *mac, AuthLinkType type, ConnectOption *option); +/** + * @brief Get ConnectOption info by uuid and ConnectType. + * + * @param uuid device uuid string. + * @param type connect type. + * @param option connect option info {@link ConnectOption}. + * @return return SOFTBUS_OK if get successfully, otherwise return an error code. + */ +int32_t AuthGetActiveConnectOption(const char *uuid, ConnectType type, ConnectOption *option); + #ifdef __cplusplus } #endif diff --git a/core/authentication/src/auth_manager.c b/core/authentication/src/auth_manager.c index 341ae26e0db3735d14b2de516eae6028d994e2c7..b62b0eceb1cc6de6c41ea52d073605da9561e94f 100644 --- a/core/authentication/src/auth_manager.c +++ b/core/authentication/src/auth_manager.c @@ -1885,38 +1885,6 @@ int32_t AuthInit(void) return SOFTBUS_OK; } -int32_t GetActiveAuthConnInfo(const char *uuid, ConnectType type, AuthConnInfo *connInfo) -{ - AuthManager *item = NULL; - AuthManager *next = NULL; - if (SoftBusMutexLock(&g_authLock) != 0) { - SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "lock mutex failed"); - return SOFTBUS_LOCK_ERR; - } - LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authClientHead, AuthManager, node) { - if (IsP2PLink(item) || item->option.type != type) { - continue; - } - if (strncmp(item->peerUuid, uuid, strlen(uuid)) == 0) { - (void)ConvertOptionToAuthConnInfo(&item->option, item->isAuthP2p, connInfo); - (void)SoftBusMutexUnlock(&g_authLock); - return SOFTBUS_OK; - } - } - LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authServerHead, AuthManager, node) { - if (IsP2PLink(item) || item->option.type != type) { - continue; - } - if (strncmp(item->peerUuid, uuid, strlen(uuid)) == 0) { - (void)ConvertOptionToAuthConnInfo(&item->option, item->isAuthP2p, connInfo); - (void)SoftBusMutexUnlock(&g_authLock); - return SOFTBUS_OK; - } - } - (void)SoftBusMutexUnlock(&g_authLock); - return SOFTBUS_ERR; -} - static AuthManager *GetAuthManagerInner(int64_t authId) { AuthManager *item = NULL; @@ -2029,4 +1997,56 @@ int32_t AuthGetConnectOptionByP2pMac(const char *mac, AuthLinkType type, Connect (void)SoftBusMutexUnlock(&g_authLock); SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "auth not found by peer p2p mac: %d.", type); return SOFTBUS_ERR; -} \ No newline at end of file +} + +int32_t GetActiveAuthConnInfo(const char *uuid, ConnectType type, AuthConnInfo *connInfo) +{ + ConnectOption option = {0}; + if (uuid == NULL || strlen(uuid) == 0 || connInfo == NULL) { + SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "invalid param."); + return SOFTBUS_INVALID_PARAM; + } + if (AuthGetActiveConnectOption(uuid, type, &option) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "get active auth fail, type = %d.", type); + return SOFTBUS_ERR; + } + (void)ConvertOptionToAuthConnInfo(&option, false, connInfo); + return SOFTBUS_OK; +} + +int32_t AuthGetActiveConnectOption(const char *uuid, ConnectType type, ConnectOption *option) +{ + if (uuid == NULL || strlen(uuid) == 0 || option == NULL) { + SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "invalid param."); + return SOFTBUS_INVALID_PARAM; + } + AuthManager *item = NULL; + AuthManager *next = NULL; + if (SoftBusMutexLock(&g_authLock) != 0) { + SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "lock mutex failed"); + return SOFTBUS_LOCK_ERR; + } + LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authClientHead, AuthManager, node) { + if (IsP2PLink(item) || item->option.type != type) { + continue; + } + if (strncmp(item->peerUuid, uuid, strlen(uuid)) == 0) { + (void)memcpy_s(option, sizeof(ConnectOption), &item->option, sizeof(ConnectOption)); + (void)SoftBusMutexUnlock(&g_authLock); + return SOFTBUS_OK; + } + } + LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authServerHead, AuthManager, node) { + if (IsP2PLink(item) || item->option.type != type) { + continue; + } + if (strncmp(item->peerUuid, uuid, strlen(uuid)) == 0) { + (void)memcpy_s(option, sizeof(ConnectOption), &item->option, sizeof(ConnectOption)); + (void)SoftBusMutexUnlock(&g_authLock); + return SOFTBUS_OK; + } + } + (void)SoftBusMutexUnlock(&g_authLock); + SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "active auth not found, type = %d.", type); + return SOFTBUS_ERR; +} diff --git a/core/authentication/src/auth_manager_virtual.c b/core/authentication/src/auth_manager_virtual.c index 57d8de13f541141e0970ad8d7cb100bd5d919dc4..e51d72325fe8051da5225ed634b51d78a90a4baa 100644 --- a/core/authentication/src/auth_manager_virtual.c +++ b/core/authentication/src/auth_manager_virtual.c @@ -1,159 +1,167 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "auth_manager.h" - -#include "softbus_errcode.h" -#include "softbus_log.h" - -int32_t AuthInit(void) -{ - SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "init virtual auth manager"); - return SOFTBUS_OK; -} - -void AuthDeinit(void) -{ -} - -uint32_t AuthGetEncryptHeadLen(void) -{ - return 0; -} - -int32_t AuthEncrypt(const ConnectOption *option, AuthSideFlag *side, uint8_t *data, uint32_t len, OutBuf *outbuf) -{ - (void)option; - (void)side; - (void)data; - (void)len; - (void)outbuf; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t AuthDecrypt(const ConnectOption *option, AuthSideFlag side, uint8_t *data, uint32_t len, OutBuf *outbuf) -{ - (void)option; - (void)side; - (void)data; - (void)len; - (void)outbuf; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t AuthPostData(const AuthDataHead *head, const uint8_t *data, uint32_t len) -{ - (void)head; - (void)data; - (void)len; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t AuthGetUuidByOption(const ConnectOption *option, char *buf, uint32_t bufLen) -{ - (void)option; - (void)buf; - (void)bufLen; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t AuthTransDataRegCallback(AuthTransModule moduleId, AuthTransCallback *cb) -{ - (void)moduleId; - (void)cb; - return SOFTBUS_OK; -} - -void AuthTransDataUnRegCallback(AuthTransModule moduleId) -{ - (void)moduleId; -} - -int64_t AuthOpenChannel(const ConnectOption *option) -{ - (void)option; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t AuthCloseChannel(int64_t authId) -{ - (void)authId; - return SOFTBUS_NOT_IMPLEMENT; -} - -int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback) -{ - (void)info; - (void)requestId; - (void)callback; - return SOFTBUS_OK; -} - -void AuthCloseConn(int64_t authId) -{ - (void)authId; -} - -uint32_t AuthGenRequestId(void) -{ - return SOFTBUS_OK; -} - -int32_t AuthGetConnInfo(int64_t authId, AuthConnInfo *info) -{ - (void)authId; - (void)info; - return SOFTBUS_OK; -} - -int32_t AuthGetDeviceUuid(int64_t authId, char *buf, uint32_t size) -{ - (void)authId; - (void)buf; - (void)size; - return SOFTBUS_OK; -} - -int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo) -{ - (void)uuid; - (void)connInfo; - return SOFTBUS_OK; -} - -int32_t AuthSetP2pMac(int64_t authId, const char *mac) -{ - (void)authId; - (void)mac; - return SOFTBUS_OK; -} - -int32_t AuthGetConnectOptionByP2pMac(const char *mac, AuthLinkType type, ConnectOption *option) -{ - (void)mac; - (void)type; - (void)option; - return SOFTBUS_OK; -} - -int32_t AuthEncryptBySeq(int32_t seq, AuthSideFlag *side, uint8_t *data, uint32_t len, OutBuf *outBuf) -{ - (void)seq; - (void)side; - (void)data; - (void)len; - (void)outBuf; - return SOFTBUS_OK; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "auth_manager.h" + +#include "softbus_errcode.h" +#include "softbus_log.h" + +int32_t AuthInit(void) +{ + SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "init virtual auth manager"); + return SOFTBUS_OK; +} + +void AuthDeinit(void) +{ +} + +uint32_t AuthGetEncryptHeadLen(void) +{ + return 0; +} + +int32_t AuthEncrypt(const ConnectOption *option, AuthSideFlag *side, uint8_t *data, uint32_t len, OutBuf *outbuf) +{ + (void)option; + (void)side; + (void)data; + (void)len; + (void)outbuf; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthDecrypt(const ConnectOption *option, AuthSideFlag side, uint8_t *data, uint32_t len, OutBuf *outbuf) +{ + (void)option; + (void)side; + (void)data; + (void)len; + (void)outbuf; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthPostData(const AuthDataHead *head, const uint8_t *data, uint32_t len) +{ + (void)head; + (void)data; + (void)len; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthGetUuidByOption(const ConnectOption *option, char *buf, uint32_t bufLen) +{ + (void)option; + (void)buf; + (void)bufLen; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthTransDataRegCallback(AuthTransModule moduleId, AuthTransCallback *cb) +{ + (void)moduleId; + (void)cb; + return SOFTBUS_OK; +} + +void AuthTransDataUnRegCallback(AuthTransModule moduleId) +{ + (void)moduleId; +} + +int64_t AuthOpenChannel(const ConnectOption *option) +{ + (void)option; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthCloseChannel(int64_t authId) +{ + (void)authId; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback) +{ + (void)info; + (void)requestId; + (void)callback; + return SOFTBUS_NOT_IMPLEMENT; +} + +void AuthCloseConn(int64_t authId) +{ + (void)authId; +} + +uint32_t AuthGenRequestId(void) +{ + return 0; +} + +int32_t AuthGetConnInfo(int64_t authId, AuthConnInfo *info) +{ + (void)authId; + (void)info; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthGetDeviceUuid(int64_t authId, char *buf, uint32_t size) +{ + (void)authId; + (void)buf; + (void)size; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo) +{ + (void)uuid; + (void)connInfo; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthSetP2pMac(int64_t authId, const char *mac) +{ + (void)authId; + (void)mac; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthGetConnectOptionByP2pMac(const char *mac, AuthLinkType type, ConnectOption *option) +{ + (void)mac; + (void)type; + (void)option; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthEncryptBySeq(int32_t seq, AuthSideFlag *side, uint8_t *data, uint32_t len, OutBuf *outBuf) +{ + (void)seq; + (void)side; + (void)data; + (void)len; + (void)outBuf; + return SOFTBUS_NOT_IMPLEMENT; +} + +int32_t AuthGetActiveConnectOption(const char *uuid, ConnectType type, ConnectOption *option) +{ + (void)uuid; + (void)type; + (void)option; + return SOFTBUS_NOT_IMPLEMENT; +}