Sync with the private code. 80/20180/1
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 29 Apr 2014 07:17:19 +0000 (16:17 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 29 Apr 2014 07:17:19 +0000 (16:17 +0900)
commit a4ea3106538a3c75eeb8e9fe730eee66d2cc2a02
Author: Sung-jae Park <nicesj.park@samsung.com>
Date:   Tue Apr 22 17:57:52 2014 +0900
  Remove dependency of sec-product-feature

commit 327f620ea51a132122c03eeb3475332119be1396
Author: Sung-jae Park <nicesj.park@samsung.com>
Date:   Thu Apr 17 21:58:36 2014 +0900
  Add new method to get the PID of client process.

  Only if the client is in same host (localhost),
  Get the PID from socket and deliever it to the service core.

commit 9c6c30f4c6cf4a14f042d4cfb92bd25e6e834288
Author: Sung-jae Park <nicesj.park@samsung.com>
Date:   Thu Apr 17 20:38:22 2014 +0900
  Don't try to unpremultipling alpha value.
  For the sake for scrolling performance.

commit 3e1688e1833077a83dff4a86c17749d71be0fb8d
Author: youngsub ko <ys4610.ko@samsung.com>
Date:   Wed Apr 16 17:05:39 2014 +0900
  [notification service] fixed problem multicast packet about deleting notification sent to viewers when deletion isn't successful

commit 01929e7b0f5fc79d6c6ddef2f7be434f3131b089
Author: youngsub ko <ys4610.ko@samsung.com>
Date:   Wed Apr 16 15:28:34 2014 +0900
  [notification service] code cleanup

Change-Id: I286ce5fed15e4a29888024e637ae5cc03f7b456e

data/private.conf.ini
include/service_common.h
packaging/data-provider-master.spec
src/notification_service.c
src/service_common.c

index 597f22c..d0bdfb5 100644 (file)
@@ -32,6 +32,6 @@ com_core_thread=true
 use_xmonitor=false
 #input=/dev/input/event2
 pd_request_timeout=5.0
-premultiplied=1
+premultiplied=0
 #emergency_disk=source=tmpfs;type=tmpfs;option=size=6M
 #services=[livebox],[shortcut],[notification],[utility],[badge],[file]
index f6ca153..f0dbf96 100644 (file)
@@ -29,6 +29,17 @@ struct service_context;
 struct service_event_item;
 
 extern int tcb_fd(struct tcb *tcb);
+
+/*!
+ * \remarks This function will return valid pid only after it gets the packet from a client.
+ *          or it will returns -1.
+ * \param[in] Thread Control Block
+ * \return pid Process Id
+ * \retval -1 TCB is not valid or the client is remote host. so we cannot get the PID of it.
+ * \retval >0 Process Id (PID)
+ */
+extern int tcb_pid(struct tcb *tcb);
+
 extern struct service_context *tcb_svc_ctx(struct tcb *tcb);
 extern int tcb_client_type(struct tcb *tcb);
 extern int tcb_client_type_set(struct tcb *tcb, enum tcb_type type);
index 5374053..875684c 100644 (file)
@@ -2,7 +2,7 @@
 
 Name: data-provider-master
 Summary: Master service provider for liveboxes
-Version: 0.41.2
+Version: 0.42.1
 Release: 1
 Group: HomeTF/Livebox
 License: Flora
index 3e64ef9..2f00587 100755 (executable)
@@ -38,7 +38,6 @@
 #ifndef NOTIFICATION_DEL_PACKET_UNIT
 #define NOTIFICATION_DEL_PACKET_UNIT 10
 #endif
-#define ENABLE_NS_ACCESS_CONTROL 1
 
 static struct info {
        Eina_List *context_list;
@@ -61,18 +60,7 @@ struct noti_service {
        void (*handler_access_error)(struct tcb *tcb, struct packet *packet);
 };
 
-/*!
- * FUNCTIONS to handle notifcation
- */
-static inline int get_priv_id(int num_deleted, int *list_deleted, int index) {
-       if (index < num_deleted) {
-               return *(list_deleted + index);
-       } else {
-               return -1;
-       }
-}
-
-static inline char *get_string(char *string)
+static inline char *_string_get(char *string)
 {
        if (string == NULL) {
                return NULL;
@@ -84,58 +72,35 @@ static inline char *get_string(char *string)
        return string;
 }
 
-static inline struct packet *create_packet_from_deleted_list(int op_num, int *list, int start_index) {
+/*!
+ * FUNCTIONS to create packets
+ */
+static inline int _priv_id_get_from_list(int num_data, int *list, int index) {
+       if (index < num_data) {
+               return *(list + index);
+       } else {
+               return -1;
+       }
+}
+
+static inline struct packet *_packet_create_with_list(int op_num, int *list, int start_index) {
        return packet_create(
                "del_noti_multiple",
                "iiiiiiiiiii",
                ((op_num - start_index) > NOTIFICATION_DEL_PACKET_UNIT) ? NOTIFICATION_DEL_PACKET_UNIT : op_num - start_index,
-               get_priv_id(op_num, list, start_index),
-               get_priv_id(op_num, list, start_index + 1),
-               get_priv_id(op_num, list, start_index + 2),
-               get_priv_id(op_num, list, start_index + 3),
-               get_priv_id(op_num, list, start_index + 4),
-               get_priv_id(op_num, list, start_index + 5),
-               get_priv_id(op_num, list, start_index + 6),
-               get_priv_id(op_num, list, start_index + 7),
-               get_priv_id(op_num, list, start_index + 8),
-               get_priv_id(op_num, list, start_index + 9)
+               _priv_id_get_from_list(op_num, list, start_index),
+               _priv_id_get_from_list(op_num, list, start_index + 1),
+               _priv_id_get_from_list(op_num, list, start_index + 2),
+               _priv_id_get_from_list(op_num, list, start_index + 3),
+               _priv_id_get_from_list(op_num, list, start_index + 4),
+               _priv_id_get_from_list(op_num, list, start_index + 5),
+               _priv_id_get_from_list(op_num, list, start_index + 6),
+               _priv_id_get_from_list(op_num, list, start_index + 7),
+               _priv_id_get_from_list(op_num, list, start_index + 8),
+               _priv_id_get_from_list(op_num, list, start_index + 9)
                );
 }
 
-static void _notification_data_init(void)
-{
-       int property = 0;
-       int priv_id = 0;
-       char *noti_pkgname = NULL;
-       notification_h noti = NULL;
-       notification_list_h noti_list = NULL;
-       notification_list_h noti_list_head = NULL;
-       notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
-
-       notification_get_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
-       noti_list_head = noti_list;
-
-       while (noti_list != NULL) {
-               noti = notification_list_get_data(noti_list);
-               if (noti) {
-                       notification_get_id(noti, NULL, &priv_id);
-                       notification_get_pkgname(noti, &noti_pkgname);
-                       notification_get_property(noti, &property);
-                       notification_get_type(noti, &noti_type);
-
-                       if (noti_type == NOTIFICATION_TYPE_ONGOING
-                                       || property & NOTIFICATION_PROP_VOLATILE_DISPLAY) {
-                               notification_noti_delete_by_priv_id(noti_pkgname, priv_id);
-                       }
-               }
-               noti_list = notification_list_get_next(noti_list);
-       }
-
-       if (noti_list_head != NULL) {
-               notification_free_list(noti_list_head);
-       }
-}
-
 /*!
  * SERVICE HANDLER
  */
@@ -260,7 +225,7 @@ static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void
        char *pkgname = NULL;
 
        if (packet_get(packet, "si", &pkgname, &priv_id) == 2) {
-               pkgname = get_string(pkgname);
+               pkgname = _string_get(pkgname);
 
                ret = notification_noti_delete_by_priv_id_get_changes(pkgname, priv_id, &num_changes);
 
@@ -275,7 +240,7 @@ static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void
                        ErrPrint("failed to create a reply packet\n");
                }
 
-               if (ret != NOTIFICATION_ERROR_NONE && num_changes <= 0) {
+               if (ret != NOTIFICATION_ERROR_NONE || num_changes <= 0) {
                        ErrPrint("failed to delete a notification:%d %d\n", ret, num_changes);
                        return ;
                }
@@ -303,7 +268,7 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi
        int *list_deleted = NULL;
 
        if (packet_get(packet, "si", &pkgname, &type) == 2) {
-               pkgname = get_string(pkgname);
+               pkgname = _string_get(pkgname);
                DbgPrint("pkgname: [%s] type: [%d]\n", pkgname, type);
 
                ret = notification_noti_delete_all(type, pkgname, &num_deleted, &list_deleted);
@@ -329,7 +294,7 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi
 
                if (num_deleted > 0) {
                        if (num_deleted <= NOTIFICATION_DEL_PACKET_UNIT) {
-                               packet_service = create_packet_from_deleted_list(num_deleted, list_deleted, 0);
+                               packet_service = _packet_create_with_list(num_deleted, list_deleted, 0);
 
                                if (packet_service) {
                                        if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) {
@@ -344,7 +309,7 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi
                                int set_total = num_deleted / NOTIFICATION_DEL_PACKET_UNIT;
 
                                for (set = 0; set <= set_total; set++) {
-                                       packet_service = create_packet_from_deleted_list(num_deleted,
+                                       packet_service = _packet_create_with_list(num_deleted,
                                                        list_deleted, set * NOTIFICATION_DEL_PACKET_UNIT);
 
                                        if (packet_service) {
@@ -368,7 +333,7 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi
        }
 }
 
-static void _handler_set_noti_property(struct tcb *tcb, struct packet *packet, void *data)
+static void _handler_noti_property_set(struct tcb *tcb, struct packet *packet, void *data)
 {
        int ret = 0, ret_p = 0;
        struct packet *packet_reply = NULL;
@@ -377,9 +342,9 @@ static void _handler_set_noti_property(struct tcb *tcb, struct packet *packet, v
        char *value = NULL;
 
        if (packet_get(packet, "sss", &pkgname, &property, &value) == 3) {
-               pkgname = get_string(pkgname);
-               property = get_string(property);
-               value = get_string(value);
+               pkgname = _string_get(pkgname);
+               property = _string_get(property);
+               value = _string_get(value);
 
                ret = notification_setting_db_set(pkgname, property, value);
 
@@ -401,7 +366,7 @@ static void _handler_set_noti_property(struct tcb *tcb, struct packet *packet, v
        }
 }
 
-static void _handler_get_noti_property(struct tcb *tcb, struct packet *packet, void *data)
+static void _handler_noti_property_get(struct tcb *tcb, struct packet *packet, void *data)
 {
        int ret = 0, ret_p = 0;
        struct packet *packet_reply = NULL;
@@ -410,8 +375,8 @@ static void _handler_get_noti_property(struct tcb *tcb, struct packet *packet, v
        char *value = NULL;
 
        if (packet_get(packet, "sss", &pkgname, &property) == 2) {
-               pkgname = get_string(pkgname);
-               property = get_string(property);
+               pkgname = _string_get(pkgname);
+               property = _string_get(property);
 
                ret = notification_setting_db_get(pkgname, property, &value);
 
@@ -431,16 +396,6 @@ static void _handler_get_noti_property(struct tcb *tcb, struct packet *packet, v
        }
 }
 
-static void _notification_init(void) {
-       int ret = -1;
-       int restart_count = 0;
-
-       ret = vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count);
-       if (ret == 0 && restart_count <= 1) {
-               _notification_data_init();
-       }
-}
-
 static void _handler_service_register(struct tcb *tcb, struct packet *packet, void *data)
 {
        int ret = 0;
@@ -459,7 +414,10 @@ static void _handler_service_register(struct tcb *tcb, struct packet *packet, vo
        }
 }
 
-static void _handler_access_control_error_common(struct tcb *tcb, struct packet *packet)
+/*!
+ * SERVICE PERMISSION CHECK
+ */
+static void _permission_check_common(struct tcb *tcb, struct packet *packet)
 {
        int ret_p = 0;
        struct packet *packet_reply = NULL;
@@ -475,7 +433,7 @@ static void _handler_access_control_error_common(struct tcb *tcb, struct packet
        }
 }
 
-static void _handler_access_control_error_refresh(struct tcb *tcb, struct packet *packet)
+static void _permission_check_refresh(struct tcb *tcb, struct packet *packet)
 {
        int ret_p = 0;
        struct packet *packet_reply = NULL;
@@ -491,7 +449,7 @@ static void _handler_access_control_error_refresh(struct tcb *tcb, struct packet
        }
 }
 
-static void _handler_access_control_error_get_property(struct tcb *tcb, struct packet *packet)
+static void _permission_check_property_get(struct tcb *tcb, struct packet *packet)
 {
        int ret_p = 0;
        struct packet *packet_reply = NULL;
@@ -507,7 +465,7 @@ static void _handler_access_control_error_get_property(struct tcb *tcb, struct p
        }
 }
 
-static int _is_valid_permission(int fd, struct noti_service *service)
+static int _persmission_check(int fd, struct noti_service *service)
 {
        int ret;
 
@@ -523,6 +481,53 @@ static int _is_valid_permission(int fd, struct noti_service *service)
 }
 
 /*!
+ * NOTIFICATION SERVICE INITIALIZATION
+ */
+static void _notification_data_init(void)
+{
+       int property = 0;
+       int priv_id = 0;
+       char *noti_pkgname = NULL;
+       notification_h noti = NULL;
+       notification_list_h noti_list = NULL;
+       notification_list_h noti_list_head = NULL;
+       notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
+
+       notification_get_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
+       noti_list_head = noti_list;
+
+       while (noti_list != NULL) {
+               noti = notification_list_get_data(noti_list);
+               if (noti) {
+                       notification_get_id(noti, NULL, &priv_id);
+                       notification_get_pkgname(noti, &noti_pkgname);
+                       notification_get_property(noti, &property);
+                       notification_get_type(noti, &noti_type);
+
+                       if (noti_type == NOTIFICATION_TYPE_ONGOING
+                                       || property & NOTIFICATION_PROP_VOLATILE_DISPLAY) {
+                               notification_noti_delete_by_priv_id(noti_pkgname, priv_id);
+                       }
+               }
+               noti_list = notification_list_get_next(noti_list);
+       }
+
+       if (noti_list_head != NULL) {
+               notification_free_list(noti_list_head);
+       }
+}
+
+static void _notification_init(void) {
+       int ret = -1;
+       int restart_count = 0;
+
+       ret = vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count);
+       if (ret == 0 && restart_count <= 1) {
+               _notification_data_init();
+       }
+}
+
+/*!
  * SERVICE THREAD
  */
 static int service_thread_main(struct tcb *tcb, struct packet *packet, void *data)
@@ -535,49 +540,49 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat
                        .handler = _handler_insert,
                        .rule = "data-provider-master::notification.client",
                        .access = "w",
-                       .handler_access_error = _handler_access_control_error_common,
+                       .handler_access_error = _permission_check_common,
                },
                {
                        .cmd = "update_noti",
                        .handler = _handler_update,
                        .rule = "data-provider-master::notification.client",
                        .access = "w",
-                       .handler_access_error = _handler_access_control_error_common,
+                       .handler_access_error = _permission_check_common,
                },
                {
                        .cmd = "refresh_noti",
                        .handler = _handler_refresh,
                        .rule = "data-provider-master::notification.client",
                        .access = "w",
-                       .handler_access_error = _handler_access_control_error_refresh,
+                       .handler_access_error = _permission_check_refresh,
                },
                {
                        .cmd = "del_noti_single",
                        .handler = _handler_delete_single,
                        .rule = "data-provider-master::notification.client",
                        .access = "w",
-                       .handler_access_error = _handler_access_control_error_common,
+                       .handler_access_error = _permission_check_common,
                },
                {
                        .cmd = "del_noti_multiple",
                        .handler = _handler_delete_multiple,
                        .rule = "data-provider-master::notification.client",
                        .access = "w",
-                       .handler_access_error = _handler_access_control_error_common,
+                       .handler_access_error = _permission_check_common,
                },
                {
                        .cmd = "set_noti_property",
-                       .handler = _handler_set_noti_property,
+                       .handler = _handler_noti_property_set,
                        .rule = "data-provider-master::notification.client",
                        .access = "w",
-                       .handler_access_error = _handler_access_control_error_common,
+                       .handler_access_error = _permission_check_common,
                },
                {
                        .cmd = "get_noti_property",
-                       .handler = _handler_get_noti_property,
+                       .handler = _handler_noti_property_get,
                        .rule = "data-provider-master::notification.client",
                        .access = "r",
-                       .handler_access_error = _handler_access_control_error_get_property,
+                       .handler_access_error = _permission_check_property_get,
                },
                {
                        .cmd = "service_register",
@@ -616,18 +621,13 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat
                                continue;
                        }
 
-#if ENABLE_NS_ACCESS_CONTROL
-                       if (_is_valid_permission(tcb_fd(tcb), &(service_req_table[i])) == 1) {
+                       if (_persmission_check(tcb_fd(tcb), &(service_req_table[i])) == 1) {
                                service_req_table[i].handler(tcb, packet, data);
                        } else {
                                if (service_req_table[i].handler_access_error != NULL) {
                                        service_req_table[i].handler_access_error(tcb, packet);
                                }
                        }
-#else
-                       _is_valid_permission(tcb_fd(tcb), &(service_req_table[i]));
-                       service_req_table[i].handler(tcb, packet, data);
-#endif
                        break;
                }
 
index 4de77e1..9ddd002 100644 (file)
@@ -105,6 +105,7 @@ struct tcb { /* Thread controll block */
        int fd; /*!< Connection handle */
        enum tcb_type type;
        int ctrl_pipe[PIPE_MAX];
+       pid_t pid; /*!< Keep the PID of client, if the client is remote one, this will be -1 */
 };
 
 /*!
@@ -122,7 +123,6 @@ static void *client_packet_pump_main(void *data)
        int size = 0;
        int packet_offset = 0;
        int recv_offset = 0;
-       int pid;
        long ret;
        int fd;
        char evt_ch = EVT_CH;
@@ -181,7 +181,7 @@ static void *client_packet_pump_main(void *data)
                        ptr = NULL;
                        break;
                }
-               
+
                /*!
                 * \TODO
                 * Service!!! Receive packet & route packet
@@ -201,7 +201,7 @@ static void *client_packet_pump_main(void *data)
                        recv_state = RECV_HEADER;
                        /* Go through, don't break from here */
                case RECV_HEADER:
-                       ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &pid);
+                       ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid);
                        if (ret <= 0) {
                                if (ret == 0) {
                                        ret = -ECANCELED;
@@ -243,7 +243,7 @@ static void *client_packet_pump_main(void *data)
                        }
                        break;
                case RECV_PAYLOAD:
-                       ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &pid);
+                       ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid);
                        if (ret <= 0) {
                                if (ret == 0) {
                                        ret = -ECANCELED;
@@ -436,6 +436,7 @@ static inline struct tcb *tcb_create(struct service_context *svc_ctx, int fd)
        tcb->fd = fd;
        tcb->svc_ctx = svc_ctx;
        tcb->type = TCB_CLIENT_TYPE_APP;
+       tcb->pid = -1;
 
        DbgPrint("Create a new service thread [%d]\n", fd);
        status = pthread_create(&tcb->thid, NULL, client_packet_pump_main, tcb);
@@ -694,7 +695,7 @@ static void *server_main(void *data)
                                ErrPrint("Failed to create a new TCB: %d (%d)\n", client_fd, svc_ctx->fd);
                                secure_socket_destroy_handle(client_fd);
                        }
-               } 
+               }
 
                if (FD_ISSET(svc_ctx->evt_pipe[PIPE_READ], &set)) {
                        if (read(svc_ctx->evt_pipe[PIPE_READ], &evt_ch, sizeof(evt_ch)) != sizeof(evt_ch)) {
@@ -784,7 +785,7 @@ static void *server_main(void *data)
                         * how can I protect this TCB from deletion without disturbing the server thread?
                         */
                        tcb_destroy(svc_ctx, tcb);
-               } 
+               }
 
                /* If there is no such triggered FD? */
        }
@@ -982,6 +983,19 @@ HAPI int tcb_is_valid(struct service_context *svc_ctx, struct tcb *tcb)
  * \note
  * SERVER THREAD
  */
+HAPI int tcb_pid(struct tcb *tcb)
+{
+       if (!tcb) {
+               return -1;
+       }
+
+       return tcb->pid;
+}
+
+/*!
+ * \note
+ * SERVER THREAD
+ */
 HAPI int tcb_fd(struct tcb *tcb)
 {
        if (!tcb) {