conn.h 4.13 KB
Newer Older
1
/*****************************************************************************
2
 * conn.h: HTTP connections
3 4 5 6 7 8 9 10 11 12 13
 *****************************************************************************
 * Copyright (C) 2015 Rémi Denis-Courmont
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15 16 17 18 19 20
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

21 22 23 24 25 26 27
/**
 * \defgroup http_conn Connections
 * HTTP connections
 * \ingroup http_connmgr
 * @{
 */

28
struct vlc_tls;
29
struct vlc_http_conn;
30
struct vlc_http_msg;
31
struct vlc_http_stream;
32

33 34 35 36 37 38
struct vlc_http_conn_cbs
{
    struct vlc_http_stream *(*stream_open)(struct vlc_http_conn *,
                                           const struct vlc_http_msg *);
    void (*release)(struct vlc_http_conn *);
};
39

40 41 42 43 44
struct vlc_http_conn
{
    const struct vlc_http_conn_cbs *cbs;
    struct vlc_tls *tls;
};
45

46 47 48 49 50 51 52 53 54 55 56
static inline struct vlc_http_stream *
vlc_http_stream_open(struct vlc_http_conn *conn, const struct vlc_http_msg *m)
{
    return conn->cbs->stream_open(conn, m);
}

static inline void vlc_http_conn_release(struct vlc_http_conn *conn)
{
    conn->cbs->release(conn);
}

57 58 59
void vlc_http_err(void *, const char *msg, ...) VLC_FORMAT(2, 3);
void vlc_http_dbg(void *, const char *msg, ...) VLC_FORMAT(2, 3);

60 61 62 63
/**
 * \defgroup http1 HTTP/1.x
 * @{
 */
64 65
struct vlc_http_conn *vlc_h1_conn_create(void *ctx, struct vlc_tls *,
                                         bool proxy);
66 67
struct vlc_http_stream *vlc_chunked_open(struct vlc_http_stream *,
                                         struct vlc_tls *);
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/**
 * Sends an HTTP/1.x request through a new connection.
 *
 * This function resolves a the specified HTTP server hostname, establishes a
 * connection to specified TCP port of the server, then sends an HTTP request.
 * The connection is not protected with TLS.
 *
 * All those operations are combined in a single function call in order to
 * support TCP Fast Open. That can save one round-trip when establishing a new
 * HTTP connection.

 * \note In the case of TLS, TCP Fast Open would convey the TLS Client Hello
 * message rather than the HTTP request header. The HTTP request header can
 * however be sent with the TLS False Start. This is handled by the TLS stack
 * and does not require a combined function call.
 *
 * \param ctx opaque context pointer for the HTTP connection
 * \param hostname HTTP server or proxy hostname to connect to
 * \param port TCP port number to connect to
 * \param proxy true of the hostname and port correspond to an HTTP proxy,
 *              or false if they correspond to an HTTP origin server
 * \param req HTTP request message
 * \param idempotent whether the HTTP request is idempotent (e.g. GET),
 *                   or not (e.g. POST)
 * \param connp pointer to storage space for the established HTTP connection
 *              (or NULL if the connection is not to be reused) [OUT]
 *              can be NULL if the connection is not meant to be reused
 * \return an HTTP stream on success, NULL on error
 * \note *connp is undefined on error.
 */
struct vlc_http_stream *vlc_h1_request(void *ctx, const char *hostname,
                                       unsigned port, bool proxy,
                                       const struct vlc_http_msg *req,
                                       bool idempotent,
                                       struct vlc_http_conn **restrict connp);

105 106 107 108 109 110
/** @} */

/**
 * \defgroup h2 HTTP/2.0
 * @{
 */
111
struct vlc_http_conn *vlc_h2_conn_create(void *ctx, struct vlc_tls *);
112 113 114 115

/** @} */

/** @} */