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

/indra/llmessage/llareslistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 97 lines | 44 code | 6 blank | 47 comment | 2 complexity | 5479e5b3753947e31451b55383e32af2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llareslistener.cpp
  3. * @author Nat Goodspeed
  4. * @date 2009-03-18
  5. * @brief Implementation for llareslistener.
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. // Precompiled header
  29. #include "linden_common.h"
  30. // associated header
  31. #include "llareslistener.h"
  32. // STL headers
  33. // std headers
  34. // external library headers
  35. // other Linden headers
  36. #include "llares.h"
  37. #include "llerror.h"
  38. #include "llevents.h"
  39. #include "llsdutil.h"
  40. LLAresListener::LLAresListener(LLAres* llares):
  41. LLEventAPI("LLAres",
  42. "LLAres listener to request DNS operations"),
  43. mAres(llares)
  44. {
  45. // add() every method we want to be able to invoke via this event API.
  46. // Optional last parameter validates expected LLSD request structure.
  47. add("rewriteURI",
  48. "Given [\"uri\"], return on [\"reply\"] an array of alternative URIs.\n"
  49. "On failure, returns an array containing only the original URI, so\n"
  50. "failure case can be processed like success case.",
  51. &LLAresListener::rewriteURI,
  52. LLSD().with("uri", LLSD()).with("reply", LLSD()));
  53. }
  54. /// This UriRewriteResponder subclass packages returned URIs as an LLSD
  55. /// array to send back to the requester.
  56. class UriRewriteResponder: public LLAres::UriRewriteResponder
  57. {
  58. public:
  59. /**
  60. * Specify the request, containing the event pump name on which to send
  61. * the reply.
  62. */
  63. UriRewriteResponder(const LLSD& request):
  64. mReqID(request),
  65. mPumpName(request["reply"])
  66. {}
  67. /// Called by base class with results. This is called in both the
  68. /// success and error cases. On error, the calling logic passes the
  69. /// original URI.
  70. virtual void rewriteResult(const std::vector<std::string>& uris)
  71. {
  72. LLSD result;
  73. for (std::vector<std::string>::const_iterator ui(uris.begin()), uend(uris.end());
  74. ui != uend; ++ui)
  75. {
  76. result.append(*ui);
  77. }
  78. // This call knows enough to avoid trying to insert a map key into an
  79. // LLSD array. It's there so that if, for any reason, we ever decide
  80. // to change the response from array to map, it will Just Start Working.
  81. mReqID.stamp(result);
  82. LLEventPumps::instance().obtain(mPumpName).post(result);
  83. }
  84. private:
  85. LLReqID mReqID;
  86. const std::string mPumpName;
  87. };
  88. void LLAresListener::rewriteURI(const LLSD& data)
  89. {
  90. mAres->rewriteURI(data["uri"], new UriRewriteResponder(data));
  91. }