libnetapi.so: make headers of deprecated classes private

These classes have been moved to the public API too soon, and they need some
more time to mature before they can be declared stable.

Change-Id: I9c52a8e6cc103922abde7a6b911fe0c3e6bf5700
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3665
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Niels Sascha Reedijk
2021-01-27 19:53:11 +00:00
parent 35d8d4d113
commit 603e0bdf62
26 changed files with 9 additions and 4 deletions
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Adrien Destugues, [email protected]
*/
#ifndef _B_DATA_REQUEST_H_
#define _B_DATA_REQUEST_H_
#include <UrlProtocolRoster.h>
#include <UrlRequest.h>
class BDataRequest: public BUrlRequest {
public:
const BUrlResult& Result() const;
private:
friend class BUrlProtocolRoster;
BDataRequest(const BUrl& url,
BUrlProtocolListener* listener = NULL,
BUrlContext* context = NULL);
status_t _ProtocolLoop();
private:
BUrlResult fResult;
};
#endif
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright 2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_FILE_REQUEST_H_
#define _B_FILE_REQUEST_H_
#include <deque>
#include <UrlRequest.h>
#include <UrlProtocolRoster.h>
class BFileRequest : public BUrlRequest {
public:
virtual ~BFileRequest();
const BUrlResult& Result() const;
void SetDisableListener(bool disable);
private:
friend class BUrlProtocolRoster;
BFileRequest(const BUrl& url,
BUrlProtocolListener* listener = NULL,
BUrlContext* context = NULL);
status_t _ProtocolLoop();
private:
BUrlResult fResult;
};
#endif // _B_FILE_REQUEST_H_
@@ -0,0 +1,49 @@
/*
* Copyright 2014 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_GOPHER_REQUEST_H_
#define _B_GOPHER_REQUEST_H_
#include <deque>
#include <NetworkRequest.h>
#include <UrlProtocolRoster.h>
class BGopherRequest : public BNetworkRequest {
public:
virtual ~BGopherRequest();
status_t Stop();
const BUrlResult& Result() const;
void SetDisableListener(bool disable);
private:
friend class BUrlProtocolRoster;
BGopherRequest(const BUrl& url,
BUrlProtocolListener* listener = NULL,
BUrlContext* context = NULL);
status_t _ProtocolLoop();
void _SendRequest();
bool _NeedsParsing();
bool _NeedsLastDotStrip();
void _ParseInput(bool last);
BString& _HTMLEscapeString(BString &str);
private:
char fItemType;
BString fPath;
ssize_t fPosition;
BUrlResult fResult;
};
#endif // _B_GOPHER_REQUEST_H_
@@ -0,0 +1,101 @@
/*
* Copyright 2010-2014 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_HTTP_AUTHENTICATION_H_
#define _B_HTTP_AUTHENTICATION_H_
#include <Locker.h>
#include <String.h>
#include <Url.h>
// HTTP authentication method
enum BHttpAuthenticationMethod {
B_HTTP_AUTHENTICATION_NONE = 0,
// No authentication
B_HTTP_AUTHENTICATION_BASIC = 1,
// Basic base64 authentication method (unsecure)
B_HTTP_AUTHENTICATION_DIGEST = 2,
// Digest authentication
B_HTTP_AUTHENTICATION_IE_DIGEST = 4
// Slightly modified digest authentication to mimic old IE one
};
enum BHttpAuthenticationAlgorithm {
B_HTTP_AUTHENTICATION_ALGORITHM_NONE,
B_HTTP_AUTHENTICATION_ALGORITHM_MD5,
B_HTTP_AUTHENTICATION_ALGORITHM_MD5_SESS
};
enum BHttpAuthenticationQop {
B_HTTP_QOP_NONE,
B_HTTP_QOP_AUTH,
B_HTTP_QOP_AUTHINT
};
class BHttpAuthentication {
public:
BHttpAuthentication();
BHttpAuthentication(const BString& username,
const BString& password);
BHttpAuthentication(
const BHttpAuthentication& other);
BHttpAuthentication& operator=(
const BHttpAuthentication& other);
// Field modification
void SetUserName(const BString& username);
void SetPassword(const BString& password);
void SetMethod(
BHttpAuthenticationMethod type);
status_t Initialize(const BString& wwwAuthenticate);
// Field access
const BString& UserName() const;
const BString& Password() const;
BHttpAuthenticationMethod Method() const;
BString Authorization(const BUrl& url,
const BString& method) const;
// Base64 encoding
// TODO: Move to a common place. We may have multiple implementations
// in the Haiku tree...
static BString Base64Encode(const BString& string);
static BString Base64Decode(const BString& string);
private:
BString _DigestResponse(const BString& uri,
const BString& method) const;
// TODO: Rename these? _H seems to return a hash value,
// _KD returns a hash value of the "data" prepended by
// the "secret" string...
BString _H(const BString& value) const;
BString _KD(const BString& secret,
const BString& data) const;
private:
BHttpAuthenticationMethod fAuthenticationMethod;
BString fUserName;
BString fPassword;
BString fRealm;
BString fDigestNonce;
mutable BString fDigestCnonce;
mutable int fDigestNc;
BString fDigestOpaque;
bool fDigestStale;
BHttpAuthenticationAlgorithm fDigestAlgorithm;
BHttpAuthenticationQop fDigestQop;
BString fAuthorizationString;
mutable BLocker fLock;
};
#endif // _B_HTTP_AUTHENTICATION_H_
+191
View File
@@ -0,0 +1,191 @@
/*
* Copyright 2010-2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_HTTP_FORM_H_
#define _B_HTTP_FORM_H_
#include <Path.h>
#include <String.h>
#include <map>
enum form_type {
B_HTTP_FORM_URL_ENCODED,
B_HTTP_FORM_MULTIPART
};
enum form_content_type {
B_HTTPFORM_UNKNOWN,
B_HTTPFORM_STRING,
B_HTTPFORM_FILE,
B_HTTPFORM_BUFFER
};
class BHttpFormData {
private:
// Empty constructor is only kept for compatibility with map<>::operator[],
// but never used (see BHttpForm::operator[] which does the necessary
// check up)
BHttpFormData();
#if (__GNUC__ >= 6) || defined(__clang__)
friend class std::pair<const BString, BHttpFormData>;
#else
friend class std::map<BString, BHttpFormData>;
#endif
public:
BHttpFormData(const BString& name,
const BString& value);
BHttpFormData(const BString& name,
const BPath& file);
BHttpFormData(const BString& name,
const void* buffer, ssize_t size);
BHttpFormData(const BHttpFormData& other);
~BHttpFormData();
// Retrieve data informations
bool InitCheck() const;
const BString& Name() const;
const BString& String() const;
const BPath& File() const;
const void* Buffer() const;
ssize_t BufferSize() const;
bool IsFile() const;
const BString& Filename() const;
const BString& MimeType() const;
form_content_type Type() const;
// Change behavior
status_t MarkAsFile(const BString& filename,
const BString& mimeType = "");
void UnmarkAsFile();
status_t CopyBuffer();
// Overloaded operators
BHttpFormData& operator=(const BHttpFormData& other);
private:
form_content_type fDataType;
bool fCopiedBuffer;
bool fFileMark;
BString fName;
BString fStringValue;
BPath fPathValue;
const void* fBufferValue;
ssize_t fBufferSize;
BString fFilename;
BString fMimeType;
};
class BHttpForm {
public:
// Nested types
class Iterator;
typedef std::map<BString, BHttpFormData> FormStorage;
public:
BHttpForm();
BHttpForm(const BHttpForm& other);
BHttpForm(const BString& formString);
~BHttpForm();
// Form string parsing
void ParseString(const BString& formString);
BString RawData() const;
// Form add
status_t AddString(const BString& name,
const BString& value);
status_t AddInt(const BString& name, int32 value);
status_t AddFile(const BString& fieldName,
const BPath& file);
status_t AddBuffer(const BString& fieldName,
const void* buffer, ssize_t size);
status_t AddBufferCopy(const BString& fieldName,
const void* buffer, ssize_t size);
// Mark a field as a filename
void MarkAsFile(const BString& fieldName,
const BString& filename,
const BString& mimeType);
void MarkAsFile(const BString& fieldName,
const BString& filename);
void UnmarkAsFile(const BString& fieldName);
// Change form type
void SetFormType(form_type type);
// Form test
bool HasField(const BString& name) const;
// Form retrieve
BString GetMultipartHeader(const BString& fieldName) const;
form_content_type GetType(const BString& fieldname) const;
// Form informations
form_type GetFormType() const;
const BString& GetMultipartBoundary() const;
BString GetMultipartFooter() const;
ssize_t ContentLength() const;
// Form iterator
Iterator GetIterator();
// Form clear
void Clear();
// Overloaded operators
BHttpFormData& operator[](const BString& name);
private:
void _ExtractNameValuePair(const BString& string, int32* index);
void _GenerateMultipartBoundary();
BString _GetMultipartHeader(const BHttpFormData* element) const;
form_content_type _GetType(FormStorage::const_iterator it) const;
void _Erase(FormStorage::iterator it);
private:
friend class Iterator;
FormStorage fFields;
form_type fType;
BString fMultipartBoundary;
};
class BHttpForm::Iterator {
public:
Iterator(const Iterator& other);
BHttpFormData* Next();
bool HasNext() const;
void Remove();
BString MultipartHeader();
Iterator& operator=(const Iterator& other);
private:
Iterator(BHttpForm* form);
void _FindNext();
private:
friend class BHttpForm;
BHttpForm* fForm;
BHttpForm::FormStorage::iterator
fStdIterator;
BHttpFormData* fElement;
BHttpFormData* fPrevElement;
};
#endif // _B_HTTP_FORM_H_
+90
View File
@@ -0,0 +1,90 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_HTTP_HEADERS_H_
#define _B_HTTP_HEADERS_H_
#include <List.h>
#include <Message.h>
#include <String.h>
class BHttpHeader {
public:
BHttpHeader();
BHttpHeader(const char* string);
BHttpHeader(const char* name,
const char* value);
BHttpHeader(const BHttpHeader& copy);
// Header data modification
void SetName(const char* name);
void SetValue(const char* value);
bool SetHeader(const char* string);
// Header data access
const char* Name() const;
const char* Value() const;
const char* Header() const;
// Header data test
bool NameIs(const char* name) const;
// Overloaded members
BHttpHeader& operator=(const BHttpHeader& other);
private:
BString fName;
BString fValue;
mutable BString fRawHeader;
mutable bool fRawHeaderValid;
};
class BHttpHeaders {
public:
BHttpHeaders();
BHttpHeaders(const BHttpHeaders& copy);
~BHttpHeaders();
// Header list access
const char* HeaderValue(const char* name) const;
BHttpHeader& HeaderAt(int32 index) const;
// Header count
int32 CountHeaders() const;
// Header list tests
int32 HasHeader(const char* name) const;
// Header add or replacement
bool AddHeader(const char* line);
bool AddHeader(const char* name,
const char* value);
bool AddHeader(const char* name,
int32 value);
// Archiving
void PopulateFromArchive(BMessage*);
void Archive(BMessage*) const;
// Header deletion
void Clear();
// Overloaded operators
BHttpHeaders& operator=(const BHttpHeaders& other);
BHttpHeader& operator[](int32 index) const;
const char* operator[](const char* name) const;
private:
void _EraseData();
bool _AddOrDeleteHeader(BHttpHeader* header);
private:
BList fHeaderList;
};
#endif // _B_HTTP_HEADERS_H_
+240
View File
@@ -0,0 +1,240 @@
/*
* Copyright 2010-2021 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_PROTOCOL_HTTP_H_
#define _B_URL_PROTOCOL_HTTP_H_
#include <deque>
#include <Certificate.h>
#include <HttpForm.h>
#include <HttpHeaders.h>
#include <HttpResult.h>
#include <NetworkAddress.h>
#include <NetworkRequest.h>
#include <UrlProtocolRoster.h>
namespace BPrivate {
class CheckedSecureSocket;
class CheckedProxySecureSocket;
};
class BHttpRequest : public BNetworkRequest {
public:
virtual ~BHttpRequest();
void SetMethod(const char* const method);
void SetFollowLocation(bool follow);
void SetMaxRedirections(int8 maxRedirections);
void SetReferrer(const BString& referrer);
void SetUserAgent(const BString& agent);
void SetDiscardData(bool discard);
void SetDisableListener(bool disable);
void SetAutoReferrer(bool enable);
void SetUserName(const BString& name);
void SetPassword(const BString& password);
void SetRangeStart(off_t position);
void SetRangeEnd(off_t position);
void SetPostFields(const BHttpForm& fields);
void SetHeaders(const BHttpHeaders& headers);
void AdoptPostFields(BHttpForm* const fields);
void AdoptInputData(BDataIO* const data,
const ssize_t size = -1);
void AdoptHeaders(BHttpHeaders* const headers);
status_t Stop();
const BUrlResult& Result() const;
static bool IsInformationalStatusCode(int16 code);
static bool IsSuccessStatusCode(int16 code);
static bool IsRedirectionStatusCode(int16 code);
static bool IsClientErrorStatusCode(int16 code);
static bool IsServerErrorStatusCode(int16 code);
static int16 StatusCodeClass(int16 code);
private:
friend class BUrlProtocolRoster;
BHttpRequest(const BUrl& url,
bool ssl = false,
const char* protocolName = "HTTP",
BUrlProtocolListener* listener = NULL,
BUrlContext* context = NULL);
BHttpRequest(const BHttpRequest& other);
void _ResetOptions();
status_t _ProtocolLoop();
status_t _MakeRequest();
BString _SerializeRequest();
BString _SerializeHeaders();
void _SendPostData();
void _ParseStatus();
void _ParseHeaders();
// URL result parameters access
BPositionIO* _ResultRawData();
BHttpHeaders& _ResultHeaders();
void _SetResultStatusCode(int32 statusCode);
BString& _ResultStatusText();
// SSL failure management
friend class BPrivate::CheckedSecureSocket;
friend class BPrivate::CheckedProxySecureSocket;
bool _CertificateVerificationFailed(
BCertificate& certificate,
const char* message);
// Utility methods
bool _IsDefaultPort();
// Listener notification
void _NotifyDataReceived(const char* data,
off_t pos, ssize_t length,
off_t bytesReceived, ssize_t bytesTotal);
private:
bool fSSL;
BString fRequestMethod;
int8 fHttpVersion;
BHttpHeaders fHeaders;
// Request status
BHttpResult fResult;
// Request state/events
enum {
kRequestInitialState,
kRequestStatusReceived,
kRequestHeadersReceived,
kRequestContentReceived,
kRequestTrailingHeadersReceived
} fRequestStatus;
// Protocol options
uint8 fOptMaxRedirs;
BString fOptReferer;
BString fOptUserAgent;
BString fOptUsername;
BString fOptPassword;
uint32 fOptAuthMethods;
BHttpHeaders* fOptHeaders;
BHttpForm* fOptPostFields;
BDataIO* fOptInputData;
ssize_t fOptInputDataSize;
off_t fOptRangeStart;
off_t fOptRangeEnd;
bool fOptSetCookies : 1;
bool fOptFollowLocation : 1;
bool fOptDiscardData : 1;
bool fOptDisableListener : 1;
bool fOptAutoReferer : 1;
};
// Request method
const char* const B_HTTP_GET = "GET";
const char* const B_HTTP_POST = "POST";
const char* const B_HTTP_PUT = "PUT";
const char* const B_HTTP_HEAD = "HEAD";
const char* const B_HTTP_DELETE = "DELETE";
const char* const B_HTTP_OPTIONS = "OPTIONS";
const char* const B_HTTP_TRACE = "TRACE";
const char* const B_HTTP_CONNECT = "CONNECT";
// HTTP Version
enum {
B_HTTP_10 = 1,
B_HTTP_11
};
// HTTP status classes
enum http_status_code_class {
B_HTTP_STATUS_CLASS_INVALID = 000,
B_HTTP_STATUS_CLASS_INFORMATIONAL = 100,
B_HTTP_STATUS_CLASS_SUCCESS = 200,
B_HTTP_STATUS_CLASS_REDIRECTION = 300,
B_HTTP_STATUS_CLASS_CLIENT_ERROR = 400,
B_HTTP_STATUS_CLASS_SERVER_ERROR = 500
};
// Known HTTP status codes
enum http_status_code {
// Informational status codes
B_HTTP_STATUS__INFORMATIONAL_BASE = 100,
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,
B_HTTP_STATUS_CREATED,
B_HTTP_STATUS_ACCEPTED,
B_HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION,
B_HTTP_STATUS_NO_CONTENT,
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,
B_HTTP_STATUS_MOVED_PERMANENTLY,
B_HTTP_STATUS_FOUND,
B_HTTP_STATUS_SEE_OTHER,
B_HTTP_STATUS_NOT_MODIFIED,
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,
B_HTTP_STATUS_UNAUTHORIZED,
B_HTTP_STATUS_PAYMENT_REQUIRED,
B_HTTP_STATUS_FORBIDDEN,
B_HTTP_STATUS_NOT_FOUND,
B_HTTP_STATUS_METHOD_NOT_ALLOWED,
B_HTTP_STATUS_NOT_ACCEPTABLE,
B_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED,
B_HTTP_STATUS_REQUEST_TIMEOUT,
B_HTTP_STATUS_CONFLICT,
B_HTTP_STATUS_GONE,
B_HTTP_STATUS_LENGTH_REQUIRED,
B_HTTP_STATUS_PRECONDITION_FAILED,
B_HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE,
B_HTTP_STATUS_REQUEST_URI_TOO_LARGE,
B_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
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,
B_HTTP_STATUS_NOT_IMPLEMENTED,
B_HTTP_STATUS_BAD_GATEWAY,
B_HTTP_STATUS_SERVICE_UNAVAILABLE,
B_HTTP_STATUS_GATEWAY_TIMEOUT,
B_HTTP_STATUS__SERVER_ERROR_END
};
// HTTP default User-Agent
#define B_HTTP_PROTOCOL_USER_AGENT_FORMAT "ServicesKit (%s)"
#endif // _B_URL_PROTOCOL_HTTP_H_
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2017 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_HTTP_RESULT_H_
#define _B_HTTP_RESULT_H_
#include <iostream>
#include <HttpHeaders.h>
#include <String.h>
#include <Url.h>
#include <UrlResult.h>
class BUrlRequest;
class BHttpResult: public BUrlResult {
friend class BHttpRequest;
public:
BHttpResult(const BUrl& url);
BHttpResult(BMessage*);
BHttpResult(const BHttpResult& other);
~BHttpResult();
// Result parameters modifications
void SetUrl(const BUrl& url);
// Result parameters access
const BUrl& Url() const;
BString ContentType() const;
size_t Length() const;
// HTTP-Specific stuff
const BHttpHeaders& Headers() const;
const BString& StatusText() const;
int32 StatusCode() const;
// Result tests
bool HasHeaders() const;
// Overloaded members
BHttpResult& operator=(const BHttpResult& other);
virtual status_t Archive(BMessage*, bool) const;
static BArchivable* Instantiate(BMessage*);
private:
BUrl fUrl;
BHttpHeaders fHeaders;
int32 fStatusCode;
BString fStatusString;
};
#endif // _B_URL_RESULT_H_
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_HTTP_TIME_H_
#define _B_HTTP_TIME_H_
#include <ctime>
#include <DateTime.h>
#include <String.h>
namespace BPrivate {
enum {
B_HTTP_TIME_FORMAT_PARSED = -1,
B_HTTP_TIME_FORMAT_RFC1123 = 0,
B_HTTP_TIME_FORMAT_PREFERRED = B_HTTP_TIME_FORMAT_RFC1123,
B_HTTP_TIME_FORMAT_COOKIE,
B_HTTP_TIME_FORMAT_RFC1036,
B_HTTP_TIME_FORMAT_ASCTIME
};
class BHttpTime {
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;
};
}
#endif // _B_HTTP_TIME_H_
+114
View File
@@ -0,0 +1,114 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_NETWORK_COOKIE_H_
#define _B_NETWORK_COOKIE_H_
#include <Archivable.h>
#include <DateTime.h>
#include <Message.h>
#include <String.h>
#include <Url.h>
class BNetworkCookie : public BArchivable {
public:
BNetworkCookie(const char* name,
const char* value, const BUrl& url);
BNetworkCookie(const BString& cookieString,
const BUrl& url);
BNetworkCookie(BMessage* archive);
BNetworkCookie();
virtual ~BNetworkCookie();
// Parse a "SetCookie" string
status_t ParseCookieString(const BString& string,
const BUrl& url);
// Modify the cookie fields
BNetworkCookie& SetName(const BString& name);
BNetworkCookie& SetValue(const BString& value);
status_t SetDomain(const BString& domain);
status_t SetPath(const BString& path);
BNetworkCookie& SetMaxAge(int32 maxAge);
BNetworkCookie& SetExpirationDate(time_t expireDate);
BNetworkCookie& SetExpirationDate(BDateTime& expireDate);
BNetworkCookie& SetSecure(bool secure);
BNetworkCookie& SetHttpOnly(bool httpOnly);
// Access the cookie fields
const BString& Name() const;
const BString& Value() const;
const BString& Domain() const;
const BString& Path() const;
time_t ExpirationDate() const;
const BString& ExpirationString() const;
bool Secure() const;
bool HttpOnly() const;
const BString& RawCookie(bool full) const;
bool IsHostOnly() const;
bool IsSessionCookie() const;
bool IsValid() const;
bool IsValidForUrl(const BUrl& url) const;
bool IsValidForDomain(const BString& domain) const;
bool IsValidForPath(const BString& path) const;
// Test if cookie fields are defined
bool HasName() const;
bool HasValue() const;
bool HasDomain() const;
bool HasPath() const;
bool HasExpirationDate() const;
// Test if cookie could be deleted
bool ShouldDeleteAtExit() const;
bool ShouldDeleteNow() const;
// BArchivable members
virtual status_t Archive(BMessage* into,
bool deep = true) const;
static BArchivable* Instantiate(BMessage* archive);
// Overloaded operators
bool operator==(const BNetworkCookie& other);
bool operator!=(const BNetworkCookie& other);
private:
void _Reset();
int32 _ExtractNameValuePair(const BString& string,
BString& name, BString& value,
int32 index);
int32 _ExtractAttributeValuePair(
const BString& string, BString& name,
BString& value, int32 index);
BString _DefaultPathForUrl(const BUrl& url);
bool _CanBeSetFromUrl(const BUrl& url) const;
bool _CanBeSetFromDomain(const BString& path) const;
bool _CanBeSetFromPath(const BString& path) const;
private:
mutable BString fRawCookie;
mutable bool fRawCookieValid;
mutable BString fRawFullCookie;
mutable bool fRawFullCookieValid;
mutable BString fExpirationString;
mutable bool fExpirationStringValid;
BString fName;
BString fValue;
BString fDomain;
BString fPath;
BDateTime fExpiration;
status_t fInitStatus;
bool fSecure;
bool fHttpOnly;
bool fHostOnly;
bool fSessionCookie;
};
#endif // _B_NETWORK_COOKIE_H_
@@ -0,0 +1,161 @@
/*
* Copyright 2010-2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_NETWORK_COOKIE_JAR_H_
#define _B_NETWORK_COOKIE_JAR_H_
#include <pthread.h>
#include <Archivable.h>
#include <Flattenable.h>
#include <Message.h>
#include <NetworkCookie.h>
#include <ObjectList.h>
#include <String.h>
#include <Url.h>
class BNetworkCookieList: public BObjectList<const BNetworkCookie> {
public:
BNetworkCookieList();
~BNetworkCookieList();
status_t LockForReading();
status_t LockForWriting();
status_t Unlock();
private:
pthread_rwlock_t fLock;
};
class BNetworkCookieJar : public BArchivable, public BFlattenable {
public:
// Nested types
class Iterator;
class UrlIterator;
struct PrivateIterator;
struct PrivateHashMap;
public:
BNetworkCookieJar();
BNetworkCookieJar(
const BNetworkCookieJar& other);
BNetworkCookieJar(
const BNetworkCookieList& otherList);
BNetworkCookieJar(BMessage* archive);
virtual ~BNetworkCookieJar();
status_t AddCookie(const BNetworkCookie& cookie);
status_t AddCookie(const BString& cookie,
const BUrl& url);
status_t AddCookie(BNetworkCookie* cookie);
status_t AddCookies(const BNetworkCookieList& cookies);
uint32 DeleteOutdatedCookies();
uint32 PurgeForExit();
// BArchivable members
virtual status_t Archive(BMessage* into,
bool deep = true) const;
static BArchivable* Instantiate(BMessage* archive);
// BFlattenable members
virtual bool IsFixedSize() const;
virtual type_code TypeCode() const;
virtual ssize_t FlattenedSize() const;
virtual status_t Flatten(void* buffer, ssize_t size)
const;
virtual bool AllowsTypeCode(type_code code) const;
virtual status_t Unflatten(type_code code,
const void* buffer, ssize_t size);
BNetworkCookieJar& operator=(const BNetworkCookieJar& other);
// Iterators
Iterator GetIterator() const;
UrlIterator GetUrlIterator(const BUrl& url) const;
private:
void _DoFlatten() const;
private:
friend class Iterator;
friend class UrlIterator;
PrivateHashMap* fCookieHashMap;
mutable BString fFlattened;
};
class BNetworkCookieJar::Iterator {
public:
Iterator(const Iterator& other);
~Iterator();
Iterator& operator=(const Iterator& other);
bool HasNext() const;
const BNetworkCookie* Next();
const BNetworkCookie* NextDomain();
const BNetworkCookie* Remove();
void RemoveDomain();
private:
Iterator(const BNetworkCookieJar* map);
void _FindNext();
private:
friend class BNetworkCookieJar;
BNetworkCookieJar* fCookieJar;
PrivateIterator* fIterator;
BNetworkCookieList* fLastList;
BNetworkCookieList* fList;
const BNetworkCookie* fElement;
const BNetworkCookie* fLastElement;
int32 fIndex;
};
// The copy constructor and assignment operator create new iterators for the
// same cookie jar and url. Iteration will start over.
class BNetworkCookieJar::UrlIterator {
public:
UrlIterator(const UrlIterator& other);
~UrlIterator();
bool HasNext() const;
const BNetworkCookie* Next();
const BNetworkCookie* Remove();
UrlIterator& operator=(const UrlIterator& other);
private:
UrlIterator(const BNetworkCookieJar* map,
const BUrl& url);
void _Initialize();
bool _SuperDomain();
void _FindNext();
void _FindDomain();
bool _FindPath();
private:
friend class BNetworkCookieJar;
BNetworkCookieJar* fCookieJar;
PrivateIterator* fIterator;
BNetworkCookieList* fList;
BNetworkCookieList* fLastList;
const BNetworkCookie* fElement;
const BNetworkCookie* fLastElement;
int32 fIndex;
int32 fLastIndex;
BUrl fUrl;
};
#endif // _B_NETWORK_COOKIE_JAR_
@@ -0,0 +1,43 @@
/*
* Copyright 2014 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_NET_REQUEST_H_
#define _B_NET_REQUEST_H_
#include <NetBuffer.h>
#include <NetworkAddress.h>
#include <UrlRequest.h>
class BAbstractSocket;
class BNetworkRequest: public BUrlRequest
{
public:
BNetworkRequest(const BUrl& url,
BUrlProtocolListener* listener,
BUrlContext* context,
const char* threadName,
const char* protocolName);
virtual status_t Stop();
virtual void SetTimeout(bigtime_t timeout);
protected:
bool _ResolveHostName(BString host, uint16_t port);
void _ProtocolSetup();
status_t _GetLine(BString& destString);
protected:
BAbstractSocket* fSocket;
BNetworkAddress fRemoteAddr;
BNetBuffer fInputBuffer;
};
#endif
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2015 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_CONTEXT_H_
#define _B_URL_CONTEXT_H_
#include <Certificate.h>
#include <HttpAuthentication.h>
#include <NetworkCookieJar.h>
#include <Referenceable.h>
class BUrlContext: public BReferenceable {
public:
BUrlContext();
~BUrlContext();
// Context modifiers
void SetCookieJar(
const BNetworkCookieJar& cookieJar);
void AddAuthentication(const BUrl& url,
const BHttpAuthentication& authentication);
void SetProxy(BString host, uint16 port);
void AddCertificateException(const BCertificate& certificate);
// Context accessors
BNetworkCookieJar& GetCookieJar();
BHttpAuthentication& GetAuthentication(const BUrl& url);
bool UseProxy();
BString GetProxyHost();
uint16 GetProxyPort();
bool HasCertificateException(const BCertificate& certificate);
private:
class BHttpAuthenticationMap;
private:
BNetworkCookieJar fCookieJar;
BHttpAuthenticationMap* fAuthenticationMap;
typedef BObjectList<const BCertificate> BCertificateSet;
BCertificateSet fCertificates;
BString fProxyHost;
uint16 fProxyPort;
};
#endif // _B_URL_CONTEXT_H_
@@ -0,0 +1,33 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_PROTOCOL_ASYNCHRONOUS_LISTENER_H_
#define _B_URL_PROTOCOL_ASYNCHRONOUS_LISTENER_H_
#include <Handler.h>
#include <Message.h>
#include <UrlProtocolDispatchingListener.h>
class BUrlProtocolAsynchronousListener : public BHandler,
public BUrlProtocolListener {
public:
BUrlProtocolAsynchronousListener(
bool transparent = false);
virtual ~BUrlProtocolAsynchronousListener();
// Synchronous listener access
BUrlProtocolListener* SynchronousListener();
// BHandler interface
virtual void MessageReceived(BMessage* message);
private:
BUrlProtocolDispatchingListener*
fSynchronousListener;
};
#endif // _B_URL_PROTOCOL_ASYNCHRONOUS_LISTENER_H_
@@ -0,0 +1,75 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_
#define _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_
#include <Messenger.h>
#include <Message.h>
#include <UrlProtocolListener.h>
//! To be in AppTypes.h
enum {
B_URL_PROTOCOL_NOTIFICATION = '_UPN'
};
// Notification types
enum {
B_URL_PROTOCOL_CONNECTION_OPENED,
B_URL_PROTOCOL_HOSTNAME_RESOLVED,
B_URL_PROTOCOL_RESPONSE_STARTED,
B_URL_PROTOCOL_HEADERS_RECEIVED,
B_URL_PROTOCOL_DATA_RECEIVED,
B_URL_PROTOCOL_DOWNLOAD_PROGRESS,
B_URL_PROTOCOL_UPLOAD_PROGRESS,
B_URL_PROTOCOL_REQUEST_COMPLETED,
B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED,
B_URL_PROTOCOL_DEBUG_MESSAGE
};
class BUrlProtocolDispatchingListener : public BUrlProtocolListener {
public:
BUrlProtocolDispatchingListener(
BHandler* handler);
BUrlProtocolDispatchingListener(
const BMessenger& messenger);
virtual ~BUrlProtocolDispatchingListener();
virtual void ConnectionOpened(BUrlRequest* caller);
virtual void HostnameResolved(BUrlRequest* caller,
const char* ip);
virtual void ResponseStarted(BUrlRequest* caller);
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);
virtual void RequestCompleted(BUrlRequest* caller,
bool success);
virtual void DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type,
const char* text);
virtual bool CertificateVerificationFailed(
BUrlRequest* caller,
BCertificate& certificate,
const char* message);
private:
void _SendMessage(BMessage* message,
int8 notification, BUrlRequest* caller);
private:
BMessenger fMessenger;
};
#endif // _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_
@@ -0,0 +1,55 @@
/*
* Copyright 2010-2017 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_PROTOCOL_LISTENER_H_
#define _B_URL_PROTOCOL_LISTENER_H_
#include <stddef.h>
#include <cstdlib>
#include <UrlResult.h>
class BCertificate;
class BUrlRequest;
enum BUrlProtocolDebugMessage {
B_URL_PROTOCOL_DEBUG_TEXT,
B_URL_PROTOCOL_DEBUG_ERROR,
B_URL_PROTOCOL_DEBUG_HEADER_IN,
B_URL_PROTOCOL_DEBUG_HEADER_OUT,
B_URL_PROTOCOL_DEBUG_TRANSFER_IN,
B_URL_PROTOCOL_DEBUG_TRANSFER_OUT
};
class BUrlProtocolListener {
public:
virtual void ConnectionOpened(BUrlRequest* caller);
virtual void HostnameResolved(BUrlRequest* caller,
const char* ip);
virtual void ResponseStarted(BUrlRequest* caller);
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);
virtual void RequestCompleted(BUrlRequest* caller,
bool success);
virtual void DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type,
const char* text);
virtual bool CertificateVerificationFailed(
BUrlRequest* caller,
BCertificate& certificate,
const char* message);
};
#endif // _B_URL_PROTOCOL_LISTENER_H_
@@ -0,0 +1,25 @@
/*
* Copyright 2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_ROSTER_H_
#define _B_URL_ROSTER_H_
#include <stdlib.h>
class BUrl;
class BUrlContext;
class BUrlProtocolListener;
class BUrlRequest;
class BUrlProtocolRoster {
public:
static BUrlRequest* MakeRequest(const BUrl& url,
BUrlProtocolListener* listener = NULL,
BUrlContext* context = NULL);
};
#endif
+70
View File
@@ -0,0 +1,70 @@
/*
* Copyright 2010-2014 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 <UrlContext.h>
#include <UrlProtocolListener.h>
#include <UrlResult.h>
#include <OS.h>
#include <Referenceable.h>
class BUrlRequest {
public:
BUrlRequest(const BUrl& url,
BUrlProtocolListener* listener,
BUrlContext* context,
const char* threadName,
const char* protocolName);
virtual ~BUrlRequest();
// URL protocol thread management
virtual thread_id Run();
virtual status_t Pause();
virtual status_t Resume();
virtual status_t Stop();
virtual void SetTimeout(bigtime_t timeout) {}
// URL protocol parameters modification
status_t SetUrl(const BUrl& url);
status_t SetContext(BUrlContext* context);
status_t SetListener(BUrlProtocolListener* listener);
// URL protocol parameters access
const BUrl& Url() const;
BUrlContext* Context() const;
BUrlProtocolListener* Listener() const;
const BString& Protocol() const;
// URL protocol informations
bool IsRunning() const;
status_t Status() const;
virtual const BUrlResult& Result() const = 0;
protected:
static int32 _ThreadEntry(void* arg);
virtual void _ProtocolSetup() {};
virtual status_t _ProtocolLoop() = 0;
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
const char* format, ...);
protected:
BUrl fUrl;
BReference<BUrlContext> fContext;
BUrlProtocolListener* fListener;
bool fQuit;
bool fRunning;
status_t fThreadStatus;
thread_id fThreadId;
BString fThreadName;
BString fProtocol;
};
#endif // _B_URL_REQUEST_H_
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2017 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_RESULT_H_
#define _B_URL_RESULT_H_
#include <Archivable.h>
#include <String.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;
};
#endif
@@ -0,0 +1,46 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_SYNCHRONOUS_REQUEST_H_
#define _B_URL_SYNCHRONOUS_REQUEST_H_
#include <UrlRequest.h>
#include <UrlProtocolListener.h>
class BUrlSynchronousRequest : public BUrlRequest, public BUrlProtocolListener {
public:
BUrlSynchronousRequest(BUrlRequest& asynchronousRequest);
virtual ~BUrlSynchronousRequest() { };
// Synchronous wait
virtual status_t Perform();
virtual status_t WaitUntilCompletion();
// Protocol hooks
virtual void ConnectionOpened(BUrlRequest* caller);
virtual void HostnameResolved(BUrlRequest* caller,
const char* ip);
virtual void ResponseStarted(BUrlRequest* caller);
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);
virtual void RequestCompleted(BUrlRequest* caller,
bool success);
protected:
bool fRequestComplete;
BUrlRequest& fWrappedRequest;
};
#endif // _B_URL_SYNCHRONOUS_REQUEST_H_