|
1 /* |
|
2 * Copyright (c) 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: Project wide definitions. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef NSPDEFS_H |
|
19 #define NSPDEFS_H |
|
20 |
|
21 #include "nsppluginreturndef.h" |
|
22 #include <sdpconnectionfield.h> |
|
23 #include <sdpmediafield.h> |
|
24 |
|
25 #ifndef COMPONENT |
|
26 #define COMPONENT |
|
27 _LIT( KComponent, "NATFW SDP Provider" ); |
|
28 #endif // COMPONENT |
|
29 |
|
30 #define __PANIC( aInt ) User::Panic( KComponent, aInt ) |
|
31 |
|
32 #define NSP_ERROR( status ) ( KErrNone > status ) |
|
33 #define NSP_ICMP( aError ) ( KErrCommsLineFail == aError ) |
|
34 #define NSP_TRIGGER( status ) ( KNatReady == status ) |
|
35 #define NSP_DELETE( status ) ( KNatReady == status ) |
|
36 |
|
37 _LIT( KNSPPrintFormat, "%S: %S" ); |
|
38 _LIT( KNSPPrintFormat2, "%S: %S %S" ); |
|
39 _LIT( KNSPPrintFormat3, "%S: %S %d" ); |
|
40 _LIT( KNSPPrintFormat4, "%S: %S %u" ); |
|
41 |
|
42 inline static TInetAddr ConvertTDesC8ToTInetAddrL( const TDesC8& aDesc, TUint aPort ) |
|
43 { |
|
44 RBuf address; |
|
45 address.CreateL( aDesc.Length() ); |
|
46 address.CleanupClosePushL(); |
|
47 address.Copy( aDesc ); |
|
48 |
|
49 TInetAddr addr; |
|
50 User::LeaveIfError( addr.Input( address ) ); |
|
51 CleanupStack::PopAndDestroy( &address ); |
|
52 |
|
53 addr.SetPort( aPort ); |
|
54 return addr; |
|
55 } |
|
56 |
|
57 inline static void ConvertTInetAddrToTDes8AndTUintL( const TInetAddr& aAddress, |
|
58 TDes8& aDes, TUint& aPort ) |
|
59 { |
|
60 RBuf address; |
|
61 address.CreateL( 40 ); |
|
62 address.CleanupClosePushL(); |
|
63 |
|
64 aAddress.Output( address ); |
|
65 aDes.Copy( address ); |
|
66 CleanupStack::PopAndDestroy( &address ); |
|
67 |
|
68 aPort = aAddress.Port(); |
|
69 } |
|
70 |
|
71 inline static const TDesC8& Address( CSdpMediaField& aMediafield ) |
|
72 { |
|
73 return ( aMediafield.ConnectionFields().Count() ? |
|
74 aMediafield.ConnectionFields()[0]->Address() : KNullDesC8 ); |
|
75 } |
|
76 |
|
77 #define CONN_ADDR( mediafield, sessionAddr ) \ |
|
78 ( Address( mediafield ).Length() ? Address( mediafield ) : sessionAddr ) |
|
79 |
|
80 |
|
81 #if (defined _DEBUG) |
|
82 |
|
83 #include <e32debug.h> |
|
84 #include <e32base.h> |
|
85 #include <s32mem.h> |
|
86 #include <sdpdocument.h> |
|
87 |
|
88 class RBufWriteStream; |
|
89 |
|
90 const TText* const KWarning = _S( "Text contains not allowed characters, log ignored" ); |
|
91 const TText8* const KCRLF = _S8( "\r\n" ); |
|
92 const TUint KCRLFLength = 2; |
|
93 const TUint KMaxLengthOfSDPMessage = 1000; |
|
94 |
|
95 static inline void PrintL( const TDesC& aStr ) |
|
96 { |
|
97 HBufC* line = HBufC::NewLC( 256 ); |
|
98 TPtr ptr( line->Des() ); |
|
99 |
|
100 if ( KErrNotFound == aStr.Locate( TChar( '%' ) ) ) |
|
101 { |
|
102 ptr.Format( KNSPPrintFormat(), &KComponent(), &aStr ); |
|
103 } |
|
104 else |
|
105 { |
|
106 TPtrC warning( KWarning ); |
|
107 ptr.Format( KNSPPrintFormat(), &KComponent(), &warning ); |
|
108 } |
|
109 |
|
110 RDebug::Print( line->Des() ); |
|
111 CleanupStack::PopAndDestroy( line ); |
|
112 } |
|
113 static inline void Print( const TDesC& aStr ) |
|
114 { |
|
115 TRAP_IGNORE( PrintL( aStr ) ); |
|
116 } |
|
117 |
|
118 static inline void PrintL( const TDesC& aStr1, const TDesC& aStr2 ) |
|
119 { |
|
120 HBufC* line = HBufC::NewLC( 256 ); |
|
121 TPtr ptr( line->Des() ); |
|
122 |
|
123 if ( KErrNotFound == aStr1.Locate( TChar( '%' ) ) ) |
|
124 { |
|
125 ptr.Format( KNSPPrintFormat2(), &KComponent(), &aStr1, &aStr2 ); |
|
126 } |
|
127 else |
|
128 { |
|
129 TPtrC warning( KWarning ); |
|
130 ptr.Format( _L( "%S: %S" ), &KComponent(), &warning ); |
|
131 } |
|
132 |
|
133 RDebug::Print( line->Des() ); |
|
134 CleanupStack::PopAndDestroy( line ); |
|
135 } |
|
136 static inline void Print( const TDesC& aStr1, const TDesC& aStr2 ) |
|
137 { |
|
138 TRAP_IGNORE( PrintL( aStr1, aStr2 ) ); |
|
139 } |
|
140 |
|
141 static inline void PrintL( const TDesC& aStr, TInt aTInt ) |
|
142 { |
|
143 HBufC* line = HBufC::NewLC( 256 ); |
|
144 TPtr ptr( line->Des() ); |
|
145 |
|
146 if ( KErrNotFound == aStr.Locate( TChar( '%' ) ) ) |
|
147 { |
|
148 ptr.Format( KNSPPrintFormat3(), &KComponent(), &aStr, aTInt ); |
|
149 } |
|
150 else |
|
151 { |
|
152 TPtrC warning( KWarning ); |
|
153 ptr.Format( _L( "%S: %S" ), &KComponent(), &warning ); |
|
154 } |
|
155 |
|
156 RDebug::Print( line->Des() ); |
|
157 CleanupStack::PopAndDestroy( line ); |
|
158 } |
|
159 static inline void Print( const TDesC& aStr, TInt aTInt ) |
|
160 { |
|
161 TRAP_IGNORE( PrintL( aStr, aTInt ) ); |
|
162 } |
|
163 |
|
164 static inline void PrintL( const TDesC& aStr, TUint aTUint ) |
|
165 { |
|
166 HBufC* line = HBufC::NewLC( 256 ); |
|
167 TPtr ptr( line->Des() ); |
|
168 |
|
169 if ( KErrNotFound == aStr.Locate( TChar( '%' ) ) ) |
|
170 { |
|
171 ptr.Format( KNSPPrintFormat4(), &KComponent(), &aStr, aTUint ); |
|
172 } |
|
173 else |
|
174 { |
|
175 TPtrC warning( KWarning ); |
|
176 ptr.Format( _L( "%S: %S" ), &KComponent(), &warning ); |
|
177 } |
|
178 |
|
179 RDebug::Print( line->Des() ); |
|
180 CleanupStack::PopAndDestroy( line ); |
|
181 } |
|
182 static inline void Print( const TDesC& aStr, TUint aTUint ) |
|
183 { |
|
184 TRAP_IGNORE( PrintL( aStr, aTUint ) ); |
|
185 } |
|
186 |
|
187 static inline void Log8L( const TDesC8& aDesC8 ) |
|
188 { |
|
189 HBufC* buffer = HBufC::NewL( aDesC8.Length() ); |
|
190 TPtr ptr( buffer->Des() ); |
|
191 ptr.Copy( aDesC8 ); |
|
192 Print( buffer->Des() ); |
|
193 delete buffer; |
|
194 } |
|
195 |
|
196 static inline void Log8L( const TDesC& aStr, const TDesC8& aDesC8 ) |
|
197 { |
|
198 HBufC* buffer = HBufC::NewL( aDesC8.Length() ); |
|
199 TPtr ptr( buffer->Des() ); |
|
200 ptr.Copy( aDesC8 ); |
|
201 Print( aStr, buffer->Des() ); |
|
202 delete buffer; |
|
203 } |
|
204 |
|
205 static inline HBufC8* EncodeSdpDocumentL( const CSdpDocument& aDoc ) |
|
206 { |
|
207 CBufFlat* encBuf = CBufFlat::NewL( KMaxLengthOfSDPMessage ); |
|
208 CleanupStack::PushL( encBuf ); |
|
209 RBufWriteStream writeStream; |
|
210 CleanupClosePushL( writeStream ); |
|
211 writeStream.Open( *encBuf ); |
|
212 aDoc.EncodeL( writeStream ); |
|
213 CleanupStack::PopAndDestroy( &writeStream ); |
|
214 HBufC8* buff = encBuf->Ptr(0).AllocL(); |
|
215 CleanupStack::PopAndDestroy( encBuf ); |
|
216 return buff; |
|
217 } |
|
218 |
|
219 #define NSPLOG_STR( aLit ) \ |
|
220 { _LIT( KStr, aLit ); Print( KStr() ); } |
|
221 #define NSPLOG_STR2( aLit, b16 ) \ |
|
222 { _LIT( KStr, aLit ); Print( KStr(), b16 ); } |
|
223 #define NSPLOG_STR3( aLit, b16, c16 ) \ |
|
224 { _LIT( KStr, aLit ); Print( KStr(), b16, c16 ); } |
|
225 #define NSPLOG_INT( aLit, bInt ) \ |
|
226 { _LIT( KStr, aLit ); Print( KStr(), bInt ); } |
|
227 #define NSPLOG_UINT( aLit, bUInt ) \ |
|
228 { _LIT( KStr, aLit ); Print( KStr(), bUInt ); } |
|
229 |
|
230 #define NSPLOG8_STR( a8 ) \ |
|
231 { Log8L( a8 ); } |
|
232 #define NSPLOG8_STR2( aLit, b8 ) \ |
|
233 { _LIT( KStr, aLit ); Log8L( KStr(), b8 ); } |
|
234 |
|
235 #define NSPLOG8_DOC_L( aDoc ) \ |
|
236 {\ |
|
237 HBufC8* buffer = EncodeSdpDocumentL( aDoc );\ |
|
238 CleanupStack::PushL( buffer );\ |
|
239 TPtrC8 ptr( buffer->Des() );\ |
|
240 while( ptr.Length() )\ |
|
241 {\ |
|
242 const TInt length = ptr.Length();\ |
|
243 const TInt index = ptr.Find( TPtrC8( KCRLF ) );\ |
|
244 const TInt left = ( KErrNotFound != index ? index : length );\ |
|
245 const TInt right = ( length - KCRLFLength - left );\ |
|
246 HBufC8* line = ptr.Left( left ).AllocLC();\ |
|
247 Log8L( line->Des() );\ |
|
248 CleanupStack::PopAndDestroy( line );\ |
|
249 ptr.Set( ptr.Right( 0 < right ? right : 0 ) );\ |
|
250 }\ |
|
251 CleanupStack::PopAndDestroy( buffer );\ |
|
252 } |
|
253 |
|
254 #define NSPDEBUG_PANIC( aInt ) \ |
|
255 NSPLOG_INT( "NATFW SDP Provider!! code:", aInt ) __PANIC( aInt ) |
|
256 |
|
257 #if (defined NSP_PRINT_INPUT) |
|
258 |
|
259 #define NSP_INPUT_OFFER_L( aOffer ) \ |
|
260 {\ |
|
261 NSPLOG_STR( "============ INPUT OFFER =============" )\ |
|
262 NSPLOG8_DOC_L( aOffer )\ |
|
263 NSPLOG_STR( "======================================" )\ |
|
264 } |
|
265 #define NSP_INPUT_OFFER( aOffer ) \ |
|
266 TRAP_IGNORE( NSP_INPUT_OFFER_L( aOffer ) ); |
|
267 #define NSP_INPUT_ANSWER_L( aAnswer ) \ |
|
268 {\ |
|
269 NSPLOG_STR( "============ INPUT ANSWER ============" )\ |
|
270 NSPLOG8_DOC_L( aAnswer )\ |
|
271 NSPLOG_STR( "======================================" )\ |
|
272 } |
|
273 #define NSP_INPUT_ANSWER( aAnswer ) \ |
|
274 TRAP_IGNORE( NSP_INPUT_ANSWER_L( aAnswer ) ); |
|
275 |
|
276 #else // NSP_PRINT_INPUT |
|
277 |
|
278 #define NSP_INPUT_OFFER_L( aOffer ) |
|
279 #define NSP_INPUT_OFFER( aOffer ) |
|
280 #define NSP_INPUT_ANSWER_L( aAnswer ) |
|
281 #define NSP_INPUT_ANSWER( aAnswer ) |
|
282 |
|
283 #endif // NSP_PRINT_INPUT |
|
284 |
|
285 #if (defined NSP_PRINT_OUTPUT) |
|
286 |
|
287 #define NSP_OUTPUT_INITIALIZED \ |
|
288 {\ |
|
289 NSPLOG_STR( "============ INITIALIZED =============" )\ |
|
290 NSPLOG_STR( "======================================" )\ |
|
291 } |
|
292 #define NSP_OUTPUT_OFFER_L( aStatus, aOffer ) \ |
|
293 if ( KNatReady == aStatus )\ |
|
294 {\ |
|
295 NSPLOG_STR( "============ OUTPUT OFFER ============" )\ |
|
296 NSPLOG8_DOC_L( aOffer )\ |
|
297 NSPLOG_STR( "======================================" )\ |
|
298 } |
|
299 #define NSP_OUTPUT_OFFER( aStatus, aOffer ) \ |
|
300 TRAP_IGNORE( NSP_OUTPUT_OFFER_L( aStatus, aOffer ) ); |
|
301 #define NSP_OUTPUT_ANSWER_L( aStatus, aAnswer ) \ |
|
302 if ( KNatReady == aStatus )\ |
|
303 {\ |
|
304 NSPLOG_STR( "============ OUTPUT ANSWER ===========" )\ |
|
305 NSPLOG8_DOC_L( aAnswer )\ |
|
306 NSPLOG_STR( "======================================" )\ |
|
307 } |
|
308 #define NSP_OUTPUT_ANSWER( aStatus, aAnswer ) \ |
|
309 TRAP_IGNORE( NSP_OUTPUT_ANSWER_L( aStatus, aAnswer ) ); |
|
310 #define NSP_OUTPUT_UPDATESDP_L( aStatus, aOffer ) \ |
|
311 if ( KNatReady == aStatus )\ |
|
312 {\ |
|
313 NSPLOG_STR( "============ UPDATED SDP =============" )\ |
|
314 NSPLOG8_DOC_L( aOffer )\ |
|
315 NSPLOG_STR( "======================================" )\ |
|
316 } |
|
317 #define NSP_OUTPUT_UPDATESDP( aStatus, aOffer ) \ |
|
318 TRAP_IGNORE( NSP_OUTPUT_UPDATESDP_L( aStatus, aOffer ) ); |
|
319 #define NSP_OUTPUT_ERROR( aError ) \ |
|
320 {\ |
|
321 NSPLOG_STR( "============ OUTPUT ERROR ============" )\ |
|
322 NSPLOG_INT( ":", aError )\ |
|
323 NSPLOG_STR( "======================================" )\ |
|
324 } |
|
325 |
|
326 |
|
327 #else // NSP_PRINT_OUTPUT |
|
328 |
|
329 #define NSP_OUTPUT_INITIALIZED |
|
330 #define NSP_OUTPUT_OFFER_L( aStatus, aOffer ) |
|
331 #define NSP_OUTPUT_OFFER( aStatus, aOffer ) |
|
332 #define NSP_OUTPUT_ANSWER_L( aStatus, aAnswer ) |
|
333 #define NSP_OUTPUT_ANSWER( aStatus, aAnswer ) |
|
334 #define NSP_OUTPUT_UPDATESDP_L( aStatus, aOffer ) |
|
335 #define NSP_OUTPUT_UPDATESDP( aStatus, aOffer ) |
|
336 #define NSP_OUTPUT_ERROR( aError ) |
|
337 |
|
338 #endif // NSP_PRINT_OUTPUT |
|
339 |
|
340 #else // _DEBUG |
|
341 |
|
342 #define NSPLOG_STR( aLit ) |
|
343 #define NSPLOG_STR2( aLit, b16 ) |
|
344 #define NSPLOG_STR3( aLit, b16, c16 ) |
|
345 #define NSPLOG_INT( aLit, bInt ) |
|
346 #define NSPLOG_UINT( aLit, bUInt ) |
|
347 #define NSPLOG8_STR( a8 ) |
|
348 #define NSPLOG8_STR2( aLit, b8 ) |
|
349 #define NSPLOG8_DOC_L( aDoc ) |
|
350 #define NSPDEBUG_PANIC( aInt ) |
|
351 |
|
352 #define NSP_INPUT_OFFER_L( aOffer ) |
|
353 #define NSP_INPUT_OFFER( aOffer ) |
|
354 #define NSP_INPUT_ANSWER_L( aAnswer ) |
|
355 #define NSP_INPUT_ANSWER( aAnswer ) |
|
356 #define NSP_OUTPUT_INITIALIZED |
|
357 #define NSP_OUTPUT_OFFER_L( aStatus, aOffer ) |
|
358 #define NSP_OUTPUT_OFFER( aStatus, aOffer ) |
|
359 #define NSP_OUTPUT_ANSWER_L( aStatus, aAnswer ) |
|
360 #define NSP_OUTPUT_ANSWER( aStatus, aAnswer ) |
|
361 #define NSP_OUTPUT_UPDATESDP_L( aStatus, aOffer ) |
|
362 #define NSP_OUTPUT_UPDATESDP( aStatus, aOffer ) |
|
363 #define NSP_OUTPUT_ERROR( aError ) |
|
364 |
|
365 #endif // _DEBUG |
|
366 |
|
367 #endif // NSPDEFS_H |
|
368 |
|
369 // end of file |
|
370 |