+static int __convert_updateinfo_type(const char *type, pkgmgrinfo_updateinfo_update_type *converted_type)
+{
+ if (type == NULL || converted_type == NULL)
+ return -1;
+
+ if (strncmp(type, PMINFO_UPDATEINFO_TYPE_NONE, strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
+ *converted_type = PMINFO_UPDATEINFO_NONE;
+ else if (strncmp(type, PMINFO_UPDATEINFO_TYPE_FORCE, strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
+ *converted_type = PMINFO_UPDATEINFO_FORCE;
+ else if (strncmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL, strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
+ *converted_type = PMINFO_UPDATEINFO_OPTIONAL;
+ else
+ return -1;
+ return 0;
+}
+
+static int __handle_request_register_pkg_update_info(
+ uid_t caller_uid, GDBusMethodInvocation *invocation,
+ GVariant *parameters)
+{
+ char *reqkey;
+ char buf[MAX_PKG_ARGS_LEN];
+ int ret;
+ pkgmgrinfo_pkginfo_h pkg_info;
+ bool is_global_pkg;
+ pkgmgrinfo_updateinfo_h update_info;
+ pkgmgrinfo_updateinfo_update_type converted_type;
+ uid_t target_uid = (uid_t)-1;
+ gchar *pkgid = NULL;
+ gchar *version = NULL;
+
+ g_variant_get(parameters, "(ussi)", &target_uid, &pkgid, &version, &converted_type);
+
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, target_uid, &pkg_info);
+ if (ret != PMINFO_R_OK) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_EIO));
+ return -1;
+ }
+ ret = pkgmgrinfo_pkginfo_is_global(pkg_info, &is_global_pkg);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_EIO));
+ return -1;
+ }
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+
+ /* return error if given pkg is global pkg but caller is not admin */
+ if (caller_uid >= REGULAR_USER && is_global_pkg
+ && !__is_admin_user(caller_uid)) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_EPRIV));
+ return -1;
+ }
+
+ ret = pkgmgrinfo_updateinfo_create(&update_info);
+ if (ret != PMINFO_R_OK) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ENOMEM));
+ return -1;
+ }
+
+ ret = pkgmgrinfo_updateinfo_set_pkgid(update_info, (char *)pkgid);
+ if (ret != PMINFO_R_OK) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ENOMEM));
+ return -1;
+ }
+
+ ret = pkgmgrinfo_updateinfo_set_version(update_info, (char *)version);
+ if (ret != PMINFO_R_OK) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ENOMEM));
+ return -1;
+ }
+
+ ret = pkgmgrinfo_updateinfo_set_type(update_info, converted_type);
+ if (ret != PMINFO_R_OK) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ENOMEM));
+ return -1;
+ }
+
+ reqkey = __generate_reqkey("register_pkg_update_info");
+ if (reqkey == NULL) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ENOMEM));
+ return -1;
+ }
+
+ if (_push_queue(target_uid, caller_uid, reqkey,
+ REQUEST_TYPE_REGISTER_PKG_UPDATE_INFO, "default",
+ NULL, buf, update_info))
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+
+ if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+ (gpointer)invocation))
+ ERR("reqkey already exists");
+
+ return 0;
+}
+
+static int __handle_request_unregister_pkg_update_info(
+ uid_t caller_uid, GDBusMethodInvocation *invocation,
+ GVariant *parameters)
+{
+ uid_t target_uid = (uid_t)-1;
+ char *pkgid = NULL;
+ char *reqkey;
+ pkgmgrinfo_pkginfo_h pkg_info;
+ bool is_global_pkg;
+ int ret;
+
+ 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;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, target_uid, &pkg_info);
+ if (ret != PMINFO_R_OK) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_EIO));
+ return -1;
+ }
+ ret = pkgmgrinfo_pkginfo_is_global(pkg_info, &is_global_pkg);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_EIO));
+ return -1;
+ }
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+
+ /* return error if given pkg is global pkg but caller is not admin */
+ if (caller_uid >= REGULAR_USER && is_global_pkg
+ && !__is_admin_user(caller_uid)) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_EPRIV));
+ return -1;
+ }
+
+ reqkey = __generate_reqkey("unregister_pkg_update_info");
+ if (reqkey == NULL) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ENOMEM));
+ return -1;
+ }
+
+ if (_push_queue(target_uid, caller_uid, reqkey,
+ REQUEST_TYPE_UNREGISTER_PKG_UPDATE_INFO, "default",
+ pkgid, NULL, NULL))
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+
+ if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+ (gpointer)invocation))
+ ERR("reqkey already exists");
+
+
+ return 0;
+
+}
+
+static int __handle_request_unregister_all_pkg_update_info(
+ uid_t caller_uid, GDBusMethodInvocation *invocation,
+ GVariant *parameters)
+{
+ uid_t target_uid = (uid_t)-1;
+ char *reqkey;
+
+ g_variant_get(parameters, "(u)", &target_uid);
+ if (target_uid == (uid_t)-1) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+ return -1;
+ }
+
+ reqkey = __generate_reqkey("unregister_all_pkg_update_info");
+ if (reqkey == NULL) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+ return -1;
+ }
+
+ if (_push_queue(target_uid, caller_uid, reqkey,
+ REQUEST_TYPE_UNREGISTER_ALL_PKG_UPDATE_INFO, "default",
+ NULL, NULL, NULL))
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+
+ if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+ (gpointer)invocation))
+ ERR("reqkey already exists");
+
+ return 0;
+}
+