$(SQLITE3_CFLAGS) \
$(DB_UTIL_CFLAGS) \
$(PHONESTATUS_CFLAGS) \
- $(TZ_PLATFORM_CONFIG_CFLAGS)
+ $(TZ_PLATFORM_CONFIG_CFLAGS) \
+ $(LIBSMACK_CFLAGS)
libmedia_utils_la_LIBADD = $(GLIB_LIBS) \
$(DLOG_LIBS) \
$(SQLITE3_LIBS) \
$(DB_UTIL_LIBS) \
$(PHONESTATUS_LIBS) \
- $(TZ_PLATFORM_CONFIG_LIBS)
+ $(TZ_PLATFORM_CONFIG_LIBS) \
+ $(LIBSMACK_LIBS)
### file-manager-server ###
CPPFLAGS="${CPPFLAGS} -DRND_LINUX"
#using UDS socket
-#CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_"
-CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_TCP_"
+CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_"
+#CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_TCP_"
# FMS_DEBUG - File Manager Service debug options
# To open debug options:
AC_SUBST(TZ_PLATFORM_CONFIG_CFLAGS)
AC_SUBST(TZ_PLATFORM_CONFIG_LIBS)
+#smack lib
+PKG_CHECK_MODULES(LIBSMACK, libsmack)
+AC_SUBST(LIBSMACK_CFLAGS)
+AC_SUBST(LIBSMACK_LIBS)
+
#ticker noti library
PKG_CHECK_MODULES(STATUS, notification)
AC_SUBST(STATUS_CFLAGS)
{
ms_msg_type_e msg_type;
int pid;
+ uid_t uid;
int result;
size_t msg_size; /*this is size of message below and this does not include the terminationg null byte ('\0'). */
char msg[MAX_MSG_SIZE];
int thumb_type;
int status;
int pid;
+ uid_t uid;
int thumb_size;
int thumb_width;
int thumb_height;
typedef void MediaDBHandle; /**< Handle */
-int media_db_connect(MediaDBHandle **handle);
+int media_db_connect(MediaDBHandle **handle, uid_t uid);
int media_db_disconnect(MediaDBHandle *handle);
-int media_db_request_update_db(const char *query_str);
+int media_db_request_update_db(const char *query_str, uid_t uid);
-int media_db_request_update_db_batch_start(const char *query_str);
+int media_db_request_update_db_batch_start(const char *query_str, uid_t uid);
-int media_db_request_update_db_batch(const char *query_str);
+int media_db_request_update_db_batch(const char *query_str, uid_t uid);
-int media_db_request_update_db_batch_end(const char *query_str);
+int media_db_request_update_db_batch_end(const char *query_str, uid_t uid);
-int media_db_request_directory_scan(const char *directory_path);
+int media_db_request_directory_scan(const char *directory_path , uid_t uid);
/**
* @}
typedef void (*scan_complete_cb)(media_request_result_s *, void *);
typedef void (*insert_complete_cb)(media_request_result_s *, void *);
-int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data);
+int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data, uid_t uid);
-int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data);
+int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data, uid_t uid);
-int media_burstshot_register(const char *list_path, insert_complete_cb user_callback, void *user_data);
+int media_burstshot_register(const char *list_path, insert_complete_cb user_callback, void *user_data, uid_t uid);
/**
* @}
#include <tzplatform_config.h>
-#define MEDIA_ROOT_PATH_INTERNAL tzplatform_mkpath(TZ_SYS_DATA,"data-media")
+#define MEDIA_ROOT_PATH_INTERNAL tzplatform_getenv(TZ_USER_HOME)
#define MEDIA_ROOT_PATH_SDCARD tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
#define MEDIA_DATA_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service")
-#define MEDIA_DB_NAME tzplatform_mkpath(TZ_SYS_DB, ".media.db") /**< media db name*/
+#define MEDIA_DB_NAME tzplatform_mkpath(TZ_USER_DB, ".media.db") /**< media db name*/
#endif /*_MEDIA_UTIL_H_*/
#include <string.h>
#include <errno.h>
#include <db-util.h>
+#include <grp.h>
+#include <pwd.h>
+#include <sys/smack.h>
#include "media-server-ipc.h"
#include "media-util-dbg.h"
#include "media-util-internal.h"
#include "media-util.h"
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
+#define BUFSIZE 4096
+
+#define QUERY_ATTACH "attach database '%s' as Global"
+#define QUERY_CREATE_VIEW_ALBUM "CREATE temp VIEW album as select distinct * from (select * from main.album m union select * from Global.album g)"
+#define QUERY_CREATE_VIEW_FOLDER "CREATE temp VIEW folder as select distinct * from (select * from main.folder m union select * from Global.folder g)"
+#define QUERY_CREATE_VIEW_PLAYLIST "CREATE temp VIEW playlist as select distinct * from (select * from main.playlist m union select * from Global.playlist g)"
+#define QUERY_CREATE_VIEW_PLAYLIST_VIEW "CREATE temp VIEW playlist_view as select distinct * from (select * from main.playlist_view m union select * from Global.playlist_view g)"
+#define QUERY_CREATE_VIEW_TAG_MAP "CREATE temp VIEW tag_map as select distinct * from (select * from main.tag_map m union select * from Global.tag_map g)"
+#define QUERY_CREATE_VIEW_BOOKMARK "CREATE temp VIEW bookmark as select distinct * from (select * from main.bookmark m union select * from Global.bookmark g)"
+#define QUERY_CREATE_VIEW_MEDIA "CREATE temp VIEW media as select distinct * from (select * from main.media m union select * from Global.media g)"
+#define QUERY_CREATE_VIEW_PLAYLIST_MAP "CREATE temp VIEW playlist_map as select distinct * from (select * from main.playlist_map m union select * from Global.playlist_map g)"
+#define QUERY_CREATE_VIEW_TAG "CREATE temp VIEW tag as select distinct * from (select * from main.tag m union select * from Global.tag g)"
+#define QUERY_CREATE_VIEW_TAG_VIEW "CREATE temp VIEW tag_view as select distinct * from (select * from main.tag_view m union select * from Global.tag_view g)"
+
+#define QUERY_DETACH "detach database Global"
+#define QUERY_DROP_VIEW_ALBUM "DROP VIEW album"
+#define QUERY_DROP_VIEW_FOLDER "DROP VIEW folder"
+#define QUERY_DROP_VIEW_PLAYLIST "DROP VIEW playlist"
+#define QUERY_DROP_VIEW_PLAYLIST_VIEW "DROP VIEW playlist_view"
+#define QUERY_DROP_VIEW_TAG_MAP "DROP VIEW tag_map"
+#define QUERY_DROP_VIEW_BOOKMARK "DROP VIEW bookmark"
+#define QUERY_DROP_VIEW_MEDIA "DROP VIEW media"
+#define QUERY_DROP_VIEW_PLAYLIST_MAP "DROP VIEW playlist_map"
+#define QUERY_DROP_VIEW_TAG "DROP VIEW tag"
+#define QUERY_DROP_VIEW_TAG_VIEW "DROP VIEW tag_view"
+
static __thread char **sql_list = NULL;
static __thread int g_list_idx = 0;
static int __media_db_busy_handler(void *pData, int count);
-static int __media_db_connect_db_with_handle(sqlite3 **db_handle);
+static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid);
static int __media_db_disconnect_db_with_handle(sqlite3 *db_handle);
-static int __media_db_request_update(ms_msg_type_e msg_type, const char *request_msg);
+static int __media_db_request_update(ms_msg_type_e msg_type, const char *request_msg, uid_t uid);
void __media_db_destroy_sql_list()
{
}
return WEXITSTATUS(status);
}
-#define SCRIPT_INIT_DB "/usr/bin/media-data-sdk_create_db.sh"
-static int __media_db_connect_db_with_handle(sqlite3 **db_handle)
+
+static char* __media_get_media_DB(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ char * dir = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_DB_NAME);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ MSAPI_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ MSAPI_DBG_ERR("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ MSAPI_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/.applications/dbspace/.media.db", userinfo->pw_dir);
+ }
+
+ dir = strrchr(result_psswd, '/');
+ if(!dir)
+ return result_psswd;
+
+ //Control if db exist create otherwise
+ if(access(dir + 1, F_OK)) {
+ int ret;
+ mkdir(dir + 1, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+ ret = chown(dir + 1, uid, grpinfo->gr_gid);
+ if (ret == -1) {
+ char buf[BUFSIZE];
+ strerror_r(errno, buf, sizeof(buf));
+ MSAPI_DBG_ERR("FAIL : chown %s %d.%d, because %s", dir + 1, uid, grpinfo->gr_gid, buf);
+ }
+ }
+
+ return result_psswd;
+}
+
+static int __media_db_update_directly(sqlite3 *db_handle, const char *sql_str)
{
int ret = MS_MEDIA_ERR_NONE;
+ char *zErrMsg = NULL;
+ MSAPI_DBG_INFO("SQL = [%s]", sql_str);
+
+ ret = sqlite3_exec(db_handle, sql_str, NULL, NULL, &zErrMsg);
+
+ if (SQLITE_OK != ret) {
+ MSAPI_DBG_ERR("DB Update Fail SQL:%s [%s], err[%d]", sql_str, zErrMsg, ret);
+ if (ret == SQLITE_BUSY)
+ ret = MS_MEDIA_ERR_DB_BUSY_FAIL;
+ else
+ ret = MS_MEDIA_ERR_DB_UPDATE_FAIL;
+ } else {
+ MSAPI_DBG("DB Update Success");
+ }
+
+ if (zErrMsg)
+ sqlite3_free (zErrMsg);
+
+ return ret;
+}
+
+static int __media_db_connect_db_with_handle(sqlite3 **db_handle,uid_t uid)
+{
+ int i;
+ int ret = MS_MEDIA_ERR_NONE;
+ char *mediadb_path = NULL;
+ char *mediadbjournal_path = NULL;
+
/*Init DB*/
- struct stat sts;
- /* Check if the DB exists; if not, create it and initialize it */
- ret = stat(MEDIA_DB_NAME, &sts);
- if (ret == -1 && errno == ENOENT)
- {
- const char *argv_script[] = {"/bin/sh", SCRIPT_INIT_DB, NULL };
- ret = _xsystem(argv_script);
+ const char *tbls[46] = {
+ "CREATE TABLE IF NOT EXISTS album (album_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, artist TEXT, album_art TEXT, unique(name, artist));",
+ "CREATE TABLE IF NOT EXISTS bookmark (bookmark_id INTEGER PRIMARY KEY AUTOINCREMENT, media_uuid TEXT NOT NULL, marked_time INTEGER DEFAULT 0, thumbnail_path TEXT, unique(media_uuid, marked_time));",
+ "CREATE TABLE IF NOT EXISTS folder (folder_uuid TEXT PRIMARY KEY, path TEXT NOT NULL UNIQUE, name TEXT NOT NULL, modified_time INTEGER DEFAULT 0, storage_type INTEGER, unique(path, name, storage_type));",
+ "CREATE TABLE IF NOT EXISTS media (media_uuid TEXT PRIMARY KEY, path TEXT NOT NULL UNIQUE, file_name TEXT NOT NULL, media_type INTEGER, mime_type TEXT, size INTEGER DEFAULT 0, added_time INTEGER DEFAULT 0, modified_time INTEGER DEFAULT 0, folder_uuid TEXT NOT NULL, thumbnail_path TEXT, title TEXT, album_id INTEGER DEFAULT 0, album TEXT, artist TEXT, genre TEXT, composer TEXT, year TEXT, recorded_date TEXT, copyright TEXT, track_num TEXT, description TEXT, bitrate INTEGER DEFAULT -1, samplerate INTEGER DEFAULT -1, channel INTEGER DEFAULT -1, duration INTEGER DEFAULT -1, longitude DOUBLE DEFAULT 0, latitude DOUBLE DEFAULT 0, altitude DOUBLE DEFAULT 0, width INTEGER DEFAULT -1, height INTEGER DEFAULT -1, datetaken TEXT, orientation INTEGER DEFAULT -1, burst_id TEXT, played_count INTEGER DEFAULT 0, last_played_time INTEGER DEFAULT 0, last_played_position INTEGER DEFAULT 0, rating INTEGER DEFAULT 0, favourite INTEGER DEFAULT 0, author TEXT, provider TEXT, content_name TEXT, category TEXT, location_tag TEXT, age_rating TEXT, keyword TEXT, is_drm INTEGER DEFAULT 0, storage_type INTEGER, validity INTEGER DEFAULT 1, unique(path, file_name) );",
+ "CREATE TABLE IF NOT EXISTS playlist ( playlist_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, thumbnail_path TEXT );",
+ "CREATE TABLE IF NOT EXISTS playlist_map ( _id INTEGER PRIMARY KEY AUTOINCREMENT, playlist_id INTEGER NOT NULL, media_uuid TEXT NOT NULL, play_order INTEGER NOT NULL );",
+ "CREATE TABLE IF NOT EXISTS tag ( tag_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE );",
+ "CREATE TABLE IF NOT EXISTS tag_map ( _id INTEGER PRIMARY KEY AUTOINCREMENT, tag_id INTEGER NOT NULL, media_uuid TEXT NOT NULL, unique(tag_id, media_uuid) );",
+ "CREATE INDEX folder_folder_uuid_idx on folder (folder_uuid);",
+ "CREATE INDEX folder_uuid_idx on media (folder_uuid);",
+ "CREATE INDEX media_album_idx on media (album);",
+ "CREATE INDEX media_artist_idx on media (artist);",
+ "CREATE INDEX media_author_idx on media (author);",
+ "CREATE INDEX media_category_idx on media (category);",
+ "CREATE INDEX media_composer_idx on media (composer);",
+ "CREATE INDEX media_content_name_idx on media (content_name);",
+ "CREATE INDEX media_file_name_idx on media (file_name);",
+ "CREATE INDEX media_genre_idx on media (genre);",
+ "CREATE INDEX media_location_tag_idx on media (location_tag);",
+ "CREATE INDEX media_media_type_idx on media (media_type);",
+ "CREATE INDEX media_media_uuid_idx on media (media_uuid);",
+ "CREATE INDEX media_modified_time_idx on media (modified_time);",
+ "CREATE INDEX media_path_idx on media (path);",
+ "CREATE INDEX media_provider_idx on media (provider);",
+ "CREATE INDEX media_title_idx on media (title);",
+ "CREATE VIEW IF NOT EXISTS playlist_view AS "
+ "SELECT "
+ "p.playlist_id, p.name, p.thumbnail_path, media_count, pm._id as pm_id, pm.play_order, m.media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, m.thumbnail_path, description, rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel FROM playlist AS p "
+ "INNER JOIN playlist_map AS pm "
+ "INNER JOIN media AS m "
+ "INNER JOIN (SELECT count(playlist_id) as media_count, playlist_id FROM playlist_map group by playlist_id) as cnt_tbl "
+ "ON (p.playlist_id=pm.playlist_id AND pm.media_uuid = m.media_uuid AND cnt_tbl.playlist_id=pm.playlist_id AND m.validity=1) "
+ "UNION "
+ "SELECT "
+ "playlist_id, name, thumbnail_path, 0, 0, -1, NULL, NULL, -1, -1, -1, -1, -1, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, NULL, -1 FROM playlist "
+ "WHERE playlist_id "
+ "NOT IN (select playlist_id from playlist_map);",
+ "CREATE VIEW IF NOT EXISTS tag_view AS "
+ "SELECT "
+ "t.tag_id, t.name, media_count, tm._id as tm_id, m.media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel FROM tag AS t "
+ "INNER JOIN tag_map AS tm "
+ "INNER JOIN media AS m "
+ "INNER JOIN (SELECT count(tag_id) as media_count, tag_id FROM tag_map group by tag_id) as cnt_tbl "
+ "ON (t.tag_id=tm.tag_id AND tm.media_uuid = m.media_uuid AND cnt_tbl.tag_id=tm.tag_id AND m.validity=1)"
+ "UNION "
+ "SELECT "
+ "tag_id, name, 0, 0, NULL, NULL, -1, -1, -1, -1, -1, NULL, NULL, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, -1, -1, -1, -1, -1, NULL, -1 FROM tag "
+ "WHERE tag_id "
+ "NOT IN (select tag_id from tag_map); ",
+ "CREATE TRIGGER album_cleanup DELETE ON media BEGIN DELETE FROM album WHERE (SELECT count(*) FROM media WHERE album_id=old.album_id)=1 AND album_id=old.album_id;END;",
+ "CREATE TRIGGER bookmark_cleanup DELETE ON media BEGIN DELETE FROM bookmark WHERE media_uuid=old.media_uuid;END;",
+ "CREATE TRIGGER folder_cleanup DELETE ON media BEGIN DELETE FROM folder WHERE (SELECT count(*) FROM media WHERE folder_uuid=old.folder_uuid)=1 AND folder_uuid=old.folder_uuid;END;",
+ "CREATE TRIGGER playlist_map_cleanup DELETE ON media BEGIN DELETE FROM playlist_map WHERE media_uuid=old.media_uuid;END;",
+ "CREATE TRIGGER playlist_map_cleanup_1 DELETE ON playlist BEGIN DELETE FROM playlist_map WHERE playlist_id=old.playlist_id;END;",
+ "CREATE TRIGGER tag_map_cleanup DELETE ON media BEGIN DELETE FROM tag_map WHERE media_uuid=old.media_uuid;END;",
+ "CREATE TRIGGER tag_map_cleanup_1 DELETE ON tag BEGIN DELETE FROM tag_map WHERE tag_id=old.tag_id;END;",
+ NULL
+ };
+
+ mediadb_path = __media_get_media_DB(uid);
+
+ if (access(mediadb_path, F_OK)) {
+ if (MS_MEDIA_ERR_NONE == db_util_open_with_options(mediadb_path, db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
+ for (i = 0; tbls[i] != NULL; i++) {
+ ret = __media_db_update_directly(*db_handle, tbls[i]);
+ }
+ if(smack_setlabel(__media_get_media_DB(uid), "User", SMACK_LABEL_ACCESS)){
+ MSAPI_DBG_ERR("failed chsmack -a \"User\" %s", mediadb_path);
+ } else {
+ MSAPI_DBG_ERR("chsmack -a \"User\" %s", mediadb_path);
+ }
+ asprintf(&mediadbjournal_path, "%s-journal", mediadb_path);
+ if(smack_setlabel(mediadbjournal_path, "User", SMACK_LABEL_ACCESS)){
+ MSAPI_DBG_ERR("failed chsmack -a \"User\" %s", mediadbjournal_path);
+ } else {
+ MSAPI_DBG_ERR("chsmack -a \"User\" %s", mediadbjournal_path);
+ }
+ } else {
+ MSAPI_DBG_ERR("Failed to create table %s\n",__media_get_media_DB(uid));
+ }
}
- ret = db_util_open(MEDIA_DB_NAME, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
+
+ ret = db_util_open(__media_get_media_DB(uid), db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
if (SQLITE_OK != ret) {
MSAPI_DBG_ERR("error when db open");
return MS_MEDIA_ERR_NONE;
}
-static int __media_db_request_update(ms_msg_type_e msg_type, const char *request_msg)
+static int __media_db_request_update(ms_msg_type_e msg_type, const char *request_msg, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
int request_msg_size = 0;
send_msg.msg_type = msg_type;
send_msg.msg_size = request_msg_size;
strncpy(send_msg.msg, request_msg, request_msg_size);
+ send_msg.uid = uid;
/*Create Socket*/
#ifdef _USE_UDS_SOCKET_
}
#ifdef _USE_UDS_SOCKET_
-extern char MEDIA_IPC_PATH[][50];
+extern char MEDIA_IPC_PATH[][70];
#elif defined(_USE_UDS_SOCKET_TCP_)
extern char MEDIA_IPC_PATH[][50];
#endif
return 0;
}
-static int __media_db_request_batch_update(ms_msg_type_e msg_type, const char *request_msg)
+static int __media_db_request_batch_update(ms_msg_type_e msg_type, const char *request_msg, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
int request_msg_size = 0;
send_msg.msg_type = msg_type;
send_msg.msg_size = request_msg_size;
+ send_msg.uid = uid;
strncpy(send_msg.msg, request_msg, request_msg_size);
sockfd = __media_db_get_client_tcp_sock();
return ret;
}
-static int _media_db_update_directly(sqlite3 *db_handle, const char *sql_str)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *zErrMsg = NULL;
-
- MSAPI_DBG_INFO("SQL = [%s]", sql_str);
-
- ret = sqlite3_exec(db_handle, sql_str, NULL, NULL, &zErrMsg);
-
- if (SQLITE_OK != ret) {
- MSAPI_DBG_ERR("DB Update Fail SQL:%s [%s], err[%d]", sql_str, zErrMsg, ret);
- if (ret == SQLITE_BUSY)
- ret = MS_MEDIA_ERR_DB_BUSY_FAIL;
- else
- ret = MS_MEDIA_ERR_DB_UPDATE_FAIL;
- } else {
- MSAPI_DBG("DB Update Success");
- }
-
- if (zErrMsg)
- sqlite3_free (zErrMsg);
-
- return ret;
-}
-
-int media_db_connect(MediaDBHandle **handle)
+int media_db_connect(MediaDBHandle **handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3 * db_handle = NULL;
MSAPI_DBG_FUNC();
- ret = __media_db_connect_db_with_handle(&db_handle);
+ ret = __media_db_connect_db_with_handle(&db_handle,uid);
MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
*handle = db_handle;
return __media_db_disconnect_db_with_handle(db_handle);
}
-int media_db_request_update_db(const char *query_str)
+int media_db_request_update_db(const char *query_str, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query");
- ret = __media_db_request_update(MS_MSG_DB_UPDATE, query_str);
+ ret = __media_db_request_update(MS_MSG_DB_UPDATE, query_str ,uid);
return ret;
}
-int media_db_request_update_db_batch_start(const char *query_str)
+int media_db_request_update_db_batch_start(const char *query_str, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
return ret;
}
- ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH_START, query_str);
+ ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH_START, query_str, uid);
return ret;
}
-int media_db_request_update_db_batch(const char *query_str)
+int media_db_request_update_db_batch(const char *query_str, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query");
- ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH, query_str);
+ ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH, query_str, uid);
return ret;
}
-int media_db_request_update_db_batch_end(const char *query_str)
+int media_db_request_update_db_batch_end(const char *query_str, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
return ret;
}
- ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH_END, query_str);
+ ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH_END, query_str, uid);
__media_db_close_tcp_client_socket();
return ret;
}
-int media_db_request_directory_scan(const char *directory_path)
+int media_db_request_directory_scan(const char *directory_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
MSAPI_RETVM_IF(!MS_STRING_VALID(directory_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Directory Path is NULL");
- ret = __media_db_request_update(MS_MSG_DIRECTORY_SCANNING, directory_path);
+ ret = __media_db_request_update(MS_MSG_DIRECTORY_SCANNING, directory_path, uid);
return ret;
}
MSAPI_RETVM_IF(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query");
- ret = _media_db_update_directly(db_handle, query_str);
+ ret = __media_db_update_directly(db_handle, query_str);
return ret;
}
char *current_sql = NULL;
for (i = 0; i < g_list_idx; i++) {
current_sql = sql_list[i];
- ret = _media_db_update_directly(db_handle, current_sql);
+ ret = __media_db_update_directly(db_handle, current_sql);
if (ret < 0) {
if (i == 0) {
/* This is fail of "BEGIN" */
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <grp.h>
+#include <pwd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#include "media-util-dbg.h"
#include "media-util.h"
#ifdef _USE_UDS_SOCKET_
-char MEDIA_IPC_PATH[][50] ={
- {"/tmp/media_ipc_dbbatchupdate.dat"},
- {"/tmp/media_ipc_scandaemon.dat"},
- {"/tmp/media_ipc_scancomm.dat"},
- {"/tmp/media_ipc_scanner.dat"},
- {"/tmp/media_ipc_dbupdate.dat"},
- {"/tmp/media_ipc_thumbcreator.dat"},
- {"/tmp/media_ipc_thumbcomm.dat"},
- {"/tmp/media_ipc_thumbdaemon.dat"},
+char MEDIA_IPC_PATH[][70] ={
+ {"/var/run/media-server/media_ipc_dbbatchupdate.socket"},
+ {"/var/run/media-server/media_ipc_scandaemon.socket"},
+ {"/var/run/media-server/media_ipc_scancomm.socket"},
+ {"/var/run/media-server/media_ipc_scanner.socket"},
+ {"/var/run/media-server/media_ipc_dbupdate.socket"},
+ {"/var/run/media-server/media_ipc_thumbcreator.socket"},
+ {"/var/run/media-server/media_ipc_thumbcomm.socket"},
+ {"/var/run/media-server/media_ipc_thumbdaemon.socket"},
+};
+
+char MEDIA_IPC_PATH_CLIENT[][80] ={
+ {"/var/run/user/%i/media-server/media_ipc_dbbatchupdate_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_scandaemon_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_scancomm_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_scanner_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_dbupdate_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_thumbcreator_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_thumbcomm_client%i.socket"},
+ {"/var/run/user/%i/media-server/media_ipc_thumbdaemon_client%i.socket"},
};
-char MEDIA_IPC_PATH_CLIENT[][50] ={
- {"/tmp/media_ipc_dbbatchupdate_client.dat"},
- {"/tmp/media_ipc_scandaemon_client.dat"},
- {"/tmp/media_ipc_scancomm_client.dat"},
- {"/tmp/media_ipc_scanner_client.dat"},
- {"/tmp/media_ipc_dbupdate_client.dat"},
- {"/tmp/media_ipc_thumbcreator_client.dat"},
- {"/tmp/media_ipc_thumbcomm_client.dat"},
- {"/tmp/media_ipc_thumbdaemon_client.dat"},
+char MEDIA_IPC_PATH_CLIENT_ROOT[][80] ={
+ {"/var/run/media-server/media_ipc_dbbatchupdate_client%i.socket"},
+ {"/var/run/media-server/media_ipc_scandaemon_client%i.socket"},
+ {"/var/run/media-server/media_ipc_scancomm_client%i.socket"},
+ {"/var/run/media-server/media_ipc_scanner_client%i.socket"},
+ {"/var/run/media-server/media_ipc_dbupdate_client%i.socket"},
+ {"/var/run/media-server/media_ipc_thumbcreator_client%i.socket"},
+ {"/var/run/media-server/media_ipc_thumbcomm_client%i.socket"},
+ {"/var/run/media-server/media_ipc_thumbdaemon_client%i.socket"},
};
+
#elif defined(_USE_UDS_SOCKET_TCP_)
char MEDIA_IPC_PATH[][50] ={
{"/tmp/media_ipc_dbbatchupdate.dat"},
};
#endif
+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);
+}
+
#ifdef _USE_UDS_SOCKET_
int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port)
#else
struct timeval tv_timeout = { timeout_sec, 0 };
+ char *buffer;
+ char *path;
+ int cx,len;
+
+#ifdef _USE_UDS_SOCKET_
+ mode_t orig_mode;
+
+ if (tzplatform_getuid(TZ_USER_NAME) == 0 ){
+ cx = snprintf ( NULL, 0, MEDIA_IPC_PATH_CLIENT_ROOT[port],getpid());
+ buffer = (char*)malloc((cx + 1 )*sizeof(char));
+ snprintf ( buffer, cx + 1, MEDIA_IPC_PATH_CLIENT_ROOT[port],getpid());
+ } else {
+ len = snprintf ( NULL, 0, "/var/run/user/%i/media-server", tzplatform_getuid(TZ_USER_NAME));
+ path = (char*)malloc((len + 1 )*sizeof(char));
+ snprintf ( path, len + 1, "/var/run/user/%i/media-server", tzplatform_getuid(TZ_USER_NAME));
+ _mkdir(path, 0777);
+ free(path);
+ cx = snprintf ( NULL, 0, MEDIA_IPC_PATH_CLIENT[port], tzplatform_getuid(TZ_USER_NAME),getpid());
+ buffer = (char*)malloc((cx + 1 )*sizeof(char));
+ snprintf ( buffer, cx + 1, MEDIA_IPC_PATH_CLIENT[port],tzplatform_getuid(TZ_USER_NAME),getpid());
+ }
+ orig_mode = umask(0111);
+#endif
+
if(protocol == MS_PROTOCOL_UDP)
{
#ifdef _USE_UDS_SOCKET_
#ifdef _USE_UDS_SOCKET_
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
- MSAPI_DBG("%s", MEDIA_IPC_PATH_CLIENT[port]);
- unlink(MEDIA_IPC_PATH_CLIENT[port]);
- strcpy(serv_addr.sun_path, MEDIA_IPC_PATH_CLIENT[port]);
-
+ MSAPI_DBG("%s", buffer);
+ unlink(buffer);
+ strcpy(serv_addr.sun_path, buffer);
+
/* Bind to the local address */
if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
MSAPI_DBG_ERR("bind failed : %s", strerror(errno));
close(sock);
+#ifdef _USE_UDS_SOCKET_
+ free(buffer);
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
#endif
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
+#ifdef _USE_UDS_SOCKET_
+ free(buffer);
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
}
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
MSAPI_DBG_ERR("setsockopt failed: %s", strerror(errno));
close(sock);
+#ifdef _USE_UDS_SOCKET_
+ free(buffer);
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
}
*sock_fd = sock;
+#ifdef _USE_UDS_SOCKET_
+ free(buffer);
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_NONE;
}
struct sockaddr_un serv_addr;
mode_t orig_mode;
- orig_mode = umask(0);
+ orig_mode = umask(0111);
/* Create a TCP socket */
if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
int n_reuse = 1;
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un serv_addr;
+ mode_t orig_mode;
+ orig_mode = umask(0111);
#else
struct sockaddr_in serv_addr;
#endif
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
+#ifdef _USE_UDS_SOCKET_
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
}
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
+#ifdef _USE_UDS_SOCKET_
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
}
if (bind_success == false) {
MSAPI_DBG_ERR("bind failed : %s %d_", strerror(errno), errno);
close(sock);
+#ifdef _USE_UDS_SOCKET_
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
if (listen(sock, SOMAXCONN) < 0) {
MSAPI_DBG_ERR("listen failed : %s", strerror(errno));
close(sock);
+#ifdef _USE_UDS_SOCKET_
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_SOCKET_CONN;
}
}
*sock_fd = sock;
+#ifdef _USE_UDS_SOCKET_
+ umask(orig_mode);
+#endif
return MS_MEDIA_ERR_NONE;
}
#include <stdbool.h>
#include <dirent.h>
#include <vconf.h>
+#include <grp.h>
+#include <pwd.h>
#include "media-server-ipc.h"
#include "media-util-internal.h"
void *user_data;
} media_callback_data;
-static bool _is_valid_path(const char *path)
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
+
+static char* __media_get_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ MSAPI_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ MSAPI_DBG_ERR("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ MSAPI_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s", userinfo->pw_dir);
+ }
+
+ return result_psswd;
+}
+
+static bool _is_valid_path(const char *path, uid_t uid)
{
- if (path == NULL)
- return false;
+
+ int lenght_path;
+ char * user_path = NULL;
+
+ if (path == NULL)
+ return false;
+
+ user_path = __media_get_path(uid);
+ lenght_path = strlen(user_path);
- if (strncmp(path, MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)) == 0) {
+ if (strncmp(path, user_path, lenght_path) == 0) {
return true;
} else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
return true;
return true;
}
-static int _check_dir_path(const char *dir_path)
+static int _check_dir_path(const char *dir_path, uid_t uid)
{
struct stat sb;
DIR *dp = NULL;
- if (!_is_valid_path(dir_path)) {
+ if (!_is_valid_path(dir_path,uid)) {
MSAPI_DBG("Invalid path : %s", dir_path);
return MS_MEDIA_ERR_INVALID_PATH;
}
return MS_MEDIA_ERR_NONE;
}
-static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *request_msg, scan_complete_cb user_callback, void *user_data)
+static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *request_msg, scan_complete_cb user_callback, void *user_data, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
int request_msg_size = 0;
send_msg.msg_type = msg_type;
send_msg.pid = syscall(__NR_getpid);
send_msg.msg_size = request_msg_size;
+ send_msg.uid = uid;
strncpy(send_msg.msg, request_msg, request_msg_size);
/*Create Socket*/
}
-int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data)
+int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data, uid_t uid)
{
int ret;
- ret = _check_dir_path(directory_path);
+ ret = _check_dir_path(directory_path,uid);
if(ret != MS_MEDIA_ERR_NONE)
return ret;
if (recursive_on == TRUE)
- ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING, directory_path, user_callback, user_data);
+ ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING, directory_path, user_callback, user_data, uid);
else
- ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, directory_path, user_callback, user_data);
+ ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, directory_path, user_callback, user_data, uid);
return ret;
}
-int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data)
+int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data, uid_t uid)
{
int ret;
- ret = __media_db_request_update_async(MS_MSG_BULK_INSERT, list_path, user_callback, user_data);
+ ret = __media_db_request_update_async(MS_MSG_BULK_INSERT, list_path, user_callback, user_data, uid);
MSAPI_DBG("client receive: %d", ret);
return ret;
}
-int media_burstshot_register(const char *list_path, insert_complete_cb user_callback, void *user_data)
+int media_burstshot_register(const char *list_path, insert_complete_cb user_callback, void *user_data, uid_t uid)
{
int ret;
- ret = __media_db_request_update_async(MS_MSG_BURSTSHOT_INSERT, list_path, user_callback, user_data);
+ ret = __media_db_request_update_async(MS_MSG_BURSTSHOT_INSERT, list_path, user_callback, user_data, uid);
MSAPI_DBG("client receive: %d", ret);
Name: media-server
Summary: File manager service server.
-Version: 0.2.46
+Version: 0.2.47
Release: 0
Group: Multimedia/Service
License: Apache-2.0
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(libsmack)
BuildRequires: pkgconfig(libtzplatform-config)
%description
mkdir -p %{buildroot}%{TZ_SYS_DATA}/data-media/Images
mkdir -p %{buildroot}%{TZ_SYS_DATA}/data-media/Sounds/Voice\ recorder
mkdir -p %{buildroot}%{TZ_SYS_DATA}/data-media/Videos
-mkdir -p %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/mmc
-mkdir -p %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/phone
+mkdir -p %{buildroot}%{TZ_SYS_DATA}/file-manager-service/.thumb/mmc
+mkdir -p %{buildroot}%{TZ_SYS_DATA}/file-manager-service/.thumb/phone
install -m 0775 ./data-media/Images/* %{buildroot}%{TZ_SYS_DATA}/data-media/Images/
-install -m 0775 ./data-media/dbspace/file-manager-service/.thumb/thumb_default.png %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/
-install -D -m 0775 ./data-media/dbspace/file-manager-service/.thumb/mmc/* %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/mmc/
-install -m 0775 ./data-media/dbspace/file-manager-service/.thumb/phone/PHONE_THUMB_HERE %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/phone/
-install -m 0775 ./data-media/dbspace/file-manager-service/.thumb/phone/.jpg* %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/phone/
-install -D -m 0775 ./data-media/dbspace/file-manager-service/* %{buildroot}%{TZ_SYS_DATA}/data-media/file-manager-service/
+install -m 0775 ./data-media/dbspace/file-manager-service/.thumb/thumb_default.png %{buildroot}%{TZ_SYS_DATA}/file-manager-service/.thumb/
+install -D -m 0775 ./data-media/dbspace/file-manager-service/.thumb/mmc/* %{buildroot}%{TZ_SYS_DATA}/file-manager-service/.thumb/mmc/
+install -m 0775 ./data-media/dbspace/file-manager-service/.thumb/phone/PHONE_THUMB_HERE %{buildroot}%{TZ_SYS_DATA}/file-manager-service/.thumb/phone/
+install -m 0775 ./data-media/dbspace/file-manager-service/.thumb/phone/.jpg* %{buildroot}%{TZ_SYS_DATA}/file-manager-service/.thumb/phone/
+install -D -m 0775 ./data-media/dbspace/file-manager-service/* %{buildroot}%{TZ_SYS_DATA}/file-manager-service/
install -m 0775 %{SOURCE1004} %{buildroot}%{_bindir}/media-data-sdk_create_db.sh
%post
vconftool set -t int file/private/mediaserver/scan_directory "1" -f
chgrp %TZ_SYS_USER_GROUP %{_bindir}/media-data-sdk_create_db.sh
chgrp -R %TZ_SYS_USER_GROUP %{TZ_SYS_DATA}/data-media
+chgrp -R %TZ_SYS_USER_GROUP %{TZ_SYS_DATA}/file-manager-service
%post -n libmedia-utils -p /sbin/ldconfig
%postun -n libmedia-utils -p /sbin/ldconfig
%license LICENSE.APLv2.0
%{_bindir}/media-data-sdk_create_db.sh
%{TZ_SYS_DATA}/data-media/*
-%{TZ_SYS_DATA}/data-media/file-manager-service/.thumb/*
+%{TZ_SYS_DATA}/file-manager-service/.thumb/*
+%{TZ_SYS_DATA}/file-manager-service/plugin-config
%files -n libmedia-utils
%manifest libmedia-utils.manifest
ms_end(void);
ms_storage_type_t
-ms_get_storage_type_by_full(const char *path);
+ms_get_storage_type_by_full(const char *path, uid_t uid);
int
ms_get_mime(const char *path, char *mimetype);
* @brief This file implements main database operation.
*/
+#define _GNU_SOURCE
+
#include <errno.h>
#include <vconf.h>
#include <aul/aul.h>
+#include <grp.h>
+#include <pwd.h>
#include "media-util.h"
#include "media-server-ipc.h"
#endif
#define MS_DRM_CONTENT_TYPE_LENGTH 100
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
#ifdef FMS_PERF
void
return true;
}
}
+static char* __media_get_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ MS_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ MS_DBG_ERR("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s", userinfo->pw_dir);
+ }
+
+ return result_psswd;
+}
ms_storage_type_t
-ms_get_storage_type_by_full(const char *path)
+ms_get_storage_type_by_full(const char *path, uid_t uid)
{
- if (strncmp(path, MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)) == 0) {
+ int lenght_path;
+ char * user_path = NULL;
+
+ if (path == NULL)
+ return false;
+
+ user_path = __media_get_path(uid);
+ lenght_path = strlen(user_path);
+
+ if (strncmp(path, user_path, lenght_path) == 0) {
return MS_STORAGE_INTERNAL;
} else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
return MS_STORAGE_EXTERNAL;
printf("\n");
printf("db-update --help for check this messages.\n");
printf("\n");
- printf("A file or directory must exists under %s or %s.\n",tzplatform_mkpath(TZ_SYS_DATA,"data-media"),tzplatform_mkpath(TZ_SYS_STORAGE,"sdcard"));
+ printf("A file or directory must exists under %s or %s.\n",tzplatform_getenv(TZ_USER_HOME),tzplatform_mkpath(TZ_SYS_STORAGE,"sdcard"));
printf("Using %s is allowed SD card is mounted.\n",tzplatform_mkpath(TZ_SYS_STORAGE,"sdcard"));
printf("\n");
printf("=======================================================================================\n");
int dir_scan_non_recursive(char *path)
{
- return media_directory_scanning_async(path, FALSE, callback, NULL);
+ return media_directory_scanning_async(path, FALSE, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
}
int dir_scan_recursive(char *path)
{
- return media_directory_scanning_async(path, TRUE, callback, NULL);
+ return media_directory_scanning_async(path, TRUE, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
}
typedef enum {
#include "media-common-types.h"
typedef int (*CHECK_ITEM)(const char*, char **);
-typedef int (*CONNECT)(void**, char **);
+typedef int (*CONNECT)(void**, uid_t, char **);
typedef int (*DISCONNECT)(void*, char **);
typedef int (*CHECK_ITEM_EXIST)(void*, const char*, int, char **);
typedef int (*INSERT_ITEM_BEGIN)(void*, int, int, int, char **);
-typedef int (*INSERT_ITEM_END)(void*, char **);
-typedef int (*INSERT_ITEM)(void*, const char*, int, char **);
-typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, char **);
+typedef int (*INSERT_ITEM_END)(void*, uid_t, char **);
+typedef int (*INSERT_ITEM)(void*, const char*, int, uid_t, char **);
+typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, uid_t, char **);
typedef int (*SET_ITEM_VALIDITY_BEGIN)(void*, int, char **);
-typedef int (*SET_ITEM_VALIDITY_END)(void*, char **);
+typedef int (*SET_ITEM_VALIDITY_END)(void*, uid_t, char **);
typedef int (*SET_ITEM_VALIDITY)(void*, const char*, int, int, char **);
-typedef int (*DELETE_ALL_ITEMS_IN_STORAGE)(void*, int, char **);
-typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(void*, int, char **);
+typedef int (*DELETE_ALL_ITEMS_IN_STORAGE)(void*, int, uid_t, char **);
+typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(void*, int, uid_t, char **);
typedef int (*UPDATE_BEGIN)(void);
-typedef int (*UPDATE_END)(void);
-typedef int (*SET_FOLDER_ITEM_VALIDITY)(void*, const char*, int, int, char**);
-typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void*, const char*, char**);
-typedef int (*INSERT_BURST_ITEM)(void *, const char *, int , char **);
+typedef int (*UPDATE_END)(uid_t);
+typedef int (*SET_FOLDER_ITEM_VALIDITY)(void*, const char*, int, int, uid_t, char**);
+typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void*, const char*, uid_t, char**);
+typedef int (*INSERT_BURST_ITEM)(void *, const char *, int, uid_t, char **);
typedef int (*SEND_DIR_UPDATE_NOTI)(void *, const char *, char **);
typedef int (*COUNT_DELETE_ITEMS_IN_FOLDER)(void *, const char *, int *, char **);
msc_unload_functions(void);
int
-msc_connect_db(void ***handle);
+msc_connect_db(void ***handle, uid_t uid);
int
msc_disconnect_db(void ***handle);
int
-msc_validate_item(void **handle, const char *path);
+msc_validate_item(void **handle, const char *path, uid_t uid);
int
-msc_insert_item_batch(void **handle, const char *path);
+msc_insert_item_batch(void **handle, const char *path, uid_t uid);
int
-msc_insert_burst_item(void **handle, const char *path);
+msc_insert_burst_item(void **handle, const char *path, uid_t uid);
bool
-msc_delete_all_items(void **handle, ms_storage_type_t store_type);
+msc_delete_all_items(void **handle, ms_storage_type_t store_type, uid_t uid);
int
-msc_invalidate_all_items(void **handle, ms_storage_type_t store_type);
+msc_invalidate_all_items(void **handle, ms_storage_type_t store_type, uid_t uid);
bool
-msc_delete_invalid_items(void **handle, ms_storage_type_t store_type);
+msc_delete_invalid_items(void **handle, ms_storage_type_t store_type, uid_t uid);
int
-msc_set_folder_validity(void **handle, const char *path, int validity, int recursive);
+msc_set_folder_validity(void **handle, const char *path, int validity, int recursive, uid_t uid);
int
-msc_delete_invalid_items_in_folder(void **handle, const char*path);
+msc_delete_invalid_items_in_folder(void **handle, const char*path, uid_t uid);
int
msc_send_dir_update_noti(void **handle, const char*path);
msc_register_start(void **handle, ms_noti_status_e noti_status, int pid);
void
-msc_register_end(void **handle);
+msc_register_end(void **handle, uid_t uid);
void
msc_validate_start(void **handle);
void
-msc_validate_end(void **handle);
+msc_validate_end(void **handle, uid_t uid);
#endif /*_MEDIA_SCANNER_DB_SVC_H_*/
#include <tzplatform_config.h>
-#define CONFIG_PATH tzplatform_mkpath(TZ_SYS_DATA,"data-media/file-manager-service/plugin-config")
+#define CONFIG_PATH tzplatform_mkpath(TZ_SYS_DATA,"file-manager-service/plugin-config")
#define EXT ".so"
#define EXT_LEN 3
#define MSC_REGISTER_COUNT 100 /*For bundle commit*/
}
int
-msc_connect_db(void ***handle)
+msc_connect_db(void ***handle, uid_t uid)
{
int lib_index;
int ret;
MS_MALLOC(*handle, sizeof (void*) * lib_num);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), &err_msg); /*dlopen*/
+ ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
int
-msc_validate_item(void **handle, const char *path)
+msc_validate_item(void **handle, const char *path, uid_t uid)
{
int lib_index;
int res = MS_MEDIA_ERR_NONE;
char *err_msg = NULL;
ms_storage_type_t storage_type;
- storage_type = ms_get_storage_type_by_full(path);
+ storage_type = ms_get_storage_type_by_full(path,uid);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_msc_check_category(path, lib_index)) {
MSC_DBG_ERR("not exist in %d. insert data", lib_index);
MS_SAFE_FREE(err_msg);
- ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
+ ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
MSC_DBG_ERR("[%s]", path);
}
int
-msc_invalidate_all_items(void **handle, ms_storage_type_t store_type)
+msc_invalidate_all_items(void **handle, ms_storage_type_t store_type , uid_t uid)
{
int lib_index;
int res = MS_MEDIA_ERR_NONE;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, &err_msg); /*dlopen*/
+ ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
int
-msc_insert_item_batch(void **handle, const char *path)
+msc_insert_item_batch(void **handle, const char *path, uid_t uid)
{
int lib_index;
int res = MS_MEDIA_ERR_NONE;
char *err_msg = NULL;
ms_storage_type_t storage_type;
- storage_type = ms_get_storage_type_by_full(path);
+ storage_type = ms_get_storage_type_by_full(path,uid);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_msc_check_category(path, lib_index)) {
- ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
+ ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MSC_DBG_ERR("[%s]", path);
}
int
-msc_insert_burst_item(void **handle, const char *path)
+msc_insert_burst_item(void **handle, const char *path , uid_t uid)
{
int lib_index;
int res = MS_MEDIA_ERR_NONE;
char *err_msg = NULL;
ms_storage_type_t storage_type;
- storage_type = ms_get_storage_type_by_full(path);
+ storage_type = ms_get_storage_type_by_full(path,uid);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_msc_check_category(path, lib_index)) {
- ret = ((INSERT_BURST_ITEM)func_array[lib_index][eINSERT_BURST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
+ ret = ((INSERT_BURST_ITEM)func_array[lib_index][eINSERT_BURST])(handle[lib_index], uid, path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MSC_DBG_ERR("[%s]", path);
}
bool
-msc_delete_all_items(void **handle, ms_storage_type_t store_type)
+msc_delete_all_items(void **handle, ms_storage_type_t store_type, uid_t uid)
{
int lib_index;
int ret = 0;
/* To reset media db when differnet mmc is inserted. */
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DELETE_ALL_ITEMS_IN_STORAGE)func_array[lib_index][eDELETE_ALL])(handle[lib_index], store_type, &err_msg); /*dlopen*/
+ ret = ((DELETE_ALL_ITEMS_IN_STORAGE)func_array[lib_index][eDELETE_ALL])(handle[lib_index], store_type, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
bool
-msc_delete_invalid_items(void **handle, ms_storage_type_t store_type)
+msc_delete_invalid_items(void **handle, ms_storage_type_t store_type, uid_t uid)
{
int lib_index;
int ret;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DELETE_ALL_INVALID_ITMES_IN_STORAGE)func_array[lib_index][eDELETE_INVALID_ITEMS])(handle[lib_index], store_type, &err_msg); /*dlopen*/
+ ret = ((DELETE_ALL_INVALID_ITMES_IN_STORAGE)func_array[lib_index][eDELETE_INVALID_ITEMS])(handle[lib_index], store_type, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
int
-msc_set_folder_validity(void **handle, const char *path, int validity, int recursive)
+msc_set_folder_validity(void **handle, const char *path, int validity, int recursive, uid_t uid)
{
int lib_index;
int ret;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_FOLDER_ITEM_VALIDITY)func_array[lib_index][eSET_FOLDER_VALIDITY])(handle[lib_index], path, validity, recursive,&err_msg); /*dlopen*/
+ ret = ((SET_FOLDER_ITEM_VALIDITY)func_array[lib_index][eSET_FOLDER_VALIDITY])(handle[lib_index], path, validity, recursive, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
int
-msc_delete_invalid_items_in_folder(void **handle, const char*path)
+msc_delete_invalid_items_in_folder(void **handle, const char*path, uid_t uid)
{
int lib_index;
int ret;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DELETE_ALL_INVALID_ITEMS_IN_FOLDER)func_array[lib_index][eDELETE_FOLDER])(handle[lib_index], path, &err_msg); /*dlopen*/
+ ret = ((DELETE_ALL_INVALID_ITEMS_IN_FOLDER)func_array[lib_index][eDELETE_FOLDER])(handle[lib_index], path, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
void
-msc_register_end(void **handle)
+msc_register_end(void **handle, uid_t uid)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((INSERT_ITEM_END)func_array[lib_index][eINSERT_END])(handle[lib_index], &err_msg);/*dlopen*/
+ ret = ((INSERT_ITEM_END)func_array[lib_index][eINSERT_END])(handle[lib_index], uid, &err_msg);/*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((UPDATE_END)func_array[lib_index][eUPDATE_END])();/*dlopen*/
+ ret = ((UPDATE_END)func_array[lib_index][eUPDATE_END])(uid);/*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
void
-msc_validate_end(void **handle)
+msc_validate_end(void **handle, uid_t uid)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ITEM_VALIDITY_END)func_array[lib_index][eSET_VALIDITY_END])(handle[lib_index], &err_msg);/*dlopen*/
+ ret = ((SET_ITEM_VALIDITY_END)func_array[lib_index][eSET_VALIDITY_END])(handle[lib_index], uid, &err_msg);/*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
#include <malloc.h>
#include <pmapi.h>
#include <vconf.h>
+#include <grp.h>
+#include <pwd.h>
#include "media-util.h"
#include "media-server-ipc.h"
#include "media-scanner-socket.h"
#include "media-scanner-scan.h"
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
+
typedef struct msc_scan_data {
char *name;
struct msc_scan_data *next;
dir_path[len -1] = '\0';
}
-static int _msc_dir_scan(void **handle, const char*start_path, ms_storage_type_t storage_type, int scan_type)
+static int _msc_dir_scan(void **handle, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid)
{
DIR *dp = NULL;
GArray *dir_array = NULL;
char *new_path = NULL;
char *current_path = NULL;
char path[MS_FILE_PATH_LEN_MAX] = { 0 };
- int (*scan_function)(void **, const char*) = NULL;
+ int (*scan_function)(void **, const char*, uid_t) = NULL;
/* make new array for storing directory */
dir_array = g_array_new (FALSE, FALSE, sizeof (char*));
continue;
}
/* insert into media DB */
- if (scan_function(handle,path) != MS_MEDIA_ERR_NONE) {
+ if (scan_function(handle,path,uid) != MS_MEDIA_ERR_NONE) {
MSC_DBG_ERR("failed to update db : %d\n", scan_type);
continue;
}
char *start_path = NULL;
ms_storage_type_t storage_type;
- storage_type = ms_get_storage_type_by_full(scan_data->msg);
+ storage_type = ms_get_storage_type_by_full(scan_data->msg,scan_data->uid);
scan_type = scan_data->msg_type;
/*if scan type is not MS_SCAN_NONE, check data in db. */
start_path = strndup(scan_data->msg, scan_data->msg_size);
scan_type = scan_data->msg_type;
- err = _msc_dir_scan(handle, start_path, storage_type, scan_type);
+ err = _msc_dir_scan(handle, start_path, storage_type, scan_type,scan_data->uid);
if (err != MS_MEDIA_ERR_NONE) {
MSC_DBG_ERR("error : %d", err);
}
MSC_DBG_INFO("INVALID");
/*In this case, update just validation record*/
/*update just valid type*/
- err = msc_invalidate_all_items(handle, storage_type);
+ err = msc_invalidate_all_items(handle, storage_type,scan_data->uid);
if (err != MS_MEDIA_ERR_NONE) {
MSC_DBG_ERR("error : %d", err);
}
int err;
int ret;
void **handle = NULL;
- ms_storage_type_t storage_type;
int scan_type;
char *noti_path = NULL;
MSC_DBG_INFO("DIRECTORY SCAN START");
/*connect to media db, if conneting is failed, db updating is stopped*/
- err = msc_connect_db(&handle);
+ err = msc_connect_db(&handle, scan_data->uid);
if (err != MS_MEDIA_ERR_NONE)
continue;
- storage_type = ms_get_storage_type_by_full(scan_data->msg);
scan_type = scan_data->msg_type;
if (scan_type != MS_MSG_DIRECTORY_SCANNING
/*change validity before scanning*/
if (scan_type == MS_MSG_DIRECTORY_SCANNING)
- err = msc_set_folder_validity(handle, scan_data->msg, MS_INVALID, MS_RECURSIVE);
+ err = msc_set_folder_validity(handle, scan_data->msg, MS_INVALID, MS_RECURSIVE,scan_data->uid);
else
- err = msc_set_folder_validity(handle, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE);
+ err = msc_set_folder_validity(handle, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE,scan_data->uid);
if (err != MS_MEDIA_ERR_NONE)
MSC_DBG_ERR("error : %d", err);
/*insert data into media db */
ret = _msc_db_update(handle, scan_data);
-
+
/*call for bundle commit*/
- msc_register_end(handle);
- msc_validate_end(handle);
+ msc_register_end(handle,scan_data->uid);
+ msc_validate_end(handle,scan_data->uid);
if (ret == MS_MEDIA_ERR_NONE) {
MSC_DBG_INFO("working normally");
MSC_DBG_INFO("delete count %d", count);
MSC_DBG_INFO("insert count %d", insert_count);
- msc_delete_invalid_items_in_folder(handle, scan_data->msg);
+ msc_delete_invalid_items_in_folder(handle, scan_data->msg,scan_data->uid);
if ( !(count == 0 && insert_count == 0)) {
msc_send_dir_update_noti(handle, noti_path);
goto NEXT;
}
- storage_type = ms_get_storage_type_by_full(scan_data->msg);
+ storage_type = ms_get_storage_type_by_full(scan_data->msg,scan_data->uid);
MSC_DBG_INFO("%d", storage_type);
/*connect to media db, if conneting is failed, db updating is stopped*/
- err = msc_connect_db(&handle);
+ err = msc_connect_db(&handle,scan_data->uid);
if (err != MS_MEDIA_ERR_NONE)
continue;
/*Delete all data before full scanning*/
if (scan_type == MS_MSG_STORAGE_ALL) {
- res = msc_delete_all_items(handle, storage_type);
+ res = msc_delete_all_items(handle, storage_type,scan_data->uid);
if (res != true) {
MSC_DBG_ERR("msc_delete_all_record fails");
}
} else if (scan_type == MS_MSG_STORAGE_PARTIAL) {
- err = msc_invalidate_all_items(handle, storage_type);
+ err = msc_invalidate_all_items(handle, storage_type,scan_data->uid);
if (err != MS_MEDIA_ERR_NONE)
MSC_DBG_ERR("error : %d", err);
}
ret = _msc_db_update(handle, scan_data);
/*call for bundle commit*/
- msc_register_end(handle);
+ msc_register_end(handle,scan_data->uid);
if (scan_type == MS_MSG_STORAGE_PARTIAL) {
/*disable bundle commit*/
- msc_validate_end(handle);
+ msc_validate_end(handle,scan_data->uid);
if (ret == MS_MEDIA_ERR_NONE) {
MSC_DBG_INFO("working normally");
- msc_delete_invalid_items(handle, storage_type);
+ msc_delete_invalid_items(handle, storage_type,scan_data->uid);
}
}
}
/*disconnect form media db*/
- if (handle) msc_disconnect_db(&handle);
+ if (handle) msc_disconnect_db(&handle);
NEXT:
/*Active flush */
int ret;
void **handle = NULL;
ms_msg_type_e current_msg = MS_MSG_MAX;
- int (*insert_function)(void **, const char*) = NULL;
+ int (*insert_function)(void **, uid_t, const char*) = NULL;
/*create array for processing overlay data*/
register_array = g_array_new (FALSE, FALSE, sizeof (ms_comm_msg_s *));
}
/* connect to media db, if conneting is failed, db updating is stopped */
- err = msc_connect_db(&handle);
+ err = msc_connect_db(&handle,register_data->uid);
if (err != MS_MEDIA_ERR_NONE)
goto FREE_RESOURCE;
}
/* insert to db */
- err = insert_function(handle, insert_path);
+ err = insert_function(handle, insert_path, register_data->uid);
if (power_off) {
MSC_DBG_INFO("power off");
/*call for bundle commit*/
- msc_register_end(handle);
+ msc_register_end(handle, register_data->uid);
goto _POWEROFF;
}
}
/*call for bundle commit*/
- msc_register_end(handle);
+ msc_register_end(handle, register_data->uid);
/*disconnect form media db*/
if (handle) msc_disconnect_db(&handle);
return TRUE;
}
- MSC_DBG_INFO("receive msg from [%d] %d, %s", recv_msg->pid, recv_msg->msg_type, recv_msg->msg);
+ MSC_DBG_INFO("receive msg from [%d] %d, %s, uid %d", recv_msg->pid, recv_msg->msg_type, recv_msg->msg, recv_msg->uid);
/* copy from recived data */
req_num = recv_msg->msg_type;
send_msg.pid = scan_data->pid;
send_msg.result = result;
send_msg.msg_size = strlen(scan_data->msg);
+ send_msg.uid = scan_data->uid;
strncpy(send_msg.msg, scan_data->msg, send_msg.msg_size);
ret = ms_ipc_send_msg_to_server(sockfd, MS_SCAN_COMM_PORT, &send_msg, NULL);
#include "media-common-types.h"
-typedef int (*CONNECT)(void**, char **);
+typedef int (*CONNECT)(void**, uid_t, char **);
typedef int (*DISCONNECT)(void*, char **);
-typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, char **);
+typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, uid_t,char **);
int
ms_load_functions(void);
ms_unload_functions(void);
int
-ms_connect_db(void ***handle);
+ms_connect_db(void ***handle, uid_t uid);
int
ms_disconnect_db(void ***handle);
int
-ms_invalidate_all_items(void **handle, ms_storage_type_t store_type);
+ms_invalidate_all_items(void **handle, ms_storage_type_t store_type, uid_t uid);
#endif /*_MEDIA_SERVER_DB_SVC_H_*/
#include <tzplatform_config.h>
-#define CONFIG_PATH tzplatform_mkpath(TZ_SYS_DATA,"data-media/file-manager-service/plugin-config")
+#define CONFIG_PATH tzplatform_mkpath(TZ_SYS_DATA,"file-manager-service/plugin-config")
#define EXT ".so"
#define EXT_LEN 3
}
int
-ms_connect_db(void ***handle)
+ms_connect_db(void ***handle, uid_t uid)
{
int lib_index;
int ret;
MS_MALLOC(*handle, sizeof (void*) * lib_num);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), &err_msg); /*dlopen*/
+ ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), uid, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
}
int
-ms_invalidate_all_items(void **handle, ms_storage_type_t store_type)
+ms_invalidate_all_items(void **handle, ms_storage_type_t store_type, uid_t uid)
{
int lib_index;
int res = MS_MEDIA_ERR_NONE;
char *err_msg = NULL;
MS_DBG("");
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, &err_msg); /*dlopen*/
+ ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, uid, &err_msg); /*dlopen*/
if (ret != 0) {
MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
GMainContext *context = NULL;
MediaDBHandle *db_handle = NULL;
- /* Connect Media DB*/
- if(media_db_connect(&db_handle) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("Failed to connect DB\n");
- return FALSE;
- }
/* Create Socket*/
ret = ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_DB_UPDATE_PORT, &sockfd);
if(ret != MS_MEDIA_ERR_NONE) {
- /* Disconnect DB*/
- media_db_disconnect(db_handle);
MS_DBG_ERR("Failed to create socket\n");
return FALSE;
ret = ms_ipc_create_server_socket(MS_PROTOCOL_TCP, MS_DB_BATCH_UPDATE_PORT, &tcp_sockfd);
#endif
if(ret != MS_MEDIA_ERR_NONE) {
- /* Disconnect DB*/
- media_db_disconnect(db_handle);
close(sockfd);
MS_DBG_ERR("Failed to create socket\n");
return FALSE;
g_io_channel_shutdown(channel, FALSE, NULL);
g_io_channel_unref(channel);
- /* Disconnect DB*/
- media_db_disconnect(db_handle);
/*close socket*/
close(sockfd);
#include <malloc.h>
#include <vconf.h>
#include <heynoti.h>
+#include <sys/stat.h>
#include "media-util.h"
#include "media-common-utils.h"
}
/*connect to media db, if conneting is failed, db updating is stopped*/
- ms_connect_db(&handle);
+ ms_connect_db(&handle,tzplatform_getuid(TZ_USER_NAME));
/*update just valid type*/
- if (ms_invalidate_all_items(handle, MS_STORAGE_EXTERNAL) != MS_MEDIA_ERR_NONE)
+ if (ms_invalidate_all_items(handle, MS_STORAGE_EXTERNAL, tzplatform_getuid(TZ_USER_NAME)) != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("ms_change_valid_type fail");
/*disconnect form media db*/
return;
}
+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);
+}
int main(int argc, char **argv)
{
_ms_new_global_variable();
/*prepare socket*/
+ /* create dir socket */
+ _mkdir("/var/run/media-server",S_IRWXU | S_IRWXG | S_IRWXO);
+
/* Create and bind new UDP socket */
if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_SCANNER_PORT, &sockfd)
!= MS_MEDIA_ERR_NONE) {
sleep(1);
}
- _db_clear();
-
- ms_send_storage_scan_request(MS_STORAGE_INTERNAL, MS_SCAN_PART);
-
if (ms_is_mmc_inserted()) {
if (!ms_drm_insert_ext_memory())
MS_DBG_ERR("ms_drm_insert_ext_memory failed");
* @version 1.0
* @brief
*/
+
#include <arpa/inet.h>
#include <sys/types.h>
#ifdef _USE_UDS_SOCKET_
return TRUE;
}
- MS_DBG("receive msg from [%d] %d, %s", recv_msg.pid, recv_msg.msg_type, recv_msg.msg);
+ MS_DBG("receive msg from [%d] %d, %s, uid %d", recv_msg.pid, recv_msg.msg_type, recv_msg.msg, recv_msg.uid);
if (recv_msg.msg_size > 0 && recv_msg.msg_size < MS_FILE_PATH_LEN_MAX) {
msg_size = recv_msg.msg_size;
scan_msg.msg_type = req_num;
scan_msg.pid = pid;
scan_msg.msg_size = msg_size;
+ scan_msg.uid = recv_msg.uid;
ms_strcopy(scan_msg.msg, path_size, "%s", recv_msg.msg);
g_mutex_unlock(scanner_mutex);
.msg = {0},
};
+ scan_msg.uid = tzplatform_getuid(TZ_USER_NAME);
+
/* msg_type */
switch (scan_type) {
case MS_SCAN_PART:
int send_msg = MS_MEDIA_ERR_NONE;
int sockfd = MS_SOCK_NOT_ALLOCATE;
int ret = MS_MEDIA_ERR_NONE;
- MediaDBHandle *db_handle = (MediaDBHandle *)data;
+ MediaDBHandle *db_handle = NULL;
ms_comm_msg_s msg;
char * sql_query = NULL;
return TRUE;
}
+ media_db_connect(&db_handle, recv_msg.uid);
+
sql_query = strndup(recv_msg.msg, recv_msg.msg_size);
if (sql_query != NULL) {
ret = media_db_update_db(db_handle, sql_query);
ms_ipc_send_msg_to_client(sockfd, &msg, &client_addr);
+ media_db_disconnect(db_handle);
+
/*Active flush */
malloc_trim(0);
int recv_msg_size = -1;
int ret = MS_MEDIA_ERR_NONE;
char * sql_query = NULL;
- MediaDBHandle *db_handle = (MediaDBHandle *)data;
+ MediaDBHandle *db_handle = NULL;
sock = g_io_channel_unix_get_fd(src);
if (sock < 0) {
sql_query = strndup(recv_msg.msg, recv_msg.msg_size);
if (sql_query != NULL) {
+ media_db_connect(&db_handle, recv_msg.uid);
if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_START) {
ret = media_db_update_db_batch_start(sql_query);
} else if(recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_END) {
} else {
}
+ media_db_disconnect(db_handle);
MS_SAFE_FREE(sql_query);
send_msg = ret;
} thumbRequest;
#ifdef _USE_UDS_SOCKET_
-extern char MEDIA_IPC_PATH[][50];
+extern char MEDIA_IPC_PATH[][70];
+
#endif
gboolean _ms_thumb_agent_start_jobs(gpointer data)