libnetservices.a: Put the experimental API into BPrivate::Network namespace

In order to prevent classes between libnetapi.so with the legacy API and
applications using the libnetservices.a library, the latter will have the
classes in a distinct namespace.

In the implementation, both libbnetapi.so and libnetservices.a will use the
same header and source files. If LIBNETAPI_DEPRECATED is defined during build,
the headers and source will have binary compatible behavior. Otherwise, the
classes and other objects will be put in the HaikuExt namespace.

In order to build the libbnetapi.so and libnetservices.a with the proper
build configuration, there is a stub `src/kits/net/libnetapi_deprecated` folder
that applies the special configuration to the source files.

Currently HaikuDepot, Webpositive, libshared.a and the http_streamer add on
use the compatible API in libbnetapi.so.

Change-Id: Ic73e9f271ef75749adda46f6f72e9a0b2851b461
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3667
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Niels Sascha Reedijk
2021-01-27 19:53:11 +00:00
parent 1b133b90fd
commit ce64ffdb90
50 changed files with 405 additions and 53 deletions
+12
View File
@@ -15,6 +15,12 @@
#include <UrlRequest.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BDataRequest: public BUrlRequest {
public:
const BUrlResult& Result() const;
@@ -30,4 +36,10 @@ private:
BUrlResult fResult;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif
+11
View File
@@ -13,6 +13,12 @@
#include <UrlProtocolRoster.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BFileRequest : public BUrlRequest {
public:
virtual ~BFileRequest();
@@ -32,5 +38,10 @@ private:
BUrlResult fResult;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_FILE_REQUEST_H_
@@ -12,6 +12,12 @@
#include <UrlProtocolRoster.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BGopherRequest : public BNetworkRequest {
public:
virtual ~BGopherRequest();
@@ -45,5 +51,10 @@ private:
BUrlResult fResult;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_GOPHER_REQUEST_H_
@@ -10,6 +10,13 @@
#include <String.h>
#include <Url.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
// HTTP authentication method
enum BHttpAuthenticationMethod {
B_HTTP_AUTHENTICATION_NONE = 0,
@@ -98,4 +105,10 @@ private:
mutable BLocker fLock;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_HTTP_AUTHENTICATION_H_
+12
View File
@@ -12,6 +12,12 @@
#include <map>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
enum form_type {
B_HTTP_FORM_URL_ENCODED,
B_HTTP_FORM_MULTIPART
@@ -188,4 +194,10 @@ private:
BHttpFormData* fPrevElement;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_HTTP_FORM_H_
+12
View File
@@ -11,6 +11,12 @@
#include <String.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BHttpHeader {
public:
BHttpHeader();
@@ -87,4 +93,10 @@ private:
BList fHeaderList;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_HTTP_HEADERS_H_
+12
View File
@@ -23,6 +23,12 @@ namespace BPrivate {
};
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BHttpRequest : public BNetworkRequest {
public:
virtual ~BHttpRequest();
@@ -237,4 +243,10 @@ 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_
+11
View File
@@ -14,6 +14,12 @@
#include <UrlResult.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlRequest;
@@ -55,5 +61,10 @@ private:
BString fStatusString;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_RESULT_H_
+9 -1
View File
@@ -12,6 +12,10 @@
namespace BPrivate {
#ifndef LIBNETAPI_DEPRECATED
namespace Network {
#endif
enum {
B_HTTP_TIME_FORMAT_PARSED = -1,
B_HTTP_TIME_FORMAT_RFC1123 = 0,
@@ -43,5 +47,9 @@ private:
int8 fDateFormat;
};
}
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
#endif
} // namespace BPrivate
#endif // _B_HTTP_TIME_H_
@@ -13,6 +13,12 @@
#include <Url.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BNetworkCookie : public BArchivable {
public:
BNetworkCookie(const char* name,
@@ -110,5 +116,11 @@ private:
bool fSessionCookie;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_NETWORK_COOKIE_H_
@@ -16,6 +16,12 @@
#include <Url.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BNetworkCookieList: public BObjectList<const BNetworkCookie> {
public:
BNetworkCookieList();
@@ -158,4 +164,10 @@ private:
BUrl fUrl;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_NETWORK_COOKIE_JAR_
@@ -14,6 +14,12 @@
class BAbstractSocket;
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BNetworkRequest: public BUrlRequest
{
public:
@@ -39,5 +45,10 @@ protected:
BNetBuffer fInputBuffer;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif
+13
View File
@@ -14,6 +14,12 @@
#include <Referenceable.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlContext: public BReferenceable {
public:
BUrlContext();
@@ -49,4 +55,11 @@ private:
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_CONTEXT_H_
@@ -10,6 +10,11 @@
#include <Message.h>
#include <UrlProtocolDispatchingListener.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlProtocolAsynchronousListener : public BHandler,
public BUrlProtocolListener {
@@ -28,6 +33,12 @@ private:
BUrlProtocolDispatchingListener*
fSynchronousListener;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_PROTOCOL_ASYNCHRONOUS_LISTENER_H_
@@ -10,6 +10,11 @@
#include <Message.h>
#include <UrlProtocolListener.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
//! To be in AppTypes.h
enum {
@@ -71,5 +76,11 @@ private:
BMessenger fMessenger;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_PROTOCOL_DISPATCHING_LISTENER_H_
@@ -13,6 +13,13 @@
class BCertificate;
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlRequest;
@@ -52,4 +59,10 @@ public:
const char* message);
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_PROTOCOL_LISTENER_H_
@@ -11,6 +11,13 @@
class BUrl;
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlContext;
class BUrlProtocolListener;
class BUrlRequest;
@@ -22,4 +29,10 @@ public:
BUrlContext* context = NULL);
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif
+11
View File
@@ -14,6 +14,12 @@
#include <Referenceable.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlRequest {
public:
BUrlRequest(const BUrl& url,
@@ -66,5 +72,10 @@ protected:
BString fProtocol;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_REQUEST_H_
+12
View File
@@ -10,6 +10,12 @@
#include <String.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlResult: public BArchivable {
public:
BUrlResult();
@@ -31,4 +37,10 @@ private:
size_t fLength;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif
@@ -10,6 +10,12 @@
#include <UrlProtocolListener.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
class BUrlSynchronousRequest : public BUrlRequest, public BUrlProtocolListener {
public:
BUrlSynchronousRequest(BUrlRequest& asynchronousRequest);
@@ -43,4 +49,10 @@ protected:
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_URL_SYNCHRONOUS_REQUEST_H_
@@ -3,6 +3,9 @@ SubDir HAIKU_TOP src add-ons media plugins http_streamer ;
UsePrivateHeaders media netservices shared ;
UsePrivateHeaders [ FDirName media experimental ] ;
# Use the deprecated libnetapi.so classes
SubDirC++Flags [ FDefines LIBNETAPI_DEPRECATED ] ;
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
+3
View File
@@ -229,6 +229,9 @@ local generatedReferenceParserSourceFiles =
DumpExportReferenceJsonListener.cpp
;
# Use the deprecated libnetapi.so network classes
SubDirC++Flags [ FDefines LIBNETAPI_DEPRECATED ] ;
Application HaikuDepot
:
$(applicationSources)
+3
View File
@@ -3,6 +3,9 @@ SubDir HAIKU_TOP src apps webpositive ;
SubDirC++Flags $(defines) -Wno-error=sequence-point -Wno-error=format-truncation ;
SubDirCcFlags $(defines) -Wno-error=sequence-point -Wno-error=format-truncation ;
# Use the deprecated libnetapi.so classes
SubDirC++Flags [ FDefines LIBNETAPI_DEPRECATED ] ;
# source directories
local sourceDirs =
autocompletion
+1
View File
@@ -1,4 +1,5 @@
SubDir HAIKU_TOP src kits network ;
SubInclude HAIKU_TOP src kits network libnetapi ;
SubInclude HAIKU_TOP src kits network libnetapi_deprecated ;
SubInclude HAIKU_TOP src kits network libnetservices ;
@@ -0,0 +1,3 @@
SubDir HAIKU_TOP src kits network libnetapi_deprecated ;
include [ FDirName $(HAIKU_TOP) src kits network libnetservices JamCommon ] ;
@@ -15,6 +15,11 @@
#include <stdio.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
BDataRequest::BDataRequest(const BUrl& url, BUrlProtocolListener* listener,
BUrlContext* context)
: BUrlRequest(url, listener, context, "data URL parser", "data"),
@@ -17,6 +17,10 @@
#include <Path.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
BFileRequest::BFileRequest(const BUrl& url, BUrlProtocolListener* listener,
BUrlContext* context)
:
@@ -23,6 +23,11 @@
#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/
* TODO: add proper favicon
@@ -15,6 +15,11 @@
#include <AutoLocker.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
#if DEBUG > 0
#define PRINT(x) printf x
#else
@@ -23,6 +23,9 @@ static int32 kBoundaryRandomSize = 16;
using namespace std;
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
// #pragma mark - BHttpFormData
@@ -15,6 +15,10 @@
#include <HttpHeaders.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
// #pragma mark -- BHttpHeader
@@ -34,6 +34,11 @@
static const int32 kHttpBufferSize = 4096;
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
namespace BPrivate {
class CheckedSecureSocket: public BSecureSocket
@@ -15,6 +15,10 @@
using std::ostream;
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
BHttpResult::BHttpResult(const BUrl& url)
:
@@ -47,7 +47,11 @@ 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()
+61
View File
@@ -0,0 +1,61 @@
# This module is built as an independent static library, and as a (deprecated)
# part of libnetapi.so. In the latter case LIBNETAPI_DEPRECATED will be defined
# to ensure binary compatibility.
UsePrivateHeaders net netservices shared support ;
local sources =
# FUTURE: The HTTP stuff should all go into an add-on. It needs
# linking against libcrypto.so and only the add-on should link
# against it.
DataRequest.cpp
HttpAuthentication.cpp
HttpHeaders.cpp
HttpForm.cpp
HttpRequest.cpp
HttpResult.cpp
# FUTURE: another add-on for file:// (a much simpler one)
FileRequest.cpp
# FUTURE: another add-on for gopher://
GopherRequest.cpp
HttpTime.cpp
NetworkCookie.cpp
NetworkCookieJar.cpp
NetworkRequest.cpp
UrlContext.cpp
UrlProtocolAsynchronousListener.cpp
UrlProtocolDispatchingListener.cpp
UrlProtocolListener.cpp
UrlProtocolRoster.cpp
UrlRequest.cpp
UrlResult.cpp
UrlSynchronousRequest.cpp
;
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
local architecture = $(TARGET_PACKAGING_ARCH) ;
if $(SUBDIR:B) = libnetapi_deprecated {
SubDirC++Flags [ FDefines LIBNETAPI_DEPRECATED ] ;
UseHeaders [ FDirName $(HAIKU_TOP) src kits network libnetservices ] : false ;
MergeObject <libnetapi!$(architecture)>netservices.o :
$(sources)
: <$(architecture)>libshared.a
;
} else {
StaticLibrary [ MultiArchDefaultGristFiles libnetservices.a ] :
$(sources)
;
}
SEARCH on [ FGristFiles $(sources) ]
= [ FDirName $(HAIKU_TOP) src kits network libnetservices ] ;
}
}
+1 -49
View File
@@ -1,51 +1,3 @@
SubDir HAIKU_TOP src kits network libnetservices ;
UsePrivateHeaders net netservices shared support ;
local sources =
# FUTURE: The HTTP stuff should all go into an add-on. It needs
# linking against libcrypto.so and only the add-on should link
# against it.
DataRequest.cpp
HttpAuthentication.cpp
HttpHeaders.cpp
HttpForm.cpp
HttpRequest.cpp
HttpResult.cpp
# FUTURE: another add-on for file:// (a much simpler one)
FileRequest.cpp
# FUTURE: another add-on for gopher://
GopherRequest.cpp
HttpTime.cpp
NetworkCookie.cpp
NetworkCookieJar.cpp
NetworkRequest.cpp
UrlContext.cpp
UrlProtocolAsynchronousListener.cpp
UrlProtocolDispatchingListener.cpp
UrlProtocolListener.cpp
UrlProtocolRoster.cpp
UrlRequest.cpp
UrlResult.cpp
UrlSynchronousRequest.cpp
;
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
local architecture = $(TARGET_PACKAGING_ARCH) ;
MergeObject <libnetapi!$(architecture)>netservices.o :
$(sources)
: <$(architecture)>libshared.a
;
StaticLibrary <$(architecture)>libnetservices.a :
$(sources)
;
}
}
include [ FDirName $(HAIKU_TOP) src kits network libnetservices JamCommon ] ;
@@ -20,9 +20,12 @@
#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";
@@ -380,7 +383,7 @@ BNetworkCookie::ExpirationString() const
BHttpTime date(fExpiration);
if (!fExpirationStringValid) {
fExpirationString = date.ToString(BPrivate::B_HTTP_TIME_FORMAT_COOKIE);
fExpirationString = date.ToString(B_HTTP_TIME_FORMAT_COOKIE);
fExpirationStringValid = true;
}
@@ -19,6 +19,10 @@
#include "NetworkCookieJarPrivate.h"
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
// #define TRACE_COOKIE
#ifdef TRACE_COOKIE
# define TRACE(x...) printf(x)
@@ -9,6 +9,13 @@
#include <HashMap.h>
#ifndef LIBNETAPI_DEPRECATED
using BPrivate::Network::BNetworkCookie;
using BPrivate::Network::BNetworkCookieJar;
using BPrivate::Network::BNetworkCookieList;
#endif
typedef BPrivate::SynchronizedHashMap<HashString, BNetworkCookieList*>
BNetworkCookieHashMap;
@@ -14,6 +14,10 @@
#include <AbstractSocket.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
BNetworkRequest::BNetworkRequest(const BUrl& url, BUrlProtocolListener* listener,
BUrlContext* context, const char* threadName, const char* protocolName)
:
@@ -16,6 +16,10 @@
#include <HashString.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
class BUrlContext::BHttpAuthenticationMap : public
SynchronizedHashMap<BPrivate::HashString, BHttpAuthentication*> {};
@@ -19,6 +19,11 @@
#include <UrlResult.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
extern const char* kUrlProtocolMessageType;
extern const char* kUrlProtocolCaller;
@@ -16,6 +16,10 @@
#include <assert.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
const char* kUrlProtocolMessageType = "be:urlProtocolMessageType";
const char* kUrlProtocolCaller = "be:urlProtocolCaller";
@@ -15,6 +15,9 @@
using namespace std;
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
void
BUrlProtocolListener::ConnectionOpened(BUrlRequest*)
@@ -18,6 +18,9 @@
#include <HttpRequest.h>
#include <UrlRequest.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
/* static */ BUrlRequest*
BUrlProtocolRoster::MakeRequest(const BUrl& url,
@@ -12,6 +12,10 @@
#include <stdio.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
static BReference<BUrlContext> gDefaultContext = new(std::nothrow) BUrlContext();
@@ -10,6 +10,10 @@
#include <UrlResult.h>
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
BUrlResult::BUrlResult()
:
BArchivable(),
@@ -12,6 +12,9 @@
#define PRINT(x) printf x;
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
BUrlSynchronousRequest::BUrlSynchronousRequest(BUrlRequest& request)
:
+3
View File
@@ -13,6 +13,9 @@ UsePrivateHeaders
;
UsePrivateSystemHeaders ;
# Use the deprecated libnetapi.so classes
SubDirC++Flags [ FDefines LIBNETAPI_DEPRECATED ] ;
HPKG_SOURCES =
AttributeDataReader.cpp
BlockBufferPool.cpp
+3
View File
@@ -9,6 +9,9 @@ if [ Glob $(SUBDIR) : DefaultGeolocationServiceKey.h ] {
SubDirC++Flags [ FDefines HAVE_DEFAULT_GEOLOCATION_SERVICE_KEY ] ;
}
# Use the deprecated libnetapi.so classes
SubDirC++Flags [ FDefines LIBNETAPI_DEPRECATED ] ;
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {