Code cleanup

* Moved Responder stuff to LLHTTPClient.
* Renamed LLHTTPClient::Responder to LLHTTPClient::ResponderWithResult.
* Deleted LLHTTPClientAdapter and LLHTTPClientInterface.
* Renamed AICurlInterface::TransferInfo to AITransferInfo and moved it
  to llhttpclient.h
* Removed 'CURLcode code' argument from completed_headers.
This commit is contained in:
Aleric Inglewood
2012-10-31 23:02:03 +01:00
parent 7549b471c3
commit c0ac428179
58 changed files with 549 additions and 657 deletions

View File

@@ -429,151 +429,6 @@ std::string strerror(CURLcode errorcode)
return curl_easy_strerror(errorcode);
}
//-----------------------------------------------------------------------------
// class ResponderBase
//
ResponderBase::ResponderBase(void) : mReferenceCount(0), mCode(CURLE_FAILED_INIT), mFinished(false)
{
DoutEntering(dc::curl, "AICurlInterface::Responder() with this = " << (void*)this);
}
ResponderBase::~ResponderBase()
{
DoutEntering(dc::curl, "AICurlInterface::ResponderBase::~ResponderBase() with this = " << (void*)this << "; mReferenceCount = " << mReferenceCount);
llassert(mReferenceCount == 0);
}
void ResponderBase::setURL(std::string const& url)
{
// setURL is called from llhttpclient.cpp (request()), before calling any of the below (of course).
// We don't need locking here therefore; it's a case of initializing before use.
mURL = url;
}
AIHTTPTimeoutPolicy const& ResponderBase::getHTTPTimeoutPolicy(void) const
{
return AIHTTPTimeoutPolicy::getDebugSettingsCurlTimeout();
}
void ResponderBase::decode_llsd_body(U32 status, std::string const& reason, LLChannelDescriptors const& channels, buffer_ptr_t const& buffer, LLSD& content)
{
// If the status indicates success (and we get here) then we expect the body to be LLSD.
bool const should_be_llsd = (200 <= status && status < 300);
if (should_be_llsd)
{
LLBufferStream istr(channels, buffer.get());
if (LLSDSerialize::fromXML(content, istr) == LLSDParser::PARSE_FAILURE)
{
// Unfortunately we can't show the body of the message... I think this is a pretty serious error
// though, so if this ever happens it has to be investigated by making a copy of the buffer
// before serializing it, as is done below.
llwarns << "Failed to deserialize LLSD. " << mURL << " [" << status << "]: " << reason << llendl;
}
// LLSDSerialize::fromXML destructed buffer, we can't initialize content now.
return;
}
// Put the body in content as-is.
std::stringstream ss;
buffer->writeChannelTo(ss, channels.in());
content = ss.str();
#ifdef SHOW_ASSERT
if (!should_be_llsd)
{
// Make sure that the server indeed never returns LLSD as body when the http status is an error.
LLSD dummy;
bool server_sent_llsd_with_http_error = LLSDSerialize::fromXML(dummy, ss) > 0;
if (server_sent_llsd_with_http_error)
{
llwarns << "The server sent us a response with http status " << status << " and LLSD(!) body: \"" << ss.str() << "\"!" << llendl;
}
llassert(!server_sent_llsd_with_http_error);
}
#endif
}
void ResponderBase::decode_raw_body(U32 status, std::string const& reason, LLChannelDescriptors const& channels, buffer_ptr_t const& buffer, std::string& content)
{
LLMutexLock lock(buffer->getMutex());
LLBufferArray::const_segment_iterator_t const end = buffer->endSegment();
for (LLBufferArray::const_segment_iterator_t iter = buffer->beginSegment(); iter != end; ++iter)
{
if (iter->isOnChannel(channels.in()))
{
content.append((char*)iter->data(), iter->size());
}
}
}
// Called with HTML body.
// virtual
void ResponderWithCompleted::completedRaw(U32 status, std::string const& reason, LLChannelDescriptors const& channels, buffer_ptr_t const& buffer)
{
LLSD content;
decode_llsd_body(status, reason, channels, buffer, content);
// Allow derived class to override at this point.
completed(status, reason, content);
}
// virtual
void ResponderWithCompleted::completed(U32 status, std::string const& reason, LLSD const& content)
{
// Either completedRaw() or this method must be overridden by the derived class. Hence, we should never get here.
llassert_always(false);
}
// virtual
void Responder::finished(CURLcode code, U32 http_status, std::string const& reason, LLChannelDescriptors const& channels, buffer_ptr_t const& buffer)
{
mCode = code;
LLSD content;
decode_llsd_body(http_status, reason, channels, buffer, content);
// HTTP status good?
if (200 <= http_status && http_status < 300)
{
// Allow derived class to override at this point.
result(content);
}
else
{
// Allow derived class to override at this point.
errorWithContent(http_status, reason, content);
}
mFinished = true;
}
// virtual
void Responder::errorWithContent(U32 status, std::string const& reason, LLSD const&)
{
// Allow derived class to override at this point.
error(status, reason);
}
// virtual
void Responder::error(U32 status, std::string const& reason)
{
llinfos << mURL << " [" << status << "]: " << reason << llendl;
}
// Friend functions.
void intrusive_ptr_add_ref(ResponderBase* responder)
{
responder->mReferenceCount++;
}
void intrusive_ptr_release(ResponderBase* responder)
{
if (--responder->mReferenceCount == 0)
{
delete responder;
}
}
} // namespace AICurlInterface
//==================================================================================
@@ -1281,7 +1136,7 @@ void CurlEasyRequest::print_curl_timings(void) const
DoutCurl("CURLINFO_STARTTRANSFER_TIME = " << t);
}
void CurlEasyRequest::getTransferInfo(AICurlInterface::TransferInfo* info)
void CurlEasyRequest::getTransferInfo(AITransferInfo* info)
{
// Curl explicitly demands a double for these info's.
double size, total_time, speed;
@@ -1294,7 +1149,7 @@ void CurlEasyRequest::getTransferInfo(AICurlInterface::TransferInfo* info)
info->mSpeedDownload = speed;
}
void CurlEasyRequest::getResult(CURLcode* result, AICurlInterface::TransferInfo* info)
void CurlEasyRequest::getResult(CURLcode* result, AITransferInfo* info)
{
*result = mResult;
if (info && mResult != CURLE_FAILED_INIT)
@@ -1407,7 +1262,7 @@ ThreadSafeBufferedCurlEasyRequest const* CurlResponderBuffer::get_lockobj(void)
return static_cast<ThreadSafeBufferedCurlEasyRequest const*>(AIThreadSafeSimple<CurlResponderBuffer>::wrapper_cast(this));
}
void CurlResponderBuffer::prepRequest(AICurlEasyRequest_wat& curl_easy_request_w, AIHTTPHeaders const& headers, AICurlInterface::ResponderPtr responder)
void CurlResponderBuffer::prepRequest(AICurlEasyRequest_wat& curl_easy_request_w, AIHTTPHeaders const& headers, LLHTTPClient::ResponderPtr responder)
{
mInput.reset(new LLBufferArray);
mInput->setThreaded(true);