From 1e745ba48bcabf9a4a52a28689f5612019167040 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sat, 20 Oct 2012 23:48:30 +0200 Subject: [PATCH] Curl work in progress. Minor changes like comment fixes and addition of accessors that will be needed for future commits. Also removed Responder::fatalError as it was never used. --- indra/aistatemachine/aicurl.cpp | 8 +------- indra/aistatemachine/aicurl.h | 12 +++++------- indra/aistatemachine/aicurlprivate.h | 2 +- indra/aistatemachine/aicurlthread.cpp | 2 +- indra/llmessage/llbuffer.cpp | 16 +++++++++++++++- indra/llmessage/llbuffer.h | 2 ++ indra/llmessage/llurlrequest.cpp | 2 +- indra/llmessage/llurlrequest.h | 5 +++++ 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/indra/aistatemachine/aicurl.cpp b/indra/aistatemachine/aicurl.cpp index 128110080..7217a3409 100644 --- a/indra/aistatemachine/aicurl.cpp +++ b/indra/aistatemachine/aicurl.cpp @@ -479,12 +479,6 @@ void Responder::completedRaw(U32 status, std::string const& reason, LLChannelDes completed(status, reason, content); } -void Responder::fatalError(std::string const& reason) -{ - llwarns << "Responder::fatalError(\"" << reason << "\") is called (" << mURL << "). Passing it to Responder::completed with fake HTML error status and empty HTML body!" << llendl; - completed(U32_MAX, reason, LLSD()); -} - // virtual void Responder::completed(U32 status, std::string const& reason, LLSD const& content) { @@ -1364,7 +1358,7 @@ void CurlResponderBuffer::prepRequest(AICurlEasyRequest_wat& curl_easy_request_w curl_easy_request_w->setHeaderCallback(&curlHeaderCallback, lockobj); // Allow up to ten redirects. - if (responder && responder->followRedir()) + if (responder->followRedir()) { curl_easy_request_w->setopt(CURLOPT_FOLLOWLOCATION, 1); curl_easy_request_w->setopt(CURLOPT_MAXREDIRS, HTTP_REDIRECTS_DEFAULT); diff --git a/indra/aistatemachine/aicurl.h b/indra/aistatemachine/aicurl.h index e1a999c9c..a41e544ec 100644 --- a/indra/aistatemachine/aicurl.h +++ b/indra/aistatemachine/aicurl.h @@ -204,7 +204,7 @@ class Responder : public AICurlResponderBufferEvents { Responder(void); virtual ~Responder(); - private: + protected: // Associated URL, used for debug output. std::string mURL; @@ -216,6 +216,9 @@ class Responder : public AICurlResponderBufferEvents { // used only when printing debug output regarding activity of the Responder. void setURL(std::string const& url); + // Accessor. + std::string const& getURL(void) const { return mURL; } + protected: // Called when the "HTTP/1.0 " header is received. /*virual*/ void received_HTTP_header(void) @@ -237,7 +240,7 @@ class Responder : public AICurlResponderBufferEvents { completedHeaders(status, reason, mReceivedHeaders); } - // Derived classes can override this to get the HTML header that was received, when the message is completed. + // Derived classes can override this to get the HTML headers that were received, when the message is completed. // The default does nothing. virtual void completedHeaders(U32 status, std::string const& reason, AIHTTPHeaders const& headers); @@ -252,11 +255,6 @@ class Responder : public AICurlResponderBufferEvents { // The default is to interpret the content as LLSD and call completed(). virtual void completedRaw(U32 status, std::string const& reason, LLChannelDescriptors const& channels, buffer_ptr_t const& buffer); - // Called from LLHTTPClient request calls, if an error occurs even before we can call one of the above. - // It calls completed() with a fake status U32_MAX, as that is what some derived clients expect (bad design). - // This means that if a derived class overrides completedRaw() it now STILL has to override completed() to catch this error. - void fatalError(std::string const& reason); - // A derived class should return true if curl should follow redirections. // The default is not to follow redirections. virtual bool followRedir(void) { return false; } diff --git a/indra/aistatemachine/aicurlprivate.h b/indra/aistatemachine/aicurlprivate.h index b4741eca0..f6a1642ca 100644 --- a/indra/aistatemachine/aicurlprivate.h +++ b/indra/aistatemachine/aicurlprivate.h @@ -366,7 +366,7 @@ class CurlEasyRequest : public CurlEasyHandle { private: curl_slist* mHeaders; AICurlEasyHandleEvents* mEventsTarget; - CURLcode mResult; + CURLcode mResult; //AIFIXME: this does not belong in the request object, but belongs in the response object. AIHTTPTimeoutPolicy const* mTimeoutPolicy; std::string mLowercaseHostname; // Lowercase hostname (canonicalized) extracted from the url. diff --git a/indra/aistatemachine/aicurlthread.cpp b/indra/aistatemachine/aicurlthread.cpp index a70f8e820..e303a4a44 100644 --- a/indra/aistatemachine/aicurlthread.cpp +++ b/indra/aistatemachine/aicurlthread.cpp @@ -2105,7 +2105,7 @@ void CurlResponderBuffer::processOutput(AICurlEasyRequest_wat& curl_easy_request { // Only the responder registers for these events. llassert(mEventsTarget == mResponder.get()); - // Allow clients to parse headers before we attempt to parse + // Allow clients to parse result codes and headers before we attempt to parse // the body and provide completed/result/error calls. mEventsTarget->completed_headers(responseCode, responseReason); } diff --git a/indra/llmessage/llbuffer.cpp b/indra/llmessage/llbuffer.cpp index 437674775..0f31f7065 100644 --- a/indra/llmessage/llbuffer.cpp +++ b/indra/llmessage/llbuffer.cpp @@ -393,7 +393,14 @@ LLBufferArray::segment_iterator_t LLBufferArray::splitAfter(U8* address) mSegments.insert(it, segment2); return rv; } - + +//mMutexp should be locked before calling this. +LLBufferArray::const_segment_iterator_t LLBufferArray::beginSegment() const +{ + ASSERT_LLBUFFERARRAY_MUTEX_LOCKED + return mSegments.begin(); +} + //mMutexp should be locked before calling this. LLBufferArray::segment_iterator_t LLBufferArray::beginSegment() { @@ -401,6 +408,13 @@ LLBufferArray::segment_iterator_t LLBufferArray::beginSegment() return mSegments.begin(); } +//mMutexp should be locked before calling this. +LLBufferArray::const_segment_iterator_t LLBufferArray::endSegment() const +{ + ASSERT_LLBUFFERARRAY_MUTEX_LOCKED + return mSegments.end(); +} + //mMutexp should be locked before calling this. LLBufferArray::segment_iterator_t LLBufferArray::endSegment() { diff --git a/indra/llmessage/llbuffer.h b/indra/llmessage/llbuffer.h index 7f83896a7..4940da2fe 100644 --- a/indra/llmessage/llbuffer.h +++ b/indra/llmessage/llbuffer.h @@ -495,6 +495,7 @@ public: * @return Returns the segment if there is one. */ segment_iterator_t beginSegment(); + const_segment_iterator_t beginSegment() const; /** * @brief Get the one-past-the-end segment in the buffer array @@ -502,6 +503,7 @@ public: * @return Returns the iterator for an invalid segment location. */ segment_iterator_t endSegment(); + const_segment_iterator_t endSegment() const; /** * @brief Get the segment which holds the given address. diff --git a/indra/llmessage/llurlrequest.cpp b/indra/llmessage/llurlrequest.cpp index 17c393b02..d1ce88672 100644 --- a/indra/llmessage/llurlrequest.cpp +++ b/indra/llmessage/llurlrequest.cpp @@ -516,7 +516,7 @@ bool LLURLRequest::configure(AICurlEasyRequest_wat const& curlEasyRequest_w) case HTTP_PUT: { // Disable the expect http 1.1 extension. POST and PUT default - // to turning this on, and I am not too sure what it means. + // to using this, causing the broken server to get confused. curlEasyRequest_w->addHeader("Expect:"); curlEasyRequest_w->setopt(CURLOPT_UPLOAD, 1); curlEasyRequest_w->setopt(CURLOPT_INFILESIZE, mBodySize); diff --git a/indra/llmessage/llurlrequest.h b/indra/llmessage/llurlrequest.h index 5ae4d64aa..3244f0035 100644 --- a/indra/llmessage/llurlrequest.h +++ b/indra/llmessage/llurlrequest.h @@ -77,6 +77,11 @@ class LLURLRequest : public AICurlEasyRequestStateMachine { */ LLURLRequest(ERequestAction action, std::string const& url, Injector* body, AICurlInterface::ResponderPtr responder, AIHTTPHeaders& headers, bool is_auth, bool no_compression); + protected: + // Call abort(), not delete. + /*virtual*/ ~LLURLRequest() { } + + public: /** * @brief Turn on cookie handling for this request with CURLOPT_COOKIEFILE. */