2 * Copyright 2010-2017 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _B_URL_PROTOCOL_LISTENER_H_
6 #define _B_URL_PROTOCOL_LISTENER_H_
12 #include <UrlResult.h>
19 enum BUrlProtocolDebugMessage
{
20 B_URL_PROTOCOL_DEBUG_TEXT
,
21 B_URL_PROTOCOL_DEBUG_ERROR
,
22 B_URL_PROTOCOL_DEBUG_HEADER_IN
,
23 B_URL_PROTOCOL_DEBUG_HEADER_OUT
,
24 B_URL_PROTOCOL_DEBUG_TRANSFER_IN
,
25 B_URL_PROTOCOL_DEBUG_TRANSFER_OUT
29 class BUrlProtocolListener
{
35 Called when the socket is opened.
37 virtual void ConnectionOpened(BUrlRequest
* caller
);
42 Parameters: ip String representing the IP address of the resource
45 Called when the final IP is discovered
47 virtual void HostnameResolved(BUrlRequest
* caller
,
54 Called when the request has been emitted and the server begins to
55 reply. Typically when the HTTP status code is received.
57 virtual void ResponseStarted(BUrlRequest
* caller
);
63 Called when all the server response metadata (such as headers) have
66 virtual void HeadersReceived(BUrlRequest
* caller
,
67 const BUrlResult
& result
);
70 DataReceived(data, position, size)
71 Frequency: Zero or more
72 Parameters: data Pointer to the data block in memory
73 position Offset of the data in the stream
74 size Size of the data block
76 Called each time a full block of data is received.
78 virtual void DataReceived(BUrlRequest
* caller
,
79 const char* data
, off_t position
,
83 DownloadProgress(bytesReceived, bytesTotal)
84 Frequency: Once or more
85 Parameters: bytesReceived Number of data bytes received
86 bytesTotal Total number of data bytes expected
88 Called each time a data block is received.
90 virtual void DownloadProgress(BUrlRequest
* caller
,
91 ssize_t bytesReceived
, ssize_t bytesTotal
);
94 UploadProgress(bytesSent, bytesTotal)
95 Frequency: Once or more
96 Parameters: bytesSent Number of data bytes sent
97 bytesTotal Total number of data bytes expected
99 Called each time a data block is emitted.
101 virtual void UploadProgress(BUrlRequest
* caller
,
102 ssize_t bytesSent
, ssize_t bytesTotal
);
105 RequestCompleted(success)
107 Parameters: success true if the resource have been successfully
110 Called once the request is complete.
112 virtual void RequestCompleted(BUrlRequest
* caller
,
116 DebugMessage(type, text)
117 Frequency: zero or more
118 Parameters: type Type of the verbose message (see BUrlProtocolDebug)
120 Called each time a debug message is emitted
122 virtual void DebugMessage(BUrlRequest
* caller
,
123 BUrlProtocolDebugMessage type
,
127 CertificateVerificationFailed(certificate, message)
129 Parameters: certificate SSL certificate which coulnd't be validated
130 message error message describing the problem
132 Return true to proceed anyway, false to abort the connection
134 virtual bool CertificateVerificationFailed(
136 BCertificate
& certificate
,
137 const char* message
);
140 #endif // _B_URL_PROTOCOL_LISTENER_H_