blob: a15e4c723672c60887785061394d11bf9cdc89a3 [file] [log] [blame]
Willy Tarreau62f52692017-10-08 23:01:42 +02001/*
2 * HTTP/2 mux-demux for connections
3 *
4 * Copyright 2017 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <common/cfgparse.h>
14#include <common/config.h>
15#include <proto/connection.h>
16#include <proto/stream.h>
17
18
19/*****************************************************************/
20/* functions below are dedicated to the mux setup and management */
21/*****************************************************************/
22
23/* Initialize the mux once it's attached. For outgoing connections, the context
24 * is already initialized before installing the mux, so we detect incoming
25 * connections from the fact that the context is still NULL. Returns < 0 on
26 * error.
27 */
28static int h2_init(struct connection *conn)
29{
30 if (conn->mux_ctx) {
31 /* we don't support outgoing connections for now */
32 return -1;
33 }
34
35 /* not implemented yet */
36 return -1;
37}
38
39/* release function for a connection. This one should be called to free all
40 * resources allocated to the mux.
41 */
42static void h2_release(struct connection *conn)
43{
44}
45
46
47/*********************************************************/
48/* functions below are I/O callbacks from the connection */
49/*********************************************************/
50
51/* callback called on recv event by the connection handler */
52static void h2_recv(struct connection *conn)
53{
54}
55
56/* callback called on send event by the connection handler */
57static void h2_send(struct connection *conn)
58{
59}
60
61/* callback called on any event by the connection handler.
62 * It applies changes and returns zero, or < 0 if it wants immediate
63 * destruction of the connection (which normally doesn not happen in h2).
64 */
65static int h2_wake(struct connection *conn)
66{
67 return 0;
68}
69
70/*******************************************/
71/* functions below are used by the streams */
72/*******************************************/
73
74/*
75 * Attach a new stream to a connection
76 * (Used for outgoing connections)
77 */
78static struct conn_stream *h2_attach(struct connection *conn)
79{
80 return NULL;
81}
82
83/* callback used to update the mux's polling flags after changing a cs' status.
84 * The caller (cs_update_mux_polling) will take care of propagating any changes
85 * to the transport layer.
86 */
87static void h2_update_poll(struct conn_stream *cs)
88{
89}
90
91/*
92 * Detach the stream from the connection and possibly release the connection.
93 */
94static void h2_detach(struct conn_stream *cs)
95{
96}
97
98static void h2_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
99{
100}
101
102static void h2_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
103{
104}
105
106/*
107 * Called from the upper layer, to get more data
108 */
109static int h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, int count)
110{
111 /* FIXME: not handled for now */
112 cs->flags |= CS_FL_ERROR;
113 return 0;
114}
115
116/* Called from the upper layer, to send data */
117static int h2_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags)
118{
119 /* FIXME: not handled for now */
120 cs->flags |= CS_FL_ERROR;
121 return 0;
122}
123
124
125/*******************************************************/
126/* functions below are dedicated to the config parsers */
127/*******************************************************/
128
129
130
131/****************************************/
132/* MUX initialization and instanciation */
133/***************************************/
134
135/* The mux operations */
136const struct mux_ops h2_ops = {
137 .init = h2_init,
138 .recv = h2_recv,
139 .send = h2_send,
140 .wake = h2_wake,
141 .update_poll = h2_update_poll,
142 .rcv_buf = h2_rcv_buf,
143 .snd_buf = h2_snd_buf,
144 .attach = h2_attach,
145 .detach = h2_detach,
146 .shutr = h2_shutr,
147 .shutw = h2_shutw,
148 .release = h2_release,
149 .name = "H2",
150};
151
152/* ALPN selection : this mux registers ALPN tolen "h2" */
153static struct alpn_mux_list alpn_mux_h2 =
154 { .token = IST("h2"), .mode = ALPN_MODE_HTTP, .mux = &h2_ops };
155
156/* config keyword parsers */
157static struct cfg_kw_list cfg_kws = {ILH, {
158 { 0, NULL, NULL }
159}};
160
161__attribute__((constructor))
162static void __h2_init(void)
163{
164 alpn_register_mux(&alpn_mux_h2);
165 cfg_register_keywords(&cfg_kws);
166}