tizen 2.3.1 release
[framework/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 <dlfcn.h>
32
33 #include "pkgmgr_parser_internal.h"
34 #include "pkgmgr_parser_db.h"
35
36 #include "pkgmgrinfo_debug.h"
37 #include "pkgmgrinfo_type.h"
38
39 #ifdef LOG_TAG
40 #undef LOG_TAG
41 #endif
42 #define LOG_TAG "PKGMGR_PARSER"
43
44 #define MAX_QUERY_LEN           4096
45 #define MAX_PACKAGE_STR_SIZE 512
46 #define MAX_ALIAS_INI_ENTRY     (2 * MAX_PACKAGE_STR_SIZE) + 1
47 #define USR_APPSVC_ALIAS_INI "/usr/share/appsvc/alias.ini"
48 #define OPT_APPSVC_ALIAS_INI "/opt/usr/share/appsvc/alias.ini"
49 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
50 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
51
52 sqlite3 *pkgmgr_parser_db;
53 sqlite3 *pkgmgr_cert_db;
54
55
56 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
57                                                 "(package text primary key not null, " \
58                                                 "package_type text DEFAULT 'rpm', " \
59                                                 "package_version text, " \
60                                                 "install_location text, " \
61                                                 "package_size text, " \
62                                                 "package_removable text DEFAULT 'true', " \
63                                                 "package_preload text DEFAULT 'false', " \
64                                                 "package_readonly text DEFAULT 'false', " \
65                                                 "package_update text DEFAULT 'false', " \
66                                                 "package_appsetting text DEFAULT 'false', " \
67                                                 "package_nodisplay text DEFAULT 'false', " \
68                                                 "package_system text DEFAULT 'false', " \
69                                                 "author_name text, " \
70                                                 "author_email text, " \
71                                                 "author_href text," \
72                                                 "installed_time text," \
73                                                 "installed_storage text," \
74                                                 "storeclient_id text," \
75                                                 "mainapp_id text," \
76                                                 "package_url text," \
77                                                 "root_path text," \
78                                                 "csc_path text," \
79                                                 "package_support_disable text DEFAULT 'false', " \
80                                                 "package_mother_package text DEFAULT 'false', " \
81                                                 "package_disable text DEFAULT 'false', " \
82                                                 "package_support_mode text, " \
83                                                 "package_hash text, " \
84                                                 "package_reserve1 text," \
85                                                 "package_reserve2 text," \
86                                                 "package_reserve3 text," \
87                                                 "package_reserve4 text," \
88                                                 "package_reserve5 text)"
89
90 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
91                                                 "(package text not null, " \
92                                                 "package_locale text DEFAULT 'No Locale', " \
93                                                 "package_label text, " \
94                                                 "package_icon text, " \
95                                                 "package_description text, " \
96                                                 "package_license text, " \
97                                                 "package_author, " \
98                                                 "PRIMARY KEY(package, package_locale), " \
99                                                 "FOREIGN KEY(package) " \
100                                                 "REFERENCES package_info(package) " \
101                                                 "ON DELETE CASCADE)"
102
103 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
104                                                 "(package text not null, " \
105                                                 "privilege text not null, " \
106                                                 "PRIMARY KEY(package, privilege) " \
107                                                 "FOREIGN KEY(package) " \
108                                                 "REFERENCES package_info(package) " \
109                                                 "ON DELETE CASCADE)"
110
111 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
112                                                 "(app_id text primary key not null, " \
113                                                 "app_component text, " \
114                                                 "app_exec text, " \
115                                                 "app_ambient_support text DEFAULT 'false', " \
116                                                 "app_nodisplay text DEFAULT 'false', " \
117                                                 "app_type text, " \
118                                                 "app_onboot text DEFAULT 'false', " \
119                                                 "app_multiple text DEFAULT 'false', " \
120                                                 "app_autorestart text DEFAULT 'false', " \
121                                                 "app_taskmanage text DEFAULT 'false', " \
122                                                 "app_enabled text DEFAULT 'true', " \
123                                                 "app_hwacceleration text DEFAULT 'default', " \
124                                                 "app_screenreader text DEFAULT 'use-system-setting', " \
125                                                 "app_mainapp text, " \
126                                                 "app_recentimage text, " \
127                                                 "app_launchcondition text, " \
128                                                 "app_indicatordisplay text DEFAULT 'true', " \
129                                                 "app_portraitimg text, " \
130                                                 "app_landscapeimg text, " \
131                                                 "app_effectimage_type text, " \
132                                                 "app_guestmodevisibility text DEFAULT 'true', " \
133                                                 "app_permissiontype text DEFAULT 'normal', " \
134                                                 "app_preload text DEFAULT 'false', " \
135                                                 "app_submode text DEFAULT 'false', " \
136                                                 "app_submode_mainid text, " \
137                                                 "app_installed_storage text, " \
138                                                 "app_process_pool text DEFAULT 'false', " \
139                                                 "app_multi_instance text DEFAULT 'false', " \
140                                                 "app_multi_instance_mainid text, " \
141                                                 "app_multi_window text DEFAULT 'false', " \
142                                                 "app_support_disable text DEFAULT 'false', " \
143                                                 "app_disable text DEFAULT 'false', " \
144                                                 "app_ui_gadget text DEFAULT 'false', " \
145                                                 "app_removable text DEFAULT 'false', " \
146                                                 "app_support_mode text, " \
147                                                 "app_support_feature text, " \
148                                                 "component_type text, " \
149                                                 "package text not null, " \
150                                                 "app_package_type text DEFAULT 'rpm', " \
151                                                 "app_package_system text, " \
152                                                 "app_package_installed_time text, " \
153                                                 "app_reserve1 text, " \
154                                                 "app_reserve2 text, " \
155                                                 "app_reserve3 text, " \
156                                                 "app_reserve4 text, " \
157                                                 "app_reserve5 text, " \
158                                                 "FOREIGN KEY(package) " \
159                                                 "REFERENCES package_info(package) " \
160                                                 "ON DELETE CASCADE)"
161
162 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
163                                                 "(app_id text not null, " \
164                                                 "app_locale text DEFAULT 'No Locale', " \
165                                                 "app_label text, " \
166                                                 "app_icon text, " \
167                                                 "PRIMARY KEY(app_id,app_locale) " \
168                                                 "FOREIGN KEY(app_id) " \
169                                                 "REFERENCES package_app_info(app_id) " \
170                                                 "ON DELETE CASCADE)"
171
172 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
173                                                 "(app_id text not null, " \
174                                                 "app_icon text, " \
175                                                 "app_icon_section text, " \
176                                                 "app_icon_resolution text, " \
177                                                 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
178                                                 "FOREIGN KEY(app_id) " \
179                                                 "REFERENCES package_app_info(app_id) " \
180                                                 "ON DELETE CASCADE)"
181
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
183                                                 "(app_id text not null, " \
184                                                 "app_locale text DEFAULT 'No Locale', " \
185                                                 "app_image_section text, " \
186                                                 "app_image text, " \
187                                                 "PRIMARY KEY(app_id,app_image_section) " \
188                                                 "FOREIGN KEY(app_id) " \
189                                                 "REFERENCES package_app_info(app_id) " \
190                                                 "ON DELETE CASCADE)"
191
192 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
193                                                 "(app_id text not null, " \
194                                                 "app_control text not null, " \
195                                                 "PRIMARY KEY(app_id,app_control) " \
196                                                 "FOREIGN KEY(app_id) " \
197                                                 "REFERENCES package_app_info(app_id) " \
198                                                 "ON DELETE CASCADE)"
199
200 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
201                                                 "(app_id text not null, " \
202                                                 "operation text not null, " \
203                                                 "uri_scheme text, " \
204                                                 "mime_type text, " \
205                                                 "subapp_name text, " \
206                                                 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
207                                                 "FOREIGN KEY(app_id) " \
208                                                 "REFERENCES package_app_info(app_id) " \
209                                                 "ON DELETE CASCADE)"
210
211 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
212                                                 "(app_id text not null, " \
213                                                 "category text not null, " \
214                                                 "PRIMARY KEY(app_id,category) " \
215                                                 "FOREIGN KEY(app_id) " \
216                                                 "REFERENCES package_app_info(app_id) " \
217                                                 "ON DELETE CASCADE)"
218
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
220                                                 "(app_id text not null, " \
221                                                 "md_key text not null, " \
222                                                 "md_value text not null, " \
223                                                 "PRIMARY KEY(app_id, md_key, md_value) " \
224                                                 "FOREIGN KEY(app_id) " \
225                                                 "REFERENCES package_app_info(app_id) " \
226                                                 "ON DELETE CASCADE)"
227
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
229                                                 "(app_id text not null, " \
230                                                 "pm_type text not null, " \
231                                                 "pm_value text not null, " \
232                                                 "PRIMARY KEY(app_id, pm_type, pm_value) " \
233                                                 "FOREIGN KEY(app_id) " \
234                                                 "REFERENCES package_app_info(app_id) " \
235                                                 "ON DELETE CASCADE)"
236
237 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
238                                                 "(app_id text not null, " \
239                                                 "data_share_path text not null, " \
240                                                 "data_share_allowed text not null, " \
241                                                 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
242                                                 "FOREIGN KEY(app_id) " \
243                                                 "REFERENCES package_app_info(app_id) " \
244                                                 "ON DELETE CASCADE)"
245
246 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
247                                                 "(app_id text not null, " \
248                                                 "data_share_request text not null, " \
249                                                 "PRIMARY KEY(app_id,data_share_request) " \
250                                                 "FOREIGN KEY(app_id) " \
251                                                 "REFERENCES package_app_info(app_id) " \
252                                                 "ON DELETE CASCADE)"
253
254 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
255                                                 "(cert_info text not null, " \
256                                                 "cert_id integer, " \
257                                                 "cert_ref_count integer, " \
258                                                 "PRIMARY KEY(cert_id)) "
259
260 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
261                                                 "(package text not null, " \
262                                                 "author_root_cert integer, " \
263                                                 "author_im_cert integer, " \
264                                                 "author_signer_cert integer, " \
265                                                 "dist_root_cert integer, " \
266                                                 "dist_im_cert integer, " \
267                                                 "dist_signer_cert integer, " \
268                                                 "dist2_root_cert integer, " \
269                                                 "dist2_im_cert integer, " \
270                                                 "dist2_signer_cert integer, " \
271                                                 "PRIMARY KEY(package)) "
272
273 #define QUERY_CREATE_TABLE_PACKAGE_PKG_RESERVE "create table if not exists package_pkg_reserve " \
274                                                 "(pkgid text not null, " \
275                                                 "reserve1 text, " \
276                                                 "reserve2 text, " \
277                                                 "reserve3 text, " \
278                                                 "reserve4 text, " \
279                                                 "reserve5 text, " \
280                                                 "PRIMARY KEY(pkgid)) "
281
282 #define QUERY_CREATE_TABLE_PACKAGE_APP_RESERVE "create table if not exists package_app_reserve " \
283                                                 "(app_id text not null, " \
284                                                 "reserve1 text, " \
285                                                 "reserve2 text, " \
286                                                 "reserve3 text, " \
287                                                 "reserve4 text, " \
288                                                 "reserve5 text, " \
289                                                 "PRIMARY KEY(app_id)) "
290
291 #define QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO "create table if not exists package_plugin_info " \
292                                                 "(pkgid text primary key not null, " \
293                                                 "enabled_plugin INTEGER DEFAULT 0)"
294
295 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
296                                                 "(app_id text not null, " \
297                                                 "providerid text not null, " \
298                                                 "access text not null, " \
299                                                 "type text not null, " \
300                                                 "PRIMARY KEY(app_id, providerid, access, type) " \
301                                                 "FOREIGN KEY(app_id) " \
302                                                 "REFERENCES package_app_info(app_id) " \
303                                                 "ON DELETE CASCADE)"
304
305 #define QUERY_CREATE_TABLE_PACKAGE_APP_ALIASID "create table if not exists package_app_aliasid" \
306                                                 "(app_id text primary key not null, "\
307                                                 "alias_id text not null)"
308
309 static int __insert_uiapplication_info(manifest_x *mfx);
310 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
311 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
312 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
313 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
314 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
315 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
316 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
317 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
318 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
319 static int __delete_manifest_info_from_pkgid(const char *pkgid);
320 static int __delete_manifest_info_from_appid(const char *appid);
321 static int __insert_manifest_info_in_db(manifest_x *mfx);
322 static int __delete_manifest_info_from_db(manifest_x *mfx);
323 static int __delete_appinfo_from_db(char *db_table, const char *appid);
324 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
325 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
326
327 static void __str_trim(char *input)
328 {
329         char *trim_str = input;
330
331         if (input == NULL)
332                 return;
333
334         while (*input != 0) {
335                 if (!isspace(*input)) {
336                         *trim_str = *input;
337                         trim_str++;
338                 }
339                 input++;
340         }
341
342         *trim_str = 0;
343         return;
344 }
345
346 const char *__get_str(const char *str)
347 {
348         if (str == NULL)
349         {
350                 return PKGMGR_PARSER_EMPTY_STR;
351         }
352
353         return str;
354 }
355
356 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
357 {
358         int ret = -1;
359         sqlite3 *handle;
360         if (access(db_path, F_OK) == 0) {
361                 ret =
362                     db_util_open(db_path, &handle,
363                                  DB_UTIL_REGISTER_HOOK_METHOD);
364                 if (ret != SQLITE_OK) {
365                         _LOGD("connect db [%s] failed!\n",
366                                db_path);
367                         return -1;
368                 }
369                 *db_handle = handle;
370                 return 0;
371         }
372         _LOGD("%s DB does not exists. Create one!!\n", db_path);
373
374         ret =
375             db_util_open(db_path, &handle,
376                          DB_UTIL_REGISTER_HOOK_METHOD);
377
378         if (ret != SQLITE_OK) {
379                 _LOGD("connect db [%s] failed!\n", db_path);
380                 return -1;
381         }
382         *db_handle = handle;
383         return 0;
384 }
385
386 int __evaluate_query(sqlite3 *db_handle, char *query)
387 {
388         sqlite3_stmt* p_statement;
389         int result;
390     result = sqlite3_prepare_v2(db_handle, query, strlen(query), &p_statement, NULL);
391     if (result != SQLITE_OK) {
392         _LOGE("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result, sqlite3_errmsg(db_handle), query);
393                 return -1;
394     }
395
396         result = sqlite3_step(p_statement);
397         if (result != SQLITE_DONE) {
398                 _LOGE("Sqlite3 error [%d] : <%s> executing <%s> statement\n", result, sqlite3_errmsg(db_handle), query);
399                 return -1;
400         }
401
402         result = sqlite3_finalize(p_statement);
403         if (result != SQLITE_OK) {
404                 _LOGE("Sqlite3 error [%d] : <%s> finalizing <%s> statement\n", result, sqlite3_errmsg(db_handle), query);
405                 return -1;
406         }
407         return 0;
408 }
409
410 int __initialize_db(sqlite3 *db_handle, char *db_query)
411 {
412         return (__evaluate_query(db_handle, db_query));
413 }
414
415 int __exec_query(char *query)
416 {
417         return (__evaluate_query(pkgmgr_parser_db, query));
418 }
419
420 int __exec_query_no_msg(char *query)
421 {
422         char *error_message = NULL;
423         if (SQLITE_OK !=
424             sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
425                 sqlite3_free(error_message);
426                 return -1;
427         }
428         sqlite3_free(error_message);
429         return 0;
430 }
431
432 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
433 {
434         char *error_message = NULL;
435         if (SQLITE_OK !=
436             sqlite3_exec(db, query, callback, data, &error_message)) {
437                 _LOGE("Don't execute query = %s error message = %s\n", query,
438                        error_message);
439                 sqlite3_free(error_message);
440                 return -1;
441         }
442         sqlite3_free(error_message);
443         return 0;
444 }
445
446 GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
447 {
448
449         while(lbl != NULL)
450         {
451                 if (lbl->lang)
452                         locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
453                 lbl = lbl->next;
454         }
455         while(lcn != NULL)
456         {
457                 if (lcn->lang)
458                         locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
459                 lcn = lcn->next;
460         }
461         while(icn != NULL)
462         {
463                 if (icn->lang)
464                         locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
465                 icn = icn->next;
466         }
467         while(dcn != NULL)
468         {
469                 if (dcn->lang)
470                         locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
471                 dcn = dcn->next;
472         }
473         while(ath != NULL)
474         {
475                 if (ath->lang)
476                         locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
477                 ath = ath->next;
478         }
479         return locale;
480
481 }
482
483 static GList *__create_icon_list(GList *locale, icon_x *icn)
484 {
485         while(icn != NULL)
486         {
487                 if (icn->section)
488                         locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
489                 icn = icn->next;
490         }
491         return locale;
492 }
493
494 static GList *__create_image_list(GList *locale, image_x *image)
495 {
496         while(image != NULL)
497         {
498                 if (image->section)
499                         locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
500                 image = image->next;
501         }
502         return locale;
503 }
504
505 void __trimfunc(GList* trim_list)
506 {
507         char *trim_data = NULL;
508         char *prev = NULL;
509
510         GList *list = NULL;
511         list = g_list_first(trim_list);
512
513         while (list) {
514                 trim_data = (char *)list->data;
515                 if (trim_data) {
516                         if (prev) {
517                                 if (strcmp(trim_data, prev) == 0) {
518                                         trim_list = g_list_remove(trim_list, trim_data);
519                                         list = g_list_first(trim_list);
520                                         prev = NULL;
521                                         continue;
522                                 } else
523                                         prev = trim_data;
524                         }
525                         else
526                                 prev = trim_data;
527                 }
528                 list = g_list_next(list);
529         }
530 }
531
532 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
533 {
534         if (a == NULL || b == NULL)
535                 return 0;
536         if (strcmp((char*)a, (char*)b) == 0)
537                 return 0;
538         if (strcmp((char*)a, (char*)b) < 0)
539                 return -1;
540         if (strcmp((char*)a, (char*)b) > 0)
541                 return 1;
542         return 0;
543 }
544
545 void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
546                 char **label, char **license, char **icon, char **description, char **author)
547 {
548         while(lbl != NULL)
549         {
550                 if (lbl->lang) {
551                         if (strcmp(lbl->lang, (char *)data) == 0) {
552                                 *label = (char*)lbl->text;
553                                 break;
554                         }
555                 }
556                 lbl = lbl->next;
557         }
558         while(lcn != NULL)
559         {
560                 if (lcn->lang) {
561                         if (strcmp(lcn->lang, (char *)data) == 0) {
562                                 *license = (char*)lcn->text;
563                                 break;
564                         }
565                 }
566                 lcn = lcn->next;
567         }
568         while(icn != NULL)
569         {
570                 if (icn->section == NULL) {
571                         if (icn->lang) {
572                                 if (strcmp(icn->lang, (char *)data) == 0) {
573                                         *icon = (char*)icn->text;
574                                         break;
575                                 }
576                         }
577                 }
578                 icn = icn->next;
579         }
580         while(dcn != NULL)
581         {
582                 if (dcn->lang) {
583                         if (strcmp(dcn->lang, (char *)data) == 0) {
584                                 *description = (char*)dcn->text;
585                                 break;
586                         }
587                 }
588                 dcn = dcn->next;
589         }
590         while(ath != NULL)
591         {
592                 if (ath->lang) {
593                         if (strcmp(ath->lang, (char *)data) == 0) {
594                                 *author = (char*)ath->text;
595                                 break;
596                         }
597                 }
598                 ath = ath->next;
599         }
600
601 }
602
603 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
604 {
605         while(icn != NULL)
606         {
607                 if (icn->section) {
608                         if (strcmp(icn->section, (char *)data) == 0) {
609                                 *icon = (char*)icn->text;
610                                 *resolution = (char*)icn->resolution;
611                                 break;
612                         }
613                 }
614                 icn = icn->next;
615         }
616 }
617
618 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
619 {
620         while(image != NULL)
621         {
622                 if (image->section) {
623                         if (strcmp(image->section, (char *)data) == 0) {
624                                 *lang = (char*)image->lang;
625                                 *img = (char*)image->text;
626                                 break;
627                         }
628                 }
629                 image = image->next;
630         }
631 }
632
633 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
634 {
635         int ret = -1;
636         char *label = NULL;
637         char *icon = NULL;
638         char *description = NULL;
639         char *license = NULL;
640         char *author = NULL;
641         char *query = NULL;
642
643         manifest_x *mfx = (manifest_x *)userdata;
644         label_x *lbl = mfx->label;
645         license_x *lcn = mfx->license;
646         icon_x *icn = mfx->icon;
647         description_x *dcn = mfx->description;
648         author_x *ath = mfx->author;
649
650         __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
651         if (!label && !description && !icon && !license && !author)
652                 return;
653
654         query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
655                 "package_label, package_icon, package_description, package_license, package_author) values " \
656                 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
657                 mfx->package,
658                 (char*)data,
659                 __get_str(label),
660                 __get_str(icon),
661                 __get_str(description),
662                 __get_str(license),
663                 __get_str(author));
664
665         ret = __exec_query(query);
666         if (ret == -1)
667                 _LOGD("Package Localized Info DB Insert failed\n");
668
669         sqlite3_free(query);
670 }
671
672 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
673 {
674         uiapplication_x *up = mfx->uiapplication;
675         datacontrol_x *dc = NULL;
676         int ret = -1;
677         char *query = NULL;
678
679         while (up != NULL)
680         {
681                 dc = up->datacontrol;
682                 while (dc != NULL) {
683                         query = sqlite3_mprintf("insert into package_app_data_control(app_id, providerid, access, type) " \
684                                 "values(%Q, %Q, %Q, %Q)", \
685                                 up->appid,
686                                 dc->providerid,
687                                 dc->access,
688                                 dc->type);
689
690                         ret = __exec_query(query);
691                         sqlite3_free(query);
692                         if (ret == -1) {
693                                 _LOGD("Package UiApp Data Control DB Insert Failed\n");
694                                 return -1;
695                         }
696                         dc = dc->next;
697                 }
698                 up = up->next;
699         }
700         return 0;
701 }
702
703 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
704 {
705         int ret = -1;
706         char *label = NULL;
707         char *icon = NULL;
708         char *query = NULL;
709
710         uiapplication_x *up = (uiapplication_x*)userdata;
711         label_x *lbl = up->label;
712         icon_x *icn = up->icon;
713
714         __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
715         if (!label && !icon)
716                 return;
717
718         query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
719                 "app_label, app_icon) values " \
720                 "(%Q, %Q, %Q, %Q)", up->appid, (char*)data,
721                 __get_str(label), __get_str(icon));
722         ret = __exec_query(query);
723         if (ret == -1)
724                 _LOGD("Package UiApp Localized Info DB Insert failed\n");
725
726         sqlite3_free(query);
727
728         /*insert ui app locale info to pkg locale to get mainapp data */
729         if (strcasecmp(up->mainapp, "true")==0) {
730                 char *update_query = NULL;
731                 update_query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
732                         "package_label, package_icon, package_description, package_license, package_author) values " \
733                         "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
734                         up->package,
735                         (char*)data,
736                         __get_str(label),
737                         __get_str(icon),
738                         PKGMGR_PARSER_EMPTY_STR,
739                         PKGMGR_PARSER_EMPTY_STR,
740                         PKGMGR_PARSER_EMPTY_STR);
741
742                 ret = __exec_query_no_msg(update_query);
743                 sqlite3_free(update_query);
744
745                 if (icon != NULL) {
746                         update_query = sqlite3_mprintf("update package_localized_info set package_icon=%Q " \
747                                 "where package=%Q and package_locale=%Q", icon, up->package, (char*)data);
748                         ret = __exec_query_no_msg(update_query);
749                         sqlite3_free(update_query);
750                 }
751         }
752 }
753
754 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
755 {
756         int ret = -1;
757         char *icon = NULL;
758         char *resolution = NULL;
759         char * query = NULL;
760
761         uiapplication_x *up = (uiapplication_x*)userdata;
762         icon_x *icn = up->icon;
763
764         __extract_icon_data(data, icn, &icon, &resolution);
765         if (!icon && !resolution)
766                 return;
767
768         query = sqlite3_mprintf("insert into package_app_icon_section_info(app_id, " \
769                 "app_icon, app_icon_section, app_icon_resolution) values " \
770                 "(%Q, %Q, %Q, %Q)", up->appid,
771                 icon, (char*)data, resolution);
772
773         ret = __exec_query(query);
774         if (ret == -1)
775                 _LOGD("Package UiApp Localized Info DB Insert failed\n");
776
777         sqlite3_free(query);
778 }
779
780 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
781 {
782         int ret = -1;
783         char *lang = NULL;
784         char *img = NULL;
785         char *query = NULL;
786
787         uiapplication_x *up = (uiapplication_x*)userdata;
788         image_x *image = up->image;
789
790         __extract_image_data(data, image, &lang, &img);
791         if (!lang && !img)
792                 return;
793
794         query = sqlite3_mprintf("insert into package_app_image_info(app_id, app_locale, " \
795                 "app_image_section, app_image) values " \
796                 "(%Q, %Q, %Q, %Q)", up->appid, lang, (char*)data, img);
797
798         ret = __exec_query(query);
799         if (ret == -1)
800                 _LOGD("Package UiApp image Info DB Insert failed\n");
801
802         sqlite3_free(query);
803 }
804
805 static int __insert_ui_mainapp_info(manifest_x *mfx)
806 {
807         uiapplication_x *up = mfx->uiapplication;
808         int ret = -1;
809         char *query = NULL;
810         while(up != NULL)
811         {
812                 query = sqlite3_mprintf("update package_app_info set app_mainapp=%Q where app_id=%Q", up->mainapp, up->appid);
813
814                 ret = __exec_query(query);
815                 sqlite3_free(query);
816                 if (ret == -1) {
817                         _LOGD("Package UiApp Info DB Insert Failed\n");
818                         return -1;
819                 }
820                 if (strcasecmp(up->mainapp, "True") == 0) {
821                         FREE_AND_NULL(mfx->mainapp_id);
822                         mfx->mainapp_id = strdup(up->appid);
823                 }
824
825                 up = up->next;
826         }
827
828         if (mfx->mainapp_id == NULL){
829                 if (mfx->uiapplication && mfx->uiapplication->appid) {
830                         query = sqlite3_mprintf("update package_app_info set app_mainapp='true' where app_id=%Q", mfx->uiapplication->appid);
831                 } else {
832                         _LOGD("Not valid appid\n");
833                         return -1;
834                 }
835
836                 ret = __exec_query(query);
837                 sqlite3_free(query);
838                 if (ret == -1) {
839                         _LOGD("Package UiApp Info DB Insert Failed\n");
840                         return -1;
841                 }
842
843                 FREE_AND_NULL(mfx->uiapplication->mainapp);
844                 mfx->uiapplication->mainapp= strdup("true");
845                 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
846         }
847
848         query = sqlite3_mprintf("update package_info set mainapp_id=%Q where package=%Q", mfx->mainapp_id, mfx->package);
849         ret = __exec_query(query);
850         sqlite3_free(query);
851         if (ret == -1) {
852                 _LOGD("Package Info DB update Failed\n");
853                 return -1;
854         }
855
856         return 0;
857 }
858 /* _PRODUCT_LAUNCHING_ENHANCED_
859 *  up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
860 */
861 static int __insert_uiapplication_info(manifest_x *mfx)
862 {
863         uiapplication_x *up = mfx->uiapplication;
864         int ret = -1;
865         char *query = NULL;
866         char *type = NULL;
867
868         if (mfx->type)
869                 type = strdup(mfx->type);
870         else
871                 type = strdup("rpm");
872
873         while(up != NULL)
874         {
875                 query = sqlite3_mprintf("insert into package_app_info(app_id, app_component, app_exec, app_ambient_support, app_nodisplay, app_type, app_onboot, " \
876                         "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
877                         "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_effectimage_type, app_guestmodevisibility, app_permissiontype, "\
878                         "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, app_multi_instance, app_multi_instance_mainid, app_multi_window, app_support_disable, "\
879                         "app_ui_gadget, app_removable, app_support_mode, app_support_feature, component_type, package, "\
880                         "app_package_type, app_package_system, app_package_installed_time"\
881                         ") " \
882                         "values(%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
883                         up->appid,
884                         "uiapp",
885                         up->exec,
886                         up->ambient_support,
887                         up->nodisplay,
888                         up->type,
889                         up->onboot,
890                         up->multiple,
891                         up->autorestart,
892                         up->taskmanage,
893                         up->enabled,
894                         up->hwacceleration,
895                         up->screenreader,
896                         up->mainapp,
897                         __get_str(up->recentimage),
898                         up->launchcondition,
899                         up->indicatordisplay,
900                         __get_str(up->portraitimg),
901                         __get_str(up->landscapeimg),
902                         __get_str(up->effectimage_type),
903                         up->guestmode_visibility,
904                         up->permission_type,
905                         mfx->preload,
906                         up->submode,
907                         __get_str(up->submode_mainid),
908                         mfx->installed_storage,
909                         up->process_pool,
910                         up->multi_instance,
911                         __get_str(up->multi_instance_mainid),
912                         up->multi_window,
913                         mfx->support_disable,
914                         up->ui_gadget,
915                         mfx->removable,
916                         mfx->support_mode,
917                         up->support_feature,
918                         up->component_type,
919                         mfx->package,
920                         type,
921                         mfx->system,
922                         mfx->installed_time
923                         );
924
925                 ret = __exec_query(query);
926                 sqlite3_free(query);
927                 if (ret == -1) {
928                         _LOGD("Package UiApp Info DB Insert Failed\n");
929                         FREE_AND_NULL(type);
930                         return -1;
931                 }
932                 up = up->next;
933         }
934         FREE_AND_NULL(type);
935         return 0;
936 }
937
938 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
939 {
940         uiapplication_x *up = mfx->uiapplication;
941         category_x *ct = NULL;
942         int ret = -1;
943         char *query = NULL;
944         while(up != NULL)
945         {
946                 ct = up->category;
947                 while (ct != NULL)
948                 {
949                         query = sqlite3_mprintf("insert into package_app_app_category(app_id, category) " \
950                                 "values(%Q, %Q)",\
951                                  up->appid, ct->name);
952                         ret = __exec_query(query);
953                         sqlite3_free(query);
954                         if (ret == -1) {
955                                 _LOGD("Package UiApp Category Info DB Insert Failed\n");
956                                 return -1;
957                         }
958                         ct = ct->next;
959                 }
960                 up = up->next;
961         }
962         return 0;
963 }
964
965 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
966 {
967         uiapplication_x *up = mfx->uiapplication;
968         metadata_x *md = NULL;
969         int ret = -1;
970         char *query = NULL;
971         while(up != NULL)
972         {
973                 md = up->metadata;
974                 while (md != NULL)
975                 {
976                         if (md->key) {
977                                 query = sqlite3_mprintf("insert into package_app_app_metadata(app_id, md_key, md_value) " \
978                                         "values(%Q, %Q, %Q)",\
979                                          up->appid, md->key, __get_str(md->value));
980                                 ret = __exec_query(query);
981                                 sqlite3_free(query);
982                                 if (ret == -1) {
983                                         _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
984                                         return -1;
985                                 }
986                         }
987                         md = md->next;
988                 }
989                 up = up->next;
990         }
991         return 0;
992 }
993
994 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
995 {
996         uiapplication_x *up = mfx->uiapplication;
997         permission_x *pm = NULL;
998         int ret = -1;
999         char *query = NULL;
1000         while(up != NULL)
1001         {
1002                 pm = up->permission;
1003                 while (pm != NULL)
1004                 {
1005                         query = sqlite3_mprintf("insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1006                                 "values(%Q, %Q, %Q)",\
1007                                  up->appid, pm->type, pm->value);
1008                         ret = __exec_query(query);
1009                         sqlite3_free(query);
1010                         if (ret == -1) {
1011                                 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1012                                 return -1;
1013                         }
1014                         pm = pm->next;
1015                 }
1016                 up = up->next;
1017         }
1018         return 0;
1019 }
1020
1021 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1022 {
1023         int ret = 0;
1024         char *buf = NULL;
1025         char *buftemp = NULL;
1026         char *query = NULL;
1027         uiapplication_x *up = mfx->uiapplication;
1028
1029         buf = (char *)calloc(1, BUFMAX);
1030         retvm_if(!buf, PMINFO_R_ERROR, "Malloc Failed\n");
1031
1032         buftemp = (char *)calloc(1, BUFMAX);
1033         tryvm_if(!buftemp, ret = PMINFO_R_ERROR, "Malloc Failed\n");
1034
1035         for(; up; up=up->next) {
1036                 if (up->appsvc) {
1037                         appsvc_x *asvc = NULL;
1038                         operation_x *op = NULL;
1039                         mime_x *mi = NULL;
1040                         uri_x *ui = NULL;
1041                         subapp_x *sub = NULL;
1042                         const char *operation = NULL;
1043                         const char *mime = NULL;
1044                         const char *uri = NULL;
1045                         const char *subapp = NULL;
1046                         int i = 0;
1047                         memset(buf, '\0', BUFMAX);
1048                         memset(buftemp, '\0', BUFMAX);
1049
1050                         asvc = up->appsvc;
1051                         while(asvc != NULL) {
1052                                 op = asvc->operation;
1053                                 while(op != NULL) {
1054                                         if (op)
1055                                                 operation = op->name;
1056                                         mi = asvc->mime;
1057
1058                                         do
1059                                         {
1060                                                 if (mi)
1061                                                         mime = mi->name;
1062                                                 sub = asvc->subapp;
1063                                                 do
1064                                                 {
1065                                                         if (sub)
1066                                                                 subapp = sub->name;
1067                                                         ui = asvc->uri;
1068                                                         do
1069                                                         {
1070                                                                 if (ui)
1071                                                                         uri = ui->name;
1072
1073                                                                 if(i++ > 0) {
1074                                                                         strncpy(buftemp, buf, BUFMAX);
1075                                                                         snprintf(buf, BUFMAX, "%s;", buftemp);
1076                                                                 }
1077
1078                                                                 strncpy(buftemp, buf, BUFMAX);
1079                                                                 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
1080 //                                                              _LOGD("buf[%s]\n", buf);
1081
1082                                                                 if (ui)
1083                                                                         ui = ui->next;
1084                                                                 uri = NULL;
1085                                                         } while(ui != NULL);
1086                                                         if (sub)
1087                                                                 sub = sub->next;
1088                                                         subapp = NULL;
1089                                                 }while(sub != NULL);
1090                                                 if (mi)
1091                                                         mi = mi->next;
1092                                                 mime = NULL;
1093                                         }while(mi != NULL);
1094                                         if (op)
1095                                                 op = op->next;
1096                                         operation = NULL;
1097                                 }
1098                                 asvc = asvc->next;
1099                         }
1100
1101                         query= sqlite3_mprintf("insert into package_app_app_control(app_id, app_control) values(%Q, %Q)", up->appid,  buf);
1102                         ret = __exec_query(query);
1103                         if (ret < 0) {
1104                                 _LOGD("Package UiApp app_control DB Insert Failed\n");
1105                         }
1106                         sqlite3_free(query);
1107                 }
1108         }
1109
1110 catch:
1111         FREE_AND_NULL(buf);
1112         FREE_AND_NULL(buftemp);
1113
1114         return 0;
1115 }
1116
1117 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1118 {
1119         uiapplication_x *up = mfx->uiapplication;
1120         appsvc_x *asvc = NULL;
1121         operation_x *op = NULL;
1122         mime_x *mi = NULL;
1123         uri_x *ui = NULL;
1124         subapp_x *sub = NULL;
1125         int ret = -1;
1126         char *query = NULL;
1127         const char *operation = NULL;
1128         const char *mime = NULL;
1129         const char *uri = NULL;
1130         const char *subapp = NULL;
1131         while(up != NULL)
1132         {
1133                 asvc = up->appsvc;
1134                 while(asvc != NULL)
1135                 {
1136                         op = asvc->operation;
1137                         while(op != NULL)
1138                         {
1139                                 if (op)
1140                                         operation = op->name;
1141                                 mi = asvc->mime;
1142
1143                                 do
1144                                 {
1145                                         if (mi)
1146                                                 mime = mi->name;
1147                                         sub = asvc->subapp;
1148                                         do
1149                                         {
1150                                                 if (sub)
1151                                                         subapp = sub->name;
1152                                                 ui = asvc->uri;
1153                                                 do
1154                                                 {
1155                                                         if (ui)
1156                                                                 uri = ui->name;
1157                                                         query = sqlite3_mprintf("insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1158                                                                 "values(%Q, %Q, %Q, %Q, %Q)",\
1159                                                                  up->appid,
1160                                                                  operation,
1161                                                                  __get_str(uri),
1162                                                                  __get_str(mime),
1163                                                                  __get_str(subapp));
1164
1165                                                         ret = __exec_query(query);
1166                                                         sqlite3_free(query);
1167                                                         if (ret == -1) {
1168                                                                 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1169                                                                 return -1;
1170                                                         }
1171                                                         if (ui)
1172                                                                 ui = ui->next;
1173                                                         uri = NULL;
1174                                                 } while(ui != NULL);
1175                                                 if (sub)
1176                                                         sub = sub->next;
1177                                                 subapp = NULL;
1178                                         }while(sub != NULL);
1179                                         if (mi)
1180                                                 mi = mi->next;
1181                                         mime = NULL;
1182                                 }while(mi != NULL);
1183                                 if (op)
1184                                         op = op->next;
1185                                 operation = NULL;
1186                         }
1187                         asvc = asvc->next;
1188                 }
1189                 up = up->next;
1190         }
1191         return 0;
1192 }
1193
1194 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1195 {
1196         uiapplication_x *up = mfx->uiapplication;
1197         datashare_x *ds = NULL;
1198         request_x *rq = NULL;
1199         int ret = -1;
1200         char *query = NULL;
1201         while(up != NULL)
1202         {
1203                 ds = up->datashare;
1204                 while(ds != NULL)
1205                 {
1206                         rq = ds->request;
1207                         while(rq != NULL)
1208                         {
1209                                 query = sqlite3_mprintf("insert into package_app_share_request(app_id, data_share_request) " \
1210                                         "values(%Q, %Q)",\
1211                                          up->appid, rq->text);
1212                                 ret = __exec_query(query);
1213                                 sqlite3_free(query);
1214                                 if (ret == -1) {
1215                                         _LOGD("Package UiApp Share Request DB Insert Failed\n");
1216                                         return -1;
1217                                 }
1218                                 rq = rq->next;
1219                         }
1220                         ds = ds->next;
1221                 }
1222                 up = up->next;
1223         }
1224         return 0;
1225 }
1226
1227 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1228 {
1229         uiapplication_x *up = mfx->uiapplication;
1230         datashare_x *ds = NULL;
1231         define_x *df = NULL;
1232         allowed_x *al = NULL;
1233         int ret = -1;
1234         char *query = NULL;
1235         while(up != NULL)
1236         {
1237                 ds = up->datashare;
1238                 while(ds != NULL)
1239                 {
1240                         df = ds->define;
1241                         while(df != NULL)
1242                         {
1243                                 al = df->allowed;
1244                                 while(al != NULL)
1245                                 {
1246                                         query = sqlite3_mprintf("insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1247                                                 "values(%Q, %Q, %Q)",\
1248                                                  up->appid, df->path, al->text);
1249                                         ret = __exec_query(query);
1250                                         sqlite3_free(query);
1251                                         if (ret == -1) {
1252                                                 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1253                                                 return -1;
1254                                         }
1255                                         al = al->next;
1256                                 }
1257                                 df = df->next;
1258                         }
1259                         ds = ds->next;
1260                 }
1261                 up = up->next;
1262         }
1263         return 0;
1264 }
1265
1266 static int __insert_manifest_info_in_db(manifest_x *mfx)
1267 {
1268         label_x *lbl = mfx->label;
1269         license_x *lcn = mfx->license;
1270         icon_x *icn = mfx->icon;
1271         description_x *dcn = mfx->description;
1272         author_x *ath = mfx->author;
1273         uiapplication_x *up = mfx->uiapplication;
1274         uiapplication_x *up_icn = mfx->uiapplication;
1275         uiapplication_x *up_image = mfx->uiapplication;
1276         privileges_x *pvs = NULL;
1277         privilege_x *pv = NULL;
1278         char *query = NULL;
1279         char root[MAX_QUERY_LEN] = { '\0' };
1280         int ret = -1;
1281         char *type = NULL;
1282         char *path = NULL;
1283         const char *auth_name = NULL;
1284         const char *auth_email = NULL;
1285         const char *auth_href = NULL;
1286
1287         GList *pkglocale = NULL;
1288         GList *applocale = NULL;
1289         GList *appicon = NULL;
1290         GList *appimage = NULL;
1291
1292         if (ath) {
1293                 if (ath->text)
1294                         auth_name = ath->text;
1295                 if (ath->email)
1296                         auth_email = ath->email;
1297                 if (ath->href)
1298                         auth_href = ath->href;
1299         }
1300
1301         /*Insert in the package_info DB*/
1302         if (mfx->type)
1303                 type = strdup(mfx->type);
1304         else
1305                 type = strdup("rpm");
1306         /*Insert in the package_info DB*/
1307         if (mfx->root_path) {
1308                 path = strdup(mfx->root_path);
1309         } else {
1310                 if (type && strcmp(type,"rpm")==0) {
1311                         snprintf(root, MAX_QUERY_LEN - 1, "/opt/share/packages/%s.xml", mfx->package);
1312                         if (access(root, F_OK) == 0) {
1313                                 memset(root, '\0', MAX_QUERY_LEN);
1314                                 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1315                         } else {
1316                                 memset(root, '\0', MAX_QUERY_LEN);
1317                                 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package);
1318                         }
1319                 } else {
1320                         snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1321                 }
1322
1323                 path = strdup(root);
1324         }
1325
1326         query = sqlite3_mprintf("insert into package_info(package, package_type, package_version, install_location, package_size, " \
1327                 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1328                 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable, " \
1329                 "package_mother_package, package_support_mode, package_reserve1, package_reserve2, package_hash) " \
1330                 "values(%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
1331                  mfx->package,
1332                  type,
1333                  mfx->version,
1334                  __get_str(mfx->installlocation),
1335                  __get_str(mfx->package_size),
1336                  mfx->removable,
1337                  mfx->preload,
1338                  mfx->readonly,
1339                  mfx->update,
1340                  mfx->appsetting,
1341                  mfx->nodisplay_setting,
1342                  mfx->system,
1343                  __get_str(auth_name),
1344                  __get_str(auth_email),
1345                  __get_str(auth_href),
1346                  mfx->installed_time,
1347                  mfx->installed_storage,
1348                  __get_str(mfx->storeclient_id),
1349                  mfx->mainapp_id,
1350                  __get_str(mfx->package_url),
1351                  path,
1352                  __get_str(mfx->csc_path),
1353                  mfx->support_disable,
1354                  mfx->mother_package,
1355                  mfx->support_mode,
1356                  __get_str(mfx->support_reset),
1357                  mfx->use_reset,
1358                  mfx->hash
1359                  );
1360
1361         ret = __exec_query(query);
1362         sqlite3_free(query);
1363         if (ret == -1) {
1364                 _LOGD("Package Info DB Insert Failed\n");
1365                 FREE_AND_NULL(type);
1366                 FREE_AND_NULL(path);
1367                 return -1;
1368         }
1369
1370         FREE_AND_NULL(type);
1371         FREE_AND_NULL(path);
1372
1373         /*Insert in the package_privilege_info DB*/
1374         pvs = mfx->privileges;
1375         while (pvs != NULL) {
1376                 pv = pvs->privilege;
1377                 while (pv != NULL) {
1378                         query = sqlite3_mprintf("insert into package_privilege_info(package, privilege) " \
1379                                 "values(%Q, %Q)",\
1380                                  mfx->package, pv->text);
1381                         ret = __exec_query(query);
1382                         sqlite3_free(query);
1383                         if (ret == -1) {
1384                                 _LOGD("Package Privilege Info DB Insert Failed\n");
1385                                 return -1;
1386                         }
1387                         pv = pv->next;
1388                 }
1389                 pvs = pvs->next;
1390         }
1391
1392         ret = __insert_ui_mainapp_info(mfx);
1393         if (ret == -1)
1394                 return -1;
1395
1396         /*Insert the package locale*/
1397         pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1398         /*remove duplicated data in pkglocale*/
1399         __trimfunc(pkglocale);
1400
1401         /*Insert the app locale info */
1402         while(up != NULL)
1403         {
1404                 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1405                 up = up->next;
1406         }
1407         /*remove duplicated data in applocale*/
1408         __trimfunc(applocale);
1409
1410         /*Insert the app icon info */
1411         while(up_icn != NULL)
1412         {
1413                 appicon = __create_icon_list(appicon, up_icn->icon);
1414                 up_icn = up_icn->next;
1415         }
1416         /*remove duplicated data in appicon*/
1417         __trimfunc(appicon);
1418
1419         /*Insert the image info */
1420         while(up_image != NULL)
1421         {
1422                 appimage = __create_image_list(appimage, up_image->image);
1423                 up_image = up_image->next;
1424         }
1425         /*remove duplicated data in appimage*/
1426         __trimfunc(appimage);
1427
1428         /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1429         /*_LOGD("\n");*/
1430         /*g_list_foreach(applocale, __printfunc, NULL);*/
1431
1432         g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1433
1434         /*native app locale info*/
1435         up = mfx->uiapplication;
1436         while(up != NULL)
1437         {
1438                 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1439                 up = up->next;
1440         }
1441
1442         /*app icon locale info*/
1443         up_icn = mfx->uiapplication;
1444         while(up_icn != NULL)
1445         {
1446                 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1447                 up_icn = up_icn->next;
1448         }
1449
1450         /*app image info*/
1451         up_image = mfx->uiapplication;
1452         while(up_image != NULL)
1453         {
1454                 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1455                 up_image = up_image->next;
1456         }
1457
1458         g_list_free(pkglocale);
1459         pkglocale = NULL;
1460         g_list_free(applocale);
1461         applocale = NULL;
1462         g_list_free(appicon);
1463         appicon = NULL;
1464         g_list_free(appimage);
1465         appimage = NULL;
1466
1467
1468         /*Insert in the package_app_info DB*/
1469         ret = __insert_uiapplication_info(mfx);
1470         if (ret == -1)
1471                 return -1;
1472
1473         /*Insert in the package_app_app_control DB*/
1474         ret = __insert_uiapplication_appcontrol_info(mfx);
1475         if (ret == -1)
1476                 return -1;
1477
1478         /*Insert in the package_app_app_category DB*/
1479         ret = __insert_uiapplication_appcategory_info(mfx);
1480         if (ret == -1)
1481                 return -1;
1482
1483         /*Insert in the package_app_app_metadata DB*/
1484         ret = __insert_uiapplication_appmetadata_info(mfx);
1485         if (ret == -1)
1486                 return -1;
1487
1488         /*Insert in the package_app_app_permission DB*/
1489         ret = __insert_uiapplication_apppermission_info(mfx);
1490         if (ret == -1)
1491                 return -1;
1492
1493         /*Insert in the package_app_app_svc DB*/
1494         ret = __insert_uiapplication_appsvc_info(mfx);
1495         if (ret == -1)
1496                 return -1;
1497
1498         /*Insert in the package_app_share_allowed DB*/
1499         ret = __insert_uiapplication_share_allowed_info(mfx);
1500         if (ret == -1)
1501                 return -1;
1502
1503         /*Insert in the package_app_share_request DB*/
1504         ret = __insert_uiapplication_share_request_info(mfx);
1505         if (ret == -1)
1506                 return -1;
1507
1508         /*Insert in the package_app_data_control DB*/
1509         ret = __insert_uiapplication_datacontrol_info(mfx);
1510         if (ret == -1)
1511                 return -1;
1512
1513         return 0;
1514
1515 }
1516
1517 static int __update_pkg_info_for_disable(const char *pkgid, bool disable)
1518 {
1519         char *query = NULL;
1520         int ret = -1;
1521
1522         /*Update from package info*/
1523         query = sqlite3_mprintf("update package_info set package_disable=%Q where package=%Q", disable?"true":"false", pkgid);
1524         ret = __exec_query(query);
1525         sqlite3_free(query);
1526         retvm_if(ret < 0, PMINFO_R_ERROR, "__exec_query() failed.\n");
1527
1528         /*Update from app info*/
1529         query = sqlite3_mprintf("update package_app_info set app_disable=%Q where package=%Q", disable?"true":"false", pkgid);
1530         ret = __exec_query(query);
1531         sqlite3_free(query);
1532         retvm_if(ret < 0, PMINFO_R_ERROR, "__exec_query() failed.\n");
1533
1534         return PMINFO_R_OK;
1535 }
1536
1537 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1538 {
1539         int ret = 0;
1540         char *query = sqlite3_mprintf("delete from %Q where app_id=%Q", db_table, appid);
1541         ret = __exec_query(query);
1542         sqlite3_free(query);
1543         if (ret == -1) {
1544                 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1545                 ret = -1;
1546         }
1547
1548         return ret;
1549 }
1550
1551 static int __delete_manifest_info_from_db(manifest_x *mfx)
1552 {
1553         int ret = -1;
1554         uiapplication_x *up = mfx->uiapplication;
1555
1556         /* Delete package info DB */
1557         ret = __delete_manifest_info_from_pkgid(mfx->package);
1558         retvm_if(ret < 0, PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
1559
1560         while (up != NULL) {
1561                 ret = __delete_manifest_info_from_appid(up->appid);
1562                 retvm_if(ret < 0, PMINFO_R_ERROR, "App Info DB Delete Failed\n");
1563
1564                 up = up->next;
1565         }
1566
1567         return 0;
1568 }
1569
1570 static int __delete_appsvc_db(const char *appid)
1571 {
1572         int ret = -1;
1573         void *lib_handle = NULL;
1574         int (*appsvc_operation) (const char *);
1575
1576         if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1577                 _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
1578                 return ret;
1579         }
1580         if ((appsvc_operation =
1581                  dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1582                 _LOGE("can not find symbol \n");
1583                 goto END;
1584         }
1585
1586         ret = appsvc_operation(appid);
1587
1588 END:
1589         if (lib_handle)
1590                 dlclose(lib_handle);
1591
1592         return ret;
1593 }
1594
1595 static int __delete_appsvc_info_from_db(manifest_x *mfx)
1596 {
1597         int ret = 0;
1598         uiapplication_x *uiapplication = mfx->uiapplication;
1599
1600         for(; uiapplication; uiapplication=uiapplication->next) {
1601                 ret = __delete_appsvc_db(uiapplication->appid);
1602                 if (ret <0)
1603                         _LOGE("can not remove_appsvc_db\n");
1604         }
1605
1606         return ret;
1607 }
1608
1609 static int __delete_manifest_info_from_pkgid(const char *pkgid)
1610 {
1611         char *query = NULL;
1612         int ret = -1;
1613
1614         /*Delete from cert table*/
1615         ret = pkgmgrinfo_delete_certinfo(pkgid);
1616         retvm_if(ret < 0, PMINFO_R_ERROR, "Cert Info  DB Delete Failed\n");
1617
1618         /*Delete from Package Info DB*/
1619         query = sqlite3_mprintf("delete from package_info where package=%Q", pkgid);
1620         ret = __exec_query(query);
1621         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
1622
1623         /*Delete from Package Localized Info*/
1624         sqlite3_free(query);
1625         query = sqlite3_mprintf("delete from package_localized_info where package=%Q", pkgid);
1626         ret = __exec_query(query);
1627         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Localized Info DB Delete Failed\n");
1628
1629         /*Delete from Package Privilege Info*/
1630         sqlite3_free(query);
1631         query = sqlite3_mprintf("delete from package_privilege_info where package=%Q", pkgid);
1632         ret = __exec_query(query);
1633         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Privilege Info DB Delete Failed\n");
1634
1635 catch:
1636         sqlite3_free(query);
1637         return 0;
1638 }
1639
1640
1641 static  int __delete_manifest_info_from_appid(const char *appid)
1642 {
1643         int ret = -1;
1644
1645         ret = __delete_appinfo_from_db("package_app_info", appid);
1646         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1647
1648         ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1649         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1650
1651         ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1652         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1653
1654         ret = __delete_appinfo_from_db("package_app_image_info", appid);
1655         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1656
1657         ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1658         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1659
1660         ret = __delete_appinfo_from_db("package_app_app_control", appid);
1661         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1662
1663         ret = __delete_appinfo_from_db("package_app_app_category", appid);
1664         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1665
1666         ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1667         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1668
1669         ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1670         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1671
1672         ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1673         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1674
1675         ret = __delete_appinfo_from_db("package_app_share_request", appid);
1676         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1677
1678         ret = __delete_appinfo_from_db("package_app_data_control", appid);
1679         retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1680
1681         return 0;
1682 }
1683
1684
1685 static int __update_preload_condition_in_db()
1686 {
1687         int ret = -1;
1688         char *query = NULL;
1689
1690         query = sqlite3_mprintf("update package_info set package_preload='true'");
1691
1692         ret = __exec_query(query);
1693         sqlite3_free(query);
1694         if (ret == -1)
1695                 _LOGD("Package preload_condition update failed\n");
1696
1697         return ret;
1698 }
1699
1700 int pkgmgr_parser_initialize_db()
1701 {
1702         int ret = -1;
1703         /*Manifest DB*/
1704         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1705         if (ret == -1) {
1706                 _LOGD("package info DB initialization failed\n");
1707                 return ret;
1708         }
1709         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1710         if (ret == -1) {
1711                 _LOGD("package localized info DB initialization failed\n");
1712                 return ret;
1713         }
1714         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1715         if (ret == -1) {
1716                 _LOGD("package app app privilege DB initialization failed\n");
1717                 return ret;
1718         }
1719         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1720         if (ret == -1) {
1721                 _LOGD("package app info DB initialization failed\n");
1722                 return ret;
1723         }
1724         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1725         if (ret == -1) {
1726                 _LOGD("package app localized info DB initialization failed\n");
1727                 return ret;
1728         }
1729         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1730         if (ret == -1) {
1731                 _LOGD("package app icon localized info DB initialization failed\n");
1732                 return ret;
1733         }
1734         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1735         if (ret == -1) {
1736                 _LOGD("package app image info DB initialization failed\n");
1737                 return ret;
1738         }
1739         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1740         if (ret == -1) {
1741                 _LOGD("package app app control DB initialization failed\n");
1742                 return ret;
1743         }
1744         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1745         if (ret == -1) {
1746                 _LOGD("package app app category DB initialization failed\n");
1747                 return ret;
1748         }
1749         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1750         if (ret == -1) {
1751                 _LOGD("package app app category DB initialization failed\n");
1752                 return ret;
1753         }
1754         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1755         if (ret == -1) {
1756                 _LOGD("package app app permission DB initialization failed\n");
1757                 return ret;
1758         }
1759         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1760         if (ret == -1) {
1761                 _LOGD("package app app svc DB initialization failed\n");
1762                 return ret;
1763         }
1764         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1765         if (ret == -1) {
1766                 _LOGD("package app share allowed DB initialization failed\n");
1767                 return ret;
1768         }
1769         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1770         if (ret == -1) {
1771                 _LOGD("package app share request DB initialization failed\n");
1772                 return ret;
1773         }
1774         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1775         if (ret == -1) {
1776                 _LOGD("package app data control DB initialization failed\n");
1777                 return ret;
1778         }
1779         /*Cert DB*/
1780         ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1781         if (ret == -1) {
1782                 _LOGD("package cert info DB initialization failed\n");
1783                 return ret;
1784         }
1785         ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1786         if (ret == -1) {
1787                 _LOGD("package cert index info DB initialization failed\n");
1788                 return ret;
1789         }
1790         /*reserve DB*/
1791         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PKG_RESERVE);
1792         if (ret == -1) {
1793                 _LOGD("package pkg reserve info DB initialization failed\n");
1794                 return ret;
1795         }
1796         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_RESERVE);
1797         if (ret == -1) {
1798                 _LOGD("package pkg reserve info DB initialization failed\n");
1799                 return ret;
1800         }
1801
1802         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO);
1803         if (ret == -1) {
1804                 _LOGD("package pkg reserve info DB initialization failed\n");
1805                 return ret;
1806         }
1807         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ALIASID);
1808         if (ret == -1) {
1809                 _LOGD("package app aliasId DB initialization failed\n");
1810                 return ret;
1811         }
1812 #ifdef _APPFW_FEATURE_PROFILE_WEARABLE
1813         ret = __init_tables_for_wearable();
1814         if (ret == -1) {
1815                 _LOGD("package pkg reserve info DB initialization failed\n");
1816                 return ret;
1817         }
1818 #endif
1819
1820         return 0;
1821 }
1822
1823 int pkgmgr_parser_check_and_create_db()
1824 {
1825         int ret = -1;
1826         /*Manifest DB*/
1827         ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
1828         if (ret) {
1829                 _LOGD("Manifest DB creation Failed\n");
1830                 return -1;
1831         }
1832         /*Cert DB*/
1833         ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
1834         if (ret) {
1835                 _LOGD("Cert DB creation Failed\n");
1836                 return -1;
1837         }
1838         return 0;
1839 }
1840
1841 void pkgmgr_parser_close_db()
1842 {
1843         sqlite3_close(pkgmgr_parser_db);
1844         sqlite3_close(pkgmgr_cert_db);
1845 }
1846
1847 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1848 {
1849         if (mfx == NULL) {
1850                 _LOGD("manifest pointer is NULL\n");
1851                 return -1;
1852         }
1853         int ret = 0;
1854         ret = pkgmgr_parser_check_and_create_db();
1855         if (ret == -1) {
1856                 _LOGD("Failed to open DB\n");
1857                 return ret;
1858         }
1859         ret = pkgmgr_parser_initialize_db();
1860         if (ret == -1)
1861                 goto err;
1862         /*Begin transaction*/
1863         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1864         if (ret != SQLITE_OK) {
1865                 _LOGD("Failed to begin transaction[%d]\n", ret);
1866                 ret = -1;
1867                 goto err;
1868         }
1869         _LOGD("Transaction Begin\n");
1870         ret = __insert_manifest_info_in_db(mfx);
1871         if (ret == -1) {
1872                 _LOGD("Insert into DB failed. Rollback now\n");
1873                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1874                 if (ret != SQLITE_OK)
1875                         _LOGD("ROLLBACK is fail after insert_disabled_pkg_info_in_db\n");
1876
1877                 ret = -1;
1878                 goto err;
1879         }
1880         /*Commit transaction*/
1881         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1882         if (ret != SQLITE_OK) {
1883                 _LOGD("Failed to commit transaction. Rollback now\n");
1884                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1885                 if (ret != SQLITE_OK)
1886                 _LOGE("Failed to commit transaction. Rollback now\n");
1887
1888                 ret = -1;
1889                 goto err;
1890         }
1891         _LOGD("Transaction Commit and End\n");
1892 err:
1893         pkgmgr_parser_close_db();
1894         return ret;
1895 }
1896
1897 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1898 {
1899         if (mfx == NULL) {
1900                 _LOGD("manifest pointer is NULL\n");
1901                 return -1;
1902         }
1903         int ret = 0;
1904         ret = pkgmgr_parser_check_and_create_db();
1905         if (ret == -1) {
1906                 _LOGD("Failed to open DB\n");
1907                 return ret;
1908         }
1909         ret = pkgmgr_parser_initialize_db();
1910         if (ret == -1)
1911                 goto err;
1912
1913         /*Begin transaction*/
1914         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1915         if (ret != SQLITE_OK) {
1916                 _LOGD("Failed to begin transaction\n");
1917                 ret = -1;
1918                 goto err;
1919         }
1920         _LOGD("Transaction Begin\n");
1921         ret = __delete_manifest_info_from_db(mfx);
1922         if (ret == -1) {
1923                 _LOGD("Delete from DB failed. Rollback now\n");
1924                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1925                 if (ret != SQLITE_OK)
1926                         _LOGD("Failed to commit transaction. Rollback now\n");
1927                 goto err;
1928         }
1929         ret = __insert_manifest_info_in_db(mfx);
1930         if (ret == -1) {
1931                 _LOGD("Insert into DB failed. Rollback now\n");
1932                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1933                 if (ret != SQLITE_OK)
1934                         _LOGD("Failed to commit transaction. Rollback now\n");
1935                 goto err;
1936         }
1937
1938         /*Commit transaction*/
1939         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1940         if (ret != SQLITE_OK) {
1941                 _LOGD("Failed to commit transaction. Rollback now\n");
1942                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1943                 if (ret != SQLITE_OK)
1944                         _LOGD("Failed to commit transaction. Rollback now\n");
1945
1946                 ret = -1;
1947                 goto err;
1948         }
1949         _LOGD("Transaction Commit and End\n");
1950 err:
1951         pkgmgr_parser_close_db();
1952         return ret;
1953 }
1954
1955 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1956 {
1957         if (mfx == NULL) {
1958                 _LOGD("manifest pointer is NULL\n");
1959                 return -1;
1960         }
1961         int ret = 0;
1962         ret = pkgmgr_parser_check_and_create_db();
1963         if (ret == -1) {
1964                 _LOGD("Failed to open DB\n");
1965                 return ret;
1966         }
1967         /*Begin transaction*/
1968         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1969         if (ret != SQLITE_OK) {
1970                 _LOGD("Failed to begin transaction\n");
1971                 ret = -1;
1972                 goto err;
1973         }
1974         _LOGD("Transaction Begin\n");
1975         ret = __delete_manifest_info_from_db(mfx);
1976         if (ret == -1) {
1977                 _LOGD("Delete from DB failed. Rollback now\n");
1978                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1979                 if (ret != SQLITE_OK)
1980                         _LOGE("Failed to commit transaction, Rollback now\n");
1981
1982                 goto err;
1983         }
1984         /*Commit transaction*/
1985         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1986         if (ret != SQLITE_OK) {
1987                 _LOGD("Failed to commit transaction, Rollback now\n");
1988                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1989                 if (ret != SQLITE_OK)
1990                         _LOGE("Failed to commit transaction, Rollback now\n");
1991
1992                 ret = -1;
1993                 goto err;
1994         }
1995
1996         ret = __delete_appsvc_info_from_db(mfx);
1997         if (ret == -1)
1998                 _LOGD("Removing appsvc_db failed\n");
1999         else
2000                 _LOGD("Removing appsvc_db Success\n");
2001
2002         _LOGD("Transaction Commit and End\n");
2003 err:
2004         pkgmgr_parser_close_db();
2005         return ret;
2006 }
2007
2008 API int pkgmgr_parser_update_preload_info_in_db()
2009 {
2010         int ret = 0;
2011         ret = pkgmgr_parser_check_and_create_db();
2012         if (ret == -1) {
2013                 _LOGD("Failed to open DB\n");
2014                 return ret;
2015         }
2016         /*Begin transaction*/
2017         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2018         if (ret != SQLITE_OK) {
2019                 _LOGD("Failed to begin transaction\n");
2020                 ret = -1;
2021                 goto err;
2022         }
2023         _LOGD("Transaction Begin\n");
2024         ret = __update_preload_condition_in_db();
2025         if (ret == -1) {
2026                 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2027                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2028                 if (ret != SQLITE_OK)
2029                         _LOGE("Failed to commit transaction, Rollback now\n");
2030
2031                 goto err;
2032         }
2033         /*Commit transaction*/
2034         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2035         if (ret != SQLITE_OK) {
2036                 _LOGD("Failed to commit transaction, Rollback now\n");
2037                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2038                 if (ret != SQLITE_OK)
2039                         _LOGE("Failed to commit transaction, Rollback now\n");
2040
2041                 ret = -1;
2042                 goto err;
2043         }
2044         _LOGD("Transaction Commit and End\n");
2045 err:
2046         pkgmgr_parser_close_db();
2047         return ret;
2048 }
2049
2050 API int pkgmgr_parser_delete_pkgid_info_from_db(const char *pkgid)
2051 {
2052         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2053
2054         int ret = 0;
2055
2056         /*open db*/
2057         ret = pkgmgr_parser_check_and_create_db();
2058         retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
2059
2060         /*Begin transaction*/
2061         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2062         if (ret != SQLITE_OK) {
2063                 _LOGE("Failed to begin transaction\n");
2064                 ret = -1;
2065                 goto err;
2066         }
2067
2068         _LOGD("Start to Delete pkgid[%s] info from db\n", pkgid);
2069
2070         /*delete pkg info*/
2071         ret = __delete_manifest_info_from_pkgid(pkgid);
2072         if (ret == -1) {
2073                 _LOGD("Delete from DB failed. Rollback now\n");
2074                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2075                 if (ret != SQLITE_OK)
2076                         _LOGE("Failed to begin transaction\n");
2077                 goto err;
2078         }
2079
2080         /*Commit transaction*/
2081         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2082         if (ret != SQLITE_OK) {
2083                 _LOGD("Failed to commit transaction, Rollback now\n");
2084                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2085                 if (ret != SQLITE_OK)
2086                         _LOGE("Failed to commit transaction, Rollback now\n");
2087
2088                 ret = -1;
2089                 goto err;
2090         }
2091
2092 err:
2093         pkgmgr_parser_close_db();
2094         return ret;
2095 }
2096
2097 API int pkgmgr_parser_delete_appid_info_from_db(const char *appid)
2098 {
2099         retvm_if(appid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2100
2101         int ret = 0;
2102
2103         /*open db*/
2104         ret = pkgmgr_parser_check_and_create_db();
2105         retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
2106
2107         /*Begin transaction*/
2108         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2109         if (ret != SQLITE_OK) {
2110                 _LOGE("Failed to begin transaction\n");
2111                 ret = -1;
2112                 goto err;
2113         }
2114
2115         _LOGD("Start to Delete appid[%s] info from db\n", appid);
2116
2117         /*delete appinfo db*/
2118         ret = __delete_manifest_info_from_appid(appid);
2119         if (ret < 0)
2120                 _LOGE("Fail to delete appid[%s] info from pkgmgr db\n", appid);
2121
2122         /*delete appsvc db*/
2123         ret = __delete_appsvc_db(appid);
2124         if (ret < 0)
2125                 _LOGE("Fail to delete appid[%s] info from appsvc db\n", appid);
2126
2127         /*Commit transaction*/
2128         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2129         if (ret != SQLITE_OK) {
2130                 _LOGD("Failed to commit transaction, Rollback now\n");
2131                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2132                 if (ret != SQLITE_OK)
2133                         _LOGE("Failed to commit transaction, Rollback now\n");
2134
2135                 ret = -1;
2136                 goto err;
2137         }
2138
2139 err:
2140         pkgmgr_parser_close_db();
2141         return ret;
2142 }
2143
2144 API int pkgmgr_parser_update_enabled_pkg_info_in_db(const char *pkgid)
2145 {
2146         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL.");
2147
2148         int ret = 0;
2149
2150         _LOGD("pkgmgr_parser_update_enabled_pkg_info_in_db(%s)\n", pkgid);
2151
2152         /*open db*/
2153         ret = pkgmgr_parser_check_and_create_db();
2154         retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_parser_check_and_create_db(%s) failed.\n", pkgid);
2155
2156         /*Begin transaction*/
2157         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2158         if (ret != SQLITE_OK) {
2159                 _LOGE("sqlite3_exec(BEGIN EXCLUSIVE) failed.\n");
2160                 ret = -1;
2161                 goto err;
2162         }
2163
2164         /*update pkg info*/
2165         ret = __update_pkg_info_for_disable(pkgid, false);
2166         if (ret == -1) {
2167                 _LOGD("__update_pkg_info_for_disable(%s) failed.\n", pkgid);
2168                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2169                 if (ret != SQLITE_OK)
2170                         _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2171                 goto err;
2172         }
2173
2174         /*Commit transaction*/
2175         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2176         if (ret != SQLITE_OK) {
2177                 _LOGD("sqlite3_exec(COMMIT) failed.\n");
2178                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2179                 if (ret != SQLITE_OK)
2180                         _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2181
2182                 ret = -1;
2183                 goto err;
2184         }
2185
2186 err:
2187         pkgmgr_parser_close_db();
2188         return ret;
2189 }
2190
2191 API int pkgmgr_parser_update_disabled_pkg_info_in_db(const char *pkgid)
2192 {
2193         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL.");
2194
2195         int ret = 0;
2196
2197         _LOGD("pkgmgr_parser_update_disabled_pkg_info_in_db(%s)\n", pkgid);
2198
2199         /*open db*/
2200         ret = pkgmgr_parser_check_and_create_db();
2201         retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_parser_check_and_create_db(%s) failed.\n", pkgid);
2202
2203         /*Begin transaction*/
2204         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2205         if (ret != SQLITE_OK) {
2206                 _LOGE("sqlite3_exec(BEGIN EXCLUSIVE) failed.\n");
2207                 ret = -1;
2208                 goto err;
2209         }
2210
2211         /*update pkg info*/
2212         ret = __update_pkg_info_for_disable(pkgid, true);
2213         if (ret == -1) {
2214                 _LOGD("__update_pkg_info_for_disable(%s) failed.\n", pkgid);
2215                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2216                 if (ret != SQLITE_OK)
2217                         _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2218                 goto err;
2219         }
2220
2221         /*Commit transaction*/
2222         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2223         if (ret != SQLITE_OK) {
2224                 _LOGD("sqlite3_exec(COMMIT) failed.\n");
2225                 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2226                 if (ret != SQLITE_OK)
2227                         _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2228
2229                 ret = -1;
2230                 goto err;
2231         }
2232
2233 err:
2234         pkgmgr_parser_close_db();
2235         return ret;
2236 }
2237
2238 int pkgmgr_parser_insert_app_aliasid_info_in_db(void)
2239 {
2240         FILE *ini_file = NULL;
2241         char *match = NULL;
2242         char *tizen_id = NULL;
2243         char *app_id = NULL;
2244         int len = 0;
2245         char buf[ MAX_ALIAS_INI_ENTRY ] = {0};
2246         int ret = PM_PARSER_R_OK;
2247         sqlite3 *pkgmgr_db = NULL;
2248         char *query = NULL;
2249
2250         /*Open the alias.ini file*/
2251         ini_file  = fopen(USR_APPSVC_ALIAS_INI,"r");
2252         if(ini_file){
2253                 /*Open the pkgmgr DB*/
2254                 ret = db_util_open_with_options(MANIFEST_DB, &pkgmgr_db, SQLITE_OPEN_READWRITE, NULL);
2255                 if (ret != SQLITE_OK) {
2256                         _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2257                         fclose(ini_file);
2258                         return PM_PARSER_R_ERROR;
2259
2260                 }
2261                 /*Begin Transaction*/
2262                 ret = sqlite3_exec(pkgmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2263                 tryvm_if(ret != SQLITE_OK, ret = PM_PARSER_R_ERROR, "Failed to begin transaction");
2264
2265                 _LOGD("Transaction Begin\n");
2266
2267                 /*delete all the previous entries from package_app_aliasid tables*/
2268                 query = sqlite3_mprintf("delete from package_app_aliasid");
2269                 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2270                 sqlite3_free(query);
2271                 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR,"sqlite exec failed to delete entries from package_app_aliasid!!");
2272
2273                 while ( fgets ( buf, sizeof(buf), ini_file ) != NULL ) /* read a line */
2274                 {
2275                         match = strstr(buf,"=");
2276                         if(match == NULL)
2277                                 continue;
2278                         /*format of alias.ini entry is 'tizen_app_id=alias_id'*/
2279                         /*get the tizen appid id*/
2280                         len = strlen(buf)-strlen(match);
2281                         tizen_id = malloc(len + 1);
2282                         tryvm_if(tizen_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2283                         memset(tizen_id,'\0',len +1);
2284                         strncpy(tizen_id,buf,len);
2285                         tizen_id[len]='\0';
2286                         __str_trim(tizen_id);
2287
2288                         /*get the corresponding alias id*/
2289                         len = strlen(match)-1;
2290                         app_id = malloc(len + 1);
2291                         tryvm_if(app_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2292                         memset(app_id,'\0',len + 1);
2293                         strncpy(app_id, match + 1, len);
2294                         app_id[len]='\0';
2295                         __str_trim(app_id);
2296
2297                         /* Insert the data into DB*/
2298                         query = sqlite3_mprintf("insert into package_app_aliasid(app_id, alias_id) values(%Q ,%Q)",tizen_id,app_id);
2299                         ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2300                         sqlite3_free(query);
2301                         tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR, "sqlite exec failed to insert entries into package_app_aliasid table!!");
2302
2303                         FREE_AND_NULL(tizen_id);
2304                         FREE_AND_NULL(app_id);
2305                         memset(buf,'\0',MAX_ALIAS_INI_ENTRY);
2306                 }
2307
2308                 /*Commit transaction*/
2309                 ret = sqlite3_exec(pkgmgr_db, "COMMIT", NULL, NULL, NULL);
2310                 if (ret != SQLITE_OK) {
2311                         _LOGE("Failed to commit transaction, Rollback now\n");
2312                         ret = sqlite3_exec(pkgmgr_db, "ROLLBACK", NULL, NULL, NULL);
2313                         if (ret != SQLITE_OK)
2314                                 _LOGE("Failed to Rollback\n");
2315
2316                         ret = PM_PARSER_R_ERROR;
2317                         goto catch;
2318                 }
2319                 _LOGE("Transaction Commit and End\n");
2320                 ret =  PM_PARSER_R_OK;
2321         }else{
2322                 perror(USR_APPSVC_ALIAS_INI);
2323                 ret = -1;
2324         }
2325
2326 catch:
2327         if(ini_file)
2328                 fclose ( ini_file);
2329
2330         FREE_AND_NULL(tizen_id);
2331         FREE_AND_NULL(app_id);
2332         sqlite3_close(pkgmgr_db);
2333         return ret;
2334
2335
2336 }
2337
2338 int pkgmgr_parser_update_app_aliasid_info_in_db(void)
2339 {
2340         FILE *ini_file = NULL;
2341         char *match = NULL;
2342         char *tizen_id = NULL;
2343         char *app_id = NULL;
2344         int len = 0;
2345         char buf[ MAX_ALIAS_INI_ENTRY ] = {0};
2346         int ret = PM_PARSER_R_OK;
2347         sqlite3 *pkgmgr_db = NULL;
2348         char *query = NULL;
2349
2350         /*Open the alias.ini file*/
2351         ini_file  = fopen(OPT_APPSVC_ALIAS_INI,"r");
2352         if(ini_file){
2353                 /*Open the pkgmgr DB*/
2354                 ret = db_util_open_with_options(MANIFEST_DB, &pkgmgr_db, SQLITE_OPEN_READWRITE, NULL);
2355                 if (ret != SQLITE_OK) {
2356                         _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2357                         fclose(ini_file);
2358                         return PM_PARSER_R_ERROR;
2359
2360                 }
2361                 /*Begin Transaction*/
2362                 ret = sqlite3_exec(pkgmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2363                 tryvm_if(ret != SQLITE_OK, ret = PM_PARSER_R_ERROR, "Failed to begin transaction");
2364
2365                 _LOGD("Transaction Begin\n");
2366
2367                 while ( fgets ( buf, sizeof(buf), ini_file ) != NULL ) /* read a line */
2368                 {
2369                         match = strstr(buf,"=");
2370                         if(match == NULL)
2371                                 continue;
2372                         /*format of alias.ini entry is 'tizen_app_id=alias_id'*/
2373                         /*get the tizen appid id*/
2374                         len = strlen(buf)-strlen(match);
2375                         tizen_id = malloc(len + 1);
2376                         tryvm_if(tizen_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2377                         memset(tizen_id,'\0',len +1);
2378                         strncpy(tizen_id,buf,len);
2379                         tizen_id[len]='\0';
2380                         __str_trim(tizen_id);
2381
2382                         /*get the corresponding alias id*/
2383                         len = strlen(match)-1;
2384                         app_id = malloc(len + 1);
2385                         tryvm_if(app_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2386                         memset(app_id,'\0',len + 1);
2387                         strncpy(app_id, match + 1, len);
2388                         app_id[len]='\0';
2389                         __str_trim(app_id);
2390
2391                         /* Insert the data into DB*/
2392                         query = sqlite3_mprintf("insert or replace into package_app_aliasid(app_id, alias_id) values(%Q ,%Q)",tizen_id,app_id);
2393                         ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2394                         sqlite3_free(query);
2395                         tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR, "sqlite exec failed to insert entries into package_app_aliasid table!!");
2396
2397                         FREE_AND_NULL(tizen_id);
2398                         FREE_AND_NULL(app_id);
2399                         memset(buf,'\0',MAX_ALIAS_INI_ENTRY);
2400                 }
2401
2402                 /*Commit transaction*/
2403                 ret = sqlite3_exec(pkgmgr_db, "COMMIT", NULL, NULL, NULL);
2404                 if (ret != SQLITE_OK) {
2405                         _LOGE("Failed to commit transaction, Rollback now\n");
2406                         ret = sqlite3_exec(pkgmgr_db, "ROLLBACK", NULL, NULL, NULL);
2407                         if (ret != SQLITE_OK)
2408                                 _LOGE("Failed to Rollback\n");
2409
2410                         ret = PM_PARSER_R_ERROR;
2411                         goto catch;
2412                 }
2413                 _LOGE("Transaction Commit and End\n");
2414                 ret =  PM_PARSER_R_OK;
2415         }else{
2416                 perror(OPT_APPSVC_ALIAS_INI);
2417                 ret = -1;
2418         }
2419
2420 catch:
2421         if(ini_file)
2422                 fclose ( ini_file);
2423
2424         FREE_AND_NULL(tizen_id);
2425         FREE_AND_NULL(app_id);
2426         sqlite3_close(pkgmgr_db);
2427         return ret;
2428
2429
2430 }
2431