mmsengine/mmsmessage/inc/mmsserverentry.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2003 - 2007 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 *     Entry wrapper for server side components using CMmsEncode and CMmsDecode
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef MMSSERVERENTRY_H
       
    22 #define MMSSERVERENTRY_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <mmsvattachmentmanager.h>
       
    26 #include <s32file.h>
       
    27 #include "mmsentrywrapper.h"
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // DATA TYPES
       
    34 
       
    35 // FUNCTION PROTOTYPES
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class CDRMMessageParser;
       
    39 class CMsvStore;
       
    40 class CMmsDrmCaf;
       
    41 
       
    42 // CLASS DECLARATION
       
    43 
       
    44 /**
       
    45 * Entry wrapper implementing MMmsEntryWrapper for server side.
       
    46 *
       
    47 * @lib mmscodec.lib
       
    48 * @since 2.1
       
    49 */
       
    50 class CMmsServerEntry :public CBase, public MMmsEntryWrapper
       
    51     {
       
    52     public:  // Constructors and destructor
       
    53         
       
    54         /**
       
    55         * Two-phased constructor.
       
    56         * @param aFs opened file system handle.
       
    57         * @param aServerEntry reference to a server entry,
       
    58         *     originally refers to the entry to be handled.
       
    59         * @param aServiceId TMsvId of MMS service entry.
       
    60         */
       
    61         IMPORT_C static CMmsServerEntry* NewL( RFs& aFs,
       
    62             CMsvServerEntry& aServerEntry,
       
    63             TMsvId aServiceId );
       
    64         
       
    65         /**
       
    66         * Destructor.
       
    67         */
       
    68         virtual ~CMmsServerEntry();
       
    69 
       
    70     public: // Functions from base classes
       
    71     
       
    72         /**
       
    73         * From MMmsEntryWrapper: Provide an edit store for editing messages
       
    74         * Ownership of the store is transferred. Caller must delete the store
       
    75         * @return CMsvStore* if successful, leaves if unsuccessful
       
    76         */
       
    77         CMsvStore* EditStoreL();
       
    78 
       
    79         /**
       
    80         * From MMmsEntryWrapper: provide a read store for editing messages
       
    81         * Ownership of the store is transferred. Caller must delete the store
       
    82         * @return CMsvStore* if successful, leaves if unsuccessful
       
    83         */
       
    84         CMsvStore* ReadStoreL();
       
    85 
       
    86         /**
       
    87         * From MMmsEntryWrapper: reads index entry contents from current entry
       
    88         * @param TMsvEntry reference to entry to be filled with data
       
    89         * @return error code, KErrNone if successful
       
    90         */
       
    91         TInt GetIndexEntry( TMsvEntry& aTMsvEntry );
       
    92        
       
    93         /**
       
    94         * From MMmsEntryWrapper: stores index entry contents to current entry
       
    95         * @param TMsvEntry reference to entry to be written to disk
       
    96         * @return error code KErrNone, if successful
       
    97         */
       
    98         TInt ChangeIndexEntry( TMsvEntry& aTMsvEntry );
       
    99 
       
   100         /**
       
   101         * From MMmsEntryWrapper: Sets context to specified message entry
       
   102         * @param aId ID of the new message entry.
       
   103         * @return error code, KErrNone if successful
       
   104         *     if not successful, context is not changed
       
   105         */
       
   106         TInt SetCurrentEntry( TMsvId aId );
       
   107 
       
   108         /**
       
   109         * From MMmsEntryWrapper: Returns total size of all attachments including mime headers
       
   110         * and binary attachment data. Linked attachments are included
       
   111         * This function is needed to allocate the encoding buffer.
       
   112         * @param aStore Read store for the message entry
       
   113         * @return combined size of all attachments, including linked attachments
       
   114         */
       
   115         TInt AttachmentsSizeL( CMsvStore& aStore );
       
   116 
       
   117         /**
       
   118         * From MMmsEntryWrapper: Check if disk space is below critical level.
       
   119         * @param aDataSize amount of data to be added. If aDataSize == 0,
       
   120         *     returns info if disk space is already below critical level.
       
   121         * @return error code KErrDiskFull if data does not fit,
       
   122         *     KErrNone if data fits.
       
   123         *     May return some other error code if appropriate.
       
   124         *     KErrNone always means it is all right to save the data.
       
   125         */
       
   126         TInt DiskSpaceBelowCriticalLevelL( TInt aDataSize );
       
   127 
       
   128         /**
       
   129         * From MMmsEntryWrapper: Store CMmsHeaders to messaging store.
       
   130         *     ( main message entry )
       
   131         * @param aMmsHeaders headers to store.
       
   132         * @param aStore store to be used. If not given, function gets and commits store
       
   133         * @return error code if not successful, KErrNone if successful.
       
   134         */
       
   135         TInt StoreMmsHeadersL( CMmsHeaders& aMmsHeaders, CMsvStore* aStore );
       
   136 
       
   137         /**
       
   138         * From MMmsEntryWrapper: Restore CMmsHeaders from messaging store.
       
   139         *     ( main message entry )
       
   140         * @param aMmsHeaders headers to restore.
       
   141         * @param aStore store to be used. If not given, function gets and closes store
       
   142         * Leaves if cannot restore headers.
       
   143         */
       
   144         void RestoreMmsHeadersL( CMmsHeaders& aMmsHeaders, CMsvStore* aStore );
       
   145 
       
   146         /**
       
   147         * From MMmsEntryWrapper: Save attachment data and MIME headers.
       
   148         * Create attachment, save data to file and save MIME headers.
       
   149         *     Must check first if enough disk space.
       
   150         *     DRM handling is done here if needed.
       
   151         *     Return code tells if whole attachment was removed.
       
   152         *     This is the one-shot function that does everything:
       
   153         *     Creates attachent, opens file, writes data, flushes it,
       
   154         *     closes file, saves MIME headers.
       
   155         *     Caller must commit and close store
       
   156         * @param aStore edit store for current entry
       
   157         * @param aFileName Suggested filename.
       
   158         * @param aAttachmentData Pointer to the attachment binary data.
       
   159         * @param aMimeHeaders Mime header structure to be saved.
       
   160         * @param aAttachment id of the newly created attachment if successful
       
   161         * @param aAttachmentSize size of the attachment binary data + mime headers
       
   162         * @param aDRMFlags structure where DRM flags are collected.
       
   163         *     These flags will ultimately be collected together for all
       
   164         *     attachments and stored into iMtmData1 of the parent entry.
       
   165         *     Therefore the function must only OR new flags into the structure
       
   166         *     and must not change any other bits (the same value may be reused
       
   167         *     for all attachments collecting the flags together).
       
   168         * @return Error code must indicate if attachment was removed (DRM) so that
       
   169         *     the first attachment id may be adjusted. (Decode must keep track
       
   170         *     of the first attachment in case root is not specified for
       
   171         *     multipart/related structure.
       
   172         *     KErrNone = All well.
       
   173         *     KDRMRemoved = all well otherwise, but DRM attachment was removed,
       
   174         *         and first attachment id must be adjusted accordingly.
       
   175         *     Some other error code means a more serious error.
       
   176         */
       
   177         TInt CreateFileAttachmentL(
       
   178             CMsvStore& aStore,
       
   179             const TDesC& aFileName,
       
   180             const TPtrC8& aAttachmentData,
       
   181             CMsvMimeHeaders& aMimeHeaders,
       
   182             TMsvAttachmentId& aAttachment,
       
   183             TInt& aAttachmentSize,
       
   184             TInt32& aDRMFlags);
       
   185 
       
   186         /**
       
   187         * From MMmsEntryWrapper: Deletes a message store entry.
       
   188         * @param aEntryIndex is the index of the entry, which will be deleted. 
       
   189         * If the Entry has children, all children are destroyed too.
       
   190         * @return error code if not successful, KErrNone if successful.
       
   191         */
       
   192         TInt DeleteEntry( TMsvId aEntryIndex );
       
   193 
       
   194         /**
       
   195         * From MMmsEntryWrapper: Check if aFileName would be a valid filename.
       
   196         * Cannot use path because absolute path is not known. Only filename is checked
       
   197         * @param aFileName suggestion of a filename.
       
   198         * @return ETrue if filename is valid, EFalse if not.
       
   199         */
       
   200         TBool IsValidFilename( const TPtrC& aFileName );
       
   201 
       
   202         /**
       
   203         * From MMmsEntryWrapper: Read the decoding flag from the service entry.
       
   204         *     (Info stored in MMS service entry)
       
   205         * @return ETrue = Log add details while decoding
       
   206         *     EFalse = Don't log details.
       
   207         */
       
   208         TBool GetDecodingFlag();
       
   209 
       
   210         /**
       
   211         * From MMmsEntryWrapper: Read the flag that tells if all incoming
       
   212         *     messages are dumped to a file. (Info stored in MMS service entry)
       
   213         * @return ETrue = dump binary message to file while decoding
       
   214         *     EFalse = No binary dump wanted
       
   215         */
       
   216         TBool GetDumpFlag();
       
   217         
       
   218         /**
       
   219         * From MMmsEntryWrapper
       
   220         * Create Empty attachment file and save Mime headers.
       
   221         *     DRM check is done here.
       
   222         *     This function is the initialization function for chunked
       
   223         *         attachment handling.
       
   224         *     This function creates attachent, opens file, and saves MIME headers.
       
   225         *
       
   226         * @since v3.1
       
   227         * @param aStore edit store for current message entry
       
   228         *      Caller must keep store open until FinalizeAttachmentL has been called.
       
   229         * @param aFileName Suggested filename.
       
   230         * @param aMimeHeaders Mime header structure to be saved.
       
   231         * @param aAttachment id of the newly created attachment if successful
       
   232         * @param aAttachmentSize size of the attachment binary data + mime headers
       
   233         */
       
   234         void CreateEmptyFileAttachmentL(
       
   235             CMsvStore& aStore,
       
   236             const TDesC& aFileName,
       
   237             CMsvMimeHeaders& aMimeHeaders,
       
   238             TMsvAttachmentId& aAttachment);
       
   239             
       
   240         /**
       
   241         * From MMmsEntryWrapper
       
   242         * Write attachment data into file.
       
   243         * Call DRM handler if needed.
       
   244         *
       
   245         * @since v3.1
       
   246         *
       
   247         * @param aAttachmentData Pointer to the attachment binary data.
       
   248         * @param aDRMFlags structure where DRM flags are collected.
       
   249         *     These flags will ultimately be collected together for all
       
   250         *     attachments and stored into iMtmData1 of the parent entry.
       
   251         *     Therefore the function must only OR new flags into the structure
       
   252         *     and must not change any other bits (the same value may be reused
       
   253         *     for all attachments collecting the flags together).
       
   254         * @return Error code must indicate if attachment was removed (DRM) so that
       
   255         *     KErrNone = All well.
       
   256         *     KDRMRemoved = all well otherwise, but DRM attachment was removed,
       
   257         *         and first attachment id must be adjusted accordingly.
       
   258         *     Some other error code means an error.
       
   259         * Leaves if memory runs out
       
   260         */
       
   261         TInt ProcessAttachmentDataL(
       
   262             const TPtrC8& aAttachmentData,
       
   263             TInt32& aDRMFlags );
       
   264         
       
   265         /**
       
   266         * From MMmsEntryWrapper
       
   267         * Finalize the attachment.
       
   268         * Flush buffers and close file, calculate total size.
       
   269         * Caller must commit the store after this
       
   270         *
       
   271         * @since v3.1
       
   272         *
       
   273         * @param aStore edit store for current entry
       
   274         * @param aAttachmentSize size of the attachment binary data + mime headers
       
   275         * @param aDRMFlags structure where DRM flags are collected.
       
   276         *     These flags will ultimately be collected together for all
       
   277         *     attachments and stored into iMtmData1 of the parent entry.
       
   278         *     Therefore the function must only OR new flags into the structure
       
   279         *     and must not change any other bits (the same value may be reused
       
   280         *     for all attachments collecting the flags together).
       
   281         * @return Error code must indicate if attachment was removed (DRM) so that
       
   282         *     KErrNone = All well.
       
   283         *     KDRMRemoved = all well otherwise, but DRM attachment was removed,
       
   284         *         and first attachment id must be adjusted accordingly.
       
   285         *     Some other error code means an error.
       
   286         * Leaves if memory runs out
       
   287         */
       
   288         TInt FinalizeAttachmentL(
       
   289             CMsvStore& aStore,
       
   290             TInt& aAttachmentSize,
       
   291             TInt32& aDRMFlags );
       
   292 
       
   293 
       
   294     protected:  // New functions
       
   295         
       
   296     protected:  // Functions from base classes
       
   297         
       
   298     private:
       
   299 
       
   300         /**
       
   301         * C++ constructor.
       
   302         * @param aFs opened file system handle.
       
   303         * @param aServerEntry reference to a server entry,
       
   304         *     originally refers to the entry to be handled.
       
   305         */
       
   306         CMmsServerEntry( RFs& aFs, CMsvServerEntry& aServerEntry );
       
   307 
       
   308         /**
       
   309         * @param aServiceId TMsvId of MMS service entry.
       
   310         */
       
   311         void ConstructL( TMsvId aServiceId );
       
   312         
       
   313         /**
       
   314         * Closes stream and file in case they are open
       
   315         */
       
   316         void Reset();
       
   317 
       
   318 
       
   319     public:     // Data
       
   320     
       
   321     protected:  // Data
       
   322 
       
   323     private:    // Data
       
   324         RFs& iFs;                      // file system handle
       
   325         CMsvServerEntry& iServerEntry; // message entry
       
   326         TMsvId iServiceId;             // MMS service entry id
       
   327         TMsvId iMessageEntry;          // Id of the current main message entry
       
   328         TInt   iMessageDrive;          // messages are on C: drive by default,
       
   329                                        // may be moved to other drive
       
   330         TBool  iDump;                  // dump flag
       
   331         TBool  iLogAllDecoded;         // detailed logging flag
       
   332         TBool  iDRMNeeded;             // Server entry keeps track of DRM handling
       
   333         RFile  iAttaFile;              // file handle for writing the attachment
       
   334         TBool  iFileOpen;              // keep track if we have an open file
       
   335         TMsvAttachmentId iAttaId;      // current attachment
       
   336         TBool  iRemoveDRM;             // keep track if attachment has to be removed
       
   337         
       
   338 // DRM handlind using CAF. The DRM class is now a C-class
       
   339         CMmsDrmCaf* iDrmHandler;          
       
   340 
       
   341         
       
   342 
       
   343     public:     // Friend classes
       
   344     protected:  // Friend classes
       
   345     private:    // Friend classes
       
   346 
       
   347     };
       
   348 
       
   349 #endif      // MMSSERVERENTRY_H   
       
   350             
       
   351 // End of File