update tizen source
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginDrm.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <string.h>
32 #include "MmsPluginDrm.h"
33 #include "MmsPluginCodec.h"
34 #include "MsgMmsTypes.h"
35 #include "MsgDrmWrapper.h"
36 #include "MsgDebug.h"
37 #include "drm-service.h"
38
39 #ifdef __SUPPORT_DRM__
40
41 MmsDrm2ConvertState     mmsDrm2ConvertState;
42
43 MsgDrmType MsgGetDRMType(MsgType *pMsgType, MsgBody *pMsgBody)
44 {
45         MsgDrmType drmType = MSG_DRM_TYPE_NONE;
46         MsgMultipart *pMultipart = NULL;
47
48         if (MsgIsMultipart(pMsgType->type)) {
49                 pMultipart = pMsgBody->body.pMultipart;
50                 while (pMultipart) {
51                         if (drmType < pMultipart->type.drmInfo.drmType)
52                                 drmType = pMultipart->type.drmInfo.drmType;
53
54                         pMultipart = pMultipart->pNext;
55                 }
56         } else {
57                 drmType = pMsgType->drmInfo.drmType;
58         }
59
60         return drmType;
61 }
62
63 void MmsDrm2SetConvertState(MmsDrm2ConvertState newConvertState)
64 {
65         mmsDrm2ConvertState = newConvertState;
66         MSG_DEBUG("MmsDrm2SetConvertState: mmsDrm2ConvertState = %d\n", mmsDrm2ConvertState);
67 }
68
69 MmsDrm2ConvertState MmsDrm2GetConvertState(void)
70 {
71         return mmsDrm2ConvertState;
72 }
73
74 bool MsgDRM2GetDRMInfo(char *szFilePath, MsgType *pMsgType)
75 {
76         if (szFilePath == NULL || pMsgType == NULL) {
77                 MSG_DEBUG("Param is NULL szFilePath = %d, pMsgType = %d", szFilePath, pMsgType);
78                 return false;
79         }
80
81         char szMimeType[DRM_MAX_TYPE_LEN + 1];
82         char szContentID[DRM_MAX_CID_LEN + 1];
83         MSG_DRM_TYPE drmType = MSG_DRM_NONE;
84
85         MsgDrmGetDrmType(szFilePath, &drmType);
86         MsgDrmGetMimeTypeEx(szFilePath, szMimeType, DRM_MAX_TYPE_LEN + 1);
87         MsgDrmGetContentID(szFilePath, szContentID, DRM_MAX_CID_LEN + 1);
88         MSG_DEBUG("drmType: %d", drmType);
89
90         switch (drmType) {
91         case MSG_DRM_FORWARD_LOCK:
92                 pMsgType->drmInfo.drmType = MSG_DRM_TYPE_FL;
93                 pMsgType->drmInfo.contentType = (MsgContentType)_MsgGetCode(MSG_TYPE, szMimeType);
94                 if (MsgCopyDrmInfo(pMsgType) == false) {
95                         MSG_DEBUG("MsgDRM2GetDRMInfo : MsgCopyDrmInfo failed");
96                         return false;
97                 }
98                 break;
99
100         case MSG_DRM_COMBINED_DELIVERY:
101                 pMsgType->drmInfo.drmType = MSG_DRM_TYPE_CD;
102                 pMsgType->drmInfo.szContentURI = MsgResolveContentURI(szContentID);
103                 break;
104
105         case MSG_DRM_SEPARATE_DELIVERY:
106                 pMsgType->drmInfo.drmType = MSG_DRM_TYPE_SD;
107
108                 pMsgType->drmInfo.contentType = (MsgContentType)_MsgGetCode(MSG_TYPE, szMimeType);
109
110                 drm_dcf_header_t dcfHdrInfo;
111                 drm_svc_get_dcf_header_info(szFilePath, &dcfHdrInfo);
112
113                 if (dcfHdrInfo.version == DRM_OMA_DRMV1_RIGHTS) {
114                         pMsgType->drmInfo.szContentName = MsgRemoveQuoteFromFilename(dcfHdrInfo.headerUnion.headerV1.contentName);
115                         pMsgType->drmInfo.szContentDescription = MsgStrCopy(dcfHdrInfo.headerUnion.headerV1.contentDescription);
116                 }
117                 break;
118
119         default:
120                 pMsgType->drmInfo.drmType = MSG_DRM_TYPE_NONE;
121                 break;
122         }
123
124         pMsgType->drmInfo.szDrm2FullPath = MsgStrCopy(szFilePath);
125         MSG_DEBUG("pMsgType->drmInfo.szDrm2FullPath: %s", pMsgType->drmInfo.szDrm2FullPath);
126
127         return true;
128 }
129
130 bool MsgDRMIsForwardLockType(MsgDrmType drmType)
131 {
132         switch (drmType) {
133         case MSG_DRM_TYPE_FL:
134         case MSG_DRM_TYPE_CD:
135                 return true;
136
137         case MSG_DRM_TYPE_NONE:         //SD & plain can be forwarded
138         case MSG_DRM_TYPE_SD:
139         default:
140                 return false;
141         }
142 }
143
144 bool MsgChangeDrm2FileName(char *szFileName)
145 {
146         char szTempFileName[MSG_FILENAME_LEN_MAX] = {0,};
147
148         if (szFileName == NULL || szFileName[0] == '\0')
149                 return false;
150
151         MsgGetFileNameWithoutExtension(szTempFileName, szFileName);
152
153         if (strrchr(szTempFileName, '.'))
154                 return true;
155
156         strcat(szTempFileName, ".dcf");
157         strcpy(szFileName, szTempFileName);
158
159         MSG_DEBUG("MsgChangeDrm2FileName: made szFileName = %s \n", szFileName);
160
161         return true;
162 }
163
164 bool MsgIsDCFFile(char *szFilePath)
165 {
166         int length = 0;
167
168         MSG_DEBUG("MsgIsDCFFile: szFilePath = %s \n", szFilePath);
169
170         length = MsgStrlen(szFilePath);
171         if (szFilePath[length - 4] == '.' &&
172                 (szFilePath[length - 3] == 'd' || szFilePath[length - 3] == 'D') &&
173                 (szFilePath[length - 2] == 'c' || szFilePath[length - 2] == 'C') &&
174                 (szFilePath[length - 1] == 'f' || szFilePath[length - 1] == 'F'))
175                 return true;
176
177         return false;
178 }
179
180 #endif