From 553410c3508255c285835ee394e4d8a0db6cb1f0 Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Thu, 9 Feb 2012 10:54:47 -0800 Subject: [PATCH 1/6] Make the ncurses check a runtime check --- configure.ac | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 61509a35..61bd8d59 100644 --- a/configure.ac +++ b/configure.ac @@ -70,10 +70,12 @@ if test "x${have_cunit}" = "xyes"; then # needed because cunit in Mac OS X requires it. LIBS_TEMP=${LIBS} LIBS=${CUNIT_LIBS} - AC_SEARCH_LIBS([CU_initialize_registry], [ncurses]) - CUNIT_LIBS=${LIBS} - AC_SUBST([CUNIT_LIBS]) + CFLAGS_TEMP=${CFLAGS} + CFLAGS=${CUNIT_CFLAGS} + AC_RUN_IFELSE(AC_LANG_PROGRAM([[#include "CUnit/Basic.h"]], [CU_initialize_registry()]), [], + [CUNIT_LIBS="${LIBS} -lncurses"]) LIBS=${LIBS_TEMP} + CFLAGS=${CFLAGS_TEMP} fi AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ]) From 69dc06f2fb2d48cb18baff4f547794ffd1a8e4c2 Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Thu, 9 Feb 2012 11:32:07 -0800 Subject: [PATCH 2/6] Ignore spdyd --- examples/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/.gitignore b/examples/.gitignore index 76f4335d..4bc65f96 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1 +1,2 @@ spdycat +spdyd From 40e8fc960e0b6315a918be990e1e3a0df7ee516f Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Wed, 15 Feb 2012 12:07:25 -0800 Subject: [PATCH 3/6] Create a test that explicitly checks that a key exists only once in a name/value block. --- tests/main.c | 2 + tests/spdylay_frame_test.c | 86 ++++++++++++++++++++++++++++++++++++++ tests/spdylay_frame_test.h | 1 + 3 files changed, 89 insertions(+) diff --git a/tests/main.c b/tests/main.c index f144a84f..f670504b 100644 --- a/tests/main.c +++ b/tests/main.c @@ -134,6 +134,8 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "frame_nv_sort", test_spdylay_frame_nv_sort) || !CU_add_test(pSuite, "frame_nv_downcase", test_spdylay_frame_nv_downcase) || + !CU_add_test(pSuite, "frame_nv_downcase", + test_spdylay_frame_pack_nv_duplicate_keys) || !CU_add_test(pSuite, "stream_add_pushed_stream", test_spdylay_stream_add_pushed_stream)) { CU_cleanup_registry(); diff --git a/tests/spdylay_frame_test.c b/tests/spdylay_frame_test.c index 73a22e95..b9b59a62 100644 --- a/tests/spdylay_frame_test.c +++ b/tests/spdylay_frame_test.c @@ -60,6 +60,92 @@ void test_spdylay_frame_unpack_nv() spdylay_frame_nv_del(nv); } +void test_spdylay_frame_pack_nv_duplicate_keys() +{ + int i; + uint8_t out[1024]; + const char *nv_src[] = { + "method", "GET", + "scheme", "https", + "url", "/", + "X-hEad", "foo", + "x-heaD", "bar", + "version", "HTTP/1.1", + NULL + }; + char **nv = spdylay_frame_nv_copy(nv_src); + spdylay_frame_nv_downcase(nv); + spdylay_frame_nv_sort(nv); + size_t inlen = spdylay_frame_pack_nv(out, nv); + const uint8_t *outptr = out; + int pairs = spdylay_get_uint16(outptr); + CU_ASSERT(pairs == 5); + outptr += 2; + + int len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 6); + CU_ASSERT(memcmp(outptr, "method", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 3); + CU_ASSERT(memcmp(outptr, "GET", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 6); + CU_ASSERT(memcmp(outptr, "scheme", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 5); + CU_ASSERT(memcmp(outptr, "https", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 3); + CU_ASSERT(memcmp(outptr, "url", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 1); + CU_ASSERT(memcmp(outptr, "/", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 7); + CU_ASSERT(memcmp(outptr, "version", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 8); + CU_ASSERT(memcmp(outptr, "HTTP/1.1", len) == 0); + outptr += len; + + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 6); + CU_ASSERT(memcmp(outptr, "x-head", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 7); + CU_ASSERT(memcmp(outptr, "foo\0bar", len) == 0); + outptr += len; + + spdylay_frame_nv_del(nv); +} + void test_spdylay_frame_count_nv_space() { CU_ASSERT(83 == spdylay_frame_count_nv_space((char**)headers)); diff --git a/tests/spdylay_frame_test.h b/tests/spdylay_frame_test.h index 6484e565..7c62e836 100644 --- a/tests/spdylay_frame_test.h +++ b/tests/spdylay_frame_test.h @@ -26,6 +26,7 @@ #define SPDYLAY_FRAME_TEST_H void test_spdylay_frame_unpack_nv(); +void test_spdylay_frame_pack_nv_duplicate_keys(); void test_spdylay_frame_count_nv_space(); void test_spdylay_frame_count_unpack_nv_space(); void test_spdylay_frame_pack_ping(); From d04449eb287148b7b78decc5434fdf66d6091af7 Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Wed, 15 Feb 2012 13:33:30 -0800 Subject: [PATCH 4/6] Document that url should have the query parameters. --- lib/includes/spdylay/spdylay.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/includes/spdylay/spdylay.h b/lib/includes/spdylay/spdylay.h index aa5c86fd..ed9730c5 100644 --- a/lib/includes/spdylay/spdylay.h +++ b/lib/includes/spdylay/spdylay.h @@ -399,9 +399,10 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session, * range of [0, 3]. 0 means the higest priority. |nv| must include * following name/value pairs: * - * "method": HTTP method (e.g., "GET" or "POST") + * "method": HTTP method (e.g., "GET", "POST", "HEAD", etc) * "scheme": URI scheme (e.g., "https") - * "url": Absolute path of this request (e.g., "/foo") + * "url": Absolute path and parameters of this request (e.g., "/foo", + * "/foo;bar;haz?h=j&y=123") * "version": HTTP version (e.g., "HTTP/1.1") * * "host" name/value pair is also required by some hosts. From f05a67641f0bfee464a631b93490a7ca89b1339e Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Wed, 15 Feb 2012 13:49:02 -0800 Subject: [PATCH 5/6] Be a bit more liberal about what methods accept message bodies. --- lib/includes/spdylay/spdylay.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/includes/spdylay/spdylay.h b/lib/includes/spdylay/spdylay.h index ed9730c5..7be286c3 100644 --- a/lib/includes/spdylay/spdylay.h +++ b/lib/includes/spdylay/spdylay.h @@ -411,11 +411,12 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session, * also lower-cases all names in |nv|. * * If |data_prd| is not NULL, it provides data which will be sent in - * subsequent DATA frames. In this case, "POST" must be specified with - * "method" key in |nv|. If |data_prd| is NULL, SYN_STREAM have - * FLAG_FIN. |stream_user_data| can be an arbitrary pointer, which - * can be retrieved by spdylay_session_get_stream_user_data(). Since - * stream ID is not known before sending SYN_STREAM frame and the + * subsequent DATA frames. In this case, a method that allows request + * message bodies (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9) + * must be specified with "method" key in |nv| (e.g. POST). If |data_prd| is + * NULL, SYN_STREAM have * FLAG_FIN. |stream_user_data| can be an arbitrary + * pointer, which can be retrieved by spdylay_session_get_stream_user_data(). + * Since stream ID is not known before sending SYN_STREAM frame and the * application code has to compare url, and possibly other header * field values, to identify stream ID for the request in * spdylay_on_ctrl_send_callback(). With |stream_user_data|, the From 63353ea48646445c7b084c180b64bfb906fc193f Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Wed, 15 Feb 2012 14:30:36 -0800 Subject: [PATCH 6/6] Ensure read_callback is non-NULL for request bodies. --- lib/spdylay_submit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spdylay_submit.c b/lib/spdylay_submit.c index 86245a09..2b156810 100644 --- a/lib/spdylay_submit.c +++ b/lib/spdylay_submit.c @@ -124,7 +124,7 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri, if(pri > 3) { return SPDYLAY_ERR_INVALID_ARGUMENT; } - if(data_prd) { + if(data_prd != NULL && data_prd->read_callback != NULL) { data_prd_copy = malloc(sizeof(spdylay_data_provider)); if(data_prd_copy == NULL) { return SPDYLAY_ERR_NOMEM;