void test_nghttp2_frame_pack_priority(void) { nghttp2_priority frame, oframe; nghttp2_bufs bufs; nghttp2_priority_spec pri_spec; int rv; frame_pack_bufs_init(&bufs); /* First, pack priority with priority group and weight */ nghttp2_priority_spec_init(&pri_spec, 1000000009, 12, 1); nghttp2_frame_priority_init(&frame, 1000000007, &pri_spec); rv = nghttp2_frame_pack_priority(&bufs, &frame); CU_ASSERT(0 == rv); CU_ASSERT(NGHTTP2_FRAME_HDLEN + 5 == nghttp2_bufs_len(&bufs)); CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs)); check_frame_header(5, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); CU_ASSERT(1000000009 == oframe.pri_spec.stream_id); CU_ASSERT(12 == oframe.pri_spec.weight); CU_ASSERT(1 == oframe.pri_spec.exclusive); nghttp2_frame_priority_free(&oframe); nghttp2_bufs_reset(&bufs); nghttp2_bufs_free(&bufs); nghttp2_frame_priority_free(&frame); }
void nghttp2_outbound_item_free(nghttp2_outbound_item *item) { if(item == NULL) { return; } if(item->frame_cat == NGHTTP2_CAT_CTRL) { nghttp2_frame *frame; frame = nghttp2_outbound_item_get_ctrl_frame(item); switch(frame->hd.type) { case NGHTTP2_HEADERS: nghttp2_frame_headers_free(&frame->headers); if(item->aux_data) { free(((nghttp2_headers_aux_data*)item->aux_data)->data_prd); } 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: nghttp2_frame_settings_free(&frame->settings); break; case NGHTTP2_PUSH_PROMISE: nghttp2_frame_push_promise_free(&frame->push_promise); break; case NGHTTP2_PING: nghttp2_frame_ping_free(&frame->ping); break; case NGHTTP2_GOAWAY: nghttp2_frame_goaway_free(&frame->goaway); break; case NGHTTP2_WINDOW_UPDATE: nghttp2_frame_window_update_free(&frame->window_update); break; case NGHTTP2_EXT_ALTSVC: nghttp2_frame_altsvc_free(&frame->ext); free(frame->ext.payload); break; } } else if(item->frame_cat == NGHTTP2_CAT_DATA) { nghttp2_private_data *data_frame; data_frame = nghttp2_outbound_item_get_data_frame(item); nghttp2_frame_private_data_free(data_frame); } else { /* Unreachable */ assert(0); } free(item->frame); free(item->aux_data); }
int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags _U_, int32_t stream_id, const nghttp2_priority_spec *pri_spec) { int rv; nghttp2_outbound_item *item; nghttp2_frame *frame; nghttp2_priority_spec copy_pri_spec; nghttp2_mem *mem; mem = &session->mem; if (stream_id == 0 || pri_spec == NULL) { return NGHTTP2_ERR_INVALID_ARGUMENT; } if (stream_id == pri_spec->stream_id) { return NGHTTP2_ERR_INVALID_ARGUMENT; } copy_pri_spec = *pri_spec; nghttp2_priority_spec_normalize_weight(©_pri_spec); 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_priority_init(&frame->priority, stream_id, ©_pri_spec); rv = nghttp2_session_add_item(session, item); if (rv != 0) { nghttp2_frame_priority_free(&frame->priority); nghttp2_mem_free(mem, item); return rv; } return 0; }