Remove nghttp2_submit_* API functions which has char **nv parameter

The nghttp2_submit_{request,response}2 functions are renamed as
nghttp2_submit_{request, response}.
This commit is contained in:
Tatsuhiro Tsujikawa
2013-12-08 21:19:33 +09:00
parent d6212a6055
commit 6c77cec270
16 changed files with 315 additions and 727 deletions

View File

@@ -114,9 +114,10 @@ static void run_nghttp2_session_send(void)
{
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
const char *nv[] = { ":host", "example.org",
":scheme", "https",
NULL };
nghttp2_nv nv[] = {
MAKE_NV(":host", "example.org"),
MAKE_NV(":scheme", "https")
};
nghttp2_data_provider data_prd;
nghttp2_settings_entry iv[2];
my_user_data ud;
@@ -136,12 +137,12 @@ static void run_nghttp2_session_send(void)
if(rv != 0) {
goto client_new_fail;
}
rv = nghttp2_submit_request(session, 3, nv, &data_prd, NULL);
rv = nghttp2_submit_request(session, 3, nv, ARRLEN(nv), &data_prd, NULL);
if(rv != 0) {
goto fail;
}
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1,
NGHTTP2_PRI_DEFAULT, nv, NULL);
NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL);
if(rv != 0) {
goto fail;
}
@@ -152,7 +153,7 @@ static void run_nghttp2_session_send(void)
/* The HEADERS submitted by the previous nghttp2_submit_headers will
have stream ID 3. Send HEADERS to that stream. */
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
NGHTTP2_PRI_DEFAULT, nv, NULL);
NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL);
if(rv != 0) {
goto fail;
}
@@ -175,7 +176,7 @@ static void run_nghttp2_session_send(void)
}
/* Sending against half-closed stream */
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
NGHTTP2_PRI_DEFAULT, nv, NULL);
NGHTTP2_PRI_DEFAULT, nv, ARRLEN(nv), NULL);
if(rv != 0) {
goto fail;
}
@@ -224,9 +225,10 @@ static void run_nghttp2_session_recv(void)
uint8_t *buf = NULL;
size_t buflen = 0;
ssize_t framelen;
const char *nv[] = { ":authority", "example.org",
":scheme", "https",
NULL };
nghttp2_nv nv[] = {
MAKE_NV(":authority", "example.org"),
MAKE_NV(":scheme", "https")
};
nghttp2_settings_entry iv[2];
my_user_data ud;
data_feed df;
@@ -239,13 +241,13 @@ static void run_nghttp2_session_recv(void)
ud.df = &df;
nghttp2_failmalloc_pause();
nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
nghttp2_session_server_new(&session, &callbacks, &ud);
nghttp2_failmalloc_unpause();
/* HEADERS */
nghttp2_failmalloc_pause();
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM,
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame.headers,
@@ -319,9 +321,10 @@ static void run_nghttp2_frame_pack_headers(void)
uint8_t *buf = NULL;
size_t buflen = 0;
ssize_t framelen;
const char *nv[] = { ":host", "example.org",
":scheme", "https",
NULL };
nghttp2_nv nv[] = {
MAKE_NV(":host", "example.org"),
MAKE_NV(":scheme", "https")
};
int rv;
nghttp2_nv *nva;
ssize_t nvlen;
@@ -334,7 +337,7 @@ static void run_nghttp2_frame_pack_headers(void)
if(rv != 0) {
goto inflate_init_fail;
}
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nvlen = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
if(nvlen < 0) {
goto nv_copy_fail;
}

View File

@@ -128,21 +128,14 @@ int main(int argc, char* argv[])
!CU_add_test(pSuite, "session_upgrade", test_nghttp2_session_upgrade) ||
!CU_add_test(pSuite, "session_reprioritize_stream",
test_nghttp2_session_reprioritize_stream) ||
!CU_add_test(pSuite, "submit_response", test_nghttp2_submit_response) ||
!CU_add_test(pSuite, "submit_response_without_data",
test_nghttp2_submit_response_without_data) ||
!CU_add_test(pSuite, "submit_request_with_data",
test_nghttp2_submit_request_with_data) ||
!CU_add_test(pSuite, "submit_request_without_data",
test_nghttp2_submit_request_without_data) ||
!CU_add_test(pSuite, "submit_request2_with_data",
test_nghttp2_submit_request2_with_data) ||
!CU_add_test(pSuite, "submit_request2_without_data",
test_nghttp2_submit_request2_without_data) ||
!CU_add_test(pSuite, "submit_response2_with_data",
test_nghttp2_submit_response2_with_data) ||
!CU_add_test(pSuite, "submit_response2_without_data",
test_nghttp2_submit_response2_without_data) ||
!CU_add_test(pSuite, "submit_response_with_data",
test_nghttp2_submit_response_with_data) ||
!CU_add_test(pSuite, "submit_response_without_data",
test_nghttp2_submit_response_without_data) ||
!CU_add_test(pSuite, "submit_headers_start_stream",
test_nghttp2_submit_headers_start_stream) ||
!CU_add_test(pSuite, "submit_headers_reply",
@@ -205,8 +198,6 @@ int main(int argc, char* argv[])
test_nghttp2_session_data_backoff_by_high_pri_frame) ||
!CU_add_test(pSuite, "pack_settings_payload",
test_nghttp2_pack_settings_payload) ||
!CU_add_test(pSuite, "frame_nv_check_null",
test_nghttp2_frame_nv_check_null) ||
!CU_add_test(pSuite, "frame_pack_headers",
test_nghttp2_frame_pack_headers) ||
!CU_add_test(pSuite, "frame_pack_headers_frame_too_large",
@@ -226,8 +217,6 @@ int main(int argc, char* argv[])
test_nghttp2_frame_pack_window_update) ||
!CU_add_test(pSuite, "nv_array_check_null",
test_nghttp2_nv_array_check_null) ||
!CU_add_test(pSuite, "nv_array_from_cstr",
test_nghttp2_nv_array_from_cstr) ||
!CU_add_test(pSuite, "nv_array_copy", test_nghttp2_nv_array_copy) ||
!CU_add_test(pSuite, "iv_check", test_nghttp2_iv_check) ||
!CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) ||

View File

@@ -33,28 +33,29 @@
#include "nghttp2_helper.h"
#include "nghttp2_test_helper.h"
static const char *headers[] = {
"method", "GET",
"scheme", "https",
"url", "/",
"x-head", "foo",
"x-head", "bar",
"version", "HTTP/1.1",
"x-empty", "",
NULL
};
void test_nghttp2_frame_nv_check_null(void)
static nghttp2_nv make_nv(const char *name, const char *value)
{
const char *headers1[] = { "path", "/", "host", "a", NULL };
const char *headers2[] = { "", "/", "host", "a", NULL };
const char *headers3[] = { "path", "/", "host\x01", "a", NULL };
const char *headers4[] = { "PATH", "/", "host", NULL, NULL };
nghttp2_nv nv;
nv.name = (uint8_t*)name;
nv.value = (uint8_t*)value;
nv.namelen = strlen(name);
nv.valuelen = strlen(value);
return nv;
}
CU_ASSERT(nghttp2_frame_nv_check_null(headers1));
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers2));
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers3));
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers4));
#define HEADERS_LENGTH 7
static nghttp2_nv* headers(void)
{
nghttp2_nv *nva = malloc(sizeof(nghttp2_nv) * HEADERS_LENGTH);
nva[0] = make_nv("method", "GET");
nva[1] = make_nv("scheme", "https");
nva[2] = make_nv("url", "/");
nva[3] = make_nv("x-head", "foo");
nva[4] = make_nv("x-head", "bar");
nva[5] = make_nv("version", "HTTP/1.1");
nva[6] = make_nv("x-empty", "");
return nva;
}
static void check_frame_header(uint16_t length, uint8_t type, uint8_t flags,
@@ -79,7 +80,8 @@ void test_nghttp2_frame_pack_headers()
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
nva = headers();
nvlen = HEADERS_LENGTH;
nghttp2_frame_headers_init(&frame,
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
1000000007,
@@ -138,19 +140,20 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
nghttp2_nv *nva;
ssize_t nvlen;
size_t big_vallen = NGHTTP2_MAX_HD_VALUE_LENGTH;
char *big_hds[17];
size_t big_hdslen = sizeof(big_hds)/sizeof(big_hds[0]) - 1;
nghttp2_nv big_hds[8];
size_t big_hdslen = ARRLEN(big_hds);
size_t i;
for(i = 0; i < big_hdslen; i += 2) {
big_hds[i] = (char*)"header";
big_hds[i+1] = malloc(big_vallen+1);
memset(big_hds[i+1], '0'+i, big_vallen);
big_hds[i+1][big_vallen] = '\0';
for(i = 0; i < big_hdslen; ++i) {
big_hds[i].name = (uint8_t*)"header";
big_hds[i].value = malloc(big_vallen+1);
memset(big_hds[i].value, '0'+i, big_vallen);
big_hds[i].value[big_vallen] = '\0';
big_hds[i].namelen = strlen((char*)big_hds[i].name);
big_hds[i].valuelen = big_vallen;
}
big_hds[big_hdslen] = NULL;
nvlen = nghttp2_nv_array_from_cstr(&nva, (const char**)big_hds);
nvlen = nghttp2_nv_array_copy(&nva, big_hds, big_hdslen);
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
nghttp2_frame_headers_init(&frame,
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
@@ -161,8 +164,8 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
nghttp2_frame_headers_free(&frame);
free(buf);
for(i = 0; i < big_hdslen; i += 2) {
free(big_hds[i+1]);
for(i = 0; i < big_hdslen; ++i) {
free(big_hds[i].value);
}
nghttp2_hd_deflate_free(&deflater);
}
@@ -260,7 +263,8 @@ void test_nghttp2_frame_pack_push_promise()
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_RESPONSE);
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_RESPONSE);
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
nva = headers();
nvlen = HEADERS_LENGTH;
nghttp2_frame_push_promise_init(&frame, NGHTTP2_FLAG_END_PUSH_PROMISE,
1000000007, (1U << 31) - 1, nva, nvlen);
framelen = nghttp2_frame_pack_push_promise(&buf, &buflen, &frame, &deflater);
@@ -373,48 +377,6 @@ void test_nghttp2_nv_array_check_null(void)
CU_ASSERT(nghttp2_nv_array_check_null(nva4, ARRLEN(nva4)));
}
void test_nghttp2_nv_array_from_cstr(void)
{
const char *empty[] = {NULL};
const char *emptynv[] = {"", "", "", "", NULL};
const char *nv[] = {"alpha", "bravo", "charlie", "delta", NULL};
const char *bignv[] = {"echo", NULL, NULL};
size_t bigvallen = 64*1024;
char *bigval = malloc(bigvallen+1);
nghttp2_nv *nva;
ssize_t rv;
memset(bigval, '0', bigvallen);
bigval[bigvallen] = '\0';
bignv[1] = bigval;
rv = nghttp2_nv_array_from_cstr(&nva, empty);
CU_ASSERT(0 == rv);
CU_ASSERT(NULL == nva);
rv = nghttp2_nv_array_from_cstr(&nva, emptynv);
CU_ASSERT(0 == rv);
CU_ASSERT(NULL == nva);
rv = nghttp2_nv_array_from_cstr(&nva, nv);
CU_ASSERT(2 == rv);
CU_ASSERT(nva[0].namelen == 5);
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
CU_ASSERT(nva[0].valuelen = 5);
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
CU_ASSERT(nva[1].namelen == 7);
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
CU_ASSERT(nva[1].valuelen == 5);
CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));
nghttp2_nv_array_del(nva);
rv = nghttp2_nv_array_from_cstr(&nva, bignv);
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv);
free(bigval);
}
void test_nghttp2_nv_array_copy(void)
{
nghttp2_nv *nva;

View File

@@ -25,7 +25,6 @@
#ifndef NGHTTP2_FRAME_TEST_H
#define NGHTTP2_FRAME_TEST_H
void test_nghttp2_frame_nv_check_null(void);
void test_nghttp2_frame_pack_headers(void);
void test_nghttp2_frame_pack_headers_frame_too_large(void);
void test_nghttp2_frame_pack_priority(void);
@@ -36,7 +35,6 @@ void test_nghttp2_frame_pack_ping(void);
void test_nghttp2_frame_pack_goaway(void);
void test_nghttp2_frame_pack_window_update(void);
void test_nghttp2_nv_array_check_null(void);
void test_nghttp2_nv_array_from_cstr(void);
void test_nghttp2_nv_array_copy(void);
void test_nghttp2_iv_check(void);

File diff suppressed because it is too large Load Diff

View File

@@ -53,14 +53,10 @@ void test_nghttp2_session_send_push_promise(void);
void test_nghttp2_session_is_my_stream_id(void);
void test_nghttp2_session_upgrade(void);
void test_nghttp2_session_reprioritize_stream(void);
void test_nghttp2_submit_response(void);
void test_nghttp2_submit_response_without_data(void);
void test_nghttp2_submit_request_with_data(void);
void test_nghttp2_submit_request_without_data(void);
void test_nghttp2_submit_request2_with_data(void);
void test_nghttp2_submit_request2_without_data(void);
void test_nghttp2_submit_response2_with_data(void);
void test_nghttp2_submit_response2_without_data(void);
void test_nghttp2_submit_response_with_data(void);
void test_nghttp2_submit_response_without_data(void);
void test_nghttp2_submit_headers_start_stream(void);
void test_nghttp2_submit_headers_reply(void);
void test_nghttp2_submit_headers_push_reply(void);