Commit Graph

64 Commits

Author SHA1 Message Date
Shyotl
dedd75dc4f Implement all aisv3 HTTP requests. Added PATCH and COPY methods. 2015-07-23 01:02:02 -05:00
Shyotl
9f10d9510d Initial AISv3 merge. New HTTP messages not plugged in yet. 2015-06-25 20:16:30 -05:00
Shyotl
1c627317ec No longer include llerrorlegacy.h. Updated llstl to include deletion utilites. 2015-06-19 03:54:20 -05:00
Inusaito Sayori
232bf22e51 Compile foxies 2014-12-05 18:43:50 -05:00
Inusaito Sayori
e69385861a Add LLHTTPClient::putRaw 2014-11-25 23:36:43 -05:00
Aleric Inglewood
74dff061ff Support for new LL Responder API.
This adds mStatus, mReason and mContent to ResponderBase
and fills those in instead of passing it to member functions.
The added danger here is that now code can accidently try
to access these variables while they didn't already get a
correct value.

Affected members of ResponderBase (that now have less arguments):
decode_llsd_body, decode_raw_body, completedHeaders,
completed -> httpCompleted, result -> httpSuccess,
errorWithContent and error -> httpFailure.

New API:

ResponderBase::setResult
ResponderBase::getStatus()
ResponderBase::getReason()
ResponderBase::getContent()
ResponderBase::getResponseHeaders() (returns AIHTTPReceivedHeaders though, not LLSD)
ResponderBase::dumpResponse()
ResponderWithCompleted::completeResult
ResponderWithResult::failureResult (previously pubErrorWithContent)
ResponderWithResult::successResult (previously pubResult)

Not implemented:

getHTTPMethod() - use getName() instead which returns the class name of the responder.

completedHeaders() is still called as usual, although you can ignore
it (not implement in a derived responder) and call getResponseHeaders()
instead, provided you implement needsHeaders() and have it return true.

However, classes derived from ResponderHeadersOnly do not have
completedHeaders(), so they still must implement completedHeaders(),
and then call getResponseHeaders() or just access mReceivedHeaders
directly, as usual.
2014-07-12 18:29:44 +02:00
Aleric Inglewood
589035c1db Attempt to fix gray avatars on mobile networks.
Ported from
e879862791
2014-06-16 21:02:27 +02:00
Inusaito Sayori
5c06afc977 [LLMeshRepo sync] AICurl updates toward LLCurl
LLHTTPClient::getByteRange no longer throws AICurlNoEasyHandle, instead it returns whether or not it threw, to match the true/false convention of LLCurl.
- In addition, the header param has been shifted to earlier in this function to ease diffings.
ResponderBase now has static bool isGoodStatus, introduced into the Responder base class of LLCurl
2014-04-17 20:23:48 -04:00
Aleric Inglewood
06bebcc5c4 Bug fix for BlockingResponder.
Blocking http requests (code using responders derived from
BlockingResponder) *do* call getRaw() and getLLSD to get the body of
server error messages. It is therefore perfectly ok if mStatus !=
HTTP_OK.
2013-11-19 21:16:12 +01:00
Aleric Inglewood
7b9f854c66 Fix for 'with active responder' llerrs crash.
This fixes at least one case (crash report 8407), which comes
down to not cleanly informing a responder of failure when the
request url is empty (or so badly formed that it isn't a valid
url). As a result, the statemachine would abort() without
informing the responder - which is bad, sort of.

The previous cases where the responder needed to be informed
of a failure, namely "statemachine timed_out()" and "bad_socket()"
when a socket suddenly becomes bad for unknown reason, have been
replaced with the more general 'aborted()' function, which must
be called before the statemachine calls abort(). Clearly this
has been done for all cases of abort() now, so that if the
llerrs fires again in the future then that would have to be
after the statemachine calls finish(), which is still as "impossible"
as it was - hence the llerrs is still there to make sure.

The reason that this seldom happened on SL, and more often on
opensim, even more often on home-brew test grids, seems plausible:
malformed urls happen more in those cases.

I also took the opportunity to improve the robustness of cases
where the curl error code is checked: it makes no sense to check
what curl gives as error code when an internal error occurred.
2013-11-18 18:16:26 +01:00
Aleric Inglewood
a9972bbf02 Suppress spammy warning (debug mode) 2013-10-30 20:32:22 +01:00
Aleric Inglewood
929badb110 Let statemachine honor approvements.
The inventory bulk fetch is not thread-safe, so the it doesn't start
right away, causing the approvement not to be honored upon return from
post_approved (formerly post_nb).

This patch renames wantsMoreHTTPReqestsFor to approveHTTPRequestFor,
and has it return NULL or a AIPerService::Approvement object.
The latter is now passed to the CurlEasyHandle object instead of just a
boolean mQueueIfTooMuchBandwidthUsage, and then the Approvement is
honored by the state machine right after the request is actually added
to the command queue.

This should avoid a flood of inventory requests in the case
approveHTTPRequestFor is called multiple times before the main thread
adds the requests to the command queue. I don't think that actually ever
happens, but I added debug code (to find some problem) that is so damn
strictly checking everything that I need to be this precise in order to
do that testing.
2013-05-12 04:19:44 +02:00
Aleric Inglewood
1d629438c0 Add HTTP bandwidth throttling for every other responder.
Most notably getMesh (the only one possibly using any significant
bandwidth), but in general every type of requests that just have to
happen anyway and in the order they are requested: they are just passed
to the curl thread, but now the curl thread will queue them and hold
back if the (general) service they use is loaded too heavily.
2013-05-06 02:54:10 +02:00
Aleric Inglewood
712c46a74e Add comment with regard to LLSD in the body of pages with an HTTP error code. 2013-03-21 20:56:21 +01:00
Aleric Inglewood
7dfef31469 Possible upload timeout improvement.
When uploading finishes, but is not detected, the timeout should be for
"reply delay", the time that the server takes before it replies, and not
CurlTimeoutLowSpeedTime. This patch adds code that takes this failure
into account (which happened only ONCE for me on Metropolis while flying
around and using trickle (not sure if that is relevant), so it's not
that likely to improvement anything in practise. Note that it is
detected by an assertion when it happens, so that we can safely assume
it normally never happened on SL).

* Generalized PUT / POST configuration by adding
  CurlEasyRequest::setPut, which now also supports keep-alive (which
  still isn't used).
* Upload content length is now stored in CurlEasyRequest::mContentLength
* CurlEasyRequest::has_stalled() now return false if it was possbile
  that the 'upload finished' detect failed AND calls upload_finished()
  itself in that case, so it is no longer 'const'.
* If low speed is detect exactly when the last bytes are being attempted
  to be sent (unlikely scenario), then the upload gets 4 more seconds
  after which is switches to CurlTimeoutReplyDelay.
* Added EDoesAuthentication and EAllowCompressedReply to replace
  booleans, for readability and type-safety, as did EKeepAlive. Note
  that this change inverts the meaning of the compression related parameter.
* Unrelated: removed an unnecessary #include "llurlrequest.h" from
  llxmlrpcresponder.h
2013-03-10 16:43:15 +01:00
Aleric Inglewood
96d302aa42 Be more verbose about internal (curl / timeout) errors.
Translates the CURLE_WRITE_ERROR into what it really means: that the low
speed check failed.
2013-03-09 05:26:52 +01:00
Aleric Inglewood
b9b5f13624 Run HTTPGetResponder in any thread.
This fixes a bug where unref() was called when a state machine was
aborted before it reached bs_initialized. Debug code was added to detect
errors related to that.

In order to run HTTPGetResponder in any thread, I needed direct access
to LLHTTPClient::request, so I had to move that to the header file,
and therefore had to move ERequestAction from LLURLRequest to
LLHTTPClient to avoid include problems.

With this, textures are fetched with no latency: call to
LLHTTPClient::request runs all the way till the state machine is idle
(AICurlEasyRequestStateMachine_waitAdded). There is small delay till the
curl thread wakes up, which then processes the request and opens the url
etc. When the transaction is finished, it calls
AIStateMachine::advance_state(AICurlEasyRequestStateMachine_removed_after_finished)
which subsequently doesn't return until the state machine is completely
finished (bs_killed). The LLURLRequest isn't deleted yet at that point
because the AITimer of the LLURLRequest runs in the main thread: it is
aborted, but only the next time the main thread state engines run that
is deleted and the timer keeps an LLPointer to it's parent, the
LLURLRequest, so only then the LLURLRequest object is destructed. This
however has nothing to do with the texture-bandwidth loop.
2013-03-07 01:52:21 +01:00
Aleric Inglewood
c4dceaf3e9 Rewrite of AIStateMachine, version 2. 2013-03-06 03:26:43 +01:00
Siana Gearz
6a774e4685 This should fix voice decline crash 2013-02-03 21:56:13 +01:00
Aleric Inglewood
1c8027b1e6 Add statemachine parent callback support to LLHTTPClient::post 2013-01-27 22:02:19 +01:00
Aleric Inglewood
024c62aed4 Fix the "map/set iterators incompatible" bug.
cookies is only valid when AIHTTPReceivedHeaders::getValues return true.
2013-01-12 04:24:21 +01:00
Aleric Inglewood
f9738cb611 Add getName() to every non-base class Responder object. 2013-01-11 04:15:55 +01:00
Aleric Inglewood
b22832ba54 Fix cookie handling.
Cookies are now collected during redirects, one the last cookie
of a given name is kept. Cookies are then set by looking for
the right cookie name (instead of what viewer 3 does: just
use the last cookie that was set).

This fixes the merchant outbox.
2012-12-24 19:58:54 +01:00
Aleric Inglewood
fac3fc67b6 Add filtering for curl debug output.
Add CURLTR debug channel for libcurl API calls,
and use CURLIO only for libcurl debug output.
Note: need to set gDebugCurlTerse to true for
filtering to take effect, then pass 'debug_on'
to the LLHttpClient methods that require debugging.
2012-12-24 02:54:36 +01:00
Aleric Inglewood
8095d6c48c Large snapshot update (part 3) 2012-12-22 19:07:08 +01:00
Aleric Inglewood
c097d650dc Don't upload partial files 2012-11-14 19:26:16 +01:00
Aleric Inglewood
b7af32bee3 Use std::istream::read instead of readsome
According to the docs
(http://www.cplusplus.com/reference/iostream/istream/readsome/)
readsome would also set state flag eofbit, but apparently I'm
misinterpreting it.  Anyway, using read() and then gcount()
to get the number of bytes does work.
2012-11-14 18:37:44 +01:00
Aleric Inglewood
e307df79a1 Ignore the body in case of internal errors 2012-11-14 04:00:26 +01:00
Aleric Inglewood
6f8ea87c46 Add ResponderHeadersOnly.
ResponderHeadersOnly is a base class for responders that use
HTTPClient::head or HTTPClient::getHeaderOnly. It already
has a needsHeaders() that return true and only allows for
completedHeaders to be overridden.

I removed the CURLOPT_HEADER option for these cases, because
that only causes the headers to be send to the writeCallback
as if they are part of the body, in addition to the headerCallback;
That gave raise to some confusion for the existing code (ie,
unexpected errors when trying to decode the body as LLSD and
duplicated 'low speed' information for the Timeout policy code.
2012-11-13 21:46:35 +01:00
Aleric Inglewood
04e7dc1270 Collect and print stats about HTTP status code 2012-11-10 02:19:20 +01:00
Aleric Inglewood
cb52e82a60 Moved and extended AICurlInterface::Stats
Moved AICurlPrivate::Stats to AICurlInterface::Stats and added several
counters to keep track of the number of existing instances of
respectively AICurlEasyRequest, AICurlEasyRequestStateMachine,
BufferedCurlEasyRequest, ResponderBase and
ThreadSafeBufferedCurlEasyRequest.
2012-11-07 02:15:23 +01:00
Aleric Inglewood
a495a6bfbc Short circuit llsd debug check. 2012-11-05 01:04:02 +01:00
Aleric Inglewood
c0ac428179 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.
2012-10-31 23:11:42 +01:00
Aleric Inglewood
0b265320a9 Code clean up.
* Removed LLCurlRequest and replaced it's last usage with LLHTTPClient API calls.
* Deleted dead code.
* Renamed all the get4/post4/put4/getByteRange4 etc, back to their
  original name without the '4'.
2012-10-31 05:01:24 +01:00
Aleric Inglewood
9996cf6157 Bug fix 2012-10-30 21:17:25 +01:00
Aleric Inglewood
65e012c540 More curl fixes and changes.
* Moved LegacyPolledResponder::mCode to ResponderBase::mCode.
* Added a parameter to ResponderBase::finished (and pubError*) to set mCode.
* Renamed ResponderBase::decode_body to decode_llsd_body and added ResponderBase::decode_raw_body.
* Use LegacyPolledResponder::finished instead of LegacyPolledResponder::completed_headers
  to set remaining cached values.
* Fixed assertion in case of -DCWDEBUG and upload finish detection failure in case of HEAD
  method (mDebugIsGetMethod -> mDebugIsHeadOrGetMethod).
* Add XmlTreeInjector : support for LLXmlTree.
* Split BlockingResponder into BlockingLLSDResponder and BlockingRawResponder.
* Final blocking responders are now: BlockingLLSDPostResponder, BlockingLLSDGetResponder
  and BlockingRawGetResponder.
* Added LLHTTPClient::blockingGetRaw
* Got rid of hipporestrequest.* -- and fixed hippogridmanager.cpp to use
  LLHTTPClient::blockingGetRaw instead, and fixed llviewermessage.cpp to use
  AICurlInterface::ResponderWithCompleted and decode_raw_body instead of
  HippoRestHandlerRaw and LLHTTPClient::get4 instead of HippoRestRequest::get5.
2012-10-28 17:38:25 +01:00
Aleric Inglewood
2a88f7d7c4 ResponderAdapter stuff
Renamed AICurlInterface::Responder to AICurlInterface::ResponderBase,
but without the virtual 'event' methods.
Derived from that: Responder and ReponderWithCompleted, where the
first defines result = 0, ErrorWithContent and error, and the latter
completedRaw and completed.
Added HttpClient::IgnoreBody, derived from Responder and implementing
'result' doing nothing; HttpClient::Ignore is now derived from
IgnoreBody and defines the still pure virtual getHTTPTimeoutPolicy.

Added ResponderBase::decode_body, which is now the sole place
where the code makes the decision wether some response data might be
LLSD or not based on the http status result. Before it just tried
to decode everything as LLSD, which seems a bit nonsense.

ResponderWithCompleted::completed no longer does anything, since
classes derived from ResponderWithCompleted are expected to override it,
or never call it by overriding completedRaw.

Entry point is now ResponderBase::finished = 0, instead of
completedRaw, where ResponderWithCompleted implements finished by
called completedRaw, but Responder doesn't: that directly calls
result/errorWithContent/error. Or, for the hack ResponderAdapter,
the entry points are pubResult/pubErrorWithContent.
Those are now the ONLY public methods, so more confusion.
mFinished is now set in all cases.

As a result of all that, it is no longer possible to accidently
pass a responder to ResponderAdapter that would break because it
expects completed() and completedRaw() to be called.

Added LLBufferArray::writeChannelTo.

Fixed bug for BlockingResponder::body (returned reference to temporary).

LLSDMessage::ResponderAdapter now allows a "timeoutpolicy" name
to be passed (not doing so results in the default timings), so
that the timeout policy of the used responder is retained.

Fixed llfasttimerview.cpp to test LLSDSerialize::fromXML() to return
a positive value instead of non-zero, because it may return -1 when the
parsing fails (three places).

Removed LLHTTPClient::Responder as base class from
LLFloaterRegionDebugConsole completely: it isn't a responder!

Several other responder classes were simplified a bit in order to
compile again with the above changes.
2012-10-26 04:13:29 +02:00
Aleric Inglewood
243db9a3a8 Moved mFinished/is_finished() from LegacyPolledResponder to Responder.
Slightly more robust, adds one boolean to all responders, 99%
of which don't need that though, and an extra call redirection,
but well... We might need it this way when I add the possibility
to abort a transfer.
2012-10-22 22:52:18 +02:00
Aleric Inglewood
768f1b5710 Fixes blocking_request. Adds LegacyPolledResponder and BlockingResponder.
XMLRPCResponder also uses the new LegacyPolledResponder now.
Renamed http_result() -> http_status().
2012-10-22 20:19:44 +02:00
Aleric Inglewood
7f50b2ba7b Add XMLRPC support to LLHTTPClient and that instead of LLXMLRPCTransaction 2012-10-22 01:59:17 +02:00
Aleric Inglewood
f8273e977e Make NoVerifySSLCert work for all LLURLRequest
Moved CURLOPT_ENCODING from CurlEasyRequest::setPost_raw, and
CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST from
CurlResponderBuffer::prepRequest, to LLURLRequest::configure,
enabling the debug setting NoVerifySSLCert for the latter
two to work as follows: old behavior if "NoVerifySSLCert"
is not set, and check neither if it is set. However, if
the (new) bool mIsAuth is set the behavior of LLXMLRPCTransaction::Impl::init
is used. This is so in a next commit we can replace
LLXMLRPCTransaction with LLURLRequest: LLXMLRPCTransaction::Impl::init
will be removed. For the same reason, when the new boolean
mNoCompression is set then CURLOPT_ENCODING is set to "identity",
otherwise the old behavior (of clearing it) is used.
2012-10-20 23:28:33 +02:00
Aleric Inglewood
3f1fb9a66e Add improved timeout handling for HTTP transactions.
Introduces AIHTTPTimeoutPolicy objects which do not just
specify a single "timeout" in seconds, but a plethora of
timings related to the life cycle of the average HTTP
transaction.

This knowledge is that moved to the Responder being
used instead of floating constants hardcoded in the
callers of http requests. This assumes that the same
timeout policy is wanted for each transaction that
uses the same Responder, which can be enforced is needed.

I added a AIHTTPTimeoutPolicy for EVERY responder,
only to make it easier later to tune timeout values
and/or to get feedback about which responder runs
into HTTP errors in debug output (especially time outs),
so that they can be tuned later. If we already understood
exactly what we were doing then most responders could
have been left alone and just return the default timeout
policy: by far most timeout policies are just a copy
of the default policy, currently.

This commit is not finished... It's a work in progress
(viewer runs fine with it though).
2012-10-05 15:53:29 +02:00
Aleric Inglewood
1254a7bbe2 Merge remote-tracking branch 'github/master' into curlthreading3
Conflicts:
	indra/aistatemachine/aistatemachine.cpp
2012-09-22 01:25:54 +02:00
Aleric Inglewood
81bc6b49f8 Debug code bug fix; removal of CurlEasyHandle::getErrorString()
CurlEasyHandle::mErrorBuffer (CURLOPT_ERRORBUFFER) can NOT be
used to retrieve information about an error returned by
curl_multi_info_read in CURLMsg::data::result. This buffer is
only initialized when a curl_easy_* call returns an error,
and those errors are already printed automagically.

Initialize the buffer with an empty string upon invokation
of an curl_easy_* call, so we are sure the error belongs to
the last call.
2012-09-21 01:28:26 +02:00
Aleric Inglewood
2d12a82a54 Always flush LLBufferStream objects. 2012-09-20 04:49:43 +02:00
Aleric Inglewood
1d5a63c180 Fixed showing TOS floater.
This creates a separate events interface structure
for CurlResponderBuffer (AICurlResponderBufferEvents)
for dealing with received HTTP headers.

The headers are passed to the Responder, but only
if the class derived from Responder implements
completedHeaders (otherwise it makes little sense
to even decode the headers).

Basically this is a reimplementation of the functionality
of the old LLHTTPClientURLAdaptor class.
2012-09-18 23:59:09 +02:00
Aleric Inglewood
83b13f6a3f WIP: make everything use AICurlEasyRequestStateMachine 2012-08-20 21:18:19 +02:00
Aleric Inglewood
536cb6febd Merge branch 'curlthreading2' into curlthreading3
Conflicts:
	indra/CMakeLists.txt
	indra/llcommon/llstring.h
	indra/llmessage/CMakeLists.txt
	indra/llmessage/llhttpclient.cpp
	indra/llmessage/llhttpclient.h
	indra/llmessage/llurlrequest.cpp
	indra/llmessage/llurlrequest.h
	indra/newview/hipporestrequest.cpp
	indra/newview/llappviewer.cpp
2012-08-15 00:51:40 +02:00
Aleric Inglewood
19293601b3 Manual pick of stuff from 'shycurl' (68ad5411) that seemed to make sense. 2012-08-14 02:38:06 +02:00
Siana Gearz
36ff4dcd11 Don't feed empty, non-working callback to CURL
Cherry-Pick of 96a4e16a

Conflicts:
	indra/llmessage/llurlrequest.cpp
	indra/llmessage/llurlrequest.h
	indra/newview/hipporestrequest.cpp

Clear reasons for conflicts, resolved.
2012-08-13 23:33:49 +02:00