From 1a06926464f7e0944ff2734b80b41f3931d4c8db Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Wed, 21 Feb 2018 16:11:44 +0900 Subject: [PATCH 01/16] Add new AccessControl and Remove sender_appid from dbus - Add new AccessControl for trusted app - Remove sender_appid that was passed through dbus Change-Id: I648bdbfa8bc97a8c363ffa994ebe5d71a10c6288 Signed-off-by: Inkyun Kil --- include/rpc-port.h | 3 +++ src/ac-internal.cc | 66 ++++++++++++++++++++++++++++++++++++++++-------- src/ac-internal.h | 14 +++++++--- src/fdbroker-internal.cc | 66 ++++++++++++++++++++++++++++++++++++------------ src/fdbroker-internal.h | 3 ++- src/rpc-port.cc | 13 ++++++++++ src/stub-internal.cc | 5 ++++ src/stub-internal.h | 1 + 8 files changed, 140 insertions(+), 31 deletions(-) diff --git a/include/rpc-port.h b/include/rpc-port.h index 7897990..855c14e 100755 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -21,6 +21,8 @@ extern "C" { #endif +#include + /* common */ typedef void *rpc_port_h; int rpc_port_read(rpc_port_h h, void *buf, unsigned int size); @@ -62,6 +64,7 @@ int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name); int rpc_port_stub_destroy(rpc_port_stub_h h); int rpc_port_stub_listen(rpc_port_stub_h h); int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege); +int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted); int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void *data); int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 7ce273c..97f47af 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -18,7 +18,9 @@ #define _GNU_SOURCE #endif +#include #include +#include #include #include @@ -39,12 +41,11 @@ void AccessController::AddPrivilege(const std::string& privilege) { privileges_.push_back(privilege); } -int AccessController::CheckPrivilege(GDBusConnection *connection, const char* sender_appid) { - Cynara c; - - if (c.FetchCredsFromDBus(connection, sender_appid) != 0 ) - return -1; +void AccessController::SetTrusted(const bool trusted) { + trusted_ = trusted; +} +int AccessController::CheckPrivilege(Cynara& c) { for (auto& privilege : privileges_) { if (c.Check(privilege) != 0) { return -1; @@ -54,6 +55,51 @@ int AccessController::CheckPrivilege(GDBusConnection *connection, const char* se return 0; } +int AccessController::CheckTrusted(const char* sender_appid) { + if (appid_.empty()) { + char appid[255]; + if (aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)) < 0) + return -1; + + appid_ = appid; + } + + LOGD("CheckCertificate : %s :: %s", appid_.c_str(), sender_appid); + pkgmgrinfo_cert_compare_result_type_e res; + int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(appid_.c_str(), sender_appid, getuid(), &res); + if (ret < 0) { + LOGE("CheckCertificate() Failed"); + return -1; + } + if (res != PMINFO_CERT_COMPARE_MATCH) { + LOGE("CheckCertificate() Failed : MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH"); + return -1; + } + + return 0; +} + +int AccessController::Check(GDBusConnection* connection, const char* sender, + const char* sender_appid) { + Cynara c; + int ret = 0; + + if (c.FetchCredsFromDBus(connection, sender) != 0) + return -1; + + if (!privileges_.empty()) { + ret = CheckPrivilege(c); + if (ret) + return ret; + } + + if (trusted_) { + ret = CheckTrusted(sender_appid); + } + + return ret; +} + int AccessController::SetCache(const std::string& sender) { return -1; } @@ -77,7 +123,7 @@ AccessController::Cynara::~Cynara() { cynara_finish(cynara_); } -int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection *connection, const char *sender_appid) { +int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, const char* sender) { int ret; if (client_) { @@ -90,13 +136,13 @@ int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection *connection, co user_ = nullptr; } - ret = cynara_creds_gdbus_get_user(connection, sender_appid, USER_METHOD_DEFAULT, &user_); + ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user_); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_user() is failed : %d", ret); return -1; } - ret = cynara_creds_gdbus_get_client(connection, sender_appid, CLIENT_METHOD_DEFAULT, &client_); + ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client_); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_client() is failed : %d", ret); return -1; @@ -107,9 +153,9 @@ int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection *connection, co } int AccessController::Cynara::Check(const std::string& privilege) { - LOGD("check %s", privilege.c_str()); + LOGD("check privilege %s", privilege.c_str()); if (cynara_check(cynara_, client_, "", user_, privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) { - LOGE("cynara_check() is failed : %s", privilege.c_str()); + LOGD("cynara_check() is not allowed : %s", privilege.c_str()); return -1; } diff --git a/src/ac-internal.h b/src/ac-internal.h index 1948ff0..9a9ae63 100644 --- a/src/ac-internal.h +++ b/src/ac-internal.h @@ -31,20 +31,20 @@ namespace internal { class AccessController { public: + AccessController(bool trusted = false) : trusted_(trusted) {} virtual ~AccessController(); void AddPrivilege(const std::string& privilege); - int CheckPrivilege(GDBusConnection *connection, const char* sender_appid); + void SetTrusted(const bool trusted); + int Check(GDBusConnection *connection, const char *sender, const char* sender_appid); private: - int SetCache(const std::string& sender); - class Cynara { public: Cynara(); ~Cynara(); - int FetchCredsFromDBus(GDBusConnection *connection, const char *sender_appid); + int FetchCredsFromDBus(GDBusConnection *connection, const char *sender); int Check(const std::string& privilege); private: @@ -53,9 +53,15 @@ class AccessController { char *user_; }; + int SetCache(const std::string& sender); + int CheckTrusted(const char *sender_appid); + int CheckPrivilege(Cynara& c); + private: std::vector privileges_; std::map cache_; + bool trusted_; + std::string appid_; }; } // namespace internal diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 451ab34..ce59d32 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -225,7 +225,6 @@ int FdBroker::Send(const std::string& target_appid, GDBusMessage *msg; GDBusMessage *reply; GError *err = nullptr; - GVariant *body; GVariant *reply_body; SocketPair sock_pair(mock_); FdList fd_list; @@ -261,9 +260,7 @@ int FdBroker::Send(const std::string& target_appid, return -1; } - body = g_variant_new("(s)", sender_appid); g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); - g_dbus_message_set_body(msg, body); reply = g_dbus_connection_send_message_with_reply_sync(DBusConnectionManager::GetInst().GetConnection(), msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, nullptr, nullptr, &err); @@ -298,21 +295,13 @@ int FdBroker::Send(const std::string& target_appid, return fd; } -void FdBroker::ReceiveMessage(GVariant* parameters, +void FdBroker::ReceiveMessage(const char* sender_appid, GDBusMethodInvocation* invocation) { - char* sender_appid = nullptr; GDBusMessage* msg; GUnixFDList* fd_list; int fd_len; int* returned_fds = nullptr; - g_variant_get(parameters, "(&s)", &sender_appid); - - if (sender_appid == nullptr) { - LOGE("Invalid argument : sender_appid is NULL"); - return; - } - msg = g_dbus_method_invocation_get_message(invocation); fd_list = g_dbus_message_get_unix_fd_list(msg); @@ -335,12 +324,20 @@ void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { FdBroker* broker = static_cast(user_data); - int ret; + int ret = -1; + char sender_appid[255]; + int sender_pid; + + sender_pid = broker->GetSenderPid(conn, sender); + if (aul_app_get_appid_bypid(sender_pid, sender_appid, sizeof(sender_appid)) < 0) { + g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret)); + return; + } AccessController& ac = broker->GetAccessController(); - ret = ac.CheckPrivilege(conn, sender); + ret = ac.Check(conn, sender, sender_appid); if (ret == 0) - broker->ReceiveMessage(parameters, invocation); + broker->ReceiveMessage(sender_appid, invocation); g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret)); } @@ -386,6 +383,44 @@ int FdBroker::GetOwnerId(const std::string& interface_name) { return owner_id; } +int FdBroker::GetSenderPid(GDBusConnection *connection, const gchar *sender) { + GDBusMessage *msg = NULL; + GDBusMessage *reply = NULL; + GError *err = NULL; + GVariant *body; + int pid = 0; + + msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", + "org.freedesktop.DBus", "GetConnectionUnixProcessID"); + if (!msg) { + LOGE("Can't allocate new method call"); + goto out; + } + + g_dbus_message_set_body(msg, g_variant_new("(s)", sender)); + reply = g_dbus_connection_send_message_with_reply_sync(connection, msg, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err); + + if (!reply) { + if (err != NULL) { + LOGE("Failed to get pid [%s]", err->message); + g_error_free(err); + } + goto out; + } + + body = g_dbus_message_get_body(reply); + g_variant_get(body, "(u)", &pid); + +out: + if (msg) + g_object_unref(msg); + if (reply) + g_object_unref(reply); + + return pid; +} + int FdBroker::RegisterDbusInterface(const std::string& port_name) { static const GDBusInterfaceVTable interface_vtable = { OnReceiveDbusMethod, @@ -398,7 +433,6 @@ int FdBroker::RegisterDbusInterface(const std::string& port_name) { static const char introspection_postfix[] = "'>" " " - " " " " " " " " diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index 77ff32d..b5fba79 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -143,8 +143,9 @@ class FdBroker { GDBusMethodInvocation *invocation, gpointer user_data); int GetOwnerId(const std::string& interface_name); + int GetSenderPid(GDBusConnection *connection, const gchar *sender); int RegisterDbusInterface(const std::string& port_name); - void ReceiveMessage(GVariant* parameters, GDBusMethodInvocation* invocation); + void ReceiveMessage(const char* sender_appid, GDBusMethodInvocation* invocation); std::string GetInterfaceName(const std::string& target_appid, const std::string& port_name); static void OnNameAppeared(GDBusConnection *connection, diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 5c81f93..3c9e142 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -331,6 +331,19 @@ RPC_API int rpc_port_stub_add_privilege(rpc_port_stub_h h, return 0; } +RPC_API int rpc_port_stub_set_trusted(rpc_port_stub_h h, + const bool trusted) { + if (h == nullptr) + return -1; + + auto p = static_cast<::StubExt*>(h); + std::lock_guard lock(p->GetMutex()); + + p->SetTrusted(trusted); + return 0; +} + + RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void* data) { if (h == nullptr) diff --git a/src/stub-internal.cc b/src/stub-internal.cc index 18a2dbb..c981ba5 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -55,6 +55,11 @@ void Stub::AddPrivilege(const std::string& privilege) { ac.AddPrivilege(privilege); } +void Stub::SetTrusted(const bool trusted) { + AccessController& ac = fd_broker_.GetAccessController(); + ac.SetTrusted(trusted); +} + gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, gpointer data) { Stub* stub = static_cast(data); diff --git a/src/stub-internal.h b/src/stub-internal.h index 5819428..ab89aa3 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -48,6 +48,7 @@ class Stub : private FdBroker::IEventListener { void Listen(IEventListener* ev); void AddPrivilege(const std::string& privilege); + void SetTrusted(const bool trusted); private: class AcceptedPort : public Port { -- 2.7.4 From 222d23abac285fbd4e96250233fbc70590833ae0 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Wed, 7 Mar 2018 11:03:54 +0900 Subject: [PATCH 03/16] Add doxygen for header file Change-Id: Ie0b683f3e96ba92b986483f5cc57d72a51857ce0 Signed-off-by: Inkyun Kil --- doc/rpc-port_doc.h | 45 +++++ include/rpc-port-internal.h | 6 +- include/rpc-port-parcel.h | 347 ++++++++++++++++++++++++++++++++++++++- include/rpc-port.h | 388 +++++++++++++++++++++++++++++++++++++++++--- src/port-internal.cc | 17 +- src/rpc-port-parcel.cc | 107 ++++++------ src/rpc-port.cc | 86 +++++----- 7 files changed, 860 insertions(+), 136 deletions(-) create mode 100644 doc/rpc-port_doc.h diff --git a/doc/rpc-port_doc.h b/doc/rpc-port_doc.h new file mode 100644 index 0000000..2c1cf87 --- /dev/null +++ b/doc/rpc-port_doc.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef __RPC_PORT_DOC_H__ +#define __RPC_PORT_DOC_H__ + + +/** + * @ingroup CAPI_APPLICATION_FRAMEWORK + * @defgroup CAPI_RPC_PORT_MODULE RPC Port + * @brief The @ref CAPI_RPC_PORT_MODULE API provides functions to send and receive messages between applications. + * @section CAPI_RPC_PORT_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_RPC_PORT_MODULE_OVERVIEW Overview + * The @ref CAPI_RPC_PORT_MODULE API provides functions for passing messages between applications. + * Applications can read and write data by using rpc-port. +*/ + +/** + * @ingroup CAPI_RPC_PORT_MODULE + * @defgroup CAPI_RPC_PORT_PARCEL_MODULE RPC Port Parcel + * @brief The @ref CAPI_RPC_PORT_PRCEL_MODULE API provides functions to make parcel data + * @section CAPI_PACKAGE_INFO_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_RPC_PORT_PARCEL_MODULE_OVERVIEW Overview + * It is container for a data that can be sent via RPCPort. +*/ + + +#endif /* __RPC_PORT_DOC_H__ */ diff --git a/include/rpc-port-internal.h b/include/rpc-port-internal.h index 1f7db12..5a9af2a 100644 --- a/include/rpc-port-internal.h +++ b/include/rpc-port-internal.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __RPC_PORT_INTERNAL_INCLUDE_H__ -#define __RPC_PORT_INTERNAL_INCLUDE_H__ +#ifndef __TIZEN_APPFW_RPC_PORT_INTERNAL_INCLUDE_H__ +#define __TIZEN_APPFW_RPC_PORT_INTERNAL_INCLUDE_H__ #include @@ -30,7 +30,7 @@ int rpc_port_stub_create_mockup(rpc_port_stub_h *h, const char *port_name); } #endif -#endif /* __RPC_PORT_INTERNAL_INCLUDE_H__ */ +#endif /* __TIZEN_APPFW_RPC_PORT_INTERNAL_INCLUDE_H__ */ diff --git a/include/rpc-port-parcel.h b/include/rpc-port-parcel.h index 847e0a5..04e9a23 100644 --- a/include/rpc-port-parcel.h +++ b/include/rpc-port-parcel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __RPC_PORT_PARCEL_INCLUDE_H__ -#define __RPC_PORT_PARCEL_INCLUDE_H__ +#ifndef __TIZEN_APPFW_RPC_PORT_PARCEL_INCLUDE_H__ +#define __TIZEN_APPFW_RPC_PORT_PARCEL_INCLUDE_H__ #include #include @@ -25,41 +25,380 @@ extern "C" { #endif +/** + * @addtogroup CAPI_RPC_PORT_PARCEL_MODULE + * @{ + */ + +/** + * @brief The rpc port parcel handle. + * @since_tizen 5.0 + */ typedef void *rpc_port_parcel_h; + +/** + * @brief The interface for converting data to/from a parcel. + * @since_tizen 5.0 + */ typedef struct __rpc_port_parcelable { void (*to)(rpc_port_parcel_h h, void *data); void (*from)(rpc_port_parcel_h h, void *data); } rpc_port_parcelable_t; +/** + * @brief Creates a rpc port parcel handle. + * @since_tizen 5.0 + * @remarks You must release @a h using rpc_port_parcel_destroy(). + * @param[out] h The rpc port parcel handle that is newly created + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @see rpc_port_parcel_destroy() + */ int rpc_port_parcel_create(rpc_port_parcel_h *h); + +/** + * @brief Creates a rpc port parcel handle from port. + * @details Creates a rpc port parcel handle using read data from the port. + * It calls rpc_port_read() internally. + * @since_tizen 5.0 + * @remarks You must release @a h using rpc_port_parcel_destroy(). + * @param[out] h The rpc port parcel handle that is newly created + * @param[in] port The rpc port handle for creating handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + * @see rpc_port_parcel_destroy() + * @see rpc_port_parcel_send() + */ int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port); + +/** + * @brief Sends parcel data through the port. + * @details Sends parcel data through the port. It calls rpc_port_write() + * internally. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle that is newly created + * @param[in] port The rpc port handle for writing data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + * @see rpc_port_parcel_create_from_port() + */ int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port); + +/** + * @brief Destroys a rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_create() + */ int rpc_port_parcel_destroy(rpc_port_parcel_h h); + +/** + * @brief Writes a byte value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] b Byte data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_byte() + */ int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b); + +/** + * @brief Writes a short value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] i short data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_int16() + */ int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i); + +/** + * @brief Writes a integer value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] i int data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_int32() + */ int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i); + +/** + * @brief Writes a long long integer value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] i long long data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_int64() + */ int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i); + +/** + * @brief Writes a floating point value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] f float data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_float() + */ int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f); + +/** + * @brief Writes a double precision floating point value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] d double data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_double() + */ int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d); + +/** + * @brief Writes a string value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] str string data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_string() + */ int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char *str); + +/** + * @brief Writes a boolean value into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] b boolean data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_bool() + */ int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b); + +/** + * @brief Writes a bundle data into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] b Bundle data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_bundle() + */ int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle *b); + +/** + * @brief Writes a count for array into rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] count Array count + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read_array_count() + */ int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count); + +/** + * @brief Writes the data into parcel handle using @a parcelable. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] parcelable The interface to write the data into parcel handle + * @param[in] data Data which write into parcel + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_read() + */ int rpc_port_parcel_write(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable, void *data); + +/** + * @brief Reads a byte value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] b Byte data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_byte() + */ int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char *b); + +/** + * @brief Reads a short value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] i short data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_int16() + */ int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i); + +/** + * @brief Reads a integer value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] i int data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_int32() + */ int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int *i); + +/** + * @brief Reads a long long integer value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] i long long data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_int64() + */ int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long *i); + +/** + * @brief Reads a floating point value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] f float data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_float() + */ int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f); + +/** + * @brief Reads a double precision floating point value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] d double data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_double() + */ int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d); + +/** + * @brief Reads a string value from rpc port parcel handle. + * @since_tizen 5.0 + * @remarks The @a str should be released using free(). + * @param[in] h The rpc port parcel handle + * @param[out] str string data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_string() + */ int rpc_port_parcel_read_string(rpc_port_parcel_h h, char **str); + +/** + * @brief Reads a boolean value from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] b boolean data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_bool() + */ int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b); + +/** + * @brief Reads a bundle data from rpc port parcel handle. + * @since_tizen 5.0 + * @remarks The @a b should be released using bundle_free(). + * @param[in] h The rpc port parcel handle + * @param[out] b Bundle data + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_bundle() + */ int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle **b); + +/** + * @brief Reads a count for array from rpc port parcel handle. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[out] count Array count + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_array_count() + */ int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count); + +/** + * @brief Reads a parcel from the data using @a parcelable. + * @since_tizen 5.0 + * @param[in] h The rpc port parcel handle + * @param[in] parcelable The interface to get data from parcel handle + * @param[in] data Data which get from parcel + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write() + */ int rpc_port_parcel_read(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable, void *data); +/** + * @} + */ + #ifdef __cplusplus } #endif -#endif // __RPC_PORT_PARCEL_INCLUDE_H__ +#endif // __TIZEN_APPFW_RPC_PORT_PARCEL_INCLUDE_H__ diff --git a/include/rpc-port.h b/include/rpc-port.h index 855c14e..14983bf 100755 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -14,66 +14,404 @@ * limitations under the License. */ -#ifndef __RPC_PORT_INCLUDE_H__ -#define __RPC_PORT_INCLUDE_H__ +#ifndef __TIZEN_APPFW_RPC_PORT_INCLUDE_H__ +#define __TIZEN_APPFW_RPC_PORT_INCLUDE_H__ #ifdef __cplusplus extern "C" { #endif #include +#include -/* common */ +/** + * @addtogroup CAPI_RPC_PORT_MODULE + * @{ + */ + + +/** + * @brief Enumeration for error codes of a rpc port. + * @since_tizen 4.0 + */ +typedef enum { + RPC_PORT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + RPC_PORT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */ + RPC_PORT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + RPC_PORT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + RPC_PORT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ +} rpc_port_error_e; + +/* Common */ + +/** + * @brief The rpc port handle. + * @since_tizen 5.0 + */ typedef void *rpc_port_h; + +/** + * @brief Reads data from an RPC port. + * @since_tizen 5.0 + * + * @param[in] h The rpc port handle + * @param[out] buf Buffer for reading data + * @param[in] size Size for reading data + * + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + * @see rpc_port_write() + */ int rpc_port_read(rpc_port_h h, void *buf, unsigned int size); + +/** + * @brief Writes data to an RPC port. + * @since_tizen 5.0 + * + * @param[in] h The rpc port handle + * @param[in] buf Buffer for writing data + * @param[in] size Size for writing data + * + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + * @see rpc_port_read() + */ int rpc_port_write(rpc_port_h h, const void *buf, unsigned int size); -/* proxy */ -typedef void (*rpc_port_proxy_connected_event_cb)(const char *ep, - const char *port_name, rpc_port_h port, void *data); -typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *ep, - const char *port_name, void *data); -typedef void (*rpc_port_proxy_rejected_event_cb)(const char *ep, - const char *port_name, void *data); -typedef void (*rpc_port_proxy_received_event_cb)(const char *ep, - const char *port_name, void *data); + +/* Proxy */ + +/** + * @brief Called when the proxy is connected. + * @details The function is called when the proxy is connected with stub by port. + * @since_tizen 5.0 + * @param[in] receiver The target stub app id + * @param[in] port_name The name of the port + * @param[in] port The rpc port handle for reading and writing + * @param[in] user_data The user data passed from the register function + */ +typedef void (*rpc_port_proxy_connected_event_cb)(const char *receiver, + const char *port_name, rpc_port_h port, void *user_data); + +/** + * @brief Called when the proxy is disconnected. + * @details The function is called when the proxy is disconnected from stub. + * @since_tizen 5.0 + * @param[in] receiver The target stub app id + * @param[in] port_name The name of the port + * @param[in] user_data The user data passed from the register function + */ +typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *receiver, + const char *port_name, void *user_data); + +/** + * @brief Called when the proxy is rejected. + * @details The function is called when the proxy is rejected to connect stub. + * @since_tizen 5.0 + * @param[in] receiver The target stub app id + * @param[in] port_name The name of the port + * @param[in] user_data The user data passed from the register function + */ +typedef void (*rpc_port_proxy_rejected_event_cb)(const char *receiver, + const char *port_name, void *user_data); + +/** + * @brief Called when the proxy received data. + * @details The function is called when the proxy received data from stub. + * @since_tizen 5.0 + * @param[in] receiver The target stub app id + * @param[in] port_name The name of the port + * @param[in] user_data The user data passed from the register function + */ +typedef void (*rpc_port_proxy_received_event_cb)(const char *receiver, + const char *port_name, void *user_data); + +/** + * @brief The rpc port proxy handle. + * @since_tizen 5.0 + */ typedef void *rpc_port_proxy_h; + +/** + * @brief Creates a rpc port proxy handle. + * @since_tizen 5.0 + * @remarks You must release @a h using rpc_port_proxy_destroy(). + * @param[out] h The rpc port proxy handle that is newly created + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @see rpc_port_proxy_destroy() + */ int rpc_port_proxy_create(rpc_port_proxy_h *h); + +/** + * @brief Destroys a rpc port proxy handle. + * @since_tizen 5.0 + * @param[in] h The rpc port proxy handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_proxy_create() + */ int rpc_port_proxy_destroy(rpc_port_proxy_h h); + +/** + * @brief Connects to @a port of @a appid. + * @details To send and receive data, the proxy should connect to port of stub + * @since_tizen 5.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/appmanager.launch \n + * %http://tizen.org/privilege/datasharing + * @remarks If you want to use this function, you must add privileges. + * @param[in] h The rpc port proxy handle + * @param[in] appid The target stub appid + * @param[in] port The name of rpc port + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied + */ int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, const char *port); +/** + * @brief Adds a proxy connected callback. + * @since_tizen 5.0 + * @param[in] h The rpc port proxy handle + * @param[in] cb The callback function to be called when proxy is connected + * @param[in] user_data The user data to be passed to + * the rpc_port_proxy_connected_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_connected_event_cb cb, void *data); + rpc_port_proxy_connected_event_cb cb, void *user_data); + +/** + * @brief Adds a proxy disconnected callback. + * @since_tizen 5.0 + * @param[in] h The rpc port proxy handle + * @param[in] cb The callback function to be called when proxy is disconnected + * @param[in] user_data The user data to be passed to + * the rpc_port_proxy_disconnected_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_disconnected_event_cb cb, void *data); + rpc_port_proxy_disconnected_event_cb cb, void *user_data); + +/** + * @brief Adds a proxy rejected callback. + * @since_tizen 5.0 + * @param[in] h The rpc port proxy handle + * @param[in] cb The callback function to be called when proxy is rejected + * @param[in] user_data The user data to be passed to + * the rpc_port_proxy_rejected_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_rejected_event_cb cb, void *data); + rpc_port_proxy_rejected_event_cb cb, void *user_data); + +/** + * @brief Adds a proxy received callback. + * @since_tizen 5.0 + * @param[in] h The rpc port proxy handle + * @param[in] cb The callback function to be called when proxy received data + * @param[in] user_data The user data to be passed to + * the rpc_port_proxy_received_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_received_event_cb cb, void *data); + rpc_port_proxy_received_event_cb cb, void *user_data); -/* stub */ +/* Stub */ + +/** + * @brief The rpc port stub handle. + * @since_tizen 5.0 + */ typedef void *rpc_port_stub_h; + +/** + * @brief Called when the proxy is connected with stub. + * @details The function is called when the proxy is connected with stub. + * When a proxy connects to stub several times with new port, + * you can handle each request by using @a instance. + * @since_tizen 5.0 + * @param[in] sender The target proxy app id + * @param[in] instance The information of the request + * @param[in] user_data The user data passed from the register function + */ typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, - const char *instance, void *data); + const char *instance, void *user_data); + +/** + * @brief Called when the proxy is disconnected from stub. + * @details The function is called when the proxy is disconnected from stub. + * When a proxy is disconnected, you can check the request + * by using @a instance. + * @since_tizen 5.0 + * @param[in] sender The target proxy app id + * @param[in] instance The information of the request + * @param[in] user_data The user data passed from the register function + */ typedef void (*rpc_port_stub_disconnected_event_cb)(const char *sender, - const char *instance, void *data); + const char *instance, void *user_data); + +/** + * @brief Called when the stub received data from proxy. + * @details The function is called when the stub received data from stub. + * When a stub received data from several ports, you can handle + * each request by using @a instance. + * @since_tizen 5.0 + * @param[in] sender The target proxy app id + * @param[in] instance The information of the request + * @param[in] port The rpc port handle for reading and writing + * @param[in] user_data The user data passed from the register function + */ typedef int (*rpc_port_stub_received_event_cb)(const char *sender, - const char *instance, rpc_port_h port, void *data); + const char *instance, rpc_port_h port, void *user_data); + +/** + * @brief Creates a rpc port stub handle. + * @since_tizen 5.0 + * @remarks You must release @a h using rpc_port_stub_destroy(). + * @param[out] h The rpc port stub handle that is newly created + * @param[in] port_name The name of the port which want to listen + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_stub_destroy() + */ int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name); + +/** + * @brief Destroys a rpc port stub handle. + * @since_tizen 5.0 + * @param[in] h The rpc port stub handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_stub_create() + */ int rpc_port_stub_destroy(rpc_port_stub_h h); + +/** + * @brief Listens to the requests for connections. + * @details The stub listens requests to connect by port + * @since_tizen 5.0 + * @param[in] h The rpc port stub handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + */ int rpc_port_stub_listen(rpc_port_stub_h h); + +/** + * @brief Adds a privilege to the stub. + * @details The stub can control access to the port using tizen privilege. + * It allows connections only if the proxy which have the privileges. + * @since_tizen 5.0 + * @param[in] h The rpc port stub handle + * @param[in] privilege The privilege to access this stub + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege); + +/** + * @brief Sets trusted to the stub. + * @details The stub can control access to the port using tizen certificate. + * It allows connections only if the proxy is signed with the same + * certificate. + * @since_tizen 5.0 + * @param[in] h The rpc port stub handle + * @param[in] trusted Whether stub allows only trusted proxy or not + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted); + +/** + * @brief Adds a stub connected callback. + * @since_tizen 5.0 + * @param[in] h The rpc stub stub handle + * @param[in] cb The callback function to be called when proxy is connected + * with the stub + * @param[in] user_data The user data to be passed to + * the rpc_port_stub_connected_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, - rpc_port_stub_connected_event_cb cb, void *data); + rpc_port_stub_connected_event_cb cb, void *user_data); + +/** + * @brief Adds a stub disconnected callback. + * @since_tizen 5.0 + * @param[in] h The rpc port stub handle + * @param[in] cb The callback function to be called when proxy is disconnected + * with the stub + * @param[in] user_data The user data to be passed to + * the rpc_port_stub_disconnected_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, - rpc_port_stub_disconnected_event_cb cb, void *data); + rpc_port_stub_disconnected_event_cb cb, void *user_data); + +/** + * @brief Adds a stub received callback. + * @since_tizen 5.0 + * @param[in] h The rpc port stub handle + * @param[in] cb The callback function to be called when stub received data + * @param[in] user_data The user data to be passed to + * the rpc_port_stub_received_event_cb() function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + */ int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, - rpc_port_stub_received_event_cb cb, void *data); + rpc_port_stub_received_event_cb cb, void *user_data); + +/** + * @} + */ #ifdef __cplusplus } #endif -#endif /* __RPC_PORT_INCLUDE_H__ */ +#endif /* __TIZEN_APPFW_RPC_PORT_INCLUDE_H__ */ diff --git a/src/port-internal.cc b/src/port-internal.cc index 7f95add..f69ff24 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -26,6 +26,7 @@ #include #include +#include "rpc-port.h" #include "port-internal.h" #ifdef LOG_TAG @@ -66,7 +67,7 @@ int Port::Read(void* buf, unsigned int size) { nb = read(fd_, buffer, left); if (nb == 0) { LOGE("read_socket: ...read EOF, socket closed %d: nb %d\n", fd_, nb); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } else if (nb == -1) { if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { LOGE("read_socket: %d errno, sleep and retry ...", errno); @@ -75,7 +76,7 @@ int Port::Read(void* buf, unsigned int size) { continue; } LOGE("read_socket: ...error fd %d: errno %d\n", fd_, errno); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } left -= nb; @@ -86,10 +87,10 @@ int Port::Read(void* buf, unsigned int size) { if (left != 0) { LOGE("error fd %d: retry_cnt %d", fd_, retry_cnt); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } - return 0; + return RPC_PORT_ERROR_NONE; } int Port::Write(const void* buf, unsigned int size) { @@ -109,7 +110,7 @@ int Port::Write(const void* buf, unsigned int size) { ret = poll(fds, 1, SEND_TIMEOUT); if (ret == 0) { LOGE("write_socket: : fd %d poll timeout", fd_); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } while (left && (retry_cnt < MAX_RETRY_CNT)) { @@ -122,7 +123,7 @@ int Port::Write(const void* buf, unsigned int size) { } LOGE("write_socket: ...error fd %d: errno %d\n", fd_, errno); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } left -= nb; @@ -133,10 +134,10 @@ int Port::Write(const void* buf, unsigned int size) { if (left != 0) { LOGE("error fd %d: retry_cnt %d", fd_, retry_cnt); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } - return 0; + return RPC_PORT_ERROR_NONE; } } // namespace internal diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index d1d161b..c5272a7 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ RPC_API int rpc_port_parcel_create(rpc_port_parcel_h* h) { *h = p; - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, @@ -59,7 +59,7 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, *h = p; - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { @@ -67,7 +67,7 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { int len = p->GetRaw().size(); if (len <= 0) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; internal::Port* pt = static_cast(port); { @@ -81,260 +81,261 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { return ret; } - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_destroy(rpc_port_parcel_h h) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; delete static_cast(h); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteByte(b); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteInt16(i); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteInt32(i); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteInt64(i); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteFloat(f); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteDouble(d); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteString(str); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteBool(b); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteBundle(b); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); p->WriteArrayCount(count); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h, rpc_port_parcelable_t* parcelable, void* data) { if (parcelable == nullptr || parcelable->to == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; parcelable->to(h, data); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b) { + if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *b = p->ReadByte(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short* i) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *i = p->ReadInt16(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *i = p->ReadInt32(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *i = p->ReadInt64(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float* f) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *f = p->ReadFloat(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double* d) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *d = p->ReadDouble(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *str = strdup(p->ReadString()); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool* b) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *b = p->ReadBool(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *b = p->ReadBundle(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int* count) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; Parcel* p = static_cast(h); *count = p->ReadArrayCount(); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_parcel_read(rpc_port_parcel_h h, rpc_port_parcelable_t* parcelable, void* data) { if (parcelable == nullptr || parcelable->from == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; parcelable->from(h, data); - return 0; + return RPC_PORT_ERROR_NONE; } diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 3c9e142..e33fd9d 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -177,7 +177,7 @@ class StubExt : public Stub, public Stub::IEventListener { RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto port = static_cast(h); @@ -186,7 +186,7 @@ RPC_API int rpc_port_read(rpc_port_h h, void* buf, unsigned int size) { RPC_API int rpc_port_write(rpc_port_h h, const void* buf, unsigned int size) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto port = static_cast(h); @@ -197,7 +197,7 @@ RPC_API int rpc_port_proxy_create(rpc_port_proxy_h* h) { auto p = new ::ProxyExt(); *h = p; - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_proxy_create_mockup(rpc_port_proxy_h* h) { @@ -209,18 +209,18 @@ RPC_API int rpc_port_proxy_create_mockup(rpc_port_proxy_h* h) { RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); delete p; - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char* appid, const char* port) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); std::lock_guard lock(p->GetMutex()); @@ -230,61 +230,61 @@ RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char* appid, } RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_connected_event_cb cb, void *data) { + rpc_port_proxy_connected_event_cb cb, void *user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddConnectedEventListener(cb, data); - return 0; + p->AddConnectedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_disconnected_event_cb cb, void* data) { + rpc_port_proxy_disconnected_event_cb cb, void* user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddDisconnectedEventListener(cb, data); - return 0; + p->AddDisconnectedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_rejected_event_cb cb, void* data) { + rpc_port_proxy_rejected_event_cb cb, void* user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddRejectedEventListener(cb, data); - return 0; + p->AddRejectedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, - rpc_port_proxy_received_event_cb cb, void* data) { + rpc_port_proxy_received_event_cb cb, void* user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddReceivedEventListener(cb, data); - return 0; + p->AddReceivedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = new ::StubExt(port_name); *h = p; - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_create_mockup(rpc_port_stub_h* h, @@ -300,17 +300,17 @@ RPC_API int rpc_port_stub_create_mockup(rpc_port_stub_h* h, RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); delete p; - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); @@ -322,60 +322,60 @@ RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) { RPC_API int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char* privilege) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); p->AddPrivilege(privilege); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); p->SetTrusted(trusted); - return 0; + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, - rpc_port_stub_connected_event_cb cb, void* data) { + rpc_port_stub_connected_event_cb cb, void* user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddConnectedEventListener(cb, data); - return 0; + p->AddConnectedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, - rpc_port_stub_disconnected_event_cb cb, void* data) { + rpc_port_stub_disconnected_event_cb cb, void* user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddDisconnectedEventListener(cb, data); - return 0; + p->AddDisconnectedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } RPC_API int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, - rpc_port_stub_received_event_cb cb, void* data) { + rpc_port_stub_received_event_cb cb, void* user_data) { if (h == nullptr) - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); - p->AddReceivedEventListener(cb, data); - return 0; + p->AddReceivedEventListener(cb, user_data); + return RPC_PORT_ERROR_NONE; } -- 2.7.4 From ed1babc6af435428d8f6d6e7e210d695577d3997 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 15 Mar 2018 09:32:45 +0900 Subject: [PATCH 04/16] Release version 1.0.1 changes - Add doxygen for header file Change-Id: I54172c9facf15f2bfb0d1b2865b3a24e66d01975 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index a7bcda7..820cff6 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.0 +Version: 1.0.1 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From efdfba5964d0cf3a7677288c32c9eeba6f5319b6 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 16 Mar 2018 10:59:42 +0900 Subject: [PATCH 05/16] Fix wrong doc Change-Id: I064e07db97905183d114c044295652274e160283 Signed-off-by: Inkyun Kil --- doc/rpc-port_doc.h | 2 +- include/rpc-port.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/rpc-port_doc.h b/doc/rpc-port_doc.h index 2c1cf87..a035269 100644 --- a/doc/rpc-port_doc.h +++ b/doc/rpc-port_doc.h @@ -33,7 +33,7 @@ /** * @ingroup CAPI_RPC_PORT_MODULE * @defgroup CAPI_RPC_PORT_PARCEL_MODULE RPC Port Parcel - * @brief The @ref CAPI_RPC_PORT_PRCEL_MODULE API provides functions to make parcel data + * @brief The @ref CAPI_RPC_PORT_PARCEL_MODULE API provides functions to make parcel data * @section CAPI_PACKAGE_INFO_MODULE_HEADER Required Header * \#include * diff --git a/include/rpc-port.h b/include/rpc-port.h index 14983bf..b3afaad 100755 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -32,7 +32,7 @@ extern "C" { /** * @brief Enumeration for error codes of a rpc port. - * @since_tizen 4.0 + * @since_tizen 5.0 */ typedef enum { RPC_PORT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ @@ -146,6 +146,7 @@ typedef void *rpc_port_proxy_h; * @return @c 0 on success, * otherwise a negative error value * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL * @see rpc_port_proxy_destroy() */ int rpc_port_proxy_create(rpc_port_proxy_h *h); -- 2.7.4 From e8a445757f4f657d5a16a278402467ab248215af Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 20 Mar 2018 14:15:29 +0900 Subject: [PATCH 06/16] Release version 1.0.2 Changes: - Fix wrong doc Change-Id: I59affa30985aac9725770e2c9a408444a412f81e Signed-off-by: Inkyun Kil --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 820cff6..7c06de2 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.1 +Version: 1.0.2 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 58c2c034c7df8473f674c14a58833a411eede14b Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 20 Mar 2018 14:59:00 +0900 Subject: [PATCH 07/16] Fix error codes Change-Id: I931d7969bc4fc197b2f573069653e0bc68923b04 Signed-off-by: Inkyun Kil --- src/fdbroker-internal.cc | 10 +++++----- src/fdbroker-internal.h | 1 + src/proxy-internal.cc | 17 +++++++++++++---- src/proxy-internal.h | 2 +- src/rpc-port.cc | 22 ++++++++++------------ src/stub-internal.cc | 6 +++--- src/stub-internal.h | 2 +- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index ce59d32..850de59 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -477,12 +477,12 @@ int FdBroker::RegisterDbusInterface(const std::string& port_name) { int FdBroker::Listen(IEventListener* ev, const std::string& port_name) { if (listener_ != nullptr) { LOGE("listener_ is not NULL"); - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; } if (ev == nullptr) { LOGE("ev is NULL"); - return -1; + return RPC_PORT_ERROR_INVALID_PARAMETER; } if (mock_) { @@ -491,18 +491,18 @@ int FdBroker::Listen(IEventListener* ev, const std::string& port_name) { if (ret < 0) return ret; - return 0; + return RPC_PORT_ERROR_NONE; } int ret = RegisterDbusInterface(port_name); if (ret != 0) { LOGE("Failed to register dbus interface"); - return -1; + return RPC_PORT_ERROR_IO_ERROR; } listener_ = ev; - return 0; + return RPC_PORT_ERROR_NONE; } AccessController& FdBroker::GetAccessController() { diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index b5fba79..d844064 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -27,6 +27,7 @@ #include #include "ac-internal.h" +#include "rpc-port.h" namespace rpc_port { namespace internal { diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 82fae45..adc17ab 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -139,17 +139,26 @@ void Proxy::OnPortVanished(const std::string& appid, LOGD("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str()); } -void Proxy::Connect(const std::string appid, const std::string& port_name, +int Proxy::Connect(const std::string appid, const std::string& port_name, IEventListener* ev) { - if (ev == nullptr || listener_ != nullptr) - return; + if (ev == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + if (listener_ != nullptr) { + LOGD("Already connected"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } listener_ = ev; target_appid_ = appid; port_name_ = port_name; int r = fd_broker_.Watch(this, appid, port_name); - if (r < 0) + if (r < 0) { listener_ = nullptr; + return RPC_PORT_ERROR_IO_ERROR; + } + + return RPC_PORT_ERROR_NONE; } } // namespace internal diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 7c12f9c..2cad82c 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -43,7 +43,7 @@ class Proxy : public FdBroker::IEventWatcher { virtual void OnReceived(const std::string& endpoint) = 0; }; - void Connect(const std::string appid, const std::string& port_name, + int Connect(const std::string appid, const std::string& port_name, IEventListener* ev); std::shared_ptr GetPort() const { return port_; diff --git a/src/rpc-port.cc b/src/rpc-port.cc index e33fd9d..fa12ddb 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -225,13 +225,12 @@ RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char* appid, auto p = static_cast<::ProxyExt*>(h); std::lock_guard lock(p->GetMutex()); - p->Connect(appid, port, p); - return 0; + return p->Connect(appid, port, p); } RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_connected_event_cb cb, void *user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); @@ -243,7 +242,7 @@ RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_disconnected_event_cb cb, void* user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); @@ -255,7 +254,7 @@ RPC_API int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_rejected_event_cb cb, void* user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); @@ -267,7 +266,7 @@ RPC_API int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, RPC_API int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, rpc_port_proxy_received_event_cb cb, void* user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::ProxyExt*>(h); @@ -315,13 +314,12 @@ RPC_API int rpc_port_stub_listen(rpc_port_stub_h h) { auto p = static_cast<::StubExt*>(h); std::lock_guard lock(p->GetMutex()); - p->Listen(p); - return 0; + return p->Listen(p); } RPC_API int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char* privilege) { - if (h == nullptr) + if (h == nullptr || privilege == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); @@ -346,7 +344,7 @@ RPC_API int rpc_port_stub_set_trusted(rpc_port_stub_h h, RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void* user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); @@ -358,7 +356,7 @@ RPC_API int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, rpc_port_stub_disconnected_event_cb cb, void* user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); @@ -370,7 +368,7 @@ RPC_API int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, RPC_API int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, rpc_port_stub_received_event_cb cb, void* user_data) { - if (h == nullptr) + if (h == nullptr || cb == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; auto p = static_cast<::StubExt*>(h); diff --git a/src/stub-internal.cc b/src/stub-internal.cc index c981ba5..f126bb0 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -42,12 +42,12 @@ Stub::~Stub() { LOGD("Stub::~Stub"); } -void Stub::Listen(IEventListener* ev) { +int Stub::Listen(IEventListener* ev) { if (ev == nullptr) - return; + return RPC_PORT_ERROR_INVALID_PARAMETER; listener_ = ev; - fd_broker_.Listen(this, port_name_); + return fd_broker_.Listen(this, port_name_); } void Stub::AddPrivilege(const std::string& privilege) { diff --git a/src/stub-internal.h b/src/stub-internal.h index ab89aa3..ebbce2a 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -46,7 +46,7 @@ class Stub : private FdBroker::IEventListener { Stub(const std::string& port_name, bool mock = false); virtual ~Stub(); - void Listen(IEventListener* ev); + int Listen(IEventListener* ev); void AddPrivilege(const std::string& privilege); void SetTrusted(const bool trusted); -- 2.7.4 From 04a9d4159f0b7cb6f95a0d5db9eb83b418044741 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 20 Mar 2018 15:40:27 +0900 Subject: [PATCH 08/16] Fix retry sleep time Change-Id: I40a4dc15e6f2a7250d981244673b5951bf43280e Signed-off-by: Inkyun Kil --- src/port-internal.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index f69ff24..8049fef 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -58,7 +58,7 @@ int Port::Read(void* buf, unsigned int size) { unsigned int left = size; ssize_t nb; int retry_cnt = 0; - const struct timespec TRY_SLEEP_TIME = { 0, 500 * 1000 * 1000 }; + struct timespec TRY_SLEEP_TIME = { 0, 5 * 1000 * 1000 }; int bytes_read = 0; char* buffer = static_cast(buf); std::lock_guard lock(mutex_); @@ -73,6 +73,7 @@ int Port::Read(void* buf, unsigned int size) { LOGE("read_socket: %d errno, sleep and retry ...", errno); retry_cnt++; nanosleep(&TRY_SLEEP_TIME, 0); + TRY_SLEEP_TIME.tv_nsec *= 2; continue; } LOGE("read_socket: ...error fd %d: errno %d\n", fd_, errno); -- 2.7.4 From 86474b40f8ac890ba984761260385bab0e90368a Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 27 Mar 2018 18:16:43 +0900 Subject: [PATCH 09/16] Fix doc and return code - Add docs to explain return value in details - Fix wrong return code Change-Id: I070992dd8a868b1ccc2dd83ee7dd8048dc083b3a Signed-off-by: Inkyun Kil --- include/rpc-port.h | 5 ++++- src/fdbroker-internal.cc | 6 +++--- src/proxy-internal.cc | 5 +++++ src/rpc-port.cc | 3 +++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/rpc-port.h b/include/rpc-port.h index b3afaad..d4f3de0 100755 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -282,12 +282,15 @@ typedef void (*rpc_port_stub_disconnected_event_cb)(const char *sender, * @brief Called when the stub received data from proxy. * @details The function is called when the stub received data from stub. * When a stub received data from several ports, you can handle - * each request by using @a instance. + * each request by using @a instance. If the function returns non zero + * value, the stub is disconnected. * @since_tizen 5.0 * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] port The rpc port handle for reading and writing * @param[in] user_data The user data passed from the register function + * @return @c zero to continue receive data with the sender, + * otherwise @c nonzero to disconnect from the port */ typedef int (*rpc_port_stub_received_event_cb)(const char *sender, const char *instance, rpc_port_h port, void *user_data); diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 850de59..ba991c6 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -539,9 +539,9 @@ int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, if (!mock_) { r = aul_rpc_port_prepare_stub(target_appid.c_str(), port_name.c_str()); if (r != AUL_R_OK) { - LOGE("Failed to prepare stub %s:%s", - target_appid.c_str(), port_name.c_str()); - return -1; + LOGE("Failed to prepare stub %s:%s [ret : %d]", + target_appid.c_str(), port_name.c_str(), r); + return r; } } diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index adc17ab..d49091f 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -30,6 +30,8 @@ #define LOG_TAG "RPC_PORT" +#define EILLEGALACCESS 127 + namespace rpc_port { namespace internal { @@ -155,6 +157,9 @@ int Proxy::Connect(const std::string appid, const std::string& port_name, int r = fd_broker_.Watch(this, appid, port_name); if (r < 0) { listener_ = nullptr; + if (r == -EILLEGALACCESS) + return RPC_PORT_ERROR_PERMISSION_DENIED; + return RPC_PORT_ERROR_IO_ERROR; } diff --git a/src/rpc-port.cc b/src/rpc-port.cc index fa12ddb..bc56034 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -194,6 +194,9 @@ RPC_API int rpc_port_write(rpc_port_h h, const void* buf, unsigned int size) { } RPC_API int rpc_port_proxy_create(rpc_port_proxy_h* h) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + auto p = new ::ProxyExt(); *h = p; -- 2.7.4 From 0c2dcdeeb35e244c0e63c7b6983701eaf794852f Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 3 Apr 2018 15:32:24 +0900 Subject: [PATCH 10/16] Fix static analyzer issues Change-Id: Ibbe6afa15c5c48ec374f01305f5ebe4b3664c7b3 Signed-off-by: Junghoon Park --- src/rpc-port-parcel.cc | 4 ++++ src/stub-internal.h | 2 +- unit_tests/src/rpc_port_parcel_test.cc | 27 +++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index c5272a7..1a266d8 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -21,6 +21,8 @@ #include "parcel-internal.h" #include "port-internal.h" +#define MAX_PARCEL_SIZE (1024 * 1024 * 10) + #undef RPC_API #define RPC_API extern "C" __attribute__((visibility("default"))) @@ -46,6 +48,8 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, if (ret != 0) return ret; + if (len <= 0 || len > MAX_PARCEL_SIZE) + return RPC_PORT_ERROR_IO_ERROR; buf = new unsigned char[len]; ret = rpc_port_read(port, buf, len); if (ret != 0) { diff --git a/src/stub-internal.h b/src/stub-internal.h index ebbce2a..ba66bfe 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -75,7 +75,7 @@ class Stub : private FdBroker::IEventListener { private: std::list> ports_; - IEventListener* listener_; + IEventListener* listener_ = nullptr; FdBroker fd_broker_; std::string port_name_; }; diff --git a/unit_tests/src/rpc_port_parcel_test.cc b/unit_tests/src/rpc_port_parcel_test.cc index 12384c0..fba0b95 100644 --- a/unit_tests/src/rpc_port_parcel_test.cc +++ b/unit_tests/src/rpc_port_parcel_test.cc @@ -25,6 +25,25 @@ using namespace std; using ::testing::AtLeast; +namespace { +class CStringHolder { + public: + CStringHolder(char* ptr) noexcept + : ptr_(ptr) {} + ~CStringHolder() { + if (ptr_) + free(ptr_); + } + + const char* Get() const { + return ptr_; + } + + private: + char* ptr_; +}; +} + class ParcelTest : public ::testing::Test { public: virtual void SetUp() { @@ -58,9 +77,9 @@ class ParcelTest : public ::testing::Test { static void ReadParcelable(rpc_port_parcel_h h, void* data) { char* s = nullptr; int ret = rpc_port_parcel_read_string(h, &s); + ::CStringHolder str(s); ASSERT_EQ(ret, 0); - ASSERT_STREQ(s, "abcdef"); - free(s); + ASSERT_STREQ(str.Get(), "abcdef"); double b; ret = rpc_port_parcel_read_double(h, &b); @@ -161,9 +180,9 @@ TEST_F(ParcelTest, read_write_string) { char* s = nullptr; ret = rpc_port_parcel_read_string(handle_, &s); + ::CStringHolder s1(s); ASSERT_EQ(ret, 0); - ASSERT_STREQ(s, str); - free(s); + ASSERT_STREQ(s1.Get(), str); } TEST_F(ParcelTest, read_write_bool) { -- 2.7.4 From 5ba83292ec8379061afe335abf8f28100c3c0819 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 3 Apr 2018 17:43:55 +0900 Subject: [PATCH 11/16] Release version 1.0.3 Changes: - Fix static analyzer issues - Fix doc and return code - Fix retry sleep time - Fix error codes Change-Id: Ibe3903d9cdc0bd55a30064d83a68e9ffd38d5d01 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 7c06de2..2d5899a 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.2 +Version: 1.0.3 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 7bb1817764ea8e1a6118c9bfd62e7043ade62379 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 4 Apr 2018 09:38:44 +0900 Subject: [PATCH 12/16] Fix the static analyzer issue - Fix the issue about FD double-free Change-Id: Ie2d968a9ca9eaf2e620b8a1fb46c2d5d3c6cfb89 Signed-off-by: Junghoon Park --- src/proxy-internal.cc | 6 +----- src/stub-internal.cc | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index d49091f..b08074c 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -46,10 +46,8 @@ Proxy::~Proxy() { if (disconn_src_ > 0) g_source_remove(disconn_src_); - if (gioc_ != nullptr) { - g_io_channel_shutdown(gioc_, TRUE, nullptr); + if (gioc_ != nullptr) g_io_channel_unref(gioc_); - } } gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, @@ -95,7 +93,6 @@ int Proxy::Watch(int fd) { OnSocketDisconnected, this); if (disconn_src_ == 0) { LOGE("fail to add watch on socket"); - g_io_channel_shutdown(gioc_, TRUE, nullptr); g_io_channel_unref(gioc_); gioc_ = nullptr; return -1; @@ -108,7 +105,6 @@ int Proxy::Watch(int fd) { LOGE("fail to add watch on socket"); g_source_remove(disconn_src_); disconn_src_ = 0; - g_io_channel_shutdown(gioc_, TRUE, nullptr); g_io_channel_unref(gioc_); gioc_ = nullptr; return -1; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index f126bb0..cbd09ab 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -141,10 +141,8 @@ Stub::AcceptedPort::~AcceptedPort() { if (src_ > 0) g_source_remove(src_); - if (gioc_ != nullptr) { - g_io_channel_shutdown(gioc_, TRUE, nullptr); + if (gioc_ != nullptr) g_io_channel_unref(gioc_); - } } int Stub::AcceptedPort::Watch() { @@ -162,7 +160,6 @@ int Stub::AcceptedPort::Watch() { Stub::OnSocketDisconnected, parent_); if (disconn_src_ == 0) { LOGE("fail to add watch on socket"); - g_io_channel_shutdown(gioc_, TRUE, nullptr); g_io_channel_unref(gioc_); gioc_ = nullptr; return -1; @@ -175,7 +172,6 @@ int Stub::AcceptedPort::Watch() { LOGE("fail to add watch on socket"); g_source_remove(disconn_src_); disconn_src_ = 0; - g_io_channel_shutdown(gioc_, TRUE, nullptr); g_io_channel_unref(gioc_); gioc_ = nullptr; return -1; -- 2.7.4 From 255f3351ad48757acca3d1a370a78ebd4ff44531 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 4 Apr 2018 10:32:34 +0900 Subject: [PATCH 13/16] Release version 1.0.4 Changes: - Fix the static analyzer issue Change-Id: I085271503cc180be7e13bef94244edf848cee853 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 2d5899a..2d4e9e2 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.3 +Version: 1.0.4 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 898bb451f79dbe18ddd52b48dd1bb0d1461d7322 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 19 Mar 2018 18:49:58 +0900 Subject: [PATCH 14/16] Remove capi-rpc-port pkgconfig and so files Change-Id: Icd5ae094abad4b42ba518c654be2a32fa765fee2 Signed-off-by: Inkyun Kil --- CMakeLists.txt | 5 ----- capi-rpc-port.pc.in | 13 ------------- packaging/rpc-port.spec | 4 ---- 3 files changed, 22 deletions(-) delete mode 100644 capi-rpc-port.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 74d68ba..af6b846 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,14 +47,9 @@ SET(PC_REQUIRED ${${this_target}_requires}) ## OUTPUT PATHS SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output) -ADD_CUSTOM_COMMAND( - TARGET ${this_target} POST_BUILD - COMMAND ln -s ./librpc-port.so.${MAJORVER} ${LIBRARY_OUTPUT_PATH}/libcapi-rpc-port.so.${MAJORVER}) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/${this_target}.pc.in ${CMAKE_SOURCE_DIR}/${this_target}.pc @ONLY) INSTALL(FILES ${CMAKE_SOURCE_DIR}/${this_target}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/capi-${this_target}.pc.in ${CMAKE_SOURCE_DIR}/capi-${this_target}.pc @ONLY) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/capi-${this_target}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(TARGETS ${this_target} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/capi-rpc-port.pc.in b/capi-rpc-port.pc.in deleted file mode 100644 index 70f43da..0000000 --- a/capi-rpc-port.pc.in +++ /dev/null @@ -1,13 +0,0 @@ - -# Package Information for pkg-config - -prefix=@PREFIX@ -exec_prefix=/usr -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDE_INSTALL_DIR@/rpc-port - -Name: capi-rpc-port -Description: @PACKAGE_DESCRIPTION@ -Version: @VERSION@ -Libs: -L${libdir} -lrpc-port -Cflags: -I${includedir} diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 2d4e9e2..34f99f7 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -24,9 +24,6 @@ Requires(postun): /sbin/ldconfig Requires: amd-mod-rpc-port -Provides: capi-rpc-port -Provides: libcapi-rpc-port.so.1 - %description RPC Port library package. @@ -61,7 +58,6 @@ rm -rf %{buildroot} %files %manifest %{name}.manifest %attr(0644,root,root) %{_libdir}/lib%{name}.so.* -%attr(0644,root,root) %{_libdir}/libcapi-rpc-port.so.* %license LICENSE.APLv2 %files devel -- 2.7.4 From 51f1714a83f5a68426ee0eb18aff9d1cf8166142 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 9 Apr 2018 16:37:11 +0900 Subject: [PATCH 15/16] Fix error codes Change-Id: I3f961813c36880e95cbfcf4349290a59e99c52de Signed-off-by: Inkyun Kil --- include/rpc-port-parcel.h | 2 +- src/rpc-port-parcel.cc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/rpc-port-parcel.h b/include/rpc-port-parcel.h index 04e9a23..715d020 100644 --- a/include/rpc-port-parcel.h +++ b/include/rpc-port-parcel.h @@ -68,7 +68,7 @@ int rpc_port_parcel_create(rpc_port_parcel_h *h); * @return @c 0 on success, * otherwise a negative error value * @retval #RPC_PORT_ERROR_NONE Successful - * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a port is NULL * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error * @see rpc_port_parcel_destroy() * @see rpc_port_parcel_send() diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 1a266d8..5ede077 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -41,6 +41,9 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, int len; unsigned char* buf; + if (port == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + internal::Port* pt = static_cast(port); { std::lock_guard lock(pt->GetMutex()); @@ -67,6 +70,9 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, } RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { + if (h == nullptr || port == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + Parcel* p = static_cast(h); int len = p->GetRaw().size(); -- 2.7.4 From a3570d1f09a371316eb65cd48a3db4d9e567c5b1 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 10 Apr 2018 13:26:47 +0900 Subject: [PATCH 16/16] Release version 1.0.5 Changes: - Fix error codes - Remove capi-rpc-port pkgconfig and so files Change-Id: I1d00c03c2fead74a1a448c7ba6f8d45145a143cc Signed-off-by: Inkyun Kil --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 34f99f7..a738f19 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.4 +Version: 1.0.5 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4