1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* libmedia-thumbnail
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Hyunjun Ko <zzoon.ko@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <media-util.h>
#include "media-thumb-debug.h"
#include "media-thumb-internal.h"
int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid)
{
char *hash_name = NULL;
char file_ext[255] = { 0 };
char *get_path = NULL;
int ret_len = 0;
ms_user_storage_type_e storage_type = -1;
int ret = MS_MEDIA_ERR_NONE;
if (file_full_path == NULL || thumb_hash_path == NULL || max_thumb_path <= 0) {
thumb_err("file_full_path==NULL || thumb_hash_path == NULL || max_thumb_path <= 0");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
_media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext));
ret = ms_user_get_storage_type(uid, file_full_path, &storage_type);
if ((ret != MS_MEDIA_ERR_NONE) || ((storage_type != MS_USER_STORAGE_INTERNAL) && (storage_type != MS_USER_STORAGE_EXTERNAL))) {
thumb_err_slog("origin path(%s) is invalid. err : [%d] storage_type [%d]", file_full_path, ret, storage_type);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
hash_name = _media_thumb_generate_hash_name(file_full_path);
if (hash_name == NULL) {
thumb_err("_media_thumb_generate_hash_name fail");
return MS_MEDIA_ERR_INTERNAL;
}
ret = ms_user_get_root_thumb_store_path(uid, &get_path);
if (get_path != NULL) {
if (strcasecmp(file_ext, "PNG") == 0)
ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.png", get_path, file_ext, hash_name);
else
ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", get_path, file_ext, hash_name);
}
SAFE_FREE(get_path);
if ((ret_len < 0) || (ret_len > (int)max_thumb_path)) {
thumb_err("invalid hash path ret_len[%d]", ret_len);
return MS_MEDIA_ERR_INTERNAL;
}
return MS_MEDIA_ERR_NONE;
}
|