Apply coding rule 66/54266/1 accepted/tizen/ivi/20160218.023346 accepted/tizen/mobile/20151214.134721 accepted/tizen/tv/20151214.135204 accepted/tizen/wearable/20151214.135943 submit/tizen/20151214.110925 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718 submit/tizen_ivi/20160217.000000 submit/tizen_ivi/20160217.000002
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 14 Dec 2015 10:11:25 +0000 (19:11 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 14 Dec 2015 11:03:50 +0000 (20:03 +0900)
Change-Id: I5eba92c6874cea7a0db4c03177e86a38dd90602a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/ac_lib.c
src/ac_server.c
src/ac_sock.c

index cfb92b3..3f3cb8b 100755 (executable)
@@ -25,7 +25,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <app-checker.h>
+#include "app-checker.h"
 #include "ac_sock.h"
 #include "internal.h"
 
@@ -74,7 +74,7 @@ SLPAPI int ac_check_launch_privilege(const char *appid, const char *pkg_type, in
 {
        int ret = -1;
 
-       if(appid == NULL || pkg_type == NULL)
+       if (appid == NULL || pkg_type == NULL)
                return AC_R_EINVAL;
 
        ret = app_send_cmd(appid, pkg_type, pid, AC_CHECK);
@@ -86,7 +86,7 @@ SLPAPI int ac_register_launch_privilege(const char *pkg_name, const char *pkg_ty
 {
        int ret = -1;
 
-       if(pkg_name == NULL || pkg_type == NULL)
+       if (pkg_name == NULL || pkg_type == NULL)
                return AC_R_EINVAL;
 
        ret = app_send_cmd(pkg_name, pkg_type, -1, AC_REGISTER);
@@ -98,11 +98,10 @@ SLPAPI int ac_unregister_launch_privilege(const char *pkg_name, const char *pkg_
 {
        int ret = -1;
 
-       if(pkg_name == NULL || pkg_type == NULL)
+       if (pkg_name == NULL || pkg_type == NULL)
                return AC_R_EINVAL;
 
        ret = app_send_cmd(pkg_name, pkg_type, -1, AC_UNREGISTER);
 
-       return ret;     
+       return ret;
 }
-
index 2508bc4..e7e3b20 100755 (executable)
 #include <stdlib.h>
 #include <dlfcn.h>
 
-#include <app-checker.h>
+#include "app-checker.h"
 #include "ac_sock.h"
 #include "internal.h"
 
 #define PLUGINS_PREFIX LIBPREFIX "/ac-plugins"
-#define MAX_LOCAL_BUFSZ        512
+#define MAX_LOCAL_BUFSZ 512
 
 #ifndef SLPAPI
 #define SLPAPI __attribute__ ((visibility("default")))
@@ -70,13 +70,14 @@ static int __send_to_sigkill(int pid)
        return 0;
 }
 
-static int __check_launch_privilege(const char *pkg_name, const char *pkg_type, int pid)
+static int __check_launch_privilege(const char *pkg_name,
+               const char *pkg_type, int pid)
 {
        GSList *iter = NULL;
        GSList *iter2 = NULL;
        ac_type_list_t *type_t;
        ac_so_list_t *so_t;
-       
+
        for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) {
                type_t = iter->data;
                if (strncmp(type_t->pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE) == 0) {
@@ -84,13 +85,13 @@ static int __check_launch_privilege(const char *pkg_name, const char *pkg_type,
                                so_t = iter2->data;
                                _D("type : %s / so name : %s / func : %x", type_t->pkg_type, so_t->so_name, so_t->ac_check);
                                if (so_t->ac_check && so_t->ac_check(pkg_name) < 0) {
-                                       if(pid > 0)
-                                               __send_to_sigkill(pid);                                 
+                                       if (pid > 0)
+                                               __send_to_sigkill(pid);
                                        return AC_R_ERROR;
                                }
                        }
                        return AC_R_OK;
-               }                                               
+               }
        }
 
        return AC_R_ENOPULUGINS;
@@ -103,18 +104,17 @@ static int __register_launch_privilege(const char *pkg_name, const char *pkg_typ
        ac_type_list_t *type_t;
        ac_so_list_t *so_t;
        int ret = AC_R_OK;
-       
+
        for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) {
                type_t = iter->data;
                if (strncmp(type_t->pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE) == 0) {
                        for (iter2 = type_t->so_list; iter2 != NULL; iter = g_slist_next(iter2)) {
                                so_t = iter2->data;
-                               if (so_t->ac_register && so_t->ac_register(pkg_name) < 0) {
+                               if (so_t->ac_register && so_t->ac_register(pkg_name) < 0)
                                        ret = AC_R_ERROR;
-                               }
                        }
                        return ret;
-               }                                               
+               }
        }
 
        return AC_R_ENOPULUGINS;
@@ -128,18 +128,17 @@ static int __unregister_launch_privilege(const char *pkg_name, const char *pkg_t
        ac_type_list_t *type_t;
        ac_so_list_t *so_t;
        int ret = AC_R_OK;
-       
+
        for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) {
                type_t = iter->data;
                if (strncmp(type_t->pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE) == 0) {
                        for (iter2 = type_t->so_list; iter2 != NULL; iter = g_slist_next(iter2)) {
                                so_t = iter2->data;
-                               if (so_t->ac_unregister && so_t->ac_unregister(pkg_name) < 0) {
+                               if (so_t->ac_unregister && so_t->ac_unregister(pkg_name) < 0)
                                        ret = AC_R_ERROR;
-                               }
                        }
                        return ret;
-               }                                               
+               }
        }
 
        return AC_R_ENOPULUGINS;;
@@ -170,22 +169,21 @@ static gboolean __ac_handler(gpointer data)
        case AC_CHECK:
                _send_result_to_server(clifd, AC_R_OK);
                ret = __check_launch_privilege(ad->pkg_name, ad->pkg_type, ad->pid);
-               g_free(ad); 
+               g_free(ad);
                free(pkt);
                return TRUE;
                break;
        case AC_REGISTER:
                ret = __register_launch_privilege(ad->pkg_name, ad->pkg_type);
-               break;          
+               break;
        case AC_UNREGISTER:
                ret = __unregister_launch_privilege(ad->pkg_name, ad->pkg_type);
-               break;          
+               break;
        default:
                _E("no support packet");
        }
 
        _send_result_to_server(clifd, ret);
-       
        g_free(ad);
        free(pkt);
        return TRUE;
@@ -232,22 +230,21 @@ static void __pkt_type_list_free()
        GSList *iter2 = NULL;
        ac_type_list_t *type_t;
        ac_so_list_t *so_t;
-       
+
        for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) {
                type_t = iter->data;
-               if(type_t) {
+               if (type_t) {
                        for (iter2 = type_t->so_list; iter2 != NULL; iter2 = g_slist_next(iter2)) {
                                so_t = iter2->data;
-                               if(so_t) {
-                                       if(so_t->so_name)
+                               if (so_t) {
+                                       if (so_t->so_name)
                                                free(so_t->so_name);
                                        free(so_t);
                                }
                        }
                        g_slist_free(type_t->so_list);
-               
-               
-                       if(type_t->pkg_type)
+
+                       if (type_t->pkg_type)
                                free(type_t->pkg_type);
                        free(type_t);
                }
@@ -279,9 +276,8 @@ int __initialize()
        g_source_set_priority(src, G_PRIORITY_DEFAULT);
 
        ret = g_source_attach(src, NULL);
-       if (ret == 0)
-       {
-               /* TODO: error handle*/
+       if (ret == 0) {
+               /* TODO: error handle */
                return AC_R_ERROR;
        }
 
@@ -296,23 +292,22 @@ int __initialize()
        ac_type_list_t *type_t = NULL;
        void *handle = NULL;
        ac_so_list_t *so_t = NULL;
-       
+
        dp = opendir(PLUGINS_PREFIX);
-       if (dp == NULL) {
+       if (dp == NULL)
                return AC_R_ERROR;
-       }
+
        while ((dentry = readdir(dp)) != NULL) {
-               
-               if(dentry->d_type != DT_DIR) 
+               if (dentry->d_type != DT_DIR)
                        continue;
-               if(strcmp(dentry->d_name,".") == 0 || strcmp(dentry->d_name,"..") == 0) 
+               if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0)
                        continue;
-               
-               snprintf(buf,MAX_LOCAL_BUFSZ,"%s/%s",PLUGINS_PREFIX,dentry->d_name);
+
+               snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%s", PLUGINS_PREFIX, dentry->d_name);
                _D("type : %s", dentry->d_name);
 
                type_t = malloc(sizeof(ac_type_list_t));
-               if(type_t == NULL) {
+               if (type_t == NULL) {
                        __pkt_type_list_free();
                        closedir(dp);
                        return AC_R_ERROR;
@@ -322,26 +317,25 @@ int __initialize()
                type_t->so_list = NULL;
 
                pkg_type_list = g_slist_append(pkg_type_list, (void *)type_t);
-               
+
                sub_dp = opendir(buf);
                if (sub_dp == NULL) {
                        __pkt_type_list_free();
                        closedir(dp);
                        return AC_R_ERROR;
                }
-               
+
                while ((sub_dentry = readdir(sub_dp)) != NULL) {
-                       
-                       if(sub_dentry->d_type == DT_DIR) 
+                       if (sub_dentry->d_type == DT_DIR)
                                continue;
-                       snprintf(buf2,MAX_LOCAL_BUFSZ,"%s/%s", buf, sub_dentry->d_name);
+                       snprintf(buf2, MAX_LOCAL_BUFSZ, "%s/%s", buf, sub_dentry->d_name);
                        _D("so_name : %s", buf2);
-                       
+
                        handle = dlopen(buf2, RTLD_LAZY);
-                       if(handle == NULL) 
+                       if (handle == NULL)
                                continue;
                        so_t = malloc(sizeof(ac_so_list_t));
-                       if(so_t == NULL) {
+                       if (so_t == NULL) {
                                __pkt_type_list_free();
                                dlclose(handle);
                                handle = NULL;
@@ -368,18 +362,17 @@ int __initialize()
 SLPAPI int ac_server_initialize()
 {
        int ret = AC_R_OK;
-       
+
        ret = __initialize();
-       
+
        return ret;
 }
 
 SLPAPI int ac_server_check_launch_privilege(const char *pkg_name, const char *pkg_type, int pid)
 {
        int ret = -1;
+
        ret = __check_launch_privilege(pkg_name, pkg_type, pid);
 
        return ret;
 }
-
-
index ce81406..61310e2 100755 (executable)
@@ -55,9 +55,9 @@ int _create_server_sock()
        fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
        /*  support above version 2.6.27*/
        if (fd < 0) {
-               if(errno == EINVAL) {
+               if (errno == EINVAL) {
                        fd = socket(AF_UNIX, SOCK_STREAM, 0);
-                       if(fd < 0) {
+                       if (fd < 0) {
                                _E("second chance - socket create error");
                                return -1;
                        }
@@ -69,9 +69,9 @@ int _create_server_sock()
 
        memset(&saddr, 0, sizeof(saddr));
        saddr.sun_family = AF_UNIX;
-       snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s",AC_SOCK_NAME);
+       snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s", AC_SOCK_NAME);
        unlink(saddr.sun_path);
-       
+
        if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
                _E("bind error");
                close(fd);
@@ -91,7 +91,7 @@ int _create_server_sock()
                _E("listen error");
                close(fd);
                return -1;
-       }       
+       }
 
        return fd;
 }
@@ -103,7 +103,7 @@ int _create_client_sock()
        int retry = 1;
        int ret = -1;
 
-       fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);    
+       fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
        /*  support above version 2.6.27*/
        if (fd < 0) {
                if (errno == EINVAL) {
@@ -158,8 +158,8 @@ static int __connect_client_sock(int fd, const struct sockaddr *saptr, socklen_t
        error = 0;
        if ((ret = connect(fd, (struct sockaddr *)saptr, salen)) < 0) {
                if (errno != EAGAIN && errno != EINPROGRESS) {
-                       fcntl(fd, F_SETFL, flags);      
-                       return (-2);
+                       fcntl(fd, F_SETFL, flags);
+                       return -2;
                }
        }
 
@@ -173,28 +173,29 @@ static int __connect_client_sock(int fd, const struct sockaddr *saptr, socklen_t
        timeout.tv_sec = 0;
        timeout.tv_usec = nsec;
 
-       if ((ret = select(fd + 1, &readfds, &writefds, NULL, 
+       if ((ret = select(fd + 1, &readfds, &writefds, NULL,
                        nsec ? &timeout : NULL)) == 0) {
                close(fd);      /* timeout */
                errno = ETIMEDOUT;
-               return (-1);
+               return -1;
        }
 
        if (FD_ISSET(fd, &readfds) || FD_ISSET(fd, &writefds)) {
                len = sizeof(error);
                if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
-                       return (-1);    /* Solaris pending error */
+                       return -1;      /* Solaris pending error */
        } else
-               return (-1);    /* select error: sockfd not set*/
+               return -1;      /* select error: sockfd not set*/
 
  done:
-       fcntl(fd, F_SETFL, flags);      
+       fcntl(fd, F_SETFL, flags);
        if (error) {
-               close(fd);      
+               close(fd);
                errno = error;
-               return (-1);
+               return -1;
        }
-       return (0);
+
+       return 0;
 }
 
 /**
@@ -229,9 +230,8 @@ int _app_send_raw(int cmd, unsigned char *data, int datalen)
 
        if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
                _E("sendto() failed - %d %d", len, datalen + 8);
-               if (errno == EPIPE) {
+               if (errno == EPIPE)
                        _E("fd:%d\n", fd);
-               }
                close(fd);
                if (pkt) {
                        free(pkt);
@@ -285,7 +285,7 @@ ac_pkt_t *_app_recv_raw(int fd, int *clifd, struct ucred *cr)
        }
 
        pkt = (ac_pkt_t *) malloc(sizeof(char) * AC_SOCK_MAXBUFF);
-       if(pkt == NULL) {
+       if (pkt == NULL) {
                close(*clifd);
                return NULL;
        }
@@ -296,9 +296,10 @@ ac_pkt_t *_app_recv_raw(int fd, int *clifd, struct ucred *cr)
  retry_recv:
        /* receive single packet from socket */
        len = recv(*clifd, pkt, AC_SOCK_MAXBUFF, 0);
-       if (len < 0)
+       if (len < 0) {
                if (errno == EINTR)
                        goto retry_recv;
+       }
 
        if ((len < 8) || (len != (pkt->len + 8))) {
                _E("recv error %d %d", len, pkt->len);