ff5eea6f4b352edde1ce44fa6879e479c7536d84
[framework/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.c
1 /*
2  * pkgmgr-info
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22 #define _GNU_SOURCE
23 #include <dlfcn.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28 #include <ctype.h>
29 #include <time.h>
30 #include <string.h>
31 #include <libxml/parser.h>
32 #include <libxml/xmlreader.h>
33 #include <libxml/xmlschemas.h>
34 #include <vconf.h>
35 #include <glib.h>
36 #include <db-util.h>
37
38 #include "pkgmgr_parser.h"
39 #include "pkgmgr_parser_internal.h"
40 #include "pkgmgr_parser_db.h"
41 #include "pkgmgr-info.h"
42 #include "pkgmgr_parser_signature.h"
43 #include "pkgmgr-info-debug.h"
44 #include "pkgmgr_parser_plugin.h"
45
46 #ifdef LOG_TAG
47 #undef LOG_TAG
48 #endif
49 #define LOG_TAG "PKGMGR_PARSER"
50
51 #define MANIFEST_RW_DIRECTORY "/opt/share/packages"
52 #define MANIFEST_RO_DIRECTORY "/usr/share/packages"
53 #define ASCII(s) (const char *)s
54 #define XMLCHAR(s) (const xmlChar *)s
55 #define BUFMAX 1024*128
56
57 const char *package;
58
59 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
60 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege);
61 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges);
62 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile);
63 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed);
64 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation);
65 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri);
66 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime);
67 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp);
68 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition);
69 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
70 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category);
71 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
72 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
73 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
74 static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution);
75 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
76 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
77 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
78 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
79 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
80 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon);
81 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
82 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
83 static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability);
84 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
85 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
86 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
87 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication);
88 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication);
89 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
90 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
91 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
92 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime);
93 static void __ps_free_label(label_x *label);
94 static void __ps_free_privilege(privilege_x *privilege);
95 static void __ps_free_privileges(privileges_x *privileges);
96 static void __ps_free_deviceprofile(deviceprofile_x * deviceprofile);
97 static void __ps_free_allowed(allowed_x *allowed);
98 static void __ps_free_operation(operation_x *operation);
99 static void __ps_free_uri(uri_x *uri);
100 static void __ps_free_mime(mime_x *mime);
101 static void __ps_free_subapp(subapp_x *subapp);
102 static void __ps_free_condition(condition_x *condition);
103 static void __ps_free_notification(notification_x *notifiation);
104 static void __ps_free_category(category_x *category);
105 static void __ps_free_metadata(metadata_x *metadata);
106 static void __ps_free_permission(permission_x *permission);
107 static void __ps_free_compatibility(compatibility_x *compatibility);
108 static void __ps_free_resolution(resolution_x *resolution);
109 static void __ps_free_request(request_x *request);
110 static void __ps_free_define(define_x *define);
111 static void __ps_free_appsvc(appsvc_x *appsvc);
112 static void __ps_free_launchconditions(launchconditions_x *launchconditions);
113 static void __ps_free_datashare(datashare_x *datashare);
114 static void __ps_free_icon(icon_x *icon);
115 static void __ps_free_author(author_x *author);
116 static void __ps_free_description(description_x *description);
117 static void __ps_free_capability(capability_x *capability);
118 static void __ps_free_license(license_x *license);
119 static void __ps_free_appcontrol(appcontrol_x *appcontrol);
120 static void __ps_free_datacontrol(datacontrol_x *datacontrol);
121 static void __ps_free_uiapplication(uiapplication_x *uiapplication);
122 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication);
123 static void __ps_free_font(font_x *font);
124 static void __ps_free_theme(theme_x *theme);
125 static void __ps_free_daemon(daemon_x *daemon);
126 static void __ps_free_ime(ime_x *ime);
127 static char *__pkgid_to_manifest(const char *pkgid);
128 static int __next_child_element(xmlTextReaderPtr reader, int depth);
129 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx);
130 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx);
131 static void __str_trim(char *input);
132 static int __validate_appid(const char *pkgid, const char *appid, char **newappid);
133
134 static void __str_trim(char *input)
135 {
136         char *trim_str = input;
137
138         if (input == NULL)
139                 return;
140
141         while (*input != 0) {
142                 if (!isspace(*input)) {
143                         *trim_str = *input;
144                         trim_str++;
145                 }
146                 input++;
147         }
148
149         *trim_str = 0;
150         return;
151 }
152
153 static int __validate_appid(const char *pkgid, const char *appid, char **newappid)
154 {
155         if (!pkgid || !appid || !newappid) {
156                 _LOGD("Arg supplied is NULL\n");
157                 return -1;
158         }
159         int pkglen = strlen(pkgid);
160         int applen = strlen(appid);
161         char *ptr = NULL;
162         char *newapp = NULL;
163         int len = 0;
164         if (strncmp(appid, ".", 1) == 0) {
165                 len = pkglen + applen + 1;
166                 newapp = calloc(1,len);
167                 if (newapp == NULL) {
168                         _LOGD("Malloc failed\n");
169                         return -1;
170                 }
171                 strncpy(newapp, pkgid, pkglen);
172                 strncat(newapp, appid, applen);
173                 _LOGD("new appid is %s\n", newapp);
174                 *newappid = newapp;
175                 return 0;
176         }
177         if (applen < pkglen) {
178                 _LOGD("app id is not proper\n");
179                 *newappid = NULL;
180 #ifdef _VALIDATE_APPID_
181                 return -1;
182 #else
183                 return 0;
184 #endif
185         }
186         if (!strcmp(appid, pkgid)) {
187                 _LOGD("appid is proper\n");
188                 *newappid = NULL;
189                 return 0;
190         }
191         else if (strncmp(appid, pkgid, pkglen) == 0) {
192                 ptr = strstr(appid, pkgid);
193                 ptr = ptr + pkglen;
194                 if (strncmp(ptr, ".", 1) == 0) {
195                         _LOGD("appid is proper\n");
196                         *newappid = NULL;
197                         return 0;
198                 }
199                 else {
200                         _LOGD("appid is not proper\n");
201                         *newappid = NULL;
202 #ifdef _VALIDATE_APPID_
203                         return -1;
204 #else
205                         return 0;
206 #endif
207                 }
208         } else {
209                 _LOGD("appid is not proper\n");
210                 *newappid = NULL;
211 #ifdef _VALIDATE_APPID_
212                 return -1;
213 #else
214                 return 0;
215 #endif
216         }
217         return 0;
218 }
219
220 static char *__pkgid_to_manifest(const char *pkgid)
221 {
222         char *manifest;
223         int size;
224
225         if (pkgid == NULL) {
226                 _LOGE("pkgid is NULL");
227                 return NULL;
228         }
229
230         size = strlen(MANIFEST_RW_DIRECTORY) + strlen(pkgid) + 10;
231         manifest = malloc(size);
232         if (manifest == NULL) {
233                 _LOGE("No memory");
234                 return NULL;
235         }
236         memset(manifest, '\0', size);
237         snprintf(manifest, size, MANIFEST_RW_DIRECTORY "/%s.xml", pkgid);
238
239         if (access(manifest, F_OK)) {
240                 snprintf(manifest, size, MANIFEST_RO_DIRECTORY "/%s.xml", pkgid);
241         }
242
243         return manifest;
244 }
245
246 static int __next_child_element(xmlTextReaderPtr reader, int depth)
247 {
248         int ret = xmlTextReaderRead(reader);
249         int cur = xmlTextReaderDepth(reader);
250         while (ret == 1) {
251
252                 switch (xmlTextReaderNodeType(reader)) {
253                 case XML_READER_TYPE_ELEMENT:
254                         if (cur == depth + 1)
255                                 return 1;
256                         break;
257                 case XML_READER_TYPE_TEXT:
258                         /*text is handled by each function separately*/
259                         if (cur == depth + 1)
260                                 return 0;
261                         break;
262                 case XML_READER_TYPE_END_ELEMENT:
263                         if (cur == depth)
264                                 return 0;
265                         break;
266                 default:
267                         if (cur <= depth)
268                                 return 0;
269                         break;
270                 }
271                 ret = xmlTextReaderRead(reader);
272                 cur = xmlTextReaderDepth(reader);
273         }
274         return ret;
275 }
276
277 static bool __check_action_fota(char *const tagv[])
278 {
279         int i = 0;
280         char delims[] = "=";
281         char *ret_result = NULL;
282         char *tag = NULL;
283         int ret = false;
284
285         if (tagv == NULL)
286                 return ret;
287
288         for (tag = strdup(tagv[0]); tag != NULL; ) {
289                 ret_result = strtok(tag, delims);
290
291                 /*check tag :  fota is true */
292                 if (strcmp(ret_result, "fota") == 0) {
293                         ret_result = strtok(NULL, delims);
294                         if (strcmp(ret_result, "true") == 0) {
295                                 ret = true;
296                         }
297                 } else
298                         _LOGD("tag process [%s]is not defined\n", ret_result);
299
300                 free(tag);
301
302                 /*check next value*/
303                 if (tagv[++i] != NULL)
304                         tag = strdup(tagv[i]);
305                 else {
306                         _LOGD("tag process success...%d\n" , ret);
307                         return ret;
308                 }
309         }
310
311         return ret;
312 }
313
314 static void __ps_free_category(category_x *category)
315 {
316         if (category == NULL)
317                 return;
318         if (category->name) {
319                 free((void *)category->name);
320                 category->name = NULL;
321         }
322         free((void*)category);
323         category = NULL;
324 }
325
326 static void __ps_free_privilege(privilege_x *privilege)
327 {
328         if (privilege == NULL)
329                 return;
330         if (privilege->text) {
331                 free((void *)privilege->text);
332                 privilege->text = NULL;
333         }
334         free((void*)privilege);
335         privilege = NULL;
336 }
337
338 static void __ps_free_privileges(privileges_x *privileges)
339 {
340         if (privileges == NULL)
341                 return;
342         /*Free Privilege*/
343         if (privileges->privilege) {
344                 privilege_x *privilege = privileges->privilege;
345                 privilege_x *tmp = NULL;
346                 while(privilege != NULL) {
347                         tmp = privilege->next;
348                         __ps_free_privilege(privilege);
349                         privilege = tmp;
350                 }
351         }
352         free((void*)privileges);
353         privileges = NULL;
354 }
355
356 static void __ps_free_metadata(metadata_x *metadata)
357 {
358         if (metadata == NULL)
359                 return;
360         if (metadata->key) {
361                 free((void *)metadata->key);
362                 metadata->key = NULL;
363         }
364         if (metadata->value) {
365                 free((void *)metadata->value);
366                 metadata->value = NULL;
367         }
368         free((void*)metadata);
369         metadata = NULL;
370 }
371
372 static void __ps_free_permission(permission_x *permission)
373 {
374         if (permission == NULL)
375                 return;
376         if (permission->type) {
377                 free((void *)permission->type);
378                 permission->type = NULL;
379         }
380         if (permission->value) {
381                 free((void *)permission->value);
382                 permission->value = NULL;
383         }
384         free((void*)permission);
385         permission = NULL;
386 }
387
388 static void __ps_free_icon(icon_x *icon)
389 {
390         if (icon == NULL)
391                 return;
392         if (icon->text) {
393                 free((void *)icon->text);
394                 icon->text = NULL;
395         }
396         if (icon->lang) {
397                 free((void *)icon->lang);
398                 icon->lang = NULL;
399         }
400         if (icon->name) {
401                 free((void *)icon->name);
402                 icon->name= NULL;
403         }
404         if (icon->section) {
405                 free((void *)icon->section);
406                 icon->section = NULL;
407         }
408         if (icon->size) {
409                 free((void *)icon->size);
410                 icon->size = NULL;
411         }
412         if (icon->resolution) {
413                 free((void *)icon->resolution);
414                 icon->resolution = NULL;
415         }
416         free((void*)icon);
417         icon = NULL;
418 }
419
420 static void __ps_free_image(image_x *image)
421 {
422         if (image == NULL)
423                 return;
424         if (image->text) {
425                 free((void *)image->text);
426                 image->text = NULL;
427         }
428         if (image->lang) {
429                 free((void *)image->lang);
430                 image->lang = NULL;
431         }
432         if (image->name) {
433                 free((void *)image->name);
434                 image->name= NULL;
435         }
436         if (image->section) {
437                 free((void *)image->section);
438                 image->section = NULL;
439         }
440         free((void*)image);
441         image = NULL;
442 }
443
444 static void __ps_free_operation(operation_x *operation)
445 {
446         if (operation == NULL)
447                 return;
448         if (operation->text) {
449                 free((void *)operation->text);
450                 operation->text = NULL;
451         }
452         free((void*)operation);
453         operation = NULL;
454 }
455
456 static void __ps_free_uri(uri_x *uri)
457 {
458         if (uri == NULL)
459                 return;
460         if (uri->text) {
461                 free((void *)uri->text);
462                 uri->text = NULL;
463         }
464         free((void*)uri);
465         uri = NULL;
466 }
467
468 static void __ps_free_mime(mime_x *mime)
469 {
470         if (mime == NULL)
471                 return;
472         if (mime->text) {
473                 free((void *)mime->text);
474                 mime->text = NULL;
475         }
476         free((void*)mime);
477         mime = NULL;
478 }
479
480 static void __ps_free_subapp(subapp_x *subapp)
481 {
482         if (subapp == NULL)
483                 return;
484         if (subapp->text) {
485                 free((void *)subapp->text);
486                 subapp->text = NULL;
487         }
488         free((void*)subapp);
489         subapp = NULL;
490 }
491
492 static void __ps_free_condition(condition_x *condition)
493 {
494         if (condition == NULL)
495                 return;
496         if (condition->text) {
497                 free((void *)condition->text);
498                 condition->text = NULL;
499         }
500         if (condition->name) {
501                 free((void *)condition->name);
502                 condition->name = NULL;
503         }
504         free((void*)condition);
505         condition = NULL;
506 }
507
508 static void __ps_free_notification(notification_x *notification)
509 {
510         if (notification == NULL)
511                 return;
512         if (notification->text) {
513                 free((void *)notification->text);
514                 notification->text = NULL;
515         }
516         if (notification->name) {
517                 free((void *)notification->name);
518                 notification->name = NULL;
519         }
520         free((void*)notification);
521         notification = NULL;
522 }
523
524 static void __ps_free_compatibility(compatibility_x *compatibility)
525 {
526         if (compatibility == NULL)
527                 return;
528         if (compatibility->text) {
529                 free((void *)compatibility->text);
530                 compatibility->text = NULL;
531         }
532         if (compatibility->name) {
533                 free((void *)compatibility->name);
534                 compatibility->name = NULL;
535         }
536         free((void*)compatibility);
537         compatibility = NULL;
538 }
539
540 static void __ps_free_resolution(resolution_x *resolution)
541 {
542         if (resolution == NULL)
543                 return;
544         if (resolution->mimetype) {
545                 free((void *)resolution->mimetype);
546                 resolution->mimetype = NULL;
547         }
548         if (resolution->urischeme) {
549                 free((void *)resolution->urischeme);
550                 resolution->urischeme = NULL;
551         }
552         free((void*)resolution);
553         resolution = NULL;
554 }
555
556 static void __ps_free_capability(capability_x *capability)
557 {
558         if (capability == NULL)
559                 return;
560         if (capability->operationid) {
561                 free((void *)capability->operationid);
562                 capability->operationid = NULL;
563         }
564         /*Free Resolution*/
565         if (capability->resolution) {
566                 resolution_x *resolution = capability->resolution;
567                 resolution_x *tmp = NULL;
568                 while(resolution != NULL) {
569                         tmp = resolution->next;
570                         __ps_free_resolution(resolution);
571                         resolution = tmp;
572                 }
573         }
574         free((void*)capability);
575         capability = NULL;
576 }
577
578 static void __ps_free_allowed(allowed_x *allowed)
579 {
580         if (allowed == NULL)
581                 return;
582         if (allowed->name) {
583                 free((void *)allowed->name);
584                 allowed->name = NULL;
585         }
586         if (allowed->text) {
587                 free((void *)allowed->text);
588                 allowed->text = NULL;
589         }
590         free((void*)allowed);
591         allowed = NULL;
592 }
593
594 static void __ps_free_request(request_x *request)
595 {
596         if (request == NULL)
597                 return;
598         if (request->text) {
599                 free((void *)request->text);
600                 request->text = NULL;
601         }
602         free((void*)request);
603         request = NULL;
604 }
605
606 static void __ps_free_datacontrol(datacontrol_x *datacontrol)
607 {
608         if (datacontrol == NULL)
609                 return;
610         if (datacontrol->providerid) {
611                 free((void *)datacontrol->providerid);
612                 datacontrol->providerid = NULL;
613         }
614         /*Free Capability*/
615         if (datacontrol->capability) {
616                 capability_x *capability = datacontrol->capability;
617                 capability_x *tmp = NULL;
618                 while(capability != NULL) {
619                         tmp = capability->next;
620                         __ps_free_capability(capability);
621                         capability = tmp;
622                 }
623         }
624         free((void*)datacontrol);
625         datacontrol = NULL;
626 }
627
628 static void __ps_free_launchconditions(launchconditions_x *launchconditions)
629 {
630         if (launchconditions == NULL)
631                 return;
632         if (launchconditions->text) {
633                 free((void *)launchconditions->text);
634                 launchconditions->text = NULL;
635         }
636         /*Free Condition*/
637         if (launchconditions->condition) {
638                 condition_x *condition = launchconditions->condition;
639                 condition_x *tmp = NULL;
640                 while(condition != NULL) {
641                         tmp = condition->next;
642                         __ps_free_condition(condition);
643                         condition = tmp;
644                 }
645         }
646         free((void*)launchconditions);
647         launchconditions = NULL;
648 }
649
650 static void __ps_free_appcontrol(appcontrol_x *appcontrol)
651 {
652         if (appcontrol == NULL)
653                 return;
654         if (appcontrol->text) {
655                 free((void *)appcontrol->text);
656                 appcontrol->text = NULL;
657         }
658         /*Free Operation*/
659         if (appcontrol->operation) {
660                 operation_x *operation = appcontrol->operation;
661                 operation_x *tmp = NULL;
662                 while(operation != NULL) {
663                         tmp = operation->next;
664                         __ps_free_operation(operation);
665                         operation = tmp;
666                 }
667         }
668         /*Free Uri*/
669         if (appcontrol->uri) {
670                 uri_x *uri = appcontrol->uri;
671                 uri_x *tmp = NULL;
672                 while(uri != NULL) {
673                         tmp = uri->next;
674                         __ps_free_uri(uri);
675                         uri = tmp;
676                 }
677         }
678         /*Free Mime*/
679         if (appcontrol->mime) {
680                 mime_x *mime = appcontrol->mime;
681                 mime_x *tmp = NULL;
682                 while(mime != NULL) {
683                         tmp = mime->next;
684                         __ps_free_mime(mime);
685                         mime = tmp;
686                 }
687         }
688         /*Free subapp*/
689         if (appcontrol->subapp) {
690                 subapp_x *subapp = appcontrol->subapp;
691                 subapp_x *tmp = NULL;
692                 while(subapp != NULL) {
693                         tmp = subapp->next;
694                         __ps_free_subapp(subapp);
695                         subapp = tmp;
696                 }
697         }
698         free((void*)appcontrol);
699         appcontrol = NULL;
700 }
701
702 static void __ps_free_appsvc(appsvc_x *appsvc)
703 {
704         if (appsvc == NULL)
705                 return;
706         if (appsvc->text) {
707                 free((void *)appsvc->text);
708                 appsvc->text = NULL;
709         }
710         /*Free Operation*/
711         if (appsvc->operation) {
712                 operation_x *operation = appsvc->operation;
713                 operation_x *tmp = NULL;
714                 while(operation != NULL) {
715                         tmp = operation->next;
716                         __ps_free_operation(operation);
717                         operation = tmp;
718                 }
719         }
720         /*Free Uri*/
721         if (appsvc->uri) {
722                 uri_x *uri = appsvc->uri;
723                 uri_x *tmp = NULL;
724                 while(uri != NULL) {
725                         tmp = uri->next;
726                         __ps_free_uri(uri);
727                         uri = tmp;
728                 }
729         }
730         /*Free Mime*/
731         if (appsvc->mime) {
732                 mime_x *mime = appsvc->mime;
733                 mime_x *tmp = NULL;
734                 while(mime != NULL) {
735                         tmp = mime->next;
736                         __ps_free_mime(mime);
737                         mime = tmp;
738                 }
739         }
740         /*Free subapp*/
741         if (appsvc->subapp) {
742                 subapp_x *subapp = appsvc->subapp;
743                 subapp_x *tmp = NULL;
744                 while(subapp != NULL) {
745                         tmp = subapp->next;
746                         __ps_free_subapp(subapp);
747                         subapp = tmp;
748                 }
749         }
750         free((void*)appsvc);
751         appsvc = NULL;
752 }
753
754 static void __ps_free_deviceprofile(deviceprofile_x *deviceprofile)
755 {
756         return;
757 }
758
759 static void __ps_free_define(define_x *define)
760 {
761         if (define == NULL)
762                 return;
763         if (define->path) {
764                 free((void *)define->path);
765                 define->path = NULL;
766         }
767         /*Free Request*/
768         if (define->request) {
769                 request_x *request = define->request;
770                 request_x *tmp = NULL;
771                 while(request != NULL) {
772                         tmp = request->next;
773                         __ps_free_request(request);
774                         request = tmp;
775                 }
776         }
777         /*Free Allowed*/
778         if (define->allowed) {
779                 allowed_x *allowed = define->allowed;
780                 allowed_x *tmp = NULL;
781                 while(allowed != NULL) {
782                         tmp = allowed->next;
783                         __ps_free_allowed(allowed);
784                         allowed = tmp;
785                 }
786         }
787         free((void*)define);
788         define = NULL;
789 }
790
791 static void __ps_free_datashare(datashare_x *datashare)
792 {
793         if (datashare == NULL)
794                 return;
795         /*Free Define*/
796         if (datashare->define) {
797                 define_x *define =  datashare->define;
798                 define_x *tmp = NULL;
799                 while(define != NULL) {
800                         tmp = define->next;
801                         __ps_free_define(define);
802                         define = tmp;
803                 }
804         }
805         /*Free Request*/
806         if (datashare->request) {
807                 request_x *request = datashare->request;
808                 request_x *tmp = NULL;
809                 while(request != NULL) {
810                         tmp = request->next;
811                         __ps_free_request(request);
812                         request = tmp;
813                 }
814         }
815         free((void*)datashare);
816         datashare = NULL;
817 }
818
819 static void __ps_free_label(label_x *label)
820 {
821         if (label == NULL)
822                 return;
823         if (label->name) {
824                 free((void *)label->name);
825                 label->name = NULL;
826         }
827         if (label->text) {
828                 free((void *)label->text);
829                 label->text = NULL;
830         }
831         if (label->lang) {
832                 free((void *)label->lang);
833                 label->lang= NULL;
834         }
835         free((void*)label);
836         label = NULL;
837 }
838
839 static void __ps_free_author(author_x *author)
840 {
841         if (author == NULL)
842                 return;
843         if (author->email) {
844                 free((void *)author->email);
845                 author->email = NULL;
846         }
847         if (author->text) {
848                 free((void *)author->text);
849                 author->text = NULL;
850         }
851         if (author->href) {
852                 free((void *)author->href);
853                 author->href = NULL;
854         }
855         if (author->lang) {
856                 free((void *)author->lang);
857                 author->lang = NULL;
858         }
859         free((void*)author);
860         author = NULL;
861 }
862
863 static void __ps_free_description(description_x *description)
864 {
865         if (description == NULL)
866                 return;
867         if (description->name) {
868                 free((void *)description->name);
869                 description->name = NULL;
870         }
871         if (description->text) {
872                 free((void *)description->text);
873                 description->text = NULL;
874         }
875         if (description->lang) {
876                 free((void *)description->lang);
877                 description->lang = NULL;
878         }
879         free((void*)description);
880         description = NULL;
881 }
882
883 static void __ps_free_license(license_x *license)
884 {
885         if (license == NULL)
886                 return;
887         if (license->text) {
888                 free((void *)license->text);
889                 license->text = NULL;
890         }
891         if (license->lang) {
892                 free((void *)license->lang);
893                 license->lang = NULL;
894         }
895         free((void*)license);
896         license = NULL;
897 }
898
899 static void __ps_free_uiapplication(uiapplication_x *uiapplication)
900 {
901         if (uiapplication == NULL)
902                 return;
903         if (uiapplication->exec) {
904                 free((void *)uiapplication->exec);
905                 uiapplication->exec = NULL;
906         }
907         if (uiapplication->appid) {
908                 free((void *)uiapplication->appid);
909                 uiapplication->appid = NULL;
910         }
911         if (uiapplication->nodisplay) {
912                 free((void *)uiapplication->nodisplay);
913                 uiapplication->nodisplay = NULL;
914         }
915         if (uiapplication->multiple) {
916                 free((void *)uiapplication->multiple);
917                 uiapplication->multiple = NULL;
918         }
919         if (uiapplication->type) {
920                 free((void *)uiapplication->type);
921                 uiapplication->type = NULL;
922         }
923         if (uiapplication->categories) {
924                 free((void *)uiapplication->categories);
925                 uiapplication->categories = NULL;
926         }
927         if (uiapplication->extraid) {
928                 free((void *)uiapplication->extraid);
929                 uiapplication->extraid = NULL;
930         }
931         if (uiapplication->taskmanage) {
932                 free((void *)uiapplication->taskmanage);
933                 uiapplication->taskmanage = NULL;
934         }
935         if (uiapplication->enabled) {
936                 free((void *)uiapplication->enabled);
937                 uiapplication->enabled = NULL;
938         }
939         if (uiapplication->hwacceleration) {
940                 free((void *)uiapplication->hwacceleration);
941                 uiapplication->hwacceleration = NULL;
942         }
943         if (uiapplication->screenreader) {
944                 free((void *)uiapplication->screenreader);
945                 uiapplication->screenreader = NULL;
946         }
947         if (uiapplication->mainapp) {
948                 free((void *)uiapplication->mainapp);
949                 uiapplication->mainapp = NULL;
950         }
951         if (uiapplication->recentimage) {
952                 free((void *)uiapplication->recentimage);
953                 uiapplication->recentimage = NULL;
954         }
955         if (uiapplication->package) {
956                 free((void *)uiapplication->package);
957                 uiapplication->package = NULL;
958         }
959         if (uiapplication->launchcondition) {
960                 free((void *)uiapplication->launchcondition);
961                 uiapplication->launchcondition = NULL;
962         }
963         /*Free Label*/
964         if (uiapplication->label) {
965                 label_x *label = uiapplication->label;
966                 label_x *tmp = NULL;
967                 while(label != NULL) {
968                         tmp = label->next;
969                         __ps_free_label(label);
970                         label = tmp;
971                 }
972         }
973         /*Free Icon*/
974         if (uiapplication->icon) {
975                 icon_x *icon = uiapplication->icon;
976                 icon_x *tmp = NULL;
977                 while(icon != NULL) {
978                         tmp = icon->next;
979                         __ps_free_icon(icon);
980                         icon = tmp;
981                 }
982         }
983         /*Free image*/
984         if (uiapplication->image) {
985                 image_x *image = uiapplication->image;
986                 image_x *tmp = NULL;
987                 while(image != NULL) {
988                         tmp = image->next;
989                         __ps_free_image(image);
990                         image = tmp;
991                 }
992         }
993         /*Free AppControl*/
994         if (uiapplication->appcontrol) {
995                 appcontrol_x *appcontrol = uiapplication->appcontrol;
996                 appcontrol_x *tmp = NULL;
997                 while(appcontrol != NULL) {
998                         tmp = appcontrol->next;
999                         __ps_free_appcontrol(appcontrol);
1000                         appcontrol = tmp;
1001                 }
1002         }
1003         /*Free LaunchConditions*/
1004         if (uiapplication->launchconditions) {
1005                 launchconditions_x *launchconditions = uiapplication->launchconditions;
1006                 launchconditions_x *tmp = NULL;
1007                 while(launchconditions != NULL) {
1008                         tmp = launchconditions->next;
1009                         __ps_free_launchconditions(launchconditions);
1010                         launchconditions = tmp;
1011                 }
1012         }
1013         /*Free Notification*/
1014         if (uiapplication->notification) {
1015                 notification_x *notification = uiapplication->notification;
1016                 notification_x *tmp = NULL;
1017                 while(notification != NULL) {
1018                         tmp = notification->next;
1019                         __ps_free_notification(notification);
1020                         notification = tmp;
1021                 }
1022         }
1023         /*Free DataShare*/
1024         if (uiapplication->datashare) {
1025                 datashare_x *datashare = uiapplication->datashare;
1026                 datashare_x *tmp = NULL;
1027                 while(datashare != NULL) {
1028                         tmp = datashare->next;
1029                         __ps_free_datashare(datashare);
1030                         datashare = tmp;
1031                 }
1032         }
1033         /*Free AppSvc*/
1034         if (uiapplication->appsvc) {
1035                 appsvc_x *appsvc = uiapplication->appsvc;
1036                 appsvc_x *tmp = NULL;
1037                 while(appsvc != NULL) {
1038                         tmp = appsvc->next;
1039                         __ps_free_appsvc(appsvc);
1040                         appsvc = tmp;
1041                 }
1042         }
1043         /*Free Category*/
1044         if (uiapplication->category) {
1045                 category_x *category = uiapplication->category;
1046                 category_x *tmp = NULL;
1047                 while(category != NULL) {
1048                         tmp = category->next;
1049                         __ps_free_category(category);
1050                         category = tmp;
1051                 }
1052         }
1053         /*Free Metadata*/
1054         if (uiapplication->metadata) {
1055                 metadata_x *metadata = uiapplication->metadata;
1056                 metadata_x *tmp = NULL;
1057                 while(metadata != NULL) {
1058                         tmp = metadata->next;
1059                         __ps_free_metadata(metadata);
1060                         metadata = tmp;
1061                 }
1062         }
1063         /*Free permission*/
1064         if (uiapplication->permission) {
1065                 permission_x *permission = uiapplication->permission;
1066                 permission_x *tmp = NULL;
1067                 while(permission != NULL) {
1068                         tmp = permission->next;
1069                         __ps_free_permission(permission);
1070                         permission = tmp;
1071                 }
1072         }
1073         /* _PRODUCT_LAUNCHING_ENHANCED_ START */
1074         if (uiapplication->indicatordisplay) {
1075                 free((void *)uiapplication->indicatordisplay);
1076                 uiapplication->indicatordisplay = NULL;
1077         }
1078         if (uiapplication->portraitimg) {
1079                 free((void *)uiapplication->portraitimg);
1080                 uiapplication->portraitimg = NULL;
1081         }
1082         if (uiapplication->landscapeimg) {
1083                 free((void *)uiapplication->landscapeimg);
1084                 uiapplication->landscapeimg = NULL;
1085         }
1086         /* _PRODUCT_LAUNCHING_ENHANCED_ END */
1087         if (uiapplication->guestmode_visibility) {
1088                 free((void *)uiapplication->guestmode_visibility);
1089                 uiapplication->guestmode_visibility = NULL;
1090         }
1091         if (uiapplication->app_component) {
1092                 free((void *)uiapplication->app_component);
1093                 uiapplication->app_component = NULL;
1094         }
1095         if (uiapplication->permission_type) {
1096                 free((void *)uiapplication->permission_type);
1097                 uiapplication->permission_type = NULL;
1098         }
1099         if (uiapplication->component_type) {
1100                 free((void *)uiapplication->component_type);
1101                 uiapplication->component_type = NULL;
1102         }
1103         if (uiapplication->preload) {
1104                 free((void *)uiapplication->preload);
1105                 uiapplication->preload = NULL;
1106         }
1107         if (uiapplication->submode) {
1108                 free((void *)uiapplication->submode);
1109                 uiapplication->submode = NULL;
1110         }
1111         if (uiapplication->submode_mainid) {
1112                 free((void *)uiapplication->submode_mainid);
1113                 uiapplication->submode_mainid = NULL;
1114         }
1115         if (uiapplication->installed_storage) {
1116                 free((void *)uiapplication->installed_storage);
1117                 uiapplication->installed_storage = NULL;
1118         }
1119         if (uiapplication->process_pool) {
1120                 free((void *)uiapplication->process_pool);
1121                 uiapplication->process_pool = NULL;
1122         }
1123         if (uiapplication->autorestart) {
1124                 free((void *)uiapplication->autorestart);
1125                 uiapplication->autorestart = NULL;
1126         }
1127         if (uiapplication->onboot) {
1128                 free((void *)uiapplication->onboot);
1129                 uiapplication->onboot = NULL;
1130         }
1131
1132         free((void*)uiapplication);
1133         uiapplication = NULL;
1134 }
1135
1136 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication)
1137 {
1138         if (serviceapplication == NULL)
1139                 return;
1140         if (serviceapplication->exec) {
1141                 free((void *)serviceapplication->exec);
1142                 serviceapplication->exec = NULL;
1143         }
1144         if (serviceapplication->appid) {
1145                 free((void *)serviceapplication->appid);
1146                 serviceapplication->appid = NULL;
1147         }
1148         if (serviceapplication->onboot) {
1149                 free((void *)serviceapplication->onboot);
1150                 serviceapplication->onboot = NULL;
1151         }
1152         if (serviceapplication->autorestart) {
1153                 free((void *)serviceapplication->autorestart);
1154                 serviceapplication->autorestart = NULL;
1155         }
1156         if (serviceapplication->type) {
1157                 free((void *)serviceapplication->type);
1158                 serviceapplication->type = NULL;
1159         }
1160         if (serviceapplication->enabled) {
1161                 free((void *)serviceapplication->enabled);
1162                 serviceapplication->enabled = NULL;
1163         }
1164         if (serviceapplication->package) {
1165                 free((void *)serviceapplication->package);
1166                 serviceapplication->package = NULL;
1167         }
1168         if (serviceapplication->permission_type) {
1169                 free((void *)serviceapplication->permission_type);
1170                 serviceapplication->permission_type = NULL;
1171         }
1172         /*Free Label*/
1173         if (serviceapplication->label) {
1174                 label_x *label = serviceapplication->label;
1175                 label_x *tmp = NULL;
1176                 while(label != NULL) {
1177                         tmp = label->next;
1178                         __ps_free_label(label);
1179                         label = tmp;
1180                 }
1181         }
1182         /*Free Icon*/
1183         if (serviceapplication->icon) {
1184                 icon_x *icon = serviceapplication->icon;
1185                 icon_x *tmp = NULL;
1186                 while(icon != NULL) {
1187                         tmp = icon->next;
1188                         __ps_free_icon(icon);
1189                         icon = tmp;
1190                 }
1191         }
1192         /*Free AppControl*/
1193         if (serviceapplication->appcontrol) {
1194                 appcontrol_x *appcontrol = serviceapplication->appcontrol;
1195                 appcontrol_x *tmp = NULL;
1196                 while(appcontrol != NULL) {
1197                         tmp = appcontrol->next;
1198                         __ps_free_appcontrol(appcontrol);
1199                         appcontrol = tmp;
1200                 }
1201         }
1202         /*Free DataControl*/
1203         if (serviceapplication->datacontrol) {
1204                 datacontrol_x *datacontrol = serviceapplication->datacontrol;
1205                 datacontrol_x *tmp = NULL;
1206                 while(datacontrol != NULL) {
1207                         tmp = datacontrol->next;
1208                         __ps_free_datacontrol(datacontrol);
1209                         datacontrol = tmp;
1210                 }
1211         }
1212         /*Free LaunchConditions*/
1213         if (serviceapplication->launchconditions) {
1214                 launchconditions_x *launchconditions = serviceapplication->launchconditions;
1215                 launchconditions_x *tmp = NULL;
1216                 while(launchconditions != NULL) {
1217                         tmp = launchconditions->next;
1218                         __ps_free_launchconditions(launchconditions);
1219                         launchconditions = tmp;
1220                 }
1221         }
1222         /*Free Notification*/
1223         if (serviceapplication->notification) {
1224                 notification_x *notification = serviceapplication->notification;
1225                 notification_x *tmp = NULL;
1226                 while(notification != NULL) {
1227                         tmp = notification->next;
1228                         __ps_free_notification(notification);
1229                         notification = tmp;
1230                 }
1231         }
1232         /*Free DataShare*/
1233         if (serviceapplication->datashare) {
1234                 datashare_x *datashare = serviceapplication->datashare;
1235                 datashare_x *tmp = NULL;
1236                 while(datashare != NULL) {
1237                         tmp = datashare->next;
1238                         __ps_free_datashare(datashare);
1239                         datashare = tmp;
1240                 }
1241         }
1242         /*Free AppSvc*/
1243         if (serviceapplication->appsvc) {
1244                 appsvc_x *appsvc = serviceapplication->appsvc;
1245                 appsvc_x *tmp = NULL;
1246                 while(appsvc != NULL) {
1247                         tmp = appsvc->next;
1248                         __ps_free_appsvc(appsvc);
1249                         appsvc = tmp;
1250                 }
1251         }
1252         /*Free Category*/
1253         if (serviceapplication->category) {
1254                 category_x *category = serviceapplication->category;
1255                 category_x *tmp = NULL;
1256                 while(category != NULL) {
1257                         tmp = category->next;
1258                         __ps_free_category(category);
1259                         category = tmp;
1260                 }
1261         }
1262         /*Free Metadata*/
1263         if (serviceapplication->metadata) {
1264                 metadata_x *metadata = serviceapplication->metadata;
1265                 metadata_x *tmp = NULL;
1266                 while(metadata != NULL) {
1267                         tmp = metadata->next;
1268                         __ps_free_metadata(metadata);
1269                         metadata = tmp;
1270                 }
1271         }
1272         /*Free permission*/
1273         if (serviceapplication->permission) {
1274                 permission_x *permission = serviceapplication->permission;
1275                 permission_x *tmp = NULL;
1276                 while(permission != NULL) {
1277                         tmp = permission->next;
1278                         __ps_free_permission(permission);
1279                         permission = tmp;
1280                 }
1281         }
1282         free((void*)serviceapplication);
1283         serviceapplication = NULL;
1284 }
1285
1286 static void __ps_free_font(font_x *font)
1287 {
1288         if (font == NULL)
1289                 return;
1290         if (font->name) {
1291                 free((void *)font->name);
1292                 font->name = NULL;
1293         }
1294         if (font->text) {
1295                 free((void *)font->text);
1296                 font->text = NULL;
1297         }
1298         free((void*)font);
1299         font = NULL;
1300 }
1301
1302 static void __ps_free_theme(theme_x *theme)
1303 {
1304         if (theme == NULL)
1305                 return;
1306         if (theme->name) {
1307                 free((void *)theme->name);
1308                 theme->name = NULL;
1309         }
1310         if (theme->text) {
1311                 free((void *)theme->text);
1312                 theme->text = NULL;
1313         }
1314         free((void*)theme);
1315         theme = NULL;
1316 }
1317
1318 static void __ps_free_daemon(daemon_x *daemon)
1319 {
1320         if (daemon == NULL)
1321                 return;
1322         if (daemon->name) {
1323                 free((void *)daemon->name);
1324                 daemon->name = NULL;
1325         }
1326         if (daemon->text) {
1327                 free((void *)daemon->text);
1328                 daemon->text = NULL;
1329         }
1330         free((void*)daemon);
1331         daemon = NULL;
1332 }
1333
1334 static void __ps_free_ime(ime_x *ime)
1335 {
1336         if (ime == NULL)
1337                 return;
1338         if (ime->name) {
1339                 free((void *)ime->name);
1340                 ime->name = NULL;
1341         }
1342         if (ime->text) {
1343                 free((void *)ime->text);
1344                 ime->text = NULL;
1345         }
1346         free((void*)ime);
1347         ime = NULL;
1348 }
1349
1350 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
1351 {
1352         xmlTextReaderRead(reader);
1353         if (xmlTextReaderValue(reader))
1354                 allowed->text = ASCII(xmlTextReaderValue(reader));
1355         return 0;
1356 }
1357
1358 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
1359 {
1360         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1361                 operation->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1362 /* Text does not exist. Only attribute exists
1363         xmlTextReaderRead(reader);
1364         if (xmlTextReaderValue(reader))
1365                 operation->text = ASCII(xmlTextReaderValue(reader));
1366 */
1367         return 0;
1368 }
1369
1370 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
1371 {
1372         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1373                 uri->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1374 /* Text does not exist. Only attribute exists
1375         xmlTextReaderRead(reader);
1376         if (xmlTextReaderValue(reader))
1377                 uri->text = ASCII(xmlTextReaderValue(reader));
1378 */
1379         return 0;
1380 }
1381
1382 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
1383 {
1384         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1385                 mime->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1386 /* Text does not exist. Only attribute exists
1387         xmlTextReaderRead(reader);
1388         if (xmlTextReaderValue(reader))
1389                 mime->text = ASCII(xmlTextReaderValue(reader));
1390 */
1391         return 0;
1392 }
1393
1394 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
1395 {
1396         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1397                 subapp->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1398 /* Text does not exist. Only attribute exists
1399         xmlTextReaderRead(reader);
1400         if (xmlTextReaderValue(reader))
1401                 mime->text = ASCII(xmlTextReaderValue(reader));
1402 */
1403         return 0;
1404 }
1405
1406 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
1407 {
1408         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1409                 condition->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1410         xmlTextReaderRead(reader);
1411         if (xmlTextReaderValue(reader))
1412                 condition->text = ASCII(xmlTextReaderValue(reader));
1413         return 0;
1414 }
1415
1416 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1417 {
1418         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1419                 notification->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1420         xmlTextReaderRead(reader);
1421         if (xmlTextReaderValue(reader))
1422                 notification->text = ASCII(xmlTextReaderValue(reader));
1423         return 0;
1424 }
1425
1426 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
1427 {
1428         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1429                 category->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1430         return 0;
1431 }
1432
1433 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
1434 {
1435         xmlTextReaderRead(reader);
1436         if (xmlTextReaderValue(reader)) {
1437                 privilege->text = ASCII(xmlTextReaderValue(reader));
1438         }
1439         return 0;
1440 }
1441
1442 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1443 {
1444         if (xmlTextReaderGetAttribute(reader, XMLCHAR("key")))
1445                 metadata->key = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("key")));
1446         if (xmlTextReaderGetAttribute(reader, XMLCHAR("value")))
1447                 metadata->value = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("value")));
1448         return 0;
1449 }
1450
1451 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1452 {
1453         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
1454                 permission->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
1455
1456         xmlTextReaderRead(reader);
1457         if (xmlTextReaderValue(reader))
1458                 permission->value = ASCII(xmlTextReaderValue(reader));
1459         return 0;
1460 }
1461
1462 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1463 {
1464         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1465                 compatibility->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1466         xmlTextReaderRead(reader);
1467         if (xmlTextReaderValue(reader))
1468                 compatibility->text = ASCII(xmlTextReaderValue(reader));
1469         return 0;
1470 }
1471
1472 static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution)
1473 {
1474         if (xmlTextReaderGetAttribute(reader, XMLCHAR("mime-type")))
1475                 resolution->mimetype = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("mime-type")));
1476         if (xmlTextReaderGetAttribute(reader, XMLCHAR("uri-scheme")))
1477                 resolution->urischeme = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("uri-scheme")));
1478         return 0;
1479 }
1480
1481 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
1482 {
1483         xmlTextReaderRead(reader);
1484         if (xmlTextReaderValue(reader))
1485                 request->text = ASCII(xmlTextReaderValue(reader));
1486         return 0;
1487 }
1488
1489 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1490 {
1491         const xmlChar *node;
1492         int ret = -1;
1493         int depth = -1;
1494         allowed_x *tmp1 = NULL;
1495         request_x *tmp2 = NULL;
1496
1497         if (xmlTextReaderGetAttribute(reader, XMLCHAR("path")))
1498                 define->path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("path")));
1499
1500         depth = xmlTextReaderDepth(reader);
1501         while ((ret = __next_child_element(reader, depth))) {
1502                 node = xmlTextReaderConstName(reader);
1503                 if (!node) {
1504                         _LOGD("xmlTextReaderConstName value is NULL\n");
1505                         return -1;
1506                 }
1507
1508                 if (!strcmp(ASCII(node), "allowed")) {
1509                         allowed_x *allowed= malloc(sizeof(allowed_x));
1510                         if (allowed == NULL) {
1511                                 _LOGD("Malloc Failed\n");
1512                                 return -1;
1513                         }
1514                         memset(allowed, '\0', sizeof(allowed_x));
1515                         LISTADD(define->allowed, allowed);
1516                         ret = __ps_process_allowed(reader, allowed);
1517                 } else if (!strcmp(ASCII(node), "request")) {
1518                         request_x *request = malloc(sizeof(request_x));
1519                         if (request == NULL) {
1520                                 _LOGD("Malloc Failed\n");
1521                                 return -1;
1522                         }
1523                         memset(request, '\0', sizeof(request_x));
1524                         LISTADD(define->request, request);
1525                         ret = __ps_process_request(reader, request);
1526                 } else
1527                         return -1;
1528                 if (ret < 0) {
1529                         _LOGD("Processing define failed\n");
1530                         return ret;
1531                 }
1532         }
1533         if (define->allowed) {
1534                 LISTHEAD(define->allowed, tmp1);
1535                 define->allowed = tmp1;
1536         }
1537         if (define->request) {
1538                 LISTHEAD(define->request, tmp2);
1539                 define->request = tmp2;
1540         }
1541         return ret;
1542 }
1543
1544 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
1545 {
1546         const xmlChar *node;
1547         int ret = -1;
1548         int depth = -1;
1549         operation_x *tmp1 = NULL;
1550         uri_x *tmp2 = NULL;
1551         mime_x *tmp3 = NULL;
1552         subapp_x *tmp4 = NULL;
1553
1554         depth = xmlTextReaderDepth(reader);
1555         while ((ret = __next_child_element(reader, depth))) {
1556                 node = xmlTextReaderConstName(reader);
1557                 if (!node) {
1558                         _LOGD("xmlTextReaderConstName value is NULL\n");
1559                         return -1;
1560                 }
1561
1562                 if (!strcmp(ASCII(node), "operation")) {
1563                         operation_x *operation = malloc(sizeof(operation_x));
1564                         if (operation == NULL) {
1565                                 _LOGD("Malloc Failed\n");
1566                                 return -1;
1567                         }
1568                         memset(operation, '\0', sizeof(operation_x));
1569                         LISTADD(appcontrol->operation, operation);
1570                         ret = __ps_process_operation(reader, operation);
1571                         _LOGD("operation processing\n");
1572                 } else if (!strcmp(ASCII(node), "uri")) {
1573                         uri_x *uri= malloc(sizeof(uri_x));
1574                         if (uri == NULL) {
1575                                 _LOGD("Malloc Failed\n");
1576                                 return -1;
1577                         }
1578                         memset(uri, '\0', sizeof(uri_x));
1579                         LISTADD(appcontrol->uri, uri);
1580                         ret = __ps_process_uri(reader, uri);
1581                         _LOGD("uri processing\n");
1582                 } else if (!strcmp(ASCII(node), "mime")) {
1583                         mime_x *mime = malloc(sizeof(mime_x));
1584                         if (mime == NULL) {
1585                                 _LOGD("Malloc Failed\n");
1586                                 return -1;
1587                         }
1588                         memset(mime, '\0', sizeof(mime_x));
1589                         LISTADD(appcontrol->mime, mime);
1590                         ret = __ps_process_mime(reader, mime);
1591                         _LOGD("mime processing\n");
1592                 } else if (!strcmp(ASCII(node), "subapp")) {
1593                         subapp_x *subapp = malloc(sizeof(subapp_x));
1594                         if (subapp == NULL) {
1595                                 _LOGD("Malloc Failed\n");
1596                                 return -1;
1597                         }
1598                         memset(subapp, '\0', sizeof(subapp_x));
1599                         LISTADD(appcontrol->subapp, subapp);
1600                         ret = __ps_process_subapp(reader, subapp);
1601                         _LOGD("subapp processing\n");
1602                 } else
1603                         return -1;
1604                 if (ret < 0) {
1605                         _LOGD("Processing appcontrol failed\n");
1606                         return ret;
1607                 }
1608         }
1609         if (appcontrol->operation) {
1610                 LISTHEAD(appcontrol->operation, tmp1);
1611                 appcontrol->operation = tmp1;
1612         }
1613         if (appcontrol->uri) {
1614                 LISTHEAD(appcontrol->uri, tmp2);
1615                 appcontrol->uri = tmp2;
1616         }
1617         if (appcontrol->mime) {
1618                 LISTHEAD(appcontrol->mime, tmp3);
1619                 appcontrol->mime = tmp3;
1620         }
1621         if (appcontrol->subapp) {
1622                 LISTHEAD(appcontrol->subapp, tmp4);
1623                 appcontrol->subapp = tmp4;
1624         }
1625
1626         xmlTextReaderRead(reader);
1627         if (xmlTextReaderValue(reader))
1628                 appcontrol->text = ASCII(xmlTextReaderValue(reader));
1629
1630         return ret;
1631 }
1632
1633 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
1634 {
1635         const xmlChar *node;
1636         int ret = -1;
1637         int depth = -1;
1638         operation_x *tmp1 = NULL;
1639         uri_x *tmp2 = NULL;
1640         mime_x *tmp3 = NULL;
1641         subapp_x *tmp4 = NULL;
1642
1643         depth = xmlTextReaderDepth(reader);
1644         while ((ret = __next_child_element(reader, depth))) {
1645                 node = xmlTextReaderConstName(reader);
1646                 if (!node) {
1647                         _LOGD("xmlTextReaderConstName value is NULL\n");
1648                         return -1;
1649                 }
1650
1651                 if (!strcmp(ASCII(node), "operation")) {
1652                         operation_x *operation = malloc(sizeof(operation_x));
1653                         if (operation == NULL) {
1654                                 _LOGD("Malloc Failed\n");
1655                                 return -1;
1656                         }
1657                         memset(operation, '\0', sizeof(operation_x));
1658                         LISTADD(appsvc->operation, operation);
1659                         ret = __ps_process_operation(reader, operation);
1660                         _LOGD("operation processing\n");
1661                 } else if (!strcmp(ASCII(node), "uri")) {
1662                         uri_x *uri= malloc(sizeof(uri_x));
1663                         if (uri == NULL) {
1664                                 _LOGD("Malloc Failed\n");
1665                                 return -1;
1666                         }
1667                         memset(uri, '\0', sizeof(uri_x));
1668                         LISTADD(appsvc->uri, uri);
1669                         ret = __ps_process_uri(reader, uri);
1670                         _LOGD("uri processing\n");
1671                 } else if (!strcmp(ASCII(node), "mime")) {
1672                         mime_x *mime = malloc(sizeof(mime_x));
1673                         if (mime == NULL) {
1674                                 _LOGD("Malloc Failed\n");
1675                                 return -1;
1676                         }
1677                         memset(mime, '\0', sizeof(mime_x));
1678                         LISTADD(appsvc->mime, mime);
1679                         ret = __ps_process_mime(reader, mime);
1680                         _LOGD("mime processing\n");
1681                 } else if (!strcmp(ASCII(node), "subapp")) {
1682                         subapp_x *subapp = malloc(sizeof(subapp_x));
1683                         if (subapp == NULL) {
1684                                 _LOGD("Malloc Failed\n");
1685                                 return -1;
1686                         }
1687                         memset(subapp, '\0', sizeof(subapp_x));
1688                         LISTADD(appsvc->subapp, subapp);
1689                         ret = __ps_process_subapp(reader, subapp);
1690                         _LOGD("subapp processing\n");
1691                 } else
1692                         return -1;
1693                 if (ret < 0) {
1694                         _LOGD("Processing appsvc failed\n");
1695                         return ret;
1696                 }
1697         }
1698         if (appsvc->operation) {
1699                 LISTHEAD(appsvc->operation, tmp1);
1700                 appsvc->operation = tmp1;
1701         }
1702         if (appsvc->uri) {
1703                 LISTHEAD(appsvc->uri, tmp2);
1704                 appsvc->uri = tmp2;
1705         }
1706         if (appsvc->mime) {
1707                 LISTHEAD(appsvc->mime, tmp3);
1708                 appsvc->mime = tmp3;
1709         }
1710         if (appsvc->subapp) {
1711                 LISTHEAD(appsvc->subapp, tmp4);
1712                 appsvc->subapp = tmp4;
1713         }
1714
1715         xmlTextReaderRead(reader);
1716         if (xmlTextReaderValue(reader))
1717                 appsvc->text = ASCII(xmlTextReaderValue(reader));
1718
1719         return ret;
1720 }
1721
1722
1723 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
1724 {
1725         const xmlChar *node;
1726         int ret = -1;
1727         int depth = -1;
1728         privilege_x *tmp1 = NULL;
1729
1730         depth = xmlTextReaderDepth(reader);
1731         while ((ret = __next_child_element(reader, depth))) {
1732                 node = xmlTextReaderConstName(reader);
1733                 if (!node) {
1734                         _LOGD("xmlTextReaderConstName value is NULL\n");
1735                         return -1;
1736                 }
1737
1738                 if (strcmp(ASCII(node), "privilege") == 0) {
1739                         privilege_x *privilege = malloc(sizeof(privilege_x));
1740                         if (privilege == NULL) {
1741                                 _LOGD("Malloc Failed\n");
1742                                 return -1;
1743                         }
1744                         memset(privilege, '\0', sizeof(privilege_x));
1745                         LISTADD(privileges->privilege, privilege);
1746                         ret = __ps_process_privilege(reader, privilege);
1747                 } else
1748                         return -1;
1749                 if (ret < 0) {
1750                         _LOGD("Processing privileges failed\n");
1751                         return ret;
1752                 }
1753         }
1754         if (privileges->privilege) {
1755                 LISTHEAD(privileges->privilege, tmp1);
1756                 privileges->privilege = tmp1;
1757         }
1758         return ret;
1759 }
1760
1761 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
1762 {
1763         const xmlChar *node;
1764         int ret = -1;
1765         int depth = -1;
1766         condition_x *tmp1 = NULL;
1767
1768         depth = xmlTextReaderDepth(reader);
1769         while ((ret = __next_child_element(reader, depth))) {
1770                 node = xmlTextReaderConstName(reader);
1771                 if (!node) {
1772                         _LOGD("xmlTextReaderConstName value is NULL\n");
1773                         return -1;
1774                 }
1775
1776                 if (strcmp(ASCII(node), "condition") == 0) {
1777                         condition_x *condition = malloc(sizeof(condition_x));
1778                         if (condition == NULL) {
1779                                 _LOGD("Malloc Failed\n");
1780                                 return -1;
1781                         }
1782                         memset(condition, '\0', sizeof(condition_x));
1783                         LISTADD(launchconditions->condition, condition);
1784                         ret = __ps_process_condition(reader, condition);
1785                 } else
1786                         return -1;
1787                 if (ret < 0) {
1788                         _LOGD("Processing launchconditions failed\n");
1789                         return ret;
1790                 }
1791         }
1792         if (launchconditions->condition) {
1793                 LISTHEAD(launchconditions->condition, tmp1);
1794                 launchconditions->condition = tmp1;
1795         }
1796
1797         xmlTextReaderRead(reader);
1798         if (xmlTextReaderValue(reader))
1799                 launchconditions->text = ASCII(xmlTextReaderValue(reader));
1800
1801         return ret;
1802 }
1803
1804 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1805 {
1806         const xmlChar *node;
1807         int ret = -1;
1808         int depth = -1;
1809         define_x *tmp1 = NULL;
1810         request_x *tmp2 = NULL;
1811         depth = xmlTextReaderDepth(reader);
1812         while ((ret = __next_child_element(reader, depth))) {
1813                 node = xmlTextReaderConstName(reader);
1814                 if (!node) {
1815                         _LOGD("xmlTextReaderConstName value is NULL\n");
1816                         return -1;
1817                 }
1818
1819                 if (!strcmp(ASCII(node), "define")) {
1820                         define_x *define= malloc(sizeof(define_x));
1821                         if (define == NULL) {
1822                                 _LOGD("Malloc Failed\n");
1823                                 return -1;
1824                         }
1825                         memset(define, '\0', sizeof(define_x));
1826                         LISTADD(datashare->define, define);
1827                         ret = __ps_process_define(reader, define);
1828                 } else if (!strcmp(ASCII(node), "request")) {
1829                         request_x *request= malloc(sizeof(request_x));
1830                         if (request == NULL) {
1831                                 _LOGD("Malloc Failed\n");
1832                                 return -1;
1833                         }
1834                         memset(request, '\0', sizeof(request_x));
1835                         LISTADD(datashare->request, request);
1836                         ret = __ps_process_request(reader, request);
1837                 } else
1838                         return -1;
1839                 if (ret < 0) {
1840                         _LOGD("Processing data-share failed\n");
1841                         return ret;
1842                 }
1843         }
1844         if (datashare->define) {
1845                 LISTHEAD(datashare->define, tmp1);
1846                 datashare->define = tmp1;
1847         }
1848         if (datashare->request) {
1849                 LISTHEAD(datashare->request, tmp2);
1850                 datashare->request = tmp2;
1851         }
1852         return ret;
1853 }
1854
1855 static char*
1856 __get_icon_with_path(const char* icon)
1857 {
1858         if (!icon)
1859                 return NULL;
1860
1861         if (index(icon, '/') == NULL) {
1862                 char* theme = NULL;
1863                 char* icon_with_path = NULL;
1864                 int len;
1865
1866                 if (!package)
1867                         return NULL;
1868
1869 /* "db/setting/theme" is not exist */
1870 #if 0
1871                 theme = vconf_get_str("db/setting/theme");
1872                 if (!theme) {
1873                         theme = strdup("default");
1874                         if(!theme) {
1875                                 return NULL;
1876                         }
1877                 }
1878 #else
1879                 theme = strdup("default");
1880 #endif
1881
1882                 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
1883                 icon_with_path = malloc(len);
1884                 if(icon_with_path == NULL) {
1885                         _LOGD("(icon_with_path == NULL) return\n");
1886                         free(theme);
1887                         return NULL;
1888                 }
1889
1890                 memset(icon_with_path, 0, len);
1891                 snprintf(icon_with_path, len, "/opt/usr/apps/%s/shared/res/icons/default/small/%s", package, icon);
1892                 do {
1893                         if (access(icon_with_path, R_OK) == 0) break;
1894                         snprintf(icon_with_path, len, "/opt/share/icons/%s/small/%s", theme, icon);
1895                         if (access(icon_with_path, R_OK) == 0) break;
1896                         snprintf(icon_with_path, len, "/usr/share/icons/%s/small/%s", theme, icon);
1897                         if (access(icon_with_path, R_OK) == 0) break;
1898                         _LOGD("cannot find icon %s", icon_with_path);
1899                         snprintf(icon_with_path, len,"/opt/share/icons/default/small/%s", icon);
1900                         if (access(icon_with_path, R_OK) == 0) break;
1901                         snprintf(icon_with_path, len, "/usr/share/icons/default/small/%s", icon);
1902                         if (access(icon_with_path, R_OK) == 0) break;
1903
1904                         /* icon path is going to be moved intto the app directory */
1905                         snprintf(icon_with_path, len, "/usr/apps/%s/shared/res/icons/default/small/%s", package, icon);
1906                         if (access(icon_with_path, R_OK) == 0) break;
1907                         snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/%s/small/%s", package, theme, icon);
1908                         if (access(icon_with_path, R_OK) == 0) break;
1909                         snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/%s/small/%s", package, theme, icon);
1910                         if (access(icon_with_path, R_OK) == 0) break;
1911                         _LOGD("cannot find icon %s", icon_with_path);
1912                         snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/default/small/%s", package, icon);
1913                         if (access(icon_with_path, R_OK) == 0) break;
1914                         snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/default/small/%s", package, icon);
1915                         if (access(icon_with_path, R_OK) == 0) break;
1916                         snprintf(icon_with_path, len, "/usr/ug/res/images/%s/%s", package, icon);
1917                         if (access(icon_with_path, R_OK) == 0) break;
1918                 } while (0);
1919
1920                 free(theme);
1921
1922                 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1923
1924                 return icon_with_path;
1925         } else {
1926                 char* confirmed_icon = NULL;
1927
1928                 confirmed_icon = strdup(icon);
1929                 if (!confirmed_icon)
1930                         return NULL;
1931                 return confirmed_icon;
1932         }
1933 }
1934
1935 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1936 {
1937         int i = 0;
1938         char delims[] = "=";
1939         char *ret_result = NULL;
1940         char *tag = NULL;
1941
1942         if (tagv == NULL)
1943                 return;
1944
1945         for (tag = strdup(tagv[0]); tag != NULL; ) {
1946                 ret_result = strtok(tag, delims);
1947
1948                 /*check tag :  preload */
1949                 if (strcmp(ret_result, "preload") == 0) {
1950                         ret_result = strtok(NULL, delims);
1951                         if (strcmp(ret_result, "true") == 0) {
1952                                 free((void *)mfx->preload);
1953                                 mfx->preload = strdup("true");
1954                         } else if (strcmp(ret_result, "false") == 0) {
1955                                 free((void *)mfx->preload);
1956                                 mfx->preload = strdup("false");
1957                         }
1958                 /*check tag :  removable*/
1959                 } else if (strcmp(ret_result, "removable") == 0) {
1960                         ret_result = strtok(NULL, delims);
1961                         if (strcmp(ret_result, "true") == 0){
1962                                 free((void *)mfx->removable);
1963                                 mfx->removable = strdup("true");
1964                         } else if (strcmp(ret_result, "false") == 0) {
1965                                 free((void *)mfx->removable);
1966                                 mfx->removable = strdup("false");
1967                         }
1968                 /*check tag :  not matched*/
1969                 } else
1970                         _LOGD("tag process [%s]is not defined\n", ret_result);
1971
1972                 free(tag);
1973
1974                 /*check next value*/
1975                 if (tagv[++i] != NULL)
1976                         tag = strdup(tagv[i]);
1977                 else {
1978                         /*update tag :  system*/
1979                         if ((strcmp(mfx->preload,"true")==0) && (strcmp(mfx->removable,"false")==0)){
1980                                 free((void *)mfx->system);
1981                                 mfx->system = strdup("true");
1982                         }
1983                         _LOGD("tag process success...\n");
1984                         return;
1985                 }
1986         }
1987 }
1988
1989 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
1990 {
1991         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
1992                 icon->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
1993         if (xmlTextReaderConstXmlLang(reader)) {
1994                 icon->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
1995                 if (icon->lang == NULL)
1996                         icon->lang = strdup(DEFAULT_LOCALE);
1997         } else {
1998                 icon->lang = strdup(DEFAULT_LOCALE);
1999         }
2000         if (xmlTextReaderGetAttribute(reader, XMLCHAR("section")))
2001                 icon->section = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("section")));
2002         if (xmlTextReaderGetAttribute(reader, XMLCHAR("size")))
2003                 icon->size = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("size")));
2004         if (xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")))
2005                 icon->resolution = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")));
2006         xmlTextReaderRead(reader);
2007         if (xmlTextReaderValue(reader)) {
2008                 const char *text  = ASCII(xmlTextReaderValue(reader));
2009                 if(text) {
2010                         icon->text = (const char *)__get_icon_with_path(text);
2011                         free((void *)text);
2012                 }
2013         }
2014
2015         return 0;
2016 }
2017
2018 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
2019 {
2020         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2021                 image->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2022         if (xmlTextReaderConstXmlLang(reader)) {
2023                 image->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2024                 if (image->lang == NULL)
2025                         image->lang = strdup(DEFAULT_LOCALE);
2026         } else {
2027                 image->lang = strdup(DEFAULT_LOCALE);
2028         }
2029         if (xmlTextReaderGetAttribute(reader, XMLCHAR("section")))
2030                 image->section = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("section")));
2031         xmlTextReaderRead(reader);
2032         if (xmlTextReaderValue(reader))
2033                 image->text = ASCII(xmlTextReaderValue(reader));
2034
2035         return 0;
2036 }
2037
2038 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
2039 {
2040         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2041                 label->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2042         if (xmlTextReaderConstXmlLang(reader)) {
2043                 label->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2044                 if (label->lang == NULL)
2045                         label->lang = strdup(DEFAULT_LOCALE);
2046         } else {
2047                 label->lang = strdup(DEFAULT_LOCALE);
2048         }
2049         xmlTextReaderRead(reader);
2050         if (xmlTextReaderValue(reader))
2051                 label->text = ASCII(xmlTextReaderValue(reader));
2052
2053 /*      _LOGD("lable name %s\n", label->name);
2054         _LOGD("lable lang %s\n", label->lang);
2055         _LOGD("lable text %s\n", label->text);
2056 */
2057         return 0;
2058
2059 }
2060
2061 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
2062 {
2063         if (xmlTextReaderGetAttribute(reader, XMLCHAR("email")))
2064                 author->email = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("email")));
2065         if (xmlTextReaderGetAttribute(reader, XMLCHAR("href")))
2066                 author->href = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("href")));
2067         if (xmlTextReaderConstXmlLang(reader)) {
2068                 author->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2069                 if (author->lang == NULL)
2070                         author->lang = strdup(DEFAULT_LOCALE);
2071         } else {
2072                 author->lang = strdup(DEFAULT_LOCALE);
2073         }
2074         xmlTextReaderRead(reader);
2075         if (xmlTextReaderValue(reader)) {
2076                 const char *text  = ASCII(xmlTextReaderValue(reader));
2077                 if (*text == '\n') {
2078                         author->text = NULL;
2079                         free((void *)text);
2080                         return 0;
2081                 }
2082                 author->text = ASCII(xmlTextReaderValue(reader));
2083         }
2084         return 0;
2085 }
2086
2087 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
2088 {
2089         if (xmlTextReaderConstXmlLang(reader)) {
2090                 description->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2091                 if (description->lang == NULL)
2092                         description->lang = strdup(DEFAULT_LOCALE);
2093         } else {
2094                 description->lang = strdup(DEFAULT_LOCALE);
2095         }
2096         xmlTextReaderRead(reader);
2097         if (xmlTextReaderValue(reader)) {
2098                 const char *text  = ASCII(xmlTextReaderValue(reader));
2099                 if (*text == '\n') {
2100                         description->text = NULL;
2101                         free((void *)text);
2102                         return 0;
2103                 }
2104                 description->text = ASCII(xmlTextReaderValue(reader));
2105         }
2106         return 0;
2107 }
2108
2109 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
2110 {
2111         if (xmlTextReaderConstXmlLang(reader)) {
2112                 license->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2113                 if (license->lang == NULL)
2114                         license->lang = strdup(DEFAULT_LOCALE);
2115         } else {
2116                 license->lang = strdup(DEFAULT_LOCALE);
2117         }
2118         xmlTextReaderRead(reader);
2119         if (xmlTextReaderValue(reader))
2120                 license->text = ASCII(xmlTextReaderValue(reader));
2121         return 0;
2122 }
2123
2124 static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability)
2125 {
2126         const xmlChar *node;
2127         int ret = -1;
2128         int depth = -1;
2129         resolution_x *tmp1 = NULL;
2130
2131         if (xmlTextReaderGetAttribute(reader, XMLCHAR("operation-id")))
2132                 capability->operationid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("operation-id")));
2133
2134         depth = xmlTextReaderDepth(reader);
2135         while ((ret = __next_child_element(reader, depth))) {
2136                 node = xmlTextReaderConstName(reader);
2137                 if (!node) {
2138                         _LOGD("xmlTextReaderConstName value is NULL\n");
2139                         return -1;
2140                 }
2141
2142                 if (!strcmp(ASCII(node), "resolution")) {
2143                         resolution_x *resolution = malloc(sizeof(resolution_x));
2144                         if (resolution == NULL) {
2145                                 _LOGD("Malloc Failed\n");
2146                                 return -1;
2147                         }
2148                         memset(resolution, '\0', sizeof(resolution_x));
2149                         LISTADD(capability->resolution, resolution);
2150                         ret = __ps_process_resolution(reader, resolution);
2151                 } else
2152                         return -1;
2153                 if (ret < 0) {
2154                         _LOGD("Processing capability failed\n");
2155                         return ret;
2156                 }
2157         }
2158
2159         if (capability->resolution) {
2160                 LISTHEAD(capability->resolution, tmp1);
2161                 capability->resolution = tmp1;
2162         }
2163
2164         return ret;
2165 }
2166
2167 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
2168 {
2169         const xmlChar *node;
2170         int ret = -1;
2171         int depth = -1;
2172         capability_x *tmp1 = NULL;
2173
2174         if (xmlTextReaderGetAttribute(reader, XMLCHAR("provider-id")))
2175                 datacontrol->providerid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("provider-id")));
2176
2177         depth = xmlTextReaderDepth(reader);
2178         while ((ret = __next_child_element(reader, depth))) {
2179                 node = xmlTextReaderConstName(reader);
2180                 if (!node) {
2181                         _LOGD("xmlTextReaderConstName value is NULL\n");
2182                         return -1;
2183                 }
2184
2185                 if (!strcmp(ASCII(node), "capability")) {
2186                         capability_x *capability = malloc(sizeof(capability_x));
2187                         if (capability == NULL) {
2188                                 _LOGD("Malloc Failed\n");
2189                                 return -1;
2190                         }
2191                         memset(capability, '\0', sizeof(capability_x));
2192                         LISTADD(datacontrol->capability, capability);
2193                         ret = __ps_process_capability(reader, capability);
2194                 } else
2195                         return -1;
2196                 if (ret < 0) {
2197                         _LOGD("Processing datacontrol failed\n");
2198                         return ret;
2199                 }
2200         }
2201
2202         if (datacontrol->capability) {
2203                 LISTHEAD(datacontrol->capability, tmp1);
2204                 datacontrol->capability = tmp1;
2205         }
2206
2207         return ret;
2208 }
2209
2210 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication)
2211 {
2212         const xmlChar *node;
2213         int ret = -1;
2214         int depth = -1;
2215         char *newappid = NULL;
2216         label_x *tmp1 = NULL;
2217         icon_x *tmp2 = NULL;
2218         appsvc_x *tmp3 = NULL;
2219         appcontrol_x *tmp4 = NULL;
2220         launchconditions_x *tmp5 = NULL;
2221         notification_x *tmp6 = NULL;
2222         datashare_x *tmp7 = NULL;
2223         category_x *tmp8 = NULL;
2224         metadata_x *tmp9 = NULL;
2225         image_x *tmp10 = NULL;
2226         permission_x *tmp11 = NULL;
2227
2228         if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
2229                 uiapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
2230                 if (uiapplication->appid == NULL) {
2231                         _LOGD("appid cant be NULL\n");
2232                         return -1;
2233                 }
2234         } else {
2235                 _LOGD("appid is mandatory\n");
2236                 return -1;
2237         }
2238         /*check appid*/
2239         ret = __validate_appid(package, uiapplication->appid, &newappid);
2240         if (ret == -1) {
2241                 _LOGD("appid is not proper\n");
2242                 return -1;
2243         } else {
2244                 if (newappid) {
2245                         if (uiapplication->appid)
2246                                 free((void *)uiapplication->appid);
2247                         uiapplication->appid = newappid;
2248                 }
2249                 uiapplication->package= strdup(package);
2250         }
2251         if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
2252                 uiapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
2253         if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay"))) {
2254                 uiapplication->nodisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay")));
2255                 if (uiapplication->nodisplay == NULL)
2256                         uiapplication->nodisplay = strdup("false");
2257         } else {
2258                 uiapplication->nodisplay = strdup("false");
2259         }
2260         if (xmlTextReaderGetAttribute(reader, XMLCHAR("multiple"))) {
2261                 uiapplication->multiple = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("multiple")));
2262                 if (uiapplication->multiple == NULL)
2263                         uiapplication->multiple = strdup("false");
2264         } else {
2265                 uiapplication->multiple = strdup("false");
2266         }
2267         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
2268                 uiapplication->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
2269         if (xmlTextReaderGetAttribute(reader, XMLCHAR("categories")))
2270                 uiapplication->categories = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("categories")));
2271         if (xmlTextReaderGetAttribute(reader, XMLCHAR("extraid")))
2272                 uiapplication->extraid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("extraid")));
2273         if (xmlTextReaderGetAttribute(reader, XMLCHAR("taskmanage"))) {
2274                 uiapplication->taskmanage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("taskmanage")));
2275                 if (uiapplication->taskmanage == NULL)
2276                         uiapplication->taskmanage = strdup("true");
2277         } else {
2278                 uiapplication->taskmanage = strdup("true");
2279         }
2280         if (xmlTextReaderGetAttribute(reader, XMLCHAR("enabled"))) {
2281                 uiapplication->enabled = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("enabled")));
2282                 if (uiapplication->enabled == NULL)
2283                         uiapplication->enabled = strdup("true");
2284         } else {
2285                 uiapplication->enabled = strdup("true");
2286         }
2287         if (xmlTextReaderGetAttribute(reader, XMLCHAR("hw-acceleration"))) {
2288                 uiapplication->hwacceleration = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("hw-acceleration")));
2289                 if (uiapplication->hwacceleration == NULL)
2290                         uiapplication->hwacceleration = strdup("use-system-setting");
2291         } else {
2292                 uiapplication->hwacceleration = strdup("use-system-setting");
2293         }
2294         if (xmlTextReaderGetAttribute(reader, XMLCHAR("screen-reader"))) {
2295                 uiapplication->screenreader = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("screen-reader")));
2296                 if (uiapplication->screenreader == NULL)
2297                         uiapplication->screenreader = strdup("use-system-setting");
2298         } else {
2299                 uiapplication->screenreader = strdup("use-system-setting");
2300         }
2301         if (xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")))
2302                 uiapplication->recentimage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")));
2303         if (xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp"))) {
2304                 uiapplication->mainapp = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp")));
2305                 if (uiapplication->mainapp == NULL)
2306                         uiapplication->mainapp = strdup("false");
2307         } else {
2308                 uiapplication->mainapp = strdup("false");
2309         }
2310         if (xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition"))) {
2311                 uiapplication->launchcondition = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition")));
2312                 if (uiapplication->launchcondition == NULL)
2313                         uiapplication->launchcondition = strdup("false");
2314         } else {
2315                 uiapplication->launchcondition = strdup("false");
2316         }
2317
2318         if (xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay"))) {
2319                 uiapplication->indicatordisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay")));
2320                 if (uiapplication->indicatordisplay == NULL)
2321                         uiapplication->indicatordisplay = strdup("true");
2322         } else {
2323                 uiapplication->indicatordisplay = strdup("true");
2324         }
2325         if (xmlTextReaderGetAttribute(reader, XMLCHAR("portrait-effectimage")))
2326                 uiapplication->portraitimg = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("portrait-effectimage")));
2327         else
2328                 uiapplication->portraitimg = NULL;
2329         if (xmlTextReaderGetAttribute(reader, XMLCHAR("landscape-effectimage")))
2330                 uiapplication->landscapeimg = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("landscape-effectimage")));
2331         else
2332                 uiapplication->landscapeimg = NULL;
2333         if (xmlTextReaderGetAttribute(reader, XMLCHAR("guestmode-visibility"))) {
2334                 uiapplication->guestmode_visibility = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("guestmode-visibility")));
2335                 if (uiapplication->guestmode_visibility == NULL)
2336                         uiapplication->guestmode_visibility = strdup("true");
2337         } else {
2338                 uiapplication->guestmode_visibility = strdup("true");
2339         }
2340         if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
2341                 uiapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
2342                 if (uiapplication->permission_type == NULL)
2343                         uiapplication->permission_type = strdup("normal");
2344         } else {
2345                 uiapplication->permission_type = strdup("normal");
2346         }
2347         if (xmlTextReaderGetAttribute(reader, XMLCHAR("component-type"))) {
2348                 uiapplication->component_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("component-type")));
2349                 if (uiapplication->component_type == NULL) {
2350                         uiapplication->component_type = strdup("uiapp");
2351                 } else {
2352                         /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
2353                         if (strcmp(uiapplication->component_type, "svcapp") != 0) {
2354                                 if (strcmp(uiapplication->component_type, "uiapp") != 0) {
2355                                         _LOGD("invalid component_type[%s]\n", uiapplication->component_type);
2356                                         return -1;
2357                                 }
2358                         }
2359                 }
2360         } else {
2361                 uiapplication->component_type = strdup("uiapp");
2362         }
2363         if (xmlTextReaderGetAttribute(reader, XMLCHAR("submode"))) {
2364                 uiapplication->submode = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("submode")));
2365                 if (uiapplication->submode == NULL)
2366                         uiapplication->submode = strdup("false");
2367         } else {
2368                 uiapplication->submode = strdup("false");
2369         }
2370         if (xmlTextReaderGetAttribute(reader, XMLCHAR("submode-mainid")))
2371                 uiapplication->submode_mainid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("submode-mainid")));
2372         if (xmlTextReaderGetAttribute(reader, XMLCHAR("process-pool"))) {
2373                 uiapplication->process_pool= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("process-pool")));
2374                 if (uiapplication->process_pool == NULL)
2375                         uiapplication->process_pool = strdup("false");
2376         } else {
2377                 uiapplication->process_pool = strdup("false");
2378         }
2379         if (xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart"))) {
2380                 uiapplication->autorestart= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart")));
2381                 if (uiapplication->autorestart == NULL)
2382                         uiapplication->autorestart = strdup("false");
2383         } else {
2384                 uiapplication->autorestart = strdup("false");
2385         }
2386         if (xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot"))) {
2387                 uiapplication->onboot= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot")));
2388                 if (uiapplication->onboot == NULL)
2389                         uiapplication->onboot = strdup("false");
2390         } else {
2391                 uiapplication->onboot = strdup("false");
2392         }
2393
2394         depth = xmlTextReaderDepth(reader);
2395         while ((ret = __next_child_element(reader, depth))) {
2396                 node = xmlTextReaderConstName(reader);
2397                 if (!node) {
2398                         _LOGD("xmlTextReaderConstName value is NULL\n");
2399                         return -1;
2400                 }
2401                 if (!strcmp(ASCII(node), "label")) {
2402                         label_x *label = malloc(sizeof(label_x));
2403                         if (label == NULL) {
2404                                 _LOGD("Malloc Failed\n");
2405                                 return -1;
2406                         }
2407                         memset(label, '\0', sizeof(label_x));
2408                         LISTADD(uiapplication->label, label);
2409                         ret = __ps_process_label(reader, label);
2410                 } else if (!strcmp(ASCII(node), "icon")) {
2411                         icon_x *icon = malloc(sizeof(icon_x));
2412                         if (icon == NULL) {
2413                                 _LOGD("Malloc Failed\n");
2414                                 return -1;
2415                         }
2416                         memset(icon, '\0', sizeof(icon_x));
2417                         LISTADD(uiapplication->icon, icon);
2418                         ret = __ps_process_icon(reader, icon);
2419                 } else if (!strcmp(ASCII(node), "image")) {
2420                         image_x *image = malloc(sizeof(image_x));
2421                         if (image == NULL) {
2422                                 _LOGD("Malloc Failed\n");
2423                                 return -1;
2424                         }
2425                         memset(image, '\0', sizeof(image_x));
2426                         LISTADD(uiapplication->image, image);
2427                         ret = __ps_process_image(reader, image);
2428                 } else if (!strcmp(ASCII(node), "category")) {
2429                         category_x *category = malloc(sizeof(category_x));
2430                         if (category == NULL) {
2431                                 _LOGD("Malloc Failed\n");
2432                                 return -1;
2433                         }
2434                         memset(category, '\0', sizeof(category_x));
2435                         LISTADD(uiapplication->category, category);
2436                         ret = __ps_process_category(reader, category);
2437                 } else if (!strcmp(ASCII(node), "metadata")) {
2438                         metadata_x *metadata = malloc(sizeof(metadata_x));
2439                         if (metadata == NULL) {
2440                                 _LOGD("Malloc Failed\n");
2441                                 return -1;
2442                         }
2443                         memset(metadata, '\0', sizeof(metadata_x));
2444                         LISTADD(uiapplication->metadata, metadata);
2445                         ret = __ps_process_metadata(reader, metadata);
2446                 } else if (!strcmp(ASCII(node), "permission")) {
2447                         permission_x *permission = malloc(sizeof(permission_x));
2448                         if (permission == NULL) {
2449                                 _LOGD("Malloc Failed\n");
2450                                 return -1;
2451                         }
2452                         memset(permission, '\0', sizeof(permission_x));
2453                         LISTADD(uiapplication->permission, permission);
2454                         ret = __ps_process_permission(reader, permission);
2455                 } else if (!strcmp(ASCII(node), "app-control")) {
2456                         appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
2457                         if (appcontrol == NULL) {
2458                                 _LOGD("Malloc Failed\n");
2459                                 return -1;
2460                         }
2461                         memset(appcontrol, '\0', sizeof(appcontrol_x));
2462                         LISTADD(uiapplication->appcontrol, appcontrol);
2463                         ret = __ps_process_appcontrol(reader, appcontrol);
2464                 } else if (!strcmp(ASCII(node), "application-service")) {
2465                         appsvc_x *appsvc = malloc(sizeof(appsvc_x));
2466                         if (appsvc == NULL) {
2467                                 _LOGD("Malloc Failed\n");
2468                                 return -1;
2469                         }
2470                         memset(appsvc, '\0', sizeof(appsvc_x));
2471                         LISTADD(uiapplication->appsvc, appsvc);
2472                         ret = __ps_process_appsvc(reader, appsvc);
2473                 } else if (!strcmp(ASCII(node), "data-share")) {
2474                         datashare_x *datashare = malloc(sizeof(datashare_x));
2475                         if (datashare == NULL) {
2476                                 _LOGD("Malloc Failed\n");
2477                                 return -1;
2478                         }
2479                         memset(datashare, '\0', sizeof(datashare_x));
2480                         LISTADD(uiapplication->datashare, datashare);
2481                         ret = __ps_process_datashare(reader, datashare);
2482                 } else if (!strcmp(ASCII(node), "launch-conditions")) {
2483                         launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
2484                         if (launchconditions == NULL) {
2485                                 _LOGD("Malloc Failed\n");
2486                                 return -1;
2487                         }
2488                         memset(launchconditions, '\0', sizeof(launchconditions_x));
2489                         LISTADD(uiapplication->launchconditions, launchconditions);
2490                         ret = __ps_process_launchconditions(reader, launchconditions);
2491                 } else if (!strcmp(ASCII(node), "notification")) {
2492                         notification_x *notification = malloc(sizeof(notification_x));
2493                         if (notification == NULL) {
2494                                 _LOGD("Malloc Failed\n");
2495                                 return -1;
2496                         }
2497                         memset(notification, '\0', sizeof(notification_x));
2498                         LISTADD(uiapplication->notification, notification);
2499                         ret = __ps_process_notification(reader, notification);
2500                 } else
2501                         return -1;
2502                 if (ret < 0) {
2503                         _LOGD("Processing uiapplication failed\n");
2504                         return ret;
2505                 }
2506         }
2507
2508         if (uiapplication->label) {
2509                 LISTHEAD(uiapplication->label, tmp1);
2510                 uiapplication->label = tmp1;
2511         }
2512         if (uiapplication->icon) {
2513                 LISTHEAD(uiapplication->icon, tmp2);
2514                 uiapplication->icon = tmp2;
2515         }
2516         if (uiapplication->appsvc) {
2517                 LISTHEAD(uiapplication->appsvc, tmp3);
2518                 uiapplication->appsvc = tmp3;
2519         }
2520         if (uiapplication->appcontrol) {
2521                 LISTHEAD(uiapplication->appcontrol, tmp4);
2522                 uiapplication->appcontrol = tmp4;
2523         }
2524         if (uiapplication->launchconditions) {
2525                 LISTHEAD(uiapplication->launchconditions, tmp5);
2526                 uiapplication->launchconditions = tmp5;
2527         }
2528         if (uiapplication->notification) {
2529                 LISTHEAD(uiapplication->notification, tmp6);
2530                 uiapplication->notification = tmp6;
2531         }
2532         if (uiapplication->datashare) {
2533                 LISTHEAD(uiapplication->datashare, tmp7);
2534                 uiapplication->datashare = tmp7;
2535         }
2536         if (uiapplication->category) {
2537                 LISTHEAD(uiapplication->category, tmp8);
2538                 uiapplication->category = tmp8;
2539         }
2540         if (uiapplication->metadata) {
2541                 LISTHEAD(uiapplication->metadata, tmp9);
2542                 uiapplication->metadata = tmp9;
2543         }
2544         if (uiapplication->image) {
2545                 LISTHEAD(uiapplication->image, tmp10);
2546                 uiapplication->image = tmp10;
2547         }
2548         if (uiapplication->permission) {
2549                 LISTHEAD(uiapplication->permission, tmp11);
2550                 uiapplication->permission = tmp11;
2551         }
2552
2553         return ret;
2554 }
2555
2556 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication)
2557 {
2558         const xmlChar *node;
2559         int ret = -1;
2560         int depth = -1;
2561         char *newappid = NULL;
2562         label_x *tmp1 = NULL;
2563         icon_x *tmp2 = NULL;
2564         appsvc_x *tmp3 = NULL;
2565         appcontrol_x *tmp4 = NULL;
2566         datacontrol_x *tmp5 = NULL;
2567         launchconditions_x *tmp6 = NULL;
2568         notification_x *tmp7 = NULL;
2569         datashare_x *tmp8 = NULL;
2570         category_x *tmp9 = NULL;
2571         metadata_x *tmp10 = NULL;
2572         permission_x *tmp11 = NULL;
2573
2574         if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
2575                 serviceapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
2576                 if (serviceapplication->appid == NULL) {
2577                         _LOGD("appid cant be NULL\n");
2578                         return -1;
2579                 }
2580         } else {
2581                 _LOGD("appid is mandatory\n");
2582                 return -1;
2583         }
2584         /*check appid*/
2585         ret = __validate_appid(package, serviceapplication->appid, &newappid);
2586         if (ret == -1) {
2587                 _LOGD("appid is not proper\n");
2588                 return -1;
2589         } else {
2590                 if (newappid) {
2591                         if (serviceapplication->appid)
2592                                 free((void *)serviceapplication->appid);
2593                         serviceapplication->appid = newappid;
2594                 }
2595         }
2596         if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
2597                 serviceapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
2598         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
2599                 serviceapplication->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
2600         if (xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot"))) {
2601                 serviceapplication->onboot = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot")));
2602                 if (serviceapplication->onboot == NULL)
2603                         serviceapplication->onboot = strdup("false");
2604         } else {
2605                 serviceapplication->onboot = strdup("false");
2606         }
2607         if (xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart"))) {
2608                 serviceapplication->autorestart = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart")));
2609                 if (serviceapplication->autorestart == NULL)
2610                         serviceapplication->autorestart = strdup("false");
2611         } else {
2612                 serviceapplication->autorestart = strdup("false");
2613         }
2614         if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
2615                 serviceapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
2616                 if (serviceapplication->permission_type == NULL)
2617                         serviceapplication->permission_type = strdup("normal");
2618         } else {
2619                 serviceapplication->permission_type = strdup("normal");
2620         }
2621
2622         depth = xmlTextReaderDepth(reader);
2623         while ((ret = __next_child_element(reader, depth))) {
2624                 node = xmlTextReaderConstName(reader);
2625                 if (!node) {
2626                         _LOGD("xmlTextReaderConstName value is NULL\n");
2627                         return -1;
2628                 }
2629
2630                 if (!strcmp(ASCII(node), "label")) {
2631                         label_x *label = malloc(sizeof(label_x));
2632                         if (label == NULL) {
2633                                 _LOGD("Malloc Failed\n");
2634                                 return -1;
2635                         }
2636                         memset(label, '\0', sizeof(label_x));
2637                         LISTADD(serviceapplication->label, label);
2638                         ret = __ps_process_label(reader, label);
2639                 } else if (!strcmp(ASCII(node), "icon")) {
2640                         icon_x *icon = malloc(sizeof(icon_x));
2641                         if (icon == NULL) {
2642                                 _LOGD("Malloc Failed\n");
2643                                 return -1;
2644                         }
2645                         memset(icon, '\0', sizeof(icon_x));
2646                         LISTADD(serviceapplication->icon, icon);
2647                         ret = __ps_process_icon(reader, icon);
2648                 } else if (!strcmp(ASCII(node), "category")) {
2649                         category_x *category = malloc(sizeof(category_x));
2650                         if (category == NULL) {
2651                                 _LOGD("Malloc Failed\n");
2652                                 return -1;
2653                         }
2654                         memset(category, '\0', sizeof(category_x));
2655                         LISTADD(serviceapplication->category, category);
2656                         ret = __ps_process_category(reader, category);
2657                 } else if (!strcmp(ASCII(node), "metadata")) {
2658                         metadata_x *metadata = malloc(sizeof(metadata_x));
2659                         if (metadata == NULL) {
2660                                 _LOGD("Malloc Failed\n");
2661                                 return -1;
2662                         }
2663                         memset(metadata, '\0', sizeof(metadata_x));
2664                         LISTADD(serviceapplication->metadata, metadata);
2665                         ret = __ps_process_metadata(reader, metadata);
2666                 } else if (!strcmp(ASCII(node), "permission")) {
2667                         permission_x *permission = malloc(sizeof(permission_x));
2668                         if (permission == NULL) {
2669                                 _LOGD("Malloc Failed\n");
2670                                 return -1;
2671                         }
2672                         memset(permission, '\0', sizeof(permission_x));
2673                         LISTADD(serviceapplication->permission, permission);
2674                         ret = __ps_process_permission(reader, permission);
2675                 } else if (!strcmp(ASCII(node), "app-control")) {
2676                         appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
2677                         if (appcontrol == NULL) {
2678                                 _LOGD("Malloc Failed\n");
2679                                 return -1;
2680                         }
2681                         memset(appcontrol, '\0', sizeof(appcontrol_x));
2682                         LISTADD(serviceapplication->appcontrol, appcontrol);
2683                         ret = __ps_process_appcontrol(reader, appcontrol);
2684                 } else if (!strcmp(ASCII(node), "application-service")) {
2685                         appsvc_x *appsvc = malloc(sizeof(appsvc_x));
2686                         if (appsvc == NULL) {
2687                                 _LOGD("Malloc Failed\n");
2688                                 return -1;
2689                         }
2690                         memset(appsvc, '\0', sizeof(appsvc_x));
2691                         LISTADD(serviceapplication->appsvc, appsvc);
2692                         ret = __ps_process_appsvc(reader, appsvc);
2693                 } else if (!strcmp(ASCII(node), "data-share")) {
2694                         datashare_x *datashare = malloc(sizeof(datashare_x));
2695                         if (datashare == NULL) {
2696                                 _LOGD("Malloc Failed\n");
2697                                 return -1;
2698                         }
2699                         memset(datashare, '\0', sizeof(datashare_x));
2700                         LISTADD(serviceapplication->datashare, datashare);
2701                         ret = __ps_process_datashare(reader, datashare);
2702                 } else if (!strcmp(ASCII(node), "launch-conditions")) {
2703                         launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
2704                         if (launchconditions == NULL) {
2705                                 _LOGD("Malloc Failed\n");
2706                                 return -1;
2707                         }
2708                         memset(launchconditions, '\0', sizeof(launchconditions_x));
2709                         LISTADD(serviceapplication->launchconditions, launchconditions);
2710                         ret = __ps_process_launchconditions(reader, launchconditions);
2711                 } else if (!strcmp(ASCII(node), "notification")) {
2712                         notification_x *notification = malloc(sizeof(notification_x));
2713                         if (notification == NULL) {
2714                                 _LOGD("Malloc Failed\n");
2715                                 return -1;
2716                         }
2717                         memset(notification, '\0', sizeof(notification_x));
2718                         LISTADD(serviceapplication->notification, notification);
2719                         ret = __ps_process_notification(reader, notification);
2720                 } else if (!strcmp(ASCII(node), "data-control")) {
2721                         datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
2722                         if (datacontrol == NULL) {
2723                                 _LOGD("Malloc Failed\n");
2724                                 return -1;
2725                         }
2726                         memset(datacontrol, '\0', sizeof(datacontrol_x));
2727                         LISTADD(serviceapplication->datacontrol, datacontrol);
2728                         ret = __ps_process_datacontrol(reader, datacontrol);
2729                 } else
2730                         return -1;
2731                 if (ret < 0) {
2732                         _LOGD("Processing serviceapplication failed\n");
2733                         return ret;
2734                 }
2735         }
2736
2737         if (serviceapplication->label) {
2738                 LISTHEAD(serviceapplication->label, tmp1);
2739                 serviceapplication->label = tmp1;
2740         }
2741         if (serviceapplication->icon) {
2742                 LISTHEAD(serviceapplication->icon, tmp2);
2743                 serviceapplication->icon = tmp2;
2744         }
2745         if (serviceapplication->appsvc) {
2746                 LISTHEAD(serviceapplication->appsvc, tmp3);
2747                 serviceapplication->appsvc = tmp3;
2748         }
2749         if (serviceapplication->appcontrol) {
2750                 LISTHEAD(serviceapplication->appcontrol, tmp4);
2751                 serviceapplication->appcontrol = tmp4;
2752         }
2753         if (serviceapplication->datacontrol) {
2754                 LISTHEAD(serviceapplication->datacontrol, tmp5);
2755                 serviceapplication->datacontrol = tmp5;
2756         }
2757         if (serviceapplication->launchconditions) {
2758                 LISTHEAD(serviceapplication->launchconditions, tmp6);
2759                 serviceapplication->launchconditions = tmp6;
2760         }
2761         if (serviceapplication->notification) {
2762                 LISTHEAD(serviceapplication->notification, tmp7);
2763                 serviceapplication->notification = tmp7;
2764         }
2765         if (serviceapplication->datashare) {
2766                 LISTHEAD(serviceapplication->datashare, tmp8);
2767                 serviceapplication->datashare = tmp8;
2768         }
2769         if (serviceapplication->category) {
2770                 LISTHEAD(serviceapplication->category, tmp9);
2771                 serviceapplication->category = tmp9;
2772         }
2773         if (serviceapplication->metadata) {
2774                 LISTHEAD(serviceapplication->metadata, tmp10);
2775                 serviceapplication->metadata = tmp10;
2776         }
2777         if (serviceapplication->permission) {
2778                 LISTHEAD(serviceapplication->permission, tmp11);
2779                 serviceapplication->permission = tmp11;
2780         }
2781
2782         return ret;
2783 }
2784
2785 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
2786 {
2787         /*TODO: once policy is set*/
2788         return 0;
2789 }
2790
2791 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
2792 {
2793         /*TODO: once policy is set*/
2794         return 0;
2795 }
2796
2797 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
2798 {
2799         /*TODO: once policy is set*/
2800         return 0;
2801 }
2802
2803 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
2804 {
2805         /*TODO: once policy is set*/
2806         return 0;
2807 }
2808
2809 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
2810 {
2811         /*TODO: once policy is set*/
2812         return 0;
2813 }
2814
2815 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
2816 {
2817         _LOGD("__start_process\n");
2818         const xmlChar *node;
2819         int ret = -1;
2820         int depth = -1;
2821         label_x *tmp1 = NULL;
2822         author_x *tmp2 = NULL;
2823         description_x *tmp3 = NULL;
2824         license_x *tmp4 = NULL;
2825         uiapplication_x *tmp5 = NULL;
2826         serviceapplication_x *tmp6 = NULL;
2827         daemon_x *tmp7 = NULL;
2828         theme_x *tmp8 = NULL;
2829         font_x *tmp9 = NULL;
2830         ime_x *tmp10 = NULL;
2831         icon_x *tmp11 = NULL;
2832         compatibility_x *tmp12 = NULL;
2833         deviceprofile_x *tmp13 = NULL;
2834         privileges_x *tmp14 = NULL;
2835
2836         depth = xmlTextReaderDepth(reader);
2837         while ((ret = __next_child_element(reader, depth))) {
2838                 node = xmlTextReaderConstName(reader);
2839                 if (!node) {
2840                         _LOGD("xmlTextReaderConstName value is NULL\n");
2841                         return -1;
2842                 }
2843
2844                 if (!strcmp(ASCII(node), "label")) {
2845                         label_x *label = malloc(sizeof(label_x));
2846                         if (label == NULL) {
2847                                 _LOGD("Malloc Failed\n");
2848                                 return -1;
2849                         }
2850                         memset(label, '\0', sizeof(label_x));
2851                         LISTADD(mfx->label, label);
2852                         ret = __ps_process_label(reader, label);
2853                 } else if (!strcmp(ASCII(node), "author")) {
2854                         author_x *author = malloc(sizeof(author_x));
2855                         if (author == NULL) {
2856                                 _LOGD("Malloc Failed\n");
2857                                 return -1;
2858                         }
2859                         memset(author, '\0', sizeof(author_x));
2860                         LISTADD(mfx->author, author);
2861                         ret = __ps_process_author(reader, author);
2862                 } else if (!strcmp(ASCII(node), "description")) {
2863                         description_x *description = malloc(sizeof(description_x));
2864                         if (description == NULL) {
2865                                 _LOGD("Malloc Failed\n");
2866                                 return -1;
2867                         }
2868                         memset(description, '\0', sizeof(description_x));
2869                         LISTADD(mfx->description, description);
2870                         ret = __ps_process_description(reader, description);
2871                 } else if (!strcmp(ASCII(node), "license")) {
2872                         license_x *license = malloc(sizeof(license_x));
2873                         if (license == NULL) {
2874                                 _LOGD("Malloc Failed\n");
2875                                 return -1;
2876                         }
2877                         memset(license, '\0', sizeof(license_x));
2878                         LISTADD(mfx->license, license);
2879                         ret = __ps_process_license(reader, license);
2880                 } else if (!strcmp(ASCII(node), "privileges")) {
2881                         privileges_x *privileges = malloc(sizeof(privileges_x));
2882                         if (privileges == NULL) {
2883                                 _LOGD("Malloc Failed\n");
2884                                 return -1;
2885                         }
2886                         memset(privileges, '\0', sizeof(privileges_x));
2887                         LISTADD(mfx->privileges, privileges);
2888                         ret = __ps_process_privileges(reader, privileges);
2889                 } else if (!strcmp(ASCII(node), "ui-application")) {
2890                         uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
2891                         if (uiapplication == NULL) {
2892                                 _LOGD("Malloc Failed\n");
2893                                 return -1;
2894                         }
2895                         memset(uiapplication, '\0', sizeof(uiapplication_x));
2896                         LISTADD(mfx->uiapplication, uiapplication);
2897                         ret = __ps_process_uiapplication(reader, uiapplication);
2898                 } else if (!strcmp(ASCII(node), "service-application")) {
2899                         serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
2900                         if (serviceapplication == NULL) {
2901                                 _LOGD("Malloc Failed\n");
2902                                 return -1;
2903                         }
2904                         memset(serviceapplication, '\0', sizeof(serviceapplication_x));
2905                         LISTADD(mfx->serviceapplication, serviceapplication);
2906                         ret = __ps_process_serviceapplication(reader, serviceapplication);
2907                 } else if (!strcmp(ASCII(node), "daemon")) {
2908                         daemon_x *daemon = malloc(sizeof(daemon_x));
2909                         if (daemon == NULL) {
2910                                 _LOGD("Malloc Failed\n");
2911                                 return -1;
2912                         }
2913                         memset(daemon, '\0', sizeof(daemon_x));
2914                         LISTADD(mfx->daemon, daemon);
2915                         ret = __ps_process_daemon(reader, daemon);
2916                 } else if (!strcmp(ASCII(node), "theme")) {
2917                         theme_x *theme = malloc(sizeof(theme_x));
2918                         if (theme == NULL) {
2919                                 _LOGD("Malloc Failed\n");
2920                                 return -1;
2921                         }
2922                         memset(theme, '\0', sizeof(theme_x));
2923                         LISTADD(mfx->theme, theme);
2924                         ret = __ps_process_theme(reader, theme);
2925                 } else if (!strcmp(ASCII(node), "font")) {
2926                         font_x *font = malloc(sizeof(font_x));
2927                         if (font == NULL) {
2928                                 _LOGD("Malloc Failed\n");
2929                                 return -1;
2930                         }
2931                         memset(font, '\0', sizeof(font_x));
2932                         LISTADD(mfx->font, font);
2933                         ret = __ps_process_font(reader, font);
2934                 } else if (!strcmp(ASCII(node), "ime")) {
2935                         ime_x *ime = malloc(sizeof(ime_x));
2936                         if (ime == NULL) {
2937                                 _LOGD("Malloc Failed\n");
2938                                 return -1;
2939                         }
2940                         memset(ime, '\0', sizeof(ime_x));
2941                         LISTADD(mfx->ime, ime);
2942                         ret = __ps_process_ime(reader, ime);
2943                 } else if (!strcmp(ASCII(node), "icon")) {
2944                         icon_x *icon = malloc(sizeof(icon_x));
2945                         if (icon == NULL) {
2946                                 _LOGD("Malloc Failed\n");
2947                                 return -1;
2948                         }
2949                         memset(icon, '\0', sizeof(icon_x));
2950                         LISTADD(mfx->icon, icon);
2951                         ret = __ps_process_icon(reader, icon);
2952                 } else if (!strcmp(ASCII(node), "device-profile")) {
2953                         deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
2954                         if (deviceprofile == NULL) {
2955                                 _LOGD("Malloc Failed\n");
2956                                 return -1;
2957                         }
2958                         memset(deviceprofile, '\0', sizeof(deviceprofile_x));
2959                         LISTADD(mfx->deviceprofile, deviceprofile);
2960                         ret = __ps_process_deviceprofile(reader, deviceprofile);
2961                 } else if (!strcmp(ASCII(node), "compatibility")) {
2962                         compatibility_x *compatibility = malloc(sizeof(compatibility_x));
2963                         if (compatibility == NULL) {
2964                                 _LOGD("Malloc Failed\n");
2965                                 return -1;
2966                         }
2967                         memset(compatibility, '\0', sizeof(compatibility_x));
2968                         LISTADD(mfx->compatibility, compatibility);
2969                         ret = __ps_process_compatibility(reader, compatibility);
2970                 } else if (!strcmp(ASCII(node), "shortcut-list")) {
2971                         continue;
2972                 } else if (!strcmp(ASCII(node), "livebox")) {
2973                         continue;
2974                 } else if (!strcmp(ASCII(node), "account")) {
2975                         continue;
2976                 } else if (!strcmp(ASCII(node), "notifications")) {
2977                         continue;
2978                 } else if (!strcmp(ASCII(node), "ime")) {
2979                         continue;
2980                 } else
2981                         return -1;
2982
2983                 if (ret < 0) {
2984                         _LOGD("Processing manifest failed\n");
2985                         return ret;
2986                 }
2987         }
2988         if (mfx->label) {
2989                 LISTHEAD(mfx->label, tmp1);
2990                 mfx->label = tmp1;
2991         }
2992         if (mfx->author) {
2993                 LISTHEAD(mfx->author, tmp2);
2994                 mfx->author = tmp2;
2995         }
2996         if (mfx->description) {
2997                 LISTHEAD(mfx->description, tmp3);
2998                 mfx->description= tmp3;
2999         }
3000         if (mfx->license) {
3001                 LISTHEAD(mfx->license, tmp4);
3002                 mfx->license= tmp4;
3003         }
3004         if (mfx->uiapplication) {
3005                 LISTHEAD(mfx->uiapplication, tmp5);
3006                 mfx->uiapplication = tmp5;
3007         }
3008         if (mfx->serviceapplication) {
3009                 LISTHEAD(mfx->serviceapplication, tmp6);
3010                 mfx->serviceapplication = tmp6;
3011         }
3012         if (mfx->daemon) {
3013                 LISTHEAD(mfx->daemon, tmp7);
3014                 mfx->daemon= tmp7;
3015         }
3016         if (mfx->theme) {
3017                 LISTHEAD(mfx->theme, tmp8);
3018                 mfx->theme= tmp8;
3019         }
3020         if (mfx->font) {
3021                 LISTHEAD(mfx->font, tmp9);
3022                 mfx->font= tmp9;
3023         }
3024         if (mfx->ime) {
3025                 LISTHEAD(mfx->ime, tmp10);
3026                 mfx->ime= tmp10;
3027         }
3028         if (mfx->icon) {
3029                 LISTHEAD(mfx->icon, tmp11);
3030                 mfx->icon= tmp11;
3031         }
3032         if (mfx->compatibility) {
3033                 LISTHEAD(mfx->compatibility, tmp12);
3034                 mfx->compatibility= tmp12;
3035         }
3036         if (mfx->deviceprofile) {
3037                 LISTHEAD(mfx->deviceprofile, tmp13);
3038                 mfx->deviceprofile= tmp13;
3039         }
3040         if (mfx->privileges) {
3041                 LISTHEAD(mfx->privileges, tmp14);
3042                 mfx->privileges = tmp14;
3043         }
3044         return ret;
3045 }
3046
3047 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
3048 {
3049         const xmlChar *node;
3050         int ret = -1;
3051
3052         if ((ret = __next_child_element(reader, -1))) {
3053                 node = xmlTextReaderConstName(reader);
3054                 if (!node) {
3055                         _LOGD("xmlTextReaderConstName value is NULL\n");
3056                         return -1;
3057                 }
3058
3059                 if (!strcmp(ASCII(node), "manifest")) {
3060                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")))
3061                                 mfx->ns = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")));
3062                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("package"))) {
3063                                 mfx->package= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("package")));
3064                                 if (mfx->package == NULL) {
3065                                         _LOGD("package cant be NULL\n");
3066                                         return -1;
3067                                 }
3068                         } else {
3069                                 _LOGD("package field is mandatory\n");
3070                                 return -1;
3071                         }
3072                         package = mfx->package;
3073                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("version")))
3074                                 mfx->version= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("version")));
3075                         /*app2ext needs package size for external installation*/
3076                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("size")))
3077                                 mfx->package_size = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("size")));
3078                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("install-location"))) {
3079                                 mfx->installlocation = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("install-location")));
3080                                 if (mfx->installlocation == NULL)
3081                                         mfx->installlocation = strdup("internal-only");
3082                         } else {
3083                                 mfx->installlocation = strdup("internal-only");
3084                         }
3085                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
3086                                 mfx->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
3087                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")))
3088                                 mfx->root_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")));
3089                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")))
3090                                 mfx->csc_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")));
3091                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting"))) {
3092                                 mfx->appsetting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting")));
3093                                 if (mfx->appsetting == NULL)
3094                                         mfx->appsetting = strdup("false");
3095                         } else {
3096                                 mfx->appsetting = strdup("false");
3097                         }
3098                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")))
3099                                 mfx->storeclient_id= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")));
3100                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting"))) {
3101                                 mfx->nodisplay_setting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting")));
3102                                 if (mfx->nodisplay_setting == NULL)
3103                                         mfx->nodisplay_setting = strdup("false");
3104                         } else {
3105                                 mfx->nodisplay_setting = strdup("false");
3106                         }
3107                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("url")))
3108                                 mfx->package_url= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("url")));
3109
3110                         /*Assign default values. If required it will be overwritten in __add_preload_info()*/
3111                         mfx->preload = strdup("False");
3112                         mfx->removable = strdup("True");
3113                         mfx->readonly = strdup("False");
3114                         mfx->update = strdup("False");
3115                         mfx->system = strdup("False");
3116                         char buf[PKG_STRING_LEN_MAX] = {'\0'};
3117                         char *val = NULL;
3118                         time_t current_time;
3119                         time(&current_time);
3120                         snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
3121                         val = strndup(buf, PKG_STRING_LEN_MAX - 1);
3122                         mfx->installed_time = val;
3123
3124                         mfx->installed_storage= strdup("installed_internal");
3125
3126                         ret = __start_process(reader, mfx);
3127                 } else {
3128                         _LOGD("No Manifest element found\n");
3129                         return -1;
3130                 }
3131         }
3132         return ret;
3133 }
3134
3135
3136 static char* __convert_to_system_locale(const char *mlocale)
3137 {
3138         if (mlocale == NULL)
3139                 return NULL;
3140         char *locale = NULL;
3141         locale = (char *)calloc(1, 6);
3142         if (!locale) {
3143                 _LOGE("Malloc Failed\n");
3144                 return NULL;
3145         }
3146
3147         strncpy(locale, mlocale, 2);
3148         strncat(locale, "_", 1);
3149         locale[3] = toupper(mlocale[3]);
3150         locale[4] = toupper(mlocale[4]);
3151         return locale;
3152 }
3153
3154 static int __ail_change_info(int op, const char *appid)
3155 {
3156         void *lib_handle = NULL;
3157         int (*ail_desktop_operation) (const char *);
3158         char *aop = NULL;
3159         int ret = 0;
3160
3161         if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
3162                 _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
3163                 goto END;
3164         }
3165
3166
3167         switch (op) {
3168                 case 0:
3169                         aop  = "ail_desktop_add";
3170                         break;
3171                 case 1:
3172                         aop  = "ail_desktop_update";
3173                         break;
3174                 case 2:
3175                         aop  = "ail_desktop_remove";
3176                         break;
3177                 case 3:
3178                         aop  = "ail_desktop_clean";
3179                         break;
3180                 case 4:
3181                         aop  = "ail_desktop_fota";
3182                         break;
3183                 default:
3184                         goto END;
3185                         break;
3186         }
3187
3188         if ((ail_desktop_operation =
3189              dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
3190                 _LOGE("can not find symbol \n");
3191                 goto END;
3192         }
3193
3194         ret = ail_desktop_operation(appid);
3195
3196 END:
3197         if (lib_handle)
3198                 dlclose(lib_handle);
3199
3200         return ret;
3201 }
3202
3203
3204 /* desktop shoud be generated automatically based on manifest */
3205 /* Currently removable, taskmanage, etc fields are not considerd. it will be decided soon.*/
3206 static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, ACTION_TYPE action)
3207 {
3208         FILE* file = NULL;
3209         int fd = 0;
3210         char filepath[PKG_STRING_LEN_MAX] = "";
3211         char *buf = NULL;
3212         char *buftemp = NULL;
3213         char *locale = NULL;
3214
3215         buf = (char *)calloc(1, BUFMAX);
3216         if (!buf) {
3217                 _LOGE("Malloc Failed\n");
3218                 return -1;
3219         }
3220
3221         buftemp = (char *)calloc(1, BUFMAX);
3222         if (!buftemp) {
3223                 _LOGE("Malloc Failed\n");
3224                 free(buf);
3225                 return -1;
3226         }
3227
3228         if (action == ACTION_UPGRADE)
3229                 __ail_change_info(AIL_CLEAN, mfx->package);
3230
3231         for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
3232
3233                 if (manifest != NULL) {
3234                         /* skip making a deskfile and update ail, if preload app is updated */
3235                         if(strstr(manifest, MANIFEST_RO_PREFIX)) {
3236                                 __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
3237                     _LOGE("preload app is update : skip and update ail : %s", manifest);
3238                                 continue;
3239                         }
3240                 }
3241
3242                 if(mfx->readonly && !strcasecmp(mfx->readonly, "True"))
3243                         snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RO_PATH, mfx->uiapplication->appid);
3244                 else
3245                         snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, mfx->uiapplication->appid);
3246
3247                 /* skip if desktop exists
3248                 if (access(filepath, R_OK) == 0)
3249                         continue;
3250                 */
3251
3252                 file = fopen(filepath, "w");
3253                 if(file == NULL)
3254                 {
3255                     _LOGS("Can't open %s", filepath);
3256                     free(buf);
3257                     free(buftemp);
3258                     return -1;
3259                 }
3260
3261                 snprintf(buf, BUFMAX, "[Desktop Entry]\n");
3262                 fwrite(buf, 1, strlen(buf), file);
3263
3264                 for( ; mfx->uiapplication->label ; mfx->uiapplication->label = mfx->uiapplication->label->next) {
3265                         if(!strcmp(mfx->uiapplication->label->lang, DEFAULT_LOCALE)) {
3266                                 snprintf(buf, BUFMAX, "Name=%s\n",      mfx->uiapplication->label->text);
3267                         } else {
3268                                 locale = __convert_to_system_locale(mfx->uiapplication->label->lang);
3269                                 snprintf(buf, BUFMAX, "Name[%s]=%s\n", locale,
3270                                         mfx->uiapplication->label->text);
3271                                 free(locale);
3272                         }
3273                         fwrite(buf, 1, strlen(buf), file);
3274                 }
3275
3276                 if(mfx->uiapplication->label && mfx->uiapplication->label->text) {
3277                         snprintf(buf, BUFMAX, "Name=%s\n", mfx->uiapplication->label->text);
3278                         fwrite(buf, 1, strlen(buf), file);
3279                 }
3280 /*
3281                 else if(mfx->label && mfx->label->text) {
3282                         snprintf(buf, BUFMAX, "Name=%s\n", mfx->label->text);
3283                         fwrite(buf, 1, strlen(buf), file);
3284                 } else {
3285                         snprintf(buf, BUFMAX, "Name=%s\n", mfx->package);
3286                         fwrite(buf, 1, strlen(buf), file);
3287                 }
3288 */
3289
3290
3291                 snprintf(buf, BUFMAX, "Type=Application\n");
3292                 fwrite(buf, 1, strlen(buf), file);
3293
3294                 if(mfx->uiapplication->exec) {
3295                         snprintf(buf, BUFMAX, "Exec=%s\n", mfx->uiapplication->exec);
3296                         fwrite(buf, 1, strlen(buf), file);
3297                 }
3298
3299                 if(mfx->uiapplication->icon && mfx->uiapplication->icon->text) {
3300                         snprintf(buf, BUFMAX, "Icon=%s\n", mfx->uiapplication->icon->text);
3301                         fwrite(buf, 1, strlen(buf), file);
3302                 } else if(mfx->icon && mfx->icon->text) {
3303                         snprintf(buf, BUFMAX, "Icon=%s\n", mfx->icon->text);
3304                         fwrite(buf, 1, strlen(buf), file);
3305                 }
3306
3307                 // MIME types
3308                 if(mfx->uiapplication && mfx->uiapplication->appsvc) {
3309                         appsvc_x *asvc = mfx->uiapplication->appsvc;
3310                         mime_x *mi = NULL;
3311                         const char *mime = NULL;
3312                         const char *mime_delim = "; ";
3313                         int mime_count = 0;
3314
3315                         strncpy(buf, "MimeType=", BUFMAX-1);
3316                         while (asvc) {
3317                                 mi = asvc->mime;
3318                                 while (mi) {
3319                                         mime_count++;
3320                                         mime = mi->name;
3321                                         _LOGD("MIME type: %s\n", mime);
3322                                         strncat(buf, mime, BUFMAX-strlen(buf)-1);
3323                                         if(mi->next) {
3324                                                 strncat(buf, mime_delim, BUFMAX-strlen(buf)-1);
3325                                         }
3326
3327                                         mi = mi->next;
3328                                         mime = NULL;
3329                                 }
3330                                 asvc = asvc->next;
3331                         }
3332                         _LOGD("MIME types: buf[%s]\n", buf);
3333                         _LOGD("MIME count: %d\n", mime_count);
3334                         if(mime_count)
3335                                 fwrite(buf, 1, strlen(buf), file);
3336                 }
3337
3338                 if(mfx->version) {
3339                         snprintf(buf, BUFMAX, "Version=%s\n", mfx->version);
3340                         fwrite(buf, 1, strlen(buf), file);
3341                 }
3342
3343                 if(mfx->uiapplication->nodisplay) {
3344                         snprintf(buf, BUFMAX, "NoDisplay=%s\n", mfx->uiapplication->nodisplay);
3345                         fwrite(buf, 1, strlen(buf), file);
3346                 }
3347
3348                 if(mfx->uiapplication->categories) {
3349                         snprintf(buf, BUFMAX, "Categories=%s\n", mfx->uiapplication->categories);
3350                         fwrite(buf, 1, strlen(buf), file);
3351                 }
3352
3353                 if(mfx->uiapplication->taskmanage && !strcasecmp(mfx->uiapplication->taskmanage, "False")) {
3354                         snprintf(buf, BUFMAX, "X-TIZEN-TaskManage=False\n");
3355                         fwrite(buf, 1, strlen(buf), file);
3356                 }
3357
3358                 if(mfx->uiapplication->enabled && !strcasecmp(mfx->uiapplication->enabled, "False")) {
3359                         snprintf(buf, BUFMAX, "X-TIZEN-Enabled=False\n");
3360                         fwrite(buf, 1, strlen(buf), file);
3361                 }
3362
3363                 if(mfx->uiapplication->hwacceleration) {
3364                         snprintf(buf, BUFMAX, "Hw-Acceleration=%s\n", mfx->uiapplication->hwacceleration);
3365                         fwrite(buf, 1, strlen(buf), file);
3366                 }
3367
3368                 if(mfx->uiapplication->multiple && !strcasecmp(mfx->uiapplication->multiple, "True")) {
3369                         snprintf(buf, BUFMAX, "X-TIZEN-Multiple=True\n");
3370                         fwrite(buf, 1, strlen(buf), file);
3371                 }
3372
3373                 if(mfx->uiapplication->extraid) {
3374                         snprintf(buf, BUFMAX, "X-TIZEN-PackageID=%s\n", mfx->uiapplication->extraid);
3375                         fwrite(buf, 1, strlen(buf), file);
3376                 }
3377
3378                 if(mfx->removable && !strcasecmp(mfx->removable, "False")) {
3379                         snprintf(buf, BUFMAX, "X-TIZEN-Removable=False\n");
3380                         fwrite(buf, 1, strlen(buf), file);
3381                 }
3382
3383                 if(mfx->type) {
3384                         snprintf(buf, BUFMAX, "X-TIZEN-PackageType=%s\n", mfx->type);
3385                         fwrite(buf, 1, strlen(buf), file);
3386                 }
3387
3388                 if(mfx->uiapplication->submode && !strcasecmp(mfx->uiapplication->submode, "True")) {
3389                         snprintf(buf, BUFMAX, "X-TIZEN-Submode=%s\n", mfx->uiapplication->submode);
3390                         fwrite(buf, 1, strlen(buf), file);
3391                         snprintf(buf, BUFMAX, "X-TIZEN-SubmodeMainid=%s\n", mfx->uiapplication->submode_mainid);
3392                         fwrite(buf, 1, strlen(buf), file);
3393                 }
3394
3395                 snprintf(buf, BUFMAX, "X-TIZEN-PkgID=%s\n", mfx->package);
3396                 fwrite(buf, 1, strlen(buf), file);
3397
3398
3399                 snprintf(buf, BUFMAX, "X-TIZEN-InstalledStorage=%s\n", mfx->installed_storage);
3400                 fwrite(buf, 1, strlen(buf), file);
3401
3402 //              snprintf(buf, BUFMAX, "X-TIZEN-PackageType=rpm\n");
3403 //              fwrite(buf, 1, strlen(buf), file);
3404
3405
3406                 if(mfx->uiapplication->appsvc) {
3407                         snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
3408                         _LOGD("buf[%s]\n", buf);
3409
3410
3411                         uiapplication_x *up = mfx->uiapplication;
3412                         appsvc_x *asvc = NULL;
3413                         operation_x *op = NULL;
3414                         mime_x *mi = NULL;
3415                         uri_x *ui = NULL;
3416                         subapp_x *sub = NULL;
3417                         const char *operation = NULL;
3418                         const char *mime = NULL;
3419                         const char *uri = NULL;
3420                         const char *subapp = NULL;
3421                         int i = 0;
3422
3423
3424                         asvc = up->appsvc;
3425                         while(asvc != NULL) {
3426                                 op = asvc->operation;
3427                                 while(op != NULL) {
3428                                         if (op)
3429                                                 operation = op->name;
3430                                         mi = asvc->mime;
3431
3432                                         do
3433                                         {
3434                                                 if (mi)
3435                                                         mime = mi->name;
3436                                                 sub = asvc->subapp;
3437                                                 do
3438                                                 {
3439                                                         if (sub)
3440                                                                 subapp = sub->name;
3441                                                         ui = asvc->uri;
3442                                                         do
3443                                                         {
3444                                                                 if (ui)
3445                                                                         uri = ui->name;
3446
3447                                                                 if(i++ > 0) {
3448                                                                         strncpy(buftemp, buf, BUFMAX);
3449                                                                         snprintf(buf, BUFMAX, "%s;", buftemp);
3450                                                                 }
3451
3452
3453                                                                 strncpy(buftemp, buf, BUFMAX);
3454                                                                 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
3455                                                                 _LOGD("buf[%s]\n", buf);
3456
3457                                                                 if (ui)
3458                                                                         ui = ui->next;
3459                                                                 uri = NULL;
3460                                                         } while(ui != NULL);
3461                                                 if (sub)
3462                                                                 sub = sub->next;
3463                                                         subapp = NULL;
3464                                                 }while(sub != NULL);
3465                                                 if (mi)
3466                                                         mi = mi->next;
3467                                                 mime = NULL;
3468                                         }while(mi != NULL);
3469                                         if (op)
3470                                                 op = op->next;
3471                                         operation = NULL;
3472                                 }
3473                                 asvc = asvc->next;
3474                         }
3475
3476
3477                         fwrite(buf, 1, strlen(buf), file);
3478
3479 //                      strncpy(buftemp, buf, BUFMAX);
3480 //                      snprintf(buf, BUFMAX, "%s\n", buftemp);
3481 //                      fwrite(buf, 1, strlen(buf), file);
3482                 }
3483
3484                 if(mfx->uiapplication->appcontrol) {
3485                         snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
3486                         _LOGD("buf[%s]\n", buf);
3487
3488                         uiapplication_x *up = mfx->uiapplication;
3489                         appcontrol_x *acontrol = NULL;
3490                         operation_x *op = NULL;
3491                         mime_x *mi = NULL;
3492                         uri_x *ui = NULL;
3493                         subapp_x *sub = NULL;
3494                         const char *operation = NULL;
3495                         const char *mime = NULL;
3496                         const char *uri = NULL;
3497                         const char *subapp = NULL;
3498                         int i = 0;
3499
3500                         acontrol = up->appcontrol;
3501                         while(acontrol != NULL) {
3502                                 op = acontrol->operation;
3503                                 while(op != NULL) {
3504                                         if (op)
3505                                                 operation = op->name;
3506                                         mi = acontrol->mime;
3507
3508                                         do
3509                                         {
3510                                                 if (mi)
3511                                                         mime = mi->name;
3512                                                 sub = acontrol->subapp;
3513                                                 do
3514                                                 {
3515                                                         if (sub)
3516                                                                 subapp = sub->name;
3517                                                         ui = acontrol->uri;
3518                                                         do
3519                                                         {
3520                                                                 if (ui)
3521                                                                         uri = ui->name;
3522
3523                                                                 if(i++ > 0) {
3524                                                                         strncpy(buftemp, buf, BUFMAX);
3525                                                                         snprintf(buf, BUFMAX, "%s;", buftemp);
3526                                                                 }
3527
3528                                                                 strncpy(buftemp, buf, BUFMAX);
3529                                                                 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
3530                                                                 _LOGD("buf[%s]\n", buf);
3531
3532                                                                 if (ui)
3533                                                                         ui = ui->next;
3534                                                                 uri = NULL;
3535                                                         } while(ui != NULL);
3536                                                 if (sub)
3537                                                                 sub = sub->next;
3538                                                         subapp = NULL;
3539                                                 }while(sub != NULL);
3540                                                 if (mi)
3541                                                         mi = mi->next;
3542                                                 mime = NULL;
3543                                         }while(mi != NULL);
3544                                         if (op)
3545                                                 op = op->next;
3546                                         operation = NULL;
3547                                 }
3548                                 acontrol = acontrol->next;
3549                         }
3550
3551
3552                         fwrite(buf, 1, strlen(buf), file);
3553
3554 //                      strncpy(buftemp, buf, BUFMAX);
3555 //                      snprintf(buf, BUFMAX, "%s\n", buftemp);
3556 //                      fwrite(buf, 1, strlen(buf), file);
3557                 }
3558
3559                 fflush(file);
3560                 fd = fileno(file);
3561                 fsync(fd);
3562                 fclose(file);
3563                 if (action == ACTION_FOTA)
3564                         __ail_change_info(AIL_FOTA, mfx->uiapplication->appid);
3565                 else
3566                         __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
3567         }
3568
3569         free(buf);
3570         free(buftemp);
3571
3572         return 0;
3573 }
3574
3575 static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
3576 {
3577         char filepath[PKG_STRING_LEN_MAX] = "";
3578         int ret = 0;
3579         uiapplication_x *uiapplication = mfx->uiapplication;
3580
3581         for(; uiapplication; uiapplication=uiapplication->next) {
3582                 snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
3583
3584                 __ail_change_info(AIL_REMOVE, uiapplication->appid);
3585
3586                 ret = remove(filepath);
3587                 if (ret <0)
3588                         return -1;
3589         }
3590
3591         return 0;
3592 }
3593
3594 static int __add_preload_info(manifest_x * mfx, const char *manifest)
3595 {
3596         FILE *fp = NULL;
3597         char buffer[1024] = { 0 };
3598         int state = 0;
3599
3600         if(strstr(manifest, MANIFEST_RO_PREFIX)) {
3601                 free((void *)mfx->readonly);
3602                 mfx->readonly = strdup("True");
3603
3604                 free((void *)mfx->preload);
3605                 mfx->preload = strdup("True");
3606
3607                 free((void *)mfx->removable);
3608                 mfx->removable = strdup("False");
3609
3610                 free((void *)mfx->system);
3611                 mfx->system = strdup("True");
3612
3613                 return 0;
3614         }
3615
3616         fp = fopen(PRELOAD_PACKAGE_LIST, "r");
3617         if (fp == NULL) {
3618                 _LOGE("no preload list\n");
3619                 return -1;
3620         }
3621
3622         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
3623                 if (buffer[0] == '#') {
3624                         if(strcasestr(buffer, "RW_NORM"))
3625                                 state = 2;
3626                         else if(strcasestr(buffer, "RW_RM"))
3627                                 state = 3;
3628                         else
3629                                 continue;
3630                 }
3631
3632                 __str_trim(buffer);
3633
3634                 if(!strcmp(mfx->package, buffer)) {
3635                         free((void *)mfx->preload);
3636                         mfx->preload = strdup("True");
3637                         if(state == 2){
3638                                 free((void *)mfx->readonly);
3639                                 mfx->readonly = strdup("False");
3640                                 free((void *)mfx->removable);
3641                                 mfx->removable = strdup("False");
3642                         } else if(state == 3){
3643                                 free((void *)mfx->readonly);
3644                                 mfx->readonly = strdup("False");
3645                                 free((void *)mfx->removable);
3646                                 mfx->removable = strdup("True");
3647                         }
3648                 }
3649
3650                 memset(buffer, 0x00, sizeof(buffer));
3651         }
3652
3653         if (fp != NULL)
3654                 fclose(fp);
3655
3656         return 0;
3657 }
3658
3659 static int __check_preload_updated(manifest_x * mfx, const char *manifest)
3660 {
3661         char filepath[PKG_STRING_LEN_MAX] = "";
3662         int ret = 0;
3663         uiapplication_x *uiapplication = mfx->uiapplication;
3664
3665         if(strstr(manifest, MANIFEST_RO_PREFIX)) {
3666                 /* if preload app is updated, then remove previous desktop file on RW*/
3667                 for(; uiapplication; uiapplication=uiapplication->next) {
3668                                 snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
3669                         ret = remove(filepath);
3670                         if (ret <0)
3671                                 return -1;
3672                 }
3673         } else {
3674                 /* if downloaded app is updated, then update tag set true*/
3675                 free((void *)mfx->update);
3676                 mfx->update = strdup("true");
3677         }
3678
3679         return 0;
3680 }
3681
3682 static int __get_appid_list(const char *pkgid, void *user_data)
3683 {
3684         int col = 0;
3685         int cols = 0;
3686         int ret = 0;
3687         char *appid = NULL;
3688
3689         sqlite3_stmt *stmt = NULL;
3690         sqlite3 *pkgmgr_parser_db;
3691
3692         char *query = sqlite3_mprintf("select app_id from package_app_info where package=%Q", pkgid);
3693
3694         ret = sqlite3_open("/opt/dbspace/.pkgmgr_parser.db", &pkgmgr_parser_db);
3695         if (ret != SQLITE_OK) {
3696                 _LOGE("open fail\n");
3697                 sqlite3_free(query);
3698                 return -1;
3699         }
3700         ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
3701         if (ret != SQLITE_OK) {
3702                 _LOGE("prepare_v2 fail\n");
3703                 sqlite3_close(pkgmgr_parser_db);
3704                 sqlite3_free(query);
3705                 return -1;
3706         }
3707
3708         cols = sqlite3_column_count(stmt);
3709         while(1)
3710         {
3711                 ret = sqlite3_step(stmt);
3712                 if(ret == SQLITE_ROW) {
3713                         for(col = 0; col < cols; col++)
3714                         {
3715                                 appid = (char*)sqlite3_column_text(stmt, col);
3716                                 _LOGS("success find appid[%s]\n", appid);
3717                                 (*(GList**)user_data) = g_list_append((*(GList**)user_data), g_strdup(appid));
3718                         }
3719                         ret = 0;
3720                 } else {
3721                         break;
3722                 }
3723         }
3724         sqlite3_finalize(stmt);
3725         sqlite3_close(pkgmgr_parser_db);
3726         sqlite3_free(query);
3727         return ret;
3728 }
3729
3730 void __call_uninstall_plugin(const char *pkgid, GList *appid_list)
3731 {
3732         char *appid = NULL;
3733         GList *tmp_list;
3734
3735         if (pkgid == NULL) {
3736                 _LOGD("pkgid is null\n");
3737                 return;
3738         }
3739
3740         tmp_list = appid_list;
3741         _pkgmgr_parser_plugin_open_db();
3742
3743         _pkgmgr_parser_plugin_uninstall_plugin(PKGMGR_PARSER_PLUGIN_TAG, pkgid, pkgid);
3744
3745         while (tmp_list) {
3746                 appid = (char *)tmp_list->data;
3747                 if (appid) {
3748                         _pkgmgr_parser_plugin_uninstall_plugin(PKGMGR_PARSER_PLUGIN_METADATA, pkgid, appid);
3749                         _pkgmgr_parser_plugin_uninstall_plugin(PKGMGR_PARSER_PLUGIN_CATEGORY, pkgid, appid);
3750                 }
3751                 tmp_list = g_list_next(tmp_list);
3752         }
3753
3754         _pkgmgr_parser_plugin_close_db();
3755 }
3756
3757 static int __delete_pkgid_info_for_uninstallation(const char *pkgid)
3758 {
3759         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3760
3761         int ret = -1;
3762         char *appid = NULL;
3763         GList *appid_list = NULL;
3764         char filepath[PKG_STRING_LEN_MAX] = "";
3765
3766         _LOGD("Start uninstall for pkgid : delete pkgid[%s]\n", pkgid);
3767
3768         /*get appid list*/
3769         ret = __get_appid_list(pkgid, &appid_list);
3770         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get app_list");
3771
3772         _LOGD("call plugin uninstall\n");
3773
3774         /*call plugin uninstall*/
3775         __call_uninstall_plugin(pkgid, appid_list);
3776
3777         /* delete pkgmgr db */
3778         ret = pkgmgr_parser_delete_pkgid_info_from_db(pkgid);
3779         if (ret == -1)
3780                 _LOGD("DB pkgid info Delete failed\n");
3781         else
3782                 _LOGD("DB pkgid info Delete Success\n");
3783
3784         /* delete desktop file*/
3785         while (appid_list) {
3786                 appid = (char *)appid_list->data;
3787                 if (appid) {
3788                         _LOGD("Delete appid[%s] info from db\n", appid);
3789
3790                         ret = pkgmgr_parser_delete_appid_info_from_db(appid);
3791                         if (ret == -1)
3792                                 _LOGD("DB appid info Delete failed\n");
3793                         else
3794                                 _LOGD("DB appid info Delete Success\n");
3795
3796                         ret = __ail_change_info(AIL_REMOVE, appid);
3797                         if (ret < 0)
3798                                 _LOGD("AIL_REMOVE failed\n");
3799
3800                         snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, appid);
3801                         if (access(filepath, R_OK) == 0) {
3802                                 ret = remove(filepath);
3803                                 if (ret < 0)
3804                                         _LOGD("remove failed\n");
3805                         }
3806                 }
3807                 appid_list = g_list_next(appid_list);
3808         }
3809
3810         g_list_free(appid_list);
3811
3812         _LOGD("Finish : uninstall for pkgid\n");
3813
3814         return PMINFO_R_OK;
3815 }
3816
3817 API int pkgmgr_parser_check_mdm_policy_for_uninstallation(const char *manifest)
3818 {
3819         int ret = PMINFO_R_OK;
3820         manifest_x *mfx = NULL;
3821
3822         mfx = pkgmgr_parser_process_manifest_xml(manifest);
3823         retvm_if(mfx == NULL, PMINFO_R_OK, "argument supplied is NULL");
3824
3825         ret = __ps_check_mdm_policy(mfx, ACTION_UNINSTALL);
3826         if (ret < 0)
3827                 _LOGE("pkg[%s] violate mdm policy.", mfx->package);
3828
3829         pkgmgr_parser_free_manifest_xml(mfx);
3830
3831         return ret;
3832 }
3833
3834 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
3835 {
3836         int ret = 0;
3837         if (mfx == NULL) {
3838                 _LOGD("Manifest pointer is NULL\n");
3839                 return -1;
3840         }
3841         ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL);
3842         if (ret == -1)
3843                 _LOGD("Creating desktop file failed\n");
3844         else
3845                 _LOGD("Creating desktop file Success\n");
3846         return ret;
3847 }
3848
3849 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
3850 {
3851         if (mfx == NULL)
3852                 return;
3853         if (mfx->ns) {
3854                 free((void *)mfx->ns);
3855                 mfx->ns = NULL;
3856         }
3857         if (mfx->package) {
3858                 free((void *)mfx->package);
3859                 mfx->package = NULL;
3860         }
3861         if (mfx->version) {
3862                 free((void *)mfx->version);
3863                 mfx->version = NULL;
3864         }
3865         if (mfx->installlocation) {
3866                 free((void *)mfx->installlocation);
3867                 mfx->installlocation = NULL;
3868         }
3869         if (mfx->preload) {
3870                 free((void *)mfx->preload);
3871                 mfx->preload = NULL;
3872         }
3873         if (mfx->readonly) {
3874                 free((void *)mfx->readonly);
3875                 mfx->readonly = NULL;
3876         }
3877         if (mfx->removable) {
3878                 free((void *)mfx->removable);
3879                 mfx->removable = NULL;
3880         }
3881         if (mfx->update) {
3882                 free((void *)mfx->update);
3883                 mfx->update = NULL;
3884         }
3885         if (mfx->system) {
3886                 free((void *)mfx->system);
3887                 mfx->system = NULL;
3888         }
3889         if (mfx->type) {
3890                 free((void *)mfx->type);
3891                 mfx->type = NULL;
3892         }
3893         if (mfx->package_size) {
3894                 free((void *)mfx->package_size);
3895                 mfx->package_size = NULL;
3896         }
3897         if (mfx->package_total_size) {
3898                 free((void *)mfx->package_total_size);
3899                 mfx->package_total_size = NULL;
3900         }
3901         if (mfx->package_data_size) {
3902                 free((void *)mfx->package_data_size);
3903                 mfx->package_data_size = NULL;
3904         }
3905         if (mfx->installed_time) {
3906                 free((void *)mfx->installed_time);
3907                 mfx->installed_time = NULL;
3908         }
3909         if (mfx->installed_storage) {
3910                 free((void *)mfx->installed_storage);
3911                 mfx->installed_storage = NULL;
3912         }
3913         if (mfx->storeclient_id) {
3914                 free((void *)mfx->storeclient_id);
3915                 mfx->storeclient_id = NULL;
3916         }
3917         if (mfx->mainapp_id) {
3918                 free((void *)mfx->mainapp_id);
3919                 mfx->mainapp_id = NULL;
3920         }
3921         if (mfx->package_url) {
3922                 free((void *)mfx->package_url);
3923                 mfx->package_url = NULL;
3924         }
3925         if (mfx->root_path) {
3926                 free((void *)mfx->root_path);
3927                 mfx->root_path = NULL;
3928         }
3929         if (mfx->csc_path) {
3930                 free((void *)mfx->csc_path);
3931                 mfx->csc_path = NULL;
3932         }
3933         if (mfx->appsetting) {
3934                 free((void *)mfx->appsetting);
3935                 mfx->appsetting = NULL;
3936         }
3937         if (mfx->nodisplay_setting) {
3938                 free((void *)mfx->nodisplay_setting);
3939                 mfx->nodisplay_setting = NULL;
3940         }
3941
3942         /*Free Icon*/
3943         if (mfx->icon) {
3944                 icon_x *icon = mfx->icon;
3945                 icon_x *tmp = NULL;
3946                 while(icon != NULL) {
3947                         tmp = icon->next;
3948                         __ps_free_icon(icon);
3949                         icon = tmp;
3950                 }
3951         }
3952         /*Free Label*/
3953         if (mfx->label) {
3954                 label_x *label = mfx->label;
3955                 label_x *tmp = NULL;
3956                 while(label != NULL) {
3957                         tmp = label->next;
3958                         __ps_free_label(label);
3959                         label = tmp;
3960                 }
3961         }
3962         /*Free Author*/
3963         if (mfx->author) {
3964                 author_x *author = mfx->author;
3965                 author_x *tmp = NULL;
3966                 while(author != NULL) {
3967                         tmp = author->next;
3968                         __ps_free_author(author);
3969                         author = tmp;
3970                 }
3971         }
3972         /*Free Description*/
3973         if (mfx->description) {
3974                 description_x *description = mfx->description;
3975                 description_x *tmp = NULL;
3976                 while(description != NULL) {
3977                         tmp = description->next;
3978                         __ps_free_description(description);
3979                         description = tmp;
3980                 }
3981         }
3982         /*Free License*/
3983         if (mfx->license) {
3984                 license_x *license = mfx->license;
3985                 license_x *tmp = NULL;
3986                 while(license != NULL) {
3987                         tmp = license->next;
3988                         __ps_free_license(license);
3989                         license = tmp;
3990                 }
3991         }
3992         /*Free Privileges*/
3993         if (mfx->privileges) {
3994                 privileges_x *privileges = mfx->privileges;
3995                 privileges_x *tmp = NULL;
3996                 while(privileges != NULL) {
3997                         tmp = privileges->next;
3998                         __ps_free_privileges(privileges);
3999                         privileges = tmp;
4000                 }
4001         }
4002         /*Free UiApplication*/
4003         if (mfx->uiapplication) {
4004                 uiapplication_x *uiapplication = mfx->uiapplication;
4005                 uiapplication_x *tmp = NULL;
4006                 while(uiapplication != NULL) {
4007                         tmp = uiapplication->next;
4008                         __ps_free_uiapplication(uiapplication);
4009                         uiapplication = tmp;
4010                 }
4011         }
4012         /*Free ServiceApplication*/
4013         if (mfx->serviceapplication) {
4014                 serviceapplication_x *serviceapplication = mfx->serviceapplication;
4015                 serviceapplication_x *tmp = NULL;
4016                 while(serviceapplication != NULL) {
4017                         tmp = serviceapplication->next;
4018                         __ps_free_serviceapplication(serviceapplication);
4019                         serviceapplication = tmp;
4020                 }
4021         }
4022         /*Free Daemon*/
4023         if (mfx->daemon) {
4024                 daemon_x *daemon = mfx->daemon;
4025                 daemon_x *tmp = NULL;
4026                 while(daemon != NULL) {
4027                         tmp = daemon->next;
4028                         __ps_free_daemon(daemon);
4029                         daemon = tmp;
4030                 }
4031         }
4032         /*Free Theme*/
4033         if (mfx->theme) {
4034                 theme_x *theme = mfx->theme;
4035                 theme_x *tmp = NULL;
4036                 while(theme != NULL) {
4037                         tmp = theme->next;
4038                         __ps_free_theme(theme);
4039                         theme = tmp;
4040                 }
4041         }
4042         /*Free Font*/
4043         if (mfx->font) {
4044                 font_x *font = mfx->font;
4045                 font_x *tmp = NULL;
4046                 while(font != NULL) {
4047                         tmp = font->next;
4048                         __ps_free_font(font);
4049                         font = tmp;
4050                 }
4051         }
4052         /*Free Ime*/
4053         if (mfx->ime) {
4054                 ime_x *ime = mfx->ime;
4055                 ime_x *tmp = NULL;
4056                 while(ime != NULL) {
4057                         tmp = ime->next;
4058                         __ps_free_ime(ime);
4059                         ime = tmp;
4060                 }
4061         }
4062         /*Free Compatibility*/
4063         if (mfx->compatibility) {
4064                 compatibility_x *compatibility = mfx->compatibility;
4065                 compatibility_x *tmp = NULL;
4066                 while(compatibility != NULL) {
4067                         tmp = compatibility->next;
4068                         __ps_free_compatibility(compatibility);
4069                         compatibility = tmp;
4070                 }
4071         }
4072         /*Free DeviceProfile*/
4073         if (mfx->deviceprofile) {
4074                 deviceprofile_x *deviceprofile = mfx->deviceprofile;
4075                 deviceprofile_x *tmp = NULL;
4076                 while(deviceprofile != NULL) {
4077                         tmp = deviceprofile->next;
4078                         __ps_free_deviceprofile(deviceprofile);
4079                         deviceprofile = tmp;
4080                 }
4081         }
4082         free((void*)mfx);
4083         mfx = NULL;
4084         return;
4085 }
4086
4087 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
4088 {
4089         _LOGD("parsing start\n");
4090         xmlTextReaderPtr reader;
4091         manifest_x *mfx = NULL;
4092
4093         reader = xmlReaderForFile(manifest, NULL, 0);
4094         if (reader) {
4095                 mfx = malloc(sizeof(manifest_x));
4096                 if (mfx) {
4097                         memset(mfx, '\0', sizeof(manifest_x));
4098                         if (__process_manifest(reader, mfx) < 0) {
4099                                 _LOGD("Parsing Failed\n");
4100                                 pkgmgr_parser_free_manifest_xml(mfx);
4101                                 mfx = NULL;
4102                         } else
4103                                 _LOGD("Parsing Success\n");
4104                 } else {
4105                         _LOGD("Memory allocation error\n");
4106                 }
4107                 xmlFreeTextReader(reader);
4108         } else {
4109                 _LOGD("Unable to create xml reader\n");
4110         }
4111         return mfx;
4112 }
4113
4114 /* These APIs are intended to call parser directly */
4115
4116 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
4117 {
4118         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4119         _LOGD("parsing manifest for installation: %s\n", manifest);
4120
4121         manifest_x *mfx = NULL;
4122         int ret = -1;
4123
4124         xmlInitParser();
4125         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4126         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4127
4128         _LOGD("Parsing Finished\n");
4129
4130         ret = __ps_check_mdm_policy(mfx, ACTION_INSTALL);
4131         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "pkg[%s] violate mdm policy.", mfx->package);
4132
4133         __add_preload_info(mfx, manifest);
4134
4135         _LOGD("Added preload infomation\n");
4136
4137         __ps_process_tag(mfx, tagv);
4138
4139         ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
4140         if (ret < 0) {
4141                 ret = __delete_pkgid_info_for_uninstallation(mfx->package);
4142                 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
4143                 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4144         }
4145
4146         _LOGD("DB Insert Success\n");
4147
4148         _pkgmgr_parser_plugin_process_plugin(mfx, manifest, ACTION_INSTALL);
4149
4150         if (__check_action_fota(tagv))
4151                 ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_FOTA);
4152         else
4153                 ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL);
4154
4155         if (ret == -1)
4156                 _LOGD("Creating desktop file failed\n");
4157         else
4158                 _LOGD("Creating desktop file Success\n");
4159
4160         pkgmgr_parser_free_manifest_xml(mfx);
4161         _LOGD("Free Done\n");
4162         xmlCleanupParser();
4163
4164         return PMINFO_R_OK;
4165 }
4166
4167 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
4168 {
4169         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4170         _LOGD("parsing manifest for upgradation: %s\n", manifest);
4171
4172         manifest_x *mfx = NULL;
4173         int ret = -1;
4174         bool preload = false;
4175         bool system = false;
4176         char *csc_path = NULL;
4177         pkgmgrinfo_pkginfo_h handle = NULL;
4178
4179         xmlInitParser();
4180         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4181         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4182
4183         _LOGD("Parsing Finished\n");
4184         
4185         __add_preload_info(mfx, manifest);
4186         _LOGD("Added preload infomation\n");
4187         __check_preload_updated(mfx, manifest);
4188
4189         ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
4190         if (ret != PMINFO_R_OK)
4191                 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
4192
4193         ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
4194         if (ret != PMINFO_R_OK)
4195                 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
4196
4197         if (preload) {
4198                 free((void *)mfx->preload);
4199                 mfx->preload = strdup("true");
4200         }
4201
4202         ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
4203         if (ret != PMINFO_R_OK)
4204                 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
4205
4206         if (system) {
4207                 free((void *)mfx->system);
4208                 mfx->system = strdup("true");
4209         }
4210
4211         ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
4212         if (ret != PMINFO_R_OK)
4213                 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
4214
4215         if (csc_path != NULL) {
4216                 if (mfx->csc_path)
4217                         free((void *)mfx->csc_path);
4218                 mfx->csc_path = strdup(csc_path);
4219         }
4220
4221         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
4222         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4223         _LOGD("DB Update Success\n");
4224
4225         _pkgmgr_parser_plugin_process_plugin(mfx, manifest, ACTION_UPGRADE);
4226
4227         ret = __ps_make_nativeapp_desktop(mfx, manifest, ACTION_UPGRADE);
4228         if (ret == -1)
4229                 _LOGD("Creating desktop file failed\n");
4230         else
4231                 _LOGD("Creating desktop file Success\n");
4232
4233         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
4234         pkgmgr_parser_free_manifest_xml(mfx);
4235         _LOGD("Free Done\n");
4236         xmlCleanupParser();
4237
4238         return PMINFO_R_OK;
4239 }
4240
4241 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
4242 {
4243         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4244         int ret = -1;
4245         manifest_x *mfx = NULL;
4246
4247         if (!strstr(manifest, ".xml")) {
4248                 _LOGD("manifest is pkgid[%s]\n", manifest);
4249                 ret = __delete_pkgid_info_for_uninstallation(manifest);
4250                 if (ret <0)
4251                         _LOGD("__delete_manifest_for_fota failed\n");
4252
4253                 return PMINFO_R_OK;
4254         }
4255
4256         _LOGD("parsing manifest for uninstallation: %s\n", manifest);
4257
4258         xmlInitParser();
4259         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4260         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4261
4262         _LOGD("Parsing Finished\n");
4263
4264         ret = __ps_check_mdm_policy(mfx, ACTION_UNINSTALL);
4265         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "pkg[%s] violate mdm policy.", mfx->package);
4266
4267         __add_preload_info(mfx, manifest);
4268         _LOGD("Added preload infomation\n");
4269
4270         _pkgmgr_parser_plugin_process_plugin(mfx, manifest, ACTION_UNINSTALL);
4271
4272         ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
4273         if (ret == -1)
4274                 _LOGD("DB Delete failed\n");
4275         else
4276                 _LOGD("DB Delete Success\n");
4277
4278         ret = __ps_remove_nativeapp_desktop(mfx);
4279         if (ret == -1)
4280                 _LOGD("Removing desktop file failed\n");
4281         else
4282                 _LOGD("Removing desktop file Success\n");
4283
4284         pkgmgr_parser_free_manifest_xml(mfx);
4285         _LOGD("Free Done\n");
4286         xmlCleanupParser();
4287
4288         return PMINFO_R_OK;
4289 }
4290
4291 API int pkgmgr_parser_parse_manifest_for_preload()
4292 {
4293         return pkgmgr_parser_update_preload_info_in_db();
4294 }
4295
4296 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
4297 {
4298         return __pkgid_to_manifest(pkgid);
4299 }
4300
4301 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4302 {
4303         return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
4304 }
4305
4306 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4307 {
4308         return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
4309 }
4310
4311 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4312 {
4313         return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
4314 }
4315
4316 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
4317 {
4318         if (manifest == NULL) {
4319                 _LOGE("manifest file is NULL\n");
4320                 return PMINFO_R_EINVAL;
4321         }
4322         int ret = -1;
4323         xmlSchemaParserCtxtPtr ctx;
4324         xmlSchemaValidCtxtPtr vctx;
4325         xmlSchemaPtr xschema;
4326         ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
4327         if (ctx == NULL) {
4328                 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
4329                 return PMINFO_R_ERROR;
4330         }
4331         xschema = xmlSchemaParse(ctx);
4332         if (xschema == NULL) {
4333                 _LOGE("xmlSchemaParse() Failed\n");
4334                 return PMINFO_R_ERROR;
4335         }
4336         vctx = xmlSchemaNewValidCtxt(xschema);
4337         if (vctx == NULL) {
4338                 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
4339                 return PMINFO_R_ERROR;
4340         }
4341         xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
4342         ret = xmlSchemaValidateFile(vctx, manifest, 0);
4343         if (ret == -1) {
4344                 _LOGE("xmlSchemaValidateFile() failed\n");
4345                 return PMINFO_R_ERROR;
4346         } else if (ret == 0) {
4347                 _LOGE("Manifest is Valid\n");
4348                 return PMINFO_R_OK;
4349         } else {
4350                 _LOGE("Manifest Validation Failed with error code %d\n", ret);
4351                 return PMINFO_R_ERROR;
4352         }
4353         return PMINFO_R_OK;
4354 }
4355
4356 API int pkgmgr_parser_insert_disabled_pkg(const char *pkgid, char *const tagv[])
4357 {
4358         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4359
4360         char *manifest = NULL;
4361         manifest_x *mfx = NULL;
4362         int ret = -1;
4363
4364         _LOGD("parsing manifest for installation: %s\n", pkgid);
4365
4366         manifest = pkgmgr_parser_get_manifest_file(pkgid);
4367         if (manifest == NULL) {
4368                 _LOGE("can not get the manifest.xml\n");
4369                 return -1;
4370         }
4371
4372         xmlInitParser();
4373         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4374         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4375
4376         _LOGD("Parsing Finished\n");
4377
4378         __add_preload_info(mfx, manifest);
4379
4380         _LOGD("Added preload infomation\n");
4381
4382         ret = pkgmgr_parser_insert_disabled_pkg_info_in_db(mfx);
4383         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4384
4385         _LOGD("DB Insert Success\n");
4386
4387         pkgmgr_parser_free_manifest_xml(mfx);
4388         _LOGD("Free Done\n");
4389         xmlCleanupParser();
4390
4391         return PMINFO_R_OK;
4392 }
4393
4394 API int pkgmgr_parser_delete_disabled_pkg(const char *pkgid, char *const tagv[])
4395 {
4396         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4397
4398         int ret = -1;
4399
4400         _LOGD("Start uninstall for pkgid : delete pkgid[%s]\n", pkgid);
4401
4402         /* delete pkgmgr db */
4403         ret = pkgmgr_parser_delete_disabled_pkgid_info_from_db(pkgid);
4404         if (ret == -1)
4405                 _LOGD("DB pkgid info Delete failed\n");
4406         else
4407                 _LOGD("DB pkgid info Delete Success\n");
4408
4409         _LOGD("Finish : uninstall for pkgid\n");
4410
4411         return PMINFO_R_OK;
4412 }
4413