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>
34 #if !defined(SECURE_LOGD)
35 #define SECURE_LOGD LOGD
38 #if !defined(SECURE_LOGE)
39 #define SECURE_LOGE LOGE
42 #if !defined(SECURE_LOGW)
43 #define SECURE_LOGW LOGW
47 #define DbgPrint(format, arg...) SECURE_LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
48 #define ErrPrint(format, arg...) SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
55 * +----+-------+-------+------+---------+-----------+------------+
56 * | id | pkgid | appid | Icon | Name | extra_key | extra_data |
57 * +----+-------+-------+------+---------+-----------+------------+
58 * | id | - | - | - | - | - | - |
59 * +----+-------+-------+------+---------+-----------+------------+
61 * +----+-------+------+------+------+
62 * | fk | pkgid | lang | name | icon |
63 * +----+-------+------+------+------+
64 * | id | - | - | | - |
65 * +----+-------+------+------+------+
68 #if !defined(LIBXML_TREE_ENABLED)
69 #error "LIBXML is not supporting the tree"
84 .dbfile = "/opt/dbspace/.shortcut_service.db",
88 static inline int begin_transaction(void)
93 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
94 if (ret != SQLITE_OK) {
95 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
99 if (sqlite3_step(stmt) != SQLITE_DONE) {
100 DbgPrint("Failed to do update (%s)\n",
101 sqlite3_errmsg(s_info.handle));
102 sqlite3_finalize(stmt);
106 sqlite3_finalize(stmt);
110 static inline int rollback_transaction(void)
115 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
116 if (ret != SQLITE_OK) {
117 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
121 if (sqlite3_step(stmt) != SQLITE_DONE) {
122 DbgPrint("Failed to do update (%s)\n",
123 sqlite3_errmsg(s_info.handle));
124 sqlite3_finalize(stmt);
128 sqlite3_finalize(stmt);
132 static inline int commit_transaction(void)
137 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
138 if (ret != SQLITE_OK) {
139 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
143 if (sqlite3_step(stmt) != SQLITE_DONE) {
144 DbgPrint("Failed to do update (%s)\n",
145 sqlite3_errmsg(s_info.handle));
146 sqlite3_finalize(stmt);
150 sqlite3_finalize(stmt);
154 static void db_create_version(void)
156 static const char *ddl = "CREATE TABLE version (version INTEGER)";
159 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
160 ErrPrint("Failed to execute the DDL (%s)\n", err);
164 if (sqlite3_changes(s_info.handle) == 0) {
165 ErrPrint("No changes to DB\n");
169 static int set_version(int version)
171 static const char *dml = "INSERT INTO version (version) VALUES (?)";
175 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
176 if (ret != SQLITE_OK) {
177 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
181 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
182 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
187 ret = sqlite3_step(stmt);
188 if (ret != SQLITE_DONE) {
189 ErrPrint("Failed to execute the DML for version: %d\n", ret);
197 sqlite3_clear_bindings(stmt);
198 sqlite3_finalize(stmt);
202 static int update_version(int version)
204 static const char *dml = "UPDATE version SET version = ?";
208 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
209 if (ret != SQLITE_OK) {
210 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
214 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
215 ErrPrint("Failed to bind a version: %s\n", sqlite3_errmsg(s_info.handle));
220 ret = sqlite3_step(stmt);
221 if (ret != SQLITE_DONE) {
222 ErrPrint("Failed to execute DML: %d\n", ret);
230 sqlite3_clear_bindings(stmt);
231 sqlite3_finalize(stmt);
235 static int get_version(void)
237 static const char *dml = "SELECT version FROM version";
241 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
242 if (ret != SQLITE_OK) {
246 if (sqlite3_step(stmt) != SQLITE_ROW) {
249 ret = sqlite3_column_int(stmt, 0);
253 sqlite3_clear_bindings(stmt);
254 sqlite3_finalize(stmt);
258 static void db_create_table(void)
261 static const char *ddl =
262 "CREATE TABLE shortcut_service ("
263 "id INTEGER PRIMARY KEY AUTOINCREMENT, "
271 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
272 ErrPrint("Failed to execute the DDL (%s)\n", err);
276 if (sqlite3_changes(s_info.handle) == 0) {
277 ErrPrint("No changes to DB\n");
280 ddl = "CREATE TABLE shortcut_name (id INTEGER, pkgid TEXT, lang TEXT, name TEXT, icon TEXT)";
281 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
282 ErrPrint("Failed to execute the DDL (%s)\n", err);
286 if (sqlite3_changes(s_info.handle) == 0) {
287 ErrPrint("No changes to DB\n");
293 static void alter_shortcut_icon(void)
296 static const char *ddl = "ALTER TABLE shortcut_name ADD icon TEXT";
298 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
299 ErrPrint("Failed to execute the DDL (%s)\n", err);
303 if (sqlite3_changes(s_info.handle) == 0) {
304 ErrPrint("No changes to DB\n");
308 static void alter_shortcut_name(void)
311 static const char *ddl = "ALTER TABLE shortcut_name ADD pkgid TEXT";
313 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
314 ErrPrint("Failed to execute the DDL (%s)\n", err);
318 if (sqlite3_changes(s_info.handle) == 0) {
319 ErrPrint("No changes to DB\n");
323 static void alter_shortcut_service(void)
326 static const char *ddl = "ALTER TABLE shortcut_service ADD pkgid TEXT";
328 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
329 ErrPrint("Failed to execute the DDL (%s)\n", err);
333 if (sqlite3_changes(s_info.handle) == 0) {
334 ErrPrint("No changes to DB\n");
338 static int db_remove_by_pkgid(const char *pkgid)
340 static const char *dml = "DELETE FROM shortcut_service WHERE pkgid = ?";
345 ErrPrint("Invalid argument\n");
349 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
350 if (ret != SQLITE_OK) {
351 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
356 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
357 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
362 if (sqlite3_step(stmt) != SQLITE_DONE) {
364 ErrPrint("Failed to execute the DML for %s\n", pkgid);
366 if (sqlite3_changes(s_info.handle) == 0) {
367 DbgPrint("No changed\n");
373 sqlite3_clear_bindings(stmt);
374 sqlite3_finalize(stmt);
378 static void do_upgrade_db_schema(void)
382 version = get_version();
387 /* Need to create version table */
389 if (set_version(1) < 0) {
390 ErrPrint("Failed to set version\n");
392 /* Need to set version */
393 alter_shortcut_name();
394 alter_shortcut_service();
396 alter_shortcut_icon();
397 if (update_version(2) < 0) {
398 ErrPrint("Failed to update version\n");
403 /* Need to update version */
404 DbgPrint("Old version: %d\n", version);
405 if (update_version(2) < 0) {
406 ErrPrint("Failed to update version\n");
409 alter_shortcut_name();
410 alter_shortcut_service();
412 alter_shortcut_icon();
417 static int db_remove_record(const char *pkgid, const char *appid, const char *key, const char *data)
419 static const char *dml = "DELETE FROM shortcut_service WHERE appid = ? AND extra_key = ? AND extra_data = ? AND pkgid = ?";
423 if (!appid || !key || !data) {
424 ErrPrint("Invalid argument\n");
428 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
429 if (ret != SQLITE_OK) {
430 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
435 if (sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
436 ErrPrint("Failed to bind a appid(%s)\n", sqlite3_errmsg(s_info.handle));
440 if (sqlite3_bind_text(stmt, 2, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
441 ErrPrint("Failed to bind a key(%s)\n", sqlite3_errmsg(s_info.handle));
445 if (sqlite3_bind_text(stmt, 3, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
446 ErrPrint("Failed to bind a data(%s)\n", sqlite3_errmsg(s_info.handle));
450 if (sqlite3_bind_text(stmt, 4, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
451 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
456 if (sqlite3_step(stmt) != SQLITE_DONE) {
458 ErrPrint("Failed to execute the DML for %s - %s(%s)\n", appid, key, data);
461 if (sqlite3_changes(s_info.handle) == 0) {
462 DbgPrint("No changes\n");
467 sqlite3_clear_bindings(stmt);
468 sqlite3_finalize(stmt);
472 static int db_remove_name_by_pkgid(const char *pkgid)
474 static const char *dml = "DELETE FROM shortcut_name WHERE pkgid = ?";
479 ErrPrint("Invalid id\n");
483 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
484 if (ret != SQLITE_OK) {
485 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
489 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
490 ErrPrint("Failed to bind pkgid(%s)\n", pkgid);
495 if (sqlite3_step(stmt) != SQLITE_DONE) {
497 ErrPrint("Failed to execute the DML for %s\n", pkgid);
501 if (sqlite3_changes(s_info.handle) == 0) {
502 DbgPrint("No chnages\n");
507 sqlite3_clear_bindings(stmt);
508 sqlite3_finalize(stmt);
512 static int db_remove_name(int id)
514 static const char *dml = "DELETE FROM shortcut_name WHERE id = ?";
519 ErrPrint("Inavlid id\n");
523 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
524 if (ret != SQLITE_OK) {
525 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
529 if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
530 ErrPrint("Failed to bind id(%d)\n", id);
536 if (sqlite3_step(stmt) != SQLITE_DONE) {
538 ErrPrint("Failed to execute the DML for %d\n", id);
542 if (sqlite3_changes(s_info.handle) == 0) {
543 DbgPrint("No changes\n");
548 sqlite3_clear_bindings(stmt);
549 sqlite3_finalize(stmt);
553 static int db_insert_record(const char *pkgid, const char *appid, const char *icon, const char *name, const char *key, const char *data)
555 static const char *dml = "INSERT INTO shortcut_service (pkgid, appid, icon, name, extra_key, extra_data) VALUES (?, ?, ?, ?, ?, ?)";
560 ErrPrint("Failed to get pkgid\n");
565 ErrPrint("Failed to get appid\n");
570 ErrPrint("Failed to get name\n");
575 ErrPrint("Failed to get key\n");
580 ErrPrint("Faield to get key\n");
584 icon = icon ? icon : "";
586 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
587 if (ret != SQLITE_OK) {
588 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
593 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
594 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
598 if (sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
599 ErrPrint("Failed to bind a appid(%s)\n", sqlite3_errmsg(s_info.handle));
603 if (sqlite3_bind_text(stmt, 3, icon, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
604 ErrPrint("Failed to bind a icon(%s)\n", sqlite3_errmsg(s_info.handle));
608 if (sqlite3_bind_text(stmt, 4, name, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
609 ErrPrint("Failed to bind a name(%s)\n", sqlite3_errmsg(s_info.handle));
613 if (sqlite3_bind_text(stmt, 5, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
614 ErrPrint("Failed to bind a service(%s)\n", sqlite3_errmsg(s_info.handle));
618 if (sqlite3_bind_text(stmt, 6, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
619 ErrPrint("Failed to bind a service(%s)\n", sqlite3_errmsg(s_info.handle));
624 if (sqlite3_step(stmt) != SQLITE_DONE) {
625 ErrPrint("Failed to execute the DML for %s - %s\n", appid, name);
631 sqlite3_clear_bindings(stmt);
632 sqlite3_finalize(stmt);
636 static int db_insert_name(int id, const char *pkgid, const char *lang, const char *name, const char *icon)
638 static const char *dml = "INSERT INTO shortcut_name (id, pkgid, lang, name, icon) VALUES (?, ?, ?, ?, ?)";
642 if (id < 0 || !lang) {
643 ErrPrint("Invalid parameters\n");
655 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
656 if (ret != SQLITE_OK) {
657 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
661 if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
662 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
667 if (sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
668 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
673 if (sqlite3_bind_text(stmt, 3, lang, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
674 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
679 if (sqlite3_bind_text(stmt, 4, name, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
680 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
685 if (sqlite3_bind_text(stmt, 5, icon, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
686 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
692 if (sqlite3_step(stmt) != SQLITE_DONE) {
693 ErrPrint("Failed to execute the DML for %d %s %s\n", id, lang, name);
699 sqlite3_clear_bindings(stmt);
700 sqlite3_finalize(stmt);
704 static int db_get_id(const char *pkgid, const char *appid, const char *key, const char *data)
706 static const char *dml = "SELECT id FROM shortcut_service WHERE pkgid = ? AND appid = ? AND extra_key = ? AND extra_data = ?";
710 if (!appid || !key || !data) {
711 ErrPrint("Invalid argument\n");
715 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
716 if (ret != SQLITE_OK) {
717 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
722 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
723 ErrPrint("Failed to bind a pkgid(%s) - %s\n", pkgid, sqlite3_errmsg(s_info.handle));
727 if (sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
728 ErrPrint("Failed to bind a appid(%s) - %s\n", appid, sqlite3_errmsg(s_info.handle));
732 if (sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
733 ErrPrint("Failed to bind a key(%s) - %s\n", key, sqlite3_errmsg(s_info.handle));
737 if (sqlite3_bind_text(stmt, 4, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
738 ErrPrint("Failed to bind a data(%s) - %s\n", data, sqlite3_errmsg(s_info.handle));
742 if (sqlite3_step(stmt) != SQLITE_ROW) {
743 ErrPrint("Failed to execute the DML for %s - %s, %s\n", appid, key, data);
748 ret = sqlite3_column_int(stmt, 0);
752 sqlite3_clear_bindings(stmt);
753 sqlite3_finalize(stmt);
757 static int db_init(void)
762 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
763 if (ret != SQLITE_OK) {
764 ErrPrint("Failed to open a DB\n");
768 if (lstat(s_info.dbfile, &stat) < 0) {
769 ErrPrint("%s\n", strerror(errno));
770 db_util_close(s_info.handle);
771 s_info.handle = NULL;
775 if (!S_ISREG(stat.st_mode)) {
776 ErrPrint("Invalid file\n");
777 db_util_close(s_info.handle);
778 s_info.handle = NULL;
789 static int db_fini(void)
791 if (!s_info.handle) {
795 db_util_close(s_info.handle);
796 s_info.handle = NULL;
801 static int do_uninstall(const char *appid)
805 ret = db_remove_by_pkgid(appid);
807 ErrPrint("Failed to remove a record: %s\n", appid);
811 ret = db_remove_name_by_pkgid(appid);
813 ErrPrint("Failed to remove name records: %s\n", appid);
820 static inline struct i18n_name *find_i18n_name(struct dlist *i18n_list, xmlChar *lang)
823 struct i18n_name *i18n;
825 dlist_foreach(i18n_list, l, i18n) {
826 if (!xmlStrcasecmp(i18n->lang, lang)) {
834 static inline struct i18n_name *create_i18n_name(xmlChar *lang, xmlChar *name, xmlChar *icon)
836 struct i18n_name *i18n;
838 i18n = malloc(sizeof(*i18n));
840 ErrPrint("Heap: %s\n", strerror(errno));
851 static inline void destroy_i18n_name(struct i18n_name *i18n)
859 static int do_install(xmlDocPtr docPtr, const char *appid)
861 xmlNodePtr node = NULL;
862 xmlNodePtr child = NULL;
868 xmlChar *shortcut_appid;
870 struct i18n_name *i18n;
871 struct dlist *i18n_list = NULL;
876 root = xmlDocGetRootElement(docPtr);
878 ErrPrint("Invalid node ptr\n");
882 for (root = root->children; root; root = root->next) {
883 if (!xmlStrcasecmp(root->name, (const xmlChar *)"shortcut-list")) {
889 ErrPrint("Root has no children\n");
893 DbgPrint("AppID: %s\n", appid);
895 root = root->children; /* Jump to children node */
896 for (node = root; node; node = node->next) {
897 if (node->type == XML_ELEMENT_NODE) {
898 DbgPrint("Element %s\n", node->name);
901 if (xmlStrcasecmp(node->name, (const xmlChar *)"shortcut")) {
905 if (!xmlHasProp(node, (xmlChar *)"extra_key") || !xmlHasProp(node, (xmlChar *)"extra_data")) {
906 DbgPrint("Invalid element %s\n", node->name);
910 key = xmlGetProp(node, (xmlChar *)"extra_key");
911 data = xmlGetProp(node, (xmlChar *)"extra_data");
912 shortcut_appid = xmlGetProp(node, (xmlChar *)"appid");
916 for (child = node->children; child; child = child->next) {
917 if (!xmlStrcasecmp(child->name, (const xmlChar *)"icon")) {
918 lang = xmlNodeGetLang(child);
921 DbgPrint("Default icon is duplicated\n");
923 icon = xmlNodeGetContent(child);
924 DbgPrint("Default icon is %s\n", icon);
930 i18n = find_i18n_name(i18n_list, lang);
935 DbgPrint("%s is duplicated\n", i18n->icon);
939 i18n->icon = xmlNodeGetContent(child);
941 i18n = create_i18n_name(lang, NULL, xmlNodeGetContent(child));
943 ErrPrint("Failed to create a new i18n_name\n");
946 i18n_list = dlist_append(i18n_list, i18n);
952 if (!xmlStrcasecmp(child->name, (const xmlChar *)"label")) {
953 lang = xmlNodeGetLang(child);
956 DbgPrint("Default name is duplicated\n");
958 name = xmlNodeGetContent(child);
959 DbgPrint("Default name is %s\n", name);
965 i18n = find_i18n_name(i18n_list, lang);
970 DbgPrint("%s is duplicated\n", i18n->name);
974 i18n->name = xmlNodeGetContent(child);
976 i18n = create_i18n_name(lang, xmlNodeGetContent(child), NULL);
978 ErrPrint("Failed to create a new i18n_name\n");
981 i18n_list = dlist_append(i18n_list, i18n);
988 DbgPrint("appid: %s\n", appid);
989 DbgPrint("shortcut appid: %s\n", shortcut_appid);
990 DbgPrint("key: %s\n", key);
991 DbgPrint("data: %s\n", data);
992 DbgPrint("icon: %s\n", icon);
993 DbgPrint("Default name: %s\n", name);
995 if (!shortcut_appid) {
996 shortcut_appid = xmlStrdup((xmlChar *)appid);
997 DbgPrint("Use the default appid\n");
1000 begin_transaction();
1001 if (db_insert_record(appid, (char *)shortcut_appid, (char *)icon, (char *)name, (char *)key, (char *)data) < 0) {
1002 ErrPrint("Failed to insert a new record\n");
1003 rollback_transaction();
1005 dlist_foreach_safe(i18n_list, l, n, i18n) {
1006 i18n_list = dlist_remove(i18n_list, l);
1007 destroy_i18n_name(i18n);
1010 id = db_get_id((char *)appid, (char *)shortcut_appid, (char *)key, (char *)data);
1012 ErrPrint("Failed to insert a new record\n");
1013 rollback_transaction();
1015 dlist_foreach_safe(i18n_list, l, n, i18n) {
1016 i18n_list = dlist_remove(i18n_list, l);
1017 destroy_i18n_name(i18n);
1020 dlist_foreach_safe(i18n_list, l, n, i18n) {
1021 i18n_list = dlist_remove(i18n_list, l);
1022 if (db_insert_name(id, appid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon) < 0) {
1023 ErrPrint("Failed to add i18n name: %s(%s)\n", i18n->name, i18n->lang);
1025 destroy_i18n_name(i18n);
1027 commit_transaction();
1035 xmlFree(shortcut_appid);
1041 int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *appid)
1043 if (!s_info.handle) {
1044 if (db_init() < 0) {
1049 do_upgrade_db_schema();
1053 int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *appid)
1057 begin_transaction();
1058 ret = do_uninstall(appid);
1060 rollback_transaction();
1063 commit_transaction();
1069 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *_appid)
1071 xmlNodePtr node = NULL;
1079 DbgPrint("Package manager doesn't support the docPtr (%s)\n", _appid);
1083 root = xmlDocGetRootElement(docPtr);
1085 ErrPrint("Invalid node ptr\n");
1089 for (root = root->children; root; root = root->next) {
1090 if (!xmlStrcasecmp(root->name, (const xmlChar *)"shortcut-list")) {
1096 ErrPrint("Root has no shortcut-list\n");
1100 DbgPrint("AppID: %s\n", _appid);
1101 root = root->children;
1102 for (node = root; node; node = node->next) {
1103 if (node->type == XML_ELEMENT_NODE) {
1104 DbgPrint("Element %s\n", node->name);
1107 if (xmlStrcasecmp(node->name, (const xmlChar *)"shortcut")) {
1111 if (!xmlHasProp(node, (xmlChar *)"extra_data")
1112 || !xmlHasProp(node, (xmlChar *)"extra_key")
1113 || !xmlHasProp(node, (xmlChar *)"appid"))
1115 DbgPrint("Invalid element %s\n", node->name);
1119 appid = xmlGetProp(node, (xmlChar *)"appid");
1120 key = xmlGetProp(node, (xmlChar *)"extra_key");
1121 data = xmlGetProp(node, (xmlChar *)"extra_data");
1123 DbgPrint("appid: %s\n", appid);
1124 DbgPrint("key: %s\n", key);
1125 DbgPrint("data: %s\n", data);
1127 id = db_get_id("", (char *)appid, (char *)key, (char *)data);
1129 ErrPrint("No records found\n");
1136 begin_transaction();
1137 if (db_remove_record("", (char *)appid, (char *)key, (char *)data) < 0) {
1138 ErrPrint("Failed to remove a record\n");
1139 rollback_transaction();
1146 if (db_remove_name(id) < 0) {
1147 ErrPrint("Failed to remove name records\n");
1148 rollback_transaction();
1154 commit_transaction();
1162 * if (node->children)
1163 * DbgPrint("Skip this node's children\n");
1170 int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *appid)
1174 if (!s_info.handle) {
1175 if (db_init() < 0) {
1180 do_upgrade_db_schema();
1182 begin_transaction();
1183 ret = do_uninstall(appid);
1185 ErrPrint("Failed to remove record: %s\n", appid);
1188 commit_transaction();
1192 int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *appid)
1198 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
1200 return do_install(docPtr, appid);
1203 int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *appid)
1207 if (!s_info.handle) {
1208 if (db_init() < 0) {
1213 do_upgrade_db_schema();
1215 begin_transaction();
1216 ret = do_uninstall(appid);
1218 ErrPrint("Failed to remove a record: %s\n", appid);
1221 commit_transaction();
1225 int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *appid)
1231 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
1234 return do_install(docPtr, appid);
1238 int main(int argc, char *argv[])
1244 ErrPRint("Invalid argument: %s XML_FILENAME\n", argv[0]);
1248 doc = xmlReadFile(argv[1], NULL, 0);
1250 ErrPrint("Failed to parse %s\n", argv[1]);
1254 root = xmlDocGetRootElement(doc);
1257 install_shortcut("", root);