drmfile_p.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "drmfile_p.h"
  2. #include "drmfile.h"
  3. #include <caf/caferr.h>
  4. #include <caf/embeddedobject.h>
  5. #include <caf/streamableptrarray.h>
  6. #include <caf/data.h>
  7. #include <e32base.h>
  8. #include <f32file.h>
  9. #include "QDebug"
  10. DRMFilePrivate::DRMFilePrivate() :
  11. CAF_file(NULL), CAF_data(NULL)
  12. {
  13. }
  14. DRMFilePrivate::~DRMFilePrivate()
  15. {
  16. close();
  17. }
  18. int DRMFilePrivate::open(const QString & fileName)
  19. {
  20. int result = KErrNone;
  21. QString symbianFileName;
  22. symbianFileName = fileName;
  23. QChar find('/');
  24. QChar replace('\\');
  25. symbianFileName.replace(find,replace,Qt::CaseInsensitive);
  26. TPtrC16 fileName_TextPtr(reinterpret_cast<const TUint16*>(symbianFileName.utf16()));
  27. TRAPD(panic_code, result = openL(fileName_TextPtr))
  28. if(panic_code != KErrNone)
  29. result = panic_code;
  30. else
  31. intentExecuted = EFalse;
  32. return result;
  33. }
  34. int DRMFilePrivate::read(char* data, int length)
  35. {
  36. int result = KErrNone;
  37. if(CAF_data == NULL)
  38. result = KErrBadHandle;
  39. else
  40. {
  41. RBuf8 buffer;
  42. TRAP (result, buffer.CreateL(length));
  43. if(result == KErrNone)
  44. {
  45. if(!intentExecuted)
  46. result = CAF_data->ExecuteIntent(ContentAccess::EExecute);
  47. if(result == KErrNone)
  48. {
  49. intentExecuted = ETrue;
  50. result = CAF_data->Read(buffer);
  51. if(result == KErrNone)
  52. {
  53. Mem::Copy((char*)data,buffer.Ptr(),buffer.Length() );
  54. result = buffer.Length();
  55. }
  56. else
  57. RDebug::Print(_L("DRMFilePrivate::read ContentAccess::CData::Read error %d"), result);
  58. }
  59. buffer.Close();
  60. }
  61. }
  62. return result;
  63. }
  64. void DRMFilePrivate::close()
  65. {
  66. if(CAF_data!=NULL)
  67. {
  68. delete CAF_data;
  69. CAF_data = NULL;
  70. }
  71. if(CAF_file!=NULL)
  72. {
  73. delete CAF_file;
  74. CAF_file = NULL;
  75. }
  76. }
  77. int DRMFilePrivate::openL(const TDesC& fileName)
  78. {
  79. int result = KErrNone;
  80. if((CAF_file!=NULL) || (CAF_data!=NULL))
  81. return KErrInUse;
  82. TFileName _fileName;
  83. CAF_file = CContent::NewL(fileName);
  84. RStreamablePtrArray <CEmbeddedObject> myArray;
  85. CleanupClosePushL(myArray);
  86. // Get an array of the embedded objects within the current container in the file
  87. CAF_file->GetEmbeddedObjectsL(myArray);
  88. if(myArray.Count() > 0)
  89. {
  90. // open the first object, multiple objects per container are not yet supported
  91. CAF_data = CAF_file->OpenContentL(ContentAccess::EExecute, myArray[0]->UniqueId());
  92. }
  93. else
  94. {
  95. // no objects found
  96. result = KErrNotFound;
  97. }
  98. CleanupStack::PopAndDestroy(&myArray);
  99. return result;
  100. }
  101. int DRMFilePrivate::size()
  102. {
  103. int size = 0;
  104. if(CAF_data!=NULL)
  105. TRAP_IGNORE(CAF_data->DataSizeL(size));
  106. return size;
  107. }
  108. #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  109. qint64 DRMFilePrivate::size64()
  110. {
  111. TInt64 size = 0;
  112. if(CAF_data!=NULL)
  113. TRAP_IGNORE(CAF_data->DataSize64L(size));
  114. return size;
  115. }
  116. #endif
  117. bool DRMFilePrivate::isDRMError(int error)
  118. {
  119. bool result = false;
  120. if(KErrCA_LowerLimit <= error && error <= KErrCA_UpperLimit)
  121. result = true;
  122. return result;
  123. }