Added convenient function spdylay_frame_nv_norm_copy()

This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-28 23:38:40 +09:00
parent e79de111a4
commit abfc100edb
4 changed files with 27 additions and 15 deletions

View File

@ -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,

View File

@ -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

View File

@ -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;
}

View File

@ -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);