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_HELPER_H
261cb0ef41Sopenharmony_ci#define NGHTTP2_HELPER_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 <string.h>
331cb0ef41Sopenharmony_ci#include <stddef.h>
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci#include <nghttp2/nghttp2.h>
361cb0ef41Sopenharmony_ci#include "nghttp2_mem.h"
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci#define nghttp2_min(A, B) ((A) < (B) ? (A) : (B))
391cb0ef41Sopenharmony_ci#define nghttp2_max(A, B) ((A) > (B) ? (A) : (B))
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci#define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0)
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci#define nghttp2_struct_of(ptr, type, member)                                   \
441cb0ef41Sopenharmony_ci  ((type *)(void *)((char *)(ptr)-offsetof(type, member)))
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci/*
471cb0ef41Sopenharmony_ci * Copies 2 byte unsigned integer |n| in host byte order to |buf| in
481cb0ef41Sopenharmony_ci * network byte order.
491cb0ef41Sopenharmony_ci */
501cb0ef41Sopenharmony_civoid nghttp2_put_uint16be(uint8_t *buf, uint16_t n);
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci/*
531cb0ef41Sopenharmony_ci * Copies 4 byte unsigned integer |n| in host byte order to |buf| in
541cb0ef41Sopenharmony_ci * network byte order.
551cb0ef41Sopenharmony_ci */
561cb0ef41Sopenharmony_civoid nghttp2_put_uint32be(uint8_t *buf, uint32_t n);
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci/*
591cb0ef41Sopenharmony_ci * Retrieves 2 byte unsigned integer stored in |data| in network byte
601cb0ef41Sopenharmony_ci * order and returns it in host byte order.
611cb0ef41Sopenharmony_ci */
621cb0ef41Sopenharmony_ciuint16_t nghttp2_get_uint16(const uint8_t *data);
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci/*
651cb0ef41Sopenharmony_ci * Retrieves 4 byte unsigned integer stored in |data| in network byte
661cb0ef41Sopenharmony_ci * order and returns it in host byte order.
671cb0ef41Sopenharmony_ci */
681cb0ef41Sopenharmony_ciuint32_t nghttp2_get_uint32(const uint8_t *data);
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_civoid nghttp2_downcase(uint8_t *s, size_t len);
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci/*
731cb0ef41Sopenharmony_ci * Adjusts |*local_window_size_ptr|, |*recv_window_size_ptr|,
741cb0ef41Sopenharmony_ci * |*recv_reduction_ptr| with |*delta_ptr| which is the
751cb0ef41Sopenharmony_ci * WINDOW_UPDATE's window_size_increment sent from local side. If
761cb0ef41Sopenharmony_ci * |delta| is strictly larger than |*recv_window_size_ptr|,
771cb0ef41Sopenharmony_ci * |*local_window_size_ptr| is increased by delta -
781cb0ef41Sopenharmony_ci * *recv_window_size_ptr. If |delta| is negative,
791cb0ef41Sopenharmony_ci * |*local_window_size_ptr| is decreased by delta.
801cb0ef41Sopenharmony_ci *
811cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following
821cb0ef41Sopenharmony_ci * negative error codes:
831cb0ef41Sopenharmony_ci *
841cb0ef41Sopenharmony_ci * NGHTTP2_ERR_FLOW_CONTROL
851cb0ef41Sopenharmony_ci *     local_window_size overflow or gets negative.
861cb0ef41Sopenharmony_ci */
871cb0ef41Sopenharmony_ciint nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr,
881cb0ef41Sopenharmony_ci                                     int32_t *recv_window_size_ptr,
891cb0ef41Sopenharmony_ci                                     int32_t *recv_reduction_ptr,
901cb0ef41Sopenharmony_ci                                     int32_t *delta_ptr);
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci/*
931cb0ef41Sopenharmony_ci * This function works like nghttp2_adjust_local_window_size().  The
941cb0ef41Sopenharmony_ci * difference is that this function assumes *delta_ptr >= 0, and
951cb0ef41Sopenharmony_ci * *recv_window_size_ptr is not decreased by *delta_ptr.
961cb0ef41Sopenharmony_ci *
971cb0ef41Sopenharmony_ci * This function returns 0 if it succeeds, or one of the following
981cb0ef41Sopenharmony_ci * negative error codes:
991cb0ef41Sopenharmony_ci *
1001cb0ef41Sopenharmony_ci * NGHTTP2_ERR_FLOW_CONTROL
1011cb0ef41Sopenharmony_ci *     local_window_size overflow or gets negative.
1021cb0ef41Sopenharmony_ci */
1031cb0ef41Sopenharmony_ciint nghttp2_increase_local_window_size(int32_t *local_window_size_ptr,
1041cb0ef41Sopenharmony_ci                                       int32_t *recv_window_size_ptr,
1051cb0ef41Sopenharmony_ci                                       int32_t *recv_reduction_ptr,
1061cb0ef41Sopenharmony_ci                                       int32_t *delta_ptr);
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci/*
1091cb0ef41Sopenharmony_ci * Returns non-zero if the function decided that WINDOW_UPDATE should
1101cb0ef41Sopenharmony_ci * be sent.
1111cb0ef41Sopenharmony_ci */
1121cb0ef41Sopenharmony_ciint nghttp2_should_send_window_update(int32_t local_window_size,
1131cb0ef41Sopenharmony_ci                                      int32_t recv_window_size);
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci/*
1161cb0ef41Sopenharmony_ci * Copies the buffer |src| of length |len| to the destination pointed
1171cb0ef41Sopenharmony_ci * by the |dest|, assuming that the |dest| is at lest |len| bytes long
1181cb0ef41Sopenharmony_ci * . Returns dest + len.
1191cb0ef41Sopenharmony_ci */
1201cb0ef41Sopenharmony_ciuint8_t *nghttp2_cpymem(uint8_t *dest, const void *src, size_t len);
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci#endif /* NGHTTP2_HELPER_H */
123