|
1 /* |
|
2 * Copyright (c) 2009-2010 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 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * Contributors: |
|
11 * |
|
12 * Description: |
|
13 * MSRP Implementation |
|
14 * |
|
15 */ |
|
16 |
|
17 // CLASS HEADER |
|
18 #include "TMSRPHeaderUtil.h" |
|
19 |
|
20 // INTERNAL INCLUDES |
|
21 #include "MsrpCommon.h" |
|
22 #include "CMSRPByteRangeHeader.h" |
|
23 |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // TMSRPHeaderUtil::ConvertToNumberL |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 TInt TMSRPHeaderUtil::ConvertToNumber( const TDesC8& aString ) |
|
30 { |
|
31 // checking for special characters: |
|
32 // Unknown byte range end |
|
33 if ( aString == KAsterisk ) |
|
34 { |
|
35 // Range unknown |
|
36 return KUnknownRange; |
|
37 } |
|
38 TLex8 numberToConvert( aString ); |
|
39 TInt convertedNumber( 0 ); |
|
40 numberToConvert.Val( convertedNumber ); |
|
41 |
|
42 return convertedNumber; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // TMSRPHeaderUtil::AppendStringL |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void TMSRPHeaderUtil::AppendStringL( const TDesC8& aString, TDes8& aDest ) |
|
50 { |
|
51 TInt newLength = aString.Length() + aDest.Length(); |
|
52 if ( newLength > aDest.MaxLength() ) |
|
53 { |
|
54 // not enough room |
|
55 User::Leave( KErrArgument ); |
|
56 } |
|
57 aDest.Append( aString ); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // TMSRPHeaderUtil::CheckStringValidity |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 TBool TMSRPHeaderUtil::CheckStringValidity( const TDesC8& aString ) |
|
65 { |
|
66 if ( !aString.Length() ) |
|
67 { |
|
68 return EFalse; |
|
69 } |
|
70 |
|
71 // Checks the syntax for the Content-Type string only. May need to extend to other headers as well |
|
72 |
|
73 TChar charToFind( KDividedCharacter ); |
|
74 TInt matchLoc = aString.Locate( charToFind ); |
|
75 if( matchLoc == KErrNotFound || matchLoc == (aString.Length() -1) ) |
|
76 { |
|
77 return EFalse; |
|
78 } |
|
79 |
|
80 TPtrC8 typePtr = aString.Left(matchLoc); |
|
81 TLex8 lex( typePtr ); |
|
82 TChar chr = lex.Get(); |
|
83 while ( chr ) |
|
84 { |
|
85 if ( !chr.IsAlphaDigit() && chr != '!' && chr != '#' && chr != '$' && chr != '%' && chr != '&' && |
|
86 chr != '\'' && chr != '*' && chr != '+' && chr != '-' && chr != '.' && chr != '^' && |
|
87 chr != '_' && chr != '`' && chr != '{' && chr != '|' && chr != '}' && chr != '~' ) |
|
88 { |
|
89 return EFalse; |
|
90 } |
|
91 chr = lex.Get(); |
|
92 } |
|
93 |
|
94 TPtrC8 subtypePtr = aString.Mid( matchLoc+1 ); |
|
95 lex.Assign( subtypePtr ); |
|
96 chr = lex.Get(); |
|
97 while ( chr ) |
|
98 { |
|
99 if ( !chr.IsAlphaDigit() && chr != '!' && chr != '#' && chr != '$' && chr != '%' && chr != '&' && |
|
100 chr != '\'' && chr != '*' && chr != '+' && chr != '-' && chr != '.' && chr != '^' && |
|
101 chr != '_' && chr != '`' && chr != '{' && chr != '|' && chr != '}' && chr != '~' ) |
|
102 { |
|
103 return EFalse; |
|
104 } |
|
105 chr = lex.Get(); |
|
106 } |
|
107 |
|
108 return ETrue; |
|
109 } |
|
110 |
|
111 // End of File |