|
1 /* |
|
2 * Copyright (c) 2006-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CNATFWUNSAFADDRESSATTRIBUTE_H |
|
22 #define CNATFWUNSAFADDRESSATTRIBUTE_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <in_sock.h> |
|
26 #include "natfwinternaldefs.h" //UNIT_TEST |
|
27 #include "natfwunsafattribute.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 |
|
31 // CLASS DECLARATION |
|
32 /** |
|
33 * An abstract base class for UNSAF attributes having |
|
34 * the same syntax as MAPPED-ADDRESS. |
|
35 */ |
|
36 class CNATFWUNSAFAddressAttribute : public CNATFWUNSAFAttribute |
|
37 { |
|
38 public: // Constructors and destructor |
|
39 |
|
40 /** |
|
41 * Destructor, deletes the resources of CNATFWUNSAFAddressAttribute. |
|
42 */ |
|
43 virtual ~CNATFWUNSAFAddressAttribute(); |
|
44 |
|
45 public: // From CNATFWUNSAFAttribute |
|
46 |
|
47 HBufC8* EncodeValueL() const; |
|
48 |
|
49 public: // New functions |
|
50 |
|
51 /** |
|
52 * Returns modifiable address |
|
53 * @return the address |
|
54 */ |
|
55 IMPORT_C TInetAddr& Address(); |
|
56 |
|
57 /** |
|
58 * Returns non-modifiable address |
|
59 * @return the address |
|
60 */ |
|
61 IMPORT_C const TInetAddr& Address() const; |
|
62 |
|
63 protected: // Constructors |
|
64 |
|
65 CNATFWUNSAFAddressAttribute(); |
|
66 CNATFWUNSAFAddressAttribute(const TInetAddr& aInetAddr); |
|
67 |
|
68 protected: // New functions |
|
69 |
|
70 /** |
|
71 * Checks if the contained ip-address is an IPv6 address. |
|
72 * @return ETrue if IPv6 address, EFalse if IPv4 address. |
|
73 */ |
|
74 TBool IsIPv6Address() const; |
|
75 |
|
76 /** |
|
77 * Checks if the ip-address is an IPv6 address. |
|
78 * @param aInetAddr IP-address |
|
79 * @return ETrue if IPv6 address, EFalse if IPv4 address. |
|
80 */ |
|
81 TBool IsIPv6Address(const TInetAddr& aInetAddr) const; |
|
82 |
|
83 /** |
|
84 * Encodes the address part (IP address and port) of the contained |
|
85 * IP-address. |
|
86 * @param aResult Buffer where the result will be written |
|
87 */ |
|
88 virtual void EncodeAddressL(TDes8& aResult) const; |
|
89 |
|
90 /** |
|
91 * Encodes the address part (IP address and port) |
|
92 * @param aInetAddr IP-address to encode |
|
93 * @param aResult Buffer where the result will be written |
|
94 */ |
|
95 void EncodeAddressL(const TInetAddr& aInetAddr, |
|
96 TDes8& aResult) const; |
|
97 |
|
98 /** |
|
99 * Decodes the value part of the attribute and updates iInetAddr |
|
100 * accordingly. |
|
101 * @param aValue Value part of the attribute to be decoded |
|
102 */ |
|
103 void DecodeValueL(const TDesC8& aValue); |
|
104 |
|
105 /** |
|
106 * Check the attribute's length field has a valid value. |
|
107 * @param aByteStream Stream containing attribute in binary format, |
|
108 * starting from the type-field. |
|
109 * @leave KErrCorrupt If the length field in aByteStream is invalid |
|
110 */ |
|
111 static void CheckLengthL(const TDesC8& aByteStream); |
|
112 |
|
113 private: // New functions, for internal use |
|
114 |
|
115 /** |
|
116 * Decodes an IPv6 address and updates iInetAddr accordingly. |
|
117 * @param aValue Address part of the attribute to be decoded |
|
118 */ |
|
119 void DecodeIPv6AddressL(const TDesC8& aValue); |
|
120 |
|
121 protected: // Data |
|
122 |
|
123 TInetAddr iInetAddr; |
|
124 |
|
125 //Values are from RFC 3489 |
|
126 enum TEncodedValue |
|
127 { |
|
128 //Offset to fields inside the attribute value |
|
129 EFamilyOffset = 1, |
|
130 EPortOffset = 2, |
|
131 EAddressOffset = 4, |
|
132 |
|
133 KAddressFamilyIPv4 = 0x01, |
|
134 KAddressFamilyIPv6 = 0x02, |
|
135 |
|
136 //Size in bytes of the attribute value |
|
137 EAttributeValueSizeIPv4 = 8, |
|
138 EAttributeValueSizeIPv6 = 20 |
|
139 }; |
|
140 |
|
141 private: // For testing purposes |
|
142 |
|
143 UNIT_TEST(UT_CNATFWUNSAFMessage) |
|
144 UNIT_TEST(UT_CNATFWUNSAFMessageFactory) |
|
145 UNIT_TEST(UT_CNATFWUNSAFMappedAddressAttribute) |
|
146 UNIT_TEST(UT_CNATFWUNSAFAlternateServerAttribute) |
|
147 UNIT_TEST(UT_CNATFWUNSAFDestinationAddressAttribute) |
|
148 UNIT_TEST(UT_CNATFWUNSAFRelayAddressAttribute) |
|
149 UNIT_TEST(UT_CNATFWUNSAFRemoteAddressAttribute) |
|
150 UNIT_TEST(UT_CNATFWUNSAFRequestedIpAttribute) |
|
151 }; |
|
152 |
|
153 #endif // CNATFWUNSAFADDRESSATTRIBUTE_H |
|
154 |
|
155 |