2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2 - HTTP/2.0 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
|
|
|
|
# include <config.h>
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.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
|
|
|
|
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
|
|
|
|
2012-02-16 12:54:30 +01:00
|
|
|
/*
|
|
|
|
* Ensures that buffer |*buf_ptr| with |*buflen_ptr| length has at
|
|
|
|
* least |min_length| bytes. If |min_length| > |*buflen_ptr|,
|
|
|
|
* allocates new buffer having at least |min_length| bytes and assigns
|
|
|
|
* its pointer to |*buf_ptr| and allocated number of bytes to
|
|
|
|
* |*buflen_ptr|. The memory pointed by |*buf_ptr| previously is
|
2012-02-21 15:24:16 +01:00
|
|
|
* freed. No memory copy is done between old and new buffer.
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr| and |*buflen_ptr| are only updated iff this function
|
|
|
|
* succeeds.
|
2012-02-21 15:24:16 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-21 15:24:16 +01:00
|
|
|
* Out of memory.
|
2012-02-16 12:54:30 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
size_t min_length);
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#endif /* NGHTTP2_HELPER_H */
|