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 <stdlib.h> /* malloc */
20 #include <string.h> /* strdup, strerror */
21 #include <sys/types.h>
29 #include <com-core_packet.h>
33 #include <package-manager.h>
34 #include <pkgmgr-info.h>
36 #include <vconf-keys.h>
38 #include <unicode/uloc.h>
43 #include "livebox-service.h"
44 #include "livebox-errno.h"
46 #define SAMSUNG_PREFIX "com.samsung."
47 #define EAPI __attribute__((visibility("default")))
48 #define DEFAULT_TIMEOUT 2.0
51 static struct supported_size_list {
54 } SIZE_LIST[NR_OF_SIZE_LIST] = {
55 { 175, 175 }, /*!< 1x1 */
56 { 354, 175 }, /*!< 2x1 */
57 { 354, 354 }, /*!< 2x2 */
58 { 712, 175 }, /*!< 4x1 */
59 { 712, 354 }, /*!< 4x2 */
60 { 712, 533 }, /*!< 4x3 */
61 { 712, 712 }, /*!< 4x4 */
62 { 712, 891 }, /*!< 4x5 */
63 { 712, 1070 }, /*!< 4x6 */
64 { 224, 215 }, /*!< 21x21 */
65 { 680, 215 }, /*!< 23x21 */
66 { 680, 653 }, /*!< 23x23 */
67 { 720, 1280 }, /*!< 0x0 */
70 struct pkglist_handle {
72 PKGLIST_TYPE_LB_LIST = 0x00beef00,
73 PKGLIST_TYPE_UNKNOWN = 0x00dead00
82 const char *conf_file;
87 char country[ULOC_COUNTRY_CAPACITY];
92 .dbfile = "/opt/dbspace/.livebox.db",
93 .conf_file = "/usr/share/data-provider-master/resolution.ini",
103 static inline int update_info(int width_type, int height_type, int width, int height)
107 if (width_type == 1 && height_type == 1) {
109 } else if (width_type == 2 && height_type == 1) {
111 } else if (width_type == 2 && height_type == 2) {
113 } else if (width_type == 4 && height_type == 1) {
115 } else if (width_type == 4 && height_type == 2) {
117 } else if (width_type == 4 && height_type == 3) {
119 } else if (width_type == 4 && height_type == 4) {
121 } else if (width_type == 4 && height_type == 5) {
123 } else if (width_type == 4 && height_type == 6) {
125 } else if (width_type == 21 && height_type == 21) {
127 } else if (width_type == 23 && height_type == 21) {
129 } else if (width_type == 23 && height_type == 23) {
131 } else if (width_type == 0 && height_type == 0) {
134 ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
138 SIZE_LIST[idx].w = width;
139 SIZE_LIST[idx].h = height;
143 static inline int update_from_file(void)
151 char buffer[MAX_COLUMN];
165 fp = fopen(s_info.conf_file, "r");
167 ErrPrint("Open failed: %s\n", strerror(errno));
168 return LB_STATUS_ERROR_IO;
177 if (idx == MAX_COLUMN) {
178 ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
184 if (isspace(ch) || ch == EOF) {
200 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
201 ErrPrint("Invalid syntax: [%s]\n", buffer);
205 } else if (ch == '=') {
208 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
209 ErrPrint("Invalid syntax: [%s]\n", buffer);
213 } else if (ch == EOF) {
214 ErrPrint("Invalid Syntax\n");
226 if (isspace(ch) || ch == EOF) {
235 if (isspace(ch) || ch == EOF) {
239 if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
240 ErrPrint("Invalid syntax: [%s]\n", buffer);
242 } else if (ch == EOF) {
243 updated += update_info(width_type, height_type, width, height);
250 updated += update_info(width_type, height_type, width, height);
255 if (ch == '\n' || ch == '\r' || ch == '\f') {
260 if (ch == '\n' || ch == '\r' || ch == '\f') {
265 ErrPrint("Unknown status. couldn't be reach to here\n");
270 if (fclose(fp) != 0) {
271 ErrPrint("fclose: %s\n", strerror(errno));
274 return NR_OF_SIZE_LIST - updated;
277 static int update_resolution(void)
289 if (s_info.res_resolved) {
290 return LB_STATUS_SUCCESS;
293 disp = XOpenDisplay(NULL);
295 ErrPrint("Failed to open a display\n");
296 return LB_STATUS_ERROR_FAULT;
299 root = XDefaultRootWindow(disp);
300 if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
302 return LB_STATUS_ERROR_FAULT;
305 if (update_from_file() == 0) {
306 DbgPrint("Resolution info is all updated by file\n");
309 for (i = 0; i < NR_OF_SIZE_LIST; i++) {
310 SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
311 SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)width / 720.0f);
315 s_info.res_resolved = 1;
316 return LB_STATUS_SUCCESS;
319 static sqlite3 *open_db(void)
323 if (!s_info.handle) {
326 ret = db_util_open_with_options(s_info.dbfile, &handle, SQLITE_OPEN_READONLY, NULL);
327 if (ret != SQLITE_OK) {
328 ErrPrint("Failed to open a DB\n");
332 handle = s_info.handle;
338 static inline __attribute__((always_inline)) void close_db(sqlite3 *handle)
340 if (!s_info.handle) {
341 db_util_close(handle);
345 static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
350 case LB_SIZE_TYPE_1x1: /*!< 175x175 */
353 case LB_SIZE_TYPE_2x1: /*!< 354x175 */
356 case LB_SIZE_TYPE_2x2: /*!< 354x354 */
359 case LB_SIZE_TYPE_4x1: /*!< 712x175 */
362 case LB_SIZE_TYPE_4x2: /*!< 712x354 */
365 case LB_SIZE_TYPE_4x3: /*!< 712x533 */
368 case LB_SIZE_TYPE_4x4: /*!< 712x712 */
371 case LB_SIZE_TYPE_4x5: /*!< 712x891 */
374 case LB_SIZE_TYPE_4x6: /*!< 712x1070 */
377 case LB_SIZE_TYPE_EASY_1x1: /*< 224x215 */
380 case LB_SIZE_TYPE_EASY_3x1: /*!< 680x215 */
383 case LB_SIZE_TYPE_EASY_3x3: /*!< 680x653 */
386 case LB_SIZE_TYPE_0x0: /*!< 720x1280 */
390 return LB_STATUS_ERROR_INVALID;
393 if (update_resolution() < 0) {
394 ErrPrint("Failed to update resolution\n");
397 *width = SIZE_LIST[idx].w;
398 *height = SIZE_LIST[idx].h;
399 return LB_STATUS_SUCCESS;
402 EAPI int livebox_service_change_period(const char *pkgname, const char *id, double period)
404 struct packet *packet;
405 struct packet *result;
409 if (!pkgname || !id || period < 0.0f) {
410 ErrPrint("Invalid argument\n");
411 return LB_STATUS_ERROR_INVALID;
414 uri = util_id_to_uri(id);
416 return LB_STATUS_ERROR_MEMORY;
419 packet = packet_create("service_change_period", "ssd", pkgname, uri, period);
422 ErrPrint("Failed to create a packet for period changing\n");
423 return LB_STATUS_ERROR_FAULT;
426 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
427 packet_unref(packet);
430 if (packet_get(result, "i", &ret) != 1) {
431 ErrPrint("Failed to parse a result packet\n");
432 ret = LB_STATUS_ERROR_INVALID;
434 packet_unref(result);
436 ErrPrint("Failed to get result packet\n");
437 ret = LB_STATUS_ERROR_FAULT;
443 EAPI int livebox_service_trigger_update_with_content(const char *pkgname, const char *id, const char *cluster, const char *category, const char *content, int force)
445 struct packet *packet;
446 struct packet *result;
451 ErrPrint("Invalid argument\n");
452 return LB_STATUS_ERROR_INVALID;
455 if (!force && access("/tmp/.live.paused", R_OK) == 0) {
456 DbgPrint("Provider is paused\n");
457 return LB_STATUS_ERROR_CANCEL;
461 uri = util_id_to_uri(id);
463 return LB_STATUS_ERROR_MEMORY;
470 cluster = "user,created";
474 category = "default";
477 packet = packet_create("service_update", "sssss", pkgname, uri, cluster, category, content);
480 * "free" function accepts NULL
484 ErrPrint("Failed to create a packet for service_update\n");
485 return LB_STATUS_ERROR_FAULT;
488 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
489 packet_unref(packet);
492 if (packet_get(result, "i", &ret) != 1) {
493 ErrPrint("Failed to parse a result packet\n");
494 ret = LB_STATUS_ERROR_INVALID;
497 packet_unref(result);
499 ErrPrint("Failed to get result packet\n");
500 ret = LB_STATUS_ERROR_FAULT;
506 EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force)
508 return livebox_service_trigger_update_with_content(pkgname, id, cluster, category, NULL, force);
512 * pkgid == Package Id (not the livebox id)
514 EAPI struct pkglist_handle *livebox_service_pkglist_create(const char *pkgid, struct pkglist_handle *handle)
519 if (handle->type != PKGLIST_TYPE_LB_LIST) {
520 ErrPrint("Invalid handle\n");
525 ErrPrint("pkgid should be NULL\n");
529 sqlite3_reset(handle->stmt);
533 handle = calloc(1, sizeof(*handle));
535 ErrPrint("Heap: %s\n", strerror(errno));
539 handle->type = PKGLIST_TYPE_LB_LIST;
541 handle->handle = open_db();
542 if (!handle->handle) {
548 ret = sqlite3_prepare_v2(handle->handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &handle->stmt, NULL);
549 if (ret != SQLITE_OK) {
550 ErrPrint("Error: %s\n", sqlite3_errmsg(handle->handle));
551 close_db(handle->handle);
556 ret = sqlite3_prepare_v2(handle->handle, "SELECT appid, pkgid, prime FROM pkgmap WHERE appid = ?", -1, &handle->stmt, NULL);
557 if (ret != SQLITE_OK) {
558 ErrPrint("Error: %s\n", sqlite3_errmsg(handle->handle));
559 close_db(handle->handle);
564 ret = sqlite3_bind_text(handle->stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
565 if (ret != SQLITE_OK) {
566 ErrPrint("Error: %s\n", sqlite3_errmsg(handle->handle));
567 sqlite3_finalize(handle->stmt);
568 close_db(handle->handle);
577 EAPI int livebox_service_get_pkglist_item(struct pkglist_handle *handle, char **appid, char **pkgname, int *is_prime)
581 char *_pkgname = NULL;
583 if (!handle || handle->type != PKGLIST_TYPE_LB_LIST) {
584 return LB_STATUS_ERROR_INVALID;
587 if (sqlite3_step(handle->stmt) != SQLITE_ROW) {
588 return LB_STATUS_ERROR_NOT_EXIST;
592 tmp = (const char *)sqlite3_column_text(handle->stmt, 0);
593 if (tmp && strlen(tmp)) {
594 _appid = strdup(tmp);
596 ErrPrint("Heap: %s\n", strerror(errno));
597 return LB_STATUS_ERROR_MEMORY;
603 tmp = (const char *)sqlite3_column_text(handle->stmt, 1);
604 if (tmp && strlen(tmp)) {
605 _pkgname = strdup(tmp);
607 ErrPrint("Heap: %s\n", strerror(errno));
609 return LB_STATUS_ERROR_MEMORY;
615 *is_prime = sqlite3_column_int(handle->stmt, 2);
626 return LB_STATUS_SUCCESS;
629 EAPI int livebox_service_pkglist_destroy(struct pkglist_handle *handle)
631 if (!handle || handle->type != PKGLIST_TYPE_LB_LIST) {
632 return LB_STATUS_ERROR_INVALID;
635 handle->type = PKGLIST_TYPE_UNKNOWN;
636 sqlite3_reset(handle->stmt);
637 sqlite3_finalize(handle->stmt);
638 close_db(handle->handle);
640 return LB_STATUS_SUCCESS;
643 EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
653 return LB_STATUS_ERROR_INVALID;
658 return LB_STATUS_ERROR_IO;
661 ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
662 if (ret != SQLITE_OK) {
663 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
664 ret = LB_STATUS_ERROR_IO;
669 while (sqlite3_step(stmt) == SQLITE_ROW) {
670 appid = (char *)sqlite3_column_text(stmt, 0);
671 if (!appid || !strlen(appid)) {
672 ErrPrint("APPID is not valid\n");
676 pkgid = (char *)sqlite3_column_text(stmt, 1);
677 if (!pkgid || !strlen(pkgid)) {
678 ErrPrint("pkgid is not valid\n");
682 is_prime = sqlite3_column_int(stmt, 2);
686 if (cb(appid, pkgid, is_prime, data) < 0) {
687 DbgPrint("Callback stopped package crawling\n");
693 sqlite3_finalize(stmt);
700 EAPI int livebox_service_get_pkglist_by_pkgid(const char *pkgid, int (*cb)(const char *lbid, int is_prime, void *data), void *data)
709 return LB_STATUS_ERROR_INVALID;
714 return LB_STATUS_ERROR_IO;
717 ret = sqlite3_prepare_v2(handle, "SELECT pkgid, prime FROM pkgmap WHERE appid = ?", -1, &stmt, NULL);
718 if (ret != SQLITE_OK) {
719 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
720 ret = LB_STATUS_ERROR_IO;
724 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
725 if (ret != SQLITE_OK) {
726 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
728 sqlite3_finalize(stmt);
729 ret = LB_STATUS_ERROR_IO;
734 while (sqlite3_step(stmt) == SQLITE_ROW) {
735 lbid = (const char *)sqlite3_column_text(stmt, 0);
736 if (!lbid || !strlen(lbid)) {
737 ErrPrint("LBID is not valid\n");
741 is_prime = sqlite3_column_int(stmt, 1);
745 if (cb(lbid, is_prime, data) < 0) {
746 DbgPrint("Callback stopped package crawling\n");
752 sqlite3_finalize(stmt);
759 struct pkgmgr_cbdata {
761 void (*cb)(const char *lbid, const char *appid, void *data);
765 static int pkgmgr_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
767 struct pkgmgr_cbdata *cbdata = (struct pkgmgr_cbdata *)user_data;
771 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
773 ErrPrint("Unable to get appid\n");
775 cbdata->cb(cbdata->lbid, appid, cbdata->cbdata);
781 static inline char *pkgmgr_get_mainapp(const char *pkgid)
783 pkgmgrinfo_pkginfo_h handle;
786 if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle) != PMINFO_R_OK) {
787 ErrPrint("Unable to get mainapp: %s\n", pkgid);
791 if (pkgmgrinfo_pkginfo_get_mainappid(handle, &ret) == PMINFO_R_OK) {
794 ErrPrint("Failed to get mainappid\n");
795 ret = NULL; /* I cannot believe the pkgmgrinfo_pkginfo_get_mainappid. it maybe able to touch my "ret" even though it fails */
799 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
803 static inline int pkgmgr_get_applist(const char *pkgid, const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
805 struct pkgmgr_cbdata cbdata;
806 pkgmgrinfo_pkginfo_h handle;
809 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
811 ErrPrint("Unable to get pkginfo: %s\n", pkgid);
817 cbdata.cbdata = data;
819 ret = pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, pkgmgr_cb, &cbdata);
821 ErrPrint("Failed to get applist\n");
824 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
828 EAPI int livebox_service_get_applist(const char *lbid, void (*cb)(const char *lbid, const char *appid, void *data), void *data)
837 return LB_STATUS_ERROR_INVALID;
842 return LB_STATUS_ERROR_IO;
845 ret = sqlite3_prepare_v2(handle, "SELECT appid FROM pkgmap WHERE (pkgid = ?) or (appid = ?)", -1, &stmt, NULL);
846 if (ret != SQLITE_OK) {
847 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
848 ret = LB_STATUS_ERROR_IO;
852 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
853 if (ret != SQLITE_OK) {
854 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
855 ret = LB_STATUS_ERROR_IO;
859 ret = sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT);
860 if (ret != SQLITE_OK) {
861 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
862 ret = LB_STATUS_ERROR_IO;
866 if (sqlite3_step(stmt) != SQLITE_ROW) {
867 ret = LB_STATUS_ERROR_INVALID;
869 sqlite3_finalize(stmt);
873 tmp = (const char *)sqlite3_column_text(stmt, 0);
874 if (!tmp || !strlen(tmp)) {
875 ErrPrint("Invalid package name (%s)\n", lbid);
876 ret = LB_STATUS_ERROR_INVALID;
878 sqlite3_finalize(stmt);
884 ErrPrint("Error: %s\n", strerror(errno));
885 ret = LB_STATUS_ERROR_MEMORY;
887 sqlite3_finalize(stmt);
892 sqlite3_finalize(stmt);
894 ret = pkgmgr_get_applist(pkgid, lbid, cb, data);
898 case PMINFO_R_EINVAL:
899 ret = LB_STATUS_ERROR_INVALID;
902 ret = LB_STATUS_SUCCESS;
906 ret = LB_STATUS_ERROR_FAULT;
915 EAPI char *livebox_service_mainappid(const char *lbid)
932 if (sqlite3_prepare_v2(handle, "SELECT appid, uiapp FROM pkgmap WHERE (pkgid = ?) or (appid = ? and prime = 1)", -1, &stmt, NULL) != SQLITE_OK) {
933 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
937 if (sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
938 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
942 if (sqlite3_bind_text(stmt, 2, lbid, -1, SQLITE_TRANSIENT) != SQLITE_OK) {
943 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
947 if (sqlite3_step(stmt) != SQLITE_ROW) {
949 sqlite3_finalize(stmt);
953 tmp = (const char *)sqlite3_column_text(stmt, 0);
954 if (!tmp || !strlen(tmp)) {
955 ErrPrint("Invalid package name (%s)\n", lbid);
957 sqlite3_finalize(stmt);
961 pkgid = (const char *)sqlite3_column_text(stmt, 1);
962 if (!pkgid || !strlen(pkgid)) {
964 * This record has no uiapp.
965 * Try to find the main ui-app id.
967 ret = pkgmgr_get_mainapp(tmp);
971 ErrPrint("Error: %s\n", strerror(errno));
976 sqlite3_finalize(stmt);
983 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
990 if (!types || !cnt || !pkgid) {
991 return LB_STATUS_ERROR_INVALID;
996 return LB_STATUS_ERROR_IO;
999 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1000 if (ret != SQLITE_OK) {
1001 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1002 ret = LB_STATUS_ERROR_IO;
1006 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1007 if (ret != SQLITE_OK) {
1008 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1009 sqlite3_reset(stmt);
1010 sqlite3_finalize(stmt);
1011 ret = LB_STATUS_ERROR_IO;
1015 if (*cnt > NR_OF_SIZE_LIST) {
1016 *cnt = NR_OF_SIZE_LIST;
1020 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1021 size = sqlite3_column_int(stmt, 0);
1027 sqlite3_reset(stmt);
1028 sqlite3_finalize(stmt);
1029 ret = LB_STATUS_SUCCESS;
1035 static inline char *cur_locale(void)
1038 language = vconf_get_str(VCONFKEY_LANGSET);
1056 language = strdup("en-us");
1058 ErrPrint("Heap: %s\n", strerror(errno));
1065 static inline char *get_default_name(const char *pkgid)
1077 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1078 if (ret != SQLITE_OK) {
1079 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1084 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1085 if (ret != SQLITE_OK) {
1086 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1090 ret = sqlite3_step(stmt);
1091 if (ret == SQLITE_ROW) {
1094 tmp = (const char *)sqlite3_column_text(stmt, 0);
1095 if (tmp && strlen(tmp)) {
1098 ErrPrint("Heap: %s\n", strerror(errno));
1104 sqlite3_reset(stmt);
1105 sqlite3_finalize(stmt);
1110 static inline char *get_default_icon(const char *pkgid)
1122 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1123 if (ret != SQLITE_OK) {
1124 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1129 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1130 if (ret != SQLITE_OK) {
1131 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1135 ret = sqlite3_step(stmt);
1136 if (ret == SQLITE_ROW) {
1139 tmp = (const char *)sqlite3_column_text(stmt, 0);
1140 if (tmp && strlen(tmp)) {
1143 ErrPrint("Heap: %s\n", strerror(errno));
1149 sqlite3_reset(stmt);
1150 sqlite3_finalize(stmt);
1155 EAPI char *livebox_service_content(const char *pkgid)
1159 char *content = NULL;
1167 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1168 if (ret != SQLITE_OK) {
1169 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1174 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1175 if (ret != SQLITE_OK) {
1176 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1180 ret = sqlite3_step(stmt);
1181 if (ret == SQLITE_ROW) {
1184 tmp = (const char *)sqlite3_column_text(stmt, 0);
1185 if (tmp && strlen(tmp)) {
1186 content = strdup(tmp);
1188 ErrPrint("Heap: %s\n", strerror(errno));
1194 sqlite3_reset(stmt);
1195 sqlite3_finalize(stmt);
1200 EAPI char *livebox_service_setup_appid(const char *lbid)
1212 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1213 if (ret != SQLITE_OK) {
1214 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1220 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1221 if (ret != SQLITE_OK) {
1222 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1226 ret = sqlite3_step(stmt);
1227 if (ret == SQLITE_ROW) {
1230 tmp = (const char *)sqlite3_column_text(stmt, 0);
1231 if (!tmp || !strlen(tmp)) {
1235 appid = strdup(tmp);
1237 ErrPrint("Error: %s\n", strerror(errno));
1242 sqlite3_reset(stmt);
1243 sqlite3_finalize(stmt);
1248 EAPI int livebox_service_nodisplay(const char *pkgid)
1259 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1260 if (ret != SQLITE_OK) {
1261 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1266 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1267 if (ret != SQLITE_OK) {
1268 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1273 ret = sqlite3_step(stmt);
1274 if (ret == SQLITE_ROW) {
1275 ret = !!sqlite3_column_int(stmt, 0);
1281 sqlite3_reset(stmt);
1282 sqlite3_finalize(stmt);
1287 static inline char *get_lb_pkgname_by_appid(const char *appid)
1305 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
1306 if (ret != SQLITE_OK) {
1307 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1312 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
1313 if (ret != SQLITE_OK) {
1314 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1318 ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT);
1319 if (ret != SQLITE_OK) {
1320 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1324 if (sqlite3_step(stmt) != SQLITE_ROW) {
1325 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
1329 tmp = (char *)sqlite3_column_text(stmt, 0);
1330 if (tmp && strlen(tmp)) {
1331 pkgid = strdup(tmp);
1333 ErrPrint("Heap: %s\n", strerror(errno));
1338 sqlite3_reset(stmt);
1339 sqlite3_finalize(stmt);
1344 EAPI int livebox_service_need_frame(const char *pkgid, int size_type)
1353 ErrPrint("Unable to open a DB\n");
1357 ret = sqlite3_prepare_v2(handle, "SELECT need_frame FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1358 if (ret != SQLITE_OK) {
1359 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1366 lbid = livebox_service_pkgname(pkgid);
1368 ErrPrint("Invalid appid (%s)\n", pkgid);
1373 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1375 if (ret != SQLITE_OK) {
1376 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1381 ret = sqlite3_bind_int(stmt, 2, size_type);
1382 if (ret != SQLITE_OK) {
1383 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1388 ret = sqlite3_step(stmt);
1389 if (ret == SQLITE_ROW) {
1390 ret = !!sqlite3_column_int(stmt, 0);
1393 ErrPrint("There is no such result\n");
1396 sqlite3_reset(stmt);
1397 sqlite3_finalize(stmt);
1402 EAPI int livebox_service_touch_effect(const char *pkgid, int size_type)
1411 ErrPrint("Unable to open a DB\n");
1415 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1416 if (ret != SQLITE_OK) {
1417 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1424 * This function will validate the "pkgid"
1425 * call the exported API in the exported API is not recomended
1428 lbid = livebox_service_pkgname(pkgid);
1430 ErrPrint("Invalid appid (%s)\n", pkgid);
1435 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1437 if (ret != SQLITE_OK) {
1438 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1443 ret = sqlite3_bind_int(stmt, 2, size_type);
1444 if (ret != SQLITE_OK) {
1445 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1450 ret = sqlite3_step(stmt);
1451 if (ret == SQLITE_ROW) {
1452 ret = !!sqlite3_column_int(stmt, 0);
1454 ret = 1; /*!< Default true: In this case the DB is corrupted. */
1455 ErrPrint("There is no result\n");
1459 sqlite3_reset(stmt);
1460 sqlite3_finalize(stmt);
1465 EAPI int livebox_service_mouse_event(const char *pkgid)
1477 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
1478 if (ret != SQLITE_OK) {
1479 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1484 lbid = livebox_service_pkgname(pkgid);
1486 ErrPrint("Failed to get lbid: %s\n", pkgid);
1491 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1493 if (ret != SQLITE_OK) {
1494 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1499 ret = sqlite3_step(stmt);
1500 if (ret == SQLITE_ROW) {
1501 ret = !!sqlite3_column_int(stmt, 0);
1503 ret = 0; /*!< Default is false, In this case the DB is corrupted */
1504 ErrPrint("There is no result.\n");
1508 sqlite3_reset(stmt);
1509 sqlite3_finalize(stmt);
1514 static inline int update_lang_info(void)
1519 syslang = vconf_get_str(VCONFKEY_LANGSET);
1521 ErrPrint("Failed to get vconf-lang\n");
1525 if (s_info.syslang && !strcmp(s_info.syslang, syslang)) {
1526 DbgPrint("Syslang is not changed: %s\n", syslang);
1531 free(s_info.syslang);
1532 s_info.syslang = syslang;
1535 uloc_setDefault((const char *)s_info.syslang, &err);
1536 if (!U_SUCCESS(err)) {
1537 ErrPrint("Failed to set default lang: %s\n", u_errorName(err));
1538 free(s_info.syslang);
1539 s_info.syslang = NULL;
1543 s_info.iso3lang = uloc_getISO3Language(uloc_getDefault());
1544 if (!s_info.iso3lang || !strlen(s_info.iso3lang)) {
1545 ErrPrint("Failed to get iso3lang\n");
1546 free(s_info.syslang);
1547 s_info.syslang = NULL;
1552 s_info.country_len = uloc_getCountry(uloc_getDefault(), s_info.country, ULOC_COUNTRY_CAPACITY, &err);
1553 if (!U_SUCCESS(err) || s_info.country_len <= 0) {
1554 ErrPrint("Failed to get locale: %s, %s, %d (%s)\n", u_errorName(err), s_info.iso3lang, s_info.country_len, s_info.country);
1555 free(s_info.syslang);
1556 s_info.syslang = NULL;
1563 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
1568 char *preview = NULL;
1580 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1581 if (ret != SQLITE_OK) {
1582 ErrPrint("Error: %s, %s\n", sqlite3_errmsg(handle), pkgid);
1587 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1588 if (ret != SQLITE_OK) {
1589 ErrPrint("Error: %s, %s\n", sqlite3_errmsg(handle), pkgid);
1593 ret = sqlite3_bind_int(stmt, 2, size_type);
1594 if (ret != SQLITE_OK) {
1595 ErrPrint("Error: %s, %s\n", sqlite3_errmsg(handle), pkgid);
1599 ret = sqlite3_step(stmt);
1600 if (ret != SQLITE_ROW) {
1601 ErrPrint("Error: %s, %s\n", sqlite3_errmsg(handle), pkgid);
1605 tmp = (const char *)sqlite3_column_text(stmt, 0);
1606 if (!tmp || !(tmp_len = strlen(tmp))) {
1607 ErrPrint("Failed to get data (%s)\n", pkgid);
1611 if (update_lang_info() != 0) {
1612 preview = strdup(tmp);
1614 ErrPrint("Heap: %s\n", strerror(errno));
1619 buf_len = tmp_len + strlen(s_info.iso3lang) + s_info.country_len + 3; /* '/' '-' '/' */
1620 preview = malloc(buf_len + 1);
1622 ErrPrint("Heap: %s\n", strerror(errno));
1626 for (i = tmp_len; i >= 0 && tmp[i] != '/'; i--);
1629 strncpy(preview, tmp, i);
1630 printed = snprintf(preview + i, buf_len - i, "%s-%s/%s", s_info.iso3lang, s_info.country, tmp + i);
1631 if (preview[i + printed] != '\0') {
1632 ErrPrint("Path is truncated\n");
1633 preview[i + printed] = '\0';
1636 if (access(preview, R_OK) != 0) {
1637 DbgPrint("Access failed: %s, %s\n", preview, strerror(errno));
1640 preview = strdup(tmp);
1642 ErrPrint("Heap: %s\n", strerror(errno));
1647 sqlite3_reset(stmt);
1648 sqlite3_finalize(stmt);
1653 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1662 language = strdup(lang);
1664 ErrPrint("Heap: %s\n", strerror(errno));
1668 language = cur_locale();
1680 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1681 if (ret != SQLITE_OK) {
1682 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1688 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1689 if (ret != SQLITE_OK) {
1690 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1694 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1695 if (ret != SQLITE_OK) {
1696 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1700 ret = sqlite3_step(stmt);
1701 if (ret == SQLITE_ROW) {
1703 tmp = (const char *)sqlite3_column_text(stmt, 0);
1704 if (!tmp || !strlen(tmp)) {
1705 icon = get_default_icon(pkgid);
1709 ErrPrint("Heap: %s\n", strerror(errno));
1713 icon = get_default_icon(pkgid);
1717 sqlite3_reset(stmt);
1718 sqlite3_finalize(stmt);
1724 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1733 language = strdup(lang);
1735 ErrPrint("Error: %s\n", strerror(errno));
1739 language = cur_locale();
1751 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1752 if (ret != SQLITE_OK) {
1753 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1759 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1760 if (ret != SQLITE_OK) {
1761 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1765 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1766 if (ret != SQLITE_OK) {
1767 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1771 ret = sqlite3_step(stmt);
1772 if (ret == SQLITE_ROW) {
1774 tmp = (const char *)sqlite3_column_text(stmt, 0);
1775 if (!tmp || !strlen(tmp)) {
1776 name = get_default_name(pkgid);
1780 ErrPrint("Heap: %s\n", strerror(errno));
1784 name = get_default_name(pkgid);
1788 sqlite3_reset(stmt);
1789 sqlite3_finalize(stmt);
1795 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1802 if (!w || !h || !cnt || !pkgid) {
1803 return LB_STATUS_ERROR_INVALID;
1808 return LB_STATUS_ERROR_IO;
1811 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1812 if (ret != SQLITE_OK) {
1813 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1814 ret = LB_STATUS_ERROR_IO;
1818 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1819 if (ret != SQLITE_OK) {
1820 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1821 sqlite3_reset(stmt);
1822 sqlite3_finalize(stmt);
1823 ret = LB_STATUS_ERROR_IO;
1827 if (*cnt > NR_OF_SIZE_LIST) {
1828 *cnt = NR_OF_SIZE_LIST;
1832 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1833 size = sqlite3_column_int(stmt, 0);
1834 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1838 sqlite3_reset(stmt);
1839 sqlite3_finalize(stmt);
1846 EAPI char *livebox_service_libexec(const char *pkgid)
1865 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1866 if (ret != SQLITE_OK) {
1867 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1871 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1872 if (ret != SQLITE_OK) {
1873 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1874 sqlite3_finalize(stmt);
1878 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1879 if (ret != SQLITE_OK) {
1880 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1881 sqlite3_finalize(stmt);
1885 if (sqlite3_step(stmt) != SQLITE_ROW) {
1886 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1887 sqlite3_reset(stmt);
1888 sqlite3_finalize(stmt);
1890 libexec = util_conf_get_libexec(pkgid);
1891 DbgPrint("Fallback to conf checker: %s\n", libexec);
1895 appid = (char *)sqlite3_column_text(stmt, 0);
1896 if (!appid || !strlen(appid)) {
1897 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1898 sqlite3_reset(stmt);
1899 sqlite3_finalize(stmt);
1903 path = (char *)sqlite3_column_text(stmt, 1);
1904 if (!path || !strlen(path)) {
1905 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1906 sqlite3_reset(stmt);
1907 sqlite3_finalize(stmt);
1911 libexec = strdup(path);
1913 ErrPrint("Heap: %s\n", strerror(errno));
1914 sqlite3_reset(stmt);
1915 sqlite3_finalize(stmt);
1919 DbgPrint("libexec: %s\n", libexec);
1921 sqlite3_reset(stmt);
1922 sqlite3_finalize(stmt);
1928 EAPI char *livebox_service_pkgname(const char *appid)
1931 pkgmgr_appinfo_h handle;
1939 lb_pkgname = get_lb_pkgname_by_appid(appid);
1946 * Try to get the package id using given appid
1948 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1949 if (ret != PKGMGR_R_OK) {
1950 ErrPrint("Failed to get appinfo\n");
1954 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1955 if (ret != PKGMGR_R_OK) {
1956 pkgmgr_appinfo_destroy_appinfo(handle);
1957 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1961 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1962 pkgmgr_appinfo_destroy_appinfo(handle);
1964 if (!lb_pkgname && util_validate_livebox_package(appid) == 0) {
1965 return strdup(appid);
1971 EAPI char *livebox_service_provider_name(const char *lbid)
1977 char *str = SAMSUNG_PREFIX;
1983 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1985 if (seq < 2 && lbid[idx] == '.') {
1991 if (!str[idx] && lbid[idx]) {
1993 return strdup(lbid);
1994 } else if (seq < 2) {
1996 if (lbid[idx] == '.') {
1998 } else if (!lbid[idx]) {
1999 ErrPrint("Invalid lbid: %s\n", lbid);
2011 ret = strdup(lbid + stage);
2013 ErrPrint("Error: %s\n", strerror(errno));
2020 EAPI int livebox_service_is_enabled(const char *lbid)
2029 pkgname = livebox_service_appid(lbid);
2033 ret = ail_get_appinfo(pkgname, &ai);
2034 if (ret != AIL_ERROR_OK) {
2039 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
2042 ail_destroy_appinfo(ai);
2044 return enabled == true;
2048 EAPI int livebox_service_is_primary(const char *lbid)
2063 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
2064 if (ret != SQLITE_OK) {
2065 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2070 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
2071 if (ret != SQLITE_OK) {
2072 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2076 ret = sqlite3_step(stmt);
2077 if (ret != SQLITE_ROW) {
2078 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2082 ret = sqlite3_column_int(stmt, 0);
2085 sqlite3_reset(stmt);
2086 sqlite3_finalize(stmt);
2091 EAPI char *livebox_service_appid(const char *pkgname)
2097 int is_prime __attribute__((__unused__));
2110 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
2111 if (ret != SQLITE_OK) {
2112 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2116 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
2117 if (ret != SQLITE_OK) {
2118 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2119 sqlite3_reset(stmt);
2120 sqlite3_finalize(stmt);
2124 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
2125 if (ret != SQLITE_OK) {
2126 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2127 sqlite3_reset(stmt);
2128 sqlite3_finalize(stmt);
2132 ret = sqlite3_step(stmt);
2133 if (ret != SQLITE_ROW) {
2134 pkgmgr_appinfo_h pkg_handle;
2137 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
2138 sqlite3_reset(stmt);
2139 sqlite3_finalize(stmt);
2141 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
2142 if (ret != PKGMGR_R_OK) {
2143 ErrPrint("Failed to get appinfo: %s\n", pkgname);
2147 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
2148 if (ret != PKGMGR_R_OK) {
2149 ErrPrint("Failed to get pkgname for (%s)\n", appid);
2150 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
2154 appid = strdup(new_appid);
2156 ErrPrint("Heap: %s\n", strerror(errno));
2159 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
2163 tmp = (char *)sqlite3_column_text(stmt, 0);
2164 if (!tmp || !strlen(tmp)) {
2165 ErrPrint("APPID is NIL\n");
2166 sqlite3_reset(stmt);
2167 sqlite3_finalize(stmt);
2171 appid = strdup(tmp);
2173 ErrPrint("Heap: %s\n", strerror(errno));
2174 sqlite3_reset(stmt);
2175 sqlite3_finalize(stmt);
2179 is_prime = sqlite3_column_int(stmt, 1);
2181 sqlite3_reset(stmt);
2182 sqlite3_finalize(stmt);
2188 EAPI char *livebox_service_lb_script_path(const char *pkgid)
2207 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
2208 if (ret != SQLITE_OK) {
2209 ErrPrint("Error: %s, pkgid(%s), ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2213 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2214 if (ret != SQLITE_OK) {
2215 ErrPrint("Error: %s, pkgid(%s), ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2216 sqlite3_finalize(stmt);
2220 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
2221 if (ret != SQLITE_OK) {
2222 ErrPrint("Error: %s, pkgid(%s), ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2223 sqlite3_finalize(stmt);
2227 ret = sqlite3_step(stmt);
2228 if (ret != SQLITE_ROW) {
2229 ErrPrint("Error: %s, pkgid(%s), ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2230 sqlite3_reset(stmt);
2231 sqlite3_finalize(stmt);
2235 appid = (char *)sqlite3_column_text(stmt, 0);
2236 if (!appid || !strlen(appid)) {
2237 ErrPrint("Invalid appid : %s, pkgid(%s)\n", sqlite3_errmsg(handle), pkgid);
2238 sqlite3_reset(stmt);
2239 sqlite3_finalize(stmt);
2243 lb_src = (char *)sqlite3_column_text(stmt, 1);
2244 if (!lb_src || !strlen(lb_src)) {
2245 ErrPrint("No records for lb src : %s, pkgid(%s), appid(%s)\n", sqlite3_errmsg(handle), pkgid, appid);
2246 sqlite3_reset(stmt);
2247 sqlite3_finalize(stmt);
2251 path = strdup(lb_src);
2253 ErrPrint("Heap: %s\n", strerror(errno));
2254 sqlite3_reset(stmt);
2255 sqlite3_finalize(stmt);
2259 DbgPrint("LB Src: %s\n", path);
2260 sqlite3_reset(stmt);
2261 sqlite3_finalize(stmt);
2267 EAPI char *livebox_service_lb_script_group(const char *pkgid)
2285 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
2286 if (ret != SQLITE_OK) {
2287 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2291 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2292 if (ret != SQLITE_OK) {
2293 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2294 sqlite3_finalize(stmt);
2298 ret = sqlite3_step(stmt);
2299 if (ret != SQLITE_ROW) {
2300 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2301 sqlite3_reset(stmt);
2302 sqlite3_finalize(stmt);
2306 tmp = (char *)sqlite3_column_text(stmt, 0);
2307 if (tmp && strlen(tmp)) {
2308 group = strdup(tmp);
2310 ErrPrint("Heap: %s\n", strerror(errno));
2314 sqlite3_reset(stmt);
2315 sqlite3_finalize(stmt);
2321 EAPI char *livebox_service_pd_script_path(const char *pkgid)
2340 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
2341 if (ret != SQLITE_OK) {
2342 ErrPrint("Error: %s pkgid(%s) ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2346 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2347 if (ret != SQLITE_OK) {
2348 ErrPrint("Error: %s pkgid(%s) ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2349 sqlite3_finalize(stmt);
2353 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
2354 if (ret != SQLITE_OK) {
2355 ErrPrint("Error: %s pkgid(%s) ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2356 sqlite3_finalize(stmt);
2360 ret = sqlite3_step(stmt);
2361 if (ret != SQLITE_ROW) {
2362 ErrPrint("Error: %s pkgid(%s) ret(%d)\n", sqlite3_errmsg(handle), pkgid, ret);
2363 sqlite3_reset(stmt);
2364 sqlite3_finalize(stmt);
2368 appid = (char *)sqlite3_column_text(stmt, 0);
2369 if (!appid || !strlen(appid)) {
2370 ErrPrint("Error: %s pkgid(%s)\n", sqlite3_errmsg(handle), pkgid);
2371 sqlite3_reset(stmt);
2372 sqlite3_finalize(stmt);
2376 pd_src = (char *)sqlite3_column_text(stmt, 1);
2377 if (!pd_src || !strlen(pd_src)) {
2378 ErrPrint("Error: %s pkgid(%s) appid(%s)\n", sqlite3_errmsg(handle), pkgid, appid);
2379 sqlite3_reset(stmt);
2380 sqlite3_finalize(stmt);
2384 path = strdup(pd_src);
2386 ErrPrint("Heap: %s\n", strerror(errno));
2387 sqlite3_reset(stmt);
2388 sqlite3_finalize(stmt);
2392 DbgPrint("PD Src: %s\n", path);
2393 sqlite3_reset(stmt);
2394 sqlite3_finalize(stmt);
2400 EAPI char *livebox_service_pd_script_group(const char *pkgid)
2418 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
2419 if (ret != SQLITE_OK) {
2420 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2424 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
2425 if (ret != SQLITE_OK) {
2426 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2427 sqlite3_finalize(stmt);
2431 ret = sqlite3_step(stmt);
2432 if (ret != SQLITE_ROW) {
2433 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2434 sqlite3_reset(stmt);
2435 sqlite3_finalize(stmt);
2439 tmp = (char *)sqlite3_column_text(stmt, 0);
2440 if (tmp && strlen(tmp)) {
2441 group = strdup(tmp);
2443 ErrPrint("Heap: %s\n", strerror(errno));
2446 sqlite3_reset(stmt);
2447 sqlite3_finalize(stmt);
2453 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
2457 const char *cluster;
2462 return LB_STATUS_ERROR_INVALID;
2467 return LB_STATUS_ERROR_IO;
2471 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
2472 if (ret != SQLITE_OK) {
2473 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2474 cnt = LB_STATUS_ERROR_IO;
2478 while (sqlite3_step(stmt) == SQLITE_ROW) {
2479 cluster = (const char *)sqlite3_column_text(stmt, 0);
2480 if (!cluster || !strlen(cluster)) {
2484 if (cb(cluster, data) < 0) {
2491 sqlite3_reset(stmt);
2492 sqlite3_finalize(stmt);
2498 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
2502 const char *category;
2506 if (!cluster || !cb) {
2507 return LB_STATUS_ERROR_INVALID;
2512 return LB_STATUS_ERROR_IO;
2515 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
2516 if (ret != SQLITE_OK) {
2517 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
2518 cnt = LB_STATUS_ERROR_IO;
2523 while (sqlite3_step(stmt) == SQLITE_ROW) {
2524 category = (const char *)sqlite3_column_text(stmt, 0);
2525 if (!category || !strlen(category)) {
2529 if (cb(cluster, category, data) < 0) {
2536 sqlite3_reset(stmt);
2537 sqlite3_finalize(stmt);
2543 EAPI int livebox_service_init(void)
2545 if (s_info.handle) {
2546 DbgPrint("Already initialized\n");
2547 s_info.init_count++;
2551 s_info.handle = open_db();
2552 if (s_info.handle) {
2553 s_info.init_count++;
2557 return LB_STATUS_ERROR_IO;
2560 EAPI int livebox_service_fini(void)
2562 if (!s_info.handle || s_info.init_count <= 0) {
2563 ErrPrint("Service is not initialized\n");
2564 return LB_STATUS_ERROR_IO;
2567 s_info.init_count--;
2568 if (s_info.init_count > 0) {
2569 DbgPrint("Init count %d\n", s_info.init_count);
2573 db_util_close(s_info.handle);
2574 s_info.handle = NULL;
2578 EAPI int livebox_service_get_size(int type, int *width, int *height)
2591 return convert_size_from_type(type, width, height);
2594 EAPI int livebox_service_size_type(int width, int height)
2598 if (update_resolution() < 0) {
2599 ErrPrint("Failed to update the size list\n");
2602 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
2603 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height) {
2610 return LB_SIZE_TYPE_1x1;
2612 return LB_SIZE_TYPE_2x1;
2614 return LB_SIZE_TYPE_2x2;
2616 return LB_SIZE_TYPE_4x1;
2618 return LB_SIZE_TYPE_4x2;
2620 return LB_SIZE_TYPE_4x3;
2622 return LB_SIZE_TYPE_4x4;
2624 return LB_SIZE_TYPE_4x5;
2626 return LB_SIZE_TYPE_4x6;
2628 return LB_SIZE_TYPE_EASY_1x1;
2630 return LB_SIZE_TYPE_EASY_3x1;
2632 return LB_SIZE_TYPE_EASY_3x3;
2634 return LB_SIZE_TYPE_0x0;
2639 return LB_SIZE_TYPE_UNKNOWN;