diff --git a/lib/Makefile.am b/lib/Makefile.am index 08a6d7a2..933e5453 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -32,7 +32,7 @@ DISTCLEANFILES = $(pkgconfig_DATA) lib_LTLIBRARIES = libnghttp2.la OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \ - nghttp2_buffer.c nghttp2_frame.c \ + nghttp2_frame.c \ nghttp2_buf.c \ nghttp2_stream.c nghttp2_outbound_item.c \ nghttp2_session.c nghttp2_submit.c \ @@ -42,7 +42,7 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \ nghttp2_version.c HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \ - nghttp2_buffer.h nghttp2_frame.h \ + nghttp2_frame.h \ nghttp2_buf.h \ nghttp2_session.h nghttp2_helper.h nghttp2_stream.h nghttp2_int.h \ nghttp2_npn.h nghttp2_gzip.h \ diff --git a/lib/nghttp2_buffer.c b/lib/nghttp2_buffer.c deleted file mode 100644 index ec2649d1..00000000 --- a/lib/nghttp2_buffer.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * nghttp2 - HTTP/2.0 C Library - * - * Copyright (c) 2014 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. - */ -#include "nghttp2_buffer.h" - -#include -#include - -#include "nghttp2_helper.h" - -void nghttp2_buffer_init(nghttp2_buffer *buffer, size_t max_capacity) -{ - buffer->buf = NULL; - buffer->len = 0; - buffer->capacity = 0; - buffer->max_capacity = max_capacity; -} - -void nghttp2_buffer_free(nghttp2_buffer *buffer) -{ - free(buffer->buf); -} - -int nghttp2_buffer_reserve(nghttp2_buffer *buffer, size_t len) -{ - if(len > buffer->max_capacity) { - return NGHTTP2_ERR_BUFFER_ERROR; - } - if(buffer->capacity < len) { - uint8_t *new_buf; - size_t new_cap = buffer->capacity == 0 ? 8 : buffer->capacity * 3 / 2; - new_cap = nghttp2_min(buffer->max_capacity, nghttp2_max(new_cap, len)); - new_buf = realloc(buffer->buf, new_cap); - if(new_buf == NULL) { - return NGHTTP2_ERR_NOMEM; - } - buffer->buf = new_buf; - buffer->capacity = new_cap; - } - return 0; -} - -int nghttp2_buffer_add(nghttp2_buffer *buffer, - const uint8_t *data, size_t len) -{ - int rv; - rv = nghttp2_buffer_reserve(buffer, buffer->len + len); - if(rv != 0) { - return rv; - } - memcpy(buffer->buf + buffer->len, data, len); - buffer->len += len; - return 0; -} - -int nghttp2_buffer_add_byte(nghttp2_buffer *buffer, uint8_t b) -{ - int rv; - rv = nghttp2_buffer_reserve(buffer, buffer->len + 1); - if(rv != 0) { - return rv; - } - buffer->buf[buffer->len] = b; - ++buffer->len; - return 0; -} - -void nghttp2_buffer_release(nghttp2_buffer *buffer) -{ - buffer->buf = NULL; - buffer->len = 0; - buffer->capacity = 0; -} diff --git a/lib/nghttp2_buffer.h b/lib/nghttp2_buffer.h deleted file mode 100644 index a2f46e27..00000000 --- a/lib/nghttp2_buffer.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * nghttp2 - HTTP/2.0 C Library - * - * Copyright (c) 2014 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. - */ -#ifndef NGHTTP2_BUFFER_H -#define NGHTTP2_BUFFER_H - -#ifdef HAVE_CONFIG_H -# include -#endif /* HAVE_CONFIG_H */ - -#include - -#include "nghttp2_int.h" - -/* - * Byte array buffer - */ -typedef struct { - uint8_t *buf; - /* Capacity of this buffer */ - size_t capacity; - /* How many bytes are written to buf. len <= capacity must hold. */ - size_t len; - /* Maximum capacity this buffer can grow up */ - size_t max_capacity; -} nghttp2_buffer; - -void nghttp2_buffer_init(nghttp2_buffer *buffer, size_t max_capacity); - -void nghttp2_buffer_free(nghttp2_buffer *buffer); - -/* - * 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. - * - * 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 - */ -int nghttp2_buffer_reserve(nghttp2_buffer *buffer, size_t len); - -/* - * Appends the |data| with |len| bytes 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 - */ -int nghttp2_buffer_add(nghttp2_buffer *buffer, - const uint8_t *data, size_t len); - -/* - * 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 - */ -int nghttp2_buffer_add_byte(nghttp2_buffer *buffer, uint8_t b); - -/* - * Releases the buffer without freeing it. The data members in buffer - * is initialized. - */ -void nghttp2_buffer_release(nghttp2_buffer *buffer); - -#endif /* NGHTTP2_BUFFER_H */ diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index c2ee2c9a..18dd001b 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -31,7 +31,6 @@ #include #include "nghttp2_hd.h" -#include "nghttp2_buffer.h" #include "nghttp2_buf.h" #define NGHTTP2_FRAME_LENGTH_MASK ((1 << 14) - 1) diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index 81f894cf..42d7049a 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -35,7 +35,6 @@ #include "nghttp2_frame.h" #include "nghttp2_hd.h" #include "nghttp2_stream.h" -#include "nghttp2_buffer.h" #include "nghttp2_outbound_item.h" #include "nghttp2_int.h" #include "nghttp2_buf.h" diff --git a/tests/Makefile.am b/tests/Makefile.am index b2748aa7..4fdc8731 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,7 +31,6 @@ check_PROGRAMS += failmalloc endif # ENABLE_FAILMALLOC OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \ - nghttp2_buffer_test.c \ nghttp2_test_helper.c \ nghttp2_frame_test.c \ nghttp2_stream_test.c \ @@ -42,7 +41,7 @@ OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \ nghttp2_helper_test.c HFILES = nghttp2_pq_test.h nghttp2_map_test.h nghttp2_queue_test.h \ - nghttp2_buffer_test.h nghttp2_session_test.h \ + nghttp2_session_test.h \ nghttp2_frame_test.h nghttp2_stream_test.h nghttp2_hd_test.h \ nghttp2_npn_test.h nghttp2_gzip_test.h nghttp2_helper_test.h \ nghttp2_test_helper.h diff --git a/tests/main.c b/tests/main.c index 9db8f840..59253f01 100644 --- a/tests/main.c +++ b/tests/main.c @@ -29,7 +29,6 @@ #include "nghttp2_pq_test.h" #include "nghttp2_map_test.h" #include "nghttp2_queue_test.h" -#include "nghttp2_buffer_test.h" #include "nghttp2_session_test.h" #include "nghttp2_frame_test.h" #include "nghttp2_stream_test.h" @@ -72,7 +71,6 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "map_functional", test_nghttp2_map_functional) || !CU_add_test(pSuite, "map_each_free", test_nghttp2_map_each_free) || !CU_add_test(pSuite, "queue", test_nghttp2_queue) || - !CU_add_test(pSuite, "buffer", test_nghttp2_buffer) || !CU_add_test(pSuite, "npn", test_nghttp2_npn) || !CU_add_test(pSuite, "session_recv", test_nghttp2_session_recv) || !CU_add_test(pSuite, "session_recv_invalid_stream_id", diff --git a/tests/nghttp2_buffer_test.c b/tests/nghttp2_buffer_test.c deleted file mode 100644 index a10b1c8f..00000000 --- a/tests/nghttp2_buffer_test.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * nghttp2 - HTTP/2.0 C Library - * - * 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. - */ -#include "nghttp2_buffer_test.h" - -#include - -#include - -#include "nghttp2_buffer.h" - -void test_nghttp2_buffer(void) -{ - nghttp2_buffer buffer; - - nghttp2_buffer_init(&buffer, 16); - - CU_ASSERT(0 == buffer.len); - - CU_ASSERT(0 == nghttp2_buffer_add(&buffer, (const uint8_t*)"foo", 3)); - CU_ASSERT(3 == buffer.len); - - CU_ASSERT(0 == nghttp2_buffer_add_byte(&buffer, '.')); - CU_ASSERT(4 == buffer.len); - - CU_ASSERT(0 == nghttp2_buffer_add(&buffer, - (const uint8_t*)"012345678901", 12)); - CU_ASSERT(16 == buffer.len); - - CU_ASSERT(NGHTTP2_ERR_BUFFER_ERROR == nghttp2_buffer_add_byte(&buffer, '.')); - CU_ASSERT(NGHTTP2_ERR_BUFFER_ERROR == - nghttp2_buffer_add(&buffer, (const uint8_t*)".", 1)); - - nghttp2_buffer_free(&buffer); -} diff --git a/tests/nghttp2_buffer_test.h b/tests/nghttp2_buffer_test.h deleted file mode 100644 index e884c3a7..00000000 --- a/tests/nghttp2_buffer_test.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * nghttp2 - HTTP/2.0 C Library - * - * 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. - */ -#ifndef NGHTTP2_BUFFER_TEST_H -#define NGHTTP2_BUFFER_TEST_H - -void test_nghttp2_buffer(void); -void test_nghttp2_buffer_reader(void); - -#endif /* NGHTTP2_BUFFER_TEST_H */