http-client.c revision 30d917bcd48d70af0371baf27571cc198d621a62
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "net.h"
#include "str.h"
#include "hash.h"
#include "array.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "connection.h"
#include "dns-lookup.h"
#include "iostream-rawlog.h"
#include "iostream-ssl.h"
#include "http-url.h"
#include "http-client-private.h"
#define HTTP_DEFAULT_PORT 80
#define HTTPS_DEFAULT_PORT 443
/* FIXME: This implementation not yet finished. The essence works: it is
possible to submit requests through the client. Responses are dumped to
stdout
Structure so far:
Client - Acts much like a browser; it is not dedicated to a single host.
Client can accept requests to different hosts, which can be served
at different IPs. Redirects can be handled in the background by
making a new connection. Connections to new hosts are created once
needed for servicing a request.
Requests - Semantics are similar to imapc commands. Create a request,
optionally modify some aspects of it and finally submit it.
Hosts - We maintain a 'cache' of hosts for which we have looked up IPs.
Requests are first queued in the host struct on a per-port basis.
Connections - Actual connections to a server. Once a connection is ready to
handle requests, it claims a request from a host object. One
connection hand service multiple hosts and one host can have
multiple associated connections, possibly to different ips and
ports.
TODO: lots of cleanup, authentication, ssl, timeouts, rawlog etc.
*/
/*
* Logging
*/
static inline void
static inline void
const char *format, ...)
{
}
/*
* Client
*/
{
struct http_client *client;
}
return client;
}
{
struct http_client_host *host;
struct http_client_peer *peer;
/* free peers */
}
/* free hosts */
}
}
{
/* move connections */
/* FIXME: we wouldn't necessarily need to switch all of them
immediately, only those that have requests now. but also connections
that get new requests before ioloop is switched again.. */
struct http_client_connection *conn =
(struct http_client_connection *)_conn;
}
/* move dns lookups */
struct http_client_host *host;
}
}
{
if (client->pending_requests == 0)
return;
/* either we're waiting for network I/O or we're getting out of a
callback using timeout_add_short(0) */
do {
} while (client->pending_requests > 0);
}