2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
19 #include <sys/types.h>
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
31 #include <livebox-service.h>
36 #define DbgPrint(format, arg...) SECURE_LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
37 #define ErrPrint(format, arg...) SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
38 #define ErrPrintWithConsole(format, arg...) do { fprintf(stderr, "[%s/%s:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); } while (0)
42 #define DEFAULT_CATEGORY "http://tizen.org/category/default"
54 * CREATE TABLE version ( version INTEGER )
58 * +-------+-------+-------+-------+-------------------+
59 * | appid | pkgid | uiapp | prime | categ(from ver 2) |
60 * +-------+-------+-------+-------+-------------------+
61 * | - | - | - | - | - |
62 * +-------+-------+-------+-------+-------------------+
63 * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )
67 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
68 * | pkgid | network | abi | secured | box_type | box_src | box_group | pd_type | pd_src | pd_group | libexec | timeout | period | script | pinup |
69 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
70 * | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
71 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
72 * CREATE TABLE provider ( pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, abi TEXT, secured INTEGER, box_type INTEGER, box_src TEXT, box_group TEXT, pd_type TEXT, pd_src TEXT, pd_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid))
74 * = box_type = { text | buffer | script | image }
75 * = pd_type = { text | buffer | script }
76 * = network = { 1 | 0 }
77 * = secured = { 1 | 0 }
81 * +-------+------+---------+-------------+---------+---------+-----------+-------+
82 * | pkgid | Icon | Name | auto_launch | pd_size | content | nodisplay | setup |
83 * +-------+------+---------+-------------+---------+---------+-----------+-------+
84 * | - | - | - | - | - | - | - | - |
85 * +-------+------+---------+-------------+---------+---------+-----------+-------+
86 * CREATE TABLE client ( pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, auto_launch TEXT, pd_size TEXT, content TEXT, nodisplay INTEGER, setup TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
88 * = auto_launch = UI-APPID
89 * = pd_size = WIDTHxHEIGHT
93 * +-------+------+------+------+
94 * | fk | lang | name | icon |
95 * +-------+------+------+------+
96 * | pkgid | - | - | - |
97 * +-------+------+------+------+
98 * CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
102 * +-------+-----------+---------+--------------+------------+-------------------------+
103 * | pkgid | size_type | preview | touch_effect | need_frame | mouse_event(from ver 3) |
104 * +-------+-----------+---------+--------------+------------+-------------------------+
105 * | - | - | - | - | - | - |
106 * +-------+-----------+---------+--------------+------------+-------------------------+
107 * CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, INTEGER, touch_effect INTEGER, need_frame INTEGER, mouse_event INTEGER, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
109 * = box_size_list = { WIDTHxHEIGHT; WIDTHxHEIGHT; ... }
112 * +----+---------+----------+-------+
113 * | id | cluster | category | pkgid |
114 * +----+---------+----------+-------+
116 * +----+---------+----------+-------|
117 * CREATE TABLE groupinfo ( id INTEGER PRIMARY KEY AUTOINCREMENT, cluster TEXT NOT NULL, category TEXT NOT NULL, appid TEXT NOT NULL, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ))
120 * +-------+----+----------+-----------+
121 * | pkgid | id | ctx_item | option_id |
122 * +-------+----+----------+-----------+
123 * CREATE TABLE groupmap ( option_id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, pkgid TEXT NOT NULL, ctx_item TEXT NOT NULL, FOREIGN KEY(id) REFERENCES groupinfo(id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
127 * +-------+-----------+-----+-------+
128 * | pkgid | option_id | key | value |
129 * +-------+-----------+-----+-------+
130 * CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, FOREIGN KEY(option_id) REFERENCES groupmap(option_id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
133 #if !defined(LIBXML_TREE_ENABLED)
134 #error "LIBXML is not supporting the tree"
141 #define LOG_TAG "PKGMGR_LIVEBOX"
170 xmlChar *auto_launch;
172 xmlChar *name; /* Default name */
173 xmlChar *icon; /* Default icon */
174 xmlChar *libexec; /* Path of the SO file */
175 xmlChar *timeout; /* INTEGER, timeout */
176 xmlChar *period; /* DOUBLE, update period */
177 xmlChar *script; /* Script engine */
178 xmlChar *content; /* Content information */
180 xmlChar *uiapp; /* UI App Id */
181 xmlChar *category; /* Category of this box */
183 int pinup; /* Is this support the pinup feature? */
184 int primary; /* Is this primary livebox? */
187 int default_mouse_event; /* Mouse event processing option for livebox */
188 int default_touch_effect;
189 int default_need_frame;
191 enum lb_type lb_type;
194 int size_list; /* 1x1, 2x1, 2x2, 4x1, 4x2, 4x3, 4x4 */
196 xmlChar *preview[NR_OF_SIZE_LIST];
197 int touch_effect[NR_OF_SIZE_LIST]; /* Touch effect of a livebox */
198 int need_frame[NR_OF_SIZE_LIST]; /* Box needs frame which should be cared by viewer */
199 int mouse_event[NR_OF_SIZE_LIST];
201 enum pd_type pd_type;
204 xmlChar *pd_size; /* Default PD size */
206 struct dlist *i18n_list;
207 struct dlist *group_list;
214 struct dlist *option_list;
226 .dbfile = "/opt/dbspace/.livebox.db",
230 static inline int begin_transaction(void)
235 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
237 if (ret != SQLITE_OK) {
238 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
242 if (sqlite3_step(stmt) != SQLITE_DONE) {
243 DbgPrint("Failed to do update (%s)\n",
244 sqlite3_errmsg(s_info.handle));
245 sqlite3_finalize(stmt);
249 sqlite3_finalize(stmt);
253 static inline int rollback_transaction(void)
258 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
259 if (ret != SQLITE_OK) {
260 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
264 if (sqlite3_step(stmt) != SQLITE_DONE) {
265 DbgPrint("Failed to do update (%s)\n",
266 sqlite3_errmsg(s_info.handle));
267 sqlite3_finalize(stmt);
271 sqlite3_finalize(stmt);
275 static inline int commit_transaction(void)
280 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
281 if (ret != SQLITE_OK) {
282 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
286 if (sqlite3_step(stmt) != SQLITE_DONE) {
287 DbgPrint("Failed to do update (%s)\n",
288 sqlite3_errmsg(s_info.handle));
289 sqlite3_finalize(stmt);
293 sqlite3_finalize(stmt);
297 static void db_create_version(void)
299 static const char *ddl = "CREATE TABLE version (version INTEGER)";
302 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
303 ErrPrint("Failed to execute the DDL (%s)\n", err);
307 if (sqlite3_changes(s_info.handle) == 0) {
308 ErrPrint("No changes to DB\n");
312 static int set_version(int version)
314 static const char *dml = "INSERT INTO version (version) VALUES (?)";
318 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
319 if (ret != SQLITE_OK) {
320 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
324 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
325 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
330 ret = sqlite3_step(stmt);
331 if (ret != SQLITE_DONE) {
332 ErrPrint("Failed to execute the DML for version: %d\n", ret);
340 sqlite3_clear_bindings(stmt);
341 sqlite3_finalize(stmt);
345 static int update_version(int version)
347 static const char *dml = "UPDATE version SET version = ?";
351 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
352 if (ret != SQLITE_OK) {
353 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
357 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
358 ErrPrint("Failed to bind a version: %s\n", sqlite3_errmsg(s_info.handle));
363 ret = sqlite3_step(stmt);
364 if (ret != SQLITE_DONE) {
365 ErrPrint("Failed to execute DML: %d\n", ret);
373 sqlite3_clear_bindings(stmt);
374 sqlite3_finalize(stmt);
378 static int get_version(void)
380 static const char *dml = "SELECT version FROM version";
384 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
385 if (ret != SQLITE_OK) {
389 if (sqlite3_step(stmt) != SQLITE_ROW) {
392 ret = sqlite3_column_int(stmt, 0);
396 sqlite3_clear_bindings(stmt);
397 sqlite3_finalize(stmt);
403 * From version 1 to 2
405 static void upgrade_pkgmap_for_category(void)
408 static const char *ddl;
410 ddl = "ALTER TABLE pkgmap ADD COLUMN category TEXT DEFAULT \"" DEFAULT_CATEGORY "\"";
411 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
412 ErrPrint("Failed to execute the DDL (%s)\n", err);
416 if (sqlite3_changes(s_info.handle) == 0) {
417 ErrPrint("No changes to DB\n");
425 * From version 2 to 3
426 * mouse_event is deleted from client table
427 * mouse_event is added to box_size table
429 * Every size has their own configuration for mouse_event flag.
431 static void upgrade_to_version_3(void)
434 static const char *ddl;
435 static const char *dml;
436 sqlite3_stmt *select_stmt;
441 * Create a new column for mouse_event to box_size table.
443 ddl = "ALTER TABLE box_size ADD COLUMN mouse_event INTEGER DEFAULT 0";
444 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
445 ErrPrint("Failed to execute the DDL (%s)\n", err);
449 if (sqlite3_changes(s_info.handle) == 0) {
450 ErrPrint("No changes to DB\n");
455 * Copy mouse_event values from the client to the box_size table.
457 dml = "SELECT pkgid, mouse_event FROM client";
458 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &select_stmt, NULL);
459 if (ret == SQLITE_OK) {
460 sqlite3_stmt *update_stmt;
462 dml = "UPDATE box_size SET mouse_event = ? WHERE pkgid = ?";
463 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &update_stmt, NULL);
464 if (ret == SQLITE_OK) {
468 while (sqlite3_step(select_stmt) == SQLITE_ROW) {
469 pkgid = (const char *)sqlite3_column_text(select_stmt, 0);
471 ErrPrint("Package Id is not valid\n");
475 mouse_event = sqlite3_column_int(select_stmt, 1);
477 ret = sqlite3_bind_int(update_stmt, 1, mouse_event);
478 if (ret != SQLITE_OK) {
479 ErrPrint("Failed to bind mouse_event [%s], [%d]\n", pkgid, mouse_event);
480 sqlite3_reset(update_stmt);
481 sqlite3_clear_bindings(update_stmt);
485 ret = sqlite3_bind_text(update_stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
486 if (ret != SQLITE_OK) {
487 ErrPrint("Failed to bind pkgid [%s], [%d]\n", pkgid, mouse_event);
488 sqlite3_reset(update_stmt);
489 sqlite3_clear_bindings(update_stmt);
493 ret = sqlite3_step(update_stmt);
494 if (ret != SQLITE_DONE) {
495 ErrPrint("Failed to execute DML: %d\n", ret);
496 sqlite3_reset(update_stmt);
497 sqlite3_clear_bindings(update_stmt);
501 sqlite3_reset(update_stmt);
502 sqlite3_clear_bindings(update_stmt);
505 sqlite3_finalize(update_stmt);
507 ErrPrint("Failed to execute DML\n");
510 sqlite3_reset(select_stmt);
511 sqlite3_clear_bindings(select_stmt);
512 sqlite3_finalize(select_stmt);
514 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
519 * Drop a column from the client table
521 ddl = "ALTER TABLE client DROP COLUMN mouse_event";
522 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
523 ErrPrint("Failed to execute the DDL (%s)\n", err);
527 if (sqlite3_changes(s_info.handle) == 0) {
528 ErrPrint("No changes to DB\n");
534 static void do_upgrade_db_schema(void)
538 version = get_version();
543 /* Need to create version table */
545 if (set_version(CUR_VER) < 0) {
546 ErrPrint("Failed to set version\n");
548 /* Need to set version */
550 upgrade_pkgmap_for_category();
552 upgrade_to_version_3();
554 /* Need to update version */
555 DbgPrint("Old version: %d\n", version);
556 if (update_version(CUR_VER) < 0) {
557 ErrPrint("Failed to update version\n");
564 static inline int db_create_pkgmap(void)
567 static const char *ddl;
569 ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )";
570 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
571 ErrPrint("Failed to execute the DDL (%s)\n", err);
575 if (sqlite3_changes(s_info.handle) == 0) {
576 ErrPrint("No changes to DB\n");
582 static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const char *uiappid, int primary, const char *category)
585 static const char *dml;
588 dml = "INSERT INTO pkgmap ( appid, pkgid, uiapp, prime, category ) VALUES (? ,?, ?, ?, ?)";
589 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
590 if (ret != SQLITE_OK) {
591 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
595 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
596 if (ret != SQLITE_OK) {
597 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
602 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
603 if (ret != SQLITE_OK) {
604 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
609 ret = sqlite3_bind_text(stmt, 3, uiappid, -1, SQLITE_TRANSIENT);
610 if (ret != SQLITE_OK) {
611 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
616 ret = sqlite3_bind_int(stmt, 4, primary);
617 if (ret != SQLITE_OK) {
618 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
623 ret = sqlite3_bind_text(stmt, 5, category, -1, SQLITE_TRANSIENT);
624 if (ret != SQLITE_OK) {
625 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
631 if (sqlite3_step(stmt) != SQLITE_DONE) {
632 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
638 sqlite3_clear_bindings(stmt);
639 sqlite3_finalize(stmt);
643 static inline int db_remove_pkgmap(const char *pkgid)
646 static const char *dml;
649 dml = "DELETE FROM pkgmap WHERE pkgid = ?";
650 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
651 if (ret != SQLITE_OK) {
652 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
656 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
657 if (ret != SQLITE_OK) {
658 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
664 if (sqlite3_step(stmt) != SQLITE_DONE) {
665 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
671 sqlite3_clear_bindings(stmt);
672 sqlite3_finalize(stmt);
676 static inline int db_create_provider(void)
679 static const char *ddl;
681 ddl = "CREATE TABLE provider (" \
682 "pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, " \
683 "abi TEXT, secured INTEGER, box_type INTEGER, " \
684 "box_src TEXT, box_group TEXT, pd_type INTEGER, " \
685 "pd_src TEXT, pd_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, "\
686 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
688 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
689 ErrPrint("Failed to execute the DDL (%s)\n", err);
693 if (sqlite3_changes(s_info.handle) == 0) {
694 ErrPrint("No changes to DB\n");
700 static inline int db_remove_provider(const char *pkgid)
702 static const char *dml;
706 dml = "DELETE FROM provider WHERE pkgid = ?";
707 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
708 if (ret != SQLITE_OK) {
709 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
713 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
714 if (ret != SQLITE_OK) {
715 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
721 if (sqlite3_step(stmt) != SQLITE_DONE) {
722 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
728 sqlite3_clear_bindings(stmt);
729 sqlite3_finalize(stmt);
732 static int db_insert_provider(struct livebox *livebox)
734 static const char *dml;
737 char *abi = (char *)livebox->abi;
738 char *box_src = (char *)livebox->lb_src;
739 char *box_group = (char *)livebox->lb_group;
740 char *pd_src = (char *)livebox->pd_src;
741 char *pd_group = (char *)livebox->pd_group;
742 char *libexec = (char *)livebox->libexec;
743 char *timeout = (char *)livebox->timeout;
744 char *period = (char *)livebox->period;
745 char *script = (char *)livebox->script;
763 dml = "INSERT INTO provider ( pkgid, network, abi, secured, box_type, box_src, box_group, pd_type, pd_src, pd_group, libexec, timeout, period, script, pinup ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
764 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
765 if (ret != SQLITE_OK) {
766 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
770 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
771 if (ret != SQLITE_OK) {
772 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
777 ret = sqlite3_bind_int(stmt, 2, livebox->network);
778 if (ret != SQLITE_OK) {
779 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
784 ret = sqlite3_bind_text(stmt, 3, abi, -1, SQLITE_TRANSIENT);
785 if (ret != SQLITE_OK) {
786 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
790 ret = sqlite3_bind_int(stmt, 4, livebox->secured);
791 if (ret != SQLITE_OK) {
792 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
797 ret = sqlite3_bind_int(stmt, 5, livebox->lb_type);
798 if (ret != SQLITE_OK) {
799 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
804 ret = sqlite3_bind_text(stmt, 6, box_src, -1, SQLITE_TRANSIENT);
805 if (ret != SQLITE_OK) {
806 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
811 ret = sqlite3_bind_text(stmt, 7, box_group, -1, SQLITE_TRANSIENT);
812 if (ret != SQLITE_OK) {
813 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
818 ret = sqlite3_bind_int(stmt, 8, livebox->pd_type);
819 if (ret != SQLITE_OK) {
820 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
825 ret = sqlite3_bind_text(stmt, 9, pd_src, -1, SQLITE_TRANSIENT);
826 if (ret != SQLITE_OK) {
827 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
832 ret = sqlite3_bind_text(stmt, 10, pd_group, -1, SQLITE_TRANSIENT);
833 if (ret != SQLITE_OK) {
834 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
839 ret = sqlite3_bind_text(stmt, 11, libexec, -1, SQLITE_TRANSIENT);
840 if (ret != SQLITE_OK) {
841 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
846 ret = sqlite3_bind_int(stmt, 12, atoi(timeout));
847 if (ret != SQLITE_OK) {
848 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
853 ret = sqlite3_bind_text(stmt, 13, period, -1, SQLITE_TRANSIENT);
854 if (ret != SQLITE_OK) {
855 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
860 ret = sqlite3_bind_text(stmt, 14, script, -1, SQLITE_TRANSIENT);
861 if (ret != SQLITE_OK) {
862 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
867 ret = sqlite3_bind_int(stmt, 15, livebox->pinup);
868 if (ret != SQLITE_OK) {
869 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
875 if (sqlite3_step(stmt) != SQLITE_DONE) {
876 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
882 sqlite3_clear_bindings(stmt);
883 sqlite3_finalize(stmt);
887 static inline int db_create_client(void)
890 static const char *ddl;
892 ddl = "CREATE TABLE client (" \
893 "pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, " \
894 "auto_launch TEXT, pd_size TEXT, content TEXT, nodisplay INTEGER, setup TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
895 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
896 ErrPrint("Failed to execute the DDL (%s)\n", err);
900 if (sqlite3_changes(s_info.handle) == 0) {
901 ErrPrint("No changes to DB\n");
907 static inline int db_insert_client(struct livebox *livebox)
909 static const char *dml;
913 dml = "INSERT INTO client ( pkgid, icon, name, auto_launch, pd_size, content, nodisplay, setup ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
914 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
915 if (ret != SQLITE_OK) {
916 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
920 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
921 if (ret != SQLITE_OK) {
922 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
927 ret = sqlite3_bind_text(stmt, 2, (char *)livebox->icon, -1, SQLITE_TRANSIENT);
928 if (ret != SQLITE_OK) {
929 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
934 ret = sqlite3_bind_text(stmt, 3, (char *)livebox->name, -1, SQLITE_TRANSIENT);
935 if (ret != SQLITE_OK) {
936 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
941 ret = sqlite3_bind_text(stmt, 4, (char *)livebox->auto_launch, -1, SQLITE_TRANSIENT);
942 if (ret != SQLITE_OK) {
943 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
948 ret = sqlite3_bind_text(stmt, 5, (char *)livebox->pd_size, -1, SQLITE_TRANSIENT);
949 if (ret != SQLITE_OK) {
950 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
955 ret = sqlite3_bind_text(stmt, 6, (char *)livebox->content, -1, SQLITE_TRANSIENT);
956 if (ret != SQLITE_OK) {
957 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
962 ret = sqlite3_bind_int(stmt, 7, livebox->nodisplay);
963 if (ret != SQLITE_OK) {
964 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
969 ret = sqlite3_bind_text(stmt, 8, (char *)livebox->setup, -1, SQLITE_TRANSIENT);
970 if (ret != SQLITE_OK) {
971 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
977 if (sqlite3_step(stmt) != SQLITE_DONE) {
978 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
984 sqlite3_clear_bindings(stmt);
985 sqlite3_finalize(stmt);
989 static inline int db_remove_client(const char *pkgid)
991 static const char *dml;
995 dml = "DELETE FROM client WHERE pkgid = ?";
996 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
997 if (ret != SQLITE_OK) {
998 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1002 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1003 if (ret != SQLITE_OK) {
1004 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1010 if (sqlite3_step(stmt) != SQLITE_DONE) {
1011 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1016 sqlite3_reset(stmt);
1017 sqlite3_clear_bindings(stmt);
1018 sqlite3_finalize(stmt);
1022 static inline int db_create_i18n(void)
1025 static const char *ddl;
1027 ddl = "CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, " \
1028 "icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1029 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1030 ErrPrint("Failed to execute the DDL (%s)\n", err);
1034 if (sqlite3_changes(s_info.handle) == 0) {
1035 ErrPrint("No changes to DB\n");
1041 static inline int db_insert_i18n(const char *pkgid, const char *lang, const char *name, const char *icon)
1043 static const char *dml;
1047 DbgPrint("%s - lang[%s] name[%s] icon[%s]\n", pkgid, lang, name, icon);
1048 dml = "INSERT INTO i18n ( pkgid, lang, name, icon ) VALUES (?, ?, ?, ?)";
1049 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1050 if (ret != SQLITE_OK) {
1051 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1055 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1056 if (ret != SQLITE_OK) {
1057 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1062 ret = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
1063 if (ret != SQLITE_OK) {
1064 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1069 ret = sqlite3_bind_text(stmt, 3, name, -1, SQLITE_TRANSIENT);
1070 if (ret != SQLITE_OK) {
1071 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1076 ret = sqlite3_bind_text(stmt, 4, icon, -1, SQLITE_TRANSIENT);
1077 if (ret != SQLITE_OK) {
1078 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1084 if (sqlite3_step(stmt) != SQLITE_DONE) {
1085 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1090 sqlite3_reset(stmt);
1091 sqlite3_clear_bindings(stmt);
1092 sqlite3_finalize(stmt);
1096 static inline int db_remove_i18n(const char *pkgid)
1098 static const char *dml;
1102 dml = "DELETE FROM i18n WHERE pkgid = ?";
1103 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1104 if (ret != SQLITE_OK) {
1105 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1109 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1110 if (ret != SQLITE_OK) {
1111 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1117 if (sqlite3_step(stmt) != SQLITE_DONE) {
1118 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1122 if (sqlite3_changes(s_info.handle) == 0) {
1123 DbgPrint("No changes\n");
1127 sqlite3_reset(stmt);
1128 sqlite3_clear_bindings(stmt);
1129 sqlite3_finalize(stmt);
1133 static inline int db_create_group(void)
1136 static const char *ddl;
1138 ddl = "CREATE TABLE groupinfo ( id INTEGER PRIMARY KEY AUTOINCREMENT, cluster TEXT NOT NULL, category TEXT NOT NULL, pkgid TEXT NOT NULL, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1139 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1140 ErrPrint("Failed to execute the DDL (%s)\n", err);
1144 if (sqlite3_changes(s_info.handle) == 0) {
1145 ErrPrint("No changes to DB\n");
1151 static inline int db_insert_group(const char *pkgid, const char *cluster, const char *category)
1153 static const char *dml;
1157 dml = "INSERT INTO groupinfo ( cluster, category, pkgid ) VALUES (?, ?, ?)";
1158 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1159 if (ret != SQLITE_OK) {
1160 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1164 ret = sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT);
1165 if (ret != SQLITE_OK) {
1166 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1171 ret = sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT);
1172 if (ret != SQLITE_OK) {
1173 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1178 ret = sqlite3_bind_text(stmt, 3, pkgid, -1, SQLITE_TRANSIENT);
1179 if (ret != SQLITE_OK) {
1180 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1186 if (sqlite3_step(stmt) != SQLITE_DONE) {
1187 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1192 sqlite3_reset(stmt);
1193 sqlite3_clear_bindings(stmt);
1194 sqlite3_finalize(stmt);
1198 static int db_get_group_id(const char *cluster, const char *category)
1200 static const char *dml = "SELECT id FROM groupinfo WHERE cluster = ? AND category = ?";
1204 if (!cluster || !category) {
1205 ErrPrint("Invalid argument\n");
1209 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1210 if (ret != SQLITE_OK) {
1211 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
1216 if (sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
1217 ErrPrint("Failed to bind a cluster(%s) - %s\n", cluster, sqlite3_errmsg(s_info.handle));
1221 if (sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
1222 ErrPrint("Failed to bind a category(%s) - %s\n", category, sqlite3_errmsg(s_info.handle));
1226 if (sqlite3_step(stmt) != SQLITE_ROW) {
1227 ErrPrint("Failed to execute the DML for %s - %s\n", cluster, category);
1231 ret = sqlite3_column_int(stmt, 0);
1234 sqlite3_reset(stmt);
1235 sqlite3_clear_bindings(stmt);
1236 sqlite3_finalize(stmt);
1240 static inline int db_remove_group(const char *pkgid)
1242 static const char *dml;
1246 dml = "DELETE FROM groupinfo WHERE pkgid = ?";
1247 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1248 if (ret != SQLITE_OK) {
1249 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1253 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1254 if (ret != SQLITE_OK) {
1255 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1261 if (sqlite3_step(stmt) != SQLITE_DONE) {
1262 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1266 if (sqlite3_changes(s_info.handle) == 0) {
1267 DbgPrint("No changes\n");
1271 sqlite3_reset(stmt);
1272 sqlite3_clear_bindings(stmt);
1273 sqlite3_finalize(stmt);
1277 static inline int db_create_groupmap(void)
1280 static const char *ddl;
1282 ddl = "CREATE TABLE groupmap (option_id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, pkgid TEXT NOT NULL, ctx_item TEXT NOT NULL, FOREIGN KEY(id) REFERENCES groupinfo(id), FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1283 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1284 ErrPrint("Failed to execute the DDL (%s)\n", err);
1288 if (sqlite3_changes(s_info.handle) == 0) {
1289 ErrPrint("No changes to DB\n");
1295 static inline int db_get_option_id(int id, const char *pkgid, const char *ctx_item)
1297 static const char *dml;
1301 dml = "SELECT option_id FROM groupmap WHERE id = ? AND pkgid = ? AND ctx_item = ?";
1302 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1303 if (ret != SQLITE_OK) {
1304 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1308 ret = sqlite3_bind_int(stmt, 1, id);
1309 if (ret != SQLITE_OK) {
1310 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1315 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1316 if (ret != SQLITE_OK) {
1317 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1322 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1323 if (ret != SQLITE_OK) {
1324 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1330 if (sqlite3_step(stmt) != SQLITE_ROW) {
1331 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1336 ret = sqlite3_column_int(stmt, 0);
1339 sqlite3_reset(stmt);
1340 sqlite3_clear_bindings(stmt);
1341 sqlite3_finalize(stmt);
1345 static inline int db_insert_groupmap(int id, const char *pkgid, const char *ctx_item)
1347 static const char *dml;
1351 DbgPrint("%d (%s) add to groupmap\n", id, pkgid);
1353 dml = "INSERT INTO groupmap ( id, pkgid, ctx_item ) VALUES (?, ?, ?)";
1354 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1355 if (ret != SQLITE_OK) {
1356 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1360 ret = sqlite3_bind_int(stmt, 1, id);
1361 if (ret != SQLITE_OK) {
1362 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1367 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1368 if (ret != SQLITE_OK) {
1369 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1374 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1375 if (ret != SQLITE_OK) {
1376 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1382 if (sqlite3_step(stmt) != SQLITE_DONE) {
1383 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1388 sqlite3_reset(stmt);
1389 sqlite3_clear_bindings(stmt);
1390 sqlite3_finalize(stmt);
1394 static inline int db_remove_groupmap(const char *pkgid)
1396 static const char *dml;
1400 dml = "DELETE FROM groupmap WHERE pkgid = ?";
1401 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1402 if (ret != SQLITE_OK) {
1403 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1407 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1408 if (ret != SQLITE_OK) {
1409 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1415 if (sqlite3_step(stmt) != SQLITE_DONE) {
1416 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1420 if (sqlite3_changes(s_info.handle) == 0) {
1421 DbgPrint("No changes\n");
1425 sqlite3_reset(stmt);
1426 sqlite3_clear_bindings(stmt);
1427 sqlite3_finalize(stmt);
1431 static inline int db_create_option(void)
1434 static const char *ddl;
1436 ddl = "CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, " \
1437 "FOREIGN KEY(option_id) REFERENCES groupmap(option_id), " \
1438 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1439 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1440 ErrPrint("Failed to execute the DDL (%s)\n", err);
1444 if (sqlite3_changes(s_info.handle) == 0) {
1445 ErrPrint("No changes to DB\n");
1451 static inline int db_insert_option(const char *pkgid, int option_id, const char *key, const char *value)
1453 static const char *dml;
1457 dml = "INSERT INTO option (pkgid, option_id, key, value) VALUES (?, ?, ?, ?)";
1458 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1459 if (ret != SQLITE_OK) {
1460 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1464 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1465 if (ret != SQLITE_OK) {
1466 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1471 ret = sqlite3_bind_int(stmt, 2, option_id);
1472 if (ret != SQLITE_OK) {
1473 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1478 ret = sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
1479 if (ret != SQLITE_OK) {
1480 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1485 ret = sqlite3_bind_text(stmt, 4, value, -1, SQLITE_TRANSIENT);
1486 if (ret != SQLITE_OK) {
1487 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1493 if (sqlite3_step(stmt) != SQLITE_DONE) {
1494 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1498 sqlite3_reset(stmt);
1499 sqlite3_clear_bindings(stmt);
1500 sqlite3_finalize(stmt);
1504 static inline int db_remove_option(const char *pkgid)
1506 static const char *dml;
1510 dml = "DELETE FROM option WHERE pkgid = ?";
1511 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1512 if (ret != SQLITE_OK) {
1513 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1517 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1518 if (ret != SQLITE_OK) {
1519 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1525 if (sqlite3_step(stmt) != SQLITE_DONE) {
1526 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1530 if (sqlite3_changes(s_info.handle) == 0) {
1531 DbgPrint("No changes\n");
1535 sqlite3_reset(stmt);
1536 sqlite3_clear_bindings(stmt);
1537 sqlite3_finalize(stmt);
1541 static inline int db_create_box_size(void)
1544 static const char *ddl;
1546 ddl = "CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, touch_effect INTEGER, need_frame INTEGER, mouse_event INTEGER " \
1547 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1548 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1549 ErrPrint("Failed to execute the DDL (%s)\n", err);
1553 if (sqlite3_changes(s_info.handle) == 0) {
1554 ErrPrint("No changes to DB\n");
1560 static int db_insert_box_size(const char *pkgid, int size_type, const char *preview, int touch_effect, int need_frame, int mouse_event)
1562 static const char *dml;
1566 DbgPrint("box size: %s - %d (%s) is added\n", pkgid, size_type, preview);
1567 dml = "INSERT INTO box_size ( pkgid, size_type, preview, touch_effect, need_frame, mouse_event ) VALUES (?, ?, ?, ?, ?, ?)";
1568 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1569 if (ret != SQLITE_OK) {
1570 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1574 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1575 if (ret != SQLITE_OK) {
1576 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1581 ret = sqlite3_bind_int(stmt, 2, size_type);
1582 if (ret != SQLITE_OK) {
1583 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1588 ret = sqlite3_bind_text(stmt, 3, preview, -1, SQLITE_TRANSIENT);
1589 if (ret != SQLITE_OK) {
1590 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1595 ret = sqlite3_bind_int(stmt, 4, touch_effect);
1596 if (ret != SQLITE_OK) {
1597 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1602 ret = sqlite3_bind_int(stmt, 5, need_frame);
1603 if (ret != SQLITE_OK) {
1604 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1609 ret = sqlite3_bind_int(stmt, 6, mouse_event);
1610 if (ret != SQLITE_OK) {
1611 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1617 if (sqlite3_step(stmt) != SQLITE_DONE) {
1618 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1623 sqlite3_reset(stmt);
1624 sqlite3_clear_bindings(stmt);
1625 sqlite3_finalize(stmt);
1629 static inline int db_remove_box_size(const char *pkgid)
1631 static const char *dml;
1635 dml = "DELETE FROM box_size WHERE pkgid = ?";
1636 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1637 if (ret != SQLITE_OK) {
1638 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1642 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1643 if (ret != SQLITE_OK) {
1644 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1650 if (sqlite3_step(stmt) != SQLITE_DONE) {
1651 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1655 if (sqlite3_changes(s_info.handle) == 0) {
1656 DbgPrint("No changes\n");
1660 sqlite3_reset(stmt);
1661 sqlite3_clear_bindings(stmt);
1662 sqlite3_finalize(stmt);
1666 static inline void db_create_table(void)
1669 begin_transaction();
1671 ret = db_create_pkgmap();
1673 rollback_transaction();
1677 ret = db_create_provider();
1679 rollback_transaction();
1683 ret = db_create_client();
1685 rollback_transaction();
1689 ret = db_create_i18n();
1691 rollback_transaction();
1695 ret = db_create_box_size();
1697 rollback_transaction();
1701 ret = db_create_group();
1703 rollback_transaction();
1707 ret = db_create_option();
1709 rollback_transaction();
1713 ret = db_create_groupmap();
1715 rollback_transaction();
1719 commit_transaction();
1722 static int db_init(void)
1727 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
1728 if (ret != SQLITE_OK) {
1729 ErrPrint("Failed to open a DB\n");
1733 if (lstat(s_info.dbfile, &stat) < 0) {
1734 ErrPrint("%s\n", strerror(errno));
1735 db_util_close(s_info.handle);
1736 s_info.handle = NULL;
1740 if (!S_ISREG(stat.st_mode)) {
1741 ErrPrint("Invalid file\n");
1742 db_util_close(s_info.handle);
1743 s_info.handle = NULL;
1747 if (!stat.st_size) {
1754 static inline int db_fini(void)
1756 if (!s_info.handle) {
1760 db_util_close(s_info.handle);
1761 s_info.handle = NULL;
1766 static inline int validate_pkgid(const char *appid, const char *pkgid)
1768 /* Just return 1 Always */
1769 return 1 || !strncmp(appid, pkgid, strlen(appid));
1772 static int livebox_destroy(struct livebox *livebox)
1777 struct group *group;
1778 struct option *option;
1782 xmlFree(livebox->auto_launch);
1783 xmlFree(livebox->pkgid);
1784 xmlFree(livebox->abi);
1785 xmlFree(livebox->name);
1786 xmlFree(livebox->icon);
1787 xmlFree(livebox->lb_src);
1788 xmlFree(livebox->lb_group);
1789 xmlFree(livebox->pd_src);
1790 xmlFree(livebox->pd_group);
1791 xmlFree(livebox->pd_size);
1792 xmlFree(livebox->libexec);
1793 xmlFree(livebox->script);
1794 xmlFree(livebox->period);
1795 xmlFree(livebox->content);
1796 xmlFree(livebox->setup);
1797 xmlFree(livebox->category);
1798 xmlFree(livebox->preview[0]); /* 1x1 */
1799 xmlFree(livebox->preview[1]); /* 2x1 */
1800 xmlFree(livebox->preview[2]); /* 2x2 */
1801 xmlFree(livebox->preview[3]); /* 4x1 */
1802 xmlFree(livebox->preview[4]); /* 4x2 */
1803 xmlFree(livebox->preview[5]); /* 4x3 */
1804 xmlFree(livebox->preview[6]); /* 4x4 */
1805 xmlFree(livebox->preview[7]); /* 4x5 */
1806 xmlFree(livebox->preview[8]); /* 4x6 */
1807 xmlFree(livebox->preview[9]); /* easy 1x1 */
1808 xmlFree(livebox->preview[10]); /* easy 3x1 */
1809 xmlFree(livebox->preview[11]); /* easy 3x3 */
1810 xmlFree(livebox->preview[12]); /* full */
1812 dlist_foreach_safe(livebox->i18n_list, l, n, i18n) {
1813 livebox->i18n_list = dlist_remove(livebox->i18n_list, l);
1814 xmlFree(i18n->name);
1815 xmlFree(i18n->icon);
1816 xmlFree(i18n->lang);
1820 dlist_foreach_safe(livebox->group_list, l, n, group) {
1821 livebox->group_list = dlist_remove(livebox->group_list, l);
1822 DbgPrint("Release %s/%s\n", group->cluster, group->category);
1824 if (group->ctx_item) {
1825 dlist_foreach_safe(group->option_list, il, in, option) {
1826 group->option_list = dlist_remove(group->option_list, il);
1827 DbgPrint("Release option %s(%s)\n", option->key, option->value);
1828 xmlFree(option->key);
1829 xmlFree(option->value);
1832 xmlFree(group->ctx_item);
1835 xmlFree(group->cluster);
1836 xmlFree(group->category);
1844 static inline void update_i18n_name(struct livebox *livebox, xmlNodePtr node)
1851 name = xmlNodeGetContent(node);
1853 ErrPrint("Invalid tag\n");
1857 lang = xmlNodeGetLang(node);
1859 if (livebox->name) {
1860 DbgPrint("Override default name: %s\n", livebox->name);
1861 xmlFree(livebox->name);
1864 livebox->name = name;
1868 dlist_foreach(livebox->i18n_list, l, i18n) {
1869 if (!xmlStrcasecmp(i18n->lang, lang)) {
1871 DbgPrint("Override name: %s\n", i18n->name);
1872 xmlFree(i18n->name);
1880 i18n = calloc(1, sizeof(*i18n));
1882 ErrPrint("Heap: %s\n", strerror(errno));
1890 DbgPrint("Label[%s] - [%s] added\n", i18n->lang, i18n->name);
1891 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1894 static inline void update_i18n_icon(struct livebox *livebox, xmlNodePtr node)
1901 icon = xmlNodeGetContent(node);
1903 ErrPrint("Invalid tag\n");
1907 lang = xmlNodeGetLang(node);
1909 if (livebox->icon) {
1910 DbgPrint("Override default icon: %s\n", livebox->icon);
1911 xmlFree(livebox->icon);
1914 livebox->icon = icon;
1918 dlist_foreach(livebox->i18n_list, l, i18n) {
1919 if (!xmlStrcasecmp(i18n->lang, lang)) {
1921 DbgPrint("Override icon %s for %s\n", i18n->icon, i18n->name);
1922 xmlFree(i18n->icon);
1930 i18n = calloc(1, sizeof(*i18n));
1932 ErrPrint("Heap: %s\n", strerror(errno));
1940 DbgPrint("Icon[%s] - [%s] added\n", i18n->lang, i18n->icon);
1941 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1944 static inline void update_launch(struct livebox *livebox, xmlNodePtr node)
1948 launch = xmlNodeGetContent(node);
1950 DbgPrint("Has no launch\n");
1954 if (livebox->auto_launch) {
1955 xmlFree(livebox->auto_launch);
1958 livebox->auto_launch = xmlStrdup(launch);
1959 if (!livebox->auto_launch) {
1960 ErrPrint("Failed to duplicate string: %s\n", (char *)launch);
1965 static inline void update_category(struct livebox *livebox, xmlNodePtr node)
1968 category = xmlNodeGetContent(node);
1970 DbgPrint("Has no valid category\n");
1974 if (livebox->category) {
1975 xmlFree(livebox->category);
1978 livebox->category = xmlStrdup(category);
1979 if (!livebox->category) {
1980 ErrPrint("Failed to duplicate string: %s\n", (char *)category);
1985 static inline void update_ui_appid(struct livebox *livebox, xmlNodePtr node)
1988 uiapp = xmlNodeGetContent(node);
1990 DbgPrint("Has no valid ui-appid\n");
1994 if (livebox->uiapp) {
1995 xmlFree(livebox->uiapp);
1998 livebox->uiapp = xmlStrdup(uiapp);
1999 if (!livebox->uiapp) {
2000 ErrPrint("Failed to duplicate string: %s\n", (char *)uiapp);
2005 static inline void update_setup(struct livebox *livebox, xmlNodePtr node)
2008 setup = xmlNodeGetContent(node);
2010 DbgPrint("Has no setup\n");
2014 if (livebox->setup) {
2015 xmlFree(livebox->setup);
2018 livebox->setup = xmlStrdup(setup);
2019 if (!livebox->setup) {
2020 ErrPrint("Failed to duplicate string: %s\n", (char *)setup);
2025 static inline void update_content(struct livebox *livebox, xmlNodePtr node)
2028 content = xmlNodeGetContent(node);
2030 DbgPrint("Has no content\n");
2034 if (livebox->content) {
2035 xmlFree(livebox->content);
2038 livebox->content = xmlStrdup(content);
2039 if (!livebox->content) {
2040 ErrPrint("Failed to duplicate string: %s\n", (char *)content);
2045 static void update_size_info(struct livebox *livebox, int idx, xmlNodePtr node)
2047 if (xmlHasProp(node, (const xmlChar *)"preview")) {
2048 livebox->preview[idx] = xmlGetProp(node, (const xmlChar *)"preview");
2051 if (xmlHasProp(node, (const xmlChar *)"need_frame")) {
2052 xmlChar *need_frame;
2054 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
2056 livebox->need_frame[idx] = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
2057 xmlFree(need_frame);
2059 livebox->need_frame[idx] = livebox->default_need_frame;
2062 livebox->need_frame[idx] = livebox->default_need_frame;
2065 if (xmlHasProp(node, (const xmlChar *)"touch_effect")) {
2066 xmlChar *touch_effect;
2068 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
2070 livebox->touch_effect[idx] = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
2071 xmlFree(touch_effect);
2073 livebox->touch_effect[idx] = livebox->default_touch_effect;
2076 livebox->touch_effect[idx] = livebox->default_touch_effect;
2079 if (xmlHasProp(node, (const xmlChar *)"mouse_event")) {
2080 xmlChar *mouse_event;
2082 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
2084 livebox->mouse_event[idx] = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
2085 xmlFree(mouse_event);
2087 livebox->mouse_event[idx] = livebox->default_mouse_event;
2090 livebox->mouse_event[idx] = livebox->default_mouse_event;
2094 static inline void update_box(struct livebox *livebox, xmlNodePtr node)
2096 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2097 livebox->lb_type = LB_TYPE_FILE;
2101 type = xmlGetProp(node, (const xmlChar *)"type");
2103 ErrPrint("Type is NIL\n");
2104 livebox->lb_type = LB_TYPE_FILE;
2106 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
2107 livebox->lb_type = LB_TYPE_TEXT;
2108 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
2109 livebox->lb_type = LB_TYPE_BUFFER;
2110 } else if (!xmlStrcasecmp(type, (const xmlChar *)"script")) {
2111 livebox->lb_type = LB_TYPE_SCRIPT;
2112 } else { /* Default */
2113 livebox->lb_type = LB_TYPE_FILE;
2120 if (!xmlHasProp(node, (const xmlChar *)"mouse_event")) {
2121 livebox->default_mouse_event = 0;
2123 xmlChar *mouse_event;
2125 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
2127 ErrPrint("mouse_event is NIL\n");
2128 livebox->default_mouse_event = 0;
2130 livebox->default_mouse_event = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
2131 xmlFree(mouse_event);
2135 if (!xmlHasProp(node, (const xmlChar *)"touch_effect")) {
2136 livebox->default_touch_effect = 1;
2138 xmlChar *touch_effect;
2140 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
2141 if (!touch_effect) {
2142 ErrPrint("default touch_effect is NIL\n");
2143 livebox->default_touch_effect = 1;
2145 livebox->default_touch_effect = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
2146 xmlFree(touch_effect);
2150 if (!xmlHasProp(node, (const xmlChar *)"need_frame")) {
2151 livebox->default_need_frame = 0;
2153 xmlChar *need_frame;
2155 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
2157 ErrPrint("default need_frame is NIL\n");
2158 livebox->default_need_frame = 0;
2160 livebox->default_need_frame = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
2161 xmlFree(need_frame);
2165 for (node = node->children; node; node = node->next) {
2166 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2170 size = xmlNodeGetContent(node);
2172 ErrPrint("Invalid size tag\n");
2176 if (xmlHasProp(node, (const xmlChar *)"mode")) {
2178 mode = xmlGetProp(node, (const xmlChar *)"mode");
2180 DbgPrint("Easy mode: %s\n", mode);
2181 is_easy = !xmlStrcasecmp(mode, (const xmlChar *)"easy");
2186 if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
2188 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
2189 update_size_info(livebox, 9, node);
2191 livebox->size_list |= LB_SIZE_TYPE_1x1;
2192 update_size_info(livebox, 0, node);
2194 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x1")) {
2196 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
2197 update_size_info(livebox, 10, node);
2199 ErrPrint("Invalid size tag (%s)\n", size);
2201 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x3")) {
2203 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
2204 update_size_info(livebox, 11, node);
2206 ErrPrint("Invalid size tag (%s)\n", size);
2208 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
2209 livebox->size_list |= LB_SIZE_TYPE_2x1;
2210 update_size_info(livebox, 1, node);
2211 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
2212 livebox->size_list |= LB_SIZE_TYPE_2x2;
2213 update_size_info(livebox, 2, node);
2214 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
2215 livebox->size_list |= LB_SIZE_TYPE_4x1;
2216 update_size_info(livebox, 3, node);
2217 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
2218 livebox->size_list |= LB_SIZE_TYPE_4x2;
2219 update_size_info(livebox, 4, node);
2220 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
2221 livebox->size_list |= LB_SIZE_TYPE_4x3;
2222 update_size_info(livebox, 5, node);
2223 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
2224 livebox->size_list |= LB_SIZE_TYPE_4x4;
2225 update_size_info(livebox, 6, node);
2226 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x5")) {
2227 livebox->size_list |= LB_SIZE_TYPE_4x5;
2228 update_size_info(livebox, 7, node);
2229 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x6")) {
2230 livebox->size_list |= LB_SIZE_TYPE_4x6;
2231 update_size_info(livebox, 8, node);
2232 } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
2233 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
2234 update_size_info(livebox, 9, node);
2235 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
2236 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
2237 update_size_info(livebox, 10, node);
2238 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
2239 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
2240 update_size_info(livebox, 11, node);
2241 } else if (!xmlStrcasecmp(size, (const xmlChar *)"0x0")) {
2242 livebox->size_list |= LB_SIZE_TYPE_0x0;
2243 update_size_info(livebox, 12, node);
2245 ErrPrint("Invalid size tag (%s)\n", size);
2249 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2252 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2253 ErrPrint("Invalid script tag. has no src\n");
2257 src = xmlGetProp(node, (const xmlChar *)"src");
2259 ErrPrint("Invalid script tag. src is NIL\n");
2263 if (livebox->lb_src) {
2264 DbgPrint("Override lb src: %s\n", livebox->lb_src);
2265 xmlFree(livebox->lb_src);
2268 livebox->lb_src = src;
2270 if (xmlHasProp(node, (const xmlChar *)"group")) {
2272 group = xmlGetProp(node, (const xmlChar *)"group");
2274 ErrPrint("Group is NIL\n");
2276 if (livebox->lb_group) {
2277 DbgPrint("Override lb group: %s\n", livebox->lb_group);
2278 xmlFree(livebox->lb_group);
2281 livebox->lb_group = group;
2288 static inline void update_group(struct livebox *livebox, xmlNodePtr node)
2291 xmlNodePtr category;
2292 xmlNodePtr option_item;
2293 xmlChar *cluster_name;
2294 xmlChar *category_name;
2300 struct group *group;
2301 struct option *option;
2304 for (cluster = cluster->children; cluster; cluster = cluster->next) {
2305 if (xmlStrcasecmp(cluster->name, (const xmlChar *)"cluster")) {
2306 DbgPrint("Skip: %s\n", cluster->name);
2310 if (!xmlHasProp(cluster, (const xmlChar *)"name")) {
2311 ErrPrint("Invalid cluster, has no name\n");
2315 cluster_name = xmlGetProp(cluster, (const xmlChar *)"name");
2316 if (!cluster_name) {
2317 ErrPrint("Invalid cluster name. NIL\n");
2321 for (category = cluster->children; category; category = category->next) {
2322 if (xmlStrcasecmp(category->name, (const xmlChar *)"category")) {
2323 DbgPrint("Skip: %s\n", category->name);
2327 if (!xmlHasProp(category, (const xmlChar *)"name")) {
2328 ErrPrint("Invalid category, has no name\n");
2332 category_name = xmlGetProp(category, (const xmlChar *)"name");
2333 if (!category_name) {
2334 ErrPrint("Invalid category name. NIL\n");
2338 group = calloc(1, sizeof(*group));
2340 ErrPrint("Heap: %s\n", strerror(errno));
2341 xmlFree(category_name);
2345 group->cluster = xmlStrdup(cluster_name);
2346 if (!group->cluster) {
2347 ErrPrint("Heap: %s\n", strerror(errno));
2348 xmlFree(category_name);
2353 group->category = category_name;
2354 livebox->group_list = dlist_append(livebox->group_list, group);
2356 if (!xmlHasProp(category, (const xmlChar *)"context")) {
2357 DbgPrint("%s, %s has no ctx info\n", group->cluster, group->category);
2361 ctx_item = xmlGetProp(category, (const xmlChar *)"context");
2363 ErrPrint("Failed to get context ID (%s, %s)\n", group->cluster, group->category);
2367 group->ctx_item = ctx_item;
2368 DbgPrint("Build group item: %s - %s - %s\n", group->cluster, group->category, group->ctx_item);
2370 for (option_item = category->children; option_item; option_item = option_item->next) {
2371 if (xmlStrcasecmp(option_item->name, (const xmlChar *)"option")) {
2372 DbgPrint("Skip: %s\n", option_item->name);
2376 if (!xmlHasProp(option_item, (const xmlChar *)"key")) {
2377 ErrPrint("Invalid option, has no key\n");
2381 if (!xmlHasProp(option_item, (const xmlChar *)"value")) {
2382 ErrPrint("Invalid option, has no value\n");
2386 key = xmlGetProp(option_item, (const xmlChar *)"key");
2388 ErrPrint("Invalid key. NIL\n");
2392 value = xmlGetProp(option_item, (const xmlChar *)"value");
2394 ErrPrint("Invalid valid. NIL\n");
2399 option = calloc(1, sizeof(*option));
2401 ErrPrint("Heap: %s\n", strerror(errno));
2408 option->value = value;
2410 group->option_list = dlist_append(group->option_list, option);
2414 xmlFree(cluster_name);
2418 static inline void update_pd(struct livebox *livebox, xmlNodePtr node)
2420 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2421 livebox->pd_type = PD_TYPE_SCRIPT;
2425 type = xmlGetProp(node, (const xmlChar *)"type");
2427 ErrPrint("type is NIL\n");
2431 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
2432 livebox->pd_type = PD_TYPE_TEXT;
2433 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
2434 livebox->pd_type = PD_TYPE_BUFFER;
2436 livebox->pd_type = PD_TYPE_SCRIPT;
2442 for (node = node->children; node; node = node->next) {
2443 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2446 size = xmlNodeGetContent(node);
2448 ErrPrint("Invalid size tag\n");
2452 if (livebox->pd_size) {
2453 DbgPrint("Override pd size: %s\n", livebox->pd_size);
2454 xmlFree(livebox->pd_size);
2456 livebox->pd_size = size;
2457 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2460 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2461 ErrPrint("Invalid script tag, has no src\n");
2465 src = xmlGetProp(node, (const xmlChar *)"src");
2467 ErrPrint("src is NIL\n");
2471 if (livebox->pd_src) {
2472 DbgPrint("Overide PD src: %s\n", livebox->pd_src);
2473 xmlFree(livebox->pd_src);
2476 livebox->pd_src = src;
2478 if (xmlHasProp(node, (const xmlChar *)"group")) {
2480 group = xmlGetProp(node, (const xmlChar *)"group");
2482 ErrPrint("Group is NIL\n");
2484 if (livebox->pd_group) {
2485 DbgPrint("Override PD group : %s\n", livebox->pd_group);
2486 xmlFree(livebox->pd_group);
2489 livebox->pd_group = group;
2496 static int db_insert_livebox(struct livebox *livebox, const char *appid)
2501 struct group *group;
2504 struct option *option;
2506 begin_transaction();
2507 ret = db_insert_pkgmap(appid, (char *)livebox->pkgid, (char *)livebox->uiapp, livebox->primary, (char *)livebox->category);
2512 ret = db_insert_provider(livebox);
2517 ret = db_insert_client(livebox);
2522 dlist_foreach(livebox->i18n_list, l, i18n) {
2523 ret = db_insert_i18n((char *)livebox->pkgid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon);
2529 if (livebox->size_list & LB_SIZE_TYPE_1x1) {
2530 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_1x1, (char *)livebox->preview[0], livebox->touch_effect[0], livebox->need_frame[0], livebox->mouse_event[0]);
2536 if (livebox->size_list & LB_SIZE_TYPE_2x1) {
2537 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x1, (char *)livebox->preview[1], livebox->touch_effect[1], livebox->need_frame[1], livebox->mouse_event[1]);
2543 if (livebox->size_list & LB_SIZE_TYPE_2x2) {
2544 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x2, (char *)livebox->preview[2], livebox->touch_effect[2], livebox->need_frame[2], livebox->mouse_event[2]);
2550 if (livebox->size_list & LB_SIZE_TYPE_4x1) {
2551 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x1, (char *)livebox->preview[3], livebox->touch_effect[3], livebox->need_frame[3], livebox->mouse_event[3]);
2557 if (livebox->size_list & LB_SIZE_TYPE_4x2) {
2558 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x2, (char *)livebox->preview[4], livebox->touch_effect[4], livebox->need_frame[4], livebox->mouse_event[4]);
2564 if (livebox->size_list & LB_SIZE_TYPE_4x3) {
2565 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x3, (char *)livebox->preview[5], livebox->touch_effect[5], livebox->need_frame[5], livebox->mouse_event[5]);
2571 if (livebox->size_list & LB_SIZE_TYPE_4x4) {
2572 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x4, (char *)livebox->preview[6], livebox->touch_effect[6], livebox->need_frame[6], livebox->mouse_event[6]);
2578 if (livebox->size_list & LB_SIZE_TYPE_4x5) {
2579 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x5, (char *)livebox->preview[7], livebox->touch_effect[7], livebox->need_frame[7], livebox->mouse_event[7]);
2585 if (livebox->size_list & LB_SIZE_TYPE_4x6) {
2586 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x6, (char *)livebox->preview[8], livebox->touch_effect[8], livebox->need_frame[8], livebox->mouse_event[8]);
2592 if (livebox->size_list & LB_SIZE_TYPE_EASY_1x1) {
2593 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_EASY_1x1, (char *)livebox->preview[9], livebox->touch_effect[9], livebox->need_frame[9], livebox->mouse_event[9]);
2599 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x1) {
2600 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_EASY_3x1, (char *)livebox->preview[10], livebox->touch_effect[10], livebox->need_frame[10], livebox->mouse_event[10]);
2606 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x3) {
2607 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_EASY_3x3, (char *)livebox->preview[11], livebox->touch_effect[11], livebox->need_frame[11], livebox->mouse_event[11]);
2613 if (livebox->size_list & LB_SIZE_TYPE_0x0) {
2614 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_0x0, (char *)livebox->preview[12], livebox->touch_effect[12], livebox->need_frame[12], livebox->mouse_event[12]);
2620 dlist_foreach(livebox->group_list, l, group) {
2622 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2626 ret = db_insert_group((char *)livebox->pkgid, (char *)group->cluster, (char *)group->category);
2628 ErrPrint("[%s]-[%s] is not exists\n", group->cluster, group->category);
2632 DbgPrint("New group name is built - %s/%s\n", group->cluster, group->category);
2633 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2635 ErrPrint("Failed to get group id for %s/%s\n", group->cluster, group->category);
2640 if (!group->ctx_item) {
2641 DbgPrint("%s, %s - has no ctx info\n", group->cluster, group->category);
2645 ret = db_insert_groupmap(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2650 /* REUSE "id" from here , option ID */
2651 id = db_get_option_id(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2656 dlist_foreach(group->option_list, il, option) {
2657 ret = db_insert_option((char *)livebox->pkgid, id, (char *)option->key, (char *)option->value);
2664 commit_transaction();
2665 livebox_destroy(livebox);
2669 ErrPrint("ROLLBACK\n");
2670 rollback_transaction();
2671 livebox_destroy(livebox);
2675 static int do_install(xmlNodePtr node, const char *appid)
2677 struct livebox *livebox;
2681 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2682 ErrPrint("Missing appid\n");
2686 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2687 if (!pkgid || !validate_pkgid(appid, (char *)pkgid)) {
2688 ErrPrint("Invalid appid\n");
2693 DbgPrint("appid: %s\n", (char *)pkgid);
2695 livebox = calloc(1, sizeof(*livebox));
2697 ErrPrint("Heap: %s\n", strerror(errno));
2702 livebox->pkgid = pkgid;
2704 if (xmlHasProp(node, (const xmlChar *)"primary")) {
2705 tmp = xmlGetProp(node, (const xmlChar *)"primary");
2706 livebox->primary = !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2710 if (xmlHasProp(node, (const xmlChar *)"script")) {
2711 livebox->script = xmlGetProp(node, (const xmlChar *)"script");
2712 if (!livebox->script) {
2713 ErrPrint("script is NIL\n");
2717 if (xmlHasProp(node, (const xmlChar *)"nodisplay")) {
2718 tmp = xmlGetProp(node, (const xmlChar *)"nodisplay");
2719 livebox->nodisplay = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2723 if (xmlHasProp(node, (const xmlChar *)"pinup")) {
2724 tmp = xmlGetProp(node, (const xmlChar *)"pinup");
2725 livebox->pinup = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2729 if (xmlHasProp(node, (const xmlChar *)"period")) {
2730 livebox->period = xmlGetProp(node, (const xmlChar *)"period");
2731 if (!livebox->period) {
2732 ErrPrint("Period is NIL\n");
2736 if (xmlHasProp(node, (const xmlChar *)"timeout")) {
2737 livebox->timeout = xmlGetProp(node, (const xmlChar *)"timeout");
2738 if (!livebox->timeout) {
2739 ErrPrint("Timeout is NIL\n");
2743 if (xmlHasProp(node, (const xmlChar *)"secured")) {
2744 tmp = xmlGetProp(node, (const xmlChar *)"secured");
2745 livebox->secured = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2749 if (xmlHasProp(node, (const xmlChar *)"network")) {
2750 tmp = xmlGetProp(node, (const xmlChar *)"network");
2751 livebox->network = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2755 if (xmlHasProp(node, (const xmlChar *)"abi")) {
2756 livebox->abi = xmlGetProp(node, (const xmlChar *)"abi");
2757 if (!livebox->abi) {
2758 ErrPrint("ABI is NIL\n");
2759 livebox_destroy(livebox);
2763 livebox->abi = xmlStrdup((const xmlChar *)"c");
2764 if (!livebox->abi) {
2765 ErrPrint("Heap: %s\n", strerror(errno));
2766 livebox_destroy(livebox);
2771 if (xmlHasProp(node, (const xmlChar *)"libexec")) {
2772 livebox->libexec = xmlGetProp(node, (const xmlChar *)"libexec");
2773 if (!livebox->libexec) {
2774 ErrPrint("libexec is NIL\n");
2775 livebox_destroy(livebox);
2778 } else if (!xmlStrcasecmp(livebox->abi, (const xmlChar *)"c") || !xmlStrcasecmp(livebox->abi, (const xmlChar *)"cpp")) {
2782 len = strlen((char *)livebox->pkgid) + strlen("/libexec/liblive-.so") + 1;
2784 filename = malloc(len);
2786 livebox_destroy(livebox);
2790 snprintf(filename, len, "/libexec/liblive-%s.so", livebox->pkgid);
2791 livebox->libexec = xmlStrdup((xmlChar *)filename);
2792 DbgPrint("Use the default libexec: %s\n", filename);
2795 if (!livebox->libexec) {
2796 livebox_destroy(livebox);
2801 for (node = node->children; node; node = node->next) {
2802 if (!xmlStrcmp(node->name, (const xmlChar *)"text")) {
2806 DbgPrint("Nodename: %s\n", node->name);
2807 if (!xmlStrcasecmp(node->name, (const xmlChar *)"label")) {
2808 update_i18n_name(livebox, node);
2812 if (!xmlStrcasecmp(node->name, (const xmlChar *)"icon")) {
2813 update_i18n_icon(livebox, node);
2817 if (!xmlStrcasecmp(node->name, (const xmlChar *)"box")) {
2818 update_box(livebox, node);
2822 if (!xmlStrcasecmp(node->name, (const xmlChar *)"pd")) {
2823 update_pd(livebox, node);
2827 if (!xmlStrcasecmp(node->name, (const xmlChar *)"group")) {
2828 update_group(livebox, node);
2832 if (!xmlStrcasecmp(node->name, (const xmlChar *)"content")) {
2833 update_content(livebox, node);
2837 if (!xmlStrcasecmp(node->name, (const xmlChar *)"setup")) {
2838 update_setup(livebox, node);
2842 if (!xmlStrcasecmp(node->name, (const xmlChar *)"launch")) {
2843 update_launch(livebox, node);
2847 if (!xmlStrcasecmp(node->name, (const xmlChar *)"ui-appid")) {
2848 update_ui_appid(livebox, node);
2852 if (!xmlStrcasecmp(node->name, (const xmlChar *)"category")) {
2853 update_category(livebox, node);
2858 return db_insert_livebox(livebox, appid);
2861 static inline int do_uninstall(xmlNodePtr node, const char *appid)
2866 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2867 ErrPrint("Missing appid\n");
2871 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2872 if (!validate_pkgid(appid, (char *)pkgid)) {
2873 ErrPrint("Invalid package\n");
2878 begin_transaction();
2879 ret = db_remove_box_size((char *)pkgid);
2884 ret = db_remove_i18n((char *)pkgid);
2889 ret = db_remove_client((char *)pkgid);
2894 ret = db_remove_provider((char *)pkgid);
2899 ret = db_remove_option((char *)pkgid);
2900 DbgPrint("Remove option: %d\n", ret);
2902 ret = db_remove_groupmap((char *)pkgid);
2903 DbgPrint("Remove groupmap: %d\n", ret);
2905 ret = db_remove_group((char *)pkgid);
2910 ret = db_remove_pkgmap((char *)pkgid);
2915 commit_transaction();
2921 rollback_transaction();
2926 static int pkglist_get_via_callback(const char *appid, void (*cb)(const char *appid, const char *pkgid, int prime, void *data), void *data)
2928 const char *dml = "SELECT pkgid, prime FROM pkgmap WHERE appid = ?";
2935 if (!cb || !appid || !strlen(appid)) {
2939 if (!s_info.handle) {
2940 if (db_init() < 0) {
2941 ErrPrint("Failed to init DB\n");
2946 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
2947 if (ret != SQLITE_OK) {
2948 ErrPrint("Failed to prepare the intial DML(%s)\n", sqlite3_errmsg(s_info.handle));
2953 if (sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
2954 ErrPrint("Failed to bind a cluster - %s\n", sqlite3_errmsg(s_info.handle));
2958 while (sqlite3_step(stmt) == SQLITE_ROW) {
2959 pkgid = (const char *)sqlite3_column_text(stmt, 0);
2960 if (!pkgid || !strlen(pkgid)) {
2964 prime = sqlite3_column_int(stmt, 1);
2965 cb(appid, pkgid, prime, data);
2970 sqlite3_reset(stmt);
2971 sqlite3_clear_bindings(stmt);
2972 sqlite3_finalize(stmt);
2976 static void clear_all_pkg(const char *appid, const char *pkgid, int prime, void *data)
2980 ErrPrintWithConsole("Remove old package info: appid(%s), pkgid(%s)\n", appid, pkgid);
2982 ret = db_remove_box_size((char *)pkgid);
2984 ErrPrint("Remove box size: %d\n", ret);
2987 ret = db_remove_i18n((char *)pkgid);
2989 ErrPrint("Remove i18n: %d\n", ret);
2992 ret = db_remove_client((char *)pkgid);
2994 ErrPrint("Remove client: %d\n", ret);
2997 ret = db_remove_provider((char *)pkgid);
2999 ErrPrint("Remove provider: %d\n", ret);
3002 ret = db_remove_option((char *)pkgid);
3004 ErrPrint("Remove option: %d\n", ret);
3007 ret = db_remove_groupmap((char *)pkgid);
3009 ErrPrint("Remove groupmap: %d\n", ret);
3012 ret = db_remove_group((char *)pkgid);
3014 ErrPrint("Remove group: %d\n", ret);
3017 ret = db_remove_pkgmap((char *)pkgid);
3019 ErrPrint("Remove pkgmap: %d\n", ret);
3023 int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *appid)
3027 ErrPrintWithConsole("%s\n", appid);
3029 if (!s_info.handle) {
3030 if (db_init() < 0) {
3031 ErrPrintWithConsole("Failed to init DB\n");
3036 do_upgrade_db_schema();
3038 begin_transaction();
3039 cnt = pkglist_get_via_callback(appid, clear_all_pkg, NULL);
3040 commit_transaction();
3043 DbgPrint("Package[%s] is not deleted: %d\n", appid, cnt);
3048 int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *appid)
3050 ErrPrintWithConsole("[%s]\n", appid);
3055 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
3060 ErrPrintWithConsole("[%s]\n", appid);
3062 if (!s_info.handle) {
3063 ErrPrintWithConsole("Failed to init DB\n");
3067 node = xmlDocGetRootElement(docPtr);
3069 ErrPrintWithConsole("Invalid document\n");
3073 for (node = node->children; node; node = node->next) {
3074 DbgPrint("node->name: %s\n", node->name);
3075 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
3076 ret = do_install(node, appid);
3078 DbgPrint("Returns: %d\n", ret);
3086 int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *appid)
3090 ErrPrintWithConsole("[%s]\n", appid);
3092 if (!s_info.handle) {
3093 if (db_init() < 0) {
3094 ErrPrint("Failed to init DB\n");
3099 do_upgrade_db_schema();
3101 begin_transaction();
3102 cnt = pkglist_get_via_callback(appid, clear_all_pkg, NULL);
3103 commit_transaction();
3106 DbgPrint("Package %s is deleted: %d\n", appid, cnt);
3111 int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *appid)
3113 ErrPrintWithConsole("[%s]\n", appid);
3118 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
3123 ErrPrintWithConsole("[%s]\n", appid);
3125 if (!s_info.handle) {
3126 ErrPrint("Failed to init DB\n");
3130 node = xmlDocGetRootElement(docPtr);
3132 ErrPrint("Invalid document\n");
3136 for (node = node->children; node; node = node->next) {
3137 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
3138 ret = do_install(node, appid);
3140 DbgPrint("Returns: %d\n", ret);
3148 int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *appid)
3150 ErrPrintWithConsole("[%s]\n", appid);
3152 if (!s_info.handle) {
3153 if (db_init() < 0) {
3154 ErrPrint("Failed to init DB\n");
3159 do_upgrade_db_schema();
3163 int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *appid)
3167 ErrPrintWithConsole("[%s]\n", appid);
3169 if (!s_info.handle) {
3173 begin_transaction();
3174 cnt = pkglist_get_via_callback(appid, clear_all_pkg, NULL);
3175 commit_transaction();
3178 DbgPrint("Package %s is deleted: %d\n", appid, cnt);
3184 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *appid)
3186 ErrPrintWithConsole("[%s]\n", appid);
3187 if (!s_info.handle) {
3190 /* Doesn't need to do anything from here, we already dealt it with this */