From ec998b4c6efee0ddba48481dfba630e18c53a29c Mon Sep 17 00:00:00 2001
From: Rider Linden <rider@lindenlab.com>
Date: Thu, 3 Sep 2015 16:14:40 -0700
Subject: [PATCH] Region experience allow/disallow.

---
 indra/llmessage/llexperiencecache.cpp | 47 ++++++++++++++++++++++
 indra/llmessage/llexperiencecache.h   |  7 +++-
 indra/newview/llfloaterregioninfo.cpp | 58 +++++++++------------------
 indra/newview/llfloaterregioninfo.h   |  2 +
 4 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp
index 233b15dcdd3..af0bae02282 100644
--- a/indra/llmessage/llexperiencecache.cpp
+++ b/indra/llmessage/llexperiencecache.cpp
@@ -657,6 +657,7 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda
     if (url.empty())
     {
         LL_WARNS("ExperienceCache") << "No Group Experiences capability" << LL_ENDL;
+        return;
     }
 
     url += "?" + groupId.asString();
@@ -676,6 +677,52 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda
     fn(experienceIds);
 }
 
+//-------------------------------------------------------------------------
+void LLExperienceCache::getRegionExperiences(CapabilityQuery_t regioncaps, ExperienceGetFn_t fn)
+{
+    LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Region Experiences",
+        boost::bind(&LLExperienceCache::regionExperiencesCoro, this, _1, regioncaps, false, LLSD(), fn));
+}
+
+void LLExperienceCache::setRegionExperiences(CapabilityQuery_t regioncaps, const LLSD &experiences, ExperienceGetFn_t fn)
+{
+    LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Region Experiences",
+        boost::bind(&LLExperienceCache::regionExperiencesCoro, this, _1, regioncaps, true, experiences, fn));
+}
+
+void LLExperienceCache::regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter,
+    CapabilityQuery_t regioncaps, bool update, LLSD experiences, ExperienceGetFn_t fn)
+{
+    LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest());
+
+    // search for experiences owned by the current group
+    std::string url = regioncaps("RegionExperiences");
+    if (url.empty())
+    {
+        LL_WARNS("ExperienceCache") << "No Region Experiences capability" << LL_ENDL;
+        return;
+    }
+
+    LLSD result;
+    if (update)
+        result = httpAdapter->postAndYield(httpRequest, url, experiences);
+    else
+        result = httpAdapter->getAndYield(httpRequest, url);
+
+    LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+    LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+    if (!status)
+    {
+//      fn(LLSD());
+        return;
+    }
+
+    result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
+    fn(result);
+
+}
+
 //=========================================================================
 void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys)
 {
diff --git a/indra/llmessage/llexperiencecache.h b/indra/llmessage/llexperiencecache.h
index 76cbbb6ed6b..3e3ae538f9d 100644
--- a/indra/llmessage/llexperiencecache.h
+++ b/indra/llmessage/llexperiencecache.h
@@ -67,6 +67,11 @@ class LLExperienceCache: public LLSingleton < LLExperienceCache >
     void findExperienceByName(const std::string text, int page, ExperienceGetFn_t fn);
     void getGroupExperiences(const LLUUID &groupId, ExperienceGetFn_t fn);
 
+    // the Get/Set Region Experiences take a CapabilityQuery to get the capability since 
+    // the region being queried may not be the region that the agent is standing on.
+    void getRegionExperiences(CapabilityQuery_t regioncaps, ExperienceGetFn_t fn);
+    void setRegionExperiences(CapabilityQuery_t regioncaps, const LLSD &experiences, ExperienceGetFn_t fn);
+
     //-------------------------------------------
     static const std::string NAME;			// "name"
     static const std::string EXPERIENCE_ID;	// "public_id"
@@ -139,7 +144,7 @@ class LLExperienceCache: public LLSingleton < LLExperienceCache >
     void fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, LLUUID, LLUUID, ExperienceGetFn_t);
     void findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, std::string, int, ExperienceGetFn_t);
     void getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, LLUUID , ExperienceGetFn_t);
-
+    void regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, CapabilityQuery_t regioncaps, bool update, LLSD experiences, ExperienceGetFn_t fn);
     void bootstrap(const LLSD& legacyKeys, int initialExpiration);
     void exportFile(std::ostream& ostr) const;
     void importFile(std::istream& istr);
diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp
index 37e934429f1..a166dda8ee6 100755
--- a/indra/newview/llfloaterregioninfo.cpp
+++ b/indra/newview/llfloaterregioninfo.cpp
@@ -3586,29 +3586,6 @@ void LLPanelRegionExperiences::processResponse( const LLSD& content )
 
 }
 
-
-class LLRegionExperienceResponder : public LLHTTPClient::Responder
-{
-public:
-	typedef boost::function<void (const LLSD&)> callback_t;
-
-	callback_t mCallback;
-
-	LLRegionExperienceResponder(callback_t callback) : mCallback(callback) { }
-
-protected:
-	/*virtual*/ void httpSuccess()
-	{
-		mCallback(getContent());
-	}
-
-	/*virtual*/ void httpFailure()
-	{
-		LL_WARNS() << "experience responder failed [status:" << getStatus() << "]: " << getContent() << LL_ENDL;
-	}
-};
-
-
 // Used for both access add and remove operations, depending on the flag
 // passed in (ESTATE_EXPERIENCE_ALLOWED_ADD, ESTATE_EXPERIENCE_ALLOWED_REMOVE, etc.)
 // static
@@ -3691,6 +3668,13 @@ void LLPanelRegionExperiences::infoCallback(LLHandle<LLPanelRegionExperiences> h
 	}
 }
 
+/*static*/
+std::string LLPanelRegionExperiences::regionCapabilityQuery(LLViewerRegion* region, const std::string &cap)
+{
+    // region->getHandle()  How to get a region * from a handle?
+
+    return region->getCapability(cap);
+}
 
 bool LLPanelRegionExperiences::refreshFromRegion(LLViewerRegion* region)
 {
@@ -3715,13 +3699,10 @@ bool LLPanelRegionExperiences::refreshFromRegion(LLViewerRegion* region)
 	mTrusted->loading();
 	mTrusted->setReadonly(!allow_modify);
 
-	std::string url = region->getCapability("RegionExperiences");
-	if (!url.empty())
-	{
-		LLHTTPClient::get(url, new LLRegionExperienceResponder(boost::bind(&LLPanelRegionExperiences::infoCallback, 
-			getDerivedHandle<LLPanelRegionExperiences>(), _1)));
-	}
-	return LLPanelRegionInfo::refreshFromRegion(region);
+    LLExperienceCache::getInstance()->getRegionExperiences(boost::bind(&LLPanelRegionExperiences::regionCapabilityQuery, region, _1),
+        boost::bind(&LLPanelRegionExperiences::infoCallback, getDerivedHandle<LLPanelRegionExperiences>(), _1));
+
+    return LLPanelRegionInfo::refreshFromRegion(region);
 }
 
 LLSD LLPanelRegionExperiences::addIds(LLPanelExperienceListEditor* panel)
@@ -3739,18 +3720,15 @@ LLSD LLPanelRegionExperiences::addIds(LLPanelExperienceListEditor* panel)
 BOOL LLPanelRegionExperiences::sendUpdate()
 {
 	LLViewerRegion* region = gAgent.getRegion();
-	std::string url = region->getCapability("RegionExperiences");
-	if (!url.empty())
-	{
-		LLSD content;
 
-		content["allowed"]=addIds(mAllowed);
-		content["blocked"]=addIds(mBlocked);
-		content["trusted"]=addIds(mTrusted);
+    LLSD content;
 
-		LLHTTPClient::post(url, content, new LLRegionExperienceResponder(boost::bind(&LLPanelRegionExperiences::infoCallback, 
-			getDerivedHandle<LLPanelRegionExperiences>(), _1)));
-	}
+	content["allowed"]=addIds(mAllowed);
+	content["blocked"]=addIds(mBlocked);
+	content["trusted"]=addIds(mTrusted);
+
+    LLExperienceCache::getInstance()->setRegionExperiences(boost::bind(&LLPanelRegionExperiences::regionCapabilityQuery, region, _1),
+        content, boost::bind(&LLPanelRegionExperiences::infoCallback, getDerivedHandle<LLPanelRegionExperiences>(), _1));
 
 	return TRUE;
 }
diff --git a/indra/newview/llfloaterregioninfo.h b/indra/newview/llfloaterregioninfo.h
index 90f115faaf3..3c74618fffc 100755
--- a/indra/newview/llfloaterregioninfo.h
+++ b/indra/newview/llfloaterregioninfo.h
@@ -479,6 +479,8 @@ class LLPanelRegionExperiences : public LLPanelRegionInfo
 private:
 	void refreshRegionExperiences();
 
+    static std::string regionCapabilityQuery(LLViewerRegion* region, const std::string &cap);
+
 	LLPanelExperienceListEditor* setupList(const char* control_name, U32 add_id, U32 remove_id);
 	static LLSD addIds( LLPanelExperienceListEditor* panel );
 
-- 
GitLab