|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : CSIPAuthenticateHeaderParams.cpp |
|
15 // Part of : SIP Codec |
|
16 // Version : SIP/6.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSIPAuthenticateHeaderParams.h" |
|
22 #include "sipcodecerr.h" |
|
23 #include "sipstrings.h" |
|
24 #include "sipstrconsts.h" |
|
25 #include "SIPSyntaxCheck.h" |
|
26 #include "uri8.h" |
|
27 #include "CSIPTokenizer.h" |
|
28 #include "sipcodecutils.h" |
|
29 |
|
30 // Yahoo uses this invalid character in its authentication: |
|
31 const TInt KExtraYahooChr = 2; |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // CSIPAuthenticateHeaderParams::NewL |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CSIPAuthenticateHeaderParams* CSIPAuthenticateHeaderParams::NewL( |
|
38 const CSIPAuthenticateHeaderParams& aParams) |
|
39 { |
|
40 CSIPAuthenticateHeaderParams* self = |
|
41 CSIPAuthenticateHeaderParams::NewLC (aParams); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CSIPAuthenticateHeaderParams::NewLC |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 CSIPAuthenticateHeaderParams* |
|
51 CSIPAuthenticateHeaderParams::NewLC (const CSIPAuthenticateHeaderParams& |
|
52 aParams) |
|
53 { |
|
54 CSIPAuthenticateHeaderParams* self = |
|
55 new(ELeave)CSIPAuthenticateHeaderParams; |
|
56 CleanupStack::PushL(self); |
|
57 self->CSIPParamContainerBase::ConstructL (aParams); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CSIPAuthenticateHeaderParams::CSIPAuthenticateHeaderParams |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CSIPAuthenticateHeaderParams::CSIPAuthenticateHeaderParams () |
|
66 : CSIPParamContainerBase(',') |
|
67 { |
|
68 } |
|
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // CSIPAuthenticateHeaderParams::~CSIPAuthenticateHeaderParams |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 CSIPAuthenticateHeaderParams::~CSIPAuthenticateHeaderParams () |
|
75 { |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CSIPAuthenticateHeaderParams::InternalizeL |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 CSIPAuthenticateHeaderParams* CSIPAuthenticateHeaderParams::InternalizeL( |
|
83 RReadStream& aReadStream) |
|
84 { |
|
85 CSIPAuthenticateHeaderParams* self = |
|
86 new(ELeave)CSIPAuthenticateHeaderParams; |
|
87 CleanupStack::PushL(self); |
|
88 self->DoInternalizeL(aReadStream); |
|
89 CleanupStack::Pop(self); |
|
90 return self; |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // CSIPAuthenticateHeaderParams::AddQuotesWhenEncoding |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 TBool CSIPAuthenticateHeaderParams::AddQuotesWhenEncoding( |
|
98 RStringF aParamName) const |
|
99 { |
|
100 if (aParamName == SIPStrings::StringF(SipStrConsts::ERealm) || |
|
101 aParamName == SIPStrings::StringF(SipStrConsts::ENonce) || |
|
102 aParamName == SIPStrings::StringF(SipStrConsts::EOpaque)) |
|
103 { |
|
104 return ETrue; |
|
105 } |
|
106 return EFalse; |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CSIPAuthenticateHeaderParams::CheckAndUpdateParamL |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 void CSIPAuthenticateHeaderParams::CheckAndUpdateParamL(RStringF aName, |
|
114 TBool aHasValue, |
|
115 TPtrC8& aValue) const |
|
116 { |
|
117 // realm, nonce, opaque |
|
118 if (aName == SIPStrings::StringF(SipStrConsts::ERealm) || |
|
119 aName == SIPStrings::StringF(SipStrConsts::EOpaque)) |
|
120 { |
|
121 RemoveQuotes(aValue); |
|
122 if (!SIPSyntaxCheck::QuotedStringValue(aValue)) |
|
123 { |
|
124 User::Leave(KErrSipCodecAuthenticationHeader); |
|
125 } |
|
126 return; |
|
127 } |
|
128 // nonce, cnonce |
|
129 if (aName == SIPStrings::StringF(SipStrConsts::ENonce)) |
|
130 { |
|
131 RemoveQuotes(aValue); |
|
132 if (!SIPSyntaxCheck::QuotedStringValue(aValue,KExtraYahooChr)) |
|
133 { |
|
134 User::Leave(KErrSipCodecAuthorizationHeader); |
|
135 } |
|
136 return; |
|
137 } |
|
138 // algorithm, stale |
|
139 if (aName == SIPStrings::StringF(SipStrConsts::EAlgorithm) || |
|
140 aName == SIPStrings::StringF(SipStrConsts::EStale)) |
|
141 { |
|
142 RemoveQuotes(aValue); |
|
143 if (!SIPSyntaxCheck::Token(aValue)) |
|
144 { |
|
145 User::Leave(KErrSipCodecAuthenticationHeader); |
|
146 } |
|
147 return; |
|
148 } |
|
149 // qop |
|
150 if (aName == SIPStrings::StringF(SipStrConsts::EQop)) |
|
151 { |
|
152 if (!SIPSyntaxCheck::QuotedTokenWithComma(aValue)) |
|
153 { |
|
154 User::Leave(KErrSipCodecAuthenticationHeader); |
|
155 } |
|
156 return; |
|
157 } |
|
158 // domain |
|
159 if (aName == SIPStrings::StringF(SipStrConsts::EDomain)) |
|
160 { |
|
161 CSIPTokenizer* tokenizer = CSIPTokenizer::NewLC(aValue, ' '); |
|
162 for(TInt i=0; i<tokenizer->Tokens().Count(); i++) |
|
163 { |
|
164 TUriParser8 parser; |
|
165 TPtrC8 valueWithoutQuotes; |
|
166 TInt error = 0; |
|
167 if(SIPCodecUtils::ValueWithoutQuotes |
|
168 (tokenizer->Tokens()[i], valueWithoutQuotes) |
|
169 != KErrNone) |
|
170 { |
|
171 User::Leave(KErrSipCodecAuthenticationHeader); |
|
172 } |
|
173 error = parser.Parse(valueWithoutQuotes); |
|
174 if ( error == KErrNoMemory ) |
|
175 { |
|
176 User::Leave(KErrNoMemory); |
|
177 } |
|
178 if ( error != KErrNone) |
|
179 { |
|
180 User::Leave(KErrSipCodecAuthenticationHeader); |
|
181 } |
|
182 } |
|
183 CleanupStack::PopAndDestroy(tokenizer); |
|
184 return; |
|
185 } |
|
186 // other |
|
187 if (!SIPSyntaxCheck::Token(aName.DesC())) |
|
188 { |
|
189 User::Leave(KErrSipCodecAuthenticationHeader); |
|
190 } |
|
191 if (aHasValue && |
|
192 !SIPSyntaxCheck::Token(aValue) && |
|
193 !SIPSyntaxCheck::QuotedString(aValue)) |
|
194 { |
|
195 User::Leave(KErrSipCodecAuthenticationHeader); |
|
196 } |
|
197 } |