From: vivek Date: Tue, 18 Feb 2014 12:39:31 +0000 (+0530) Subject: Add multi-user support. X-Git-Tag: accepted/tizen/common/20150414.124958^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_3.0.m14.2_ivi;p=platform%2Fcore%2Fpim%2Flibaccounts-svc.git Add multi-user support. Bug-Tizen:PTREL-231 Change-Id: I62e71c9f3f789ad9afa47ede47d7e7ba4f0b75bf Signed-off-by: vivek --- diff --git a/CMakeLists.txt b/CMakeLists.txt index da57f6e..717f820 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ src/account-xml-verify.c INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED sqlite3 dlog db-util glib-2.0 capi-base-common vconf capi-appfw-application libxml-2.0 pkgmgr-info aul) +pkg_check_modules(pkgs REQUIRED sqlite3 dlog db-util glib-2.0 capi-base-common vconf capi-appfw-application libxml-2.0 pkgmgr-info aul libtzplatform-config) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/TC/testcase/utc_account.c b/TC/testcase/utc_account.c index beeb8a5..b444216 100755 --- a/TC/testcase/utc_account.c +++ b/TC/testcase/utc_account.c @@ -18,6 +18,7 @@ #include #include #include +#include #define TEST_PACKAGE_NAME "com.samsung.facebook" @@ -257,11 +258,15 @@ static void utc_account_connect_positive(void) static void utc_account_connect_negative(void) { const char *API_NAME = __FUNCTION__; + const char *ACCT_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account.db"); + const char *ACCT_TEMP_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account-tmp.db"); + const char *ACCT_JR_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account.db-journal"); + const char *ACCT_TEMP_JR_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account-tmp.db-journal"); int ret = ACCOUNT_ERROR_NONE; - ret = rename("/opt/dbspace/.account.db", "/opt/dbspace/.account-tmp.db"); + ret = rename(ACCT_PATH, ACCT_TEMP_PATH); - ret = rename("/opt/dbspace/.account.db-journal", "/opt/dbspace/.account-tmp.db-journal"); + ret = rename(ACCT_JR_PATH, ACCT_TEMP_JR_PATH); ret = account_connect(); @@ -271,8 +276,9 @@ static void utc_account_connect_negative(void) dts_fail(API_NAME, "failed"); } - ret = rename("/opt/dbspace/.account-tmp.db", "/opt/dbspace/.account.db"); - ret = rename("/opt/dbspace/.account-tmp.db-journal", "/opt/dbspace/.account.db-journal"); + ret = rename(ACCT_TEMP_PATH, ACCT_PATH); + + ret = rename(ACCT_TEMP_JR_PATH, ACCT_JR_PATH); ret = account_disconnect(); if ( ret != ACCOUNT_ERROR_NONE) { @@ -303,11 +309,16 @@ static void utc_account_destroy_positive(void) static void utc_account_destroy_negative(void) { const char *API_NAME = __FUNCTION__; + const char *ACCT_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account.db"); + const char *ACCT_TEMP_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account-tmp.db"); + const char *ACCT_JR_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account.db-journal"); + const char *ACCT_TEMP_JR_PATH = tzplatform_mkpath(TZ_SYS_DB, ".account-tmp.db-journal"); int ret = ACCOUNT_ERROR_NONE; - ret = rename("/opt/dbspace/.account.db", "/opt/dbspace/.account-tmp.db"); - ret = rename("/opt/dbspace/.account.db-journal", "/opt/dbspace/.account-tmp.db-journal"); + ret = rename(ACCT_PATH, ACCT_TEMP_PATH); + + ret = rename(ACCT_JR_PATH, ACCT_TEMP_JR_PATH); ret = account_disconnect(); @@ -317,8 +328,9 @@ static void utc_account_destroy_negative(void) dts_fail(API_NAME, "failed"); } - ret = rename("/opt/dbspace/.account-tmp.db", "/opt/dbspace/.account.db"); - ret = rename("/opt/dbspace/.account-tmp.db-journal", "/opt/dbspace/.account.db-journal"); + ret = rename(ACCT_TEMP_PATH, ACCT_PATH); + + ret = rename(ACCT_TEMP_JR_PATH, ACCT_JR_PATH); } static void utc_account_create_positive(void) diff --git a/include/account-private.h b/include/account-private.h index 2005d15..f9397f0 100755 --- a/include/account-private.h +++ b/include/account-private.h @@ -31,6 +31,7 @@ extern "C" #include #include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -96,7 +97,7 @@ NULL after passing them to free: free(NULL) is safe (it does nothing). ptr = NULL; \ } \ -#define ACCOUNT_DB_NAME "/opt/dbspace/.account.db" +#define ACCOUNT_DB_NAME tzplatform_mkpath(TZ_SYS_DB, ".account.db") #define ACCOUNT_TABLE "account" #define CAPABILITY_TABLE "capability" #define ACCOUNT_CUSTOM_TABLE "account_custom" diff --git a/packaging/accounts_DB.sh b/packaging/accounts_DB.sh new file mode 100755 index 0000000..914dcec --- /dev/null +++ b/packaging/accounts_DB.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +source /etc/tizen-platform.conf + +sqlite3 ${TZ_SYS_DB}/.account.db 'PRAGMA journal_mode = PERSIST; + CREATE TABLE if not exists label (AppId TEXT, Label TEXT, Locale TEXT); + CREATE TABLE if not exists account_type (_id INTEGER PRIMARY KEY AUTOINCREMENT, AppId TEXT, + ServiceProviderId TEXT, IconPath TEXT, SmallIconPath TEXT, MultipleAccountSupport INT); + CREATE TABLE if not exists account_custom (AccountId INTEGER, AppId TEXT, Key TEXT, Value TEXT); + CREATE TABLE if not exists account (_id INTEGER PRIMARY KEY AUTOINCREMENT, user_name TEXT, email_address TEXT, display_name TEXT, icon_path TEXT, + source TEXT, package_name TEXT, access_token TEXT, domain_name TEXT, auth_type INTEGER, secret INTEGER, sync_support INTEGER, + txt_custom0 TEXT, txt_custom1 TEXT, txt_custom2 TEXT, txt_custom3 TEXT, txt_custom4 TEXT, + int_custom0 INTEGER, int_custom1 INTEGER, int_custom2 INTEGER, int_custom3 INTEGER, int_custom4 INTEGER); + CREATE TABLE if not exists capability (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT, value INTEGER, + package_name TEXT, user_name TEXT, account_id INTEGER, FOREIGN KEY (account_id) REFERENCES account(_id)); + CREATE TABLE if not exists provider_feature (app_id TEXT, key TEXT);' + +chgrp ${TZ_SYS_USER_GROUP} ${TZ_SYS_DB}/.account.db +chgrp ${TZ_SYS_USER_GROUP} ${TZ_SYS_DB}/.account.db-journal + +chmod 660 ${TZ_SYS_DB}/.account.db +chmod 660 ${TZ_SYS_DB}/.account.db-journal diff --git a/packaging/libaccounts-svc.spec b/packaging/libaccounts-svc.spec index 8d78dc2..080941a 100755 --- a/packaging/libaccounts-svc.spec +++ b/packaging/libaccounts-svc.spec @@ -3,10 +3,11 @@ Name: libaccounts-svc Summary: Account DB library Version: 0.2.52 Release: 1 -Group: TO_BE/FILLED_IN +Group: Social & Content/Utilities License: Apache-2.0 Source0: libaccounts-svc-%{version}.tar.gz Source1001: libaccounts-svc.manifest +Source1002: accounts_DB.sh BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) @@ -18,6 +19,8 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(libtzplatform-config) +Requires: libtzplatform-config Requires(post): /sbin/ldconfig Requires(post): /usr/bin/sqlite3 Requires(postun): /sbin/ldconfig @@ -27,14 +30,13 @@ Account DB libraryXB-Public-Package: no %package devel Summary: Development files for %{name} -Group: Development/Libraries Requires: %{name} = %{version}-%{release} %description devel Development files for %{name} %prep %setup -q -cp %{SOURCE1001} . +cp %{SOURCE1001} %{SOURCE1002} . %build export CFLAGS="${CFLAGS} -fPIC -fvisibility=hidden" @@ -46,39 +48,15 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install +install -D -m 0750 %{SOURCE1002} %{buildroot}%{_datadir}/%{name}/accounts_DB.sh + rm -rf %{buildroot}%{_libdir}/accounts-svc %post + /sbin/ldconfig -if [ ! -d /opt/dbspace ] -then - mkdir -p /opt/dbspace -fi -if [ ! -f /opt/dbspace/.account.db ] -#rm -rf /opt/dbspace/.account.db* -then - sqlite3 /opt/dbspace/.account.db 'PRAGMA journal_mode = PERSIST; - CREATE TABLE if not exists label (AppId TEXT, Label TEXT, Locale TEXT); - CREATE TABLE if not exists account_type (_id INTEGER PRIMARY KEY AUTOINCREMENT, AppId TEXT, - ServiceProviderId TEXT, IconPath TEXT, SmallIconPath TEXT, MultipleAccountSupport INT); - CREATE TABLE if not exists account_custom (AccountId INTEGER, AppId TEXT, Key TEXT, Value TEXT); - CREATE TABLE if not exists account (_id INTEGER PRIMARY KEY AUTOINCREMENT, user_name TEXT, email_address TEXT, display_name TEXT, icon_path TEXT, - source TEXT, package_name TEXT, access_token TEXT, domain_name TEXT, auth_type INTEGER, secret INTEGER, sync_support INTEGER, - txt_custom0 TEXT, txt_custom1 TEXT, txt_custom2 TEXT, txt_custom3 TEXT, txt_custom4 TEXT, - int_custom0 INTEGER, int_custom1 INTEGER, int_custom2 INTEGER, int_custom3 INTEGER, int_custom4 INTEGER); - CREATE TABLE if not exists capability (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT, value INTEGER, - package_name TEXT, user_name TEXT, account_id INTEGER, FOREIGN KEY (account_id) REFERENCES account(_id)); - CREATE TABLE if not exists provider_feature (app_id TEXT, key TEXT);' -fi - -mkdir -p /opt/usr/share/account -chown 5000:5000 /opt/dbspace/.account.db -chown 5000:5000 /opt/dbspace/.account.db-journal -chown 5000:5000 /opt/usr/share/account - -chmod 660 /opt/dbspace/.account.db -chmod 660 /opt/dbspace/.account.db-journal -chmod 755 /opt/usr/share/account +%{_datadir}/%{name}/accounts_DB.sh + #set message key value to NULL vconftool set -t string db/account/msg '' -g 6514 @@ -91,6 +69,7 @@ vconftool set -t string db/account/msg '' -g 6514 %defattr(-,root,root,-) %{_libdir}/*.so.* %{_bindir}/account-xml-verify +%{_datadir}/%{name}/accounts_DB.sh %files devel %manifest %{name}.manifest @@ -98,4 +77,5 @@ vconftool set -t string db/account/msg '' -g 6514 %{_libdir}/*.so %{_libdir}/pkgconfig/accounts-svc.pc %{_includedir}/*.h +%{_datadir}/%{name}/accounts_DB.sh %{_bindir}/account-xml-verify diff --git a/src/account-capability-parser.c b/src/account-capability-parser.c index 97d44c3..b528135 100755 --- a/src/account-capability-parser.c +++ b/src/account-capability-parser.c @@ -28,13 +28,14 @@ #include #include #include +#include #ifndef ACCOUNT_API #define ACCOUNT_API __attribute__ ((visibility("default"))) #endif -#define ACCOUNT_XML_DIR "/usr/share/account" -#define ACCOUNT_XML_OPT_DIR "/opt/usr/share/account" +#define ACCOUNT_XML_DIR tzplatform_mkpath(TZ_SYS_SHARE, "account") +#define ACCOUNT_XML_OPT_DIR tzplatform_mkpath(TZ_USER_SHARE, "account") #define BUFSIZE 1024 static void _account_parse_doc(xmlDocPtr doc, xmlNodePtr cur, diff --git a/src/account.c b/src/account.c index 731c197..e572028 100755 --- a/src/account.c +++ b/src/account.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -35,9 +37,10 @@ #include #include #include +#include -#define EAS_CMDLINE "/usr/bin/eas-engine" -#define EMAIL_SERVICE_CMDLINE "/usr/bin/email-service" +#define EAS_CMDLINE tzplatform_mkpath(TZ_SYS_BIN, "eas-engine") +#define EMAIL_SERVICE_CMDLINE tzplatform_mkpath(TZ_SYS_BIN, "email-service") #define ACTIVESYNC_APPID "activesync-ui" static sqlite3* g_hAccountDB = NULL; @@ -496,6 +499,12 @@ static int _account_db_close(void) static int _account_connect(void) { int error_code = ACCOUNT_ERROR_NONE; + const char *ACCT_DIR_PATH = tzplatform_mkpath(TZ_USER_SHARE, "account"); + pid_t pid; + + error_code = mkdir(ACCT_DIR_PATH, 755); + pid = tzplatform_getgid(TZ_SYS_USER_GROUP); + error_code = chown(ACCT_DIR_PATH, -1, pid); pthread_mutex_lock(&account_mutex);