drmfile_native_symbian.cpp 3.9 KB

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