netservices: remove all old conditional code
Change-Id: Idf3773c081ce103647c5dbea6e82c22bfc5606c9
This commit is contained in:
@@ -15,11 +15,10 @@
|
||||
#include <UrlRequest.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BDataRequest: public BUrlRequest {
|
||||
public:
|
||||
@@ -27,25 +26,20 @@ public:
|
||||
private:
|
||||
friend class BUrlProtocolRoster;
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BDataRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#else
|
||||
BDataRequest(const BUrl& url,
|
||||
BDataIO* output,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#endif
|
||||
|
||||
status_t _ProtocolLoop();
|
||||
private:
|
||||
BUrlResult fResult;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,11 +13,10 @@
|
||||
#include <UrlProtocolRoster.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BFileRequest : public BUrlRequest {
|
||||
public:
|
||||
@@ -29,26 +28,19 @@ public:
|
||||
private:
|
||||
friend class BUrlProtocolRoster;
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BFileRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#else
|
||||
BFileRequest(const BUrl& url,
|
||||
BDataIO* output,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#endif
|
||||
|
||||
status_t _ProtocolLoop();
|
||||
private:
|
||||
BUrlResult fResult;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_FILE_REQUEST_H_
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#include <UrlProtocolRoster.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BGopherRequest : public BNetworkRequest {
|
||||
public:
|
||||
@@ -29,27 +28,18 @@ public:
|
||||
private:
|
||||
friend class BUrlProtocolRoster;
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BGopherRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#else
|
||||
BGopherRequest(const BUrl& url,
|
||||
BDataIO* output,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#endif
|
||||
|
||||
status_t _ProtocolLoop();
|
||||
void _SendRequest();
|
||||
|
||||
bool _NeedsParsing();
|
||||
bool _NeedsLastDotStrip();
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
void _ParseInput(bool last);
|
||||
#else
|
||||
|
||||
status_t _ParseInput(bool last);
|
||||
#endif
|
||||
|
||||
BString& _HTMLEscapeString(BString &str);
|
||||
|
||||
@@ -62,10 +52,9 @@ private:
|
||||
BUrlResult fResult;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_GOPHER_REQUEST_H_
|
||||
|
||||
@@ -11,11 +11,10 @@
|
||||
#include <Url.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
// HTTP authentication method
|
||||
enum BHttpAuthenticationMethod {
|
||||
@@ -105,10 +104,10 @@ private:
|
||||
mutable BLocker fLock;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _B_HTTP_AUTHENTICATION_H_
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#include <map>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
enum form_type {
|
||||
B_HTTP_FORM_URL_ENCODED,
|
||||
@@ -194,10 +193,9 @@ private:
|
||||
BHttpFormData* fPrevElement;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_HTTP_FORM_H_
|
||||
|
||||
@@ -11,11 +11,10 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BHttpHeader {
|
||||
public:
|
||||
@@ -93,10 +92,9 @@ private:
|
||||
BList fHeaderList;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_HTTP_HEADERS_H_
|
||||
|
||||
@@ -23,11 +23,10 @@ namespace BPrivate {
|
||||
};
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BHttpRequest : public BNetworkRequest {
|
||||
public:
|
||||
@@ -41,9 +40,7 @@ public:
|
||||
void SetDiscardData(bool discard);
|
||||
void SetDisableListener(bool disable);
|
||||
void SetAutoReferrer(bool enable);
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
void SetStopOnError(bool stop);
|
||||
#endif
|
||||
void SetUserName(const BString& name);
|
||||
void SetPassword(const BString& password);
|
||||
void SetRangeStart(off_t position);
|
||||
@@ -70,20 +67,12 @@ public:
|
||||
private:
|
||||
friend class BUrlProtocolRoster;
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BHttpRequest(const BUrl& url,
|
||||
bool ssl = false,
|
||||
const char* protocolName = "HTTP",
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#else
|
||||
BHttpRequest(const BUrl& url,
|
||||
BDataIO* output,
|
||||
bool ssl = false,
|
||||
const char* protocolName = "HTTP",
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#endif
|
||||
BHttpRequest(const BHttpRequest& other);
|
||||
|
||||
void _ResetOptions();
|
||||
@@ -113,12 +102,6 @@ private:
|
||||
// Utility methods
|
||||
bool _IsDefaultPort();
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
// Listener notification
|
||||
void _NotifyDataReceived(const char* data,
|
||||
off_t pos, ssize_t length,
|
||||
off_t bytesReceived, ssize_t bytesTotal);
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool fSSL;
|
||||
@@ -160,9 +143,7 @@ private:
|
||||
bool fOptDiscardData : 1;
|
||||
bool fOptDisableListener : 1;
|
||||
bool fOptAutoReferer : 1;
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
bool fOptStopOnError : 1;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Request method
|
||||
@@ -260,10 +241,9 @@ enum http_status_code {
|
||||
// HTTP default User-Agent
|
||||
#define B_HTTP_PROTOCOL_USER_AGENT_FORMAT "ServicesKit (%s)"
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_URL_PROTOCOL_HTTP_H_
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#include <UrlResult.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlRequest;
|
||||
|
||||
@@ -26,9 +25,6 @@ class BHttpResult: public BUrlResult {
|
||||
|
||||
public:
|
||||
BHttpResult(const BUrl& url);
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BHttpResult(BMessage*);
|
||||
#endif
|
||||
BHttpResult(const BHttpResult& other);
|
||||
~BHttpResult();
|
||||
|
||||
@@ -38,11 +34,7 @@ public:
|
||||
// Result parameters access
|
||||
const BUrl& Url() const;
|
||||
BString ContentType() const;
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
size_t Length() const;
|
||||
#else
|
||||
off_t Length() const;
|
||||
#endif
|
||||
|
||||
// HTTP-Specific stuff
|
||||
const BHttpHeaders& Headers() const;
|
||||
@@ -55,10 +47,6 @@ public:
|
||||
// Overloaded members
|
||||
BHttpResult& operator=(const BHttpResult& other);
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
virtual status_t Archive(BMessage*, bool) const;
|
||||
static BArchivable* Instantiate(BMessage*);
|
||||
#endif
|
||||
private:
|
||||
BUrl fUrl;
|
||||
|
||||
@@ -67,10 +55,9 @@ private:
|
||||
BString fStatusString;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_URL_RESULT_H_
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
B_HTTP_TIME_FORMAT_PARSED = -1,
|
||||
@@ -31,25 +29,24 @@ public:
|
||||
BHttpTime();
|
||||
BHttpTime(BDateTime date);
|
||||
BHttpTime(const BString& dateString);
|
||||
|
||||
|
||||
// Date modification
|
||||
void SetString(const BString& string);
|
||||
void SetDate(BDateTime date);
|
||||
|
||||
|
||||
|
||||
|
||||
// Date conversion
|
||||
BDateTime Parse();
|
||||
BString ToString(int8 format = B_HTTP_TIME_FORMAT_PARSED);
|
||||
|
||||
|
||||
private:
|
||||
BString fDateString;
|
||||
BDateTime fDate;
|
||||
int8 fDateFormat;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
} // namespace Network
|
||||
#endif
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _B_HTTP_TIME_H_
|
||||
|
||||
@@ -13,11 +13,10 @@
|
||||
#include <Url.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BNetworkCookie : public BArchivable {
|
||||
public:
|
||||
@@ -116,11 +115,10 @@ private:
|
||||
bool fSessionCookie;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_NETWORK_COOKIE_H_
|
||||
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
#include <Url.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BNetworkCookieList: public BObjectList<const BNetworkCookie> {
|
||||
public:
|
||||
@@ -164,10 +163,9 @@ private:
|
||||
BUrl fUrl;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_NETWORK_COOKIE_JAR_
|
||||
|
||||
@@ -14,29 +14,20 @@
|
||||
class BAbstractSocket;
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BNetworkRequest: public BUrlRequest
|
||||
{
|
||||
public:
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BNetworkRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context,
|
||||
const char* threadName,
|
||||
const char* protocolName);
|
||||
#else
|
||||
BNetworkRequest(const BUrl& url,
|
||||
BDataIO* output,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context,
|
||||
const char* threadName,
|
||||
const char* protocolName);
|
||||
#endif
|
||||
|
||||
virtual status_t Stop();
|
||||
virtual void SetTimeout(bigtime_t timeout);
|
||||
@@ -54,10 +45,9 @@ protected:
|
||||
BNetBuffer fInputBuffer;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
#include <Referenceable.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlContext: public BReferenceable {
|
||||
public:
|
||||
@@ -55,11 +54,8 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _B_URL_CONTEXT_H_
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include <Message.h>
|
||||
#include <UrlProtocolDispatchingListener.h>
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlProtocolAsynchronousListener : public BHandler,
|
||||
public BUrlProtocolListener {
|
||||
@@ -33,12 +33,10 @@ private:
|
||||
BUrlProtocolDispatchingListener*
|
||||
fSynchronousListener;
|
||||
};
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _B_URL_PROTOCOL_ASYNCHRONOUS_LISTENER_H_
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include <Message.h>
|
||||
#include <UrlProtocolListener.h>
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
//! To be in AppTypes.h
|
||||
enum {
|
||||
@@ -28,11 +28,7 @@ enum {
|
||||
B_URL_PROTOCOL_HOSTNAME_RESOLVED,
|
||||
B_URL_PROTOCOL_RESPONSE_STARTED,
|
||||
B_URL_PROTOCOL_HEADERS_RECEIVED,
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
B_URL_PROTOCOL_DATA_RECEIVED,
|
||||
#else
|
||||
B_URL_PROTOCOL_BYTES_WRITTEN,
|
||||
#endif
|
||||
B_URL_PROTOCOL_DOWNLOAD_PROGRESS,
|
||||
B_URL_PROTOCOL_UPLOAD_PROGRESS,
|
||||
B_URL_PROTOCOL_REQUEST_COMPLETED,
|
||||
@@ -54,17 +50,6 @@ public:
|
||||
const char* ip);
|
||||
virtual void ResponseStarted(BUrlRequest* caller);
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
virtual void HeadersReceived(BUrlRequest* caller,
|
||||
const BUrlResult& result);
|
||||
virtual void DataReceived(BUrlRequest* caller,
|
||||
const char* data, off_t position,
|
||||
ssize_t size);
|
||||
virtual void DownloadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesReceived, ssize_t bytesTotal);
|
||||
virtual void UploadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesSent, ssize_t bytesTotal);
|
||||
#else
|
||||
virtual void HeadersReceived(BUrlRequest* caller);
|
||||
virtual void BytesWritten(BUrlRequest* caller,
|
||||
size_t bytesWritten);
|
||||
@@ -72,7 +57,6 @@ public:
|
||||
off_t bytesReceived, off_t bytesTotal);
|
||||
virtual void UploadProgress(BUrlRequest* caller,
|
||||
off_t bytesSent, off_t bytesTotal);
|
||||
#endif
|
||||
|
||||
virtual void RequestCompleted(BUrlRequest* caller,
|
||||
bool success);
|
||||
@@ -93,11 +77,9 @@ private:
|
||||
BMessenger fMessenger;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
class BCertificate;
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlRequest;
|
||||
|
||||
@@ -39,17 +39,6 @@ public:
|
||||
virtual void HostnameResolved(BUrlRequest* caller,
|
||||
const char* ip);
|
||||
virtual void ResponseStarted(BUrlRequest* caller);
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
virtual void HeadersReceived(BUrlRequest* caller,
|
||||
const BUrlResult& result);
|
||||
virtual void DataReceived(BUrlRequest* caller,
|
||||
const char* data, off_t position,
|
||||
ssize_t size);
|
||||
virtual void DownloadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesReceived, ssize_t bytesTotal);
|
||||
virtual void UploadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesSent, ssize_t bytesTotal);
|
||||
#else
|
||||
virtual void HeadersReceived(BUrlRequest* caller);
|
||||
virtual void BytesWritten(BUrlRequest* caller,
|
||||
size_t bytesWritten);
|
||||
@@ -57,7 +46,6 @@ public:
|
||||
off_t bytesReceived, off_t bytesTotal);
|
||||
virtual void UploadProgress(BUrlRequest* caller,
|
||||
off_t bytesSent, off_t bytesTotal);
|
||||
#endif
|
||||
|
||||
virtual void RequestCompleted(BUrlRequest* caller,
|
||||
bool success);
|
||||
@@ -70,10 +58,9 @@ public:
|
||||
const char* message);
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_URL_PROTOCOL_LISTENER_H_
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
class BDataIO;
|
||||
class BUrl;
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlContext;
|
||||
class BUrlProtocolListener;
|
||||
@@ -25,21 +25,14 @@ class BUrlRequest;
|
||||
|
||||
class BUrlProtocolRoster {
|
||||
public:
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
static BUrlRequest* MakeRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#else
|
||||
static BUrlRequest* MakeRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL);
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif // _B_URL_ROSTER_H_
|
||||
|
||||
@@ -14,36 +14,24 @@
|
||||
#include <Referenceable.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlRequest {
|
||||
public:
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BUrlRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context,
|
||||
const char* threadName,
|
||||
const char* protocolName);
|
||||
#else
|
||||
|
||||
BUrlRequest(const BUrl& url,
|
||||
BDataIO* output,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context,
|
||||
const char* threadName,
|
||||
const char* protocolName);
|
||||
#endif
|
||||
virtual ~BUrlRequest();
|
||||
|
||||
// URL protocol thread management
|
||||
virtual thread_id Run();
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
virtual status_t Pause();
|
||||
virtual status_t Resume();
|
||||
#endif
|
||||
|
||||
virtual status_t Stop();
|
||||
virtual void SetTimeout(bigtime_t timeout) {}
|
||||
@@ -52,18 +40,14 @@ public:
|
||||
status_t SetUrl(const BUrl& url);
|
||||
status_t SetContext(BUrlContext* context);
|
||||
status_t SetListener(BUrlProtocolListener* listener);
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
status_t SetOutput(BDataIO* output);
|
||||
#endif
|
||||
|
||||
// URL protocol parameters access
|
||||
const BUrl& Url() const;
|
||||
BUrlContext* Context() const;
|
||||
BUrlProtocolListener* Listener() const;
|
||||
const BString& Protocol() const;
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
BDataIO* Output() const;
|
||||
#endif
|
||||
|
||||
// URL protocol informations
|
||||
bool IsRunning() const;
|
||||
@@ -81,9 +65,7 @@ protected:
|
||||
BUrl fUrl;
|
||||
BReference<BUrlContext> fContext;
|
||||
BUrlProtocolListener* fListener;
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
BDataIO* fOutput;
|
||||
#endif
|
||||
|
||||
bool fQuit;
|
||||
bool fRunning;
|
||||
@@ -93,10 +75,9 @@ protected:
|
||||
BString fProtocol;
|
||||
};
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_URL_REQUEST_H_
|
||||
|
||||
@@ -9,37 +9,11 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
#include <Archivable.h>
|
||||
|
||||
|
||||
class BUrlResult: public BArchivable {
|
||||
public:
|
||||
BUrlResult();
|
||||
BUrlResult(BMessage*);
|
||||
virtual ~BUrlResult();
|
||||
|
||||
virtual status_t Archive(BMessage*, bool) const;
|
||||
|
||||
void SetContentType(BString contentType);
|
||||
void SetLength(size_t length);
|
||||
|
||||
virtual BString ContentType() const;
|
||||
virtual size_t Length() const;
|
||||
|
||||
static BArchivable* Instantiate(BMessage*);
|
||||
|
||||
private:
|
||||
BString fContentType;
|
||||
size_t fLength;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
|
||||
|
||||
class BUrlResult {
|
||||
public:
|
||||
BUrlResult();
|
||||
@@ -56,10 +30,9 @@ private:
|
||||
off_t fLength;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Network
|
||||
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _B_URL_RESULT_H_
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
#include <UrlProtocolListener.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlSynchronousRequest : public BUrlRequest, public BUrlProtocolListener {
|
||||
public:
|
||||
@@ -30,17 +29,6 @@ public:
|
||||
virtual void HostnameResolved(BUrlRequest* caller,
|
||||
const char* ip);
|
||||
virtual void ResponseStarted(BUrlRequest* caller);
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
virtual void HeadersReceived(BUrlRequest* caller,
|
||||
const BUrlResult& result);
|
||||
virtual void DataReceived(BUrlRequest* caller,
|
||||
const char* data, off_t position,
|
||||
ssize_t size);
|
||||
virtual void DownloadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesReceived, ssize_t bytesTotal);
|
||||
virtual void UploadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesSent, ssize_t bytesTotal);
|
||||
#else
|
||||
virtual void HeadersReceived(BUrlRequest* caller);
|
||||
virtual void BytesWritten(BUrlRequest* caller,
|
||||
size_t bytesWritten);
|
||||
@@ -48,22 +36,18 @@ public:
|
||||
off_t bytesReceived, off_t bytesTotal);
|
||||
virtual void UploadProgress(BUrlRequest* caller,
|
||||
off_t bytesSent, off_t bytesTotal);
|
||||
#endif
|
||||
|
||||
virtual void RequestCompleted(BUrlRequest* caller,
|
||||
bool success);
|
||||
|
||||
|
||||
protected:
|
||||
bool fRequestComplete;
|
||||
BUrlRequest& fWrappedRequest;
|
||||
};
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
#endif
|
||||
|
||||
#endif // _B_URL_SYNCHRONOUS_REQUEST_H_
|
||||
|
||||
@@ -14,23 +14,9 @@
|
||||
#include <mail_encoding.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BDataRequest::BDataRequest(const BUrl& url, BUrlProtocolListener* listener,
|
||||
BUrlContext* context)
|
||||
: BUrlRequest(url, listener, context, "data URL parser", "data"),
|
||||
fResult()
|
||||
{
|
||||
fResult.SetContentType("text/plain");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BDataRequest::BDataRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context)
|
||||
@@ -40,7 +26,6 @@ BDataRequest::BDataRequest(const BUrl& url, BDataIO* output,
|
||||
{
|
||||
fResult.SetContentType("text/plain");
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
const BUrlResult&
|
||||
@@ -136,15 +121,6 @@ BDataRequest::_ProtocolLoop()
|
||||
|
||||
fResult.SetLength(length);
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
if (fListener != NULL) {
|
||||
fListener->HeadersReceived(this, fResult);
|
||||
if (length > 0) {
|
||||
fListener->DataReceived(this, payload, 0, length);
|
||||
fListener->DownloadProgress(this, length, length);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (fListener != NULL)
|
||||
fListener->HeadersReceived(this);
|
||||
if (length > 0) {
|
||||
@@ -159,7 +135,6 @@ BDataRequest::_ProtocolLoop()
|
||||
fListener->DownloadProgress(this, written, written);
|
||||
}
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -16,24 +16,9 @@
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BFileRequest::BFileRequest(const BUrl& url, BUrlProtocolListener* listener,
|
||||
BUrlContext* context)
|
||||
:
|
||||
BUrlRequest(url, listener, context, "BUrlProtocol.File", "file"),
|
||||
fResult()
|
||||
{
|
||||
fUrl.UrlDecode(true);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BFileRequest::BFileRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener, BUrlContext* context)
|
||||
:
|
||||
@@ -42,7 +27,6 @@ BFileRequest::BFileRequest(const BUrl& url, BDataIO* output,
|
||||
{
|
||||
fUrl.UrlDecode(true);
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
BFileRequest::~BFileRequest()
|
||||
@@ -60,140 +44,6 @@ BFileRequest::Result() const
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
status_t
|
||||
BFileRequest::_ProtocolLoop()
|
||||
{
|
||||
BNode node(fUrl.Path().String());
|
||||
|
||||
if (node.IsSymLink()) {
|
||||
// Traverse the symlink and start over
|
||||
BEntry entry(fUrl.Path().String(), true);
|
||||
node = BNode(&entry);
|
||||
}
|
||||
|
||||
ssize_t transferredSize = 0;
|
||||
if (node.IsFile()) {
|
||||
BFile file(fUrl.Path().String(), B_READ_ONLY);
|
||||
status_t error = file.InitCheck();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
BNodeInfo info(&file);
|
||||
char mimeType[B_MIME_TYPE_LENGTH + 1];
|
||||
if (info.GetType(mimeType) != B_OK)
|
||||
update_mime_info(fUrl.Path().String(), false, true, false);
|
||||
if (info.GetType(mimeType) == B_OK)
|
||||
fResult.SetContentType(mimeType);
|
||||
|
||||
// Send all notifications to listener, if any
|
||||
if (fListener != NULL) {
|
||||
fListener->ConnectionOpened(this);
|
||||
|
||||
off_t size = 0;
|
||||
error = file.GetSize(&size);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
fResult.SetLength(size);
|
||||
|
||||
fListener->HeadersReceived(this, fResult);
|
||||
|
||||
ssize_t chunkSize = 0;
|
||||
char chunk[4096];
|
||||
while (!fQuit) {
|
||||
chunkSize = file.Read(chunk, sizeof(chunk));
|
||||
if (chunkSize > 0) {
|
||||
fListener->DataReceived(this, chunk, transferredSize,
|
||||
chunkSize);
|
||||
transferredSize += chunkSize;
|
||||
fListener->DownloadProgress(this, transferredSize, size);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (fQuit)
|
||||
return B_INTERRUPTED;
|
||||
// Return error if we didn't transfer everything
|
||||
if (transferredSize != size) {
|
||||
if (chunkSize < 0)
|
||||
return (status_t)chunkSize;
|
||||
else
|
||||
return B_IO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
node_ref ref;
|
||||
status_t error = node.GetNodeRef(&ref);
|
||||
|
||||
// Stop here, and don't hit the assert below, if the file doesn't exist.
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
assert(node.IsDirectory());
|
||||
BDirectory directory(&ref);
|
||||
|
||||
fResult.SetContentType("application/x-ftp-directory; charset=utf-8");
|
||||
// This tells WebKit to use its FTP directory rendering code.
|
||||
|
||||
if (fListener != NULL) {
|
||||
fListener->ConnectionOpened(this);
|
||||
fListener->HeadersReceived(this, fResult);
|
||||
|
||||
// Add a parent directory entry.
|
||||
fListener->DataReceived(this, "+/,\t..\r\n", transferredSize, 8);
|
||||
fListener->DownloadProgress(this, transferredSize, 0);
|
||||
transferredSize += 8;
|
||||
}
|
||||
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
BEntry entry;
|
||||
while (!fQuit && directory.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
|
||||
// We read directories using the EPLF (Easily Parsed List Format)
|
||||
// This happens to be one of the formats that WebKit can understand,
|
||||
// and it is not too hard to parse or generate.
|
||||
// http://tools.ietf.org/html/draft-bernstein-eplf-02
|
||||
BString eplf("+");
|
||||
if (entry.IsFile() || entry.IsSymLink()) {
|
||||
eplf += "r,";
|
||||
off_t fileSize;
|
||||
if (entry.GetSize(&fileSize) == B_OK)
|
||||
eplf << "s" << fileSize << ",";
|
||||
|
||||
} else if (entry.IsDirectory())
|
||||
eplf += "/,";
|
||||
|
||||
time_t modification;
|
||||
if (entry.GetModificationTime(&modification) == B_OK)
|
||||
eplf << "m" << modification << ",";
|
||||
|
||||
mode_t permissions;
|
||||
if (entry.GetPermissions(&permissions) == B_OK)
|
||||
eplf << "up" << BString().SetToFormat("%03o", permissions) << ",";
|
||||
|
||||
node_ref ref;
|
||||
if (entry.GetNodeRef(&ref) == B_OK)
|
||||
eplf << "i" << ref.device << "." << ref.node << ",";
|
||||
|
||||
entry.GetName(name);
|
||||
eplf << "\t" << name << "\r\n";
|
||||
if (fListener != NULL) {
|
||||
fListener->DataReceived(this, eplf.String(), transferredSize,
|
||||
eplf.Length());
|
||||
fListener->DownloadProgress(this, transferredSize, 0);
|
||||
}
|
||||
transferredSize += eplf.Length();
|
||||
}
|
||||
|
||||
if (!fQuit)
|
||||
fResult.SetLength(transferredSize);
|
||||
|
||||
return fQuit ? B_INTERRUPTED : B_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
status_t
|
||||
BFileRequest::_ProtocolLoop()
|
||||
{
|
||||
@@ -343,5 +193,3 @@ BFileRequest::_ProtocolLoop()
|
||||
|
||||
return fQuit ? B_INTERRUPTED : B_OK;
|
||||
}
|
||||
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
#include <String.h>
|
||||
#include <StringList.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* TODO: fix '+' in selectors, cf. gopher://gophernicus.org/1/doc/gopher/
|
||||
@@ -183,33 +181,6 @@ static const int32 kGopherBufferSize = 4096;
|
||||
static const bool kInlineImages = true;
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BGopherRequest::BGopherRequest(const BUrl& url, BUrlProtocolListener* listener,
|
||||
BUrlContext* context)
|
||||
:
|
||||
BNetworkRequest(url, listener, context, "BUrlProtocol.Gopher", "gopher"),
|
||||
fItemType(GOPHER_TYPE_NONE),
|
||||
fPosition(0),
|
||||
fResult()
|
||||
{
|
||||
fSocket = new(std::nothrow) BSocket();
|
||||
|
||||
fUrl.UrlDecode();
|
||||
// the first part of the path is actually the document type
|
||||
|
||||
fPath = Url().Path();
|
||||
if (!Url().HasPath() || fPath.Length() == 0 || fPath == "/") {
|
||||
// default entry
|
||||
fItemType = GOPHER_TYPE_DIRECTORY;
|
||||
fPath = "";
|
||||
} else if (fPath.Length() > 1 && fPath[0] == '/') {
|
||||
fItemType = fPath[1];
|
||||
fPath.Remove(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BGopherRequest::BGopherRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener, BUrlContext* context)
|
||||
:
|
||||
@@ -234,7 +205,6 @@ BGopherRequest::BGopherRequest(const BUrl& url, BDataIO* output,
|
||||
fPath.Remove(0, 2);
|
||||
}
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
BGopherRequest::~BGopherRequest()
|
||||
@@ -263,165 +233,6 @@ BGopherRequest::Result() const
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
status_t
|
||||
BGopherRequest::_ProtocolLoop()
|
||||
{
|
||||
if (fSocket == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
if (!_ResolveHostName(fUrl.Host(), fUrl.HasPort() ? fUrl.Port() : 70)) {
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR,
|
||||
"Unable to resolve hostname (%s), aborting.",
|
||||
fUrl.Host().String());
|
||||
return B_SERVER_NOT_FOUND;
|
||||
}
|
||||
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection to %s on port %d.",
|
||||
fUrl.Authority().String(), fRemoteAddr.Port());
|
||||
status_t connectError = fSocket->Connect(fRemoteAddr);
|
||||
|
||||
if (connectError != B_OK) {
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, "Socket connection error %s",
|
||||
strerror(connectError));
|
||||
return connectError;
|
||||
}
|
||||
|
||||
//! ProtocolHook:ConnectionOpened
|
||||
if (fListener != NULL)
|
||||
fListener->ConnectionOpened(this);
|
||||
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
|
||||
"Connection opened, sending request.");
|
||||
|
||||
_SendRequest();
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Request sent.");
|
||||
|
||||
// Receive loop
|
||||
bool receiveEnd = false;
|
||||
status_t readError = B_OK;
|
||||
ssize_t bytesRead = 0;
|
||||
//ssize_t bytesReceived = 0;
|
||||
//ssize_t bytesTotal = 0;
|
||||
bool dataValidated = false;
|
||||
BStackOrHeapArray<char, 4096> chunk(kGopherBufferSize);
|
||||
|
||||
while (!fQuit && !receiveEnd) {
|
||||
bytesRead = fSocket->Read(chunk, kGopherBufferSize);
|
||||
|
||||
if (bytesRead < 0) {
|
||||
readError = bytesRead;
|
||||
break;
|
||||
} else if (bytesRead == 0)
|
||||
receiveEnd = true;
|
||||
|
||||
fInputBuffer.AppendData(chunk, bytesRead);
|
||||
|
||||
if (!dataValidated) {
|
||||
size_t i;
|
||||
// on error (file doesn't exist, ...) the server sends
|
||||
// a faked directory entry with an error message
|
||||
if (fInputBuffer.Size() && fInputBuffer.Data()[0] == '3') {
|
||||
int tabs = 0;
|
||||
bool crlf = false;
|
||||
|
||||
// make sure the buffer only contains printable characters
|
||||
// and has at least 3 tabs before a CRLF
|
||||
for (i = 0; i < fInputBuffer.Size(); i++) {
|
||||
char c = fInputBuffer.Data()[i];
|
||||
if (c == '\t') {
|
||||
if (!crlf)
|
||||
tabs++;
|
||||
} else if (c == '\r' || c == '\n') {
|
||||
if (tabs < 3)
|
||||
break;
|
||||
crlf = true;
|
||||
} else if (!isprint(fInputBuffer.Data()[i])) {
|
||||
crlf = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (crlf && tabs > 2 && tabs < 5) {
|
||||
// TODO:
|
||||
//if enough data
|
||||
// else continue
|
||||
fItemType = GOPHER_TYPE_DIRECTORY;
|
||||
readError = B_RESOURCE_NOT_FOUND;
|
||||
// continue parsing the error text anyway
|
||||
}
|
||||
}
|
||||
// special case for buggy(?) Gophernicus/1.5
|
||||
static const char *buggy = "Error: File or directory not found!";
|
||||
if (fInputBuffer.Size() > strlen(buggy)
|
||||
&& !memcmp(fInputBuffer.Data(), buggy, strlen(buggy))) {
|
||||
fItemType = GOPHER_TYPE_DIRECTORY;
|
||||
readError = B_RESOURCE_NOT_FOUND;
|
||||
// continue parsing the error text anyway
|
||||
// but it won't look good
|
||||
}
|
||||
|
||||
// now we probably have correct data
|
||||
dataValidated = true;
|
||||
|
||||
//! ProtocolHook:ResponseStarted
|
||||
if (fListener != NULL)
|
||||
fListener->ResponseStarted(this);
|
||||
|
||||
// now we can assign MIME type if we know it
|
||||
const char *mime = "application/octet-stream";
|
||||
for (i = 0; gopher_type_map[i].type != GOPHER_TYPE_NONE; i++) {
|
||||
if (gopher_type_map[i].type == fItemType) {
|
||||
mime = gopher_type_map[i].mime;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fResult.SetContentType(mime);
|
||||
|
||||
// we don't really have headers but well...
|
||||
//! ProtocolHook:HeadersReceived
|
||||
if (fListener != NULL)
|
||||
fListener->HeadersReceived(this, fResult);
|
||||
}
|
||||
|
||||
if (_NeedsParsing())
|
||||
_ParseInput(receiveEnd);
|
||||
else if (fInputBuffer.Size()) {
|
||||
// send input directly
|
||||
if (fListener != NULL) {
|
||||
fListener->DataReceived(this, (const char *)fInputBuffer.Data(),
|
||||
fPosition, fInputBuffer.Size());
|
||||
}
|
||||
|
||||
fPosition += fInputBuffer.Size();
|
||||
|
||||
if (fListener != NULL)
|
||||
fListener->DownloadProgress(this, fPosition, 0);
|
||||
|
||||
// XXX: this is plain stupid, we already copied the data
|
||||
// and just want to drop it...
|
||||
char *inputTempBuffer = new(std::nothrow) char[bytesRead];
|
||||
if (inputTempBuffer == NULL) {
|
||||
readError = B_NO_MEMORY;
|
||||
break;
|
||||
}
|
||||
fInputBuffer.RemoveData(inputTempBuffer, fInputBuffer.Size());
|
||||
delete[] inputTempBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
if (fPosition > 0)
|
||||
fResult.SetLength(fPosition);
|
||||
|
||||
fSocket->Disconnect();
|
||||
|
||||
if (readError != B_OK)
|
||||
return readError;
|
||||
|
||||
return fQuit ? B_INTERRUPTED : B_OK;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
status_t
|
||||
BGopherRequest::_ProtocolLoop()
|
||||
{
|
||||
@@ -583,7 +394,6 @@ BGopherRequest::_ProtocolLoop()
|
||||
|
||||
return fQuit ? B_INTERRUPTED : B_OK;
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
void
|
||||
@@ -623,296 +433,6 @@ BGopherRequest::_NeedsLastDotStrip()
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
void
|
||||
BGopherRequest::_ParseInput(bool last)
|
||||
{
|
||||
BString line;
|
||||
|
||||
while (_GetLine(line) == B_OK) {
|
||||
char type = GOPHER_TYPE_NONE;
|
||||
BStringList fields;
|
||||
|
||||
line.MoveInto(&type, 0, 1);
|
||||
|
||||
line.Split("\t", false, fields);
|
||||
|
||||
if (type != GOPHER_TYPE_ENDOFPAGE
|
||||
&& fields.CountStrings() < FIELD_GPFLAG)
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
|
||||
"Unterminated gopher item (type '%c')", type);
|
||||
|
||||
BString pageTitle;
|
||||
BString item;
|
||||
BString title = fields.StringAt(FIELD_NAME);
|
||||
BString link("gopher://");
|
||||
BString user;
|
||||
if (fields.CountStrings() > 3) {
|
||||
link << fields.StringAt(FIELD_HOST);
|
||||
if (fields.StringAt(FIELD_PORT).Length())
|
||||
link << ":" << fields.StringAt(FIELD_PORT);
|
||||
link << "/" << type;
|
||||
//if (fields.StringAt(FIELD_SELECTOR).ByteAt(0) != '/')
|
||||
// link << "/";
|
||||
link << fields.StringAt(FIELD_SELECTOR);
|
||||
}
|
||||
_HTMLEscapeString(title);
|
||||
_HTMLEscapeString(link);
|
||||
|
||||
switch (type) {
|
||||
case GOPHER_TYPE_ENDOFPAGE:
|
||||
/* end of the page */
|
||||
break;
|
||||
case GOPHER_TYPE_TEXTPLAIN:
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"text\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_BINARY:
|
||||
case GOPHER_TYPE_BINHEX:
|
||||
case GOPHER_TYPE_BINARCHIVE:
|
||||
case GOPHER_TYPE_UUENCODED:
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"binary\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_DIRECTORY:
|
||||
/*
|
||||
* directory link
|
||||
*/
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"dir\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_ERROR:
|
||||
item << "<span class=\"error\">" << title << "</span>"
|
||||
"<br/>\n";
|
||||
if (fPosition == 0 && pageTitle.Length() == 0)
|
||||
pageTitle << "Error: " << title;
|
||||
break;
|
||||
case GOPHER_TYPE_QUERY:
|
||||
/* TODO: handle search better.
|
||||
* For now we use an unnamed input field and accept sending ?=foo
|
||||
* as it seems at least Veronica-2 ignores the = but it's unclean.
|
||||
*/
|
||||
item << "<form method=\"get\" action=\"" << link << "\" "
|
||||
"onsubmit=\"window.location = this.action + '?' + "
|
||||
"this.elements['q'].value; return false;\">"
|
||||
"<span class=\"query\">"
|
||||
"<label>" << title << " "
|
||||
"<input id=\"q\" name=\"\" type=\"text\" align=\"right\" />"
|
||||
"</label>"
|
||||
"</span></form>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_TELNET:
|
||||
/* telnet: links
|
||||
* cf. gopher://78.80.30.202/1/ps3
|
||||
* -> gopher://78.80.30.202:23/8/ps3/new -> [email protected]
|
||||
*/
|
||||
link = "telnet://";
|
||||
user = fields.StringAt(FIELD_SELECTOR);
|
||||
if (user.FindLast('/') > -1) {
|
||||
user.Remove(0, user.FindLast('/'));
|
||||
link << user << "@";
|
||||
}
|
||||
link << fields.StringAt(FIELD_HOST);
|
||||
if (fields.StringAt(FIELD_PORT) != "23")
|
||||
link << ":" << fields.StringAt(FIELD_PORT);
|
||||
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"telnet\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_TN3270:
|
||||
/* tn3270: URI scheme, cf. http://tools.ietf.org/html/rfc6270 */
|
||||
link = "tn3270://";
|
||||
user = fields.StringAt(FIELD_SELECTOR);
|
||||
if (user.FindLast('/') > -1) {
|
||||
user.Remove(0, user.FindLast('/'));
|
||||
link << user << "@";
|
||||
}
|
||||
link << fields.StringAt(FIELD_HOST);
|
||||
if (fields.StringAt(FIELD_PORT) != "23")
|
||||
link << ":" << fields.StringAt(FIELD_PORT);
|
||||
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"telnet\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_CSO_SEARCH:
|
||||
/* CSO search.
|
||||
* At least Lynx supports a cso:// URI scheme:
|
||||
* http://lynx.isc.org/lynx2.8.5/lynx2-8-5/lynx_help/lynx_url_support.html
|
||||
*/
|
||||
link = "cso://";
|
||||
user = fields.StringAt(FIELD_SELECTOR);
|
||||
if (user.FindLast('/') > -1) {
|
||||
user.Remove(0, user.FindLast('/'));
|
||||
link << user << "@";
|
||||
}
|
||||
link << fields.StringAt(FIELD_HOST);
|
||||
if (fields.StringAt(FIELD_PORT) != "105")
|
||||
link << ":" << fields.StringAt(FIELD_PORT);
|
||||
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"cso\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_GIF:
|
||||
case GOPHER_TYPE_IMAGE:
|
||||
case GOPHER_TYPE_PNG:
|
||||
case GOPHER_TYPE_BITMAP:
|
||||
/* quite dangerous, cf. gopher://namcub.accela-labs.com/1/pics */
|
||||
if (kInlineImages) {
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"img\">" << title << " "
|
||||
"<img src=\"" << link << "\" "
|
||||
"alt=\"" << title << "\"/>"
|
||||
"</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
}
|
||||
/* fallback to default, link them */
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"img\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_HTML:
|
||||
/* cf. gopher://pineapple.vg/1 */
|
||||
if (fields.StringAt(FIELD_SELECTOR).StartsWith("URL:")) {
|
||||
link = fields.StringAt(FIELD_SELECTOR);
|
||||
link.Remove(0, 4);
|
||||
}
|
||||
/* cf. gopher://sdf.org/1/sdf/classes/ */
|
||||
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"html\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_INFO:
|
||||
// TITLE resource, cf.
|
||||
// gopher://gophernicus.org/0/doc/gopher/gopher-title-resource.txt
|
||||
if (fPosition == 0 && pageTitle.Length() == 0
|
||||
&& fields.StringAt(FIELD_SELECTOR) == "TITLE") {
|
||||
pageTitle = title;
|
||||
break;
|
||||
}
|
||||
item << "<span class=\"info\">" << title << "</span>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_AUDIO:
|
||||
case GOPHER_TYPE_SOUND:
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"audio\">" << title << "</span></a>"
|
||||
"<audio src=\"" << link << "\" "
|
||||
//TODO:Fix crash in WebPositive with these
|
||||
//"controls=\"controls\" "
|
||||
//"width=\"300\" height=\"50\" "
|
||||
"alt=\"" << title << "\"/>"
|
||||
"<span>[player]</span></audio>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_PDF:
|
||||
case GOPHER_TYPE_DOC:
|
||||
/* generic case for known-to-work items */
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"document\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
case GOPHER_TYPE_MOVIE:
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"video\">" << title << "</span></a>"
|
||||
"<video src=\"" << link << "\" "
|
||||
//TODO:Fix crash in WebPositive with these
|
||||
//"controls=\"controls\" "
|
||||
//"width=\"300\" height=\"300\" "
|
||||
"alt=\"" << title << "\"/>"
|
||||
"<span>[player]</span></audio>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
default:
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
|
||||
"Unknown gopher item (type 0x%02x '%c')", type, type);
|
||||
item << "<a href=\"" << link << "\">"
|
||||
"<span class=\"unknown\">" << title << "</span></a>"
|
||||
"<br/>\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if (fPosition == 0) {
|
||||
if (pageTitle.Length() == 0)
|
||||
pageTitle << "Index of " << Url();
|
||||
|
||||
const char *uplink = ".";
|
||||
if (fPath.EndsWith("/"))
|
||||
uplink = "..";
|
||||
|
||||
// emit header
|
||||
BString header;
|
||||
header <<
|
||||
"<html>\n"
|
||||
"<head>\n"
|
||||
"<meta http-equiv=\"Content-Type\""
|
||||
" content=\"text/html; charset=UTF-8\" />\n"
|
||||
//FIXME: fix links
|
||||
//"<link rel=\"icon\" type=\"image/png\""
|
||||
// " href=\"resource:icons/directory.png\">\n"
|
||||
"<style type=\"text/css\">\n" << kStyleSheet << "</style>\n"
|
||||
"<title>" << pageTitle << "</title>\n"
|
||||
"</head>\n"
|
||||
"<body id=\"gopher\">\n"
|
||||
"<div class=\"uplink dontprint\">\n"
|
||||
"<a href=" << uplink << ">[up]</a>\n"
|
||||
"<a href=\"/\">[top]</a>\n"
|
||||
"</div>\n"
|
||||
"<h1>" << pageTitle << "</h1>\n";
|
||||
|
||||
if (fListener != NULL) {
|
||||
fListener->DataReceived(this, header.String(), fPosition,
|
||||
header.Length());
|
||||
}
|
||||
|
||||
fPosition += header.Length();
|
||||
|
||||
if (fListener != NULL)
|
||||
fListener->DownloadProgress(this, fPosition, 0);
|
||||
}
|
||||
|
||||
if (item.Length()) {
|
||||
if (fListener != NULL) {
|
||||
fListener->DataReceived(this, item.String(), fPosition,
|
||||
item.Length());
|
||||
}
|
||||
|
||||
fPosition += item.Length();
|
||||
|
||||
if (fListener != NULL)
|
||||
fListener->DownloadProgress(this, fPosition, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (last) {
|
||||
// emit footer
|
||||
BString footer =
|
||||
"</div>\n"
|
||||
"</body>\n"
|
||||
"</html>\n";
|
||||
|
||||
if (fListener != NULL) {
|
||||
fListener->DataReceived(this, footer.String(), fPosition,
|
||||
footer.Length());
|
||||
}
|
||||
|
||||
fPosition += footer.Length();
|
||||
|
||||
if (fListener != NULL)
|
||||
fListener->DownloadProgress(this, fPosition, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
status_t
|
||||
BGopherRequest::_ParseInput(bool last)
|
||||
{
|
||||
@@ -1216,7 +736,6 @@ BGopherRequest::_ParseInput(bool last)
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
BString&
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
|
||||
#include <AutoLocker.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
#if DEBUG > 0
|
||||
|
||||
@@ -22,10 +22,8 @@
|
||||
static int32 kBoundaryRandomSize = 16;
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
// #pragma mark - BHttpFormData
|
||||
|
||||
|
||||
@@ -14,10 +14,8 @@
|
||||
#include <String.h>
|
||||
#include <HttpHeaders.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
// #pragma mark -- BHttpHeader
|
||||
|
||||
|
||||
@@ -30,15 +30,12 @@
|
||||
#include <StackOrHeapArray.h>
|
||||
#include <ZlibCompressionAlgorithm.h>
|
||||
|
||||
using namespace BPrivate::Network;
|
||||
|
||||
|
||||
static const int32 kHttpBufferSize = 4096;
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class CheckedSecureSocket: public BSecureSocket
|
||||
@@ -101,53 +98,6 @@ namespace BPrivate {
|
||||
};
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BHttpRequest::BHttpRequest(const BUrl& url, bool ssl, const char* protocolName,
|
||||
BUrlProtocolListener* listener, BUrlContext* context)
|
||||
:
|
||||
BNetworkRequest(url, listener, context, "BUrlProtocol.HTTP", protocolName),
|
||||
fSSL(ssl),
|
||||
fRequestMethod(B_HTTP_GET),
|
||||
fHttpVersion(B_HTTP_11),
|
||||
fResult(url),
|
||||
fRequestStatus(kRequestInitialState),
|
||||
fOptHeaders(NULL),
|
||||
fOptPostFields(NULL),
|
||||
fOptInputData(NULL),
|
||||
fOptInputDataSize(-1),
|
||||
fOptRangeStart(-1),
|
||||
fOptRangeEnd(-1),
|
||||
fOptFollowLocation(true)
|
||||
{
|
||||
_ResetOptions();
|
||||
fSocket = NULL;
|
||||
}
|
||||
|
||||
|
||||
BHttpRequest::BHttpRequest(const BHttpRequest& other)
|
||||
:
|
||||
BNetworkRequest(other.Url(), other.fListener, other.fContext,
|
||||
"BUrlProtocol.HTTP", other.fSSL ? "HTTPS" : "HTTP"),
|
||||
fSSL(other.fSSL),
|
||||
fRequestMethod(other.fRequestMethod),
|
||||
fHttpVersion(other.fHttpVersion),
|
||||
fResult(other.fUrl),
|
||||
fRequestStatus(kRequestInitialState),
|
||||
fOptHeaders(NULL),
|
||||
fOptPostFields(NULL),
|
||||
fOptInputData(NULL),
|
||||
fOptInputDataSize(-1),
|
||||
fOptRangeStart(other.fOptRangeStart),
|
||||
fOptRangeEnd(other.fOptRangeEnd),
|
||||
fOptFollowLocation(other.fOptFollowLocation)
|
||||
{
|
||||
_ResetOptions();
|
||||
// FIXME some options may be copied from other instead.
|
||||
fSocket = NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BHttpRequest::BHttpRequest(const BUrl& url, BDataIO* output, bool ssl,
|
||||
const char* protocolName, BUrlProtocolListener* listener,
|
||||
BUrlContext* context)
|
||||
@@ -193,7 +143,6 @@ BHttpRequest::BHttpRequest(const BHttpRequest& other)
|
||||
// FIXME some options may be copied from other instead.
|
||||
fSocket = NULL;
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
BHttpRequest::~BHttpRequest()
|
||||
@@ -264,13 +213,11 @@ BHttpRequest::SetAutoReferrer(bool enable)
|
||||
}
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
void
|
||||
BHttpRequest::SetStopOnError(bool stop)
|
||||
{
|
||||
fOptStopOnError = stop;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
@@ -603,298 +550,6 @@ BHttpRequest::_ProtocolLoop()
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
status_t
|
||||
BHttpRequest::_MakeRequest()
|
||||
{
|
||||
delete fSocket;
|
||||
|
||||
if (fSSL) {
|
||||
if (fContext->UseProxy()) {
|
||||
BNetworkAddress proxy(fContext->GetProxyHost(), fContext->GetProxyPort());
|
||||
fSocket = new(std::nothrow) BPrivate::CheckedProxySecureSocket(proxy, this);
|
||||
} else
|
||||
fSocket = new(std::nothrow) BPrivate::CheckedSecureSocket(this);
|
||||
} else
|
||||
fSocket = new(std::nothrow) BSocket();
|
||||
|
||||
if (fSocket == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection to %s on port %d.",
|
||||
fUrl.Authority().String(), fRemoteAddr.Port());
|
||||
status_t connectError = fSocket->Connect(fRemoteAddr);
|
||||
|
||||
if (connectError != B_OK) {
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, "Socket connection error %s",
|
||||
strerror(connectError));
|
||||
return connectError;
|
||||
}
|
||||
|
||||
//! ProtocolHook:ConnectionOpened
|
||||
if (fListener != NULL)
|
||||
fListener->ConnectionOpened(this);
|
||||
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
|
||||
"Connection opened, sending request.");
|
||||
|
||||
BString requestHeaders;
|
||||
requestHeaders.Append(_SerializeRequest());
|
||||
requestHeaders.Append(_SerializeHeaders());
|
||||
requestHeaders.Append("\r\n");
|
||||
fSocket->Write(requestHeaders.String(), requestHeaders.Length());
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Request sent.");
|
||||
|
||||
_SendPostData();
|
||||
fRequestStatus = kRequestInitialState;
|
||||
|
||||
|
||||
|
||||
// Receive loop
|
||||
bool disableListener = false;
|
||||
bool receiveEnd = false;
|
||||
bool parseEnd = false;
|
||||
bool readByChunks = false;
|
||||
bool decompress = false;
|
||||
status_t readError = B_OK;
|
||||
ssize_t bytesRead = 0;
|
||||
off_t bytesReceived = 0;
|
||||
off_t bytesTotal = 0;
|
||||
size_t previousBufferSize = 0;
|
||||
off_t bytesUnpacked = 0;
|
||||
char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize];
|
||||
ArrayDeleter<char> inputTempBufferDeleter(inputTempBuffer);
|
||||
ssize_t inputTempSize = kHttpBufferSize;
|
||||
ssize_t chunkSize = -1;
|
||||
DynamicBuffer decompressorStorage;
|
||||
BDataIO* decompressingStream;
|
||||
ObjectDeleter<BDataIO> decompressingStreamDeleter;
|
||||
|
||||
while (!fQuit && !(receiveEnd && parseEnd)) {
|
||||
if ((!receiveEnd) && (fInputBuffer.Size() == previousBufferSize)) {
|
||||
BStackOrHeapArray<char, 4096> chunk(kHttpBufferSize);
|
||||
bytesRead = fSocket->Read(chunk, kHttpBufferSize);
|
||||
|
||||
if (bytesRead < 0) {
|
||||
readError = bytesRead;
|
||||
break;
|
||||
} else if (bytesRead == 0) {
|
||||
// Check if we got the expected number of bytes.
|
||||
// Exceptions:
|
||||
// - If the content-length is not known (bytesTotal is 0), for
|
||||
// example in the case of a chunked transfer, we can't know
|
||||
// - If the request method is "HEAD" which explicitly asks the
|
||||
// server to not send any data (only the headers)
|
||||
if (bytesTotal > 0 && bytesReceived != bytesTotal) {
|
||||
readError = B_IO_ERROR;
|
||||
break;
|
||||
}
|
||||
receiveEnd = true;
|
||||
}
|
||||
|
||||
fInputBuffer.AppendData(chunk, bytesRead);
|
||||
} else
|
||||
bytesRead = 0;
|
||||
|
||||
previousBufferSize = fInputBuffer.Size();
|
||||
|
||||
if (fRequestStatus < kRequestStatusReceived) {
|
||||
_ParseStatus();
|
||||
|
||||
//! ProtocolHook:ResponseStarted
|
||||
if (fRequestStatus >= kRequestStatusReceived && fListener != NULL
|
||||
&& !disableListener)
|
||||
fListener->ResponseStarted(this);
|
||||
}
|
||||
|
||||
if (fRequestStatus < kRequestHeadersReceived) {
|
||||
_ParseHeaders();
|
||||
|
||||
if (fRequestStatus >= kRequestHeadersReceived) {
|
||||
_ResultHeaders() = fHeaders;
|
||||
|
||||
// Parse received cookies
|
||||
if (fContext != NULL) {
|
||||
for (int32 i = 0; i < fHeaders.CountHeaders(); i++) {
|
||||
if (fHeaders.HeaderAt(i).NameIs("Set-Cookie")) {
|
||||
fContext->GetCookieJar().AddCookie(
|
||||
fHeaders.HeaderAt(i).Value(), fUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! ProtocolHook:HeadersReceived
|
||||
if (fListener != NULL && !disableListener)
|
||||
fListener->HeadersReceived(this, fResult);
|
||||
|
||||
|
||||
if (BString(fHeaders["Transfer-Encoding"]) == "chunked")
|
||||
readByChunks = true;
|
||||
|
||||
BString contentEncoding(fHeaders["Content-Encoding"]);
|
||||
// We don't advertise "deflate" support (see above), but we
|
||||
// still try to decompress it, if a server ever sends a deflate
|
||||
// stream despite it not being in our Accept-Encoding list.
|
||||
if (contentEncoding == "gzip"
|
||||
|| contentEncoding == "deflate") {
|
||||
decompress = true;
|
||||
readError = BZlibCompressionAlgorithm()
|
||||
.CreateDecompressingOutputStream(&decompressorStorage,
|
||||
NULL, decompressingStream);
|
||||
if (readError != B_OK)
|
||||
break;
|
||||
|
||||
decompressingStreamDeleter.SetTo(decompressingStream);
|
||||
}
|
||||
|
||||
int32 index = fHeaders.HasHeader("Content-Length");
|
||||
if (index != B_ERROR)
|
||||
bytesTotal = atoll(fHeaders.HeaderAt(index).Value());
|
||||
else
|
||||
bytesTotal = -1;
|
||||
|
||||
if (fRequestMethod == B_HTTP_HEAD
|
||||
|| fResult.StatusCode() == 204) {
|
||||
// In the case of a HEAD request or if the server replies
|
||||
// 204 ("no content"), we don't expect to receive anything
|
||||
// more, and the socket will be closed.
|
||||
receiveEnd = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fRequestStatus >= kRequestHeadersReceived) {
|
||||
// If Transfer-Encoding is chunked, we should read a complete
|
||||
// chunk in buffer before handling it
|
||||
if (readByChunks) {
|
||||
if (chunkSize >= 0) {
|
||||
if ((ssize_t)fInputBuffer.Size() >= chunkSize + 2) {
|
||||
// 2 more bytes to handle the closing CR+LF
|
||||
bytesRead = chunkSize;
|
||||
if (inputTempSize < chunkSize + 2) {
|
||||
inputTempSize = chunkSize + 2;
|
||||
inputTempBuffer
|
||||
= new(std::nothrow) char[inputTempSize];
|
||||
inputTempBufferDeleter.SetTo(inputTempBuffer);
|
||||
}
|
||||
|
||||
if (inputTempBuffer == NULL) {
|
||||
readError = B_NO_MEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
fInputBuffer.RemoveData(inputTempBuffer,
|
||||
chunkSize + 2);
|
||||
chunkSize = -1;
|
||||
} else {
|
||||
// Not enough data, try again later
|
||||
bytesRead = -1;
|
||||
}
|
||||
} else {
|
||||
BString chunkHeader;
|
||||
if (_GetLine(chunkHeader) == B_ERROR) {
|
||||
chunkSize = -1;
|
||||
bytesRead = -1;
|
||||
} else {
|
||||
// Format of a chunk header:
|
||||
// <chunk size in hex>[; optional data]
|
||||
int32 semiColonIndex = chunkHeader.FindFirst(';', 0);
|
||||
|
||||
// Cut-off optional data if present
|
||||
if (semiColonIndex != -1) {
|
||||
chunkHeader.Remove(semiColonIndex,
|
||||
chunkHeader.Length() - semiColonIndex);
|
||||
}
|
||||
|
||||
chunkSize = strtol(chunkHeader.String(), NULL, 16);
|
||||
if (chunkSize == 0)
|
||||
fRequestStatus = kRequestContentReceived;
|
||||
|
||||
bytesRead = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// A chunk of 0 bytes indicates the end of the chunked transfer
|
||||
if (bytesRead == 0)
|
||||
receiveEnd = true;
|
||||
} else {
|
||||
bytesRead = fInputBuffer.Size();
|
||||
|
||||
if (bytesRead > 0) {
|
||||
if (inputTempSize < bytesRead) {
|
||||
inputTempSize = bytesRead;
|
||||
inputTempBuffer = new(std::nothrow) char[bytesRead];
|
||||
inputTempBufferDeleter.SetTo(inputTempBuffer);
|
||||
}
|
||||
|
||||
if (inputTempBuffer == NULL) {
|
||||
readError = B_NO_MEMORY;
|
||||
break;
|
||||
}
|
||||
fInputBuffer.RemoveData(inputTempBuffer, bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
if (bytesRead >= 0) {
|
||||
bytesReceived += bytesRead;
|
||||
|
||||
if (fListener != NULL && !disableListener) {
|
||||
if (decompress) {
|
||||
readError = decompressingStream->WriteExactly(
|
||||
inputTempBuffer, bytesRead);
|
||||
if (readError != B_OK)
|
||||
break;
|
||||
|
||||
ssize_t size = decompressorStorage.Size();
|
||||
BStackOrHeapArray<char, 4096> buffer(size);
|
||||
size = decompressorStorage.Read(buffer, size);
|
||||
_NotifyDataReceived(buffer, bytesUnpacked, size,
|
||||
bytesReceived, bytesTotal);
|
||||
bytesUnpacked += size;
|
||||
} else if (bytesRead > 0) {
|
||||
_NotifyDataReceived(inputTempBuffer,
|
||||
bytesReceived - bytesRead, bytesRead,
|
||||
bytesReceived, bytesTotal);
|
||||
}
|
||||
}
|
||||
|
||||
if (bytesTotal >= 0 && bytesReceived >= bytesTotal)
|
||||
receiveEnd = true;
|
||||
|
||||
if (decompress && receiveEnd && !disableListener) {
|
||||
readError = decompressingStream->Flush();
|
||||
|
||||
if (readError == B_BUFFER_OVERFLOW)
|
||||
readError = B_OK;
|
||||
|
||||
if (readError != B_OK)
|
||||
break;
|
||||
|
||||
ssize_t size = decompressorStorage.Size();
|
||||
BStackOrHeapArray<char, 4096> buffer(size);
|
||||
size = decompressorStorage.Read(buffer, size);
|
||||
if (fListener != NULL) {
|
||||
_NotifyDataReceived(buffer, bytesUnpacked, size,
|
||||
bytesReceived, bytesTotal);
|
||||
bytesUnpacked += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parseEnd = (fInputBuffer.Size() == 0);
|
||||
}
|
||||
|
||||
fSocket->Disconnect();
|
||||
|
||||
if (readError != B_OK)
|
||||
return readError;
|
||||
|
||||
return fQuit ? B_INTERRUPTED : B_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
status_t
|
||||
BHttpRequest::_MakeRequest()
|
||||
{
|
||||
@@ -1214,7 +869,6 @@ BHttpRequest::_MakeRequest()
|
||||
|
||||
return fQuit ? B_INTERRUPTED : B_OK;
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
void
|
||||
@@ -1598,33 +1252,3 @@ BHttpRequest::_IsDefaultPort()
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
void
|
||||
BHttpRequest::_NotifyDataReceived(const char* data, off_t pos, ssize_t size,
|
||||
off_t bytesReceived, ssize_t bytesTotal)
|
||||
{
|
||||
if (fListener == NULL || size <= 0)
|
||||
return;
|
||||
if (fOptRangeStart > 0) {
|
||||
pos += fOptRangeStart;
|
||||
// bytesReceived and bytesTotal refer to the requested range,
|
||||
// so that should technically not be adjusted for the range start.
|
||||
// For displaying progress to the user, this is not ideal, though.
|
||||
// But only for the case where we request the remainder of a file.
|
||||
// Range requests can also be used to request any portion of a
|
||||
// resource, so not modifying them is technically more correct.
|
||||
// We can use a little trick, though: We know when the remainder
|
||||
// is requested, because then fOptRangeEnd is -1.
|
||||
if (fOptRangeEnd == -1) {
|
||||
bytesReceived += fOptRangeStart;
|
||||
if (bytesTotal > 0)
|
||||
bytesTotal += fOptRangeStart;
|
||||
}
|
||||
}
|
||||
fListener->DataReceived(this, data, pos, size);
|
||||
fListener->DownloadProgress(this, bytesReceived,
|
||||
std::max((ssize_t)0, bytesTotal));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,10 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <Debug.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
BHttpResult::BHttpResult(const BUrl& url)
|
||||
@@ -27,23 +24,6 @@ BHttpResult::BHttpResult(const BUrl& url)
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BHttpResult::BHttpResult(BMessage* archive)
|
||||
:
|
||||
BUrlResult(archive),
|
||||
fUrl(archive->FindString("http:url")),
|
||||
fHeaders(),
|
||||
fStatusCode(archive->FindInt32("http:statusCode"))
|
||||
{
|
||||
fStatusString = archive->FindString("http:statusString");
|
||||
|
||||
BMessage headers;
|
||||
archive->FindMessage("http:headers", &headers);
|
||||
fHeaders.PopulateFromArchive(&headers);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
BHttpResult::BHttpResult(const BHttpResult& other)
|
||||
:
|
||||
fUrl(other.fUrl),
|
||||
@@ -86,38 +66,6 @@ BHttpResult::ContentType() const
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
size_t
|
||||
BHttpResult::Length() const
|
||||
{
|
||||
const char* length = Headers()["Content-Length"];
|
||||
if (length == NULL)
|
||||
return 0;
|
||||
|
||||
/* NOTE: Not RFC7230 compliant:
|
||||
* - If Content-Length is a list, all values must be checked and verified
|
||||
* to be duplicates of each other, but this is currently not supported.
|
||||
*/
|
||||
size_t result = 0;
|
||||
/* strtoul() will ignore a prefixed sign, so we verify that there aren't
|
||||
* any before continuing (RFC7230 only permits digits).
|
||||
*
|
||||
* We can check length[0] directly because header values are trimmed by
|
||||
* HttpHeader beforehand. */
|
||||
if (length[0] != '-' && length[0] != '+') {
|
||||
errno = 0;
|
||||
char *endptr = NULL;
|
||||
result = strtoul(length, &endptr, 10);
|
||||
/* ERANGE will be signalled if the result is too large (which can
|
||||
* happen), in that case, return 0. */
|
||||
if (errno != 0 || *endptr != '\0')
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
off_t
|
||||
BHttpResult::Length() const
|
||||
{
|
||||
@@ -146,7 +94,6 @@ BHttpResult::Length() const
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif // BNETAPI_DEPRECATED
|
||||
|
||||
|
||||
const BHttpHeaders&
|
||||
@@ -196,34 +143,3 @@ BHttpResult::operator=(const BHttpResult& other)
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
status_t
|
||||
BHttpResult::Archive(BMessage* target, bool deep) const
|
||||
{
|
||||
status_t result = BUrlResult::Archive(target, deep);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
target->AddString("http:url", fUrl);
|
||||
target->AddInt32("http:statusCode", fStatusCode);
|
||||
target->AddString("http:statusString", fStatusString);
|
||||
|
||||
BMessage headers;
|
||||
fHeaders.Archive(&headers);
|
||||
target->AddMessage("http:headers", &headers);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ BArchivable*
|
||||
BHttpResult::Instantiate(BMessage* archive)
|
||||
{
|
||||
if (!validate_instantiation(archive, "BHttpResult"))
|
||||
return NULL;
|
||||
|
||||
return new BHttpResult(archive);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
using namespace BPrivate::Network;
|
||||
|
||||
|
||||
// The formats used should be, in order of preference (according to RFC2616,
|
||||
// section 3.3):
|
||||
@@ -47,12 +49,6 @@ static const char* kDateFormats[] = {
|
||||
"%a %d %b %H:%M:%S %Y"
|
||||
};
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate;
|
||||
#else
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
BHttpTime::BHttpTime()
|
||||
:
|
||||
@@ -78,7 +74,7 @@ BHttpTime::BHttpTime(const BString& dateString)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #pragma mark Date modification
|
||||
|
||||
|
||||
@@ -95,7 +91,7 @@ BHttpTime::SetDate(BDateTime date)
|
||||
fDate = date;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #pragma mark Date conversion
|
||||
|
||||
|
||||
@@ -103,7 +99,7 @@ BDateTime
|
||||
BHttpTime::Parse()
|
||||
{
|
||||
struct tm expireTime;
|
||||
|
||||
|
||||
if (fDateString.Length() < 4)
|
||||
return 0;
|
||||
|
||||
@@ -162,10 +158,10 @@ BHttpTime::ToString(int8 format)
|
||||
static const uint16 kTimetToStringMaxLength = 128;
|
||||
char expirationString[kTimetToStringMaxLength + 1];
|
||||
size_t strLength;
|
||||
|
||||
|
||||
strLength = strftime(expirationString, kTimetToStringMaxLength,
|
||||
kDateFormats[format], &expirationTm);
|
||||
|
||||
|
||||
expirationFinal.SetTo(expirationString, strLength);
|
||||
}
|
||||
return expirationFinal;
|
||||
|
||||
@@ -20,12 +20,8 @@
|
||||
#include <HttpTime.h>
|
||||
#include <NetworkCookie.h>
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
using BPrivate::BHttpTime;
|
||||
using BPrivate::B_HTTP_TIME_FORMAT_COOKIE;
|
||||
#else
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
static const char* kArchivedCookieName = "be:cookie.name";
|
||||
static const char* kArchivedCookieValue = "be:cookie.value";
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
|
||||
#include "NetworkCookieJarPrivate.h"
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
// #define TRACE_COOKIE
|
||||
#ifdef TRACE_COOKIE
|
||||
|
||||
@@ -8,12 +8,9 @@
|
||||
|
||||
#include <HashMap.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using BPrivate::Network::BNetworkCookie;
|
||||
using BPrivate::Network::BNetworkCookieJar;
|
||||
using BPrivate::Network::BNetworkCookieList;
|
||||
#endif
|
||||
|
||||
|
||||
typedef BPrivate::SynchronizedHashMap<HashString, BNetworkCookieList*>
|
||||
@@ -24,14 +21,14 @@ struct BNetworkCookieJar::PrivateHashMap : public BNetworkCookieHashMap {
|
||||
|
||||
struct BNetworkCookieJar::PrivateIterator {
|
||||
PrivateIterator(
|
||||
BNetworkCookieHashMap::Iterator it)
|
||||
BNetworkCookieHashMap::Iterator it)
|
||||
:
|
||||
fCookieMapIterator(it)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashString fKey;
|
||||
BNetworkCookieHashMap::Iterator
|
||||
BNetworkCookieHashMap::Iterator
|
||||
fCookieMapIterator;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,23 +13,9 @@
|
||||
|
||||
#include <AbstractSocket.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BNetworkRequest::BNetworkRequest(const BUrl& url, BUrlProtocolListener* listener,
|
||||
BUrlContext* context, const char* threadName, const char* protocolName)
|
||||
:
|
||||
BUrlRequest(url, listener, context, threadName, protocolName),
|
||||
fSocket(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BNetworkRequest::BNetworkRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener, BUrlContext* context,
|
||||
const char* threadName, const char* protocolName)
|
||||
@@ -38,7 +24,6 @@ BNetworkRequest::BNetworkRequest(const BUrl& url, BDataIO* output,
|
||||
fSocket(NULL)
|
||||
{
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
status_t
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
#include <HashMap.h>
|
||||
#include <HashString.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
class BUrlContext::BHttpAuthenticationMap : public
|
||||
SynchronizedHashMap<BPrivate::HashString, BHttpAuthentication*> {};
|
||||
|
||||
@@ -18,10 +18,7 @@
|
||||
#include <String.h>
|
||||
#include <UrlResult.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
extern const char* kUrlProtocolMessageType;
|
||||
@@ -102,60 +99,6 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
|
||||
ResponseStarted(caller);
|
||||
break;
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
case B_URL_PROTOCOL_HEADERS_RECEIVED:
|
||||
{
|
||||
BMessage archive;
|
||||
message->FindMessage("url:result", &archive);
|
||||
BUrlResult* result = dynamic_cast<BUrlResult*>(
|
||||
instantiate_object(&archive));
|
||||
if (result == NULL) {
|
||||
debugger("Failed to unarchive BUrlResult");
|
||||
result = new BUrlResult();
|
||||
}
|
||||
HeadersReceived(caller, *result);
|
||||
delete result;
|
||||
}
|
||||
|
||||
case B_URL_PROTOCOL_DATA_RECEIVED:
|
||||
{
|
||||
const char* data;
|
||||
ssize_t size = 0;
|
||||
if (message->FindData("url:data", B_STRING_TYPE,
|
||||
reinterpret_cast<const void**>(&data), &size) != B_OK) {
|
||||
printf("BOGUS DATA MESSAGE\n");
|
||||
message->PrintToStream();
|
||||
return;
|
||||
}
|
||||
|
||||
off_t position = message->FindInt32("url:position");
|
||||
|
||||
DataReceived(caller, data, position, size);
|
||||
}
|
||||
break;
|
||||
|
||||
case B_URL_PROTOCOL_DOWNLOAD_PROGRESS:
|
||||
{
|
||||
int32 bytesReceived;
|
||||
int32 bytesTotal;
|
||||
message->FindInt32("url:bytesReceived", &bytesReceived);
|
||||
message->FindInt32("url:bytesTotal", &bytesTotal);
|
||||
|
||||
DownloadProgress(caller, bytesReceived, bytesTotal);
|
||||
}
|
||||
break;
|
||||
|
||||
case B_URL_PROTOCOL_UPLOAD_PROGRESS:
|
||||
{
|
||||
int32 bytesSent;
|
||||
int32 bytesTotal;
|
||||
message->FindInt32("url:bytesSent", &bytesSent);
|
||||
message->FindInt32("url:bytesTotal", &bytesTotal);
|
||||
|
||||
UploadProgress(caller, bytesSent, bytesTotal);
|
||||
}
|
||||
break;
|
||||
#else
|
||||
case B_URL_PROTOCOL_HEADERS_RECEIVED:
|
||||
HeadersReceived(caller);
|
||||
break;
|
||||
@@ -189,7 +132,6 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
|
||||
UploadProgress(caller, bytesSent, bytesTotal);
|
||||
}
|
||||
break;
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
case B_URL_PROTOCOL_REQUEST_COMPLETED:
|
||||
{
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
const char* kUrlProtocolMessageType = "be:urlProtocolMessageType";
|
||||
const char* kUrlProtocolCaller = "be:urlProtocolCaller";
|
||||
@@ -72,66 +70,6 @@ BUrlProtocolDispatchingListener::ResponseStarted(BUrlRequest* caller)
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
void
|
||||
BUrlProtocolDispatchingListener::HeadersReceived(BUrlRequest* caller,
|
||||
const BUrlResult& result)
|
||||
{
|
||||
/* The URL request does not keep the headers valid after calling this
|
||||
* method. For asynchronous delivery to work, we need to archive them
|
||||
* into the message. */
|
||||
BMessage message(B_URL_PROTOCOL_NOTIFICATION);
|
||||
BMessage archive;
|
||||
result.Archive(&archive, true);
|
||||
message.AddMessage("url:result", &archive);
|
||||
|
||||
_SendMessage(&message, B_URL_PROTOCOL_HEADERS_RECEIVED, caller);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolDispatchingListener::DataReceived(BUrlRequest* caller,
|
||||
const char* data, off_t position, ssize_t size)
|
||||
{
|
||||
BMessage message(B_URL_PROTOCOL_NOTIFICATION);
|
||||
status_t result = message.AddData("url:data", B_STRING_TYPE, data, size,
|
||||
true, 1);
|
||||
assert(result == B_OK);
|
||||
|
||||
result = message.AddInt32("url:position", position);
|
||||
assert(result == B_OK);
|
||||
|
||||
_SendMessage(&message, B_URL_PROTOCOL_DATA_RECEIVED, caller);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolDispatchingListener::DownloadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesReceived, ssize_t bytesTotal)
|
||||
{
|
||||
BMessage message(B_URL_PROTOCOL_NOTIFICATION);
|
||||
message.AddInt32("url:bytesReceived", bytesReceived);
|
||||
message.AddInt32("url:bytesTotal", bytesTotal);
|
||||
|
||||
_SendMessage(&message, B_URL_PROTOCOL_DOWNLOAD_PROGRESS, caller);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolDispatchingListener::UploadProgress(BUrlRequest* caller,
|
||||
ssize_t bytesSent, ssize_t bytesTotal)
|
||||
{
|
||||
BMessage message(B_URL_PROTOCOL_NOTIFICATION);
|
||||
message.AddInt32("url:bytesSent", bytesSent);
|
||||
message.AddInt32("url:bytesTotal", bytesTotal);
|
||||
|
||||
_SendMessage(&message, B_URL_PROTOCOL_UPLOAD_PROGRESS, caller);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolDispatchingListener::HeadersReceived(BUrlRequest* caller)
|
||||
{
|
||||
@@ -173,7 +111,6 @@ BUrlProtocolDispatchingListener::UploadProgress(BUrlRequest* caller,
|
||||
|
||||
_SendMessage(&message, B_URL_PROTOCOL_UPLOAD_PROGRESS, caller);
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
void
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
#include <UrlProtocolListener.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolListener::ConnectionOpened(BUrlRequest*)
|
||||
@@ -44,31 +42,6 @@ BUrlProtocolListener::ResponseStarted(BUrlRequest*)
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
void
|
||||
BUrlProtocolListener::HeadersReceived(BUrlRequest*, const BUrlResult& result)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolListener::DataReceived(BUrlRequest*, const char*, off_t, ssize_t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolListener::DownloadProgress(BUrlRequest*, ssize_t, ssize_t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlProtocolListener::UploadProgress(BUrlRequest*, ssize_t, ssize_t)
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
BUrlProtocolListener::HeadersReceived(BUrlRequest*)
|
||||
@@ -92,7 +65,6 @@ void
|
||||
BUrlProtocolListener::UploadProgress(BUrlRequest*, off_t, off_t)
|
||||
{
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
void
|
||||
|
||||
@@ -18,36 +18,9 @@
|
||||
#include <HttpRequest.h>
|
||||
#include <UrlRequest.h>
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
/* static */ BUrlRequest*
|
||||
BUrlProtocolRoster::MakeRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener, BUrlContext* context)
|
||||
{
|
||||
// TODO: instanciate the correct BUrlProtocol using add-on interface
|
||||
if (url.Protocol() == "http") {
|
||||
return new(std::nothrow) BHttpRequest(url, false, "HTTP", listener,
|
||||
context);
|
||||
} else if (url.Protocol() == "https") {
|
||||
return new(std::nothrow) BHttpRequest(url, true, "HTTPS", listener,
|
||||
context);
|
||||
} else if (url.Protocol() == "file") {
|
||||
return new(std::nothrow) BFileRequest(url, listener, context);
|
||||
} else if (url.Protocol() == "data") {
|
||||
return new(std::nothrow) BDataRequest(url, listener, context);
|
||||
} else if (url.Protocol() == "gopher") {
|
||||
return new(std::nothrow) BGopherRequest(url, listener, context);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* static */ BUrlRequest*
|
||||
BUrlProtocolRoster::MakeRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener, BUrlContext* context)
|
||||
@@ -69,4 +42,3 @@ BUrlProtocolRoster::MakeRequest(const BUrl& url, BDataIO* output,
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif //LIBNETAPI_DEPRECATED
|
||||
|
||||
@@ -11,34 +11,12 @@
|
||||
#include <Debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
|
||||
static BReference<BUrlContext> gDefaultContext = new(std::nothrow) BUrlContext();
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BUrlRequest::BUrlRequest(const BUrl& url, BUrlProtocolListener* listener,
|
||||
BUrlContext* context, const char* threadName, const char* protocolName)
|
||||
:
|
||||
fUrl(url),
|
||||
fContext(context),
|
||||
fListener(listener),
|
||||
fQuit(false),
|
||||
fRunning(false),
|
||||
fThreadStatus(B_NO_INIT),
|
||||
fThreadId(0),
|
||||
fThreadName(threadName),
|
||||
fProtocol(protocolName)
|
||||
{
|
||||
if (fContext == NULL)
|
||||
fContext = gDefaultContext;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BUrlRequest::BUrlRequest(const BUrl& url, BDataIO* output,
|
||||
BUrlProtocolListener* listener, BUrlContext* context,
|
||||
const char* threadName, const char* protocolName)
|
||||
@@ -57,7 +35,6 @@ BUrlRequest::BUrlRequest(const BUrl& url, BDataIO* output,
|
||||
if (fContext == NULL)
|
||||
fContext = gDefaultContext;
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
BUrlRequest::~BUrlRequest()
|
||||
@@ -109,22 +86,6 @@ BUrlRequest::Stop()
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
status_t
|
||||
BUrlRequest::Pause()
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BUrlRequest::Resume()
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// #pragma mark URL protocol parameters modification
|
||||
|
||||
|
||||
@@ -166,7 +127,6 @@ BUrlRequest::SetListener(BUrlProtocolListener* listener)
|
||||
}
|
||||
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
status_t
|
||||
BUrlRequest::SetOutput(BDataIO* output)
|
||||
{
|
||||
@@ -176,7 +136,6 @@ BUrlRequest::SetOutput(BDataIO* output)
|
||||
fOutput = output;
|
||||
return B_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// #pragma mark URL protocol parameters access
|
||||
|
||||
@@ -10,23 +10,11 @@
|
||||
|
||||
#include <UrlSynchronousRequest.h>
|
||||
|
||||
using namespace BPrivate::Network;
|
||||
|
||||
|
||||
#define PRINT(x) printf x;
|
||||
|
||||
#ifndef LIBNETAPI_DEPRECATED
|
||||
using namespace BPrivate::Network;
|
||||
#endif
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
BUrlSynchronousRequest::BUrlSynchronousRequest(BUrlRequest& request)
|
||||
:
|
||||
BUrlRequest(request.Url(), NULL, request.Context(),
|
||||
"BUrlSynchronousRequest", request.Protocol()),
|
||||
fRequestComplete(false),
|
||||
fWrappedRequest(request)
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BUrlSynchronousRequest::BUrlSynchronousRequest(BUrlRequest& request)
|
||||
:
|
||||
@@ -36,7 +24,6 @@ BUrlSynchronousRequest::BUrlSynchronousRequest(BUrlRequest& request)
|
||||
fWrappedRequest(request)
|
||||
{
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
status_t
|
||||
@@ -86,41 +73,6 @@ BUrlSynchronousRequest::ResponseStarted(BUrlRequest*)
|
||||
}
|
||||
|
||||
|
||||
#ifdef LIBNETAPI_DEPRECATED
|
||||
void
|
||||
BUrlSynchronousRequest::HeadersReceived(BUrlRequest*, const BUrlResult& result)
|
||||
{
|
||||
PRINT(("SynchronousRequest::HeadersReceived()\n"));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlSynchronousRequest::DataReceived(BUrlRequest*, const char*,
|
||||
off_t, ssize_t size)
|
||||
{
|
||||
PRINT(("SynchronousRequest::DataReceived(%zd)\n", size));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlSynchronousRequest::DownloadProgress(BUrlRequest*,
|
||||
ssize_t bytesReceived, ssize_t bytesTotal)
|
||||
{
|
||||
PRINT(("SynchronousRequest::DownloadProgress(%zd, %zd)\n", bytesReceived,
|
||||
bytesTotal));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BUrlSynchronousRequest::UploadProgress(BUrlRequest*, ssize_t bytesSent,
|
||||
ssize_t bytesTotal)
|
||||
{
|
||||
PRINT(("SynchronousRequest::UploadProgress(%zd, %zd)\n", bytesSent,
|
||||
bytesTotal));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
BUrlSynchronousRequest::HeadersReceived(BUrlRequest*)
|
||||
{
|
||||
@@ -152,7 +104,6 @@ BUrlSynchronousRequest::UploadProgress(BUrlRequest*, off_t bytesSent,
|
||||
PRINT(("SynchronousRequest::UploadProgress(%" B_PRIdOFF ", %" B_PRIdOFF
|
||||
")\n", bytesSent, bytesTotal));
|
||||
}
|
||||
#endif // LIBNETAPI_DEPRECATED
|
||||
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user