From abfc100edbd52ca029e302612447993b7a35836c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 28 Feb 2012 23:38:40 +0900 Subject: [PATCH] Added convenient function spdylay_frame_nv_norm_copy() --- lib/spdylay_frame.c | 11 +++++++++++ lib/spdylay_frame.h | 11 +++++++++++ lib/spdylay_submit.c | 16 ++++------------ tests/spdylay_frame_test.c | 4 +--- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/spdylay_frame.c b/lib/spdylay_frame.c index 9489e46b..dac8a96b 100644 --- a/lib/spdylay_frame.c +++ b/lib/spdylay_frame.c @@ -397,6 +397,17 @@ void spdylay_frame_nv_downcase(char **nv) } } +char** spdylay_frame_nv_norm_copy(const char **nv) +{ + char **nv_copy; + nv_copy = spdylay_frame_nv_copy(nv); + if(nv_copy != NULL) { + spdylay_frame_nv_downcase(nv_copy); + spdylay_frame_nv_sort(nv_copy); + } + return nv_copy; +} + void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame, uint16_t version, uint8_t flags, int32_t stream_id, int32_t assoc_stream_id, diff --git a/lib/spdylay_frame.h b/lib/spdylay_frame.h index 2d10577d..098b5a79 100644 --- a/lib/spdylay_frame.h +++ b/lib/spdylay_frame.h @@ -536,6 +536,17 @@ void spdylay_frame_nv_sort(char **nv); */ void spdylay_frame_nv_downcase(char **nv); +/* + * This function first makes a copy of |nv| using + * spdylay_frame_nv_copy(). If it succeeds, then call + * spdylay_frame_nv_downcase() and spdylay_frame_nv_sort() with the + * copied name/value pairs. + * + * This function returns the copied name/value pairs if it succeeds, + * or NULL. + */ +char** spdylay_frame_nv_norm_copy(const char **nv); + /* * Makes copy of |iv| and return the copy. The |niv| is the number of * entries in |iv|. This function returns the pointer to the copy if diff --git a/lib/spdylay_submit.c b/lib/spdylay_submit.c index 762cd11e..c9078935 100644 --- a/lib/spdylay_submit.c +++ b/lib/spdylay_submit.c @@ -69,15 +69,13 @@ static int spdylay_submit_syn_stream_shared free(data_prd_copy); return SPDYLAY_ERR_NOMEM; } - nv_copy = spdylay_frame_nv_copy(nv); + nv_copy = spdylay_frame_nv_norm_copy(nv); if(nv_copy == NULL) { free(frame); free(aux_data); free(data_prd_copy); return SPDYLAY_ERR_NOMEM; } - spdylay_frame_nv_downcase(nv_copy); - spdylay_frame_nv_sort(nv_copy); flags_copy = 0; if(flags & SPDYLAY_CTRL_FLAG_FIN) { flags_copy |= SPDYLAY_CTRL_FLAG_FIN; @@ -118,13 +116,11 @@ int spdylay_submit_syn_reply(spdylay_session *session, uint8_t flags, if(frame == NULL) { return SPDYLAY_ERR_NOMEM; } - nv_copy = spdylay_frame_nv_copy(nv); + nv_copy = spdylay_frame_nv_norm_copy(nv); if(nv_copy == NULL) { free(frame); return SPDYLAY_ERR_NOMEM; } - spdylay_frame_nv_downcase(nv_copy); - spdylay_frame_nv_sort(nv_copy); flags_copy = 0; if(flags & SPDYLAY_CTRL_FLAG_FIN) { flags_copy |= SPDYLAY_CTRL_FLAG_FIN; @@ -150,13 +146,11 @@ int spdylay_submit_headers(spdylay_session *session, uint8_t flags, if(frame == NULL) { return SPDYLAY_ERR_NOMEM; } - nv_copy = spdylay_frame_nv_copy(nv); + nv_copy = spdylay_frame_nv_norm_copy(nv); if(nv_copy == NULL) { free(frame); return SPDYLAY_ERR_NOMEM; } - spdylay_frame_nv_downcase(nv_copy); - spdylay_frame_nv_sort(nv_copy); flags_copy = 0; if(flags & SPDYLAY_CTRL_FLAG_FIN) { flags_copy |= SPDYLAY_CTRL_FLAG_FIN; @@ -224,14 +218,12 @@ int spdylay_submit_response(spdylay_session *session, free(data_prd_copy); return SPDYLAY_ERR_NOMEM; } - nv_copy = spdylay_frame_nv_copy(nv); + nv_copy = spdylay_frame_nv_norm_copy(nv); if(nv_copy == NULL) { free(frame); free(data_prd_copy); return SPDYLAY_ERR_NOMEM; } - spdylay_frame_nv_downcase(nv_copy); - spdylay_frame_nv_sort(nv_copy); if(data_prd_copy == NULL) { flags |= SPDYLAY_CTRL_FLAG_FIN; } diff --git a/tests/spdylay_frame_test.c b/tests/spdylay_frame_test.c index 3f47db65..26b98ab4 100644 --- a/tests/spdylay_frame_test.c +++ b/tests/spdylay_frame_test.c @@ -83,9 +83,7 @@ void test_spdylay_frame_pack_nv_duplicate_keys() "version", "HTTP/1.1", NULL }; - char **nv = spdylay_frame_nv_copy(nv_src); - spdylay_frame_nv_downcase(nv); - spdylay_frame_nv_sort(nv); + char **nv = spdylay_frame_nv_norm_copy(nv_src); /* size_t inlen = */ spdylay_frame_pack_nv(out, nv, len_size); const uint8_t *outptr = out; int pairs = spdylay_get_uint16(outptr);