servicediscoveryandcontrol/pnp/test/upnp/upnpmessage/src/cupnpresponsecomposer.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <http/framework/cheadercodecplugin.h>
       
    17 #include <httpstringconstants.h>
       
    18 #include <inetprottextutils.h>
       
    19 
       
    20 #include "cupnpresponsecomposer.h"
       
    21 #include "tupnpmessagepanic.h"
       
    22 
       
    23 __FLOG_STMT(_LIT8(KSubsys,"UPnPResComposer");)
       
    24 __FLOG_STMT(_LIT8(KComponent,"UPnPMessage");)
       
    25 
       
    26 
       
    27 EXPORT_C CUpnpResponseComposer* CUpnpResponseComposer::NewL(MComposerObserver& aObserver)
       
    28 	{
       
    29 	CUpnpResponseComposer* self = new (ELeave) CUpnpResponseComposer(aObserver);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 EXPORT_C CUpnpResponseComposer::~CUpnpResponseComposer()
       
    37 	{
       
    38 	iMessageComposer.Close();
       
    39 	delete iStatusCodeBuf;
       
    40 	__FLOG(_L8("-> Response composer destroyed"));
       
    41 	__FLOG_CLOSE;
       
    42 	}
       
    43 
       
    44 CUpnpResponseComposer::CUpnpResponseComposer(MComposerObserver& aObserver)
       
    45 	:CUPnPMessageComposer(aObserver)
       
    46 	{
       
    47 	}
       
    48 
       
    49 void CUpnpResponseComposer::ConstructL()
       
    50 	{
       
    51 	CUPnPMessageComposer::ConstructL();
       
    52 	__FLOG_OPEN(KSubsys, KComponent);
       
    53 	__FLOG(_L8("-> Response Composer created"));
       
    54 	}
       
    55 
       
    56 void CUpnpResponseComposer::StartLineL(TPtrC8& aVersion, TPtrC8& aStatusCode, TPtrC8& aStatusText)
       
    57 	{
       
    58 	__FLOG(_L8("-> Composing response"));
       
    59 	__FLOG(_L8("-> Supplying start line"));
       
    60 
       
    61 	TInt statusCode = iResponse->Status();
       
    62 	InetProtTextUtils::ConvertIntToDescriptorL(statusCode, iStatusCodeBuf);
       
    63 	
       
    64 	aStatusCode.Set(iStatusCodeBuf->Des());
       
    65 	aStatusText.Set(iResponse->StatusString().DesC());
       
    66 	aVersion.Set(iResponse->StringPool().StringF(HTTP::EHttp11, THTTPTable::Table()).DesC());
       
    67 	__FLOG_3(_L8("%S %S %S"), &aVersion, &aStatusCode, &aStatusText);
       
    68 	}
       
    69 	
       
    70 // This function should be moved to CUPnPMessageComposer once the CRequest, CResponse & CMessage
       
    71 // split happens.
       
    72 TInt CUpnpResponseComposer::NextHeaderL(TPtrC8& aHeaderName, TPtrC8& aHeaderValue)
       
    73 	{
       
    74 	// Are there any more headers?
       
    75 	TInt err = KErrNotFound;
       
    76 
       
    77 	THTTPHdrFieldIter fields = iResponse->Handle().GetHeaderCollection().Fields();
       
    78 	TInt fieldPos = 0;
       
    79 	
       
    80 	while(fieldPos != iFieldIterPos)
       
    81 		{
       
    82 		++fields;
       
    83 		fieldPos++;
       
    84 		}
       
    85 	
       
    86 	if( !fields.AtEnd() )
       
    87 		{
       
    88 		// Get field current field.
       
    89 		RStringF name = iResponse->StringPool().StringF(fields());
       
    90 
       
    91 		err = KErrNone;
       
    92 			
       
    93 		// Get the OTA version of the field value
       
    94 		TPtrC8 value;
       
    95 		iResponse->Handle().GetHeaderCollection().GetRawField(name, value);
       
    96 		
       
    97 		// Pass back these values
       
    98 		aHeaderName.Set(name.DesC());
       
    99 		aHeaderValue.Set(value);
       
   100 		__FLOG(_L8("-> Supplying header value pair"));
       
   101 		__FLOG_2(_L8("%S: %S"), &aHeaderName, &aHeaderValue);		
       
   102 		
       
   103 		// Move onto next header field...
       
   104 		++fields;
       
   105 		++iFieldIterPos;
       
   106 		}
       
   107 	return err;
       
   108 	}
       
   109 
       
   110 MHTTPDataSupplier* CUpnpResponseComposer::HasBodyL()
       
   111 	{
       
   112 	return iResponse->Handle().Body();
       
   113 	}
       
   114 
       
   115 void CUpnpResponseComposer::MessageComplete()
       
   116 	{
       
   117 	CUPnPMessageComposer::MessageComplete();
       
   118 	}
       
   119 
       
   120 void CUpnpResponseComposer::MessageDataReadyL()
       
   121 	{
       
   122 	CUPnPMessageComposer::MessageDataReadyL();	
       
   123 	}
       
   124 
       
   125 TInt CUpnpResponseComposer::HandleComposeError(TInt aError)
       
   126 	{
       
   127 	return CUPnPMessageComposer::HandleComposeError(aError);
       
   128 	}
       
   129 
       
   130 EXPORT_C void CUpnpResponseComposer::ComposeResponse(CResponse* aResponse)
       
   131 	{
       
   132 	__ASSERT_DEBUG(aResponse, TUPnPMessagePanic::Panic(TUPnPMessagePanic::EMissingResponse));
       
   133 	iResponse = aResponse;
       
   134 
       
   135 	// Notify the Message Composer that the response composing can start.
       
   136 	NotifyNewBodyData ( );
       
   137 	//iMessageComposer.MessageInfoAvailable();
       
   138 	}
       
   139 
       
   140 EXPORT_C void CUpnpResponseComposer::ResponseDataSent()
       
   141 	{
       
   142 	// Notify the Message Composed that the current data has been read and it can
       
   143 	// release it.
       
   144 	__FLOG(_L8("-> Releasing message data"));
       
   145 	iDataChain.Close();	//Need to check
       
   146 	iMessageComposer.ReleaseMessageData();	
       
   147 	}
       
   148 
       
   149 EXPORT_C void CUpnpResponseComposer::ResetComposer()
       
   150 	{
       
   151 	__FLOG(_L8("-> Response composer reset"));
       
   152 	iMessageComposer.Reset();
       
   153 	iFieldIterPos = 0;
       
   154 	iDataChain.Close();	
       
   155 	}