Add request type and codes for set app label
[platform/core/appfw/pkgmgr-server.git] / src / request.c
index 3269b24..1213bc9 100644 (file)
@@ -160,6 +160,12 @@ static const char instropection_xml[] =
        "      <arg type='i' name='result' direction='out'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
+       "    <method name='set_app_label'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='appid' direction='in'/>"
+       "      <arg type='s' name='label' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
        "  </interface>"
        "</node>";
 static GDBusNodeInfo *instropection_data;
@@ -1331,6 +1337,44 @@ static int __handle_request_get_restriction_mode(uid_t caller_uid,
        return 0;
 }
 
+static int __handle_request_set_app_label(uid_t uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *appid = NULL;
+       char *label = NULL;
+       char *reqkey;
+
+       g_variant_get(parameters, "(uss)", &target_uid, &appid, &label);
+       if (target_uid == (uid_t)-1 || appid == NULL || label == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("appid");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, reqkey,
+                               REQUEST_TYPE_SET_APP_LABEL,
+                               "default", appid, label)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", 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 uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
 {
        GError *err = NULL;
@@ -1429,6 +1473,8 @@ static void __handle_method_call(GDBusConnection *connection,
        else if (g_strcmp0(method_name, "get_restriction_mode") == 0)
                ret = __handle_request_get_restriction_mode(uid, invocation,
                                parameters);
+       else if (g_strcmp0(method_name, "set_app_label") == 0)
+               ret = __handle_request_set_app_label(uid, invocation, parameters);
        else
                ret = -1;