diff options
author | Mattes D <github@xoft.cz> | 2016-03-01 16:58:43 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2016-03-01 16:58:43 +0100 |
commit | 7cc8f8dd2213cade66633d196f579895385a869a (patch) | |
tree | 83219a6eaf87a2050c10662fb8caa5d1514a6af4 /src/HTTP/UrlParser.h | |
parent | Merge pull request #3057 from tonibm19/master (diff) | |
parent | HTTP: Fixed typos and bad leftovers. (diff) | |
download | cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.gz cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.bz2 cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.lz cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.xz cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.zst cuberite-7cc8f8dd2213cade66633d196f579895385a869a.zip |
Diffstat (limited to 'src/HTTP/UrlParser.h')
-rw-r--r-- | src/HTTP/UrlParser.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/HTTP/UrlParser.h b/src/HTTP/UrlParser.h new file mode 100644 index 000000000..15a63e05d --- /dev/null +++ b/src/HTTP/UrlParser.h @@ -0,0 +1,58 @@ + +// UrlParser.h + +// Declares the cUrlParser class that parses string URL into individual parts + + + + + +#pragma once + + + + + +class cUrlParser +{ +public: + /** Returns true if the specified scheme (http, ftp, mailto, ...) is recognized by the URL parser. + Is case sensitive, known schemes are always lowercase. */ + static bool IsKnownScheme(const AString & a_Scheme) { return (GetDefaultPort(a_Scheme) > 0); } + + /** Returns the default port used by the specified scheme / protocol. + If the scheme is not known, 0 is returned. */ + static UInt16 GetDefaultPort(const AString & a_Scheme); + + /** Parses the given Authority part of an URL into individual components. + Returns true on success, + returns false and error message on failure. */ + static std::pair<bool, AString> ParseAuthorityPart( + const AString & a_AuthorityPart, + AString & a_Username, + AString & a_Password, + AString & a_Host, + UInt16 & a_Port + ); + + /** Parses the given URL into individual components. + Returns true on success, + returns false and error message on failure. + Fails if the scheme (protocol) is not known. + If port is missing, the default port for the specific scheme is applied. */ + static std::pair<bool, AString> Parse( + const AString & a_Url, + AString & a_Scheme, + AString & a_Username, + AString & a_Password, + AString & a_Host, + UInt16 & a_Port, + AString & a_Path, + AString & a_Query, + AString & a_Fragment + ); +}; + + + + |