llproductinforequest.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file llproductinforequest.cpp
  3. * @author Kent Quirk
  4. * @brief Get region type descriptions (translation from SKU to description)
  5. *
  6. * $LicenseInfo:firstyear=2009&license=viewergpl$
  7. *
  8. * Copyright (c) 2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llproductinforequest.h"
  35. #include "llcorehttputil.h"
  36. #include "lltrans.h"
  37. #include "llagent.h" // for gAgent
  38. LLProductInfoRequestManager::LLProductInfoRequestManager()
  39. : mSkuDescriptions()
  40. {
  41. }
  42. void LLProductInfoRequestManager::initSingleton()
  43. {
  44. const std::string& url = gAgent.getRegionCapability("ProductInfoRequest");
  45. if (url.empty())
  46. {
  47. return;
  48. }
  49. gCoros.launch("LLProductInfoRequestManager::getLandDescriptionsCoro",
  50. boost::bind(&LLProductInfoRequestManager::getLandDescriptionsCoro,
  51. this, url));
  52. }
  53. std::string LLProductInfoRequestManager::getDescriptionForSku(const std::string& sku)
  54. {
  55. // The description LLSD is an array of maps; each array entry has a map
  56. // with 3 fields: description, name, and sku
  57. for (LLSD::array_const_iterator it = mSkuDescriptions.beginArray(),
  58. end = mSkuDescriptions.endArray();
  59. it != end; ++it)
  60. {
  61. LL_DEBUGS("ProductInfoRequestManager") << (*it)["sku"].asString()
  62. << " = "
  63. << (*it)["description"].asString()
  64. << LL_ENDL;
  65. if ((*it)["sku"].asString() == sku)
  66. {
  67. return (*it)["description"].asString();
  68. }
  69. }
  70. return LLTrans::getString("unknown");
  71. }
  72. void LLProductInfoRequestManager::getLandDescriptionsCoro(const std::string& url)
  73. {
  74. LLCoreHttpUtil::HttpCoroutineAdapter adapter("ProductInfoRequest");
  75. LLSD result = adapter.getAndSuspend(url);
  76. LLCore::HttpStatus status =
  77. LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(result);
  78. if (!status)
  79. {
  80. llwarns << "Failure to fetch land SKU: " << status.toString()
  81. << llendl;
  82. }
  83. else if (result.has(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT) &&
  84. result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT].isArray())
  85. {
  86. mSkuDescriptions = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT];
  87. }
  88. else
  89. {
  90. llwarns << "Land SKU description response is malformed" << llendl;
  91. }
  92. }