PageRenderTime 21ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/lltrustedmessageservice.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 84 lines | 49 code | 7 blank | 28 comment | 5 complexity | 2e4c302d9f94ecd023a8378463e91215 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltrustedmessageservice.cpp
  3. * @brief LLTrustedMessageService implementation
  4. *
  5. * $LicenseInfo:firstyear=2009&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 "lltrustedmessageservice.h"
  28. #include "llhost.h"
  29. #include "llmessageconfig.h"
  30. #include "message.h"
  31. bool LLTrustedMessageService::validate(const std::string& name, LLSD& context)
  32. const
  33. {
  34. return true;
  35. }
  36. void LLTrustedMessageService::post(LLHTTPNode::ResponsePtr response,
  37. const LLSD& context,
  38. const LLSD& input) const
  39. {
  40. std::string name = context["request"]["wildcard"]["message-name"];
  41. std::string senderIP = context["request"]["remote-host"];
  42. std::string senderPort = context["request"]["headers"]
  43. ["x-secondlife-udp-listen-port"];
  44. LLSD message_data;
  45. std::string sender = senderIP + ":" + senderPort;
  46. message_data["sender"] = sender;
  47. message_data["body"] = input;
  48. // untrusted senders should not have access to the trusted message
  49. // service, but this can happen in development, so check and warn
  50. LLMessageConfig::SenderTrust trust =
  51. LLMessageConfig::getSenderTrustedness(name);
  52. if ((trust == LLMessageConfig::TRUSTED ||
  53. (trust == LLMessageConfig::NOT_SET &&
  54. gMessageSystem->isTrustedMessage(name)))
  55. && !gMessageSystem->isTrustedSender(LLHost(sender)))
  56. {
  57. LL_WARNS("Messaging") << "trusted message POST to /trusted-message/"
  58. << name << " from unknown or untrusted sender "
  59. << sender << llendl;
  60. response->status(403, "Unknown or untrusted sender");
  61. }
  62. else
  63. {
  64. gMessageSystem->receivedMessageFromTrustedSender();
  65. if (input.has("binary-template-data"))
  66. {
  67. llinfos << "Dispatching template: " << input << llendl;
  68. // try and send this message using udp dispatch
  69. LLMessageSystem::dispatchTemplate(name, message_data, response);
  70. }
  71. else
  72. {
  73. llinfos << "Dispatching without template: " << input << llendl;
  74. LLMessageSystem::dispatch(name, message_data, response);
  75. }
  76. }
  77. }