4 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Junghyun Yeon(jungh.yeon@samsung.com>,
7 * Jongmyeong Ko(jongmyeong.ko@samsung.com>, Sangyoon Jang(s89.jang@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include "pkgmgrinfo_basic.h"
31 #include "pkgmgrinfo_private.h"
32 #include "pkgmgrinfo_debug.h"
33 #include "pkgmgr-info.h"
34 #include "manager/pkginfo_manager.h"
36 static void __free_update_info(gpointer data)
38 updateinfo_x *update_info = (updateinfo_x *)data;
39 if (update_info == NULL)
42 if (update_info->pkgid)
43 free((void *)update_info->pkgid);
44 if (update_info->version)
45 free((void *)update_info->version);
46 free((void *)update_info);
50 API int pkgmgrinfo_updateinfo_create(
51 pkgmgrinfo_updateinfo_h *updateinfo_handle)
53 updateinfo_x *update_info;
55 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
56 "Update handle output parameter is NULL\n");
58 update_info = (updateinfo_x *)calloc(
59 1, sizeof(updateinfo_x));
60 if (update_info == NULL) {
61 _LOGE("Out of memory");
62 return PMINFO_R_ERROR;
65 *updateinfo_handle = update_info;
70 API int pkgmgrinfo_updateinfo_destroy(
71 pkgmgrinfo_updateinfo_h updateinfo_handle)
73 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
74 "Update info handle parameter is NULL\n");
76 __free_update_info(updateinfo_handle);
80 API int pkgmgrinfo_updateinfo_set_pkgid(
81 pkgmgrinfo_updateinfo_h updateinfo_handle, const char *pkgid)
83 updateinfo_x *updateinfo;
85 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
86 "Update info handle parameter is NULL\n");
87 retvm_if(pkgid == NULL, PMINFO_R_EINVAL,
88 "pkgid parameter is NULL\n");
90 updateinfo = (updateinfo_x *)updateinfo_handle;
91 if (updateinfo->pkgid)
92 free(updateinfo->pkgid);
94 updateinfo->pkgid = strdup(pkgid);
95 if (updateinfo->pkgid == NULL) {
96 _LOGE("Out of memory");
97 return PMINFO_R_ERROR;
103 API int pkgmgrinfo_updateinfo_set_version(
104 pkgmgrinfo_updateinfo_h updateinfo_handle, const char *version)
106 updateinfo_x *updateinfo;
108 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
109 "Update info handle parameter is NULL\n");
110 retvm_if(version == NULL, PMINFO_R_EINVAL,
111 "pkgid parameter is NULL\n");
113 updateinfo = (updateinfo_x *)updateinfo_handle;
114 if (updateinfo->version)
115 free(updateinfo->version);
117 updateinfo->version = strdup(version);
118 if (updateinfo->version == NULL) {
119 _LOGE("Out of memory");
120 return PMINFO_R_ERROR;
126 API int pkgmgrinfo_updateinfo_set_type(
127 pkgmgrinfo_updateinfo_h updateinfo_handle,
128 pkgmgrinfo_updateinfo_update_type type)
130 updateinfo_x *updateinfo;
132 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
133 "Update info handle parameter is NULL\n");
135 updateinfo = (updateinfo_x *)updateinfo_handle;
136 updateinfo->type = type;
140 API int pkgmgrinfo_updateinfo_get_pkgid(
141 pkgmgrinfo_updateinfo_h updateinfo_handle, char **pkgid)
143 updateinfo_x *update_info;
145 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
146 "Update info node parameter is NULL\n");
148 update_info = (updateinfo_x *)updateinfo_handle;
149 if (update_info->pkgid == NULL)
150 return PMINFO_R_ERROR;
152 *pkgid = update_info->pkgid;
156 API int pkgmgrinfo_updateinfo_get_version(
157 pkgmgrinfo_updateinfo_h updateinfo_handle, char **version)
159 updateinfo_x *update_info;
161 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
162 "Update info node parameter is NULL\n");
164 update_info = (updateinfo_x *)updateinfo_handle;
165 if (update_info->version == NULL)
166 return PMINFO_R_ERROR;
168 *version = update_info->version;
172 API int pkgmgrinfo_updateinfo_get_update_type(
173 pkgmgrinfo_updateinfo_h updateinfo_handle,
174 pkgmgrinfo_updateinfo_update_type *type)
176 updateinfo_x *update_info;
178 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
179 "Update info node parameter is NULL\n");
181 update_info = (updateinfo_x *)updateinfo_handle;
182 *type = update_info->type;
187 API int pkgmgrinfo_updateinfo_get_usr_updateinfo(const char *pkgid,
188 pkgmgrinfo_updateinfo_h *update_handle, uid_t uid)
191 pkgmgrinfo_pkginfo_h pkginfo = NULL;
193 GSList *info_list = NULL;
195 if (update_handle == NULL || pkgid == NULL)
196 return PMINFO_R_EINVAL;
198 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
199 if (ret != PMINFO_R_OK)
202 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
203 if (ret != PMINFO_R_OK) {
204 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
207 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
209 ret = _get_pkg_updateinfo(pkgid, &info_list,
210 (is_global_pkg) ? GLOBAL_USER : uid);
212 if (ret != PMINFO_R_OK) {
213 g_slist_free_full(info_list, __free_update_info);
214 return PMINFO_R_ERROR;
216 *update_handle = (pkgmgrinfo_updateinfo_h)info_list->data;
217 g_slist_free(info_list);
222 API int pkgmgrinfo_updateinfo_get_updateinfo(const char *pkgid,
223 pkgmgrinfo_updateinfo_h *update_handle)
225 return pkgmgrinfo_updateinfo_get_usr_updateinfo(pkgid, update_handle, _getuid());
228 API int pkgmgrinfo_updateinfo_usr_foreach_updateinfo(uid_t uid,
229 pkgmgrinfo_foreach_updateinfo_cb callback, void *user_data)
232 GSList *info_list = NULL;
235 if (callback == NULL)
236 return PMINFO_R_EINVAL;
238 ret = _get_pkg_updateinfo(NULL, &info_list, uid);
240 _LOGE("Failed to get pkg update info for user[%d]", (int)uid);
241 return PMINFO_R_ERROR;
244 for (tmp_list = info_list; tmp_list; tmp_list = g_slist_next(tmp_list)) {
245 ret = callback((pkgmgrinfo_updateinfo_h)tmp_list->data, user_data);
250 g_slist_free_full(info_list, __free_update_info);
254 API int pkgmgrinfo_updateinfo_foreach_updateinfo(
255 pkgmgrinfo_foreach_updateinfo_cb callback, void *user_data)
257 return pkgmgrinfo_updateinfo_usr_foreach_updateinfo(_getuid(),
258 callback, user_data);