2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2 - HTTP/2.0 C Library
|
2012-01-24 14:02:24 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#include "nghttp2_frame.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2012-04-05 18:45:39 +02:00
|
|
|
#include <errno.h>
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include "nghttp2_helper.h"
|
|
|
|
#include "nghttp2_net.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
size_t nghttp2_frame_get_len_size(uint16_t version)
|
2012-02-24 17:17:03 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
if(NGHTTP2_PROTO_SPDY2 == version) {
|
2012-02-24 17:17:03 +01:00
|
|
|
return 2;
|
2013-07-12 17:19:03 +02:00
|
|
|
} else if(NGHTTP2_PROTO_SPDY3 == version) {
|
2012-02-24 17:17:03 +01:00
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
/* Unsupported version */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
static uint8_t* nghttp2_pack_str(uint8_t *buf, const char *str, size_t len,
|
2012-02-24 15:05:49 +01:00
|
|
|
size_t len_size)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_put_nv_len(buf, len, len_size);
|
2012-02-24 15:05:49 +01:00
|
|
|
buf += len_size;
|
2012-01-24 14:02:24 +01:00
|
|
|
memcpy(buf, str, len);
|
|
|
|
return buf+len;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
static void nghttp2_frame_pack_ctrl_hd(uint8_t* buf, const nghttp2_ctrl_hd *hd)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint16be(&buf[0], hd->version);
|
2012-01-24 14:02:24 +01:00
|
|
|
buf[0] |= 1 << 7;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint16be(&buf[2], hd->type);
|
|
|
|
nghttp2_put_uint32be(&buf[4], hd->length);
|
2012-01-24 14:02:24 +01:00
|
|
|
buf[4] = hd->flags;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
static void nghttp2_frame_unpack_ctrl_hd(nghttp2_ctrl_hd *hd,
|
2012-01-24 14:02:24 +01:00
|
|
|
const uint8_t* buf)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
hd->version = nghttp2_get_uint16(buf) & NGHTTP2_VERSION_MASK;
|
|
|
|
hd->type = nghttp2_get_uint16(&buf[2]);
|
2012-01-24 14:02:24 +01:00
|
|
|
hd->flags = buf[4];
|
2013-07-12 17:19:03 +02:00
|
|
|
hd->length = nghttp2_get_uint32(&buf[4]) & NGHTTP2_LENGTH_MASK;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_alloc_pack_nv(uint8_t **buf_ptr,
|
2012-03-01 15:52:15 +01:00
|
|
|
size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
|
|
|
char **nv, size_t nv_offset,
|
|
|
|
size_t len_size,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_zlib *deflater)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2012-02-16 12:54:30 +01:00
|
|
|
size_t nvspace;
|
|
|
|
size_t maxframelen;
|
2012-01-24 14:02:24 +01:00
|
|
|
ssize_t framelen;
|
2012-02-16 12:54:30 +01:00
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
nvspace = nghttp2_frame_count_nv_space(nv, len_size);
|
|
|
|
r = nghttp2_reserve_buffer(nvbuf_ptr, nvbuflen_ptr, nvspace);
|
2012-02-16 12:54:30 +01:00
|
|
|
if(r != 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-02-16 12:54:30 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
maxframelen = nv_offset+nghttp2_zlib_deflate_hd_bound(deflater, nvspace);
|
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, maxframelen);
|
2012-02-16 12:54:30 +01:00
|
|
|
if(r != 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-02-16 12:54:30 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_nv(*nvbuf_ptr, nv, len_size);
|
|
|
|
framelen = nghttp2_zlib_deflate_hd(deflater,
|
2012-02-16 12:54:30 +01:00
|
|
|
(*buf_ptr)+nv_offset,
|
2012-01-25 13:31:28 +01:00
|
|
|
maxframelen-nv_offset,
|
2012-02-16 12:54:30 +01:00
|
|
|
*nvbuf_ptr, nvspace);
|
2012-01-24 14:02:24 +01:00
|
|
|
if(framelen < 0) {
|
|
|
|
return framelen;
|
|
|
|
}
|
2012-01-25 13:31:28 +01:00
|
|
|
framelen += nv_offset;
|
2012-09-14 15:41:55 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
if(framelen - NGHTTP2_FRAME_HEAD_LENGTH > NGHTTP2_LENGTH_MASK) {
|
2012-09-14 15:41:55 +02:00
|
|
|
/* In SPDY/2 and 3, Max frame size is 2**24 - 1. */
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_FRAME_TOO_LARGE;
|
2012-09-14 15:41:55 +02:00
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_buffer *in, size_t len_size)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2012-02-24 15:05:49 +01:00
|
|
|
uint32_t n;
|
2012-02-04 15:09:03 +01:00
|
|
|
size_t buflen = 0;
|
|
|
|
size_t nvlen = 0;
|
|
|
|
size_t off = 0;
|
2013-07-12 17:19:03 +02:00
|
|
|
size_t inlen = nghttp2_buffer_length(in);
|
2012-03-22 18:17:48 +01:00
|
|
|
size_t i;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader reader;
|
2012-02-04 15:09:03 +01:00
|
|
|
if(inlen < len_size) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader_init(&reader, in);
|
2012-05-25 03:46:40 +02:00
|
|
|
|
2012-02-24 15:05:49 +01:00
|
|
|
/* TODO limit n in a reasonable number */
|
2013-07-12 17:19:03 +02:00
|
|
|
n = nghttp2_frame_get_nv_len(&reader, len_size);
|
2012-02-04 15:09:03 +01:00
|
|
|
off += len_size;
|
|
|
|
for(i = 0; i < n; ++i) {
|
2012-02-24 15:05:49 +01:00
|
|
|
uint32_t len;
|
2012-03-22 18:17:48 +01:00
|
|
|
size_t j;
|
2012-02-04 15:09:03 +01:00
|
|
|
for(j = 0; j < 2; ++j) {
|
|
|
|
if(inlen-off < len_size) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
len = nghttp2_frame_get_nv_len(&reader, len_size);
|
2012-02-24 15:05:49 +01:00
|
|
|
off += len_size;
|
2012-02-04 15:09:03 +01:00
|
|
|
if(inlen-off < len) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-02-04 15:09:03 +01:00
|
|
|
}
|
|
|
|
buflen += len+1;
|
|
|
|
off += len;
|
2012-05-25 03:46:40 +02:00
|
|
|
if(j == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader_advance(&reader, len);
|
2012-05-25 03:46:40 +02:00
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nvlen += nghttp2_buffer_reader_count(&reader, len, '\0');
|
2012-02-04 15:09:03 +01:00
|
|
|
++nvlen;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
2012-02-18 09:25:13 +01:00
|
|
|
if(inlen == off) {
|
|
|
|
*nvlen_ptr = nvlen;
|
|
|
|
*buflen_ptr = buflen+(nvlen*2+1)*sizeof(char*);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-02-18 09:25:13 +01:00
|
|
|
}
|
2012-02-04 15:09:03 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_nv(char ***nv_ptr, nghttp2_buffer *in,
|
2012-02-24 15:05:49 +01:00
|
|
|
size_t len_size)
|
2012-02-04 15:09:03 +01:00
|
|
|
{
|
|
|
|
size_t nvlen, buflen;
|
2012-03-22 18:17:48 +01:00
|
|
|
int r;
|
|
|
|
size_t i;
|
2012-05-20 10:40:29 +02:00
|
|
|
char *buf, **idx, *data;
|
2012-02-24 15:05:49 +01:00
|
|
|
uint32_t n;
|
2012-03-26 16:19:58 +02:00
|
|
|
int invalid_header_block = 0;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader reader;
|
|
|
|
r = nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, in, len_size);
|
2012-02-04 15:09:03 +01:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
|
|
|
}
|
2012-05-25 03:46:40 +02:00
|
|
|
|
2012-02-04 15:09:03 +01:00
|
|
|
buf = malloc(buflen);
|
|
|
|
if(buf == NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-02-04 15:09:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader_init(&reader, in);
|
2012-05-20 10:40:29 +02:00
|
|
|
idx = (char**)buf;
|
2012-02-04 15:09:03 +01:00
|
|
|
data = buf+(nvlen*2+1)*sizeof(char*);
|
2013-07-12 17:19:03 +02:00
|
|
|
n = nghttp2_frame_get_nv_len(&reader, len_size);
|
2012-02-04 15:09:03 +01:00
|
|
|
for(i = 0; i < n; ++i) {
|
2012-02-24 15:05:49 +01:00
|
|
|
uint32_t len;
|
2012-02-04 15:09:03 +01:00
|
|
|
char *name, *val;
|
|
|
|
char *stop;
|
2013-03-23 10:11:21 +01:00
|
|
|
int multival;
|
2013-07-12 17:19:03 +02:00
|
|
|
len = nghttp2_frame_get_nv_len(&reader, len_size);
|
2012-05-25 03:46:40 +02:00
|
|
|
if(len == 0) {
|
|
|
|
invalid_header_block = 1;
|
|
|
|
}
|
2012-02-04 15:09:03 +01:00
|
|
|
name = data;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader_data(&reader, (uint8_t*)data, len);
|
2012-05-25 03:46:40 +02:00
|
|
|
for(stop = data+len; data != stop; ++data) {
|
|
|
|
unsigned char c = *data;
|
|
|
|
if(c < 0x20 || c > 0x7e || ('A' <= c && c <= 'Z')) {
|
|
|
|
invalid_header_block = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-02-04 15:09:03 +01:00
|
|
|
*data = '\0';
|
|
|
|
++data;
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
len = nghttp2_frame_get_nv_len(&reader, len_size);
|
2012-02-04 15:09:03 +01:00
|
|
|
val = data;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer_reader_data(&reader, (uint8_t*)data, len);
|
2012-02-04 15:09:03 +01:00
|
|
|
|
2013-03-23 10:11:21 +01:00
|
|
|
multival = 0;
|
2012-02-04 15:09:03 +01:00
|
|
|
for(stop = data+len; data != stop; ++data) {
|
|
|
|
if(*data == '\0') {
|
2012-05-20 10:40:29 +02:00
|
|
|
*idx++ = name;
|
|
|
|
*idx++ = val;
|
2012-03-26 16:19:58 +02:00
|
|
|
if(val == data) {
|
|
|
|
invalid_header_block = 1;
|
|
|
|
}
|
2012-02-04 15:09:03 +01:00
|
|
|
val = data+1;
|
2013-03-23 10:11:21 +01:00
|
|
|
multival = 1;
|
2012-02-04 15:09:03 +01:00
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
2012-02-04 15:09:03 +01:00
|
|
|
*data = '\0';
|
2013-03-23 10:11:21 +01:00
|
|
|
/* Check last header value is empty if NULL separator was
|
|
|
|
found. */
|
|
|
|
if(multival && val == data) {
|
|
|
|
invalid_header_block = 1;
|
|
|
|
}
|
2012-02-04 15:09:03 +01:00
|
|
|
++data;
|
|
|
|
|
2012-05-20 10:40:29 +02:00
|
|
|
*idx++ = name;
|
|
|
|
*idx++ = val;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
2012-05-20 10:40:29 +02:00
|
|
|
*idx = NULL;
|
|
|
|
assert((size_t)((char*)idx - buf) == (nvlen*2)*sizeof(char*));
|
2012-02-04 15:09:03 +01:00
|
|
|
*nv_ptr = (char**)buf;
|
2012-05-25 03:46:40 +02:00
|
|
|
if(!invalid_header_block) {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_nv_sort(*nv_ptr);
|
2012-05-25 03:46:40 +02:00
|
|
|
for(i = 2; i < nvlen*2; i += 2) {
|
|
|
|
if(strcmp((*nv_ptr)[i-2], (*nv_ptr)[i]) == 0 &&
|
|
|
|
(*nv_ptr)[i-2] != (*nv_ptr)[i]) {
|
|
|
|
invalid_header_block = 1;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
return invalid_header_block ? NGHTTP2_ERR_INVALID_HEADER_BLOCK : 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
size_t nghttp2_frame_count_nv_space(char **nv, size_t len_size)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2012-02-24 15:05:49 +01:00
|
|
|
size_t sum = len_size;
|
2012-01-24 14:02:24 +01:00
|
|
|
int i;
|
|
|
|
const char *prev = "";
|
|
|
|
size_t prevlen = 0;
|
2013-03-23 11:31:22 +01:00
|
|
|
size_t prevvallen = 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
for(i = 0; nv[i]; i += 2) {
|
|
|
|
const char *key = nv[i];
|
|
|
|
const char *val = nv[i+1];
|
|
|
|
size_t keylen = strlen(key);
|
|
|
|
size_t vallen = strlen(val);
|
|
|
|
if(prevlen == keylen && memcmp(prev, key, keylen) == 0) {
|
2013-03-23 11:31:22 +01:00
|
|
|
if(vallen) {
|
|
|
|
if(prevvallen) {
|
|
|
|
/* Join previous value, with NULL character */
|
|
|
|
sum += vallen+1;
|
|
|
|
prevvallen = vallen;
|
|
|
|
} else {
|
|
|
|
/* Previous value is empty. In this case, drop the
|
|
|
|
previous. */
|
|
|
|
sum += vallen;
|
|
|
|
}
|
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
} else {
|
|
|
|
prev = key;
|
2012-02-18 09:25:13 +01:00
|
|
|
prevlen = keylen;
|
2013-03-23 11:31:22 +01:00
|
|
|
prevvallen = vallen;
|
2012-01-24 14:02:24 +01:00
|
|
|
/* SPDY NV header does not include terminating NULL byte */
|
2012-02-24 15:05:49 +01:00
|
|
|
sum += keylen+vallen+len_size*2;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
|
|
|
int i;
|
2012-02-24 15:05:49 +01:00
|
|
|
uint8_t *bufp = buf+len_size;
|
|
|
|
uint32_t num_nv = 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
const char *prev = "";
|
2013-03-23 11:31:22 +01:00
|
|
|
uint8_t *cur_vallen_buf = NULL;
|
|
|
|
uint32_t cur_vallen = 0;
|
|
|
|
size_t prevkeylen = 0;
|
|
|
|
size_t prevvallen = 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
for(i = 0; nv[i]; i += 2) {
|
|
|
|
const char *key = nv[i];
|
|
|
|
const char *val = nv[i+1];
|
|
|
|
size_t keylen = strlen(key);
|
|
|
|
size_t vallen = strlen(val);
|
2013-03-23 11:31:22 +01:00
|
|
|
if(prevkeylen == keylen && memcmp(prev, key, keylen) == 0) {
|
|
|
|
if(vallen) {
|
|
|
|
if(prevvallen) {
|
|
|
|
/* Join previous value, with NULL character */
|
|
|
|
cur_vallen += vallen+1;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_put_nv_len(cur_vallen_buf, cur_vallen, len_size);
|
2013-03-23 11:31:22 +01:00
|
|
|
*bufp = '\0';
|
|
|
|
++bufp;
|
|
|
|
memcpy(bufp, val, vallen);
|
|
|
|
bufp += vallen;
|
|
|
|
} else {
|
|
|
|
/* Previous value is empty. In this case, drop the
|
|
|
|
previous. */
|
|
|
|
cur_vallen += vallen;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_put_nv_len(cur_vallen_buf, cur_vallen, len_size);
|
2013-03-23 11:31:22 +01:00
|
|
|
memcpy(bufp, val, vallen);
|
|
|
|
bufp += vallen;
|
|
|
|
}
|
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
} else {
|
|
|
|
++num_nv;
|
2013-07-12 17:19:03 +02:00
|
|
|
bufp = nghttp2_pack_str(bufp, key, keylen, len_size);
|
2012-01-24 14:02:24 +01:00
|
|
|
prev = key;
|
2013-03-23 11:31:22 +01:00
|
|
|
cur_vallen_buf = bufp;
|
|
|
|
cur_vallen = vallen;
|
|
|
|
prevkeylen = keylen;
|
|
|
|
prevvallen = vallen;
|
2013-07-12 17:19:03 +02:00
|
|
|
bufp = nghttp2_pack_str(bufp, val, vallen, len_size);
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_put_nv_len(buf, num_nv, len_size);
|
2012-01-24 14:02:24 +01:00
|
|
|
return bufp-buf;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_is_ctrl_frame(uint8_t first_byte)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
|
|
|
return first_byte & 0x80;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_nv_del(char **nv)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2012-02-04 15:09:03 +01:00
|
|
|
free(nv);
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
char** nghttp2_frame_nv_copy(const char **nv)
|
2012-01-26 17:17:40 +01:00
|
|
|
{
|
2012-02-04 15:09:03 +01:00
|
|
|
int i;
|
|
|
|
char *buf;
|
2012-05-20 10:40:29 +02:00
|
|
|
char **idx, *data;
|
2012-02-04 15:09:03 +01:00
|
|
|
size_t buflen = 0;
|
|
|
|
for(i = 0; nv[i]; ++i) {
|
|
|
|
buflen += strlen(nv[i])+1;
|
|
|
|
}
|
|
|
|
buflen += (i+1)*sizeof(char*);
|
|
|
|
buf = malloc(buflen);
|
|
|
|
if(buf == NULL) {
|
2012-01-26 17:17:40 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-20 10:40:29 +02:00
|
|
|
idx = (char**)buf;
|
2012-02-04 15:09:03 +01:00
|
|
|
data = buf+(i+1)*sizeof(char*);
|
|
|
|
|
|
|
|
for(i = 0; nv[i]; ++i) {
|
|
|
|
size_t len = strlen(nv[i])+1;
|
|
|
|
memcpy(data, nv[i], len);
|
2012-05-20 10:40:29 +02:00
|
|
|
*idx++ = data;
|
2012-02-04 15:09:03 +01:00
|
|
|
data += len;
|
2012-01-26 17:17:40 +01:00
|
|
|
}
|
2012-05-20 10:40:29 +02:00
|
|
|
*idx = NULL;
|
2012-02-04 15:09:03 +01:00
|
|
|
return (char**)buf;
|
2012-01-26 17:17:40 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
static int nghttp2_string_compar(const void *lhs, const void *rhs)
|
2012-01-27 16:09:01 +01:00
|
|
|
{
|
|
|
|
return strcmp(*(char **)lhs, *(char **)rhs);
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_nv_sort(char **nv)
|
2012-01-27 16:09:01 +01:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
for(n = 0; nv[n]; ++n);
|
2013-07-12 17:19:03 +02:00
|
|
|
qsort(nv, n/2, 2*sizeof(char*), nghttp2_string_compar);
|
2012-01-27 16:09:01 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_nv_downcase(char **nv)
|
2012-02-15 15:54:42 +01:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for(i = 0; nv[i]; i += 2) {
|
|
|
|
for(j = 0; nv[i][j] != '\0'; ++j) {
|
|
|
|
if('A' <= nv[i][j] && nv[i][j] <= 'Z') {
|
|
|
|
nv[i][j] += 'a'-'A';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
char** nghttp2_frame_nv_norm_copy(const char **nv)
|
2012-02-28 15:38:40 +01:00
|
|
|
{
|
|
|
|
char **nv_copy;
|
2013-07-12 17:19:03 +02:00
|
|
|
nv_copy = nghttp2_frame_nv_copy(nv);
|
2012-02-28 15:38:40 +01:00
|
|
|
if(nv_copy != NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_nv_downcase(nv_copy);
|
|
|
|
nghttp2_frame_nv_sort(nv_copy);
|
2012-02-28 15:38:40 +01:00
|
|
|
}
|
|
|
|
return nv_copy;
|
|
|
|
}
|
|
|
|
|
2012-03-06 15:43:45 +01:00
|
|
|
/* Table to translate SPDY/3 header names to SPDY/2. */
|
2013-07-12 17:19:03 +02:00
|
|
|
static const char *nghttp2_nv_3to2[] = {
|
2012-03-06 15:43:45 +01:00
|
|
|
":host", "host",
|
|
|
|
":method", "method",
|
|
|
|
":path", "url",
|
|
|
|
":scheme", "scheme",
|
|
|
|
":status", "status",
|
|
|
|
":version", "version",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_nv_3to2(char **nv)
|
2012-03-06 15:43:45 +01:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for(i = 0; nv[i]; i += 2) {
|
2013-07-12 17:19:03 +02:00
|
|
|
for(j = 0; nghttp2_nv_3to2[j]; j += 2) {
|
|
|
|
if(strcmp(nv[i], nghttp2_nv_3to2[j]) == 0) {
|
|
|
|
nv[i] = (char*)nghttp2_nv_3to2[j+1];
|
2012-03-06 15:43:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_nv_2to3(char **nv)
|
2012-03-06 15:43:45 +01:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for(i = 0; nv[i]; i += 2) {
|
2013-07-12 17:19:03 +02:00
|
|
|
for(j = 0; nghttp2_nv_3to2[j]; j += 2) {
|
|
|
|
if(strcmp(nv[i], nghttp2_nv_3to2[j+1]) == 0) {
|
|
|
|
nv[i] = (char*)nghttp2_nv_3to2[j];
|
2012-03-06 15:43:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_HTTPS_PORT 443
|
2012-04-05 18:45:39 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_nv_set_origin(char **nv, nghttp2_origin *origin)
|
2012-04-05 18:45:39 +02:00
|
|
|
{
|
|
|
|
int scheme_found, host_found;
|
|
|
|
int i;
|
|
|
|
scheme_found = host_found = 0;
|
|
|
|
for(i = 0; nv[i]; i += 2) {
|
|
|
|
if(scheme_found == 0 && strcmp(":scheme", nv[i]) == 0) {
|
|
|
|
size_t len = strlen(nv[i+1]);
|
2013-07-12 17:19:03 +02:00
|
|
|
if(len <= NGHTTP2_MAX_SCHEME) {
|
2012-04-05 18:45:39 +02:00
|
|
|
strcpy(origin->scheme, nv[i+1]);
|
|
|
|
scheme_found = 1;
|
|
|
|
}
|
|
|
|
} else if(host_found == 0 && strcmp(":host", nv[i]) == 0) {
|
|
|
|
size_t len = strlen(nv[i+1]);
|
|
|
|
char *sep = memchr(nv[i+1], ':', len);
|
|
|
|
size_t hostlen;
|
|
|
|
if(sep == NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
origin->port = NGHTTP2_HTTPS_PORT;
|
2012-04-05 18:45:39 +02:00
|
|
|
sep = nv[i+1]+len;
|
|
|
|
} else {
|
|
|
|
unsigned long int port;
|
|
|
|
errno = 0;
|
|
|
|
port = strtoul(sep+1, NULL, 10);
|
|
|
|
if(errno != 0 || port == 0 || port > UINT16_MAX) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
origin->port = port;
|
|
|
|
}
|
|
|
|
hostlen = sep-nv[i+1];
|
2013-07-12 17:19:03 +02:00
|
|
|
if(hostlen > NGHTTP2_MAX_HOSTNAME) {
|
2012-04-05 18:45:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memcpy(origin->host, nv[i+1], hostlen);
|
|
|
|
origin->host[hostlen] = '\0';
|
|
|
|
host_found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(scheme_found && host_found) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_syn_stream_init(nghttp2_syn_stream *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version, uint8_t flags,
|
2012-01-24 14:02:24 +01:00
|
|
|
int32_t stream_id, int32_t assoc_stream_id,
|
|
|
|
uint8_t pri, char **nv)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_syn_stream));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_SYN_STREAM;
|
2012-01-24 14:02:24 +01:00
|
|
|
frame->hd.flags = flags;
|
|
|
|
frame->stream_id = stream_id;
|
|
|
|
frame->assoc_stream_id = assoc_stream_id;
|
|
|
|
frame->pri = pri;
|
|
|
|
frame->nv = nv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_syn_stream_free(nghttp2_syn_stream *frame)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_nv_del(frame->nv);
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_syn_reply_init(nghttp2_syn_reply *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version, uint8_t flags,
|
2012-01-25 13:31:28 +01:00
|
|
|
int32_t stream_id, char **nv)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_syn_reply));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_SYN_REPLY;
|
2012-01-25 13:31:28 +01:00
|
|
|
frame->hd.flags = flags;
|
|
|
|
frame->stream_id = stream_id;
|
|
|
|
frame->nv = nv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_syn_reply_free(nghttp2_syn_reply *frame)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_nv_del(frame->nv);
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_ping_init(nghttp2_ping *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version, uint32_t unique_id)
|
2012-01-27 11:35:05 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_ping));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_PING;
|
|
|
|
frame->hd.flags = NGHTTP2_CTRL_FLAG_NONE;
|
2012-01-27 11:35:05 +01:00
|
|
|
frame->hd.length = 4;
|
|
|
|
frame->unique_id = unique_id;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_ping_free(nghttp2_ping *frame)
|
2012-01-27 11:35:05 +01:00
|
|
|
{}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_goaway_init(nghttp2_goaway *frame,
|
2012-02-26 08:26:38 +01:00
|
|
|
uint16_t version, int32_t last_good_stream_id,
|
|
|
|
uint32_t status_code)
|
2012-01-28 11:22:38 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_goaway));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_GOAWAY;
|
|
|
|
if(version == NGHTTP2_PROTO_SPDY2) {
|
2012-02-25 17:48:18 +01:00
|
|
|
frame->hd.length = 4;
|
2013-07-12 17:19:03 +02:00
|
|
|
} else if(version == NGHTTP2_PROTO_SPDY3) {
|
2012-02-25 17:48:18 +01:00
|
|
|
frame->hd.length = 8;
|
2012-02-26 08:26:38 +01:00
|
|
|
frame->status_code = status_code;
|
2012-02-25 17:48:18 +01:00
|
|
|
} else {
|
|
|
|
frame->hd.length = 0;
|
|
|
|
}
|
2012-01-28 11:22:38 +01:00
|
|
|
frame->last_good_stream_id = last_good_stream_id;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_goaway_free(nghttp2_goaway *frame)
|
2012-01-28 11:22:38 +01:00
|
|
|
{}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_headers_init(nghttp2_headers *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version, uint8_t flags,
|
2012-01-27 10:21:14 +01:00
|
|
|
int32_t stream_id, char **nv)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_headers));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_HEADERS;
|
2012-01-27 10:21:14 +01:00
|
|
|
frame->hd.flags = flags;
|
|
|
|
frame->stream_id = stream_id;
|
|
|
|
frame->nv = nv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_headers_free(nghttp2_headers *frame)
|
2012-01-27 10:21:14 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_nv_del(frame->nv);
|
2012-01-27 10:21:14 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version,
|
2012-01-25 13:31:28 +01:00
|
|
|
int32_t stream_id, uint32_t status_code)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_rst_stream));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_RST_STREAM;
|
2012-01-25 13:31:28 +01:00
|
|
|
frame->hd.flags = 0;
|
|
|
|
frame->hd.length = 8;
|
|
|
|
frame->stream_id = stream_id;
|
|
|
|
frame->status_code = status_code;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame)
|
2012-01-25 13:31:28 +01:00
|
|
|
{}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
|
2012-02-24 17:47:37 +01:00
|
|
|
uint16_t version,
|
|
|
|
int32_t stream_id,
|
|
|
|
int32_t delta_window_size)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_window_update));
|
2012-02-24 17:47:37 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_WINDOW_UPDATE;
|
2012-02-24 17:47:37 +01:00
|
|
|
frame->hd.flags = 0;
|
|
|
|
frame->hd.length = 8;
|
|
|
|
frame->stream_id = stream_id;
|
|
|
|
frame->delta_window_size = delta_window_size;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_window_update_free(nghttp2_window_update *frame)
|
2012-02-24 17:47:37 +01:00
|
|
|
{}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_settings_init(nghttp2_settings *frame,
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version, uint8_t flags,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_settings_entry *iv, size_t niv)
|
2012-01-31 16:26:26 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_settings));
|
2012-02-24 15:33:06 +01:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_SETTINGS;
|
2012-01-31 16:26:26 +01:00
|
|
|
frame->hd.flags = flags;
|
|
|
|
frame->hd.length = 4+niv*8;
|
|
|
|
frame->niv = niv;
|
|
|
|
frame->iv = iv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_settings_free(nghttp2_settings *frame)
|
2012-01-31 16:26:26 +01:00
|
|
|
{
|
|
|
|
free(frame->iv);
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_credential_init(nghttp2_credential *frame,
|
2012-04-05 18:45:39 +02:00
|
|
|
uint16_t version, uint16_t slot,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_mem_chunk *proof,
|
|
|
|
nghttp2_mem_chunk *certs,
|
2012-04-05 18:45:39 +02:00
|
|
|
size_t ncerts)
|
|
|
|
{
|
|
|
|
size_t i;
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_credential));
|
2012-04-05 18:45:39 +02:00
|
|
|
frame->hd.version = version;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.type = NGHTTP2_CREDENTIAL;
|
2012-04-05 18:45:39 +02:00
|
|
|
frame->slot = slot;
|
|
|
|
frame->proof = *proof;
|
|
|
|
frame->certs = certs;
|
|
|
|
frame->ncerts = ncerts;
|
|
|
|
frame->hd.length = 2+4+frame->proof.length;
|
|
|
|
for(i = 0; i < ncerts; ++i) {
|
|
|
|
frame->hd.length += 4+frame->certs[i].length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_credential_free(nghttp2_credential *frame)
|
2012-04-05 18:45:39 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
free(frame->proof.data);
|
|
|
|
for(i = 0; i < frame->ncerts; ++i) {
|
|
|
|
free(frame->certs[i].data);
|
|
|
|
}
|
|
|
|
free(frame->certs);
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_data_init(nghttp2_data *frame, int32_t stream_id,
|
2012-02-23 15:22:58 +01:00
|
|
|
uint8_t flags,
|
2013-07-12 17:19:03 +02:00
|
|
|
const nghttp2_data_provider *data_prd)
|
2012-01-26 17:17:40 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
memset(frame, 0, sizeof(nghttp2_data));
|
2012-01-26 17:17:40 +01:00
|
|
|
frame->stream_id = stream_id;
|
2012-02-15 15:02:51 +01:00
|
|
|
frame->flags = flags;
|
2012-01-26 17:17:40 +01:00
|
|
|
frame->data_prd = *data_prd;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_data_free(nghttp2_data *frame)
|
2012-01-26 17:17:40 +01:00
|
|
|
{}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_syn_stream(uint8_t **buf_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_syn_stream *frame,
|
|
|
|
nghttp2_zlib *deflater)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
2012-01-26 17:17:40 +01:00
|
|
|
ssize_t framelen;
|
2013-07-12 17:19:03 +02:00
|
|
|
size_t len_size = nghttp2_frame_get_len_size(frame->hd.version);
|
2012-02-24 17:17:03 +01:00
|
|
|
if(len_size == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
framelen = nghttp2_frame_alloc_pack_nv(buf_ptr, buflen_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
nvbuf_ptr, nvbuflen_ptr,
|
|
|
|
frame->nv,
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_SYN_STREAM_NV_OFFSET,
|
2012-02-24 17:17:03 +01:00
|
|
|
len_size,
|
2012-01-27 10:28:29 +01:00
|
|
|
deflater);
|
2012-01-24 14:02:24 +01:00
|
|
|
if(framelen < 0) {
|
|
|
|
return framelen;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.length = framelen-NGHTTP2_FRAME_HEAD_LENGTH;
|
|
|
|
memset(*buf_ptr, 0, NGHTTP2_SYN_STREAM_NV_OFFSET);
|
2012-01-24 14:02:24 +01:00
|
|
|
/* pack ctrl header after length is determined */
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[12], frame->assoc_stream_id);
|
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY3) {
|
2013-01-20 11:04:04 +01:00
|
|
|
(*buf_ptr)[16] = (frame->pri << 5);
|
2012-02-24 17:17:03 +01:00
|
|
|
(*buf_ptr)[17] = frame->slot;
|
2013-01-20 11:04:04 +01:00
|
|
|
} else {
|
|
|
|
(*buf_ptr)[16] = (frame->pri << 6);
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2012-01-24 14:02:24 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_syn_stream(nghttp2_syn_stream *frame,
|
2012-01-24 14:02:24 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer *inflatebuf)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
|
|
|
int r;
|
2012-02-24 17:17:03 +01:00
|
|
|
size_t len_size;
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_frame_unpack_syn_stream_without_nv(frame, head, headlen,
|
2012-05-25 06:49:18 +02:00
|
|
|
payload, payloadlen);
|
2013-07-12 17:19:03 +02:00
|
|
|
len_size = nghttp2_frame_get_len_size(frame->hd.version);
|
2012-02-24 17:17:03 +01:00
|
|
|
if(len_size == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2012-05-25 06:49:18 +02:00
|
|
|
if(r == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_frame_unpack_nv(&frame->nv, inflatebuf, len_size);
|
2012-05-25 06:49:18 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_syn_stream_without_nv(nghttp2_syn_stream *frame,
|
2012-05-25 06:49:18 +02:00
|
|
|
const uint8_t *head,
|
|
|
|
size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
if(headlen + payloadlen != NGHTTP2_SYN_STREAM_NV_OFFSET) {
|
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-05-25 06:49:18 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
|
2012-01-25 13:35:48 +01:00
|
|
|
frame->assoc_stream_id =
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_get_uint32(payload+4) & NGHTTP2_STREAM_ID_MASK;
|
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY3) {
|
2013-01-20 11:04:04 +01:00
|
|
|
frame->pri = (*(payload+8) >> 5);
|
2012-02-24 17:17:03 +01:00
|
|
|
frame->slot = payload[9];
|
|
|
|
} else {
|
2013-01-20 11:04:04 +01:00
|
|
|
frame->pri = (*(payload+8) >> 6);
|
2012-02-24 17:17:03 +01:00
|
|
|
frame->slot = 0;
|
|
|
|
}
|
2012-05-25 06:49:18 +02:00
|
|
|
frame->nv = NULL;
|
|
|
|
return 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_syn_reply(uint8_t **buf_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
size_t *buflen_ptr,
|
|
|
|
uint8_t **nvbuf_ptr,
|
|
|
|
size_t *nvbuflen_ptr,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_syn_reply *frame,
|
|
|
|
nghttp2_zlib *deflater)
|
2012-01-25 13:31:28 +01:00
|
|
|
{
|
2012-01-26 17:17:40 +01:00
|
|
|
ssize_t framelen;
|
2012-02-24 17:17:03 +01:00
|
|
|
size_t len_size;
|
2012-05-25 03:46:40 +02:00
|
|
|
ssize_t nv_offset;
|
2013-07-12 17:19:03 +02:00
|
|
|
len_size = nghttp2_frame_get_len_size(frame->hd.version);
|
2012-02-24 17:17:03 +01:00
|
|
|
if(len_size == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nv_offset = nghttp2_frame_nv_offset(NGHTTP2_SYN_REPLY, frame->hd.version);
|
2012-05-25 03:46:40 +02:00
|
|
|
assert(nv_offset > 0);
|
2013-07-12 17:19:03 +02:00
|
|
|
framelen = nghttp2_frame_alloc_pack_nv(buf_ptr, buflen_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
nvbuf_ptr, nvbuflen_ptr,
|
2012-02-24 17:17:03 +01:00
|
|
|
frame->nv, nv_offset,
|
|
|
|
len_size, deflater);
|
2012-01-25 13:31:28 +01:00
|
|
|
if(framelen < 0) {
|
|
|
|
return framelen;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.length = framelen-NGHTTP2_FRAME_HEAD_LENGTH;
|
2012-02-24 17:17:03 +01:00
|
|
|
memset(*buf_ptr, 0, nv_offset);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id);
|
2012-01-25 13:31:28 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_syn_reply(nghttp2_syn_reply *frame,
|
2012-01-24 14:02:24 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer *inflatebuf)
|
2012-01-24 14:02:24 +01:00
|
|
|
{
|
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_frame_unpack_syn_reply_without_nv(frame, head, headlen,
|
2012-05-25 06:49:18 +02:00
|
|
|
payload, payloadlen);
|
|
|
|
if(r == 0) {
|
|
|
|
size_t len_size;
|
2013-07-12 17:19:03 +02:00
|
|
|
len_size = nghttp2_frame_get_len_size(frame->hd.version);
|
2012-05-25 06:49:18 +02:00
|
|
|
if(len_size == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-05-25 06:49:18 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_frame_unpack_nv(&frame->nv, inflatebuf, len_size);
|
2012-05-25 06:49:18 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_syn_reply_without_nv(nghttp2_syn_reply *frame,
|
2012-05-25 06:49:18 +02:00
|
|
|
const uint8_t *head,
|
|
|
|
size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen)
|
|
|
|
{
|
2012-05-25 03:46:40 +02:00
|
|
|
ssize_t nv_offset;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
nv_offset = nghttp2_frame_nv_offset(NGHTTP2_SYN_REPLY, frame->hd.version);
|
2012-05-25 03:46:40 +02:00
|
|
|
assert(nv_offset > 0);
|
|
|
|
if((ssize_t)(headlen + payloadlen) != nv_offset) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-05-25 03:46:40 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
|
2012-05-25 06:49:18 +02:00
|
|
|
frame->nv = NULL;
|
|
|
|
return 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_ping *frame)
|
2012-01-27 11:35:05 +01:00
|
|
|
{
|
|
|
|
ssize_t framelen = 12;
|
2012-02-16 12:54:30 +01:00
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
2012-02-16 12:54:30 +01:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
2012-01-27 11:35:05 +01:00
|
|
|
}
|
2012-02-16 12:54:30 +01:00
|
|
|
memset(*buf_ptr, 0, framelen);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->unique_id);
|
2012-01-27 11:35:05 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_ping(nghttp2_ping *frame,
|
2012-01-27 11:35:05 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen)
|
|
|
|
{
|
2012-02-18 13:51:57 +01:00
|
|
|
if(payloadlen != 4) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-01-27 11:35:05 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
frame->unique_id = nghttp2_get_uint32(payload);
|
2012-01-27 11:35:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_goaway *frame)
|
2012-01-28 11:22:38 +01:00
|
|
|
{
|
2012-02-24 17:17:03 +01:00
|
|
|
ssize_t framelen;
|
2012-02-16 12:54:30 +01:00
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY2) {
|
2012-02-24 17:17:03 +01:00
|
|
|
framelen = 12;
|
2013-07-12 17:19:03 +02:00
|
|
|
} else if(frame->hd.version == NGHTTP2_PROTO_SPDY3) {
|
2012-02-24 17:17:03 +01:00
|
|
|
framelen = 16;
|
|
|
|
} else {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
2012-02-16 12:54:30 +01:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
2012-01-28 11:22:38 +01:00
|
|
|
}
|
2012-02-16 12:54:30 +01:00
|
|
|
memset(*buf_ptr, 0, framelen);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->last_good_stream_id);
|
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY3) {
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[12], frame->status_code);
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2012-01-28 11:22:38 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_goaway(nghttp2_goaway *frame,
|
2012-01-28 11:22:38 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY2) {
|
2012-02-24 17:17:03 +01:00
|
|
|
if(payloadlen != 4) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
} else if(frame->hd.version == NGHTTP2_PROTO_SPDY3) {
|
2012-02-24 17:17:03 +01:00
|
|
|
if(payloadlen != 8) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->last_good_stream_id = nghttp2_get_uint32(payload) &
|
|
|
|
NGHTTP2_STREAM_ID_MASK;
|
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY3) {
|
|
|
|
frame->status_code = nghttp2_get_uint32(payload+4);
|
2012-03-01 14:39:26 +01:00
|
|
|
} else {
|
|
|
|
frame->status_code = 0;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2012-01-28 11:22:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_headers *frame,
|
|
|
|
nghttp2_zlib *deflater)
|
2012-01-27 10:21:14 +01:00
|
|
|
{
|
|
|
|
ssize_t framelen;
|
2012-02-24 17:17:03 +01:00
|
|
|
size_t len_size;
|
2013-01-24 16:55:30 +01:00
|
|
|
ssize_t nv_offset;
|
2013-07-12 17:19:03 +02:00
|
|
|
len_size = nghttp2_frame_get_len_size(frame->hd.version);
|
2012-02-24 17:17:03 +01:00
|
|
|
if(len_size == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nv_offset = nghttp2_frame_nv_offset(NGHTTP2_HEADERS, frame->hd.version);
|
2012-05-25 03:46:40 +02:00
|
|
|
assert(nv_offset > 0);
|
2013-07-12 17:19:03 +02:00
|
|
|
framelen = nghttp2_frame_alloc_pack_nv(buf_ptr, buflen_ptr,
|
2012-02-16 12:54:30 +01:00
|
|
|
nvbuf_ptr, nvbuflen_ptr,
|
2012-02-24 17:17:03 +01:00
|
|
|
frame->nv, nv_offset,
|
|
|
|
len_size, deflater);
|
2012-01-27 10:21:14 +01:00
|
|
|
if(framelen < 0) {
|
|
|
|
return framelen;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->hd.length = framelen-NGHTTP2_FRAME_HEAD_LENGTH;
|
2012-02-24 17:17:03 +01:00
|
|
|
memset(*buf_ptr, 0, nv_offset);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id);
|
2012-01-27 10:21:14 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_headers(nghttp2_headers *frame,
|
2012-01-27 10:21:14 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer *inflatebuf)
|
2012-01-27 10:21:14 +01:00
|
|
|
{
|
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_frame_unpack_headers_without_nv(frame, head, headlen,
|
2012-05-25 06:49:18 +02:00
|
|
|
payload, payloadlen);
|
|
|
|
if(r == 0) {
|
|
|
|
size_t len_size;
|
2013-07-12 17:19:03 +02:00
|
|
|
len_size = nghttp2_frame_get_len_size(frame->hd.version);
|
2012-05-25 06:49:18 +02:00
|
|
|
if(len_size == 0) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-05-25 06:49:18 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_frame_unpack_nv(&frame->nv, inflatebuf, len_size);
|
2012-05-25 06:49:18 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_headers_without_nv(nghttp2_headers *frame,
|
2012-05-25 06:49:18 +02:00
|
|
|
const uint8_t *head,
|
|
|
|
size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen)
|
|
|
|
{
|
2012-05-25 03:46:40 +02:00
|
|
|
ssize_t nv_offset;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
nv_offset = nghttp2_frame_nv_offset(NGHTTP2_HEADERS, frame->hd.version);
|
2012-05-25 03:46:40 +02:00
|
|
|
assert(nv_offset > 0);
|
|
|
|
if((ssize_t)(headlen + payloadlen) != nv_offset) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-05-25 03:46:40 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
|
2012-05-25 06:49:18 +02:00
|
|
|
frame->nv = NULL;
|
|
|
|
return 0;
|
2012-01-27 10:21:14 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_rst_stream *frame)
|
2012-01-25 13:31:28 +01:00
|
|
|
{
|
2012-01-26 17:17:40 +01:00
|
|
|
ssize_t framelen = 16;
|
2012-02-16 12:54:30 +01:00
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
2012-02-16 12:54:30 +01:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
2012-01-25 13:31:28 +01:00
|
|
|
}
|
2012-02-16 12:54:30 +01:00
|
|
|
memset(*buf_ptr, 0, framelen);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[12], frame->status_code);
|
2012-01-25 13:31:28 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_rst_stream(nghttp2_rst_stream *frame,
|
2012-01-25 13:31:28 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen)
|
|
|
|
{
|
2012-02-18 13:51:57 +01:00
|
|
|
if(payloadlen != 8) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-01-25 13:31:28 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
|
|
|
|
frame->status_code = nghttp2_get_uint32(payload+4);
|
2012-01-25 13:31:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-31 16:26:26 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_window_update *frame)
|
2012-02-24 17:47:37 +01:00
|
|
|
{
|
|
|
|
ssize_t framelen = 16;
|
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
2012-02-24 17:47:37 +01:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
memset(*buf_ptr, 0, framelen);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[12], frame->delta_window_size);
|
2012-02-24 17:47:37 +01:00
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_window_update(nghttp2_window_update *frame,
|
2012-02-24 17:47:37 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen)
|
|
|
|
{
|
|
|
|
if(payloadlen != 8) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-02-24 17:47:37 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK;
|
|
|
|
frame->delta_window_size = nghttp2_get_uint32(&payload[4]) &
|
|
|
|
NGHTTP2_DELTA_WINDOW_SIZE_MASK;
|
2012-02-24 17:47:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_settings *frame)
|
2012-01-31 16:26:26 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH+frame->hd.length;
|
2012-03-22 18:17:48 +01:00
|
|
|
size_t i;
|
|
|
|
int r;
|
2013-07-12 17:19:03 +02:00
|
|
|
if(frame->hd.version != NGHTTP2_PROTO_SPDY2 &&
|
|
|
|
frame->hd.version != NGHTTP2_PROTO_SPDY3) {
|
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-03-08 15:49:26 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
2012-02-16 12:54:30 +01:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
2012-02-16 12:54:30 +01:00
|
|
|
memset(*buf_ptr, 0, framelen);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[8], frame->niv);
|
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY2) {
|
2012-03-08 15:49:26 +01:00
|
|
|
for(i = 0; i < frame->niv; ++i) {
|
|
|
|
int off = i*8;
|
|
|
|
/* spdy/2 spec says ID is network byte order, but publicly
|
|
|
|
deployed server sends little endian host byte order. */
|
2012-04-05 19:02:19 +02:00
|
|
|
(*buf_ptr)[12+off+0] = (frame->iv[i].settings_id) & 0xff;
|
|
|
|
(*buf_ptr)[12+off+1] = (frame->iv[i].settings_id >> 8) & 0xff;
|
|
|
|
(*buf_ptr)[12+off+2] = (frame->iv[i].settings_id >>16) & 0xff;
|
2012-03-08 15:49:26 +01:00
|
|
|
(*buf_ptr)[15+off] = frame->iv[i].flags;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[16+off], frame->iv[i].value);
|
2012-03-08 15:49:26 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i = 0; i < frame->niv; ++i) {
|
|
|
|
int off = i*8;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[12+off], frame->iv[i].settings_id);
|
2012-03-08 15:49:26 +01:00
|
|
|
(*buf_ptr)[12+off] = frame->iv[i].flags;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[16+off], frame->iv[i].value);
|
2012-03-08 15:49:26 +01:00
|
|
|
}
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_settings(nghttp2_settings *frame,
|
2012-01-31 16:26:26 +01:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload, size_t payloadlen)
|
|
|
|
{
|
2012-03-22 18:17:48 +01:00
|
|
|
size_t i;
|
2012-01-31 16:26:26 +01:00
|
|
|
if(payloadlen < 4) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
|
|
|
if(frame->hd.version != NGHTTP2_PROTO_SPDY2 &&
|
|
|
|
frame->hd.version != NGHTTP2_PROTO_SPDY3) {
|
|
|
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
2012-03-08 15:49:26 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->niv = nghttp2_get_uint32(payload);
|
2012-01-31 16:26:26 +01:00
|
|
|
if(payloadlen != 4+frame->niv*8) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->iv = malloc(frame->niv*sizeof(nghttp2_settings_entry));
|
2012-01-31 16:26:26 +01:00
|
|
|
if(frame->iv == NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
if(frame->hd.version == NGHTTP2_PROTO_SPDY2) {
|
2012-03-08 15:49:26 +01:00
|
|
|
for(i = 0; i < frame->niv; ++i) {
|
2012-03-22 18:17:48 +01:00
|
|
|
size_t off = i*8;
|
2012-03-08 15:49:26 +01:00
|
|
|
/* ID is little endian. See comments in
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_settings(). */
|
2012-04-05 19:02:19 +02:00
|
|
|
frame->iv[i].settings_id = payload[4+off] + (payload[4+off+1] << 8)
|
|
|
|
+(payload[4+off+2] << 16);
|
2012-03-08 15:49:26 +01:00
|
|
|
frame->iv[i].flags = payload[7+off];
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->iv[i].value = nghttp2_get_uint32(&payload[8+off]);
|
2012-03-08 15:49:26 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i = 0; i < frame->niv; ++i) {
|
2012-03-22 18:17:48 +01:00
|
|
|
size_t off = i*8;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->iv[i].settings_id = nghttp2_get_uint32(&payload[4+off]) &
|
|
|
|
NGHTTP2_SETTINGS_ID_MASK;
|
2012-03-08 15:49:26 +01:00
|
|
|
frame->iv[i].flags = payload[4+off];
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->iv[i].value = nghttp2_get_uint32(&payload[8+off]);
|
2012-03-08 15:49:26 +01:00
|
|
|
}
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr,
|
|
|
|
nghttp2_credential *frame)
|
2012-04-05 18:45:39 +02:00
|
|
|
{
|
|
|
|
ssize_t framelen;
|
|
|
|
int r;
|
|
|
|
size_t i, offset;
|
2013-07-12 17:19:03 +02:00
|
|
|
framelen = NGHTTP2_FRAME_HEAD_LENGTH+2+4+frame->proof.length;
|
2012-04-05 18:45:39 +02:00
|
|
|
for(i = 0; i < frame->ncerts; ++i) {
|
|
|
|
framelen += 4+frame->certs[i].length;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
2012-04-05 18:45:39 +02:00
|
|
|
if(r != 0) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
memset(*buf_ptr, 0, framelen);
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd);
|
|
|
|
offset = NGHTTP2_FRAME_HEAD_LENGTH;
|
|
|
|
nghttp2_put_uint16be(&(*buf_ptr)[offset], frame->slot);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 2;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[offset], frame->proof.length);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 4;
|
|
|
|
memcpy(&(*buf_ptr)[offset], frame->proof.data, frame->proof.length);
|
|
|
|
offset += frame->proof.length;
|
|
|
|
for(i = 0; i < frame->ncerts; ++i) {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_put_uint32be(&(*buf_ptr)[offset], frame->certs[i].length);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 4;
|
|
|
|
memcpy(&(*buf_ptr)[offset], frame->certs[i].data, frame->certs[i].length);
|
|
|
|
offset += frame->certs[i].length;
|
|
|
|
}
|
|
|
|
return framelen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Counts number of client certificate in CREDENTIAL frame payload
|
|
|
|
* |payload| with length |payloadlen|. The |payload| points to the
|
|
|
|
* length of the first certificate. This function also checks the
|
|
|
|
* frame payload is properly composed.
|
|
|
|
*
|
|
|
|
* This function returns the number of certificates in |payload| if it
|
|
|
|
* succeeds, or one of the following negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_INVALID_FRAME
|
2012-04-05 18:45:39 +02:00
|
|
|
* The frame payload is invalid.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
static int nghttp2_frame_count_unpack_cert(const uint8_t *payload,
|
2012-04-05 18:45:39 +02:00
|
|
|
size_t payloadlen)
|
|
|
|
{
|
|
|
|
size_t n, offset = 0;
|
|
|
|
for(n = 1; 1; ++n) {
|
|
|
|
size_t len;
|
|
|
|
if(offset+4 > payloadlen) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
len = nghttp2_get_uint32(&payload[offset]);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 4;
|
|
|
|
if(len > payloadlen || offset+len > payloadlen) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-04-05 18:45:39 +02:00
|
|
|
} else {
|
|
|
|
offset += len;
|
|
|
|
if(offset == payloadlen) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpacks client certificates in the |payload| with length
|
|
|
|
* |payloadlen|. First allocates memory to store the |ncerts|
|
|
|
|
* certificates. Stores certificates in the allocated space and set
|
|
|
|
* its pointer to |*certs_ptr|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-04-05 18:45:39 +02:00
|
|
|
* Out of memory
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
static int nghttp2_frame_unpack_cert(nghttp2_mem_chunk **certs_ptr,
|
2012-04-05 18:45:39 +02:00
|
|
|
size_t ncerts,
|
|
|
|
const uint8_t *payload, size_t payloadlen)
|
|
|
|
{
|
|
|
|
size_t offset, i, j;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_mem_chunk *certs;
|
|
|
|
certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts);
|
2012-04-05 18:45:39 +02:00
|
|
|
if(certs == NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
|
|
|
offset = 0;
|
|
|
|
for(i = 0; i < ncerts; ++i) {
|
2013-07-12 17:19:03 +02:00
|
|
|
certs[i].length = nghttp2_get_uint32(&payload[offset]);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 4;
|
|
|
|
certs[i].data = malloc(certs[i].length);
|
|
|
|
if(certs[i].data == NULL) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
memcpy(certs[i].data, &payload[offset], certs[i].length);
|
|
|
|
offset += certs[i].length;
|
|
|
|
}
|
|
|
|
*certs_ptr = certs;
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
for(j = 0; j < i; ++j) {
|
|
|
|
free(certs[j].data);
|
|
|
|
}
|
|
|
|
free(certs);
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_unpack_credential(nghttp2_credential *frame,
|
2012-04-05 18:45:39 +02:00
|
|
|
const uint8_t *head, size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen)
|
|
|
|
{
|
|
|
|
size_t offset;
|
|
|
|
int rv;
|
|
|
|
if(payloadlen < 10) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_unpack_ctrl_hd(&frame->hd, head);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset = 0;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->slot = nghttp2_get_uint16(&payload[offset]);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 2;
|
2013-07-12 17:19:03 +02:00
|
|
|
frame->proof.length = nghttp2_get_uint32(&payload[offset]);
|
2012-04-05 18:45:39 +02:00
|
|
|
offset += 4;
|
|
|
|
if(frame->proof.length > payloadlen ||
|
|
|
|
offset+frame->proof.length > payloadlen) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_FRAME;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
|
|
|
frame->proof.data = malloc(frame->proof.length);
|
|
|
|
if(frame->proof.data == NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
|
|
|
memcpy(frame->proof.data, &payload[offset], frame->proof.length);
|
|
|
|
offset += frame->proof.length;
|
2013-07-12 17:19:03 +02:00
|
|
|
rv = nghttp2_frame_count_unpack_cert(payload+offset, payloadlen-offset);
|
2012-04-05 18:45:39 +02:00
|
|
|
if(rv < 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
frame->ncerts = rv;
|
2013-07-12 17:19:03 +02:00
|
|
|
rv = nghttp2_frame_unpack_cert(&frame->certs, frame->ncerts,
|
2012-04-05 18:45:39 +02:00
|
|
|
payload+offset, payloadlen-offset);
|
|
|
|
if(rv != 0) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
free(frame->proof.data);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
2012-01-31 16:26:26 +01:00
|
|
|
size_t niv)
|
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_settings_entry *iv_copy;
|
|
|
|
size_t len = niv*sizeof(nghttp2_settings_entry);
|
2012-01-31 16:26:26 +01:00
|
|
|
iv_copy = malloc(len);
|
|
|
|
if(iv_copy == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(iv_copy, iv, len);
|
|
|
|
return iv_copy;
|
|
|
|
}
|
2012-03-10 10:41:01 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
static int nghttp2_settings_entry_compar(const void *lhs, const void *rhs)
|
2012-03-10 10:41:01 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
return ((nghttp2_settings_entry *)lhs)->settings_id
|
|
|
|
-((nghttp2_settings_entry *)rhs)->settings_id;
|
2012-03-10 10:41:01 +01:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_frame_iv_sort(nghttp2_settings_entry *iv, size_t niv)
|
2012-03-10 10:41:01 +01:00
|
|
|
{
|
2013-07-12 17:19:03 +02:00
|
|
|
qsort(iv, niv, sizeof(nghttp2_settings_entry), nghttp2_settings_entry_compar);
|
2012-03-10 10:41:01 +01:00
|
|
|
}
|
2012-05-25 03:46:40 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_frame_nv_offset(nghttp2_frame_type type, uint16_t version)
|
2012-05-25 03:46:40 +02:00
|
|
|
{
|
|
|
|
switch(type) {
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_SYN_STREAM:
|
|
|
|
return NGHTTP2_SYN_STREAM_NV_OFFSET;
|
|
|
|
case NGHTTP2_SYN_REPLY: {
|
|
|
|
if(version == NGHTTP2_PROTO_SPDY2) {
|
|
|
|
return NGHTTP2_SPDY2_SYN_REPLY_NV_OFFSET;
|
|
|
|
} else if(version == NGHTTP2_PROTO_SPDY3) {
|
|
|
|
return NGHTTP2_SPDY3_SYN_REPLY_NV_OFFSET;
|
2012-05-25 03:46:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_HEADERS: {
|
|
|
|
if(version == NGHTTP2_PROTO_SPDY2) {
|
|
|
|
return NGHTTP2_SPDY2_HEADERS_NV_OFFSET;
|
|
|
|
} else if(version == NGHTTP2_PROTO_SPDY3) {
|
|
|
|
return NGHTTP2_SPDY3_HEADERS_NV_OFFSET;
|
2012-05-25 03:46:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2012-08-21 16:19:15 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_frame_nv_check_null(const char **nv)
|
2012-08-21 16:19:15 +02:00
|
|
|
{
|
2013-03-23 13:23:13 +01:00
|
|
|
size_t i, j;
|
2012-08-21 16:19:15 +02:00
|
|
|
for(i = 0; nv[i]; i += 2) {
|
|
|
|
if(nv[i][0] == '\0' || nv[i+1] == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-23 13:23:13 +01:00
|
|
|
for(j = 0; nv[i][j]; ++j) {
|
|
|
|
unsigned char c = nv[i][j];
|
|
|
|
if(c < 0x20 || c > 0x7e) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-08-21 16:19:15 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|