upnp/upnpstack/controlpointbase/src/upnpfilesender.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     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:  CUpnpFileSender implementation
       
    15  *
       
    16  */
       
    17 
       
    18 #include "upnpfilesender.h"
       
    19 #include "httpuploader.h"
       
    20 #include "upnphttpmessage.h"
       
    21 #include "upnpstring.h"
       
    22 #include "upnpcons.h"
       
    23 #include "upnphttpmessagefactory.h"
       
    24 #include "upnpcontrolpoint.h"
       
    25 
       
    26 // --------------------------------------------------------------------------
       
    27 // CUpnpFileSender::CUpnpFileSender
       
    28 // --------------------------------------------------------------------------
       
    29 //
       
    30 CUpnpFileSender::CUpnpFileSender( CUpnpControlPoint& aCPToNotifyOfSendingResult )
       
    31     : iControlPoint( aCPToNotifyOfSendingResult )
       
    32     {
       
    33     // No implementation required
       
    34     }
       
    35 
       
    36 // --------------------------------------------------------------------------
       
    37 // CUpnpFileSender::~CUpnpFileSender
       
    38 // --------------------------------------------------------------------------
       
    39 //
       
    40 CUpnpFileSender::~CUpnpFileSender()
       
    41     {
       
    42     delete iUploader;
       
    43     }
       
    44 
       
    45 // --------------------------------------------------------------------------
       
    46 // CUpnpFileSender::NewLC
       
    47 // --------------------------------------------------------------------------
       
    48 //
       
    49 CUpnpFileSender* CUpnpFileSender::NewLC( CUpnpControlPoint& aCPToNotifyOfSendingResult )
       
    50     {
       
    51     CUpnpFileSender* self = new (ELeave) CUpnpFileSender( aCPToNotifyOfSendingResult );
       
    52     CleanupStack::PushL( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // --------------------------------------------------------------------------
       
    57 // CUpnpFileSender::NewL
       
    58 // --------------------------------------------------------------------------
       
    59 //
       
    60 CUpnpFileSender* CUpnpFileSender::NewL( CUpnpControlPoint& aCPToNotifyOfSendingResult )
       
    61     {
       
    62     CUpnpFileSender* self = CUpnpFileSender::NewLC( aCPToNotifyOfSendingResult );
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // DestinationUriL
       
    69 // Allocate destination uri from message
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 static HBufC8* DestinationUriL( CUpnpHttpMessage& aMessage )
       
    73     {
       
    74     TInetAddr add( aMessage.Receiver() );
       
    75     HBufC8* address = UpnpString::InetToStringL( add );
       
    76     CleanupStack::PushL( address );
       
    77     TPtrC8 path( aMessage.SenderPathFromHeader() ) ;
       
    78     HBufC8* uriBuf = HBufC8::NewL(
       
    79         UpnpHTTP::KHTTPUrl().Length() + address->Length() + path.Length() );
       
    80     TPtr8 uri( uriBuf->Des() );
       
    81     uri.Append( UpnpHTTP::KHTTPUrl );
       
    82     uri.Append( *address );
       
    83     uri.Append( path );
       
    84     CleanupStack::PopAndDestroy( address );
       
    85     return uriBuf;
       
    86     }
       
    87 
       
    88 // --------------------------------------------------------------------------
       
    89 // CUpnpFileSender::SendL
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 void CUpnpFileSender::SendL( CUpnpHttpMessage& aMessageToSend )
       
    93     {
       
    94     ASSERT( aMessageToSend.Method() == KHttpPost && aMessageToSend.OutFilename().Length() > 0 );
       
    95     if ( !iUploader )   //late initialisation
       
    96         {
       
    97         const TInt KUnused(0);
       
    98         const TUint KBufferSize( 10 * 1024 );
       
    99         const TUint KParallelTransfersNumber( 1 );
       
   100         iUploader = CHttpUploader::NewL(*this,KUnused,KBufferSize,KParallelTransfersNumber);
       
   101         }
       
   102 
       
   103     RBuf fileName;
       
   104     User::LeaveIfError( fileName.Create( aMessageToSend.OutFilename().Length() ) );
       
   105     CleanupClosePushL( fileName );
       
   106     fileName.Copy( aMessageToSend.OutFilename() );
       
   107     HBufC8* destUri = DestinationUriL( aMessageToSend );
       
   108     CleanupStack::PushL( destUri );
       
   109 
       
   110     iUploader->UploadFileL( *destUri, fileName, (TAny*)aMessageToSend.SessionId() );
       
   111 
       
   112     CleanupStack::PopAndDestroy( destUri );
       
   113     CleanupStack::PopAndDestroy( &fileName );
       
   114     }
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // CUpnpFileSender::TransferProgress
       
   118 // --------------------------------------------------------------------------
       
   119 //
       
   120 void CUpnpFileSender::TransferProgress( TAny* /*aKey*/,
       
   121                                TInt /*aBytes*/,
       
   122                                TInt /*aTotalBytes*/ )
       
   123      {
       
   124      // no implementation needed
       
   125      }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CUpnpFileSender::ReadyForTransferL
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 void CUpnpFileSender::ReadyForTransferL( TAny* aKey )
       
   132     {
       
   133     _LIT8( KTextHtmlMimeType, "text/html" );
       
   134     iUploader->SetHeaderL( aKey, UpnpHTTP::KHdrContentType, KTextHtmlMimeType );
       
   135     iUploader->SetHeaderL( aKey, UpnpHTTP::KConnection, UpnpHTTP::KClose );
       
   136     iUploader->StartTransferL( aKey );
       
   137     }
       
   138 
       
   139 // --------------------------------------------------------------------------
       
   140 // CUpnpFileSender::TransferCompleted
       
   141 // --------------------------------------------------------------------------
       
   142 //
       
   143 void CUpnpFileSender::TransferCompleted( TAny* /*aKey*/, TInt aStatus )
       
   144     {
       
   145     CUpnpHttpMessage* rsp = NULL;
       
   146     TRAP_IGNORE(
       
   147         rsp = RUpnpHttpMessageFactory::HttpResponseErrorL( TInetAddr(), aStatus ) );
       
   148     iControlPoint.HttpResponseReceived( rsp );
       
   149     delete rsp;
       
   150     }