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)
58 * +-------+-------+-------+-------+
59 * | appid | pkgid | uiapp | prime |
60 * +-------+-------+-------+-------+
62 * +-------+-------+-------+-------+
63 * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER )
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 | mouse_event |
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 DEFAULT "default", nodisplay INTEGER, setup TEXT, mouse_event, 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 |
104 * +-------+-----------+---------+--------------+------------+
105 * | - | - | - | - | - |
106 * +-------+-----------+---------+--------------+------------+
107 * CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, INTEGER, touch_effect INTEGER, need_frame 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 */
182 int pinup; /* Is this support the pinup feature? */
183 int primary; /* Is this primary livebox? */
185 int mouse_event; /* Mouse event processing option for livebox */
187 int default_touch_effect;
188 int default_need_frame;
190 enum lb_type lb_type;
193 int size_list; /* 1x1, 2x1, 2x2, 4x1, 4x2, 4x3, 4x4 */
195 xmlChar *preview[NR_OF_SIZE_LIST];
196 int touch_effect[NR_OF_SIZE_LIST]; /* Touch effect of a livebox */
197 int need_frame[NR_OF_SIZE_LIST]; /* Box needs frame which should be cared by viewer */
199 enum pd_type pd_type;
202 xmlChar *pd_size; /* Default PD size */
204 struct dlist *i18n_list;
205 struct dlist *group_list;
212 struct dlist *option_list;
224 .dbfile = "/opt/dbspace/.livebox.db",
228 static inline int begin_transaction(void)
233 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
235 if (ret != SQLITE_OK) {
236 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
240 if (sqlite3_step(stmt) != SQLITE_DONE) {
241 DbgPrint("Failed to do update (%s)\n",
242 sqlite3_errmsg(s_info.handle));
243 sqlite3_finalize(stmt);
247 sqlite3_finalize(stmt);
251 static inline int rollback_transaction(void)
256 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
257 if (ret != SQLITE_OK) {
258 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
262 if (sqlite3_step(stmt) != SQLITE_DONE) {
263 DbgPrint("Failed to do update (%s)\n",
264 sqlite3_errmsg(s_info.handle));
265 sqlite3_finalize(stmt);
269 sqlite3_finalize(stmt);
273 static inline int commit_transaction(void)
278 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
279 if (ret != SQLITE_OK) {
280 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
284 if (sqlite3_step(stmt) != SQLITE_DONE) {
285 DbgPrint("Failed to do update (%s)\n",
286 sqlite3_errmsg(s_info.handle));
287 sqlite3_finalize(stmt);
291 sqlite3_finalize(stmt);
295 static inline int db_create_pkgmap(void)
298 static const char *ddl;
300 ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, uiapp TEXT, prime INTEGER )";
301 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
302 ErrPrint("Failed to execute the DDL (%s)\n", err);
306 if (sqlite3_changes(s_info.handle) == 0)
307 ErrPrint("No changes to DB\n");
312 static inline int db_insert_pkgmap(const char *appid, const char *pkgid, const char *uiappid, int primary)
315 static const char *dml;
319 uiappid = ""; /*!< Could we replace this with Main AppId of this package? */
321 dml = "INSERT INTO pkgmap ( appid, pkgid, uiapp, prime ) VALUES (? ,?, ?, ?)";
322 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
323 if (ret != SQLITE_OK) {
324 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
328 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
329 if (ret != SQLITE_OK) {
330 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
335 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
336 if (ret != SQLITE_OK) {
337 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
342 ret = sqlite3_bind_text(stmt, 3, uiappid, -1, SQLITE_TRANSIENT);
343 if (ret != SQLITE_OK) {
344 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
349 ret = sqlite3_bind_int(stmt, 4, primary);
350 if (ret != SQLITE_OK) {
351 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
357 if (sqlite3_step(stmt) != SQLITE_DONE) {
358 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
364 sqlite3_clear_bindings(stmt);
365 sqlite3_finalize(stmt);
369 static inline int db_remove_pkgmap(const char *pkgid)
372 static const char *dml;
375 dml = "DELETE FROM pkgmap WHERE pkgid = ?";
376 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
377 if (ret != SQLITE_OK) {
378 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
382 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
383 if (ret != SQLITE_OK) {
384 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
390 if (sqlite3_step(stmt) != SQLITE_DONE) {
391 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
397 sqlite3_clear_bindings(stmt);
398 sqlite3_finalize(stmt);
402 static inline int db_create_provider(void)
405 static const char *ddl;
407 ddl = "CREATE TABLE provider (" \
408 "pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, " \
409 "abi TEXT, secured INTEGER, box_type INTEGER, " \
410 "box_src TEXT, box_group TEXT, pd_type INTEGER, " \
411 "pd_src TEXT, pd_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, "\
412 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
414 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
415 ErrPrint("Failed to execute the DDL (%s)\n", err);
419 if (sqlite3_changes(s_info.handle) == 0)
420 ErrPrint("No changes to DB\n");
425 static inline int db_remove_provider(const char *pkgid)
427 static const char *dml;
431 dml = "DELETE FROM provider WHERE pkgid = ?";
432 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
433 if (ret != SQLITE_OK) {
434 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
438 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
439 if (ret != SQLITE_OK) {
440 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
446 if (sqlite3_step(stmt) != SQLITE_DONE) {
447 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
453 sqlite3_clear_bindings(stmt);
454 sqlite3_finalize(stmt);
457 static inline int db_insert_provider(struct livebox *livebox)
459 static const char *dml;
462 char *abi = (char *)livebox->abi;
463 char *box_src = (char *)livebox->lb_src;
464 char *box_group = (char *)livebox->lb_group;
465 char *pd_src = (char *)livebox->pd_src;
466 char *pd_group = (char *)livebox->pd_group;
467 char *libexec = (char *)livebox->libexec;
468 char *timeout = (char *)livebox->timeout;
469 char *period = (char *)livebox->period;
470 char *script = (char *)livebox->script;
499 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
500 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
501 if (ret != SQLITE_OK) {
502 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
506 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
507 if (ret != SQLITE_OK) {
508 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
514 ret = sqlite3_bind_int(stmt, 2, livebox->network);
515 if (ret != SQLITE_OK) {
516 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
521 ret = sqlite3_bind_text(stmt, 3, abi, -1, SQLITE_TRANSIENT);
522 if (ret != SQLITE_OK) {
523 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
527 ret = sqlite3_bind_int(stmt, 4, livebox->secured);
528 if (ret != SQLITE_OK) {
529 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
534 ret = sqlite3_bind_int(stmt, 5, livebox->lb_type);
535 if (ret != SQLITE_OK) {
536 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
541 ret = sqlite3_bind_text(stmt, 6, box_src, -1, SQLITE_TRANSIENT);
542 if (ret != SQLITE_OK) {
543 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
548 ret = sqlite3_bind_text(stmt, 7, box_group, -1, SQLITE_TRANSIENT);
549 if (ret != SQLITE_OK) {
550 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
555 ret = sqlite3_bind_int(stmt, 8, livebox->pd_type);
556 if (ret != SQLITE_OK) {
557 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
562 ret = sqlite3_bind_text(stmt, 9, pd_src, -1, SQLITE_TRANSIENT);
563 if (ret != SQLITE_OK) {
564 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
569 ret = sqlite3_bind_text(stmt, 10, pd_group, -1, SQLITE_TRANSIENT);
570 if (ret != SQLITE_OK) {
571 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
576 ret = sqlite3_bind_text(stmt, 11, libexec, -1, SQLITE_TRANSIENT);
577 if (ret != SQLITE_OK) {
578 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
583 ret = sqlite3_bind_int(stmt, 12, atoi(timeout));
584 if (ret != SQLITE_OK) {
585 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
590 ret = sqlite3_bind_text(stmt, 13, period, -1, SQLITE_TRANSIENT);
591 if (ret != SQLITE_OK) {
592 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
597 ret = sqlite3_bind_text(stmt, 14, script, -1, SQLITE_TRANSIENT);
598 if (ret != SQLITE_OK) {
599 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
604 ret = sqlite3_bind_int(stmt, 15, livebox->pinup);
605 if (ret != SQLITE_OK) {
606 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
612 if (sqlite3_step(stmt) != SQLITE_DONE) {
613 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
619 sqlite3_clear_bindings(stmt);
620 sqlite3_finalize(stmt);
624 static inline int db_create_client(void)
627 static const char *ddl;
629 ddl = "CREATE TABLE client (" \
630 "pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, " \
631 "auto_launch TEXT, pd_size TEXT, content TEXT DEFAULT 'default', nodisplay INTEGER, setup TEXT, mouse_event INTEGER, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
632 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
633 ErrPrint("Failed to execute the DDL (%s)\n", err);
637 if (sqlite3_changes(s_info.handle) == 0)
638 ErrPrint("No changes to DB\n");
643 static inline int db_insert_client(struct livebox *livebox)
645 static const char *dml;
649 dml = "INSERT INTO client ( pkgid, icon, name, auto_launch, pd_size, content, nodisplay, setup, mouse_event ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
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, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
657 if (ret != SQLITE_OK) {
658 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
663 ret = sqlite3_bind_text(stmt, 2, (char *)livebox->icon, -1, SQLITE_TRANSIENT);
664 if (ret != SQLITE_OK) {
665 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
670 ret = sqlite3_bind_text(stmt, 3, (char *)livebox->name, -1, SQLITE_TRANSIENT);
671 if (ret != SQLITE_OK) {
672 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
677 ret = sqlite3_bind_text(stmt, 4, (char *)livebox->auto_launch, -1, SQLITE_TRANSIENT);
678 if (ret != SQLITE_OK) {
679 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
684 ret = sqlite3_bind_text(stmt, 5, (char *)livebox->pd_size, -1, SQLITE_TRANSIENT);
685 if (ret != SQLITE_OK) {
686 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
691 ret = sqlite3_bind_text(stmt, 6, livebox->content ? (char *)livebox->content : "default", -1, SQLITE_TRANSIENT);
692 if (ret != SQLITE_OK) {
693 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
698 ret = sqlite3_bind_int(stmt, 7, livebox->nodisplay);
699 if (ret != SQLITE_OK) {
700 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
705 ret = sqlite3_bind_text(stmt, 8, livebox->setup ? (char *)livebox->setup : "", -1, SQLITE_TRANSIENT);
706 if (ret != SQLITE_OK) {
707 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
712 ret = sqlite3_bind_int(stmt, 9, livebox->mouse_event);
713 if (ret != SQLITE_OK) {
714 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
720 if (sqlite3_step(stmt) != SQLITE_DONE) {
721 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
727 sqlite3_clear_bindings(stmt);
728 sqlite3_finalize(stmt);
732 static inline int db_remove_client(const char *pkgid)
734 static const char *dml;
738 dml = "DELETE FROM client WHERE pkgid = ?";
739 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
740 if (ret != SQLITE_OK) {
741 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
745 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
746 if (ret != SQLITE_OK) {
747 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
753 if (sqlite3_step(stmt) != SQLITE_DONE) {
754 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
760 sqlite3_clear_bindings(stmt);
761 sqlite3_finalize(stmt);
765 static inline int db_create_i18n(void)
768 static const char *ddl;
770 ddl = "CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, " \
771 "icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
772 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
773 ErrPrint("Failed to execute the DDL (%s)\n", err);
777 if (sqlite3_changes(s_info.handle) == 0)
778 ErrPrint("No changes to DB\n");
783 static inline int db_insert_i18n(const char *pkgid, const char *lang, const char *name, const char *icon)
785 static const char *dml;
789 DbgPrint("%s - lang[%s] name[%s] icon[%s]\n", pkgid, lang, name, icon);
790 dml = "INSERT INTO i18n ( pkgid, lang, name, icon ) VALUES (?, ?, ?, ?)";
791 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
792 if (ret != SQLITE_OK) {
793 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
797 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
798 if (ret != SQLITE_OK) {
799 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
804 ret = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
805 if (ret != SQLITE_OK) {
806 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
811 ret = sqlite3_bind_text(stmt, 3, name, -1, SQLITE_TRANSIENT);
812 if (ret != SQLITE_OK) {
813 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
818 ret = sqlite3_bind_text(stmt, 4, icon, -1, SQLITE_TRANSIENT);
819 if (ret != SQLITE_OK) {
820 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
826 if (sqlite3_step(stmt) != SQLITE_DONE) {
827 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
833 sqlite3_clear_bindings(stmt);
834 sqlite3_finalize(stmt);
838 static inline int db_remove_i18n(const char *pkgid)
840 static const char *dml;
844 dml = "DELETE FROM i18n WHERE pkgid = ?";
845 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
846 if (ret != SQLITE_OK) {
847 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
851 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
852 if (ret != SQLITE_OK) {
853 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
859 if (sqlite3_step(stmt) != SQLITE_DONE) {
860 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
864 if (sqlite3_changes(s_info.handle) == 0)
865 DbgPrint("No changes\n");
869 sqlite3_clear_bindings(stmt);
870 sqlite3_finalize(stmt);
874 static inline int db_create_group(void)
877 static const char *ddl;
879 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)";
880 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
881 ErrPrint("Failed to execute the DDL (%s)\n", err);
885 if (sqlite3_changes(s_info.handle) == 0)
886 ErrPrint("No changes to DB\n");
891 static inline int db_insert_group(const char *pkgid, const char *cluster, const char *category)
893 static const char *dml;
897 dml = "INSERT INTO groupinfo ( cluster, category, pkgid ) VALUES (?, ?, ?)";
898 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
899 if (ret != SQLITE_OK) {
900 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
904 ret = sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT);
905 if (ret != SQLITE_OK) {
906 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
911 ret = sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT);
912 if (ret != SQLITE_OK) {
913 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
918 ret = sqlite3_bind_text(stmt, 3, pkgid, -1, SQLITE_TRANSIENT);
919 if (ret != SQLITE_OK) {
920 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
926 if (sqlite3_step(stmt) != SQLITE_DONE) {
927 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
933 sqlite3_clear_bindings(stmt);
934 sqlite3_finalize(stmt);
938 static inline int db_get_group_id(const char *cluster, const char *category)
940 static const char *dml = "SELECT id FROM groupinfo WHERE cluster = ? AND category = ?";
944 if (!cluster || !category) {
945 ErrPrint("Invalid argument\n");
949 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
950 if (ret != SQLITE_OK) {
951 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
956 if (sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
957 ErrPrint("Failed to bind a cluster(%s) - %s\n", cluster, sqlite3_errmsg(s_info.handle));
961 if (sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
962 ErrPrint("Failed to bind a category(%s) - %s\n", category, sqlite3_errmsg(s_info.handle));
966 if (sqlite3_step(stmt) != SQLITE_ROW) {
967 ErrPrint("Failed to execute the DML for %s - %s\n", cluster, category);
971 ret = sqlite3_column_int(stmt, 0);
975 sqlite3_clear_bindings(stmt);
976 sqlite3_finalize(stmt);
980 static inline int db_remove_group(const char *pkgid)
982 static const char *dml;
986 dml = "DELETE FROM groupinfo WHERE pkgid = ?";
987 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
988 if (ret != SQLITE_OK) {
989 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
993 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
994 if (ret != SQLITE_OK) {
995 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1001 if (sqlite3_step(stmt) != SQLITE_DONE) {
1002 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1006 if (sqlite3_changes(s_info.handle) == 0)
1007 DbgPrint("No changes\n");
1010 sqlite3_reset(stmt);
1011 sqlite3_clear_bindings(stmt);
1012 sqlite3_finalize(stmt);
1016 static inline int db_create_groupmap(void)
1019 static const char *ddl;
1021 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)";
1022 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1023 ErrPrint("Failed to execute the DDL (%s)\n", err);
1027 if (sqlite3_changes(s_info.handle) == 0)
1028 ErrPrint("No changes to DB\n");
1033 static inline int db_get_option_id(int id, const char *pkgid, const char *ctx_item)
1035 static const char *dml;
1039 dml = "SELECT option_id FROM groupmap WHERE id = ? AND pkgid = ? AND ctx_item = ?";
1040 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1041 if (ret != SQLITE_OK) {
1042 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1046 ret = sqlite3_bind_int(stmt, 1, id);
1047 if (ret != SQLITE_OK) {
1048 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1053 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1054 if (ret != SQLITE_OK) {
1055 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1060 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1061 if (ret != SQLITE_OK) {
1062 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1068 if (sqlite3_step(stmt) != SQLITE_ROW) {
1069 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1074 ret = sqlite3_column_int(stmt, 0);
1077 sqlite3_reset(stmt);
1078 sqlite3_clear_bindings(stmt);
1079 sqlite3_finalize(stmt);
1083 static inline int db_insert_groupmap(int id, const char *pkgid, const char *ctx_item)
1085 static const char *dml;
1089 DbgPrint("%d (%s) add to groupmap\n", id, pkgid);
1091 dml = "INSERT INTO groupmap ( id, pkgid, ctx_item ) VALUES (?, ?, ?)";
1092 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1093 if (ret != SQLITE_OK) {
1094 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1098 ret = sqlite3_bind_int(stmt, 1, id);
1099 if (ret != SQLITE_OK) {
1100 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1105 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1106 if (ret != SQLITE_OK) {
1107 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1112 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1113 if (ret != SQLITE_OK) {
1114 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1120 if (sqlite3_step(stmt) != SQLITE_DONE) {
1121 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1126 sqlite3_reset(stmt);
1127 sqlite3_clear_bindings(stmt);
1128 sqlite3_finalize(stmt);
1132 static inline int db_remove_groupmap(const char *pkgid)
1134 static const char *dml;
1138 dml = "DELETE FROM groupmap WHERE pkgid = ?";
1139 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1140 if (ret != SQLITE_OK) {
1141 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1145 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1146 if (ret != SQLITE_OK) {
1147 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1153 if (sqlite3_step(stmt) != SQLITE_DONE) {
1154 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1158 if (sqlite3_changes(s_info.handle) == 0)
1159 DbgPrint("No changes\n");
1162 sqlite3_reset(stmt);
1163 sqlite3_clear_bindings(stmt);
1164 sqlite3_finalize(stmt);
1168 static inline int db_create_option(void)
1171 static const char *ddl;
1173 ddl = "CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, " \
1174 "FOREIGN KEY(option_id) REFERENCES groupmap(option_id), " \
1175 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1176 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1177 ErrPrint("Failed to execute the DDL (%s)\n", err);
1181 if (sqlite3_changes(s_info.handle) == 0)
1182 ErrPrint("No changes to DB\n");
1187 static inline int db_insert_option(const char *pkgid, int option_id, const char *key, const char *value)
1189 static const char *dml;
1193 dml = "INSERT INTO option (pkgid, option_id, key, value) VALUES (?, ?, ?, ?)";
1194 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1195 if (ret != SQLITE_OK) {
1196 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1200 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1201 if (ret != SQLITE_OK) {
1202 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1207 ret = sqlite3_bind_int(stmt, 2, option_id);
1208 if (ret != SQLITE_OK) {
1209 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1214 ret = sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
1215 if (ret != SQLITE_OK) {
1216 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1221 ret = sqlite3_bind_text(stmt, 4, value, -1, SQLITE_TRANSIENT);
1222 if (ret != SQLITE_OK) {
1223 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1229 if (sqlite3_step(stmt) != SQLITE_DONE) {
1230 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1234 sqlite3_reset(stmt);
1235 sqlite3_clear_bindings(stmt);
1236 sqlite3_finalize(stmt);
1240 static inline int db_remove_option(const char *pkgid)
1242 static const char *dml;
1246 dml = "DELETE FROM option 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");
1270 sqlite3_reset(stmt);
1271 sqlite3_clear_bindings(stmt);
1272 sqlite3_finalize(stmt);
1276 static inline int db_create_box_size(void)
1279 static const char *ddl;
1281 ddl = "CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, touch_effect INTEGER, need_frame INTEGER, " \
1282 "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");
1294 static inline int db_insert_box_size(const char *pkgid, int size_type, const char *preview, int touch_effect, int need_frame)
1296 static const char *dml;
1300 DbgPrint("box size: %s - %d (%s) is added\n", pkgid, size_type, preview);
1301 dml = "INSERT INTO box_size ( pkgid, size_type, preview, touch_effect, need_frame ) VALUES (?, ?, ?, ?, ?)";
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_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1309 if (ret != SQLITE_OK) {
1310 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1315 ret = sqlite3_bind_int(stmt, 2, size_type);
1316 if (ret != SQLITE_OK) {
1317 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1322 ret = sqlite3_bind_text(stmt, 3, preview ? preview : "", -1, SQLITE_TRANSIENT);
1323 if (ret != SQLITE_OK) {
1324 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1329 ret = sqlite3_bind_int(stmt, 4, touch_effect);
1330 if (ret != SQLITE_OK) {
1331 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1336 ret = sqlite3_bind_int(stmt, 5, need_frame);
1337 if (ret != SQLITE_OK) {
1338 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1344 if (sqlite3_step(stmt) != SQLITE_DONE) {
1345 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1350 sqlite3_reset(stmt);
1351 sqlite3_clear_bindings(stmt);
1352 sqlite3_finalize(stmt);
1356 static inline int db_remove_box_size(const char *pkgid)
1358 static const char *dml;
1362 dml = "DELETE FROM box_size WHERE pkgid = ?";
1363 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1364 if (ret != SQLITE_OK) {
1365 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1369 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1370 if (ret != SQLITE_OK) {
1371 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1377 if (sqlite3_step(stmt) != SQLITE_DONE) {
1378 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1382 if (sqlite3_changes(s_info.handle) == 0)
1383 DbgPrint("No changes\n");
1386 sqlite3_reset(stmt);
1387 sqlite3_clear_bindings(stmt);
1388 sqlite3_finalize(stmt);
1392 static inline void db_create_table(void)
1395 begin_transaction();
1397 ret = db_create_pkgmap();
1399 rollback_transaction();
1403 ret = db_create_provider();
1405 rollback_transaction();
1409 ret = db_create_client();
1411 rollback_transaction();
1415 ret = db_create_i18n();
1417 rollback_transaction();
1421 ret = db_create_box_size();
1423 rollback_transaction();
1427 ret = db_create_group();
1429 rollback_transaction();
1433 ret = db_create_option();
1435 rollback_transaction();
1439 ret = db_create_groupmap();
1441 rollback_transaction();
1445 commit_transaction();
1448 static inline int db_init(void)
1453 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
1454 if (ret != SQLITE_OK) {
1455 ErrPrint("Failed to open a DB\n");
1459 if (lstat(s_info.dbfile, &stat) < 0) {
1460 ErrPrint("%s\n", strerror(errno));
1461 db_util_close(s_info.handle);
1462 s_info.handle = NULL;
1466 if (!S_ISREG(stat.st_mode)) {
1467 ErrPrint("Invalid file\n");
1468 db_util_close(s_info.handle);
1469 s_info.handle = NULL;
1479 static inline int db_fini(void)
1484 db_util_close(s_info.handle);
1485 s_info.handle = NULL;
1490 static inline int validate_pkgid(const char *appid, const char *pkgid)
1492 /* Just return 1 Always */
1493 return 1 || !strncmp(appid, pkgid, strlen(appid));
1496 static inline int livebox_destroy(struct livebox *livebox)
1501 struct group *group;
1502 struct option *option;
1506 xmlFree(livebox->auto_launch);
1507 xmlFree(livebox->pkgid);
1508 xmlFree(livebox->abi);
1509 xmlFree(livebox->name);
1510 xmlFree(livebox->icon);
1511 xmlFree(livebox->lb_src);
1512 xmlFree(livebox->lb_group);
1513 xmlFree(livebox->pd_src);
1514 xmlFree(livebox->pd_group);
1515 xmlFree(livebox->pd_size);
1516 xmlFree(livebox->libexec);
1517 xmlFree(livebox->script);
1518 xmlFree(livebox->period);
1519 xmlFree(livebox->content);
1520 xmlFree(livebox->setup);
1521 xmlFree(livebox->preview[0]); /* 1x1 */
1522 xmlFree(livebox->preview[1]); /* 2x1 */
1523 xmlFree(livebox->preview[2]); /* 2x2 */
1524 xmlFree(livebox->preview[3]); /* 4x1 */
1525 xmlFree(livebox->preview[4]); /* 4x2 */
1526 xmlFree(livebox->preview[5]); /* 4x3 */
1527 xmlFree(livebox->preview[6]); /* 4x4 */
1528 xmlFree(livebox->preview[7]); /* 4x5 */
1529 xmlFree(livebox->preview[8]); /* 4x6 */
1530 xmlFree(livebox->preview[9]); /* easy 1x1 */
1531 xmlFree(livebox->preview[10]); /* easy 3x1 */
1532 xmlFree(livebox->preview[11]); /* easy 3x3 */
1533 xmlFree(livebox->preview[12]); /* full */
1535 dlist_foreach_safe(livebox->i18n_list, l, n, i18n) {
1536 livebox->i18n_list = dlist_remove(livebox->i18n_list, l);
1537 xmlFree(i18n->name);
1538 xmlFree(i18n->icon);
1539 xmlFree(i18n->lang);
1543 dlist_foreach_safe(livebox->group_list, l, n, group) {
1544 livebox->group_list = dlist_remove(livebox->group_list, l);
1545 DbgPrint("Release %s/%s\n", group->cluster, group->category);
1547 if (group->ctx_item) {
1548 dlist_foreach_safe(group->option_list, il, in, option) {
1549 group->option_list = dlist_remove(group->option_list, il);
1550 DbgPrint("Release option %s(%s)\n", option->key, option->value);
1551 xmlFree(option->key);
1552 xmlFree(option->value);
1555 xmlFree(group->ctx_item);
1558 xmlFree(group->cluster);
1559 xmlFree(group->category);
1567 static inline void update_i18n_name(struct livebox *livebox, xmlNodePtr node)
1574 name = xmlNodeGetContent(node);
1576 ErrPrint("Invalid tag\n");
1580 lang = xmlNodeGetLang(node);
1582 if (livebox->name) {
1583 DbgPrint("Override default name: %s\n", livebox->name);
1584 xmlFree(livebox->name);
1587 livebox->name = name;
1591 dlist_foreach(livebox->i18n_list, l, i18n) {
1592 if (!xmlStrcasecmp(i18n->lang, lang)) {
1594 DbgPrint("Override name: %s\n", i18n->name);
1595 xmlFree(i18n->name);
1603 i18n = calloc(1, sizeof(*i18n));
1605 ErrPrint("Heap: %s\n", strerror(errno));
1613 DbgPrint("Label[%s] - [%s] added\n", i18n->lang, i18n->name);
1614 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1617 static inline void update_i18n_icon(struct livebox *livebox, xmlNodePtr node)
1624 icon = xmlNodeGetContent(node);
1626 ErrPrint("Invalid tag\n");
1630 lang = xmlNodeGetLang(node);
1632 if (livebox->icon) {
1633 DbgPrint("Override default icon: %s\n", livebox->icon);
1634 xmlFree(livebox->icon);
1637 livebox->icon = icon;
1641 dlist_foreach(livebox->i18n_list, l, i18n) {
1642 if (!xmlStrcasecmp(i18n->lang, lang)) {
1644 DbgPrint("Override icon %s for %s\n", i18n->icon, i18n->name);
1645 xmlFree(i18n->icon);
1653 i18n = calloc(1, sizeof(*i18n));
1655 ErrPrint("Heap: %s\n", strerror(errno));
1663 DbgPrint("Icon[%s] - [%s] added\n", i18n->lang, i18n->icon);
1664 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1667 static inline void update_launch(struct livebox *livebox, xmlNodePtr node)
1670 launch = xmlNodeGetContent(node);
1672 DbgPrint("Has no launch\n");
1676 livebox->auto_launch = xmlStrdup(launch);
1677 if (!livebox->auto_launch) {
1678 ErrPrint("Failed to duplicate string: %s\n", (char *)launch);
1683 static inline void update_ui_appid(struct livebox *livebox, xmlNodePtr node)
1686 uiapp = xmlNodeGetContent(node);
1688 DbgPrint("Has no valid ui-appid\n");
1692 livebox->uiapp = xmlStrdup(uiapp);
1693 if (!livebox->uiapp) {
1694 ErrPrint("Failed to duplicate string: %s\n", (char *)uiapp);
1699 static inline void update_setup(struct livebox *livebox, xmlNodePtr node)
1702 setup = xmlNodeGetContent(node);
1704 DbgPrint("Has no setup\n");
1708 livebox->setup = xmlStrdup(setup);
1709 if (!livebox->setup) {
1710 ErrPrint("Failed to duplicate string: %s\n", (char *)setup);
1715 static inline void update_content(struct livebox *livebox, xmlNodePtr node)
1718 content = xmlNodeGetContent(node);
1720 DbgPrint("Has no content\n");
1724 livebox->content = xmlStrdup(content);
1725 if (!livebox->content) {
1726 ErrPrint("Failed to duplicate string: %s\n", (char *)content);
1731 static inline void update_size_info(struct livebox *livebox, int idx, xmlNodePtr node)
1733 if (xmlHasProp(node, (const xmlChar *)"preview")) {
1734 livebox->preview[idx] = xmlGetProp(node, (const xmlChar *)"preview");
1737 if (xmlHasProp(node, (const xmlChar *)"need_frame")) {
1738 xmlChar *need_frame;
1740 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
1742 livebox->need_frame[idx] = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
1743 xmlFree(need_frame);
1745 livebox->need_frame[idx] = livebox->default_need_frame;
1748 livebox->need_frame[idx] = livebox->default_need_frame;
1751 if (xmlHasProp(node, (const xmlChar *)"touch_effect")) {
1752 xmlChar *touch_effect;
1754 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
1756 livebox->touch_effect[idx] = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
1757 xmlFree(touch_effect);
1759 livebox->touch_effect[idx] = livebox->default_touch_effect;
1762 livebox->touch_effect[idx] = livebox->default_touch_effect;
1766 static inline void update_box(struct livebox *livebox, xmlNodePtr node)
1768 if (!xmlHasProp(node, (const xmlChar *)"type")) {
1769 livebox->lb_type = LB_TYPE_FILE;
1773 type = xmlGetProp(node, (const xmlChar *)"type");
1775 ErrPrint("Type is NIL\n");
1776 livebox->lb_type = LB_TYPE_FILE;
1778 if (!xmlStrcasecmp(type, (const xmlChar *)"text"))
1779 livebox->lb_type = LB_TYPE_TEXT;
1780 else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer"))
1781 livebox->lb_type = LB_TYPE_BUFFER;
1782 else if (!xmlStrcasecmp(type, (const xmlChar *)"script"))
1783 livebox->lb_type = LB_TYPE_SCRIPT;
1785 livebox->lb_type = LB_TYPE_FILE;
1791 if (!xmlHasProp(node, (const xmlChar *)"mouse_event")) {
1792 livebox->mouse_event = 0;
1794 xmlChar *mouse_event;
1796 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
1798 ErrPrint("mouse_event is NIL\n");
1799 livebox->mouse_event = 0;
1801 livebox->mouse_event = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
1802 xmlFree(mouse_event);
1806 if (!xmlHasProp(node, (const xmlChar *)"touch_effect")) {
1807 livebox->default_touch_effect = 1;
1809 xmlChar *touch_effect;
1811 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
1812 if (!touch_effect) {
1813 ErrPrint("default touch_effect is NIL\n");
1814 livebox->default_touch_effect = 1;
1816 livebox->default_touch_effect = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
1817 xmlFree(touch_effect);
1821 if (!xmlHasProp(node, (const xmlChar *)"need_frame")) {
1822 livebox->default_need_frame = 0;
1824 xmlChar *need_frame;
1826 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
1828 ErrPrint("default need_frame is NIL\n");
1829 livebox->default_need_frame = 0;
1831 livebox->default_need_frame = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
1832 xmlFree(need_frame);
1836 for (node = node->children; node; node = node->next) {
1837 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
1841 size = xmlNodeGetContent(node);
1843 ErrPrint("Invalid size tag\n");
1847 if (xmlHasProp(node, (const xmlChar *)"mode")) {
1849 mode = xmlGetProp(node, (const xmlChar *)"mode");
1851 DbgPrint("Easy mode: %s\n", mode);
1852 is_easy = !xmlStrcasecmp(mode, (const xmlChar *)"easy");
1857 if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
1859 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
1860 update_size_info(livebox, 9, node);
1862 livebox->size_list |= LB_SIZE_TYPE_1x1;
1863 update_size_info(livebox, 0, node);
1865 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x1")) {
1867 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
1868 update_size_info(livebox, 10, node);
1870 ErrPrint("Invalid size tag (%s)\n", size);
1872 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x3")) {
1874 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
1875 update_size_info(livebox, 11, node);
1877 ErrPrint("Invalid size tag (%s)\n", size);
1879 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
1880 livebox->size_list |= LB_SIZE_TYPE_2x1;
1881 update_size_info(livebox, 1, node);
1882 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
1883 livebox->size_list |= LB_SIZE_TYPE_2x2;
1884 update_size_info(livebox, 2, node);
1885 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
1886 livebox->size_list |= LB_SIZE_TYPE_4x1;
1887 update_size_info(livebox, 3, node);
1888 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
1889 livebox->size_list |= LB_SIZE_TYPE_4x2;
1890 update_size_info(livebox, 4, node);
1891 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
1892 livebox->size_list |= LB_SIZE_TYPE_4x3;
1893 update_size_info(livebox, 5, node);
1894 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
1895 livebox->size_list |= LB_SIZE_TYPE_4x4;
1896 update_size_info(livebox, 6, node);
1897 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x5")) {
1898 livebox->size_list |= LB_SIZE_TYPE_4x5;
1899 update_size_info(livebox, 7, node);
1900 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x6")) {
1901 livebox->size_list |= LB_SIZE_TYPE_4x6;
1902 update_size_info(livebox, 8, node);
1903 } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
1904 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
1905 update_size_info(livebox, 9, node);
1906 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
1907 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
1908 update_size_info(livebox, 10, node);
1909 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
1910 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
1911 update_size_info(livebox, 11, node);
1912 } else if (!xmlStrcasecmp(size, (const xmlChar *)"0x0")) {
1913 livebox->size_list |= LB_SIZE_TYPE_0x0;
1914 update_size_info(livebox, 12, node);
1916 ErrPrint("Invalid size tag (%s)\n", size);
1920 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
1923 if (!xmlHasProp(node, (const xmlChar *)"src")) {
1924 ErrPrint("Invalid script tag. has no src\n");
1928 src = xmlGetProp(node, (const xmlChar *)"src");
1930 ErrPrint("Invalid script tag. src is NIL\n");
1934 if (livebox->lb_src) {
1935 DbgPrint("Override lb src: %s\n", livebox->lb_src);
1936 xmlFree(livebox->lb_src);
1939 livebox->lb_src = src;
1941 if (xmlHasProp(node, (const xmlChar *)"group")) {
1943 group = xmlGetProp(node, (const xmlChar *)"group");
1945 ErrPrint("Group is NIL\n");
1947 if (livebox->lb_group) {
1948 DbgPrint("Override lb group: %s\n", livebox->lb_group);
1949 xmlFree(livebox->lb_group);
1952 livebox->lb_group = group;
1959 static inline void update_group(struct livebox *livebox, xmlNodePtr node)
1962 xmlNodePtr category;
1963 xmlNodePtr option_item;
1964 xmlChar *cluster_name;
1965 xmlChar *category_name;
1971 struct group *group;
1972 struct option *option;
1975 for (cluster = cluster->children; cluster; cluster = cluster->next) {
1976 if (xmlStrcasecmp(cluster->name, (const xmlChar *)"cluster")) {
1977 DbgPrint("Skip: %s\n", cluster->name);
1981 if (!xmlHasProp(cluster, (const xmlChar *)"name")) {
1982 ErrPrint("Invalid cluster, has no name\n");
1986 cluster_name = xmlGetProp(cluster, (const xmlChar *)"name");
1987 if (!cluster_name) {
1988 ErrPrint("Invalid cluster name. NIL\n");
1992 for (category = cluster->children; category; category = category->next) {
1993 if (xmlStrcasecmp(category->name, (const xmlChar *)"category")) {
1994 DbgPrint("Skip: %s\n", category->name);
1998 if (!xmlHasProp(category, (const xmlChar *)"name")) {
1999 ErrPrint("Invalid category, has no name\n");
2003 category_name = xmlGetProp(category, (const xmlChar *)"name");
2004 if (!category_name) {
2005 ErrPrint("Invalid category name. NIL\n");
2009 group = calloc(1, sizeof(*group));
2011 ErrPrint("Heap: %s\n", strerror(errno));
2012 xmlFree(category_name);
2016 group->cluster = xmlStrdup(cluster_name);
2017 if (!group->cluster) {
2018 ErrPrint("Heap: %s\n", strerror(errno));
2019 xmlFree(category_name);
2024 group->category = category_name;
2025 livebox->group_list = dlist_append(livebox->group_list, group);
2027 if (!xmlHasProp(category, (const xmlChar *)"context")) {
2028 DbgPrint("%s, %s has no ctx info\n", group->cluster, group->category);
2032 ctx_item = xmlGetProp(category, (const xmlChar *)"context");
2034 ErrPrint("Failed to get context ID (%s, %s)\n", group->cluster, group->category);
2038 group->ctx_item = ctx_item;
2039 DbgPrint("Build group item: %s - %s - %s\n", group->cluster, group->category, group->ctx_item);
2041 for (option_item = category->children; option_item; option_item = option_item->next) {
2042 if (xmlStrcasecmp(option_item->name, (const xmlChar *)"option")) {
2043 DbgPrint("Skip: %s\n", option_item->name);
2047 if (!xmlHasProp(option_item, (const xmlChar *)"key")) {
2048 ErrPrint("Invalid option, has no key\n");
2052 if (!xmlHasProp(option_item, (const xmlChar *)"value")) {
2053 ErrPrint("Invalid option, has no value\n");
2057 key = xmlGetProp(option_item, (const xmlChar *)"key");
2059 ErrPrint("Invalid key. NIL\n");
2063 value = xmlGetProp(option_item, (const xmlChar *)"value");
2065 ErrPrint("Invalid valid. NIL\n");
2070 option = calloc(1, sizeof(*option));
2072 ErrPrint("Heap: %s\n", strerror(errno));
2079 option->value = value;
2081 group->option_list = dlist_append(group->option_list, option);
2085 xmlFree(cluster_name);
2089 static inline void update_pd(struct livebox *livebox, xmlNodePtr node)
2091 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2092 livebox->pd_type = PD_TYPE_SCRIPT;
2096 type = xmlGetProp(node, (const xmlChar *)"type");
2098 ErrPrint("type is NIL\n");
2102 if (!xmlStrcasecmp(type, (const xmlChar *)"text"))
2103 livebox->pd_type = PD_TYPE_TEXT;
2104 else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer"))
2105 livebox->pd_type = PD_TYPE_BUFFER;
2107 livebox->pd_type = PD_TYPE_SCRIPT;
2112 for (node = node->children; node; node = node->next) {
2113 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2116 size = xmlNodeGetContent(node);
2118 ErrPrint("Invalid size tag\n");
2122 if (livebox->pd_size) {
2123 DbgPrint("Override pd size: %s\n", livebox->pd_size);
2124 xmlFree(livebox->pd_size);
2126 livebox->pd_size = size;
2127 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2130 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2131 ErrPrint("Invalid script tag, has no src\n");
2135 src = xmlGetProp(node, (const xmlChar *)"src");
2137 ErrPrint("src is NIL\n");
2141 if (livebox->pd_src) {
2142 DbgPrint("Overide PD src: %s\n", livebox->pd_src);
2143 xmlFree(livebox->pd_src);
2146 livebox->pd_src = src;
2148 if (xmlHasProp(node, (const xmlChar *)"group")) {
2150 group = xmlGetProp(node, (const xmlChar *)"group");
2152 ErrPrint("Group is NIL\n");
2154 if (livebox->pd_group) {
2155 DbgPrint("Override PD group : %s\n", livebox->pd_group);
2156 xmlFree(livebox->pd_group);
2159 livebox->pd_group = group;
2166 static inline int db_insert_livebox(struct livebox *livebox, const char *appid)
2171 struct group *group;
2174 struct option *option;
2176 begin_transaction();
2177 ret = db_insert_pkgmap(appid, (char *)livebox->pkgid, (char *)livebox->uiapp, livebox->primary);
2181 ret = db_insert_provider(livebox);
2185 ret = db_insert_client(livebox);
2189 dlist_foreach(livebox->i18n_list, l, i18n) {
2190 ret = db_insert_i18n((char *)livebox->pkgid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon);
2195 if (livebox->size_list & LB_SIZE_TYPE_1x1) {
2196 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_1x1, (char *)livebox->preview[0], livebox->touch_effect[0], livebox->need_frame[0]);
2201 if (livebox->size_list & LB_SIZE_TYPE_2x1) {
2202 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x1, (char *)livebox->preview[1], livebox->touch_effect[1], livebox->need_frame[1]);
2207 if (livebox->size_list & LB_SIZE_TYPE_2x2) {
2208 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x2, (char *)livebox->preview[2], livebox->touch_effect[2], livebox->need_frame[2]);
2213 if (livebox->size_list & LB_SIZE_TYPE_4x1) {
2214 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x1, (char *)livebox->preview[3], livebox->touch_effect[3], livebox->need_frame[3]);
2219 if (livebox->size_list & LB_SIZE_TYPE_4x2) {
2220 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x2, (char *)livebox->preview[4], livebox->touch_effect[4], livebox->need_frame[4]);
2225 if (livebox->size_list & LB_SIZE_TYPE_4x3) {
2226 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x3, (char *)livebox->preview[5], livebox->touch_effect[5], livebox->need_frame[5]);
2231 if (livebox->size_list & LB_SIZE_TYPE_4x4) {
2232 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x4, (char *)livebox->preview[6], livebox->touch_effect[6], livebox->need_frame[6]);
2237 if (livebox->size_list & LB_SIZE_TYPE_4x5) {
2238 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x5, (char *)livebox->preview[7], livebox->touch_effect[7], livebox->need_frame[7]);
2243 if (livebox->size_list & LB_SIZE_TYPE_4x6) {
2244 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x6, (char *)livebox->preview[8], livebox->touch_effect[8], livebox->need_frame[8]);
2249 if (livebox->size_list & LB_SIZE_TYPE_EASY_1x1) {
2250 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]);
2255 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x1) {
2256 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]);
2261 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x3) {
2262 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]);
2267 if (livebox->size_list & LB_SIZE_TYPE_0x0) {
2268 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_0x0, (char *)livebox->preview[12], livebox->touch_effect[12], livebox->need_frame[12]);
2273 dlist_foreach(livebox->group_list, l, group) {
2275 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2279 ret = db_insert_group((char *)livebox->pkgid, (char *)group->cluster, (char *)group->category);
2281 ErrPrint("[%s]-[%s] is not exists\n", group->cluster, group->category);
2285 DbgPrint("New group name is built - %s/%s\n", group->cluster, group->category);
2286 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2288 ErrPrint("Failed to get group id for %s/%s\n", group->cluster, group->category);
2293 if (!group->ctx_item) {
2294 DbgPrint("%s, %s - has no ctx info\n", group->cluster, group->category);
2298 ret = db_insert_groupmap(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2302 /* REUSE "id" from here , option ID */
2303 id = db_get_option_id(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2307 dlist_foreach(group->option_list, il, option) {
2308 ret = db_insert_option((char *)livebox->pkgid, id, (char *)option->key, (char *)option->value);
2314 commit_transaction();
2315 livebox_destroy(livebox);
2319 ErrPrint("ROLLBACK\n");
2320 rollback_transaction();
2321 livebox_destroy(livebox);
2325 static inline int do_install(xmlNodePtr node, const char *appid)
2327 struct livebox *livebox;
2331 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2332 ErrPrint("Missing appid\n");
2336 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2337 if (!pkgid || !validate_pkgid(appid, (char *)pkgid)) {
2338 ErrPrint("Invalid appid\n");
2343 DbgPrint("appid: %s\n", (char *)pkgid);
2345 livebox = calloc(1, sizeof(*livebox));
2347 ErrPrint("Heap: %s\n", strerror(errno));
2352 livebox->pkgid = pkgid;
2354 if (xmlHasProp(node, (const xmlChar *)"primary")) {
2355 tmp = xmlGetProp(node, (const xmlChar *)"primary");
2356 livebox->primary = !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2360 if (xmlHasProp(node, (const xmlChar *)"script")) {
2361 livebox->script = xmlGetProp(node, (const xmlChar *)"script");
2362 if (!livebox->script)
2363 ErrPrint("script is NIL\n");
2366 if (xmlHasProp(node, (const xmlChar *)"nodisplay")) {
2367 tmp = xmlGetProp(node, (const xmlChar *)"nodisplay");
2368 livebox->nodisplay = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2372 if (xmlHasProp(node, (const xmlChar *)"pinup")) {
2373 tmp = xmlGetProp(node, (const xmlChar *)"pinup");
2374 livebox->pinup = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2378 if (xmlHasProp(node, (const xmlChar *)"period")) {
2379 livebox->period = xmlGetProp(node, (const xmlChar *)"period");
2380 if (!livebox->period)
2381 ErrPrint("Period is NIL\n");
2384 if (xmlHasProp(node, (const xmlChar *)"timeout")) {
2385 livebox->timeout = xmlGetProp(node, (const xmlChar *)"timeout");
2386 if (!livebox->timeout)
2387 ErrPrint("Timeout is NIL\n");
2390 if (xmlHasProp(node, (const xmlChar *)"secured")) {
2391 tmp = xmlGetProp(node, (const xmlChar *)"secured");
2392 livebox->secured = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2396 if (xmlHasProp(node, (const xmlChar *)"network")) {
2397 tmp = xmlGetProp(node, (const xmlChar *)"network");
2398 livebox->network = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2402 if (xmlHasProp(node, (const xmlChar *)"abi")) {
2403 livebox->abi = xmlGetProp(node, (const xmlChar *)"abi");
2404 if (!livebox->abi) {
2405 ErrPrint("ABI is NIL\n");
2406 livebox_destroy(livebox);
2410 livebox->abi = xmlStrdup((const xmlChar *)"c");
2411 if (!livebox->abi) {
2412 ErrPrint("Heap: %s\n", strerror(errno));
2413 livebox_destroy(livebox);
2418 if (xmlHasProp(node, (const xmlChar *)"libexec")) {
2419 livebox->libexec = xmlGetProp(node, (const xmlChar *)"libexec");
2420 if (!livebox->libexec) {
2421 ErrPrint("libexec is NIL\n");
2422 livebox_destroy(livebox);
2425 } else if (!xmlStrcasecmp(livebox->abi, (const xmlChar *)"c") || !xmlStrcasecmp(livebox->abi, (const xmlChar *)"cpp")) {
2429 len = strlen((char *)livebox->pkgid) + strlen("/libexec/liblive-.so") + 1;
2431 filename = malloc(len);
2433 livebox_destroy(livebox);
2437 snprintf(filename, len, "/libexec/liblive-%s.so", livebox->pkgid);
2438 livebox->libexec = xmlStrdup((xmlChar *)filename);
2439 DbgPrint("Use the default libexec: %s\n", filename);
2442 if (!livebox->libexec) {
2443 livebox_destroy(livebox);
2448 for (node = node->children; node; node = node->next) {
2449 if (!xmlStrcmp(node->name, (const xmlChar *)"text"))
2452 DbgPrint("Nodename: %s\n", node->name);
2453 if (!xmlStrcasecmp(node->name, (const xmlChar *)"label")) {
2454 update_i18n_name(livebox, node);
2458 if (!xmlStrcasecmp(node->name, (const xmlChar *)"icon")) {
2459 update_i18n_icon(livebox, node);
2463 if (!xmlStrcasecmp(node->name, (const xmlChar *)"box")) {
2464 update_box(livebox, node);
2468 if (!xmlStrcasecmp(node->name, (const xmlChar *)"pd")) {
2469 update_pd(livebox, node);
2473 if (!xmlStrcasecmp(node->name, (const xmlChar *)"group")) {
2474 update_group(livebox, node);
2478 if (!xmlStrcasecmp(node->name, (const xmlChar *)"content")) {
2479 update_content(livebox, node);
2483 if (!xmlStrcasecmp(node->name, (const xmlChar *)"setup")) {
2484 update_setup(livebox, node);
2488 if (!xmlStrcasecmp(node->name, (const xmlChar *)"launch")) {
2489 update_launch(livebox, node);
2493 if (!xmlStrcasecmp(node->name, (const xmlChar *)"ui-appid")) {
2494 update_ui_appid(livebox, node);
2499 return db_insert_livebox(livebox, appid);
2502 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
2507 if (!s_info.handle) {
2508 if (db_init() < 0) {
2509 ErrPrint("Failed to init DB\n");
2514 node = xmlDocGetRootElement(docPtr);
2516 ErrPrint("Invalid document\n");
2520 for (node = node->children; node; node = node->next) {
2521 DbgPrint("node->name: %s\n", node->name);
2522 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
2523 ret = do_install(node, appid);
2524 DbgPrint("Returns: %d\n", ret);
2531 static inline int do_uninstall(xmlNodePtr node, const char *appid)
2536 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2537 ErrPrint("Missing appid\n");
2541 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2542 if (!validate_pkgid(appid, (char *)pkgid)) {
2543 ErrPrint("Invalid package\n");
2548 begin_transaction();
2549 ret = db_remove_box_size((char *)pkgid);
2553 ret = db_remove_i18n((char *)pkgid);
2557 ret = db_remove_client((char *)pkgid);
2561 ret = db_remove_provider((char *)pkgid);
2565 ret = db_remove_option((char *)pkgid);
2566 DbgPrint("Remove option: %d\n", ret);
2568 ret = db_remove_groupmap((char *)pkgid);
2569 DbgPrint("Remove groupmap: %d\n", ret);
2571 ret = db_remove_group((char *)pkgid);
2575 ret = db_remove_pkgmap((char *)pkgid);
2579 commit_transaction();
2585 rollback_transaction();
2590 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
2595 if (!s_info.handle) {
2596 if (db_init() < 0) {
2597 ErrPrint("Failed to init DB\n");
2602 node = xmlDocGetRootElement(docPtr);
2604 ErrPrint("Invalid document\n");
2608 for (node = node->children; node; node = node->next) {
2609 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
2610 ret = do_uninstall(node, appid);
2611 ret = do_install(node, appid);
2612 DbgPrint("Returns: %d\n", ret);
2619 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *appid)
2624 if (!s_info.handle) {
2625 if (db_init() < 0) {
2626 ErrPrint("Failed to init DB\n");
2631 node = xmlDocGetRootElement(docPtr);
2633 ErrPrint("Invalid document\n");
2637 for (node = node->children; node; node = node->next) {
2638 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
2639 ret = do_uninstall(node, appid);
2640 DbgPrint("Returns: %d\n", ret);