|
1 /* |
|
2 * Copyright (c) 2002-2003 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 #include "rtpcommrecv.h" |
|
22 |
|
23 /////////////////////Class CRtpCommRecv/////////////////////////////////////// |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // SetRemoteAddress |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 void CRtpCommRecv::SetRemoteAddress(TInetAddr& aAddr) |
|
31 { |
|
32 iRemoteAddr.SetAddress( aAddr.Address() ); |
|
33 iRemoteAddr.SetPort( aAddr.Port() ); |
|
34 if (aAddr.Family() == KAfInet6 ) |
|
35 { |
|
36 iRemoteAddr.SetAddress( aAddr.Ip6Address() ); |
|
37 } |
|
38 iRemoteAddrSet = ETrue; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CRtpCommRecv::CRtpCommRecv( TPortType aPortType, RSocket& aSocket, |
|
47 TInt aPriority, MRtpErrNotify& aErrNotify, |
|
48 TBool aNonRtpObserverSet ) |
|
49 : CActive( aPriority ), |
|
50 iPortType( aPortType ), |
|
51 iRecvNotify( NULL ), |
|
52 iSocket( aSocket ), |
|
53 iRtpErrNotify( aErrNotify ), |
|
54 iNonRtpObserverSet(aNonRtpObserverSet) |
|
55 { |
|
56 // Note: high priority needed to prevent socket server buffers filling up |
|
57 CActiveScheduler::Add( this ); |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CRtpCommRecv::ConstructL() |
|
65 { |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // Two-phased constructor. |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CRtpCommRecv* CRtpCommRecv::NewL( TPortType aPortType, RSocket& aSocket, |
|
73 TInt aPriority, MRtpErrNotify& aErrNotify, |
|
74 TBool aNonRtpObserverSet ) |
|
75 { |
|
76 CRtpCommRecv* self = new ( ELeave ) CRtpCommRecv( aPortType, aSocket, |
|
77 aPriority, aErrNotify, |
|
78 aNonRtpObserverSet ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop(); //self |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Destructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CRtpCommRecv::~CRtpCommRecv() |
|
90 { |
|
91 Cancel(); // -> in base class -> goes on to call DoCancel in this class... |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CRtpCommRecv::DoCancel() |
|
96 // Cancel ongoing requests. |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CRtpCommRecv::DoCancel() |
|
100 { |
|
101 // Cancel asychronous read request |
|
102 iSocket.CancelRead(); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CRtpCommRecv::RegisterReceivedNotify() |
|
107 // |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void CRtpCommRecv::RegisterReceivedNotify( MReceivedNotify* aNotify ) |
|
111 { |
|
112 iRecvNotify = aNotify; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CRtpCommRecv::SetNonRtpObserverFlag() |
|
117 // |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CRtpCommRecv::SetNonRtpObserverFlag(TBool aValue) |
|
121 { |
|
122 iNonRtpObserverSet = aValue; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CRtpCommRecv::Recv() |
|
127 // |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CRtpCommRecv::Recv( TDes8& aPacket ) |
|
131 { |
|
132 if ( !IsActive() ) |
|
133 { |
|
134 iSocket.RecvFrom( aPacket, iFromAddr, 0, iStatus ); |
|
135 |
|
136 SetActive(); |
|
137 return KErrNone; |
|
138 } |
|
139 else |
|
140 { |
|
141 return KErrInUse; |
|
142 } |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CRtpCommRecv::RunL() |
|
147 // |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CRtpCommRecv::RunL() |
|
151 { |
|
152 RTP_DEBUG_DETAIL( "CRtpCommRecv::RunL entry" ); |
|
153 if ( !iRecvNotify ) |
|
154 { |
|
155 RTP_DEBUG_PACKET( "CRtpCommRecv::RunL -- No receiver registered" ); |
|
156 iRtpErrNotify.ErrorNotify( KErrNotReady ); |
|
157 } |
|
158 else |
|
159 { |
|
160 if ( iStatus == KErrNone ) |
|
161 { |
|
162 if (!iNonRtpObserverSet && |
|
163 iRemoteAddrSet && !iFromAddr.Match(iRemoteAddr)) |
|
164 { |
|
165 // reject |
|
166 RTP_DEBUG_DETAIL( "Reject Rtp packet received" ); |
|
167 |
|
168 iRecvNotify->OnPacketRejected(iPortType); |
|
169 } |
|
170 else |
|
171 { |
|
172 //Note that Floor Control Msgs comes from the same remote addr with |
|
173 // rtp packets. |
|
174 if ( iPortType == ERTPPort ) |
|
175 { |
|
176 RTP_DEBUG_DETAIL( "CRtpCommRecv::RunL -- Rtp Packet is received"); |
|
177 iRecvNotify->OnRtpReceivedL(); |
|
178 } |
|
179 else if ( iPortType == ERTCPPort ) |
|
180 { |
|
181 RTP_DEBUG_DETAIL( "CRtpCommRecv::RunL -- Rtcp Packet is received" ); |
|
182 iRecvNotify->OnRtcpReceivedL(); |
|
183 } |
|
184 else |
|
185 { |
|
186 // Do nothing |
|
187 RTP_DEBUG_DETAIL( "CRtpCommRecv::RunL -- Unknown port type" ); |
|
188 } |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 RTP_DEBUG_DETAIL_DVALUE( "CRtpCommRecv::RunL -- ERROR: iStatus: ", iStatus.Int() ); |
|
194 // Also let the client application know that this happened |
|
195 iRtpErrNotify.ErrorNotify( iStatus.Int() ); |
|
196 // Let the session decide what to do with the error |
|
197 iRecvNotify->OnReceptionError( iPortType, iStatus.Int() ); |
|
198 } |
|
199 } |
|
200 RTP_DEBUG_DETAIL( "CRtpCommRecv::RunL exit" ); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // CRtpCommRecv::IsSetRemoteAdress() |
|
205 // |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 TBool CRtpCommRecv::IsSetRemoteAdress() |
|
209 { |
|
210 TBool same = ETrue; |
|
211 //This will be called by RtpSession classe to verify if the packet come from |
|
212 // setting remote address. This is important when NonRtpObserver has been set |
|
213 // in RunL and when NonRtpObs has been set, then it does not check remote address |
|
214 // since some response might come from STUN server, but if "from" address is not |
|
215 //checked then there could be some intrusion RTP valid packet and RTP stack is |
|
216 // volunerable for this attack. |
|
217 if ( iRemoteAddrSet && !iFromAddr.Match(iRemoteAddr)) |
|
218 { |
|
219 same = EFalse; |
|
220 return same; |
|
221 } |
|
222 return same; |
|
223 } |
|
224 |
|
225 // End of File |
|
226 |
|
227 |
|
228 |