From: segwon Date: Tue, 15 Nov 2016 12:20:21 +0000 (+0900) Subject: Develop the ACL Internal API for Convergence Setting App(d2d-conv-setting) X-Git-Tag: accepted/tizen/common/20161121.143334~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d7ee6ea30d352d56ef19e64a8fafce23d1a67fe;p=platform%2Fcore%2Fconvergence%2Fd2d-conv-manager.git Develop the ACL Internal API for Convergence Setting App(d2d-conv-setting) + Coding Rule Check Signed-off-by: segwon Change-Id: Ida13e4157a4a45c5f7ae2bfbb1be7b18a6c6104e --- diff --git a/common/Types.h b/common/Types.h index 6b90880..ee54c6e 100644 --- a/common/Types.h +++ b/common/Types.h @@ -137,6 +137,8 @@ enum request_type { #define CONV_SMART_TV "Samsung SmartTV" #define CONV_DEVICE_TYPE_TV "TV" #define CONV_DEVICE_TYPE_MOBILE "MOBILE" +#define CONV_DEVICE_TYPE_WEARABLE "WEARABLE" +#define CONV_DEVICE_TYPE_UNKNOWN "UNKNOWN" enum ApplicationState { APP_COMM_STATE_NONE = 0, @@ -195,6 +197,7 @@ enum AccessControlState { #define CONV_JSON_ACCESS_REQUEST_TYPE "access_request_type" #define CONV_JSON_ACCESS_REQUEST_RESULT "access_request_result" #define CONV_JSON_PASSCODE "passcode" +#define CONV_JSON_ACCESS_CONTROL_STATE "access_control_state" #define CONV_JSON_APP_CONTROL_REPLY "app_control_reply" #define CONV_JSON_APP_CONTROL_REQUEST "app_control_request" #define CONV_JSON_APP_CONTROL_RESULT "app_control_result" @@ -211,4 +214,9 @@ enum AccessControlState { #define CONV_ACCESS_CONTROL_PASSCODE_WRONG "PASSCODE_WRONG" #define CONV_ACCESS_CONTROL_PASSCODE_REJECTED "PASSCODE_REHECTED" +#define CONV_SUBJECT_ACCESS_CONTROL_REGIST "conv/access/regist" +#define CONV_SUBJECT_ACCESS_CONTROL_SET "conv/access/set" +#define CONV_SUBJECT_ACCESS_CONTROL_GET "conv/access/get" +#define CONV_SUBJECT_ACCESS_CONTROL_REMOVE "conv/access/remove" + #endif diff --git a/daemon/RequestHandler.cpp b/daemon/RequestHandler.cpp index 9e93173..bf5338c 100755 --- a/daemon/RequestHandler.cpp +++ b/daemon/RequestHandler.cpp @@ -18,6 +18,7 @@ #include "DiscoveryManager.h" #include "ServiceManager.h" #include "ConnectionManager.h" +#include "access_control/ACLManager.h" using namespace std; @@ -67,10 +68,13 @@ int conv::RequestHandler::handleRequest(Request* requestObj) if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_DISCOVERY_START) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_DISCOVERY_STOP)) return discovery_manager::handleRequest (requestObj); else if ( !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_START) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_STOP) - || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_SET) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_GET)) + || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_SET) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_GET) ) result = service_manager::handleRequest(requestObj); else if ( !strcmp(requestObj->getSubject(), CONV_SUBJECT_CONNECTION_START) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_CONNECTION_STOP) ) result = connection_manager::handleRequest(requestObj); + else if ( !strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_SET) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_REMOVE) + || !strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_GET) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_REGIST) ) + result = conv::acl_manager::handleRequest(requestObj); break; case REQ_SUPPORT: break; diff --git a/daemon/ServiceManager.cpp b/daemon/ServiceManager.cpp index 66e52fb..0a8c14d 100755 --- a/daemon/ServiceManager.cpp +++ b/daemon/ServiceManager.cpp @@ -317,9 +317,15 @@ static iotcon_representation_h _get_d2d_service_representation(conv::ServiceMana #if defined(_TV_) _D("device type : TV"); string deviceTypeStr(CONV_DEVICE_TYPE_TV); -#else +#elif defined(_MOBILE_) _D("device type : MOBILE"); string deviceTypeStr(CONV_DEVICE_TYPE_MOBILE); +#elif defined(_WEARABLE_) + _D("device type : WEARABLE"); + string deviceTypeStr(CONV_DEVICE_TYPE_WEARABLE); +#else + _D("device type : UNKNOWN"); + string deviceTypeStr(CONV_DEVICE_TYPE_UNKNOWN); #endif char* deviceType = new char[deviceTypeStr.size() + 1]; diff --git a/daemon/Util.cpp b/daemon/Util.cpp index 503cfa1..69ce3cd 100755 --- a/daemon/Util.cpp +++ b/daemon/Util.cpp @@ -19,6 +19,7 @@ #include #include #include "Log.h" +#include "Types.h" #include #include #include @@ -34,6 +35,19 @@ using namespace std; +std::string conv::util::getDeviceType() +{ +#if defined(_TV_) + return CONV_DEVICE_TYPE_TV; +#elif defined(_MOBILE_) + return CONV_DEVICE_TYPE_MOBILE; +#elif defined(_WEARABLE_) + return CONV_DEVICE_TYPE_WEARABLE; +#else + return CONV_DEVICE_TYPE_UNKNOWN; +#endif +} + std::string conv::util::getBtMacAddress() { static std::string __macAddress; @@ -264,4 +278,4 @@ std::string conv::util::getIpAddress(std::string hostAddress) std::string sub = hostAddress.substr(FRONT_PROTOCOL_SIZE, pos - FRONT_PROTOCOL_SIZE); return sub; -} +} \ No newline at end of file diff --git a/daemon/Util.h b/daemon/Util.h index b8470e8..8aff362 100644 --- a/daemon/Util.h +++ b/daemon/Util.h @@ -22,6 +22,7 @@ namespace conv { namespace util { + std::string getDeviceType(); std::string getBtMacAddress(); std::string getDeviceName(); std::string getP2pMacAddress(); diff --git a/daemon/access_control/ACLManager.cpp b/daemon/access_control/ACLManager.cpp index 591f646..c1690f7 100644 --- a/daemon/access_control/ACLManager.cpp +++ b/daemon/access_control/ACLManager.cpp @@ -1,16 +1,20 @@ -#include "ACLManager.h" -#include "Log.h" - -#include -#include -#include -#include -#include -#include -#include -#include +/* + * Copyright (c) 2016 Samsung Electronics 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. + */ -#define DB_FILE_NAME "ACCESS_DEVICES.db" +#include "ACLManager.h" typedef struct { conv::acl_manager::PopupCallback callback; @@ -21,7 +25,7 @@ usercallback_info *info = NULL; static char passcode[5]; -ACLResult conv::acl_manager::PasscodeChecker (char *input_passcode) +ACLResult conv::acl_manager::PasscodeChecker(char *input_passcode) { bool isShowPopup = false; const char *app_id = "org.tizen.d2d-conv-syspopup"; @@ -56,7 +60,7 @@ void CreatePasscode() srand((unsigned int)time(NULL)); - for (int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { int random_num = rand() % 63; passcode[i] = token[random_num]; } @@ -92,8 +96,7 @@ void conv::acl_manager::LaunchPasscodeInputPopup(PopupCallback callback, void *u b = bundle_create(); bundle_add(b, "TYPE", "PASSCODE_INPUT_POPUP"); - char *popup_name = "d2d-conv-syspopup"; - int ret = syspopup_launch(popup_name, b); + int ret = syspopup_launch((char *)"d2d-conv-syspopup", b); if (ret != 0) { _E("syspopup_launch Error (%d).", ret); } @@ -122,8 +125,7 @@ void conv::acl_manager::LaunchPasscodeShowPopup(const char *deviceName) bundle_add(b, "DATA_PASSCODE", passcode); bundle_add(b, "DATA_DEVICE_NAME", deviceName); - char *popup_name = "d2d-conv-syspopup"; - int ret = syspopup_launch(popup_name, b); + int ret = syspopup_launch((char *)"d2d-conv-syspopup", b); if (ret != 0) { _E("syspopup_launch Error (%d).", ret); } @@ -161,6 +163,23 @@ void conv::acl_manager::LaunchAccessRejectedToast() LaunchToast((char*)"REJECTED"); } +static char convert_mac(char c) +{ + char convertC = c; + if ((convertC >= 'A') && (convertC <= 'F')) { + convertC = ((((convertC - 'A') + 10) | 0x02) - 10) + 'A'; + } else if ((convertC >= '0') && (convertC <= '9')) { + convertC = ((convertC - '0') | 0x02); + if (convertC < 10) + convertC = convertC + '0'; + else + convertC = 'A' + (convertC - 10); + } else { + _E("wrong byte for mac!"); + } + return convertC; +} + static int database_initialize(sqlite3 **database, sqlite3_stmt **stmt, const char *query) { int ret = sqlite3_open(DB_FILE_NAME, &(*database)); @@ -169,7 +188,7 @@ static int database_initialize(sqlite3 **database, sqlite3_stmt **stmt, const ch return ret; } - const char *create_table_query = "create table if not exists DEVICES_INFO(MAC_ADDRESS text(100) NOT NULL PRIMARY KEY, DEVICE_NAME text(50) NOT NULL, IP_ADDRESS text(50) NOT NULL, ACL_STATE int NOT NULL);"; + const char *create_table_query = "create table if not exists DEVICES_INFO(MAC_ADDRESS text(100) NOT NULL PRIMARY KEY, DEVICE_TYPE text(20) NOT NULL, DEVICE_NAME text(50) NOT NULL, ACL_STATE int NOT NULL);"; ret = sqlite3_exec(*database, create_table_query, NULL, NULL, NULL); if (ret != SQLITE_OK) { _E("Create the database table is fail. (%d: %s)", ret, sqlite3_errmsg(*database)); @@ -222,7 +241,7 @@ static int database_finalize(sqlite3 *database, sqlite3_stmt *stmt) while (true) { ret = sqlite3_exec(database, "COMMIT TRANSACTION", NULL, NULL, NULL); if (ret != SQLITE_BUSY) { - if(ret == SQLITE_ERROR) { + if (ret == SQLITE_ERROR) { _E("Transaction commit is fail. (%d: %s)", ret, sqlite3_errmsg(database)); sqlite3_close(database); return ret; @@ -240,52 +259,54 @@ static int database_finalize(sqlite3 *database, sqlite3_stmt *stmt) return SQLITE_OK; } -ACLResult conv::acl_manager::SetDeviceInfoAndACL(const char* MacAddress, const char* deviceName, const char* deviceIP, ACManagerPolicy deviceState) +ACLResult conv::acl_manager::SetDeviceInfoAndACL(const char *macAddress, const char *deviceType, const char *deviceName, const char *deviceIP, ACManagerPolicy aclState) { sqlite3 *database = NULL; sqlite3_stmt *stmt = NULL; - const char *insert_device_info_query = "insert into DEVICES_INFO (MAC_ADDRESS, DEVICE_NAME, IP_ADDRESS, ACL_STATE) values (?, ?, ?, ?);"; + const char *insert_device_info_query = "insert into DEVICES_INFO (MAC_ADDRESS, DEVICE_TYPE, DEVICE_NAME, ACL_STATE) values (?, ?, ?, ?);"; int ret = database_initialize(&database, &stmt, insert_device_info_query); if (ret != SQLITE_OK) { return ACLResult_Error; } - ret = sqlite3_bind_text(stmt, 1, MacAddress, strlen(MacAddress), SQLITE_TRANSIENT); + char _mac[50]; + strcpy(_mac, macAddress); + _mac[1] = convert_mac(_mac[1]); + ret = sqlite3_bind_text(stmt, 1, _mac, strlen(_mac), SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - _E("Statement binding the MacAddress text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + _E("Statement binding the macAddress text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); } - ret = sqlite3_bind_text(stmt, 2, deviceName, strlen(deviceName), SQLITE_TRANSIENT); + ret = sqlite3_bind_text(stmt, 2, deviceType, strlen(deviceType), SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - _E("Statement binding the deviceName text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + _E("Statement binding the macAddress text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); } - ret = sqlite3_bind_text(stmt, 3, deviceIP, strlen(deviceIP), SQLITE_TRANSIENT); + ret = sqlite3_bind_text(stmt, 3, deviceName, strlen(deviceName), SQLITE_TRANSIENT); if (ret != SQLITE_OK) { - _E("Statement binding the deviceIP text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + _E("Statement binding the deviceName text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); } - ret = sqlite3_bind_int(stmt, 4, deviceState); + ret = sqlite3_bind_int(stmt, 4, aclState); if (ret != SQLITE_OK) { - _E("Statement binding the deviceState integer is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + _E("Statement binding the aclState integer is fail. (%d: %s)", ret, sqlite3_errmsg(database)); } ret = sqlite3_step(stmt); - if (ret != SQLITE_OK) { + if (ret != SQLITE_DONE) { _E("Statement step is fail. (%d: %s)", ret, sqlite3_errmsg(database)); } ret = database_finalize(database, stmt); - if(ret != SQLITE_OK){ + if (ret != SQLITE_OK) { return ACLResult_Error; } return ACLResult_OK; } - -ACLResult conv::acl_manager::GetACLState (const char *MacAddress, ACManagerPolicy *AclState) +ACLResult conv::acl_manager::GetACLState(const char *macAddress, ACManagerPolicy *aclState) { sqlite3 *database = NULL; sqlite3_stmt *stmt = NULL; @@ -296,38 +317,35 @@ ACLResult conv::acl_manager::GetACLState (const char *MacAddress, ACManagerPolic return ACLResult_Error; } - if(database == NULL) { - _E("DATABASE is NULL"); - } - _E("DATABASE is not NULL"); - - - ret = sqlite3_bind_text(stmt, 1, MacAddress, strlen(MacAddress), SQLITE_TRANSIENT); + char _mac[50]; + strcpy(_mac, macAddress); + _mac[1] = convert_mac(_mac[1]); + ret = sqlite3_bind_text(stmt, 1, _mac, strlen(_mac), SQLITE_TRANSIENT); if (ret != SQLITE_OK) { _E("MacAddress Bind fail. (%d: %s)", ret, sqlite3_errmsg(database)); } while (sqlite3_step(stmt) == SQLITE_ROW) { - *AclState = static_cast (sqlite3_column_int(stmt, 0)); + *aclState = static_cast (sqlite3_column_int(stmt, 0)); } ret = database_finalize(database, stmt); - if(ret != SQLITE_OK){ + if (ret != SQLITE_OK) { return ACLResult_Error; } return ACLResult_OK; } -ACLResult conv::acl_manager::AddACLDevice (const char *MacAddress, const char *deviceName, const char *deviceIP, ACManagerPolicy *AclState) +ACLResult conv::acl_manager::AddACLDevice(const char *macAddress, const char *deviceName, const char *deviceIP, ACManagerPolicy *aclState) { - if (AclState == NULL || MacAddress == NULL || deviceName == NULL || deviceIP == NULL) { + if (aclState == NULL || macAddress == NULL || deviceName == NULL || deviceIP == NULL) { return ACLResult_Error; } - *AclState = ACMANAGER_POLICY_U2; + *aclState = ACMANAGER_POLICY_U2; - int ret = conv::acl_manager::GetACLState(MacAddress, AclState); + int ret = conv::acl_manager::GetACLState(macAddress, aclState); if (ret != ACLResult_OK) { return ACLResult_Error; } @@ -335,29 +353,232 @@ ACLResult conv::acl_manager::AddACLDevice (const char *MacAddress, const char *d return ACLResult_OK; } -static ACLResult PrintDatabase () +static void RegistACLDevice(conv::Request *requestObj, const char *macAddress, const char *deviceType, const char *deviceName, ACManagerPolicy aclState) +{ + int ret = conv::acl_manager::SetDeviceInfoAndACL(macAddress, deviceType, deviceName, NULL, aclState); + if (ret != ACLResult_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + requestObj->reply(CONV_ERROR_NONE); + delete requestObj; +} + +static void ChangeACLState(conv::Request *requestObj, const char *macAddress, const char *deviceName, ACManagerPolicy aclState) { sqlite3 *database = NULL; sqlite3_stmt *stmt = NULL; - const char *get_table_info_all_query = "select MAC_ADDRESS, DEVICE_NAME, DEVICE_IP, ACL_STATE from DEVICES_INFO;"; + const char *set_acl_state_query = "update DEVICES_INFO SET DEVICE_NAME=?, ACL_STATE=? where MAC_ADDRESS=?;"; - int ret = database_initialize(&database, &stmt, get_table_info_all_query); + int ret = database_initialize(&database, &stmt, set_acl_state_query); if (ret != SQLITE_OK) { - return ACLResult_Error; + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + ret = sqlite3_bind_text(stmt, 1, deviceName, strlen(deviceName), SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + _E("Statement binding the deviceName text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + } + + ret = sqlite3_bind_int(stmt, 2, aclState); + if (ret != SQLITE_OK) { + _E("Statement binding the aclState integer is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + } + + char _mac[50]; + strcpy(_mac, macAddress); + _mac[1] = convert_mac(_mac[1]); + ret = sqlite3_bind_text(stmt, 3, _mac, strlen(_mac), SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + _E("Statement binding the macAddress text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + } + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _E("Statement step is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + } + + ret = database_finalize(database, stmt); + if (ret != SQLITE_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + requestObj->reply(CONV_ERROR_NONE); + delete requestObj; +} + +static void SetACLState(conv::Request *requestObj, const char *macAddress, const char *deviceType, const char *deviceName, ACManagerPolicy aclState) +{ + sqlite3 *database = NULL; + sqlite3_stmt *stmt = NULL; + + const char *is_exist_query = "select count(*) from DEVICES_INFO where MAC_ADDRESS=?;"; + + int ret = database_initialize(&database, &stmt, is_exist_query); + if (ret != SQLITE_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + char _mac[50]; + strcpy(_mac, macAddress); + _mac[1] = convert_mac(_mac[1]); + ret = sqlite3_bind_text(stmt, 1, _mac, strlen(_mac), SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + _E("Statement binding the macAddress text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); } + int count = 0; + while (sqlite3_step(stmt) == SQLITE_ROW) { - char *MacAddress = (char *)sqlite3_column_text(stmt, 0); - char *DeviceName = (char *)sqlite3_column_text(stmt, 1); - char *DeviceIP = (char *)sqlite3_column_text(stmt, 2); - ACManagerPolicy AclState = static_cast (sqlite3_column_int(stmt, 3)); - _I("MacAddress:%s, DeviceName:%s, IP:%s, State:%d", MacAddress, DeviceName, DeviceIP, AclState); + count = sqlite3_column_int(stmt, 0); } ret = database_finalize(database, stmt); - if(ret != SQLITE_OK){ - return ACLResult_Error; + if (ret != SQLITE_OK){ + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; } - return ACLResult_OK; + switch (count) + { + case 0 : RegistACLDevice(requestObj, macAddress, deviceType, deviceName, aclState); break; + case 1 : ChangeACLState(requestObj, macAddress, deviceName, aclState); break; + } +} + +static void RemoveACLDevice(conv::Request *requestObj, const char *macAddress) +{ + sqlite3 *database = NULL; + sqlite3_stmt *stmt = NULL; + const char *remove_acl_device_query = "delete from DEVICES_INFO WHERE MAC_ADDRESS=?;"; + + int ret = database_initialize(&database, &stmt, remove_acl_device_query); + if (ret != SQLITE_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + char _mac[50]; + strcpy(_mac, macAddress); + _mac[1] = convert_mac(_mac[1]); + ret = sqlite3_bind_text(stmt, 1, _mac, strlen(_mac), SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + _E("Statement binding the macAddress text is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + } + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _E("Statement step is fail. (%d: %s)", ret, sqlite3_errmsg(database)); + } + + ret = database_finalize(database, stmt); + if (ret != SQLITE_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + requestObj->reply(CONV_ERROR_NONE); + delete requestObj; +} + +static void GetACLDeviceList(conv::Request *requestObj) +{ + sqlite3 *database = NULL; + sqlite3_stmt *stmt = NULL; + const char *get_acl_device_list_query = "select MAC_ADDRESS, DEVICE_TYPE, DEVICE_NAME, ACL_STATE from DEVICES_INFO;"; + + int ret = database_initialize(&database, &stmt, get_acl_device_list_query); + if (ret != SQLITE_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + char *macAddress = (char *)sqlite3_column_text(stmt, 0); + char *deviceType = (char *)sqlite3_column_text(stmt, 1); + char *deviceName = (char *)sqlite3_column_text(stmt, 2); + ACManagerPolicy aclState = static_cast (sqlite3_column_int(stmt, 3)); + + _I("[ACL] MacAddress:%s, DeviceType:%s, DeviceName:%s, State:%d", macAddress, deviceType, deviceName, aclState); + + conv::Json result_data; + result_data.set(NULL, CONV_JSON_DEVICE_ID, macAddress); + result_data.set(NULL, CONV_JSON_DEVICE_TYPE, deviceType); + result_data.set(NULL, CONV_JSON_DEVICE_NAME, deviceName); + result_data.set(NULL, CONV_JSON_ACCESS_CONTROL_STATE, aclState); + requestObj->publish(CONV_ERROR_NONE, result_data); + } + + ret = database_finalize(database, stmt); + if (ret != SQLITE_OK) { + requestObj->reply(CONV_ERROR_INVALID_OPERATION); + delete requestObj; + return; + } + + requestObj->reply(CONV_ERROR_NONE); + delete requestObj; +} + +int conv::acl_manager::handleRequest(conv::Request *requestObj) +{ + if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_REGIST)) { + std::string mac_address; + std::string device_type; + std::string device_name; + int state; + + conv::Json output_data = requestObj->getDescription(); + output_data.get(NULL, CONV_JSON_DEVICE_ID, &mac_address); + output_data.get(NULL, CONV_JSON_DEVICE_TYPE, &device_type); + output_data.get(NULL, CONV_JSON_DEVICE_NAME, &device_name); + output_data.get(NULL, CONV_JSON_ACCESS_CONTROL_STATE, &state); + + ACManagerPolicy aclState = ACMANAGER_POLICY_U2; + switch(state) + { + case 0 : aclState = ACMANAGER_POLICY_P; break; + case 1 : aclState = ACMANAGER_POLICY_D; break; + } + + RegistACLDevice(requestObj, (const char*)mac_address.c_str(), (const char*)device_type.c_str(), (const char*)device_name.c_str(), aclState); + + } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_SET)) { + std::string mac_address; + std::string device_type; + std::string device_name; + int state; + + conv::Json output_data = requestObj->getDescription(); + output_data.get(NULL, CONV_JSON_DEVICE_ID, &mac_address); + output_data.get(NULL, CONV_JSON_DEVICE_TYPE, &device_type); + output_data.get(NULL, CONV_JSON_DEVICE_NAME, &device_name); + output_data.get(NULL, CONV_JSON_ACCESS_CONTROL_STATE, &state); + + ACManagerPolicy aclState = static_cast (state); + SetACLState(requestObj, (const char*)mac_address.c_str(), (const char*)device_type.c_str(), (const char*)device_name.c_str(), aclState); + + } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_REMOVE)) { + std::string mac_address; + conv::Json output_data = requestObj->getDescription(); + output_data.get(NULL, CONV_JSON_DEVICE_ID, &mac_address); + RemoveACLDevice(requestObj, (const char*)mac_address.c_str()); + + } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_ACCESS_CONTROL_GET)) { + GetACLDeviceList(requestObj); + } + + return CONV_ERROR_NONE; } \ No newline at end of file diff --git a/daemon/access_control/ACLManager.h b/daemon/access_control/ACLManager.h index a33d458..662f881 100644 --- a/daemon/access_control/ACLManager.h +++ b/daemon/access_control/ACLManager.h @@ -17,6 +17,22 @@ #ifndef __CONV_ACL_MANAGER_H__ #define __CONV_ACL_MANAGER_H__ +#include "Types.h" +#include "../Request.h" +#include "../Json.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DB_FILE_NAME "ACCESS_DEVICES.db" + typedef enum ACManagerPolicy { ACMANAGER_POLICY_P = 0, /* allowed/permitted */ ACMANAGER_POLICY_D, /* denied */ @@ -33,7 +49,7 @@ typedef enum ACLResult { } ACLResult; namespace conv { - namespace acl_manager { + namespace acl_manager { typedef void (*PopupCallback)(void *userdata, int result, char *passcode); @@ -47,10 +63,12 @@ namespace conv { ACLResult PasscodeChecker (char *input_passcode); - ACLResult GetACLState(const char *MacAddress, ACManagerPolicy *AclState); - ACLResult AddACLDevice(const char *MacAddress, const char *deviceName, const char *deviceIP, ACManagerPolicy *AclState); - ACLResult SetDeviceInfoAndACL(const char* MacAddress, const char* deviceName, const char* deviceIP, ACManagerPolicy deviceState); - } + ACLResult GetACLState(const char *macAddress, ACManagerPolicy *aclState); + ACLResult AddACLDevice(const char *macAddress, const char *deviceName, const char *deviceIP, ACManagerPolicy *aclState); + ACLResult SetDeviceInfoAndACL(const char* macAddress, const char *deviceType, const char* deviceName, const char* deviceIP, ACManagerPolicy aclState); + + int handleRequest(Request *requestObj); + } } -#endif /* End of __CONV_ACL_MANAGER_H__ */ +#endif /* End of __CONV_ACL_MANAGER_H__ */ diff --git a/daemon/discovery_provider/IotconDiscoveryProvider.cpp b/daemon/discovery_provider/IotconDiscoveryProvider.cpp index 58aebb2..4db7db7 100755 --- a/daemon/discovery_provider/IotconDiscoveryProvider.cpp +++ b/daemon/discovery_provider/IotconDiscoveryProvider.cpp @@ -352,7 +352,7 @@ int conv::IotconDiscoveryProvider::start() return CONV_ERROR_INVALID_OPERATION; } - ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4_ONLY | IOTCON_CONNECTIVITY_PREFER_UDP, + ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4, query, __found_resource, NULL); iotcon_query_destroy(query); diff --git a/daemon/service_provider/RemoteAppControlServiceProvider.cpp b/daemon/service_provider/RemoteAppControlServiceProvider.cpp index 7c58856..37fdf26 100755 --- a/daemon/service_provider/RemoteAppControlServiceProvider.cpp +++ b/daemon/service_provider/RemoteAppControlServiceProvider.cpp @@ -206,14 +206,18 @@ static void _app_control_cb(app_control_h request, app_control_h reply, app_cont static int __access_control(iotcon_request_h request, iotcon_attributes_h attributes) { + _D("Access Request Handling"); + string policy; char *deviceName; - - _D("Access Request Handling"); int ret = iotcon_attributes_get_str(attributes, CONV_JSON_DEVICE_NAME, &deviceName); IF_FAIL_RETURN_TAG(ret == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_PARAMETER, _E, "iotcon_representation_get_attributes() Fail(%d)", ret); + char *deviceType; + ret = iotcon_attributes_get_str(attributes, CONV_JSON_DEVICE_TYPE, &deviceType); + IF_FAIL_RETURN_TAG(ret == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_PARAMETER, _E, "iotcon_representation_get_attributes() Fail(%d)", ret); + char *hostAddress; ret = iotcon_request_get_host_address(request, &hostAddress); IF_FAIL_RETURN_TAG(ret == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_PARAMETER, _E, "iotcon_request_get_host_address() Fail(%d)", ret); @@ -225,14 +229,14 @@ static int __access_control(iotcon_request_h request, iotcon_attributes_h attrib IF_FAIL_RETURN_TAG(conv::util::getPeerMac(ip, -1, macAddress), CONV_ERROR_INVALID_PARAMETER, _E, "getPeerMac failed"); - _D("Device Name : %s, Device IP : %s, Mac : %s", deviceName, ip.c_str(), macAddress); + _D("Device Name : %s, Device IP : %s, Mac : %s, DeviceType : %s", deviceName, ip.c_str(), macAddress, deviceType); char *access_request_type = NULL; ret = iotcon_attributes_get_str(attributes, CONV_JSON_ACCESS_REQUEST_TYPE, &access_request_type); _D("Access Request : %s", access_request_type); IF_FAIL_RETURN_TAG(ret == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_PARAMETER, _E, "iotcon_representation_get_attributes() Fail(%d)", ret); - if(!strcmp(CONV_ACCESS_CONTROL_REQUEST, access_request_type)) { + if (!strcmp(CONV_ACCESS_CONTROL_REQUEST, access_request_type)) { ACManagerPolicy acManagerPolicy = ACMANAGER_POLICY_U; IF_FAIL_RETURN_TAG(AddACLDevice(macAddress, deviceName, ip.c_str(), &acManagerPolicy) == ACLResult_OK, CONV_ERROR_INVALID_OPERATION, _E, "AddACLDevice failed"); #if defined(_WEARABLE_) @@ -247,18 +251,16 @@ static int __access_control(iotcon_request_h request, iotcon_attributes_h attrib } else if (acManagerPolicy == ACMANAGER_POLICY_U){ _D("UNDECIDED"); policy = CONV_ACCESS_CONTROL_DENIED; -#if defined(_D2D_INTERNAL_ACL_) } else if (acManagerPolicy == ACMANAGER_POLICY_U2) { +#if defined(_D2D_INTERNAL_ACL_) _D("UNDECIDED"); conv::acl_manager::LaunchPasscodeShowPopup(deviceName); policy = CONV_ACCESS_CONTROL_PASSCODE_REQUEST; - } -#else - } #endif + } _D("acManagerPolicy:%d", acManagerPolicy); -#if defined(_D2D_INTERNAL_ACL_) } else if (!strcmp(CONV_ACCESS_CONTROL_PASSCODE_RESPONSE, access_request_type)) { +#if defined(_D2D_INTERNAL_ACL_) char *input_passcode; ret = iotcon_attributes_get_str(attributes, CONV_JSON_PASSCODE, &input_passcode); IF_FAIL_RETURN_TAG(ret == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_PARAMETER, _E, "iotcon_attributes_get_str() Fail(%d)", ret); @@ -266,22 +268,22 @@ static int __access_control(iotcon_request_h request, iotcon_attributes_h attrib ret = conv::acl_manager::PasscodeChecker(input_passcode); if (ret == ACLResult_OK) { policy = CONV_ACCESS_CONTROL_PASSCODE_RIGHT; - SetDeviceInfoAndACL(macAddress, deviceName, ip.c_str(), ACMANAGER_POLICY_P); + conv::acl_manager::SetDeviceInfoAndACL(macAddress, deviceType, deviceName, ip.c_str(), ACMANAGER_POLICY_P); conv::acl_manager::LaunchAccessAllowedToast(); } else if (ret == ACLResult_Error){ policy = CONV_ACCESS_CONTROL_PASSCODE_WRONG; } else if (ret == ACLResult_Close) { policy = CONV_ACCESS_CONTROL_PASSCODE_REJECTED; } - +#endif } else if (!strcmp(CONV_ACCESS_CONTROL_PASSCODE_CANCEL, access_request_type)) { +#if defined(_D2D_INTERNAL_ACL_) _D("Access Cancel Handling"); policy = CONV_ACCESS_CONTROL_DENIED; conv::acl_manager::LaunchPopupCancelToast(); - } -#else - } #endif + } + iotcon_response_result_e result; result = IOTCON_RESPONSE_OK; @@ -315,6 +317,7 @@ static int __app_control_launch(iotcon_request_h request, iotcon_attributes_h at _D("Device IP : %s, Mac : %s", ip.c_str(), macAddress); ACManagerPolicy acManagerPolicy = ACMANAGER_POLICY_U; + #if !defined(_WEARABLE_) IF_FAIL_RETURN_TAG(GetACLState(macAddress, &acManagerPolicy) == ACLResult_OK, CONV_ERROR_INVALID_OPERATION, _E, "ACL check failed"); if (acManagerPolicy == ACMANAGER_POLICY_P) { @@ -324,6 +327,7 @@ static int __app_control_launch(iotcon_request_h request, iotcon_attributes_h at return CONV_ERROR_INVALID_OPERATION; } #endif + app_control_h app_control; int reply = 0; char *appctl_char; @@ -569,26 +573,30 @@ static void __on_access_response(iotcon_remote_resource_h resource, iotcon_error svcInfo->accessControlState = ACCESS_CONTROL_STATE_PERMITTED; sendResponse(result, CONV_JSON_ON_START, CONV_ERROR_NONE, svcInfo->registeredRequest); return; -#if defined(_D2D_INTERNAL_ACL_) + } else if (!strcmp(CONV_ACCESS_CONTROL_PASSCODE_REQUEST, accessControlResult)) { +#if defined(_D2D_INTERNAL_ACL_) _D("__on_access_response PASSCODE REQUEST"); conv::acl_manager::LaunchPasscodeInputPopup(passcode_popup_callback, svcInfo); return; - +#endif } else if (!strcmp(CONV_ACCESS_CONTROL_PASSCODE_RIGHT, accessControlResult)) { +#if defined(_D2D_INTERNAL_ACL_) _D("__on_access_response PASSCODE RIGHT"); conv::acl_manager::LaunchAccessAllowedToast(); conv::Json result; svcInfo->accessControlState = ACCESS_CONTROL_STATE_PERMITTED; sendResponse(result, CONV_JSON_ON_START, CONV_ERROR_NONE, svcInfo->registeredRequest); return; - +#endif } else if (!strcmp(CONV_ACCESS_CONTROL_PASSCODE_WRONG, accessControlResult)) { +#if defined(_D2D_INTERNAL_ACL_) _D("__on_access_response PASSCODE WRONG"); conv::acl_manager::LaunchPasscodeWrongToast(); return; - +#endif } else if (!strcmp(CONV_ACCESS_CONTROL_PASSCODE_REJECTED, accessControlResult)) { +#if defined(_D2D_INTERNAL_ACL_) _D("__on_access_response PASSCODE REJECTED"); conv::acl_manager::LaunchAccessRejectedToast(); conv::Json result; @@ -619,13 +627,15 @@ static void passcode_popup_callback(void *user_data, int result, char *passcode) if (result == ACLResult_Cancel) { iotcon_attributes_add_str(attributes, CONV_JSON_REQUEST_TYPE, (char*)CONV_ACCESS_CONTROL_REQUEST); iotcon_attributes_add_str(attributes, CONV_JSON_ACCESS_REQUEST_TYPE, (char*)CONV_ACCESS_CONTROL_PASSCODE_CANCEL); - iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_NAME, (char*)svcInfo->deviceName.c_str()); + iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_NAME, (char*)conv::util::getDeviceName().c_str()); + iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_TYPE, (char*)conv::util::getDeviceType().c_str()); } else if (result == ACLResult_Connect) { iotcon_attributes_add_str(attributes, CONV_JSON_REQUEST_TYPE, (char*)CONV_ACCESS_CONTROL_REQUEST); iotcon_attributes_add_str(attributes, CONV_JSON_ACCESS_REQUEST_TYPE, (char*)CONV_ACCESS_CONTROL_PASSCODE_RESPONSE); iotcon_attributes_add_str(attributes, CONV_JSON_PASSCODE, passcode); - iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_NAME, (char*)svcInfo->deviceName.c_str()); + iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_NAME, (char*)conv::util::getDeviceName().c_str()); + iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_TYPE, (char*)conv::util::getDeviceType().c_str()); } iotcon_representation_set_attributes(representation, attributes); @@ -667,7 +677,7 @@ int conv::RemoteAppControlServiceProvider::startRequest(Request* requestObj) iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT); - error = iotcon_remote_resource_create(svcInfo->iotconInfoObj.address.c_str(), IOTCON_CONNECTIVITY_IPV4_ONLY, svcInfo->iotconInfoObj.uri.c_str(), properties, resource_types, resource_ifaces, + error = iotcon_remote_resource_create(svcInfo->iotconInfoObj.address.c_str(), IOTCON_CONNECTIVITY_IPV4, svcInfo->iotconInfoObj.uri.c_str(), properties, resource_types, resource_ifaces, &(svcInfo->iotconInfoObj.iotconResourceHandle)); _D("remote resource created : %s, %s", svcInfo->iotconInfoObj.address.c_str(), svcInfo->iotconInfoObj.uri.c_str()); @@ -686,6 +696,7 @@ int conv::RemoteAppControlServiceProvider::startRequest(Request* requestObj) iotcon_attributes_add_str(attributes, CONV_JSON_REQUEST_TYPE, (char*)CONV_ACCESS_CONTROL_REQUEST); iotcon_attributes_add_str(attributes, CONV_JSON_ACCESS_REQUEST_TYPE, (char*)CONV_ACCESS_CONTROL_REQUEST); iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_NAME, (char*)conv::util::getDeviceName().c_str()); + iotcon_attributes_add_str(attributes, CONV_JSON_DEVICE_TYPE, (char*)conv::util::getDeviceType().c_str()); iotcon_representation_set_attributes(representation, attributes); svcInfo->iotconInfoObj.iotconRepresentationHandle = representation; diff --git a/lib/conv_lib_acl.cpp b/lib/conv_lib_acl.cpp new file mode 100644 index 0000000..6c26a8b --- /dev/null +++ b/lib/conv_lib_acl.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2016 Samsung Electronics 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 +#include +#include "d2d_conv_internal.h" +#include "conv_lib_json.h" +#include "dbus_client.h" +#include "Types.h" + +EXTAPI int conv_internal_regist_acl_device(char *mac_address, char *device_type, char *device_name, int access_control_state) +{ + json input_data; + input_data.set(NULL, CONV_JSON_DEVICE_ID, mac_address); + input_data.set(NULL, CONV_JSON_DEVICE_TYPE, device_type); + input_data.set(NULL, CONV_JSON_DEVICE_NAME, device_name); + input_data.set(NULL, CONV_JSON_ACCESS_CONTROL_STATE, access_control_state); + + int req_id; + const char* input = const_cast (input_data.str().c_str()); + _D("input:%s", input); + + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_REGIST, input_data.str().c_str()); + IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_regist_acl_device()"); + + return CONV_ERROR_NONE; +} + +EXTAPI int conv_internal_set_acl_state(char *mac_address, char *device_type, char *device_name, int access_control_state) +{ + json input_data; + input_data.set(NULL, CONV_JSON_DEVICE_ID, mac_address); + input_data.set(NULL, CONV_JSON_DEVICE_TYPE, device_type); + input_data.set(NULL, CONV_JSON_DEVICE_NAME, device_name); + input_data.set(NULL, CONV_JSON_ACCESS_CONTROL_STATE, access_control_state); + + int req_id; + const char* input = const_cast (input_data.str().c_str()); + _D("input:%s", input); + + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_SET, input_data.str().c_str()); + IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_set_acl_state()"); + + return CONV_ERROR_NONE; +} + +EXTAPI int conv_internal_remove_acl_device(char *mac_address) +{ + json input_data; + input_data.set(NULL, CONV_JSON_DEVICE_ID, mac_address); + + int req_id; + const char* input = const_cast (input_data.str().c_str()); + _D("input:%s", input); + + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_REMOVE, input_data.str().c_str()); + IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_remove_acl_device())"); + + return CONV_ERROR_NONE; +} + +struct access_control_callback_info_s { + conv_access_control_list_foreach_cb cb; + void* user_data; +}; + +typedef std::map callback_map_t; +static callback_map_t callback_map; + +static void conv_subject_cb(const char *subject, int req_id, int error, json data) +{ + std::string mac_address; + std::string device_type; + std::string device_name; + int acl_state; + + data.get(NULL, CONV_JSON_DEVICE_ID, &mac_address); + data.get(NULL, CONV_JSON_DEVICE_TYPE, &device_type); + data.get(NULL, CONV_JSON_DEVICE_NAME, &device_name); + data.get(NULL, CONV_JSON_ACCESS_CONTROL_STATE, &acl_state); + + callback_map_t::iterator it = callback_map.find(req_id); + if (it == callback_map.end()) { + _E("No Callback found for response."); + return; + } + + access_control_callback_info_s *callback_info = it->second; + callback_info->cb((char*)mac_address.c_str(), (char*)device_type.c_str(), (char*)device_name.c_str(), acl_state, callback_info->user_data); +} + +static void register_subject_callbacks() +{ + conv::dbus_client::register_callback(CONV_SUBJECT_ACCESS_CONTROL_GET, conv_subject_cb); + _I("Done with registering subject callback"); +} + +EXTAPI int conv_internal_get_acl_list(conv_access_control_list_foreach_cb callback, void *user_data) +{ + register_subject_callbacks(); + + access_control_callback_info_s *cb_info = new(std::nothrow)access_control_callback_info_s(); + cb_info->cb = callback; + cb_info->user_data = user_data; + + int req_id; + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_GET, NULL); + IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_get_acl_list()"); + + callback_map[req_id] = cb_info; + + return CONV_ERROR_NONE; +} \ No newline at end of file diff --git a/lib/include/d2d_conv_internal.h b/lib/include/d2d_conv_internal.h index 327bbda..4c60093 100755 --- a/lib/include/d2d_conv_internal.h +++ b/lib/include/d2d_conv_internal.h @@ -52,11 +52,11 @@ extern "C" { * @param[out] value The result value * * @return 0 on success, otherwise a negative error value - * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_NONE Successful * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONV_ERROR_NOT_SUPPORTED Not supported * @retval #CONV_ERROR_NO_DATA No Data - * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory * */ int conv_channel_internal_export_to_string(conv_channel_h handle, char** value); @@ -70,11 +70,11 @@ int conv_channel_internal_export_to_string(conv_channel_h handle, char** value); * @param[out] value The result value * * @return 0 on success, otherwise a negative error value - * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_NONE Successful * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONV_ERROR_NOT_SUPPORTED Not supported * @retval #CONV_ERROR_NO_DATA No Data - * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory * */ int conv_payload_internal_export_to_string(conv_payload_h handle, char** value); @@ -86,11 +86,11 @@ int conv_payload_internal_export_to_string(conv_payload_h handle, char** value); * @param[in] activation_state The activation state to set * * @return 0 on success, otherwise a negative error value - * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_NONE Successful * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONV_ERROR_NOT_SUPPORTED Not supported * @retval #CONV_ERROR_NO_DATA No Data - * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory * */ int conv_internal_set_activation_state(int activation_state); @@ -102,11 +102,11 @@ int conv_internal_set_activation_state(int activation_state); * @param[out] activation_state The current activation state * * @return 0 on success, otherwise a negative error value - * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_NONE Successful * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONV_ERROR_NOT_SUPPORTED Not supported * @retval #CONV_ERROR_NO_DATA No Data - * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory * */ int conv_internal_get_activation_state(int* activation_state); @@ -118,11 +118,11 @@ int conv_internal_get_activation_state(int* activation_state); * @param[in] activation_state The activation state to set * * @return 0 on success, otherwise a negative error value - * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_NONE Successful * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONV_ERROR_NOT_SUPPORTED Not supported * @retval #CONV_ERROR_NO_DATA No Data - * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory * */ int conv_internal_set_service_activation_state(int activation_state); @@ -134,15 +134,106 @@ int conv_internal_set_service_activation_state(int activation_state); * @param[in] activation_state The activation state to set * * @return 0 on success, otherwise a negative error value - * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_NONE Successful * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONV_ERROR_NOT_SUPPORTED Not supported * @retval #CONV_ERROR_NO_DATA No Data - * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory * */ int conv_internal_get_service_activation_state(int* activation_state); +/** + * @brief Regist D2D Convergence access device + * @since_tizen 3.0 + * + * @param[in] mac_address The access device mac address + * @param[in] device_type The access device device type + * @param[in] device_name The access device device name + * @param[in] access_control_state The access device access state + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * @retval #CONV_ERROR_NO_DATA No Data + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int conv_internal_regist_acl_device(char *mac_address, char *device_type, char *device_name, int access_control_state); + +/** + * @brief Remove D2D Convergence access device + * @since_tizen 3.0 + * + * @param[in] mac_address The access device mac address + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * @retval #CONV_ERROR_NO_DATA No Data + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int conv_internal_remove_acl_device(char *mac_address); + +/** + * @brief Set D2D Convergence access state + * @since_tizen 3.0 + * + * @param[in] mac_address The access device mac address + * @param[in] device_type The access device device type + * @param[in] device_name The access device device name + * @param[in] access_control_state The access device access state + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * @retval #CONV_ERROR_NO_DATA No Data + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int conv_internal_set_acl_state(char *mac_address, char *device_type, char *device_name, int access_control_state); + +/** + * @brief Called for each D2D Convergence access devices information + * @since_tizen 3.0 + * + * @param[in] mac_address The access device mac address + * @param[in] device_type The access device device type + * @param[in] device_name The access device device name + * @param[in] access_control_state The access device access state + * @param[in] user_data The user data + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * @retval #CONV_ERROR_NO_DATA No Data + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * + */ +typedef void(* conv_access_control_list_foreach_cb)(char *mac_address, char *device_type, char *device_name, int access_control_state, void* user_data); + +/** + * @brief Get D2D Convergence access devices information + * @since_tizen 3.0 + * + * @param[in] callback The callback function to get each access devices information + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * @retval #CONV_ERROR_NO_DATA No Data + * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int conv_internal_get_acl_list(conv_access_control_list_foreach_cb callback, void *user_data); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/msf_tizen_client/include/SearchProvider.h b/msf_tizen_client/include/SearchProvider.h index ef50144..d627ae0 100644 --- a/msf_tizen_client/include/SearchProvider.h +++ b/msf_tizen_client/include/SearchProvider.h @@ -36,7 +36,6 @@ class Search; class ttl_info { - private: long msfd_ttl; long mdns_ttl; @@ -75,7 +74,6 @@ protected: Service getServiceById(string id); static Service getServiceByIp(string ip); static map aliveMap; - }; #endif diff --git a/msf_tizen_client/include/mDNSSearchProvider.h b/msf_tizen_client/include/mDNSSearchProvider.h index f9f0f6e..e03c547 100644 --- a/msf_tizen_client/include/mDNSSearchProvider.h +++ b/msf_tizen_client/include/mDNSSearchProvider.h @@ -45,7 +45,6 @@ public: class MDNSServiceCallback : public Result_Base { - private: mDNSSearchProvider* provider; diff --git a/msf_tizen_client/src/Channel.cpp b/msf_tizen_client/src/Channel.cpp index 4248c06..5c54858 100755 --- a/msf_tizen_client/src/Channel.cpp +++ b/msf_tizen_client/src/Channel.cpp @@ -268,7 +268,6 @@ void Channel::foreach_json_object(JsonObject *object, const gchar *name, p->msg_id = json_node_get_int(node); MSF_DBG("msg-id set as %d", p->msg_id); } else if (json_node_get_value_type(node) == G_TYPE_STRING) { - if (json_object_has_member(root_json_object, Message::PROPERTY_EVENT.c_str())) { p->eventType = json_object_get_string_member(root_json_object, Message::PROPERTY_EVENT.c_str()); @@ -401,7 +400,6 @@ void Channel::setConnectionTimeout(long timeout) { } void Channel::handleConnectMessage(string UID) { - clients->reset(); clients->add(clientList); @@ -534,7 +532,6 @@ void Channel::emit(string event, const char *msg, string from, } if (messageListeners.size() != 0) { - if (messageListeners.find(event) == messageListeners.end()) { return; } @@ -579,7 +576,6 @@ bool Channel::connect(Result_Base *result1) { } bool Channel::connect(map attributes, Result_Base *result1) { - string uid = getUID(); registerCallback(uid, (void *)result1, Result_Client); @@ -800,8 +796,6 @@ void Channel::write_socket(Channel* ch_p) if (ch_p->write_buf_count) { lws_callback_on_writable(ch_p->wsi_mirror); } - - } } @@ -966,7 +960,7 @@ void Channel::publish(string event, const char *data, unsigned char payload[], publishMessage(event, data, to.c_str(), payload, payload_size, user_data); } -void Channel::publish(string event, const char *data, const char *target, +void Channel::publish(string event, const char *data, const char *target, void *user_data) { string to = "\""; @@ -984,7 +978,7 @@ void Channel::publish(string event, const char *data, const char *target, publishMessage(event, data, to.c_str(), payload, payload_size, user_data); } -void Channel::publish(string event, const char *data, Client client, +void Channel::publish(string event, const char *data, Client client, void* user_data) { string to = "\""; @@ -1043,7 +1037,6 @@ void Channel::publishMessage(string method, string event, const char *data, handleError(string(), Error::create("Not Connected")); return; } else { - if (write_buf_index == 999 && write_buf_count != 999) { write_buf_index = 0; } @@ -1332,7 +1325,6 @@ void Channel::create_websocket(void *att) { Context = NULL; wsi_mirror = NULL; } - } void Channel::get_ip_port_from_uri(string uri, string* dest_ip, int* dest_port) { diff --git a/msf_tizen_client/src/MSFDSearchProvider.cpp b/msf_tizen_client/src/MSFDSearchProvider.cpp index f7e16d4..1217621 100755 --- a/msf_tizen_client/src/MSFDSearchProvider.cpp +++ b/msf_tizen_client/src/MSFDSearchProvider.cpp @@ -265,7 +265,6 @@ void MSFDSearchProvider::processReceivedMsg(char *buf, int buflen) if (state == TYPE_DISCOVER) { return; } else if (state == STATE_ALIVE || state == STATE_UP) { - if (itr == aliveMap.end()) { ResultMSFDServiceCallback *rService = new ResultMSFDServiceCallback(); rService->MSFDSearchProvider_pointer = this; diff --git a/msf_tizen_client/src/SearchProvider.cpp b/msf_tizen_client/src/SearchProvider.cpp index 9d8f3a7..2c4bab5 100755 --- a/msf_tizen_client/src/SearchProvider.cpp +++ b/msf_tizen_client/src/SearchProvider.cpp @@ -28,12 +28,10 @@ ttl_info::ttl_info(long ttl, int service_type):msfd_ttl(0), mdns_ttl(0) msfd_ttl = ttl; else if (service_type == MDNS) mdns_ttl = ttl; - } ttl_info::ttl_info():msfd_ttl(0), mdns_ttl(0) { - } long ttl_info:: get_ttl(int service_type) @@ -44,7 +42,6 @@ long ttl_info:: get_ttl(int service_type) return mdns_ttl; else return -1; - } void ttl_info::update_ttl(long ttl, int service_type) @@ -117,7 +114,6 @@ Service SearchProvider::getServiceByIp(string ip) { std::list::iterator iterator; for (iterator = Search::services.begin(); iterator != Search::services.end(); ++iterator) { - string url = (*iterator).getUri(); std::string::size_type pos = url.find(ip); if (pos != string::npos) { diff --git a/msf_tizen_client/src/mDNSSearchProvider.cpp b/msf_tizen_client/src/mDNSSearchProvider.cpp index edf5ff6..ad304b7 100755 --- a/msf_tizen_client/src/mDNSSearchProvider.cpp +++ b/msf_tizen_client/src/mDNSSearchProvider.cpp @@ -228,7 +228,6 @@ static void dnssd_browse_reply(dnssd_service_state_e service_state, dnssd_servic void mDNSSearchProvider::start() { - if (!service_cb) service_cb = new MDNSServiceCallback(this);