2012-02-19 15:42:25 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-02-19 15:42:25 +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_outbound_item.h"
|
2012-02-19 15:42:25 +01:00
|
|
|
|
2012-03-29 16:59:51 +02:00
|
|
|
#include <assert.h>
|
2015-04-24 19:23:01 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void nghttp2_outbound_item_init(nghttp2_outbound_item *item) {
|
|
|
|
item->cycle = 0;
|
|
|
|
item->qnext = NULL;
|
|
|
|
item->queued = 0;
|
|
|
|
|
|
|
|
memset(&item->aux_data, 0, sizeof(nghttp2_aux_data));
|
|
|
|
}
|
2012-03-29 16:59:51 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem) {
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_frame *frame;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (item == NULL) {
|
2012-02-19 15:42:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-10-02 17:59:44 +02:00
|
|
|
|
|
|
|
frame = &item->frame;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (frame->hd.type) {
|
2014-10-02 17:59:44 +02:00
|
|
|
case NGHTTP2_DATA:
|
|
|
|
nghttp2_frame_data_free(&frame->data);
|
|
|
|
break;
|
|
|
|
case NGHTTP2_HEADERS:
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_frame_headers_free(&frame->headers, mem);
|
2014-10-02 17:59:44 +02:00
|
|
|
break;
|
|
|
|
case NGHTTP2_PRIORITY:
|
|
|
|
nghttp2_frame_priority_free(&frame->priority);
|
|
|
|
break;
|
|
|
|
case NGHTTP2_RST_STREAM:
|
|
|
|
nghttp2_frame_rst_stream_free(&frame->rst_stream);
|
|
|
|
break;
|
|
|
|
case NGHTTP2_SETTINGS:
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_frame_settings_free(&frame->settings, mem);
|
2014-10-02 17:59:44 +02:00
|
|
|
break;
|
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_frame_push_promise_free(&frame->push_promise, mem);
|
2014-10-02 17:59:44 +02:00
|
|
|
break;
|
|
|
|
case NGHTTP2_PING:
|
|
|
|
nghttp2_frame_ping_free(&frame->ping);
|
|
|
|
break;
|
|
|
|
case NGHTTP2_GOAWAY:
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_frame_goaway_free(&frame->goaway, mem);
|
2014-10-02 17:59:44 +02:00
|
|
|
break;
|
|
|
|
case NGHTTP2_WINDOW_UPDATE:
|
|
|
|
nghttp2_frame_window_update_free(&frame->window_update);
|
|
|
|
break;
|
2016-03-29 16:29:26 +02:00
|
|
|
default: {
|
|
|
|
nghttp2_ext_aux_data *aux_data;
|
|
|
|
|
|
|
|
aux_data = &item->aux_data.ext;
|
|
|
|
|
|
|
|
if (aux_data->builtin == 0) {
|
|
|
|
nghttp2_frame_extension_free(&frame->ext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (frame->hd.type) {
|
|
|
|
case NGHTTP2_ALTSVC:
|
|
|
|
nghttp2_frame_altsvc_free(&frame->ext, mem);
|
|
|
|
break;
|
2017-04-25 16:48:52 +02:00
|
|
|
case NGHTTP2_ORIGIN:
|
|
|
|
nghttp2_frame_origin_free(&frame->ext, mem);
|
|
|
|
break;
|
2016-03-29 16:29:26 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-19 15:42:25 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-24 15:30:32 +02:00
|
|
|
|
|
|
|
void nghttp2_outbound_queue_init(nghttp2_outbound_queue *q) {
|
|
|
|
q->head = q->tail = NULL;
|
|
|
|
q->n = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nghttp2_outbound_queue_push(nghttp2_outbound_queue *q,
|
|
|
|
nghttp2_outbound_item *item) {
|
|
|
|
if (q->tail) {
|
|
|
|
q->tail = q->tail->qnext = item;
|
|
|
|
} else {
|
|
|
|
q->head = q->tail = item;
|
|
|
|
}
|
|
|
|
++q->n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nghttp2_outbound_queue_pop(nghttp2_outbound_queue *q) {
|
|
|
|
nghttp2_outbound_item *item;
|
|
|
|
if (!q->head) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
item = q->head;
|
|
|
|
q->head = q->head->qnext;
|
|
|
|
item->qnext = NULL;
|
|
|
|
if (!q->head) {
|
|
|
|
q->tail = NULL;
|
|
|
|
}
|
|
|
|
--q->n;
|
|
|
|
}
|