e7839135c8d51cd9f1db35694f5b8d5ca54e1d39
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser_db.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
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <db-util.h>
30 #include <glib.h>
31 #include "pkgmgr_parser_internal.h"
32 #include "pkgmgr_parser_db.h"
33
34 #define PKGMGR_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
35 #define PKGMGR_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
36 #define MAX_QUERY_LEN           4096
37 sqlite3 *pkgmgr_parser_db;
38 sqlite3 *pkgmgr_cert_db;
39 GList *pkglocale = NULL;
40 GList *applocale = NULL;
41 GList *appicon = NULL;
42 char *prev = NULL;
43
44 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
45                                                 "(package text primary key not null, " \
46                                                 "package_type text DEFAULT 'rpm', " \
47                                                 "package_version text, " \
48                                                 "install_location text, " \
49                                                 "package_size text, " \
50                                                 "package_removable text DEFAULT 'true', " \
51                                                 "package_preload text DEFAULT 'false', " \
52                                                 "package_readonly text DEFAULT 'false', " \
53                                                 "author_name text, " \
54                                                 "author_email text, " \
55                                                 "author_href text," \
56                                                 "installed_time text," \
57                                                 "storeclient_id text," \
58                                                 "mainapp_id text," \
59                                                 "package_url text)"
60
61 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
62                                                 "(package text not null, " \
63                                                 "package_locale text DEFAULT 'No Locale', " \
64                                                 "package_label text, " \
65                                                 "package_icon text, " \
66                                                 "package_description text, " \
67                                                 "package_license text, " \
68                                                 "package_author, " \
69                                                 "PRIMARY KEY(package, package_locale), " \
70                                                 "FOREIGN KEY(package) " \
71                                                 "REFERENCES package_info(package) " \
72                                                 "ON DELETE CASCADE)"
73
74 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
75                                                 "(app_id text primary key not null, " \
76                                                 "app_component text, " \
77                                                 "app_exec text, " \
78                                                 "app_nodisplay text DEFAULT 'false', " \
79                                                 "app_type text, " \
80                                                 "app_onboot text DEFAULT 'false', " \
81                                                 "app_multiple text DEFAULT 'false', " \
82                                                 "app_autorestart text DEFAULT 'false', " \
83                                                 "app_taskmanage text DEFAULT 'false', " \
84                                                 "app_hwacceleration text DEFAULT 'use-system-setting', " \
85                                                 "app_mainapp text, " \
86                                                 "app_recentimage text, " \
87                                                 "package text not null, " \
88                                                 "FOREIGN KEY(package) " \
89                                                 "REFERENCES package_info(package) " \
90                                                 "ON DELETE CASCADE)"
91
92 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
93                                                 "(app_id text not null, " \
94                                                 "app_locale text DEFAULT 'No Locale', " \
95                                                 "app_label text, " \
96                                                 "app_icon text, " \
97                                                 "PRIMARY KEY(app_id,app_locale) " \
98                                                 "FOREIGN KEY(app_id) " \
99                                                 "REFERENCES package_app_info(app_id) " \
100                                                 "ON DELETE CASCADE)"
101
102 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_LOCALIZED_INFO "create table if not exists package_app_icon_localized_info " \
103                                                 "(app_id text not null, " \
104                                                 "app_locale text DEFAULT 'No Locale', " \
105                                                 "app_icon text, " \
106                                                 "app_icon_section text, " \
107                                                 "app_icon_resolution text, " \
108                                                 "PRIMARY KEY(app_id,app_locale,app_icon_section,app_icon_resolution) " \
109                                                 "FOREIGN KEY(app_id) " \
110                                                 "REFERENCES package_app_info(app_id) " \
111                                                 "ON DELETE CASCADE)"
112
113 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
114                                                 "(app_id text not null, " \
115                                                 "operation text not null, " \
116                                                 "uri_scheme text, " \
117                                                 "mime_type text, " \
118                                                 "subapp_name text, " \
119                                                 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
120                                                 "FOREIGN KEY(app_id) " \
121                                                 "REFERENCES package_app_info(app_id) " \
122                                                 "ON DELETE CASCADE)"
123
124 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
125                                                 "(app_id text not null, " \
126                                                 "operation text not null, " \
127                                                 "uri_scheme text, " \
128                                                 "mime_type text, " \
129                                                 "subapp_name text, " \
130                                                 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
131                                                 "FOREIGN KEY(app_id) " \
132                                                 "REFERENCES package_app_info(app_id) " \
133                                                 "ON DELETE CASCADE)"
134
135 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
136                                                 "(app_id text not null, " \
137                                                 "category text not null, " \
138                                                 "PRIMARY KEY(app_id,category) " \
139                                                 "FOREIGN KEY(app_id) " \
140                                                 "REFERENCES package_app_info(app_id) " \
141                                                 "ON DELETE CASCADE)"
142
143 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
144                                                 "(app_id text not null, " \
145                                                 "data_share_path text not null, " \
146                                                 "data_share_allowed text not null, " \
147                                                 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
148                                                 "FOREIGN KEY(app_id) " \
149                                                 "REFERENCES package_app_info(app_id) " \
150                                                 "ON DELETE CASCADE)"
151
152 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
153                                                 "(app_id text not null, " \
154                                                 "data_share_request text not null, " \
155                                                 "PRIMARY KEY(app_id,data_share_request) " \
156                                                 "FOREIGN KEY(app_id) " \
157                                                 "REFERENCES package_app_info(app_id) " \
158                                                 "ON DELETE CASCADE)"
159
160 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
161                                                 "(package text not null, " \
162                                                 "author_root_cert text, " \
163                                                 "author_im_cert text, " \
164                                                 "author_signer_cert text, " \
165                                                 "dist_root_cert text, " \
166                                                 "dist_im_cert text, " \
167                                                 "dist_signer_cert text, " \
168                                                 "dist2_root_cert text, " \
169                                                 "dist2_im_cert text, " \
170                                                 "dist2_signer_cert text, " \
171                                                 "PRIMARY KEY(package), " \
172                                                 "FOREIGN KEY(package) " \
173                                                 "REFERENCES package_info(package) " \
174                                                 "ON DELETE CASCADE)"
175
176 static int __insert_uiapplication_info(manifest_x *mfx);
177 static int __insert_serviceapplication_info(manifest_x *mfx);
178 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
179 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
180 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
181 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
182 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
183 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
184 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
185 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
186 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
187 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
188 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
189 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
190 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
191 static int __insert_manifest_info_in_db(manifest_x *mfx);
192 static int __update_manifest_info_in_db(manifest_x *mfx);
193 static int __delete_cert_info_from_db(manifest_x *mfx);
194 static int __delete_manifest_info_from_db(manifest_x *mfx);
195 static int __initialize_package_info_db();
196 static int __initialize_package_localized_info_db();
197 static int __initialize_package_app_info_db();
198 static int __initialize_package_cert_info_db();
199 static int __initialize_package_app_localized_info_db();
200 static int __initialize_package_app_icon_localized_info_db();
201 static int __initialize_package_app_app_svc_db();
202 static int __initialize_package_app_app_category_db();
203 static int __initialize_package_app_app_control_db();
204 static int __initialize_package_app_share_allowed_db();
205 static int __initialize_package_app_share_request_db();
206 static int __exec_query(char *query);
207 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
208                 char **label, char **license, char **icon, char **description, char **author);
209
210 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
211 static void __trimfunc1(gpointer data, gpointer userdata);
212 static void __trimfunc2(gpointer data, gpointer userdata);
213 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
214
215 static int __initialize_package_info_db()
216 {
217         char *error_message = NULL;
218         if (SQLITE_OK !=
219             sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO,
220                          NULL, NULL, &error_message)) {
221                 DBG("Don't execute query = %s error message = %s\n",
222                        QUERY_CREATE_TABLE_PACKAGE_INFO, error_message);
223                 sqlite3_free(error_message);
224                 return -1;
225         }
226         sqlite3_free(error_message);
227         return 0;
228 }
229
230 static int __pkgmgr_parser_cert_create_db()
231 {
232         int ret = -1;
233         if (access(PKGMGR_CERT_DB_FILE, F_OK) == 0) {
234                 ret =
235                     db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
236                                  DB_UTIL_REGISTER_HOOK_METHOD);
237                 if (ret != SQLITE_OK) {
238                         DBG("connect db [%s] failed!\n",
239                                PKGMGR_CERT_DB_FILE);
240                         return -1;
241                 }
242                 return 0;
243         }
244         DBG("Pkgmgr DB does not exists. Create one!!\n");
245
246         ret =
247             db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
248                          DB_UTIL_REGISTER_HOOK_METHOD);
249
250         if (ret != SQLITE_OK) {
251                 DBG("connect db [%s] failed!\n", PKGMGR_CERT_DB_FILE);
252                 return -1;
253         }
254         return 0;
255 }
256
257 static int __initialize_package_cert_info_db()
258 {
259         char *error_message = NULL;
260         int ret = -1;
261         ret = __pkgmgr_parser_cert_create_db();
262         if (ret == -1) {
263                 DBG("Failed to open DB\n");
264                 return ret;
265         }
266
267         if (SQLITE_OK !=
268             sqlite3_exec(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
269                          NULL, NULL, &error_message)) {
270                 DBG("Don't execute query = %s error message = %s\n",
271                        QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, error_message);
272                 sqlite3_free(error_message);
273                 sqlite3_close(pkgmgr_cert_db);
274                 return -1;
275         }
276         sqlite3_free(error_message);
277         sqlite3_close(pkgmgr_cert_db);
278         return 0;
279 }
280
281 static int __initialize_package_localized_info_db()
282 {
283         char *error_message = NULL;
284         if (SQLITE_OK !=
285             sqlite3_exec(pkgmgr_parser_db,
286                          QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO, NULL, NULL,
287                          &error_message)) {
288                 DBG("Don't execute query = %s error message = %s\n",
289                        QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
290                        error_message);
291                 sqlite3_free(error_message);
292                 return -1;
293         }
294         sqlite3_free(error_message);
295         return 0;
296 }
297
298 static int __initialize_package_app_info_db()
299 {
300         char *error_message = NULL;
301         if (SQLITE_OK !=
302             sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
303                          NULL, NULL, &error_message)) {
304                 DBG("Don't execute query = %s error message = %s\n",
305                        QUERY_CREATE_TABLE_PACKAGE_APP_INFO, error_message);
306                 sqlite3_free(error_message);
307                 return -1;
308         }
309         sqlite3_free(error_message);
310         return 0;
311 }
312
313 static int __initialize_package_app_localized_info_db()
314 {
315         char *error_message = NULL;
316         if (SQLITE_OK !=
317             sqlite3_exec(pkgmgr_parser_db,
318                          QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO, NULL,
319                          NULL, &error_message)) {
320                 DBG("Don't execute query = %s error message = %s\n",
321                        QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
322                        error_message);
323                 sqlite3_free(error_message);
324                 return -1;
325         }
326         sqlite3_free(error_message);
327         return 0;
328 }
329
330 static int __initialize_package_app_icon_localized_info_db()
331 {
332         char *error_message = NULL;
333         if (SQLITE_OK !=
334             sqlite3_exec(pkgmgr_parser_db,
335                          QUERY_CREATE_TABLE_PACKAGE_APP_ICON_LOCALIZED_INFO, NULL,
336                          NULL, &error_message)) {
337                 DBG("Don't execute query = %s error message = %s\n",
338                        QUERY_CREATE_TABLE_PACKAGE_APP_ICON_LOCALIZED_INFO,
339                        error_message);
340                 sqlite3_free(error_message);
341                 return -1;
342         }
343         sqlite3_free(error_message);
344         return 0;
345 }
346
347 static int __initialize_package_app_app_control_db()
348 {
349         char *error_message = NULL;
350         if (SQLITE_OK !=
351             sqlite3_exec(pkgmgr_parser_db,
352                          QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, NULL, NULL,
353                          &error_message)) {
354                 DBG("Don't execute query = %s error message = %s\n",
355                        QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, error_message);
356                 sqlite3_free(error_message);
357                 return -1;
358         }
359         sqlite3_free(error_message);
360         return 0;
361 }
362
363 static int __initialize_package_app_app_category_db()
364 {
365         char *error_message = NULL;
366         if (SQLITE_OK !=
367             sqlite3_exec(pkgmgr_parser_db,
368                          QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, NULL, NULL,
369                          &error_message)) {
370                 DBG("Don't execute query = %s error message = %s\n",
371                        QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, error_message);
372                 sqlite3_free(error_message);
373                 return -1;
374         }
375         sqlite3_free(error_message);
376         return 0;
377 }
378
379 static int __initialize_package_app_app_svc_db()
380 {
381         char *error_message = NULL;
382         if (SQLITE_OK !=
383             sqlite3_exec(pkgmgr_parser_db,
384                          QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, NULL, NULL,
385                          &error_message)) {
386                 DBG("Don't execute query = %s error message = %s\n",
387                        QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, error_message);
388                 sqlite3_free(error_message);
389                 return -1;
390         }
391         sqlite3_free(error_message);
392         return 0;
393 }
394
395 static int __initialize_package_app_share_allowed_db()
396 {
397         char *error_message = NULL;
398         if (SQLITE_OK !=
399             sqlite3_exec(pkgmgr_parser_db,
400                          QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, NULL,
401                          NULL, &error_message)) {
402                 DBG("Don't execute query = %s error message = %s\n",
403                        QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED,
404                        error_message);
405                 sqlite3_free(error_message);
406                 return -1;
407         }
408         sqlite3_free(error_message);
409         return 0;
410 }
411
412 static int __initialize_package_app_share_request_db()
413 {
414         char *error_message = NULL;
415         if (SQLITE_OK !=
416             sqlite3_exec(pkgmgr_parser_db,
417                          QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, NULL,
418                          NULL, &error_message)) {
419                 DBG("Don't execute query = %s error message = %s\n",
420                        QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST,
421                        error_message);
422                 sqlite3_free(error_message);
423                 return -1;
424         }
425         sqlite3_free(error_message);
426         return 0;
427 }
428
429 static int __exec_query(char *query)
430 {
431         char *error_message = NULL;
432         if (SQLITE_OK !=
433             sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
434                 DBG("Don't execute query = %s error message = %s\n", query,
435                        error_message);
436                 sqlite3_free(error_message);
437                 return -1;
438         }
439         sqlite3_free(error_message);
440         return 0;
441 }
442 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
443 {
444
445         while(lbl != NULL)
446         {
447                 if (lbl->lang)
448                         locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
449                 lbl = lbl->next;
450         }
451         while(lcn != NULL)
452         {
453                 if (lcn->lang)
454                         locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
455                 lcn = lcn->next;
456         }
457         while(icn != NULL)
458         {
459                 if (icn->lang)
460                         locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
461                 icn = icn->next;
462         }
463         while(dcn != NULL)
464         {
465                 if (dcn->lang)
466                         locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
467                 dcn = dcn->next;
468         }
469         while(ath != NULL)
470         {
471                 if (ath->lang)
472                         locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
473                 ath = ath->next;
474         }
475         return locale;
476
477 }
478
479 static GList *__create_icon_list(GList *locale, icon_x *icn)
480 {
481         while(icn != NULL)
482         {
483                 if (icn->section)
484                         locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
485                 icn = icn->next;
486         }
487         return locale;
488 }
489
490 static void __printfunc(gpointer data, gpointer userdata)
491 {
492         DBG("%s  ", (char*)data);
493 }
494
495 static void __trimfunc1(gpointer data, gpointer userdata)
496 {
497         if (prev) {
498                 if (strcmp((char *)data, prev) == 0) {
499                         pkglocale = g_list_remove(pkglocale, data);
500                 } else
501                         prev = (char *)data;
502         }
503         else
504                 prev = (char *)data;
505 }
506
507 static void __trimfunc2(gpointer data, gpointer userdata)
508 {
509         if (prev) {
510                 if (strcmp((char *)data, prev) == 0) {
511                         applocale = g_list_remove(applocale, data);
512                 } else
513                         prev = (char *)data;
514         }
515         else
516                 prev = (char *)data;
517 }
518
519 static void __trimfunc3(gpointer data, gpointer userdata)
520 {
521         if (prev) {
522                 if (strcmp((char *)data, prev) == 0) {
523                         appicon = g_list_remove(appicon, data);
524                 } else
525                         prev = (char *)data;
526         }
527         else
528                 prev = (char *)data;
529 }
530
531 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
532 {
533         if (a == NULL || b == NULL)
534                 return 0;
535         if (strcmp((char*)a, (char*)b) == 0)
536                 return 0;
537         if (strcmp((char*)a, (char*)b) < 0)
538                 return -1;
539         if (strcmp((char*)a, (char*)b) > 0)
540                 return 1;
541 }
542
543 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
544                 char **label, char **license, char **icon, char **description, char **author)
545 {
546         while(lbl != NULL)
547         {
548                 if (lbl->lang) {
549                         if (strcmp(lbl->lang, (char *)data) == 0) {
550                                 *label = (char*)lbl->text;
551                                 break;
552                         }
553                 }
554                 lbl = lbl->next;
555         }
556         while(lcn != NULL)
557         {
558                 if (lcn->lang) {
559                         if (strcmp(lcn->lang, (char *)data) == 0) {
560                                 *license = (char*)lcn->text;
561                                 break;
562                         }
563                 }
564                 lcn = lcn->next;
565         }
566         while(icn != NULL)
567         {
568                 if (icn->lang) {
569                         if (strcmp(icn->lang, (char *)data) == 0) {
570                                 *icon = (char*)icn->text;
571                                 break;
572                         }
573                 }
574                 icn = icn->next;
575         }
576         while(dcn != NULL)
577         {
578                 if (dcn->lang) {
579                         if (strcmp(dcn->lang, (char *)data) == 0) {
580                                 *description = (char*)dcn->text;
581                                 break;
582                         }
583                 }
584                 dcn = dcn->next;
585         }
586         while(ath != NULL)
587         {
588                 if (ath->lang) {
589                         if (strcmp(ath->lang, (char *)data) == 0) {
590                                 *author = (char*)ath->text;
591                                 break;
592                         }
593                 }
594                 ath = ath->next;
595         }
596
597 }
598
599 static void __extract_icon_data(gpointer data, icon_x *icn, char **lang, char **icon, char **resolution)
600 {
601         while(icn != NULL)
602         {
603                 if (icn->section) {
604                         if (strcmp(icn->section, (char *)data) == 0) {
605                                 *lang = (char*)icn->lang;
606                                 *icon = (char*)icn->text;
607                                 *resolution = (char*)icn->resolution;
608                                 break;
609                         }
610                 }
611                 icn = icn->next;
612         }
613 }
614
615 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
616 {
617         int ret = -1;
618         char *label = NULL;
619         char *icon = NULL;
620         char *description = NULL;
621         char *license = NULL;
622         char *author = NULL;
623         char query[MAX_QUERY_LEN] = {'\0'};
624
625         manifest_x *mfx = (manifest_x *)userdata;
626         label_x *lbl = mfx->label;
627         license_x *lcn = mfx->license;
628         icon_x *icn = mfx->icon;
629         description_x *dcn = mfx->description;
630         author_x *ath = mfx->author;
631
632         __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
633         if (!label && !description && !icon && !license && !author)
634                 return;
635         snprintf(query, MAX_QUERY_LEN, "insert into package_localized_info(package, package_locale, " \
636                 "package_label, package_icon, package_description, package_license, package_author) values " \
637                 "('%s', '%s', '%s', '%s', '%s', '%s', '%s')", mfx->package, (char*)data,
638                 label, icon, description, license, author);
639         ret = __exec_query(query);
640         if (ret == -1)
641                 DBG("Package Localized Info DB Insert failed\n");
642 }
643
644 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
645 {
646         int ret = -1;
647         char *label = NULL;
648         char *icon = NULL;
649         char query[MAX_QUERY_LEN] = {'\0'};
650
651         uiapplication_x *up = (uiapplication_x*)userdata;
652         label_x *lbl = up->label;
653         icon_x *icn = up->icon;
654
655         __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
656         if (!label && !icon)
657                 return;
658         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
659                 "app_label, app_icon) values " \
660                 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
661                 label, icon);
662         ret = __exec_query(query);
663         if (ret == -1)
664                 DBG("Package UiApp Localized Info DB Insert failed\n");
665
666 }
667
668 static void __insert_uiapplication_icon_locale_info(gpointer data, gpointer userdata)
669 {
670         int ret = -1;
671         char *lang = NULL;
672         char *icon = NULL;
673         char *resolution = NULL;
674         char query[MAX_QUERY_LEN] = {'\0'};
675
676         uiapplication_x *up = (uiapplication_x*)userdata;
677         icon_x *icn = up->icon;
678
679         __extract_icon_data(data, icn, &lang, &icon, &resolution);
680         if (!lang && !icon && !resolution)
681                 return;
682         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_localized_info(app_id, app_locale, " \
683                 "app_icon, app_icon_section, app_icon_resolution) values " \
684                 "('%q', '%q', '%q', '%q', '%q')", up->appid, lang,
685                 icon, (char*)data, resolution);
686
687         ret = __exec_query(query);
688         if (ret == -1)
689                 DBG("Package UiApp Localized Info DB Insert failed\n");
690
691 }
692
693 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
694 {
695         int ret = -1;
696         char *icon = NULL;
697         char *label = NULL;
698         char query[MAX_QUERY_LEN] = {'\0'};
699
700         serviceapplication_x *sp = (serviceapplication_x*)userdata;
701         label_x *lbl = sp->label;
702         icon_x *icn = sp->icon;
703
704         __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
705         if (!icon && !label)
706                 return;
707         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
708                 "app_label, app_icon) values " \
709                 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
710                 label, icon);
711         ret = __exec_query(query);
712         if (ret == -1)
713                 DBG("Package ServiceApp Localized Info DB Insert failed\n");
714 }
715
716 static int __insert_ui_mainapp_info(manifest_x *mfx)
717 {
718         uiapplication_x *up = mfx->uiapplication;
719         int ret = -1;
720         char query[MAX_QUERY_LEN] = {'\0'};
721         while(up != NULL)
722         {
723                 snprintf(query, MAX_QUERY_LEN,
724                         "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
725
726                 ret = __exec_query(query);
727                 if (ret == -1) {
728                         DBG("Package UiApp Info DB Insert Failed\n");
729                         return -1;
730                 }
731                 if (strcasecmp(up->mainapp, "True")==0)
732                         mfx->mainapp_id = strdup(up->appid);
733
734                 up = up->next;
735                 memset(query, '\0', MAX_QUERY_LEN);
736         }
737
738         if (mfx->mainapp_id == NULL){
739                 snprintf(query, MAX_QUERY_LEN,
740                         "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
741                 ret = __exec_query(query);
742                 if (ret == -1) {
743                         DBG("Package UiApp Info DB Insert Failed\n");
744                         return -1;
745                 }
746                 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
747         }
748
749         memset(query, '\0', MAX_QUERY_LEN);
750         snprintf(query, MAX_QUERY_LEN,
751                 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
752         ret = __exec_query(query);
753         if (ret == -1) {
754                 DBG("Package Info DB update Failed\n");
755                 return -1;
756         }
757
758         return 0;
759 }
760
761 static int __insert_uiapplication_info(manifest_x *mfx)
762 {
763         uiapplication_x *up = mfx->uiapplication;
764         int ret = -1;
765         char query[MAX_QUERY_LEN] = {'\0'};
766         while(up != NULL)
767         {
768                 snprintf(query, MAX_QUERY_LEN,
769                          "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
770                         "app_multiple, app_autorestart, app_taskmanage, app_hwacceleration, app_mainapp , app_recentimage, package) " \
771                         "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
772                          up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
773                          "\0", up->taskmanage, up->hwacceleration,up->mainapp, up->recentimage, mfx->package);
774                 ret = __exec_query(query);
775                 if (ret == -1) {
776                         DBG("Package UiApp Info DB Insert Failed\n");
777                         return -1;
778                 }
779                 up = up->next;
780                 memset(query, '\0', MAX_QUERY_LEN);
781         }
782         return 0;
783 }
784
785 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
786 {
787         uiapplication_x *up = mfx->uiapplication;
788         category_x *ct = NULL;
789         int ret = -1;
790         char query[MAX_QUERY_LEN] = {'\0'};
791         while(up != NULL)
792         {
793                 ct = up->category;
794                 while (ct != NULL)
795                 {
796                         snprintf(query, MAX_QUERY_LEN,
797                                 "insert into package_app_app_category(app_id, category) " \
798                                 "values('%s','%s')",\
799                                  up->appid, ct->name);
800                         ret = __exec_query(query);
801                         if (ret == -1) {
802                                 DBG("Package UiApp Category Info DB Insert Failed\n");
803                                 return -1;
804                         }
805                         ct = ct->next;
806                         memset(query, '\0', MAX_QUERY_LEN);
807                 }
808                 up = up->next;
809         }
810         return 0;
811 }
812
813 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
814 {
815         uiapplication_x *up = mfx->uiapplication;
816         appcontrol_x *acontrol = NULL;
817         operation_x *op = NULL;
818         mime_x *mi = NULL;
819         uri_x *ui = NULL;
820         subapp_x *sub = NULL;
821         int ret = -1;
822         char query[MAX_QUERY_LEN] = {'\0'};
823         char *operation = NULL;
824         char *mime = NULL;
825         char *uri = NULL;
826         char *subapp = NULL;
827         while(up != NULL)
828         {
829                 acontrol = up->appcontrol;
830                 while(acontrol != NULL)
831                 {
832                         op = acontrol->operation;
833                         while(op != NULL)
834                         {
835                                 if (op)
836                                         operation = op->name;
837                                 mi = acontrol->mime;
838
839                                 do
840                                 {
841                                         if (mi)
842                                                 mime = mi->name;
843                                         sub = acontrol->subapp;
844                                         do
845                                         {
846                                                 if (sub)
847                                                         subapp = sub->name;
848                                                 ui = acontrol->uri;
849                                                 do
850                                                 {
851                                                         if (ui)
852                                                                 uri = ui->name;
853                                                         snprintf(query, MAX_QUERY_LEN,
854                                                                  "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
855                                                                 "values('%s', '%s', '%s', '%s', '%s')",\
856                                                                  up->appid, operation, uri, mime, subapp);
857
858                                                         ret = __exec_query(query);
859                                                         if (ret == -1) {
860                                                                 DBG("Package UiApp AppSvc DB Insert Failed\n");
861                                                                 return -1;
862                                                         }
863                                                         memset(query, '\0', MAX_QUERY_LEN);
864                                                         if (ui)
865                                                                 ui = ui->next;
866                                                         uri = NULL;
867                                                 } while(ui != NULL);
868                                                 if (sub)
869                                                         sub = sub->next;
870                                                 subapp = NULL;
871                                         }while(sub != NULL);
872                                         if (mi)
873                                                 mi = mi->next;
874                                         mime = NULL;
875                                 }while(mi != NULL);
876                                 if (op)
877                                         op = op->next;
878                                 operation = NULL;
879                         }
880                         acontrol = acontrol->next;
881                 }
882                 up = up->next;
883         }
884         return 0;
885 }
886
887 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
888 {
889         uiapplication_x *up = mfx->uiapplication;
890         appsvc_x *asvc = NULL;
891         operation_x *op = NULL;
892         mime_x *mi = NULL;
893         uri_x *ui = NULL;
894         subapp_x *sub = NULL;
895         int ret = -1;
896         char query[MAX_QUERY_LEN] = {'\0'};
897         char *operation = NULL;
898         char *mime = NULL;
899         char *uri = NULL;
900         char *subapp = NULL;
901         while(up != NULL)
902         {
903                 asvc = up->appsvc;
904                 while(asvc != NULL)
905                 {
906                         op = asvc->operation;
907                         while(op != NULL)
908                         {
909                                 if (op)
910                                         operation = op->name;
911                                 mi = asvc->mime;
912
913                                 do
914                                 {
915                                         if (mi)
916                                                 mime = mi->name;
917                                         sub = asvc->subapp;
918                                         do
919                                         {
920                                                 if (sub)
921                                                         subapp = sub->name;
922                                                 ui = asvc->uri;
923                                                 do
924                                                 {
925                                                         if (ui)
926                                                                 uri = ui->name;
927                                                         snprintf(query, MAX_QUERY_LEN,
928                                                                  "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
929                                                                 "values('%s', '%s', '%s', '%s', '%s')",\
930                                                                  up->appid, operation, uri, mime, subapp);
931
932                                                         ret = __exec_query(query);
933                                                         if (ret == -1) {
934                                                                 DBG("Package UiApp AppSvc DB Insert Failed\n");
935                                                                 return -1;
936                                                         }
937                                                         memset(query, '\0', MAX_QUERY_LEN);
938                                                         if (ui)
939                                                                 ui = ui->next;
940                                                         uri = NULL;
941                                                 } while(ui != NULL);
942                                                 if (sub)
943                                                         sub = sub->next;
944                                                 subapp = NULL;
945                                         }while(sub != NULL);
946                                         if (mi)
947                                                 mi = mi->next;
948                                         mime = NULL;
949                                 }while(mi != NULL);
950                                 if (op)
951                                         op = op->next;
952                                 operation = NULL;
953                         }
954                         asvc = asvc->next;
955                 }
956                 up = up->next;
957         }
958         return 0;
959 }
960
961 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
962 {
963         uiapplication_x *up = mfx->uiapplication;
964         datashare_x *ds = NULL;
965         request_x *rq = NULL;
966         int ret = -1;
967         char query[MAX_QUERY_LEN] = {'\0'};
968         while(up != NULL)
969         {
970                 ds = up->datashare;
971                 while(ds != NULL)
972                 {
973                         rq = ds->request;
974                         while(rq != NULL)
975                         {
976                                 snprintf(query, MAX_QUERY_LEN,
977                                          "insert into package_app_share_request(app_id, data_share_request) " \
978                                         "values('%s', '%s')",\
979                                          up->appid, rq->text);
980                                 ret = __exec_query(query);
981                                 if (ret == -1) {
982                                         DBG("Package UiApp Share Request DB Insert Failed\n");
983                                         return -1;
984                                 }
985                                 memset(query, '\0', MAX_QUERY_LEN);
986                                 rq = rq->next;
987                         }
988                         ds = ds->next;
989                 }
990                 up = up->next;
991         }
992         return 0;
993 }
994
995 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
996 {
997         uiapplication_x *up = mfx->uiapplication;
998         datashare_x *ds = NULL;
999         define_x *df = NULL;
1000         allowed_x *al = NULL;
1001         int ret = -1;
1002         char query[MAX_QUERY_LEN] = {'\0'};
1003         while(up != NULL)
1004         {
1005                 ds = up->datashare;
1006                 while(ds != NULL)
1007                 {
1008                         df = ds->define;
1009                         while(df != NULL)
1010                         {
1011                                 al = df->allowed;
1012                                 while(al != NULL)
1013                                 {
1014                                         snprintf(query, MAX_QUERY_LEN,
1015                                                  "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1016                                                 "values('%s', '%s', '%s')",\
1017                                                  up->appid, df->path, al->text);
1018                                         ret = __exec_query(query);
1019                                         if (ret == -1) {
1020                                                 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1021                                                 return -1;
1022                                         }
1023                                         memset(query, '\0', MAX_QUERY_LEN);
1024                                         al = al->next;
1025                                 }
1026                                 df = df->next;
1027                         }
1028                         ds = ds->next;
1029                 }
1030                 up = up->next;
1031         }
1032         return 0;
1033 }
1034
1035 static int __insert_serviceapplication_info(manifest_x *mfx)
1036 {
1037         serviceapplication_x *sp = mfx->serviceapplication;
1038         int ret = -1;
1039         char query[MAX_QUERY_LEN] = {'\0'};
1040         while(sp != NULL)
1041         {
1042                 snprintf(query, MAX_QUERY_LEN,
1043                          "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
1044                         "app_multiple, app_autorestart, package) " \
1045                         "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1046                          sp->appid, "svcapp", sp->exec, "\0", sp->type, sp->onboot, "\0",
1047                          sp->autorestart, mfx->package);
1048                 ret = __exec_query(query);
1049                 if (ret == -1) {
1050                         DBG("Package ServiceApp Info DB Insert Failed\n");
1051                         return -1;
1052                 }
1053                 sp = sp->next;
1054                 memset(query, '\0', MAX_QUERY_LEN);
1055         }
1056         return 0;
1057 }
1058
1059 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1060 {
1061         serviceapplication_x *sp = mfx->serviceapplication;
1062         category_x *ct = NULL;
1063         int ret = -1;
1064         char query[MAX_QUERY_LEN] = {'\0'};
1065         while(sp != NULL)
1066         {
1067                 ct = sp->category;
1068                 while (ct != NULL)
1069                 {
1070                         snprintf(query, MAX_QUERY_LEN,
1071                                 "insert into package_app_app_category(app_id, category) " \
1072                                 "values('%s','%s')",\
1073                                  sp->appid, ct->name);
1074                         ret = __exec_query(query);
1075                         if (ret == -1) {
1076                                 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1077                                 return -1;
1078                         }
1079                         ct = ct->next;
1080                         memset(query, '\0', MAX_QUERY_LEN);
1081                 }
1082                 sp = sp->next;
1083         }
1084         return 0;
1085 }
1086
1087 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1088 {
1089         serviceapplication_x *sp = mfx->serviceapplication;
1090         appcontrol_x *acontrol = NULL;
1091         int ret = -1;
1092         char query[MAX_QUERY_LEN] = {'\0'};
1093         operation_x *op = NULL;
1094         mime_x *mi = NULL;
1095         uri_x *ui = NULL;
1096         subapp_x *sub = NULL;
1097         char *operation = NULL;
1098         char *mime = NULL;
1099         char *uri = NULL;
1100         char *subapp = NULL;
1101         while(sp != NULL)
1102         {
1103                 acontrol = sp->appcontrol;
1104                 while(acontrol != NULL)
1105                 {
1106                         op = acontrol->operation;
1107                         while(op != NULL)
1108                         {
1109                         if (op)
1110                                 operation = op->name;
1111                         mi = acontrol->mime;
1112                                 do
1113                                 {
1114                                 if (mi)
1115                                         mime = mi->name;
1116                                 sub = acontrol->subapp;
1117                                         do
1118                                         {
1119                                         if (sub)
1120                                                 subapp = sub->name;
1121                                         ui = acontrol->uri;
1122                                                 do
1123                                                 {
1124                                                         if (ui)
1125                                                                 uri = ui->name;
1126                                                         snprintf(query, MAX_QUERY_LEN,
1127                                                                  "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1128                                                                 "values('%s', '%s', '%s', '%s', '%s')",\
1129                                                                  sp->appid, operation, uri, mime, subapp);
1130                                                         ret = __exec_query(query);
1131                                                         if (ret == -1) {
1132                                                                 DBG("Package UiApp AppSvc DB Insert Failed\n");
1133                                                                 return -1;
1134                                                         }
1135                                                         memset(query, '\0', MAX_QUERY_LEN);
1136                                                         if (ui)
1137                                                                 ui = ui->next;
1138                                                         uri = NULL;
1139                                                 } while(ui != NULL);
1140                                                 if (sub)
1141                                                         sub = sub->next;
1142                                                 subapp = NULL;
1143                                                 }while(sub != NULL);
1144                                         if (mi)
1145                                                 mi = mi->next;
1146                                         mime = NULL;
1147                                 }while(mi != NULL);
1148                                 if (op)
1149                                         op = op->next;
1150                                 operation = NULL;
1151                         }
1152                         acontrol = acontrol->next;
1153                 }
1154                 sp = sp->next;
1155         }
1156         return 0;
1157 }
1158
1159 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1160 {
1161         serviceapplication_x *sp = mfx->serviceapplication;
1162         appsvc_x *asvc = NULL;
1163         int ret = -1;
1164         char query[MAX_QUERY_LEN] = {'\0'};
1165         operation_x *op = NULL;
1166         mime_x *mi = NULL;
1167         uri_x *ui = NULL;
1168         subapp_x *sub = NULL;
1169         char *operation = NULL;
1170         char *mime = NULL;
1171         char *uri = NULL;
1172         char *subapp = NULL;
1173         while(sp != NULL)
1174         {
1175                 asvc = sp->appsvc;
1176                 while(asvc != NULL)
1177                 {
1178                         op = asvc->operation;
1179                         while(op != NULL)
1180                         {
1181                         if (op)
1182                                 operation = op->name;
1183                         mi = asvc->mime;
1184                                 do
1185                                 {
1186                                 if (mi)
1187                                         mime = mi->name;
1188                                 sub = asvc->subapp;
1189                                         do
1190                                         {
1191                                         if (sub)
1192                                                 subapp = sub->name;
1193                                         ui = asvc->uri;
1194                                                         do
1195                                                         {
1196                                                                 if (ui)
1197                                                                         uri = ui->name;
1198                                                                 snprintf(query, MAX_QUERY_LEN,
1199                                                                          "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1200                                                                         "values('%s', '%s', '%s', '%s', '%s')",\
1201                                                                          sp->appid, operation, uri, mime, subapp);
1202                                                                 ret = __exec_query(query);
1203                                                                 if (ret == -1) {
1204                                                                         DBG("Package UiApp AppSvc DB Insert Failed\n");
1205                                                                         return -1;
1206                                                                 }
1207                                                                 memset(query, '\0', MAX_QUERY_LEN);
1208                                                                 if (ui)
1209                                                                         ui = ui->next;
1210                                                                 uri = NULL;
1211                                                         } while(ui != NULL);
1212                                                 if (sub)
1213                                                         sub     = sub->next;
1214                                                 subapp = NULL;
1215                                         }while(sub != NULL);
1216                                         if (mi)
1217                                                 mi = mi->next;
1218                                         mime = NULL;
1219                                 }while(mi != NULL);
1220                                 if (op)
1221                                         op = op->next;
1222                                 operation = NULL;
1223                         }
1224                         asvc = asvc->next;
1225                 }
1226                 sp = sp->next;
1227         }
1228         return 0;
1229 }
1230
1231
1232
1233 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1234 {
1235         serviceapplication_x *sp = mfx->serviceapplication;
1236         datashare_x *ds = NULL;
1237         request_x *rq = NULL;
1238         int ret = -1;
1239         char query[MAX_QUERY_LEN] = {'\0'};
1240         while(sp != NULL)
1241         {
1242                 ds = sp->datashare;
1243                 while(ds != NULL)
1244                 {
1245                         rq = ds->request;
1246                         while(rq != NULL)
1247                         {
1248                                 snprintf(query, MAX_QUERY_LEN,
1249                                          "insert into package_app_share_request(app_id, data_share_request) " \
1250                                         "values('%s', '%s')",\
1251                                          sp->appid, rq->text);
1252                                 ret = __exec_query(query);
1253                                 if (ret == -1) {
1254                                         DBG("Package ServiceApp Share Request DB Insert Failed\n");
1255                                         return -1;
1256                                 }
1257                                 memset(query, '\0', MAX_QUERY_LEN);
1258                                 rq = rq->next;
1259                         }
1260                         ds = ds->next;
1261                 }
1262                 sp = sp->next;
1263         }
1264         return 0;
1265 }
1266
1267
1268
1269 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1270 {
1271         serviceapplication_x *sp = mfx->serviceapplication;
1272         datashare_x *ds = NULL;
1273         define_x *df = NULL;
1274         allowed_x *al = NULL;
1275         int ret = -1;
1276         char query[MAX_QUERY_LEN] = {'\0'};
1277         while(sp != NULL)
1278         {
1279                 ds = sp->datashare;
1280                 while(ds != NULL)
1281                 {
1282                         df = ds->define;
1283                         while(df != NULL)
1284                         {
1285                                 al = df->allowed;
1286                                 while(al != NULL)
1287                                 {
1288                                         snprintf(query, MAX_QUERY_LEN,
1289                                                  "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1290                                                 "values('%s', '%s', '%s')",\
1291                                                  sp->appid, df->path, al->text);
1292                                         ret = __exec_query(query);
1293                                         if (ret == -1) {
1294                                                 DBG("Package App Share Allowed DB Insert Failed\n");
1295                                                 return -1;
1296                                         }
1297                                         memset(query, '\0', MAX_QUERY_LEN);
1298                                         al = al->next;
1299                                 }
1300                                 df = df->next;
1301                         }
1302                         ds = ds->next;
1303                 }
1304                 sp = sp->next;
1305         }
1306         return 0;
1307 }
1308
1309 static int __insert_manifest_info_in_db(manifest_x *mfx)
1310 {
1311         label_x *lbl = mfx->label;
1312         license_x *lcn = mfx->license;
1313         icon_x *icn = mfx->icon;
1314         description_x *dcn = mfx->description;
1315         author_x *ath = mfx->author;
1316         uiapplication_x *up = mfx->uiapplication;
1317         uiapplication_x *up_icn = mfx->uiapplication;
1318         serviceapplication_x *sp = mfx->serviceapplication;
1319         char query[MAX_QUERY_LEN] = { '\0' };
1320         int ret = -1;
1321         char *type = NULL;
1322         char *auth_name = NULL;
1323         char *auth_email = NULL;
1324         char *auth_href = NULL;
1325         if (ath) {
1326                 if (ath->text)
1327                         auth_name = ath->text;
1328                 if (ath->email)
1329                         auth_email = ath->email;
1330                 if (ath->href)
1331                         auth_href = ath->href;
1332         }
1333
1334         /*Insert in the package_info DB*/
1335         if (mfx->type)
1336                 type = strdup(mfx->type);
1337         else
1338                 type = strdup("rpm");
1339         snprintf(query, MAX_QUERY_LEN,
1340                  "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1341                 "package_removable, package_preload, package_readonly, author_name, author_email, author_href, installed_time, storeclient_id, mainapp_id, package_url) " \
1342                 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1343                  mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1344                  mfx->readonly, auth_name, auth_email, auth_href, mfx->installed_time, mfx->storeclient_id, mfx->mainapp_id, mfx->package_url);
1345         ret = __exec_query(query);
1346         if (ret == -1) {
1347                 DBG("Package Info DB Insert Failed\n");
1348                 if (type) {
1349                         free(type);
1350                         type = NULL;
1351                 }
1352                 return -1;
1353         }
1354         if (type) {
1355                 free(type);
1356                 type = NULL;
1357         }
1358         /*Insert the package locale and app locale info */
1359         pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1360         g_list_foreach(pkglocale, __trimfunc1, NULL);
1361         prev = NULL;
1362
1363         while(up != NULL)
1364         {
1365                 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1366                 up = up->next;
1367         }
1368         while(sp != NULL)
1369         {
1370                 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1371                 sp = sp->next;
1372         }
1373         g_list_foreach(applocale, __trimfunc2, NULL);
1374         prev = NULL;
1375
1376         /*Insert the app icon info */
1377         while(up_icn != NULL)
1378         {
1379                 appicon = __create_icon_list(appicon, up_icn->icon);
1380                 up_icn = up_icn->next;
1381         }
1382         g_list_foreach(appicon, __trimfunc3, NULL);
1383         prev = NULL;
1384
1385         /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1386         /*DBG("\n");*/
1387         /*g_list_foreach(applocale, __printfunc, NULL);*/
1388
1389         /*package locale info*/
1390         g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1391         /*native app locale info*/
1392         up = mfx->uiapplication;
1393         while(up != NULL)
1394         {
1395                 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1396                 up = up->next;
1397         }
1398         /*agent app locale info*/
1399         sp = mfx->serviceapplication;
1400         while(sp != NULL)
1401         {
1402                 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1403                 sp = sp->next;
1404         }
1405
1406         /*app icon locale info*/
1407         up_icn = mfx->uiapplication;
1408         while(up_icn != NULL)
1409         {
1410                 g_list_foreach(appicon, __insert_uiapplication_icon_locale_info, (gpointer)up_icn);
1411                 up_icn = up_icn->next;
1412         }
1413
1414         g_list_free(pkglocale);
1415         pkglocale = NULL;
1416         g_list_free(applocale);
1417         applocale = NULL;
1418         g_list_free(appicon);
1419         appicon = NULL;
1420
1421
1422         /*Insert in the package_app_info DB*/
1423         ret = __insert_uiapplication_info(mfx);
1424         if (ret == -1)
1425                 return -1;
1426         ret = __insert_ui_mainapp_info(mfx);
1427         if (ret == -1)
1428                 return -1;
1429         ret = __insert_serviceapplication_info(mfx);
1430         if (ret == -1)
1431                 return -1;
1432
1433         /*Insert in the package_app_app_control DB*/
1434         ret = __insert_uiapplication_appcontrol_info(mfx);
1435         if (ret == -1)
1436                 return -1;
1437         ret = __insert_serviceapplication_appcontrol_info(mfx);
1438         if (ret == -1)
1439                 return -1;
1440
1441         /*Insert in the package_app_app_category DB*/
1442         ret = __insert_uiapplication_appcategory_info(mfx);
1443         if (ret == -1)
1444                 return -1;
1445         ret = __insert_serviceapplication_appcategory_info(mfx);
1446         if (ret == -1)
1447                 return -1;
1448
1449         /*Insert in the package_app_app_svc DB*/
1450         ret = __insert_uiapplication_appsvc_info(mfx);
1451         if (ret == -1)
1452                 return -1;
1453         ret = __insert_serviceapplication_appsvc_info(mfx);
1454         if (ret == -1)
1455                 return -1;
1456
1457         /*Insert in the package_app_share_allowed DB*/
1458         ret = __insert_uiapplication_share_allowed_info(mfx);
1459         if (ret == -1)
1460                 return -1;
1461         ret = __insert_serviceapplication_share_allowed_info(mfx);
1462         if (ret == -1)
1463                 return -1;
1464
1465         /*Insert in the package_app_share_request DB*/
1466         ret = __insert_uiapplication_share_request_info(mfx);
1467         if (ret == -1)
1468                 return -1;
1469         ret = __insert_serviceapplication_share_request_info(mfx);
1470         if (ret == -1)
1471                 return -1;
1472
1473         return 0;
1474
1475 }
1476
1477 static int __delete_cert_info_from_db(manifest_x *mfx)
1478 {
1479         char query[MAX_QUERY_LEN] = { '\0' };
1480         int ret = -1;
1481         char *error_message = NULL;
1482
1483         ret = __pkgmgr_parser_cert_create_db();
1484         if (ret == -1) {
1485                 DBG("Failed to open DB\n");
1486                 return ret;
1487         }
1488
1489         /*Begin transaction*/
1490         ret = sqlite3_exec(pkgmgr_cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1491         if (ret != SQLITE_OK) {
1492                 DBG("Failed to begin transaction\n");
1493                 sqlite3_close(pkgmgr_cert_db);
1494                 return -1;
1495         }
1496         DBG("Transaction Begin\n");
1497         snprintf(query, MAX_QUERY_LEN,
1498                  "delete from package_cert_info where package='%s'", mfx->package);
1499
1500         if (SQLITE_OK !=
1501             sqlite3_exec(pkgmgr_cert_db, query, NULL, NULL, &error_message)) {
1502                 DBG("Don't execute query = %s error message = %s\n", query,
1503                        error_message);
1504                 ret = -1;
1505         }
1506         sqlite3_free(error_message);
1507
1508         if (ret == -1) {
1509                 DBG("Delete from DB failed. Rollback now\n");
1510                 sqlite3_exec(pkgmgr_cert_db, "ROLLBACK", NULL, NULL, NULL);
1511                 sqlite3_close(pkgmgr_cert_db);
1512                 return -1;
1513         }
1514         /*Commit transaction*/
1515         ret = sqlite3_exec(pkgmgr_cert_db, "COMMIT", NULL, NULL, NULL);
1516         if (ret != SQLITE_OK) {
1517                 DBG("Failed to commit transaction, Rollback now\n");
1518                 sqlite3_exec(pkgmgr_cert_db, "ROLLBACK", NULL, NULL, NULL);
1519                 sqlite3_close(pkgmgr_cert_db);
1520                 return -1;
1521         }
1522         DBG("Transaction Commit and End\n");
1523         sqlite3_free(error_message);
1524         sqlite3_close(pkgmgr_cert_db);
1525         return 0;
1526
1527 }
1528
1529 static int __delete_manifest_info_from_db(manifest_x *mfx)
1530 {
1531         char query[MAX_QUERY_LEN] = { '\0' };
1532         int ret = -1;
1533         uiapplication_x *up = mfx->uiapplication;
1534         serviceapplication_x *sp = mfx->serviceapplication;
1535
1536         ret = __delete_cert_info_from_db(mfx);
1537         if (ret == -1) {
1538                 DBG("Package cert DB Delete Failed\n");
1539                 return -1;
1540         }
1541
1542         /*Delete from Package Info DB*/
1543         snprintf(query, MAX_QUERY_LEN,
1544                  "delete from package_info where package='%s'", mfx->package);
1545         ret = __exec_query(query);
1546         if (ret == -1) {
1547                 DBG("Package Info DB Delete Failed\n");
1548                 return -1;
1549         }
1550         memset(query, '\0', MAX_QUERY_LEN);
1551
1552         /*Delete from Package Localized Info*/
1553         snprintf(query, MAX_QUERY_LEN,
1554                  "delete from package_localized_info where package='%s'", mfx->package);
1555         ret = __exec_query(query);
1556         if (ret == -1) {
1557                 DBG("Package Localized Info DB Delete Failed\n");
1558                 return -1;
1559         }
1560         memset(query, '\0', MAX_QUERY_LEN);
1561
1562         /*Delete from Package App Info*/
1563         while(up != NULL)
1564         {
1565                 snprintf(query, MAX_QUERY_LEN,
1566                          "delete from package_app_info where app_id='%s'", up->appid);
1567                 ret = __exec_query(query);
1568                 if (ret == -1) {
1569                         DBG("Package App Info DB Delete Failed\n");
1570                         return -1;
1571                 }
1572                 memset(query, '\0', MAX_QUERY_LEN);
1573                 up = up->next;
1574         }
1575         while(sp != NULL)
1576         {
1577                 snprintf(query, MAX_QUERY_LEN,
1578                          "delete from package_app_info where app_id='%s'", sp->appid);
1579                 ret = __exec_query(query);
1580                 if (ret == -1) {
1581                         DBG("Package App Info DB Delete Failed\n");
1582                         return -1;
1583                 }
1584                 memset(query, '\0', MAX_QUERY_LEN);
1585                 sp = sp->next;
1586         }
1587
1588         /*Delete from Package App Localized Info*/
1589         up = mfx->uiapplication;
1590         sp = mfx->serviceapplication;
1591         while(up != NULL)
1592         {
1593                 snprintf(query, MAX_QUERY_LEN,
1594                          "delete from package_app_localized_info where app_id='%s'", up->appid);
1595                 ret = __exec_query(query);
1596                 if (ret == -1) {
1597                         DBG("Package App Localized Info DB Delete Failed\n");
1598                         return -1;
1599                 }
1600                 memset(query, '\0', MAX_QUERY_LEN);
1601                 up = up->next;
1602         }
1603         while(sp != NULL)
1604         {
1605                 snprintf(query, MAX_QUERY_LEN,
1606                          "delete from package_app_localized_info where app_id='%s'", sp->appid);
1607                 ret = __exec_query(query);
1608                 if (ret == -1) {
1609                         DBG("Package App Localized Info DB Delete Failed\n");
1610                         return -1;
1611                 }
1612                 memset(query, '\0', MAX_QUERY_LEN);
1613                 sp = sp->next;
1614         }
1615
1616         /*Delete from Package App App-Svc*/
1617         up = mfx->uiapplication;
1618         sp = mfx->serviceapplication;
1619         while(up != NULL)
1620         {
1621                 snprintf(query, MAX_QUERY_LEN,
1622                          "delete from package_app_app_svc where app_id='%s'", up->appid);
1623                 ret = __exec_query(query);
1624                 if (ret == -1) {
1625                         DBG("Package App App-Svc DB Delete Failed\n");
1626                         return -1;
1627                 }
1628                 memset(query, '\0', MAX_QUERY_LEN);
1629                 up = up->next;
1630         }
1631         while(sp != NULL)
1632         {
1633                 snprintf(query, MAX_QUERY_LEN,
1634                          "delete from package_app_app_svc where app_id='%s'", sp->appid);
1635                 ret = __exec_query(query);
1636                 if (ret == -1) {
1637                         DBG("Package App App-Svc DB Delete Failed\n");
1638                         return -1;
1639                 }
1640                 memset(query, '\0', MAX_QUERY_LEN);
1641                 sp = sp->next;
1642         }
1643
1644         /*Delete from Package App App-Control*/
1645         up = mfx->uiapplication;
1646         sp = mfx->serviceapplication;
1647         while(up != NULL)
1648         {
1649                 snprintf(query, MAX_QUERY_LEN,
1650                          "delete from package_app_app_control where app_id='%s'", up->appid);
1651                 ret = __exec_query(query);
1652                 if (ret == -1) {
1653                         DBG("Package App App-Control DB Delete Failed\n");
1654                         return -1;
1655                 }
1656                 memset(query, '\0', MAX_QUERY_LEN);
1657                 up = up->next;
1658         }
1659         while(sp != NULL)
1660         {
1661                 snprintf(query, MAX_QUERY_LEN,
1662                          "delete from package_app_app_control where app_id='%s'", sp->appid);
1663                 ret = __exec_query(query);
1664                 if (ret == -1) {
1665                         DBG("Package App App-Control DB Delete Failed\n");
1666                         return -1;
1667                 }
1668                 memset(query, '\0', MAX_QUERY_LEN);
1669                 sp = sp->next;
1670         }
1671
1672         /*Delete from Package App App-Category*/
1673         up = mfx->uiapplication;
1674         sp = mfx->serviceapplication;
1675         while(up != NULL)
1676         {
1677                 snprintf(query, MAX_QUERY_LEN,
1678                          "delete from package_app_app_category where app_id='%s'", up->appid);
1679                 ret = __exec_query(query);
1680                 if (ret == -1) {
1681                         DBG("Package App App-Category DB Delete Failed\n");
1682                         return -1;
1683                 }
1684                 memset(query, '\0', MAX_QUERY_LEN);
1685                 up = up->next;
1686         }
1687         while(sp != NULL)
1688         {
1689                 snprintf(query, MAX_QUERY_LEN,
1690                          "delete from package_app_app_category where app_id='%s'", sp->appid);
1691                 ret = __exec_query(query);
1692                 if (ret == -1) {
1693                         DBG("Package App App-Category DB Delete Failed\n");
1694                         return -1;
1695                 }
1696                 memset(query, '\0', MAX_QUERY_LEN);
1697                 sp = sp->next;
1698         }
1699
1700         /*Delete from Package App Share Allowed*/
1701         up = mfx->uiapplication;
1702         sp = mfx->serviceapplication;
1703         while(up != NULL)
1704         {
1705                 snprintf(query, MAX_QUERY_LEN,
1706                          "delete from package_app_share_allowed where app_id='%s'", up->appid);
1707                 ret = __exec_query(query);
1708                 if (ret == -1) {
1709                         DBG("Package App Share Allowed DB Delete Failed\n");
1710                         return -1;
1711                 }
1712                 memset(query, '\0', MAX_QUERY_LEN);
1713                 up = up->next;
1714         }
1715         while(sp != NULL)
1716         {
1717                 snprintf(query, MAX_QUERY_LEN,
1718                          "delete from package_app_share_allowed where app_id='%s'", sp->appid);
1719                 ret = __exec_query(query);
1720                 if (ret == -1) {
1721                         DBG("Package App Share Allowed DB Delete Failed\n");
1722                         return -1;
1723                 }
1724                 memset(query, '\0', MAX_QUERY_LEN);
1725                 sp = sp->next;
1726         }
1727
1728         /*Delete from Package App Share Request*/
1729         up = mfx->uiapplication;
1730         sp = mfx->serviceapplication;
1731         while(up != NULL)
1732         {
1733                 snprintf(query, MAX_QUERY_LEN,
1734                          "delete from package_app_share_request where app_id='%s'", up->appid);
1735                 ret = __exec_query(query);
1736                 if (ret == -1) {
1737                         DBG("Package App Share Request DB Delete Failed\n");
1738                         return -1;
1739                 }
1740                 memset(query, '\0', MAX_QUERY_LEN);
1741                 up = up->next;
1742         }
1743         while(sp != NULL)
1744         {
1745                 snprintf(query, MAX_QUERY_LEN,
1746                          "delete from package_app_share_request where app_id='%s'", sp->appid);
1747                 ret = __exec_query(query);
1748                 if (ret == -1) {
1749                         DBG("Package App Share Request DB Delete Failed\n");
1750                         return -1;
1751                 }
1752                 memset(query, '\0', MAX_QUERY_LEN);
1753                 sp = sp->next;
1754         }
1755         return 0;
1756 }
1757
1758
1759 int pkgmgr_parser_initialize_db()
1760 {
1761         int ret = -1;
1762         ret = __initialize_package_info_db();
1763         if (ret == -1) {
1764                 DBG("package info DB initialization failed\n");
1765                 return ret;
1766         }
1767         ret = __initialize_package_localized_info_db();
1768         if (ret == -1) {
1769                 DBG("package localized info DB initialization failed\n");
1770                 return ret;
1771         }
1772         ret = __initialize_package_cert_info_db();
1773         if (ret == -1) {
1774                 DBG("package cert info DB initialization failed\n");
1775                 return ret;
1776         }
1777         ret = __initialize_package_app_info_db();
1778         if (ret == -1) {
1779                 DBG("package app info DB initialization failed\n");
1780                 return ret;
1781         }
1782         ret = __initialize_package_app_localized_info_db();
1783         if (ret == -1) {
1784                 DBG("package app localized info DB initialization failed\n");
1785                 return ret;
1786         }
1787         ret = __initialize_package_app_icon_localized_info_db();
1788         if (ret == -1) {
1789                 DBG("package app icon localized info DB initialization failed\n");
1790                 return ret;
1791         }
1792         ret = __initialize_package_app_app_control_db();
1793         if (ret == -1) {
1794                 DBG("package app app control DB initialization failed\n");
1795                 return ret;
1796         }
1797         ret = __initialize_package_app_app_category_db();
1798         if (ret == -1) {
1799                 DBG("package app app category DB initialization failed\n");
1800                 return ret;
1801         }
1802         ret = __initialize_package_app_app_svc_db();
1803         if (ret == -1) {
1804                 DBG("package app app svc DB initialization failed\n");
1805                 return ret;
1806         }
1807         ret = __initialize_package_app_share_allowed_db();
1808         if (ret == -1) {
1809                 DBG("package app share allowed DB initialization failed\n");
1810                 return ret;
1811         }
1812         ret = __initialize_package_app_share_request_db();
1813         if (ret == -1) {
1814                 DBG("package app share request DB initialization failed\n");
1815                 return ret;
1816         }
1817         return 0;
1818 }
1819
1820 int pkgmgr_parser_check_and_create_db()
1821 {
1822         int ret = -1;
1823         if (access(PKGMGR_PARSER_DB_FILE, F_OK) == 0) {
1824                 ret =
1825                     db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
1826                                  DB_UTIL_REGISTER_HOOK_METHOD);
1827                 if (ret != SQLITE_OK) {
1828                         DBG("connect db [%s] failed!\n",
1829                                PKGMGR_PARSER_DB_FILE);
1830                         return -1;
1831                 }
1832                 return 0;
1833         }
1834         DBG("Pkgmgr DB does not exists. Create one!!\n");
1835
1836         ret =
1837             db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
1838                          DB_UTIL_REGISTER_HOOK_METHOD);
1839
1840         if (ret != SQLITE_OK) {
1841                 DBG("connect db [%s] failed!\n", PKGMGR_PARSER_DB_FILE);
1842                 return -1;
1843         }
1844         return 0;
1845 }
1846
1847 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1848 {
1849         if (mfx == NULL) {
1850                 DBG("manifest pointer is NULL\n");
1851                 return -1;
1852         }
1853         int ret = -1;
1854         ret = pkgmgr_parser_check_and_create_db();
1855         if (ret == -1) {
1856                 DBG("Failed to open DB\n");
1857                 return ret;
1858         }
1859         ret = pkgmgr_parser_initialize_db();
1860         if (ret == -1)
1861                 return ret;
1862         /*Begin transaction*/
1863         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1864         if (ret != SQLITE_OK) {
1865                 DBG("Failed to begin transaction\n");
1866                 sqlite3_close(pkgmgr_parser_db);
1867                 return -1;
1868         }
1869         DBG("Transaction Begin\n");
1870         ret = __insert_manifest_info_in_db(mfx);
1871         if (ret == -1) {
1872                 DBG("Insert into DB failed. Rollback now\n");
1873                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1874                 sqlite3_close(pkgmgr_parser_db);
1875                 return -1;
1876         }
1877         /*Commit transaction*/
1878         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1879         if (ret != SQLITE_OK) {
1880                 DBG("Failed to commit transaction. Rollback now\n");
1881                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1882                 sqlite3_close(pkgmgr_parser_db);
1883                 return -1;
1884         }
1885         DBG("Transaction Commit and End\n");
1886         sqlite3_close(pkgmgr_parser_db);
1887         return 0;
1888 }
1889
1890 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1891 {
1892         if (mfx == NULL) {
1893                 DBG("manifest pointer is NULL\n");
1894                 return -1;
1895         }
1896         int ret = -1;
1897         ret = pkgmgr_parser_check_and_create_db();
1898         if (ret == -1) {
1899                 DBG("Failed to open DB\n");
1900                 return ret;
1901         }
1902         ret = pkgmgr_parser_initialize_db();
1903         if (ret == -1)
1904                 return ret;
1905
1906         /*Begin transaction*/
1907         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1908         if (ret != SQLITE_OK) {
1909                 DBG("Failed to begin transaction\n");
1910                 sqlite3_close(pkgmgr_parser_db);
1911                 return -1;
1912         }
1913         DBG("Transaction Begin\n");
1914         ret = __delete_manifest_info_from_db(mfx);
1915         if (ret == -1) {
1916                 DBG("Delete from DB failed. Rollback now\n");
1917                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1918                 sqlite3_close(pkgmgr_parser_db);
1919                 return -1;
1920         }
1921         ret = __insert_manifest_info_in_db(mfx);
1922         if (ret == -1) {
1923                 DBG("Insert into DB failed. Rollback now\n");
1924                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1925                 sqlite3_close(pkgmgr_parser_db);
1926                 return -1;
1927         }
1928
1929         /*Commit transaction*/
1930         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1931         if (ret != SQLITE_OK) {
1932                 DBG("Failed to commit transaction. Rollback now\n");
1933                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1934                 sqlite3_close(pkgmgr_parser_db);
1935                 return -1;
1936         }
1937         DBG("Transaction Commit and End\n");
1938         sqlite3_close(pkgmgr_parser_db);
1939         return 0;
1940 }
1941
1942 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1943 {
1944         if (mfx == NULL) {
1945                 DBG("manifest pointer is NULL\n");
1946                 return -1;
1947         }
1948         int ret = -1;
1949         ret = pkgmgr_parser_check_and_create_db();
1950         if (ret == -1) {
1951                 DBG("Failed to open DB\n");
1952                 return ret;
1953         }
1954         /*Begin transaction*/
1955         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1956         if (ret != SQLITE_OK) {
1957                 DBG("Failed to begin transaction\n");
1958                 sqlite3_close(pkgmgr_parser_db);
1959                 return -1;
1960         }
1961         DBG("Transaction Begin\n");
1962         ret = __delete_manifest_info_from_db(mfx);
1963         if (ret == -1) {
1964                 DBG("Delete from DB failed. Rollback now\n");
1965                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1966                 sqlite3_close(pkgmgr_parser_db);
1967                 return -1;
1968         }
1969         /*Commit transaction*/
1970         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1971         if (ret != SQLITE_OK) {
1972                 DBG("Failed to commit transaction, Rollback now\n");
1973                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1974                 sqlite3_close(pkgmgr_parser_db);
1975                 return -1;
1976         }
1977         DBG("Transaction Commit and End\n");
1978         sqlite3_close(pkgmgr_parser_db);
1979         return 0;
1980 }