diff options
author | Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org> | 2014-02-10 11:57:09 +0100 |
---|---|---|
committer | Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org> | 2014-03-20 11:47:33 +0100 |
commit | 9646d9e4df0c40dfafe7e3456a2e5f774036af11 (patch) | |
tree | 15b168875f8b79d0b3c5d324184bd7b1d5dad75b | |
parent | b7d3b209e89a68b973cb03f8bf1ea4bc06fff99e (diff) | |
download | favorites-9646d9e4df0c40dfafe7e3456a2e5f774036af11.tar.gz favorites-9646d9e4df0c40dfafe7e3456a2e5f774036af11.tar.bz2 favorites-9646d9e4df0c40dfafe7e3456a2e5f774036af11.zip |
remove hardcoded path for multiuser support
Bug-Tizen: PTREL-262
Change-Id: I39a94d08d75f851eae5bd86958d99b7e259565e5
Signed-off-by: Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>
-rwxr-xr-x | CMakeLists.txt | 4 | ||||
-rw-r--r-- | browser_history_DB_init.sh | 27 | ||||
-rw-r--r-- | include/favorites_private.h | 2 | ||||
-rw-r--r-- | internet_bookmark_DB_init.sh | 45 | ||||
-rw-r--r-- | packaging/capi-web-favorites.spec | 82 | ||||
-rw-r--r-- | src/favorites_bookmark.c | 20 | ||||
-rw-r--r-- | src/favorites_history.c | 54 |
7 files changed, 158 insertions, 76 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b2028dd..2630a4a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(requires "db-util dlog sqlite3 evas capi-base-common") +SET(requires "db-util dlog sqlite3 evas capi-base-common libtzplatform-config") SET(pc_requires "capi-base-common") INCLUDE(FindPkgConfig) @@ -66,6 +66,8 @@ CONFIGURE_FILE( @ONLY ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/internet_bookmark_DB_init.sh DESTINATION ${TZ_SYS_SHARE}/${fw_name}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/browser_history_DB_init.sh DESTINATION ${TZ_SYS_SHARE}/${fw_name}) IF(UNIX) diff --git a/browser_history_DB_init.sh b/browser_history_DB_init.sh new file mode 100644 index 0000000..b39ed42 --- /dev/null +++ b/browser_history_DB_init.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +source /etc/tizen-platform.conf + +sqlite3 $TZ_USER_DB/.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);' + + +# Change db file owner & permission +chown :$TZ_SYS_USER_GROUP $TZ_USER_DB/.browser-history.db +chown :$TZ_SYS_USER_GROUP $TZ_USER_DB/.browser-history.db-journal +chmod 666 $TZ_USER_DB/.browser-history.db +chmod 666 $TZ_USER_DB/.browser-history.db-journal + diff --git a/include/favorites_private.h b/include/favorites_private.h index db298e6..da2ef18 100644 --- a/include/favorites_private.h +++ b/include/favorites_private.h @@ -122,6 +122,8 @@ void _favorites_history_db_finalize(sqlite3_stmt *stmt); int _favorites_history_db_open(void);
int _favorites_free_history_entry(favorites_history_entry_s *entry);
+int _xsystem(const char *argv[]);
+
#ifdef __cplusplus
};
#endif
diff --git a/internet_bookmark_DB_init.sh b/internet_bookmark_DB_init.sh new file mode 100644 index 0000000..d336aed --- /dev/null +++ b/internet_bookmark_DB_init.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +source /etc/tizen-platform.conf + +sqlite3 $TZ_USER_DB/.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 + );' + +chown :$TZ_SYS_USER_GROUP $TZ_USER_DB/.internet_bookmark.db +chown :$TZ_SYS_USER_GROUP $TZ_USER_DB/.internet_bookmark.db-journal +chmod 666 $TZ_USER_DB/.internet_bookmark.db +chmod 666 $TZ_USER_DB/.internet_bookmark.db-journal diff --git a/packaging/capi-web-favorites.spec b/packaging/capi-web-favorites.spec index 9355728..5893e66 100644 --- a/packaging/capi-web-favorites.spec +++ b/packaging/capi-web-favorites.spec @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(evas) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(libtzplatform-config) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -31,7 +32,7 @@ cp %{SOURCE1001} . %build -%cmake . +%cmake . -DTZ_SYS_SHARE=%TZ_SYS_SHARE make %{?jobs:-j%jobs} %install @@ -39,84 +40,17 @@ make %{?jobs:-j%jobs} %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 +source /etc/tizen-platform.conf +users_gid=$(getent group $TZ_SYS_USER_GROUP | cut -f3 -d':') # 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 +vconftool set -t string db/browser/browser_user_agent "System user agent" -g $users_gid -f +vconftool set -t string db/browser/custom_user_agent "" -g $users_gid -f #public keys -vconftool set -t string db/browser/user_agent "Mozilla/5.0 (Linux; Tizen 2.1; sdk) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.1 Mobile Safari/537.3" -g 5000 -f +vconftool set -t string db/browser/user_agent "Mozilla/5.0 (Linux; Tizen 2.1; sdk) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.1 Mobile Safari/537.3" -g $users_gid -f %postun -p /sbin/ldconfig @@ -124,6 +58,8 @@ vconftool set -t string db/browser/user_agent "Mozilla/5.0 (Linux; Tizen 2.1; sd %files %manifest %{name}.manifest %{_libdir}/libcapi-web-favorites.so +%attr(0755,root,%TZ_SYS_USER_GROUP) %TZ_SYS_SHARE/%{name}/internet_bookmark_DB_init.sh +%attr(0755,root,%TZ_SYS_USER_GROUP) %TZ_SYS_SHARE/%{name}/browser_history_DB_init.sh %files devel %manifest %{name}.manifest diff --git a/src/favorites_bookmark.c b/src/favorites_bookmark.c index dea1373..286d02b 100644 --- a/src/favorites_bookmark.c +++ b/src/favorites_bookmark.c @@ -19,11 +19,17 @@ #include <db-util.h>
#include <favorites.h>
#include <favorites_private.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <tzplatform_config.h>
#if defined(BROWSER_BOOKMARK_SYNC)
#include "bookmark-adaptor.h"
#include "time.h"
#endif
+#define INTERNET_BOOKMARK_DB tzplatform_mkpath(TZ_USER_DB,".internet_bookmark.db")
+#define SCRIPT_INIT_INTERNET_BOOKMARK_DB tzplatform_mkpath(TZ_SYS_SHARE, "capi-web-favorites/internet_bookmark_DB_init.sh")
+
sqlite3 *gl_internet_bookmark_db = 0;
/* Private Functions */
@@ -47,7 +53,19 @@ void _favorites_finalize_bookmark_db(sqlite3_stmt *stmt) }
const char *_favorites_get_bookmark_db_name(void)
{
- return "/opt/usr/dbspace/.internet_bookmark.db";
+
+ // init of db
+ struct stat sts;
+ int ret;
+
+ /* Check if the DB exists; if not, create it and initialize it */
+ ret = stat(INTERNET_BOOKMARK_DB, &sts);
+ if (ret == -1 && errno == ENOENT){
+ const char *argv_script[] = {"/bin/sh", SCRIPT_INIT_INTERNET_BOOKMARK_DB, NULL };
+ ret = _xsystem(argv_script);
+ }
+
+ return INTERNET_BOOKMARK_DB;
}
int _favorites_open_bookmark_db(void)
{
diff --git a/src/favorites_history.c b/src/favorites_history.c index d72d28d..115b29c 100644 --- a/src/favorites_history.c +++ b/src/favorites_history.c @@ -17,12 +17,18 @@ #include <string.h>
#include <dlog.h>
#include <db-util.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/wait.h>
#include <favorites.h>
#include <favorites_private.h>
+#include <tzplatform_config.h>
+
sqlite3 *gl_internet_history_db = 0;
-#define INTERNET_HISTORY_DB_NAME "/opt/usr/dbspace/.browser-history.db"
+#define INTERNET_HISTORY_DB_NAME tzplatform_mkpath(TZ_USER_DB,".browser-history.db")
+#define SCRIPT_INIT_INTERNET_HISTORY_DB tzplatform_mkpath(TZ_SYS_SHARE, "capi-web-favorites/browser_history_DB_init.sh")
/* Private Functions */
void _favorites_history_db_close(void)
@@ -41,8 +47,54 @@ void _favorites_history_db_finalize(sqlite3_stmt *stmt) }
_favorites_history_db_close();
}
+
+int _xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
int _favorites_history_db_open(void)
{
+
+ // init of db
+ struct stat sts;
+ int ret;
+
+ /* Check if the DB exists; if not, create it and initialize it */
+ ret = stat(INTERNET_HISTORY_DB_NAME, &sts);
+ if (ret == -1 && errno == ENOENT){
+ const char *argv_script[] = {"/bin/sh", SCRIPT_INIT_INTERNET_HISTORY_DB, NULL };
+ ret = _xsystem(argv_script);
+ }
+
_favorites_history_db_close();
if (db_util_open
(INTERNET_HISTORY_DB_NAME, &gl_internet_history_db,
|