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>
32 /* For multi-user support */
33 #include <tzplatform_config.h>
37 #if !defined(SECURE_LOGD)
38 #define SECURE_LOGD LOGD
41 #if !defined(SECURE_LOGE)
42 #define SECURE_LOGE LOGE
45 #if !defined(SECURE_LOGW)
46 #define SECURE_LOGW LOGW
50 #define DbgPrint(format, arg...) SECURE_LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
51 #define ErrPrint(format, arg...) SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
58 * +----+-------+-------+------+---------+-----------+------------+
59 * | id | pkgid | appid | Icon | Name | extra_key | extra_data |
60 * +----+-------+-------+------+---------+-----------+------------+
61 * | id | - | - | - | - | - | - |
62 * +----+-------+-------+------+---------+-----------+------------+
64 * +----+-------+------+------+------+
65 * | fk | pkgid | lang | name | icon |
66 * +----+-------+------+------+------+
67 * | id | - | - | | - |
68 * +----+-------+------+------+------+
71 #if !defined(LIBXML_TREE_ENABLED)
72 #error "LIBXML is not supporting the tree"
91 static inline int begin_transaction(void)
96 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
97 if (ret != SQLITE_OK) {
98 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
102 if (sqlite3_step(stmt) != SQLITE_DONE) {
103 DbgPrint("Failed to do update (%s)\n",
104 sqlite3_errmsg(s_info.handle));
105 sqlite3_finalize(stmt);
109 sqlite3_finalize(stmt);
113 static inline int rollback_transaction(void)
118 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
119 if (ret != SQLITE_OK) {
120 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
124 if (sqlite3_step(stmt) != SQLITE_DONE) {
125 DbgPrint("Failed to do update (%s)\n",
126 sqlite3_errmsg(s_info.handle));
127 sqlite3_finalize(stmt);
131 sqlite3_finalize(stmt);
135 static inline int commit_transaction(void)
140 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
141 if (ret != SQLITE_OK) {
142 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
146 if (sqlite3_step(stmt) != SQLITE_DONE) {
147 DbgPrint("Failed to do update (%s)\n",
148 sqlite3_errmsg(s_info.handle));
149 sqlite3_finalize(stmt);
153 sqlite3_finalize(stmt);
157 static void db_create_version(void)
159 static const char *ddl = "CREATE TABLE version (version INTEGER)";
162 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
163 ErrPrint("Failed to execute the DDL (%s)\n", err);
167 if (sqlite3_changes(s_info.handle) == 0) {
168 ErrPrint("No changes to DB\n");
172 static int set_version(int version)
174 static const char *dml = "INSERT INTO version (version) VALUES (?)";
178 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
179 if (ret != SQLITE_OK) {
180 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
184 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
185 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
190 ret = sqlite3_step(stmt);
191 if (ret != SQLITE_DONE) {
192 ErrPrint("Failed to execute the DML for version: %d\n", ret);
200 sqlite3_clear_bindings(stmt);
201 sqlite3_finalize(stmt);
205 static int update_version(int version)
207 static const char *dml = "UPDATE version SET version = ?";
211 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
212 if (ret != SQLITE_OK) {
213 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
217 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
218 ErrPrint("Failed to bind a version: %s\n", sqlite3_errmsg(s_info.handle));
223 ret = sqlite3_step(stmt);
224 if (ret != SQLITE_DONE) {
225 ErrPrint("Failed to execute DML: %d\n", ret);
233 sqlite3_clear_bindings(stmt);
234 sqlite3_finalize(stmt);
238 static int get_version(void)
240 static const char *dml = "SELECT version FROM version";
244 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
245 if (ret != SQLITE_OK) {
249 if (sqlite3_step(stmt) != SQLITE_ROW) {
252 ret = sqlite3_column_int(stmt, 0);
256 sqlite3_clear_bindings(stmt);
257 sqlite3_finalize(stmt);
261 static void db_create_table(void)
264 static const char *ddl =
265 "CREATE TABLE shortcut_service ("
266 "id INTEGER PRIMARY KEY AUTOINCREMENT, "
274 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
275 ErrPrint("Failed to execute the DDL (%s)\n", err);
279 if (sqlite3_changes(s_info.handle) == 0) {
280 ErrPrint("No changes to DB\n");
283 ddl = "CREATE TABLE shortcut_name (id INTEGER, pkgid TEXT, lang TEXT, name TEXT, icon TEXT)";
284 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
285 ErrPrint("Failed to execute the DDL (%s)\n", err);
289 if (sqlite3_changes(s_info.handle) == 0) {
290 ErrPrint("No changes to DB\n");
296 static void alter_shortcut_icon(void)
299 static const char *ddl = "ALTER TABLE shortcut_name ADD icon TEXT";
301 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
302 ErrPrint("Failed to execute the DDL (%s)\n", err);
306 if (sqlite3_changes(s_info.handle) == 0) {
307 ErrPrint("No changes to DB\n");
311 static void alter_shortcut_name(void)
314 static const char *ddl = "ALTER TABLE shortcut_name ADD pkgid TEXT";
316 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
317 ErrPrint("Failed to execute the DDL (%s)\n", err);
321 if (sqlite3_changes(s_info.handle) == 0) {
322 ErrPrint("No changes to DB\n");
326 static void alter_shortcut_service(void)
329 static const char *ddl = "ALTER TABLE shortcut_service ADD pkgid TEXT";
331 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
332 ErrPrint("Failed to execute the DDL (%s)\n", err);
336 if (sqlite3_changes(s_info.handle) == 0) {
337 ErrPrint("No changes to DB\n");
341 static int db_remove_by_pkgid(const char *pkgid)
343 static const char *dml = "DELETE FROM shortcut_service WHERE pkgid = ?";
348 ErrPrint("Invalid argument\n");
352 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
353 if (ret != SQLITE_OK) {
354 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
359 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
360 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
365 if (sqlite3_step(stmt) != SQLITE_DONE) {
367 ErrPrint("Failed to execute the DML for %s\n", pkgid);
369 if (sqlite3_changes(s_info.handle) == 0) {
370 DbgPrint("No changed\n");
376 sqlite3_clear_bindings(stmt);
377 sqlite3_finalize(stmt);
381 static void do_upgrade_db_schema(void)
385 version = get_version();
390 /* Need to create version table */
392 if (set_version(1) < 0) {
393 ErrPrint("Failed to set version\n");
395 /* Need to set version */
396 alter_shortcut_name();
397 alter_shortcut_service();
399 alter_shortcut_icon();
400 if (update_version(2) < 0) {
401 ErrPrint("Failed to update version\n");
406 /* Need to update version */
407 DbgPrint("Old version: %d\n", version);
408 if (update_version(2) < 0) {
409 ErrPrint("Failed to update version\n");
412 alter_shortcut_name();
413 alter_shortcut_service();
415 alter_shortcut_icon();
420 static int db_remove_record(const char *pkgid, const char *appid, const char *key, const char *data)
422 static const char *dml = "DELETE FROM shortcut_service WHERE appid = ? AND extra_key = ? AND extra_data = ? AND pkgid = ?";
426 if (!appid || !key || !data) {
427 ErrPrint("Invalid argument\n");
431 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
432 if (ret != SQLITE_OK) {
433 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
438 if (sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
439 ErrPrint("Failed to bind a appid(%s)\n", sqlite3_errmsg(s_info.handle));
443 if (sqlite3_bind_text(stmt, 2, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
444 ErrPrint("Failed to bind a key(%s)\n", sqlite3_errmsg(s_info.handle));
448 if (sqlite3_bind_text(stmt, 3, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
449 ErrPrint("Failed to bind a data(%s)\n", sqlite3_errmsg(s_info.handle));
453 if (sqlite3_bind_text(stmt, 4, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
454 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
459 if (sqlite3_step(stmt) != SQLITE_DONE) {
461 ErrPrint("Failed to execute the DML for %s - %s(%s)\n", appid, key, data);
464 if (sqlite3_changes(s_info.handle) == 0) {
465 DbgPrint("No changes\n");
470 sqlite3_clear_bindings(stmt);
471 sqlite3_finalize(stmt);
475 static int db_remove_name_by_pkgid(const char *pkgid)
477 static const char *dml = "DELETE FROM shortcut_name WHERE pkgid = ?";
482 ErrPrint("Invalid id\n");
486 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
487 if (ret != SQLITE_OK) {
488 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
492 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
493 ErrPrint("Failed to bind pkgid(%s)\n", pkgid);
498 if (sqlite3_step(stmt) != SQLITE_DONE) {
500 ErrPrint("Failed to execute the DML for %s\n", pkgid);
504 if (sqlite3_changes(s_info.handle) == 0) {
505 DbgPrint("No chnages\n");
510 sqlite3_clear_bindings(stmt);
511 sqlite3_finalize(stmt);
515 static int db_remove_name(int id)
517 static const char *dml = "DELETE FROM shortcut_name WHERE id = ?";
522 ErrPrint("Inavlid id\n");
526 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
527 if (ret != SQLITE_OK) {
528 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
532 if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
533 ErrPrint("Failed to bind id(%d)\n", id);
539 if (sqlite3_step(stmt) != SQLITE_DONE) {
541 ErrPrint("Failed to execute the DML for %d\n", id);
545 if (sqlite3_changes(s_info.handle) == 0) {
546 DbgPrint("No changes\n");
551 sqlite3_clear_bindings(stmt);
552 sqlite3_finalize(stmt);
556 static int db_insert_record(const char *pkgid, const char *appid, const char *icon, const char *name, const char *key, const char *data)
558 static const char *dml = "INSERT INTO shortcut_service (pkgid, appid, icon, name, extra_key, extra_data) VALUES (?, ?, ?, ?, ?, ?)";
563 ErrPrint("Failed to get pkgid\n");
568 ErrPrint("Failed to get appid\n");
573 ErrPrint("Failed to get name\n");
578 ErrPrint("Failed to get key\n");
583 ErrPrint("Faield to get key\n");
587 icon = icon ? icon : "";
589 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
590 if (ret != SQLITE_OK) {
591 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
596 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
597 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
601 if (sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
602 ErrPrint("Failed to bind a appid(%s)\n", sqlite3_errmsg(s_info.handle));
606 if (sqlite3_bind_text(stmt, 3, icon, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
607 ErrPrint("Failed to bind a icon(%s)\n", sqlite3_errmsg(s_info.handle));
611 if (sqlite3_bind_text(stmt, 4, name, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
612 ErrPrint("Failed to bind a name(%s)\n", sqlite3_errmsg(s_info.handle));
616 if (sqlite3_bind_text(stmt, 5, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
617 ErrPrint("Failed to bind a service(%s)\n", sqlite3_errmsg(s_info.handle));
621 if (sqlite3_bind_text(stmt, 6, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
622 ErrPrint("Failed to bind a service(%s)\n", sqlite3_errmsg(s_info.handle));
627 if (sqlite3_step(stmt) != SQLITE_DONE) {
628 ErrPrint("Failed to execute the DML for %s - %s\n", appid, name);
634 sqlite3_clear_bindings(stmt);
635 sqlite3_finalize(stmt);
639 static int db_insert_name(int id, const char *pkgid, const char *lang, const char *name, const char *icon)
641 static const char *dml = "INSERT INTO shortcut_name (id, pkgid, lang, name, icon) VALUES (?, ?, ?, ?, ?)";
645 if (id < 0 || !lang) {
646 ErrPrint("Invalid parameters\n");
658 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
659 if (ret != SQLITE_OK) {
660 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
664 if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
665 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
670 if (sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
671 ErrPrint("Failed to bind a pkgid(%s)\n", sqlite3_errmsg(s_info.handle));
676 if (sqlite3_bind_text(stmt, 3, lang, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
677 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
682 if (sqlite3_bind_text(stmt, 4, name, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
683 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
688 if (sqlite3_bind_text(stmt, 5, icon, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
689 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
695 if (sqlite3_step(stmt) != SQLITE_DONE) {
696 ErrPrint("Failed to execute the DML for %d %s %s\n", id, lang, name);
702 sqlite3_clear_bindings(stmt);
703 sqlite3_finalize(stmt);
707 static int db_get_id(const char *pkgid, const char *appid, const char *key, const char *data)
709 static const char *dml = "SELECT id FROM shortcut_service WHERE pkgid = ? AND appid = ? AND extra_key = ? AND extra_data = ?";
713 if (!appid || !key || !data) {
714 ErrPrint("Invalid argument\n");
718 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
719 if (ret != SQLITE_OK) {
720 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
725 if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
726 ErrPrint("Failed to bind a pkgid(%s) - %s\n", pkgid, sqlite3_errmsg(s_info.handle));
730 if (sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
731 ErrPrint("Failed to bind a appid(%s) - %s\n", appid, sqlite3_errmsg(s_info.handle));
735 if (sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
736 ErrPrint("Failed to bind a key(%s) - %s\n", key, sqlite3_errmsg(s_info.handle));
740 if (sqlite3_bind_text(stmt, 4, data, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
741 ErrPrint("Failed to bind a data(%s) - %s\n", data, sqlite3_errmsg(s_info.handle));
745 if (sqlite3_step(stmt) != SQLITE_ROW) {
746 ErrPrint("Failed to execute the DML for %s - %s, %s\n", appid, key, data);
751 ret = sqlite3_column_int(stmt, 0);
755 sqlite3_clear_bindings(stmt);
756 sqlite3_finalize(stmt);
760 static int db_init(void)
765 s_info.dbfile = tzplatform_mkpath(TZ_SYS_DB, ".shortcut_service.db");
766 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
767 if (ret != SQLITE_OK) {
768 ErrPrint("Failed to open a DB\n");
772 if (lstat(s_info.dbfile, &stat) < 0) {
773 ErrPrint("%s\n", strerror(errno));
774 db_util_close(s_info.handle);
775 s_info.handle = NULL;
779 if (!S_ISREG(stat.st_mode)) {
780 ErrPrint("Invalid file\n");
781 db_util_close(s_info.handle);
782 s_info.handle = NULL;
793 static int db_fini(void)
795 if (!s_info.handle) {
799 db_util_close(s_info.handle);
800 s_info.handle = NULL;
805 static int do_uninstall(const char *appid)
809 ret = db_remove_by_pkgid(appid);
811 ErrPrint("Failed to remove a record: %s\n", appid);
815 ret = db_remove_name_by_pkgid(appid);
817 ErrPrint("Failed to remove name records: %s\n", appid);
824 static inline struct i18n_name *find_i18n_name(struct dlist *i18n_list, xmlChar *lang)
827 struct i18n_name *i18n;
829 dlist_foreach(i18n_list, l, i18n) {
830 if (!xmlStrcasecmp(i18n->lang, lang)) {
838 static inline struct i18n_name *create_i18n_name(xmlChar *lang, xmlChar *name, xmlChar *icon)
840 struct i18n_name *i18n;
842 i18n = malloc(sizeof(*i18n));
844 ErrPrint("Heap: %s\n", strerror(errno));
855 static inline void destroy_i18n_name(struct i18n_name *i18n)
863 static int do_install(xmlDocPtr docPtr, const char *appid)
865 xmlNodePtr node = NULL;
866 xmlNodePtr child = NULL;
872 xmlChar *shortcut_appid;
874 struct i18n_name *i18n;
875 struct dlist *i18n_list = NULL;
880 root = xmlDocGetRootElement(docPtr);
882 ErrPrint("Invalid node ptr\n");
886 for (root = root->children; root; root = root->next) {
887 if (!xmlStrcasecmp(root->name, (const xmlChar *)"shortcut-list")) {
893 ErrPrint("Root has no children\n");
897 DbgPrint("AppID: %s\n", appid);
899 root = root->children; /* Jump to children node */
900 for (node = root; node; node = node->next) {
901 if (node->type == XML_ELEMENT_NODE) {
902 DbgPrint("Element %s\n", node->name);
905 if (xmlStrcasecmp(node->name, (const xmlChar *)"shortcut")) {
909 if (!xmlHasProp(node, (xmlChar *)"extra_key") || !xmlHasProp(node, (xmlChar *)"extra_data")) {
910 DbgPrint("Invalid element %s\n", node->name);
914 key = xmlGetProp(node, (xmlChar *)"extra_key");
915 data = xmlGetProp(node, (xmlChar *)"extra_data");
916 shortcut_appid = xmlGetProp(node, (xmlChar *)"appid");
920 for (child = node->children; child; child = child->next) {
921 if (!xmlStrcasecmp(child->name, (const xmlChar *)"icon")) {
922 lang = xmlNodeGetLang(child);
925 DbgPrint("Default icon is duplicated\n");
927 icon = xmlNodeGetContent(child);
928 DbgPrint("Default icon is %s\n", icon);
934 i18n = find_i18n_name(i18n_list, lang);
939 DbgPrint("%s is duplicated\n", i18n->icon);
943 i18n->icon = xmlNodeGetContent(child);
945 i18n = create_i18n_name(lang, NULL, xmlNodeGetContent(child));
947 ErrPrint("Failed to create a new i18n_name\n");
950 i18n_list = dlist_append(i18n_list, i18n);
956 if (!xmlStrcasecmp(child->name, (const xmlChar *)"label")) {
957 lang = xmlNodeGetLang(child);
960 DbgPrint("Default name is duplicated\n");
962 name = xmlNodeGetContent(child);
963 DbgPrint("Default name is %s\n", name);
969 i18n = find_i18n_name(i18n_list, lang);
974 DbgPrint("%s is duplicated\n", i18n->name);
978 i18n->name = xmlNodeGetContent(child);
980 i18n = create_i18n_name(lang, xmlNodeGetContent(child), NULL);
982 ErrPrint("Failed to create a new i18n_name\n");
985 i18n_list = dlist_append(i18n_list, i18n);
992 DbgPrint("appid: %s\n", appid);
993 DbgPrint("shortcut appid: %s\n", shortcut_appid);
994 DbgPrint("key: %s\n", key);
995 DbgPrint("data: %s\n", data);
996 DbgPrint("icon: %s\n", icon);
997 DbgPrint("Default name: %s\n", name);
999 if (!shortcut_appid) {
1000 shortcut_appid = xmlStrdup((xmlChar *)appid);
1001 DbgPrint("Use the default appid\n");
1004 begin_transaction();
1005 if (db_insert_record(appid, (char *)shortcut_appid, (char *)icon, (char *)name, (char *)key, (char *)data) < 0) {
1006 ErrPrint("Failed to insert a new record\n");
1007 rollback_transaction();
1009 dlist_foreach_safe(i18n_list, l, n, i18n) {
1010 i18n_list = dlist_remove(i18n_list, l);
1011 destroy_i18n_name(i18n);
1014 id = db_get_id((char *)appid, (char *)shortcut_appid, (char *)key, (char *)data);
1016 ErrPrint("Failed to insert a new record\n");
1017 rollback_transaction();
1019 dlist_foreach_safe(i18n_list, l, n, i18n) {
1020 i18n_list = dlist_remove(i18n_list, l);
1021 destroy_i18n_name(i18n);
1024 dlist_foreach_safe(i18n_list, l, n, i18n) {
1025 i18n_list = dlist_remove(i18n_list, l);
1026 if (db_insert_name(id, appid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon) < 0) {
1027 ErrPrint("Failed to add i18n name: %s(%s)\n", i18n->name, i18n->lang);
1029 destroy_i18n_name(i18n);
1031 commit_transaction();
1039 xmlFree(shortcut_appid);
1045 int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *appid)
1047 if (!s_info.handle) {
1048 if (db_init() < 0) {
1053 do_upgrade_db_schema();
1057 int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *appid)
1061 begin_transaction();
1062 ret = do_uninstall(appid);
1064 rollback_transaction();
1067 commit_transaction();
1073 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *_appid)
1075 xmlNodePtr node = NULL;
1083 DbgPrint("Package manager doesn't support the docPtr (%s)\n", _appid);
1087 root = xmlDocGetRootElement(docPtr);
1089 ErrPrint("Invalid node ptr\n");
1093 for (root = root->children; root; root = root->next) {
1094 if (!xmlStrcasecmp(root->name, (const xmlChar *)"shortcut-list")) {
1100 ErrPrint("Root has no shortcut-list\n");
1104 DbgPrint("AppID: %s\n", _appid);
1105 root = root->children;
1106 for (node = root; node; node = node->next) {
1107 if (node->type == XML_ELEMENT_NODE) {
1108 DbgPrint("Element %s\n", node->name);
1111 if (xmlStrcasecmp(node->name, (const xmlChar *)"shortcut")) {
1115 if (!xmlHasProp(node, (xmlChar *)"extra_data")
1116 || !xmlHasProp(node, (xmlChar *)"extra_key")
1117 || !xmlHasProp(node, (xmlChar *)"appid"))
1119 DbgPrint("Invalid element %s\n", node->name);
1123 appid = xmlGetProp(node, (xmlChar *)"appid");
1124 key = xmlGetProp(node, (xmlChar *)"extra_key");
1125 data = xmlGetProp(node, (xmlChar *)"extra_data");
1127 DbgPrint("appid: %s\n", appid);
1128 DbgPrint("key: %s\n", key);
1129 DbgPrint("data: %s\n", data);
1131 id = db_get_id("", (char *)appid, (char *)key, (char *)data);
1133 ErrPrint("No records found\n");
1140 begin_transaction();
1141 if (db_remove_record("", (char *)appid, (char *)key, (char *)data) < 0) {
1142 ErrPrint("Failed to remove a record\n");
1143 rollback_transaction();
1150 if (db_remove_name(id) < 0) {
1151 ErrPrint("Failed to remove name records\n");
1152 rollback_transaction();
1158 commit_transaction();
1166 * if (node->children)
1167 * DbgPrint("Skip this node's children\n");
1174 int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *appid)
1178 if (!s_info.handle) {
1179 if (db_init() < 0) {
1184 do_upgrade_db_schema();
1186 begin_transaction();
1187 ret = do_uninstall(appid);
1189 ErrPrint("Failed to remove record: %s\n", appid);
1192 commit_transaction();
1196 int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *appid)
1202 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
1204 return do_install(docPtr, appid);
1207 int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *appid)
1211 if (!s_info.handle) {
1212 if (db_init() < 0) {
1217 do_upgrade_db_schema();
1219 begin_transaction();
1220 ret = do_uninstall(appid);
1222 ErrPrint("Failed to remove a record: %s\n", appid);
1225 commit_transaction();
1229 int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *appid)
1235 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
1238 return do_install(docPtr, appid);
1242 int main(int argc, char *argv[])
1248 ErrPRint("Invalid argument: %s XML_FILENAME\n", argv[0]);
1252 doc = xmlReadFile(argv[1], NULL, 0);
1254 ErrPrint("Failed to parse %s\n", argv[1]);
1258 root = xmlDocGetRootElement(doc);
1261 install_shortcut("", root);