webservices/wsoviplugin/src/wsovidevicehandler.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 #include "wsovidevicehandler.h"
       
    28 #include "senlogger.h"
       
    29 #include <SenTransportProperties.h>
       
    30 using namespace OAuth;
       
    31 // Create instance of concrete ECOM interface implementation
       
    32 CWSOviDeviceHandler* CWSOviDeviceHandler::NewL(TAny* aHandlerCtx)
       
    33     {
       
    34     
       
    35     MSenHandlerContext* handlerCtx =
       
    36         reinterpret_cast<MSenHandlerContext*>(aHandlerCtx);
       
    37     CWSOviDeviceHandler* self   = new (ELeave) CWSOviDeviceHandler(*handlerCtx);
       
    38     CleanupStack::PushL (self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 // Constructor
       
    45 CWSOviDeviceHandler::CWSOviDeviceHandler(MSenHandlerContext& aCtx):CSenMessageHandler(aCtx)
       
    46     {
       
    47     }
       
    48 
       
    49 // Destructor
       
    50 CWSOviDeviceHandler::~CWSOviDeviceHandler()
       
    51     {
       
    52     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviDeviceHandler::~CWSOviDeviceHandler()")));
       
    53     delete iNAuthVersion;
       
    54     }
       
    55 
       
    56 // Second phase construction.
       
    57 void CWSOviDeviceHandler::ConstructL()
       
    58     {
       
    59     }
       
    60     
       
    61 TInt CWSOviDeviceHandler::InvokeL(MSenMessageContext& aCtx)
       
    62     {
       
    63         TInt error(KErrNone);
       
    64         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviDeviceHandler::InvokeL(MSenMessageContext& aCtx)")));
       
    65         CSenTransportProperties* tp = ((CWSOviMessageContext&)aCtx).TP();
       
    66         if (!tp) return KErrNotFound;
       
    67         TPtrC8 consumerKey;
       
    68         error = tp->PropertyL(KNCIMConsumerKeyId, consumerKey);		
       
    69         
       
    70         const TDesC8* nAuthVersion = iHandlerContext.GetDesC8L(HandlerContextKey::KVersion);
       
    71         
       
    72         if (!iNAuthVersion)
       
    73             {
       
    74             if ( !nAuthVersion || *nAuthVersion == KNullDesC8() )
       
    75                 {
       
    76                 iNAuthVersion = KParValVersion().AllocL();
       
    77                 }
       
    78             else
       
    79                 {
       
    80                 iNAuthVersion = nAuthVersion->AllocL();
       
    81                 }
       
    82             }
       
    83         
       
    84         HBufC8* value = HBufC8::NewLC(KParNokiaAuth().Length() +
       
    85         							  KSpace().Length() +
       
    86         							  
       
    87         							  KParRealm().Length() +
       
    88  				                      KEqual().Length() + KQtMark().Length() +
       
    89  				                      KParValRealm().Length() +
       
    90 				                      KQtMark().Length() + KComma().Length() +
       
    91                                       
       
    92                                       KParVersion().Length() + 
       
    93                                       KEqual().Length() + 2*KQtMark().Length() + 
       
    94                                       iNAuthVersion->Length() + KComma().Length() +
       
    95                                         
       
    96                                       KParConsumerKey().Length() + 
       
    97                                       KEqual().Length() + 2*KQtMark().Length() + 
       
    98                                       consumerKey.Length()
       
    99                                         
       
   100                                         
       
   101                                       );
       
   102         
       
   103         
       
   104         //Authorization: OAuth,oauth_version="1.0"
       
   105         value->Des().Append(KParNokiaAuth());
       
   106         value->Des().Append(KSpace());
       
   107        
       
   108         value->Des().Append(KParRealm());
       
   109         value->Des().Append(KEqual());
       
   110         value->Des().Append(KQtMark());
       
   111         value->Des().Append(KParValRealm);
       
   112         value->Des().Append(KQtMark());
       
   113         value->Des().Append(KComma());
       
   114 
       
   115         value->Des().Append(KParConsumerKey());
       
   116         value->Des().Append(KEqual());
       
   117         value->Des().Append(KQtMark());
       
   118         value->Des().Append(consumerKey);
       
   119         value->Des().Append(KQtMark());
       
   120         value->Des().Append(KComma());
       
   121         
       
   122         
       
   123         value->Des().Append(KParVersion());
       
   124         value->Des().Append(KEqual());
       
   125         value->Des().Append(KQtMark());
       
   126         value->Des().Append(*iNAuthVersion);
       
   127         value->Des().Append(KQtMark());
       
   128      
       
   129         tp->SetPropertyL(KAuthHttpHeader, *value, KHttpHeaderType);
       
   130         CleanupStack::PopAndDestroy(value);
       
   131 
       
   132         RMapDescriptors& headerProperties = ((CWSOviMessageContext&)aCtx).OAuthProperies();
       
   133         HBufC8* newValue = NULL;
       
   134 		newValue = iNAuthVersion->AllocL();
       
   135         headerProperties.Insert(&KParVersion, newValue);
       
   136 
       
   137         //msg context keeps same tp, so we dont have to update msg context
       
   138         return KErrNone;
       
   139     }
       
   140     
       
   141 SenHandler::THandlerDirection CWSOviDeviceHandler::Direction() const
       
   142     {
       
   143     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviDeviceHandler::Direction()")));
       
   144     return SenHandler::EOutgoing;
       
   145     };
       
   146 SenHandler::THandlerPhase CWSOviDeviceHandler::Phase()
       
   147     {
       
   148     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviDeviceHandler::Phase()")));
       
   149     return SenHandler::EMessage;
       
   150     };    
       
   151     
       
   152 TInt CWSOviDeviceHandler::InitL(MSenHandlerContext& aCtx)
       
   153     {
       
   154     iHandlerContext = aCtx;
       
   155     return KErrNone;
       
   156     }
       
   157 // END OF FILE
       
   158