OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
12 #ifndef NETWORK_CORE_TCP_HTTP_H
13 #define NETWORK_CORE_TCP_HTTP_H
31 virtual void OnReceiveData(
const char *data,
size_t length) = 0;
58 return this->sock != INVALID_SOCKET;
64 const char *host,
const char *url,
const char *
data,
int depth);
69 const char *
data =
nullptr,
int depth = 0);
92 const char *
data =
nullptr,
int depth = 0) :
117 this->data =
nullptr;
bool IsConnected() const
Whether this socket is currently bound to a socket.
Base socket handler for HTTP traffic.
HTTPCallback * callback
The callback to call for the incoming data.
Callback for when the HTTP handler has something to tell us.
"Helper" class for creating TCP connections in a non-blocking manner
SocketHandler for all network sockets in OpenTTD.
const char * data
The (POST) data we might want to forward (to a redirect).
virtual void OnReceiveData(const char *data, size_t length)=0
We're receiving data.
const char * url
The URL we want to get at the server.
NetworkHTTPContentConnecter(const NetworkAddress &address, HTTPCallback *callback, const char *url, const char *data=nullptr, int depth=0)
Start the connecting.
const char * data
The data to send.
~NetworkHTTPSocketHandler()
Free whatever needs to be freed.
Connect with a HTTP server and do ONE query.
HTTPCallback * callback
Callback to tell that we received some data (or won't).
int redirect_depth
The depth of the redirection.
int recv_pos
Current position in buffer.
char recv_buffer[4096]
Partially received message.
const char * GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
void OnConnect(SOCKET s) override
Callback when the connection succeeded.
virtual void OnFailure()=0
An error has occurred and the connection has been closed.
NetworkAddress address
Address we're connecting to.
NetworkRecvStatus CloseConnection(bool error=true) override
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
static int Connect(char *uri, HTTPCallback *callback, const char *data=nullptr, int depth=0)
Connect to the given URI.
int Receive()
Handle receiving of HTTP data.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
virtual ~HTTPCallback()
Silentium.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
NetworkHTTPSocketHandler(SOCKET sock, HTTPCallback *callback, const char *host, const char *url, const char *data, int depth)
Start the querying.
static void HTTPReceive()
Do the receiving for all HTTP connections.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
int depth
How far we have recursed.
~NetworkHTTPContentConnecter()
Free all our allocated data.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
int recv_length
Length of the data still retrieving.
void OnFailure() override
Callback for when the connection attempt failed.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
SOCKET sock
The socket currently connected to.
int HandleHeader()
Handle the header of a HTTP reply.