xref: /haiku/headers/private/netservices2/NetServicesDefs.h (revision 99d1318ec02694fc520a0dc38ae38565db7e8c3c)
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 
15 namespace BPrivate {
16 
17 namespace Network {
18 
19 
20 // Standard exceptions
21 class BUnsupportedProtocol : public BError
22 {
23 public:
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 
34 private:
35 			BUrl				fUrl;
36 			BStringList			fSupportedProtocols;
37 };
38 
39 
40 class BInvalidUrl : public BError
41 {
42 public:
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 
50 private:
51 			BUrl				fUrl;
52 };
53 
54 
55 class BNetworkRequestError : public BError
56 {
57 public:
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 
73 private:
74 			ErrorType			fErrorType;
75 			status_t			fErrorCode = B_OK;
76 			BString				fCustomMessage;
77 };
78 
79 
80 BString encode_to_base64(const BString& string);
81 
82 
83 namespace UrlEvent {
84 enum {
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 
97 namespace UrlEventData {
98 extern const char* Id;
99 extern const char* HostName;
100 extern const char* NumBytes;
101 extern const char* TotalBytes;
102 extern const char* Success;
103 extern const char* DebugType;
104 extern const char* DebugMessage;
105 
106 enum { DebugInfo = '_DBI', DebugWarning = '_DBW', DebugError = '_DBE' };
107 } // namespace UrlEventData
108 
109 } // namespace Network
110 
111 } // namespace BPrivate
112 
113 #endif
114