22e6f34800b4f5bdd71456d7eb377b8bd4fe2de0
[platform/framework/web/download-provider.git] / agent / download-agent-plugin-drm.c
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <string.h>
18
19 #include "drm_client.h"
20 #include "drm_client_types.h"
21 #include "drm_trusted_client.h"
22 #include "drm_trusted_client_types.h"
23
24 #include "download-agent-debug.h"
25 #include "download-agent-plugin-drm.h"
26
27
28 void __EDRM_clean_up()
29 {
30         int ret = 0;
31         ret = drm_trusted_handle_request(DRM_TRUSTED_REQ_TYPE_CLIENT_CLEAN_UP, NULL, NULL);
32    if (DRM_RETURN_SUCCESS == ret) {
33            DA_LOGD( "Clean up successfull");
34    } else {
35            DA_LOGE("ret[%0x%x]",ret);
36    }
37 }
38
39 da_bool_t EDRM_convert(const char *in_file_path, char **out_file_path)
40 {
41         drm_trusted_conv_info_s input;
42         drm_trusted_conv_resp_info_s output;
43         size_t len = 0;
44         int ret = 0;
45
46         memset(&input, 0x0, sizeof(drm_trusted_conv_info_s));
47         memset(&output, 0x0, sizeof(drm_trusted_conv_resp_info_s));
48
49         len = strlen(in_file_path);
50         if (len >= sizeof(input.filePath))
51                 len = sizeof(input.filePath) - 1;
52         memcpy(input.filePath, in_file_path, len);
53
54         ret = drm_trusted_convert_dm(&input, &output);
55
56         if (DRM_TRUSTED_RETURN_SUCCESS != ret) {
57                 DA_LOGE("ret[%0x%x]",ret);
58                 __EDRM_clean_up();
59                 return DA_FALSE;
60         } else {
61                 DA_SECURE_LOGD("Returned filePath[%s]", output.filePath);
62                 *out_file_path = strdup(output.filePath);
63         }
64         __EDRM_clean_up();
65         return DA_TRUE;
66 }
67
68 da_ret_t EDRM_wm_get_license(char *rights_url, char **out_content_url)
69 {
70         int ret = 0;
71         int len = 0;
72         drm_initiator_info_s init_info;
73         drm_web_server_resp_data_s resp_data;
74
75         if (rights_url == NULL)
76                 return DA_ERR_DRM_FAIL;
77
78         memset(&init_info, 0, sizeof(init_info));
79         memset(&resp_data, 0, sizeof(resp_data));
80         strncpy(init_info.initiator_url, rights_url,
81                         DRM_MAX_LEN_INITIATOR_URL - 1);
82         len = strlen(rights_url);
83         if (len > DRM_MAX_LEN_INITIATOR_URL - 1)
84                 init_info.initiator_url_len = (unsigned int)len;
85         else
86                 init_info.initiator_url_len = DRM_MAX_LEN_INITIATOR_URL;
87         ret = drm_process_request(DRM_REQUEST_TYPE_SUBMIT_INITIATOR_URL,
88                         &init_info, &resp_data);
89         if (DRM_RETURN_SUCCESS == ret) {
90                 DA_SECURE_LOGD("resp_data.content_url = %s", resp_data.content_url);
91                 /* Rights or Domain Certificate are installed successfully */
92                 /* Check for contentURL */
93                 if (strlen(resp_data.content_url) > 0) {
94                         char *content_url = NULL;
95                         size_t content_url_len = 0;
96                         content_url_len = strlen(resp_data.content_url);
97                         content_url = (char *)calloc(1, content_url_len + 1);
98                         if (content_url) {
99                                 strncpy(content_url, resp_data.content_url,
100                                         content_url_len);
101                                 *out_content_url = content_url;
102                                 DA_SECURE_LOGD("drm sumitted initiator url "
103                                                 "succeeded with [%s]", *out_content_url);
104                                 __EDRM_clean_up();
105                                 return DA_RESULT_OK;
106                         } else {
107                                 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
108                                 __EDRM_clean_up();
109                                 return DA_ERR_FAIL_TO_MEMALLOC;
110                         }
111                 } else {
112                         DA_LOGV("content_url is NULL.\
113                                         Join/Leave Domain, Metering case.");
114                         *out_content_url = DA_NULL;
115                         __EDRM_clean_up();
116                         return DA_RESULT_OK;
117                 }
118         } else {
119                 DA_LOGE("drm_process_request() failed");
120                 __EDRM_clean_up();
121                 return DA_ERR_DRM_FAIL;
122         }
123 }
124