2021-09-13 09:37:49 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Haiku Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETSERVICES_DEFS_H_
|
|
|
|
#define _NETSERVICES_DEFS_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <ErrorsExt.h>
|
|
|
|
#include <StringList.h>
|
|
|
|
#include <Url.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
namespace Network {
|
|
|
|
|
|
|
|
|
|
|
|
// Standard exceptions
|
2022-10-30 00:45:39 +03:00
|
|
|
class BUnsupportedProtocol : public BError
|
|
|
|
{
|
2021-09-13 09:37:49 +03:00
|
|
|
public:
|
2022-10-30 00:45:39 +03:00
|
|
|
BUnsupportedProtocol(const char* origin, BUrl url,
|
|
|
|
BStringList supportedProtocols);
|
|
|
|
BUnsupportedProtocol(BString origin, BUrl url,
|
|
|
|
BStringList supportedProtocols);
|
2021-09-13 09:37:49 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
virtual const char* Message() const noexcept override;
|
2021-09-13 09:37:49 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
const BUrl& Url() const;
|
|
|
|
const BStringList& SupportedProtocols() const;
|
2021-09-13 09:37:49 +03:00
|
|
|
|
|
|
|
private:
|
2022-10-30 00:45:39 +03:00
|
|
|
BUrl fUrl;
|
|
|
|
BStringList fSupportedProtocols;
|
2021-09-13 09:37:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
class BInvalidUrl : public BError
|
|
|
|
{
|
2021-09-13 09:37:49 +03:00
|
|
|
public:
|
2022-10-30 00:45:39 +03:00
|
|
|
BInvalidUrl(const char* origin, BUrl url);
|
|
|
|
BInvalidUrl(BString origin, BUrl url);
|
2021-09-13 09:37:49 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
virtual const char* Message() const noexcept override;
|
2021-09-13 09:37:49 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
const BUrl& Url() const;
|
2021-09-13 09:37:49 +03:00
|
|
|
|
|
|
|
private:
|
2022-10-30 00:45:39 +03:00
|
|
|
BUrl fUrl;
|
2021-09-13 09:37:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
class BNetworkRequestError : public BError
|
|
|
|
{
|
2022-03-07 10:59:03 +03:00
|
|
|
public:
|
2022-10-30 00:45:39 +03:00
|
|
|
enum ErrorType { HostnameError, NetworkError, ProtocolError, SystemError, Canceled };
|
2022-03-07 10:59:03 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
BNetworkRequestError(const char* origin, ErrorType type,
|
|
|
|
status_t errorCode, const BString& customMessage = BString());
|
|
|
|
BNetworkRequestError(const char* origin, ErrorType type,
|
|
|
|
const BString& customMessage = BString());
|
2022-03-07 10:59:03 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
virtual const char* Message() const noexcept override;
|
|
|
|
virtual BString DebugMessage() const override;
|
2022-03-07 10:59:03 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
ErrorType Type() const noexcept;
|
|
|
|
status_t ErrorCode() const noexcept;
|
2022-03-07 10:59:03 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
const char* CustomMessage() const noexcept;
|
2022-08-07 10:47:19 +03:00
|
|
|
|
2022-03-07 10:59:03 +03:00
|
|
|
private:
|
2022-10-30 00:45:39 +03:00
|
|
|
ErrorType fErrorType;
|
|
|
|
status_t fErrorCode = B_OK;
|
|
|
|
BString fCustomMessage;
|
2022-03-07 10:59:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-05-29 17:13:54 +03:00
|
|
|
BString encode_to_base64(const BString& string);
|
|
|
|
|
|
|
|
|
2022-07-24 10:56:02 +03:00
|
|
|
namespace UrlEvent {
|
2022-10-30 00:45:39 +03:00
|
|
|
enum {
|
|
|
|
HostNameResolved = '_NHR',
|
|
|
|
ConnectionOpened = '_NCO',
|
|
|
|
UploadProgress = '_NUP',
|
|
|
|
ResponseStarted = '_NRS',
|
|
|
|
DownloadProgress = '_NDP',
|
|
|
|
BytesWritten = '_NBW',
|
|
|
|
RequestCompleted = '_NRC',
|
|
|
|
DebugMessage = '_NDB'
|
|
|
|
};
|
2022-07-24 10:56:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace UrlEventData {
|
2022-10-30 00:45:39 +03:00
|
|
|
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;
|
2022-07-24 10:56:02 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
enum { DebugInfo = '_DBI', DebugWarning = '_DBW', DebugError = '_DBE' };
|
|
|
|
} // namespace UrlEventData
|
2021-09-13 09:37:49 +03:00
|
|
|
|
2022-10-30 00:45:39 +03:00
|
|
|
} // namespace Network
|
|
|
|
|
|
|
|
} // namespace BPrivate
|
2021-09-13 09:37:49 +03:00
|
|
|
|
|
|
|
#endif
|