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 __DCF_CONTAINER_H__
18#define __DCF_CONTAINER_H__
19
20#include <Drm2CommonTypes.h>
21#include <uvector.h>
22#include <dcf/DrmIStream.h>
23#include <dcf/DrmDcfCommon.h>
24
25class DrmInStream;
26
27/////////dcf container
28class DcfContainer : public FullBox
29{
30public:
31    friend class DrmInStream;
32
33    /** default constructor of DcfContainer */
34    DcfContainer(istream& inRawData):FullBox(NULL),mConStream(inRawData){}
35
36    /**
37     * constructor for DcfContainer, used to parse DCF container
38     * \param data  DCF container data
39     * \param len   DCF container data len
40     * \param off   the offset from the start of DCF container
41     */
42    DcfContainer(const uint8_t* data,istream& inRawData,uint64_t conOff);
43
44    /** Destructor for DcfContainer */
45    ~DcfContainer();
46
47    /**
48     * get the content type of one content
49     * \param none
50     * \return
51     *   the content type
52     */
53    string getContentType(void) const;
54
55    /**
56     * get the encryption method apply to content
57     * \param none
58     * \return
59     *   the encryption method
60     */
61    uint8_t getEncryptionMethod(void) const;
62
63    /**
64     * get the padding scheme apply to content
65     * \param none
66     * \return
67     *   the padding scheme
68     */
69    uint8_t getPaddingScheme(void) const;
70
71    /**
72     * get the length of plain content
73     * \param none
74     * \return
75     *   the length of plain content
76     */
77    uint64_t getPlaintextLength(void) const;
78
79    /**
80     * get the length of content ID
81     * \param none
82     * \return
83     *   the length of content ID
84     */
85    uint16_t getContentIDLength(void) const;
86
87    /**
88     * get the length of rights issuer URL
89     * \param none
90     * \return
91     *   the length of rights issuer URL
92     */
93    uint16_t getRightsIssuerURLLength(void) const;
94
95    /**
96     * get the length of textal header
97     * \param none
98     * \return
99     *   the length of textal header
100     */
101    uint16_t getTextualHeadersLength(void) const;
102
103    /**
104     * get the content ID of one content
105     * \param none
106     * \return
107     *   the content ID
108     */
109    string getContentID(void) const;
110
111    /**
112     * get the rights issuer URL
113     * \param none
114     * \return
115     *   the rights issuer URL
116     */
117    string getRightsIssuerURL(void) const;
118
119    /**
120     * get the preview method
121     * \param none
122     * \return
123     *   the preview method
124     */
125    string getPreviewMethod(void) const;
126
127    /**
128     * get the location of content
129     * \param none
130     * \return
131     *   the location of content
132     */
133    string getContentLocation(void) const;
134
135    /**
136     * get the URL of content
137     * \param none
138     * \return
139     *   the URL of content
140     */
141    string getContentURL(void) const;
142
143    /**
144     * get the customer head
145     * \param none
146     * \return
147     *   the customer head
148     */
149    vector<string> getCustomerHead(void) const;
150
151    /**
152     * get the preview element data
153     * \param none
154     * \return
155     *   the DRM Instream of preview element data
156     */
157    DrmInStream getPreviewElementData(void) const;
158
159    /**
160     * get the plain content
161     * \param none
162     * \return
163     *   the DRM Instream of plain content
164     */
165    DrmInStream getDecryptContent(uint8_t* decryptKey) const;
166
167    /**
168     * get the istream of DCF
169     * \param none
170     * \return
171     *   the istream of DCF
172     */
173    istream& getStream(void) const;
174
175PRIVATE:
176    static const uint32_t USER_DATA_FLAG = 0x01;
177
178    uint8_t mContentTypeLen;
179    string mContentType;
180    uint8_t mEncryptionMethod;
181    uint8_t mPaddingScheme;
182    uint64_t mPlaintextLength;
183    uint16_t mContentIDLength;
184    uint16_t mRightsIssuerURLLength;
185    uint16_t mTextualHeadersLength;
186    string mContentID;
187    string mRightsIssuerURL;
188    vector<TextualHeader*> mTextualHeaders;
189    bool mSilentFirst;
190    string mSlientMethod;
191    string mSilentRightsURL;
192    string mPreviewMethod;
193    string mPreviewElementURI;
194    string mPreviewRightsURL;
195    string mContentURL;
196    string mContentVersion;
197    string mContentLocation;
198    vector<string> mCustomHeader;
199    bool mHasUserData;
200    uint64_t mDataLen;
201    istream& mConStream;
202    uint64_t mDecOffset;
203
204PRIVATE:
205    // parse text header
206    bool parseTextualHeaders(const uint8_t* data, uint32_t len);
207    void copy(const DcfContainer& container);
208    DcfContainer(const DcfContainer& container):FullBox(NULL),mConStream(container.mConStream){}
209    DcfContainer& operator=(const DcfContainer& other){return *this;}
210};
211
212
213#endif
214