Path: blob/main/crypto/openssl/demos/http3/ossl-nghttp3.h
39507 views
/*1* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/8#ifndef OSSL_NGHTTP3_H9# define OSSL_NGHTTP3_H1011# include <openssl/bio.h>12# include <openssl/ssl.h>13# include <nghttp3/nghttp3.h>1415/*16* ossl-nghttp3: Demo binding of nghttp3 to OpenSSL QUIC17* =====================================================18*19* This is a simple library which provides an example binding of the nghttp320* HTTP/3 library to OpenSSL's QUIC API.21*/2223/* Represents an HTTP/3 connection to a server. */24typedef struct ossl_demo_h3_conn_st OSSL_DEMO_H3_CONN;2526/* Represents an HTTP/3 request, control or QPACK stream. */27typedef struct ossl_demo_h3_stream_st OSSL_DEMO_H3_STREAM;2829/*30* Creates a HTTP/3 connection using the given QUIC client connection BIO. The31* BIO must be able to provide an SSL object pointer using BIO_get_ssl. Takes32* ownership of the reference. If the QUIC connection SSL object has not already33* been connected, HTTP/3 ALPN is set automatically. If it has already been34* connected, HTTP/3 ALPN ("h3") must have been configured and no streams must35* have been created yet.36*37* If settings is NULL, use default settings only. Settings unsupported by38* this QUIC binding are ignored.39*40* user_data is an application-provided opaque value which can be retrieved41* using OSSL_DEMO_H3_CONN_get_user_data. Note that the user data value passed42* to the callback functions specified in callbacks is a pointer to the43* OSSL_DEMO_H3_CONN, not user_data.44*45* Returns NULL on failure.46*/47OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_conn(BIO *qconn_bio,48const nghttp3_callbacks *callbacks,49const nghttp3_settings *settings,50void *user_data);5152/*53* Works identically to OSSL_DEMO_H3_CONN_new_for_conn except that it manages54* the creation of a QUIC connection SSL object automatically using an address55* string. addr should be a string such as "www.example.com:443". The created56* underlying QUIC connection SSL object is owned by the OSSL_DEMO_H3_CONN and57* can be subsequently retrieved using OSSL_DEMO_H3_CONN_get0_connection.58*59* Returns NULL on failure. ctx must be an SSL_CTX using a QUIC client60* SSL_METHOD.61*/62OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_addr(SSL_CTX *ctx,63const char *addr,64const nghttp3_callbacks *callbacks,65const nghttp3_settings *settings,66void *user_data);6768/* Equivalent to SSL_connect(OSSL_DEMO_H3_CONN_get0_connection(conn)). */69int OSSL_DEMO_H3_CONN_connect(OSSL_DEMO_H3_CONN *conn);7071/*72* Free the OSSL_DEMO_H3_CONN and any underlying QUIC connection SSL object and73* associated streams.74*/75void OSSL_DEMO_H3_CONN_free(OSSL_DEMO_H3_CONN *conn);7677/*78* Returns the user data value which was specified in79* OSSL_DEMO_H3_CONN_new_for_conn.80*/81void *OSSL_DEMO_H3_CONN_get_user_data(const OSSL_DEMO_H3_CONN *conn);8283/* Returns the underlying QUIC connection SSL object. */84SSL *OSSL_DEMO_H3_CONN_get0_connection(const OSSL_DEMO_H3_CONN *conn);8586/*87* Handle any pending events on a given HTTP/3 connection. Returns 0 on error.88*/89int OSSL_DEMO_H3_CONN_handle_events(OSSL_DEMO_H3_CONN *conn);9091/*92* Submits a new HTTP/3 request on the given connection. Returns 0 on error.93*94* This works analogously to nghttp3_conn_submit_request(). The stream user data95* pointer passed to the callbacks is a OSSL_DEMO_H3_STREAM object pointer; to96* retrieve the stream user data pointer passed to this function, use97* OSSL_DEMO_H3_STREAM_get_user_data.98*/99int OSSL_DEMO_H3_CONN_submit_request(OSSL_DEMO_H3_CONN *conn,100const nghttp3_nv *hdr, size_t hdrlen,101const nghttp3_data_reader *dr,102void *stream_user_data);103104/*105* Returns the user data value which was specified in106* OSSL_DEMO_H3_CONN_submit_request.107*/108void *OSSL_DEMO_H3_STREAM_get_user_data(const OSSL_DEMO_H3_STREAM *stream);109110#endif111112113