mirror of
https://github.com/nghttp2/nghttp2.git
synced 2025-12-08 19:18:53 +08:00
Remove nghttp2_submit_* API functions which has char **nv parameter
The nghttp2_submit_{request,response}2 functions are renamed as
nghttp2_submit_{request, response}.
This commit is contained in:
@@ -1764,27 +1764,20 @@ const char* nghttp2_strerror(int lib_error_code);
|
||||
* The |pri| is priority of this request. 0 is the highest priority
|
||||
* value and :macro:`NGHTTP2_PRI_LOWEST` is the lowest value.
|
||||
*
|
||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
||||
* pointer to the value string. The one beyond last value must be
|
||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
||||
* ``nv[2*N]`` must be ``NULL``.
|
||||
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||
* |nvlen| elements.
|
||||
*
|
||||
* HTTP/2.0 specification has requirement about header fields in the
|
||||
* request HEADERS. See the specification for more details.
|
||||
*
|
||||
* This function creates copies of all name/value pairs in |nv|. It
|
||||
* also lower-cases all names in |nv|.
|
||||
*
|
||||
* The string in |nv| must be NULL-terminated. Use
|
||||
* `nghttp2_submit_request2()` if name/value pairs are not
|
||||
* NULL-terminated strings.
|
||||
* This function creates copies of all name/value pairs in |nva|. It
|
||||
* also lower-cases all names in |nva|.
|
||||
*
|
||||
* If |data_prd| is not ``NULL``, it provides data which will be sent
|
||||
* in subsequent DATA frames. In this case, a method that allows
|
||||
* request message bodies
|
||||
* (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9) must
|
||||
* be specified with ``:method`` key in |nv| (e.g. ``POST``). This
|
||||
* be specified with ``:method`` key in |nva| (e.g. ``POST``). This
|
||||
* function does not take ownership of the |data_prd|. The function
|
||||
* copies the members of the |data_prd|. If |data_prd| is ``NULL``,
|
||||
* HEADERS have END_STREAM set. The |stream_user_data| is data
|
||||
@@ -1808,55 +1801,30 @@ const char* nghttp2_strerror(int lib_error_code);
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||
* The |pri| is invalid; or the |nv| includes empty name or
|
||||
* ``NULL`` value.
|
||||
* The |pri| is invalid; or the |nva| includes empty name, or name
|
||||
* which contains invalid characters.
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_submit_request(nghttp2_session *session, int32_t pri,
|
||||
const char **nv,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd,
|
||||
void *stream_user_data);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Just like `nghttp2_submit_request()`, but this function takes the
|
||||
* |nva|, which is an array of ``nghttp2_nv`` with |nvlen| elements,
|
||||
* as name/value pairs. This function is useful if name/value pairs
|
||||
* are not NULL-terminated strings.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||
* The |pri| is invalid; or the |nva| includes empty name or
|
||||
* name which contains invalid characters.
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_submit_request2(nghttp2_session *session, int32_t pri,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd,
|
||||
void *stream_user_data);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Submits response HEADERS frame and optionally one or more DATA
|
||||
* frames against the stream |stream_id|.
|
||||
*
|
||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
||||
* pointer to the value string. The one beyond last value must be
|
||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
||||
* ``nv[2*N]`` must be ``NULL``.
|
||||
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||
* |nvlen| elements.
|
||||
*
|
||||
* HTTP/2.0 specification has requirement about header fields in the
|
||||
* response HEADERS. See the specification for more details.
|
||||
*
|
||||
* This function creates copies of all name/value pairs in |nv|. It
|
||||
* also lower-cases all names in |nv|.
|
||||
* This function creates copies of all name/value pairs in |nva|. It
|
||||
* also lower-cases all names in |nva|.
|
||||
*
|
||||
* If |data_prd| is not ``NULL``, it provides data which will be sent
|
||||
* in subsequent DATA frames. This function does not take ownership
|
||||
@@ -1868,36 +1836,16 @@ int nghttp2_submit_request2(nghttp2_session *session, int32_t pri,
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||
* The |nv| includes empty name or ``NULL`` value.
|
||||
* The |nva| includes empty name or name which contains invalid
|
||||
* characters.
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_submit_response(nghttp2_session *session,
|
||||
int32_t stream_id, const char **nv,
|
||||
int32_t stream_id,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Just like `nghttp2_submit_response()`, but this function takes the
|
||||
* |nva|, which is an array of ``nghttp2_nv`` with |nvlen| elements,
|
||||
* as name/value pairs. This function is useful if name/value pairs
|
||||
* are not NULL-terminated strings.
|
||||
*
|
||||
* This function returns 0 if it succeeds, or one of the following
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||
* The |pri| is invalid; or the |nva| includes empty name or
|
||||
* name which contains invalid characters.
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_submit_response2(nghttp2_session *session,
|
||||
int32_t stream_id,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
@@ -1921,14 +1869,11 @@ int nghttp2_submit_response2(nghttp2_session *session,
|
||||
*
|
||||
* The |pri| is priority of this request.
|
||||
*
|
||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
||||
* pointer to the value string. The one beyond last value must be
|
||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
||||
* ``nv[2*N]`` must be ``NULL``.
|
||||
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||
* |nvlen| elements.
|
||||
*
|
||||
* This function creates copies of all name/value pairs in |nv|. It
|
||||
* also lower-cases all names in |nv|.
|
||||
* This function creates copies of all name/value pairs in |nva|. It
|
||||
* also lower-cases all names in |nva|.
|
||||
*
|
||||
* The |stream_user_data| is a pointer to an arbitrary data which is
|
||||
* associated to the stream this frame will open. Therefore it is only
|
||||
@@ -1943,13 +1888,14 @@ int nghttp2_submit_response2(nghttp2_session *session,
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||
* The |pri| is invalid; or the |nv| includes empty name or
|
||||
* ``NULL`` value.
|
||||
* The |pri| is invalid; or the |nva| includes empty name, or name
|
||||
* which contains invalid characters.
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
||||
int32_t stream_id, int32_t pri, const char **nv,
|
||||
int32_t stream_id, int32_t pri,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
void *stream_user_data);
|
||||
|
||||
/**
|
||||
@@ -2059,14 +2005,11 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||
*
|
||||
* The |stream_id| must be client initiated stream ID.
|
||||
*
|
||||
* The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]``
|
||||
* contains a pointer to the name string and ``nv[2*i+1]`` contains a
|
||||
* pointer to the value string. The one beyond last value must be
|
||||
* ``NULL``. That is, if the |nv| contains N name/value pairs,
|
||||
* ``nv[2*N]`` must be ``NULL``.
|
||||
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
|
||||
* |nvlen| elements.
|
||||
*
|
||||
* This function creates copies of all name/value pairs in |nv|. It
|
||||
* also lower-cases all names in |nv|.
|
||||
* This function creates copies of all name/value pairs in |nva|. It
|
||||
* also lower-cases all names in |nva|.
|
||||
*
|
||||
* Since the library reorders the frames and tries to send the highest
|
||||
* prioritized one first and the HTTP/2.0 specification requires the
|
||||
@@ -2081,14 +2024,16 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||
* negative error codes:
|
||||
*
|
||||
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
|
||||
* The |nv| includes empty name or ``NULL`` value.
|
||||
* The |nva| includes empty name, or name which contains invalid
|
||||
* characters.
|
||||
* :enum:`NGHTTP2_ERR_STREAM_CLOSED`
|
||||
* The stream is already closed or does not exist.
|
||||
* :enum:`NGHTTP2_ERR_NOMEM`
|
||||
* Out of memory.
|
||||
*/
|
||||
int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
||||
int32_t stream_id, const char **nv);
|
||||
int32_t stream_id,
|
||||
const nghttp2_nv *nva, size_t nvlen);
|
||||
|
||||
/**
|
||||
* @function
|
||||
|
||||
@@ -585,19 +585,6 @@ nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
||||
return iv_copy;
|
||||
}
|
||||
|
||||
int nghttp2_frame_nv_check_null(const char **nv)
|
||||
{
|
||||
size_t i;
|
||||
for(i = 0; nv[i]; i += 2) {
|
||||
if(nv[i+1] == NULL ||
|
||||
!nghttp2_check_header_name_nocase((const uint8_t*)nv[i],
|
||||
strlen(nv[i]))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nghttp2_nv_array_check_null(const nghttp2_nv *nva, size_t nvlen)
|
||||
{
|
||||
size_t i;
|
||||
@@ -665,50 +652,6 @@ void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen)
|
||||
qsort(nva, nvlen, sizeof(nghttp2_nv), nv_compar);
|
||||
}
|
||||
|
||||
ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv)
|
||||
{
|
||||
int i;
|
||||
uint8_t *data;
|
||||
size_t buflen = 0, nvlen = 0;
|
||||
nghttp2_nv *p;
|
||||
for(i = 0; nv[i]; ++i) {
|
||||
size_t len = strlen(nv[i]);
|
||||
if(len > NGHTTP2_MAX_HD_VALUE_LENGTH) {
|
||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
buflen += len;
|
||||
}
|
||||
nvlen = i/2;
|
||||
/* If all name/value pair is 0-length, remove them */
|
||||
if(nvlen == 0 || buflen == 0) {
|
||||
*nva_ptr = NULL;
|
||||
return 0;
|
||||
}
|
||||
buflen += sizeof(nghttp2_nv)*nvlen;
|
||||
*nva_ptr = malloc(buflen);
|
||||
if(*nva_ptr == NULL) {
|
||||
return NGHTTP2_ERR_NOMEM;
|
||||
}
|
||||
p = *nva_ptr;
|
||||
data = (uint8_t*)(*nva_ptr) + sizeof(nghttp2_nv)*nvlen;
|
||||
|
||||
for(i = 0; nv[i]; i += 2) {
|
||||
size_t len = strlen(nv[i]);
|
||||
memcpy(data, nv[i], len);
|
||||
p->name = data;
|
||||
p->namelen = len;
|
||||
nghttp2_downcase(p->name, p->namelen);
|
||||
data += len;
|
||||
len = strlen(nv[i+1]);
|
||||
memcpy(data, nv[i+1], len);
|
||||
p->value = data;
|
||||
p->valuelen = len;
|
||||
data += len;
|
||||
++p;
|
||||
}
|
||||
return nvlen;
|
||||
}
|
||||
|
||||
ssize_t nghttp2_nv_array_copy(nghttp2_nv **nva_ptr,
|
||||
const nghttp2_nv *nva, size_t nvlen)
|
||||
{
|
||||
|
||||
@@ -514,37 +514,12 @@ void nghttp2_frame_data_free(nghttp2_data *frame);
|
||||
nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
||||
size_t niv);
|
||||
|
||||
/*
|
||||
* Checks names are not empty string and do not contain control
|
||||
* characters and values are not NULL.
|
||||
*
|
||||
* This function returns nonzero if it succeeds, or 0.
|
||||
*/
|
||||
int nghttp2_frame_nv_check_null(const char **nv);
|
||||
|
||||
/*
|
||||
* Sorts the |nva| in ascending order of name and value. If names are
|
||||
* equivalent, sort them by value.
|
||||
*/
|
||||
void nghttp2_nv_array_sort(nghttp2_nv *nva, size_t nvlen);
|
||||
|
||||
/*
|
||||
* Copies name/value pairs from |nv| to |*nva_ptr|, which is
|
||||
* dynamically allocated so that all items can be stored.
|
||||
*
|
||||
* The |*nva_ptr| must be freed using nghttp2_nv_array_del().
|
||||
*
|
||||
* This function returns the number of name/value pairs in |*nva_ptr|,
|
||||
* or one of the following negative error codes:
|
||||
*
|
||||
* NGHTTP2_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||
* The length of name or value in |nv| is strictly larger than
|
||||
* NGHTTP2_MAX_HD_VALUE_LENGTH.
|
||||
*/
|
||||
ssize_t nghttp2_nv_array_from_cstr(nghttp2_nv **nva_ptr, const char **nv);
|
||||
|
||||
/*
|
||||
* Copies name/value pairs from |nva|, which contains |nvlen| pairs,
|
||||
* to |*nva_ptr|, which is dynamically allocated so that all items can
|
||||
|
||||
@@ -98,29 +98,6 @@ static int nghttp2_submit_headers_shared
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int nghttp2_submit_headers_shared_nv
|
||||
(nghttp2_session *session,
|
||||
uint8_t flags,
|
||||
int32_t stream_id,
|
||||
int32_t pri,
|
||||
const char **nv,
|
||||
const nghttp2_data_provider *data_prd,
|
||||
void *stream_user_data)
|
||||
{
|
||||
ssize_t nvlen;
|
||||
nghttp2_nv *nva_copy;
|
||||
if(!nghttp2_frame_nv_check_null(nv)) {
|
||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
nvlen = nghttp2_nv_array_from_cstr(&nva_copy, nv);
|
||||
if(nvlen < 0) {
|
||||
return nvlen;
|
||||
}
|
||||
return nghttp2_submit_headers_shared(session, flags, stream_id,
|
||||
pri, nva_copy, nvlen, data_prd,
|
||||
stream_user_data);
|
||||
}
|
||||
|
||||
static int nghttp2_submit_headers_shared_nva
|
||||
(nghttp2_session *session,
|
||||
uint8_t flags,
|
||||
@@ -147,10 +124,11 @@ static int nghttp2_submit_headers_shared_nva
|
||||
|
||||
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
||||
int32_t stream_id, int32_t pri,
|
||||
const char **nv, void *stream_user_data)
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
void *stream_user_data)
|
||||
{
|
||||
return nghttp2_submit_headers_shared_nv(session, flags, stream_id,
|
||||
pri, nv, NULL, stream_user_data);
|
||||
return nghttp2_submit_headers_shared_nva(session, flags, stream_id, pri,
|
||||
nva, nvlen, NULL, stream_user_data);
|
||||
}
|
||||
|
||||
|
||||
@@ -213,35 +191,35 @@ int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||
}
|
||||
|
||||
int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
|
||||
int32_t stream_id, const char **nv)
|
||||
int32_t stream_id,
|
||||
const nghttp2_nv *nva, size_t nvlen)
|
||||
{
|
||||
nghttp2_frame *frame;
|
||||
nghttp2_nv *nva;
|
||||
ssize_t nvlen;
|
||||
nghttp2_nv *nva_copy;
|
||||
uint8_t flags_copy;
|
||||
int r;
|
||||
int rv;
|
||||
|
||||
if(!nghttp2_nv_array_check_null(nva, nvlen)) {
|
||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
if(nghttp2_session_get_stream(session, stream_id) == NULL) {
|
||||
return NGHTTP2_ERR_STREAM_CLOSED;
|
||||
}
|
||||
if(!nghttp2_frame_nv_check_null(nv)) {
|
||||
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
frame = malloc(sizeof(nghttp2_frame));
|
||||
if(frame == NULL) {
|
||||
return NGHTTP2_ERR_NOMEM;
|
||||
}
|
||||
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
|
||||
if(nvlen < 0) {
|
||||
rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen);
|
||||
if(rv < 0) {
|
||||
free(frame);
|
||||
return nvlen;
|
||||
return rv;
|
||||
}
|
||||
/* TODO Implement header continuation */
|
||||
flags_copy = NGHTTP2_FLAG_END_PUSH_PROMISE;
|
||||
nghttp2_frame_push_promise_init(&frame->push_promise, flags_copy,
|
||||
stream_id, -1, nva, nvlen);
|
||||
r = nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL);
|
||||
if(r != 0) {
|
||||
stream_id, -1, nva_copy, nvlen);
|
||||
rv = nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL);
|
||||
if(rv != 0) {
|
||||
nghttp2_frame_push_promise_free(&frame->push_promise);
|
||||
free(frame);
|
||||
}
|
||||
@@ -307,19 +285,9 @@ static uint8_t set_request_flags(int32_t pri,
|
||||
}
|
||||
|
||||
int nghttp2_submit_request(nghttp2_session *session, int32_t pri,
|
||||
const char **nv,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd,
|
||||
void *stream_user_data)
|
||||
{
|
||||
uint8_t flags = set_request_flags(pri, data_prd);
|
||||
return nghttp2_submit_headers_shared_nv(session, flags, -1, pri, nv,
|
||||
data_prd, stream_user_data);
|
||||
}
|
||||
|
||||
int nghttp2_submit_request2(nghttp2_session *session, int32_t pri,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd,
|
||||
void *stream_user_data)
|
||||
{
|
||||
uint8_t flags = set_request_flags(pri, data_prd);
|
||||
return nghttp2_submit_headers_shared_nva(session, flags, -1, pri, nva, nvlen,
|
||||
@@ -336,19 +304,9 @@ static uint8_t set_response_flags(const nghttp2_data_provider *data_prd)
|
||||
}
|
||||
|
||||
int nghttp2_submit_response(nghttp2_session *session,
|
||||
int32_t stream_id, const char **nv,
|
||||
int32_t stream_id,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd)
|
||||
{
|
||||
uint8_t flags = set_response_flags(data_prd);
|
||||
return nghttp2_submit_headers_shared_nv(session, flags, stream_id,
|
||||
NGHTTP2_PRI_DEFAULT, nv, data_prd,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int nghttp2_submit_response2(nghttp2_session *session,
|
||||
int32_t stream_id,
|
||||
const nghttp2_nv *nva, size_t nvlen,
|
||||
const nghttp2_data_provider *data_prd)
|
||||
{
|
||||
uint8_t flags = set_response_flags(data_prd);
|
||||
return nghttp2_submit_headers_shared_nva(session, flags, stream_id,
|
||||
|
||||
Reference in New Issue
Block a user