|
1 /* |
|
2 * Copyright (c) 2008-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: Settings handler class for svtmatching. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "svturiparser.h" |
|
20 |
|
21 // Valid characters for GSM call |
|
22 _LIT( KPhoneValidChars, "0123456789*#+pwPW" ); |
|
23 // For parsing protocol prefix and domain part out of a VoIP call URI |
|
24 _LIT( KSvtColon, ":" ); |
|
25 _LIT( KSvtAt, "@" ); |
|
26 // Indicates the start of sip uri. |
|
27 const TUint KStartBracket = '<'; |
|
28 // Indicates the end of sip uri. |
|
29 const TUint KEndBracket = '>'; |
|
30 const TUint KSpaceMark = ' '; |
|
31 const TUint KQuotationMark = '"'; |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CSvtUriParser::CSvtUriParser() |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CSvtUriParser* CSvtUriParser::NewL() |
|
48 { |
|
49 CSvtUriParser* self = new ( ELeave ) CSvtUriParser; |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CSvtUriParser::~CSvtUriParser() |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Parses sip uri by ignore domain part setting |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CSvtUriParser::ParseAddressL( |
|
67 TInt aIgnoreDomain, |
|
68 const TDesC& aOriginal, |
|
69 RBuf& aParsedAddress ) const |
|
70 { |
|
71 switch ( aIgnoreDomain ) |
|
72 { |
|
73 case 1: |
|
74 case 2: |
|
75 { |
|
76 HandleUserNamePartL( aIgnoreDomain, aOriginal, aParsedAddress ); |
|
77 break; |
|
78 } |
|
79 case 0: |
|
80 default: |
|
81 { |
|
82 aParsedAddress.Close(); |
|
83 aParsedAddress.CreateL( aOriginal ); |
|
84 break; |
|
85 } |
|
86 |
|
87 } |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Resolves display name from sip uri |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CSvtUriParser::DisplayNameFromUri( |
|
95 const TDesC& aData, |
|
96 RBuf& aDisplayname ) const |
|
97 { |
|
98 TInt ret( KErrNotFound ); |
|
99 |
|
100 TPtrC resultStr( aData ); |
|
101 aDisplayname.Close(); |
|
102 |
|
103 // resolves potential SIP Display info and removes it from uri |
|
104 // also possible "<" and ">" character are removed around the SIP uri |
|
105 TInt uriStartIndex = resultStr.LocateReverse( KStartBracket ); |
|
106 TInt uriEndIndex = resultStr.LocateReverse( KEndBracket ); |
|
107 |
|
108 if ( uriStartIndex > uriEndIndex ) |
|
109 { |
|
110 // Start and end separators in wrong order: "xxxx>xxxx<xxx" |
|
111 return KErrArgument; |
|
112 } |
|
113 |
|
114 if ( KErrNotFound != uriStartIndex && KErrNotFound != uriEndIndex ) |
|
115 { |
|
116 // brackets found so modify descriptor and save the display info |
|
117 |
|
118 // check if there is anything before "<" if there is use |
|
119 // it as displayname if match op fails. |
|
120 if ( uriStartIndex > 1 ) |
|
121 { |
|
122 TPtrC tempStr( resultStr.Left( uriStartIndex ) ); |
|
123 // remove possible quotation marks from displayname |
|
124 TInt index = tempStr.Locate( KQuotationMark ); |
|
125 if ( KErrNotFound != index ) |
|
126 { |
|
127 // marks have to be removed |
|
128 tempStr.Set( tempStr.Mid( ++index ) ); |
|
129 if ( tempStr[tempStr.Length() - 1] == KQuotationMark ) |
|
130 { |
|
131 tempStr.Set( tempStr.Left( tempStr.Length() - 1 ) ); |
|
132 } |
|
133 } |
|
134 ret = aDisplayname.Create( tempStr ); |
|
135 } |
|
136 } |
|
137 else |
|
138 { |
|
139 // it is also possible that displayname is included |
|
140 // in, in case that there is no brackets around the uri. So if there is something |
|
141 // inside quotationMarks it should be used as displayname |
|
142 |
|
143 // check if displayname is found |
|
144 TInt displayNameStart = resultStr.Locate( KQuotationMark ); |
|
145 TInt displayNameEnd = resultStr.LocateReverse( KQuotationMark ); |
|
146 |
|
147 if ( displayNameStart != KErrNotFound |
|
148 && displayNameEnd != KErrNotFound |
|
149 && displayNameStart < displayNameEnd ) |
|
150 { |
|
151 // displayname is included |
|
152 // ++, to remove quotationMark from the start |
|
153 ret = aDisplayname.Create( resultStr.Mid( ++displayNameStart, |
|
154 // -1, to remove quotationMark from the end |
|
155 displayNameEnd - displayNameStart - 1 ) ); |
|
156 } |
|
157 else |
|
158 { |
|
159 // check if there is spaces in the uri, if there is |
|
160 // everything before it belongs to display name |
|
161 TInt index = resultStr.LocateReverse( KSpaceMark ); |
|
162 |
|
163 if ( KErrNotFound != index ) |
|
164 { |
|
165 // set displayname |
|
166 ret = aDisplayname.Create( resultStr.Left( index ) ); |
|
167 } |
|
168 |
|
169 } |
|
170 } |
|
171 |
|
172 return ret; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // Check original address for spaces. |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CSvtUriParser::CheckForSpacesL( |
|
180 const TDesC& aOriginal, |
|
181 RBuf& aCheckedAddress ) const |
|
182 { |
|
183 aCheckedAddress.CreateL( aOriginal ); |
|
184 |
|
185 TInt index( 0 ); |
|
186 while ( index != KErrNotFound ) |
|
187 { |
|
188 index = aCheckedAddress.Locate( KSpaceMark ); |
|
189 |
|
190 // Remove space if itīs in begin or end of string |
|
191 if ( index == 0 || ( index == ( aCheckedAddress.Length() - 1 ) ) ) |
|
192 { |
|
193 aCheckedAddress.Delete( index, 1 ); |
|
194 } |
|
195 else |
|
196 { |
|
197 index = KErrNotFound; |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // Check is string valid for gsm call |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 TBool CSvtUriParser::IsValidGsmNumber( const TDesC& aOriginal ) const |
|
207 { |
|
208 TLex input( aOriginal ); |
|
209 TPtrC valid( KPhoneValidChars ); |
|
210 |
|
211 while ( valid.Locate( input.Peek() ) != KErrNotFound ) |
|
212 { |
|
213 input.Inc(); |
|
214 } |
|
215 |
|
216 return !input.Remainder().Length(); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Gets username part from sip uri |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 TInt CSvtUriParser::GetUserNamePart( |
|
224 const TDesC& aOriginal, |
|
225 TDes& aUserName ) const |
|
226 { |
|
227 if ( aOriginal.Length() > aUserName.MaxLength() ) |
|
228 { |
|
229 return KErrArgument; |
|
230 } |
|
231 |
|
232 aUserName.Copy( aOriginal ); |
|
233 |
|
234 // Parse protocol prefix and domain part out of a VoIP call URI |
|
235 TInt pos( aUserName.Find( KSvtColon ) ); |
|
236 if ( pos > KErrNotFound ) |
|
237 { |
|
238 aUserName.Delete( 0, pos+1 ); |
|
239 } |
|
240 |
|
241 pos = aUserName.Find( KSvtAt ); |
|
242 if ( pos > KErrNotFound ) |
|
243 { |
|
244 aUserName.Delete( pos, aUserName.Length() - pos ); |
|
245 } |
|
246 |
|
247 if ( 0 == aUserName.Length() ) |
|
248 { |
|
249 return KErrNotFound; |
|
250 } |
|
251 |
|
252 return KErrNone; |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Handles sip uri's username part for ignore domain part values 1 and 2 |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CSvtUriParser::HandleUserNamePartL( |
|
260 TInt aIgnoreDomain, |
|
261 const TDesC& aOriginal, |
|
262 RBuf& aParsedAddress ) const |
|
263 { |
|
264 if ( 0 == aOriginal.Length() ) |
|
265 { |
|
266 User::Leave( KErrArgument ); |
|
267 } |
|
268 |
|
269 HBufC* buf = HBufC::NewLC( aOriginal.Length() ); |
|
270 TPtr des( buf->Des() ); |
|
271 |
|
272 User::LeaveIfError( GetUserNamePart( aOriginal, des ) ); |
|
273 |
|
274 aParsedAddress.Close(); |
|
275 |
|
276 if ( ( 1 == aIgnoreDomain && IsValidGsmNumber( des ) ) || |
|
277 2 == aIgnoreDomain ) |
|
278 { |
|
279 // Set parsed address |
|
280 User::LeaveIfError( aParsedAddress.Create( des ) ); |
|
281 } |
|
282 else |
|
283 { |
|
284 User::LeaveIfError( aParsedAddress.Create( aOriginal ) ); |
|
285 } |
|
286 |
|
287 CleanupStack::PopAndDestroy( buf ); |
|
288 } |
|
289 |
|
290 |