summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSehong Na <sehong.na@samsung.com>2014-05-31 12:34:15 +0900
committerSehong Na <sehong.na@samsung.com>2014-05-31 12:34:15 +0900
commitb3c89794f8bff2460ddc6966a2cd50493097c841 (patch)
tree1d876c7e28d23a1905a9b791822149d18253c3ca
downloadfavorites-tizen_2.3.tar.gz
favorites-tizen_2.3.tar.bz2
favorites-tizen_2.3.zip
-rw-r--r--AUTHORS1
-rwxr-xr-xCMakeLists.txt100
-rwxr-xr-xLICENSE.APLv2202
-rwxr-xr-xNOTICE.APLv23
-rw-r--r--capi-web-favorites.manifest5
-rwxr-xr-xcapi-web-favorites.pc.in14
-rw-r--r--debian/capi-web-favorites-dev.install4
-rw-r--r--debian/capi-web-favorites-dev.postinst1
-rw-r--r--debian/capi-web-favorites.install1
-rw-r--r--debian/capi-web-favorites.postinst1
-rwxr-xr-xdebian/changelog7
-rwxr-xr-xdebian/compat1
-rw-r--r--debian/control22
-rwxr-xr-xdebian/rules71
-rw-r--r--include/favorites.h364
-rw-r--r--include/favorites_private.h129
-rwxr-xr-xpackaging/capi-web-favorites.spec138
-rw-r--r--src/favorites_bookmark.c2033
-rw-r--r--src/favorites_history.c390
19 files changed, 3487 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..fa388cd
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Sangpyo Kim <sangpyo7.kim at samsung dot com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..b2028dd
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,100 @@
+SET_TARGET_PROPERTIES(${fw_name}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-web-favorites")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(requires "db-util dlog sqlite3 evas capi-base-common")
+SET(pc_requires "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${requires})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+ADD_DEFINITIONS(
+ -DLOG_TAG=\"favorites\"
+)
+#ADD_DEFINITIONS("-DBROWSER_BOOKMARK_SYNC")
+ADD_DEFINITIONS("-DROOT_IS_ZERO")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/web
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/web)
+
+CONFIGURE_FILE(
+ ${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100755
index 0000000..d645695
--- /dev/null
+++ b/LICENSE.APLv2
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ 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.
+
+ 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,
+ 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 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 in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) 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
+
+ (d) 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 Apache License to your work.
+
+ To apply the Apache 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 Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+
+ 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/NOTICE.APLv2 b/NOTICE.APLv2
new file mode 100755
index 0000000..1c1a4d0
--- /dev/null
+++ b/NOTICE.APLv2
@@ -0,0 +1,3 @@
+Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License, Version 2 terms and conditions.
diff --git a/capi-web-favorites.manifest b/capi-web-favorites.manifest
new file mode 100644
index 0000000..97e8c31
--- /dev/null
+++ b/capi-web-favorites.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
diff --git a/capi-web-favorites.pc.in b/capi-web-favorites.pc.in
new file mode 100755
index 0000000..71f9891
--- /dev/null
+++ b/capi-web-favorites.pc.in
@@ -0,0 +1,14 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/web
+
+Name: @PC_NAME@
+Description: Internet bookmark and history control API
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
diff --git a/debian/capi-web-favorites-dev.install b/debian/capi-web-favorites-dev.install
new file mode 100644
index 0000000..761a28b
--- /dev/null
+++ b/debian/capi-web-favorites-dev.install
@@ -0,0 +1,4 @@
+/usr/include/*
+/usr/include/*/*
+/usr/lib/pkgconfig/*.pc
+
diff --git a/debian/capi-web-favorites-dev.postinst b/debian/capi-web-favorites-dev.postinst
new file mode 100644
index 0000000..1a24852
--- /dev/null
+++ b/debian/capi-web-favorites-dev.postinst
@@ -0,0 +1 @@
+#!/bin/sh
diff --git a/debian/capi-web-favorites.install b/debian/capi-web-favorites.install
new file mode 100644
index 0000000..4a755a4
--- /dev/null
+++ b/debian/capi-web-favorites.install
@@ -0,0 +1 @@
+/usr/lib/lib*.so*
diff --git a/debian/capi-web-favorites.postinst b/debian/capi-web-favorites.postinst
new file mode 100644
index 0000000..1a24852
--- /dev/null
+++ b/debian/capi-web-favorites.postinst
@@ -0,0 +1 @@
+#!/bin/sh
diff --git a/debian/changelog b/debian/changelog
new file mode 100755
index 0000000..da62784
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,7 @@
+capi-web-favorites (0.0.1) unstable; urgency=low
+
+ * Git: framework/api/favorites
+ * Tag: capi-web-favorites_0.0.1
+ * first upload
+
+ -- Sangpyo Kim <sangpyo7.kim@samsung.com> Wed, 24 Aug 2011 21:12:42 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100755
index 0000000..7ed6ff8
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..a6d7bf3
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,22 @@
+
+Source: capi-web-favorites
+Section: libs
+Priority: extra
+Uploaders: Sangpyo Kim <sangpyo7.kim@samsung.com>, Inbum Chang <ibchang@samsung.com>
+Maintainer: Sangpyo Kim <sangpyo7.kim@samsung.com>, Inbum Chang <ibchang@samsung.com>
+Build-Depends: debhelper (>= 5), dlog-dev, libslp-db-util-dev, libsqlite3-dev, libevas-dev(>=0.1), capi-base-common-dev
+
+Package: capi-web-favorites
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Internet Bookmark and history control API
+
+Package: capi-web-favorites-dev
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-web-favorites(= ${Source-Version}), capi-base-common-dev
+Description: Internet Bookmark and history control API for Developer
+
+Package: capi-web-favorites-dbg
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-web-favorites(= ${Source-Version})
+Description: Internet Bookmark and history control API (unstripped)
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..e28a316
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,71 @@
+#!/usr/bin/make -f
+
+FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1)
+MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1)
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+CMAKE_ROOT_DIR ?= $(CURDIR)
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER}
+ touch configure-stamp
+
+build: build-stamp
+build-stamp: configure-stamp
+ dh_testdir
+ cd $(CMAKE_BUILD_DIR) && $(MAKE)
+ touch $@
+
+clean:
+ cd $(CMAKE_ROOT_DIR)
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ # Add here commands to clean up after the build process.
+ rm -f
+ rm -rf $(CMAKE_BUILD_DIR)
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/wavplayer.
+ cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+ dh_install --sourcedir=debian/tmp
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=capi-web-favorites-dbg
+ dh_fixperms
+ dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+
diff --git a/include/favorites.h b/include/favorites.h
new file mode 100644
index 0000000..8000481
--- /dev/null
+++ b/include/favorites.h
@@ -0,0 +1,364 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 __TIZEN_WEB_FAVORITES_H__
+#define __TIZEN_WEB_FAVORITES_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <Evas.h>
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * @addtogroup CAPI_WEB_FAVORITES_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumerations for favorites error.
+ */
+typedef enum favorites_error{
+ FAVORITES_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ FAVORITES_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
+ FAVORITES_ERROR_DB_FAILED = TIZEN_ERROR_WEB_CLASS | 0x62, /**< Database operation failure */
+ FAVORITES_ERROR_ITEM_ALREADY_EXIST = TIZEN_ERROR_WEB_CLASS | 0x63, /**< Requested data already exists */
+ FAVORITES_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file or directory */
+ FAVORITES_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN /**< Unknown error */
+} favorites_error_e;
+
+/**
+ * @brief The structure of bookmark entry in search results.
+ *
+ * @details This structure is passed to callback function in all bookmark related
+ * iterations through list received from search functions.
+ *
+ * @see bookmark_foreach_cb()
+ */
+typedef struct {
+ char* address; /**< Bookmark URL */
+ char* title; /**< The title of the bookmark */
+ char* creation_date; /**< The date of creation(yyyy-mm-dd hh:mm:ss) */
+ char* update_date; /**< The last updated date(yyyy-mm-dd hh:mm:ss) */
+ char* visit_date; /**< The last visit date(yyyy-mm-dd hh:mm:ss) */
+ int id; /**< The unique ID of bookmark */
+ bool is_folder; /**< property bookmark or folder\n @c 1: folder, @c 0: bookmark */
+ int folder_id; /**< The ID of parent folder */
+ int order_index; /**< The order index of bookmarks when show the list at the browser */
+ bool editable; /**< The flag of editability\n @c 1 : writable, @c 0: read-only, not ediable */
+} favorites_bookmark_entry_s;
+
+/**
+ * @brief Called to get bookmark details for each found bookmark.
+ *
+ * @param[in] item The bookmark entry handle or folder entry handle
+ * @param[in] user_data The user data passed from the foreach function
+ *
+ * @return @c true to continue with the next iteration of the loop or @c false to break out of the loop.
+ *
+ * @pre favorites_bookmark_foreach() will invoke this callback.
+ *
+ * @see favorites_bookmark_foreach()
+ */
+typedef bool (*favorites_bookmark_foreach_cb)(favorites_bookmark_entry_s *item, void *user_data);
+
+/**
+ * @brief Gets the id of the root folder.
+ *
+ * @param[out] root_folder_id The id of the root folder.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int favorites_bookmark_get_root_folder_id(int *root_id);
+
+/**
+ * @brief Adds a bookmark to bookmark database.
+ *
+ * @remarks If a folder named @a "foldername" doesn't exist, it will be created in the root folder.
+ * @param[in] url Bookmark URL
+ * @param[in] title The title of the bookmark
+ * @param[in] folder_name The name of parent folder in the root folder
+ * @param[out] saved_id The unique id of the added bookmark
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_ITEM_ALREADY_EXIST Requested data already exists
+ *
+ */
+int favorites_bookmark_add_bookmark(const char *url, const char *title, const char *folder_name, int *saved_id);
+
+/**
+ * @brief Adds a bookmark or folder item to bookmark database.
+ *
+ * @remarks If the parent_id is not valid folder id, this API will return error.
+ * @param[in] title The title of the bookmark or folder
+ * @param[in] url The bookmark URL. if the type is folder, this param will be ignored.
+ * @param[in] parent_id The unique id of folder which added item belong to.
+ * @param[in] type The type of item ( 0 : bookmark, 1 : folder )
+ * @param[out] saved_id The unique id of the added item
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_ITEM_ALREADY_EXIST Requested data already exists
+ * @retval #FAVORITES_ERROR_NO_SUCH_FILE parent_id is not valid
+ *
+ */
+int favorites_bookmark_add(const char *title, const char *url, int parent_id, int type, int *saved_id);
+
+/**
+ * @brief Deletes the bookmark item of given bookmark id.
+ *
+ * @param[in] bookmark_id The unique ID of bookmark to delete
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_bookmark_delete_bookmark(int bookmark_id);
+
+/**
+ * @brief Deletes all bookmarks and sub folders.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_bookmark_delete_all_bookmarks(void);
+
+/**
+ * @brief Gets a number of bookmark list items.
+ *
+ * @param[out] count The number of bookmarks and sub folders.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int favorites_bookmark_get_count(int *count);
+
+/**
+ * @brief Retrieves all bookmarks and folders by invoking the given callback function iteratively.
+ *
+ * @remarks All bookmarks and folders data are also used by browser application
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ * @post This function invokes bookmark_foreach_cb() repeatedly for each bookmark.
+ *
+ * @see bookmark_foreach_cb()
+ */
+int favorites_bookmark_foreach(favorites_bookmark_foreach_cb callback, void *user_data);
+
+/**
+ * @brief Exports a whole bookmark list as a netscape HTML bookmark file.
+ *
+ * @param[in] file_path The absolute path of the export file. This must includes html file name.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_bookmark_export_list(const char *file_path);
+
+/**
+ * @brief Gets the bookmark's favicon as a evas object type
+ *
+ * @param[in] bookmark_id The unique ID of bookmark
+ * @param[in] evas The given canvas
+ * @param[out] icon Retrieved favicon evas object of bookmark.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_bookmark_get_favicon(int bookmark_id, Evas *evas, Evas_Object **icon);
+
+/**
+ * @brief Sets the bookmark's favicon
+ *
+ * @param[in] bookmark_id The unique ID of bookmark
+ * @param[in] icon The favicon object to save
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_bookmark_set_favicon(int bookmark_id, Evas_Object *icon);
+
+/**
+ * @brief The structure of history entry in search results.
+ *
+ * @details This structure is passed to callback function in all history related
+ * iterations through list received from search functions.
+ *
+ * @see history_foreach_cb()
+ */
+typedef struct {
+ char* address; /**< URL history */
+ char* title; /**< The title of history */
+ int count; /**< The visit count */
+ char* visit_date; /**< The last visit date */
+ int id; /**< The unique ID of history */
+} favorites_history_entry_s;
+
+/**
+ * @brief Called to get history details for each found history.
+ *
+ * @param[in] item The history entry handle
+ * @param[in] user_data The user data passed from the foreach function
+ *
+ * @return @c true to continue with the next iteration of the loop or @c false to break out of the loop.
+ *
+ * @pre favorites_history_foreach() will invoke this callback.
+ *
+ * @see favorites_history_foreach()
+ */
+typedef bool (*favorites_history_foreach_cb)(favorites_history_entry_s *item, void *user_data);
+
+/**
+ * @brief Gets a number of history list items.
+ *
+ * @param[out] count The number of histories.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int favorites_history_get_count(int *count);
+
+/**
+ * @brief Retrieves all histories by invoking the given callback function iteratively.
+ *
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ * @post This function invokes history_foreach_cb().
+ *
+ * @see history_foreach_cb()
+ */
+int favorites_history_foreach(favorites_history_foreach_cb callback, void *user_data);
+
+/**
+ * @brief Deletes the history item of given history id.
+ *
+ * @param[in] history_id The history ID to delete
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_history_delete_history(int history_id);
+
+/**
+ * @brief Deletes the history item of given history url.
+ *
+ * @param[in] url history url which wants to be deleted
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_history_delete_history_by_url(const char *url);
+
+/**
+ * @brief Deletes all histories.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_history_delete_all_histories(void);
+
+/**
+ * @brief Deletes all histories accessed with the browser within the specified time period.
+ *
+ * @param[in] begin_date The start date of the period
+ * @param[in] end_date The end date of the period
+ *
+ * @remarks Date format must be "yyyy-mm-dd hh:mm:ss" ex: "2000-01-01 01:20:35".
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_history_delete_history_by_term(const char *begin_date, const char *end_date);
+
+/**
+ * @brief Gets the history's favicon as an evas object type
+ *
+ * @param[in] history_id The unique ID of history item
+ * @param[in] evas The given canvas
+ * @param[out] icon Retrieved favicon evas object of bookmark.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #FAVORITES_ERROR_NONE Successful
+ * @retval #FAVORITES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FAVORITES_ERROR_DB_FAILED Database failed
+ *
+ */
+int favorites_history_get_favicon(int history_id, Evas *evas, Evas_Object **icon);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* __TIZEN_WEB_FAVORITES_H__ */
diff --git a/include/favorites_private.h b/include/favorites_private.h
new file mode 100644
index 0000000..db298e6
--- /dev/null
+++ b/include/favorites_private.h
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 __TIZEN_WEB_FAVORITES_PRIVATE_H__
+#define __TIZEN_WEB_FAVORITES_PRIVATE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**********************************************
+ * Logging macro
+ **********************************************/
+#define FAVORITES_LOGD(fmt, args...) LOGD(fmt, ##args)
+#define FAVORITES_LOGI(fmt, args...) LOGI(fmt, ##args)
+#define FAVORITES_LOGW(fmt, args...) LOGW(fmt, ##args)
+#define FAVORITES_LOGE(fmt, args...) LOGE(fmt, ##args)
+#define FAVORITES_LOGE_IF(cond, fmt, args...) LOGE_IF(cond, fmt, ##args)
+
+/**********************************************
+ * Argument checking macro
+ **********************************************/
+#define FAVORITES_NULL_ARG_CHECK(_arg_) do { \
+ if(_arg_ == NULL) { \
+ LOGE("[%s] FAVORITES_ERR_INVALID_PARAMETER(0x%08x)", __FUNCTION__,\
+ FAVORITES_ERROR_INVALID_PARAMETER); \
+ return FAVORITES_ERROR_INVALID_PARAMETER; \
+ } \
+}while(0)
+
+#define FAVORITES_INVALID_ARG_CHECK(_condition_) do { \
+ if(_condition_) { \
+ LOGE("[%s] FAVORITES_ERR_INVALID_PARAMETER(0x%08x)", __FUNCTION__,\
+ FAVORITES_ERROR_INVALID_PARAMETER); \
+ return FAVORITES_ERROR_INVALID_PARAMETER; \
+ } \
+}while(0)
+
+#define _FAVORITES_FREE(_srcx_) { if(NULL != _srcx_) free(_srcx_); }
+#define _FAVORITES_STRDUP(_srcx_) (NULL != _srcx_) ? strdup(_srcx_):NULL
+
+struct bookmark_entry_internal{
+ char* address; /**< URL of the bookmark */
+ char* title; /**< Title of the bookmark */
+ char* creationdate; /**< date of created */
+ char* updatedate; /**< date of last updated */
+ char* visitdate; /**< date of last visited */
+ int id; /**< uniq id of bookmark */
+ int is_folder; /**< property bookmark or folder 1: bookmark 1: folder */
+ int folder_id; /**< parent folder id */
+ int orderIndex; /**< order sequence */
+ int editable; /**< flag of editability 1 : WRITABLE 0: READ ONLY */
+};
+typedef struct bookmark_entry_internal bookmark_entry_internal_s;
+typedef struct bookmark_entry_internal *bookmark_entry_internal_h;
+
+struct bookmark_list {
+ int count;
+ bookmark_entry_internal_h item;
+};
+
+/**
+ * @brief The bookmark entry list handle.
+ */
+typedef struct bookmark_list bookmark_list_s;
+
+/**
+ * @brief The bookmark entry list structure.
+ */
+typedef struct bookmark_list *bookmark_list_h;
+
+struct favicon_entry {
+ void *data; /* favicon image data pointer. ( Allocated memory) */
+ int length; /* favicon image data's length */
+ int w; /* favicon image width */
+ int h; /* favicon image height */
+};
+typedef struct favicon_entry favicon_entry_s;
+typedef struct favicon_entry *favicon_entry_h;
+
+/* bookmark internal API */
+void _favorites_close_bookmark_db(void);
+void _favorites_finalize_bookmark_db(sqlite3_stmt *stmt);
+const char *_favorites_get_bookmark_db_name(void);
+int _favorites_open_bookmark_db(void);
+void _favorites_free_bookmark_list(bookmark_list_h m_list);
+int _favorites_free_bookmark_entry(favorites_bookmark_entry_s *entry);
+int _favorites_get_bookmark_lastindex(int locationId);
+int _favorites_get_bookmark_count_at_folder(int folderId);
+int _favorites_bookmark_get_folder_count(void);
+bookmark_list_h _favorites_get_bookmark_list_at_folder(int folderId);
+bookmark_list_h _favorites_bookmark_get_folder_list(void);
+int _favorites_get_unixtime_from_datetime(char *datetime);
+int _add_bookmark(const char *title, const char *address, int parent_id, int *saved_bookmark_id);
+int _add_folder(const char *title, int parent_id, int *saved_folder_id);
+int _get_root_folder_id(void);
+int _get_exists_id(int id);
+int _get_exists_bookmark(const char *address);
+int _get_exists_folder(const char *title, int parent_id);
+int _get_bookmark_id(const char *address);
+int _get_folder_id(const char *title, const int parent);
+int _get_count_by_folder(int parent_id);
+int _get_list_by_folder(int parent_id, bookmark_list_h *list);
+int _set_full_tree_to_html_recur(int parent_id, FILE *fp, int depth);
+
+/* history internal API */
+void _favorites_history_db_close(void);
+void _favorites_history_db_finalize(sqlite3_stmt *stmt);
+int _favorites_history_db_open(void);
+int _favorites_free_history_entry(favorites_history_entry_s *entry);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* __TIZEN_WEB_FAVORITES_PRIVATE_H__ */
diff --git a/packaging/capi-web-favorites.spec b/packaging/capi-web-favorites.spec
new file mode 100755
index 0000000..53d180d
--- /dev/null
+++ b/packaging/capi-web-favorites.spec
@@ -0,0 +1,138 @@
+Name: capi-web-favorites
+Summary: Internet bookmark and history API
+Version: 0.0.17
+Release: 1
+Group: TO_BE/FILLED_IN
+License: Apache License, Version 2.0
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(capi-base-common)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary: Internet Bookmark and History in Tizen Native API (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+
+
+%prep
+%setup -q
+
+
+%build
+%cmake .
+make %{?jobs:-j%jobs}
+
+%install
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+%make_install
+
+%post
+/sbin/ldconfig
+mkdir -p /opt/usr/dbspace/
+##### History ######
+if [ ! -f /opt/usr/dbspace/.browser-history.db ];
+then
+ sqlite3 /opt/usr/dbspace/.browser-history.db 'PRAGMA journal_mode=PERSIST;
+ CREATE TABLE history(
+ id INTEGER PRIMARY KEY AUTOINCREMENT
+ , address
+ , title
+ , counter INTEGER
+ , visitdate DATETIME
+ , favicon BLOB
+ , favicon_length INTEGER
+ , favicon_w INTEGER
+ , favicon_h INTEGER
+ , snapshot BLOB
+ , snapshot_stride INTEGER
+ , snapshot_w INTEGER
+ , snapshot_h INTEGER);'
+fi
+
+### Bookmark ###
+if [ ! -f /opt/usr/dbspace/.internet_bookmark.db ];
+then
+ sqlite3 /opt/usr/dbspace/.internet_bookmark.db 'PRAGMA journal_mode=PERSIST;
+ CREATE TABLE bookmarks(
+ id INTEGER PRIMARY KEY AUTOINCREMENT
+ ,type INTEGER
+ ,parent INTEGER
+ ,address
+ ,title
+ ,creationdate
+ ,sequence INTEGER
+ ,updatedate
+ ,visitdate
+ ,editable INTEGER
+ ,accesscount INTEGER
+ ,favicon BLOB
+ ,favicon_length INTEGER
+ ,favicon_w INTEGER
+ ,favicon_h INTEGER
+ ,created_date
+ ,account_name
+ ,account_type
+ ,thumbnail BLOB
+ ,thumbnail_length INTEGER
+ ,thumbnail_w INTEGER
+ ,thumbnail_h INTEGER
+ ,version INTEGER
+ ,sync
+ ,tag1
+ ,tag2
+ ,tag3
+ ,tag4
+ );
+ create index idx_bookmarks_on_parent_type on bookmarks(parent, type);
+
+ CREATE TABLE tags(
+ tag
+ );'
+fi
+# Change db file owner & permission
+chown :5000 /opt/usr/dbspace/.browser-history.db
+chown :5000 /opt/usr/dbspace/.browser-history.db-journal
+chown :5000 /opt/usr/dbspace/.internet_bookmark.db
+chown :5000 /opt/usr/dbspace/.internet_bookmark.db-journal
+chmod 666 /opt/usr/dbspace/.browser-history.db
+chmod 666 /opt/usr/dbspace/.browser-history.db-journal
+chmod 666 /opt/usr/dbspace/.internet_bookmark.db
+chmod 666 /opt/usr/dbspace/.internet_bookmark.db-journal
+
+if [ -f /usr/lib/rpm-plugins/msm.so ]
+then
+ chsmack -a 'org.tizen.browser::db_external' /opt/usr/dbspace/.browser-history.db*
+ chsmack -a 'org.tizen.browser::db_external' /opt/usr/dbspace/.internet_bookmark.db*
+fi
+##################################################
+# set default vconf values
+##################################################
+#internal keys
+vconftool set -t string db/browser/browser_user_agent "System user agent" -g 5000 -f
+vconftool set -t string db/browser/custom_user_agent "" -g 5000 -f
+#public keys
+vconftool set -t string db/browser/user_agent "Mozilla/5.0 (Linux; Tizen 2.2; sdk) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.2 Mobile Safari/537.3" -g 5000 -f
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%manifest capi-web-favorites.manifest
+%{_libdir}/libcapi-web-favorites.so
+/usr/share/license/%{name}
+
+%files devel
+%{_includedir}/web/*.h
+%{_libdir}/pkgconfig/*.pc
diff --git a/src/favorites_bookmark.c b/src/favorites_bookmark.c
new file mode 100644
index 0000000..dea1373
--- /dev/null
+++ b/src/favorites_bookmark.c
@@ -0,0 +1,2033 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 <string.h>
+#include <dlog.h>
+#include <db-util.h>
+#include <favorites.h>
+#include <favorites_private.h>
+#if defined(BROWSER_BOOKMARK_SYNC)
+#include "bookmark-adaptor.h"
+#include "time.h"
+#endif
+
+sqlite3 *gl_internet_bookmark_db = 0;
+
+/* Private Functions */
+void _favorites_close_bookmark_db(void)
+{
+ if (gl_internet_bookmark_db) {
+ if (db_util_close(gl_internet_bookmark_db) != DB_UTIL_OK) {
+ FAVORITES_LOGE("db_util_close is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ }
+ gl_internet_bookmark_db = 0;
+ }
+}
+
+void _favorites_finalize_bookmark_db(sqlite3_stmt *stmt)
+{
+ if (sqlite3_finalize(stmt) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_finalize is failed");
+ }
+ _favorites_close_bookmark_db();
+}
+const char *_favorites_get_bookmark_db_name(void)
+{
+ return "/opt/usr/dbspace/.internet_bookmark.db";
+}
+int _favorites_open_bookmark_db(void)
+{
+ _favorites_close_bookmark_db();
+ if (db_util_open
+ (_favorites_get_bookmark_db_name(), &gl_internet_bookmark_db,
+ DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
+ if (db_util_close(gl_internet_bookmark_db) != DB_UTIL_OK) {
+ FAVORITES_LOGE("db_util_close is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ }
+ gl_internet_bookmark_db = 0;
+ return -1;
+ }
+ return gl_internet_bookmark_db ? 0 : -1;
+}
+
+void _favorites_free_bookmark_list(bookmark_list_h m_list)
+{
+ FAVORITES_LOGE(" ");
+
+ int i = 0;
+ if (m_list == NULL)
+ return;
+
+ if (m_list->item != NULL) {
+ for (i = 0; i < m_list->count; i++) {
+ if (m_list->item[i].address != NULL)
+ free(m_list->item[i].address);
+ if (m_list->item[i].title != NULL)
+ free(m_list->item[i].title);
+ if (m_list->item[i].creationdate != NULL)
+ free(m_list->item[i].creationdate);
+ if (m_list->item[i].updatedate != NULL)
+ free(m_list->item[i].updatedate);
+ }
+ free(m_list->item);
+ }
+ free(m_list);
+ m_list = NULL;
+}
+
+int _favorites_free_bookmark_entry(favorites_bookmark_entry_s *entry)
+{
+ FAVORITES_NULL_ARG_CHECK(entry);
+
+ if (entry->address != NULL)
+ free(entry->address);
+ if (entry->title != NULL)
+ free(entry->title);
+ if (entry->creation_date != NULL)
+ free(entry->creation_date);
+ if (entry->update_date != NULL)
+ free(entry->update_date);
+
+ return FAVORITES_ERROR_NONE;
+}
+
+/* search last of sequence(order's index) */
+int _favorites_get_bookmark_lastindex(int locationId)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select sequence from bookmarks where parent=? order by sequence desc",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(stmt, 1, locationId) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if ((nError = sqlite3_step(stmt)) == SQLITE_ROW) {
+ int index = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return index;
+ } else if (nError == SQLITE_DONE) {
+ FAVORITES_LOGE("Not found items in This Folder");
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+int _favorites_get_bookmark_count_at_folder(int folderId)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+ FAVORITES_LOGE("");
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ /*bookmark */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select count(*) from bookmarks where parent=? and type=0",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_int(stmt, 1, folderId) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int count = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ FAVORITES_LOGE("count: %d", count);
+ return count;
+ } else if (nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+int _favorites_bookmark_get_folder_count(void)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+ FAVORITES_LOGE("");
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ /* folder + bookmark */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select count(*) from bookmarks where type=1",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int count = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return count;
+ } else if (nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+bookmark_list_h _favorites_get_bookmark_list_at_folder(int folderId)
+{
+ bookmark_list_h m_list = NULL;
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ FAVORITES_LOGE("folderId: %d", folderId);
+ if(folderId<=0){
+ FAVORITES_LOGE("folderId is wrong");
+ return NULL;
+ }
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ /* check the total count of items */
+ int item_count = 0;
+ item_count = _favorites_get_bookmark_count_at_folder(folderId);
+
+ if (item_count <= 0)
+ return NULL;
+
+ /* Get bookmarks list only under given folder */
+ sprintf(query, "select id, type, parent, address, title, editable,\
+ creationdate, updatedate, sequence \
+ from bookmarks where type=0 and parent =%d order by sequence"
+ , folderId);
+ FAVORITES_LOGE("query: %s", query);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return NULL;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ query, -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return NULL;
+ }
+
+ /* allocation .... Array for Items */
+ m_list = (bookmark_list_h) calloc(1, sizeof(bookmark_list_s));
+ m_list->item =
+ (bookmark_entry_internal_h) calloc(item_count, sizeof(bookmark_entry_internal_s));
+ m_list->count = item_count;
+ int i = 0;
+ while ((nError = sqlite3_step(stmt)) == SQLITE_ROW
+ && (i < item_count)) {
+ m_list->item[i].id = sqlite3_column_int(stmt, 0);
+ m_list->item[i].is_folder = sqlite3_column_int(stmt, 1);
+ m_list->item[i].folder_id = sqlite3_column_int(stmt, 2);
+
+ if (!m_list->item[i].is_folder) {
+ const char *url =
+ (const char *)(sqlite3_column_text(stmt, 3));
+ m_list->item[i].address = NULL;
+ if (url) {
+ int length = strlen(url);
+ if (length > 0) {
+ m_list->item[i].address =
+ (char *)calloc(length + 1,
+ sizeof(char));
+ memcpy(m_list->item[i].address, url,
+ length);
+ }
+ }
+ }
+
+ const char *title =
+ (const char *)(sqlite3_column_text(stmt, 4));
+ m_list->item[i].title = NULL;
+ if (title) {
+ int length = strlen(title);
+ if (length > 0) {
+ m_list->item[i].title =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(m_list->item[i].title, title, length);
+ }
+ FAVORITES_LOGE("Bookmark Title:%s\n", m_list->item[i].title);
+ }
+ m_list->item[i].editable = sqlite3_column_int(stmt, 5);
+
+ const char *creationdate =
+ (const char *)(sqlite3_column_text(stmt, 6));
+ m_list->item[i].creationdate = NULL;
+ if (creationdate) {
+ int length = strlen(creationdate);
+ if (length > 0) {
+ m_list->item[i].creationdate =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(m_list->item[i].creationdate,
+ creationdate, length);
+ }
+ }
+ const char *updatedate =
+ (const char *)(sqlite3_column_text(stmt, 7));
+ m_list->item[i].updatedate = NULL;
+ if (updatedate) {
+ int length = strlen(updatedate);
+ if (length > 0) {
+ m_list->item[i].updatedate =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(m_list->item[i].updatedate, updatedate,
+ length);
+ }
+ }
+
+ m_list->item[i].orderIndex = sqlite3_column_int(stmt, 8);
+ i++;
+ }
+ m_list->count = i;
+
+ if (i <= 0) {
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ _favorites_free_bookmark_list(m_list);
+ return NULL;
+ }
+ _favorites_finalize_bookmark_db(stmt);
+ return m_list;
+}
+
+bookmark_list_h _favorites_bookmark_get_folder_list(void)
+{
+ bookmark_list_h m_list = NULL;
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ FAVORITES_LOGE("");
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ /* check the total count of items */
+ int item_count = 0;
+ item_count = _favorites_bookmark_get_folder_count();
+
+ if (item_count <= 0)
+ return NULL;
+
+ /* Get bookmarks list only under given folder */
+ sprintf(query, "select id, type, parent, address, title, editable,\
+ creationdate, updatedate, sequence \
+ from bookmarks where type=1 order by sequence");
+ FAVORITES_LOGE("query: %s", query);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return NULL;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ query, -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return NULL;
+ }
+
+ /* allocation .... Array for Items */
+ m_list = (bookmark_list_h) calloc(1, sizeof(bookmark_list_s));
+ m_list->item =
+ (bookmark_entry_internal_h) calloc(item_count, sizeof(bookmark_entry_internal_s));
+ m_list->count = item_count;
+ int i = 0;
+ while ((nError = sqlite3_step(stmt)) == SQLITE_ROW
+ && (i < item_count)) {
+ m_list->item[i].id = sqlite3_column_int(stmt, 0);
+ m_list->item[i].is_folder = sqlite3_column_int(stmt, 1);
+ m_list->item[i].folder_id = sqlite3_column_int(stmt, 2);
+
+ if (!m_list->item[i].is_folder) {
+ const char *url =
+ (const char *)(sqlite3_column_text(stmt, 3));
+ m_list->item[i].address = NULL;
+ if (url) {
+ int length = strlen(url);
+ if (length > 0) {
+ m_list->item[i].address =
+ (char *)calloc(length + 1,
+ sizeof(char));
+ memcpy(m_list->item[i].address, url,
+ length);
+ }
+ }
+ }
+
+ const char *title =
+ (const char *)(sqlite3_column_text(stmt, 4));
+ m_list->item[i].title = NULL;
+ if (title) {
+ int length = strlen(title);
+ if (length > 0) {
+ m_list->item[i].title =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(m_list->item[i].title, title, length);
+ }
+ FAVORITES_LOGE("Bookmark Title:%s\n", m_list->item[i].title);
+ }
+ m_list->item[i].editable = sqlite3_column_int(stmt, 5);
+
+ const char *creationdate =
+ (const char *)(sqlite3_column_text(stmt, 6));
+ m_list->item[i].creationdate = NULL;
+ if (creationdate) {
+ int length = strlen(creationdate);
+ if (length > 0) {
+ m_list->item[i].creationdate =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(m_list->item[i].creationdate,
+ creationdate, length);
+ }
+ }
+ const char *updatedate =
+ (const char *)(sqlite3_column_text(stmt, 7));
+ m_list->item[i].updatedate = NULL;
+ if (updatedate) {
+ int length = strlen(updatedate);
+ if (length > 0) {
+ m_list->item[i].updatedate =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(m_list->item[i].updatedate, updatedate,
+ length);
+ }
+ }
+
+ m_list->item[i].orderIndex = sqlite3_column_int(stmt, 8);
+ i++;
+ }
+ m_list->count = i;
+
+ if (nError == SQLITE_DONE) {
+ if (m_list->count > 0) {
+ _favorites_finalize_bookmark_db(stmt);
+ return m_list;
+ } else if (m_list->count == 0) {
+ FAVORITES_LOGE("There is no folders");
+ _favorites_finalize_bookmark_db(stmt);
+ _favorites_free_bookmark_list(m_list);
+ return NULL;
+ }
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ _favorites_free_bookmark_list(m_list);
+ return NULL;
+}
+
+int _favorites_get_unixtime_from_datetime(char *datetime)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if(datetime == NULL ) {
+ FAVORITES_LOGE("datetime is NULL\n");
+ return -1;
+ }
+
+ FAVORITES_LOGE("datetime: %s\n", datetime);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "SELECT strftime('%s', ?)",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, datetime, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int unixtime = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return unixtime;
+ } else if (nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+int _add_bookmark(const char *title, const char *address, int parent_id, int *saved_bookmark_id)
+{
+ FAVORITES_LOGD("");
+ if (title == NULL || strlen(title) <= 0) {
+ FAVORITES_LOGD("Invalid param: Title is empty");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+ if (address == NULL || strlen(address) <= 0) {
+ FAVORITES_LOGD("Invalid param: Address is empty");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+ if (memcmp(address, "file://", 7) == 0) {
+ FAVORITES_LOGD("Not Allow file://");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+#if defined(BROWSER_BOOKMARK_SYNC)
+ if (parent_id != _get_root_folder_id()) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ }
+ FAVORITES_LOGD("[%s][%s][%d]", title, address, parent_id);
+ int id = -1;
+ int *ids = NULL;
+ int ids_count = -1;
+ bp_bookmark_adaptor_get_duplicated_url_ids_p(&ids, &ids_count, 1,
+ -1, -1, 0, 0, address, 0);
+ if (ids_count > 0)
+ id = ids[0];
+ free(ids);
+
+ if (ids_count > 0) {
+ FAVORITES_LOGE("same URI is already exist");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ bp_bookmark_info_fmt info;
+ memset(&info, 0x00, sizeof(bp_bookmark_info_fmt));
+ info.type = 0;
+ info.parent = parent_id;
+ info.sequence = -1;
+ info.access_count = -1;
+ info.editable = 1;
+ time_t seconds = 0;
+ info.date_created = time(&seconds);
+ info.date_modified = time(&seconds);
+ if (address != NULL && strlen(address) > 0)
+ info.url = strdup(address);
+ if (title != NULL && strlen(title) > 0)
+ info.title = strdup(title);
+
+ int ret = bp_bookmark_adaptor_easy_create(&id, &info);
+ if (ret == 0) {
+ ret = bp_bookmark_adaptor_set_sequence(id, -1); // max sequence
+ bp_bookmark_adaptor_easy_free(&info);
+ if (ret == 0) {
+ *saved_bookmark_id = id;
+ FAVORITES_LOGD("bp_bookmark_adaptor_easy_create is success(id:%d)", *saved_bookmark_id);
+ bp_bookmark_adaptor_publish_notification();
+ return FAVORITES_ERROR_NONE;
+ }
+ }
+ int errcode = bp_bookmark_adaptor_get_errorcode();
+ bp_bookmark_adaptor_easy_free(&info);
+ FAVORITES_LOGE("bp_bookmark_adaptor_easy_create is failed[%d]", errcode);
+ return FAVORITES_ERROR_DB_FAILED;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+#if defined(ROOT_IS_ZERO)
+ if (parent_id != _get_root_folder_id()) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ }
+#else
+ if (parent_id > 0) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ } else {
+ parent_id = _get_root_folder_id();
+ }
+#endif
+ FAVORITES_LOGD("[%s][%s][%d]", title, address, parent_id);
+
+ int uid = _get_exists_bookmark(address);
+ /* ignore this call.. already exist. */
+ if (uid > 0) {
+ FAVORITES_LOGE("Bookmark is already exist. cancel the add operation.");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ int lastIndex = _favorites_get_bookmark_lastindex(parent_id);
+ if (lastIndex < 0) {
+ FAVORITES_LOGE("Database::getLastIndex() is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "INSERT INTO bookmarks (type, parent, address, title, creationdate,\
+ updatedate, editable, sequence)\
+ VALUES (0, ?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?)",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /*parent */
+ if (sqlite3_bind_int(stmt, 1, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /*address */
+ if (sqlite3_bind_text(stmt, 2, address, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /*title */
+ if (sqlite3_bind_text(stmt, 3, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /* order */
+ if (lastIndex >= 0) {
+ if (sqlite3_bind_int(stmt, 4, (lastIndex + 1)) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ int id = _get_bookmark_id(address);
+ if (id > 0)
+ *saved_bookmark_id = id;
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
+int _add_folder(const char *title, int parent_id, int *saved_folder_id)
+{
+ FAVORITES_LOGD("");
+ if (title == NULL || strlen(title) <= 0) {
+ FAVORITES_LOGD("Invalid param: Title is empty");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+#if defined(BROWSER_BOOKMARK_SYNC)
+ if (parent_id != _get_root_folder_id()) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ }
+ int id = -1;
+ int *ids = NULL;
+ int ids_count = -1;
+ bp_bookmark_adaptor_get_duplicated_title_ids_p(&ids, &ids_count, 1,
+ -1, parent_id, 1, 0, title, 0);
+ if (ids_count > 0)
+ id = ids[0];
+ free(ids);
+
+ if (ids_count > 0) {
+ FAVORITES_LOGE("same title with same parent is already exist");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ bp_bookmark_info_fmt info;
+ memset(&info, 0x00, sizeof(bp_bookmark_info_fmt));
+ info.type = 1;
+ info.parent = parent_id;
+ info.sequence = -1;
+ info.access_count = -1;
+ info.editable = 1;
+ if (title != NULL && strlen(title) > 0)
+ info.title = strdup(title);
+ int ret = bp_bookmark_adaptor_easy_create(&id, &info);
+ if (ret == 0) {
+ ret = bp_bookmark_adaptor_set_sequence(id, -1); // max sequence
+ bp_bookmark_adaptor_easy_free(&info);
+ if (ret == 0) {
+ *saved_folder_id = id;
+ FAVORITES_LOGD("bmsvc_add_bookmark is success(id:%d)", *saved_folder_id);
+ bp_bookmark_adaptor_publish_notification();
+ return FAVORITES_ERROR_NONE;
+ }
+ }
+ int errcode = bp_bookmark_adaptor_get_errorcode();
+ bp_bookmark_adaptor_easy_free(&info);
+ FAVORITES_LOGE("bp_bookmark_adaptor_easy_create is failed[%d]", errcode);
+ return FAVORITES_ERROR_DB_FAILED;
+#else
+#if defined(ROOT_IS_ZERO)
+ if (parent_id != _get_root_folder_id()) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ }
+#else
+ if (parent_id > 0) {
+ /* check whether folder is exist or not. */
+ if (_get_exists_id(parent_id) <= 0) {
+ FAVORITES_LOGE("Not found parent folder (%d)\n", parent_id);
+ return FAVORITES_ERROR_NO_SUCH_FILE;
+ }
+ } else {
+ parent_id = _get_root_folder_id();
+ }
+#endif
+ FAVORITES_LOGD("[%s][%d]", title, parent_id);
+
+ int uid = _get_exists_folder(title, parent_id);
+ /* ignore this call.. already exist. */
+ if (uid > 0) {
+ FAVORITES_LOGE("Folder is already exist. cancel the add operation.");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ int lastIndex = _favorites_get_bookmark_lastindex(parent_id);
+ if (lastIndex < 0) {
+ FAVORITES_LOGE("Database::getLastIndex() is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ int nError;
+ sqlite3_stmt *stmt;
+
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "INSERT INTO bookmarks (type, parent, title, creationdate,\
+ updatedate, sequence, editable)\
+ VALUES (1, ?, ?, DATETIME('now'), DATETIME('now'), ?, 1)",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /*parent */
+ if (sqlite3_bind_int(stmt, 1, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /*title */
+ if (sqlite3_bind_text(stmt, 2, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ /* order */
+ if (lastIndex >= 0) {
+ if (sqlite3_bind_int(stmt, 3, (lastIndex + 1)) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ int id = _get_folder_id(title, parent_id);
+ if (id > 0)
+ *saved_folder_id = id;
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
+
+int _get_root_folder_id(void)
+{
+#if defined(BROWSER_BOOKMARK_SYNC)
+ FAVORITES_LOGE("SYNC");
+ int root_id = -1;
+ bp_bookmark_adaptor_get_root(&root_id);
+ return root_id;
+#else
+#if defined(ROOT_IS_ZERO)
+ return 0;
+#else
+ FAVORITES_LOGE("NOT SYNC");
+ return 1;
+#endif
+#endif
+}
+
+int _get_exists_id(int id)
+{
+ FAVORITES_LOGE("");
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int value = -1;
+ int ret = -1;
+ int errorcode = -1;
+ ret = bp_bookmark_adaptor_get_type(id, &value);
+ if (ret < 0) {
+ errorcode = bp_bookmark_adaptor_get_errorcode();
+ if (errorcode == BP_BOOKMARK_ERROR_NO_DATA)
+ return 0;
+ else
+ return -1;
+ }
+ return 1;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (id < 0)
+ return -1;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select * from bookmarks where id=?",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ /* The given foldername is exist on the bookmark table */
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ } else if (nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+
+ _favorites_close_bookmark_db();
+ return -1;
+#endif
+}
+
+int _get_exists_bookmark(const char *address)
+{
+ FAVORITES_LOGD("");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select * from bookmarks where address=? and type=0",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, address, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ } else if (nError == SQLITE_DONE) {
+ //FAVORITES_LOGE("bookmark doesn't exists");
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+int _get_exists_folder(const char *title, int parent_id)
+{
+ FAVORITES_LOGD("");
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select * from bookmarks where title=? and parent=? and type=1",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_int(stmt, 2, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ } else if (nError == SQLITE_DONE) {
+ //FAVORITES_LOGE("folder doesn't exists");
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+int _get_bookmark_id(const char *address)
+{
+ FAVORITES_LOGE("");
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int id = -1;
+ int *ids = NULL;
+ int ids_count = -1;
+ bp_bookmark_adaptor_get_duplicated_url_ids_p(&ids, &ids_count, 1,
+ -1, -1, 0, 0, address, 0);
+ if (ids_count > 0)
+ id = ids[0];
+ free(ids);
+
+ if (ids_count > 0) {
+ return id;
+ }
+ FAVORITES_LOGE("There is no such bookmark url exists.");
+ return -1;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select id from bookmarks where address=? and type=0",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, address, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int id = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return id;
+ } else if (nError == SQLITE_DONE) {
+ //FAVORITES_LOGE("bookmark id doesn't exists");
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_close_bookmark_db();
+ return -1;
+#endif
+}
+
+int _get_folder_id(const char *title, const int parent)
+{
+ FAVORITES_LOGE("");
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int id = -1;
+ int *ids = NULL;
+ int ids_count = -1;
+ bp_bookmark_adaptor_get_duplicated_title_ids_p(&ids, &ids_count, 1,
+ -1, parent, 1, 0, title, 0);
+ if (ids_count > 0)
+ id = ids[0];
+ free(ids);
+
+ if (ids_count > 0) {
+ return id;
+ }
+ FAVORITES_LOGE("There is no such folder exists.");
+ return -1;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+ /* same title */
+ nError =
+ sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "SELECT id FROM bookmarks WHERE title=? AND parent=? AND type=1",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_text(stmt, 1, title, -1, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(stmt, 2, parent) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int id = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return id;
+ } else if (nError == SQLITE_DONE) {
+ //FAVORITES_LOGE("folder id doesn't exists");
+ _favorites_finalize_bookmark_db(stmt);
+ return 0;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_close_bookmark_db();
+ return -1;
+#endif
+}
+
+int _get_count_by_folder(int parent_id)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+ FAVORITES_LOGE("");
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ /*bookmark */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select count(*) from bookmarks where parent=?",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if (sqlite3_bind_int(stmt, 1, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int count = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ FAVORITES_LOGE("count: %d", count);
+ return count;
+ } else if (nError == SQLITE_DONE) {
+ FAVORITES_LOGE("No rows");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return -1;
+}
+
+
+int _get_list_by_folder(int parent_id, bookmark_list_h *list)
+{
+ FAVORITES_LOGD("");
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int *ids = NULL;
+ int ids_count = -1;
+ bp_bookmark_info_fmt info;
+ if (bp_bookmark_adaptor_get_sequence_child_ids_p(&ids, &ids_count, -1, 0, parent_id, -1, 0) < 0) {
+ FAVORITES_LOGE("bp_bookmark_adaptor_get_sequence_child_ids_p is failed");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ FAVORITES_LOGD("ids_count: %d", ids_count);
+ if (ids_count < 0) {
+ FAVORITES_LOGE("bookmark list is empty");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ *list = (bookmark_list_h) calloc(1, sizeof(bookmark_list_s));
+ (*list)->count = 0;
+ (*list)->item =
+ (bookmark_entry_internal_h) calloc(ids_count, sizeof(bookmark_entry_internal_s));
+ int i = 0;
+ for(i = 0; i < ids_count; i++) {
+ (*list)->item[i].id = ids[i];
+ if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
+ BP_BOOKMARK_O_PARENT | BP_BOOKMARK_O_SEQUENCE |
+ BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
+ BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_DATE_CREATED |
+ BP_BOOKMARK_O_DATE_MODIFIED), &info) == 0) {
+ (*list)->item[i].is_folder = info.type;
+ (*list)->item[i].folder_id = info.parent;
+ (*list)->item[i].orderIndex = info.sequence;
+ (*list)->item[i].editable = info.editable;
+
+ if (info.url != NULL && strlen(info.url) > 0)
+ (*list)->item[i].address = strdup(info.url);
+ if (info.title != NULL && strlen(info.title) > 0)
+ (*list)->item[i].title = strdup(info.title);
+ FAVORITES_LOGD("Title: %s", (*list)->item[i].title);
+
+ (*list)->item[i].creationdate = NULL;
+ (*list)->item[i].creationdate = (char *)calloc(128, sizeof(char));
+ strftime((*list)->item[i].creationdate,128,"%Y-%m-%d %H:%M:%S",localtime((time_t *)&(info.date_created)));
+
+ (*list)->item[i].updatedate = NULL;
+ (*list)->item[i].updatedate = (char *)calloc(128, sizeof(char));
+ strftime((*list)->item[i].updatedate,128,"%Y-%m-%d %H:%M:%S",localtime((time_t *)&(info.date_modified)));
+ }
+ bp_bookmark_adaptor_easy_free(&info);
+ }
+ (*list)->count = i;
+ FAVORITES_LOGE("bookmark list count : %d", (*list)->count);
+ free(ids);
+ return FAVORITES_ERROR_NONE;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ int item_count = _get_count_by_folder(parent_id);
+ if (item_count < 0) {
+ FAVORITES_LOGD("_get_count_by_folder is failed");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select id, type, parent, address, title, editable,\
+ creationdate, updatedate, sequence \
+ from bookmarks where parent=? order by sequence",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ if (sqlite3_bind_int(stmt, 1, parent_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ *list = (bookmark_list_h) calloc(1, sizeof(bookmark_list_s));
+ (*list)->count = 0;
+ (*list)->item =
+ (bookmark_entry_internal_h) calloc(item_count, sizeof(bookmark_entry_internal_s));
+ int i = 0;
+ while ((nError = sqlite3_step(stmt)) == SQLITE_ROW && (i < item_count)) {
+ (*list)->item[i].id = sqlite3_column_int(stmt, 0);
+ (*list)->item[i].is_folder = sqlite3_column_int(stmt, 1);
+ (*list)->item[i].folder_id = sqlite3_column_int(stmt, 2);
+
+ (*list)->item[i].address = NULL;
+ if (!(*list)->item[i].is_folder) {
+ const char *url = (const char *)(sqlite3_column_text(stmt, 3));
+ if (url) {
+ int length = strlen(url);
+ if (length > 0) {
+ (*list)->item[i].address = (char *)calloc(length + 1, sizeof(char));
+ memcpy((*list)->item[i].address, url, length);
+ FAVORITES_LOGE ("url:%s\n", url);
+ }
+ }
+ }
+
+ const char *title = (const char *)(sqlite3_column_text(stmt, 4));
+ (*list)->item[i].title = NULL;
+ if (title) {
+ int length = strlen(title);
+ if (length > 0) {
+ (*list)->item[i].title = (char *)calloc(length + 1, sizeof(char));
+ memcpy((*list)->item[i].title, title, length);
+ }
+ }
+ (*list)->item[i].editable = sqlite3_column_int(stmt, 5);
+
+ const char *creationdate = (const char *)(sqlite3_column_text(stmt, 6));
+ (*list)->item[i].creationdate = NULL;
+ if (creationdate) {
+ int length = strlen(creationdate);
+ if (length > 0) {
+ (*list)->item[i].creationdate = (char *)calloc(length + 1, sizeof(char));
+ memcpy((*list)->item[i].creationdate, creationdate, length);
+ }
+ }
+ const char *updatedate = (const char *)(sqlite3_column_text(stmt, 7));
+ (*list)->item[i].updatedate = NULL;
+ if (updatedate) {
+ int length = strlen(updatedate);
+ if (length > 0) {
+ (*list)->item[i].updatedate = (char *)calloc(length + 1, sizeof(char));
+ memcpy((*list)->item[i].updatedate, updatedate, length);
+ }
+ }
+
+ (*list)->item[i].orderIndex = sqlite3_column_int(stmt, 8);
+ i++;
+ }
+
+ (*list)->count = i;
+ FAVORITES_LOGE("bookmark list count : %d", (*list)->count);
+
+ if ((nError != SQLITE_ROW) && (nError != SQLITE_DONE)) {
+ FAVORITES_LOGE("sqlite3_step is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+#endif
+}
+
+int _set_full_tree_to_html_recur(int parent_id, FILE *fp, int depth)
+{
+ FAVORITES_LOGD("depth: %d", depth);
+ if (parent_id < 0)
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ if (fp == NULL)
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ if (depth < 0)
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+
+ bookmark_list_h child_list = NULL;
+
+ int ret = _get_list_by_folder(parent_id, &child_list);
+
+ if (ret != FAVORITES_ERROR_NONE) {
+ _favorites_free_bookmark_list(child_list);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ int i = 0;
+ int j = 0;
+ FAVORITES_LOGD("list->count: %d", child_list->count);
+ for (i=0; i < (child_list->count); i++) {
+ FAVORITES_LOGD("title: %s", child_list->item[i].title);
+ if (child_list->item[i].is_folder) {
+ for (j=0 ; j < depth ; j++) {
+ fputs("\t", fp);
+ }
+ int folder_adddate_unixtime = 0;
+ folder_adddate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ child_list->item[i].creationdate);
+ fprintf(fp, "<DT><H3 FOLDED ADD_DATE=\"%d\">%s</H3>\n",
+ folder_adddate_unixtime, child_list->item[i].title);
+ for (j=0 ; j < depth ; j++) {
+ fputs("\t", fp);
+ }
+ fputs("<DL><p>\n", fp);
+ ret = _set_full_tree_to_html_recur(child_list->item[i].id, fp, depth+1);
+ if (ret != FAVORITES_ERROR_NONE) {
+ _favorites_free_bookmark_list(child_list);
+ return ret;
+ }
+ for (j=0 ; j < depth ; j++) {
+ fputs("\t", fp);
+ }
+ fputs("</DL><p>\n", fp);
+ }else {
+ int bookmark_adddate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ child_list->item[i].creationdate);
+
+ if(bookmark_adddate_unixtime<0)
+ bookmark_adddate_unixtime=0;
+
+ int bookmark_updatedate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ child_list->item[i].updatedate);
+
+ if(bookmark_updatedate_unixtime<0)
+ bookmark_updatedate_unixtime=0;
+
+ for (j=0 ; j < depth ; j++) {
+ fputs("\t", fp);
+ }
+ fprintf(fp,"<DT><A HREF=\"%s\" ",
+ child_list->item[i].address);
+ fprintf(fp,"ADD_DATE=\"%d\" ",
+ bookmark_adddate_unixtime);
+ fprintf(fp,"LAST_VISIT=\"%d\" ",
+ bookmark_updatedate_unixtime);
+ fprintf(fp,"LAST_MODIFIED=\"%d\">",
+ bookmark_updatedate_unixtime);
+ fprintf(fp,"%s</A>\n", child_list->item[i].title );
+ }
+ }
+
+ _favorites_free_bookmark_list(child_list);
+ return FAVORITES_ERROR_NONE;
+}
+
+/*************************************************************
+ * APIs for Internet favorites
+ *************************************************************/
+int favorites_bookmark_get_root_folder_id(int *root_id)
+{
+ FAVORITES_LOGE("");
+ if (!root_id)
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+
+ *root_id = _get_root_folder_id();
+ FAVORITES_LOGE("root_id: %d", *root_id);
+ return FAVORITES_ERROR_NONE;
+}
+
+int favorites_bookmark_add_bookmark(const char *url, const char *title, const char *foldername, int *bookmark_id)
+{
+ FAVORITES_LOGE("");
+ int ret = 0;
+ int root_id = 1;
+ int folder_id = 1;
+
+ if (!foldername || (strlen(foldername) <= 0)) {
+ FAVORITES_LOGE("foldername is empty. id is now root.\n");
+ folder_id = _get_root_folder_id();
+ } else {
+ FAVORITES_LOGE("adding folder\n");
+ ret = favorites_bookmark_add(foldername, url, root_id, 1, &folder_id);
+ if (ret != FAVORITES_ERROR_NONE) {
+ if (ret == FAVORITES_ERROR_ITEM_ALREADY_EXIST) {
+ folder_id = _get_folder_id(foldername, _get_root_folder_id());
+ } else
+ return ret;
+ }
+ }
+ return favorites_bookmark_add(title, url, folder_id, 0, bookmark_id);
+}
+
+int favorites_bookmark_add(const char *title, const char *url, int parent_id, int type, int *saved_id)
+{
+ FAVORITES_LOGD("");
+ int ret = 0;
+ if (type == 0) {
+ FAVORITES_LOGD("type is bookmark");
+ ret = _add_bookmark(title, url, parent_id, saved_id);
+ } else {
+ FAVORITES_LOGD("type is folder");
+ ret = _add_folder(title, parent_id, saved_id);
+ }
+
+ return ret;
+}
+
+int favorites_bookmark_get_count(int *count)
+{
+ FAVORITES_LOGD("");
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int ids_count = 0;
+ int *ids = NULL;
+ bp_bookmark_adaptor_get_full_ids_p(&ids, &ids_count);
+ *count = ids_count;
+ free(ids);
+
+ if (*count <0) {
+ FAVORITES_LOGE("bp_bookmark_adaptor_get_full_ids_p is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ return FAVORITES_ERROR_NONE;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ FAVORITES_NULL_ARG_CHECK(count);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /* folder + bookmark */
+#if defined(ROOT_IS_ZERO)
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select count(*) from bookmarks",
+ -1, &stmt, NULL);
+#else
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select count(*) from bookmarks where parent != 0",
+ -1, &stmt, NULL);
+#endif
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ *count = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ } else if (nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
+int favorites_bookmark_foreach(favorites_bookmark_foreach_cb callback,void *user_data)
+{
+ FAVORITES_NULL_ARG_CHECK(callback);
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int ids_count = 0;
+ int *ids = NULL;
+ int func_ret = 0;
+ int is_folder = -1;
+ int editable = -1;
+
+ if (bp_bookmark_adaptor_get_full_ids_p(&ids, &ids_count) < 0) {
+ FAVORITES_LOGE ("bp_bookmark_adaptor_get_full_ids_p is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ FAVORITES_LOGD("bp_bookmark_adaptor_get_full_ids_p count : %d", ids_count);
+ if (ids_count > 0) {
+ int i = 0;
+ for (i = 0; i < ids_count; i++) {
+ FAVORITES_LOGD("I[%d] id : %d", i, ids[i]);
+ favorites_bookmark_entry_s result;
+ memset(&result, 0x00, sizeof(favorites_bookmark_entry_s));
+ result.id = ids[i];
+ bp_bookmark_adaptor_get_type(result.id, &is_folder);
+ if (is_folder > 0)
+ result.is_folder = 1;
+ else
+ result.is_folder = 0;
+ FAVORITES_LOGD("is_folder : %d", result.is_folder);
+ bp_bookmark_adaptor_get_parent_id(result.id, &(result.folder_id));
+ FAVORITES_LOGD("folder_id : %d", result.folder_id);
+ bp_bookmark_adaptor_get_url(result.id, &(result.address));
+ FAVORITES_LOGD("address : %s", result.address);
+ bp_bookmark_adaptor_get_title(result.id, &(result.title));
+ FAVORITES_LOGD("title : %s", result.title);
+ bp_bookmark_adaptor_get_is_editable(result.id, &editable);
+ if (editable > 0)
+ result.editable = 1;
+ else
+ result.editable = 0;
+ bp_bookmark_adaptor_get_sequence(result.id, &(result.order_index));
+ FAVORITES_LOGD("order_index : %d", result.order_index);
+
+ result.creation_date = NULL;
+ int recv_int = -1;
+ bp_bookmark_adaptor_get_date_created(result.id, &recv_int);
+ result.creation_date = (char *)calloc(128, sizeof(char));
+ strftime(result.creation_date,128,"%Y-%m-%d %H:%M:%S",localtime((time_t *)&recv_int));
+ FAVORITES_LOGD("Creationdata:%s", result.creation_date);
+
+ result.update_date = NULL;
+ bp_bookmark_adaptor_get_date_modified(result.id, &recv_int);
+ result.update_date = (char *)calloc(128, sizeof(char));
+ strftime(result.update_date,128,"%Y-%m-%d %H:%M:%S",localtime((time_t *)&recv_int));
+ FAVORITES_LOGD("update_date:%s", result.update_date);
+
+ result.visit_date = NULL;
+ bp_bookmark_adaptor_get_date_visited(result.id, &recv_int);
+ result.visit_date = (char *)calloc(128, sizeof(char));
+ strftime(result.visit_date,128,"%Y-%m-%d %H:%M:%S",localtime((time_t *)&recv_int));
+ FAVORITES_LOGD("visit_date:%s", result.visit_date);
+
+ func_ret = callback(&result, user_data);
+ _favorites_free_bookmark_entry(&result);
+ if(func_ret == 0)
+ break;
+ }
+ }
+ free(ids);
+ FAVORITES_LOGE ("There are no more bookmarks.\n");
+ return FAVORITES_ERROR_NONE;
+#else
+ int nError;
+ int func_ret = 0;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+#if defined(ROOT_IS_ZERO)
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select id, type, parent, address, title, editable,\
+ creationdate, updatedate, sequence \
+ from bookmarks order by sequence",
+ -1, &stmt, NULL);
+#else
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select id, type, parent, address, title, editable,\
+ creationdate, updatedate, sequence \
+ from bookmarks where parent != 0 order by sequence",
+ -1, &stmt, NULL);
+#endif
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ while ((nError = sqlite3_step(stmt)) == SQLITE_ROW) {
+ favorites_bookmark_entry_s result;
+ memset(&result, 0x00, sizeof(favorites_bookmark_entry_s));
+ result.id = sqlite3_column_int(stmt, 0);
+ result.is_folder = sqlite3_column_int(stmt, 1);
+ result.folder_id = sqlite3_column_int(stmt, 2);
+
+ result.address = NULL;
+ if (!result.is_folder) {
+ const char *url = (const char *)(sqlite3_column_text(stmt, 3));
+ if (url) {
+ int length = strlen(url);
+ if (length > 0) {
+ result.address = (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.address, url, length);
+ FAVORITES_LOGE ("url:%s\n", url);
+ }
+ }
+ }
+
+ const char *title = (const char *)(sqlite3_column_text(stmt, 4));
+ result.title = NULL;
+ if (title) {
+ int length = strlen(title);
+ if (length > 0) {
+ result.title = (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.title, title, length);
+ FAVORITES_LOGE ("title:%s\n", title);
+ }
+ }
+ result.editable = sqlite3_column_int(stmt, 5);
+
+ const char *creation_date = (const char *)(sqlite3_column_text(stmt, 6));
+ result.creation_date = NULL;
+ if (creation_date) {
+ int length = strlen(creation_date);
+ if (length > 0) {
+ result.creation_date = (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.creation_date, creation_date, length);
+ }
+ }
+ const char *update_date = (const char *)(sqlite3_column_text(stmt, 7));
+ result.update_date = NULL;
+ if (update_date) {
+ int length = strlen(update_date);
+ if (length > 0) {
+ result.update_date = (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.update_date, update_date, length);
+ }
+ }
+
+ result.order_index = sqlite3_column_int(stmt, 8);
+
+ func_ret = callback(&result, user_data);
+ _favorites_free_bookmark_entry(&result);
+ if(func_ret == 0)
+ break;
+ }
+
+ FAVORITES_LOGE ("There are no more bookmarks.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+#endif
+}
+
+int favorites_bookmark_export_list(const char *file_path)
+{
+ FAVORITES_NULL_ARG_CHECK(file_path);
+
+ int root_id = -1;
+ favorites_bookmark_get_root_folder_id(&root_id);
+
+ FILE *fp = NULL;
+ FAVORITES_LOGE("file_path: %s", file_path);
+ fp = fopen(file_path, "w");
+ if (fp == NULL) {
+ FAVORITES_LOGE("file opening is failed.");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+ fputs("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n", fp);
+ fputs("<!-- This is an automatically generated file.\n", fp);
+ fputs("It will be read and overwritten.\n", fp);
+ fputs("Do Not Edit! -->\n", fp);
+ fputs("<META HTTP-EQUIV=\"Content-Type\" ", fp);
+ fputs("CONTENT=\"text/html; charset=UTF-8\">\n", fp);
+ fputs("<TITLE>Bookmarks</TITLE>\n", fp);
+ fputs("<H1>Bookmarks</H1>\n", fp);
+ fputs("<DL><p>\n", fp);
+
+ int ret = -1;
+ ret = _set_full_tree_to_html_recur(root_id, fp, 1);
+ if (ret != FAVORITES_ERROR_NONE) {
+ fclose(fp);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ fputs("</DL><p>\n", fp);
+ fclose(fp);
+ return FAVORITES_ERROR_NONE;
+}
+
+int favorites_bookmark_get_favicon(int id, Evas *evas, Evas_Object **icon)
+{
+ FAVORITES_LOGD("");
+ FAVORITES_INVALID_ARG_CHECK(id<0);
+ FAVORITES_NULL_ARG_CHECK(evas);
+ FAVORITES_NULL_ARG_CHECK(icon);
+#if defined(BROWSER_BOOKMARK_SYNC)
+ void *favicon_data_temp=NULL;
+ favicon_entry_h favicon;
+ favicon = (favicon_entry_h) calloc(1, sizeof(favicon_entry_s));
+ int ret = bp_bookmark_adaptor_get_favicon(id, (unsigned char **)&favicon_data_temp, &(favicon->length));
+ if (ret == 0) {
+ if (bp_bookmark_adaptor_get_favicon_width(id, &(favicon->w)) == 0) {
+ if (bp_bookmark_adaptor_get_favicon_height(id, &(favicon->h)) == 0) {
+ FAVORITES_LOGD("favicon is successfully loaded.");
+ } else {
+ FAVORITES_LOGE("bp_bookmark_adaptor_set_favicon_height is failed");
+ *icon = NULL;
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ } else {
+ FAVORITES_LOGE("bp_bookmark_adaptor_set_favicon_width is failed");
+ *icon = NULL;
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ } else {
+ FAVORITES_LOGE("bp_bookmark_adaptor_set_favicon is failed");
+ *icon = NULL;
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ FAVORITES_LOGD("len: %d, w:%d, h:%d", favicon->length, favicon->w, favicon->h);
+ if (favicon->length > 0){
+ *icon = evas_object_image_filled_add(evas);
+ evas_object_image_colorspace_set(*icon, EVAS_COLORSPACE_ARGB8888);
+ evas_object_image_size_set(*icon, favicon->w, favicon->h);
+ evas_object_image_fill_set(*icon, 0, 0, favicon->w, favicon->h);
+ evas_object_image_filled_set(*icon, EINA_TRUE);
+ evas_object_image_alpha_set(*icon,EINA_TRUE);
+ evas_object_image_data_set(*icon, favicon_data_temp);
+ return FAVORITES_ERROR_NONE;
+ }
+ *icon = NULL;
+ FAVORITES_LOGE("favicon length is 0");
+ return FAVORITES_ERROR_DB_FAILED;
+#else
+ void *favicon_data_temp=NULL;
+ favicon_entry_h favicon;
+ sqlite3_stmt *stmt;
+ char query[1024];
+ int nError;
+
+ memset(&query, 0x00, sizeof(char)*1024);
+ sprintf(query, "select favicon, favicon_length, favicon_w, favicon_h from bookmarks\
+ where id=%d"
+ , id);
+ FAVORITES_LOGE("query: %s", query);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ query, -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ favicon = (favicon_entry_h) calloc(1, sizeof(favicon_entry_s));
+ /* loading favicon from bookmark db */
+ favicon_data_temp = (void *)sqlite3_column_blob(stmt,0);
+ favicon->length = sqlite3_column_int(stmt,1);
+ favicon->w = sqlite3_column_int(stmt,2);
+ favicon->h = sqlite3_column_int(stmt,3);
+
+ if (favicon->length > 0){
+ favicon->data = calloc(1, favicon->length);
+ memcpy(favicon->data, favicon_data_temp, favicon->length);
+ /* transforming to evas object */
+ *icon = evas_object_image_filled_add(evas);
+ evas_object_image_colorspace_set(*icon,
+ EVAS_COLORSPACE_ARGB8888);
+ evas_object_image_size_set(*icon, favicon->w, favicon->h);
+ evas_object_image_fill_set(*icon, 0, 0, favicon->w,
+ favicon->h);
+ evas_object_image_filled_set(*icon, EINA_TRUE);
+ evas_object_image_alpha_set(*icon,EINA_TRUE);
+ evas_object_image_data_set(*icon, favicon->data);
+ }
+ free(favicon);
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_NONE;
+#endif
+}
+
+int favorites_bookmark_set_favicon(int bookmark_id, Evas_Object *icon)
+{
+ FAVORITES_LOGD("");
+ FAVORITES_INVALID_ARG_CHECK(bookmark_id<0);
+ FAVORITES_NULL_ARG_CHECK(icon);
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int icon_w = 0;
+ int icon_h = 0;
+ int stride = 0;
+ int icon_length = 0;
+ void *icon_data = (void *)evas_object_image_data_get(icon, EINA_TRUE);
+ evas_object_image_size_get(icon, &icon_w, &icon_h);
+ stride = evas_object_image_stride_get(icon);
+ icon_length = icon_h * stride;
+ FAVORITES_LOGD("favicon size w:%d, h:%d, stride: %d", icon_w, icon_h, stride);
+ int ret = bp_bookmark_adaptor_set_favicon(bookmark_id,(const unsigned char *)icon_data, icon_length);
+ if (ret == 0) {
+ if (bp_bookmark_adaptor_set_favicon_width(bookmark_id, icon_w) == 0) {
+ if (bp_bookmark_adaptor_set_favicon_height(bookmark_id, icon_h) == 0) {
+ FAVORITES_LOGE("favicon is successfully saved.");
+ bp_bookmark_adaptor_publish_notification();
+ return FAVORITES_ERROR_NONE;
+ } else
+ FAVORITES_LOGE("bp_bookmark_adaptor_set_favicon_height is failed");
+ } else
+ FAVORITES_LOGE("bp_bookmark_adaptor_set_favicon_width is failed");
+ } else
+ FAVORITES_LOGE("bp_bookmark_adaptor_set_favicon is failed");
+ FAVORITES_LOGE("set favicon is failed");
+ return FAVORITES_ERROR_DB_FAILED;
+#else
+ int icon_w = 0;
+ int icon_h = 0;
+ int stride = 0;
+ int icon_length = 0;
+ void *icon_data = (void *)evas_object_image_data_get(icon, EINA_TRUE);
+ evas_object_image_size_get(icon, &icon_w, &icon_h);
+ stride = evas_object_image_stride_get(icon);
+ icon_length = icon_h * stride;
+ FAVORITES_LOGD("favicon size w:%d, h:%d, stride: %d", icon_w, icon_h, stride);
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "UPDATE bookmarks SET favicon=?,\
+ favicon_length=?, favicon_w=?, favicon_h=? \
+ WHERE id=?", -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ // bind
+ if (sqlite3_bind_blob(stmt, 1, icon_data , icon_length, NULL) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_blob(icon_data) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 2, icon_length) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(icon_length) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 3, icon_w) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(icon_w) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 4, icon_h) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(icon_h) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ if (sqlite3_bind_int(stmt, 5, bookmark_id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int(bookmark_id) is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
+int favorites_bookmark_delete_bookmark(int id)
+{
+ FAVORITES_LOGE("");
+ FAVORITES_INVALID_ARG_CHECK(id<0);
+#if defined(BROWSER_BOOKMARK_SYNC)
+ if (bp_bookmark_adaptor_delete(id) < 0)
+ return FAVORITES_ERROR_DB_FAILED;
+ else {
+ bp_bookmark_adaptor_publish_notification();
+ return FAVORITES_ERROR_NONE;
+ }
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+#if defined(ROOT_IS_ZERO)
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "delete from bookmarks where id=?", -1, &stmt, NULL);
+#else
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "delete from bookmarks where id=? and parent != 0", -1, &stmt, NULL);
+#endif
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ // bind
+ if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
+int favorites_bookmark_delete_all_bookmarks(void)
+{
+ FAVORITES_LOGD("");
+#if defined(BROWSER_BOOKMARK_SYNC)
+ int ids_count = 0;
+ int *ids = NULL;
+
+ if (bp_bookmark_adaptor_get_full_ids_p(&ids, &ids_count) < 0) {
+ FAVORITES_LOGE ("bp_bookmark_adaptor_get_full_ids_p is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ FAVORITES_LOGD("bp_bookmark_adaptor_get_full_ids_p count : %d", ids_count);
+ if (ids_count > 0) {
+ int i = 0;
+ for (i = 0; i < ids_count; i++) {
+ FAVORITES_LOGD("I[%d] id : %d", i, ids[i]);
+ if (bp_bookmark_adaptor_delete(ids[i]) < 0) {
+ free(ids);
+ return FAVORITES_ERROR_DB_FAILED;
+ } else
+ bp_bookmark_adaptor_publish_notification();
+ }
+ }
+ free(ids);
+ return FAVORITES_ERROR_NONE;
+#else
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+#if defined(ROOT_IS_ZERO)
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "delete from bookmarks", -1, &stmt, NULL);
+#else
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "delete from bookmarks where parent !=0", -1, &stmt, NULL);
+#endif
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_bookmark_db));
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+#endif
+}
+
diff --git a/src/favorites_history.c b/src/favorites_history.c
new file mode 100644
index 0000000..d72d28d
--- /dev/null
+++ b/src/favorites_history.c
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 <string.h>
+#include <dlog.h>
+#include <db-util.h>
+#include <favorites.h>
+#include <favorites_private.h>
+
+sqlite3 *gl_internet_history_db = 0;
+
+#define INTERNET_HISTORY_DB_NAME "/opt/usr/dbspace/.browser-history.db"
+
+/* Private Functions */
+void _favorites_history_db_close(void)
+{
+ if (gl_internet_history_db) {
+ /* ASSERT(currentThread() == m_openingThread); */
+ db_util_close(gl_internet_history_db);
+ gl_internet_history_db = 0;
+ }
+}
+
+void _favorites_history_db_finalize(sqlite3_stmt *stmt)
+{
+ if (sqlite3_finalize(stmt) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_finalize is failed");
+ }
+ _favorites_history_db_close();
+}
+int _favorites_history_db_open(void)
+{
+ _favorites_history_db_close();
+ if (db_util_open
+ (INTERNET_HISTORY_DB_NAME, &gl_internet_history_db,
+ DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
+ db_util_close(gl_internet_history_db);
+ gl_internet_history_db = 0;
+ return -1;
+ }
+ return gl_internet_history_db ? 0 : -1;
+}
+
+int _favorites_free_history_entry(favorites_history_entry_s *entry)
+{
+ FAVORITES_NULL_ARG_CHECK(entry);
+
+ if (entry->address != NULL)
+ free(entry->address);
+ if (entry->title != NULL)
+ free(entry->title);
+ if (entry->visit_date != NULL)
+ free(entry->visit_date);
+
+ return FAVORITES_ERROR_NONE;
+}
+/*************************************************************
+ * APIs for Internet favorites
+ *************************************************************/
+int favorites_history_get_count(int *count)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+ FAVORITES_LOGE("");
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /* folder + bookmark */
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ "select count(*) from history",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ *count = sqlite3_column_int(stmt, 0);
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ _favorites_history_db_close();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+/* Public CAPI */
+int favorites_history_foreach(favorites_history_foreach_cb callback,void *user_data)
+{
+ FAVORITES_NULL_ARG_CHECK(callback);
+ int nError;
+ int func_ret = 0;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ "select id, address, title, counter, visitdate\
+ from history order by visitdate desc",
+ -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ while ((nError = sqlite3_step(stmt)) == SQLITE_ROW) {
+ favorites_history_entry_s result;
+ result.id = sqlite3_column_int(stmt, 0);
+
+ result.address = NULL;
+ const char *url = (const char *)(sqlite3_column_text(stmt, 1));
+ if (url) {
+ int length = strlen(url);
+ if (length > 0) {
+ result.address = (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.address, url, length);
+ FAVORITES_LOGE ("url:%s\n", url);
+ }
+ }
+
+ const char *title = (const char *)(sqlite3_column_text(stmt, 2));
+ result.title = NULL;
+ if (title) {
+ int length = strlen(title);
+ if (length > 0) {
+ result.title = (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.title, title, length);
+ }
+ }
+ result.count = sqlite3_column_int(stmt, 3);
+
+ const char *visit_date =
+ (const char *)(sqlite3_column_text(stmt, 4));
+ result.visit_date = NULL;
+ if (visit_date) {
+ int length = strlen(visit_date);
+ if (length > 0) {
+ result.visit_date =
+ (char *)calloc(length + 1, sizeof(char));
+ memcpy(result.visit_date,
+ visit_date, length);
+ FAVORITES_LOGE("Date:%s\n", result.visit_date);
+ }
+ }
+
+ func_ret = callback(&result, user_data);
+ _favorites_free_history_entry(&result);
+ if(func_ret == 0)
+ break;
+ }
+
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+}
+
+int favorites_history_delete_history(int id)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+
+ FAVORITES_INVALID_ARG_CHECK(id<0);
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ "delete from history where id=?", -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ // bind
+ if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_bind_int is failed");
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_history_db_close();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int favorites_history_delete_history_by_url(const char *url)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (!url || (strlen(url) <= 0)) {
+ FAVORITES_LOGE("url is empty\n");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ "delete from history where address=?", -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ // bind
+ if (sqlite3_bind_text(stmt, 1, url, -1, NULL) != SQLITE_OK)
+ FAVORITES_LOGE("sqlite3_bind_text is failed.\n");
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_history_db_close();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int favorites_history_delete_all_histories(void)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ "delete from history", -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_history_db_close();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int favorites_history_delete_history_by_term(const char *begin, const char *end)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ if (!begin || (strlen(begin) <= 0)) {
+ FAVORITES_LOGE("begin date is empty\n");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!end || (strlen(end) <= 0)) {
+ FAVORITES_LOGE("end date is empty\n");
+ end = "now";
+ }
+
+ sprintf(query, "delete from history where visitdate\
+ between datetime('%s') and datetime('%s')", begin, end);
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ query, -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW || nError == SQLITE_DONE) {
+ FAVORITES_LOGE("sqlite3_step is DONE");
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_history_db_close();
+
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int favorites_history_get_favicon(int id, Evas *evas, Evas_Object **icon)
+{
+ FAVORITES_INVALID_ARG_CHECK(id<0);
+ FAVORITES_NULL_ARG_CHECK(evas);
+ FAVORITES_NULL_ARG_CHECK(icon);
+
+ sqlite3_stmt *stmt;
+ char query[1024];
+ void *favicon_data_temp=NULL;
+ favicon_entry_h favicon;
+ int nError;
+
+ memset(&query, 0x00, sizeof(char)*1024);
+ sprintf(query, "select favicon, favicon_length, favicon_w, favicon_h from history\
+ where id=%d"
+ , id);
+ FAVORITES_LOGE("query: %s", query);
+
+ if (_favorites_history_db_open() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_history_db,
+ query, -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed(%s).\n",
+ sqlite3_errmsg(gl_internet_history_db));
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ favicon = (favicon_entry_h) calloc(1, sizeof(favicon_entry_s));
+ /* loading favicon from history db */
+ favicon_data_temp = (void *)sqlite3_column_blob(stmt,0);
+ favicon->length = sqlite3_column_int(stmt,1);
+ favicon->w = sqlite3_column_int(stmt,2);
+ favicon->h = sqlite3_column_int(stmt,3);
+
+ if (favicon->length > 0){
+ favicon->data = calloc(1, favicon->length);
+ memcpy(favicon->data, favicon_data_temp, favicon->length);
+ /* transforming to evas object */
+ *icon = evas_object_image_filled_add(evas);
+ evas_object_image_colorspace_set(*icon,
+ EVAS_COLORSPACE_ARGB8888);
+ evas_object_image_size_set(*icon, favicon->w, favicon->h);
+ evas_object_image_fill_set(*icon, 0, 0, favicon->w,
+ favicon->h);
+ evas_object_image_filled_set(*icon, EINA_TRUE);
+ evas_object_image_alpha_set(*icon,EINA_TRUE);
+ evas_object_image_data_set(*icon, favicon->data);
+ }
+ free(favicon);
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+
+ _favorites_history_db_close();
+ return FAVORITES_ERROR_NONE;
+}
+