|
1 /* |
|
2 * Copyright (c) 2009 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 #ifndef CREQUESTCHECKER_H |
|
20 #define CREQUESTCHECKER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <mtp/mtpprotocolconstants.h> |
|
24 #include <mtp/tmtptyperequest.h> |
|
25 |
|
26 class CMTPObjectMetaData; |
|
27 class MMTPDataProviderFramework; |
|
28 class MMTPConnection; |
|
29 |
|
30 /** |
|
31 * element type in the request |
|
32 */ |
|
33 enum TMTPElementType |
|
34 { |
|
35 /** |
|
36 * Session ID type |
|
37 */ |
|
38 EMTPElementTypeSessionID, |
|
39 |
|
40 /** |
|
41 * Object Handle type |
|
42 */ |
|
43 EMTPElementTypeObjectHandle, |
|
44 |
|
45 /** |
|
46 * Format code type |
|
47 */ |
|
48 EMTPElementTypeFormatCode, |
|
49 |
|
50 /** |
|
51 * Storeage Id type |
|
52 */ |
|
53 EMTPElementTypeStorageId, |
|
54 }; |
|
55 |
|
56 /** |
|
57 * element attribute to check in the reqeust |
|
58 */ |
|
59 enum TMTPElementAttr |
|
60 { |
|
61 /** |
|
62 * no attribute to check |
|
63 */ |
|
64 EMTPElementAttrNone = 0x0000, |
|
65 |
|
66 /** |
|
67 * the object/storage should be readable |
|
68 */ |
|
69 EMTPElementAttrRead = 0x0001, |
|
70 |
|
71 /** |
|
72 * the object/storage should be writable |
|
73 */ |
|
74 EMTPElementAttrWrite = 0x0002, |
|
75 |
|
76 /** |
|
77 * the object should be a file |
|
78 */ |
|
79 EMTPElementAttrFile = 0x0004, |
|
80 |
|
81 /** |
|
82 * the object should be a directory |
|
83 */ |
|
84 EMTPElementAttrDir = 0x0008, |
|
85 |
|
86 /** |
|
87 * supported format array |
|
88 */ |
|
89 EMTPElementAttrFormatEnums = 0x0010, |
|
90 |
|
91 /** |
|
92 * The object can be either a file or directory. |
|
93 */ |
|
94 EMTPElementAttrFileOrDir = 0x0020, |
|
95 }; |
|
96 |
|
97 /** |
|
98 * defines the verification data structure |
|
99 */ |
|
100 struct TMTPRequestElementInfo |
|
101 { |
|
102 TMTPTypeRequest::TElements iElementIndex; //which element in the request to check |
|
103 TMTPElementType iElementType; //the type of the element |
|
104 TInt iElementAttr; //the attribute of the element |
|
105 TInt iCount; //number of special values (0, 1, 2) |
|
106 TUint32 iValue1; //special value 1 |
|
107 TUint32 iValue2; //special value 2 |
|
108 }; |
|
109 |
|
110 /** |
|
111 * defines a generic request verification class. It iterates through the verification data elements, |
|
112 * and performs the check based on the element type/attribute. |
|
113 */ |
|
114 class CRequestChecker : public CBase |
|
115 { |
|
116 public: |
|
117 /** |
|
118 * Two-phase construction method |
|
119 * @param aFramework The data provider framework |
|
120 * @param aConnection The connection object |
|
121 * @return a pointer to the created request checker object |
|
122 */ |
|
123 static CRequestChecker* NewL( MMTPDataProviderFramework& aFramework, |
|
124 MMTPConnection& aConnection ); |
|
125 |
|
126 /** |
|
127 * Destructor |
|
128 */ |
|
129 ~CRequestChecker(); |
|
130 |
|
131 /** |
|
132 * Verfiy the request. It check the request header first (session id and transaction code), and check for special values, last |
|
133 * it iterates through the verification elements for checking individul parameters in the request |
|
134 * @param aRequest The request object to verify |
|
135 * @param aCount The number of verification elements |
|
136 * @param aElementInfo The array of verification elements |
|
137 * @return reponse code to return to the initiator |
|
138 */ |
|
139 TMTPResponseCode VerifyRequestL( const TMTPTypeRequest& aRequest, |
|
140 TInt aCount, |
|
141 const TMTPRequestElementInfo* aElementInfo ); |
|
142 |
|
143 /** |
|
144 * Return the object info for the handle. |
|
145 * This is to remove extra expensive DMBS retrieval operations. |
|
146 * @param aHandle the handle of the object requested |
|
147 * @return an object info for the handle |
|
148 */ |
|
149 CMTPObjectMetaData* GetObjectInfo( TUint32 aHandle ) const; |
|
150 |
|
151 private: |
|
152 /** |
|
153 * Check the request header portion (session Id and transaction code) |
|
154 * @param aRequest the request object to check |
|
155 * @return repsonse code to return to initiator |
|
156 */ |
|
157 TMTPResponseCode CheckRequestHeader( const TMTPTypeRequest& aRequest ) const; |
|
158 |
|
159 /** |
|
160 * Check the session id in the request parameter (NOTE the session id is different from the one in the request header), |
|
161 * this usually only applies to the OpenSession request |
|
162 * @param aSessionId Session id of the request. |
|
163 * @param aElementInfo ElementInfo data array to check against. |
|
164 * @return repsonse code to return to initiator |
|
165 */ |
|
166 TMTPResponseCode VerifySessionId( TUint32 aSessionId, |
|
167 const TMTPRequestElementInfo& aElementInfo ) const; |
|
168 |
|
169 /** |
|
170 * Check the object handle in the request parameter, whether the handle is in the object store, read/write, file/dir |
|
171 * @param aHandle Object handle to be checked. |
|
172 * @param aElementInfo Element info array to be checked against. |
|
173 * @return repsonse code to return to initiator |
|
174 */ |
|
175 TMTPResponseCode VerifyObjectHandleL( TUint32 aHandle, |
|
176 const TMTPRequestElementInfo& aElementInfo ); |
|
177 |
|
178 /** |
|
179 * Check the storage id parameter in the request, read/write attributes |
|
180 * @param aStorageId Storage id to be checked. |
|
181 * @param aElementInfo Element info array to be checked against. |
|
182 * @return repsonse code to return to initiator |
|
183 */ |
|
184 TMTPResponseCode VerifyStorageIdL( TUint32 aStorageId, |
|
185 const TMTPRequestElementInfo& aElementInfo ) const; |
|
186 |
|
187 /** |
|
188 * Check the format code parameter in the request, |
|
189 * @param aStorageId aFormatCode to be checked. |
|
190 * @param aElementInfo Element info array to be checked against. |
|
191 * @return repsonse code to return to initiator |
|
192 */ |
|
193 TMTPResponseCode VerifyFormatCode( TUint32 aFormatCode, |
|
194 const TMTPRequestElementInfo& aElementInfo ) const; |
|
195 |
|
196 /** |
|
197 * Check if the parameter is one of the special values |
|
198 * @param aParameter The parameter value in the request |
|
199 * @param aElementInfo The ElementInfo for the parameter |
|
200 * @return ETrue if the parameter is one of the special values, otherwise, EFalse |
|
201 */ |
|
202 TBool IsSpecialValue( TUint32 aParameter, |
|
203 const TMTPRequestElementInfo& aElementInfo ) const; |
|
204 |
|
205 private: |
|
206 /** |
|
207 * Standard c++ constructor |
|
208 */ |
|
209 CRequestChecker( MMTPDataProviderFramework& aFramework, |
|
210 MMTPConnection& aConnection ); |
|
211 |
|
212 /** |
|
213 * Two-phase construction |
|
214 */ |
|
215 void ConstructL(); |
|
216 |
|
217 private: |
|
218 MMTPDataProviderFramework& iFramework; |
|
219 MMTPConnection& iConnection; |
|
220 RArray<TUint32> iHandles; //these two arrays contain the mapping from the handle to objectinfo |
|
221 RPointerArray<CMTPObjectMetaData> iObjectArray; |
|
222 |
|
223 }; |
|
224 |
|
225 #endif // CREQUESTCHECKER_H |