ossl-nghttp3.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_NGHTTP3_H
  10. # define OSSL_NGHTTP3_H
  11. # include <openssl/bio.h>
  12. # include <openssl/ssl.h>
  13. # include <nghttp3/nghttp3.h>
  14. /*
  15. * ossl-nghttp3: Demo binding of nghttp3 to OpenSSL QUIC
  16. * =====================================================
  17. *
  18. * This is a simple library which provides an example binding of the nghttp3
  19. * HTTP/3 library to OpenSSL's QUIC API.
  20. */
  21. /* Represents an HTTP/3 connection to a server. */
  22. typedef struct ossl_demo_h3_conn_st OSSL_DEMO_H3_CONN;
  23. /* Represents an HTTP/3 request, control or QPACK stream. */
  24. typedef struct ossl_demo_h3_stream_st OSSL_DEMO_H3_STREAM;
  25. /*
  26. * Creates a HTTP/3 connection using the given QUIC client connection BIO. The
  27. * BIO must be able to provide an SSL object pointer using BIO_get_ssl. Takes
  28. * ownership of the reference. If the QUIC connection SSL object has not already
  29. * been connected, HTTP/3 ALPN is set automatically. If it has already been
  30. * connected, HTTP/3 ALPN ("h3") must have been configured and no streams must
  31. * have been created yet.
  32. *
  33. * If settings is NULL, use default settings only. Settings unsupported by
  34. * this QUIC binding are ignored.
  35. *
  36. * user_data is an application-provided opaque value which can be retrieved
  37. * using OSSL_DEMO_H3_CONN_get_user_data. Note that the user data value passed
  38. * to the callback functions specified in callbacks is a pointer to the
  39. * OSSL_DEMO_H3_CONN, not user_data.
  40. *
  41. * Returns NULL on failure.
  42. */
  43. OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_conn(BIO *qconn_bio,
  44. const nghttp3_callbacks *callbacks,
  45. const nghttp3_settings *settings,
  46. void *user_data);
  47. /*
  48. * Works identically to OSSL_DEMO_H3_CONN_new_for_conn except that it manages
  49. * the creation of a QUIC connection SSL object automatically using an address
  50. * string. addr should be a string such as "www.example.com:443". The created
  51. * underlying QUIC connection SSL object is owned by the OSSL_DEMO_H3_CONN and
  52. * can be subsequently retrieved using OSSL_DEMO_H3_CONN_get0_connection.
  53. *
  54. * Returns NULL on failure. ctx must be a SSL_CTX using a QUIC client
  55. * SSL_METHOD.
  56. */
  57. OSSL_DEMO_H3_CONN *OSSL_DEMO_H3_CONN_new_for_addr(SSL_CTX *ctx,
  58. const char *addr,
  59. const nghttp3_callbacks *callbacks,
  60. const nghttp3_settings *settings,
  61. void *user_data);
  62. /* Equivalent to SSL_connect(OSSL_DEMO_H3_CONN_get0_connection(conn)). */
  63. int OSSL_DEMO_H3_CONN_connect(OSSL_DEMO_H3_CONN *conn);
  64. /*
  65. * Free the OSSL_DEMO_H3_CONN and any underlying QUIC connection SSL object and
  66. * associated streams.
  67. */
  68. void OSSL_DEMO_H3_CONN_free(OSSL_DEMO_H3_CONN *conn);
  69. /*
  70. * Returns the user data value which was specified in
  71. * OSSL_DEMO_H3_CONN_new_for_conn.
  72. */
  73. void *OSSL_DEMO_H3_CONN_get_user_data(const OSSL_DEMO_H3_CONN *conn);
  74. /* Returns the underlying QUIC connection SSL object. */
  75. SSL *OSSL_DEMO_H3_CONN_get0_connection(const OSSL_DEMO_H3_CONN *conn);
  76. /*
  77. * Handle any pending events on a given HTTP/3 connection. Returns 0 on error.
  78. */
  79. int OSSL_DEMO_H3_CONN_handle_events(OSSL_DEMO_H3_CONN *conn);
  80. /*
  81. * Submits a new HTTP/3 request on the given connection. Returns 0 on error.
  82. *
  83. * This works analogously to nghttp3_conn_submit_request(). The stream user data
  84. * pointer passed to the callbacks is a OSSL_DEMO_H3_STREAM object pointer; to
  85. * retrieve the stream user data pointer passed to this function, use
  86. * OSSL_DEMO_H3_STREAM_get_user_data.
  87. */
  88. int OSSL_DEMO_H3_CONN_submit_request(OSSL_DEMO_H3_CONN *conn,
  89. const nghttp3_nv *hdr, size_t hdrlen,
  90. const nghttp3_data_reader *dr,
  91. void *stream_user_data);
  92. /*
  93. * Returns the user data value which was specified in
  94. * OSSL_DEMO_H3_CONN_submit_request.
  95. */
  96. void *OSSL_DEMO_H3_STREAM_get_user_data(const OSSL_DEMO_H3_STREAM *stream);
  97. #endif