drmfile_p.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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), CAF_data(NULL)
  19. {
  20. }
  21. DRMFilePrivate::~DRMFilePrivate()
  22. {
  23. close();
  24. }
  25. int DRMFilePrivate::open(const QString & fileName)
  26. {
  27. int result = KErrNone;
  28. QString symbianFileName;
  29. symbianFileName = fileName;
  30. QChar find('/');
  31. QChar replace('\\');
  32. symbianFileName.replace(find,replace,Qt::CaseInsensitive);
  33. TPtrC16 fileName_TextPtr(reinterpret_cast<const TUint16*>(symbianFileName.utf16()));
  34. TRAPD(panic_code, result = openL(fileName_TextPtr))
  35. if(panic_code != KErrNone)
  36. result = panic_code;
  37. else
  38. intentExecuted = EFalse;
  39. return result;
  40. }
  41. int DRMFilePrivate::read(uchar*& data, int length)
  42. {
  43. int result = KErrNone;
  44. data = NULL;
  45. while(true)
  46. {
  47. if(CAF_data == NULL)
  48. {
  49. result = KErrBadHandle;
  50. break;
  51. }
  52. RBuf8 buffer;
  53. if(!length)
  54. TRAP(result, CAF_data->DataSizeL(length));
  55. if(result != KErrNone)
  56. break;
  57. length++; //to be able use PtrZ() call
  58. TRAP (result, buffer.CreateL(length));
  59. if(result != KErrNone)
  60. break;
  61. if(!intentExecuted)
  62. result = CAF_data->ExecuteIntent(ContentAccess::EExecute);
  63. if(result != KErrNone)
  64. break;
  65. intentExecuted = ETrue;
  66. result = CAF_data->Read(buffer);
  67. if(result != KErrNone)
  68. break;
  69. result = length;
  70. uchar* ptr = const_cast<uchar*>(buffer.PtrZ()); //give up ownership from RBuf8
  71. data = ptr;
  72. break;
  73. }
  74. if(result < KErrNone)
  75. RDebug::Print(_L("DRMFilePrivate::read ContentAccess::CData::Read error %d"), result);
  76. return result;
  77. }
  78. void DRMFilePrivate::close()
  79. {
  80. if(CAF_data!=NULL)
  81. {
  82. delete CAF_data;
  83. CAF_data = NULL;
  84. }
  85. if(CAF_file!=NULL)
  86. {
  87. delete CAF_file;
  88. CAF_file = NULL;
  89. }
  90. }
  91. int DRMFilePrivate::openL(const TDesC& fileName)
  92. {
  93. int result = KErrNone;
  94. if((CAF_file!=NULL) || (CAF_data!=NULL))
  95. return KErrInUse;
  96. CAF_file = CContent::NewL(fileName);
  97. RStreamablePtrArray <CEmbeddedObject> myArray;
  98. CleanupClosePushL(myArray);
  99. // Get an array of the embedded objects within the current container in the file
  100. CAF_file->GetEmbeddedObjectsL(myArray);
  101. if(myArray.Count() > 0)
  102. {
  103. // open the first object, multiple objects per container are not yet supported
  104. CAF_data = CAF_file->OpenContentL(ContentAccess::EExecute, myArray[0]->UniqueId());
  105. }
  106. else
  107. {
  108. // no objects found
  109. result = KErrNotFound;
  110. }
  111. CleanupStack::PopAndDestroy(&myArray);
  112. return result;
  113. }
  114. int DRMFilePrivate::size()
  115. {
  116. int size = 0;
  117. if(CAF_data!=NULL)
  118. TRAP_IGNORE(CAF_data->DataSizeL(size));
  119. return size;
  120. }
  121. #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  122. qint64 DRMFilePrivate::size64()
  123. {
  124. TInt64 size = 0;
  125. if(CAF_data!=NULL)
  126. TRAP_IGNORE(CAF_data->DataSize64L(size));
  127. return size;
  128. }
  129. #endif
  130. bool DRMFilePrivate::isDRMError(int error)
  131. {
  132. bool result = false;
  133. if(KErrCA_LowerLimit <= error && error <= KErrCA_UpperLimit)
  134. result = true;
  135. return result;
  136. }