UrlProtocolListener.h revision cfc4b623
1/*
2 * Copyright 2010 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
12class BUrlRequest;
13
14
15enum BUrlProtocolDebugMessage {
16	B_URL_PROTOCOL_DEBUG_TEXT,
17	B_URL_PROTOCOL_DEBUG_ERROR,
18	B_URL_PROTOCOL_DEBUG_HEADER_IN,
19	B_URL_PROTOCOL_DEBUG_HEADER_OUT,
20	B_URL_PROTOCOL_DEBUG_TRANSFER_IN,
21	B_URL_PROTOCOL_DEBUG_TRANSFER_OUT
22};
23
24
25class BUrlProtocolListener {
26public:
27	/**
28		ConnectionOpened()
29		Frequency:	Once
30
31		 Called when the socket is opened.
32	*/
33	virtual	void				ConnectionOpened(BUrlRequest* caller);
34
35	/**
36		HostnameResolved(ip)
37		Frequency:	Once
38		Parameters:	ip		 String representing the IP address of the resource
39							host.
40
41		 Called when the final IP is discovered
42	*/
43	virtual void				HostnameResolved(BUrlRequest* caller,
44									const char* ip);
45
46	/**
47		ReponseStarted()
48		Frequency:	Once
49
50		 Called when the request has been emitted and the server begins to
51		reply. Typically when the HTTP status code is received.
52	*/
53	virtual void				ResponseStarted(BUrlRequest* caller);
54
55	/**
56		HeadersReceived()
57		Frequency:	Once
58
59		 Called when all the server response metadata (such as headers) have
60		been read and parsed.
61	*/
62	virtual void				HeadersReceived(BUrlRequest* caller);
63
64	/**
65		DataReceived(data, position, size)
66		Frequency:	Zero or more
67		Parameters:	data	 Pointer to the data block in memory
68					position Offset of the data in the stream
69					size	 Size of the data block
70
71		 Called each time a full block of data is received.
72	*/
73	virtual void				DataReceived(BUrlRequest* caller,
74									const char* data, off_t position,
75									ssize_t size);
76
77	/**
78		DownloadProgress(bytesReceived, bytesTotal)
79		Frequency:	Once or more
80		Parameters:	bytesReceived	Number of data bytes received
81					bytesTotal		Total number of data bytes expected
82
83		 Called each time a data block is received.
84	*/
85	virtual	void				DownloadProgress(BUrlRequest* caller,
86									ssize_t bytesReceived, ssize_t bytesTotal);
87
88	/**
89		UploadProgress(bytesSent, bytesTotal)
90		Frequency:	Once or more
91		Parameters:	bytesSent		Number of data bytes sent
92					bytesTotal		Total number of data bytes expected
93
94		 Called each time a data block is emitted.
95	*/
96	virtual void				UploadProgress(BUrlRequest* caller,
97									ssize_t bytesSent, ssize_t bytesTotal);
98
99	/**
100		RequestCompleted(success)
101		Frequency:	Once
102		Parameters:	success			true if the resource have been successfully
103									false if not
104
105		 Called once the request is complete.
106	*/
107	virtual void				RequestCompleted(BUrlRequest* caller,
108									bool success);
109
110	/**
111		DebugMessage(type, text)
112		Frequency:	zero or more
113		Parameters:	type	Type of the verbose message (see BUrlProtocolDebug)
114
115		 Called each time a debug message is emitted
116	*/
117	virtual void				DebugMessage(BUrlRequest* caller,
118									BUrlProtocolDebugMessage type,
119									const char* text);
120};
121
122#endif // _B_URL_PROTOCOL_LISTENER_H_
123