Change queue of cleardata
[platform/core/appfw/pkgmgr-server.git] / src / request.c
index f7c10fb..b3f9164 100644 (file)
@@ -97,6 +97,13 @@ static const char instropection_xml[] =
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
+       "    <method name='getsize_sync'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='i' name='get_type' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='x' name='size_info' direction='out'/>"
+       "    </method>"
        "    <method name='cleardata'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
@@ -168,6 +175,11 @@ static const char instropection_xml[] =
        "      <arg type='s' name='label' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
+       "    <method name='migrate_external_image'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
        "  </interface>"
        "</node>";
 static GDBusNodeInfo *instropection_data;
@@ -235,7 +247,6 @@ static int __is_admin_user(uid_t uid)
        return 1;
 }
 
-#define REGULAR_USER 5000
 static int __check_caller_permission(uid_t uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
@@ -321,8 +332,9 @@ static int __handle_request_install(uid_t caller_uid,
                goto catch;
        }
 
+       pkgpath = _get_adjusted_pkgpath(pkgpath, caller_uid);
        pkgtype = _get_pkgtype_from_file(pkgpath);
-       if (!pkgtype && arg_pkgtype)
+       if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype))
                pkgtype = (const char *)arg_pkgtype;
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
@@ -410,8 +422,9 @@ static int __handle_request_mount_install(uid_t caller_uid,
                goto catch;
        }
 
+       pkgpath = _get_adjusted_pkgpath(pkgpath, caller_uid);
        pkgtype = _get_pkgtype_from_file(pkgpath);
-       if (!pkgtype && arg_pkgtype)
+       if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype))
                pkgtype = (const char *)arg_pkgtype;
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
@@ -472,7 +485,7 @@ static int __handle_request_reinstall(uid_t caller_uid,
        pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
                return -1;
        }
 
@@ -518,7 +531,7 @@ static int __handle_request_uninstall(uid_t caller_uid,
        pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
                return -1;
        }
 
@@ -566,7 +579,7 @@ static int __handle_request_move(uid_t caller_uid,
        pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
                return -1;
        }
 
@@ -624,7 +637,7 @@ static int __handle_request_enable_pkgs(uid_t caller_uid,
                if (pkgtype == NULL) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(is)",
-                                               PKGMGR_R_ESYSTEM, ""));
+                                               PKGMGR_R_ENOPKG, ""));
                        free(reqkey);
                        return -1;
                }
@@ -676,7 +689,7 @@ static int __handle_request_disable_pkgs(uid_t caller_uid,
                if (pkgtype == NULL) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(is)",
-                                               PKGMGR_R_ESYSTEM, ""));
+                                               PKGMGR_R_ENOPKG, ""));
                        free(reqkey);
                        return -1;
                }
@@ -915,51 +928,68 @@ static int __handle_request_getsize(uid_t caller_uid,
        return 0;
 }
 
-static int __handle_request_cleardata(uid_t caller_uid,
+static int __handle_request_getsize_sync(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype;
        char *pkgid = NULL;
-       char *reqkey = NULL;
+       int get_type = -1;
+       char *reqkey;
+       char buf[4];
 
-       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+       g_variant_get(parameters, "(u&si)", &target_uid, &pkgid, &get_type);
+       if (target_uid == (uid_t)-1 || pkgid == NULL || get_type == -1) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
        }
 
-       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
-       if (pkgtype == NULL) {
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
        }
 
-       reqkey = __generate_reqkey(pkgid);
-       if (reqkey == NULL) {
+       snprintf(buf, sizeof(buf), "%d", get_type);
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE_SYNC,
+                               "pkgtool", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
-               free(pkgtype);
+                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+               free(reqkey);
                return -1;
        }
 
-       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_CLEARDATA,
-                               pkgtype, pkgid, NULL)) {
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
+
+       return 0;
+}
+
+static int __handle_request_cleardata(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *pkgid = NULL;
+
+       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARDATA,
+                               "pkgtool", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
-               free(reqkey);
-               free(pkgtype);
                return -1;
        }
 
        g_dbus_method_invocation_return_value(invocation,
                        g_variant_new("(i)", PKGMGR_R_OK));
 
-       free(reqkey);
-       free(pkgtype);
-
        return 0;
 }
 
@@ -1385,6 +1415,55 @@ static int __handle_request_set_app_label(uid_t uid,
        return 0;
 }
 
+static int __handle_request_migrate_external_image(uid_t uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *pkgid = NULL;
+       char *pkgtype;
+       char *reqkey;
+
+       g_variant_get(parameters, "(us)", &target_uid, &pkgid);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+               return -1;
+       }
+
+       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOPKG));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               free(pkgtype);
+               return -1;
+       }
+
+       if (_push_queue(target_uid, uid, reqkey,
+                               REQUEST_TYPE_MIGRATE_EXTERNAL_IMAGE,
+                               pkgtype, pkgid, NULL)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+               free(reqkey);
+               free(pkgtype);
+               return -1;
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+                       g_variant_new("(i)", PKGMGR_R_OK));
+
+       free(reqkey);
+       free(pkgtype);
+
+       return 0;
+}
+
 static uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
 {
        GError *err = NULL;
@@ -1403,6 +1482,7 @@ static uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
        }
 
        g_variant_get(result, "(u)", &uid);
+       g_variant_unref(result);
 
        return uid;
 }
@@ -1443,6 +1523,8 @@ static void __handle_method_call(GDBusConnection *connection,
                ret = __handle_request_disable_pkgs(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "getsize") == 0)
                ret = __handle_request_getsize(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "getsize_sync") == 0)
+               ret = __handle_request_getsize_sync(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "clearcache") == 0)
                ret = __handle_request_clearcache(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "enable_app") == 0)
@@ -1485,6 +1567,9 @@ static void __handle_method_call(GDBusConnection *connection,
                                parameters);
        else if (g_strcmp0(method_name, "set_app_label") == 0)
                ret = __handle_request_set_app_label(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "migrate_external_image") == 0)
+               ret = __handle_request_migrate_external_image(uid, invocation,
+                               parameters);
        else
                ret = -1;