1/*
2 * Copyright (C) 2007 The Android Open Source Project
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#ifndef __PARSER_DM_H__
18#define __PARSER_DM_H__
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <drm_common_types.h>
25
26#define MAX_CONTENT_TYPE_LEN                                64
27#define MAX_CONTENT_ID                                      256
28#define MAX_CONTENT_BOUNDARY_LEN                            256
29#define MAX_RIGHTS_ISSUER_LEN                               256
30
31#define DRM_MIME_TYPE_RIGHTS_XML                            "application/vnd.oma.drm.rights+xml"
32#define DRM_MIME_TYPE_CONTENT                               "application/vnd.oma.drm.content"
33
34#define HEADERS_TRANSFER_CODING                             "Content-Transfer-Encoding:"
35#define HEADERS_CONTENT_TYPE                                "Content-Type:"
36#define HEADERS_CONTENT_ID                                  "Content-ID:"
37
38#define TRANSFER_CODING_TYPE_7BIT                           "7bit"
39#define TRANSFER_CODING_TYPE_8BIT                           "8bit"
40#define TRANSFER_CODING_TYPE_BINARY                         "binary"
41#define TRANSFER_CODING_TYPE_BASE64                         "base64"
42
43#define DRM_UID_TYPE_FORWORD_LOCK                           "forwardlock"
44#define DRM_NEW_LINE_CRLF                                   "\r\n"
45
46#define HEADERS_TRANSFER_CODING_LEN                         26
47#define HEADERS_CONTENT_TYPE_LEN                            13
48#define HEADERS_CONTENT_ID_LEN                              11
49
50#define DRM_MESSAGE_CODING_7BIT                             0  /* default */
51#define DRM_MESSAGE_CODING_8BIT                             1
52#define DRM_MESSAGE_CODING_BINARY                           2
53#define DRM_MESSAGE_CODING_BASE64                           3
54
55#define DRM_B64_DEC_BLOCK                                   3
56#define DRM_B64_ENC_BLOCK                                   4
57
58typedef struct _T_DRM_DM_Info {
59    uint8_t contentType[MAX_CONTENT_TYPE_LEN];  /**< Content type */
60    uint8_t contentID[MAX_CONTENT_ID];          /**< Content ID */
61    uint8_t boundary[MAX_CONTENT_BOUNDARY_LEN]; /**< DRM message's boundary */
62    uint8_t deliveryType;                       /**< The Delivery type */
63    uint8_t transferEncoding;                   /**< Transfer encoding type */
64    int32_t contentOffset;                      /**< The offset of the media content from the original DRM data */
65    int32_t contentLen;                         /**< The length of the media content */
66    int32_t rightsOffset;                       /**< The offset of the rights object in case of combined delivery */
67    int32_t rightsLen;                          /**< The length of the rights object in case of combined delivery */
68    uint8_t rightsIssuer[MAX_RIGHTS_ISSUER_LEN];/**< The rights issuer address in case of separate delivery */
69} T_DRM_DM_Info;
70
71/**
72 * Search the string in a limited length.
73 *
74 * \param str           The original string
75 * \param strSearch     The sub-string to be searched
76 * \param len           The length limited
77 *
78 * \return
79 *      -NULL, when there is not the searched string in length
80 *      -The pointer of this sub-string
81 */
82const uint8_t* drm_strnstr(const uint8_t* str, const uint8_t* strSearch, int32_t len);
83
84/**
85 * Parse the DRM message format data.
86 *
87 * \param buffer        (in)Input the DRM message format data
88 * \param bufferLen     (in)The input buffer length
89 * \param pDmInfo       (out)A structure pointer which contain information of DRM message headers
90 *
91 * \return
92 *      -TRUE, when success
93 *      -FALSE, when failed
94 */
95int32_t drm_parseDM(const uint8_t* buffer, int32_t bufferLen, T_DRM_DM_Info* pDmInfo);
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif /* __PARSER_DM_H__ */
102