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 BUrlProtocol; 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(BUrlProtocol* 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(BUrlProtocol* 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(BUrlProtocol* 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(BUrlProtocol* caller); 63 64 /* 65 DataReceived(data, size) 66 Frequency: Zero or more 67 Parameters: data Pointer to the data block in memory 68 size Size of the data block 69 70 Called each time a full block of data is received. 71 */ 72 virtual void DataReceived(BUrlProtocol* caller, 73 const char* data, ssize_t size); 74 75 /* 76 DownloadProgress(bytesReceived, bytesTotal) 77 Frequency: Once or more 78 Parameters: bytesReceived Number of data bytes received 79 bytesTotal Total number of data bytes expected 80 81 Called each time a data block is received. 82 */ 83 virtual void DownloadProgress(BUrlProtocol* caller, 84 ssize_t bytesReceived, ssize_t bytesTotal); 85 86 /* 87 UploadProgress(bytesSent, bytesTotal) 88 Frequency: Once or more 89 Parameters: bytesSent Number of data bytes sent 90 bytesTotal Total number of data bytes expected 91 92 Called each time a data block is emitted. 93 */ 94 virtual void UploadProgress(BUrlProtocol* caller, 95 ssize_t bytesSent, ssize_t bytesTotal); 96 97 /* 98 RequestCompleted(success) 99 Frequency: Once 100 Parameters: success true if the resource have been successfully 101 false if not 102 103 Called once the request is complete. 104 */ 105 virtual void RequestCompleted(BUrlProtocol* caller, 106 bool success); 107 108 /* 109 DebugMessage(type, text) 110 Frequency: zero or more 111 Parameters: type Type of the verbose message (see BUrlProtocolDebug) 112 113 Called each time a debug message is emitted 114 */ 115 virtual void DebugMessage(BUrlProtocol* caller, 116 BUrlProtocolDebugMessage type, 117 const char* text); 118}; 119 120#endif // _B_URL_PROTOCOL_LISTENER_H_ 121