4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@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.
33 #include "pkgmgr-info.h"
34 #include "pkgmgrinfo_debug.h"
35 #include "pkgmgrinfo_private.h"
36 #include "pkgmgr_parser.h"
38 static GHashTable *plugin_set_list;
40 struct _pkginfo_str_map_t {
41 pkgmgrinfo_pkginfo_filter_prop_str prop;
45 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
46 {E_PMINFO_PKGINFO_PROP_PACKAGE_ID, PMINFO_PKGINFO_PROP_PACKAGE_ID},
47 {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE, PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
48 {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION, PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
49 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
50 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
51 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
52 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
53 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF},
54 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE},
55 {E_PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE, PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE}
58 struct _pkginfo_int_map_t {
59 pkgmgrinfo_pkginfo_filter_prop_int prop;
63 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
64 {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE, PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
67 struct _pkginfo_bool_map_t {
68 pkgmgrinfo_pkginfo_filter_prop_bool prop;
72 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
73 {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
74 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
75 {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY, PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
76 {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
77 {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
78 {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING, PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
79 {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
80 {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE},
81 {E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE},
82 {E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM}
85 struct _appinfo_str_map_t {
86 pkgmgrinfo_appinfo_filter_prop_str prop;
90 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
91 {E_PMINFO_APPINFO_PROP_APP_ID, PMINFO_APPINFO_PROP_APP_ID},
92 {E_PMINFO_APPINFO_PROP_APP_COMPONENT, PMINFO_APPINFO_PROP_APP_COMPONENT},
93 {E_PMINFO_APPINFO_PROP_APP_EXEC, PMINFO_APPINFO_PROP_APP_EXEC},
94 {E_PMINFO_APPINFO_PROP_APP_ICON, PMINFO_APPINFO_PROP_APP_ICON},
95 {E_PMINFO_APPINFO_PROP_APP_TYPE, PMINFO_APPINFO_PROP_APP_TYPE},
96 {E_PMINFO_APPINFO_PROP_APP_OPERATION, PMINFO_APPINFO_PROP_APP_OPERATION},
97 {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
98 {E_PMINFO_APPINFO_PROP_APP_MIME, PMINFO_APPINFO_PROP_APP_MIME},
99 {E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY},
100 {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION},
101 {E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER},
102 {E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE},
103 {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE},
104 {E_PMINFO_APPINFO_PROP_PRIVILEGE, PMINFO_APPINFO_PROP_PRIVILEGE}
107 struct _appinfo_int_map_t {
108 pkgmgrinfo_appinfo_filter_prop_int prop;
109 const char *property;
112 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
113 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE, PMINFO_APPINFO_PROP_APP_SUPPORT_MODE}
116 struct _appinfo_bool_map_t {
117 pkgmgrinfo_appinfo_filter_prop_bool prop;
118 const char *property;
121 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
122 {E_PMINFO_APPINFO_PROP_APP_NODISPLAY, PMINFO_APPINFO_PROP_APP_NODISPLAY},
123 {E_PMINFO_APPINFO_PROP_APP_MULTIPLE, PMINFO_APPINFO_PROP_APP_MULTIPLE},
124 {E_PMINFO_APPINFO_PROP_APP_ONBOOT, PMINFO_APPINFO_PROP_APP_ONBOOT},
125 {E_PMINFO_APPINFO_PROP_APP_AUTORESTART, PMINFO_APPINFO_PROP_APP_AUTORESTART},
126 {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE, PMINFO_APPINFO_PROP_APP_TASKMANAGE},
127 {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
128 {E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET},
129 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
130 {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE},
131 {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE},
132 {E_PMINFO_APPINFO_PROP_PKG_DISABLE, PMINFO_APPINFO_PROP_PKG_DISABLE}
135 API pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
139 pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
141 if (property == NULL)
143 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
144 for (i = 0 ; i < max; i++) {
145 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
146 prop = pkginfo_str_prop_map[i].prop;
153 API pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
157 pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
159 if (property == NULL)
161 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
162 for (i = 0 ; i < max; i++) {
163 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
164 prop = pkginfo_int_prop_map[i].prop;
171 API pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
175 pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
177 if (property == NULL)
179 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
180 for (i = 0 ; i < max; i++) {
181 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
182 prop = pkginfo_bool_prop_map[i].prop;
189 API pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
193 pkgmgrinfo_appinfo_filter_prop_str prop = -1;
195 if (property == NULL)
197 max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
198 for (i = 0 ; i < max; i++) {
199 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
200 prop = appinfo_str_prop_map[i].prop;
207 API pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
211 pkgmgrinfo_appinfo_filter_prop_int prop = -1;
213 if (property == NULL)
215 max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
216 for (i = 0 ; i < max; i++) {
217 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
218 prop = appinfo_int_prop_map[i].prop;
225 API pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
229 pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
231 if (property == NULL)
233 max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
234 for (i = 0 ; i < max; i++) {
235 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
236 prop = appinfo_bool_prop_map[i].prop;
243 void _pkgmgrinfo_node_destroy(pkgmgrinfo_node_x *node)
253 API int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params)
255 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
256 char buf[MAX_QUERY_LEN] = {'\0'};
260 char *saveptr = NULL;
262 switch (node->prop) {
263 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
264 snprintf(buf, sizeof(buf), "pi.package=?");
266 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
267 snprintf(buf, sizeof(buf), "pi.package_type=?");
269 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
270 snprintf(buf, sizeof(buf), "pi.package_version=?");
272 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
273 snprintf(buf, sizeof(buf), "pi.install_location=?");
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
276 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
278 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
279 snprintf(buf, sizeof(buf), "pi.author_name=?");
281 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
282 snprintf(buf, sizeof(buf), "pi.author_href=?");
284 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
285 snprintf(buf, sizeof(buf), "pi.author_email=?");
287 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
288 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
289 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
291 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
292 snprintf(buf, sizeof(buf), "pi.package_size=?");
294 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
295 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
297 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
298 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
300 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
301 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
303 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
304 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
306 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
307 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
309 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
310 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
312 case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
313 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
315 case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
317 case E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM:
318 snprintf(buf, sizeof(buf), "pi.package_system=? COLLATE NOCASE");
320 case E_PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE:
321 if (node->value == NULL || strlen(node->value) == 0) {
322 *condition = strdup("package_res_info.res_type IS NOT NULL COLLATE NOCASE");
323 if (*condition == NULL) {
324 _LOGE("out of memeory");
327 return E_PMINFO_PKGINFO_JOIN_RES_INFO;
329 snprintf(buf, sizeof(buf), "package_res_info.res_type=? COLLATE NOCASE");
330 flag = E_PMINFO_PKGINFO_JOIN_RES_INFO;
333 case E_PMINFO_APPINFO_PROP_APP_ID:
334 snprintf(buf, sizeof(buf), "ai.app_id=?");
336 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
337 snprintf(buf, sizeof(buf), "ai.app_component=?");
339 case E_PMINFO_APPINFO_PROP_APP_EXEC:
340 snprintf(buf, sizeof(buf), "ai.app_exec=?");
342 case E_PMINFO_APPINFO_PROP_APP_ICON:
343 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
344 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
346 case E_PMINFO_APPINFO_PROP_APP_TYPE:
347 snprintf(buf, sizeof(buf), "ai.app_type=?");
349 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
350 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE ?||'|%%%%|%%%%'");
351 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
353 case E_PMINFO_APPINFO_PROP_APP_URI:
354 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|'||?||'|%%%%'");
355 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
357 case E_PMINFO_APPINFO_PROP_APP_MIME:
358 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|%%%%|'||?");
359 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
361 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
362 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
363 value = strdup(node->value);
365 _LOGE("out of memeory");
368 ptr = strtok_r(value, ",", &saveptr);
373 strncat(buf, "?", sizeof(buf) - strlen(buf) - 1);
374 *params = g_list_append(*params, strdup(ptr));
375 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
376 strncat(buf, ", ?", sizeof(buf) - strlen(buf) - 1);
377 *params = g_list_append(*params, strdup(ptr));
379 strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
380 *condition = strdup(buf);
381 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
385 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
386 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
388 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
389 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
391 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
392 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
394 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
395 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
397 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
398 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
400 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
401 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
403 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
404 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
406 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
407 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
409 case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
410 snprintf(buf, sizeof(buf), "ai.package=?");
412 case E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE:
413 snprintf(buf, sizeof(buf), "ai.app_installed_storage=?");
415 case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
416 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
418 case E_PMINFO_APPINFO_PROP_APP_DISABLE:
421 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
422 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
424 case E_PMINFO_APPINFO_PROP_PKG_DISABLE:
427 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
428 snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
430 case E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE:
431 case E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE:
434 case E_PMINFO_APPINFO_PROP_PRIVILEGE:
435 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
436 flag = E_PMINFO_APPINFO_JOIN_PRIVILEGE;
439 _LOGE("Invalid Property Type\n");
443 *condition = strdup(buf);
444 *params = g_list_append(*params, strdup(node->value));
448 API int __get_pkg_metadata_filter_condition(gpointer data, char **condition,
451 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
452 char buf[MAX_QUERY_LEN];
454 snprintf(buf, sizeof(buf), "(package_metadata.md_key=?");
456 strncat(buf, " AND package_metadata.md_value=?",
457 sizeof(buf) - strlen(buf) - 1);
458 strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
460 *condition = strdup(buf);
461 *params = g_list_append(*params, strdup(node->key));
463 *params = g_list_append(*params, strdup(node->value));
465 return E_PMINFO_PKGINFO_JOIN_METADATA;
468 API int __get_metadata_filter_condition(gpointer data, char **condition,
471 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
472 char buf[MAX_QUERY_LEN];
474 snprintf(buf, sizeof(buf), "(package_app_app_metadata.md_key=?");
476 strncat(buf, " AND package_app_app_metadata.md_value=?",
477 sizeof(buf) - strlen(buf) - 1);
478 strncat(buf, ")", sizeof(buf) - strlen(buf) - 1);
480 *condition = strdup(buf);
481 *params = g_list_append(*params, strdup(node->key));
483 *params = g_list_append(*params, strdup(node->value));
485 return E_PMINFO_APPINFO_JOIN_METADATA;
488 API int _add_icon_info_into_list(const char *locale, char *value, GList **icon)
492 info = calloc(1, sizeof(icon_x));
494 LOGE("out of memory");
495 return PMINFO_R_ERROR;
498 info->lang = strdup(locale);
499 *icon = g_list_prepend(*icon, info);
504 API int _add_label_info_into_list(const char *locale, char *value, GList **label)
508 info = calloc(1, sizeof(label_x));
510 LOGE("out of memory");
511 return PMINFO_R_ERROR;
514 info->lang = strdup(locale);
515 *label = g_list_prepend(*label, info);
520 API int __pkginfo_check_installed_storage(package_x *pkginfo)
522 char buf[MAX_QUERY_LEN] = {'\0'};
525 retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
526 retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
527 "installed_storage is NULL\n");
529 if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
530 snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
531 ret = access(buf, R_OK);
533 _LOGE("can not access [%s] - %d", buf, ret);
534 return PMINFO_R_ERROR;
541 API int __appinfo_check_installed_storage(application_x *appinfo)
543 retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
544 "installed_storage is NULL\n");
546 if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
547 retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
548 "external path is NULL\n");
549 if (access(appinfo->external_path, R_OK) != 0) {
550 _LOGE("can not access [%s]", appinfo->external_path);
551 return PMINFO_R_ERROR;
559 const char *manifest;
563 const struct type_map type_map[] = {
564 { "res/wgt/config.xml", "wgt" },
565 { "config.xml", "wgt" },
566 { "tizen-manifest.xml", "tpk" },
570 API char *__get_type_from_path(const char *pkg_path)
572 const char *type = NULL;
576 uf = unzOpen(pkg_path);
578 _LOGE("failed to open zip file %s", pkg_path);
582 for (i = 0; type_map[i].manifest != NULL; i++) {
583 if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) {
584 _LOGD("pkgtype of %s: [%s]", pkg_path,
586 type = type_map[i].type;
593 _LOGE("cannot get pkg type of file %s", pkg_path);
600 static void __get_library_path(const char *pkg_type, const char **path)
604 snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so",
607 *path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf);
610 API pkg_plugin_set *__load_library(const char *pkg_type)
612 void *library_handle;
613 pkg_plugin_set *plugin_set;
614 bool (*on_load)(pkg_plugin_set *plugin);
615 const char *library_path;
617 __get_library_path(pkg_type, &library_path);
618 if (library_path == NULL) {
619 _LOGE("cannot get library path for %s", pkg_type);
623 if (plugin_set_list == NULL) {
624 plugin_set_list = g_hash_table_new_full(g_str_hash,
625 g_str_equal, free, free);
626 if (plugin_set_list == NULL) {
627 _LOGE("out of memory");
632 plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
633 (gconstpointer)pkg_type);
635 _LOGD("already loaded [%s]", library_path);
639 library_handle = dlopen(library_path, RTLD_LAZY);
640 if (library_handle == NULL) {
641 _LOGE("dlopen is failed library_path[%s]", library_path);
645 on_load = dlsym(library_handle, "pkg_plugin_on_load");
646 if (on_load == NULL || dlerror() != NULL) {
647 _LOGE("cannot find symbol");
648 dlclose(library_handle);
652 plugin_set = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set));
653 if (plugin_set == NULL) {
654 _LOGE("out of memory");
655 dlclose(library_handle);
659 if (on_load(plugin_set) != 0) {
660 _LOGE("pkg_plugin_on_load failed");
662 dlclose(library_handle);
667 plugin_set->plugin_handle = library_handle;
668 snprintf(plugin_set->pkg_type,
669 sizeof(plugin_set->pkg_type), "%s", pkg_type);
671 g_hash_table_insert(plugin_set_list, (gpointer)strdup(pkg_type),
672 (gpointer)plugin_set);
674 _LOGD("library [%s] is loaded", library_path);
679 API void __unload_library(const char *pkg_type)
681 pkg_plugin_set *plugin_set;
683 if (plugin_set_list == NULL)
686 plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list,
687 (gconstpointer)pkg_type);
689 if (plugin_set == NULL) {
690 _LOGE("pkg plugin for %s is not loaded", pkg_type);
694 plugin_set->plugin_on_unload();
695 dlclose(plugin_set->plugin_handle);
696 g_hash_table_remove(plugin_set_list, (gconstpointer)pkg_type);