vfs: check userland buffers before reading them.
[haiku.git] / headers / os / net / UrlProtocolListener.h
blobbc988262400f7d7e3ea2795d5c2d1b6ddb7f81cc
1 /*
2 * Copyright 2010-2017 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _B_URL_PROTOCOL_LISTENER_H_
6 #define _B_URL_PROTOCOL_LISTENER_H_
9 #include <stddef.h>
10 #include <cstdlib>
12 #include <UrlResult.h>
15 class BCertificate;
16 class BUrlRequest;
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 {
30 public:
31 /**
32 ConnectionOpened()
33 Frequency: Once
35 Called when the socket is opened.
37 virtual void ConnectionOpened(BUrlRequest* caller);
39 /**
40 HostnameResolved(ip)
41 Frequency: Once
42 Parameters: ip String representing the IP address of the resource
43 host.
45 Called when the final IP is discovered
47 virtual void HostnameResolved(BUrlRequest* caller,
48 const char* ip);
50 /**
51 ReponseStarted()
52 Frequency: Once
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);
59 /**
60 HeadersReceived()
61 Frequency: Once
63 Called when all the server response metadata (such as headers) have
64 been read and parsed.
66 virtual void HeadersReceived(BUrlRequest* caller,
67 const BUrlResult& result);
69 /**
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,
80 ssize_t size);
82 /**
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);
93 /**
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)
106 Frequency: Once
107 Parameters: success true if the resource have been successfully
108 false if not
110 Called once the request is complete.
112 virtual void RequestCompleted(BUrlRequest* caller,
113 bool success);
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,
124 const char* text);
127 CertificateVerificationFailed(certificate, message)
128 Frequency: Once
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(
135 BUrlRequest* caller,
136 BCertificate& certificate,
137 const char* message);
140 #endif // _B_URL_PROTOCOL_LISTENER_H_