2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "MsgDrmWrapper.h"
19 #include "MsgUtilFile.h"
27 #include <sys/types.h>
33 #include <drm_client_types.h>
34 #include <drm_client.h>
36 #define MSG_MAX_DRM_FILE_PATH MSG_FILEPATH_LEN_MAX
38 bool MsgDrmRegisterFile(MSG_DRM_OPENMODE eMode, char *pBuffer, int nSize)
40 if (eMode == MSG_MODE_STREAM) {
41 MSG_DEBUG("Fail(eMode == MSG_MODE_STREAM)");
45 if (pBuffer == NULL) {
46 MSG_DEBUG("[Error] pBuffer is NULL");
50 MSG_DEBUG("buffer = %s, nSize = %d", pBuffer, nSize);
52 drm_bool_type_e isDrm;
53 int eDRMResult = drm_is_drm_file(pBuffer, &isDrm);
55 if (eDRMResult != DRM_RETURN_SUCCESS || isDrm != DRM_TRUE) {
56 MSG_DEBUG("file is not drm file");
60 drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_FILE;
62 eDRMResult = drm_process_request(request_type, pBuffer, NULL);
63 if (DRM_RETURN_SUCCESS != eDRMResult) {
64 MSG_DEBUG("drm_process_request is failed : %d", eDRMResult);
71 bool MsgDrmUnregisterFile(char *szFilename)
73 if (szFilename == NULL) {
74 MSG_DEBUG("[Error] szFilename is NULL");
78 MSG_DEBUG("szFilename = %s", szFilename);
80 drm_request_type_e request_type = DRM_REQUEST_TYPE_UNREGISTER_FILE;
82 int eDRMResult = drm_process_request(request_type, szFilename, NULL); // Unregister a DCF file
83 if (DRM_RETURN_SUCCESS != eDRMResult) {
84 MSG_DEBUG("drm_process_request : %d", eDRMResult);
91 bool MsgDrmIsDrmFile(const char *szFilePath)
93 drm_bool_type_e isDrm;
94 int eDRMResult = drm_is_drm_file(szFilePath, &isDrm);
96 if (eDRMResult != DRM_RETURN_SUCCESS || isDrm != DRM_TRUE) {
97 MSG_DEBUG("file is not drm file");
104 /*Added to convert the .dm files in to .dcf files since our platform supports only .dcf :: Start*/
105 bool MsgDrmConvertDmtoDcfType(char *inputFile, char *outputFile)
110 bool MsgDrmGetDrmType(const char *szFileName, MSG_DRM_TYPE *eDRMType)
112 if (szFileName == NULL || eDRMType == NULL) {
113 MSG_DEBUG("Param is NULL");
117 drm_file_type_e file_type;
118 int result = drm_get_file_type(szFileName, &file_type);
119 if (result != DRM_RETURN_SUCCESS) {
120 MSG_DEBUG("drm_get_file_type is failed %d", result);
124 if (file_type == DRM_TYPE_OMA_V1) {
125 drm_file_info_s drmInfo;
126 bzero(&drmInfo, sizeof(drm_file_info_s));
127 int eDRMResult = drm_get_file_info(szFileName, &drmInfo);
128 if (DRM_RETURN_SUCCESS != eDRMResult) {
129 MSG_DEBUG("drm_get_file_info is Fail eDRMResult = %d", eDRMResult);
133 // Convert DRM_METHOD into MSG_DRM_TYPE
134 switch (drmInfo.oma_info.method) {
135 case DRM_METHOD_TYPE_FORWARD_LOCK:
136 *eDRMType = MSG_DRM_FORWARD_LOCK;
138 case DRM_METHOD_TYPE_COMBINED_DELIVERY:
139 *eDRMType = MSG_DRM_COMBINED_DELIVERY;
141 case DRM_METHOD_TYPE_SEPARATE_DELIVERY:
142 *eDRMType = MSG_DRM_SEPARATE_DELIVERY;
145 *eDRMType = MSG_DRM_NONE;
148 MSG_DEBUG("eDRMType : %d", *eDRMType);
150 MSG_DEBUG("This is not a DRM_TYPE_OMA_V1 type");
157 bool MsgDrmGetMimeTypeEx(const char *szFileName, char *szMimeType, int nMimeTypeLen)
159 if (!szFileName || !szMimeType || !nMimeTypeLen) {
160 MSG_DEBUG("param is NULL");
164 char strTemp[MSG_MAX_DRM_FILE_PATH + 1] = {0,};
166 strncpy(strTemp, szFileName, strlen(szFileName));
168 drm_content_info_s tdcfContentinfo;
169 memset(&tdcfContentinfo, 0x00, sizeof(drm_content_info_s));
170 int eDRMResult = drm_get_content_info(strTemp, &tdcfContentinfo); // Get attribute of DRM File
171 if (DRM_RETURN_SUCCESS == eDRMResult) {
172 MSG_DEBUG("contentType = %s", tdcfContentinfo.mime_type);
173 snprintf(szMimeType, nMimeTypeLen, "%s", tdcfContentinfo.mime_type);
176 MSG_DEBUG("drm_get_content_info is failed %d", eDRMResult);
183 bool MsgDrmGetContentID(const char *szFileName, char *szContentID, int nContentIDLen)
185 if (!szFileName || !szContentID || !nContentIDLen) {
186 MSG_DEBUG("param is NULL");
190 char strTemp[MSG_MAX_DRM_FILE_PATH + 1] = {0,};
192 strncpy(strTemp, szFileName, MSG_MAX_DRM_FILE_PATH);
194 drm_content_info_s content_info;
195 memset(&content_info, 0x00, sizeof(drm_content_info_s));
197 int result = drm_get_content_info(strTemp, &content_info);
198 if (DRM_RETURN_SUCCESS == result) {
199 MSG_DEBUG("contentID = %s", content_info.content_id);
200 snprintf(szContentID, nContentIDLen, "%s", content_info.content_id);
202 MSG_DEBUG("drm_get_content_info is failed %d", result);