1/*
2 * Copyright 2021 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6#ifndef _NETSERVICES_DEFS_H_
7#define _NETSERVICES_DEFS_H_
8
9
10#include <ErrorsExt.h>
11#include <StringList.h>
12#include <Url.h>
13
14
15namespace BPrivate {
16
17namespace Network {
18
19
20// Standard exceptions
21class BUnsupportedProtocol : public BError
22{
23public:
24								BUnsupportedProtocol(const char* origin, BUrl url,
25									BStringList supportedProtocols);
26								BUnsupportedProtocol(BString origin, BUrl url,
27									BStringList supportedProtocols);
28
29	virtual	const char*			Message() const noexcept override;
30
31			const BUrl&			Url() const;
32			const BStringList&	SupportedProtocols() const;
33
34private:
35			BUrl				fUrl;
36			BStringList			fSupportedProtocols;
37};
38
39
40class BInvalidUrl : public BError
41{
42public:
43								BInvalidUrl(const char* origin, BUrl url);
44								BInvalidUrl(BString origin, BUrl url);
45
46	virtual	const char*			Message() const noexcept override;
47
48			const BUrl&				Url() const;
49
50private:
51			BUrl				fUrl;
52};
53
54
55class BNetworkRequestError : public BError
56{
57public:
58	enum ErrorType { HostnameError, NetworkError, ProtocolError, SystemError, Canceled };
59
60								BNetworkRequestError(const char* origin, ErrorType type,
61									status_t errorCode, const BString& customMessage = BString());
62								BNetworkRequestError(const char* origin, ErrorType type,
63									const BString& customMessage = BString());
64
65	virtual	const char*			Message() const noexcept override;
66	virtual	BString				DebugMessage() const override;
67
68			ErrorType			Type() const noexcept;
69			status_t			ErrorCode() const noexcept;
70
71			const char*			CustomMessage() const noexcept;
72
73private:
74			ErrorType			fErrorType;
75			status_t			fErrorCode = B_OK;
76			BString				fCustomMessage;
77};
78
79
80BString encode_to_base64(const BString& string);
81
82
83namespace UrlEvent {
84enum {
85	HostNameResolved = '_NHR',
86	ConnectionOpened = '_NCO',
87	UploadProgress = '_NUP',
88	ResponseStarted = '_NRS',
89	DownloadProgress = '_NDP',
90	BytesWritten = '_NBW',
91	RequestCompleted = '_NRC',
92	DebugMessage = '_NDB'
93};
94}
95
96
97namespace UrlEventData {
98extern const char* Id;
99extern const char* HostName;
100extern const char* NumBytes;
101extern const char* TotalBytes;
102extern const char* Success;
103extern const char* DebugType;
104extern const char* DebugMessage;
105
106enum { DebugInfo = '_DBI', DebugWarning = '_DBW', DebugError = '_DBE' };
107} // namespace UrlEventData
108
109} // namespace Network
110
111} // namespace BPrivate
112
113#endif
114