|
1 /** @file |
|
2 * Copyright (c) 2008-2008 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 #include "upnpipfilteringdnsquery.h" |
|
21 |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // CUpnpIPFilteringDNSQuery::CUpnpIPFilteringDNSQuery |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CUpnpIPFilteringDNSQuery::CUpnpIPFilteringDNSQuery( const RMessage2& aMessage ) |
|
31 : CActive( EPriorityStandard ), |
|
32 iDNSStatus( KErrNotFound ), |
|
33 iMessage( aMessage ) |
|
34 |
|
35 { |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CUpnpIPFilteringDNSQuery::ConstructL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 void CUpnpIPFilteringDNSQuery::ConstructL( const TDesC8& aRemoteName ) |
|
44 { |
|
45 iRemoteName.CreateL( aRemoteName.Length() ); |
|
46 iRemoteName.Copy( aRemoteName ); |
|
47 CActiveScheduler::Add( this ); |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CUpnpIPFilteringDNSQuery::NewL( |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CUpnpIPFilteringDNSQuery* CUpnpIPFilteringDNSQuery::NewL( |
|
56 const RMessage2& aMessage, |
|
57 const TDesC8& aRemoteName |
|
58 ) |
|
59 { |
|
60 CUpnpIPFilteringDNSQuery* self = CUpnpIPFilteringDNSQuery::NewLC( |
|
61 aMessage, aRemoteName ); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CUpnpIPFilteringDNSQuery::NewLC |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CUpnpIPFilteringDNSQuery* CUpnpIPFilteringDNSQuery::NewLC( |
|
72 const RMessage2& aMessage, |
|
73 const TDesC8& aRemoteName ) |
|
74 { |
|
75 CUpnpIPFilteringDNSQuery* self = new ( ELeave ) CUpnpIPFilteringDNSQuery( |
|
76 aMessage ); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL( aRemoteName ); |
|
79 return self; |
|
80 } |
|
81 |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CUpnpIPFilteringDNSQuery::~CUpnpIPFilteringDNSQuery |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CUpnpIPFilteringDNSQuery::~CUpnpIPFilteringDNSQuery() |
|
88 { |
|
89 Cancel(); |
|
90 iHostResolver.Close(); |
|
91 iRemoteName.Close(); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CUpnpIPFilteringDNSQuery::AddAddress |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CUpnpIPFilteringDNSQuery::AddAddress( ) |
|
99 { |
|
100 iAction = EAddAddress; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CUpnpIPFilteringDNSQuery::RemoveAddress |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CUpnpIPFilteringDNSQuery::RemoveAddress( ) |
|
108 { |
|
109 iAction = ERemoveAddress; |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CUpnpIPFilteringDNSQuery::StartDNSQuery |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CUpnpIPFilteringDNSQuery::StartDNSQuery( RSocketServ& aSockServ, |
|
118 RConnection& aConnection, |
|
119 CUpnpIPFiltering* aIPListOwner ) |
|
120 { |
|
121 iIPListOwner = aIPListOwner; |
|
122 TInt err( iHostResolver.Open( aSockServ, KAfInet, |
|
123 KProtocolInetUdp, |
|
124 aConnection ) ); |
|
125 if( err ) |
|
126 { |
|
127 RequestCompleted( err ); |
|
128 return; |
|
129 } |
|
130 |
|
131 iHostResolver.GetByName( iRemoteName, iAddrDetails, iStatus ); |
|
132 SetActive(); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CUpnpIPFilteringDNSQuery::Status |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CUpnpIPFilteringDNSQuery::Status( TInt aStatus ) |
|
140 { |
|
141 return ( iDNSStatus == 0 ? iDNSStatus : aStatus ); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // CUpnpIPFilteringDNSQuery::RequestCompleted( |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 void CUpnpIPFilteringDNSQuery::RequestCompleted( TInt aStatus ) |
|
149 { |
|
150 iMessage.Complete( aStatus ); |
|
151 iIPListOwner->RequestCompleted( this ); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // From CActive |
|
156 // CUpnpIPFilteringDNSQuery::RunL |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CUpnpIPFilteringDNSQuery::RunL() |
|
160 { |
|
161 if( iStatus.Int()== KErrNone ) |
|
162 { |
|
163 iDNSStatus = KErrNone; |
|
164 switch( iAction ) |
|
165 { |
|
166 case EAddAddress: |
|
167 { |
|
168 if( iIPListOwner ) |
|
169 { |
|
170 if( iIPListOwner->AddAddressL( |
|
171 static_cast<TInetAddr>( iAddrDetails().iAddr ) ) >= 0 |
|
172 ) |
|
173 { |
|
174 iIPListOwner->IPListChange(); |
|
175 } |
|
176 } |
|
177 break; |
|
178 } |
|
179 case ERemoveAddress: |
|
180 { |
|
181 if( iIPListOwner ) |
|
182 { |
|
183 if ( iIPListOwner->RemoveAddressL( |
|
184 static_cast<TInetAddr>( iAddrDetails().iAddr ) ) >= 0 |
|
185 ) |
|
186 { |
|
187 iIPListOwner->IPListChange(); |
|
188 } |
|
189 } |
|
190 break; |
|
191 } |
|
192 default: |
|
193 { |
|
194 break; |
|
195 } |
|
196 } |
|
197 iHostResolver.Next( iAddrDetails , iStatus ); |
|
198 SetActive(); |
|
199 } |
|
200 else |
|
201 { |
|
202 RequestCompleted( Status( iStatus.Int() ) ); |
|
203 } |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // From CActive |
|
208 // CUpnpIPFilteringDNSQuery::RunError |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 TInt CUpnpIPFilteringDNSQuery::RunError( TInt aError ) |
|
212 { |
|
213 RequestCompleted( Status( aError ) ); |
|
214 return KErrNone; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // From CActive |
|
219 // CUpnpIPFilteringDNSQuery::DoCancel |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 void CUpnpIPFilteringDNSQuery::DoCancel() |
|
223 { |
|
224 iHostResolver.Cancel(); |
|
225 iMessage.Complete( KErrCancel ); |
|
226 } |
|
227 // End of file |