Rebranding nghttp2
This commit is contained in:
parent
7b59a11480
commit
0edce70343
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
SUBDIRS = lib src tests examples doc python
|
SUBDIRS = lib src tests examples doc
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
|
|
73
NEWS
73
NEWS
|
@ -1,73 +0,0 @@
|
||||||
spdylay 1.0.0
|
|
||||||
=============
|
|
||||||
|
|
||||||
Release Note
|
|
||||||
------------
|
|
||||||
|
|
||||||
This release adds several enhancements to the spdyct and shrpx and
|
|
||||||
strict checks for name/value pairs. It fixes the bug that server can
|
|
||||||
not push the stream against server initiated stream ID. The internal
|
|
||||||
priority management mechanism is updated so that outbound DATA frames
|
|
||||||
with variety of SPDY priority can interleave more frequently and don't
|
|
||||||
let the low priority streams starve. The development is very stable
|
|
||||||
now, so we'll make this release 1.0.0.
|
|
||||||
|
|
||||||
Changes
|
|
||||||
-------
|
|
||||||
|
|
||||||
* Adjust priority of outbound DATA frames so that it does not starve
|
|
||||||
others
|
|
||||||
|
|
||||||
This change makes frames with variety of priority interleave more
|
|
||||||
frequently.
|
|
||||||
|
|
||||||
* Drop priveleges only after listening on possibly priveleged port
|
|
||||||
|
|
||||||
Patch from moparisthebest
|
|
||||||
|
|
||||||
* Add --honor-cipher-order option to mitigate BEAST attacks
|
|
||||||
|
|
||||||
Patch from moparisthebest
|
|
||||||
|
|
||||||
* Fix building on mac os x. "error: invalid suffix on literal; C++11
|
|
||||||
requires a space between literal and identifier"
|
|
||||||
|
|
||||||
Patch from snnn
|
|
||||||
|
|
||||||
* Allow server initiated stream ID in associated-stream-id
|
|
||||||
|
|
||||||
* spdycat, shrpx: TLS SNI enhancements
|
|
||||||
|
|
||||||
shrpx:
|
|
||||||
* Added an option to set the TLS SNI extension between shrpx and the
|
|
||||||
origin on the command line
|
|
||||||
|
|
||||||
spdycat:
|
|
||||||
* If the user set an explicit host header ( using --headers ) use that
|
|
||||||
name for the TLS SNI extension.
|
|
||||||
* Added the handshake completion time to the verbose output
|
|
||||||
* The gettimeofday call in get_time was using the incorrect structure
|
|
||||||
( I believe )
|
|
||||||
* In update_html_parser it was submitting the request regardless of
|
|
||||||
the return value of add_request.
|
|
||||||
|
|
||||||
Patch from Stephen Ludin
|
|
||||||
|
|
||||||
* shrpx: Support non-TLS SPDY in frontend connection
|
|
||||||
|
|
||||||
* Don't allow control characters in outgoing name/value pairs
|
|
||||||
|
|
||||||
This check is done in spdylay_submit_* family functions and they
|
|
||||||
will return error if they found control characters.
|
|
||||||
|
|
||||||
* Don't pack multiple empty header values in one header field
|
|
||||||
|
|
||||||
SPDY spec does not allow multiple empty header values in one header
|
|
||||||
field. This change makes out-going framer ignore such empty header
|
|
||||||
value if there is non-empty header value with the same name.
|
|
||||||
|
|
||||||
* Fix the incoming last empty header value is not checked properly
|
|
||||||
|
|
||||||
This change fixes the bug that spdylay_frame_unpack_nv does not
|
|
||||||
check the size of header value if it is the last value in NULL
|
|
||||||
separated list.
|
|
620
README.rst
620
README.rst
|
@ -1,603 +1,27 @@
|
||||||
Spdylay - SPDY C Library
|
nghttp2 - HTTP/2.0 C Library
|
||||||
========================
|
============================
|
||||||
|
|
||||||
This is an experimental implementation of Google's SPDY protocol in C.
|
This is an experimental implementation of Hypertext Transfer Protocol
|
||||||
|
version 2.0.
|
||||||
This library provides SPDY version 2 and 3 framing layer
|
|
||||||
implementation. It does not perform any I/O operations. When the
|
|
||||||
library needs them, it calls the callback functions provided by the
|
|
||||||
application. It also does not include any event polling mechanism, so
|
|
||||||
the application can freely choose the way of handling events. This
|
|
||||||
library code does not depend on any particular SSL library (except for
|
|
||||||
example programs which depend on OpenSSL 1.0.1 or later).
|
|
||||||
|
|
||||||
This project also develops SPDY client, server and proxy on top of
|
|
||||||
Spdylay library. See `SPDY Client and Server Programs`_ section.
|
|
||||||
|
|
||||||
Development Status
|
Development Status
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
Most of the SPDY/2 and SPDY/3 functionality has been implemented. In
|
We started work based on spdylay codebase and just replaced spdylay
|
||||||
both versions, the direct support of server-push has not been
|
keyword with nghttp2. So just now it is just a relabled SPDY
|
||||||
available yet. The application can achieve server-push using
|
implementation and is not HTTP/2.0 implementation at all. To take
|
||||||
primitive APIs though.
|
advantage of the existing code, we will perform the following steps to
|
||||||
|
implement HTTP/2.0 based on implementation draft
|
||||||
As described below, we can create SPDY client and server with the
|
(http://tools.ietf.org/html/draft-ietf-httpbis-http2-04):
|
||||||
current Spdylay API.
|
|
||||||
|
1. Implement HTTP/2.0 frames and semantics, except for header
|
||||||
Requirements
|
compression. Server push may be omitted because I am not so
|
||||||
------------
|
interested in it.
|
||||||
|
2. Modify spdycat and spdyd to work with new library code and perform
|
||||||
The following packages are needed to build the library:
|
internal testing. We use NPN for TLS for now.
|
||||||
|
3. Implement header compression, which may be based on draft-x (x >=
|
||||||
* pkg-config >= 0.20
|
1).
|
||||||
* zlib >= 1.2.3
|
4. Add new client and server which can perform HTTP upgrade mechanism.
|
||||||
|
5. At this step, the library and demo client/server should be
|
||||||
To build and run the unit test programs, the following packages are
|
interoperable to the other implementation. Do some interoperable
|
||||||
needed:
|
testing with the other ones (e.g., node-http2)
|
||||||
|
|
||||||
* cunit >= 2.1
|
|
||||||
|
|
||||||
To build and run the example programs, the following packages are
|
|
||||||
needed:
|
|
||||||
|
|
||||||
* OpenSSL >= 1.0.1
|
|
||||||
|
|
||||||
To enable ``-a`` option (getting linked assets from the downloaded
|
|
||||||
resouce) in ``spdycat`` (one of the example program), the following
|
|
||||||
packages are needed:
|
|
||||||
|
|
||||||
* libxml2 >= 2.7.7
|
|
||||||
|
|
||||||
To build SPDY/HTTPS to HTTP reverse proxy ``shrpx`` (one of the
|
|
||||||
example program), the following packages are needed:
|
|
||||||
|
|
||||||
* libevent-openssl >= 2.0.8
|
|
||||||
|
|
||||||
If you are using Ubuntu 12.04, you need the following packages
|
|
||||||
installed:
|
|
||||||
|
|
||||||
* autoconf
|
|
||||||
* automake
|
|
||||||
* autotools-dev
|
|
||||||
* libtool
|
|
||||||
* pkg-config
|
|
||||||
* zlib1g-dev
|
|
||||||
* libcunit1-dev
|
|
||||||
* libssl-dev
|
|
||||||
* libxml2-dev
|
|
||||||
* libevent-dev
|
|
||||||
|
|
||||||
Build from git
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Building from git is easy, but please be sure that at least autoconf 2.68 is
|
|
||||||
used::
|
|
||||||
|
|
||||||
$ autoreconf -i
|
|
||||||
$ automake
|
|
||||||
$ autoconf
|
|
||||||
$ ./configure
|
|
||||||
$ make
|
|
||||||
|
|
||||||
Building documentation
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
To build documentation, run::
|
|
||||||
|
|
||||||
$ make html
|
|
||||||
|
|
||||||
The documents will be generated under ``doc/manual/html/``.
|
|
||||||
|
|
||||||
The generated documents will not be installed with ``make install``.
|
|
||||||
|
|
||||||
Building Android binary
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
In this section, we briefly describe how to build Android binary using
|
|
||||||
`Android NDK <http://developer.android.com/tools/sdk/ndk/index.html>`_
|
|
||||||
cross-compiler on Debian Linux.
|
|
||||||
|
|
||||||
We offer ``android-config`` and ``android-make`` scripts to make the
|
|
||||||
build easier. To make these script work, NDK toolchain must be
|
|
||||||
installed in the following way. First, let introduce ``ANDROID_HOME``
|
|
||||||
environment variable. We need to install toolchain under
|
|
||||||
``$ANDROID_HOME/toolchain``. An user can freely choose the path for
|
|
||||||
``ANDROID_HOME``. For example, to install toolchain under
|
|
||||||
``$ANDROID_HOME/toolchain``, do this in the the directory where NDK is
|
|
||||||
unpacked::
|
|
||||||
|
|
||||||
$ build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=$ANDROID_HOME/toolchain
|
|
||||||
|
|
||||||
The platform level is not important here because we don't use Android
|
|
||||||
specific C/C++ API.
|
|
||||||
|
|
||||||
The dependent libraries, such as OpenSSL and libevent should be built
|
|
||||||
with the toolchain and installed under ``$ANDROID_HOME/usr/local``.
|
|
||||||
We recommend to build these libraries as static library to make the
|
|
||||||
deployment easier. libxml2 support is currently disabled.
|
|
||||||
|
|
||||||
We use zlib which comes with Android NDK, so we don't have to build it
|
|
||||||
by ourselves.
|
|
||||||
|
|
||||||
Before running ``android-config`` and ``android-make``,
|
|
||||||
``ANDOIRD_HOME`` environment variable must be set to point to the
|
|
||||||
correct path.
|
|
||||||
|
|
||||||
After ``android-config``, run ``android-make`` to compile sources.
|
|
||||||
``android-make`` is just include path to cross compiler in ``PATH``
|
|
||||||
and run make. So if you include path to corss compiler by yourself,
|
|
||||||
you can just run make to build spdylay and tools as usual.
|
|
||||||
|
|
||||||
API
|
|
||||||
---
|
|
||||||
|
|
||||||
The public API reference is available on online. Visit
|
|
||||||
http://spdylay.sourceforge.net/. All public APIs are in
|
|
||||||
*spdylay/spdylay.h*. All public API functions as well as the callback
|
|
||||||
function typedefs are documented.
|
|
||||||
|
|
||||||
SPDY Client and Server Programs
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
The *src* directory contains SPDY client and server implementations
|
|
||||||
using Spdylay library. These programs are intended to make sure that
|
|
||||||
Spdylay API is acutally usable for real implementation and also for
|
|
||||||
debugging purposes. Please note that OpenSSL with `NPN
|
|
||||||
<http://technotes.googlecode.com/git/nextprotoneg.html>`_ support is
|
|
||||||
required in order to build and run these programs. At the time of
|
|
||||||
this writing, the OpenSSL 1.0.1 supports NPN.
|
|
||||||
|
|
||||||
Spdycat - SPDY client
|
|
||||||
+++++++++++++++++++++
|
|
||||||
|
|
||||||
The SPDY client is called ``spdycat``. It is a dead simple downloader
|
|
||||||
like wget/curl. It connects to SPDY server and gets resources given in
|
|
||||||
the command-line::
|
|
||||||
|
|
||||||
$ src/spdycat -h
|
|
||||||
Usage: spdycat [-Oansv23] [-t <SECONDS>] [-w <WINDOW_BITS>] [--cert=<CERT>]
|
|
||||||
[--key=<KEY>] [--no-tls] [-d <FILE>] [-m <N>] <URI>...
|
|
||||||
|
|
||||||
OPTIONS:
|
|
||||||
-v, --verbose Print debug information such as reception/
|
|
||||||
transmission of frames and name/value pairs.
|
|
||||||
-n, --null-out Discard downloaded data.
|
|
||||||
-O, --remote-name Save download data in the current directory.
|
|
||||||
The filename is dereived from URI. If URI
|
|
||||||
ends with '/', 'index.html' is used as a
|
|
||||||
filename. Not implemented yet.
|
|
||||||
-2, --spdy2 Only use SPDY/2.
|
|
||||||
-3, --spdy3 Only use SPDY/3.
|
|
||||||
-t, --timeout=<N> Timeout each request after <N> seconds.
|
|
||||||
-w, --window-bits=<N>
|
|
||||||
Sets the initial window size to 2**<N>.
|
|
||||||
-a, --get-assets Download assets such as stylesheets, images
|
|
||||||
and script files linked from the downloaded
|
|
||||||
resource. Only links whose origins are the
|
|
||||||
same with the linking resource will be
|
|
||||||
downloaded.
|
|
||||||
-s, --stat Print statistics.
|
|
||||||
-H, --header Add a header to the requests.
|
|
||||||
--cert=<CERT> Use the specified client certificate file.
|
|
||||||
The file must be in PEM format.
|
|
||||||
--key=<KEY> Use the client private key file. The file
|
|
||||||
must be in PEM format.
|
|
||||||
--no-tls Disable SSL/TLS. Use -2 or -3 to specify
|
|
||||||
SPDY protocol version to use.
|
|
||||||
-d, --data=<FILE> Post FILE to server. If - is given, data
|
|
||||||
will be read from stdin.
|
|
||||||
-m, --multiply=<N> Request each URI <N> times. By default, same
|
|
||||||
URI is not requested twice. This option
|
|
||||||
disables it too.
|
|
||||||
|
|
||||||
$ src/spdycat -nv https://www.google.com/
|
|
||||||
[ 0.025] NPN select next protocol: the remote server offers:
|
|
||||||
* spdy/3
|
|
||||||
* spdy/2
|
|
||||||
* http/1.1
|
|
||||||
NPN selected the protocol: spdy/3
|
|
||||||
[ 0.035] recv SETTINGS frame <version=3, flags=0, length=20>
|
|
||||||
(niv=2)
|
|
||||||
[4(1):100]
|
|
||||||
[7(0):12288]
|
|
||||||
[ 0.035] send SYN_STREAM frame <version=3, flags=1, length=106>
|
|
||||||
(stream_id=1, assoc_stream_id=0, pri=3)
|
|
||||||
:host: www.google.com
|
|
||||||
:method: GET
|
|
||||||
:path: /
|
|
||||||
:scheme: https
|
|
||||||
:version: HTTP/1.1
|
|
||||||
accept: */*
|
|
||||||
user-agent: spdylay/0.2.0
|
|
||||||
[ 0.077] recv SYN_REPLY frame <version=3, flags=0, length=558>
|
|
||||||
(stream_id=1)
|
|
||||||
:status: 302 Found
|
|
||||||
:version: HTTP/1.1
|
|
||||||
cache-control: private
|
|
||||||
content-length: 222
|
|
||||||
content-type: text/html; charset=UTF-8
|
|
||||||
date: Sun, 13 May 2012 08:02:54 GMT
|
|
||||||
location: https://www.google.co.jp/
|
|
||||||
server: gws
|
|
||||||
x-frame-options: SAMEORIGIN
|
|
||||||
x-xss-protection: 1; mode=block
|
|
||||||
[ 0.077] recv DATA frame (stream_id=1, flags=1, length=222)
|
|
||||||
[ 0.077] send GOAWAY frame <version=3, flags=0, length=8>
|
|
||||||
(last_good_stream_id=0)
|
|
||||||
|
|
||||||
Spdyd - SPDY server
|
|
||||||
+++++++++++++++++++
|
|
||||||
|
|
||||||
SPDY server is called ``spdyd`` and serves static files. It is single
|
|
||||||
threaded and multiplexes connections using non-blocking socket. The
|
|
||||||
static files are read using blocking I/O system call, ``read(2)``. It
|
|
||||||
speaks SPDY/2 and SPDY/3::
|
|
||||||
|
|
||||||
$ src/spdyd --htdocs=/your/htdocs/ -v 3000 server.key server.crt
|
|
||||||
IPv4: listen on port 3000
|
|
||||||
IPv6: listen on port 3000
|
|
||||||
The negotiated next protocol: spdy/3
|
|
||||||
[id=1] [ 17.456] send SETTINGS frame <version=3, flags=0, length=12>
|
|
||||||
(niv=1)
|
|
||||||
[4(0):100]
|
|
||||||
[id=1] [ 17.457] recv SYN_STREAM frame <version=3, flags=1, length=108>
|
|
||||||
(stream_id=1, assoc_stream_id=0, pri=3)
|
|
||||||
:host: localhost:3000
|
|
||||||
:method: GET
|
|
||||||
:path: /README
|
|
||||||
:scheme: https
|
|
||||||
:version: HTTP/1.1
|
|
||||||
accept: */*
|
|
||||||
user-agent: spdylay/0.2.0
|
|
||||||
[id=1] [ 17.457] send SYN_REPLY frame <version=3, flags=0, length=113>
|
|
||||||
(stream_id=1)
|
|
||||||
:status: 200 OK
|
|
||||||
:version: HTTP/1.1
|
|
||||||
cache-control: max-age=3600
|
|
||||||
content-length: 15
|
|
||||||
date: Sun, 13 May 2012 08:06:12 GMT
|
|
||||||
last-modified: Tue, 17 Jan 2012 15:39:01 GMT
|
|
||||||
server: spdyd spdylay/0.2.0
|
|
||||||
[id=1] [ 17.467] send DATA frame (stream_id=1, flags=0, length=15)
|
|
||||||
[id=1] [ 17.467] send DATA frame (stream_id=1, flags=1, length=0)
|
|
||||||
[id=1] [ 17.468] stream_id=1 closed
|
|
||||||
[id=1] [ 17.468] recv GOAWAY frame <version=3, flags=0, length=8>
|
|
||||||
(last_good_stream_id=0)
|
|
||||||
[id=1] [ 17.468] closed
|
|
||||||
|
|
||||||
Currently, ``spdyd`` needs ``epoll`` or ``kqueue``.
|
|
||||||
|
|
||||||
Shrpx - A reverse proxy for SPDY/HTTPS
|
|
||||||
++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
The ``shrpx`` is a multi-threaded reverse proxy for SPDY/HTTPS. It
|
|
||||||
converts SPDY/HTTPS traffic to plain HTTP. It is initially developed
|
|
||||||
as a reverse proxy, but now it has other operation modes such as a
|
|
||||||
frontend forward proxy. For example, with ``--spdy-proxy`` (``-s`` in
|
|
||||||
shorthand) option, it can be used as secure SPDY proxy with a proxy
|
|
||||||
(e.g., Squid) in the backend. With ``--cliet-proxy`` (``-p``) option,
|
|
||||||
it acts like an ordinaly forward proxy but expects secure SPDY proxy
|
|
||||||
in the backend. Thus it becomes an adapter to secure SPDY proxy for
|
|
||||||
clients which does not support secure SPDY proxy. The another notable
|
|
||||||
operation mode is ``--spdy-relay``, which just relays SPDY/HTTPS
|
|
||||||
traffic to the backend in SPDY. The following table summarizes the
|
|
||||||
operation modes.
|
|
||||||
|
|
||||||
================== ========== ======= =============
|
|
||||||
Mode option Frontend Backend Note
|
|
||||||
================== ========== ======= =============
|
|
||||||
default SPDY/HTTPS HTTP Reverse proxy
|
|
||||||
``--spdy`` SPDY/HTTPS HTTP SPDY proxy
|
|
||||||
``--spdy-relay`` SPDY/HTTPS SPDY
|
|
||||||
``--client`` HTTP SPDY
|
|
||||||
``--client-proxy`` HTTP SPDY Forward proxy
|
|
||||||
================== ========== ======= =============
|
|
||||||
|
|
||||||
The ``shrpx`` supports configuration file. See ``--conf`` option and
|
|
||||||
sample configuration file ``shrpx.conf.sample``.
|
|
||||||
|
|
||||||
We briefly describe the architecture of ``shrpx`` here. It has a
|
|
||||||
dedicated thread which listens on server sockets. When it accepted
|
|
||||||
the incoming connection, it passes the file descriptor of the incoming
|
|
||||||
connection to one of the worker thread. Each worker thread has its
|
|
||||||
own event loop and can handle many connections using non-blocking I/O.
|
|
||||||
The number of worker thread can be specified using the command-line
|
|
||||||
option. The `libevent <http://libevent.org/>`_ is used to handle
|
|
||||||
low-level network I/O.
|
|
||||||
|
|
||||||
Here is the command-line options::
|
|
||||||
|
|
||||||
$ src/shrpx -h
|
|
||||||
Usage: shrpx [-Dh] [-s|--client|-p] [-b <HOST,PORT>]
|
|
||||||
[-f <HOST,PORT>] [-n <CORES>] [-c <NUM>] [-L <LEVEL>]
|
|
||||||
[OPTIONS...] [<PRIVATE_KEY> <CERT>]
|
|
||||||
|
|
||||||
A reverse proxy for SPDY/HTTPS.
|
|
||||||
|
|
||||||
Positional arguments:
|
|
||||||
<PRIVATE_KEY> Set path to server's private key. Required
|
|
||||||
unless either -p or --client is specified.
|
|
||||||
<CERT> Set path to server's certificate. Required
|
|
||||||
unless either -p or --client is specified.
|
|
||||||
|
|
||||||
OPTIONS:
|
|
||||||
|
|
||||||
Connections:
|
|
||||||
-b, --backend=<HOST,PORT>
|
|
||||||
Set backend host and port.
|
|
||||||
Default: '127.0.0.1,80'
|
|
||||||
-f, --frontend=<HOST,PORT>
|
|
||||||
Set frontend host and port.
|
|
||||||
Default: '0.0.0.0,3000'
|
|
||||||
--backlog=<NUM> Set listen backlog size.
|
|
||||||
Default: 256
|
|
||||||
--backend-ipv4 Resolve backend hostname to IPv4 address
|
|
||||||
only.
|
|
||||||
--backend-ipv6 Resolve backend hostname to IPv6 address
|
|
||||||
only.
|
|
||||||
|
|
||||||
Performance:
|
|
||||||
-n, --workers=<CORES>
|
|
||||||
Set the number of worker threads.
|
|
||||||
Default: 1
|
|
||||||
|
|
||||||
Timeout:
|
|
||||||
--frontend-spdy-read-timeout=<SEC>
|
|
||||||
Specify read timeout for SPDY frontend
|
|
||||||
connection. Default: 180
|
|
||||||
--frontend-read-timeout=<SEC>
|
|
||||||
Specify read timeout for non-SPDY frontend
|
|
||||||
connection. Default: 180
|
|
||||||
--frontend-write-timeout=<SEC>
|
|
||||||
Specify write timeout for both SPDY and
|
|
||||||
non-SPDY frontends.
|
|
||||||
connection. Default: 60
|
|
||||||
--backend-read-timeout=<SEC>
|
|
||||||
Specify read timeout for backend connection.
|
|
||||||
Default: 900
|
|
||||||
--backend-write-timeout=<SEC>
|
|
||||||
Specify write timeout for backend
|
|
||||||
connection. Default: 60
|
|
||||||
--backend-keep-alive-timeout=<SEC>
|
|
||||||
Specify keep-alive timeout for backend
|
|
||||||
connection. Default: 60
|
|
||||||
--backend-http-proxy-uri=<URI>
|
|
||||||
Specify proxy URI in the form
|
|
||||||
http://[<USER>:<PASS>@]<PROXY>:<PORT>. If
|
|
||||||
a proxy requires authentication, specify
|
|
||||||
<USER> and <PASS>. Note that they must be
|
|
||||||
properly percent-encoded. This proxy is used
|
|
||||||
when the backend connection is SPDY. First,
|
|
||||||
make a CONNECT request to the proxy and
|
|
||||||
it connects to the backend on behalf of
|
|
||||||
shrpx. This forms tunnel. After that, shrpx
|
|
||||||
performs SSL/TLS handshake with the
|
|
||||||
downstream through the tunnel. The timeouts
|
|
||||||
when connecting and making CONNECT request
|
|
||||||
can be specified by --backend-read-timeout
|
|
||||||
and --backend-write-timeout options.
|
|
||||||
|
|
||||||
SSL/TLS:
|
|
||||||
--ciphers=<SUITE> Set allowed cipher list. The format of the
|
|
||||||
string is described in OpenSSL ciphers(1).
|
|
||||||
--honor-cipher-order
|
|
||||||
Honor server cipher order, giving the
|
|
||||||
ability to mitigate BEAST attacks.
|
|
||||||
-k, --insecure When used with -p or --client, don't verify
|
|
||||||
backend server's certificate.
|
|
||||||
--cacert=<PATH> When used with -p or --client, set path to
|
|
||||||
trusted CA certificate file.
|
|
||||||
The file must be in PEM format. It can
|
|
||||||
contain multiple certificates. If the
|
|
||||||
linked OpenSSL is configured to load system
|
|
||||||
wide certificates, they are loaded
|
|
||||||
at startup regardless of this option.
|
|
||||||
--private-key-passwd-file=<FILEPATH>
|
|
||||||
Path to file that contains password for the
|
|
||||||
server's private key. If none is given and
|
|
||||||
the private key is password protected it'll
|
|
||||||
be requested interactively.
|
|
||||||
--subcert=<KEYPATH>:<CERTPATH>
|
|
||||||
Specify additional certificate and private
|
|
||||||
key file. Shrpx will choose certificates
|
|
||||||
based on the hostname indicated by client
|
|
||||||
using TLS SNI extension. This option can be
|
|
||||||
used multiple times.
|
|
||||||
--backend-tls-sni-field=<HOST>
|
|
||||||
Explicitly set the content of the TLS SNI
|
|
||||||
extension. This will default to the backend
|
|
||||||
HOST name.
|
|
||||||
|
|
||||||
SPDY:
|
|
||||||
-c, --spdy-max-concurrent-streams=<NUM>
|
|
||||||
Set the maximum number of the concurrent
|
|
||||||
streams in one SPDY session.
|
|
||||||
Default: 100
|
|
||||||
--frontend-spdy-window-bits=<N>
|
|
||||||
Sets the initial window size of SPDY
|
|
||||||
frontend connection to 2**<N>.
|
|
||||||
Default: 16
|
|
||||||
--frontend-spdy-no-tls
|
|
||||||
Disable SSL/TLS on frontend SPDY
|
|
||||||
connections. SPDY protocol must be specified
|
|
||||||
using --frontend-spdy-proto. This option
|
|
||||||
also disables frontend HTTP/1.1.
|
|
||||||
--frontend-spdy-proto
|
|
||||||
Specify SPDY protocol used in frontend
|
|
||||||
connection if --frontend-spdy-no-tls is
|
|
||||||
used. Default: spdy/3
|
|
||||||
--backend-spdy-window-bits=<N>
|
|
||||||
Sets the initial window size of SPDY
|
|
||||||
backend connection to 2**<N>.
|
|
||||||
Default: 16
|
|
||||||
--backend-spdy-no-tls
|
|
||||||
Disable SSL/TLS on backend SPDY connections.
|
|
||||||
SPDY protocol must be specified using
|
|
||||||
--backend-spdy-proto
|
|
||||||
--backend-spdy-proto
|
|
||||||
Specify SPDY protocol used in backend
|
|
||||||
connection if --backend-spdy-no-tls is used.
|
|
||||||
Default: spdy/3
|
|
||||||
|
|
||||||
Mode:
|
|
||||||
-s, --spdy-proxy Enable secure SPDY proxy mode.
|
|
||||||
--spdy-bridge Communicate with the backend in SPDY. Thus
|
|
||||||
the incoming SPDY/HTTPS connections are
|
|
||||||
converted to SPDY connection and relayed to
|
|
||||||
the backend. See --backend-http-proxy-uri
|
|
||||||
option if you are behind the proxy and want
|
|
||||||
to connect to the outside SPDY proxy.
|
|
||||||
--client Instead of accepting SPDY/HTTPS connection,
|
|
||||||
accept HTTP connection and communicate with
|
|
||||||
backend server in SPDY. To use shrpx as
|
|
||||||
a forward proxy, use -p option instead.
|
|
||||||
-p, --client-proxy Like --client option, but it also requires
|
|
||||||
the request path from frontend must be
|
|
||||||
an absolute URI, suitable for use as a
|
|
||||||
forward proxy.
|
|
||||||
|
|
||||||
Logging:
|
|
||||||
-L, --log-level=<LEVEL>
|
|
||||||
Set the severity level of log output.
|
|
||||||
INFO, WARNING, ERROR and FATAL.
|
|
||||||
Default: WARNING
|
|
||||||
--accesslog Print simple accesslog to stderr.
|
|
||||||
--syslog Send log messages to syslog.
|
|
||||||
--syslog-facility=<FACILITY>
|
|
||||||
Set syslog facility.
|
|
||||||
Default: daemon
|
|
||||||
|
|
||||||
Misc:
|
|
||||||
--add-x-forwarded-for
|
|
||||||
Append X-Forwarded-For header field to the
|
|
||||||
downstream request.
|
|
||||||
--no-via Don't append to Via header field. If Via
|
|
||||||
header field is received, it is left
|
|
||||||
unaltered.
|
|
||||||
-D, --daemon Run in a background. If -D is used, the
|
|
||||||
current working directory is changed to '/'.
|
|
||||||
--pid-file=<PATH> Set path to save PID of this program.
|
|
||||||
--user=<USER> Run this program as USER. This option is
|
|
||||||
intended to be used to drop root privileges.
|
|
||||||
--conf=<PATH> Load configuration from PATH.
|
|
||||||
Default: /etc/shrpx/shrpx.conf
|
|
||||||
-v, --version Print version and exit.
|
|
||||||
-h, --help Print this help and exit.
|
|
||||||
|
|
||||||
For those of you who are curious, ``shrpx`` is an abbreviation of
|
|
||||||
"Spdy/https to Http Reverse ProXy".
|
|
||||||
|
|
||||||
Without any of ``-s``, ``--spdy-bridge``, ``-p`` and ``--client``
|
|
||||||
options, ``shrpx`` works as reverse proxy to the backend server::
|
|
||||||
|
|
||||||
Client <-- (SPDY, HTTPS) --> Shrpx <-- (HTTP) --> Web Server
|
|
||||||
[reverse proxy]
|
|
||||||
|
|
||||||
With ``-s`` option, it works as secure SPDY proxy::
|
|
||||||
|
|
||||||
Client <-- (SPDY, HTTPS) --> Shrpx <-- (HTTP) --> Proxy
|
|
||||||
[SPDY proxy] (e.g., Squid)
|
|
||||||
|
|
||||||
The ``Client`` in the above is needs to be configured to use shrpx as
|
|
||||||
secure SPDY proxy.
|
|
||||||
|
|
||||||
At the time of this writing, Chrome is the only browser which supports
|
|
||||||
secure SPDY proxy. The one way to configure Chrome to use secure SPDY
|
|
||||||
proxy is create proxy.pac script like this::
|
|
||||||
|
|
||||||
function FindProxyForURL(url, host) {
|
|
||||||
return "HTTPS SERVERADDR:PORT";
|
|
||||||
}
|
|
||||||
|
|
||||||
``SERVERADDR`` and ``PORT`` is the hostname/address and port of the
|
|
||||||
machine shrpx is running. Please note that Chrome requires valid
|
|
||||||
certificate for secure SPDY proxy.
|
|
||||||
|
|
||||||
Then run chrome with the following arguments::
|
|
||||||
|
|
||||||
$ google-chrome --proxy-pac-url=file:///path/to/proxy.pac --use-npn
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
At the time of this writing, Chrome 24 limits the maximum
|
|
||||||
concurrent connections to the proxy to 32. And due to the
|
|
||||||
limitation of socket pool handling in Chrome, it is quickly filled
|
|
||||||
up if SPDY proxy is used and many SPDY sessions are established. If
|
|
||||||
it reaches the limit, the new connections are simply blocked until
|
|
||||||
existing connections are timed out. (See `Chrome Issue 92244
|
|
||||||
<https://code.google.com/p/chromium/issues/detail?id=92244>`_). The
|
|
||||||
workaround is make the number of maximum connections high, say, 99,
|
|
||||||
which is the highest. To do this, you need to change so called
|
|
||||||
Policy setup. See `Policy Templates
|
|
||||||
<http://dev.chromium.org/administrators/policy-templates>`_ for
|
|
||||||
details how to change Policy setup on the platform you use. The
|
|
||||||
Policy name we are looking for is `MaxConnectionsPerProxy
|
|
||||||
<http://dev.chromium.org/administrators/policy-list-3#MaxConnectionsPerProxy>`_
|
|
||||||
For example, if you are using Linux, follow the instruction
|
|
||||||
described in `Linux Quick Start
|
|
||||||
<http://dev.chromium.org/administrators/linux-quick-start>`_ and
|
|
||||||
create ``/etc/opt/chrome/policies/managed/test_policy.json`` file
|
|
||||||
with the following content and restart Chrome::
|
|
||||||
|
|
||||||
{
|
|
||||||
"MaxConnectionsPerProxy" :99
|
|
||||||
}
|
|
||||||
|
|
||||||
With ``--spdy-bridge``, it accepts SPDY/HTTPS connections and
|
|
||||||
communicates with backend in SPDY::
|
|
||||||
|
|
||||||
Client <-- (SPDY, HTTPS) --> Shrpx <-- (SPDY) --> Web or SPDY Proxy etc
|
|
||||||
[SPDY bridge] (e.g., shrpx -s)
|
|
||||||
|
|
||||||
With ``-p`` option, it works as forward proxy and expects that the
|
|
||||||
backend is secure SPDY proxy::
|
|
||||||
|
|
||||||
Client <-- (HTTP) --> Shrpx <-- (SPDY) --> Secure SPDY Proxy
|
|
||||||
[forward proxy] (e.g., shrpx -s or node-spdyproxy)
|
|
||||||
|
|
||||||
The ``Client`` is needs to be configured to use shrpx as forward proxy.
|
|
||||||
|
|
||||||
In this configuration, clients which do not support secure SPDY proxy
|
|
||||||
can use secure SPDY proxy through ``shrpx``. Putting ``shrpx`` in the
|
|
||||||
same box or same network with the clients, this configuration can
|
|
||||||
bring the benefits of secure SPDY proxy to those clients. Since the
|
|
||||||
maximum number of connections per server still applies in proxy
|
|
||||||
connection, the performance gain is not obvious. For example, if the
|
|
||||||
maximum number of connections per server is 6, after sending 6
|
|
||||||
requests to the proxy, client blocks further requests, which kills
|
|
||||||
performance which might be gained in SPDY connection. For clients
|
|
||||||
which can tweak these values (e.g.,
|
|
||||||
``network.http.max-connections-per-server`` in Firefox), increasing
|
|
||||||
them may improve the performance.
|
|
||||||
|
|
||||||
With ``--client`` option, it works as reverse proxy and expects that
|
|
||||||
the backend is SPDY-enabled Web server::
|
|
||||||
|
|
||||||
Client <-- (HTTP) --> Shrpx <-- (SPDY) --> Web Server
|
|
||||||
[reverse proxy]
|
|
||||||
|
|
||||||
For the operation modes which talk to the backend in SPDY, the backend
|
|
||||||
connections can be tunneled though HTTP proxy. The proxy is specified
|
|
||||||
using ``--backend-http-proxy-uri`` option. The following figure
|
|
||||||
illustrates the example of ``--spdy-bridge`` and
|
|
||||||
``--backend-http-proxy-uri`` option to talk to the outside SPDY proxy
|
|
||||||
through HTTP proxy::
|
|
||||||
|
|
||||||
Client <-- (SPDY, HTTPS) --> Shrpx <-- (SPDY) --
|
|
||||||
[SPDY bridge]
|
|
||||||
|
|
||||||
--===================---> SPDY Proxy
|
|
||||||
(HTTP proxy tunnel) (e.g., shrpx -s)
|
|
||||||
|
|
||||||
Examples
|
|
||||||
--------
|
|
||||||
|
|
||||||
The *examples* directory contains a simple SPDY client implementation
|
|
||||||
in C.
|
|
||||||
|
|
||||||
Python-Spdylay - Python Wrapper
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
The library comes with Python wrapper ``python-spdylay``. See
|
|
||||||
``python`` directory.
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013 Tatsuhiro Tsujikawa
|
# Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013 Tatsuhiro Tsujikawa
|
# Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
dnl Spdylay - SPDY Library
|
dnl nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
dnl Copyright (c) 2012 Tatsuhiro Tsujikawa
|
dnl Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ dnl LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
dnl OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
dnl OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
dnl WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
dnl WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
AC_PREREQ(2.61)
|
AC_PREREQ(2.61)
|
||||||
AC_INIT([spdylay], [1.0.0], [t-tujikawa@users.sourceforge.net])
|
AC_INIT([nghttp2], [1.0.0], [t-tujikawa@users.sourceforge.net])
|
||||||
LT_PREREQ([2.2.6])
|
LT_PREREQ([2.2.6])
|
||||||
LT_INIT()
|
LT_INIT()
|
||||||
dnl See versioning rule:
|
dnl See versioning rule:
|
||||||
|
@ -290,16 +290,15 @@ AC_SUBST([SRC_LIBS])
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
lib/Makefile
|
lib/Makefile
|
||||||
lib/libspdylay.pc
|
lib/libnghttp2.pc
|
||||||
lib/includes/Makefile
|
lib/includes/Makefile
|
||||||
lib/includes/spdylay/spdylayver.h
|
lib/includes/nghttp2/nghttp2ver.h
|
||||||
tests/Makefile
|
tests/Makefile
|
||||||
tests/testdata/Makefile
|
tests/testdata/Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
examples/Makefile
|
examples/Makefile
|
||||||
doc/Makefile
|
doc/Makefile
|
||||||
doc/conf.py
|
doc/conf.py
|
||||||
python/Makefile
|
|
||||||
])
|
])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
EXTRA_DIST = README.rst apiref-header.rst index.rst mkapiref.py python.rst \
|
EXTRA_DIST = README.rst apiref-header.rst index.rst mkapiref.py \
|
||||||
package_README.rst _static/default2.css _templates/menu.html
|
package_README.rst _static/default2.css _templates/menu.html
|
||||||
|
|
||||||
# Makefile for Sphinx documentation
|
# Makefile for Sphinx documentation
|
||||||
|
@ -59,8 +59,8 @@ help:
|
||||||
@echo " linkcheck to check all external links for integrity"
|
@echo " linkcheck to check all external links for integrity"
|
||||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||||
|
|
||||||
apiref.rst: $(top_builddir)/lib/includes/spdylay/spdylayver.h \
|
apiref.rst: $(top_builddir)/lib/includes/nghttp2/nghttp2ver.h \
|
||||||
$(top_builddir)/lib/includes/spdylay/spdylay.h
|
$(top_builddir)/lib/includes/nghttp2/nghttp2.h
|
||||||
$(builddir)/mkapiref.py --header apiref-header.rst $^ > $@
|
$(builddir)/mkapiref.py --header apiref-header.rst $^ > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -103,17 +103,17 @@ qthelp:
|
||||||
@echo
|
@echo
|
||||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Spdylay.qhcp"
|
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/nghttp2.qhcp"
|
||||||
@echo "To view the help file:"
|
@echo "To view the help file:"
|
||||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Spdylay.qhc"
|
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/nghttp2.qhc"
|
||||||
|
|
||||||
devhelp:
|
devhelp:
|
||||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||||
@echo
|
@echo
|
||||||
@echo "Build finished."
|
@echo "Build finished."
|
||||||
@echo "To view the help file:"
|
@echo "To view the help file:"
|
||||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/Spdylay"
|
@echo "# mkdir -p $$HOME/.local/share/devhelp/nghttp2"
|
||||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Spdylay"
|
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/nghttp2"
|
||||||
@echo "# devhelp"
|
@echo "# devhelp"
|
||||||
|
|
||||||
epub:
|
epub:
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
Spdylay Documentation
|
nghttp2 Documentation
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
The documentation of Spdylay is generated using Sphinx. This
|
The documentation of nghttp2 is generated using Sphinx. This
|
||||||
directory contains the source files to be processed by Sphinx. The
|
directory contains the source files to be processed by Sphinx. The
|
||||||
source file for API reference is generated using a script called
|
source file for API reference is generated using a script called
|
||||||
``mkapiref.py`` from the Spdylay C source code.
|
``mkapiref.py`` from the nghttp2 C source code.
|
||||||
|
|
||||||
Generating API reference
|
Generating API reference
|
||||||
------------------------
|
------------------------
|
||||||
|
@ -49,7 +49,7 @@ The example follows::
|
||||||
*
|
*
|
||||||
* Submits PING frame to the |session|.
|
* Submits PING frame to the |session|.
|
||||||
*/
|
*/
|
||||||
int spdylay_submit_ping(spdylay_session *session);
|
int nghttp2_submit_ping(nghttp2_session *session);
|
||||||
|
|
||||||
|
|
||||||
@functypedef
|
@functypedef
|
||||||
|
@ -68,8 +68,8 @@ The example follows::
|
||||||
* Callback function invoked when |session| wants to send data to
|
* Callback function invoked when |session| wants to send data to
|
||||||
* remote peer.
|
* remote peer.
|
||||||
*/
|
*/
|
||||||
typedef ssize_t (*spdylay_send_callback)
|
typedef ssize_t (*nghttp2_send_callback)
|
||||||
(spdylay_session *session,
|
(nghttp2_session *session,
|
||||||
const uint8_t *data, size_t length, int flags, void *user_data);
|
const uint8_t *data, size_t length, int flags, void *user_data);
|
||||||
|
|
||||||
@enum
|
@enum
|
||||||
|
@ -93,18 +93,18 @@ The example follows::
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum
|
* @enum
|
||||||
* Error codes used in the Spdylay library.
|
* Error codes used in the nghttp2 library.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/**
|
/**
|
||||||
* Invalid argument passed.
|
* Invalid argument passed.
|
||||||
*/
|
*/
|
||||||
SPDYLAY_ERR_INVALID_ARGUMENT = -501,
|
NGHTTP2_ERR_INVALID_ARGUMENT = -501,
|
||||||
/**
|
/**
|
||||||
* Zlib error.
|
* Zlib error.
|
||||||
*/
|
*/
|
||||||
SPDYLAY_ERR_ZLIB = -502,
|
NGHTTP2_ERR_ZLIB = -502,
|
||||||
} spdylay_error;
|
} nghttp2_error;
|
||||||
|
|
||||||
@struct
|
@struct
|
||||||
#######
|
#######
|
||||||
|
@ -142,7 +142,7 @@ Some examples follow::
|
||||||
* The length field of this control frame.
|
* The length field of this control frame.
|
||||||
*/
|
*/
|
||||||
int32_t length;
|
int32_t length;
|
||||||
} spdylay_ctrl_hd;
|
} nghttp2_ctrl_hd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct
|
* @struct
|
||||||
|
@ -151,7 +151,7 @@ Some examples follow::
|
||||||
* session. The details of this structure is hidden from the public
|
* session. The details of this structure is hidden from the public
|
||||||
* API.
|
* API.
|
||||||
*/
|
*/
|
||||||
typedef struct spdylay_session spdylay_session;
|
typedef struct nghttp2_session nghttp2_session;
|
||||||
|
|
||||||
@union
|
@union
|
||||||
######
|
######
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<h3>Menu</h3>
|
<h3>Menu</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="http://sourceforge.net/projects/spdylay/files/stable/">Download</a></li>
|
<li><a href="https://github.com/tatsuhiro-t/nghttp2/issues">Issues</a></li>
|
||||||
<li><a href="https://github.com/tatsuhiro-t/spdylay/issues">Issues</a></li>
|
<li><a href="https://github.com/tatsuhiro-t/nghttp2">Source</a></li>
|
||||||
<li><a href="https://github.com/tatsuhiro-t/spdylay">Source</a></li>
|
|
||||||
<li><a href="http://sourceforge.net/projects/spdylay">SF.net Project Page</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -1,154 +0,0 @@
|
||||||
SPDY Proxy with Firefox for Android
|
|
||||||
===================================
|
|
||||||
|
|
||||||
This document describes how to use SPDY proxy from Android device
|
|
||||||
using Firefox for Android. No root privilege is required. It may be
|
|
||||||
possible to use other Web browser/software if they provide the ability
|
|
||||||
to specify HTTP proxy. Because we don't use the features only
|
|
||||||
available in latest Android devices, this method works on relatively
|
|
||||||
old but still used versions, e.g., Andriod 2.3 series.
|
|
||||||
|
|
||||||
Setting up SPDY Proxy
|
|
||||||
---------------------
|
|
||||||
|
|
||||||
If you have VPS, then you can setup SPDY proxy there. You can use
|
|
||||||
``shrpx`` with ``-s`` option + Squid as SPDY proxy. Alternatively,
|
|
||||||
`node-spdyproxy <https://github.com/igrigorik/node-spdyproxy/>`_ may
|
|
||||||
also work. If you don't have VPS, but your home internet connection
|
|
||||||
has global IP address which can be accessible from Android device, you
|
|
||||||
can use your home PC as SPDY proxy temporarily for the experiment.
|
|
||||||
The self-signed certificate is OK because we will run ``shrpx`` with
|
|
||||||
``-k`` option on Android in this example. Alternatively, you can store
|
|
||||||
your certificate in Android device and specify it using ``--cacert``
|
|
||||||
option. If you think these are insecure, obtain valid certificate.
|
|
||||||
|
|
||||||
Building spdylay library and shrpx
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
First Android NDK must be installed on your system. Refer
|
|
||||||
:doc:`package_README` to see how to install NDK. In the following document, We
|
|
||||||
use ``ANDROID_HOME`` environment variable.
|
|
||||||
|
|
||||||
To make it easier to run Android cross-compiler tools (and for the
|
|
||||||
sake of this document), include the path to those commands to
|
|
||||||
``PATH``::
|
|
||||||
|
|
||||||
$ export PATH=$ANDROID_HOME/toolchain/bin:$PATH
|
|
||||||
|
|
||||||
We need to build dependent libraries: OpenSSL and libevent.
|
|
||||||
|
|
||||||
To configure OpenSSL, use the following script::
|
|
||||||
|
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -z "$ANDROID_HOME" ]; then
|
|
||||||
echo 'No $ANDROID_HOME specified.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
PREFIX=$ANDROID_HOME/usr/local
|
|
||||||
TOOLCHAIN=$ANDROID_HOME/toolchain
|
|
||||||
PATH=$TOOLCHAIN/bin:$PATH
|
|
||||||
|
|
||||||
export CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
|
|
||||||
./Configure --prefix=$PREFIX android
|
|
||||||
|
|
||||||
Then run ``make install`` to build and install library.
|
|
||||||
|
|
||||||
For libevent, use the following script to configure::
|
|
||||||
|
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -z "$ANDROID_HOME" ]; then
|
|
||||||
echo 'No $ANDROID_HOME specified.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
PREFIX=$ANDROID_HOME/usr/local
|
|
||||||
TOOLCHAIN=$ANDROID_HOME/toolchain
|
|
||||||
PATH=$TOOLCHAIN/bin:$PATH
|
|
||||||
|
|
||||||
./configure \
|
|
||||||
--host=arm-linux-androideabi \
|
|
||||||
--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
|
|
||||||
--prefix=$PREFIX \
|
|
||||||
--disable-shared \
|
|
||||||
--enable-static \
|
|
||||||
CPPFLAGS=-I$PREFIX/include \
|
|
||||||
LDFLAGS=-L$PREFIX/lib
|
|
||||||
|
|
||||||
Then run ``make install`` to
|
|
||||||
build and install library.
|
|
||||||
|
|
||||||
To build spdylay, use ``android-config`` to configure and
|
|
||||||
``android-make`` to build as described in :doc:`package_README`.
|
|
||||||
|
|
||||||
If all went well, ``shrpx`` binary is created in src directory. Strip
|
|
||||||
debugging information from the binary using the following command::
|
|
||||||
|
|
||||||
$ arm-linux-androideabi-strip src/shrpx
|
|
||||||
|
|
||||||
Setup shrpx on Android device
|
|
||||||
-----------------------------
|
|
||||||
|
|
||||||
There may be several ways to run ``shrpx`` on Android. I describe the
|
|
||||||
way to use `Android Terminal Emulator
|
|
||||||
<https://github.com/jackpal/Android-Terminal-Emulator>`_. It can be
|
|
||||||
installed from Google Play. Copy ``shrpx`` binary to the location
|
|
||||||
where the Android-Terminal-Emulator is installed (In case of my phone,
|
|
||||||
it is ``/data/data/jackpal.androidterm``) and give the executable
|
|
||||||
permission to ``shrpx`` using ``chmod``::
|
|
||||||
|
|
||||||
$ chmod 755 shrpx
|
|
||||||
|
|
||||||
Then run ``shrpx`` in client-mode like this::
|
|
||||||
|
|
||||||
$ ./shrpx -k -p -f localhost,8000 -b SPDY-PROXY-ADDR,SPDY-PROXY-PORT
|
|
||||||
|
|
||||||
Substitute ``SPDY-PROXY-ADDR`` and ``SPDY-PROXY-PORT`` with the SPDY
|
|
||||||
proxy address and port you have setup respectively. The ``-k`` option
|
|
||||||
tells ``shrpx`` not to complain the self-signed certificate for SPDY
|
|
||||||
proxy. The ``-p`` option makes ``shrpx`` run so called client mode.
|
|
||||||
In that mode, ``shrpx`` acts like ordinary HTTP forward proxy in
|
|
||||||
frontend connection, it forwards the requests from the client to
|
|
||||||
backend in encrypted SPDY connection. The ``-f`` option specify the
|
|
||||||
address and port ``shrpx`` listens to. In this setup, the web browser
|
|
||||||
should be setup to use HTTP proxy localhost:8000. The ``-b`` option
|
|
||||||
specify the SPDY proxy address and port ``shrpx`` forwards the
|
|
||||||
requests from the client. The configuration looks like this::
|
|
||||||
|
|
||||||
|
|
||||||
+----Android------------------------+ +---SPDY-Proxy------+
|
|
||||||
| [Firefox] <-- HTTP --> [shrpx] <--=-- SPDY --=-->[shrpx,squid]<--=-- SPDY --> ...
|
|
||||||
+-----------------------------------+ +-------------------+ HTTP
|
|
||||||
|
|
||||||
With the above command-line option, ``shrpx`` only opens 1 connection
|
|
||||||
to SPDY proxy. Of course, Firefox will use multiple connections to
|
|
||||||
neighboring ``shrpx``. ``shrpx`` coalesces all the requests in 1
|
|
||||||
backend connection, that is the benefit SPDY proxy brings in.
|
|
||||||
|
|
||||||
Setup Firefox to use SPDY proxy
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
If you have not installed, Firefox for Android, install it. Enter
|
|
||||||
``about:config`` in URL bar in Firefox and locate proxy
|
|
||||||
settings. Setup those values like this::
|
|
||||||
|
|
||||||
network.proxy.http = localhost
|
|
||||||
network.proxy.http_port = 8000
|
|
||||||
network.proxy.ssl = localhost
|
|
||||||
network.proxy.ssl_port = 8000
|
|
||||||
network.proxy.type = 1
|
|
||||||
|
|
||||||
You also need to tweak the following settings to increase in-flight
|
|
||||||
requests to circumvent latency::
|
|
||||||
|
|
||||||
network.http.max-persistent-connections-per-proxy
|
|
||||||
network.http.max-connections
|
|
||||||
network.http.max-connections-per-server
|
|
||||||
|
|
||||||
Since ``shrpx`` handles maximum 100 concurrent streams, it is
|
|
||||||
reasonable to set
|
|
||||||
``network.http.max-persistent-connections-per-proxy`` to ``100``.
|
|
||||||
|
|
||||||
Now borwse the sites with Firefox. The all HTTP requests are now sent
|
|
||||||
via internal ``shrpx`` to SPDY proxy in 1 connection. SPDY proxy will
|
|
||||||
get resources on behalf of the client and sent back the response.
|
|
|
@ -4,16 +4,16 @@ API Reference
|
||||||
Includes
|
Includes
|
||||||
--------
|
--------
|
||||||
|
|
||||||
To use the public APIs, include ``spdylay/spdylay.h``::
|
To use the public APIs, include ``nghttp2/nghttp2.h``::
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
Remarks
|
Remarks
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Do not call `spdylay_session_send`, `spdylay_session_recv` or
|
Do not call `nghttp2_session_send`, `nghttp2_session_recv` or
|
||||||
`spdylay_session_mem_recv` from the spdylay callback functions
|
`nghttp2_session_mem_recv` from the nghttp2 callback functions
|
||||||
directly or indirectly. It will lead to the crash. You can submit
|
directly or indirectly. It will lead to the crash. You can submit
|
||||||
requests or frames in the callbacks then call `spdylay_session_send`,
|
requests or frames in the callbacks then call `nghttp2_session_send`,
|
||||||
`spdylay_session_recv` or `spdylay_session_mem_recv` outside of the
|
`nghttp2_session_recv` or `nghttp2_session_mem_recv` outside of the
|
||||||
callbacks.
|
callbacks.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#
|
#
|
||||||
# Spdylay documentation build configuration file, created by
|
# nghttp2 documentation build configuration file, created by
|
||||||
# sphinx-quickstart on Sun Mar 11 22:57:49 2012.
|
# sphinx-quickstart on Sun Mar 11 22:57:49 2012.
|
||||||
#
|
#
|
||||||
# This file is execfile()d with the current directory set to its containing dir.
|
# This file is execfile()d with the current directory set to its containing dir.
|
||||||
|
@ -63,7 +63,7 @@ source_suffix = '.rst'
|
||||||
master_doc = 'index'
|
master_doc = 'index'
|
||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u'Spdylay'
|
project = u'nghttp2'
|
||||||
copyright = u'2012, 2013, Tatsuhiro Tsujikawa'
|
copyright = u'2012, 2013, Tatsuhiro Tsujikawa'
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
|
@ -204,7 +204,7 @@ html_sidebars = {
|
||||||
#html_file_suffix = None
|
#html_file_suffix = None
|
||||||
|
|
||||||
# Output file base name for HTML help builder.
|
# Output file base name for HTML help builder.
|
||||||
htmlhelp_basename = 'Spdylaydoc'
|
htmlhelp_basename = 'nghttp2doc'
|
||||||
|
|
||||||
|
|
||||||
# -- Options for LaTeX output --------------------------------------------------
|
# -- Options for LaTeX output --------------------------------------------------
|
||||||
|
@ -218,7 +218,7 @@ htmlhelp_basename = 'Spdylaydoc'
|
||||||
# Grouping the document tree into LaTeX files. List of tuples
|
# Grouping the document tree into LaTeX files. List of tuples
|
||||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||||
latex_documents = [
|
latex_documents = [
|
||||||
('index', 'Spdylay.tex', u'Spdylay Documentation',
|
('index', 'nghttp2.tex', u'nghttp2 Documentation',
|
||||||
u'Tatsuhiro Tsujikawa', 'manual'),
|
u'Tatsuhiro Tsujikawa', 'manual'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ latex_documents = [
|
||||||
# One entry per manual page. List of tuples
|
# One entry per manual page. List of tuples
|
||||||
# (source start file, name, description, authors, manual section).
|
# (source start file, name, description, authors, manual section).
|
||||||
man_pages = [
|
man_pages = [
|
||||||
('index', 'spdylay', u'Spdylay Documentation',
|
('index', 'nghttp2', u'nghttp2 Documentation',
|
||||||
[u'Tatsuhiro Tsujikawa'], 1)
|
[u'Tatsuhiro Tsujikawa'], 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,13 @@
|
||||||
.. Spdylay documentation master file, created by
|
.. nghttp2 documentation master file, created by
|
||||||
sphinx-quickstart on Sun Mar 11 22:57:49 2012.
|
sphinx-quickstart on Sun Mar 11 22:57:49 2012.
|
||||||
You can adapt this file completely to your liking, but it should at least
|
You can adapt this file completely to your liking, but it should at least
|
||||||
contain the root `toctree` directive.
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
Spdylay - SPDY C Library
|
nghttp2 - HTTP/2.0 C Library
|
||||||
========================
|
============================
|
||||||
|
|
||||||
This is an experimental implementation of Google's SPDY protocol in C.
|
This is an experimental implementation of Hypertext Transfer Protocol
|
||||||
This library provides SPDY version 2 and 3 framing layer
|
version 2.0.
|
||||||
implementation. It does not perform any I/O operations. When the
|
|
||||||
library needs them, it calls the callback functions provided by the
|
|
||||||
application. It also does not include any event polling mechanism, so
|
|
||||||
the application can freely choose the way of handling events. This
|
|
||||||
library code does not depend on any particular SSL library (except for
|
|
||||||
example programs which depend on OpenSSL 1.0.1 or later).
|
|
||||||
|
|
||||||
This project also develops SPDY client, server and proxy on top of
|
|
||||||
Spdylay library.
|
|
||||||
|
|
||||||
Contents:
|
Contents:
|
||||||
|
|
||||||
|
@ -25,10 +16,8 @@ Contents:
|
||||||
|
|
||||||
package_README
|
package_README
|
||||||
apiref
|
apiref
|
||||||
python
|
|
||||||
android-spdy-proxy
|
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
---------
|
---------
|
||||||
|
|
||||||
* http://www.chromium.org/spdy
|
* http://tools.ietf.org/html/draft-ietf-httpbis-http2-04
|
||||||
|
|
|
@ -95,9 +95,9 @@ if "%1" == "qthelp" (
|
||||||
echo.
|
echo.
|
||||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Spdylay.qhcp
|
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\nghttp2.qhcp
|
||||||
echo.To view the help file:
|
echo.To view the help file:
|
||||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Spdylay.ghc
|
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\nghttp2.ghc
|
||||||
goto end
|
goto end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
|
1077
doc/python.rst
1077
doc/python.rst
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ AM_CFLAGS = -Wall
|
||||||
AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
|
AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
|
||||||
@OPENSSL_CFLAGS@ @DEFS@
|
@OPENSSL_CFLAGS@ @DEFS@
|
||||||
AM_LDFLAGS = @OPENSSL_LIBS@
|
AM_LDFLAGS = @OPENSSL_LIBS@
|
||||||
LDADD = $(top_builddir)/lib/libspdylay.la
|
LDADD = $(top_builddir)/lib/libnghttp2.la
|
||||||
|
|
||||||
noinst_PROGRAMS = spdycli
|
noinst_PROGRAMS = spdycli
|
||||||
spdycli_SOURCES = spdycli.c
|
spdycli_SOURCES = spdycli.c
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef SPDY_H
|
#ifndef SPDY_H
|
||||||
#define SPDY_H
|
#define SPDY_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
@ -33,14 +33,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "spdylay_ssl.h"
|
#include "nghttp2_ssl.h"
|
||||||
#include "uri.h"
|
#include "uri.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "SpdyServer.h"
|
#include "SpdyServer.h"
|
||||||
|
|
||||||
using namespace spdylay;
|
using namespace nghttp2;
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
class request {
|
class request {
|
||||||
public:
|
public:
|
||||||
|
@ -141,9 +141,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
ssize_t string_read_callback
|
ssize_t string_read_callback
|
||||||
(spdylay_session *session, int32_t stream_id,
|
(nghttp2_session *session, int32_t stream_id,
|
||||||
uint8_t *buf, size_t length, int *eof,
|
uint8_t *buf, size_t length, int *eof,
|
||||||
spdylay_data_source *source, void *user_data)
|
nghttp2_data_source *source, void *user_data)
|
||||||
{
|
{
|
||||||
std::pair<std::string, size_t>& body_pair =
|
std::pair<std::string, size_t>& body_pair =
|
||||||
*reinterpret_cast<std::pair<std::string, size_t>*>(source->ptr);
|
*reinterpret_cast<std::pair<std::string, size_t>*>(source->ptr);
|
||||||
|
@ -159,7 +159,7 @@ ssize_t string_read_callback
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_request_recv_callback
|
void on_request_recv_callback
|
||||||
(spdylay_session *session, int32_t stream_id, void *user_data)
|
(nghttp2_session *session, int32_t stream_id, void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = reinterpret_cast<SpdyEventHandler*>(user_data);
|
SpdyEventHandler *hd = reinterpret_cast<SpdyEventHandler*>(user_data);
|
||||||
Request *req = hd->get_stream(stream_id);
|
Request *req = hd->get_stream(stream_id);
|
||||||
|
@ -171,7 +171,7 @@ void on_request_recv_callback
|
||||||
response_obj.set_header("content-length", util::to_str(body_length));
|
response_obj.set_header("content-length", util::to_str(body_length));
|
||||||
req->response_body = std::make_pair(response_obj.get_body(), 0);
|
req->response_body = std::make_pair(response_obj.get_body(), 0);
|
||||||
|
|
||||||
spdylay_data_provider data_prd;
|
nghttp2_data_provider data_prd;
|
||||||
data_prd.source.ptr = &req->response_body;
|
data_prd.source.ptr = &req->response_body;
|
||||||
data_prd.read_callback = string_read_callback;
|
data_prd.read_callback = string_read_callback;
|
||||||
hd->submit_response(response_obj.get_status_string(), stream_id,
|
hd->submit_response(response_obj.get_status_string(), stream_id,
|
||||||
|
@ -236,6 +236,6 @@ int run(Server& server)
|
||||||
|
|
||||||
} // namespace reactor
|
} // namespace reactor
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // SPDY_H
|
#endif // SPDY_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - SPDY Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* This program is written to show how to use Spdylay API in C and
|
* This program is written to show how to use nghttp2 API in C and
|
||||||
* intentionally made simple.
|
* intentionally made simple.
|
||||||
*/
|
*/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
@ -53,12 +53,12 @@ enum {
|
||||||
|
|
||||||
struct Connection {
|
struct Connection {
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
spdylay_session *session;
|
nghttp2_session *session;
|
||||||
/* WANT_READ if SSL connection needs more input; or WANT_WRITE if it
|
/* WANT_READ if SSL connection needs more input; or WANT_WRITE if it
|
||||||
needs more output; or IO_NONE. This is necessary because SSL/TLS
|
needs more output; or IO_NONE. This is necessary because SSL/TLS
|
||||||
re-negotiation is possible at any time. Spdylay API offers
|
re-negotiation is possible at any time. nghttp2 API offers
|
||||||
similar functions like spdylay_session_want_read() and
|
similar functions like nghttp2_session_want_read() and
|
||||||
spdylay_session_want_write() but they do not take into account
|
nghttp2_session_want_write() but they do not take into account
|
||||||
SSL connection. */
|
SSL connection. */
|
||||||
int want_io;
|
int want_io;
|
||||||
};
|
};
|
||||||
|
@ -74,7 +74,7 @@ struct Request {
|
||||||
/* Stream ID for this request. */
|
/* Stream ID for this request. */
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
/* The gzip stream inflater for the compressed response. */
|
/* The gzip stream inflater for the compressed response. */
|
||||||
spdylay_gzip *inflater;
|
nghttp2_gzip *inflater;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct URI {
|
struct URI {
|
||||||
|
@ -127,7 +127,7 @@ static void dief(const char *func, const char *msg)
|
||||||
static void diec(const char *func, int error_code)
|
static void diec(const char *func, int error_code)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "FATAL: %s: error_code=%d, msg=%s\n", func, error_code,
|
fprintf(stderr, "FATAL: %s: error_code=%d, msg=%s\n", func, error_code,
|
||||||
spdylay_strerror(error_code));
|
nghttp2_strerror(error_code));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ static void check_gzip(struct Request *req, char **nv)
|
||||||
if(req->inflater) {
|
if(req->inflater) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rv = spdylay_gzip_inflate_new(&req->inflater);
|
rv = nghttp2_gzip_inflate_new(&req->inflater);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
die("Can't allocate inflate stream.");
|
die("Can't allocate inflate stream.");
|
||||||
}
|
}
|
||||||
|
@ -158,12 +158,12 @@ static void check_gzip(struct Request *req, char **nv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The implementation of spdylay_send_callback type. Here we write
|
* The implementation of nghttp2_send_callback type. Here we write
|
||||||
* |data| with size |length| to the network and return the number of
|
* |data| with size |length| to the network and return the number of
|
||||||
* bytes actually written. See the documentation of
|
* bytes actually written. See the documentation of
|
||||||
* spdylay_send_callback for the details.
|
* nghttp2_send_callback for the details.
|
||||||
*/
|
*/
|
||||||
static ssize_t send_callback(spdylay_session *session,
|
static ssize_t send_callback(nghttp2_session *session,
|
||||||
const uint8_t *data, size_t length, int flags,
|
const uint8_t *data, size_t length, int flags,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -178,21 +178,21 @@ static ssize_t send_callback(spdylay_session *session,
|
||||||
if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
|
if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
|
||||||
connection->want_io = (err == SSL_ERROR_WANT_READ ?
|
connection->want_io = (err == SSL_ERROR_WANT_READ ?
|
||||||
WANT_READ : WANT_WRITE);
|
WANT_READ : WANT_WRITE);
|
||||||
rv = SPDYLAY_ERR_WOULDBLOCK;
|
rv = NGHTTP2_ERR_WOULDBLOCK;
|
||||||
} else {
|
} else {
|
||||||
rv = SPDYLAY_ERR_CALLBACK_FAILURE;
|
rv = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The implementation of spdylay_recv_callback type. Here we read data
|
* The implementation of nghttp2_recv_callback type. Here we read data
|
||||||
* from the network and write them in |buf|. The capacity of |buf| is
|
* from the network and write them in |buf|. The capacity of |buf| is
|
||||||
* |length| bytes. Returns the number of bytes stored in |buf|. See
|
* |length| bytes. Returns the number of bytes stored in |buf|. See
|
||||||
* the documentation of spdylay_recv_callback for the details.
|
* the documentation of nghttp2_recv_callback for the details.
|
||||||
*/
|
*/
|
||||||
static ssize_t recv_callback(spdylay_session *session,
|
static ssize_t recv_callback(nghttp2_session *session,
|
||||||
uint8_t *buf, size_t length, int flags,
|
uint8_t *buf, size_t length, int flags,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -207,31 +207,31 @@ static ssize_t recv_callback(spdylay_session *session,
|
||||||
if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
|
if(err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
|
||||||
connection->want_io = (err == SSL_ERROR_WANT_READ ?
|
connection->want_io = (err == SSL_ERROR_WANT_READ ?
|
||||||
WANT_READ : WANT_WRITE);
|
WANT_READ : WANT_WRITE);
|
||||||
rv = SPDYLAY_ERR_WOULDBLOCK;
|
rv = NGHTTP2_ERR_WOULDBLOCK;
|
||||||
} else {
|
} else {
|
||||||
rv = SPDYLAY_ERR_CALLBACK_FAILURE;
|
rv = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(rv == 0) {
|
} else if(rv == 0) {
|
||||||
rv = SPDYLAY_ERR_EOF;
|
rv = NGHTTP2_ERR_EOF;
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The implementation of spdylay_before_ctrl_send_callback type. We
|
* The implementation of nghttp2_before_ctrl_send_callback type. We
|
||||||
* use this function to get stream ID of the request. This is because
|
* use this function to get stream ID of the request. This is because
|
||||||
* stream ID is not known when we submit the request
|
* stream ID is not known when we submit the request
|
||||||
* (spdylay_submit_request).
|
* (nghttp2_submit_request).
|
||||||
*/
|
*/
|
||||||
static void before_ctrl_send_callback(spdylay_session *session,
|
static void before_ctrl_send_callback(nghttp2_session *session,
|
||||||
spdylay_frame_type type,
|
nghttp2_frame_type type,
|
||||||
spdylay_frame *frame,
|
nghttp2_frame *frame,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
if(type == SPDYLAY_SYN_STREAM) {
|
if(type == NGHTTP2_SYN_STREAM) {
|
||||||
struct Request *req;
|
struct Request *req;
|
||||||
int stream_id = frame->syn_stream.stream_id;
|
int stream_id = frame->syn_stream.stream_id;
|
||||||
req = spdylay_session_get_stream_user_data(session, stream_id);
|
req = nghttp2_session_get_stream_user_data(session, stream_id);
|
||||||
if(req && req->stream_id == -1) {
|
if(req && req->stream_id == -1) {
|
||||||
req->stream_id = stream_id;
|
req->stream_id = stream_id;
|
||||||
printf("[INFO] Stream ID = %d\n", stream_id);
|
printf("[INFO] Stream ID = %d\n", stream_id);
|
||||||
|
@ -239,16 +239,16 @@ static void before_ctrl_send_callback(spdylay_session *session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_ctrl_send_callback(spdylay_session *session,
|
static void on_ctrl_send_callback(nghttp2_session *session,
|
||||||
spdylay_frame_type type,
|
nghttp2_frame_type type,
|
||||||
spdylay_frame *frame, void *user_data)
|
nghttp2_frame *frame, void *user_data)
|
||||||
{
|
{
|
||||||
char **nv;
|
char **nv;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
size_t i;
|
size_t i;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SPDYLAY_SYN_STREAM:
|
case NGHTTP2_SYN_STREAM:
|
||||||
nv = frame->syn_stream.nv;
|
nv = frame->syn_stream.nv;
|
||||||
name = "SYN_STREAM";
|
name = "SYN_STREAM";
|
||||||
stream_id = frame->syn_stream.stream_id;
|
stream_id = frame->syn_stream.stream_id;
|
||||||
|
@ -256,7 +256,7 @@ static void on_ctrl_send_callback(spdylay_session *session,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(name && spdylay_session_get_stream_user_data(session, stream_id)) {
|
if(name && nghttp2_session_get_stream_user_data(session, stream_id)) {
|
||||||
printf("[INFO] C ----------------------------> S (%s)\n", name);
|
printf("[INFO] C ----------------------------> S (%s)\n", name);
|
||||||
for(i = 0; nv[i]; i += 2) {
|
for(i = 0; nv[i]; i += 2) {
|
||||||
printf(" %s: %s\n", nv[i], nv[i+1]);
|
printf(" %s: %s\n", nv[i], nv[i+1]);
|
||||||
|
@ -264,9 +264,9 @@ static void on_ctrl_send_callback(spdylay_session *session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_ctrl_recv_callback(spdylay_session *session,
|
static void on_ctrl_recv_callback(nghttp2_session *session,
|
||||||
spdylay_frame_type type,
|
nghttp2_frame_type type,
|
||||||
spdylay_frame *frame, void *user_data)
|
nghttp2_frame *frame, void *user_data)
|
||||||
{
|
{
|
||||||
struct Request *req;
|
struct Request *req;
|
||||||
char **nv;
|
char **nv;
|
||||||
|
@ -274,12 +274,12 @@ static void on_ctrl_recv_callback(spdylay_session *session,
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
size_t i;
|
size_t i;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SPDYLAY_SYN_REPLY:
|
case NGHTTP2_SYN_REPLY:
|
||||||
nv = frame->syn_reply.nv;
|
nv = frame->syn_reply.nv;
|
||||||
name = "SYN_REPLY";
|
name = "SYN_REPLY";
|
||||||
stream_id = frame->syn_reply.stream_id;
|
stream_id = frame->syn_reply.stream_id;
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_HEADERS:
|
case NGHTTP2_HEADERS:
|
||||||
nv = frame->headers.nv;
|
nv = frame->headers.nv;
|
||||||
name = "HEADERS";
|
name = "HEADERS";
|
||||||
stream_id = frame->headers.stream_id;
|
stream_id = frame->headers.stream_id;
|
||||||
|
@ -290,7 +290,7 @@ static void on_ctrl_recv_callback(spdylay_session *session,
|
||||||
if(!name) {
|
if(!name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
req = spdylay_session_get_stream_user_data(session, stream_id);
|
req = nghttp2_session_get_stream_user_data(session, stream_id);
|
||||||
if(req) {
|
if(req) {
|
||||||
check_gzip(req, nv);
|
check_gzip(req, nv);
|
||||||
printf("[INFO] C <---------------------------- S (%s)\n", name);
|
printf("[INFO] C <---------------------------- S (%s)\n", name);
|
||||||
|
@ -301,23 +301,23 @@ static void on_ctrl_recv_callback(spdylay_session *session,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The implementation of spdylay_on_stream_close_callback type. We use
|
* The implementation of nghttp2_on_stream_close_callback type. We use
|
||||||
* this function to know the response is fully received. Since we just
|
* this function to know the response is fully received. Since we just
|
||||||
* fetch 1 resource in this program, after reception of the response,
|
* fetch 1 resource in this program, after reception of the response,
|
||||||
* we submit GOAWAY and close the session.
|
* we submit GOAWAY and close the session.
|
||||||
*/
|
*/
|
||||||
static void on_stream_close_callback(spdylay_session *session,
|
static void on_stream_close_callback(nghttp2_session *session,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
spdylay_status_code status_code,
|
nghttp2_status_code status_code,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct Request *req;
|
struct Request *req;
|
||||||
req = spdylay_session_get_stream_user_data(session, stream_id);
|
req = nghttp2_session_get_stream_user_data(session, stream_id);
|
||||||
if(req) {
|
if(req) {
|
||||||
int rv;
|
int rv;
|
||||||
rv = spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK);
|
rv = nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
diec("spdylay_submit_goaway", rv);
|
diec("nghttp2_submit_goaway", rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,16 +325,16 @@ static void on_stream_close_callback(spdylay_session *session,
|
||||||
#define MAX_OUTLEN 4096
|
#define MAX_OUTLEN 4096
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The implementation of spdylay_on_data_chunk_recv_callback type. We
|
* The implementation of nghttp2_on_data_chunk_recv_callback type. We
|
||||||
* use this function to print the received response body.
|
* use this function to print the received response body.
|
||||||
*/
|
*/
|
||||||
static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
|
static void on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
const uint8_t *data, size_t len,
|
const uint8_t *data, size_t len,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct Request *req;
|
struct Request *req;
|
||||||
req = spdylay_session_get_stream_user_data(session, stream_id);
|
req = nghttp2_session_get_stream_user_data(session, stream_id);
|
||||||
if(req) {
|
if(req) {
|
||||||
printf("[INFO] C <---------------------------- S (DATA)\n");
|
printf("[INFO] C <---------------------------- S (DATA)\n");
|
||||||
printf(" %lu bytes\n", (unsigned long int)len);
|
printf(" %lu bytes\n", (unsigned long int)len);
|
||||||
|
@ -344,9 +344,9 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
|
||||||
size_t outlen = MAX_OUTLEN;
|
size_t outlen = MAX_OUTLEN;
|
||||||
size_t tlen = len;
|
size_t tlen = len;
|
||||||
int rv;
|
int rv;
|
||||||
rv = spdylay_gzip_inflate(req->inflater, out, &outlen, data, &tlen);
|
rv = nghttp2_gzip_inflate(req->inflater, out, &outlen, data, &tlen);
|
||||||
if(rv == -1) {
|
if(rv == -1) {
|
||||||
spdylay_submit_rst_stream(session, stream_id, SPDYLAY_INTERNAL_ERROR);
|
nghttp2_submit_rst_stream(session, stream_id, NGHTTP2_INTERNAL_ERROR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fwrite(out, 1, outlen, stdout);
|
fwrite(out, 1, outlen, stdout);
|
||||||
|
@ -362,14 +362,14 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup callback functions. Spdylay API offers many callback
|
* Setup callback functions. nghttp2 API offers many callback
|
||||||
* functions, but most of them are optional. The send_callback is
|
* functions, but most of them are optional. The send_callback is
|
||||||
* always required. Since we use spdylay_session_recv(), the
|
* always required. Since we use nghttp2_session_recv(), the
|
||||||
* recv_callback is also required.
|
* recv_callback is also required.
|
||||||
*/
|
*/
|
||||||
static void setup_spdylay_callbacks(spdylay_session_callbacks *callbacks)
|
static void setup_nghttp2_callbacks(nghttp2_session_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
memset(callbacks, 0, sizeof(spdylay_session_callbacks));
|
memset(callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||||
callbacks->send_callback = send_callback;
|
callbacks->send_callback = send_callback;
|
||||||
callbacks->recv_callback = recv_callback;
|
callbacks->recv_callback = recv_callback;
|
||||||
callbacks->before_ctrl_send_callback = before_ctrl_send_callback;
|
callbacks->before_ctrl_send_callback = before_ctrl_send_callback;
|
||||||
|
@ -381,7 +381,7 @@ static void setup_spdylay_callbacks(spdylay_session_callbacks *callbacks)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callback function for SSL/TLS NPN. Since this program only supports
|
* Callback function for SSL/TLS NPN. Since this program only supports
|
||||||
* SPDY protocol, if server does not offer SPDY protocol the Spdylay
|
* SPDY protocol, if server does not offer SPDY protocol the nghttp2
|
||||||
* library supports, we terminate program.
|
* library supports, we terminate program.
|
||||||
*/
|
*/
|
||||||
static int select_next_proto_cb(SSL* ssl,
|
static int select_next_proto_cb(SSL* ssl,
|
||||||
|
@ -391,9 +391,9 @@ static int select_next_proto_cb(SSL* ssl,
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
uint16_t *spdy_proto_version;
|
uint16_t *spdy_proto_version;
|
||||||
/* spdylay_select_next_protocol() selects SPDY protocol version the
|
/* nghttp2_select_next_protocol() selects SPDY protocol version the
|
||||||
Spdylay library supports. */
|
nghttp2 library supports. */
|
||||||
rv = spdylay_select_next_protocol(out, outlen, in, inlen);
|
rv = nghttp2_select_next_protocol(out, outlen, in, inlen);
|
||||||
if(rv <= 0) {
|
if(rv <= 0) {
|
||||||
die("Server did not advertise spdy/2 or spdy/3 protocol.");
|
die("Server did not advertise spdy/2 or spdy/3 protocol.");
|
||||||
}
|
}
|
||||||
|
@ -498,11 +498,11 @@ static void set_tcp_nodelay(int fd)
|
||||||
static void ctl_poll(struct pollfd *pollfd, struct Connection *connection)
|
static void ctl_poll(struct pollfd *pollfd, struct Connection *connection)
|
||||||
{
|
{
|
||||||
pollfd->events = 0;
|
pollfd->events = 0;
|
||||||
if(spdylay_session_want_read(connection->session) ||
|
if(nghttp2_session_want_read(connection->session) ||
|
||||||
connection->want_io == WANT_READ) {
|
connection->want_io == WANT_READ) {
|
||||||
pollfd->events |= POLLIN;
|
pollfd->events |= POLLIN;
|
||||||
}
|
}
|
||||||
if(spdylay_session_want_write(connection->session) ||
|
if(nghttp2_session_want_write(connection->session) ||
|
||||||
connection->want_io == WANT_WRITE) {
|
connection->want_io == WANT_WRITE) {
|
||||||
pollfd->events |= POLLOUT;
|
pollfd->events |= POLLOUT;
|
||||||
}
|
}
|
||||||
|
@ -527,11 +527,11 @@ static void submit_request(struct Connection *connection, struct Request *req)
|
||||||
nv[6] = ":scheme"; nv[7] = "https";
|
nv[6] = ":scheme"; nv[7] = "https";
|
||||||
nv[8] = ":host"; nv[9] = req->hostport;
|
nv[8] = ":host"; nv[9] = req->hostport;
|
||||||
nv[10] = "accept"; nv[11] = "*/*";
|
nv[10] = "accept"; nv[11] = "*/*";
|
||||||
nv[12] = "user-agent"; nv[13] = "spdylay/"SPDYLAY_VERSION;
|
nv[12] = "user-agent"; nv[13] = "nghttp2/"NGHTTP2_VERSION;
|
||||||
nv[14] = NULL;
|
nv[14] = NULL;
|
||||||
rv = spdylay_submit_request(connection->session, pri, nv, NULL, req);
|
rv = nghttp2_submit_request(connection->session, pri, nv, NULL, req);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
diec("spdylay_submit_request", rv);
|
diec("nghttp2_submit_request", rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,13 +541,13 @@ static void submit_request(struct Connection *connection, struct Request *req)
|
||||||
static void exec_io(struct Connection *connection)
|
static void exec_io(struct Connection *connection)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
rv = spdylay_session_recv(connection->session);
|
rv = nghttp2_session_recv(connection->session);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
diec("spdylay_session_recv", rv);
|
diec("nghttp2_session_recv", rv);
|
||||||
}
|
}
|
||||||
rv = spdylay_session_send(connection->session);
|
rv = nghttp2_session_send(connection->session);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
diec("spdylay_session_send", rv);
|
diec("nghttp2_session_send", rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +566,7 @@ static void request_free(struct Request *req)
|
||||||
free(req->host);
|
free(req->host);
|
||||||
free(req->path);
|
free(req->path);
|
||||||
free(req->hostport);
|
free(req->hostport);
|
||||||
spdylay_gzip_inflate_del(req->inflater);
|
nghttp2_gzip_inflate_del(req->inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -574,7 +574,7 @@ static void request_free(struct Request *req)
|
||||||
*/
|
*/
|
||||||
static void fetch_uri(const struct URI *uri)
|
static void fetch_uri(const struct URI *uri)
|
||||||
{
|
{
|
||||||
spdylay_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
int fd;
|
int fd;
|
||||||
SSL_CTX *ssl_ctx;
|
SSL_CTX *ssl_ctx;
|
||||||
SSL *ssl;
|
SSL *ssl;
|
||||||
|
@ -587,7 +587,7 @@ static void fetch_uri(const struct URI *uri)
|
||||||
|
|
||||||
request_init(&req, uri);
|
request_init(&req, uri);
|
||||||
|
|
||||||
setup_spdylay_callbacks(&callbacks);
|
setup_nghttp2_callbacks(&callbacks);
|
||||||
|
|
||||||
/* Establish connection and setup SSL */
|
/* Establish connection and setup SSL */
|
||||||
fd = connect_to(req.host, req.port);
|
fd = connect_to(req.host, req.port);
|
||||||
|
@ -615,10 +615,10 @@ static void fetch_uri(const struct URI *uri)
|
||||||
set_tcp_nodelay(fd);
|
set_tcp_nodelay(fd);
|
||||||
|
|
||||||
printf("[INFO] SPDY protocol version = %d\n", spdy_proto_version);
|
printf("[INFO] SPDY protocol version = %d\n", spdy_proto_version);
|
||||||
rv = spdylay_session_client_new(&connection.session, spdy_proto_version,
|
rv = nghttp2_session_client_new(&connection.session, spdy_proto_version,
|
||||||
&callbacks, &connection);
|
&callbacks, &connection);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
diec("spdylay_session_client_new", rv);
|
diec("nghttp2_session_client_new", rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Submit the HTTP request to the outbound queue. */
|
/* Submit the HTTP request to the outbound queue. */
|
||||||
|
@ -628,8 +628,8 @@ static void fetch_uri(const struct URI *uri)
|
||||||
ctl_poll(pollfds, &connection);
|
ctl_poll(pollfds, &connection);
|
||||||
|
|
||||||
/* Event loop */
|
/* Event loop */
|
||||||
while(spdylay_session_want_read(connection.session) ||
|
while(nghttp2_session_want_read(connection.session) ||
|
||||||
spdylay_session_want_write(connection.session)) {
|
nghttp2_session_want_write(connection.session)) {
|
||||||
int nfds = poll(pollfds, npollfds, -1);
|
int nfds = poll(pollfds, npollfds, -1);
|
||||||
if(nfds == -1) {
|
if(nfds == -1) {
|
||||||
dief("poll", strerror(errno));
|
dief("poll", strerror(errno));
|
||||||
|
@ -644,7 +644,7 @@ static void fetch_uri(const struct URI *uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resource cleanup */
|
/* Resource cleanup */
|
||||||
spdylay_session_del(connection.session);
|
nghttp2_session_del(connection.session);
|
||||||
SSL_shutdown(ssl);
|
SSL_shutdown(ssl);
|
||||||
SSL_free(ssl);
|
SSL_free(ssl);
|
||||||
SSL_CTX_free(ssl_ctx);
|
SSL_CTX_free(ssl_ctx);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -26,25 +26,25 @@ AM_CFLAGS = -Wall
|
||||||
AM_CPPFLAGS = -I$(srcdir)/includes -I$(builddir)/includes @DEFS@
|
AM_CPPFLAGS = -I$(srcdir)/includes -I$(builddir)/includes @DEFS@
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = libspdylay.pc
|
pkgconfig_DATA = libnghttp2.pc
|
||||||
DISTCLEANFILES = $(pkgconfig_DATA)
|
DISTCLEANFILES = $(pkgconfig_DATA)
|
||||||
|
|
||||||
lib_LTLIBRARIES = libspdylay.la
|
lib_LTLIBRARIES = libnghttp2.la
|
||||||
|
|
||||||
OBJECTS = spdylay_pq.c spdylay_map.c spdylay_queue.c \
|
OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \
|
||||||
spdylay_buffer.c spdylay_frame.c spdylay_zlib.c \
|
nghttp2_buffer.c nghttp2_frame.c nghttp2_zlib.c \
|
||||||
spdylay_session.c spdylay_helper.c spdylay_stream.c spdylay_npn.c \
|
nghttp2_session.c nghttp2_helper.c nghttp2_stream.c nghttp2_npn.c \
|
||||||
spdylay_submit.c spdylay_outbound_item.c \
|
nghttp2_submit.c nghttp2_outbound_item.c \
|
||||||
spdylay_client_cert_vector.c spdylay_gzip.c
|
nghttp2_client_cert_vector.c nghttp2_gzip.c
|
||||||
|
|
||||||
HFILES = spdylay_pq.h spdylay_int.h spdylay_map.h spdylay_queue.h \
|
HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
|
||||||
spdylay_buffer.h spdylay_frame.h spdylay_zlib.h \
|
nghttp2_buffer.h nghttp2_frame.h nghttp2_zlib.h \
|
||||||
spdylay_session.h spdylay_helper.h spdylay_stream.h spdylay_int.h \
|
nghttp2_session.h nghttp2_helper.h nghttp2_stream.h nghttp2_int.h \
|
||||||
spdylay_npn.h spdylay_gzip.h \
|
nghttp2_npn.h nghttp2_gzip.h \
|
||||||
spdylay_submit.h spdylay_outbound_item.h \
|
nghttp2_submit.h nghttp2_outbound_item.h \
|
||||||
spdylay_client_cert_vector.h \
|
nghttp2_client_cert_vector.h \
|
||||||
spdylay_net.h
|
nghttp2_net.h
|
||||||
|
|
||||||
libspdylay_la_SOURCES = $(HFILES) $(OBJECTS)
|
libnghttp2_la_SOURCES = $(HFILES) $(OBJECTS)
|
||||||
libspdylay_la_LDFLAGS = -no-undefined \
|
libnghttp2_la_LDFLAGS = -no-undefined \
|
||||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
|
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -20,4 +20,4 @@
|
||||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
nobase_include_HEADERS = spdylay/spdylay.h spdylay/spdylayver.h
|
nobase_include_HEADERS = nghttp2/nghttp2.h nghttp2/nghttp2ver.h
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,13 +22,13 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAYVER_H
|
#ifndef NGHTTP2VER_H
|
||||||
#define SPDYLAYVER_H
|
#define NGHTTP2VER_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @macro
|
* @macro
|
||||||
* Version number of the Spdylay library release
|
* Version number of the Spdylay library release
|
||||||
*/
|
*/
|
||||||
#define SPDYLAY_VERSION "@PACKAGE_VERSION@"
|
#define NGHTTP2_VERSION "@PACKAGE_VERSION@"
|
||||||
|
|
||||||
#endif /* SPDYLAYVER_H */
|
#endif /* NGHTTP2VER_H */
|
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ exec_prefix=@exec_prefix@
|
||||||
libdir=@libdir@
|
libdir=@libdir@
|
||||||
includedir=@includedir@
|
includedir=@includedir@
|
||||||
|
|
||||||
Name: Spdylay
|
Name: nghttp2
|
||||||
Description: SPDY C library
|
Description: HTTP/2.0 C library
|
||||||
URL: http://spdylay.sourceforge.net/
|
URL: https://github.com/tatsuhiro-t/nghttp2
|
||||||
Version: @VERSION@
|
Version: @VERSION@
|
||||||
Libs: -L${libdir} -lspdylay
|
Libs: -L${libdir} -lnghttp2
|
||||||
Requires.private: zlib
|
Requires.private: zlib
|
||||||
Cflags: -I${includedir}
|
Cflags: -I${includedir}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,15 +22,15 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_buffer.h"
|
#include "nghttp2_buffer.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "spdylay_net.h"
|
#include "nghttp2_net.h"
|
||||||
#include "spdylay_helper.h"
|
#include "nghttp2_helper.h"
|
||||||
|
|
||||||
void spdylay_buffer_init(spdylay_buffer *buffer, size_t chunk_capacity)
|
void nghttp2_buffer_init(nghttp2_buffer *buffer, size_t chunk_capacity)
|
||||||
{
|
{
|
||||||
buffer->root.data = NULL;
|
buffer->root.data = NULL;
|
||||||
buffer->root.next = NULL;
|
buffer->root.next = NULL;
|
||||||
|
@ -44,30 +44,30 @@ void spdylay_buffer_init(spdylay_buffer *buffer, size_t chunk_capacity)
|
||||||
buffer->last_offset = buffer->capacity;
|
buffer->last_offset = buffer->capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_free(spdylay_buffer *buffer)
|
void nghttp2_buffer_free(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
spdylay_buffer_chunk *p = buffer->root.next;
|
nghttp2_buffer_chunk *p = buffer->root.next;
|
||||||
while(p) {
|
while(p) {
|
||||||
spdylay_buffer_chunk *next = p->next;
|
nghttp2_buffer_chunk *next = p->next;
|
||||||
free(p->data);
|
free(p->data);
|
||||||
free(p);
|
free(p);
|
||||||
p = next;
|
p = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_buffer_alloc(spdylay_buffer *buffer)
|
int nghttp2_buffer_alloc(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
if(buffer->current->next == NULL) {
|
if(buffer->current->next == NULL) {
|
||||||
spdylay_buffer_chunk *chunk;
|
nghttp2_buffer_chunk *chunk;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
chunk = malloc(sizeof(spdylay_buffer_chunk));
|
chunk = malloc(sizeof(nghttp2_buffer_chunk));
|
||||||
if(chunk == NULL) {
|
if(chunk == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
buf = malloc(buffer->capacity);
|
buf = malloc(buffer->capacity);
|
||||||
if(buf == NULL) {
|
if(buf == NULL) {
|
||||||
free(chunk);
|
free(chunk);
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
chunk->data = buf;
|
chunk->data = buf;
|
||||||
chunk->next = NULL;
|
chunk->next = NULL;
|
||||||
|
@ -81,7 +81,7 @@ int spdylay_buffer_alloc(spdylay_buffer *buffer)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* spdylay_buffer_get(spdylay_buffer *buffer)
|
uint8_t* nghttp2_buffer_get(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
if(buffer->current->data == NULL) {
|
if(buffer->current->data == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -90,51 +90,51 @@ uint8_t* spdylay_buffer_get(spdylay_buffer *buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_buffer_avail(spdylay_buffer *buffer)
|
size_t nghttp2_buffer_avail(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
return buffer->capacity-buffer->last_offset;
|
return buffer->capacity-buffer->last_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_advance(spdylay_buffer *buffer, size_t amount)
|
void nghttp2_buffer_advance(nghttp2_buffer *buffer, size_t amount)
|
||||||
{
|
{
|
||||||
buffer->last_offset += amount;
|
buffer->last_offset += amount;
|
||||||
buffer->len += amount;
|
buffer->len += amount;
|
||||||
assert(buffer->last_offset <= buffer->capacity);
|
assert(buffer->last_offset <= buffer->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_buffer_write(spdylay_buffer *buffer, const uint8_t *data,
|
int nghttp2_buffer_write(nghttp2_buffer *buffer, const uint8_t *data,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
while(len) {
|
while(len) {
|
||||||
size_t writelen;
|
size_t writelen;
|
||||||
if(spdylay_buffer_avail(buffer) == 0) {
|
if(nghttp2_buffer_avail(buffer) == 0) {
|
||||||
if((rv = spdylay_buffer_alloc(buffer)) != 0) {
|
if((rv = nghttp2_buffer_alloc(buffer)) != 0) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writelen = spdylay_min(spdylay_buffer_avail(buffer), len);
|
writelen = nghttp2_min(nghttp2_buffer_avail(buffer), len);
|
||||||
memcpy(spdylay_buffer_get(buffer), data, writelen);
|
memcpy(nghttp2_buffer_get(buffer), data, writelen);
|
||||||
data += writelen;
|
data += writelen;
|
||||||
len -= writelen;
|
len -= writelen;
|
||||||
spdylay_buffer_advance(buffer, writelen);
|
nghttp2_buffer_advance(buffer, writelen);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_buffer_length(spdylay_buffer *buffer)
|
size_t nghttp2_buffer_length(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
return buffer->len;
|
return buffer->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_buffer_capacity(spdylay_buffer *buffer)
|
size_t nghttp2_buffer_capacity(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
return buffer->capacity;
|
return buffer->capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_serialize(spdylay_buffer *buffer, uint8_t *buf)
|
void nghttp2_buffer_serialize(nghttp2_buffer *buffer, uint8_t *buf)
|
||||||
{
|
{
|
||||||
spdylay_buffer_chunk *p = buffer->root.next;
|
nghttp2_buffer_chunk *p = buffer->root.next;
|
||||||
for(; p; p = p->next) {
|
for(; p; p = p->next) {
|
||||||
size_t len;
|
size_t len;
|
||||||
if(p == buffer->current) {
|
if(p == buffer->current) {
|
||||||
|
@ -147,49 +147,49 @@ void spdylay_buffer_serialize(spdylay_buffer *buffer, uint8_t *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_reset(spdylay_buffer *buffer)
|
void nghttp2_buffer_reset(nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
buffer->current = &buffer->root;
|
buffer->current = &buffer->root;
|
||||||
buffer->len = 0;
|
buffer->len = 0;
|
||||||
buffer->last_offset = buffer->capacity;
|
buffer->last_offset = buffer->capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_reader_init(spdylay_buffer_reader *reader,
|
void nghttp2_buffer_reader_init(nghttp2_buffer_reader *reader,
|
||||||
spdylay_buffer *buffer)
|
nghttp2_buffer *buffer)
|
||||||
{
|
{
|
||||||
reader->buffer = buffer;
|
reader->buffer = buffer;
|
||||||
reader->current = buffer->root.next;
|
reader->current = buffer->root.next;
|
||||||
reader->offset = 0;
|
reader->offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t spdylay_buffer_reader_uint8(spdylay_buffer_reader *reader)
|
uint8_t nghttp2_buffer_reader_uint8(nghttp2_buffer_reader *reader)
|
||||||
{
|
{
|
||||||
uint8_t out;
|
uint8_t out;
|
||||||
spdylay_buffer_reader_data(reader, &out, sizeof(uint8_t));
|
nghttp2_buffer_reader_data(reader, &out, sizeof(uint8_t));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t spdylay_buffer_reader_uint16(spdylay_buffer_reader *reader)
|
uint16_t nghttp2_buffer_reader_uint16(nghttp2_buffer_reader *reader)
|
||||||
{
|
{
|
||||||
uint16_t out;
|
uint16_t out;
|
||||||
spdylay_buffer_reader_data(reader, (uint8_t*)&out, sizeof(uint16_t));
|
nghttp2_buffer_reader_data(reader, (uint8_t*)&out, sizeof(uint16_t));
|
||||||
return ntohs(out);
|
return ntohs(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t spdylay_buffer_reader_uint32(spdylay_buffer_reader *reader)
|
uint32_t nghttp2_buffer_reader_uint32(nghttp2_buffer_reader *reader)
|
||||||
{
|
{
|
||||||
uint32_t out;
|
uint32_t out;
|
||||||
spdylay_buffer_reader_data(reader, (uint8_t*)&out, sizeof(uint32_t));
|
nghttp2_buffer_reader_data(reader, (uint8_t*)&out, sizeof(uint32_t));
|
||||||
return ntohl(out);
|
return ntohl(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_reader_data(spdylay_buffer_reader *reader,
|
void nghttp2_buffer_reader_data(nghttp2_buffer_reader *reader,
|
||||||
uint8_t *out, size_t len)
|
uint8_t *out, size_t len)
|
||||||
{
|
{
|
||||||
while(len) {
|
while(len) {
|
||||||
size_t remlen, readlen;
|
size_t remlen, readlen;
|
||||||
remlen = reader->buffer->capacity - reader->offset;
|
remlen = reader->buffer->capacity - reader->offset;
|
||||||
readlen = spdylay_min(remlen, len);
|
readlen = nghttp2_min(remlen, len);
|
||||||
memcpy(out, reader->current->data + reader->offset, readlen);
|
memcpy(out, reader->current->data + reader->offset, readlen);
|
||||||
out += readlen;
|
out += readlen;
|
||||||
len -= readlen;
|
len -= readlen;
|
||||||
|
@ -201,7 +201,7 @@ void spdylay_buffer_reader_data(spdylay_buffer_reader *reader,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_buffer_reader_count(spdylay_buffer_reader *reader,
|
int nghttp2_buffer_reader_count(nghttp2_buffer_reader *reader,
|
||||||
size_t len, uint8_t c)
|
size_t len, uint8_t c)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
@ -209,7 +209,7 @@ int spdylay_buffer_reader_count(spdylay_buffer_reader *reader,
|
||||||
size_t remlen, readlen, i;
|
size_t remlen, readlen, i;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
remlen = reader->buffer->capacity - reader->offset;
|
remlen = reader->buffer->capacity - reader->offset;
|
||||||
readlen = spdylay_min(remlen, len);
|
readlen = nghttp2_min(remlen, len);
|
||||||
p = reader->current->data + reader->offset;
|
p = reader->current->data + reader->offset;
|
||||||
for(i = 0; i < readlen; ++i) {
|
for(i = 0; i < readlen; ++i) {
|
||||||
if(p[i] == c) {
|
if(p[i] == c) {
|
||||||
|
@ -226,13 +226,13 @@ int spdylay_buffer_reader_count(spdylay_buffer_reader *reader,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_buffer_reader_advance(spdylay_buffer_reader *reader,
|
void nghttp2_buffer_reader_advance(nghttp2_buffer_reader *reader,
|
||||||
size_t amount)
|
size_t amount)
|
||||||
{
|
{
|
||||||
while(amount) {
|
while(amount) {
|
||||||
size_t remlen, skiplen;
|
size_t remlen, skiplen;
|
||||||
remlen = reader->buffer->capacity - reader->offset;
|
remlen = reader->buffer->capacity - reader->offset;
|
||||||
skiplen = spdylay_min(remlen, amount);
|
skiplen = nghttp2_min(remlen, amount);
|
||||||
amount -= skiplen;
|
amount -= skiplen;
|
||||||
reader->offset += skiplen;
|
reader->offset += skiplen;
|
||||||
if(reader->buffer->capacity == reader->offset) {
|
if(reader->buffer->capacity == reader->offset) {
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,19 +22,19 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_BUFFER_H
|
#ifndef NGHTTP2_BUFFER_H
|
||||||
#define SPDYLAY_BUFFER_H
|
#define NGHTTP2_BUFFER_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
typedef struct spdylay_buffer_chunk {
|
typedef struct nghttp2_buffer_chunk {
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
struct spdylay_buffer_chunk *next;
|
struct nghttp2_buffer_chunk *next;
|
||||||
} spdylay_buffer_chunk;
|
} nghttp2_buffer_chunk;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List of fixed sized chunks
|
* List of fixed sized chunks
|
||||||
|
@ -44,28 +44,28 @@ typedef struct {
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
/* Root of list of chunk buffers. The root is dummy and its data
|
/* Root of list of chunk buffers. The root is dummy and its data
|
||||||
member is always NULL. */
|
member is always NULL. */
|
||||||
spdylay_buffer_chunk root;
|
nghttp2_buffer_chunk root;
|
||||||
/* Points to the current chunk to write */
|
/* Points to the current chunk to write */
|
||||||
spdylay_buffer_chunk *current;
|
nghttp2_buffer_chunk *current;
|
||||||
/* Total length of this buffer */
|
/* Total length of this buffer */
|
||||||
size_t len;
|
size_t len;
|
||||||
/* Offset of last chunk buffer */
|
/* Offset of last chunk buffer */
|
||||||
size_t last_offset;
|
size_t last_offset;
|
||||||
} spdylay_buffer;
|
} nghttp2_buffer;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes buffer with fixed chunk size chunk_capacity.
|
* Initializes buffer with fixed chunk size chunk_capacity.
|
||||||
*/
|
*/
|
||||||
void spdylay_buffer_init(spdylay_buffer *buffer, size_t chunk_capacity);
|
void nghttp2_buffer_init(nghttp2_buffer *buffer, size_t chunk_capacity);
|
||||||
/* Releases allocated memory for buffer */
|
/* Releases allocated memory for buffer */
|
||||||
void spdylay_buffer_free(spdylay_buffer *buffer);
|
void nghttp2_buffer_free(nghttp2_buffer *buffer);
|
||||||
/* Returns buffer pointer */
|
/* Returns buffer pointer */
|
||||||
uint8_t* spdylay_buffer_get(spdylay_buffer *buffer);
|
uint8_t* nghttp2_buffer_get(nghttp2_buffer *buffer);
|
||||||
/* Returns available buffer length */
|
/* Returns available buffer length */
|
||||||
size_t spdylay_buffer_avail(spdylay_buffer *buffer);
|
size_t nghttp2_buffer_avail(nghttp2_buffer *buffer);
|
||||||
/* Advances buffer pointer by amount. This reduces available buffer
|
/* Advances buffer pointer by amount. This reduces available buffer
|
||||||
length. */
|
length. */
|
||||||
void spdylay_buffer_advance(spdylay_buffer *buffer, size_t amount);
|
void nghttp2_buffer_advance(nghttp2_buffer *buffer, size_t amount);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Writes the |data| with the |len| bytes starting at the current
|
* Writes the |data| with the |len| bytes starting at the current
|
||||||
|
@ -77,94 +77,94 @@ void spdylay_buffer_advance(spdylay_buffer *buffer, size_t amount);
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_buffer_write(spdylay_buffer *buffer, const uint8_t *data,
|
int nghttp2_buffer_write(nghttp2_buffer *buffer, const uint8_t *data,
|
||||||
size_t len);
|
size_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate new chunk buffer. This will increase total length of
|
* Allocate new chunk buffer. This will increase total length of
|
||||||
* buffer (returned by spdylay_buffer_length) by capacity-last_offset.
|
* buffer (returned by nghttp2_buffer_length) by capacity-last_offset.
|
||||||
* It means untouched buffer is assumued to be written.
|
* It means untouched buffer is assumued to be written.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative eror codes:
|
* negative eror codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_buffer_alloc(spdylay_buffer *buffer);
|
int nghttp2_buffer_alloc(nghttp2_buffer *buffer);
|
||||||
|
|
||||||
/* Returns total length of buffer */
|
/* Returns total length of buffer */
|
||||||
size_t spdylay_buffer_length(spdylay_buffer *buffer);
|
size_t nghttp2_buffer_length(nghttp2_buffer *buffer);
|
||||||
|
|
||||||
/* Returns capacity of each fixed chunk buffer */
|
/* Returns capacity of each fixed chunk buffer */
|
||||||
size_t spdylay_buffer_capacity(spdylay_buffer *buffer);
|
size_t nghttp2_buffer_capacity(nghttp2_buffer *buffer);
|
||||||
|
|
||||||
/* Stores the contents of buffer into |buf|. |buf| must be at least
|
/* Stores the contents of buffer into |buf|. |buf| must be at least
|
||||||
spdylay_buffer_length(buffer) bytes long. */
|
nghttp2_buffer_length(buffer) bytes long. */
|
||||||
void spdylay_buffer_serialize(spdylay_buffer *buffer, uint8_t *buf);
|
void nghttp2_buffer_serialize(nghttp2_buffer *buffer, uint8_t *buf);
|
||||||
|
|
||||||
/* Reset |buffer| for reuse. Set the total length of buffer to 0.
|
/* Reset |buffer| for reuse. Set the total length of buffer to 0.
|
||||||
Next spdylay_buffer_avail() returns 0. This function does not free
|
Next nghttp2_buffer_avail() returns 0. This function does not free
|
||||||
allocated memory space; they are reused. */
|
allocated memory space; they are reused. */
|
||||||
void spdylay_buffer_reset(spdylay_buffer *buffer);
|
void nghttp2_buffer_reset(nghttp2_buffer *buffer);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reader interface to read data from spdylay_buffer sequentially.
|
* Reader interface to read data from nghttp2_buffer sequentially.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* The buffer to read */
|
/* The buffer to read */
|
||||||
spdylay_buffer *buffer;
|
nghttp2_buffer *buffer;
|
||||||
/* Pointer to the current chunk to read. */
|
/* Pointer to the current chunk to read. */
|
||||||
spdylay_buffer_chunk *current;
|
nghttp2_buffer_chunk *current;
|
||||||
/* Offset to the current chunk data to read. */
|
/* Offset to the current chunk data to read. */
|
||||||
size_t offset;
|
size_t offset;
|
||||||
} spdylay_buffer_reader;
|
} nghttp2_buffer_reader;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the |reader| with the |buffer|.
|
* Initializes the |reader| with the |buffer|.
|
||||||
*/
|
*/
|
||||||
void spdylay_buffer_reader_init(spdylay_buffer_reader *reader,
|
void nghttp2_buffer_reader_init(nghttp2_buffer_reader *reader,
|
||||||
spdylay_buffer *buffer);
|
nghttp2_buffer *buffer);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads 1 byte and return it. This function will advance the current
|
* Reads 1 byte and return it. This function will advance the current
|
||||||
* position by 1.
|
* position by 1.
|
||||||
*/
|
*/
|
||||||
uint8_t spdylay_buffer_reader_uint8(spdylay_buffer_reader *reader);
|
uint8_t nghttp2_buffer_reader_uint8(nghttp2_buffer_reader *reader);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads 2 bytes integer in network byte order and returns it in host
|
* Reads 2 bytes integer in network byte order and returns it in host
|
||||||
* byte order. This function will advance the current position by 2.
|
* byte order. This function will advance the current position by 2.
|
||||||
*/
|
*/
|
||||||
uint16_t spdylay_buffer_reader_uint16(spdylay_buffer_reader *reader);
|
uint16_t nghttp2_buffer_reader_uint16(nghttp2_buffer_reader *reader);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads 4 bytes integer in network byte order and returns it in host
|
* Reads 4 bytes integer in network byte order and returns it in host
|
||||||
* byte order. This function will advance the current position by 4.
|
* byte order. This function will advance the current position by 4.
|
||||||
*/
|
*/
|
||||||
uint32_t spdylay_buffer_reader_uint32(spdylay_buffer_reader *reader);
|
uint32_t nghttp2_buffer_reader_uint32(nghttp2_buffer_reader *reader);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads |len| bytes and store them in the |out|. This function will
|
* Reads |len| bytes and store them in the |out|. This function will
|
||||||
* advance the current position by |len|.
|
* advance the current position by |len|.
|
||||||
*/
|
*/
|
||||||
void spdylay_buffer_reader_data(spdylay_buffer_reader *reader,
|
void nghttp2_buffer_reader_data(nghttp2_buffer_reader *reader,
|
||||||
uint8_t *out, size_t len);
|
uint8_t *out, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads |len| bytes and count the occurrence of |c| there and return
|
* Reads |len| bytes and count the occurrence of |c| there and return
|
||||||
* it. This function will advance the current position by |len|.
|
* it. This function will advance the current position by |len|.
|
||||||
*/
|
*/
|
||||||
int spdylay_buffer_reader_count(spdylay_buffer_reader *reader,
|
int nghttp2_buffer_reader_count(nghttp2_buffer_reader *reader,
|
||||||
size_t len, uint8_t c);
|
size_t len, uint8_t c);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Advances the current position by |amount|.
|
* Advances the current position by |amount|.
|
||||||
*/
|
*/
|
||||||
void spdylay_buffer_reader_advance(spdylay_buffer_reader *reader,
|
void nghttp2_buffer_reader_advance(nghttp2_buffer_reader *reader,
|
||||||
size_t amount);
|
size_t amount);
|
||||||
|
|
||||||
#endif /* SPDYLAY_BUFFER_H */
|
#endif /* NGHTTP2_BUFFER_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,24 +22,24 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_client_cert_vector.h"
|
#include "nghttp2_client_cert_vector.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "spdylay_helper.h"
|
#include "nghttp2_helper.h"
|
||||||
|
|
||||||
int spdylay_origin_equal(const spdylay_origin *lhs, const spdylay_origin *rhs)
|
int nghttp2_origin_equal(const nghttp2_origin *lhs, const nghttp2_origin *rhs)
|
||||||
{
|
{
|
||||||
return strcmp(lhs->scheme, rhs->scheme) == 0 &&
|
return strcmp(lhs->scheme, rhs->scheme) == 0 &&
|
||||||
strcmp(lhs->host, rhs->host) == 0 && lhs->port == rhs->port;
|
strcmp(lhs->host, rhs->host) == 0 && lhs->port == rhs->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_origin_set(spdylay_origin *origin,
|
int nghttp2_origin_set(nghttp2_origin *origin,
|
||||||
const char *scheme, const char *host, uint16_t port)
|
const char *scheme, const char *host, uint16_t port)
|
||||||
{
|
{
|
||||||
if(strlen(scheme) > SPDYLAY_MAX_SCHEME ||
|
if(strlen(scheme) > NGHTTP2_MAX_SCHEME ||
|
||||||
strlen(host) > SPDYLAY_MAX_HOSTNAME) {
|
strlen(host) > NGHTTP2_MAX_HOSTNAME) {
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
strcpy(origin->scheme, scheme);
|
strcpy(origin->scheme, scheme);
|
||||||
strcpy(origin->host, host);
|
strcpy(origin->host, host);
|
||||||
|
@ -47,31 +47,31 @@ int spdylay_origin_set(spdylay_origin *origin,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* spdylay_origin_get_scheme(const spdylay_origin *origin)
|
const char* nghttp2_origin_get_scheme(const nghttp2_origin *origin)
|
||||||
{
|
{
|
||||||
return origin->scheme;
|
return origin->scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* spdylay_origin_get_host(const spdylay_origin *origin)
|
const char* nghttp2_origin_get_host(const nghttp2_origin *origin)
|
||||||
{
|
{
|
||||||
return origin->host;
|
return origin->host;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t spdylay_origin_get_port(const spdylay_origin *origin)
|
uint16_t nghttp2_origin_get_port(const nghttp2_origin *origin)
|
||||||
{
|
{
|
||||||
return origin->port;
|
return origin->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_client_cert_vector_init(spdylay_client_cert_vector *certvec,
|
int nghttp2_client_cert_vector_init(nghttp2_client_cert_vector *certvec,
|
||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
certvec->size = certvec->capacity = size;
|
certvec->size = certvec->capacity = size;
|
||||||
certvec->last_slot = 0;
|
certvec->last_slot = 0;
|
||||||
if(certvec->capacity) {
|
if(certvec->capacity) {
|
||||||
size_t vec_size = sizeof(spdylay_origin*)*certvec->capacity;
|
size_t vec_size = sizeof(nghttp2_origin*)*certvec->capacity;
|
||||||
certvec->vector = malloc(vec_size);
|
certvec->vector = malloc(vec_size);
|
||||||
if(certvec->vector == NULL) {
|
if(certvec->vector == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
memset(certvec->vector, 0, vec_size);
|
memset(certvec->vector, 0, vec_size);
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,7 +80,7 @@ int spdylay_client_cert_vector_init(spdylay_client_cert_vector *certvec,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_client_cert_vector_free(spdylay_client_cert_vector *certvec)
|
void nghttp2_client_cert_vector_free(nghttp2_client_cert_vector *certvec)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for(i = 0; i < certvec->size; ++i) {
|
for(i = 0; i < certvec->size; ++i) {
|
||||||
|
@ -89,17 +89,17 @@ void spdylay_client_cert_vector_free(spdylay_client_cert_vector *certvec)
|
||||||
free(certvec->vector);
|
free(certvec->vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_client_cert_vector_resize(spdylay_client_cert_vector *certvec,
|
int nghttp2_client_cert_vector_resize(nghttp2_client_cert_vector *certvec,
|
||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
if(certvec->capacity < size) {
|
if(certvec->capacity < size) {
|
||||||
spdylay_origin **vector = realloc(certvec->vector,
|
nghttp2_origin **vector = realloc(certvec->vector,
|
||||||
sizeof(spdylay_origin*)*size);
|
sizeof(nghttp2_origin*)*size);
|
||||||
if(vector == NULL) {
|
if(vector == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
memset(vector + certvec->capacity, 0,
|
memset(vector + certvec->capacity, 0,
|
||||||
sizeof(spdylay_origin*)*(size - certvec->capacity));
|
sizeof(nghttp2_origin*)*(size - certvec->capacity));
|
||||||
certvec->vector = vector;
|
certvec->vector = vector;
|
||||||
certvec->size = certvec->capacity = size;
|
certvec->size = certvec->capacity = size;
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,7 +108,7 @@ int spdylay_client_cert_vector_resize(spdylay_client_cert_vector *certvec,
|
||||||
free(certvec->vector[i]);
|
free(certvec->vector[i]);
|
||||||
certvec->vector[i] = NULL;
|
certvec->vector[i] = NULL;
|
||||||
}
|
}
|
||||||
certvec->size = spdylay_min(certvec->size, size);
|
certvec->size = nghttp2_min(certvec->size, size);
|
||||||
if(certvec->last_slot > certvec->size) {
|
if(certvec->last_slot > certvec->size) {
|
||||||
certvec->last_slot = certvec->size;
|
certvec->last_slot = certvec->size;
|
||||||
}
|
}
|
||||||
|
@ -116,20 +116,20 @@ int spdylay_client_cert_vector_resize(spdylay_client_cert_vector *certvec,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_client_cert_vector_find(spdylay_client_cert_vector *certvec,
|
size_t nghttp2_client_cert_vector_find(nghttp2_client_cert_vector *certvec,
|
||||||
const spdylay_origin *origin)
|
const nghttp2_origin *origin)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for(i = 0; i < certvec->size && certvec->vector[i]; ++i) {
|
for(i = 0; i < certvec->size && certvec->vector[i]; ++i) {
|
||||||
if(spdylay_origin_equal(origin, certvec->vector[i])) {
|
if(nghttp2_origin_equal(origin, certvec->vector[i])) {
|
||||||
return i+1;
|
return i+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec,
|
size_t nghttp2_client_cert_vector_put(nghttp2_client_cert_vector *certvec,
|
||||||
spdylay_origin *origin)
|
nghttp2_origin *origin)
|
||||||
{
|
{
|
||||||
if(certvec->size == 0) {
|
if(certvec->size == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -144,8 +144,8 @@ size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec,
|
||||||
return certvec->last_slot;
|
return certvec->last_slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spdylay_origin* spdylay_client_cert_vector_get_origin
|
const nghttp2_origin* nghttp2_client_cert_vector_get_origin
|
||||||
(spdylay_client_cert_vector *certvec,
|
(nghttp2_client_cert_vector *certvec,
|
||||||
size_t slot)
|
size_t slot)
|
||||||
{
|
{
|
||||||
if(slot == 0 || slot > certvec->size || !certvec->vector[slot-1]) {
|
if(slot == 0 || slot > certvec->size || !certvec->vector[slot-1]) {
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,36 +22,36 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_CLIENT_CERT_VECTOR_H
|
#ifndef NGHTTP2_CLIENT_CERT_VECTOR_H
|
||||||
#define SPDYLAY_CLIENT_CERT_VECTOR_H
|
#define NGHTTP2_CLIENT_CERT_VECTOR_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
struct spdylay_origin {
|
struct nghttp2_origin {
|
||||||
char scheme[SPDYLAY_MAX_SCHEME+1];
|
char scheme[NGHTTP2_MAX_SCHEME+1];
|
||||||
char host[SPDYLAY_MAX_HOSTNAME+1];
|
char host[NGHTTP2_MAX_HOSTNAME+1];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_origin **vector;
|
nghttp2_origin **vector;
|
||||||
/* The size of the vector. */
|
/* The size of the vector. */
|
||||||
size_t size;
|
size_t size;
|
||||||
/* The real capacity of the vector. size <= capacity holds true. */
|
/* The real capacity of the vector. size <= capacity holds true. */
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
/* The last slot where origin is stored. The default value is 0. */
|
/* The last slot where origin is stored. The default value is 0. */
|
||||||
size_t last_slot;
|
size_t last_slot;
|
||||||
} spdylay_client_cert_vector;
|
} nghttp2_client_cert_vector;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns nonzero if |lhs| and |rhs| are equal. The equality is
|
* Returns nonzero if |lhs| and |rhs| are equal. The equality is
|
||||||
* defined such that each member is equal respectively.
|
* defined such that each member is equal respectively.
|
||||||
*/
|
*/
|
||||||
int spdylay_origin_equal(const spdylay_origin *lhs, const spdylay_origin *rhs);
|
int nghttp2_origin_equal(const nghttp2_origin *lhs, const nghttp2_origin *rhs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convenient function to set members to the |origin|. The |origin|
|
* Convenient function to set members to the |origin|. The |origin|
|
||||||
|
@ -60,28 +60,28 @@ int spdylay_origin_equal(const spdylay_origin *lhs, const spdylay_origin *rhs);
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_ARGUMENT
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||||
* The |scheme| is longer than SPDYLAY_MAX_SCHEME; or the |host|
|
* The |scheme| is longer than NGHTTP2_MAX_SCHEME; or the |host|
|
||||||
* is longer than SPDYLAY_MAX_HOSTNAME.
|
* is longer than NGHTTP2_MAX_HOSTNAME.
|
||||||
*/
|
*/
|
||||||
int spdylay_origin_set(spdylay_origin *origin,
|
int nghttp2_origin_set(nghttp2_origin *origin,
|
||||||
const char *scheme, const char *host, uint16_t port);
|
const char *scheme, const char *host, uint16_t port);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the client certificate vector with the vector size
|
* Initializes the client certificate vector with the vector size
|
||||||
* |size|.
|
* |size|.
|
||||||
*/
|
*/
|
||||||
int spdylay_client_cert_vector_init(spdylay_client_cert_vector *certvec,
|
int nghttp2_client_cert_vector_init(nghttp2_client_cert_vector *certvec,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
void spdylay_client_cert_vector_free(spdylay_client_cert_vector *certvec);
|
void nghttp2_client_cert_vector_free(nghttp2_client_cert_vector *certvec);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the slot of the |origin| in the client certificate vector.
|
* Returns the slot of the |origin| in the client certificate vector.
|
||||||
* If it is not found, returns 0.
|
* If it is not found, returns 0.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_client_cert_vector_find(spdylay_client_cert_vector *certvec,
|
size_t nghttp2_client_cert_vector_find(nghttp2_client_cert_vector *certvec,
|
||||||
const spdylay_origin *origin);
|
const nghttp2_origin *origin);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Puts the |origin| to the |certvec|. This function takes ownership
|
* Puts the |origin| to the |certvec|. This function takes ownership
|
||||||
|
@ -90,8 +90,8 @@ size_t spdylay_client_cert_vector_find(spdylay_client_cert_vector *certvec,
|
||||||
* This function returns the positive slot index of the certificate
|
* This function returns the positive slot index of the certificate
|
||||||
* vector where the |origin| is stored if it succeeds, or 0.
|
* vector where the |origin| is stored if it succeeds, or 0.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec,
|
size_t nghttp2_client_cert_vector_put(nghttp2_client_cert_vector *certvec,
|
||||||
spdylay_origin *origin);
|
nghttp2_origin *origin);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Resizes client certificate vector to the size |size|.
|
* Resizes client certificate vector to the size |size|.
|
||||||
|
@ -99,14 +99,14 @@ size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_client_cert_vector_resize(spdylay_client_cert_vector *certvec,
|
int nghttp2_client_cert_vector_resize(nghttp2_client_cert_vector *certvec,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
const spdylay_origin* spdylay_client_cert_vector_get_origin
|
const nghttp2_origin* nghttp2_client_cert_vector_get_origin
|
||||||
(spdylay_client_cert_vector *certvec,
|
(nghttp2_client_cert_vector *certvec,
|
||||||
size_t slot);
|
size_t slot);
|
||||||
|
|
||||||
#endif /* SPDYLAY_CLIENT_CERT_VECTOR_H */
|
#endif /* NGHTTP2_CLIENT_CERT_VECTOR_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,57 +22,57 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_FRAME_H
|
#ifndef NGHTTP2_FRAME_H
|
||||||
#define SPDYLAY_FRAME_H
|
#define NGHTTP2_FRAME_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include "spdylay_zlib.h"
|
#include "nghttp2_zlib.h"
|
||||||
#include "spdylay_buffer.h"
|
#include "nghttp2_buffer.h"
|
||||||
#include "spdylay_client_cert_vector.h"
|
#include "nghttp2_client_cert_vector.h"
|
||||||
|
|
||||||
#define SPDYLAY_STREAM_ID_MASK 0x7fffffff
|
#define NGHTTP2_STREAM_ID_MASK 0x7fffffff
|
||||||
/* This is actually the maximum length of a control frame in SPDY/2
|
/* This is actually the maximum length of a control frame in SPDY/2
|
||||||
and 3. */
|
and 3. */
|
||||||
#define SPDYLAY_LENGTH_MASK 0xffffff
|
#define NGHTTP2_LENGTH_MASK 0xffffff
|
||||||
#define SPDYLAY_VERSION_MASK 0x7fff
|
#define NGHTTP2_VERSION_MASK 0x7fff
|
||||||
#define SPDYLAY_DELTA_WINDOW_SIZE_MASK 0x7fffffff
|
#define NGHTTP2_DELTA_WINDOW_SIZE_MASK 0x7fffffff
|
||||||
#define SPDYLAY_SETTINGS_ID_MASK 0xffffff
|
#define NGHTTP2_SETTINGS_ID_MASK 0xffffff
|
||||||
|
|
||||||
/* The length of DATA frame payload. */
|
/* The length of DATA frame payload. */
|
||||||
#define SPDYLAY_DATA_PAYLOAD_LENGTH 4096
|
#define NGHTTP2_DATA_PAYLOAD_LENGTH 4096
|
||||||
|
|
||||||
/* The number of bytes of frame header. */
|
/* The number of bytes of frame header. */
|
||||||
#define SPDYLAY_FRAME_HEAD_LENGTH 8
|
#define NGHTTP2_FRAME_HEAD_LENGTH 8
|
||||||
|
|
||||||
/* The offset to the name/value header block in the frame (including
|
/* The offset to the name/value header block in the frame (including
|
||||||
frame header) */
|
frame header) */
|
||||||
#define SPDYLAY_SYN_STREAM_NV_OFFSET 18
|
#define NGHTTP2_SYN_STREAM_NV_OFFSET 18
|
||||||
|
|
||||||
#define SPDYLAY_SPDY2_SYN_REPLY_NV_OFFSET 14
|
#define NGHTTP2_SPDY2_SYN_REPLY_NV_OFFSET 14
|
||||||
#define SPDYLAY_SPDY3_SYN_REPLY_NV_OFFSET 12
|
#define NGHTTP2_SPDY3_SYN_REPLY_NV_OFFSET 12
|
||||||
|
|
||||||
#define SPDYLAY_SPDY2_HEADERS_NV_OFFSET 14
|
#define NGHTTP2_SPDY2_HEADERS_NV_OFFSET 14
|
||||||
#define SPDYLAY_SPDY3_HEADERS_NV_OFFSET 12
|
#define NGHTTP2_SPDY3_HEADERS_NV_OFFSET 12
|
||||||
|
|
||||||
#define spdylay_frame_get_nv_len(RED, LEN_SIZE) \
|
#define nghttp2_frame_get_nv_len(RED, LEN_SIZE) \
|
||||||
(LEN_SIZE == 2 ? spdylay_buffer_reader_uint16(RED) : \
|
(LEN_SIZE == 2 ? nghttp2_buffer_reader_uint16(RED) : \
|
||||||
spdylay_buffer_reader_uint32(RED))
|
nghttp2_buffer_reader_uint32(RED))
|
||||||
|
|
||||||
#define spdylay_frame_put_nv_len(OUT, VAL, LEN_SIZE) \
|
#define nghttp2_frame_put_nv_len(OUT, VAL, LEN_SIZE) \
|
||||||
(LEN_SIZE == 2 ? \
|
(LEN_SIZE == 2 ? \
|
||||||
spdylay_put_uint16be(OUT, VAL) : spdylay_put_uint32be(OUT, VAL))
|
nghttp2_put_uint16be(OUT, VAL) : nghttp2_put_uint32be(OUT, VAL))
|
||||||
|
|
||||||
/* Category of SPDY frames. */
|
/* Category of SPDY frames. */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* Control frame */
|
/* Control frame */
|
||||||
SPDYLAY_CTRL,
|
NGHTTP2_CTRL,
|
||||||
/* DATA frame */
|
/* DATA frame */
|
||||||
SPDYLAY_DATA
|
NGHTTP2_DATA
|
||||||
} spdylay_frame_category;
|
} nghttp2_frame_category;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct
|
* @struct
|
||||||
|
@ -84,7 +84,7 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
/**
|
/**
|
||||||
* The DATA frame flags. See :type:`spdylay_data_flag`.
|
* The DATA frame flags. See :type:`nghttp2_data_flag`.
|
||||||
*/
|
*/
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
/**
|
/**
|
||||||
|
@ -95,15 +95,15 @@ typedef struct {
|
||||||
/**
|
/**
|
||||||
* The data to be sent for this DATA frame.
|
* The data to be sent for this DATA frame.
|
||||||
*/
|
*/
|
||||||
spdylay_data_provider data_prd;
|
nghttp2_data_provider data_prd;
|
||||||
} spdylay_data;
|
} nghttp2_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the number of bytes in length of name/value pair for the
|
* Returns the number of bytes in length of name/value pair for the
|
||||||
* given protocol version |version|. If |version| is not supported,
|
* given protocol version |version|. If |version| is not supported,
|
||||||
* returns 0.
|
* returns 0.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_frame_get_len_size(uint16_t version);
|
size_t nghttp2_frame_get_len_size(uint16_t version);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Packs SYN_STREAM frame |frame| in wire format and store it in
|
* Packs SYN_STREAM frame |frame| in wire format and store it in
|
||||||
|
@ -122,21 +122,21 @@ size_t spdylay_frame_get_len_size(uint16_t version);
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The deflate operation failed.
|
* The deflate operation failed.
|
||||||
* SPDYLAY_ERR_FRAME_TOO_LARGE
|
* NGHTTP2_ERR_FRAME_TOO_LARGE
|
||||||
* The length of the frame is too large.
|
* The length of the frame is too large.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_syn_stream(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_pack_syn_stream(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
uint8_t **nvbuf_ptr,
|
uint8_t **nvbuf_ptr,
|
||||||
size_t *nvbuflen_ptr,
|
size_t *nvbuflen_ptr,
|
||||||
spdylay_syn_stream *frame,
|
nghttp2_syn_stream *frame,
|
||||||
spdylay_zlib *deflater);
|
nghttp2_zlib *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks SYN_STREAM frame byte sequence into |frame|. The control
|
* Unpacks SYN_STREAM frame byte sequence into |frame|. The control
|
||||||
|
@ -149,24 +149,24 @@ ssize_t spdylay_frame_pack_syn_stream(uint8_t **buf_ptr,
|
||||||
*
|
*
|
||||||
* This function also validates the name/value pairs. If unpacking
|
* This function also validates the name/value pairs. If unpacking
|
||||||
* succeeds but validation fails, it is indicated by returning
|
* succeeds but validation fails, it is indicated by returning
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK.
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK
|
||||||
* Unpacking succeeds but the header block is invalid.
|
* Unpacking succeeds but the header block is invalid.
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_syn_stream(spdylay_syn_stream *frame,
|
int nghttp2_frame_unpack_syn_stream(nghttp2_syn_stream *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen,
|
const uint8_t *payload, size_t payloadlen,
|
||||||
spdylay_buffer *inflatebuf);
|
nghttp2_buffer *inflatebuf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks SYN_STREAM frame byte sequence into |frame|. This function
|
* Unpacks SYN_STREAM frame byte sequence into |frame|. This function
|
||||||
|
@ -175,10 +175,10 @@ int spdylay_frame_unpack_syn_stream(spdylay_syn_stream *frame,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_syn_stream_without_nv(spdylay_syn_stream *frame,
|
int nghttp2_frame_unpack_syn_stream_without_nv(nghttp2_syn_stream *frame,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
|
@ -201,21 +201,21 @@ int spdylay_frame_unpack_syn_stream_without_nv(spdylay_syn_stream *frame,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The deflate operation failed.
|
* The deflate operation failed.
|
||||||
* SPDYLAY_ERR_FRAME_TOO_LARGE
|
* NGHTTP2_ERR_FRAME_TOO_LARGE
|
||||||
* The length of the frame is too large.
|
* The length of the frame is too large.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_syn_reply(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_pack_syn_reply(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
uint8_t **nvbuf_ptr,
|
uint8_t **nvbuf_ptr,
|
||||||
size_t *nvbuflen_ptr,
|
size_t *nvbuflen_ptr,
|
||||||
spdylay_syn_reply *frame,
|
nghttp2_syn_reply *frame,
|
||||||
spdylay_zlib *deflater);
|
nghttp2_zlib *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks SYN_REPLY frame byte sequence into |frame|.
|
* Unpacks SYN_REPLY frame byte sequence into |frame|.
|
||||||
|
@ -225,24 +225,24 @@ ssize_t spdylay_frame_pack_syn_reply(uint8_t **buf_ptr,
|
||||||
*
|
*
|
||||||
* This function also validates the name/value pairs. If unpacking
|
* This function also validates the name/value pairs. If unpacking
|
||||||
* succeeds but validation fails, it is indicated by returning
|
* succeeds but validation fails, it is indicated by returning
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK.
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK
|
||||||
* Unpacking succeeds but the header block is invalid.
|
* Unpacking succeeds but the header block is invalid.
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_syn_reply(spdylay_syn_reply *frame,
|
int nghttp2_frame_unpack_syn_reply(nghttp2_syn_reply *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen,
|
const uint8_t *payload, size_t payloadlen,
|
||||||
spdylay_buffer *inflatebuf);
|
nghttp2_buffer *inflatebuf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks SYN_REPLY frame byte sequence into |frame|. This function
|
* Unpacks SYN_REPLY frame byte sequence into |frame|. This function
|
||||||
|
@ -251,10 +251,10 @@ int spdylay_frame_unpack_syn_reply(spdylay_syn_reply *frame,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_syn_reply_without_nv(spdylay_syn_reply *frame,
|
int nghttp2_frame_unpack_syn_reply_without_nv(nghttp2_syn_reply *frame,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
|
@ -269,11 +269,11 @@ int spdylay_frame_unpack_syn_reply_without_nv(spdylay_syn_reply *frame,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_ping *frame);
|
nghttp2_ping *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks PING wire format into |frame|.
|
* Unpacks PING wire format into |frame|.
|
||||||
|
@ -281,10 +281,10 @@ ssize_t spdylay_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_ping(spdylay_ping *frame,
|
int nghttp2_frame_unpack_ping(nghttp2_ping *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen);
|
const uint8_t *payload, size_t payloadlen);
|
||||||
|
|
||||||
|
@ -297,13 +297,13 @@ int spdylay_frame_unpack_ping(spdylay_ping *frame,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_goaway *frame);
|
nghttp2_goaway *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks GOAWAY wire format into |frame|.
|
* Unpacks GOAWAY wire format into |frame|.
|
||||||
|
@ -311,12 +311,12 @@ ssize_t spdylay_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_goaway(spdylay_goaway *frame,
|
int nghttp2_frame_unpack_goaway(nghttp2_goaway *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen);
|
const uint8_t *payload, size_t payloadlen);
|
||||||
|
|
||||||
|
@ -337,19 +337,19 @@ int spdylay_frame_unpack_goaway(spdylay_goaway *frame,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The deflate operation failed.
|
* The deflate operation failed.
|
||||||
* SPDYLAY_ERR_FRAME_TOO_LARGE
|
* NGHTTP2_ERR_FRAME_TOO_LARGE
|
||||||
* The length of the frame is too large.
|
* The length of the frame is too large.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr,
|
uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr,
|
||||||
spdylay_headers *frame,
|
nghttp2_headers *frame,
|
||||||
spdylay_zlib *deflater);
|
nghttp2_zlib *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks HEADERS wire format into |frame|.
|
* Unpacks HEADERS wire format into |frame|.
|
||||||
|
@ -359,24 +359,24 @@ ssize_t spdylay_frame_pack_headers(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
*
|
*
|
||||||
* This function also validates the name/value pairs. If unpacking
|
* This function also validates the name/value pairs. If unpacking
|
||||||
* succeeds but validation fails, it is indicated by returning
|
* succeeds but validation fails, it is indicated by returning
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK.
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK
|
||||||
* Unpacking succeeds but the header block is invalid.
|
* Unpacking succeeds but the header block is invalid.
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_headers(spdylay_headers *frame,
|
int nghttp2_frame_unpack_headers(nghttp2_headers *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen,
|
const uint8_t *payload, size_t payloadlen,
|
||||||
spdylay_buffer *inflatebuf);
|
nghttp2_buffer *inflatebuf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
* Unpacks HEADERS frame byte sequence into |frame|. This function
|
||||||
|
@ -385,10 +385,10 @@ int spdylay_frame_unpack_headers(spdylay_headers *frame,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_headers_without_nv(spdylay_headers *frame,
|
int nghttp2_frame_unpack_headers_without_nv(nghttp2_headers *frame,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
|
@ -404,11 +404,11 @@ int spdylay_frame_unpack_headers_without_nv(spdylay_headers *frame,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_rst_stream *frame);
|
nghttp2_rst_stream *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks RST_STREAM frame byte sequence into |frame|.
|
* Unpacks RST_STREAM frame byte sequence into |frame|.
|
||||||
|
@ -416,10 +416,10 @@ ssize_t spdylay_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_rst_stream(spdylay_rst_stream *frame,
|
int nghttp2_frame_unpack_rst_stream(nghttp2_rst_stream *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen);
|
const uint8_t *payload, size_t payloadlen);
|
||||||
|
|
||||||
|
@ -434,11 +434,11 @@ int spdylay_frame_unpack_rst_stream(spdylay_rst_stream *frame,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_window_update *frame);
|
nghttp2_window_update *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
|
* Unpacks WINDOW_UPDATE frame byte sequence into |frame|.
|
||||||
|
@ -446,10 +446,10 @@ ssize_t spdylay_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_window_update(spdylay_window_update *frame,
|
int nghttp2_frame_unpack_window_update(nghttp2_window_update *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
size_t payloadlen);
|
size_t payloadlen);
|
||||||
|
@ -463,13 +463,13 @@ int spdylay_frame_unpack_window_update(spdylay_window_update *frame,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_settings *frame);
|
nghttp2_settings *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks SETTINGS wire format into |frame|.
|
* Unpacks SETTINGS wire format into |frame|.
|
||||||
|
@ -477,14 +477,14 @@ ssize_t spdylay_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_settings(spdylay_settings *frame,
|
int nghttp2_frame_unpack_settings(nghttp2_settings *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen);
|
const uint8_t *payload, size_t payloadlen);
|
||||||
|
|
||||||
|
@ -497,11 +497,11 @@ int spdylay_frame_unpack_settings(spdylay_settings *frame,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* returns one of the following negative error codes:
|
* returns one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr,
|
ssize_t nghttp2_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_credential *frame);
|
nghttp2_credential *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks CREDENTIAL wire format into |frame|.
|
* Unpacks CREDENTIAL wire format into |frame|.
|
||||||
|
@ -509,12 +509,12 @@ ssize_t spdylay_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
* This function returns 0 if it succeeds or one of the following
|
* This function returns 0 if it succeeds or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_credential(spdylay_credential *frame,
|
int nghttp2_frame_unpack_credential(nghttp2_credential *frame,
|
||||||
const uint8_t *head, size_t headlen,
|
const uint8_t *head, size_t headlen,
|
||||||
const uint8_t *payload, size_t payloadlen);
|
const uint8_t *payload, size_t payloadlen);
|
||||||
/*
|
/*
|
||||||
|
@ -526,14 +526,14 @@ int spdylay_frame_unpack_credential(spdylay_credential *frame,
|
||||||
* This function can handles duplicate keys and concatenation of thier
|
* This function can handles duplicate keys and concatenation of thier
|
||||||
* values with '\0'.
|
* values with '\0'.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_frame_count_nv_space(char **nv, size_t len_size);
|
size_t nghttp2_frame_count_nv_space(char **nv, size_t len_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Packs name/value pairs in |nv| in |buf|. |buf| must have at least
|
* Packs name/value pairs in |nv| in |buf|. |buf| must have at least
|
||||||
* spdylay_frame_count_nv_space(nv) bytes. |len_size| is the number
|
* nghttp2_frame_count_nv_space(nv) bytes. |len_size| is the number
|
||||||
* of bytes in length of name/value pair and it must be 2 or 4.
|
* of bytes in length of name/value pair and it must be 2 or 4.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size);
|
ssize_t nghttp2_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Packs name/value pairs in |nv| in |*buf_ptr| with offset
|
* Packs name/value pairs in |nv| in |*buf_ptr| with offset
|
||||||
|
@ -545,20 +545,20 @@ ssize_t spdylay_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size);
|
||||||
* containing this name/value pairs if it succeeds, or one of the
|
* containing this name/value pairs if it succeeds, or one of the
|
||||||
* following negative error codes:
|
* following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The deflate operation failed.
|
* The deflate operation failed.
|
||||||
* SPDYLAY_ERR_FRAME_TOO_LARGE
|
* NGHTTP2_ERR_FRAME_TOO_LARGE
|
||||||
* The length of the frame is too large.
|
* The length of the frame is too large.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_alloc_pack_nv(uint8_t **buf_ptr,
|
ssize_t nghttp2_frame_alloc_pack_nv(uint8_t **buf_ptr,
|
||||||
size_t *buflen_ptr,
|
size_t *buflen_ptr,
|
||||||
uint8_t **nvbuf_ptr,
|
uint8_t **nvbuf_ptr,
|
||||||
size_t *nvbuflen_ptr,
|
size_t *nvbuflen_ptr,
|
||||||
char **nv, size_t nv_offset,
|
char **nv, size_t nv_offset,
|
||||||
size_t len_size,
|
size_t len_size,
|
||||||
spdylay_zlib *deflater);
|
nghttp2_zlib *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Counts number of name/value pair in |in| and computes length of
|
* Counts number of name/value pair in |in| and computes length of
|
||||||
|
@ -586,11 +586,11 @@ ssize_t spdylay_frame_alloc_pack_nv(uint8_t **buf_ptr,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_FRAME
|
* NGHTTP2_ERR_INVALID_FRAME
|
||||||
* The input data are invalid.
|
* The input data are invalid.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr,
|
int nghttp2_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr,
|
||||||
spdylay_buffer *in, size_t len_size);
|
nghttp2_buffer *in, size_t len_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unpacks name/value header block in wire format |in| and stores them
|
* Unpacks name/value header block in wire format |in| and stores them
|
||||||
|
@ -600,25 +600,25 @@ int spdylay_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr,
|
||||||
*
|
*
|
||||||
* This function also validates the name/value pairs. If unpacking
|
* This function also validates the name/value pairs. If unpacking
|
||||||
* succeeds but validation fails, it is indicated by returning
|
* succeeds but validation fails, it is indicated by returning
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK.
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK.
|
||||||
*
|
*
|
||||||
* If error other than SPDYLAY_ERR_INVALID_HEADER_BLOCK is returned,
|
* If error other than NGHTTP2_ERR_INVALID_HEADER_BLOCK is returned,
|
||||||
* the |nv_ptr| is not assigned. In other words,
|
* the |nv_ptr| is not assigned. In other words,
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK means unpacking succeeded, but
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK means unpacking succeeded, but
|
||||||
* header block validation failed.
|
* header block validation failed.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_HEADER_BLOCK
|
* NGHTTP2_ERR_INVALID_HEADER_BLOCK
|
||||||
* Unpacking succeeds but the header block is invalid. The
|
* Unpacking succeeds but the header block is invalid. The
|
||||||
* possible reasons are: There are duplicate header names; or the
|
* possible reasons are: There are duplicate header names; or the
|
||||||
* header names are not encoded in US-ASCII character set and not
|
* header names are not encoded in US-ASCII character set and not
|
||||||
* lower cased; or the header name is zero-length string.
|
* lower cased; or the header name is zero-length string.
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_unpack_nv(char ***nv_ptr, spdylay_buffer *in,
|
int nghttp2_frame_unpack_nv(char ***nv_ptr, nghttp2_buffer *in,
|
||||||
size_t len_size);
|
size_t len_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -626,131 +626,131 @@ int spdylay_frame_unpack_nv(char ***nv_ptr, spdylay_buffer *in,
|
||||||
* takes ownership of |nv|, so caller must not free it. If stream_id
|
* takes ownership of |nv|, so caller must not free it. If stream_id
|
||||||
* is not assigned yet, it must be 0.
|
* is not assigned yet, it must be 0.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame,
|
void nghttp2_frame_syn_stream_init(nghttp2_syn_stream *frame,
|
||||||
uint16_t version, uint8_t flags,
|
uint16_t version, uint8_t flags,
|
||||||
int32_t stream_id, int32_t assoc_stream_id,
|
int32_t stream_id, int32_t assoc_stream_id,
|
||||||
uint8_t pri, char **nv);
|
uint8_t pri, char **nv);
|
||||||
|
|
||||||
void spdylay_frame_syn_stream_free(spdylay_syn_stream *frame);
|
void nghttp2_frame_syn_stream_free(nghttp2_syn_stream *frame);
|
||||||
|
|
||||||
void spdylay_frame_syn_reply_init(spdylay_syn_reply *frame,
|
void nghttp2_frame_syn_reply_init(nghttp2_syn_reply *frame,
|
||||||
uint16_t version, uint8_t flags,
|
uint16_t version, uint8_t flags,
|
||||||
int32_t stream_id, char **nv);
|
int32_t stream_id, char **nv);
|
||||||
|
|
||||||
void spdylay_frame_syn_reply_free(spdylay_syn_reply *frame);
|
void nghttp2_frame_syn_reply_free(nghttp2_syn_reply *frame);
|
||||||
|
|
||||||
void spdylay_frame_ping_init(spdylay_ping *frame, uint16_t version,
|
void nghttp2_frame_ping_init(nghttp2_ping *frame, uint16_t version,
|
||||||
uint32_t unique_id);
|
uint32_t unique_id);
|
||||||
|
|
||||||
void spdylay_frame_ping_free(spdylay_ping *frame);
|
void nghttp2_frame_ping_free(nghttp2_ping *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes GOAWAY frame |frame| with given values. The
|
* Initializes GOAWAY frame |frame| with given values. The
|
||||||
* |status_code| is ignored if |version| == SPDYLAY_PROTO_SPDY2.
|
* |status_code| is ignored if |version| == NGHTTP2_PROTO_SPDY2.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_goaway_init(spdylay_goaway *frame, uint16_t version,
|
void nghttp2_frame_goaway_init(nghttp2_goaway *frame, uint16_t version,
|
||||||
int32_t last_good_stream_id,
|
int32_t last_good_stream_id,
|
||||||
uint32_t status_code);
|
uint32_t status_code);
|
||||||
|
|
||||||
void spdylay_frame_goaway_free(spdylay_goaway *frame);
|
void nghttp2_frame_goaway_free(nghttp2_goaway *frame);
|
||||||
|
|
||||||
void spdylay_frame_headers_init(spdylay_headers *frame, uint16_t version,
|
void nghttp2_frame_headers_init(nghttp2_headers *frame, uint16_t version,
|
||||||
uint8_t flags,
|
uint8_t flags,
|
||||||
int32_t stream_id, char **nv);
|
int32_t stream_id, char **nv);
|
||||||
|
|
||||||
void spdylay_frame_headers_free(spdylay_headers *frame);
|
void nghttp2_frame_headers_free(nghttp2_headers *frame);
|
||||||
|
|
||||||
void spdylay_frame_rst_stream_init(spdylay_rst_stream *frame,
|
void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame,
|
||||||
uint16_t version,
|
uint16_t version,
|
||||||
int32_t stream_id, uint32_t status_code);
|
int32_t stream_id, uint32_t status_code);
|
||||||
|
|
||||||
void spdylay_frame_rst_stream_free(spdylay_rst_stream *frame);
|
void nghttp2_frame_rst_stream_free(nghttp2_rst_stream *frame);
|
||||||
|
|
||||||
void spdylay_frame_window_update_init(spdylay_window_update *frame,
|
void nghttp2_frame_window_update_init(nghttp2_window_update *frame,
|
||||||
uint16_t version,
|
uint16_t version,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
int32_t delta_window_size);
|
int32_t delta_window_size);
|
||||||
|
|
||||||
void spdylay_frame_window_update_free(spdylay_window_update *frame);
|
void nghttp2_frame_window_update_free(nghttp2_window_update *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes SETTINGS frame |frame| with given values. |frame| takes
|
* Initializes SETTINGS frame |frame| with given values. |frame| takes
|
||||||
* ownership of |iv|, so caller must not free it. The |flags| are
|
* ownership of |iv|, so caller must not free it. The |flags| are
|
||||||
* bitwise-OR of one or more of spdylay_settings_flag.
|
* bitwise-OR of one or more of nghttp2_settings_flag.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_settings_init(spdylay_settings *frame,
|
void nghttp2_frame_settings_init(nghttp2_settings *frame,
|
||||||
uint16_t version, uint8_t flags,
|
uint16_t version, uint8_t flags,
|
||||||
spdylay_settings_entry *iv, size_t niv);
|
nghttp2_settings_entry *iv, size_t niv);
|
||||||
|
|
||||||
void spdylay_frame_settings_free(spdylay_settings *frame);
|
void nghttp2_frame_settings_free(nghttp2_settings *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes CREDENTIAL frame |frame| with given values. This
|
* Initializes CREDENTIAL frame |frame| with given values. This
|
||||||
* function takes ownership of |proof->data| and |certs| on success.
|
* function takes ownership of |proof->data| and |certs| on success.
|
||||||
* Note that the ownership of |proof| is not taken.
|
* Note that the ownership of |proof| is not taken.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_credential_init(spdylay_credential *frame,
|
void nghttp2_frame_credential_init(nghttp2_credential *frame,
|
||||||
uint16_t version, uint16_t slot,
|
uint16_t version, uint16_t slot,
|
||||||
spdylay_mem_chunk *proof,
|
nghttp2_mem_chunk *proof,
|
||||||
spdylay_mem_chunk *certs,
|
nghttp2_mem_chunk *certs,
|
||||||
size_t ncerts);
|
size_t ncerts);
|
||||||
|
|
||||||
void spdylay_frame_credential_free(spdylay_credential *frame);
|
void nghttp2_frame_credential_free(nghttp2_credential *frame);
|
||||||
|
|
||||||
void spdylay_frame_data_init(spdylay_data *frame, int32_t stream_id,
|
void nghttp2_frame_data_init(nghttp2_data *frame, int32_t stream_id,
|
||||||
uint8_t flags,
|
uint8_t flags,
|
||||||
const spdylay_data_provider *data_prd);
|
const nghttp2_data_provider *data_prd);
|
||||||
|
|
||||||
void spdylay_frame_data_free(spdylay_data *frame);
|
void nghttp2_frame_data_free(nghttp2_data *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns 1 if the first byte of this frame indicates it is a control
|
* Returns 1 if the first byte of this frame indicates it is a control
|
||||||
* frame.
|
* frame.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_is_ctrl_frame(uint8_t first_byte);
|
int nghttp2_frame_is_ctrl_frame(uint8_t first_byte);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates memory of name/value pair |nv|.
|
* Deallocates memory of name/value pair |nv|.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_nv_del(char **nv);
|
void nghttp2_frame_nv_del(char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Makes a deep copy of |nv| and returns the copy. This function
|
* Makes a deep copy of |nv| and returns the copy. This function
|
||||||
* returns the pointer to the copy if it succeeds, or NULL. To free
|
* returns the pointer to the copy if it succeeds, or NULL. To free
|
||||||
* allocated memory, use spdylay_frame_nv_del().
|
* allocated memory, use nghttp2_frame_nv_del().
|
||||||
*/
|
*/
|
||||||
char** spdylay_frame_nv_copy(const char **nv);
|
char** nghttp2_frame_nv_copy(const char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sorts |nv| in the ascending order of name.
|
* Sorts |nv| in the ascending order of name.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_nv_sort(char **nv);
|
void nghttp2_frame_nv_sort(char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Makes names in |nv| lower cased.
|
* Makes names in |nv| lower cased.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_nv_downcase(char **nv);
|
void nghttp2_frame_nv_downcase(char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function first makes a copy of |nv| using
|
* This function first makes a copy of |nv| using
|
||||||
* spdylay_frame_nv_copy(). If it succeeds, then call
|
* nghttp2_frame_nv_copy(). If it succeeds, then call
|
||||||
* spdylay_frame_nv_downcase() and spdylay_frame_nv_sort() with the
|
* nghttp2_frame_nv_downcase() and nghttp2_frame_nv_sort() with the
|
||||||
* copied name/value pairs.
|
* copied name/value pairs.
|
||||||
*
|
*
|
||||||
* This function returns the copied name/value pairs if it succeeds,
|
* This function returns the copied name/value pairs if it succeeds,
|
||||||
* or NULL.
|
* or NULL.
|
||||||
*/
|
*/
|
||||||
char** spdylay_frame_nv_norm_copy(const char **nv);
|
char** nghttp2_frame_nv_norm_copy(const char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Translates the |nv| in SPDY/3 header names into SPDY/2.
|
* Translates the |nv| in SPDY/3 header names into SPDY/2.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_nv_3to2(char **nv);
|
void nghttp2_frame_nv_3to2(char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Translates the |nv| in SPDY/2 header names into SPDY/3.
|
* Translates the |nv| in SPDY/2 header names into SPDY/3.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_nv_2to3(char **nv);
|
void nghttp2_frame_nv_2to3(char **nv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assigns the members of the |origin| using ":scheme" and ":host"
|
* Assigns the members of the |origin| using ":scheme" and ":host"
|
||||||
|
@ -765,17 +765,17 @@ void spdylay_frame_nv_2to3(char **nv);
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error code:
|
* negative error code:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_ARGUMENT
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||||
* The |nv| lacks either :scheme or :host, or both.
|
* The |nv| lacks either :scheme or :host, or both.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_nv_set_origin(char **nv, spdylay_origin *origin);
|
int nghttp2_frame_nv_set_origin(char **nv, nghttp2_origin *origin);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Makes copy of |iv| and return the copy. The |niv| is the number of
|
* Makes copy of |iv| and return the copy. The |niv| is the number of
|
||||||
* entries in |iv|. This function returns the pointer to the copy if
|
* entries in |iv|. This function returns the pointer to the copy if
|
||||||
* it succeeds, or NULL.
|
* it succeeds, or NULL.
|
||||||
*/
|
*/
|
||||||
spdylay_settings_entry* spdylay_frame_iv_copy(const spdylay_settings_entry *iv,
|
nghttp2_settings_entry* nghttp2_frame_iv_copy(const nghttp2_settings_entry *iv,
|
||||||
size_t niv);
|
size_t niv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -783,15 +783,15 @@ spdylay_settings_entry* spdylay_frame_iv_copy(const spdylay_settings_entry *iv,
|
||||||
* The number of the element in the array pointed by the |iv| is given
|
* The number of the element in the array pointed by the |iv| is given
|
||||||
* by the |niv|.
|
* by the |niv|.
|
||||||
*/
|
*/
|
||||||
void spdylay_frame_iv_sort(spdylay_settings_entry *iv, size_t niv);
|
void nghttp2_frame_iv_sort(nghttp2_settings_entry *iv, size_t niv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the offset of the name/header block in the frame, including
|
* Returns the offset of the name/header block in the frame, including
|
||||||
* frame header. If |type| is neither SPDYLAY_SYN_STREAM,
|
* frame header. If |type| is neither NGHTTP2_SYN_STREAM,
|
||||||
* SPDYLAY_SYN_REPLY nor SPDYLAY_HEADERS, this function returns -1.
|
* NGHTTP2_SYN_REPLY nor NGHTTP2_HEADERS, this function returns -1.
|
||||||
* If |version| is unknown, this function returns -1.
|
* If |version| is unknown, this function returns -1.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_frame_nv_offset(spdylay_frame_type type, uint16_t version);
|
ssize_t nghttp2_frame_nv_offset(nghttp2_frame_type type, uint16_t version);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks names are not empty string and do not contain control
|
* Checks names are not empty string and do not contain control
|
||||||
|
@ -799,6 +799,6 @@ ssize_t spdylay_frame_nv_offset(spdylay_frame_type type, uint16_t version);
|
||||||
*
|
*
|
||||||
* This function returns nonzero if it succeeds, or 0.
|
* This function returns nonzero if it succeeds, or 0.
|
||||||
*/
|
*/
|
||||||
int spdylay_frame_nv_check_null(const char **nv);
|
int nghttp2_frame_nv_check_null(const char **nv);
|
||||||
|
|
||||||
#endif /* SPDYLAY_FRAME_H */
|
#endif /* NGHTTP2_FRAME_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,16 +22,16 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_gzip.h"
|
#include "nghttp2_gzip.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
int spdylay_gzip_inflate_new(spdylay_gzip **inflater_ptr)
|
int nghttp2_gzip_inflate_new(nghttp2_gzip **inflater_ptr)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
*inflater_ptr = malloc(sizeof(spdylay_gzip));
|
*inflater_ptr = malloc(sizeof(nghttp2_gzip));
|
||||||
if(*inflater_ptr == NULL) {
|
if(*inflater_ptr == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
(*inflater_ptr)->zst.next_in = Z_NULL;
|
(*inflater_ptr)->zst.next_in = Z_NULL;
|
||||||
(*inflater_ptr)->zst.avail_in = 0;
|
(*inflater_ptr)->zst.avail_in = 0;
|
||||||
|
@ -41,12 +41,12 @@ int spdylay_gzip_inflate_new(spdylay_gzip **inflater_ptr)
|
||||||
rv = inflateInit2(&(*inflater_ptr)->zst, 47);
|
rv = inflateInit2(&(*inflater_ptr)->zst, 47);
|
||||||
if(rv != Z_OK) {
|
if(rv != Z_OK) {
|
||||||
free(*inflater_ptr);
|
free(*inflater_ptr);
|
||||||
return SPDYLAY_ERR_GZIP;
|
return NGHTTP2_ERR_GZIP;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_gzip_inflate_del(spdylay_gzip *inflater)
|
void nghttp2_gzip_inflate_del(nghttp2_gzip *inflater)
|
||||||
{
|
{
|
||||||
if(inflater != NULL) {
|
if(inflater != NULL) {
|
||||||
inflateEnd(&inflater->zst);
|
inflateEnd(&inflater->zst);
|
||||||
|
@ -54,7 +54,7 @@ void spdylay_gzip_inflate_del(spdylay_gzip *inflater)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_gzip_inflate(spdylay_gzip *inflater,
|
int nghttp2_gzip_inflate(nghttp2_gzip *inflater,
|
||||||
uint8_t *out, size_t *outlen_ptr,
|
uint8_t *out, size_t *outlen_ptr,
|
||||||
const uint8_t *in, size_t *inlen_ptr)
|
const uint8_t *in, size_t *inlen_ptr)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,7 @@ int spdylay_gzip_inflate(spdylay_gzip *inflater,
|
||||||
case Z_STREAM_ERROR:
|
case Z_STREAM_ERROR:
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
case Z_MEM_ERROR:
|
case Z_MEM_ERROR:
|
||||||
return SPDYLAY_ERR_GZIP;
|
return NGHTTP2_ERR_GZIP;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
/* We need this for some compilers */
|
/* We need this for some compilers */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,17 +22,17 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_GZIP_H
|
#ifndef NGHTTP2_GZIP_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
struct spdylay_gzip {
|
struct nghttp2_gzip {
|
||||||
z_stream zst;
|
z_stream zst;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPDYLAY_GZIP_H */
|
#endif /* NGHTTP2_GZIP_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,39 +22,39 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_helper.h"
|
#include "nghttp2_helper.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "spdylay_net.h"
|
#include "nghttp2_net.h"
|
||||||
|
|
||||||
void spdylay_put_uint16be(uint8_t *buf, uint16_t n)
|
void nghttp2_put_uint16be(uint8_t *buf, uint16_t n)
|
||||||
{
|
{
|
||||||
uint16_t x = htons(n);
|
uint16_t x = htons(n);
|
||||||
memcpy(buf, &x, sizeof(uint16_t));
|
memcpy(buf, &x, sizeof(uint16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_put_uint32be(uint8_t *buf, uint32_t n)
|
void nghttp2_put_uint32be(uint8_t *buf, uint32_t n)
|
||||||
{
|
{
|
||||||
uint32_t x = htonl(n);
|
uint32_t x = htonl(n);
|
||||||
memcpy(buf, &x, sizeof(uint32_t));
|
memcpy(buf, &x, sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t spdylay_get_uint16(const uint8_t *data)
|
uint16_t nghttp2_get_uint16(const uint8_t *data)
|
||||||
{
|
{
|
||||||
uint16_t n;
|
uint16_t n;
|
||||||
memcpy(&n, data, sizeof(uint16_t));
|
memcpy(&n, data, sizeof(uint16_t));
|
||||||
return ntohs(n);
|
return ntohs(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t spdylay_get_uint32(const uint8_t *data)
|
uint32_t nghttp2_get_uint32(const uint8_t *data)
|
||||||
{
|
{
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
memcpy(&n, data, sizeof(uint32_t));
|
memcpy(&n, data, sizeof(uint32_t));
|
||||||
return ntohl(n);
|
return ntohl(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
int nghttp2_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t min_length)
|
size_t min_length)
|
||||||
{
|
{
|
||||||
if(min_length > *buflen_ptr) {
|
if(min_length > *buflen_ptr) {
|
||||||
|
@ -62,7 +62,7 @@ int spdylay_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
min_length = (min_length+4095)/4096*4096;
|
min_length = (min_length+4095)/4096*4096;
|
||||||
temp = malloc(min_length);
|
temp = malloc(min_length);
|
||||||
if(temp == NULL) {
|
if(temp == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
} else {
|
} else {
|
||||||
free(*buf_ptr);
|
free(*buf_ptr);
|
||||||
*buf_ptr = temp;
|
*buf_ptr = temp;
|
||||||
|
@ -72,58 +72,58 @@ int spdylay_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* spdylay_strerror(int error_code)
|
const char* nghttp2_strerror(int error_code)
|
||||||
{
|
{
|
||||||
switch(error_code) {
|
switch(error_code) {
|
||||||
case 0:
|
case 0:
|
||||||
return "Success";
|
return "Success";
|
||||||
case SPDYLAY_ERR_INVALID_ARGUMENT:
|
case NGHTTP2_ERR_INVALID_ARGUMENT:
|
||||||
return "Invalid argument";
|
return "Invalid argument";
|
||||||
case SPDYLAY_ERR_ZLIB:
|
case NGHTTP2_ERR_ZLIB:
|
||||||
return "Zlib error";
|
return "Zlib error";
|
||||||
case SPDYLAY_ERR_UNSUPPORTED_VERSION:
|
case NGHTTP2_ERR_UNSUPPORTED_VERSION:
|
||||||
return "Unsupported SPDY version";
|
return "Unsupported SPDY version";
|
||||||
case SPDYLAY_ERR_WOULDBLOCK:
|
case NGHTTP2_ERR_WOULDBLOCK:
|
||||||
return "Operation would block";
|
return "Operation would block";
|
||||||
case SPDYLAY_ERR_PROTO:
|
case NGHTTP2_ERR_PROTO:
|
||||||
return "Protocol error";
|
return "Protocol error";
|
||||||
case SPDYLAY_ERR_INVALID_FRAME:
|
case NGHTTP2_ERR_INVALID_FRAME:
|
||||||
return "Invalid frame octets";
|
return "Invalid frame octets";
|
||||||
case SPDYLAY_ERR_EOF:
|
case NGHTTP2_ERR_EOF:
|
||||||
return "EOF";
|
return "EOF";
|
||||||
case SPDYLAY_ERR_DEFERRED:
|
case NGHTTP2_ERR_DEFERRED:
|
||||||
return "Data transfer deferred";
|
return "Data transfer deferred";
|
||||||
case SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE:
|
case NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE:
|
||||||
return "No more Stream ID available";
|
return "No more Stream ID available";
|
||||||
case SPDYLAY_ERR_STREAM_CLOSED:
|
case NGHTTP2_ERR_STREAM_CLOSED:
|
||||||
return "Stream was already closed or invalid";
|
return "Stream was already closed or invalid";
|
||||||
case SPDYLAY_ERR_STREAM_CLOSING:
|
case NGHTTP2_ERR_STREAM_CLOSING:
|
||||||
return "Stream is closing";
|
return "Stream is closing";
|
||||||
case SPDYLAY_ERR_STREAM_SHUT_WR:
|
case NGHTTP2_ERR_STREAM_SHUT_WR:
|
||||||
return "The transmission is not allowed for this stream";
|
return "The transmission is not allowed for this stream";
|
||||||
case SPDYLAY_ERR_INVALID_STREAM_ID:
|
case NGHTTP2_ERR_INVALID_STREAM_ID:
|
||||||
return "Stream ID is invalid";
|
return "Stream ID is invalid";
|
||||||
case SPDYLAY_ERR_INVALID_STREAM_STATE:
|
case NGHTTP2_ERR_INVALID_STREAM_STATE:
|
||||||
return "Invalid stream state";
|
return "Invalid stream state";
|
||||||
case SPDYLAY_ERR_DEFERRED_DATA_EXIST:
|
case NGHTTP2_ERR_DEFERRED_DATA_EXIST:
|
||||||
return "Another DATA frame has already been deferred";
|
return "Another DATA frame has already been deferred";
|
||||||
case SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED:
|
case NGHTTP2_ERR_SYN_STREAM_NOT_ALLOWED:
|
||||||
return "SYN_STREAM is not allowed";
|
return "SYN_STREAM is not allowed";
|
||||||
case SPDYLAY_ERR_GOAWAY_ALREADY_SENT:
|
case NGHTTP2_ERR_GOAWAY_ALREADY_SENT:
|
||||||
return "GOAWAY has already been sent";
|
return "GOAWAY has already been sent";
|
||||||
case SPDYLAY_ERR_INVALID_HEADER_BLOCK:
|
case NGHTTP2_ERR_INVALID_HEADER_BLOCK:
|
||||||
return "Invalid header block";
|
return "Invalid header block";
|
||||||
case SPDYLAY_ERR_INVALID_STATE:
|
case NGHTTP2_ERR_INVALID_STATE:
|
||||||
return "Invalid state";
|
return "Invalid state";
|
||||||
case SPDYLAY_ERR_GZIP:
|
case NGHTTP2_ERR_GZIP:
|
||||||
return "Gzip error";
|
return "Gzip error";
|
||||||
case SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE:
|
case NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE:
|
||||||
return "The user callback function failed due to the temporal error";
|
return "The user callback function failed due to the temporal error";
|
||||||
case SPDYLAY_ERR_FRAME_TOO_LARGE:
|
case NGHTTP2_ERR_FRAME_TOO_LARGE:
|
||||||
return "The length of the frame is too large";
|
return "The length of the frame is too large";
|
||||||
case SPDYLAY_ERR_NOMEM:
|
case NGHTTP2_ERR_NOMEM:
|
||||||
return "Out of memory";
|
return "Out of memory";
|
||||||
case SPDYLAY_ERR_CALLBACK_FAILURE:
|
case NGHTTP2_ERR_CALLBACK_FAILURE:
|
||||||
return "The user callback function failed";
|
return "The user callback function failed";
|
||||||
default:
|
default:
|
||||||
return "Unknown error code";
|
return "Unknown error code";
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,41 +22,41 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_HELPER_H
|
#ifndef NGHTTP2_HELPER_H
|
||||||
#define SPDYLAY_HELPER_H
|
#define NGHTTP2_HELPER_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
#define spdylay_min(A, B) ((A) < (B) ? (A) : (B))
|
#define nghttp2_min(A, B) ((A) < (B) ? (A) : (B))
|
||||||
#define spdylay_max(A, B) ((A) > (B) ? (A) : (B))
|
#define nghttp2_max(A, B) ((A) > (B) ? (A) : (B))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copies 2 byte unsigned integer |n| in host byte order to |buf| in
|
* Copies 2 byte unsigned integer |n| in host byte order to |buf| in
|
||||||
* network byte order.
|
* network byte order.
|
||||||
*/
|
*/
|
||||||
void spdylay_put_uint16be(uint8_t *buf, uint16_t n);
|
void nghttp2_put_uint16be(uint8_t *buf, uint16_t n);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copies 4 byte unsigned integer |n| in host byte order to |buf| in
|
* Copies 4 byte unsigned integer |n| in host byte order to |buf| in
|
||||||
* network byte order.
|
* network byte order.
|
||||||
*/
|
*/
|
||||||
void spdylay_put_uint32be(uint8_t *buf, uint32_t n);
|
void nghttp2_put_uint32be(uint8_t *buf, uint32_t n);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieves 2 byte unsigned integer stored in |data| in network byte
|
* Retrieves 2 byte unsigned integer stored in |data| in network byte
|
||||||
* order and returns it in host byte order.
|
* order and returns it in host byte order.
|
||||||
*/
|
*/
|
||||||
uint16_t spdylay_get_uint16(const uint8_t *data);
|
uint16_t nghttp2_get_uint16(const uint8_t *data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieves 4 byte unsigned integer stored in |data| in network byte
|
* Retrieves 4 byte unsigned integer stored in |data| in network byte
|
||||||
* order and returns it in host byte order.
|
* order and returns it in host byte order.
|
||||||
*/
|
*/
|
||||||
uint32_t spdylay_get_uint32(const uint8_t *data);
|
uint32_t nghttp2_get_uint32(const uint8_t *data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ensures that buffer |*buf_ptr| with |*buflen_ptr| length has at
|
* Ensures that buffer |*buf_ptr| with |*buflen_ptr| length has at
|
||||||
|
@ -71,10 +71,10 @@ uint32_t spdylay_get_uint32(const uint8_t *data);
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
int nghttp2_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t min_length);
|
size_t min_length);
|
||||||
|
|
||||||
#endif /* SPDYLAY_HELPER_H */
|
#endif /* NGHTTP2_HELPER_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,8 +22,8 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_INT_H
|
#ifndef NGHTTP2_INT_H
|
||||||
#define SPDYLAY_INT_H
|
#define NGHTTP2_INT_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
|
@ -33,12 +33,12 @@
|
||||||
|
|
||||||
/* Macros, types and constants for internal use */
|
/* Macros, types and constants for internal use */
|
||||||
|
|
||||||
typedef int (*spdylay_compar)(const void *lhs, const void *rhs);
|
typedef int (*nghttp2_compar)(const void *lhs, const void *rhs);
|
||||||
|
|
||||||
/* Internal error code. They must be in the range [-499, -100],
|
/* Internal error code. They must be in the range [-499, -100],
|
||||||
inclusive. */
|
inclusive. */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPDYLAY_ERR_CREDENTIAL_PENDING = -101
|
NGHTTP2_ERR_CREDENTIAL_PENDING = -101
|
||||||
} spdylay_internal_error;
|
} nghttp2_internal_error;
|
||||||
|
|
||||||
#endif /* SPDYLAY_INT_H */
|
#endif /* NGHTTP2_INT_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,21 +22,21 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_map.h"
|
#include "nghttp2_map.h"
|
||||||
|
|
||||||
void spdylay_map_init(spdylay_map *map)
|
void nghttp2_map_init(nghttp2_map *map)
|
||||||
{
|
{
|
||||||
map->root = NULL;
|
map->root = NULL;
|
||||||
map->size = 0;
|
map->size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_map_free(spdylay_map *map)
|
void nghttp2_map_free(nghttp2_map *map)
|
||||||
{
|
{
|
||||||
map->root = NULL;
|
map->root = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find left most node, which is not necessarily a leaf. */
|
/* Find left most node, which is not necessarily a leaf. */
|
||||||
static spdylay_map_entry* find_left_most(spdylay_map_entry *entry)
|
static nghttp2_map_entry* find_left_most(nghttp2_map_entry *entry)
|
||||||
{
|
{
|
||||||
while(entry->left) {
|
while(entry->left) {
|
||||||
entry = entry->left;
|
entry = entry->left;
|
||||||
|
@ -45,7 +45,7 @@ static spdylay_map_entry* find_left_most(spdylay_map_entry *entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find left most leaf. */
|
/* Find left most leaf. */
|
||||||
static spdylay_map_entry* find_left_most_leaf(spdylay_map_entry *entry)
|
static nghttp2_map_entry* find_left_most_leaf(nghttp2_map_entry *entry)
|
||||||
{
|
{
|
||||||
for(;;) {
|
for(;;) {
|
||||||
entry = find_left_most(entry);
|
entry = find_left_most(entry);
|
||||||
|
@ -60,8 +60,8 @@ static spdylay_map_entry* find_left_most_leaf(spdylay_map_entry *entry)
|
||||||
|
|
||||||
/* Returns next node in postorder traversal. Returns NULL if there is
|
/* Returns next node in postorder traversal. Returns NULL if there is
|
||||||
no next node. */
|
no next node. */
|
||||||
static spdylay_map_entry* traverse_postorder(spdylay_map_entry *parent,
|
static nghttp2_map_entry* traverse_postorder(nghttp2_map_entry *parent,
|
||||||
spdylay_map_entry *entry)
|
nghttp2_map_entry *entry)
|
||||||
{
|
{
|
||||||
if(!parent) {
|
if(!parent) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -77,17 +77,17 @@ static spdylay_map_entry* traverse_postorder(spdylay_map_entry *parent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_map_each_free(spdylay_map *map,
|
void nghttp2_map_each_free(nghttp2_map *map,
|
||||||
int (*func)(spdylay_map_entry *entry, void *ptr),
|
int (*func)(nghttp2_map_entry *entry, void *ptr),
|
||||||
void *ptr)
|
void *ptr)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *entry;
|
nghttp2_map_entry *entry;
|
||||||
if(!map->root) {
|
if(!map->root) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
entry = find_left_most_leaf(map->root);
|
entry = find_left_most_leaf(map->root);
|
||||||
while(entry) {
|
while(entry) {
|
||||||
spdylay_map_entry *parent = entry->parent;
|
nghttp2_map_entry *parent = entry->parent;
|
||||||
/* Ignore return value. */
|
/* Ignore return value. */
|
||||||
func(entry, ptr);
|
func(entry, ptr);
|
||||||
/* entry has been deleted. */
|
/* entry has been deleted. */
|
||||||
|
@ -98,9 +98,9 @@ void spdylay_map_each_free(spdylay_map *map,
|
||||||
|
|
||||||
/* Returns next node in inorder traversal. Returns NULL if there is no
|
/* Returns next node in inorder traversal. Returns NULL if there is no
|
||||||
next node. */
|
next node. */
|
||||||
static spdylay_map_entry* traverse_inorder(spdylay_map_entry *entry)
|
static nghttp2_map_entry* traverse_inorder(nghttp2_map_entry *entry)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *parent;
|
nghttp2_map_entry *parent;
|
||||||
if(entry->right) {
|
if(entry->right) {
|
||||||
return find_left_most(entry->right);
|
return find_left_most(entry->right);
|
||||||
}
|
}
|
||||||
|
@ -112,11 +112,11 @@ static spdylay_map_entry* traverse_inorder(spdylay_map_entry *entry)
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_map_each(spdylay_map *map,
|
int nghttp2_map_each(nghttp2_map *map,
|
||||||
int (*func)(spdylay_map_entry *entry, void *ptr),
|
int (*func)(nghttp2_map_entry *entry, void *ptr),
|
||||||
void *ptr)
|
void *ptr)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *entry;
|
nghttp2_map_entry *entry;
|
||||||
if(!map->root) {
|
if(!map->root) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -147,16 +147,16 @@ static uint32_t hash32shift(uint32_t key)
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_map_entry_init(spdylay_map_entry *entry, key_type key)
|
void nghttp2_map_entry_init(nghttp2_map_entry *entry, key_type key)
|
||||||
{
|
{
|
||||||
entry->key = key;
|
entry->key = key;
|
||||||
entry->parent = entry->left = entry->right = NULL;
|
entry->parent = entry->left = entry->right = NULL;
|
||||||
entry->priority = hash32shift(key);
|
entry->priority = hash32shift(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static spdylay_map_entry* rotate_left(spdylay_map_entry *entry)
|
static nghttp2_map_entry* rotate_left(nghttp2_map_entry *entry)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *root = entry->right;
|
nghttp2_map_entry *root = entry->right;
|
||||||
entry->right = root->left;
|
entry->right = root->left;
|
||||||
root->left = entry;
|
root->left = entry;
|
||||||
|
|
||||||
|
@ -175,9 +175,9 @@ static spdylay_map_entry* rotate_left(spdylay_map_entry *entry)
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
static spdylay_map_entry* rotate_right(spdylay_map_entry* entry)
|
static nghttp2_map_entry* rotate_right(nghttp2_map_entry* entry)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *root = entry->left;
|
nghttp2_map_entry *root = entry->left;
|
||||||
entry->left = root->right;
|
entry->left = root->right;
|
||||||
root->right = entry;
|
root->right = entry;
|
||||||
|
|
||||||
|
@ -196,9 +196,9 @@ static spdylay_map_entry* rotate_right(spdylay_map_entry* entry)
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_map_insert(spdylay_map *map, spdylay_map_entry *new_entry)
|
int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_entry *new_entry)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *entry = map->root, *parent = NULL;
|
nghttp2_map_entry *entry = map->root, *parent = NULL;
|
||||||
if(map->root == NULL) {
|
if(map->root == NULL) {
|
||||||
map->root = new_entry;
|
map->root = new_entry;
|
||||||
map->size = 1;
|
map->size = 1;
|
||||||
|
@ -207,7 +207,7 @@ int spdylay_map_insert(spdylay_map *map, spdylay_map_entry *new_entry)
|
||||||
/* Find position to insert. */
|
/* Find position to insert. */
|
||||||
while(1) {
|
while(1) {
|
||||||
if(new_entry->key == entry->key) {
|
if(new_entry->key == entry->key) {
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
} else {
|
} else {
|
||||||
if(new_entry->key < entry->key) {
|
if(new_entry->key < entry->key) {
|
||||||
if(entry->left) {
|
if(entry->left) {
|
||||||
|
@ -250,9 +250,9 @@ int spdylay_map_insert(spdylay_map *map, spdylay_map_entry *new_entry)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdylay_map_entry* spdylay_map_find(spdylay_map *map, key_type key)
|
nghttp2_map_entry* nghttp2_map_find(nghttp2_map *map, key_type key)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *entry = map->root;
|
nghttp2_map_entry *entry = map->root;
|
||||||
while(entry != NULL) {
|
while(entry != NULL) {
|
||||||
if(key < entry->key) {
|
if(key < entry->key) {
|
||||||
entry = entry->left;
|
entry = entry->left;
|
||||||
|
@ -265,12 +265,12 @@ spdylay_map_entry* spdylay_map_find(spdylay_map *map, key_type key)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_map_remove(spdylay_map *map, key_type key)
|
int nghttp2_map_remove(nghttp2_map *map, key_type key)
|
||||||
{
|
{
|
||||||
spdylay_map_entry *entry = map->root;
|
nghttp2_map_entry *entry = map->root;
|
||||||
|
|
||||||
if(map->root == NULL) {
|
if(map->root == NULL) {
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
/* Locate entry to delete. */
|
/* Locate entry to delete. */
|
||||||
while(entry) {
|
while(entry) {
|
||||||
|
@ -284,7 +284,7 @@ int spdylay_map_remove(spdylay_map *map, key_type key)
|
||||||
}
|
}
|
||||||
if(!entry) {
|
if(!entry) {
|
||||||
/* Not found */
|
/* Not found */
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
/* Rotate and bubble down to satisfy heap property. */
|
/* Rotate and bubble down to satisfy heap property. */
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
@ -330,7 +330,7 @@ int spdylay_map_remove(spdylay_map *map, key_type key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_map_size(spdylay_map *map)
|
size_t nghttp2_map_size(nghttp2_map *map)
|
||||||
{
|
{
|
||||||
return map->size;
|
return map->size;
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,43 +22,43 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_MAP_H
|
#ifndef NGHTTP2_MAP_H
|
||||||
#define SPDYLAY_MAP_H
|
#define NGHTTP2_MAP_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include "spdylay_int.h"
|
#include "nghttp2_int.h"
|
||||||
|
|
||||||
/* Implementation of ordered map */
|
/* Implementation of ordered map */
|
||||||
|
|
||||||
typedef uint32_t key_type;
|
typedef uint32_t key_type;
|
||||||
typedef uint32_t pri_type;
|
typedef uint32_t pri_type;
|
||||||
|
|
||||||
typedef struct spdylay_map_entry {
|
typedef struct nghttp2_map_entry {
|
||||||
key_type key;
|
key_type key;
|
||||||
struct spdylay_map_entry *parent, *left, *right;
|
struct nghttp2_map_entry *parent, *left, *right;
|
||||||
pri_type priority;
|
pri_type priority;
|
||||||
} spdylay_map_entry;
|
} nghttp2_map_entry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_map_entry *root;
|
nghttp2_map_entry *root;
|
||||||
size_t size;
|
size_t size;
|
||||||
} spdylay_map;
|
} nghttp2_map;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the map |map|.
|
* Initializes the map |map|.
|
||||||
*/
|
*/
|
||||||
void spdylay_map_init(spdylay_map *map);
|
void nghttp2_map_init(nghttp2_map *map);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates any resources allocated for |map|. The stored entries
|
* Deallocates any resources allocated for |map|. The stored entries
|
||||||
* are not freed by this function. Use spdylay_map_each_free() to free
|
* are not freed by this function. Use nghttp2_map_each_free() to free
|
||||||
* each entries.
|
* each entries.
|
||||||
*/
|
*/
|
||||||
void spdylay_map_free(spdylay_map *map);
|
void nghttp2_map_free(nghttp2_map *map);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates each entries using |func| function and any resources
|
* Deallocates each entries using |func| function and any resources
|
||||||
|
@ -66,15 +66,15 @@ void spdylay_map_free(spdylay_map *map);
|
||||||
* given the |entry| object. The |ptr| will be passed to the |func| as
|
* given the |entry| object. The |ptr| will be passed to the |func| as
|
||||||
* send argument. The return value of the |func| will be ignored.
|
* send argument. The return value of the |func| will be ignored.
|
||||||
*/
|
*/
|
||||||
void spdylay_map_each_free(spdylay_map *map,
|
void nghttp2_map_each_free(nghttp2_map *map,
|
||||||
int (*func)(spdylay_map_entry *entry, void *ptr),
|
int (*func)(nghttp2_map_entry *entry, void *ptr),
|
||||||
void *ptr);
|
void *ptr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the |entry| with the |key|. All entries to be inserted
|
* Initializes the |entry| with the |key|. All entries to be inserted
|
||||||
* to the map must be initialized with this function.
|
* to the map must be initialized with this function.
|
||||||
*/
|
*/
|
||||||
void spdylay_map_entry_init(spdylay_map_entry *entry, key_type key);
|
void nghttp2_map_entry_init(nghttp2_map_entry *entry, key_type key);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inserts the new |entry| with the key |entry->key| to the map |map|.
|
* Inserts the new |entry| with the key |entry->key| to the map |map|.
|
||||||
|
@ -82,16 +82,16 @@ void spdylay_map_entry_init(spdylay_map_entry *entry, key_type key);
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error code:
|
* negative error code:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_ARGUMENT
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||||
* The item associated by |key| already exists.
|
* The item associated by |key| already exists.
|
||||||
*/
|
*/
|
||||||
int spdylay_map_insert(spdylay_map *map, spdylay_map_entry *entry);
|
int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_entry *entry);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the entry associated by the key |key|. If there is no such
|
* Returns the entry associated by the key |key|. If there is no such
|
||||||
* entry, this function returns NULL.
|
* entry, this function returns NULL.
|
||||||
*/
|
*/
|
||||||
spdylay_map_entry* spdylay_map_find(spdylay_map *map, key_type key);
|
nghttp2_map_entry* nghttp2_map_find(nghttp2_map *map, key_type key);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Removes the entry associated by the key |key| from the |map|. The
|
* Removes the entry associated by the key |key| from the |map|. The
|
||||||
|
@ -100,15 +100,15 @@ spdylay_map_entry* spdylay_map_find(spdylay_map *map, key_type key);
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_ARGUMENT
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||||
* The entry associated by |key| does not exist.
|
* The entry associated by |key| does not exist.
|
||||||
*/
|
*/
|
||||||
int spdylay_map_remove(spdylay_map *map, key_type key);
|
int nghttp2_map_remove(nghttp2_map *map, key_type key);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the number of items stored in the map |map|.
|
* Returns the number of items stored in the map |map|.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_map_size(spdylay_map *map);
|
size_t nghttp2_map_size(nghttp2_map *map);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Applies the function |func| to each entry in the |map| with the
|
* Applies the function |func| to each entry in the |map| with the
|
||||||
|
@ -122,10 +122,10 @@ size_t spdylay_map_size(spdylay_map *map);
|
||||||
* invocation of |func| returns.
|
* invocation of |func| returns.
|
||||||
*
|
*
|
||||||
* Don't use this function to free each entry. Use
|
* Don't use this function to free each entry. Use
|
||||||
* spdylay_map_each_free() instead.
|
* nghttp2_map_each_free() instead.
|
||||||
*/
|
*/
|
||||||
int spdylay_map_each(spdylay_map *map,
|
int nghttp2_map_each(nghttp2_map *map,
|
||||||
int (*func)(spdylay_map_entry *entry, void *ptr),
|
int (*func)(nghttp2_map_entry *entry, void *ptr),
|
||||||
void *ptr);
|
void *ptr);
|
||||||
|
|
||||||
#endif /* SPDYLAY_MAP_H */
|
#endif /* NGHTTP2_MAP_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,8 +22,8 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_NET_H
|
#ifndef NGHTTP2_NET_H
|
||||||
#define SPDYLAY_NET_H
|
#define NGHTTP2_NET_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
|
@ -41,4 +41,4 @@
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
#endif /* HAVE_WINSOCK2_H */
|
#endif /* HAVE_WINSOCK2_H */
|
||||||
|
|
||||||
#endif /* SPDYLAY_NET_H */
|
#endif /* NGHTTP2_NET_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,29 +22,29 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_npn.h"
|
#include "nghttp2_npn.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const spdylay_npn_proto proto_list[] = {
|
static const nghttp2_npn_proto proto_list[] = {
|
||||||
{ (const unsigned char*)"spdy/3", 6, SPDYLAY_PROTO_SPDY3 },
|
{ (const unsigned char*)"spdy/3", 6, NGHTTP2_PROTO_SPDY3 },
|
||||||
{ (const unsigned char*)"spdy/2", 6, SPDYLAY_PROTO_SPDY2 }
|
{ (const unsigned char*)"spdy/2", 6, NGHTTP2_PROTO_SPDY2 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const spdylay_npn_proto* spdylay_npn_get_proto_list(size_t *len_ptr)
|
const nghttp2_npn_proto* nghttp2_npn_get_proto_list(size_t *len_ptr)
|
||||||
{
|
{
|
||||||
*len_ptr = sizeof(proto_list)/sizeof(spdylay_npn_proto);
|
*len_ptr = sizeof(proto_list)/sizeof(nghttp2_npn_proto);
|
||||||
return proto_list;
|
return proto_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_select_next_protocol(unsigned char **out, unsigned char *outlen,
|
int nghttp2_select_next_protocol(unsigned char **out, unsigned char *outlen,
|
||||||
const unsigned char *in, unsigned int inlen)
|
const unsigned char *in, unsigned int inlen)
|
||||||
{
|
{
|
||||||
int http_selected = 0;
|
int http_selected = 0;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for(; i < inlen; i += in[i]+1) {
|
for(; i < inlen; i += in[i]+1) {
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
for(j = 0; j < sizeof(proto_list)/sizeof(spdylay_npn_proto); ++j) {
|
for(j = 0; j < sizeof(proto_list)/sizeof(nghttp2_npn_proto); ++j) {
|
||||||
if(in[i] == proto_list[j].len &&
|
if(in[i] == proto_list[j].len &&
|
||||||
memcmp(&in[i+1], proto_list[j].proto, in[i]) == 0) {
|
memcmp(&in[i+1], proto_list[j].proto, in[i]) == 0) {
|
||||||
*out = (unsigned char*)&in[i+1];
|
*out = (unsigned char*)&in[i+1];
|
||||||
|
@ -67,16 +67,16 @@ int spdylay_select_next_protocol(unsigned char **out, unsigned char *outlen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t spdylay_npn_get_version(const unsigned char *proto, size_t protolen)
|
uint16_t nghttp2_npn_get_version(const unsigned char *proto, size_t protolen)
|
||||||
{
|
{
|
||||||
if(proto == NULL) {
|
if(proto == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if(protolen == 6) {
|
if(protolen == 6) {
|
||||||
if(memcmp("spdy/2", proto, 6) == 0) {
|
if(memcmp("spdy/2", proto, 6) == 0) {
|
||||||
return SPDYLAY_PROTO_SPDY2;
|
return NGHTTP2_PROTO_SPDY2;
|
||||||
} else if(memcmp("spdy/3", proto, 6) == 0) {
|
} else if(memcmp("spdy/3", proto, 6) == 0) {
|
||||||
return SPDYLAY_PROTO_SPDY3;
|
return NGHTTP2_PROTO_SPDY3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,13 +22,13 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_NPN_H
|
#ifndef NGHTTP2_NPN_H
|
||||||
#define SPDYLAY_NPN_H
|
#define NGHTTP2_NPN_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG
|
#ifdef HAVE_CONFIG
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG */
|
#endif /* HAVE_CONFIG */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
#endif /* SPDYLAY_NPN_H */
|
#endif /* NGHTTP2_NPN_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,58 +22,58 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_outbound_item.h"
|
#include "nghttp2_outbound_item.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void spdylay_outbound_item_free(spdylay_outbound_item *item)
|
void nghttp2_outbound_item_free(nghttp2_outbound_item *item)
|
||||||
{
|
{
|
||||||
if(item == NULL) {
|
if(item == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(item->frame_cat == SPDYLAY_CTRL) {
|
if(item->frame_cat == NGHTTP2_CTRL) {
|
||||||
spdylay_frame_type frame_type;
|
nghttp2_frame_type frame_type;
|
||||||
spdylay_frame *frame;
|
nghttp2_frame *frame;
|
||||||
frame_type = spdylay_outbound_item_get_ctrl_frame_type(item);
|
frame_type = nghttp2_outbound_item_get_ctrl_frame_type(item);
|
||||||
frame = spdylay_outbound_item_get_ctrl_frame(item);
|
frame = nghttp2_outbound_item_get_ctrl_frame(item);
|
||||||
switch(frame_type) {
|
switch(frame_type) {
|
||||||
case SPDYLAY_SYN_STREAM:
|
case NGHTTP2_SYN_STREAM:
|
||||||
spdylay_frame_syn_stream_free(&frame->syn_stream);
|
nghttp2_frame_syn_stream_free(&frame->syn_stream);
|
||||||
free(((spdylay_syn_stream_aux_data*)item->aux_data)->data_prd);
|
free(((nghttp2_syn_stream_aux_data*)item->aux_data)->data_prd);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_SYN_REPLY:
|
case NGHTTP2_SYN_REPLY:
|
||||||
spdylay_frame_syn_reply_free(&frame->syn_reply);
|
nghttp2_frame_syn_reply_free(&frame->syn_reply);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_RST_STREAM:
|
case NGHTTP2_RST_STREAM:
|
||||||
spdylay_frame_rst_stream_free(&frame->rst_stream);
|
nghttp2_frame_rst_stream_free(&frame->rst_stream);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_SETTINGS:
|
case NGHTTP2_SETTINGS:
|
||||||
spdylay_frame_settings_free(&frame->settings);
|
nghttp2_frame_settings_free(&frame->settings);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_NOOP:
|
case NGHTTP2_NOOP:
|
||||||
/* We don't have any public API to add NOOP, so here is
|
/* We don't have any public API to add NOOP, so here is
|
||||||
unreachable. */
|
unreachable. */
|
||||||
assert(0);
|
assert(0);
|
||||||
case SPDYLAY_PING:
|
case NGHTTP2_PING:
|
||||||
spdylay_frame_ping_free(&frame->ping);
|
nghttp2_frame_ping_free(&frame->ping);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_GOAWAY:
|
case NGHTTP2_GOAWAY:
|
||||||
spdylay_frame_goaway_free(&frame->goaway);
|
nghttp2_frame_goaway_free(&frame->goaway);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_HEADERS:
|
case NGHTTP2_HEADERS:
|
||||||
spdylay_frame_headers_free(&frame->headers);
|
nghttp2_frame_headers_free(&frame->headers);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_WINDOW_UPDATE:
|
case NGHTTP2_WINDOW_UPDATE:
|
||||||
spdylay_frame_window_update_free(&frame->window_update);
|
nghttp2_frame_window_update_free(&frame->window_update);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_CREDENTIAL:
|
case NGHTTP2_CREDENTIAL:
|
||||||
spdylay_frame_credential_free(&frame->credential);
|
nghttp2_frame_credential_free(&frame->credential);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if(item->frame_cat == SPDYLAY_DATA) {
|
} else if(item->frame_cat == NGHTTP2_DATA) {
|
||||||
spdylay_data *data_frame;
|
nghttp2_data *data_frame;
|
||||||
data_frame = spdylay_outbound_item_get_data_frame(item);
|
data_frame = nghttp2_outbound_item_get_data_frame(item);
|
||||||
spdylay_frame_data_free(data_frame);
|
nghttp2_frame_data_free(data_frame);
|
||||||
} else {
|
} else {
|
||||||
/* Unreachable */
|
/* Unreachable */
|
||||||
assert(0);
|
assert(0);
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,32 +22,32 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_OUTBOUND_ITEM_H
|
#ifndef NGHTTP2_OUTBOUND_ITEM_H
|
||||||
#define SPDYLAY_OUTBOUND_ITEM_H
|
#define NGHTTP2_OUTBOUND_ITEM_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include "spdylay_frame.h"
|
#include "nghttp2_frame.h"
|
||||||
|
|
||||||
/* Priority for PING */
|
/* Priority for PING */
|
||||||
#define SPDYLAY_OB_PRI_PING -10
|
#define NGHTTP2_OB_PRI_PING -10
|
||||||
/* Priority for CREDENTIAL */
|
/* Priority for CREDENTIAL */
|
||||||
#define SPDYLAY_OB_PRI_CREDENTIAL -2
|
#define NGHTTP2_OB_PRI_CREDENTIAL -2
|
||||||
/* Priority for the frame which must be sent after CREDENTIAL */
|
/* Priority for the frame which must be sent after CREDENTIAL */
|
||||||
#define SPDYLAY_OB_PRI_AFTER_CREDENTIAL -1
|
#define NGHTTP2_OB_PRI_AFTER_CREDENTIAL -1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_data_provider *data_prd;
|
nghttp2_data_provider *data_prd;
|
||||||
void *stream_user_data;
|
void *stream_user_data;
|
||||||
} spdylay_syn_stream_aux_data;
|
} nghttp2_syn_stream_aux_data;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Type of |frame|. SPDYLAY_CTRL: spdylay_frame*, SPDYLAY_DATA:
|
/* Type of |frame|. NGHTTP2_CTRL: nghttp2_frame*, NGHTTP2_DATA:
|
||||||
spdylay_data* */
|
nghttp2_data* */
|
||||||
spdylay_frame_category frame_cat;
|
nghttp2_frame_category frame_cat;
|
||||||
void *frame;
|
void *frame;
|
||||||
void *aux_data;
|
void *aux_data;
|
||||||
/* Initial priority of this item */
|
/* Initial priority of this item */
|
||||||
|
@ -63,18 +63,18 @@ typedef struct {
|
||||||
prioritized streams. */
|
prioritized streams. */
|
||||||
int pri;
|
int pri;
|
||||||
int64_t seq;
|
int64_t seq;
|
||||||
} spdylay_outbound_item;
|
} nghttp2_outbound_item;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates resource for |item|. If |item| is NULL, this function
|
* Deallocates resource for |item|. If |item| is NULL, this function
|
||||||
* does nothing.
|
* does nothing.
|
||||||
*/
|
*/
|
||||||
void spdylay_outbound_item_free(spdylay_outbound_item *item);
|
void nghttp2_outbound_item_free(nghttp2_outbound_item *item);
|
||||||
|
|
||||||
/* Macros to cast spdylay_outbound_item.frame to the proper type. */
|
/* Macros to cast nghttp2_outbound_item.frame to the proper type. */
|
||||||
#define spdylay_outbound_item_get_ctrl_frame(ITEM) ((spdylay_frame*)ITEM->frame)
|
#define nghttp2_outbound_item_get_ctrl_frame(ITEM) ((nghttp2_frame*)ITEM->frame)
|
||||||
#define spdylay_outbound_item_get_ctrl_frame_type(ITEM) \
|
#define nghttp2_outbound_item_get_ctrl_frame_type(ITEM) \
|
||||||
(((spdylay_frame*)ITEM->frame)->ctrl.hd.type)
|
(((nghttp2_frame*)ITEM->frame)->ctrl.hd.type)
|
||||||
#define spdylay_outbound_item_get_data_frame(ITEM) ((spdylay_data*)ITEM->frame)
|
#define nghttp2_outbound_item_get_data_frame(ITEM) ((nghttp2_data*)ITEM->frame)
|
||||||
|
|
||||||
#endif /* SPDYLAY_OUTBOUND_ITEM_H */
|
#endif /* NGHTTP2_OUTBOUND_ITEM_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,34 +22,34 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_pq.h"
|
#include "nghttp2_pq.h"
|
||||||
|
|
||||||
int spdylay_pq_init(spdylay_pq *pq, spdylay_compar compar)
|
int nghttp2_pq_init(nghttp2_pq *pq, nghttp2_compar compar)
|
||||||
{
|
{
|
||||||
pq->capacity = 4096;
|
pq->capacity = 4096;
|
||||||
pq->q = malloc(pq->capacity * sizeof(void*));
|
pq->q = malloc(pq->capacity * sizeof(void*));
|
||||||
if(pq->q == NULL) {
|
if(pq->q == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
pq->length = 0;
|
pq->length = 0;
|
||||||
pq->compar = compar;
|
pq->compar = compar;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_pq_free(spdylay_pq *pq)
|
void nghttp2_pq_free(nghttp2_pq *pq)
|
||||||
{
|
{
|
||||||
free(pq->q);
|
free(pq->q);
|
||||||
pq->q = NULL;
|
pq->q = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swap(spdylay_pq *pq, size_t i, size_t j)
|
static void swap(nghttp2_pq *pq, size_t i, size_t j)
|
||||||
{
|
{
|
||||||
void *t = pq->q[i];
|
void *t = pq->q[i];
|
||||||
pq->q[i] = pq->q[j];
|
pq->q[i] = pq->q[j];
|
||||||
pq->q[j] = t;
|
pq->q[j] = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bubble_up(spdylay_pq *pq, size_t index)
|
static void bubble_up(nghttp2_pq *pq, size_t index)
|
||||||
{
|
{
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -62,13 +62,13 @@ static void bubble_up(spdylay_pq *pq, size_t index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_pq_push(spdylay_pq *pq, void *item)
|
int nghttp2_pq_push(nghttp2_pq *pq, void *item)
|
||||||
{
|
{
|
||||||
if(pq->capacity <= pq->length) {
|
if(pq->capacity <= pq->length) {
|
||||||
void *nq;
|
void *nq;
|
||||||
nq = realloc(pq->q, (pq->capacity*2) * sizeof(void*));
|
nq = realloc(pq->q, (pq->capacity*2) * sizeof(void*));
|
||||||
if(nq == NULL) {
|
if(nq == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
pq->capacity *= 2;
|
pq->capacity *= 2;
|
||||||
pq->q = nq;
|
pq->q = nq;
|
||||||
|
@ -79,7 +79,7 @@ int spdylay_pq_push(spdylay_pq *pq, void *item)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* spdylay_pq_top(spdylay_pq *pq)
|
void* nghttp2_pq_top(nghttp2_pq *pq)
|
||||||
{
|
{
|
||||||
if(pq->length == 0) {
|
if(pq->length == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -88,7 +88,7 @@ void* spdylay_pq_top(spdylay_pq *pq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bubble_down(spdylay_pq *pq, size_t index)
|
static void bubble_down(nghttp2_pq *pq, size_t index)
|
||||||
{
|
{
|
||||||
size_t lchild = index*2+1;
|
size_t lchild = index*2+1;
|
||||||
size_t minindex = index;
|
size_t minindex = index;
|
||||||
|
@ -108,7 +108,7 @@ static void bubble_down(spdylay_pq *pq, size_t index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_pq_pop(spdylay_pq *pq)
|
void nghttp2_pq_pop(nghttp2_pq *pq)
|
||||||
{
|
{
|
||||||
if(pq->length > 0) {
|
if(pq->length > 0) {
|
||||||
pq->q[0] = pq->q[pq->length-1];
|
pq->q[0] = pq->q[pq->length-1];
|
||||||
|
@ -117,12 +117,12 @@ void spdylay_pq_pop(spdylay_pq *pq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_pq_empty(spdylay_pq *pq)
|
int nghttp2_pq_empty(nghttp2_pq *pq)
|
||||||
{
|
{
|
||||||
return pq->length == 0;
|
return pq->length == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_pq_size(spdylay_pq *pq)
|
size_t nghttp2_pq_size(nghttp2_pq *pq)
|
||||||
{
|
{
|
||||||
return pq->length;
|
return pq->length;
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,15 +22,15 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_PQ_H
|
#ifndef NGHTTP2_PQ_H
|
||||||
#define SPDYLAY_PQ_H
|
#define NGHTTP2_PQ_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include "spdylay_int.h"
|
#include "nghttp2_int.h"
|
||||||
|
|
||||||
/* Implementation of priority queue */
|
/* Implementation of priority queue */
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ typedef struct {
|
||||||
automatically extended when length is reached to this value. */
|
automatically extended when length is reached to this value. */
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
/* The compare function between items */
|
/* The compare function between items */
|
||||||
spdylay_compar compar;
|
nghttp2_compar compar;
|
||||||
} spdylay_pq;
|
} nghttp2_pq;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes priority queue |pq| with compare function |cmp|.
|
* Initializes priority queue |pq| with compare function |cmp|.
|
||||||
|
@ -52,16 +52,16 @@ typedef struct {
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_pq_init(spdylay_pq *pq, spdylay_compar cmp);
|
int nghttp2_pq_init(nghttp2_pq *pq, nghttp2_compar cmp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates any resources allocated for |pq|. The stored items are
|
* Deallocates any resources allocated for |pq|. The stored items are
|
||||||
* not freed by this function.
|
* not freed by this function.
|
||||||
*/
|
*/
|
||||||
void spdylay_pq_free(spdylay_pq *pq);
|
void nghttp2_pq_free(nghttp2_pq *pq);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds |item| to the priority queue |pq|.
|
* Adds |item| to the priority queue |pq|.
|
||||||
|
@ -69,31 +69,31 @@ void spdylay_pq_free(spdylay_pq *pq);
|
||||||
* This function returns 0 if it succeds, or one of the following
|
* This function returns 0 if it succeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_pq_push(spdylay_pq *pq, void *item);
|
int nghttp2_pq_push(nghttp2_pq *pq, void *item);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns item at the top of the queue |pq|. If the queue is empty,
|
* Returns item at the top of the queue |pq|. If the queue is empty,
|
||||||
* this function returns NULL.
|
* this function returns NULL.
|
||||||
*/
|
*/
|
||||||
void* spdylay_pq_top(spdylay_pq *pq);
|
void* nghttp2_pq_top(nghttp2_pq *pq);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pops item at the top of the queue |pq|. The popped item is not
|
* Pops item at the top of the queue |pq|. The popped item is not
|
||||||
* freed by this function.
|
* freed by this function.
|
||||||
*/
|
*/
|
||||||
void spdylay_pq_pop(spdylay_pq *pq);
|
void nghttp2_pq_pop(nghttp2_pq *pq);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns nonzero if the queue |pq| is empty.
|
* Returns nonzero if the queue |pq| is empty.
|
||||||
*/
|
*/
|
||||||
int spdylay_pq_empty(spdylay_pq *pq);
|
int nghttp2_pq_empty(nghttp2_pq *pq);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the number of items in the queue |pq|.
|
* Returns the number of items in the queue |pq|.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_pq_size(spdylay_pq *pq);
|
size_t nghttp2_pq_size(nghttp2_pq *pq);
|
||||||
|
|
||||||
#endif /* SPDYLAY_PQ_H */
|
#endif /* NGHTTP2_PQ_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,36 +22,36 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_queue.h"
|
#include "nghttp2_queue.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void spdylay_queue_init(spdylay_queue *queue)
|
void nghttp2_queue_init(nghttp2_queue *queue)
|
||||||
{
|
{
|
||||||
queue->front = queue->back = NULL;
|
queue->front = queue->back = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_queue_free(spdylay_queue *queue)
|
void nghttp2_queue_free(nghttp2_queue *queue)
|
||||||
{
|
{
|
||||||
if(!queue) {
|
if(!queue) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
spdylay_queue_cell *p = queue->front;
|
nghttp2_queue_cell *p = queue->front;
|
||||||
while(p) {
|
while(p) {
|
||||||
spdylay_queue_cell *next = p->next;
|
nghttp2_queue_cell *next = p->next;
|
||||||
free(p);
|
free(p);
|
||||||
p = next;
|
p = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_queue_push(spdylay_queue *queue, void *data)
|
int nghttp2_queue_push(nghttp2_queue *queue, void *data)
|
||||||
{
|
{
|
||||||
spdylay_queue_cell *new_cell = (spdylay_queue_cell*)malloc
|
nghttp2_queue_cell *new_cell = (nghttp2_queue_cell*)malloc
|
||||||
(sizeof(spdylay_queue_cell));
|
(sizeof(nghttp2_queue_cell));
|
||||||
if(!new_cell) {
|
if(!new_cell) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
new_cell->data = data;
|
new_cell->data = data;
|
||||||
new_cell->next = NULL;
|
new_cell->next = NULL;
|
||||||
|
@ -65,9 +65,9 @@ int spdylay_queue_push(spdylay_queue *queue, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_queue_pop(spdylay_queue *queue)
|
void nghttp2_queue_pop(nghttp2_queue *queue)
|
||||||
{
|
{
|
||||||
spdylay_queue_cell *front = queue->front;
|
nghttp2_queue_cell *front = queue->front;
|
||||||
assert(front);
|
assert(front);
|
||||||
queue->front = front->next;
|
queue->front = front->next;
|
||||||
if(front == queue->back) {
|
if(front == queue->back) {
|
||||||
|
@ -76,19 +76,19 @@ void spdylay_queue_pop(spdylay_queue *queue)
|
||||||
free(front);
|
free(front);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* spdylay_queue_front(spdylay_queue *queue)
|
void* nghttp2_queue_front(nghttp2_queue *queue)
|
||||||
{
|
{
|
||||||
assert(queue->front);
|
assert(queue->front);
|
||||||
return queue->front->data;
|
return queue->front->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* spdylay_queue_back(spdylay_queue *queue)
|
void* nghttp2_queue_back(nghttp2_queue *queue)
|
||||||
{
|
{
|
||||||
assert(queue->back);
|
assert(queue->back);
|
||||||
return queue->back->data;
|
return queue->back->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_queue_empty(spdylay_queue *queue)
|
int nghttp2_queue_empty(nghttp2_queue *queue)
|
||||||
{
|
{
|
||||||
return queue->front == NULL;
|
return queue->front == NULL;
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,30 +22,30 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_QUEUE_H
|
#ifndef NGHTTP2_QUEUE_H
|
||||||
#define SPDYLAY_QUEUE_H
|
#define NGHTTP2_QUEUE_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
typedef struct spdylay_queue_cell {
|
typedef struct nghttp2_queue_cell {
|
||||||
void *data;
|
void *data;
|
||||||
struct spdylay_queue_cell *next;
|
struct nghttp2_queue_cell *next;
|
||||||
} spdylay_queue_cell;
|
} nghttp2_queue_cell;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_queue_cell *front, *back;
|
nghttp2_queue_cell *front, *back;
|
||||||
} spdylay_queue;
|
} nghttp2_queue;
|
||||||
|
|
||||||
void spdylay_queue_init(spdylay_queue *queue);
|
void nghttp2_queue_init(nghttp2_queue *queue);
|
||||||
void spdylay_queue_free(spdylay_queue *queue);
|
void nghttp2_queue_free(nghttp2_queue *queue);
|
||||||
int spdylay_queue_push(spdylay_queue *queue, void *data);
|
int nghttp2_queue_push(nghttp2_queue *queue, void *data);
|
||||||
void spdylay_queue_pop(spdylay_queue *queue);
|
void nghttp2_queue_pop(nghttp2_queue *queue);
|
||||||
void* spdylay_queue_front(spdylay_queue *queue);
|
void* nghttp2_queue_front(nghttp2_queue *queue);
|
||||||
void* spdylay_queue_back(spdylay_queue *queue);
|
void* nghttp2_queue_back(nghttp2_queue *queue);
|
||||||
int spdylay_queue_empty(spdylay_queue *queue);
|
int nghttp2_queue_empty(nghttp2_queue *queue);
|
||||||
|
|
||||||
#endif /* SPDYLAY_QUEUE_H */
|
#endif /* NGHTTP2_QUEUE_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,47 +22,47 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_SESSION_H
|
#ifndef NGHTTP2_SESSION_H
|
||||||
#define SPDYLAY_SESSION_H
|
#define NGHTTP2_SESSION_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include "spdylay_pq.h"
|
#include "nghttp2_pq.h"
|
||||||
#include "spdylay_map.h"
|
#include "nghttp2_map.h"
|
||||||
#include "spdylay_frame.h"
|
#include "nghttp2_frame.h"
|
||||||
#include "spdylay_zlib.h"
|
#include "nghttp2_zlib.h"
|
||||||
#include "spdylay_stream.h"
|
#include "nghttp2_stream.h"
|
||||||
#include "spdylay_buffer.h"
|
#include "nghttp2_buffer.h"
|
||||||
#include "spdylay_outbound_item.h"
|
#include "nghttp2_outbound_item.h"
|
||||||
#include "spdylay_client_cert_vector.h"
|
#include "nghttp2_client_cert_vector.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @macro
|
* @macro
|
||||||
* Lowest priority value in SPDY/2, which is 3.
|
* Lowest priority value in SPDY/2, which is 3.
|
||||||
*/
|
*/
|
||||||
#define SPDYLAY_PRI_LOWEST_SPDY2 3
|
#define NGHTTP2_PRI_LOWEST_SPDY2 3
|
||||||
/**
|
/**
|
||||||
* @macro
|
* @macro
|
||||||
* Lowest priority value in SPDY/3, which is 7.
|
* Lowest priority value in SPDY/3, which is 7.
|
||||||
*/
|
*/
|
||||||
#define SPDYLAY_PRI_LOWEST_SPDY3 7
|
#define NGHTTP2_PRI_LOWEST_SPDY3 7
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Option flags.
|
* Option flags.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0
|
NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0
|
||||||
} spdylay_optmask;
|
} nghttp2_optmask;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_outbound_item *item;
|
nghttp2_outbound_item *item;
|
||||||
/* Buffer for outbound frames. Used to pack one frame. The memory
|
/* Buffer for outbound frames. Used to pack one frame. The memory
|
||||||
pointed by framebuf is initially allocated by
|
pointed by framebuf is initially allocated by
|
||||||
spdylay_session_{client,server}_new() and deallocated by
|
nghttp2_session_{client,server}_new() and deallocated by
|
||||||
spdylay_session_del() */
|
nghttp2_session_del() */
|
||||||
uint8_t *framebuf;
|
uint8_t *framebuf;
|
||||||
/* The capacity of framebuf in bytes */
|
/* The capacity of framebuf in bytes */
|
||||||
size_t framebufmax;
|
size_t framebufmax;
|
||||||
|
@ -70,48 +70,48 @@ typedef struct {
|
||||||
size_t framebuflen;
|
size_t framebuflen;
|
||||||
/* The number of bytes has been sent */
|
/* The number of bytes has been sent */
|
||||||
size_t framebufoff;
|
size_t framebufoff;
|
||||||
} spdylay_active_outbound_item;
|
} nghttp2_active_outbound_item;
|
||||||
|
|
||||||
/* Buffer length for inbound raw byte stream. */
|
/* Buffer length for inbound raw byte stream. */
|
||||||
#define SPDYLAY_INBOUND_BUFFER_LENGTH 16384
|
#define NGHTTP2_INBOUND_BUFFER_LENGTH 16384
|
||||||
|
|
||||||
#define SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH (SPDYLAY_DATA_PAYLOAD_LENGTH+8)
|
#define NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH (NGHTTP2_DATA_PAYLOAD_LENGTH+8)
|
||||||
#define SPDYLAY_INITIAL_INBOUND_FRAMEBUF_LENGTH \
|
#define NGHTTP2_INITIAL_INBOUND_FRAMEBUF_LENGTH \
|
||||||
SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH
|
NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH
|
||||||
#define SPDYLAY_INITIAL_NV_BUFFER_LENGTH 4096
|
#define NGHTTP2_INITIAL_NV_BUFFER_LENGTH 4096
|
||||||
|
|
||||||
#define SPDYLAY_INITIAL_WINDOW_SIZE 65536
|
#define NGHTTP2_INITIAL_WINDOW_SIZE 65536
|
||||||
|
|
||||||
/* Initial size of client certificate vector */
|
/* Initial size of client certificate vector */
|
||||||
#define SPDYLAY_INITIAL_CLIENT_CERT_VECTOR_LENGTH 8
|
#define NGHTTP2_INITIAL_CLIENT_CERT_VECTOR_LENGTH 8
|
||||||
/* Maxmum size of client certificate vector */
|
/* Maxmum size of client certificate vector */
|
||||||
#define SPDYLAY_MAX_CLIENT_CERT_VECTOR_LENGTH 255
|
#define NGHTTP2_MAX_CLIENT_CERT_VECTOR_LENGTH 255
|
||||||
|
|
||||||
/* Internal state when receiving incoming frame */
|
/* Internal state when receiving incoming frame */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* Receiving frame header */
|
/* Receiving frame header */
|
||||||
SPDYLAY_RECV_HEAD,
|
NGHTTP2_RECV_HEAD,
|
||||||
/* Receiving frame payload (comes after length field) */
|
/* Receiving frame payload (comes after length field) */
|
||||||
SPDYLAY_RECV_PAYLOAD,
|
NGHTTP2_RECV_PAYLOAD,
|
||||||
/* Receiving frame payload, but the received bytes are discarded. */
|
/* Receiving frame payload, but the received bytes are discarded. */
|
||||||
SPDYLAY_RECV_PAYLOAD_IGN,
|
NGHTTP2_RECV_PAYLOAD_IGN,
|
||||||
/* Receiving frame payload that comes before name/value header
|
/* Receiving frame payload that comes before name/value header
|
||||||
block. Applied only for SYN_STREAM, SYN_REPLY and HEADERS. */
|
block. Applied only for SYN_STREAM, SYN_REPLY and HEADERS. */
|
||||||
SPDYLAY_RECV_PAYLOAD_PRE_NV,
|
NGHTTP2_RECV_PAYLOAD_PRE_NV,
|
||||||
/* Receiving name/value header block in frame payload. Applied only
|
/* Receiving name/value header block in frame payload. Applied only
|
||||||
for SYN_STREAM, SYN_REPLY and HEADERS. */
|
for SYN_STREAM, SYN_REPLY and HEADERS. */
|
||||||
SPDYLAY_RECV_PAYLOAD_NV
|
NGHTTP2_RECV_PAYLOAD_NV
|
||||||
} spdylay_inbound_state;
|
} nghttp2_inbound_state;
|
||||||
|
|
||||||
#define SPDYLAY_HEAD_LEN 8
|
#define NGHTTP2_HEAD_LEN 8
|
||||||
|
|
||||||
/* Maximum unique ID in use for PING. If unique ID exeeds this number,
|
/* Maximum unique ID in use for PING. If unique ID exeeds this number,
|
||||||
it wraps to 1 (client) or 2 (server) */
|
it wraps to 1 (client) or 2 (server) */
|
||||||
#define SPDYLAY_MAX_UNIQUE_ID ((1u << 31)-1)
|
#define NGHTTP2_MAX_UNIQUE_ID ((1u << 31)-1)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_inbound_state state;
|
nghttp2_inbound_state state;
|
||||||
uint8_t headbuf[SPDYLAY_HEAD_LEN];
|
uint8_t headbuf[NGHTTP2_HEAD_LEN];
|
||||||
/* How many bytes are filled in headbuf */
|
/* How many bytes are filled in headbuf */
|
||||||
size_t headbufoff;
|
size_t headbufoff;
|
||||||
/* Payload for control frames. It is not used for DATA frames */
|
/* Payload for control frames. It is not used for DATA frames */
|
||||||
|
@ -131,53 +131,53 @@ typedef struct {
|
||||||
size_t off;
|
size_t off;
|
||||||
/* Buffer used to store name/value pairs while inflating them using
|
/* Buffer used to store name/value pairs while inflating them using
|
||||||
zlib on unpack */
|
zlib on unpack */
|
||||||
spdylay_buffer inflatebuf;
|
nghttp2_buffer inflatebuf;
|
||||||
/* Error code */
|
/* Error code */
|
||||||
int error_code;
|
int error_code;
|
||||||
} spdylay_inbound_frame;
|
} nghttp2_inbound_frame;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPDYLAY_GOAWAY_NONE = 0,
|
NGHTTP2_GOAWAY_NONE = 0,
|
||||||
/* Flag means GOAWAY frame is sent to the remote peer. */
|
/* Flag means GOAWAY frame is sent to the remote peer. */
|
||||||
SPDYLAY_GOAWAY_SEND = 0x1,
|
NGHTTP2_GOAWAY_SEND = 0x1,
|
||||||
/* Flag means GOAWAY frame is received from the remote peer. */
|
/* Flag means GOAWAY frame is received from the remote peer. */
|
||||||
SPDYLAY_GOAWAY_RECV = 0x2,
|
NGHTTP2_GOAWAY_RECV = 0x2,
|
||||||
/* Flag means connection should be dropped after sending GOAWAY. */
|
/* Flag means connection should be dropped after sending GOAWAY. */
|
||||||
SPDYLAY_GOAWAY_FAIL_ON_SEND = 0x4
|
NGHTTP2_GOAWAY_FAIL_ON_SEND = 0x4
|
||||||
} spdylay_goaway_flag;
|
} nghttp2_goaway_flag;
|
||||||
|
|
||||||
struct spdylay_session {
|
struct nghttp2_session {
|
||||||
/* The protocol version: either SPDYLAY_PROTO_SPDY2 or
|
/* The protocol version: either NGHTTP2_PROTO_SPDY2 or
|
||||||
SPDYLAY_PROTO_SPDY3 */
|
NGHTTP2_PROTO_SPDY3 */
|
||||||
uint16_t version;
|
uint16_t version;
|
||||||
uint8_t server;
|
uint8_t server;
|
||||||
/* Next Stream ID. Made unsigned int to detect >= (1 << 31). */
|
/* Next Stream ID. Made unsigned int to detect >= (1 << 31). */
|
||||||
uint32_t next_stream_id;
|
uint32_t next_stream_id;
|
||||||
int32_t last_recv_stream_id;
|
int32_t last_recv_stream_id;
|
||||||
/* Counter of unique ID of PING. Wraps when it exceeds
|
/* Counter of unique ID of PING. Wraps when it exceeds
|
||||||
SPDYLAY_MAX_UNIQUE_ID */
|
NGHTTP2_MAX_UNIQUE_ID */
|
||||||
uint32_t next_unique_id;
|
uint32_t next_unique_id;
|
||||||
|
|
||||||
/* Sequence number of outbound frame to maintain the order of
|
/* Sequence number of outbound frame to maintain the order of
|
||||||
enqueue if priority is equal. */
|
enqueue if priority is equal. */
|
||||||
int64_t next_seq;
|
int64_t next_seq;
|
||||||
|
|
||||||
spdylay_map /* <spdylay_stream*> */ streams;
|
nghttp2_map /* <nghttp2_stream*> */ streams;
|
||||||
/* The number of outgoing streams. This will be capped by
|
/* The number of outgoing streams. This will be capped by
|
||||||
remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]. */
|
remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]. */
|
||||||
size_t num_outgoing_streams;
|
size_t num_outgoing_streams;
|
||||||
/* The number of incoming streams. This will be capped by
|
/* The number of incoming streams. This will be capped by
|
||||||
local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]. */
|
local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]. */
|
||||||
size_t num_incoming_streams;
|
size_t num_incoming_streams;
|
||||||
|
|
||||||
/* Queue for outbound frames other than SYN_STREAM */
|
/* Queue for outbound frames other than SYN_STREAM */
|
||||||
spdylay_pq /* <spdylay_outbound_item*> */ ob_pq;
|
nghttp2_pq /* <nghttp2_outbound_item*> */ ob_pq;
|
||||||
/* Queue for outbound SYN_STREAM frame */
|
/* Queue for outbound SYN_STREAM frame */
|
||||||
spdylay_pq /* <spdylay_outbound_item*> */ ob_ss_pq;
|
nghttp2_pq /* <nghttp2_outbound_item*> */ ob_ss_pq;
|
||||||
|
|
||||||
spdylay_active_outbound_item aob;
|
nghttp2_active_outbound_item aob;
|
||||||
|
|
||||||
spdylay_inbound_frame iframe;
|
nghttp2_inbound_frame iframe;
|
||||||
|
|
||||||
/* Buffer used to store inflated name/value pairs in wire format
|
/* Buffer used to store inflated name/value pairs in wire format
|
||||||
temporarily on pack/unpack. */
|
temporarily on pack/unpack. */
|
||||||
|
@ -185,14 +185,14 @@ struct spdylay_session {
|
||||||
/* The number of bytes allocated for nvbuf */
|
/* The number of bytes allocated for nvbuf */
|
||||||
size_t nvbuflen;
|
size_t nvbuflen;
|
||||||
|
|
||||||
spdylay_zlib hd_deflater;
|
nghttp2_zlib hd_deflater;
|
||||||
spdylay_zlib hd_inflater;
|
nghttp2_zlib hd_inflater;
|
||||||
|
|
||||||
/* The last unique ID sent to the peer. */
|
/* The last unique ID sent to the peer. */
|
||||||
uint32_t last_ping_unique_id;
|
uint32_t last_ping_unique_id;
|
||||||
|
|
||||||
/* Flags indicating GOAWAY is sent and/or recieved. The flags are
|
/* Flags indicating GOAWAY is sent and/or recieved. The flags are
|
||||||
composed by bitwise OR-ing spdylay_goaway_flag. */
|
composed by bitwise OR-ing nghttp2_goaway_flag. */
|
||||||
uint8_t goaway_flags;
|
uint8_t goaway_flags;
|
||||||
/* This is the value in GOAWAY frame sent by remote endpoint. */
|
/* This is the value in GOAWAY frame sent by remote endpoint. */
|
||||||
int32_t last_good_stream_id;
|
int32_t last_good_stream_id;
|
||||||
|
@ -203,28 +203,28 @@ struct spdylay_session {
|
||||||
|
|
||||||
/* Settings value received from the remote endpoint. We just use ID
|
/* Settings value received from the remote endpoint. We just use ID
|
||||||
as index. The index = 0 is unused. */
|
as index. The index = 0 is unused. */
|
||||||
uint32_t remote_settings[SPDYLAY_SETTINGS_MAX+1];
|
uint32_t remote_settings[NGHTTP2_SETTINGS_MAX+1];
|
||||||
/* Settings value of the local endpoint. */
|
/* Settings value of the local endpoint. */
|
||||||
uint32_t local_settings[SPDYLAY_SETTINGS_MAX+1];
|
uint32_t local_settings[NGHTTP2_SETTINGS_MAX+1];
|
||||||
|
|
||||||
/* Option flags. This is bitwise-OR of 0 or more of spdylay_optmask. */
|
/* Option flags. This is bitwise-OR of 0 or more of nghttp2_optmask. */
|
||||||
uint32_t opt_flags;
|
uint32_t opt_flags;
|
||||||
/* Maxmum size of buffer to use when receving control frame. */
|
/* Maxmum size of buffer to use when receving control frame. */
|
||||||
uint32_t max_recv_ctrl_frame_buf;
|
uint32_t max_recv_ctrl_frame_buf;
|
||||||
|
|
||||||
/* Client certificate vector */
|
/* Client certificate vector */
|
||||||
spdylay_client_cert_vector cli_certvec;
|
nghttp2_client_cert_vector cli_certvec;
|
||||||
|
|
||||||
spdylay_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
void *user_data;
|
void *user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Struct used when updating initial window size of each active
|
/* Struct used when updating initial window size of each active
|
||||||
stream. */
|
stream. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spdylay_session *session;
|
nghttp2_session *session;
|
||||||
int32_t new_window_size, old_window_size;
|
int32_t new_window_size, old_window_size;
|
||||||
} spdylay_update_window_size_arg;
|
} nghttp2_update_window_size_arg;
|
||||||
|
|
||||||
/* TODO stream timeout etc */
|
/* TODO stream timeout etc */
|
||||||
|
|
||||||
|
@ -232,15 +232,15 @@ typedef struct {
|
||||||
* Returns nonzero value if |stream_id| is initiated by local
|
* Returns nonzero value if |stream_id| is initiated by local
|
||||||
* endpoint.
|
* endpoint.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_is_my_stream_id(spdylay_session *session,
|
int nghttp2_session_is_my_stream_id(nghttp2_session *session,
|
||||||
int32_t stream_id);
|
int32_t stream_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds frame |frame| to the outbound queue in |session|. The
|
* Adds frame |frame| to the outbound queue in |session|. The
|
||||||
* |frame_cat| must be either SPDYLAY_CTRL or SPDYLAY_DATA. If the
|
* |frame_cat| must be either NGHTTP2_CTRL or NGHTTP2_DATA. If the
|
||||||
* |frame_cat| is SPDYLAY_CTRL, the |frame| must be a pointer to
|
* |frame_cat| is NGHTTP2_CTRL, the |frame| must be a pointer to
|
||||||
* spdylay_frame. If the |frame_cat| is SPDYLAY_DATA, it must be a
|
* nghttp2_frame. If the |frame_cat| is NGHTTP2_DATA, it must be a
|
||||||
* pointer to spdylay_data. |aux_data| is a pointer to the arbitrary
|
* pointer to nghttp2_data. |aux_data| is a pointer to the arbitrary
|
||||||
* data. Its interpretation is defined per the type of the frame. When
|
* data. Its interpretation is defined per the type of the frame. When
|
||||||
* this function succeeds, it takes ownership of |frame| and
|
* this function succeeds, it takes ownership of |frame| and
|
||||||
* |aux_data|, so caller must not free them on success.
|
* |aux_data|, so caller must not free them on success.
|
||||||
|
@ -248,78 +248,78 @@ int spdylay_session_is_my_stream_id(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_add_frame(spdylay_session *session,
|
int nghttp2_session_add_frame(nghttp2_session *session,
|
||||||
spdylay_frame_category frame_cat,
|
nghttp2_frame_category frame_cat,
|
||||||
void *abs_frame, void *aux_data);
|
void *abs_frame, void *aux_data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds RST_STREAM frame for the stream |stream_id| with status code
|
* Adds RST_STREAM frame for the stream |stream_id| with status code
|
||||||
* |status_code|. This is a convenient function built on top of
|
* |status_code|. This is a convenient function built on top of
|
||||||
* spdylay_session_add_frame() to add RST_STREAM easily.
|
* nghttp2_session_add_frame() to add RST_STREAM easily.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_add_rst_stream(spdylay_session *session,
|
int nghttp2_session_add_rst_stream(nghttp2_session *session,
|
||||||
int32_t stream_id, uint32_t status_code);
|
int32_t stream_id, uint32_t status_code);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds PING frame with unique ID |unique_id|. This is a convenient
|
* Adds PING frame with unique ID |unique_id|. This is a convenient
|
||||||
* functin built on top of spdylay_session_add_frame() to add PING
|
* functin built on top of nghttp2_session_add_frame() to add PING
|
||||||
* easily.
|
* easily.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_add_ping(spdylay_session *session, uint32_t unique_id);
|
int nghttp2_session_add_ping(nghttp2_session *session, uint32_t unique_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds GOAWAY frame with last-good-stream-ID |last_good_stream_id|
|
* Adds GOAWAY frame with last-good-stream-ID |last_good_stream_id|
|
||||||
* and the status code |status_code|. The |status_code| is ignored if
|
* and the status code |status_code|. The |status_code| is ignored if
|
||||||
* the protocol version is SPDYLAY_PROTO_SPDY2. This is a convenient
|
* the protocol version is NGHTTP2_PROTO_SPDY2. This is a convenient
|
||||||
* function built on top of spdylay_session_add_frame() to add GOAWAY
|
* function built on top of nghttp2_session_add_frame() to add GOAWAY
|
||||||
* easily.
|
* easily.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_add_goaway(spdylay_session *session,
|
int nghttp2_session_add_goaway(nghttp2_session *session,
|
||||||
int32_t last_good_stream_id,
|
int32_t last_good_stream_id,
|
||||||
uint32_t status_code);
|
uint32_t status_code);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds WINDOW_UPDATE frame with stream ID |stream_id| and
|
* Adds WINDOW_UPDATE frame with stream ID |stream_id| and
|
||||||
* delta-window-size |delta_window_size|. This is a convenient
|
* delta-window-size |delta_window_size|. This is a convenient
|
||||||
* function built on top of spdylay_session_add_frame() to add
|
* function built on top of nghttp2_session_add_frame() to add
|
||||||
* WINDOW_UPDATE easily.
|
* WINDOW_UPDATE easily.
|
||||||
*
|
*
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_add_window_update(spdylay_session *session,
|
int nghttp2_session_add_window_update(nghttp2_session *session,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
int32_t delta_window_size);
|
int32_t delta_window_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates new stream in |session| with stream ID |stream_id|,
|
* Creates new stream in |session| with stream ID |stream_id|,
|
||||||
* priority |pri| and flags |flags|. SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL
|
* priority |pri| and flags |flags|. NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL
|
||||||
* flag is set in |flags|, this stream is
|
* flag is set in |flags|, this stream is
|
||||||
* unidirectional. SPDYLAY_CTRL_FLAG_FIN flag is set in |flags|, the
|
* unidirectional. NGHTTP2_CTRL_FLAG_FIN flag is set in |flags|, the
|
||||||
* sender of SYN_STREAM will not send any further data in this
|
* sender of SYN_STREAM will not send any further data in this
|
||||||
* stream. Since this function is called when SYN_STREAM is sent or
|
* stream. Since this function is called when SYN_STREAM is sent or
|
||||||
* received, these flags are taken from SYN_STREAM. The state of
|
* received, these flags are taken from SYN_STREAM. The state of
|
||||||
|
@ -330,10 +330,10 @@ int spdylay_session_add_window_update(spdylay_session *session,
|
||||||
* This function returns a pointer to created new stream object, or
|
* This function returns a pointer to created new stream object, or
|
||||||
* NULL.
|
* NULL.
|
||||||
*/
|
*/
|
||||||
spdylay_stream* spdylay_session_open_stream(spdylay_session *session,
|
nghttp2_stream* nghttp2_session_open_stream(nghttp2_session *session,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
uint8_t flags, uint8_t pri,
|
uint8_t flags, uint8_t pri,
|
||||||
spdylay_stream_state initial_state,
|
nghttp2_stream_state initial_state,
|
||||||
void *stream_user_data);
|
void *stream_user_data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -344,19 +344,19 @@ spdylay_stream* spdylay_session_open_stream(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one the following
|
* This function returns 0 if it succeeds, or one the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_ARGUMENT
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||||
* The specified stream does not exist.
|
* The specified stream does not exist.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id,
|
int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id,
|
||||||
spdylay_status_code status_code);
|
nghttp2_status_code status_code);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Closes all pushed streams which associate them to stream
|
* Closes all pushed streams which associate them to stream
|
||||||
* |stream_id| with the status code |status_code|.
|
* |stream_id| with the status code |status_code|.
|
||||||
*/
|
*/
|
||||||
void spdylay_session_close_pushed_streams(spdylay_session *session,
|
void nghttp2_session_close_pushed_streams(nghttp2_session *session,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
spdylay_status_code status_code);
|
nghttp2_status_code status_code);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If further receptions and transmissions over the stream |stream_id|
|
* If further receptions and transmissions over the stream |stream_id|
|
||||||
|
@ -365,11 +365,11 @@ void spdylay_session_close_pushed_streams(spdylay_session *session,
|
||||||
* This function returns 0 if it
|
* This function returns 0 if it
|
||||||
* succeeds, or one of the following negative error codes:
|
* succeeds, or one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_INVALID_ARGUMENT
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
||||||
* The specified stream does not exist.
|
* The specified stream does not exist.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_close_stream_if_shut_rdwr(spdylay_session *session,
|
int nghttp2_session_close_stream_if_shut_rdwr(nghttp2_session *session,
|
||||||
spdylay_stream *stream);
|
nghttp2_stream *stream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when SYN_STREAM is received, assuming |frame.syn_stream| is
|
* Called when SYN_STREAM is received, assuming |frame.syn_stream| is
|
||||||
|
@ -380,11 +380,11 @@ int spdylay_session_close_stream_if_shut_rdwr(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_syn_stream_received(spdylay_session *session,
|
int nghttp2_session_on_syn_stream_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when SYN_REPLY is received, assuming |frame.syn_reply| is
|
* Called when SYN_REPLY is received, assuming |frame.syn_reply| is
|
||||||
|
@ -393,11 +393,11 @@ int spdylay_session_on_syn_stream_received(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_syn_reply_received(spdylay_session *session,
|
int nghttp2_session_on_syn_reply_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -406,8 +406,8 @@ int spdylay_session_on_syn_reply_received(spdylay_session *session,
|
||||||
*
|
*
|
||||||
* This function returns 0 and never fail.
|
* This function returns 0 and never fail.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_rst_stream_received(spdylay_session *session,
|
int nghttp2_session_on_rst_stream_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when SETTINGS is received, assuming |frame.settings| is
|
* Called when SETTINGS is received, assuming |frame.settings| is
|
||||||
|
@ -415,8 +415,8 @@ int spdylay_session_on_rst_stream_received(spdylay_session *session,
|
||||||
*
|
*
|
||||||
* This function returns 0 and never fail.
|
* This function returns 0 and never fail.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_settings_received(spdylay_session *session,
|
int nghttp2_session_on_settings_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when PING is received, assuming |frame.ping| is properly
|
* Called when PING is received, assuming |frame.ping| is properly
|
||||||
|
@ -425,11 +425,11 @@ int spdylay_session_on_settings_received(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_ping_received(spdylay_session *session,
|
int nghttp2_session_on_ping_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when GOAWAY is received, assuming |frame.goaway| is properly
|
* Called when GOAWAY is received, assuming |frame.goaway| is properly
|
||||||
|
@ -437,8 +437,8 @@ int spdylay_session_on_ping_received(spdylay_session *session,
|
||||||
*
|
*
|
||||||
* This function returns 0 and never fail.
|
* This function returns 0 and never fail.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_goaway_received(spdylay_session *session,
|
int nghttp2_session_on_goaway_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when HEADERS is recieved, assuming |frame.headers| is
|
* Called when HEADERS is recieved, assuming |frame.headers| is
|
||||||
|
@ -447,11 +447,11 @@ int spdylay_session_on_goaway_received(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_headers_received(spdylay_session *session,
|
int nghttp2_session_on_headers_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when WINDOW_UPDATE is recieved, assuming
|
* Called when WINDOW_UPDATE is recieved, assuming
|
||||||
|
@ -460,11 +460,11 @@ int spdylay_session_on_headers_received(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_window_update_received(spdylay_session *session,
|
int nghttp2_session_on_window_update_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when CREDENTIAL is received, assuming |frame.credential| is
|
* Called when CREDENTIAL is received, assuming |frame.credential| is
|
||||||
|
@ -472,8 +472,8 @@ int spdylay_session_on_window_update_received(spdylay_session *session,
|
||||||
*
|
*
|
||||||
* Currently, this function always succeeds and returns 0.
|
* Currently, this function always succeeds and returns 0.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_credential_received(spdylay_session *session,
|
int nghttp2_session_on_credential_received(nghttp2_session *session,
|
||||||
spdylay_frame *frame);
|
nghttp2_frame *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when DATA is received.
|
* Called when DATA is received.
|
||||||
|
@ -481,18 +481,18 @@ int spdylay_session_on_credential_received(spdylay_session *session,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_on_data_received(spdylay_session *session,
|
int nghttp2_session_on_data_received(nghttp2_session *session,
|
||||||
uint8_t flags, int32_t length,
|
uint8_t flags, int32_t length,
|
||||||
int32_t stream_id);
|
int32_t stream_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns spdylay_stream* object whose stream ID is |stream_id|. It
|
* Returns nghttp2_stream* object whose stream ID is |stream_id|. It
|
||||||
* could be NULL if such stream does not exist.
|
* could be NULL if such stream does not exist.
|
||||||
*/
|
*/
|
||||||
spdylay_stream* spdylay_session_get_stream(spdylay_session *session,
|
nghttp2_stream* nghttp2_session_get_stream(nghttp2_session *session,
|
||||||
int32_t stream_id);
|
int32_t stream_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -506,30 +506,30 @@ spdylay_stream* spdylay_session_get_stream(spdylay_session *session,
|
||||||
* This function returns the size of packed frame if it succeeds, or
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* one of the following negative error codes:
|
* one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_DEFERRED
|
* NGHTTP2_ERR_DEFERRED
|
||||||
* The DATA frame is postponed.
|
* The DATA frame is postponed.
|
||||||
* SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE
|
* NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
|
||||||
* The read_callback failed (stream error).
|
* The read_callback failed (stream error).
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
* SPDYLAY_ERR_CALLBACK_FAILURE
|
* NGHTTP2_ERR_CALLBACK_FAILURE
|
||||||
* The read_callback failed (session error).
|
* The read_callback failed (session error).
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
ssize_t nghttp2_session_pack_data(nghttp2_session *session,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
size_t datamax,
|
size_t datamax,
|
||||||
spdylay_data *frame);
|
nghttp2_data *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns next unique ID which can be used with PING.
|
* Returns next unique ID which can be used with PING.
|
||||||
*/
|
*/
|
||||||
uint32_t spdylay_session_get_next_unique_id(spdylay_session *session);
|
uint32_t nghttp2_session_get_next_unique_id(nghttp2_session *session);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns top of outbound frame queue. This function returns NULL if
|
* Returns top of outbound frame queue. This function returns NULL if
|
||||||
* queue is empty.
|
* queue is empty.
|
||||||
*/
|
*/
|
||||||
spdylay_outbound_item* spdylay_session_get_ob_pq_top(spdylay_session *session);
|
nghttp2_outbound_item* nghttp2_session_get_ob_pq_top(nghttp2_session *session);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pops and returns next item to send. If there is no such item,
|
* Pops and returns next item to send. If there is no such item,
|
||||||
|
@ -538,8 +538,8 @@ spdylay_outbound_item* spdylay_session_get_ob_pq_top(spdylay_session *session);
|
||||||
* session->ob_ss_pq has item and max concurrent streams is reached,
|
* session->ob_ss_pq has item and max concurrent streams is reached,
|
||||||
* then this function returns NULL.
|
* then this function returns NULL.
|
||||||
*/
|
*/
|
||||||
spdylay_outbound_item* spdylay_session_pop_next_ob_item
|
nghttp2_outbound_item* nghttp2_session_pop_next_ob_item
|
||||||
(spdylay_session *session);
|
(nghttp2_session *session);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns next item to send. If there is no such item, this function
|
* Returns next item to send. If there is no such item, this function
|
||||||
|
@ -548,17 +548,17 @@ spdylay_outbound_item* spdylay_session_pop_next_ob_item
|
||||||
* session->ob_ss_pq has item and max concurrent streams is reached,
|
* session->ob_ss_pq has item and max concurrent streams is reached,
|
||||||
* then this function returns NULL.
|
* then this function returns NULL.
|
||||||
*/
|
*/
|
||||||
spdylay_outbound_item* spdylay_session_get_next_ob_item
|
nghttp2_outbound_item* nghttp2_session_get_next_ob_item
|
||||||
(spdylay_session *session);
|
(nghttp2_session *session);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Updates local settings with the |iv|. The number of elements in the
|
* Updates local settings with the |iv|. The number of elements in the
|
||||||
* array pointed by the |iv| is given by the |niv|. This function
|
* array pointed by the |iv| is given by the |niv|. This function
|
||||||
* assumes that the all settings_id member in |iv| are in range 1 to
|
* assumes that the all settings_id member in |iv| are in range 1 to
|
||||||
* SPDYLAY_SETTINGS_MAX, inclusive.
|
* NGHTTP2_SETTINGS_MAX, inclusive.
|
||||||
*/
|
*/
|
||||||
void spdylay_session_update_local_settings(spdylay_session *session,
|
void nghttp2_session_update_local_settings(nghttp2_session *session,
|
||||||
spdylay_settings_entry *iv,
|
nghttp2_settings_entry *iv,
|
||||||
size_t niv);
|
size_t niv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -566,16 +566,16 @@ void spdylay_session_update_local_settings(spdylay_session *session,
|
||||||
* |syn_stream|. The origin is computed from |syn_stream->nv|. If no
|
* |syn_stream|. The origin is computed from |syn_stream->nv|. If no
|
||||||
* client certificate is required, return 0. If CREDENTIAL frame needs
|
* client certificate is required, return 0. If CREDENTIAL frame needs
|
||||||
* to be sent before the |syn_stream|, this function returns
|
* to be sent before the |syn_stream|, this function returns
|
||||||
* :macro:`SPDYLAY_ERR_CREDENTIAL_PENDING`. In this case, CREDENTIAL
|
* :macro:`NGHTTP2_ERR_CREDENTIAL_PENDING`. In this case, CREDENTIAL
|
||||||
* frame has been already queued. This function returns one of the
|
* frame has been already queued. This function returns one of the
|
||||||
* following negative error codes:
|
* following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
* SPDYLAY_ERR_CREDENTIAL_PENDING
|
* NGHTTP2_ERR_CREDENTIAL_PENDING
|
||||||
* The CREDENTIAL frame must be sent before the |syn_stream|.
|
* The CREDENTIAL frame must be sent before the |syn_stream|.
|
||||||
*/
|
*/
|
||||||
int spdylay_session_prep_credential(spdylay_session *session,
|
int nghttp2_session_prep_credential(nghttp2_session *session,
|
||||||
spdylay_syn_stream *syn_stream);
|
nghttp2_syn_stream *syn_stream);
|
||||||
|
|
||||||
#endif /* SPDYLAY_SESSION_H */
|
#endif /* NGHTTP2_SESSION_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,45 +22,45 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_stream.h"
|
#include "nghttp2_stream.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void spdylay_stream_init(spdylay_stream *stream, int32_t stream_id,
|
void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id,
|
||||||
uint8_t flags, uint8_t pri,
|
uint8_t flags, uint8_t pri,
|
||||||
spdylay_stream_state initial_state,
|
nghttp2_stream_state initial_state,
|
||||||
int32_t initial_window_size,
|
int32_t initial_window_size,
|
||||||
void *stream_user_data)
|
void *stream_user_data)
|
||||||
{
|
{
|
||||||
spdylay_map_entry_init(&stream->map_entry, stream_id);
|
nghttp2_map_entry_init(&stream->map_entry, stream_id);
|
||||||
stream->stream_id = stream_id;
|
stream->stream_id = stream_id;
|
||||||
stream->flags = flags;
|
stream->flags = flags;
|
||||||
stream->pri = pri;
|
stream->pri = pri;
|
||||||
stream->state = initial_state;
|
stream->state = initial_state;
|
||||||
stream->shut_flags = SPDYLAY_SHUT_NONE;
|
stream->shut_flags = NGHTTP2_SHUT_NONE;
|
||||||
stream->pushed_streams = NULL;
|
stream->pushed_streams = NULL;
|
||||||
stream->pushed_streams_length = 0;
|
stream->pushed_streams_length = 0;
|
||||||
stream->pushed_streams_capacity = 0;
|
stream->pushed_streams_capacity = 0;
|
||||||
stream->stream_user_data = stream_user_data;
|
stream->stream_user_data = stream_user_data;
|
||||||
stream->deferred_data = NULL;
|
stream->deferred_data = NULL;
|
||||||
stream->deferred_flags = SPDYLAY_DEFERRED_NONE;
|
stream->deferred_flags = NGHTTP2_DEFERRED_NONE;
|
||||||
stream->window_size = initial_window_size;
|
stream->window_size = initial_window_size;
|
||||||
stream->recv_window_size = 0;
|
stream->recv_window_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_stream_free(spdylay_stream *stream)
|
void nghttp2_stream_free(nghttp2_stream *stream)
|
||||||
{
|
{
|
||||||
free(stream->pushed_streams);
|
free(stream->pushed_streams);
|
||||||
spdylay_outbound_item_free(stream->deferred_data);
|
nghttp2_outbound_item_free(stream->deferred_data);
|
||||||
free(stream->deferred_data);
|
free(stream->deferred_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_stream_shutdown(spdylay_stream *stream, spdylay_shut_flag flag)
|
void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag)
|
||||||
{
|
{
|
||||||
stream->shut_flags |= flag;
|
stream->shut_flags |= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_stream_add_pushed_stream(spdylay_stream *stream, int32_t stream_id)
|
int nghttp2_stream_add_pushed_stream(nghttp2_stream *stream, int32_t stream_id)
|
||||||
{
|
{
|
||||||
if(stream->pushed_streams_capacity == stream->pushed_streams_length) {
|
if(stream->pushed_streams_capacity == stream->pushed_streams_length) {
|
||||||
int32_t *streams;
|
int32_t *streams;
|
||||||
|
@ -68,7 +68,7 @@ int spdylay_stream_add_pushed_stream(spdylay_stream *stream, int32_t stream_id)
|
||||||
5 : stream->pushed_streams_capacity*2;
|
5 : stream->pushed_streams_capacity*2;
|
||||||
streams = realloc(stream->pushed_streams, capacity*sizeof(uint32_t));
|
streams = realloc(stream->pushed_streams, capacity*sizeof(uint32_t));
|
||||||
if(streams == NULL) {
|
if(streams == NULL) {
|
||||||
return SPDYLAY_ERR_NOMEM;
|
return NGHTTP2_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
stream->pushed_streams = streams;
|
stream->pushed_streams = streams;
|
||||||
stream->pushed_streams_capacity = capacity;
|
stream->pushed_streams_capacity = capacity;
|
||||||
|
@ -77,8 +77,8 @@ int spdylay_stream_add_pushed_stream(spdylay_stream *stream, int32_t stream_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_stream_defer_data(spdylay_stream *stream,
|
void nghttp2_stream_defer_data(nghttp2_stream *stream,
|
||||||
spdylay_outbound_item *data,
|
nghttp2_outbound_item *data,
|
||||||
uint8_t flags)
|
uint8_t flags)
|
||||||
{
|
{
|
||||||
assert(stream->deferred_data == NULL);
|
assert(stream->deferred_data == NULL);
|
||||||
|
@ -86,13 +86,13 @@ void spdylay_stream_defer_data(spdylay_stream *stream,
|
||||||
stream->deferred_flags = flags;
|
stream->deferred_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_stream_detach_deferred_data(spdylay_stream *stream)
|
void nghttp2_stream_detach_deferred_data(nghttp2_stream *stream)
|
||||||
{
|
{
|
||||||
stream->deferred_data = NULL;
|
stream->deferred_data = NULL;
|
||||||
stream->deferred_flags = SPDYLAY_DEFERRED_NONE;
|
stream->deferred_flags = NGHTTP2_DEFERRED_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_stream_update_initial_window_size(spdylay_stream *stream,
|
void nghttp2_stream_update_initial_window_size(nghttp2_stream *stream,
|
||||||
int32_t new_initial_window_size,
|
int32_t new_initial_window_size,
|
||||||
int32_t old_initial_window_size)
|
int32_t old_initial_window_size)
|
||||||
{
|
{
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,71 +22,71 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_STREAM_H
|
#ifndef NGHTTP2_STREAM_H
|
||||||
#define SPDYLAY_STREAM_H
|
#define NGHTTP2_STREAM_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
#include "spdylay_outbound_item.h"
|
#include "nghttp2_outbound_item.h"
|
||||||
#include "spdylay_map.h"
|
#include "nghttp2_map.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If local peer is stream initiator:
|
* If local peer is stream initiator:
|
||||||
* SPDYLAY_STREAM_OPENING : upon sending SYN_STREAM
|
* NGHTTP2_STREAM_OPENING : upon sending SYN_STREAM
|
||||||
* SPDYLAY_STREAM_OPENED : upon receiving SYN_REPLY
|
* NGHTTP2_STREAM_OPENED : upon receiving SYN_REPLY
|
||||||
* SPDYLAY_STREAM_CLOSING : upon queuing RST_STREAM
|
* NGHTTP2_STREAM_CLOSING : upon queuing RST_STREAM
|
||||||
*
|
*
|
||||||
* If remote peer is stream initiator:
|
* If remote peer is stream initiator:
|
||||||
* SPDYLAY_STREAM_OPENING : upon receiving SYN_STREAM
|
* NGHTTP2_STREAM_OPENING : upon receiving SYN_STREAM
|
||||||
* SPDYLAY_STREAM_OPENED : upon sending SYN_REPLY
|
* NGHTTP2_STREAM_OPENED : upon sending SYN_REPLY
|
||||||
* SPDYLAY_STREAM_CLOSING : upon queuing RST_STREAM
|
* NGHTTP2_STREAM_CLOSING : upon queuing RST_STREAM
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* Initial state */
|
/* Initial state */
|
||||||
SPDYLAY_STREAM_INITIAL,
|
NGHTTP2_STREAM_INITIAL,
|
||||||
/* For stream initiator: SYN_STREAM has been sent, but SYN_REPLY is
|
/* For stream initiator: SYN_STREAM has been sent, but SYN_REPLY is
|
||||||
not received yet. For receiver: SYN_STREAM has been received,
|
not received yet. For receiver: SYN_STREAM has been received,
|
||||||
but it does not send SYN_REPLY yet. */
|
but it does not send SYN_REPLY yet. */
|
||||||
SPDYLAY_STREAM_OPENING,
|
NGHTTP2_STREAM_OPENING,
|
||||||
/* For stream initiator: SYN_REPLY is received. For receiver:
|
/* For stream initiator: SYN_REPLY is received. For receiver:
|
||||||
SYN_REPLY is sent. */
|
SYN_REPLY is sent. */
|
||||||
SPDYLAY_STREAM_OPENED,
|
NGHTTP2_STREAM_OPENED,
|
||||||
/* RST_STREAM is received, but somehow we need to keep stream in
|
/* RST_STREAM is received, but somehow we need to keep stream in
|
||||||
memory. */
|
memory. */
|
||||||
SPDYLAY_STREAM_CLOSING
|
NGHTTP2_STREAM_CLOSING
|
||||||
} spdylay_stream_state;
|
} nghttp2_stream_state;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPDYLAY_SHUT_NONE = 0,
|
NGHTTP2_SHUT_NONE = 0,
|
||||||
/* Indicates further receptions will be disallowed. */
|
/* Indicates further receptions will be disallowed. */
|
||||||
SPDYLAY_SHUT_RD = 0x01,
|
NGHTTP2_SHUT_RD = 0x01,
|
||||||
/* Indicates further transmissions will be disallowed. */
|
/* Indicates further transmissions will be disallowed. */
|
||||||
SPDYLAY_SHUT_WR = 0x02,
|
NGHTTP2_SHUT_WR = 0x02,
|
||||||
/* Indicates both further receptions and transmissions will be
|
/* Indicates both further receptions and transmissions will be
|
||||||
disallowed. */
|
disallowed. */
|
||||||
SPDYLAY_SHUT_RDWR = SPDYLAY_SHUT_RD | SPDYLAY_SHUT_WR
|
NGHTTP2_SHUT_RDWR = NGHTTP2_SHUT_RD | NGHTTP2_SHUT_WR
|
||||||
} spdylay_shut_flag;
|
} nghttp2_shut_flag;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPDYLAY_DEFERRED_NONE = 0,
|
NGHTTP2_DEFERRED_NONE = 0,
|
||||||
/* Indicates the DATA is deferred due to flow control. */
|
/* Indicates the DATA is deferred due to flow control. */
|
||||||
SPDYLAY_DEFERRED_FLOW_CONTROL = 0x01
|
NGHTTP2_DEFERRED_FLOW_CONTROL = 0x01
|
||||||
} spdylay_deferred_flag;
|
} nghttp2_deferred_flag;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Intrusive Map */
|
/* Intrusive Map */
|
||||||
spdylay_map_entry map_entry;
|
nghttp2_map_entry map_entry;
|
||||||
/* stream ID */
|
/* stream ID */
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
spdylay_stream_state state;
|
nghttp2_stream_state state;
|
||||||
/* Use same value in SYN_STREAM frame */
|
/* Use same value in SYN_STREAM frame */
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
/* Use same scheme in SYN_STREAM frame */
|
/* Use same scheme in SYN_STREAM frame */
|
||||||
uint8_t pri;
|
uint8_t pri;
|
||||||
/* Bitwise OR of zero or more spdylay_shut_flag values */
|
/* Bitwise OR of zero or more nghttp2_shut_flag values */
|
||||||
uint8_t shut_flags;
|
uint8_t shut_flags;
|
||||||
/* The array of server-pushed stream IDs which associate them to
|
/* The array of server-pushed stream IDs which associate them to
|
||||||
this stream. */
|
this stream. */
|
||||||
|
@ -99,9 +99,9 @@ typedef struct {
|
||||||
/* The arbitrary data provided by user for this stream. */
|
/* The arbitrary data provided by user for this stream. */
|
||||||
void *stream_user_data;
|
void *stream_user_data;
|
||||||
/* Deferred DATA frame */
|
/* Deferred DATA frame */
|
||||||
spdylay_outbound_item *deferred_data;
|
nghttp2_outbound_item *deferred_data;
|
||||||
/* The flags for defered DATA. Bitwise OR of zero or more
|
/* The flags for defered DATA. Bitwise OR of zero or more
|
||||||
spdylay_deferred_flag values */
|
nghttp2_deferred_flag values */
|
||||||
uint8_t deferred_flags;
|
uint8_t deferred_flags;
|
||||||
/* Current sender window size. This value is computed against the
|
/* Current sender window size. This value is computed against the
|
||||||
current initial window size of remote endpoint. */
|
current initial window size of remote endpoint. */
|
||||||
|
@ -109,21 +109,21 @@ typedef struct {
|
||||||
/* Keep track of the number of bytes received without
|
/* Keep track of the number of bytes received without
|
||||||
WINDOW_UPDATE. */
|
WINDOW_UPDATE. */
|
||||||
int32_t recv_window_size;
|
int32_t recv_window_size;
|
||||||
} spdylay_stream;
|
} nghttp2_stream;
|
||||||
|
|
||||||
void spdylay_stream_init(spdylay_stream *stream, int32_t stream_id,
|
void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id,
|
||||||
uint8_t flags, uint8_t pri,
|
uint8_t flags, uint8_t pri,
|
||||||
spdylay_stream_state initial_state,
|
nghttp2_stream_state initial_state,
|
||||||
int32_t initial_window_size,
|
int32_t initial_window_size,
|
||||||
void *stream_user_data);
|
void *stream_user_data);
|
||||||
|
|
||||||
void spdylay_stream_free(spdylay_stream *stream);
|
void nghttp2_stream_free(nghttp2_stream *stream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disallow either further receptions or transmissions, or both.
|
* Disallow either further receptions or transmissions, or both.
|
||||||
* |flag| is bitwise OR of one or more of spdylay_shut_flag.
|
* |flag| is bitwise OR of one or more of nghttp2_shut_flag.
|
||||||
*/
|
*/
|
||||||
void spdylay_stream_shutdown(spdylay_stream *stream, spdylay_shut_flag flag);
|
void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add server-pushed |stream_id| to this stream. This happens when
|
* Add server-pushed |stream_id| to this stream. This happens when
|
||||||
|
@ -133,33 +133,33 @@ void spdylay_stream_shutdown(spdylay_stream *stream, spdylay_shut_flag flag);
|
||||||
* RETURN VALUE
|
* RETURN VALUE
|
||||||
* ------------
|
* ------------
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
int spdylay_stream_add_pushed_stream(spdylay_stream *stream, int32_t stream_id);
|
int nghttp2_stream_add_pushed_stream(nghttp2_stream *stream, int32_t stream_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Defer DATA frame |data|. We won't call this function in the
|
* Defer DATA frame |data|. We won't call this function in the
|
||||||
* situation where stream->deferred_data != NULL. If |flags| is
|
* situation where stream->deferred_data != NULL. If |flags| is
|
||||||
* bitwise OR of zero or more spdylay_deferred_flag values.
|
* bitwise OR of zero or more nghttp2_deferred_flag values.
|
||||||
*/
|
*/
|
||||||
void spdylay_stream_defer_data(spdylay_stream *stream,
|
void nghttp2_stream_defer_data(nghttp2_stream *stream,
|
||||||
spdylay_outbound_item *data,
|
nghttp2_outbound_item *data,
|
||||||
uint8_t flags);
|
uint8_t flags);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detaches deferred data from this stream. This function does not
|
* Detaches deferred data from this stream. This function does not
|
||||||
* free deferred data.
|
* free deferred data.
|
||||||
*/
|
*/
|
||||||
void spdylay_stream_detach_deferred_data(spdylay_stream *stream);
|
void nghttp2_stream_detach_deferred_data(nghttp2_stream *stream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Updates the initial window size with the new value
|
* Updates the initial window size with the new value
|
||||||
* |new_initial_window_size|. The |old_initial_window_size| is used to
|
* |new_initial_window_size|. The |old_initial_window_size| is used to
|
||||||
* calculate the current window size.
|
* calculate the current window size.
|
||||||
*/
|
*/
|
||||||
void spdylay_stream_update_initial_window_size(spdylay_stream *stream,
|
void nghttp2_stream_update_initial_window_size(nghttp2_stream *stream,
|
||||||
int32_t new_initial_window_size,
|
int32_t new_initial_window_size,
|
||||||
int32_t old_initial_window_size);
|
int32_t old_initial_window_size);
|
||||||
|
|
||||||
#endif /* SPDYLAY_STREAM */
|
#endif /* NGHTTP2_STREAM */
|
|
@ -0,0 +1,335 @@
|
||||||
|
/*
|
||||||
|
* nghttp2 - HTTP/2.0 C 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 "nghttp2_submit.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "nghttp2_session.h"
|
||||||
|
#include "nghttp2_frame.h"
|
||||||
|
#include "nghttp2_helper.h"
|
||||||
|
|
||||||
|
static int nghttp2_submit_syn_stream_shared
|
||||||
|
(nghttp2_session *session,
|
||||||
|
uint8_t flags,
|
||||||
|
int32_t assoc_stream_id,
|
||||||
|
uint8_t pri,
|
||||||
|
const char **nv,
|
||||||
|
const nghttp2_data_provider *data_prd,
|
||||||
|
void *stream_user_data)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
nghttp2_frame *frame;
|
||||||
|
char **nv_copy;
|
||||||
|
uint8_t flags_copy;
|
||||||
|
nghttp2_data_provider *data_prd_copy = NULL;
|
||||||
|
nghttp2_syn_stream_aux_data *aux_data;
|
||||||
|
if(pri > nghttp2_session_get_pri_lowest(session)) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
if(assoc_stream_id != 0 && session->server == 0) {
|
||||||
|
assoc_stream_id = 0;
|
||||||
|
}
|
||||||
|
if(!nghttp2_frame_nv_check_null(nv)) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
if(data_prd != NULL && data_prd->read_callback != NULL) {
|
||||||
|
data_prd_copy = malloc(sizeof(nghttp2_data_provider));
|
||||||
|
if(data_prd_copy == NULL) {
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
*data_prd_copy = *data_prd;
|
||||||
|
}
|
||||||
|
aux_data = malloc(sizeof(nghttp2_syn_stream_aux_data));
|
||||||
|
if(aux_data == NULL) {
|
||||||
|
free(data_prd_copy);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
aux_data->data_prd = data_prd_copy;
|
||||||
|
aux_data->stream_user_data = stream_user_data;
|
||||||
|
|
||||||
|
frame = malloc(sizeof(nghttp2_frame));
|
||||||
|
if(frame == NULL) {
|
||||||
|
free(aux_data);
|
||||||
|
free(data_prd_copy);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
nv_copy = nghttp2_frame_nv_norm_copy(nv);
|
||||||
|
if(nv_copy == NULL) {
|
||||||
|
free(frame);
|
||||||
|
free(aux_data);
|
||||||
|
free(data_prd_copy);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
flags_copy = 0;
|
||||||
|
if(flags & NGHTTP2_CTRL_FLAG_FIN) {
|
||||||
|
flags_copy |= NGHTTP2_CTRL_FLAG_FIN;
|
||||||
|
}
|
||||||
|
if(flags & NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL) {
|
||||||
|
flags_copy |= NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL;
|
||||||
|
}
|
||||||
|
nghttp2_frame_syn_stream_init(&frame->syn_stream,
|
||||||
|
session->version, flags_copy,
|
||||||
|
0, assoc_stream_id, pri, nv_copy);
|
||||||
|
r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame,
|
||||||
|
aux_data);
|
||||||
|
if(r != 0) {
|
||||||
|
nghttp2_frame_syn_stream_free(&frame->syn_stream);
|
||||||
|
free(frame);
|
||||||
|
free(aux_data);
|
||||||
|
free(data_prd_copy);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_syn_stream(nghttp2_session *session, uint8_t flags,
|
||||||
|
int32_t assoc_stream_id, uint8_t pri,
|
||||||
|
const char **nv, void *stream_user_data)
|
||||||
|
{
|
||||||
|
return nghttp2_submit_syn_stream_shared(session, flags, assoc_stream_id,
|
||||||
|
pri, nv, NULL, stream_user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_syn_reply(nghttp2_session *session, uint8_t flags,
|
||||||
|
int32_t stream_id, const char **nv)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
nghttp2_frame *frame;
|
||||||
|
char **nv_copy;
|
||||||
|
uint8_t flags_copy;
|
||||||
|
if(!nghttp2_frame_nv_check_null(nv)) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
frame = malloc(sizeof(nghttp2_frame));
|
||||||
|
if(frame == NULL) {
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
nv_copy = nghttp2_frame_nv_norm_copy(nv);
|
||||||
|
if(nv_copy == NULL) {
|
||||||
|
free(frame);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
flags_copy = 0;
|
||||||
|
if(flags & NGHTTP2_CTRL_FLAG_FIN) {
|
||||||
|
flags_copy |= NGHTTP2_CTRL_FLAG_FIN;
|
||||||
|
}
|
||||||
|
nghttp2_frame_syn_reply_init(&frame->syn_reply, session->version, flags_copy,
|
||||||
|
stream_id, nv_copy);
|
||||||
|
r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL);
|
||||||
|
if(r != 0) {
|
||||||
|
nghttp2_frame_syn_reply_free(&frame->syn_reply);
|
||||||
|
free(frame);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
|
||||||
|
int32_t stream_id, const char **nv)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
nghttp2_frame *frame;
|
||||||
|
char **nv_copy;
|
||||||
|
uint8_t flags_copy;
|
||||||
|
if(!nghttp2_frame_nv_check_null(nv)) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
frame = malloc(sizeof(nghttp2_frame));
|
||||||
|
if(frame == NULL) {
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
nv_copy = nghttp2_frame_nv_norm_copy(nv);
|
||||||
|
if(nv_copy == NULL) {
|
||||||
|
free(frame);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
flags_copy = 0;
|
||||||
|
if(flags & NGHTTP2_CTRL_FLAG_FIN) {
|
||||||
|
flags_copy |= NGHTTP2_CTRL_FLAG_FIN;
|
||||||
|
}
|
||||||
|
nghttp2_frame_headers_init(&frame->headers, session->version, flags_copy,
|
||||||
|
stream_id, nv_copy);
|
||||||
|
r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL);
|
||||||
|
if(r != 0) {
|
||||||
|
nghttp2_frame_headers_free(&frame->headers);
|
||||||
|
free(frame);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_ping(nghttp2_session *session)
|
||||||
|
{
|
||||||
|
return nghttp2_session_add_ping(session,
|
||||||
|
nghttp2_session_get_next_unique_id(session));
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_rst_stream(nghttp2_session *session, int32_t stream_id,
|
||||||
|
uint32_t status_code)
|
||||||
|
{
|
||||||
|
return nghttp2_session_add_rst_stream(session, stream_id, status_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_goaway(nghttp2_session *session, uint32_t status_code)
|
||||||
|
{
|
||||||
|
return nghttp2_session_add_goaway(session, session->last_recv_stream_id,
|
||||||
|
status_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags,
|
||||||
|
const nghttp2_settings_entry *iv, size_t niv)
|
||||||
|
{
|
||||||
|
nghttp2_frame *frame;
|
||||||
|
nghttp2_settings_entry *iv_copy;
|
||||||
|
int check[NGHTTP2_SETTINGS_MAX+1];
|
||||||
|
size_t i;
|
||||||
|
int r;
|
||||||
|
memset(check, 0, sizeof(check));
|
||||||
|
for(i = 0; i < niv; ++i) {
|
||||||
|
if(iv[i].settings_id > NGHTTP2_SETTINGS_MAX || iv[i].settings_id == 0 ||
|
||||||
|
check[iv[i].settings_id] == 1) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
} else {
|
||||||
|
check[iv[i].settings_id] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
frame = malloc(sizeof(nghttp2_frame));
|
||||||
|
if(frame == NULL) {
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
iv_copy = nghttp2_frame_iv_copy(iv, niv);
|
||||||
|
if(iv_copy == NULL) {
|
||||||
|
free(frame);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
nghttp2_frame_iv_sort(iv_copy, niv);
|
||||||
|
nghttp2_frame_settings_init(&frame->settings, session->version,
|
||||||
|
flags, iv_copy, niv);
|
||||||
|
r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL);
|
||||||
|
if(r == 0) {
|
||||||
|
nghttp2_session_update_local_settings(session, iv_copy, niv);
|
||||||
|
} else {
|
||||||
|
nghttp2_frame_settings_free(&frame->settings);
|
||||||
|
free(frame);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_window_update(nghttp2_session *session, int32_t stream_id,
|
||||||
|
int32_t delta_window_size)
|
||||||
|
{
|
||||||
|
nghttp2_stream *stream;
|
||||||
|
if(delta_window_size <= 0) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
stream = nghttp2_session_get_stream(session, stream_id);
|
||||||
|
if(stream) {
|
||||||
|
stream->recv_window_size -= nghttp2_min(delta_window_size,
|
||||||
|
stream->recv_window_size);
|
||||||
|
return nghttp2_session_add_window_update(session, stream_id,
|
||||||
|
delta_window_size);
|
||||||
|
} else {
|
||||||
|
return NGHTTP2_ERR_STREAM_CLOSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_request(nghttp2_session *session, uint8_t pri,
|
||||||
|
const char **nv,
|
||||||
|
const nghttp2_data_provider *data_prd,
|
||||||
|
void *stream_user_data)
|
||||||
|
{
|
||||||
|
int flags;
|
||||||
|
flags = 0;
|
||||||
|
if(data_prd == NULL || data_prd->read_callback == NULL) {
|
||||||
|
flags |= NGHTTP2_CTRL_FLAG_FIN;
|
||||||
|
}
|
||||||
|
return nghttp2_submit_syn_stream_shared(session, flags, 0, pri, nv, data_prd,
|
||||||
|
stream_user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_response(nghttp2_session *session,
|
||||||
|
int32_t stream_id, const char **nv,
|
||||||
|
const nghttp2_data_provider *data_prd)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
nghttp2_frame *frame;
|
||||||
|
char **nv_copy;
|
||||||
|
uint8_t flags = 0;
|
||||||
|
nghttp2_data_provider *data_prd_copy = NULL;
|
||||||
|
if(!nghttp2_frame_nv_check_null(nv)) {
|
||||||
|
return NGHTTP2_ERR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
if(data_prd != NULL && data_prd->read_callback != NULL) {
|
||||||
|
data_prd_copy = malloc(sizeof(nghttp2_data_provider));
|
||||||
|
if(data_prd_copy == NULL) {
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
*data_prd_copy = *data_prd;
|
||||||
|
}
|
||||||
|
frame = malloc(sizeof(nghttp2_frame));
|
||||||
|
if(frame == NULL) {
|
||||||
|
free(data_prd_copy);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
nv_copy = nghttp2_frame_nv_norm_copy(nv);
|
||||||
|
if(nv_copy == NULL) {
|
||||||
|
free(frame);
|
||||||
|
free(data_prd_copy);
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
if(data_prd_copy == NULL) {
|
||||||
|
flags |= NGHTTP2_CTRL_FLAG_FIN;
|
||||||
|
}
|
||||||
|
nghttp2_frame_syn_reply_init(&frame->syn_reply, session->version, flags,
|
||||||
|
stream_id, nv_copy);
|
||||||
|
r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame,
|
||||||
|
data_prd_copy);
|
||||||
|
if(r != 0) {
|
||||||
|
nghttp2_frame_syn_reply_free(&frame->syn_reply);
|
||||||
|
free(frame);
|
||||||
|
free(data_prd_copy);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nghttp2_submit_data(nghttp2_session *session, int32_t stream_id,
|
||||||
|
uint8_t flags,
|
||||||
|
const nghttp2_data_provider *data_prd)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
nghttp2_data *data_frame;
|
||||||
|
uint8_t nflags = 0;
|
||||||
|
data_frame = malloc(sizeof(nghttp2_frame));
|
||||||
|
if(data_frame == NULL) {
|
||||||
|
return NGHTTP2_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
if(flags & NGHTTP2_DATA_FLAG_FIN) {
|
||||||
|
nflags |= NGHTTP2_DATA_FLAG_FIN;
|
||||||
|
}
|
||||||
|
nghttp2_frame_data_init(data_frame, stream_id, nflags, data_prd);
|
||||||
|
r = nghttp2_session_add_frame(session, NGHTTP2_DATA, data_frame, NULL);
|
||||||
|
if(r != 0) {
|
||||||
|
nghttp2_frame_data_free(data_frame);
|
||||||
|
free(data_frame);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,13 +22,13 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_SUBMIT_H
|
#ifndef NGHTTP2_SUBMIT_H
|
||||||
#define SPDYLAY_SUBMIT_H
|
#define NGHTTP2_SUBMIT_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
#endif /* SPDYLAY_SUBMIT_H */
|
#endif /* NGHTTP2_SUBMIT_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "spdylay_zlib.h"
|
#include "nghttp2_zlib.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
@ -226,21 +226,21 @@ static const uint8_t spdy3_hd_dict[] = {
|
||||||
0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e /* - e n q - 0 - */
|
0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e /* - e n q - 0 - */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t* spdylay_select_hd_dict(size_t *len_ptr, uint16_t version)
|
static const uint8_t* nghttp2_select_hd_dict(size_t *len_ptr, uint16_t version)
|
||||||
{
|
{
|
||||||
const uint8_t *hd_dict;
|
const uint8_t *hd_dict;
|
||||||
hd_dict = NULL;
|
hd_dict = NULL;
|
||||||
if(version == SPDYLAY_PROTO_SPDY2) {
|
if(version == NGHTTP2_PROTO_SPDY2) {
|
||||||
hd_dict = (const uint8_t*)spdy2_hd_dict;
|
hd_dict = (const uint8_t*)spdy2_hd_dict;
|
||||||
*len_ptr = sizeof(spdy2_hd_dict);
|
*len_ptr = sizeof(spdy2_hd_dict);
|
||||||
} else if(version == SPDYLAY_PROTO_SPDY3) {
|
} else if(version == NGHTTP2_PROTO_SPDY3) {
|
||||||
hd_dict = spdy3_hd_dict;
|
hd_dict = spdy3_hd_dict;
|
||||||
*len_ptr = sizeof(spdy3_hd_dict);
|
*len_ptr = sizeof(spdy3_hd_dict);
|
||||||
}
|
}
|
||||||
return hd_dict;
|
return hd_dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_zlib_deflate_hd_init(spdylay_zlib *deflater, int comp,
|
int nghttp2_zlib_deflate_hd_init(nghttp2_zlib *deflater, int comp,
|
||||||
uint16_t version)
|
uint16_t version)
|
||||||
{
|
{
|
||||||
const unsigned char *hd_dict;
|
const unsigned char *hd_dict;
|
||||||
|
@ -250,25 +250,25 @@ int spdylay_zlib_deflate_hd_init(spdylay_zlib *deflater, int comp,
|
||||||
deflater->zst.zfree = Z_NULL;
|
deflater->zst.zfree = Z_NULL;
|
||||||
deflater->zst.opaque = Z_NULL;
|
deflater->zst.opaque = Z_NULL;
|
||||||
deflater->version = version;
|
deflater->version = version;
|
||||||
hd_dict = spdylay_select_hd_dict(&hd_dict_length, version);
|
hd_dict = nghttp2_select_hd_dict(&hd_dict_length, version);
|
||||||
if(hd_dict == NULL) {
|
if(hd_dict == NULL) {
|
||||||
return SPDYLAY_ERR_UNSUPPORTED_VERSION;
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
||||||
}
|
}
|
||||||
if(Z_OK != deflateInit2(&deflater->zst,
|
if(Z_OK != deflateInit2(&deflater->zst,
|
||||||
comp ? COMPRESSION_LEVEL : Z_NO_COMPRESSION,
|
comp ? COMPRESSION_LEVEL : Z_NO_COMPRESSION,
|
||||||
Z_DEFLATED, WINDOW_BITS, MEM_LEVEL,
|
Z_DEFLATED, WINDOW_BITS, MEM_LEVEL,
|
||||||
Z_DEFAULT_STRATEGY)) {
|
Z_DEFAULT_STRATEGY)) {
|
||||||
return SPDYLAY_ERR_ZLIB;
|
return NGHTTP2_ERR_ZLIB;
|
||||||
}
|
}
|
||||||
if(Z_OK != deflateSetDictionary(&deflater->zst, (uint8_t*)hd_dict,
|
if(Z_OK != deflateSetDictionary(&deflater->zst, (uint8_t*)hd_dict,
|
||||||
hd_dict_length)) {
|
hd_dict_length)) {
|
||||||
spdylay_zlib_deflate_free(deflater);
|
nghttp2_zlib_deflate_free(deflater);
|
||||||
return SPDYLAY_ERR_ZLIB;
|
return NGHTTP2_ERR_ZLIB;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spdylay_zlib_inflate_hd_init(spdylay_zlib *inflater, uint16_t version)
|
int nghttp2_zlib_inflate_hd_init(nghttp2_zlib *inflater, uint16_t version)
|
||||||
{
|
{
|
||||||
const unsigned char *hd_dict;
|
const unsigned char *hd_dict;
|
||||||
size_t hd_dict_length;
|
size_t hd_dict_length;
|
||||||
|
@ -278,27 +278,27 @@ int spdylay_zlib_inflate_hd_init(spdylay_zlib *inflater, uint16_t version)
|
||||||
inflater->zst.zfree = Z_NULL;
|
inflater->zst.zfree = Z_NULL;
|
||||||
inflater->zst.opaque = Z_NULL;
|
inflater->zst.opaque = Z_NULL;
|
||||||
inflater->version = version;
|
inflater->version = version;
|
||||||
hd_dict = spdylay_select_hd_dict(&hd_dict_length, version);
|
hd_dict = nghttp2_select_hd_dict(&hd_dict_length, version);
|
||||||
if(hd_dict == NULL) {
|
if(hd_dict == NULL) {
|
||||||
return SPDYLAY_ERR_UNSUPPORTED_VERSION;
|
return NGHTTP2_ERR_UNSUPPORTED_VERSION;
|
||||||
}
|
}
|
||||||
if(Z_OK != inflateInit(&inflater->zst)) {
|
if(Z_OK != inflateInit(&inflater->zst)) {
|
||||||
return SPDYLAY_ERR_ZLIB;
|
return NGHTTP2_ERR_ZLIB;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_zlib_deflate_free(spdylay_zlib *deflater)
|
void nghttp2_zlib_deflate_free(nghttp2_zlib *deflater)
|
||||||
{
|
{
|
||||||
deflateEnd(&deflater->zst);
|
deflateEnd(&deflater->zst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spdylay_zlib_inflate_free(spdylay_zlib *inflater)
|
void nghttp2_zlib_inflate_free(nghttp2_zlib *inflater)
|
||||||
{
|
{
|
||||||
inflateEnd(&inflater->zst);
|
inflateEnd(&inflater->zst);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t spdylay_zlib_deflate_hd(spdylay_zlib *deflater,
|
ssize_t nghttp2_zlib_deflate_hd(nghttp2_zlib *deflater,
|
||||||
uint8_t *out, size_t outlen,
|
uint8_t *out, size_t outlen,
|
||||||
const uint8_t *in, size_t inlen)
|
const uint8_t *in, size_t inlen)
|
||||||
{
|
{
|
||||||
|
@ -311,51 +311,51 @@ ssize_t spdylay_zlib_deflate_hd(spdylay_zlib *deflater,
|
||||||
if(r == Z_OK) {
|
if(r == Z_OK) {
|
||||||
return outlen-deflater->zst.avail_out;
|
return outlen-deflater->zst.avail_out;
|
||||||
} else {
|
} else {
|
||||||
return SPDYLAY_ERR_ZLIB;
|
return NGHTTP2_ERR_ZLIB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spdylay_zlib_deflate_hd_bound(spdylay_zlib *deflater, size_t len)
|
size_t nghttp2_zlib_deflate_hd_bound(nghttp2_zlib *deflater, size_t len)
|
||||||
{
|
{
|
||||||
return deflateBound(&deflater->zst, len);
|
return deflateBound(&deflater->zst, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t spdylay_zlib_inflate_hd(spdylay_zlib *inflater,
|
ssize_t nghttp2_zlib_inflate_hd(nghttp2_zlib *inflater,
|
||||||
spdylay_buffer* buf,
|
nghttp2_buffer* buf,
|
||||||
const uint8_t *in, size_t inlen)
|
const uint8_t *in, size_t inlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
inflater->zst.avail_in = inlen;
|
inflater->zst.avail_in = inlen;
|
||||||
inflater->zst.next_in = (uint8_t*)in;
|
inflater->zst.next_in = (uint8_t*)in;
|
||||||
while(1) {
|
while(1) {
|
||||||
if(spdylay_buffer_avail(buf) == 0) {
|
if(nghttp2_buffer_avail(buf) == 0) {
|
||||||
if((r = spdylay_buffer_alloc(buf)) != 0) {
|
if((r = nghttp2_buffer_alloc(buf)) != 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inflater->zst.avail_out = spdylay_buffer_avail(buf);
|
inflater->zst.avail_out = nghttp2_buffer_avail(buf);
|
||||||
inflater->zst.next_out = spdylay_buffer_get(buf);
|
inflater->zst.next_out = nghttp2_buffer_get(buf);
|
||||||
r = inflate(&inflater->zst, Z_NO_FLUSH);
|
r = inflate(&inflater->zst, Z_NO_FLUSH);
|
||||||
if(r == Z_STREAM_ERROR || r == Z_STREAM_END || r == Z_DATA_ERROR) {
|
if(r == Z_STREAM_ERROR || r == Z_STREAM_END || r == Z_DATA_ERROR) {
|
||||||
return SPDYLAY_ERR_ZLIB;
|
return NGHTTP2_ERR_ZLIB;
|
||||||
} else if(r == Z_NEED_DICT) {
|
} else if(r == Z_NEED_DICT) {
|
||||||
const uint8_t *hd_dict;
|
const uint8_t *hd_dict;
|
||||||
size_t hd_dict_length;
|
size_t hd_dict_length;
|
||||||
hd_dict = spdylay_select_hd_dict(&hd_dict_length, inflater->version);
|
hd_dict = nghttp2_select_hd_dict(&hd_dict_length, inflater->version);
|
||||||
assert(hd_dict);
|
assert(hd_dict);
|
||||||
if(Z_OK != inflateSetDictionary(&inflater->zst, (uint8_t*)hd_dict,
|
if(Z_OK != inflateSetDictionary(&inflater->zst, (uint8_t*)hd_dict,
|
||||||
hd_dict_length)) {
|
hd_dict_length)) {
|
||||||
return SPDYLAY_ERR_ZLIB;
|
return NGHTTP2_ERR_ZLIB;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(r == Z_OK) {
|
if(r == Z_OK) {
|
||||||
size_t adv = spdylay_buffer_avail(buf)-inflater->zst.avail_out;
|
size_t adv = nghttp2_buffer_avail(buf)-inflater->zst.avail_out;
|
||||||
spdylay_buffer_advance(buf, adv);
|
nghttp2_buffer_advance(buf, adv);
|
||||||
}
|
}
|
||||||
if(inflater->zst.avail_in == 0 && inflater->zst.avail_out > 0) {
|
if(inflater->zst.avail_in == 0 && inflater->zst.avail_out > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return spdylay_buffer_length(buf);
|
return nghttp2_buffer_length(buf);
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,22 +22,22 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_ZLIB_H
|
#ifndef NGHTTP2_ZLIB_H
|
||||||
#define SPDYLAY_ZLIB_H
|
#define NGHTTP2_ZLIB_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif /* HAVE_CONFIG_H */
|
#endif /* HAVE_CONFIG_H */
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "spdylay_buffer.h"
|
#include "nghttp2_buffer.h"
|
||||||
|
|
||||||
/* This structure is used for both deflater and inflater. */
|
/* This structure is used for both deflater and inflater. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
z_stream zst;
|
z_stream zst;
|
||||||
/* The protocol version to select the dictionary later. */
|
/* The protocol version to select the dictionary later. */
|
||||||
uint16_t version;
|
uint16_t version;
|
||||||
} spdylay_zlib;
|
} nghttp2_zlib;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes |deflater| for deflating name/values pairs in the frame
|
* Initializes |deflater| for deflating name/values pairs in the frame
|
||||||
|
@ -47,12 +47,12 @@ typedef struct {
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The z_stream initialization failed.
|
* The z_stream initialization failed.
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
*/
|
*/
|
||||||
int spdylay_zlib_deflate_hd_init(spdylay_zlib *deflater, int comp,
|
int nghttp2_zlib_deflate_hd_init(nghttp2_zlib *deflater, int comp,
|
||||||
uint16_t version);
|
uint16_t version);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -62,43 +62,43 @@ int spdylay_zlib_deflate_hd_init(spdylay_zlib *deflater, int comp,
|
||||||
* This function returns 0 if it succeeds, or one of the following
|
* This function returns 0 if it succeeds, or one of the following
|
||||||
* negative error codes:
|
* negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The z_stream initialization failed.
|
* The z_stream initialization failed.
|
||||||
* SPDYLAY_ERR_UNSUPPORTED_VERSION
|
* NGHTTP2_ERR_UNSUPPORTED_VERSION
|
||||||
* The version is not supported.
|
* The version is not supported.
|
||||||
*/
|
*/
|
||||||
int spdylay_zlib_inflate_hd_init(spdylay_zlib *inflater, uint16_t version);
|
int nghttp2_zlib_inflate_hd_init(nghttp2_zlib *inflater, uint16_t version);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates any resources allocated for |deflater|.
|
* Deallocates any resources allocated for |deflater|.
|
||||||
*/
|
*/
|
||||||
void spdylay_zlib_deflate_free(spdylay_zlib *deflater);
|
void nghttp2_zlib_deflate_free(nghttp2_zlib *deflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocates any resources allocated for |inflater|.
|
* Deallocates any resources allocated for |inflater|.
|
||||||
*/
|
*/
|
||||||
void spdylay_zlib_inflate_free(spdylay_zlib *inflater);
|
void nghttp2_zlib_inflate_free(nghttp2_zlib *inflater);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the maximum length when |len| bytes of data are deflated by
|
* Returns the maximum length when |len| bytes of data are deflated by
|
||||||
* |deflater|.
|
* |deflater|.
|
||||||
*/
|
*/
|
||||||
size_t spdylay_zlib_deflate_hd_bound(spdylay_zlib *deflater, size_t len);
|
size_t nghttp2_zlib_deflate_hd_bound(nghttp2_zlib *deflater, size_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deflates data stored in |in| with length |inlen|. The output is
|
* Deflates data stored in |in| with length |inlen|. The output is
|
||||||
* written to |out| with length |outlen|. This is not a strict
|
* written to |out| with length |outlen|. This is not a strict
|
||||||
* requirement but |outlen| should have at least
|
* requirement but |outlen| should have at least
|
||||||
* spdylay_zlib_deflate_hd_bound(|inlen|) bytes for successful
|
* nghttp2_zlib_deflate_hd_bound(|inlen|) bytes for successful
|
||||||
* operation.
|
* operation.
|
||||||
*
|
*
|
||||||
* This function returns the number of bytes outputted if it succeeds,
|
* This function returns the number of bytes outputted if it succeeds,
|
||||||
* or one of the following negative error codes:
|
* or one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The deflate operation failed.
|
* The deflate operation failed.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_zlib_deflate_hd(spdylay_zlib *deflater,
|
ssize_t nghttp2_zlib_deflate_hd(nghttp2_zlib *deflater,
|
||||||
uint8_t *out, size_t outlen,
|
uint8_t *out, size_t outlen,
|
||||||
const uint8_t *in, size_t inlen);
|
const uint8_t *in, size_t inlen);
|
||||||
|
|
||||||
|
@ -109,14 +109,14 @@ ssize_t spdylay_zlib_deflate_hd(spdylay_zlib *deflater,
|
||||||
* This function returns the number of bytes outputted if it succeeds,
|
* This function returns the number of bytes outputted if it succeeds,
|
||||||
* or one of the following negative error codes:
|
* or one of the following negative error codes:
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_ZLIB
|
* NGHTTP2_ERR_ZLIB
|
||||||
* The inflate operation failed.
|
* The inflate operation failed.
|
||||||
*
|
*
|
||||||
* SPDYLAY_ERR_NOMEM
|
* NGHTTP2_ERR_NOMEM
|
||||||
* Out of memory.
|
* Out of memory.
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_zlib_inflate_hd(spdylay_zlib *inflater,
|
ssize_t nghttp2_zlib_inflate_hd(nghttp2_zlib *inflater,
|
||||||
spdylay_buffer* buf,
|
nghttp2_buffer* buf,
|
||||||
const uint8_t *in, size_t inlen);
|
const uint8_t *in, size_t inlen);
|
||||||
|
|
||||||
#endif /* SPDYLAY_ZLIB_H */
|
#endif /* NGHTTP2_ZLIB_H */
|
|
@ -1,335 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 <string.h>
|
|
||||||
|
|
||||||
#include "spdylay_session.h"
|
|
||||||
#include "spdylay_frame.h"
|
|
||||||
#include "spdylay_helper.h"
|
|
||||||
|
|
||||||
static int spdylay_submit_syn_stream_shared
|
|
||||||
(spdylay_session *session,
|
|
||||||
uint8_t flags,
|
|
||||||
int32_t assoc_stream_id,
|
|
||||||
uint8_t pri,
|
|
||||||
const char **nv,
|
|
||||||
const spdylay_data_provider *data_prd,
|
|
||||||
void *stream_user_data)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
spdylay_frame *frame;
|
|
||||||
char **nv_copy;
|
|
||||||
uint8_t flags_copy;
|
|
||||||
spdylay_data_provider *data_prd_copy = NULL;
|
|
||||||
spdylay_syn_stream_aux_data *aux_data;
|
|
||||||
if(pri > spdylay_session_get_pri_lowest(session)) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
if(assoc_stream_id != 0 && session->server == 0) {
|
|
||||||
assoc_stream_id = 0;
|
|
||||||
}
|
|
||||||
if(!spdylay_frame_nv_check_null(nv)) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
if(data_prd != NULL && data_prd->read_callback != NULL) {
|
|
||||||
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_norm_copy(nv);
|
|
||||||
if(nv_copy == NULL) {
|
|
||||||
free(frame);
|
|
||||||
free(aux_data);
|
|
||||||
free(data_prd_copy);
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
flags_copy = 0;
|
|
||||||
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
|
|
||||||
flags_copy |= SPDYLAY_CTRL_FLAG_FIN;
|
|
||||||
}
|
|
||||||
if(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) {
|
|
||||||
flags_copy |= SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL;
|
|
||||||
}
|
|
||||||
spdylay_frame_syn_stream_init(&frame->syn_stream,
|
|
||||||
session->version, flags_copy,
|
|
||||||
0, assoc_stream_id, pri, nv_copy);
|
|
||||||
r = spdylay_session_add_frame(session, SPDYLAY_CTRL, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_syn_stream(spdylay_session *session, uint8_t flags,
|
|
||||||
int32_t assoc_stream_id, uint8_t pri,
|
|
||||||
const char **nv, void *stream_user_data)
|
|
||||||
{
|
|
||||||
return spdylay_submit_syn_stream_shared(session, flags, assoc_stream_id,
|
|
||||||
pri, nv, NULL, stream_user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_syn_reply(spdylay_session *session, uint8_t flags,
|
|
||||||
int32_t stream_id, const char **nv)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
spdylay_frame *frame;
|
|
||||||
char **nv_copy;
|
|
||||||
uint8_t flags_copy;
|
|
||||||
if(!spdylay_frame_nv_check_null(nv)) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
frame = malloc(sizeof(spdylay_frame));
|
|
||||||
if(frame == NULL) {
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
nv_copy = spdylay_frame_nv_norm_copy(nv);
|
|
||||||
if(nv_copy == NULL) {
|
|
||||||
free(frame);
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
flags_copy = 0;
|
|
||||||
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
|
|
||||||
flags_copy |= SPDYLAY_CTRL_FLAG_FIN;
|
|
||||||
}
|
|
||||||
spdylay_frame_syn_reply_init(&frame->syn_reply, session->version, flags_copy,
|
|
||||||
stream_id, nv_copy);
|
|
||||||
r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL);
|
|
||||||
if(r != 0) {
|
|
||||||
spdylay_frame_syn_reply_free(&frame->syn_reply);
|
|
||||||
free(frame);
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_headers(spdylay_session *session, uint8_t flags,
|
|
||||||
int32_t stream_id, const char **nv)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
spdylay_frame *frame;
|
|
||||||
char **nv_copy;
|
|
||||||
uint8_t flags_copy;
|
|
||||||
if(!spdylay_frame_nv_check_null(nv)) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
frame = malloc(sizeof(spdylay_frame));
|
|
||||||
if(frame == NULL) {
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
nv_copy = spdylay_frame_nv_norm_copy(nv);
|
|
||||||
if(nv_copy == NULL) {
|
|
||||||
free(frame);
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
flags_copy = 0;
|
|
||||||
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
|
|
||||||
flags_copy |= SPDYLAY_CTRL_FLAG_FIN;
|
|
||||||
}
|
|
||||||
spdylay_frame_headers_init(&frame->headers, session->version, flags_copy,
|
|
||||||
stream_id, nv_copy);
|
|
||||||
r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL);
|
|
||||||
if(r != 0) {
|
|
||||||
spdylay_frame_headers_free(&frame->headers);
|
|
||||||
free(frame);
|
|
||||||
}
|
|
||||||
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_rst_stream(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, uint32_t status_code)
|
|
||||||
{
|
|
||||||
return spdylay_session_add_goaway(session, session->last_recv_stream_id,
|
|
||||||
status_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_settings(spdylay_session *session, uint8_t flags,
|
|
||||||
const spdylay_settings_entry *iv, size_t niv)
|
|
||||||
{
|
|
||||||
spdylay_frame *frame;
|
|
||||||
spdylay_settings_entry *iv_copy;
|
|
||||||
int check[SPDYLAY_SETTINGS_MAX+1];
|
|
||||||
size_t i;
|
|
||||||
int r;
|
|
||||||
memset(check, 0, sizeof(check));
|
|
||||||
for(i = 0; i < niv; ++i) {
|
|
||||||
if(iv[i].settings_id > SPDYLAY_SETTINGS_MAX || iv[i].settings_id == 0 ||
|
|
||||||
check[iv[i].settings_id] == 1) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
} else {
|
|
||||||
check[iv[i].settings_id] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
frame = malloc(sizeof(spdylay_frame));
|
|
||||||
if(frame == NULL) {
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
iv_copy = spdylay_frame_iv_copy(iv, niv);
|
|
||||||
if(iv_copy == NULL) {
|
|
||||||
free(frame);
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
spdylay_frame_iv_sort(iv_copy, niv);
|
|
||||||
spdylay_frame_settings_init(&frame->settings, session->version,
|
|
||||||
flags, iv_copy, niv);
|
|
||||||
r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL);
|
|
||||||
if(r == 0) {
|
|
||||||
spdylay_session_update_local_settings(session, iv_copy, niv);
|
|
||||||
} else {
|
|
||||||
spdylay_frame_settings_free(&frame->settings);
|
|
||||||
free(frame);
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id,
|
|
||||||
int32_t delta_window_size)
|
|
||||||
{
|
|
||||||
spdylay_stream *stream;
|
|
||||||
if(delta_window_size <= 0) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
stream = spdylay_session_get_stream(session, stream_id);
|
|
||||||
if(stream) {
|
|
||||||
stream->recv_window_size -= spdylay_min(delta_window_size,
|
|
||||||
stream->recv_window_size);
|
|
||||||
return spdylay_session_add_window_update(session, stream_id,
|
|
||||||
delta_window_size);
|
|
||||||
} else {
|
|
||||||
return SPDYLAY_ERR_STREAM_CLOSED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_request(spdylay_session *session, uint8_t pri,
|
|
||||||
const char **nv,
|
|
||||||
const spdylay_data_provider *data_prd,
|
|
||||||
void *stream_user_data)
|
|
||||||
{
|
|
||||||
int flags;
|
|
||||||
flags = 0;
|
|
||||||
if(data_prd == NULL || data_prd->read_callback == NULL) {
|
|
||||||
flags |= SPDYLAY_CTRL_FLAG_FIN;
|
|
||||||
}
|
|
||||||
return spdylay_submit_syn_stream_shared(session, flags, 0, pri, nv, data_prd,
|
|
||||||
stream_user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
int spdylay_submit_response(spdylay_session *session,
|
|
||||||
int32_t stream_id, const char **nv,
|
|
||||||
const 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(!spdylay_frame_nv_check_null(nv)) {
|
|
||||||
return SPDYLAY_ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
if(data_prd != NULL && data_prd->read_callback != NULL) {
|
|
||||||
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_norm_copy(nv);
|
|
||||||
if(nv_copy == NULL) {
|
|
||||||
free(frame);
|
|
||||||
free(data_prd_copy);
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
if(data_prd_copy == NULL) {
|
|
||||||
flags |= SPDYLAY_CTRL_FLAG_FIN;
|
|
||||||
}
|
|
||||||
spdylay_frame_syn_reply_init(&frame->syn_reply, session->version, flags,
|
|
||||||
stream_id, nv_copy);
|
|
||||||
r = spdylay_session_add_frame(session, SPDYLAY_CTRL, 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,
|
|
||||||
uint8_t flags,
|
|
||||||
const spdylay_data_provider *data_prd)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
spdylay_data *data_frame;
|
|
||||||
uint8_t nflags = 0;
|
|
||||||
data_frame = malloc(sizeof(spdylay_frame));
|
|
||||||
if(data_frame == NULL) {
|
|
||||||
return SPDYLAY_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
if(flags & SPDYLAY_DATA_FLAG_FIN) {
|
|
||||||
nflags |= SPDYLAY_DATA_FLAG_FIN;
|
|
||||||
}
|
|
||||||
spdylay_frame_data_init(data_frame, stream_id, nflags, data_prd);
|
|
||||||
r = spdylay_session_add_frame(session, SPDYLAY_DATA, data_frame, NULL);
|
|
||||||
if(r != 0) {
|
|
||||||
spdylay_frame_data_free(data_frame);
|
|
||||||
free(data_frame);
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
include spdylay.pyx cspdylay.pxd spdylay_tests.py spdyclient.py spdyserv.py README.rst
|
|
|
@ -1,24 +0,0 @@
|
||||||
# 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.
|
|
||||||
EXTRA_DIST = MANIFEST.in README.rst cspdylay.pxd setup.py \
|
|
||||||
spdyclient.py spdylay.pyx spdylay_tests.py spdyserv.py
|
|
|
@ -1,113 +0,0 @@
|
||||||
Python-spdylay is a Python SPDY library on top of Spdylay C
|
|
||||||
library. It supports SPDY/2 and SPDY/3 protocol.
|
|
||||||
|
|
||||||
It does not perform any I/O operations. When the library needs them,
|
|
||||||
it calls the callback functions provided by the application. It also
|
|
||||||
does not include any event polling mechanism, so the application can
|
|
||||||
freely choose the way of handling events.
|
|
||||||
|
|
||||||
It provides almost all API Spdylay provides with Pythonic fashion.
|
|
||||||
|
|
||||||
The core library API works with Python 2 and 3. But
|
|
||||||
``ThreadedSPDYServer`` requires Python 3.3 because it uses TLS NPN
|
|
||||||
extension.
|
|
||||||
|
|
||||||
Installation
|
|
||||||
============
|
|
||||||
|
|
||||||
First install Spdylay library. You can grab a source distribution from
|
|
||||||
`sf.net download page
|
|
||||||
<http://sourceforge.net/projects/spdylay/files/stable/>`_
|
|
||||||
or `clone git repository <https://github.com/tatsuhiro-t/spdylay>`_.
|
|
||||||
|
|
||||||
See `Spdylay documentation
|
|
||||||
<http://spdylay.sourceforge.net/package_README.html>`_ for the
|
|
||||||
required packages and how to build Spdylay from git repository.
|
|
||||||
|
|
||||||
After Spdylay is installed, run ``build_ext`` command to build
|
|
||||||
extension module::
|
|
||||||
|
|
||||||
$ python setup.py build_ext
|
|
||||||
|
|
||||||
If you installed Spdylay library in other than standard location, use
|
|
||||||
``--include-dirs`` and ``--library-dirs`` to specify header file and
|
|
||||||
library locations respectively.
|
|
||||||
|
|
||||||
Documentation
|
|
||||||
=============
|
|
||||||
|
|
||||||
See `python-spdylay documentation
|
|
||||||
<http://spdylay.sourceforge.net/python.html>`_.
|
|
||||||
|
|
||||||
Samples
|
|
||||||
=======
|
|
||||||
|
|
||||||
Here is a simple SPDY server::
|
|
||||||
|
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# The example SPDY server. Python 3.3 or later is required because TLS
|
|
||||||
# NPN is used in spdylay.ThreadedSPDYServer. Put private key and
|
|
||||||
# certificate file in the current working directory.
|
|
||||||
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
# private key file
|
|
||||||
KEY_FILE='server.key'
|
|
||||||
# certificate file
|
|
||||||
CERT_FILE='server.crt'
|
|
||||||
|
|
||||||
class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler):
|
|
||||||
|
|
||||||
def do_GET(self):
|
|
||||||
self.send_response(200)
|
|
||||||
self.send_header('content-type', 'text/html; charset=UTF-8')
|
|
||||||
|
|
||||||
content = '''\
|
|
||||||
<html>
|
|
||||||
<head><title>SPDY FTW</title></head>
|
|
||||||
<body>
|
|
||||||
<h1>SPDY FTW</h1>
|
|
||||||
<p>The age of HTTP/1.1 is over. The time of SPDY has come.</p>
|
|
||||||
</body>
|
|
||||||
</html>'''.encode('UTF-8')
|
|
||||||
|
|
||||||
self.wfile.write(content)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
HOST, PORT = "localhost", 3000
|
|
||||||
|
|
||||||
server = spdylay.ThreadedSPDYServer((HOST, PORT),
|
|
||||||
MySPDYRequestHandler,
|
|
||||||
cert_file=CERT_FILE,
|
|
||||||
key_file=KEY_FILE)
|
|
||||||
server.start()
|
|
||||||
|
|
||||||
Here is a simple SPDY client::
|
|
||||||
|
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# The example SPDY client. You need Python 3.3 or later because we
|
|
||||||
# use TLS NPN.
|
|
||||||
#
|
|
||||||
# Usage: spdyclient.py URL...
|
|
||||||
#
|
|
||||||
import sys
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
class MyStreamHandler(spdylay.BaseSPDYStreamHandler):
|
|
||||||
def on_header(self, nv):
|
|
||||||
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
|
|
||||||
for k, v in nv:
|
|
||||||
sys.stdout.write('{}: {}\n'.format(k, v))
|
|
||||||
|
|
||||||
def on_data(self, data):
|
|
||||||
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
|
|
||||||
sys.stdout.buffer.write(data)
|
|
||||||
|
|
||||||
def on_close(self, status_code):
|
|
||||||
sys.stdout.write('Stream#{} closed\n'.format(self.stream_id))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
uris = sys.argv[1:]
|
|
||||||
spdylay.urlfetch(uris, MyStreamHandler)
|
|
|
@ -1,334 +0,0 @@
|
||||||
from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t
|
|
||||||
|
|
||||||
cdef extern from 'spdylay/spdylay.h':
|
|
||||||
|
|
||||||
ctypedef enum spdylay_proto_version:
|
|
||||||
SPDYLAY_PROTO_SPDY2
|
|
||||||
SPDYLAY_PROTO_SPDY3
|
|
||||||
|
|
||||||
ctypedef enum spdylay_error:
|
|
||||||
SPDYLAY_ERR_INVALID_ARGUMENT
|
|
||||||
SPDYLAY_ERR_ZLIB
|
|
||||||
SPDYLAY_ERR_UNSUPPORTED_VERSION
|
|
||||||
SPDYLAY_ERR_WOULDBLOCK
|
|
||||||
SPDYLAY_ERR_PROTO
|
|
||||||
SPDYLAY_ERR_INVALID_FRAME
|
|
||||||
SPDYLAY_ERR_EOF
|
|
||||||
SPDYLAY_ERR_DEFERRED
|
|
||||||
SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE
|
|
||||||
SPDYLAY_ERR_STREAM_CLOSED
|
|
||||||
SPDYLAY_ERR_STREAM_CLOSING
|
|
||||||
SPDYLAY_ERR_STREAM_SHUT_WR
|
|
||||||
SPDYLAY_ERR_INVALID_STREAM_ID
|
|
||||||
SPDYLAY_ERR_INVALID_STREAM_STATE
|
|
||||||
SPDYLAY_ERR_DEFERRED_DATA_EXIST
|
|
||||||
SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED
|
|
||||||
SPDYLAY_ERR_GOAWAY_ALREADY_SENT
|
|
||||||
SPDYLAY_ERR_INVALID_HEADER_BLOCK
|
|
||||||
SPDYLAY_ERR_INVALID_STATE
|
|
||||||
SPDYLAY_ERR_GZIP
|
|
||||||
SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE
|
|
||||||
SPDYLAY_ERR_FATAL
|
|
||||||
SPDYLAY_ERR_NOMEM
|
|
||||||
SPDYLAY_ERR_CALLBACK_FAILURE
|
|
||||||
|
|
||||||
ctypedef enum spdylay_ctrl_flag:
|
|
||||||
SPDYLAY_CTRL_FLAG_NONE
|
|
||||||
SPDYLAY_CTRL_FLAG_FIN
|
|
||||||
SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL
|
|
||||||
|
|
||||||
ctypedef enum spdylay_data_flag:
|
|
||||||
SPDYLAY_DATA_FLAG_NONE
|
|
||||||
SPDYLAY_DATA_FLAG_FIN
|
|
||||||
|
|
||||||
ctypedef enum spdylay_frame_type:
|
|
||||||
SPDYLAY_SYN_STREAM
|
|
||||||
SPDYLAY_SYN_REPLY
|
|
||||||
SPDYLAY_RST_STREAM
|
|
||||||
SPDYLAY_SETTINGS
|
|
||||||
SPDYLAY_NOOP
|
|
||||||
SPDYLAY_PING
|
|
||||||
SPDYLAY_GOAWAY
|
|
||||||
SPDYLAY_HEADERS
|
|
||||||
SPDYLAY_WINDOW_UPDATE
|
|
||||||
SPDYLAY_CREDENTIAL
|
|
||||||
|
|
||||||
ctypedef enum spdylay_status_code:
|
|
||||||
SPDYLAY_OK
|
|
||||||
SPDYLAY_PROTOCOL_ERROR
|
|
||||||
SPDYLAY_INVALID_STREAM
|
|
||||||
SPDYLAY_REFUSED_STREAM
|
|
||||||
SPDYLAY_UNSUPPORTED_VERSION
|
|
||||||
SPDYLAY_CANCEL
|
|
||||||
SPDYLAY_INTERNAL_ERROR
|
|
||||||
SPDYLAY_FLOW_CONTROL_ERROR
|
|
||||||
# Following status codes were introduced in SPDY/3
|
|
||||||
SPDYLAY_STREAM_IN_USE
|
|
||||||
SPDYLAY_STREAM_ALREADY_CLOSED
|
|
||||||
SPDYLAY_INVALID_CREDENTIALS
|
|
||||||
SPDYLAY_FRAME_TOO_LARGE
|
|
||||||
|
|
||||||
# The status codes for GOAWAY, introduced in SPDY/3.
|
|
||||||
ctypedef enum spdylay_goaway_status_code:
|
|
||||||
SPDYLAY_GOAWAY_OK
|
|
||||||
SPDYLAY_GOAWAY_PROTOCOL_ERROR
|
|
||||||
SPDYLAY_GOAWAY_INTERNAL_ERROR
|
|
||||||
|
|
||||||
ctypedef enum spdylay_settings_flag:
|
|
||||||
SPDYLAY_FLAG_SETTINGS_NONE
|
|
||||||
SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS
|
|
||||||
|
|
||||||
ctypedef enum spdylay_settings_id_flag:
|
|
||||||
SPDYLAY_ID_FLAG_SETTINGS_NONE
|
|
||||||
SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE
|
|
||||||
SPDYLAY_ID_FLAG_SETTINGS_PERSISTED
|
|
||||||
|
|
||||||
ctypedef enum spdylay_settings_id:
|
|
||||||
SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH
|
|
||||||
SPDYLAY_SETTINGS_DOWNLOAD_BANDWIDTH
|
|
||||||
SPDYLAY_SETTINGS_ROUND_TRIP_TIME
|
|
||||||
SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS
|
|
||||||
SPDYLAY_SETTINGS_CURRENT_CWND
|
|
||||||
SPDYLAY_SETTINGS_DOWNLOAD_RETRANS_RATE
|
|
||||||
SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE
|
|
||||||
SPDYLAY_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE
|
|
||||||
SPDYLAY_SETTINGS_MAX
|
|
||||||
|
|
||||||
ctypedef struct spdylay_ctrl_hd:
|
|
||||||
uint16_t version
|
|
||||||
uint16_t type
|
|
||||||
uint8_t flags
|
|
||||||
int32_t length
|
|
||||||
|
|
||||||
ctypedef struct spdylay_syn_stream:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
int32_t stream_id
|
|
||||||
int32_t assoc_stream_id
|
|
||||||
uint8_t pri
|
|
||||||
uint8_t slot
|
|
||||||
char **nv
|
|
||||||
|
|
||||||
ctypedef struct spdylay_syn_reply:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
int32_t stream_id
|
|
||||||
char **nv
|
|
||||||
|
|
||||||
ctypedef struct spdylay_headers:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
int32_t stream_id
|
|
||||||
char **nv
|
|
||||||
|
|
||||||
ctypedef struct spdylay_rst_stream:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
int32_t stream_id
|
|
||||||
uint32_t status_code
|
|
||||||
|
|
||||||
ctypedef struct spdylay_settings_entry:
|
|
||||||
int32_t settings_id
|
|
||||||
uint8_t flags
|
|
||||||
uint32_t value
|
|
||||||
|
|
||||||
ctypedef struct spdylay_settings:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
size_t niv
|
|
||||||
spdylay_settings_entry *iv
|
|
||||||
|
|
||||||
ctypedef struct spdylay_ping:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
uint32_t unique_id
|
|
||||||
|
|
||||||
ctypedef struct spdylay_goaway:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
int32_t last_good_stream_id
|
|
||||||
uint32_t status_code
|
|
||||||
|
|
||||||
ctypedef struct spdylay_window_update:
|
|
||||||
spdylay_ctrl_hd hd
|
|
||||||
int32_t stream_id
|
|
||||||
int32_t delta_window_size
|
|
||||||
|
|
||||||
ctypedef union spdylay_frame:
|
|
||||||
spdylay_syn_stream syn_stream
|
|
||||||
spdylay_syn_reply syn_reply
|
|
||||||
spdylay_rst_stream rst_stream
|
|
||||||
spdylay_settings settings
|
|
||||||
spdylay_ping ping
|
|
||||||
spdylay_goaway goaway
|
|
||||||
spdylay_headers headers
|
|
||||||
spdylay_window_update window_update
|
|
||||||
#spdylay_credential credential
|
|
||||||
|
|
||||||
ctypedef union spdylay_data_source:
|
|
||||||
int fd
|
|
||||||
void *ptr
|
|
||||||
|
|
||||||
ctypedef ssize_t (*spdylay_data_source_read_callback)\
|
|
||||||
(spdylay_session *session, int32_t stream_id,
|
|
||||||
uint8_t *buf, size_t length, int *eof,
|
|
||||||
spdylay_data_source *source, void *user_data)
|
|
||||||
|
|
||||||
ctypedef struct spdylay_data_provider:
|
|
||||||
spdylay_data_source source
|
|
||||||
spdylay_data_source_read_callback read_callback
|
|
||||||
|
|
||||||
ctypedef struct spdylay_session:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
ctypedef ssize_t (*spdylay_send_callback)\
|
|
||||||
(spdylay_session *session,
|
|
||||||
uint8_t *data, size_t length, int flags, void *user_data)
|
|
||||||
|
|
||||||
ctypedef ssize_t (*spdylay_recv_callback)\
|
|
||||||
(spdylay_session *session,
|
|
||||||
uint8_t *buf, size_t length, int flags, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_ctrl_recv_callback)\
|
|
||||||
(spdylay_session *session, spdylay_frame_type frame_type,
|
|
||||||
spdylay_frame *frame, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_invalid_ctrl_recv_callback)\
|
|
||||||
(spdylay_session *session, spdylay_frame_type type,
|
|
||||||
spdylay_frame *frame, uint32_t status_code, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_data_chunk_recv_callback)\
|
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id,
|
|
||||||
uint8_t *data, size_t len, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_data_recv_callback)\
|
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id,
|
|
||||||
int32_t length, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_before_ctrl_send_callback)\
|
|
||||||
(spdylay_session *session, spdylay_frame_type type,
|
|
||||||
spdylay_frame *frame, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_ctrl_send_callback)\
|
|
||||||
(spdylay_session *session, spdylay_frame_type type,
|
|
||||||
spdylay_frame *frame, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_ctrl_not_send_callback)\
|
|
||||||
(spdylay_session *session, spdylay_frame_type type,
|
|
||||||
spdylay_frame *frame, int error_code, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_data_send_callback)\
|
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id,
|
|
||||||
int32_t length, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_stream_close_callback)\
|
|
||||||
(spdylay_session *session, int32_t stream_id,
|
|
||||||
spdylay_status_code status_code, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_request_recv_callback)\
|
|
||||||
(spdylay_session *session, int32_t stream_id, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_ctrl_recv_parse_error_callback)\
|
|
||||||
(spdylay_session *session, spdylay_frame_type type,
|
|
||||||
uint8_t *head, size_t headlen, uint8_t *payload, size_t payloadlen,
|
|
||||||
int error_code, void *user_data)
|
|
||||||
|
|
||||||
ctypedef void (*spdylay_on_unknown_ctrl_recv_callback)\
|
|
||||||
(spdylay_session *session, uint8_t *head, size_t headlen,
|
|
||||||
uint8_t *payload, size_t payloadlen, void *user_data)
|
|
||||||
|
|
||||||
ctypedef struct spdylay_session_callbacks:
|
|
||||||
spdylay_send_callback send_callback
|
|
||||||
spdylay_recv_callback recv_callback
|
|
||||||
spdylay_on_ctrl_recv_callback on_ctrl_recv_callback
|
|
||||||
spdylay_on_invalid_ctrl_recv_callback on_invalid_ctrl_recv_callback
|
|
||||||
spdylay_on_data_chunk_recv_callback on_data_chunk_recv_callback
|
|
||||||
spdylay_on_data_recv_callback on_data_recv_callback
|
|
||||||
spdylay_before_ctrl_send_callback before_ctrl_send_callback
|
|
||||||
spdylay_on_ctrl_send_callback on_ctrl_send_callback
|
|
||||||
spdylay_on_ctrl_not_send_callback on_ctrl_not_send_callback
|
|
||||||
spdylay_on_data_send_callback on_data_send_callback
|
|
||||||
spdylay_on_stream_close_callback on_stream_close_callback
|
|
||||||
spdylay_on_request_recv_callback on_request_recv_callback
|
|
||||||
spdylay_on_ctrl_recv_parse_error_callback \
|
|
||||||
on_ctrl_recv_parse_error_callback
|
|
||||||
spdylay_on_unknown_ctrl_recv_callback on_unknown_ctrl_recv_callback
|
|
||||||
|
|
||||||
int spdylay_session_client_new(spdylay_session **session_ptr,
|
|
||||||
int version,
|
|
||||||
spdylay_session_callbacks *callbacks,
|
|
||||||
void *user_data)
|
|
||||||
|
|
||||||
int spdylay_session_server_new(spdylay_session **session_ptr,
|
|
||||||
int version,
|
|
||||||
spdylay_session_callbacks *callbacks,
|
|
||||||
void *user_data)
|
|
||||||
|
|
||||||
void spdylay_session_del(spdylay_session *session)
|
|
||||||
|
|
||||||
|
|
||||||
int spdylay_session_recv(spdylay_session *session)
|
|
||||||
|
|
||||||
ssize_t spdylay_session_mem_recv(spdylay_session *session,
|
|
||||||
uint8_t *data, size_t length)
|
|
||||||
|
|
||||||
int spdylay_session_send(spdylay_session *session)
|
|
||||||
|
|
||||||
int spdylay_session_resume_data(spdylay_session *session,
|
|
||||||
int32_t stream_id)
|
|
||||||
|
|
||||||
bint spdylay_session_want_read(spdylay_session *session)
|
|
||||||
|
|
||||||
bint spdylay_session_want_write(spdylay_session *session)
|
|
||||||
|
|
||||||
void* spdylay_session_get_stream_user_data(spdylay_session *session,
|
|
||||||
int32_t stream_id)
|
|
||||||
|
|
||||||
size_t spdylay_session_get_outbound_queue_size(spdylay_session *session)
|
|
||||||
|
|
||||||
uint8_t spdylay_session_get_pri_lowest(spdylay_session *session)
|
|
||||||
|
|
||||||
int spdylay_session_fail_session(spdylay_session *session,
|
|
||||||
uint32_t status_code)
|
|
||||||
|
|
||||||
char* spdylay_strerror(int error_code)
|
|
||||||
|
|
||||||
int spdylay_submit_request(spdylay_session *session, uint8_t pri,
|
|
||||||
char **nv,
|
|
||||||
spdylay_data_provider *data_prd,
|
|
||||||
void *stream_user_data)
|
|
||||||
|
|
||||||
int spdylay_submit_response(spdylay_session *session,
|
|
||||||
int32_t stream_id, char **nv,
|
|
||||||
spdylay_data_provider *data_prd)
|
|
||||||
|
|
||||||
int spdylay_submit_syn_stream(spdylay_session *session, uint8_t flags,
|
|
||||||
int32_t assoc_stream_id, uint8_t pri,
|
|
||||||
char **nv, void *stream_user_data)
|
|
||||||
|
|
||||||
int spdylay_submit_syn_reply(spdylay_session *session, uint8_t flags,
|
|
||||||
int32_t stream_id, char **nv)
|
|
||||||
|
|
||||||
int spdylay_submit_headers(spdylay_session *session, uint8_t flags,
|
|
||||||
int32_t stream_id, char **nv)
|
|
||||||
|
|
||||||
int spdylay_submit_data(spdylay_session *session, int32_t stream_id,
|
|
||||||
uint8_t flags, spdylay_data_provider *data_prd)
|
|
||||||
|
|
||||||
int spdylay_submit_rst_stream(spdylay_session *session,
|
|
||||||
int32_t stream_id, uint32_t status_code)
|
|
||||||
|
|
||||||
int spdylay_submit_ping(spdylay_session *session)
|
|
||||||
|
|
||||||
int spdylay_submit_goaway(spdylay_session *session, uint32_t status_code)
|
|
||||||
|
|
||||||
int spdylay_submit_settings(spdylay_session *session, uint8_t flags,
|
|
||||||
spdylay_settings_entry *iv, size_t niv)
|
|
||||||
|
|
||||||
int spdylay_submit_window_update(spdylay_session *session,
|
|
||||||
int32_t stream_id,
|
|
||||||
int32_t delta_window_size)
|
|
||||||
|
|
||||||
ctypedef struct spdylay_npn_proto:
|
|
||||||
unsigned char *proto
|
|
||||||
uint8_t len
|
|
||||||
uint16_t version
|
|
||||||
|
|
||||||
spdylay_npn_proto* spdylay_npn_get_proto_list(size_t *len_ptr)
|
|
||||||
|
|
||||||
uint16_t spdylay_npn_get_version(unsigned char *proto,
|
|
||||||
size_t protolen)
|
|
142
python/setup.py
142
python/setup.py
|
@ -1,142 +0,0 @@
|
||||||
from distutils.core import setup
|
|
||||||
from distutils.extension import Extension
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name = 'python-spdylay',
|
|
||||||
# Also update __version__ in spdylay.pyx
|
|
||||||
version = '0.1.2',
|
|
||||||
description = 'Python SPDY library on top of Spdylay C library',
|
|
||||||
author = 'Tatsuhiro Tsujikawa',
|
|
||||||
author_email = 'tatsuhiro.t@gmail.com',
|
|
||||||
url = 'http://spdylay.sourceforge.net/',
|
|
||||||
keywords = [],
|
|
||||||
ext_modules = [Extension("spdylay",
|
|
||||||
["spdylay.c"],
|
|
||||||
libraries=['spdylay'])],
|
|
||||||
long_description="""\
|
|
||||||
Python-spdylay is a Python SPDY library on top of Spdylay C
|
|
||||||
library. It supports SPDY/2 and SPDY/3 protocol.
|
|
||||||
|
|
||||||
It does not perform any I/O operations. When the library needs them,
|
|
||||||
it calls the callback functions provided by the application. It also
|
|
||||||
does not include any event polling mechanism, so the application can
|
|
||||||
freely choose the way of handling events.
|
|
||||||
|
|
||||||
It provides almost all API Spdylay provides with Pythonic fashion.
|
|
||||||
|
|
||||||
The core library API works with Python 2 and 3. But
|
|
||||||
``ThreadedSPDYServer`` requires Python 3.3 because it uses TLS NPN
|
|
||||||
extension.
|
|
||||||
|
|
||||||
Installation
|
|
||||||
============
|
|
||||||
|
|
||||||
First install Spdylay library. You can grab a source distribution from
|
|
||||||
`sf.net download page
|
|
||||||
<http://sourceforge.net/projects/spdylay/files/stable/>`_
|
|
||||||
or `clone git repository <https://github.com/tatsuhiro-t/spdylay>`_.
|
|
||||||
|
|
||||||
See `Spdylay documentation
|
|
||||||
<http://spdylay.sourceforge.net/package_README.html>`_ for the
|
|
||||||
required packages and how to build Spdylay from git repository.
|
|
||||||
|
|
||||||
After Spdylay is installed, run ``build_ext`` command to build
|
|
||||||
extension module::
|
|
||||||
|
|
||||||
$ python setup.py build_ext
|
|
||||||
|
|
||||||
If you installed Spdylay library in other than standard location, use
|
|
||||||
``--include-dirs`` and ``--library-dirs`` to specify header file and
|
|
||||||
library locations respectively.
|
|
||||||
|
|
||||||
Documentation
|
|
||||||
=============
|
|
||||||
|
|
||||||
See `python-spdylay documentation
|
|
||||||
<http://spdylay.sourceforge.net/python.html>`_.
|
|
||||||
|
|
||||||
Samples
|
|
||||||
=======
|
|
||||||
|
|
||||||
Here is a simple SPDY server::
|
|
||||||
|
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# The example SPDY server. Python 3.3 or later is required because TLS
|
|
||||||
# NPN is used in spdylay.ThreadedSPDYServer. Put private key and
|
|
||||||
# certificate file in the current working directory.
|
|
||||||
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
# private key file
|
|
||||||
KEY_FILE='server.key'
|
|
||||||
# certificate file
|
|
||||||
CERT_FILE='server.crt'
|
|
||||||
|
|
||||||
class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler):
|
|
||||||
|
|
||||||
def do_GET(self):
|
|
||||||
self.send_response(200)
|
|
||||||
self.send_header('content-type', 'text/html; charset=UTF-8')
|
|
||||||
|
|
||||||
content = '''\\
|
|
||||||
<html>
|
|
||||||
<head><title>SPDY FTW</title></head>
|
|
||||||
<body>
|
|
||||||
<h1>SPDY FTW</h1>
|
|
||||||
<p>The age of HTTP/1.1 is over. The time of SPDY has come.</p>
|
|
||||||
</body>
|
|
||||||
</html>'''.encode('UTF-8')
|
|
||||||
|
|
||||||
self.wfile.write(content)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
HOST, PORT = "localhost", 3000
|
|
||||||
|
|
||||||
server = spdylay.ThreadedSPDYServer((HOST, PORT),
|
|
||||||
MySPDYRequestHandler,
|
|
||||||
cert_file=CERT_FILE,
|
|
||||||
key_file=KEY_FILE)
|
|
||||||
server.start()
|
|
||||||
|
|
||||||
Here is a simple SPDY client::
|
|
||||||
|
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# The example SPDY client. You need Python 3.3 or later because we
|
|
||||||
# use TLS NPN.
|
|
||||||
#
|
|
||||||
# Usage: spdyclient.py URL...
|
|
||||||
#
|
|
||||||
import sys
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
class MyStreamHandler(spdylay.BaseSPDYStreamHandler):
|
|
||||||
def on_header(self, nv):
|
|
||||||
sys.stdout.write('Stream#{}\\n'.format(self.stream_id))
|
|
||||||
for k, v in nv:
|
|
||||||
sys.stdout.write('{}: {}\\n'.format(k, v))
|
|
||||||
|
|
||||||
def on_data(self, data):
|
|
||||||
sys.stdout.write('Stream#{}\\n'.format(self.stream_id))
|
|
||||||
sys.stdout.buffer.write(data)
|
|
||||||
|
|
||||||
def on_close(self, status_code):
|
|
||||||
sys.stdout.write('Stream#{} closed\\n'.format(self.stream_id))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
uris = sys.argv[1:]
|
|
||||||
spdylay.urlfetch(uris, MyStreamHandler)
|
|
||||||
""",
|
|
||||||
classifiers = [
|
|
||||||
'Development Status :: 4 - Beta',
|
|
||||||
'Intended Audience :: Developers',
|
|
||||||
'License :: OSI Approved :: MIT License',
|
|
||||||
'Operating System :: OS Independent',
|
|
||||||
'Programming Language :: Cython',
|
|
||||||
'Programming Language :: Python',
|
|
||||||
'Programming Language :: Python :: 3',
|
|
||||||
'Topic :: Internet :: WWW/HTTP',
|
|
||||||
'Topic :: Software Development :: Libraries :: Python Modules'
|
|
||||||
]
|
|
||||||
)
|
|
|
@ -1,26 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# The example SPDY client. You need Python 3.3 or later because we
|
|
||||||
# use TLS NPN.
|
|
||||||
#
|
|
||||||
# Usage: spdyclient.py URL...
|
|
||||||
#
|
|
||||||
import sys
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
class MyStreamHandler(spdylay.BaseSPDYStreamHandler):
|
|
||||||
def on_header(self, nv):
|
|
||||||
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
|
|
||||||
for k, v in nv:
|
|
||||||
sys.stdout.write('{}: {}\n'.format(k, v))
|
|
||||||
|
|
||||||
def on_data(self, data):
|
|
||||||
sys.stdout.write('Stream#{}\n'.format(self.stream_id))
|
|
||||||
sys.stdout.buffer.write(data)
|
|
||||||
|
|
||||||
def on_close(self, status_code):
|
|
||||||
sys.stdout.write('Stream#{} closed\n'.format(self.stream_id))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
uris = sys.argv[1:]
|
|
||||||
spdylay.urlfetch(uris, MyStreamHandler)
|
|
1684
python/spdylay.pyx
1684
python/spdylay.pyx
File diff suppressed because it is too large
Load Diff
|
@ -1,345 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import io
|
|
||||||
import collections
|
|
||||||
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
class BufferList:
|
|
||||||
def __init__(self):
|
|
||||||
self.buffers = collections.deque()
|
|
||||||
|
|
||||||
def add_buffer(self, bytebuf):
|
|
||||||
self.buffers.append(bytebuf)
|
|
||||||
|
|
||||||
def get_bytes(self, length):
|
|
||||||
while self.buffers:
|
|
||||||
first = self.buffers[0]
|
|
||||||
data = first.read(length)
|
|
||||||
if data:
|
|
||||||
return data
|
|
||||||
else:
|
|
||||||
self.buffers.popleft()
|
|
||||||
return None
|
|
||||||
|
|
||||||
class IOBridge:
|
|
||||||
def __init__(self, inputs, outputs):
|
|
||||||
self.inputs = inputs
|
|
||||||
self.outputs = outputs
|
|
||||||
|
|
||||||
class Streams:
|
|
||||||
def __init__(self, iob):
|
|
||||||
self.iob = iob
|
|
||||||
self.streams = {}
|
|
||||||
self.recv_frames = []
|
|
||||||
self.recv_data = io.BytesIO()
|
|
||||||
|
|
||||||
def recv_cb(session, length):
|
|
||||||
iob = session.user_data.iob
|
|
||||||
return iob.inputs.get_bytes(length)
|
|
||||||
|
|
||||||
def send_cb(session, data):
|
|
||||||
iob = session.user_data.iob
|
|
||||||
iob.outputs.add_buffer(io.BytesIO(data))
|
|
||||||
return len(data)
|
|
||||||
|
|
||||||
def read_cb(session, stream_id, length, read_ctrl, source):
|
|
||||||
data = source.read(length)
|
|
||||||
if not data:
|
|
||||||
read_ctrl.flags = spdylay.READ_EOF
|
|
||||||
return data
|
|
||||||
|
|
||||||
def on_data_chunk_recv_cb(session, flags, stream_id, data):
|
|
||||||
session.user_data.recv_data.write(data)
|
|
||||||
|
|
||||||
def on_ctrl_recv_cb(session, frame):
|
|
||||||
session.user_data.recv_frames.append(frame)
|
|
||||||
|
|
||||||
class SpdylayTests(unittest.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
client_output = BufferList()
|
|
||||||
server_output = BufferList()
|
|
||||||
|
|
||||||
client_iob = IOBridge(server_output, client_output)
|
|
||||||
server_iob = IOBridge(client_output, server_output)
|
|
||||||
|
|
||||||
self.client_streams = Streams(client_iob)
|
|
||||||
self.server_streams = Streams(server_iob)
|
|
||||||
|
|
||||||
self.client_session = spdylay.Session(\
|
|
||||||
spdylay.CLIENT,
|
|
||||||
spdylay.PROTO_SPDY3,
|
|
||||||
user_data=self.client_streams,
|
|
||||||
recv_cb=recv_cb,
|
|
||||||
send_cb=send_cb,
|
|
||||||
on_ctrl_recv_cb=on_ctrl_recv_cb,
|
|
||||||
on_data_chunk_recv_cb=on_data_chunk_recv_cb)
|
|
||||||
|
|
||||||
self.server_session = spdylay.Session(\
|
|
||||||
spdylay.SERVER,
|
|
||||||
spdylay.PROTO_SPDY3,
|
|
||||||
user_data=self.server_streams,
|
|
||||||
recv_cb=recv_cb,
|
|
||||||
send_cb=send_cb,
|
|
||||||
on_ctrl_recv_cb=on_ctrl_recv_cb,
|
|
||||||
on_data_chunk_recv_cb=on_data_chunk_recv_cb)
|
|
||||||
|
|
||||||
def test_submit_request_and_response(self):
|
|
||||||
data_prd = spdylay.DataProvider(io.BytesIO(b'Hello World'), read_cb)
|
|
||||||
self.client_session.submit_request(0, [(u':method', u'POST')],
|
|
||||||
data_prd=data_prd,
|
|
||||||
stream_user_data=data_prd)
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual(0, frame.assoc_stream_id)
|
|
||||||
self.assertEqual(0, frame.pri)
|
|
||||||
self.assertEqual((u':method', u'POST'), frame.nv[0])
|
|
||||||
|
|
||||||
self.assertEqual(b'Hello World',
|
|
||||||
self.server_streams.recv_data.getvalue())
|
|
||||||
|
|
||||||
self.assertEqual(data_prd, self.client_session.get_stream_user_data(1))
|
|
||||||
|
|
||||||
data_prd = spdylay.DataProvider(io.BytesIO(b'Foo the bar'), read_cb)
|
|
||||||
self.server_session.submit_response(1, [(u':status', u'200 OK')],
|
|
||||||
data_prd=data_prd)
|
|
||||||
self.server_session.send()
|
|
||||||
self.client_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.client_streams.recv_frames))
|
|
||||||
frame = self.client_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_REPLY, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual((u':status', u'200 OK'), frame.nv[0])
|
|
||||||
|
|
||||||
self.assertEqual(b'Foo the bar',
|
|
||||||
self.client_streams.recv_data.getvalue())
|
|
||||||
|
|
||||||
def test_submit_syn_stream_and_syn_stream(self):
|
|
||||||
self.client_session.submit_syn_stream(spdylay.CTRL_FLAG_FIN, 2,
|
|
||||||
[(u':path', u'/')])
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual(0, frame.assoc_stream_id)
|
|
||||||
self.assertEqual(2, frame.pri)
|
|
||||||
self.assertEqual((u':path', u'/'), frame.nv[0])
|
|
||||||
|
|
||||||
self.server_session.submit_syn_reply(spdylay.CTRL_FLAG_FIN, 1,
|
|
||||||
[(u':version', u'HTTP/1.1')])
|
|
||||||
self.server_session.send()
|
|
||||||
self.client_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.client_streams.recv_frames))
|
|
||||||
frame = self.client_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_REPLY, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual((u':version', u'HTTP/1.1'), frame.nv[0])
|
|
||||||
|
|
||||||
def test_submit_rst_stream(self):
|
|
||||||
self.client_session.submit_syn_stream(spdylay.CTRL_FLAG_FIN, 2,
|
|
||||||
[(u':path', u'/')])
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.server_session.submit_rst_stream(1, spdylay.PROTOCOL_ERROR)
|
|
||||||
self.server_session.send()
|
|
||||||
self.client_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.client_streams.recv_frames))
|
|
||||||
frame = self.client_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.RST_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual(spdylay.PROTOCOL_ERROR, frame.status_code)
|
|
||||||
|
|
||||||
def test_submit_goaway(self):
|
|
||||||
self.client_session.submit_goaway(spdylay.GOAWAY_PROTOCOL_ERROR)
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.GOAWAY, frame.frame_type)
|
|
||||||
self.assertEqual(spdylay.GOAWAY_PROTOCOL_ERROR, frame.status_code)
|
|
||||||
|
|
||||||
def test_resume_data(self):
|
|
||||||
self.assertFalse(self.client_session.resume_data(1))
|
|
||||||
|
|
||||||
def test_get_pri_lowest(self):
|
|
||||||
self.assertEqual(7, self.client_session.get_pri_lowest())
|
|
||||||
|
|
||||||
def test_fail_session(self):
|
|
||||||
self.client_session.fail_session(spdylay.GOAWAY_PROTOCOL_ERROR)
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.GOAWAY, frame.frame_type)
|
|
||||||
self.assertEqual(spdylay.GOAWAY_PROTOCOL_ERROR, frame.status_code)
|
|
||||||
|
|
||||||
self.assertFalse(self.client_session.want_read())
|
|
||||||
self.assertFalse(self.client_session.want_write())
|
|
||||||
|
|
||||||
def test_deferred_data(self):
|
|
||||||
def deferred_read_cb(session, stream_id, length, read_ctrl, source):
|
|
||||||
return spdylay.ERR_DEFERRED
|
|
||||||
|
|
||||||
data_prd = spdylay.DataProvider(io.BytesIO(b'Hello World'),
|
|
||||||
deferred_read_cb)
|
|
||||||
self.client_session.submit_request(0, [(u':method', u'POST')],
|
|
||||||
data_prd=data_prd,
|
|
||||||
stream_user_data=data_prd)
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual(0, frame.assoc_stream_id)
|
|
||||||
self.assertEqual(0, frame.pri)
|
|
||||||
self.assertEqual((u':method', u'POST'), frame.nv[0])
|
|
||||||
|
|
||||||
self.assertEqual(b'', self.server_streams.recv_data.getvalue())
|
|
||||||
|
|
||||||
data_prd.read_cb = read_cb
|
|
||||||
|
|
||||||
self.client_session.resume_data(1)
|
|
||||||
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(b'Hello World',
|
|
||||||
self.server_streams.recv_data.getvalue())
|
|
||||||
|
|
||||||
def test_recv_cb_eof(self):
|
|
||||||
def eof_recv_cb(session, length):
|
|
||||||
raise spdylay.EOFError()
|
|
||||||
|
|
||||||
self.client_session = spdylay.Session(\
|
|
||||||
spdylay.CLIENT,
|
|
||||||
spdylay.PROTO_SPDY3,
|
|
||||||
user_data=self.client_streams,
|
|
||||||
recv_cb=eof_recv_cb)
|
|
||||||
|
|
||||||
with self.assertRaises(spdylay.EOFError):
|
|
||||||
self.client_session.recv()
|
|
||||||
|
|
||||||
def test_recv_cb_callback_failure(self):
|
|
||||||
def cbfail_recv_cb(session, length):
|
|
||||||
raise spdylay.CallbackFailureError()
|
|
||||||
|
|
||||||
self.client_session = spdylay.Session(\
|
|
||||||
spdylay.CLIENT,
|
|
||||||
spdylay.PROTO_SPDY3,
|
|
||||||
user_data=self.client_streams,
|
|
||||||
recv_cb=cbfail_recv_cb)
|
|
||||||
|
|
||||||
with self.assertRaises(spdylay.CallbackFailureError):
|
|
||||||
self.client_session.recv()
|
|
||||||
|
|
||||||
def test_send_cb_callback_failure(self):
|
|
||||||
def cbfail_send_cb(session, data):
|
|
||||||
raise spdylay.CallbackFailureError()
|
|
||||||
|
|
||||||
self.client_session = spdylay.Session(\
|
|
||||||
spdylay.CLIENT,
|
|
||||||
spdylay.PROTO_SPDY3,
|
|
||||||
user_data=self.client_streams,
|
|
||||||
send_cb=cbfail_send_cb)
|
|
||||||
|
|
||||||
self.client_session.submit_goaway(spdylay.GOAWAY_OK)
|
|
||||||
|
|
||||||
with self.assertRaises(spdylay.CallbackFailureError):
|
|
||||||
self.client_session.send()
|
|
||||||
|
|
||||||
def test_submit_data(self):
|
|
||||||
self.client_session.submit_syn_stream(spdylay.CTRL_FLAG_NONE, 2,
|
|
||||||
[(u':path', u'/')])
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
|
|
||||||
data_prd = spdylay.DataProvider(io.BytesIO(b'Hello World'), read_cb)
|
|
||||||
self.client_session.submit_data(1, spdylay.DATA_FLAG_FIN, data_prd)
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(b'Hello World',
|
|
||||||
self.server_streams.recv_data.getvalue())
|
|
||||||
|
|
||||||
def test_submit_headers(self):
|
|
||||||
self.client_session.submit_syn_stream(spdylay.CTRL_FLAG_NONE, 2,
|
|
||||||
[(u':path', u'/')])
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
|
|
||||||
self.client_session.submit_headers(spdylay.CTRL_FLAG_FIN, 1,
|
|
||||||
[(u':host', u'localhost')])
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(2, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[1]
|
|
||||||
self.assertEqual(spdylay.HEADERS, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual((u':host', u'localhost'), frame.nv[0])
|
|
||||||
|
|
||||||
def test_submit_ping(self):
|
|
||||||
self.client_session.submit_ping()
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.PING, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.unique_id)
|
|
||||||
|
|
||||||
def test_submit_window_update(self):
|
|
||||||
self.client_session.submit_syn_stream(spdylay.CTRL_FLAG_NONE, 2,
|
|
||||||
[(u':path', u'/')])
|
|
||||||
self.client_session.send()
|
|
||||||
self.server_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.server_streams.recv_frames))
|
|
||||||
frame = self.server_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.SYN_STREAM, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
|
|
||||||
self.server_session.submit_window_update(1, 4096)
|
|
||||||
self.server_session.send()
|
|
||||||
self.client_session.recv()
|
|
||||||
|
|
||||||
self.assertEqual(1, len(self.client_streams.recv_frames))
|
|
||||||
frame = self.client_streams.recv_frames[0]
|
|
||||||
self.assertEqual(spdylay.WINDOW_UPDATE, frame.frame_type)
|
|
||||||
self.assertEqual(1, frame.stream_id)
|
|
||||||
self.assertEqual(4096, frame.delta_window_size)
|
|
||||||
|
|
||||||
def test_get_npn_protocols(self):
|
|
||||||
protos = spdylay.get_npn_protocols()
|
|
||||||
self.assertEqual(['spdy/3', 'spdy/2'], protos)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
|
@ -1,43 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# The example SPDY server. Python 3.3 or later is required because TLS
|
|
||||||
# NPN is used in spdylay.ThreadedSPDYServer. Put private key and
|
|
||||||
# certificate file in the current working directory.
|
|
||||||
|
|
||||||
import spdylay
|
|
||||||
|
|
||||||
# private key file
|
|
||||||
KEY_FILE='server.key'
|
|
||||||
# certificate file
|
|
||||||
CERT_FILE='server.crt'
|
|
||||||
|
|
||||||
class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler):
|
|
||||||
|
|
||||||
def do_GET(self):
|
|
||||||
if self.path == '/notfound':
|
|
||||||
# Example code to return error
|
|
||||||
self.send_error(404)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.send_response(200)
|
|
||||||
self.send_header('content-type', 'text/html; charset=UTF-8')
|
|
||||||
|
|
||||||
content = '''\
|
|
||||||
<html>
|
|
||||||
<head><title>SPDY FTW</title></head>
|
|
||||||
<body>
|
|
||||||
<h1>SPDY FTW</h1>
|
|
||||||
<p>The age of HTTP/1.1 is over. The time of SPDY has come.</p>
|
|
||||||
</body>
|
|
||||||
</html>'''.encode('UTF-8')
|
|
||||||
|
|
||||||
self.wfile.write(content)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
HOST, PORT = "localhost", 3000
|
|
||||||
|
|
||||||
server = spdylay.ThreadedSPDYServer((HOST, PORT),
|
|
||||||
MySPDYRequestHandler,
|
|
||||||
cert_file=CERT_FILE,
|
|
||||||
key_file=KEY_FILE)
|
|
||||||
server.start()
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef EVENT_POLL_H
|
#ifndef EVENT_POLL_H
|
||||||
#define EVENT_POLL_H
|
#define EVENT_POLL_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#ifdef HAVE_EPOLL
|
#ifdef HAVE_EPOLL
|
||||||
# include "EventPoll_epoll.h"
|
# include "EventPoll_epoll.h"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,9 +25,9 @@
|
||||||
#ifndef EVENT_POLL_EVENT_H
|
#ifndef EVENT_POLL_EVENT_H
|
||||||
#define EVENT_POLL_EVENT_H
|
#define EVENT_POLL_EVENT_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
enum EventPollEvent {
|
enum EventPollEvent {
|
||||||
EP_POLLIN = 1,
|
EP_POLLIN = 1,
|
||||||
|
@ -41,6 +41,6 @@ enum EventPollOp {
|
||||||
EP_MOD
|
EP_MOD
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // EVENT_POLL_EVENT_H
|
#endif // EVENT_POLL_EVENT_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
EventPoll::EventPoll(size_t max_events)
|
EventPoll::EventPoll(size_t max_events)
|
||||||
: max_events_(max_events), num_events_(0)
|
: max_events_(max_events), num_events_(0)
|
||||||
|
@ -113,4 +113,4 @@ int EventPoll::ctl_event(int op, int fd, int events, void *user_data)
|
||||||
return update_event(epfd_, op, fd, events, user_data);
|
return update_event(epfd_, op, fd, events, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef EVENT_POLL_EPOLL_H
|
#ifndef EVENT_POLL_EPOLL_H
|
||||||
#define EVENT_POLL_EPOLL_H
|
#define EVENT_POLL_EPOLL_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
#include "EventPollEvent.h"
|
#include "EventPollEvent.h"
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
class EventPoll {
|
class EventPoll {
|
||||||
public:
|
public:
|
||||||
|
@ -57,6 +57,6 @@ private:
|
||||||
size_t num_events_;
|
size_t num_events_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // EVENT_POLL_EPOLL_H
|
#endif // EVENT_POLL_EPOLL_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
# define PTR_TO_UDATA(X) (X)
|
# define PTR_TO_UDATA(X) (X)
|
||||||
#endif // !KEVENT_UDATA_INTPTR_T
|
#endif // !KEVENT_UDATA_INTPTR_T
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
EventPoll::EventPoll(size_t max_events)
|
EventPoll::EventPoll(size_t max_events)
|
||||||
: max_events_(max_events), num_events_(0)
|
: max_events_(max_events), num_events_(0)
|
||||||
|
@ -116,4 +116,4 @@ int EventPoll::ctl_event(int op, int fd, int events, void *user_data)
|
||||||
return update_event(kq_, fd, events, user_data);
|
return update_event(kq_, fd, events, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef EVENT_POLL_KQUEUE_H
|
#ifndef EVENT_POLL_KQUEUE_H
|
||||||
#define EVENT_POLL_KQUEUE_H
|
#define EVENT_POLL_KQUEUE_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
#include "EventPollEvent.h"
|
#include "EventPollEvent.h"
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
class EventPoll {
|
class EventPoll {
|
||||||
public:
|
public:
|
||||||
|
@ -59,6 +59,6 @@ private:
|
||||||
size_t num_events_;
|
size_t num_events_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // EVENT_POLL_KQUEUE_H
|
#endif // EVENT_POLL_KQUEUE_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
ParserData::ParserData(const std::string& base_uri)
|
ParserData::ParserData(const std::string& base_uri)
|
||||||
: base_uri(base_uri)
|
: base_uri(base_uri)
|
||||||
|
@ -174,4 +174,4 @@ void HtmlParser::clear_links()
|
||||||
parser_data_.links.clear();
|
parser_data_.links.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef HTML_PARSER_H
|
#ifndef HTML_PARSER_H
|
||||||
#define HTML_PARSER_H
|
#define HTML_PARSER_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
#include <libxml/HTMLparser.h>
|
#include <libxml/HTMLparser.h>
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
struct ParserData {
|
struct ParserData {
|
||||||
std::string base_uri;
|
std::string base_uri;
|
||||||
|
@ -57,11 +57,11 @@ private:
|
||||||
ParserData parser_data_;
|
ParserData parser_data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#else // !HAVE_LIBXML2
|
#else // !HAVE_LIBXML2
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
class HtmlParser {
|
class HtmlParser {
|
||||||
public:
|
public:
|
||||||
|
@ -74,7 +74,7 @@ private:
|
||||||
std::vector<std::string> links_;
|
std::vector<std::string> links_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // !HAVE_LIBXML2
|
#endif // !HAVE_LIBXML2
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Spdylay - SPDY Library
|
# nghttp2 - HTTP/2.0 C Library
|
||||||
|
|
||||||
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
# Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
|
||||||
@OPENSSL_CFLAGS@ @XML_CPPFLAGS@ @LIBEVENT_OPENSSL_CFLAGS@ @DEFS@
|
@OPENSSL_CFLAGS@ @XML_CPPFLAGS@ @LIBEVENT_OPENSSL_CFLAGS@ @DEFS@
|
||||||
AM_LDFLAGS = @OPENSSL_LIBS@ @XML_LIBS@ @LIBEVENT_OPENSSL_LIBS@ @SRC_LIBS@
|
AM_LDFLAGS = @OPENSSL_LIBS@ @XML_LIBS@ @LIBEVENT_OPENSSL_LIBS@ @SRC_LIBS@
|
||||||
|
|
||||||
LDADD = $(top_builddir)/lib/libspdylay.la
|
LDADD = $(top_builddir)/lib/libnghttp2.la
|
||||||
|
|
||||||
bin_PROGRAMS += spdycat
|
bin_PROGRAMS += spdycat
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ if HAVE_LIBEVENT_OPENSSL
|
||||||
bin_PROGRAMS += shrpx
|
bin_PROGRAMS += shrpx
|
||||||
endif # HAVE_LIBEVENT_OPENSSL
|
endif # HAVE_LIBEVENT_OPENSSL
|
||||||
|
|
||||||
HELPER_OBJECTS = util.cc timegm.c spdylay_ssl.cc
|
HELPER_OBJECTS = util.cc timegm.c nghttp2_ssl.cc
|
||||||
HELPER_HFILES = util.h timegm.h spdylay_ssl.h spdylay_config.h
|
HELPER_HFILES = util.h timegm.h nghttp2_ssl.h nghttp2_config.h
|
||||||
|
|
||||||
EVENT_OBJECTS =
|
EVENT_OBJECTS =
|
||||||
EVENT_HFILES = EventPoll.h EventPollEvent.h
|
EVENT_HFILES = EventPoll.h EventPollEvent.h
|
||||||
|
@ -114,7 +114,7 @@ shrpx_unittest_SOURCES = shrpx-unittest.cc \
|
||||||
shrpx_ssl_test.cc shrpx_ssl_test.h\
|
shrpx_ssl_test.cc shrpx_ssl_test.h\
|
||||||
${SHRPX_SRCS}
|
${SHRPX_SRCS}
|
||||||
shrpx_unittest_CPPFLAGS = ${AM_CPPFLAGS}\
|
shrpx_unittest_CPPFLAGS = ${AM_CPPFLAGS}\
|
||||||
-DSPDYLAY_TESTS_DIR=\"$(top_srcdir)/tests\"
|
-DNGHTTP2_TESTS_DIR=\"$(top_srcdir)/tests\"
|
||||||
shrpx_unittest_LDFLAGS = -static @OPENSSL_LIBS@ @LIBEVENT_OPENSSL_LIBS@\
|
shrpx_unittest_LDFLAGS = -static @OPENSSL_LIBS@ @LIBEVENT_OPENSSL_LIBS@\
|
||||||
@SRC_LIBS@ @CUNIT_LIBS@ @TESTS_LIBS@
|
@SRC_LIBS@ @CUNIT_LIBS@ @TESTS_LIBS@
|
||||||
TESTS += shrpx-unittest
|
TESTS += shrpx-unittest
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "spdylay_ssl.h"
|
#include "nghttp2_ssl.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "EventPoll.h"
|
#include "EventPoll.h"
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
# define O_BINARY (0)
|
# define O_BINARY (0)
|
||||||
#endif // O_BINARY
|
#endif // O_BINARY
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Config config;
|
Config config;
|
||||||
|
@ -56,7 +56,7 @@ const std::string STATUS_304 = "304 Not Modified";
|
||||||
const std::string STATUS_400 = "400 Bad Request";
|
const std::string STATUS_400 = "400 Bad Request";
|
||||||
const std::string STATUS_404 = "404 Not Found";
|
const std::string STATUS_404 = "404 Not Found";
|
||||||
const std::string DEFAULT_HTML = "index.html";
|
const std::string DEFAULT_HTML = "index.html";
|
||||||
const std::string SPDYD_SERVER = "spdyd spdylay/" SPDYLAY_VERSION;
|
const std::string SPDYD_SERVER = "spdyd nghttp2/" NGHTTP2_VERSION;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Config::Config(): verbose(false), daemon(false), port(0),
|
Config::Config(): verbose(false), daemon(false), port(0),
|
||||||
|
@ -176,20 +176,20 @@ void on_session_closed(EventHandler *hd, int64_t session_id)
|
||||||
SpdyEventHandler::SpdyEventHandler(const Config* config,
|
SpdyEventHandler::SpdyEventHandler(const Config* config,
|
||||||
int fd, SSL *ssl,
|
int fd, SSL *ssl,
|
||||||
uint16_t version,
|
uint16_t version,
|
||||||
const spdylay_session_callbacks *callbacks,
|
const nghttp2_session_callbacks *callbacks,
|
||||||
int64_t session_id)
|
int64_t session_id)
|
||||||
: EventHandler(config),
|
: EventHandler(config),
|
||||||
fd_(fd), ssl_(ssl), version_(version), session_id_(session_id),
|
fd_(fd), ssl_(ssl), version_(version), session_id_(session_id),
|
||||||
io_flags_(0)
|
io_flags_(0)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
r = spdylay_session_server_new(&session_, version, callbacks, this);
|
r = nghttp2_session_server_new(&session_, version, callbacks, this);
|
||||||
assert(r == 0);
|
assert(r == 0);
|
||||||
spdylay_settings_entry entry;
|
nghttp2_settings_entry entry;
|
||||||
entry.settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS;
|
entry.settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
||||||
entry.value = SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS;
|
entry.value = NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS;
|
||||||
entry.flags = SPDYLAY_ID_FLAG_SETTINGS_NONE;
|
entry.flags = NGHTTP2_ID_FLAG_SETTINGS_NONE;
|
||||||
r = spdylay_submit_settings(session_, SPDYLAY_FLAG_SETTINGS_NONE,
|
r = nghttp2_submit_settings(session_, NGHTTP2_FLAG_SETTINGS_NONE,
|
||||||
&entry, 1);
|
&entry, 1);
|
||||||
assert(r == 0);
|
assert(r == 0);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ SpdyEventHandler::SpdyEventHandler(const Config* config,
|
||||||
SpdyEventHandler::~SpdyEventHandler()
|
SpdyEventHandler::~SpdyEventHandler()
|
||||||
{
|
{
|
||||||
on_session_closed(this, session_id_);
|
on_session_closed(this, session_id_);
|
||||||
spdylay_session_del(session_);
|
nghttp2_session_del(session_);
|
||||||
for(std::map<int32_t, Request*>::iterator i = id2req_.begin(),
|
for(std::map<int32_t, Request*>::iterator i = id2req_.begin(),
|
||||||
eoi = id2req_.end(); i != eoi; ++i) {
|
eoi = id2req_.end(); i != eoi; ++i) {
|
||||||
delete (*i).second;
|
delete (*i).second;
|
||||||
|
@ -218,21 +218,21 @@ uint16_t SpdyEventHandler::version() const
|
||||||
int SpdyEventHandler::execute(Sessions *sessions)
|
int SpdyEventHandler::execute(Sessions *sessions)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
r = spdylay_session_recv(session_);
|
r = nghttp2_session_recv(session_);
|
||||||
if(r == 0) {
|
if(r == 0) {
|
||||||
r = spdylay_session_send(session_);
|
r = nghttp2_session_send(session_);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpdyEventHandler::want_read()
|
bool SpdyEventHandler::want_read()
|
||||||
{
|
{
|
||||||
return spdylay_session_want_read(session_) || (io_flags_ & WANT_READ);
|
return nghttp2_session_want_read(session_) || (io_flags_ & WANT_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpdyEventHandler::want_write()
|
bool SpdyEventHandler::want_write()
|
||||||
{
|
{
|
||||||
return spdylay_session_want_write(session_) || (io_flags_ & WANT_WRITE);
|
return nghttp2_session_want_write(session_) || (io_flags_ & WANT_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpdyEventHandler::fd() const
|
int SpdyEventHandler::fd() const
|
||||||
|
@ -242,8 +242,8 @@ int SpdyEventHandler::fd() const
|
||||||
|
|
||||||
bool SpdyEventHandler::finish()
|
bool SpdyEventHandler::finish()
|
||||||
{
|
{
|
||||||
return !spdylay_session_want_read(session_) &&
|
return !nghttp2_session_want_read(session_) &&
|
||||||
!spdylay_session_want_write(session_);
|
!nghttp2_session_want_write(session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SpdyEventHandler::send_data(const uint8_t *data, size_t len, int flags)
|
ssize_t SpdyEventHandler::send_data(const uint8_t *data, size_t len, int flags)
|
||||||
|
@ -293,7 +293,7 @@ int SpdyEventHandler::submit_file_response(const std::string& status,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
time_t last_modified,
|
time_t last_modified,
|
||||||
off_t file_length,
|
off_t file_length,
|
||||||
spdylay_data_provider *data_prd)
|
nghttp2_data_provider *data_prd)
|
||||||
{
|
{
|
||||||
std::string date_str = util::http_date(time(0));
|
std::string date_str = util::http_date(time(0));
|
||||||
std::string content_length = util::to_str(file_length);
|
std::string content_length = util::to_str(file_length);
|
||||||
|
@ -313,14 +313,14 @@ int SpdyEventHandler::submit_file_response(const std::string& status,
|
||||||
nv[12] = "last-modified";
|
nv[12] = "last-modified";
|
||||||
nv[13] = last_modified_str.c_str();
|
nv[13] = last_modified_str.c_str();
|
||||||
}
|
}
|
||||||
return spdylay_submit_response(session_, stream_id, nv, data_prd);
|
return nghttp2_submit_response(session_, stream_id, nv, data_prd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpdyEventHandler::submit_response
|
int SpdyEventHandler::submit_response
|
||||||
(const std::string& status,
|
(const std::string& status,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
const std::vector<std::pair<std::string, std::string> >& headers,
|
const std::vector<std::pair<std::string, std::string> >& headers,
|
||||||
spdylay_data_provider *data_prd)
|
nghttp2_data_provider *data_prd)
|
||||||
{
|
{
|
||||||
std::string date_str = util::http_date(time(0));
|
std::string date_str = util::http_date(time(0));
|
||||||
const char **nv = new const char*[8+headers.size()*2+1];
|
const char **nv = new const char*[8+headers.size()*2+1];
|
||||||
|
@ -337,14 +337,14 @@ int SpdyEventHandler::submit_response
|
||||||
nv[8+i*2+1] = headers[i].second.c_str();
|
nv[8+i*2+1] = headers[i].second.c_str();
|
||||||
}
|
}
|
||||||
nv[8+headers.size()*2] = 0;
|
nv[8+headers.size()*2] = 0;
|
||||||
int r = spdylay_submit_response(session_, stream_id, nv, data_prd);
|
int r = nghttp2_submit_response(session_, stream_id, nv, data_prd);
|
||||||
delete [] nv;
|
delete [] nv;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpdyEventHandler::submit_response(const std::string& status,
|
int SpdyEventHandler::submit_response(const std::string& status,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
spdylay_data_provider *data_prd)
|
nghttp2_data_provider *data_prd)
|
||||||
{
|
{
|
||||||
const char *nv[] = {
|
const char *nv[] = {
|
||||||
":status", status.c_str(),
|
":status", status.c_str(),
|
||||||
|
@ -352,7 +352,7 @@ int SpdyEventHandler::submit_response(const std::string& status,
|
||||||
"server", SPDYD_SERVER.c_str(),
|
"server", SPDYD_SERVER.c_str(),
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
return spdylay_submit_response(session_, stream_id, nv, data_prd);
|
return nghttp2_submit_response(session_, stream_id, nv, data_prd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpdyEventHandler::add_stream(int32_t stream_id, Request *req)
|
void SpdyEventHandler::add_stream(int32_t stream_id, Request *req)
|
||||||
|
@ -378,7 +378,7 @@ int64_t SpdyEventHandler::session_id() const
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
ssize_t hd_send_callback(spdylay_session *session,
|
ssize_t hd_send_callback(nghttp2_session *session,
|
||||||
const uint8_t *data, size_t len, int flags,
|
const uint8_t *data, size_t len, int flags,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -386,47 +386,47 @@ ssize_t hd_send_callback(spdylay_session *session,
|
||||||
ssize_t r = hd->send_data(data, len, flags);
|
ssize_t r = hd->send_data(data, len, flags);
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
if(hd->would_block()) {
|
if(hd->would_block()) {
|
||||||
r = SPDYLAY_ERR_WOULDBLOCK;
|
r = NGHTTP2_ERR_WOULDBLOCK;
|
||||||
} else {
|
} else {
|
||||||
r = SPDYLAY_ERR_CALLBACK_FAILURE;
|
r = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(r == 0) {
|
} else if(r == 0) {
|
||||||
// In OpenSSL, r == 0 means EOF because SSL_write may do read.
|
// In OpenSSL, r == 0 means EOF because SSL_write may do read.
|
||||||
r = SPDYLAY_ERR_CALLBACK_FAILURE;
|
r = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
ssize_t hd_recv_callback(spdylay_session *session,
|
ssize_t hd_recv_callback(nghttp2_session *session,
|
||||||
uint8_t *data, size_t len, int flags, void *user_data)
|
uint8_t *data, size_t len, int flags, void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
||||||
ssize_t r = hd->recv_data(data, len, flags);
|
ssize_t r = hd->recv_data(data, len, flags);
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
if(hd->would_block()) {
|
if(hd->would_block()) {
|
||||||
r = SPDYLAY_ERR_WOULDBLOCK;
|
r = NGHTTP2_ERR_WOULDBLOCK;
|
||||||
} else {
|
} else {
|
||||||
r = SPDYLAY_ERR_CALLBACK_FAILURE;
|
r = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(r == 0) {
|
} else if(r == 0) {
|
||||||
r = SPDYLAY_ERR_EOF;
|
r = NGHTTP2_ERR_EOF;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ssize_t file_read_callback
|
ssize_t file_read_callback
|
||||||
(spdylay_session *session, int32_t stream_id,
|
(nghttp2_session *session, int32_t stream_id,
|
||||||
uint8_t *buf, size_t length, int *eof,
|
uint8_t *buf, size_t length, int *eof,
|
||||||
spdylay_data_source *source, void *user_data)
|
nghttp2_data_source *source, void *user_data)
|
||||||
{
|
{
|
||||||
int fd = source->fd;
|
int fd = source->fd;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
while((r = read(fd, buf, length)) == -1 && errno == EINTR);
|
while((r = read(fd, buf, length)) == -1 && errno == EINTR);
|
||||||
if(r == -1) {
|
if(r == -1) {
|
||||||
return SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE;
|
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
if(r == 0) {
|
if(r == 0) {
|
||||||
*eof = 1;
|
*eof = 1;
|
||||||
|
@ -469,7 +469,7 @@ void prepare_status_response(Request *req, SpdyEventHandler *hd,
|
||||||
close(pipefd[1]);
|
close(pipefd[1]);
|
||||||
|
|
||||||
req->file = pipefd[0];
|
req->file = pipefd[0];
|
||||||
spdylay_data_provider data_prd;
|
nghttp2_data_provider data_prd;
|
||||||
data_prd.source.fd = pipefd[0];
|
data_prd.source.fd = pipefd[0];
|
||||||
data_prd.read_callback = file_read_callback;
|
data_prd.read_callback = file_read_callback;
|
||||||
std::vector<std::pair<std::string, std::string> > headers;
|
std::vector<std::pair<std::string, std::string> > headers;
|
||||||
|
@ -544,7 +544,7 @@ void prepare_response(Request *req, SpdyEventHandler *hd)
|
||||||
prepare_status_response(req, hd, STATUS_404);
|
prepare_status_response(req, hd, STATUS_404);
|
||||||
} else {
|
} else {
|
||||||
req->file = file;
|
req->file = file;
|
||||||
spdylay_data_provider data_prd;
|
nghttp2_data_provider data_prd;
|
||||||
data_prd.source.fd = file;
|
data_prd.source.fd = file;
|
||||||
data_prd.read_callback = file_read_callback;
|
data_prd.read_callback = file_read_callback;
|
||||||
if(last_mod_found && buf.st_mtime <= last_mod) {
|
if(last_mod_found && buf.st_mtime <= last_mod) {
|
||||||
|
@ -569,7 +569,7 @@ void append_nv(Request *req, char **nv)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void hd_on_ctrl_recv_callback
|
void hd_on_ctrl_recv_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
||||||
|
@ -578,14 +578,14 @@ void hd_on_ctrl_recv_callback
|
||||||
on_ctrl_recv_callback(session, type, frame, user_data);
|
on_ctrl_recv_callback(session, type, frame, user_data);
|
||||||
}
|
}
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SPDYLAY_SYN_STREAM: {
|
case NGHTTP2_SYN_STREAM: {
|
||||||
int32_t stream_id = frame->syn_stream.stream_id;
|
int32_t stream_id = frame->syn_stream.stream_id;
|
||||||
Request *req = new Request(stream_id);
|
Request *req = new Request(stream_id);
|
||||||
append_nv(req, frame->syn_stream.nv);
|
append_nv(req, frame->syn_stream.nv);
|
||||||
hd->add_stream(stream_id, req);
|
hd->add_stream(stream_id, req);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SPDYLAY_HEADERS: {
|
case NGHTTP2_HEADERS: {
|
||||||
int32_t stream_id = frame->headers.stream_id;
|
int32_t stream_id = frame->headers.stream_id;
|
||||||
Request *req = hd->get_stream(stream_id);
|
Request *req = hd->get_stream(stream_id);
|
||||||
append_nv(req, frame->headers.nv);
|
append_nv(req, frame->headers.nv);
|
||||||
|
@ -598,7 +598,7 @@ void hd_on_ctrl_recv_callback
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void htdocs_on_request_recv_callback
|
void htdocs_on_request_recv_callback
|
||||||
(spdylay_session *session, int32_t stream_id, void *user_data)
|
(nghttp2_session *session, int32_t stream_id, void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
||||||
prepare_response(hd->get_stream(stream_id), hd);
|
prepare_response(hd->get_stream(stream_id), hd);
|
||||||
|
@ -606,7 +606,7 @@ void htdocs_on_request_recv_callback
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void hd_on_ctrl_send_callback
|
void hd_on_ctrl_send_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
||||||
|
@ -619,7 +619,7 @@ void hd_on_ctrl_send_callback
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void on_data_chunk_recv_callback
|
void on_data_chunk_recv_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id,
|
||||||
const uint8_t *data, size_t len, void *user_data)
|
const uint8_t *data, size_t len, void *user_data)
|
||||||
{
|
{
|
||||||
// TODO Handle POST
|
// TODO Handle POST
|
||||||
|
@ -628,7 +628,7 @@ void on_data_chunk_recv_callback
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void hd_on_data_recv_callback
|
void hd_on_data_recv_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
// TODO Handle POST
|
// TODO Handle POST
|
||||||
|
@ -642,7 +642,7 @@ void hd_on_data_recv_callback
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void hd_on_data_send_callback
|
void hd_on_data_send_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
||||||
|
@ -655,7 +655,7 @@ void hd_on_data_send_callback
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void on_stream_close_callback
|
void on_stream_close_callback
|
||||||
(spdylay_session *session, int32_t stream_id, spdylay_status_code status_code,
|
(nghttp2_session *session, int32_t stream_id, nghttp2_status_code status_code,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
SpdyEventHandler *hd = (SpdyEventHandler*)user_data;
|
||||||
|
@ -670,9 +670,9 @@ void on_stream_close_callback
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void fill_callback(spdylay_session_callbacks& callbacks, const Config *config)
|
void fill_callback(nghttp2_session_callbacks& callbacks, const Config *config)
|
||||||
{
|
{
|
||||||
memset(&callbacks, 0, sizeof(spdylay_session_callbacks));
|
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||||
callbacks.send_callback = hd_send_callback;
|
callbacks.send_callback = hd_send_callback;
|
||||||
callbacks.recv_callback = hd_recv_callback;
|
callbacks.recv_callback = hd_recv_callback;
|
||||||
callbacks.on_stream_close_callback = on_stream_close_callback;
|
callbacks.on_stream_close_callback = on_stream_close_callback;
|
||||||
|
@ -725,7 +725,7 @@ public:
|
||||||
if(config()->verbose) {
|
if(config()->verbose) {
|
||||||
std::cout << "The negotiated next protocol: " << proto << std::endl;
|
std::cout << "The negotiated next protocol: " << proto << std::endl;
|
||||||
}
|
}
|
||||||
version_ = spdylay_npn_get_version(next_proto, next_proto_len);
|
version_ = nghttp2_npn_get_version(next_proto, next_proto_len);
|
||||||
if(config()->version != 0) {
|
if(config()->version != 0) {
|
||||||
if(config()->version != version_) {
|
if(config()->version != version_) {
|
||||||
version_ = 0;
|
version_ = 0;
|
||||||
|
@ -776,7 +776,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void add_next_handler(Sessions *sessions)
|
void add_next_handler(Sessions *sessions)
|
||||||
{
|
{
|
||||||
spdylay_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
fill_callback(callbacks, config());
|
fill_callback(callbacks, config());
|
||||||
SpdyEventHandler *hd = new SpdyEventHandler(config(),
|
SpdyEventHandler *hd = new SpdyEventHandler(config(),
|
||||||
fd_, ssl_, version_, &callbacks,
|
fd_, ssl_, version_, &callbacks,
|
||||||
|
@ -840,7 +840,7 @@ private:
|
||||||
{
|
{
|
||||||
int64_t session_id = ++(*session_id_seed_ptr_);
|
int64_t session_id = ++(*session_id_seed_ptr_);
|
||||||
if(config()->no_tls) {
|
if(config()->no_tls) {
|
||||||
spdylay_session_callbacks callbacks;
|
nghttp2_session_callbacks callbacks;
|
||||||
fill_callback(callbacks, config());
|
fill_callback(callbacks, config());
|
||||||
SpdyEventHandler *hd = new SpdyEventHandler(config(),
|
SpdyEventHandler *hd = new SpdyEventHandler(config(),
|
||||||
cfd, 0,
|
cfd, 0,
|
||||||
|
@ -985,11 +985,11 @@ int SpdyServer::run()
|
||||||
memcpy(&proto_list[8], "spdy/2", 6);
|
memcpy(&proto_list[8], "spdy/2", 6);
|
||||||
|
|
||||||
switch(config_->version) {
|
switch(config_->version) {
|
||||||
case SPDYLAY_PROTO_SPDY3:
|
case NGHTTP2_PROTO_SPDY3:
|
||||||
next_proto.first = proto_list;
|
next_proto.first = proto_list;
|
||||||
next_proto.second = 7;
|
next_proto.second = 7;
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_PROTO_SPDY2:
|
case NGHTTP2_PROTO_SPDY2:
|
||||||
next_proto.first = proto_list+7;
|
next_proto.first = proto_list+7;
|
||||||
next_proto.second = 7;
|
next_proto.second = 7;
|
||||||
break;
|
break;
|
||||||
|
@ -1070,4 +1070,4 @@ int SpdyServer::run()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#ifndef SPDY_SERVER_H
|
#ifndef SPDY_SERVER_H
|
||||||
#define SPDY_SERVER_H
|
#define SPDY_SERVER_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -38,9 +38,9 @@
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
std::string htdocs;
|
std::string htdocs;
|
||||||
|
@ -50,7 +50,7 @@ struct Config {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
std::string private_key_file;
|
std::string private_key_file;
|
||||||
std::string cert_file;
|
std::string cert_file;
|
||||||
spdylay_on_request_recv_callback on_request_recv_callback;
|
nghttp2_on_request_recv_callback on_request_recv_callback;
|
||||||
void *data_ptr;
|
void *data_ptr;
|
||||||
uint16_t version;
|
uint16_t version;
|
||||||
bool verify_client;
|
bool verify_client;
|
||||||
|
@ -99,7 +99,7 @@ class SpdyEventHandler : public EventHandler {
|
||||||
public:
|
public:
|
||||||
SpdyEventHandler(const Config* config,
|
SpdyEventHandler(const Config* config,
|
||||||
int fd, SSL *ssl, uint16_t version,
|
int fd, SSL *ssl, uint16_t version,
|
||||||
const spdylay_session_callbacks *callbacks,
|
const nghttp2_session_callbacks *callbacks,
|
||||||
int64_t session_id);
|
int64_t session_id);
|
||||||
virtual ~SpdyEventHandler();
|
virtual ~SpdyEventHandler();
|
||||||
virtual int execute(Sessions *sessions);
|
virtual int execute(Sessions *sessions);
|
||||||
|
@ -120,24 +120,24 @@ public:
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
time_t last_modified,
|
time_t last_modified,
|
||||||
off_t file_length,
|
off_t file_length,
|
||||||
spdylay_data_provider *data_prd);
|
nghttp2_data_provider *data_prd);
|
||||||
|
|
||||||
int submit_response(const std::string& status,
|
int submit_response(const std::string& status,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
spdylay_data_provider *data_prd);
|
nghttp2_data_provider *data_prd);
|
||||||
|
|
||||||
int submit_response
|
int submit_response
|
||||||
(const std::string& status,
|
(const std::string& status,
|
||||||
int32_t stream_id,
|
int32_t stream_id,
|
||||||
const std::vector<std::pair<std::string, std::string> >& headers,
|
const std::vector<std::pair<std::string, std::string> >& headers,
|
||||||
spdylay_data_provider *data_prd);
|
nghttp2_data_provider *data_prd);
|
||||||
|
|
||||||
void add_stream(int32_t stream_id, Request *req);
|
void add_stream(int32_t stream_id, Request *req);
|
||||||
void remove_stream(int32_t stream_id);
|
void remove_stream(int32_t stream_id);
|
||||||
Request* get_stream(int32_t stream_id);
|
Request* get_stream(int32_t stream_id);
|
||||||
int64_t session_id() const;
|
int64_t session_id() const;
|
||||||
private:
|
private:
|
||||||
spdylay_session *session_;
|
nghttp2_session *session_;
|
||||||
int fd_;
|
int fd_;
|
||||||
SSL* ssl_;
|
SSL* ssl_;
|
||||||
uint16_t version_;
|
uint16_t version_;
|
||||||
|
@ -158,13 +158,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
void htdocs_on_request_recv_callback
|
void htdocs_on_request_recv_callback
|
||||||
(spdylay_session *session, int32_t stream_id, void *user_data);
|
(nghttp2_session *session, int32_t stream_id, void *user_data);
|
||||||
|
|
||||||
ssize_t file_read_callback
|
ssize_t file_read_callback
|
||||||
(spdylay_session *session, int32_t stream_id,
|
(nghttp2_session *session, int32_t stream_id,
|
||||||
uint8_t *buf, size_t length, int *eof,
|
uint8_t *buf, size_t length, int *eof,
|
||||||
spdylay_data_source *source, void *user_data);
|
nghttp2_data_source *source, void *user_data);
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // SPDY_SERVER_H
|
#endif // SPDY_SERVER_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
namespace base64 {
|
namespace base64 {
|
||||||
|
|
||||||
|
@ -174,6 +174,6 @@ std::string decode(InputIterator first, InputIterator last)
|
||||||
|
|
||||||
} // namespace base64
|
} // namespace base64
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // BASE64_H
|
#endif // BASE64_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,11 +22,11 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_CONFIG_H
|
#ifndef NGHTTP2_CONFIG_H
|
||||||
#define SPDYLAY_CONFIG_H
|
#define NGHTTP2_CONFIG_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif // HAVE_CONFIG_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
#endif // SPDYLAY_CONFIG_H
|
#endif // NGHTTP2_CONFIG_H
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -43,36 +43,36 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "spdylay_ssl.h"
|
#include "nghttp2_ssl.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
bool ssl_debug = false;
|
bool ssl_debug = false;
|
||||||
|
|
||||||
Spdylay::Spdylay(int fd, SSL *ssl, uint16_t version,
|
Spdylay::Spdylay(int fd, SSL *ssl, uint16_t version,
|
||||||
const spdylay_session_callbacks *callbacks,
|
const nghttp2_session_callbacks *callbacks,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
: fd_(fd), ssl_(ssl), version_(version), user_data_(user_data),
|
: fd_(fd), ssl_(ssl), version_(version), user_data_(user_data),
|
||||||
io_flags_(0)
|
io_flags_(0)
|
||||||
{
|
{
|
||||||
int r = spdylay_session_client_new(&session_, version_, callbacks, this);
|
int r = nghttp2_session_client_new(&session_, version_, callbacks, this);
|
||||||
assert(r == 0);
|
assert(r == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Spdylay::~Spdylay()
|
Spdylay::~Spdylay()
|
||||||
{
|
{
|
||||||
spdylay_session_del(session_);
|
nghttp2_session_del(session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Spdylay::recv()
|
int Spdylay::recv()
|
||||||
{
|
{
|
||||||
return spdylay_session_recv(session_);
|
return nghttp2_session_recv(session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Spdylay::send()
|
int Spdylay::send()
|
||||||
{
|
{
|
||||||
return spdylay_session_send(session_);
|
return nghttp2_session_send(session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Spdylay::send_data(const uint8_t *data, size_t len, int flags)
|
ssize_t Spdylay::send_data(const uint8_t *data, size_t len, int flags)
|
||||||
|
@ -115,18 +115,18 @@ ssize_t Spdylay::recv_data(uint8_t *data, size_t len, int flags)
|
||||||
|
|
||||||
bool Spdylay::want_read()
|
bool Spdylay::want_read()
|
||||||
{
|
{
|
||||||
return spdylay_session_want_read(session_) || (io_flags_ & WANT_READ);
|
return nghttp2_session_want_read(session_) || (io_flags_ & WANT_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Spdylay::want_write()
|
bool Spdylay::want_write()
|
||||||
{
|
{
|
||||||
return spdylay_session_want_write(session_) || (io_flags_ & WANT_WRITE);
|
return nghttp2_session_want_write(session_) || (io_flags_ & WANT_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Spdylay::finish()
|
bool Spdylay::finish()
|
||||||
{
|
{
|
||||||
return !spdylay_session_want_read(session_) &&
|
return !nghttp2_session_want_read(session_) &&
|
||||||
!spdylay_session_want_write(session_);
|
!nghttp2_session_want_write(session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Spdylay::fd() const
|
int Spdylay::fd() const
|
||||||
|
@ -144,7 +144,7 @@ int Spdylay::submit_request(const std::string& scheme,
|
||||||
const std::string& path,
|
const std::string& path,
|
||||||
const std::map<std::string,std::string> &headers,
|
const std::map<std::string,std::string> &headers,
|
||||||
uint8_t pri,
|
uint8_t pri,
|
||||||
const spdylay_data_provider *data_prd,
|
const nghttp2_data_provider *data_prd,
|
||||||
int64_t data_length,
|
int64_t data_length,
|
||||||
void *stream_user_data)
|
void *stream_user_data)
|
||||||
{
|
{
|
||||||
|
@ -167,7 +167,7 @@ int Spdylay::submit_request(const std::string& scheme,
|
||||||
":host", hostport.c_str(),
|
":host", hostport.c_str(),
|
||||||
"accept", "*/*",
|
"accept", "*/*",
|
||||||
"accept-encoding", "gzip, deflate",
|
"accept-encoding", "gzip, deflate",
|
||||||
"user-agent", "spdylay/" SPDYLAY_VERSION
|
"user-agent", "nghttp2/" NGHTTP2_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
int hardcoded_entry_count = sizeof(static_nv) / sizeof(*static_nv);
|
int hardcoded_entry_count = sizeof(static_nv) / sizeof(*static_nv);
|
||||||
|
@ -215,7 +215,7 @@ int Spdylay::submit_request(const std::string& scheme,
|
||||||
}
|
}
|
||||||
nv[pos] = NULL;
|
nv[pos] = NULL;
|
||||||
|
|
||||||
int r = spdylay_submit_request(session_, pri, nv, data_prd,
|
int r = nghttp2_submit_request(session_, pri, nv, data_prd,
|
||||||
stream_user_data);
|
stream_user_data);
|
||||||
|
|
||||||
delete [] nv;
|
delete [] nv;
|
||||||
|
@ -223,9 +223,9 @@ int Spdylay::submit_request(const std::string& scheme,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Spdylay::submit_settings(int flags, spdylay_settings_entry *iv, size_t niv)
|
int Spdylay::submit_settings(int flags, nghttp2_settings_entry *iv, size_t niv)
|
||||||
{
|
{
|
||||||
return spdylay_submit_settings(session_, flags, iv, niv);
|
return nghttp2_submit_settings(session_, flags, iv, niv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Spdylay::would_block()
|
bool Spdylay::would_block()
|
||||||
|
@ -419,7 +419,7 @@ int set_tcp_nodelay(int fd)
|
||||||
return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, (socklen_t)sizeof(val));
|
return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, (socklen_t)sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_callback(spdylay_session *session,
|
ssize_t send_callback(nghttp2_session *session,
|
||||||
const uint8_t *data, size_t len, int flags,
|
const uint8_t *data, size_t len, int flags,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -427,30 +427,30 @@ ssize_t send_callback(spdylay_session *session,
|
||||||
ssize_t r = sc->send_data(data, len, flags);
|
ssize_t r = sc->send_data(data, len, flags);
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
if(sc->would_block()) {
|
if(sc->would_block()) {
|
||||||
r = SPDYLAY_ERR_WOULDBLOCK;
|
r = NGHTTP2_ERR_WOULDBLOCK;
|
||||||
} else {
|
} else {
|
||||||
r = SPDYLAY_ERR_CALLBACK_FAILURE;
|
r = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(r == 0) {
|
} else if(r == 0) {
|
||||||
// In OpenSSL, r == 0 means EOF because SSL_write may do read.
|
// In OpenSSL, r == 0 means EOF because SSL_write may do read.
|
||||||
r = SPDYLAY_ERR_CALLBACK_FAILURE;
|
r = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t recv_callback(spdylay_session *session,
|
ssize_t recv_callback(nghttp2_session *session,
|
||||||
uint8_t *data, size_t len, int flags, void *user_data)
|
uint8_t *data, size_t len, int flags, void *user_data)
|
||||||
{
|
{
|
||||||
Spdylay *sc = (Spdylay*)user_data;
|
Spdylay *sc = (Spdylay*)user_data;
|
||||||
ssize_t r = sc->recv_data(data, len, flags);
|
ssize_t r = sc->recv_data(data, len, flags);
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
if(sc->would_block()) {
|
if(sc->would_block()) {
|
||||||
r = SPDYLAY_ERR_WOULDBLOCK;
|
r = NGHTTP2_ERR_WOULDBLOCK;
|
||||||
} else {
|
} else {
|
||||||
r = SPDYLAY_ERR_CALLBACK_FAILURE;
|
r = NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
} else if(r == 0) {
|
} else if(r == 0) {
|
||||||
r = SPDYLAY_ERR_EOF;
|
r = NGHTTP2_ERR_EOF;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -521,7 +521,7 @@ void print_timer()
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void print_ctrl_hd(const spdylay_ctrl_hd& hd)
|
void print_ctrl_hd(const nghttp2_ctrl_hd& hd)
|
||||||
{
|
{
|
||||||
printf("<version=%u, flags=%u, length=%d>\n",
|
printf("<version=%u, flags=%u, length=%d>\n",
|
||||||
hd.version, hd.flags, hd.length);
|
hd.version, hd.flags, hd.length);
|
||||||
|
@ -541,8 +541,8 @@ const char* frame_name_ansi_esc(print_type ptype)
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void print_frame(print_type ptype, spdylay_frame_type type,
|
void print_frame(print_type ptype, nghttp2_frame_type type,
|
||||||
spdylay_frame *frame)
|
nghttp2_frame *frame)
|
||||||
{
|
{
|
||||||
printf("%s%s%s frame ",
|
printf("%s%s%s frame ",
|
||||||
frame_name_ansi_esc(ptype),
|
frame_name_ansi_esc(ptype),
|
||||||
|
@ -550,24 +550,24 @@ void print_frame(print_type ptype, spdylay_frame_type type,
|
||||||
ansi_escend());
|
ansi_escend());
|
||||||
print_ctrl_hd(frame->syn_stream.hd);
|
print_ctrl_hd(frame->syn_stream.hd);
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SPDYLAY_SYN_STREAM:
|
case NGHTTP2_SYN_STREAM:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(stream_id=%d, assoc_stream_id=%d, pri=%u)\n",
|
printf("(stream_id=%d, assoc_stream_id=%d, pri=%u)\n",
|
||||||
frame->syn_stream.stream_id, frame->syn_stream.assoc_stream_id,
|
frame->syn_stream.stream_id, frame->syn_stream.assoc_stream_id,
|
||||||
frame->syn_stream.pri);
|
frame->syn_stream.pri);
|
||||||
print_nv(frame->syn_stream.nv);
|
print_nv(frame->syn_stream.nv);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_SYN_REPLY:
|
case NGHTTP2_SYN_REPLY:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(stream_id=%d)\n", frame->syn_reply.stream_id);
|
printf("(stream_id=%d)\n", frame->syn_reply.stream_id);
|
||||||
print_nv(frame->syn_reply.nv);
|
print_nv(frame->syn_reply.nv);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_RST_STREAM:
|
case NGHTTP2_RST_STREAM:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(stream_id=%d, status_code=%u)\n",
|
printf("(stream_id=%d, status_code=%u)\n",
|
||||||
frame->rst_stream.stream_id, frame->rst_stream.status_code);
|
frame->rst_stream.stream_id, frame->rst_stream.status_code);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_SETTINGS:
|
case NGHTTP2_SETTINGS:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(niv=%lu)\n", static_cast<unsigned long>(frame->settings.niv));
|
printf("(niv=%lu)\n", static_cast<unsigned long>(frame->settings.niv));
|
||||||
for(size_t i = 0; i < frame->settings.niv; ++i) {
|
for(size_t i = 0; i < frame->settings.niv; ++i) {
|
||||||
|
@ -577,20 +577,20 @@ void print_frame(print_type ptype, spdylay_frame_type type,
|
||||||
frame->settings.iv[i].flags, frame->settings.iv[i].value);
|
frame->settings.iv[i].flags, frame->settings.iv[i].value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_PING:
|
case NGHTTP2_PING:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(unique_id=%d)\n", frame->ping.unique_id);
|
printf("(unique_id=%d)\n", frame->ping.unique_id);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_GOAWAY:
|
case NGHTTP2_GOAWAY:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(last_good_stream_id=%d)\n", frame->goaway.last_good_stream_id);
|
printf("(last_good_stream_id=%d)\n", frame->goaway.last_good_stream_id);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_HEADERS:
|
case NGHTTP2_HEADERS:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(stream_id=%d)\n", frame->headers.stream_id);
|
printf("(stream_id=%d)\n", frame->headers.stream_id);
|
||||||
print_nv(frame->headers.nv);
|
print_nv(frame->headers.nv);
|
||||||
break;
|
break;
|
||||||
case SPDYLAY_WINDOW_UPDATE:
|
case NGHTTP2_WINDOW_UPDATE:
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("(stream_id=%d, delta_window_size=%d)\n",
|
printf("(stream_id=%d, delta_window_size=%d)\n",
|
||||||
frame->window_update.stream_id,
|
frame->window_update.stream_id,
|
||||||
|
@ -604,7 +604,7 @@ void print_frame(print_type ptype, spdylay_frame_type type,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void on_ctrl_recv_callback
|
void on_ctrl_recv_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
print_timer();
|
print_timer();
|
||||||
|
@ -617,29 +617,29 @@ namespace {
|
||||||
const char* strstatus(uint32_t status_code)
|
const char* strstatus(uint32_t status_code)
|
||||||
{
|
{
|
||||||
switch(status_code) {
|
switch(status_code) {
|
||||||
case SPDYLAY_OK:
|
case NGHTTP2_OK:
|
||||||
return "OK";
|
return "OK";
|
||||||
case SPDYLAY_PROTOCOL_ERROR:
|
case NGHTTP2_PROTOCOL_ERROR:
|
||||||
return "PROTOCOL_ERROR";
|
return "PROTOCOL_ERROR";
|
||||||
case SPDYLAY_INVALID_STREAM:
|
case NGHTTP2_INVALID_STREAM:
|
||||||
return "INVALID_STREAM";
|
return "INVALID_STREAM";
|
||||||
case SPDYLAY_REFUSED_STREAM:
|
case NGHTTP2_REFUSED_STREAM:
|
||||||
return "REFUSED_STREAM";
|
return "REFUSED_STREAM";
|
||||||
case SPDYLAY_UNSUPPORTED_VERSION:
|
case NGHTTP2_UNSUPPORTED_VERSION:
|
||||||
return "UNSUPPORTED_VERSION";
|
return "UNSUPPORTED_VERSION";
|
||||||
case SPDYLAY_CANCEL:
|
case NGHTTP2_CANCEL:
|
||||||
return "CANCEL";
|
return "CANCEL";
|
||||||
case SPDYLAY_INTERNAL_ERROR:
|
case NGHTTP2_INTERNAL_ERROR:
|
||||||
return "INTERNAL_ERROR";
|
return "INTERNAL_ERROR";
|
||||||
case SPDYLAY_FLOW_CONTROL_ERROR:
|
case NGHTTP2_FLOW_CONTROL_ERROR:
|
||||||
return "FLOW_CONTROL_ERROR";
|
return "FLOW_CONTROL_ERROR";
|
||||||
case SPDYLAY_STREAM_IN_USE:
|
case NGHTTP2_STREAM_IN_USE:
|
||||||
return "STREAM_IN_USE";
|
return "STREAM_IN_USE";
|
||||||
case SPDYLAY_STREAM_ALREADY_CLOSED:
|
case NGHTTP2_STREAM_ALREADY_CLOSED:
|
||||||
return "STREAM_ALREADY_CLOSED";
|
return "STREAM_ALREADY_CLOSED";
|
||||||
case SPDYLAY_INVALID_CREDENTIALS:
|
case NGHTTP2_INVALID_CREDENTIALS:
|
||||||
return "INVALID_CREDENTIALS";
|
return "INVALID_CREDENTIALS";
|
||||||
case SPDYLAY_FRAME_TOO_LARGE:
|
case NGHTTP2_FRAME_TOO_LARGE:
|
||||||
return "FRAME_TOO_LARGE";
|
return "FRAME_TOO_LARGE";
|
||||||
default:
|
default:
|
||||||
return "Unknown status code";
|
return "Unknown status code";
|
||||||
|
@ -648,7 +648,7 @@ const char* strstatus(uint32_t status_code)
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void on_invalid_ctrl_recv_callback
|
void on_invalid_ctrl_recv_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
uint32_t status_code, void *user_data)
|
uint32_t status_code, void *user_data)
|
||||||
{
|
{
|
||||||
print_timer();
|
print_timer();
|
||||||
|
@ -670,8 +670,8 @@ void dump_header(const uint8_t *head, size_t headlen)
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void on_ctrl_recv_parse_error_callback(spdylay_session *session,
|
void on_ctrl_recv_parse_error_callback(nghttp2_session *session,
|
||||||
spdylay_frame_type type,
|
nghttp2_frame_type type,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
|
@ -684,12 +684,12 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session,
|
||||||
ctrl_names[type-1],
|
ctrl_names[type-1],
|
||||||
ansi_escend());
|
ansi_escend());
|
||||||
print_frame_attr_indent();
|
print_frame_attr_indent();
|
||||||
printf("Error: %s\n", spdylay_strerror(error_code));
|
printf("Error: %s\n", nghttp2_strerror(error_code));
|
||||||
dump_header(head, headlen);
|
dump_header(head, headlen);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_unknown_ctrl_recv_callback(spdylay_session *session,
|
void on_unknown_ctrl_recv_callback(nghttp2_session *session,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
|
@ -703,7 +703,7 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session,
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_ctrl_send_callback
|
void on_ctrl_send_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
print_timer();
|
print_timer();
|
||||||
|
@ -723,7 +723,7 @@ void print_data_frame(print_type ptype, uint8_t flags, int32_t stream_id,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void on_data_recv_callback
|
void on_data_recv_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
print_timer();
|
print_timer();
|
||||||
|
@ -733,7 +733,7 @@ void on_data_recv_callback
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_data_send_callback
|
void on_data_send_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
print_timer();
|
print_timer();
|
||||||
|
@ -772,7 +772,7 @@ int select_next_proto_cb(SSL* ssl,
|
||||||
}
|
}
|
||||||
std::string& next_proto = *(std::string*)arg;
|
std::string& next_proto = *(std::string*)arg;
|
||||||
if(next_proto.empty()) {
|
if(next_proto.empty()) {
|
||||||
if(spdylay_select_next_protocol(out, outlen, in, inlen) <= 0) {
|
if(nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) {
|
||||||
std::cerr << "Server did not advertise spdy/2 or spdy/3 protocol."
|
std::cerr << "Server did not advertise spdy/2 or spdy/3 protocol."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
abort();
|
abort();
|
||||||
|
@ -921,4 +921,4 @@ int get_time(timeval *tv)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -22,10 +22,10 @@
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef SPDYLAY_SSL_H
|
#ifndef NGHTTP2_SSL_H
|
||||||
#define SPDYLAY_SSL_H
|
#define NGHTTP2_SSL_H
|
||||||
|
|
||||||
#include "spdylay_config.h"
|
#include "nghttp2_config.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -35,16 +35,16 @@
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
namespace spdylay {
|
namespace nghttp2 {
|
||||||
|
|
||||||
extern bool ssl_debug;
|
extern bool ssl_debug;
|
||||||
|
|
||||||
class Spdylay {
|
class Spdylay {
|
||||||
public:
|
public:
|
||||||
Spdylay(int fd, SSL *ssl, uint16_t version,
|
Spdylay(int fd, SSL *ssl, uint16_t version,
|
||||||
const spdylay_session_callbacks *callbacks,
|
const nghttp2_session_callbacks *callbacks,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
~Spdylay();
|
~Spdylay();
|
||||||
int recv();
|
int recv();
|
||||||
|
@ -59,17 +59,17 @@ public:
|
||||||
const std::string& hostport, const std::string& path,
|
const std::string& hostport, const std::string& path,
|
||||||
const std::map<std::string,std::string>& headers,
|
const std::map<std::string,std::string>& headers,
|
||||||
uint8_t pri,
|
uint8_t pri,
|
||||||
const spdylay_data_provider *data_prd,
|
const nghttp2_data_provider *data_prd,
|
||||||
int64_t data_length,
|
int64_t data_length,
|
||||||
void *stream_user_data);
|
void *stream_user_data);
|
||||||
int submit_settings(int flags, spdylay_settings_entry *iv, size_t niv);
|
int submit_settings(int flags, nghttp2_settings_entry *iv, size_t niv);
|
||||||
bool would_block();
|
bool would_block();
|
||||||
void* user_data();
|
void* user_data();
|
||||||
private:
|
private:
|
||||||
int fd_;
|
int fd_;
|
||||||
SSL *ssl_;
|
SSL *ssl_;
|
||||||
uint16_t version_;
|
uint16_t version_;
|
||||||
spdylay_session *session_;
|
nghttp2_session *session_;
|
||||||
void *user_data_;
|
void *user_data_;
|
||||||
uint8_t io_flags_;
|
uint8_t io_flags_;
|
||||||
bool debug_;
|
bool debug_;
|
||||||
|
@ -85,32 +85,32 @@ int make_non_block(int fd);
|
||||||
|
|
||||||
int set_tcp_nodelay(int fd);
|
int set_tcp_nodelay(int fd);
|
||||||
|
|
||||||
ssize_t send_callback(spdylay_session *session,
|
ssize_t send_callback(nghttp2_session *session,
|
||||||
const uint8_t *data, size_t len, int flags,
|
const uint8_t *data, size_t len, int flags,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
ssize_t recv_callback(spdylay_session *session,
|
ssize_t recv_callback(nghttp2_session *session,
|
||||||
uint8_t *data, size_t len, int flags, void *user_data);
|
uint8_t *data, size_t len, int flags, void *user_data);
|
||||||
|
|
||||||
void print_nv(char **nv);
|
void print_nv(char **nv);
|
||||||
|
|
||||||
void on_ctrl_recv_callback
|
void on_ctrl_recv_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void on_invalid_ctrl_recv_callback
|
void on_invalid_ctrl_recv_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
uint32_t status_code, void *user_data);
|
uint32_t status_code, void *user_data);
|
||||||
|
|
||||||
void on_ctrl_recv_parse_error_callback(spdylay_session *session,
|
void on_ctrl_recv_parse_error_callback(nghttp2_session *session,
|
||||||
spdylay_frame_type type,
|
nghttp2_frame_type type,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
size_t payloadlen,
|
size_t payloadlen,
|
||||||
int error_code, void *user_data);
|
int error_code, void *user_data);
|
||||||
|
|
||||||
void on_unknown_ctrl_recv_callback(spdylay_session *session,
|
void on_unknown_ctrl_recv_callback(nghttp2_session *session,
|
||||||
const uint8_t *head,
|
const uint8_t *head,
|
||||||
size_t headlen,
|
size_t headlen,
|
||||||
const uint8_t *payload,
|
const uint8_t *payload,
|
||||||
|
@ -118,15 +118,15 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void on_ctrl_send_callback
|
void on_ctrl_send_callback
|
||||||
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
|
(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void on_data_recv_callback
|
void on_data_recv_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void on_data_send_callback
|
void on_data_send_callback
|
||||||
(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void ctl_poll(pollfd *pollfd, Spdylay *sc);
|
void ctl_poll(pollfd *pollfd, Spdylay *sc);
|
||||||
|
@ -165,6 +165,6 @@ uint8_t get_ssl_io_demand(SSL *ssl, ssize_t r);
|
||||||
// when printing SPDY frames. This function changes a static variable.
|
// when printing SPDY frames. This function changes a static variable.
|
||||||
void set_color_output(bool f);
|
void set_color_output(bool f);
|
||||||
|
|
||||||
} // namespace spdylay
|
} // namespace nghttp2
|
||||||
|
|
||||||
#endif // SPDYLAY_SSL_H
|
#endif // NGHTTP2_SSL_H
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
#include <event2/listener.h>
|
#include <event2/listener.h>
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
#include "shrpx_config.h"
|
#include "shrpx_config.h"
|
||||||
#include "shrpx_listen_handler.h"
|
#include "shrpx_listen_handler.h"
|
||||||
|
@ -324,7 +324,7 @@ void fill_default_config()
|
||||||
mod_config()->daemon = false;
|
mod_config()->daemon = false;
|
||||||
mod_config()->verify_client = false;
|
mod_config()->verify_client = false;
|
||||||
|
|
||||||
mod_config()->server_name = "shrpx spdylay/" SPDYLAY_VERSION;
|
mod_config()->server_name = "shrpx nghttp2/" NGHTTP2_VERSION;
|
||||||
set_config_str(&mod_config()->host, "0.0.0.0");
|
set_config_str(&mod_config()->host, "0.0.0.0");
|
||||||
mod_config()->port = 3000;
|
mod_config()->port = 3000;
|
||||||
mod_config()->private_key_file = 0;
|
mod_config()->private_key_file = 0;
|
||||||
|
@ -369,7 +369,7 @@ void fill_default_config()
|
||||||
|
|
||||||
mod_config()->num_worker = 1;
|
mod_config()->num_worker = 1;
|
||||||
mod_config()->spdy_max_concurrent_streams =
|
mod_config()->spdy_max_concurrent_streams =
|
||||||
SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS;
|
NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS;
|
||||||
mod_config()->add_x_forwarded_for = false;
|
mod_config()->add_x_forwarded_for = false;
|
||||||
mod_config()->no_via = false;
|
mod_config()->no_via = false;
|
||||||
mod_config()->accesslog = false;
|
mod_config()->accesslog = false;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -209,7 +209,7 @@ int ClientHandler::validate_next_proto()
|
||||||
std::string proto(next_proto, next_proto+next_proto_len);
|
std::string proto(next_proto, next_proto+next_proto_len);
|
||||||
CLOG(INFO, this) << "The negotiated next protocol: " << proto;
|
CLOG(INFO, this) << "The negotiated next protocol: " << proto;
|
||||||
}
|
}
|
||||||
uint16_t version = spdylay_npn_get_version(next_proto, next_proto_len);
|
uint16_t version = nghttp2_npn_get_version(next_proto, next_proto_len);
|
||||||
if(version) {
|
if(version) {
|
||||||
SpdyUpstream *spdy_upstream = new SpdyUpstream(version, this);
|
SpdyUpstream *spdy_upstream = new SpdyUpstream(version, this);
|
||||||
upstream_ = spdy_upstream;
|
upstream_ = spdy_upstream;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -36,14 +36,14 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <spdylay/spdylay.h>
|
#include <nghttp2/nghttp2.h>
|
||||||
|
|
||||||
#include "shrpx_log.h"
|
#include "shrpx_log.h"
|
||||||
#include "shrpx_ssl.h"
|
#include "shrpx_ssl.h"
|
||||||
#include "shrpx_http.h"
|
#include "shrpx_http.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using namespace spdylay;
|
using namespace nghttp2;
|
||||||
|
|
||||||
namespace shrpx {
|
namespace shrpx {
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ int parse_spdy_proto(const char *optarg)
|
||||||
size_t len = strlen(optarg);
|
size_t len = strlen(optarg);
|
||||||
const unsigned char *proto;
|
const unsigned char *proto;
|
||||||
proto = reinterpret_cast<const unsigned char*>(optarg);
|
proto = reinterpret_cast<const unsigned char*>(optarg);
|
||||||
uint16_t version = spdylay_npn_get_version(proto, len);
|
uint16_t version = nghttp2_npn_get_version(proto, len);
|
||||||
if(!version) {
|
if(!version) {
|
||||||
LOG(ERROR) << "Unsupported SPDY version: " << optarg;
|
LOG(ERROR) << "Unsupported SPDY version: " << optarg;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
#include "shrpx_downstream_connection.h"
|
#include "shrpx_downstream_connection.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using namespace spdylay;
|
using namespace nghttp2;
|
||||||
|
|
||||||
namespace shrpx {
|
namespace shrpx {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
#include "shrpx_log.h"
|
#include "shrpx_log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using namespace spdylay;
|
using namespace nghttp2;
|
||||||
|
|
||||||
namespace shrpx {
|
namespace shrpx {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
#include "shrpx_http.h"
|
#include "shrpx_http.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using namespace spdylay;
|
using namespace nghttp2;
|
||||||
|
|
||||||
namespace shrpx {
|
namespace shrpx {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Spdylay - SPDY Library
|
* nghttp2 - HTTP/2.0 C Library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
||||||
*
|
*
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue