tcpiputils/dnd/inc/dns.h
changeset 0 af10295192d8
child 20 7e41d162e158
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // dns.h - name resolver DNS client module header
       
    15 //
       
    16 
       
    17 #ifndef __DNS_H__
       
    18 #define __DNS_H__
       
    19 
       
    20 /**
       
    21 @file dns.h
       
    22 DNS protocol proviver
       
    23 @internalComponent	Domain Name Resolver
       
    24 */
       
    25 
       
    26 #include "listener.h"
       
    27 #include "message.h"
       
    28 #include "dns_sock.h"
       
    29 #include "hostname.h"
       
    30 
       
    31 #ifdef EXCLUDE_SYMBIAN_DNS_PUNYCODE
       
    32 #undef SYMBIAN_DNS_PUNYCODE
       
    33 #endif //EXCLUDE_SYMBIAN_DNS_PUNYCODE
       
    34 
       
    35 const TUint KDndNumRequests = KDndNumResolver * 2;
       
    36 
       
    37 class CDndRecord;
       
    38 class CDndDnsclient;
       
    39 class CDndCache;
       
    40 /**
       
    41 // @brief	The request data
       
    42 //
       
    43 // TDndReqData is the DNS protocol side of the <b>query session</b> used by a
       
    44 // <b>resolver</b>. The <b>resolvers</b> side is only visible via the MDnsResolver
       
    45 // callback class. On the other hand, the visible services of this class
       
    46 // for the resolver (CDndResolver) are defined by the MDnsSession. 
       
    47 */
       
    48 class TDndReqData : public TDnsRequest, public MDnsSession, public MDnsServerListNotify
       
    49 	{
       
    50 public:
       
    51 	//
       
    52 	// MDnsSession API (methods callable by resolver)
       
    53 	// (documented in the mixin class)
       
    54 	virtual TInt NewQuery(const TDnsMessage &aQuery, TDnsServerScope aServerScope, TUint32 aFlags);
       
    55 	virtual void CancelQuery();
       
    56 	virtual TInt DoQueryL(const TTime &aRequestTime, const EDnsQType aQType);
       
    57 	virtual TInt DoNext(TDnsMessageBuf &aReply, TInt aNext) const;
       
    58 	void DoError(TInt aError, TUint aTTL);
       
    59 	virtual TBool PickNewServer();
       
    60 	virtual TBool PickDefaultServer();
       
    61 	void Close();
       
    62 
       
    63 
       
    64 	//
       
    65 	// MDnsServerListNotify callback
       
    66 	//
       
    67 	// The notify callback from the server manager
       
    68 	virtual void ServerListComplete(const TDnsServerFilter &aFilter, TInt aResult);
       
    69 	//
       
    70 	// Upcalls from DNS Socket
       
    71 	//
       
    72 	// Build a complete DNS message from request data
       
    73 	virtual TBool Build(CDnsSocket &aSource, TMsgBuf &aBuf, TInetAddr &aServer, TInt aMaxMessage);
       
    74 	// Handle a reply message for the request (request remains queued)
       
    75 	virtual TBool Reply(CDnsSocket &aSource, const TMsgBuf &aBuf, const TInetAddr &aServer);
       
    76 	// The message has been sent (request remains queued)
       
    77 	virtual void Sent(CDnsSocket &aSource);
       
    78 	// The request has been aborted (not queued anymore)
       
    79 	virtual void Abort(CDnsSocket &aSource, const TInt aReason);
       
    80 
       
    81 	// Generate the callback event for the resolver owning this request
       
    82 	void SendResponse(TInt aErr);
       
    83 protected:
       
    84 	//
       
    85 	// Internal utilities
       
    86 	//
       
    87 	// Check the message question against request data
       
    88 	TInt CheckQuestion(const TMsgBuf &aMsg, TInt &aRCode) const;
       
    89 	// Check request against responce and translate RCODE value.
       
    90 	TInt TranslateRCODE(const TDndHeader &aHdr, TInt aRCode) const;
       
    91 	// Build a TNameRecord record from a RR
       
    92 	TInt GetResponse(const TDndRR &aRR, TNameRecord &aReply) const;
       
    93 	// Update DNS reply into cache
       
    94 	TBool UpdateCacheData(const TMsgBuf &aMsg, const TInt aAnswerOffset, const TInt aErr);
       
    95 	// Return instance ptr of the actual class instance
       
    96 	virtual const void *const Instance() const {return this; }
       
    97 
       
    98 public:
       
    99 	TUint iIsReqPending:1;	//< Resolver is waiting for a reply
       
   100 	TUint iIsUsingTCP:1;	//< Set when TCP is in use, only a safeguard against bad DNS servers.
       
   101 	TUint iIsNewQuery:1;	//< Set in NewQuery, cleared in DoQuery (used in deciding whether a new ID is needed)
       
   102 	TUint iIsFromCache:1;	//< Set if iRecord was from cached
       
   103 	TUint iOpcode:4;		//< OPCODE field of the header
       
   104 #ifdef SYMBIAN_DNS_PUNYCODE
       
   105 	TUint iIdnEnabled:1;	//< =1, support for IDN is enabled for this request.
       
   106 #endif //SYMBIAN_DNS_PUNYCODE
       
   107 
       
   108 	TUint16 iQdCount;
       
   109 	TUint32 iFlags;			//< Mofidier flags for the query (RD, PQ etc).
       
   110 	TDndQuestion iQuestion;	//< Query Information
       
   111 	TDnsServerFilter iFilter;
       
   112 	TUint32 iCurrentServer;
       
   113 
       
   114 	CDndRecord *iRecord;	//< Pointer to the record in the cache is stored here when a DNS query
       
   115 							//< is sent - for quick update of cache.
       
   116 	// Callback section
       
   117 	MDnsResolver *iCallback;
       
   118 	// "Owner" source
       
   119 	CDndDnsclient *iOwner;	//< Actual owner of the request data
       
   120 
       
   121 	TUint iNetworkId;      //< NetworkId from the request message.	
       
   122 	};
       
   123 
       
   124 class TInetAddressInfo;
       
   125 class CDndDnsclient : public CDnsSocket, public MDnsSource
       
   126     {
       
   127 	friend class CDndMonitor;
       
   128 	friend class TDndReqData;
       
   129 protected:
       
   130 	CDndDnsclient(CDndEngine &aControl, MDnsServerManager &aServerManager);
       
   131 	void ConstructL();
       
   132 public:
       
   133 	static CDndDnsclient *NewL(CDndEngine &aControl, MDnsServerManager &aServerManager);
       
   134 
       
   135 	void HandleCommandL(TInt aCommand);
       
   136 	virtual ~CDndDnsclient();
       
   137 	// Configuration has changed
       
   138 	virtual void ConfigurationChanged() = 0;
       
   139 
       
   140 	// Assign a session slot
       
   141 	MDnsSession *OpenSession(MDnsResolver *const aCallback);
       
   142 	// Check if there is a route and valid source address for the aDestination
       
   143 	TInt CheckAddress(const TInetAddr &aDestination);
       
   144 	// Resolver has received a query from application
       
   145 	void QueryBegin();
       
   146 	// Resolver has completed the query from application
       
   147 	void QueryEnd();
       
   148 
       
   149 protected:
       
   150 	// Received a Query Message from some server -- ignore by default
       
   151 	void Query(const TMsgBuf &/*aBuf*/, const TInetAddr &/*aServer*/, const RSocket &/*aSocket*/) {}
       
   152 	// Received an error indication for a server
       
   153 	void Error(const TInetAddr &aServer, TInt aError);
       
   154 	inline void ActivateSocketL(TUint aNetworkId = 0) { CDnsSocket::ActivateSocketL(aNetworkId); } // lint placebo
       
   155 
       
   156 	CDndEngine &iControl;					//< The DND Engine
       
   157 	MDnsServerManager &iServerManager;		//< The server manager
       
   158 	TDndReqData	iDndReqData[KDndNumRequests];	//< Requests being served
       
   159 	TUint iActivityCount;			//< Count of activity, shut DNS sockets when ZERO.
       
   160 	CDndCache *iCache;				//< The Cache
       
   161 	THostNames iHostNames;			//< The current hostnames
       
   162 	};
       
   163 
       
   164 #endif