xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/http2/adapter/nghttp2_callbacks.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 #ifndef QUICHE_HTTP2_ADAPTER_NGHTTP2_CALLBACKS_H_
2 #define QUICHE_HTTP2_ADAPTER_NGHTTP2_CALLBACKS_H_
3 
4 #include <cstdint>
5 
6 #include "quiche/http2/adapter/http2_protocol.h"
7 #include "quiche/http2/adapter/nghttp2.h"
8 #include "quiche/http2/adapter/nghttp2_util.h"
9 
10 namespace http2 {
11 namespace adapter {
12 namespace callbacks {
13 
14 // The following functions are nghttp2 callbacks that Nghttp2Adapter sets at the
15 // beginning of its lifetime. It is expected that |user_data| holds an
16 // Http2VisitorInterface.
17 
18 // Callback once the library is ready to send serialized frames.
19 ssize_t OnReadyToSend(nghttp2_session* session, const uint8_t* data,
20                       size_t length, int flags, void* user_data);
21 
22 // Callback once a frame header has been received.
23 int OnBeginFrame(nghttp2_session* session, const nghttp2_frame_hd* header,
24                  void* user_data);
25 
26 // Callback once a complete frame has been received.
27 int OnFrameReceived(nghttp2_session* session, const nghttp2_frame* frame,
28                     void* user_data);
29 
30 // Callback at the start of a frame carrying headers.
31 int OnBeginHeaders(nghttp2_session* session, const nghttp2_frame* frame,
32                    void* user_data);
33 
34 // Callback once a name-value header has been received.
35 int OnHeader(nghttp2_session* session, const nghttp2_frame* frame,
36              nghttp2_rcbuf* name, nghttp2_rcbuf* value, uint8_t flags,
37              void* user_data);
38 
39 // Invoked immediately before sending a frame.
40 int OnBeforeFrameSent(nghttp2_session* session, const nghttp2_frame* frame,
41                       void* user_data);
42 
43 // Invoked immediately after a frame is sent.
44 int OnFrameSent(nghttp2_session* session, const nghttp2_frame* frame,
45                 void* user_data);
46 
47 // Invoked when a non-DATA frame is not sent because of an error.
48 int OnFrameNotSent(nghttp2_session* session, const nghttp2_frame* frame,
49                    int lib_error_code, void* user_data);
50 
51 // Invoked when an invalid frame is received.
52 int OnInvalidFrameReceived(nghttp2_session* session, const nghttp2_frame* frame,
53                            int lib_error_code, void* user_data);
54 
55 // Invoked when a chunk of data (from a DATA frame payload) has been received.
56 int OnDataChunk(nghttp2_session* session, uint8_t flags,
57                 Http2StreamId stream_id, const uint8_t* data, size_t len,
58                 void* user_data);
59 
60 // Callback once a stream has been closed.
61 int OnStreamClosed(nghttp2_session* session, Http2StreamId stream_id,
62                    uint32_t error_code, void* user_data);
63 
64 // Invoked when nghttp2 has a chunk of extension frame data to pass to the
65 // application.
66 int OnExtensionChunkReceived(nghttp2_session* session,
67                              const nghttp2_frame_hd* hd, const uint8_t* data,
68                              size_t len, void* user_data);
69 
70 // Invoked when nghttp2 wants the application to unpack an extension payload.
71 int OnUnpackExtensionCallback(nghttp2_session* session, void** payload,
72                               const nghttp2_frame_hd* hd, void* user_data);
73 
74 // Invoked when nghttp2 is ready to pack an extension payload. Returns the
75 // number of bytes serialized to |buf|.
76 ssize_t OnPackExtensionCallback(nghttp2_session* session, uint8_t* buf,
77                                 size_t len, const nghttp2_frame* frame,
78                                 void* user_data);
79 
80 // Invoked when the library has an error message to deliver.
81 int OnError(nghttp2_session* session, int lib_error_code, const char* msg,
82             size_t len, void* user_data);
83 
84 nghttp2_session_callbacks_unique_ptr Create();
85 
86 }  // namespace callbacks
87 }  // namespace adapter
88 }  // namespace http2
89 
90 #endif  // QUICHE_HTTP2_ADAPTER_NGHTTP2_CALLBACKS_H_
91