upnpsharing/upnpsecurity/src/upnpsecuritymanagerplugin.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     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 : Implementation for UpnpSecurityManager ECom plugin.
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDES
       
    19 #include <e32base.h>
       
    20 #include <upnpaction.h>
       
    21 #include <upnphttpmessage.h>
       
    22 #include "upnpsecaccesscontroller.h"
       
    23 #include "upnpsecuritymanagerplugin.h"
       
    24 
       
    25 _LIT( KComponentLogfile, "upnpsecurity.txt");
       
    26 #include "upnplog.h"
       
    27 
       
    28 // ============================= MEMBER FUNCTIONS ==============================
       
    29 
       
    30 CUpnpSecurityManagerPlugin* CUpnpSecurityManagerPlugin::NewL()
       
    31     {
       
    32     __LOG( "[UpnpSecurity]\t CUpnpSecurityManagerPlugin::NewL" );
       
    33 
       
    34     CUpnpSecurityManagerPlugin* self= NULL;
       
    35     self = new( ELeave ) CUpnpSecurityManagerPlugin;
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL( );
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CUpnpSecurityManagerPlugin::CUpnpSecurityManagerPlugin
       
    44 // Constructor.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CUpnpSecurityManagerPlugin::CUpnpSecurityManagerPlugin()
       
    48     {
       
    49     __LOG( "[UpnpSecurity]\t CUpnpSecurityManagerPlugin::\
       
    50 CUpnpSecurityManagerPlugin" );
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CUpnpSecurityManagerPlugin::~CUpnpSecurityManagerPlugin
       
    55 // Destructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CUpnpSecurityManagerPlugin::~CUpnpSecurityManagerPlugin()
       
    59     {
       
    60     __LOG( "[UpnpSecurity]\t CUpnpSecurityManagerPlugin::\
       
    61 ~CUpnpSecurityManagerPlugin" );
       
    62 
       
    63     delete iAccessController;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CUpnpSecurityManagerPlugin::ConstructL
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CUpnpSecurityManagerPlugin::ConstructL()
       
    71     {
       
    72     __LOG( "[UpnpSecurity]\t CUpnpSecurityManagerPlugin::ConstructL" );
       
    73 
       
    74     iAccessController = CUpnpSecAccessController::NewL( );
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CUpnpSecurityManagerPlugin::AuthorizeMessage
       
    79 // Authorize HTTP message.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TInt CUpnpSecurityManagerPlugin::AuthorizeMessage(
       
    83     CUpnpHttpMessage* aMessage, TFileName& aRequestedFile )
       
    84     {
       
    85     __LOG( "[UpnpSecurity]\t CUpnpSecurityManagerPlugin::AuthorizeMessage" );
       
    86 
       
    87     TInt returnValue = KErrAccessDenied;
       
    88     if ( aMessage )
       
    89         {
       
    90         // Check if the access to the given file is granted already
       
    91         TRAP( returnValue,
       
    92                 iAccessController->CheckAuthorizationL( aMessage->Sender(),
       
    93                         aRequestedFile,
       
    94                         KNullDesC8 ) );
       
    95 
       
    96         // If the access was not authorized, query authorization from user
       
    97         if ( returnValue != KErrNone )
       
    98             {
       
    99             TRAP( returnValue,
       
   100                     iAccessController->QueryAuthorizationL(
       
   101                             aMessage->Sender() ) );
       
   102             }
       
   103         }
       
   104 
       
   105     // Convert the returnvalue to either "KErrNone" or "KErrAccessDenied"
       
   106     if ( returnValue != KErrNone )
       
   107         {
       
   108         returnValue = KErrAccessDenied;
       
   109         }
       
   110     return returnValue;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CUpnpSecurityManagerPlugin::AuthorizeAction
       
   115 // Authorize SOAP action.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TInt CUpnpSecurityManagerPlugin::AuthorizeAction( CUpnpAction* aAction )
       
   119     {
       
   120     __LOG( "[UpnpSecurity]\t CUpnpSecurityManagerPlugin::AuthorizeAction" );
       
   121 
       
   122     TInt returnValue = KErrAccessDenied;
       
   123     if ( aAction )
       
   124         {
       
   125         // Check if the access to the given file is granted already
       
   126         TRAP( returnValue,
       
   127                 iAccessController->CheckAuthorizationL( aAction->Sender(),
       
   128                         KNullDesC,
       
   129                         aAction->Name() ) );
       
   130 
       
   131         // If the access was not authorized, query authorization from user
       
   132         if ( returnValue != KErrNone )
       
   133             {
       
   134             TRAP( returnValue,
       
   135                     iAccessController->QueryAuthorizationL(
       
   136                             aAction->Sender() ) );
       
   137             }
       
   138         }
       
   139 
       
   140     // Convert the returnvalue to either "KErrNone" or "KErrAccessDenied"
       
   141     if ( returnValue != KErrNone )
       
   142         {
       
   143         returnValue = KErrAccessDenied;
       
   144         }
       
   145     return returnValue;
       
   146     }
       
   147 
       
   148 //  End of File