2013-07-12 17:19:03 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2013-07-12 17:19:03 +02:00
|
|
|
*
|
2013-09-08 23:21:06 +02:00
|
|
|
* Copyright (c) 2012, 2013 Tatsuhiro Tsujikawa
|
2013-07-12 17:19:03 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#include "nghttp2_submit.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2013-08-08 17:58:52 +02:00
|
|
|
#include <assert.h>
|
2013-07-12 17:19:03 +02:00
|
|
|
|
|
|
|
#include "nghttp2_session.h"
|
|
|
|
#include "nghttp2_frame.h"
|
|
|
|
#include "nghttp2_helper.h"
|
2014-03-25 18:04:24 +01:00
|
|
|
#include "nghttp2_priority_spec.h"
|
2013-07-12 17:19:03 +02:00
|
|
|
|
2016-01-11 08:18:39 +01:00
|
|
|
/*
|
|
|
|
* Detects the dependency error, that is stream attempted to depend on
|
|
|
|
* itself. If |stream_id| is -1, we use session->next_stream_id as
|
|
|
|
* stream ID.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* error codes:
|
|
|
|
*
|
|
|
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
|
|
|
* Stream attempted to depend on itself.
|
|
|
|
*/
|
|
|
|
static int detect_self_dependency(nghttp2_session *session, int32_t stream_id,
|
|
|
|
const nghttp2_priority_spec *pri_spec) {
|
|
|
|
assert(pri_spec);
|
|
|
|
|
|
|
|
if (stream_id == -1) {
|
|
|
|
if ((int32_t)session->next_stream_id == pri_spec->stream_id) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_id == pri_spec->stream_id) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
/* This function takes ownership of |nva_copy|. Regardless of the
|
|
|
|
return value, the caller must not free |nva_copy| after this
|
|
|
|
function returns. */
|
2014-11-27 15:39:04 +01:00
|
|
|
static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags,
|
|
|
|
int32_t stream_id,
|
|
|
|
const nghttp2_priority_spec *pri_spec,
|
|
|
|
nghttp2_nv *nva_copy, size_t nvlen,
|
|
|
|
const nghttp2_data_provider *data_prd,
|
2015-12-21 13:33:58 +01:00
|
|
|
void *stream_user_data) {
|
2013-09-10 17:55:35 +02:00
|
|
|
int rv;
|
2013-07-12 17:19:03 +02:00
|
|
|
uint8_t flags_copy;
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_outbound_item *item = NULL;
|
2013-09-10 17:55:35 +02:00
|
|
|
nghttp2_frame *frame = NULL;
|
2014-05-07 16:24:07 +02:00
|
|
|
nghttp2_headers_category hcat;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
|
|
|
|
|
|
|
mem = &session->mem;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
2014-11-27 15:39:04 +01:00
|
|
|
if (item == NULL) {
|
2014-10-02 17:59:44 +02:00
|
|
|
rv = NGHTTP2_ERR_NOMEM;
|
|
|
|
goto fail;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-09-30 14:45:15 +02:00
|
|
|
|
2015-04-24 19:23:01 +02:00
|
|
|
nghttp2_outbound_item_init(item);
|
2014-09-30 14:45:15 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (data_prd != NULL && data_prd->read_callback != NULL) {
|
2014-10-02 17:59:44 +02:00
|
|
|
item->aux_data.headers.data_prd = *data_prd;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
item->aux_data.headers.stream_user_data = stream_user_data;
|
|
|
|
|
2015-09-23 11:07:38 +02:00
|
|
|
flags_copy =
|
|
|
|
(uint8_t)((flags & (NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_PRIORITY)) |
|
|
|
|
NGHTTP2_FLAG_END_HEADERS);
|
2013-07-15 14:45:59 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream_id == -1) {
|
|
|
|
if (session->next_stream_id > INT32_MAX) {
|
2014-05-07 16:24:07 +02:00
|
|
|
rv = NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
stream_id = (int32_t)session->next_stream_id;
|
2014-05-07 16:24:07 +02:00
|
|
|
session->next_stream_id += 2;
|
|
|
|
|
|
|
|
hcat = NGHTTP2_HCAT_REQUEST;
|
|
|
|
} else {
|
|
|
|
/* More specific categorization will be done later. */
|
|
|
|
hcat = NGHTTP2_HCAT_HEADERS;
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
frame = &item->frame;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_frame_headers_init(&frame->headers, flags_copy, stream_id, hcat,
|
|
|
|
pri_spec, nva_copy, nvlen);
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
rv = nghttp2_session_add_item(session, item);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != 0) {
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_frame_headers_free(&frame->headers, mem);
|
2013-09-10 17:55:35 +02:00
|
|
|
goto fail2;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hcat == NGHTTP2_HCAT_REQUEST) {
|
2014-05-07 16:24:07 +02:00
|
|
|
return stream_id;
|
|
|
|
}
|
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
return 0;
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
fail:
|
2013-09-10 17:55:35 +02:00
|
|
|
/* nghttp2_frame_headers_init() takes ownership of nva_copy. */
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_nv_array_del(nva_copy, mem);
|
2014-11-27 15:39:04 +01:00
|
|
|
fail2:
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem_free(mem, item);
|
2014-09-30 14:45:15 +02:00
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static int32_t submit_headers_shared_nva(nghttp2_session *session,
|
|
|
|
uint8_t flags, int32_t stream_id,
|
|
|
|
const nghttp2_priority_spec *pri_spec,
|
|
|
|
const nghttp2_nv *nva, size_t nvlen,
|
|
|
|
const nghttp2_data_provider *data_prd,
|
2015-12-21 13:33:58 +01:00
|
|
|
void *stream_user_data) {
|
2014-06-11 16:37:16 +02:00
|
|
|
int rv;
|
2013-09-10 17:55:35 +02:00
|
|
|
nghttp2_nv *nva_copy;
|
2014-04-14 16:53:54 +02:00
|
|
|
nghttp2_priority_spec copy_pri_spec;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
|
|
|
|
|
|
|
mem = &session->mem;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (pri_spec) {
|
2014-04-01 15:54:20 +02:00
|
|
|
copy_pri_spec = *pri_spec;
|
2015-11-21 10:22:28 +01:00
|
|
|
nghttp2_priority_spec_normalize_weight(©_pri_spec);
|
2014-04-14 16:53:54 +02:00
|
|
|
} else {
|
|
|
|
nghttp2_priority_spec_default_init(©_pri_spec);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen, mem);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv < 0) {
|
2014-04-08 17:13:11 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
return submit_headers_shared(session, flags, stream_id, ©_pri_spec,
|
2015-12-21 13:33:58 +01:00
|
|
|
nva_copy, nvlen, data_prd, stream_user_data);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2015-09-28 17:06:20 +02:00
|
|
|
int nghttp2_submit_trailer(nghttp2_session *session, int32_t stream_id,
|
|
|
|
const nghttp2_nv *nva, size_t nvlen) {
|
2016-01-11 08:18:39 +01:00
|
|
|
if (stream_id <= 0) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2015-09-28 17:06:20 +02:00
|
|
|
return (int)submit_headers_shared_nva(session, NGHTTP2_FLAG_END_STREAM,
|
2015-12-21 13:33:58 +01:00
|
|
|
stream_id, NULL, nva, nvlen, NULL,
|
|
|
|
NULL);
|
2015-03-07 09:02:00 +01:00
|
|
|
}
|
|
|
|
|
2014-05-07 16:24:07 +02:00
|
|
|
int32_t nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
|
|
|
int32_t stream_id,
|
|
|
|
const nghttp2_priority_spec *pri_spec,
|
|
|
|
const nghttp2_nv *nva, size_t nvlen,
|
2014-11-27 15:39:04 +01:00
|
|
|
void *stream_user_data) {
|
2016-01-11 08:18:39 +01:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (stream_id == -1) {
|
|
|
|
if (session->server) {
|
|
|
|
return NGHTTP2_ERR_PROTO;
|
|
|
|
}
|
|
|
|
} else if (stream_id <= 0) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
flags &= NGHTTP2_FLAG_END_STREAM;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (pri_spec && !nghttp2_priority_spec_check_default(pri_spec)) {
|
2016-01-11 08:18:39 +01:00
|
|
|
rv = detect_self_dependency(session, stream_id, pri_spec);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
flags |= NGHTTP2_FLAG_PRIORITY;
|
|
|
|
} else {
|
|
|
|
pri_spec = NULL;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
return submit_headers_shared_nva(session, flags, stream_id, pri_spec, nva,
|
2015-12-21 13:33:58 +01:00
|
|
|
nvlen, NULL, stream_user_data);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2016-02-29 15:39:50 +01:00
|
|
|
int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
|
2014-11-27 15:39:04 +01:00
|
|
|
const uint8_t *opaque_data) {
|
2016-02-29 15:39:50 +01:00
|
|
|
flags &= NGHTTP2_FLAG_ACK;
|
2016-05-05 16:11:10 +02:00
|
|
|
return nghttp2_session_add_ping(session, flags, opaque_data);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
|
2014-03-25 18:04:24 +01:00
|
|
|
int32_t stream_id,
|
2014-11-27 15:39:04 +01:00
|
|
|
const nghttp2_priority_spec *pri_spec) {
|
2014-02-18 16:45:20 +01:00
|
|
|
int rv;
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_outbound_item *item;
|
2013-07-22 17:11:39 +02:00
|
|
|
nghttp2_frame *frame;
|
2014-04-01 15:54:20 +02:00
|
|
|
nghttp2_priority_spec copy_pri_spec;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
2014-12-07 15:07:13 +01:00
|
|
|
|
|
|
|
mem = &session->mem;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream_id == 0 || pri_spec == NULL) {
|
2013-07-22 17:11:39 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream_id == pri_spec->stream_id) {
|
2014-03-25 18:04:24 +01:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
copy_pri_spec = *pri_spec;
|
|
|
|
|
2015-11-21 10:22:28 +01:00
|
|
|
nghttp2_priority_spec_normalize_weight(©_pri_spec);
|
2014-04-14 16:53:54 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (item == NULL) {
|
2013-07-22 17:11:39 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-04-24 19:23:01 +02:00
|
|
|
nghttp2_outbound_item_init(item);
|
2014-10-02 17:59:44 +02:00
|
|
|
|
|
|
|
frame = &item->frame;
|
|
|
|
|
2014-04-01 15:54:20 +02:00
|
|
|
nghttp2_frame_priority_init(&frame->priority, stream_id, ©_pri_spec);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
rv = nghttp2_session_add_item(session, item);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != 0) {
|
2013-07-22 17:11:39 +02:00
|
|
|
nghttp2_frame_priority_free(&frame->priority);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem_free(mem, item);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-02-18 16:45:20 +01:00
|
|
|
return rv;
|
2013-07-22 17:11:39 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2013-07-22 17:11:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int nghttp2_submit_rst_stream(nghttp2_session *session, uint8_t flags,
|
2014-11-27 15:39:04 +01:00
|
|
|
int32_t stream_id, uint32_t error_code) {
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream_id == 0) {
|
2014-06-07 11:48:37 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
return nghttp2_session_add_rst_stream(session, stream_id, error_code);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int nghttp2_submit_goaway(nghttp2_session *session, uint8_t flags,
|
2014-11-27 15:39:04 +01:00
|
|
|
int32_t last_stream_id, uint32_t error_code,
|
|
|
|
const uint8_t *opaque_data, size_t opaque_data_len) {
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
|
|
|
|
2015-01-21 17:43:56 +01:00
|
|
|
if (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
return nghttp2_session_add_goaway(session, last_stream_id, error_code,
|
2015-01-21 17:43:56 +01:00
|
|
|
opaque_data, opaque_data_len,
|
|
|
|
NGHTTP2_GOAWAY_AUX_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nghttp2_submit_shutdown_notice(nghttp2_session *session) {
|
|
|
|
if (!session->server) {
|
|
|
|
return NGHTTP2_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
if (session->goaway_flags) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return nghttp2_session_add_goaway(session, (1u << 31) - 1, NGHTTP2_NO_ERROR,
|
|
|
|
NULL, 0,
|
|
|
|
NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
2014-11-27 15:39:04 +01:00
|
|
|
const nghttp2_settings_entry *iv, size_t niv) {
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
2013-10-27 11:22:51 +01:00
|
|
|
return nghttp2_session_add_settings(session, NGHTTP2_FLAG_NONE, iv, niv);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int32_t nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
2014-11-27 15:39:04 +01:00
|
|
|
int32_t stream_id, const nghttp2_nv *nva,
|
|
|
|
size_t nvlen,
|
|
|
|
void *promised_stream_user_data) {
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_outbound_item *item;
|
2013-07-24 18:49:05 +02:00
|
|
|
nghttp2_frame *frame;
|
2013-12-08 13:19:33 +01:00
|
|
|
nghttp2_nv *nva_copy;
|
2013-07-24 18:49:05 +02:00
|
|
|
uint8_t flags_copy;
|
2014-05-07 16:24:07 +02:00
|
|
|
int32_t promised_stream_id;
|
2013-12-08 13:19:33 +01:00
|
|
|
int rv;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
2014-12-07 15:07:13 +01:00
|
|
|
|
|
|
|
mem = &session->mem;
|
2013-07-24 18:49:05 +02:00
|
|
|
|
2016-01-11 08:18:39 +01:00
|
|
|
if (stream_id <= 0 || nghttp2_session_is_my_stream_id(session, stream_id)) {
|
2014-06-07 11:48:37 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!session->server) {
|
2014-04-08 17:13:11 +02:00
|
|
|
return NGHTTP2_ERR_PROTO;
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
/* All 32bit signed stream IDs are spent. */
|
2014-11-27 15:39:04 +01:00
|
|
|
if (session->next_stream_id > INT32_MAX) {
|
2014-10-02 17:59:44 +02:00
|
|
|
return NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
2014-11-27 15:39:04 +01:00
|
|
|
if (item == NULL) {
|
2013-07-24 18:49:05 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
|
|
|
}
|
2014-09-30 14:45:15 +02:00
|
|
|
|
2015-04-24 19:23:01 +02:00
|
|
|
nghttp2_outbound_item_init(item);
|
2014-10-02 17:59:44 +02:00
|
|
|
|
|
|
|
item->aux_data.headers.stream_user_data = promised_stream_user_data;
|
|
|
|
|
|
|
|
frame = &item->frame;
|
2014-09-30 14:45:15 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen, mem);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv < 0) {
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem_free(mem, item);
|
2013-12-08 13:19:33 +01:00
|
|
|
return rv;
|
2013-07-24 18:49:05 +02:00
|
|
|
}
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2014-02-21 13:23:51 +01:00
|
|
|
flags_copy = NGHTTP2_FLAG_END_HEADERS;
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
promised_stream_id = (int32_t)session->next_stream_id;
|
2014-05-07 16:24:07 +02:00
|
|
|
session->next_stream_id += 2;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_frame_push_promise_init(&frame->push_promise, flags_copy, stream_id,
|
|
|
|
promised_stream_id, nva_copy, nvlen);
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
rv = nghttp2_session_add_item(session, item);
|
2014-05-07 16:24:07 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != 0) {
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_frame_push_promise_free(&frame->push_promise, mem);
|
|
|
|
nghttp2_mem_free(mem, item);
|
2014-05-07 16:24:07 +02:00
|
|
|
|
|
|
|
return rv;
|
2013-07-24 18:49:05 +02:00
|
|
|
}
|
2014-05-07 16:24:07 +02:00
|
|
|
|
|
|
|
return promised_stream_id;
|
2013-07-24 18:49:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags,
|
2013-07-15 14:45:59 +02:00
|
|
|
int32_t stream_id,
|
2014-11-27 15:39:04 +01:00
|
|
|
int32_t window_size_increment) {
|
2013-08-08 17:58:52 +02:00
|
|
|
int rv;
|
2014-08-24 17:32:44 +02:00
|
|
|
nghttp2_stream *stream = 0;
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (window_size_increment == 0) {
|
2013-10-12 10:02:37 +02:00
|
|
|
return 0;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream_id == 0) {
|
|
|
|
rv = nghttp2_adjust_local_window_size(
|
|
|
|
&session->local_window_size, &session->recv_window_size,
|
|
|
|
&session->recv_reduction, &window_size_increment);
|
|
|
|
if (rv != 0) {
|
2013-08-08 17:58:52 +02:00
|
|
|
return rv;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
} else {
|
2013-07-15 14:45:59 +02:00
|
|
|
stream = nghttp2_session_get_stream(session, stream_id);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!stream) {
|
2014-01-18 08:19:28 +01:00
|
|
|
return 0;
|
2013-07-15 14:45:59 +02:00
|
|
|
}
|
2014-07-25 14:26:03 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
rv = nghttp2_adjust_local_window_size(
|
|
|
|
&stream->local_window_size, &stream->recv_window_size,
|
|
|
|
&stream->recv_reduction, &window_size_increment);
|
|
|
|
if (rv != 0) {
|
2014-07-25 14:26:03 +02:00
|
|
|
return rv;
|
|
|
|
}
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-07-02 14:20:40 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (window_size_increment > 0) {
|
|
|
|
if (stream_id == 0) {
|
2014-07-25 14:26:03 +02:00
|
|
|
session->consumed_size =
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_max(0, session->consumed_size - window_size_increment);
|
2014-07-25 14:26:03 +02:00
|
|
|
} else {
|
|
|
|
stream->consumed_size =
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_max(0, stream->consumed_size - window_size_increment);
|
2014-07-25 14:26:03 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 21:35:49 +01:00
|
|
|
return nghttp2_session_add_window_update(session, 0, stream_id,
|
2013-08-08 17:58:52 +02:00
|
|
|
window_size_increment);
|
|
|
|
}
|
|
|
|
return 0;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2016-05-29 16:13:11 +02:00
|
|
|
int nghttp2_session_set_local_window_size(nghttp2_session *session,
|
2017-03-11 09:46:39 +01:00
|
|
|
uint8_t flags, int32_t stream_id,
|
2016-05-29 16:13:11 +02:00
|
|
|
int32_t window_size) {
|
|
|
|
int32_t window_size_increment;
|
|
|
|
nghttp2_stream *stream;
|
|
|
|
int rv;
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
2016-05-29 16:13:11 +02:00
|
|
|
|
|
|
|
if (window_size < 0) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_id == 0) {
|
|
|
|
window_size_increment = window_size - session->local_window_size;
|
|
|
|
|
|
|
|
if (window_size_increment == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_size_increment < 0) {
|
|
|
|
return nghttp2_adjust_local_window_size(
|
|
|
|
&session->local_window_size, &session->recv_window_size,
|
|
|
|
&session->recv_reduction, &window_size_increment);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nghttp2_increase_local_window_size(
|
|
|
|
&session->local_window_size, &session->recv_window_size,
|
|
|
|
&session->recv_reduction, &window_size_increment);
|
|
|
|
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream = nghttp2_session_get_stream(session, stream_id);
|
|
|
|
|
|
|
|
if (stream == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_size_increment = window_size - stream->local_window_size;
|
|
|
|
|
|
|
|
if (window_size_increment == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_size_increment < 0) {
|
|
|
|
return nghttp2_adjust_local_window_size(
|
|
|
|
&stream->local_window_size, &stream->recv_window_size,
|
|
|
|
&stream->recv_reduction, &window_size_increment);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nghttp2_increase_local_window_size(
|
|
|
|
&stream->local_window_size, &stream->recv_window_size,
|
|
|
|
&stream->recv_reduction, &window_size_increment);
|
|
|
|
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_size_increment > 0) {
|
2017-01-03 21:35:49 +01:00
|
|
|
return nghttp2_session_add_window_update(session, 0, stream_id,
|
2016-05-29 16:13:11 +02:00
|
|
|
window_size_increment);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-11 09:46:39 +01:00
|
|
|
int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags,
|
2016-03-29 16:29:26 +02:00
|
|
|
int32_t stream_id, const uint8_t *origin,
|
|
|
|
size_t origin_len, const uint8_t *field_value,
|
|
|
|
size_t field_value_len) {
|
|
|
|
nghttp2_mem *mem;
|
|
|
|
uint8_t *buf, *p;
|
|
|
|
uint8_t *origin_copy;
|
|
|
|
uint8_t *field_value_copy;
|
|
|
|
nghttp2_outbound_item *item;
|
|
|
|
nghttp2_frame *frame;
|
|
|
|
nghttp2_ext_altsvc *altsvc;
|
|
|
|
int rv;
|
2017-03-11 09:46:39 +01:00
|
|
|
(void)flags;
|
2016-03-29 16:29:26 +02:00
|
|
|
|
|
|
|
mem = &session->mem;
|
|
|
|
|
2016-03-31 16:58:26 +02:00
|
|
|
if (!session->server) {
|
|
|
|
return NGHTTP2_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:29:26 +02:00
|
|
|
if (2 + origin_len + field_value_len > NGHTTP2_MAX_PAYLOADLEN) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2016-03-31 16:58:26 +02:00
|
|
|
if (stream_id == 0) {
|
|
|
|
if (origin_len == 0) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
} else if (origin_len != 0) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:29:26 +02:00
|
|
|
buf = nghttp2_mem_malloc(mem, origin_len + field_value_len + 2);
|
|
|
|
if (buf == NULL) {
|
|
|
|
return NGHTTP2_ERR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
|
|
|
|
origin_copy = p;
|
2016-03-31 16:58:26 +02:00
|
|
|
if (origin_len) {
|
|
|
|
p = nghttp2_cpymem(p, origin, origin_len);
|
|
|
|
}
|
2016-03-29 16:29:26 +02:00
|
|
|
*p++ = '\0';
|
|
|
|
|
|
|
|
field_value_copy = p;
|
2016-03-31 16:58:26 +02:00
|
|
|
if (field_value_len) {
|
|
|
|
p = nghttp2_cpymem(p, field_value, field_value_len);
|
|
|
|
}
|
2016-03-29 16:29:26 +02:00
|
|
|
*p++ = '\0';
|
|
|
|
|
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
|
|
|
if (item == NULL) {
|
|
|
|
rv = NGHTTP2_ERR_NOMEM;
|
|
|
|
goto fail_item_malloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_outbound_item_init(item);
|
|
|
|
|
|
|
|
item->aux_data.ext.builtin = 1;
|
|
|
|
|
2016-04-03 16:03:34 +02:00
|
|
|
altsvc = &item->ext_frame_payload.altsvc;
|
2016-03-29 16:29:26 +02:00
|
|
|
|
|
|
|
frame = &item->frame;
|
|
|
|
frame->ext.payload = altsvc;
|
|
|
|
|
|
|
|
nghttp2_frame_altsvc_init(&frame->ext, stream_id, origin_copy, origin_len,
|
|
|
|
field_value_copy, field_value_len);
|
|
|
|
|
|
|
|
rv = nghttp2_session_add_item(session, item);
|
|
|
|
if (rv != 0) {
|
|
|
|
nghttp2_frame_altsvc_free(&frame->ext, mem);
|
|
|
|
nghttp2_mem_free(mem, item);
|
2016-03-31 16:58:26 +02:00
|
|
|
|
|
|
|
return rv;
|
2016-03-29 16:29:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_item_malloc:
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-05-10 03:57:02 +02:00
|
|
|
int nghttp2_submit_origin(nghttp2_session *session, uint8_t flags,
|
|
|
|
const nghttp2_origin_entry *ov, size_t nov) {
|
|
|
|
nghttp2_mem *mem;
|
|
|
|
uint8_t *p;
|
|
|
|
nghttp2_outbound_item *item;
|
|
|
|
nghttp2_frame *frame;
|
|
|
|
nghttp2_ext_origin *origin;
|
|
|
|
nghttp2_origin_entry *ov_copy;
|
|
|
|
size_t len = 0;
|
|
|
|
size_t i;
|
|
|
|
int rv;
|
|
|
|
(void)flags;
|
|
|
|
|
|
|
|
mem = &session->mem;
|
|
|
|
|
|
|
|
if (!session->server) {
|
|
|
|
return NGHTTP2_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nov) {
|
|
|
|
for (i = 0; i < nov; ++i) {
|
|
|
|
len += ov[i].origin_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (2 * nov + len > NGHTTP2_MAX_PAYLOADLEN) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The last nov is added for terminal NULL character. */
|
|
|
|
ov_copy =
|
|
|
|
nghttp2_mem_malloc(mem, nov * sizeof(nghttp2_origin_entry) + len + nov);
|
|
|
|
if (ov_copy == NULL) {
|
|
|
|
return NGHTTP2_ERR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (uint8_t *)ov_copy + nov * sizeof(nghttp2_origin_entry);
|
|
|
|
|
|
|
|
for (i = 0; i < nov; ++i) {
|
|
|
|
ov_copy[i].origin = p;
|
|
|
|
ov_copy[i].origin_len = ov[i].origin_len;
|
|
|
|
p = nghttp2_cpymem(p, ov[i].origin, ov[i].origin_len);
|
|
|
|
*p++ = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
assert((size_t)(p - (uint8_t *)ov_copy) ==
|
|
|
|
nov * sizeof(nghttp2_origin_entry) + len + nov);
|
|
|
|
} else {
|
|
|
|
ov_copy = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
|
|
|
if (item == NULL) {
|
|
|
|
rv = NGHTTP2_ERR_NOMEM;
|
|
|
|
goto fail_item_malloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_outbound_item_init(item);
|
|
|
|
|
|
|
|
item->aux_data.ext.builtin = 1;
|
|
|
|
|
|
|
|
origin = &item->ext_frame_payload.origin;
|
|
|
|
|
|
|
|
frame = &item->frame;
|
|
|
|
frame->ext.payload = origin;
|
|
|
|
|
|
|
|
nghttp2_frame_origin_init(&frame->ext, ov_copy, nov);
|
|
|
|
|
|
|
|
rv = nghttp2_session_add_item(session, item);
|
|
|
|
if (rv != 0) {
|
|
|
|
nghttp2_frame_origin_free(&frame->ext, mem);
|
|
|
|
nghttp2_mem_free(mem, item);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_item_malloc:
|
|
|
|
free(ov_copy);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec,
|
2014-11-27 15:39:04 +01:00
|
|
|
const nghttp2_data_provider *data_prd) {
|
2013-07-15 14:45:59 +02:00
|
|
|
uint8_t flags = NGHTTP2_FLAG_NONE;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (data_prd == NULL || data_prd->read_callback == NULL) {
|
2013-07-15 14:45:59 +02:00
|
|
|
flags |= NGHTTP2_FLAG_END_STREAM;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (pri_spec) {
|
2014-04-14 16:53:54 +02:00
|
|
|
flags |= NGHTTP2_FLAG_PRIORITY;
|
2013-07-15 14:45:59 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-05-07 16:24:07 +02:00
|
|
|
int32_t nghttp2_submit_request(nghttp2_session *session,
|
|
|
|
const nghttp2_priority_spec *pri_spec,
|
|
|
|
const nghttp2_nv *nva, size_t nvlen,
|
|
|
|
const nghttp2_data_provider *data_prd,
|
2014-11-27 15:39:04 +01:00
|
|
|
void *stream_user_data) {
|
2014-03-25 18:04:24 +01:00
|
|
|
uint8_t flags;
|
2016-01-11 08:18:39 +01:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (session->server) {
|
|
|
|
return NGHTTP2_ERR_PROTO;
|
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2016-01-11 08:18:39 +01:00
|
|
|
if (pri_spec && !nghttp2_priority_spec_check_default(pri_spec)) {
|
|
|
|
rv = detect_self_dependency(session, -1, pri_spec);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-14 16:53:54 +02:00
|
|
|
pri_spec = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
flags = set_request_flags(pri_spec, data_prd);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
return submit_headers_shared_nva(session, flags, -1, pri_spec, nva, nvlen,
|
2015-12-21 13:33:58 +01:00
|
|
|
data_prd, stream_user_data);
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static uint8_t set_response_flags(const nghttp2_data_provider *data_prd) {
|
2013-07-15 14:45:59 +02:00
|
|
|
uint8_t flags = NGHTTP2_FLAG_NONE;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (data_prd == NULL || data_prd->read_callback == NULL) {
|
2013-07-15 14:45:59 +02:00
|
|
|
flags |= NGHTTP2_FLAG_END_STREAM;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2013-11-28 13:35:48 +01:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,
|
2013-12-08 13:19:33 +01:00
|
|
|
const nghttp2_nv *nva, size_t nvlen,
|
2014-11-27 15:39:04 +01:00
|
|
|
const nghttp2_data_provider *data_prd) {
|
2016-01-11 08:18:39 +01:00
|
|
|
uint8_t flags;
|
|
|
|
|
|
|
|
if (stream_id <= 0) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session->server) {
|
|
|
|
return NGHTTP2_ERR_PROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = set_response_flags(data_prd);
|
2014-11-27 15:39:04 +01:00
|
|
|
return submit_headers_shared_nva(session, flags, stream_id, NULL, nva, nvlen,
|
2015-12-21 13:33:58 +01:00
|
|
|
data_prd, NULL);
|
2013-11-28 13:35:48 +01:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
|
|
|
|
int32_t stream_id,
|
2014-11-27 15:39:04 +01:00
|
|
|
const nghttp2_data_provider *data_prd) {
|
2014-02-18 16:45:20 +01:00
|
|
|
int rv;
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_outbound_item *item;
|
|
|
|
nghttp2_frame *frame;
|
|
|
|
nghttp2_data_aux_data *aux_data;
|
2014-07-30 15:37:59 +02:00
|
|
|
uint8_t nflags = flags & NGHTTP2_FLAG_END_STREAM;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
|
|
|
|
|
|
|
mem = &session->mem;
|
2013-08-09 17:02:24 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream_id == 0) {
|
2014-06-07 11:48:37 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
2014-11-27 15:39:04 +01:00
|
|
|
if (item == NULL) {
|
2013-07-12 17:19:03 +02:00
|
|
|
return NGHTTP2_ERR_NOMEM;
|
|
|
|
}
|
2014-10-02 17:59:44 +02:00
|
|
|
|
2015-04-24 19:23:01 +02:00
|
|
|
nghttp2_outbound_item_init(item);
|
2014-10-02 17:59:44 +02:00
|
|
|
|
|
|
|
frame = &item->frame;
|
|
|
|
aux_data = &item->aux_data.data;
|
|
|
|
aux_data->data_prd = *data_prd;
|
|
|
|
aux_data->eof = 0;
|
|
|
|
aux_data->flags = nflags;
|
|
|
|
|
|
|
|
/* flags are sent on transmission */
|
|
|
|
nghttp2_frame_data_init(&frame->data, NGHTTP2_FLAG_NONE, stream_id);
|
|
|
|
|
|
|
|
rv = nghttp2_session_add_item(session, item);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != 0) {
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_frame_data_free(&frame->data);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem_free(mem, item);
|
2014-02-18 16:45:20 +01:00
|
|
|
return rv;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2014-02-18 16:45:20 +01:00
|
|
|
return 0;
|
2013-07-12 17:19:03 +02:00
|
|
|
}
|
2013-08-03 11:05:14 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
ssize_t nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen,
|
2013-09-09 14:30:39 +02:00
|
|
|
const nghttp2_settings_entry *iv,
|
2014-11-27 15:39:04 +01:00
|
|
|
size_t niv) {
|
|
|
|
if (!nghttp2_iv_check(iv, niv)) {
|
2013-08-03 11:05:14 +02:00
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
2013-09-08 23:21:06 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (buflen < (niv * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH)) {
|
2013-09-08 23:21:06 +02:00
|
|
|
return NGHTTP2_ERR_INSUFF_BUFSIZE;
|
2014-02-06 14:06:42 +01:00
|
|
|
}
|
2013-09-08 23:21:06 +02:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
return (ssize_t)nghttp2_frame_pack_settings_payload(buf, iv, niv);
|
2013-08-03 11:05:14 +02:00
|
|
|
}
|
2015-10-10 15:27:48 +02:00
|
|
|
|
|
|
|
int nghttp2_submit_extension(nghttp2_session *session, uint8_t type,
|
|
|
|
uint8_t flags, int32_t stream_id, void *payload) {
|
|
|
|
int rv;
|
|
|
|
nghttp2_outbound_item *item;
|
|
|
|
nghttp2_frame *frame;
|
|
|
|
nghttp2_mem *mem;
|
|
|
|
|
|
|
|
mem = &session->mem;
|
|
|
|
|
|
|
|
if (type <= NGHTTP2_CONTINUATION) {
|
|
|
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session->callbacks.pack_extension_callback) {
|
|
|
|
return NGHTTP2_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item));
|
|
|
|
if (item == NULL) {
|
|
|
|
return NGHTTP2_ERR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_outbound_item_init(item);
|
|
|
|
|
|
|
|
frame = &item->frame;
|
|
|
|
nghttp2_frame_extension_init(&frame->ext, type, flags, stream_id, payload);
|
|
|
|
|
|
|
|
rv = nghttp2_session_add_item(session, item);
|
|
|
|
if (rv != 0) {
|
|
|
|
nghttp2_frame_extension_free(&frame->ext);
|
|
|
|
nghttp2_mem_free(mem, item);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|