2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
35 #define DbgPrint(format, arg...) SECURE_LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
36 #define ErrPrint(format, arg...) SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
43 * +----+-------+-------+------+---------+-----------+------------+
44 * | id | pkgid | appid | Icon | Name | extra_key | extra_data |
45 * +----+-------+-------+------+---------+-----------+------------+
46 * | id | - | - | - | - | - | - |
47 * +----+-------+-------+------+---------+-----------+------------+
49 * +----+-------+------+------+
50 * | fk | pkgid | lang | name |
51 * +----+-------+------+------+
53 * +----+-------+------+------+
56 #if !defined(LIBXML_TREE_ENABLED)
57 #error "LIBXML is not supporting the tree"
66 .dbfile = "/opt/dbspace/.shortcut_service.db",
70 static inline int begin_transaction(void)
75 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
76 if (ret != SQLITE_OK) {
77 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
81 if (sqlite3_step(stmt) != SQLITE_DONE) {
82 DbgPrint("Failed to do update (%s)\n",
83 sqlite3_errmsg(s_info.handle));
84 sqlite3_finalize(stmt);
88 sqlite3_finalize(stmt);
92 static inline int rollback_transaction(void)
97 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
98 if (ret != SQLITE_OK) {
99 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
103 if (sqlite3_step(stmt) != SQLITE_DONE) {
104 DbgPrint("Failed to do update (%s)\n",
105 sqlite3_errmsg(s_info.handle));
106 sqlite3_finalize(stmt);
110 sqlite3_finalize(stmt);
114 static inline int commit_transaction(void)
119 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
120 if (ret != SQLITE_OK) {
121 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
125 if (sqlite3_step(stmt) != SQLITE_DONE) {
126 DbgPrint("Failed to do update (%s)\n",
127 sqlite3_errmsg(s_info.handle));
128 sqlite3_finalize(stmt);
132 sqlite3_finalize(stmt);
135 static void db_create_table(void)
138 static const char *ddl =
139 "CREATE TABLE shortcut_service ("
140 "id INTEGER PRIMARY KEY AUTOINCREMENT, "
148 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
149 ErrPrint("Failed to execute the DDL (%s)\n", err);
153 if (sqlite3_changes(s_info.handle) == 0) {
154 ErrPrint("No changes to DB\n");
157 ddl = "CREATE TABLE shortcut_name (id INTEGER, pkgid TEXT, lang TEXT, name TEXT)";
158 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
159 ErrPrint("Failed to execute the DDL (%s)\n", err);
163 if (sqlite3_changes(s_info.handle) == 0) {
164 ErrPrint("No changes to DB\n");
168 static void alter_shortcut_name(void)
171 static const char *ddl = "ALTER TABLE shortcut_name ADD pkgid TEXT";
173 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
174 ErrPrint("Failed to execute the DDL (%s)\n", err);
178 if (sqlite3_changes(s_info.handle) == 0) {
179 ErrPrint("No changes to DB\n");
183 static void alter_shortcut_service(void)
186 static const char *ddl = "ALTER TABLE shortcut_service ADD pkgid TEXT";
188 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
189 ErrPrint("Failed to execute the DDL (%s)\n", err);
193 if (sqlite3_changes(s_info.handle) == 0) {
194 ErrPrint("No changes to DB\n");
198 static int db_remove_by_pkgid(const char *pkgid)
200 static const char *dml = "DELETE FROM shortcut_service WHERE pkgid = ?";
205 ErrPrint("Invalid argument\n");
209 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
210 if (ret != SQLITE_OK) {
211 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
216 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
217 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
222 if (sqlite3_step(stmt) != SQLITE_DONE) {
224 ErrPrint("Failed to execute the DML for %s\n", pkgid);
226 if (sqlite3_changes(s_info.handle) == 0) {
227 DbgPrint("No changed\n");
233 sqlite3_clear_bindings(stmt);
234 sqlite3_finalize(stmt);
238 static int do_upgrade_db_schema(void)
240 static const char *dml = ".schema";
248 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
249 if (ret != SQLITE_OK) {
250 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
255 while (sqlite3_step(stmt) == SQLITE_ROW) {
256 schema = (const char *)sqlite3_column_text(stmt, 0);
257 if (!schema || !strlen(schema)) {
261 bufsz = strlen(schema) + 1;
263 table = malloc(bufsz);
265 ErrPrint("Heap: %s\n", strerror(errno));
272 ErrPrint("Heap: %s\n", strerror(errno));
278 if (sscanf(schema, "CREATE TABLE %s (%[^)])", table, ddl) != 2) {
281 ErrPrint("Invalid syntax: (%s)\n", schema);
285 if (!strcmp(table, "shortcut_name")) {
286 if (!strstr(ddl, "pkgid")) {
287 alter_shortcut_name();
289 } else if (!strcmp(table, "shortcut_service")) {
290 if (!strstr(ddl, "pkgid")) {
291 alter_shortcut_service();
294 ErrPrint("Unknown table: %s\n", table);
303 sqlite3_clear_bindings(stmt);
304 sqlite3_finalize(stmt);
309 static int db_remove_record(const char *pkgid, const char *appid, const char *key, const char *data)
311 static const char *dml = "DELETE FROM shortcut_service WHERE appid = ? AND extra_key = ? AND extra_data = ? AND pkgid = ?";
315 if (!appid || !key || !data) {
316 ErrPrint("Invalid argument\n");
320 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
321 if (ret != SQLITE_OK) {
322 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
327 if (sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
328 ErrPrint("Failed to bind a appid(%s)\n", sqlite3_errmsg(s_info.handle));
332 if (sqlite3_bind_text(stmt, 2, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
333 ErrPrint("Failed to bind a key(%s)\n", sqlite3_errmsg(s_info.handle));
337 if (sqlite3_bind_text(stmt, 3, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
338 ErrPrint("Failed to bind a data(%s)\n", sqlite3_errmsg(s_info.handle));
342 if (sqlite3_bind_text(stmt, 4, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
343 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
348 if (sqlite3_step(stmt) != SQLITE_DONE) {
350 ErrPrint("Failed to execute the DML for %s - %s(%s)\n", appid, key, data);
353 if (sqlite3_changes(s_info.handle) == 0) {
354 DbgPrint("No changes\n");
359 sqlite3_clear_bindings(stmt);
360 sqlite3_finalize(stmt);
364 static int db_remove_name_by_pkgid(const char *pkgid)
366 static const char *dml = "DELETE FROM shortcut_name WHERE pkgid = ?";
371 ErrPrint("Invalid id\n");
375 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
376 if (ret != SQLITE_OK) {
377 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
381 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
382 ErrPrint("Failed to bind pkgid(%s)\n", pkgid);
387 if (sqlite3_step(stmt) != SQLITE_DONE) {
389 ErrPrint("Failed to execute the DML for %s\n", pkgid);
393 if (sqlite3_changes(s_info.handle) == 0) {
394 DbgPrint("No chnages\n");
399 sqlite3_clear_bindings(stmt);
400 sqlite3_finalize(stmt);
404 static int db_remove_name(int id)
406 static const char *dml = "DELETE FROM shortcut_name WHERE id = ?";
411 ErrPrint("Inavlid id\n");
415 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
416 if (ret != SQLITE_OK) {
417 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
421 if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
422 ErrPrint("Failed to bind id(%d)\n", id);
428 if (sqlite3_step(stmt) != SQLITE_DONE) {
430 ErrPrint("Failed to execute the DML for %d\n", id);
434 if (sqlite3_changes(s_info.handle) == 0) {
435 DbgPrint("No changes\n");
440 sqlite3_clear_bindings(stmt);
441 sqlite3_finalize(stmt);
445 static int db_insert_record(const char *pkgid, const char *appid, const char *icon, const char *name, const char *key, const char *data)
447 static const char *dml = "INSERT INTO shortcut_service (pkgid, appid, icon, name, extra_key, extra_data) VALUES (?, ?, ?, ?, ?, ?)";
452 ErrPrint("Failed to get pkgid\n");
457 ErrPrint("Failed to get appid\n");
462 ErrPrint("Failed to get name\n");
467 ErrPrint("Failed to get key\n");
472 ErrPrint("Faield to get key\n");
476 icon = icon ? icon : "";
478 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
479 if (ret != SQLITE_OK) {
480 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
485 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
486 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
490 if (sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
491 ErrPrint("Failed to bind a appid(%s)\n", sqlite3_errmsg(s_info.handle));
495 if (sqlite3_bind_text(stmt, 3, icon, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
496 ErrPrint("Failed to bind a icon(%s)\n", sqlite3_errmsg(s_info.handle));
500 if (sqlite3_bind_text(stmt, 4, name, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
501 ErrPrint("Failed to bind a name(%s)\n", sqlite3_errmsg(s_info.handle));
505 if (sqlite3_bind_text(stmt, 5, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
506 ErrPrint("Failed to bind a service(%s)\n", sqlite3_errmsg(s_info.handle));
510 if (sqlite3_bind_text(stmt, 6, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
511 ErrPrint("Failed to bind a service(%s)\n", sqlite3_errmsg(s_info.handle));
516 if (sqlite3_step(stmt) != SQLITE_DONE) {
517 ErrPrint("Failed to execute the DML for %s - %s\n", appid, name);
523 sqlite3_clear_bindings(stmt);
524 sqlite3_finalize(stmt);
528 static int db_insert_name(int id, const char *pkgid, const char *lang, const char *name)
530 static const char *dml = "INSERT INTO shortcut_name (id, pkgid, lang, name) VALUES (?, ?, ?, ?)";
534 if (id < 0 || !lang || !name) {
535 ErrPrint("Invalid parameters\n");
539 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
540 if (ret != SQLITE_OK) {
541 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
545 if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
546 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
551 if (sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
552 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
557 if (sqlite3_bind_text(stmt, 3, lang, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
558 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
563 if (sqlite3_bind_text(stmt, 4, name, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
564 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
570 if (sqlite3_step(stmt) != SQLITE_DONE) {
571 ErrPrint("Failed to execute the DML for %d %s %s\n", id, lang, name);
577 sqlite3_clear_bindings(stmt);
578 sqlite3_finalize(stmt);
582 static int db_get_id(const char *pkgid, const char *appid, const char *key, const char *data)
584 static const char *dml = "SELECT id FROM shortcut_service WHERE pkgid = ? AND appid = ? AND extra_key = ? AND extra_data = ?";
588 if (!appid || !key || !data) {
589 ErrPrint("Invalid argument\n");
593 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
594 if (ret != SQLITE_OK) {
595 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
600 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
601 ErrPrint("Failed to bind a pkgid(%s) - %s\n", pkgid, sqlite3_errmsg(s_info.handle));
605 if (sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
606 ErrPrint("Failed to bind a appid(%s) - %s\n", appid, sqlite3_errmsg(s_info.handle));
610 if (sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
611 ErrPrint("Failed to bind a key(%s) - %s\n", key, sqlite3_errmsg(s_info.handle));
615 if (sqlite3_bind_text(stmt, 4, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
616 ErrPrint("Failed to bind a data(%s) - %s\n", data, sqlite3_errmsg(s_info.handle));
620 if (sqlite3_step(stmt) != SQLITE_ROW) {
621 ErrPrint("Failed to execute the DML for %s - %s, %s\n", appid, key, data);
626 ret = sqlite3_column_int(stmt, 0);
630 sqlite3_clear_bindings(stmt);
631 sqlite3_finalize(stmt);
635 static int db_init(void)
640 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
641 if (ret != SQLITE_OK) {
642 ErrPrint("Failed to open a DB\n");
646 if (lstat(s_info.dbfile, &stat) < 0) {
647 ErrPrint("%s\n", strerror(errno));
648 db_util_close(s_info.handle);
649 s_info.handle = NULL;
653 if (!S_ISREG(stat.st_mode)) {
654 ErrPrint("Invalid file\n");
655 db_util_close(s_info.handle);
656 s_info.handle = NULL;
667 static int db_fini(void)
669 if (!s_info.handle) {
673 db_util_close(s_info.handle);
674 s_info.handle = NULL;
679 static int do_uninstall(const char *appid)
683 ret = db_remove_by_pkgid(appid);
685 ErrPrint("Failed to remove a record: %s\n", appid);
689 ret = db_remove_name_by_pkgid(appid);
691 ErrPrint("Failed to remove name records: %s\n", appid);
698 static int do_install(xmlDocPtr docPtr, const char *appid)
700 xmlNodePtr node = NULL;
701 xmlNodePtr child = NULL;
706 xmlChar *shortcut_appid;
712 struct dlist *i18n_list = NULL;
717 root = xmlDocGetRootElement(docPtr);
719 ErrPrint("Invalid node ptr\n");
723 for (root = root->children; root; root = root->next) {
724 if (!xmlStrcasecmp(root->name, (const xmlChar *)"shortcut-list")) {
730 ErrPrint("Root has no children\n");
734 DbgPrint("AppID: %s\n", appid);
736 root = root->children; /* Jump to children node */
737 for (node = root; node; node = node->next) {
738 if (node->type == XML_ELEMENT_NODE) {
739 DbgPrint("Element %s\n", node->name);
742 if (xmlStrcasecmp(node->name, (const xmlChar *)"shortcut")) {
746 if (!xmlHasProp(node, (xmlChar *)"extra_key") || !xmlHasProp(node, (xmlChar *)"extra_data")) {
747 DbgPrint("Invalid element %s\n", node->name);
751 key = xmlGetProp(node, (xmlChar *)"extra_key");
752 data = xmlGetProp(node, (xmlChar *)"extra_data");
753 shortcut_appid = xmlGetProp(node, (xmlChar *)"appid");
757 for (child = node->children; child; child = child->next) {
758 if (!xmlStrcasecmp(child->name, (const xmlChar *)"icon")) {
760 DbgPrint("Icon is duplicated\n");
764 icon = xmlNodeGetContent(child);
768 if (!xmlStrcasecmp(child->name, (const xmlChar *)"label")) {
770 lang = xmlNodeGetLang(child);
773 DbgPrint("Default name is duplicated\n");
775 name = xmlNodeGetContent(child);
776 DbgPrint("Default name is %s\n", name);
782 i18n = malloc(sizeof(*i18n));
784 ErrPrint("Heap: %s\n", strerror(errno));
789 i18n->name = xmlNodeGetContent(child);
790 i18n_list = dlist_append(i18n_list, i18n);
795 DbgPrint("appid: %s\n", appid);
796 DbgPrint("shortcut appid: %s\n", shortcut_appid);
797 DbgPrint("key: %s\n", key);
798 DbgPrint("data: %s\n", data);
799 DbgPrint("icon: %s\n", icon);
800 DbgPrint("Default name: %s\n", name);
802 if (!shortcut_appid) {
803 shortcut_appid = xmlStrdup((xmlChar *)appid);
804 DbgPrint("Use the default appid\n");
808 if (db_insert_record(appid, (char *)shortcut_appid, (char *)icon, (char *)name, (char *)key, (char *)data) < 0) {
809 ErrPrint("Failed to insert a new record\n");
810 rollback_transaction();
812 dlist_foreach_safe(i18n_list, l, n, i18n) {
813 i18n_list = dlist_remove(i18n_list, l);
819 id = db_get_id((char *)appid, (char *)shortcut_appid, (char *)key, (char *)data);
821 ErrPrint("Failed to insert a new record\n");
822 rollback_transaction();
824 dlist_foreach_safe(i18n_list, l, n, i18n) {
825 i18n_list = dlist_remove(i18n_list, l);
831 dlist_foreach_safe(i18n_list, l, n, i18n) {
832 i18n_list = dlist_remove(i18n_list, l);
833 if (db_insert_name(id, appid, (char *)i18n->lang, (char *)i18n->name) < 0) {
834 ErrPrint("Failed to add i18n name: %s(%s)\n", i18n->name, i18n->lang);
840 commit_transaction();
848 xmlFree(shortcut_appid);
854 int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *appid)
856 if (!s_info.handle) {
862 do_upgrade_db_schema();
866 int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *appid)
871 ret = do_uninstall(appid);
873 rollback_transaction();
876 commit_transaction();
882 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *_appid)
884 xmlNodePtr node = NULL;
891 root = xmlDocGetRootElement(docPtr);
893 ErrPrint("Invalid node ptr\n");
897 for (root = root->children; root; root = root->next) {
898 if (!xmlStrcasecmp(root->name, (const xmlChar *)"shortcut-list")) {
904 ErrPrint("Root has no shortcut-list\n");
908 DbgPrint("AppID: %s\n", _appid);
909 root = root->children;
910 for (node = root; node; node = node->next) {
911 if (node->type == XML_ELEMENT_NODE) {
912 DbgPrint("Element %s\n", node->name);
915 if (xmlStrcasecmp(node->name, (const xmlChar *)"shortcut")) {
919 if (!xmlHasProp(node, (xmlChar *)"extra_data")
920 || !xmlHasProp(node, (xmlChar *)"extra_key")
921 || !xmlHasProp(node, (xmlChar *)"appid"))
923 DbgPrint("Invalid element %s\n", node->name);
927 appid = xmlGetProp(node, (xmlChar *)"appid");
928 key = xmlGetProp(node, (xmlChar *)"extra_key");
929 data = xmlGetProp(node, (xmlChar *)"extra_data");
931 DbgPrint("appid: %s\n", appid);
932 DbgPrint("key: %s\n", key);
933 DbgPrint("data: %s\n", data);
935 id = db_get_id("", (char *)appid, (char *)key, (char *)data);
937 ErrPrint("No records found\n");
945 if (db_remove_record("", (char *)appid, (char *)key, (char *)data) < 0) {
946 ErrPrint("Failed to remove a record\n");
947 rollback_transaction();
954 if (db_remove_name(id) < 0) {
955 ErrPrint("Failed to remove name records\n");
956 rollback_transaction();
962 commit_transaction();
970 * if (node->children)
971 * DbgPrint("Skip this node's children\n");
978 int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *appid)
982 if (!s_info.handle) {
988 do_upgrade_db_schema();
991 ret = do_uninstall(appid);
993 ErrPrint("Failed to remove record: %s\n", appid);
994 rollback_transaction();
997 commit_transaction();
1001 int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *appid)
1007 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
1009 return do_install(docPtr, appid);
1012 int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *appid)
1016 if (!s_info.handle) {
1017 if (db_init() < 0) {
1022 do_upgrade_db_schema();
1024 begin_transaction();
1025 ret = do_uninstall(appid);
1027 ErrPrint("Failed to remove a record: %s\n", appid);
1028 rollback_transaction();
1031 commit_transaction();
1035 int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *appid)
1041 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
1044 return do_install(docPtr, appid);
1048 int main(int argc, char *argv[])
1054 ErrPRint("Invalid argument: %s XML_FILENAME\n", argv[0]);
1058 doc = xmlReadFile(argv[1], NULL, 0);
1060 ErrPrint("Failed to parse %s\n", argv[1]);
1064 root = xmlDocGetRootElement(doc);
1067 install_shortcut("", root);