ssize_t nghttp2_frame_pack_push_promise(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_push_promise *frame, nghttp2_hd_context *deflater) { ssize_t framelen; size_t nv_offset = NGHTTP2_FRAME_HEAD_LENGTH + 4; ssize_t rv; rv = nghttp2_hd_deflate_hd(deflater, buf_ptr, buflen_ptr, nv_offset, frame->nva, frame->nvlen); if(rv < 0) { return rv; } framelen = rv + nv_offset; frame->hd.length = framelen - NGHTTP2_FRAME_HEAD_LENGTH; /* If frame->nvlen == 0, *buflen_ptr may be smaller than nv_offset */ rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, nv_offset); if(rv < 0) { return rv; } memset(*buf_ptr, 0, nv_offset); /* pack ctrl header after length is determined */ nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); nghttp2_put_uint32be(&(*buf_ptr)[8], frame->promised_stream_id); return framelen; }
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_headers *frame, nghttp2_hd_context *deflater) { ssize_t framelen; size_t nv_offset = headers_nv_offset(frame); ssize_t rv; rv = nghttp2_hd_deflate_hd(deflater, buf_ptr, buflen_ptr, nv_offset, frame->nva, frame->nvlen); if(rv < 0) { return rv; } framelen = rv + nv_offset; frame->hd.length = framelen - NGHTTP2_FRAME_HEAD_LENGTH; /* If frame->nvlen == 0, *buflen_ptr may be smaller than nv_offset */ rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, nv_offset); if(rv < 0) { return rv; } memset(*buf_ptr, 0, nv_offset); /* pack ctrl header after length is determined */ nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY) { nghttp2_put_uint32be(&(*buf_ptr)[8], frame->pri); } return framelen; }
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr, size_t *bufoff_ptr, nghttp2_headers *frame, nghttp2_hd_deflater *deflater) { size_t payloadoff = NGHTTP2_FRAME_HEAD_LENGTH + 2; size_t nv_offset = payloadoff + nghttp2_frame_headers_payload_nv_offset(frame); ssize_t rv; size_t payloadlen; rv = nghttp2_hd_deflate_hd(deflater, buf_ptr, buflen_ptr, nv_offset, frame->nva, frame->nvlen); if(rv < 0) { return rv; } payloadlen = nghttp2_frame_headers_payload_nv_offset(frame) + rv; *bufoff_ptr = 2; frame->padlen = 0; frame->hd.length = payloadlen; /* If frame->nvlen == 0, *buflen_ptr may be smaller than nv_offset */ rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, nv_offset); if(rv < 0) { return rv; } memset(*buf_ptr + *bufoff_ptr, 0, NGHTTP2_FRAME_HEAD_LENGTH); /* pack ctrl header after length is determined */ if(NGHTTP2_MAX_FRAME_LENGTH < payloadlen) { /* Needs CONTINUATION */ nghttp2_frame_hd hd = frame->hd; hd.flags &= ~NGHTTP2_FLAG_END_HEADERS; hd.length = NGHTTP2_MAX_FRAME_LENGTH; nghttp2_frame_pack_frame_hd(*buf_ptr + *bufoff_ptr, &hd); } else { nghttp2_frame_pack_frame_hd(*buf_ptr + *bufoff_ptr, &frame->hd); } if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY) { nghttp2_put_uint32be(&(*buf_ptr)[payloadoff], frame->pri); } return *bufoff_ptr + NGHTTP2_FRAME_HEAD_LENGTH + frame->hd.length; }
ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_window_update *frame) { ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH + 4; int rv; rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(rv != 0) { return rv; } memset(*buf_ptr, 0, framelen); nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); nghttp2_put_uint32be(&(*buf_ptr)[8], frame->window_size_increment); return framelen; }
ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_ping *frame) { ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH + 8; int rv; rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(rv != 0) { return rv; } memset(*buf_ptr, 0, framelen); nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); memcpy(&(*buf_ptr)[8], frame->opaque_data, sizeof(frame->opaque_data)); return framelen; }
ssize_t nghttp2_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_settings *frame) { ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH + frame->hd.length; int rv; rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(rv != 0) { return rv; } memset(*buf_ptr, 0, framelen); nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); nghttp2_frame_pack_settings_payload(*buf_ptr + 8, frame->iv, frame->niv); return framelen; }
ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_rst_stream *frame) { ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH + 4; int rv; rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(rv != 0) { return rv; } memset(*buf_ptr, 0, framelen); nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); nghttp2_put_uint32be(&(*buf_ptr)[8], frame->error_code); return framelen; }
ssize_t nghttp2_frame_pack_priority(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_priority *frame) { ssize_t framelen= NGHTTP2_FRAME_HEAD_LENGTH + 4; int r; r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); nghttp2_put_uint32be(&(*buf_ptr)[8], frame->pri); return framelen; }
ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr, nghttp2_goaway *frame) { ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH + frame->hd.length; int rv; rv = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(rv != 0) { return rv; } memset(*buf_ptr, 0, framelen); nghttp2_frame_pack_frame_hd(*buf_ptr, &frame->hd); nghttp2_put_uint32be(&(*buf_ptr)[8], frame->last_stream_id); nghttp2_put_uint32be(&(*buf_ptr)[12], frame->error_code); memcpy(&(*buf_ptr)[16], frame->opaque_data, frame->opaque_data_len); return framelen; }