webservices/wsframework/inc/senmtomutils.h
changeset 0 62f9d29f7211
child 14 ab1e518f96da
child 23 a1df79fa35b4
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2008-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:    Header declaration
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef SEN_MTOM_UTILS_H
       
    22 #define SEN_MTOM_UTILS_H
       
    23 
       
    24 #include <e32math.h>
       
    25 #include <imcvcodc.h>
       
    26 
       
    27 #include <SenSoapEnvelope2.h>
       
    28 #include <RSenDocument.h>
       
    29 
       
    30 #include <xmlengserializer.h>
       
    31 #include <xmlengchunkcontainer.h>
       
    32 #include <xmlengfilecontainer.h>
       
    33 #include <xmlengbinarycontainer.h>
       
    34 #include <xmlengnodelist.h>
       
    35 
       
    36 // CONSTANTS
       
    37 _LIT(KMtomNoRequestSoapEnvelopePanicText, "NULL MTOM request soap envelope");
       
    38 _LIT(KMtomNoBlobsPanicText, "NULL MTOM BLOB part");
       
    39 _LIT(KMtomNoContentTypeInBlobHeaderPanicText, "NULL MTOM ContentType in BLOB header");
       
    40 _LIT(KMtomNoCidPanicText, "NULL MTOM Cid");
       
    41 _LIT(KMtomSoapVersionInvalidPanicText, "MTOM SOAP version unknown");
       
    42 _LIT(KMtomBlobContainerTypeInvalidPanicText, "MTOM BLOB container type unknown");
       
    43 _LIT(KMtomResponseBodyInvalidPanicText, "MTOM response body doesn't conform XOP rules");
       
    44 _LIT(KMtomCidInvalidPanicText, "MTOM Cid doesn't conform XOP rules");
       
    45 
       
    46 _LIT(KMtomPanicText, "MTOM panic");
       
    47 
       
    48 const TUint KTenKBytes = 10240;
       
    49 
       
    50 /** numbers 11 or 12 at the end of constant names mean SOAP versions (1.1 or 1.2) */
       
    51 _LIT8(KHeaderRootStart11, "Content-Type: application/xop+xml;charset=UTF-8;type=\"text/xml\"\r\nContent-Transfer-Encoding: 8bit\r\nContent-ID: <");
       
    52 _LIT8(KHeaderRootStart12, "Content-Type: application/xop+xml;charset=UTF-8;type=\"application/soap+xml\"\r\nContent-Transfer-Encoding: binary\r\nContent-ID: <");
       
    53 _LIT8(KHeaderRootEnd, ">\r\n\r\n");    
       
    54 
       
    55 _LIT8(KContentTypeName, "contentType");
       
    56 _LIT8(KHeaderBinaryDataContentType, "Content-Type: ");
       
    57 _LIT8(KHeaderBinaryDataContentID, "\r\nContent-Transfer-Encoding: binary\r\nContent-ID: <");
       
    58 _LIT8(KHeaderBinaryDataEnd, ">\r\n\r\n"); 
       
    59 
       
    60 _LIT8(KNewLine, "\r\n");
       
    61 _LIT8(KDush, "--");
       
    62 
       
    63 /** the common part of file name where will be stored Blobs from Response */
       
    64 _LIT(KFileName, "c:\\SenBlobResponses\\SenBlobResponse");
       
    65 
       
    66 /**
       
    67  * Prepares XOP message with binary data to transmit it through HTTP Channel
       
    68  * and extracts BLOBs from XOP message responsed through HTTP channel 
       
    69  *
       
    70  * @lib
       
    71  * @since S60 v3.2
       
    72  */
       
    73 class SenMtomUtils
       
    74 	{
       
    75 public:
       
    76 
       
    77     /**
       
    78      * different cases of panics
       
    79      */
       
    80      enum TMtomPanics
       
    81 	    {
       
    82 	    EMtomNoRequestSoapEnvelope,
       
    83 	    EMtomNoBlobs,
       
    84 	    EMtomNoContentTypeInBlobHeader,
       
    85 	    EMtomNoCid,
       
    86 	    EMtomSoapVersionInvalid,
       
    87 	    EMtomBlobContainerTypeInvalid,
       
    88 	    EMtomResponseBodyInvalid,
       
    89 	    EMtomCidInvalid
       
    90 	    };
       
    91 
       
    92     /**
       
    93      * ContentType for MTOM consists of 
       
    94      * FiledName = "Content-Type" FiledValue = "Multipart/Related"
       
    95      * ParamName1 = "boundary" 	  ParamValue1 = BoundaryValue
       
    96      * ParamName2 = "type"  	  ParamValue1 = TypeValue
       
    97      * ParamName1 = "start" 	  ParamValue1 = StartValue
       
    98      * ParamName1 = "start-info"  ParamValue1 = StartInfoValue
       
    99      * ParamName1 = "action" 	  ParamValue1 = ActionValue
       
   100      * This structure describes ParamName & ParamValue of ConetentType
       
   101      */ 
       
   102     struct TMtomContentTypeParam
       
   103         {
       
   104         TPtrC8 paramName;
       
   105         TPtrC8 paramValue;
       
   106         };	    
       
   107     
       
   108     /**
       
   109      * This structure describes FieldValue & Params of ContentType
       
   110      */
       
   111     struct TMtomContentType
       
   112         {
       
   113         TPtrC8 fieldValue;
       
   114         RArray<TMtomContentTypeParam> params;
       
   115         };
       
   116 
       
   117 public:
       
   118 
       
   119     /**
       
   120      * Serializes SoapEnvelope message in XOP message
       
   121      * @since S60 v3.2
       
   122      * @param aSoapEnvelope2 The message with multiparts (usual view of Soap message)
       
   123      * @param aXopEnvelope The message serialized from usual view to XOP message
       
   124      */	
       
   125 	IMPORT_C static void SerializeEnvelope2L(CSenSoapEnvelope2& aSoapEnvelope2, 
       
   126 	                                         RBuf8& aXopEnvelope);
       
   127 	
       
   128     /**
       
   129    	 * Generates random content-ID for header of XOP message and for headers of BLOBs 
       
   130      * as randomNumber@homeTime
       
   131    	 * @since S60 v3.2     
       
   132    	 * @param aRootCid Generated content-ID
       
   133    	 */
       
   134  	IMPORT_C static void GenerateRandomRootCidL(RBuf8& aRootCid);
       
   135  	
       
   136  	/**
       
   137 	* Generates random boundary for mime header as randomNumber
       
   138 	* @since S60 v3.2
       
   139 	* @param aBoundary Generated random boundary
       
   140 	*/
       
   141  	IMPORT_C static void GenerateRandomBoundaryL(RBuf8& aBoundary);
       
   142  	
       
   143  	/**
       
   144  	* Generates MimeBoundary to separate mime parts of the message as --randomNumber
       
   145  	* @since S60 v3.2
       
   146  	* @param aBoundary random boundary
       
   147  	* @param aBoundaryStart Generated MIME boundary
       
   148  	*/
       
   149  	IMPORT_C static void BoundaryLineStartL(const RBuf8& aBoundary, RBuf8& aBoundaryStart);
       
   150  	
       
   151  	/**
       
   152  	* Generates MimeBoundaryEnd to end multipart message (MTOM) as --randomNumber--
       
   153  	* @since S60 v3.2
       
   154  	* @param aBoundary random boundary
       
   155  	* @param aBoundaryEnd Generated MIME boundary end
       
   156  	*/
       
   157   	IMPORT_C static void BoundaryLineEndL(const RBuf8& aBoundary, RBuf8& aBoundaryEnd);
       
   158 
       
   159     /**
       
   160      * Creates Header for Root of XOP message
       
   161      * The header sould be the next:
       
   162      *
       
   163      * --MIME_boundary
       
   164      * Content-Type: application/xop+xml; 
       
   165      * charset=UTF-8; 
       
   166      * type="text/xml" (for SOAP 1.1) or "application/soap+xml" (for SOAP 1.2)
       
   167      * Content-Transfer-Encoding: 8bit
       
   168      * Content-ID: <randomNumber@homeTime>
       
   169      *
       
   170      * where "Content-ID" is the same as "start" in Header of Outer Package
       
   171      *
       
   172      * @since S60 v3.2
       
   173      * @param aSoapEnvelope2 The message with multiparts (usual view of Soap message)
       
   174      * @param aRootCid The content ID for the header of XOP
       
   175      * @param aHeaderRoot11  Header of root of XOP message
       
   176      */
       
   177     IMPORT_C static void HeaderRootL(CSenSoapEnvelope2& aSoapEnvelope2,
       
   178     							     const RBuf8& aRootCid, RBuf8& aHeaderRoot);
       
   179 	
       
   180     /**
       
   181      * Creates Header for Binary Data[aIndex] of XOP message 
       
   182      * The header sould be the next:
       
   183 	 *
       
   184      * --MIME_boundary
       
   185 	 * Content-Type: image/png
       
   186 	 * Content-Transfer-Encoding: binary
       
   187 	 * Content-ID: <randomNumber@homeTime>
       
   188 	 *
       
   189 	 * @since S60 v3.2
       
   190      * @param aIndex Which BLOB from array of TXmlEngDataContainer is processed, starts from 0
       
   191      * @param aBinaryDataList The list of BLOBs
       
   192      * @param aHeaderBinaryData Header of binary data[aIndex]
       
   193      */
       
   194     IMPORT_C static void HeaderBinaryDataL(TUint aIndex, 
       
   195 									       RArray<TXmlEngDataContainer>& aBinaryDataList,
       
   196 			 						 	   RBuf8& aHeaderBinaryData);
       
   197 
       
   198     /**
       
   199      * Extracts a part of BLOB (10KB) from a file
       
   200      * @since S60 v3.2
       
   201      * @param aPart Which part of BLOB should be extracted
       
   202      * @param aIndex Which BLOB from array of TXmlEngDataContainer is processed, starts from 0
       
   203      * @param aBinaryDataList The list of BLOBs
       
   204      * @param aBinaryData Part of BLOB that was extracted from a file
       
   205      */
       
   206     IMPORT_C static void FileDataPartL(TUint aPart, TUint aIndex, 
       
   207 								       RArray<TXmlEngDataContainer>& aBinaryDataList,
       
   208 						       	       RBuf8& aBinaryData);									 
       
   209 
       
   210     /**
       
   211      * Extracts the rest of BLOB (less than 10KB) from a file
       
   212      * @since S60 v3.2
       
   213      * @param aParts How many parts of BLOB has already been extracted from a file
       
   214      * @param aRest How many bytes should be exracted from a file 
       
   215      * @param aIndex Which BLOB from array of TXmlEngDataContainer is processed, starts from 0
       
   216      * @param aBinaryDataList The list of BLOBs
       
   217      * @param aBinaryData The last part of BLOB that was extracted from a file
       
   218      */
       
   219     IMPORT_C static void FileDataRestL(TUint aParts, TUint aRest, TUint aIndex, 
       
   220 								       RArray<TXmlEngDataContainer>& aBinaryDataList,
       
   221 						       	       RBuf8& aBinaryData);									 
       
   222 
       
   223     /**
       
   224      * Extracts CIDs of BLOBs from response MTOM message
       
   225      * @since S60 v3.2
       
   226      * @param aBlobHeader Header of Blob from that should be extracted CID of BLOB
       
   227      * @param aCids Array of CIDs for all BLOBs    
       
   228      */
       
   229     IMPORT_C static void CidL(const RBuf8& aBlobHeader, RArray<RBuf8>& aCids);
       
   230 
       
   231     /**
       
   232      * Extracts BLOB from response MTOM message and writes it in a file
       
   233      * @since S60 v3.2
       
   234      * @param aIndex Which BLOB from response is processed, starts from 0
       
   235      * @param aFirst Shows is it First part of BLOB or not
       
   236      * @param aBlob The part of BLOB from response that should be written in fhe file
       
   237      * @param aFileNames Array of File names for the all responsed BLOBs
       
   238      * @return size of file in order to monitor progess
       
   239      */	
       
   240     IMPORT_C static TInt SetFileL(TUint aIndex, TBool aFirst, TDesC8& aBlob, 
       
   241                                   RArray<RBuf8>& aFileNames);
       
   242 
       
   243 private:													
       
   244 		
       
   245     /**
       
   246      * Generates the file name for BLOB of response MTOM message 
       
   247      * and collects it in array of file names for the all BLOBs
       
   248      * @since S60 v3.2
       
   249      * @param aIndex Which BLOB from response is processed, starts from 0
       
   250      * @param aFileNames Array of File names for the all responsed BLOBs
       
   251      */
       
   252      static void FileNameL(TUint aIndex, RArray<RBuf8>& aFileNames);
       
   253 	};
       
   254 									 
       
   255 #endif // SEN_MTOM_UTILS_H
       
   256 
       
   257 // End of file
       
   258 
       
   259