zeroconf/dnsparser/src/cdnsmessage.cpp
changeset 14 da856f45b798
equal deleted inserted replaced
12:78fbd574edf4 14:da856f45b798
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "cdnsmessage.h"
       
    21 
       
    22 
       
    23 CDnsMessage::CDnsMessage(TUint16 aId, TBool aQuery)
       
    24    {
       
    25    iHeader.SetId(aId);
       
    26    iHeader.SetQuery(aQuery);
       
    27    }
       
    28 
       
    29 EXPORT_C CDnsMessage* CDnsMessage::NewL(TUint16 aId, TBool aQuery)
       
    30 	{
       
    31 	return ( new(ELeave)CDnsMessage(aId, aQuery) );
       
    32     }
       
    33 
       
    34 CDnsMessage::~CDnsMessage()
       
    35 	{
       
    36 	iQueries.ResetAndDestroy();
       
    37 	iQueries.Close();
       
    38 	iAnswers.ResetAndDestroy();
       
    39 	iAnswers.Close();
       
    40 	iAuthorities.ResetAndDestroy();
       
    41 	iAuthorities.Close();
       
    42 	iAdditional.ResetAndDestroy();
       
    43 	iAdditional.Close();
       
    44     }
       
    45 
       
    46 EXPORT_C void CDnsMessage::SetHeader(const TDnsHeader& aHeader)
       
    47 	{
       
    48 	iHeader = aHeader;
       
    49 	}
       
    50 
       
    51 EXPORT_C void CDnsMessage::AppendQueryL(const CDnsQuestion* aQuery)
       
    52 	{
       
    53 	iQueries.AppendL(aQuery);
       
    54 	iHeader.SetQueryCount(iQueries.Count());
       
    55 	}
       
    56 
       
    57 EXPORT_C void CDnsMessage::AppendAnswerL(const CDnsResourceData* aAnswer)
       
    58 	{
       
    59     	iAnswers.AppendL(aAnswer);
       
    60     	iHeader.SetAnswerCount(iAnswers.Count());
       
    61     	}
       
    62 
       
    63 EXPORT_C void CDnsMessage::AppendAuthorityL(const CDnsResourceData* aAuthority)
       
    64 	{
       
    65 	iAuthorities.AppendL(aAuthority);
       
    66 	iHeader.SetAuthorityNSCount(iAuthorities.Count());
       
    67     }
       
    68 
       
    69 EXPORT_C void CDnsMessage::AppendAdditionalL(const CDnsResourceData* aAdditional)
       
    70     {
       
    71     iAdditional.AppendL(aAdditional);
       
    72     iHeader.SetAdditionalRCount(iAdditional.Count());
       
    73     }
       
    74 
       
    75 EXPORT_C const RPointerArray<CDnsQuestion>& CDnsMessage::Queries()const
       
    76 	{
       
    77 	return iQueries;
       
    78 	}
       
    79 
       
    80 EXPORT_C const RPointerArray<CDnsResourceData>& CDnsMessage::Answers()const
       
    81 	{
       
    82 	return iAnswers;
       
    83     }
       
    84 
       
    85 EXPORT_C const RPointerArray<CDnsResourceData>& CDnsMessage::Authorities()const
       
    86 	{
       
    87 	return iAuthorities;
       
    88     }
       
    89 
       
    90 EXPORT_C const RPointerArray<CDnsResourceData>& CDnsMessage::Additional()const
       
    91 	{
       
    92 	return iAdditional;
       
    93     }
       
    94 
       
    95 EXPORT_C const TDnsHeader& CDnsMessage::Header()const
       
    96 	{
       
    97 	return iHeader;
       
    98     }
       
    99 
       
   100 //Calculates the size of the dns message
       
   101 EXPORT_C TUint16 CDnsMessage::Size()const
       
   102     {
       
   103     TUint16 size =0;
       
   104     size  += sizeof(iHeader);
       
   105    
       
   106     TInt i;
       
   107    
       
   108     for ( i=0; i<iQueries.Count(); i++)	   
       
   109 	    {
       
   110 	    CDnsQuestion* ques = iQueries[i];
       
   111 	    size  += ques->Size();
       
   112 	    }
       
   113 
       
   114 	for ( i=0; i<iAnswers.Count(); i++)	   
       
   115 		{
       
   116 		CDnsResourceData* rData = iAnswers[i];
       
   117 		size  += rData->Size();
       
   118 		}
       
   119 	   
       
   120 	for ( i=0; i<iAuthorities.Count(); i++)	   
       
   121 		{
       
   122 		CDnsResourceData* rData = iAuthorities[i];
       
   123 		size  += rData->Size();
       
   124 	    }
       
   125 	   
       
   126 	for ( i=0; i<iAdditional.Count(); i++)	   
       
   127 		{
       
   128 		CDnsResourceData* rData = iAdditional[i];
       
   129 		size  += rData->Size();
       
   130 		}
       
   131 	return size ;
       
   132 	}
       
   133 
       
   134