2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Name : SdpConnectionField.h
17 * Interface : SDK API, SDP Codec API
24 #ifndef CSDPCONNECTIONFIELD_H
25 #define CSDPCONNECTIONFIELD_H
30 #include <stringpool.h>
34 const TUint KDefaultNumOfAddress = 1;
36 // FORWARD DECLARATIONS
45 * This class encapsulates the connection information field of
46 * the Session Description Protocol.
48 * The normative reference for correct formatting and values is
49 * draft-ietf-mmusic-sdp-new-14 unless specified otherwise in
50 * member documentation. The implementation supports this normative
51 * reference, but does not enforce it fully.
55 class CSdpConnectionField : public CBase
57 public: // Constructors and destructor
60 * Constructs a new connection field.
62 * @param aText A string containing a correctly
63 * formatted field value terminated by a CRLF.
64 * @return a new instance.
66 IMPORT_C static CSdpConnectionField* DecodeL( const TDesC8& aText );
69 * Constructs a new connection field and adds the pointer to the
72 * @param aText A string containing a correctly
73 * formatted field value terminated by a CRLF.
74 * @return a new instance.
76 IMPORT_C static CSdpConnectionField* DecodeLC( const TDesC8& aText );
79 * Constructs a new connection field.
80 * Also sets the network type to "IN" and address type to "IP4" or
81 * "IP6" depending on the address family of aAddress.
83 * @param aAddress IP address from either KAfInet
85 * @param aTTL Time-To-Live for IP4 multicasts, set it as
86 * KErrNotFound if IPv6 multicast or IPv4 unicast
87 * @param aNumOfAddress Number of addresses in multicast,
88 * if unicast, must be 1
89 * @return a new instance.
91 IMPORT_C static CSdpConnectionField* NewL(
92 const TInetAddr& aAddress,
93 TInt aTTL = KErrNotFound,
94 TUint aNumOfAddress = KDefaultNumOfAddress );
97 * Constructs a new connection field.
99 * @param aNetType A valid network type name from the pre-
100 * defined SDP string table or defined by the user.
101 * @paramaAddressType A valid address type name from the
102 * pre-defined SDP string table or defined by the user.
103 * @param const TDesC8& aAddress: A valid address of the address type.
104 * Can contain TTL & number of addresses parameter as well.
105 * @return a new instance.
107 IMPORT_C static CSdpConnectionField* NewL(
109 RStringF aAddressType,
110 const TDesC8& aAddress );
113 * Constructs a new connection field and adds the pointer to the
114 * cleanup stack. Also sets the network type to "IN" and address type
115 * to "IP4" or "IP6" depending on the address family of aAddress.
117 * @param aAddress IP address from either KAfInet
119 * @param aTTL Time-To-Live for IP4 multicasts, set it as
120 * KErrNotFound if IPv6 multicast or IPv4 unicast
121 * @param aNumOfAddress Number of addresses in multicast,
122 * if unicast, must be 1
123 * @return a new instance.
125 IMPORT_C static CSdpConnectionField* NewLC(
126 const TInetAddr& aAddress,
127 TInt aTTL = KErrNotFound,
128 TUint aNumOfAddress = KDefaultNumOfAddress );
131 * Construct a new connection field and adds the pointer to the
134 * @param aNetType A valid network type name from the pre-
135 * defined SDP string table or defined by the user
136 * @paramaAddressType A valid address type name from the
137 * pre-defined SDP string table or defined by the user
138 * @param const TDesC8& aAddress: A valid address of the address type.
139 * Can contain TTL & number of addresses parameter as well.
140 * @return a new instance.
142 IMPORT_C static CSdpConnectionField* NewLC(
143 RStringF aNetType, RStringF aAddressType, const TDesC8& aAddress );
146 * Deletes the resources held by the instance.
148 IMPORT_C ~CSdpConnectionField();
150 public: // New functions
153 * Outputs the field formatted according to SDP syntax and including
154 * the terminating CRLF.
156 * @param aStream: Stream used for output. On return the
157 * stream includes correctly formatted connection field.
159 IMPORT_C void EncodeL( RWriteStream& aStream ) const;
162 * Creates a new instance that is equal to the target.
164 * @return a new instance.
166 IMPORT_C CSdpConnectionField* CloneL() const;
169 * Compares this instance to another for equality.
171 * @param const CSdpConnectionField& aObj: The instance to compare to.
172 * @return ETrue if equal, EFalse if not.
174 IMPORT_C TBool operator== ( const CSdpConnectionField& aObj ) const;
177 * Gets the network type that is from the pre-defined SDP string table
178 * or given by the user.
180 * @return The network type.
182 IMPORT_C RStringF NetType() const;
185 * Gets the address type that is from the pre-defined SDP string table
186 * or given by the user.
188 * @return The address type.
190 IMPORT_C RStringF AddressType() const;
195 * @return Address as an IP address or null if it is
196 * not an IP address. This may be e.g. when the address
197 * has been specified as a FQDN. In this case, the address
198 * can be accessed using the other getters.
200 IMPORT_C const TInetAddr* InetAddress() const;
205 * @return Address as a string.
207 IMPORT_C const TDesC8& Address() const;
210 * Sets the address, network and address type. Also sets the network
211 * type to "IN" and address type to "IP4" or "IP6" depending on the
212 * address family of aAddress.
214 * @param aValue The new address.
215 * @param aTTL Time-To-Live for IP4 multicasts, set it as
216 * KErrNotFound if IPv6 multicast or IPv4 unicast
217 * @param aNumOfAddress Number of addresses in multicast,
218 * if unicast, must be 1.
219 * @leave KErrSdpCodecConnectionField ifaddress to be set is wrongly
222 IMPORT_C void SetInetAddressL( const TInetAddr& aValue,
223 TInt aTTL = KErrNotFound,
224 TUint aNumOfAddress = KDefaultNumOfAddress);
227 * Sets the address, network and address type.
229 * @param aNetType A valid network type name from the pre-
230 * defined SDP string table or defined by the user
231 * @param aAddressType A valid address type name from the
232 * pre-defined SDP string table or defined by the user
233 * @param aAddress A valid address of the address type.
235 IMPORT_C void SetAddressL( RStringF aNetType,
236 RStringF aAddressType,
237 const TDesC8& aAddress );
240 * Gets TTL attribute.
242 * @return TTL or KErrNotFound, if one is not available for the address
244 IMPORT_C TInt TTLValue() const;
247 * Sets TTL attribute (only valid for IP4 multicasts).
248 * Leaves if trying to set TTL to address that doesn't support it.
250 * @param aTTL Time-To-Live for IP4 multicasts
251 * @leave KErrSdpCodecConnectionField if aTTL is invalid.
253 IMPORT_C void SetTTLL( TInt aTTL );
256 * Gets the number of addresses (can be more than 1 for multicasts).
257 * Multicast addresses are contiguously allocated above the base
260 * @return Number of addresses
262 IMPORT_C TInt NumOfAddress() const;
265 * Sets the number of addreses allocated for multicast.
267 * @param aNumOfAddress Number of addresses in multicast
268 * @leave KErrSdpCodecConnectionField if the address is unicast.
270 IMPORT_C void SetNumOfAddressL( TUint aNumOfAddress );
272 public: // Internal to codec
275 * Externalizes the object to stream
277 * @param aStream Stream where the object's state will be stored
279 void ExternalizeL( RWriteStream& aStream ) const;
282 * Creates object from the stream data
284 * @param aStream Stream where the object's state will be read
285 * @return Initialized object
287 static CSdpConnectionField* InternalizeL( RReadStream& aStream );
294 CSdpConnectionField();
297 * 2nd phase constructor
299 * @param aText A string containing a correctly formatted field value
300 * terminated by a CRLF.
302 void ConstructL( const TDesC8& aText );
305 * 2nd phase constructor
307 * @param aAddress IP address from either KAfInet or KAfInet6 family
308 * @param aTTL Time-To-Live for IP4 multicasts
309 * @param aNumOfAddress Nubmer of addresses in multicast
311 void ConstructL( const TInetAddr& aAddress,
312 TInt aTTL, TUint aNumOfAddress );
315 * 2nd phase constructor
317 * @param aNetType A valid network type name from the pre-defined
318 * SDP string table or defined by the user
319 * @param aAddressType A valid address type name from the pre-defined
320 * SDP string table or defined by the user
321 * @param aAddress A valid address of the address type
323 void ConstructL( RStringF aNetType, RStringF aAddressType,
324 const TDesC8& aAddress );
327 * Checks if the address is valid against given arguments
329 * @param aAddressTypeIP4 The given type of address (EFalse = IP6)
330 * @param aAddress Address with possibly TTL & number of addresses
331 * @return error code (KErrNone if valid)
333 TInt IsValidAddress( TBool aAddressTypeIP4,
334 const TDesC8& aAddress ) const;
337 * Checks if the address is valid against given arguments
339 * @param aAddress Address in TInetAddr format
340 * @param aTTL TTL attribute
341 * @param aNumOfAddress Number off addresses
342 * @return error code (KErrNone if valid)
344 TInt IsValidAddress( const TInetAddr& aAddress,
345 TInt aTTL, TUint aNumOfAddress ) const;
348 * Parses address field
350 * @param aAddressTypeIP4 The given type of address (EFalse = IP6)
351 * @param aAddress Address with possibly TTL & number of addresses
352 * @param aTTL TTL value is stored here (or KErrNotFound)
353 * @param aNumberOfAddresses Range of addreses
354 * @return The address
356 HBufC8* ParseAddressFieldL( TBool aAddressTypeIP4,
357 const TDesC8& aAddress,
359 TUint& aNumberOfAddresses ) const;
364 * @param aPos Position of the (first) separation mark
365 * @param aTTL TTL value is stored here (or KErrNotFound)
366 * @param aAddr Addres in TInetAddr format
367 * @param aAddress The whole address field
368 * @param aNumberOfAddresses Range of addreses
369 * @return The address
371 HBufC8* ParseIP4AddressL( TInt aPos,
373 const TDesC8& aAddress,
375 TUint& aNumberOfAddresses ) const;
380 * @param aPos Position of the (first) separation mark
381 * @param aTTL TTL value is stored here (or KErrNotFound)
382 * @param aAddr Addres in TInetAddr format
383 * @param aAddress The whole address field
384 * @param aNumberOfAddresses Range of addreses
385 * @return The address
387 HBufC8* ParseIP6AddressL( TInt aPos,
389 const TDesC8& aAddress,
391 TUint& aNumberOfAddresses ) const;
394 * Copies given network type to iNetType and verifies aNetType to
397 * @param aNetType Given network type
399 void CopyNetTypeL( const TDesC8& aNetType );
402 * Copies given address type to iAddressType and verifies aAddrType
405 * @param aAddrType Given address type
407 void CopyAddressTypeL( const TDesC8& aAddrType );
410 * Copies address to iAddress, and initalizes TTL & number of addresses,
413 * @param aAddress Address string, which can also contain TTL
414 * and number of addresses attributes
416 void CopyAddressL( const TDesC8& aAddress, RStringPool aPool );
424 RStringF iAddressType;
426 // mutable TInetAddr for InetAddress()
427 mutable TInetAddr iInetAddress;
429 // Address in text format
432 // TTL for IP4 multicast addresses
434 // Number of addresses
443 #endif // CSDPCONNECTIONFIELD_H