BUrlRequest: fix various issues
* Remove unused headers interface from BUrlProtocol * Change confusing function names * Style fixes and whitespace cleanup
This commit is contained in:
@@ -15,14 +15,14 @@
|
||||
|
||||
class BUrlProtocol {
|
||||
public:
|
||||
BUrlProtocol(const BUrl& url,
|
||||
BUrlProtocol(const BUrl& url,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context,
|
||||
BUrlResult* result,
|
||||
const char* threadName,
|
||||
const char* protocolName);
|
||||
virtual ~BUrlProtocol();
|
||||
|
||||
|
||||
// URL protocol required members
|
||||
// TODO: (stippi) I know it's sometimes appealing to have these
|
||||
// "simplistic" methods that can do anything, but they remove
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
// is it here at all? Why not have non-virtual setters for specific
|
||||
// things, where the setter is properly named?
|
||||
virtual status_t SetOption(uint32 name, void* value) = 0;
|
||||
|
||||
|
||||
// URL protocol thread management
|
||||
virtual thread_id Run();
|
||||
virtual status_t Pause();
|
||||
@@ -51,27 +51,25 @@ public:
|
||||
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;
|
||||
// TODO: Does not belong here.
|
||||
BHttpHeaders& Headers() { return fRequestHeaders; }
|
||||
|
||||
|
||||
// URL protocol informations
|
||||
bool IsRunning() const;
|
||||
status_t Status() const;
|
||||
virtual const char* StatusString(status_t threadStatus)
|
||||
virtual const char* StatusString(status_t threadStatus)
|
||||
const;
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
static int32 _ThreadEntry(void* arg);
|
||||
virtual status_t _ProtocolLoop();
|
||||
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
|
||||
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
|
||||
const char* format, ...);
|
||||
|
||||
// URL result parameters access
|
||||
@@ -79,15 +77,13 @@ protected:
|
||||
BHttpHeaders& _ResultHeaders();
|
||||
void _SetResultStatusCode(int32 statusCode);
|
||||
BString& _ResultStatusText();
|
||||
|
||||
|
||||
protected:
|
||||
BUrl fUrl;
|
||||
BHttpHeaders fRequestHeaders;
|
||||
// TODO: Does not belong here.
|
||||
BUrlResult* fResult;
|
||||
BUrlContext* fContext;
|
||||
BUrlProtocolListener* fListener;
|
||||
|
||||
|
||||
bool fQuit;
|
||||
bool fRunning;
|
||||
status_t fThreadStatus;
|
||||
@@ -110,7 +106,7 @@ enum {
|
||||
B_PROT_WRITE_FAILED,
|
||||
B_PROT_READ_FAILED,
|
||||
B_PROT_NO_MEMORY,
|
||||
B_PROT_PROTOCOL_ERROR,
|
||||
B_PROT_PROTOCOL_ERROR,
|
||||
// Thread status over this one are guaranteed to be
|
||||
// errors
|
||||
B_PROT_THREAD_STATUS__END
|
||||
@@ -118,18 +114,18 @@ enum {
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class BUrlProtocolOption {
|
||||
public:
|
||||
BUrlProtocolOption(void* value) : fValuePtr(value) { }
|
||||
|
||||
|
||||
bool Bool() const { return *reinterpret_cast<bool*>(fValuePtr); }
|
||||
int8 Int8() const { return *reinterpret_cast<int8*>(fValuePtr); }
|
||||
int16 Int16() const { return *reinterpret_cast<int16*>(fValuePtr); }
|
||||
int32 Int32() const { return *reinterpret_cast<int32*>(fValuePtr); }
|
||||
char* String() const { return reinterpret_cast<char*>(fValuePtr); }
|
||||
void* Pointer() const { return fValuePtr; }
|
||||
|
||||
|
||||
private:
|
||||
void* fValuePtr;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
virtual ~BUrlProtocolHttp();
|
||||
|
||||
virtual status_t SetOption(uint32 option, void* value);
|
||||
|
||||
|
||||
static bool IsInformationalStatusCode(int16 code);
|
||||
static bool IsSuccessStatusCode(int16 code);
|
||||
static bool IsRedirectionStatusCode(int16 code);
|
||||
@@ -39,49 +39,49 @@ public:
|
||||
static int16 StatusCodeClass(int16 code);
|
||||
|
||||
virtual const char* StatusString(status_t threadStatus) const;
|
||||
|
||||
|
||||
private:
|
||||
void _ResetOptions();
|
||||
status_t _ProtocolLoop();
|
||||
bool _ResolveHostName();
|
||||
status_t _MakeRequest();
|
||||
|
||||
|
||||
void _CreateRequest();
|
||||
void _AddHeaders();
|
||||
|
||||
|
||||
status_t _GetLine(BString& destString);
|
||||
|
||||
|
||||
void _ParseStatus();
|
||||
void _ParseHeaders();
|
||||
|
||||
void _CopyChunkInBuffer(char** buffer,
|
||||
|
||||
void _CopyChunkInBuffer(char** buffer,
|
||||
ssize_t* bytesReceived);
|
||||
|
||||
|
||||
void _AddOutputBufferLine(const char* line);
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
BAbstractSocket* fSocket;
|
||||
BNetworkAddress fRemoteAddr;
|
||||
bool fSSL;
|
||||
|
||||
|
||||
int8 fRequestMethod;
|
||||
int8 fHttpVersion;
|
||||
|
||||
|
||||
BString fOutputBuffer;
|
||||
BNetBuffer fInputBuffer;
|
||||
|
||||
|
||||
BHttpHeaders fHeaders;
|
||||
BHttpAuthentication fAuthentication;
|
||||
|
||||
|
||||
// Request status
|
||||
BHttpHeaders fOutputHeaders;
|
||||
bool fStatusReceived;
|
||||
bool fHeadersReceived;
|
||||
bool fContentReceived;
|
||||
bool fTrailingHeadersReceived;
|
||||
|
||||
|
||||
|
||||
|
||||
// Protocol options
|
||||
uint8 fOptMaxRedirs;
|
||||
BString fOptReferer;
|
||||
@@ -128,21 +128,21 @@ enum {
|
||||
enum {
|
||||
B_HTTPOPT_METHOD = 0,
|
||||
// (int) Request method (see B_HTTP_GET, ...)
|
||||
B_HTTPOPT_FOLLOWLOCATION,
|
||||
B_HTTPOPT_FOLLOWLOCATION,
|
||||
// (bool) Follow Location: headers
|
||||
B_HTTPOPT_MAXREDIRS,
|
||||
B_HTTPOPT_MAXREDIRS,
|
||||
// (int) Max relocation
|
||||
B_HTTPOPT_HEADERS,
|
||||
B_HTTPOPT_HEADERS,
|
||||
// (BHttpHeaders*) Headers to be sent
|
||||
B_HTTPOPT_REFERER,
|
||||
B_HTTPOPT_REFERER,
|
||||
// (string) Referer
|
||||
B_HTTPOPT_USERAGENT,
|
||||
B_HTTPOPT_USERAGENT,
|
||||
// (string) User-Agent
|
||||
B_HTTPOPT_SETCOOKIES,
|
||||
B_HTTPOPT_SETCOOKIES,
|
||||
// (bool) Send cookies from context
|
||||
B_HTTPOPT_DISCARD_DATA,
|
||||
B_HTTPOPT_DISCARD_DATA,
|
||||
// (bool) Discard incoming data (still notified)
|
||||
B_HTTPOPT_DISABLE_LISTENER,
|
||||
B_HTTPOPT_DISABLE_LISTENER,
|
||||
// (bool) Don't send notification to the listener
|
||||
B_HTTPOPT_AUTOREFERER,
|
||||
// (bool) Automatically set the Referer header
|
||||
@@ -156,7 +156,7 @@ enum {
|
||||
// (string) Authentication password
|
||||
B_HTTPOPT_AUTHMETHOD,
|
||||
// (int) Allowed authentication methods (see BHttpAuthenticationMethod)
|
||||
|
||||
|
||||
B_HTTPOPT__OPT_NUM
|
||||
};
|
||||
|
||||
@@ -179,7 +179,7 @@ enum http_status_code {
|
||||
B_HTTP_STATUS_CONTINUE = B_HTTP_STATUS__INFORMATIONAL_BASE,
|
||||
B_HTTP_STATUS_SWITCHING_PROTOCOLS,
|
||||
B_HTTP_STATUS__INFORMATIONAL_END,
|
||||
|
||||
|
||||
// Success status codes
|
||||
B_HTTP_STATUS__SUCCESS_BASE = 200,
|
||||
B_HTTP_STATUS_OK = B_HTTP_STATUS__SUCCESS_BASE,
|
||||
@@ -190,7 +190,7 @@ enum http_status_code {
|
||||
B_HTTP_STATUS_RESET_CONTENT,
|
||||
B_HTTP_STATUS_PARTIAL_CONTENT,
|
||||
B_HTTP_STATUS__SUCCESS_END,
|
||||
|
||||
|
||||
// Redirection status codes
|
||||
B_HTTP_STATUS__REDIRECTION_BASE = 300,
|
||||
B_HTTP_STATUS_MULTIPLE_CHOICE = B_HTTP_STATUS__REDIRECTION_BASE,
|
||||
@@ -201,7 +201,7 @@ enum http_status_code {
|
||||
B_HTTP_STATUS_USE_PROXY,
|
||||
B_HTTP_STATUS_TEMPORARY_REDIRECT,
|
||||
B_HTTP_STATUS__REDIRECTION_END,
|
||||
|
||||
|
||||
// Client error status codes
|
||||
B_HTTP_STATUS__CLIENT_ERROR_BASE = 400,
|
||||
B_HTTP_STATUS_BAD_REQUEST = B_HTTP_STATUS__CLIENT_ERROR_BASE,
|
||||
@@ -223,7 +223,7 @@ enum http_status_code {
|
||||
B_HTTP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE,
|
||||
B_HTTP_STATUS_EXPECTATION_FAILED,
|
||||
B_HTTP_STATUS__CLIENT_ERROR_END,
|
||||
|
||||
|
||||
// Server error status codes
|
||||
B_HTTP_STATUS__SERVER_ERROR_BASE = 500,
|
||||
B_HTTP_STATUS_INTERNAL_SERVER_ERROR = B_HTTP_STATUS__SERVER_ERROR_BASE,
|
||||
|
||||
+13
-12
@@ -22,36 +22,34 @@ enum {
|
||||
class BUrlRequest {
|
||||
public:
|
||||
BUrlRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener);
|
||||
BUrlRequest(const BUrl& url);
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
BUrlRequest(const BUrlRequest& other);
|
||||
virtual ~BUrlRequest() { };
|
||||
virtual ~BUrlRequest();
|
||||
|
||||
// Request parameters modification
|
||||
status_t SetUrl(const BUrl& url);
|
||||
void SetContext(BUrlContext* context);
|
||||
void SetProtocolListener(
|
||||
BUrlProtocolListener* listener);
|
||||
bool SetProtocolOption(int32 option,
|
||||
bool SetProtocolOption(int32 option,
|
||||
void* value);
|
||||
// Request parameters access
|
||||
const BUrlProtocol* Protocol();
|
||||
const BUrlResult& Result();
|
||||
const BUrl& Url();
|
||||
|
||||
|
||||
// Request control
|
||||
status_t Identify();
|
||||
virtual status_t Perform();
|
||||
// TODO: Rename to Run() perhaps? "Perform" is used for FBC stuff.
|
||||
virtual status_t Start();
|
||||
virtual status_t Pause();
|
||||
virtual status_t Resume();
|
||||
virtual status_t Abort();
|
||||
|
||||
|
||||
// Request informations
|
||||
virtual bool InitCheck() const;
|
||||
virtual status_t InitCheck() const;
|
||||
bool IsRunning() const;
|
||||
status_t Status() const;
|
||||
|
||||
|
||||
// Overloaded members
|
||||
BUrlRequest& operator=(const BUrlRequest& other);
|
||||
|
||||
@@ -62,7 +60,10 @@ protected:
|
||||
BUrlResult fResult;
|
||||
BUrlContext* fContext;
|
||||
BUrl fUrl;
|
||||
bool fReady;
|
||||
status_t fInitStatus;
|
||||
|
||||
private:
|
||||
status_t _SetupProtocol();
|
||||
};
|
||||
|
||||
#endif // _B_URL_REQUEST_H_
|
||||
|
||||
Reference in New Issue
Block a user