mirror of
https://github.com/moparisthebest/spdylay
synced 2024-11-12 04:25:09 -05:00
Moved spdylay_submit_* functions to spdylay_submit.c
This commit is contained in:
parent
6f0fb62043
commit
a4961a95bd
@ -33,12 +33,14 @@ lib_LTLIBRARIES = libspdylay.la
|
||||
|
||||
OBJECTS = spdylay_pq.c spdylay_map.c spdylay_queue.c \
|
||||
spdylay_buffer.c spdylay_frame.c spdylay_zlib.c \
|
||||
spdylay_session.c spdylay_helper.c spdylay_stream.c spdylay_npn.c
|
||||
spdylay_session.c spdylay_helper.c spdylay_stream.c spdylay_npn.c \
|
||||
spdylay_submit.c
|
||||
|
||||
HFILES = spdylay_pq.h spdylay_int.h spdylay_map.h spdylay_queue.h \
|
||||
spdylay_buffer.h spdylay_frame.h spdylay_zlib.h \
|
||||
spdylay_session.h spdylay_helper.h spdylay_stream.h spdylay_int.h \
|
||||
spdylay_npn.h
|
||||
spdylay_npn.h \
|
||||
spdylay_submit.h
|
||||
|
||||
libspdylay_la_SOURCES = $(HFILES) $(OBJECTS)
|
||||
libspdylay_la_LDFLAGS = -no-undefined \
|
||||
|
@ -1533,141 +1533,6 @@ int spdylay_session_add_goaway(spdylay_session *session,
|
||||
return r;
|
||||
}
|
||||
|
||||
int spdylay_submit_ping(spdylay_session *session)
|
||||
{
|
||||
return spdylay_session_add_ping(session,
|
||||
spdylay_session_get_next_unique_id(session));
|
||||
}
|
||||
|
||||
int spdylay_submit_cancel(spdylay_session *session, int32_t stream_id,
|
||||
uint32_t status_code)
|
||||
{
|
||||
return spdylay_session_add_rst_stream(session, stream_id, status_code);
|
||||
}
|
||||
|
||||
int spdylay_submit_goaway(spdylay_session *session)
|
||||
{
|
||||
return spdylay_session_add_goaway(session, session->last_recv_stream_id);
|
||||
}
|
||||
|
||||
int spdylay_submit_response(spdylay_session *session,
|
||||
int32_t stream_id, const char **nv,
|
||||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
int r;
|
||||
spdylay_frame *frame;
|
||||
char **nv_copy;
|
||||
uint8_t flags = 0;
|
||||
spdylay_data_provider *data_prd_copy = NULL;
|
||||
if(data_prd) {
|
||||
data_prd_copy = malloc(sizeof(spdylay_data_provider));
|
||||
if(data_prd_copy == NULL) {
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
*data_prd_copy = *data_prd;
|
||||
}
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
if(frame == NULL) {
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
nv_copy = spdylay_frame_nv_copy(nv);
|
||||
if(nv_copy == NULL) {
|
||||
free(frame);
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
spdylay_frame_nv_sort(nv_copy);
|
||||
if(data_prd == NULL) {
|
||||
flags |= SPDYLAY_FLAG_FIN;
|
||||
}
|
||||
spdylay_frame_syn_reply_init(&frame->syn_reply, flags, stream_id,
|
||||
nv_copy);
|
||||
r = spdylay_session_add_frame(session, SPDYLAY_SYN_REPLY, frame,
|
||||
data_prd_copy);
|
||||
if(r != 0) {
|
||||
spdylay_frame_syn_reply_free(&frame->syn_reply);
|
||||
free(frame);
|
||||
free(data_prd_copy);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int spdylay_submit_data(spdylay_session *session, int32_t stream_id,
|
||||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
int r;
|
||||
spdylay_frame *frame;
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
if(frame == NULL) {
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
spdylay_frame_data_init(&frame->data, stream_id, data_prd);
|
||||
r = spdylay_session_add_frame(session, SPDYLAY_DATA, frame, NULL);
|
||||
if(r != 0) {
|
||||
spdylay_frame_data_free(&frame->data);
|
||||
free(frame);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int spdylay_submit_request(spdylay_session *session, uint8_t pri,
|
||||
const char **nv, spdylay_data_provider *data_prd,
|
||||
void *stream_user_data)
|
||||
{
|
||||
int r;
|
||||
spdylay_frame *frame;
|
||||
char **nv_copy;
|
||||
uint8_t flags = 0;
|
||||
spdylay_data_provider *data_prd_copy = NULL;
|
||||
spdylay_syn_stream_aux_data *aux_data;
|
||||
if(pri > 3) {
|
||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
if(data_prd) {
|
||||
data_prd_copy = malloc(sizeof(spdylay_data_provider));
|
||||
if(data_prd_copy == NULL) {
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
*data_prd_copy = *data_prd;
|
||||
}
|
||||
aux_data = malloc(sizeof(spdylay_syn_stream_aux_data));
|
||||
if(aux_data == NULL) {
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
aux_data->data_prd = data_prd_copy;
|
||||
aux_data->stream_user_data = stream_user_data;
|
||||
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
if(frame == NULL) {
|
||||
free(aux_data);
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
nv_copy = spdylay_frame_nv_copy(nv);
|
||||
if(nv_copy == NULL) {
|
||||
free(frame);
|
||||
free(aux_data);
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
spdylay_frame_nv_sort(nv_copy);
|
||||
if(data_prd == NULL) {
|
||||
flags |= SPDYLAY_FLAG_FIN;
|
||||
}
|
||||
spdylay_frame_syn_stream_init(&frame->syn_stream, flags, 0, 0, pri, nv_copy);
|
||||
r = spdylay_session_add_frame(session, SPDYLAY_SYN_STREAM, frame,
|
||||
aux_data);
|
||||
if(r != 0) {
|
||||
spdylay_frame_syn_stream_free(&frame->syn_stream);
|
||||
free(frame);
|
||||
free(aux_data);
|
||||
free(data_prd_copy);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
||||
uint8_t **buf_ptr, spdylay_data *frame)
|
||||
{
|
||||
|
163
lib/spdylay_submit.c
Normal file
163
lib/spdylay_submit.c
Normal file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Spdylay - SPDY Library
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "spdylay_submit.h"
|
||||
|
||||
#include "spdylay_session.h"
|
||||
#include "spdylay_frame.h"
|
||||
|
||||
int spdylay_submit_ping(spdylay_session *session)
|
||||
{
|
||||
return spdylay_session_add_ping(session,
|
||||
spdylay_session_get_next_unique_id(session));
|
||||
}
|
||||
|
||||
int spdylay_submit_cancel(spdylay_session *session, int32_t stream_id,
|
||||
uint32_t status_code)
|
||||
{
|
||||
return spdylay_session_add_rst_stream(session, stream_id, status_code);
|
||||
}
|
||||
|
||||
int spdylay_submit_goaway(spdylay_session *session)
|
||||
{
|
||||
return spdylay_session_add_goaway(session, session->last_recv_stream_id);
|
||||
}
|
||||
|
||||
int spdylay_submit_response(spdylay_session *session,
|
||||
int32_t stream_id, const char **nv,
|
||||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
int r;
|
||||
spdylay_frame *frame;
|
||||
char **nv_copy;
|
||||
uint8_t flags = 0;
|
||||
spdylay_data_provider *data_prd_copy = NULL;
|
||||
if(data_prd) {
|
||||
data_prd_copy = malloc(sizeof(spdylay_data_provider));
|
||||
if(data_prd_copy == NULL) {
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
*data_prd_copy = *data_prd;
|
||||
}
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
if(frame == NULL) {
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
nv_copy = spdylay_frame_nv_copy(nv);
|
||||
if(nv_copy == NULL) {
|
||||
free(frame);
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
spdylay_frame_nv_sort(nv_copy);
|
||||
if(data_prd == NULL) {
|
||||
flags |= SPDYLAY_FLAG_FIN;
|
||||
}
|
||||
spdylay_frame_syn_reply_init(&frame->syn_reply, flags, stream_id,
|
||||
nv_copy);
|
||||
r = spdylay_session_add_frame(session, SPDYLAY_SYN_REPLY, frame,
|
||||
data_prd_copy);
|
||||
if(r != 0) {
|
||||
spdylay_frame_syn_reply_free(&frame->syn_reply);
|
||||
free(frame);
|
||||
free(data_prd_copy);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int spdylay_submit_data(spdylay_session *session, int32_t stream_id,
|
||||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
int r;
|
||||
spdylay_frame *frame;
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
if(frame == NULL) {
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
spdylay_frame_data_init(&frame->data, stream_id, data_prd);
|
||||
r = spdylay_session_add_frame(session, SPDYLAY_DATA, frame, NULL);
|
||||
if(r != 0) {
|
||||
spdylay_frame_data_free(&frame->data);
|
||||
free(frame);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int spdylay_submit_request(spdylay_session *session, uint8_t pri,
|
||||
const char **nv, spdylay_data_provider *data_prd,
|
||||
void *stream_user_data)
|
||||
{
|
||||
int r;
|
||||
spdylay_frame *frame;
|
||||
char **nv_copy;
|
||||
uint8_t flags = 0;
|
||||
spdylay_data_provider *data_prd_copy = NULL;
|
||||
spdylay_syn_stream_aux_data *aux_data;
|
||||
if(pri > 3) {
|
||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
if(data_prd) {
|
||||
data_prd_copy = malloc(sizeof(spdylay_data_provider));
|
||||
if(data_prd_copy == NULL) {
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
*data_prd_copy = *data_prd;
|
||||
}
|
||||
aux_data = malloc(sizeof(spdylay_syn_stream_aux_data));
|
||||
if(aux_data == NULL) {
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
aux_data->data_prd = data_prd_copy;
|
||||
aux_data->stream_user_data = stream_user_data;
|
||||
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
if(frame == NULL) {
|
||||
free(aux_data);
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
nv_copy = spdylay_frame_nv_copy(nv);
|
||||
if(nv_copy == NULL) {
|
||||
free(frame);
|
||||
free(aux_data);
|
||||
free(data_prd_copy);
|
||||
return SPDYLAY_ERR_NOMEM;
|
||||
}
|
||||
spdylay_frame_nv_sort(nv_copy);
|
||||
if(data_prd == NULL) {
|
||||
flags |= SPDYLAY_FLAG_FIN;
|
||||
}
|
||||
spdylay_frame_syn_stream_init(&frame->syn_stream, flags, 0, 0, pri, nv_copy);
|
||||
r = spdylay_session_add_frame(session, SPDYLAY_SYN_STREAM, frame,
|
||||
aux_data);
|
||||
if(r != 0) {
|
||||
spdylay_frame_syn_stream_free(&frame->syn_stream);
|
||||
free(frame);
|
||||
free(aux_data);
|
||||
free(data_prd_copy);
|
||||
}
|
||||
return r;
|
||||
}
|
34
lib/spdylay_submit.h
Normal file
34
lib/spdylay_submit.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Spdylay - SPDY Library
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef SPDYLAY_SUBMIT_H
|
||||
#define SPDYLAY_SUBMIT_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <spdylay/spdylay.h>
|
||||
|
||||
#endif /* SPDYLAY_SUBMIT_H */
|
Loading…
Reference in New Issue
Block a user