drmfile_p.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. *
  5. * For the applicable distribution terms see the license.txt -file, included in
  6. * the distribution.
  7. */
  8. #include "drmfile_p.h"
  9. #include "drmfile.h"
  10. #include <caf/caferr.h>
  11. #include <caf/embeddedobject.h>
  12. #include <caf/streamableptrarray.h>
  13. #include <caf/data.h>
  14. #include <e32base.h>
  15. #include <f32file.h>
  16. #include "QDebug"
  17. DRMFilePrivate::DRMFilePrivate() :
  18. CAF_file(NULL)
  19. {
  20. }
  21. DRMFilePrivate::~DRMFilePrivate()
  22. {
  23. close();
  24. }
  25. int DRMFilePrivate::open(const QString & fileName)
  26. {
  27. QString symbianFileName;
  28. symbianFileName = fileName;
  29. QChar find('/');
  30. QChar replace('\\');
  31. symbianFileName.replace(find,replace,Qt::CaseInsensitive);
  32. TPtrC16 fileName_TextPtr(reinterpret_cast<const TUint16*>(symbianFileName.utf16()));
  33. TRAPD(errcode, openL(fileName_TextPtr))
  34. if (errcode == KErrNone)
  35. intentExecuted = EFalse;
  36. return errcode;
  37. }
  38. int DRMFilePrivate::read(uchar*& data, int length, int index)
  39. {
  40. int result = KErrNone;
  41. data = NULL;
  42. while (true){
  43. if (!(index >= 0 && index < CAF_data.Count())){
  44. result = KErrBadHandle;
  45. break;
  46. }
  47. CData* dataItem = CAF_data[index];
  48. RBuf8 buffer;
  49. if (!length)
  50. TRAP(result, dataItem->DataSizeL(length));
  51. if (result != KErrNone)
  52. break;
  53. length++; //to be able use PtrZ() call
  54. TRAP (result, buffer.CreateL(length));
  55. if (result != KErrNone)
  56. break;
  57. if (!intentExecuted)
  58. result = dataItem->ExecuteIntent(ContentAccess::EExecute);
  59. if (result != KErrNone)
  60. break;
  61. intentExecuted = ETrue;
  62. result = dataItem->Read(buffer);
  63. if (result != KErrNone)
  64. break;
  65. result = length;
  66. uchar* ptr = const_cast<uchar*>(buffer.PtrZ()); //give up ownership from RBuf8
  67. data = ptr;
  68. break;
  69. }
  70. if (result < KErrNone)
  71. RDebug::Print(_L("DRMFilePrivate::read ContentAccess::CData::Read error %d"), result);
  72. return result;
  73. }
  74. void DRMFilePrivate::close()
  75. {
  76. CAF_data.ResetAndDestroy();
  77. if (CAF_file!=NULL){
  78. delete CAF_file;
  79. CAF_file = NULL;
  80. }
  81. }
  82. void DRMFilePrivate::openL(const TDesC& fileName)
  83. {
  84. if (CAF_file)
  85. return;
  86. CAF_file = CContent::NewL(fileName);
  87. RStreamablePtrArray <CEmbeddedObject> myArray;
  88. CleanupClosePushL(myArray);
  89. // Get an array of the embedded objects within the current container in the file
  90. CAF_file->GetEmbeddedObjectsL(myArray);
  91. for (int i = 0; i < myArray.Count(); i++)
  92. {
  93. CAF_data.AppendL(CAF_file->OpenContentL(ContentAccess::EExecute, myArray[i]->UniqueId()));
  94. }
  95. CleanupStack::PopAndDestroy(&myArray);
  96. }
  97. int DRMFilePrivate::size(int index)
  98. {
  99. if (!(index >= 0 && index < CAF_data.Count())){
  100. return KErrGeneral;
  101. }
  102. TInt size;
  103. TRAPD(errcode, CAF_data[index]->DataSizeL(size));
  104. return ((errcode == KErrNone) ? size : errcode);
  105. }
  106. const ushort* DRMFilePrivate::getStringAttr(int index, int& len, TStringAttribute attr) const
  107. {
  108. if (!(index >= 0 && index < CAF_data.Count())){
  109. return NULL;
  110. }
  111. RBuf uri;
  112. uri.CreateL(KMaxFileName + 1);
  113. CAF_data[index]->GetStringAttribute(attr, uri);
  114. len = uri.Length();
  115. return (uri.PtrZ());
  116. }