1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/caf/supplieroutputfile.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,185 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include <apgcli.h>
1.22 +#include <apmstd.h>
1.23 +#include <caf/supplieroutputfile.h>
1.24 +
1.25 +#include <caf/caftypes.h>
1.26 +#include "resolver.h"
1.27 +
1.28 +#ifndef REMOVE_CAF1
1.29 +#include <caf/attribute.h>
1.30 +#include <caf/content.h>
1.31 +#include <caf/bitset.h>
1.32 +#endif
1.33 +
1.34 +
1.35 +using namespace ContentAccess;
1.36 +
1.37 +#ifndef REMOVE_CAF1
1.38 +EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType)
1.39 + {
1.40 + return CSupplierOutputFile::NewL(aFileName, aOutputType, KNullDesC8());
1.41 + }
1.42 +#endif
1.43 +
1.44 +EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType, const TDesC8& aMimeType)
1.45 + {
1.46 + CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
1.47 + CleanupStack::PushL(self);
1.48 + self->ConstructL(aFileName, aMimeType, aOutputType);
1.49 + CleanupStack::Pop(self);
1.50 + return self;
1.51 + }
1.52 +
1.53 +EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(RReadStream& aStream)
1.54 + {
1.55 + CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
1.56 + CleanupStack::PushL(self);
1.57 + self->InternalizeL(aStream);
1.58 + CleanupStack::Pop(self);
1.59 + return self;
1.60 + }
1.61 +
1.62 +CSupplierOutputFile::CSupplierOutputFile()
1.63 + {
1.64 + }
1.65 +
1.66 +
1.67 +void CSupplierOutputFile::ConstructL(const TDesC& aFileName, const TDesC8& aMimeType, const TOutputType aOutputType)
1.68 + {
1.69 + iOutputType = aOutputType;
1.70 +
1.71 + CAgentResolver *resolver = CAgentResolver::NewL(EFalse);
1.72 + CleanupStack::PushL(resolver);
1.73 + iFileName = resolver->ConvertAgentFileNameL(aFileName);
1.74 + CleanupStack::PopAndDestroy(resolver);
1.75 + iMimeType.Copy(aMimeType);
1.76 +
1.77 + // convert mime type to lower case
1.78 + iMimeType.LowerCase();
1.79 + }
1.80 +
1.81 +
1.82 +CSupplierOutputFile::~CSupplierOutputFile()
1.83 + {
1.84 + delete iFileName;
1.85 +#ifndef REMOVE_CAF1
1.86 + delete iAttr;
1.87 +#endif
1.88 + }
1.89 +
1.90 +
1.91 +EXPORT_C TPtrC CSupplierOutputFile::FileName() const
1.92 + {
1.93 + return *iFileName;
1.94 + }
1.95 +
1.96 +EXPORT_C TOutputType CSupplierOutputFile::OutputType() const
1.97 + {
1.98 + return iOutputType;
1.99 + }
1.100 +
1.101 +EXPORT_C TPtrC8 CSupplierOutputFile::MimeTypeL()
1.102 + {
1.103 + TUid uid;
1.104 + TDataType dataType;
1.105 + RApaLsSession apparcSession;
1.106 +
1.107 + if(iMimeType.Length() == 0)
1.108 + {
1.109 + // Use the Application Architecture Server to find the Mime type of the output File
1.110 + User::LeaveIfError(apparcSession.Connect());
1.111 + CleanupClosePushL(apparcSession);
1.112 +
1.113 + // Use a temp FS session to preserve platsec
1.114 + RFs tempFsSession;
1.115 + User::LeaveIfError(tempFsSession.Connect());
1.116 + CleanupClosePushL(tempFsSession);
1.117 + User::LeaveIfError(tempFsSession.ShareProtected());
1.118 +
1.119 + // Open file here and send the handle because AppArc doesn't have Allfiles capability
1.120 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.121 + // If file size is greater than 2GB than RFile::Open will fail with KErrTooBig.
1.122 + // So RFile64.
1.123 + RFile64 tempFile;
1.124 +#else
1.125 + RFile tempFile;
1.126 +#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.127 + User::LeaveIfError(tempFile.Open(tempFsSession, *iFileName, EFileRead|EFileShareAny));
1.128 + CleanupClosePushL(tempFile);
1.129 +
1.130 + User::LeaveIfError(apparcSession.AppForDocument(tempFile, uid, dataType));
1.131 +
1.132 + iMimeType.Copy(dataType.Des8().Left(KMaxDataTypeLength));
1.133 +
1.134 + CleanupStack::PopAndDestroy(&tempFile); // close
1.135 + CleanupStack::PopAndDestroy(&tempFsSession); // close
1.136 + CleanupStack::PopAndDestroy(&apparcSession); // close
1.137 + }
1.138 +
1.139 + return iMimeType;
1.140 + }
1.141 +
1.142 +EXPORT_C void CSupplierOutputFile::ExternalizeL(RWriteStream& aStream) const
1.143 + {
1.144 + aStream.WriteInt32L(static_cast <TInt> (iOutputType));
1.145 + aStream.WriteInt32L(iFileName->Des().Length());
1.146 + aStream.WriteL(*iFileName);
1.147 + aStream.WriteInt32L(iMimeType.Length());
1.148 + aStream.WriteL(iMimeType);
1.149 + }
1.150 +
1.151 +void CSupplierOutputFile::InternalizeL(RReadStream& aStream)
1.152 + {
1.153 + TInt length = 0;
1.154 + iOutputType = static_cast <TOutputType> (aStream.ReadInt32L());
1.155 + length = aStream.ReadInt32L();
1.156 + iFileName = HBufC::NewL(length);
1.157 + if(length)
1.158 + {
1.159 + TPtr filename = iFileName->Des();
1.160 + aStream.ReadL(filename, length);
1.161 + }
1.162 + length = aStream.ReadInt32L();
1.163 + aStream.ReadL(iMimeType, length);
1.164 + }
1.165 +
1.166 +
1.167 +
1.168 +#ifndef REMOVE_CAF1
1.169 +EXPORT_C CAttribute & CSupplierOutputFile::AttributesL (TBool aPreloaded)
1.170 + {
1.171 + // retrieve the attributes, only need to do this once since this instance
1.172 + // will only ever refer to one output file
1.173 + if(!iAttr)
1.174 + {
1.175 + // create a content consumer interface for the output file produced
1.176 + CContent* content = CContent::NewLC(FileName());
1.177 + iAttr = content->NewAttributeL(ETrue);
1.178 + CleanupStack::PopAndDestroy(content);
1.179 + }
1.180 + else if(aPreloaded) // update all attribute bits
1.181 + {
1.182 + CBitset &bitset = iAttr->QuerySet();
1.183 + bitset.SetAll();
1.184 + iAttr->GetL();
1.185 + }
1.186 + return *iAttr;
1.187 + }
1.188 +#endif // #ifndef REMOVE_CAF1