From 4e5e741907c6d32434014b4c92083f76d54b710c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 27 Aug 2012 23:16:44 +0900 Subject: [PATCH] Add spdylay_npn_get_proto_list() public API function. spdylay_npn_get_proto_list() returns a pointer to the supported SPDY version list. The element of the list is spdylay_npn_proto struct. It contains all SPDY version information this library supports. The application can use this information to configure NPN protocol offerings/selection. --- lib/includes/spdylay/spdylay.h | 35 ++++++++++++++++++++++++++++++++++ lib/spdylay_npn.c | 19 +++++++++--------- tests/main.c | 2 ++ tests/spdylay_npn_test.c | 14 ++++++++++++++ tests/spdylay_npn_test.h | 1 + 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/lib/includes/spdylay/spdylay.h b/lib/includes/spdylay/spdylay.h index 5452fa56..110de64e 100644 --- a/lib/includes/spdylay/spdylay.h +++ b/lib/includes/spdylay/spdylay.h @@ -1993,6 +1993,41 @@ int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id, int spdylay_select_next_protocol(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen); +/** + * @struct + * + * This struct contains SPDY version information this library + * supports. + */ +typedef struct { + /** + * SPDY protocol version name which can be used as TLS NPN protocol + * string. + */ + const unsigned char *proto; + /** + * The length of proto member. + */ + uint8_t len; + /** + * The corresponding SPDY version constant which can be passed to + * `spdylay_session_client_new()` and `spdylay_session_server_new()` + * as version argument. + */ + uint16_t version; +} spdylay_npn_proto; + +/** + * @function + * + * Returns a pointer to the supported SPDY version list. The number of + * elements in the list will be assigned to the |*len_ptr|. It + * contains all SPDY version information this library supports. The + * application can use this information to configure NPN protocol + * offerings/selection. + */ +const spdylay_npn_proto* spdylay_npn_get_proto_list(size_t *len_ptr); + /** * @function * diff --git a/lib/spdylay_npn.c b/lib/spdylay_npn.c index fbbffada..853b5700 100644 --- a/lib/spdylay_npn.c +++ b/lib/spdylay_npn.c @@ -26,21 +26,22 @@ #include -typedef struct { - const unsigned char *proto; - uint8_t len; - uint16_t version; -} spdylay_npn_proto; +static const spdylay_npn_proto proto_list[] = { + { (const unsigned char*)"spdy/3", 6, SPDYLAY_PROTO_SPDY3 }, + { (const unsigned char*)"spdy/2", 6, SPDYLAY_PROTO_SPDY2 } +}; + +const spdylay_npn_proto* spdylay_npn_get_proto_list(size_t *len_ptr) +{ + *len_ptr = sizeof(proto_list)/sizeof(spdylay_npn_proto); + return proto_list; +} int spdylay_select_next_protocol(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen) { int http_selected = 0; unsigned int i = 0; - static const spdylay_npn_proto proto_list[] = { - { (const unsigned char*)"spdy/3", 6, SPDYLAY_PROTO_SPDY3 }, - { (const unsigned char*)"spdy/2", 6, SPDYLAY_PROTO_SPDY2 } - }; for(; i < inlen; i += in[i]+1) { unsigned int j; for(j = 0; j < sizeof(proto_list)/sizeof(spdylay_npn_proto); ++j) { diff --git a/tests/main.c b/tests/main.c index 9aa22709..d9566f64 100644 --- a/tests/main.c +++ b/tests/main.c @@ -74,6 +74,8 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "zlib_spdy2", test_spdylay_zlib_spdy2) || !CU_add_test(pSuite, "zlib_spdy3", test_spdylay_zlib_spdy3) || !CU_add_test(pSuite, "npn", test_spdylay_npn) || + !CU_add_test(pSuite, "npn_get_proto_list", + test_spdylay_npn_get_proto_list) || !CU_add_test(pSuite, "session_recv", test_spdylay_session_recv) || !CU_add_test(pSuite, "session_recv_invalid_stream_id", test_spdylay_session_recv_invalid_stream_id) || diff --git a/tests/spdylay_npn_test.c b/tests/spdylay_npn_test.c index 726da03f..a1de3d4c 100644 --- a/tests/spdylay_npn_test.c +++ b/tests/spdylay_npn_test.c @@ -79,3 +79,17 @@ void test_spdylay_npn(void) http11(); no_overlap(); } + +void test_spdylay_npn_get_proto_list(void) +{ + size_t len; + const spdylay_npn_proto *list = spdylay_npn_get_proto_list(&len); + CU_ASSERT_EQUAL(2, len); + CU_ASSERT_STRING_EQUAL("spdy/3", list[0].proto); + CU_ASSERT_EQUAL(6, list[0].len); + CU_ASSERT_EQUAL(SPDYLAY_PROTO_SPDY3, list[0].version); + + CU_ASSERT_STRING_EQUAL("spdy/2", list[1].proto); + CU_ASSERT_EQUAL(6, list[1].len); + CU_ASSERT_EQUAL(SPDYLAY_PROTO_SPDY2, list[1].version); +} diff --git a/tests/spdylay_npn_test.h b/tests/spdylay_npn_test.h index 890b7d2c..f034e01d 100644 --- a/tests/spdylay_npn_test.h +++ b/tests/spdylay_npn_test.h @@ -26,5 +26,6 @@ #define SPDYLAY_NPN_TEST_H void test_spdylay_npn(void); +void test_spdylay_npn_get_proto_list(void); #endif /* SPDYLAY_NPN_TEST_H */