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 |
// cmessagehandler.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
/**
|
|
18 |
@file
|
|
19 |
@internalTechnology
|
|
20 |
*/
|
|
21 |
|
|
22 |
//System include
|
|
23 |
#include <mdns/cdnsmessagecomposerparser.h>
|
|
24 |
#include <mdns/cdnsmessage.h>
|
|
25 |
#include <e32base.h>
|
|
26 |
|
|
27 |
//user include
|
|
28 |
#include "cmessagehandler.h"
|
|
29 |
#include "cqueryhandler.h"
|
|
30 |
#include "ccacheentry.h"
|
|
31 |
#include "cresponsehandler.h"
|
|
32 |
#include "cadvertizehandler.h"
|
|
33 |
#include <mdns/mdnscachemgr.h>
|
|
34 |
|
|
35 |
__FLOG_STMT(_LIT8(KComponent,"MDNSServer");)
|
|
36 |
//
|
|
37 |
/**
|
|
38 |
Two phase constructor
|
|
39 |
@param aServer reference to CBonjourServer
|
|
40 |
@return pointer to CMessageHandler
|
|
41 |
*/
|
|
42 |
CMessageHandler* CMessageHandler::NewL(CMdnsServer& aServer)
|
|
43 |
{
|
|
44 |
CMessageHandler* self = new (ELeave) CMessageHandler(aServer);
|
|
45 |
CleanupStack::PushL(self);
|
|
46 |
self->ConstructL();
|
|
47 |
CleanupStack::Pop();
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
/**
|
|
51 |
Implementation of MSocketHandlerObserver
|
|
52 |
@param aData packet recieved from the mdns port
|
|
53 |
@param aAddr address from which packet is recieved
|
|
54 |
@param aLength length of the packet reieved
|
|
55 |
@return void
|
|
56 |
*/
|
|
57 |
void CMessageHandler::OnCompletionL(TDesC8& aData, const TSockAddr& aAddr, TInt aLength )
|
|
58 |
{
|
|
59 |
__FLOG(_L8("CMessageHandler::OnCompletionL - Entry"));
|
|
60 |
HandleIncomingPacketL(aData ,aAddr ,aLength );
|
|
61 |
iRecieveSocket->Activate(TSocketHandlerParams(ESocketRecieve));
|
|
62 |
__FLOG(_L8("CMessageHandler::OnCompletionL - Exit"));
|
|
63 |
}
|
|
64 |
/**
|
|
65 |
Any error in the socket will be notified here
|
|
66 |
@paran aError error with which socket leaves
|
|
67 |
@return void
|
|
68 |
*/
|
|
69 |
void CMessageHandler::OnError(TInt /*aError*/)
|
|
70 |
{
|
|
71 |
__FLOG(_L8("CMessageHandler::OnError -Entry Exit"));
|
|
72 |
}
|
|
73 |
|
|
74 |
/**
|
|
75 |
Constructor
|
|
76 |
*/
|
|
77 |
CMessageHandler::CMessageHandler(CMdnsServer& aServer):iServer(aServer)
|
|
78 |
{
|
|
79 |
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
Two phase constructor
|
|
84 |
*/
|
|
85 |
void CMessageHandler::ConstructL()
|
|
86 |
{
|
|
87 |
__FLOG_OPEN(KMDNSSubsystem, KComponent);
|
|
88 |
__FLOG(_L8("CMessageHandler::ConstructL - Entry"));
|
|
89 |
iQueryHandler = CQueryHandler::NewL(*this);
|
|
90 |
iResponseHandler = CResponseHandler::NewL(*this);
|
|
91 |
iAdvertizeHandler = CAdvertizeHandler::NewL(*this);
|
|
92 |
iRecieveSocket = CSocketHandler::NewL(iServer.Socket(),*this,ESocketRecieve);
|
|
93 |
iSendMessageQueue = CSendMessageQueue::NewL(iServer.Socket());
|
|
94 |
iRecieveSocket->Activate(TSocketHandlerParams(ESocketRecieve));
|
|
95 |
iDnsCache = CMDNSCacheManager::NewL(200);
|
|
96 |
iDummyhandler = CBaseHandler::NewL(*this);
|
|
97 |
__FLOG(_L8("CMessageHandler::ConstructL - Exit"));
|
|
98 |
}
|
|
99 |
|
|
100 |
/*
|
|
101 |
Destructor
|
|
102 |
*/
|
|
103 |
CMessageHandler::~CMessageHandler()
|
|
104 |
{
|
|
105 |
__FLOG(_L8("CMessageHandler::~CMessageHandler - Entry"));
|
|
106 |
delete iQueryHandler;
|
|
107 |
delete iResponseHandler;
|
|
108 |
delete iAdvertizeHandler;
|
|
109 |
delete iRecieveSocket;
|
|
110 |
TRAPD(err,iDnsCache->DumpCacheL());
|
|
111 |
delete iDnsCache;
|
|
112 |
delete iPacket;
|
|
113 |
delete iSendMessageQueue;
|
|
114 |
delete iDummyhandler;
|
|
115 |
__FLOG(_L8("CMessageHandler::~CMessageHandler - Exit"));
|
|
116 |
__FLOG_CLOSE;
|
|
117 |
}
|
|
118 |
/**
|
|
119 |
This method parse the packet and dispatch the packet for handling it based on the operation requested.
|
|
120 |
from the header
|
|
121 |
@param aData packet read from the mdns port
|
|
122 |
@param aAddr address from which the packet is recieved
|
|
123 |
@param length lenght of the data recieved
|
|
124 |
@return void
|
|
125 |
*/
|
|
126 |
void CMessageHandler::HandleIncomingPacketL(TDesC8& aData, const TSockAddr& aAddr, TInt /*length*/)
|
|
127 |
{
|
|
128 |
__FLOG(_L8("CMessageHandler::HandleIncomingPacketL - Entry"));
|
|
129 |
CDnsMessageComposerParser* comPos = CDnsMessageComposerParser::NewL();
|
|
130 |
CleanupStack::PushL(comPos);
|
|
131 |
CDnsMessage* message = comPos->ParseMessageL(aData);
|
|
132 |
CleanupStack::PushL(message);
|
|
133 |
CBaseHandler& iOperationHandler = GetHandlerL(*message);
|
|
134 |
iOperationHandler.HandleIncomingPacketL(*message ,aAddr);
|
|
135 |
CleanupStack::PopAndDestroy(message);//comPos and message
|
|
136 |
CleanupStack::PopAndDestroy(comPos);
|
|
137 |
__FLOG(_L8("CMessageHandler::HandleIncomingPacketL - Exit"));
|
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
This is a factory method which reads the packet and returns the handle to either
|
|
142 |
response or query handler
|
|
143 |
@param aMessage Dnspacket to read the header and to constructthe appropriate handler.
|
|
144 |
@return Poointer to CBaseHandler --base class to both response and query handler.
|
|
145 |
*/
|
|
146 |
CBaseHandler& CMessageHandler::GetHandlerL(CDnsMessage& aMessage)
|
|
147 |
{
|
|
148 |
__FLOG(_L8("CMessageHandler::GetHandlerL - Entry"));
|
|
149 |
TDnsHeader header = aMessage.Header();
|
|
150 |
//
|
|
151 |
if(header.IsQuery() && !header.IsAuthoritative())
|
|
152 |
{
|
|
153 |
return *iQueryHandler;
|
|
154 |
}
|
|
155 |
else if(header.IsAuthoritative())
|
|
156 |
{
|
|
157 |
return *iResponseHandler;
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{
|
|
161 |
return *iDummyhandler;
|
|
162 |
}
|
|
163 |
__FLOG(_L8("CMessageHandler::GetHandlerL - Exit"));
|
|
164 |
}
|
|
165 |
/**
|
|
166 |
@return return a reference to CacheManager
|
|
167 |
*/
|
|
168 |
MDNSCacheMgr& CMessageHandler::DnsCache() const
|
|
169 |
{
|
|
170 |
__FLOG(_L8("CMessageHandler::DnsCache -Entry Exit"));
|
|
171 |
return *iDnsCache;
|
|
172 |
}
|
|
173 |
|
|
174 |
/*
|
|
175 |
* Routes the query sent by the client to query handler to handle it.
|
|
176 |
* @param aMessage Pointer to a message object ;contains the query.
|
|
177 |
* @param aHandle session id which generated the query.
|
|
178 |
*/
|
|
179 |
void CMessageHandler::ServiceClientQueryL(CDnsMessage* aMessage,TInt aHandle)
|
|
180 |
{
|
|
181 |
__FLOG(_L8("CMessageHandler::ServiceClientQueryL - Entry"));
|
|
182 |
iQueryHandler->ServiceClientQueryL(aMessage, aHandle);
|
|
183 |
__FLOG(_L8("CMessageHandler::ServiceClientQueryL - Exit"));
|
|
184 |
}
|
|
185 |
|
|
186 |
/*
|
|
187 |
* returns the pointer to the messagequeue.
|
|
188 |
*/
|
|
189 |
CSendMessageQueue& CMessageHandler::MessageQueue()const
|
|
190 |
{
|
|
191 |
__FLOG(_L8("CMessageHandler::MessageQueue -Entry Exit"));
|
|
192 |
return *iSendMessageQueue;
|
|
193 |
}
|
|
194 |
|
|
195 |
/*
|
|
196 |
* Notify the server after the query has been handled.
|
|
197 |
* @param aClientHandle SessionId which had sent the query.
|
|
198 |
*/
|
|
199 |
void CMessageHandler::NotifyClientQuery(TInt aClientHandle)
|
|
200 |
{
|
|
201 |
__FLOG(_L8("CMessageHandler::NotifyClientQuery - Entry"));
|
|
202 |
iServer.NotifyClientQuery(aClientHandle);
|
|
203 |
__FLOG(_L8("CMessageHandler::NotifyClientQuery - Exit"));
|
|
204 |
}
|
|
205 |
|
|
206 |
/*
|
|
207 |
* Route an internal query to the query handler
|
|
208 |
* @param aMessage pointer to the dnsmeesage containg the query.
|
|
209 |
* @param Observer to which successfull delivery of packet to be notified.
|
|
210 |
*/
|
|
211 |
void CMessageHandler::SendQueryL(CDnsMessage* aMessage, MMessageHandler& aObserver)
|
|
212 |
{
|
|
213 |
__FLOG(_L8("CMessageHandler::SendQueryL - Entry"));
|
|
214 |
iQueryHandler->SendQueryL(aMessage, aObserver);
|
|
215 |
__FLOG(_L8("CMessageHandler::SendQueryL - Exit"));
|
|
216 |
}
|
|
217 |
/*
|
|
218 |
* Route the packet to be advertised to the adveritser.
|
|
219 |
* @param aData array of CDnsresourceData to be advertised.
|
|
220 |
* @param aSessionId session which adveritised the packet.
|
|
221 |
*/
|
|
222 |
void CMessageHandler::AdvertizePacketL(const RPointerArray<CDnsResourceData> aData, TInt aSessionId,TBool aIsUpdate)
|
|
223 |
{
|
|
224 |
__FLOG(_L8("CMessageHandler::AdvertizePacketL - Entry"));
|
|
225 |
iAdvertizeHandler->AdvertizePacketL(aData, aSessionId,aIsUpdate);
|
|
226 |
__FLOG(_L8("CMessageHandler::AdvertizePacketL - Exit"));
|
|
227 |
}
|
|
228 |
|
|
229 |
/*
|
|
230 |
* Notify the server when a new service is published
|
|
231 |
* @param aName name of the service published
|
|
232 |
* inacase of autoresolve name will be the new published name.
|
|
233 |
* @param aError will be the result of publish.ESuccess if successfull and E*Conflict.
|
|
234 |
* @param aSessionId session which initaiated publish.
|
|
235 |
*
|
|
236 |
*/
|
|
237 |
void CMessageHandler::NotifyServicePublishL(const RBuf8& aName,TInt aError, TInt aSessionId)
|
|
238 |
{
|
|
239 |
__FLOG(_L8("CMessageHandler::NotifyServicePublishL - Entry"));
|
|
240 |
iServer.NotifyServicePublishL(aName,aError, aSessionId);
|
|
241 |
__FLOG(_L8("CMessageHandler::NotifyServicePublishL - Exit"));
|
|
242 |
}
|
|
243 |
|
|
244 |
/*
|
|
245 |
* @param aProbing ETrue if hostprobing in progress.
|
|
246 |
*/
|
|
247 |
void CMessageHandler::SetStateHostProbing(TBool aProbing)
|
|
248 |
{
|
|
249 |
__FLOG(_L8("CMessageHandler::SetStateHostProbing - Entry"));
|
|
250 |
iServer.SetStateHostProbing(aProbing);
|
|
251 |
__FLOG(_L8("CMessageHandler::SetStateHostProbing - Exit"));
|
|
252 |
}
|
|
253 |
|
|
254 |
/*
|
|
255 |
* notify the server when a new service has been published in the network
|
|
256 |
* @param aName array of new service published , for the servcetype client has requested.
|
|
257 |
*/
|
|
258 |
void CMessageHandler::NotifyNewServiceL(const RArray<RBuf8>& aName)
|
|
259 |
{
|
|
260 |
__FLOG(_L8("CMessageHandler::NotifyNewServiceL - Entry"));
|
|
261 |
iServer.NotifyNewServiceL(aName);
|
|
262 |
__FLOG(_L8("CMessageHandler::NotifyNewServiceL - Exit"));
|
|
263 |
}
|
|
264 |
|
|
265 |
CMdnsServer& CMessageHandler::Server()
|
|
266 |
{
|
|
267 |
return iServer;
|
|
268 |
}
|