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

/indra/llmessage/llhttpsender.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 95 lines | 52 code | 11 blank | 32 comment | 4 complexity | c4e7cb8107e33adbba6f107307ecd8b2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llhttpsender.cpp
  3. * @brief Abstracts details of sending messages via HTTP.
  4. *
  5. * $LicenseInfo:firstyear=2007&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 "llhttpsender.h"
  28. #include <map>
  29. #include <sstream>
  30. #include "llhost.h"
  31. #include "llsd.h"
  32. namespace
  33. {
  34. typedef std::map<LLHost, LLHTTPSender*> SenderMap;
  35. static SenderMap senderMap;
  36. static LLHTTPSender* defaultSender = new LLHTTPSender();
  37. }
  38. //virtual
  39. LLHTTPSender::~LLHTTPSender()
  40. {
  41. }
  42. //virtual
  43. void LLHTTPSender::send(const LLHost& host, const std::string& name,
  44. const LLSD& body,
  45. LLHTTPClient::ResponderPtr response) const
  46. {
  47. // Default implementation inserts sender, message and sends HTTP POST
  48. std::ostringstream stream;
  49. stream << "http://" << host << "/trusted-message/" << name;
  50. llinfos << "LLHTTPSender::send: POST to " << stream.str() << llendl;
  51. LLHTTPClient::post(stream.str(), body, response);
  52. }
  53. //static
  54. void LLHTTPSender::setSender(const LLHost& host, LLHTTPSender* sender)
  55. {
  56. llinfos << "LLHTTPSender::setSender " << host << llendl;
  57. senderMap[host] = sender;
  58. }
  59. //static
  60. const LLHTTPSender& LLHTTPSender::getSender(const LLHost& host)
  61. {
  62. SenderMap::const_iterator iter = senderMap.find(host);
  63. if(iter == senderMap.end())
  64. {
  65. return *defaultSender;
  66. }
  67. return *(iter->second);
  68. }
  69. //static
  70. void LLHTTPSender::clearSender(const LLHost& host)
  71. {
  72. SenderMap::iterator iter = senderMap.find(host);
  73. if(iter != senderMap.end())
  74. {
  75. delete iter->second;
  76. senderMap.erase(iter);
  77. }
  78. }
  79. //static
  80. void LLHTTPSender::setDefaultSender(LLHTTPSender* sender)
  81. {
  82. delete defaultSender;
  83. defaultSender = sender;
  84. }