UrlProtocolListener.h revision f9e1854f
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_
7
8
9#include <stddef.h>
10#include <cstdlib>
11
12#include <UrlResult.h>
13
14
15class BCertificate;
16class BUrlRequest;
17
18
19enum 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
26};
27
28
29class BUrlProtocolListener {
30public:
31	/**
32		ConnectionOpened()
33		Frequency:	Once
34
35		Called when the socket is opened.
36	*/
37	virtual	void				ConnectionOpened(BUrlRequest* caller);
38
39	/**
40		HostnameResolved(ip)
41		Frequency:	Once
42		Parameters:	ip		 String representing the IP address of the resource
43							host.
44
45		Called when the final IP is discovered
46	*/
47	virtual void				HostnameResolved(BUrlRequest* caller,
48									const char* ip);
49
50	/**
51		ReponseStarted()
52		Frequency:	Once
53
54		Called when the request has been emitted and the server begins to
55		reply. Typically when the HTTP status code is received.
56	*/
57	virtual void				ResponseStarted(BUrlRequest* caller);
58
59	/**
60		HeadersReceived()
61		Frequency:	Once
62
63		Called when all the server response metadata (such as headers) have
64		been read and parsed.
65	*/
66	virtual void				HeadersReceived(BUrlRequest* caller,
67									const BUrlResult& result);
68
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
75
76		Called each time a full block of data is received.
77	*/
78	virtual void				DataReceived(BUrlRequest* caller,
79									const char* data, off_t position,
80									ssize_t size);
81
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
87
88		Called each time a data block is received.
89	*/
90	virtual	void				DownloadProgress(BUrlRequest* caller,
91									ssize_t bytesReceived, ssize_t bytesTotal);
92
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
98
99		Called each time a data block is emitted.
100	*/
101	virtual void				UploadProgress(BUrlRequest* caller,
102									ssize_t bytesSent, ssize_t bytesTotal);
103
104	/**
105		RequestCompleted(success)
106		Frequency:	Once
107		Parameters:	success			true if the resource have been successfully
108									false if not
109
110		Called once the request is complete.
111	*/
112	virtual void				RequestCompleted(BUrlRequest* caller,
113									bool success);
114
115	/**
116		DebugMessage(type, text)
117		Frequency:	zero or more
118		Parameters:	type	Type of the verbose message (see BUrlProtocolDebug)
119
120		Called each time a debug message is emitted
121	*/
122	virtual void				DebugMessage(BUrlRequest* caller,
123									BUrlProtocolDebugMessage type,
124									const char* text);
125
126	/**
127		CertificateVerificationFailed(certificate, message)
128		Frequency: Once
129		Parameters: certificate	SSL certificate which coulnd't be validated
130					message error message describing the problem
131
132		Return true to proceed anyway, false to abort the connection
133	*/
134	virtual bool				CertificateVerificationFailed(
135									BUrlRequest* caller,
136									BCertificate& certificate,
137									const char* message);
138};
139
140#endif // _B_URL_PROTOCOL_LISTENER_H_
141