Use libsyscommon 01/251001/1 accepted/tizen/unified/20210111.125458 submit/tizen/20210108.041937
authorYunmi Ha <yunmi.ha@samsung.com>
Wed, 6 Jan 2021 11:32:41 +0000 (20:32 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Wed, 6 Jan 2021 11:32:41 +0000 (20:32 +0900)
- list, ini-parser, dbus

Change-Id: Iaf8b4dfa551118461aae25d1d654e7ec136567ec
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
CMakeLists.txt
include/list.h [deleted file]
packaging/libstorage.spec
src/statvfs.c
src/storage-external-dbus.c
src/storage-external-dbus.h
src/storage-external.c
src/storage-inhouse.c
src/storage.c

index cbdb21f..539311a 100644 (file)
@@ -20,6 +20,7 @@ SET(dependents
                mount
                blkid
                capi-system-info
+               libsyscommon
 )
 SET(pc_dependents "capi-base-common")
 
diff --git a/include/list.h b/include/list.h
deleted file mode 100644 (file)
index 27cab68..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * storage
- *
- * Copyright (c) 2012 - 2013 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 __LIST_H__
-#define __LIST_H__
-
-#include <stdio.h>
-
-#ifdef EINA_LIST
-#include <Eina.h>
-typedef Eina_List dd_list;
-#define DD_LIST_PREPEND(a, b)  \
-       a = eina_list_prepend(a, b)
-#define DD_LIST_APPEND(a, b)   \
-       a = eina_list_append(a, b)
-#define DD_LIST_REMOVE(a, b)   \
-       a = eina_list_remove(a, b)
-#define DD_LIST_LENGTH(a)              \
-       eina_list_count(a)
-#define DD_LIST_NTH(a, b)                      \
-       eina_list_nth(a, b)
-#define DD_LIST_FREE_LIST(a)    \
-       a = eina_list_free(a)
-#define DD_LIST_FOREACH(head, elem, node)      \
-       EINA_LIST_FOREACH(head, elem, node)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
-       EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node)
-
-#else
-#include <glib.h>
-typedef GList dd_list;
-#define DD_LIST_PREPEND(a, b)          \
-       a = g_list_prepend(a, (gpointer)b)
-#define DD_LIST_APPEND(a, b)           \
-       a = g_list_append(a, (gpointer)b)
-#define DD_LIST_REMOVE(a, b)           \
-       a = g_list_remove(a, (gpointer)b)
-#define DD_LIST_LENGTH(a)                      \
-       g_list_length(a)
-#define DD_LIST_NTH(a, b)                      \
-       g_list_nth_data(a, b)
-#define DD_LIST_FREE_LIST(a)        \
-       g_list_free(a)
-#define DD_LIST_FOREACH(head, elem, node)      \
-       for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
-       for (elem = head, elem_next = g_list_next(elem), node = NULL; \
-                       elem && ((node = elem->data) != NULL); \
-                       elem = elem_next, elem_next = g_list_next(elem), node = NULL)
-
-#endif
-
-#endif
index 849064d..e6d2da5 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(mount)
 BuildRequires:  pkgconfig(blkid)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(libsyscommon)
 %if 0%{?gcov:1}
 BuildRequires: lcov
 %endif
index e7e9e56..7883276 100644 (file)
@@ -26,6 +26,7 @@
 #include <assert.h>
 #include <mntent.h>
 #include <tzplatform_config.h>
+#include <libsyscommon/ini-parser.h>
 
 #include "log.h"
 #include "common.h"
 #define STORAGE_CONF_FILE      "/etc/storage/libstorage.conf"
 
 
-#define MAX_LINE    128
-#define MAX_SECTION 64
-#define WHITESPACE  " \t"
-#define NEWLINE     "\n\r"
-#define COMMENT     '#'
-
 #define MATCH(a, b)    (!strncmp(a, b, strlen(a)))
 #define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
 
-struct parse_result {
-       char *section;
-       char *name;
-       char *value;
-};
-
 struct storage_config_info {
        double total_size;
        double check_size;
@@ -61,103 +50,6 @@ struct storage_config_info {
 
 static struct storage_config_info storage_info;
 
-static inline char *trim_str(char *s)
-{
-       char *t;
-       /* left trim */
-       s += strspn(s, WHITESPACE);
-
-       /* right trim */
-       for (t = strchr(s, 0); t > s; t--)
-               if (!strchr(WHITESPACE, t[-1]))
-                       break;
-       *t = 0;
-       return s;
-}
-
-static int config_parse(const char *file_name, int cb(struct parse_result *result,
-                       void *user_data), void *user_data)
-{
-       FILE *f = NULL;
-       struct parse_result result;
-       /* use stack for parsing */
-       char line[MAX_LINE];
-       char section[MAX_SECTION];
-       char *start, *end, *name, *value;
-       int lineno = 0, ret = 0;
-
-       if (!file_name || !cb) {
-               ret = -EINVAL;
-               goto error;
-       }
-
-       /* open conf file */
-       f = fopen(file_name, "r");
-       if (!f) {
-               _E("Failed to open file %s", file_name); //LCOV_EXCL_LINE
-               ret = -EIO;
-               goto error;
-       }
-
-       /* parsing line by line */
-       while (fgets(line, MAX_LINE, f) != NULL) {
-               lineno++;
-
-               start = line;
-               start[strcspn(start, NEWLINE)] = '\0';
-               start = trim_str(start);
-
-               if (*start == COMMENT) {
-                       continue;
-               } else if (*start == '[') {
-                       /* parse section */
-                       end = strchr(start, ']');
-                       if (!end || *end != ']') {
-                               ret = -EBADMSG;
-                               goto error;
-                       }
-
-                       *end = '\0';
-                       strncpy(section, start + 1, sizeof(section) - 1);
-                       section[MAX_SECTION-1] = '\0';
-               } else if (*start) {
-                       /* parse name & value */
-                       end = strchr(start, '=');
-                       if (!end || *end != '=') {
-                               ret = -EBADMSG;
-                               goto error;
-                       }
-                       *end = '\0';
-                       name = trim_str(start);
-                       value = trim_str(end + 1);
-                       end = strchr(value, COMMENT);
-                       if (end && *end == COMMENT) {
-                               *end = '\0';
-                               value = trim_str(value);
-                       }
-
-                       result.section = section;
-                       result.name = name;
-                       result.value = value;
-                       /* callback with parse result */
-                       ret = cb(&result, user_data);
-                       if (ret < 0) {
-                               ret = -EBADMSG;
-                               goto error;
-                       }
-               }
-       }
-       _D("Success to load %s", file_name);
-       fclose(f);
-       return 0;
-
-error:
-       if (f)
-               fclose(f);
-       _E("Failed to read %s:%d!", file_name, lineno); //LCOV_EXCL_LINE
-       return ret;
-}
-
 static int load_config(struct parse_result *result, void *user_data)
 {
        static int check_size = -1;
index 731296a..a6e83c7 100755 (executable)
 #include <stdbool.h>
 #include <errno.h>
 #include <gio/gio.h>
-#include <glib.h>
 #include <assert.h>
 #include <limits.h>
+#include <glib.h>
 #include <sys/statvfs.h>
 #include <tzplatform_config.h>
+#include <libsyscommon/dbus-system.h>
+#include <libsyscommon/list.h>
 
 #include "log.h"
 #include "storage-external-dbus.h"
@@ -51,12 +53,7 @@ struct storage_ext_callback {
        guint block_id;
 };
 
-typedef struct {
-        dbus_pending_cb func;
-        void *data;
-} pending_call_data;
-
-static dd_list *changed_list;
+static GList *changed_list;
 
 static void storage_ext_release_internal(storage_ext_device *dev)
 {
@@ -80,15 +77,15 @@ void storage_ext_release_device(storage_ext_device **dev)
        *dev = NULL;
 }
 
-void storage_ext_release_list(dd_list **list)
+void storage_ext_release_list(GList **list)
 {
        storage_ext_device *dev;
-       dd_list *elem;
+       GList *elem;
 
        if (*list == NULL)
                return;
 
-       DD_LIST_FOREACH(*list, elem, dev) {
+       SYS_G_LIST_FOREACH(*list, elem, dev) {
                storage_ext_release_internal(dev);
                free(dev);
        }
@@ -97,140 +94,7 @@ void storage_ext_release_list(dd_list **list)
        *list = NULL;
 }
 
-static GDBusConnection *get_dbus_connection(void)
-{
-       GError *err = NULL;
-       static GDBusConnection *conn;
-
-       if (conn)
-               return conn;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
-       g_type_init();
-#endif
-
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-       if (!conn) {
-//LCOV_EXCL_START System Error
-               if (err) {
-                       _E("fail to get dbus connection : %s", err->message);
-                       g_clear_error(&err);
-               } else
-                       _E("fail to get dbus connection");
-               return NULL;
-//LCOV_EXCL_STOP
-       }
-       return conn;
-}
-
-static void _cb_pending(GDBusConnection *conn,
-                       GAsyncResult *res,
-                       gpointer user_data)
-{
-       GVariant *reply = NULL;
-       GError *err = NULL;
-       pending_call_data *data = (pending_call_data *)user_data;
-
-       reply = g_dbus_connection_call_finish(conn, res, &err);
-       if (!reply || err) {
-               if (!err)
-                       g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
-                               "Error during g_dbus_connection_call");
-
-               if (data && data->func)
-                       data->func(NULL, data->data, err);
-               goto out;
-       }
-
-       if (data && data->func)
-               data->func(reply, data->data, err);
-out:
-       if (err)
-               g_error_free(err);
-       if (data)
-               free(data);
-}
-
-int dbus_method_async_with_reply_var(const char *dest, const char *path,
-               const char *iface, const char *method, GVariant *param,
-               dbus_pending_cb cb, int timeout, void *data)
-{
-       GDBusConnection *conn;
-       pending_call_data *pdata = NULL;
-       int ret = 0;
-
-       if (!dest || !path || !iface || !method)
-               return -EINVAL;
-
-       if (timeout < -1) {
-               _E("wrong timeout %d", timeout);
-               return -EINVAL;
-       }
-
-       conn = get_dbus_connection();
-       if (!conn) {
-               _E("fail to get dbus connection"); //LCOV_EXCL_LINE
-               return -1;
-       }
-
-       if (cb) {
-               pdata = (pending_call_data*)malloc(sizeof(pending_call_data));
-               if (!pdata) {
-                       ret = -ENOMEM;
-                       goto err;
-               }
-
-               pdata->func = cb;
-               pdata->data = data;
-       }
-
-       g_dbus_connection_call(conn, dest, path, iface, method,
-                       param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL,
-                       (GAsyncReadyCallback)_cb_pending,
-                       pdata);
-
-       return ret;
-err:
-       if (param)
-               g_variant_unref(param);
-       return ret;
-}
-
-GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path,
-                               const gchar *iface, const gchar *method, GVariant *param)
-{
-       GDBusConnection *conn;
-       GError *err = NULL;
-       GVariant *ret;
-
-       if (!dest || !path || !iface || !method)
-               return NULL;
-
-       conn = get_dbus_connection();
-       if (!conn) {
-               _E("fail to get dbus connection"); //LCOV_EXCL_LINE
-               return NULL;
-       }
-
-       ret = g_dbus_connection_call_sync(conn,
-                       dest, path, iface, method,
-                       param, NULL, G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, &err);
-       if (!ret) {
-//LCOV_EXCL_START System Error
-               if (err) {
-                       _E("dbus method sync call failed(%s)", err->message);
-                       g_clear_error(&err);
-               } else
-                       _E("g_dbus_connection_call_sync() failed");
-               return NULL;
-//LCOV_EXCL_STOP
-       }
-
-       return ret;
-}
-
-int storage_ext_get_list(dd_list **list)
+int storage_ext_get_list(GList **list)
 {
        GVariant *result;
        GVariantIter *iter;
@@ -240,7 +104,7 @@ int storage_ext_get_list(dd_list **list)
        if (!list)
                return -EINVAL;
 
-       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+       result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        STORAGE_EXT_GET_LIST,
@@ -250,7 +114,11 @@ int storage_ext_get_list(dd_list **list)
                return -EIO;
        }
 
-       g_variant_get(result, "(a(issssssisibii))", &iter);
+       if (!g_variant_get_safe(result, "(a(issssssisibii))", &iter)) {
+               _E("Failed to get params from gvariant.");
+               g_variant_unref(result);
+               return -EIO;
+       }
 
        while (g_variant_iter_loop(iter, "(issssssisibii)",
                                &info.type, &info.devnode, &info.syspath,
@@ -281,10 +149,10 @@ int storage_ext_get_list(dd_list **list)
                elem->flags = info.flags;
                elem->storage_id = info.storage_id;
 
-               DD_LIST_APPEND(*list, elem);
+               SYS_G_LIST_APPEND(*list, elem);
        }
 
-       ret = g_list_length(*list);
+       ret = SYS_G_LIST_LENGTH(*list);
 
 out:
        if (ret < 0)
@@ -303,7 +171,7 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf)
 
        memset(buf, 0, sizeof(struct statvfs_32));
 
-       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+       result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STATVFS,
@@ -313,11 +181,15 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf)
                return -EIO;
        }
 
-       g_variant_get(result, "(ttttttttttt)",
+       if (!g_variant_get_safe(result, "(ttttttttttt)",
                        &bsize, &frsize, &blocks,
                        &bfree, &bavail, &files,
                        &ffree, &favail, &fsid,
-                       &flag, &namemax);
+                       &flag, &namemax)) {
+               _E("Failed to get params from gvariant.");
+               g_variant_unref(result);
+               return -EIO;
+       }
 //     %llu bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax
 
        buf->f_bsize  = (unsigned long)bsize;
@@ -344,7 +216,7 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
 
        memset(buf, 0, sizeof(struct statvfs));
 
-       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+       result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STATVFS,
@@ -354,11 +226,15 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
                return -EIO;
        }
 
-       g_variant_get(result, "(ttttttttttt)",
+       if (!g_variant_get_safe(result, "(ttttttttttt)",
                        &(buf->f_bsize), &(buf->f_frsize), &(buf->f_blocks),
                        &(buf->f_bfree), &(buf->f_bavail), &(buf->f_files),
                        &(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid),
-                       &(buf->f_flag), &(buf->f_namemax));
+                       &(buf->f_flag), &(buf->f_namemax))) {
+               _E("Failed to get params from gvariant.");
+               g_variant_unref(result);
+               return -EIO;
+       }
 
 //     %lu buf->f_bsize, buf->f_frsize, buf->f_fsid, buf->f_flag, buf->f_namemax
 //     %llu buf->f_blocks, buf->f_bfree, buf->f_bavail, buf->f_files, buf->f_ffree, buf->f_favail
@@ -383,7 +259,7 @@ int storage_ext_get_storage_level(const char *path, char **level)
                return -EINVAL;
        }
 
-       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+       result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STORAGE_LEVEL,
@@ -393,9 +269,15 @@ int storage_ext_get_storage_level(const char *path, char **level)
                return -EIO;
        }
 
-       g_variant_get(result, "(s)", &tmp);
+       if (!g_variant_get_safe(result, "(s)", &tmp)) {
+               _E("Failed to get params from gvariant.");
+               g_variant_unref(result);
+               return -EIO;
+       }
+
        *level = strdup(tmp);
        g_free(tmp);
+       g_variant_unref(result);
 
        if (*level == NULL)
                return -ENOMEM;
@@ -407,7 +289,7 @@ int storage_ext_get_storage_level(const char *path, char **level)
 static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data)
 {
        storage_ext_device *dev;
-       dd_list *elem;
+       GList *elem;
        struct storage_ext_callback *callback;
        int ret;
 
@@ -418,7 +300,7 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state
        if (!dev)
                return;
 
-       g_variant_get(params, "(issssssisibii)",
+       if (!g_variant_get_safe(params, "(issssssisibii)",
                        &dev->type,
                        &dev->devnode,
                        &dev->syspath,
@@ -431,7 +313,8 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state
                        &dev->state,
                        &dev->primary,
                        &dev->flags,
-                       &dev->storage_id);
+                       &dev->storage_id))
+               return;
 
        /* Callback is called when unmount is started(DeviceBlocked signal) */
        if (state == STORAGE_EXT_CHANGED && dev->state == STORAGE_EXT_UNMOUNTED) {
@@ -439,7 +322,7 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state
                return;
        }
 
-       DD_LIST_FOREACH(changed_list, elem, callback) {
+       SYS_G_LIST_FOREACH(changed_list, elem, callback) {
                if (!callback->func)
                        continue;
                ret = callback->func(dev, state, callback->data);
@@ -493,15 +376,14 @@ static void storage_ext_changed(GDBusConnection *conn,
 
 int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
 {
-       GDBusConnection *conn;
        guint block_id = 0;
        struct storage_ext_callback *callback;
-       dd_list *elem;
+       GList *elem;
 
        if (!func)
                return -EINVAL;
 
-       DD_LIST_FOREACH(changed_list, elem, callback) {
+       SYS_G_LIST_FOREACH(changed_list, elem, callback) {
                if (callback->func != func)
                        continue;
                if (callback->block_id == 0)
@@ -518,22 +400,9 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
                //LCOV_EXCL_STOP
        }
 
-       conn = get_dbus_connection();
-       if (!conn) {
-               //LCOV_EXCL_START System Error
-               free(callback);
-               _E("Failed to get dbus connection");
-               return -EPERM;
-               //LCOV_EXCL_STOP
-       }
-
-       block_id = g_dbus_connection_signal_subscribe(conn,
-                       NULL,
+       block_id = subscribe_dbus_signal(NULL, NULL,
                        STORAGE_EXT_IFACE_MANAGER,
                        NULL,
-                       NULL,
-                       NULL,
-                       G_DBUS_SIGNAL_FLAGS_NONE,
                        storage_ext_changed,
                        NULL,
                        NULL);
@@ -549,36 +418,27 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data)
        callback->data = data;
        callback->block_id = block_id;
 
-       DD_LIST_APPEND(changed_list, callback);
+       SYS_G_LIST_APPEND(changed_list, callback);
 
        return 0;
 }
 
 void storage_ext_unregister_device_change(storage_ext_changed_cb func)
 {
-       GDBusConnection *conn;
        struct storage_ext_callback *callback;
-       dd_list *elem;
-       dd_list *elem_n;
+       GList *elem;
+       GList *elem_n;
 
        if (!func)
                return;
 
-       conn = get_dbus_connection();
-       if (!conn) {
-//LCOV_EXCL_START System Error
-               _E("fail to get dbus connection");
-               return;
-//LCOV_EXCL_STOP
-       }
-
-       DD_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) {
+       SYS_G_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) {
                if (callback->func != func)
                        continue;
                if (callback->block_id > 0)
-                       g_dbus_connection_signal_unsubscribe(conn, callback->block_id);
+                       unsubscribe_dbus_signal(NULL, callback->block_id);
 
-               DD_LIST_REMOVE(changed_list, callback);
+               SYS_G_LIST_REMOVE(changed_list, callback);
                free(callback);
        }
 }
@@ -586,8 +446,9 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func)
 int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
 {
        GVariant *result;
+       int ret;
 
-       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+       result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "GetDeviceInfo",
@@ -597,25 +458,26 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
                return -ENODEV;
        }
 
-       if (g_variant_check_format_string(result, "(issssssisibii)", true)) {
-               g_variant_get(result, "(issssssisibii)",
+       if (!g_variant_get_safe(result, "(issssssisibii)",
                                &info->type, &info->devnode, &info->syspath,
                                &info->fs_usage, &info->fs_type,
                                &info->fs_version, &info->fs_uuid,
                                &info->readonly, &info->mount_point,
                                &info->state, &info->primary,
-                               &info->flags, &info->storage_id);
-       } else {
+                               &info->flags, &info->storage_id)) {
                _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
-               return -ENODEV;
+               ret = -ENODEV;
+               goto out;
        }
 
        if (info->storage_id < 0) {
                _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
-               return -ENODEV;
+               ret = -ENODEV;
+               goto out;
        }
 
+       ret = 0;
+out:
        g_variant_unref(result);
-
-       return 0;
+       return ret;
 }
index 273e388..b9bcea4 100644 (file)
@@ -23,7 +23,6 @@
 #include <stdbool.h>
 #include <glib.h>
 #include <gio/gio.h>
-#include "list.h"
 
 #define STORAGE_EXT_BUS_NAME              "org.tizen.system.storage"
 #define STORAGE_EXT_PATH_MANAGER          "/Org/Tizen/System/Storage/Block/Manager"
@@ -97,8 +96,8 @@ typedef int (*storage_ext_changed_cb)(storage_ext_device *dev, enum storage_ext_
 
 int storage_ext_is_supported(void);
 void storage_ext_release_device(storage_ext_device **dev);
-void storage_ext_release_list(dd_list **list);
-int storage_ext_get_list(dd_list **list);
+void storage_ext_release_list(GList **list);
+int storage_ext_get_list(GList **list);
 int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf);
 int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf);
 
@@ -108,12 +107,4 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func);
 int storage_ext_get_device_info(int storage_id, storage_ext_device *info);
 int storage_ext_get_storage_level(const char *path, char **level);
 
-typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err);
-int dbus_method_async_with_reply_var(const char *dest, const char *path,
-               const char *iface, const char *method, GVariant *param,
-               dbus_pending_cb cb, int timeout, void *data);
-/* storage-internal.c */
-GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path,
-               const gchar *iface, const gchar *method, GVariant *param);
-
 #endif /* __STORAGE_EXTERNAL_DBUS_H__ */
index 3033915..e260ebc 100755 (executable)
@@ -22,9 +22,9 @@
 #include <sys/statvfs.h>
 #include <vconf.h>
 #include <tzplatform_config.h>
+#include <libsyscommon/list.h>
 
 #include "common.h"
-#include "list.h"
 #include "log.h"
 #include "storage-external-dbus.h"
 
@@ -34,7 +34,7 @@
 
 #define LUKS_NAME "crypto_LUKS"
 
-static dd_list *cb_list[STORAGE_CALLBACK_MAX];
+static GList *cb_list[STORAGE_CALLBACK_MAX];
 
 static int storage_ext_get_dev_state(storage_ext_device *dev,
                enum storage_ext_state blk_state,
@@ -134,7 +134,7 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *
 {
        int ret;
        bool ret_cb;
-       dd_list *list = NULL, *elem;
+       GList *list = NULL, *elem;
        storage_ext_device *dev;
        storage_state_e state;
 
@@ -147,7 +147,7 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *
                return ret;
        }
 
-       DD_LIST_FOREACH(list, elem, dev) {
+       SYS_G_LIST_FOREACH(list, elem, dev) {
                ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state);
                if (ret < 0) {
                        _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); //LCOV_EXCL_LINE
@@ -175,7 +175,7 @@ static int storage_ext_id_changed(storage_ext_device *dev, enum storage_ext_stat
 {
        enum storage_cb_type type = (enum storage_cb_type)data;
        struct storage_cb_info *cb_info;
-       dd_list *elem;
+       GList *elem;
        storage_state_e state;
        int ret;
 
@@ -191,7 +191,7 @@ static int storage_ext_id_changed(storage_ext_device *dev, enum storage_ext_stat
                return ret;
        }
 
-       DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info)
+       SYS_G_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info)
                cb_info->state_cb(cb_info->id, state, cb_info->user_data);
 
        return 0;
@@ -201,7 +201,7 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st
 {
        enum storage_cb_type type = (enum storage_cb_type)data;
        struct storage_cb_info *cb_info;
-       dd_list *elem;
+       GList *elem;
        storage_state_e state;
        int ret;
        storage_dev_e strdev;
@@ -241,7 +241,7 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st
        if (!strncmp(fstype, LUKS_NAME, strlen(LUKS_NAME)))
                storage_type = STORAGE_TYPE_EXTENDED_INTERNAL;
 
-       DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) {
+       SYS_G_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) {
                if (cb_info->type != storage_type)
                        continue;
                if (cb_info->type_cb)
@@ -259,13 +259,13 @@ static bool check_if_callback_exist(enum storage_cb_type type,
                struct storage_cb_info *info, struct storage_cb_info **cb_data)
 {
        struct storage_cb_info *cb_info;
-       dd_list *elem;
+       GList *elem;
 
        if (!info)
                return false;
 
        if (type == STORAGE_CALLBACK_ID) {
-               DD_LIST_FOREACH(cb_list[type], elem, cb_info) {
+               SYS_G_LIST_FOREACH(cb_list[type], elem, cb_info) {
                        if (cb_info->id == info->id &&
                            cb_info->state_cb == info->state_cb) {
                                goto out;
@@ -274,7 +274,7 @@ static bool check_if_callback_exist(enum storage_cb_type type,
        }
 
        if (type == STORAGE_CALLBACK_TYPE) {
-               DD_LIST_FOREACH(cb_list[type], elem, cb_info) {
+               SYS_G_LIST_FOREACH(cb_list[type], elem, cb_info) {
                        if (cb_info->type == info->type &&
                            cb_info->type_cb == info->type_cb)
                                goto out;
@@ -311,7 +311,7 @@ int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *i
                return -EINVAL;
        }
 
-       n = DD_LIST_LENGTH(cb_list[type]);
+       n = SYS_G_LIST_LENGTH(cb_list[type]);
        if (n == 0) {
                ret = storage_ext_register_device_change(callback, (void *)type);
                if (ret < 0)
@@ -329,7 +329,7 @@ int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *i
                return -errno;
 
        memcpy(cb_info, info, sizeof(struct storage_cb_info));
-       DD_LIST_APPEND(cb_list[type], cb_info);
+       SYS_G_LIST_APPEND(cb_list[type], cb_info);
 
        return 0;
 }
@@ -362,12 +362,12 @@ int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info
 
        /* remove device callback from list (local) */
        if (cb_info) {
-               DD_LIST_REMOVE(cb_list[type], cb_info);
+               SYS_G_LIST_REMOVE(cb_list[type], cb_info);
                free(cb_info);
        }
 
        /* check if this callback is last element */
-       n = DD_LIST_LENGTH(cb_list[type]);
+       n = SYS_G_LIST_LENGTH(cb_list[type]);
        if (n == 0)
                storage_ext_unregister_device_change(callback);
 
@@ -494,7 +494,7 @@ out:
 
 int storage_ext_get_primary_mmc_path(char *path, size_t len)
 {
-       dd_list *list = NULL, *elem;
+       GList *list = NULL, *elem;
        storage_ext_device *dev;
        int ret;
 
@@ -504,7 +504,7 @@ int storage_ext_get_primary_mmc_path(char *path, size_t len)
                return ret;
        }
 
-       DD_LIST_FOREACH(list, elem, dev) {
+       SYS_G_LIST_FOREACH(list, elem, dev) {
                if (dev->primary) {
                        snprintf(path, len, "%s", dev->mount_point);
                        ret = 0;
index b35c4fb..83dd93e 100755 (executable)
@@ -23,9 +23,9 @@
 #include <errno.h>
 #include <tzplatform_config.h>
 #include <blkid.h>
+#include <libsyscommon/dbus-system.h>
 
 #include "common.h"
-#include "list.h"
 #include "log.h"
 #include "storage-internal.h"
 #include "storage-external-dbus.h"
@@ -174,7 +174,7 @@ API int storage_get_primary_sdcard(int *storage_id, char **path)
        if (!storage_ext_is_supported())
                return STORAGE_ERROR_NOT_SUPPORTED;
 
-       result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
+       result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "GetMmcPrimary",
@@ -186,13 +186,16 @@ API int storage_get_primary_sdcard(int *storage_id, char **path)
                //LCOV_EXCL_STOP
        }
 
-       g_variant_get(result, "(issssssisibii)",
+       if (!g_variant_get_safe(result, "(issssssisibii)",
                        NULL, NULL, NULL,
                        NULL, NULL,
                        NULL, NULL,
                        NULL, &mount_point,
                        NULL, NULL,
-                       NULL, &id);
+                       NULL, &id)) {
+               g_variant_unref(result);
+               return STORAGE_ERROR_OPERATION_FAILED;
+       }
 
        g_variant_unref(result);
 
@@ -281,7 +284,7 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data)
                free(path);
 //LCOV_EXCL_STOP
 
-       ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
+       ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "Mount",
@@ -350,7 +353,7 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option)
                free(path);
 //LCOV_EXCL_STOP
 
-       ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
+       ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "Unmount",
@@ -424,7 +427,7 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option)
                free(path);
 //LCOV_EXCL_STOP
 
-       ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
+       ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "Format",
index 6778dff..5185279 100644 (file)
@@ -21,9 +21,9 @@
 #include <errno.h>
 #include <vconf.h>
 #include <tzplatform_config.h>
+#include <libsyscommon/list.h>
 
 #include "common.h"
-#include "list.h"
 #include "log.h"
 #include "storage-external.h"
 
@@ -40,9 +40,9 @@ const int tz_id[STORAGE_DIRECTORY_MAX] = {
        [STORAGE_DIRECTORY_OTHERS] = TZ_USER_OTHERS,
 };
 
-static dd_list *st_int_head; /* Internal storage list */
+static GList *st_int_head; /* Internal storage list */
 
-static dd_list *compat_cb_list;
+static GList *compat_cb_list;
 struct compat_cb_info {
        storage_state_changed_cb user_cb;
        void *user_data;
@@ -50,18 +50,18 @@ struct compat_cb_info {
 
 void add_device(const struct storage_ops *st)
 {
-       DD_LIST_APPEND(st_int_head, st);
+       SYS_G_LIST_APPEND(st_int_head, st);
 }
 
 void remove_device(const struct storage_ops *st)
 {
-       DD_LIST_REMOVE(st_int_head, st);
+       SYS_G_LIST_REMOVE(st_int_head, st);
 }
 
 API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data)
 {
        const struct storage_ops *st;
-       dd_list *elem;
+       GList *elem;
        int ret;
        bool user = true;
 
@@ -73,7 +73,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v
        if (getuid() <= USER_UID_START)
                user = false;
 
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (user) {
                        ret = callback(st->storage_id, st->type, st->get_state(),
                                        st->root(), user_data);
@@ -100,7 +100,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v
 API int storage_get_root_directory(int storage_id, char **path)
 {
        const struct storage_ops *st;
-       dd_list *elem;
+       GList *elem;
        char root[PATH_MAX];
        int ret;
        bool extendedint;
@@ -118,7 +118,7 @@ API int storage_get_root_directory(int storage_id, char **path)
                user = false;
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
                if (!user) {
@@ -170,7 +170,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
        char temp[PATH_MAX];
        char *temp2, *end;
        int ret;
-       dd_list *elem;
+       GList *elem;
        bool found;
        bool extendedint;
        bool user = true;
@@ -190,7 +190,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
 
        /* internal storage */
        found = false;
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
                found = true;
@@ -271,7 +271,7 @@ out:
 API int storage_get_type(int storage_id, storage_type_e *type)
 {
        const struct storage_ops *st;
-       dd_list *elem;
+       GList *elem;
        char root[PATH_MAX];
        int ret;
        bool extendedint;
@@ -285,7 +285,7 @@ API int storage_get_type(int storage_id, storage_type_e *type)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
                *type = st->type;
@@ -320,7 +320,7 @@ API int storage_get_state(int storage_id, storage_state_e *state)
 {
        const struct storage_ops *ops;
        storage_state_e st;
-       dd_list *elem;
+       GList *elem;
        int ret;
 
        if (storage_id < 0)
@@ -332,7 +332,7 @@ API int storage_get_state(int storage_id, storage_state_e *state)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, ops) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, ops) {
                if (ops->storage_id != storage_id)
                        continue;
                *state = ops->get_state();
@@ -367,10 +367,10 @@ static void compat_cb(int storage_id,
                bool primary, int flags, void *user_data)
 {
        struct compat_cb_info* ccb_info;
-       dd_list *elem;
+       GList *elem;
 
        if (storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD)
-               DD_LIST_FOREACH(compat_cb_list, elem, ccb_info)
+               SYS_G_LIST_FOREACH(compat_cb_list, elem, ccb_info)
                        ccb_info->user_cb(storage_id, state, ccb_info->user_data);
 }
 //LCOV_EXCL_STOP
@@ -380,7 +380,7 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca
        const struct storage_ops *st;
        struct storage_cb_info info;
        int ret;
-       dd_list *elem;
+       GList *elem;
 
        struct compat_cb_info* ccb_info;
        static int compat_cb_init = 0;
@@ -413,13 +413,13 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca
                        return STORAGE_ERROR_OPERATION_FAILED;
                ccb_info->user_cb = callback;
                ccb_info->user_data = user_data;
-               DD_LIST_APPEND(compat_cb_list, ccb_info);
+               SYS_G_LIST_APPEND(compat_cb_list, ccb_info);
 
                return STORAGE_ERROR_NONE;
        }
 
        /* Internal storage does not support registering changed callback */
-       DD_LIST_FOREACH(st_int_head, elem, st)
+       SYS_G_LIST_FOREACH(st_int_head, elem, st)
                if (st->storage_id == storage_id)
                        return STORAGE_ERROR_NONE;
 
@@ -447,7 +447,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb
        const struct storage_ops *st;
        struct storage_cb_info info;
        int ret;
-       dd_list *elem;
+       GList *elem;
 
        if (storage_id < 0)
                return STORAGE_ERROR_INVALID_PARAMETER;
@@ -464,12 +464,12 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb
                        return STORAGE_ERROR_NOT_SUPPORTED;
                }
 
-               dd_list *elem_n;
+               GList *elem_n;
                struct compat_cb_info* ccb_info;
 
-               DD_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) {
+               SYS_G_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) {
                        if (ccb_info->user_cb == callback) {
-                               DD_LIST_REMOVE(compat_cb_list, ccb_info);
+                               SYS_G_LIST_REMOVE(compat_cb_list, ccb_info);
                                free(ccb_info);
                                return STORAGE_ERROR_NONE;
                        }
@@ -478,7 +478,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb
        }
 
        /* Internal storage does not support registering changed callback */
-       DD_LIST_FOREACH(st_int_head, elem, st)
+       SYS_G_LIST_FOREACH(st_int_head, elem, st)
                if (st->storage_id == storage_id)
                        return STORAGE_ERROR_NONE;
 
@@ -505,7 +505,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes)
        const struct storage_ops *st;
        unsigned long long total;
        int ret;
-       dd_list *elem;
+       GList *elem;
 
        if (storage_id < 0)
                return STORAGE_ERROR_INVALID_PARAMETER;
@@ -516,7 +516,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
                ret = st->get_space(&total, NULL);
@@ -551,7 +551,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes)
        const struct storage_ops *st;
        unsigned long long avail;
        int ret;
-       dd_list *elem;
+       GList *elem;
 
        if (storage_id < 0)
                return STORAGE_ERROR_INVALID_PARAMETER;
@@ -562,7 +562,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes)
        }
 
        /* internal storage */
-       DD_LIST_FOREACH(st_int_head, elem, st) {
+       SYS_G_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
                ret = st->get_space(NULL, &avail);