natfw/natfwunsaf_protocols/unsaf_codec/inc/natfwunsaftcprelaypacket.h
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 #ifndef CNATFWUNSAFTCPRELAYPACKET_H
       
    22 #define CNATFWUNSAFTCPRELAYPACKET_H
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 /**
       
    27 * A class for UNSAF TCP relay packets
       
    28 *
       
    29 *  @lib natfwunsafprotocols.lib
       
    30 *  @since S60 3.2
       
    31 */
       
    32 class CNATFWUNSAFTcpRelayPacket : public CBase
       
    33     {
       
    34 public: // Enumerations
       
    35 
       
    36     enum TFrame // draft-ietf-behave-turn-02
       
    37         {
       
    38         EFrameTypeOffset     = 0,
       
    39         EFrameLengthOffset   = 2,
       
    40         
       
    41         EFrameTypePrefixMask = 0xff00,
       
    42         EFrameSize           = 4
       
    43         };
       
    44     
       
    45     enum TRelayType
       
    46         {
       
    47         EFrameTypeStun       = 0x02,
       
    48         EFrameTypeData       = 0x03,
       
    49         };
       
    50         
       
    51 public: // Constructors and destructor
       
    52     
       
    53     /**
       
    54     * Creates a CNATFWUNSAFTcpRelayPacket instance
       
    55     * @param aData Data to be relayed
       
    56     * @param aType Type of relay (STUN/DATA)
       
    57     * @return A new instance of CNATFWUNSAFTcpRelayPacket
       
    58     */
       
    59     IMPORT_C static CNATFWUNSAFTcpRelayPacket*
       
    60                 NewL(const TDesC8& aData, const TRelayType aType);
       
    61 
       
    62     /**
       
    63     * Creates a CNATFWUNSAFTcpRelayPacket instance
       
    64     * @param aData Data to be relayed
       
    65     * @param aType Type of relay (STUN/DATA)
       
    66     * @return A new instance of CNATFWUNSAFTcpRelayPacket
       
    67     */
       
    68     IMPORT_C static CNATFWUNSAFTcpRelayPacket*
       
    69                 NewLC(const TDesC8& aData, const TRelayType aType);
       
    70 
       
    71     /**
       
    72     * Creates a CNATFWUNSAFTcpRelayPacket instance.
       
    73     * @param aData Data to be relayed
       
    74     * @param aType Type of relay (STUN/DATA)
       
    75     * @return A new instance of CNATFWUNSAFTcpRelayPacket
       
    76     *       ownership is transferred.
       
    77     */
       
    78     static CNATFWUNSAFTcpRelayPacket*
       
    79         CreateL(const TDesC8& aData, const TRelayType aType);
       
    80 
       
    81     /**
       
    82     * Destructor, deletes the resources of CNATFWUNSAFTcpRelayPacket.
       
    83     */
       
    84     virtual ~CNATFWUNSAFTcpRelayPacket();
       
    85 
       
    86 public: // New functions
       
    87 
       
    88     /**
       
    89     * Encodes a relay packet
       
    90     * @return The encoded UNSAF TCP relay packet. The ownership is
       
    91     *         transferred.
       
    92     */
       
    93     IMPORT_C CBufBase* EncodeL() const;
       
    94 
       
    95     /**
       
    96     * Returns the relayed data
       
    97     * @return relayed data
       
    98     */
       
    99     IMPORT_C const TDesC8& Data() const;
       
   100 
       
   101     /**
       
   102     * Returns the relay type
       
   103     * @return relay type
       
   104     */
       
   105     IMPORT_C TRelayType Type() const;
       
   106 
       
   107     /**
       
   108     * Retrieves the UNSAF TCP relay packet length from a UNSAF TCP relay
       
   109     * packet header.
       
   110     * @param aNATFWUNSAFTcpRelayPacket a UNSAF TCP relay packet
       
   111     * @return KErrNotFound if length field cannot be parsed.
       
   112     *         Otherwise the value of the length field.
       
   113     */
       
   114     static TInt RelayLength(const TDesC8& aNATFWUNSAFTcpRelayPacket);
       
   115 
       
   116     /**
       
   117     * Writes the length field into WUNSAF TCP relay packet header.
       
   118     * @param aNATFWUNSAFTcpRelayPacket Encoded UNSAF TCP relay packet
       
   119     *        whose length is to be calculated and written.
       
   120     */
       
   121     static void SetRelayLength(CBufBase& aNATFWUNSAFTcpRelayPacket);
       
   122 
       
   123     /**
       
   124     * Writes the length field into NATFWUNSAF TCP relay packet header.
       
   125     * @param aNATFWUNSAFTcpRelayPacket Encoded UNSAF TCP relay packet whose
       
   126     *        length is to be set.
       
   127     * @param aLength Value to write into the length field.
       
   128     */
       
   129     static void SetRelayLength(CBufBase& aNATFWUNSAFTcpRelayPacket,
       
   130         TInt aLength);
       
   131 
       
   132 protected: // Constructors
       
   133 
       
   134     CNATFWUNSAFTcpRelayPacket();
       
   135     
       
   136     /**
       
   137     * Second phase constructor.
       
   138     * @param aData data to be relayed
       
   139     * @param aType type of relay (STUN/DATA)
       
   140     */
       
   141     void ConstructL(const TDesC8& aData, const TRelayType aType);
       
   142 
       
   143 private:
       
   144 
       
   145     /**
       
   146     * Encodes the UNSAF TCP relay packet header.
       
   147     * @return The encoded UNSAF relay packet header. The ownership is
       
   148     *         transferred.
       
   149     */
       
   150     CBufBase* EncodeRelayHeaderLC() const;
       
   151     
       
   152     /**
       
   153     * Checks that the length of relayed data is valid
       
   154     * @param aLength Length of the relayed data
       
   155     * @leave KErrCorrupt If the length is invalid
       
   156     */
       
   157     void CheckLengthL(TInt aLength) const;
       
   158 
       
   159 private: // Data
       
   160     
       
   161     //Relayed data, owned
       
   162     HBufC8* iData;
       
   163     
       
   164     //Relay type
       
   165     TRelayType iType;
       
   166     
       
   167 private:
       
   168 
       
   169     enum TValueDataGranularity
       
   170         {
       
   171         //The length of iValue has to be a multiple of 4
       
   172         EGranularity = 4
       
   173         };
       
   174     };
       
   175 
       
   176 #endif // CNATFWUNSAFTCPRELAYPACKET_H
       
   177 
       
   178