2012-01-19 17:04:13 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2 - HTTP/2.0 C Library
|
2012-01-19 17:04:13 +01:00
|
|
|
*
|
2014-01-25 10:24:15 +01:00
|
|
|
* Copyright (c) 2014 Tatsuhiro Tsujikawa
|
2012-01-19 17:04:13 +01:00
|
|
|
*
|
|
|
|
* 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_BUFFER_H
|
|
|
|
#define NGHTTP2_BUFFER_H
|
2012-01-19 17:04:13 +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-19 17:04:13 +01:00
|
|
|
|
2014-01-25 10:24:15 +01:00
|
|
|
#include "nghttp2_int.h"
|
2012-02-16 14:01:34 +01:00
|
|
|
|
2012-01-19 17:04:13 +01:00
|
|
|
/*
|
2014-01-25 10:24:15 +01:00
|
|
|
* Byte array buffer
|
2012-01-19 17:04:13 +01:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2014-01-25 10:24:15 +01:00
|
|
|
uint8_t *buf;
|
|
|
|
/* Capacity of this buffer */
|
2012-01-19 17:04:13 +01:00
|
|
|
size_t capacity;
|
2014-01-25 10:24:15 +01:00
|
|
|
/* How many bytes are written to buf. len <= capacity must hold. */
|
2012-01-19 17:04:13 +01:00
|
|
|
size_t len;
|
2014-01-25 10:24:15 +01:00
|
|
|
/* Maximum capacity this buffer can grow up */
|
|
|
|
size_t max_capacity;
|
2013-07-12 17:19:03 +02:00
|
|
|
} nghttp2_buffer;
|
2012-01-19 17:04:13 +01:00
|
|
|
|
2014-01-25 10:24:15 +01:00
|
|
|
void nghttp2_buffer_init(nghttp2_buffer *buffer, size_t max_capacity);
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_buffer_free(nghttp2_buffer *buffer);
|
2012-05-25 03:46:40 +02:00
|
|
|
|
|
|
|
/*
|
2014-01-25 10:24:15 +01:00
|
|
|
* Expands capacity so that it can contain at least |len| bytes of
|
|
|
|
* data. If buffer->capacity >= len, no action is taken. If len >
|
|
|
|
* buffer->max_capacity, NGHTTP2_ERR_BUFFER_ERROR is returned.
|
2012-05-25 03:46:40 +02:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2014-01-25 10:24:15 +01:00
|
|
|
* NGHTTP2_ERR_BUFFER_ERROR
|
|
|
|
* The |len| is strictly larger than buffer->max_capacity
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2014-01-25 10:24:15 +01:00
|
|
|
* Out of memory
|
2012-05-25 03:46:40 +02:00
|
|
|
*/
|
2014-01-25 10:24:15 +01:00
|
|
|
int nghttp2_buffer_reserve(nghttp2_buffer *buffer, size_t len);
|
2012-05-25 03:46:40 +02:00
|
|
|
|
2012-02-21 15:24:16 +01:00
|
|
|
/*
|
2014-01-25 10:24:15 +01:00
|
|
|
* Appends the |data| with |len| bytes to the buffer. The data is
|
|
|
|
* copied. The |buffer| will be expanded as needed.
|
2012-02-21 15:24:16 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
2014-01-25 10:24:15 +01:00
|
|
|
* negative error codes:
|
2012-02-21 15:24:16 +01:00
|
|
|
*
|
2014-01-25 10:24:15 +01:00
|
|
|
* NGHTTP2_ERR_BUFFER_ERROR
|
|
|
|
* The |len| is strictly larger than buffer->max_capacity
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2014-01-25 10:24:15 +01:00
|
|
|
* Out of memory
|
2012-05-25 03:46:40 +02:00
|
|
|
*/
|
2014-01-25 10:24:15 +01:00
|
|
|
int nghttp2_buffer_add(nghttp2_buffer *buffer,
|
|
|
|
const uint8_t *data, size_t len);
|
2012-05-25 03:46:40 +02:00
|
|
|
|
|
|
|
/*
|
2014-01-25 10:24:15 +01:00
|
|
|
* Appends the a single byte|b| to the buffer. The data is copied. The
|
|
|
|
* |buffer| will be expanded as needed.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_BUFFER_ERROR
|
|
|
|
* The |len| is strictly larger than buffer->max_capacity
|
|
|
|
* NGHTTP2_ERR_NOMEM
|
|
|
|
* Out of memory
|
2013-01-21 16:12:15 +01:00
|
|
|
*/
|
2014-01-25 10:24:15 +01:00
|
|
|
int nghttp2_buffer_add_byte(nghttp2_buffer *buffer, uint8_t b);
|
2013-01-21 16:12:15 +01:00
|
|
|
|
2012-05-25 03:46:40 +02:00
|
|
|
/*
|
2014-01-25 10:24:15 +01:00
|
|
|
* Releases the buffer without freeing it. The data members in buffer
|
|
|
|
* is initialized.
|
2012-05-25 03:46:40 +02:00
|
|
|
*/
|
2014-01-25 10:24:15 +01:00
|
|
|
void nghttp2_buffer_release(nghttp2_buffer *buffer);
|
2012-05-25 03:46:40 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#endif /* NGHTTP2_BUFFER_H */
|