PageRenderTime 34ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/lltransfersourceasset.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 254 lines | 175 code | 41 blank | 38 comment | 15 complexity | dc52c2d7580204aed88cdbdc28dba244 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltransfersourceasset.cpp
  3. * @brief Transfer system for sending an asset.
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "lltransfersourceasset.h"
  28. #include "llerror.h"
  29. #include "message.h"
  30. #include "lldatapacker.h"
  31. #include "lldir.h"
  32. #include "llvfile.h"
  33. LLTransferSourceAsset::LLTransferSourceAsset(const LLUUID &request_id, const F32 priority) :
  34. LLTransferSource(LLTST_ASSET, request_id, priority),
  35. mGotResponse(FALSE),
  36. mCurPos(0)
  37. {
  38. }
  39. LLTransferSourceAsset::~LLTransferSourceAsset()
  40. {
  41. }
  42. void LLTransferSourceAsset::initTransfer()
  43. {
  44. if (gAssetStorage)
  45. {
  46. // *HACK: asset transfers will only be coming from the viewer
  47. // to the simulator. This is subset of assets we allow to be
  48. // simply pulled straight from the asset system.
  49. LLUUID* tidp;
  50. if(LLAssetType::lookupIsAssetFetchByIDAllowed(mParams.getAssetType()))
  51. {
  52. tidp = new LLUUID(getID());
  53. gAssetStorage->getAssetData(
  54. mParams.getAssetID(),
  55. mParams.getAssetType(),
  56. LLTransferSourceAsset::responderCallback,
  57. tidp,
  58. FALSE);
  59. }
  60. else
  61. {
  62. llwarns << "Attempted to request blocked asset "
  63. << mParams.getAssetID() << ":"
  64. << LLAssetType::lookupHumanReadable(mParams.getAssetType())
  65. << llendl;
  66. sendTransferStatus(LLTS_ERROR);
  67. }
  68. }
  69. else
  70. {
  71. llwarns << "Attempted to request asset " << mParams.getAssetID()
  72. << ":" << LLAssetType::lookupHumanReadable(mParams.getAssetType())
  73. << " without an asset system!" << llendl;
  74. sendTransferStatus(LLTS_ERROR);
  75. }
  76. }
  77. F32 LLTransferSourceAsset::updatePriority()
  78. {
  79. return 0.f;
  80. }
  81. LLTSCode LLTransferSourceAsset::dataCallback(const S32 packet_id,
  82. const S32 max_bytes,
  83. U8 **data_handle,
  84. S32 &returned_bytes,
  85. BOOL &delete_returned)
  86. {
  87. //llinfos << "LLTransferSourceAsset::dataCallback" << llendl;
  88. if (!mGotResponse)
  89. {
  90. return LLTS_SKIP;
  91. }
  92. LLVFile vf(gAssetStorage->mVFS, mParams.getAssetID(), mParams.getAssetType(), LLVFile::READ);
  93. if (!vf.getSize())
  94. {
  95. // Something bad happened with the asset request!
  96. return LLTS_ERROR;
  97. }
  98. if (packet_id != mLastPacketID + 1)
  99. {
  100. llerrs << "Can't handle out of order file transfer yet!" << llendl;
  101. }
  102. // grab a buffer from the right place in the file
  103. if (!vf.seek(mCurPos, 0))
  104. {
  105. llwarns << "LLTransferSourceAsset Can't seek to " << mCurPos << " length " << vf.getSize() << llendl;
  106. llwarns << "While sending " << mParams.getAssetID() << llendl;
  107. return LLTS_ERROR;
  108. }
  109. delete_returned = TRUE;
  110. U8 *tmpp = new U8[max_bytes];
  111. *data_handle = tmpp;
  112. if (!vf.read(tmpp, max_bytes)) /* Flawfinder: Ignore */
  113. {
  114. // Read failure, need to deal with it.
  115. delete[] tmpp;
  116. *data_handle = NULL;
  117. returned_bytes = 0;
  118. delete_returned = FALSE;
  119. return LLTS_ERROR;
  120. }
  121. returned_bytes = vf.getLastBytesRead();
  122. mCurPos += returned_bytes;
  123. if (vf.eof())
  124. {
  125. if (!returned_bytes)
  126. {
  127. delete[] tmpp;
  128. *data_handle = NULL;
  129. returned_bytes = 0;
  130. delete_returned = FALSE;
  131. }
  132. return LLTS_DONE;
  133. }
  134. return LLTS_OK;
  135. }
  136. void LLTransferSourceAsset::completionCallback(const LLTSCode status)
  137. {
  138. // No matter what happens, all we want to do is close the vfile if
  139. // we've got it open.
  140. }
  141. void LLTransferSourceAsset::packParams(LLDataPacker& dp) const
  142. {
  143. //llinfos << "LLTransferSourceAsset::packParams" << llendl;
  144. mParams.packParams(dp);
  145. }
  146. BOOL LLTransferSourceAsset::unpackParams(LLDataPacker &dp)
  147. {
  148. //llinfos << "LLTransferSourceAsset::unpackParams" << llendl;
  149. return mParams.unpackParams(dp);
  150. }
  151. void LLTransferSourceAsset::responderCallback(LLVFS *vfs, const LLUUID& uuid, LLAssetType::EType type,
  152. void *user_data, S32 result, LLExtStat ext_status )
  153. {
  154. LLUUID *tidp = ((LLUUID*) user_data);
  155. LLUUID transfer_id = *(tidp);
  156. delete tidp;
  157. tidp = NULL;
  158. LLTransferSourceAsset *tsap = (LLTransferSourceAsset *) gTransferManager.findTransferSource(transfer_id);
  159. if (!tsap)
  160. {
  161. llinfos << "Aborting transfer " << transfer_id << " callback, transfer source went away" << llendl;
  162. return;
  163. }
  164. if (result)
  165. {
  166. llinfos << "AssetStorage: Error " << gAssetStorage->getErrorString(result) << " downloading uuid " << uuid << llendl;
  167. }
  168. LLTSCode status;
  169. tsap->mGotResponse = TRUE;
  170. if (LL_ERR_NOERR == result)
  171. {
  172. // Everything's OK.
  173. LLVFile vf(gAssetStorage->mVFS, uuid, type, LLVFile::READ);
  174. tsap->mSize = vf.getSize();
  175. status = LLTS_OK;
  176. }
  177. else
  178. {
  179. // Uh oh, something bad happened when we tried to get this asset!
  180. switch (result)
  181. {
  182. case LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE:
  183. status = LLTS_UNKNOWN_SOURCE;
  184. break;
  185. default:
  186. status = LLTS_ERROR;
  187. }
  188. }
  189. tsap->sendTransferStatus(status);
  190. }
  191. LLTransferSourceParamsAsset::LLTransferSourceParamsAsset()
  192. : LLTransferSourceParams(LLTST_ASSET),
  193. mAssetType(LLAssetType::AT_NONE)
  194. {
  195. }
  196. void LLTransferSourceParamsAsset::setAsset(const LLUUID &asset_id, const LLAssetType::EType asset_type)
  197. {
  198. mAssetID = asset_id;
  199. mAssetType = asset_type;
  200. }
  201. void LLTransferSourceParamsAsset::packParams(LLDataPacker &dp) const
  202. {
  203. dp.packUUID(mAssetID, "AssetID");
  204. dp.packS32(mAssetType, "AssetType");
  205. }
  206. BOOL LLTransferSourceParamsAsset::unpackParams(LLDataPacker &dp)
  207. {
  208. S32 tmp_at;
  209. dp.unpackUUID(mAssetID, "AssetID");
  210. dp.unpackS32(tmp_at, "AssetType");
  211. mAssetType = (LLAssetType::EType)tmp_at;
  212. return TRUE;
  213. }