llxfer_mem.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * @file llxfer_mem.cpp
  3. * @brief implementation of LLXfer_Mem class for a single xfer
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llxfer_mem.h"
  34. #include "llmath.h"
  35. LLXfer_Mem::LLXfer_Mem()
  36. : LLXfer(-1)
  37. {
  38. init();
  39. }
  40. LLXfer_Mem::~LLXfer_Mem()
  41. {
  42. cleanup();
  43. }
  44. void LLXfer_Mem::init()
  45. {
  46. mRemoteFilename.clear();
  47. mRemotePath = LL_PATH_NONE;
  48. mDeleteRemoteOnCompletion = false;
  49. }
  50. void LLXfer_Mem::cleanup()
  51. {
  52. LLXfer::cleanup();
  53. }
  54. void LLXfer_Mem::setXferSize(S32 xfer_size)
  55. {
  56. mXferSize = xfer_size;
  57. delete[] mBuffer;
  58. mBuffer = new char[xfer_size];
  59. mBufferLength = 0;
  60. mBufferStartOffset = 0;
  61. mBufferContainsEOF = true;
  62. }
  63. S32 LLXfer_Mem::startSend(U64 xfer_id, const LLHost& remote_host)
  64. {
  65. S32 retval = LL_ERR_NOERR; // presume success
  66. if (mXferSize <= 0)
  67. {
  68. return LL_ERR_FILE_EMPTY;
  69. }
  70. mRemoteHost = remote_host;
  71. mID = xfer_id;
  72. mPacketNum = -1;
  73. mStatus = e_LL_XFER_PENDING;
  74. return retval;
  75. }
  76. S32 LLXfer_Mem::processEOF()
  77. {
  78. S32 retval = 0;
  79. mStatus = e_LL_XFER_COMPLETE;
  80. llinfos << "xfer complete: " << getFileName() << llendl;
  81. if (mCallback)
  82. {
  83. mCallback((void*)mBuffer, mBufferLength, mCallbackDataHandle,
  84. mCallbackResult, LLExtStat::NONE);
  85. }
  86. return retval;
  87. }
  88. S32 LLXfer_Mem::initializeRequest(U64 xfer_id,
  89. const std::string& remote_filename,
  90. ELLPath remote_path,
  91. const LLHost& remote_host,
  92. bool delete_remote_on_completion,
  93. void (*callback)(void*, S32, void**, S32, LLExtStat),
  94. void** user_data)
  95. {
  96. S32 retval = 0; // presume success
  97. mRemoteHost = remote_host;
  98. // create a temp filename string using a GUID
  99. mID = xfer_id;
  100. mCallback = callback;
  101. mCallbackDataHandle = user_data;
  102. mCallbackResult = LL_ERR_NOERR;
  103. mRemoteFilename = remote_filename;
  104. mRemotePath = remote_path;
  105. mDeleteRemoteOnCompletion = delete_remote_on_completion;
  106. llinfos << "Requesting file: " << remote_filename << llendl;
  107. if (mBuffer)
  108. {
  109. delete[] mBuffer;
  110. mBuffer = NULL;
  111. }
  112. mBufferLength = 0;
  113. mPacketNum = 0;
  114. mStatus = e_LL_XFER_PENDING;
  115. return retval;
  116. }
  117. S32 LLXfer_Mem::startDownload()
  118. {
  119. S32 retval = 0; // presume success
  120. LLMessageSystem* msg = gMessageSystemp;
  121. msg->newMessageFast(_PREHASH_RequestXfer);
  122. msg->nextBlockFast(_PREHASH_XferID);
  123. msg->addU64Fast(_PREHASH_ID, mID);
  124. msg->addStringFast(_PREHASH_Filename, mRemoteFilename);
  125. msg->addU8("FilePath", (U8) mRemotePath);
  126. msg->addBool("DeleteOnCompletion", mDeleteRemoteOnCompletion);
  127. msg->addBool("UseBigPackets", mChunkSize == LL_XFER_LARGE_PAYLOAD);
  128. msg->addUUIDFast(_PREHASH_VFileID, LLUUID::null);
  129. msg->addS16Fast(_PREHASH_VFileType, -1);
  130. msg->sendReliable(mRemoteHost);
  131. mStatus = e_LL_XFER_IN_PROGRESS;
  132. return retval;
  133. }
  134. U32 LLXfer_Mem::getXferTypeTag()
  135. {
  136. return LLXfer::XFER_MEM;
  137. }