omadrm/drmengine/roap/src/RoapMessage.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include "RoapMessage.h"
       
    23 #include "Base64.h"
       
    24 
       
    25 using namespace Roap;
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 //extern  ?external_data;
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 //extern ?external_function( ?arg_type,?arg_type );
       
    32 
       
    33 // CONSTANTS
       
    34 //const ?type ?constant_var = ?constant;
       
    35 
       
    36 // MACROS
       
    37 //#define ?macro ?macro_def
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 const TInt KIso8601TimeLength = 20;
       
    41 _LIT8(KIso8601TimeFormat, "%04d-%02d-%02dT%02d:%02d:%02dZ");
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 //enum ?declaration
       
    45 //typedef ?declaration
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 //?type ?function_name( ?arg_type, ?arg_type );
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 //class ?FORWARD_CLASSNAME;
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // ?function_name ?description.
       
    57 // ?description
       
    58 // Returns: ?value_1: ?description
       
    59 //          ?value_n: ?description_line1
       
    60 //                    ?description_line2
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 
       
    64 // ============================ MEMBER FUNCTIONS ===============================
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CRoapMessage::CRoapMessage
       
    68 // C++ default constructor can NOT contain any code, that
       
    69 // might leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CRoapMessage::CRoapMessage()
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CRoapMessage::ConstructL
       
    78 // Symbian 2nd phase constructor can leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CRoapMessage::ConstructL()
       
    82     {
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CRoapMessage::NewL
       
    87 // Two-phased constructor.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CRoapMessage* CRoapMessage::NewL()
       
    91     {
       
    92     CRoapMessage* self = new( ELeave ) CRoapMessage;
       
    93     
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop();
       
    97 
       
    98     return self;
       
    99     }
       
   100 
       
   101     
       
   102 // Destructor
       
   103 CRoapMessage::~CRoapMessage()
       
   104     {
       
   105     delete iXmlData;
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CRoapMessage::?member_function
       
   111 // ?implementation_description
       
   112 // (other items were commented in a header).
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 HBufC8* CRoapMessage::MessageAsXmlL(void)
       
   116     {
       
   117     return iXmlData->AllocL();
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CRoapMessage::?member_function
       
   122 // ?implementation_description
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CRoapMessage::SetXmlData(
       
   127     HBufC8* aData)
       
   128     {
       
   129     iXmlData = aData;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CRoapMessage::?member_function
       
   134 // ?implementation_description
       
   135 // (other items were commented in a header).
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 HBufC8* CRoapMessage::TimeToIso8601L(
       
   139     TTime& aTime)
       
   140     {
       
   141     HBufC8* r = NULL;
       
   142     TDateTime t;
       
   143     
       
   144     t = aTime.DateTime();
       
   145     r = HBufC8::NewMax(KIso8601TimeLength);
       
   146     User::LeaveIfNull(r);
       
   147     TPtr8 des = r->Des();
       
   148     des.Format(KIso8601TimeFormat, t.Year(), t.Month() + 1, t.Day() + 1,
       
   149         t.Hour(), t.Minute(), t.Second());
       
   150     return r;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CRoapMessage::?member_function
       
   155 // ?implementation_description
       
   156 // (other items were commented in a header).
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TTime CRoapMessage::Iso8601ToTime(TDesC8& aTimeString)
       
   160     {
       
   161     TLex8 lex;
       
   162     TInt year = 0;
       
   163     TInt month = 0;
       
   164     TInt day = 0;
       
   165     TInt hour = 0;
       
   166     TInt minute = 0;
       
   167     TInt second = 0;
       
   168     TTime r = Time::NullTTime();
       
   169     TLocale l;
       
   170     TTimeIntervalSeconds offset(l.UniversalTimeOffset());
       
   171 
       
   172     if (aTimeString.Length() > 0)
       
   173         {    
       
   174         lex = aTimeString;
       
   175         lex.Val(year);
       
   176         lex.Inc();
       
   177         lex.Val(month);
       
   178         lex.Inc();
       
   179         lex.Val(day);
       
   180         lex.Inc();
       
   181         lex.Val(hour);
       
   182         lex.Inc();
       
   183         lex.Val(minute);
       
   184         lex.Inc();
       
   185         lex.Val(second);
       
   186         r = TTime(TDateTime(year, static_cast<TMonth>(month - 1), day - 1, hour,
       
   187             minute, second, 0));
       
   188         if (lex.Get() != 'Z')
       
   189             {
       
   190             r += offset;
       
   191             }
       
   192         }
       
   193     return r;
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CRoapMessage::?member_function
       
   198 // ?implementation_description
       
   199 // (other items were commented in a header).
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CRoapMessage::BufAppendL(
       
   203     CBufFlat* aBuffer,
       
   204     const TDesC8& aConst)
       
   205     {
       
   206     aBuffer->InsertL(aBuffer->Size(), aConst);
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CRoapMessage::?member_function
       
   211 // ?implementation_description
       
   212 // (other items were commented in a header).
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CRoapMessage::BufAppendBase64L(
       
   216     CBufFlat* aBuffer,
       
   217     const TDesC8& aConst)
       
   218     {
       
   219     HBufC8* buffer = NULL;
       
   220 
       
   221     buffer = Base64EncodeL(aConst);
       
   222     CleanupStack::PushL(buffer);
       
   223     aBuffer->InsertL(aBuffer->Size(), *buffer);
       
   224     CleanupStack::PopAndDestroy(buffer);
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CRoapMessage::?member_function
       
   229 // ?implementation_description
       
   230 // (other items were commented in a header).
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CRoapMessage::BufAppendTimeL(
       
   234     CBufFlat* aBuffer,
       
   235     TTime& aTime)
       
   236     {
       
   237     HBufC8* buffer = NULL;
       
   238 
       
   239     buffer = TimeToIso8601L(aTime);
       
   240     CleanupStack::PushL(buffer);
       
   241     aBuffer->InsertL(aBuffer->Size(), *buffer);
       
   242     CleanupStack::PopAndDestroy(buffer);
       
   243     }
       
   244 
       
   245 //  End of File