NetServices: format code using haiku-format

This commit formats all the netservices2 code with the `haiku-format` tool from
https://github.com/owenca/haiku-format (commit aa7408e), with the following
customizations:
 * SpaceBeforeRangeBasedForLoopColon is set to false
 * Braces before a catch block are not wrapped
 * Most headers, except for ExclusiveBorrow.h, have been manually reformatted
   to adhere to Haiku's header format (issue #19 in the repository)

Change-Id: I693c4515cf26402e48f35d1213ab6d5fcf14bd1e
This commit is contained in:
Niels Sascha Reedijk
2022-10-29 22:53:57 +01:00
parent 93069fc4bc
commit 71e29bbeea
31 changed files with 1502 additions and 1560 deletions
+40 -40
View File
@@ -18,74 +18,74 @@ namespace BPrivate {
namespace Network {
class BError {
class BError
{
public:
BError(const char* origin);
BError(BString origin);
virtual ~BError() noexcept;
BError(const char* origin);
BError(BString origin);
virtual ~BError() noexcept;
BError(const BError& error);
BError(BError&& error) noexcept;
BError(const BError& error);
BError(BError&& error) noexcept;
BError& operator=(const BError& error);
BError& operator=(BError&& error) noexcept;
BError& operator=(const BError& error);
BError& operator=(BError&& error) noexcept;
virtual const char* Message() const noexcept = 0;
virtual const char* Origin() const noexcept;
virtual BString DebugMessage() const;
void WriteToStream(std::ostream& stream) const;
size_t WriteToOutput(BDataIO* output) const;
virtual const char* Message() const noexcept = 0;
virtual const char* Origin() const noexcept;
virtual BString DebugMessage() const;
void WriteToStream(std::ostream& stream) const;
size_t WriteToOutput(BDataIO* output) const;
private:
virtual void _ReservedError1();
virtual void _ReservedError2();
virtual void _ReservedError3();
virtual void _ReservedError4();
virtual void _ReservedError1();
virtual void _ReservedError2();
virtual void _ReservedError3();
virtual void _ReservedError4();
private:
BString fOrigin;
BString fOrigin;
};
class BRuntimeError : public BError {
class BRuntimeError : public BError
{
public:
BRuntimeError(const char* origin, const char* message);
BRuntimeError(const char* origin, BString message);
BRuntimeError(BString origin, BString message);
BRuntimeError(const char* origin, const char* message);
BRuntimeError(const char* origin, BString message);
BRuntimeError(BString origin, BString message);
BRuntimeError(const BRuntimeError& other);
BRuntimeError(BRuntimeError&& other) noexcept;
BRuntimeError(const BRuntimeError& other);
BRuntimeError(BRuntimeError&& other) noexcept;
BRuntimeError& operator=(const BRuntimeError& other);
BRuntimeError& operator=(BRuntimeError&& other) noexcept;
BRuntimeError& operator=(const BRuntimeError& other);
BRuntimeError& operator=(BRuntimeError&& other) noexcept;
virtual const char* Message() const noexcept override;
virtual const char* Message() const noexcept override;
private:
BString fMessage;
BString fMessage;
};
class BSystemError : public BError
{
public:
BSystemError(const char* origin, status_t error);
BSystemError(BString origin, status_t error);
BSystemError(const char* origin, status_t error);
BSystemError(BString origin, status_t error);
BSystemError(const BSystemError& other);
BSystemError& operator=(const BSystemError& other);
BSystemError(const BSystemError& other);
BSystemError& operator=(const BSystemError& other);
#if __cplusplus >= 201103L
BSystemError(BSystemError&& other) noexcept;
BSystemError& operator=(BSystemError&& other) noexcept;
#endif
BSystemError(BSystemError&& other) noexcept;
BSystemError& operator=(BSystemError&& other) noexcept;
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
status_t Error() noexcept;
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
status_t Error() noexcept;
private:
status_t fErrorCode;
status_t fErrorCode;
};
} // namespace Network
+56 -104
View File
@@ -16,42 +16,37 @@ namespace BPrivate {
namespace Network {
class BBorrowError : public BError {
class BBorrowError : public BError
{
public:
BBorrowError(const char* origin)
: BError(origin)
:
BError(origin)
{
}
virtual const char*
Message() const noexcept override
{
return "BBorrowError";
}
virtual const char* Message() const noexcept override { return "BBorrowError"; }
};
class BorrowAdmin {
class BorrowAdmin
{
private:
static constexpr uint8 kOwned = 0x1;
static constexpr uint8 kBorrowed = 0x2;
std::atomic<uint8> fState = kOwned;
std::atomic<uint8> fState = kOwned;
protected:
virtual ~BorrowAdmin() = default;
virtual ~BorrowAdmin() = default;
virtual void Cleanup() noexcept {};
virtual void ReleasePointer() noexcept {};
virtual void Cleanup() noexcept {};
virtual void ReleasePointer() noexcept {};
public:
BorrowAdmin() noexcept
{
}
BorrowAdmin() noexcept {}
void
Borrow()
void Borrow()
{
auto alreadyBorrowed = (fState.fetch_or(kBorrowed) & kBorrowed) == kBorrowed;
if (alreadyBorrowed) {
@@ -60,8 +55,7 @@ public:
}
void
Return() noexcept
void Return() noexcept
{
auto cleanup = (fState.fetch_and(~kBorrowed) & kOwned) != kOwned;
if (cleanup)
@@ -69,8 +63,7 @@ public:
}
void
Forfeit() noexcept
void Forfeit() noexcept
{
auto cleanup = (fState.fetch_and(~kOwned) & kBorrowed) != kBorrowed;
if (cleanup)
@@ -78,15 +71,10 @@ public:
}
bool
IsBorrowed() noexcept
{
return (fState.load() & kBorrowed) == kBorrowed;
}
bool IsBorrowed() noexcept { return (fState.load() & kBorrowed) == kBorrowed; }
void
Release()
void Release()
{
if ((fState.load() & kBorrowed) == kBorrowed)
throw BBorrowError(__PRETTY_FUNCTION__);
@@ -96,57 +84,39 @@ public:
};
template <typename T>
class BorrowPointer : public BorrowAdmin
template<typename T> class BorrowPointer : public BorrowAdmin
{
public:
BorrowPointer(T* object) noexcept
: fPtr(object)
:
fPtr(object)
{
}
virtual ~BorrowPointer() {
delete fPtr;
}
virtual ~BorrowPointer() { delete fPtr; }
protected:
virtual void
Cleanup() noexcept override
{
delete this;
}
virtual void Cleanup() noexcept override { delete this; }
virtual void
ReleasePointer() noexcept override
{
fPtr = nullptr;
}
virtual void ReleasePointer() noexcept override { fPtr = nullptr; }
private:
T* fPtr;
T* fPtr;
};
template <typename T>
class BExclusiveBorrow {
template<typename P>
friend class BBorrow;
template<typename T> class BExclusiveBorrow
{
template<typename P> friend class BBorrow;
T* fPtr = nullptr;
BorrowAdmin* fAdminBlock = nullptr;
T* fPtr = nullptr;
BorrowAdmin* fAdminBlock = nullptr;
public:
BExclusiveBorrow() noexcept
{
}
BExclusiveBorrow() noexcept {}
BExclusiveBorrow(nullptr_t) noexcept
{
}
BExclusiveBorrow(nullptr_t) noexcept {}
BExclusiveBorrow(T* object)
@@ -178,8 +148,7 @@ public:
}
BExclusiveBorrow&
operator=(BExclusiveBorrow&& other) noexcept
BExclusiveBorrow& operator=(BExclusiveBorrow&& other) noexcept
{
if (fAdminBlock)
fAdminBlock->Forfeit();
@@ -191,15 +160,10 @@ public:
}
bool
HasValue() const noexcept
{
return bool(fPtr);
}
bool HasValue() const noexcept { return bool(fPtr); }
T&
operator*() const
T& operator*() const
{
if (fAdminBlock && !fAdminBlock->IsBorrowed())
return *fPtr;
@@ -207,8 +171,7 @@ public:
}
T*
operator->() const
T* operator->() const
{
if (fAdminBlock && !fAdminBlock->IsBorrowed())
return fPtr;
@@ -216,8 +179,7 @@ public:
}
std::unique_ptr<T>
Release()
std::unique_ptr<T> Release()
{
if (!fAdminBlock)
throw BBorrowError(__PRETTY_FUNCTION__);
@@ -230,27 +192,23 @@ public:
};
template <typename T>
class BBorrow {
T* fPtr = nullptr;
BorrowAdmin* fAdminBlock = nullptr;
template<typename T> class BBorrow
{
T* fPtr = nullptr;
BorrowAdmin* fAdminBlock = nullptr;
public:
BBorrow() noexcept
{
}
BBorrow() noexcept {}
BBorrow(nullptr_t) noexcept
{
}
BBorrow(nullptr_t) noexcept {}
template<typename P>
explicit BBorrow(BExclusiveBorrow<P>& owner)
: fPtr(owner.fPtr), fAdminBlock(owner.fAdminBlock)
:
fPtr(owner.fPtr),
fAdminBlock(owner.fAdminBlock)
{
fAdminBlock->Borrow();
}
@@ -263,15 +221,16 @@ public:
BBorrow(BBorrow&& other) noexcept
: fPtr(other.fPtr), fAdminBlock(other.fAdminBlock)
:
fPtr(other.fPtr),
fAdminBlock(other.fAdminBlock)
{
other.fPtr = nullptr;
other.fAdminBlock = nullptr;
}
BBorrow&
operator=(BBorrow&& other) noexcept
BBorrow& operator=(BBorrow&& other) noexcept
{
if (fAdminBlock)
fAdminBlock->Return();
@@ -291,15 +250,10 @@ public:
}
bool
HasValue() const noexcept
{
return bool(fPtr);
}
bool HasValue() const noexcept { return bool(fPtr); }
T&
operator*() const
T& operator*() const
{
if (fPtr)
return *fPtr;
@@ -307,8 +261,7 @@ public:
}
T*
operator->() const
T* operator->() const
{
if (fPtr)
return fPtr;
@@ -316,8 +269,7 @@ public:
}
void
Return() noexcept
void Return() noexcept
{
if (fAdminBlock)
fAdminBlock->Return();
@@ -327,9 +279,9 @@ public:
};
template<class T, class ..._Args>
template<class T, class... _Args>
BExclusiveBorrow<T>
make_exclusive_borrow(_Args&& ...__args)
make_exclusive_borrow(_Args&&... __args)
{
auto guardedObject = std::make_unique<T>(std::forward<_Args>(__args)...);
auto retval = BExclusiveBorrow<T>(guardedObject.get());
+77 -64
View File
@@ -21,70 +21,15 @@ namespace BPrivate {
namespace Network {
class BHttpFields {
class BHttpFields
{
public:
// Exceptions
class InvalidInput : public BError {
public:
InvalidInput(const char* origin, BString input);
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
BString input;
};
// Exceptions
class InvalidInput;
// Wrapper Types
class FieldName {
public:
// Comparison
bool operator==(const BString& other) const noexcept;
bool operator==(const std::string_view& other) const noexcept;
bool operator==(const FieldName& other) const noexcept;
// Conversion
operator std::string_view() const;
private:
friend class BHttpFields;
FieldName() noexcept;
FieldName(const std::string_view& name) noexcept;
FieldName(const FieldName& other) noexcept;
FieldName(FieldName&&) noexcept;
FieldName& operator=(const FieldName& other) noexcept;
FieldName& operator=(FieldName&&) noexcept;
std::string_view fName;
};
class Field {
public:
// Constructors
Field() noexcept;
Field(const std::string_view& name, const std::string_view& value);
Field(BString& field);
Field(const Field& other);
Field(Field&&) noexcept;
// Assignment
Field& operator=(const Field& other);
Field& operator=(Field&& other) noexcept;
// Access Operators
const FieldName& Name() const noexcept;
std::string_view Value() const noexcept;
std::string_view RawField() const noexcept;
bool IsEmpty() const noexcept;
private:
friend class BHttpFields;
Field(BString&& rawField);
std::optional<BString> fRawField;
FieldName fName;
std::string_view fValue;
};
class FieldName;
class Field;
// Type Aliases
using ConstIterator = std::list<Field>::const_iterator;
@@ -101,14 +46,14 @@ public:
BHttpFields& operator=(BHttpFields&&) noexcept;
// Access list
const Field& operator[](size_t index) const;
const Field& operator[](size_t index) const;
// Modifiers
void AddField(const std::string_view& name,
const std::string_view& value);
void AddField(BString& field);
void AddFields(std::initializer_list<Field> fields);
void RemoveField(const std::string_view& name) noexcept;
void RemoveField(const std::string_view& name) noexcept;
void RemoveField(ConstIterator it) noexcept;
void MakeEmpty() noexcept;
@@ -126,9 +71,77 @@ private:
};
class BHttpFields::InvalidInput : public BError
{
public:
InvalidInput(const char* origin, BString input);
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
BString input;
};
class BHttpFields::FieldName
{
public:
// Comparison
bool operator==(const BString& other) const noexcept;
bool operator==(const std::string_view& other) const noexcept;
bool operator==(const FieldName& other) const noexcept;
// Conversion
operator std::string_view() const;
private:
friend class BHttpFields;
FieldName() noexcept;
FieldName(const std::string_view& name) noexcept;
FieldName(const FieldName& other) noexcept;
FieldName(FieldName&&) noexcept;
FieldName& operator=(const FieldName& other) noexcept;
FieldName& operator=(FieldName&&) noexcept;
std::string_view fName;
};
class BHttpFields::Field
{
public:
// Constructors
Field() noexcept;
Field(const std::string_view& name, const std::string_view& value);
Field(BString& field);
Field(const Field& other);
Field(Field&&) noexcept;
// Assignment
Field& operator=(const Field& other);
Field& operator=(Field&& other) noexcept;
// Access Operators
const FieldName& Name() const noexcept;
std::string_view Value() const noexcept;
std::string_view RawField() const noexcept;
bool IsEmpty() const noexcept;
private:
friend class BHttpFields;
Field(BString&& rawField);
std::optional<BString> fRawField;
FieldName fName;
std::string_view fValue;
};
} // namespace Network
} // namespace BPrivate
#endif // _B_HTTP_FIELDS_H_
+61 -61
View File
@@ -29,30 +29,14 @@ class HttpBuffer;
class HttpSerializer;
class BHttpMethod {
class BHttpMethod
{
public:
// Constants for default methods in RFC 7230 section 4.2
enum Verb {
Get,
Head,
Post,
Put,
Delete,
Connect,
Options,
Trace
};
enum Verb { Get, Head, Post, Put, Delete, Connect, Options, Trace };
// Error type when constructing with a custom method
class InvalidMethod : public BError {
public:
InvalidMethod(const char* origin, BString input);
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
BString input;
};
class InvalidMethod;
// Constructors & Destructor
BHttpMethod(Verb verb) noexcept;
@@ -70,78 +54,94 @@ public:
bool operator!=(const Verb& other) const noexcept;
// Get the method as a string
const std::string_view Method() const noexcept;
const std::string_view Method() const noexcept;
private:
std::variant<Verb, BString> fMethod;
std::variant<Verb, BString> fMethod;
};
class BHttpMethod::InvalidMethod : public BError
{
public:
InvalidMethod(const char* origin, BString input);
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
BString input;
};
struct BHttpAuthentication {
BString username;
BString password;
BString username;
BString password;
};
class BHttpRequest {
class BHttpRequest
{
public:
// Aggregate parameter types
struct Body {
std::unique_ptr<BDataIO> input;
BString mimeType;
std::optional<off_t> size;
std::optional<off_t> startPosition;
};
struct Body;
// Constructors and Destructor
BHttpRequest();
BHttpRequest(const BUrl& url);
BHttpRequest(const BHttpRequest& other) = delete;
BHttpRequest(BHttpRequest&& other) noexcept;
~BHttpRequest();
BHttpRequest();
BHttpRequest(const BUrl& url);
BHttpRequest(const BHttpRequest& other) = delete;
BHttpRequest(BHttpRequest&& other) noexcept;
~BHttpRequest();
// Assignment operators
BHttpRequest& operator=(const BHttpRequest& other) = delete;
BHttpRequest& operator=(BHttpRequest&&) noexcept;
BHttpRequest& operator=(const BHttpRequest& other) = delete;
BHttpRequest& operator=(BHttpRequest&&) noexcept;
// Access
bool IsEmpty() const noexcept;
const BHttpAuthentication* Authentication() const noexcept;
const BHttpFields& Fields() const noexcept;
uint8 MaxRedirections() const noexcept;
const BHttpMethod& Method() const noexcept;
const Body* RequestBody() const noexcept;
bool StopOnError() const noexcept;
bigtime_t Timeout() const noexcept;
const BUrl& Url() const noexcept;
bool IsEmpty() const noexcept;
const BHttpAuthentication* Authentication() const noexcept;
const BHttpFields& Fields() const noexcept;
uint8 MaxRedirections() const noexcept;
const BHttpMethod& Method() const noexcept;
const Body* RequestBody() const noexcept;
bool StopOnError() const noexcept;
bigtime_t Timeout() const noexcept;
const BUrl& Url() const noexcept;
// Named Setters
void SetAuthentication(const BHttpAuthentication& authentication);
void SetFields(const BHttpFields& fields);
void SetMaxRedirections(uint8 maxRedirections);
void SetMethod(const BHttpMethod& method);
void SetRequestBody(std::unique_ptr<BDataIO> input,
BString mimeType, std::optional<off_t> size);
void SetStopOnError(bool stopOnError);
void SetTimeout(bigtime_t timeout);
void SetUrl(const BUrl& url);
void SetAuthentication(const BHttpAuthentication& authentication);
void SetFields(const BHttpFields& fields);
void SetMaxRedirections(uint8 maxRedirections);
void SetMethod(const BHttpMethod& method);
void SetRequestBody(std::unique_ptr<BDataIO> input, BString mimeType,
std::optional<off_t> size);
void SetStopOnError(bool stopOnError);
void SetTimeout(bigtime_t timeout);
void SetUrl(const BUrl& url);
// Clearing Options
void ClearAuthentication() noexcept;
void ClearAuthentication() noexcept;
std::unique_ptr<BDataIO> ClearRequestBody() noexcept;
// Serialization
BString HeaderToString() const;
BString HeaderToString() const;
private:
friend class BHttpSession;
friend class HttpSerializer;
struct Data;
bool RewindBody() noexcept;
void SerializeHeaderTo(HttpBuffer& buffer) const;
bool RewindBody() noexcept;
void SerializeHeaderTo(HttpBuffer& buffer) const;
std::unique_ptr<Data> fData;
std::unique_ptr<Data> fData;
};
struct BHttpRequest::Body {
std::unique_ptr<BDataIO> input;
BString mimeType;
std::optional<off_t> size;
std::optional<off_t> startPosition;
};
+28 -30
View File
@@ -22,19 +22,18 @@ class BHttpFields;
struct HttpResultPrivate;
struct BHttpBody
{
std::optional<BString> text;
struct BHttpBody {
std::optional<BString> text;
};
enum class BHttpStatusClass : int16 {
Invalid = 000,
Informational = 100,
Success = 200,
Redirection = 300,
ClientError = 400,
ServerError = 500
Invalid = 000,
Informational = 100,
Success = 200,
Redirection = 300,
ClientError = 400,
ServerError = 500
};
@@ -93,14 +92,13 @@ enum class BHttpStatusCode : int16 {
};
struct BHttpStatus
{
int16 code = 0;
BString text;
struct BHttpStatus {
int16 code = 0;
BString text;
// Helpers
BHttpStatusClass StatusClass() const noexcept;
BHttpStatusCode StatusCode() const noexcept;
BHttpStatusClass StatusClass() const noexcept;
BHttpStatusCode StatusCode() const noexcept;
};
@@ -108,32 +106,32 @@ class BHttpResult
{
public:
// Constructors and destructor
BHttpResult(const BHttpResult& other) = delete;
BHttpResult(BHttpResult&& other) noexcept;
~BHttpResult();
BHttpResult(const BHttpResult& other) = delete;
BHttpResult(BHttpResult&& other) noexcept;
~BHttpResult();
// Assignment operators
BHttpResult& operator=(const BHttpResult& other) = delete;
BHttpResult& operator=(BHttpResult&& other) noexcept;
BHttpResult& operator=(const BHttpResult& other) = delete;
BHttpResult& operator=(BHttpResult&& other) noexcept;
// Blocking Access Functions
const BHttpStatus& Status() const;
const BHttpFields& Fields() const;
BHttpBody& Body() const;
const BHttpStatus& Status() const;
const BHttpFields& Fields() const;
BHttpBody& Body() const;
// Check if data is available yet
bool HasStatus() const;
bool HasFields() const;
bool HasBody() const;
bool IsCompleted() const;
bool HasStatus() const;
bool HasFields() const;
bool HasBody() const;
bool IsCompleted() const;
// Identity
int32 Identity() const;
int32 Identity() const;
private:
friend class BHttpSession;
BHttpResult(std::shared_ptr<HttpResultPrivate> data);
std::shared_ptr<HttpResultPrivate> fData;
BHttpResult(std::shared_ptr<HttpResultPrivate> data);
std::shared_ptr<HttpResultPrivate> fData;
};
+21 -26
View File
@@ -22,53 +22,48 @@ class BHttpRequest;
class BHttpResult;
class BHttpSession {
class BHttpSession
{
public:
// Constructors & Destructor
BHttpSession();
BHttpSession(const BHttpSession&) noexcept;
BHttpSession(BHttpSession&&) noexcept = delete;
~BHttpSession() noexcept;
BHttpSession();
BHttpSession(const BHttpSession&) noexcept;
BHttpSession(BHttpSession&&) noexcept = delete;
~BHttpSession() noexcept;
// Assignment operators
BHttpSession& operator=(const BHttpSession&) noexcept;
BHttpSession& operator=(BHttpSession&&) noexcept = delete;
BHttpSession& operator=(const BHttpSession&) noexcept;
BHttpSession& operator=(BHttpSession&&) noexcept = delete;
// Requests
BHttpResult Execute(BHttpRequest&& request,
BBorrow<BDataIO> target = nullptr,
BMessenger observer = BMessenger());
void Cancel(int32 identifier);
void Cancel(const BHttpResult& request);
BHttpResult Execute(BHttpRequest&& request, BBorrow<BDataIO> target = nullptr,
BMessenger observer = BMessenger());
void Cancel(int32 identifier);
void Cancel(const BHttpResult& request);
// Concurrency limits
void SetMaxConnectionsPerHost(size_t maxConnections);
void SetMaxHosts(size_t maxConnections);
void SetMaxConnectionsPerHost(size_t maxConnections);
void SetMaxHosts(size_t maxConnections);
private:
struct Redirect;
class Request;
class Impl;
std::shared_ptr<Impl> fImpl;
std::shared_ptr<Impl> fImpl;
};
namespace UrlEvent {
enum {
HttpStatus = '_HST',
HttpFields = '_HHF',
CertificateError = '_CER',
HttpRedirect = '_HRE'
};
enum { HttpStatus = '_HST', HttpFields = '_HHF', CertificateError = '_CER', HttpRedirect = '_HRE' };
}
namespace UrlEventData {
extern const char* HttpStatusCode;
extern const char* SSLCertificate;
extern const char* SSLMessage;
extern const char* HttpRedirectUrl;
}
extern const char* HttpStatusCode;
extern const char* SSLCertificate;
extern const char* SSLMessage;
extern const char* HttpRedirectUrl;
} // namespace UrlEventData
} // namespace Network
+30 -28
View File
@@ -15,52 +15,54 @@ namespace BPrivate {
namespace Network {
enum class BHttpTimeFormat : int8 {
RFC1123 = 0,
RFC850,
AscTime
};
enum class BHttpTimeFormat : int8 { RFC1123 = 0, RFC850, AscTime };
class BHttpTime {
class BHttpTime
{
public:
// Error type
class InvalidInput : public BError {
public:
InvalidInput(const char* origin, BString input);
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
BString input;
};
class InvalidInput;
// Constructors
BHttpTime() noexcept;
BHttpTime(BDateTime date);
BHttpTime(const BString& dateString);
BHttpTime() noexcept;
BHttpTime(BDateTime date);
BHttpTime(const BString& dateString);
// Date modification
void SetTo(const BString& string);
void SetTo(BDateTime date);
void SetTo(const BString& string);
void SetTo(BDateTime date);
// Date Access
BDateTime DateTime() const noexcept;
BHttpTimeFormat DateTimeFormat() const noexcept;
BString ToString(BHttpTimeFormat outputFormat = BHttpTimeFormat::RFC1123) const;
BDateTime DateTime() const noexcept;
BHttpTimeFormat DateTimeFormat() const noexcept;
BString ToString(BHttpTimeFormat outputFormat
= BHttpTimeFormat::RFC1123) const;
private:
void _Parse(const BString& dateString);
void _Parse(const BString& dateString);
BDateTime fDate;
BHttpTimeFormat fDateFormat;
BDateTime fDate;
BHttpTimeFormat fDateFormat;
};
class BHttpTime::InvalidInput : public BError
{
public:
InvalidInput(const char* origin, BString input);
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
BString input;
};
// Convenience functions
BDateTime parse_http_time(const BString& string);
BString format_http_time(BDateTime timestamp,
BDateTime parse_http_time(const BString& string);
BString format_http_time(BDateTime timestamp,
BHttpTimeFormat outputFormat = BHttpTimeFormat::RFC1123);
+54 -61
View File
@@ -18,65 +18,62 @@ namespace Network {
// Standard exceptions
class BUnsupportedProtocol : public BError {
class BUnsupportedProtocol : public BError
{
public:
BUnsupportedProtocol(const char* origin, BUrl url,
BStringList supportedProtocols);
BUnsupportedProtocol(BString origin, BUrl url,
BStringList supportedProtocols);
BUnsupportedProtocol(const char* origin, BUrl url,
BStringList supportedProtocols);
BUnsupportedProtocol(BString origin, BUrl url,
BStringList supportedProtocols);
virtual const char* Message() const noexcept override;
virtual const char* Message() const noexcept override;
const BUrl& Url() const;
const BStringList& SupportedProtocols() const;
const BUrl& Url() const;
const BStringList& SupportedProtocols() const;
private:
BUrl fUrl;
BStringList fSupportedProtocols;
BUrl fUrl;
BStringList fSupportedProtocols;
};
class BInvalidUrl : public BError {
class BInvalidUrl : public BError
{
public:
BInvalidUrl(const char* origin, BUrl url);
BInvalidUrl(BString origin, BUrl url);
BInvalidUrl(const char* origin, BUrl url);
BInvalidUrl(BString origin, BUrl url);
virtual const char* Message() const noexcept override;
virtual const char* Message() const noexcept override;
const BUrl& Url() const;
const BUrl& Url() const;
private:
BUrl fUrl;
BUrl fUrl;
};
class BNetworkRequestError : public BError {
class BNetworkRequestError : public BError
{
public:
enum ErrorType {
HostnameError,
NetworkError,
ProtocolError,
SystemError,
Canceled
};
enum ErrorType { HostnameError, NetworkError, ProtocolError, SystemError, Canceled };
BNetworkRequestError(const char* origin, ErrorType type,
status_t errorCode, const BString& customMessage = BString());
BNetworkRequestError(const char* origin, ErrorType type,
const BString& customMessage = BString());
BNetworkRequestError(const char* origin, ErrorType type,
status_t errorCode, const BString& customMessage = BString());
BNetworkRequestError(const char* origin, ErrorType type,
const BString& customMessage = BString());
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
virtual const char* Message() const noexcept override;
virtual BString DebugMessage() const override;
ErrorType Type() const noexcept;
status_t ErrorCode() const noexcept;
ErrorType Type() const noexcept;
status_t ErrorCode() const noexcept;
const char* CustomMessage() const noexcept;
const char* CustomMessage() const noexcept;
private:
ErrorType fErrorType;
status_t fErrorCode = B_OK;
BString fCustomMessage;
ErrorType fErrorType;
status_t fErrorCode = B_OK;
BString fCustomMessage;
};
@@ -84,37 +81,33 @@ BString encode_to_base64(const BString& string);
namespace UrlEvent {
enum {
HostNameResolved = '_NHR',
ConnectionOpened = '_NCO',
UploadProgress = '_NUP',
ResponseStarted = '_NRS',
DownloadProgress = '_NDP',
BytesWritten = '_NBW',
RequestCompleted = '_NRC',
DebugMessage = '_NDB'
};
enum {
HostNameResolved = '_NHR',
ConnectionOpened = '_NCO',
UploadProgress = '_NUP',
ResponseStarted = '_NRS',
DownloadProgress = '_NDP',
BytesWritten = '_NBW',
RequestCompleted = '_NRC',
DebugMessage = '_NDB'
};
}
namespace UrlEventData {
extern const char* Id;
extern const char* HostName;
extern const char* NumBytes;
extern const char* TotalBytes;
extern const char* Success;
extern const char* DebugType;
extern const char* DebugMessage;
extern const char* Id;
extern const char* HostName;
extern const char* NumBytes;
extern const char* TotalBytes;
extern const char* Success;
extern const char* DebugType;
extern const char* DebugMessage;
enum {
DebugInfo = '_DBI',
DebugWarning = '_DBW',
DebugError = '_DBE'
};
}
enum { DebugInfo = '_DBI', DebugWarning = '_DBW', DebugError = '_DBE' };
} // namespace UrlEventData
}
} // namespace Network
}
} // namespace BPrivate
#endif