|
1 // Copyright (c) 2007-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 // Name : CSenderUdp.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // Version : SIP/5.1 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSenderUdp.h" |
|
22 #include "CommonConsts.h" |
|
23 #include "SipLogs.h" |
|
24 #include "SipAssert.h" |
|
25 #include "siperr.h" |
|
26 #include "TSIPTransportParams.h" |
|
27 #include "sipmessage.h" |
|
28 #include "CSocketContainer.h" |
|
29 #include "COwnerSettingsList.h" |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CSenderUdp::NewL |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CSenderUdp* CSenderUdp::NewL( |
|
36 MContext& aContext, |
|
37 COwnerSettingsList& aSettingsList ) |
|
38 { |
|
39 CSenderUdp* self = NewLC( aContext, aSettingsList ); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CSenderUdp::NewLC |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CSenderUdp* CSenderUdp::NewLC( |
|
49 MContext& aContext, |
|
50 COwnerSettingsList& aSettingsList ) |
|
51 { |
|
52 CSenderUdp* self = new ( ELeave ) CSenderUdp( aContext, aSettingsList ); |
|
53 CleanupStack::PushL( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSenderUdp::CSenderUdp |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CSenderUdp::CSenderUdp( MContext& aContext, COwnerSettingsList& aSettingsList ) : |
|
62 CSender( aContext, aSettingsList ), |
|
63 iPermissionToSend( ETrue ) |
|
64 { |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSenderUdp::~CSenderUdp |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CSenderUdp::~CSenderUdp() |
|
72 { |
|
73 Cancel(); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSenderUdp::SendL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 TBool CSenderUdp::SendL( const TSIPTransportParams& aTransportParams, |
|
81 CSIPMessage& aMessage, |
|
82 const TInetAddr& aAddr, |
|
83 TUint aOrigTransport, |
|
84 TRequestStatus& aStat, |
|
85 TBool /*aStore*/, |
|
86 TBool aForceUDP ) |
|
87 { |
|
88 COutgoingData* data = |
|
89 COutgoingData::NewL( aTransportParams, aMessage, aAddr, |
|
90 aOrigTransport, aStat, *iContext.SigCompHandler(), |
|
91 aForceUDP ); |
|
92 |
|
93 if ( !IsActive() && iPermissionToSend ) |
|
94 { |
|
95 iList.AddFirst( *data ); |
|
96 |
|
97 TCleanupItem cleanupItem( CleanCurrentDataOnLeave, this ); |
|
98 CleanupStack::PushL( cleanupItem ); |
|
99 |
|
100 EncodeAndSendL( EFalse ); |
|
101 |
|
102 CleanupStack::Pop( 1 ); // cleanupItem |
|
103 } |
|
104 else |
|
105 { |
|
106 iList.AddLast( *data ); |
|
107 } |
|
108 |
|
109 return EFalse; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CSenderUdp::SendL |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CSenderUdp::SendL( COutgoingData* aData ) |
|
117 { |
|
118 iList.AddLast( *aData ); |
|
119 SendNextL(); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CSenderUdp::SendNextL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CSenderUdp::SendNextL() |
|
127 { |
|
128 if ( !IsActive() ) |
|
129 { |
|
130 if ( iPermissionToSend && !iList.IsEmpty() ) |
|
131 { |
|
132 EncodeAndSendL( ETrue ); |
|
133 } |
|
134 else |
|
135 { |
|
136 iContext.Sending( EFalse ); |
|
137 } |
|
138 } |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CSenderUdp::SetSendPermission |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CSenderUdp::SetSendPermission( TBool aPermissionToSend ) |
|
146 { |
|
147 iPermissionToSend = aPermissionToSend; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CSenderUdp::EncodeAndSendL |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CSenderUdp::EncodeAndSendL( TBool aRemoveFromList ) |
|
155 { |
|
156 COutgoingData* data = CurrentData(); |
|
157 |
|
158 __SIP_ASSERT_LEAVE( data, KErrNotFound ); |
|
159 |
|
160 TBool sendData = ETrue; |
|
161 TPtr8 pointer = data->EncodeL( EFalse ); |
|
162 TInt encodedLen = pointer.Length(); |
|
163 |
|
164 if ( encodedLen > KMaxMessageLength && data->ForceUDP() ) |
|
165 { |
|
166 // Message is too large to be sent with UDP |
|
167 User::Leave( KErrTooBig ); |
|
168 } |
|
169 |
|
170 if ( (encodedLen < KMaxUdpMessageSize || |
|
171 !data->Message().IsRequest() || |
|
172 data->ForceUDP() || |
|
173 data->OrigTransport() == KProtocolInetUdp) && |
|
174 !data->Compressed() ) |
|
175 { |
|
176 iOutgoingMessage.Set( pointer ); |
|
177 } |
|
178 else if ( data->Compressed() && encodedLen < KMaxUdpMessageSize ) |
|
179 { |
|
180 iOutgoingMessage.Set( pointer ); |
|
181 } |
|
182 else |
|
183 { |
|
184 data->Sent(); |
|
185 if ( aRemoveFromList ) |
|
186 { |
|
187 iList.Remove( *data ); |
|
188 } |
|
189 CleanupStack::PushL( data ); |
|
190 iContext.ReRouteL( KProtocolInetTcp, data ); |
|
191 CleanupStack::Pop( data ); |
|
192 sendData = EFalse; |
|
193 } |
|
194 |
|
195 if ( sendData ) |
|
196 { |
|
197 CSocketContainer* socketContainer( |
|
198 iContext.SocketContainer( IpAddrType( data->Address() ) ) ); |
|
199 __ASSERT_ALWAYS( socketContainer, User::Leave( KErrNotFound ) ); |
|
200 __SIP_MESSAGE_LOG( "Connection Manager::SendToNetwork via UDP", |
|
201 iOutgoingMessage ) |
|
202 WriteToLog( iOutgoingMessage ); |
|
203 |
|
204 // Set socket options before sending, options will be cleared after |
|
205 // send has completed. |
|
206 iSettingsList.SetOpts( |
|
207 data->TransportParams(), socketContainer->Socket() ); |
|
208 |
|
209 iContext.Sending( ETrue ); |
|
210 socketContainer->Socket().SendTo( |
|
211 iOutgoingMessage, |
|
212 data->Address(), |
|
213 0, |
|
214 iStatus ); |
|
215 SetActive(); |
|
216 } |
|
217 } |