upload tizen1.0 source
[framework/multimedia/libmedia-service.git] / src / common / media-svc-util.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include "uuid.h"
23 #include <stdlib.h>
24
25 char *_media_info_generate_uuid(void)
26 {
27         uuid_t uuid_value;
28         static char uuid_unparsed[50];  
29
30         uuid_generate(uuid_value);
31         uuid_unparse(uuid_value, uuid_unparsed);
32
33         //mediainfo_dbg("UUID : %s", uuid_unparsed);
34         return uuid_unparsed;
35 }
36
37 int _media_svc_check_escape_char(char ch)
38 {
39         int i;
40         char escape_char[3] = {'%', '_' ,'#'};
41
42         for (i = 0; i < 3; i++) {
43                 if (ch == escape_char[i]) {
44                         return 1;
45                 }
46         }
47
48         return 0;
49 }
50
51 char *_media_svc_escape_str(char *input, int len)
52 {
53         int i = 0;
54         int j = 0;
55         char *result = NULL;
56         
57         result = (char*)malloc(len * 2 * sizeof(char) + 1);
58         if (result == NULL) {
59                 return NULL;
60         }
61
62         for (i = 0; i < len; i++, j++) {
63                 if (input[i] == '\0') break;
64
65                 if (_media_svc_check_escape_char(input[i])) {
66                         result[j] = '#';
67                         result[++j] = input[i];
68                 } else {
69                         result[j] = input[i];
70                 }
71         }
72
73         result[j] = '\0';
74         
75         return result;
76 }
77