1ec7d71e6SNiels Sascha Reedijk /* 2ec7d71e6SNiels Sascha Reedijk * Copyright 2021 Haiku Inc. All rights reserved. 3ec7d71e6SNiels Sascha Reedijk * Distributed under the terms of the MIT License. 4ec7d71e6SNiels Sascha Reedijk */ 5ec7d71e6SNiels Sascha Reedijk 6ec7d71e6SNiels Sascha Reedijk #ifndef _NETSERVICES_DEFS_H_ 7ec7d71e6SNiels Sascha Reedijk #define _NETSERVICES_DEFS_H_ 8ec7d71e6SNiels Sascha Reedijk 9ec7d71e6SNiels Sascha Reedijk 10ec7d71e6SNiels Sascha Reedijk #include <ErrorsExt.h> 11ec7d71e6SNiels Sascha Reedijk #include <StringList.h> 12ec7d71e6SNiels Sascha Reedijk #include <Url.h> 13ec7d71e6SNiels Sascha Reedijk 14ec7d71e6SNiels Sascha Reedijk 15ec7d71e6SNiels Sascha Reedijk namespace BPrivate { 16ec7d71e6SNiels Sascha Reedijk 17ec7d71e6SNiels Sascha Reedijk namespace Network { 18ec7d71e6SNiels Sascha Reedijk 19ec7d71e6SNiels Sascha Reedijk 20ec7d71e6SNiels Sascha Reedijk // Standard exceptions 21*71e29bbeSNiels Sascha Reedijk class BUnsupportedProtocol : public BError 22*71e29bbeSNiels Sascha Reedijk { 23ec7d71e6SNiels Sascha Reedijk public: 24ec7d71e6SNiels Sascha Reedijk BUnsupportedProtocol(const char* origin, BUrl url, 25ec7d71e6SNiels Sascha Reedijk BStringList supportedProtocols); 26ec7d71e6SNiels Sascha Reedijk BUnsupportedProtocol(BString origin, BUrl url, 27ec7d71e6SNiels Sascha Reedijk BStringList supportedProtocols); 28ec7d71e6SNiels Sascha Reedijk 29ec7d71e6SNiels Sascha Reedijk virtual const char* Message() const noexcept override; 30ec7d71e6SNiels Sascha Reedijk 31ec7d71e6SNiels Sascha Reedijk const BUrl& Url() const; 32ec7d71e6SNiels Sascha Reedijk const BStringList& SupportedProtocols() const; 33ec7d71e6SNiels Sascha Reedijk 34ec7d71e6SNiels Sascha Reedijk private: 35ec7d71e6SNiels Sascha Reedijk BUrl fUrl; 36ec7d71e6SNiels Sascha Reedijk BStringList fSupportedProtocols; 37ec7d71e6SNiels Sascha Reedijk }; 38ec7d71e6SNiels Sascha Reedijk 39ec7d71e6SNiels Sascha Reedijk 40*71e29bbeSNiels Sascha Reedijk class BInvalidUrl : public BError 41*71e29bbeSNiels Sascha Reedijk { 42ec7d71e6SNiels Sascha Reedijk public: 43ec7d71e6SNiels Sascha Reedijk BInvalidUrl(const char* origin, BUrl url); 44ec7d71e6SNiels Sascha Reedijk BInvalidUrl(BString origin, BUrl url); 45ec7d71e6SNiels Sascha Reedijk 46ec7d71e6SNiels Sascha Reedijk virtual const char* Message() const noexcept override; 47ec7d71e6SNiels Sascha Reedijk 48ec7d71e6SNiels Sascha Reedijk const BUrl& Url() const; 49ec7d71e6SNiels Sascha Reedijk 50ec7d71e6SNiels Sascha Reedijk private: 51ec7d71e6SNiels Sascha Reedijk BUrl fUrl; 52ec7d71e6SNiels Sascha Reedijk }; 53ec7d71e6SNiels Sascha Reedijk 54ec7d71e6SNiels Sascha Reedijk 55*71e29bbeSNiels Sascha Reedijk class BNetworkRequestError : public BError 56*71e29bbeSNiels Sascha Reedijk { 573b2aa6c3SNiels Sascha Reedijk public: 58*71e29bbeSNiels Sascha Reedijk enum ErrorType { HostnameError, NetworkError, ProtocolError, SystemError, Canceled }; 593b2aa6c3SNiels Sascha Reedijk 603b2aa6c3SNiels Sascha Reedijk BNetworkRequestError(const char* origin, ErrorType type, 619cb56a48SNiels Sascha Reedijk status_t errorCode, const BString& customMessage = BString()); 629cb56a48SNiels Sascha Reedijk BNetworkRequestError(const char* origin, ErrorType type, 639cb56a48SNiels Sascha Reedijk const BString& customMessage = BString()); 643b2aa6c3SNiels Sascha Reedijk 653b2aa6c3SNiels Sascha Reedijk virtual const char* Message() const noexcept override; 663b2aa6c3SNiels Sascha Reedijk virtual BString DebugMessage() const override; 673b2aa6c3SNiels Sascha Reedijk 683b2aa6c3SNiels Sascha Reedijk ErrorType Type() const noexcept; 693b2aa6c3SNiels Sascha Reedijk status_t ErrorCode() const noexcept; 703b2aa6c3SNiels Sascha Reedijk 719cb56a48SNiels Sascha Reedijk const char* CustomMessage() const noexcept; 729cb56a48SNiels Sascha Reedijk 733b2aa6c3SNiels Sascha Reedijk private: 743b2aa6c3SNiels Sascha Reedijk ErrorType fErrorType; 753b2aa6c3SNiels Sascha Reedijk status_t fErrorCode = B_OK; 769cb56a48SNiels Sascha Reedijk BString fCustomMessage; 773b2aa6c3SNiels Sascha Reedijk }; 783b2aa6c3SNiels Sascha Reedijk 793b2aa6c3SNiels Sascha Reedijk 80f9d9d202SNiels Sascha Reedijk BString encode_to_base64(const BString& string); 81f9d9d202SNiels Sascha Reedijk 82f9d9d202SNiels Sascha Reedijk 8360355daeSNiels Sascha Reedijk namespace UrlEvent { 8460355daeSNiels Sascha Reedijk enum { 8560355daeSNiels Sascha Reedijk HostNameResolved = '_NHR', 8660355daeSNiels Sascha Reedijk ConnectionOpened = '_NCO', 8760355daeSNiels Sascha Reedijk UploadProgress = '_NUP', 8860355daeSNiels Sascha Reedijk ResponseStarted = '_NRS', 8960355daeSNiels Sascha Reedijk DownloadProgress = '_NDP', 9060355daeSNiels Sascha Reedijk BytesWritten = '_NBW', 9160355daeSNiels Sascha Reedijk RequestCompleted = '_NRC', 9260355daeSNiels Sascha Reedijk DebugMessage = '_NDB' 9360355daeSNiels Sascha Reedijk }; 9460355daeSNiels Sascha Reedijk } 9560355daeSNiels Sascha Reedijk 9660355daeSNiels Sascha Reedijk 9760355daeSNiels Sascha Reedijk namespace UrlEventData { 9860355daeSNiels Sascha Reedijk extern const char* Id; 9960355daeSNiels Sascha Reedijk extern const char* HostName; 10060355daeSNiels Sascha Reedijk extern const char* NumBytes; 10160355daeSNiels Sascha Reedijk extern const char* TotalBytes; 10260355daeSNiels Sascha Reedijk extern const char* Success; 10360355daeSNiels Sascha Reedijk extern const char* DebugType; 10460355daeSNiels Sascha Reedijk extern const char* DebugMessage; 1058a16ecbcSNiels Sascha Reedijk 106*71e29bbeSNiels Sascha Reedijk enum { DebugInfo = '_DBI', DebugWarning = '_DBW', DebugError = '_DBE' }; 107*71e29bbeSNiels Sascha Reedijk } // namespace UrlEventData 10860355daeSNiels Sascha Reedijk 109*71e29bbeSNiels Sascha Reedijk } // namespace Network 110ec7d71e6SNiels Sascha Reedijk 111*71e29bbeSNiels Sascha Reedijk } // namespace BPrivate 112ec7d71e6SNiels Sascha Reedijk 113ec7d71e6SNiels Sascha Reedijk #endif 114