natfw/natfwunsaf_protocols/unsaf_codec/src/natfwunsafchangerequestattribute.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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 
       
    21 #include <es_sock.h>
       
    22 #include "natfwunsafchangerequestattribute.h"
       
    23 #include "natfwunsafutils.h"
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CNATFWUNSAFChangeRequestAttribute::NewL
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CNATFWUNSAFChangeRequestAttribute*
       
    30 CNATFWUNSAFChangeRequestAttribute::NewL(TBool aChangeIP, TBool aChangePort)
       
    31     {
       
    32     CNATFWUNSAFChangeRequestAttribute* self =
       
    33         CNATFWUNSAFChangeRequestAttribute::NewLC(aChangeIP, aChangePort);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CNATFWUNSAFChangeRequestAttribute::NewLC
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CNATFWUNSAFChangeRequestAttribute*
       
    43 CNATFWUNSAFChangeRequestAttribute::NewLC(TBool aChangeIP, TBool aChangePort)
       
    44     {
       
    45     CNATFWUNSAFChangeRequestAttribute* self =
       
    46         new (ELeave) CNATFWUNSAFChangeRequestAttribute(aChangeIP, aChangePort);
       
    47     CleanupStack::PushL(self);
       
    48     return self;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CNATFWUNSAFChangeRequestAttribute::DecodeAttributeL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CNATFWUNSAFAttribute*
       
    56 CNATFWUNSAFChangeRequestAttribute::DecodeAttributeL(const TDesC8& aByteStream)
       
    57     {
       
    58     TUint16 valueLength = ParseLengthL(aByteStream);
       
    59     __ASSERT_ALWAYS(valueLength == EAttributeValueSize,
       
    60                     User::Leave(KErrCorrupt));
       
    61     __ASSERT_ALWAYS(aByteStream.Length() >= EValueOffset + valueLength,
       
    62                     User::Leave(KErrArgument));
       
    63 
       
    64     TUint32 value = BigEndian::Get32(aByteStream.Mid(EValueOffset).Ptr());
       
    65 
       
    66     return NewL((value & EChangeIPMask) > 0, (value & EChangePortMask) > 0);
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CNATFWUNSAFChangeRequestAttribute::CNATFWUNSAFChangeRequestAttribute
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CNATFWUNSAFChangeRequestAttribute::CNATFWUNSAFChangeRequestAttribute(
       
    74     TBool aChangeIP, TBool aChangePort) :
       
    75     CNATFWUNSAFAttribute(),
       
    76     iChangeIP(aChangeIP),
       
    77     iChangePort(aChangePort)
       
    78     {
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CNATFWUNSAFChangeRequestAttribute::~CNATFWUNSAFChangeRequestAttribute
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CNATFWUNSAFChangeRequestAttribute::~CNATFWUNSAFChangeRequestAttribute()
       
    86     {
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CNATFWUNSAFChangeRequestAttribute::Type
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CNATFWUNSAFAttribute::TType CNATFWUNSAFChangeRequestAttribute::Type() const
       
    94     {
       
    95     return EChangeRequest;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CNATFWUNSAFChangeRequestAttribute::EncodeValueL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 HBufC8* CNATFWUNSAFChangeRequestAttribute::EncodeValueL() const
       
   103     {
       
   104     HBufC8* encodedValue = HBufC8::NewLC(EAttributeValueSize);
       
   105 
       
   106     TPtr8 ptr = encodedValue->Des();
       
   107     ptr.FillZ(EAttributeValueSize);
       
   108 
       
   109     TUint32 value(0);
       
   110     if (ChangeIP())
       
   111         {
       
   112         value = value | EChangeIPMask;
       
   113         }
       
   114     if (ChangePort())
       
   115         {
       
   116         value = value | EChangePortMask;
       
   117         }
       
   118 
       
   119     NATFWUNSAFUtils::WriteNetworkOrder32L(ptr, 0, value);
       
   120 
       
   121     CleanupStack::Pop(encodedValue);
       
   122     return encodedValue;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CNATFWUNSAFChangeRequestAttribute::ChangeIP
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TBool CNATFWUNSAFChangeRequestAttribute::ChangeIP() const
       
   130     {
       
   131     return iChangeIP;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CNATFWUNSAFChangeRequestAttribute::ChangePort
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TBool CNATFWUNSAFChangeRequestAttribute::ChangePort() const
       
   139     {
       
   140     return iChangePort;
       
   141     }