#ADD_DEFINITIONS("-D_PERFORMANCE_CHECK_")
ADD_DEFINITIONS("-D_USE_NEW_MEDIA_DB_")
ADD_DEFINITIONS("-D_USE_MEDIA_UTIL_")
-ADD_DEFINITIONS("-D_USE_UDS_SOCKET_TCP_")
+ADD_DEFINITIONS("-D_USE_UDS_SOCKET_")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both")
CONFIGURE_FILE(media-thumbnail.pc.in media-thumbnail.pc @ONLY)
#ifndef _MEDIA_THUMBNAIL_H_
#define _MEDIA_THUMBNAIL_H_
+#include <sys/types.h>
+
#include "media-thumb-types.h"
#include "media-thumb-error.h"
* @endcode
*/
-int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length);
+int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid);
/**
* thumbnail_request_from_db_async:
* @endcode
*/
-int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data);
+int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data, uid_t uid);
/**
* thumbnail_request_save_to_file:
*/
int thumbnail_request_save_to_file(const char *origin_path,
media_thumb_type thumb_type,
- const char *thumb_path);
+ const char *thumb_path, uid_t uid);
/**
* @endcode
*/
-int thumbnail_request_extract_all_thumbs(void);
+int thumbnail_request_extract_all_thumbs(uid_t uid);
-int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height);
+int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid);
/* Cancel APIs that a request to extract thumbnail */
-int thumbnail_request_cancel_media(const char *origin_path);
+int thumbnail_request_cancel_media(const char *origin_path, uid_t uid);
/* Cancel APIs that all requests to extract thumbnail of a process */
int thumbnail_request_cancel_all();
Name: libmedia-thumbnail
-Version: 0.1.77
+Version: 0.1.78
Release: 1
License: Apache-2.0
Summary: Media thumbnail service Library
#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
static __thread char **arr_path;
+static __thread uid_t *arr_uid;
static __thread int g_idx = 0;
static __thread int g_cur_idx = 0;
gboolean _thumb_daemon_start_jobs(gpointer data)
{
thumb_dbg("");
- /* Initialize ecore-evas to use evas library */
- ecore_evas_init();
#ifdef _USE_MEDIA_UTIL_
_thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY);
return;
}
-int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
+int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
{
int err = -1;
- err = _media_thumb_process(req_msg, res_msg);
+ err = _media_thumb_process(req_msg, res_msg, uid);
if (err < 0) {
if (req_msg->msg_type == THUMB_REQUEST_SAVE_FILE) {
thumb_err("_media_thumb_process is failed: %d", err);
return err;
}
-int _thumb_daemon_all_extract()
+int _thumb_daemon_all_extract(uid_t uid)
{
int err = -1;
int count = 0;
sqlite3 *sqlite_db_handle = NULL;
sqlite3_stmt *sqlite_stmt = NULL;
- err = _media_thumb_db_connect();
+ err = _media_thumb_db_connect(uid);
if (err < 0) {
thumb_err("_media_thumb_db_connect failed: %d", err);
return MEDIA_THUMB_ERROR_DB;
if (g_idx == 0) {
arr_path = (char**)malloc(sizeof(char*));
+ arr_uid = (uid_t*)malloc(sizeof(uid_t));
} else {
arr_path = (char**)realloc(arr_path, (g_idx + 1) * sizeof(char*));
+ arr_uid = (uid_t*)realloc(arr_uid, (g_idx + 1) * sizeof(uid_t));
}
-
+ arr_uid[g_idx] = uid;
arr_path[g_idx++] = strdup(path);
}
{
int err = -1;
char *path = NULL;
+ uid_t uid = NULL;
if (g_cur_idx < g_idx) {
thumb_dbg("There are %d jobs in the queue", g_idx - g_cur_idx);
thumb_dbg("Current idx : [%d]", g_cur_idx);
+ uid = arr_uid[g_cur_idx];
path = arr_path[g_cur_idx++];
thumbMsg recv_msg, res_msg;
strncpy(recv_msg.org_path, path, sizeof(recv_msg.org_path));
recv_msg.org_path[sizeof(recv_msg.org_path) - 1] = '\0';
- _thumb_daemon_process_job(&recv_msg, &res_msg);
+ _thumb_daemon_process_job(&recv_msg, &res_msg,uid );
if (res_msg.status == THUMB_SUCCESS) {
- err = _media_thumb_db_connect();
+ err = _media_thumb_db_connect(uid);
if (err < 0) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
return TRUE;
err = _media_thumb_update_db(recv_msg.org_path,
res_msg.dst_path,
res_msg.origin_width,
- res_msg.origin_height);
+ res_msg.origin_height,
+ uid);
if (err < 0) {
thumb_err("_media_thumb_update_db failed : %d", err);
}
g_idx = 0;
thumb_warn("Deleting array");
SAFE_FREE(arr_path);
+ SAFE_FREE(arr_uid);
//_media_thumb_db_disconnect();
_thumb_server_send_msg_to_agent(MS_MSG_THUMB_EXTRACT_ALL_DONE); // MS_MSG_THUMB_EXTRACT_ALL_DONE
if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) {
thumb_dbg("All thumbnails are being extracted now");
- _thumb_daemon_all_extract();
+ _thumb_daemon_all_extract(recv_msg.uid);
g_idle_add(_thumb_daemon_process_queue_jobs, NULL);
} else if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
thumb_warn("received KILL msg from thumbnail agent.");
} else {
long start = thumb_get_debug_time();
- _thumb_daemon_process_job(&recv_msg, &res_msg);
+ _thumb_daemon_process_job(&recv_msg, &res_msg,recv_msg.uid);
long end = thumb_get_debug_time();
thumb_dbg("Time : %f (%s)", ((double)(end - start) / (double)CLOCKS_PER_SEC), recv_msg.org_path);
if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
thumb_warn("Shutting down...");
- g_main_loop_quit(g_thumb_server_mainloop);
+ ecore_main_loop_quit();
}
return TRUE;
memset(&serv_addr, 0, sizeof(serv_addr));
#ifdef _USE_UDS_SOCKET_
serv_addr.sun_family = AF_UNIX;
- strcpy(serv_addr.sun_path, "/tmp/media_ipc_thumbcomm.dat");
+ strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcomm.socket");
#else
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
thumb_dbg("Singal Hander for HEYNOTI \"power_off_start\"");
if (g_thumb_server_mainloop)
- g_main_loop_quit(g_thumb_server_mainloop);
- else
+ ecore_main_loop_quit();
+ else
exit(1);
return;
}
-
-void* gmainloop_thread(void *data)
+int main()
{
- GSource *source = NULL;
- GIOChannel *channel = (GIOChannel *)data;
- GMainContext *context = NULL;
-
- g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
- context = g_main_loop_get_context(g_thumb_server_mainloop);
-
- source = g_io_create_watch(channel, G_IO_IN);
+
+ int sockfd = -1;
- /* Set callback to be called when socket is readable */
- g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
- g_source_attach(source, context);
-
- g_main_loop_run(g_thumb_server_mainloop);
-
- pthread_exit(NULL);
-}
+ GSource *source = NULL;
+ GIOChannel *channel = NULL;
+ GMainContext *context = NULL;
-int main()
-{
/*heynoti for power off*/
int err = 0;
int heynoti_id = heynoti_init();
- int sockfd = -1;
-
if (heynoti_id < 0) {
thumb_err("heynoti_init failed");
} else {
}
}
- /* Create and bind new UDP socket */
- if (!_thumb_server_prepare_socket(&sockfd)) {
- thumb_err("Failed to create socket\n");
- return -1;
- }
-
/* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
if (err == -1)
if (err == -1)
thumb_err("vconf_notify_key_changed : %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
+ /* Create and bind new UDP socket */
+ if (!_thumb_server_prepare_socket(&sockfd)) {
+ thumb_err("Failed to create socket\n");
+ return -1;
+ }
+
+ context = g_main_context_default ();
+
+ /* Create new channel to watch udp socket */
+ channel = g_io_channel_unix_new(sockfd);
+ source = g_io_create_watch(channel, G_IO_IN);
+
+ /* Set callback to be called when socket is readable */
+ g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
+ g_source_attach(source, context);
+
+ GSource *source_evas_init = NULL;
+ source_evas_init = g_idle_source_new ();
+ g_source_set_callback (source_evas_init, _thumb_daemon_start_jobs, NULL, NULL);
+ g_source_attach (source_evas_init, context);
+
/* Would be used when glib 2.32 is installed
GSource *sig_handler_src = NULL;
sig_handler_src = g_unix_signal_source_new (SIGTERM);
*/
ecore_evas_init();
- GIOChannel *channel = NULL;
- /* Create new channel to watch udp socket */
- channel = g_io_channel_unix_new(sockfd);
-
- static pthread_t thread;
- pthread_create(&thread, NULL, gmainloop_thread, channel);
-
thumb_dbg("************************************");
thumb_dbg("*** Thumbnail server is running ***");
thumb_dbg("************************************");
g_io_channel_shutdown(channel, FALSE, NULL);
g_io_channel_unref(channel);
_thumb_daemon_finish_jobs();
- g_main_loop_unref(g_thumb_server_mainloop);
return 0;
}
#include <unistd.h>
#include <errno.h>
#include <signal.h>
+#include <sys/types.h>
#ifndef _MEDIA_THUMB_IPC_H_
#define _MEDIA_THUMB_IPC_H_
media_thumb_type thumb_type;
int status;
int pid;
+ uid_t uid;
int thumb_size;
int thumb_width;
int thumb_height;
const char *origin_path,
char *thumb_path,
int max_length,
- media_thumb_info *thumb_info);
+ media_thumb_info *thumb_info,
+ uid_t uid);
int
_media_thumb_request_async(int msg_type,
media_thumb_type thumb_type,
const char *origin_path,
- thumbUserData *userData);
+ thumbUserData *userData,
+ uid_t uid);
int
-_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg);
+_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid);
#endif /*_MEDIA_THUMB_IPC_H_*/
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info);
+ media_thumb_info *thumb_info,
+ uid_t uid);
int
_media_thumb_video(const char *origin_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info);
+ media_thumb_info *thumb_info,
+ uid_t uid);
#endif /*_MEDIA_THUMB_INTERNAL_H_*/
sqlite3 *_media_thumb_db_get_handle();
int
-_media_thumb_db_connect();
+_media_thumb_db_connect(uid_t uid);
int
_media_thumb_db_disconnect();
_media_thumb_update_db(const char *origin_path,
char *thumb_path,
int width,
- int height);
+ int height,
+ uid_t uid);
#endif /*_MEDIA_THUMB_DB_H_*/
#define THUMB_PATH_PHONE MEDIA_ROOT_PATH_INTERNAL /**< File path prefix of files stored in phone */
#define THUMB_PATH_MMC MEDIA_ROOT_PATH_SDCARD /**< File path prefix of files stored in mmc card */
-#define THUMB_PHONE_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/phone")
-#define THUMB_MMC_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/mmc")
+#define THUMB_PHONE_PATH tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/.thumb/phone")
+#define THUMB_MMC_PATH tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/.thumb/mmc")
-#define THUMB_DEFAULT_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/thumb_default.png")
+#define THUMB_DEFAULT_PATH tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/.thumb/thumb_default.png")
typedef enum
{
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);
int
_media_thumb_save_to_file_with_evas(unsigned char *data,
int *height,
int *origin_width,
int *origin_height,
- int *alpha);
+ int *alpha,
+ uid_t uid);
#endif /*_MEDIA_THUMB_UTIL_H_*/
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include <grp.h>
+#include <pwd.h>
+
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
static __thread GQueue *g_request_queue = NULL;
typedef struct {
}
int
-_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info)
+_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid)
{
int sock;
#ifdef _USE_UDS_SOCKET_
#ifdef _USE_MEDIA_UTIL_
#ifdef _USE_UDS_SOCKET_
- strcpy(serv_addr.sun_path, "/tmp/media_ipc_thumbcreator.dat");
+ strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
#elif defined(_USE_UDS_SOCKET_TCP_)
thumb_dbg("");
- strcpy(serv_addr.sun_path, "/tmp/media_ipc_thumbcreator.dat");
+ strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
#else
serv_addr.sin_port = htons(MS_THUMB_CREATOR_PORT);
#endif
/* Set requset message */
req_msg.msg_type = msg_type;
req_msg.thumb_type = thumb_type;
+ req_msg.uid = uid;
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
return 0;
}
+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_get_default_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(THUMB_DEFAULT_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);
+ }
+
+ /* create dir */
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
int
-_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
+_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
{
int err = -1;
unsigned char *data = NULL;
thumb_path[0] = '\0';
max_length = sizeof(res_msg->dst_path);
- err = _media_thumb_db_connect();
+ err = _media_thumb_db_connect(uid);
if (err < 0) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
return MEDIA_THUMB_ERROR_DB;
return MEDIA_THUMB_ERROR_NONE;
} else {
if (strlen(thumb_path) == 0) {
- err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid);
if (err < 0) {
thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
- strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length);
_media_thumb_db_disconnect();
return err;
}
strncpy(thumb_path, req_msg->dst_path, max_length);
} else if (msg_type == THUMB_REQUEST_ALL_MEDIA) {
- err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length);
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid);
if (err < 0) {
thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
- strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length);
_media_thumb_db_disconnect();
return err;
}
thumb_path[strlen(thumb_path)] = '\0';
}
- thumb_dbg("Thumb path : %s", thumb_path);
-
if (g_file_test(thumb_path,
G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
thumb_warn("thumb path already exists in file system.. remove the existed file");
_media_thumb_remove_file(thumb_path);
}
- err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha);
+ err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
if (err < 0) {
thumb_err("_thumbnail_get_data failed - %d\n", err);
SAFE_FREE(data);
- strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length);
_media_thumb_db_disconnect();
return err;
}
SAFE_FREE(data);
if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA)
- strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length);
+ strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length);
_media_thumb_db_disconnect();
return err;
/* DB update if needed */
if (need_update_db == 1) {
- err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height);
+ err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height, uid);
if (err < 0) {
thumb_err("_media_thumb_update_db failed : %d", err);
}
}
int
-_media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData)
+_media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData, uid_t uid)
{
int sock;
#ifdef _USE_UDS_SOCKET_
req_msg.pid = pid;
req_msg.msg_type = msg_type;
req_msg.thumb_type = thumb_type;
+ req_msg.uid = uid;
+
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
int orientation,
int required_width,
int required_height,
- media_thumb_info *thumb_info)
+ media_thumb_info *thumb_info, uid_t uid)
{
ExifEntry *entry;
ExifIfd ifd;
err =
_media_thumb_get_hash_name(file_full_path,
thumb_path,
- sizeof(thumb_path));
+ sizeof(thumb_path), uid);
if (err < 0) {
thumb_dbg("_media_thumb_get_hash_name failed\n");
SAFE_FREE(thumb);
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info)
+ media_thumb_info *thumb_info,
+ uid_t uid)
{
int err = -1;
ExifData *ed = NULL;
}
/* Second, Get thumb from exif */
- err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info);
+ err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info, uid);
if (err < 0) {
thumb_dbg("_media_thumb_get_thumb_from_exif failed");
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info)
+ media_thumb_info *thumb_info, uid_t uid)
{
int err = -1;
int image_type = 0;
if (image_type == IMG_CODEC_AGIF) {
err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info);
} else if (image_type == IMG_CODEC_JPEG) {
- err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info);
+ err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info, uid);
} else if (image_type == IMG_CODEC_PNG) {
err = _media_thumb_png(origin_path, thumb_width, thumb_height, format, thumb_info);
} else if (image_type == IMG_CODEC_GIF) {
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info)
+ media_thumb_info *thumb_info,
+ uid_t uid)
{
int err = -1;
#include <glib.h>
-int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length)
+int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid)
{
int err = -1;
//int need_update_db = 0;
}
*/
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
+ err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
//_media_thumb_db_disconnect();
return MEDIA_THUMB_ERROR_NONE;
}
-int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path)
+int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path, uid_t uid)
{
int err = -1;
tmp_thumb_path[sizeof(tmp_thumb_path) - 1] = '\0';
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
+ err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
return MEDIA_THUMB_ERROR_NONE;
}
-int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height)
+int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
{
int err = -1;
//int need_update_db = 0;
}
*/
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
+ err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
//_media_thumb_db_disconnect();
return MEDIA_THUMB_ERROR_NONE;
}
-int thumbnail_request_extract_all_thumbs(void)
+int thumbnail_request_extract_all_thumbs(uid_t uid)
{
int err = -1;
char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
+ err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
return MEDIA_THUMB_ERROR_NONE;
}
-int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data)
+int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data, uid_t uid)
{
int err = -1;
userData->user_data = user_data;
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData);
+ err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
SAFE_FREE(userData);
return MEDIA_THUMB_ERROR_NONE;
}
-int thumbnail_request_cancel_media(const char *origin_path)
+int thumbnail_request_cancel_media(const char *origin_path, uid_t uid)
{
int err = -1;
return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
}
- err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL);
+ err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
return MEDIA_THUMB_ERROR_NONE;
}
-int thumbnail_request_cancel_all()
+int thumbnail_request_cancel_all(uid_t uid)
{
int err = -1;
char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
+ err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
if (err < 0) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
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;
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;
_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;
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;
const char *origin_path,
char *thumb_path,
int width,
- int height)
+ int height,
+ uid_t uid)
{
thumb_dbg("");
int err = -1;
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;
}
int
-_media_thumb_db_connect()
+_media_thumb_db_connect(uid_t uid)
{
int err = -1;
/*
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;
_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;
}
#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;
#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)
{
}
}
+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;
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);
int *height,
int *origin_width,
int *origin_height,
- int *alpha)
+ int *alpha,
+ uid_t uid)
{
int err = -1;
int thumb_width = -1;
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;
long start = thumb_get_debug_time();
- err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha);
+ err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, tzplatform_getuid(TZ_USER_NAME));
if (err < 0) {
printf("_thumbnail_get_data failed - %d\n", err);
return -1;
//const char *origin_path = "/opt/media/test/movie2.avi";
char thumb_path[MAX_PATH_SIZE + 1];
- err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path));
+ err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path), tzplatform_getuid(TZ_USER_NAME));
if (err < 0) {
printf("thumbnail_request_from_db failed : %d\n", err);
return -1;
return -1;
}
- err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path);
+ err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path, tzplatform_getuid(TZ_USER_NAME));
if (err < 0) {
printf("thumbnail_request_save_to_file failed : %d\n", err);
return -1;
} else if (mode == 5) {
printf("Test thumbnail_request_extract_all_thumbs\n");
- err = thumbnail_request_extract_all_thumbs();
+ err = thumbnail_request_extract_all_thumbs(tzplatform_getuid(TZ_USER_NAME));
if (err < 0) {
printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
return -1;
} else if (mode == 6) {
printf("Test thumbnail_request_cancel_media\n");
- err = thumbnail_request_cancel_media(origin_path);
+ err = thumbnail_request_cancel_media(origin_path,tzplatform_getuid(TZ_USER_NAME));
if (err < 0) {
printf("thumbnail_request_cancel_media failed : %d\n", err);
return -1;