#endif
static char *g_old_path = NULL;
+#define TIZEN_USER_CONTENT_PATH tzplatform_getenv(TZ_USER_CONTENT)
int _media_util_check_file_exist(const char *path)
{
return MEDIA_CONTENT_ERROR_NONE;
}
-int _media_content_replace_path_in_condition(const char *condition, char *replace_condition)
+int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ char old_condition[MAX_QUERY_SIZE] = {0, };
+ char new_condition[MAX_QUERY_SIZE] = {0, };
+ char *find = NULL;
+ unsigned int str_len = 0;
- if (!STRING_VALID(g_old_path)) {
- ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path);
+ char *find_str = NULL;
+ char *to_replace_str = NULL;
+
+ if (replace == TRUE) { //change User session path to System session path
+ ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &find_str);
if (ret != STORAGE_ERROR_NONE) {
media_content_error("storage_get_directory failed");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
}
- }
-
- media_content_sec_debug("Old condition[%s]", condition);
- if (((strstr(condition, "PATH") != NULL) || (strstr(condition, "path") != NULL)) && (strstr(condition, g_old_path) != NULL)) {
- char *cond = strdup(condition);
- char *repl_cond_ptr = replace_condition;
- char *cond_ptr = cond;
- if (cond_ptr == NULL) {
- media_content_error("memory allocation failed");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ to_replace_str = g_strdup(TIZEN_USER_CONTENT_PATH);
+ if (!STRING_VALID(to_replace_str)) {
+ media_content_error("Get TZ_USER_CONTENT failed");
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
}
- while (*cond_ptr != '\0') {
- if (strlen(cond_ptr) < strlen(g_old_path)) {
- memcpy(repl_cond_ptr, cond_ptr, strlen(cond_ptr));
- break;
- }
- /* replace path only and keep other condition */
- if (memcmp(cond_ptr, g_old_path, strlen(g_old_path)) == 0) {
- memcpy(repl_cond_ptr, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT)));
- cond_ptr += strlen(g_old_path);
- repl_cond_ptr += strlen(tzplatform_getenv(TZ_USER_CONTENT));
- } else {
- *repl_cond_ptr = *cond_ptr;
- cond_ptr++;
- repl_cond_ptr++;
- }
- }
- SAFE_FREE(cond);
} else {
- snprintf(replace_condition, MAX_QUERY_SIZE, "%s", condition);
- }
-
- if (!STRING_VALID(replace_condition)) {
- media_content_error("replace failed");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
- }
-
- media_content_sec_debug("repl cond[%s]", replace_condition);
-
- return MEDIA_CONTENT_ERROR_NONE;
-}
-
-int _media_content_rollback_path_in_condition(const char *condition, char *replace_condition)
-{
- int ret = MEDIA_CONTENT_ERROR_NONE;
+ find_str = g_strdup(TIZEN_USER_CONTENT_PATH);
+ if (!STRING_VALID(find_str)) {
+ media_content_error("Get TZ_USER_CONTENT failed");
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
- if (!STRING_VALID(g_old_path)) {
- ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path);
+ ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &to_replace_str);
if (ret != STORAGE_ERROR_NONE) {
media_content_error("storage_get_directory failed");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
}
}
+ memset(old_condition, 0, sizeof(old_condition));
+ memset(new_condition, 0, sizeof(new_condition));
+
media_content_sec_debug("Old condition[%s]", condition);
- if (((strstr(condition, "PATH") != NULL) || (strstr(condition, "path") != NULL)) && (strstr(condition, tzplatform_getenv(TZ_USER_CONTENT)) != NULL)) {
- char *cond = strdup(condition);
- char *repl_cond_ptr = replace_condition;
- char *cond_ptr = cond;
- if (cond_ptr == NULL) {
- media_content_error("memory allocation failed");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
- }
- while (*cond_ptr != '\0') {
- if (strlen(cond_ptr) < strlen(tzplatform_getenv(TZ_USER_CONTENT))) {
- memcpy(repl_cond_ptr, cond_ptr, strlen(cond_ptr));
- break;
- }
- /* replace path only and keep other condition */
- if (memcmp(cond_ptr, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))) == 0) {
- memcpy(repl_cond_ptr, g_old_path, strlen(g_old_path));
- cond_ptr += strlen(tzplatform_getenv(TZ_USER_CONTENT));
- repl_cond_ptr += strlen(g_old_path);
- } else {
- *repl_cond_ptr = *cond_ptr;
- cond_ptr++;
- repl_cond_ptr++;
- }
+ if (!SAFE_STRLCPY(new_condition, condition, sizeof(new_condition))) {
+ media_content_error("MEDIA_CONTENT_ERROR_INVALID_OPERATION(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_OPERATION);
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ find = strstr(new_condition, find_str);
+
+ while (find != NULL) {
+ str_len = find - new_condition;
+
+ memset(old_condition, 0, sizeof(old_condition));
+ if (!SAFE_STRLCPY(old_condition, new_condition, sizeof(old_condition))) {
+ media_content_error("MEDIA_CONTENT_ERROR_INVALID_OPERATION(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_OPERATION);
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
}
- SAFE_FREE(cond);
- } else {
- snprintf(replace_condition, MAX_QUERY_SIZE, "%s", condition);
+ memset(new_condition, 0, sizeof(new_condition));
+
+ snprintf(new_condition, str_len + 1, "%s", old_condition);
+
+ SAFE_STRLCAT(new_condition, to_replace_str, sizeof(new_condition));
+ SAFE_STRLCAT(new_condition, old_condition + str_len + strlen(find_str), sizeof(new_condition));
+
+ find = strstr(new_condition, find_str);
}
+ if (!SAFE_STRLCPY(replace_condition, new_condition, MAX_QUERY_SIZE)) {
+ media_content_error("MEDIA_CONTENT_ERROR_INVALID_OPERATION(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_OPERATION);
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ media_content_sec_debug("repl cond[%s]", replace_condition);
+
if (!STRING_VALID(replace_condition)) {
media_content_error("replace failed");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ goto ERROR;
}
- media_content_sec_debug("repl cond[%s]", replace_condition);
+ERROR:
+ SAFE_FREE(find_str);
+ SAFE_FREE(to_replace_str);
- return MEDIA_CONTENT_ERROR_NONE;
+ return ret;
}
int _media_content_replace_path(const char *path, char *replace_path)