From 52cb2aea8667056671b67a3c70eeefd00a061751 Mon Sep 17 00:00:00 2001
From: Kartic Krishnamurthy <drunkensufi@lindenlab.com>
Date: Wed, 8 Aug 2007 00:55:57 +0000
Subject: svn merge -r67131:67483
 svn+ssh://svn/svn/linden/branches/Branch_1-18-1

---
 indra/llmessage/llhttpclient.cpp | 11 +++++++++++
 indra/llmessage/llurlrequest.cpp | 42 ++++++++++++++++++++++++++++++++++++++++
 indra/llmessage/llurlrequest.h   |  6 ++++++
 indra/newview/llhudmanager.cpp   |  5 ++---
 indra/newview/llhudobject.cpp    | 18 ++++++++++++++++-
 indra/newview/llhudobject.h      |  2 ++
 6 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp
index c798e6473c..1763acaf8c 100644
--- a/indra/llmessage/llhttpclient.cpp
+++ b/indra/llmessage/llhttpclient.cpp
@@ -245,6 +245,7 @@ static void request(
 	LLURLRequest *req = new LLURLRequest(method, url);
 	req->requestEncoding("");
 
+    // Insert custom headers is the caller sent any
     if (headers.isMap())
     {
         LLSD::map_const_iterator iter = headers.beginMap();
@@ -253,7 +254,17 @@ static void request(
         for (; iter != end; ++iter)
         {
             std::ostringstream header;
+            //if the header is "Pragma" with no value
+            //the caller intends to force libcurl to drop
+            //the Pragma header it so gratuitously inserts
+            //Before inserting the header, force libcurl
+            //to not use the proxy (read: llurlrequest.cpp)
+            if ((iter->first == "Pragma") && (iter->second.asString() == ""))
+            {
+                req->useProxy(FALSE);
+            }
             header << iter->first << ": " << iter->second.asString() ;
+            llinfos << "header = " << header.str() << llendl;
             req->addHeader(header.str().c_str());
         }
     }
diff --git a/indra/llmessage/llurlrequest.cpp b/indra/llmessage/llurlrequest.cpp
index a7b8573b0d..1008f82c4d 100644
--- a/indra/llmessage/llurlrequest.cpp
+++ b/indra/llmessage/llurlrequest.cpp
@@ -19,6 +19,7 @@
 #include "llpumpio.h"
 #include "llsd.h"
 #include "llstring.h"
+#include "apr-1/apr_env.h"
 
 static const U32 HTTP_STATUS_PIPE_ERROR = 499;
 
@@ -182,6 +183,47 @@ void LLURLRequest::setCallback(LLURLRequestComplete* callback)
 	curl_easy_setopt(mDetail->mCurl, CURLOPT_WRITEHEADER, callback);
 }
 
+// Added to mitigate the effect of libcurl looking
+// for the ALL_PROXY and http_proxy env variables
+// and deciding to insert a Pragma: no-cache
+// header! The only usage of this method at the
+// time of this writing is in llhttpclient.cpp
+// in the request() method, where this method
+// is called with use_proxy = FALSE
+void LLURLRequest::useProxy(bool use_proxy)
+{
+    static char *env_proxy;
+
+    if (use_proxy && (env_proxy == NULL))
+    {
+        apr_status_t status;
+        apr_pool_t* pool;
+        apr_pool_create(&pool, NULL);
+        status = apr_env_get(&env_proxy, "ALL_PROXY", pool);
+        if (status != APR_SUCCESS)
+        {
+            status = apr_env_get(&env_proxy, "http_proxy", pool);
+        }
+        if (status != APR_SUCCESS)
+        {
+           use_proxy = FALSE;
+        }
+        apr_pool_destroy(pool);
+    }
+
+
+    lldebugs << "use_proxy = " << (use_proxy?'Y':'N') << ", env_proxy = " << env_proxy << llendl;
+
+    if (env_proxy && use_proxy)
+    {
+        curl_easy_setopt(mDetail->mCurl, CURLOPT_PROXY, env_proxy);
+    }
+    else
+    {
+        curl_easy_setopt(mDetail->mCurl, CURLOPT_PROXY, "");
+    }
+}
+
 // virtual
 LLIOPipe::EStatus LLURLRequest::handleError(
 	LLIOPipe::EStatus status,
diff --git a/indra/llmessage/llurlrequest.h b/indra/llmessage/llurlrequest.h
index 38c801cb10..0741e557b2 100644
--- a/indra/llmessage/llurlrequest.h
+++ b/indra/llmessage/llurlrequest.h
@@ -154,6 +154,12 @@ public:
 
 	/* @name LLIOPipe virtual implementations
 	 */
+
+    /**
+     * @ brief Turn off (or on) the CURLOPT_PROXY header.
+     */
+    void useProxy(bool use_proxy);
+
 public:
 	/** 
 	 * @brief Give this pipe a chance to handle a generated error
diff --git a/indra/newview/llhudmanager.cpp b/indra/newview/llhudmanager.cpp
index b3e51de317..a3c6523b86 100644
--- a/indra/newview/llhudmanager.cpp
+++ b/indra/newview/llhudmanager.cpp
@@ -107,8 +107,8 @@ void LLHUDManager::cleanupEffects()
 
 LLHUDEffect *LLHUDManager::createViewerEffect(const U8 type, BOOL send_to_sim, BOOL originated_here)
 {
-	// Should assert that this is actually an LLHUDEffect
-	LLHUDEffect *hep = (LLHUDEffect *)LLHUDObject::addHUDObject(type);
+	// SJB: DO NOT USE addHUDObject!!! Not all LLHUDObjects are LLHUDEffects!
+	LLHUDEffect *hep = LLHUDObject::addHUDEffect(type);
 	if (!hep)
 	{
 		return NULL;
@@ -149,7 +149,6 @@ void LLHUDManager::processViewerEffect(LLMessageSystem *mesgsys, void **user_dat
 	{
 		effectp = NULL;
 		LLHUDEffect::getIDType(mesgsys, k, effect_id, effect_type);
-
 		S32 i;
 		for (i = 0; i < gHUDManager->mHUDEffects.count(); i++)
 		{
diff --git a/indra/newview/llhudobject.cpp b/indra/newview/llhudobject.cpp
index 0bcbbbb140..b6a6f14fc9 100644
--- a/indra/newview/llhudobject.cpp
+++ b/indra/newview/llhudobject.cpp
@@ -135,6 +135,22 @@ LLHUDObject *LLHUDObject::addHUDObject(const U8 type)
 	case LL_HUD_CONNECTOR:
 		hud_objectp = new LLHUDConnector(type);
 		break;
+	default:
+		llwarns << "Unknown type of hud object:" << (U32) type << llendl;
+	}
+	if (hud_objectp)
+	{
+		sHUDObjects.push_back(hud_objectp);
+	}
+	return hud_objectp;
+}
+
+LLHUDEffect *LLHUDObject::addHUDEffect(const U8 type)
+{
+	LLHUDEffect *hud_objectp = NULL;
+	
+	switch (type)
+	{
 	case LL_HUD_EFFECT_BEAM:
 		hud_objectp = new LLHUDEffectSpiral(type);
 		((LLHUDEffectSpiral *)hud_objectp)->setDuration(0.7f);
@@ -213,7 +229,7 @@ LLHUDObject *LLHUDObject::addHUDObject(const U8 type)
 		hud_objectp = new LLHUDEffectPointAt(type);
 		break;
 	default:
-		llwarns << "Unknown type of hud object:" << (U32) type << llendl;
+		llwarns << "Unknown type of hud effect:" << (U32) type << llendl;
 	}
 
 	if (hud_objectp)
diff --git a/indra/newview/llhudobject.h b/indra/newview/llhudobject.h
index 3b5589c05b..828af5cf17 100644
--- a/indra/newview/llhudobject.h
+++ b/indra/newview/llhudobject.h
@@ -26,6 +26,7 @@ class LLViewerCamera;
 class LLFontGL;
 class LLFace;
 class LLViewerObject;
+class LLHUDEffect;
 
 class LLHUDObject : public LLRefCount
 {
@@ -45,6 +46,7 @@ public:
 	U8 getType() const { return mType; }
 
 	static LLHUDObject *addHUDObject(const U8 type);
+	static LLHUDEffect *addHUDEffect(const U8 type);
 	static void updateAll();
 	static void renderAll();
 	static void renderAllForSelect();
-- 
cgit v1.2.3