|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCMSContentInfo.h" |
|
21 #include <asn1dec.h> |
|
22 #include <asn1enc.h> |
|
23 |
|
24 // CONSTANTS |
|
25 const TInt KMinNumberOfSubModules = 2; |
|
26 const TInt KMaxNumberOfSubModules = 2; |
|
27 const TUint8 KContentTag = 0; |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CCMSContentInfo::CCMSContentInfo |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CCMSContentInfo::CCMSContentInfo() |
|
38 { |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CCMSContentInfo::ConstructL |
|
43 // Symbian 2nd phase constructor can leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C void CCMSContentInfo::ConstructL() |
|
47 { |
|
48 // creating with empty values |
|
49 SetContentTypeL( KNullDesC() ); |
|
50 SetContentL( KNullDesC8() ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCMSContentInfo::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C void CCMSContentInfo::ConstructL( |
|
59 const TDesC& aContentType ) |
|
60 { |
|
61 SetContentTypeL( aContentType ); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CCMSContentInfo::ConstructL |
|
66 // Symbian 2nd phase constructor can leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C void CCMSContentInfo::ConstructL( |
|
70 const TDesC& aContentType, |
|
71 const TDesC8& aContent ) |
|
72 { |
|
73 SetContentTypeL( aContentType ); |
|
74 SetContentL( aContent ); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CCMSContentInfo::NewLC |
|
79 // Two-phased constructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CCMSContentInfo* CCMSContentInfo::NewLC() |
|
83 { |
|
84 CCMSContentInfo* self = new( ELeave ) CCMSContentInfo(); |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CCMSContentInfo::NewLC |
|
92 // Two-phased constructor. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CCMSContentInfo* CCMSContentInfo::NewLC( |
|
96 const TDesC& aContentType, |
|
97 const TDesC8& aContent ) |
|
98 { |
|
99 CCMSContentInfo* self = new( ELeave ) CCMSContentInfo(); |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL( aContentType, aContent ); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // Destructor |
|
106 CCMSContentInfo::~CCMSContentInfo() |
|
107 { |
|
108 delete iContent; |
|
109 delete iContentType; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CCMSContentInfo::DecodeL |
|
114 // Decrypts raw data to this instance |
|
115 // ----------------------------------------------------------------------------- |
|
116 void CCMSContentInfo::DecodeL( const TDesC8& aRawData ) |
|
117 { |
|
118 CArrayPtr<TASN1DecGeneric>* itemsData = DecodeSequenceLC( aRawData, |
|
119 KMinNumberOfSubModules, |
|
120 KMaxNumberOfSubModules ); |
|
121 // we would not get this far if there is not 2 |
|
122 // decoding attribute type |
|
123 TASN1DecObjectIdentifier decOid; |
|
124 HBufC* oid = decOid.DecodeDERL( *itemsData->At( 0 ) ); |
|
125 delete iContentType; |
|
126 iContentType = oid; |
|
127 |
|
128 // decoding content |
|
129 HBufC8* contDesc = NULL; |
|
130 TASN1DecGeneric taggedContent( *itemsData->At( 1 ) ); |
|
131 if( taggedContent.Tag() != KContentTag ) |
|
132 { |
|
133 User::Leave( KErrArgument ); |
|
134 } |
|
135 contDesc = taggedContent.GetContentDER().AllocL(); |
|
136 |
|
137 delete iContent; |
|
138 iContent = contDesc; |
|
139 CleanupStack::PopAndDestroy( itemsData ); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CCMSContentInfo::EncoderLC |
|
144 // Returns ASN1 encoder for this instance |
|
145 // ----------------------------------------------------------------------------- |
|
146 CASN1EncBase* CCMSContentInfo::EncoderLC() const |
|
147 { |
|
148 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
149 |
|
150 // add attribute type |
|
151 CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC( *iContentType ); |
|
152 root->AddAndPopChildL( oid ); |
|
153 |
|
154 // add content |
|
155 CASN1EncEncoding* content = CASN1EncEncoding::NewL( *iContent ); |
|
156 // explicitly tagged to 0 |
|
157 // Takes ownership of the encoder, *including* the case when |
|
158 // this method leaves. |
|
159 CASN1EncExplicitTag* explicitTag = |
|
160 CASN1EncExplicitTag::NewLC( content, KContentTag ); |
|
161 root->AddAndPopChildL( explicitTag ); |
|
162 return root; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CCMSContentInfo::Content |
|
167 // Getter for content |
|
168 // ----------------------------------------------------------------------------- |
|
169 EXPORT_C const TDesC8& CCMSContentInfo::Content() const |
|
170 { |
|
171 return *iContent; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CCMSContentInfo::SetContentL |
|
176 // Setter for content, takes copy |
|
177 // ----------------------------------------------------------------------------- |
|
178 EXPORT_C void CCMSContentInfo::SetContentL( const TDesC8& aContent ) |
|
179 { |
|
180 HBufC8* tmp = aContent.AllocL(); |
|
181 delete iContent; |
|
182 iContent = tmp; |
|
183 } |
|
184 |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CCMSContentInfo::ContentType |
|
188 // Getter for content type |
|
189 // ----------------------------------------------------------------------------- |
|
190 EXPORT_C const TDesC& CCMSContentInfo::ContentType() const |
|
191 { |
|
192 return *iContentType; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CCMSContentInfo::SetContentTypeL |
|
197 // Setter for content type, takes copy |
|
198 // ----------------------------------------------------------------------------- |
|
199 EXPORT_C void CCMSContentInfo::SetContentTypeL( const TDesC& aContentType ) |
|
200 { |
|
201 HBufC* tmp = aContentType.AllocL(); |
|
202 delete iContentType; |
|
203 iContentType = tmp; |
|
204 } |
|
205 // End of File |