Sort nv in spdylay_submit_request and spdylay_submit_response

This commit is contained in:
Tatsuhiro Tsujikawa 2012-01-28 00:09:01 +09:00
parent 4c6765e1ed
commit de57b6efea
6 changed files with 41 additions and 1 deletions

View File

@ -337,6 +337,18 @@ char** spdylay_frame_nv_copy(const char **nv)
return nnv;
}
static int spdylay_string_compar(const void *lhs, const void *rhs)
{
return strcmp(*(char **)lhs, *(char **)rhs);
}
void spdylay_frame_nv_sort(char **nv)
{
int n;
for(n = 0; nv[n]; ++n);
qsort(nv, n/2, 2*sizeof(char*), spdylay_string_compar);
}
void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame, uint8_t flags,
int32_t stream_id, int32_t assoc_stream_id,
uint8_t pri, char **nv)

View File

@ -213,4 +213,9 @@ void spdylay_frame_nv_free(char **nv);
*/
char** spdylay_frame_nv_copy(const char **nv);
/*
* Sorts |nv| in the ascending order of name.
*/
void spdylay_frame_nv_sort(char **nv);
#endif /* SPDYLAY_FRAME_H */

View File

@ -1019,6 +1019,7 @@ int spdylay_submit_response(spdylay_session *session,
free(frame);
return SPDYLAY_ERR_NOMEM;
}
spdylay_frame_nv_sort(nv_copy);
if(data_prd == NULL) {
flags |= SPDYLAY_FLAG_FIN;
}
@ -1068,6 +1069,7 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri,
free(frame);
return SPDYLAY_ERR_NOMEM;
}
spdylay_frame_nv_sort(nv_copy);
/* When we support POST using spdylay_data_provider, flags should be
0 if data_prd is set. */
flags |= SPDYLAY_FLAG_FIN;

View File

@ -91,7 +91,8 @@ int main()
test_spdylay_frame_count_nv_space) ||
!CU_add_test(pSuite, "frame_pack_ping", test_spdylay_frame_pack_ping) ||
!CU_add_test(pSuite, "frame_pack_headers",
test_spdylay_frame_pack_headers)) {
test_spdylay_frame_pack_headers) ||
!CU_add_test(pSuite, "frame_nv_sort", test_spdylay_frame_nv_sort)) {
CU_cleanup_registry();
return CU_get_error();
}

View File

@ -99,3 +99,22 @@ void test_spdylay_frame_pack_headers()
spdylay_zlib_inflate_free(&inflater);
spdylay_zlib_deflate_free(&deflater);
}
void test_spdylay_frame_nv_sort()
{
char *nv[7];
nv[0] = (char*)"version";
nv[1] = (char*)"HTTP/1.1";
nv[2] = (char*)"method";
nv[3] = (char*)"GET";
nv[4] = (char*)"scheme";
nv[5] = (char*)"https";
nv[6] = NULL;
spdylay_frame_nv_sort(nv);
CU_ASSERT(strcmp("method", nv[0]) == 0);
CU_ASSERT(strcmp("GET", nv[1]) == 0);
CU_ASSERT(strcmp("scheme", nv[2]) == 0);
CU_ASSERT(strcmp("https", nv[3]) == 0);
CU_ASSERT(strcmp("version", nv[4]) == 0);
CU_ASSERT(strcmp("HTTP/1.1", nv[5]) == 0);
}

View File

@ -29,5 +29,6 @@ void test_spdylay_frame_unpack_nv();
void test_spdylay_frame_count_nv_space();
void test_spdylay_frame_pack_ping();
void test_spdylay_frame_pack_headers();
void test_spdylay_frame_nv_sort();
#endif /* SPDYLAY_FRAME_TEST_H */