refactor getsize sync function
[platform/core/appfw/pkgmgr-server.git] / src / request.c
index 1213bc9..fce8210 100644 (file)
@@ -21,6 +21,7 @@ static const char instropection_xml[] =
        "  <interface name='org.tizen.pkgmgr'>"
        "    <method name='install'>"
        "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgpath' direction='in'/>"
        "      <arg type='as' name='args' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
@@ -34,6 +35,7 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='mount_install'>"
        "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgpath' direction='in'/>"
        "      <arg type='as' name='args' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
@@ -95,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'/>"
@@ -233,7 +242,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)
 {
@@ -278,6 +286,7 @@ static int __handle_request_install(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
+       char *arg_pkgtype = NULL;
        const char *pkgtype;
        char *pkgpath = NULL;
        char *args = NULL;
@@ -289,7 +298,8 @@ static int __handle_request_install(uid_t caller_uid,
        int i = 0;
        int len = 0;
 
-       g_variant_get(parameters, "(u&s@as)", &target_uid, &pkgpath, &value);
+       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &arg_pkgtype,
+                       &pkgpath, &value);
        tmp_args = (gchar **)g_variant_get_strv(value, &args_count);
 
        for (i = 0; i < args_count; i++)
@@ -317,7 +327,9 @@ static int __handle_request_install(uid_t caller_uid,
                goto catch;
        }
 
-       pkgtype = _get_pkgtype_from_file(pkgpath);
+       pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid);
+       if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype))
+               pkgtype = (const char *)arg_pkgtype;
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
@@ -363,6 +375,7 @@ static int __handle_request_mount_install(uid_t caller_uid,
        GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
+       char *arg_pkgtype = NULL;
        const char *pkgtype;
        char *pkgpath = NULL;
        char *args = NULL;
@@ -374,7 +387,8 @@ static int __handle_request_mount_install(uid_t caller_uid,
        int i = 0;
        int len = 0;
 
-       g_variant_get(parameters, "(u&s@as)", &target_uid, &pkgpath, &value);
+       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &arg_pkgtype,
+                       &pkgpath, &value);
        tmp_args = (gchar **)g_variant_get_strv(value, &args_count);
 
        for (i = 0; i < args_count; i++)
@@ -402,7 +416,9 @@ static int __handle_request_mount_install(uid_t caller_uid,
                goto catch;
        }
 
-       pkgtype = _get_pkgtype_from_file(pkgpath);
+       pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid);
+       if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype))
+               pkgtype = (const char *)arg_pkgtype;
        if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
@@ -462,7 +478,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;
        }
 
@@ -508,7 +524,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;
        }
 
@@ -556,7 +572,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;
        }
 
@@ -614,7 +630,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;
                }
@@ -666,7 +682,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;
                }
@@ -905,6 +921,45 @@ static int __handle_request_getsize(uid_t caller_uid,
        return 0;
 }
 
+static int __handle_request_getsize_sync(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *pkgid = NULL;
+       int get_type = -1;
+       char *reqkey;
+       char buf[4];
+
+       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("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               return -1;
+       }
+
+       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("(is)", PKGMGR_R_ESYSTEM, ""));
+               free(reqkey);
+               return -1;
+       }
+
+       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)
 {
@@ -923,7 +978,7 @@ static int __handle_request_cleardata(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("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(i)", PKGMGR_R_ENOPKG));
                return -1;
        }
 
@@ -1359,7 +1414,7 @@ static int __handle_request_set_app_label(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(target_uid, reqkey,
+       if (_push_queue(target_uid, uid, reqkey,
                                REQUEST_TYPE_SET_APP_LABEL,
                                "default", appid, label)) {
                g_dbus_method_invocation_return_value(invocation,
@@ -1433,6 +1488,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)