PageRenderTime 37ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpostcard.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 155 lines | 94 code | 23 blank | 38 comment | 3 complexity | c952d0908bec916966d43bc2cf80195f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpostcard.cpp
  3. * @brief Sending postcards.
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, 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 "llviewerprecompiledheaders.h"
  27. #include "llpostcard.h"
  28. #include "llvfile.h"
  29. #include "llvfs.h"
  30. #include "llviewerregion.h"
  31. #include "message.h"
  32. #include "llagent.h"
  33. #include "llassetuploadresponders.h"
  34. ///////////////////////////////////////////////////////////////////////////////
  35. // misc
  36. static void postcard_upload_callback(const LLUUID& asset_id, void *user_data, S32 result, LLExtStat ext_status)
  37. {
  38. LLSD* postcard_data = (LLSD*)user_data;
  39. if (result)
  40. {
  41. // TODO: display the error messages in UI
  42. llwarns << "Failed to send postcard: " << LLAssetStorage::getErrorString(result) << llendl;
  43. LLPostCard::reportPostResult(false);
  44. }
  45. else
  46. {
  47. // only create the postcard once the upload succeeds
  48. // request the postcard
  49. const LLSD& data = *postcard_data;
  50. LLMessageSystem* msg = gMessageSystem;
  51. msg->newMessage("SendPostcard");
  52. msg->nextBlock("AgentData");
  53. msg->addUUID("AgentID", gAgent.getID());
  54. msg->addUUID("SessionID", gAgent.getSessionID());
  55. msg->addUUID("AssetID", data["asset-id"].asUUID());
  56. msg->addVector3d("PosGlobal", LLVector3d(data["pos-global"]));
  57. msg->addString("To", data["to"]);
  58. msg->addString("From", data["from"]);
  59. msg->addString("Name", data["name"]);
  60. msg->addString("Subject", data["subject"]);
  61. msg->addString("Msg", data["msg"]);
  62. msg->addBOOL("AllowPublish", FALSE);
  63. msg->addBOOL("MaturePublish", FALSE);
  64. gAgent.sendReliableMessage();
  65. LLPostCard::reportPostResult(true);
  66. }
  67. delete postcard_data;
  68. }
  69. ///////////////////////////////////////////////////////////////////////////////
  70. // LLPostcardSendResponder
  71. class LLPostcardSendResponder : public LLAssetUploadResponder
  72. {
  73. LOG_CLASS(LLPostcardSendResponder);
  74. public:
  75. LLPostcardSendResponder(const LLSD &post_data,
  76. const LLUUID& vfile_id,
  77. LLAssetType::EType asset_type):
  78. LLAssetUploadResponder(post_data, vfile_id, asset_type)
  79. {
  80. }
  81. /*virtual*/ void uploadComplete(const LLSD& content)
  82. {
  83. llinfos << "Postcard sent" << llendl;
  84. LL_DEBUGS("Snapshots") << "content: " << content << llendl;
  85. LLPostCard::reportPostResult(true);
  86. }
  87. /*virtual*/ void uploadFailure(const LLSD& content)
  88. {
  89. llwarns << "Sending postcard failed: " << content << llendl;
  90. LLPostCard::reportPostResult(false);
  91. }
  92. };
  93. ///////////////////////////////////////////////////////////////////////////////
  94. // LLPostCard
  95. LLPostCard::result_callback_t LLPostCard::mResultCallback;
  96. // static
  97. void LLPostCard::send(LLPointer<LLImageFormatted> image, const LLSD& postcard_data)
  98. {
  99. LLTransactionID transaction_id;
  100. LLAssetID asset_id;
  101. transaction_id.generate();
  102. asset_id = transaction_id.makeAssetID(gAgent.getSecureSessionID());
  103. LLVFile::writeFile(image->getData(), image->getDataSize(), gVFS, asset_id, LLAssetType::AT_IMAGE_JPEG);
  104. // upload the image
  105. std::string url = gAgent.getRegion()->getCapability("SendPostcard");
  106. if (!url.empty())
  107. {
  108. llinfos << "Sending postcard via capability" << llendl;
  109. // the capability already encodes: agent ID, region ID
  110. LL_DEBUGS("Snapshots") << "url: " << url << llendl;
  111. LL_DEBUGS("Snapshots") << "body: " << postcard_data << llendl;
  112. LL_DEBUGS("Snapshots") << "data size: " << image->getDataSize() << llendl;
  113. LLHTTPClient::post(url, postcard_data,
  114. new LLPostcardSendResponder(postcard_data, asset_id, LLAssetType::AT_IMAGE_JPEG));
  115. }
  116. else
  117. {
  118. llinfos << "Sending postcard" << llendl;
  119. LLSD* data = new LLSD(postcard_data);
  120. (*data)["asset-id"] = asset_id;
  121. gAssetStorage->storeAssetData(transaction_id, LLAssetType::AT_IMAGE_JPEG,
  122. &postcard_upload_callback, (void *)data, FALSE);
  123. }
  124. }
  125. // static
  126. void LLPostCard::reportPostResult(bool ok)
  127. {
  128. if (mResultCallback)
  129. {
  130. mResultCallback(ok);
  131. }
  132. }