PageRenderTime 49ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/slp-pkgmgr/parser/pkgmgr_parser_db.c

https://review.tizen.org/git/
C | 1307 lines | 1180 code | 81 blank | 46 comment | 240 complexity | df4d855b36a69fbc2c6be5049bed83b4 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
  1. /*
  2. * slp-pkgmgr
  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. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <unistd.h>
  28. #include <db-util.h>
  29. #include <glib.h>
  30. #include "pkgmgr_parser_internal.h"
  31. #include "pkgmgr_parser_db.h"
  32. #include "pkgmgr-api.h"
  33. #define PKGMGR_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
  34. #define MAX_QUERY_LEN 4096
  35. sqlite3 *pkgmgr_parser_db;
  36. GList *pkglocale = NULL;
  37. GList *applocale = NULL;
  38. char *prev = NULL;
  39. #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
  40. "(package text primary key not null, " \
  41. "package_type text DEFAULT 'rpm', " \
  42. "package_version text, " \
  43. "install_location text, " \
  44. "package_removable text DEFAULT 'true', " \
  45. "package_preload text DEFAULT 'false', " \
  46. "package_readonly text DEFAULT 'false', " \
  47. "author_name text, " \
  48. "author_email text, " \
  49. "author_href text)"
  50. #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
  51. "(package text not null, " \
  52. "package_locale text DEFAULT 'No Locale', " \
  53. "package_label text, " \
  54. "package_icon text, " \
  55. "package_description text, " \
  56. "package_license text, " \
  57. "package_author, " \
  58. "PRIMARY KEY(package, package_locale), " \
  59. "FOREIGN KEY(package) " \
  60. "REFERENCES package_info(package) " \
  61. "ON DELETE CASCADE)"
  62. #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
  63. "(app_id text primary key not null, " \
  64. "app_component text, " \
  65. "app_exec text, " \
  66. "app_nodisplay text DEFAULT 'false', " \
  67. "app_type text, " \
  68. "app_onboot text DEFAULT 'false', " \
  69. "app_multiple text DEFAULT 'false', " \
  70. "app_autorestart text DEFAULT 'false', " \
  71. "app_taskmanage text DEFAULT 'false', " \
  72. "package text not null, " \
  73. "FOREIGN KEY(package) " \
  74. "REFERENCES package_info(package) " \
  75. "ON DELETE CASCADE)"
  76. #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
  77. "(app_id text not null, " \
  78. "app_locale text DEFAULT 'No Locale', " \
  79. "app_label text, " \
  80. "app_icon text, " \
  81. "PRIMARY KEY(app_id,app_locale) " \
  82. "FOREIGN KEY(app_id) " \
  83. "REFERENCES package_app_info(app_id) " \
  84. "ON DELETE CASCADE)"
  85. #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
  86. "(app_id text not null, " \
  87. "operation text not null, " \
  88. "uri_scheme text, " \
  89. "mime_type text, " \
  90. "PRIMARY KEY(app_id,operation,uri_scheme,mime_type) " \
  91. "FOREIGN KEY(app_id) " \
  92. "REFERENCES package_app_info(app_id) " \
  93. "ON DELETE CASCADE)"
  94. #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
  95. "(app_id text not null, " \
  96. "data_share_path text not null, " \
  97. "data_share_allowed text not null, " \
  98. "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
  99. "FOREIGN KEY(app_id) " \
  100. "REFERENCES package_app_info(app_id) " \
  101. "ON DELETE CASCADE)"
  102. #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
  103. "(app_id text not null, " \
  104. "data_share_request text not null, " \
  105. "PRIMARY KEY(app_id,data_share_request) " \
  106. "FOREIGN KEY(app_id) " \
  107. "REFERENCES package_app_info(app_id) " \
  108. "ON DELETE CASCADE)"
  109. static int __insert_uiapplication_info(manifest_x *mfx);
  110. static int __insert_serviceapplication_info(manifest_x *mfx);
  111. static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
  112. static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
  113. static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
  114. static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
  115. static int __insert_uiapplication_share_request_info(manifest_x *mfx);
  116. static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
  117. static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
  118. static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
  119. static void __insert_pkglocale_info(gpointer data, gpointer userdata);
  120. static int __insert_manifest_info_in_db(manifest_x *mfx);
  121. static int __update_manifest_info_in_db(manifest_x *mfx);
  122. static int __delete_manifest_info_from_db(manifest_x *mfx);
  123. static int __initialize_package_info_db();
  124. static int __initialize_package_localized_info_db();
  125. static int __initialize_package_app_info_db();
  126. static int __initialize_package_app_localized_info_db();
  127. static int __initialize_package_app_app_svc_db();
  128. static int __initialize_package_app_share_allowed_db();
  129. static int __initialize_package_app_share_request_db();
  130. static int __exec_query(char *query);
  131. static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
  132. char **label, char **license, char **icon, char **description, char **author);
  133. static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
  134. static void __trimfunc1(gpointer data, gpointer userdata);
  135. static void __trimfunc2(gpointer data, gpointer userdata);
  136. static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
  137. static int __initialize_package_info_db()
  138. {
  139. char *error_message = NULL;
  140. if (SQLITE_OK !=
  141. sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO,
  142. NULL, NULL, &error_message)) {
  143. DBG("Don't execute query = %s error message = %s\n",
  144. QUERY_CREATE_TABLE_PACKAGE_INFO, error_message);
  145. sqlite3_free(error_message);
  146. return -1;
  147. }
  148. sqlite3_free(error_message);
  149. return 0;
  150. }
  151. static int __initialize_package_localized_info_db()
  152. {
  153. char *error_message = NULL;
  154. if (SQLITE_OK !=
  155. sqlite3_exec(pkgmgr_parser_db,
  156. QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO, NULL, NULL,
  157. &error_message)) {
  158. DBG("Don't execute query = %s error message = %s\n",
  159. QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
  160. error_message);
  161. sqlite3_free(error_message);
  162. return -1;
  163. }
  164. sqlite3_free(error_message);
  165. return 0;
  166. }
  167. static int __initialize_package_app_info_db()
  168. {
  169. char *error_message = NULL;
  170. if (SQLITE_OK !=
  171. sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
  172. NULL, NULL, &error_message)) {
  173. DBG("Don't execute query = %s error message = %s\n",
  174. QUERY_CREATE_TABLE_PACKAGE_APP_INFO, error_message);
  175. sqlite3_free(error_message);
  176. return -1;
  177. }
  178. sqlite3_free(error_message);
  179. return 0;
  180. }
  181. static int __initialize_package_app_localized_info_db()
  182. {
  183. char *error_message = NULL;
  184. if (SQLITE_OK !=
  185. sqlite3_exec(pkgmgr_parser_db,
  186. QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO, NULL,
  187. NULL, &error_message)) {
  188. DBG("Don't execute query = %s error message = %s\n",
  189. QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
  190. error_message);
  191. sqlite3_free(error_message);
  192. return -1;
  193. }
  194. sqlite3_free(error_message);
  195. return 0;
  196. }
  197. static int __initialize_package_app_app_svc_db()
  198. {
  199. char *error_message = NULL;
  200. if (SQLITE_OK !=
  201. sqlite3_exec(pkgmgr_parser_db,
  202. QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, NULL, NULL,
  203. &error_message)) {
  204. DBG("Don't execute query = %s error message = %s\n",
  205. QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, error_message);
  206. sqlite3_free(error_message);
  207. return -1;
  208. }
  209. sqlite3_free(error_message);
  210. return 0;
  211. }
  212. static int __initialize_package_app_share_allowed_db()
  213. {
  214. char *error_message = NULL;
  215. if (SQLITE_OK !=
  216. sqlite3_exec(pkgmgr_parser_db,
  217. QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, NULL,
  218. NULL, &error_message)) {
  219. DBG("Don't execute query = %s error message = %s\n",
  220. QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED,
  221. error_message);
  222. sqlite3_free(error_message);
  223. return -1;
  224. }
  225. sqlite3_free(error_message);
  226. return 0;
  227. }
  228. static int __initialize_package_app_share_request_db()
  229. {
  230. char *error_message = NULL;
  231. if (SQLITE_OK !=
  232. sqlite3_exec(pkgmgr_parser_db,
  233. QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, NULL,
  234. NULL, &error_message)) {
  235. DBG("Don't execute query = %s error message = %s\n",
  236. QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST,
  237. error_message);
  238. sqlite3_free(error_message);
  239. return -1;
  240. }
  241. sqlite3_free(error_message);
  242. return 0;
  243. }
  244. static int __exec_query(char *query)
  245. {
  246. char *error_message = NULL;
  247. if (SQLITE_OK !=
  248. sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
  249. DBG("Don't execute query = %s error message = %s\n", query,
  250. error_message);
  251. sqlite3_free(error_message);
  252. return -1;
  253. }
  254. sqlite3_free(error_message);
  255. return 0;
  256. }
  257. static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
  258. {
  259. while(lbl != NULL)
  260. {
  261. if (lbl->lang)
  262. locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
  263. lbl = lbl->next;
  264. }
  265. while(lcn != NULL)
  266. {
  267. if (lcn->lang)
  268. locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
  269. lcn = lcn->next;
  270. }
  271. while(icn != NULL)
  272. {
  273. if (icn->lang)
  274. locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
  275. icn = icn->next;
  276. }
  277. while(dcn != NULL)
  278. {
  279. if (dcn->lang)
  280. locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
  281. dcn = dcn->next;
  282. }
  283. while(ath != NULL)
  284. {
  285. if (ath->lang)
  286. locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
  287. ath = ath->next;
  288. }
  289. return locale;
  290. }
  291. static void __printfunc(gpointer data, gpointer userdata)
  292. {
  293. DBG("%s ", (char*)data);
  294. }
  295. static void __trimfunc1(gpointer data, gpointer userdata)
  296. {
  297. if (prev) {
  298. if (strcmp((char *)data, prev) == 0) {
  299. pkglocale = g_list_remove(pkglocale, data);
  300. } else
  301. prev = (char *)data;
  302. }
  303. else
  304. prev = (char *)data;
  305. }
  306. static void __trimfunc2(gpointer data, gpointer userdata)
  307. {
  308. if (prev) {
  309. if (strcmp((char *)data, prev) == 0) {
  310. applocale = g_list_remove(applocale, data);
  311. } else
  312. prev = (char *)data;
  313. }
  314. else
  315. prev = (char *)data;
  316. }
  317. static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
  318. {
  319. if (a == NULL || b == NULL)
  320. return 0;
  321. if (strcmp((char*)a, (char*)b) == 0)
  322. return 0;
  323. if (strcmp((char*)a, (char*)b) < 0)
  324. return -1;
  325. if (strcmp((char*)a, (char*)b) > 0)
  326. return 1;
  327. }
  328. static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
  329. char **label, char **license, char **icon, char **description, char **author)
  330. {
  331. while(lbl != NULL)
  332. {
  333. if (lbl->lang) {
  334. if (strcmp(lbl->lang, (char *)data) == 0) {
  335. *label = (char*)lbl->text;
  336. break;
  337. }
  338. }
  339. lbl = lbl->next;
  340. }
  341. while(lcn != NULL)
  342. {
  343. if (lcn->lang) {
  344. if (strcmp(lcn->lang, (char *)data) == 0) {
  345. *license = (char*)lcn->text;
  346. break;
  347. }
  348. }
  349. lcn = lcn->next;
  350. }
  351. while(icn != NULL)
  352. {
  353. if (icn->lang) {
  354. if (strcmp(icn->lang, (char *)data) == 0) {
  355. *icon = (char*)icn->text;
  356. break;
  357. }
  358. }
  359. icn = icn->next;
  360. }
  361. while(dcn != NULL)
  362. {
  363. if (dcn->lang) {
  364. if (strcmp(dcn->lang, (char *)data) == 0) {
  365. *description = (char*)dcn->text;
  366. break;
  367. }
  368. }
  369. dcn = dcn->next;
  370. }
  371. while(ath != NULL)
  372. {
  373. if (ath->lang) {
  374. if (strcmp(ath->lang, (char *)data) == 0) {
  375. *author = (char*)ath->text;
  376. break;
  377. }
  378. }
  379. ath = ath->next;
  380. }
  381. }
  382. static void __insert_pkglocale_info(gpointer data, gpointer userdata)
  383. {
  384. int ret = -1;
  385. char *label = NULL;
  386. char *icon = NULL;
  387. char *description = NULL;
  388. char *license = NULL;
  389. char *author = NULL;
  390. char query[MAX_QUERY_LEN] = {'\0'};
  391. manifest_x *mfx = (manifest_x *)userdata;
  392. label_x *lbl = mfx->label;
  393. license_x *lcn = mfx->license;
  394. icon_x *icn = mfx->icon;
  395. description_x *dcn = mfx->description;
  396. author_x *ath = mfx->author;
  397. __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
  398. if (!label && !description && !icon && !license && !author)
  399. return;
  400. snprintf(query, MAX_QUERY_LEN, "insert into package_localized_info(package, package_locale, " \
  401. "package_label, package_icon, package_description, package_license, package_author) values " \
  402. "('%s', '%s', '%s', '%s', '%s', '%s', '%s')", mfx->package, (char*)data,
  403. label, icon, description, license, author);
  404. ret = __exec_query(query);
  405. if (ret == -1)
  406. DBG("Package Localized Info DB Insert failed\n");
  407. }
  408. static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
  409. {
  410. int ret = -1;
  411. char *label = NULL;
  412. char *icon = NULL;
  413. char query[MAX_QUERY_LEN] = {'\0'};
  414. uiapplication_x *up = (uiapplication_x*)userdata;
  415. label_x *lbl = up->label;
  416. icon_x *icn = up->icon;
  417. __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
  418. if (!label && !icon)
  419. return;
  420. snprintf(query, MAX_QUERY_LEN, "insert into package_app_localized_info(app_id, app_locale, " \
  421. "app_label, app_icon) values " \
  422. "('%s', '%s', '%s', '%s')", up->appid, (char*)data,
  423. label, icon);
  424. ret = __exec_query(query);
  425. if (ret == -1)
  426. DBG("Package UiApp Localized Info DB Insert failed\n");
  427. }
  428. static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
  429. {
  430. int ret = -1;
  431. char *icon = NULL;
  432. char *label = NULL;
  433. char query[MAX_QUERY_LEN] = {'\0'};
  434. serviceapplication_x *sp = (serviceapplication_x*)userdata;
  435. label_x *lbl = sp->label;
  436. icon_x *icn = sp->icon;
  437. __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
  438. if (!icon && !label)
  439. return;
  440. snprintf(query, MAX_QUERY_LEN, "insert into package_app_localized_info(app_id, app_locale, " \
  441. "app_label, app_icon) values " \
  442. "('%s', '%s', '%s', '%s')", sp->appid, (char*)data,
  443. label, icon);
  444. ret = __exec_query(query);
  445. if (ret == -1)
  446. DBG("Package ServiceApp Localized Info DB Insert failed\n");
  447. }
  448. static int __insert_uiapplication_info(manifest_x *mfx)
  449. {
  450. uiapplication_x *up = mfx->uiapplication;
  451. int ret = -1;
  452. char query[MAX_QUERY_LEN] = {'\0'};
  453. while(up != NULL)
  454. {
  455. snprintf(query, MAX_QUERY_LEN,
  456. "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
  457. "app_multiple, app_autorestart, app_taskmanage, package) " \
  458. "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
  459. up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
  460. "\0", up->taskmanage, mfx->package);
  461. ret = __exec_query(query);
  462. if (ret == -1) {
  463. DBG("Package UiApp Info DB Insert Failed\n");
  464. return -1;
  465. }
  466. up = up->next;
  467. memset(query, '\0', MAX_QUERY_LEN);
  468. }
  469. return 0;
  470. }
  471. static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
  472. {
  473. uiapplication_x *up = mfx->uiapplication;
  474. appsvc_x *asvc = NULL;
  475. operation_x *op = NULL;
  476. mime_x *mi = NULL;
  477. uri_x *ui = NULL;
  478. int ret = -1;
  479. char query[MAX_QUERY_LEN] = {'\0'};
  480. char *operation = NULL;
  481. char *mime = NULL;
  482. char *uri = NULL;
  483. while(up != NULL)
  484. {
  485. asvc = up->appsvc;
  486. while(asvc != NULL)
  487. {
  488. op = asvc->operation;
  489. while(op != NULL)
  490. {
  491. if (op)
  492. operation = op->name;
  493. mi = asvc->mime;
  494. do
  495. {
  496. if (mi)
  497. mime = mi->name;
  498. ui = asvc->uri;
  499. do
  500. {
  501. if (ui)
  502. uri = ui->name;
  503. snprintf(query, MAX_QUERY_LEN,
  504. "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type) " \
  505. "values('%s', '%s', '%s', '%s')",\
  506. up->appid, operation, uri, mime);
  507. ret = __exec_query(query);
  508. if (ret == -1) {
  509. DBG("Package UiApp AppSvc DB Insert Failed\n");
  510. return -1;
  511. }
  512. memset(query, '\0', MAX_QUERY_LEN);
  513. if (ui)
  514. ui = ui->next;
  515. uri = NULL;
  516. } while(ui != NULL);
  517. if (mi)
  518. mi = mi->next;
  519. mime = NULL;
  520. }while(mi != NULL);
  521. if (op)
  522. op = op->next;
  523. operation = NULL;
  524. }
  525. asvc = asvc->next;
  526. }
  527. up = up->next;
  528. }
  529. return 0;
  530. }
  531. static int __insert_uiapplication_share_request_info(manifest_x *mfx)
  532. {
  533. uiapplication_x *up = mfx->uiapplication;
  534. datashare_x *ds = NULL;
  535. request_x *rq = NULL;
  536. int ret = -1;
  537. char query[MAX_QUERY_LEN] = {'\0'};
  538. while(up != NULL)
  539. {
  540. ds = up->datashare;
  541. while(ds != NULL)
  542. {
  543. rq = ds->request;
  544. while(rq != NULL)
  545. {
  546. snprintf(query, MAX_QUERY_LEN,
  547. "insert into package_app_share_request(app_id, data_share_request) " \
  548. "values('%s', '%s')",\
  549. up->appid, rq->text);
  550. ret = __exec_query(query);
  551. if (ret == -1) {
  552. DBG("Package UiApp Share Request DB Insert Failed\n");
  553. return -1;
  554. }
  555. memset(query, '\0', MAX_QUERY_LEN);
  556. rq = rq->next;
  557. }
  558. ds = ds->next;
  559. }
  560. up = up->next;
  561. }
  562. return 0;
  563. }
  564. static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
  565. {
  566. uiapplication_x *up = mfx->uiapplication;
  567. datashare_x *ds = NULL;
  568. define_x *df = NULL;
  569. allowed_x *al = NULL;
  570. int ret = -1;
  571. char query[MAX_QUERY_LEN] = {'\0'};
  572. while(up != NULL)
  573. {
  574. ds = up->datashare;
  575. while(ds != NULL)
  576. {
  577. df = ds->define;
  578. while(df != NULL)
  579. {
  580. al = df->allowed;
  581. while(al != NULL)
  582. {
  583. snprintf(query, MAX_QUERY_LEN,
  584. "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
  585. "values('%s', '%s', '%s')",\
  586. up->appid, df->path, al->text);
  587. ret = __exec_query(query);
  588. if (ret == -1) {
  589. DBG("Package UiApp Share Allowed DB Insert Failed\n");
  590. return -1;
  591. }
  592. memset(query, '\0', MAX_QUERY_LEN);
  593. al = al->next;
  594. }
  595. df = df->next;
  596. }
  597. ds = ds->next;
  598. }
  599. up = up->next;
  600. }
  601. return 0;
  602. }
  603. static int __insert_serviceapplication_info(manifest_x *mfx)
  604. {
  605. serviceapplication_x *sp = mfx->serviceapplication;
  606. int ret = -1;
  607. char query[MAX_QUERY_LEN] = {'\0'};
  608. while(sp != NULL)
  609. {
  610. snprintf(query, MAX_QUERY_LEN,
  611. "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
  612. "app_multiple, app_autorestart, package) " \
  613. "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
  614. sp->appid, "svcapp", sp->exec, "\0", sp->type, sp->onboot, "\0",
  615. sp->autorestart, mfx->package);
  616. ret = __exec_query(query);
  617. if (ret == -1) {
  618. DBG("Package ServiceApp Info DB Insert Failed\n");
  619. return -1;
  620. }
  621. sp = sp->next;
  622. memset(query, '\0', MAX_QUERY_LEN);
  623. }
  624. return 0;
  625. }
  626. static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
  627. {
  628. serviceapplication_x *sp = mfx->serviceapplication;
  629. appsvc_x *asvc = NULL;
  630. int ret = -1;
  631. char query[MAX_QUERY_LEN] = {'\0'};
  632. operation_x *op = NULL;
  633. mime_x *mi = NULL;
  634. uri_x *ui = NULL;
  635. char *operation = NULL;
  636. char *mime = NULL;
  637. char *uri = NULL;
  638. while(sp != NULL)
  639. {
  640. asvc = sp->appsvc;
  641. while(asvc != NULL)
  642. {
  643. op = asvc->operation;
  644. while(op != NULL)
  645. {
  646. if (op)
  647. operation = op->name;
  648. mi = asvc->mime;
  649. do
  650. {
  651. if (mi)
  652. mime = mi->name;
  653. ui = asvc->uri;
  654. do
  655. {
  656. if (ui)
  657. uri = ui->name;
  658. snprintf(query, MAX_QUERY_LEN,
  659. "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type) " \
  660. "values('%s', '%s', '%s', '%s')",\
  661. sp->appid, operation, uri, mime);
  662. ret = __exec_query(query);
  663. if (ret == -1) {
  664. DBG("Package UiApp AppSvc DB Insert Failed\n");
  665. return -1;
  666. }
  667. memset(query, '\0', MAX_QUERY_LEN);
  668. if (ui)
  669. ui = ui->next;
  670. uri = NULL;
  671. } while(ui != NULL);
  672. if (mi)
  673. mi = mi->next;
  674. mime = NULL;
  675. }while(mi != NULL);
  676. if (op)
  677. op = op->next;
  678. operation = NULL;
  679. }
  680. asvc = asvc->next;
  681. }
  682. sp = sp->next;
  683. }
  684. return 0;
  685. }
  686. static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
  687. {
  688. serviceapplication_x *sp = mfx->serviceapplication;
  689. datashare_x *ds = NULL;
  690. request_x *rq = NULL;
  691. int ret = -1;
  692. char query[MAX_QUERY_LEN] = {'\0'};
  693. while(sp != NULL)
  694. {
  695. ds = sp->datashare;
  696. while(ds != NULL)
  697. {
  698. rq = ds->request;
  699. while(rq != NULL)
  700. {
  701. snprintf(query, MAX_QUERY_LEN,
  702. "insert into package_app_share_request(app_id, data_share_request) " \
  703. "values('%s', '%s')",\
  704. sp->appid, rq->text);
  705. ret = __exec_query(query);
  706. if (ret == -1) {
  707. DBG("Package ServiceApp Share Request DB Insert Failed\n");
  708. return -1;
  709. }
  710. memset(query, '\0', MAX_QUERY_LEN);
  711. rq = rq->next;
  712. }
  713. ds = ds->next;
  714. }
  715. sp = sp->next;
  716. }
  717. return 0;
  718. }
  719. static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
  720. {
  721. serviceapplication_x *sp = mfx->serviceapplication;
  722. datashare_x *ds = NULL;
  723. define_x *df = NULL;
  724. allowed_x *al = NULL;
  725. int ret = -1;
  726. char query[MAX_QUERY_LEN] = {'\0'};
  727. while(sp != NULL)
  728. {
  729. ds = sp->datashare;
  730. while(ds != NULL)
  731. {
  732. df = ds->define;
  733. while(df != NULL)
  734. {
  735. al = df->allowed;
  736. while(al != NULL)
  737. {
  738. snprintf(query, MAX_QUERY_LEN,
  739. "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
  740. "values('%s', '%s', '%s')",\
  741. sp->appid, df->path, al->text);
  742. ret = __exec_query(query);
  743. if (ret == -1) {
  744. DBG("Package App Share Allowed DB Insert Failed\n");
  745. return -1;
  746. }
  747. memset(query, '\0', MAX_QUERY_LEN);
  748. al = al->next;
  749. }
  750. df = df->next;
  751. }
  752. ds = ds->next;
  753. }
  754. sp = sp->next;
  755. }
  756. return 0;
  757. }
  758. static int __insert_manifest_info_in_db(manifest_x *mfx)
  759. {
  760. label_x *lbl = mfx->label;
  761. license_x *lcn = mfx->license;
  762. icon_x *icn = mfx->icon;
  763. description_x *dcn = mfx->description;
  764. author_x *ath = mfx->author;
  765. uiapplication_x *up = mfx->uiapplication;
  766. serviceapplication_x *sp = mfx->serviceapplication;
  767. char query[MAX_QUERY_LEN] = { '\0' };
  768. int ret = -1;
  769. char *type = NULL;
  770. char *auth_name = NULL;
  771. char *auth_email = NULL;
  772. char *auth_href = NULL;
  773. if (ath) {
  774. if (ath->text)
  775. auth_name = ath->text;
  776. if (ath->email)
  777. auth_email = ath->email;
  778. if (ath->href)
  779. auth_href = ath->href;
  780. }
  781. /*Insert in the package_info DB*/
  782. if (mfx->type)
  783. type = strdup(mfx->type);
  784. else
  785. type = strdup("rpm");
  786. snprintf(query, MAX_QUERY_LEN,
  787. "insert into package_info(package, package_type, package_version, install_location, " \
  788. "package_removable, package_preload, package_readonly, author_name, author_email, author_href) " \
  789. "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
  790. mfx->package, type, mfx->version, mfx->installlocation, mfx->removable, mfx->preload,
  791. mfx->readonly, auth_name, auth_email, auth_href);
  792. ret = __exec_query(query);
  793. if (ret == -1) {
  794. DBG("Package Info DB Insert Failed\n");
  795. if (type) {
  796. free(type);
  797. type = NULL;
  798. }
  799. return -1;
  800. }
  801. if (type) {
  802. free(type);
  803. type = NULL;
  804. }
  805. /*Insert the package locale and app locale info */
  806. pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
  807. g_list_foreach(pkglocale, __trimfunc1, NULL);
  808. prev = NULL;
  809. while(up != NULL)
  810. {
  811. applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
  812. up = up->next;
  813. }
  814. while(sp != NULL)
  815. {
  816. applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
  817. sp = sp->next;
  818. }
  819. g_list_foreach(applocale, __trimfunc2, NULL);
  820. prev = NULL;
  821. /*g_list_foreach(pkglocale, __printfunc, NULL);*/
  822. /*DBG("\n");*/
  823. /*g_list_foreach(applocale, __printfunc, NULL);*/
  824. /*package locale info*/
  825. g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
  826. /*native app locale info*/
  827. up = mfx->uiapplication;
  828. while(up != NULL)
  829. {
  830. g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
  831. up = up->next;
  832. }
  833. /*agent app locale info*/
  834. sp = mfx->serviceapplication;
  835. while(sp != NULL)
  836. {
  837. g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
  838. sp = sp->next;
  839. }
  840. g_list_free(pkglocale);
  841. pkglocale = NULL;
  842. g_list_free(applocale);
  843. applocale = NULL;
  844. /*Insert in the package_app_info DB*/
  845. ret = __insert_uiapplication_info(mfx);
  846. if (ret == -1)
  847. return -1;
  848. ret = __insert_serviceapplication_info(mfx);
  849. if (ret == -1)
  850. return -1;
  851. /*Insert in the package_app_app_svc DB*/
  852. ret = __insert_uiapplication_appsvc_info(mfx);
  853. if (ret == -1)
  854. return -1;
  855. ret = __insert_serviceapplication_appsvc_info(mfx);
  856. if (ret == -1)
  857. return -1;
  858. /*Insert in the package_app_share_allowed DB*/
  859. ret = __insert_uiapplication_share_allowed_info(mfx);
  860. if (ret == -1)
  861. return -1;
  862. ret = __insert_serviceapplication_share_allowed_info(mfx);
  863. if (ret == -1)
  864. return -1;
  865. /*Insert in the package_app_share_request DB*/
  866. ret = __insert_uiapplication_share_request_info(mfx);
  867. if (ret == -1)
  868. return -1;
  869. ret = __insert_serviceapplication_share_request_info(mfx);
  870. if (ret == -1)
  871. return -1;
  872. return 0;
  873. }
  874. static int __delete_manifest_info_from_db(manifest_x *mfx)
  875. {
  876. char query[MAX_QUERY_LEN] = { '\0' };
  877. int ret = -1;
  878. uiapplication_x *up = mfx->uiapplication;
  879. serviceapplication_x *sp = mfx->serviceapplication;
  880. /*Delete from Package Info DB*/
  881. snprintf(query, MAX_QUERY_LEN,
  882. "delete from package_info where package='%s'", mfx->package);
  883. ret = __exec_query(query);
  884. if (ret == -1) {
  885. DBG("Package Info DB Delete Failed\n");
  886. return -1;
  887. }
  888. memset(query, '\0', MAX_QUERY_LEN);
  889. /*Delete from Package Localized Info*/
  890. snprintf(query, MAX_QUERY_LEN,
  891. "delete from package_localized_info where package='%s'", mfx->package);
  892. ret = __exec_query(query);
  893. if (ret == -1) {
  894. DBG("Package Localized Info DB Delete Failed\n");
  895. return -1;
  896. }
  897. memset(query, '\0', MAX_QUERY_LEN);
  898. /*Delete from Package App Info*/
  899. while(up != NULL)
  900. {
  901. snprintf(query, MAX_QUERY_LEN,
  902. "delete from package_app_info where app_id='%s'", up->appid);
  903. ret = __exec_query(query);
  904. if (ret == -1) {
  905. DBG("Package App Info DB Delete Failed\n");
  906. return -1;
  907. }
  908. memset(query, '\0', MAX_QUERY_LEN);
  909. up = up->next;
  910. }
  911. while(sp != NULL)
  912. {
  913. snprintf(query, MAX_QUERY_LEN,
  914. "delete from package_app_info where app_id='%s'", sp->appid);
  915. ret = __exec_query(query);
  916. if (ret == -1) {
  917. DBG("Package App Info DB Delete Failed\n");
  918. return -1;
  919. }
  920. memset(query, '\0', MAX_QUERY_LEN);
  921. sp = sp->next;
  922. }
  923. /*Delete from Package App Localized Info*/
  924. up = mfx->uiapplication;
  925. sp = mfx->serviceapplication;
  926. while(up != NULL)
  927. {
  928. snprintf(query, MAX_QUERY_LEN,
  929. "delete from package_app_localized_info where app_id='%s'", up->appid);
  930. ret = __exec_query(query);
  931. if (ret == -1) {
  932. DBG("Package App Localized Info DB Delete Failed\n");
  933. return -1;
  934. }
  935. memset(query, '\0', MAX_QUERY_LEN);
  936. up = up->next;
  937. }
  938. while(sp != NULL)
  939. {
  940. snprintf(query, MAX_QUERY_LEN,
  941. "delete from package_app_localized_info where app_id='%s'", sp->appid);
  942. ret = __exec_query(query);
  943. if (ret == -1) {
  944. DBG("Package App Localized Info DB Delete Failed\n");
  945. return -1;
  946. }
  947. memset(query, '\0', MAX_QUERY_LEN);
  948. sp = sp->next;
  949. }
  950. /*Delete from Package App App-Svc*/
  951. up = mfx->uiapplication;
  952. sp = mfx->serviceapplication;
  953. while(up != NULL)
  954. {
  955. snprintf(query, MAX_QUERY_LEN,
  956. "delete from package_app_app_svc where app_id='%s'", up->appid);
  957. ret = __exec_query(query);
  958. if (ret == -1) {
  959. DBG("Package App App-Svc DB Delete Failed\n");
  960. return -1;
  961. }
  962. memset(query, '\0', MAX_QUERY_LEN);
  963. up = up->next;
  964. }
  965. while(sp != NULL)
  966. {
  967. snprintf(query, MAX_QUERY_LEN,
  968. "delete from package_app_app_svc where app_id='%s'", sp->appid);
  969. ret = __exec_query(query);
  970. if (ret == -1) {
  971. DBG("Package App App-Svc DB Delete Failed\n");
  972. return -1;
  973. }
  974. memset(query, '\0', MAX_QUERY_LEN);
  975. sp = sp->next;
  976. }
  977. /*Delete from Package App Share Allowed*/
  978. up = mfx->uiapplication;
  979. sp = mfx->serviceapplication;
  980. while(up != NULL)
  981. {
  982. snprintf(query, MAX_QUERY_LEN,
  983. "delete from package_app_share_allowed where app_id='%s'", up->appid);
  984. ret = __exec_query(query);
  985. if (ret == -1) {
  986. DBG("Package App Share Allowed DB Delete Failed\n");
  987. return -1;
  988. }
  989. memset(query, '\0', MAX_QUERY_LEN);
  990. up = up->next;
  991. }
  992. while(sp != NULL)
  993. {
  994. snprintf(query, MAX_QUERY_LEN,
  995. "delete from package_app_share_allowed where app_id='%s'", sp->appid);
  996. ret = __exec_query(query);
  997. if (ret == -1) {
  998. DBG("Package App Share Allowed DB Delete Failed\n");
  999. return -1;
  1000. }
  1001. memset(query, '\0', MAX_QUERY_LEN);
  1002. sp = sp->next;
  1003. }
  1004. /*Delete from Package App Share Request*/
  1005. up = mfx->uiapplication;
  1006. sp = mfx->serviceapplication;
  1007. while(up != NULL)
  1008. {
  1009. snprintf(query, MAX_QUERY_LEN,
  1010. "delete from package_app_share_request where app_id='%s'", up->appid);
  1011. ret = __exec_query(query);
  1012. if (ret == -1) {
  1013. DBG("Package App Share Request DB Delete Failed\n");
  1014. return -1;
  1015. }
  1016. memset(query, '\0', MAX_QUERY_LEN);
  1017. up = up->next;
  1018. }
  1019. while(sp != NULL)
  1020. {
  1021. snprintf(query, MAX_QUERY_LEN,
  1022. "delete from package_app_share_request where app_id='%s'", sp->appid);
  1023. ret = __exec_query(query);
  1024. if (ret == -1) {
  1025. DBG("Package App Share Request DB Delete Failed\n");
  1026. return -1;
  1027. }
  1028. memset(query, '\0', MAX_QUERY_LEN);
  1029. sp = sp->next;
  1030. }
  1031. return 0;
  1032. }
  1033. int pkgmgr_parser_initialize_db()
  1034. {
  1035. int ret = -1;
  1036. ret = __initialize_package_info_db();
  1037. if (ret == -1) {
  1038. DBG("package info DB initialization failed\n");
  1039. return ret;
  1040. }
  1041. ret = __initialize_package_localized_info_db();
  1042. if (ret == -1) {
  1043. DBG("package localized info DB initialization failed\n");
  1044. return ret;
  1045. }
  1046. ret = __initialize_package_app_info_db();
  1047. if (ret == -1) {
  1048. DBG("package app info DB initialization failed\n");
  1049. return ret;
  1050. }
  1051. ret = __initialize_package_app_localized_info_db();
  1052. if (ret == -1) {
  1053. DBG("package app localized info DB initialization failed\n");
  1054. return ret;
  1055. }
  1056. ret = __initialize_package_app_app_svc_db();
  1057. if (ret == -1) {
  1058. DBG("package app app svc DB initialization failed\n");
  1059. return ret;
  1060. }
  1061. ret = __initialize_package_app_share_allowed_db();
  1062. if (ret == -1) {
  1063. DBG("package app share allowed DB initialization failed\n");
  1064. return ret;
  1065. }
  1066. ret = __initialize_package_app_share_request_db();
  1067. if (ret == -1) {
  1068. DBG("package app share request DB initialization failed\n");
  1069. return ret;
  1070. }
  1071. return 0;
  1072. }
  1073. int pkgmgr_parser_check_and_create_db()
  1074. {
  1075. int ret = -1;
  1076. if (access(PKGMGR_PARSER_DB_FILE, F_OK) == 0) {
  1077. ret =
  1078. db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
  1079. DB_UTIL_REGISTER_HOOK_METHOD);
  1080. if (ret != SQLITE_OK) {
  1081. DBG("connect db [%s] failed!\n",
  1082. PKGMGR_PARSER_DB_FILE);
  1083. return -1;
  1084. }
  1085. return 0;
  1086. }
  1087. DBG("Pkgmgr DB does not exists. Create one!!\n");
  1088. ret =
  1089. db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
  1090. DB_UTIL_REGISTER_HOOK_METHOD);
  1091. if (ret != SQLITE_OK) {
  1092. DBG("connect db [%s] failed!\n", PKGMGR_PARSER_DB_FILE);
  1093. return -1;
  1094. }
  1095. return 0;
  1096. }
  1097. API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
  1098. {
  1099. if (mfx == NULL) {
  1100. DBG("manifest pointer is NULL\n");
  1101. return -1;
  1102. }
  1103. int ret = -1;
  1104. ret = pkgmgr_parser_check_and_create_db();
  1105. if (ret == -1) {
  1106. DBG("Failed to open DB\n");
  1107. return ret;
  1108. }
  1109. ret = pkgmgr_parser_initialize_db();
  1110. if (ret == -1)
  1111. return ret;
  1112. /*Begin transaction*/
  1113. ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
  1114. if (ret != SQLITE_OK) {
  1115. DBG("Failed to begin transaction\n");
  1116. sqlite3_close(pkgmgr_parser_db);
  1117. return -1;
  1118. }
  1119. DBG("Transaction Begin\n");
  1120. ret = __insert_manifest_info_in_db(mfx);
  1121. if (ret == -1) {
  1122. DBG("Insert into DB failed. Rollback now\n");
  1123. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1124. sqlite3_close(pkgmgr_parser_db);
  1125. return -1;
  1126. }
  1127. /*Commit transaction*/
  1128. ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
  1129. if (ret != SQLITE_OK) {
  1130. DBG("Failed to commit transaction. Rollback now\n");
  1131. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1132. sqlite3_close(pkgmgr_parser_db);
  1133. return -1;
  1134. }
  1135. DBG("Transaction Commit and End\n");
  1136. sqlite3_close(pkgmgr_parser_db);
  1137. return 0;
  1138. }
  1139. API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
  1140. {
  1141. if (mfx == NULL) {
  1142. DBG("manifest pointer is NULL\n");
  1143. return -1;
  1144. }
  1145. int ret = -1;
  1146. ret = pkgmgr_parser_check_and_create_db();
  1147. if (ret == -1) {
  1148. DBG("Failed to open DB\n");
  1149. return ret;
  1150. }
  1151. ret = pkgmgr_parser_initialize_db();
  1152. if (ret == -1)
  1153. return ret;
  1154. /*Begin transaction*/
  1155. ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
  1156. if (ret != SQLITE_OK) {
  1157. DBG("Failed to begin transaction\n");
  1158. sqlite3_close(pkgmgr_parser_db);
  1159. return -1;
  1160. }
  1161. DBG("Transaction Begin\n");
  1162. ret = __delete_manifest_info_from_db(mfx);
  1163. if (ret == -1) {
  1164. DBG("Delete from DB failed. Rollback now\n");
  1165. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1166. sqlite3_close(pkgmgr_parser_db);
  1167. return -1;
  1168. }
  1169. ret = __insert_manifest_info_in_db(mfx);
  1170. if (ret == -1) {
  1171. DBG("Insert into DB failed. Rollback now\n");
  1172. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1173. sqlite3_close(pkgmgr_parser_db);
  1174. return -1;
  1175. }
  1176. /*Commit transaction*/
  1177. ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
  1178. if (ret != SQLITE_OK) {
  1179. DBG("Failed to commit transaction. Rollback now\n");
  1180. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1181. sqlite3_close(pkgmgr_parser_db);
  1182. return -1;
  1183. }
  1184. DBG("Transaction Commit and End\n");
  1185. sqlite3_close(pkgmgr_parser_db);
  1186. return 0;
  1187. }
  1188. API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
  1189. {
  1190. if (mfx == NULL) {
  1191. DBG("manifest pointer is NULL\n");
  1192. return -1;
  1193. }
  1194. int ret = -1;
  1195. ret = pkgmgr_parser_check_and_create_db();
  1196. if (ret == -1) {
  1197. DBG("Failed to open DB\n");
  1198. return ret;
  1199. }
  1200. /*Begin transaction*/
  1201. ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
  1202. if (ret != SQLITE_OK) {
  1203. DBG("Failed to begin transaction\n");
  1204. sqlite3_close(pkgmgr_parser_db);
  1205. return -1;
  1206. }
  1207. DBG("Transaction Begin\n");
  1208. ret = __delete_manifest_info_from_db(mfx);
  1209. if (ret == -1) {
  1210. DBG("Delete from DB failed. Rollback now\n");
  1211. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1212. sqlite3_close(pkgmgr_parser_db);
  1213. return -1;
  1214. }
  1215. /*Commit transaction*/
  1216. ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
  1217. if (ret != SQLITE_OK) {
  1218. DBG("Failed to commit transaction, Rollback now\n");
  1219. sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
  1220. sqlite3_close(pkgmgr_parser_db);
  1221. return -1;
  1222. }
  1223. DBG("Transaction Commit and End\n");
  1224. sqlite3_close(pkgmgr_parser_db);
  1225. return 0;
  1226. }