4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@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.
25 #include <media-util-err.h>
28 static const char ACCEPTABLE_URI_CHARS[96] = {
29 /* ! " # $ % & ' ( ) * + , - . / */
30 0x00, 0x3F, 0x20, 0x20, 0x28, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x2A,
31 0x28, 0x3F, 0x3F, 0x1C,
32 /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
33 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20,
34 0x20, 0x2C, 0x20, 0x20,
35 /* @ A B C D E F G H I J K L M N O */
36 0x38, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
37 0x3F, 0x3F, 0x3F, 0x3F,
38 /* P Q R S T U V W X Y Z [ \ ] ^ _ */
39 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20,
40 0x20, 0x20, 0x20, 0x3F,
41 /* ` a b c d e f g h i j k l m n o */
42 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
43 0x3F, 0x3F, 0x3F, 0x3F,
44 /* p q r s t u v w x y z { | } ~ DEL */
45 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20,
46 0x20, 0x20, 0x3F, 0x20
49 char *_media_thumb_generate_hash_name(const char *file)
53 static char md5out[(2 * MD5_HASHBYTES) + 1];
54 unsigned char hash[MD5_HASHBYTES];
55 static const char hex[] = "0123456789abcdef";
59 const unsigned char *c;
66 length = 3 * strlen(file) + 9;
68 memset(md5out, 0, sizeof(md5out));
70 #define _check_uri_char(c) \
71 ((c) >= 32 && (c) < 128 && (ACCEPTABLE_URI_CHARS[(c) - 32] & 0x08))
78 strncpy(uri, "file://", length);
79 uri[length - 1] = '\0';
80 t = uri + sizeof("file://") - 1;
82 for (c = (const unsigned char *)file; *c != '\0'; c++) {
83 if (!_check_uri_char(*c)) {
92 #undef _check_uri_char
94 memset(&ctx, 0x00, sizeof(MD5_CTX));
96 media_thumb_MD5Init(&ctx);
97 media_thumb_MD5Update(&ctx, (unsigned char const *)uri, (unsigned)strlen(uri));
98 media_thumb_MD5Final(hash, &ctx);
100 for (n = 0; n < MD5_HASHBYTES; n++) {
101 md5out[2 * n] = hex[hash[n] >> 4];
102 md5out[2 * n + 1] = hex[hash[n] & 0x0f];
104 md5out[2 * n] = '\0';