|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "WapMsgUtils.h" |
|
17 #include <wapmessage.h> |
|
18 #include <wapmsgerr.h> |
|
19 #include <es_wsms.h> |
|
20 #include <f32file.h> |
|
21 |
|
22 TInt CSWSWapMsgUtils::GetLocalAddress(HBufC8*& aLocalHost) |
|
23 /** |
|
24 Not supported |
|
25 @internalComponent |
|
26 @released |
|
27 @since v8.0 |
|
28 */ |
|
29 { |
|
30 // Panic client if the buffer isn't null |
|
31 __ASSERT_ALWAYS(aLocalHost==NULL, User::Panic(Wap::KWapMsgPanicDescriptor, KErrArgument)); |
|
32 |
|
33 RArray<Wap::TAddressInfo> myArray; |
|
34 |
|
35 TInt ret(0); |
|
36 TRAPD(err, ret=CWapMessageUtils::GetLocalAddressesL(myArray)) |
|
37 if (err) |
|
38 { |
|
39 return err; |
|
40 } |
|
41 // GetLocalAddressesL can return KErrNotFound if there is no network interface up |
|
42 if (ret) |
|
43 { |
|
44 return ret; |
|
45 } |
|
46 |
|
47 TBuf16<256>tempBuf16; |
|
48 TBuf8<256>tempBuf8; |
|
49 TInetAddr* info = &myArray[0].iAddress; |
|
50 // Output the address to a descriptor |
|
51 info->Output(tempBuf16); |
|
52 // Need to convert the buffer to 8 bit; |
|
53 tempBuf8.Copy(tempBuf16); |
|
54 // Note: Ownership of the allocated buffer is passed to the client |
|
55 aLocalHost = HBufC8::New( tempBuf16.Length() ); |
|
56 if (!aLocalHost) |
|
57 { |
|
58 return KErrNoMemory; |
|
59 } |
|
60 // Now copy the 8 bit version of the address |
|
61 *aLocalHost = tempBuf8; |
|
62 |
|
63 return KErrNone; |
|
64 } |
|
65 |
|
66 void CSWSWapMsgUtils::BuildAddrL(TSockAddr& aAddr, Wap::TBearer aBearer, const TDesC8& aHost, Wap::TPort aPort) |
|
67 /** |
|
68 Build a socket address according to the given parameters. |
|
69 @internalComponent |
|
70 @released |
|
71 @since v8.0 |
|
72 @param aAddr the socket address which is built from given parameters |
|
73 @param aBearer the underlie bearer type |
|
74 @param aHost the host name |
|
75 @param aHost the port number |
|
76 */ |
|
77 { |
|
78 if (aBearer==Wap::EIP) |
|
79 { |
|
80 TInetAddr addr(aPort); |
|
81 HBufC16* addr16=HBufC16::NewL(aHost.Length()); |
|
82 TPtr16 addr16Des=addr16->Des(); |
|
83 addr16Des.Copy(aHost); |
|
84 // coverity[check_return] |
|
85 addr.Input(addr16Des); |
|
86 aAddr=addr; |
|
87 delete addr16; |
|
88 } |
|
89 else |
|
90 { |
|
91 TWapAddr addr; |
|
92 addr.SetWapPort(TWapPortNumber(aPort)); |
|
93 addr.SetWapAddress(aHost); |
|
94 aAddr=addr; |
|
95 } |
|
96 } |
|
97 void CSWSWapMsgUtils::AnalyseAddrL(TSockAddr& aAddr, Wap::TBearer aBearer, TDes8& aHost, Wap::TPort& aPort) |
|
98 /** |
|
99 Analyse a socket address, and generate host name and port |
|
100 @internalComponent |
|
101 @released |
|
102 @since v8.0 |
|
103 @param aAddr the socket address to be analysed |
|
104 @param aBearer the underlie bearer type |
|
105 @param aHost the host name |
|
106 @param aHost the port number |
|
107 */ |
|
108 { |
|
109 aPort=static_cast<Wap::TPort>(aAddr.Port()); |
|
110 if (aBearer==Wap::EIP) |
|
111 { |
|
112 TInetAddr addr(aAddr); |
|
113 // If the family is KAfInet6, the output buffer must be at least |
|
114 // 39 characters. |
|
115 // If less, the buffer is filled with '*' characters. |
|
116 HBufC16* addr16=HBufC16::NewL(40); |
|
117 TPtr16 addr16Des=addr16->Des(); |
|
118 addr.Output(addr16Des); |
|
119 aHost.Copy(addr16Des); |
|
120 delete addr16; |
|
121 } |
|
122 else |
|
123 { |
|
124 TWapAddr& wapAddr = *(reinterpret_cast<TWapAddr*>(&aAddr)); |
|
125 TPtrC8 addr=wapAddr.WapAddress(); |
|
126 aHost.Copy(addr); |
|
127 } |
|
128 } |
|
129 |