2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-01-24 14:02:24 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#ifndef NGHTTP2_HELPER_H
|
|
|
|
#define NGHTTP2_HELPER_H
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-11-27 15:39:04 +01:00
|
|
|
#include <config.h>
|
2012-01-24 14:02:24 +01:00
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2015-04-15 15:32:11 +02:00
|
|
|
#include <string.h>
|
2015-08-16 12:01:10 +02:00
|
|
|
#include <stddef.h>
|
2015-04-15 15:32:11 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2014-12-07 15:07:13 +01:00
|
|
|
#include "nghttp2_mem.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#define nghttp2_min(A, B) ((A) < (B) ? (A) : (B))
|
|
|
|
#define nghttp2_max(A, B) ((A) > (B) ? (A) : (B))
|
2012-03-09 16:10:11 +01:00
|
|
|
|
2015-04-15 15:32:11 +02:00
|
|
|
#define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0)
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
#define nghttp2_struct_of(ptr, type, member) \
|
|
|
|
({ \
|
|
|
|
const typeof(((type *)0)->member) *nghttp2__mptr = (ptr); \
|
|
|
|
(type *)(void *)((char *)nghttp2__mptr - __builtin_offsetof(type, member)); \
|
|
|
|
})
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* Copies 2 byte unsigned integer |n| in host byte order to |buf| in
|
|
|
|
* network byte order.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_put_uint16be(uint8_t *buf, uint16_t n);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copies 4 byte unsigned integer |n| in host byte order to |buf| in
|
|
|
|
* network byte order.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_put_uint32be(uint8_t *buf, uint32_t n);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieves 2 byte unsigned integer stored in |data| in network byte
|
|
|
|
* order and returns it in host byte order.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
uint16_t nghttp2_get_uint16(const uint8_t *data);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieves 4 byte unsigned integer stored in |data| in network byte
|
|
|
|
* order and returns it in host byte order.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
uint32_t nghttp2_get_uint32(const uint8_t *data);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-19 09:50:31 +02:00
|
|
|
/*
|
2014-05-06 17:02:29 +02:00
|
|
|
* Allocates |n| bytes of memory and copy the memory region pointed by
|
2013-07-19 09:50:31 +02:00
|
|
|
* |src| with the length |n| bytes into it. Returns the allocated memory.
|
|
|
|
*
|
|
|
|
* This function returns pointer to allocated memory, or one of the
|
|
|
|
* following negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory.
|
|
|
|
*/
|
2014-12-07 15:07:13 +01:00
|
|
|
void *nghttp2_memdup(const void *src, size_t n, nghttp2_mem *mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2013-07-19 17:08:14 +02:00
|
|
|
void nghttp2_downcase(uint8_t *s, size_t len);
|
|
|
|
|
2013-08-08 17:58:52 +02:00
|
|
|
/*
|
2013-10-12 10:02:37 +02:00
|
|
|
* Adjusts |*local_window_size_ptr|, |*recv_window_size_ptr|,
|
|
|
|
* |*recv_reduction_ptr| with |*delta_ptr| which is the
|
|
|
|
* WINDOW_UPDATE's window_size_increment sent from local side. If
|
|
|
|
* |delta| is strictly larger than |*recv_window_size_ptr|,
|
|
|
|
* |*local_window_size_ptr| is increased by delta -
|
|
|
|
* *recv_window_size_ptr. If |delta| is negative,
|
2013-08-08 17:58:52 +02:00
|
|
|
* |*local_window_size_ptr| is decreased by delta.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_FLOW_CONTROL
|
|
|
|
* local_window_size overflow or gets negative.
|
|
|
|
*/
|
|
|
|
int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr,
|
|
|
|
int32_t *recv_window_size_ptr,
|
2013-10-12 10:02:37 +02:00
|
|
|
int32_t *recv_reduction_ptr,
|
|
|
|
int32_t *delta_ptr);
|
2013-08-08 17:58:52 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns non-zero if the function decided that WINDOW_UPDATE should
|
|
|
|
* be sent.
|
|
|
|
*/
|
|
|
|
int nghttp2_should_send_window_update(int32_t local_window_size,
|
|
|
|
int32_t recv_window_size);
|
|
|
|
|
2014-03-10 17:47:38 +01:00
|
|
|
/*
|
|
|
|
* Copies the buffer |src| of length |len| to the destination pointed
|
|
|
|
* by the |dest|, assuming that the |dest| is at lest |len| bytes long
|
|
|
|
* . Returns dest + len.
|
|
|
|
*/
|
2014-11-27 15:39:04 +01:00
|
|
|
uint8_t *nghttp2_cpymem(uint8_t *dest, const void *src, size_t len);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#endif /* NGHTTP2_HELPER_H */
|