Commit 24cb9080 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Add flags to nghttp2_nv structure

This is preliminary change for upcoming HPACK updates.  The flags are
used to determine the name/value pair is indexable or not.
parent da5db205
......@@ -53,11 +53,13 @@ enum {
#define MAKE_NV(NAME, VALUE) \
{(uint8_t*)NAME, (uint8_t*)VALUE, \
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(sizeof(VALUE) - 1) }
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(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)) }
(uint16_t)(sizeof(NAME) - 1), (uint16_t)(strlen(VALUE)), \
NGHTTP2_NV_FLAG_NONE }
struct Connection {
SSL *ssl;
......
......@@ -381,10 +381,12 @@ static void send_client_connection_header(http2_session_data *session_data)
}
#define MAKE_NV(NAME, VALUE, VALUELEN) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, VALUELEN }
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, VALUELEN, \
NGHTTP2_NV_FLAG_NONE }
#define MAKE_NV2(NAME, VALUE) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1 }
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1, \
NGHTTP2_NV_FLAG_NONE }
/* Send HTTP request to the remote peer */
static void submit_request(http2_session_data *session_data)
......
......@@ -49,7 +49,8 @@
#define ARRLEN(x) (sizeof(x)/sizeof(x[0]))
#define MAKE_NV(NAME, VALUE) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1 }
{ (uint8_t*)NAME, (uint8_t*)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1, \
NGHTTP2_NV_FLAG_NONE }
struct app_context;
typedef struct app_context app_context;
......
......@@ -346,6 +346,22 @@ typedef enum {
NGHTTP2_MSG_MORE
} nghttp2_io_flag;
/**
* @enum
*
* The flags for header field name/value pair.
*/
typedef enum {
/**
* No flag set.
*/
NGHTTP2_NV_FLAG_NONE = 0,
/**
* Indicates that this name/value pair must not be indexed.
*/
NGHTTP2_NV_FLAG_NO_INDEX = 0x1
} nghttp2_nv_flag;
/**
* @struct
*
......@@ -370,6 +386,10 @@ typedef struct {
* The length of the |value|.
*/
uint16_t valuelen;
/**
* Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
*/
uint8_t flags;
} nghttp2_nv;
/**
......
......@@ -919,6 +919,8 @@ ssize_t nghttp2_nv_array_copy(nghttp2_nv **nva_ptr,
data = (uint8_t*)(*nva_ptr) + sizeof(nghttp2_nv)*nvlen;
for(i = 0; i < nvlen; ++i) {
p->flags = nva[i].flags;
memcpy(data, nva[i].name, nva[i].namelen);
p->name = data;
p->namelen = nva[i].namelen;
......
......@@ -34,7 +34,7 @@
/* Make scalar initialization form of nghttp2_nv */
#define MAKE_STATIC_ENT(I, N, V, NH, VH) \
{ { { (uint8_t*)N, (uint8_t*)V, sizeof(N) - 1, sizeof(V) - 1 }, \
{ { { (uint8_t*)N, (uint8_t*)V, sizeof(N) - 1, sizeof(V) - 1, 0 }, \
NH, VH, 1, NGHTTP2_HD_FLAG_NONE }, I }
/* Sorted by hash(name) and its table index */
......@@ -144,6 +144,11 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags,
uint8_t *value, uint16_t valuelen)
{
int rv = 0;
/* Since nghttp2_hd_entry is used for indexing, ent->nv.flags always
NGHTTP2_NV_FLAG_NONE */
ent->nv.flags = NGHTTP2_NV_FLAG_NONE;
if((flags & NGHTTP2_HD_FLAG_NAME_ALLOC) &&
(flags & NGHTTP2_HD_FLAG_NAME_GIFT) == 0) {
if(namelen == 0) {
......@@ -1402,6 +1407,9 @@ static int hd_inflate_commit_newname(nghttp2_hd_inflater *inflater,
return NGHTTP2_ERR_NOMEM;
}
/* Set NGHTTP2_NV_FLAG_NO_INDEX if never indexing repr is used */
nv.flags = NGHTTP2_NV_FLAG_NONE;
if(inflater->index_required) {
nghttp2_hd_entry *new_ent;
uint8_t ent_flags;
......@@ -1455,6 +1463,9 @@ static int hd_inflate_commit_indname(nghttp2_hd_inflater *inflater,
return NGHTTP2_ERR_NOMEM;
}
/* Set NGHTTP2_NV_FLAG_NO_INDEX if never indexing repr is used */
nv.flags = NGHTTP2_NV_FLAG_NONE;
nv.name = inflater->ent_name->nv.name;
nv.namelen = inflater->ent_name->nv.namelen;
......
......@@ -341,7 +341,8 @@ nghttp2_nv make_nv(const std::string& name, const std::string& value)
return {
(uint8_t*)name.c_str(),
(uint8_t*)value.c_str(),
(uint16_t)name.size(), (uint16_t)value.size()
(uint16_t)name.size(), (uint16_t)value.size(),
NGHTTP2_NV_FLAG_NONE
};
}
......
......@@ -130,7 +130,8 @@ 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) };
(uint16_t)(N - 1), (uint16_t)(M - 1),
NGHTTP2_NV_FLAG_NONE };
}
// Create nghttp2_nv from string literal |name| and c-string |value|.
......@@ -138,7 +139,8 @@ 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) };
(uint16_t)(N - 1), (uint16_t)strlen(value),
NGHTTP2_NV_FLAG_NONE };
}
// Create nghttp2_nv from string literal |name| and std::string
......@@ -147,7 +149,8 @@ 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() };
(uint16_t)(N - 1), (uint16_t)value.size(),
NGHTTP2_NV_FLAG_NONE };
}
// Appends headers in |headers| to |nv|. Certain headers, including
......
......@@ -38,7 +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)}
(uint16_t)(sizeof(K)-1), (uint16_t)(sizeof(V)-1), \
NGHTTP2_NV_FLAG_NONE }
namespace shrpx {
......
......@@ -34,7 +34,8 @@
#include "nghttp2_session.h"
#define MAKE_NV(NAME, VALUE) \
{ (uint8_t*)NAME, (uint8_t*)VALUE, strlen(NAME), strlen(VALUE) }
{ (uint8_t*)NAME, (uint8_t*)VALUE, strlen(NAME), strlen(VALUE), \
NGHTTP2_NV_FLAG_NONE }
#define ARRLEN(ARR) (sizeof(ARR)/sizeof(ARR[0]))
#define assert_nv_equal(A, B, len) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment