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>
35 #if !defined(SECURE_LOGD)
36 #define SECURE_LOGD LOGD
39 #if !defined(SECURE_LOGE)
40 #define SECURE_LOGE LOGE
43 #if !defined(SECURE_LOGW)
44 #define SECURE_LOGW LOGW
48 #define DbgPrint(format, arg...) SECURE_LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
49 #define ErrPrint(format, arg...) SECURE_LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
50 #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)
54 #define DEFAULT_CATEGORY "http://tizen.org/category/default"
66 * CREATE TABLE version ( version INTEGER )
70 * +-------+-------+-------+-------+-------------------+
71 * | appid | pkgid | uiapp | prime | categ(from ver 2) |
72 * +-------+-------+-------+-------+-------------------+
73 * | - | - | - | - | - |
74 * +-------+-------+-------+-------+-------------------+
75 * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )
79 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
80 * | pkgid | network | abi | secured | box_type | box_src | box_group | pd_type | pd_src | pd_group | libexec | timeout | period | script | pinup |
81 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
82 * | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
83 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
84 * 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))
86 * = box_type = { text | buffer | script | image }
87 * = pd_type = { text | buffer | script }
88 * = network = { 1 | 0 }
89 * = secured = { 1 | 0 }
93 * +-------+------+---------+-------------+---------+---------+-----------+-------+
94 * | pkgid | Icon | Name | auto_launch | pd_size | content | nodisplay | setup |
95 * +-------+------+---------+-------------+---------+---------+-----------+-------+
96 * | - | - | - | - | - | - | - | - |
97 * +-------+------+---------+-------------+---------+---------+-----------+-------+
98 * 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) )
100 * = auto_launch = UI-APPID
101 * = pd_size = WIDTHxHEIGHT
105 * +-------+------+------+------+
106 * | fk | lang | name | icon |
107 * +-------+------+------+------+
108 * | pkgid | - | - | - |
109 * +-------+------+------+------+
110 * CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
114 * +-------+-----------+---------+--------------+------------+-------------------------+
115 * | pkgid | size_type | preview | touch_effect | need_frame | mouse_event(from ver 3) |
116 * +-------+-----------+---------+--------------+------------+-------------------------+
117 * | - | - | - | - | - | - |
118 * +-------+-----------+---------+--------------+------------+-------------------------+
119 * 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) )
121 * = box_size_list = { WIDTHxHEIGHT; WIDTHxHEIGHT; ... }
124 * +----+---------+----------+-------+
125 * | id | cluster | category | pkgid |
126 * +----+---------+----------+-------+
128 * +----+---------+----------+-------|
129 * 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) ))
132 * +-------+----+----------+-----------+
133 * | pkgid | id | ctx_item | option_id |
134 * +-------+----+----------+-----------+
135 * 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) )
139 * +-------+-----------+-----+-------+
140 * | pkgid | option_id | key | value |
141 * +-------+-----------+-----+-------+
142 * 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) )
145 #if !defined(LIBXML_TREE_ENABLED)
146 #error "LIBXML is not supporting the tree"
153 #define LOG_TAG "PKGMGR_LIVEBOX"
182 xmlChar *auto_launch;
184 xmlChar *name; /* Default name */
185 xmlChar *icon; /* Default icon */
186 xmlChar *libexec; /* Path of the SO file */
187 xmlChar *timeout; /* INTEGER, timeout */
188 xmlChar *period; /* DOUBLE, update period */
189 xmlChar *script; /* Script engine */
190 xmlChar *content; /* Content information */
192 xmlChar *uiapp; /* UI App Id */
193 xmlChar *category; /* Category of this box */
195 int pinup; /* Is this support the pinup feature? */
196 int primary; /* Is this primary livebox? */
199 int default_mouse_event; /* Mouse event processing option for livebox */
200 int default_touch_effect;
201 int default_need_frame;
203 enum lb_type lb_type;
206 int size_list; /* 1x1, 2x1, 2x2, 4x1, 4x2, 4x3, 4x4 */
208 xmlChar *preview[NR_OF_SIZE_LIST];
209 int touch_effect[NR_OF_SIZE_LIST]; /* Touch effect of a livebox */
210 int need_frame[NR_OF_SIZE_LIST]; /* Box needs frame which should be cared by viewer */
211 int mouse_event[NR_OF_SIZE_LIST];
213 enum pd_type pd_type;
216 xmlChar *pd_size; /* Default PD size */
218 struct dlist *i18n_list;
219 struct dlist *group_list;
226 struct dlist *option_list;
238 .dbfile = "/opt/dbspace/.livebox.db",
242 static inline int begin_transaction(void)
247 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
249 if (ret != SQLITE_OK) {
250 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
254 if (sqlite3_step(stmt) != SQLITE_DONE) {
255 DbgPrint("Failed to do update (%s)\n",
256 sqlite3_errmsg(s_info.handle));
257 sqlite3_finalize(stmt);
261 sqlite3_finalize(stmt);
265 static inline int rollback_transaction(void)
270 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
271 if (ret != SQLITE_OK) {
272 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
276 if (sqlite3_step(stmt) != SQLITE_DONE) {
277 DbgPrint("Failed to do update (%s)\n",
278 sqlite3_errmsg(s_info.handle));
279 sqlite3_finalize(stmt);
283 sqlite3_finalize(stmt);
287 static inline int commit_transaction(void)
292 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
293 if (ret != SQLITE_OK) {
294 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
298 if (sqlite3_step(stmt) != SQLITE_DONE) {
299 DbgPrint("Failed to do update (%s)\n",
300 sqlite3_errmsg(s_info.handle));
301 sqlite3_finalize(stmt);
305 sqlite3_finalize(stmt);
309 static void db_create_version(void)
311 static const char *ddl = "CREATE TABLE version (version INTEGER)";
314 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
315 ErrPrint("Failed to execute the DDL (%s)\n", err);
319 if (sqlite3_changes(s_info.handle) == 0) {
320 ErrPrint("No changes to DB\n");
324 static int set_version(int version)
326 static const char *dml = "INSERT INTO version (version) VALUES (?)";
330 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
331 if (ret != SQLITE_OK) {
332 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
336 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
337 ErrPrint("Failed to bind a id(%s)\n", sqlite3_errmsg(s_info.handle));
342 ret = sqlite3_step(stmt);
343 if (ret != SQLITE_DONE) {
344 ErrPrint("Failed to execute the DML for version: %d\n", ret);
352 sqlite3_clear_bindings(stmt);
353 sqlite3_finalize(stmt);
357 static int update_version(int version)
359 static const char *dml = "UPDATE version SET version = ?";
363 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
364 if (ret != SQLITE_OK) {
365 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
369 if (sqlite3_bind_int(stmt, 1, version) != SQLITE_OK) {
370 ErrPrint("Failed to bind a version: %s\n", sqlite3_errmsg(s_info.handle));
375 ret = sqlite3_step(stmt);
376 if (ret != SQLITE_DONE) {
377 ErrPrint("Failed to execute DML: %d\n", ret);
385 sqlite3_clear_bindings(stmt);
386 sqlite3_finalize(stmt);
390 static int get_version(void)
392 static const char *dml = "SELECT version FROM version";
396 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
397 if (ret != SQLITE_OK) {
401 if (sqlite3_step(stmt) != SQLITE_ROW) {
404 ret = sqlite3_column_int(stmt, 0);
408 sqlite3_clear_bindings(stmt);
409 sqlite3_finalize(stmt);
415 * From version 1 to 2
417 static void upgrade_pkgmap_for_category(void)
420 static const char *ddl;
422 ddl = "ALTER TABLE pkgmap ADD COLUMN category TEXT DEFAULT \"" DEFAULT_CATEGORY "\"";
423 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
424 ErrPrint("Failed to execute the DDL (%s)\n", err);
428 if (sqlite3_changes(s_info.handle) == 0) {
429 ErrPrint("No changes to DB\n");
437 * From version 2 to 3
438 * mouse_event is deleted from client table
439 * mouse_event is added to box_size table
441 * Every size has their own configuration for mouse_event flag.
443 static void upgrade_to_version_3(void)
446 static const char *ddl;
447 static const char *dml;
448 sqlite3_stmt *select_stmt;
453 * Create a new column for mouse_event to box_size table.
455 ddl = "ALTER TABLE box_size ADD COLUMN mouse_event INTEGER DEFAULT 0";
456 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
457 ErrPrint("Failed to execute the DDL (%s)\n", err);
461 if (sqlite3_changes(s_info.handle) == 0) {
462 ErrPrint("No changes to DB\n");
467 * Copy mouse_event values from the client to the box_size table.
469 dml = "SELECT pkgid, mouse_event FROM client";
470 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &select_stmt, NULL);
471 if (ret == SQLITE_OK) {
472 sqlite3_stmt *update_stmt;
474 dml = "UPDATE box_size SET mouse_event = ? WHERE pkgid = ?";
475 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &update_stmt, NULL);
476 if (ret == SQLITE_OK) {
480 while (sqlite3_step(select_stmt) == SQLITE_ROW) {
481 pkgid = (const char *)sqlite3_column_text(select_stmt, 0);
483 ErrPrint("Package Id is not valid\n");
487 mouse_event = sqlite3_column_int(select_stmt, 1);
489 ret = sqlite3_bind_int(update_stmt, 1, mouse_event);
490 if (ret != SQLITE_OK) {
491 ErrPrint("Failed to bind mouse_event [%s], [%d]\n", pkgid, mouse_event);
492 sqlite3_reset(update_stmt);
493 sqlite3_clear_bindings(update_stmt);
497 ret = sqlite3_bind_text(update_stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
498 if (ret != SQLITE_OK) {
499 ErrPrint("Failed to bind pkgid [%s], [%d]\n", pkgid, mouse_event);
500 sqlite3_reset(update_stmt);
501 sqlite3_clear_bindings(update_stmt);
505 ret = sqlite3_step(update_stmt);
506 if (ret != SQLITE_DONE) {
507 ErrPrint("Failed to execute DML: %d\n", ret);
508 sqlite3_reset(update_stmt);
509 sqlite3_clear_bindings(update_stmt);
513 sqlite3_reset(update_stmt);
514 sqlite3_clear_bindings(update_stmt);
517 sqlite3_finalize(update_stmt);
519 ErrPrint("Failed to execute DML\n");
522 sqlite3_reset(select_stmt);
523 sqlite3_clear_bindings(select_stmt);
524 sqlite3_finalize(select_stmt);
526 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
531 * Drop a column from the client table
533 ddl = "ALTER TABLE client DROP COLUMN mouse_event";
534 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
535 ErrPrint("Failed to execute the DDL (%s)\n", err);
539 if (sqlite3_changes(s_info.handle) == 0) {
540 ErrPrint("No changes to DB\n");
546 static void do_upgrade_db_schema(void)
550 version = get_version();
555 /* Need to create version table */
557 if (set_version(CUR_VER) < 0) {
558 ErrPrint("Failed to set version\n");
560 /* Need to set version */
562 upgrade_pkgmap_for_category();
564 upgrade_to_version_3();
566 /* Need to update version */
567 DbgPrint("Old version: %d\n", version);
568 if (update_version(CUR_VER) < 0) {
569 ErrPrint("Failed to update version\n");
576 static inline int db_create_pkgmap(void)
579 static const char *ddl;
581 ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER, category TEXT )";
582 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
583 ErrPrint("Failed to execute the DDL (%s)\n", err);
587 if (sqlite3_changes(s_info.handle) == 0) {
588 ErrPrint("No changes to DB\n");
594 static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const char *uiappid, int primary, const char *category)
597 static const char *dml;
600 dml = "INSERT INTO pkgmap ( appid, pkgid, uiapp, prime, category ) VALUES (? ,?, ?, ?, ?)";
601 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
602 if (ret != SQLITE_OK) {
603 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
607 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
608 if (ret != SQLITE_OK) {
609 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
614 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
615 if (ret != SQLITE_OK) {
616 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
621 ret = sqlite3_bind_text(stmt, 3, uiappid, -1, SQLITE_TRANSIENT);
622 if (ret != SQLITE_OK) {
623 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
628 ret = sqlite3_bind_int(stmt, 4, primary);
629 if (ret != SQLITE_OK) {
630 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
635 ret = sqlite3_bind_text(stmt, 5, category, -1, SQLITE_TRANSIENT);
636 if (ret != SQLITE_OK) {
637 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
643 if (sqlite3_step(stmt) != SQLITE_DONE) {
644 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
650 sqlite3_clear_bindings(stmt);
651 sqlite3_finalize(stmt);
655 static inline int db_remove_pkgmap(const char *pkgid)
658 static const char *dml;
661 dml = "DELETE FROM pkgmap WHERE pkgid = ?";
662 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
663 if (ret != SQLITE_OK) {
664 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
668 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
669 if (ret != SQLITE_OK) {
670 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
676 if (sqlite3_step(stmt) != SQLITE_DONE) {
677 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
683 sqlite3_clear_bindings(stmt);
684 sqlite3_finalize(stmt);
688 static inline int db_create_provider(void)
691 static const char *ddl;
693 ddl = "CREATE TABLE provider (" \
694 "pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, " \
695 "abi TEXT, secured INTEGER, box_type INTEGER, " \
696 "box_src TEXT, box_group TEXT, pd_type INTEGER, " \
697 "pd_src TEXT, pd_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, "\
698 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
700 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
701 ErrPrint("Failed to execute the DDL (%s)\n", err);
705 if (sqlite3_changes(s_info.handle) == 0) {
706 ErrPrint("No changes to DB\n");
712 static inline int db_remove_provider(const char *pkgid)
714 static const char *dml;
718 dml = "DELETE FROM provider WHERE pkgid = ?";
719 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
720 if (ret != SQLITE_OK) {
721 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
725 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
726 if (ret != SQLITE_OK) {
727 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
733 if (sqlite3_step(stmt) != SQLITE_DONE) {
734 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
740 sqlite3_clear_bindings(stmt);
741 sqlite3_finalize(stmt);
744 static int db_insert_provider(struct livebox *livebox)
746 static const char *dml;
749 char *abi = (char *)livebox->abi;
750 char *box_src = (char *)livebox->lb_src;
751 char *box_group = (char *)livebox->lb_group;
752 char *pd_src = (char *)livebox->pd_src;
753 char *pd_group = (char *)livebox->pd_group;
754 char *libexec = (char *)livebox->libexec;
755 char *timeout = (char *)livebox->timeout;
756 char *period = (char *)livebox->period;
757 char *script = (char *)livebox->script;
775 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
776 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
777 if (ret != SQLITE_OK) {
778 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
782 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
783 if (ret != SQLITE_OK) {
784 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
789 ret = sqlite3_bind_int(stmt, 2, livebox->network);
790 if (ret != SQLITE_OK) {
791 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
796 ret = sqlite3_bind_text(stmt, 3, abi, -1, SQLITE_TRANSIENT);
797 if (ret != SQLITE_OK) {
798 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
802 ret = sqlite3_bind_int(stmt, 4, livebox->secured);
803 if (ret != SQLITE_OK) {
804 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
809 ret = sqlite3_bind_int(stmt, 5, livebox->lb_type);
810 if (ret != SQLITE_OK) {
811 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
816 ret = sqlite3_bind_text(stmt, 6, box_src, -1, SQLITE_TRANSIENT);
817 if (ret != SQLITE_OK) {
818 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
823 ret = sqlite3_bind_text(stmt, 7, box_group, -1, SQLITE_TRANSIENT);
824 if (ret != SQLITE_OK) {
825 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
830 ret = sqlite3_bind_int(stmt, 8, livebox->pd_type);
831 if (ret != SQLITE_OK) {
832 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
837 ret = sqlite3_bind_text(stmt, 9, pd_src, -1, SQLITE_TRANSIENT);
838 if (ret != SQLITE_OK) {
839 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
844 ret = sqlite3_bind_text(stmt, 10, pd_group, -1, SQLITE_TRANSIENT);
845 if (ret != SQLITE_OK) {
846 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
851 ret = sqlite3_bind_text(stmt, 11, libexec, -1, SQLITE_TRANSIENT);
852 if (ret != SQLITE_OK) {
853 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
858 ret = sqlite3_bind_int(stmt, 12, atoi(timeout));
859 if (ret != SQLITE_OK) {
860 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
865 ret = sqlite3_bind_text(stmt, 13, period, -1, SQLITE_TRANSIENT);
866 if (ret != SQLITE_OK) {
867 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
872 ret = sqlite3_bind_text(stmt, 14, script, -1, SQLITE_TRANSIENT);
873 if (ret != SQLITE_OK) {
874 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
879 ret = sqlite3_bind_int(stmt, 15, livebox->pinup);
880 if (ret != SQLITE_OK) {
881 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
887 if (sqlite3_step(stmt) != SQLITE_DONE) {
888 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
894 sqlite3_clear_bindings(stmt);
895 sqlite3_finalize(stmt);
899 static inline int db_create_client(void)
902 static const char *ddl;
904 ddl = "CREATE TABLE client (" \
905 "pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, " \
906 "auto_launch TEXT, pd_size TEXT, content TEXT, nodisplay INTEGER, setup TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
907 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
908 ErrPrint("Failed to execute the DDL (%s)\n", err);
912 if (sqlite3_changes(s_info.handle) == 0) {
913 ErrPrint("No changes to DB\n");
919 static inline int db_insert_client(struct livebox *livebox)
921 static const char *dml;
925 dml = "INSERT INTO client ( pkgid, icon, name, auto_launch, pd_size, content, nodisplay, setup ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
926 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
927 if (ret != SQLITE_OK) {
928 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
932 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
933 if (ret != SQLITE_OK) {
934 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
939 ret = sqlite3_bind_text(stmt, 2, (char *)livebox->icon, -1, SQLITE_TRANSIENT);
940 if (ret != SQLITE_OK) {
941 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
946 ret = sqlite3_bind_text(stmt, 3, (char *)livebox->name, -1, SQLITE_TRANSIENT);
947 if (ret != SQLITE_OK) {
948 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
953 ret = sqlite3_bind_text(stmt, 4, (char *)livebox->auto_launch, -1, SQLITE_TRANSIENT);
954 if (ret != SQLITE_OK) {
955 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
960 ret = sqlite3_bind_text(stmt, 5, (char *)livebox->pd_size, -1, SQLITE_TRANSIENT);
961 if (ret != SQLITE_OK) {
962 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
967 ret = sqlite3_bind_text(stmt, 6, (char *)livebox->content, -1, SQLITE_TRANSIENT);
968 if (ret != SQLITE_OK) {
969 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
974 ret = sqlite3_bind_int(stmt, 7, livebox->nodisplay);
975 if (ret != SQLITE_OK) {
976 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
981 ret = sqlite3_bind_text(stmt, 8, (char *)livebox->setup, -1, SQLITE_TRANSIENT);
982 if (ret != SQLITE_OK) {
983 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
989 if (sqlite3_step(stmt) != SQLITE_DONE) {
990 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
996 sqlite3_clear_bindings(stmt);
997 sqlite3_finalize(stmt);
1001 static inline int db_remove_client(const char *pkgid)
1003 static const char *dml;
1007 dml = "DELETE FROM client WHERE pkgid = ?";
1008 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1009 if (ret != SQLITE_OK) {
1010 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1014 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1015 if (ret != SQLITE_OK) {
1016 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1022 if (sqlite3_step(stmt) != SQLITE_DONE) {
1023 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1028 sqlite3_reset(stmt);
1029 sqlite3_clear_bindings(stmt);
1030 sqlite3_finalize(stmt);
1034 static inline int db_create_i18n(void)
1037 static const char *ddl;
1039 ddl = "CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, " \
1040 "icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1041 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1042 ErrPrint("Failed to execute the DDL (%s)\n", err);
1046 if (sqlite3_changes(s_info.handle) == 0) {
1047 ErrPrint("No changes to DB\n");
1053 static inline int db_insert_i18n(const char *pkgid, const char *lang, const char *name, const char *icon)
1055 static const char *dml;
1059 DbgPrint("%s - lang[%s] name[%s] icon[%s]\n", pkgid, lang, name, icon);
1060 dml = "INSERT INTO i18n ( pkgid, lang, name, icon ) VALUES (?, ?, ?, ?)";
1061 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1062 if (ret != SQLITE_OK) {
1063 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1067 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1068 if (ret != SQLITE_OK) {
1069 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1074 ret = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
1075 if (ret != SQLITE_OK) {
1076 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1081 ret = sqlite3_bind_text(stmt, 3, name, -1, SQLITE_TRANSIENT);
1082 if (ret != SQLITE_OK) {
1083 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1088 ret = sqlite3_bind_text(stmt, 4, icon, -1, SQLITE_TRANSIENT);
1089 if (ret != SQLITE_OK) {
1090 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1096 if (sqlite3_step(stmt) != SQLITE_DONE) {
1097 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1102 sqlite3_reset(stmt);
1103 sqlite3_clear_bindings(stmt);
1104 sqlite3_finalize(stmt);
1108 static inline int db_remove_i18n(const char *pkgid)
1110 static const char *dml;
1114 dml = "DELETE FROM i18n WHERE pkgid = ?";
1115 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1116 if (ret != SQLITE_OK) {
1117 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1121 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1122 if (ret != SQLITE_OK) {
1123 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1129 if (sqlite3_step(stmt) != SQLITE_DONE) {
1130 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1134 if (sqlite3_changes(s_info.handle) == 0) {
1135 DbgPrint("No changes\n");
1139 sqlite3_reset(stmt);
1140 sqlite3_clear_bindings(stmt);
1141 sqlite3_finalize(stmt);
1145 static inline int db_create_group(void)
1148 static const char *ddl;
1150 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)";
1151 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1152 ErrPrint("Failed to execute the DDL (%s)\n", err);
1156 if (sqlite3_changes(s_info.handle) == 0) {
1157 ErrPrint("No changes to DB\n");
1163 static inline int db_insert_group(const char *pkgid, const char *cluster, const char *category)
1165 static const char *dml;
1169 dml = "INSERT INTO groupinfo ( cluster, category, pkgid ) VALUES (?, ?, ?)";
1170 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1171 if (ret != SQLITE_OK) {
1172 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1176 ret = sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT);
1177 if (ret != SQLITE_OK) {
1178 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1183 ret = sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT);
1184 if (ret != SQLITE_OK) {
1185 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1190 ret = sqlite3_bind_text(stmt, 3, pkgid, -1, SQLITE_TRANSIENT);
1191 if (ret != SQLITE_OK) {
1192 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1198 if (sqlite3_step(stmt) != SQLITE_DONE) {
1199 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1204 sqlite3_reset(stmt);
1205 sqlite3_clear_bindings(stmt);
1206 sqlite3_finalize(stmt);
1210 static int db_get_group_id(const char *cluster, const char *category)
1212 static const char *dml = "SELECT id FROM groupinfo WHERE cluster = ? AND category = ?";
1216 if (!cluster || !category) {
1217 ErrPrint("Invalid argument\n");
1221 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1222 if (ret != SQLITE_OK) {
1223 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
1228 if (sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
1229 ErrPrint("Failed to bind a cluster(%s) - %s\n", cluster, sqlite3_errmsg(s_info.handle));
1233 if (sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
1234 ErrPrint("Failed to bind a category(%s) - %s\n", category, sqlite3_errmsg(s_info.handle));
1238 if (sqlite3_step(stmt) != SQLITE_ROW) {
1239 ErrPrint("Failed to execute the DML for %s - %s\n", cluster, category);
1243 ret = sqlite3_column_int(stmt, 0);
1246 sqlite3_reset(stmt);
1247 sqlite3_clear_bindings(stmt);
1248 sqlite3_finalize(stmt);
1252 static inline int db_remove_group(const char *pkgid)
1254 static const char *dml;
1258 dml = "DELETE FROM groupinfo WHERE pkgid = ?";
1259 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1260 if (ret != SQLITE_OK) {
1261 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1265 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1266 if (ret != SQLITE_OK) {
1267 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1273 if (sqlite3_step(stmt) != SQLITE_DONE) {
1274 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1278 if (sqlite3_changes(s_info.handle) == 0) {
1279 DbgPrint("No changes\n");
1283 sqlite3_reset(stmt);
1284 sqlite3_clear_bindings(stmt);
1285 sqlite3_finalize(stmt);
1289 static inline int db_create_groupmap(void)
1292 static const char *ddl;
1294 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)";
1295 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1296 ErrPrint("Failed to execute the DDL (%s)\n", err);
1300 if (sqlite3_changes(s_info.handle) == 0) {
1301 ErrPrint("No changes to DB\n");
1307 static inline int db_get_option_id(int id, const char *pkgid, const char *ctx_item)
1309 static const char *dml;
1313 dml = "SELECT option_id FROM groupmap WHERE id = ? AND pkgid = ? AND ctx_item = ?";
1314 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1315 if (ret != SQLITE_OK) {
1316 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1320 ret = sqlite3_bind_int(stmt, 1, id);
1321 if (ret != SQLITE_OK) {
1322 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1327 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1328 if (ret != SQLITE_OK) {
1329 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1334 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1335 if (ret != SQLITE_OK) {
1336 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1342 if (sqlite3_step(stmt) != SQLITE_ROW) {
1343 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1348 ret = sqlite3_column_int(stmt, 0);
1351 sqlite3_reset(stmt);
1352 sqlite3_clear_bindings(stmt);
1353 sqlite3_finalize(stmt);
1357 static inline int db_insert_groupmap(int id, const char *pkgid, const char *ctx_item)
1359 static const char *dml;
1363 DbgPrint("%d (%s) add to groupmap\n", id, pkgid);
1365 dml = "INSERT INTO groupmap ( id, pkgid, ctx_item ) VALUES (?, ?, ?)";
1366 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1367 if (ret != SQLITE_OK) {
1368 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1372 ret = sqlite3_bind_int(stmt, 1, id);
1373 if (ret != SQLITE_OK) {
1374 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1379 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1380 if (ret != SQLITE_OK) {
1381 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1386 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1387 if (ret != SQLITE_OK) {
1388 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1394 if (sqlite3_step(stmt) != SQLITE_DONE) {
1395 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1400 sqlite3_reset(stmt);
1401 sqlite3_clear_bindings(stmt);
1402 sqlite3_finalize(stmt);
1406 static inline int db_remove_groupmap(const char *pkgid)
1408 static const char *dml;
1412 dml = "DELETE FROM groupmap WHERE pkgid = ?";
1413 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1414 if (ret != SQLITE_OK) {
1415 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1419 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1420 if (ret != SQLITE_OK) {
1421 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1427 if (sqlite3_step(stmt) != SQLITE_DONE) {
1428 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1432 if (sqlite3_changes(s_info.handle) == 0) {
1433 DbgPrint("No changes\n");
1437 sqlite3_reset(stmt);
1438 sqlite3_clear_bindings(stmt);
1439 sqlite3_finalize(stmt);
1443 static inline int db_create_option(void)
1446 static const char *ddl;
1448 ddl = "CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, " \
1449 "FOREIGN KEY(option_id) REFERENCES groupmap(option_id), " \
1450 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1451 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1452 ErrPrint("Failed to execute the DDL (%s)\n", err);
1456 if (sqlite3_changes(s_info.handle) == 0) {
1457 ErrPrint("No changes to DB\n");
1463 static inline int db_insert_option(const char *pkgid, int option_id, const char *key, const char *value)
1465 static const char *dml;
1469 dml = "INSERT INTO option (pkgid, option_id, key, value) VALUES (?, ?, ?, ?)";
1470 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1471 if (ret != SQLITE_OK) {
1472 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1476 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1477 if (ret != SQLITE_OK) {
1478 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1483 ret = sqlite3_bind_int(stmt, 2, option_id);
1484 if (ret != SQLITE_OK) {
1485 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1490 ret = sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
1491 if (ret != SQLITE_OK) {
1492 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1497 ret = sqlite3_bind_text(stmt, 4, value, -1, SQLITE_TRANSIENT);
1498 if (ret != SQLITE_OK) {
1499 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1505 if (sqlite3_step(stmt) != SQLITE_DONE) {
1506 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1510 sqlite3_reset(stmt);
1511 sqlite3_clear_bindings(stmt);
1512 sqlite3_finalize(stmt);
1516 static inline int db_remove_option(const char *pkgid)
1518 static const char *dml;
1522 dml = "DELETE FROM option WHERE pkgid = ?";
1523 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1524 if (ret != SQLITE_OK) {
1525 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1529 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1530 if (ret != SQLITE_OK) {
1531 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1537 if (sqlite3_step(stmt) != SQLITE_DONE) {
1538 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1542 if (sqlite3_changes(s_info.handle) == 0) {
1543 DbgPrint("No changes\n");
1547 sqlite3_reset(stmt);
1548 sqlite3_clear_bindings(stmt);
1549 sqlite3_finalize(stmt);
1553 static inline int db_create_box_size(void)
1556 static const char *ddl;
1558 ddl = "CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, touch_effect INTEGER, need_frame INTEGER, mouse_event INTEGER " \
1559 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1560 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1561 ErrPrint("Failed to execute the DDL (%s)\n", err);
1565 if (sqlite3_changes(s_info.handle) == 0) {
1566 ErrPrint("No changes to DB\n");
1572 static int db_insert_box_size(const char *pkgid, int size_type, const char *preview, int touch_effect, int need_frame, int mouse_event)
1574 static const char *dml;
1578 DbgPrint("box size: %s - %d (%s) is added\n", pkgid, size_type, preview);
1579 dml = "INSERT INTO box_size ( pkgid, size_type, preview, touch_effect, need_frame, mouse_event ) VALUES (?, ?, ?, ?, ?, ?)";
1580 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1581 if (ret != SQLITE_OK) {
1582 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1586 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1587 if (ret != SQLITE_OK) {
1588 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1593 ret = sqlite3_bind_int(stmt, 2, size_type);
1594 if (ret != SQLITE_OK) {
1595 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1600 ret = sqlite3_bind_text(stmt, 3, preview, -1, SQLITE_TRANSIENT);
1601 if (ret != SQLITE_OK) {
1602 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1607 ret = sqlite3_bind_int(stmt, 4, touch_effect);
1608 if (ret != SQLITE_OK) {
1609 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1614 ret = sqlite3_bind_int(stmt, 5, need_frame);
1615 if (ret != SQLITE_OK) {
1616 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1621 ret = sqlite3_bind_int(stmt, 6, mouse_event);
1622 if (ret != SQLITE_OK) {
1623 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1629 if (sqlite3_step(stmt) != SQLITE_DONE) {
1630 ErrPrintWithConsole("Error: %s\n", sqlite3_errmsg(s_info.handle));
1635 sqlite3_reset(stmt);
1636 sqlite3_clear_bindings(stmt);
1637 sqlite3_finalize(stmt);
1641 static inline int db_remove_box_size(const char *pkgid)
1643 static const char *dml;
1647 dml = "DELETE FROM box_size WHERE pkgid = ?";
1648 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1649 if (ret != SQLITE_OK) {
1650 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1654 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1655 if (ret != SQLITE_OK) {
1656 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1662 if (sqlite3_step(stmt) != SQLITE_DONE) {
1663 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1667 if (sqlite3_changes(s_info.handle) == 0) {
1668 DbgPrint("No changes\n");
1672 sqlite3_reset(stmt);
1673 sqlite3_clear_bindings(stmt);
1674 sqlite3_finalize(stmt);
1678 static inline void db_create_table(void)
1681 begin_transaction();
1683 ret = db_create_pkgmap();
1685 rollback_transaction();
1689 ret = db_create_provider();
1691 rollback_transaction();
1695 ret = db_create_client();
1697 rollback_transaction();
1701 ret = db_create_i18n();
1703 rollback_transaction();
1707 ret = db_create_box_size();
1709 rollback_transaction();
1713 ret = db_create_group();
1715 rollback_transaction();
1719 ret = db_create_option();
1721 rollback_transaction();
1725 ret = db_create_groupmap();
1727 rollback_transaction();
1731 commit_transaction();
1734 static int db_init(void)
1739 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
1740 if (ret != SQLITE_OK) {
1741 ErrPrint("Failed to open a DB\n");
1745 if (lstat(s_info.dbfile, &stat) < 0) {
1746 ErrPrint("%s\n", strerror(errno));
1747 db_util_close(s_info.handle);
1748 s_info.handle = NULL;
1752 if (!S_ISREG(stat.st_mode)) {
1753 ErrPrint("Invalid file\n");
1754 db_util_close(s_info.handle);
1755 s_info.handle = NULL;
1759 if (!stat.st_size) {
1766 static inline int db_fini(void)
1768 if (!s_info.handle) {
1772 db_util_close(s_info.handle);
1773 s_info.handle = NULL;
1778 static inline int validate_pkgid(const char *appid, const char *pkgid)
1780 /* Just return 1 Always */
1781 return 1 || !strncmp(appid, pkgid, strlen(appid));
1784 static int livebox_destroy(struct livebox *livebox)
1789 struct group *group;
1790 struct option *option;
1794 xmlFree(livebox->auto_launch);
1795 xmlFree(livebox->pkgid);
1796 xmlFree(livebox->abi);
1797 xmlFree(livebox->name);
1798 xmlFree(livebox->icon);
1799 xmlFree(livebox->lb_src);
1800 xmlFree(livebox->lb_group);
1801 xmlFree(livebox->pd_src);
1802 xmlFree(livebox->pd_group);
1803 xmlFree(livebox->pd_size);
1804 xmlFree(livebox->libexec);
1805 xmlFree(livebox->script);
1806 xmlFree(livebox->period);
1807 xmlFree(livebox->content);
1808 xmlFree(livebox->setup);
1809 xmlFree(livebox->category);
1810 xmlFree(livebox->preview[0]); /* 1x1 */
1811 xmlFree(livebox->preview[1]); /* 2x1 */
1812 xmlFree(livebox->preview[2]); /* 2x2 */
1813 xmlFree(livebox->preview[3]); /* 4x1 */
1814 xmlFree(livebox->preview[4]); /* 4x2 */
1815 xmlFree(livebox->preview[5]); /* 4x3 */
1816 xmlFree(livebox->preview[6]); /* 4x4 */
1817 xmlFree(livebox->preview[7]); /* 4x5 */
1818 xmlFree(livebox->preview[8]); /* 4x6 */
1819 xmlFree(livebox->preview[9]); /* easy 1x1 */
1820 xmlFree(livebox->preview[10]); /* easy 3x1 */
1821 xmlFree(livebox->preview[11]); /* easy 3x3 */
1822 xmlFree(livebox->preview[12]); /* full */
1824 dlist_foreach_safe(livebox->i18n_list, l, n, i18n) {
1825 livebox->i18n_list = dlist_remove(livebox->i18n_list, l);
1826 xmlFree(i18n->name);
1827 xmlFree(i18n->icon);
1828 xmlFree(i18n->lang);
1832 dlist_foreach_safe(livebox->group_list, l, n, group) {
1833 livebox->group_list = dlist_remove(livebox->group_list, l);
1834 DbgPrint("Release %s/%s\n", group->cluster, group->category);
1836 if (group->ctx_item) {
1837 dlist_foreach_safe(group->option_list, il, in, option) {
1838 group->option_list = dlist_remove(group->option_list, il);
1839 DbgPrint("Release option %s(%s)\n", option->key, option->value);
1840 xmlFree(option->key);
1841 xmlFree(option->value);
1844 xmlFree(group->ctx_item);
1847 xmlFree(group->cluster);
1848 xmlFree(group->category);
1856 static inline void update_i18n_name(struct livebox *livebox, xmlNodePtr node)
1863 name = xmlNodeGetContent(node);
1865 ErrPrint("Invalid tag\n");
1869 lang = xmlNodeGetLang(node);
1871 if (livebox->name) {
1872 DbgPrint("Override default name: %s\n", livebox->name);
1873 xmlFree(livebox->name);
1876 livebox->name = name;
1880 dlist_foreach(livebox->i18n_list, l, i18n) {
1881 if (!xmlStrcasecmp(i18n->lang, lang)) {
1883 DbgPrint("Override name: %s\n", i18n->name);
1884 xmlFree(i18n->name);
1892 i18n = calloc(1, sizeof(*i18n));
1894 ErrPrint("Heap: %s\n", strerror(errno));
1902 DbgPrint("Label[%s] - [%s] added\n", i18n->lang, i18n->name);
1903 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1906 static inline void update_i18n_icon(struct livebox *livebox, xmlNodePtr node)
1913 icon = xmlNodeGetContent(node);
1915 ErrPrint("Invalid tag\n");
1919 lang = xmlNodeGetLang(node);
1921 if (livebox->icon) {
1922 DbgPrint("Override default icon: %s\n", livebox->icon);
1923 xmlFree(livebox->icon);
1926 livebox->icon = icon;
1930 dlist_foreach(livebox->i18n_list, l, i18n) {
1931 if (!xmlStrcasecmp(i18n->lang, lang)) {
1933 DbgPrint("Override icon %s for %s\n", i18n->icon, i18n->name);
1934 xmlFree(i18n->icon);
1942 i18n = calloc(1, sizeof(*i18n));
1944 ErrPrint("Heap: %s\n", strerror(errno));
1952 DbgPrint("Icon[%s] - [%s] added\n", i18n->lang, i18n->icon);
1953 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1956 static inline void update_launch(struct livebox *livebox, xmlNodePtr node)
1960 launch = xmlNodeGetContent(node);
1962 DbgPrint("Has no launch\n");
1966 if (livebox->auto_launch) {
1967 xmlFree(livebox->auto_launch);
1970 livebox->auto_launch = xmlStrdup(launch);
1971 if (!livebox->auto_launch) {
1972 ErrPrint("Failed to duplicate string: %s\n", (char *)launch);
1977 static inline void update_category(struct livebox *livebox, xmlNodePtr node)
1980 category = xmlNodeGetContent(node);
1982 DbgPrint("Has no valid category\n");
1986 if (livebox->category) {
1987 xmlFree(livebox->category);
1990 livebox->category = xmlStrdup(category);
1991 if (!livebox->category) {
1992 ErrPrint("Failed to duplicate string: %s\n", (char *)category);
1997 static inline void update_ui_appid(struct livebox *livebox, xmlNodePtr node)
2000 uiapp = xmlNodeGetContent(node);
2002 DbgPrint("Has no valid ui-appid\n");
2006 if (livebox->uiapp) {
2007 xmlFree(livebox->uiapp);
2010 livebox->uiapp = xmlStrdup(uiapp);
2011 if (!livebox->uiapp) {
2012 ErrPrint("Failed to duplicate string: %s\n", (char *)uiapp);
2017 static inline void update_setup(struct livebox *livebox, xmlNodePtr node)
2020 setup = xmlNodeGetContent(node);
2022 DbgPrint("Has no setup\n");
2026 if (livebox->setup) {
2027 xmlFree(livebox->setup);
2030 livebox->setup = xmlStrdup(setup);
2031 if (!livebox->setup) {
2032 ErrPrint("Failed to duplicate string: %s\n", (char *)setup);
2037 static inline void update_content(struct livebox *livebox, xmlNodePtr node)
2040 content = xmlNodeGetContent(node);
2042 DbgPrint("Has no content\n");
2046 if (livebox->content) {
2047 xmlFree(livebox->content);
2050 livebox->content = xmlStrdup(content);
2051 if (!livebox->content) {
2052 ErrPrint("Failed to duplicate string: %s\n", (char *)content);
2057 static void update_size_info(struct livebox *livebox, int idx, xmlNodePtr node)
2059 if (xmlHasProp(node, (const xmlChar *)"preview")) {
2060 livebox->preview[idx] = xmlGetProp(node, (const xmlChar *)"preview");
2063 if (xmlHasProp(node, (const xmlChar *)"need_frame")) {
2064 xmlChar *need_frame;
2066 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
2068 livebox->need_frame[idx] = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
2069 xmlFree(need_frame);
2071 livebox->need_frame[idx] = livebox->default_need_frame;
2074 livebox->need_frame[idx] = livebox->default_need_frame;
2077 if (xmlHasProp(node, (const xmlChar *)"touch_effect")) {
2078 xmlChar *touch_effect;
2080 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
2082 livebox->touch_effect[idx] = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
2083 xmlFree(touch_effect);
2085 livebox->touch_effect[idx] = livebox->default_touch_effect;
2088 livebox->touch_effect[idx] = livebox->default_touch_effect;
2091 if (xmlHasProp(node, (const xmlChar *)"mouse_event")) {
2092 xmlChar *mouse_event;
2094 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
2096 livebox->mouse_event[idx] = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
2097 xmlFree(mouse_event);
2099 livebox->mouse_event[idx] = livebox->default_mouse_event;
2102 livebox->mouse_event[idx] = livebox->default_mouse_event;
2106 static inline void update_box(struct livebox *livebox, xmlNodePtr node)
2108 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2109 livebox->lb_type = LB_TYPE_FILE;
2113 type = xmlGetProp(node, (const xmlChar *)"type");
2115 ErrPrint("Type is NIL\n");
2116 livebox->lb_type = LB_TYPE_FILE;
2118 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
2119 livebox->lb_type = LB_TYPE_TEXT;
2120 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
2121 livebox->lb_type = LB_TYPE_BUFFER;
2122 } else if (!xmlStrcasecmp(type, (const xmlChar *)"script")) {
2123 livebox->lb_type = LB_TYPE_SCRIPT;
2124 } else { /* Default */
2125 livebox->lb_type = LB_TYPE_FILE;
2132 if (!xmlHasProp(node, (const xmlChar *)"mouse_event")) {
2133 livebox->default_mouse_event = 0;
2135 xmlChar *mouse_event;
2137 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
2139 ErrPrint("mouse_event is NIL\n");
2140 livebox->default_mouse_event = 0;
2142 livebox->default_mouse_event = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
2143 xmlFree(mouse_event);
2147 if (!xmlHasProp(node, (const xmlChar *)"touch_effect")) {
2148 livebox->default_touch_effect = 1;
2150 xmlChar *touch_effect;
2152 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
2153 if (!touch_effect) {
2154 ErrPrint("default touch_effect is NIL\n");
2155 livebox->default_touch_effect = 1;
2157 livebox->default_touch_effect = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
2158 xmlFree(touch_effect);
2162 if (!xmlHasProp(node, (const xmlChar *)"need_frame")) {
2163 livebox->default_need_frame = 0;
2165 xmlChar *need_frame;
2167 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
2169 ErrPrint("default need_frame is NIL\n");
2170 livebox->default_need_frame = 0;
2172 livebox->default_need_frame = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
2173 xmlFree(need_frame);
2177 for (node = node->children; node; node = node->next) {
2178 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2182 size = xmlNodeGetContent(node);
2184 ErrPrint("Invalid size tag\n");
2188 if (xmlHasProp(node, (const xmlChar *)"mode")) {
2190 mode = xmlGetProp(node, (const xmlChar *)"mode");
2192 DbgPrint("Easy mode: %s\n", mode);
2193 is_easy = !xmlStrcasecmp(mode, (const xmlChar *)"easy");
2198 if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
2200 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
2201 update_size_info(livebox, 9, node);
2203 livebox->size_list |= LB_SIZE_TYPE_1x1;
2204 update_size_info(livebox, 0, node);
2206 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x1")) {
2208 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
2209 update_size_info(livebox, 10, node);
2211 ErrPrint("Invalid size tag (%s)\n", size);
2213 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x3")) {
2215 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
2216 update_size_info(livebox, 11, node);
2218 ErrPrint("Invalid size tag (%s)\n", size);
2220 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
2221 livebox->size_list |= LB_SIZE_TYPE_2x1;
2222 update_size_info(livebox, 1, node);
2223 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
2224 livebox->size_list |= LB_SIZE_TYPE_2x2;
2225 update_size_info(livebox, 2, node);
2226 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
2227 livebox->size_list |= LB_SIZE_TYPE_4x1;
2228 update_size_info(livebox, 3, node);
2229 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
2230 livebox->size_list |= LB_SIZE_TYPE_4x2;
2231 update_size_info(livebox, 4, node);
2232 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
2233 livebox->size_list |= LB_SIZE_TYPE_4x3;
2234 update_size_info(livebox, 5, node);
2235 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
2236 livebox->size_list |= LB_SIZE_TYPE_4x4;
2237 update_size_info(livebox, 6, node);
2238 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x5")) {
2239 livebox->size_list |= LB_SIZE_TYPE_4x5;
2240 update_size_info(livebox, 7, node);
2241 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x6")) {
2242 livebox->size_list |= LB_SIZE_TYPE_4x6;
2243 update_size_info(livebox, 8, node);
2244 } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
2245 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
2246 update_size_info(livebox, 9, node);
2247 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
2248 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
2249 update_size_info(livebox, 10, node);
2250 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
2251 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
2252 update_size_info(livebox, 11, node);
2253 } else if (!xmlStrcasecmp(size, (const xmlChar *)"0x0")) {
2254 livebox->size_list |= LB_SIZE_TYPE_0x0;
2255 update_size_info(livebox, 12, node);
2257 ErrPrint("Invalid size tag (%s)\n", size);
2261 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2264 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2265 ErrPrint("Invalid script tag. has no src\n");
2269 src = xmlGetProp(node, (const xmlChar *)"src");
2271 ErrPrint("Invalid script tag. src is NIL\n");
2275 if (livebox->lb_src) {
2276 DbgPrint("Override lb src: %s\n", livebox->lb_src);
2277 xmlFree(livebox->lb_src);
2280 livebox->lb_src = src;
2282 if (xmlHasProp(node, (const xmlChar *)"group")) {
2284 group = xmlGetProp(node, (const xmlChar *)"group");
2286 ErrPrint("Group is NIL\n");
2288 if (livebox->lb_group) {
2289 DbgPrint("Override lb group: %s\n", livebox->lb_group);
2290 xmlFree(livebox->lb_group);
2293 livebox->lb_group = group;
2300 static inline void update_group(struct livebox *livebox, xmlNodePtr node)
2303 xmlNodePtr category;
2304 xmlNodePtr option_item;
2305 xmlChar *cluster_name;
2306 xmlChar *category_name;
2312 struct group *group;
2313 struct option *option;
2316 for (cluster = cluster->children; cluster; cluster = cluster->next) {
2317 if (xmlStrcasecmp(cluster->name, (const xmlChar *)"cluster")) {
2318 DbgPrint("Skip: %s\n", cluster->name);
2322 if (!xmlHasProp(cluster, (const xmlChar *)"name")) {
2323 ErrPrint("Invalid cluster, has no name\n");
2327 cluster_name = xmlGetProp(cluster, (const xmlChar *)"name");
2328 if (!cluster_name) {
2329 ErrPrint("Invalid cluster name. NIL\n");
2333 for (category = cluster->children; category; category = category->next) {
2334 if (xmlStrcasecmp(category->name, (const xmlChar *)"category")) {
2335 DbgPrint("Skip: %s\n", category->name);
2339 if (!xmlHasProp(category, (const xmlChar *)"name")) {
2340 ErrPrint("Invalid category, has no name\n");
2344 category_name = xmlGetProp(category, (const xmlChar *)"name");
2345 if (!category_name) {
2346 ErrPrint("Invalid category name. NIL\n");
2350 group = calloc(1, sizeof(*group));
2352 ErrPrint("Heap: %s\n", strerror(errno));
2353 xmlFree(category_name);
2357 group->cluster = xmlStrdup(cluster_name);
2358 if (!group->cluster) {
2359 ErrPrint("Heap: %s\n", strerror(errno));
2360 xmlFree(category_name);
2365 group->category = category_name;
2366 livebox->group_list = dlist_append(livebox->group_list, group);
2368 if (!xmlHasProp(category, (const xmlChar *)"context")) {
2369 DbgPrint("%s, %s has no ctx info\n", group->cluster, group->category);
2373 ctx_item = xmlGetProp(category, (const xmlChar *)"context");
2375 ErrPrint("Failed to get context ID (%s, %s)\n", group->cluster, group->category);
2379 group->ctx_item = ctx_item;
2380 DbgPrint("Build group item: %s - %s - %s\n", group->cluster, group->category, group->ctx_item);
2382 for (option_item = category->children; option_item; option_item = option_item->next) {
2383 if (xmlStrcasecmp(option_item->name, (const xmlChar *)"option")) {
2384 DbgPrint("Skip: %s\n", option_item->name);
2388 if (!xmlHasProp(option_item, (const xmlChar *)"key")) {
2389 ErrPrint("Invalid option, has no key\n");
2393 if (!xmlHasProp(option_item, (const xmlChar *)"value")) {
2394 ErrPrint("Invalid option, has no value\n");
2398 key = xmlGetProp(option_item, (const xmlChar *)"key");
2400 ErrPrint("Invalid key. NIL\n");
2404 value = xmlGetProp(option_item, (const xmlChar *)"value");
2406 ErrPrint("Invalid valid. NIL\n");
2411 option = calloc(1, sizeof(*option));
2413 ErrPrint("Heap: %s\n", strerror(errno));
2420 option->value = value;
2422 group->option_list = dlist_append(group->option_list, option);
2426 xmlFree(cluster_name);
2430 static inline void update_pd(struct livebox *livebox, xmlNodePtr node)
2432 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2433 livebox->pd_type = PD_TYPE_SCRIPT;
2437 type = xmlGetProp(node, (const xmlChar *)"type");
2439 ErrPrint("type is NIL\n");
2443 if (!xmlStrcasecmp(type, (const xmlChar *)"text")) {
2444 livebox->pd_type = PD_TYPE_TEXT;
2445 } else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer")) {
2446 livebox->pd_type = PD_TYPE_BUFFER;
2448 livebox->pd_type = PD_TYPE_SCRIPT;
2454 for (node = node->children; node; node = node->next) {
2455 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2458 size = xmlNodeGetContent(node);
2460 ErrPrint("Invalid size tag\n");
2464 if (livebox->pd_size) {
2465 DbgPrint("Override pd size: %s\n", livebox->pd_size);
2466 xmlFree(livebox->pd_size);
2468 livebox->pd_size = size;
2469 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2472 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2473 ErrPrint("Invalid script tag, has no src\n");
2477 src = xmlGetProp(node, (const xmlChar *)"src");
2479 ErrPrint("src is NIL\n");
2483 if (livebox->pd_src) {
2484 DbgPrint("Overide PD src: %s\n", livebox->pd_src);
2485 xmlFree(livebox->pd_src);
2488 livebox->pd_src = src;
2490 if (xmlHasProp(node, (const xmlChar *)"group")) {
2492 group = xmlGetProp(node, (const xmlChar *)"group");
2494 ErrPrint("Group is NIL\n");
2496 if (livebox->pd_group) {
2497 DbgPrint("Override PD group : %s\n", livebox->pd_group);
2498 xmlFree(livebox->pd_group);
2501 livebox->pd_group = group;
2508 static int db_insert_livebox(struct livebox *livebox, const char *appid)
2513 struct group *group;
2516 struct option *option;
2518 begin_transaction();
2519 ret = db_insert_pkgmap(appid, (char *)livebox->pkgid, (char *)livebox->uiapp, livebox->primary, (char *)livebox->category);
2524 ret = db_insert_provider(livebox);
2529 ret = db_insert_client(livebox);
2534 dlist_foreach(livebox->i18n_list, l, i18n) {
2535 ret = db_insert_i18n((char *)livebox->pkgid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon);
2541 if (livebox->size_list & LB_SIZE_TYPE_1x1) {
2542 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]);
2548 if (livebox->size_list & LB_SIZE_TYPE_2x1) {
2549 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]);
2555 if (livebox->size_list & LB_SIZE_TYPE_2x2) {
2556 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]);
2562 if (livebox->size_list & LB_SIZE_TYPE_4x1) {
2563 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]);
2569 if (livebox->size_list & LB_SIZE_TYPE_4x2) {
2570 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]);
2576 if (livebox->size_list & LB_SIZE_TYPE_4x3) {
2577 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]);
2583 if (livebox->size_list & LB_SIZE_TYPE_4x4) {
2584 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]);
2590 if (livebox->size_list & LB_SIZE_TYPE_4x5) {
2591 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]);
2597 if (livebox->size_list & LB_SIZE_TYPE_4x6) {
2598 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]);
2604 if (livebox->size_list & LB_SIZE_TYPE_EASY_1x1) {
2605 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]);
2611 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x1) {
2612 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]);
2618 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x3) {
2619 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]);
2625 if (livebox->size_list & LB_SIZE_TYPE_0x0) {
2626 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]);
2632 dlist_foreach(livebox->group_list, l, group) {
2634 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2638 ret = db_insert_group((char *)livebox->pkgid, (char *)group->cluster, (char *)group->category);
2640 ErrPrint("[%s]-[%s] is not exists\n", group->cluster, group->category);
2644 DbgPrint("New group name is built - %s/%s\n", group->cluster, group->category);
2645 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2647 ErrPrint("Failed to get group id for %s/%s\n", group->cluster, group->category);
2652 if (!group->ctx_item) {
2653 DbgPrint("%s, %s - has no ctx info\n", group->cluster, group->category);
2657 ret = db_insert_groupmap(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2662 /* REUSE "id" from here , option ID */
2663 id = db_get_option_id(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2668 dlist_foreach(group->option_list, il, option) {
2669 ret = db_insert_option((char *)livebox->pkgid, id, (char *)option->key, (char *)option->value);
2676 commit_transaction();
2677 livebox_destroy(livebox);
2681 ErrPrint("ROLLBACK\n");
2682 rollback_transaction();
2683 livebox_destroy(livebox);
2687 static int do_install(xmlNodePtr node, const char *appid)
2689 struct livebox *livebox;
2693 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2694 ErrPrint("Missing appid\n");
2698 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2699 if (!pkgid || !validate_pkgid(appid, (char *)pkgid)) {
2700 ErrPrint("Invalid appid\n");
2705 DbgPrint("appid: %s\n", (char *)pkgid);
2707 livebox = calloc(1, sizeof(*livebox));
2709 ErrPrint("Heap: %s\n", strerror(errno));
2714 livebox->pkgid = pkgid;
2716 if (xmlHasProp(node, (const xmlChar *)"primary")) {
2717 tmp = xmlGetProp(node, (const xmlChar *)"primary");
2718 livebox->primary = !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2722 if (xmlHasProp(node, (const xmlChar *)"script")) {
2723 livebox->script = xmlGetProp(node, (const xmlChar *)"script");
2724 if (!livebox->script) {
2725 ErrPrint("script is NIL\n");
2729 if (xmlHasProp(node, (const xmlChar *)"nodisplay")) {
2730 tmp = xmlGetProp(node, (const xmlChar *)"nodisplay");
2731 livebox->nodisplay = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2735 if (xmlHasProp(node, (const xmlChar *)"pinup")) {
2736 tmp = xmlGetProp(node, (const xmlChar *)"pinup");
2737 livebox->pinup = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2741 if (xmlHasProp(node, (const xmlChar *)"period")) {
2742 livebox->period = xmlGetProp(node, (const xmlChar *)"period");
2743 if (!livebox->period) {
2744 ErrPrint("Period is NIL\n");
2748 if (xmlHasProp(node, (const xmlChar *)"timeout")) {
2749 livebox->timeout = xmlGetProp(node, (const xmlChar *)"timeout");
2750 if (!livebox->timeout) {
2751 ErrPrint("Timeout is NIL\n");
2755 if (xmlHasProp(node, (const xmlChar *)"secured")) {
2756 tmp = xmlGetProp(node, (const xmlChar *)"secured");
2757 livebox->secured = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2761 if (xmlHasProp(node, (const xmlChar *)"network")) {
2762 tmp = xmlGetProp(node, (const xmlChar *)"network");
2763 livebox->network = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2767 if (xmlHasProp(node, (const xmlChar *)"abi")) {
2768 livebox->abi = xmlGetProp(node, (const xmlChar *)"abi");
2769 if (!livebox->abi) {
2770 ErrPrint("ABI is NIL\n");
2771 livebox_destroy(livebox);
2775 livebox->abi = xmlStrdup((const xmlChar *)"c");
2776 if (!livebox->abi) {
2777 ErrPrint("Heap: %s\n", strerror(errno));
2778 livebox_destroy(livebox);
2783 if (xmlHasProp(node, (const xmlChar *)"libexec")) {
2784 livebox->libexec = xmlGetProp(node, (const xmlChar *)"libexec");
2785 if (!livebox->libexec) {
2786 ErrPrint("libexec is NIL\n");
2787 livebox_destroy(livebox);
2790 } else if (!xmlStrcasecmp(livebox->abi, (const xmlChar *)"c") || !xmlStrcasecmp(livebox->abi, (const xmlChar *)"cpp")) {
2794 len = strlen((char *)livebox->pkgid) + strlen("/libexec/liblive-.so") + 1;
2796 filename = malloc(len);
2798 livebox_destroy(livebox);
2802 snprintf(filename, len, "/libexec/liblive-%s.so", livebox->pkgid);
2803 livebox->libexec = xmlStrdup((xmlChar *)filename);
2804 DbgPrint("Use the default libexec: %s\n", filename);
2807 if (!livebox->libexec) {
2808 livebox_destroy(livebox);
2813 for (node = node->children; node; node = node->next) {
2814 if (!xmlStrcmp(node->name, (const xmlChar *)"text")) {
2818 DbgPrint("Nodename: %s\n", node->name);
2819 if (!xmlStrcasecmp(node->name, (const xmlChar *)"label")) {
2820 update_i18n_name(livebox, node);
2824 if (!xmlStrcasecmp(node->name, (const xmlChar *)"icon")) {
2825 update_i18n_icon(livebox, node);
2829 if (!xmlStrcasecmp(node->name, (const xmlChar *)"box")) {
2830 update_box(livebox, node);
2834 if (!xmlStrcasecmp(node->name, (const xmlChar *)"pd")) {
2835 update_pd(livebox, node);
2839 if (!xmlStrcasecmp(node->name, (const xmlChar *)"group")) {
2840 update_group(livebox, node);
2844 if (!xmlStrcasecmp(node->name, (const xmlChar *)"content")) {
2845 update_content(livebox, node);
2849 if (!xmlStrcasecmp(node->name, (const xmlChar *)"setup")) {
2850 update_setup(livebox, node);
2854 if (!xmlStrcasecmp(node->name, (const xmlChar *)"launch")) {
2855 update_launch(livebox, node);
2859 if (!xmlStrcasecmp(node->name, (const xmlChar *)"ui-appid")) {
2860 update_ui_appid(livebox, node);
2864 if (!xmlStrcasecmp(node->name, (const xmlChar *)"category")) {
2865 update_category(livebox, node);
2870 return db_insert_livebox(livebox, appid);
2873 static inline int do_uninstall(xmlNodePtr node, const char *appid)
2878 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2879 ErrPrint("Missing appid\n");
2883 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2884 if (!validate_pkgid(appid, (char *)pkgid)) {
2885 ErrPrint("Invalid package\n");
2890 begin_transaction();
2891 ret = db_remove_box_size((char *)pkgid);
2896 ret = db_remove_i18n((char *)pkgid);
2901 ret = db_remove_client((char *)pkgid);
2906 ret = db_remove_provider((char *)pkgid);
2911 ret = db_remove_option((char *)pkgid);
2912 DbgPrint("Remove option: %d\n", ret);
2914 ret = db_remove_groupmap((char *)pkgid);
2915 DbgPrint("Remove groupmap: %d\n", ret);
2917 ret = db_remove_group((char *)pkgid);
2922 ret = db_remove_pkgmap((char *)pkgid);
2927 commit_transaction();
2933 rollback_transaction();
2938 static int pkglist_get_via_callback(const char *appid, void (*cb)(const char *appid, const char *pkgid, int prime, void *data), void *data)
2940 const char *dml = "SELECT pkgid, prime FROM pkgmap WHERE appid = ?";
2947 if (!cb || !appid || !strlen(appid)) {
2951 if (!s_info.handle) {
2952 if (db_init() < 0) {
2953 ErrPrint("Failed to init DB\n");
2958 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
2959 if (ret != SQLITE_OK) {
2960 ErrPrint("Failed to prepare the intial DML(%s)\n", sqlite3_errmsg(s_info.handle));
2965 if (sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
2966 ErrPrint("Failed to bind a cluster - %s\n", sqlite3_errmsg(s_info.handle));
2970 while (sqlite3_step(stmt) == SQLITE_ROW) {
2971 pkgid = (const char *)sqlite3_column_text(stmt, 0);
2972 if (!pkgid || !strlen(pkgid)) {
2976 prime = sqlite3_column_int(stmt, 1);
2977 cb(appid, pkgid, prime, data);
2982 sqlite3_reset(stmt);
2983 sqlite3_clear_bindings(stmt);
2984 sqlite3_finalize(stmt);
2988 static void clear_all_pkg(const char *appid, const char *pkgid, int prime, void *data)
2992 ErrPrintWithConsole("Remove old package info: appid(%s), pkgid(%s)\n", appid, pkgid);
2994 ret = db_remove_box_size((char *)pkgid);
2996 ErrPrint("Remove box size: %d\n", ret);
2999 ret = db_remove_i18n((char *)pkgid);
3001 ErrPrint("Remove i18n: %d\n", ret);
3004 ret = db_remove_client((char *)pkgid);
3006 ErrPrint("Remove client: %d\n", ret);
3009 ret = db_remove_provider((char *)pkgid);
3011 ErrPrint("Remove provider: %d\n", ret);
3014 ret = db_remove_option((char *)pkgid);
3016 ErrPrint("Remove option: %d\n", ret);
3019 ret = db_remove_groupmap((char *)pkgid);
3021 ErrPrint("Remove groupmap: %d\n", ret);
3024 ret = db_remove_group((char *)pkgid);
3026 ErrPrint("Remove group: %d\n", ret);
3029 ret = db_remove_pkgmap((char *)pkgid);
3031 ErrPrint("Remove pkgmap: %d\n", ret);
3035 int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *appid)
3039 ErrPrintWithConsole("%s\n", appid);
3041 if (!s_info.handle) {
3042 if (db_init() < 0) {
3043 ErrPrintWithConsole("Failed to init DB\n");
3048 do_upgrade_db_schema();
3050 begin_transaction();
3051 cnt = pkglist_get_via_callback(appid, clear_all_pkg, NULL);
3052 commit_transaction();
3055 DbgPrint("Package[%s] is not deleted: %d\n", appid, cnt);
3060 int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *appid)
3062 ErrPrintWithConsole("[%s]\n", appid);
3067 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
3072 ErrPrintWithConsole("[%s]\n", appid);
3074 if (!s_info.handle) {
3075 ErrPrintWithConsole("Failed to init DB\n");
3079 node = xmlDocGetRootElement(docPtr);
3081 ErrPrintWithConsole("Invalid document\n");
3085 for (node = node->children; node; node = node->next) {
3086 DbgPrint("node->name: %s\n", node->name);
3087 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
3088 ret = do_install(node, appid);
3090 DbgPrint("Returns: %d\n", ret);
3098 int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *appid)
3102 ErrPrintWithConsole("[%s]\n", appid);
3104 if (!s_info.handle) {
3105 if (db_init() < 0) {
3106 ErrPrint("Failed to init DB\n");
3111 do_upgrade_db_schema();
3113 begin_transaction();
3114 cnt = pkglist_get_via_callback(appid, clear_all_pkg, NULL);
3115 commit_transaction();
3118 DbgPrint("Package %s is deleted: %d\n", appid, cnt);
3123 int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *appid)
3125 ErrPrintWithConsole("[%s]\n", appid);
3130 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
3135 ErrPrintWithConsole("[%s]\n", appid);
3137 if (!s_info.handle) {
3138 ErrPrint("Failed to init DB\n");
3142 node = xmlDocGetRootElement(docPtr);
3144 ErrPrint("Invalid document\n");
3148 for (node = node->children; node; node = node->next) {
3149 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
3150 ret = do_install(node, appid);
3152 DbgPrint("Returns: %d\n", ret);
3160 int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *appid)
3162 ErrPrintWithConsole("[%s]\n", appid);
3164 if (!s_info.handle) {
3165 if (db_init() < 0) {
3166 ErrPrint("Failed to init DB\n");
3171 do_upgrade_db_schema();
3175 int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *appid)
3179 ErrPrintWithConsole("[%s]\n", appid);
3181 if (!s_info.handle) {
3185 begin_transaction();
3186 cnt = pkglist_get_via_callback(appid, clear_all_pkg, NULL);
3187 commit_transaction();
3190 DbgPrint("Package %s is deleted: %d\n", appid, cnt);
3196 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *appid)
3198 ErrPrintWithConsole("[%s]\n", appid);
3199 if (!s_info.handle) {
3202 /* Doesn't need to do anything from here, we already dealt it with this */