Extend namelen and valuelen in nghttp2_nv to size_t

This commit is contained in:
Tatsuhiro Tsujikawa 2014-04-30 23:08:34 +09:00
parent abe74f869f
commit 660c536275
9 changed files with 24 additions and 34 deletions

View File

@ -52,14 +52,12 @@ enum {
};
#define MAKE_NV(NAME, VALUE) \
{(uint8_t*)NAME, (uint8_t*)VALUE, \
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(sizeof(VALUE) - 1), \
NGHTTP2_NV_FLAG_NONE }
{(uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1, \
NGHTTP2_NV_FLAG_NONE}
#define MAKE_NV_CS(NAME, VALUE) \
{(uint8_t*)NAME, (uint8_t*)VALUE, \
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(strlen(VALUE)), \
NGHTTP2_NV_FLAG_NONE }
{(uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, strlen(VALUE), \
NGHTTP2_NV_FLAG_NONE}
struct Connection {
SSL *ssl;

View File

@ -384,11 +384,11 @@ typedef struct {
/**
* The length of the |name|.
*/
uint16_t namelen;
size_t namelen;
/**
* The length of the |value|.
*/
uint16_t valuelen;
size_t valuelen;
/**
* Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
*/

View File

@ -140,8 +140,8 @@ typedef struct {
} nghttp2_nva_out;
int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags,
uint8_t *name, uint16_t namelen,
uint8_t *value, uint16_t valuelen)
uint8_t *name, size_t namelen,
uint8_t *value, size_t valuelen)
{
int rv = 0;
@ -706,7 +706,7 @@ static int emit_indname_block(nghttp2_bufs *bufs, size_t index,
}
DEBUGF(fprintf(stderr,
"deflatehd: emit indname index=%zu, valuelen=%u, "
"deflatehd: emit indname index=%zu, valuelen=%zu, "
"indexing=%d, no_index=%d\n",
index, nv->valuelen, inc_indexing, no_index));
@ -754,7 +754,7 @@ static int emit_newname_block(nghttp2_bufs *bufs, nghttp2_nv *nv,
no_index = (nv->flags & NGHTTP2_NV_FLAG_NO_INDEX) != 0;
DEBUGF(fprintf(stderr,
"deflatehd: emit newname namelen=%u, valuelen=%u, "
"deflatehd: emit newname namelen=%zu, valuelen=%zu, "
"indexing=%d, no_index=%d\n",
nv->namelen, nv->valuelen, inc_indexing, no_index));

View File

@ -195,8 +195,8 @@ struct nghttp2_hd_inflater {
* Out of memory.
*/
int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags,
uint8_t *name, uint16_t namelen,
uint8_t *value, uint16_t valuelen);
uint8_t *name, size_t namelen,
uint8_t *value, size_t valuelen);
void nghttp2_hd_entry_free(nghttp2_hd_entry *ent);

View File

@ -483,7 +483,7 @@ int verbose_on_header_callback(nghttp2_session *session,
{
nghttp2_nv nva = {
const_cast<uint8_t*>(name), const_cast<uint8_t*>(value),
static_cast<uint16_t>(namelen), static_cast<uint16_t>(valuelen)
namelen, valuelen
};
for(auto& nv : http2::sort_nva(&nva, 1)) {

View File

@ -252,7 +252,7 @@ std::vector<nghttp2_nv> sort_nva(const nghttp2_nv *nva, size_t nvlen)
break;
}
auto l = std::find(j, end, '\0');
res.push_back({v[i].name, j, v[i].namelen, static_cast<uint16_t>(l-j)});
res.push_back({v[i].name, j, v[i].namelen, static_cast<size_t>(l - j)});
j = l;
}
}
@ -346,12 +346,8 @@ nghttp2_nv make_nv(const std::string& name, const std::string& value,
flags = no_index ? NGHTTP2_NV_FLAG_NO_INDEX : NGHTTP2_NV_FLAG_NONE;
return {
(uint8_t*)name.c_str(),
(uint8_t*)value.c_str(),
(uint16_t)name.size(), (uint16_t)value.size(),
flags
};
return {(uint8_t*)name.c_str(), (uint8_t*)value.c_str(),
name.size(), value.size(), flags};
}
Headers concat_norm_headers(Headers headers)

View File

@ -160,18 +160,15 @@ nghttp2_nv make_nv(const std::string& name, const std::string& value,
template<size_t N, size_t M>
nghttp2_nv make_nv_ll(const char(&name)[N], const char(&value)[M])
{
return { (uint8_t*)name, (uint8_t*)value,
(uint16_t)(N - 1), (uint16_t)(M - 1),
NGHTTP2_NV_FLAG_NONE };
return {(uint8_t*)name, (uint8_t*)value, N - 1, M - 1, NGHTTP2_NV_FLAG_NONE};
}
// Create nghttp2_nv from string literal |name| and c-string |value|.
template<size_t N>
nghttp2_nv make_nv_lc(const char(&name)[N], const char *value)
{
return { (uint8_t*)name, (uint8_t*)value,
(uint16_t)(N - 1), (uint16_t)strlen(value),
NGHTTP2_NV_FLAG_NONE };
return {(uint8_t*)name, (uint8_t*)value, N - 1, strlen(value),
NGHTTP2_NV_FLAG_NONE};
}
// Create nghttp2_nv from string literal |name| and std::string
@ -179,9 +176,8 @@ nghttp2_nv make_nv_lc(const char(&name)[N], const char *value)
template<size_t N>
nghttp2_nv make_nv_ls(const char(&name)[N], const std::string& value)
{
return { (uint8_t*)name, (uint8_t*)value.c_str(),
(uint16_t)(N - 1), (uint16_t)value.size(),
NGHTTP2_NV_FLAG_NONE };
return {(uint8_t*)name, (uint8_t*)value.c_str(), N - 1, value.size(),
NGHTTP2_NV_FLAG_NONE};
}
// Appends headers in |headers| to |nv|. Certain headers, including

View File

@ -38,8 +38,8 @@
using namespace nghttp2;
#define MAKE_NV(K, V) {(uint8_t*)K, (uint8_t*)V, \
(uint16_t)(sizeof(K)-1), (uint16_t)(sizeof(V)-1), \
NGHTTP2_NV_FLAG_NONE }
sizeof(K) - 1, sizeof(V) - 1, \
NGHTTP2_NV_FLAG_NONE}
namespace shrpx {

View File

@ -569,7 +569,7 @@ void test_nghttp2_nv_array_copy(void)
nghttp2_nv bignv;
bignv.name = (uint8_t*)"echo";
bignv.namelen = (uint16_t)strlen("echo");
bignv.namelen = strlen("echo");
bignv.valuelen = (1 << 14) - 1;
bignv.value = malloc(bignv.valuelen);
memset(bignv.value, '0', bignv.valuelen);