From f4186b6d3d45259c83fa1b13db25abcd34f227a9 Mon Sep 17 00:00:00 2001
From: Rick Pasetto <rick@lindenlab.com>
Date: Mon, 9 Nov 2009 18:17:42 -0800
Subject: [PATCH] PARTIAL FIX (workaround) DEV-41949:
 LLMediaEntry::setWhitelist() and LLMediaEntry::asLLSD() have a contract
 conflict Review #31

So, here's what was happening, briefly:

- LLMediaEntry::setWhitelist() would be a no-op if given an LLSD that did not have a WHITELIST_KEY
- LLMediaEntry::asLLSD() would render the LLMediaEntry *without* a WHITELIST_KEY if the whitelist was empty

Therefore, when the viewer marshalled an LLMediaEntry for the server, it would send it without a WHITELIST_KEY. When the server got it, it would not erase the last value.

This is actually a workaround: it patches asLLSD() with an LLSD::emptyArray() if the key is not there. However, this should be fixed on the server: in either or both of the following ways:

1) LLMediaEntry::setWhitelist() should not be a no-op if the LLSD has no WHITELIST_KEY: it should erase the whitelist
2) LLMediaEntry::asLLSD() should render an empty whitelist in WHITELIST_KEY as an empty array

Note that both could be done and still work.

A unit test should and will be written next.
---
 indra/newview/llpanelmediasettingssecurity.cpp | 4 +++-
 indra/newview/llvovolume.cpp                   | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llpanelmediasettingssecurity.cpp b/indra/newview/llpanelmediasettingssecurity.cpp
index 611293f3e20..bec2494eac9 100644
--- a/indra/newview/llpanelmediasettingssecurity.cpp
+++ b/indra/newview/llpanelmediasettingssecurity.cpp
@@ -215,7 +215,9 @@ void LLPanelMediaSettingsSecurity::getValues( LLSD &fill_me_in )
     // iterate over white list and extract items
     std::vector< LLScrollListItem* > white_list_items = mWhiteListList->getAllData();
     std::vector< LLScrollListItem* >::iterator iter = white_list_items.begin();
-    fill_me_in.erase(LLMediaEntry::WHITELIST_KEY);
+	// *NOTE: need actually set the key to be an emptyArray(), or the merge
+	// we do with this LLSD will think there's nothing to change.
+    fill_me_in[LLMediaEntry::WHITELIST_KEY] = LLSD::emptyArray();
     while( iter != white_list_items.end() )
     {
         std::string white_list_url = (*iter)->getValue().asString();
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 021fc746488..3803c65e749 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -108,6 +108,11 @@ class LLMediaDataClientObjectImpl : public LLMediaDataClientObject
 				if (te->getMediaData() != NULL)
 				{
 					result = te->getMediaData()->asLLSD();
+					// XXX HACK: workaround bug in asLLSD() where whitelist is not set properly
+					if (!result.has(LLMediaEntry::WHITELIST_KEY))
+					{
+						result[LLMediaEntry::WHITELIST_KEY] = LLSD::emptyArray();
+					}
 				}
 			}
 			return result;
-- 
GitLab