webservices/wshttpchanneltransportplugin/src/senatomtxnstate.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2007-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 // INCLUDE FILES
       
    26 #include <http.h>
       
    27 
       
    28 #include "senatomtxnstate.h"
       
    29 #include "senhttpchannel.h"
       
    30 #include "sendebug.h"
       
    31 #include "senlogger.h"
       
    32 
       
    33 
       
    34 
       
    35 // =========================== MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CSenAtomTxnState::CSenAtomTxnState
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CSenAtomTxnState::CSenAtomTxnState(MSenResponseObserver& aObserver)
       
    44     : CSenMultiPartTxnState(aObserver)
       
    45     {
       
    46     }
       
    47     
       
    48 CSenAtomTxnState* CSenAtomTxnState::NewL(MSenResponseObserver& aObserver,
       
    49                           		         const TDesC8* aUri,
       
    50                                    		 CSenAtomEntry& aAtomEntry)
       
    51                                    		 
       
    52     {
       
    53     CSenAtomTxnState* pNew = NewLC( aObserver, aUri, 
       
    54                                 	aAtomEntry);
       
    55     CleanupStack::Pop(pNew);
       
    56     return pNew;
       
    57     }
       
    58 
       
    59 CSenAtomTxnState* CSenAtomTxnState::NewLC(MSenResponseObserver& aObserver,
       
    60                                   		  const TDesC8* aUri,
       
    61                                   		  CSenAtomEntry& aAtomEntry)
       
    62    
       
    63     {
       
    64     CSenAtomTxnState* pNew = new (ELeave) CSenAtomTxnState(aObserver);
       
    65     CleanupStack::PushL(pNew);
       
    66     pNew->ConstructL(aUri, aAtomEntry);
       
    67     return pNew;
       
    68     }
       
    69 
       
    70 
       
    71 void CSenAtomTxnState::ConstructL(const TDesC8* aUri,
       
    72                          	      CSenAtomEntry& aAtomEntry)
       
    73     {
       
    74     
       
    75     __ASSERT_ALWAYS(aUri != NULL,
       
    76                     User::Panic(KRequestUriNullPanicText,
       
    77                                 CSenHttpChannel::ERequestUriNull));
       
    78     iRequestUri = aUri->AllocL();
       
    79     
       
    80     if(!&aAtomEntry)
       
    81 		{
       
    82 		iHasRequestBody = EFalse;
       
    83 		User::Panic(KMultiPartNoRequestMessagePanicText, SenMultiPartUtils::EMultiPartNoRequestMessage);
       
    84 		}
       
    85    	TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenAtomTxnState::ConstructL")));  	
       
    86    	iMessage = &(MSenMessage&)aAtomEntry; // not owned
       
    87    	RSenDocument doc = aAtomEntry.AsDocumentL();
       
    88  	doc.GetDataContainerList(iBinaryDataList);
       
    89 
       
    90  	iCountDataParts = 3 + iBinaryDataList.Count()*2; //how many parts there are in MultiPart message 
       
    91 	iHasRequestBody = ETrue;
       
    92     }
       
    93     
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // creates HTTP content type header for Atom multipart message
       
    97 //
       
    98 // HTTP content type header should be the next:
       
    99 // Content-Type: Multipart/Related;boundary=MIME_boundary;type="application/atom+xml";
       
   100 // start="<>"; start-info="text/xml"
       
   101 //
       
   102 //
       
   103 // Note: 1.it's one line without return carrige
       
   104 //       2."boundary" is generated as <rundomNumber>
       
   105 //       3."start" is generated as <randomNumber>@<homeTime>
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CSenAtomTxnState::SetContentTypeHeaderL(const RHTTPSession aSession, RHTTPHeaders aHeaders)
       
   109 	{
       
   110 	_LIT8(KMultipartRelated,"Multipart/Related");
       
   111 	_LIT8(KBoundry,"boundary");
       
   112 	_LIT8(KType,"type");
       
   113 	_LIT8(KStart,"start");
       
   114 	_LIT8(KStartInfo,"start-info");
       
   115     _LIT8(KApplicationAtom,"\"application/atom+xml\"");
       
   116     _LIT8(KTextXml,"\"text/xml\"");
       
   117     _LIT8(KSlashLessthan,"\"<");
       
   118 	_LIT8(KSlashGreaterthan,">\"");
       
   119 	SenMultiPartUtils::GenerateRandomRootCidL(iRootCid);
       
   120 	RBuf8 rootCid(NULL);
       
   121 	rootCid.ReAllocL(4+iRootCid.Length());
       
   122 	CleanupClosePushL(rootCid);
       
   123     rootCid.Append(KSlashLessthan);
       
   124 	rootCid.Append(iRootCid);
       
   125 	rootCid.Append(KSlashGreaterthan);
       
   126 	 
       
   127 	SenMultiPartUtils::GenerateRandomBoundaryL(iMimeBoundaryOut);
       
   128 
       
   129 	RStringF multipartRelated = aSession.StringPool().OpenFStringL(KMultipartRelated);
       
   130 	RStringF boundary         = aSession.StringPool().OpenFStringL(KBoundry);
       
   131 	RStringF boundaryVal      = aSession.StringPool().OpenFStringL(iMimeBoundaryOut);
       
   132 	RStringF type             = aSession.StringPool().OpenFStringL(KType);
       
   133 	RStringF typeVal          = aSession.StringPool().OpenFStringL(KApplicationAtom);
       
   134 	RStringF start            = aSession.StringPool().OpenFStringL(KStart);
       
   135 	RStringF startVal         = aSession.StringPool().OpenFStringL(rootCid);
       
   136 	RStringF startInfo        = aSession.StringPool().OpenFStringL(KStartInfo);
       
   137 	RStringF startInfoVal   = aSession.StringPool().OpenFStringL(KTextXml);
       
   138 	
       
   139 	CleanupStack::PopAndDestroy(&rootCid);
       
   140 	
       
   141 	THTTPHdrVal contentTypeVal(multipartRelated);
       
   142 	THTTPHdrVal boundVal(boundaryVal);
       
   143 	THTTPHdrVal tVal(typeVal);
       
   144 	THTTPHdrVal stVal(startVal);
       
   145 	
       
   146 	THTTPHdrVal stInfoVal;
       
   147 
       
   148 	stInfoVal = startInfoVal;
       
   149 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   150 					   contentTypeVal, boundary, boundVal);
       
   151 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   152 				       contentTypeVal, type, tVal);
       
   153 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   154 					   contentTypeVal, start, stVal);
       
   155 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   156 					   contentTypeVal, startInfo, stInfoVal);
       
   157 
       
   158 					   
       
   159     multipartRelated.Close();
       
   160 	boundary.Close();         
       
   161 	boundaryVal.Close();      
       
   162 	type.Close();             
       
   163 	typeVal.Close();          
       
   164 	start.Close();            
       
   165 	startVal.Close();         
       
   166 	startInfo.Close();        
       
   167 	startInfoVal.Close();   
       
   168 	}
       
   169 
       
   170 // ---------------------------------------------------------------------
       
   171 // creates AtomEntry in Request
       
   172 // ---------------------------------------------------------------------
       
   173 //    
       
   174 void CSenAtomTxnState::MessageL()
       
   175     {
       
   176     SenMultiPartUtils::SerializeMessageL(*(CSenAtomEntry*)iMessage, iCurrentPart, ESerializerDefault);
       
   177     TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenAtomTxnState::GetNextDataPart - aDataPart (Atom Message):")));
       
   178     iCurPart = ETrue; 
       
   179     }
       
   180 
       
   181 
       
   182 //  End of File