|
1 // Copyright (c) 2004-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 : CProxyQuery.cpp |
|
15 // Part of : ProxyResolver |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CProxyQuery.h" |
|
22 #include "MSIPProxyResolverObserver.h" |
|
23 #include "MQueryObserver.h" |
|
24 #include <utf.h> |
|
25 #include <nifman.h> |
|
26 |
|
27 |
|
28 const TInt CProxyQuery::iOffset = _FOFF(CProxyQuery, iLink); |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CProxyQuery::NewL |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CProxyQuery* CProxyQuery::NewL( TUint aRequestId, |
|
35 TUint32 aIAPId, |
|
36 MSIPProxyResolverObserver& aResolverObserver, |
|
37 MQueryObserver& aQueryObserver, |
|
38 RSocketServ& aServer ) |
|
39 { |
|
40 CProxyQuery* self = CProxyQuery::NewLC( aRequestId, |
|
41 aIAPId, |
|
42 aResolverObserver, |
|
43 aQueryObserver, |
|
44 aServer ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CProxyQuery::NewLC |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CProxyQuery* CProxyQuery::NewLC( TUint aRequestId, |
|
54 TUint32 aIAPId, |
|
55 MSIPProxyResolverObserver& aResolverObserver, |
|
56 MQueryObserver& aQueryObserver, |
|
57 RSocketServ& aServer ) |
|
58 { |
|
59 CProxyQuery* self = new( ELeave )CProxyQuery( aRequestId, |
|
60 aIAPId, |
|
61 aResolverObserver, |
|
62 aQueryObserver, |
|
63 aServer ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CProxyQuery::~CProxyQuery |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CProxyQuery::~CProxyQuery () |
|
74 { |
|
75 delete iConnCont; |
|
76 delete iResultsArray; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CProxyQuery::Connection() |
|
81 // returns the RConnection object |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 RConnection & CProxyQuery::Connection() |
|
85 { |
|
86 return iConnCont->Connection(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CProxyQuery::ConnectionOpened() |
|
91 // returns connection opening status |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 TBool CProxyQuery::ConnectionOpened() |
|
95 { |
|
96 return iConnectionOpened; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CProxyQuery::ConstructL |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CProxyQuery::ConstructL() |
|
104 { |
|
105 iConnCont = CProxyConnectionContainer::NewL( *this, iIAPId, iServer ); |
|
106 iSipServerAddrBuf().index = 0; |
|
107 iSipServerDomainBuf().index = 0; |
|
108 iCurrentQueryType = KConnGetSipServerDomain; |
|
109 iResultsArray = new (ELeave) CDesC8ArrayFlat(1); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CProxyQuery::CProxyQuery |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CProxyQuery::CProxyQuery( TUint aRequestId, |
|
117 TUint32 aIAPId, |
|
118 MSIPProxyResolverObserver& aResolverObserver, |
|
119 MQueryObserver& aQueryObserver, |
|
120 RSocketServ& aServer ) |
|
121 : iRequestId( aRequestId ), |
|
122 iIAPId( aIAPId ), |
|
123 iResolverObserver( aResolverObserver ), |
|
124 iQueryObserver( aQueryObserver ), |
|
125 iConnectionOpened( EFalse ), |
|
126 iServer( aServer ) |
|
127 { |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CProxyQuery::ResolvingRequestComplete |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CProxyQuery::ResolvingRequestComplete() |
|
135 { |
|
136 if ( iResultsArray->Count() > 0 ) |
|
137 { |
|
138 iResolverObserver.ProxyResolvingRequestComplete( iRequestId, |
|
139 iResultsArray ); |
|
140 iResultsArray = NULL; // ownership transferred |
|
141 } |
|
142 else |
|
143 { |
|
144 ResolvingRequestFailed( KErrNotFound ); |
|
145 } |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CProxyQuery::ResolvingRequestFailed |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CProxyQuery::ResolvingRequestFailed( TInt aError ) |
|
153 { |
|
154 iResolverObserver.ProxyResolvingRequestFailed( iRequestId, aError ); |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CProxyQuery::RequestId |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 TUint CProxyQuery::RequestId() const |
|
162 { |
|
163 return iRequestId; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CProxyQuery::IAPId |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 TUint32 CProxyQuery::IAPId() const |
|
171 { |
|
172 return iIAPId; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CProxyQuery::ConnectionReady |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CProxyQuery::ConnectionReady() |
|
180 { |
|
181 iConnectionOpened = ETrue; |
|
182 iQueryObserver.ConnectionReady(this); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CProxyQuery::ErrorOccured |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CProxyQuery::ErrorOccured( TInt aError ) |
|
190 { |
|
191 iConnectionOpened = EFalse; //just to be sure.. |
|
192 iQueryObserver.ErrorOccured( aError, this ); |
|
193 } |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CProxyQuery::CurrentQueryType |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 TUint CProxyQuery::CurrentQueryType() |
|
201 { |
|
202 return iCurrentQueryType; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CProxyQuery::SetQueryType |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CProxyQuery::SetQueryType( TUint aNewType ) |
|
210 { |
|
211 iCurrentQueryType = aNewType; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CProxyQuery::SetNextIndex |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CProxyQuery::SetNextIndex() |
|
219 { |
|
220 if ( iCurrentQueryType == KConnGetSipServerAddr ) |
|
221 { |
|
222 (iSipServerAddrBuf().index)++; |
|
223 } |
|
224 else |
|
225 { |
|
226 (iSipServerDomainBuf().index)++; |
|
227 } |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CProxyQuery::GetBuf |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 TDes8* CProxyQuery::GetBuf() |
|
235 { |
|
236 if ( iCurrentQueryType == KConnGetSipServerAddr ) |
|
237 { |
|
238 return &iSipServerAddrBuf; |
|
239 } |
|
240 else |
|
241 { |
|
242 return &iSipServerDomainBuf; |
|
243 } |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CProxyQuery::AddResultsL |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CProxyQuery::AddResultsL() |
|
251 { |
|
252 THostName addr; |
|
253 if ( iCurrentQueryType == KConnGetSipServerAddr ) |
|
254 { |
|
255 iSipServerAddrBuf().address.Output( addr ); |
|
256 |
|
257 } |
|
258 else |
|
259 { |
|
260 addr.Copy( iSipServerDomainBuf().domainName ); |
|
261 } |
|
262 |
|
263 HBufC8* addrBuf = HBufC8::NewLC( 2*addr.Length() ); |
|
264 TPtr8 addrBufPtr = addrBuf->Des(); |
|
265 User::LeaveIfError( |
|
266 CnvUtfConverter::ConvertFromUnicodeToUtf8( addrBufPtr, addr ) ); |
|
267 if ( addrBufPtr.Length() > 0 ) |
|
268 { |
|
269 iResultsArray->AppendL( addrBufPtr ); |
|
270 } |
|
271 CleanupStack::PopAndDestroy( addrBuf ); |
|
272 } |
|
273 |
|
274 |