haiku/headers/private/netservices/HttpHeaders.h
Niels Sascha Reedijk ce64ffdb90 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 <pulkomandy@gmail.com>
2021-01-27 19:53:11 +00:00

103 lines
2.1 KiB
C++

/*
* 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>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
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;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_HTTP_HEADERS_H_