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.
31 #include "pkgmgrinfo_basic.h"
32 #include "pkgmgrinfo_private.h"
33 #include "pkgmgrinfo_debug.h"
34 #include "pkgmgr-info.h"
35 #include "manager/pkginfo_manager.h"
37 static void __free_update_info(gpointer data)
39 updateinfo_x *update_info = (updateinfo_x *)data;
40 if (update_info == NULL)
43 if (update_info->pkgid)
44 free((void *)update_info->pkgid);
45 if (update_info->version)
46 free((void *)update_info->version);
47 free((void *)update_info);
51 API int pkgmgrinfo_updateinfo_create(
52 pkgmgrinfo_updateinfo_h *updateinfo_handle)
54 updateinfo_x *update_info;
56 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
57 "Update handle output parameter is NULL\n");
59 update_info = (updateinfo_x *)calloc(
60 1, sizeof(updateinfo_x));
61 if (update_info == NULL) {
62 _LOGE("Out of memory");
63 return PMINFO_R_ERROR;
66 *updateinfo_handle = update_info;
71 API int pkgmgrinfo_updateinfo_destroy(
72 pkgmgrinfo_updateinfo_h updateinfo_handle)
74 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
75 "Update info handle parameter is NULL\n");
77 __free_update_info(updateinfo_handle);
81 API int pkgmgrinfo_updateinfo_set_pkgid(
82 pkgmgrinfo_updateinfo_h updateinfo_handle, const char *pkgid)
84 updateinfo_x *updateinfo;
86 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
87 "Update info handle parameter is NULL\n");
88 retvm_if(pkgid == NULL, PMINFO_R_EINVAL,
89 "pkgid parameter is NULL\n");
91 updateinfo = (updateinfo_x *)updateinfo_handle;
92 if (updateinfo->pkgid)
93 free(updateinfo->pkgid);
95 updateinfo->pkgid = strdup(pkgid);
96 if (updateinfo->pkgid == NULL) {
97 _LOGE("Out of memory");
98 return PMINFO_R_ERROR;
104 API int pkgmgrinfo_updateinfo_set_version(
105 pkgmgrinfo_updateinfo_h updateinfo_handle, const char *version)
107 updateinfo_x *updateinfo;
109 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
110 "Update info handle parameter is NULL\n");
111 retvm_if(version == NULL, PMINFO_R_EINVAL,
112 "pkgid parameter is NULL\n");
114 updateinfo = (updateinfo_x *)updateinfo_handle;
115 if (updateinfo->version)
116 free(updateinfo->version);
118 updateinfo->version = strdup(version);
119 if (updateinfo->version == NULL) {
120 _LOGE("Out of memory");
121 return PMINFO_R_ERROR;
127 API int pkgmgrinfo_updateinfo_set_type(
128 pkgmgrinfo_updateinfo_h updateinfo_handle,
129 pkgmgrinfo_updateinfo_update_type type)
131 updateinfo_x *updateinfo;
133 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
134 "Update info handle parameter is NULL\n");
136 updateinfo = (updateinfo_x *)updateinfo_handle;
137 updateinfo->type = type;
141 API int pkgmgrinfo_updateinfo_get_pkgid(
142 pkgmgrinfo_updateinfo_h updateinfo_handle, char **pkgid)
144 updateinfo_x *update_info;
146 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
147 "Update info node parameter is NULL\n");
149 update_info = (updateinfo_x *)updateinfo_handle;
150 if (update_info->pkgid == NULL)
151 return PMINFO_R_ERROR;
153 *pkgid = update_info->pkgid;
157 API int pkgmgrinfo_updateinfo_get_version(
158 pkgmgrinfo_updateinfo_h updateinfo_handle, char **version)
160 updateinfo_x *update_info;
162 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
163 "Update info node parameter is NULL\n");
165 update_info = (updateinfo_x *)updateinfo_handle;
166 if (update_info->version == NULL)
167 return PMINFO_R_ERROR;
169 *version = update_info->version;
173 API int pkgmgrinfo_updateinfo_get_update_type(
174 pkgmgrinfo_updateinfo_h updateinfo_handle,
175 pkgmgrinfo_updateinfo_update_type *type)
177 updateinfo_x *update_info;
179 retvm_if(updateinfo_handle == NULL, PMINFO_R_EINVAL,
180 "Update info node parameter is NULL\n");
182 update_info = (updateinfo_x *)updateinfo_handle;
183 *type = update_info->type;
188 API int pkgmgrinfo_updateinfo_get_usr_updateinfo(const char *pkgid,
189 pkgmgrinfo_updateinfo_h *update_handle, uid_t uid)
192 pkgmgrinfo_pkginfo_h pkginfo = NULL;
194 GSList *info_list = NULL;
196 if (update_handle == NULL || pkgid == NULL)
197 return PMINFO_R_EINVAL;
199 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
200 if (ret != PMINFO_R_OK)
203 ret = pkgmgrinfo_pkginfo_is_global(pkginfo, &is_global_pkg);
204 if (ret != PMINFO_R_OK) {
205 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
208 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
210 ret = _get_pkg_updateinfo(pkgid, &info_list,
211 (is_global_pkg) ? GLOBAL_USER : uid);
213 if (ret != PMINFO_R_OK) {
214 g_slist_free_full(info_list, __free_update_info);
215 return PMINFO_R_ERROR;
217 *update_handle = (pkgmgrinfo_updateinfo_h)info_list->data;
218 g_slist_free(info_list);
223 API int pkgmgrinfo_updateinfo_get_updateinfo(const char *pkgid,
224 pkgmgrinfo_updateinfo_h *update_handle)
226 return pkgmgrinfo_updateinfo_get_usr_updateinfo(pkgid, update_handle, _getuid());
229 API int pkgmgrinfo_updateinfo_usr_foreach_updateinfo(uid_t uid,
230 pkgmgrinfo_foreach_updateinfo_cb callback, void *user_data)
233 GSList *info_list = NULL;
236 if (callback == NULL)
237 return PMINFO_R_EINVAL;
239 ret = _get_pkg_updateinfo(NULL, &info_list, uid);
241 _LOGE("Failed to get pkg update info for user[%d]", (int)uid);
242 g_slist_free_full(info_list, __free_update_info);
243 return PMINFO_R_ERROR;
246 ret = _get_pkg_updateinfo(NULL, &info_list, GLOBAL_USER);
248 _LOGE("Failed to get pkg update info for user[%d]",
250 g_slist_free_full(info_list, __free_update_info);
251 return PMINFO_R_ERROR;
254 for (tmp_list = info_list; tmp_list; tmp_list = g_slist_next(tmp_list)) {
255 ret = callback((pkgmgrinfo_updateinfo_h)tmp_list->data, user_data);
260 g_slist_free_full(info_list, __free_update_info);
264 API int pkgmgrinfo_updateinfo_foreach_updateinfo(
265 pkgmgrinfo_foreach_updateinfo_cb callback, void *user_data)
267 return pkgmgrinfo_updateinfo_usr_foreach_updateinfo(_getuid(),
268 callback, user_data);