os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32defaultattributes.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <apgcli.h>
sl@0
    20
#include <f32file.h>
sl@0
    21
sl@0
    22
#include <caf/attributeset.h>
sl@0
    23
#include <caf/stringattributeset.h>
sl@0
    24
#include <caf/virtualpath.h>
sl@0
    25
#include <caf/caferr.h>
sl@0
    26
#include "f32defaultattributes.h"
sl@0
    27
sl@0
    28
sl@0
    29
using namespace ContentAccess;
sl@0
    30
sl@0
    31
TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& )
sl@0
    32
	{
sl@0
    33
	TInt err = KErrNone;
sl@0
    34
	// All files handled by the F32 agent are unprotected and have the same
sl@0
    35
	// standard set of attributes
sl@0
    36
	switch(aAttribute)
sl@0
    37
		{
sl@0
    38
		case EIsForwardable:
sl@0
    39
		case EIsModifyable:
sl@0
    40
		case EIsCopyable:
sl@0
    41
		case ECanPlay:
sl@0
    42
		case ECanPrint:
sl@0
    43
		case ECanExecute:
sl@0
    44
		case ECanView:
sl@0
    45
		case ECanRewind:
sl@0
    46
		case ECopyPaste:
sl@0
    47
		case ECanMove:
sl@0
    48
		case ECanRename:
sl@0
    49
		case ECanAutomaticConsume:
sl@0
    50
			aValue = ETrue;
sl@0
    51
			break;
sl@0
    52
		case EIsMediaPlayerOnly:
sl@0
    53
		case EIsAutomatedUseOnly:
sl@0
    54
		case EIsProtected:			
sl@0
    55
		case EPreviewAvailable:
sl@0
    56
			aValue = EFalse;
sl@0
    57
			break;
sl@0
    58
		case ETrackNumber:
sl@0
    59
		case EContentCDataInUse:
sl@0
    60
		case EContentVersion:
sl@0
    61
		default:
sl@0
    62
			err = KErrCANotSupported;
sl@0
    63
			break;
sl@0
    64
		};
sl@0
    65
	return err;
sl@0
    66
	}
sl@0
    67
sl@0
    68
TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUri) 
sl@0
    69
	{
sl@0
    70
	TInt i = 0;
sl@0
    71
	TInt attribute = 0;
sl@0
    72
	TInt value=0;
sl@0
    73
	TInt err = KErrNone;
sl@0
    74
	TInt numAttributes = aAttributeSet.Count();
sl@0
    75
	
sl@0
    76
	// loop through all the attriutes in the set and find their values
sl@0
    77
	for(i = 0; i < numAttributes; i++)
sl@0
    78
		{
sl@0
    79
		attribute = aAttributeSet[i];
sl@0
    80
		err = GetAttribute(attribute, value, aUri);
sl@0
    81
		aAttributeSet.SetValue(attribute, value, err);
sl@0
    82
		}	
sl@0
    83
	return KErrNone;
sl@0
    84
	}
sl@0
    85
sl@0
    86
TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUri)
sl@0
    87
	{
sl@0
    88
	TInt err = KErrNone;
sl@0
    89
	TBuf8 <KMaxDataTypeLength> mimeType;
sl@0
    90
sl@0
    91
	switch(aAttribute)
sl@0
    92
		{
sl@0
    93
		case EMimeType:
sl@0
    94
			TRAP(err, GetMimeTypeL(aUri, mimeType));
sl@0
    95
			if(err == KErrNone)
sl@0
    96
				{
sl@0
    97
				aValue.Copy(mimeType);
sl@0
    98
				}
sl@0
    99
			break;
sl@0
   100
		default:
sl@0
   101
			err = KErrCANotSupported;
sl@0
   102
			break;
sl@0
   103
		};
sl@0
   104
	return err;
sl@0
   105
	}
sl@0
   106
sl@0
   107
TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUri)
sl@0
   108
	{
sl@0
   109
	TInt i = 0;
sl@0
   110
	TInt attribute = 0;
sl@0
   111
	TInt err = KErrNone;
sl@0
   112
	TBuf <KMaxDataTypeLength> buf;
sl@0
   113
sl@0
   114
	TInt numAttributes = aStringAttributeSet.Count();
sl@0
   115
sl@0
   116
	// loop through all the attriutes in the set and find their values
sl@0
   117
	for(i = 0; i < numAttributes; i++)
sl@0
   118
		{
sl@0
   119
		buf.SetLength(0);
sl@0
   120
		attribute = aStringAttributeSet[i];
sl@0
   121
		err = GetStringAttribute(attribute, buf, aUri);
sl@0
   122
		err = aStringAttributeSet.SetValue(attribute,buf, err);
sl@0
   123
		if(err != KErrNone)
sl@0
   124
			{
sl@0
   125
			return err;
sl@0
   126
			}
sl@0
   127
		}	
sl@0
   128
	return KErrNone;
sl@0
   129
	}
sl@0
   130
sl@0
   131
void TF32DefaultAttributes::GetMimeTypeL(const TDesC& aURI, TDes8& aMimeType)
sl@0
   132
	{
sl@0
   133
	TUid appUid(KNullUid);
sl@0
   134
	TDataType dataType;
sl@0
   135
	RApaLsSession apparcSession;
sl@0
   136
	
sl@0
   137
	// Connect to Apparc
sl@0
   138
	User::LeaveIfError(apparcSession.Connect());
sl@0
   139
	CleanupClosePushL(apparcSession);
sl@0
   140
sl@0
   141
	User::LeaveIfError(apparcSession.AppForDocument(aURI, appUid, dataType));
sl@0
   142
	
sl@0
   143
	if(dataType.Des8().Length() == 0)
sl@0
   144
		{
sl@0
   145
		User::Leave(KErrNotFound);
sl@0
   146
		}
sl@0
   147
sl@0
   148
	aMimeType.Append(dataType.Des8());
sl@0
   149
	CleanupStack::PopAndDestroy(&apparcSession);
sl@0
   150
	}
sl@0
   151
sl@0
   152
sl@0
   153
TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, RFile& /*aFile*/)
sl@0
   154
	{
sl@0
   155
	return GetAttribute(aAttribute, aValue, KNullDesC);
sl@0
   156
	}
sl@0
   157
	
sl@0
   158
TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, RFile& aFile)
sl@0
   159
	{
sl@0
   160
	TInt i = 0;
sl@0
   161
	TInt attribute = 0;
sl@0
   162
	TInt value = 0;
sl@0
   163
	TInt err = KErrNone;
sl@0
   164
	TInt numAttributes = aAttributeSet.Count();
sl@0
   165
	
sl@0
   166
	// loop through all the attributes in the set and find their values
sl@0
   167
	for(i = 0; i < numAttributes; i++)
sl@0
   168
		{
sl@0
   169
		attribute = aAttributeSet[i];
sl@0
   170
		err = GetAttribute(attribute, value, aFile);
sl@0
   171
		aAttributeSet.SetValue(attribute, value, err);
sl@0
   172
		}	
sl@0
   173
	return KErrNone;
sl@0
   174
	}
sl@0
   175
	
sl@0
   176
TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, RFile& aFile)
sl@0
   177
	{
sl@0
   178
	TInt err = KErrNone;
sl@0
   179
	TBuf8 <KMaxDataTypeLength> mimeType;
sl@0
   180
sl@0
   181
	switch(aAttribute)
sl@0
   182
		{
sl@0
   183
		case EMimeType:
sl@0
   184
			TRAP(err, GetMimeTypeL(aFile, mimeType));
sl@0
   185
			if(err == KErrNone)
sl@0
   186
				{
sl@0
   187
				aValue.Copy(mimeType);
sl@0
   188
				}
sl@0
   189
			break;
sl@0
   190
		default:
sl@0
   191
			err = KErrCANotSupported;
sl@0
   192
			break;
sl@0
   193
		};
sl@0
   194
	return err;
sl@0
   195
	}
sl@0
   196
	
sl@0
   197
TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile)
sl@0
   198
	{
sl@0
   199
	TInt i = 0;
sl@0
   200
	TInt attribute = 0;
sl@0
   201
	TInt err = KErrNone;
sl@0
   202
	TBuf <KMaxDataTypeLength> buf;
sl@0
   203
sl@0
   204
	TInt numAttributes = aStringAttributeSet.Count();
sl@0
   205
sl@0
   206
	// loop through all the attriutes in the set and find their values
sl@0
   207
	for(i = 0; i < numAttributes; i++)
sl@0
   208
		{
sl@0
   209
		buf.SetLength(0);
sl@0
   210
		attribute = aStringAttributeSet[i];
sl@0
   211
		err = GetStringAttribute(attribute, buf, aFile);
sl@0
   212
		err = aStringAttributeSet.SetValue(attribute,buf, err);
sl@0
   213
		if(err != KErrNone)
sl@0
   214
			{
sl@0
   215
			return err;
sl@0
   216
			}
sl@0
   217
		}	
sl@0
   218
	return KErrNone;
sl@0
   219
	}
sl@0
   220
	
sl@0
   221
void TF32DefaultAttributes::GetMimeTypeL(RFile& aFile, TDes8& aMimeType)
sl@0
   222
	{
sl@0
   223
	TUid appUid(KNullUid);
sl@0
   224
	TDataType dataType;
sl@0
   225
	RApaLsSession apparcSession;
sl@0
   226
	
sl@0
   227
	// Connect to Apparc
sl@0
   228
	User::LeaveIfError(apparcSession.Connect());
sl@0
   229
	CleanupClosePushL(apparcSession);
sl@0
   230
sl@0
   231
	User::LeaveIfError(apparcSession.AppForDocument(aFile, appUid, dataType));
sl@0
   232
	
sl@0
   233
	if(dataType.Des8().Length() == 0)
sl@0
   234
		{
sl@0
   235
		User::Leave(KErrNotFound);
sl@0
   236
		}
sl@0
   237
	
sl@0
   238
	aMimeType.Append(dataType.Des8());
sl@0
   239
	CleanupStack::PopAndDestroy(&apparcSession);
sl@0
   240
	}
sl@0
   241
sl@0
   242
TInt TF32DefaultAttributes::CheckUniqueId(const TDesC& aUniqueId)
sl@0
   243
	{
sl@0
   244
	// The only UniqueId values that make sense for the F32 agent are
sl@0
   245
	// a zero length descriptor (indicating the application is referring to the entire file 
sl@0
   246
	// or KDefaultContentObject which is also the entire file in the case of the F32 agent
sl@0
   247
	if(aUniqueId.Length() == 0 || aUniqueId == KDefaultContentObject())
sl@0
   248
		{
sl@0
   249
		return KErrNone;	
sl@0
   250
		}
sl@0
   251
	else 
sl@0
   252
		{
sl@0
   253
		return KErrNotFound;	
sl@0
   254
		}
sl@0
   255
	}
sl@0
   256
	
sl@0
   257
TInt TF32DefaultAttributes::CheckVirtualPath(const TVirtualPathPtr& aVirtualPath)
sl@0
   258
	{
sl@0
   259
	// check the Unique Id
sl@0
   260
	TInt err = CheckUniqueId(aVirtualPath.UniqueId());
sl@0
   261
	
sl@0
   262
	// check if the file exists
sl@0
   263
	
sl@0
   264
	
sl@0
   265
	return err;
sl@0
   266
	}	
sl@0
   267
	
sl@0
   268
TUint TF32DefaultAttributes::GetFileMode(TContentShareMode aMode)
sl@0
   269
	{
sl@0
   270
	
sl@0
   271
	TUint fileMode = EFileStream | EFileRead;
sl@0
   272
sl@0
   273
	if(aMode  == EContentShareReadWrite)
sl@0
   274
		{
sl@0
   275
		fileMode |= EFileShareReadersOrWriters;
sl@0
   276
		}
sl@0
   277
	else if(aMode == EContentShareExclusive)
sl@0
   278
		{
sl@0
   279
		fileMode  |= EFileShareExclusive;
sl@0
   280
		}
sl@0
   281
	else
sl@0
   282
		{
sl@0
   283
		fileMode |= EFileShareReadersOnly;
sl@0
   284
		}
sl@0
   285
		
sl@0
   286
	return fileMode;
sl@0
   287
	}
sl@0
   288
sl@0
   289
#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
sl@0
   290
	
sl@0
   291
TInt TF32DefaultAttributes::GetAttribute(const TDesC8& /*aHeaderData*/, TInt aAttribute, TInt& aValue)
sl@0
   292
	{
sl@0
   293
	return GetAttribute(aAttribute, aValue, KNullDesC);
sl@0
   294
	}
sl@0
   295
	
sl@0
   296
TInt TF32DefaultAttributes::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet)
sl@0
   297
	{
sl@0
   298
	TInt i = 0;
sl@0
   299
	TInt attribute = 0;
sl@0
   300
	TInt value = 0;
sl@0
   301
	TInt err = KErrNone;
sl@0
   302
	TInt numAttributes = aAttributeSet.Count();
sl@0
   303
	
sl@0
   304
	// loop through all the attriutes in the set and find their values
sl@0
   305
	for(i = 0; i < numAttributes; i++)
sl@0
   306
		{
sl@0
   307
		attribute = aAttributeSet[i];
sl@0
   308
		err = GetAttribute(aHeaderData, attribute, value);
sl@0
   309
		aAttributeSet.SetValue(attribute, value, err);
sl@0
   310
		}	
sl@0
   311
	return KErrNone;
sl@0
   312
	}
sl@0
   313
	
sl@0
   314
TInt TF32DefaultAttributes::GetStringAttribute(const TDesC8& /*aHeaderData*/, TInt aAttribute, TDes& aValue)
sl@0
   315
	{
sl@0
   316
	TInt err = KErrNone;
sl@0
   317
	TBuf8 <KMaxDataTypeLength> mimeType;
sl@0
   318
sl@0
   319
	switch(aAttribute)
sl@0
   320
		{
sl@0
   321
		case EMimeType:
sl@0
   322
			aValue.Copy(KNullDesC());
sl@0
   323
			break;
sl@0
   324
		case EContentID:
sl@0
   325
			aValue.Copy(KDefaultContentObject());
sl@0
   326
			break;
sl@0
   327
		default:
sl@0
   328
			err = KErrCANotSupported;
sl@0
   329
			break;
sl@0
   330
		};
sl@0
   331
	return err;
sl@0
   332
	}
sl@0
   333
	
sl@0
   334
TInt TF32DefaultAttributes::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet)
sl@0
   335
	{
sl@0
   336
	TInt i = 0;
sl@0
   337
	TInt attribute = 0;
sl@0
   338
	TInt err = KErrNone;
sl@0
   339
	TBuf <KMaxDataTypeLength> buf;
sl@0
   340
sl@0
   341
	TInt numAttributes = aStringAttributeSet.Count();
sl@0
   342
sl@0
   343
	// loop through all the attriutes in the set and find their values
sl@0
   344
	for(i = 0; i < numAttributes; i++)
sl@0
   345
		{
sl@0
   346
		buf.SetLength(0);
sl@0
   347
		attribute = aStringAttributeSet[i];
sl@0
   348
		err = GetStringAttribute(aHeaderData, attribute, buf);
sl@0
   349
		err = aStringAttributeSet.SetValue(attribute, buf, err);
sl@0
   350
		if(err != KErrNone)
sl@0
   351
			{
sl@0
   352
			return err;
sl@0
   353
			}
sl@0
   354
		}	
sl@0
   355
	return KErrNone;
sl@0
   356
	}
sl@0
   357
sl@0
   358
#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT