|
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 CNATFWUNSAFATTRIBUTE_H |
|
22 #define CNATFWUNSAFATTRIBUTE_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include "natfwinternaldefs.h" //UNIT_TEST |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 |
|
30 // CLASS DECLARATION |
|
31 /** |
|
32 * An abstract base class for UNSAF attributes. |
|
33 */ |
|
34 class CNATFWUNSAFAttribute : public CBase |
|
35 { |
|
36 public: // Enumerations |
|
37 |
|
38 enum TType // Values are from RFC 3489 and TURN-draft |
|
39 { |
|
40 EMappedAddress = 0x0001, |
|
41 EResponseAddress = 0x0002, |
|
42 EChangeRequest = 0x0003, |
|
43 ESourceAddress = 0x0004, |
|
44 EChangedAddress = 0x0005, |
|
45 EUsername = 0x0006, |
|
46 EPassword = 0x0007, |
|
47 EMessageIntegrity = 0x0008, |
|
48 EErrorCode = 0x0009, |
|
49 EUnknownAttributes = 0x000a, |
|
50 EReflectedFrom = 0x000b, |
|
51 ELifetime = 0x000d, |
|
52 EMagicCookie = 0x000f, |
|
53 EBandwidth = 0x0010, |
|
54 EDestinationAddress = 0x0011, |
|
55 ERemoteAddress = 0x0012, |
|
56 EData = 0x0013, |
|
57 ERealm = 0x0014, |
|
58 ENonce = 0x0015, |
|
59 ERelayAddress = 0x0016, |
|
60 ERequestedPortProps = 0x0018, |
|
61 ERequestedTransport = 0x0019, |
|
62 EXorMappedAddress = 0x0020, |
|
63 ETimerVal = 0x0021, |
|
64 ERequestedIp = 0x0022, |
|
65 EConnectStat = 0x0023, |
|
66 EPriority = 0x0024, |
|
67 EUseCandidate = 0x0025, |
|
68 EXorOnly = 0x8021, //was 0x0021, but clashes with TIMER_VAL |
|
69 EServer = 0x8022, |
|
70 EAlternateServer = 0x8023, |
|
71 EFingerprint = 0x8028, |
|
72 EIceControlled = 0x8029, |
|
73 EIceControlling = 0x802a |
|
74 }; |
|
75 |
|
76 public: // Constructors and destructor |
|
77 |
|
78 /** |
|
79 * Destructor, deletes the resources of CNATFWUNSAFAttribute. |
|
80 */ |
|
81 virtual ~CNATFWUNSAFAttribute(); |
|
82 |
|
83 public: // New pure virtual functions |
|
84 |
|
85 /** |
|
86 * The type of the UNSAF attribute |
|
87 * @return UNSAF attribute type |
|
88 */ |
|
89 virtual CNATFWUNSAFAttribute::TType Type() const = 0; |
|
90 |
|
91 public: // New functions |
|
92 |
|
93 /** |
|
94 * Encodes the UNSAF attribute including its type and length |
|
95 * @return The encoded UNSAF attribute. The ownership is |
|
96 * transferred. |
|
97 */ |
|
98 HBufC8* EncodeL() const; |
|
99 |
|
100 /** |
|
101 * Parses the byte stream for a UNSAF attribute type and length. |
|
102 * Leaves if stream does not contain enough data |
|
103 * @param aByteStream Stream to parse |
|
104 * @param aType OUT: attribute type |
|
105 * @param aTotalLength OUT: Total length of the attribute, including |
|
106 * type, length and value elements |
|
107 * @leave KErrArgument If the stream doesn't contain enough data |
|
108 */ |
|
109 static void ParseTypeAndLengthL(const TDesC8& aByteStream, |
|
110 TUint16& aType, |
|
111 TUint16& aLength); |
|
112 |
|
113 /** |
|
114 * Checks if the UNSAF attribute indicated by aType is mandatory to |
|
115 * understand. |
|
116 * @param aType UNSAF attribute type |
|
117 * @return ETrue Attribute is mandatory and must be understood |
|
118 * EFalse Attribute is optional |
|
119 */ |
|
120 static TBool IsMandatory(TUint16 aType); |
|
121 |
|
122 /** |
|
123 * Checks if the UNSAF attribute indicated by aType is word boundary |
|
124 * aligned by definition. |
|
125 * @param aType UNSAF attribute type |
|
126 * @return ETrue Attribute is word boundary aligned and must not be |
|
127 * padded out. |
|
128 * EFalse Attribute may need padding out. |
|
129 */ |
|
130 static TBool IsWordBoundaryAligned(TUint16 aType); |
|
131 |
|
132 protected: // Enums |
|
133 |
|
134 enum TEncodedAttributeOffset |
|
135 { |
|
136 //Offset to fields inside the encoded attribute |
|
137 ETypeOffset = 0, |
|
138 ELengthOffset = 2, |
|
139 EValueOffset = 4 |
|
140 }; |
|
141 |
|
142 protected: // Constructors |
|
143 |
|
144 CNATFWUNSAFAttribute(); |
|
145 |
|
146 |
|
147 protected: // New pure virtual functions |
|
148 |
|
149 /** |
|
150 * Encodes the UNSAF attribute value. |
|
151 * Used from CNATFWUNSAFAttribute::EncodeL. |
|
152 * @return The encoded UNSAF attribute value. |
|
153 * The ownership is transferred. |
|
154 */ |
|
155 virtual HBufC8* EncodeValueL() const = 0; |
|
156 |
|
157 protected: // New functions |
|
158 |
|
159 /** |
|
160 * Parses the byte stream and returns the value of length element. |
|
161 * @param aByteStream Stream to parse |
|
162 * @return Length of value element |
|
163 * @leave KErrArgument If the stream doesn't contain enough data |
|
164 */ |
|
165 static TUint16 ParseLengthL(const TDesC8& aByteStream); |
|
166 |
|
167 private: // For testing purposes |
|
168 |
|
169 UNIT_TEST(CNATFWUNSAFMessageTest) |
|
170 UNIT_TEST(CNATFWUNSAFMessageFactoryTest) |
|
171 UNIT_TEST(CNATFWUNSAFMappedAddressAttributeTest) |
|
172 UNIT_TEST(CNATFWUNSAFMessageIntegrityAttributeTest) |
|
173 }; |
|
174 |
|
175 #endif // CNATFWUNSAFATTRIBUTE_H |
|
176 |
|
177 |