2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 #include <libxml/parser.h>
29 #include <libxml/xmlreader.h>
30 #include <libxml/xmlschemas.h>
32 #include <tzplatform_config.h>
34 #include "pkgmgrinfo_basic.h"
35 #include "pkgmgr-info.h"
36 #include "pkgmgr_parser.h"
37 #include "pkgmgr_parser_db.h"
38 #include "pkgmgr_parser_debug.h"
39 #include "pkgmgr_parser_internal.h"
41 #define ASCII(s) (char *)s
42 #define XMLCHAR(s) (const xmlChar *)s
44 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
45 #define METADATA_PARSER_NAME "metadataparser:"
47 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
48 #define CATEGORY_PARSER_NAME "categoryparser:"
50 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
51 #define TAG_PARSER_NAME "parserlib:"
56 /* plugin process_type */
58 PLUGIN_PRE_PROCESS = 0,
60 } PLUGIN_PROCESS_TYPE;
64 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, char **xml_attribute, char *default_value)
66 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
68 *xml_attribute = strdup((const char *)attrib_val);
71 if (default_value != NULL)
72 *xml_attribute = strdup(default_value);
76 static void __save_xml_value(xmlTextReaderPtr reader, char **xml_attribute)
79 const xmlChar *attrib_val;
81 ret = xmlTextReaderRead(reader);
84 attrib_val = xmlTextReaderConstValue(reader);
87 *xml_attribute = strdup((const char *)attrib_val);
90 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
92 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
93 if (attrib_val != NULL)
94 *xml_attribute = strdup(ASCII(attrib_val));
96 *xml_attribute = strdup(DEFAULT_LOCALE);
99 static void __save_xml_installed_time(manifest_x *mfx)
101 char buf[PKG_STRING_LEN_MAX] = {'\0'};
105 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
106 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
107 mfx->installed_time = val;
110 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
112 char root[PKG_STRING_LEN_MAX] = { '\0' };
118 tzplatform_set_user(uid);
119 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
120 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
122 mfx->root_path = strdup(root);
124 tzplatform_reset_user();
127 static void __save_xml_default_value(manifest_x * mfx)
129 mfx->preload = strdup("False");
130 mfx->removable = strdup("True");
131 mfx->readonly = strdup("False");
132 mfx->update = strdup("False");
133 mfx->system = strdup("False");
134 mfx->installed_storage = strdup("installed_internal");
135 package = mfx->package;
138 static int __next_child_element(xmlTextReaderPtr reader, int depth)
140 int ret = xmlTextReaderRead(reader);
141 int cur = xmlTextReaderDepth(reader);
144 switch (xmlTextReaderNodeType(reader)) {
145 case XML_READER_TYPE_ELEMENT:
146 if (cur == depth + 1)
149 case XML_READER_TYPE_TEXT:
150 /*text is handled by each function separately*/
151 if (cur == depth + 1)
154 case XML_READER_TYPE_END_ELEMENT:
163 ret = xmlTextReaderRead(reader);
164 cur = xmlTextReaderDepth(reader);
169 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
171 __save_xml_attribute(reader, "name", &label->name, NULL);
172 __save_xml_lang(reader, &label->lang);
173 __save_xml_value(reader, &label->text);
178 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
180 __save_xml_attribute(reader, "email", &author->email, NULL);
181 __save_xml_attribute(reader, "href", &author->href, NULL);
182 __save_xml_value(reader, &author->text);
186 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
188 __save_xml_lang(reader, &description->lang);
189 __save_xml_value(reader, &description->text);
193 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
195 __save_xml_lang(reader, &license->lang);
196 __save_xml_value(reader, &license->text);
200 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
202 __save_xml_attribute(reader, "type", &privilege->type, "tpk");
203 __save_xml_value(reader, &privilege->value);
206 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
212 depth = xmlTextReaderDepth(reader);
213 while ((ret = __next_child_element(reader, depth))) {
214 node = xmlTextReaderConstName(reader);
216 _LOGD("xmlTextReaderConstName value is NULL\n");
220 if (strcmp(ASCII(node), "privilege") == 0) {
221 privilege_x *privilege = calloc(1, sizeof(privilege_x));
222 if (privilege == NULL) {
223 _LOGD("Malloc Failed\n");
226 ret = __ps_process_privilege(reader, privilege);
230 *privileges = g_list_append(*privileges, (gpointer)privilege);
235 _LOGD("Processing privileges failed\n");
242 static char *__get_icon_with_path(const char *icon, uid_t uid)
244 char icon_with_path[BUFSIZE];
245 const char *app_path;
247 if (!icon || !package)
250 /* just use absolute path */
251 if (index(icon, '/'))
255 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
256 snprintf(icon_with_path, sizeof(icon_with_path),
257 "%s%s", getIconPath(uid, true), icon);
258 if (access(icon_with_path, F_OK) == 0)
261 snprintf(icon_with_path, sizeof(icon_with_path),
262 "%s%s", getIconPath(uid, false), icon);
263 if (access(icon_with_path, F_OK) == 0)
266 /* for backward compatibility (.../default/small/...)
267 * this should be removed
269 snprintf(icon_with_path, sizeof(icon_with_path),
270 "%sdefault/small/%s",
271 getIconPath(uid, true), icon);
272 if (access(icon_with_path, F_OK) == 0)
275 snprintf(icon_with_path, sizeof(icon_with_path),
276 "%sdefault/small/%s",
277 getIconPath(uid, false), icon);
278 if (access(icon_with_path, F_OK) == 0)
281 /* If doesn't exist in case of Global app,
282 * try to get icon directly into app's directory
284 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
286 snprintf(icon_with_path, sizeof(icon_with_path),
287 "%s/%s/%s", app_path, package, icon);
288 if (access(icon_with_path, F_OK) == 0)
291 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
293 snprintf(icon_with_path, sizeof(icon_with_path),
294 "%s/%s/%s", app_path, package, icon);
295 if (access(icon_with_path, F_OK) == 0)
298 tzplatform_set_user(uid);
299 app_path = tzplatform_getenv(TZ_USER_APP);
300 tzplatform_reset_user();
302 snprintf(icon_with_path, sizeof(icon_with_path),
303 "%s/%s/%s", app_path, package, icon);
304 if (access(icon_with_path, F_OK) == 0)
308 /* some preload package has icons at below path */
309 snprintf(icon_with_path, sizeof(icon_with_path),
310 "%s/%s/res/icons/%s", app_path, package, icon);
311 if (access(icon_with_path, F_OK) == 0)
314 /* since 2.3 tpk package */
315 snprintf(icon_with_path, sizeof(icon_with_path),
316 "%s/%s/shared/res/%s", app_path, package, icon);
317 if (access(icon_with_path, F_OK) == 0)
320 _LOGE("cannot find icon path for [%s]", icon);
324 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
326 return strdup(icon_with_path);
329 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
334 __save_xml_attribute(reader, "section", &icon->section, NULL);
335 __save_xml_attribute(reader, "size", &icon->size, NULL);
336 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
337 __save_xml_lang(reader, &icon->lang);
339 ret = xmlTextReaderRead(reader);
342 text = ASCII(xmlTextReaderValue(reader));
344 icon->text = __get_icon_with_path(text, uid);
351 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
353 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
354 __save_xml_value(reader, &compatibility->text);
358 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
360 __save_xml_attribute(reader, "section", &image->section, NULL);
361 __save_xml_lang(reader, &image->lang);
362 __save_xml_value(reader, &image->text);
366 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
368 __save_xml_attribute(reader, "name", category, NULL);
372 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
374 __save_xml_attribute(reader, "key", &metadata->key, NULL);
375 __save_xml_attribute(reader, "value", &metadata->value, NULL);
379 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
381 __save_xml_attribute(reader, "type", &permission->type, NULL);
382 __save_xml_value(reader, &permission->value);
386 struct appcontrol_data {
391 char operation[BUFSIZE];
396 static void __ps_process_mime(gpointer data, gpointer user_data)
398 char *mime = (char *)data;
399 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
400 appcontrol_x *appcontrol;
402 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
404 appcontrol = calloc(1, sizeof(appcontrol_x));
405 if (appcontrol == NULL) {
406 _LOGD("Malloc Failed\n");
409 if (strlen(ad->operation))
410 appcontrol->operation = strdup(ad->operation);
412 appcontrol->uri = strdup(ad->uri);
413 appcontrol->mime = strdup(ad->mime);
414 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
417 static void __ps_process_uri(gpointer data, gpointer user_data)
419 char *uri = (char *)data;
420 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
421 appcontrol_x *appcontrol;
423 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
425 if (ad->mimes != NULL) {
426 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
428 appcontrol = calloc(1, sizeof(appcontrol_x));
429 if (appcontrol == NULL) {
430 _LOGD("Malloc Failed\n");
433 if (strlen(ad->operation))
434 appcontrol->operation = strdup(ad->operation);
435 appcontrol->uri = strdup(ad->uri);
436 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
440 static void __ps_process_operation(gpointer data, gpointer user_data)
442 char *operation = (char *)data;
443 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
444 appcontrol_x *appcontrol;
446 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
448 if (ad->uris != NULL) {
449 g_list_foreach(ad->uris, __ps_process_uri, user_data);
450 } else if (ad->mimes != NULL) {
451 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
453 appcontrol = calloc(1, sizeof(appcontrol_x));
454 if (appcontrol == NULL) {
455 _LOGD("Malloc Failed\n");
458 appcontrol->operation = strdup(ad->operation);
459 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
463 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
465 struct appcontrol_data ad = {0, };
467 ad.operations = operations;
471 if (ad.operations == NULL)
474 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
476 return ad.appcontrols;
479 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
485 GList *operations = NULL;
490 depth = xmlTextReaderDepth(reader);
491 while ((ret = __next_child_element(reader, depth)) > 0) {
492 node = xmlTextReaderConstName(reader);
494 _LOGD("xmlTextReaderConstName value is NULL\n");
495 g_list_free_full(operations, free);
496 g_list_free_full(uris, free);
497 g_list_free_full(mimes, free);
502 if (!strcmp(ASCII(node), "operation")) {
503 __save_xml_attribute(reader, "name", &val, NULL);
505 operations = g_list_append(operations, (gpointer)val);
506 _LOGD("operation processing\n");
507 } else if (!strcmp(ASCII(node), "uri")) {
508 __save_xml_attribute(reader, "name", &val, NULL);
510 uris = g_list_append(uris, (gpointer)val);
511 _LOGD("uri processing\n");
512 } else if (!strcmp(ASCII(node), "mime")) {
513 __save_xml_attribute(reader, "name", &val, NULL);
515 mimes = g_list_append(mimes, (gpointer)val);
516 _LOGD("mime processing\n");
517 } else if (!strcmp(ASCII(node), "subapp")) {
525 _LOGD("Processing appcontrol failed\n");
526 g_list_free_full(operations, free);
527 g_list_free_full(uris, free);
528 g_list_free_full(mimes, free);
532 result = __make_appcontrol_list(operations, uris, mimes);
534 *appcontrol = g_list_concat(*appcontrol, result);
538 g_list_free_full(operations, free);
539 g_list_free_full(uris, free);
540 g_list_free_full(mimes, free);
545 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
547 __save_xml_value(reader, allowed);
551 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
553 __save_xml_value(reader, request);
557 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
564 __save_xml_attribute(reader, "path", &define->path, NULL);
566 depth = xmlTextReaderDepth(reader);
567 while ((ret = __next_child_element(reader, depth))) {
568 node = xmlTextReaderConstName(reader);
570 _LOGD("xmlTextReaderConstName value is NULL\n");
574 if (!strcmp(ASCII(node), "allowed")) {
576 ret = __ps_process_allowed(reader, &val);
578 define->allowed = g_list_append(define->allowed, (gpointer)val);
579 } else if (!strcmp(ASCII(node), "request")) {
581 ret = __ps_process_request(reader, &val);
583 define->request = g_list_append(define->request, (gpointer)val);
588 _LOGD("Processing define failed\n");
595 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
601 depth = xmlTextReaderDepth(reader);
602 while ((ret = __next_child_element(reader, depth))) {
603 node = xmlTextReaderConstName(reader);
605 _LOGD("xmlTextReaderConstName value is NULL\n");
609 if (!strcmp(ASCII(node), "define")) {
610 define_x *define = calloc(1, sizeof(define_x));
611 if (define == NULL) {
612 _LOGD("Malloc Failed\n");
615 datashare->define = g_list_append(datashare->define, define);
616 ret = __ps_process_define(reader, define);
617 } else if (!strcmp(ASCII(node), "request")) {
619 ret = __ps_process_request(reader, &val);
621 datashare->request = g_list_append(datashare->request, (gpointer)val);
625 _LOGD("Processing data-share failed\n");
632 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
634 __save_xml_attribute(reader, "name", condition, NULL);
638 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
645 depth = xmlTextReaderDepth(reader);
646 while ((ret = __next_child_element(reader, depth))) {
647 node = xmlTextReaderConstName(reader);
649 _LOGD("xmlTextReaderConstName value is NULL\n");
653 if (strcmp(ASCII(node), "condition") == 0) {
655 ret = __ps_process_condition(reader, &val);
657 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
661 _LOGD("Processing launchconditions failed\n");
669 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
671 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
672 __save_xml_value(reader, ¬ification->text);
676 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
678 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
679 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
680 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
684 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
686 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
687 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
688 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
689 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
690 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
691 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
692 __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
696 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
701 splashscreen_x *splashscreen;
703 depth = xmlTextReaderDepth(reader);
704 while ((ret = __next_child_element(reader, depth))) {
705 node = xmlTextReaderConstName(reader);
707 _LOGD("xmlTextReaderConstName value is NULL\n");
711 if (strcmp(ASCII(node), "splash-screen") == 0) {
712 splashscreen = calloc(1, sizeof(splashscreen_x));
713 if (splashscreen == NULL) {
714 _LOGD("Malloc Failed\n");
717 *splashscreens = g_list_append(*splashscreens, splashscreen);
718 ret = __ps_process_splashscreen(reader, splashscreen);
724 _LOGD("Processing splash-screen failed\n");
731 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
738 __save_xml_attribute(reader, "appid", &application->appid, NULL);
739 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
740 __save_xml_attribute(reader, "exec", &application->exec, NULL);
741 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
742 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
743 __save_xml_attribute(reader, "type", &application->type, NULL);
744 __save_xml_attribute(reader, "categories", &application->categories, NULL);
745 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
746 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
747 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
748 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
749 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
750 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
751 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
752 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
753 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
754 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
755 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
756 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
757 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
758 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
759 retvm_if(((strcmp(application->component_type, "svcapp") != 0) && (strcmp(application->component_type, "uiapp") != 0) && (strcmp(application->component_type, "widgetapp") != 0)), PM_PARSER_R_ERROR, "invalid component_type[%s]", application->component_type);
760 __save_xml_attribute(reader, "submode", &application->submode, "false");
761 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
762 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
763 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
764 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
765 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
766 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
767 __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
769 application->package = strdup(package);
770 /* overwrite some attributes if the app is widgetapp */
771 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
772 free((void *)application->nodisplay);
773 application->nodisplay = strdup("true");
774 free((void *)application->multiple);
775 application->multiple = strdup("true");
776 free((void *)application->type);
777 application->type = strdup("capp");
778 free((void *)application->taskmanage);
779 application->taskmanage = strdup("false");
780 free((void *)application->indicatordisplay);
781 application->indicatordisplay = strdup("false");
784 /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
785 if (strcmp(application->hwacceleration, "use-GL") == 0) {
786 free((void *)application->hwacceleration);
787 application->hwacceleration = strdup("on");
788 } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
789 free((void *)application->hwacceleration);
790 application->hwacceleration = strdup("off");
791 } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
792 free((void *)application->hwacceleration);
793 application->hwacceleration = strdup("default");
796 depth = xmlTextReaderDepth(reader);
797 while ((ret = __next_child_element(reader, depth))) {
798 node = xmlTextReaderConstName(reader);
800 _LOGD("xmlTextReaderConstName value is NULL\n");
803 if (!strcmp(ASCII(node), "label")) {
804 label_x *label = calloc(1, sizeof(label_x));
806 _LOGD("Malloc Failed\n");
809 application->label = g_list_append(application->label, label);
810 ret = __ps_process_label(reader, label);
811 } else if (!strcmp(ASCII(node), "icon")) {
812 icon_x *icon = calloc(1, sizeof(icon_x));
814 _LOGD("Malloc Failed\n");
817 application->icon = g_list_append(application->icon, icon);
818 ret = __ps_process_icon(reader, icon, uid);
819 } else if (!strcmp(ASCII(node), "image")) {
820 image_x *image = calloc(1, sizeof(image_x));
822 _LOGD("Malloc Failed\n");
825 application->image = g_list_append(application->image, image);
826 ret = __ps_process_image(reader, image);
827 } else if (!strcmp(ASCII(node), "category")) {
829 ret = __ps_process_category(reader, &val);
831 application->category = g_list_append(application->category, (gpointer)val);
832 } else if (!strcmp(ASCII(node), "metadata")) {
833 metadata_x *metadata = calloc(1, sizeof(metadata_x));
834 if (metadata == NULL) {
835 _LOGD("Malloc Failed\n");
838 application->metadata = g_list_append(application->metadata, metadata);
839 ret = __ps_process_metadata(reader, metadata);
840 } else if (!strcmp(ASCII(node), "permission")) {
841 permission_x *permission = calloc(1, sizeof(permission_x));
842 if (permission == NULL) {
843 _LOGD("Malloc Failed\n");
846 application->permission = g_list_append(application->permission, permission);
847 ret = __ps_process_permission(reader, permission);
848 } else if (!strcmp(ASCII(node), "app-control")) {
849 ret = __ps_process_appcontrol(reader, &application->appcontrol);
850 } else if (!strcmp(ASCII(node), "application-service")) {
851 ret = __ps_process_appcontrol(reader, &application->appcontrol);
852 } else if (!strcmp(ASCII(node), "data-share")) {
853 datashare_x *datashare = calloc(1, sizeof(datashare_x));
854 if (datashare == NULL) {
855 _LOGD("Malloc Failed\n");
858 application->datashare = g_list_append(application->datashare, datashare);
859 ret = __ps_process_datashare(reader, datashare);
860 } else if (!strcmp(ASCII(node), "launch-conditions")) {
861 ret = __ps_process_launchconditions(reader, &application->launchconditions);
862 } else if (!strcmp(ASCII(node), "notification")) {
863 notification_x *notification = calloc(1, sizeof(notification_x));
864 if (notification == NULL) {
865 _LOGD("Malloc Failed\n");
868 application->notification = g_list_append(application->notification, notification);
869 ret = __ps_process_notification(reader, notification);
870 } else if (!strcmp(ASCII(node), "datacontrol")) {
871 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
872 if (datacontrol == NULL) {
873 _LOGD("Malloc Failed\n");
876 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
877 ret = __ps_process_datacontrol(reader, datacontrol);
878 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
879 ret = __ps_process_splashscreens(reader, &application->splashscreens);
883 _LOGD("Processing application failed\n");
891 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
893 _LOGD("__start_process\n");
898 depth = xmlTextReaderDepth(reader);
899 while ((ret = __next_child_element(reader, depth))) {
900 node = xmlTextReaderConstName(reader);
902 _LOGD("xmlTextReaderConstName value is NULL\n");
906 if (!strcmp(ASCII(node), "label")) {
907 label_x *label = calloc(1, sizeof(label_x));
909 _LOGD("Malloc Failed\n");
912 mfx->label = g_list_append(mfx->label, label);
913 ret = __ps_process_label(reader, label);
914 } else if (!strcmp(ASCII(node), "author")) {
915 author_x *author = calloc(1, sizeof(author_x));
916 if (author == NULL) {
917 _LOGD("Malloc Failed\n");
920 mfx->author = g_list_append(mfx->author, author);
921 ret = __ps_process_author(reader, author);
922 } else if (!strcmp(ASCII(node), "description")) {
923 description_x *description = calloc(1, sizeof(description_x));
924 if (description == NULL) {
925 _LOGD("Malloc Failed\n");
928 mfx->description = g_list_append(mfx->description, description);
929 ret = __ps_process_description(reader, description);
930 } else if (!strcmp(ASCII(node), "license")) {
931 license_x *license = calloc(1, sizeof(license_x));
932 if (license == NULL) {
933 _LOGD("Malloc Failed\n");
936 mfx->license = g_list_append(mfx->license, license);
937 ret = __ps_process_license(reader, license);
938 } else if (!strcmp(ASCII(node), "privileges")) {
939 ret = __ps_process_privileges(reader, &mfx->privileges);
940 } else if (!strcmp(ASCII(node), "ui-application")) {
941 application_x *application = calloc(1, sizeof(application_x));
942 if (application == NULL) {
943 _LOGD("Malloc Failed\n");
946 mfx->application = g_list_append(mfx->application, application);
947 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
948 } else if (!strcmp(ASCII(node), "service-application")) {
949 application_x *application = calloc(1, sizeof(application_x));
950 if (application == NULL) {
951 _LOGD("Malloc Failed\n");
954 mfx->application = g_list_append(mfx->application, application);
955 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
956 } else if (!strcmp(ASCII(node), "widget-application")) {
957 application_x *application = calloc(1, sizeof(application_x));
958 if (application == NULL) {
959 _LOGD("Malloc Failed\n");
962 mfx->application = g_list_append(mfx->application, application);
963 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
964 } else if (!strcmp(ASCII(node), "watch-application")) {
965 application_x *application = calloc(1, sizeof(application_x));
966 if (application == NULL) {
967 _LOGD("Malloc Failed\n");
970 mfx->application = g_list_append(mfx->application, application);
971 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
972 } else if (!strcmp(ASCII(node), "icon")) {
973 icon_x *icon = calloc(1, sizeof(icon_x));
975 _LOGD("Malloc Failed\n");
978 mfx->icon = g_list_append(mfx->icon, icon);
979 ret = __ps_process_icon(reader, icon, uid);
980 } else if (!strcmp(ASCII(node), "compatibility")) {
981 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
982 if (compatibility == NULL) {
983 _LOGD("Malloc Failed\n");
986 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
987 ret = __ps_process_compatibility(reader, compatibility);
988 } else if (!strcmp(ASCII(node), "shortcut-list")) {
990 } else if (!strcmp(ASCII(node), "livebox")) {
992 } else if (!strcmp(ASCII(node), "account")) {
994 } else if (!strcmp(ASCII(node), "notifications")) {
996 } else if (!strcmp(ASCII(node), "ime")) {
998 } else if (!strcmp(ASCII(node), "feature")) {
1001 _LOGI("Unknown element: %s", ASCII(node));
1006 _LOGD("Processing manifest failed\n");
1013 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1015 const xmlChar *node;
1018 if ((ret = __next_child_element(reader, -1))) {
1019 node = xmlTextReaderConstName(reader);
1021 _LOGD("xmlTextReaderConstName value is NULL\n");
1025 if (!strcmp(ASCII(node), "manifest")) {
1026 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1027 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1028 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1029 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1030 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1031 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1032 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1033 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1034 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1035 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1036 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1037 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1038 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1039 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1040 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1042 __save_xml_installed_time(mfx);
1043 __save_xml_root_path(mfx, uid);
1044 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1045 __save_xml_default_value(mfx);
1047 ret = __start_process(reader, mfx, uid);
1049 _LOGD("No Manifest element found\n");
1056 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1058 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1059 xmlTextReaderPtr reader;
1060 manifest_x *mfx = NULL;
1062 reader = xmlReaderForFile(manifest, NULL, 0);
1064 mfx = malloc(sizeof(manifest_x));
1066 memset(mfx, '\0', sizeof(manifest_x));
1067 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1068 _LOGD("Parsing Failed\n");
1069 pkgmgr_parser_free_manifest_xml(mfx);
1072 _LOGD("Parsing Success\n");
1074 _LOGD("Memory allocation error\n");
1076 xmlFreeTextReader(reader);
1078 _LOGD("Unable to create xml reader\n");
1083 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1085 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1086 xmlTextReaderPtr reader;
1087 manifest_x *mfx = NULL;
1089 reader = xmlReaderForFile(manifest, NULL, 0);
1091 mfx = malloc(sizeof(manifest_x));
1093 memset(mfx, '\0', sizeof(manifest_x));
1094 if (__process_manifest(reader, mfx, uid) < 0) {
1095 _LOGD("Parsing Failed\n");
1096 pkgmgr_parser_free_manifest_xml(mfx);
1099 _LOGD("Parsing Success\n");
1101 _LOGD("Memory allocation error\n");
1103 xmlFreeTextReader(reader);
1105 _LOGD("Unable to create xml reader\n");
1110 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1113 char delims[] = "=";
1114 char *ret_result = NULL;
1121 for (tag = strdup(tagv[0]); tag != NULL; ) {
1122 ret_result = strtok_r(tag, delims, &ptr);
1123 if (ret_result != NULL) {
1124 /*check tag : preload */
1125 if (strcmp(ret_result, "preload") == 0) {
1126 ret_result = strtok_r(NULL, delims, &ptr);
1127 if (ret_result && strcmp(ret_result, "true") == 0) {
1128 free((void *)mfx->preload);
1129 mfx->preload = strdup("true");
1130 } else if (ret_result && strcmp(ret_result, "false") == 0) {
1131 free((void *)mfx->preload);
1132 mfx->preload = strdup("false");
1134 /*check tag : removable*/
1135 } else if (strcmp(ret_result, "removable") == 0) {
1136 ret_result = strtok_r(NULL, delims, &ptr);
1137 if (ret_result && strcmp(ret_result, "true") == 0) {
1138 free((void *)mfx->removable);
1139 mfx->removable = strdup("true");
1140 } else if (ret_result && strcmp(ret_result, "false") == 0) {
1141 free((void *)mfx->removable);
1142 mfx->removable = strdup("false");
1144 /*check tag : not matched*/
1146 _LOGD("tag process [%s]is not defined\n", ret_result);
1150 /*check next value*/
1151 if (tagv[++i] != NULL)
1152 tag = strdup(tagv[i]);
1154 _LOGD("tag process success...\n");
1160 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
1161 ACTION_TYPE action, const char *pkgid)
1163 int (*plugin_install) (xmlDocPtr, const char *);
1168 case ACTION_INSTALL:
1169 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
1171 case ACTION_UPGRADE:
1172 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
1174 case ACTION_UNINSTALL:
1175 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
1181 if ((plugin_install =
1182 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1183 _LOGE("can not find symbol[%s] \n", ac);
1187 ret = plugin_install(docPtr, pkgid);
1188 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
1194 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
1197 const xmlChar *name;
1199 if (xmlTextReaderDepth(reader) != 1) {
1200 _LOGE("Node depth is not 1");
1204 if (xmlTextReaderNodeType(reader) != 1) {
1205 _LOGE("Node type is not 1");
1209 const xmlChar *value;
1210 name = xmlTextReaderConstName(reader);
1212 _LOGE("TEST TEST TES\n");
1213 name = BAD_CAST "--";
1216 value = xmlTextReaderConstValue(reader);
1217 if (value != NULL) {
1218 if (xmlStrlen(value) > 40)
1219 _LOGD(" %.40s...", value);
1221 _LOGD(" %s", value);
1224 name = xmlTextReaderConstName(reader);
1226 _LOGE("TEST TEST TES\n");
1227 name = BAD_CAST "--";
1230 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
1231 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
1232 if (copyDocPtr == NULL)
1234 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
1235 if (rootElement == NULL)
1237 xmlNode *cur_node = xmlFirstElementChild(rootElement);
1238 if (cur_node == NULL)
1240 xmlNode *temp = xmlTextReaderExpand(reader);
1243 xmlNode *next_node = NULL;
1244 while (cur_node != NULL) {
1245 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1246 (temp->line == cur_node->line)) {
1249 next_node = xmlNextElementSibling(cur_node);
1250 xmlUnlinkNode(cur_node);
1251 xmlFreeNode(cur_node);
1252 cur_node = next_node;
1255 if (cur_node == NULL)
1257 next_node = xmlNextElementSibling(cur_node);
1259 cur_node->next = NULL;
1260 next_node->prev = NULL;
1261 xmlFreeNodeList(next_node);
1262 xmlSetTreeDoc(cur_node, copyDocPtr);
1264 xmlSetTreeDoc(cur_node, copyDocPtr);
1267 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
1273 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1275 switch (xmlTextReaderNodeType(reader)) {
1276 case XML_READER_TYPE_END_ELEMENT:
1280 case XML_READER_TYPE_ELEMENT:
1282 /* Elements without closing tag don't receive */
1283 const xmlChar *elementName =
1284 xmlTextReaderLocalName(reader);
1285 if (elementName == NULL)
1288 if (strcmp(tag, ASCII(elementName)) == 0) {
1289 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1290 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1301 static void __str_trim(char *input)
1303 char *trim_str = input;
1308 while (*input != 0) {
1309 if (!isspace(*input)) {
1320 static char *__get_parser_plugin(const char *type)
1323 char buffer[1024] = { 0 };
1324 char temp_path[1024] = { 0 };
1328 _LOGE("invalid argument\n");
1332 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1334 _LOGE("no matching backendlib\n");
1338 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1339 if (buffer[0] == '#')
1344 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
1345 path = path + strlen(PKG_PARSERLIB);
1349 memset(buffer, 0x00, 1024);
1356 _LOGE("no matching backendlib\n");
1360 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1362 return strdup(temp_path);
1365 static void *__open_lib_handle(char *tag)
1367 char *lib_path = NULL;
1368 void *lib_handle = NULL;
1370 lib_path = __get_parser_plugin(tag);
1371 retvm_if(!lib_path, NULL, "lib_path get fail");
1373 lib_handle = dlopen(lib_path, RTLD_LAZY);
1374 if (lib_handle == NULL)
1375 _LOGE("dlopen is failed lib_path[%s]", lib_path);
1382 static void __close_lib_handle(void *lib_handle)
1384 dlclose(lib_handle);
1387 static char * __get_tag_by_key(char *md_key)
1389 char *md_tag = NULL;
1391 if (md_key == NULL) {
1392 _LOGD("md_key is NULL\n");
1396 md_tag = strrchr(md_key, 47) + 1;
1399 return strdup(md_tag);
1402 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1404 int (*plugin_install) (const char *);
1408 if (process == PLUGIN_PRE_PROCESS) {
1410 case ACTION_INSTALL:
1411 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1413 case ACTION_UPGRADE:
1414 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1416 case ACTION_UNINSTALL:
1417 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1422 } else if (process == PLUGIN_POST_PROCESS) {
1424 case ACTION_INSTALL:
1425 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1427 case ACTION_UPGRADE:
1428 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1430 case ACTION_UNINSTALL:
1431 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1439 if ((plugin_install =
1440 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1444 ret = plugin_install(pkgid);
1448 static int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1450 xmlTextReaderPtr reader;
1454 void *lib_handle = NULL;
1455 char tag[PKG_STRING_LEN_MAX] = { 0 };
1457 fp = fopen(TAG_PARSER_LIST, "r");
1458 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1460 while (fgets(tag, sizeof(tag), fp) != NULL) {
1463 lib_handle = __open_lib_handle(tag);
1464 if (lib_handle == NULL)
1467 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1468 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1470 docPtr = xmlReadFile(filename, NULL, 0);
1471 reader = xmlReaderWalker(docPtr);
1472 if (reader != NULL) {
1473 ret = xmlTextReaderRead(reader);
1475 __process_tag(lib_handle, reader, action, tag, mfx->package);
1476 ret = xmlTextReaderRead(reader);
1478 xmlFreeTextReader(reader);
1481 _LOGD("%s : failed to parse", filename);
1483 _LOGD("Unable to open %s", filename);
1486 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1487 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1489 __close_lib_handle(lib_handle);
1491 memset(tag, 0x00, sizeof(tag));
1500 static void __metadata_parser_clear_dir_list(GList* dir_list)
1503 __metadata_t* detail = NULL;
1506 list = g_list_first(dir_list);
1508 detail = (__metadata_t *)list->data;
1511 free((void *)detail->key);
1513 free((void *)detail->value);
1516 list = g_list_next(list);
1518 g_list_free(dir_list);
1522 static char *__get_metadata_parser_plugin(const char *type)
1525 char buffer[1024] = { 0 };
1526 char temp_path[1024] = { 0 };
1530 _LOGE("invalid argument\n");
1534 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1536 _LOGE("no matching metadata parser\n");
1540 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1541 if (buffer[0] == '#')
1546 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
1547 path = path + strlen(METADATA_PARSER_NAME);
1552 memset(buffer, 0x00, 1024);
1559 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME, type);
1563 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1565 return strdup(temp_path);
1568 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
1569 ACTION_TYPE action, const char *pkgid, const char *appid)
1571 char *lib_path = NULL;
1572 void *lib_handle = NULL;
1573 int (*metadata_parser_plugin) (const char *, const char *, GList *);
1578 case ACTION_INSTALL:
1579 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
1581 case ACTION_UPGRADE:
1582 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
1584 case ACTION_UNINSTALL:
1585 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
1591 lib_path = __get_metadata_parser_plugin(tag);
1593 _LOGE("get %s parser fail\n", tag);
1597 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1598 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1602 if ((metadata_parser_plugin =
1603 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1604 _LOGE("can not find symbol[%s] \n", ac);
1608 ret = metadata_parser_plugin(pkgid, appid, md_list);
1610 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1612 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1618 dlclose(lib_handle);
1622 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
1626 char buffer[1024] = { 0, };
1629 GList *md_tmp = NULL;
1631 char *md_tag = NULL;
1633 GList *md_list = NULL;
1634 __metadata_t *md_detail = NULL;
1636 md_tag = __get_tag_by_key(md_key);
1637 if (md_tag == NULL) {
1638 _LOGD("md_tag is NULL\n");
1642 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1643 app = (application_x *)app_tmp->data;
1646 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1647 md = (metadata_x *)md_tmp->data;
1650 /* get glist of metadata key and value combination */
1651 memset(buffer, 0x00, 1024);
1652 snprintf(buffer, 1024, "%s/", md_key);
1653 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
1654 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
1655 if (md_detail == NULL) {
1656 _LOGD("Memory allocation failed\n");
1660 md_detail->key = strdup(md->key);
1661 if (md_detail->key == NULL) {
1662 _LOGD("Memory allocation failed\n");
1667 md_detail->value = strdup(md->value);
1668 if (md_detail->value == NULL) {
1669 _LOGD("Memory allocation failed\n");
1670 free((void *)md_detail->key);
1675 md_list = g_list_append(md_list, (gpointer)md_detail);
1680 /* send glist to parser when tags for metadata plugin parser exist. */
1682 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
1684 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
1686 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
1688 __metadata_parser_clear_dir_list(md_list);
1697 __metadata_parser_clear_dir_list(md_list);
1704 static int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1706 fprintf(stdout, "__ps_process_metadata_parser\n");
1709 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1711 fp = fopen(METADATA_PARSER_LIST, "r");
1713 _LOGD("no preload list\n");
1717 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1719 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1730 static void __category_parser_clear_dir_list(GList* dir_list)
1733 __category_t* detail = NULL;
1736 list = g_list_first(dir_list);
1738 detail = (__category_t *)list->data;
1741 free((void *)detail->name);
1745 list = g_list_next(list);
1747 g_list_free(dir_list);
1751 static char *__get_category_parser_plugin(const char *type)
1754 char buffer[1024] = { 0 };
1755 char temp_path[1024] = { 0 };
1759 _LOGE("invalid argument\n");
1763 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1765 _LOGE("no matching metadata parser\n");
1769 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1770 if (buffer[0] == '#')
1775 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
1776 path = path + strlen(CATEGORY_PARSER_NAME);
1781 memset(buffer, 0x00, 1024);
1788 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME, type);
1792 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1794 return strdup(temp_path);
1797 static int __ps_run_category_parser(GList *category_list, const char *tag,
1798 ACTION_TYPE action, const char *pkgid, const char *appid)
1800 char *lib_path = NULL;
1801 void *lib_handle = NULL;
1802 int (*category_parser_plugin) (const char *, const char *, GList *);
1807 case ACTION_INSTALL:
1808 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
1810 case ACTION_UPGRADE:
1811 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
1813 case ACTION_UNINSTALL:
1814 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
1820 lib_path = __get_category_parser_plugin(tag);
1822 _LOGE("get %s parser fail\n", tag);
1826 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1827 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1831 if ((category_parser_plugin =
1832 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1833 _LOGE("can not find symbol[%s] \n", ac);
1837 ret = category_parser_plugin(pkgid, appid, category_list);
1839 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1841 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1847 dlclose(lib_handle);
1851 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
1855 char buffer[1024] = { 0, };
1858 GList *category_tmp;
1859 const char *category;
1860 char *category_tag = NULL;
1862 GList *category_list = NULL;
1863 __category_t *category_detail = NULL;
1865 category_tag = __get_tag_by_key(category_key);
1866 if (category_tag == NULL) {
1867 _LOGD("md_tag is NULL\n");
1871 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1872 app = (application_x *)app_tmp->data;
1875 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
1876 category = (const char *)category_tmp->data;
1877 /* get glist of category key and value combination */
1878 memset(buffer, 0x00, 1024);
1879 snprintf(buffer, 1024, "%s/", category_key);
1880 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
1881 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
1882 if (category_detail == NULL) {
1883 _LOGD("Memory allocation failed\n");
1887 category_detail->name = strdup(category);
1888 if (category_detail->name == NULL) {
1889 _LOGD("Memory allocation failed\n");
1890 free(category_detail);
1894 category_list = g_list_append(category_list, (gpointer)category_detail);
1899 /* send glist to parser when tags for metadata plugin parser exist. */
1901 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
1903 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
1905 _LOGD("category_parser success for tag[%s]\n", category_tag);
1907 __category_parser_clear_dir_list(category_list);
1908 category_list = NULL;
1916 __category_parser_clear_dir_list(category_list);
1923 static int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1927 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1929 fp = fopen(CATEGORY_PARSER_LIST, "r");
1931 _LOGD("no category parser list\n");
1935 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1936 __str_trim(category_key);
1937 ret = __run_category_parser_prestep(mfx, category_key, action);
1948 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
1950 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1951 _LOGD("parsing manifest for installation: %s\n", manifest);
1953 manifest_x *mfx = NULL;
1957 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1958 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1960 _LOGD("Parsing Finished\n");
1962 __ps_process_tag(mfx, tagv);
1964 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
1965 if (ret == PMINFO_R_ERROR) {
1966 _LOGE("DB Insert failed");
1967 pkgmgr_parser_free_manifest_xml(mfx);
1968 return PMINFO_R_ERROR;
1971 _LOGD("DB Insert Success\n");
1973 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1974 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1976 _LOGD("Creating metadata parser failed\n");
1978 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1980 _LOGD("Creating category parser failed\n");
1982 pkgmgr_parser_free_manifest_xml(mfx);
1983 _LOGD("Free Done\n");
1989 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
1991 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1992 _LOGD("parsing manifest for installation: %s\n", manifest);
1993 manifest_x *mfx = NULL;
1997 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1998 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2000 _LOGD("Parsing Finished\n");
2002 __ps_process_tag(mfx, tagv);
2004 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2005 if (ret == PMINFO_R_ERROR) {
2006 _LOGE("DB Insert failed");
2007 pkgmgr_parser_free_manifest_xml(mfx);
2008 return PMINFO_R_ERROR;
2011 _LOGD("DB Insert Success\n");
2013 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2014 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2016 _LOGD("Creating metadata parser failed\n");
2017 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2019 _LOGD("Creating category parser failed\n");
2021 pkgmgr_parser_free_manifest_xml(mfx);
2022 _LOGD("Free Done\n");
2028 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2030 if (!strstr(manifest, getUserManifestPath(uid,
2031 strcmp(mfx->preload, "true") == 0))) {
2032 /* if downloaded app is updated, then update tag set true*/
2034 free((void *)mfx->update);
2035 mfx->update = strdup("true");
2041 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2043 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2044 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2045 manifest_x *mfx = NULL;
2047 bool preload = false;
2048 bool system = false;
2049 char *csc_path = NULL;
2050 pkgmgrinfo_pkginfo_h handle = NULL;
2053 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2054 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2056 _LOGD("Parsing Finished\n");
2057 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2059 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2060 if (ret != PMINFO_R_OK)
2061 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2062 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2063 if (ret != PMINFO_R_OK)
2064 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2067 free((void *)mfx->preload);
2068 mfx->preload = strdup("true");
2071 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2072 if (ret != PMINFO_R_OK)
2073 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2075 free((void *)mfx->system);
2076 mfx->system = strdup("true");
2079 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2080 if (ret != PMINFO_R_OK)
2081 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2083 if (csc_path != NULL) {
2085 free((void *)mfx->csc_path);
2086 mfx->csc_path = strdup(csc_path);
2089 /*Delete from cert table*/
2090 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2091 if (ret != PMINFO_R_OK) {
2092 _LOGD("Cert Info DB Delete Failed\n");
2093 pkgmgr_parser_free_manifest_xml(mfx);
2094 return PMINFO_R_ERROR;
2097 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2098 if (ret != PMINFO_R_OK) {
2099 _LOGD("DB Insert failed\n");
2100 pkgmgr_parser_free_manifest_xml(mfx);
2101 return PMINFO_R_ERROR;
2104 _LOGD("DB Update Success\n");
2106 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2107 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2109 _LOGD("Upgrade metadata parser failed\n");
2110 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2112 _LOGD("Creating category parser failed\n");
2113 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2114 pkgmgr_parser_free_manifest_xml(mfx);
2115 _LOGD("Free Done\n");
2121 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2123 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2124 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2125 manifest_x *mfx = NULL;
2127 bool preload = false;
2128 bool system = false;
2129 char *csc_path = NULL;
2130 pkgmgrinfo_pkginfo_h handle = NULL;
2133 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2134 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2136 _LOGD("Parsing Finished\n");
2137 __check_preload_updated(mfx, manifest, uid);
2139 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2140 if (ret != PMINFO_R_OK)
2141 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2142 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2143 if (ret != PMINFO_R_OK)
2144 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2147 free((void *)mfx->preload);
2148 mfx->preload = strdup("true");
2151 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2152 if (ret != PMINFO_R_OK)
2153 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2156 free((void *)mfx->system);
2157 mfx->system = strdup("true");
2160 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2161 if (ret != PMINFO_R_OK)
2162 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2163 if (csc_path != NULL) {
2165 free((void *)mfx->csc_path);
2166 mfx->csc_path = strdup(csc_path);
2169 /*Delete from cert table*/
2170 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2171 if (ret != PMINFO_R_OK) {
2172 _LOGD("Cert Info DB Delete Failed\n");
2173 pkgmgr_parser_free_manifest_xml(mfx);
2174 return PMINFO_R_ERROR;
2177 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2178 if (ret != PMINFO_R_OK) {
2179 _LOGD("DB Insert failed\n");
2180 pkgmgr_parser_free_manifest_xml(mfx);
2181 return PMINFO_R_ERROR;
2184 _LOGD("DB Update Success\n");
2186 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2187 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2189 _LOGD("Upgrade metadata parser failed\n");
2190 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2192 _LOGD("Creating category parser failed\n");
2193 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2194 pkgmgr_parser_free_manifest_xml(mfx);
2195 _LOGD("Free Done\n");
2201 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2203 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2204 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2206 manifest_x *mfx = NULL;
2209 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2210 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2212 _LOGD("Parsing Finished\n");
2214 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2216 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2218 _LOGD("Removing metadata parser failed\n");
2220 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2222 _LOGD("Creating category parser failed\n");
2224 /*Delete from cert table*/
2225 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2227 _LOGD("Cert Info DB Delete Failed\n");
2228 pkgmgr_parser_free_manifest_xml(mfx);
2232 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2234 _LOGD("DB Delete failed\n");
2236 _LOGD("DB Delete Success\n");
2238 pkgmgr_parser_free_manifest_xml(mfx);
2239 _LOGD("Free Done\n");
2245 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2247 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2249 void *lib_handle = NULL;
2250 int (*appsvc_operation) (const char *, uid_t);
2253 application_x *application;
2255 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2256 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2260 if ((appsvc_operation =
2261 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2262 _LOGE("can not find symbol \n");
2266 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2267 application = (application_x *)tmp->data;
2268 if (application == NULL)
2270 ret = appsvc_operation(application->appid, uid);
2272 _LOGE("can not operation symbol \n");
2277 dlclose(lib_handle);
2282 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2284 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2285 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2287 manifest_x *mfx = NULL;
2290 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2291 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2293 _LOGD("Parsing Finished\n");
2295 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2297 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2299 _LOGD("Removing metadata parser failed\n");
2301 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2303 _LOGD("Creating category parser failed\n");
2305 /*Delete from cert table*/
2306 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2308 _LOGD("Cert Info DB Delete Failed\n");
2309 pkgmgr_parser_free_manifest_xml(mfx);
2313 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2315 _LOGD("DB Delete failed\n");
2317 _LOGD("DB Delete Success\n");
2319 ret = __ps_remove_appsvc_db(mfx, uid);
2321 _LOGD("Removing appsvc_db failed\n");
2323 _LOGD("Removing appsvc_db Success\n");
2325 pkgmgr_parser_free_manifest_xml(mfx);
2326 _LOGD("Free Done\n");