summaryrefslogtreecommitdiff
path: root/agent/download-agent-plugin-drm.c
blob: 22e6f34800b4f5bdd71456d7eb377b8bd4fe2de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <string.h>

#include "drm_client.h"
#include "drm_client_types.h"
#include "drm_trusted_client.h"
#include "drm_trusted_client_types.h"

#include "download-agent-debug.h"
#include "download-agent-plugin-drm.h"


void __EDRM_clean_up()
{
	int ret = 0;
	ret = drm_trusted_handle_request(DRM_TRUSTED_REQ_TYPE_CLIENT_CLEAN_UP, NULL, NULL);
   if (DRM_RETURN_SUCCESS == ret) {
	   DA_LOGD( "Clean up successfull");
   } else {
	   DA_LOGE("ret[%0x%x]",ret);
   }
}

da_bool_t EDRM_convert(const char *in_file_path, char **out_file_path)
{
	drm_trusted_conv_info_s input;
	drm_trusted_conv_resp_info_s output;
	size_t len = 0;
	int ret = 0;

	memset(&input, 0x0, sizeof(drm_trusted_conv_info_s));
	memset(&output, 0x0, sizeof(drm_trusted_conv_resp_info_s));

	len = strlen(in_file_path);
	if (len >= sizeof(input.filePath))
		len = sizeof(input.filePath) - 1;
	memcpy(input.filePath, in_file_path, len);

	ret = drm_trusted_convert_dm(&input, &output);

	if (DRM_TRUSTED_RETURN_SUCCESS != ret) {
		DA_LOGE("ret[%0x%x]",ret);
		__EDRM_clean_up();
		return DA_FALSE;
	} else {
		DA_SECURE_LOGD("Returned filePath[%s]", output.filePath);
		*out_file_path = strdup(output.filePath);
	}
	__EDRM_clean_up();
	return DA_TRUE;
}

da_ret_t EDRM_wm_get_license(char *rights_url, char **out_content_url)
{
	int ret = 0;
	int len = 0;
	drm_initiator_info_s init_info;
	drm_web_server_resp_data_s resp_data;

	if (rights_url == NULL)
		return DA_ERR_DRM_FAIL;

	memset(&init_info, 0, sizeof(init_info));
	memset(&resp_data, 0, sizeof(resp_data));
	strncpy(init_info.initiator_url, rights_url,
			DRM_MAX_LEN_INITIATOR_URL - 1);
	len = strlen(rights_url);
	if (len > DRM_MAX_LEN_INITIATOR_URL - 1)
		init_info.initiator_url_len = (unsigned int)len;
	else
		init_info.initiator_url_len = DRM_MAX_LEN_INITIATOR_URL;
	ret = drm_process_request(DRM_REQUEST_TYPE_SUBMIT_INITIATOR_URL,
			&init_info, &resp_data);
	if (DRM_RETURN_SUCCESS == ret) {
		DA_SECURE_LOGD("resp_data.content_url = %s", resp_data.content_url);
		/* Rights or Domain Certificate are installed successfully */
		/* Check for contentURL */
		if (strlen(resp_data.content_url) > 0) {
			char *content_url = NULL;
			size_t content_url_len = 0;
			content_url_len = strlen(resp_data.content_url);
			content_url = (char *)calloc(1, content_url_len + 1);
			if (content_url) {
				strncpy(content_url, resp_data.content_url,
					content_url_len);
				*out_content_url = content_url;
				DA_SECURE_LOGD("drm sumitted initiator url "
						"succeeded with [%s]", *out_content_url);
				__EDRM_clean_up();
				return DA_RESULT_OK;
			} else {
				DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
				__EDRM_clean_up();
				return DA_ERR_FAIL_TO_MEMALLOC;
			}
		} else {
			DA_LOGV("content_url is NULL.\
					Join/Leave Domain, Metering case.");
			*out_content_url = DA_NULL;
			__EDRM_clean_up();
			return DA_RESULT_OK;
		}
	} else {
		DA_LOGE("drm_process_request() failed");
		__EDRM_clean_up();
		return DA_ERR_DRM_FAIL;
	}
}