Tizen 2.1 base
[framework/multimedia/media-server.git] / common / scanner / media-scanner-drm.c
1 /*
2  *  Media Server
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Yong Yeon Kim <yy9875.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 /**
23  * This file defines api utilities of contents manager engines.
24  *
25  * @file                media-server-drm.c
26  * @author      Yong Yeon Kim(yy9875.kim@samsung.com)
27  * @version     1.0
28  * @brief       This file implements main database operation.
29  */
30 #include <drm_client_types.h>
31 #include <drm_client.h>
32
33 #include "media-util.h"
34
35 #include "media-scanner-dbg.h"
36 #include "media-server-types.h"
37 #include "media-scanner-drm.h"
38
39 bool
40 msc_is_drm_file(const char *path)
41 {
42         int ret;
43         drm_bool_type_e is_drm_file = DRM_UNKNOWN;
44
45         ret = drm_is_drm_file(path,&is_drm_file);
46         if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
47                 return true;
48
49         return false;
50 }
51
52 int
53 msc_get_mime_in_drm_info(const char *path, char *mime)
54 {
55         int ret;
56         drm_content_info_s contentInfo;
57
58         if (path == NULL || mime == NULL)
59                 return MS_MEDIA_ERR_INVALID_PARAMETER;
60
61         memset(&contentInfo,0x0,sizeof(drm_content_info_s));
62         ret = drm_get_content_info(path, &contentInfo);
63         if (ret != DRM_RETURN_SUCCESS) {
64                 MSC_DBG_ERR("drm_svc_get_content_info() failed");
65                 MSC_DBG_ERR("%s [%d]", path, ret);
66                 return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
67         }
68
69         strncpy(mime, contentInfo.mime_type, 100);
70
71         return MS_MEDIA_ERR_NONE;
72 }
73
74 int
75 msc_drm_register(const char* path)
76 {
77         int res = MS_MEDIA_ERR_NONE;
78         int ret;
79
80         ret = drm_process_request(DRM_REQUEST_TYPE_REGISTER_FILE, (void *)path, NULL);
81         if (ret != DRM_RETURN_SUCCESS) {
82                 MSC_DBG_ERR("drm_svc_register_file error : %d %s", ret, path);
83                 res = MS_MEDIA_ERR_DRM_REGISTER_FAIL;
84         }
85
86         return res;
87 }
88
89 void
90 msc_drm_unregister(const char* path)
91 {
92         int ret;
93
94         ret = drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_FILE, (void *)path, NULL);
95         if (ret != DRM_RETURN_SUCCESS)
96                 MSC_DBG_ERR("drm_process_request error : %d", ret);
97 }
98
99 void
100 msc_drm_unregister_all(void)
101 {
102         if (drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_ALL_FILES , NULL, NULL) == DRM_RETURN_SUCCESS)
103                 MSC_DBG_INFO("drm_svc_unregister_all_contents OK");
104 }
105
106 bool
107 msc_drm_insert_ext_memory(void)
108 {
109         if (drm_process_request(DRM_REQUEST_TYPE_INSERT_EXT_MEMORY, NULL, NULL) != DRM_RETURN_SUCCESS)
110                 return false;
111
112         return true;
113 }
114
115 bool
116 msc_drm_extract_ext_memory(void)
117 {
118         if (drm_process_request(DRM_REQUEST_TYPE_EXTRACT_EXT_MEMORY , NULL, NULL)  != DRM_RETURN_SUCCESS)
119                 return false;
120
121         return true;
122 }
123