os/security/contentmgmt/contentaccessfwfordrm/source/caf/Supplier.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/caf/Supplier.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,209 @@
     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 +
    1.22 +#include <caf/caftypes.h>
    1.23 +#include <caf/metadataarray.h>
    1.24 +#include <caf/supplier.h>
    1.25 +#include "resolver.h"
    1.26 +#include <caf/importfile.h>
    1.27 +#include "agentinfo.h"
    1.28 +#include <caf/agentinterface.h>
    1.29 +
    1.30 +#ifndef REMOVE_CAF1
    1.31 +#include <caf/cafmimeheader.h>
    1.32 +#include <apmstd.h> 
    1.33 +#endif // REMOVE_CAF1
    1.34 +
    1.35 +using namespace ContentAccess;
    1.36 +
    1.37 +EXPORT_C CSupplier* CSupplier::NewLC()
    1.38 +	{
    1.39 +	CSupplier* self = new (ELeave) CSupplier();
    1.40 +	CleanupStack::PushL(self);
    1.41 +	self->ConstructL();
    1.42 +	return self;
    1.43 +	}
    1.44 +
    1.45 +EXPORT_C CSupplier* CSupplier::NewL()
    1.46 +	{
    1.47 +	CSupplier* self = NewLC();
    1.48 +	CleanupStack::Pop(self);
    1.49 +	return self;
    1.50 +	}
    1.51 +
    1.52 +CSupplier::CSupplier()
    1.53 +	{
    1.54 +	}
    1.55 +
    1.56 +CSupplier::~CSupplier()
    1.57 +	{
    1.58 +	delete iAgentResolver;
    1.59 +	delete iOutputDirectory;
    1.60 +	}
    1.61 +
    1.62 +void CSupplier::ConstructL()
    1.63 +	{
    1.64 +	iAgentResolver = CAgentResolver::NewL(EFalse);
    1.65 +	iOutputDirectory=HBufC::NewL(0);
    1.66 +	}
    1.67 +
    1.68 +EXPORT_C TBool CSupplier::IsImportSupported(const TDesC8& aMimeType)
    1.69 +	{
    1.70 +	TBuf8 <KMaxDataTypeLength> mimeLowerCase;
    1.71 +	if(aMimeType.Length() > KMaxDataTypeLength)
    1.72 +		{
    1.73 +		return EFalse;
    1.74 +		}
    1.75 +
    1.76 +	// Convert supplied mime type to lower case
    1.77 +	mimeLowerCase.Copy(aMimeType);
    1.78 +	mimeLowerCase.LowerCase();
    1.79 +
    1.80 +	// Search for the mime type in the agents
    1.81 +	for(TInt i = 0; i < iAgentResolver->SupplierMimeTypes().Count(); i++)
    1.82 +		{
    1.83 +		if(mimeLowerCase.Compare(iAgentResolver->SupplierMimeTypes()[i]) == 0)
    1.84 +			{
    1.85 +			return ETrue;
    1.86 +			}
    1.87 +		}
    1.88 +	return EFalse;
    1.89 +	}
    1.90 +
    1.91 +EXPORT_C void CSupplier::PrepareHTTPRequestHeaders(RStringPool& aStringPool, RHTTPHeaders& aRequestHeaders) const
    1.92 +	{
    1.93 +	// Ignore errors from any particular agent because we can't
    1.94 +	// let one agent ruin things for everyone else.
    1.95 +	TInt i = 0;
    1.96 +	TInt err = KErrNone;
    1.97 +	CAgentManager* manager = NULL;
    1.98 +	for(i = 0; i < iAgentResolver->AgentInfoCount(); i++)
    1.99 +		{
   1.100 +		TRAP(err, manager = &iAgentResolver->AgentInfo(i).AgentManagerL());
   1.101 +		if(err == KErrNone)
   1.102 +			{
   1.103 +			manager->PrepareHTTPRequestHeaders(aStringPool, aRequestHeaders);
   1.104 +			}	
   1.105 +		}
   1.106 +	}
   1.107 +
   1.108 +
   1.109 +EXPORT_C void CSupplier::SetOutputDirectoryL(const TDesC &aOutputDirectory)
   1.110 +	{
   1.111 +	HBufC *newOutputDirectory;
   1.112 +
   1.113 +	// Make sure the path has a backslash at the end
   1.114 +	TInt pos = aOutputDirectory.LocateReverse(TChar(KPathDelimiter));
   1.115 +	if(pos + 1 != aOutputDirectory.Length())
   1.116 +		{
   1.117 +		// Append a trailing backslash
   1.118 +		newOutputDirectory=HBufC::NewL(aOutputDirectory.Length()+1);
   1.119 +		newOutputDirectory->Des().Append(aOutputDirectory);
   1.120 +		newOutputDirectory->Des().Append(TChar(KPathDelimiter));
   1.121 +		}
   1.122 +	else
   1.123 +		{
   1.124 +		newOutputDirectory=aOutputDirectory.AllocL();
   1.125 +		}
   1.126 +
   1.127 +	// replace the existing output path
   1.128 +	delete iOutputDirectory;
   1.129 +	iOutputDirectory = newOutputDirectory;
   1.130 +	}
   1.131 +
   1.132 +EXPORT_C CImportFile* CSupplier::ImportFileL(const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aSuggestedFileName)
   1.133 +	{
   1.134 +	CAgentInfo& agentInfo = iAgentResolver->ResolveSupplierMimeL(aMimeType);
   1.135 +
   1.136 +	TUid agentUid = agentInfo.Agent().ImplementationUid();
   1.137 +	
   1.138 +	// Create import object, agent creates output files
   1.139 +	CImportFile* import = CImportFile::NewL (agentUid, aMimeType, aImportMetaData, *iOutputDirectory, aSuggestedFileName);
   1.140 +	return import;
   1.141 +	}
   1.142 +
   1.143 +EXPORT_C CImportFile* CSupplier::ImportFileL(const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData)
   1.144 +	{
   1.145 +	// Create import object, client provides output files
   1.146 +	CAgentInfo& agentInfo = iAgentResolver->ResolveSupplierMimeL(aMimeType);
   1.147 +	
   1.148 +	TUid agentUid = agentInfo.Agent().ImplementationUid();
   1.149 +	
   1.150 +	// Create import object, agent creates output files
   1.151 +	CImportFile* import = CImportFile::NewL (agentUid, aMimeType, aImportMetaData);
   1.152 +	return import;
   1.153 +	}
   1.154 +
   1.155 +#ifndef REMOVE_CAF1
   1.156 +EXPORT_C CImportFile *  CSupplier::ImportFileL (CCafMimeHeader &aMimeHeader, const TDesC &aSuggestedFileName)
   1.157 +	{
   1.158 +	TBuf8 <KMaxDataTypeLength> mimeType;
   1.159 +
   1.160 +	// string constants used to fill in CMetaDataArray
   1.161 +	_LIT8(KContentType, "Content-Type");
   1.162 +	_LIT8(KContentLength, "Content-Length");
   1.163 +	_LIT8(KContentId, "Content-Id");
   1.164 +	_LIT8(KContentTransferEncoding, "Content-Tranfer-Encoding");
   1.165 +	_LIT8(KBoundary, "Content-Boundary");
   1.166 +
   1.167 +	// create new CMetaDataArray to hold the information previously supplied in CCafMimeHeader
   1.168 +	CMetaDataArray *array = CMetaDataArray::NewLC();
   1.169 +
   1.170 +	// Copy "standard mime data" to the CMetaDataArray
   1.171 +	if(aMimeHeader.StandardMimeData(EContentType).Length() != 0)
   1.172 +		{
   1.173 +		array->AddL(KContentType(),aMimeHeader.StandardMimeData(EContentType));
   1.174 +		mimeType.Append(aMimeHeader.StandardMimeData(EContentType));
   1.175 +		}
   1.176 +	if(aMimeHeader.StandardMimeData(EContentLength).Length() != 0)
   1.177 +		{
   1.178 +		array->AddL(KContentLength(),aMimeHeader.StandardMimeData(EContentLength));
   1.179 +		}
   1.180 +	if(aMimeHeader.StandardMimeData(EContentLength).Length() != 0)
   1.181 +		{
   1.182 +		array->AddL(KContentLength(),aMimeHeader.StandardMimeData(EContentLength));
   1.183 +		}
   1.184 +	if(aMimeHeader.StandardMimeData(EContentId).Length() != 0)
   1.185 +		{
   1.186 +		array->AddL(KContentId(),aMimeHeader.StandardMimeData(EContentId));
   1.187 +		}
   1.188 +	if(aMimeHeader.StandardMimeData(EContentTransferEncoding).Length() != 0)
   1.189 +		{
   1.190 +		array->AddL(KContentTransferEncoding(),aMimeHeader.StandardMimeData(EContentTransferEncoding));
   1.191 +		}
   1.192 +	if(aMimeHeader.StandardMimeData(EBoundary).Length() != 0)
   1.193 +		{
   1.194 +		array->AddL(KBoundary(),aMimeHeader.StandardMimeData(EBoundary));
   1.195 +		}
   1.196 +
   1.197 +	// Add "non-standard" mime fields to CMetaDataArray
   1.198 +	TInt count = aMimeHeader.NonStandardMimeCount();
   1.199 +	for( TInt i = 0; i < count; i++)
   1.200 +		{
   1.201 +		array->AddL(aMimeHeader.NonStandardMimeField(i), aMimeHeader.NonStandardMimeData(i));
   1.202 +		}
   1.203 +
   1.204 +	// Create new CImportFile object
   1.205 +	CImportFile *importFile = ImportFileL(mimeType, *array, aSuggestedFileName);
   1.206 +	CleanupStack::PopAndDestroy(array);
   1.207 +	return importFile;
   1.208 +	}
   1.209 +
   1.210 +#endif // REMOVE_CAF1
   1.211 +
   1.212 +