summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>2014-08-26 14:28:49 (GMT)
committerJean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>2014-09-30 12:09:14 (GMT)
commit561e2cae46730cdbadf485dfa7ab449e60524bae (patch)
tree5d2127e248aac6750950cbd2352976729baa4bc7 /src/util
parent1b8cf739c37f1103b7fa613b788f0d5e32f5bad9 (diff)
downloadlibmedia-thumbnail-561e2cae46730cdbadf485dfa7ab449e60524bae.zip
libmedia-thumbnail-561e2cae46730cdbadf485dfa7ab449e60524bae.tar.gz
libmedia-thumbnail-561e2cae46730cdbadf485dfa7ab449e60524bae.tar.bz2
Use User UID to write or read into database Use Unix socket Fix-Tizen: TC-1482 Change-Id: I557a28de1650c9af1a30ef7d795d64464eaa2e8f Signed-off-by: Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>
Diffstat (limited to 'src/util')
-rwxr-xr-xsrc/util/media-thumb-db.c26
-rwxr-xr-xsrc/util/media-thumb-util.c113
2 files changed, 121 insertions, 18 deletions
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index e3ca193..1ee9aa5 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -241,7 +241,8 @@ _media_thumb_get_thumb_path_from_db(sqlite3 *handle,
int
_media_thumb_update_thumb_path_to_db(sqlite3 *handle,
const char *origin_path,
- char *thumb_path)
+ char *thumb_path,
+ uid_t uid)
{
thumb_dbg("");
int err = -1;
@@ -281,7 +282,7 @@ _media_thumb_update_thumb_path_to_db(sqlite3 *handle,
if (err_msg)
sqlite3_free(err_msg);
#else
- err = media_db_request_update_db(query_string);
+ err = media_db_request_update_db(query_string, uid);
if (err < 0) {
thumb_err("media_db_request_update_db failed : %d", err);
return err;
@@ -296,7 +297,8 @@ int
_media_thumb_update_wh_to_db(sqlite3 *handle,
const char *origin_path,
int width,
- int height)
+ int height,
+ uid_t uid)
{
thumb_dbg("");
int err = -1;
@@ -333,7 +335,7 @@ _media_thumb_update_wh_to_db(sqlite3 *handle,
if (err_msg)
sqlite3_free(err_msg);
#else
- err = media_db_request_update_db(query_string);
+ err = media_db_request_update_db(query_string, uid);
if (err < 0) {
thumb_err("media_db_request_update_db failed : %d", err);
return err;
@@ -349,7 +351,8 @@ _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
const char *origin_path,
char *thumb_path,
int width,
- int height)
+ int height,
+ uid_t uid)
{
thumb_dbg("");
int err = -1;
@@ -364,7 +367,7 @@ _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
path_string = sqlite3_mprintf("%s", origin_path);
query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string);
- err = media_db_request_update_db(query_string);
+ err = media_db_request_update_db(query_string, uid);
if (err < 0) {
thumb_err("media_db_request_update_db failed : %d", err);
return err;
@@ -376,7 +379,7 @@ _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
}
int
-_media_thumb_db_connect()
+_media_thumb_db_connect(uid_t uid)
{
int err = -1;
/*
@@ -395,7 +398,7 @@ _media_thumb_db_connect()
return err;
}
#else
- err = media_db_connect(&db_handle);
+ err = media_db_connect(&db_handle,uid);
if (err < 0) {
thumb_err("media_db_connect failed: %d", err);
db_handle = NULL;
@@ -528,7 +531,8 @@ int
_media_thumb_update_db(const char *origin_path,
char *thumb_path,
int width,
- int height)
+ int height,
+ uid_t uid)
{
thumb_dbg("");
int err = -1;
@@ -588,13 +592,13 @@ _media_thumb_update_db(const char *origin_path,
}
#else
if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
- err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height);
+ err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height,uid);
if (err < 0) {
thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
return MEDIA_THUMB_ERROR_DB;
}
} else {
- err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
+ err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path, uid);
if (err < 0) {
thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
return MEDIA_THUMB_ERROR_DB;
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
index 0db4133..3f287bd 100755
--- a/src/util/media-thumb-util.c
+++ b/src/util/media-thumb-util.c
@@ -29,6 +29,10 @@
#include <Evas.h>
#include <Ecore_Evas.h>
+#include <grp.h>
+#include <pwd.h>
+
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
int _media_thumb_get_width(media_thumb_type thumb_type)
{
@@ -195,9 +199,103 @@ int _media_thumb_remove_file(const char *path)
}
}
+static int _mkdir(const char *dir, mode_t mode) {
+ char tmp[256];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp),"%s",dir);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ tmp[len - 1] = 0;
+ for(p = tmp + 1; *p; p++)
+ if(*p == '/') {
+ *p = 0;
+ mkdir(tmp, mode);
+ *p = '/';
+ }
+ return mkdir(tmp, mode);
+}
+
+static char* _media_thumb_mmc_get_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(THUMB_MMC_PATH);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ thumb_err("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ thumb_err("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
+ }
+
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
+static char* _media_thumb_phone_get_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(THUMB_PHONE_PATH);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ thumb_err("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ thumb_err("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
+ }
+
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
int
_media_thumb_get_hash_name(const char *file_full_path,
- char *thumb_hash_path, size_t max_thumb_path)
+ char *thumb_hash_path, size_t max_thumb_path, uid_t uid)
{
char *hash_name;
char *thumb_dir = NULL;
@@ -215,11 +313,11 @@ _media_thumb_get_hash_name(const char *file_full_path,
store_type = _media_thumb_get_store_type_by_path(file_full_path);
if (store_type == THUMB_PHONE) {
- thumb_dir = THUMB_PHONE_PATH;
+ thumb_dir = _media_thumb_phone_get_path(uid);
} else if (store_type == THUMB_MMC) {
- thumb_dir = THUMB_MMC_PATH;
+ thumb_dir = _media_thumb_mmc_get_path(uid);
} else {
- thumb_dir = THUMB_PHONE_PATH;
+ thumb_dir = _media_thumb_phone_get_path(uid);
}
hash_name = _media_thumb_generate_hash_name(file_full_path);
@@ -303,7 +401,8 @@ int _thumbnail_get_data(const char *origin_path,
int *height,
int *origin_width,
int *origin_height,
- int *alpha)
+ int *alpha,
+ uid_t uid)
{
int err = -1;
int thumb_width = -1;
@@ -345,14 +444,14 @@ int _thumbnail_get_data(const char *origin_path,
file_type = _media_thumb_get_file_type(origin_path);
if (file_type == THUMB_IMAGE_TYPE) {
- err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info);
+ err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info, uid);
if (err < 0) {
thumb_err("_media_thumb_image failed");
return err;
}
} else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
+ err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info,uid);
if (err < 0) {
thumb_err("_media_thumb_image failed");
return err;