Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_helper.h
3153 views
/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2012 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_HELPER_H25#define NGHTTP2_HELPER_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <string.h>32#include <stddef.h>3334#include <nghttp2/nghttp2.h>35#include "nghttp2_mem.h"3637#define nghttp2_min(A, B) ((A) < (B) ? (A) : (B))38#define nghttp2_max(A, B) ((A) > (B) ? (A) : (B))3940#define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0)4142#define nghttp2_struct_of(ptr, type, member) \43((type *)(void *)((char *)(ptr)-offsetof(type, member)))4445/*46* Copies 2 byte unsigned integer |n| in host byte order to |buf| in47* network byte order.48*/49void nghttp2_put_uint16be(uint8_t *buf, uint16_t n);5051/*52* Copies 4 byte unsigned integer |n| in host byte order to |buf| in53* network byte order.54*/55void nghttp2_put_uint32be(uint8_t *buf, uint32_t n);5657/*58* Retrieves 2 byte unsigned integer stored in |data| in network byte59* order and returns it in host byte order.60*/61uint16_t nghttp2_get_uint16(const uint8_t *data);6263/*64* Retrieves 4 byte unsigned integer stored in |data| in network byte65* order and returns it in host byte order.66*/67uint32_t nghttp2_get_uint32(const uint8_t *data);6869void nghttp2_downcase(uint8_t *s, size_t len);7071/*72* Adjusts |*local_window_size_ptr|, |*recv_window_size_ptr|,73* |*recv_reduction_ptr| with |*delta_ptr| which is the74* WINDOW_UPDATE's window_size_increment sent from local side. If75* |delta| is strictly larger than |*recv_window_size_ptr|,76* |*local_window_size_ptr| is increased by delta -77* *recv_window_size_ptr. If |delta| is negative,78* |*local_window_size_ptr| is decreased by delta.79*80* This function returns 0 if it succeeds, or one of the following81* negative error codes:82*83* NGHTTP2_ERR_FLOW_CONTROL84* local_window_size overflow or gets negative.85*/86int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr,87int32_t *recv_window_size_ptr,88int32_t *recv_reduction_ptr,89int32_t *delta_ptr);9091/*92* This function works like nghttp2_adjust_local_window_size(). The93* difference is that this function assumes *delta_ptr >= 0, and94* *recv_window_size_ptr is not decreased by *delta_ptr.95*96* This function returns 0 if it succeeds, or one of the following97* negative error codes:98*99* NGHTTP2_ERR_FLOW_CONTROL100* local_window_size overflow or gets negative.101*/102int nghttp2_increase_local_window_size(int32_t *local_window_size_ptr,103int32_t *recv_window_size_ptr,104int32_t *recv_reduction_ptr,105int32_t *delta_ptr);106107/*108* Returns non-zero if the function decided that WINDOW_UPDATE should109* be sent.110*/111int nghttp2_should_send_window_update(int32_t local_window_size,112int32_t recv_window_size);113114/*115* Copies the buffer |src| of length |len| to the destination pointed116* by the |dest|, assuming that the |dest| is at lest |len| bytes long117* . Returns dest + len.118*/119uint8_t *nghttp2_cpymem(uint8_t *dest, const void *src, size_t len);120121#endif /* NGHTTP2_HELPER_H */122123124