4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "media-util.h"
30 #include "media-server-ipc.h"
31 #include "media-common-dbg.h"
32 #include "media-common-utils.h"
36 #define MILLION 1000000L
37 struct timeval g_mmc_start_time;
38 struct timeval g_mmc_end_time;
41 #define MS_DRM_CONTENT_TYPE_LENGTH 100
42 #define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
46 ms_check_start_time(struct timeval *start_time)
48 gettimeofday(start_time, NULL);
52 ms_check_end_time(struct timeval *end_time)
54 gettimeofday(end_time, NULL);
58 ms_check_time_diff(struct timeval *start_time, struct timeval *end_time)
63 time.tv_sec = end_time->tv_sec - start_time->tv_sec;
64 time.tv_usec = end_time->tv_usec - start_time->tv_usec;
65 difftime = MILLION * time.tv_sec + time.tv_usec;
66 MS_DBG("The function_to_time took %ld microseconds or %f seconds.",
67 difftime, difftime / (double)MILLION);
72 ms_is_mmc_inserted(void)
75 ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &data);
76 if (data != VCONFKEY_SYSMAN_MMC_MOUNTED) {
82 static char* __media_get_path(uid_t uid)
84 char *result_psswd = NULL;
85 struct group *grpinfo = NULL;
88 result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
89 grpinfo = getgrnam("users");
91 MS_DBG_ERR("getgrnam(users) returns NULL !");
92 MS_SAFE_FREE(result_psswd);
98 struct passwd *userinfo = getpwuid(uid);
99 if(userinfo == NULL) {
100 MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
103 grpinfo = getgrnam("users");
104 if(grpinfo == NULL) {
105 MS_DBG_ERR("getgrnam(users) returns NULL !");
108 // Compare git_t type and not group name
109 if (grpinfo->gr_gid != userinfo->pw_gid) {
110 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
113 asprintf(&result_psswd, "%s", userinfo->pw_dir);
120 ms_get_storage_type_by_full(const char *path, uid_t uid)
123 char * user_path = NULL;
128 user_path = __media_get_path(uid);
129 length_path = strlen(user_path);
131 if (strncmp(path, user_path, length_path) == 0) {
132 return MS_STORAGE_INTERNAL;
133 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
134 return MS_STORAGE_EXTERNAL;
137 return MS_MEDIA_ERR_INVALID_PATH;
142 ms_strappend(char *res, const int size, const char *pattern,
143 const char *str1, const char *str2)
146 int real_size = size - 1;
148 if (!res ||!pattern || !str1 ||!str2 )
149 return MS_MEDIA_ERR_INVALID_PARAMETER;
151 if (real_size < (strlen(str1) + strlen(str2)))
152 return MS_MEDIA_ERR_INVALID_PARAMETER;
154 len = snprintf(res, real_size, pattern, str1, str2);
156 return MS_MEDIA_ERR_INVALID_PARAMETER;
161 return MS_MEDIA_ERR_NONE;
165 ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
168 int real_size = size;
170 if (!res || !pattern || !str1) {
171 MS_DBG_ERR("parameta is invalid");
172 return MS_MEDIA_ERR_INVALID_PARAMETER;
175 if (real_size < strlen(str1)) {
176 MS_DBG_ERR("size is wrong");
177 return MS_MEDIA_ERR_INVALID_PARAMETER;
180 len = snprintf(res, real_size, pattern, str1);
182 MS_DBG_ERR("snprintf failed");
183 return MS_MEDIA_ERR_INVALID_PARAMETER;
188 return MS_MEDIA_ERR_NONE;
192 ms_config_get_int(const char *key, int *value)
196 if (!key || !value) {
197 MS_DBG_ERR("Arguments key or value is NULL");
201 err = vconf_get_int(key, value);
207 MS_DBG_ERR("Unexpected error code: %d", err);
213 ms_config_set_int(const char *key, int value)
218 MS_DBG_ERR("Arguments key is NULL");
222 err = vconf_set_int(key, value);
228 MS_DBG_ERR("Unexpected error code: %d", err);
234 ms_config_get_str(const char *key, char *value)
237 if (!key || !value) {
238 MS_DBG_ERR("Arguments key or value is NULL");
242 res = vconf_get_str(key);
244 strncpy(value, res, strlen(res) + 1);
253 ms_config_set_str(const char *key, const char *value)
257 if (!key || !value) {
258 MS_DBG_ERR("Arguments key or value is NULL");
262 err = vconf_set_str(key, value);
266 MS_DBG_ERR("fail to vconf_set_str %d", err);
272 ms_config_get_bool(const char *key, int *value)
276 if (!key || !value) {
277 MS_DBG_ERR("Arguments key or value is NULL");
281 err = vconf_get_bool(key, value);
287 MS_DBG_ERR("Unexpected error code: %d", err);