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 !");
97 struct passwd *userinfo = getpwuid(uid);
98 if(userinfo == NULL) {
99 MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
102 grpinfo = getgrnam("users");
103 if(grpinfo == NULL) {
104 MS_DBG_ERR("getgrnam(users) returns NULL !");
107 // Compare git_t type and not group name
108 if (grpinfo->gr_gid != userinfo->pw_gid) {
109 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
112 asprintf(&result_psswd, "%s", userinfo->pw_dir);
119 ms_get_storage_type_by_full(const char *path, uid_t uid)
122 char * user_path = NULL;
127 user_path = __media_get_path(uid);
128 length_path = strlen(user_path);
130 if (strncmp(path, user_path, length_path) == 0) {
131 return MS_STORAGE_INTERNAL;
132 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
133 return MS_STORAGE_EXTERNAL;
136 return MS_MEDIA_ERR_INVALID_PATH;
141 ms_strappend(char *res, const int size, const char *pattern,
142 const char *str1, const char *str2)
145 int real_size = size - 1;
147 if (!res ||!pattern || !str1 ||!str2 )
148 return MS_MEDIA_ERR_INVALID_PARAMETER;
150 if (real_size < (strlen(str1) + strlen(str2)))
151 return MS_MEDIA_ERR_INVALID_PARAMETER;
153 len = snprintf(res, real_size, pattern, str1, str2);
155 return MS_MEDIA_ERR_INVALID_PARAMETER;
160 return MS_MEDIA_ERR_NONE;
164 ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
167 int real_size = size;
169 if (!res || !pattern || !str1) {
170 MS_DBG_ERR("parameta is invalid");
171 return MS_MEDIA_ERR_INVALID_PARAMETER;
174 if (real_size < strlen(str1)) {
175 MS_DBG_ERR("size is wrong");
176 return MS_MEDIA_ERR_INVALID_PARAMETER;
179 len = snprintf(res, real_size, pattern, str1);
181 MS_DBG_ERR("snprintf failed");
182 return MS_MEDIA_ERR_INVALID_PARAMETER;
187 return MS_MEDIA_ERR_NONE;
191 ms_config_get_int(const char *key, int *value)
195 if (!key || !value) {
196 MS_DBG_ERR("Arguments key or value is NULL");
200 err = vconf_get_int(key, value);
206 MS_DBG_ERR("Unexpected error code: %d", err);
212 ms_config_set_int(const char *key, int value)
217 MS_DBG_ERR("Arguments key is NULL");
221 err = vconf_set_int(key, value);
227 MS_DBG_ERR("Unexpected error code: %d", err);
233 ms_config_get_str(const char *key, char *value)
236 if (!key || !value) {
237 MS_DBG_ERR("Arguments key or value is NULL");
241 res = vconf_get_str(key);
243 strncpy(value, res, strlen(res) + 1);
252 ms_config_set_str(const char *key, const char *value)
256 if (!key || !value) {
257 MS_DBG_ERR("Arguments key or value is NULL");
261 err = vconf_set_str(key, value);
265 MS_DBG_ERR("fail to vconf_set_str %d", err);
271 ms_config_get_bool(const char *key, int *value)
275 if (!key || !value) {
276 MS_DBG_ERR("Arguments key or value is NULL");
280 err = vconf_get_bool(key, value);
286 MS_DBG_ERR("Unexpected error code: %d", err);