1 /* 2 * Copyright 2010 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_ 6 #define _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_ 7 8 9 #include <Messenger.h> 10 #include <Message.h> 11 #include <UrlProtocolListener.h> 12 13 #ifndef LIBNETAPI_DEPRECATED 14 namespace BPrivate { 15 16 namespace Network { 17 #endif 18 19 //! To be in AppTypes.h 20 enum { 21 B_URL_PROTOCOL_NOTIFICATION = '_UPN' 22 }; 23 24 25 // Notification types 26 enum { 27 B_URL_PROTOCOL_CONNECTION_OPENED, 28 B_URL_PROTOCOL_HOSTNAME_RESOLVED, 29 B_URL_PROTOCOL_RESPONSE_STARTED, 30 B_URL_PROTOCOL_HEADERS_RECEIVED, 31 #ifdef LIBNETAPI_DEPRECATED 32 B_URL_PROTOCOL_DATA_RECEIVED, 33 #else 34 B_URL_PROTOCOL_BYTES_WRITTEN, 35 #endif 36 B_URL_PROTOCOL_DOWNLOAD_PROGRESS, 37 B_URL_PROTOCOL_UPLOAD_PROGRESS, 38 B_URL_PROTOCOL_REQUEST_COMPLETED, 39 B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED, 40 B_URL_PROTOCOL_DEBUG_MESSAGE 41 }; 42 43 44 class BUrlProtocolDispatchingListener : public BUrlProtocolListener { 45 public: 46 BUrlProtocolDispatchingListener( 47 BHandler* handler); 48 BUrlProtocolDispatchingListener( 49 const BMessenger& messenger); 50 virtual ~BUrlProtocolDispatchingListener(); 51 52 virtual void ConnectionOpened(BUrlRequest* caller); 53 virtual void HostnameResolved(BUrlRequest* caller, 54 const char* ip); 55 virtual void ResponseStarted(BUrlRequest* caller); 56 57 #ifdef LIBNETAPI_DEPRECATED 58 virtual void HeadersReceived(BUrlRequest* caller, 59 const BUrlResult& result); 60 virtual void DataReceived(BUrlRequest* caller, 61 const char* data, off_t position, 62 ssize_t size); 63 virtual void DownloadProgress(BUrlRequest* caller, 64 ssize_t bytesReceived, ssize_t bytesTotal); 65 virtual void UploadProgress(BUrlRequest* caller, 66 ssize_t bytesSent, ssize_t bytesTotal); 67 #else 68 virtual void HeadersReceived(BUrlRequest* caller); 69 virtual void BytesWritten(BUrlRequest* caller, 70 size_t bytesWritten); 71 virtual void DownloadProgress(BUrlRequest* caller, 72 off_t bytesReceived, off_t bytesTotal); 73 virtual void UploadProgress(BUrlRequest* caller, 74 off_t bytesSent, off_t bytesTotal); 75 #endif 76 77 virtual void RequestCompleted(BUrlRequest* caller, 78 bool success); 79 virtual void DebugMessage(BUrlRequest* caller, 80 BUrlProtocolDebugMessage type, 81 const char* text); 82 virtual bool CertificateVerificationFailed( 83 BUrlRequest* caller, 84 BCertificate& certificate, 85 const char* message); 86 87 private: 88 void _SendMessage(BMessage* message, 89 int8 notification, 90 BUrlRequest* caller); 91 92 private: 93 BMessenger fMessenger; 94 }; 95 96 #ifndef LIBNETAPI_DEPRECATED 97 } // namespace Network 98 99 } // namespace BPrivate 100 #endif 101 102 #endif // _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_ 103 104