1 /* |
|
2 * Copyright (c) 2007 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: Implementation of Miscallaneous service functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <uri8.h> |
|
22 #include <uriutils.h> |
|
23 #include <authority8.h> |
|
24 #include <delimitedpath8.h> |
|
25 //#include <e32const.h> |
|
26 |
|
27 #include "vccmiscutils.h" |
|
28 #include "rubydebug.h" |
|
29 |
|
30 _LIT( KVCCSIPScheme, "sip" ); |
|
31 _LIT( KVCCSIPSScheme, "sips" ); |
|
32 _LIT( KVCCHTTPScheme, "http" ); |
|
33 _LIT( KVCCHTTPSScheme, "https" ); |
|
34 |
|
35 const TUint KAt = '@'; |
|
36 |
|
37 const TInt KVCCMinVDNLength = 5; |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Checks if 16 bit reference is valid URI (VDI). |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C TInt TVCCMiscUtils::URIValidL( const TDesC16& aURI ) |
|
46 { |
|
47 RUBY_DEBUG_BLOCK( "TVCCMiscUtils::URIValidL()" ); |
|
48 |
|
49 TUriParser parser; |
|
50 // Check if uri contains multiple @ characters |
|
51 TUint atcount( 0 ); |
|
52 for( TUint i(0); i<aURI.Length(); i++ ) |
|
53 { |
|
54 if( KAt == aURI[i] ) |
|
55 { |
|
56 ++atcount; |
|
57 } |
|
58 } |
|
59 |
|
60 if( atcount>1 ) |
|
61 { |
|
62 return KErrUnknown; |
|
63 } |
|
64 |
|
65 |
|
66 // Parse the URI |
|
67 TInt err = parser.Parse( aURI ); |
|
68 |
|
69 if ( !err ) |
|
70 { |
|
71 // Check for invalid characters |
|
72 // 0x00-0x1F and > 0x7F), space (0x20), delimiter characters ('<', '>', |
|
73 // '#', '%', '"') and unwise characters ('{', '}', '|', '\', '^', '[', |
|
74 // ']', '`') are illegal |
|
75 if ( !UriUtils::HasInvalidChars( aURI ) ) |
|
76 { |
|
77 // Check if scheme is valid |
|
78 if ( parser.IsSchemeValid() ) |
|
79 { |
|
80 // Extract the scheme for comparing |
|
81 const TDesC& scheme = parser.Extract( EUriScheme ); |
|
82 |
|
83 // SIP or SIPS scheme |
|
84 if ( scheme.Compare( KVCCSIPScheme ) == 0 || |
|
85 scheme.Compare( KVCCSIPSScheme ) == 0 ) |
|
86 { |
|
87 err = parser.Validate(); |
|
88 } |
|
89 // HTTP or HTTPS scheme |
|
90 else if ( scheme.Compare( KVCCHTTPScheme ) == 0 || |
|
91 scheme.Compare( KVCCHTTPSScheme ) == 0 ) |
|
92 { |
|
93 // Do nothing at the moment. |
|
94 } |
|
95 else |
|
96 { |
|
97 err = KErrUnknown; |
|
98 } |
|
99 } |
|
100 // No scheme, maybe a host type |
|
101 else |
|
102 { |
|
103 UriUtils::TUriHostType type = UriUtils::HostType( aURI ); |
|
104 |
|
105 switch ( type ) |
|
106 { |
|
107 case UriUtils::EIPv6Host: |
|
108 case UriUtils::EIPv4Host: |
|
109 case UriUtils::ETextHost: |
|
110 break; |
|
111 default: |
|
112 { |
|
113 err = KErrUnknown; |
|
114 break; |
|
115 } |
|
116 } // switch |
|
117 } // else |
|
118 } // if invalid characters |
|
119 else |
|
120 { |
|
121 err = KErrNotSupported; |
|
122 } |
|
123 } |
|
124 |
|
125 return err; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // Checks if reference is valid VDN. |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C TBool TVCCMiscUtils::VDNValidL( const TDesC16& aVDN ) |
|
133 { |
|
134 RUBY_DEBUG_BLOCK( "TVCCMiscUtils::VDNValidL()" ); |
|
135 |
|
136 TBool retVal( ETrue ); |
|
137 TLex input( aVDN ); |
|
138 TInt numCount( 0 ); |
|
139 |
|
140 // Is the string empty |
|
141 if ( aVDN.Length() > 0 ) |
|
142 { |
|
143 input.Mark(); |
|
144 |
|
145 // Deal with the '+' -sign at the beginning of the string |
|
146 if (input.Peek() == '+') |
|
147 { |
|
148 // Step forward |
|
149 input.Inc(); |
|
150 } |
|
151 |
|
152 for ( ;; numCount++ ) |
|
153 { |
|
154 if ( !( input.Peek().IsDigit() ) && !( input.Peek().Eos() ) ) |
|
155 { |
|
156 // Next character is not a digit or end-of-string character |
|
157 retVal = EFalse; |
|
158 break; |
|
159 } |
|
160 else if ( input.Peek().Eos() && numCount < KVCCMinVDNLength ) |
|
161 { |
|
162 // End of string but number count is too small to be a valid VDN |
|
163 retVal = EFalse; |
|
164 break; |
|
165 } |
|
166 else if ( input.Peek().Eos() && numCount >= KVCCMinVDNLength ) |
|
167 { |
|
168 // At the end of string and number count is acceptable to be a |
|
169 // valid VDN |
|
170 break; |
|
171 } |
|
172 else |
|
173 { |
|
174 // step forward |
|
175 input.Inc(); |
|
176 } |
|
177 } // for |
|
178 } |
|
179 else |
|
180 { |
|
181 // Empty string |
|
182 retVal = EFalse; |
|
183 } |
|
184 |
|
185 return retVal; |
|
186 } |
|
187 |
|