networkprotocols/dnsproxy/dnsproxyserver/src/dnsproxywriter.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // This class constructs the DNS response packet and sends it back to
       
    15 // querying hosts. After sending the DNS query response to querying hosts,
       
    16 // DNS writer checks if there is anything pending in the queue which needs
       
    17 // to be send back to the querying host.Once done it deletes the completed
       
    18 // query context from the queue. This is dervied from CActive.
       
    19 //
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file
       
    25  @internalTechnology
       
    26 */
       
    27 #include "inet6log.h"
       
    28 #include <cflog.h>
       
    29 #include "dnsproxylistener.h"
       
    30 #include "dnsproxywriter.h"
       
    31 
       
    32 CDnsProxyWriter* CDnsProxyWriter::NewL(CDnsProxyListener& aListener)
       
    33 /**
       
    34  * This method creates an instance of CDnsProxyWriter.
       
    35  * @param aListener - Reference of the listener object
       
    36  * @return - Pointer to class instance
       
    37  *
       
    38  * @internalTechnology
       
    39  **/
       
    40 	{
       
    41     CDnsProxyWriter*writer = new(ELeave)CDnsProxyWriter(aListener);
       
    42 	return writer;
       
    43 	}
       
    44 
       
    45 CDnsProxyWriter::CDnsProxyWriter(CDnsProxyListener& aListener):CActive(EPriorityStandard),iListener(aListener)
       
    46 /**
       
    47  * This is constructor for CDnsProxyWriter.It adds itself to CActive scheduler.
       
    48  * @param aListener - Reference of the listener object
       
    49  * @return - None
       
    50  *
       
    51  * @internalTechnology
       
    52  **/
       
    53 
       
    54 	{
       
    55 	CActiveScheduler::Add(this);
       
    56 	}
       
    57 
       
    58 void CDnsProxyWriter::ConstructL()
       
    59 /**
       
    60  * Second phase construction
       
    61  * @param -None
       
    62  * @return -None
       
    63  *
       
    64  * @internalTechnology
       
    65  **/
       
    66 
       
    67 	{
       
    68 	}
       
    69 
       
    70 CDnsProxyWriter::~CDnsProxyWriter()
       
    71 /**
       
    72  * This is destructor for CDnsProxyWriter.It cancels any pending requests.
       
    73  * @param -None
       
    74  * @return -None
       
    75  *
       
    76  * @internalTechnology
       
    77  **/
       
    78 
       
    79 	{
       
    80     Cancel();
       
    81 	}
       
    82 
       
    83 void CDnsProxyWriter::RunL()
       
    84 /**
       
    85  * This method implements RunL method of this active object.It deletes all the completed queries
       
    86  * and processes the next resolved query. That is, query whose state is EResolved.
       
    87  *
       
    88  * @param - None
       
    89  * @return - None
       
    90  *
       
    91  * @internalTechnology
       
    92  **/
       
    93 
       
    94 	{
       
    95 		//delete the completed messages
       
    96 		TInt index = 0;
       
    97 		TQueryContext *qCtx = NULL;
       
    98 
       
    99 		while(iListener.iQueryContext.Count() > index)
       
   100 			{
       
   101 			TQueryState queryState = iListener.iQueryContext[index]->GetQueryState();
       
   102 			TQueryContext *qCtx = iListener.GetQCtxFromList(EQueryDone);
       
   103 			if(qCtx)
       
   104 				{
       
   105 				iListener.DeleteQCtxFromListL(qCtx);
       
   106 				qCtx = NULL;
       
   107 				}
       
   108             index++;
       
   109 			}
       
   110 			
       
   111 		qCtx = iListener.GetQCtxFromList(EResolved);
       
   112 		if(qCtx)
       
   113 			{
       
   114 			WriteTo(qCtx);
       
   115 			}
       
   116 	}
       
   117 
       
   118 void CDnsProxyWriter::DoCancel()
       
   119 /**
       
   120  * This method cancels outstanding write request.
       
   121  * @param - None
       
   122  * @return - None
       
   123  *
       
   124  * @internalTechnology
       
   125  **/
       
   126 
       
   127 	{
       
   128 	iListener.iListenerSocket.CancelSend();
       
   129 	}
       
   130 
       
   131 void CDnsProxyWriter::WriteTo(TQueryContext* aQueryContext)
       
   132 /**
       
   133  * This method gets DNS response from query context and sends it to the querying host.
       
   134  * @param queryContext - Pointer to the query context
       
   135  * @return - None
       
   136  *
       
   137  * @internalTechnology
       
   138  **/
       
   139 	{
       
   140 	if(IsActive())
       
   141 		return;
       
   142 	
       
   143 	TPtrC8 msg = aQueryContext->GetDnsReplyMessage();
       
   144 	addr = aQueryContext->GetSourceAddr();
       
   145 	aQueryContext->SetQueryState(EQueryDone);
       
   146 
       
   147 	iListener.iListenerSocket.SendTo(msg,aQueryContext->GetSourceAddr(),0,iStatus);
       
   148 	SetActive();
       
   149 	}
       
   150 
       
   151 TInt CDnsProxyWriter::RunError(TInt /*aErr*/)
       
   152 /**
       
   153  * This method implements RunError method of an active object. This helps in debugging.
       
   154  * @param aErr - Error code
       
   155  * @return - Error code
       
   156  *
       
   157  * @internalTechnology
       
   158  **/
       
   159 	{
       
   160 	iListener.DeleteAllQCtxFromList();
       
   161 	return KErrNone;
       
   162 	}