14
|
1 |
// Copyright (c) 2008-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 |
// mdnsserversession.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
/**
|
|
18 |
@file
|
|
19 |
@internalTechnology
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "mdnsserversession.h"
|
|
23 |
#include <s32mem.h>
|
|
24 |
#include <utf.h>
|
|
25 |
#include "mdnsserver.h"
|
|
26 |
#include <mdns/cmdnsserverconstants.h>
|
|
27 |
#include <f32file.h>
|
|
28 |
__FLOG_STMT(_LIT8(KComponent,"MDNSServer");)
|
|
29 |
/*
|
|
30 |
* Two phase constructor.
|
|
31 |
*/
|
|
32 |
CMdnsServerSession* CMdnsServerSession::NewL(const CMdnsServer& aServer)
|
|
33 |
{
|
|
34 |
CMdnsServerSession* self = CMdnsServerSession::NewLC(aServer);
|
|
35 |
CleanupStack::Pop(self);
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
/*
|
|
41 |
* Two phase constructor
|
|
42 |
* @param aServer reference to the server.
|
|
43 |
*/
|
|
44 |
CMdnsServerSession* CMdnsServerSession::NewLC(const CMdnsServer& aServer)
|
|
45 |
{
|
|
46 |
CMdnsServerSession* self = new (ELeave) CMdnsServerSession(aServer);
|
|
47 |
CleanupStack::PushL(self);
|
|
48 |
self->ConstructL();
|
|
49 |
return self;
|
|
50 |
}
|
|
51 |
|
|
52 |
/*
|
|
53 |
* @param aMessage RMessage object.
|
|
54 |
*/
|
|
55 |
void CMdnsServerSession::ServiceL(const RMessage2& aMessage)
|
|
56 |
{
|
|
57 |
__FLOG(_L8("CMdnsServerSession::ServiceL - Entry"));
|
|
58 |
switch (aMessage.Function())
|
|
59 |
{
|
|
60 |
case EZeroconfServerMessageVersion:
|
|
61 |
break;
|
|
62 |
|
|
63 |
case EMdnsServerQueryMessages:
|
|
64 |
{
|
|
65 |
if(NULL != iClientQuery.Handle())
|
|
66 |
{
|
|
67 |
aMessage.Complete(KErrInUse);
|
|
68 |
}
|
|
69 |
else if (iServer.IsHostProbing() )
|
|
70 |
{
|
|
71 |
iServer.MessageQueue()->AppendMessageL(EQueryMessage,aMessage,SessionId());
|
|
72 |
}
|
|
73 |
else
|
|
74 |
{
|
|
75 |
ServiceQueryL(aMessage);
|
|
76 |
}
|
|
77 |
}
|
|
78 |
break;
|
|
79 |
|
|
80 |
case EMdnsServerRecieveMessages:
|
|
81 |
{
|
|
82 |
HBufC8* buffer = HBufC8::NewLC(KDnsBufferlength);
|
|
83 |
TPtr8 bufferPointer(buffer->Des());
|
|
84 |
iResponseBundle.Store(bufferPointer);
|
|
85 |
aMessage.Write(0,bufferPointer);
|
|
86 |
CleanupStack::PopAndDestroy();//delete buffer
|
|
87 |
aMessage.Complete(KErrNone);
|
|
88 |
iResponseBundle.Close();
|
|
89 |
}
|
|
90 |
break;
|
|
91 |
|
|
92 |
case EMndsServerPublishMessages:
|
|
93 |
{
|
|
94 |
if( iServer.IsHostProbing() || iServer.IsPublishingService())
|
|
95 |
{
|
|
96 |
iServer.MessageQueue()->AppendMessageL(EPublishMessage,aMessage,SessionId());
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
iServer.SetPublishingService(ETrue);
|
|
101 |
PublishL(aMessage);
|
|
102 |
}
|
|
103 |
break;
|
|
104 |
}
|
|
105 |
case EMdnsServerStartNotifyMessages:
|
|
106 |
{
|
|
107 |
RegisterNotifyL(aMessage);
|
|
108 |
aMessage.Complete(KErrNone);
|
|
109 |
break;
|
|
110 |
}
|
|
111 |
|
|
112 |
case EMdnsServerStopNotifyMessages:
|
|
113 |
{
|
|
114 |
StopNotifyL(aMessage);
|
|
115 |
aMessage.Complete(KErrNone);
|
|
116 |
break;
|
|
117 |
}
|
|
118 |
|
|
119 |
case EMdnsServerRecieveNotifyMessages:
|
|
120 |
{
|
|
121 |
iNotifyMessageRequest = aMessage;
|
|
122 |
break;
|
|
123 |
}
|
|
124 |
default:
|
|
125 |
User::Leave(KErrUnknown);
|
|
126 |
break;
|
|
127 |
}
|
|
128 |
|
|
129 |
__FLOG(_L8("CMdnsServerSession::ServiceL - Exit"));
|
|
130 |
}
|
|
131 |
|
|
132 |
void CMdnsServerSession::ServiceError(const RMessage2& aMessage, TInt aError)
|
|
133 |
{
|
|
134 |
__FLOG(_L8("CMdnsServerSession::ServiceError - Entry Exit"));
|
|
135 |
aMessage.Complete(aError);
|
|
136 |
}
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
void CMdnsServerSession::CleanUp()
|
|
141 |
{
|
|
142 |
__FLOG(_L8("CMdnsServerSession::CleanUp - Entry"));
|
|
143 |
// First thing is to send bye-bye packets to the services that we have published.
|
|
144 |
|
|
145 |
RPointerArray <CCacheEntry> cacheEntries;
|
|
146 |
iServer.MessageHandler().DnsCache().AuthoritativeEntriesL(cacheEntries);
|
|
147 |
|
|
148 |
for(TInt index =0; index < cacheEntries.Count();index++)
|
|
149 |
{
|
|
150 |
CCacheEntry* entry = cacheEntries[index];
|
|
151 |
if(entry->SessionId()==iSessionId)
|
|
152 |
{
|
|
153 |
// To filter out address records.
|
|
154 |
if(entry->ServiceRecord())
|
|
155 |
{
|
|
156 |
|
|
157 |
// found the entry to be deleted
|
|
158 |
if(entry->ServiceRecord())
|
|
159 |
entry->ServiceRecord()->SetTtl(0);
|
|
160 |
if(entry->TxtRecord())
|
|
161 |
entry->TxtRecord()->SetTtl(0);
|
|
162 |
if(entry->PtrRecord())
|
|
163 |
entry->PtrRecord()->SetTtl(0);
|
|
164 |
|
|
165 |
// delete the entry in the cache
|
|
166 |
|
|
167 |
// !!!!!! Assuming that the entry will always contain a srv record.
|
|
168 |
iServer.MessageHandler().DnsCache().DeleteEntryL(entry->ServiceRecord()->Name());
|
|
169 |
|
|
170 |
CDnsMessage* message = CDnsMessage::NewL(0,EFalse);
|
|
171 |
CleanupStack::PushL(message);
|
|
172 |
|
|
173 |
TDnsHeader header(message->Header());
|
|
174 |
header.SetAuthoritative(ETrue);
|
|
175 |
message->SetHeader(header);
|
|
176 |
|
|
177 |
if(entry->ServiceRecord())
|
|
178 |
message->AppendAnswerL(entry->ServiceRecord()->CloneL());
|
|
179 |
if(entry->PtrRecord())
|
|
180 |
message->AppendAnswerL(entry->PtrRecord()->CloneL());
|
|
181 |
if(entry->TxtRecord())
|
|
182 |
message->AppendAnswerL(entry->TxtRecord()->CloneL());
|
|
183 |
|
|
184 |
// bye-bye packet on the way to the network !!!
|
|
185 |
iServer.MessageHandler().SendQueryL(message,iServer);
|
|
186 |
CleanupStack::Pop(); //message
|
|
187 |
}
|
|
188 |
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
|
|
193 |
cacheEntries.ResetAndDestroy();
|
|
194 |
cacheEntries.Close();
|
|
195 |
__FLOG(_L8("CMdnsServerSession::CleanUp - Exit"));
|
|
196 |
}
|
|
197 |
/*
|
|
198 |
* Destructor
|
|
199 |
*/
|
|
200 |
CMdnsServerSession::~CMdnsServerSession()
|
|
201 |
{
|
|
202 |
__FLOG(_L8("CMdnsServerSession::~CMdnsServerSession - Entry"));
|
|
203 |
CleanUp();
|
|
204 |
iQueryBundle.Close();
|
|
205 |
iResponseBundle.Close();
|
|
206 |
iServer.DropSession();
|
|
207 |
for(TInt i =0 ; i<iRegisterNotifyArray.Count();i++ )
|
|
208 |
{
|
|
209 |
iRegisterNotifyArray[i].Close();
|
|
210 |
}
|
|
211 |
iRegisterNotifyArray.Close();
|
|
212 |
__FLOG(_L8("CMdnsServerSession::~CMdnsServerSession - Exit"));
|
|
213 |
__FLOG_CLOSE;
|
|
214 |
}
|
|
215 |
/*
|
|
216 |
* Constructor
|
|
217 |
*/
|
|
218 |
CMdnsServerSession::CMdnsServerSession(const CMdnsServer& aServer)
|
|
219 |
: iServer(const_cast<CMdnsServer&>(aServer))
|
|
220 |
{
|
|
221 |
iSessionId = iServer.NewSession();
|
|
222 |
}
|
|
223 |
|
|
224 |
/*
|
|
225 |
* Two phase constructor
|
|
226 |
*/
|
|
227 |
void CMdnsServerSession::ConstructL()
|
|
228 |
{
|
|
229 |
__FLOG_OPEN(KMDNSSubsystem, KComponent);
|
|
230 |
}
|
|
231 |
|
|
232 |
//TODO
|
|
233 |
TInt CMdnsServerSession::CountResources()
|
|
234 |
{
|
|
235 |
return 3;
|
|
236 |
}
|
|
237 |
|
|
238 |
void CMdnsServerSession::ServerVersionL(const RMessage2& aMessage)
|
|
239 |
{
|
|
240 |
__FLOG(_L8("CMdnsServerSession::ServerVersionL - Entry"));
|
|
241 |
TVersion mdnsServerVersion(0, 8, 0);
|
|
242 |
TPckgC<TVersion> pkg(mdnsServerVersion);
|
|
243 |
aMessage.WriteL(0, pkg);
|
|
244 |
aMessage.Complete(KErrNone);
|
|
245 |
__FLOG(_L8("CMdnsServerSession::ServerVersionL - Exit"));
|
|
246 |
|
|
247 |
}
|
|
248 |
/*
|
|
249 |
* Service any query rom the client
|
|
250 |
*/
|
|
251 |
void CMdnsServerSession::ServiceQueryL(const RMessage2& aMessage)
|
|
252 |
{
|
|
253 |
__FLOG(_L8("CMdnsServerSession::ServiceQueryL - Entry"));
|
|
254 |
iQueryBundle.Close();
|
|
255 |
iClientQuery = aMessage;
|
|
256 |
TInt len = aMessage.GetDesLengthL(0);
|
|
257 |
HBufC8* query = HBufC8::NewLC(aMessage.GetDesLengthL(0));
|
|
258 |
TPtr8 loadPtr = query->Des();
|
|
259 |
aMessage.ReadL(0,loadPtr);
|
|
260 |
iQueryBundle.CreateL();
|
|
261 |
TInt retOnLoad = iQueryBundle.Load(loadPtr);
|
|
262 |
User::LeaveIfError(retOnLoad);
|
|
263 |
RParameterFamily pnpFamily = iQueryBundle.GetFamilyAtIndex(0);
|
|
264 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
265 |
CDnsMessage* message = CDnsMessage::NewL(0,ETrue );
|
|
266 |
CleanupStack::PushL(message);
|
|
267 |
for ( TInt paramIndex = count - 1; paramIndex >= 0; paramIndex-- )
|
|
268 |
{
|
|
269 |
CMDnsQueryRequestParamSet* queryParam = static_cast<CMDnsQueryRequestParamSet*> (pnpFamily.GetParameterSetAtIndex ( paramIndex, RParameterFamily::ERequested ));
|
|
270 |
HBufC8* name = HBufC8::NewL(256);
|
|
271 |
CleanupStack::PushL(name);
|
|
272 |
TPtr8 ptrName(name->Des());
|
|
273 |
ptrName.Append(queryParam->InstanceName());
|
|
274 |
if(queryParam->InstanceName().Length() > 0)
|
|
275 |
{
|
|
276 |
ptrName.Append(_L8("."));
|
|
277 |
}
|
|
278 |
ptrName.Append(queryParam->ServiceType());
|
|
279 |
if(queryParam->QueryType() != EDnsType_A)
|
|
280 |
{
|
|
281 |
ptrName.Append(1 == queryParam->Protocol() ? KTcpProtocolType : KUdpProtocolType);
|
|
282 |
}
|
|
283 |
ptrName.Append(KLocalTld);
|
|
284 |
ptrName.Append(_L8("."));
|
|
285 |
CDnsQuestion* question = CDnsQuestion::NewL();
|
|
286 |
CleanupStack::PushL(question);
|
|
287 |
question->SetNameL(ptrName);
|
|
288 |
question->SetClass(EDnsClass_IN);
|
|
289 |
question->SetType(queryParam->QueryType());
|
|
290 |
question->SetUnicast(EFalse);
|
|
291 |
message->AppendQueryL(question);
|
|
292 |
CleanupStack::Pop();
|
|
293 |
CleanupStack::PopAndDestroy();//name
|
|
294 |
}
|
|
295 |
iServer.MessageHandler().ServiceClientQueryL(message,aMessage.Handle());
|
|
296 |
CleanupStack::Pop();//message
|
|
297 |
CleanupStack::PopAndDestroy();//query
|
|
298 |
__FLOG(_L8("CMdnsServerSession::ServiceQueryL - Exit"));
|
|
299 |
}
|
|
300 |
|
|
301 |
TInt CMdnsServerSession::OutStandQueryClientHandle()const
|
|
302 |
{
|
|
303 |
return iClientQuery.Handle();
|
|
304 |
}
|
|
305 |
|
|
306 |
void CMdnsServerSession::SendResponseL()
|
|
307 |
{
|
|
308 |
__FLOG(_L8("CMdnsServerSession::SendResponseL - Entry"));
|
|
309 |
RParameterFamily pnpFamily = iQueryBundle.GetFamilyAtIndex(0);
|
|
310 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
311 |
//Open a new reference to ResponseBundle
|
|
312 |
iResponseBundle.Open ();
|
|
313 |
CleanupClosePushL( iResponseBundle );
|
|
314 |
for(TInt index =0 ;index <count ; index++)
|
|
315 |
{
|
|
316 |
CMDnsQueryRequestParamSet* queryParam = static_cast<CMDnsQueryRequestParamSet*> (pnpFamily.GetParameterSetAtIndex ( index, RParameterFamily::ERequested ));
|
|
317 |
HBufC8* name = HBufC8::NewL(KDnsBufferlength);
|
|
318 |
CleanupStack::PushL(name);
|
|
319 |
TPtr8 ptrName(name->Des());
|
|
320 |
ptrName.Append(queryParam->InstanceName());
|
|
321 |
if(queryParam->InstanceName().Size()>0)
|
|
322 |
ptrName.Append(_L8("."));
|
|
323 |
ptrName.Append(queryParam->ServiceType());
|
|
324 |
if(queryParam->QueryType() != EDnsType_A)
|
|
325 |
{
|
|
326 |
ptrName.Append(1 == queryParam->Protocol() ? KTcpProtocolType : KUdpProtocolType);
|
|
327 |
}
|
|
328 |
ptrName.Append(KLocalTld);
|
|
329 |
ptrName.Append(_L8("."));
|
|
330 |
RPointerArray<CCacheEntry> records;
|
|
331 |
iServer.MessageHandler().DnsCache().FindServiceL(records,ptrName,(TDnsType)queryParam->QueryType());
|
|
332 |
TInt count = records.Count();
|
|
333 |
switch((TDnsType)queryParam->QueryType())
|
|
334 |
{
|
|
335 |
case EDnsType_PTR:
|
|
336 |
{
|
|
337 |
RParameterFamily pnpFamily = iResponseBundle.CreateFamilyL (EMdnsPtrParamset);
|
|
338 |
while(count -- > 0 )
|
|
339 |
{
|
|
340 |
iResponseBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
341 |
CMDnsPtrParamSet* responseParam = CMDnsPtrParamSet::NewL(pnpFamily);
|
|
342 |
responseParam->SetInstanceNameL(records[count]->PtrRecord()->Name());
|
|
343 |
responseParam->SetDomainNameL(records[count]->PtrRecord()->DomainName());
|
|
344 |
//responseParam->SetTtlL(records[count]->PtrRecord()->Ttl());
|
|
345 |
}
|
|
346 |
break;
|
|
347 |
}
|
|
348 |
case EDnsType_SRV:
|
|
349 |
{
|
|
350 |
RParameterFamily pnpFamily = iResponseBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
351 |
while(count -- > 0 )
|
|
352 |
{
|
|
353 |
iResponseBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
354 |
CMDnsSrvParamSet* responseParam = CMDnsSrvParamSet::NewL(pnpFamily);
|
|
355 |
responseParam->SetDomainNameL(records[count]->ServiceRecord()->Name());
|
|
356 |
responseParam->SetTargetL(records[count]->ServiceRecord()->Target());
|
|
357 |
responseParam->SetPriority(records[count]->ServiceRecord()->Priority());
|
|
358 |
responseParam->SetWeight(records[count]->ServiceRecord()->Weight());
|
|
359 |
responseParam->SetPort(records[count]->ServiceRecord()->Port());
|
|
360 |
}
|
|
361 |
break;
|
|
362 |
}
|
|
363 |
case EDnsType_TXT:
|
|
364 |
{
|
|
365 |
RParameterFamily pnpFamily = iResponseBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
366 |
while(count -- > 0 )
|
|
367 |
{
|
|
368 |
iResponseBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
369 |
CMDnsTxtParamSet* responseParam = CMDnsTxtParamSet::NewL(pnpFamily);
|
|
370 |
responseParam->SetDomainNameL(records[count]->TxtRecord()->Name());
|
|
371 |
RArray<RBuf8> txtData = records[count]->TxtRecord()->Text();
|
|
372 |
|
|
373 |
for(TInt j=0;j<txtData.Count();j++)
|
|
374 |
{
|
|
375 |
responseParam->AppendTxtData(txtData[j]);
|
|
376 |
}
|
|
377 |
}
|
|
378 |
break;
|
|
379 |
}
|
|
380 |
case EDnsType_A:
|
|
381 |
{
|
|
382 |
RParameterFamily pnpFamily = iResponseBundle.CreateFamilyL (EMdnsAddrParamset);
|
|
383 |
while(count -- > 0 )
|
|
384 |
{
|
|
385 |
iResponseBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
386 |
CMDnsAddrParamSet* responseParam = CMDnsAddrParamSet::NewL(pnpFamily);
|
|
387 |
responseParam->SetDomainNameL(records[count]->AddressRecord()->Name());
|
|
388 |
responseParam->SetAddress(records[count]->AddressRecord()->Address());
|
|
389 |
}
|
|
390 |
break;
|
|
391 |
}
|
|
392 |
case EDnsQType_Any:
|
|
393 |
{
|
|
394 |
iResponseBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
395 |
while(count -- > 0 )
|
|
396 |
{
|
|
397 |
CreateAnyQueryResponseL(*records[count]);
|
|
398 |
}
|
|
399 |
break;
|
|
400 |
}
|
|
401 |
|
|
402 |
}
|
|
403 |
records.ResetAndDestroy();
|
|
404 |
records.Close();
|
|
405 |
CleanupStack::PopAndDestroy();//name
|
|
406 |
}//end of for loop
|
|
407 |
|
|
408 |
HBufC8* buffer = HBufC8::NewLC(KDnsBufferlength);
|
|
409 |
TPtr8 bufferPointer(buffer->Des());
|
|
410 |
iResponseBundle.Store(bufferPointer);
|
|
411 |
TInt len = bufferPointer.Length();
|
|
412 |
TPckgC<TInt> lenbuf(len);
|
|
413 |
iClientQuery.Write(1,lenbuf);
|
|
414 |
CleanupStack::PopAndDestroy();//buffer
|
|
415 |
iClientQuery.Complete(KErrNone);
|
|
416 |
CleanupStack::Pop();//iResponseBundle
|
|
417 |
__FLOG(_L8("CMdnsServerSession::SendResponseL - Exit"));
|
|
418 |
}
|
|
419 |
|
|
420 |
void CMdnsServerSession::PublishL(const RMessage2& aMessage)
|
|
421 |
{
|
|
422 |
__FLOG(_L8("CMdnsServerSession::PublishL - Entry"));
|
|
423 |
TBool isUpdate = aMessage.Int2();
|
|
424 |
iPublishRequest = aMessage;
|
|
425 |
TInt len = aMessage.GetDesLengthL(0);
|
|
426 |
HBufC8* query = HBufC8::NewLC(aMessage.GetDesLengthL(0));
|
|
427 |
TPtr8 loadPtr = query->Des();
|
|
428 |
aMessage.ReadL(0,loadPtr);
|
|
429 |
iPublishBundle.CreateL();
|
|
430 |
TInt retOnLoad = iPublishBundle.Load(loadPtr);
|
|
431 |
TInt familyCount = iPublishBundle.CountParameterFamilies();
|
|
432 |
RPointerArray<CDnsResourceData> publishRecordArray;
|
|
433 |
for(TInt i =0 ; i< familyCount; i++)
|
|
434 |
{
|
|
435 |
RParameterFamily pnpFamily = iPublishBundle.GetFamilyAtIndex(i);
|
|
436 |
switch (pnpFamily.Id())
|
|
437 |
{
|
|
438 |
case EMdnsSrvParamset:
|
|
439 |
{
|
|
440 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
441 |
for (TInt index= 0; index < count ; index++ )
|
|
442 |
{
|
|
443 |
CMDnsSrvParamSet* srvParamSet = static_cast<CMDnsSrvParamSet*> (pnpFamily.GetParameterSetAtIndex ( index, RParameterFamily::ERequested ));
|
|
444 |
CRdTypeSrv* srvRecord = CRdTypeSrv::NewL();
|
|
445 |
CleanupStack::PushL(srvRecord);
|
|
446 |
srvRecord->SetNameL(srvParamSet->DomainName());
|
|
447 |
srvRecord->SetClass(EDnsClass_IN);
|
|
448 |
srvRecord->SetFlushBit(EFalse);
|
|
449 |
srvRecord->SetPort(srvParamSet->Port());
|
|
450 |
srvRecord->SetPriority(srvParamSet->Priority() );
|
|
451 |
srvRecord->SetTargetL(iServer.HostName());
|
|
452 |
srvRecord->SetTtl(120);
|
|
453 |
srvRecord->SetType(EDnsType_SRV);
|
|
454 |
srvRecord->SetWeight(srvParamSet->Weight());
|
|
455 |
publishRecordArray.AppendL(srvRecord);
|
|
456 |
CleanupStack::Pop();//CRdtypeSrv
|
|
457 |
//Ptr Record
|
|
458 |
/*
|
|
459 |
CRdTypePtr* ptrRecord = CRdTypePtr::NewL();
|
|
460 |
CleanupStack::PushL(ptrRecord);
|
|
461 |
TInt pos = srvParamSet->DomainName().Locate('.');
|
|
462 |
ptrRecord->SetNameL(srvParamSet->DomainName().Mid(pos+1));
|
|
463 |
ptrRecord->SetClass(EDnsClass_IN);
|
|
464 |
ptrRecord->SetFlushBit(EFalse);
|
|
465 |
ptrRecord->SetTtl(120);
|
|
466 |
ptrRecord->SetType(EDnsType_PTR);
|
|
467 |
ptrRecord->SetDomainNameL(srvParamSet->DomainName());
|
|
468 |
publishRecordArray.AppendL(ptrRecord);
|
|
469 |
CleanupStack::Pop();
|
|
470 |
*/
|
|
471 |
}
|
|
472 |
break;
|
|
473 |
}
|
|
474 |
case EMdnsPtrParamset:
|
|
475 |
{
|
|
476 |
//do nothing
|
|
477 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
478 |
for (TInt index= 0; index < count ; index++ )
|
|
479 |
{
|
|
480 |
CMDnsPtrParamSet* ptrParamSet = static_cast<CMDnsPtrParamSet*>(pnpFamily.GetParameterSetAtIndex( index, RParameterFamily::ERequested ));
|
|
481 |
CRdTypePtr* ptrRecord = CRdTypePtr::NewL();
|
|
482 |
CleanupStack::PushL(ptrRecord);
|
|
483 |
ptrRecord->SetNameL(ptrParamSet->InstanceName());
|
|
484 |
ptrRecord->SetClass(EDnsClass_IN);
|
|
485 |
ptrRecord->SetFlushBit(EFalse);
|
|
486 |
ptrRecord->SetTtl(120);
|
|
487 |
ptrRecord->SetType(EDnsType_PTR);
|
|
488 |
ptrRecord->SetDomainNameL(ptrParamSet->DomainName());
|
|
489 |
publishRecordArray.AppendL(ptrRecord);
|
|
490 |
CleanupStack::Pop();//Remove Ptr Record from the queue..
|
|
491 |
}
|
|
492 |
break;
|
|
493 |
}
|
|
494 |
case EMdnsAddrParamset:
|
|
495 |
{
|
|
496 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
497 |
for (TInt index= 0; index < count ; index++ )
|
|
498 |
{
|
|
499 |
CMDnsAddrParamSet* addrParamSet = static_cast<CMDnsAddrParamSet*>(pnpFamily.GetParameterSetAtIndex( index, RParameterFamily::ERequested ));
|
|
500 |
CRdTypeA* addrRecord = CRdTypeA::NewL();
|
|
501 |
CleanupStack::PushL(addrRecord);
|
|
502 |
addrRecord->SetAddr(addrParamSet->Address());
|
|
503 |
addrRecord->SetNameL(addrParamSet->DomainName());
|
|
504 |
addrRecord->SetClass(EDnsClass_IN);
|
|
505 |
addrRecord->SetFlushBit(EFalse);
|
|
506 |
addrRecord->SetTtl(120);
|
|
507 |
addrRecord->SetType(EDnsType_A);
|
|
508 |
publishRecordArray.AppendL(addrRecord);
|
|
509 |
CleanupStack::Pop();//remove addrecord from the queue
|
|
510 |
}
|
|
511 |
break;
|
|
512 |
}
|
|
513 |
case EMdnsTxtParamset:
|
|
514 |
{
|
|
515 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
516 |
for (TInt index= 0; index < count ; index++ )
|
|
517 |
{
|
|
518 |
CMDnsTxtParamSet* txtParamSet = static_cast<CMDnsTxtParamSet*>(pnpFamily.GetParameterSetAtIndex( index, RParameterFamily::ERequested ));
|
|
519 |
CRdTypeTxt* txtRecord = CRdTypeTxt::NewL();
|
|
520 |
CleanupStack::PushL(txtRecord);
|
|
521 |
txtRecord->SetNameL(txtParamSet->DomainName());
|
|
522 |
txtRecord->SetClass(EDnsClass_IN);
|
|
523 |
txtRecord->SetFlushBit(EFalse);
|
|
524 |
txtRecord->SetTtl(120);
|
|
525 |
txtRecord->SetType(EDnsType_TXT);
|
|
526 |
RArray<RBuf8> txtArray ;
|
|
527 |
txtParamSet->TxtDataL(txtArray);
|
|
528 |
TInt txtCnt = txtArray.Count();
|
|
529 |
for(TInt count = 0; count < txtCnt ; count ++ )
|
|
530 |
{
|
|
531 |
txtRecord->AppendTextDataL(txtArray[count]);
|
|
532 |
}
|
|
533 |
txtArray.Close();
|
|
534 |
publishRecordArray.AppendL(txtRecord);
|
|
535 |
CleanupStack::Pop();//remove txtRecord from the queue..
|
|
536 |
}
|
|
537 |
break;
|
|
538 |
}
|
|
539 |
}
|
|
540 |
|
|
541 |
}
|
|
542 |
TRAPD(publishError ,iServer.MessageHandler().AdvertizePacketL(publishRecordArray,iSessionId , isUpdate));
|
|
543 |
if(publishError == KErrNotFound)
|
|
544 |
{
|
|
545 |
aMessage.Complete(KErrNotFound);
|
|
546 |
}
|
|
547 |
publishRecordArray.Close();
|
|
548 |
iPublishBundle.Close();
|
|
549 |
CleanupStack::PopAndDestroy(query);
|
|
550 |
__FLOG(_L8("CMdnsServerSession::PublishL - Exit"));
|
|
551 |
}
|
|
552 |
|
|
553 |
void CMdnsServerSession::HandleServiceNameConflictL(const RBuf8& aName,TInt aError)
|
|
554 |
{
|
|
555 |
__FLOG(_L8("CMdnsServerSession::HandleServiceNameConflictL - Entry"));
|
|
556 |
iResponseBundle.Open ();
|
|
557 |
CleanupClosePushL( iResponseBundle );
|
|
558 |
|
|
559 |
RParameterFamily pnpFamily = iResponseBundle.CreateFamilyL (EMdnsPublishResponseParamset);
|
|
560 |
iResponseBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
561 |
|
|
562 |
CMDnsPublishResponseParamSet* responseParam = CMDnsPublishResponseParamSet::NewL(pnpFamily);
|
|
563 |
responseParam->SetDomainNameL(aName);
|
|
564 |
responseParam->SetError(aError);
|
|
565 |
|
|
566 |
|
|
567 |
TInt len = iResponseBundle.Length();
|
|
568 |
TPckgC<TInt> lenbuf(len);
|
|
569 |
iPublishRequest.Write(1,lenbuf);
|
|
570 |
|
|
571 |
iPublishRequest.Complete(KErrNone);
|
|
572 |
CleanupStack::Pop();//iResponseBundle
|
|
573 |
__FLOG(_L8("CMdnsServerSession::HandleServiceNameConflictL - Exit"));
|
|
574 |
}
|
|
575 |
|
|
576 |
void CMdnsServerSession::RegisterNotifyL(const RMessage2& aMessage)
|
|
577 |
{
|
|
578 |
__FLOG(_L8("CMdnsServerSession::RegisterNotifyL - Entry"));
|
|
579 |
iIsNotifyRequested = ETrue;
|
|
580 |
RPnPParameterBundle registerBundle;
|
|
581 |
TInt size = aMessage.GetDesLength(0);
|
|
582 |
HBufC8* registerbuf = HBufC8::NewLC(aMessage.GetDesLengthL(0));
|
|
583 |
TPtr8 loadPtr = registerbuf->Des();
|
|
584 |
aMessage.ReadL(0,loadPtr);
|
|
585 |
registerBundle.CreateL();
|
|
586 |
registerBundle.Load(loadPtr);
|
|
587 |
RParameterFamily pnpFamily = registerBundle.GetFamilyAtIndex(0);
|
|
588 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
589 |
for(TInt index =0 ; index<count ; index++)
|
|
590 |
{
|
|
591 |
CMDnsRegisterNotifyParamSet* registerParamSet = static_cast<CMDnsRegisterNotifyParamSet*>(pnpFamily.GetParameterSetAtIndex( index, RParameterFamily::ERequested ));
|
|
592 |
RBuf8 instanceName;
|
|
593 |
instanceName.CreateL(registerParamSet->InstanceName());
|
|
594 |
iRegisterNotifyArray.AppendL(instanceName);
|
|
595 |
}
|
|
596 |
registerBundle.Close();
|
|
597 |
CleanupStack::PopAndDestroy();//registerbuffer
|
|
598 |
__FLOG(_L8("CMdnsServerSession::RegisterNotifyL - Exit"));
|
|
599 |
}
|
|
600 |
|
|
601 |
void CMdnsServerSession::StopNotifyL(const RMessage2& aMessage)
|
|
602 |
{
|
|
603 |
__FLOG(_L8("CMdnsServerSession::StopNotifyL - Entry"));
|
|
604 |
RPnPParameterBundle registerBundle;
|
|
605 |
TInt size = aMessage.GetDesLength(0);
|
|
606 |
HBufC8* registerbuf = HBufC8::NewLC(aMessage.GetDesLengthL(0));
|
|
607 |
TPtr8 loadPtr = registerbuf->Des();
|
|
608 |
aMessage.ReadL(0,loadPtr);
|
|
609 |
registerBundle.CreateL();
|
|
610 |
registerBundle.Load(loadPtr);
|
|
611 |
RParameterFamily pnpFamily = registerBundle.GetFamilyAtIndex(0);
|
|
612 |
TUint count = pnpFamily.CountParameterSets ( RParameterFamily::ERequested ) ;
|
|
613 |
for(TInt index =0 ; index< count; index++)
|
|
614 |
{
|
|
615 |
CMDnsRegisterNotifyParamSet* registerParamSet = static_cast<CMDnsRegisterNotifyParamSet*>(pnpFamily.GetParameterSetAtIndex( index, RParameterFamily::ERequested ));
|
|
616 |
RBuf8 instanceName;
|
|
617 |
instanceName.CreateL(registerParamSet->InstanceName());
|
|
618 |
for(TInt i =0 ; i< iRegisterNotifyArray.Count();i++)
|
|
619 |
{
|
|
620 |
if(instanceName.Compare(iRegisterNotifyArray[i]) == 0)
|
|
621 |
{
|
|
622 |
RBuf8& temp = iRegisterNotifyArray[i];
|
|
623 |
iRegisterNotifyArray.Remove(i);
|
|
624 |
temp.Close();
|
|
625 |
}
|
|
626 |
}
|
|
627 |
instanceName.Close();
|
|
628 |
}
|
|
629 |
if(iRegisterNotifyArray.Count() == 0 )
|
|
630 |
{
|
|
631 |
iIsNotifyRequested =EFalse;
|
|
632 |
}
|
|
633 |
registerBundle.Close();
|
|
634 |
CleanupStack::PopAndDestroy();//registerbuffer
|
|
635 |
__FLOG(_L8("CMdnsServerSession::StopNotifyL - Exit"));
|
|
636 |
}
|
|
637 |
|
|
638 |
TInt CMdnsServerSession::SessionId()
|
|
639 |
{
|
|
640 |
__FLOG(_L8("CMdnsServerSession::SessionId - Exit"));
|
|
641 |
return iSessionId;
|
|
642 |
}
|
|
643 |
void CMdnsServerSession::NewServiceL(const RArray<RBuf8>& aName)
|
|
644 |
{
|
|
645 |
__FLOG(_L8("CMdnsServerSession::NewServiceL - Entry"));
|
|
646 |
if(iIsNotifyRequested && iNotifyMessageRequest.Handle())
|
|
647 |
{
|
|
648 |
RPnPParameterBundle publishBundle;
|
|
649 |
publishBundle.CreateL();
|
|
650 |
RParameterFamily pnpFamily = publishBundle.CreateFamilyL (EMdnsPtrParamset);
|
|
651 |
publishBundle.SetPnPObserver((MPnPObserver*)NULL);
|
|
652 |
for(TInt i =0 ; i < aName.Count();i++)
|
|
653 |
{
|
|
654 |
for(TInt j= 0 ; j< iRegisterNotifyArray.Count(); j++)
|
|
655 |
{
|
|
656 |
TInt pos = aName[i].Find(iRegisterNotifyArray[j]);
|
|
657 |
if(pos != KErrNotFound)
|
|
658 |
{
|
|
659 |
CMDnsPtrParamSet* responseParam = CMDnsPtrParamSet::NewL(pnpFamily);
|
|
660 |
responseParam->SetInstanceNameL(iRegisterNotifyArray[j]);
|
|
661 |
responseParam->SetDomainNameL(aName[i]);
|
|
662 |
// have to fill up the ttl field, query the cache
|
|
663 |
RPointerArray <CCacheEntry> aEntries;
|
|
664 |
iServer.MessageHandler().DnsCache().FindServiceL(aEntries,aName[i],EDnsType_SRV);
|
|
665 |
responseParam->SetTtlL(0);
|
|
666 |
if(aEntries.Count()==0)
|
|
667 |
{
|
|
668 |
// already deleted from cache
|
|
669 |
responseParam->SetTtlL(0);
|
|
670 |
}
|
|
671 |
else if(aEntries[0]->PtrRecord()!=NULL)
|
|
672 |
{
|
|
673 |
responseParam->SetTtlL(aEntries[0]->PtrRecord()->Ttl());
|
|
674 |
}
|
|
675 |
aEntries.ResetAndDestroy();
|
|
676 |
aEntries.Close();
|
|
677 |
break;
|
|
678 |
}
|
|
679 |
}
|
|
680 |
}
|
|
681 |
HBufC8* buffer = HBufC8::NewLC(KDnsBufferlength);
|
|
682 |
TPtr8 bufferPointer(buffer->Des());
|
|
683 |
publishBundle.Store(bufferPointer);
|
|
684 |
iNotifyMessageRequest.Write(0,bufferPointer);
|
|
685 |
iNotifyMessageRequest.Complete(KErrNone);
|
|
686 |
CleanupStack::PopAndDestroy(buffer);//buffer
|
|
687 |
publishBundle.Close();
|
|
688 |
}
|
|
689 |
__FLOG(_L8("CMdnsServerSession::NewServiceL - Exit"));
|
|
690 |
}
|
|
691 |
|
|
692 |
|
|
693 |
void CMdnsServerSession::CreateAnyQueryResponseL(CCacheEntry& aEntry)
|
|
694 |
{
|
|
695 |
RParameterFamily ptrFamily = iResponseBundle.CreateFamilyL (EMdnsPtrParamset);
|
|
696 |
RParameterFamily srvFamily = iResponseBundle.CreateFamilyL (EMdnsSrvParamset);
|
|
697 |
RParameterFamily txtFamily = iResponseBundle.CreateFamilyL (EMdnsTxtParamset);
|
|
698 |
RParameterFamily AFamily = iResponseBundle.CreateFamilyL (EMdnsAddrParamset);
|
|
699 |
if(aEntry.AddressRecord()!= NULL)
|
|
700 |
{
|
|
701 |
CMDnsAddrParamSet* responseParam = CMDnsAddrParamSet::NewL(AFamily);
|
|
702 |
responseParam->SetDomainNameL(aEntry.AddressRecord()->Name());
|
|
703 |
responseParam->SetAddress(aEntry.AddressRecord()->Address());
|
|
704 |
}
|
|
705 |
if(aEntry.ServiceRecord()!= NULL)
|
|
706 |
{
|
|
707 |
CMDnsSrvParamSet* responseParam = CMDnsSrvParamSet::NewL(srvFamily);
|
|
708 |
responseParam->SetDomainNameL(aEntry.ServiceRecord()->Name());
|
|
709 |
responseParam->SetTargetL(aEntry.ServiceRecord()->Target());
|
|
710 |
responseParam->SetPriority(aEntry.ServiceRecord()->Priority());
|
|
711 |
responseParam->SetWeight(aEntry.ServiceRecord()->Weight());
|
|
712 |
responseParam->SetPort(aEntry.ServiceRecord()->Port());
|
|
713 |
}
|
|
714 |
if(aEntry.PtrRecord()!= NULL)
|
|
715 |
{
|
|
716 |
CMDnsPtrParamSet* responseParam = CMDnsPtrParamSet::NewL(ptrFamily);
|
|
717 |
responseParam->SetInstanceNameL(aEntry.PtrRecord()->Name());
|
|
718 |
responseParam->SetDomainNameL(aEntry.PtrRecord()->DomainName());
|
|
719 |
//responseParam->SetTtlL(aEntry.PtrRecord()->Ttl());
|
|
720 |
}
|
|
721 |
if(aEntry.TxtRecord()!= NULL)
|
|
722 |
{
|
|
723 |
CMDnsTxtParamSet* responseParam = CMDnsTxtParamSet::NewL(txtFamily);
|
|
724 |
responseParam->SetDomainNameL(aEntry.TxtRecord()->Name());
|
|
725 |
RArray<RBuf8> txtData = aEntry.TxtRecord()->Text();
|
|
726 |
for(TInt txtCount = 0 ;txtCount < txtData.Count();txtCount++)
|
|
727 |
{
|
|
728 |
responseParam->AppendTxtData(txtData[txtCount]);
|
|
729 |
}
|
|
730 |
}
|
|
731 |
|
|
732 |
}
|