|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: CUpnpRangeHeaderParser is a class used to range header prsing |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CUPNPRANGEHEADERPARSER_H |
|
20 #define C_CUPNPRANGEHEADERPARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <in_sock.h> |
|
26 #include "upnpcons.h" |
|
27 #include "upnphttpservertransaction.h" |
|
28 |
|
29 class CUpnpHttpMessage; |
|
30 |
|
31 static const TInt KIntegerOccurance = 3; |
|
32 static const TInt KSlashSpaceAndMinusSize = 3; |
|
33 static const TInt KMaxIntegerInContentLength = 2; |
|
34 |
|
35 |
|
36 // CLASS DECLARATION |
|
37 |
|
38 NONSHARABLE_CLASS (CUpnpRangeHeaderParser) : public CBase |
|
39 { |
|
40 public: // Constructors and destructor |
|
41 |
|
42 /** |
|
43 * Two-phased constructor. |
|
44 * |
|
45 * @param aHeaderBuffer should be leave safe |
|
46 */ |
|
47 static CUpnpRangeHeaderParser* NewL( CUpnpHttpServerTransaction& aTransaction, |
|
48 TInt& aStartPos, TInt& aEndPos ); |
|
49 static CUpnpRangeHeaderParser* NewLC( CUpnpHttpServerTransaction& aTransaction, |
|
50 TInt& aStartPos, TInt& aEndPos ); |
|
51 |
|
52 /** |
|
53 * Destructor. |
|
54 */ |
|
55 virtual ~CUpnpRangeHeaderParser(); |
|
56 |
|
57 public: // New functions |
|
58 |
|
59 /** |
|
60 * Returns parsing status as HTTP error code (e.g. EHttpPartialContent, -EHttpBadRequest) if Range header exist or |
|
61 * EHttpOk if doesn't |
|
62 * If request is corrected and Range header exist all references passed into construction phase |
|
63 * gots new value |
|
64 */ |
|
65 TInt ParseRangeL( CUpnpHttpMessage* aMsg, TInt aFileSize ); |
|
66 |
|
67 private: |
|
68 |
|
69 /** |
|
70 * C++ default constructor. |
|
71 */ |
|
72 |
|
73 CUpnpRangeHeaderParser( CUpnpHttpServerTransaction &aTransaction, |
|
74 TInt& aStartPos, TInt& aEndPos ); |
|
75 |
|
76 /** |
|
77 * By default Symbian 2nd phase constructor is private. |
|
78 */ |
|
79 void ConstructL(); |
|
80 |
|
81 /** |
|
82 * Checks syntax of Range header |
|
83 * EHttpPartialContent if Range header exists and syntax is proper |
|
84 * EHttpOk if Range header doesn't exist |
|
85 * -EHttpBadRequest if Range syntax is improper |
|
86 */ |
|
87 TInt CheckRangeHeaderSyntax( CUpnpHttpMessage* aMsg ); |
|
88 |
|
89 /** |
|
90 * Checks Range value |
|
91 * EHttpPartialContent if values there are proper |
|
92 * - HTTP error code if not |
|
93 */ |
|
94 TInt CheckRangeValues( TInt aFileSize ); |
|
95 |
|
96 /** |
|
97 * Parses HTTP Range header, according to rules described in DLNA specyfication |
|
98 * and if header is correct, it returns first and last byte positions. If header |
|
99 * is not correct, those values are random and should not be used. |
|
100 * @param aRangeHeader Range header. |
|
101 * @param aStartPos reference which will be filled with first byte position. |
|
102 * @param aEndPos reference which will be filled with last byte position or |
|
103 * with KErrNotFound if such position was not specified in the header which is correct. |
|
104 * @return ETrue if header syntax is correct, EFalse if not. |
|
105 **/ |
|
106 static TBool ParseRangeHeader( TDesC8& aRangeHeader, TInt& aStartPos, TInt& aEndPos ); |
|
107 |
|
108 /** |
|
109 * Appends Content-Length header to response |
|
110 */ |
|
111 void AppendContentLengthToResponseL( TInt aFileSize, TInt rangeStatus ); |
|
112 |
|
113 |
|
114 /** |
|
115 * Appends Bytes header to response |
|
116 */ |
|
117 void AppendBytesToResponseL( TInt aFileSize ); |
|
118 |
|
119 |
|
120 /** |
|
121 * Creates response for 206 Partial Content |
|
122 */ |
|
123 void CreatePartialContentResponseL( |
|
124 TInt aFileSize, TInt aHttpCode ); |
|
125 |
|
126 /** |
|
127 * Creates response for 204 No Content |
|
128 */ |
|
129 void CreateNoContentResponseL( TInt aFileSize, TInt aHttpCode ); |
|
130 |
|
131 /** |
|
132 * Checks number format |
|
133 * Returns ETrue if aNumber is improper |
|
134 */ |
|
135 static TBool HasImproperChars( const TLex8& aNumber ); |
|
136 |
|
137 /** |
|
138 * Moves parser position to first not white space |
|
139 */ |
|
140 static void MovePosition( const TDesC8& aString, TInt& aPos ); |
|
141 |
|
142 /** |
|
143 * Handles conversion exception |
|
144 * Returns EFalse if error cannot be handled |
|
145 */ |
|
146 static TBool HandleConversionException( TLex8& aNumber, TInt& aRangePos, TInt aError ); |
|
147 |
|
148 /** |
|
149 Members |
|
150 */ |
|
151 private: |
|
152 // Reference to response header, not owned |
|
153 CUpnpHttpServerTransaction &iTransaction; |
|
154 // Reference to start position |
|
155 TInt& iStartPos; |
|
156 // Reference to end position |
|
157 TInt& iEndPos; |
|
158 //size parsing buffer |
|
159 TBuf8<KMaxIntegerInContentLength*KMaxIntegerLength> iSizeBuffer; |
|
160 |
|
161 }; |
|
162 |
|
163 |
|
164 #endif |
|
165 |