2010-10-27 18:03:31 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Haiku Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _B_URL_REQUEST_H_
|
|
|
|
#define _B_URL_REQUEST_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <Url.h>
|
|
|
|
#include <UrlResult.h>
|
|
|
|
#include <UrlContext.h>
|
|
|
|
#include <UrlProtocolListener.h>
|
2013-10-08 13:30:56 +04:00
|
|
|
#include <OS.h>
|
2010-10-27 18:03:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
class BUrlRequest {
|
|
|
|
public:
|
|
|
|
BUrlRequest(const BUrl& url,
|
2013-10-08 13:30:56 +04:00
|
|
|
BUrlProtocolListener* listener,
|
|
|
|
BUrlContext* context,
|
|
|
|
BUrlResult& result,
|
|
|
|
const char* threadName,
|
|
|
|
const char* protocolName);
|
2013-02-11 00:36:34 +04:00
|
|
|
virtual ~BUrlRequest();
|
2010-10-27 18:03:31 +04:00
|
|
|
|
2013-10-08 13:30:56 +04:00
|
|
|
// URL protocol thread management
|
|
|
|
virtual thread_id Run();
|
2010-10-27 18:03:31 +04:00
|
|
|
virtual status_t Pause();
|
|
|
|
virtual status_t Resume();
|
2013-10-08 13:30:56 +04:00
|
|
|
virtual status_t Stop();
|
2013-02-11 00:36:34 +04:00
|
|
|
|
2013-10-08 13:30:56 +04:00
|
|
|
// URL protocol parameters modification
|
|
|
|
status_t SetUrl(const BUrl& url);
|
|
|
|
status_t SetResult(BUrlResult& result);
|
|
|
|
status_t SetContext(BUrlContext* context);
|
|
|
|
status_t SetListener(BUrlProtocolListener* listener);
|
|
|
|
|
|
|
|
// URL protocol parameters access
|
|
|
|
const BUrl& Url() const;
|
|
|
|
BUrlResult& Result() const;
|
|
|
|
BUrlContext* Context() const;
|
|
|
|
BUrlProtocolListener* Listener() const;
|
|
|
|
const BString& Protocol() const;
|
|
|
|
|
|
|
|
// URL protocol informations
|
2010-10-27 18:03:31 +04:00
|
|
|
bool IsRunning() const;
|
|
|
|
status_t Status() const;
|
2013-10-08 13:30:56 +04:00
|
|
|
virtual const char* StatusString(status_t threadStatus)
|
|
|
|
const;
|
|
|
|
|
2013-02-11 00:36:34 +04:00
|
|
|
|
2013-10-08 13:30:56 +04:00
|
|
|
protected:
|
|
|
|
static int32 _ThreadEntry(void* arg);
|
|
|
|
virtual status_t _ProtocolLoop();
|
|
|
|
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
|
|
|
|
const char* format, ...);
|
2010-10-27 18:03:31 +04:00
|
|
|
|
2013-10-08 13:30:56 +04:00
|
|
|
// URL result parameters access
|
|
|
|
BMallocIO& _ResultRawData();
|
|
|
|
BHttpHeaders& _ResultHeaders();
|
|
|
|
void _SetResultStatusCode(int32 statusCode);
|
|
|
|
BString& _ResultStatusText();
|
2010-10-27 18:03:31 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
BUrl fUrl;
|
2013-10-08 13:30:56 +04:00
|
|
|
BUrlResult& fResult;
|
|
|
|
BUrlContext* fContext;
|
|
|
|
BUrlProtocolListener* fListener;
|
2013-02-11 00:36:34 +04:00
|
|
|
|
2013-10-08 13:30:56 +04:00
|
|
|
bool fQuit;
|
|
|
|
bool fRunning;
|
|
|
|
status_t fThreadStatus;
|
|
|
|
thread_id fThreadId;
|
|
|
|
BString fThreadName;
|
|
|
|
BString fProtocol;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Rename, this is in the global namespace.
|
|
|
|
enum {
|
|
|
|
B_PROT_THREAD_STATUS__BASE = 0,
|
|
|
|
B_PROT_SUCCESS = B_PROT_THREAD_STATUS__BASE,
|
|
|
|
B_PROT_RUNNING,
|
|
|
|
B_PROT_PAUSED,
|
|
|
|
B_PROT_ABORTED,
|
|
|
|
B_PROT_SOCKET_ERROR,
|
|
|
|
B_PROT_CONNECTION_FAILED,
|
|
|
|
B_PROT_CANT_RESOLVE_HOSTNAME,
|
|
|
|
B_PROT_WRITE_FAILED,
|
|
|
|
B_PROT_READ_FAILED,
|
|
|
|
B_PROT_NO_MEMORY,
|
|
|
|
B_PROT_PROTOCOL_ERROR,
|
|
|
|
// Thread status over this one are guaranteed to be
|
|
|
|
// errors
|
|
|
|
B_PROT_THREAD_STATUS__END
|
2010-10-27 18:03:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _B_URL_REQUEST_H_
|