diff options
author | Kim Kibum <kb0929.kim@samsung.com> | 2012-04-29 16:58:24 +0900 |
---|---|---|
committer | Kim Kibum <kb0929.kim@samsung.com> | 2012-04-29 16:58:24 +0900 |
commit | e457b7228f124ad064faa8168584f0cdd7e32773 (patch) | |
tree | c5435fc5b80c35f6204b94a909a9504cae97722d | |
parent | b3f8a1f2924e1e6269000fd6e06da5aa8e082a8c (diff) | |
download | favorites-e457b7228f124ad064faa8168584f0cdd7e32773.tar.gz favorites-e457b7228f124ad064faa8168584f0cdd7e32773.tar.bz2 favorites-e457b7228f124ad064faa8168584f0cdd7e32773.zip |
upload tizen1.0 source
-rwxr-xr-x | CMakeLists.txt | 98 | ||||
-rwxr-xr-x | capi-web-favorites.pc.in | 14 | ||||
-rw-r--r-- | debian/capi-web-favorites-dev.install | 4 | ||||
-rw-r--r-- | debian/capi-web-favorites-dev.postinst | 1 | ||||
-rw-r--r-- | debian/capi-web-favorites.install | 1 | ||||
-rw-r--r-- | debian/capi-web-favorites.postinst | 1 | ||||
-rwxr-xr-x | debian/changelog | 26 | ||||
-rwxr-xr-x | debian/compat | 1 | ||||
-rw-r--r-- | debian/control | 22 | ||||
-rwxr-xr-x | debian/rules | 71 | ||||
-rw-r--r-- | include/favorites.h | 301 | ||||
-rw-r--r-- | include/favorites_private.h | 133 | ||||
-rwxr-xr-x | packaging/capi-web-favorites.spec | 54 | ||||
-rwxr-xr-x | packaging/capi-web-favorites.spec~ | 54 | ||||
-rw-r--r-- | src/favorites_bookmark.c | 1149 | ||||
-rw-r--r-- | src/favorites_history.c | 320 |
16 files changed, 2250 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..3c93fe5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,98 @@ +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\" +) + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +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( + 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/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/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..13452bb --- /dev/null +++ b/debian/changelog @@ -0,0 +1,26 @@ +capi-web-favorites (0.0.3) unstable; urgency=low + + * Git: api/favorites + * Tag: capi-web-favorites_0.0.3 + + * Applying modification to fix miss typing and some wrong settings. + + -- Sangpyo Kim <sangpyo7.kim@samsung.com> Thu, 15 Mar 2012 17:42:44 +0900 + +capi-web-favorites (0.0.2) unstable; urgency=low + + * Git: api/favorites + * Tag: capi-web-favorites_0.0.2 + + * moving location of history database file + * SO versioning fixed + + -- Sangpyo Kim <sangpyo7.kim@samsung.com> Fri, 17 Feb 2012 15:23:59 +0900 + +capi-web-favorites (0.0.1) unstable; urgency=low + + * Git: 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..d16cfe2 --- /dev/null +++ b/include/favorites.h @@ -0,0 +1,301 @@ +/*
+ * Copyright (c) 2011 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_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 */
+ char* update_date; /**< The last updated date */
+ char* visit_date; /**< The last visit date */
+ int id; /**< The unique ID of bookmark */
+ bool is_folder; /**< property bookmark or folder\n @c true: folder, @c false: 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 true : writable, @c false: 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 Adds an entry to bookmark list.
+ *
+ * @remarks If a folder named @a "foldername" doesn't exist, it will be created.
+ * @remarks The folder named "Bookmarks" is reserved for the root folder.
+ * @param[in] url Book URL
+ * @param[in] title The title of the bookmark
+ * @param[in] folder_name The name of parent folder
+ * @param[out] bookmark_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 *bookmark_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 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);
+
+/**
+ * @}
+ */
+
+#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..e370b0a --- /dev/null +++ b/include/favorites_private.h @@ -0,0 +1,133 @@ +/*
+ * Copyright (c) 2011 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(\
+ "[%s: %s: %d] "fmt, (rindex(__FILE__, '/')? rindex(__FILE__, '/') + 1 : __FILE__),\
+ __FUNCTION__, __LINE__, ##args)
+#define FAVORITES_LOGI(fmt, args...) LOGI(\
+ "[%s: %s: %d] "fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/') + 1 : __FILE__),\
+ __FUNCTION__, __LINE__, ##args)
+#define FAVORITES_LOGW(fmt, args...) LOGW(\
+ "[%s: %s: %d] "fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/') + 1 : __FILE__),\
+ __FUNCTION__, __LINE__, ##args)
+#define FAVORITES_LOGE(fmt, args...) LOGE(\
+ "[%s: %s: %d] "fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/') + 1 : __FILE__),\
+ __FUNCTION__, __LINE__, ##args)
+#define FAVORITES_LOGE_IF(cond, fmt, args...) LOGE_IF(cond,\
+ "[%s: %s: %d] "fmt, (rindex(__FILE__, '/') ? rindex(__FILE__, '/') + 1 : __FILE__),\
+ __FUNCTION__, __LINE__, ##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_bookmark_get_folderID(const char *foldername);
+int _favorites_bookmark_is_folder_exist(const char *foldername);
+int _favorites_bookmark_create_folder(const char *foldername);
+int _favorites_bookmark_is_bookmark_exist(const char *url, const char *title, const int folderId);
+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 _favorites_bookmark_get_bookmark_id(const char *url, const char *title, const int folder_id);
+
+/* 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..e569467 --- /dev/null +++ b/packaging/capi-web-favorites.spec @@ -0,0 +1,54 @@ +Name: capi-web-favorites +Summary: Internet bookmark and history API +Version: 0.0.3 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +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 . -DCMAKE_INSTALL_PREFIX=/usr + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%{_libdir}/libcapi-web-favorites.so + +%files devel +%{_includedir}/web/*.h +%{_libdir}/pkgconfig/*.pc + + diff --git a/packaging/capi-web-favorites.spec~ b/packaging/capi-web-favorites.spec~ new file mode 100755 index 0000000..904f6fa --- /dev/null +++ b/packaging/capi-web-favorites.spec~ @@ -0,0 +1,54 @@ +Name: capi-web-favorites +Summary: Internet bookmark and history API +Version: 0.0.1 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +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 . -DCMAKE_INSTALL_PREFIX=/usr + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%{_libdir}/libcapi-web-favorites.so + +%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..85f1927 --- /dev/null +++ b/src/favorites_bookmark.c @@ -0,0 +1,1149 @@ +/*
+ * Copyright (c) 2011 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>
+
+__thread sqlite3 *gl_internet_bookmark_db = 0;
+
+/* Private Functions */
+void _favorites_close_bookmark_db(void)
+{
+ if (gl_internet_bookmark_db) {
+ /* ASSERT(currentThread() == m_openingThread); */
+ db_util_close(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/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) {
+ db_util_close(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");
+ _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;
+ }
+ FAVORITES_LOGE("Not found items in This Folder");
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _favorites_bookmark_get_folderID(const char *foldername)
+{
+ FAVORITES_LOGE("foldername: %s", foldername);
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ /* If there is no identical folder name, create new folder */
+ if (_favorites_bookmark_is_folder_exist(foldername)==0){
+ if(_favorites_bookmark_create_folder(foldername)!=1){
+ FAVORITES_LOGE("folder creating is failed.");
+ return -1;
+ }
+ }
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ sprintf(query, "select id from bookmarks where type=1 AND title='%s'"
+ , foldername);
+
+ /* check foldername in the bookmark table */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,query
+ ,-1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ int folderId = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return folderId;
+ }
+ _favorites_close_bookmark_db();
+ return 1;
+}
+
+int _favorites_bookmark_is_folder_exist(const char *foldername)
+{
+ FAVORITES_LOGE("\n");
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ if (!foldername || (strlen(foldername) <= 0)) {
+ FAVORITES_LOGE("foldername is empty\n");
+ return -1;
+ }
+ FAVORITES_LOGE("foldername: %s", foldername);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ sprintf(query, "select id from bookmarks where type=1 AND title='%s'"
+ , foldername);
+
+ /* check foldername in the bookmark table */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,query
+ ,-1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _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;
+ }
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _favorites_bookmark_create_folder(const char *foldername)
+{
+ FAVORITES_LOGE("\n");
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+ int lastIndex = 0;
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ if (!foldername || (strlen(foldername) <= 0)) {
+ FAVORITES_LOGE("foldername is empty\n");
+ return -1;
+ }
+
+ if ((lastIndex = _favorites_get_bookmark_lastindex(1)) < 0) {
+ FAVORITES_LOGE("Database::getLastIndex() is failed.\n");
+ return -1;
+ }
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ sprintf(query, "insert into bookmarks \
+ (type, parent, title, creationdate, sequence, updatedate, editable)\
+ values (1, 1, '%s', DATETIME('now'), %d, DATETIME('now'), 1)"
+ , foldername, lastIndex);
+
+ FAVORITES_LOGE("query:%s\n", query);
+
+ 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 -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || nError == SQLITE_DONE) {
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+int _favorites_bookmark_is_bookmark_exist
+ (const char *url, const char *title, const int folderId)
+{
+ FAVORITES_LOGE("folderId: %d", folderId);
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ memset(&query, 0x00, sizeof(char)*1024);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ sprintf(query, "select id from bookmarks where \
+ type=0 AND address='%s' AND title='%s' AND parent=%d"
+ , url, title, folderId);
+ FAVORITES_LOGE("query: %s", query);
+
+ /* check bookmark in the bookmark table */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,query
+ ,-1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_ROW) {
+ /* There is same bookmark exist. */
+ _favorites_finalize_bookmark_db(stmt);
+ return 1;
+ }
+
+ FAVORITES_LOGE("there is no identical bookmark\n");
+ _favorites_close_bookmark_db();
+ /* there is no identical bookmark*/
+ return 0;
+}
+
+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.\n");
+ _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;
+ }
+ _favorites_close_bookmark_db();
+ FAVORITES_LOGE("End");
+ return 0;
+}
+
+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 and parent != 0",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _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;
+ }
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+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.\n");
+ _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 and parent != 0 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.\n");
+ _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;
+}
+
+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.\n");
+ _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;
+ }
+ _favorites_close_bookmark_db();
+ return 1;
+}
+
+/* search last of sequence(order's index) */
+int _favorites_bookmark_get_bookmark_id(const char *url, const char *title, const int folder_id)
+{
+ int nError;
+ sqlite3_stmt *stmt;
+ char query[1024];
+
+ /* Get the id of bookmark */
+ sprintf(query, "select id from bookmarks where \
+ type=0 AND address='%s' AND title='%s' AND parent=%d"
+ , url, title, folder_id);
+ FAVORITES_LOGE("query: %s", query);
+
+ if (_favorites_open_bookmark_db() < 0) {
+ FAVORITES_LOGE("db_util_open is failed\n");
+ return -1;
+ }
+
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ query, -1, &stmt, NULL);
+
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed");
+ _favorites_finalize_bookmark_db(stmt);
+ return -1;
+ }
+
+ if ((nError = sqlite3_step(stmt)) == SQLITE_ROW) {
+ int bookmark_id = sqlite3_column_int(stmt, 0);
+ _favorites_finalize_bookmark_db(stmt);
+ return bookmark_id;
+ }
+ FAVORITES_LOGE("No match with given url");
+ _favorites_close_bookmark_db();
+ return 0;
+}
+
+/*************************************************************
+ * APIs for Internet favorites
+ *************************************************************/
+int favorites_bookmark_add_bookmark(const char *url, const char *title, const char *foldername, int *bookmark_id)
+{
+ FAVORITES_LOGE("");
+ int nError;
+ sqlite3_stmt *stmt;
+ int folderId = 1;
+ char query[1024];
+ int lastIndex = 0;
+
+ memset(&query, 0x00, sizeof(char)*1024);
+ if (!url || (strlen(url) <= 0)) {
+ FAVORITES_LOGE("url is empty\n");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!title || (strlen(title) <= 0)) {
+ FAVORITES_LOGE("title is empty\n");
+ return FAVORITES_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check the foldername is exist and get a folderid */
+ if (!foldername || (strlen(foldername) <= 0)) {
+ FAVORITES_LOGE("foldername is empty. id is now root.\n");
+ folderId = 1;
+ }else if (!strcmp("Bookmarks", foldername)){
+ /*root folder name is "Bookmarks".*/
+ folderId = 1;
+ } else {
+ folderId = _favorites_bookmark_get_folderID(foldername);
+ if(folderId<0){
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+ }
+
+ /* Check the bookmarks is already exist*/
+ if(_favorites_bookmark_is_bookmark_exist(url, title, folderId)!=0){
+ FAVORITES_LOGE("The bookmark is already exist.\n");
+ return FAVORITES_ERROR_ITEM_ALREADY_EXIST;
+ }
+
+ /* get a last index for order of bookmark items */
+ if ((lastIndex = _favorites_get_bookmark_lastindex(folderId)) < 0) {
+ FAVORITES_LOGE("Database::getLastIndex() is failed.\n");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ /* Creating SQL query sentence. */
+ sprintf(query, "insert into bookmarks\
+ (type, parent, address, title, creationdate, editable, sequence, accesscount)\
+ values(0, %d, '%s', '%s', DATETIME('now'), 1, %d, 0);"
+ , folderId, url, title, lastIndex);
+
+ 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.\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);
+ if (bookmark_id != NULL) {
+ *bookmark_id = _favorites_bookmark_get_bookmark_id(url, title, folderId);
+ }
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int favorites_bookmark_get_count(int *count)
+{
+ 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 */
+ nError = sqlite3_prepare_v2(gl_internet_bookmark_db,
+ "select count(*) from bookmarks where parent != 0",
+ -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _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;
+ }
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
+int favorites_bookmark_foreach(favorites_bookmark_foreach_cb callback,void *user_data)
+{
+ FAVORITES_NULL_ARG_CHECK(callback);
+ 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;
+ }
+ 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);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE ("sqlite3_prepare_v2 is failed.\n");
+ _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);
+ }
+ }
+ 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;
+}
+
+int favorites_bookmark_export_list(const char * file_path)
+{
+ FAVORITES_NULL_ARG_CHECK(file_path);
+ FILE *fp = NULL;
+ bookmark_list_h folders_list = NULL;
+ bookmark_list_h bookmarks_list = NULL;
+
+ /* Get list of all bookmarks */
+ folders_list = _favorites_bookmark_get_folder_list();
+ if(folders_list == NULL ) {
+ FAVORITES_LOGE("There is no folders even root folder");
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ 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);
+ /*Set subfolders and its bookmark items */
+ int i = 0;
+ int folder_adddate_unixtime = 0;
+ int k=0;
+ int bookmark_adddate_unixtime = 0;
+ int bookmark_updatedate_unixtime = 0;
+ for(i=0; i < (folders_list->count); i++) {
+ folder_adddate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ folders_list->item[i].creationdate);
+ FAVORITES_LOGE("TITLE: %s", folders_list->item[i].title);
+
+ fprintf(fp, "\t<DT><H3 FOLDED ADD_DATE=\"%d\">%s</H3>\n",
+ folder_adddate_unixtime, folders_list->item[i].title);
+ fputs("\t<DL><p>\n", fp);
+ /* Get bookmarks under this folder and put the list into the file*/
+ _favorites_free_bookmark_list(bookmarks_list);
+ bookmarks_list = NULL;
+ bookmarks_list = _favorites_get_bookmark_list_at_folder(
+ folders_list->item[i].id);
+ if(bookmarks_list!= NULL){
+ for(k=0;k<(bookmarks_list->count); k++){
+ bookmark_adddate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ bookmarks_list->item[k].creationdate);
+
+ if(bookmark_adddate_unixtime<0)
+ bookmark_adddate_unixtime=0;
+
+ bookmark_updatedate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ bookmarks_list->item[k].updatedate);
+
+ if(bookmark_updatedate_unixtime<0)
+ bookmark_updatedate_unixtime=0;
+
+ fprintf(fp,"\t\t<DT><A HREF=\"%s\" ",
+ bookmarks_list->item[k].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", bookmarks_list->item[k].title );
+ }
+ }
+ fputs("\t</DL><p>\n", fp);
+ }
+
+ /*Set root folder's bookmark items */
+ _favorites_free_bookmark_list(bookmarks_list);
+ bookmarks_list = NULL;
+ bookmarks_list = _favorites_get_bookmark_list_at_folder(1);
+ if(bookmarks_list!= NULL){
+ for(k=0;k<(bookmarks_list->count); k++){
+ bookmark_adddate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ bookmarks_list->item[k].creationdate);
+
+ if(bookmark_adddate_unixtime<0)
+ bookmark_adddate_unixtime=0;
+
+ bookmark_updatedate_unixtime =
+ _favorites_get_unixtime_from_datetime(
+ bookmarks_list->item[k].updatedate);
+
+ if(bookmark_updatedate_unixtime<0)
+ bookmark_updatedate_unixtime=0;
+
+ fprintf(fp,"\t<DT><A HREF=\"%s\" ",
+ bookmarks_list->item[k].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", bookmarks_list->item[k].title );
+ }
+ }
+ fputs("</DL><p>\n", fp);
+ fclose(fp);
+
+ return FAVORITES_ERROR_NONE;
+}
+
+int favorites_bookmark_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 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);
+ }
+ _favorites_finalize_bookmark_db(stmt);
+ return FAVORITES_ERROR_NONE;
+ }
+
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_NONE;
+}
+
+int favorites_bookmark_delete_bookmark(int id)
+{
+ FAVORITES_INVALID_ARG_CHECK(id<0);
+ 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,
+ "delete from bookmarks where id=? and parent != 0", -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 is failed.\n");
+ _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_OK || 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;
+}
+
+int favorites_bookmark_delete_all_bookmarks(void)
+{
+ 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,
+ "delete from bookmarks where parent !=0", -1, &stmt, NULL);
+ if (nError != SQLITE_OK) {
+ FAVORITES_LOGE("sqlite3_prepare_v2 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);
+ return FAVORITES_ERROR_NONE;
+ }
+ FAVORITES_LOGE("sqlite3_step is failed");
+ _favorites_close_bookmark_db();
+ return FAVORITES_ERROR_DB_FAILED;
+}
+
diff --git a/src/favorites_history.c b/src/favorites_history.c new file mode 100644 index 0000000..de6ffa1 --- /dev/null +++ b/src/favorites_history.c @@ -0,0 +1,320 @@ +/*
+ * Copyright (c) 2011 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>
+
+__thread sqlite3 *gl_internet_history_db = 0;
+
+#define INTERNET_HISTORY_DB_NAME "/opt/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.\n");
+ _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.\n");
+ _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.\n");
+ _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_OK || 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.\n");
+ _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_OK || 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.\n");
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || 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.\n");
+ _favorites_history_db_finalize(stmt);
+ return FAVORITES_ERROR_DB_FAILED;
+ }
+
+ nError = sqlite3_step(stmt);
+ if (nError == SQLITE_OK || 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;
+}
+
|