Fix wrong callback called bug 49/57949/4 accepted/tizen/ivi/20160218.023223 accepted/tizen/mobile/20160127.072634 accepted/tizen/tv/20160127.072800 accepted/tizen/wearable/20160127.072836 submit/tizen/20160127.015957 submit/tizen_ivi/20160217.000000 submit/tizen_ivi/20160217.000002
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 26 Jan 2016 08:42:23 +0000 (17:42 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 27 Jan 2016 01:52:29 +0000 (10:52 +0900)
When trusted and none trusted port registered with same
port name, message-port api can not tell which callback
should be called when socket transfer happened.
(after first communication)

Change-Id: Id599946aa0ffe7907225f9123c55fdbd0451fc12
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/message-port.c

index b5a0364..dacd5ae 100755 (executable)
@@ -94,13 +94,13 @@ typedef struct message_port_pkt {
        int remote_port_name_len;
        char *remote_port_name;
        bool is_bidirection;
+       bool is_trusted;
        int data_len;
        unsigned char *data;
 } message_port_pkt_s;
 
 typedef struct message_port_callback_info {
        messageport_message_cb callback;
-       bool is_trusted;
        int local_id;
        char *remote_app_id;
        GIOChannel *gio_read;
@@ -602,6 +602,7 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
                close(fd);
                return NULL;
        }
+
        if (__read_string_from_socket(fd, (char **)&pkt->remote_port_name, &pkt->remote_port_name_len) != MESSAGEPORT_ERROR_NONE) {
                LOGE("read socket fail: port_name");
                free(pkt->remote_port_name);
@@ -609,6 +610,7 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
                close(fd);
                return NULL;
        }
+
        if (__read_socket(fd, (char *)&pkt->is_bidirection, sizeof(pkt->is_bidirection), &nb) != MESSAGEPORT_ERROR_NONE) {
                LOGE("read socket fail: is_bidirection");
                free(pkt->remote_port_name);
@@ -616,6 +618,15 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
                close(fd);
                return NULL;
        }
+
+       if (__read_socket(fd, (char *)&pkt->is_trusted, sizeof(pkt->is_trusted), &nb) != MESSAGEPORT_ERROR_NONE) {
+               LOGE("read socket fail: is_trusted");
+               free(pkt->remote_port_name);
+               free(pkt);
+               close(fd);
+               return NULL;
+       }
+
        if (__read_string_from_socket(fd, (char **)&pkt->data, &pkt->data_len) != MESSAGEPORT_ERROR_NONE) {
                LOGE("read socket fail: data");
                free(pkt->remote_port_name);
@@ -623,6 +634,7 @@ message_port_pkt_s *__message_port_recv_raw(int fd)
                close(fd);
                return NULL;
        }
+
        return pkt;
 }
 
@@ -671,9 +683,9 @@ static gboolean __socket_request_handler(GIOChannel *gio,
                kb = bundle_decode(pkt->data, pkt->data_len);
 
                if (pkt->is_bidirection)
-                       mi->callback(mi->local_id, mi->remote_app_id, pkt->remote_port_name, mi->is_trusted, kb, NULL);
+                       mi->callback(mi->local_id, mi->remote_app_id, pkt->remote_port_name, pkt->is_trusted, kb, NULL);
                else
-                       mi->callback(mi->local_id, mi->remote_app_id, NULL, mi->is_trusted, kb, NULL);
+                       mi->callback(mi->local_id, mi->remote_app_id, NULL, pkt->is_trusted, kb, NULL);
 
                if (pkt) {
                        if (pkt->remote_port_name)
@@ -762,7 +774,6 @@ static bool send_message(GVariant *parameters, GDBusMethodInvocation *invocation
        callback_info->local_id = mi->local_id;
        callback_info->remote_app_id = strdup(local_appid);
        callback_info->callback = mi->callback;
-       callback_info->is_trusted = local_trusted;
 
        GError *error = NULL;
        GDBusMessage *msg = g_dbus_method_invocation_get_message(invocation);
@@ -1232,17 +1243,24 @@ int __message_port_send_async(int sockfd, bundle *kb, const char *local_port,
                _LOGE("write local_port fail");
                return MESSAGEPORT_ERROR_IO_ERROR;
        }
+
        if (__write_socket(sockfd, (char *)&is_bidirection, sizeof(is_bidirection), &nb) != MESSAGEPORT_ERROR_NONE) {
                _LOGE("write is_bidirection fail");
                return MESSAGEPORT_ERROR_IO_ERROR;
        }
 
+       if (__write_socket(sockfd, (char *)&local_trusted, sizeof(local_trusted), &nb) != MESSAGEPORT_ERROR_NONE) {
+               _LOGE("write local_trusted fail");
+               return MESSAGEPORT_ERROR_IO_ERROR;
+       }
+
        bundle_encode(kb, &kb_data, &data_len);
        if (kb_data == NULL) {
                _LOGE("bundle encode fail");
                ret = MESSAGEPORT_ERROR_IO_ERROR;
                goto out;
        }
+
        if (data_len > MAX_MESSAGE_SIZE) {
                _LOGE("bigger than max size\n");
                ret = MESSAGEPORT_ERROR_MAX_EXCEEDED;