2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <sys/types.h>
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
31 #include <livebox-service.h>
36 #define DbgPrint(format, arg...) LOGD("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
37 #define ErrPrint(format, arg...) LOGE("[
\e[32m%s/%s
\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg)
46 * +-------+-------+---------+
47 * | appid | pkgid | prime |
48 * +-------+-------+---------+
50 * +-------+-------+---------+
51 * CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, prime INTEGER )
55 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
56 * | pkgid | network | abi | secured | box_type | box_src | box_group | pd_type | pd_src | pd_group | libexec | timeout | period | script | pinup |
57 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
58 * | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
59 * +-------+---------+-----+---------+----------+---------+-----------+---------+--------+----------+---------+---------+--------+--------+-------+
60 * 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))
62 * = box_type = { text | buffer | script | image }
63 * = pd_type = { text | buffer | script }
64 * = network = { 1 | 0 }
65 * = secured = { 1 | 0 }
69 * +-------+------+---------+-------------+---------+---------+-----------+-------+-------------+
70 * | pkgid | Icon | Name | auto_launch | pd_size | content | nodisplay | setup | mouse_event |
71 * +-------+------+---------+-------------+---------+---------+-----------+-------+-------------+
72 * | - | - | - | - | - | - | - | - | - }
73 * +-------+------+---------+-------------+---------+---------+-----------+-------+-------------+
74 * 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) )
76 * = auto_launch = UI-APPID
77 * = pd_size = WIDTHxHEIGHT
81 * +-------+------+------+------+
82 * | fk | lang | name | icon |
83 * +-------+------+------+------+
84 * | pkgid | - | - | - |
85 * +-------+------+------+------+
86 * CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) )
90 * +-------+-----------+---------+--------------+------------+
91 * | pkgid | size_type | preview | touch_effect | need_frame |
92 * +-------+-----------+---------+--------------+------------+
93 * | - | - | - | - | - |
94 * +-------+-----------+---------+--------------+------------+
95 * 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) )
97 * = box_size_list = { WIDTHxHEIGHT; WIDTHxHEIGHT; ... }
100 * +----+---------+----------+-------+
101 * | id | cluster | category | pkgid |
102 * +----+---------+----------+-------+
104 * +----+---------+----------+-------|
105 * 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) ))
108 * +-------+----+----------+-----------+
109 * | pkgid | id | ctx_item | option_id |
110 * +-------+----+----------+-----------+
111 * 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) )
115 * +-------+-----------+-----+-------+
116 * | pkgid | option_id | key | value |
117 * +-------+-----------+-----+-------+
118 * 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) )
121 #if !defined(LIBXML_TREE_ENABLED)
122 #error "LIBXML is not supporting the tree"
129 #define LOG_TAG "PKGMGR_LIVEBOX"
158 xmlChar *auto_launch;
160 xmlChar *name; /* Default name */
161 xmlChar *icon; /* Default icon */
162 xmlChar *libexec; /* Path of the SO file */
163 xmlChar *timeout; /* INTEGER, timeout */
164 xmlChar *period; /* DOUBLE, update period */
165 xmlChar *script; /* Script engine */
166 xmlChar *content; /* Content information */
169 int pinup; /* Is this support the pinup feature? */
170 int primary; /* Is this primary livebox? */
172 int mouse_event; /* Mouse event processing option for livebox */
174 int default_touch_effect;
175 int default_need_frame;
177 enum lb_type lb_type;
180 int size_list; /* 1x1, 2x1, 2x2, 4x1, 4x2, 4x3, 4x4 */
182 xmlChar *preview[NR_OF_SIZE_LIST];
183 int touch_effect[NR_OF_SIZE_LIST]; /* Touch effect of a livebox */
184 int need_frame[NR_OF_SIZE_LIST]; /* Box needs frame which should be cared by viewer */
186 enum pd_type pd_type;
189 xmlChar *pd_size; /* Default PD size */
191 struct dlist *i18n_list;
192 struct dlist *group_list;
199 struct dlist *option_list;
211 .dbfile = "/opt/dbspace/.livebox.db",
215 static inline int begin_transaction(void)
220 ret = sqlite3_prepare_v2(s_info.handle, "BEGIN TRANSACTION", -1, &stmt, NULL);
222 if (ret != SQLITE_OK) {
223 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
227 if (sqlite3_step(stmt) != SQLITE_DONE) {
228 DbgPrint("Failed to do update (%s)\n",
229 sqlite3_errmsg(s_info.handle));
230 sqlite3_finalize(stmt);
234 sqlite3_finalize(stmt);
238 static inline int rollback_transaction(void)
243 ret = sqlite3_prepare_v2(s_info.handle, "ROLLBACK TRANSACTION", -1, &stmt, NULL);
244 if (ret != SQLITE_OK) {
245 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
249 if (sqlite3_step(stmt) != SQLITE_DONE) {
250 DbgPrint("Failed to do update (%s)\n",
251 sqlite3_errmsg(s_info.handle));
252 sqlite3_finalize(stmt);
256 sqlite3_finalize(stmt);
260 static inline int commit_transaction(void)
265 ret = sqlite3_prepare_v2(s_info.handle, "COMMIT TRANSACTION", -1, &stmt, NULL);
266 if (ret != SQLITE_OK) {
267 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
271 if (sqlite3_step(stmt) != SQLITE_DONE) {
272 DbgPrint("Failed to do update (%s)\n",
273 sqlite3_errmsg(s_info.handle));
274 sqlite3_finalize(stmt);
278 sqlite3_finalize(stmt);
282 static inline int db_create_pkgmap(void)
285 static const char *ddl;
287 ddl = "CREATE TABLE pkgmap ( pkgid TEXT PRIMARY KEY NOT NULL, appid TEXT, prime INTEGER )";
288 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
289 ErrPrint("Failed to execute the DDL (%s)\n", err);
293 if (sqlite3_changes(s_info.handle) == 0)
294 ErrPrint("No changes to DB\n");
299 static inline int db_insert_pkgmap(const char *appid, const char *pkgid, int primary)
302 static const char *dml;
305 dml = "INSERT INTO pkgmap ( appid, pkgid, prime ) VALUES (? ,?, ?)";
306 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
307 if (ret != SQLITE_OK) {
308 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
312 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
313 if (ret != SQLITE_OK) {
314 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
319 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
320 if (ret != SQLITE_OK) {
321 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
326 ret = sqlite3_bind_int(stmt, 3, primary);
327 if (ret != SQLITE_OK) {
328 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
334 if (sqlite3_step(stmt) != SQLITE_DONE) {
335 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
341 sqlite3_clear_bindings(stmt);
342 sqlite3_finalize(stmt);
346 static inline int db_remove_pkgmap(const char *pkgid)
349 static const char *dml;
352 dml = "DELETE FROM pkgmap WHERE pkgid = ?";
353 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
354 if (ret != SQLITE_OK) {
355 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
359 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
360 if (ret != SQLITE_OK) {
361 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
367 if (sqlite3_step(stmt) != SQLITE_DONE) {
368 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
374 sqlite3_clear_bindings(stmt);
375 sqlite3_finalize(stmt);
379 static inline int db_create_provider(void)
382 static const char *ddl;
384 ddl = "CREATE TABLE provider (" \
385 "pkgid TEXT PRIMARY KEY NOT NULL, network INTEGER, " \
386 "abi TEXT, secured INTEGER, box_type INTEGER, " \
387 "box_src TEXT, box_group TEXT, pd_type INTEGER, " \
388 "pd_src TEXT, pd_group TEXT, libexec TEXT, timeout INTEGER, period TEXT, script TEXT, pinup INTEGER, "\
389 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
391 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
392 ErrPrint("Failed to execute the DDL (%s)\n", err);
396 if (sqlite3_changes(s_info.handle) == 0)
397 ErrPrint("No changes to DB\n");
402 static inline int db_remove_provider(const char *pkgid)
404 static const char *dml;
408 dml = "DELETE FROM provider WHERE pkgid = ?";
409 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
410 if (ret != SQLITE_OK) {
411 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
415 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
416 if (ret != SQLITE_OK) {
417 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
423 if (sqlite3_step(stmt) != SQLITE_DONE) {
424 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
430 sqlite3_clear_bindings(stmt);
431 sqlite3_finalize(stmt);
434 static inline int db_insert_provider(struct livebox *livebox)
436 static const char *dml;
439 char *abi = (char *)livebox->abi;
440 char *box_src = (char *)livebox->lb_src;
441 char *box_group = (char *)livebox->lb_group;
442 char *pd_src = (char *)livebox->pd_src;
443 char *pd_group = (char *)livebox->pd_group;
444 char *libexec = (char *)livebox->libexec;
445 char *timeout = (char *)livebox->timeout;
446 char *period = (char *)livebox->period;
447 char *script = (char *)livebox->script;
476 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
477 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
478 if (ret != SQLITE_OK) {
479 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
483 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
484 if (ret != SQLITE_OK) {
485 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
491 ret = sqlite3_bind_int(stmt, 2, livebox->network);
492 if (ret != SQLITE_OK) {
493 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
498 ret = sqlite3_bind_text(stmt, 3, abi, -1, SQLITE_TRANSIENT);
499 if (ret != SQLITE_OK) {
500 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
504 ret = sqlite3_bind_int(stmt, 4, livebox->secured);
505 if (ret != SQLITE_OK) {
506 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
511 ret = sqlite3_bind_int(stmt, 5, livebox->lb_type);
512 if (ret != SQLITE_OK) {
513 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
518 ret = sqlite3_bind_text(stmt, 6, box_src, -1, SQLITE_TRANSIENT);
519 if (ret != SQLITE_OK) {
520 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
525 ret = sqlite3_bind_text(stmt, 7, box_group, -1, SQLITE_TRANSIENT);
526 if (ret != SQLITE_OK) {
527 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
532 ret = sqlite3_bind_int(stmt, 8, livebox->pd_type);
533 if (ret != SQLITE_OK) {
534 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
539 ret = sqlite3_bind_text(stmt, 9, pd_src, -1, SQLITE_TRANSIENT);
540 if (ret != SQLITE_OK) {
541 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
546 ret = sqlite3_bind_text(stmt, 10, pd_group, -1, SQLITE_TRANSIENT);
547 if (ret != SQLITE_OK) {
548 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
553 ret = sqlite3_bind_text(stmt, 11, libexec, -1, SQLITE_TRANSIENT);
554 if (ret != SQLITE_OK) {
555 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
560 ret = sqlite3_bind_int(stmt, 12, atoi(timeout));
561 if (ret != SQLITE_OK) {
562 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
567 ret = sqlite3_bind_text(stmt, 13, period, -1, SQLITE_TRANSIENT);
568 if (ret != SQLITE_OK) {
569 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
574 ret = sqlite3_bind_text(stmt, 14, script, -1, SQLITE_TRANSIENT);
575 if (ret != SQLITE_OK) {
576 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
581 ret = sqlite3_bind_int(stmt, 15, livebox->pinup);
582 if (ret != SQLITE_OK) {
583 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
589 if (sqlite3_step(stmt) != SQLITE_DONE) {
590 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
596 sqlite3_clear_bindings(stmt);
597 sqlite3_finalize(stmt);
601 static inline int db_create_client(void)
604 static const char *ddl;
606 ddl = "CREATE TABLE client (" \
607 "pkgid TEXT PRIMARY KEY NOT NULL, icon TEXT, name TEXT, " \
608 "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)";
609 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
610 ErrPrint("Failed to execute the DDL (%s)\n", err);
614 if (sqlite3_changes(s_info.handle) == 0)
615 ErrPrint("No changes to DB\n");
620 static inline int db_insert_client(struct livebox *livebox)
622 static const char *dml;
626 dml = "INSERT INTO client ( pkgid, icon, name, auto_launch, pd_size, content, nodisplay, setup, mouse_event ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
627 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
628 if (ret != SQLITE_OK) {
629 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
633 ret = sqlite3_bind_text(stmt, 1, (char *)livebox->pkgid, -1, SQLITE_TRANSIENT);
634 if (ret != SQLITE_OK) {
635 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
640 ret = sqlite3_bind_text(stmt, 2, (char *)livebox->icon, -1, SQLITE_TRANSIENT);
641 if (ret != SQLITE_OK) {
642 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
647 ret = sqlite3_bind_text(stmt, 3, (char *)livebox->name, -1, SQLITE_TRANSIENT);
648 if (ret != SQLITE_OK) {
649 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
654 ret = sqlite3_bind_text(stmt, 4, (char *)livebox->auto_launch, -1, SQLITE_TRANSIENT);
655 if (ret != SQLITE_OK) {
656 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
661 ret = sqlite3_bind_text(stmt, 5, (char *)livebox->pd_size, -1, SQLITE_TRANSIENT);
662 if (ret != SQLITE_OK) {
663 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
668 ret = sqlite3_bind_text(stmt, 6, livebox->content ? (char *)livebox->content : "default", -1, SQLITE_TRANSIENT);
669 if (ret != SQLITE_OK) {
670 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
675 ret = sqlite3_bind_int(stmt, 7, livebox->nodisplay);
676 if (ret != SQLITE_OK) {
677 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
682 ret = sqlite3_bind_text(stmt, 8, livebox->setup ? (char *)livebox->setup : "", -1, SQLITE_TRANSIENT);
683 if (ret != SQLITE_OK) {
684 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
689 ret = sqlite3_bind_int(stmt, 9, livebox->mouse_event);
690 if (ret != SQLITE_OK) {
691 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
697 if (sqlite3_step(stmt) != SQLITE_DONE) {
698 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
704 sqlite3_clear_bindings(stmt);
705 sqlite3_finalize(stmt);
709 static inline int db_remove_client(const char *pkgid)
711 static const char *dml;
715 dml = "DELETE FROM client WHERE pkgid = ?";
716 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
717 if (ret != SQLITE_OK) {
718 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
722 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
723 if (ret != SQLITE_OK) {
724 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
730 if (sqlite3_step(stmt) != SQLITE_DONE) {
731 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
737 sqlite3_clear_bindings(stmt);
738 sqlite3_finalize(stmt);
742 static inline int db_create_i18n(void)
745 static const char *ddl;
747 ddl = "CREATE TABLE i18n ( pkgid TEXT NOT NULL, lang TEXT COLLATE NOCASE, name TEXT, " \
748 "icon TEXT, FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
749 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
750 ErrPrint("Failed to execute the DDL (%s)\n", err);
754 if (sqlite3_changes(s_info.handle) == 0)
755 ErrPrint("No changes to DB\n");
760 static inline int db_insert_i18n(const char *pkgid, const char *lang, const char *name, const char *icon)
762 static const char *dml;
766 DbgPrint("%s - lang[%s] name[%s] icon[%s]\n", pkgid, lang, name, icon);
767 dml = "INSERT INTO i18n ( pkgid, lang, name, icon ) VALUES (?, ?, ?, ?)";
768 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
769 if (ret != SQLITE_OK) {
770 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
774 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
775 if (ret != SQLITE_OK) {
776 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
781 ret = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT);
782 if (ret != SQLITE_OK) {
783 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
788 ret = sqlite3_bind_text(stmt, 3, name, -1, SQLITE_TRANSIENT);
789 if (ret != SQLITE_OK) {
790 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
795 ret = sqlite3_bind_text(stmt, 4, icon, -1, SQLITE_TRANSIENT);
796 if (ret != SQLITE_OK) {
797 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
803 if (sqlite3_step(stmt) != SQLITE_DONE) {
804 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
810 sqlite3_clear_bindings(stmt);
811 sqlite3_finalize(stmt);
815 static inline int db_remove_i18n(const char *pkgid)
817 static const char *dml;
821 dml = "DELETE FROM i18n WHERE pkgid = ?";
822 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
823 if (ret != SQLITE_OK) {
824 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
828 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
829 if (ret != SQLITE_OK) {
830 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
836 if (sqlite3_step(stmt) != SQLITE_DONE) {
837 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
841 if (sqlite3_changes(s_info.handle) == 0)
842 DbgPrint("No changes\n");
846 sqlite3_clear_bindings(stmt);
847 sqlite3_finalize(stmt);
851 static inline int db_create_group(void)
854 static const char *ddl;
856 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)";
857 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
858 ErrPrint("Failed to execute the DDL (%s)\n", err);
862 if (sqlite3_changes(s_info.handle) == 0)
863 ErrPrint("No changes to DB\n");
868 static inline int db_insert_group(const char *pkgid, const char *cluster, const char *category)
870 static const char *dml;
874 dml = "INSERT INTO groupinfo ( cluster, category, pkgid ) VALUES (?, ?, ?)";
875 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
876 if (ret != SQLITE_OK) {
877 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
881 ret = sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT);
882 if (ret != SQLITE_OK) {
883 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
888 ret = sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT);
889 if (ret != SQLITE_OK) {
890 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
895 ret = sqlite3_bind_text(stmt, 3, pkgid, -1, SQLITE_TRANSIENT);
896 if (ret != SQLITE_OK) {
897 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
903 if (sqlite3_step(stmt) != SQLITE_DONE) {
904 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
910 sqlite3_clear_bindings(stmt);
911 sqlite3_finalize(stmt);
915 static inline int db_get_group_id(const char *cluster, const char *category)
917 static const char *dml = "SELECT id FROM groupinfo WHERE cluster = ? AND category = ?";
921 if (!cluster || !category) {
922 ErrPrint("Invalid argument\n");
926 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
927 if (ret != SQLITE_OK) {
928 ErrPrint("Failed to prepare the initial DML(%s)\n", sqlite3_errmsg(s_info.handle));
933 if (sqlite3_bind_text(stmt, 1, cluster, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
934 ErrPrint("Failed to bind a cluster(%s) - %s\n", cluster, sqlite3_errmsg(s_info.handle));
938 if (sqlite3_bind_text(stmt, 2, category, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
939 ErrPrint("Failed to bind a category(%s) - %s\n", category, sqlite3_errmsg(s_info.handle));
943 if (sqlite3_step(stmt) != SQLITE_ROW) {
944 ErrPrint("Failed to execute the DML for %s - %s\n", cluster, category);
948 ret = sqlite3_column_int(stmt, 0);
952 sqlite3_clear_bindings(stmt);
953 sqlite3_finalize(stmt);
957 static inline int db_remove_group(const char *pkgid)
959 static const char *dml;
963 dml = "DELETE FROM groupinfo WHERE pkgid = ?";
964 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
965 if (ret != SQLITE_OK) {
966 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
970 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
971 if (ret != SQLITE_OK) {
972 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
978 if (sqlite3_step(stmt) != SQLITE_DONE) {
979 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
983 if (sqlite3_changes(s_info.handle) == 0)
984 DbgPrint("No changes\n");
988 sqlite3_clear_bindings(stmt);
989 sqlite3_finalize(stmt);
993 static inline int db_create_groupmap(void)
996 static const char *ddl;
998 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)";
999 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1000 ErrPrint("Failed to execute the DDL (%s)\n", err);
1004 if (sqlite3_changes(s_info.handle) == 0)
1005 ErrPrint("No changes to DB\n");
1010 static inline int db_get_option_id(int id, const char *pkgid, const char *ctx_item)
1012 static const char *dml;
1016 dml = "SELECT option_id FROM groupmap WHERE id = ? AND pkgid = ? AND ctx_item = ?";
1017 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1018 if (ret != SQLITE_OK) {
1019 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1023 ret = sqlite3_bind_int(stmt, 1, id);
1024 if (ret != SQLITE_OK) {
1025 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1030 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1031 if (ret != SQLITE_OK) {
1032 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1037 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1038 if (ret != SQLITE_OK) {
1039 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1045 if (sqlite3_step(stmt) != SQLITE_ROW) {
1046 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1051 ret = sqlite3_column_int(stmt, 0);
1054 sqlite3_reset(stmt);
1055 sqlite3_clear_bindings(stmt);
1056 sqlite3_finalize(stmt);
1060 static inline int db_insert_groupmap(int id, const char *pkgid, const char *ctx_item)
1062 static const char *dml;
1066 DbgPrint("%d (%s) add to groupmap\n", id, pkgid);
1068 dml = "INSERT INTO groupmap ( id, pkgid, ctx_item ) VALUES (?, ?, ?)";
1069 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1070 if (ret != SQLITE_OK) {
1071 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1075 ret = sqlite3_bind_int(stmt, 1, id);
1076 if (ret != SQLITE_OK) {
1077 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1082 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1083 if (ret != SQLITE_OK) {
1084 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1089 ret = sqlite3_bind_text(stmt, 3, ctx_item, -1, SQLITE_TRANSIENT);
1090 if (ret != SQLITE_OK) {
1091 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1097 if (sqlite3_step(stmt) != SQLITE_DONE) {
1098 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1103 sqlite3_reset(stmt);
1104 sqlite3_clear_bindings(stmt);
1105 sqlite3_finalize(stmt);
1109 static inline int db_remove_groupmap(const char *pkgid)
1111 static const char *dml;
1115 dml = "DELETE FROM groupmap WHERE pkgid = ?";
1116 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1117 if (ret != SQLITE_OK) {
1118 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1122 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1123 if (ret != SQLITE_OK) {
1124 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1130 if (sqlite3_step(stmt) != SQLITE_DONE) {
1131 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1135 if (sqlite3_changes(s_info.handle) == 0)
1136 DbgPrint("No changes\n");
1139 sqlite3_reset(stmt);
1140 sqlite3_clear_bindings(stmt);
1141 sqlite3_finalize(stmt);
1145 static inline int db_create_option(void)
1148 static const char *ddl;
1150 ddl = "CREATE TABLE option ( pkgid TEXT NOT NULL, option_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL, " \
1151 "FOREIGN KEY(option_id) REFERENCES groupmap(option_id), " \
1152 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1153 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1154 ErrPrint("Failed to execute the DDL (%s)\n", err);
1158 if (sqlite3_changes(s_info.handle) == 0)
1159 ErrPrint("No changes to DB\n");
1164 static inline int db_insert_option(const char *pkgid, int option_id, const char *key, const char *value)
1166 static const char *dml;
1170 dml = "INSERT INTO option (pkgid, option_id, key, value) VALUES (?, ?, ?, ?)";
1171 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1172 if (ret != SQLITE_OK) {
1173 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1177 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1178 if (ret != SQLITE_OK) {
1179 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1184 ret = sqlite3_bind_int(stmt, 2, option_id);
1185 if (ret != SQLITE_OK) {
1186 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1191 ret = sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
1192 if (ret != SQLITE_OK) {
1193 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1198 ret = sqlite3_bind_text(stmt, 4, value, -1, SQLITE_TRANSIENT);
1199 if (ret != SQLITE_OK) {
1200 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1206 if (sqlite3_step(stmt) != SQLITE_DONE) {
1207 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1211 sqlite3_reset(stmt);
1212 sqlite3_clear_bindings(stmt);
1213 sqlite3_finalize(stmt);
1217 static inline int db_remove_option(const char *pkgid)
1219 static const char *dml;
1223 dml = "DELETE FROM option WHERE pkgid = ?";
1224 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1225 if (ret != SQLITE_OK) {
1226 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1230 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1231 if (ret != SQLITE_OK) {
1232 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1238 if (sqlite3_step(stmt) != SQLITE_DONE) {
1239 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1243 if (sqlite3_changes(s_info.handle) == 0)
1244 DbgPrint("No changes\n");
1247 sqlite3_reset(stmt);
1248 sqlite3_clear_bindings(stmt);
1249 sqlite3_finalize(stmt);
1253 static inline int db_create_box_size(void)
1256 static const char *ddl;
1258 ddl = "CREATE TABLE box_size ( pkgid TEXT NOT NULL, size_type INTEGER, preview TEXT, touch_effect INTEGER, need_frame INTEGER, " \
1259 "FOREIGN KEY(pkgid) REFERENCES pkgmap(pkgid) ON DELETE CASCADE)";
1260 if (sqlite3_exec(s_info.handle, ddl, NULL, NULL, &err) != SQLITE_OK) {
1261 ErrPrint("Failed to execute the DDL (%s)\n", err);
1265 if (sqlite3_changes(s_info.handle) == 0)
1266 ErrPrint("No changes to DB\n");
1271 static inline int db_insert_box_size(const char *pkgid, int size_type, const char *preview, int touch_effect, int need_frame)
1273 static const char *dml;
1277 DbgPrint("box size: %s - %d (%s) is added\n", pkgid, size_type, preview);
1278 dml = "INSERT INTO box_size ( pkgid, size_type, preview, touch_effect, need_frame ) VALUES (?, ?, ?, ?, ?)";
1279 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1280 if (ret != SQLITE_OK) {
1281 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1285 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1286 if (ret != SQLITE_OK) {
1287 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1292 ret = sqlite3_bind_int(stmt, 2, size_type);
1293 if (ret != SQLITE_OK) {
1294 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1299 ret = sqlite3_bind_text(stmt, 3, preview ? preview : "", -1, SQLITE_TRANSIENT);
1300 if (ret != SQLITE_OK) {
1301 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1306 ret = sqlite3_bind_int(stmt, 4, touch_effect);
1307 if (ret != SQLITE_OK) {
1308 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1313 ret = sqlite3_bind_int(stmt, 5, need_frame);
1314 if (ret != SQLITE_OK) {
1315 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1321 if (sqlite3_step(stmt) != SQLITE_DONE) {
1322 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1327 sqlite3_reset(stmt);
1328 sqlite3_clear_bindings(stmt);
1329 sqlite3_finalize(stmt);
1333 static inline int db_remove_box_size(const char *pkgid)
1335 static const char *dml;
1339 dml = "DELETE FROM box_size WHERE pkgid = ?";
1340 ret = sqlite3_prepare_v2(s_info.handle, dml, -1, &stmt, NULL);
1341 if (ret != SQLITE_OK) {
1342 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1346 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1347 if (ret != SQLITE_OK) {
1348 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1354 if (sqlite3_step(stmt) != SQLITE_DONE) {
1355 DbgPrint("Error: %s\n", sqlite3_errmsg(s_info.handle));
1359 if (sqlite3_changes(s_info.handle) == 0)
1360 DbgPrint("No changes\n");
1363 sqlite3_reset(stmt);
1364 sqlite3_clear_bindings(stmt);
1365 sqlite3_finalize(stmt);
1369 static inline void db_create_table(void)
1372 begin_transaction();
1374 ret = db_create_pkgmap();
1376 rollback_transaction();
1380 ret = db_create_provider();
1382 rollback_transaction();
1386 ret = db_create_client();
1388 rollback_transaction();
1392 ret = db_create_i18n();
1394 rollback_transaction();
1398 ret = db_create_box_size();
1400 rollback_transaction();
1404 ret = db_create_group();
1406 rollback_transaction();
1410 ret = db_create_option();
1412 rollback_transaction();
1416 ret = db_create_groupmap();
1418 rollback_transaction();
1422 commit_transaction();
1425 static inline int db_init(void)
1430 ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
1431 if (ret != SQLITE_OK) {
1432 ErrPrint("Failed to open a DB\n");
1436 if (lstat(s_info.dbfile, &stat) < 0) {
1437 ErrPrint("%s\n", strerror(errno));
1438 db_util_close(s_info.handle);
1439 s_info.handle = NULL;
1443 if (!S_ISREG(stat.st_mode)) {
1444 ErrPrint("Invalid file\n");
1445 db_util_close(s_info.handle);
1446 s_info.handle = NULL;
1456 static inline int db_fini(void)
1461 db_util_close(s_info.handle);
1462 s_info.handle = NULL;
1467 static inline int validate_pkgid(const char *appid, const char *pkgid)
1469 /* Just return 1 Always */
1470 return 1 || !strncmp(appid, pkgid, strlen(appid));
1473 static inline int livebox_destroy(struct livebox *livebox)
1478 struct group *group;
1479 struct option *option;
1483 xmlFree(livebox->auto_launch);
1484 xmlFree(livebox->pkgid);
1485 xmlFree(livebox->abi);
1486 xmlFree(livebox->name);
1487 xmlFree(livebox->icon);
1488 xmlFree(livebox->lb_src);
1489 xmlFree(livebox->lb_group);
1490 xmlFree(livebox->pd_src);
1491 xmlFree(livebox->pd_group);
1492 xmlFree(livebox->pd_size);
1493 xmlFree(livebox->libexec);
1494 xmlFree(livebox->script);
1495 xmlFree(livebox->period);
1496 xmlFree(livebox->content);
1497 xmlFree(livebox->setup);
1498 xmlFree(livebox->preview[0]); /* 1x1 */
1499 xmlFree(livebox->preview[1]); /* 2x1 */
1500 xmlFree(livebox->preview[2]); /* 2x2 */
1501 xmlFree(livebox->preview[3]); /* 4x1 */
1502 xmlFree(livebox->preview[4]); /* 4x2 */
1503 xmlFree(livebox->preview[5]); /* 4x3 */
1504 xmlFree(livebox->preview[6]); /* 4x4 */
1505 xmlFree(livebox->preview[7]); /* 4x5 */
1506 xmlFree(livebox->preview[8]); /* 4x6 */
1507 xmlFree(livebox->preview[9]); /* easy 1x1 */
1508 xmlFree(livebox->preview[10]); /* easy 3x1 */
1509 xmlFree(livebox->preview[11]); /* easy 3x3 */
1510 xmlFree(livebox->preview[12]); /* full */
1512 dlist_foreach_safe(livebox->i18n_list, l, n, i18n) {
1513 livebox->i18n_list = dlist_remove(livebox->i18n_list, l);
1514 xmlFree(i18n->name);
1515 xmlFree(i18n->icon);
1516 xmlFree(i18n->lang);
1520 dlist_foreach_safe(livebox->group_list, l, n, group) {
1521 livebox->group_list = dlist_remove(livebox->group_list, l);
1522 DbgPrint("Release %s/%s\n", group->cluster, group->category);
1524 if (group->ctx_item) {
1525 dlist_foreach_safe(group->option_list, il, in, option) {
1526 group->option_list = dlist_remove(group->option_list, il);
1527 DbgPrint("Release option %s(%s)\n", option->key, option->value);
1528 xmlFree(option->key);
1529 xmlFree(option->value);
1532 xmlFree(group->ctx_item);
1535 xmlFree(group->cluster);
1536 xmlFree(group->category);
1544 static inline void update_i18n_name(struct livebox *livebox, xmlNodePtr node)
1551 name = xmlNodeGetContent(node);
1553 ErrPrint("Invalid tag\n");
1557 lang = xmlNodeGetLang(node);
1559 if (livebox->name) {
1560 DbgPrint("Override default name: %s\n", livebox->name);
1561 xmlFree(livebox->name);
1564 livebox->name = name;
1568 dlist_foreach(livebox->i18n_list, l, i18n) {
1569 if (!xmlStrcasecmp(i18n->lang, lang)) {
1571 DbgPrint("Override name: %s\n", i18n->name);
1572 xmlFree(i18n->name);
1580 i18n = calloc(1, sizeof(*i18n));
1582 ErrPrint("Heap: %s\n", strerror(errno));
1590 DbgPrint("Label[%s] - [%s] added\n", i18n->lang, i18n->name);
1591 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1594 static inline void update_i18n_icon(struct livebox *livebox, xmlNodePtr node)
1601 icon = xmlNodeGetContent(node);
1603 ErrPrint("Invalid tag\n");
1607 lang = xmlNodeGetLang(node);
1609 if (livebox->icon) {
1610 DbgPrint("Override default icon: %s\n", livebox->icon);
1611 xmlFree(livebox->icon);
1614 livebox->icon = icon;
1618 dlist_foreach(livebox->i18n_list, l, i18n) {
1619 if (!xmlStrcasecmp(i18n->lang, lang)) {
1621 DbgPrint("Override icon %s for %s\n", i18n->icon, i18n->name);
1622 xmlFree(i18n->icon);
1630 i18n = calloc(1, sizeof(*i18n));
1632 ErrPrint("Heap: %s\n", strerror(errno));
1640 DbgPrint("Icon[%s] - [%s] added\n", i18n->lang, i18n->icon);
1641 livebox->i18n_list = dlist_append(livebox->i18n_list, i18n);
1644 static inline void update_launch(struct livebox *livebox, xmlNodePtr node)
1647 launch = xmlNodeGetContent(node);
1649 DbgPrint("Has no launch\n");
1653 livebox->auto_launch = xmlStrdup(launch);
1654 if (!livebox->auto_launch) {
1655 ErrPrint("Failed to duplicate string: %s\n", (char *)launch);
1660 static inline void update_setup(struct livebox *livebox, xmlNodePtr node)
1663 setup = xmlNodeGetContent(node);
1665 DbgPrint("Has no setup\n");
1669 livebox->setup = xmlStrdup(setup);
1670 if (!livebox->setup) {
1671 ErrPrint("Failed to duplicate string: %s\n", (char *)setup);
1676 static inline void update_content(struct livebox *livebox, xmlNodePtr node)
1679 content = xmlNodeGetContent(node);
1681 DbgPrint("Has no content\n");
1685 livebox->content = xmlStrdup(content);
1686 if (!livebox->content) {
1687 ErrPrint("Failed to duplicate string: %s\n", (char *)content);
1692 static inline void update_size_info(struct livebox *livebox, int idx, xmlNodePtr node)
1694 if (xmlHasProp(node, (const xmlChar *)"preview")) {
1695 livebox->preview[idx] = xmlGetProp(node, (const xmlChar *)"preview");
1698 if (xmlHasProp(node, (const xmlChar *)"need_frame")) {
1699 xmlChar *need_frame;
1701 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
1703 livebox->need_frame[idx] = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
1704 xmlFree(need_frame);
1706 livebox->need_frame[idx] = livebox->default_need_frame;
1709 livebox->need_frame[idx] = livebox->default_need_frame;
1712 if (xmlHasProp(node, (const xmlChar *)"touch_effect")) {
1713 xmlChar *touch_effect;
1715 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
1717 livebox->touch_effect[idx] = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
1718 xmlFree(touch_effect);
1720 livebox->touch_effect[idx] = livebox->default_touch_effect;
1723 livebox->touch_effect[idx] = livebox->default_touch_effect;
1727 static inline void update_box(struct livebox *livebox, xmlNodePtr node)
1729 if (!xmlHasProp(node, (const xmlChar *)"type")) {
1730 livebox->lb_type = LB_TYPE_FILE;
1734 type = xmlGetProp(node, (const xmlChar *)"type");
1736 ErrPrint("Type is NIL\n");
1737 livebox->lb_type = LB_TYPE_FILE;
1739 if (!xmlStrcasecmp(type, (const xmlChar *)"text"))
1740 livebox->lb_type = LB_TYPE_TEXT;
1741 else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer"))
1742 livebox->lb_type = LB_TYPE_BUFFER;
1743 else if (!xmlStrcasecmp(type, (const xmlChar *)"script"))
1744 livebox->lb_type = LB_TYPE_SCRIPT;
1746 livebox->lb_type = LB_TYPE_FILE;
1752 if (!xmlHasProp(node, (const xmlChar *)"mouse_event")) {
1753 livebox->mouse_event = 0;
1755 xmlChar *mouse_event;
1757 mouse_event = xmlGetProp(node, (const xmlChar *)"mouse_event");
1759 ErrPrint("mouse_event is NIL\n");
1760 livebox->mouse_event = 0;
1762 livebox->mouse_event = !xmlStrcasecmp(mouse_event, (const xmlChar *)"true");
1763 xmlFree(mouse_event);
1767 if (!xmlHasProp(node, (const xmlChar *)"touch_effect")) {
1768 livebox->default_touch_effect = 1;
1770 xmlChar *touch_effect;
1772 touch_effect = xmlGetProp(node, (const xmlChar *)"touch_effect");
1773 if (!touch_effect) {
1774 ErrPrint("default touch_effect is NIL\n");
1775 livebox->default_touch_effect = 1;
1777 livebox->default_touch_effect = !xmlStrcasecmp(touch_effect, (const xmlChar *)"true");
1778 xmlFree(touch_effect);
1782 if (!xmlHasProp(node, (const xmlChar *)"need_frame")) {
1783 livebox->default_need_frame = 0;
1785 xmlChar *need_frame;
1787 need_frame = xmlGetProp(node, (const xmlChar *)"need_frame");
1789 ErrPrint("default need_frame is NIL\n");
1790 livebox->default_need_frame = 0;
1792 livebox->default_need_frame = !xmlStrcasecmp(need_frame, (const xmlChar *)"true");
1793 xmlFree(need_frame);
1797 for (node = node->children; node; node = node->next) {
1798 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
1802 size = xmlNodeGetContent(node);
1804 ErrPrint("Invalid size tag\n");
1808 if (xmlHasProp(node, (const xmlChar *)"mode")) {
1810 mode = xmlGetProp(node, (const xmlChar *)"mode");
1812 DbgPrint("Easy mode: %s\n", mode);
1813 is_easy = !xmlStrcasecmp(mode, (const xmlChar *)"easy");
1818 if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
1820 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
1821 update_size_info(livebox, 9, node);
1823 livebox->size_list |= LB_SIZE_TYPE_1x1;
1824 update_size_info(livebox, 0, node);
1826 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x1")) {
1828 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
1829 update_size_info(livebox, 10, node);
1831 ErrPrint("Invalid size tag (%s)\n", size);
1833 } else if (!xmlStrcasecmp(size, (const xmlChar *)"3x3")) {
1835 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
1836 update_size_info(livebox, 11, node);
1838 ErrPrint("Invalid size tag (%s)\n", size);
1840 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
1841 livebox->size_list |= LB_SIZE_TYPE_2x1;
1842 update_size_info(livebox, 1, node);
1843 } else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
1844 livebox->size_list |= LB_SIZE_TYPE_2x2;
1845 update_size_info(livebox, 2, node);
1846 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
1847 livebox->size_list |= LB_SIZE_TYPE_4x1;
1848 update_size_info(livebox, 3, node);
1849 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
1850 livebox->size_list |= LB_SIZE_TYPE_4x2;
1851 update_size_info(livebox, 4, node);
1852 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
1853 livebox->size_list |= LB_SIZE_TYPE_4x3;
1854 update_size_info(livebox, 5, node);
1855 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
1856 livebox->size_list |= LB_SIZE_TYPE_4x4;
1857 update_size_info(livebox, 6, node);
1858 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x5")) {
1859 livebox->size_list |= LB_SIZE_TYPE_4x5;
1860 update_size_info(livebox, 7, node);
1861 } else if (!xmlStrcasecmp(size, (const xmlChar *)"4x6")) {
1862 livebox->size_list |= LB_SIZE_TYPE_4x6;
1863 update_size_info(livebox, 8, node);
1864 } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
1865 livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
1866 update_size_info(livebox, 9, node);
1867 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
1868 livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
1869 update_size_info(livebox, 10, node);
1870 } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
1871 livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
1872 update_size_info(livebox, 11, node);
1873 } else if (!xmlStrcasecmp(size, (const xmlChar *)"0x0")) {
1874 livebox->size_list |= LB_SIZE_TYPE_0x0;
1875 update_size_info(livebox, 12, node);
1877 ErrPrint("Invalid size tag (%s)\n", size);
1881 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
1884 if (!xmlHasProp(node, (const xmlChar *)"src")) {
1885 ErrPrint("Invalid script tag. has no src\n");
1889 src = xmlGetProp(node, (const xmlChar *)"src");
1891 ErrPrint("Invalid script tag. src is NIL\n");
1895 if (livebox->lb_src) {
1896 DbgPrint("Override lb src: %s\n", livebox->lb_src);
1897 xmlFree(livebox->lb_src);
1900 livebox->lb_src = src;
1902 if (xmlHasProp(node, (const xmlChar *)"group")) {
1904 group = xmlGetProp(node, (const xmlChar *)"group");
1906 ErrPrint("Group is NIL\n");
1908 if (livebox->lb_group) {
1909 DbgPrint("Override lb group: %s\n", livebox->lb_group);
1910 xmlFree(livebox->lb_group);
1913 livebox->lb_group = group;
1920 static inline void update_group(struct livebox *livebox, xmlNodePtr node)
1923 xmlNodePtr category;
1924 xmlNodePtr option_item;
1925 xmlChar *cluster_name;
1926 xmlChar *category_name;
1932 struct group *group;
1933 struct option *option;
1936 for (cluster = cluster->children; cluster; cluster = cluster->next) {
1937 if (xmlStrcasecmp(cluster->name, (const xmlChar *)"cluster")) {
1938 DbgPrint("Skip: %s\n", cluster->name);
1942 if (!xmlHasProp(cluster, (const xmlChar *)"name")) {
1943 ErrPrint("Invalid cluster, has no name\n");
1947 cluster_name = xmlGetProp(cluster, (const xmlChar *)"name");
1948 if (!cluster_name) {
1949 ErrPrint("Invalid cluster name. NIL\n");
1953 for (category = cluster->children; category; category = category->next) {
1954 if (xmlStrcasecmp(category->name, (const xmlChar *)"category")) {
1955 DbgPrint("Skip: %s\n", category->name);
1959 if (!xmlHasProp(category, (const xmlChar *)"name")) {
1960 ErrPrint("Invalid category, has no name\n");
1964 category_name = xmlGetProp(category, (const xmlChar *)"name");
1965 if (!category_name) {
1966 ErrPrint("Invalid category name. NIL\n");
1970 group = calloc(1, sizeof(*group));
1972 ErrPrint("Heap: %s\n", strerror(errno));
1973 xmlFree(category_name);
1977 group->cluster = xmlStrdup(cluster_name);
1978 if (!group->cluster) {
1979 ErrPrint("Heap: %s\n", strerror(errno));
1980 xmlFree(category_name);
1985 group->category = category_name;
1986 livebox->group_list = dlist_append(livebox->group_list, group);
1988 if (!xmlHasProp(category, (const xmlChar *)"context")) {
1989 DbgPrint("%s, %s has no ctx info\n", group->cluster, group->category);
1993 ctx_item = xmlGetProp(category, (const xmlChar *)"context");
1995 ErrPrint("Failed to get context ID (%s, %s)\n", group->cluster, group->category);
1999 group->ctx_item = ctx_item;
2000 DbgPrint("Build group item: %s - %s - %s\n", group->cluster, group->category, group->ctx_item);
2002 for (option_item = category->children; option_item; option_item = option_item->next) {
2003 if (xmlStrcasecmp(option_item->name, (const xmlChar *)"option")) {
2004 DbgPrint("Skip: %s\n", option_item->name);
2008 if (!xmlHasProp(option_item, (const xmlChar *)"key")) {
2009 ErrPrint("Invalid option, has no key\n");
2013 if (!xmlHasProp(option_item, (const xmlChar *)"value")) {
2014 ErrPrint("Invalid option, has no value\n");
2018 key = xmlGetProp(option_item, (const xmlChar *)"key");
2020 ErrPrint("Invalid key. NIL\n");
2024 value = xmlGetProp(option_item, (const xmlChar *)"value");
2026 ErrPrint("Invalid valid. NIL\n");
2031 option = calloc(1, sizeof(*option));
2033 ErrPrint("Heap: %s\n", strerror(errno));
2040 option->value = value;
2042 group->option_list = dlist_append(group->option_list, option);
2046 xmlFree(cluster_name);
2050 static inline void update_pd(struct livebox *livebox, xmlNodePtr node)
2052 if (!xmlHasProp(node, (const xmlChar *)"type")) {
2053 livebox->pd_type = PD_TYPE_SCRIPT;
2057 type = xmlGetProp(node, (const xmlChar *)"type");
2059 ErrPrint("type is NIL\n");
2063 if (!xmlStrcasecmp(type, (const xmlChar *)"text"))
2064 livebox->pd_type = PD_TYPE_TEXT;
2065 else if (!xmlStrcasecmp(type, (const xmlChar *)"buffer"))
2066 livebox->pd_type = PD_TYPE_BUFFER;
2068 livebox->pd_type = PD_TYPE_SCRIPT;
2073 for (node = node->children; node; node = node->next) {
2074 if (!xmlStrcasecmp(node->name, (const xmlChar *)"size")) {
2077 size = xmlNodeGetContent(node);
2079 ErrPrint("Invalid size tag\n");
2083 if (livebox->pd_size) {
2084 DbgPrint("Override pd size: %s\n", livebox->pd_size);
2085 xmlFree(livebox->pd_size);
2087 livebox->pd_size = size;
2088 } else if (!xmlStrcasecmp(node->name, (const xmlChar *)"script")) {
2091 if (!xmlHasProp(node, (const xmlChar *)"src")) {
2092 ErrPrint("Invalid script tag, has no src\n");
2096 src = xmlGetProp(node, (const xmlChar *)"src");
2098 ErrPrint("src is NIL\n");
2102 if (livebox->pd_src) {
2103 DbgPrint("Overide PD src: %s\n", livebox->pd_src);
2104 xmlFree(livebox->pd_src);
2107 livebox->pd_src = src;
2109 if (xmlHasProp(node, (const xmlChar *)"group")) {
2111 group = xmlGetProp(node, (const xmlChar *)"group");
2113 ErrPrint("Group is NIL\n");
2115 if (livebox->pd_group) {
2116 DbgPrint("Override PD group : %s\n", livebox->pd_group);
2117 xmlFree(livebox->pd_group);
2120 livebox->pd_group = group;
2127 static inline int db_insert_livebox(struct livebox *livebox, const char *appid)
2132 struct group *group;
2135 struct option *option;
2137 begin_transaction();
2138 ret = db_insert_pkgmap(appid, (char *)livebox->pkgid, livebox->primary);
2142 ret = db_insert_provider(livebox);
2146 ret = db_insert_client(livebox);
2150 dlist_foreach(livebox->i18n_list, l, i18n) {
2151 ret = db_insert_i18n((char *)livebox->pkgid, (char *)i18n->lang, (char *)i18n->name, (char *)i18n->icon);
2156 if (livebox->size_list & LB_SIZE_TYPE_1x1) {
2157 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_1x1, (char *)livebox->preview[0], livebox->touch_effect[0], livebox->need_frame[0]);
2162 if (livebox->size_list & LB_SIZE_TYPE_2x1) {
2163 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x1, (char *)livebox->preview[1], livebox->touch_effect[1], livebox->need_frame[1]);
2168 if (livebox->size_list & LB_SIZE_TYPE_2x2) {
2169 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x2, (char *)livebox->preview[2], livebox->touch_effect[2], livebox->need_frame[2]);
2174 if (livebox->size_list & LB_SIZE_TYPE_4x1) {
2175 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x1, (char *)livebox->preview[3], livebox->touch_effect[3], livebox->need_frame[3]);
2180 if (livebox->size_list & LB_SIZE_TYPE_4x2) {
2181 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x2, (char *)livebox->preview[4], livebox->touch_effect[4], livebox->need_frame[4]);
2186 if (livebox->size_list & LB_SIZE_TYPE_4x3) {
2187 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x3, (char *)livebox->preview[5], livebox->touch_effect[5], livebox->need_frame[5]);
2192 if (livebox->size_list & LB_SIZE_TYPE_4x4) {
2193 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x4, (char *)livebox->preview[6], livebox->touch_effect[6], livebox->need_frame[6]);
2198 if (livebox->size_list & LB_SIZE_TYPE_4x5) {
2199 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x5, (char *)livebox->preview[7], livebox->touch_effect[7], livebox->need_frame[7]);
2204 if (livebox->size_list & LB_SIZE_TYPE_4x6) {
2205 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x6, (char *)livebox->preview[8], livebox->touch_effect[8], livebox->need_frame[8]);
2210 if (livebox->size_list & LB_SIZE_TYPE_EASY_1x1) {
2211 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]);
2216 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x1) {
2217 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]);
2222 if (livebox->size_list & LB_SIZE_TYPE_EASY_3x3) {
2223 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]);
2228 if (livebox->size_list & LB_SIZE_TYPE_0x0) {
2229 ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_0x0, (char *)livebox->preview[12], livebox->touch_effect[12], livebox->need_frame[12]);
2234 dlist_foreach(livebox->group_list, l, group) {
2236 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2240 ret = db_insert_group((char *)livebox->pkgid, (char *)group->cluster, (char *)group->category);
2242 ErrPrint("[%s]-[%s] is not exists\n", group->cluster, group->category);
2246 DbgPrint("New group name is built - %s/%s\n", group->cluster, group->category);
2247 id = db_get_group_id((char *)group->cluster, (char *)group->category);
2249 ErrPrint("Failed to get group id for %s/%s\n", group->cluster, group->category);
2254 if (!group->ctx_item) {
2255 DbgPrint("%s, %s - has no ctx info\n", group->cluster, group->category);
2259 ret = db_insert_groupmap(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2263 /* REUSE "id" from here , option ID */
2264 id = db_get_option_id(id, (char *)livebox->pkgid, (char *)group->ctx_item);
2268 dlist_foreach(group->option_list, il, option) {
2269 ret = db_insert_option((char *)livebox->pkgid, id, (char *)option->key, (char *)option->value);
2275 commit_transaction();
2276 livebox_destroy(livebox);
2280 ErrPrint("ROLLBACK\n");
2281 rollback_transaction();
2282 livebox_destroy(livebox);
2286 static inline int do_install(xmlNodePtr node, const char *appid)
2288 struct livebox *livebox;
2292 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2293 ErrPrint("Missing appid\n");
2297 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2298 if (!pkgid || !validate_pkgid(appid, (char *)pkgid)) {
2299 ErrPrint("Invalid appid\n");
2304 DbgPrint("appid: %s\n", (char *)pkgid);
2306 livebox = calloc(1, sizeof(*livebox));
2308 ErrPrint("Heap: %s\n", strerror(errno));
2313 livebox->pkgid = pkgid;
2315 if (xmlHasProp(node, (const xmlChar *)"primary")) {
2316 tmp = xmlGetProp(node, (const xmlChar *)"primary");
2317 livebox->primary = !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2321 if (xmlHasProp(node, (const xmlChar *)"script")) {
2322 livebox->script = xmlGetProp(node, (const xmlChar *)"script");
2323 if (!livebox->script)
2324 ErrPrint("script is NIL\n");
2327 if (xmlHasProp(node, (const xmlChar *)"nodisplay")) {
2328 tmp = xmlGetProp(node, (const xmlChar *)"nodisplay");
2329 livebox->nodisplay = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2333 if (xmlHasProp(node, (const xmlChar *)"pinup")) {
2334 tmp = xmlGetProp(node, (const xmlChar *)"pinup");
2335 livebox->pinup = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2339 if (xmlHasProp(node, (const xmlChar *)"period")) {
2340 livebox->period = xmlGetProp(node, (const xmlChar *)"period");
2341 if (!livebox->period)
2342 ErrPrint("Period is NIL\n");
2345 if (xmlHasProp(node, (const xmlChar *)"timeout")) {
2346 livebox->timeout = xmlGetProp(node, (const xmlChar *)"timeout");
2347 if (!livebox->timeout)
2348 ErrPrint("Timeout is NIL\n");
2351 if (xmlHasProp(node, (const xmlChar *)"secured")) {
2352 tmp = xmlGetProp(node, (const xmlChar *)"secured");
2353 livebox->secured = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2357 if (xmlHasProp(node, (const xmlChar *)"network")) {
2358 tmp = xmlGetProp(node, (const xmlChar *)"network");
2359 livebox->network = tmp && !xmlStrcasecmp(tmp, (const xmlChar *)"true");
2363 if (xmlHasProp(node, (const xmlChar *)"abi")) {
2364 livebox->abi = xmlGetProp(node, (const xmlChar *)"abi");
2365 if (!livebox->abi) {
2366 ErrPrint("ABI is NIL\n");
2367 livebox_destroy(livebox);
2371 livebox->abi = xmlStrdup((const xmlChar *)"c");
2372 if (!livebox->abi) {
2373 ErrPrint("Heap: %s\n", strerror(errno));
2374 livebox_destroy(livebox);
2379 if (xmlHasProp(node, (const xmlChar *)"libexec")) {
2380 livebox->libexec = xmlGetProp(node, (const xmlChar *)"libexec");
2381 if (!livebox->libexec) {
2382 ErrPrint("libexec is NIL\n");
2383 livebox_destroy(livebox);
2386 } else if (!xmlStrcasecmp(livebox->abi, (const xmlChar *)"c") || !xmlStrcasecmp(livebox->abi, (const xmlChar *)"cpp")) {
2390 len = strlen((char *)livebox->pkgid) + strlen("/libexec/liblive-.so") + 1;
2392 filename = malloc(len);
2394 livebox_destroy(livebox);
2398 snprintf(filename, len, "/libexec/liblive-%s.so", livebox->pkgid);
2399 livebox->libexec = xmlStrdup((xmlChar *)filename);
2400 DbgPrint("Use the default libexec: %s\n", filename);
2403 if (!livebox->libexec) {
2404 livebox_destroy(livebox);
2409 for (node = node->children; node; node = node->next) {
2410 if (!xmlStrcmp(node->name, (const xmlChar *)"text"))
2413 DbgPrint("Nodename: %s\n", node->name);
2414 if (!xmlStrcasecmp(node->name, (const xmlChar *)"label")) {
2415 update_i18n_name(livebox, node);
2419 if (!xmlStrcasecmp(node->name, (const xmlChar *)"icon")) {
2420 update_i18n_icon(livebox, node);
2424 if (!xmlStrcasecmp(node->name, (const xmlChar *)"box")) {
2425 update_box(livebox, node);
2429 if (!xmlStrcasecmp(node->name, (const xmlChar *)"pd")) {
2430 update_pd(livebox, node);
2434 if (!xmlStrcasecmp(node->name, (const xmlChar *)"group")) {
2435 update_group(livebox, node);
2439 if (!xmlStrcasecmp(node->name, (const xmlChar *)"content")) {
2440 update_content(livebox, node);
2444 if (!xmlStrcasecmp(node->name, (const xmlChar *)"setup")) {
2445 update_setup(livebox, node);
2449 if (!xmlStrcasecmp(node->name, (const xmlChar *)"launch")) {
2450 update_launch(livebox, node);
2455 return db_insert_livebox(livebox, appid);
2458 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char *appid)
2463 if (!s_info.handle) {
2464 if (db_init() < 0) {
2465 ErrPrint("Failed to init DB\n");
2470 node = xmlDocGetRootElement(docPtr);
2472 ErrPrint("Invalid document\n");
2476 for (node = node->children; node; node = node->next) {
2477 DbgPrint("node->name: %s\n", node->name);
2478 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
2479 ret = do_install(node, appid);
2480 DbgPrint("Returns: %d\n", ret);
2487 static inline int do_uninstall(xmlNodePtr node, const char *appid)
2492 if (!xmlHasProp(node, (const xmlChar *)"appid")) {
2493 ErrPrint("Missing appid\n");
2497 pkgid = xmlGetProp(node, (const xmlChar *)"appid");
2498 if (!validate_pkgid(appid, (char *)pkgid)) {
2499 ErrPrint("Invalid package\n");
2504 begin_transaction();
2505 ret = db_remove_box_size((char *)pkgid);
2509 ret = db_remove_i18n((char *)pkgid);
2513 ret = db_remove_client((char *)pkgid);
2517 ret = db_remove_provider((char *)pkgid);
2521 ret = db_remove_option((char *)pkgid);
2522 DbgPrint("Remove option: %d\n", ret);
2524 ret = db_remove_groupmap((char *)pkgid);
2525 DbgPrint("Remove groupmap: %d\n", ret);
2527 ret = db_remove_group((char *)pkgid);
2531 ret = db_remove_pkgmap((char *)pkgid);
2535 commit_transaction();
2541 rollback_transaction();
2546 int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char *appid)
2551 if (!s_info.handle) {
2552 if (db_init() < 0) {
2553 ErrPrint("Failed to init DB\n");
2558 node = xmlDocGetRootElement(docPtr);
2560 ErrPrint("Invalid document\n");
2564 for (node = node->children; node; node = node->next) {
2565 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
2566 ret = do_uninstall(node, appid);
2567 ret = do_install(node, appid);
2568 DbgPrint("Returns: %d\n", ret);
2575 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *appid)
2580 if (!s_info.handle) {
2581 if (db_init() < 0) {
2582 ErrPrint("Failed to init DB\n");
2587 node = xmlDocGetRootElement(docPtr);
2589 ErrPrint("Invalid document\n");
2593 for (node = node->children; node; node = node->next) {
2594 if (!xmlStrcasecmp(node->name, (const xmlChar *)"livebox")) {
2595 ret = do_uninstall(node, appid);
2596 DbgPrint("Returns: %d\n", ret);