OMA DRM CAF Agent API: Using OMA DRM CAF Agent API

The following sections illustrate the most common use cases of OMA DRM CAF Agent API

Determining the file type

// allocate a content object, specify that we only want to peek at it

CContent* content = CContent::NewL(fileName, EPeek, EContentShareReadOnly);

TInt value = 0;



if (content->GetAttribute(EFileType, value) == KErrNone)

	{

	if (value == ENoDcf)

		{

		// the file is not an OMA DRM file

		}

	else if (value == EOma1Dcf)

		{

		// the file is an OMA DRM 1.0 file

		}

	else if (value == EOma2Dcf)

		{

		// the file is an OMA DRM 2.0 file

		}

	}

else

	{

	// the file type could not be determined

	}

Accessing embedded preview parts

// allocate a data object, specify that we only want to peek at it, and

// that we want the default part of the file

CData* data = CData::NewL(TVirtualPathPtr(fileName, KDefaultContentObject),

		EPeek, EContentShareReadOnly);

TBuf<256> part;



if (data->GetStringAttribute(EInstantPreviewUri, part) == KErrNone &&

	part.Length() > 0)

	{

	delete data;

	// open the part, now with the actual intent

	data = CData::NewL(TVirtualPathPtr(fileName, part), EView,

		EContentShareReadOnly);

	// do something with the data

	…

	}

else

	{

	// no preview part available

	}

Inserting domain Rights objects

// allocate a content object, specify that we only want to peek at it,

// but we need to be able to write

CContent* content = CContent::NewL(fileName, EPeek, EContentShareReadWrite);



if (content->AgentSpecificCommand(EEmbedDomainRo, KNullDesC, KNullDesC) ==

	KErrNone)

	{

	// embedding succeeded

	}

Processing DRM messages

// Import is handling via the CSupplier class

CSupplier* supplier = CSupplier::NewLC();

CMetaDataArray* metaData = CMetaDataArray::NewLC();



// Set the target for the encrypted file

supplier->SetOutputDirectoryL(KEncryptedDir);



// The agent is selected based on the MIME type of the data to be imported

CImportFile* file = supplier->ImportFileL(KOma1DrmMessageContentType,

        *metaData, KTempDcfName);

file->WriteData(KDMSimple);

file->WriteDataComplete();

CSupplierOutputFile& output = file->OutputFileL(0);

Encryption of content

CSupplier* supplier = CSupplier::NewLC();

CMetaDataArray* metaData = CMetaDataArray::NewLC();



// Tell the agent which MIME type to use for the encrypted data

metaData->AddL(KOmaImportMimeTypeField, _L8("image/gif"));

supplier->SetOutputDirectoryL(KEncryptedDir);



// The KOmaImportContentType is a OMA DRM agent specific MIME type which

// indicates that plain content is to be encrypted

CImportFile* file = supplier->ImportFileL(KOmaImportContentType,

        *metaData, KTempDcfName);

file->WriteData(KDMSimple);

file->WriteDataComplete();

CSupplierOutputFile& output = file->OutputFileL(0);

Error handling

Error handling is defined in relevant CAF operations. In addition to that, the KErrOverflow error indicates that the given output buffer is not large enough to hold the result of the requested operation.

Memory overhead

The methods returning string attribute values and the agent specific commands must be called with enough memory allocated in the output parameters. Otherwise, the function calls fail with the KErrOverflow error code.

Extensions to the API

CAF API can be extended using agent-specific commands and attributes, and OMA DRM CAF Agent API is such an extension. It is expected that any additional functionality of OMA DRM CAF Agent will be provided by adding new attribute and command enumeration values.


Copyright © Nokia Corporation 2001-2008
Back to top