|
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 NATFWUNSAFUTILS_H |
|
22 #define NATFWUNSAFUTILS_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 |
|
29 // CLASS DECLARATION |
|
30 /** |
|
31 * Utility functions |
|
32 * |
|
33 * @lib natfwunsafprotocols.lib |
|
34 */ |
|
35 NONSHARABLE_CLASS(NATFWUNSAFUtils) |
|
36 { |
|
37 public: // New functions |
|
38 |
|
39 inline static TUint8 HighByte(TUint16 aValue) |
|
40 { |
|
41 return aValue >> 8; |
|
42 } |
|
43 |
|
44 inline static TUint8 LowByte(TUint16 aValue) |
|
45 { |
|
46 return aValue & 0xff; |
|
47 } |
|
48 |
|
49 inline static TUint16 HighWord(TUint32 aValue) |
|
50 { |
|
51 return aValue >> 16; |
|
52 } |
|
53 |
|
54 inline static TUint16 LowWord(TUint32 aValue) |
|
55 { |
|
56 return aValue & 0xffff; |
|
57 } |
|
58 |
|
59 inline static TUint32 HighDWord(TUint64 aValue) |
|
60 { |
|
61 return aValue >> 32; |
|
62 } |
|
63 |
|
64 inline static TUint32 LowDWord(TUint64 aValue) |
|
65 { |
|
66 return aValue & 0xffffffff; |
|
67 } |
|
68 |
|
69 /** |
|
70 * Writes an unsigned 16 bit value in network byte order (big-endian) |
|
71 * into aPtr, at the given position. |
|
72 * @param aPtr Buffer where the aValue is written, must have enough |
|
73 * space |
|
74 * @param aOffset Position inside the buffer pointed by aPtr, where the |
|
75 * value is written. |
|
76 * @param aValue 16 bit unsigned value to write |
|
77 * @leave KErrArgument if aPtr is too short to contain enough data |
|
78 */ |
|
79 static void WriteNetworkOrder16L(TDes8& aPtr, |
|
80 TInt aOffset, |
|
81 TUint16 aValue); |
|
82 |
|
83 /** |
|
84 * Writes an unsigned 32 bit value in network byte order (big-endian) |
|
85 * into aPtr, at the given position. |
|
86 * @param aPtr Buffer where the aValue is written, must have enough |
|
87 * space |
|
88 * @param aOffset Position inside the buffer pointed by aPtr, where the |
|
89 * value is written. |
|
90 * @param aValue 32 bit unsigned value to write |
|
91 * @leave KErrArgument if aPtr is too short to contain enough data |
|
92 */ |
|
93 static void WriteNetworkOrder32L(TDes8& aPtr, |
|
94 TInt aOffset, |
|
95 TUint32 aValue); |
|
96 |
|
97 /** |
|
98 * Writes an unsigned 64 bit value in network byte order (big-endian) |
|
99 * into aPtr, at the given position. |
|
100 * @param aPtr Buffer where the aValue is written, must have enough |
|
101 * space |
|
102 * @param aOffset Position inside the buffer pointed by aPtr, where the |
|
103 * value is written. |
|
104 * @param aValue 64 bit unsigned value to write |
|
105 * @leave KErrArgument if aPtr is too short to contain enough data |
|
106 */ |
|
107 static void WriteNetworkOrder64L(TDes8& aPtr, |
|
108 TInt aOffset, |
|
109 TUint64 aValue); |
|
110 |
|
111 /** |
|
112 * Gets a quadruple word from a byte stream in big-endian format. |
|
113 * @param aPtr Pointer to a byte stream buffer |
|
114 * @return A 64-bit integer in big-endian format |
|
115 */ |
|
116 static TUint64 GetQuadWordL(const TUint8* aPtr); |
|
117 |
|
118 /** |
|
119 * Utility functions for string and character handling |
|
120 */ |
|
121 static TBool IsQuotedPairChar(const TChar& aCharacter); |
|
122 |
|
123 static TBool IsQdTextChar(const TChar& aCharacter); |
|
124 |
|
125 static TBool IsQuotedString(const TDesC8& aString); |
|
126 |
|
127 static TPtrC8 RealmValueFromQuotedStringL(const TDesC8& aString ); |
|
128 |
|
129 static TBool QuotedStringValue (const TDesC8& aValue); |
|
130 |
|
131 static TBool StartsAndEndsWithQuotes (const TDesC8& aString); |
|
132 |
|
133 static TBool SkipAndCheckNonAscii (const TChar& aChr, TLex8& aLex); |
|
134 |
|
135 static TBool IsUTF8NonAsciiStartChar (const TChar& aChar); |
|
136 |
|
137 static TBool SkipAndCheckContChars (TLex8& aLex, TInt aCount); |
|
138 |
|
139 static TBool IsUTF8ContChar (const TChar& aChar); |
|
140 |
|
141 }; |
|
142 |
|
143 #endif // NATFWUNSAFUTILS_H |
|
144 |
|
145 |