|
1 /* |
|
2 * Copyright (c) 2003-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: |
|
15 * Name : SdpConnectionField.h |
|
16 * Part of : SDP Codec |
|
17 * Interface : SDK API, SDP Codec API |
|
18 * Version : 1.0 |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 |
|
24 #ifndef CSDPCONNECTIONFIELD_H |
|
25 #define CSDPCONNECTIONFIELD_H |
|
26 |
|
27 // INCLUDES |
|
28 #include <e32base.h> |
|
29 #include <in_sock.h> |
|
30 #include <stringpool.h> |
|
31 |
|
32 // CONSTANTS |
|
33 const TUint KDefaultNumOfAddress = 1; |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class RReadStream; |
|
37 class RWriteStream; |
|
38 |
|
39 // CLASS DECLARATION |
|
40 /** |
|
41 * @publishedAll |
|
42 * @released |
|
43 * |
|
44 * This class encapsulates the connection information field of |
|
45 * the Session Description Protocol. |
|
46 * |
|
47 * The normative reference for correct formatting and values is |
|
48 * draft-ietf-mmusic-sdp-new-14 unless specified otherwise in |
|
49 * member documentation. The implementation supports this normative |
|
50 * reference, but does not enforce it fully. |
|
51 * |
|
52 * @lib sdpcodec.lib |
|
53 */ |
|
54 class CSdpConnectionField : public CBase |
|
55 { |
|
56 public: // Constructors and destructor |
|
57 |
|
58 /** |
|
59 * Constructs a new connection field. |
|
60 * |
|
61 * @param aText A string containing a correctly |
|
62 * formatted field value terminated by a CRLF. |
|
63 * @return a new instance. |
|
64 */ |
|
65 IMPORT_C static CSdpConnectionField* DecodeL( const TDesC8& aText ); |
|
66 |
|
67 /** |
|
68 * Constructs a new connection field and adds the pointer to the |
|
69 * cleanup stack. |
|
70 * |
|
71 * @param aText A string containing a correctly |
|
72 * formatted field value terminated by a CRLF. |
|
73 * @return a new instance. |
|
74 */ |
|
75 IMPORT_C static CSdpConnectionField* DecodeLC( const TDesC8& aText ); |
|
76 |
|
77 /** |
|
78 * Constructs a new connection field. |
|
79 * Also sets the network type to "IN" and address type to "IP4" or |
|
80 * "IP6" depending on the address family of aAddress. |
|
81 * |
|
82 * @param aAddress IP address from either KAfInet |
|
83 * or KAfInet6 family |
|
84 * @param aTTL Time-To-Live for IP4 multicasts, set it as |
|
85 * KErrNotFound if IPv6 multicast or IPv4 unicast |
|
86 * @param aNumOfAddress Number of addresses in multicast, |
|
87 * if unicast, must be 1 |
|
88 * @return a new instance. |
|
89 */ |
|
90 IMPORT_C static CSdpConnectionField* NewL( |
|
91 const TInetAddr& aAddress, |
|
92 TInt aTTL = KErrNotFound, |
|
93 TUint aNumOfAddress = KDefaultNumOfAddress ); |
|
94 |
|
95 /** |
|
96 * Constructs a new connection field. |
|
97 * |
|
98 * @param aNetType A valid network type name from the pre- |
|
99 * defined SDP string table or defined by the user. |
|
100 * @paramaAddressType A valid address type name from the |
|
101 * pre-defined SDP string table or defined by the user. |
|
102 * @param const TDesC8& aAddress: A valid address of the address type. |
|
103 * Can contain TTL & number of addresses parameter as well. |
|
104 * @return a new instance. |
|
105 */ |
|
106 IMPORT_C static CSdpConnectionField* NewL( |
|
107 RStringF aNetType, |
|
108 RStringF aAddressType, |
|
109 const TDesC8& aAddress ); |
|
110 |
|
111 /** |
|
112 * Constructs a new connection field and adds the pointer to the |
|
113 * cleanup stack. Also sets the network type to "IN" and address type |
|
114 * to "IP4" or "IP6" depending on the address family of aAddress. |
|
115 * |
|
116 * @param aAddress IP address from either KAfInet |
|
117 * or KAfInet6 family |
|
118 * @param aTTL Time-To-Live for IP4 multicasts, set it as |
|
119 * KErrNotFound if IPv6 multicast or IPv4 unicast |
|
120 * @param aNumOfAddress Number of addresses in multicast, |
|
121 * if unicast, must be 1 |
|
122 * @return a new instance. |
|
123 */ |
|
124 IMPORT_C static CSdpConnectionField* NewLC( |
|
125 const TInetAddr& aAddress, |
|
126 TInt aTTL = KErrNotFound, |
|
127 TUint aNumOfAddress = KDefaultNumOfAddress ); |
|
128 |
|
129 /** |
|
130 * Construct a new connection field and adds the pointer to the |
|
131 * cleanup stack. |
|
132 * |
|
133 * @param aNetType A valid network type name from the pre- |
|
134 * defined SDP string table or defined by the user |
|
135 * @paramaAddressType A valid address type name from the |
|
136 * pre-defined SDP string table or defined by the user |
|
137 * @param const TDesC8& aAddress: A valid address of the address type. |
|
138 * Can contain TTL & number of addresses parameter as well. |
|
139 * @return a new instance. |
|
140 */ |
|
141 IMPORT_C static CSdpConnectionField* NewLC( |
|
142 RStringF aNetType, RStringF aAddressType, const TDesC8& aAddress ); |
|
143 |
|
144 /** |
|
145 * Deletes the resources held by the instance. |
|
146 */ |
|
147 IMPORT_C ~CSdpConnectionField(); |
|
148 |
|
149 public: // New functions |
|
150 |
|
151 /** |
|
152 * Outputs the field formatted according to SDP syntax and including |
|
153 * the terminating CRLF. |
|
154 * |
|
155 * @param aStream: Stream used for output. On return the |
|
156 * stream includes correctly formatted connection field. |
|
157 */ |
|
158 IMPORT_C void EncodeL( RWriteStream& aStream ) const; |
|
159 |
|
160 /** |
|
161 * Creates a new instance that is equal to the target. |
|
162 * |
|
163 * @return a new instance. |
|
164 */ |
|
165 IMPORT_C CSdpConnectionField* CloneL() const; |
|
166 |
|
167 /** |
|
168 * Compares this instance to another for equality. |
|
169 * |
|
170 * @param const CSdpConnectionField& aObj: The instance to compare to. |
|
171 * @return ETrue if equal, EFalse if not. |
|
172 */ |
|
173 IMPORT_C TBool operator== ( const CSdpConnectionField& aObj ) const; |
|
174 |
|
175 /** |
|
176 * Gets the network type that is from the pre-defined SDP string table |
|
177 * or given by the user. |
|
178 * |
|
179 * @return The network type. |
|
180 */ |
|
181 IMPORT_C RStringF NetType() const; |
|
182 |
|
183 /** |
|
184 * Gets the address type that is from the pre-defined SDP string table |
|
185 * or given by the user. |
|
186 * |
|
187 * @return The address type. |
|
188 */ |
|
189 IMPORT_C RStringF AddressType() const; |
|
190 |
|
191 /** |
|
192 * Gets the address. |
|
193 * |
|
194 * @return Address as an IP address or null if it is |
|
195 * not an IP address. This may be e.g. when the address |
|
196 * has been specified as a FQDN. In this case, the address |
|
197 * can be accessed using the other getters. |
|
198 */ |
|
199 IMPORT_C const TInetAddr* InetAddress() const; |
|
200 |
|
201 /** |
|
202 * Gets the address. |
|
203 * |
|
204 * @return Address as a string. |
|
205 */ |
|
206 IMPORT_C const TDesC8& Address() const; |
|
207 |
|
208 /** |
|
209 * Sets the address, network and address type. Also sets the network |
|
210 * type to "IN" and address type to "IP4" or "IP6" depending on the |
|
211 * address family of aAddress. |
|
212 * |
|
213 * @param aValue The new address. |
|
214 * @param aTTL Time-To-Live for IP4 multicasts, set it as |
|
215 * KErrNotFound if IPv6 multicast or IPv4 unicast |
|
216 * @param aNumOfAddress Number of addresses in multicast, |
|
217 * if unicast, must be 1. |
|
218 * @leave KErrSdpCodecConnectionField ifaddress to be set is wrongly |
|
219 * formatted. |
|
220 */ |
|
221 IMPORT_C void SetInetAddressL( const TInetAddr& aValue, |
|
222 TInt aTTL = KErrNotFound, |
|
223 TUint aNumOfAddress = KDefaultNumOfAddress); |
|
224 |
|
225 /** |
|
226 * Sets the address, network and address type. |
|
227 * |
|
228 * @param aNetType A valid network type name from the pre- |
|
229 * defined SDP string table or defined by the user |
|
230 * @param aAddressType A valid address type name from the |
|
231 * pre-defined SDP string table or defined by the user |
|
232 * @param aAddress A valid address of the address type. |
|
233 */ |
|
234 IMPORT_C void SetAddressL( RStringF aNetType, |
|
235 RStringF aAddressType, |
|
236 const TDesC8& aAddress ); |
|
237 |
|
238 /** |
|
239 * Gets TTL attribute. |
|
240 * |
|
241 * @return TTL or KErrNotFound, if one is not available for the address |
|
242 */ |
|
243 IMPORT_C TInt TTLValue() const; |
|
244 |
|
245 /** |
|
246 * Sets TTL attribute (only valid for IP4 multicasts). |
|
247 * Leaves if trying to set TTL to address that doesn't support it. |
|
248 * |
|
249 * @param aTTL Time-To-Live for IP4 multicasts |
|
250 * @leave KErrSdpCodecConnectionField if aTTL is invalid. |
|
251 */ |
|
252 IMPORT_C void SetTTLL( TInt aTTL ); |
|
253 |
|
254 /** |
|
255 * Gets the number of addresses (can be more than 1 for multicasts). |
|
256 * Multicast addresses are contiguously allocated above the base |
|
257 * address. |
|
258 * |
|
259 * @return Number of addresses |
|
260 */ |
|
261 IMPORT_C TInt NumOfAddress() const; |
|
262 |
|
263 /** |
|
264 * Sets the number of addreses allocated for multicast. |
|
265 * |
|
266 * @param aNumOfAddress Number of addresses in multicast |
|
267 * @leave KErrSdpCodecConnectionField if the address is unicast. |
|
268 */ |
|
269 IMPORT_C void SetNumOfAddressL( TUint aNumOfAddress ); |
|
270 |
|
271 public: // Internal to codec |
|
272 |
|
273 /** |
|
274 * Externalizes the object to stream |
|
275 * |
|
276 * @param aStream Stream where the object's state will be stored |
|
277 */ |
|
278 void ExternalizeL( RWriteStream& aStream ) const; |
|
279 |
|
280 /** |
|
281 * Creates object from the stream data |
|
282 * |
|
283 * @param aStream Stream where the object's state will be read |
|
284 * @return Initialized object |
|
285 */ |
|
286 static CSdpConnectionField* InternalizeL( RReadStream& aStream ); |
|
287 |
|
288 private: // Internal |
|
289 |
|
290 /** |
|
291 * Constructor |
|
292 */ |
|
293 CSdpConnectionField(); |
|
294 |
|
295 /** |
|
296 * 2nd phase constructor |
|
297 * |
|
298 * @param aText A string containing a correctly formatted field value |
|
299 * terminated by a CRLF. |
|
300 */ |
|
301 void ConstructL( const TDesC8& aText ); |
|
302 |
|
303 /** |
|
304 * 2nd phase constructor |
|
305 * |
|
306 * @param aAddress IP address from either KAfInet or KAfInet6 family |
|
307 * @param aTTL Time-To-Live for IP4 multicasts |
|
308 * @param aNumOfAddress Nubmer of addresses in multicast |
|
309 */ |
|
310 void ConstructL( const TInetAddr& aAddress, |
|
311 TInt aTTL, TUint aNumOfAddress ); |
|
312 |
|
313 /** |
|
314 * 2nd phase constructor |
|
315 * |
|
316 * @param aNetType A valid network type name from the pre-defined |
|
317 * SDP string table or defined by the user |
|
318 * @param aAddressType A valid address type name from the pre-defined |
|
319 * SDP string table or defined by the user |
|
320 * @param aAddress A valid address of the address type |
|
321 */ |
|
322 void ConstructL( RStringF aNetType, RStringF aAddressType, |
|
323 const TDesC8& aAddress ); |
|
324 |
|
325 /** |
|
326 * Checks if the address is valid against given arguments |
|
327 * |
|
328 * @param aAddressTypeIP4 The given type of address (EFalse = IP6) |
|
329 * @param aAddress Address with possibly TTL & number of addresses |
|
330 * @return error code (KErrNone if valid) |
|
331 */ |
|
332 TInt IsValidAddress( TBool aAddressTypeIP4, |
|
333 const TDesC8& aAddress ) const; |
|
334 |
|
335 /** |
|
336 * Checks if the address is valid against given arguments |
|
337 * |
|
338 * @param aAddress Address in TInetAddr format |
|
339 * @param aTTL TTL attribute |
|
340 * @param aNumOfAddress Number off addresses |
|
341 * @return error code (KErrNone if valid) |
|
342 */ |
|
343 TInt IsValidAddress( const TInetAddr& aAddress, |
|
344 TInt aTTL, TUint aNumOfAddress ) const; |
|
345 |
|
346 /** |
|
347 * Parses address field |
|
348 * |
|
349 * @param aAddressTypeIP4 The given type of address (EFalse = IP6) |
|
350 * @param aAddress Address with possibly TTL & number of addresses |
|
351 * @param aTTL TTL value is stored here (or KErrNotFound) |
|
352 * @param aNumberOfAddresses Range of addreses |
|
353 * @return The address |
|
354 */ |
|
355 HBufC8* ParseAddressFieldL( TBool aAddressTypeIP4, |
|
356 const TDesC8& aAddress, |
|
357 TInt& aTTL, |
|
358 TUint& aNumberOfAddresses ) const; |
|
359 |
|
360 /** |
|
361 * Parses IP4 address |
|
362 * |
|
363 * @param aPos Position of the (first) separation mark |
|
364 * @param aTTL TTL value is stored here (or KErrNotFound) |
|
365 * @param aAddr Addres in TInetAddr format |
|
366 * @param aAddress The whole address field |
|
367 * @param aNumberOfAddresses Range of addreses |
|
368 * @return The address |
|
369 */ |
|
370 HBufC8* ParseIP4AddressL( TInt aPos, |
|
371 TInetAddr& aAddr, |
|
372 const TDesC8& aAddress, |
|
373 TInt& aTTL, |
|
374 TUint& aNumberOfAddresses ) const; |
|
375 |
|
376 /** |
|
377 * Parses IP6 address |
|
378 * |
|
379 * @param aPos Position of the (first) separation mark |
|
380 * @param aTTL TTL value is stored here (or KErrNotFound) |
|
381 * @param aAddr Addres in TInetAddr format |
|
382 * @param aAddress The whole address field |
|
383 * @param aNumberOfAddresses Range of addreses |
|
384 * @return The address |
|
385 */ |
|
386 HBufC8* ParseIP6AddressL( TInt aPos, |
|
387 TInetAddr& aAddr, |
|
388 const TDesC8& aAddress, |
|
389 TInt& aTTL, |
|
390 TUint& aNumberOfAddresses ) const; |
|
391 |
|
392 /** |
|
393 * Copies given network type to iNetType and verifies aNetType to |
|
394 * be valid |
|
395 * |
|
396 * @param aNetType Given network type |
|
397 */ |
|
398 void CopyNetTypeL( const TDesC8& aNetType ); |
|
399 |
|
400 /** |
|
401 * Copies given address type to iAddressType and verifies aAddrType |
|
402 * to be valid |
|
403 * |
|
404 * @param aAddrType Given address type |
|
405 */ |
|
406 void CopyAddressTypeL( const TDesC8& aAddrType ); |
|
407 |
|
408 /** |
|
409 * Copies address to iAddress, and initalizes TTL & number of addresses, |
|
410 * leaves on error |
|
411 * |
|
412 * @param aAddress Address string, which can also contain TTL |
|
413 * and number of addresses attributes |
|
414 */ |
|
415 void CopyAddressL( const TDesC8& aAddress, RStringPool aPool ); |
|
416 |
|
417 private: // Data |
|
418 |
|
419 // <network type> |
|
420 RStringF iNetType; |
|
421 |
|
422 // <address type> |
|
423 RStringF iAddressType; |
|
424 |
|
425 // mutable TInetAddr for InetAddress() |
|
426 mutable TInetAddr iInetAddress; |
|
427 |
|
428 // Address in text format |
|
429 HBufC8* iAddress; |
|
430 |
|
431 // TTL for IP4 multicast addresses |
|
432 TInt iTTL; |
|
433 // Number of addresses |
|
434 TUint iNumOfAddress; |
|
435 |
|
436 // String pool |
|
437 RStringPool iPool; |
|
438 |
|
439 void __DbgTestInvariant() const; |
|
440 |
|
441 |
|
442 }; |
|
443 |
|
444 #endif // CSDPCONNECTIONFIELD_H |