From a8f663b3b2e60daf2b6bc1f8900729ef304f0029 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Fri, 4 Mar 2022 15:44:31 -0500
Subject: [PATCH] More opensim code

---
 indra/newview/llviewerregion.cpp | 55 ++++++++++++++++++++++++++++++++
 indra/newview/llviewerregion.h   |  7 ++++
 2 files changed, 62 insertions(+)

diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 902ff453f3f..fa98d715256 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -3175,6 +3175,30 @@ S32 LLViewerRegion::getNumSeedCapRetries()
 
 void LLViewerRegion::setCapability(const std::string& name, const std::string& url)
 {
+	bool add_to_mapping = true;
+
+	std::string base_url = get_base_cap_url(url);
+	//we need a multimap, since CERTAIN PEOPLE use non-unique URIs for each Cap.
+	//let's check if this cap name is already registered for this URI
+	//TODO: Better represented as map of sets
+	if(mCapURLMappings.count(base_url) > 0)
+	{
+		auto iter = mCapURLMappings.find(base_url);
+
+		while(iter != mCapURLMappings.cend())
+		{
+			if(iter->second == name)
+			{
+				add_to_mapping = false;
+				break;
+			}
+			++iter;
+		}
+	}
+
+	if(add_to_mapping)
+		mCapURLMappings.insert(std::pair<std::string, std::string>(base_url, name));
+
 	if(name == "EventQueueGet")
 	{
 		delete mImpl->mEventPoll;
@@ -3298,6 +3322,37 @@ bool LLViewerRegion::isCapabilityAvailable(std::string_view name) const
 	return true;
 }
 
+std::set<std::string> LLViewerRegion::getCapURLNames(const std::string &cap_url)
+{
+	std::set<std::string> url_capnames;
+	if(mCapURLMappings.count(cap_url) > 0)
+	{
+		auto range = mCapURLMappings.equal_range(cap_url);
+
+		for (url_mapping_t::iterator iter = range.first; iter != range.second; ++iter)
+		{
+			url_capnames.insert(iter->second);
+		}
+	}
+	return url_capnames;
+}
+
+
+bool LLViewerRegion::isCapURLMapped(const std::string &cap_url)
+{
+	return (mCapURLMappings.count(cap_url) > 0);
+}
+
+std::set<std::string> LLViewerRegion::getAllCaps()
+{
+	std::set<std::string> url_capnames;
+	for (auto& capability : mImpl->mCapabilities)
+    {
+		url_capnames.insert(capability.first);
+	}
+	return url_capnames;
+}
+
 bool LLViewerRegion::capabilitiesReceived() const
 {
 	return mCapabilitiesReceived;
diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h
index bc368d6bcdc..ce62c20411f 100644
--- a/indra/newview/llviewerregion.h
+++ b/indra/newview/llviewerregion.h
@@ -269,6 +269,10 @@ class LLViewerRegion final : public LLCapabilityProvider // implements this inte
     const std::string& getCapabilityDebug(std::string_view name) const;
 
 
+	virtual std::set<std::string> getCapURLNames(const std::string& cap_url);
+	virtual bool isCapURLMapped(const std::string& cap_url);
+	virtual std::set<std::string> getAllCaps();
+
 	// has region received its final (not seed) capability list?
 	bool capabilitiesReceived() const;
 	void setCapabilitiesReceived(bool received);
@@ -613,6 +617,9 @@ class LLViewerRegion final : public LLCapabilityProvider // implements this inte
 
 	mutable tex_matrix_t mWorldMapTiles;
 	absl::flat_hash_set<std::string> mGodNames;
+
+	using url_mapping_t = std::unordered_multimap<std::string, std::string>;
+	url_mapping_t mCapURLMappings;
 };
 
 inline BOOL LLViewerRegion::getRegionProtocol(U64 protocol) const
-- 
GitLab