mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
0e7bac9Fix include pathe5bb90fFix constness of Proxyac0142aUse template castef6e381Add missing Url.h include206e65cFix constness of operator[]695cc38Use template instantiation for friend declaration7b1e03aAdd BaseFromMember49bc04fMake List<>::Node not uncopyabled5954ffAdd Journal to UnitTest58da106Temporarily disable ServiceQueue dtor precondition assertsfe58c1aAdd missing #include2c02580Add PropertyStream for server state introspection24c2315Add ScopedWrapperContexta3845f5Add RelativeTime::value_type typedef7442932Fix missing PropertyStream membersed5a98fMore PropertyStream output for PeerFinderfcfa10dAdd PropertyStream3cf0729Tidy up AbstractHandler usage in HTTPClient55171f4Remove obsolete source files1311ca3Increase arity of SharedFunction67d807dAdd IPEndpoint::key_equalebf395eAdd ErrorCode and boost library2c3ead3Add ServiceQueue::wrap6c7f5d0Move many Thread related classes93e9d86Measure CPU utilization in ServiceQueueca47d72Move ServiceQueue, ThreadLocalValue, SpinLockc864e4dMove WaitableEventff305e6Add CPUMeter and ScopedTimeInterval01fd05cAdd RecursiveMutex, UnlockGuard, TryLockGuard5831a53Remove Journal from most Stoppable overridesb60a7f3Add Request and Response HTTP parsers44445ffRefactor net buffers classesac37c38Beast class refactor8b7056bFix eof on HTTP client get228b664Remove obsolete beast container classes1dfd655Use RelativeTime from startup in DeadlineTimerae22d5dAdd more methods to RelativeTimec67929eRemove unhandled exception catcher2472a90Add 64 bit output for MurmurHashf3d97c7Add RelativeTime::fromStartupb0b8660IPEndpoint better parsingae551cdAdd alternate form string parsing to IPEndpointd0a0dbfDon't break on Throw0e46762Add hasher functors for IPEndpointa1ec423Add Thread::stopThreadAsync4f7dca3Add compiler, stdlib, and platform skeleton to beast/config4394594Tidy up some use of Error for throwe5e0f52Journal console output improvementsf07515eAdd Stoppable prepare and start interfacesd37dd46Move RelativeTime to chrono, add ostream support3f6e7aaAdd console feature to Journalad0064aJournal option to write to Output window (MSVC)0b7574bAdd compilation test scriptcc05ce1Add ServiceQueuee132aabUse boost for functional when the config is set026b926Fix is_continuation for boost versionc807a4eFix invoked_type type reference2ff781bRemove LockFreeStack::size3acb474Add SharedData::ConstAccess7e4c834Add LockFreeStack::empty9c61a6dAdded AbstractHandler, WrapHandler. HTTPClient Fixes.94e40dcFix unittest, by removing recursive call.38bf408Fix nonstandard C++ extension in getNullSink1ef044dBuild fixesd5d3746Fix missing <cmath> include for Gentoo5f231d3Update copyright notice and licenses7b89bf6Add FixedArray, IntrusiveArray, Crypto5c5de57Reorganize beast modules and files9e18bb3Merge commit '43deaaa5cf0d0178a4a6c3cb69c02a2a9a43ec7d' as 'src/beast/beast/http/impl/http-parser'57703acFix BeforeBoost.h includefbc247bAdd Stoppable to beast56496d8IPEndpoint comparisons9d9c822Migrate some headers and general tidying1a3cddcAdd SharedArg and AsyncObject373ca9cAdd HTTPRequest and improvements to HTTPMessage parsing9534516Add some thread classes and fix SharedData with a simple mutex adapter755ab36Make CallQueue unit test runManualc0ca037Remove Beast version printing on startup7efb6a3Reorganize some MPL and Utility classes and files69c26a1Fix missing BeastConfig.h include in Net.cpp40aa552Disable Beast version printing in Ripple BeastConfig.h7b1352dAdd InterruptibleThread unit test68cf759ThreadWithCallQueue unit test adjustment6501deaIPEndpoint parsing and tidying72fc42bMove and add some template metaprogramming classes2a164f0Change filname capitalization (end)6a14f25Change filename capitalization92fd417Move integer types to beast/CStdInt.hebbd9ffMove TargetPlatform.h to beast/Config.h874b524Add IPEndpoint14b34fcTidy up some zlib macro undefines34fffcaRename beast sources for consistency4e59ab2Add CallQueue unit test327d7a6Fixes for consolidated beast unity includesd5ece4eRemove unused and broken classes39f13beRemove unused ConcurrentObject37624a7Add ThreadWithCallQueue unit teste82ec68Remove obsolete beast_Function90551a6Temporarily leave sqlite3 in whatever threading mode it was already in.43ebbb1Fix SharedSingleton to use memoryBarrierf343941Tidy up SharedSingleton doc comments001997eFix leak on exit from Singleton dependency cycle83b9d22Rename to DeadlineTimer::cancel()77874eeUse new instead of ::new for placement2a04dccJournal improvements50965caSharedFunction improvements277e32bAdd LockFreeStack iteratorsd94e4c2Fix undefined behavior in UnsignedIntegerCalc (again)2dc25ceFix DeadlineTimer, callback while holding lock207ffdeFix undefined behavior in UnsignedIntegerCalc1ad8ff9Fix UnsignedInteger::isZero1dd2836Add support for multiprecision integer arithmetic and binary data encodinga45fc47Update .gitignore962a95dTidy up UnsignedIntegerca695faAdd Time::isNull()e96ce99Better random number facilities in UnitTest550b8e5Fine tune UnsignedInteger declaration8e7e3b7Allow negative relative expirations in DeadlineTimerf3dc7ceAdd generic Journal class for loggingbfdda32Make ChildProcess UnitTest manual since it malfunctions02acf7dGeneral refactoring of beast framework classes84ef06eFix ExitHook to derive from AtExitHookf0acc9cReduce the max threads in the Workers unit test55447b0New SharedSingleton, resolves destruction of objects with static storage duration.41eb8a1Remove deprecated SharedPtr::getObject9eda4bcMake SharedObject members const, the counter mutable6eda777Remove deprecated createOnDemandOnce SingletonLifetime option8c522aaFix off by one in pending i/o count on HTTPClient057344eAdd HTTPMessage::toString and familyee728e3Add UniformResourceLocator::emptyae324fbMove ./modules to ./src git-subtree-dir: src/beast git-subtree-split:0e7bac945f
343 lines
14 KiB
C++
343 lines
14 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
|
|
Portions of this file are from JUCE.
|
|
Copyright (c) 2013 - Raw Material Software Ltd.
|
|
Please visit http://www.juce.com
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#ifndef BEAST_URL_H_INCLUDED
|
|
#define BEAST_URL_H_INCLUDED
|
|
|
|
class InputStream;
|
|
class XmlElement;
|
|
|
|
|
|
//==============================================================================
|
|
/**
|
|
Represents a URL and has a bunch of useful functions to manipulate it.
|
|
|
|
This class can be used to launch URLs in browsers, and also to create
|
|
InputStreams that can read from remote http or ftp sources.
|
|
*/
|
|
class BEAST_API URL : LeakChecked <URL>
|
|
{
|
|
public:
|
|
//==============================================================================
|
|
/** Creates an empty URL. */
|
|
URL();
|
|
|
|
/** Creates a URL from a string. */
|
|
URL (const String& url);
|
|
|
|
/** Creates a copy of another URL. */
|
|
URL (const URL& other);
|
|
|
|
/** Destructor. */
|
|
~URL();
|
|
|
|
/** Copies this URL from another one. */
|
|
URL& operator= (const URL& other);
|
|
|
|
/** Compares two URLs.
|
|
All aspects of the URLs must be identical for them to match, including any parameters,
|
|
upload files, etc.
|
|
*/
|
|
bool operator== (const URL&) const;
|
|
bool operator!= (const URL&) const;
|
|
|
|
//==============================================================================
|
|
/** Returns a string version of the URL.
|
|
|
|
If includeGetParameters is true and any parameters have been set with the
|
|
withParameter() method, then the string will have these appended on the
|
|
end and url-encoded.
|
|
*/
|
|
String toString (bool includeGetParameters) const;
|
|
|
|
/** True if it seems to be valid. */
|
|
bool isWellFormed() const;
|
|
|
|
/** Returns just the domain part of the URL.
|
|
|
|
E.g. for "http://www.xyz.com/foobar", this will return "www.xyz.com".
|
|
*/
|
|
String getDomain() const;
|
|
|
|
/** Returns the path part of the URL.
|
|
|
|
E.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar".
|
|
*/
|
|
String getSubPath() const;
|
|
|
|
/** Returns the scheme of the URL.
|
|
|
|
E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't
|
|
include the colon).
|
|
*/
|
|
String getScheme() const;
|
|
|
|
/** Attempts to read a port number from the URL.
|
|
@returns the port number, or 0 if none is explicitly specified.
|
|
*/
|
|
int getPort() const;
|
|
|
|
/** Returns a new version of this URL that uses a different sub-path.
|
|
|
|
E.g. if the URL is "http://www.xyz.com/foo?x=1" and you call this with
|
|
"bar", it'll return "http://www.xyz.com/bar?x=1".
|
|
*/
|
|
URL withNewSubPath (const String& newPath) const;
|
|
|
|
/** Returns a new URL that refers to a sub-path relative to this one.
|
|
|
|
E.g. if the URL is "http://www.xyz.com/foo" and you call this with
|
|
"bar", it'll return "http://www.xyz.com/foo/bar". Note that there's no way for
|
|
this method to know whether the original URL is a file or directory, so it's
|
|
up to you to make sure it's a directory. It also won't attempt to be smart about
|
|
the content of the childPath string, so if this string is an absolute URL, it'll
|
|
still just get bolted onto the end of the path.
|
|
|
|
@see File::getChildFile
|
|
*/
|
|
URL getChildURL (const String& subPath) const;
|
|
|
|
//==============================================================================
|
|
/** Returns a copy of this URL, with a GET or POST parameter added to the end.
|
|
|
|
Any control characters in the value will be encoded.
|
|
|
|
e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com"
|
|
would produce a new url whose toString(true) method would return
|
|
"www.fish.com?amount=some+fish".
|
|
|
|
@see getParameterNames, getParameterValues
|
|
*/
|
|
URL withParameter (const String& parameterName,
|
|
const String& parameterValue) const;
|
|
|
|
/** Returns a copy of this URl, with a file-upload type parameter added to it.
|
|
|
|
When performing a POST where one of your parameters is a binary file, this
|
|
lets you specify the file.
|
|
|
|
Note that the filename is stored, but the file itself won't actually be read
|
|
until this URL is later used to create a network input stream.
|
|
*/
|
|
URL withFileToUpload (const String& parameterName,
|
|
const File& fileToUpload,
|
|
const String& mimeType) const;
|
|
|
|
/** Returns an array of the names of all the URL's parameters.
|
|
|
|
E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would
|
|
contain two items: "type" and "amount".
|
|
|
|
You can call getParameterValues() to get the corresponding value of each
|
|
parameter. Note that the list can contain multiple parameters with the same name.
|
|
|
|
@see getParameterValues, withParameter
|
|
*/
|
|
const StringArray& getParameterNames() const noexcept { return parameterNames; }
|
|
|
|
/** Returns an array of the values of all the URL's parameters.
|
|
|
|
E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would
|
|
contain two items: "haddock" and "some fish".
|
|
|
|
The values returned will have been cleaned up to remove any escape characters.
|
|
|
|
You can call getParameterNames() to get the corresponding name of each
|
|
parameter. Note that the list can contain multiple parameters with the same name.
|
|
|
|
@see getParameterNames, withParameter
|
|
*/
|
|
const StringArray& getParameterValues() const noexcept { return parameterValues; }
|
|
|
|
/** Returns the set of files that should be uploaded as part of a POST operation.
|
|
|
|
This is the set of files that were added to the URL with the withFileToUpload()
|
|
method.
|
|
*/
|
|
const StringPairArray& getFilesToUpload() const;
|
|
|
|
/** Returns the set of mime types associated with each of the upload files.
|
|
*/
|
|
const StringPairArray& getMimeTypesOfUploadFiles() const;
|
|
|
|
/** Returns a copy of this URL, with a block of data to send as the POST data.
|
|
|
|
If you're setting the POST data, be careful not to have any parameters set
|
|
as well, otherwise it'll all get thrown in together, and might not have the
|
|
desired effect.
|
|
|
|
If the URL already contains some POST data, this will replace it, rather
|
|
than being appended to it.
|
|
|
|
This data will only be used if you specify a post operation when you call
|
|
createInputStream().
|
|
*/
|
|
URL withPOSTData (const String& postData) const;
|
|
|
|
/** Returns the data that was set using withPOSTData(). */
|
|
const String& getPostData() const noexcept { return postData; }
|
|
|
|
//==============================================================================
|
|
/** Tries to launch the system's default browser to open the URL.
|
|
|
|
Returns true if this seems to have worked.
|
|
*/
|
|
bool launchInDefaultBrowser() const;
|
|
|
|
//==============================================================================
|
|
/** Takes a guess as to whether a string might be a valid website address.
|
|
|
|
This isn't foolproof!
|
|
*/
|
|
static bool isProbablyAWebsiteURL (const String& possibleURL);
|
|
|
|
/** Takes a guess as to whether a string might be a valid email address.
|
|
|
|
This isn't foolproof!
|
|
*/
|
|
static bool isProbablyAnEmailAddress (const String& possibleEmailAddress);
|
|
|
|
//==============================================================================
|
|
/** This callback function can be used by the createInputStream() method.
|
|
|
|
It allows your app to receive progress updates during a lengthy POST operation. If you
|
|
want to continue the operation, this should return true, or false to abort.
|
|
*/
|
|
typedef bool (OpenStreamProgressCallback) (void* context, int bytesSent, int totalBytes);
|
|
|
|
/** Attempts to open a stream that can read from this URL.
|
|
|
|
@param usePostCommand if true, it will try to do use a http 'POST' to pass
|
|
the paramters, otherwise it'll encode them into the
|
|
URL and do a 'GET'.
|
|
@param progressCallback if this is non-zero, it lets you supply a callback function
|
|
to keep track of the operation's progress. This can be useful
|
|
for lengthy POST operations, so that you can provide user feedback.
|
|
@param progressCallbackContext if a callback is specified, this value will be passed to
|
|
the function
|
|
@param extraHeaders if not empty, this string is appended onto the headers that
|
|
are used for the request. It must therefore be a valid set of HTML
|
|
header directives, separated by newlines.
|
|
@param connectionTimeOutMs if 0, this will use whatever default setting the OS chooses. If
|
|
a negative number, it will be infinite. Otherwise it specifies a
|
|
time in milliseconds.
|
|
@param responseHeaders if this is non-zero, all the (key, value) pairs received as headers
|
|
in the response will be stored in this array
|
|
@returns an input stream that the caller must delete, or a null pointer if there was an
|
|
error trying to open it.
|
|
*/
|
|
InputStream* createInputStream (bool usePostCommand,
|
|
OpenStreamProgressCallback* progressCallback = nullptr,
|
|
void* progressCallbackContext = nullptr,
|
|
const String& extraHeaders = String::empty,
|
|
int connectionTimeOutMs = 0,
|
|
StringPairArray* responseHeaders = nullptr) const;
|
|
|
|
|
|
//==============================================================================
|
|
/** Tries to download the entire contents of this URL into a binary data block.
|
|
|
|
If it succeeds, this will return true and append the data it read onto the end
|
|
of the memory block.
|
|
|
|
@param destData the memory block to append the new data to
|
|
@param usePostCommand whether to use a POST command to get the data (uses
|
|
a GET command if this is false)
|
|
@see readEntireTextStream, readEntireXmlStream
|
|
*/
|
|
bool readEntireBinaryStream (MemoryBlock& destData,
|
|
bool usePostCommand = false) const;
|
|
|
|
/** Tries to download the entire contents of this URL as a string.
|
|
|
|
If it fails, this will return an empty string, otherwise it will return the
|
|
contents of the downloaded file. If you need to distinguish between a read
|
|
operation that fails and one that returns an empty string, you'll need to use
|
|
a different method, such as readEntireBinaryStream().
|
|
|
|
@param usePostCommand whether to use a POST command to get the data (uses
|
|
a GET command if this is false)
|
|
@see readEntireBinaryStream, readEntireXmlStream
|
|
*/
|
|
String readEntireTextStream (bool usePostCommand = false) const;
|
|
|
|
/** Tries to download the entire contents of this URL and parse it as XML.
|
|
|
|
If it fails, or if the text that it reads can't be parsed as XML, this will
|
|
return 0.
|
|
|
|
When it returns a valid XmlElement object, the caller is responsibile for deleting
|
|
this object when no longer needed.
|
|
|
|
@param usePostCommand whether to use a POST command to get the data (uses
|
|
a GET command if this is false)
|
|
|
|
@see readEntireBinaryStream, readEntireTextStream
|
|
*/
|
|
XmlElement* readEntireXmlStream (bool usePostCommand = false) const;
|
|
|
|
//==============================================================================
|
|
/** Adds escape sequences to a string to encode any characters that aren't
|
|
legal in a URL.
|
|
|
|
E.g. any spaces will be replaced with "%20".
|
|
|
|
This is the opposite of removeEscapeChars().
|
|
|
|
If isParameter is true, it means that the string is going to be used
|
|
as a parameter, so it also encodes '$' and ',' (which would otherwise
|
|
be legal in a URL.
|
|
|
|
@see removeEscapeChars
|
|
*/
|
|
static String addEscapeChars (const String& stringToAddEscapeCharsTo,
|
|
bool isParameter);
|
|
|
|
/** Replaces any escape character sequences in a string with their original
|
|
character codes.
|
|
|
|
E.g. any instances of "%20" will be replaced by a space.
|
|
|
|
This is the opposite of addEscapeChars().
|
|
|
|
@see addEscapeChars
|
|
*/
|
|
static String removeEscapeChars (const String& stringToRemoveEscapeCharsFrom);
|
|
|
|
private:
|
|
//==============================================================================
|
|
String url, postData;
|
|
StringArray parameterNames, parameterValues;
|
|
StringPairArray filesToUpload, mimeTypes;
|
|
|
|
void addParameter (const String&, const String&);
|
|
|
|
static InputStream* createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,
|
|
OpenStreamProgressCallback* progressCallback,
|
|
void* progressCallbackContext, const String& headers,
|
|
const int timeOutMs, StringPairArray* responseHeaders);
|
|
};
|
|
|
|
|
|
#endif // BEAST_URL_H_INCLUDED
|