11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * nghttp2 - HTTP/2 C Library
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Copyright (c) 2012 Tatsuhiro Tsujikawa
51cb0ef41Sopenharmony_ci *
61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
71cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the
81cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
91cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
101cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
111cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
121cb0ef41Sopenharmony_ci * the following conditions:
131cb0ef41Sopenharmony_ci *
141cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be
151cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software.
161cb0ef41Sopenharmony_ci *
171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
181cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
191cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
201cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
211cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
221cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
231cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
241cb0ef41Sopenharmony_ci */
251cb0ef41Sopenharmony_ci#ifndef NGHTTP2_OUTBOUND_ITEM_H
261cb0ef41Sopenharmony_ci#define NGHTTP2_OUTBOUND_ITEM_H
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci#ifdef HAVE_CONFIG_H
291cb0ef41Sopenharmony_ci#  include <config.h>
301cb0ef41Sopenharmony_ci#endif /* HAVE_CONFIG_H */
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci#include <nghttp2/nghttp2.h>
331cb0ef41Sopenharmony_ci#include "nghttp2_frame.h"
341cb0ef41Sopenharmony_ci#include "nghttp2_mem.h"
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci/* struct used for HEADERS and PUSH_PROMISE frame */
371cb0ef41Sopenharmony_citypedef struct {
381cb0ef41Sopenharmony_ci  nghttp2_data_provider data_prd;
391cb0ef41Sopenharmony_ci  void *stream_user_data;
401cb0ef41Sopenharmony_ci  /* error code when request HEADERS is canceled by RST_STREAM while
411cb0ef41Sopenharmony_ci     it is in queue. */
421cb0ef41Sopenharmony_ci  uint32_t error_code;
431cb0ef41Sopenharmony_ci  /* nonzero if request HEADERS is canceled.  The error code is stored
441cb0ef41Sopenharmony_ci     in |error_code|. */
451cb0ef41Sopenharmony_ci  uint8_t canceled;
461cb0ef41Sopenharmony_ci} nghttp2_headers_aux_data;
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci/* struct used for DATA frame */
491cb0ef41Sopenharmony_citypedef struct {
501cb0ef41Sopenharmony_ci  /**
511cb0ef41Sopenharmony_ci   * The data to be sent for this DATA frame.
521cb0ef41Sopenharmony_ci   */
531cb0ef41Sopenharmony_ci  nghttp2_data_provider data_prd;
541cb0ef41Sopenharmony_ci  /**
551cb0ef41Sopenharmony_ci   * The flags of DATA frame.  We use separate flags here and
561cb0ef41Sopenharmony_ci   * nghttp2_data frame.  The latter contains flags actually sent to
571cb0ef41Sopenharmony_ci   * peer.  This |flags| may contain NGHTTP2_FLAG_END_STREAM and only
581cb0ef41Sopenharmony_ci   * when |eof| becomes nonzero, flags in nghttp2_data has
591cb0ef41Sopenharmony_ci   * NGHTTP2_FLAG_END_STREAM set.
601cb0ef41Sopenharmony_ci   */
611cb0ef41Sopenharmony_ci  uint8_t flags;
621cb0ef41Sopenharmony_ci  /**
631cb0ef41Sopenharmony_ci   * The flag to indicate whether EOF was reached or not. Initially
641cb0ef41Sopenharmony_ci   * |eof| is 0. It becomes 1 after all data were read.
651cb0ef41Sopenharmony_ci   */
661cb0ef41Sopenharmony_ci  uint8_t eof;
671cb0ef41Sopenharmony_ci  /**
681cb0ef41Sopenharmony_ci   * The flag to indicate that NGHTTP2_DATA_FLAG_NO_COPY is used.
691cb0ef41Sopenharmony_ci   */
701cb0ef41Sopenharmony_ci  uint8_t no_copy;
711cb0ef41Sopenharmony_ci} nghttp2_data_aux_data;
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_citypedef enum {
741cb0ef41Sopenharmony_ci  NGHTTP2_GOAWAY_AUX_NONE = 0x0,
751cb0ef41Sopenharmony_ci  /* indicates that session should be terminated after the
761cb0ef41Sopenharmony_ci     transmission of this frame. */
771cb0ef41Sopenharmony_ci  NGHTTP2_GOAWAY_AUX_TERM_ON_SEND = 0x1,
781cb0ef41Sopenharmony_ci  /* indicates that this GOAWAY is just a notification for graceful
791cb0ef41Sopenharmony_ci     shutdown.  No nghttp2_session.goaway_flags should be updated on
801cb0ef41Sopenharmony_ci     the reaction to this frame. */
811cb0ef41Sopenharmony_ci  NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE = 0x2
821cb0ef41Sopenharmony_ci} nghttp2_goaway_aux_flag;
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ci/* struct used for GOAWAY frame */
851cb0ef41Sopenharmony_citypedef struct {
861cb0ef41Sopenharmony_ci  /* bitwise-OR of one or more of nghttp2_goaway_aux_flag. */
871cb0ef41Sopenharmony_ci  uint8_t flags;
881cb0ef41Sopenharmony_ci} nghttp2_goaway_aux_data;
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci/* struct used for extension frame */
911cb0ef41Sopenharmony_citypedef struct {
921cb0ef41Sopenharmony_ci  /* nonzero if this extension frame is serialized by library
931cb0ef41Sopenharmony_ci     function, instead of user-defined callbacks. */
941cb0ef41Sopenharmony_ci  uint8_t builtin;
951cb0ef41Sopenharmony_ci} nghttp2_ext_aux_data;
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci/* Additional data which cannot be stored in nghttp2_frame struct */
981cb0ef41Sopenharmony_citypedef union {
991cb0ef41Sopenharmony_ci  nghttp2_data_aux_data data;
1001cb0ef41Sopenharmony_ci  nghttp2_headers_aux_data headers;
1011cb0ef41Sopenharmony_ci  nghttp2_goaway_aux_data goaway;
1021cb0ef41Sopenharmony_ci  nghttp2_ext_aux_data ext;
1031cb0ef41Sopenharmony_ci} nghttp2_aux_data;
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_cistruct nghttp2_outbound_item;
1061cb0ef41Sopenharmony_citypedef struct nghttp2_outbound_item nghttp2_outbound_item;
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_cistruct nghttp2_outbound_item {
1091cb0ef41Sopenharmony_ci  nghttp2_frame frame;
1101cb0ef41Sopenharmony_ci  /* Storage for extension frame payload.  frame->ext.payload points
1111cb0ef41Sopenharmony_ci     to this structure to avoid frequent memory allocation. */
1121cb0ef41Sopenharmony_ci  nghttp2_ext_frame_payload ext_frame_payload;
1131cb0ef41Sopenharmony_ci  nghttp2_aux_data aux_data;
1141cb0ef41Sopenharmony_ci  /* The priority used in priority comparison.  Smaller is served
1151cb0ef41Sopenharmony_ci     earlier.  For PING, SETTINGS and non-DATA frames (excluding
1161cb0ef41Sopenharmony_ci     response HEADERS frame) have dedicated cycle value defined above.
1171cb0ef41Sopenharmony_ci     For DATA frame, cycle is computed by taking into account of
1181cb0ef41Sopenharmony_ci     effective weight and frame payload length previously sent, so
1191cb0ef41Sopenharmony_ci     that the amount of transmission is distributed across streams
1201cb0ef41Sopenharmony_ci     proportional to effective weight (inside a tree). */
1211cb0ef41Sopenharmony_ci  uint64_t cycle;
1221cb0ef41Sopenharmony_ci  nghttp2_outbound_item *qnext;
1231cb0ef41Sopenharmony_ci  /* nonzero if this object is queued, except for DATA or HEADERS
1241cb0ef41Sopenharmony_ci     which are attached to stream as item. */
1251cb0ef41Sopenharmony_ci  uint8_t queued;
1261cb0ef41Sopenharmony_ci};
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ci/*
1291cb0ef41Sopenharmony_ci * Initializes |item|.  No memory allocation is done in this function.
1301cb0ef41Sopenharmony_ci * Don't call nghttp2_outbound_item_free() until frame member is
1311cb0ef41Sopenharmony_ci * initialized.
1321cb0ef41Sopenharmony_ci */
1331cb0ef41Sopenharmony_civoid nghttp2_outbound_item_init(nghttp2_outbound_item *item);
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci/*
1361cb0ef41Sopenharmony_ci * Deallocates resource for |item|. If |item| is NULL, this function
1371cb0ef41Sopenharmony_ci * does nothing.
1381cb0ef41Sopenharmony_ci */
1391cb0ef41Sopenharmony_civoid nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem);
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci/*
1421cb0ef41Sopenharmony_ci * queue for nghttp2_outbound_item.
1431cb0ef41Sopenharmony_ci */
1441cb0ef41Sopenharmony_citypedef struct {
1451cb0ef41Sopenharmony_ci  nghttp2_outbound_item *head, *tail;
1461cb0ef41Sopenharmony_ci  /* number of items in this queue. */
1471cb0ef41Sopenharmony_ci  size_t n;
1481cb0ef41Sopenharmony_ci} nghttp2_outbound_queue;
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_civoid nghttp2_outbound_queue_init(nghttp2_outbound_queue *q);
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci/* Pushes |item| into |q| */
1531cb0ef41Sopenharmony_civoid nghttp2_outbound_queue_push(nghttp2_outbound_queue *q,
1541cb0ef41Sopenharmony_ci                                 nghttp2_outbound_item *item);
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_ci/* Pops |item| at the top from |q|.  If |q| is empty, nothing
1571cb0ef41Sopenharmony_ci   happens. */
1581cb0ef41Sopenharmony_civoid nghttp2_outbound_queue_pop(nghttp2_outbound_queue *q);
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ci/* Returns the top item. */
1611cb0ef41Sopenharmony_ci#define nghttp2_outbound_queue_top(Q) ((Q)->head)
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci/* Returns the size of the queue */
1641cb0ef41Sopenharmony_ci#define nghttp2_outbound_queue_size(Q) ((Q)->n)
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci#endif /* NGHTTP2_OUTBOUND_ITEM_H */
167