sync with master
authorJinkun Jang <jinkun.jang@samsung.com>
Sat, 16 Mar 2013 12:47:49 +0000 (21:47 +0900)
committerJinkun Jang <jinkun.jang@samsung.com>
Sat, 16 Mar 2013 12:47:49 +0000 (21:47 +0900)
13 files changed:
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
include/debug.h [new file with mode: 0644]
include/dlist.h [new file with mode: 0644]
include/livebox-service.h [new file with mode: 0644]
include/livebox-service_PG.h [new file with mode: 0644]
include/util.h [new file with mode: 0644]
liblivebox-service.manifest [new file with mode: 0644]
livebox-service.pc.in [new file with mode: 0644]
packaging/liblivebox-service.spec [new file with mode: 0644]
src/dlist.c [new file with mode: 0644]
src/livebox-service.c [new file with mode: 0644]
src/util.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3dfdcdd
--- /dev/null
@@ -0,0 +1,59 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(livebox-service C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(PROJECT_NAME "${PROJECT_NAME}")
+SET(LIBDIR "\${exec_prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}")
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.0.1")
+
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+       dlog
+       glib-2.0
+       gio-2.0
+       com-core
+       sqlite3
+       db-util
+       pkgmgr
+       x11
+       vconf
+       ail
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -g")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-DLOG_TAG=\"LIVEBOX_SERVICE\"")
+ADD_DEFINITIONS("-DNDEBUG")
+ADD_DEFINITIONS("-DSERVICE_SOCKET=\"/opt/usr/share/live_magazine/.service.socket\"")
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED
+       src/dlist.c
+       src/livebox-service.c
+       src/util.c
+)
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
+
+CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
+SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc")
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/livebox-service.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/livebox-service_PG.h DESTINATION /usr/share/doc/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}")
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..27daa90
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,83 @@
+Flora License 
+
+Version 1.0, May, 2012 
+
+http://www.tizenopensource.org/license 
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 
+
+1. Definitions. 
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 
+
+"Tizen Certified Platform" shall mean a software platform that complies with the standards set forth in the Compatibility Definition Document and passes the Compatibility Test Suite as defined from time to time by the Tizen Technical Steering Group and certified by the Tizen Association or its designated agent. 
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work solely as incorporated into a Tizen Certified Platform, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work solely as incorporated into a Tizen Certified Platform to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof pursuant to the copyright license above, in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 
+
+You must give any other recipients of the Work or Derivative Works a copy of this License; and 
+You must cause any modified files to carry prominent notices stating that You changed the files; and 
+You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 
+If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 
+
+END OF TERMS AND CONDITIONS 
+
+APPENDIX: How to apply the Flora License to your work 
+
+To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 
+
+   Copyright [yyyy] [name of copyright owner] 
+
+
+   Licensed under the Flora License, Version 1.0 (the "License"); 
+
+   you may not use this file except in compliance with the License. 
+
+   You may obtain a copy of the License at 
+
+
+       http://www.tizenopensource.org/license 
+
+
+   Unless required by applicable law or agreed to in writing, software 
+
+   distributed under the License is distributed on an "AS IS" BASIS, 
+
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+
+   See the License for the specific language governing permissions and 
+
+   limitations under the License. 
diff --git a/include/debug.h b/include/debug.h
new file mode 100644 (file)
index 0000000..2d2748e
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(FLOG)
+#define DbgPrint(format, arg...)       LOGD("[\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg)
+#define ErrPrint(format, arg...)       LOGE("[\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg)
+#else
+extern FILE *__file_log_fp;
+#define DbgPrint(format, arg...) do { fprintf(__file_log_fp, "[LOG] [\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
+
+#define ErrPrint(format, arg...) do { fprintf(__file_log_fp, "[ERR] [\e[32m%s/%s\e[0m:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
+#endif
+
+/* End of a file */
diff --git a/include/dlist.h b/include/dlist.h
new file mode 100644 (file)
index 0000000..b4a5719
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define dlist_remove_data(list, data) do { \
+       struct dlist *l; \
+       l = dlist_find_data(list, data); \
+       list = dlist_remove(list, l); \
+} while (0)
+
+#define dlist_foreach(list, l, data) \
+       for ((l) = (list); (l) && ((data) = dlist_data(l)); (l) = dlist_next(l))
+
+#define dlist_foreach_safe(list, l, n, data) \
+       for ((l) = (list), (n) = dlist_next(l); \
+               (l) && ((data) = dlist_data(l)); \
+               (l) = (n), (n) = dlist_next(l))
+
+struct dlist;
+
+extern struct dlist *dlist_append(struct dlist *list, void *data);
+extern struct dlist *dlist_prepend(struct dlist *list, void *data);
+extern struct dlist *dlist_remove(struct dlist *list, struct dlist *l);
+extern struct dlist *dlist_find_data(struct dlist *list, void *data);
+extern void *dlist_data(struct dlist *l);
+extern struct dlist *dlist_next(struct dlist *l);
+extern struct dlist *dlist_prev(struct dlist *l);
+extern int dlist_count(struct dlist *l);
+extern struct dlist *dlist_nth(struct dlist *l, int nth);
+
+/* End of a file */
diff --git a/include/livebox-service.h b/include/livebox-service.h
new file mode 100644 (file)
index 0000000..1de8c31
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LIVEBOX_SERVICE_H
+#define __LIVEBOX_SERVICE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NR_OF_SIZE_LIST 10
+
+enum livebox_size_type {
+       LB_SIZE_TYPE_1x1 = 0x0001,
+       LB_SIZE_TYPE_2x1 = 0x0002,
+       LB_SIZE_TYPE_2x2 = 0x0004,
+       LB_SIZE_TYPE_4x1 = 0x0008,
+       LB_SIZE_TYPE_4x2 = 0x0010,
+       LB_SIZE_TYPE_4x3 = 0x0020,
+       LB_SIZE_TYPE_4x4 = 0x0040,
+       LB_SIZE_TYPE_EASY_1x1 = 0x0100,
+       LB_SIZE_TYPE_EASY_3x1 = 0x0200,
+       LB_SIZE_TYPE_EASY_3x3 = 0x0400,
+       LB_SIZE_TYPE_UNKNOWN = 0xFFFF,
+};
+
+/*!
+ * \brief
+ * \param[in] type
+ * \param[out] width
+ * \param[out] height
+ * \return 0 for success
+ */
+extern int livebox_service_get_size(int type, int *width, int *height);
+
+/*!
+ * \brief
+ * \param[in] width
+ * \param[in] height
+ * \return Type of a livebox
+ */
+extern int livebox_service_size_type(int width, int height);
+
+/*!
+ * \brief
+ * \param[in] pkgid Livebox's appid
+ * \return true(1) / false(0)
+ */
+extern int livebox_service_mouse_event(const char *pkgid);
+
+/*!
+ * \brief
+ * \param[in] pkgid Livebox's appid
+ * \return true(1) / false(0)
+ */
+extern int livebox_service_touch_effect(const char *pkgid);
+
+/*!
+ * \brief
+ * \param[in] pkgname Livebox package name
+ * \param[in] id Set NULL if you don't know what the Id is.
+ * \param[in] cluster Cluster name. Default NULL
+ * \param[in] category Category name, Default NULL
+ * \param[in] force 1 if you want to update your livebox even if the provider is paused or 0. 0 is default
+ */
+extern int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force);
+
+/*!
+ * \brief Change the period of given livebox instance
+ * \param[in] pkgname Livebox package name
+ * \param[in] id Livebox instance id
+ * \param[in] period New update period in sec
+ */
+extern int livebox_service_change_period(const char *pkgname, const char *id, double period);
+
+/*!
+ * \brief Synchronous package list getter
+ *        callback (appid, lbid, is_prime)
+ *        appid == Application Package ID (pkgname)
+ *        lbid = Livebox Package ID
+ *        is_prime = 1 if the livebox is default one for associated application package
+ * \param[in] cb Callback function
+ * \return Count of livebox packages or errno (-EIO, -EINVAL)
+ */
+extern int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *lbid, int is_prime, void *data), void *data);
+
+/*!
+ * \brief Get the pkgname of a primary livebox using given lbid or pkgid.
+ * \param[in] id Livebox Id or Package Id
+ * \return pkgname String which is allocated on the heap
+ */
+extern char *livebox_service_pkgname(const char *id);
+
+/*!
+ * \brief Check the pirmary flag of given livebox Id.
+ * \param[in] lbid Livebox Id
+ * \return int 0 if is not a primary or 1
+ */
+extern int livebox_service_is_primary(const char *lbid);
+
+/*!
+ * \brief Get the name of a livebox (provider name == livebox appid), you have to release the return value after use it
+ * \param[in] Livebox AppID
+ * \return Livebox AppId (Same with input)
+ */
+extern char *livebox_service_provider_name(const char *lbid);
+
+/*!
+ * \brief Get the appId of setup app which is specified by given livebox Id's manifest.
+ * \param[in] Livebox AppId
+ * \return Setup AppId if exists or NULL
+ */
+extern char *livebox_service_setup_appid(const char *lbid);
+
+/*!
+ *\brief Get the application pkgname(appid) of given livebox package name, <manifest package="AAA">
+ * \param[in] pkgname
+ * \return appid String which is allocated on the heap
+ */
+extern char *livebox_service_appid(const char *pkgname);
+
+/*!
+ * \brief Internationalized name of given livebox package.
+ *        USER must has to do "free" after using the returned string.
+ * \param[in] pkgid App ID of a livebox. (It must has to be a livebox package ID. not the UI-APP and the PACKAGE.
+ * \param[in] lang locale(en-us, ko-kr, ...), if it is NULL, function will use the system locale automatically
+ * \return name if it fails to get name, returns NULL, or allocated heap address.
+ */
+extern char *livebox_service_i18n_name(const char *pkgid, const char *lang);
+
+/*!
+ * \brief
+ * \param[in] pkgid livebox ID. NOT the UI-APP ID and PACKAGE ID
+ * \param[in] size_type
+ * \return path preview image path
+ */
+extern char *livebox_service_preview(const char *pkgid, int size_type);
+
+/*!
+ * \brief Get the default content string of the given livebox
+ * \param[in] pkgid Livebox ID. Not the UI-APP ID and PACKAGE ID
+ * \return content content string
+ */
+extern char *livebox_service_content(const char *pkgid);
+
+/*!
+ * \brief Internationalized icon path of given livebox package.
+ *        USER must has to do "free" after using the returned string.
+ * \param[in] pkgid App ID of a livebox. (It must has to be a livebox package ID. not the UI-APP and the PACKAGE.
+ * \param[in] lang locale(en-us, ko-kr, ...), if it is NULL, function will use the system locale automatically
+ * \return name if it fails to get path of an icon, returns NULL, or allocated heap address.
+ */
+extern char *livebox_service_i18n_icon(const char *pkgid, const char *lang);
+
+/*!
+ * \brief Get the path of the plug-in module
+ * \param[in] appid Package name of a livebox
+ * \return path String which is allocated on the heap
+ */
+extern char *livebox_service_libexec(const char *appid);
+
+/*!
+ * \brief Get the "nodisplay" value
+ * \param[in] pkgid Livebox package id.
+ * \return true/false
+ */
+extern int livebox_service_nodisplay(const char *pkgid);
+
+/*!
+ * \brief Check the status of the livebox
+ * \param[in] lbid Livebox Id
+ * \return int 1 enabled, 0 disabled
+ */
+extern int livebox_service_is_enabled(const char *lbid);
+
+/*!
+ * \brief
+ * \param[in]
+ * \return
+ */
+extern char *livebox_service_lb_script_path(const char *pkgid);
+
+/*!
+ * \brief
+ * \param[in]
+ * \return
+ */
+extern char *livebox_service_lb_script_group(const char *pkgid);
+
+/*!
+ * \brief
+ * \param[in]
+ * \return
+ */
+extern char *livebox_service_pd_script_path(const char *pkgid);
+
+/*!
+ * \brief
+ * \param[in]
+ * \return
+ */
+extern char *livebox_service_pd_script_group(const char *pkgid);
+
+/*!
+ * \brief
+ * \return
+ */
+extern int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h);
+
+/*!
+ * \brief
+ * \return
+ */
+extern int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types);
+
+/*!
+ */
+extern int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data);
+
+/*!
+ */
+extern int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data);
+
+/*!
+ * \brief
+ * \return
+ */
+extern int livebox_service_init(void);
+
+/*!
+ * \brief
+ * \return
+ */
+extern int livebox_service_fini(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* End of a file */
diff --git a/include/livebox-service_PG.h b/include/livebox-service_PG.h
new file mode 100644 (file)
index 0000000..62077ae
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
diff --git a/include/util.h b/include/util.h
new file mode 100644 (file)
index 0000000..3dd8a74
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern double util_timestamp(void);
+extern const char *util_basename(const char *name);
+extern unsigned long util_free_space(const char *path);
+extern char *util_replace_string(const char *src, const char *pattern, const char *replace);
+extern const char *util_uri_to_path(const char *uri);
+extern int util_validate_livebox_package(const char *pkgname);
+extern char *util_conf_get_libexec(const char *pkgname);
+
+#define SCHEMA_FILE    "file://"
+#define SCHEMA_PIXMAP  "pixmap://"
+#define SCHEMA_SHM     "shm://"
+
+/* End of a file */
diff --git a/liblivebox-service.manifest b/liblivebox-service.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/livebox-service.pc.in b/livebox-service.pc.in
new file mode 100644 (file)
index 0000000..c0abee8
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: livebox-service
+Description: livebox service library
+Version: @VERSION@
+Libs: -L${libdir} -llivebox-service
+Cflags: -I${includedir}
+cppflags: -I${includedir}
diff --git a/packaging/liblivebox-service.spec b/packaging/liblivebox-service.spec
new file mode 100644 (file)
index 0000000..e1d59f6
--- /dev/null
@@ -0,0 +1,57 @@
+Name: liblivebox-service
+Summary: Service API for gathering installed livebox information.
+Version: 0.3.9
+Release: 1
+Group: framework/livebox
+License: Flora License
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake, gettext-tools, coreutils
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(com-core)
+BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(pkgmgr)
+BuildRequires: pkgconfig(x11)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(ail)
+
+%description
+Service API for gathering information of installed liveboxes
+
+%package devel
+Summary: Files for livebox service.
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+Gathering the installed livebox information.
+
+%prep
+%setup -q
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+mkdir -p %{buildroot}/%{_datarootdir}/license
+
+%post
+
+%files -n liblivebox-service
+%manifest liblivebox-service.manifest
+%defattr(-,root,root,-)
+%{_libdir}/*.so*
+%{_datarootdir}/license/*
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/livebox-service/livebox-service.h
+%{_datarootdir}/doc/livebox-service/livebox-service_PG.h
+%{_libdir}/pkgconfig/*.pc
+
+# End of a file
diff --git a/src/dlist.c b/src/dlist.c
new file mode 100644 (file)
index 0000000..56ff060
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "dlist.h"
+
+/*!
+ * \brief
+ * This dlist is called Modified Doubly Linked List.
+ *
+ * Noramlly, The dobule linked list contains address of previous and next element.
+ * This dlist also contains them, but the tail element only contains prev address.
+ *
+ * The head element's prev pointer indicates the last element.
+ * But the last element's next pointer indicates NIL.
+ *
+ * So we can find the last element while crawling this DList
+ * But we have to remember the address of the head element.
+ */
+
+struct dlist {
+       struct dlist *next;
+       struct dlist *prev;
+       void *data;
+};
+
+struct dlist *dlist_append(struct dlist *list, void *data)
+{
+       struct dlist *item;
+
+       item = malloc(sizeof(*item));
+       if (!item)
+               return NULL;
+
+       item->next = NULL;
+       item->data = data;
+
+       if (!list) {
+               item->prev = item;
+
+               list = item;
+       } else {
+               item->prev = list->prev;
+               item->prev->next = item;
+               list->prev = item;
+       }
+
+       assert(!list->prev->next && "item NEXT");
+
+       return list;
+}
+
+struct dlist *dlist_prepend(struct dlist *list, void *data)
+{
+       struct dlist *item;
+
+       item = malloc(sizeof(*item));
+       if (!item)
+               return NULL;
+
+       item->data = data;
+
+       if (!list) {
+               item->prev = item;
+               item->next = NULL;
+       } else {
+               if (list->prev->next)
+                       list->prev->next = item;
+
+               item->prev = list->prev;
+               item->next = list;
+
+               list->prev = item;
+
+       }
+
+       return item;
+}
+
+struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
+{
+       if (!list || !l)
+               return NULL;
+
+       if (l == list)
+               list = l->next;
+       else
+               l->prev->next = l->next;
+
+       if (l->next)
+               l->next->prev = l->prev;
+       /*!
+        * \note
+        * If the removed entry 'l' has no next element, it is the last element.
+        * In this case, check the existence of the list first,
+        * and if the list is not empty, update the 'prev' of the list (which is a head element of the list) 
+        *
+        * If we didn't care about this, the head element(list) can indicates the invalid element.
+        */
+       else if (list)
+               list->prev = l->prev;
+
+       free(l);
+       return list;
+}
+
+struct dlist *dlist_find_data(struct dlist *list, void *data)
+{
+       struct dlist *l;
+       void *_data;
+
+       dlist_foreach(list, l, _data) {
+               if (data == _data)
+                       return l;
+       }
+
+       return NULL;
+}
+
+void *dlist_data(struct dlist *l)
+{
+       return l ? l->data : NULL;
+}
+
+struct dlist *dlist_next(struct dlist *l)
+{
+       return l ? l->next : NULL;
+}
+
+struct dlist *dlist_prev(struct dlist *l)
+{
+       return l ? l->prev : NULL;
+}
+
+int dlist_count(struct dlist *l)
+{
+       register int i;
+       struct dlist *n;
+       void *data;
+
+       i = 0;
+       dlist_foreach(l, n, data) {
+               i++;
+       }
+
+       return i;
+}
+
+struct dlist *dlist_nth(struct dlist *l, int nth)
+{
+       register int i;
+       struct dlist *n;
+
+       i = 0;
+       for (n = l; n; n = n->next) {
+               if (i == nth)
+                       return n;
+               i++;
+       }
+
+       return NULL;
+}
+
+/* End of a file */
diff --git a/src/livebox-service.c b/src/livebox-service.c
new file mode 100644 (file)
index 0000000..1d52caf
--- /dev/null
@@ -0,0 +1,1945 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h> /* malloc */
+#include <string.h> /* strdup, strerror */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sqlite3.h>
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <ctype.h>
+
+#include <com-core_packet.h>
+#include <packet.h>
+#include <dlog.h>
+#include <db-util.h>
+#include <package-manager.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <ail.h>
+
+#include "dlist.h"
+#include "util.h"
+#include "debug.h"
+#include "livebox-service.h"
+
+#define SAMSUNG_PREFIX "com.samsung."
+#define EAPI __attribute__((visibility("default")))
+#define DEFAULT_TIMEOUT 2.0
+#define MAX_COLUMN 80
+
+static struct supported_size_list {
+       int w;
+       int h;
+} SIZE_LIST[NR_OF_SIZE_LIST] = {
+       { 172, 172 }, /*!< 1x1 */
+       { 348, 172 }, /*!< 2x1 */
+       { 348, 348 }, /*!< 2x2 */
+       { 700, 172 }, /*!< 4x1 */
+       { 700, 348 }, /*!< 4x2 */
+       { 700, 520 }, /*!< 4x3 */
+       { 700, 700 }, /*!< 4x4 */
+       { 207, 207 }, /*!< 21x21 */
+       { 645, 207 }, /*!< 23x21 */
+       { 645, 645 }, /*!< 23x23 */
+};
+
+static struct info {
+       sqlite3 *handle;
+       const char *dbfile;
+       const char *conf_file;
+       int init_count;
+       int res_resolved;
+} s_info = {
+       .handle = NULL,
+       .dbfile = "/opt/dbspace/.livebox.db", 
+       .conf_file = "/usr/share/data-provider-master/resolution.ini",
+       .init_count = 0,
+       .res_resolved = 0,
+};
+
+static inline int update_info(int width_type, int height_type, int width, int height)
+{
+       int idx;
+
+       if (width_type == 1 && height_type == 1) {
+               DbgPrint("1x1 Updated to %dx%d\n", width, height);
+               idx = 0;
+       } else if (width_type == 2 && height_type == 1) {
+               DbgPrint("2x1 Updated to %dx%d\n", width, height);
+               idx = 1;
+       } else if (width_type == 2 && height_type == 2) {
+               DbgPrint("2x2 Updated to %dx%d\n", width, height);
+               idx = 2;
+       } else if (width_type == 4 && height_type == 1) {
+               DbgPrint("4x1 Updated to %dx%d\n", width, height);
+               idx = 3;
+       } else if (width_type == 4 && height_type == 2) {
+               DbgPrint("4x2 Updated to %dx%d\n", width, height);
+               idx = 4;
+       } else if (width_type == 4 && height_type == 3) {
+               DbgPrint("4x3 Updated to %dx%d\n", width, height);
+               idx = 5;
+       } else if (width_type == 4 && height_type == 4) {
+               DbgPrint("4x4 Updated to %dx%d\n", width, height);
+               idx = 6;
+       } else if (width_type == 21 && height_type == 21) {
+               DbgPrint("Easy 1x1 Updated to %dx%d\n", width, height);
+               idx = 7;
+       } else if (width_type == 23 && height_type == 21) {
+               DbgPrint("Easy 3x1 Updated to %dx%d\n", width, height);
+               idx = 8;
+       } else if (width_type == 23 && height_type == 23) {
+               DbgPrint("Easy 3x3 Updated to %dx%d\n", width, height);
+               idx = 9;
+       } else {
+               ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
+               return 0;
+       }
+
+       SIZE_LIST[idx].w = width;
+       SIZE_LIST[idx].h = height;
+       return 1;
+}
+
+static inline int update_from_file(void)
+{
+       FILE *fp;
+       int updated;
+       int width_type;
+       int height_type;
+       int width;
+       int height;
+       char buffer[MAX_COLUMN];
+       int ch;
+       int idx;
+       enum status {
+               START = 0x0,
+               TYPE = 0x01,
+               SIZE = 0x02,
+               COMMENT = 0x03,
+               ERROR = 0x04,
+               EOL = 0x05,
+               TYPE_END = 0x06,
+               SIZE_START = 0x07,
+       } status;
+
+       fp = fopen(s_info.conf_file, "r");
+       if (!fp) {
+               ErrPrint("Open failed: %s\n", strerror(errno));
+               return -EIO;
+       }
+
+       updated = 0;
+       status = START;
+       idx = 0;
+       do {
+               ch = fgetc(fp);
+
+               if (idx == MAX_COLUMN) {
+                       ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
+                       status = ERROR;
+               }
+
+               switch (status) {
+               case START:
+                       if (isspace(ch) || ch == EOF)
+                               continue;
+
+                       if (ch == '#') {
+                               status = COMMENT;
+                       } else {
+                               status = TYPE;
+                               idx = 0;
+                               ungetc(ch, fp);
+                       }
+                       break;
+               case TYPE:
+                       if (isblank(ch)) {
+                               buffer[idx] = '\0';
+                               status = TYPE_END;
+                               if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
+                                       ErrPrint("Invalid syntax: [%s]\n", buffer);
+                                       status = ERROR;
+                               }
+                               break;
+                       } else if (ch == '=') {
+                               buffer[idx] = '\0';
+                               status = SIZE_START;
+                               if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
+                                       ErrPrint("Invalid syntax: [%s]\n", buffer);
+                                       status = ERROR;
+                               }
+                               break;
+                       } else if (ch == EOF) {
+                               ErrPrint("Invalid Syntax\n");
+                               status = ERROR;
+                               continue;
+                       }
+                       buffer[idx++] = ch;
+                       break;
+               case TYPE_END:
+                       if (ch == '=')
+                               status = SIZE_START;
+                       break;
+               case SIZE_START:
+                       if (isspace(ch) || ch == EOF)
+                               continue;
+
+                       status = SIZE;
+                       idx = 0;
+                       ungetc(ch, fp);
+                       break;
+               case SIZE:
+                       if (isspace(ch) || ch == EOF) {
+                               buffer[idx] = '\0';
+                               status = EOL;
+
+                               if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
+                                       ErrPrint("Invalid syntax: [%s]\n", buffer);
+                                       status = ERROR;
+                               } else if (ch == EOF) {
+                                       updated += update_info(width_type, height_type, width, height);
+                               }
+                               break;
+                       }
+                       buffer[idx++] = ch;
+                       break;
+               case EOL:
+                       updated += update_info(width_type, height_type, width, height);
+                       status = START;
+                       ungetc(ch, fp);
+                       break;
+               case ERROR:
+                       if (ch == '\n' || ch == '\r' || ch == '\f')
+                               status = START;
+                       break;
+               case COMMENT:
+                       if (ch == '\n' || ch == '\r' || ch == '\f')
+                               status = START;
+                       break;
+               default:
+                       ErrPrint("Unknown status. couldn't be reach to here\n");
+                       break;
+               }
+       } while (!feof(fp));
+       fclose(fp);
+
+       return NR_OF_SIZE_LIST - updated;
+}
+
+static int update_resolution(void)
+{
+       Display *disp;
+       Window root;
+       Window dummy;
+       int x, y;
+       unsigned int width;
+       unsigned int height;
+       unsigned int border;
+       unsigned int depth;
+       register int i;
+
+       if (s_info.res_resolved)
+               return 0;
+
+       disp = XOpenDisplay(NULL);
+       if (!disp) {
+               ErrPrint("Failed to open a display\n");
+               return -EFAULT;
+       }
+
+       root = XDefaultRootWindow(disp);
+       if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
+               XCloseDisplay(disp);
+               return -EFAULT;
+       }
+
+       if (update_from_file() == 0)
+               DbgPrint("Resolution info is all updated by file\n");
+
+       DbgPrint("Screen resolution: %dx%d\n", width, height);
+       for (i = 0; i < NR_OF_SIZE_LIST; i++) {
+               SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
+               SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)width / 720.0f);
+               DbgPrint("(Ratio)Size is updated [%d] %dx%d\n", i, SIZE_LIST[i].w, SIZE_LIST[i].h);
+       }
+
+       XCloseDisplay(disp);
+       s_info.res_resolved = 1;
+       return 0;
+}
+
+static inline sqlite3 *open_db(void)
+{
+       sqlite3 *handle;
+
+       if (!s_info.handle) {
+               int ret;
+
+               ret = db_util_open(s_info.dbfile, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
+               if (ret != SQLITE_OK) {
+                       ErrPrint("Failed to open a DB\n");
+                       return NULL;
+               }
+       } else {
+               handle = s_info.handle;
+       }
+
+       return handle;
+}
+
+static inline void close_db(sqlite3 *handle)
+{
+       if (!s_info.handle)
+               db_util_close(handle);
+}
+
+static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
+{
+       int idx;
+
+       switch (type) {
+       case LB_SIZE_TYPE_1x1: /*!< 172x172 */
+               idx = 0;
+               break;
+       case LB_SIZE_TYPE_2x1: /*!< 348x172 */
+               idx = 1;
+               break;
+       case LB_SIZE_TYPE_2x2: /*!< 348x348 */
+               idx = 2;
+               break;
+       case LB_SIZE_TYPE_4x1: /*!< 700x172 */
+               idx = 3;
+               break;
+       case LB_SIZE_TYPE_4x2: /*!< 700x348 */
+               idx = 4;
+               break;
+       case LB_SIZE_TYPE_4x3: /*!< 700x520 */
+               idx = 5;
+               break;
+       case LB_SIZE_TYPE_4x4: /*!< 700x700 */
+               idx = 6;
+               break;
+       case LB_SIZE_TYPE_EASY_1x1: /*< 207x207 */
+               idx = 7;
+               break;
+       case LB_SIZE_TYPE_EASY_3x1: /*!< 645x207 */
+               idx = 8;
+               break;
+       case LB_SIZE_TYPE_EASY_3x3: /*!< 645x645 */
+               idx = 9;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (update_resolution() < 0)
+               ErrPrint("Failed to update resolution\n");
+
+       *width = SIZE_LIST[idx].w;
+       *height = SIZE_LIST[idx].h;
+       return 0;
+}
+
+EAPI int livebox_service_change_period(const char *pkgname, const char *id, double period)
+{
+       struct packet *packet;
+       struct packet *result;
+       int ret;
+
+       if (!pkgname || !id || period < 0.0f) {
+               ErrPrint("Invalid argument\n");
+               return -EINVAL;
+       }
+
+       if (!id)
+               id = "";
+
+       packet = packet_create("service_change_period", "ssd", pkgname, id, period);
+       if (!packet) {
+               ErrPrint("Failed to create a packet for period changing\n");
+               return -EFAULT;
+       }
+
+       result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
+       packet_unref(packet);
+
+       if (result) {
+               if (packet_get(result, "i", &ret) != 1) {
+                       ErrPrint("Failed to parse a result packet\n");
+                       ret = -EINVAL;
+               }
+               packet_unref(result);
+       } else {
+               ErrPrint("Failed to get result packet\n");
+               ret = -EFAULT;
+       }
+
+       return ret;
+}
+
+EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force)
+{
+       struct packet *packet;
+       struct packet *result;
+       int ret;
+
+       if (!pkgname) {
+               ErrPrint("Invalid argument\n");
+               return -EINVAL;
+       }
+
+       if (!force && access("/tmp/.live.paused", R_OK) == 0) {
+               DbgPrint("Provider is paused\n");
+               return -ECANCELED;
+       }
+
+       if (!id)
+               id = "";
+
+       if (!cluster)
+               cluster = "user,created";
+
+       if (!category)
+               category = "default";
+
+       packet = packet_create("service_update", "ssss", pkgname, id, cluster, category);
+       if (!packet) {
+               ErrPrint("Failed to create a packet for service_update\n");
+               return -EFAULT;
+       }
+
+       result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
+       packet_unref(packet);
+
+       if (result) {
+               if (packet_get(result, "i", &ret) != 1) {
+                       ErrPrint("Failed to parse a result packet\n");
+                       ret = -EINVAL;
+               }
+
+               packet_unref(result);
+       } else {
+               ErrPrint("Failed to get result packet\n");
+               ret = -EFAULT;
+       }
+
+       return ret;
+}
+
+EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
+{
+       int ret;
+       sqlite3_stmt *stmt;
+       char *appid;
+       char *pkgid;
+       int is_prime;
+       sqlite3 *handle;
+
+       if (!cb)
+               return -EINVAL;
+
+       handle = open_db();
+       if (!handle)
+               return -EIO;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = -EIO;
+               goto out;
+       }
+
+       ret = 0;
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               appid = (char *)sqlite3_column_text(stmt, 0);
+               if (!appid || !strlen(appid)) {
+                       ErrPrint("APPID is not valid\n");
+                       continue;
+               }
+
+               pkgid = (char *)sqlite3_column_text(stmt, 1);
+               if (!pkgid || !strlen(pkgid)) {
+                       ErrPrint("pkgid is not valid\n");
+                       continue;
+               }
+
+               is_prime = sqlite3_column_int(stmt, 2);
+
+               ret++;
+
+               if (cb(appid, pkgid, is_prime, data) < 0) {
+                       DbgPrint("Callback stopped package crawling\n");
+                       break;
+               }
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+
+out:
+       close_db(handle);
+       return ret;
+}
+
+EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int size;
+       int ret;
+
+       if (!types || !cnt || !pkgid)
+               return -EINVAL;
+
+       handle = open_db();
+       if (!handle)
+               return -EIO;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = -EIO;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               ret = -EIO;
+               goto out;
+       }
+
+       if (*cnt > NR_OF_SIZE_LIST)
+               *cnt = NR_OF_SIZE_LIST;
+
+       ret = 0;
+       while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
+               size = sqlite3_column_int(stmt, 0);
+               types[ret] = size;
+               ret++;
+       }
+
+       *cnt = ret;
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       ret = 0;
+out:
+       close_db(handle);
+       return ret;
+}
+
+static inline char *cur_locale(void)
+{
+       char *language;
+       language = vconf_get_str(VCONFKEY_LANGSET);
+       if (language) {
+               char *ptr;
+
+               ptr = language;
+               while (*ptr) {
+                       if (*ptr == '.') {
+                               *ptr = '\0';
+                               break;
+                       }
+
+                       if (*ptr == '_')
+                               *ptr = '-';
+
+                       ptr++;
+               }
+       } else {
+               language = strdup("en-us");
+               if (!language)
+                       ErrPrint("Heap: %s\n", strerror(errno));
+       }
+
+       return language;
+}
+
+static inline char *get_default_name(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       char *name = NULL;
+       int ret;
+
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret ==  SQLITE_ROW) {
+               const char *tmp;
+
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (tmp && strlen(tmp)) {
+                       name = strdup(tmp);
+                       if (!name)
+                               ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return name;
+}
+
+static inline char *get_default_icon(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       char *icon = NULL;
+       int ret;
+
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               const char *tmp;
+
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (tmp && strlen(tmp)) {
+                       icon = strdup(tmp);
+                       if (!icon)
+                               ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return icon;
+}
+
+EAPI char *livebox_service_content(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       char *content = NULL;
+       int ret;
+
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               const char *tmp;
+
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (tmp && strlen(tmp)) {
+                       content = strdup(tmp);
+                       if (!content)
+                               ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return content;
+}
+
+EAPI char *livebox_service_setup_appid(const char *lbid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *appid;
+
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       appid = NULL;
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               const char *tmp;
+
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (!tmp || !strlen(tmp))
+                       goto out;
+
+               appid = strdup(tmp);
+               if (!appid)
+                       ErrPrint("Error: %s\n", strerror(errno));
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return appid;
+}
+
+EAPI int livebox_service_nodisplay(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+
+       handle = open_db();
+       if (!handle)
+               return 0;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return 0;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = 0;
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW)
+               ret = !!sqlite3_column_int(stmt, 0);
+       else
+               ret = 0;
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return ret;
+}
+
+static inline char *get_lb_pkgname_by_appid(const char *appid)
+{
+       sqlite3_stmt *stmt;
+       char *pkgid;
+       char *tmp;
+       sqlite3 *handle;
+       int ret;
+
+       if (!appid)
+               return NULL;
+
+       pkgid = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
+               goto out;
+       }
+
+       tmp = (char *)sqlite3_column_text(stmt, 0);
+       if (tmp && strlen(tmp)) {
+               pkgid = strdup(tmp);
+               if (!pkgid)
+                       ErrPrint("Heap: %s\n", strerror(errno));
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return pkgid;
+}
+
+EAPI int livebox_service_touch_effect(const char *pkgid)
+{
+       char *lbid;
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+
+       handle = open_db();
+       if (!handle) {
+               ErrPrint("Unable to open a DB\n");
+               return 1;
+       }
+
+       ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return 1;
+       }
+
+       /*!
+        * \note
+        * This function will validate the "pkgid"
+        * call the exported API in the exported API is not recomended
+        * but... I used.
+        */
+       lbid = livebox_service_pkgname(pkgid);
+       if (!lbid) {
+               ErrPrint("Invalid appid (%s)\n", pkgid);
+               ret = 1;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
+       free(lbid);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = 1;
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               ret = !!sqlite3_column_int(stmt, 0);
+       } else {
+               ret = 1; /*!< Default true: In this case the DB is corrupted. */
+               ErrPrint("There is no result\n");
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return ret;
+}
+
+EAPI int livebox_service_mouse_event(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       char *lbid;
+       int ret;
+
+       handle = open_db();
+       if (!handle)
+               return 0;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return 0;
+       }
+
+       lbid = livebox_service_pkgname(pkgid);
+       if (!lbid) {
+               ErrPrint("Failed to get lbid: %s\n", pkgid);
+               ret = 0;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
+       free(lbid);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = 0;
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               ret = !!sqlite3_column_int(stmt, 0);
+       } else {
+               ret = 0; /*!< Default is false, In this case the DB is corrupted */
+               ErrPrint("There is no result.\n");
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return ret;
+}
+
+EAPI char *livebox_service_preview(const char *pkgid, int size_type)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *preview = NULL;
+
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_int(stmt, 2, size_type);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               const char *tmp;
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (tmp && strlen(tmp)) {
+                       preview = strdup(tmp);
+                       if (!preview)
+                               ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return preview;
+}
+
+EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       char *language;
+       char *icon = NULL;
+       int ret;
+
+       if (lang) {
+               language = strdup(lang);
+               if (!language) {
+                       ErrPrint("Heap: %s\n", strerror(errno));
+                       return NULL;
+               }
+       } else {
+               language = cur_locale();
+               if (!language)
+                       return NULL;
+       }
+
+       handle = open_db();
+       if (!handle) {
+               free(language);
+               return NULL;
+       }
+
+       ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               free(language);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               const char *tmp;
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (!tmp || !strlen(tmp)) {
+                       icon = get_default_icon(pkgid);
+               } else {
+                       icon = strdup(tmp);
+                       if (!icon)
+                               ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       } else {
+               icon = get_default_icon(pkgid);
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       free(language);
+       return icon;
+}
+
+EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       char *language;
+       char *name = NULL;
+       int ret;
+
+       if (lang) {
+               language = strdup(lang);
+               if (!language) {
+                       ErrPrint("Error: %s\n", strerror(errno));
+                       return NULL;
+               }
+       } else {
+               language = cur_locale();
+               if (!language)
+                       return NULL;
+       }
+
+       handle = open_db();
+       if (!handle) {
+               free(language);
+               return NULL;
+       }
+
+       ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               free(language);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW) {
+               const char *tmp;
+               tmp = (const char *)sqlite3_column_text(stmt, 0);
+               if (!tmp || !strlen(tmp)) {
+                       name = get_default_name(pkgid);
+               } else {
+                       name = strdup(tmp);
+                       if (!name)
+                               ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       } else {
+               name = get_default_name(pkgid);
+       }
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       free(language);
+       return name;
+}
+
+EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int size;
+       int ret;
+
+       if (!w || !h || !cnt || !pkgid)
+               return -EINVAL;
+
+       handle = open_db();
+       if (!handle)
+               return -EIO;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               ret = -EIO;
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               ret = -EIO;
+               goto out;
+       }
+
+       if (*cnt > NR_OF_SIZE_LIST)
+               *cnt = NR_OF_SIZE_LIST;
+
+       ret = 0;
+       while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
+               size = sqlite3_column_int(stmt, 0);
+               ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
+       }
+
+       *cnt = ret;
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       ret = 0;
+out:
+       close_db(handle);
+       return ret;
+}
+
+EAPI char *livebox_service_libexec(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *libexec;
+       char *appid;
+       char *path;
+
+       if (!pkgid)
+               return NULL;
+
+       libexec = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+
+               libexec = util_conf_get_libexec(pkgid);
+               DbgPrint("Fallback to conf checker: %s\n", libexec);
+               goto out;
+       }
+
+       appid = (char *)sqlite3_column_text(stmt, 0);
+       if (!appid || !strlen(appid)) {
+               ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       path = (char *)sqlite3_column_text(stmt, 1);
+       if (!path || !strlen(path)) {
+               ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       libexec = strdup(path);
+       if (!libexec) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       DbgPrint("libexec: %s\n", libexec);
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return libexec;
+}
+
+EAPI char *livebox_service_pkgname(const char *appid)
+{
+       char *lb_pkgname;
+       pkgmgr_appinfo_h handle;
+       int ret;
+       char *new_appid;
+
+       if (!appid)
+               return NULL;
+
+       lb_pkgname = get_lb_pkgname_by_appid(appid);
+       if (lb_pkgname)
+               return lb_pkgname;
+
+       /*!
+        * \note
+        * Try to get the package id using given appid
+        */
+       ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
+       if (ret != PKGMGR_R_OK) {
+               ErrPrint("Failed to get appinfo\n");
+               return NULL;
+       }
+
+       ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
+       if (ret != PKGMGR_R_OK) {
+               pkgmgr_appinfo_destroy_appinfo(handle);
+               ErrPrint("Failed to get pkgname for (%s)\n", appid);
+               return NULL;
+       }
+
+       lb_pkgname = get_lb_pkgname_by_appid(new_appid);
+       pkgmgr_appinfo_destroy_appinfo(handle);
+
+       if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
+               return strdup(appid);
+
+       return lb_pkgname;
+}
+
+EAPI char *livebox_service_provider_name(const char *lbid)
+{
+       char *ret;
+       int stage = 0;
+       int seq = 0;
+       int idx = 0;
+       char *str = SAMSUNG_PREFIX;
+
+       if (!lbid)
+               return NULL;
+
+       while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
+               idx++;
+               if (seq < 2 && lbid[idx] == '.') {
+                       stage = idx;
+                       seq++;
+               }
+       }
+
+       if (!str[idx] && lbid[idx]) {
+               /* Inhouse */
+               return strdup(lbid);
+       } else if (seq < 2) {
+               while (seq < 2) {
+                       if (lbid[idx] == '.') {
+                               seq++;
+                       } else if (!lbid[idx]) {
+                               ErrPrint("Invalid lbid: %s\n", lbid);
+                               return NULL;
+                       }
+
+                       idx++;
+               }
+
+               stage = idx;
+       } else {
+               stage++;
+       }
+
+       ret = strdup(lbid + stage);
+       if (!ret) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       return ret;
+}
+
+EAPI int livebox_service_is_enabled(const char *lbid)
+{
+       return 1;
+       /*
+       ail_appinfo_h ai;
+       char *pkgname;
+       bool enabled;
+       int ret;
+
+       pkgname = livebox_service_appid(lbid);
+       if (!pkgname)
+               return 0;
+
+       ret = ail_get_appinfo(pkgname, &ai);
+       if (ret != AIL_ERROR_OK) {
+               free(pkgname);
+               return 0;
+       }
+
+       if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
+               enabled = false;
+
+       ail_destroy_appinfo(ai);
+       free(pkgname);
+       return enabled == true;
+       */
+}
+
+EAPI int livebox_service_is_primary(const char *lbid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret = 0;
+
+       if (!lbid)
+               return 0;
+
+       handle = open_db();
+       if (!handle)
+               return 0;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               close_db(handle);
+               return 0;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_column_int(stmt, 1);
+
+out:
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+       close_db(handle);
+       return ret;
+}
+
+/*!
+ * appid == Package ID
+ * pkgid == Livebox ID
+ */
+EAPI char *livebox_service_appid(const char *pkgname)
+{
+       sqlite3_stmt *stmt;
+       char *appid;
+       char *tmp;
+       sqlite3 *handle;
+       int is_prime __attribute__((__unused__));
+       int ret;
+
+       if (!pkgname)
+               return NULL;
+
+       appid = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               pkgmgr_appinfo_h pkg_handle;
+               char *new_appid;
+
+               ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+
+               ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
+               if (ret != PKGMGR_R_OK) {
+                       ErrPrint("Failed to get appinfo: %s\n", pkgname);
+                       goto out;
+               }
+
+               ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
+               if (ret != PKGMGR_R_OK) {
+                       ErrPrint("Failed to get pkgname for (%s)\n", appid);
+                       pkgmgr_appinfo_destroy_appinfo(pkg_handle);
+                       goto out;
+               }
+
+               appid = strdup(new_appid);
+               if (!appid)
+                       ErrPrint("Heap: %s\n", strerror(errno));
+
+               pkgmgr_appinfo_destroy_appinfo(pkg_handle);
+               goto out;
+       }
+
+       tmp = (char *)sqlite3_column_text(stmt, 0);
+       if (!tmp || !strlen(tmp)) {
+               ErrPrint("APPID is NIL\n");
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       appid = strdup(tmp);
+       if (!appid) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       is_prime = sqlite3_column_int(stmt, 1);
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return appid;
+}
+
+EAPI char *livebox_service_lb_script_path(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *path;
+       char *appid;
+       char *lb_src;
+
+       if (!pkgid)
+               return NULL;
+
+       path = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       appid = (char *)sqlite3_column_text(stmt, 0);
+       if (!appid || !strlen(appid)) {
+               ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       lb_src = (char *)sqlite3_column_text(stmt, 1);
+       if (!lb_src || !strlen(lb_src)) {
+               ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       path = strdup(lb_src);
+       if (!path) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       DbgPrint("LB Src: %s\n", path);
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return path;
+}
+
+EAPI char *livebox_service_lb_script_group(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *group;
+       char *tmp;
+
+       if (!pkgid)
+               return NULL;
+
+       group = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       tmp = (char *)sqlite3_column_text(stmt, 0);
+       if (tmp && strlen(tmp)) {
+               group = strdup(tmp);
+               if (!group)
+                       ErrPrint("Heap: %s\n", strerror(errno));
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return group;
+}
+
+EAPI char *livebox_service_pd_script_path(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *path;
+       char *pd_src;
+       const char *appid;
+
+       if (!pkgid)
+               return NULL;
+
+       path = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       appid = (char *)sqlite3_column_text(stmt, 0);
+       if (!appid || !strlen(appid)) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       pd_src = (char *)sqlite3_column_text(stmt, 1);
+       if (!pd_src || !strlen(pd_src)) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       path = strdup(pd_src);
+       if (!path) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       DbgPrint("PD Src: %s\n", path);
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return path;
+}
+
+EAPI char *livebox_service_pd_script_group(const char *pkgid)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       int ret;
+       char *group;
+       char *tmp;
+
+       if (!pkgid)
+               return NULL;
+
+       group = NULL;
+       handle = open_db();
+       if (!handle)
+               return NULL;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               goto out;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               sqlite3_reset(stmt);
+               sqlite3_finalize(stmt);
+               goto out;
+       }
+
+       tmp = (char *)sqlite3_column_text(stmt, 0);
+       if (tmp && strlen(tmp)) {
+               group = strdup(tmp);
+               if (!group)
+                       ErrPrint("Heap: %s\n", strerror(errno));
+       }
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return group;
+}
+
+EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       const char *cluster;
+       int cnt;
+       int ret;
+
+       if (!cb)
+               return -EINVAL;
+
+       handle = open_db();
+       if (!handle)
+               return -EIO;
+
+       cnt = 0;
+       ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               cnt = -EIO;
+               goto out;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               cluster = (const char *)sqlite3_column_text(stmt, 0);
+               if (!cluster || !strlen(cluster))
+                       continue;
+
+               if (cb(cluster, data) < 0)
+                       break;
+
+               cnt++;
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return cnt;
+}
+
+EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
+{
+       sqlite3_stmt *stmt;
+       sqlite3 *handle;
+       const char *category;
+       int cnt;
+       int ret;
+
+       if (!cluster || !cb)
+               return -EINVAL;
+
+       handle = open_db();
+       if (!handle)
+               return -EIO;
+
+       ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
+               cnt = -EIO;
+               goto out;
+       }
+
+       cnt = 0;
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               category = (const char *)sqlite3_column_text(stmt, 0);
+               if (!category || !strlen(category))
+                       continue;
+
+               if (cb(cluster, category, data) < 0)
+                       break;
+
+               cnt++;
+       }
+
+       sqlite3_reset(stmt);
+       sqlite3_finalize(stmt);
+out:
+       close_db(handle);
+       return cnt;
+}
+
+EAPI int livebox_service_init(void)
+{
+       if (s_info.handle) {
+               DbgPrint("Already initialized\n");
+               s_info.init_count++;
+               return 0;
+       }
+
+       s_info.handle = open_db();
+       if (s_info.handle) {
+               s_info.init_count++;
+               return 0;
+       }
+
+       return -EIO;
+}
+
+EAPI int livebox_service_fini(void)
+{
+       if (!s_info.handle || s_info.init_count <= 0) {
+               ErrPrint("Service is not initialized\n");
+               return -EIO;
+       }
+
+       s_info.init_count--;
+       if (s_info.init_count > 0) {
+               DbgPrint("Init count %d\n", s_info.init_count);
+               return 0;
+       }
+
+       db_util_close(s_info.handle);
+       s_info.handle = NULL;
+       return 0;
+}
+
+EAPI int livebox_service_get_size(int type, int *width, int *height)
+{
+       int _width;
+       int _height;
+
+       if (!width)
+               width = &_width;
+
+       if (!height)
+               height = &_height;
+
+       return convert_size_from_type(type, width, height);
+}
+
+EAPI int livebox_service_size_type(int width, int height)
+{
+       int idx;
+
+       if (update_resolution() < 0)
+               ErrPrint("Failed to update the size list\n");
+
+       for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
+               if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
+                       break;
+       }
+
+       switch (idx) {
+       case 0:
+               return LB_SIZE_TYPE_1x1;
+       case 1:
+               return LB_SIZE_TYPE_2x1;
+       case 2:
+               return LB_SIZE_TYPE_2x2;
+       case 3:
+               return LB_SIZE_TYPE_4x1;
+       case 4:
+               return LB_SIZE_TYPE_4x2;
+       case 5:
+               return LB_SIZE_TYPE_4x3;
+       case 6:
+               return LB_SIZE_TYPE_4x4;
+       case 7:
+               return LB_SIZE_TYPE_EASY_1x1;
+       case 8:
+               return LB_SIZE_TYPE_EASY_3x1;
+       case 9:
+               return LB_SIZE_TYPE_EASY_3x3;
+       default:
+               break;
+       }
+
+       return LB_SIZE_TYPE_UNKNOWN;
+}
+
+/* End of a file */
diff --git a/src/util.c b/src/util.c
new file mode 100644 (file)
index 0000000..e5a545e
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * Copyright 2012  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/statvfs.h>
+
+#include <dlog.h>
+
+#include "util.h"
+#include "debug.h"
+
+int errno;
+
+static inline char *check_native_livebox(const char *pkgname)
+{
+       int len;
+       char *path;
+
+       len = strlen(pkgname) * 2;
+       len += strlen("/opt/usr/live/%s/libexec/liblive-%s.so");
+
+       path = malloc(len + 1);
+       if (!path) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
+       if (access(path, F_OK | R_OK) != 0) {
+               ErrPrint("%s is not a valid package\n", pkgname);
+               free(path);
+               return NULL;
+       }
+
+       return path;
+}
+
+static inline char *check_web_livebox(const char *pkgname)
+{
+       int len;
+       char *path;
+
+       len = strlen(pkgname) * 2;
+       len += strlen("/opt/usr/apps/%s/res/wgt/livebox/index.html");
+
+       path = malloc(len + 1);
+       if (!path) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname);
+       if (access(path, F_OK | R_OK) != 0) {
+               ErrPrint("%s is not a valid package\n", pkgname);
+               free(path);
+               return NULL;
+       }
+
+       return path;
+}
+
+int util_validate_livebox_package(const char *pkgname)
+{
+       char *path;
+
+       if (!pkgname) {
+               ErrPrint("Invalid argument\n");
+               return -EINVAL;
+       }
+
+       path = check_native_livebox(pkgname);
+       if (path) {
+               free(path);
+               return 0;
+       }
+
+       path = check_web_livebox(pkgname);
+       if (path) {
+               free(path);
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+double util_timestamp(void)
+{
+       struct timeval tv;
+
+       gettimeofday(&tv, NULL);
+
+       return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+}
+
+const char *util_basename(const char *name)
+{
+       int length;
+       length = name ? strlen(name) : 0;
+       if (!length)
+               return ".";
+
+       while (--length > 0 && name[length] != '/');
+
+       return length <= 0 ? name : (name + length + (name[length] == '/'));
+}
+
+unsigned long util_free_space(const char *path)
+{
+       struct statvfs st;
+       unsigned long space;
+
+       if (statvfs(path, &st) < 0) {
+               ErrPrint("statvfs: %s\n", strerror(errno));
+               return 0lu;
+       }
+
+       space = st.f_bsize * st.f_bfree;
+       /*!
+        * \note
+        * Must have to check the overflow
+        */
+       return space;
+}
+
+char *util_replace_string(const char *src, const char *pattern, const char *replace)
+{
+       int s_idx;
+       int p_idx;
+       int n_idx;
+       int t_idx;
+       int r_idx;
+       int idx;
+       char *result;
+       int len;
+       int rlen;
+       int matched;
+
+       if (!src || !pattern || !replace || !src[0] || !pattern[0]) {
+               ErrPrint("Invalid argument: %s %s %s\n", src, pattern, replace);
+               return NULL;
+       }
+
+       rlen = strlen(replace);
+       len = strlen(src);
+       result = malloc(len + 1);
+       if (!result) {
+               ErrPrint("Heap:%s\n", strerror(errno));
+               return NULL;
+       }
+
+       r_idx = 0;
+       idx = 0;
+       matched = 0;
+       for (s_idx = 0; src[s_idx]; s_idx++) {
+               if (idx == len) {
+                       char *tmp;
+
+                       len += (rlen > len ? rlen : len);
+                       tmp = realloc(result, len + 1);
+                       if (!tmp) {
+                               ErrPrint("Heap: %s\n", strerror(errno));
+                               free(result);
+                               return NULL;
+                       }
+                       result = tmp;
+               }
+
+               if (src[s_idx] == pattern[0]) {
+                       n_idx = -1;
+                       t_idx = s_idx;
+                       r_idx = idx;
+
+                       if (r_idx == len) {
+                               char *tmp;
+                               len += (rlen > len ? rlen : len);
+                               tmp = realloc(result, len + 1);
+                               if (!tmp) {
+                                       ErrPrint("Heap: %s\n", strerror(errno));
+                                       free(result);
+                                       return NULL;
+                               }
+                               result = tmp;
+                       }
+                       result[r_idx++] = src[t_idx++];
+                       p_idx = 1;
+                       while (pattern[p_idx]) {
+                               if (src[t_idx] == pattern[p_idx]) {
+                                       if (n_idx < 0) {
+                                               if (src[t_idx] == pattern[0]) {
+                                                       n_idx = t_idx;
+                                               } else {
+                                                       if (r_idx == len) {
+                                                               char *tmp;
+                                                               len += (rlen > len ? rlen : len);
+                                                               tmp = realloc(result, len + 1);
+                                                               if (!tmp) {
+                                                                       ErrPrint("Heap: %s\n", strerror(errno));
+                                                                       free(result);
+                                                                       return NULL;
+                                                               }
+                                                               result = tmp;
+                                                       }
+                                                       result[r_idx++] = src[t_idx];
+                                               }
+                                       }
+
+                                       p_idx++;
+                                       t_idx++;
+                                       continue;
+                               }
+
+                               if (n_idx < 0)
+                                       s_idx = t_idx;
+                               else
+                                       s_idx = n_idx;
+
+                               break;
+                       }
+
+                       if (pattern[p_idx] == '\0') {
+                               if (idx + rlen >= len) {
+                                       char *tmp;
+                                       len += (rlen > len ? rlen : len);
+                                       tmp = realloc(result, len + 1);
+                                       if (!tmp) {
+                                               ErrPrint("Heap: %s\n", strerror(errno));
+                                               free(result);
+                                               return NULL;
+                                       }
+                                       result = tmp;
+                                       matched++;
+                               }
+                               strcpy(result + idx, replace);
+                               idx += strlen(replace);
+                               s_idx = t_idx - 1;
+                       } else {
+                               idx = r_idx;
+                               s_idx = (n_idx < 0 ? t_idx : n_idx) - 1;
+                       }
+               } else {
+                       result[idx++] = src[s_idx];
+               }
+       }
+
+       result[idx] = '\0';
+
+       if (!matched) {
+               free(result);
+               result = NULL;
+       }
+
+       return result;
+}
+
+const char *util_uri_to_path(const char *uri)
+{
+       int len;
+
+       len = strlen(SCHEMA_FILE);
+       if (strncasecmp(uri, SCHEMA_FILE, len))
+               return NULL;
+
+       return uri + len;
+}
+
+char *util_conf_get_libexec(const char *pkgname)
+{
+       char *path;
+
+       if (!pkgname) {
+               ErrPrint("Invalid argument\n");
+               return NULL;
+       }
+
+       path = check_native_livebox(pkgname);
+       if (!path)
+               path = check_web_livebox(pkgname);
+
+       return path;
+}
+/* End of a file */