diff --git a/Makefile.am b/Makefile.am index ba8f5552..c1775e4c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -20,7 +20,7 @@ # 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. -SUBDIRS = lib src tests examples doc python +SUBDIRS = lib src tests examples doc ACLOCAL_AMFLAGS = -I m4 diff --git a/NEWS b/NEWS index 4494b3c0..e69de29b 100644 --- a/NEWS +++ b/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. diff --git a/README.rst b/README.rst index 7879ff9c..a0d9acd4 100644 --- a/README.rst +++ b/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 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. +This is an experimental implementation of Hypertext Transfer Protocol +version 2.0. Development Status ------------------ -Most of the SPDY/2 and SPDY/3 functionality has been implemented. In -both versions, the direct support of server-push has not been -available yet. The application can achieve server-push using -primitive APIs though. - -As described below, we can create SPDY client and server with the -current Spdylay API. - -Requirements ------------- - -The following packages are needed to build the library: - -* pkg-config >= 0.20 -* zlib >= 1.2.3 - -To build and run the unit test programs, the following packages are -needed: - -* 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 `_ -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 -`_ 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 ] [-w ] [--cert=] - [--key=] [--no-tls] [-d ] [-m ] ... - - 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= Timeout each request after seconds. - -w, --window-bits= - Sets the initial window size to 2**. - -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= Use the specified client certificate file. - The file must be in PEM format. - --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= Post FILE to server. If - is given, data - will be read from stdin. - -m, --multiply= Request each URI 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 - (niv=2) - [4(1):100] - [7(0):12288] - [ 0.035] send SYN_STREAM frame - (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 - (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 - (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 - (niv=1) - [4(0):100] - [id=1] [ 17.457] recv SYN_STREAM frame - (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 - (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 - (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 `_ 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 ] - [-f ] [-n ] [-c ] [-L ] - [OPTIONS...] [ ] - - A reverse proxy for SPDY/HTTPS. - - Positional arguments: - Set path to server's private key. Required - unless either -p or --client is specified. - Set path to server's certificate. Required - unless either -p or --client is specified. - - OPTIONS: - - Connections: - -b, --backend= - Set backend host and port. - Default: '127.0.0.1,80' - -f, --frontend= - Set frontend host and port. - Default: '0.0.0.0,3000' - --backlog= 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= - Set the number of worker threads. - Default: 1 - - Timeout: - --frontend-spdy-read-timeout= - Specify read timeout for SPDY frontend - connection. Default: 180 - --frontend-read-timeout= - Specify read timeout for non-SPDY frontend - connection. Default: 180 - --frontend-write-timeout= - Specify write timeout for both SPDY and - non-SPDY frontends. - connection. Default: 60 - --backend-read-timeout= - Specify read timeout for backend connection. - Default: 900 - --backend-write-timeout= - Specify write timeout for backend - connection. Default: 60 - --backend-keep-alive-timeout= - Specify keep-alive timeout for backend - connection. Default: 60 - --backend-http-proxy-uri= - Specify proxy URI in the form - http://[:@]:. If - a proxy requires authentication, specify - and . 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= 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= 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= - 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=: - 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= - Explicitly set the content of the TLS SNI - extension. This will default to the backend - HOST name. - - SPDY: - -c, --spdy-max-concurrent-streams= - Set the maximum number of the concurrent - streams in one SPDY session. - Default: 100 - --frontend-spdy-window-bits= - Sets the initial window size of SPDY - frontend connection to 2**. - 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= - Sets the initial window size of SPDY - backend connection to 2**. - 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= - 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= - 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= Set path to save PID of this program. - --user= Run this program as USER. This option is - intended to be used to drop root privileges. - --conf= 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 - `_). 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 - `_ for - details how to change Policy setup on the platform you use. The - Policy name we are looking for is `MaxConnectionsPerProxy - `_ - For example, if you are using Linux, follow the instruction - described in `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. +We started work based on spdylay codebase and just replaced spdylay +keyword with nghttp2. So just now it is just a relabled SPDY +implementation and is not HTTP/2.0 implementation at all. To take +advantage of the existing code, we will perform the following steps to +implement HTTP/2.0 based on implementation draft +(http://tools.ietf.org/html/draft-ietf-httpbis-http2-04): + +1. Implement HTTP/2.0 frames and semantics, except for header + 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 + internal testing. We use NPN for TLS for now. +3. Implement header compression, which may be based on draft-x (x >= + 1). +4. Add new client and server which can perform HTTP upgrade mechanism. +5. At this step, the library and demo client/server should be + interoperable to the other implementation. Do some interoperable + testing with the other ones (e.g., node-http2) diff --git a/android-config b/android-config index 71583021..5c402a80 100755 --- a/android-config +++ b/android-config @@ -1,6 +1,6 @@ #!/bin/sh # -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # # Copyright (c) 2013 Tatsuhiro Tsujikawa # diff --git a/android-make b/android-make index a08b7f0b..e28c42a9 100755 --- a/android-make +++ b/android-make @@ -1,6 +1,6 @@ #!/bin/sh # -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # # Copyright (c) 2013 Tatsuhiro Tsujikawa # diff --git a/configure.ac b/configure.ac index 43d6d92b..0f19dc70 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -dnl Spdylay - SPDY Library +dnl nghttp2 - HTTP/2.0 C Library 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 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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_INIT() dnl See versioning rule: @@ -290,16 +290,15 @@ AC_SUBST([SRC_LIBS]) AC_CONFIG_FILES([ Makefile lib/Makefile - lib/libspdylay.pc + lib/libnghttp2.pc lib/includes/Makefile - lib/includes/spdylay/spdylayver.h + lib/includes/nghttp2/nghttp2ver.h tests/Makefile tests/testdata/Makefile src/Makefile examples/Makefile doc/Makefile doc/conf.py - python/Makefile ]) AC_OUTPUT diff --git a/doc/Makefile.am b/doc/Makefile.am index ab82ce0a..d30095df 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -21,7 +21,7 @@ # 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 = 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 # Makefile for Sphinx documentation @@ -59,8 +59,8 @@ help: @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" -apiref.rst: $(top_builddir)/lib/includes/spdylay/spdylayver.h \ - $(top_builddir)/lib/includes/spdylay/spdylay.h +apiref.rst: $(top_builddir)/lib/includes/nghttp2/nghttp2ver.h \ + $(top_builddir)/lib/includes/nghttp2/nghttp2.h $(builddir)/mkapiref.py --header apiref-header.rst $^ > $@ clean: @@ -103,17 +103,17 @@ qthelp: @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".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 "# assistant -collectionFile $(BUILDDIR)/qthelp/Spdylay.qhc" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/nghttp2.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/Spdylay" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Spdylay" + @echo "# mkdir -p $$HOME/.local/share/devhelp/nghttp2" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/nghttp2" @echo "# devhelp" epub: diff --git a/doc/README.rst b/doc/README.rst index b5831905..35bfe7ed 100644 --- a/doc/README.rst +++ b/doc/README.rst @@ -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 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 ------------------------ @@ -49,7 +49,7 @@ The example follows:: * * Submits PING frame to the |session|. */ - int spdylay_submit_ping(spdylay_session *session); + int nghttp2_submit_ping(nghttp2_session *session); @functypedef @@ -68,8 +68,8 @@ The example follows:: * Callback function invoked when |session| wants to send data to * remote peer. */ - typedef ssize_t (*spdylay_send_callback) - (spdylay_session *session, + typedef ssize_t (*nghttp2_send_callback) + (nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data); @enum @@ -93,18 +93,18 @@ The example follows:: /** * @enum - * Error codes used in the Spdylay library. + * Error codes used in the nghttp2 library. */ typedef enum { /** * Invalid argument passed. */ - SPDYLAY_ERR_INVALID_ARGUMENT = -501, + NGHTTP2_ERR_INVALID_ARGUMENT = -501, /** * Zlib error. */ - SPDYLAY_ERR_ZLIB = -502, - } spdylay_error; + NGHTTP2_ERR_ZLIB = -502, + } nghttp2_error; @struct ####### @@ -142,7 +142,7 @@ Some examples follow:: * The length field of this control frame. */ int32_t length; - } spdylay_ctrl_hd; + } nghttp2_ctrl_hd; /** * @struct @@ -151,7 +151,7 @@ Some examples follow:: * session. The details of this structure is hidden from the public * API. */ - typedef struct spdylay_session spdylay_session; + typedef struct nghttp2_session nghttp2_session; @union ###### diff --git a/doc/_templates/menu.html b/doc/_templates/menu.html index ae4f7f6c..36c7f29b 100644 --- a/doc/_templates/menu.html +++ b/doc/_templates/menu.html @@ -1,7 +1,5 @@

Menu

diff --git a/doc/android-spdy-proxy.rst b/doc/android-spdy-proxy.rst deleted file mode 100644 index 0ee4d797..00000000 --- a/doc/android-spdy-proxy.rst +++ /dev/null @@ -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 `_ 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 -`_. 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. diff --git a/doc/apiref-header.rst b/doc/apiref-header.rst index b4c3a4c9..1192df24 100644 --- a/doc/apiref-header.rst +++ b/doc/apiref-header.rst @@ -4,16 +4,16 @@ API Reference Includes -------- -To use the public APIs, include ``spdylay/spdylay.h``:: +To use the public APIs, include ``nghttp2/nghttp2.h``:: - #include + #include Remarks ------- -Do not call `spdylay_session_send`, `spdylay_session_recv` or -`spdylay_session_mem_recv` from the spdylay callback functions +Do not call `nghttp2_session_send`, `nghttp2_session_recv` or +`nghttp2_session_mem_recv` from the nghttp2 callback functions directly or indirectly. It will lead to the crash. You can submit -requests or frames in the callbacks then call `spdylay_session_send`, -`spdylay_session_recv` or `spdylay_session_mem_recv` outside of the +requests or frames in the callbacks then call `nghttp2_session_send`, +`nghttp2_session_recv` or `nghttp2_session_mem_recv` outside of the callbacks. diff --git a/doc/conf.py.in b/doc/conf.py.in index 1f15c369..f7ee3989 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -23,7 +23,7 @@ # 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. # # This file is execfile()d with the current directory set to its containing dir. @@ -63,7 +63,7 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'Spdylay' +project = u'nghttp2' copyright = u'2012, 2013, Tatsuhiro Tsujikawa' # The version info for the project you're documenting, acts as replacement for @@ -204,7 +204,7 @@ html_sidebars = { #html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'Spdylaydoc' +htmlhelp_basename = 'nghttp2doc' # -- Options for LaTeX output -------------------------------------------------- @@ -218,7 +218,7 @@ htmlhelp_basename = 'Spdylaydoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'Spdylay.tex', u'Spdylay Documentation', + ('index', 'nghttp2.tex', u'nghttp2 Documentation', u'Tatsuhiro Tsujikawa', 'manual'), ] @@ -251,7 +251,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'spdylay', u'Spdylay Documentation', + ('index', 'nghttp2', u'nghttp2 Documentation', [u'Tatsuhiro Tsujikawa'], 1) ] diff --git a/doc/index.rst b/doc/index.rst index deeb3917..c29c6607 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -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. You can adapt this file completely to your liking, but it should at least 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 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. +This is an experimental implementation of Hypertext Transfer Protocol +version 2.0. Contents: @@ -25,10 +16,8 @@ Contents: package_README apiref - python - android-spdy-proxy Resources --------- -* http://www.chromium.org/spdy +* http://tools.ietf.org/html/draft-ietf-httpbis-http2-04 diff --git a/doc/make.bat b/doc/make.bat index 6f693b28..2e0500de 100644 --- a/doc/make.bat +++ b/doc/make.bat @@ -95,9 +95,9 @@ if "%1" == "qthelp" ( echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .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.^> assistant -collectionFile %BUILDDIR%\qthelp\Spdylay.ghc + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\nghttp2.ghc goto end ) diff --git a/doc/mkapiref.py b/doc/mkapiref.py index bdd38831..3ab088d8 100755 --- a/doc/mkapiref.py +++ b/doc/mkapiref.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa diff --git a/doc/python.rst b/doc/python.rst deleted file mode 100644 index 594df515..00000000 --- a/doc/python.rst +++ /dev/null @@ -1,1077 +0,0 @@ -Python-spdylay - Spdylay Python Extension Module -================================================ - -.. py:module:: spdylay - -Python-spdylay is the Python extension module of Spdylay SPDY C -library. - -Build ------ - -To generate C source code from ``spdylay.pyx``, run ``cython``:: - - $ cython spdylay.pyx - -To build extension, run ``setup.py``:: - - $ python setup.py build_ext - -Session Objects ---------------- - -.. py:class:: Session(side, version, config=None, send_cb=None, recv_cb=None, on_ctrl_recv_cb=None, on_invalid_ctrl_recv_cb=None, on_data_chunk_recv_cb=None, on_data_recv_cb=None, before_ctrl_send_cb=None, on_ctrl_send_cb=None, on_ctrl_not_send_cb=None, on_data_send_cb=None, on_stream_close_cb=None, on_request_recv_cb=None, on_ctrl_recv_parse_error_cb=None, on_unknown_ctrl_recv_cb=None, user_data=None) - - This is the class to hold the resources needed for a SPDY session. - Sending and receiving SPDY frames are done using the methods of - this class. - - The *side* specifies server or client. Use one of the following: - - .. py:data:: CLIENT - - Indicates client. - - .. py:data:: SERVER - - Indicates server. - - The *version* specifies SPDY protocol version. Use of the following: - - .. py:data:: PROTO_SPDY2 - - Indicates SPDY/2. - - .. py:data:: PROTO_SPDY3 - - Indicates SPDY/3. - - The *user_data* specifies opaque object tied to this object. It - can be accessed through :py:attr:`user_data` attribute. - - The *recv_cb* specifies callback function (callable) invoked when - the object wants to receive data from the remote peer. The - signature of this callback is: - - .. py:function:: recv_cb(session, length) - - The *session* is the :py:class:`Session` object invoking the - callback. The implementation of this function must read at - most *length* bytes of bytestring and return it. If it cannot - read any single byte without blocking, it must return empty - bytestring or ``None``. If it gets EOF before it reads any - single byte, it must raise :py:class:`EOFError`. For other - errors, it must raise :py:class:`CallbackFailureError`. - - The *send_cb* specifies callback function (callable) invoked when - session wants to send data to the remote peer. The signature of - this callback is: - - .. py:function:: send_cb(session, data) - - The *session* is the :py:class:`Session` object invoking the - callback. The *data* is the bytestring to send. The - implementation of this function will send all or part of - *data*. It must return the number of bytes sent if it - succeeds. If it cannot send any single byte without blocking, - it must return 0 or ``None``. For other errors, it must return - :py:class:`CallbackFailureError`. - - The *on_ctrl_recv_cb* specifies callback function (callable) - invoked when a control frame is received. - - .. py:function:: on_ctrl_recv_cb(session, frame) - - The *session* is the :py:class:`Session` object invoking the - callback. The *frame* is the received control - frame. ``frame.frame_type`` tells the type of frame. See - `Frame Types`_ for the details. Once the frame type is - identified, access attribute of the *frame* to get - information. - - The *on_invalid_ctrl_recv_cb* specifies callback function - (callable) invoked when an invalid control frame is received. - - .. py:function:: on_invalid_ctrl_recv_cb(session, frame, status_code) - - The *session* is the :py:class:`Session` object invoking the - callback. The *frame* is the received control - frame. ``frame.frame_type`` tells the type of frame. See - `Frame Types`_ for the details. Once the frame type is - identified, access attribute of the *frame* to get - information. The *status_code* is one of the `Stream Status - Codes`_ and indicates the error. When this callback function - is invoked, either RST_STREAM or GOAWAY will be sent. - - The *on_data_chunk_recv_cb* specifies callback function (callable) - invoked when a chunk of data in DATA frame is received. - - .. py:function:: on_data_chunk_recv_cb(session, flags, stream_id, data) - - The *session* is the :py:class:`Session` object invoking the - callback. The *stream_id* is the stream ID this DATA frame - belongs to. The *flags* is the flags of DATA frame which this - data chunk is contained. ``(flags & DATA_FLAG_FIN) != 0`` does - not necessarily mean this chunk of data is the last one in the - stream. You should use :py:func:`on_data_recv_cb` to know all - data frames are received. The *data* is the bytestring of - received data. - - The *on_data_recv_cb* specifies callback function (callable) - invoked when DATA frame is received. - - .. py:function:: on_data_recv_cb(session, flags, stream_id, length) - - The actual data it contains are received by - :py:func:`on_data_chunk_recv_cb()`. - - The *before_ctrl_send_cb* specifies callback function (callable) - invoked before the control frame is sent. - - .. py:function:: before_ctrl_send_cb(session, frame) - - The *session* is the :py:class:`Session` object invoking the - callback. The *frame* is the control frame to be - sent. ``frame.frame_type`` tells the type of frame. See `Frame - Types`_ for the details. Once the frame type is identified, - access attribute of the *frame* to get information. - - The *on_ctrl_send_cb* specifies callback function (callable) - invoked after the control frame is sent. - - .. py:function:: on_ctrl_send_cb(session, frame) - - The *session* is the :py:class:`Session` object invoking the - callback. The *frame* is the control frame to be - sent. ``frame.frame_type`` tells the type of frame. See `Frame - Types`_ for the details. Once the frame type is identified, - access attribute of the *frame* to get information. - - The *on_ctrl_not_send_cb* specifies callback function (callable) - after the control frame is not sent because of the error. - - .. py:function:: on_ctrl_not_send_cb(session, frame, error_code) - - The *session* is the :py:class:`Session` object invoking the - callback. The *frame* is the received control - frame. ``frame.frame_type`` tells the type of frame. See - `Frame Types`_ for the details. Once the frame type is - identified, access attribute of the *frame* to get - information. The *error_code* is one of the `Error Codes`_ - and indicates the error. - - The *on_data_send_cb* specifies callback function (callable) - invoked after DATA frame is sent. - - .. py:function:: on_data_send_cb(session, flags, stream_id, length) - - The *on_stream_close_cb* specifies callback function (callable) - invoked when the stream is closed. - - .. py:function:: on_stream_close_cb(session, stream_id, status_code) - - The *session* is the :py:class:`Session` object invoking the - callback. The *stream_id* indicates the stream ID. The reason - of closure is indicated by the *status_code*. See `Stream - Status Codes`_ for the details. The stream_user_data, which - was specified in :py:meth:`submit_request()` or - :py:meth:`submit_syn_stream()`, is still available in this - function. - - The *on_request_recv_cb* specifies callback function (callable) - invoked when the request from the remote peer is received. In - other words, the frame with FIN flag set is received. In HTTP, - this means HTTP request, including request body, is fully - received. - - .. py:function:: on_request_recv_cb(session, stream_id) - - The *session* is the :py:class:`Session` object invoking the - callback. The *stream_id* indicates the stream ID. - - The *on_ctrl_recv_parse_error_cb* specifies callback function - (callable) invoked when the received control frame octets could - not be parsed correctly. - - .. py:function:: on_ctrl_recv_parse_error_cb(session, type, head, payload, error_code) - - The *type* indicates the type of received control frame. The - *head* is the bytestring of control frame header. The - *payload* is the bytestring of data portion of the received - frame. The *error_code* is one of the error code defined in - `Error Codes`_ and indicates the error. - - The *on_unknown_ctrl_recv_cb* specifies callback function - (callable) invoked when the received control frame type is - unknown. - - .. py:function:: on_unknown_ctrl_recv_cb(session, head, payload) - - The *head* is the bytestring of control frame header. The - *payload* is the bytestring of data portion of the received - frame. - - The :py:class:`InvalidArgumentError` will be raised if the given - argument is invalid. The :py:class:`UnsupportedVersionError` will - be raised if the *version* is not supported. The - :py:class:`ZlibError` will be raised if initialization of zlib - failed. - -.. py:attribute:: Session.user_data - - The object passed in the constructor as *user_data* argument. - This attribute is read-only. - -.. py:method:: Session.send() - - Sends pending frames to the remote peer. This method retrieves - the highest prioritized frame from the outbound queue and sends it - to the remote peer. It does this as many as possible until the - user callback :py:func:`send_cb` returns 0 or ``None`` or the - outbound queue becomes empty. This method calls several callback - functions which are passed when initializing the session. See - :func:`spdylay_session_send` about the callback functions invoked - from this method. - - The :py:class:`CallbackFailureError` will be raised if the - callback function failed. - -.. py:method:: Session.recv(data=None) - - Receives frames from the remote peer. This method receives as - many frames as possible until the user callback :py:func:`recv_cb` - returns empty bytestring or ``None``. This function calls several - callback functions which are passed when initializing the session. - See :func:`spdylay_session_recv` about the callback functions - invoked from this method. If data is ``None``, this method will - invoke :py:func:`recv_cb` callback function to receive incoming - data. If data is not ``None``, it must be a bytestring and this - method uses it as the incoming data and does not call - :py:func:`recv_cb` callback function. - - The :py:class:`EOFError` will be raised if the remote peer did - shutdown on the connection. The :py:class:`CallbackFailureError` - will be raised if the callback function failed. - -.. py:method:: Session.resume_data(stream_id) - - Puts back previously deferred DATA frame in the stream *stream_id* - to the outbound queue. - - This method returns ``True`` if it succeeds, or ``False``. This - method will fail if the stream does not exist or no deferred data - exist. - -.. py:method:: Session.want_read() - - Returns ``True`` if session wants to receive data from the - remote peer. - - If both :py:meth:`want_read()` and :py:meth:`want_write()` return - ``False``, the application should drop the connection. - -.. py:method:: Session.want_write() - - Returns ``True`` if session wants to send data to the remote peer. - - If both :py:meth:`want_read()` and :py:meth:`want_write()` return - ``False``, the application should drop the connection. - -.. py:method:: Session.get_stream_user_data(stream_id) - - Returns stream_user_data for the stream *stream_id*. The - stream_user_data is provided by :py:meth:`submit_request()` or - :py:meth:`submit_syn_stream()`. If the stream is initiated by the - remote endpoint, stream_user_data is always ``None``. If the - stream is initiated by the local endpoint and ``None`` is given in - :py:meth:`submit_request()` or :py:meth:`submit_syn_stream()`, - then this function returns ``None``. If the stream does not exist, - this function returns ``None``. - -.. py:method:: Session.get_outbound_queue_size() - - Returns the number of frames in the outbound queue. This does not - include the deferred DATA frames. - -.. py:method:: Session.get_pri_lowest() - - Returns lowest priority value for the session. - -.. py:method:: Session.fail_session(status_code) - - Submits GOAWAY frame. The status code *status_code* is ignored if - the protocol version is :py:const:`PROTO_SPDY2`. - - This method should be called when the connection should be - terminated after sending GOAWAY. If the remaining streams should - be processed after GOAWAY, use :py:meth:`submit_goaway()` instead. - -.. py:method:: Session.submit_request(pri, nv, data_prd=None, stream_user_data=None) - - Submits SYN_STREAM frame and optionally one or more DATA frames. - - The *pri* is priority of this request. ``0`` is the highest - priority value. Use :py:meth:`get_pri_lowest()` to know the lowest - priority value for this session. - - The *nv* is a list containing the name/value pairs. The each - element is a pair of unicode strings: name and value (e.g., - ``(u'host', u'localhost')``). - - The *nv* must include following name/value pairs: - - ``:method`` - HTTP method (e.g., ``GET``, ``POST``, ``HEAD``, etc) - ``:scheme`` - URI scheme (e.g., ``https``) - ``:path`` - Absolute path and parameters of this request (e.g., ``/foo``, - ``/foo;bar;haz?h=j&y=123``) - ``:version`` - HTTP version (e.g., ``HTTP/1.1``) - ``:host`` - The hostport portion of the URI for this request (e.g., - ``example.org:443``). This is the same as the HTTP “Host” - header field. - - If the session is initialized with the version - :py:const:`PROTO_SPDY2`, the above names are translated to - ``method``, ``scheme``, ``url``, ``version`` and ``host`` - respectively. - - The names in *nv* will be lower-cased when they are sent. - - If *data_prd* is not ``None``, it provides data which will be sent - in subsequent DATA frames. In this case, a method that allows - request message bodies - (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9) must - be specified with ``:method`` key in nv (e.g. ``POST``). The type - of *data_prd* is expected to be :py:class:`DataProvider`. If - *data_prd* is ``None``, SYN_STREAM have FLAG_FIN set. - - .. note:: - - This method does not increase reference count of *data_prd*, - so the application must hold the reference to it until the - stream is closed. - - The *stream_user_data* is data associated to the stream opened by - this request and can be an arbitrary object, which can be - retrieved later by :py:meth:`get_stream_user_data()`. - - Since the library reorders the frames and tries to send the - highest prioritized one first and the SPDY specification requires - the stream ID must be strictly increasing, the stream ID of this - request cannot be known until it is about to sent. To know the - stream ID of the request, the application can use - :py:func:`before_ctrl_send_cb`. This callback is called just - before the frame is sent. For SYN_STREAM frame, the argument frame - has the stream ID assigned. Also since the stream is already - opened, :py:meth:`get_stream_user_data()` can be used to get - stream_user_data to identify which SYN_STREAM we are processing. - - The :py:class:`InvalidArgumentError` will be raised if the *pri* - is invalid; or the *nv* includes empty name or ``None`` value. - -.. py:method:: Session.submit_response(stream_id, nv, data_prd=None) - - Submits SYN_REPLY frame and optionally one or more DATA frames - against the stream *stream_id*. - - The *nv* is a list containing the name/value pairs. The each - element is a pair of unicode strings: name and value (e.g., - ``(u'host', u'localhost')``). - - The *nv* must include following name/value pairs: - - ``:status`` - HTTP status code (e.g., ``200`` or ``200 OK``) - ``:version`` - HTTP response version (e.g., ``HTTP/1.1``) - - If the session is initialized with the version - :py:const:`PROTO_SPDY2`, the above names are translated to - ``status`` and ``version`` respectively. - - The names in *nv* will be lower-cased when they are sent. - - If *data_prd* is not ``None``, it provides data which will be sent - in subsequent DATA frames. The type of *data_prd* is expected to - be :py:class:`DataProvider`. If *data_prd* is ``None``, SYN_REPLY - have FLAG_FIN set. - - .. note:: - - This method does not increase reference count of *data_prd*, - so the application must hold the reference to it until the - stream is closed. - - The :py:class:`InvalidArgumentError` will be raised if the *nv* - includes empty name or ``None`` value. - -.. py:method:: Session.submit_syn_stream(flags, pri, nv, assoc_stream_id=0, stream_user_data=None) - - Submits SYN_STREAM frame. The *flags* is bitwise OR of the - following values: - - * :py:const:`CTRL_FLAG_FIN` - * :py:const:`CTRL_FLAG_UNIDIRECTIONAL` - - If *flags* includes :py:const:`CTRL_FLAG_FIN`, this frame has - FLAG_FIN flag set. - - The *assoc_stream_id* is used for server-push. Specify 0 if this - stream is not server-push. If session is initialized for client - use, *assoc_stream_id* is ignored. - - The *pri* is priority of this request. ``0`` is the highest - priority value. Use :py:meth:`get_pri_lowest()` to know the lowest - priority value for this session. - - The *nv* is a list containing the name/value pairs. The each - element is a pair of unicode strings: name and value (e.g., - ``(u'host', u'localhost')``). - - The names in *nv* will be lower-cased when they are sent. - - The *stream_user_data* is data associated to the stream opened by - this request and can be an arbitrary object, which can be - retrieved later by :py:meth:`get_stream_user_data()`. - - This function is low-level in a sense that the application code - can specify flags and the Associated-To-Stream-ID directly. For - usual HTTP request, :py:meth:`submit_request()` is useful. - - The :py:class:`InvalidArgumentError` will be raised if the *pri* - is invalid; or the *assoc_stream_id* is invalid; or the *nv* - includes empty name or ``None`` value. - -.. py:method:: Session.submit_syn_reply(flags, stream_id, nv) - - Submits SYN_REPLY frame. The *flags* is bitwise OR of the - following values: - - * :py:const:`CTRL_FLAG_FIN` - - If *flags* includes :py:const:`CTRL_FLAG_FIN`, this frame has - FLAG_FIN flag set. - - The stream which this frame belongs to is given in the - *stream_id*. The *nv* is the name/value pairs in this frame. - - The *nv* is a list containing the name/value pairs. The each - element is a pair of unicode strings: name and value (e.g., - ``(u'host', u'localhost')``). - - The names in *nv* will be lower-cased when they are sent. - - The :py:class:`InvalidArgumentError` will be raised if the *nv* - includes empty name or ``None`` value. - -.. py:method:: Session.submit_headers(flags, stream_id, nv) - - Submits HEADERS frame. The *flags* is bitwise OR of the following - values: - - * :py:const:`CTRL_FLAG_FIN` - - If *flags* includes :py:const:`CTRL_FLAG_FIN`, this frame has - FLAG_FIN flag set. - - The stream which this frame belongs to is given in the - *stream_id*. The *nv* is the name/value pairs in this frame. - - The *nv* is a list containing the name/value pairs. The each - element is a pair of unicode strings: name and value (e.g., - ``(u'host', u'localhost')``). - - The names in *nv* will be lower-cased when they are sent. - - The :py:class:`InvalidArgumentError` will be raised if the *nv* - includes empty name or ``None`` value. - -.. py:method:: Session.submit_data(stream_id, flags, data_prd) - - Submits one or more DATA frames to the stream *stream_id*. The - data to be sent are provided by *data_prd*. The type of - *data_prd* is expected to be :py:class:`DataProvider`. If *flags* - contains :py:const:`DATA_FLAG_FIN`, the last DATA frame has - FLAG_FIN set. - - .. note:: - - This method does not increase reference count of *data_prd*, - so the application must hold the reference to it until the - stream is closed. - -.. py:method:: Session.submit_rst_stream(stream_id, status_code) - - Submits RST_STREAM frame to cancel/reject the stream *stream_id* - with the status code *status_code*. See `Stream Status Codes`_ for - available status codes. - -.. py:method:: Session.submit_ping() - - Submits PING frame. - -.. py:method:: Session.submit_goaway(status_code) - - Submits GOAWAY frame. The status code *status_code* is ignored if - the protocol version is :py:const:`PROTO_SPDY2`. See `GOAWAY - Status Codes`_ for available status codes. - -.. py:method:: Session.submit_settings(flags, iv) - - Stores local settings and submits SETTINGS frame. The *flags* is - bitwise OR of the values described in `SETTINGS Frame Flags`_. - - The *iv* is a list of tuple ``(settings_id, flag, value)``. For - settings_id, see `SETTINGS IDs`_. For flag, see `SETTINGS ID - Flags`_. - - The :py:class:`InvalidArgumentError` will be raised if the *iv* - contains duplicate settings ID or invalid value. - -.. py:method:: Session.submit_window_update(stream_id, delta_window_size) - - Submits WINDOW_UPDATE frame. The effective range of the - *delta_window_size* is ``[1, (1 << 31)-1]``, inclusive. But the - application must be responsible to keep the resulting window - ``size <= (1 << 31)-1``. - - The :py:class:`InvalidArgumentError` will be raised if the - *delta_window_size* is 0 or negative. The - :py:class:`StreamClosedError` will be raised if the stream is - already closed or does not exist. - -Helper Functions ----------------- - -.. py:function:: get_npn_protocols() - - Returns SPDY version strings which can be directly passed to - ``ssl.SSLContext.set_npn_protocols()``. Please note that the - returned list only includes SPDY version strings this library - supports. If the application intends to support other fallback - protocols (e.g., ``http/1.1``), the application should add them to - the returned list. - -.. py:function:: npn_get_version(proto) - - Returns SPDY version which spdylay library supports from the given - protocol name. The *proto* is the unicode string to the protocol - name. Currently, ``spdy/2`` and ``spdy/3`` are supported. The - returned nonzero SPDY version can be passed as the version - argument in :py:class:`Session` constructor. - - This function returns nonzero SPDY version if it succeeds, or 0. - - -Data Provider Objects ---------------------- - -.. py:class:: DataProvider(source, read_cb) - - This class represents the data source and the way to read a chunk - of data from it. The *source* is expected to be the data source to - read, but the application can freely pass any object including - ``None``. The *read_cb* is the callback function invoked when the - library needs to read data. The data read will be sent as DATA - frame. - - .. py:function:: read_cb(session, stream_id, length, read_ctrl, source) - - The *session* is the :py:class:`Session` object. The - *stream_id* is the stream to send data. The *source* is the - object passed as a *source* in DataProvider constructor. The - implementation of this callback must read at most *length* - bytes of data and return it as bytestring. When all data is - read, assign :py:const:`READ_EOF` to ``read_ctrl.flags``. If - the application wants to postpone DATA frames, (e.g., - asynchronous I/O, or reading data blocks for long time), it is - achieved by returning :py:const:`ERR_DEFERRED` without reading - any data in this invocation. The library removes DATA frame - from the outgoing queue temporarily. To move back deferred - DATA frame to outgoing queue, call - :py:meth:`Session.resume_data()`. In case of error, there are - 2 choices. Raising :py:class:`TemporalCallbackFailureError` - will close the stream by issuing RST_STREAM with - :py:const:`INTERNAL_ERROR`. Raising - :py:class:`CallbackFailureError` will signal the entire - session failure. - -.. py:attribute:: DataProvider.source - -.. py:attribute:: DataProvider.read_cb - -Control Frame Objects ---------------------- - -.. py:class:: CtrlFrame - - The base class of SPDY control frames. - - .. py:attribute:: version - - Version - - .. py:attribute:: frame_type - - Frame type. See `Frame Types`_. - - .. py:attribute:: flags - - Flags. See `Control Frame Flags`_. - - .. py:attribute:: length - - Frame payload length - -The following frame classes inherit :py:class:`CtrlFrame` class. - -.. py:class:: SynStreamFrame - - .. py:attribute:: stream_id - - Stream ID - - .. py:attribute:: assoc_stream_id - - Associated-To-Stream-ID - - .. py:attribute:: pri - - Priority - - .. py:attribute:: slot - - Credential slot - - .. py:attribute:: nv - - List of name/value pair. - -.. py:class:: SynReplyFrame - - .. py:attribute:: stream_id - - Stream ID - - .. py:attribute:: nv - - List of name/value pair. - -.. py:class:: HeadersFrame - - .. py:attribute:: stream_id - - Stream ID - - .. py:attribute:: nv - - List of name/value pair. - -.. py:class:: RstStreamFrame - - - .. py:attribute:: stream_id - - Stream ID - - .. py:attribute:: status_code - - Status code - -.. py:class:: SettingsFrame - - .. py:attribute:: iv - - List of tuple ``(settings_id, flags, value)`` - -.. py:class:: PingFrame - - .. py:attribute:: unique_id - - Unique ID - -.. py:class:: GoawayFrame - - .. py:attribute:: last_good_stream_id - - Last good stream ID - - .. py:attribute:: status_code - - Status code - -.. py:class:: WindowUpdateFrame - - .. py:attribute:: stream_id - - Stream ID - - .. py:attribute:: delta_window_size - - Delta window size - -Exceptions ----------- - -.. py:class:: EOFError - -.. py:class:: CallbackFailureError - -.. py:class:: TemporalCallbackFailureError - -.. py:class:: InvalidArgumentError - -.. py:class:: ZlibError - -.. py:class:: UnsupportedVersionError - -.. py:class:: StreamClosedError - -Read Callback Flags -------------------- - -.. py:data:: READ_EOF - -Error Codes ------------ - -.. py:data:: ERR_INVALID_ARGUMENT -.. py:data:: ERR_ZLIB -.. py:data:: ERR_UNSUPPORTED_VERSION -.. py:data:: ERR_WOULDBLOCK -.. py:data:: ERR_PROTO -.. py:data:: ERR_INVALID_FRAME -.. py:data:: ERR_EOF -.. py:data:: ERR_DEFERRED -.. py:data:: ERR_STREAM_ID_NOT_AVAILABLE -.. py:data:: ERR_STREAM_CLOSED -.. py:data:: ERR_STREAM_CLOSING -.. py:data:: ERR_STREAM_SHUT_WR -.. py:data:: ERR_INVALID_STREAM_ID -.. py:data:: ERR_INVALID_STREAM_STATE -.. py:data:: ERR_DEFERRED_DATA_EXIST -.. py:data:: ERR_SYN_STREAM_NOT_ALLOWED -.. py:data:: ERR_GOAWAY_ALREADY_SENT -.. py:data:: ERR_INVALID_HEADER_BLOCK -.. py:data:: ERR_INVALID_STATE -.. py:data:: ERR_GZIP -.. py:data:: ERR_TEMPORAL_CALLBACK_FAILURE - -Following error codes indicate fatal error. - -.. py:data:: ERR_FATAL -.. py:data:: ERR_NOMEM -.. py:data:: ERR_CALLBACK_FAILURE - -Frame Types ------------ - -.. py:data:: SYN_STREAM - -.. py:data:: SYN_REPLY - -.. py:data:: RST_STREAM - -.. py:data:: SETTINGS - -.. py:data:: NOOP - - Note that this was deprecated in SPDY/3. - -.. py:data:: PING - -.. py:data:: GOAWAY - -.. py:data:: HEADERS - -.. py:data:: WINDOW_UPDATE - - This first appeared in SPDY/3. - -.. py:data:: CREDENTIAL - - This first appeared in SPDY/3. - -Control Frame Flags -------------------- - -.. py:data:: CTRL_FLAG_NONE - - Indicates no flags set. - -.. py:data:: CTRL_FLAG_FIN - -.. py:data:: CTRL_FLAG_UNIDIRECTIONAL - -Stream Status Codes -------------------- - -.. py:data:: OK - - This is not a valid status code for RST_STREAM. Don't use this in - :py:meth:`Session.submit_rst_stream()`. - -.. py:data:: PROTOCOL_ERROR - -.. py:data:: INVALID_STREAM - -.. py:data:: REFUSED_STREAM - -.. py:data:: UNSUPPORTED_VERSION - -.. py:data:: CANCEL - -.. py:data:: INTERNAL_ERROR - -.. py:data:: FLOW_CONTROL_ERROR - -Following status codes were introduced in SPDY/3. - -.. py:data:: STREAM_IN_USE - -.. py:data:: STREAM_ALREADY_CLOSED - -.. py:data:: INVALID_CREDENTIALS - -.. py:data:: FRAME_TOO_LARGE - -GOAWAY Status Codes -------------------- - -.. py:data:: GOAWAY_OK - -.. py:data:: GOAWAY_PROTOCOL_ERROR - -.. py:data:: GOAWAY_INTERNAL_ERROR - -SETTINGS Frame Flags --------------------- - -.. py:data:: FLAG_SETTINGS_NONE - -.. py:data:: FLAG_SETTINGS_CLEAR_SETTINGS - -SETTINGS IDs ------------- - -.. py:data:: SETTINGS_UPLOAD_BANDWIDTH - -.. py:data:: SETTINGS_DOWNLOAD_BANDWIDTH - -.. py:data:: SETTINGS_ROUND_TRIP_TIME - -.. py:data:: SETTINGS_MAX_CONCURRENT_STREAMS - -.. py:data:: SETTINGS_CURRENT_CWND - -.. py:data:: SETTINGS_DOWNLOAD_RETRANS_RATE - -.. py:data:: SETTINGS_INITIAL_WINDOW_SIZE - -.. py:data:: SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE - -.. py:data:: SETTINGS_MAX - -SETTINGS ID Flags ------------------ - -.. py:data:: ID_FLAG_SETTINGS_NONE - -.. py:data:: ID_FLAG_SETTINGS_PERSIST_VALUE - -.. py:data:: ID_FLAG_SETTINGS_PERSISTED - -Simple SPDY Client ------------------- - -This module offers a simple SPDY client implementation. The function -:py:func:`urlfetch()` fetches given URLs. For each URL, -*StreamHandlerClass* is instantiated and its methods are called when -certain event occurs. The *StreamHandlerClass* must be a subclass of -:py:class:`BaseSPDYStreamHandler`. - -.. py:function:: urlfetch(url_or_urls, StreamHandlerClass) - - Opens URL and handles the response from the servers. - - The *url_or_urls* is either one URL string or list of URL string. - For each URL, *StreamHandlerClass* is instantiated and it handles - the request to and response from the server. If successive URLs in - *url_or_urls* list have same origin, they are processed in one - SPDY session. - -.. py:class:: BaseSPDYStreamHandler(url, fetcher) - - This class handles one URL retrieval, which corresponds one SPDY - stream. The *url* is the URL to fetch. The *fetcher* is a driver - object to call methods of this object. For now it is opaque - object. This class is intended to be subclassed by the application - to add specific behavior. - - ``BaseSPDYStreamHandler`` has the following instance variables: - - .. py:attribute:: url - - The URL for this stream. - - .. py:attribute:: stream_id - - The stream ID for this stream. - - ``BaseSPDYStreamHandler`` has the following methods: - - .. py:method:: on_header(nv) - - Called when name/value pairs (headers) *nv* is received. This - method may be overridden by subclasses. The default - implementation does nothing. - - .. py:method:: on_data(data) - - Called when *data* is received. This method may be overridden - by subclass. The default implementation does nothing. - - .. py:method:: on_close(status_code) - - Called when this stream is closed. The *status_code* indicates - the reason of the closure. See `Stream Status Codes`_. This - method may be overridden by subclass. The default - implementation does nothing. - -The example follows: - -.. literalinclude:: ../python/spdyclient.py - :language: python - -Simple SPDY Server ------------------- - -This module offers a simple SPDY server implementation to ready for -use with little additional code. - -The :py:class:`ThreadedSPDYServer` is a ``socketserver.TCPServer`` -subclass. As the name of the class suggests, it is multi threaded. -It only supports SPDY connection and does not fallback to HTTP/1.1. -Since it uses TLS NPN extension, Python 3.3.0 or later is required. - -.. py:class:: ThreadedSPDYServer(server_address, RequestHandlerCalss, cert_file, key_file) - - This class builds on ``TCPServer`` class by passing - *server_address* and *RequestHandlerCalss*. The request is handled - by the instance of *RequestHandlerCalss*. - -The :py:class:`ThreadedSPDYServer` requires a *RequestHandlerCalss* on -instantiation, which must be a subclass of -:py:class:`BaseSPDYRequestHandler`. - -Most texts are copied (and modified) from ``http.server`` -documentation. - -.. py:class:: BaseSPDYRequestHandler(request, client_address, server) - - This class is used to handle the SPDY requests (streams) that - arrive at the server. By itself, it cannot respond to any actual - SPDY requests; it must be subclassed to handle each request method - (e.g. ``GET`` or ``POST``). ``BaseSPDYRequestHandler`` provides a - number of class and instance variables, and methods for use by - subclasses. - - The handler will gather headers (name/value pairs in SPDY terms) - and read POST data (if any), then call a method specific to the - request type. The method name is constructed from the request. For - example, for the request method ``SPAM``, the ``do_SPAM()`` method - will be called with no arguments. All of the relevant information - is stored in instance variables of the handler. Subclasses should - not need to override or extend the ``__init__()`` method. - - .. note:: - - Currently, this implementation accepts request body only if - method is POST and the request body will be stored in memory. - - ``BaseSPDYRequestHandler`` has the following instance variables: - - .. py:attribute:: client_address - - Contains a tuple of the form ``(host, port)`` referring to the - client's address. - - .. py:attribute:: server - - Contains the server instance. - - .. py:attribute:: command - - Contains the command (request type, method). For example, - ``GET``. - - .. py:attribute:: path - - Contains the request path. - - .. py:attribute:: request_version - - Contains the version string from the request. For example, - ``HTTP/1.1``. - - .. py:attribute:: headers - - Contains the request headers. Each name/value pair is a tuple - of the form ``(name, value)``. - - .. py:attribute:: rfile - - Contains an input stream, positioned at the start of the - optional input data. If there is no optional input data, it - may be ``None``. - - .. py:attribute:: wfile - - Contains the output stream for writing a response back to the - client. - - ``BaseSPDYRequestHandler`` has the following class variables: - - .. py:attribute:: server_version - - Specifies the server software version. - - .. py:attribute:: sys_version - - Contains the Python system version. - - A ``BaseSPDYRequestHandler`` instance has the following methods: - - .. py:method:: handle() - - Interacts client exchanging SPDY frames. When a request is - completely received, it calls appropriate ``do_*()`` method. - This method will handle multiple requests (streams) until SPDY - session is over. - - .. py:method:: send_error(code, message=None) - - Send a complete error reply to the client The numeric *code* - specifies the HTTP error code, with *message* as optional, - more specific text. A complete set of headers is sent, - followed by HTML text. - - .. py:method:: send_response(code, message=None) - - Adds a response code and, optionally, short message. - This will be formatted as ':status' response header field. - - .. py:method:: send_header(keyword, value) - - Adds the HTTP header. The *keyword* and *value* must be - unicode strings and not ``None``. - -The example of ``BaseSPDYRequestHandler`` and ``ThreadedSPDYServer`` -follows: - -.. literalinclude:: ../python/spdyserv.py - :language: python diff --git a/examples/Makefile.am b/examples/Makefile.am index 2515ae9b..8a65d114 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -27,7 +27,7 @@ AM_CFLAGS = -Wall AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \ @OPENSSL_CFLAGS@ @DEFS@ AM_LDFLAGS = @OPENSSL_LIBS@ -LDADD = $(top_builddir)/lib/libspdylay.la +LDADD = $(top_builddir)/lib/libnghttp2.la noinst_PROGRAMS = spdycli spdycli_SOURCES = spdycli.c diff --git a/examples/spdy.h b/examples/spdy.h index d2f921d9..22e27bf2 100644 --- a/examples/spdy.h +++ b/examples/spdy.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef SPDY_H #define SPDY_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include @@ -33,14 +33,14 @@ #include #include -#include "spdylay_ssl.h" +#include "nghttp2_ssl.h" #include "uri.h" #include "util.h" #include "SpdyServer.h" -using namespace spdylay; +using namespace nghttp2; -namespace spdylay { +namespace nghttp2 { class request { public: @@ -141,9 +141,9 @@ private: }; 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, - spdylay_data_source *source, void *user_data) + nghttp2_data_source *source, void *user_data) { std::pair& body_pair = *reinterpret_cast*>(source->ptr); @@ -159,7 +159,7 @@ ssize_t string_read_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(user_data); 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)); 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.read_callback = string_read_callback; hd->submit_response(response_obj.get_status_string(), stream_id, @@ -236,6 +236,6 @@ int run(Server& server) } // namespace reactor -} // namespace spdylay +} // namespace nghttp2 #endif // SPDY_H diff --git a/examples/spdycli.c b/examples/spdycli.c index e2c6885d..eb107f8b 100644 --- a/examples/spdycli.c +++ b/examples/spdycli.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - SPDY Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -23,7 +23,7 @@ * 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. */ #include @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include @@ -53,12 +53,12 @@ enum { struct Connection { SSL *ssl; - spdylay_session *session; + nghttp2_session *session; /* 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 - re-negotiation is possible at any time. Spdylay API offers - similar functions like spdylay_session_want_read() and - spdylay_session_want_write() but they do not take into account + re-negotiation is possible at any time. nghttp2 API offers + similar functions like nghttp2_session_want_read() and + nghttp2_session_want_write() but they do not take into account SSL connection. */ int want_io; }; @@ -74,7 +74,7 @@ struct Request { /* Stream ID for this request. */ int32_t stream_id; /* The gzip stream inflater for the compressed response. */ - spdylay_gzip *inflater; + nghttp2_gzip *inflater; }; struct URI { @@ -127,7 +127,7 @@ static void dief(const char *func, const char *msg) static void diec(const char *func, int 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); } @@ -150,7 +150,7 @@ static void check_gzip(struct Request *req, char **nv) if(req->inflater) { return; } - rv = spdylay_gzip_inflate_new(&req->inflater); + rv = nghttp2_gzip_inflate_new(&req->inflater); if(rv != 0) { 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 * 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, 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) { connection->want_io = (err == SSL_ERROR_WANT_READ ? WANT_READ : WANT_WRITE); - rv = SPDYLAY_ERR_WOULDBLOCK; + rv = NGHTTP2_ERR_WOULDBLOCK; } else { - rv = SPDYLAY_ERR_CALLBACK_FAILURE; + rv = NGHTTP2_ERR_CALLBACK_FAILURE; } } 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 * |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, 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) { connection->want_io = (err == SSL_ERROR_WANT_READ ? WANT_READ : WANT_WRITE); - rv = SPDYLAY_ERR_WOULDBLOCK; + rv = NGHTTP2_ERR_WOULDBLOCK; } else { - rv = SPDYLAY_ERR_CALLBACK_FAILURE; + rv = NGHTTP2_ERR_CALLBACK_FAILURE; } } else if(rv == 0) { - rv = SPDYLAY_ERR_EOF; + rv = NGHTTP2_ERR_EOF; } 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 * 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, - spdylay_frame_type type, - spdylay_frame *frame, +static void before_ctrl_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, void *user_data) { - if(type == SPDYLAY_SYN_STREAM) { + if(type == NGHTTP2_SYN_STREAM) { struct Request *req; 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) { req->stream_id = 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, - spdylay_frame_type type, - spdylay_frame *frame, void *user_data) +static void on_ctrl_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, void *user_data) { char **nv; const char *name = NULL; int32_t stream_id; size_t i; switch(type) { - case SPDYLAY_SYN_STREAM: + case NGHTTP2_SYN_STREAM: nv = frame->syn_stream.nv; name = "SYN_STREAM"; stream_id = frame->syn_stream.stream_id; @@ -256,7 +256,7 @@ static void on_ctrl_send_callback(spdylay_session *session, default: 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); for(i = 0; nv[i]; i += 2) { 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, - spdylay_frame_type type, - spdylay_frame *frame, void *user_data) +static void on_ctrl_recv_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, void *user_data) { struct Request *req; char **nv; @@ -274,12 +274,12 @@ static void on_ctrl_recv_callback(spdylay_session *session, int32_t stream_id; size_t i; switch(type) { - case SPDYLAY_SYN_REPLY: + case NGHTTP2_SYN_REPLY: nv = frame->syn_reply.nv; name = "SYN_REPLY"; stream_id = frame->syn_reply.stream_id; break; - case SPDYLAY_HEADERS: + case NGHTTP2_HEADERS: nv = frame->headers.nv; name = "HEADERS"; stream_id = frame->headers.stream_id; @@ -290,7 +290,7 @@ static void on_ctrl_recv_callback(spdylay_session *session, if(!name) { return; } - req = spdylay_session_get_stream_user_data(session, stream_id); + req = nghttp2_session_get_stream_user_data(session, stream_id); if(req) { check_gzip(req, nv); 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 * fetch 1 resource in this program, after reception of the response, * 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, - spdylay_status_code status_code, + nghttp2_status_code status_code, void *user_data) { 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) { int rv; - rv = spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK); + rv = nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK); 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 /* - * 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. */ -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, const uint8_t *data, size_t len, void *user_data) { 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) { printf("[INFO] C <---------------------------- S (DATA)\n"); 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 tlen = len; 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) { - spdylay_submit_rst_stream(session, stream_id, SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, stream_id, NGHTTP2_INTERNAL_ERROR); break; } 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 - * always required. Since we use spdylay_session_recv(), the + * always required. Since we use nghttp2_session_recv(), the * 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->recv_callback = recv_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 - * 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. */ static int select_next_proto_cb(SSL* ssl, @@ -391,9 +391,9 @@ static int select_next_proto_cb(SSL* ssl, { int rv; uint16_t *spdy_proto_version; - /* spdylay_select_next_protocol() selects SPDY protocol version the - Spdylay library supports. */ - rv = spdylay_select_next_protocol(out, outlen, in, inlen); + /* nghttp2_select_next_protocol() selects SPDY protocol version the + nghttp2 library supports. */ + rv = nghttp2_select_next_protocol(out, outlen, in, inlen); if(rv <= 0) { 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) { pollfd->events = 0; - if(spdylay_session_want_read(connection->session) || + if(nghttp2_session_want_read(connection->session) || connection->want_io == WANT_READ) { pollfd->events |= POLLIN; } - if(spdylay_session_want_write(connection->session) || + if(nghttp2_session_want_write(connection->session) || connection->want_io == WANT_WRITE) { pollfd->events |= POLLOUT; } @@ -527,11 +527,11 @@ static void submit_request(struct Connection *connection, struct Request *req) nv[6] = ":scheme"; nv[7] = "https"; nv[8] = ":host"; nv[9] = req->hostport; 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; - rv = spdylay_submit_request(connection->session, pri, nv, NULL, req); + rv = nghttp2_submit_request(connection->session, pri, nv, NULL, req); 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) { int rv; - rv = spdylay_session_recv(connection->session); + rv = nghttp2_session_recv(connection->session); 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) { - 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->path); 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) { - spdylay_session_callbacks callbacks; + nghttp2_session_callbacks callbacks; int fd; SSL_CTX *ssl_ctx; SSL *ssl; @@ -587,7 +587,7 @@ static void fetch_uri(const struct URI *uri) request_init(&req, uri); - setup_spdylay_callbacks(&callbacks); + setup_nghttp2_callbacks(&callbacks); /* Establish connection and setup SSL */ fd = connect_to(req.host, req.port); @@ -615,10 +615,10 @@ static void fetch_uri(const struct URI *uri) set_tcp_nodelay(fd); 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); if(rv != 0) { - diec("spdylay_session_client_new", rv); + diec("nghttp2_session_client_new", rv); } /* Submit the HTTP request to the outbound queue. */ @@ -628,8 +628,8 @@ static void fetch_uri(const struct URI *uri) ctl_poll(pollfds, &connection); /* Event loop */ - while(spdylay_session_want_read(connection.session) || - spdylay_session_want_write(connection.session)) { + while(nghttp2_session_want_read(connection.session) || + nghttp2_session_want_write(connection.session)) { int nfds = poll(pollfds, npollfds, -1); if(nfds == -1) { dief("poll", strerror(errno)); @@ -644,7 +644,7 @@ static void fetch_uri(const struct URI *uri) } /* Resource cleanup */ - spdylay_session_del(connection.session); + nghttp2_session_del(connection.session); SSL_shutdown(ssl); SSL_free(ssl); SSL_CTX_free(ssl_ctx); diff --git a/examples/spdynative.cc b/examples/spdynative.cc index 3e64bd15..235939c3 100644 --- a/examples/spdynative.cc +++ b/examples/spdynative.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/lib/Makefile.am b/lib/Makefile.am index f3fdc1c0..719f26a4 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -26,25 +26,25 @@ AM_CFLAGS = -Wall AM_CPPFLAGS = -I$(srcdir)/includes -I$(builddir)/includes @DEFS@ pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libspdylay.pc +pkgconfig_DATA = libnghttp2.pc DISTCLEANFILES = $(pkgconfig_DATA) -lib_LTLIBRARIES = libspdylay.la +lib_LTLIBRARIES = libnghttp2.la -OBJECTS = spdylay_pq.c spdylay_map.c spdylay_queue.c \ - spdylay_buffer.c spdylay_frame.c spdylay_zlib.c \ - spdylay_session.c spdylay_helper.c spdylay_stream.c spdylay_npn.c \ - spdylay_submit.c spdylay_outbound_item.c \ - spdylay_client_cert_vector.c spdylay_gzip.c +OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \ + nghttp2_buffer.c nghttp2_frame.c nghttp2_zlib.c \ + nghttp2_session.c nghttp2_helper.c nghttp2_stream.c nghttp2_npn.c \ + nghttp2_submit.c nghttp2_outbound_item.c \ + nghttp2_client_cert_vector.c nghttp2_gzip.c -HFILES = spdylay_pq.h spdylay_int.h spdylay_map.h spdylay_queue.h \ - spdylay_buffer.h spdylay_frame.h spdylay_zlib.h \ - spdylay_session.h spdylay_helper.h spdylay_stream.h spdylay_int.h \ - spdylay_npn.h spdylay_gzip.h \ - spdylay_submit.h spdylay_outbound_item.h \ - spdylay_client_cert_vector.h \ - spdylay_net.h +HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \ + nghttp2_buffer.h nghttp2_frame.h nghttp2_zlib.h \ + nghttp2_session.h nghttp2_helper.h nghttp2_stream.h nghttp2_int.h \ + nghttp2_npn.h nghttp2_gzip.h \ + nghttp2_submit.h nghttp2_outbound_item.h \ + nghttp2_client_cert_vector.h \ + nghttp2_net.h -libspdylay_la_SOURCES = $(HFILES) $(OBJECTS) -libspdylay_la_LDFLAGS = -no-undefined \ +libnghttp2_la_SOURCES = $(HFILES) $(OBJECTS) +libnghttp2_la_LDFLAGS = -no-undefined \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) diff --git a/lib/includes/Makefile.am b/lib/includes/Makefile.am index 3d466fea..dec70162 100644 --- a/lib/includes/Makefile.am +++ b/lib/includes/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -20,4 +20,4 @@ # 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. -nobase_include_HEADERS = spdylay/spdylay.h spdylay/spdylayver.h +nobase_include_HEADERS = nghttp2/nghttp2.h nghttp2/nghttp2ver.h diff --git a/lib/includes/spdylay/spdylay.h b/lib/includes/nghttp2/nghttp2.h similarity index 70% rename from lib/includes/spdylay/spdylay.h rename to lib/includes/nghttp2/nghttp2.h index 583348f9..59987d86 100644 --- a/lib/includes/spdylay/spdylay.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,8 +22,8 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_H -#define SPDYLAY_H +#ifndef NGHTTP2_H +#define NGHTTP2_H #ifdef __cplusplus extern "C" { @@ -33,9 +33,9 @@ extern "C" { #include #include -#include +#include -struct spdylay_session; +struct nghttp2_session; /** * @struct * @@ -43,7 +43,7 @@ struct spdylay_session; * session. The details of this structure are intentionally hidden * from the public API. */ -typedef struct spdylay_session spdylay_session; +typedef struct nghttp2_session nghttp2_session; /** * @enum @@ -54,12 +54,12 @@ typedef enum { /** * SPDY protocol version 2 */ - SPDYLAY_PROTO_SPDY2 = 2, + NGHTTP2_PROTO_SPDY2 = 2, /** * SPDY protocol version 3 */ - SPDYLAY_PROTO_SPDY3 = 3 -} spdylay_proto_version; + NGHTTP2_PROTO_SPDY3 = 3 +} nghttp2_proto_version; /** * @enum @@ -71,81 +71,81 @@ typedef enum { /** * Invalid argument passed. */ - SPDYLAY_ERR_INVALID_ARGUMENT = -501, + NGHTTP2_ERR_INVALID_ARGUMENT = -501, /** * Zlib error. */ - SPDYLAY_ERR_ZLIB = -502, + NGHTTP2_ERR_ZLIB = -502, /** * The specified protocol version is not supported. */ - SPDYLAY_ERR_UNSUPPORTED_VERSION = -503, + NGHTTP2_ERR_UNSUPPORTED_VERSION = -503, /** - * Used as a return value from :type:`spdylay_send_callback` and - * :type:`spdylay_recv_callback` to indicate that the operation + * Used as a return value from :type:`nghttp2_send_callback` and + * :type:`nghttp2_recv_callback` to indicate that the operation * would block. */ - SPDYLAY_ERR_WOULDBLOCK = -504, + NGHTTP2_ERR_WOULDBLOCK = -504, /** * General protocol error */ - SPDYLAY_ERR_PROTO = -505, + NGHTTP2_ERR_PROTO = -505, /** * The frame is invalid. */ - SPDYLAY_ERR_INVALID_FRAME = -506, + NGHTTP2_ERR_INVALID_FRAME = -506, /** * The peer performed a shutdown on the connection. */ - SPDYLAY_ERR_EOF = -507, + NGHTTP2_ERR_EOF = -507, /** * Used as a return value from - * :func:`spdylay_data_source_read_callback` to indicate that data + * :func:`nghttp2_data_source_read_callback` to indicate that data * transfer is postponed. See - * :func:`spdylay_data_source_read_callback` for details. + * :func:`nghttp2_data_source_read_callback` for details. */ - SPDYLAY_ERR_DEFERRED = -508, + NGHTTP2_ERR_DEFERRED = -508, /** * Stream ID has reached the maximum value. Therefore no stream ID * is available. */ - SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE = -509, + NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509, /** * The stream is already closed; or the stream ID is invalid. */ - SPDYLAY_ERR_STREAM_CLOSED = -510, + NGHTTP2_ERR_STREAM_CLOSED = -510, /** * RST_STREAM has been added to the outbound queue. The stream is in * closing state. */ - SPDYLAY_ERR_STREAM_CLOSING = -511, + NGHTTP2_ERR_STREAM_CLOSING = -511, /** * The transmission is not allowed for this stream (e.g., a frame * with FLAG_FIN flag set has already sent). */ - SPDYLAY_ERR_STREAM_SHUT_WR = -512, + NGHTTP2_ERR_STREAM_SHUT_WR = -512, /** * The stream ID is invalid. */ - SPDYLAY_ERR_INVALID_STREAM_ID = -513, + NGHTTP2_ERR_INVALID_STREAM_ID = -513, /** * The state of the stream is not valid (e.g., SYN_REPLY cannot be * sent to the stream if SYN_REPLY has already been sent). */ - SPDYLAY_ERR_INVALID_STREAM_STATE = -514, + NGHTTP2_ERR_INVALID_STREAM_STATE = -514, /** * Another DATA frame has already been deferred. */ - SPDYLAY_ERR_DEFERRED_DATA_EXIST = -515, + NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515, /** * SYN_STREAM is not allowed. (e.g., GOAWAY has been sent and/or * received. */ - SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED = -516, + NGHTTP2_ERR_SYN_STREAM_NOT_ALLOWED = -516, /** * GOAWAY has already been sent. */ - SPDYLAY_ERR_GOAWAY_ALREADY_SENT = -517, + NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517, /** * The received frame contains the invalid header block. (e.g., * There are duplicate header names; or the header names are not @@ -153,43 +153,43 @@ typedef enum { * header name is zero-length string; or the header value contains * multiple in-sequence NUL bytes). */ - SPDYLAY_ERR_INVALID_HEADER_BLOCK = -518, + NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518, /** * Indicates that the context is not suitable to perform the * requested operation. */ - SPDYLAY_ERR_INVALID_STATE = -519, + NGHTTP2_ERR_INVALID_STATE = -519, /** * The gzip error. */ - SPDYLAY_ERR_GZIP = -520, + NGHTTP2_ERR_GZIP = -520, /** * The user callback function failed due to the temporal error. */ - SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE = -521, + NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521, /** * The length of the frame is too large. */ - SPDYLAY_ERR_FRAME_TOO_LARGE = -522, + NGHTTP2_ERR_FRAME_TOO_LARGE = -522, /** - * The errors < :enum:`SPDYLAY_ERR_FATAL` mean that the library is + * The errors < :enum:`NGHTTP2_ERR_FATAL` mean that the library is * under unexpected condition and cannot process any further data * reliably (e.g., out of memory). */ - SPDYLAY_ERR_FATAL = -900, + NGHTTP2_ERR_FATAL = -900, /** * Out of memory. This is a fatal error. */ - SPDYLAY_ERR_NOMEM = -901, + NGHTTP2_ERR_NOMEM = -901, /** * The user callback function failed. This is a fatal error. */ - SPDYLAY_ERR_CALLBACK_FAILURE = -902 -} spdylay_error; + NGHTTP2_ERR_CALLBACK_FAILURE = -902 +} nghttp2_error; typedef enum { - SPDYLAY_MSG_MORE -} spdylay_io_flag; + NGHTTP2_MSG_MORE +} nghttp2_io_flag; /** * @enum @@ -199,44 +199,44 @@ typedef enum { /** * The SYN_STREAM control frame. */ - SPDYLAY_SYN_STREAM = 1, + NGHTTP2_SYN_STREAM = 1, /** * The SYN_REPLY control frame. */ - SPDYLAY_SYN_REPLY = 2, + NGHTTP2_SYN_REPLY = 2, /** * The RST_STREAM control frame. */ - SPDYLAY_RST_STREAM = 3, + NGHTTP2_RST_STREAM = 3, /** * The SETTINGS control frame. */ - SPDYLAY_SETTINGS = 4, + NGHTTP2_SETTINGS = 4, /** * The NOOP control frame. This was deprecated in SPDY/3. */ - SPDYLAY_NOOP = 5, + NGHTTP2_NOOP = 5, /** * The PING control frame. */ - SPDYLAY_PING = 6, + NGHTTP2_PING = 6, /** * The GOAWAY control frame. */ - SPDYLAY_GOAWAY = 7, + NGHTTP2_GOAWAY = 7, /** * The HEADERS control frame. */ - SPDYLAY_HEADERS = 8, + NGHTTP2_HEADERS = 8, /** * The WINDOW_UPDATE control frame. This first appeared in SPDY/3. */ - SPDYLAY_WINDOW_UPDATE = 9, + NGHTTP2_WINDOW_UPDATE = 9, /** * The CREDENTIAL control frame. This first appeared in SPDY/3. */ - SPDYLAY_CREDENTIAL = 10 -} spdylay_frame_type; + NGHTTP2_CREDENTIAL = 10 +} nghttp2_frame_type; /** * @enum @@ -247,16 +247,16 @@ typedef enum { /** * No flag set. */ - SPDYLAY_CTRL_FLAG_NONE = 0, + NGHTTP2_CTRL_FLAG_NONE = 0, /** * FLAG_FIN flag. */ - SPDYLAY_CTRL_FLAG_FIN = 0x1, + NGHTTP2_CTRL_FLAG_FIN = 0x1, /** * FLAG_UNIDIRECTIONAL flag. */ - SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL = 0x2 -} spdylay_ctrl_flag; + NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL = 0x2 +} nghttp2_ctrl_flag; /** * @enum @@ -266,12 +266,12 @@ typedef enum { /** * No flag set. */ - SPDYLAY_DATA_FLAG_NONE = 0, + NGHTTP2_DATA_FLAG_NONE = 0, /** * FLAG_FIN flag. */ - SPDYLAY_DATA_FLAG_FIN = 0x1 -} spdylay_data_flag; + NGHTTP2_DATA_FLAG_FIN = 0x1 +} nghttp2_data_flag; /** * @enum @@ -281,12 +281,12 @@ typedef enum { /** * No flag set. */ - SPDYLAY_FLAG_SETTINGS_NONE = 0, + NGHTTP2_FLAG_SETTINGS_NONE = 0, /** * SETTINGS_CLEAR_SETTINGS flag. */ - SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS = 1 -} spdylay_settings_flag; + NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS = 1 +} nghttp2_settings_flag; /** * @enum @@ -296,16 +296,16 @@ typedef enum { /** * No flag set. */ - SPDYLAY_ID_FLAG_SETTINGS_NONE = 0, + NGHTTP2_ID_FLAG_SETTINGS_NONE = 0, /** * FLAG_SETTINGS_PERSIST_VALUE flag. */ - SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE = 1, + NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE = 1, /** * FLAG_SETTINGS_PERSISTED flag. */ - SPDYLAY_ID_FLAG_SETTINGS_PERSISTED = 2 -} spdylay_settings_id_flag; + NGHTTP2_ID_FLAG_SETTINGS_PERSISTED = 2 +} nghttp2_settings_id_flag; /** * @enum @@ -315,47 +315,47 @@ typedef enum { /** * SETTINGS_UPLOAD_BANDWIDTH */ - SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH = 1, + NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH = 1, /** * SETTINGS_DOWNLOAD_BANDWIDTH */ - SPDYLAY_SETTINGS_DOWNLOAD_BANDWIDTH = 2, + NGHTTP2_SETTINGS_DOWNLOAD_BANDWIDTH = 2, /** * SETTINGS_ROUND_TRIP_TIME */ - SPDYLAY_SETTINGS_ROUND_TRIP_TIME = 3, + NGHTTP2_SETTINGS_ROUND_TRIP_TIME = 3, /** * SETTINGS_MAX_CONCURRENT_STREAMS */ - SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS = 4, + NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 4, /** * SETTINGS_CURRENT_CWND */ - SPDYLAY_SETTINGS_CURRENT_CWND = 5, + NGHTTP2_SETTINGS_CURRENT_CWND = 5, /** * SETTINGS_DOWNLOAD_RETRANS_RATE */ - SPDYLAY_SETTINGS_DOWNLOAD_RETRANS_RATE = 6, + NGHTTP2_SETTINGS_DOWNLOAD_RETRANS_RATE = 6, /** * SETTINGS_INITIAL_WINDOW_SIZE */ - SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE = 7, + NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 7, /** * SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE. This first appeared in * SPDY/3. */ - SPDYLAY_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE = 8, + NGHTTP2_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE = 8, /** - * Maximum ID of :type:`spdylay_settings_id`. + * Maximum ID of :type:`nghttp2_settings_id`. */ - SPDYLAY_SETTINGS_MAX = 8 -} spdylay_settings_id; + NGHTTP2_SETTINGS_MAX = 8 +} nghttp2_settings_id; /** * @macro * Default maximum concurrent streams. */ -#define SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS 100 +#define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS 100 /** * @enum @@ -363,56 +363,56 @@ typedef enum { */ typedef enum { /** - * SPDYLAY_OK is not valid status code for RST_STREAM. It is defined - * just for spdylay library use. + * NGHTTP2_OK is not valid status code for RST_STREAM. It is defined + * just for nghttp2 library use. */ - SPDYLAY_OK = 0, + NGHTTP2_OK = 0, /** * PROTOCOL_ERROR */ - SPDYLAY_PROTOCOL_ERROR = 1, + NGHTTP2_PROTOCOL_ERROR = 1, /** * INVALID_STREAM */ - SPDYLAY_INVALID_STREAM = 2, + NGHTTP2_INVALID_STREAM = 2, /** * REFUSED_STREAM */ - SPDYLAY_REFUSED_STREAM = 3, + NGHTTP2_REFUSED_STREAM = 3, /** * UNSUPPORTED_VERSION */ - SPDYLAY_UNSUPPORTED_VERSION = 4, + NGHTTP2_UNSUPPORTED_VERSION = 4, /** * CANCEL */ - SPDYLAY_CANCEL = 5, + NGHTTP2_CANCEL = 5, /** * INTERNAL_ERROR */ - SPDYLAY_INTERNAL_ERROR = 6, + NGHTTP2_INTERNAL_ERROR = 6, /** * FLOW_CONTROL_ERROR */ - SPDYLAY_FLOW_CONTROL_ERROR = 7, + NGHTTP2_FLOW_CONTROL_ERROR = 7, /* Following status codes were introduced in SPDY/3 */ /** * STREAM_IN_USE */ - SPDYLAY_STREAM_IN_USE = 8, + NGHTTP2_STREAM_IN_USE = 8, /** * STREAM_ALREADY_CLOSED */ - SPDYLAY_STREAM_ALREADY_CLOSED = 9, + NGHTTP2_STREAM_ALREADY_CLOSED = 9, /** * INVALID_CREDENTIALS */ - SPDYLAY_INVALID_CREDENTIALS = 10, + NGHTTP2_INVALID_CREDENTIALS = 10, /** * FRAME_TOO_LARGE */ - SPDYLAY_FRAME_TOO_LARGE = 11 -} spdylay_status_code; + NGHTTP2_FRAME_TOO_LARGE = 11 +} nghttp2_status_code; /** * @enum @@ -422,16 +422,16 @@ typedef enum { /** * OK. This indicates a normal session teardown. */ - SPDYLAY_GOAWAY_OK = 0, + NGHTTP2_GOAWAY_OK = 0, /** * PROTOCOL_ERROR */ - SPDYLAY_GOAWAY_PROTOCOL_ERROR = 1, + NGHTTP2_GOAWAY_PROTOCOL_ERROR = 1, /** * INTERNAL_ERROR */ - SPDYLAY_GOAWAY_INTERNAL_ERROR = 2 -} spdylay_goaway_status_code; + NGHTTP2_GOAWAY_INTERNAL_ERROR = 2 +} nghttp2_goaway_status_code; /** * @struct @@ -454,7 +454,7 @@ typedef struct { * The length field of this control frame. */ int32_t length; -} spdylay_ctrl_hd; +} nghttp2_ctrl_hd; /** * @struct @@ -464,7 +464,7 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The stream ID. */ @@ -476,7 +476,7 @@ typedef struct { int32_t assoc_stream_id; /** * The priority of this frame. 0 is the highest priority value. Use - * `spdylay_session_get_pri_lowest()` to know the lowest priority + * `nghttp2_session_get_pri_lowest()` to know the lowest priority * value. */ uint8_t pri; @@ -493,7 +493,7 @@ typedef struct { * ``NULL``. This member may be ``NULL``. */ char **nv; -} spdylay_syn_stream; +} nghttp2_syn_stream; /** * @struct @@ -503,7 +503,7 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The stream ID. */ @@ -516,7 +516,7 @@ typedef struct { * ``NULL``. This member may be ``NULL``. */ char **nv; -} spdylay_syn_reply; +} nghttp2_syn_reply; /** * @struct @@ -526,7 +526,7 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The stream ID. */ @@ -539,7 +539,7 @@ typedef struct { * ``NULL``. This member may be ``NULL``. */ char **nv; -} spdylay_headers; +} nghttp2_headers; /** * @struct @@ -549,16 +549,16 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The stream ID. */ int32_t stream_id; /** - * The status code. See :type:`spdylay_status_code`. + * The status code. See :type:`nghttp2_status_code`. */ uint32_t status_code; -} spdylay_rst_stream; +} nghttp2_rst_stream; /** * @struct @@ -566,18 +566,18 @@ typedef struct { */ typedef struct { /** - * The SETTINGS ID. See :type:`spdylay_settings_id`. + * The SETTINGS ID. See :type:`nghttp2_settings_id`. */ int32_t settings_id; /** - * The flags. See :type:`spdylay_settings_id_flag`. + * The flags. See :type:`nghttp2_settings_id_flag`. */ uint8_t flags; /** * The value of this entry. */ uint32_t value; -} spdylay_settings_entry; +} nghttp2_settings_entry; /** * @struct @@ -587,7 +587,7 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The number of SETTINGS ID/Value pairs in |iv|. */ @@ -595,8 +595,8 @@ typedef struct { /** * The pointer to the array of SETTINGS ID/Value pair. */ - spdylay_settings_entry *iv; -} spdylay_settings; + nghttp2_settings_entry *iv; +} nghttp2_settings; /** * @struct @@ -606,12 +606,12 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The unique ID. */ uint32_t unique_id; -} spdylay_ping; +} nghttp2_ping; /** * @struct @@ -621,17 +621,17 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The last-good-stream ID. */ int32_t last_good_stream_id; /** * The status code. This first appeared in SPDY/3. See - * :type:`spdylay_goaway_status_code`. + * :type:`nghttp2_goaway_status_code`. */ uint32_t status_code; -} spdylay_goaway; +} nghttp2_goaway; /** * @struct @@ -643,7 +643,7 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The stream ID. */ @@ -652,7 +652,7 @@ typedef struct { * The delta-window-size. */ int32_t delta_window_size; -} spdylay_window_update; +} nghttp2_window_update; /** * @struct @@ -668,7 +668,7 @@ typedef struct { * The length of the data. */ size_t length; -} spdylay_mem_chunk; +} nghttp2_mem_chunk; /** * @struct @@ -680,7 +680,7 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; + nghttp2_ctrl_hd hd; /** * The index in the client certificate vector. */ @@ -689,16 +689,16 @@ typedef struct { * Cryptographic proof that the client has possession of the private * key associated with the certificate. */ - spdylay_mem_chunk proof; + nghttp2_mem_chunk proof; /** * The certificate chain. The certs[0] is the leaf certificate. */ - spdylay_mem_chunk *certs; + nghttp2_mem_chunk *certs; /** * The number of certificates in |certs|. */ size_t ncerts; -} spdylay_credential; +} nghttp2_credential; /** * @struct @@ -710,14 +710,14 @@ typedef struct { /** * The control frame header. */ - spdylay_ctrl_hd hd; -} spdylay_ctrl_frame; + nghttp2_ctrl_hd hd; +} nghttp2_ctrl_frame; /** * @union * * This union represents the some kind of data source passed to - * :type:`spdylay_data_source_read_callback`. + * :type:`nghttp2_data_source_read_callback`. */ typedef union { /** @@ -728,7 +728,7 @@ typedef union { * The pointer to an arbitrary object. */ void *ptr; -} spdylay_data_source; +} nghttp2_data_source; /** * @functypedef @@ -740,20 +740,20 @@ typedef union { * |buf| and return number of data stored in |buf|. If EOF is reached, * set |*eof| to 1. If the application wants to postpone DATA frames, * (e.g., asynchronous I/O, or reading data blocks for long time), it - * is achieved by returning :enum:`SPDYLAY_ERR_DEFERRED` without + * is achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without * reading any data in this invocation. The library removes DATA * frame from the outgoing queue temporarily. To move back deferred - * DATA frame to outgoing queue, call `spdylay_session_resume_data()`. + * DATA frame to outgoing queue, call `nghttp2_session_resume_data()`. * In case of error, there are 2 choices. Returning - * :enum:`SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream - * by issuing RST_STREAM with :enum:`SPDYLAY_INTERNAL_ERROR`. - * Returning :enum:`SPDYLAY_ERR_CALLBACK_FAILURE` will signal the + * :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream + * by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`. + * Returning :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the * entire session failure. */ -typedef ssize_t (*spdylay_data_source_read_callback) -(spdylay_session *session, int32_t stream_id, +typedef ssize_t (*nghttp2_data_source_read_callback) +(nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, int *eof, - spdylay_data_source *source, void *user_data); + nghttp2_data_source *source, void *user_data); /** * @struct @@ -765,61 +765,61 @@ typedef struct { /** * The data source. */ - spdylay_data_source source; + nghttp2_data_source source; /** * The callback function to read a chunk of data from the |source|. */ - spdylay_data_source_read_callback read_callback; -} spdylay_data_provider; + nghttp2_data_source_read_callback read_callback; +} nghttp2_data_provider; /** * @union * * This union includes all control frames to pass them - * to various function calls as spdylay_frame type. + * to various function calls as nghttp2_frame type. */ typedef union { /** * Convenient structure to inspect control frame header. */ - spdylay_ctrl_frame ctrl; + nghttp2_ctrl_frame ctrl; /** * The SYN_STREAM control frame. */ - spdylay_syn_stream syn_stream; + nghttp2_syn_stream syn_stream; /** * The SYN_REPLY control frame. */ - spdylay_syn_reply syn_reply; + nghttp2_syn_reply syn_reply; /** * The RST_STREAM control frame. */ - spdylay_rst_stream rst_stream; + nghttp2_rst_stream rst_stream; /** * The SETTINGS control frame. */ - spdylay_settings settings; + nghttp2_settings settings; /** * The PING control frame. */ - spdylay_ping ping; + nghttp2_ping ping; /** * The GOAWAY control frame. */ - spdylay_goaway goaway; + nghttp2_goaway goaway; /** * The HEADERS control frame. */ - spdylay_headers headers; + nghttp2_headers headers; /** * The WINDOW_UPDATE control frame. */ - spdylay_window_update window_update; + nghttp2_window_update window_update; /** * The CREDENTIAL control frame. */ - spdylay_credential credential; -} spdylay_frame; + nghttp2_credential credential; +} nghttp2_frame; /** * @functypedef @@ -829,11 +829,11 @@ typedef union { * |length| bytes of data stored in |data|. The |flags| is currently * not used and always 0. It must return the number of bytes sent if * it succeeds. If it cannot send any single byte without blocking, - * it must return :enum:`SPDYLAY_ERR_WOULDBLOCK`. For other errors, it - * must return :enum:`SPDYLAY_ERR_CALLBACK_FAILURE`. + * it must return :enum:`NGHTTP2_ERR_WOULDBLOCK`. For other errors, it + * must return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. */ -typedef ssize_t (*spdylay_send_callback) -(spdylay_session *session, +typedef ssize_t (*nghttp2_send_callback) +(nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data); /** @@ -844,36 +844,36 @@ typedef ssize_t (*spdylay_send_callback) * most |length| bytes of data and store it in |buf|. The |flags| is * currently not used and always 0. It must return the number of bytes * written in |buf| if it succeeds. If it cannot read any single byte - * without blocking, it must return :enum:`SPDYLAY_ERR_WOULDBLOCK`. If + * without blocking, it must return :enum:`NGHTTP2_ERR_WOULDBLOCK`. If * it gets EOF before it reads any single byte, it must return - * :enum:`SPDYLAY_ERR_EOF`. For other errors, it must return - * :enum:`SPDYLAY_ERR_CALLBACK_FAILURE`. + * :enum:`NGHTTP2_ERR_EOF`. For other errors, it must return + * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. */ -typedef ssize_t (*spdylay_recv_callback) -(spdylay_session *session, +typedef ssize_t (*nghttp2_recv_callback) +(nghttp2_session *session, uint8_t *buf, size_t length, int flags, void *user_data); /** * @functypedef * - * Callback function invoked by `spdylay_session_recv()` when a + * Callback function invoked by `nghttp2_session_recv()` when a * control frame is received. */ -typedef void (*spdylay_on_ctrl_recv_callback) -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +typedef void (*nghttp2_on_ctrl_recv_callback) +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, void *user_data); /** * @functypedef * - * Callback function invoked by `spdylay_session_recv()` when an + * Callback function invoked by `nghttp2_session_recv()` when an * invalid control frame is received. The |status_code| is one of the - * :enum:`spdylay_status_code` and indicates the error. When this + * :enum:`nghttp2_status_code` and indicates the error. When this * callback function is invoked, the library automatically submits * either RST_STREAM or GOAWAY frame. */ -typedef void (*spdylay_on_invalid_ctrl_recv_callback) -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +typedef void (*nghttp2_on_invalid_ctrl_recv_callback) +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, uint32_t status_code, void *user_data); /** @@ -882,13 +882,13 @@ typedef void (*spdylay_on_invalid_ctrl_recv_callback) * Callback function invoked when a chunk of data in DATA frame is * received. The |stream_id| is the stream ID this DATA frame belongs * to. The |flags| is the flags of DATA frame which this data chunk is - * contained. ``(flags & SPDYLAY_DATA_FLAG_FIN) != 0`` does not + * contained. ``(flags & NGHTTP2_DATA_FLAG_FIN) != 0`` does not * necessarily mean this chunk of data is the last one in the - * stream. You should use :type:`spdylay_on_data_recv_callback` to + * stream. You should use :type:`nghttp2_on_data_recv_callback` to * know all data frames are received. */ -typedef void (*spdylay_on_data_chunk_recv_callback) -(spdylay_session *session, uint8_t flags, int32_t stream_id, +typedef void (*nghttp2_on_data_chunk_recv_callback) +(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data); /** @@ -896,10 +896,10 @@ typedef void (*spdylay_on_data_chunk_recv_callback) * * Callback function invoked when DATA frame is received. The actual * data it contains are received by - * :type:`spdylay_on_data_chunk_recv_callback`. + * :type:`nghttp2_on_data_chunk_recv_callback`. */ -typedef void (*spdylay_on_data_recv_callback) -(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length, +typedef void (*nghttp2_on_data_recv_callback) +(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length, void *user_data); /** @@ -908,11 +908,11 @@ typedef void (*spdylay_on_data_recv_callback) * Callback function invoked before the control frame |frame| of type * |type| is sent. This may be useful, for example, to know the stream * ID of SYN_STREAM frame (see also - * `spdylay_session_get_stream_user_data()`), which is not assigned + * `nghttp2_session_get_stream_user_data()`), which is not assigned * when it was queued. */ -typedef void (*spdylay_before_ctrl_send_callback) -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +typedef void (*nghttp2_before_ctrl_send_callback) +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, void *user_data); /** @@ -921,8 +921,8 @@ typedef void (*spdylay_before_ctrl_send_callback) * Callback function invoked after the control frame |frame| of type * |type| is sent. */ -typedef void (*spdylay_on_ctrl_send_callback) -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +typedef void (*nghttp2_on_ctrl_send_callback) +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, void *user_data); /** @@ -931,10 +931,10 @@ typedef void (*spdylay_on_ctrl_send_callback) * Callback function invoked after the control frame |frame| of type * |type| is not sent because of the error. The error is indicated by * the |error_code|, which is one of the values defined in - * :type:`spdylay_error`. + * :type:`nghttp2_error`. */ -typedef void (*spdylay_on_ctrl_not_send_callback) -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +typedef void (*nghttp2_on_ctrl_not_send_callback) +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, int error_code, void *user_data); /** @@ -942,8 +942,8 @@ typedef void (*spdylay_on_ctrl_not_send_callback) * * Callback function invoked after DATA frame is sent. */ -typedef void (*spdylay_on_data_send_callback) -(spdylay_session *session, uint8_t flags, int32_t stream_id, int32_t length, +typedef void (*nghttp2_on_data_send_callback) +(nghttp2_session *session, uint8_t flags, int32_t stream_id, int32_t length, void *user_data); /** @@ -952,11 +952,11 @@ typedef void (*spdylay_on_data_send_callback) * Callback function invoked when the stream |stream_id| is * closed. The reason of closure is indicated by the * |status_code|. The stream_user_data, which was specified in - * `spdylay_submit_request()` or `spdylay_submit_syn_stream()`, is + * `nghttp2_submit_request()` or `nghttp2_submit_syn_stream()`, is * still available in this function. */ -typedef void (*spdylay_on_stream_close_callback) -(spdylay_session *session, int32_t stream_id, spdylay_status_code status_code, +typedef void (*nghttp2_on_stream_close_callback) +(nghttp2_session *session, int32_t stream_id, nghttp2_status_code status_code, void *user_data); /** @@ -967,8 +967,8 @@ typedef void (*spdylay_on_stream_close_callback) * In HTTP, this means HTTP request, including request body, is fully * received. */ -typedef void (*spdylay_on_request_recv_callback) -(spdylay_session *session, int32_t stream_id, void *user_data); +typedef void (*nghttp2_on_request_recv_callback) +(nghttp2_session *session, int32_t stream_id, void *user_data); /** * @functypedef @@ -982,11 +982,11 @@ typedef void (*spdylay_on_request_recv_callback) * The |payload| is the pointer to the data portion of the received * frame. The |payloadlen| is the length of the |payload|. This is * the data after the length field. The |error_code| is one of the - * error code defined in :enum:`spdylay_error` and indicates the + * error code defined in :enum:`nghttp2_error` and indicates the * error. */ -typedef void (*spdylay_on_ctrl_recv_parse_error_callback) -(spdylay_session *session, spdylay_frame_type type, +typedef void (*nghttp2_on_ctrl_recv_parse_error_callback) +(nghttp2_session *session, nghttp2_frame_type type, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, int error_code, void *user_data); @@ -1003,16 +1003,16 @@ typedef void (*spdylay_on_ctrl_recv_parse_error_callback) * |payloadlen| is the length of the |payload|. This is the data after * the length field. */ -typedef void (*spdylay_on_unknown_ctrl_recv_callback) -(spdylay_session *session, +typedef void (*nghttp2_on_unknown_ctrl_recv_callback) +(nghttp2_session *session, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, void *user_data); -#define SPDYLAY_MAX_SCHEME 255 -#define SPDYLAY_MAX_HOSTNAME 255 +#define NGHTTP2_MAX_SCHEME 255 +#define NGHTTP2_MAX_HOSTNAME 255 -struct spdylay_origin; +struct nghttp2_origin; /** * @struct @@ -1021,28 +1021,28 @@ struct spdylay_origin; * port). The details of this structure is intentionally hidden. To * access these members, use accessor functions below. */ -typedef struct spdylay_origin spdylay_origin; +typedef struct nghttp2_origin nghttp2_origin; /** * @function * * Returns the scheme member of the |origin|. */ -const char* spdylay_origin_get_scheme(const spdylay_origin *origin); +const char* nghttp2_origin_get_scheme(const nghttp2_origin *origin); /** * @function * * Returns the host member of the |origin|. */ -const char* spdylay_origin_get_host(const spdylay_origin *origin); +const char* nghttp2_origin_get_host(const nghttp2_origin *origin); /** * @function * * Returns the port member of the |origin|. */ -uint16_t spdylay_origin_get_port(const spdylay_origin *origin); +uint16_t nghttp2_origin_get_port(const nghttp2_origin *origin); /** * @functypedef @@ -1058,8 +1058,8 @@ uint16_t spdylay_origin_get_port(const spdylay_origin *origin); * the application code may be required to pass the same proof more * than once. */ -typedef ssize_t (*spdylay_get_credential_proof) -(spdylay_session *session, const spdylay_origin *origin, +typedef ssize_t (*nghttp2_get_credential_proof) +(nghttp2_session *session, const nghttp2_origin *origin, uint8_t *proof, size_t prooflen, void *user_data); /** @@ -1070,12 +1070,12 @@ typedef ssize_t (*spdylay_get_credential_proof) * implementation of this function must return the length of the * client certificate chain. If no client certificate is required for * the given |origin|, return 0. If positive integer is returned, - * :type:`spdylay_get_credential_proof` and - * :type:`spdylay_get_credential_cert` callback functions will be used + * :type:`nghttp2_get_credential_proof` and + * :type:`nghttp2_get_credential_cert` callback functions will be used * to get the cryptographic proof and certificate respectively. */ -typedef ssize_t (*spdylay_get_credential_ncerts) -(spdylay_session *session, const spdylay_origin *origin, void *user_data); +typedef ssize_t (*nghttp2_get_credential_ncerts) +(nghttp2_session *session, const nghttp2_origin *origin, void *user_data); /** * @functypedef @@ -1088,8 +1088,8 @@ typedef ssize_t (*spdylay_get_credential_ncerts) * |certlen| > 0, write certificate into |cert| exactly |certlen| * bytes and return 0. */ -typedef ssize_t (*spdylay_get_credential_cert) -(spdylay_session *session, const spdylay_origin *origin, size_t idx, +typedef ssize_t (*nghttp2_get_credential_cert) +(nghttp2_session *session, const nghttp2_origin *origin, size_t idx, uint8_t *cert, size_t certlen, void *user_data); /** @@ -1102,84 +1102,84 @@ typedef struct { * Callback function invoked when the |session| wants to send data * to the remote peer. */ - spdylay_send_callback send_callback; + nghttp2_send_callback send_callback; /** * Callback function invoked when the |session| wants to receive * data from the remote peer. */ - spdylay_recv_callback recv_callback; + nghttp2_recv_callback recv_callback; /** - * Callback function invoked by `spdylay_session_recv()` when a + * Callback function invoked by `nghttp2_session_recv()` when a * control frame is received. */ - spdylay_on_ctrl_recv_callback on_ctrl_recv_callback; + nghttp2_on_ctrl_recv_callback on_ctrl_recv_callback; /** - * Callback function invoked by `spdylay_session_recv()` when an + * Callback function invoked by `nghttp2_session_recv()` when an * invalid control frame is received. */ - spdylay_on_invalid_ctrl_recv_callback on_invalid_ctrl_recv_callback; + nghttp2_on_invalid_ctrl_recv_callback on_invalid_ctrl_recv_callback; /** * Callback function invoked when a chunk of data in DATA frame is * received. */ - spdylay_on_data_chunk_recv_callback on_data_chunk_recv_callback; + nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback; /** * Callback function invoked when DATA frame is received. */ - spdylay_on_data_recv_callback on_data_recv_callback; + nghttp2_on_data_recv_callback on_data_recv_callback; /** * Callback function invoked before the control frame is sent. */ - spdylay_before_ctrl_send_callback before_ctrl_send_callback; + nghttp2_before_ctrl_send_callback before_ctrl_send_callback; /** * Callback function invoked after the control frame is sent. */ - spdylay_on_ctrl_send_callback on_ctrl_send_callback; + nghttp2_on_ctrl_send_callback on_ctrl_send_callback; /** * The callback function invoked when a control frame is not sent * because of an error. */ - spdylay_on_ctrl_not_send_callback on_ctrl_not_send_callback; + nghttp2_on_ctrl_not_send_callback on_ctrl_not_send_callback; /** * Callback function invoked after DATA frame is sent. */ - spdylay_on_data_send_callback on_data_send_callback; + nghttp2_on_data_send_callback on_data_send_callback; /** * Callback function invoked when the stream is closed. */ - spdylay_on_stream_close_callback on_stream_close_callback; + nghttp2_on_stream_close_callback on_stream_close_callback; /** * Callback function invoked when request from the remote peer is * received. */ - spdylay_on_request_recv_callback on_request_recv_callback; + nghttp2_on_request_recv_callback on_request_recv_callback; /** * Callback function invoked when the library needs the * cryptographic proof that the client has possession of the private * key associated with the certificate. */ - spdylay_get_credential_proof get_credential_proof; + nghttp2_get_credential_proof get_credential_proof; /** * Callback function invoked when the library needs the length of the * client certificate chain. */ - spdylay_get_credential_ncerts get_credential_ncerts; + nghttp2_get_credential_ncerts get_credential_ncerts; /** * Callback function invoked when the library needs the client * certificate. */ - spdylay_get_credential_cert get_credential_cert; + nghttp2_get_credential_cert get_credential_cert; /** * Callback function invoked when the received control frame octets * could not be parsed correctly. */ - spdylay_on_ctrl_recv_parse_error_callback on_ctrl_recv_parse_error_callback; + nghttp2_on_ctrl_recv_parse_error_callback on_ctrl_recv_parse_error_callback; /** * Callback function invoked when the received control frame type is * unknown. */ - spdylay_on_unknown_ctrl_recv_callback on_unknown_ctrl_recv_callback; -} spdylay_session_callbacks; + nghttp2_on_unknown_ctrl_recv_callback on_unknown_ctrl_recv_callback; +} nghttp2_session_callbacks; /** * @function @@ -1190,30 +1190,30 @@ typedef struct { * |callbacks|. |user_data| is an arbitrary user supplied data, which * will be passed to the callback functions. * - * The :member:`spdylay_session_callbacks.send_callback` must be - * specified. If the application code uses `spdylay_session_recv()`, - * the :member:`spdylay_session_callbacks.recv_callback` must be + * The :member:`nghttp2_session_callbacks.send_callback` must be + * specified. If the application code uses `nghttp2_session_recv()`, + * the :member:`nghttp2_session_callbacks.recv_callback` must be * specified. The other members of |callbacks| can be ``NULL``. To - * use CREDENTIAL frame, specify :macro:`SPDYLAY_PROTO_SPDY3` in + * use CREDENTIAL frame, specify :macro:`NGHTTP2_PROTO_SPDY3` in * |version| and specify - * :member:`spdylay_session_callbacks.get_credential_ncerts`, - * :member:`spdylay_session_callbacks.get_credential_cert` and - * :member:`spdylay_session_callbacks.get_credential_proof`. See also - * `spdylay_session_set_initial_client_cert_origin()`. + * :member:`nghttp2_session_callbacks.get_credential_ncerts`, + * :member:`nghttp2_session_callbacks.get_credential_cert` and + * :member:`nghttp2_session_callbacks.get_credential_proof`. See also + * `nghttp2_session_set_initial_client_cert_origin()`. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. - * :enum:`SPDYLAY_ERR_ZLIB` + * :enum:`NGHTTP2_ERR_ZLIB` * The z_stream initialization failed. - * :enum:`SPDYLAY_ERR_UNSUPPORTED_VERSION` + * :enum:`NGHTTP2_ERR_UNSUPPORTED_VERSION` * The version is not supported. */ -int spdylay_session_client_new(spdylay_session **session_ptr, +int nghttp2_session_client_new(nghttp2_session **session_ptr, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data); /** @@ -1225,24 +1225,24 @@ int spdylay_session_client_new(spdylay_session **session_ptr, * |callbacks|. |user_data| is an arbitrary user supplied data, which * will be passed to the callback functions. * - * The :member:`spdylay_session_callbacks.send_callback` must be - * specified. If the application code uses `spdylay_session_recv()`, - * the :member:`spdylay_session_callbacks.recv_callback` must be + * The :member:`nghttp2_session_callbacks.send_callback` must be + * specified. If the application code uses `nghttp2_session_recv()`, + * the :member:`nghttp2_session_callbacks.recv_callback` must be * specified. The other members of |callbacks| can be ``NULL``. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. - * :enum:`SPDYLAY_ERR_ZLIB` + * :enum:`NGHTTP2_ERR_ZLIB` * The z_stream initialization failed. - * :enum:`SPDYLAY_ERR_UNSUPPORTED_VERSION` + * :enum:`NGHTTP2_ERR_UNSUPPORTED_VERSION` * The version is not supported. */ -int spdylay_session_server_new(spdylay_session **session_ptr, +int nghttp2_session_server_new(nghttp2_session **session_ptr, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data); /** @@ -1251,47 +1251,47 @@ int spdylay_session_server_new(spdylay_session **session_ptr, * Frees any resources allocated for |session|. If |session| is * ``NULL``, this function does nothing. */ -void spdylay_session_del(spdylay_session *session); +void nghttp2_session_del(nghttp2_session *session); /** * @enum * - * Configuration options for :type:`spdylay_session`. + * Configuration options for :type:`nghttp2_session`. */ typedef enum { /** * This option prevents the library from sending WINDOW_UPDATE * automatically. If this option is set, the application is * responsible for sending WINDOW_UPDATE using - * `spdylay_submit_window_update`. + * `nghttp2_submit_window_update`. */ - SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE = 1, + NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE = 1, /** * This option sets maximum receive buffer size for incoming control * frame. */ - SPDYLAY_OPT_MAX_RECV_CTRL_FRAME_BUFFER = 2 -} spdylay_opt; + NGHTTP2_OPT_MAX_RECV_CTRL_FRAME_BUFFER = 2 +} nghttp2_opt; /** * @function * * Sets the configuration option for the |session|. The |optname| is - * one of :type:`spdylay_opt`. The |optval| is the pointer to the + * one of :type:`nghttp2_opt`. The |optval| is the pointer to the * option value and the |optlen| is the size of |*optval|. The * required type of |optval| varies depending on the |optname|. See * below. * * The following |optname| are supported: * - * :enum:`SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE` + * :enum:`NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE` * The |optval| must be a pointer to ``int``. If the |*optval| is * nonzero, the library will not send WINDOW_UPDATE automatically. * Therefore, the application is responsible for sending - * WINDOW_UPDATE using `spdylay_submit_window_update`. This option + * WINDOW_UPDATE using `nghttp2_submit_window_update`. This option * defaults to 0. * - * :enum:`SPDYLAY_OPT_MAX_RECV_CTRL_FRAME_BUFFER` + * :enum:`NGHTTP2_OPT_MAX_RECV_CTRL_FRAME_BUFFER` * The |optval| must be a pointer to ``uint32_t``. The |*optval| * must be in the range [(1 << 13), (1 << 24)-1], inclusive. This * option defaults to (1 << 24)-1. @@ -1299,11 +1299,11 @@ typedef enum { * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |optname| is not supported; or the |optval| and/or the * |optlen| are invalid. */ -int spdylay_session_set_option(spdylay_session *session, +int nghttp2_session_set_option(nghttp2_session *session, int optname, void *optval, size_t optlen); /** @@ -1312,7 +1312,7 @@ int spdylay_session_set_option(spdylay_session *session, * Sets the origin tuple (|scheme|, |host| and |port|) that the * connection is made to and the client certificate is sent in the * first TLS handshake. This function must be called before any call - * of `spdylay_session_send()` and `spdylay_session_recv()` and be + * of `nghttp2_session_send()` and `nghttp2_session_recv()` and be * called only once per session. This function must not be called if * the |session| is initialized for server use. If the client did not * provide the client certificate in the first TLS handshake, this @@ -1324,13 +1324,13 @@ int spdylay_session_set_option(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory - * :enum:`SPDYLAY_ERR_INVALID_STATE` + * :enum:`NGHTTP2_ERR_INVALID_STATE` * The |session| is initialized for server use; or the client * certificate vector size is 0. */ -int spdylay_session_set_initial_client_cert_origin(spdylay_session *session, +int nghttp2_session_set_initial_client_cert_origin(nghttp2_session *session, const char *scheme, const char *host, uint16_t port); @@ -1345,8 +1345,8 @@ int spdylay_session_set_initial_client_cert_origin(spdylay_session *session, * This function must not be called if the |session| is initialized * for server use. */ -const spdylay_origin* spdylay_session_get_client_cert_origin -(spdylay_session *session, +const nghttp2_origin* nghttp2_session_get_client_cert_origin +(nghttp2_session *session, size_t slot); /** @@ -1357,8 +1357,8 @@ const spdylay_origin* spdylay_session_get_client_cert_origin * This function retrieves the highest prioritized frame from the * outbound queue and sends it to the remote peer. It does this as * many as possible until the user callback - * :member:`spdylay_session_callbacks.send_callback` returns - * :enum:`SPDYLAY_ERR_WOULDBLOCK` or the outbound queue becomes empty. + * :member:`nghttp2_session_callbacks.send_callback` returns + * :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty. * This function calls several callback functions which are passed * when initializing the |session|. Here is the simple time chart * which tells when each callback is invoked: @@ -1367,41 +1367,41 @@ const spdylay_origin* spdylay_session_get_client_cert_origin * 2. Prepare transmission of the frame. * 3. If the control frame cannot be sent because some preconditions * are not met (e.g., SYN_STREAM cannot be sent after GOAWAY), - * :member:`spdylay_session_callbacks.on_ctrl_not_send_callback` is + * :member:`nghttp2_session_callbacks.on_ctrl_not_send_callback` is * invoked. Abort the following steps. * 4. If the frame is SYN_STREAM, the stream is opened here. * If the |session| is initialized for client use and the protocol - * version is :macro:`SPDYLAY_PROTO_SPDY3` and the library needs + * version is :macro:`NGHTTP2_PROTO_SPDY3` and the library needs * the client certificate for the origin, - * :member:`spdylay_session_callbacks.get_credential_ncerts` is + * :member:`nghttp2_session_callbacks.get_credential_ncerts` is * invoked. If the result is more than zero, - * :member:`spdylay_session_callbacks.get_credential_proof` and - * :member:`spdylay_session_callbacks.get_credential_cert` are also + * :member:`nghttp2_session_callbacks.get_credential_proof` and + * :member:`nghttp2_session_callbacks.get_credential_cert` are also * invoked. - * 5. :member:`spdylay_session_callbacks.before_ctrl_send_callback` is + * 5. :member:`nghttp2_session_callbacks.before_ctrl_send_callback` is * invoked. - * 6. :member:`spdylay_session_callbacks.send_callback` is invoked one + * 6. :member:`nghttp2_session_callbacks.send_callback` is invoked one * or more times to send the frame. * 7. If the frame is a control frame, - * :member:`spdylay_session_callbacks.on_ctrl_send_callback` is + * :member:`nghttp2_session_callbacks.on_ctrl_send_callback` is * invoked. * 8. If the frame is a DATA frame, - * :member:`spdylay_session_callbacks.on_data_send_callback` is + * :member:`nghttp2_session_callbacks.on_data_send_callback` is * invoked. * 9. If the transmission of the frame triggers closure of the stream, * the stream is closed and - * :member:`spdylay_session_callbacks.on_stream_close_callback` is + * :member:`nghttp2_session_callbacks.on_stream_close_callback` is * invoked. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. - * :enum:`SPDYLAY_ERR_CALLBACK_FAILURE` + * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` * The callback function failed. */ -int spdylay_session_send(spdylay_session *session); +int nghttp2_session_send(nghttp2_session *session); /** * @function @@ -1409,63 +1409,63 @@ int spdylay_session_send(spdylay_session *session); * Receives frames from the remote peer. * * This function receives as many frames as possible until the user - * callback :member:`spdylay_session_callbacks.recv_callback` returns - * :enum:`SPDYLAY_ERR_WOULDBLOCK`. This function calls several + * callback :member:`nghttp2_session_callbacks.recv_callback` returns + * :enum:`NGHTTP2_ERR_WOULDBLOCK`. This function calls several * callback functions which are passed when initializing the * |session|. Here is the simple time chart which tells when each * callback is invoked: * - * 1. :member:`spdylay_session_callbacks.recv_callback` is invoked one + * 1. :member:`nghttp2_session_callbacks.recv_callback` is invoked one * or more times to receive frame header. * 2. If the frame is DATA frame: * - * 2.1. :member:`spdylay_session_callbacks.recv_callback` is invoked + * 2.1. :member:`nghttp2_session_callbacks.recv_callback` is invoked * to receive DATA payload. For each chunk of data, - * :member:`spdylay_session_callbacks.on_data_chunk_recv_callback` + * :member:`nghttp2_session_callbacks.on_data_chunk_recv_callback` * is invoked. * 2.2. If one DATA frame is completely received, - * :member:`spdylay_session_callbacks.on_data_recv_callback` is + * :member:`nghttp2_session_callbacks.on_data_recv_callback` is * invoked. If the frame is the final frame of the request, - * :member:`spdylay_session_callbacks.on_request_recv_callback` + * :member:`nghttp2_session_callbacks.on_request_recv_callback` * is invoked. If the reception of the frame triggers the * closure of the stream, - * :member:`spdylay_session_callbacks.on_stream_close_callback` + * :member:`nghttp2_session_callbacks.on_stream_close_callback` * is invoked. * * 3. If the frame is the control frame: * - * 3.1. :member:`spdylay_session_callbacks.recv_callback` is invoked + * 3.1. :member:`nghttp2_session_callbacks.recv_callback` is invoked * one or more times to receive whole frame. * 3.2. If the received frame is valid, - * :member:`spdylay_session_callbacks.on_ctrl_recv_callback` is + * :member:`nghttp2_session_callbacks.on_ctrl_recv_callback` is * invoked. If the frame is the final frame of the request, - * :member:`spdylay_session_callbacks.on_request_recv_callback` + * :member:`nghttp2_session_callbacks.on_request_recv_callback` * is invoked. If the reception of the frame triggers the * closure of the stream, - * :member:`spdylay_session_callbacks.on_stream_close_callback` + * :member:`nghttp2_session_callbacks.on_stream_close_callback` * is invoked. * 3.3. If the received frame is unpacked but is interpreted as * invalid, - * :member:`spdylay_session_callbacks.on_invalid_ctrl_recv_callback` + * :member:`nghttp2_session_callbacks.on_invalid_ctrl_recv_callback` * is invoked. * 3.4. If the received frame could not be unpacked correctly, - * :member:`spdylay_session_callbacks.on_ctrl_recv_parse_error_callback` + * :member:`nghttp2_session_callbacks.on_ctrl_recv_parse_error_callback` * is invoked. * 3.5. If the received frame type is unknown, - * :member:`spdylay_session_callbacks.on_unknown_ctrl_recv_callback` + * :member:`nghttp2_session_callbacks.on_unknown_ctrl_recv_callback` * is invoked. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_EOF` + * :enum:`NGHTTP2_ERR_EOF` * The remote peer did shutdown on the connection. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. - * :enum:`SPDYLAY_ERR_CALLBACK_FAILURE` + * :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` * The callback function failed. */ -int spdylay_session_recv(spdylay_session *session); +int nghttp2_session_recv(nghttp2_session *session); /** * @function @@ -1473,12 +1473,12 @@ int spdylay_session_recv(spdylay_session *session); * Processes data |in| as an input from the remote endpoint. The * |inlen| indicates the number of bytes in the |in|. * - * This function behaves like `spdylay_session_recv()` except that it - * does not use :member:`spdylay_session_callbacks.recv_callback` to + * This function behaves like `nghttp2_session_recv()` except that it + * does not use :member:`nghttp2_session_callbacks.recv_callback` to * receive data; the |in| is the only data for the invocation of this * function. If all bytes are processed, this function returns. The * other callbacks are called in the same way as they are in - * `spdylay_session_recv()`. + * `nghttp2_session_recv()`. * * In the current implementation, this function always tries to * processes all input data unless an error occurs. @@ -1486,10 +1486,10 @@ int spdylay_session_recv(spdylay_session *session); * This function returns the number of processed bytes, or one of the * following negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -ssize_t spdylay_session_mem_recv(spdylay_session *session, +ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, size_t inlen); /** @@ -1501,12 +1501,12 @@ ssize_t spdylay_session_mem_recv(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The stream does not exist or no deferred data exist. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_session_resume_data(spdylay_session *session, int32_t stream_id); +int nghttp2_session_resume_data(nghttp2_session *session, int32_t stream_id); /** * @function @@ -1514,11 +1514,11 @@ int spdylay_session_resume_data(spdylay_session *session, int32_t stream_id); * Returns nonzero value if |session| wants to receive data from the * remote peer. * - * If both `spdylay_session_want_read()` and - * `spdylay_session_want_write()` return 0, the application should + * If both `nghttp2_session_want_read()` and + * `nghttp2_session_want_write()` return 0, the application should * drop the connection. */ -int spdylay_session_want_read(spdylay_session *session); +int nghttp2_session_want_read(nghttp2_session *session); /** * @function @@ -1526,25 +1526,25 @@ int spdylay_session_want_read(spdylay_session *session); * Returns nonzero value if |session| wants to send data to the remote * peer. * - * If both `spdylay_session_want_read()` and - * `spdylay_session_want_write()` return 0, the application should + * If both `nghttp2_session_want_read()` and + * `nghttp2_session_want_write()` return 0, the application should * drop the connection. */ -int spdylay_session_want_write(spdylay_session *session); +int nghttp2_session_want_write(nghttp2_session *session); /** * @function * * Returns stream_user_data for the stream |stream_id|. The - * stream_user_data is provided by `spdylay_submit_request()` or - * `spdylay_submit_syn_stream()`. If the stream is initiated by the + * stream_user_data is provided by `nghttp2_submit_request()` or + * `nghttp2_submit_syn_stream()`. If the stream is initiated by the * remote endpoint, stream_user_data is always ``NULL``. If the stream * is initiated by the local endpoint and ``NULL`` is given in - * `spdylay_submit_request()` or `spdylay_submit_syn_stream()`, then + * `nghttp2_submit_request()` or `nghttp2_submit_syn_stream()`, then * this function returns ``NULL``. If the stream does not exist, this * function returns ``NULL``. */ -void* spdylay_session_get_stream_user_data(spdylay_session *session, +void* nghttp2_session_get_stream_user_data(nghttp2_session *session, int32_t stream_id); /** @@ -1553,41 +1553,41 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session, * Returns the number of frames in the outbound queue. This does not * include the deferred DATA frames. */ -size_t spdylay_session_get_outbound_queue_size(spdylay_session *session); +size_t nghttp2_session_get_outbound_queue_size(nghttp2_session *session); /** * @function * * Returns lowest priority value for the |session|. */ -uint8_t spdylay_session_get_pri_lowest(spdylay_session *session); +uint8_t nghttp2_session_get_pri_lowest(nghttp2_session *session); /** * @function * * Submits GOAWAY frame. The status code |status_code| is ignored if - * the protocol version is :macro:`SPDYLAY_PROTO_SPDY2`. + * the protocol version is :macro:`NGHTTP2_PROTO_SPDY2`. * * This function should be called when the connection should be * terminated after sending GOAWAY. If the remaining streams should be - * processed after GOAWAY, use `spdylay_submit_goaway()` instead. + * processed after GOAWAY, use `nghttp2_submit_goaway()` instead. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_session_fail_session(spdylay_session *session, +int nghttp2_session_fail_session(nghttp2_session *session, uint32_t status_code); /** * @function * * Returns string describing the |error_code|. The |error_code| must - * be one of the :enum:`spdylay_error`. + * be one of the :enum:`nghttp2_error`. */ -const char* spdylay_strerror(int error_code); +const char* nghttp2_strerror(int error_code); /** * @function @@ -1596,7 +1596,7 @@ const char* spdylay_strerror(int error_code); * frames. * * The |pri| is priority of this request. 0 is the highest priority - * value. Use `spdylay_session_get_pri_lowest()` to know the lowest + * value. Use `nghttp2_session_get_pri_lowest()` to know the lowest * priority value for this |session|. * * The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]`` @@ -1622,7 +1622,7 @@ const char* spdylay_strerror(int error_code); * field. * * If the |session| is initialized with the version - * :macro:`SPDYLAY_PROTO_SPDY2`, the above names are translated to + * :macro:`NGHTTP2_PROTO_SPDY2`, the above names are translated to * ``method``, ``scheme``, ``url``, ``version`` and ``host`` * respectively. * @@ -1639,32 +1639,32 @@ const char* spdylay_strerror(int error_code); * SYN_STREAM have FLAG_FIN set. The |stream_user_data| is data * associated to the stream opened by this request and can be an * arbitrary pointer, which can be retrieved later by - * `spdylay_session_get_stream_user_data()`. + * `nghttp2_session_get_stream_user_data()`. * * Since the library reorders the frames and tries to send the highest * prioritized one first and the SPDY specification requires the * stream ID must be strictly increasing, the stream ID of this * request cannot be known until it is about to sent. To know the * stream ID of the request, the application can use - * :member:`spdylay_session_callbacks.before_ctrl_send_callback`. This + * :member:`nghttp2_session_callbacks.before_ctrl_send_callback`. This * callback is called just before the frame is sent. For SYN_STREAM * frame, the argument frame has the stream ID assigned. Also since * the stream is already opened, - * `spdylay_session_get_stream_user_data()` can be used to get + * `nghttp2_session_get_stream_user_data()` can be used to get * |stream_user_data| to identify which SYN_STREAM we are processing. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |pri| is invalid; or the |nv| includes empty name or NULL * value. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_request(spdylay_session *session, uint8_t pri, +int nghttp2_submit_request(nghttp2_session *session, uint8_t pri, const char **nv, - const spdylay_data_provider *data_prd, + const nghttp2_data_provider *data_prd, void *stream_user_data); /** @@ -1687,7 +1687,7 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri, * HTTP response version (e.g., ``HTTP/1.1``) * * If the |session| is initialized with the version - * :macro:`SPDYLAY_PROTO_SPDY2`, the above names are translated to + * :macro:`NGHTTP2_PROTO_SPDY2`, the above names are translated to * ``status`` and ``version`` respectively. * * This function creates copies of all name/value pairs in |nv|. It @@ -1702,14 +1702,14 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |nv| includes empty name or NULL value. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_response(spdylay_session *session, +int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, const char **nv, - const spdylay_data_provider *data_prd); + const nghttp2_data_provider *data_prd); /** * @function @@ -1717,10 +1717,10 @@ int spdylay_submit_response(spdylay_session *session, * Submits SYN_STREAM frame. The |flags| is bitwise OR of the * following values: * - * * :enum:`SPDYLAY_CTRL_FLAG_FIN` - * * :enum:`SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL` + * * :enum:`NGHTTP2_CTRL_FLAG_FIN` + * * :enum:`NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL` * - * If |flags| includes :enum:`SPDYLAY_CTRL_FLAG_FIN`, this frame has + * If |flags| includes :enum:`NGHTTP2_CTRL_FLAG_FIN`, this frame has * FLAG_FIN flag set. * * The |assoc_stream_id| is used for server-push. Specify 0 if this @@ -1728,7 +1728,7 @@ int spdylay_submit_response(spdylay_session *session, * use, |assoc_stream_id| is ignored. * * The |pri| is priority of this request. 0 is the highest priority - * value. Use `spdylay_session_get_pri_lowest()` to know the lowest + * value. Use `nghttp2_session_get_pri_lowest()` to know the lowest * priority value for this |session|. * * The |nv| contains the name/value pairs. For i >= 0, ``nv[2*i]`` @@ -1745,18 +1745,18 @@ int spdylay_submit_response(spdylay_session *session, * * This function is low-level in a sense that the application code can * specify flags and the Associated-To-Stream-ID directly. For usual - * HTTP request, `spdylay_submit_request()` is useful. + * HTTP request, `nghttp2_submit_request()` is useful. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |pri| is invalid; or the |assoc_stream_id| is invalid; or * the |nv| includes empty name or NULL value. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_syn_stream(spdylay_session *session, uint8_t flags, +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); @@ -1766,9 +1766,9 @@ int spdylay_submit_syn_stream(spdylay_session *session, uint8_t flags, * Submits SYN_REPLY frame. The |flags| is bitwise OR of the following * values: * - * * :enum:`SPDYLAY_CTRL_FLAG_FIN` + * * :enum:`NGHTTP2_CTRL_FLAG_FIN` * - * If |flags| includes :enum:`SPDYLAY_CTRL_FLAG_FIN`, this frame has + * If |flags| includes :enum:`NGHTTP2_CTRL_FLAG_FIN`, this frame has * FLAG_FIN flag set. * * The stream which this frame belongs to is given in the @@ -1786,12 +1786,12 @@ int spdylay_submit_syn_stream(spdylay_session *session, uint8_t flags, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |nv| includes empty name or NULL value. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_syn_reply(spdylay_session *session, uint8_t flags, +int nghttp2_submit_syn_reply(nghttp2_session *session, uint8_t flags, int32_t stream_id, const char **nv); /** @@ -1800,9 +1800,9 @@ int spdylay_submit_syn_reply(spdylay_session *session, uint8_t flags, * Submits HEADERS frame. The |flags| is bitwise OR of the following * values: * - * * :enum:`SPDYLAY_CTRL_FLAG_FIN` + * * :enum:`NGHTTP2_CTRL_FLAG_FIN` * - * If |flags| includes :enum:`SPDYLAY_CTRL_FLAG_FIN`, this frame has + * If |flags| includes :enum:`NGHTTP2_CTRL_FLAG_FIN`, this frame has * FLAG_FIN flag set. * * The stream which this frame belongs to is given in the @@ -1820,12 +1820,12 @@ int spdylay_submit_syn_reply(spdylay_session *session, uint8_t flags, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |nv| includes empty name or NULL value. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_headers(spdylay_session *session, uint8_t flags, +int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags, int32_t stream_id, const char **nv); /** @@ -1833,7 +1833,7 @@ int spdylay_submit_headers(spdylay_session *session, uint8_t flags, * * Submits one or more DATA frames to the stream |stream_id|. The * data to be sent are provided by |data_prd|. If |flags| contains - * :enum:`SPDYLAY_DATA_FLAG_FIN`, the last DATA frame has FLAG_FIN + * :enum:`NGHTTP2_DATA_FLAG_FIN`, the last DATA frame has FLAG_FIN * set. * * This function does not take ownership of the |data_prd|. The @@ -1842,11 +1842,11 @@ int spdylay_submit_headers(spdylay_session *session, uint8_t flags, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_data(spdylay_session *session, int32_t stream_id, - uint8_t flags, const spdylay_data_provider *data_prd); +int nghttp2_submit_data(nghttp2_session *session, int32_t stream_id, + uint8_t flags, const nghttp2_data_provider *data_prd); /** * @function @@ -1857,10 +1857,10 @@ int spdylay_submit_data(spdylay_session *session, int32_t stream_id, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_rst_stream(spdylay_session *session, int32_t stream_id, +int nghttp2_submit_rst_stream(nghttp2_session *session, int32_t stream_id, uint32_t status_code); /** @@ -1873,33 +1873,33 @@ int spdylay_submit_rst_stream(spdylay_session *session, int32_t stream_id, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_ping(spdylay_session *session); +int nghttp2_submit_ping(nghttp2_session *session); /** * @function * * Submits GOAWAY frame. The status code |status_code| is ignored if - * the protocol version is :macro:`SPDYLAY_PROTO_SPDY2`. + * the protocol version is :macro:`NGHTTP2_PROTO_SPDY2`. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_goaway(spdylay_session *session, uint32_t status_code); +int nghttp2_submit_goaway(nghttp2_session *session, uint32_t status_code); /** * @function * * Stores local settings and submits SETTINGS frame. The |iv| is the - * pointer to the array of :type:`spdylay_settings_entry`. The |niv| - * indicates the number of :type:`spdylay_settings_entry`. The |flags| + * pointer to the array of :type:`nghttp2_settings_entry`. The |niv| + * indicates the number of :type:`nghttp2_settings_entry`. The |flags| * is bitwise-OR of one or more values from - * :type:`spdylay_settings_flag`. + * :type:`nghttp2_settings_flag`. * * This function does not take ownership of the |iv|. This function * copies all the elements in the |iv|. @@ -1907,13 +1907,13 @@ int spdylay_submit_goaway(spdylay_session *session, uint32_t status_code); * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |iv| contains duplicate settings ID or invalid value. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_settings(spdylay_session *session, uint8_t flags, - const spdylay_settings_entry *iv, size_t niv); +int nghttp2_submit_settings(nghttp2_session *session, uint8_t flags, + const nghttp2_settings_entry *iv, size_t niv); /** * @function @@ -1926,14 +1926,14 @@ int spdylay_submit_settings(spdylay_session *session, uint8_t flags, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_INVALID_ARGUMENT` + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` * The |delta_window_size| is 0 or negative. - * :enum:`SPDYLAY_ERR_STREAM_CLOSED` + * :enum:`NGHTTP2_ERR_STREAM_CLOSED` * The stream is already closed or does not exist. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id, +int nghttp2_submit_window_update(nghttp2_session *session, int32_t stream_id, int32_t delta_window_size); /** @@ -1952,11 +1952,11 @@ int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id, * * The selection algorithm is as follows: * - * 1. If server's list contains SPDY versions the spdylay library + * 1. If server's list contains SPDY versions the nghttp2 library * supports, this function selects one of them and returns its SPDY * protocol version which can be used directly with - * `spdylay_session_client_new()` and - * `spdylay_session_server_new()` . The following steps are not + * `nghttp2_session_client_new()` and + * `nghttp2_session_server_new()` . The following steps are not * taken. * * 2. If server's list contains ``http/1.1``, this function selects @@ -1966,9 +1966,9 @@ int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id, * non-overlap case). In this case, |out| and |outlen| are left * untouched. * - * When spdylay supports updated version of SPDY in the future, this + * When nghttp2 supports updated version of SPDY in the future, this * function may select updated protocol and application code which - * relies on spdylay for SPDY stuff needs not be modified. + * relies on nghttp2 for SPDY stuff needs not be modified. * * Selecting ``spdy/2`` means that ``spdy/2`` is written into |*out| * and length of ``spdy/2`` (which is 6) is assigned to |*outlen|. @@ -1986,7 +1986,7 @@ int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id, * void *arg) * { * int version; - * version = spdylay_select_next_protocol(out, outlen, in, inlen); + * version = nghttp2_select_next_protocol(out, outlen, in, inlen); * if(version > 0) { * ((MyType*)arg)->spdy_version = version; * } @@ -1995,7 +1995,7 @@ int spdylay_submit_window_update(spdylay_session *session, int32_t stream_id, * ... * SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj); */ -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); /** @@ -2016,11 +2016,11 @@ typedef struct { uint8_t len; /** * The corresponding SPDY version constant which can be passed to - * `spdylay_session_client_new()` and `spdylay_session_server_new()` + * `nghttp2_session_client_new()` and `nghttp2_session_server_new()` * as version argument. */ uint16_t version; -} spdylay_npn_proto; +} nghttp2_npn_proto; /** * @function @@ -2031,21 +2031,21 @@ typedef struct { * application can use this information to configure NPN protocol * offerings/selection. */ -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); /** * @function * - * Returns spdy version which spdylay library supports from the given + * Returns spdy version which nghttp2 library supports from the given * protocol name. The |proto| is the pointer to the protocol name and * |protolen| is its length. Currently, ``spdy/2`` and ``spdy/3`` are * supported. * * This function returns nonzero spdy version if it succeeds, or 0. */ -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); -struct spdylay_gzip; +struct nghttp2_gzip; /** * @struct @@ -2053,7 +2053,7 @@ struct spdylay_gzip; * The gzip stream to inflate data. The details of this structure are * intentionally hidden from the public API. */ -typedef struct spdylay_gzip spdylay_gzip; +typedef struct nghttp2_gzip nghttp2_gzip; /** * @function @@ -2063,19 +2063,19 @@ typedef struct spdylay_gzip spdylay_gzip; * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_GZIP` + * :enum:`NGHTTP2_ERR_GZIP` * The initialization of gzip stream failed. - * :enum:`SPDYLAY_ERR_NOMEM` + * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int spdylay_gzip_inflate_new(spdylay_gzip **inflater_ptr); +int nghttp2_gzip_inflate_new(nghttp2_gzip **inflater_ptr); /** * @function * * Frees the inflate stream. The |inflater| may be ``NULL``. */ -void spdylay_gzip_inflate_del(spdylay_gzip *inflater); +void nghttp2_gzip_inflate_del(nghttp2_gzip *inflater); /** * @function @@ -2089,29 +2089,29 @@ void spdylay_gzip_inflate_del(spdylay_gzip *inflater); * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * :enum:`SPDYLAY_ERR_GZIP` + * :enum:`NGHTTP2_ERR_GZIP` * The inflation of gzip stream failed. * * The example follows:: * - * void on_data_chunk_recv_callback(spdylay_session *session, + * void on_data_chunk_recv_callback(nghttp2_session *session, * uint8_t flags, * int32_t stream_id, * const uint8_t *data, size_t len, * void *user_data) * { * ... - * req = spdylay_session_get_stream_user_data(session, stream_id); - * spdylay_gzip *inflater = req->inflater; + * req = nghttp2_session_get_stream_user_data(session, stream_id); + * nghttp2_gzip *inflater = req->inflater; * while(len > 0) { * uint8_t out[MAX_OUTLEN]; * size_t outlen = MAX_OUTLEN; * size_t tlen = len; * int rv; - * rv = spdylay_gzip_inflate(inflater, out, &outlen, data, &tlen); + * rv = nghttp2_gzip_inflate(inflater, out, &outlen, data, &tlen); * if(rv != 0) { - * spdylay_submit_rst_stream(session, stream_id, - * SPDYLAY_INTERNAL_ERROR); + * nghttp2_submit_rst_stream(session, stream_id, + * NGHTTP2_INTERNAL_ERROR); * break; * } * ... Do stuff ... @@ -2121,7 +2121,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, const uint8_t *in, size_t *inlen_ptr); @@ -2129,4 +2129,4 @@ int spdylay_gzip_inflate(spdylay_gzip *inflater, } #endif -#endif /* SPDYLAY_H */ +#endif /* NGHTTP2_H */ diff --git a/lib/includes/spdylay/spdylayver.h.in b/lib/includes/nghttp2/nghttp2ver.h.in similarity index 89% rename from lib/includes/spdylay/spdylayver.h.in rename to lib/includes/nghttp2/nghttp2ver.h.in index fdd029e6..d1bbb2ec 100644 --- a/lib/includes/spdylay/spdylayver.h.in +++ b/lib/includes/nghttp2/nghttp2ver.h.in @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,13 +22,13 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAYVER_H -#define SPDYLAYVER_H +#ifndef NGHTTP2VER_H +#define NGHTTP2VER_H /** * @macro * Version number of the Spdylay library release */ -#define SPDYLAY_VERSION "@PACKAGE_VERSION@" +#define NGHTTP2_VERSION "@PACKAGE_VERSION@" -#endif /* SPDYLAYVER_H */ +#endif /* NGHTTP2VER_H */ diff --git a/lib/libspdylay.pc.in b/lib/libnghttp2.pc.in similarity index 89% rename from lib/libspdylay.pc.in rename to lib/libnghttp2.pc.in index 0769b0de..eb7aef09 100644 --- a/lib/libspdylay.pc.in +++ b/lib/libnghttp2.pc.in @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -25,10 +25,10 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ -Name: Spdylay -Description: SPDY C library -URL: http://spdylay.sourceforge.net/ +Name: nghttp2 +Description: HTTP/2.0 C library +URL: https://github.com/tatsuhiro-t/nghttp2 Version: @VERSION@ -Libs: -L${libdir} -lspdylay +Libs: -L${libdir} -lnghttp2 Requires.private: zlib Cflags: -I${includedir} diff --git a/lib/spdylay_buffer.c b/lib/nghttp2_buffer.c similarity index 67% rename from lib/spdylay_buffer.c rename to lib/nghttp2_buffer.c index 87afa853..4b1fcf13 100644 --- a/lib/spdylay_buffer.c +++ b/lib/nghttp2_buffer.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,15 +22,15 @@ * 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_buffer.h" +#include "nghttp2_buffer.h" #include #include -#include "spdylay_net.h" -#include "spdylay_helper.h" +#include "nghttp2_net.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.next = NULL; @@ -44,30 +44,30 @@ void spdylay_buffer_init(spdylay_buffer *buffer, size_t chunk_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) { - spdylay_buffer_chunk *next = p->next; + nghttp2_buffer_chunk *next = p->next; free(p->data); free(p); p = next; } } -int spdylay_buffer_alloc(spdylay_buffer *buffer) +int nghttp2_buffer_alloc(nghttp2_buffer *buffer) { if(buffer->current->next == NULL) { - spdylay_buffer_chunk *chunk; + nghttp2_buffer_chunk *chunk; uint8_t *buf; - chunk = malloc(sizeof(spdylay_buffer_chunk)); + chunk = malloc(sizeof(nghttp2_buffer_chunk)); if(chunk == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } buf = malloc(buffer->capacity); if(buf == NULL) { free(chunk); - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } chunk->data = buf; chunk->next = NULL; @@ -81,7 +81,7 @@ int spdylay_buffer_alloc(spdylay_buffer *buffer) return 0; } -uint8_t* spdylay_buffer_get(spdylay_buffer *buffer) +uint8_t* nghttp2_buffer_get(nghttp2_buffer *buffer) { if(buffer->current->data == 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; } -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->len += amount; 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) { int rv; while(len) { size_t writelen; - if(spdylay_buffer_avail(buffer) == 0) { - if((rv = spdylay_buffer_alloc(buffer)) != 0) { + if(nghttp2_buffer_avail(buffer) == 0) { + if((rv = nghttp2_buffer_alloc(buffer)) != 0) { return rv; } } - writelen = spdylay_min(spdylay_buffer_avail(buffer), len); - memcpy(spdylay_buffer_get(buffer), data, writelen); + writelen = nghttp2_min(nghttp2_buffer_avail(buffer), len); + memcpy(nghttp2_buffer_get(buffer), data, writelen); data += writelen; len -= writelen; - spdylay_buffer_advance(buffer, writelen); + nghttp2_buffer_advance(buffer, writelen); } return 0; } -size_t spdylay_buffer_length(spdylay_buffer *buffer) +size_t nghttp2_buffer_length(nghttp2_buffer *buffer) { return buffer->len; } -size_t spdylay_buffer_capacity(spdylay_buffer *buffer) +size_t nghttp2_buffer_capacity(nghttp2_buffer *buffer) { 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) { size_t len; 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->len = 0; buffer->last_offset = buffer->capacity; } -void spdylay_buffer_reader_init(spdylay_buffer_reader *reader, - spdylay_buffer *buffer) +void nghttp2_buffer_reader_init(nghttp2_buffer_reader *reader, + nghttp2_buffer *buffer) { reader->buffer = buffer; reader->current = buffer->root.next; 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; - spdylay_buffer_reader_data(reader, &out, sizeof(uint8_t)); + nghttp2_buffer_reader_data(reader, &out, sizeof(uint8_t)); 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; - 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); } -uint32_t spdylay_buffer_reader_uint32(spdylay_buffer_reader *reader) +uint32_t nghttp2_buffer_reader_uint32(nghttp2_buffer_reader *reader) { 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); } -void spdylay_buffer_reader_data(spdylay_buffer_reader *reader, +void nghttp2_buffer_reader_data(nghttp2_buffer_reader *reader, uint8_t *out, size_t len) { while(len) { size_t remlen, readlen; remlen = reader->buffer->capacity - reader->offset; - readlen = spdylay_min(remlen, len); + readlen = nghttp2_min(remlen, len); memcpy(out, reader->current->data + reader->offset, readlen); out += 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) { int res = 0; @@ -209,7 +209,7 @@ int spdylay_buffer_reader_count(spdylay_buffer_reader *reader, size_t remlen, readlen, i; uint8_t *p; remlen = reader->buffer->capacity - reader->offset; - readlen = spdylay_min(remlen, len); + readlen = nghttp2_min(remlen, len); p = reader->current->data + reader->offset; for(i = 0; i < readlen; ++i) { if(p[i] == c) { @@ -226,13 +226,13 @@ int spdylay_buffer_reader_count(spdylay_buffer_reader *reader, return res; } -void spdylay_buffer_reader_advance(spdylay_buffer_reader *reader, +void nghttp2_buffer_reader_advance(nghttp2_buffer_reader *reader, size_t amount) { while(amount) { size_t remlen, skiplen; remlen = reader->buffer->capacity - reader->offset; - skiplen = spdylay_min(remlen, amount); + skiplen = nghttp2_min(remlen, amount); amount -= skiplen; reader->offset += skiplen; if(reader->buffer->capacity == reader->offset) { diff --git a/lib/spdylay_buffer.h b/lib/nghttp2_buffer.h similarity index 68% rename from lib/spdylay_buffer.h rename to lib/nghttp2_buffer.h index aeeaf9db..755f34df 100644 --- a/lib/spdylay_buffer.h +++ b/lib/nghttp2_buffer.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,19 +22,19 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_BUFFER_H -#define SPDYLAY_BUFFER_H +#ifndef NGHTTP2_BUFFER_H +#define NGHTTP2_BUFFER_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include +#include -typedef struct spdylay_buffer_chunk { +typedef struct nghttp2_buffer_chunk { uint8_t *data; - struct spdylay_buffer_chunk *next; -} spdylay_buffer_chunk; + struct nghttp2_buffer_chunk *next; +} nghttp2_buffer_chunk; /* * List of fixed sized chunks @@ -44,28 +44,28 @@ typedef struct { size_t capacity; /* Root of list of chunk buffers. The root is dummy and its data member is always NULL. */ - spdylay_buffer_chunk root; + nghttp2_buffer_chunk root; /* Points to the current chunk to write */ - spdylay_buffer_chunk *current; + nghttp2_buffer_chunk *current; /* Total length of this buffer */ size_t len; /* Offset of last chunk buffer */ size_t last_offset; -} spdylay_buffer; +} nghttp2_buffer; /* * 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 */ -void spdylay_buffer_free(spdylay_buffer *buffer); +void nghttp2_buffer_free(nghttp2_buffer *buffer); /* Returns buffer pointer */ -uint8_t* spdylay_buffer_get(spdylay_buffer *buffer); +uint8_t* nghttp2_buffer_get(nghttp2_buffer *buffer); /* 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 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 @@ -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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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); /* * 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. * * This function returns 0 if it succeeds, or one of the following * negative eror codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_buffer_alloc(spdylay_buffer *buffer); +int nghttp2_buffer_alloc(nghttp2_buffer *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 */ -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 - spdylay_buffer_length(buffer) bytes long. */ -void spdylay_buffer_serialize(spdylay_buffer *buffer, uint8_t *buf); + nghttp2_buffer_length(buffer) bytes long. */ +void nghttp2_buffer_serialize(nghttp2_buffer *buffer, uint8_t *buf); /* 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. */ -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 { /* The buffer to read */ - spdylay_buffer *buffer; + nghttp2_buffer *buffer; /* Pointer to the current chunk to read. */ - spdylay_buffer_chunk *current; + nghttp2_buffer_chunk *current; /* Offset to the current chunk data to read. */ size_t offset; -} spdylay_buffer_reader; +} nghttp2_buffer_reader; /* * Initializes the |reader| with the |buffer|. */ -void spdylay_buffer_reader_init(spdylay_buffer_reader *reader, - spdylay_buffer *buffer); +void nghttp2_buffer_reader_init(nghttp2_buffer_reader *reader, + nghttp2_buffer *buffer); /* * Reads 1 byte and return it. This function will advance the current * 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 * 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 * 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 * 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); /** * Reads |len| bytes and count the occurrence of |c| there and return * 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); /* * 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); -#endif /* SPDYLAY_BUFFER_H */ +#endif /* NGHTTP2_BUFFER_H */ diff --git a/lib/spdylay_client_cert_vector.c b/lib/nghttp2_client_cert_vector.c similarity index 67% rename from lib/spdylay_client_cert_vector.c rename to lib/nghttp2_client_cert_vector.c index 0a75c1d5..0d4dda77 100644 --- a/lib/spdylay_client_cert_vector.c +++ b/lib/nghttp2_client_cert_vector.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,24 +22,24 @@ * 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_client_cert_vector.h" +#include "nghttp2_client_cert_vector.h" #include -#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 && 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) { - if(strlen(scheme) > SPDYLAY_MAX_SCHEME || - strlen(host) > SPDYLAY_MAX_HOSTNAME) { - return SPDYLAY_ERR_INVALID_ARGUMENT; + if(strlen(scheme) > NGHTTP2_MAX_SCHEME || + strlen(host) > NGHTTP2_MAX_HOSTNAME) { + return NGHTTP2_ERR_INVALID_ARGUMENT; } strcpy(origin->scheme, scheme); strcpy(origin->host, host); @@ -47,31 +47,31 @@ int spdylay_origin_set(spdylay_origin *origin, 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; } -const char* spdylay_origin_get_host(const spdylay_origin *origin) +const char* nghttp2_origin_get_host(const nghttp2_origin *origin) { 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; } -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) { certvec->size = certvec->capacity = size; certvec->last_slot = 0; 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); if(certvec->vector == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } memset(certvec->vector, 0, vec_size); } else { @@ -80,7 +80,7 @@ int spdylay_client_cert_vector_init(spdylay_client_cert_vector *certvec, 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; 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); } -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) { if(certvec->capacity < size) { - spdylay_origin **vector = realloc(certvec->vector, - sizeof(spdylay_origin*)*size); + nghttp2_origin **vector = realloc(certvec->vector, + sizeof(nghttp2_origin*)*size); if(vector == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } memset(vector + certvec->capacity, 0, - sizeof(spdylay_origin*)*(size - certvec->capacity)); + sizeof(nghttp2_origin*)*(size - certvec->capacity)); certvec->vector = vector; certvec->size = certvec->capacity = size; } else { @@ -108,7 +108,7 @@ int spdylay_client_cert_vector_resize(spdylay_client_cert_vector *certvec, free(certvec->vector[i]); certvec->vector[i] = NULL; } - certvec->size = spdylay_min(certvec->size, size); + certvec->size = nghttp2_min(certvec->size, size); if(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; } -size_t spdylay_client_cert_vector_find(spdylay_client_cert_vector *certvec, - const spdylay_origin *origin) +size_t nghttp2_client_cert_vector_find(nghttp2_client_cert_vector *certvec, + const nghttp2_origin *origin) { size_t 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 0; } -size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec, - spdylay_origin *origin) +size_t nghttp2_client_cert_vector_put(nghttp2_client_cert_vector *certvec, + nghttp2_origin *origin) { if(certvec->size == 0) { return 0; @@ -144,8 +144,8 @@ size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec, return certvec->last_slot; } -const spdylay_origin* spdylay_client_cert_vector_get_origin -(spdylay_client_cert_vector *certvec, +const nghttp2_origin* nghttp2_client_cert_vector_get_origin +(nghttp2_client_cert_vector *certvec, size_t slot) { if(slot == 0 || slot > certvec->size || !certvec->vector[slot-1]) { diff --git a/lib/spdylay_client_cert_vector.h b/lib/nghttp2_client_cert_vector.h similarity index 69% rename from lib/spdylay_client_cert_vector.h rename to lib/nghttp2_client_cert_vector.h index f47a32cc..1fd5cb99 100644 --- a/lib/spdylay_client_cert_vector.h +++ b/lib/nghttp2_client_cert_vector.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,36 +22,36 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_CLIENT_CERT_VECTOR_H -#define SPDYLAY_CLIENT_CERT_VECTOR_H +#ifndef NGHTTP2_CLIENT_CERT_VECTOR_H +#define NGHTTP2_CLIENT_CERT_VECTOR_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include +#include -struct spdylay_origin { - char scheme[SPDYLAY_MAX_SCHEME+1]; - char host[SPDYLAY_MAX_HOSTNAME+1]; +struct nghttp2_origin { + char scheme[NGHTTP2_MAX_SCHEME+1]; + char host[NGHTTP2_MAX_HOSTNAME+1]; uint16_t port; }; typedef struct { - spdylay_origin **vector; + nghttp2_origin **vector; /* The size of the vector. */ size_t size; /* The real capacity of the vector. size <= capacity holds true. */ size_t capacity; /* The last slot where origin is stored. The default value is 0. */ size_t last_slot; -} spdylay_client_cert_vector; +} nghttp2_client_cert_vector; /* * Returns nonzero if |lhs| and |rhs| are equal. The equality is * 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| @@ -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 * negative error codes: * - * SPDYLAY_ERR_INVALID_ARGUMENT - * The |scheme| is longer than SPDYLAY_MAX_SCHEME; or the |host| - * is longer than SPDYLAY_MAX_HOSTNAME. + * NGHTTP2_ERR_INVALID_ARGUMENT + * The |scheme| is longer than NGHTTP2_MAX_SCHEME; or the |host| + * 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); /* * Initializes the client certificate vector with the vector 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); -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. * If it is not found, returns 0. */ -size_t spdylay_client_cert_vector_find(spdylay_client_cert_vector *certvec, - const spdylay_origin *origin); +size_t nghttp2_client_cert_vector_find(nghttp2_client_cert_vector *certvec, + const nghttp2_origin *origin); /* * 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 * vector where the |origin| is stored if it succeeds, or 0. */ -size_t spdylay_client_cert_vector_put(spdylay_client_cert_vector *certvec, - spdylay_origin *origin); +size_t nghttp2_client_cert_vector_put(nghttp2_client_cert_vector *certvec, + nghttp2_origin *origin); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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); -const spdylay_origin* spdylay_client_cert_vector_get_origin -(spdylay_client_cert_vector *certvec, +const nghttp2_origin* nghttp2_client_cert_vector_get_origin +(nghttp2_client_cert_vector *certvec, size_t slot); -#endif /* SPDYLAY_CLIENT_CERT_VECTOR_H */ +#endif /* NGHTTP2_CLIENT_CERT_VECTOR_H */ diff --git a/lib/spdylay_frame.c b/lib/nghttp2_frame.c similarity index 55% rename from lib/spdylay_frame.c rename to lib/nghttp2_frame.c index b7c7be8b..f7515e55 100644 --- a/lib/spdylay_frame.c +++ b/lib/nghttp2_frame.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,21 +22,21 @@ * 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_frame.h" +#include "nghttp2_frame.h" #include #include #include #include -#include "spdylay_helper.h" -#include "spdylay_net.h" +#include "nghttp2_helper.h" +#include "nghttp2_net.h" -size_t spdylay_frame_get_len_size(uint16_t version) +size_t nghttp2_frame_get_len_size(uint16_t version) { - if(SPDYLAY_PROTO_SPDY2 == version) { + if(NGHTTP2_PROTO_SPDY2 == version) { return 2; - } else if(SPDYLAY_PROTO_SPDY3 == version) { + } else if(NGHTTP2_PROTO_SPDY3 == version) { return 4; } else { /* Unsupported version */ @@ -44,57 +44,57 @@ size_t spdylay_frame_get_len_size(uint16_t version) } } -static uint8_t* spdylay_pack_str(uint8_t *buf, const char *str, size_t len, +static uint8_t* nghttp2_pack_str(uint8_t *buf, const char *str, size_t len, size_t len_size) { - spdylay_frame_put_nv_len(buf, len, len_size); + nghttp2_frame_put_nv_len(buf, len, len_size); buf += len_size; memcpy(buf, str, len); return buf+len; } -static void spdylay_frame_pack_ctrl_hd(uint8_t* buf, const spdylay_ctrl_hd *hd) +static void nghttp2_frame_pack_ctrl_hd(uint8_t* buf, const nghttp2_ctrl_hd *hd) { - spdylay_put_uint16be(&buf[0], hd->version); + nghttp2_put_uint16be(&buf[0], hd->version); buf[0] |= 1 << 7; - spdylay_put_uint16be(&buf[2], hd->type); - spdylay_put_uint32be(&buf[4], hd->length); + nghttp2_put_uint16be(&buf[2], hd->type); + nghttp2_put_uint32be(&buf[4], hd->length); buf[4] = hd->flags; } -static void spdylay_frame_unpack_ctrl_hd(spdylay_ctrl_hd *hd, +static void nghttp2_frame_unpack_ctrl_hd(nghttp2_ctrl_hd *hd, const uint8_t* buf) { - hd->version = spdylay_get_uint16(buf) & SPDYLAY_VERSION_MASK; - hd->type = spdylay_get_uint16(&buf[2]); + hd->version = nghttp2_get_uint16(buf) & NGHTTP2_VERSION_MASK; + hd->type = nghttp2_get_uint16(&buf[2]); hd->flags = buf[4]; - hd->length = spdylay_get_uint32(&buf[4]) & SPDYLAY_LENGTH_MASK; + hd->length = nghttp2_get_uint32(&buf[4]) & NGHTTP2_LENGTH_MASK; } -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, uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr, char **nv, size_t nv_offset, size_t len_size, - spdylay_zlib *deflater) + nghttp2_zlib *deflater) { size_t nvspace; size_t maxframelen; ssize_t framelen; int r; - nvspace = spdylay_frame_count_nv_space(nv, len_size); - r = spdylay_reserve_buffer(nvbuf_ptr, nvbuflen_ptr, nvspace); + nvspace = nghttp2_frame_count_nv_space(nv, len_size); + r = nghttp2_reserve_buffer(nvbuf_ptr, nvbuflen_ptr, nvspace); if(r != 0) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - maxframelen = nv_offset+spdylay_zlib_deflate_hd_bound(deflater, nvspace); - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, maxframelen); + maxframelen = nv_offset+nghttp2_zlib_deflate_hd_bound(deflater, nvspace); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, maxframelen); if(r != 0) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - spdylay_frame_pack_nv(*nvbuf_ptr, nv, len_size); - framelen = spdylay_zlib_deflate_hd(deflater, + nghttp2_frame_pack_nv(*nvbuf_ptr, nv, len_size); + framelen = nghttp2_zlib_deflate_hd(deflater, (*buf_ptr)+nv_offset, maxframelen-nv_offset, *nvbuf_ptr, nvspace); @@ -103,50 +103,50 @@ ssize_t spdylay_frame_alloc_pack_nv(uint8_t **buf_ptr, } framelen += nv_offset; - if(framelen - SPDYLAY_FRAME_HEAD_LENGTH > SPDYLAY_LENGTH_MASK) { + if(framelen - NGHTTP2_FRAME_HEAD_LENGTH > NGHTTP2_LENGTH_MASK) { /* In SPDY/2 and 3, Max frame size is 2**24 - 1. */ - return SPDYLAY_ERR_FRAME_TOO_LARGE; + return NGHTTP2_ERR_FRAME_TOO_LARGE; } return framelen; } -int spdylay_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr, - spdylay_buffer *in, size_t len_size) +int nghttp2_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr, + nghttp2_buffer *in, size_t len_size) { uint32_t n; size_t buflen = 0; size_t nvlen = 0; size_t off = 0; - size_t inlen = spdylay_buffer_length(in); + size_t inlen = nghttp2_buffer_length(in); size_t i; - spdylay_buffer_reader reader; + nghttp2_buffer_reader reader; if(inlen < len_size) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - spdylay_buffer_reader_init(&reader, in); + nghttp2_buffer_reader_init(&reader, in); /* TODO limit n in a reasonable number */ - n = spdylay_frame_get_nv_len(&reader, len_size); + n = nghttp2_frame_get_nv_len(&reader, len_size); off += len_size; for(i = 0; i < n; ++i) { uint32_t len; size_t j; for(j = 0; j < 2; ++j) { if(inlen-off < len_size) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - len = spdylay_frame_get_nv_len(&reader, len_size); + len = nghttp2_frame_get_nv_len(&reader, len_size); off += len_size; if(inlen-off < len) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } buflen += len+1; off += len; if(j == 0) { - spdylay_buffer_reader_advance(&reader, len); + nghttp2_buffer_reader_advance(&reader, len); } } - nvlen += spdylay_buffer_reader_count(&reader, len, '\0'); + nvlen += nghttp2_buffer_reader_count(&reader, len, '\0'); ++nvlen; } if(inlen == off) { @@ -154,11 +154,11 @@ int spdylay_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr, *buflen_ptr = buflen+(nvlen*2+1)*sizeof(char*); return 0; } else { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } } -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 nvlen, buflen; @@ -167,31 +167,31 @@ int spdylay_frame_unpack_nv(char ***nv_ptr, spdylay_buffer *in, char *buf, **idx, *data; uint32_t n; int invalid_header_block = 0; - spdylay_buffer_reader reader; - r = spdylay_frame_count_unpack_nv_space(&nvlen, &buflen, in, len_size); + nghttp2_buffer_reader reader; + r = nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, in, len_size); if(r != 0) { return r; } buf = malloc(buflen); if(buf == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - spdylay_buffer_reader_init(&reader, in); + nghttp2_buffer_reader_init(&reader, in); idx = (char**)buf; data = buf+(nvlen*2+1)*sizeof(char*); - n = spdylay_frame_get_nv_len(&reader, len_size); + n = nghttp2_frame_get_nv_len(&reader, len_size); for(i = 0; i < n; ++i) { uint32_t len; char *name, *val; char *stop; int multival; - len = spdylay_frame_get_nv_len(&reader, len_size); + len = nghttp2_frame_get_nv_len(&reader, len_size); if(len == 0) { invalid_header_block = 1; } name = data; - spdylay_buffer_reader_data(&reader, (uint8_t*)data, len); + nghttp2_buffer_reader_data(&reader, (uint8_t*)data, len); for(stop = data+len; data != stop; ++data) { unsigned char c = *data; if(c < 0x20 || c > 0x7e || ('A' <= c && c <= 'Z')) { @@ -201,9 +201,9 @@ int spdylay_frame_unpack_nv(char ***nv_ptr, spdylay_buffer *in, *data = '\0'; ++data; - len = spdylay_frame_get_nv_len(&reader, len_size); + len = nghttp2_frame_get_nv_len(&reader, len_size); val = data; - spdylay_buffer_reader_data(&reader, (uint8_t*)data, len); + nghttp2_buffer_reader_data(&reader, (uint8_t*)data, len); multival = 0; for(stop = data+len; data != stop; ++data) { @@ -232,7 +232,7 @@ int spdylay_frame_unpack_nv(char ***nv_ptr, spdylay_buffer *in, assert((size_t)((char*)idx - buf) == (nvlen*2)*sizeof(char*)); *nv_ptr = (char**)buf; if(!invalid_header_block) { - spdylay_frame_nv_sort(*nv_ptr); + nghttp2_frame_nv_sort(*nv_ptr); for(i = 2; i < nvlen*2; i += 2) { if(strcmp((*nv_ptr)[i-2], (*nv_ptr)[i]) == 0 && (*nv_ptr)[i-2] != (*nv_ptr)[i]) { @@ -241,10 +241,10 @@ int spdylay_frame_unpack_nv(char ***nv_ptr, spdylay_buffer *in, } } } - return invalid_header_block ? SPDYLAY_ERR_INVALID_HEADER_BLOCK : 0; + return invalid_header_block ? NGHTTP2_ERR_INVALID_HEADER_BLOCK : 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) { size_t sum = len_size; int i; @@ -279,7 +279,7 @@ size_t spdylay_frame_count_nv_space(char **nv, size_t len_size) return sum; } -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) { int i; uint8_t *bufp = buf+len_size; @@ -299,7 +299,7 @@ ssize_t spdylay_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size) if(prevvallen) { /* Join previous value, with NULL character */ cur_vallen += vallen+1; - spdylay_frame_put_nv_len(cur_vallen_buf, cur_vallen, len_size); + nghttp2_frame_put_nv_len(cur_vallen_buf, cur_vallen, len_size); *bufp = '\0'; ++bufp; memcpy(bufp, val, vallen); @@ -308,37 +308,37 @@ ssize_t spdylay_frame_pack_nv(uint8_t *buf, char **nv, size_t len_size) /* Previous value is empty. In this case, drop the previous. */ cur_vallen += vallen; - spdylay_frame_put_nv_len(cur_vallen_buf, cur_vallen, len_size); + nghttp2_frame_put_nv_len(cur_vallen_buf, cur_vallen, len_size); memcpy(bufp, val, vallen); bufp += vallen; } } } else { ++num_nv; - bufp = spdylay_pack_str(bufp, key, keylen, len_size); + bufp = nghttp2_pack_str(bufp, key, keylen, len_size); prev = key; cur_vallen_buf = bufp; cur_vallen = vallen; prevkeylen = keylen; prevvallen = vallen; - bufp = spdylay_pack_str(bufp, val, vallen, len_size); + bufp = nghttp2_pack_str(bufp, val, vallen, len_size); } } - spdylay_frame_put_nv_len(buf, num_nv, len_size); + nghttp2_frame_put_nv_len(buf, num_nv, len_size); return bufp-buf; } -int spdylay_frame_is_ctrl_frame(uint8_t first_byte) +int nghttp2_frame_is_ctrl_frame(uint8_t first_byte) { return first_byte & 0x80; } -void spdylay_frame_nv_del(char **nv) +void nghttp2_frame_nv_del(char **nv) { free(nv); } -char** spdylay_frame_nv_copy(const char **nv) +char** nghttp2_frame_nv_copy(const char **nv) { int i; char *buf; @@ -365,19 +365,19 @@ char** spdylay_frame_nv_copy(const char **nv) return (char**)buf; } -static int spdylay_string_compar(const void *lhs, const void *rhs) +static int nghttp2_string_compar(const void *lhs, const void *rhs) { return strcmp(*(char **)lhs, *(char **)rhs); } -void spdylay_frame_nv_sort(char **nv) +void nghttp2_frame_nv_sort(char **nv) { int n; for(n = 0; nv[n]; ++n); - qsort(nv, n/2, 2*sizeof(char*), spdylay_string_compar); + qsort(nv, n/2, 2*sizeof(char*), nghttp2_string_compar); } -void spdylay_frame_nv_downcase(char **nv) +void nghttp2_frame_nv_downcase(char **nv) { int i, j; for(i = 0; nv[i]; i += 2) { @@ -389,19 +389,19 @@ void spdylay_frame_nv_downcase(char **nv) } } -char** spdylay_frame_nv_norm_copy(const char **nv) +char** nghttp2_frame_nv_norm_copy(const char **nv) { char **nv_copy; - nv_copy = spdylay_frame_nv_copy(nv); + nv_copy = nghttp2_frame_nv_copy(nv); if(nv_copy != NULL) { - spdylay_frame_nv_downcase(nv_copy); - spdylay_frame_nv_sort(nv_copy); + nghttp2_frame_nv_downcase(nv_copy); + nghttp2_frame_nv_sort(nv_copy); } return nv_copy; } /* Table to translate SPDY/3 header names to SPDY/2. */ -static const char *spdylay_nv_3to2[] = { +static const char *nghttp2_nv_3to2[] = { ":host", "host", ":method", "method", ":path", "url", @@ -411,35 +411,35 @@ static const char *spdylay_nv_3to2[] = { NULL }; -void spdylay_frame_nv_3to2(char **nv) +void nghttp2_frame_nv_3to2(char **nv) { int i, j; for(i = 0; nv[i]; i += 2) { - for(j = 0; spdylay_nv_3to2[j]; j += 2) { - if(strcmp(nv[i], spdylay_nv_3to2[j]) == 0) { - nv[i] = (char*)spdylay_nv_3to2[j+1]; + for(j = 0; nghttp2_nv_3to2[j]; j += 2) { + if(strcmp(nv[i], nghttp2_nv_3to2[j]) == 0) { + nv[i] = (char*)nghttp2_nv_3to2[j+1]; break; } } } } -void spdylay_frame_nv_2to3(char **nv) +void nghttp2_frame_nv_2to3(char **nv) { int i, j; for(i = 0; nv[i]; i += 2) { - for(j = 0; spdylay_nv_3to2[j]; j += 2) { - if(strcmp(nv[i], spdylay_nv_3to2[j+1]) == 0) { - nv[i] = (char*)spdylay_nv_3to2[j]; + for(j = 0; nghttp2_nv_3to2[j]; j += 2) { + if(strcmp(nv[i], nghttp2_nv_3to2[j+1]) == 0) { + nv[i] = (char*)nghttp2_nv_3to2[j]; break; } } } } -#define SPDYLAY_HTTPS_PORT 443 +#define NGHTTP2_HTTPS_PORT 443 -int spdylay_frame_nv_set_origin(char **nv, spdylay_origin *origin) +int nghttp2_frame_nv_set_origin(char **nv, nghttp2_origin *origin) { int scheme_found, host_found; int i; @@ -447,7 +447,7 @@ int spdylay_frame_nv_set_origin(char **nv, spdylay_origin *origin) for(i = 0; nv[i]; i += 2) { if(scheme_found == 0 && strcmp(":scheme", nv[i]) == 0) { size_t len = strlen(nv[i+1]); - if(len <= SPDYLAY_MAX_SCHEME) { + if(len <= NGHTTP2_MAX_SCHEME) { strcpy(origin->scheme, nv[i+1]); scheme_found = 1; } @@ -456,7 +456,7 @@ int spdylay_frame_nv_set_origin(char **nv, spdylay_origin *origin) char *sep = memchr(nv[i+1], ':', len); size_t hostlen; if(sep == NULL) { - origin->port = SPDYLAY_HTTPS_PORT; + origin->port = NGHTTP2_HTTPS_PORT; sep = nv[i+1]+len; } else { unsigned long int port; @@ -468,7 +468,7 @@ int spdylay_frame_nv_set_origin(char **nv, spdylay_origin *origin) origin->port = port; } hostlen = sep-nv[i+1]; - if(hostlen > SPDYLAY_MAX_HOSTNAME) { + if(hostlen > NGHTTP2_MAX_HOSTNAME) { continue; } memcpy(origin->host, nv[i+1], hostlen); @@ -479,18 +479,18 @@ int spdylay_frame_nv_set_origin(char **nv, spdylay_origin *origin) if(scheme_found && host_found) { return 0; } else { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } } -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, int32_t stream_id, int32_t assoc_stream_id, uint8_t pri, char **nv) { - memset(frame, 0, sizeof(spdylay_syn_stream)); + memset(frame, 0, sizeof(nghttp2_syn_stream)); frame->hd.version = version; - frame->hd.type = SPDYLAY_SYN_STREAM; + frame->hd.type = NGHTTP2_SYN_STREAM; frame->hd.flags = flags; frame->stream_id = stream_id; frame->assoc_stream_id = assoc_stream_id; @@ -498,52 +498,52 @@ void spdylay_frame_syn_stream_init(spdylay_syn_stream *frame, frame->nv = nv; } -void spdylay_frame_syn_stream_free(spdylay_syn_stream *frame) +void nghttp2_frame_syn_stream_free(nghttp2_syn_stream *frame) { - spdylay_frame_nv_del(frame->nv); + nghttp2_frame_nv_del(frame->nv); } -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, int32_t stream_id, char **nv) { - memset(frame, 0, sizeof(spdylay_syn_reply)); + memset(frame, 0, sizeof(nghttp2_syn_reply)); frame->hd.version = version; - frame->hd.type = SPDYLAY_SYN_REPLY; + frame->hd.type = NGHTTP2_SYN_REPLY; frame->hd.flags = flags; frame->stream_id = stream_id; frame->nv = nv; } -void spdylay_frame_syn_reply_free(spdylay_syn_reply *frame) +void nghttp2_frame_syn_reply_free(nghttp2_syn_reply *frame) { - spdylay_frame_nv_del(frame->nv); + nghttp2_frame_nv_del(frame->nv); } -void spdylay_frame_ping_init(spdylay_ping *frame, +void nghttp2_frame_ping_init(nghttp2_ping *frame, uint16_t version, uint32_t unique_id) { - memset(frame, 0, sizeof(spdylay_ping)); + memset(frame, 0, sizeof(nghttp2_ping)); frame->hd.version = version; - frame->hd.type = SPDYLAY_PING; - frame->hd.flags = SPDYLAY_CTRL_FLAG_NONE; + frame->hd.type = NGHTTP2_PING; + frame->hd.flags = NGHTTP2_CTRL_FLAG_NONE; frame->hd.length = 4; frame->unique_id = unique_id; } -void spdylay_frame_ping_free(spdylay_ping *frame) +void nghttp2_frame_ping_free(nghttp2_ping *frame) {} -void spdylay_frame_goaway_init(spdylay_goaway *frame, +void nghttp2_frame_goaway_init(nghttp2_goaway *frame, uint16_t version, int32_t last_good_stream_id, uint32_t status_code) { - memset(frame, 0, sizeof(spdylay_goaway)); + memset(frame, 0, sizeof(nghttp2_goaway)); frame->hd.version = version; - frame->hd.type = SPDYLAY_GOAWAY; - if(version == SPDYLAY_PROTO_SPDY2) { + frame->hd.type = NGHTTP2_GOAWAY; + if(version == NGHTTP2_PROTO_SPDY2) { frame->hd.length = 4; - } else if(version == SPDYLAY_PROTO_SPDY3) { + } else if(version == NGHTTP2_PROTO_SPDY3) { frame->hd.length = 8; frame->status_code = status_code; } else { @@ -552,87 +552,87 @@ void spdylay_frame_goaway_init(spdylay_goaway *frame, frame->last_good_stream_id = last_good_stream_id; } -void spdylay_frame_goaway_free(spdylay_goaway *frame) +void nghttp2_frame_goaway_free(nghttp2_goaway *frame) {} -void spdylay_frame_headers_init(spdylay_headers *frame, +void nghttp2_frame_headers_init(nghttp2_headers *frame, uint16_t version, uint8_t flags, int32_t stream_id, char **nv) { - memset(frame, 0, sizeof(spdylay_headers)); + memset(frame, 0, sizeof(nghttp2_headers)); frame->hd.version = version; - frame->hd.type = SPDYLAY_HEADERS; + frame->hd.type = NGHTTP2_HEADERS; frame->hd.flags = flags; frame->stream_id = stream_id; frame->nv = nv; } -void spdylay_frame_headers_free(spdylay_headers *frame) +void nghttp2_frame_headers_free(nghttp2_headers *frame) { - spdylay_frame_nv_del(frame->nv); + nghttp2_frame_nv_del(frame->nv); } -void spdylay_frame_rst_stream_init(spdylay_rst_stream *frame, +void nghttp2_frame_rst_stream_init(nghttp2_rst_stream *frame, uint16_t version, int32_t stream_id, uint32_t status_code) { - memset(frame, 0, sizeof(spdylay_rst_stream)); + memset(frame, 0, sizeof(nghttp2_rst_stream)); frame->hd.version = version; - frame->hd.type = SPDYLAY_RST_STREAM; + frame->hd.type = NGHTTP2_RST_STREAM; frame->hd.flags = 0; frame->hd.length = 8; frame->stream_id = stream_id; frame->status_code = 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, int32_t stream_id, int32_t delta_window_size) { - memset(frame, 0, sizeof(spdylay_window_update)); + memset(frame, 0, sizeof(nghttp2_window_update)); frame->hd.version = version; - frame->hd.type = SPDYLAY_WINDOW_UPDATE; + frame->hd.type = NGHTTP2_WINDOW_UPDATE; frame->hd.flags = 0; frame->hd.length = 8; frame->stream_id = stream_id; frame->delta_window_size = delta_window_size; } -void spdylay_frame_window_update_free(spdylay_window_update *frame) +void nghttp2_frame_window_update_free(nghttp2_window_update *frame) {} -void spdylay_frame_settings_init(spdylay_settings *frame, +void nghttp2_frame_settings_init(nghttp2_settings *frame, uint16_t version, uint8_t flags, - spdylay_settings_entry *iv, size_t niv) + nghttp2_settings_entry *iv, size_t niv) { - memset(frame, 0, sizeof(spdylay_settings)); + memset(frame, 0, sizeof(nghttp2_settings)); frame->hd.version = version; - frame->hd.type = SPDYLAY_SETTINGS; + frame->hd.type = NGHTTP2_SETTINGS; frame->hd.flags = flags; frame->hd.length = 4+niv*8; frame->niv = niv; frame->iv = iv; } -void spdylay_frame_settings_free(spdylay_settings *frame) +void nghttp2_frame_settings_free(nghttp2_settings *frame) { free(frame->iv); } -void spdylay_frame_credential_init(spdylay_credential *frame, +void nghttp2_frame_credential_init(nghttp2_credential *frame, uint16_t version, uint16_t slot, - spdylay_mem_chunk *proof, - spdylay_mem_chunk *certs, + nghttp2_mem_chunk *proof, + nghttp2_mem_chunk *certs, size_t ncerts) { size_t i; - memset(frame, 0, sizeof(spdylay_credential)); + memset(frame, 0, sizeof(nghttp2_credential)); frame->hd.version = version; - frame->hd.type = SPDYLAY_CREDENTIAL; + frame->hd.type = NGHTTP2_CREDENTIAL; frame->slot = slot; frame->proof = *proof; frame->certs = certs; @@ -643,7 +643,7 @@ void spdylay_frame_credential_init(spdylay_credential *frame, } } -void spdylay_frame_credential_free(spdylay_credential *frame) +void nghttp2_frame_credential_free(nghttp2_credential *frame) { size_t i; free(frame->proof.data); @@ -653,47 +653,47 @@ void spdylay_frame_credential_free(spdylay_credential *frame) free(frame->certs); } -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, - const spdylay_data_provider *data_prd) + const nghttp2_data_provider *data_prd) { - memset(frame, 0, sizeof(spdylay_data)); + memset(frame, 0, sizeof(nghttp2_data)); frame->stream_id = stream_id; frame->flags = flags; frame->data_prd = *data_prd; } -void spdylay_frame_data_free(spdylay_data *frame) +void nghttp2_frame_data_free(nghttp2_data *frame) {} -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, uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr, - spdylay_syn_stream *frame, - spdylay_zlib *deflater) + nghttp2_syn_stream *frame, + nghttp2_zlib *deflater) { ssize_t framelen; - size_t len_size = spdylay_frame_get_len_size(frame->hd.version); + size_t len_size = nghttp2_frame_get_len_size(frame->hd.version); if(len_size == 0) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - framelen = spdylay_frame_alloc_pack_nv(buf_ptr, buflen_ptr, + framelen = nghttp2_frame_alloc_pack_nv(buf_ptr, buflen_ptr, nvbuf_ptr, nvbuflen_ptr, frame->nv, - SPDYLAY_SYN_STREAM_NV_OFFSET, + NGHTTP2_SYN_STREAM_NV_OFFSET, len_size, deflater); if(framelen < 0) { return framelen; } - frame->hd.length = framelen-SPDYLAY_FRAME_HEAD_LENGTH; - memset(*buf_ptr, 0, SPDYLAY_SYN_STREAM_NV_OFFSET); + frame->hd.length = framelen-NGHTTP2_FRAME_HEAD_LENGTH; + memset(*buf_ptr, 0, NGHTTP2_SYN_STREAM_NV_OFFSET); /* pack ctrl header after length is determined */ - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->stream_id); - spdylay_put_uint32be(&(*buf_ptr)[12], frame->assoc_stream_id); - if(frame->hd.version == SPDYLAY_PROTO_SPDY3) { + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id); + nghttp2_put_uint32be(&(*buf_ptr)[12], frame->assoc_stream_id); + if(frame->hd.version == NGHTTP2_PROTO_SPDY3) { (*buf_ptr)[16] = (frame->pri << 5); (*buf_ptr)[17] = frame->slot; } else { @@ -702,39 +702,39 @@ ssize_t spdylay_frame_pack_syn_stream(uint8_t **buf_ptr, return framelen; } -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 *payload, size_t payloadlen, - spdylay_buffer *inflatebuf) + nghttp2_buffer *inflatebuf) { int r; size_t len_size; - r = spdylay_frame_unpack_syn_stream_without_nv(frame, head, headlen, + r = nghttp2_frame_unpack_syn_stream_without_nv(frame, head, headlen, payload, payloadlen); - len_size = spdylay_frame_get_len_size(frame->hd.version); + len_size = nghttp2_frame_get_len_size(frame->hd.version); if(len_size == 0) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } if(r == 0) { - r = spdylay_frame_unpack_nv(&frame->nv, inflatebuf, len_size); + r = nghttp2_frame_unpack_nv(&frame->nv, inflatebuf, len_size); } return r; } -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, size_t headlen, const uint8_t *payload, size_t payloadlen) { - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - if(headlen + payloadlen != SPDYLAY_SYN_STREAM_NV_OFFSET) { - return SPDYLAY_ERR_INVALID_FRAME; + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + if(headlen + payloadlen != NGHTTP2_SYN_STREAM_NV_OFFSET) { + return NGHTTP2_ERR_INVALID_FRAME; } - frame->stream_id = spdylay_get_uint32(payload) & SPDYLAY_STREAM_ID_MASK; + frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; frame->assoc_stream_id = - spdylay_get_uint32(payload+4) & SPDYLAY_STREAM_ID_MASK; - if(frame->hd.version == SPDYLAY_PROTO_SPDY3) { + nghttp2_get_uint32(payload+4) & NGHTTP2_STREAM_ID_MASK; + if(frame->hd.version == NGHTTP2_PROTO_SPDY3) { frame->pri = (*(payload+8) >> 5); frame->slot = payload[9]; } else { @@ -745,294 +745,294 @@ int spdylay_frame_unpack_syn_stream_without_nv(spdylay_syn_stream *frame, return 0; } -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, uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr, - spdylay_syn_reply *frame, - spdylay_zlib *deflater) + nghttp2_syn_reply *frame, + nghttp2_zlib *deflater) { ssize_t framelen; size_t len_size; ssize_t nv_offset; - len_size = spdylay_frame_get_len_size(frame->hd.version); + len_size = nghttp2_frame_get_len_size(frame->hd.version); if(len_size == 0) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - nv_offset = spdylay_frame_nv_offset(SPDYLAY_SYN_REPLY, frame->hd.version); + nv_offset = nghttp2_frame_nv_offset(NGHTTP2_SYN_REPLY, frame->hd.version); assert(nv_offset > 0); - framelen = spdylay_frame_alloc_pack_nv(buf_ptr, buflen_ptr, + framelen = nghttp2_frame_alloc_pack_nv(buf_ptr, buflen_ptr, nvbuf_ptr, nvbuflen_ptr, frame->nv, nv_offset, len_size, deflater); if(framelen < 0) { return framelen; } - frame->hd.length = framelen-SPDYLAY_FRAME_HEAD_LENGTH; + frame->hd.length = framelen-NGHTTP2_FRAME_HEAD_LENGTH; memset(*buf_ptr, 0, nv_offset); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->stream_id); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id); return framelen; } -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 *payload, size_t payloadlen, - spdylay_buffer *inflatebuf) + nghttp2_buffer *inflatebuf) { int r; - r = spdylay_frame_unpack_syn_reply_without_nv(frame, head, headlen, + r = nghttp2_frame_unpack_syn_reply_without_nv(frame, head, headlen, payload, payloadlen); if(r == 0) { size_t len_size; - len_size = spdylay_frame_get_len_size(frame->hd.version); + len_size = nghttp2_frame_get_len_size(frame->hd.version); if(len_size == 0) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - r = spdylay_frame_unpack_nv(&frame->nv, inflatebuf, len_size); + r = nghttp2_frame_unpack_nv(&frame->nv, inflatebuf, len_size); } return r; } -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, size_t headlen, const uint8_t *payload, size_t payloadlen) { ssize_t nv_offset; - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - nv_offset = spdylay_frame_nv_offset(SPDYLAY_SYN_REPLY, frame->hd.version); + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + nv_offset = nghttp2_frame_nv_offset(NGHTTP2_SYN_REPLY, frame->hd.version); assert(nv_offset > 0); if((ssize_t)(headlen + payloadlen) != nv_offset) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - frame->stream_id = spdylay_get_uint32(payload) & SPDYLAY_STREAM_ID_MASK; + frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; frame->nv = NULL; return 0; } -ssize_t spdylay_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_ping *frame) +ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_ping *frame) { ssize_t framelen = 12; int r; - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->unique_id); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->unique_id); return framelen; } -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 *payload, size_t payloadlen) { if(payloadlen != 4) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - frame->unique_id = spdylay_get_uint32(payload); + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + frame->unique_id = nghttp2_get_uint32(payload); return 0; } -ssize_t spdylay_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_goaway *frame) +ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_goaway *frame) { ssize_t framelen; int r; - if(frame->hd.version == SPDYLAY_PROTO_SPDY2) { + if(frame->hd.version == NGHTTP2_PROTO_SPDY2) { framelen = 12; - } else if(frame->hd.version == SPDYLAY_PROTO_SPDY3) { + } else if(frame->hd.version == NGHTTP2_PROTO_SPDY3) { framelen = 16; } else { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->last_good_stream_id); - if(frame->hd.version == SPDYLAY_PROTO_SPDY3) { - spdylay_put_uint32be(&(*buf_ptr)[12], frame->status_code); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->last_good_stream_id); + if(frame->hd.version == NGHTTP2_PROTO_SPDY3) { + nghttp2_put_uint32be(&(*buf_ptr)[12], frame->status_code); } return framelen; } -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 *payload, size_t payloadlen) { - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - if(frame->hd.version == SPDYLAY_PROTO_SPDY2) { + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + if(frame->hd.version == NGHTTP2_PROTO_SPDY2) { if(payloadlen != 4) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - } else if(frame->hd.version == SPDYLAY_PROTO_SPDY3) { + } else if(frame->hd.version == NGHTTP2_PROTO_SPDY3) { if(payloadlen != 8) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } } else { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - frame->last_good_stream_id = spdylay_get_uint32(payload) & - SPDYLAY_STREAM_ID_MASK; - if(frame->hd.version == SPDYLAY_PROTO_SPDY3) { - frame->status_code = spdylay_get_uint32(payload+4); + frame->last_good_stream_id = nghttp2_get_uint32(payload) & + NGHTTP2_STREAM_ID_MASK; + if(frame->hd.version == NGHTTP2_PROTO_SPDY3) { + frame->status_code = nghttp2_get_uint32(payload+4); } else { frame->status_code = 0; } return 0; } -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, - spdylay_headers *frame, - spdylay_zlib *deflater) + nghttp2_headers *frame, + nghttp2_zlib *deflater) { ssize_t framelen; size_t len_size; ssize_t nv_offset; - len_size = spdylay_frame_get_len_size(frame->hd.version); + len_size = nghttp2_frame_get_len_size(frame->hd.version); if(len_size == 0) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - nv_offset = spdylay_frame_nv_offset(SPDYLAY_HEADERS, frame->hd.version); + nv_offset = nghttp2_frame_nv_offset(NGHTTP2_HEADERS, frame->hd.version); assert(nv_offset > 0); - framelen = spdylay_frame_alloc_pack_nv(buf_ptr, buflen_ptr, + framelen = nghttp2_frame_alloc_pack_nv(buf_ptr, buflen_ptr, nvbuf_ptr, nvbuflen_ptr, frame->nv, nv_offset, len_size, deflater); if(framelen < 0) { return framelen; } - frame->hd.length = framelen-SPDYLAY_FRAME_HEAD_LENGTH; + frame->hd.length = framelen-NGHTTP2_FRAME_HEAD_LENGTH; memset(*buf_ptr, 0, nv_offset); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->stream_id); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id); return framelen; } -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 *payload, size_t payloadlen, - spdylay_buffer *inflatebuf) + nghttp2_buffer *inflatebuf) { int r; - r = spdylay_frame_unpack_headers_without_nv(frame, head, headlen, + r = nghttp2_frame_unpack_headers_without_nv(frame, head, headlen, payload, payloadlen); if(r == 0) { size_t len_size; - len_size = spdylay_frame_get_len_size(frame->hd.version); + len_size = nghttp2_frame_get_len_size(frame->hd.version); if(len_size == 0) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - r = spdylay_frame_unpack_nv(&frame->nv, inflatebuf, len_size); + r = nghttp2_frame_unpack_nv(&frame->nv, inflatebuf, len_size); } return r; } -int spdylay_frame_unpack_headers_without_nv(spdylay_headers *frame, +int nghttp2_frame_unpack_headers_without_nv(nghttp2_headers *frame, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen) { ssize_t nv_offset; - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - nv_offset = spdylay_frame_nv_offset(SPDYLAY_HEADERS, frame->hd.version); + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + nv_offset = nghttp2_frame_nv_offset(NGHTTP2_HEADERS, frame->hd.version); assert(nv_offset > 0); if((ssize_t)(headlen + payloadlen) != nv_offset) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - frame->stream_id = spdylay_get_uint32(payload) & SPDYLAY_STREAM_ID_MASK; + frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; frame->nv = NULL; return 0; } -ssize_t spdylay_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_rst_stream *frame) +ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_rst_stream *frame) { ssize_t framelen = 16; int r; - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->stream_id); - spdylay_put_uint32be(&(*buf_ptr)[12], frame->status_code); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id); + nghttp2_put_uint32be(&(*buf_ptr)[12], frame->status_code); return framelen; } -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 *payload, size_t payloadlen) { if(payloadlen != 8) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - frame->stream_id = spdylay_get_uint32(payload) & SPDYLAY_STREAM_ID_MASK; - frame->status_code = spdylay_get_uint32(payload+4); + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; + frame->status_code = nghttp2_get_uint32(payload+4); return 0; } -ssize_t spdylay_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_window_update *frame) +ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_window_update *frame) { ssize_t framelen = 16; int r; - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->stream_id); - spdylay_put_uint32be(&(*buf_ptr)[12], frame->delta_window_size); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->stream_id); + nghttp2_put_uint32be(&(*buf_ptr)[12], frame->delta_window_size); return framelen; } -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 *payload, size_t payloadlen) { if(payloadlen != 8) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - frame->stream_id = spdylay_get_uint32(payload) & SPDYLAY_STREAM_ID_MASK; - frame->delta_window_size = spdylay_get_uint32(&payload[4]) & - SPDYLAY_DELTA_WINDOW_SIZE_MASK; + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + frame->stream_id = nghttp2_get_uint32(payload) & NGHTTP2_STREAM_ID_MASK; + frame->delta_window_size = nghttp2_get_uint32(&payload[4]) & + NGHTTP2_DELTA_WINDOW_SIZE_MASK; return 0; } -ssize_t spdylay_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_settings *frame) +ssize_t nghttp2_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_settings *frame) { - ssize_t framelen = SPDYLAY_FRAME_HEAD_LENGTH+frame->hd.length; + ssize_t framelen = NGHTTP2_FRAME_HEAD_LENGTH+frame->hd.length; size_t i; int r; - if(frame->hd.version != SPDYLAY_PROTO_SPDY2 && - frame->hd.version != SPDYLAY_PROTO_SPDY3) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + if(frame->hd.version != NGHTTP2_PROTO_SPDY2 && + frame->hd.version != NGHTTP2_PROTO_SPDY3) { + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - spdylay_put_uint32be(&(*buf_ptr)[8], frame->niv); - if(frame->hd.version == SPDYLAY_PROTO_SPDY2) { + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + nghttp2_put_uint32be(&(*buf_ptr)[8], frame->niv); + if(frame->hd.version == NGHTTP2_PROTO_SPDY2) { for(i = 0; i < frame->niv; ++i) { int off = i*8; /* spdy/2 spec says ID is network byte order, but publicly @@ -1041,87 +1041,87 @@ ssize_t spdylay_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr, (*buf_ptr)[12+off+1] = (frame->iv[i].settings_id >> 8) & 0xff; (*buf_ptr)[12+off+2] = (frame->iv[i].settings_id >>16) & 0xff; (*buf_ptr)[15+off] = frame->iv[i].flags; - spdylay_put_uint32be(&(*buf_ptr)[16+off], frame->iv[i].value); + nghttp2_put_uint32be(&(*buf_ptr)[16+off], frame->iv[i].value); } } else { for(i = 0; i < frame->niv; ++i) { int off = i*8; - spdylay_put_uint32be(&(*buf_ptr)[12+off], frame->iv[i].settings_id); + nghttp2_put_uint32be(&(*buf_ptr)[12+off], frame->iv[i].settings_id); (*buf_ptr)[12+off] = frame->iv[i].flags; - spdylay_put_uint32be(&(*buf_ptr)[16+off], frame->iv[i].value); + nghttp2_put_uint32be(&(*buf_ptr)[16+off], frame->iv[i].value); } } return framelen; } -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 *payload, size_t payloadlen) { size_t i; if(payloadlen < 4) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); - if(frame->hd.version != SPDYLAY_PROTO_SPDY2 && - frame->hd.version != SPDYLAY_PROTO_SPDY3) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); + if(frame->hd.version != NGHTTP2_PROTO_SPDY2 && + frame->hd.version != NGHTTP2_PROTO_SPDY3) { + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - frame->niv = spdylay_get_uint32(payload); + frame->niv = nghttp2_get_uint32(payload); if(payloadlen != 4+frame->niv*8) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - frame->iv = malloc(frame->niv*sizeof(spdylay_settings_entry)); + frame->iv = malloc(frame->niv*sizeof(nghttp2_settings_entry)); if(frame->iv == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - if(frame->hd.version == SPDYLAY_PROTO_SPDY2) { + if(frame->hd.version == NGHTTP2_PROTO_SPDY2) { for(i = 0; i < frame->niv; ++i) { size_t off = i*8; /* ID is little endian. See comments in - spdylay_frame_pack_settings(). */ + nghttp2_frame_pack_settings(). */ frame->iv[i].settings_id = payload[4+off] + (payload[4+off+1] << 8) +(payload[4+off+2] << 16); frame->iv[i].flags = payload[7+off]; - frame->iv[i].value = spdylay_get_uint32(&payload[8+off]); + frame->iv[i].value = nghttp2_get_uint32(&payload[8+off]); } } else { for(i = 0; i < frame->niv; ++i) { size_t off = i*8; - frame->iv[i].settings_id = spdylay_get_uint32(&payload[4+off]) & - SPDYLAY_SETTINGS_ID_MASK; + frame->iv[i].settings_id = nghttp2_get_uint32(&payload[4+off]) & + NGHTTP2_SETTINGS_ID_MASK; frame->iv[i].flags = payload[4+off]; - frame->iv[i].value = spdylay_get_uint32(&payload[8+off]); + frame->iv[i].value = nghttp2_get_uint32(&payload[8+off]); } } return 0; } -ssize_t spdylay_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_credential *frame) +ssize_t nghttp2_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_credential *frame) { ssize_t framelen; int r; size_t i, offset; - framelen = SPDYLAY_FRAME_HEAD_LENGTH+2+4+frame->proof.length; + framelen = NGHTTP2_FRAME_HEAD_LENGTH+2+4+frame->proof.length; for(i = 0; i < frame->ncerts; ++i) { framelen += 4+frame->certs[i].length; } - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } memset(*buf_ptr, 0, framelen); - spdylay_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); - offset = SPDYLAY_FRAME_HEAD_LENGTH; - spdylay_put_uint16be(&(*buf_ptr)[offset], frame->slot); + nghttp2_frame_pack_ctrl_hd(*buf_ptr, &frame->hd); + offset = NGHTTP2_FRAME_HEAD_LENGTH; + nghttp2_put_uint16be(&(*buf_ptr)[offset], frame->slot); offset += 2; - spdylay_put_uint32be(&(*buf_ptr)[offset], frame->proof.length); + nghttp2_put_uint32be(&(*buf_ptr)[offset], frame->proof.length); offset += 4; memcpy(&(*buf_ptr)[offset], frame->proof.data, frame->proof.length); offset += frame->proof.length; for(i = 0; i < frame->ncerts; ++i) { - spdylay_put_uint32be(&(*buf_ptr)[offset], frame->certs[i].length); + nghttp2_put_uint32be(&(*buf_ptr)[offset], frame->certs[i].length); offset += 4; memcpy(&(*buf_ptr)[offset], frame->certs[i].data, frame->certs[i].length); offset += frame->certs[i].length; @@ -1138,22 +1138,22 @@ ssize_t spdylay_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr, * This function returns the number of certificates in |payload| if it * succeeds, or one of the following negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The frame payload is invalid. */ -static int spdylay_frame_count_unpack_cert(const uint8_t *payload, +static int nghttp2_frame_count_unpack_cert(const uint8_t *payload, size_t payloadlen) { size_t n, offset = 0; for(n = 1; 1; ++n) { size_t len; if(offset+4 > payloadlen) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - len = spdylay_get_uint32(&payload[offset]); + len = nghttp2_get_uint32(&payload[offset]); offset += 4; if(len > payloadlen || offset+len > payloadlen) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } else { offset += len; if(offset == payloadlen) { @@ -1173,22 +1173,22 @@ static int spdylay_frame_count_unpack_cert(const uint8_t *payload, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory */ -static int spdylay_frame_unpack_cert(spdylay_mem_chunk **certs_ptr, +static int nghttp2_frame_unpack_cert(nghttp2_mem_chunk **certs_ptr, size_t ncerts, const uint8_t *payload, size_t payloadlen) { size_t offset, i, j; - spdylay_mem_chunk *certs; - certs = malloc(sizeof(spdylay_mem_chunk)*ncerts); + nghttp2_mem_chunk *certs; + certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts); if(certs == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } offset = 0; for(i = 0; i < ncerts; ++i) { - certs[i].length = spdylay_get_uint32(&payload[offset]); + certs[i].length = nghttp2_get_uint32(&payload[offset]); offset += 4; certs[i].data = malloc(certs[i].length); if(certs[i].data == NULL) { @@ -1204,10 +1204,10 @@ static int spdylay_frame_unpack_cert(spdylay_mem_chunk **certs_ptr, free(certs[j].data); } free(certs); - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } -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 *payload, size_t payloadlen) @@ -1215,30 +1215,30 @@ int spdylay_frame_unpack_credential(spdylay_credential *frame, size_t offset; int rv; if(payloadlen < 10) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } - spdylay_frame_unpack_ctrl_hd(&frame->hd, head); + nghttp2_frame_unpack_ctrl_hd(&frame->hd, head); offset = 0; - frame->slot = spdylay_get_uint16(&payload[offset]); + frame->slot = nghttp2_get_uint16(&payload[offset]); offset += 2; - frame->proof.length = spdylay_get_uint32(&payload[offset]); + frame->proof.length = nghttp2_get_uint32(&payload[offset]); offset += 4; if(frame->proof.length > payloadlen || offset+frame->proof.length > payloadlen) { - return SPDYLAY_ERR_INVALID_FRAME; + return NGHTTP2_ERR_INVALID_FRAME; } frame->proof.data = malloc(frame->proof.length); if(frame->proof.data == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } memcpy(frame->proof.data, &payload[offset], frame->proof.length); offset += frame->proof.length; - rv = spdylay_frame_count_unpack_cert(payload+offset, payloadlen-offset); + rv = nghttp2_frame_count_unpack_cert(payload+offset, payloadlen-offset); if(rv < 0) { goto fail; } frame->ncerts = rv; - rv = spdylay_frame_unpack_cert(&frame->certs, frame->ncerts, + rv = nghttp2_frame_unpack_cert(&frame->certs, frame->ncerts, payload+offset, payloadlen-offset); if(rv != 0) { goto fail; @@ -1249,11 +1249,11 @@ int spdylay_frame_unpack_credential(spdylay_credential *frame, return rv; } -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) { - spdylay_settings_entry *iv_copy; - size_t len = niv*sizeof(spdylay_settings_entry); + nghttp2_settings_entry *iv_copy; + size_t len = niv*sizeof(nghttp2_settings_entry); iv_copy = malloc(len); if(iv_copy == NULL) { return NULL; @@ -1262,35 +1262,35 @@ spdylay_settings_entry* spdylay_frame_iv_copy(const spdylay_settings_entry *iv, return iv_copy; } -static int spdylay_settings_entry_compar(const void *lhs, const void *rhs) +static int nghttp2_settings_entry_compar(const void *lhs, const void *rhs) { - return ((spdylay_settings_entry *)lhs)->settings_id - -((spdylay_settings_entry *)rhs)->settings_id; + return ((nghttp2_settings_entry *)lhs)->settings_id + -((nghttp2_settings_entry *)rhs)->settings_id; } -void spdylay_frame_iv_sort(spdylay_settings_entry *iv, size_t niv) +void nghttp2_frame_iv_sort(nghttp2_settings_entry *iv, size_t niv) { - qsort(iv, niv, sizeof(spdylay_settings_entry), spdylay_settings_entry_compar); + qsort(iv, niv, sizeof(nghttp2_settings_entry), nghttp2_settings_entry_compar); } -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) { switch(type) { - case SPDYLAY_SYN_STREAM: - return SPDYLAY_SYN_STREAM_NV_OFFSET; - case SPDYLAY_SYN_REPLY: { - if(version == SPDYLAY_PROTO_SPDY2) { - return SPDYLAY_SPDY2_SYN_REPLY_NV_OFFSET; - } else if(version == SPDYLAY_PROTO_SPDY3) { - return SPDYLAY_SPDY3_SYN_REPLY_NV_OFFSET; + case NGHTTP2_SYN_STREAM: + return NGHTTP2_SYN_STREAM_NV_OFFSET; + case NGHTTP2_SYN_REPLY: { + if(version == NGHTTP2_PROTO_SPDY2) { + return NGHTTP2_SPDY2_SYN_REPLY_NV_OFFSET; + } else if(version == NGHTTP2_PROTO_SPDY3) { + return NGHTTP2_SPDY3_SYN_REPLY_NV_OFFSET; } break; } - case SPDYLAY_HEADERS: { - if(version == SPDYLAY_PROTO_SPDY2) { - return SPDYLAY_SPDY2_HEADERS_NV_OFFSET; - } else if(version == SPDYLAY_PROTO_SPDY3) { - return SPDYLAY_SPDY3_HEADERS_NV_OFFSET; + case NGHTTP2_HEADERS: { + if(version == NGHTTP2_PROTO_SPDY2) { + return NGHTTP2_SPDY2_HEADERS_NV_OFFSET; + } else if(version == NGHTTP2_PROTO_SPDY3) { + return NGHTTP2_SPDY3_HEADERS_NV_OFFSET; } break; } @@ -1300,7 +1300,7 @@ ssize_t spdylay_frame_nv_offset(spdylay_frame_type type, uint16_t version) return -1; } -int spdylay_frame_nv_check_null(const char **nv) +int nghttp2_frame_nv_check_null(const char **nv) { size_t i, j; for(i = 0; nv[i]; i += 2) { diff --git a/lib/spdylay_frame.h b/lib/nghttp2_frame.h similarity index 72% rename from lib/spdylay_frame.h rename to lib/nghttp2_frame.h index f6373ff9..53b9621f 100644 --- a/lib/spdylay_frame.h +++ b/lib/nghttp2_frame.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,57 +22,57 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_FRAME_H -#define SPDYLAY_FRAME_H +#ifndef NGHTTP2_FRAME_H +#define NGHTTP2_FRAME_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include -#include "spdylay_zlib.h" -#include "spdylay_buffer.h" -#include "spdylay_client_cert_vector.h" +#include +#include "nghttp2_zlib.h" +#include "nghttp2_buffer.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 and 3. */ -#define SPDYLAY_LENGTH_MASK 0xffffff -#define SPDYLAY_VERSION_MASK 0x7fff -#define SPDYLAY_DELTA_WINDOW_SIZE_MASK 0x7fffffff -#define SPDYLAY_SETTINGS_ID_MASK 0xffffff +#define NGHTTP2_LENGTH_MASK 0xffffff +#define NGHTTP2_VERSION_MASK 0x7fff +#define NGHTTP2_DELTA_WINDOW_SIZE_MASK 0x7fffffff +#define NGHTTP2_SETTINGS_ID_MASK 0xffffff /* 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. */ -#define SPDYLAY_FRAME_HEAD_LENGTH 8 +#define NGHTTP2_FRAME_HEAD_LENGTH 8 /* The offset to the name/value header block in the frame (including 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 SPDYLAY_SPDY3_SYN_REPLY_NV_OFFSET 12 +#define NGHTTP2_SPDY2_SYN_REPLY_NV_OFFSET 14 +#define NGHTTP2_SPDY3_SYN_REPLY_NV_OFFSET 12 -#define SPDYLAY_SPDY2_HEADERS_NV_OFFSET 14 -#define SPDYLAY_SPDY3_HEADERS_NV_OFFSET 12 +#define NGHTTP2_SPDY2_HEADERS_NV_OFFSET 14 +#define NGHTTP2_SPDY3_HEADERS_NV_OFFSET 12 -#define spdylay_frame_get_nv_len(RED, LEN_SIZE) \ - (LEN_SIZE == 2 ? spdylay_buffer_reader_uint16(RED) : \ - spdylay_buffer_reader_uint32(RED)) +#define nghttp2_frame_get_nv_len(RED, LEN_SIZE) \ + (LEN_SIZE == 2 ? nghttp2_buffer_reader_uint16(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 ? \ - spdylay_put_uint16be(OUT, VAL) : spdylay_put_uint32be(OUT, VAL)) + nghttp2_put_uint16be(OUT, VAL) : nghttp2_put_uint32be(OUT, VAL)) /* Category of SPDY frames. */ typedef enum { /* Control frame */ - SPDYLAY_CTRL, + NGHTTP2_CTRL, /* DATA frame */ - SPDYLAY_DATA -} spdylay_frame_category; + NGHTTP2_DATA +} nghttp2_frame_category; /** * @struct @@ -84,7 +84,7 @@ typedef struct { */ 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; /** @@ -95,15 +95,15 @@ typedef struct { /** * The data to be sent for this DATA frame. */ - spdylay_data_provider data_prd; -} spdylay_data; + nghttp2_data_provider data_prd; +} nghttp2_data; /* * Returns the number of bytes in length of name/value pair for the * given protocol version |version|. If |version| is not supported, * 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 @@ -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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The deflate operation failed. - * SPDYLAY_ERR_FRAME_TOO_LARGE + * NGHTTP2_ERR_FRAME_TOO_LARGE * The length of the frame is too large. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr, - spdylay_syn_stream *frame, - spdylay_zlib *deflater); + nghttp2_syn_stream *frame, + nghttp2_zlib *deflater); /* * 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 * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_HEADER_BLOCK + * NGHTTP2_ERR_INVALID_HEADER_BLOCK * Unpacking succeeds but the header block is invalid. - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The input data are invalid. - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 *payload, size_t payloadlen, - spdylay_buffer *inflatebuf); + nghttp2_buffer *inflatebuf); /* * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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, size_t headlen, 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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The deflate operation failed. - * SPDYLAY_ERR_FRAME_TOO_LARGE + * NGHTTP2_ERR_FRAME_TOO_LARGE * The length of the frame is too large. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr, - spdylay_syn_reply *frame, - spdylay_zlib *deflater); + nghttp2_syn_reply *frame, + nghttp2_zlib *deflater); /* * 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 * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_HEADER_BLOCK + * NGHTTP2_ERR_INVALID_HEADER_BLOCK * Unpacking succeeds but the header block is invalid. - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The input data are invalid. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 *payload, size_t payloadlen, - spdylay_buffer *inflatebuf); + nghttp2_buffer *inflatebuf); /* * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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, size_t headlen, 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_ping *frame); +ssize_t nghttp2_frame_pack_ping(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_ping *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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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 *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 * negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_goaway *frame); +ssize_t nghttp2_frame_pack_goaway(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_goaway *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 * negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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 *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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The deflate operation failed. - * SPDYLAY_ERR_FRAME_TOO_LARGE + * NGHTTP2_ERR_FRAME_TOO_LARGE * The length of the frame is too large. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, - spdylay_headers *frame, - spdylay_zlib *deflater); + nghttp2_headers *frame, + nghttp2_zlib *deflater); /* * 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 * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_HEADER_BLOCK + * NGHTTP2_ERR_INVALID_HEADER_BLOCK * Unpacking succeeds but the header block is invalid. - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The input data are invalid. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 *payload, size_t payloadlen, - spdylay_buffer *inflatebuf); + nghttp2_buffer *inflatebuf); /* * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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, size_t headlen, 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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_rst_stream *frame); +ssize_t nghttp2_frame_pack_rst_stream(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_rst_stream *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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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 *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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_window_update *frame); +ssize_t nghttp2_frame_pack_window_update(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_window_update *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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * 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 *payload, 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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_settings *frame); +ssize_t nghttp2_frame_pack_settings(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_settings *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 * negative error codes: * - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * The version is not supported. - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The input data are invalid. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 *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 * returns one of the following negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr, - spdylay_credential *frame); +ssize_t nghttp2_frame_pack_credential(uint8_t **buf_ptr, size_t *buflen_ptr, + nghttp2_credential *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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The input data are invalid. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 *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 * 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 - * 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. */ -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 @@ -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 * following negative error codes: * - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The deflate operation failed. - * SPDYLAY_ERR_FRAME_TOO_LARGE + * NGHTTP2_ERR_FRAME_TOO_LARGE * The length of the frame is too large. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, uint8_t **nvbuf_ptr, size_t *nvbuflen_ptr, char **nv, size_t nv_offset, size_t len_size, - spdylay_zlib *deflater); + nghttp2_zlib *deflater); /* * 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_FRAME + * NGHTTP2_ERR_INVALID_FRAME * The input data are invalid. */ -int spdylay_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr, - spdylay_buffer *in, size_t len_size); +int nghttp2_frame_count_unpack_nv_space(size_t *nvlen_ptr, size_t *buflen_ptr, + nghttp2_buffer *in, size_t len_size); /* * 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 * 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, - * SPDYLAY_ERR_INVALID_HEADER_BLOCK means unpacking succeeded, but + * NGHTTP2_ERR_INVALID_HEADER_BLOCK means unpacking succeeded, but * header block validation failed. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_INVALID_HEADER_BLOCK + * NGHTTP2_ERR_INVALID_HEADER_BLOCK * Unpacking succeeds but the header block is invalid. The * possible reasons are: There are duplicate header names; or the * header names are not encoded in US-ASCII character set and not * lower cased; or the header name is zero-length string. - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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); /* @@ -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 * 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, int32_t stream_id, int32_t assoc_stream_id, 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, 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); -void spdylay_frame_ping_free(spdylay_ping *frame); +void nghttp2_frame_ping_free(nghttp2_ping *frame); /* * 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, 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, 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, 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, int32_t stream_id, 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 * 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, - 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 * function takes ownership of |proof->data| and |certs| on success. * 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, - spdylay_mem_chunk *proof, - spdylay_mem_chunk *certs, + nghttp2_mem_chunk *proof, + nghttp2_mem_chunk *certs, 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, - 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 * 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|. */ -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 * 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. */ -void spdylay_frame_nv_sort(char **nv); +void nghttp2_frame_nv_sort(char **nv); /* * 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 - * spdylay_frame_nv_copy(). If it succeeds, then call - * spdylay_frame_nv_downcase() and spdylay_frame_nv_sort() with the + * nghttp2_frame_nv_copy(). If it succeeds, then call + * nghttp2_frame_nv_downcase() and nghttp2_frame_nv_sort() with the * copied name/value pairs. * * This function returns the copied name/value pairs if it succeeds, * 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. */ -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. */ -void spdylay_frame_nv_2to3(char **nv); +void nghttp2_frame_nv_2to3(char **nv); /* * 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 * negative error code: * - * SPDYLAY_ERR_INVALID_ARGUMENT + * NGHTTP2_ERR_INVALID_ARGUMENT * 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 * entries in |iv|. This function returns the pointer to the copy if * 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); /* @@ -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 * 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 - * frame header. If |type| is neither SPDYLAY_SYN_STREAM, - * SPDYLAY_SYN_REPLY nor SPDYLAY_HEADERS, this function returns -1. + * frame header. If |type| is neither NGHTTP2_SYN_STREAM, + * NGHTTP2_SYN_REPLY nor NGHTTP2_HEADERS, 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 @@ -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. */ -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 */ diff --git a/lib/spdylay_gzip.c b/lib/nghttp2_gzip.c similarity index 86% rename from lib/spdylay_gzip.c rename to lib/nghttp2_gzip.c index f066769f..e472ec7f 100644 --- a/lib/spdylay_gzip.c +++ b/lib/nghttp2_gzip.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,16 +22,16 @@ * 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_gzip.h" +#include "nghttp2_gzip.h" #include -int spdylay_gzip_inflate_new(spdylay_gzip **inflater_ptr) +int nghttp2_gzip_inflate_new(nghttp2_gzip **inflater_ptr) { int rv; - *inflater_ptr = malloc(sizeof(spdylay_gzip)); + *inflater_ptr = malloc(sizeof(nghttp2_gzip)); if(*inflater_ptr == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } (*inflater_ptr)->zst.next_in = Z_NULL; (*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); if(rv != Z_OK) { free(*inflater_ptr); - return SPDYLAY_ERR_GZIP; + return NGHTTP2_ERR_GZIP; } return 0; } -void spdylay_gzip_inflate_del(spdylay_gzip *inflater) +void nghttp2_gzip_inflate_del(nghttp2_gzip *inflater) { if(inflater != NULL) { 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, 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_NEED_DICT: case Z_MEM_ERROR: - return SPDYLAY_ERR_GZIP; + return NGHTTP2_ERR_GZIP; default: assert(0); /* We need this for some compilers */ diff --git a/lib/spdylay_gzip.h b/lib/nghttp2_gzip.h similarity index 90% rename from lib/spdylay_gzip.h rename to lib/nghttp2_gzip.h index 4c0daf5d..6f309c89 100644 --- a/lib/spdylay_gzip.h +++ b/lib/nghttp2_gzip.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,17 +22,17 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_GZIP_H +#ifndef NGHTTP2_GZIP_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include -#include +#include -struct spdylay_gzip { +struct nghttp2_gzip { z_stream zst; }; -#endif /* SPDYLAY_GZIP_H */ +#endif /* NGHTTP2_GZIP_H */ diff --git a/lib/spdylay_helper.c b/lib/nghttp2_helper.c similarity index 68% rename from lib/spdylay_helper.c rename to lib/nghttp2_helper.c index 6686e829..e7132091 100644 --- a/lib/spdylay_helper.c +++ b/lib/nghttp2_helper.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,39 +22,39 @@ * 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_helper.h" +#include "nghttp2_helper.h" #include -#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); 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); 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; memcpy(&n, data, sizeof(uint16_t)); return ntohs(n); } -uint32_t spdylay_get_uint32(const uint8_t *data) +uint32_t nghttp2_get_uint32(const uint8_t *data) { uint32_t n; memcpy(&n, data, sizeof(uint32_t)); 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) { 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; temp = malloc(min_length); if(temp == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } else { free(*buf_ptr); *buf_ptr = temp; @@ -72,58 +72,58 @@ int spdylay_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr, return 0; } -const char* spdylay_strerror(int error_code) +const char* nghttp2_strerror(int error_code) { switch(error_code) { case 0: return "Success"; - case SPDYLAY_ERR_INVALID_ARGUMENT: + case NGHTTP2_ERR_INVALID_ARGUMENT: return "Invalid argument"; - case SPDYLAY_ERR_ZLIB: + case NGHTTP2_ERR_ZLIB: return "Zlib error"; - case SPDYLAY_ERR_UNSUPPORTED_VERSION: + case NGHTTP2_ERR_UNSUPPORTED_VERSION: return "Unsupported SPDY version"; - case SPDYLAY_ERR_WOULDBLOCK: + case NGHTTP2_ERR_WOULDBLOCK: return "Operation would block"; - case SPDYLAY_ERR_PROTO: + case NGHTTP2_ERR_PROTO: return "Protocol error"; - case SPDYLAY_ERR_INVALID_FRAME: + case NGHTTP2_ERR_INVALID_FRAME: return "Invalid frame octets"; - case SPDYLAY_ERR_EOF: + case NGHTTP2_ERR_EOF: return "EOF"; - case SPDYLAY_ERR_DEFERRED: + case NGHTTP2_ERR_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"; - case SPDYLAY_ERR_STREAM_CLOSED: + case NGHTTP2_ERR_STREAM_CLOSED: return "Stream was already closed or invalid"; - case SPDYLAY_ERR_STREAM_CLOSING: + case NGHTTP2_ERR_STREAM_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"; - case SPDYLAY_ERR_INVALID_STREAM_ID: + case NGHTTP2_ERR_INVALID_STREAM_ID: return "Stream ID is invalid"; - case SPDYLAY_ERR_INVALID_STREAM_STATE: + case NGHTTP2_ERR_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"; - case SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED: + case NGHTTP2_ERR_SYN_STREAM_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"; - case SPDYLAY_ERR_INVALID_HEADER_BLOCK: + case NGHTTP2_ERR_INVALID_HEADER_BLOCK: return "Invalid header block"; - case SPDYLAY_ERR_INVALID_STATE: + case NGHTTP2_ERR_INVALID_STATE: return "Invalid state"; - case SPDYLAY_ERR_GZIP: + case NGHTTP2_ERR_GZIP: 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"; - case SPDYLAY_ERR_FRAME_TOO_LARGE: + case NGHTTP2_ERR_FRAME_TOO_LARGE: return "The length of the frame is too large"; - case SPDYLAY_ERR_NOMEM: + case NGHTTP2_ERR_NOMEM: return "Out of memory"; - case SPDYLAY_ERR_CALLBACK_FAILURE: + case NGHTTP2_ERR_CALLBACK_FAILURE: return "The user callback function failed"; default: return "Unknown error code"; diff --git a/lib/spdylay_helper.h b/lib/nghttp2_helper.h similarity index 81% rename from lib/spdylay_helper.h rename to lib/nghttp2_helper.h index 7355cd71..cb3f3691 100644 --- a/lib/spdylay_helper.h +++ b/lib/nghttp2_helper.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,41 +22,41 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_HELPER_H -#define SPDYLAY_HELPER_H +#ifndef NGHTTP2_HELPER_H +#define NGHTTP2_HELPER_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include +#include -#define spdylay_min(A, B) ((A) < (B) ? (A) : (B)) -#define spdylay_max(A, B) ((A) > (B) ? (A) : (B)) +#define nghttp2_min(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 * 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 * 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 * 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 * 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 @@ -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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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); -#endif /* SPDYLAY_HELPER_H */ +#endif /* NGHTTP2_HELPER_H */ diff --git a/lib/spdylay_int.h b/lib/nghttp2_int.h similarity index 85% rename from lib/spdylay_int.h rename to lib/nghttp2_int.h index 02fcd69e..6448e421 100644 --- a/lib/spdylay_int.h +++ b/lib/nghttp2_int.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,8 +22,8 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_INT_H -#define SPDYLAY_INT_H +#ifndef NGHTTP2_INT_H +#define NGHTTP2_INT_H #ifdef HAVE_CONFIG_H # include @@ -33,12 +33,12 @@ /* 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], inclusive. */ typedef enum { - SPDYLAY_ERR_CREDENTIAL_PENDING = -101 -} spdylay_internal_error; + NGHTTP2_ERR_CREDENTIAL_PENDING = -101 +} nghttp2_internal_error; -#endif /* SPDYLAY_INT_H */ +#endif /* NGHTTP2_INT_H */ diff --git a/lib/spdylay_map.c b/lib/nghttp2_map.c similarity index 81% rename from lib/spdylay_map.c rename to lib/nghttp2_map.c index a42c98ef..92e5ea7e 100644 --- a/lib/spdylay_map.c +++ b/lib/nghttp2_map.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,21 +22,21 @@ * 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_map.h" +#include "nghttp2_map.h" -void spdylay_map_init(spdylay_map *map) +void nghttp2_map_init(nghttp2_map *map) { map->root = NULL; map->size = 0; } -void spdylay_map_free(spdylay_map *map) +void nghttp2_map_free(nghttp2_map *map) { map->root = NULL; } /* 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) { entry = entry->left; @@ -45,7 +45,7 @@ static spdylay_map_entry* find_left_most(spdylay_map_entry *entry) } /* 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(;;) { 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 no next node. */ -static spdylay_map_entry* traverse_postorder(spdylay_map_entry *parent, - spdylay_map_entry *entry) +static nghttp2_map_entry* traverse_postorder(nghttp2_map_entry *parent, + nghttp2_map_entry *entry) { if(!parent) { return NULL; @@ -77,17 +77,17 @@ static spdylay_map_entry* traverse_postorder(spdylay_map_entry *parent, } } -void spdylay_map_each_free(spdylay_map *map, - int (*func)(spdylay_map_entry *entry, void *ptr), +void nghttp2_map_each_free(nghttp2_map *map, + int (*func)(nghttp2_map_entry *entry, void *ptr), void *ptr) { - spdylay_map_entry *entry; + nghttp2_map_entry *entry; if(!map->root) { return; } entry = find_left_most_leaf(map->root); while(entry) { - spdylay_map_entry *parent = entry->parent; + nghttp2_map_entry *parent = entry->parent; /* Ignore return value. */ func(entry, ptr); /* 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 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) { return find_left_most(entry->right); } @@ -112,11 +112,11 @@ static spdylay_map_entry* traverse_inorder(spdylay_map_entry *entry) return parent; } -int spdylay_map_each(spdylay_map *map, - int (*func)(spdylay_map_entry *entry, void *ptr), +int nghttp2_map_each(nghttp2_map *map, + int (*func)(nghttp2_map_entry *entry, void *ptr), void *ptr) { - spdylay_map_entry *entry; + nghttp2_map_entry *entry; if(!map->root) { return 0; } @@ -147,16 +147,16 @@ static uint32_t hash32shift(uint32_t 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->parent = entry->left = entry->right = NULL; 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; root->left = entry; @@ -175,9 +175,9 @@ static spdylay_map_entry* rotate_left(spdylay_map_entry *entry) 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; root->right = entry; @@ -196,9 +196,9 @@ static spdylay_map_entry* rotate_right(spdylay_map_entry* entry) 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) { map->root = new_entry; map->size = 1; @@ -207,7 +207,7 @@ int spdylay_map_insert(spdylay_map *map, spdylay_map_entry *new_entry) /* Find position to insert. */ while(1) { if(new_entry->key == entry->key) { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } else { if(new_entry->key < entry->key) { if(entry->left) { @@ -250,9 +250,9 @@ int spdylay_map_insert(spdylay_map *map, spdylay_map_entry *new_entry) 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) { if(key < entry->key) { entry = entry->left; @@ -265,12 +265,12 @@ spdylay_map_entry* spdylay_map_find(spdylay_map *map, key_type key) 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) { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } /* Locate entry to delete. */ while(entry) { @@ -284,7 +284,7 @@ int spdylay_map_remove(spdylay_map *map, key_type key) } if(!entry) { /* Not found */ - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } /* Rotate and bubble down to satisfy heap property. */ for(;;) { @@ -330,7 +330,7 @@ int spdylay_map_remove(spdylay_map *map, key_type key) return 0; } -size_t spdylay_map_size(spdylay_map *map) +size_t nghttp2_map_size(nghttp2_map *map) { return map->size; } diff --git a/lib/spdylay_map.h b/lib/nghttp2_map.h similarity index 75% rename from lib/spdylay_map.h rename to lib/nghttp2_map.h index 869de195..1dacd70e 100644 --- a/lib/spdylay_map.h +++ b/lib/nghttp2_map.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,43 +22,43 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_MAP_H -#define SPDYLAY_MAP_H +#ifndef NGHTTP2_MAP_H +#define NGHTTP2_MAP_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include -#include "spdylay_int.h" +#include +#include "nghttp2_int.h" /* Implementation of ordered map */ typedef uint32_t key_type; typedef uint32_t pri_type; -typedef struct spdylay_map_entry { +typedef struct nghttp2_map_entry { key_type key; - struct spdylay_map_entry *parent, *left, *right; + struct nghttp2_map_entry *parent, *left, *right; pri_type priority; -} spdylay_map_entry; +} nghttp2_map_entry; typedef struct { - spdylay_map_entry *root; + nghttp2_map_entry *root; size_t size; -} spdylay_map; +} nghttp2_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 - * 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. */ -void spdylay_map_free(spdylay_map *map); +void nghttp2_map_free(nghttp2_map *map); /* * 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 * send argument. The return value of the |func| will be ignored. */ -void spdylay_map_each_free(spdylay_map *map, - int (*func)(spdylay_map_entry *entry, void *ptr), +void nghttp2_map_each_free(nghttp2_map *map, + int (*func)(nghttp2_map_entry *entry, void *ptr), void *ptr); /* * Initializes the |entry| with the |key|. All entries to be inserted * 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|. @@ -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 * negative error code: * - * SPDYLAY_ERR_INVALID_ARGUMENT + * NGHTTP2_ERR_INVALID_ARGUMENT * 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 * 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 @@ -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 * negative error codes: * - * SPDYLAY_ERR_INVALID_ARGUMENT + * NGHTTP2_ERR_INVALID_ARGUMENT * 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|. */ -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 @@ -122,10 +122,10 @@ size_t spdylay_map_size(spdylay_map *map); * invocation of |func| returns. * * 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 (*func)(spdylay_map_entry *entry, void *ptr), +int nghttp2_map_each(nghttp2_map *map, + int (*func)(nghttp2_map_entry *entry, void *ptr), void *ptr); -#endif /* SPDYLAY_MAP_H */ +#endif /* NGHTTP2_MAP_H */ diff --git a/lib/spdylay_net.h b/lib/nghttp2_net.h similarity index 93% rename from lib/spdylay_net.h rename to lib/nghttp2_net.h index 45a14916..a80e1461 100644 --- a/lib/spdylay_net.h +++ b/lib/nghttp2_net.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,8 +22,8 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_NET_H -#define SPDYLAY_NET_H +#ifndef NGHTTP2_NET_H +#define NGHTTP2_NET_H #ifdef HAVE_CONFIG_H # include @@ -41,4 +41,4 @@ # include #endif /* HAVE_WINSOCK2_H */ -#endif /* SPDYLAY_NET_H */ +#endif /* NGHTTP2_NET_H */ diff --git a/lib/spdylay_npn.c b/lib/nghttp2_npn.c similarity index 77% rename from lib/spdylay_npn.c rename to lib/nghttp2_npn.c index 853b5700..d82bb0d1 100644 --- a/lib/spdylay_npn.c +++ b/lib/nghttp2_npn.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,29 +22,29 @@ * 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_npn.h" +#include "nghttp2_npn.h" #include -static const spdylay_npn_proto proto_list[] = { - { (const unsigned char*)"spdy/3", 6, SPDYLAY_PROTO_SPDY3 }, - { (const unsigned char*)"spdy/2", 6, SPDYLAY_PROTO_SPDY2 } +static const nghttp2_npn_proto proto_list[] = { + { (const unsigned char*)"spdy/3", 6, NGHTTP2_PROTO_SPDY3 }, + { (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; } -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) { int http_selected = 0; unsigned int i = 0; for(; i < inlen; i += in[i]+1) { 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 && memcmp(&in[i+1], proto_list[j].proto, in[i]) == 0) { *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) { return 0; } else { if(protolen == 6) { if(memcmp("spdy/2", proto, 6) == 0) { - return SPDYLAY_PROTO_SPDY2; + return NGHTTP2_PROTO_SPDY2; } else if(memcmp("spdy/3", proto, 6) == 0) { - return SPDYLAY_PROTO_SPDY3; + return NGHTTP2_PROTO_SPDY3; } } return 0; diff --git a/lib/spdylay_npn.h b/lib/nghttp2_npn.h similarity index 90% rename from lib/spdylay_npn.h rename to lib/nghttp2_npn.h index 8d60c9d8..69ac466f 100644 --- a/lib/spdylay_npn.h +++ b/lib/nghttp2_npn.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,13 +22,13 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_NPN_H -#define SPDYLAY_NPN_H +#ifndef NGHTTP2_NPN_H +#define NGHTTP2_NPN_H #ifdef HAVE_CONFIG # include #endif /* HAVE_CONFIG */ -#include +#include -#endif /* SPDYLAY_NPN_H */ +#endif /* NGHTTP2_NPN_H */ diff --git a/lib/spdylay_outbound_item.c b/lib/nghttp2_outbound_item.c similarity index 53% rename from lib/spdylay_outbound_item.c rename to lib/nghttp2_outbound_item.c index 51e854eb..0466147b 100644 --- a/lib/spdylay_outbound_item.c +++ b/lib/nghttp2_outbound_item.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,58 +22,58 @@ * 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_outbound_item.h" +#include "nghttp2_outbound_item.h" #include -void spdylay_outbound_item_free(spdylay_outbound_item *item) +void nghttp2_outbound_item_free(nghttp2_outbound_item *item) { if(item == NULL) { return; } - if(item->frame_cat == SPDYLAY_CTRL) { - spdylay_frame_type frame_type; - spdylay_frame *frame; - frame_type = spdylay_outbound_item_get_ctrl_frame_type(item); - frame = spdylay_outbound_item_get_ctrl_frame(item); + if(item->frame_cat == NGHTTP2_CTRL) { + nghttp2_frame_type frame_type; + nghttp2_frame *frame; + frame_type = nghttp2_outbound_item_get_ctrl_frame_type(item); + frame = nghttp2_outbound_item_get_ctrl_frame(item); switch(frame_type) { - case SPDYLAY_SYN_STREAM: - spdylay_frame_syn_stream_free(&frame->syn_stream); - free(((spdylay_syn_stream_aux_data*)item->aux_data)->data_prd); + case NGHTTP2_SYN_STREAM: + nghttp2_frame_syn_stream_free(&frame->syn_stream); + free(((nghttp2_syn_stream_aux_data*)item->aux_data)->data_prd); break; - case SPDYLAY_SYN_REPLY: - spdylay_frame_syn_reply_free(&frame->syn_reply); + case NGHTTP2_SYN_REPLY: + nghttp2_frame_syn_reply_free(&frame->syn_reply); break; - case SPDYLAY_RST_STREAM: - spdylay_frame_rst_stream_free(&frame->rst_stream); + case NGHTTP2_RST_STREAM: + nghttp2_frame_rst_stream_free(&frame->rst_stream); break; - case SPDYLAY_SETTINGS: - spdylay_frame_settings_free(&frame->settings); + case NGHTTP2_SETTINGS: + nghttp2_frame_settings_free(&frame->settings); break; - case SPDYLAY_NOOP: + case NGHTTP2_NOOP: /* We don't have any public API to add NOOP, so here is unreachable. */ assert(0); - case SPDYLAY_PING: - spdylay_frame_ping_free(&frame->ping); + case NGHTTP2_PING: + nghttp2_frame_ping_free(&frame->ping); break; - case SPDYLAY_GOAWAY: - spdylay_frame_goaway_free(&frame->goaway); + case NGHTTP2_GOAWAY: + nghttp2_frame_goaway_free(&frame->goaway); break; - case SPDYLAY_HEADERS: - spdylay_frame_headers_free(&frame->headers); + case NGHTTP2_HEADERS: + nghttp2_frame_headers_free(&frame->headers); break; - case SPDYLAY_WINDOW_UPDATE: - spdylay_frame_window_update_free(&frame->window_update); + case NGHTTP2_WINDOW_UPDATE: + nghttp2_frame_window_update_free(&frame->window_update); break; - case SPDYLAY_CREDENTIAL: - spdylay_frame_credential_free(&frame->credential); + case NGHTTP2_CREDENTIAL: + nghttp2_frame_credential_free(&frame->credential); break; } - } else if(item->frame_cat == SPDYLAY_DATA) { - spdylay_data *data_frame; - data_frame = spdylay_outbound_item_get_data_frame(item); - spdylay_frame_data_free(data_frame); + } else if(item->frame_cat == NGHTTP2_DATA) { + nghttp2_data *data_frame; + data_frame = nghttp2_outbound_item_get_data_frame(item); + nghttp2_frame_data_free(data_frame); } else { /* Unreachable */ assert(0); diff --git a/lib/spdylay_outbound_item.h b/lib/nghttp2_outbound_item.h similarity index 71% rename from lib/spdylay_outbound_item.h rename to lib/nghttp2_outbound_item.h index 902c94d8..0cb2914a 100644 --- a/lib/spdylay_outbound_item.h +++ b/lib/nghttp2_outbound_item.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,32 +22,32 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_OUTBOUND_ITEM_H -#define SPDYLAY_OUTBOUND_ITEM_H +#ifndef NGHTTP2_OUTBOUND_ITEM_H +#define NGHTTP2_OUTBOUND_ITEM_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include -#include "spdylay_frame.h" +#include +#include "nghttp2_frame.h" /* Priority for PING */ -#define SPDYLAY_OB_PRI_PING -10 +#define NGHTTP2_OB_PRI_PING -10 /* 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 */ -#define SPDYLAY_OB_PRI_AFTER_CREDENTIAL -1 +#define NGHTTP2_OB_PRI_AFTER_CREDENTIAL -1 typedef struct { - spdylay_data_provider *data_prd; + nghttp2_data_provider *data_prd; void *stream_user_data; -} spdylay_syn_stream_aux_data; +} nghttp2_syn_stream_aux_data; typedef struct { - /* Type of |frame|. SPDYLAY_CTRL: spdylay_frame*, SPDYLAY_DATA: - spdylay_data* */ - spdylay_frame_category frame_cat; + /* Type of |frame|. NGHTTP2_CTRL: nghttp2_frame*, NGHTTP2_DATA: + nghttp2_data* */ + nghttp2_frame_category frame_cat; void *frame; void *aux_data; /* Initial priority of this item */ @@ -63,18 +63,18 @@ typedef struct { prioritized streams. */ int pri; int64_t seq; -} spdylay_outbound_item; +} nghttp2_outbound_item; /* * Deallocates resource for |item|. If |item| is NULL, this function * 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. */ -#define spdylay_outbound_item_get_ctrl_frame(ITEM) ((spdylay_frame*)ITEM->frame) -#define spdylay_outbound_item_get_ctrl_frame_type(ITEM) \ - (((spdylay_frame*)ITEM->frame)->ctrl.hd.type) -#define spdylay_outbound_item_get_data_frame(ITEM) ((spdylay_data*)ITEM->frame) +/* Macros to cast nghttp2_outbound_item.frame to the proper type. */ +#define nghttp2_outbound_item_get_ctrl_frame(ITEM) ((nghttp2_frame*)ITEM->frame) +#define nghttp2_outbound_item_get_ctrl_frame_type(ITEM) \ + (((nghttp2_frame*)ITEM->frame)->ctrl.hd.type) +#define nghttp2_outbound_item_get_data_frame(ITEM) ((nghttp2_data*)ITEM->frame) -#endif /* SPDYLAY_OUTBOUND_ITEM_H */ +#endif /* NGHTTP2_OUTBOUND_ITEM_H */ diff --git a/lib/spdylay_pq.c b/lib/nghttp2_pq.c similarity index 81% rename from lib/spdylay_pq.c rename to lib/nghttp2_pq.c index 43a5fbea..2a8d8938 100644 --- a/lib/spdylay_pq.c +++ b/lib/nghttp2_pq.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,34 +22,34 @@ * 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_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->q = malloc(pq->capacity * sizeof(void*)); if(pq->q == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } pq->length = 0; pq->compar = compar; return 0; } -void spdylay_pq_free(spdylay_pq *pq) +void nghttp2_pq_free(nghttp2_pq *pq) { free(pq->q); 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]; pq->q[i] = pq->q[j]; 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) { 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) { void *nq; nq = realloc(pq->q, (pq->capacity*2) * sizeof(void*)); if(nq == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } pq->capacity *= 2; pq->q = nq; @@ -79,7 +79,7 @@ int spdylay_pq_push(spdylay_pq *pq, void *item) return 0; } -void* spdylay_pq_top(spdylay_pq *pq) +void* nghttp2_pq_top(nghttp2_pq *pq) { if(pq->length == 0) { 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 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) { 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; } -size_t spdylay_pq_size(spdylay_pq *pq) +size_t nghttp2_pq_size(nghttp2_pq *pq) { return pq->length; } diff --git a/lib/spdylay_pq.h b/lib/nghttp2_pq.h similarity index 81% rename from lib/spdylay_pq.h rename to lib/nghttp2_pq.h index 9835e213..c574ba6d 100644 --- a/lib/spdylay_pq.h +++ b/lib/nghttp2_pq.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,15 +22,15 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_PQ_H -#define SPDYLAY_PQ_H +#ifndef NGHTTP2_PQ_H +#define NGHTTP2_PQ_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include -#include "spdylay_int.h" +#include +#include "nghttp2_int.h" /* Implementation of priority queue */ @@ -43,8 +43,8 @@ typedef struct { automatically extended when length is reached to this value. */ size_t capacity; /* The compare function between items */ - spdylay_compar compar; -} spdylay_pq; + nghttp2_compar compar; +} nghttp2_pq; /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 * 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|. @@ -69,31 +69,31 @@ void spdylay_pq_free(spdylay_pq *pq); * This function returns 0 if it succeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, * 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 * 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. */ -int spdylay_pq_empty(spdylay_pq *pq); +int nghttp2_pq_empty(nghttp2_pq *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 */ diff --git a/lib/spdylay_queue.c b/lib/nghttp2_queue.c similarity index 73% rename from lib/spdylay_queue.c rename to lib/nghttp2_queue.c index a0881475..9f638254 100644 --- a/lib/spdylay_queue.c +++ b/lib/nghttp2_queue.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,36 +22,36 @@ * 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_queue.h" +#include "nghttp2_queue.h" #include #include -void spdylay_queue_init(spdylay_queue *queue) +void nghttp2_queue_init(nghttp2_queue *queue) { queue->front = queue->back = NULL; } -void spdylay_queue_free(spdylay_queue *queue) +void nghttp2_queue_free(nghttp2_queue *queue) { if(!queue) { return; } else { - spdylay_queue_cell *p = queue->front; + nghttp2_queue_cell *p = queue->front; while(p) { - spdylay_queue_cell *next = p->next; + nghttp2_queue_cell *next = p->next; free(p); 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 - (sizeof(spdylay_queue_cell)); + nghttp2_queue_cell *new_cell = (nghttp2_queue_cell*)malloc + (sizeof(nghttp2_queue_cell)); if(!new_cell) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } new_cell->data = data; new_cell->next = NULL; @@ -65,9 +65,9 @@ int spdylay_queue_push(spdylay_queue *queue, void *data) 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); queue->front = front->next; if(front == queue->back) { @@ -76,19 +76,19 @@ void spdylay_queue_pop(spdylay_queue *queue) free(front); } -void* spdylay_queue_front(spdylay_queue *queue) +void* nghttp2_queue_front(nghttp2_queue *queue) { assert(queue->front); return queue->front->data; } -void* spdylay_queue_back(spdylay_queue *queue) +void* nghttp2_queue_back(nghttp2_queue *queue) { assert(queue->back); return queue->back->data; } -int spdylay_queue_empty(spdylay_queue *queue) +int nghttp2_queue_empty(nghttp2_queue *queue) { return queue->front == NULL; } diff --git a/lib/spdylay_queue.h b/lib/nghttp2_queue.h similarity index 66% rename from lib/spdylay_queue.h rename to lib/nghttp2_queue.h index ff20bca1..e53564b1 100644 --- a/lib/spdylay_queue.h +++ b/lib/nghttp2_queue.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,30 +22,30 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_QUEUE_H -#define SPDYLAY_QUEUE_H +#ifndef NGHTTP2_QUEUE_H +#define NGHTTP2_QUEUE_H #ifdef HAVE_CONFIG_H # include "config.h" #endif /* HAVE_CONFIG_H */ -#include +#include -typedef struct spdylay_queue_cell { +typedef struct nghttp2_queue_cell { void *data; - struct spdylay_queue_cell *next; -} spdylay_queue_cell; + struct nghttp2_queue_cell *next; +} nghttp2_queue_cell; typedef struct { - spdylay_queue_cell *front, *back; -} spdylay_queue; + nghttp2_queue_cell *front, *back; +} nghttp2_queue; -void spdylay_queue_init(spdylay_queue *queue); -void spdylay_queue_free(spdylay_queue *queue); -int spdylay_queue_push(spdylay_queue *queue, void *data); -void spdylay_queue_pop(spdylay_queue *queue); -void* spdylay_queue_front(spdylay_queue *queue); -void* spdylay_queue_back(spdylay_queue *queue); -int spdylay_queue_empty(spdylay_queue *queue); +void nghttp2_queue_init(nghttp2_queue *queue); +void nghttp2_queue_free(nghttp2_queue *queue); +int nghttp2_queue_push(nghttp2_queue *queue, void *data); +void nghttp2_queue_pop(nghttp2_queue *queue); +void* nghttp2_queue_front(nghttp2_queue *queue); +void* nghttp2_queue_back(nghttp2_queue *queue); +int nghttp2_queue_empty(nghttp2_queue *queue); -#endif /* SPDYLAY_QUEUE_H */ +#endif /* NGHTTP2_QUEUE_H */ diff --git a/lib/spdylay_session.c b/lib/nghttp2_session.c similarity index 52% rename from lib/spdylay_session.c rename to lib/nghttp2_session.c index f1247b47..cac9db72 100644 --- a/lib/spdylay_session.c +++ b/lib/nghttp2_session.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,64 +22,64 @@ * 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_session.h" +#include "nghttp2_session.h" #include #include #include #include -#include "spdylay_helper.h" -#include "spdylay_net.h" +#include "nghttp2_helper.h" +#include "nghttp2_net.h" /* * Returns non-zero if the number of outgoing opened streams is larger * than or equal to - * remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]. + * remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]. */ -static int spdylay_session_is_outgoing_concurrent_streams_max -(spdylay_session *session) +static int nghttp2_session_is_outgoing_concurrent_streams_max +(nghttp2_session *session) { - return session->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] + return session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] <= session->num_outgoing_streams; } /* * Returns non-zero if the number of incoming opened streams is larger * than or equal to - * local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]. + * local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]. */ -static int spdylay_session_is_incoming_concurrent_streams_max -(spdylay_session *session) +static int nghttp2_session_is_incoming_concurrent_streams_max +(nghttp2_session *session) { - return session->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] + return session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] <= session->num_incoming_streams; } /* * Returns non-zero if |error| is non-fatal error. */ -static int spdylay_is_non_fatal(int error) +static int nghttp2_is_non_fatal(int error) { - return error < 0 && error > SPDYLAY_ERR_FATAL; + return error < 0 && error > NGHTTP2_ERR_FATAL; } /* * Returns non-zero if |error| is fatal error. */ -static int spdylay_is_fatal(int error) +static int nghttp2_is_fatal(int error) { - return error < SPDYLAY_ERR_FATAL; + return error < NGHTTP2_ERR_FATAL; } -int spdylay_session_fail_session(spdylay_session *session, +int nghttp2_session_fail_session(nghttp2_session *session, uint32_t status_code) { - session->goaway_flags |= SPDYLAY_GOAWAY_FAIL_ON_SEND; - return spdylay_submit_goaway(session, status_code); + session->goaway_flags |= NGHTTP2_GOAWAY_FAIL_ON_SEND; + return nghttp2_submit_goaway(session, status_code); } -int spdylay_session_is_my_stream_id(spdylay_session *session, +int nghttp2_session_is_my_stream_id(nghttp2_session *session, int32_t stream_id) { int r; @@ -90,17 +90,17 @@ int spdylay_session_is_my_stream_id(spdylay_session *session, return (session->server && r == 0) || (!session->server && r == 1); } -spdylay_stream* spdylay_session_get_stream(spdylay_session *session, +nghttp2_stream* nghttp2_session_get_stream(nghttp2_session *session, int32_t stream_id) { - return (spdylay_stream*)spdylay_map_find(&session->streams, stream_id); + return (nghttp2_stream*)nghttp2_map_find(&session->streams, stream_id); } -static int spdylay_outbound_item_compar(const void *lhsx, const void *rhsx) +static int nghttp2_outbound_item_compar(const void *lhsx, const void *rhsx) { - const spdylay_outbound_item *lhs, *rhs; - lhs = (const spdylay_outbound_item*)lhsx; - rhs = (const spdylay_outbound_item*)rhsx; + const nghttp2_outbound_item *lhs, *rhs; + lhs = (const nghttp2_outbound_item*)lhsx; + rhs = (const nghttp2_outbound_item*)rhsx; if(lhs->pri == rhs->pri) { return (lhs->seq < rhs->seq) ? -1 : ((lhs->seq > rhs->seq) ? 1 : 0); } else { @@ -108,12 +108,12 @@ static int spdylay_outbound_item_compar(const void *lhsx, const void *rhsx) } } -static void spdylay_inbound_frame_reset(spdylay_inbound_frame *iframe) +static void nghttp2_inbound_frame_reset(nghttp2_inbound_frame *iframe) { - iframe->state = SPDYLAY_RECV_HEAD; + iframe->state = NGHTTP2_RECV_HEAD; iframe->payloadlen = iframe->buflen = iframe->off = 0; iframe->headbufoff = 0; - spdylay_buffer_reset(&iframe->inflatebuf); + nghttp2_buffer_reset(&iframe->inflatebuf); iframe->error_code = 0; } @@ -122,120 +122,120 @@ static void spdylay_inbound_frame_reset(spdylay_inbound_frame *iframe) * incoming frame. If the incoming frame does not have name/value * block, this function returns -1. */ -static size_t spdylay_inbound_frame_payload_nv_offset -(spdylay_inbound_frame *iframe) +static size_t nghttp2_inbound_frame_payload_nv_offset +(nghttp2_inbound_frame *iframe) { uint16_t type, version; ssize_t offset; - type = spdylay_get_uint16(&iframe->headbuf[2]); - version = spdylay_get_uint16(&iframe->headbuf[0]) & SPDYLAY_VERSION_MASK; - offset = spdylay_frame_nv_offset(type, version); + type = nghttp2_get_uint16(&iframe->headbuf[2]); + version = nghttp2_get_uint16(&iframe->headbuf[0]) & NGHTTP2_VERSION_MASK; + offset = nghttp2_frame_nv_offset(type, version); if(offset != -1) { - offset -= SPDYLAY_HEAD_LEN; + offset -= NGHTTP2_HEAD_LEN; } return offset; } -static int spdylay_session_new(spdylay_session **session_ptr, +static int nghttp2_session_new(nghttp2_session **session_ptr, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data, size_t cli_certvec_length, int hd_comp) { int r; - if(version != SPDYLAY_PROTO_SPDY2 && version != SPDYLAY_PROTO_SPDY3) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + if(version != NGHTTP2_PROTO_SPDY2 && version != NGHTTP2_PROTO_SPDY3) { + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } - *session_ptr = malloc(sizeof(spdylay_session)); + *session_ptr = malloc(sizeof(nghttp2_session)); if(*session_ptr == NULL) { - r = SPDYLAY_ERR_NOMEM; + r = NGHTTP2_ERR_NOMEM; goto fail_session; } - memset(*session_ptr, 0, sizeof(spdylay_session)); + memset(*session_ptr, 0, sizeof(nghttp2_session)); (*session_ptr)->version = version; /* next_stream_id, last_recv_stream_id and next_unique_id are - initialized in either spdylay_session_client_new or - spdylay_session_server_new */ + initialized in either nghttp2_session_client_new or + nghttp2_session_server_new */ (*session_ptr)->flow_control = - (*session_ptr)->version == SPDYLAY_PROTO_SPDY3; + (*session_ptr)->version == NGHTTP2_PROTO_SPDY3; (*session_ptr)->last_ping_unique_id = 0; (*session_ptr)->next_seq = 0; - (*session_ptr)->goaway_flags = SPDYLAY_GOAWAY_NONE; + (*session_ptr)->goaway_flags = NGHTTP2_GOAWAY_NONE; (*session_ptr)->last_good_stream_id = 0; (*session_ptr)->max_recv_ctrl_frame_buf = (1 << 24)-1; - r = spdylay_zlib_deflate_hd_init(&(*session_ptr)->hd_deflater, + r = nghttp2_zlib_deflate_hd_init(&(*session_ptr)->hd_deflater, hd_comp, (*session_ptr)->version); if(r != 0) { goto fail_hd_deflater; } - r = spdylay_zlib_inflate_hd_init(&(*session_ptr)->hd_inflater, + r = nghttp2_zlib_inflate_hd_init(&(*session_ptr)->hd_inflater, (*session_ptr)->version); if(r != 0) { goto fail_hd_inflater; } - spdylay_map_init(&(*session_ptr)->streams); - r = spdylay_pq_init(&(*session_ptr)->ob_pq, spdylay_outbound_item_compar); + nghttp2_map_init(&(*session_ptr)->streams); + r = nghttp2_pq_init(&(*session_ptr)->ob_pq, nghttp2_outbound_item_compar); if(r != 0) { goto fail_ob_pq; } - r = spdylay_pq_init(&(*session_ptr)->ob_ss_pq, spdylay_outbound_item_compar); + r = nghttp2_pq_init(&(*session_ptr)->ob_ss_pq, nghttp2_outbound_item_compar); if(r != 0) { goto fail_ob_ss_pq; } (*session_ptr)->aob.framebuf = malloc - (SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH); + (NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH); if((*session_ptr)->aob.framebuf == NULL) { - r = SPDYLAY_ERR_NOMEM; + r = NGHTTP2_ERR_NOMEM; goto fail_aob_framebuf; } - (*session_ptr)->aob.framebufmax = SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH; + (*session_ptr)->aob.framebufmax = NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH; - (*session_ptr)->nvbuf = malloc(SPDYLAY_INITIAL_NV_BUFFER_LENGTH); + (*session_ptr)->nvbuf = malloc(NGHTTP2_INITIAL_NV_BUFFER_LENGTH); if((*session_ptr)->nvbuf == NULL) { - r = SPDYLAY_ERR_NOMEM; + r = NGHTTP2_ERR_NOMEM; goto fail_nvbuf; } - (*session_ptr)->nvbuflen = SPDYLAY_INITIAL_NV_BUFFER_LENGTH; + (*session_ptr)->nvbuflen = NGHTTP2_INITIAL_NV_BUFFER_LENGTH; memset((*session_ptr)->remote_settings, 0, sizeof((*session_ptr)->remote_settings)); - (*session_ptr)->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = - SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS; - (*session_ptr)->remote_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE] = - SPDYLAY_INITIAL_WINDOW_SIZE; + (*session_ptr)->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = + NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS; + (*session_ptr)->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE] = + NGHTTP2_INITIAL_WINDOW_SIZE; memset((*session_ptr)->local_settings, 0, sizeof((*session_ptr)->local_settings)); - (*session_ptr)->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = - SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS; - (*session_ptr)->local_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE] = - SPDYLAY_INITIAL_WINDOW_SIZE; + (*session_ptr)->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = + NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS; + (*session_ptr)->local_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE] = + NGHTTP2_INITIAL_WINDOW_SIZE; (*session_ptr)->callbacks = *callbacks; (*session_ptr)->user_data = user_data; - (*session_ptr)->iframe.buf = malloc(SPDYLAY_INITIAL_INBOUND_FRAMEBUF_LENGTH); + (*session_ptr)->iframe.buf = malloc(NGHTTP2_INITIAL_INBOUND_FRAMEBUF_LENGTH); if((*session_ptr)->iframe.buf == NULL) { - r = SPDYLAY_ERR_NOMEM; + r = NGHTTP2_ERR_NOMEM; goto fail_iframe_buf; } - (*session_ptr)->iframe.bufmax = SPDYLAY_INITIAL_INBOUND_FRAMEBUF_LENGTH; - spdylay_buffer_init(&(*session_ptr)->iframe.inflatebuf, 4096); + (*session_ptr)->iframe.bufmax = NGHTTP2_INITIAL_INBOUND_FRAMEBUF_LENGTH; + nghttp2_buffer_init(&(*session_ptr)->iframe.inflatebuf, 4096); - spdylay_inbound_frame_reset(&(*session_ptr)->iframe); + nghttp2_inbound_frame_reset(&(*session_ptr)->iframe); - r = spdylay_client_cert_vector_init(&(*session_ptr)->cli_certvec, + r = nghttp2_client_cert_vector_init(&(*session_ptr)->cli_certvec, cli_certvec_length); if(r != 0) { goto fail_client_cert_vector; @@ -250,29 +250,29 @@ static int spdylay_session_new(spdylay_session **session_ptr, fail_nvbuf: free((*session_ptr)->aob.framebuf); fail_aob_framebuf: - spdylay_pq_free(&(*session_ptr)->ob_ss_pq); + nghttp2_pq_free(&(*session_ptr)->ob_ss_pq); fail_ob_ss_pq: - spdylay_pq_free(&(*session_ptr)->ob_pq); + nghttp2_pq_free(&(*session_ptr)->ob_pq); fail_ob_pq: /* No need to free (*session_ptr)->streams) here. */ - spdylay_zlib_inflate_free(&(*session_ptr)->hd_inflater); + nghttp2_zlib_inflate_free(&(*session_ptr)->hd_inflater); fail_hd_inflater: - spdylay_zlib_deflate_free(&(*session_ptr)->hd_deflater); + nghttp2_zlib_deflate_free(&(*session_ptr)->hd_deflater); fail_hd_deflater: free(*session_ptr); fail_session: return r; } -int spdylay_session_client_new(spdylay_session **session_ptr, +int nghttp2_session_client_new(nghttp2_session **session_ptr, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data) { int r; /* For client side session, header compression is disabled. */ - r = spdylay_session_new(session_ptr, version, callbacks, user_data, - SPDYLAY_INITIAL_CLIENT_CERT_VECTOR_LENGTH, 0); + r = nghttp2_session_new(session_ptr, version, callbacks, user_data, + NGHTTP2_INITIAL_CLIENT_CERT_VECTOR_LENGTH, 0); if(r == 0) { /* IDs for use in client */ (*session_ptr)->next_stream_id = 1; @@ -282,14 +282,14 @@ int spdylay_session_client_new(spdylay_session **session_ptr, return r; } -int spdylay_session_server_new(spdylay_session **session_ptr, +int nghttp2_session_server_new(nghttp2_session **session_ptr, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data) { int r; /* Enable header compression on server side. */ - r = spdylay_session_new(session_ptr, version, callbacks, user_data, + r = nghttp2_session_new(session_ptr, version, callbacks, user_data, 0, 1 /* hd_comp */); if(r == 0) { (*session_ptr)->server = 1; @@ -301,141 +301,141 @@ int spdylay_session_server_new(spdylay_session **session_ptr, return r; } -static int spdylay_free_streams(spdylay_map_entry *entry, void *ptr) +static int nghttp2_free_streams(nghttp2_map_entry *entry, void *ptr) { - spdylay_stream_free((spdylay_stream*)entry); + nghttp2_stream_free((nghttp2_stream*)entry); free(entry); return 0; } -static void spdylay_session_ob_pq_free(spdylay_pq *pq) +static void nghttp2_session_ob_pq_free(nghttp2_pq *pq) { - while(!spdylay_pq_empty(pq)) { - spdylay_outbound_item *item = (spdylay_outbound_item*)spdylay_pq_top(pq); - spdylay_outbound_item_free(item); + while(!nghttp2_pq_empty(pq)) { + nghttp2_outbound_item *item = (nghttp2_outbound_item*)nghttp2_pq_top(pq); + nghttp2_outbound_item_free(item); free(item); - spdylay_pq_pop(pq); + nghttp2_pq_pop(pq); } - spdylay_pq_free(pq); + nghttp2_pq_free(pq); } -static void spdylay_active_outbound_item_reset -(spdylay_active_outbound_item *aob) +static void nghttp2_active_outbound_item_reset +(nghttp2_active_outbound_item *aob) { - spdylay_outbound_item_free(aob->item); + nghttp2_outbound_item_free(aob->item); free(aob->item); aob->item = NULL; aob->framebuflen = aob->framebufoff = 0; } -void spdylay_session_del(spdylay_session *session) +void nghttp2_session_del(nghttp2_session *session) { if(session == NULL) { return; } - spdylay_map_each_free(&session->streams, spdylay_free_streams, NULL); - spdylay_session_ob_pq_free(&session->ob_pq); - spdylay_session_ob_pq_free(&session->ob_ss_pq); - spdylay_zlib_deflate_free(&session->hd_deflater); - spdylay_zlib_inflate_free(&session->hd_inflater); - spdylay_active_outbound_item_reset(&session->aob); + nghttp2_map_each_free(&session->streams, nghttp2_free_streams, NULL); + nghttp2_session_ob_pq_free(&session->ob_pq); + nghttp2_session_ob_pq_free(&session->ob_ss_pq); + nghttp2_zlib_deflate_free(&session->hd_deflater); + nghttp2_zlib_inflate_free(&session->hd_inflater); + nghttp2_active_outbound_item_reset(&session->aob); free(session->aob.framebuf); free(session->nvbuf); - spdylay_buffer_free(&session->iframe.inflatebuf); + nghttp2_buffer_free(&session->iframe.inflatebuf); free(session->iframe.buf); - spdylay_client_cert_vector_free(&session->cli_certvec); + nghttp2_client_cert_vector_free(&session->cli_certvec); free(session); } -int spdylay_session_add_frame(spdylay_session *session, - spdylay_frame_category frame_cat, +int nghttp2_session_add_frame(nghttp2_session *session, + nghttp2_frame_category frame_cat, void *abs_frame, void *aux_data) { int r = 0; - spdylay_outbound_item *item; - item = malloc(sizeof(spdylay_outbound_item)); + nghttp2_outbound_item *item; + item = malloc(sizeof(nghttp2_outbound_item)); if(item == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } item->frame_cat = frame_cat; item->frame = abs_frame; item->aux_data = aux_data; item->seq = session->next_seq++; /* Set priority lowest at the moment. */ - item->pri = spdylay_session_get_pri_lowest(session); - if(frame_cat == SPDYLAY_CTRL) { - spdylay_frame *frame = (spdylay_frame*)abs_frame; - spdylay_frame_type frame_type = frame->ctrl.hd.type; + item->pri = nghttp2_session_get_pri_lowest(session); + if(frame_cat == NGHTTP2_CTRL) { + nghttp2_frame *frame = (nghttp2_frame*)abs_frame; + nghttp2_frame_type frame_type = frame->ctrl.hd.type; switch(frame_type) { - case SPDYLAY_SYN_STREAM: + case NGHTTP2_SYN_STREAM: item->pri = frame->syn_stream.pri; break; - case SPDYLAY_SYN_REPLY: { - spdylay_stream *stream = spdylay_session_get_stream + case NGHTTP2_SYN_REPLY: { + nghttp2_stream *stream = nghttp2_session_get_stream (session, frame->syn_reply.stream_id); if(stream) { item->pri = stream->pri; } break; } - case SPDYLAY_RST_STREAM: { - spdylay_stream *stream = spdylay_session_get_stream + case NGHTTP2_RST_STREAM: { + nghttp2_stream *stream = nghttp2_session_get_stream (session, frame->rst_stream.stream_id); if(stream) { - stream->state = SPDYLAY_STREAM_CLOSING; + stream->state = NGHTTP2_STREAM_CLOSING; item->pri = stream->pri; } break; } - case SPDYLAY_SETTINGS: - /* Should SPDYLAY_SETTINGS have higher priority? */ + case NGHTTP2_SETTINGS: + /* Should NGHTTP2_SETTINGS have higher priority? */ item->pri = -1; break; - case SPDYLAY_NOOP: + case NGHTTP2_NOOP: /* We don't have any public API to add NOOP, so here is unreachable. */ assert(0); - case SPDYLAY_PING: + case NGHTTP2_PING: /* Ping has highest priority. */ - item->pri = SPDYLAY_OB_PRI_PING; + item->pri = NGHTTP2_OB_PRI_PING; break; - case SPDYLAY_GOAWAY: + case NGHTTP2_GOAWAY: /* Should GOAWAY have higher priority? */ break; - case SPDYLAY_HEADERS: { - spdylay_stream *stream = spdylay_session_get_stream + case NGHTTP2_HEADERS: { + nghttp2_stream *stream = nghttp2_session_get_stream (session, frame->headers.stream_id); if(stream) { item->pri = stream->pri; } break; } - case SPDYLAY_WINDOW_UPDATE: { - spdylay_stream *stream = spdylay_session_get_stream + case NGHTTP2_WINDOW_UPDATE: { + nghttp2_stream *stream = nghttp2_session_get_stream (session, frame->window_update.stream_id); if(stream) { item->pri = stream->pri; } break; } - case SPDYLAY_CREDENTIAL: - item->pri = SPDYLAY_OB_PRI_CREDENTIAL; + case NGHTTP2_CREDENTIAL: + item->pri = NGHTTP2_OB_PRI_CREDENTIAL; break; } - if(frame_type == SPDYLAY_SYN_STREAM) { - r = spdylay_pq_push(&session->ob_ss_pq, item); + if(frame_type == NGHTTP2_SYN_STREAM) { + r = nghttp2_pq_push(&session->ob_ss_pq, item); } else { - r = spdylay_pq_push(&session->ob_pq, item); + r = nghttp2_pq_push(&session->ob_pq, item); } - } else if(frame_cat == SPDYLAY_DATA) { - spdylay_data *data_frame = (spdylay_data*)abs_frame; - spdylay_stream *stream = spdylay_session_get_stream(session, + } else if(frame_cat == NGHTTP2_DATA) { + nghttp2_data *data_frame = (nghttp2_data*)abs_frame; + nghttp2_stream *stream = nghttp2_session_get_stream(session, data_frame->stream_id); if(stream) { item->pri = stream->pri; } - r = spdylay_pq_push(&session->ob_pq, item); + r = nghttp2_pq_push(&session->ob_pq, item); } else { /* Unreachable */ assert(0); @@ -448,47 +448,47 @@ int spdylay_session_add_frame(spdylay_session *session, return 0; } -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) { int r; - spdylay_frame *frame; - frame = malloc(sizeof(spdylay_frame)); + nghttp2_frame *frame; + frame = malloc(sizeof(nghttp2_frame)); if(frame == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - spdylay_frame_rst_stream_init(&frame->rst_stream, session->version, + nghttp2_frame_rst_stream_init(&frame->rst_stream, session->version, stream_id, status_code); - r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); + r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); if(r != 0) { - spdylay_frame_rst_stream_free(&frame->rst_stream); + nghttp2_frame_rst_stream_free(&frame->rst_stream); free(frame); return r; } return 0; } -spdylay_stream* spdylay_session_open_stream(spdylay_session *session, +nghttp2_stream* nghttp2_session_open_stream(nghttp2_session *session, int32_t stream_id, uint8_t flags, uint8_t pri, - spdylay_stream_state initial_state, + nghttp2_stream_state initial_state, void *stream_user_data) { int r; - spdylay_stream *stream = malloc(sizeof(spdylay_stream)); + nghttp2_stream *stream = malloc(sizeof(nghttp2_stream)); if(stream == NULL) { return NULL; } - spdylay_stream_init(stream, stream_id, flags, pri, initial_state, + nghttp2_stream_init(stream, stream_id, flags, pri, initial_state, session->remote_settings - [SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE], + [NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE], stream_user_data); - r = spdylay_map_insert(&session->streams, &stream->map_entry); + r = nghttp2_map_insert(&session->streams, &stream->map_entry); if(r != 0) { free(stream); stream = NULL; } - if(spdylay_session_is_my_stream_id(session, stream_id)) { + if(nghttp2_session_is_my_stream_id(session, stream_id)) { ++session->num_outgoing_streams; } else { ++session->num_incoming_streams; @@ -496,63 +496,63 @@ spdylay_stream* spdylay_session_open_stream(spdylay_session *session, return stream; } -int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id, - spdylay_status_code status_code) +int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, + nghttp2_status_code status_code) { - spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream = nghttp2_session_get_stream(session, stream_id); if(stream) { - if(stream->state != SPDYLAY_STREAM_INITIAL && + if(stream->state != NGHTTP2_STREAM_INITIAL && session->callbacks.on_stream_close_callback) { session->callbacks.on_stream_close_callback(session, stream_id, status_code, session->user_data); } - if(spdylay_session_is_my_stream_id(session, stream_id)) { + if(nghttp2_session_is_my_stream_id(session, stream_id)) { --session->num_outgoing_streams; } else { --session->num_incoming_streams; } - spdylay_map_remove(&session->streams, stream_id); - spdylay_stream_free(stream); + nghttp2_map_remove(&session->streams, stream_id); + nghttp2_stream_free(stream); free(stream); return 0; } else { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } } -int spdylay_session_close_stream_if_shut_rdwr(spdylay_session *session, - spdylay_stream *stream) +int nghttp2_session_close_stream_if_shut_rdwr(nghttp2_session *session, + nghttp2_stream *stream) { - if((stream->shut_flags & SPDYLAY_SHUT_RDWR) == SPDYLAY_SHUT_RDWR) { - return spdylay_session_close_stream(session, stream->stream_id, - SPDYLAY_OK); + if((stream->shut_flags & NGHTTP2_SHUT_RDWR) == NGHTTP2_SHUT_RDWR) { + return nghttp2_session_close_stream(session, stream->stream_id, + NGHTTP2_OK); } else { return 0; } } -void spdylay_session_close_pushed_streams(spdylay_session *session, +void nghttp2_session_close_pushed_streams(nghttp2_session *session, int32_t stream_id, - spdylay_status_code status_code) + nghttp2_status_code status_code) { - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); if(stream) { size_t i; for(i = 0; i < stream->pushed_streams_length; ++i) { - spdylay_session_close_stream(session, stream->pushed_streams[i], + nghttp2_session_close_stream(session, stream->pushed_streams[i], status_code); } } } -static int spdylay_predicate_stream_for_send(spdylay_stream *stream) +static int nghttp2_predicate_stream_for_send(nghttp2_stream *stream) { if(stream == NULL) { - return SPDYLAY_ERR_STREAM_CLOSED; - } else if(stream->shut_flags & SPDYLAY_SHUT_WR) { - return SPDYLAY_ERR_STREAM_SHUT_WR; + return NGHTTP2_ERR_STREAM_CLOSED; + } else if(stream->shut_flags & NGHTTP2_SHUT_WR) { + return NGHTTP2_ERR_STREAM_SHUT_WR; } else { return 0; } @@ -565,32 +565,32 @@ static int spdylay_predicate_stream_for_send(spdylay_stream *stream) * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_STREAM_CLOSED + * NGHTTP2_ERR_STREAM_CLOSED * The Associated-To-Stream is already closed or does not exist. - * SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE + * NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE * Stream ID has reached the maximum value. Therefore no stream ID * is available. */ -static int spdylay_session_predicate_syn_stream_send -(spdylay_session *session, - spdylay_syn_stream *frame) +static int nghttp2_session_predicate_syn_stream_send +(nghttp2_session *session, + nghttp2_syn_stream *frame) { if(session->goaway_flags) { /* When GOAWAY is sent or received, peer must not send new SYN_STREAM. */ - return SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED; + return NGHTTP2_ERR_SYN_STREAM_NOT_ALLOWED; } /* All 32bit signed stream IDs are spent. */ if(session->next_stream_id > INT32_MAX) { - return SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE; + return NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE; } if(frame->assoc_stream_id != 0) { /* Check associated stream is active. */ /* We assume here that if frame->assoc_stream_id != 0, session->server is always 1. */ - if(spdylay_session_get_stream(session, frame->assoc_stream_id) == + if(nghttp2_session_get_stream(session, frame->assoc_stream_id) == NULL) { - return SPDYLAY_ERR_STREAM_CLOSED; + return NGHTTP2_ERR_STREAM_CLOSED; } } return 0; @@ -603,37 +603,37 @@ static int spdylay_session_predicate_syn_stream_send * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_STREAM_CLOSED + * NGHTTP2_ERR_STREAM_CLOSED * The stream is already closed or does not exist. - * SPDYLAY_ERR_STREAM_SHUT_WR + * NGHTTP2_ERR_STREAM_SHUT_WR * The transmission is not allowed for this stream (e.g., a frame * with FIN flag set has already sent) - * SPDYLAY_ERR_INVALID_STREAM_ID + * NGHTTP2_ERR_INVALID_STREAM_ID * The stream ID is invalid. - * SPDYLAY_ERR_STREAM_CLOSING + * NGHTTP2_ERR_STREAM_CLOSING * RST_STREAM was queued for this stream. - * SPDYLAY_ERR_INVALID_STREAM_STATE + * NGHTTP2_ERR_INVALID_STREAM_STATE * The state of the stream is not valid (e.g., SYN_REPLY has * already sent). */ -static int spdylay_session_predicate_syn_reply_send(spdylay_session *session, +static int nghttp2_session_predicate_syn_reply_send(nghttp2_session *session, int32_t stream_id) { - spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream = nghttp2_session_get_stream(session, stream_id); int r; - r = spdylay_predicate_stream_for_send(stream); + r = nghttp2_predicate_stream_for_send(stream); if(r != 0) { return r; } - if(spdylay_session_is_my_stream_id(session, stream_id)) { - return SPDYLAY_ERR_INVALID_STREAM_ID; + if(nghttp2_session_is_my_stream_id(session, stream_id)) { + return NGHTTP2_ERR_INVALID_STREAM_ID; } else { - if(stream->state == SPDYLAY_STREAM_OPENING) { + if(stream->state == NGHTTP2_STREAM_OPENING) { return 0; - } else if(stream->state == SPDYLAY_STREAM_CLOSING) { - return SPDYLAY_ERR_STREAM_CLOSING; + } else if(stream->state == NGHTTP2_STREAM_CLOSING) { + return NGHTTP2_ERR_STREAM_CLOSING; } else { - return SPDYLAY_ERR_INVALID_STREAM_STATE; + return NGHTTP2_ERR_INVALID_STREAM_STATE; } } } @@ -645,39 +645,39 @@ static int spdylay_session_predicate_syn_reply_send(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_STREAM_CLOSED + * NGHTTP2_ERR_STREAM_CLOSED * The stream is already closed or does not exist. - * SPDYLAY_ERR_STREAM_SHUT_WR + * NGHTTP2_ERR_STREAM_SHUT_WR * The transmission is not allowed for this stream (e.g., a frame * with FIN flag set has already sent) - * SPDYLAY_ERR_STREAM_CLOSING + * NGHTTP2_ERR_STREAM_CLOSING * RST_STREAM was queued for this stream. - * SPDYLAY_ERR_INVALID_STREAM_STATE + * NGHTTP2_ERR_INVALID_STREAM_STATE * The state of the stream is not valid (e.g., if the local peer * is receiving side and SYN_REPLY has not been sent). */ -static int spdylay_session_predicate_headers_send(spdylay_session *session, +static int nghttp2_session_predicate_headers_send(nghttp2_session *session, int32_t stream_id) { - spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream = nghttp2_session_get_stream(session, stream_id); int r; - r = spdylay_predicate_stream_for_send(stream); + r = nghttp2_predicate_stream_for_send(stream); if(r != 0) { return r; } - if(spdylay_session_is_my_stream_id(session, stream_id)) { - if(stream->state != SPDYLAY_STREAM_CLOSING) { + if(nghttp2_session_is_my_stream_id(session, stream_id)) { + if(stream->state != NGHTTP2_STREAM_CLOSING) { return 0; } else { - return SPDYLAY_ERR_STREAM_CLOSING; + return NGHTTP2_ERR_STREAM_CLOSING; } } else { - if(stream->state == SPDYLAY_STREAM_OPENED) { + if(stream->state == NGHTTP2_STREAM_OPENED) { return 0; - } else if(stream->state == SPDYLAY_STREAM_CLOSING) { - return SPDYLAY_ERR_STREAM_CLOSING; + } else if(stream->state == NGHTTP2_STREAM_CLOSING) { + return NGHTTP2_ERR_STREAM_CLOSING; } else { - return SPDYLAY_ERR_INVALID_STREAM_STATE; + return NGHTTP2_ERR_INVALID_STREAM_STATE; } } } @@ -690,23 +690,23 @@ static int spdylay_session_predicate_headers_send(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_STREAM_CLOSED + * NGHTTP2_ERR_STREAM_CLOSED * The stream is already closed or does not exist. - * SPDYLAY_ERR_STREAM_CLOSING + * NGHTTP2_ERR_STREAM_CLOSING * RST_STREAM was queued for this stream. */ -static int spdylay_session_predicate_window_update_send -(spdylay_session *session, +static int nghttp2_session_predicate_window_update_send +(nghttp2_session *session, int32_t stream_id) { - spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream = nghttp2_session_get_stream(session, stream_id); if(stream == NULL) { - return SPDYLAY_ERR_STREAM_CLOSED; + return NGHTTP2_ERR_STREAM_CLOSED; } - if(stream->state != SPDYLAY_STREAM_CLOSING) { + if(stream->state != NGHTTP2_STREAM_CLOSING) { return 0; } else { - return SPDYLAY_ERR_STREAM_CLOSING; + return NGHTTP2_ERR_STREAM_CLOSING; } } @@ -715,14 +715,14 @@ static int spdylay_session_predicate_window_update_send * is enabled, the return value takes into account the current window * size. */ -static size_t spdylay_session_next_data_read(spdylay_session *session, - spdylay_stream *stream) +static size_t nghttp2_session_next_data_read(nghttp2_session *session, + nghttp2_stream *stream) { if(session->flow_control == 0) { - return SPDYLAY_DATA_PAYLOAD_LENGTH; + return NGHTTP2_DATA_PAYLOAD_LENGTH; } else if(stream->window_size > 0) { - return stream->window_size < SPDYLAY_DATA_PAYLOAD_LENGTH ? - stream->window_size : SPDYLAY_DATA_PAYLOAD_LENGTH; + return stream->window_size < NGHTTP2_DATA_PAYLOAD_LENGTH ? + stream->window_size : NGHTTP2_DATA_PAYLOAD_LENGTH; } else { return 0; } @@ -735,25 +735,25 @@ static size_t spdylay_session_next_data_read(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_STREAM_CLOSED + * NGHTTP2_ERR_STREAM_CLOSED * The stream is already closed or does not exist. - * SPDYLAY_ERR_STREAM_SHUT_WR + * NGHTTP2_ERR_STREAM_SHUT_WR * The transmission is not allowed for this stream (e.g., a frame * with FIN flag set has already sent) - * SPDYLAY_ERR_DEFERRED_DATA_EXIST + * NGHTTP2_ERR_DEFERRED_DATA_EXIST * Another DATA frame has already been deferred. - * SPDYLAY_ERR_STREAM_CLOSING + * NGHTTP2_ERR_STREAM_CLOSING * RST_STREAM was queued for this stream. - * SPDYLAY_ERR_INVALID_STREAM_STATE + * NGHTTP2_ERR_INVALID_STREAM_STATE * The state of the stream is not valid (e.g., if the local peer * is receiving side and SYN_REPLY has not been sent). */ -static int spdylay_session_predicate_data_send(spdylay_session *session, +static int nghttp2_session_predicate_data_send(nghttp2_session *session, int32_t stream_id) { - spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream = nghttp2_session_get_stream(session, stream_id); int r; - r = spdylay_predicate_stream_for_send(stream); + r = nghttp2_predicate_stream_for_send(stream); if(r != 0) { return r; } @@ -761,10 +761,10 @@ static int spdylay_session_predicate_data_send(spdylay_session *session, /* stream->deferred_data != NULL means previously queued DATA frame has not been sent. We don't allow new DATA frame is sent in this case. */ - return SPDYLAY_ERR_DEFERRED_DATA_EXIST; + return NGHTTP2_ERR_DEFERRED_DATA_EXIST; } - if(spdylay_session_is_my_stream_id(session, stream_id)) { - /* If stream->state is SPDYLAY_STREAM_CLOSING, RST_STREAM was + if(nghttp2_session_is_my_stream_id(session, stream_id)) { + /* If stream->state is NGHTTP2_STREAM_CLOSING, RST_STREAM was queued but not yet sent. In this case, we won't send DATA frames. This is because in the current architecture, DATA and RST_STREAM in the same stream have same priority and DATA is @@ -772,18 +772,18 @@ static int spdylay_session_predicate_data_send(spdylay_session *session, frames are sent. This is not desirable situation; we want to close stream as soon as possible. To achieve this, we remove DATA frame before RST_STREAM. */ - if(stream->state != SPDYLAY_STREAM_CLOSING) { + if(stream->state != NGHTTP2_STREAM_CLOSING) { return 0; } else { - return SPDYLAY_ERR_STREAM_CLOSING; + return NGHTTP2_ERR_STREAM_CLOSING; } } else { - if(stream->state == SPDYLAY_STREAM_OPENED) { + if(stream->state == NGHTTP2_STREAM_OPENED) { return 0; - } else if(stream->state == SPDYLAY_STREAM_CLOSING) { - return SPDYLAY_ERR_STREAM_CLOSING; + } else if(stream->state == NGHTTP2_STREAM_CLOSING) { + return NGHTTP2_ERR_STREAM_CLOSING; } else { - return SPDYLAY_ERR_INVALID_STREAM_STATE; + return NGHTTP2_ERR_INVALID_STREAM_STATE; } } } @@ -795,12 +795,12 @@ static int spdylay_session_predicate_data_send(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -static int spdylay_session_get_credential_proof(spdylay_session *session, - const spdylay_origin *origin, - spdylay_mem_chunk *proof) +static int nghttp2_session_get_credential_proof(nghttp2_session *session, + const nghttp2_origin *origin, + nghttp2_mem_chunk *proof) { proof->length = session->callbacks.get_credential_proof(session, origin, @@ -808,7 +808,7 @@ static int spdylay_session_get_credential_proof(spdylay_session *session, session->user_data); proof->data = malloc(proof->length); if(proof->data == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } session->callbacks.get_credential_proof(session, origin, proof->data, proof->length, @@ -825,19 +825,19 @@ static int spdylay_session_get_credential_proof(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -static int spdylay_session_get_credential_cert(spdylay_session *session, - const spdylay_origin *origin, - spdylay_mem_chunk **certs_ptr, +static int nghttp2_session_get_credential_cert(nghttp2_session *session, + const nghttp2_origin *origin, + nghttp2_mem_chunk **certs_ptr, size_t ncerts) { - spdylay_mem_chunk *certs; + nghttp2_mem_chunk *certs; size_t i, j; - certs = malloc(sizeof(spdylay_mem_chunk)*ncerts); + certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts); if(certs == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } for(i = 0; i < ncerts; ++i) { certs[i].length = session->callbacks.get_credential_cert @@ -860,61 +860,61 @@ static int spdylay_session_get_credential_cert(spdylay_session *session, free(certs[j].data); } free(certs); - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } -int spdylay_session_prep_credential(spdylay_session *session, - spdylay_syn_stream *syn_stream) +int nghttp2_session_prep_credential(nghttp2_session *session, + nghttp2_syn_stream *syn_stream) { int rv; - spdylay_origin origin; - spdylay_frame *frame; - spdylay_mem_chunk proof; + nghttp2_origin origin; + nghttp2_frame *frame; + nghttp2_mem_chunk proof; if(session->cli_certvec.size == 0) { return 0; } - rv = spdylay_frame_nv_set_origin(syn_stream->nv, &origin); + rv = nghttp2_frame_nv_set_origin(syn_stream->nv, &origin); if(rv == 0) { size_t slot; - slot = spdylay_client_cert_vector_find(&session->cli_certvec, &origin); + slot = nghttp2_client_cert_vector_find(&session->cli_certvec, &origin); if(slot == 0) { ssize_t ncerts; ncerts = session->callbacks.get_credential_ncerts(session, &origin, session->user_data); if(ncerts > 0) { - spdylay_mem_chunk *certs; - spdylay_origin *origin_copy; - frame = malloc(sizeof(spdylay_frame)); + nghttp2_mem_chunk *certs; + nghttp2_origin *origin_copy; + frame = malloc(sizeof(nghttp2_frame)); if(frame == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - origin_copy = malloc(sizeof(spdylay_origin)); + origin_copy = malloc(sizeof(nghttp2_origin)); if(origin_copy == NULL) { goto fail_after_frame; } *origin_copy = origin; - slot = spdylay_client_cert_vector_put(&session->cli_certvec, + slot = nghttp2_client_cert_vector_put(&session->cli_certvec, origin_copy); - rv = spdylay_session_get_credential_proof(session, &origin, &proof); + rv = nghttp2_session_get_credential_proof(session, &origin, &proof); if(rv != 0) { goto fail_after_frame; } - rv = spdylay_session_get_credential_cert(session, &origin, + rv = nghttp2_session_get_credential_cert(session, &origin, &certs, ncerts); if(rv != 0) { goto fail_after_proof; } - spdylay_frame_credential_init(&frame->credential, + nghttp2_frame_credential_init(&frame->credential, session->version, slot, &proof, certs, ncerts); - rv = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); + rv = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); if(rv != 0) { - spdylay_frame_credential_free(&frame->credential); + nghttp2_frame_credential_free(&frame->credential); free(frame); return rv; } - return SPDYLAY_ERR_CREDENTIAL_PENDING; + return NGHTTP2_ERR_CREDENTIAL_PENDING; } } else { return slot; @@ -929,40 +929,40 @@ int spdylay_session_prep_credential(spdylay_session *session, } -static ssize_t spdylay_session_prep_frame(spdylay_session *session, - spdylay_outbound_item *item) +static ssize_t nghttp2_session_prep_frame(nghttp2_session *session, + nghttp2_outbound_item *item) { ssize_t framebuflen = 0; - if(item->frame_cat == SPDYLAY_CTRL) { - spdylay_frame *frame; - spdylay_frame_type frame_type; - frame = spdylay_outbound_item_get_ctrl_frame(item); - frame_type = spdylay_outbound_item_get_ctrl_frame_type(item); + if(item->frame_cat == NGHTTP2_CTRL) { + nghttp2_frame *frame; + nghttp2_frame_type frame_type; + frame = nghttp2_outbound_item_get_ctrl_frame(item); + frame_type = nghttp2_outbound_item_get_ctrl_frame_type(item); switch(frame_type) { - case SPDYLAY_SYN_STREAM: { + case NGHTTP2_SYN_STREAM: { int32_t stream_id; - spdylay_syn_stream_aux_data *aux_data; + nghttp2_syn_stream_aux_data *aux_data; int r; - r = spdylay_session_predicate_syn_stream_send(session, + r = nghttp2_session_predicate_syn_stream_send(session, &frame->syn_stream); if(r != 0) { return r; } - if(session->version == SPDYLAY_PROTO_SPDY3 && + if(session->version == NGHTTP2_PROTO_SPDY3 && session->callbacks.get_credential_proof && session->callbacks.get_credential_cert && !session->server) { int slot_index; - slot_index = spdylay_session_prep_credential(session, + slot_index = nghttp2_session_prep_credential(session, &frame->syn_stream); - if(slot_index == SPDYLAY_ERR_CREDENTIAL_PENDING) { + if(slot_index == NGHTTP2_ERR_CREDENTIAL_PENDING) { /* CREDENTIAL frame has been queued. SYN_STREAM has to be sent after that. Change the priority of this item to achieve this. */ - item->pri = SPDYLAY_OB_PRI_AFTER_CREDENTIAL; - r = spdylay_pq_push(&session->ob_ss_pq, item); + item->pri = NGHTTP2_OB_PRI_AFTER_CREDENTIAL; + r = nghttp2_pq_push(&session->ob_ss_pq, item); if(r == 0) { - return SPDYLAY_ERR_CREDENTIAL_PENDING; + return NGHTTP2_ERR_CREDENTIAL_PENDING; } else { return r; } @@ -972,121 +972,121 @@ static ssize_t spdylay_session_prep_frame(spdylay_session *session, stream_id = session->next_stream_id; frame->syn_stream.stream_id = stream_id; session->next_stream_id += 2; - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_3to2(frame->syn_stream.nv); - spdylay_frame_nv_sort(frame->syn_stream.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_3to2(frame->syn_stream.nv); + nghttp2_frame_nv_sort(frame->syn_stream.nv); } - framebuflen = spdylay_frame_pack_syn_stream(&session->aob.framebuf, + framebuflen = nghttp2_frame_pack_syn_stream(&session->aob.framebuf, &session->aob.framebufmax, &session->nvbuf, &session->nvbuflen, &frame->syn_stream, &session->hd_deflater); - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_2to3(frame->syn_stream.nv); - spdylay_frame_nv_sort(frame->syn_stream.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_2to3(frame->syn_stream.nv); + nghttp2_frame_nv_sort(frame->syn_stream.nv); } if(framebuflen < 0) { return framebuflen; } - aux_data = (spdylay_syn_stream_aux_data*)item->aux_data; - if(spdylay_session_open_stream(session, stream_id, + aux_data = (nghttp2_syn_stream_aux_data*)item->aux_data; + if(nghttp2_session_open_stream(session, stream_id, frame->syn_stream.hd.flags, frame->syn_stream.pri, - SPDYLAY_STREAM_INITIAL, + NGHTTP2_STREAM_INITIAL, aux_data->stream_user_data) == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } break; } - case SPDYLAY_SYN_REPLY: { + case NGHTTP2_SYN_REPLY: { int r; - r = spdylay_session_predicate_syn_reply_send(session, + r = nghttp2_session_predicate_syn_reply_send(session, frame->syn_reply.stream_id); if(r != 0) { return r; } - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_3to2(frame->syn_reply.nv); - spdylay_frame_nv_sort(frame->syn_reply.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_3to2(frame->syn_reply.nv); + nghttp2_frame_nv_sort(frame->syn_reply.nv); } - framebuflen = spdylay_frame_pack_syn_reply(&session->aob.framebuf, + framebuflen = nghttp2_frame_pack_syn_reply(&session->aob.framebuf, &session->aob.framebufmax, &session->nvbuf, &session->nvbuflen, &frame->syn_reply, &session->hd_deflater); - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_2to3(frame->syn_reply.nv); - spdylay_frame_nv_sort(frame->syn_reply.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_2to3(frame->syn_reply.nv); + nghttp2_frame_nv_sort(frame->syn_reply.nv); } if(framebuflen < 0) { return framebuflen; } break; } - case SPDYLAY_RST_STREAM: - framebuflen = spdylay_frame_pack_rst_stream(&session->aob.framebuf, + case NGHTTP2_RST_STREAM: + framebuflen = nghttp2_frame_pack_rst_stream(&session->aob.framebuf, &session->aob.framebufmax, &frame->rst_stream); if(framebuflen < 0) { return framebuflen; } break; - case SPDYLAY_SETTINGS: - framebuflen = spdylay_frame_pack_settings(&session->aob.framebuf, + case NGHTTP2_SETTINGS: + framebuflen = nghttp2_frame_pack_settings(&session->aob.framebuf, &session->aob.framebufmax, &frame->settings); if(framebuflen < 0) { return framebuflen; } break; - case SPDYLAY_NOOP: + case NGHTTP2_NOOP: /* We don't have any public API to add NOOP, so here is unreachable. */ assert(0); - case SPDYLAY_PING: - framebuflen = spdylay_frame_pack_ping(&session->aob.framebuf, + case NGHTTP2_PING: + framebuflen = nghttp2_frame_pack_ping(&session->aob.framebuf, &session->aob.framebufmax, &frame->ping); if(framebuflen < 0) { return framebuflen; } break; - case SPDYLAY_HEADERS: { + case NGHTTP2_HEADERS: { int r; - r = spdylay_session_predicate_headers_send(session, + r = nghttp2_session_predicate_headers_send(session, frame->headers.stream_id); if(r != 0) { return r; } - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_3to2(frame->headers.nv); - spdylay_frame_nv_sort(frame->headers.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_3to2(frame->headers.nv); + nghttp2_frame_nv_sort(frame->headers.nv); } - framebuflen = spdylay_frame_pack_headers(&session->aob.framebuf, + framebuflen = nghttp2_frame_pack_headers(&session->aob.framebuf, &session->aob.framebufmax, &session->nvbuf, &session->nvbuflen, &frame->headers, &session->hd_deflater); - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_2to3(frame->headers.nv); - spdylay_frame_nv_sort(frame->headers.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_2to3(frame->headers.nv); + nghttp2_frame_nv_sort(frame->headers.nv); } if(framebuflen < 0) { return framebuflen; } break; } - case SPDYLAY_WINDOW_UPDATE: { + case NGHTTP2_WINDOW_UPDATE: { int r; - r = spdylay_session_predicate_window_update_send + r = nghttp2_session_predicate_window_update_send (session, frame->window_update.stream_id); if(r != 0) { return r; } - framebuflen = spdylay_frame_pack_window_update(&session->aob.framebuf, + framebuflen = nghttp2_frame_pack_window_update(&session->aob.framebuf, &session->aob.framebufmax, &frame->window_update); if(framebuflen < 0) { @@ -1094,23 +1094,23 @@ static ssize_t spdylay_session_prep_frame(spdylay_session *session, } break; } - case SPDYLAY_GOAWAY: - if(session->goaway_flags & SPDYLAY_GOAWAY_SEND) { + case NGHTTP2_GOAWAY: + if(session->goaway_flags & NGHTTP2_GOAWAY_SEND) { /* TODO The spec does not mandate that both endpoints have to exchange GOAWAY. This implementation allows receiver of first GOAWAY can sent its own GOAWAY to tell the remote peer that last-good-stream-id. */ - return SPDYLAY_ERR_GOAWAY_ALREADY_SENT; + return NGHTTP2_ERR_GOAWAY_ALREADY_SENT; } - framebuflen = spdylay_frame_pack_goaway(&session->aob.framebuf, + framebuflen = nghttp2_frame_pack_goaway(&session->aob.framebuf, &session->aob.framebufmax, &frame->goaway); if(framebuflen < 0) { return framebuflen; } break; - case SPDYLAY_CREDENTIAL: { - framebuflen = spdylay_frame_pack_credential(&session->aob.framebuf, + case NGHTTP2_CREDENTIAL: { + framebuflen = nghttp2_frame_pack_credential(&session->aob.framebuf, &session->aob.framebufmax, &frame->credential); if(framebuflen < 0) { @@ -1119,37 +1119,37 @@ static ssize_t spdylay_session_prep_frame(spdylay_session *session, break; } default: - framebuflen = SPDYLAY_ERR_INVALID_ARGUMENT; + framebuflen = NGHTTP2_ERR_INVALID_ARGUMENT; } - } else if(item->frame_cat == SPDYLAY_DATA) { + } else if(item->frame_cat == NGHTTP2_DATA) { size_t next_readmax; - spdylay_stream *stream; - spdylay_data *data_frame; + nghttp2_stream *stream; + nghttp2_data *data_frame; int r; - data_frame = spdylay_outbound_item_get_data_frame(item); - r = spdylay_session_predicate_data_send(session, data_frame->stream_id); + data_frame = nghttp2_outbound_item_get_data_frame(item); + r = nghttp2_session_predicate_data_send(session, data_frame->stream_id); if(r != 0) { return r; } - stream = spdylay_session_get_stream(session, data_frame->stream_id); + stream = nghttp2_session_get_stream(session, data_frame->stream_id); /* Assuming stream is not NULL */ assert(stream); - next_readmax = spdylay_session_next_data_read(session, stream); + next_readmax = nghttp2_session_next_data_read(session, stream); if(next_readmax == 0) { - spdylay_stream_defer_data(stream, item, SPDYLAY_DEFERRED_FLOW_CONTROL); - return SPDYLAY_ERR_DEFERRED; + nghttp2_stream_defer_data(stream, item, NGHTTP2_DEFERRED_FLOW_CONTROL); + return NGHTTP2_ERR_DEFERRED; } - framebuflen = spdylay_session_pack_data(session, + framebuflen = nghttp2_session_pack_data(session, &session->aob.framebuf, &session->aob.framebufmax, next_readmax, data_frame); - if(framebuflen == SPDYLAY_ERR_DEFERRED) { - spdylay_stream_defer_data(stream, item, SPDYLAY_DEFERRED_NONE); - return SPDYLAY_ERR_DEFERRED; - } else if(framebuflen == SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE) { - r = spdylay_session_add_rst_stream(session, data_frame->stream_id, - SPDYLAY_INTERNAL_ERROR); + if(framebuflen == NGHTTP2_ERR_DEFERRED) { + nghttp2_stream_defer_data(stream, item, NGHTTP2_DEFERRED_NONE); + return NGHTTP2_ERR_DEFERRED; + } else if(framebuflen == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { + r = nghttp2_session_add_rst_stream(session, data_frame->stream_id, + NGHTTP2_INTERNAL_ERROR); if(r == 0) { return framebuflen; } else { @@ -1165,35 +1165,35 @@ static ssize_t spdylay_session_prep_frame(spdylay_session *session, return framebuflen; } -spdylay_outbound_item* spdylay_session_get_ob_pq_top -(spdylay_session *session) +nghttp2_outbound_item* nghttp2_session_get_ob_pq_top +(nghttp2_session *session) { - return (spdylay_outbound_item*)spdylay_pq_top(&session->ob_pq); + return (nghttp2_outbound_item*)nghttp2_pq_top(&session->ob_pq); } -spdylay_outbound_item* spdylay_session_get_next_ob_item -(spdylay_session *session) +nghttp2_outbound_item* nghttp2_session_get_next_ob_item +(nghttp2_session *session) { - if(spdylay_pq_empty(&session->ob_pq)) { - if(spdylay_pq_empty(&session->ob_ss_pq)) { + if(nghttp2_pq_empty(&session->ob_pq)) { + if(nghttp2_pq_empty(&session->ob_ss_pq)) { return NULL; } else { /* Return item only when concurrent connection limit is not reached */ - if(spdylay_session_is_outgoing_concurrent_streams_max(session)) { + if(nghttp2_session_is_outgoing_concurrent_streams_max(session)) { return NULL; } else { - return spdylay_pq_top(&session->ob_ss_pq); + return nghttp2_pq_top(&session->ob_ss_pq); } } } else { - if(spdylay_pq_empty(&session->ob_ss_pq)) { - return spdylay_pq_top(&session->ob_pq); + if(nghttp2_pq_empty(&session->ob_ss_pq)) { + return nghttp2_pq_top(&session->ob_pq); } else { - spdylay_outbound_item *item, *syn_stream_item; - item = spdylay_pq_top(&session->ob_pq); - syn_stream_item = spdylay_pq_top(&session->ob_ss_pq); - if(spdylay_session_is_outgoing_concurrent_streams_max(session) || + nghttp2_outbound_item *item, *syn_stream_item; + item = nghttp2_pq_top(&session->ob_pq); + syn_stream_item = nghttp2_pq_top(&session->ob_ss_pq); + if(nghttp2_session_is_outgoing_concurrent_streams_max(session) || item->pri < syn_stream_item->pri || (item->pri == syn_stream_item->pri && item->seq < syn_stream_item->seq)) { @@ -1205,42 +1205,42 @@ spdylay_outbound_item* spdylay_session_get_next_ob_item } } -spdylay_outbound_item* spdylay_session_pop_next_ob_item -(spdylay_session *session) +nghttp2_outbound_item* nghttp2_session_pop_next_ob_item +(nghttp2_session *session) { - if(spdylay_pq_empty(&session->ob_pq)) { - if(spdylay_pq_empty(&session->ob_ss_pq)) { + if(nghttp2_pq_empty(&session->ob_pq)) { + if(nghttp2_pq_empty(&session->ob_ss_pq)) { return NULL; } else { /* Pop item only when concurrent connection limit is not reached */ - if(spdylay_session_is_outgoing_concurrent_streams_max(session)) { + if(nghttp2_session_is_outgoing_concurrent_streams_max(session)) { return NULL; } else { - spdylay_outbound_item *item; - item = spdylay_pq_top(&session->ob_ss_pq); - spdylay_pq_pop(&session->ob_ss_pq); + nghttp2_outbound_item *item; + item = nghttp2_pq_top(&session->ob_ss_pq); + nghttp2_pq_pop(&session->ob_ss_pq); return item; } } } else { - if(spdylay_pq_empty(&session->ob_ss_pq)) { - spdylay_outbound_item *item; - item = spdylay_pq_top(&session->ob_pq); - spdylay_pq_pop(&session->ob_pq); + if(nghttp2_pq_empty(&session->ob_ss_pq)) { + nghttp2_outbound_item *item; + item = nghttp2_pq_top(&session->ob_pq); + nghttp2_pq_pop(&session->ob_pq); return item; } else { - spdylay_outbound_item *item, *syn_stream_item; - item = spdylay_pq_top(&session->ob_pq); - syn_stream_item = spdylay_pq_top(&session->ob_ss_pq); - if(spdylay_session_is_outgoing_concurrent_streams_max(session) || + nghttp2_outbound_item *item, *syn_stream_item; + item = nghttp2_pq_top(&session->ob_pq); + syn_stream_item = nghttp2_pq_top(&session->ob_ss_pq); + if(nghttp2_session_is_outgoing_concurrent_streams_max(session) || item->pri < syn_stream_item->pri || (item->pri == syn_stream_item->pri && item->seq < syn_stream_item->seq)) { - spdylay_pq_pop(&session->ob_pq); + nghttp2_pq_pop(&session->ob_pq); return item; } else { - spdylay_pq_pop(&session->ob_ss_pq); + nghttp2_pq_pop(&session->ob_ss_pq); return syn_stream_item; } } @@ -1251,10 +1251,10 @@ spdylay_outbound_item* spdylay_session_pop_next_ob_item * Adjust priority of item so that the higher priority long DATA * frames don't starve lower priority streams. */ -static void spdylay_outbound_item_adjust_pri(spdylay_session *session, - spdylay_outbound_item *item) +static void nghttp2_outbound_item_adjust_pri(nghttp2_session *session, + nghttp2_outbound_item *item) { - if(item->pri > spdylay_session_get_pri_lowest(session)) { + if(item->pri > nghttp2_session_get_pri_lowest(session)) { item->pri = item->inipri; } else { ++item->pri; @@ -1267,48 +1267,48 @@ static void spdylay_outbound_item_adjust_pri(spdylay_session *session, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. - * SPDYLAY_ERR_CALLBACK_FAILURE + * NGHTTP2_ERR_CALLBACK_FAILURE * The callback function failed. */ -static int spdylay_session_after_frame_sent(spdylay_session *session) +static int nghttp2_session_after_frame_sent(nghttp2_session *session) { /* TODO handle FIN flag. */ - spdylay_outbound_item *item = session->aob.item; - if(item->frame_cat == SPDYLAY_CTRL) { - spdylay_frame *frame; - spdylay_frame_type type; - frame = spdylay_outbound_item_get_ctrl_frame(session->aob.item); - type = spdylay_outbound_item_get_ctrl_frame_type(session->aob.item); + nghttp2_outbound_item *item = session->aob.item; + if(item->frame_cat == NGHTTP2_CTRL) { + nghttp2_frame *frame; + nghttp2_frame_type type; + frame = nghttp2_outbound_item_get_ctrl_frame(session->aob.item); + type = nghttp2_outbound_item_get_ctrl_frame_type(session->aob.item); if(session->callbacks.on_ctrl_send_callback) { session->callbacks.on_ctrl_send_callback (session, type, frame, session->user_data); } switch(type) { - case SPDYLAY_SYN_STREAM: { - spdylay_stream *stream = - spdylay_session_get_stream(session, frame->syn_stream.stream_id); + case NGHTTP2_SYN_STREAM: { + nghttp2_stream *stream = + nghttp2_session_get_stream(session, frame->syn_stream.stream_id); if(stream) { - spdylay_syn_stream_aux_data *aux_data; - stream->state = SPDYLAY_STREAM_OPENING; - if(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR); + nghttp2_syn_stream_aux_data *aux_data; + stream->state = NGHTTP2_STREAM_OPENING; + if(frame->syn_stream.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); } - if(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); + if(frame->syn_stream.hd.flags & NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); } - spdylay_session_close_stream_if_shut_rdwr(session, stream); - /* We assume aux_data is a pointer to spdylay_syn_stream_aux_data */ - aux_data = (spdylay_syn_stream_aux_data*)item->aux_data; + nghttp2_session_close_stream_if_shut_rdwr(session, stream); + /* We assume aux_data is a pointer to nghttp2_syn_stream_aux_data */ + aux_data = (nghttp2_syn_stream_aux_data*)item->aux_data; if(aux_data->data_prd) { int r; - /* spdylay_submit_data() makes a copy of aux_data->data_prd */ - r = spdylay_submit_data(session, frame->syn_stream.stream_id, - SPDYLAY_DATA_FLAG_FIN, aux_data->data_prd); + /* nghttp2_submit_data() makes a copy of aux_data->data_prd */ + r = nghttp2_submit_data(session, frame->syn_stream.stream_id, + NGHTTP2_DATA_FLAG_FIN, aux_data->data_prd); if(r != 0) { /* FATAL error */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); /* TODO If r is not FATAL, we should send RST_STREAM. */ return r; } @@ -1316,25 +1316,25 @@ static int spdylay_session_after_frame_sent(spdylay_session *session) } break; } - case SPDYLAY_SYN_REPLY: { - spdylay_stream *stream = - spdylay_session_get_stream(session, frame->syn_reply.stream_id); + case NGHTTP2_SYN_REPLY: { + nghttp2_stream *stream = + nghttp2_session_get_stream(session, frame->syn_reply.stream_id); if(stream) { - stream->state = SPDYLAY_STREAM_OPENED; - if(frame->syn_reply.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR); + stream->state = NGHTTP2_STREAM_OPENED; + if(frame->syn_reply.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); } - spdylay_session_close_stream_if_shut_rdwr(session, stream); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); if(item->aux_data) { - /* We assume aux_data is a pointer to spdylay_data_provider */ - spdylay_data_provider *data_prd = - (spdylay_data_provider*)item->aux_data; + /* We assume aux_data is a pointer to nghttp2_data_provider */ + nghttp2_data_provider *data_prd = + (nghttp2_data_provider*)item->aux_data; int r; - r = spdylay_submit_data(session, frame->syn_reply.stream_id, - SPDYLAY_DATA_FLAG_FIN, data_prd); + r = nghttp2_submit_data(session, frame->syn_reply.stream_id, + NGHTTP2_DATA_FLAG_FIN, data_prd); if(r != 0) { /* FATAL error */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); /* TODO If r is not FATAL, we should send RST_STREAM. */ return r; } @@ -1342,135 +1342,135 @@ static int spdylay_session_after_frame_sent(spdylay_session *session) } break; } - case SPDYLAY_RST_STREAM: + case NGHTTP2_RST_STREAM: if(!session->server && - spdylay_session_is_my_stream_id(session, + nghttp2_session_is_my_stream_id(session, frame->rst_stream.stream_id) && - frame->rst_stream.status_code == SPDYLAY_CANCEL) { - spdylay_session_close_pushed_streams(session, + frame->rst_stream.status_code == NGHTTP2_CANCEL) { + nghttp2_session_close_pushed_streams(session, frame->rst_stream.stream_id, frame->rst_stream.status_code); } - spdylay_session_close_stream(session, frame->rst_stream.stream_id, + nghttp2_session_close_stream(session, frame->rst_stream.stream_id, frame->rst_stream.status_code); break; - case SPDYLAY_SETTINGS: + case NGHTTP2_SETTINGS: /* nothing to do */ break; - case SPDYLAY_NOOP: + case NGHTTP2_NOOP: /* We don't have any public API to add NOOP, so here is unreachable. */ assert(0); - case SPDYLAY_PING: + case NGHTTP2_PING: /* We record the time now and show application code RTT when reply PING is received. */ session->last_ping_unique_id = frame->ping.unique_id; break; - case SPDYLAY_GOAWAY: - session->goaway_flags |= SPDYLAY_GOAWAY_SEND; + case NGHTTP2_GOAWAY: + session->goaway_flags |= NGHTTP2_GOAWAY_SEND; break; - case SPDYLAY_HEADERS: { - spdylay_stream *stream = - spdylay_session_get_stream(session, frame->headers.stream_id); + case NGHTTP2_HEADERS: { + nghttp2_stream *stream = + nghttp2_session_get_stream(session, frame->headers.stream_id); if(stream) { - if(frame->headers.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR); + if(frame->headers.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); } - spdylay_session_close_stream_if_shut_rdwr(session, stream); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); } break; } - case SPDYLAY_WINDOW_UPDATE: + case NGHTTP2_WINDOW_UPDATE: break; - case SPDYLAY_CREDENTIAL: + case NGHTTP2_CREDENTIAL: break; } - spdylay_active_outbound_item_reset(&session->aob); - } else if(item->frame_cat == SPDYLAY_DATA) { + nghttp2_active_outbound_item_reset(&session->aob); + } else if(item->frame_cat == NGHTTP2_DATA) { int r; - spdylay_data *data_frame; - data_frame = spdylay_outbound_item_get_data_frame(session->aob.item); + nghttp2_data *data_frame; + data_frame = nghttp2_outbound_item_get_data_frame(session->aob.item); if(session->callbacks.on_data_send_callback) { session->callbacks.on_data_send_callback (session, data_frame->eof ? data_frame->flags : - (data_frame->flags & (~SPDYLAY_DATA_FLAG_FIN)), + (data_frame->flags & (~NGHTTP2_DATA_FLAG_FIN)), data_frame->stream_id, - session->aob.framebuflen-SPDYLAY_HEAD_LEN, session->user_data); + session->aob.framebuflen-NGHTTP2_HEAD_LEN, session->user_data); } - if(data_frame->eof && (data_frame->flags & SPDYLAY_DATA_FLAG_FIN)) { - spdylay_stream *stream = - spdylay_session_get_stream(session, data_frame->stream_id); + if(data_frame->eof && (data_frame->flags & NGHTTP2_DATA_FLAG_FIN)) { + nghttp2_stream *stream = + nghttp2_session_get_stream(session, data_frame->stream_id); if(stream) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR); - spdylay_session_close_stream_if_shut_rdwr(session, stream); + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); } } /* If session is closed or RST_STREAM was queued, we won't send further data. */ if(data_frame->eof || - spdylay_session_predicate_data_send(session, + nghttp2_session_predicate_data_send(session, data_frame->stream_id) != 0) { - spdylay_active_outbound_item_reset(&session->aob); + nghttp2_active_outbound_item_reset(&session->aob); } else { - spdylay_outbound_item* next_item; - next_item = spdylay_session_get_next_ob_item(session); - spdylay_outbound_item_adjust_pri(session, session->aob.item); + nghttp2_outbound_item* next_item; + next_item = nghttp2_session_get_next_ob_item(session); + nghttp2_outbound_item_adjust_pri(session, session->aob.item); /* If priority of this stream is higher or equal to other stream waiting at the top of the queue, we continue to send this data. */ if(next_item == NULL || session->aob.item->pri <= next_item->pri) { size_t next_readmax; - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, data_frame->stream_id); + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, data_frame->stream_id); /* Assuming stream is not NULL */ assert(stream); - next_readmax = spdylay_session_next_data_read(session, stream); + next_readmax = nghttp2_session_next_data_read(session, stream); if(next_readmax == 0) { - spdylay_stream_defer_data(stream, session->aob.item, - SPDYLAY_DEFERRED_FLOW_CONTROL); + nghttp2_stream_defer_data(stream, session->aob.item, + NGHTTP2_DEFERRED_FLOW_CONTROL); session->aob.item = NULL; - spdylay_active_outbound_item_reset(&session->aob); + nghttp2_active_outbound_item_reset(&session->aob); return 0; } - r = spdylay_session_pack_data(session, + r = nghttp2_session_pack_data(session, &session->aob.framebuf, &session->aob.framebufmax, next_readmax, data_frame); - if(r == SPDYLAY_ERR_DEFERRED) { - spdylay_stream_defer_data(stream, session->aob.item, - SPDYLAY_DEFERRED_NONE); + if(r == NGHTTP2_ERR_DEFERRED) { + nghttp2_stream_defer_data(stream, session->aob.item, + NGHTTP2_DEFERRED_NONE); session->aob.item = NULL; - spdylay_active_outbound_item_reset(&session->aob); - } else if(r == SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE) { + nghttp2_active_outbound_item_reset(&session->aob); + } else if(r == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { /* Stop DATA frame chain and issue RST_STREAM to close the stream. We don't return - SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE intentionally. */ - r = spdylay_session_add_rst_stream(session, data_frame->stream_id, - SPDYLAY_INTERNAL_ERROR); - spdylay_active_outbound_item_reset(&session->aob); + NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE intentionally. */ + r = nghttp2_session_add_rst_stream(session, data_frame->stream_id, + NGHTTP2_INTERNAL_ERROR); + nghttp2_active_outbound_item_reset(&session->aob); if(r != 0) { return r; } } else if(r < 0) { - /* In this context, r is either SPDYLAY_ERR_NOMEM or - SPDYLAY_ERR_CALLBACK_FAILURE */ - spdylay_active_outbound_item_reset(&session->aob); + /* In this context, r is either NGHTTP2_ERR_NOMEM or + NGHTTP2_ERR_CALLBACK_FAILURE */ + nghttp2_active_outbound_item_reset(&session->aob); return r; } else { session->aob.framebuflen = r; session->aob.framebufoff = 0; } } else { - r = spdylay_pq_push(&session->ob_pq, session->aob.item); + r = nghttp2_pq_push(&session->ob_pq, session->aob.item); if(r == 0) { session->aob.item = NULL; - spdylay_active_outbound_item_reset(&session->aob); + nghttp2_active_outbound_item_reset(&session->aob); } else { /* FATAL error */ - assert(r < SPDYLAY_ERR_FATAL); - spdylay_active_outbound_item_reset(&session->aob); + assert(r < NGHTTP2_ERR_FATAL); + nghttp2_active_outbound_item_reset(&session->aob); return r; } } @@ -1482,7 +1482,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session) return 0; } -int spdylay_session_send(spdylay_session *session) +int nghttp2_session_send(nghttp2_session *session) { int r; while(1) { @@ -1490,37 +1490,37 @@ int spdylay_session_send(spdylay_session *session) size_t datalen; ssize_t sentlen; if(session->aob.item == NULL) { - spdylay_outbound_item *item; + nghttp2_outbound_item *item; ssize_t framebuflen; - item = spdylay_session_pop_next_ob_item(session); + item = nghttp2_session_pop_next_ob_item(session); if(item == NULL) { break; } - framebuflen = spdylay_session_prep_frame(session, item); - if(framebuflen == SPDYLAY_ERR_DEFERRED || - framebuflen == SPDYLAY_ERR_CREDENTIAL_PENDING) { + framebuflen = nghttp2_session_prep_frame(session, item); + if(framebuflen == NGHTTP2_ERR_DEFERRED || + framebuflen == NGHTTP2_ERR_CREDENTIAL_PENDING) { continue; } else if(framebuflen < 0) { - if(item->frame_cat == SPDYLAY_CTRL && + if(item->frame_cat == NGHTTP2_CTRL && session->callbacks.on_ctrl_not_send_callback && - spdylay_is_non_fatal(framebuflen)) { + nghttp2_is_non_fatal(framebuflen)) { /* The library is responsible for the transmission of WINDOW_UPDATE frame, so we don't call error callback for it. */ - spdylay_frame_type frame_type; - frame_type = spdylay_outbound_item_get_ctrl_frame_type(item); - if(frame_type != SPDYLAY_WINDOW_UPDATE) { + nghttp2_frame_type frame_type; + frame_type = nghttp2_outbound_item_get_ctrl_frame_type(item); + if(frame_type != NGHTTP2_WINDOW_UPDATE) { session->callbacks.on_ctrl_not_send_callback (session, frame_type, - spdylay_outbound_item_get_ctrl_frame(item), + nghttp2_outbound_item_get_ctrl_frame(item), framebuflen, session->user_data); } } - spdylay_outbound_item_free(item); + nghttp2_outbound_item_free(item); free(item); - if(spdylay_is_fatal(framebuflen)) { + if(nghttp2_is_fatal(framebuflen)) { return framebuflen; } else { continue; @@ -1529,12 +1529,12 @@ int spdylay_session_send(spdylay_session *session) session->aob.item = item; session->aob.framebuflen = framebuflen; /* Call before_send callback */ - if(item->frame_cat == SPDYLAY_CTRL && + if(item->frame_cat == NGHTTP2_CTRL && session->callbacks.before_ctrl_send_callback) { session->callbacks.before_ctrl_send_callback (session, - spdylay_outbound_item_get_ctrl_frame_type(item), - spdylay_outbound_item_get_ctrl_frame(item), + nghttp2_outbound_item_get_ctrl_frame_type(item), + nghttp2_outbound_item_get_ctrl_frame(item), session->user_data); } } @@ -1543,29 +1543,29 @@ int spdylay_session_send(spdylay_session *session) sentlen = session->callbacks.send_callback(session, data, datalen, 0, session->user_data); if(sentlen < 0) { - if(sentlen == SPDYLAY_ERR_WOULDBLOCK) { + if(sentlen == NGHTTP2_ERR_WOULDBLOCK) { return 0; } else { - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } } else { session->aob.framebufoff += sentlen; if(session->flow_control && - session->aob.item->frame_cat == SPDYLAY_DATA) { - spdylay_data *frame; - spdylay_stream *stream; - frame = spdylay_outbound_item_get_data_frame(session->aob.item); - stream = spdylay_session_get_stream(session, frame->stream_id); + session->aob.item->frame_cat == NGHTTP2_DATA) { + nghttp2_data *frame; + nghttp2_stream *stream; + frame = nghttp2_outbound_item_get_data_frame(session->aob.item); + stream = nghttp2_session_get_stream(session, frame->stream_id); if(stream) { - stream->window_size -= spdylay_get_uint32(&session->aob.framebuf[4]); + stream->window_size -= nghttp2_get_uint32(&session->aob.framebuf[4]); } } if(session->aob.framebufoff == session->aob.framebuflen) { /* Frame has completely sent */ - r = spdylay_session_after_frame_sent(session); + r = nghttp2_session_after_frame_sent(session); if(r < 0) { /* FATAL */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); return r; } } @@ -1574,25 +1574,25 @@ int spdylay_session_send(spdylay_session *session) return 0; } -static ssize_t spdylay_recv(spdylay_session *session, uint8_t *buf, size_t len) +static ssize_t nghttp2_recv(nghttp2_session *session, uint8_t *buf, size_t len) { ssize_t r; r = session->callbacks.recv_callback (session, buf, len, 0, session->user_data); if(r > 0) { if((size_t)r > len) { - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } } else if(r < 0) { - if(r != SPDYLAY_ERR_WOULDBLOCK && r != SPDYLAY_ERR_EOF) { - r = SPDYLAY_ERR_CALLBACK_FAILURE; + if(r != NGHTTP2_ERR_WOULDBLOCK && r != NGHTTP2_ERR_EOF) { + r = NGHTTP2_ERR_CALLBACK_FAILURE; } } return r; } -static void spdylay_session_call_on_request_recv -(spdylay_session *session, int32_t stream_id) +static void nghttp2_session_call_on_request_recv +(nghttp2_session *session, int32_t stream_id) { if(session->callbacks.on_request_recv_callback) { session->callbacks.on_request_recv_callback(session, stream_id, @@ -1600,8 +1600,8 @@ static void spdylay_session_call_on_request_recv } } -static void spdylay_session_call_on_ctrl_frame_received -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame) +static void nghttp2_session_call_on_ctrl_frame_received +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame) { if(session->callbacks.on_ctrl_recv_callback) { session->callbacks.on_ctrl_recv_callback @@ -1613,7 +1613,7 @@ static void spdylay_session_call_on_ctrl_frame_received * Checks whether received stream_id is valid. * This function returns 1 if it succeeds, or 0. */ -static int spdylay_session_is_new_peer_stream_id(spdylay_session *session, +static int nghttp2_session_is_new_peer_stream_id(nghttp2_session *session, int32_t stream_id) { if(stream_id == 0) { @@ -1629,7 +1629,7 @@ static int spdylay_session_is_new_peer_stream_id(spdylay_session *session, /* * Returns non-zero iff version == session->version */ -static int spdylay_session_check_version(spdylay_session *session, +static int nghttp2_session_check_version(nghttp2_session *session, uint16_t version) { return session->version == version; @@ -1637,52 +1637,52 @@ static int spdylay_session_check_version(spdylay_session *session, /* * Validates received SYN_STREAM frame |frame|. This function returns - * 0 if it succeeds, or non-zero spdylay_status_code. + * 0 if it succeeds, or non-zero nghttp2_status_code. */ -static int spdylay_session_validate_syn_stream(spdylay_session *session, - spdylay_syn_stream *frame) +static int nghttp2_session_validate_syn_stream(nghttp2_session *session, + nghttp2_syn_stream *frame) { - if(!spdylay_session_check_version(session, frame->hd.version)) { - return SPDYLAY_UNSUPPORTED_VERSION; + if(!nghttp2_session_check_version(session, frame->hd.version)) { + return NGHTTP2_UNSUPPORTED_VERSION; } if(session->server) { if(frame->assoc_stream_id != 0) { - return SPDYLAY_PROTOCOL_ERROR; + return NGHTTP2_PROTOCOL_ERROR; } } else { if(frame->assoc_stream_id == 0) { /* spdy/2 spec: When a client receives a SYN_STREAM from the server with an Associated-To-Stream-ID of 0, it must reply with a RST_STREAM with error code INVALID_STREAM. */ - return SPDYLAY_INVALID_STREAM; + return NGHTTP2_INVALID_STREAM; } - if((frame->hd.flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) == 0 || - spdylay_session_get_stream(session, frame->assoc_stream_id) == NULL) { + if((frame->hd.flags & NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL) == 0 || + nghttp2_session_get_stream(session, frame->assoc_stream_id) == NULL) { /* It seems spdy/2 spec does not say which status code should be returned in these cases. */ - return SPDYLAY_PROTOCOL_ERROR; + return NGHTTP2_PROTOCOL_ERROR; } } - if(spdylay_session_is_incoming_concurrent_streams_max(session)) { + if(nghttp2_session_is_incoming_concurrent_streams_max(session)) { /* spdy/2 spec does not clearly say what to do when max concurrent streams number is reached. The mod_spdy sends - SPDYLAY_REFUSED_STREAM and we think it is reasonable. So we + NGHTTP2_REFUSED_STREAM and we think it is reasonable. So we follow it. */ - return SPDYLAY_REFUSED_STREAM; + return NGHTTP2_REFUSED_STREAM; } return 0; } -static int spdylay_session_handle_invalid_stream -(spdylay_session *session, +static int nghttp2_session_handle_invalid_stream +(nghttp2_session *session, int32_t stream_id, - spdylay_frame_type type, - spdylay_frame *frame, - spdylay_status_code status_code) + nghttp2_frame_type type, + nghttp2_frame *frame, + nghttp2_status_code status_code) { int r; - r = spdylay_session_add_rst_stream(session, stream_id, status_code); + r = nghttp2_session_add_rst_stream(session, stream_id, status_code); if(r != 0) { return r; } @@ -1693,8 +1693,8 @@ static int spdylay_session_handle_invalid_stream return 0; } -int spdylay_session_on_syn_stream_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_syn_stream_received(nghttp2_session *session, + nghttp2_frame *frame) { int r = 0; int status_code; @@ -1706,8 +1706,8 @@ int spdylay_session_on_syn_stream_received(spdylay_session *session, /* SPDY/3 spec says if an endpoint receives same stream ID twice, it MUST issue a stream error with status code PROTOCOL_ERROR. */ - status_code = SPDYLAY_PROTOCOL_ERROR; - } else if(!spdylay_session_is_new_peer_stream_id + status_code = NGHTTP2_PROTOCOL_ERROR; + } else if(!nghttp2_session_is_new_peer_stream_id (session, frame->syn_stream.stream_id)) { /* SPDY/3 spec says if an endpoint receives a SYN_STREAM with a stream ID which is less than any previously received @@ -1715,156 +1715,156 @@ int spdylay_session_on_syn_stream_received(spdylay_session *session, PROTOCOL_ERROR */ if(session->callbacks.on_invalid_ctrl_recv_callback) { session->callbacks.on_invalid_ctrl_recv_callback(session, - SPDYLAY_SYN_STREAM, + NGHTTP2_SYN_STREAM, frame, - SPDYLAY_PROTOCOL_ERROR, + NGHTTP2_PROTOCOL_ERROR, session->user_data); } - return spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + return nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } else { session->last_recv_stream_id = frame->syn_stream.stream_id; - status_code = spdylay_session_validate_syn_stream(session, + status_code = nghttp2_session_validate_syn_stream(session, &frame->syn_stream); } if(status_code == 0) { uint8_t flags = frame->syn_stream.hd.flags; - if((flags & SPDYLAY_CTRL_FLAG_FIN) && - (flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL)) { + if((flags & NGHTTP2_CTRL_FLAG_FIN) && + (flags & NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL)) { /* If the stream is UNIDIRECTIONAL and FIN bit set, we can close stream upon receiving SYN_STREAM. So, the stream needs not to be opened. */ } else { - spdylay_stream *stream; - stream = spdylay_session_open_stream(session, frame->syn_stream.stream_id, + nghttp2_stream *stream; + stream = nghttp2_session_open_stream(session, frame->syn_stream.stream_id, frame->syn_stream.hd.flags, frame->syn_stream.pri, - SPDYLAY_STREAM_OPENING, + NGHTTP2_STREAM_OPENING, NULL); if(stream) { - if(flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); + if(flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); } - if(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR); + if(flags & NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); } - /* We don't call spdylay_session_close_stream_if_shut_rdwr() - here because either SPDYLAY_CTRL_FLAG_FIN or - SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL is not set here. */ + /* We don't call nghttp2_session_close_stream_if_shut_rdwr() + here because either NGHTTP2_CTRL_FLAG_FIN or + NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL is not set here. */ } } - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_SYN_STREAM, + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_SYN_STREAM, frame); - if(flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_session_call_on_request_recv(session, + if(flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_session_call_on_request_recv(session, frame->syn_stream.stream_id); - if(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) { + if(flags & NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL) { /* Note that we call on_stream_close_callback without opening stream. */ if(session->callbacks.on_stream_close_callback) { session->callbacks.on_stream_close_callback - (session, frame->syn_stream.stream_id, SPDYLAY_OK, + (session, frame->syn_stream.stream_id, NGHTTP2_OK, session->user_data); } } } } else { - r = spdylay_session_handle_invalid_stream - (session, frame->syn_stream.stream_id, SPDYLAY_SYN_STREAM, frame, + r = nghttp2_session_handle_invalid_stream + (session, frame->syn_stream.stream_id, NGHTTP2_SYN_STREAM, frame, status_code); } return r; } -int spdylay_session_on_syn_reply_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_syn_reply_received(nghttp2_session *session, + nghttp2_frame *frame) { int r = 0; int valid = 0; - int status_code = SPDYLAY_PROTOCOL_ERROR; - spdylay_stream *stream; - if(!spdylay_session_check_version(session, frame->syn_reply.hd.version)) { + int status_code = NGHTTP2_PROTOCOL_ERROR; + nghttp2_stream *stream; + if(!nghttp2_session_check_version(session, frame->syn_reply.hd.version)) { return 0; } - if((stream = spdylay_session_get_stream(session, + if((stream = nghttp2_session_get_stream(session, frame->syn_reply.stream_id)) && - (stream->shut_flags & SPDYLAY_SHUT_RD) == 0) { - if(spdylay_session_is_my_stream_id(session, frame->syn_reply.stream_id)) { - if(stream->state == SPDYLAY_STREAM_OPENING) { + (stream->shut_flags & NGHTTP2_SHUT_RD) == 0) { + if(nghttp2_session_is_my_stream_id(session, frame->syn_reply.stream_id)) { + if(stream->state == NGHTTP2_STREAM_OPENING) { valid = 1; - stream->state = SPDYLAY_STREAM_OPENED; - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_SYN_REPLY, + stream->state = NGHTTP2_STREAM_OPENED; + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_SYN_REPLY, frame); - if(frame->syn_reply.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { + if(frame->syn_reply.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { /* This is the last frame of this stream, so disallow further receptions. */ - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); - spdylay_session_close_stream_if_shut_rdwr(session, stream); + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); } - } else if(stream->state == SPDYLAY_STREAM_CLOSING) { - /* This is race condition. SPDYLAY_STREAM_CLOSING indicates + } else if(stream->state == NGHTTP2_STREAM_CLOSING) { + /* This is race condition. NGHTTP2_STREAM_CLOSING indicates that we queued RST_STREAM but it has not been sent. It will eventually sent, so we just ignore this frame. */ valid = 1; } else { - if(session->version == SPDYLAY_PROTO_SPDY3) { + if(session->version == NGHTTP2_PROTO_SPDY3) { /* SPDY/3 spec says if multiple SYN_REPLY frames for the same active stream ID are received, the receiver must issue a stream error with the status code STREAM_IN_USE. */ - status_code = SPDYLAY_STREAM_IN_USE; + status_code = NGHTTP2_STREAM_IN_USE; } } } } if(!valid) { - r = spdylay_session_handle_invalid_stream - (session, frame->syn_reply.stream_id, SPDYLAY_SYN_REPLY, frame, + r = nghttp2_session_handle_invalid_stream + (session, frame->syn_reply.stream_id, NGHTTP2_SYN_REPLY, frame, status_code); } return r; } -int spdylay_session_on_rst_stream_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_rst_stream_received(nghttp2_session *session, + nghttp2_frame *frame) { - if(!spdylay_session_check_version(session, frame->rst_stream.hd.version)) { + if(!nghttp2_session_check_version(session, frame->rst_stream.hd.version)) { return 0; } - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_RST_STREAM, + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_RST_STREAM, frame); if(session->server && - !spdylay_session_is_my_stream_id(session, frame->rst_stream.stream_id) && - frame->rst_stream.status_code == SPDYLAY_CANCEL) { - spdylay_session_close_pushed_streams(session, frame->rst_stream.stream_id, + !nghttp2_session_is_my_stream_id(session, frame->rst_stream.stream_id) && + frame->rst_stream.status_code == NGHTTP2_CANCEL) { + nghttp2_session_close_pushed_streams(session, frame->rst_stream.stream_id, frame->rst_stream.status_code); } - spdylay_session_close_stream(session, frame->rst_stream.stream_id, + nghttp2_session_close_stream(session, frame->rst_stream.stream_id, frame->rst_stream.status_code); return 0; } -static int spdylay_update_initial_window_size_func(spdylay_map_entry *entry, +static int nghttp2_update_initial_window_size_func(nghttp2_map_entry *entry, void *ptr) { - spdylay_update_window_size_arg *arg; - spdylay_stream *stream; - arg = (spdylay_update_window_size_arg*)ptr; - stream = (spdylay_stream*)entry; - spdylay_stream_update_initial_window_size(stream, + nghttp2_update_window_size_arg *arg; + nghttp2_stream *stream; + arg = (nghttp2_update_window_size_arg*)ptr; + stream = (nghttp2_stream*)entry; + nghttp2_stream_update_initial_window_size(stream, arg->new_window_size, arg->old_window_size); /* If window size gets positive, push deferred DATA frame to outbound queue. */ if(stream->window_size > 0 && stream->deferred_data && - (stream->deferred_flags & SPDYLAY_DEFERRED_FLOW_CONTROL)) { + (stream->deferred_flags & NGHTTP2_DEFERRED_FLOW_CONTROL)) { int rv; - rv = spdylay_pq_push(&arg->session->ob_pq, stream->deferred_data); + rv = nghttp2_pq_push(&arg->session->ob_pq, stream->deferred_data); if(rv == 0) { - spdylay_stream_detach_deferred_data(stream); + nghttp2_stream_detach_deferred_data(stream); } else { /* FATAL */ - assert(rv < SPDYLAY_ERR_FATAL); + assert(rv < NGHTTP2_ERR_FATAL); return rv; } } @@ -1878,71 +1878,71 @@ static int spdylay_update_initial_window_size_func(spdylay_map_entry *entry, * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -static int spdylay_session_update_initial_window_size -(spdylay_session *session, +static int nghttp2_session_update_initial_window_size +(nghttp2_session *session, int32_t new_initial_window_size) { - spdylay_update_window_size_arg arg; + nghttp2_update_window_size_arg arg; arg.session = session; arg.new_window_size = new_initial_window_size; arg.old_window_size = - session->remote_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE]; - return spdylay_map_each(&session->streams, - spdylay_update_initial_window_size_func, + session->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]; + return nghttp2_map_each(&session->streams, + nghttp2_update_initial_window_size_func, &arg); } -void spdylay_session_update_local_settings(spdylay_session *session, - spdylay_settings_entry *iv, +void nghttp2_session_update_local_settings(nghttp2_session *session, + nghttp2_settings_entry *iv, size_t niv) { size_t i; for(i = 0; i < niv; ++i) { - assert(iv[i].settings_id > 0 && iv[i].settings_id <= SPDYLAY_SETTINGS_MAX); + assert(iv[i].settings_id > 0 && iv[i].settings_id <= NGHTTP2_SETTINGS_MAX); session->local_settings[iv[i].settings_id] = iv[i].value; } } -int spdylay_session_on_settings_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_settings_received(nghttp2_session *session, + nghttp2_frame *frame) { int rv; size_t i; - int check[SPDYLAY_SETTINGS_MAX+1]; - if(!spdylay_session_check_version(session, frame->settings.hd.version)) { + int check[NGHTTP2_SETTINGS_MAX+1]; + if(!nghttp2_session_check_version(session, frame->settings.hd.version)) { return 0; } /* Check ID/value pairs and persist them if necessary. */ memset(check, 0, sizeof(check)); for(i = 0; i < frame->settings.niv; ++i) { - spdylay_settings_entry *entry = &frame->settings.iv[i]; + nghttp2_settings_entry *entry = &frame->settings.iv[i]; /* SPDY/3 spec says if the multiple values for the same ID were found, use the first one and ignore the rest. */ - if(entry->settings_id > SPDYLAY_SETTINGS_MAX || entry->settings_id == 0 || + if(entry->settings_id > NGHTTP2_SETTINGS_MAX || entry->settings_id == 0 || check[entry->settings_id] == 1) { continue; } check[entry->settings_id] = 1; - if(entry->settings_id == SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE && + if(entry->settings_id == NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && session->flow_control) { /* Update the initial window size of the all active streams */ /* Check that initial_window_size < (1u << 31) */ if(entry->value < (1u << 31)) { - rv = spdylay_session_update_initial_window_size(session, entry->value); + rv = nghttp2_session_update_initial_window_size(session, entry->value); if(rv != 0) { return rv; } } } else if(entry->settings_id == - SPDYLAY_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE) { + NGHTTP2_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE) { if(!session->server) { /* Limit certificate vector length in the reasonable size. */ - entry->value = spdylay_min(entry->value, - SPDYLAY_MAX_CLIENT_CERT_VECTOR_LENGTH); - rv = spdylay_client_cert_vector_resize(&session->cli_certvec, + entry->value = nghttp2_min(entry->value, + NGHTTP2_MAX_CLIENT_CERT_VECTOR_LENGTH); + rv = nghttp2_client_cert_vector_resize(&session->cli_certvec, entry->value); if(rv != 0) { return rv; @@ -1951,15 +1951,15 @@ int spdylay_session_on_settings_received(spdylay_session *session, } session->remote_settings[entry->settings_id] = entry->value; } - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_SETTINGS, frame); + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_SETTINGS, frame); return 0; } -int spdylay_session_on_ping_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_ping_received(nghttp2_session *session, + nghttp2_frame *frame) { int r = 0; - if(!spdylay_session_check_version(session, frame->ping.hd.version)) { + if(!nghttp2_session_check_version(session, frame->ping.hd.version)) { return 0; } if(frame->ping.unique_id != 0) { @@ -1968,105 +1968,105 @@ int spdylay_session_on_ping_received(spdylay_session *session, /* Assign 0 to last_ping_unique_id so that we can ignore same ID. */ session->last_ping_unique_id = 0; - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_PING, frame); + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_PING, frame); } else if((session->server && frame->ping.unique_id % 2 == 1) || (!session->server && frame->ping.unique_id % 2 == 0)) { /* Peer sent ping, so ping it back */ - r = spdylay_session_add_ping(session, frame->ping.unique_id); - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_PING, frame); + r = nghttp2_session_add_ping(session, frame->ping.unique_id); + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_PING, frame); } } return r; } -int spdylay_session_on_goaway_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_goaway_received(nghttp2_session *session, + nghttp2_frame *frame) { - if(!spdylay_session_check_version(session, frame->goaway.hd.version)) { + if(!nghttp2_session_check_version(session, frame->goaway.hd.version)) { return 0; } session->last_good_stream_id = frame->goaway.last_good_stream_id; - session->goaway_flags |= SPDYLAY_GOAWAY_RECV; - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_GOAWAY, frame); + session->goaway_flags |= NGHTTP2_GOAWAY_RECV; + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_GOAWAY, frame); return 0; } -int spdylay_session_on_window_update_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_window_update_received(nghttp2_session *session, + nghttp2_frame *frame) { - spdylay_stream *stream; - if(!spdylay_session_check_version(session, frame->window_update.hd.version)) { + nghttp2_stream *stream; + if(!nghttp2_session_check_version(session, frame->window_update.hd.version)) { return 0; } if(!session->flow_control) { return 0; } - stream = spdylay_session_get_stream(session, frame->window_update.stream_id); + stream = nghttp2_session_get_stream(session, frame->window_update.stream_id); if(stream) { if(INT32_MAX-frame->window_update.delta_window_size < stream->window_size) { int r; - r = spdylay_session_handle_invalid_stream - (session, frame->window_update.stream_id, SPDYLAY_WINDOW_UPDATE, frame, - SPDYLAY_FLOW_CONTROL_ERROR); + r = nghttp2_session_handle_invalid_stream + (session, frame->window_update.stream_id, NGHTTP2_WINDOW_UPDATE, frame, + NGHTTP2_FLOW_CONTROL_ERROR); return r; } else { stream->window_size += frame->window_update.delta_window_size; if(stream->window_size > 0 && stream->deferred_data != NULL && - (stream->deferred_flags & SPDYLAY_DEFERRED_FLOW_CONTROL)) { + (stream->deferred_flags & NGHTTP2_DEFERRED_FLOW_CONTROL)) { int r; - r = spdylay_pq_push(&session->ob_pq, stream->deferred_data); + r = nghttp2_pq_push(&session->ob_pq, stream->deferred_data); if(r == 0) { - spdylay_stream_detach_deferred_data(stream); + nghttp2_stream_detach_deferred_data(stream); } else if(r < 0) { /* FATAL */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); return r; } } - spdylay_session_call_on_ctrl_frame_received(session, - SPDYLAY_WINDOW_UPDATE, frame); + nghttp2_session_call_on_ctrl_frame_received(session, + NGHTTP2_WINDOW_UPDATE, frame); } } return 0; } -int spdylay_session_on_credential_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_credential_received(nghttp2_session *session, + nghttp2_frame *frame) { - if(!spdylay_session_check_version(session, frame->credential.hd.version)) { + if(!nghttp2_session_check_version(session, frame->credential.hd.version)) { return 0; } /* We don't care about the body of the CREDENTIAL frame. It is left to the application code to decide it is invalid or not. */ - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_CREDENTIAL, + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_CREDENTIAL, frame); return 0; } -int spdylay_session_on_headers_received(spdylay_session *session, - spdylay_frame *frame) +int nghttp2_session_on_headers_received(nghttp2_session *session, + nghttp2_frame *frame) { int r = 0; int valid = 0; - spdylay_stream *stream; - if(!spdylay_session_check_version(session, frame->headers.hd.version)) { + nghttp2_stream *stream; + if(!nghttp2_session_check_version(session, frame->headers.hd.version)) { return 0; } - if((stream = spdylay_session_get_stream(session, + if((stream = nghttp2_session_get_stream(session, frame->headers.stream_id)) && - (stream->shut_flags & SPDYLAY_SHUT_RD) == 0) { - if(spdylay_session_is_my_stream_id(session, frame->headers.stream_id)) { - if(stream->state == SPDYLAY_STREAM_OPENED) { + (stream->shut_flags & NGHTTP2_SHUT_RD) == 0) { + if(nghttp2_session_is_my_stream_id(session, frame->headers.stream_id)) { + if(stream->state == NGHTTP2_STREAM_OPENED) { valid = 1; - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_HEADERS, + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_HEADERS, frame); - if(frame->headers.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); - spdylay_session_close_stream_if_shut_rdwr(session, stream); + if(frame->headers.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); } - } else if(stream->state == SPDYLAY_STREAM_CLOSING) { - /* This is race condition. SPDYLAY_STREAM_CLOSING indicates + } else if(stream->state == NGHTTP2_STREAM_CLOSING) { + /* This is race condition. NGHTTP2_STREAM_CLOSING indicates that we queued RST_STREAM but it has not been sent. It will eventually sent, so we just ignore this frame. */ valid = 1; @@ -2074,31 +2074,31 @@ int spdylay_session_on_headers_received(spdylay_session *session, } else { /* If this is remote peer initiated stream, it is OK unless it have sent FIN frame already. But if stream is in - SPDYLAY_STREAM_CLOSING, we discard the frame. This is a race + NGHTTP2_STREAM_CLOSING, we discard the frame. This is a race condition. */ valid = 1; - if(stream->state != SPDYLAY_STREAM_CLOSING) { - spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_HEADERS, + if(stream->state != NGHTTP2_STREAM_CLOSING) { + nghttp2_session_call_on_ctrl_frame_received(session, NGHTTP2_HEADERS, frame); - if(frame->headers.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { - spdylay_session_call_on_request_recv(session, + if(frame->headers.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { + nghttp2_session_call_on_request_recv(session, frame->headers.stream_id); - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); - spdylay_session_close_stream_if_shut_rdwr(session, stream); + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); } } } } if(!valid) { - r = spdylay_session_handle_invalid_stream - (session, frame->headers.stream_id, SPDYLAY_HEADERS, frame, - SPDYLAY_PROTOCOL_ERROR); + r = nghttp2_session_handle_invalid_stream + (session, frame->headers.stream_id, NGHTTP2_HEADERS, frame, + NGHTTP2_PROTOCOL_ERROR); } return r; } -static void spdylay_session_handle_parse_error(spdylay_session *session, - spdylay_frame_type type, +static void nghttp2_session_handle_parse_error(nghttp2_session *session, + nghttp2_frame_type type, int error_code) { if(session->callbacks.on_ctrl_recv_parse_error_callback) { @@ -2114,34 +2114,34 @@ static void spdylay_session_handle_parse_error(spdylay_session *session, } } -static int spdylay_get_status_code_from_error_code(int error_code) +static int nghttp2_get_status_code_from_error_code(int error_code) { switch(error_code) { - case(SPDYLAY_ERR_FRAME_TOO_LARGE): - return SPDYLAY_FRAME_TOO_LARGE; + case(NGHTTP2_ERR_FRAME_TOO_LARGE): + return NGHTTP2_FRAME_TOO_LARGE; default: - return SPDYLAY_PROTOCOL_ERROR; + return NGHTTP2_PROTOCOL_ERROR; } } /* For errors, this function only returns FATAL error. */ -static int spdylay_session_process_ctrl_frame(spdylay_session *session) +static int nghttp2_session_process_ctrl_frame(nghttp2_session *session) { int r = 0; uint16_t type; - spdylay_frame frame; - type = spdylay_get_uint16(&session->iframe.headbuf[2]); + nghttp2_frame frame; + type = nghttp2_get_uint16(&session->iframe.headbuf[2]); switch(type) { - case SPDYLAY_SYN_STREAM: + case NGHTTP2_SYN_STREAM: if(session->iframe.error_code == 0) { - r = spdylay_frame_unpack_syn_stream(&frame.syn_stream, + r = nghttp2_frame_unpack_syn_stream(&frame.syn_stream, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen, &session->iframe.inflatebuf); - } else if(session->iframe.error_code == SPDYLAY_ERR_FRAME_TOO_LARGE) { - r = spdylay_frame_unpack_syn_stream_without_nv + } else if(session->iframe.error_code == NGHTTP2_ERR_FRAME_TOO_LARGE) { + r = nghttp2_frame_unpack_syn_stream_without_nv (&frame.syn_stream, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); @@ -2152,32 +2152,32 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session) r = session->iframe.error_code; } if(r == 0) { - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_2to3(frame.syn_stream.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_2to3(frame.syn_stream.nv); } - r = spdylay_session_on_syn_stream_received(session, &frame); - spdylay_frame_syn_stream_free(&frame.syn_stream); - } else if(r == SPDYLAY_ERR_INVALID_HEADER_BLOCK || - r == SPDYLAY_ERR_FRAME_TOO_LARGE) { - r = spdylay_session_handle_invalid_stream - (session, frame.syn_stream.stream_id, SPDYLAY_SYN_STREAM, &frame, - spdylay_get_status_code_from_error_code(r)); - spdylay_frame_syn_stream_free(&frame.syn_stream); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_syn_stream_received(session, &frame); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + } else if(r == NGHTTP2_ERR_INVALID_HEADER_BLOCK || + r == NGHTTP2_ERR_FRAME_TOO_LARGE) { + r = nghttp2_session_handle_invalid_stream + (session, frame.syn_stream.stream_id, NGHTTP2_SYN_STREAM, &frame, + nghttp2_get_status_code_from_error_code(r)); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_SYN_REPLY: + case NGHTTP2_SYN_REPLY: if(session->iframe.error_code == 0) { - r = spdylay_frame_unpack_syn_reply(&frame.syn_reply, + r = nghttp2_frame_unpack_syn_reply(&frame.syn_reply, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen, &session->iframe.inflatebuf); - } else if(session->iframe.error_code == SPDYLAY_ERR_FRAME_TOO_LARGE) { - r = spdylay_frame_unpack_syn_reply_without_nv + } else if(session->iframe.error_code == NGHTTP2_ERR_FRAME_TOO_LARGE) { + r = nghttp2_frame_unpack_syn_reply_without_nv (&frame.syn_reply, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); @@ -2188,90 +2188,90 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session) r = session->iframe.error_code; } if(r == 0) { - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_2to3(frame.syn_reply.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_2to3(frame.syn_reply.nv); } - r = spdylay_session_on_syn_reply_received(session, &frame); - spdylay_frame_syn_reply_free(&frame.syn_reply); - } else if(r == SPDYLAY_ERR_INVALID_HEADER_BLOCK || - r == SPDYLAY_ERR_FRAME_TOO_LARGE) { - r = spdylay_session_handle_invalid_stream - (session, frame.syn_reply.stream_id, SPDYLAY_SYN_REPLY, &frame, - spdylay_get_status_code_from_error_code(r)); - spdylay_frame_syn_reply_free(&frame.syn_reply); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_syn_reply_received(session, &frame); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + } else if(r == NGHTTP2_ERR_INVALID_HEADER_BLOCK || + r == NGHTTP2_ERR_FRAME_TOO_LARGE) { + r = nghttp2_session_handle_invalid_stream + (session, frame.syn_reply.stream_id, NGHTTP2_SYN_REPLY, &frame, + nghttp2_get_status_code_from_error_code(r)); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_RST_STREAM: - r = spdylay_frame_unpack_rst_stream(&frame.rst_stream, + case NGHTTP2_RST_STREAM: + r = nghttp2_frame_unpack_rst_stream(&frame.rst_stream, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); if(r == 0) { - r = spdylay_session_on_rst_stream_received(session, &frame); - spdylay_frame_rst_stream_free(&frame.rst_stream); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_rst_stream_received(session, &frame); + nghttp2_frame_rst_stream_free(&frame.rst_stream); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_SETTINGS: - r = spdylay_frame_unpack_settings(&frame.settings, + case NGHTTP2_SETTINGS: + r = nghttp2_frame_unpack_settings(&frame.settings, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); if(r == 0) { - r = spdylay_session_on_settings_received(session, &frame); - spdylay_frame_settings_free(&frame.settings); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_settings_received(session, &frame); + nghttp2_frame_settings_free(&frame.settings); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_NOOP: + case NGHTTP2_NOOP: break; - case SPDYLAY_PING: - r = spdylay_frame_unpack_ping(&frame.ping, + case NGHTTP2_PING: + r = nghttp2_frame_unpack_ping(&frame.ping, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); if(r == 0) { - r = spdylay_session_on_ping_received(session, &frame); - spdylay_frame_ping_free(&frame.ping); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_ping_received(session, &frame); + nghttp2_frame_ping_free(&frame.ping); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_GOAWAY: - r = spdylay_frame_unpack_goaway(&frame.goaway, + case NGHTTP2_GOAWAY: + r = nghttp2_frame_unpack_goaway(&frame.goaway, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); if(r == 0) { - r = spdylay_session_on_goaway_received(session, &frame); - spdylay_frame_goaway_free(&frame.goaway); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_goaway_received(session, &frame); + nghttp2_frame_goaway_free(&frame.goaway); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_HEADERS: + case NGHTTP2_HEADERS: if(session->iframe.error_code == 0) { - r = spdylay_frame_unpack_headers(&frame.headers, + r = nghttp2_frame_unpack_headers(&frame.headers, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen, &session->iframe.inflatebuf); - } else if(session->iframe.error_code == SPDYLAY_ERR_FRAME_TOO_LARGE) { - r = spdylay_frame_unpack_headers_without_nv + } else if(session->iframe.error_code == NGHTTP2_ERR_FRAME_TOO_LARGE) { + r = nghttp2_frame_unpack_headers_without_nv (&frame.headers, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); @@ -2282,48 +2282,48 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session) r = session->iframe.error_code; } if(r == 0) { - if(session->version == SPDYLAY_PROTO_SPDY2) { - spdylay_frame_nv_2to3(frame.headers.nv); + if(session->version == NGHTTP2_PROTO_SPDY2) { + nghttp2_frame_nv_2to3(frame.headers.nv); } - r = spdylay_session_on_headers_received(session, &frame); - spdylay_frame_headers_free(&frame.headers); - } else if(r == SPDYLAY_ERR_INVALID_HEADER_BLOCK || - r == SPDYLAY_ERR_FRAME_TOO_LARGE) { - r = spdylay_session_handle_invalid_stream - (session, frame.headers.stream_id, SPDYLAY_HEADERS, &frame, - spdylay_get_status_code_from_error_code(r)); - spdylay_frame_headers_free(&frame.headers); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_headers_received(session, &frame); + nghttp2_frame_headers_free(&frame.headers); + } else if(r == NGHTTP2_ERR_INVALID_HEADER_BLOCK || + r == NGHTTP2_ERR_FRAME_TOO_LARGE) { + r = nghttp2_session_handle_invalid_stream + (session, frame.headers.stream_id, NGHTTP2_HEADERS, &frame, + nghttp2_get_status_code_from_error_code(r)); + nghttp2_frame_headers_free(&frame.headers); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_WINDOW_UPDATE: - r = spdylay_frame_unpack_window_update(&frame.window_update, + case NGHTTP2_WINDOW_UPDATE: + r = nghttp2_frame_unpack_window_update(&frame.window_update, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); if(r == 0) { - r = spdylay_session_on_window_update_received(session, &frame); - spdylay_frame_window_update_free(&frame.window_update); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_window_update_received(session, &frame); + nghttp2_frame_window_update_free(&frame.window_update); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; - case SPDYLAY_CREDENTIAL: - r = spdylay_frame_unpack_credential(&frame.credential, + case NGHTTP2_CREDENTIAL: + r = nghttp2_frame_unpack_credential(&frame.credential, session->iframe.headbuf, sizeof(session->iframe.headbuf), session->iframe.buf, session->iframe.buflen); if(r == 0) { - r = spdylay_session_on_credential_received(session, &frame); - spdylay_frame_credential_free(&frame.credential); - } else if(spdylay_is_non_fatal(r)) { - spdylay_session_handle_parse_error(session, type, r); - r = spdylay_session_fail_session(session, SPDYLAY_GOAWAY_PROTOCOL_ERROR); + r = nghttp2_session_on_credential_received(session, &frame); + nghttp2_frame_credential_free(&frame.credential); + } else if(nghttp2_is_non_fatal(r)) { + nghttp2_session_handle_parse_error(session, type, r); + r = nghttp2_session_fail_session(session, NGHTTP2_GOAWAY_PROTOCOL_ERROR); } break; default: @@ -2338,79 +2338,79 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session) session->user_data); } } - if(spdylay_is_fatal(r)) { + if(nghttp2_is_fatal(r)) { return r; } else { return 0; } } -int spdylay_session_on_data_received(spdylay_session *session, +int nghttp2_session_on_data_received(nghttp2_session *session, uint8_t flags, int32_t length, int32_t stream_id) { int r = 0; - spdylay_status_code status_code = 0; - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, stream_id); + nghttp2_status_code status_code = 0; + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); if(stream) { - if((stream->shut_flags & SPDYLAY_SHUT_RD) == 0) { + if((stream->shut_flags & NGHTTP2_SHUT_RD) == 0) { int valid = 0; - if(spdylay_session_is_my_stream_id(session, stream_id)) { - if(stream->state == SPDYLAY_STREAM_OPENED) { + if(nghttp2_session_is_my_stream_id(session, stream_id)) { + if(stream->state == NGHTTP2_STREAM_OPENED) { valid = 1; if(session->callbacks.on_data_recv_callback) { session->callbacks.on_data_recv_callback (session, flags, stream_id, length, session->user_data); } - } else if(stream->state != SPDYLAY_STREAM_CLOSING) { - status_code = SPDYLAY_PROTOCOL_ERROR; + } else if(stream->state != NGHTTP2_STREAM_CLOSING) { + status_code = NGHTTP2_PROTOCOL_ERROR; } - } else if(stream->state != SPDYLAY_STREAM_CLOSING) { + } else if(stream->state != NGHTTP2_STREAM_CLOSING) { /* It is OK if this is remote peer initiated stream and we did - not receive FIN unless stream is in SPDYLAY_STREAM_CLOSING + not receive FIN unless stream is in NGHTTP2_STREAM_CLOSING state. This is a race condition. */ valid = 1; if(session->callbacks.on_data_recv_callback) { session->callbacks.on_data_recv_callback (session, flags, stream_id, length, session->user_data); } - if(flags & SPDYLAY_DATA_FLAG_FIN) { - spdylay_session_call_on_request_recv(session, stream_id); + if(flags & NGHTTP2_DATA_FLAG_FIN) { + nghttp2_session_call_on_request_recv(session, stream_id); } } if(valid) { - if(flags & SPDYLAY_DATA_FLAG_FIN) { - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); - spdylay_session_close_stream_if_shut_rdwr(session, stream); + if(flags & NGHTTP2_DATA_FLAG_FIN) { + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); + nghttp2_session_close_stream_if_shut_rdwr(session, stream); } } } else { - status_code = SPDYLAY_PROTOCOL_ERROR; + status_code = NGHTTP2_PROTOCOL_ERROR; } } else { - status_code = SPDYLAY_INVALID_STREAM; + status_code = NGHTTP2_INVALID_STREAM; } if(status_code != 0) { - r = spdylay_session_add_rst_stream(session, stream_id, status_code); + r = nghttp2_session_add_rst_stream(session, stream_id, status_code); } return r; } /* For errors, this function only returns FATAL error. */ -static int spdylay_session_process_data_frame(spdylay_session *session) +static int nghttp2_session_process_data_frame(nghttp2_session *session) { uint8_t flags; int32_t length; int32_t stream_id; int r; - stream_id = spdylay_get_uint32(session->iframe.headbuf) & - SPDYLAY_STREAM_ID_MASK; + stream_id = nghttp2_get_uint32(session->iframe.headbuf) & + NGHTTP2_STREAM_ID_MASK; flags = session->iframe.headbuf[4]; - length = spdylay_get_uint32(&session->iframe.headbuf[4]) & - SPDYLAY_LENGTH_MASK; - r = spdylay_session_on_data_received(session, flags, length, stream_id); - if(spdylay_is_fatal(r)) { + length = nghttp2_get_uint32(&session->iframe.headbuf[4]) & + NGHTTP2_LENGTH_MASK; + r = nghttp2_session_on_data_received(session, flags, length, stream_id); + if(nghttp2_is_fatal(r)) { return r; } else { return 0; @@ -2419,23 +2419,23 @@ static int spdylay_session_process_data_frame(spdylay_session *session) /* * Accumulates received bytes |delta_size| and decides whether to send - * WINDOW_UPDATE. If SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE is set, + * WINDOW_UPDATE. If NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE is set, * WINDOW_UPDATE will not be sent. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -static int spdylay_session_update_recv_window_size(spdylay_session *session, +static int nghttp2_session_update_recv_window_size(nghttp2_session *session, int32_t stream_id, int32_t delta_size) { - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); if(stream) { - /* If SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE is set and the application + /* If NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE is set and the application does not send WINDOW_UPDATE and the remote endpoint keeps sending data, stream->recv_window_size will eventually overflow. */ @@ -2444,14 +2444,14 @@ static int spdylay_session_update_recv_window_size(spdylay_session *session, } else { stream->recv_window_size += delta_size; } - if(!(session->opt_flags & SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE)) { + if(!(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE)) { /* This is just a heuristics. */ /* We have to use local_settings here because it is the constraint the remote endpoint should honor. */ if((size_t)stream->recv_window_size*2 >= - session->local_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE]) { + session->local_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]) { int r; - r = spdylay_session_add_window_update(session, stream_id, + r = nghttp2_session_add_window_update(session, stream_id, stream->recv_window_size); if(r == 0) { stream->recv_window_size = 0; @@ -2468,20 +2468,20 @@ static int spdylay_session_update_recv_window_size(spdylay_session *session, * Returns nonzero if the reception of DATA for stream |stream_id| is * allowed. */ -static int spdylay_session_check_data_recv_allowed(spdylay_session *session, +static int nghttp2_session_check_data_recv_allowed(nghttp2_session *session, int32_t stream_id) { - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); if(stream) { - if((stream->shut_flags & SPDYLAY_SHUT_RD) == 0) { - if(spdylay_session_is_my_stream_id(session, stream_id)) { - if(stream->state == SPDYLAY_STREAM_OPENED) { + if((stream->shut_flags & NGHTTP2_SHUT_RD) == 0) { + if(nghttp2_session_is_my_stream_id(session, stream_id)) { + if(stream->state == NGHTTP2_STREAM_OPENED) { return 1; } - } else if(stream->state != SPDYLAY_STREAM_CLOSING) { + } else if(stream->state != NGHTTP2_STREAM_CLOSING) { /* It is OK if this is remote peer initiated stream and we did - not receive FIN unless stream is in SPDYLAY_STREAM_CLOSING + not receive FIN unless stream is in NGHTTP2_STREAM_CLOSING state. This is a race condition. */ return 1; } @@ -2490,7 +2490,7 @@ static int spdylay_session_check_data_recv_allowed(spdylay_session *session, return 0; } -ssize_t spdylay_session_mem_recv(spdylay_session *session, +ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, size_t inlen) { const uint8_t *inmark, *inlimit; @@ -2498,92 +2498,92 @@ ssize_t spdylay_session_mem_recv(spdylay_session *session, inlimit = in+inlen; while(1) { ssize_t r; - if(session->iframe.state == SPDYLAY_RECV_HEAD) { + if(session->iframe.state == NGHTTP2_RECV_HEAD) { size_t remheadbytes; size_t readlen; size_t bufavail = inlimit-inmark; if(bufavail == 0) { break; } - remheadbytes = SPDYLAY_HEAD_LEN-session->iframe.headbufoff; - readlen = spdylay_min(remheadbytes, bufavail); + remheadbytes = NGHTTP2_HEAD_LEN-session->iframe.headbufoff; + readlen = nghttp2_min(remheadbytes, bufavail); memcpy(session->iframe.headbuf+session->iframe.headbufoff, inmark, readlen); inmark += readlen; session->iframe.headbufoff += readlen; - if(session->iframe.headbufoff == SPDYLAY_HEAD_LEN) { - session->iframe.state = SPDYLAY_RECV_PAYLOAD; + if(session->iframe.headbufoff == NGHTTP2_HEAD_LEN) { + session->iframe.state = NGHTTP2_RECV_PAYLOAD; session->iframe.payloadlen = - spdylay_get_uint32(&session->iframe.headbuf[4]) & - SPDYLAY_LENGTH_MASK; - if(spdylay_frame_is_ctrl_frame(session->iframe.headbuf[0])) { + nghttp2_get_uint32(&session->iframe.headbuf[4]) & + NGHTTP2_LENGTH_MASK; + if(nghttp2_frame_is_ctrl_frame(session->iframe.headbuf[0])) { /* control frame */ ssize_t buflen; - buflen = spdylay_inbound_frame_payload_nv_offset(&session->iframe); + buflen = nghttp2_inbound_frame_payload_nv_offset(&session->iframe); if(buflen == -1) { /* Check if payloadlen is small enough for buffering */ if(session->iframe.payloadlen > session->max_recv_ctrl_frame_buf) { - session->iframe.error_code = SPDYLAY_ERR_FRAME_TOO_LARGE; - session->iframe.state = SPDYLAY_RECV_PAYLOAD_IGN; + session->iframe.error_code = NGHTTP2_ERR_FRAME_TOO_LARGE; + session->iframe.state = NGHTTP2_RECV_PAYLOAD_IGN; buflen = 0; } else { buflen = session->iframe.payloadlen; } } else if(buflen < (ssize_t)session->iframe.payloadlen) { if(session->iframe.payloadlen > session->max_recv_ctrl_frame_buf) { - session->iframe.error_code = SPDYLAY_ERR_FRAME_TOO_LARGE; + session->iframe.error_code = NGHTTP2_ERR_FRAME_TOO_LARGE; } /* We are going to receive payload even if the receiving frame is too large to synchronize zlib context. For name/value header block, we will just burn zlib cycle and discard outputs. */ - session->iframe.state = SPDYLAY_RECV_PAYLOAD_PRE_NV; + session->iframe.state = NGHTTP2_RECV_PAYLOAD_PRE_NV; } /* buflen >= session->iframe.payloadlen means frame is malformed. In this case, we just buffer these bytes and handle error later. */ session->iframe.buflen = buflen; - r = spdylay_reserve_buffer(&session->iframe.buf, + r = nghttp2_reserve_buffer(&session->iframe.buf, &session->iframe.bufmax, buflen); if(r != 0) { /* FATAL */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); return r; } } else { /* Check stream is open. If it is not open or closing, ignore payload. */ int32_t stream_id; - stream_id = spdylay_get_uint32(session->iframe.headbuf); - if(!spdylay_session_check_data_recv_allowed(session, stream_id)) { - session->iframe.state = SPDYLAY_RECV_PAYLOAD_IGN; + stream_id = nghttp2_get_uint32(session->iframe.headbuf); + if(!nghttp2_session_check_data_recv_allowed(session, stream_id)) { + session->iframe.state = NGHTTP2_RECV_PAYLOAD_IGN; } } } else { break; } } - if(session->iframe.state == SPDYLAY_RECV_PAYLOAD || - session->iframe.state == SPDYLAY_RECV_PAYLOAD_PRE_NV || - session->iframe.state == SPDYLAY_RECV_PAYLOAD_NV || - session->iframe.state == SPDYLAY_RECV_PAYLOAD_IGN) { + if(session->iframe.state == NGHTTP2_RECV_PAYLOAD || + session->iframe.state == NGHTTP2_RECV_PAYLOAD_PRE_NV || + session->iframe.state == NGHTTP2_RECV_PAYLOAD_NV || + session->iframe.state == NGHTTP2_RECV_PAYLOAD_IGN) { size_t rempayloadlen; size_t bufavail, readlen; int32_t data_stream_id = 0; - uint8_t data_flags = SPDYLAY_DATA_FLAG_NONE; + uint8_t data_flags = NGHTTP2_DATA_FLAG_NONE; rempayloadlen = session->iframe.payloadlen - session->iframe.off; bufavail = inlimit - inmark; if(rempayloadlen > 0 && bufavail == 0) { break; } - readlen = spdylay_min(bufavail, rempayloadlen); - if(session->iframe.state == SPDYLAY_RECV_PAYLOAD_PRE_NV) { + readlen = nghttp2_min(bufavail, rempayloadlen); + if(session->iframe.state == NGHTTP2_RECV_PAYLOAD_PRE_NV) { size_t pnvlen, rpnvlen, readpnvlen; - pnvlen = spdylay_inbound_frame_payload_nv_offset(&session->iframe); + pnvlen = nghttp2_inbound_frame_payload_nv_offset(&session->iframe); rpnvlen = pnvlen - session->iframe.off; - readpnvlen = spdylay_min(rpnvlen, readlen); + readpnvlen = nghttp2_min(rpnvlen, readlen); memcpy(session->iframe.buf+session->iframe.off, inmark, readpnvlen); readlen -= readpnvlen; @@ -2591,47 +2591,47 @@ ssize_t spdylay_session_mem_recv(spdylay_session *session, inmark += readpnvlen; if(session->iframe.off == pnvlen) { - session->iframe.state = SPDYLAY_RECV_PAYLOAD_NV; + session->iframe.state = NGHTTP2_RECV_PAYLOAD_NV; } } - if(session->iframe.state == SPDYLAY_RECV_PAYLOAD_NV) { + if(session->iframe.state == NGHTTP2_RECV_PAYLOAD_NV) { /* For frame with name/value header block, the compressed portion of the block is incrementally decompressed. The result is stored in inflatebuf. */ if(session->iframe.error_code == 0 || - session->iframe.error_code == SPDYLAY_ERR_FRAME_TOO_LARGE) { + session->iframe.error_code == NGHTTP2_ERR_FRAME_TOO_LARGE) { ssize_t decomplen; - if(session->iframe.error_code == SPDYLAY_ERR_FRAME_TOO_LARGE) { - spdylay_buffer_reset(&session->iframe.inflatebuf); + if(session->iframe.error_code == NGHTTP2_ERR_FRAME_TOO_LARGE) { + nghttp2_buffer_reset(&session->iframe.inflatebuf); } - decomplen = spdylay_zlib_inflate_hd(&session->hd_inflater, + decomplen = nghttp2_zlib_inflate_hd(&session->hd_inflater, &session->iframe.inflatebuf, inmark, readlen); if(decomplen < 0) { /* We are going to overwrite error_code here if it is already set. But it is fine because the only possible - nonzero error code here is SPDYLAY_ERR_FRAME_TOO_LARGE + nonzero error code here is NGHTTP2_ERR_FRAME_TOO_LARGE and zlib/fatal error can override it. */ session->iframe.error_code = decomplen; - } else if(spdylay_buffer_length(&session->iframe.inflatebuf) + } else if(nghttp2_buffer_length(&session->iframe.inflatebuf) > session->max_recv_ctrl_frame_buf) { /* If total length in inflatebuf exceeds certain limit, set TOO_LARGE_FRAME to error_code and issue RST_STREAM later. */ - session->iframe.error_code = SPDYLAY_ERR_FRAME_TOO_LARGE; + session->iframe.error_code = NGHTTP2_ERR_FRAME_TOO_LARGE; } } - } else if(spdylay_frame_is_ctrl_frame(session->iframe.headbuf[0])) { - if(session->iframe.state != SPDYLAY_RECV_PAYLOAD_IGN) { + } else if(nghttp2_frame_is_ctrl_frame(session->iframe.headbuf[0])) { + if(session->iframe.state != NGHTTP2_RECV_PAYLOAD_IGN) { memcpy(session->iframe.buf+session->iframe.off, inmark, readlen); } } else { /* For data frame, We don't buffer data. Instead, just pass received data to callback function. */ - data_stream_id = spdylay_get_uint32(session->iframe.headbuf) & - SPDYLAY_STREAM_ID_MASK; + data_stream_id = nghttp2_get_uint32(session->iframe.headbuf) & + NGHTTP2_STREAM_ID_MASK; data_flags = session->iframe.headbuf[4]; - if(session->iframe.state != SPDYLAY_RECV_PAYLOAD_IGN) { + if(session->iframe.state != NGHTTP2_RECV_PAYLOAD_IGN) { if(session->callbacks.on_data_chunk_recv_callback) { session->callbacks.on_data_chunk_recv_callback(session, data_flags, @@ -2646,81 +2646,81 @@ ssize_t spdylay_session_mem_recv(spdylay_session *session, inmark += readlen; if(session->flow_control && - session->iframe.state != SPDYLAY_RECV_PAYLOAD_IGN && - !spdylay_frame_is_ctrl_frame(session->iframe.headbuf[0])) { + session->iframe.state != NGHTTP2_RECV_PAYLOAD_IGN && + !nghttp2_frame_is_ctrl_frame(session->iframe.headbuf[0])) { if(readlen > 0 && (session->iframe.payloadlen != session->iframe.off || - (data_flags & SPDYLAY_DATA_FLAG_FIN) == 0)) { - r = spdylay_session_update_recv_window_size(session, + (data_flags & NGHTTP2_DATA_FLAG_FIN) == 0)) { + r = nghttp2_session_update_recv_window_size(session, data_stream_id, readlen); if(r < 0) { /* FATAL */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); return r; } } } if(session->iframe.payloadlen == session->iframe.off) { - if(spdylay_frame_is_ctrl_frame(session->iframe.headbuf[0])) { - r = spdylay_session_process_ctrl_frame(session); + if(nghttp2_frame_is_ctrl_frame(session->iframe.headbuf[0])) { + r = nghttp2_session_process_ctrl_frame(session); } else { - r = spdylay_session_process_data_frame(session); + r = nghttp2_session_process_data_frame(session); } if(r < 0) { /* FATAL */ - assert(r < SPDYLAY_ERR_FATAL); + assert(r < NGHTTP2_ERR_FATAL); return r; } - spdylay_inbound_frame_reset(&session->iframe); + nghttp2_inbound_frame_reset(&session->iframe); } } } return inmark-in; } -int spdylay_session_recv(spdylay_session *session) +int nghttp2_session_recv(nghttp2_session *session) { - uint8_t buf[SPDYLAY_INBOUND_BUFFER_LENGTH]; + uint8_t buf[NGHTTP2_INBOUND_BUFFER_LENGTH]; while(1) { ssize_t readlen; - readlen = spdylay_recv(session, buf, sizeof(buf)); + readlen = nghttp2_recv(session, buf, sizeof(buf)); if(readlen > 0) { - ssize_t proclen = spdylay_session_mem_recv(session, buf, readlen); + ssize_t proclen = nghttp2_session_mem_recv(session, buf, readlen); if(proclen < 0) { return proclen; } assert(proclen == readlen); - } else if(readlen == 0 || readlen == SPDYLAY_ERR_WOULDBLOCK) { + } else if(readlen == 0 || readlen == NGHTTP2_ERR_WOULDBLOCK) { return 0; - } else if(readlen == SPDYLAY_ERR_EOF) { + } else if(readlen == NGHTTP2_ERR_EOF) { return readlen; } else if(readlen < 0) { - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } } } -int spdylay_session_want_read(spdylay_session *session) +int nghttp2_session_want_read(nghttp2_session *session) { /* If these flags are set, we don't want to read. The application should drop the connection. */ - if((session->goaway_flags & SPDYLAY_GOAWAY_FAIL_ON_SEND) && - (session->goaway_flags & SPDYLAY_GOAWAY_SEND)) { + if((session->goaway_flags & NGHTTP2_GOAWAY_FAIL_ON_SEND) && + (session->goaway_flags & NGHTTP2_GOAWAY_SEND)) { return 0; } /* Unless GOAWAY is sent or received, we always want to read incoming frames. After GOAWAY is sent or received, we are only interested in active streams. */ - return !session->goaway_flags || spdylay_map_size(&session->streams) > 0; + return !session->goaway_flags || nghttp2_map_size(&session->streams) > 0; } -int spdylay_session_want_write(spdylay_session *session) +int nghttp2_session_want_write(nghttp2_session *session) { /* If these flags are set, we don't want to write any data. The application should drop the connection. */ - if((session->goaway_flags & SPDYLAY_GOAWAY_FAIL_ON_SEND) && - (session->goaway_flags & SPDYLAY_GOAWAY_SEND)) { + if((session->goaway_flags & NGHTTP2_GOAWAY_FAIL_ON_SEND) && + (session->goaway_flags & NGHTTP2_GOAWAY_SEND)) { return 0; } /* @@ -2730,78 +2730,78 @@ int spdylay_session_want_write(spdylay_session *session) * SYN_STREAM. After GOAWAY is sent or received, we want to write * frames if there is pending ones AND there are active frames. */ - return (session->aob.item != NULL || !spdylay_pq_empty(&session->ob_pq) || - (!spdylay_pq_empty(&session->ob_ss_pq) && - !spdylay_session_is_outgoing_concurrent_streams_max(session))) && - (!session->goaway_flags || spdylay_map_size(&session->streams) > 0); + return (session->aob.item != NULL || !nghttp2_pq_empty(&session->ob_pq) || + (!nghttp2_pq_empty(&session->ob_ss_pq) && + !nghttp2_session_is_outgoing_concurrent_streams_max(session))) && + (!session->goaway_flags || nghttp2_map_size(&session->streams) > 0); } -int spdylay_session_add_ping(spdylay_session *session, uint32_t unique_id) +int nghttp2_session_add_ping(nghttp2_session *session, uint32_t unique_id) { int r; - spdylay_frame *frame; - frame = malloc(sizeof(spdylay_frame)); + nghttp2_frame *frame; + frame = malloc(sizeof(nghttp2_frame)); if(frame == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - spdylay_frame_ping_init(&frame->ping, session->version, unique_id); - r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); + nghttp2_frame_ping_init(&frame->ping, session->version, unique_id); + r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); if(r != 0) { - spdylay_frame_ping_free(&frame->ping); + nghttp2_frame_ping_free(&frame->ping); free(frame); } return r; } -int spdylay_session_add_goaway(spdylay_session *session, +int nghttp2_session_add_goaway(nghttp2_session *session, int32_t last_good_stream_id, uint32_t status_code) { int r; - spdylay_frame *frame; - frame = malloc(sizeof(spdylay_frame)); + nghttp2_frame *frame; + frame = malloc(sizeof(nghttp2_frame)); if(frame == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - spdylay_frame_goaway_init(&frame->goaway, session->version, + nghttp2_frame_goaway_init(&frame->goaway, session->version, last_good_stream_id, status_code); - r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); + r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); if(r != 0) { - spdylay_frame_goaway_free(&frame->goaway); + nghttp2_frame_goaway_free(&frame->goaway); free(frame); } return r; } -int spdylay_session_add_window_update(spdylay_session *session, +int nghttp2_session_add_window_update(nghttp2_session *session, int32_t stream_id, int32_t delta_window_size) { int r; - spdylay_frame *frame; - frame = malloc(sizeof(spdylay_frame)); + nghttp2_frame *frame; + frame = malloc(sizeof(nghttp2_frame)); if(frame == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } - spdylay_frame_window_update_init(&frame->window_update, session->version, + nghttp2_frame_window_update_init(&frame->window_update, session->version, stream_id, delta_window_size); - r = spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); + r = nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); if(r != 0) { - spdylay_frame_window_update_free(&frame->window_update); + nghttp2_frame_window_update_free(&frame->window_update); free(frame); } return r; } -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, size_t datamax, - spdylay_data *frame) + nghttp2_data *frame) { ssize_t framelen = datamax+8, r; int eof_flags; uint8_t flags; - r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen); + r = nghttp2_reserve_buffer(buf_ptr, buflen_ptr, framelen); if(r != 0) { return r; } @@ -2809,30 +2809,30 @@ ssize_t spdylay_session_pack_data(spdylay_session *session, r = frame->data_prd.read_callback (session, frame->stream_id, (*buf_ptr)+8, datamax, &eof_flags, &frame->data_prd.source, session->user_data); - if(r == SPDYLAY_ERR_DEFERRED || r == SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE) { + if(r == NGHTTP2_ERR_DEFERRED || r == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { return r; } else if(r < 0 || datamax < (size_t)r) { /* This is the error code when callback is failed. */ - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } - memset(*buf_ptr, 0, SPDYLAY_HEAD_LEN); - spdylay_put_uint32be(&(*buf_ptr)[0], frame->stream_id); - spdylay_put_uint32be(&(*buf_ptr)[4], r); + memset(*buf_ptr, 0, NGHTTP2_HEAD_LEN); + nghttp2_put_uint32be(&(*buf_ptr)[0], frame->stream_id); + nghttp2_put_uint32be(&(*buf_ptr)[4], r); flags = 0; if(eof_flags) { frame->eof = 1; - if(frame->flags & SPDYLAY_DATA_FLAG_FIN) { - flags |= SPDYLAY_DATA_FLAG_FIN; + if(frame->flags & NGHTTP2_DATA_FLAG_FIN) { + flags |= NGHTTP2_DATA_FLAG_FIN; } } (*buf_ptr)[4] = flags; return r+8; } -uint32_t spdylay_session_get_next_unique_id(spdylay_session *session) +uint32_t nghttp2_session_get_next_unique_id(nghttp2_session *session) { uint32_t ret_id; - if(session->next_unique_id > SPDYLAY_MAX_UNIQUE_ID) { + if(session->next_unique_id > NGHTTP2_MAX_UNIQUE_ID) { if(session->server) { session->next_unique_id = 2; } else { @@ -2844,11 +2844,11 @@ uint32_t spdylay_session_get_next_unique_id(spdylay_session *session) return ret_id; } -void* spdylay_session_get_stream_user_data(spdylay_session *session, +void* nghttp2_session_get_stream_user_data(nghttp2_session *session, int32_t stream_id) { - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); if(stream) { return stream->stream_user_data; } else { @@ -2856,104 +2856,104 @@ void* spdylay_session_get_stream_user_data(spdylay_session *session, } } -int spdylay_session_resume_data(spdylay_session *session, int32_t stream_id) +int nghttp2_session_resume_data(nghttp2_session *session, int32_t stream_id) { int r; - spdylay_stream *stream; - stream = spdylay_session_get_stream(session, stream_id); + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); if(stream == NULL || stream->deferred_data == NULL || - (stream->deferred_flags & SPDYLAY_DEFERRED_FLOW_CONTROL)) { - return SPDYLAY_ERR_INVALID_ARGUMENT; + (stream->deferred_flags & NGHTTP2_DEFERRED_FLOW_CONTROL)) { + return NGHTTP2_ERR_INVALID_ARGUMENT; } - r = spdylay_pq_push(&session->ob_pq, stream->deferred_data); + r = nghttp2_pq_push(&session->ob_pq, stream->deferred_data); if(r == 0) { - spdylay_stream_detach_deferred_data(stream); + nghttp2_stream_detach_deferred_data(stream); } return r; } -uint8_t spdylay_session_get_pri_lowest(spdylay_session *session) +uint8_t nghttp2_session_get_pri_lowest(nghttp2_session *session) { - if(session->version == SPDYLAY_PROTO_SPDY2) { - return SPDYLAY_PRI_LOWEST_SPDY2; - } else if(session->version == SPDYLAY_PROTO_SPDY3) { - return SPDYLAY_PRI_LOWEST_SPDY3; + if(session->version == NGHTTP2_PROTO_SPDY2) { + return NGHTTP2_PRI_LOWEST_SPDY2; + } else if(session->version == NGHTTP2_PROTO_SPDY3) { + return NGHTTP2_PRI_LOWEST_SPDY3; } else { return 0; } } -size_t spdylay_session_get_outbound_queue_size(spdylay_session *session) +size_t nghttp2_session_get_outbound_queue_size(nghttp2_session *session) { - return spdylay_pq_size(&session->ob_pq)+spdylay_pq_size(&session->ob_ss_pq); + return nghttp2_pq_size(&session->ob_pq)+nghttp2_pq_size(&session->ob_ss_pq); } -int spdylay_session_set_initial_client_cert_origin(spdylay_session *session, +int nghttp2_session_set_initial_client_cert_origin(nghttp2_session *session, const char *scheme, const char *host, uint16_t port) { - spdylay_origin *origin; + nghttp2_origin *origin; size_t slot; - if(strlen(scheme) > SPDYLAY_MAX_SCHEME || - strlen(host) > SPDYLAY_MAX_HOSTNAME) { - return SPDYLAY_ERR_INVALID_ARGUMENT; + if(strlen(scheme) > NGHTTP2_MAX_SCHEME || + strlen(host) > NGHTTP2_MAX_HOSTNAME) { + return NGHTTP2_ERR_INVALID_ARGUMENT; } if(session->server || (session->cli_certvec.size == 0 || session->cli_certvec.last_slot != 0)) { - return SPDYLAY_ERR_INVALID_STATE; + return NGHTTP2_ERR_INVALID_STATE; } - origin = malloc(sizeof(spdylay_origin)); + origin = malloc(sizeof(nghttp2_origin)); if(origin == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } strcpy(origin->scheme, scheme); strcpy(origin->host, host); origin->port = port; - slot = spdylay_client_cert_vector_put(&session->cli_certvec, origin); + slot = nghttp2_client_cert_vector_put(&session->cli_certvec, origin); assert(slot == 1); return 0; } -const spdylay_origin* spdylay_session_get_client_cert_origin -(spdylay_session *session, +const nghttp2_origin* nghttp2_session_get_client_cert_origin +(nghttp2_session *session, size_t slot) { - return spdylay_client_cert_vector_get_origin(&session->cli_certvec, slot); + return nghttp2_client_cert_vector_get_origin(&session->cli_certvec, slot); } -int spdylay_session_set_option(spdylay_session *session, +int nghttp2_session_set_option(nghttp2_session *session, int optname, void *optval, size_t optlen) { switch(optname) { - case SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE: + case NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE: if(optlen == sizeof(int)) { int intval = *(int*)optval; if(intval) { - session->opt_flags |= SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE; + session->opt_flags |= NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE; } else { - session->opt_flags &= ~SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE; + session->opt_flags &= ~NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE; } } else { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } break; - case SPDYLAY_OPT_MAX_RECV_CTRL_FRAME_BUFFER: + case NGHTTP2_OPT_MAX_RECV_CTRL_FRAME_BUFFER: if(optlen == sizeof(uint32_t)) { uint32_t intval = *(uint32_t*)optval; if((1 << 13) <= intval && intval < (1 << 24)) { session->max_recv_ctrl_frame_buf = intval; } else { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } } else { - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } break; default: - return SPDYLAY_ERR_INVALID_ARGUMENT; + return NGHTTP2_ERR_INVALID_ARGUMENT; } return 0; } diff --git a/lib/spdylay_session.h b/lib/nghttp2_session.h similarity index 67% rename from lib/spdylay_session.h rename to lib/nghttp2_session.h index 1a342c90..f0e2ab2e 100644 --- a/lib/spdylay_session.h +++ b/lib/nghttp2_session.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,47 +22,47 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_SESSION_H -#define SPDYLAY_SESSION_H +#ifndef NGHTTP2_SESSION_H +#define NGHTTP2_SESSION_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include -#include "spdylay_pq.h" -#include "spdylay_map.h" -#include "spdylay_frame.h" -#include "spdylay_zlib.h" -#include "spdylay_stream.h" -#include "spdylay_buffer.h" -#include "spdylay_outbound_item.h" -#include "spdylay_client_cert_vector.h" +#include +#include "nghttp2_pq.h" +#include "nghttp2_map.h" +#include "nghttp2_frame.h" +#include "nghttp2_zlib.h" +#include "nghttp2_stream.h" +#include "nghttp2_buffer.h" +#include "nghttp2_outbound_item.h" +#include "nghttp2_client_cert_vector.h" /** * @macro * Lowest priority value in SPDY/2, which is 3. */ -#define SPDYLAY_PRI_LOWEST_SPDY2 3 +#define NGHTTP2_PRI_LOWEST_SPDY2 3 /** * @macro * Lowest priority value in SPDY/3, which is 7. */ -#define SPDYLAY_PRI_LOWEST_SPDY3 7 +#define NGHTTP2_PRI_LOWEST_SPDY3 7 /* * Option flags. */ typedef enum { - SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0 -} spdylay_optmask; + NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0 +} nghttp2_optmask; typedef struct { - spdylay_outbound_item *item; + nghttp2_outbound_item *item; /* Buffer for outbound frames. Used to pack one frame. The memory pointed by framebuf is initially allocated by - spdylay_session_{client,server}_new() and deallocated by - spdylay_session_del() */ + nghttp2_session_{client,server}_new() and deallocated by + nghttp2_session_del() */ uint8_t *framebuf; /* The capacity of framebuf in bytes */ size_t framebufmax; @@ -70,48 +70,48 @@ typedef struct { size_t framebuflen; /* The number of bytes has been sent */ size_t framebufoff; -} spdylay_active_outbound_item; +} nghttp2_active_outbound_item; /* 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 SPDYLAY_INITIAL_INBOUND_FRAMEBUF_LENGTH \ - SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH -#define SPDYLAY_INITIAL_NV_BUFFER_LENGTH 4096 +#define NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH (NGHTTP2_DATA_PAYLOAD_LENGTH+8) +#define NGHTTP2_INITIAL_INBOUND_FRAMEBUF_LENGTH \ + NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH +#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 */ -#define SPDYLAY_INITIAL_CLIENT_CERT_VECTOR_LENGTH 8 +#define NGHTTP2_INITIAL_CLIENT_CERT_VECTOR_LENGTH 8 /* 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 */ typedef enum { /* Receiving frame header */ - SPDYLAY_RECV_HEAD, + NGHTTP2_RECV_HEAD, /* Receiving frame payload (comes after length field) */ - SPDYLAY_RECV_PAYLOAD, + NGHTTP2_RECV_PAYLOAD, /* 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 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 for SYN_STREAM, SYN_REPLY and HEADERS. */ - SPDYLAY_RECV_PAYLOAD_NV -} spdylay_inbound_state; + NGHTTP2_RECV_PAYLOAD_NV +} 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, 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 { - spdylay_inbound_state state; - uint8_t headbuf[SPDYLAY_HEAD_LEN]; + nghttp2_inbound_state state; + uint8_t headbuf[NGHTTP2_HEAD_LEN]; /* How many bytes are filled in headbuf */ size_t headbufoff; /* Payload for control frames. It is not used for DATA frames */ @@ -131,53 +131,53 @@ typedef struct { size_t off; /* Buffer used to store name/value pairs while inflating them using zlib on unpack */ - spdylay_buffer inflatebuf; + nghttp2_buffer inflatebuf; /* Error code */ int error_code; -} spdylay_inbound_frame; +} nghttp2_inbound_frame; typedef enum { - SPDYLAY_GOAWAY_NONE = 0, + NGHTTP2_GOAWAY_NONE = 0, /* 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. */ - SPDYLAY_GOAWAY_RECV = 0x2, + NGHTTP2_GOAWAY_RECV = 0x2, /* Flag means connection should be dropped after sending GOAWAY. */ - SPDYLAY_GOAWAY_FAIL_ON_SEND = 0x4 -} spdylay_goaway_flag; + NGHTTP2_GOAWAY_FAIL_ON_SEND = 0x4 +} nghttp2_goaway_flag; -struct spdylay_session { - /* The protocol version: either SPDYLAY_PROTO_SPDY2 or - SPDYLAY_PROTO_SPDY3 */ +struct nghttp2_session { + /* The protocol version: either NGHTTP2_PROTO_SPDY2 or + NGHTTP2_PROTO_SPDY3 */ uint16_t version; uint8_t server; /* Next Stream ID. Made unsigned int to detect >= (1 << 31). */ uint32_t next_stream_id; int32_t last_recv_stream_id; /* Counter of unique ID of PING. Wraps when it exceeds - SPDYLAY_MAX_UNIQUE_ID */ + NGHTTP2_MAX_UNIQUE_ID */ uint32_t next_unique_id; /* Sequence number of outbound frame to maintain the order of enqueue if priority is equal. */ int64_t next_seq; - spdylay_map /* */ streams; + nghttp2_map /* */ streams; /* 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; /* 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; /* Queue for outbound frames other than SYN_STREAM */ - spdylay_pq /* */ ob_pq; + nghttp2_pq /* */ ob_pq; /* Queue for outbound SYN_STREAM frame */ - spdylay_pq /* */ ob_ss_pq; + nghttp2_pq /* */ 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 temporarily on pack/unpack. */ @@ -185,14 +185,14 @@ struct spdylay_session { /* The number of bytes allocated for nvbuf */ size_t nvbuflen; - spdylay_zlib hd_deflater; - spdylay_zlib hd_inflater; + nghttp2_zlib hd_deflater; + nghttp2_zlib hd_inflater; /* The last unique ID sent to the peer. */ uint32_t last_ping_unique_id; /* 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; /* This is the value in GOAWAY frame sent by remote endpoint. */ int32_t last_good_stream_id; @@ -203,28 +203,28 @@ struct spdylay_session { /* Settings value received from the remote endpoint. We just use ID 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. */ - 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; /* Maxmum size of buffer to use when receving control frame. */ uint32_t max_recv_ctrl_frame_buf; /* 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; }; /* Struct used when updating initial window size of each active stream. */ typedef struct { - spdylay_session *session; + nghttp2_session *session; int32_t new_window_size, old_window_size; -} spdylay_update_window_size_arg; +} nghttp2_update_window_size_arg; /* TODO stream timeout etc */ @@ -232,15 +232,15 @@ typedef struct { * Returns nonzero value if |stream_id| is initiated by local * 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); /* * Adds frame |frame| to the outbound queue in |session|. The - * |frame_cat| must be either SPDYLAY_CTRL or SPDYLAY_DATA. If the - * |frame_cat| is SPDYLAY_CTRL, the |frame| must be a pointer to - * spdylay_frame. If the |frame_cat| is SPDYLAY_DATA, it must be a - * pointer to spdylay_data. |aux_data| is a pointer to the arbitrary + * |frame_cat| must be either NGHTTP2_CTRL or NGHTTP2_DATA. If the + * |frame_cat| is NGHTTP2_CTRL, the |frame| must be a pointer to + * nghttp2_frame. If the |frame_cat| is NGHTTP2_DATA, it must be a + * pointer to nghttp2_data. |aux_data| is a pointer to the arbitrary * data. Its interpretation is defined per the type of the frame. When * this function succeeds, it takes ownership of |frame| and * |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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_session_add_frame(spdylay_session *session, - spdylay_frame_category frame_cat, +int nghttp2_session_add_frame(nghttp2_session *session, + nghttp2_frame_category frame_cat, void *abs_frame, void *aux_data); /* * Adds RST_STREAM frame for the stream |stream_id| with status code * |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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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); /* * 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. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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| * and the status code |status_code|. The |status_code| is ignored if - * the protocol version is SPDYLAY_PROTO_SPDY2. This is a convenient - * function built on top of spdylay_session_add_frame() to add GOAWAY + * the protocol version is NGHTTP2_PROTO_SPDY2. This is a convenient + * function built on top of nghttp2_session_add_frame() to add GOAWAY * easily. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, uint32_t status_code); /* * Adds WINDOW_UPDATE frame with stream ID |stream_id| and * 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. * * This function returns 0 if it succeeds, or one of the following * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 delta_window_size); /* * 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 - * 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 * stream. Since this function is called when SYN_STREAM is sent or * 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 * NULL. */ -spdylay_stream* spdylay_session_open_stream(spdylay_session *session, +nghttp2_stream* nghttp2_session_open_stream(nghttp2_session *session, int32_t stream_id, uint8_t flags, uint8_t pri, - spdylay_stream_state initial_state, + nghttp2_stream_state initial_state, 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 * negative error codes: * - * SPDYLAY_ERR_INVALID_ARGUMENT + * NGHTTP2_ERR_INVALID_ARGUMENT * The specified stream does not exist. */ -int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id, - spdylay_status_code status_code); +int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, + nghttp2_status_code status_code); /* * Closes all pushed streams which associate them to stream * |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, - spdylay_status_code status_code); + nghttp2_status_code status_code); /* * 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 * succeeds, or one of the following negative error codes: * - * SPDYLAY_ERR_INVALID_ARGUMENT + * NGHTTP2_ERR_INVALID_ARGUMENT * The specified stream does not exist. */ -int spdylay_session_close_stream_if_shut_rdwr(spdylay_session *session, - spdylay_stream *stream); +int nghttp2_session_close_stream_if_shut_rdwr(nghttp2_session *session, + nghttp2_stream *stream); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_session_on_syn_stream_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_syn_stream_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_session_on_syn_reply_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_syn_reply_received(nghttp2_session *session, + nghttp2_frame *frame); /* @@ -406,8 +406,8 @@ int spdylay_session_on_syn_reply_received(spdylay_session *session, * * This function returns 0 and never fail. */ -int spdylay_session_on_rst_stream_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_rst_stream_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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. */ -int spdylay_session_on_settings_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_settings_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_session_on_ping_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_ping_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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. */ -int spdylay_session_on_goaway_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_goaway_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_session_on_headers_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_headers_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -int spdylay_session_on_window_update_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_window_update_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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. */ -int spdylay_session_on_credential_received(spdylay_session *session, - spdylay_frame *frame); +int nghttp2_session_on_credential_received(nghttp2_session *session, + nghttp2_frame *frame); /* * 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 * negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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, 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. */ -spdylay_stream* spdylay_session_get_stream(spdylay_session *session, +nghttp2_stream* nghttp2_session_get_stream(nghttp2_session *session, 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 * one of the following negative error codes: * - * SPDYLAY_ERR_DEFERRED + * NGHTTP2_ERR_DEFERRED * The DATA frame is postponed. - * SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE + * NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE * The read_callback failed (stream error). - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. - * SPDYLAY_ERR_CALLBACK_FAILURE + * NGHTTP2_ERR_CALLBACK_FAILURE * 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, size_t datamax, - spdylay_data *frame); + nghttp2_data *frame); /* * 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 * 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, @@ -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, * then this function returns NULL. */ -spdylay_outbound_item* spdylay_session_pop_next_ob_item -(spdylay_session *session); +nghttp2_outbound_item* nghttp2_session_pop_next_ob_item +(nghttp2_session *session); /* * 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, * then this function returns NULL. */ -spdylay_outbound_item* spdylay_session_get_next_ob_item -(spdylay_session *session); +nghttp2_outbound_item* nghttp2_session_get_next_ob_item +(nghttp2_session *session); /* * Updates local settings with the |iv|. The number of elements in the * 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 - * SPDYLAY_SETTINGS_MAX, inclusive. + * NGHTTP2_SETTINGS_MAX, inclusive. */ -void spdylay_session_update_local_settings(spdylay_session *session, - spdylay_settings_entry *iv, +void nghttp2_session_update_local_settings(nghttp2_session *session, + nghttp2_settings_entry *iv, 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 * client certificate is required, return 0. If CREDENTIAL frame needs * 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 * following negative error codes: * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. - * SPDYLAY_ERR_CREDENTIAL_PENDING + * NGHTTP2_ERR_CREDENTIAL_PENDING * The CREDENTIAL frame must be sent before the |syn_stream|. */ -int spdylay_session_prep_credential(spdylay_session *session, - spdylay_syn_stream *syn_stream); +int nghttp2_session_prep_credential(nghttp2_session *session, + nghttp2_syn_stream *syn_stream); -#endif /* SPDYLAY_SESSION_H */ +#endif /* NGHTTP2_SESSION_H */ diff --git a/lib/spdylay_stream.c b/lib/nghttp2_stream.c similarity index 75% rename from lib/spdylay_stream.c rename to lib/nghttp2_stream.c index fd047e74..95d6d523 100644 --- a/lib/spdylay_stream.c +++ b/lib/nghttp2_stream.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,45 +22,45 @@ * 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_stream.h" +#include "nghttp2_stream.h" #include -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, - spdylay_stream_state initial_state, + nghttp2_stream_state initial_state, int32_t initial_window_size, 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->flags = flags; stream->pri = pri; stream->state = initial_state; - stream->shut_flags = SPDYLAY_SHUT_NONE; + stream->shut_flags = NGHTTP2_SHUT_NONE; stream->pushed_streams = NULL; stream->pushed_streams_length = 0; stream->pushed_streams_capacity = 0; stream->stream_user_data = stream_user_data; stream->deferred_data = NULL; - stream->deferred_flags = SPDYLAY_DEFERRED_NONE; + stream->deferred_flags = NGHTTP2_DEFERRED_NONE; stream->window_size = initial_window_size; stream->recv_window_size = 0; } -void spdylay_stream_free(spdylay_stream *stream) +void nghttp2_stream_free(nghttp2_stream *stream) { free(stream->pushed_streams); - spdylay_outbound_item_free(stream->deferred_data); + nghttp2_outbound_item_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; } -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) { 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; streams = realloc(stream->pushed_streams, capacity*sizeof(uint32_t)); if(streams == NULL) { - return SPDYLAY_ERR_NOMEM; + return NGHTTP2_ERR_NOMEM; } stream->pushed_streams = streams; stream->pushed_streams_capacity = capacity; @@ -77,8 +77,8 @@ int spdylay_stream_add_pushed_stream(spdylay_stream *stream, int32_t stream_id) return 0; } -void spdylay_stream_defer_data(spdylay_stream *stream, - spdylay_outbound_item *data, +void nghttp2_stream_defer_data(nghttp2_stream *stream, + nghttp2_outbound_item *data, uint8_t flags) { assert(stream->deferred_data == NULL); @@ -86,13 +86,13 @@ void spdylay_stream_defer_data(spdylay_stream *stream, 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_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 old_initial_window_size) { diff --git a/lib/spdylay_stream.h b/lib/nghttp2_stream.h similarity index 69% rename from lib/spdylay_stream.h rename to lib/nghttp2_stream.h index e6a820f9..9a6be542 100644 --- a/lib/spdylay_stream.h +++ b/lib/nghttp2_stream.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,71 +22,71 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_STREAM_H -#define SPDYLAY_STREAM_H +#ifndef NGHTTP2_STREAM_H +#define NGHTTP2_STREAM_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include -#include "spdylay_outbound_item.h" -#include "spdylay_map.h" +#include +#include "nghttp2_outbound_item.h" +#include "nghttp2_map.h" /* * If local peer is stream initiator: - * SPDYLAY_STREAM_OPENING : upon sending SYN_STREAM - * SPDYLAY_STREAM_OPENED : upon receiving SYN_REPLY - * SPDYLAY_STREAM_CLOSING : upon queuing RST_STREAM + * NGHTTP2_STREAM_OPENING : upon sending SYN_STREAM + * NGHTTP2_STREAM_OPENED : upon receiving SYN_REPLY + * NGHTTP2_STREAM_CLOSING : upon queuing RST_STREAM * * If remote peer is stream initiator: - * SPDYLAY_STREAM_OPENING : upon receiving SYN_STREAM - * SPDYLAY_STREAM_OPENED : upon sending SYN_REPLY - * SPDYLAY_STREAM_CLOSING : upon queuing RST_STREAM + * NGHTTP2_STREAM_OPENING : upon receiving SYN_STREAM + * NGHTTP2_STREAM_OPENED : upon sending SYN_REPLY + * NGHTTP2_STREAM_CLOSING : upon queuing RST_STREAM */ typedef enum { /* Initial state */ - SPDYLAY_STREAM_INITIAL, + NGHTTP2_STREAM_INITIAL, /* For stream initiator: SYN_STREAM has been sent, but SYN_REPLY is not received yet. For receiver: SYN_STREAM has been received, but it does not send SYN_REPLY yet. */ - SPDYLAY_STREAM_OPENING, + NGHTTP2_STREAM_OPENING, /* For stream initiator: SYN_REPLY is received. For receiver: SYN_REPLY is sent. */ - SPDYLAY_STREAM_OPENED, + NGHTTP2_STREAM_OPENED, /* RST_STREAM is received, but somehow we need to keep stream in memory. */ - SPDYLAY_STREAM_CLOSING -} spdylay_stream_state; + NGHTTP2_STREAM_CLOSING +} nghttp2_stream_state; typedef enum { - SPDYLAY_SHUT_NONE = 0, + NGHTTP2_SHUT_NONE = 0, /* Indicates further receptions will be disallowed. */ - SPDYLAY_SHUT_RD = 0x01, + NGHTTP2_SHUT_RD = 0x01, /* Indicates further transmissions will be disallowed. */ - SPDYLAY_SHUT_WR = 0x02, + NGHTTP2_SHUT_WR = 0x02, /* Indicates both further receptions and transmissions will be disallowed. */ - SPDYLAY_SHUT_RDWR = SPDYLAY_SHUT_RD | SPDYLAY_SHUT_WR -} spdylay_shut_flag; + NGHTTP2_SHUT_RDWR = NGHTTP2_SHUT_RD | NGHTTP2_SHUT_WR +} nghttp2_shut_flag; typedef enum { - SPDYLAY_DEFERRED_NONE = 0, + NGHTTP2_DEFERRED_NONE = 0, /* Indicates the DATA is deferred due to flow control. */ - SPDYLAY_DEFERRED_FLOW_CONTROL = 0x01 -} spdylay_deferred_flag; + NGHTTP2_DEFERRED_FLOW_CONTROL = 0x01 +} nghttp2_deferred_flag; typedef struct { /* Intrusive Map */ - spdylay_map_entry map_entry; + nghttp2_map_entry map_entry; /* stream ID */ int32_t stream_id; - spdylay_stream_state state; + nghttp2_stream_state state; /* Use same value in SYN_STREAM frame */ uint8_t flags; /* Use same scheme in SYN_STREAM frame */ 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; /* The array of server-pushed stream IDs which associate them to this stream. */ @@ -99,9 +99,9 @@ typedef struct { /* The arbitrary data provided by user for this stream. */ void *stream_user_data; /* Deferred DATA frame */ - spdylay_outbound_item *deferred_data; + nghttp2_outbound_item *deferred_data; /* The flags for defered DATA. Bitwise OR of zero or more - spdylay_deferred_flag values */ + nghttp2_deferred_flag values */ uint8_t deferred_flags; /* Current sender window size. This value is computed against the current initial window size of remote endpoint. */ @@ -109,21 +109,21 @@ typedef struct { /* Keep track of the number of bytes received without WINDOW_UPDATE. */ 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, - spdylay_stream_state initial_state, + nghttp2_stream_state initial_state, int32_t initial_window_size, 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. - * |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 @@ -133,33 +133,33 @@ void spdylay_stream_shutdown(spdylay_stream *stream, spdylay_shut_flag flag); * RETURN VALUE * ------------ * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * 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 * 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, - spdylay_outbound_item *data, +void nghttp2_stream_defer_data(nghttp2_stream *stream, + nghttp2_outbound_item *data, uint8_t flags); /* * Detaches deferred data from this stream. This function does not * 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 * |new_initial_window_size|. The |old_initial_window_size| is used to * 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 old_initial_window_size); -#endif /* SPDYLAY_STREAM */ +#endif /* NGHTTP2_STREAM */ diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c new file mode 100644 index 00000000..46b31cfc --- /dev/null +++ b/lib/nghttp2_submit.c @@ -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 + +#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; +} diff --git a/lib/spdylay_submit.h b/lib/nghttp2_submit.h similarity index 89% rename from lib/spdylay_submit.h rename to lib/nghttp2_submit.h index b7bad410..c8478366 100644 --- a/lib/spdylay_submit.h +++ b/lib/nghttp2_submit.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,13 +22,13 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_SUBMIT_H -#define SPDYLAY_SUBMIT_H +#ifndef NGHTTP2_SUBMIT_H +#define NGHTTP2_SUBMIT_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include +#include -#endif /* SPDYLAY_SUBMIT_H */ +#endif /* NGHTTP2_SUBMIT_H */ diff --git a/lib/spdylay_zlib.c b/lib/nghttp2_zlib.c similarity index 92% rename from lib/spdylay_zlib.c rename to lib/nghttp2_zlib.c index 445c5edc..7029f9fa 100644 --- a/lib/spdylay_zlib.c +++ b/lib/nghttp2_zlib.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,7 +22,7 @@ * 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_zlib.h" +#include "nghttp2_zlib.h" #include @@ -226,21 +226,21 @@ static const uint8_t spdy3_hd_dict[] = { 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; hd_dict = NULL; - if(version == SPDYLAY_PROTO_SPDY2) { + if(version == NGHTTP2_PROTO_SPDY2) { hd_dict = (const uint8_t*)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; *len_ptr = sizeof(spdy3_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) { 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.opaque = Z_NULL; 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) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } if(Z_OK != deflateInit2(&deflater->zst, comp ? COMPRESSION_LEVEL : Z_NO_COMPRESSION, Z_DEFLATED, WINDOW_BITS, MEM_LEVEL, Z_DEFAULT_STRATEGY)) { - return SPDYLAY_ERR_ZLIB; + return NGHTTP2_ERR_ZLIB; } if(Z_OK != deflateSetDictionary(&deflater->zst, (uint8_t*)hd_dict, hd_dict_length)) { - spdylay_zlib_deflate_free(deflater); - return SPDYLAY_ERR_ZLIB; + nghttp2_zlib_deflate_free(deflater); + return NGHTTP2_ERR_ZLIB; } 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; 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.opaque = Z_NULL; 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) { - return SPDYLAY_ERR_UNSUPPORTED_VERSION; + return NGHTTP2_ERR_UNSUPPORTED_VERSION; } if(Z_OK != inflateInit(&inflater->zst)) { - return SPDYLAY_ERR_ZLIB; + return NGHTTP2_ERR_ZLIB; } return 0; } -void spdylay_zlib_deflate_free(spdylay_zlib *deflater) +void nghttp2_zlib_deflate_free(nghttp2_zlib *deflater) { deflateEnd(&deflater->zst); } -void spdylay_zlib_inflate_free(spdylay_zlib *inflater) +void nghttp2_zlib_inflate_free(nghttp2_zlib *inflater) { 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, const uint8_t *in, size_t inlen) { @@ -311,51 +311,51 @@ ssize_t spdylay_zlib_deflate_hd(spdylay_zlib *deflater, if(r == Z_OK) { return outlen-deflater->zst.avail_out; } 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); } -ssize_t spdylay_zlib_inflate_hd(spdylay_zlib *inflater, - spdylay_buffer* buf, +ssize_t nghttp2_zlib_inflate_hd(nghttp2_zlib *inflater, + nghttp2_buffer* buf, const uint8_t *in, size_t inlen) { int r; inflater->zst.avail_in = inlen; inflater->zst.next_in = (uint8_t*)in; while(1) { - if(spdylay_buffer_avail(buf) == 0) { - if((r = spdylay_buffer_alloc(buf)) != 0) { + if(nghttp2_buffer_avail(buf) == 0) { + if((r = nghttp2_buffer_alloc(buf)) != 0) { return r; } } - inflater->zst.avail_out = spdylay_buffer_avail(buf); - inflater->zst.next_out = spdylay_buffer_get(buf); + inflater->zst.avail_out = nghttp2_buffer_avail(buf); + inflater->zst.next_out = nghttp2_buffer_get(buf); r = inflate(&inflater->zst, Z_NO_FLUSH); 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) { const uint8_t *hd_dict; 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); if(Z_OK != inflateSetDictionary(&inflater->zst, (uint8_t*)hd_dict, hd_dict_length)) { - return SPDYLAY_ERR_ZLIB; + return NGHTTP2_ERR_ZLIB; } } else { if(r == Z_OK) { - size_t adv = spdylay_buffer_avail(buf)-inflater->zst.avail_out; - spdylay_buffer_advance(buf, adv); + size_t adv = nghttp2_buffer_avail(buf)-inflater->zst.avail_out; + nghttp2_buffer_advance(buf, adv); } if(inflater->zst.avail_in == 0 && inflater->zst.avail_out > 0) { break; } } } - return spdylay_buffer_length(buf); + return nghttp2_buffer_length(buf); } diff --git a/lib/spdylay_zlib.h b/lib/nghttp2_zlib.h similarity index 78% rename from lib/spdylay_zlib.h rename to lib/nghttp2_zlib.h index f1e0d636..cc802d6a 100644 --- a/lib/spdylay_zlib.h +++ b/lib/nghttp2_zlib.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,22 +22,22 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_ZLIB_H -#define SPDYLAY_ZLIB_H +#ifndef NGHTTP2_ZLIB_H +#define NGHTTP2_ZLIB_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include -#include "spdylay_buffer.h" +#include "nghttp2_buffer.h" /* This structure is used for both deflater and inflater. */ typedef struct { z_stream zst; /* The protocol version to select the dictionary later. */ uint16_t version; -} spdylay_zlib; +} nghttp2_zlib; /* * 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 * negative error codes: * - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The z_stream initialization failed. - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * 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); /* @@ -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 * negative error codes: * - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The z_stream initialization failed. - * SPDYLAY_ERR_UNSUPPORTED_VERSION + * NGHTTP2_ERR_UNSUPPORTED_VERSION * 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|. */ -void spdylay_zlib_deflate_free(spdylay_zlib *deflater); +void nghttp2_zlib_deflate_free(nghttp2_zlib *deflater); /* * 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 * |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 * written to |out| with length |outlen|. This is not a strict * 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. * * This function returns the number of bytes outputted if it succeeds, * or one of the following negative error codes: * - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * 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, 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, * or one of the following negative error codes: * - * SPDYLAY_ERR_ZLIB + * NGHTTP2_ERR_ZLIB * The inflate operation failed. * - * SPDYLAY_ERR_NOMEM + * NGHTTP2_ERR_NOMEM * Out of memory. */ -ssize_t spdylay_zlib_inflate_hd(spdylay_zlib *inflater, - spdylay_buffer* buf, +ssize_t nghttp2_zlib_inflate_hd(nghttp2_zlib *inflater, + nghttp2_buffer* buf, const uint8_t *in, size_t inlen); -#endif /* SPDYLAY_ZLIB_H */ +#endif /* NGHTTP2_ZLIB_H */ diff --git a/lib/spdylay_submit.c b/lib/spdylay_submit.c deleted file mode 100644 index 3ac1bf66..00000000 --- a/lib/spdylay_submit.c +++ /dev/null @@ -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 - -#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; -} diff --git a/python/MANIFEST.in b/python/MANIFEST.in deleted file mode 100644 index 15e924f2..00000000 --- a/python/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include spdylay.pyx cspdylay.pxd spdylay_tests.py spdyclient.py spdyserv.py README.rst diff --git a/python/Makefile.am b/python/Makefile.am deleted file mode 100644 index fd503a51..00000000 --- a/python/Makefile.am +++ /dev/null @@ -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 diff --git a/python/README.rst b/python/README.rst deleted file mode 100644 index 70772313..00000000 --- a/python/README.rst +++ /dev/null @@ -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 -`_ -or `clone git repository `_. - -See `Spdylay documentation -`_ 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 -`_. - -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 = '''\ - - SPDY FTW - -

SPDY FTW

-

The age of HTTP/1.1 is over. The time of SPDY has come.

- - '''.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) diff --git a/python/cspdylay.pxd b/python/cspdylay.pxd deleted file mode 100644 index f6662afc..00000000 --- a/python/cspdylay.pxd +++ /dev/null @@ -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) diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index 9d52327e..00000000 --- a/python/setup.py +++ /dev/null @@ -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 -`_ -or `clone git repository `_. - -See `Spdylay documentation -`_ 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 -`_. - -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 = '''\\ - - SPDY FTW - -

SPDY FTW

-

The age of HTTP/1.1 is over. The time of SPDY has come.

- - '''.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' - ] - ) diff --git a/python/spdyclient.py b/python/spdyclient.py deleted file mode 100644 index 8cdbf8f9..00000000 --- a/python/spdyclient.py +++ /dev/null @@ -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) diff --git a/python/spdylay.pyx b/python/spdylay.pyx deleted file mode 100644 index c3678ae1..00000000 --- a/python/spdylay.pyx +++ /dev/null @@ -1,1684 +0,0 @@ -cimport cspdylay - -from libc.stdlib cimport malloc, free -from libc.string cimport memcpy, memset -from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t - -# Also update version in setup.py -__version__ = '0.1.2' - -class EOFError(Exception): - pass - -class CallbackFailureError(Exception): - pass - -class TemporalCallbackFailureError(Exception): - pass - -class InvalidArgumentError(Exception): - pass - -class ZlibError(Exception): - pass - -class UnsupportedVersionError(Exception): - pass - -class StreamClosedError(Exception): - pass - -class DataProvider: - def __init__(self, source, read_cb): - self.source = source - self.read_cb = read_cb - -cdef class CtrlFrame: - cdef uint16_t version - cdef uint16_t frame_type - cdef uint8_t flags - cdef int32_t length - - cdef void fillhd(self, cspdylay.spdylay_ctrl_hd *hd): - self.version = hd.version - self.frame_type = hd.type - self.flags = hd.flags - self.length = hd.length - - property version: - def __get__(self): - return self.version - - property frame_type: - def __get__(self): - return self.frame_type - - property flags: - def __get__(self): - return self.flags - - property length: - def __get__(self): - return self.length - -cdef class SynStreamFrame(CtrlFrame): - cdef int32_t stream_id - cdef int32_t assoc_stream_id - cdef uint8_t pri - cdef uint8_t slot - cdef object nv - - cdef fill(self, cspdylay.spdylay_syn_stream *frame): - self.fillhd(&frame.hd) - - self.stream_id = frame.stream_id - self.assoc_stream_id = frame.assoc_stream_id - self.pri = frame.pri - self.slot = frame.slot - self.nv = cnv2pynv(frame.nv) - - property stream_id: - def __get__(self): - return self.stream_id - - property assoc_stream_id: - def __get__(self): - return self.assoc_stream_id - - property pri: - def __get__(self): - return self.pri - - property nv: - def __get__(self): - return self.nv - -cdef class SynReplyFrame(CtrlFrame): - cdef int32_t stream_id - cdef object nv - - cdef fill(self, cspdylay.spdylay_syn_reply *frame): - self.fillhd(&frame.hd) - - self.stream_id = frame.stream_id - self.nv = cnv2pynv(frame.nv) - - property stream_id: - def __get__(self): - return self.stream_id - property nv: - def __get__(self): - return self.nv - -cdef class HeadersFrame(CtrlFrame): - cdef int32_t stream_id - cdef object nv - - cdef fill(self, cspdylay.spdylay_headers *frame): - self.fillhd(&frame.hd) - - self.stream_id = frame.stream_id - self.nv = cnv2pynv(frame.nv) - - property stream_id: - def __get__(self): - return self.stream_id - - property nv: - def __get__(self): - return self.nv - -cdef class RstStreamFrame(CtrlFrame): - cdef int32_t stream_id - cdef uint32_t status_code - - cdef fill(self, cspdylay.spdylay_rst_stream *frame): - self.fillhd(&frame.hd) - - self.stream_id = frame.stream_id - self.status_code = frame.status_code - - property stream_id: - def __get__(self): - return self.stream_id - - property status_code: - def __get__(self): - return self.status_code - -cdef class SettingsFrame(CtrlFrame): - cdef object iv - - cdef fill(self, cspdylay.spdylay_settings *frame): - self.fillhd(&frame.hd) - - self.iv = csettings2pysettings(frame.niv, frame.iv) - - - property iv: - def __get__(self): - return self.iv - -cdef class PingFrame(CtrlFrame): - cdef uint32_t unique_id - - cdef fill(self, cspdylay.spdylay_ping *frame): - self.fillhd(&frame.hd) - - self.unique_id = frame.unique_id - - property unique_id: - def __get__(self): - return self.unique_id - -cdef class GoawayFrame(CtrlFrame): - cdef int32_t last_good_stream_id - cdef uint32_t status_code - - cdef fill(self, cspdylay.spdylay_goaway *frame): - self.fillhd(&frame.hd) - - self.last_good_stream_id = frame.last_good_stream_id - self.status_code = frame.status_code - - property last_good_stream_id: - def __get__(self): - return self.last_good_stream_id - - property status_code: - def __get__(self): - return self.status_code - -cdef class WindowUpdateFrame(CtrlFrame): - cdef int32_t stream_id - cdef int32_t delta_window_size - - cdef fill(self, cspdylay.spdylay_window_update *frame): - self.fillhd(&frame.hd) - - self.stream_id = frame.stream_id - self.delta_window_size = frame.delta_window_size - - property stream_id: - def __get__(self): - return self.stream_id - - property delta_window_size: - def __get__(self): - return self.delta_window_size - -cdef cnv2pynv(char **nv): - ''' Convert C-style name/value pairs ``nv`` to Python style - pairs. We assume that strings in nv is UTF-8 encoded as per SPDY - spec. In Python pairs, we use unicode string.''' - cdef size_t i - pynv = [] - i = 0 - while nv[i] != NULL: - pynv.append((nv[i].decode('UTF-8'), nv[i+1].decode('UTF-8'))) - i += 2 - return pynv - -cdef char** pynv2cnv(object nv) except *: - ''' Convert Python style UTF-8 name/value pairs ``nv`` to C-style - pairs. Python style name/value pairs are list of tuple (key, - value).''' - cdef char **cnv = malloc((len(nv)*2+1)*sizeof(char*)) - cdef size_t i - if cnv == NULL: - raise MemoryError() - i = 0 - for n, v in nv: - cnv[i] = n - i += 1 - cnv[i] = v - i += 1 - cnv[i] = NULL - return cnv - -cdef pynv_encode(nv): - res = [] - for k, v in nv: - res.append((k.encode('UTF-8'), v.encode('UTF-8'))) - return res - -cdef object csettings2pysettings(size_t niv, - cspdylay.spdylay_settings_entry *iv): - cdef size_t i = 0 - cdef cspdylay.spdylay_settings_entry *ent - res = [] - while i < niv: - ent = &iv[i] - res.append((ent.settings_id, ent.flags, ent.value)) - i += 1 - return res - -cdef cspdylay.spdylay_settings_entry* pysettings2csettings(object iv) except *: - cdef size_t i - cdef cspdylay.spdylay_settings_entry *civ =\ - malloc(\ - len(iv)*sizeof(cspdylay.spdylay_settings_entry)) - if civ == NULL: - raise MemoryError() - i = 0 - for settings_id, flags, value in iv: - civ[i].settings_id = settings_id - civ[i].flags = flags - civ[i].value = value - i += 1 - return civ - -cdef cspdylay.spdylay_data_provider create_c_data_prd\ -(cspdylay.spdylay_data_provider *cdata_prd, object pydata_prd): - cdata_prd.source.ptr = pydata_prd - cdata_prd.read_callback = read_callback - - -cdef object cframe2pyframe(cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame): - cdef SynStreamFrame syn_stream - cdef SynReplyFrame syn_reply - cdef HeadersFrame headers - cdef RstStreamFrame rst_stream - cdef SettingsFrame settings - cdef PingFrame ping - cdef GoawayFrame goaway - cdef WindowUpdateFrame window_update - cdef object pyframe = None - if frame_type == cspdylay.SPDYLAY_SYN_STREAM: - syn_stream = SynStreamFrame() - syn_stream.fill(&frame.syn_stream) - pyframe = syn_stream - elif frame_type == cspdylay.SPDYLAY_SYN_REPLY: - syn_reply = SynReplyFrame() - syn_reply.fill(&frame.syn_reply) - pyframe = syn_reply - elif frame_type == cspdylay.SPDYLAY_HEADERS: - headers = HeadersFrame() - headers.fill(&frame.headers) - pyframe = headers - elif frame_type == cspdylay.SPDYLAY_RST_STREAM: - rst_stream = RstStreamFrame() - rst_stream.fill(&frame.rst_stream) - pyframe = rst_stream - elif frame_type == cspdylay.SPDYLAY_SETTINGS: - settings = SettingsFrame() - settings.fill(&frame.settings) - pyframe = settings - elif frame_type == cspdylay.SPDYLAY_PING: - ping = PingFrame() - ping.fill(&frame.ping) - pyframe = ping - elif frame_type == cspdylay.SPDYLAY_GOAWAY: - goaway = GoawayFrame() - goaway.fill(&frame.goaway) - pyframe = goaway - elif frame_type == cspdylay.SPDYLAY_WINDOW_UPDATE: - window_update = WindowUpdateFrame() - window_update.fill(&frame.window_update) - pyframe = window_update - return pyframe - -cdef void _call_frame_callback(Session pysession, - cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame, - object callback): - if not callback: - return - try: - pyframe = cframe2pyframe(frame_type, frame) - if pyframe: - callback(pysession, pyframe) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_ctrl_recv_callback(cspdylay.spdylay_session *session, - cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame, - void *user_data): - cdef Session pysession = user_data - _call_frame_callback(pysession, frame_type, frame, - pysession.on_ctrl_recv_cb) - -cdef void on_invalid_ctrl_recv_callback(cspdylay.spdylay_session *session, - cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame, - uint32_t status_code, - void *user_data): - cdef Session pysession = user_data - - if not pysession.on_invalid_ctrl_recv_cb: - return - try: - pyframe = cframe2pyframe(frame_type, frame) - if pyframe: - pysession.on_invalid_ctrl_recv_cb(pysession, pyframe, status_code) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void before_ctrl_send_callback(cspdylay.spdylay_session *session, - cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame, - void *user_data): - cdef Session pysession = user_data - _call_frame_callback(pysession, frame_type, frame, - pysession.before_ctrl_send_cb) - -cdef void on_ctrl_send_callback(cspdylay.spdylay_session *session, - cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame, - void *user_data): - cdef Session pysession = user_data - _call_frame_callback(pysession, frame_type, frame, - pysession.on_ctrl_send_cb) - -cdef void on_ctrl_not_send_callback(cspdylay.spdylay_session *session, - cspdylay.spdylay_frame_type frame_type, - cspdylay.spdylay_frame *frame, - int error_code, - void *user_data): - cdef Session pysession = user_data - - if not pysession.on_ctrl_not_send_cb: - return - try: - pyframe = cframe2pyframe(frame_type, frame) - if pyframe: - pysession.on_ctrl_not_send_cb(pysession, pyframe, error_code) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_ctrl_recv_parse_error_callback(\ - cspdylay.spdylay_session *session, - cspdylay.spdylay_frame_type frame_type, - uint8_t *head, size_t headlen, - uint8_t *payload, size_t payloadlen, - int error_code, void *user_data): - cdef Session pysession = user_data - - if not pysession.on_ctrl_recv_parse_error_cb: - return - try: - pysession.on_ctrl_recv_parse_error_cb(pysession, frame_type, - (head)[:headlen], - (payload)[:payloadlen], - error_code) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_unknown_ctrl_recv_callback(cspdylay.spdylay_session *session, - uint8_t *head, size_t headlen, - uint8_t *payload, size_t payloadlen, - void *user_data): - cdef Session pysession = user_data - - if not pysession.on_unknown_ctrl_recv_cb: - return - try: - pysession.on_unknown_ctrl_recv_cb(pysession, - (head)[:headlen], - (payload)[:payloadlen]) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef ssize_t recv_callback(cspdylay.spdylay_session *session, - uint8_t *buf, size_t length, - int flags, void *user_data): - cdef Session pysession = user_data - if pysession.recv_callback: - try: - data = pysession.recv_callback(pysession, length) - except EOFError as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_EOF - except CallbackFailureError as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - except Exception as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - except BaseException as e: - pysession.base_error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - if data: - if len(data) > length: - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - memcpy(buf, data, len(data)) - return len(data) - else: - return cspdylay.SPDYLAY_ERR_WOULDBLOCK - else: - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - -cdef ssize_t send_callback(cspdylay.spdylay_session *session, - uint8_t *data, size_t length, int flags, - void *user_data): - cdef Session pysession = user_data - if pysession.send_callback: - try: - rv = pysession.send_callback(pysession, (data)[:length]) - except CallbackFailureError as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - except Exception as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - except BaseException as e: - pysession.base_error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - - if rv: - return rv - else: - return cspdylay.SPDYLAY_ERR_WOULDBLOCK - else: - # If no send_callback is given, pretend all data were sent and - # just return length - return length - -cdef void on_data_chunk_recv_callback(cspdylay.spdylay_session *session, - uint8_t flags, int32_t stream_id, - uint8_t *data, size_t length, - void *user_data): - cdef Session pysession = user_data - if pysession.on_data_chunk_recv_cb: - try: - pysession.on_data_chunk_recv_cb(pysession, flags, stream_id, - (data)[:length]) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_data_recv_callback(cspdylay.spdylay_session *session, - uint8_t flags, int32_t stream_id, - int32_t length, void *user_data): - cdef Session pysession = user_data - if pysession.on_data_recv_cb: - try: - pysession.on_data_recv_cb(pysession, flags, stream_id, length) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_data_send_callback(cspdylay.spdylay_session *session, - uint8_t flags, int32_t stream_id, - int32_t length, void *user_data): - cdef Session pysession = user_data - if pysession.on_data_send_cb: - try: - pysession.on_data_send_cb(pysession, flags, stream_id, length) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_stream_close_callback(cspdylay.spdylay_session *session, - int32_t stream_id, - cspdylay.spdylay_status_code status_code, - void *user_data): - cdef Session pysession = user_data - if pysession.on_stream_close_cb: - try: - pysession.on_stream_close_cb(pysession, stream_id, status_code) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef void on_request_recv_callback(cspdylay.spdylay_session *session, - int32_t stream_id, - void *user_data): - cdef Session pysession = user_data - if pysession.on_request_recv_cb: - try: - pysession.on_request_recv_cb(pysession, stream_id) - except Exception as e: - pysession.error = e - except BaseException as e: - pysession.base_error = e - -cdef class ReadCtrl: - cdef int flags - - def __cinit__(self): - self.flags = 0 - - property flags: - def __set__(self, value): - self.flags = value - -cdef ssize_t read_callback(cspdylay.spdylay_session *session, - int32_t stream_id, uint8_t *buf, size_t length, - int *eof, cspdylay.spdylay_data_source *source, - void *user_data): - cdef Session pysession = user_data - cdef ReadCtrl read_ctrl = ReadCtrl() - data_prd = source.ptr - - try: - res = data_prd.read_cb(pysession, stream_id, length, read_ctrl, - data_prd.source) - except TemporalCallbackFailureError as e: - return cspdylay.SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE - except CallbackFailureError as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - except Exception as e: - pysession.error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - except BaseException as e: - pysession.base_error = e - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - - if read_ctrl.flags & READ_EOF: - eof[0] = 1 - if res == cspdylay.SPDYLAY_ERR_DEFERRED: - return res - elif res: - if len(res) > length: - return cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - memcpy(buf, res, len(res)) - return len(res) - else: - return 0 - -cdef class Session: - cdef cspdylay.spdylay_session *_c_session - cdef object recv_callback - cdef object send_callback - cdef object on_ctrl_recv_cb - cdef object on_invalid_ctrl_recv_cb - cdef object on_data_chunk_recv_cb - cdef object on_data_recv_cb - cdef object before_ctrl_send_cb - cdef object on_ctrl_send_cb - cdef object on_ctrl_not_send_cb - cdef object on_data_send_cb - cdef object on_stream_close_cb - cdef object on_request_recv_cb - cdef object on_ctrl_recv_parse_error_cb - cdef object on_unknown_ctrl_recv_cb - cdef object user_data - - cdef object error - cdef object base_error - - property user_data: - def __get__(self): - return self.user_data - - def __cinit__(self, side, version, config=None, - send_cb=None, recv_cb=None, - on_ctrl_recv_cb=None, - on_invalid_ctrl_recv_cb=None, - on_data_chunk_recv_cb=None, - on_data_recv_cb=None, - before_ctrl_send_cb=None, - on_ctrl_send_cb=None, - on_ctrl_not_send_cb=None, - on_data_send_cb=None, - on_stream_close_cb=None, - on_request_recv_cb=None, - on_ctrl_recv_parse_error_cb=None, - on_unknown_ctrl_recv_cb=None, - user_data=None): - cdef cspdylay.spdylay_session_callbacks c_session_callbacks - cdef int rv - self._c_session = NULL - memset(&c_session_callbacks, 0, sizeof(c_session_callbacks)) - c_session_callbacks.recv_callback = \ - recv_callback - c_session_callbacks.send_callback = \ - send_callback - c_session_callbacks.on_ctrl_recv_callback = \ - on_ctrl_recv_callback - c_session_callbacks.on_invalid_ctrl_recv_callback = \ - \ - on_invalid_ctrl_recv_callback - c_session_callbacks.on_data_chunk_recv_callback = \ - \ - on_data_chunk_recv_callback - c_session_callbacks.on_data_recv_callback = \ - on_data_recv_callback - c_session_callbacks.before_ctrl_send_callback = \ - \ - before_ctrl_send_callback - c_session_callbacks.on_ctrl_send_callback = \ - on_ctrl_send_callback - c_session_callbacks.on_ctrl_not_send_callback = \ - \ - on_ctrl_not_send_callback - c_session_callbacks.on_data_send_callback = \ - on_data_send_callback - c_session_callbacks.on_stream_close_callback = \ - on_stream_close_callback - c_session_callbacks.on_request_recv_callback = \ - on_request_recv_callback - # c_session_callbacks.get_credential_proof = NULL - # c_session_callbacks.get_credential_ncerts = NULL - # c_session_callbacks.get_credential_cert = NULL - c_session_callbacks.on_ctrl_recv_parse_error_callback = \ - \ - on_ctrl_recv_parse_error_callback - c_session_callbacks.on_unknown_ctrl_recv_callback = \ - \ - on_unknown_ctrl_recv_callback - - self.recv_callback = recv_cb - self.send_callback = send_cb - self.on_ctrl_recv_cb = on_ctrl_recv_cb - self.on_invalid_ctrl_recv_cb = on_invalid_ctrl_recv_cb - self.on_data_chunk_recv_cb = on_data_chunk_recv_cb - self.on_data_recv_cb = on_data_recv_cb - self.before_ctrl_send_cb = before_ctrl_send_cb - self.on_ctrl_send_cb = on_ctrl_send_cb - self.on_ctrl_not_send_cb = on_ctrl_not_send_cb - self.on_data_send_cb = on_data_send_cb - self.on_stream_close_cb = on_stream_close_cb - self.on_request_recv_cb = on_request_recv_cb - self.on_ctrl_recv_parse_error_cb = on_ctrl_recv_parse_error_cb - self.on_unknown_ctrl_recv_cb = on_unknown_ctrl_recv_cb - - self.user_data = user_data - - if side == CLIENT: - rv = cspdylay.spdylay_session_client_new(&self._c_session, - version, - &c_session_callbacks, - self) - elif side == SERVER: - rv = cspdylay.spdylay_session_server_new(&self._c_session, - version, - &c_session_callbacks, - self) - else: - raise InvalidArgumentError('side must be either CLIENT or SERVER') - - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - elif rv == cspdylay.SPDYLAY_ERR_ZLIB: - raise ZlibError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_UNSUPPORTED_VERSION: - raise UnsupportedVersionError(_strerror(rv)) - - def __init__(self, side, version, config=None, - send_cb=None, recv_cb=None, - on_ctrl_recv_cb=None, - on_invalid_ctrl_recv_cb=None, - on_data_chunk_recv_cb=None, - on_data_recv_cb=None, - before_ctrl_send_cb=None, - on_ctrl_send_cb=None, - on_ctrl_not_send_cb=None, - on_data_send_cb=None, - on_stream_close_cb=None, - on_request_recv_cb=None, - on_ctrl_recv_parse_error_cb=None, - user_data=None): - pass - - def __dealloc__(self): - cspdylay.spdylay_session_del(self._c_session) - - cpdef recv(self, data=None): - cdef int rv - cdef char *c_data - self.error = self.base_error = None - if data is None: - rv = cspdylay.spdylay_session_recv(self._c_session) - else: - c_data = data - rv = cspdylay.spdylay_session_mem_recv(self._c_session, - c_data, len(data)) - if self.base_error: - raise self.base_error - if self.error: - raise self.error - - if rv >= 0: - return - elif rv == cspdylay.SPDYLAY_ERR_EOF: - raise EOFError() - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - elif rv == cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE: - raise CallbackFailureError() - - cpdef send(self): - cdef int rv - self.error = self.base_error = None - rv = cspdylay.spdylay_session_send(self._c_session) - if self.base_error: - raise self.base_error - elif self.error: - raise self.error - - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - elif rv == cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE: - raise CallbackFailureError() - - cpdef resume_data(self, stream_id): - cpdef int rv - rv = cspdylay.spdylay_session_resume_data(self._c_session, stream_id) - if rv == 0: - return True - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - return False - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef want_read(self): - return cspdylay.spdylay_session_want_read(self._c_session) - - cpdef want_write(self): - return cspdylay.spdylay_session_want_write(self._c_session) - - cpdef get_stream_user_data(self, stream_id): - return cspdylay.spdylay_session_get_stream_user_data(\ - self._c_session, stream_id) - - cpdef get_outbound_queue_size(self): - return cspdylay.spdylay_session_get_outbound_queue_size(\ - self._c_session) - - cpdef get_pri_lowest(self): - return cspdylay.spdylay_session_get_pri_lowest(self._c_session) - - - cpdef fail_session(self, status_code): - cdef int rv - rv = cspdylay.spdylay_session_fail_session(self._c_session, - status_code) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_request(self, pri, nv, data_prd=None, stream_user_data=None): - cdef cspdylay.spdylay_data_provider c_data_prd - cdef cspdylay.spdylay_data_provider *c_data_prd_ptr - cpdef int rv - cdef char **cnv - nv = pynv_encode(nv) - cnv = pynv2cnv(nv) - if data_prd: - create_c_data_prd(&c_data_prd, data_prd) - c_data_prd_ptr = &c_data_prd - else: - c_data_prd_ptr = NULL - - rv = cspdylay.spdylay_submit_request(self._c_session, pri, cnv, - c_data_prd_ptr, - stream_user_data) - free(cnv) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_response(self, stream_id, nv, data_prd=None): - cdef cspdylay.spdylay_data_provider c_data_prd - cdef cspdylay.spdylay_data_provider *c_data_prd_ptr - cpdef int rv - cdef char **cnv - nv = pynv_encode(nv) - cnv = pynv2cnv(nv) - if data_prd: - create_c_data_prd(&c_data_prd, data_prd) - c_data_prd_ptr = &c_data_prd - else: - c_data_prd_ptr = NULL - - rv = cspdylay.spdylay_submit_response(self._c_session, stream_id, - cnv, c_data_prd_ptr) - free(cnv) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_syn_stream(self, flags, pri, nv, assoc_stream_id=0, - stream_user_data=None): - cdef int rv - cdef char **cnv - nv = pynv_encode(nv) - cnv = pynv2cnv(nv) - rv = cspdylay.spdylay_submit_syn_stream(self._c_session, - flags, - assoc_stream_id, - pri, - cnv, - stream_user_data) - free(cnv) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_syn_reply(self, flags, stream_id, nv): - cdef int rv - cdef char **cnv - nv = pynv_encode(nv) - cnv = pynv2cnv(nv) - rv = cspdylay.spdylay_submit_syn_reply(self._c_session, - flags, stream_id, cnv) - free(cnv) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_headers(self, flags, stream_id, nv): - cdef int rv - cdef char **cnv - nv = pynv_encode(nv) - cnv = pynv2cnv(nv) - rv = cspdylay.spdylay_submit_headers(self._c_session, - flags, stream_id, cnv) - free(cnv) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_data(self, stream_id, flags, data_prd): - cdef cspdylay.spdylay_data_provider c_data_prd - cdef cspdylay.spdylay_data_provider *c_data_prd_ptr - cpdef int rv - if data_prd: - create_c_data_prd(&c_data_prd, data_prd) - c_data_prd_ptr = &c_data_prd - else: - c_data_prd_ptr = NULL - - rv = cspdylay.spdylay_submit_data(self._c_session, stream_id, - flags, c_data_prd_ptr) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_rst_stream(self, stream_id, status_code): - cdef int rv - rv = cspdylay.spdylay_submit_rst_stream(self._c_session, stream_id, - status_code) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_ping(self): - cdef int rv - rv = cspdylay.spdylay_submit_ping(self._c_session) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_goaway(self, status_code): - cdef int rv - rv = cspdylay.spdylay_submit_goaway(self._c_session, status_code) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_window_update(self, stream_id, delta_window_size): - cdef int rv - rv = cspdylay.spdylay_submit_window_update(self._c_session, stream_id, - delta_window_size) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError() - elif rv == cspdylay.SPDYLAY_ERR_STREAM_CLOSED: - raise StreamClosedError() - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - - cpdef submit_settings(self, flags, iv): - ''' Submit SETTINGS frame. iv is list of tuple (settings_id, - flag, value) - ''' - cdef int rv - cdef cspdylay.spdylay_settings_entry *civ = pysettings2csettings(iv) - rv = cspdylay.spdylay_submit_settings(self._c_session, flags, - civ, len(iv)) - free(civ) - if rv == 0: - return - elif rv == cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT: - raise InvalidArgumentError(_strerror(rv)) - elif rv == cspdylay.SPDYLAY_ERR_NOMEM: - raise MemoryError() - -cdef _strerror(int error_code): - return cspdylay.spdylay_strerror(error_code).decode('UTF-8') - -cpdef get_npn_protocols(): - cdef size_t proto_list_len - cdef cspdylay.spdylay_npn_proto *proto_list - proto_list = cspdylay.spdylay_npn_get_proto_list(&proto_list_len) - res = [] - for i in range(proto_list_len): - res.append((proto_list[i].proto)[:proto_list[i].len]\ - .decode('UTF-8')) - return res - -cpdef int npn_get_version(proto): - cdef char *cproto - if proto == None: - return 0 - proto = proto.encode('UTF-8') - cproto = proto - return cspdylay.spdylay_npn_get_version(cproto, len(proto)) - -# Side -CLIENT = 1 -SERVER = 2 - -# SPDY protocol version -PROTO_SPDY2 = cspdylay.SPDYLAY_PROTO_SPDY2 -PROTO_SPDY3 = cspdylay.SPDYLAY_PROTO_SPDY3 - -# Control frame flags -CTRL_FLAG_NONE = cspdylay.SPDYLAY_CTRL_FLAG_NONE -CTRL_FLAG_FIN = cspdylay.SPDYLAY_CTRL_FLAG_FIN -CTRL_FLAG_UNIDIRECTIONAL = cspdylay.SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL - -# Data frame flags -DATA_FLAG_NONE = cspdylay.SPDYLAY_DATA_FLAG_NONE -DATA_FLAG_FIN = cspdylay.SPDYLAY_DATA_FLAG_FIN - -# Error codes -ERR_INVALID_ARGUMENT = cspdylay.SPDYLAY_ERR_INVALID_ARGUMENT -ERR_ZLIB = cspdylay.SPDYLAY_ERR_ZLIB -ERR_UNSUPPORTED_VERSION = cspdylay.SPDYLAY_ERR_UNSUPPORTED_VERSION -ERR_WOULDBLOCK = cspdylay.SPDYLAY_ERR_WOULDBLOCK -ERR_PROTO = cspdylay.SPDYLAY_ERR_PROTO -ERR_INVALID_FRAME = cspdylay.SPDYLAY_ERR_INVALID_FRAME -ERR_EOF = cspdylay.SPDYLAY_ERR_EOF -ERR_DEFERRED = cspdylay.SPDYLAY_ERR_DEFERRED -ERR_STREAM_ID_NOT_AVAILABLE = cspdylay.SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE -ERR_STREAM_CLOSED = cspdylay.SPDYLAY_ERR_STREAM_CLOSED -ERR_STREAM_CLOSING = cspdylay.SPDYLAY_ERR_STREAM_CLOSING -ERR_STREAM_SHUT_WR = cspdylay.SPDYLAY_ERR_STREAM_SHUT_WR -ERR_INVALID_STREAM_ID = cspdylay.SPDYLAY_ERR_INVALID_STREAM_ID -ERR_INVALID_STREAM_STATE = cspdylay.SPDYLAY_ERR_INVALID_STREAM_STATE -ERR_DEFERRED_DATA_EXIST = cspdylay.SPDYLAY_ERR_DEFERRED_DATA_EXIST -ERR_SYN_STREAM_NOT_ALLOWED = cspdylay.SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED -ERR_GOAWAY_ALREADY_SENT = cspdylay.SPDYLAY_ERR_GOAWAY_ALREADY_SENT -ERR_INVALID_HEADER_BLOCK = cspdylay.SPDYLAY_ERR_INVALID_HEADER_BLOCK -ERR_INVALID_STATE = cspdylay.SPDYLAY_ERR_INVALID_STATE -ERR_GZIP = cspdylay.SPDYLAY_ERR_GZIP -ERR_TEMPORAL_CALLBACK_FAILURE = cspdylay.SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE -ERR_FATAL = cspdylay.SPDYLAY_ERR_FATAL -ERR_NOMEM = cspdylay.SPDYLAY_ERR_NOMEM -ERR_CALLBACK_FAILURE = cspdylay.SPDYLAY_ERR_CALLBACK_FAILURE - -# Read Callback Flags -READ_EOF = 1 - -# The status code for RST_STREAM -OK = cspdylay.SPDYLAY_OK -PROTOCOL_ERROR = cspdylay.SPDYLAY_PROTOCOL_ERROR -INVALID_STREAM = cspdylay.SPDYLAY_INVALID_STREAM -REFUSED_STREAM = cspdylay.SPDYLAY_REFUSED_STREAM -UNSUPPORTED_VERSION = cspdylay.SPDYLAY_UNSUPPORTED_VERSION -CANCEL = cspdylay.SPDYLAY_CANCEL -INTERNAL_ERROR = cspdylay.SPDYLAY_INTERNAL_ERROR -FLOW_CONTROL_ERROR = cspdylay.SPDYLAY_FLOW_CONTROL_ERROR -# Following status codes were introduced in SPDY/3 -STREAM_IN_USE = cspdylay.SPDYLAY_STREAM_IN_USE -STREAM_ALREADY_CLOSED = cspdylay.SPDYLAY_STREAM_ALREADY_CLOSED -INVALID_CREDENTIALS = cspdylay.SPDYLAY_INVALID_CREDENTIALS -FRAME_TOO_LARGE = cspdylay.SPDYLAY_FRAME_TOO_LARGE - -# The status codes for GOAWAY, introduced in SPDY/3. -GOAWAY_OK = cspdylay.SPDYLAY_GOAWAY_OK -GOAWAY_PROTOCOL_ERROR = cspdylay.SPDYLAY_GOAWAY_PROTOCOL_ERROR -GOAWAY_INTERNAL_ERROR = cspdylay.SPDYLAY_GOAWAY_INTERNAL_ERROR - -# Frame types -SYN_STREAM = cspdylay.SPDYLAY_SYN_STREAM -SYN_REPLY = cspdylay.SPDYLAY_SYN_REPLY -RST_STREAM = cspdylay.SPDYLAY_RST_STREAM -SETTINGS = cspdylay.SPDYLAY_SETTINGS -NOOP = cspdylay.SPDYLAY_NOOP -PING = cspdylay.SPDYLAY_PING -GOAWAY = cspdylay.SPDYLAY_GOAWAY -HEADERS = cspdylay.SPDYLAY_HEADERS -WINDOW_UPDATE = cspdylay.SPDYLAY_WINDOW_UPDATE -CREDENTIAL = cspdylay.SPDYLAY_CREDENTIAL - -# The flags for the SETTINGS control frame. -FLAG_SETTINGS_NONE = cspdylay.SPDYLAY_FLAG_SETTINGS_NONE -FLAG_SETTINGS_CLEAR_SETTINGS = cspdylay.SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS - -# The flags for SETTINGS ID/value pair. -ID_FLAG_SETTINGS_NONE = cspdylay.SPDYLAY_ID_FLAG_SETTINGS_NONE -ID_FLAG_SETTINGS_PERSIST_VALUE = cspdylay.SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE -ID_FLAG_SETTINGS_PERSISTED = cspdylay.SPDYLAY_ID_FLAG_SETTINGS_PERSISTED - -# The SETTINGS ID. -SETTINGS_UPLOAD_BANDWIDTH = cspdylay.SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH -SETTINGS_DOWNLOAD_BANDWIDTH = cspdylay.SPDYLAY_SETTINGS_DOWNLOAD_BANDWIDTH -SETTINGS_ROUND_TRIP_TIME = cspdylay.SPDYLAY_SETTINGS_ROUND_TRIP_TIME -SETTINGS_MAX_CONCURRENT_STREAMS = \ - cspdylay.SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS -SETTINGS_CURRENT_CWND = cspdylay.SPDYLAY_SETTINGS_CURRENT_CWND -SETTINGS_DOWNLOAD_RETRANS_RATE = \ - cspdylay.SPDYLAY_SETTINGS_DOWNLOAD_RETRANS_RATE -SETTINGS_INITIAL_WINDOW_SIZE = cspdylay.SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE -SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE = \ - cspdylay.SPDYLAY_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE -SETTINGS_MAX = cspdylay.SPDYLAY_SETTINGS_MAX - -try: - # Simple SPDY Server implementation. We mimics the methods and - # attributes of http.server.BaseHTTPRequestHandler. Since this - # implementation uses TLS NPN, Python 3.3.0 or later is required. - - import socket - import threading - import socketserver - import ssl - import io - import select - import sys - import time - from xml.sax.saxutils import escape - - class Stream: - def __init__(self, stream_id): - self.stream_id = stream_id - self.data_prd = None - - self.method = None - self.path = None - self.version = None - self.scheme = None - self.host = None - self.headers = [] - - self.rfile = None - self.wfile = None - - def process_headers(self, headers): - for k, v in headers: - if k == ':method': - self.method = v - elif k == ':scheme': - self.scheme = v - elif k == ':path': - self.path = v - elif k == ':version': - self.version = v - elif k == ':host': - self.host = v - else: - self.headers.append((k, v)) - - class SessionCtrl: - def __init__(self): - self.streams = {} - - class BaseSPDYRequestHandler(socketserver.BaseRequestHandler): - - server_version = 'Python-spdylay' - - error_content_type = 'text/html; charset=UTF-8' - - # Same HTML from Apache error page - error_message_format = '''\ - - -{code} {reason} - -

{reason}

-

{explain}

-
-
{server} at {hostname} Port {port}
- -''' - - def send_error(self, code, message=None): - # Make sure that code is really int - code = int(code) - try: - shortmsg, longmsg = self.responses[code] - except KeyError: - shortmsg, longmsg = '???', '???' - if message is None: - message = shortmsg - explain = longmsg - - content = self.error_message_format.format(\ - code=code, - reason = escape(message), - explain=escape(explain), - server=escape(self.server_version), - hostname=escape(socket.getfqdn()), - port=self.server.server_address[1]).encode('UTF-8') - - self.send_response(code, message) - self.send_header('content-type', self.error_content_type) - self.send_header('content-length', str(len(content))) - - self.wfile.write(content) - - def send_response(self, code, message=None): - if message is None: - try: - shortmsg, _ = self.responses[code] - except KeyError: - shortmsg = '???' - message = shortmsg - - self._response_headers.append((':status', - '{} {}'.format(code, message))) - - def send_header(self, keyword, value): - self._response_headers.append((keyword, value)) - - def version_string(self): - return self.server_version + ' ' + self.sys_version - - def handle_one_request(self, stream): - self.stream = stream - - stream.wfile = io.BytesIO() - - self.command = stream.method - self.path = stream.path - self.request_version = stream.version - self.headers = stream.headers - self.rfile = stream.rfile - self.wfile = stream.wfile - self._response_headers = [] - - if stream.method is None: - self.send_error(400) - else: - mname = 'do_' + stream.method - if hasattr(self, mname): - method = getattr(self, mname) - - if self.rfile is not None: - self.rfile.seek(0) - - method() - else: - self.send_error(501, 'Unsupported method ({})'\ - .format(stream.method)) - - self.wfile.seek(0) - data_prd = DataProvider(self.wfile, self.read_cb) - stream.data_prd = data_prd - - self.send_header(':version', 'HTTP/1.1') - self.send_header('server', self.version_string()) - self.send_header('date', self.date_time_string()) - - self.session.submit_response(stream.stream_id, - self._response_headers, data_prd) - - - def send_cb(self, session, data): - return self.request.send(data) - - def read_cb(self, session, stream_id, length, read_ctrl, source): - data = source.read(length) - if not data: - read_ctrl.flags = READ_EOF - return data - - def on_ctrl_recv_cb(self, session, frame): - if frame.frame_type == SYN_STREAM: - stream = Stream(frame.stream_id) - self.ssctrl.streams[frame.stream_id] = stream - - stream.process_headers(frame.nv) - elif frame.frame_type == HEADERS: - if frame.stream_id in self.ssctrl.streams: - stream = self.ssctrl.streams[frame.stream_id] - stream.process_headers(frame.nv) - - def on_data_chunk_recv_cb(self, session, flags, stream_id, data): - if stream_id in self.ssctrl.streams: - stream = self.ssctrl.streams[stream_id] - if stream.method == 'POST': - if not stream.rfile: - stream.rfile = io.BytesIO() - stream.rfile.write(data) - else: - # We don't allow request body if method is not POST - session.submit_rst_stream(stream_id, PROTOCOL_ERROR) - - def on_stream_close_cb(self, session, stream_id, status_code): - if stream_id in self.ssctrl.streams: - del self.ssctrl.streams[stream_id] - - def on_request_recv_cb(self, session, stream_id): - if stream_id in self.ssctrl.streams: - stream = self.ssctrl.streams[stream_id] - self.handle_one_request(stream) - - def handle(self): - self.request.setsockopt(socket.IPPROTO_TCP, - socket.TCP_NODELAY, True) - try: - self.request.do_handshake() - self.request.setblocking(False) - - version = npn_get_version(self.request.selected_npn_protocol()) - if version == 0: - return - - self.ssctrl = SessionCtrl() - self.session = Session(\ - SERVER, version, - send_cb=self.send_cb, - on_ctrl_recv_cb=self.on_ctrl_recv_cb, - on_data_chunk_recv_cb=self.on_data_chunk_recv_cb, - on_stream_close_cb=self.on_stream_close_cb, - on_request_recv_cb=self.on_request_recv_cb) - - self.session.submit_settings(\ - FLAG_SETTINGS_NONE, - [(SETTINGS_MAX_CONCURRENT_STREAMS, ID_FLAG_SETTINGS_NONE, - 100)] - ) - - while self.session.want_read() or self.session.want_write(): - want_read = want_write = False - try: - data = self.request.recv(4096) - if data: - self.session.recv(data) - else: - break - except ssl.SSLWantReadError: - want_read = True - except ssl.SSLWantWriteError: - want_write = True - try: - self.session.send() - except ssl.SSLWantReadError: - want_read = True - except ssl.SSLWantWriteError: - want_write = True - - if want_read or want_write: - select.select([self.request] if want_read else [], - [self.request] if want_write else [], - []) - finally: - self.request.setblocking(True) - - # The following methods and attributes are copied from - # Lib/http/server.py of cpython source code - - def date_time_string(self, timestamp=None): - """Return the current date and time formatted for a - message header.""" - if timestamp is None: - timestamp = time.time() - year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp) - s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % ( - self.weekdayname[wd], - day, self.monthname[month], year, - hh, mm, ss) - return s - - weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] - - monthname = [None, - 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - - # The Python system version, truncated to its first component. - sys_version = "Python/" + sys.version.split()[0] - - # Table mapping response codes to messages; entries have the - # form {code: (shortmessage, longmessage)}. - # See RFC 2616 and 6585. - responses = { - 100: ('Continue', 'Request received, please continue'), - 101: ('Switching Protocols', - 'Switching to new protocol; obey Upgrade header'), - - 200: ('OK', 'Request fulfilled, document follows'), - 201: ('Created', 'Document created, URL follows'), - 202: ('Accepted', - 'Request accepted, processing continues off-line'), - 203: ('Non-Authoritative Information', - 'Request fulfilled from cache'), - 204: ('No Content', 'Request fulfilled, nothing follows'), - 205: ('Reset Content', 'Clear input form for further input.'), - 206: ('Partial Content', 'Partial content follows.'), - - 300: ('Multiple Choices', - 'Object has several resources -- see URI list'), - 301: ('Moved Permanently', - 'Object moved permanently -- see URI list'), - 302: ('Found', 'Object moved temporarily -- see URI list'), - 303: ('See Other', 'Object moved -- see Method and URL list'), - 304: ('Not Modified', - 'Document has not changed since given time'), - 305: ('Use Proxy', - 'You must use proxy specified in Location to access this ' - 'resource.'), - 307: ('Temporary Redirect', - 'Object moved temporarily -- see URI list'), - - 400: ('Bad Request', - 'Bad request syntax or unsupported method'), - 401: ('Unauthorized', - 'No permission -- see authorization schemes'), - 402: ('Payment Required', - 'No payment -- see charging schemes'), - 403: ('Forbidden', - 'Request forbidden -- authorization will not help'), - 404: ('Not Found', 'Nothing matches the given URI'), - 405: ('Method Not Allowed', - 'Specified method is invalid for this resource.'), - 406: ('Not Acceptable', 'URI not available in preferred format.'), - 407: ('Proxy Authentication Required', 'You must authenticate with ' - 'this proxy before proceeding.'), - 408: ('Request Timeout', 'Request timed out; try again later.'), - 409: ('Conflict', 'Request conflict.'), - 410: ('Gone', - 'URI no longer exists and has been permanently removed.'), - 411: ('Length Required', 'Client must specify Content-Length.'), - 412: ('Precondition Failed', 'Precondition in headers is false.'), - 413: ('Request Entity Too Large', 'Entity is too large.'), - 414: ('Request-URI Too Long', 'URI is too long.'), - 415: ('Unsupported Media Type', - 'Entity body in unsupported format.'), - 416: ('Requested Range Not Satisfiable', - 'Cannot satisfy request range.'), - 417: ('Expectation Failed', - 'Expect condition could not be satisfied.'), - 428: ('Precondition Required', - 'The origin server requires the request to be conditional.'), - 429: ('Too Many Requests', 'The user has sent too many requests ' - 'in a given amount of time ("rate limiting").'), - 431: ('Request Header Fields Too Large', - 'The server is unwilling to process ' - 'the request because its header fields are too large.'), - - 500: ('Internal Server Error', 'Server got itself in trouble'), - 501: ('Not Implemented', - 'Server does not support this operation'), - 502: ('Bad Gateway', - 'Invalid responses from another server/proxy.'), - 503: ('Service Unavailable', - 'The server cannot process the request due to a high load'), - 504: ('Gateway Timeout', - 'The gateway server did not receive a timely response'), - 505: ('HTTP Version Not Supported', 'Cannot fulfill request.'), - 511: ('Network Authentication Required', - 'The client needs to authenticate to gain network access.'), - } - - class ThreadedSPDYServer(socketserver.ThreadingMixIn, - socketserver.TCPServer): - def __init__(self, server_address, RequestHandlerCalss, - cert_file, key_file): - self.allow_reuse_address = True - - self.ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - self.ctx.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | \ - ssl.OP_NO_COMPRESSION - self.ctx.load_cert_chain(cert_file, key_file) - self.ctx.set_npn_protocols(get_npn_protocols()) - - socketserver.TCPServer.__init__(self, server_address, - RequestHandlerCalss) - - def start(self, daemon=False): - server_thread = threading.Thread(target=self.serve_forever) - server_thread.daemon = daemon - server_thread.start() - - def process_request(self, request, client_address): - # ThreadingMixIn.process_request() dispatches request and - # client_address to separate thread. To cleanly shutdown - # SSL/TLS wrapped socket, we wrap socket here. - - # SSL/TLS handshake is postponed to each thread. - request = self.ctx.wrap_socket(\ - request, server_side=True, do_handshake_on_connect=False) - - socketserver.ThreadingMixIn.process_request(self, - request, client_address) - - - # Simple SPDY client implementation. Since this implementation - # uses TLS NPN, Python 3.3.0 or later is required. - - from urllib.parse import urlsplit - - class BaseSPDYStreamHandler: - def __init__(self, url, fetcher): - self.url = url - self.fetcher = fetcher - self.stream_id = None - - def on_header(self, nv): - pass - - def on_data(self, data): - pass - - def on_close(self, status_code): - pass - - class UrlFetchError(Exception): - pass - - class UrlFetcher: - def __init__(self, server_address, urls, StreamHandlerClass): - self.server_address = server_address - self.handlers = [StreamHandlerClass(url, self) for url in urls] - self.streams = {} - self.finished = [] - - self.ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - self.ctx.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | \ - ssl.OP_NO_COMPRESSION - self.ctx.set_npn_protocols(get_npn_protocols()) - - def send_cb(self, session, data): - return self.sock.send(data) - - def before_ctrl_send_cb(self, session, frame): - if frame.frame_type == SYN_STREAM: - handler = session.get_stream_user_data(frame.stream_id) - if handler: - handler.stream_id = frame.stream_id - self.streams[handler.stream_id] = handler - - def on_ctrl_recv_cb(self, session, frame): - if frame.frame_type == SYN_REPLY or frame.frame_type == HEADERS: - if frame.stream_id in self.streams: - handler = self.streams[frame.stream_id] - handler.on_header(frame.nv) - - def on_data_chunk_recv_cb(self, session, flags, stream_id, data): - if stream_id in self.streams: - handler = self.streams[stream_id] - handler.on_data(data) - - def on_stream_close_cb(self, session, stream_id, status_code): - if stream_id in self.streams: - handler = self.streams[stream_id] - handler.on_close(status_code) - del self.streams[stream_id] - self.finished.append(handler) - - def connect(self, server_address): - self.sock = None - for res in socket.getaddrinfo(server_address[0], server_address[1], - socket.AF_UNSPEC, - socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - except OSError as msg: - self.sock = None - continue - try: - self.sock.connect(sa) - except OSError as msg: - self.sock.close() - self.sock = None - continue - break - else: - raise UrlFetchError('Could not connect to {}'\ - .format(server_address)) - - def tls_handshake(self): - self.sock = self.ctx.wrap_socket(self.sock, server_side=False, - do_handshake_on_connect=False) - self.sock.do_handshake() - - self.version = npn_get_version(self.sock.selected_npn_protocol()) - if self.version == 0: - raise UrlFetchError('NPN failed') - - def loop(self): - self.connect(self.server_address) - try: - self._loop() - finally: - self.sock.shutdown(socket.SHUT_RDWR) - self.sock.close() - - def _loop(self): - self.tls_handshake() - self.sock.setblocking(False) - - session = Session(CLIENT, - self.version, - send_cb=self.send_cb, - on_ctrl_recv_cb=self.on_ctrl_recv_cb, - on_data_chunk_recv_cb=self.on_data_chunk_recv_cb, - before_ctrl_send_cb=self.before_ctrl_send_cb, - on_stream_close_cb=self.on_stream_close_cb) - - session.submit_settings(\ - FLAG_SETTINGS_NONE, - [(SETTINGS_MAX_CONCURRENT_STREAMS, ID_FLAG_SETTINGS_NONE, 100)] - ) - - if self.server_address[1] == 443: - hostport = self.server_address[0] - else: - hostport = '{}:{}'.format(self.server_address[0], - self.server_address[1]) - - for handler in self.handlers: - res = urlsplit(handler.url) - if res.path: - path = res.path - else: - path = '/' - if res.query: - path = '?'.join([path, res.query]) - - session.submit_request(0, - [(':method', 'GET'), - (':scheme', 'https'), - (':path', path), - (':version', 'HTTP/1.1'), - (':host', hostport), - ('accept', '*/*'), - ('user-agent', 'python-spdylay')], - stream_user_data=handler) - - while (session.want_read() or session.want_write()) \ - and not len(self.finished) == len(self.handlers): - want_read = want_write = False - try: - data = self.sock.recv(4096) - if data: - session.recv(data) - else: - break - except ssl.SSLWantReadError: - want_read = True - except ssl.SSLWantWriteError: - want_write = True - try: - session.send() - except ssl.SSLWantReadError: - want_read = True - except ssl.SSLWantWriteError: - want_write = True - - if want_read or want_write: - select.select([self.sock] if want_read else [], - [self.sock] if want_write else [], - []) - - def _urlfetch_session_one(urls, StreamHandlerClass): - res = urlsplit(urls[0]) - if res.scheme != 'https': - raise UrlFetchError('Unsupported scheme {}'.format(res.scheme)) - hostname = res.hostname - port = res.port if res.port else 443 - - f = UrlFetcher((hostname, port), urls, StreamHandlerClass) - f.loop() - - def urlfetch(url_or_urls, StreamHandlerClass): - if isinstance(url_or_urls, str): - _urlfetch_session_one([url_or_urls], StreamHandlerClass) - else: - urls = [] - prev_addr = (None, None) - for url in url_or_urls: - res = urlsplit(url) - port = res.port if res.port else 443 - if prev_addr != (res.hostname, port): - if urls: - _urlfetch_session_one(urls, StreamHandlerClass) - urls = [] - prev_addr = (res.hostname, port) - urls.append(url) - if urls: - _urlfetch_session_one(urls, StreamHandlerClass) - -except ImportError: - # No server for 2.x because they lack TLS NPN. - pass diff --git a/python/spdylay_tests.py b/python/spdylay_tests.py deleted file mode 100644 index 196e943e..00000000 --- a/python/spdylay_tests.py +++ /dev/null @@ -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() diff --git a/python/spdyserv.py b/python/spdyserv.py deleted file mode 100644 index 804fa9ad..00000000 --- a/python/spdyserv.py +++ /dev/null @@ -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 = '''\ - -SPDY FTW - -

SPDY FTW

-

The age of HTTP/1.1 is over. The time of SPDY has come.

- -'''.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() diff --git a/src/EventPoll.h b/src/EventPoll.h index 17be1595..4433f6b0 100644 --- a/src/EventPoll.h +++ b/src/EventPoll.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef EVENT_POLL_H #define EVENT_POLL_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #ifdef HAVE_EPOLL # include "EventPoll_epoll.h" diff --git a/src/EventPollEvent.h b/src/EventPollEvent.h index d5e0d72b..562ba5b3 100644 --- a/src/EventPollEvent.h +++ b/src/EventPollEvent.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,9 +25,9 @@ #ifndef EVENT_POLL_EVENT_H #define EVENT_POLL_EVENT_H -#include "spdylay_config.h" +#include "nghttp2_config.h" -namespace spdylay { +namespace nghttp2 { enum EventPollEvent { EP_POLLIN = 1, @@ -41,6 +41,6 @@ enum EventPollOp { EP_MOD }; -} // namespace spdylay +} // namespace nghttp2 #endif // EVENT_POLL_EVENT_H diff --git a/src/EventPoll_epoll.cc b/src/EventPoll_epoll.cc index 0a63edfc..8622274a 100644 --- a/src/EventPoll_epoll.cc +++ b/src/EventPoll_epoll.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -28,7 +28,7 @@ #include -namespace spdylay { +namespace nghttp2 { EventPoll::EventPoll(size_t max_events) : 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); } -} // namespace spdylay +} // namespace nghttp2 diff --git a/src/EventPoll_epoll.h b/src/EventPoll_epoll.h index 9205cf0d..1a595e10 100644 --- a/src/EventPoll_epoll.h +++ b/src/EventPoll_epoll.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef EVENT_POLL_EPOLL_H #define EVENT_POLL_EPOLL_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include @@ -33,7 +33,7 @@ #include "EventPollEvent.h" -namespace spdylay { +namespace nghttp2 { class EventPoll { public: @@ -57,6 +57,6 @@ private: size_t num_events_; }; -} // namespace spdylay +} // namespace nghttp2 #endif // EVENT_POLL_EPOLL_H diff --git a/src/EventPoll_kqueue.cc b/src/EventPoll_kqueue.cc index 64c20b2d..1006ad29 100644 --- a/src/EventPoll_kqueue.cc +++ b/src/EventPoll_kqueue.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -35,7 +35,7 @@ # define PTR_TO_UDATA(X) (X) #endif // !KEVENT_UDATA_INTPTR_T -namespace spdylay { +namespace nghttp2 { EventPoll::EventPoll(size_t max_events) : 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); } -} // namespace spdylay +} // namespace nghttp2 diff --git a/src/EventPoll_kqueue.h b/src/EventPoll_kqueue.h index 8ef01c7c..67f63b82 100644 --- a/src/EventPoll_kqueue.h +++ b/src/EventPoll_kqueue.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef EVENT_POLL_KQUEUE_H #define EVENT_POLL_KQUEUE_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include @@ -35,7 +35,7 @@ #include "EventPollEvent.h" -namespace spdylay { +namespace nghttp2 { class EventPoll { public: @@ -59,6 +59,6 @@ private: size_t num_events_; }; -} // namespace spdylay +} // namespace nghttp2 #endif // EVENT_POLL_KQUEUE_H diff --git a/src/HtmlParser.cc b/src/HtmlParser.cc index 1e3f52ba..47fcdbcb 100644 --- a/src/HtmlParser.cc +++ b/src/HtmlParser.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -28,7 +28,7 @@ #include "util.h" -namespace spdylay { +namespace nghttp2 { ParserData::ParserData(const std::string& base_uri) : base_uri(base_uri) @@ -174,4 +174,4 @@ void HtmlParser::clear_links() parser_data_.links.clear(); } -} // namespace spdylay +} // namespace nghttp2 diff --git a/src/HtmlParser.h b/src/HtmlParser.h index 79275bc9..e0f3798a 100644 --- a/src/HtmlParser.h +++ b/src/HtmlParser.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef HTML_PARSER_H #define HTML_PARSER_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include #include @@ -34,7 +34,7 @@ #include -namespace spdylay { +namespace nghttp2 { struct ParserData { std::string base_uri; @@ -57,11 +57,11 @@ private: ParserData parser_data_; }; -} // namespace spdylay +} // namespace nghttp2 #else // !HAVE_LIBXML2 -namespace spdylay { +namespace nghttp2 { class HtmlParser { public: @@ -74,7 +74,7 @@ private: std::vector links_; }; -} // namespace spdylay +} // namespace nghttp2 #endif // !HAVE_LIBXML2 diff --git a/src/Makefile.am b/src/Makefile.am index ae6a885a..790d8212 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # 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@ 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 @@ -44,8 +44,8 @@ if HAVE_LIBEVENT_OPENSSL bin_PROGRAMS += shrpx endif # HAVE_LIBEVENT_OPENSSL -HELPER_OBJECTS = util.cc timegm.c spdylay_ssl.cc -HELPER_HFILES = util.h timegm.h spdylay_ssl.h spdylay_config.h +HELPER_OBJECTS = util.cc timegm.c nghttp2_ssl.cc +HELPER_HFILES = util.h timegm.h nghttp2_ssl.h nghttp2_config.h EVENT_OBJECTS = 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_SRCS} 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@\ @SRC_LIBS@ @CUNIT_LIBS@ @TESTS_LIBS@ TESTS += shrpx-unittest diff --git a/src/SpdyServer.cc b/src/SpdyServer.cc index 2ad4304f..730e4ccb 100644 --- a/src/SpdyServer.cc +++ b/src/SpdyServer.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -39,7 +39,7 @@ #include #include -#include "spdylay_ssl.h" +#include "nghttp2_ssl.h" #include "util.h" #include "EventPoll.h" @@ -47,7 +47,7 @@ # define O_BINARY (0) #endif // O_BINARY -namespace spdylay { +namespace nghttp2 { namespace { 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_404 = "404 Not Found"; 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 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, int fd, SSL *ssl, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, int64_t session_id) : EventHandler(config), fd_(fd), ssl_(ssl), version_(version), session_id_(session_id), io_flags_(0) { int r; - r = spdylay_session_server_new(&session_, version, callbacks, this); + r = nghttp2_session_server_new(&session_, version, callbacks, this); assert(r == 0); - spdylay_settings_entry entry; - entry.settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - entry.value = SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS; - entry.flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - r = spdylay_submit_settings(session_, SPDYLAY_FLAG_SETTINGS_NONE, + nghttp2_settings_entry entry; + entry.settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + entry.value = NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS; + entry.flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + r = nghttp2_submit_settings(session_, NGHTTP2_FLAG_SETTINGS_NONE, &entry, 1); assert(r == 0); } @@ -197,7 +197,7 @@ SpdyEventHandler::SpdyEventHandler(const Config* config, SpdyEventHandler::~SpdyEventHandler() { on_session_closed(this, session_id_); - spdylay_session_del(session_); + nghttp2_session_del(session_); for(std::map::iterator i = id2req_.begin(), eoi = id2req_.end(); i != eoi; ++i) { delete (*i).second; @@ -218,21 +218,21 @@ uint16_t SpdyEventHandler::version() const int SpdyEventHandler::execute(Sessions *sessions) { int r; - r = spdylay_session_recv(session_); + r = nghttp2_session_recv(session_); if(r == 0) { - r = spdylay_session_send(session_); + r = nghttp2_session_send(session_); } return r; } 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() { - return spdylay_session_want_write(session_) || (io_flags_ & WANT_WRITE); + return nghttp2_session_want_write(session_) || (io_flags_ & WANT_WRITE); } int SpdyEventHandler::fd() const @@ -242,8 +242,8 @@ int SpdyEventHandler::fd() const bool SpdyEventHandler::finish() { - return !spdylay_session_want_read(session_) && - !spdylay_session_want_write(session_); + return !nghttp2_session_want_read(session_) && + !nghttp2_session_want_write(session_); } 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, time_t last_modified, 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 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[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 (const std::string& status, int32_t stream_id, const std::vector >& headers, - spdylay_data_provider *data_prd) + nghttp2_data_provider *data_prd) { std::string date_str = util::http_date(time(0)); 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+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; return r; } int SpdyEventHandler::submit_response(const std::string& status, int32_t stream_id, - spdylay_data_provider *data_prd) + nghttp2_data_provider *data_prd) { const char *nv[] = { ":status", status.c_str(), @@ -352,7 +352,7 @@ int SpdyEventHandler::submit_response(const std::string& status, "server", SPDYD_SERVER.c_str(), 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) @@ -378,7 +378,7 @@ int64_t SpdyEventHandler::session_id() const } 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, void *user_data) { @@ -386,47 +386,47 @@ ssize_t hd_send_callback(spdylay_session *session, ssize_t r = hd->send_data(data, len, flags); if(r < 0) { if(hd->would_block()) { - r = SPDYLAY_ERR_WOULDBLOCK; + r = NGHTTP2_ERR_WOULDBLOCK; } else { - r = SPDYLAY_ERR_CALLBACK_FAILURE; + r = NGHTTP2_ERR_CALLBACK_FAILURE; } } else if(r == 0) { // In OpenSSL, r == 0 means EOF because SSL_write may do read. - r = SPDYLAY_ERR_CALLBACK_FAILURE; + r = NGHTTP2_ERR_CALLBACK_FAILURE; } return r; } } // 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) { SpdyEventHandler *hd = (SpdyEventHandler*)user_data; ssize_t r = hd->recv_data(data, len, flags); if(r < 0) { if(hd->would_block()) { - r = SPDYLAY_ERR_WOULDBLOCK; + r = NGHTTP2_ERR_WOULDBLOCK; } else { - r = SPDYLAY_ERR_CALLBACK_FAILURE; + r = NGHTTP2_ERR_CALLBACK_FAILURE; } } else if(r == 0) { - r = SPDYLAY_ERR_EOF; + r = NGHTTP2_ERR_EOF; } return r; } } // namespace 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, - spdylay_data_source *source, void *user_data) + nghttp2_data_source *source, void *user_data) { int fd = source->fd; ssize_t r; while((r = read(fd, buf, length)) == -1 && errno == EINTR); if(r == -1) { - return SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE; + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } else { if(r == 0) { *eof = 1; @@ -469,7 +469,7 @@ void prepare_status_response(Request *req, SpdyEventHandler *hd, close(pipefd[1]); req->file = pipefd[0]; - spdylay_data_provider data_prd; + nghttp2_data_provider data_prd; data_prd.source.fd = pipefd[0]; data_prd.read_callback = file_read_callback; std::vector > headers; @@ -544,7 +544,7 @@ void prepare_response(Request *req, SpdyEventHandler *hd) prepare_status_response(req, hd, STATUS_404); } else { req->file = file; - spdylay_data_provider data_prd; + nghttp2_data_provider data_prd; data_prd.source.fd = file; data_prd.read_callback = file_read_callback; if(last_mod_found && buf.st_mtime <= last_mod) { @@ -569,7 +569,7 @@ void append_nv(Request *req, char **nv) namespace { 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) { SpdyEventHandler *hd = (SpdyEventHandler*)user_data; @@ -578,14 +578,14 @@ void hd_on_ctrl_recv_callback on_ctrl_recv_callback(session, type, frame, user_data); } switch(type) { - case SPDYLAY_SYN_STREAM: { + case NGHTTP2_SYN_STREAM: { int32_t stream_id = frame->syn_stream.stream_id; Request *req = new Request(stream_id); append_nv(req, frame->syn_stream.nv); hd->add_stream(stream_id, req); break; } - case SPDYLAY_HEADERS: { + case NGHTTP2_HEADERS: { int32_t stream_id = frame->headers.stream_id; Request *req = hd->get_stream(stream_id); append_nv(req, frame->headers.nv); @@ -598,7 +598,7 @@ void hd_on_ctrl_recv_callback } // namespace 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; prepare_response(hd->get_stream(stream_id), hd); @@ -606,7 +606,7 @@ void htdocs_on_request_recv_callback namespace { 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) { SpdyEventHandler *hd = (SpdyEventHandler*)user_data; @@ -619,7 +619,7 @@ void hd_on_ctrl_send_callback namespace { 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) { // TODO Handle POST @@ -628,7 +628,7 @@ void on_data_chunk_recv_callback namespace { 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) { // TODO Handle POST @@ -642,7 +642,7 @@ void hd_on_data_recv_callback namespace { 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) { SpdyEventHandler *hd = (SpdyEventHandler*)user_data; @@ -655,7 +655,7 @@ void hd_on_data_send_callback namespace { 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) { SpdyEventHandler *hd = (SpdyEventHandler*)user_data; @@ -670,9 +670,9 @@ void on_stream_close_callback } // 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.recv_callback = hd_recv_callback; callbacks.on_stream_close_callback = on_stream_close_callback; @@ -725,7 +725,7 @@ public: if(config()->verbose) { 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 != version_) { version_ = 0; @@ -776,7 +776,7 @@ public: private: void add_next_handler(Sessions *sessions) { - spdylay_session_callbacks callbacks; + nghttp2_session_callbacks callbacks; fill_callback(callbacks, config()); SpdyEventHandler *hd = new SpdyEventHandler(config(), fd_, ssl_, version_, &callbacks, @@ -840,7 +840,7 @@ private: { int64_t session_id = ++(*session_id_seed_ptr_); if(config()->no_tls) { - spdylay_session_callbacks callbacks; + nghttp2_session_callbacks callbacks; fill_callback(callbacks, config()); SpdyEventHandler *hd = new SpdyEventHandler(config(), cfd, 0, @@ -985,11 +985,11 @@ int SpdyServer::run() memcpy(&proto_list[8], "spdy/2", 6); switch(config_->version) { - case SPDYLAY_PROTO_SPDY3: + case NGHTTP2_PROTO_SPDY3: next_proto.first = proto_list; next_proto.second = 7; break; - case SPDYLAY_PROTO_SPDY2: + case NGHTTP2_PROTO_SPDY2: next_proto.first = proto_list+7; next_proto.second = 7; break; @@ -1070,4 +1070,4 @@ int SpdyServer::run() return 0; } -} // namespace spdylay +} // namespace nghttp2 diff --git a/src/SpdyServer.h b/src/SpdyServer.h index 240fe756..0c3468cb 100644 --- a/src/SpdyServer.h +++ b/src/SpdyServer.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef SPDY_SERVER_H #define SPDY_SERVER_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include #include @@ -38,9 +38,9 @@ #include -#include +#include -namespace spdylay { +namespace nghttp2 { struct Config { std::string htdocs; @@ -50,7 +50,7 @@ struct Config { uint16_t port; std::string private_key_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; uint16_t version; bool verify_client; @@ -99,7 +99,7 @@ class SpdyEventHandler : public EventHandler { public: SpdyEventHandler(const Config* config, int fd, SSL *ssl, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, int64_t session_id); virtual ~SpdyEventHandler(); virtual int execute(Sessions *sessions); @@ -120,24 +120,24 @@ public: int32_t stream_id, time_t last_modified, off_t file_length, - spdylay_data_provider *data_prd); + nghttp2_data_provider *data_prd); int submit_response(const std::string& status, int32_t stream_id, - spdylay_data_provider *data_prd); + nghttp2_data_provider *data_prd); int submit_response (const std::string& status, int32_t stream_id, const std::vector >& headers, - spdylay_data_provider *data_prd); + nghttp2_data_provider *data_prd); void add_stream(int32_t stream_id, Request *req); void remove_stream(int32_t stream_id); Request* get_stream(int32_t stream_id); int64_t session_id() const; private: - spdylay_session *session_; + nghttp2_session *session_; int fd_; SSL* ssl_; uint16_t version_; @@ -158,13 +158,13 @@ private: }; 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 -(spdylay_session *session, int32_t stream_id, +(nghttp2_session *session, int32_t stream_id, 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 diff --git a/src/base64.h b/src/base64.h index b7215e22..6d1baf4a 100644 --- a/src/base64.h +++ b/src/base64.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2013 Tatsuhiro Tsujikawa * @@ -27,7 +27,7 @@ #include -namespace spdylay { +namespace nghttp2 { namespace base64 { @@ -174,6 +174,6 @@ std::string decode(InputIterator first, InputIterator last) } // namespace base64 -} // namespace spdylay +} // namespace nghttp2 #endif // BASE64_H diff --git a/src/spdylay_config.h b/src/nghttp2_config.h similarity index 91% rename from src/spdylay_config.h rename to src/nghttp2_config.h index 3eba3e5d..0b4c3a55 100644 --- a/src/spdylay_config.h +++ b/src/nghttp2_config.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,11 +22,11 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_CONFIG_H -#define SPDYLAY_CONFIG_H +#ifndef NGHTTP2_CONFIG_H +#define NGHTTP2_CONFIG_H #ifdef HAVE_CONFIG_H # include #endif // HAVE_CONFIG_H -#endif // SPDYLAY_CONFIG_H +#endif // NGHTTP2_CONFIG_H diff --git a/src/spdylay_ssl.cc b/src/nghttp2_ssl.cc similarity index 88% rename from src/spdylay_ssl.cc rename to src/nghttp2_ssl.cc index c27b12a0..c6b49621 100644 --- a/src/spdylay_ssl.cc +++ b/src/nghttp2_ssl.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -43,36 +43,36 @@ #include #include -#include "spdylay_ssl.h" +#include "nghttp2_ssl.h" #include "util.h" -namespace spdylay { +namespace nghttp2 { bool ssl_debug = false; Spdylay::Spdylay(int fd, SSL *ssl, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data) : fd_(fd), ssl_(ssl), version_(version), user_data_(user_data), 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); } Spdylay::~Spdylay() { - spdylay_session_del(session_); + nghttp2_session_del(session_); } int Spdylay::recv() { - return spdylay_session_recv(session_); + return nghttp2_session_recv(session_); } 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) @@ -115,18 +115,18 @@ ssize_t Spdylay::recv_data(uint8_t *data, size_t len, int flags) 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() { - return spdylay_session_want_write(session_) || (io_flags_ & WANT_WRITE); + return nghttp2_session_want_write(session_) || (io_flags_ & WANT_WRITE); } bool Spdylay::finish() { - return !spdylay_session_want_read(session_) && - !spdylay_session_want_write(session_); + return !nghttp2_session_want_read(session_) && + !nghttp2_session_want_write(session_); } int Spdylay::fd() const @@ -144,7 +144,7 @@ int Spdylay::submit_request(const std::string& scheme, const std::string& path, const std::map &headers, uint8_t pri, - const spdylay_data_provider *data_prd, + const nghttp2_data_provider *data_prd, int64_t data_length, void *stream_user_data) { @@ -167,7 +167,7 @@ int Spdylay::submit_request(const std::string& scheme, ":host", hostport.c_str(), "accept", "*/*", "accept-encoding", "gzip, deflate", - "user-agent", "spdylay/" SPDYLAY_VERSION + "user-agent", "nghttp2/" NGHTTP2_VERSION }; 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; - int r = spdylay_submit_request(session_, pri, nv, data_prd, + int r = nghttp2_submit_request(session_, pri, nv, data_prd, stream_user_data); delete [] nv; @@ -223,9 +223,9 @@ int Spdylay::submit_request(const std::string& scheme, 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() @@ -419,7 +419,7 @@ int set_tcp_nodelay(int fd) 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, void *user_data) { @@ -427,30 +427,30 @@ ssize_t send_callback(spdylay_session *session, ssize_t r = sc->send_data(data, len, flags); if(r < 0) { if(sc->would_block()) { - r = SPDYLAY_ERR_WOULDBLOCK; + r = NGHTTP2_ERR_WOULDBLOCK; } else { - r = SPDYLAY_ERR_CALLBACK_FAILURE; + r = NGHTTP2_ERR_CALLBACK_FAILURE; } } else if(r == 0) { // In OpenSSL, r == 0 means EOF because SSL_write may do read. - r = SPDYLAY_ERR_CALLBACK_FAILURE; + r = NGHTTP2_ERR_CALLBACK_FAILURE; } 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) { Spdylay *sc = (Spdylay*)user_data; ssize_t r = sc->recv_data(data, len, flags); if(r < 0) { if(sc->would_block()) { - r = SPDYLAY_ERR_WOULDBLOCK; + r = NGHTTP2_ERR_WOULDBLOCK; } else { - r = SPDYLAY_ERR_CALLBACK_FAILURE; + r = NGHTTP2_ERR_CALLBACK_FAILURE; } } else if(r == 0) { - r = SPDYLAY_ERR_EOF; + r = NGHTTP2_ERR_EOF; } return r; } @@ -521,7 +521,7 @@ void print_timer() } namespace { -void print_ctrl_hd(const spdylay_ctrl_hd& hd) +void print_ctrl_hd(const nghttp2_ctrl_hd& hd) { printf("\n", hd.version, hd.flags, hd.length); @@ -541,8 +541,8 @@ const char* frame_name_ansi_esc(print_type ptype) } // namespace namespace { -void print_frame(print_type ptype, spdylay_frame_type type, - spdylay_frame *frame) +void print_frame(print_type ptype, nghttp2_frame_type type, + nghttp2_frame *frame) { printf("%s%s%s frame ", frame_name_ansi_esc(ptype), @@ -550,24 +550,24 @@ void print_frame(print_type ptype, spdylay_frame_type type, ansi_escend()); print_ctrl_hd(frame->syn_stream.hd); switch(type) { - case SPDYLAY_SYN_STREAM: + case NGHTTP2_SYN_STREAM: print_frame_attr_indent(); 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.pri); print_nv(frame->syn_stream.nv); break; - case SPDYLAY_SYN_REPLY: + case NGHTTP2_SYN_REPLY: print_frame_attr_indent(); printf("(stream_id=%d)\n", frame->syn_reply.stream_id); print_nv(frame->syn_reply.nv); break; - case SPDYLAY_RST_STREAM: + case NGHTTP2_RST_STREAM: print_frame_attr_indent(); printf("(stream_id=%d, status_code=%u)\n", frame->rst_stream.stream_id, frame->rst_stream.status_code); break; - case SPDYLAY_SETTINGS: + case NGHTTP2_SETTINGS: print_frame_attr_indent(); printf("(niv=%lu)\n", static_cast(frame->settings.niv)); 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); } break; - case SPDYLAY_PING: + case NGHTTP2_PING: print_frame_attr_indent(); printf("(unique_id=%d)\n", frame->ping.unique_id); break; - case SPDYLAY_GOAWAY: + case NGHTTP2_GOAWAY: print_frame_attr_indent(); printf("(last_good_stream_id=%d)\n", frame->goaway.last_good_stream_id); break; - case SPDYLAY_HEADERS: + case NGHTTP2_HEADERS: print_frame_attr_indent(); printf("(stream_id=%d)\n", frame->headers.stream_id); print_nv(frame->headers.nv); break; - case SPDYLAY_WINDOW_UPDATE: + case NGHTTP2_WINDOW_UPDATE: print_frame_attr_indent(); printf("(stream_id=%d, delta_window_size=%d)\n", frame->window_update.stream_id, @@ -604,7 +604,7 @@ void print_frame(print_type ptype, spdylay_frame_type type, } // namespace 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) { print_timer(); @@ -617,29 +617,29 @@ namespace { const char* strstatus(uint32_t status_code) { switch(status_code) { - case SPDYLAY_OK: + case NGHTTP2_OK: return "OK"; - case SPDYLAY_PROTOCOL_ERROR: + case NGHTTP2_PROTOCOL_ERROR: return "PROTOCOL_ERROR"; - case SPDYLAY_INVALID_STREAM: + case NGHTTP2_INVALID_STREAM: return "INVALID_STREAM"; - case SPDYLAY_REFUSED_STREAM: + case NGHTTP2_REFUSED_STREAM: return "REFUSED_STREAM"; - case SPDYLAY_UNSUPPORTED_VERSION: + case NGHTTP2_UNSUPPORTED_VERSION: return "UNSUPPORTED_VERSION"; - case SPDYLAY_CANCEL: + case NGHTTP2_CANCEL: return "CANCEL"; - case SPDYLAY_INTERNAL_ERROR: + case NGHTTP2_INTERNAL_ERROR: return "INTERNAL_ERROR"; - case SPDYLAY_FLOW_CONTROL_ERROR: + case NGHTTP2_FLOW_CONTROL_ERROR: return "FLOW_CONTROL_ERROR"; - case SPDYLAY_STREAM_IN_USE: + case NGHTTP2_STREAM_IN_USE: return "STREAM_IN_USE"; - case SPDYLAY_STREAM_ALREADY_CLOSED: + case NGHTTP2_STREAM_ALREADY_CLOSED: return "STREAM_ALREADY_CLOSED"; - case SPDYLAY_INVALID_CREDENTIALS: + case NGHTTP2_INVALID_CREDENTIALS: return "INVALID_CREDENTIALS"; - case SPDYLAY_FRAME_TOO_LARGE: + case NGHTTP2_FRAME_TOO_LARGE: return "FRAME_TOO_LARGE"; default: return "Unknown status code"; @@ -648,7 +648,7 @@ const char* strstatus(uint32_t status_code) } // namespace 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) { print_timer(); @@ -670,8 +670,8 @@ void dump_header(const uint8_t *head, size_t headlen) } } // namespace -void on_ctrl_recv_parse_error_callback(spdylay_session *session, - spdylay_frame_type type, +void on_ctrl_recv_parse_error_callback(nghttp2_session *session, + nghttp2_frame_type type, const uint8_t *head, size_t headlen, const uint8_t *payload, @@ -684,12 +684,12 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session, ctrl_names[type-1], ansi_escend()); print_frame_attr_indent(); - printf("Error: %s\n", spdylay_strerror(error_code)); + printf("Error: %s\n", nghttp2_strerror(error_code)); dump_header(head, headlen); fflush(stdout); } -void on_unknown_ctrl_recv_callback(spdylay_session *session, +void on_unknown_ctrl_recv_callback(nghttp2_session *session, const uint8_t *head, size_t headlen, const uint8_t *payload, @@ -703,7 +703,7 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session, } 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) { print_timer(); @@ -723,7 +723,7 @@ void print_data_frame(print_type ptype, uint8_t flags, int32_t stream_id, } // namespace 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) { print_timer(); @@ -733,7 +733,7 @@ void on_data_recv_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) { print_timer(); @@ -772,7 +772,7 @@ int select_next_proto_cb(SSL* ssl, } std::string& next_proto = *(std::string*)arg; 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::endl; abort(); @@ -921,4 +921,4 @@ int get_time(timeval *tv) return rv; } -} // namespace spdylay +} // namespace nghttp2 diff --git a/src/spdylay_ssl.h b/src/nghttp2_ssl.h similarity index 81% rename from src/spdylay_ssl.h rename to src/nghttp2_ssl.h index 27a13af3..d2d06e78 100644 --- a/src/spdylay_ssl.h +++ b/src/nghttp2_ssl.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,10 +22,10 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_SSL_H -#define SPDYLAY_SSL_H +#ifndef NGHTTP2_SSL_H +#define NGHTTP2_SSL_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include #include @@ -35,16 +35,16 @@ #include #include -#include +#include -namespace spdylay { +namespace nghttp2 { extern bool ssl_debug; class Spdylay { public: Spdylay(int fd, SSL *ssl, uint16_t version, - const spdylay_session_callbacks *callbacks, + const nghttp2_session_callbacks *callbacks, void *user_data); ~Spdylay(); int recv(); @@ -59,17 +59,17 @@ public: const std::string& hostport, const std::string& path, const std::map& headers, uint8_t pri, - const spdylay_data_provider *data_prd, + const nghttp2_data_provider *data_prd, int64_t data_length, 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(); void* user_data(); private: int fd_; SSL *ssl_; uint16_t version_; - spdylay_session *session_; + nghttp2_session *session_; void *user_data_; uint8_t io_flags_; bool debug_; @@ -85,32 +85,32 @@ int make_non_block(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, 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); void print_nv(char **nv); 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 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); -void on_ctrl_recv_parse_error_callback(spdylay_session *session, - spdylay_frame_type type, +void on_ctrl_recv_parse_error_callback(nghttp2_session *session, + nghttp2_frame_type type, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, 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, size_t headlen, const uint8_t *payload, @@ -118,15 +118,15 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session, void *user_data); 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 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 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 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. void set_color_output(bool f); -} // namespace spdylay +} // namespace nghttp2 -#endif // SPDYLAY_SSL_H +#endif // NGHTTP2_SSL_H diff --git a/src/shrpx-unittest.cc b/src/shrpx-unittest.cc index 34c6bdf8..0d4231ad 100644 --- a/src/shrpx-unittest.cc +++ b/src/shrpx-unittest.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2013 Tatsuhiro Tsujikawa * diff --git a/src/shrpx.cc b/src/shrpx.cc index eccf8d62..d71a281e 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -47,7 +47,7 @@ #include -#include +#include #include "shrpx_config.h" #include "shrpx_listen_handler.h" @@ -324,7 +324,7 @@ void fill_default_config() mod_config()->daemon = 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"); mod_config()->port = 3000; mod_config()->private_key_file = 0; @@ -369,7 +369,7 @@ void fill_default_config() mod_config()->num_worker = 1; 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()->no_via = false; mod_config()->accesslog = false; diff --git a/src/shrpx.h b/src/shrpx.h index 7fefc4b5..e72c5a11 100644 --- a/src/shrpx.h +++ b/src/shrpx.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_accesslog.cc b/src/shrpx_accesslog.cc index 25d69fa5..abc1d8d1 100644 --- a/src/shrpx_accesslog.cc +++ b/src/shrpx_accesslog.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_accesslog.h b/src/shrpx_accesslog.h index f3569f42..66437113 100644 --- a/src/shrpx_accesslog.h +++ b/src/shrpx_accesslog.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index e2074d99..836c7bf5 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -209,7 +209,7 @@ int ClientHandler::validate_next_proto() std::string proto(next_proto, next_proto+next_proto_len); 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) { SpdyUpstream *spdy_upstream = new SpdyUpstream(version, this); upstream_ = spdy_upstream; diff --git a/src/shrpx_client_handler.h b/src/shrpx_client_handler.h index 18bd24df..d82237b4 100644 --- a/src/shrpx_client_handler.h +++ b/src/shrpx_client_handler.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 628db47c..28b07872 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -36,14 +36,14 @@ #include #include -#include +#include #include "shrpx_log.h" #include "shrpx_ssl.h" #include "shrpx_http.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { @@ -196,7 +196,7 @@ int parse_spdy_proto(const char *optarg) size_t len = strlen(optarg); const unsigned char *proto; proto = reinterpret_cast(optarg); - uint16_t version = spdylay_npn_get_version(proto, len); + uint16_t version = nghttp2_npn_get_version(proto, len); if(!version) { LOG(ERROR) << "Unsupported SPDY version: " << optarg; return -1; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index ba368f79..e2014e15 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index e915f0a9..a23c1c55 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -33,7 +33,7 @@ #include "shrpx_downstream_connection.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index 31b5ecab..c3ab91f2 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_downstream_connection.cc b/src/shrpx_downstream_connection.cc index 5aacd145..f33d9cac 100644 --- a/src/shrpx_downstream_connection.cc +++ b/src/shrpx_downstream_connection.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_downstream_connection.h b/src/shrpx_downstream_connection.h index 80b8fbf0..98433749 100644 --- a/src/shrpx_downstream_connection.h +++ b/src/shrpx_downstream_connection.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_downstream_queue.cc b/src/shrpx_downstream_queue.cc index 2d217127..52dea965 100644 --- a/src/shrpx_downstream_queue.cc +++ b/src/shrpx_downstream_queue.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_downstream_queue.h b/src/shrpx_downstream_queue.h index cf04f175..dd4b5c27 100644 --- a/src/shrpx_downstream_queue.h +++ b/src/shrpx_downstream_queue.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_error.h b/src/shrpx_error.h index 581b1d69..76b704b3 100644 --- a/src/shrpx_error.h +++ b/src/shrpx_error.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index f873b958..26585fca 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -28,7 +28,7 @@ #include "shrpx_log.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { diff --git a/src/shrpx_http.h b/src/shrpx_http.h index bd4e31fa..61b05235 100644 --- a/src/shrpx_http.h +++ b/src/shrpx_http.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index bff7aac2..68ca6a87 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -32,7 +32,7 @@ #include "shrpx_http.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { diff --git a/src/shrpx_http_downstream_connection.h b/src/shrpx_http_downstream_connection.h index 025ba939..87792b07 100644 --- a/src/shrpx_http_downstream_connection.h +++ b/src/shrpx_http_downstream_connection.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index a40a633c..44d4486c 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -38,7 +38,7 @@ #include "shrpx_accesslog.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { diff --git a/src/shrpx_https_upstream.h b/src/shrpx_https_upstream.h index e0513d86..b79caeae 100644 --- a/src/shrpx_https_upstream.h +++ b/src/shrpx_https_upstream.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_io_control.cc b/src/shrpx_io_control.cc index 9f04406d..cb558d39 100644 --- a/src/shrpx_io_control.cc +++ b/src/shrpx_io_control.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_io_control.h b/src/shrpx_io_control.h index 7395d7cb..aa3e638e 100644 --- a/src/shrpx_io_control.h +++ b/src/shrpx_io_control.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_listen_handler.cc b/src/shrpx_listen_handler.cc index 6a2dacda..e889478f 100644 --- a/src/shrpx_listen_handler.cc +++ b/src/shrpx_listen_handler.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_listen_handler.h b/src/shrpx_listen_handler.h index adde44e5..4804af8a 100644 --- a/src/shrpx_listen_handler.h +++ b/src/shrpx_listen_handler.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 2f9bb8b3..4519190d 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_log.h b/src/shrpx_log.h index cb1abf9e..0a58c8be 100644 --- a/src/shrpx_log.h +++ b/src/shrpx_log.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_spdy_downstream_connection.cc b/src/shrpx_spdy_downstream_connection.cc index 674d78ef..d4a5c328 100644 --- a/src/shrpx_spdy_downstream_connection.cc +++ b/src/shrpx_spdy_downstream_connection.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -41,7 +41,7 @@ #include "shrpx_spdy_session.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { @@ -146,25 +146,25 @@ int SpdyDownstreamConnection::submit_rst_stream(Downstream *downstream) } rv = spdy_->submit_rst_stream(this, downstream->get_downstream_stream_id(), - SPDYLAY_INTERNAL_ERROR); + NGHTTP2_INTERNAL_ERROR); } } return rv; } namespace { -ssize_t spdy_data_read_callback(spdylay_session *session, +ssize_t spdy_data_read_callback(nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, int *eof, - spdylay_data_source *source, + nghttp2_data_source *source, void *user_data) { StreamData *sd; sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, stream_id)); + (nghttp2_session_get_stream_user_data(session, stream_id)); if(!sd || !sd->dconn) { - return SPDYLAY_ERR_DEFERRED; + return NGHTTP2_ERR_DEFERRED; } SpdyDownstreamConnection *dconn; dconn = reinterpret_cast(source->ptr); @@ -172,7 +172,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session, if(!downstream) { // In this case, RST_STREAM should have been issued. But depending // on the priority, DATA frame may come first. - return SPDYLAY_ERR_DEFERRED; + return NGHTTP2_ERR_DEFERRED; } evbuffer *body = dconn->get_request_body_buf(); int nread = 0; @@ -188,12 +188,12 @@ ssize_t spdy_data_read_callback(spdylay_session *session, if(downstream->get_upstream()->resume_read(SHRPX_NO_BUFFER, downstream) == -1) { // In this case, downstream may be deleted. - return SPDYLAY_ERR_DEFERRED; + return NGHTTP2_ERR_DEFERRED; } // Check dconn is still alive because Upstream::resume_read() // may delete downstream which will delete dconn. if(sd->dconn == 0) { - return SPDYLAY_ERR_DEFERRED; + return NGHTTP2_ERR_DEFERRED; } if(evbuffer_get_length(body) == 0) { // Check get_request_state() == MSG_COMPLETE just in case @@ -201,7 +201,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session, *eof = 1; break; } - return SPDYLAY_ERR_DEFERRED; + return NGHTTP2_ERR_DEFERRED; } } } else { @@ -343,7 +343,7 @@ int SpdyDownstreamConnection::push_request_headers() if(downstream_->get_request_method() == "CONNECT" || chunked_encoding || content_length) { // Request-body is expected. - spdylay_data_provider data_prd; + nghttp2_data_provider data_prd; data_prd.source.ptr = this; data_prd.read_callback = spdy_data_read_callback; rv = spdy_->submit_request(this, 0, nv, &data_prd); @@ -352,7 +352,7 @@ int SpdyDownstreamConnection::push_request_headers() } delete [] nv; if(rv != 0) { - DCLOG(FATAL, this) << "spdylay_submit_request() failed"; + DCLOG(FATAL, this) << "nghttp2_submit_request() failed"; return -1; } spdy_->notify(); diff --git a/src/shrpx_spdy_downstream_connection.h b/src/shrpx_spdy_downstream_connection.h index 8ee8d09c..30f35d51 100644 --- a/src/shrpx_spdy_downstream_connection.h +++ b/src/shrpx_spdy_downstream_connection.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -29,7 +29,7 @@ #include -#include +#include #include "shrpx_downstream_connection.h" diff --git a/src/shrpx_spdy_session.cc b/src/shrpx_spdy_session.cc index ae029239..caa07bf7 100644 --- a/src/shrpx_spdy_session.cc +++ b/src/shrpx_spdy_session.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -42,7 +42,7 @@ #include "util.h" #include "base64.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { @@ -71,7 +71,7 @@ int SpdySession::disconnect() if(LOG_ENABLED(INFO)) { SSLOG(INFO, this) << "Disconnecting"; } - spdylay_session_del(session_); + nghttp2_session_del(session_); session_ = 0; if(ssl_) { @@ -547,17 +547,17 @@ void SpdySession::remove_stream_data(StreamData *sd) int SpdySession::submit_request(SpdyDownstreamConnection *dconn, uint8_t pri, const char **nv, - const spdylay_data_provider *data_prd) + const nghttp2_data_provider *data_prd) { assert(state_ == CONNECTED); StreamData *sd = new StreamData(); - int rv = spdylay_submit_request(session_, pri, nv, data_prd, sd); + int rv = nghttp2_submit_request(session_, pri, nv, data_prd, sd); if(rv == 0) { dconn->attach_stream_data(sd); streams_.insert(sd); } else { - SSLOG(FATAL, this) << "spdylay_submit_request() failed: " - << spdylay_strerror(rv); + SSLOG(FATAL, this) << "nghttp2_submit_request() failed: " + << nghttp2_strerror(rv); delete sd; return -1; } @@ -568,10 +568,10 @@ int SpdySession::submit_rst_stream(SpdyDownstreamConnection *dconn, int32_t stream_id, uint32_t status_code) { assert(state_ == CONNECTED); - int rv = spdylay_submit_rst_stream(session_, stream_id, status_code); + int rv = nghttp2_submit_rst_stream(session_, stream_id, status_code); if(rv != 0) { - SSLOG(FATAL, this) << "spdylay_submit_rst_stream() failed: " - << spdylay_strerror(rv); + SSLOG(FATAL, this) << "nghttp2_submit_rst_stream() failed: " + << nghttp2_strerror(rv); return -1; } return 0; @@ -584,10 +584,10 @@ int SpdySession::submit_window_update(SpdyDownstreamConnection *dconn, int rv; int32_t stream_id; stream_id = dconn->get_downstream()->get_downstream_stream_id(); - rv = spdylay_submit_window_update(session_, stream_id, amount); - if(rv < SPDYLAY_ERR_FATAL) { - SSLOG(FATAL, this) << "spdylay_submit_window_update() failed: " - << spdylay_strerror(rv); + rv = nghttp2_submit_window_update(session_, stream_id, amount); + if(rv < NGHTTP2_ERR_FATAL) { + SSLOG(FATAL, this) << "nghttp2_submit_window_update() failed: " + << nghttp2_strerror(rv); return -1; } return 0; @@ -607,15 +607,15 @@ int SpdySession::resume_data(SpdyDownstreamConnection *dconn) { assert(state_ == CONNECTED); Downstream *downstream = dconn->get_downstream(); - int rv = spdylay_session_resume_data(session_, + int rv = nghttp2_session_resume_data(session_, downstream->get_downstream_stream_id()); switch(rv) { case 0: - case SPDYLAY_ERR_INVALID_ARGUMENT: + case NGHTTP2_ERR_INVALID_ARGUMENT: return 0; default: - SSLOG(FATAL, this) << "spdylay_resume_session() failed: " - << spdylay_strerror(rv); + SSLOG(FATAL, this) << "nghttp2_resume_session() failed: " + << nghttp2_strerror(rv); return -1; } } @@ -633,7 +633,7 @@ void call_downstream_readcb(SpdySession *spdy, Downstream *downstream) } // namespace namespace { -ssize_t send_callback(spdylay_session *session, +ssize_t send_callback(nghttp2_session *session, const uint8_t *data, size_t len, int flags, void *user_data) { @@ -644,13 +644,13 @@ ssize_t send_callback(spdylay_session *session, evbuffer *output = bufferevent_get_output(bev); // Check buffer length and return WOULDBLOCK if it is large enough. if(evbuffer_get_length(output) > Downstream::OUTPUT_UPPER_THRES) { - return SPDYLAY_ERR_WOULDBLOCK; + return NGHTTP2_ERR_WOULDBLOCK; } rv = evbuffer_add(output, data, len); if(rv == -1) { SSLOG(FATAL, spdy) << "evbuffer_add() failed"; - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } else { return len; } @@ -658,7 +658,7 @@ ssize_t send_callback(spdylay_session *session, } // namespace namespace { -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) { SpdySession *spdy = reinterpret_cast(user_data); @@ -667,9 +667,9 @@ ssize_t recv_callback(spdylay_session *session, evbuffer *input = bufferevent_get_input(bev); int nread = evbuffer_remove(input, data, len); if(nread == -1) { - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } else if(nread == 0) { - return SPDYLAY_ERR_WOULDBLOCK; + return NGHTTP2_ERR_WOULDBLOCK; } else { return nread; } @@ -678,7 +678,7 @@ ssize_t recv_callback(spdylay_session *session, namespace { 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) { int rv; @@ -689,7 +689,7 @@ void on_stream_close_callback } StreamData *sd; sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, stream_id)); + (nghttp2_session_get_stream_user_data(session, stream_id)); if(sd == 0) { // We might get this close callback when pushed streams are // closed. @@ -700,7 +700,7 @@ void on_stream_close_callback Downstream *downstream = dconn->get_downstream(); if(downstream && downstream->get_downstream_stream_id() == stream_id) { Upstream *upstream = downstream->get_upstream(); - if(status_code == SPDYLAY_OK) { + if(status_code == NGHTTP2_OK) { downstream->set_response_state(Downstream::MSG_COMPLETE); rv = upstream->on_downstream_body_complete(downstream); if(rv != 0) { @@ -720,7 +720,7 @@ void on_stream_close_callback namespace { 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) { int rv; @@ -728,18 +728,18 @@ void on_ctrl_recv_callback StreamData *sd; Downstream *downstream; switch(type) { - case SPDYLAY_SYN_STREAM: + case NGHTTP2_SYN_STREAM: if(LOG_ENABLED(INFO)) { SSLOG(INFO, spdy) << "Received upstream SYN_STREAM stream_id=" << frame->syn_stream.stream_id; } // We just respond pushed stream with RST_STREAM. - spdylay_submit_rst_stream(session, frame->syn_stream.stream_id, - SPDYLAY_REFUSED_STREAM); + nghttp2_submit_rst_stream(session, frame->syn_stream.stream_id, + NGHTTP2_REFUSED_STREAM); break; - case SPDYLAY_RST_STREAM: + case NGHTTP2_RST_STREAM: sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, + (nghttp2_session_get_stream_user_data(session, frame->rst_stream.stream_id)); if(sd && sd->dconn) { downstream = sd->dconn->get_downstream(); @@ -769,20 +769,20 @@ void on_ctrl_recv_callback } } break; - case SPDYLAY_SYN_REPLY: { + case NGHTTP2_SYN_REPLY: { sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, + (nghttp2_session_get_stream_user_data(session, frame->syn_reply.stream_id)); if(!sd || !sd->dconn) { - spdylay_submit_rst_stream(session, frame->syn_reply.stream_id, - SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, frame->syn_reply.stream_id, + NGHTTP2_INTERNAL_ERROR); break; } downstream = sd->dconn->get_downstream(); if(!downstream || downstream->get_downstream_stream_id() != frame->syn_reply.stream_id) { - spdylay_submit_rst_stream(session, frame->syn_reply.stream_id, - SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, frame->syn_reply.stream_id, + NGHTTP2_INTERNAL_ERROR); break; } char **nv = frame->syn_reply.nv; @@ -813,8 +813,8 @@ void on_ctrl_recv_callback } } if(!status || !version) { - spdylay_submit_rst_stream(session, frame->syn_reply.stream_id, - SPDYLAY_PROTOCOL_ERROR); + nghttp2_submit_rst_stream(session, frame->syn_reply.stream_id, + NGHTTP2_PROTOCOL_ERROR); downstream->set_response_state(Downstream::MSG_RESET); call_downstream_readcb(spdy, downstream); return; @@ -858,8 +858,8 @@ void on_ctrl_recv_callback } rv = upstream->on_downstream_header_complete(downstream); if(rv != 0) { - spdylay_submit_rst_stream(session, frame->syn_reply.stream_id, - SPDYLAY_PROTOCOL_ERROR); + nghttp2_submit_rst_stream(session, frame->syn_reply.stream_id, + NGHTTP2_PROTOCOL_ERROR); downstream->set_response_state(Downstream::MSG_RESET); } call_downstream_readcb(spdy, downstream); @@ -872,7 +872,7 @@ void on_ctrl_recv_callback } // namespace namespace { -void on_data_chunk_recv_callback(spdylay_session *session, +void on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data) @@ -881,14 +881,14 @@ void on_data_chunk_recv_callback(spdylay_session *session, SpdySession *spdy = reinterpret_cast(user_data); StreamData *sd; sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, stream_id)); + (nghttp2_session_get_stream_user_data(session, stream_id)); if(!sd || !sd->dconn) { - spdylay_submit_rst_stream(session, stream_id, SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, stream_id, NGHTTP2_INTERNAL_ERROR); return; } Downstream *downstream = sd->dconn->get_downstream(); if(!downstream || downstream->get_downstream_stream_id() != stream_id) { - spdylay_submit_rst_stream(session, stream_id, SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, stream_id, NGHTTP2_INTERNAL_ERROR); return; } @@ -901,8 +901,8 @@ void on_data_chunk_recv_callback(spdylay_session *session, << ", initial_window_size=" << spdy->get_initial_window_size(); } - spdylay_submit_rst_stream(session, stream_id, - SPDYLAY_FLOW_CONTROL_ERROR); + nghttp2_submit_rst_stream(session, stream_id, + NGHTTP2_FLOW_CONTROL_ERROR); downstream->set_response_state(Downstream::MSG_RESET); call_downstream_readcb(spdy, downstream); return; @@ -912,7 +912,7 @@ void on_data_chunk_recv_callback(spdylay_session *session, Upstream *upstream = downstream->get_upstream(); rv = upstream->on_downstream_body(downstream, data, len); if(rv != 0) { - spdylay_submit_rst_stream(session, stream_id, SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, stream_id, NGHTTP2_INTERNAL_ERROR); downstream->set_response_state(Downstream::MSG_RESET); } call_downstream_readcb(spdy, downstream); @@ -920,48 +920,48 @@ void on_data_chunk_recv_callback(spdylay_session *session, } // namespace namespace { -void before_ctrl_send_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, +void before_ctrl_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, void *user_data) { - if(type == SPDYLAY_SYN_STREAM) { + if(type == NGHTTP2_SYN_STREAM) { StreamData *sd; sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, + (nghttp2_session_get_stream_user_data(session, frame->syn_stream.stream_id)); if(!sd || !sd->dconn) { - spdylay_submit_rst_stream(session, frame->syn_stream.stream_id, - SPDYLAY_CANCEL); + nghttp2_submit_rst_stream(session, frame->syn_stream.stream_id, + NGHTTP2_CANCEL); return; } Downstream *downstream = sd->dconn->get_downstream(); if(downstream) { downstream->set_downstream_stream_id(frame->syn_stream.stream_id); } else { - spdylay_submit_rst_stream(session, frame->syn_stream.stream_id, - SPDYLAY_CANCEL); + nghttp2_submit_rst_stream(session, frame->syn_stream.stream_id, + NGHTTP2_CANCEL); } } } } // namespace namespace { -void on_ctrl_not_send_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, +void on_ctrl_not_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, int error_code, void *user_data) { SpdySession *spdy = reinterpret_cast(user_data); SSLOG(WARNING, spdy) << "Failed to send control frame type=" << type << ", " << "error_code=" << error_code << ":" - << spdylay_strerror(error_code); - if(type == SPDYLAY_SYN_STREAM) { + << nghttp2_strerror(error_code); + if(type == NGHTTP2_SYN_STREAM) { // To avoid stream hanging around, flag Downstream::MSG_RESET and // terminate the upstream and downstream connections. StreamData *sd; sd = reinterpret_cast - (spdylay_session_get_stream_user_data(session, + (nghttp2_session_get_stream_user_data(session, frame->syn_stream.stream_id)); if(!sd) { return; @@ -982,8 +982,8 @@ void on_ctrl_not_send_callback(spdylay_session *session, } // namespace namespace { -void on_ctrl_recv_parse_error_callback(spdylay_session *session, - spdylay_frame_type type, +void on_ctrl_recv_parse_error_callback(nghttp2_session *session, + nghttp2_frame_type type, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, int error_code, @@ -994,13 +994,13 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session, SSLOG(INFO, spdy) << "Failed to parse received control frame. type=" << type << ", error_code=" << error_code << ":" - << spdylay_strerror(error_code); + << nghttp2_strerror(error_code); } } } // namespace namespace { -void on_unknown_ctrl_recv_callback(spdylay_session *session, +void on_unknown_ctrl_recv_callback(nghttp2_session *session, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, void *user_data) @@ -1025,14 +1025,14 @@ int SpdySession::on_connect() std::string proto(next_proto, next_proto+next_proto_len); SSLOG(INFO, this) << "Negotiated next protocol: " << proto; } - version = spdylay_npn_get_version(next_proto, next_proto_len); + version = nghttp2_npn_get_version(next_proto, next_proto_len); if(!version) { return -1; } } else { version = get_config()->spdy_downstream_version; } - spdylay_session_callbacks callbacks; + nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); callbacks.send_callback = send_callback; callbacks.recv_callback = recv_callback; @@ -1045,34 +1045,34 @@ int SpdySession::on_connect() on_ctrl_recv_parse_error_callback; callbacks.on_unknown_ctrl_recv_callback = on_unknown_ctrl_recv_callback; - rv = spdylay_session_client_new(&session_, version, &callbacks, this); + rv = nghttp2_session_client_new(&session_, version, &callbacks, this); if(rv != 0) { return -1; } - if(version == SPDYLAY_PROTO_SPDY3) { + if(version == NGHTTP2_PROTO_SPDY3) { int val = 1; flow_control_ = true; - rv = spdylay_session_set_option(session_, - SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE, &val, + rv = nghttp2_session_set_option(session_, + NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE, &val, sizeof(val)); assert(rv == 0); } else { flow_control_ = false; } - spdylay_settings_entry entry[2]; - entry[0].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; + nghttp2_settings_entry entry[2]; + entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; entry[0].value = get_config()->spdy_max_concurrent_streams; - entry[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + entry[0].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; - entry[1].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; + entry[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; entry[1].value = get_initial_window_size(); - entry[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + entry[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; - rv = spdylay_submit_settings - (session_, SPDYLAY_FLAG_SETTINGS_NONE, - entry, sizeof(entry)/sizeof(spdylay_settings_entry)); + rv = nghttp2_submit_settings + (session_, NGHTTP2_FLAG_SETTINGS_NONE, + entry, sizeof(entry)/sizeof(nghttp2_settings_entry)); if(rv != 0) { return -1; } @@ -1094,18 +1094,18 @@ int SpdySession::on_connect() int SpdySession::on_read() { int rv = 0; - if((rv = spdylay_session_recv(session_)) < 0) { - if(rv != SPDYLAY_ERR_EOF) { - SSLOG(ERROR, this) << "spdylay_session_recv() returned error: " - << spdylay_strerror(rv); + if((rv = nghttp2_session_recv(session_)) < 0) { + if(rv != NGHTTP2_ERR_EOF) { + SSLOG(ERROR, this) << "nghttp2_session_recv() returned error: " + << nghttp2_strerror(rv); } - } else if((rv = spdylay_session_send(session_)) < 0) { - SSLOG(ERROR, this) << "spdylay_session_send() returned error: " - << spdylay_strerror(rv); + } else if((rv = nghttp2_session_send(session_)) < 0) { + SSLOG(ERROR, this) << "nghttp2_session_send() returned error: " + << nghttp2_strerror(rv); } if(rv == 0) { - if(spdylay_session_want_read(session_) == 0 && - spdylay_session_want_write(session_) == 0) { + if(nghttp2_session_want_read(session_) == 0 && + nghttp2_session_want_write(session_) == 0) { if(LOG_ENABLED(INFO)) { SSLOG(INFO, this) << "No more read/write for this session"; } @@ -1123,13 +1123,13 @@ int SpdySession::on_write() int SpdySession::send() { int rv = 0; - if((rv = spdylay_session_send(session_)) < 0) { - SSLOG(ERROR, this) << "spdylay_session_send() returned error: " - << spdylay_strerror(rv); + if((rv = nghttp2_session_send(session_)) < 0) { + SSLOG(ERROR, this) << "nghttp2_session_send() returned error: " + << nghttp2_strerror(rv); } if(rv == 0) { - if(spdylay_session_want_read(session_) == 0 && - spdylay_session_want_write(session_) == 0) { + if(nghttp2_session_want_read(session_) == 0 && + nghttp2_session_want_write(session_) == 0) { if(LOG_ENABLED(INFO)) { SSLOG(INFO, this) << "No more read/write for this session"; } diff --git a/src/shrpx_spdy_session.h b/src/shrpx_spdy_session.h index c728f355..0093f0b8 100644 --- a/src/shrpx_spdy_session.h +++ b/src/shrpx_spdy_session.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -34,7 +34,7 @@ #include #include -#include +#include #include "http-parser/http_parser.h" @@ -65,7 +65,7 @@ public: int submit_request(SpdyDownstreamConnection *dconn, uint8_t pri, const char **nv, - const spdylay_data_provider *data_prd); + const nghttp2_data_provider *data_prd); int submit_rst_stream(SpdyDownstreamConnection *dconn, int32_t stream_id, uint32_t status_code); @@ -119,7 +119,7 @@ private: // established. Use bufferevent_getfd(bev_) to get file descriptor // in these cases. int fd_; - spdylay_session *session_; + nghttp2_session *session_; bufferevent *bev_; std::set dconns_; std::set streams_; diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 78d7946b..0e2c5014 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -37,7 +37,7 @@ #include "shrpx_accesslog.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { @@ -46,7 +46,7 @@ const size_t SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES = 64*1024; } // namespace namespace { -ssize_t send_callback(spdylay_session *session, +ssize_t send_callback(nghttp2_session *session, const uint8_t *data, size_t len, int flags, void *user_data) { @@ -57,13 +57,13 @@ ssize_t send_callback(spdylay_session *session, evbuffer *output = bufferevent_get_output(bev); // Check buffer length and return WOULDBLOCK if it is large enough. if(evbuffer_get_length(output) > SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES) { - return SPDYLAY_ERR_WOULDBLOCK; + return NGHTTP2_ERR_WOULDBLOCK; } rv = evbuffer_add(output, data, len); if(rv == -1) { ULOG(FATAL, upstream) << "evbuffer_add() failed"; - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } else { return len; } @@ -71,7 +71,7 @@ ssize_t send_callback(spdylay_session *session, } // namespace namespace { -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) { SpdyUpstream *upstream = reinterpret_cast(user_data); @@ -80,9 +80,9 @@ ssize_t recv_callback(spdylay_session *session, evbuffer *input = bufferevent_get_input(bev); int nread = evbuffer_remove(input, data, len); if(nread == -1) { - return SPDYLAY_ERR_CALLBACK_FAILURE; + return NGHTTP2_ERR_CALLBACK_FAILURE; } else if(nread == 0) { - return SPDYLAY_ERR_WOULDBLOCK; + return NGHTTP2_ERR_WOULDBLOCK; } else { return nread; } @@ -91,7 +91,7 @@ ssize_t recv_callback(spdylay_session *session, namespace { 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) { SpdyUpstream *upstream = reinterpret_cast(user_data); @@ -137,12 +137,12 @@ void on_stream_close_callback namespace { 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) { SpdyUpstream *upstream = reinterpret_cast(user_data); switch(type) { - case SPDYLAY_SYN_STREAM: { + case NGHTTP2_SYN_STREAM: { if(LOG_ENABLED(INFO)) { ULOG(INFO, upstream) << "Received upstream SYN_STREAM stream_id=" << frame->syn_stream.stream_id; @@ -174,7 +174,7 @@ void on_ctrl_recv_callback } } if(!path || !host || !method) { - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); return; } // SpdyDownstreamConnection examines request path to find @@ -208,17 +208,17 @@ void on_ctrl_recv_callback int rv = dconn->attach_downstream(downstream); if(rv != 0) { // If downstream connection fails, issue RST_STREAM. - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); downstream->set_request_state(Downstream::CONNECT_FAIL); return; } rv = downstream->push_request_headers(); if(rv != 0) { - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); return; } downstream->set_request_state(Downstream::HEADER_COMPLETE); - if(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { + if(frame->syn_stream.hd.flags & NGHTTP2_CTRL_FLAG_FIN) { downstream->set_request_state(Downstream::MSG_COMPLETE); } break; @@ -230,7 +230,7 @@ void on_ctrl_recv_callback } // namespace namespace { -void on_data_chunk_recv_callback(spdylay_session *session, +void on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data) @@ -239,7 +239,7 @@ void on_data_chunk_recv_callback(spdylay_session *session, Downstream *downstream = upstream->find_downstream(stream_id); if(downstream) { if(downstream->push_upload_data_chunk(data, len) != 0) { - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); return; } if(upstream->get_flow_control()) { @@ -252,11 +252,11 @@ void on_data_chunk_recv_callback(spdylay_session *session, << ", initial_window_size=" << upstream->get_initial_window_size(); } - upstream->rst_stream(downstream, SPDYLAY_FLOW_CONTROL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_FLOW_CONTROL_ERROR); return; } } - if(flags & SPDYLAY_DATA_FLAG_FIN) { + if(flags & NGHTTP2_DATA_FLAG_FIN) { downstream->set_request_state(Downstream::MSG_COMPLETE); } } @@ -264,29 +264,29 @@ void on_data_chunk_recv_callback(spdylay_session *session, } // namespace namespace { -void on_ctrl_not_send_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, +void on_ctrl_not_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, int error_code, void *user_data) { SpdyUpstream *upstream = reinterpret_cast(user_data); ULOG(WARNING, upstream) << "Failed to send control frame type=" << type << ", error_code=" << error_code << ":" - << spdylay_strerror(error_code); - if(type == SPDYLAY_SYN_REPLY) { + << nghttp2_strerror(error_code); + if(type == NGHTTP2_SYN_REPLY) { // To avoid stream hanging around, issue RST_STREAM. int32_t stream_id = frame->syn_reply.stream_id; Downstream *downstream = upstream->find_downstream(stream_id); if(downstream) { - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); } } } } // namespace namespace { -void on_ctrl_recv_parse_error_callback(spdylay_session *session, - spdylay_frame_type type, +void on_ctrl_recv_parse_error_callback(nghttp2_session *session, + nghttp2_frame_type type, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, int error_code, @@ -297,13 +297,13 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session, ULOG(INFO, upstream) << "Failed to parse received control frame. type=" << type << ", error_code=" << error_code << ":" - << spdylay_strerror(error_code); + << nghttp2_strerror(error_code); } } } // namespace namespace { -void on_unknown_ctrl_recv_callback(spdylay_session *session, +void on_unknown_ctrl_recv_callback(nghttp2_session *session, const uint8_t *head, size_t headlen, const uint8_t *payload, size_t payloadlen, void *user_data) @@ -318,10 +318,10 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session, namespace { uint32_t infer_upstream_rst_stream_status_code(uint32_t downstream_status_code) { - // Only propagate SPDYLAY_REFUSED_STREAM so that upstream client + // Only propagate NGHTTP2_REFUSED_STREAM so that upstream client // can resend request. - if(downstream_status_code != SPDYLAY_REFUSED_STREAM) { - return SPDYLAY_INTERNAL_ERROR; + if(downstream_status_code != NGHTTP2_REFUSED_STREAM) { + return NGHTTP2_INTERNAL_ERROR; } else { return downstream_status_code; } @@ -336,7 +336,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler) handler->set_upstream_timeouts(&get_config()->spdy_upstream_read_timeout, &get_config()->upstream_write_timeout); - spdylay_session_callbacks callbacks; + nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); callbacks.send_callback = send_callback; callbacks.recv_callback = recv_callback; @@ -349,15 +349,15 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler) callbacks.on_unknown_ctrl_recv_callback = on_unknown_ctrl_recv_callback; int rv; - rv = spdylay_session_server_new(&session_, version, &callbacks, this); + rv = nghttp2_session_server_new(&session_, version, &callbacks, this); assert(rv == 0); - if(version == SPDYLAY_PROTO_SPDY3) { + if(version == NGHTTP2_PROTO_SPDY3) { int val = 1; flow_control_ = true; initial_window_size_ = 1 << get_config()->spdy_upstream_window_bits; - rv = spdylay_session_set_option(session_, - SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE, &val, + rv = nghttp2_session_set_option(session_, + NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE, &val, sizeof(val)); assert(rv == 0); } else { @@ -365,18 +365,18 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler) initial_window_size_ = 0; } // TODO Maybe call from outside? - spdylay_settings_entry entry[2]; - entry[0].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; + nghttp2_settings_entry entry[2]; + entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; entry[0].value = get_config()->spdy_max_concurrent_streams; - entry[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + entry[0].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; - entry[1].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; + entry[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; entry[1].value = initial_window_size_; - entry[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + entry[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; - rv = spdylay_submit_settings - (session_, SPDYLAY_FLAG_SETTINGS_NONE, - entry, sizeof(entry)/sizeof(spdylay_settings_entry)); + rv = nghttp2_submit_settings + (session_, NGHTTP2_FLAG_SETTINGS_NONE, + entry, sizeof(entry)/sizeof(nghttp2_settings_entry)); assert(rv == 0); // TODO Maybe call from outside? send(); @@ -384,24 +384,24 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler) SpdyUpstream::~SpdyUpstream() { - spdylay_session_del(session_); + nghttp2_session_del(session_); } int SpdyUpstream::on_read() { int rv = 0; - if((rv = spdylay_session_recv(session_)) < 0) { - if(rv != SPDYLAY_ERR_EOF) { - ULOG(ERROR, this) << "spdylay_session_recv() returned error: " - << spdylay_strerror(rv); + if((rv = nghttp2_session_recv(session_)) < 0) { + if(rv != NGHTTP2_ERR_EOF) { + ULOG(ERROR, this) << "nghttp2_session_recv() returned error: " + << nghttp2_strerror(rv); } - } else if((rv = spdylay_session_send(session_)) < 0) { - ULOG(ERROR, this) << "spdylay_session_send() returned error: " - << spdylay_strerror(rv); + } else if((rv = nghttp2_session_send(session_)) < 0) { + ULOG(ERROR, this) << "nghttp2_session_send() returned error: " + << nghttp2_strerror(rv); } if(rv == 0) { - if(spdylay_session_want_read(session_) == 0 && - spdylay_session_want_write(session_) == 0) { + if(nghttp2_session_want_read(session_) == 0 && + nghttp2_session_want_write(session_) == 0) { if(LOG_ENABLED(INFO)) { ULOG(INFO, this) << "No more read/write for this SPDY session"; } @@ -420,13 +420,13 @@ int SpdyUpstream::on_write() int SpdyUpstream::send() { int rv = 0; - if((rv = spdylay_session_send(session_)) < 0) { - ULOG(ERROR, this) << "spdylay_session_send() returned error: " - << spdylay_strerror(rv); + if((rv = nghttp2_session_send(session_)) < 0) { + ULOG(ERROR, this) << "nghttp2_session_send() returned error: " + << nghttp2_strerror(rv); } if(rv == 0) { - if(spdylay_session_want_read(session_) == 0 && - spdylay_session_want_write(session_) == 0) { + if(nghttp2_session_want_read(session_) == 0 && + nghttp2_session_want_write(session_) == 0) { if(LOG_ENABLED(INFO)) { ULOG(INFO, this) << "No more read/write for this SPDY session"; } @@ -479,7 +479,7 @@ void spdy_downstream_readcb(bufferevent *bev, void *ptr) DCLOG(INFO, dconn) << "HTTP parser failure"; } if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) { - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); } else { if(upstream->error_reply(downstream, 502) != 0) { delete upstream->get_client_handler(); @@ -602,10 +602,10 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr) dconn = 0; if(downstream->get_response_state() == Downstream::MSG_COMPLETE) { // For SSL tunneling - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); } else { if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) { - upstream->rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); + upstream->rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); } else { int status; if(events & BEV_EVENT_TIMEOUT) { @@ -637,11 +637,11 @@ int SpdyUpstream::rst_stream(Downstream *downstream, int status_code) << downstream->get_stream_id(); } int rv; - rv = spdylay_submit_rst_stream(session_, downstream->get_stream_id(), + rv = nghttp2_submit_rst_stream(session_, downstream->get_stream_id(), status_code); - if(rv < SPDYLAY_ERR_FATAL) { - ULOG(FATAL, this) << "spdylay_submit_rst_stream() failed: " - << spdylay_strerror(rv); + if(rv < NGHTTP2_ERR_FATAL) { + ULOG(FATAL, this) << "nghttp2_submit_rst_stream() failed: " + << nghttp2_strerror(rv); DIE(); } return 0; @@ -650,23 +650,23 @@ int SpdyUpstream::rst_stream(Downstream *downstream, int status_code) int SpdyUpstream::window_update(Downstream *downstream) { int rv; - rv = spdylay_submit_window_update(session_, downstream->get_stream_id(), + rv = nghttp2_submit_window_update(session_, downstream->get_stream_id(), downstream->get_recv_window_size()); downstream->set_recv_window_size(0); - if(rv < SPDYLAY_ERR_FATAL) { - ULOG(FATAL, this) << "spdylay_submit_window_update() failed: " - << spdylay_strerror(rv); + if(rv < NGHTTP2_ERR_FATAL) { + ULOG(FATAL, this) << "nghttp2_submit_window_update() failed: " + << nghttp2_strerror(rv); DIE(); } return 0; } namespace { -ssize_t spdy_data_read_callback(spdylay_session *session, +ssize_t spdy_data_read_callback(nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, int *eof, - spdylay_data_source *source, + nghttp2_data_source *source, void *user_data) { Downstream *downstream = reinterpret_cast(source->ptr); @@ -690,7 +690,7 @@ ssize_t spdy_data_read_callback(spdylay_session *session, } } if(nread == 0 && *eof != 1) { - return SPDYLAY_ERR_DEFERRED; + return NGHTTP2_ERR_DEFERRED; } return nread; } @@ -709,7 +709,7 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code) } downstream->set_response_state(Downstream::MSG_COMPLETE); - spdylay_data_provider data_prd; + nghttp2_data_provider data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = spdy_data_read_callback; @@ -724,11 +724,11 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code) 0 }; - rv = spdylay_submit_response(session_, downstream->get_stream_id(), nv, + rv = nghttp2_submit_response(session_, downstream->get_stream_id(), nv, &data_prd); - if(rv < SPDYLAY_ERR_FATAL) { - ULOG(FATAL, this) << "spdylay_submit_response() failed: " - << spdylay_strerror(rv); + if(rv < NGHTTP2_ERR_FATAL) { + ULOG(FATAL, this) << "nghttp2_submit_response() failed: " + << nghttp2_strerror(rv); DIE(); } if(get_config()->accesslog) { @@ -768,13 +768,13 @@ Downstream* SpdyUpstream::find_downstream(int32_t stream_id) return downstream_queue_.find(stream_id); } -spdylay_session* SpdyUpstream::get_spdy_session() +nghttp2_session* SpdyUpstream::get_spdy_session() { return session_; } -// WARNING: Never call directly or indirectly spdylay_session_send or -// spdylay_session_recv. These calls may delete downstream. +// WARNING: Never call directly or indirectly nghttp2_session_send or +// nghttp2_session_recv. These calls may delete downstream. int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) { if(LOG_ENABLED(INFO)) { @@ -823,16 +823,16 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) << downstream->get_stream_id() << "\n" << ss.str(); } - spdylay_data_provider data_prd; + nghttp2_data_provider data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = spdy_data_read_callback; int rv; - rv = spdylay_submit_response(session_, downstream->get_stream_id(), nv, + rv = nghttp2_submit_response(session_, downstream->get_stream_id(), nv, &data_prd); delete [] nv; if(rv != 0) { - ULOG(FATAL, this) << "spdylay_submit_response() failed"; + ULOG(FATAL, this) << "nghttp2_submit_response() failed"; return -1; } if(get_config()->accesslog) { @@ -843,8 +843,8 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) return 0; } -// WARNING: Never call directly or indirectly spdylay_session_send or -// spdylay_session_recv. These calls may delete downstream. +// WARNING: Never call directly or indirectly nghttp2_session_send or +// nghttp2_session_recv. These calls may delete downstream. int SpdyUpstream::on_downstream_body(Downstream *downstream, const uint8_t *data, size_t len) { @@ -854,7 +854,7 @@ int SpdyUpstream::on_downstream_body(Downstream *downstream, ULOG(FATAL, this) << "evbuffer_add() failed"; return -1; } - spdylay_session_resume_data(session_, downstream->get_stream_id()); + nghttp2_session_resume_data(session_, downstream->get_stream_id()); size_t bodylen = evbuffer_get_length(body); if(bodylen > SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES) { @@ -864,14 +864,14 @@ int SpdyUpstream::on_downstream_body(Downstream *downstream, return 0; } -// WARNING: Never call directly or indirectly spdylay_session_send or -// spdylay_session_recv. These calls may delete downstream. +// WARNING: Never call directly or indirectly nghttp2_session_send or +// nghttp2_session_recv. These calls may delete downstream. int SpdyUpstream::on_downstream_body_complete(Downstream *downstream) { if(LOG_ENABLED(INFO)) { DLOG(INFO, downstream) << "HTTP response completed"; } - spdylay_session_resume_data(session_, downstream->get_stream_id()); + nghttp2_session_resume_data(session_, downstream->get_stream_id()); return 0; } diff --git a/src/shrpx_spdy_upstream.h b/src/shrpx_spdy_upstream.h index 8734edee..366e2410 100644 --- a/src/shrpx_spdy_upstream.h +++ b/src/shrpx_spdy_upstream.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -27,7 +27,7 @@ #include "shrpx.h" -#include +#include #include "shrpx_upstream.h" #include "shrpx_downstream_queue.h" @@ -52,7 +52,7 @@ public: void remove_downstream(Downstream *downstream); Downstream* find_downstream(int32_t stream_id); - spdylay_session* get_spdy_session(); + nghttp2_session* get_spdy_session(); int rst_stream(Downstream *downstream, int status_code); int window_update(Downstream *downstream); @@ -70,7 +70,7 @@ public: int32_t get_initial_window_size() const; private: ClientHandler *handler_; - spdylay_session *session_; + nghttp2_session *session_; bool flow_control_; int32_t initial_window_size_; DownstreamQueue downstream_queue_; diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index a4ded9fc..51eb1247 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -39,7 +39,7 @@ #include #include -#include +#include #include "shrpx_log.h" #include "shrpx_client_handler.h" @@ -47,7 +47,7 @@ #include "shrpx_accesslog.h" #include "util.h" -using namespace spdylay; +using namespace nghttp2; namespace shrpx { @@ -198,7 +198,7 @@ int select_next_proto_cb(SSL* ssl, const unsigned char *in, unsigned int inlen, void *arg) { - if(spdylay_select_next_protocol(out, outlen, in, inlen) <= 0) { + if(nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) { *out = (unsigned char*)"spdy/3"; *outlen = 6; } diff --git a/src/shrpx_ssl.h b/src/shrpx_ssl.h index 60374fa8..fb1a2eca 100644 --- a/src/shrpx_ssl.h +++ b/src/shrpx_ssl.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_ssl_test.cc b/src/shrpx_ssl_test.cc index d31ca269..4f98753d 100644 --- a/src/shrpx_ssl_test.cc +++ b/src/shrpx_ssl_test.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2013 Tatsuhiro Tsujikawa * @@ -49,7 +49,7 @@ void test_shrpx_ssl_create_lookup_tree(void) "*www.example.org", "x*.host.domain", "*yy.host.domain", - "spdylay.sourceforge.net", + "nghttp2.sourceforge.net", "sourceforge.net", "sourceforge.net", // duplicate "*.foo.bar", // oo.bar is suffix of *.foo.bar @@ -120,7 +120,7 @@ void test_shrpx_ssl_cert_lookup_tree_add_cert_from_file(void) int rv; ssl::CertLookupTree* tree = ssl::cert_lookup_tree_new(); SSL_CTX *ssl_ctx = SSL_CTX_new(TLSv1_method()); - const char certfile[] = SPDYLAY_TESTS_DIR"/testdata/cacert.pem"; + const char certfile[] = NGHTTP2_TESTS_DIR"/testdata/cacert.pem"; rv = ssl::cert_lookup_tree_add_cert_from_file(tree, ssl_ctx, certfile); CU_ASSERT(0 == rv); const char localhost[] = "localhost"; diff --git a/src/shrpx_ssl_test.h b/src/shrpx_ssl_test.h index ff9967f8..1c50c70a 100644 --- a/src/shrpx_ssl_test.h +++ b/src/shrpx_ssl_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2013 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_thread_event_receiver.cc b/src/shrpx_thread_event_receiver.cc index 8d5c2c35..ef0ea1a9 100644 --- a/src/shrpx_thread_event_receiver.cc +++ b/src/shrpx_thread_event_receiver.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_thread_event_receiver.h b/src/shrpx_thread_event_receiver.h index c76ad333..587f44f3 100644 --- a/src/shrpx_thread_event_receiver.h +++ b/src/shrpx_thread_event_receiver.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_upstream.h b/src/shrpx_upstream.h index ab655ba9..03a40417 100644 --- a/src/shrpx_upstream.h +++ b/src/shrpx_upstream.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index a0b4587d..5328120b 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/shrpx_worker.h b/src/shrpx_worker.h index e0c2d8f1..6e0a3aec 100644 --- a/src/shrpx_worker.h +++ b/src/shrpx_worker.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * diff --git a/src/spdycat.cc b/src/spdycat.cc index 6d324bb6..b371c3c6 100644 --- a/src/spdycat.cc +++ b/src/spdycat.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,7 +22,7 @@ * 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_config.h" +#include "nghttp2_config.h" #include #include @@ -53,11 +53,11 @@ #include #include -#include +#include #include "http-parser/http_parser.h" -#include "spdylay_ssl.h" +#include "nghttp2_ssl.h" #include "HtmlParser.h" #include "util.h" @@ -65,7 +65,7 @@ # define O_BINARY (0) #endif // O_BINARY -namespace spdylay { +namespace nghttp2 { struct Config { bool null_out; @@ -206,9 +206,9 @@ struct Request { // URI without fragment std::string uri; http_parser_url u; - spdylay_gzip *inflater; + nghttp2_gzip *inflater; HtmlParser *html_parser; - const spdylay_data_provider *data_prd; + const nghttp2_data_provider *data_prd; int64_t data_length; int64_t data_offset; // Recursion level: 0: first entity, 1: entity linked from first entity @@ -216,7 +216,7 @@ struct Request { RequestStat stat; std::string status; Request(const std::string& uri, const http_parser_url &u, - const spdylay_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider *data_prd, int64_t data_length, int level = 0) : uri(uri), u(u), inflater(0), html_parser(0), data_prd(data_prd), @@ -226,14 +226,14 @@ struct Request { ~Request() { - spdylay_gzip_inflate_del(inflater); + nghttp2_gzip_inflate_del(inflater); delete html_parser; } void init_inflater() { int rv; - rv = spdylay_gzip_inflate_new(&inflater); + rv = nghttp2_gzip_inflate_new(&inflater); assert(rv == 0); } @@ -346,7 +346,7 @@ struct SpdySession { hostport = ss.str(); } bool add_request(const std::string& uri, const http_parser_url& u, - const spdylay_data_provider *data_prd, + const nghttp2_data_provider *data_prd, int64_t data_length, int level = 0) { @@ -412,7 +412,7 @@ SpdySession* get_session(void *user_data) } 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) { SpdySession *spdySession = get_session(user_data); @@ -426,9 +426,9 @@ void on_data_chunk_recv_callback uint8_t out[MAX_OUTLEN]; size_t outlen = MAX_OUTLEN; size_t tlen = len; - int rv = spdylay_gzip_inflate(req->inflater, out, &outlen, data, &tlen); + int rv = nghttp2_gzip_inflate(req->inflater, out, &outlen, data, &tlen); if(rv != 0) { - spdylay_submit_rst_stream(session, stream_id, SPDYLAY_INTERNAL_ERROR); + nghttp2_submit_rst_stream(session, stream_id, NGHTTP2_INTERNAL_ERROR); break; } if(!config.null_out) { @@ -447,23 +447,23 @@ void on_data_chunk_recv_callback } } -void check_stream_id(spdylay_session *session, - spdylay_frame_type type, spdylay_frame *frame, +void check_stream_id(nghttp2_session *session, + nghttp2_frame_type type, nghttp2_frame *frame, void *user_data) { SpdySession *spdySession = get_session(user_data); int32_t stream_id = frame->syn_stream.stream_id; - Request *req = (Request*)spdylay_session_get_stream_user_data(session, + Request *req = (Request*)nghttp2_session_get_stream_user_data(session, stream_id); spdySession->streams[stream_id] = req; req->record_syn_stream_time(); } void on_ctrl_send_callback2 -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, void *user_data) { - if(type == SPDYLAY_SYN_STREAM) { + if(type == NGHTTP2_SYN_STREAM) { check_stream_id(session, type, frame, user_data); } if(config.verbose) { @@ -472,21 +472,21 @@ void on_ctrl_send_callback2 } void check_response_header -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, void *user_data) { char **nv; int32_t stream_id; - if(type == SPDYLAY_SYN_REPLY) { + if(type == NGHTTP2_SYN_REPLY) { nv = frame->syn_reply.nv; stream_id = frame->syn_reply.stream_id; - } else if(type == SPDYLAY_HEADERS) { + } else if(type == NGHTTP2_HEADERS) { nv = frame->headers.nv; stream_id = frame->headers.stream_id; } else { return; } - Request *req = (Request*)spdylay_session_get_stream_user_data(session, + Request *req = (Request*)nghttp2_session_get_stream_user_data(session, stream_id); if(!req) { // Server-pushed stream does not have stream user data @@ -513,11 +513,11 @@ void check_response_header } void on_ctrl_recv_callback2 -(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, +(nghttp2_session *session, nghttp2_frame_type type, nghttp2_frame *frame, void *user_data) { - if(type == SPDYLAY_SYN_REPLY) { - Request *req = (Request*)spdylay_session_get_stream_user_data + if(type == NGHTTP2_SYN_REPLY) { + Request *req = (Request*)nghttp2_session_get_stream_user_data (session, frame->syn_reply.stream_id); assert(req); req->record_syn_reply_time(); @@ -529,7 +529,7 @@ void on_ctrl_recv_callback2 } 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) { SpdySession *spdySession = get_session(user_data); @@ -540,7 +540,7 @@ void on_stream_close_callback (*itr).second->record_complete_time(); ++spdySession->complete; if(spdySession->all_requests_processed()) { - spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK); + nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK); } } } @@ -579,7 +579,7 @@ void print_stats(const SpdySession& spdySession) } int spdy_evloop(int fd, SSL *ssl, int spdy_version, SpdySession& spdySession, - const spdylay_session_callbacks *callbacks, int timeout) + const nghttp2_session_callbacks *callbacks, int timeout) { int result = 0; Spdylay sc(fd, ssl, spdy_version, callbacks, &spdySession); @@ -588,12 +588,12 @@ int spdy_evloop(int fd, SSL *ssl, int spdy_version, SpdySession& spdySession, nfds_t npollfds = 1; pollfd pollfds[1]; - if(spdy_version >= SPDYLAY_PROTO_SPDY3 && config.window_bits != -1) { - spdylay_settings_entry iv[1]; - iv[0].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + if(spdy_version >= NGHTTP2_PROTO_SPDY3 && config.window_bits != -1) { + nghttp2_settings_entry iv[1]; + iv[0].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; iv[0].value = 1 << config.window_bits; - int rv = sc.submit_settings(SPDYLAY_FLAG_SETTINGS_NONE, iv, 1); + int rv = sc.submit_settings(NGHTTP2_FLAG_SETTINGS_NONE, iv, 1); assert(rv == 0); } for(int i = 0, n = spdySession.reqvec.size(); i < n; ++i) { @@ -617,8 +617,8 @@ int spdy_evloop(int fd, SSL *ssl, int spdy_version, SpdySession& spdySession, if(pollfds[0].revents & (POLLIN | POLLOUT)) { int rv; if((rv = sc.recv()) != 0 || (rv = sc.send()) != 0) { - if(rv != SPDYLAY_ERR_EOF || !spdySession.all_requests_processed()) { - std::cerr << "Fatal: " << spdylay_strerror(rv) << "\n" + if(rv != NGHTTP2_ERR_EOF || !spdySession.all_requests_processed()) { + std::cerr << "Fatal: " << nghttp2_strerror(rv) << "\n" << "reqnum=" << spdySession.reqvec.size() << ", completed=" << spdySession.complete << std::endl; } @@ -656,7 +656,7 @@ int spdy_evloop(int fd, SSL *ssl, int spdy_version, SpdySession& spdySession, int communicate(const std::string& host, uint16_t port, SpdySession& spdySession, - const spdylay_session_callbacks *callbacks) + const nghttp2_session_callbacks *callbacks) { int result = 0; int rv; @@ -684,10 +684,10 @@ int communicate(const std::string& host, uint16_t port, } switch(config.spdy_version) { - case SPDYLAY_PROTO_SPDY2: + case NGHTTP2_PROTO_SPDY2: next_proto = "spdy/2"; break; - case SPDYLAY_PROTO_SPDY3: + case NGHTTP2_PROTO_SPDY3: next_proto = "spdy/3"; break; } @@ -759,7 +759,7 @@ int communicate(const std::string& host, uint16_t port, } spdySession.record_handshake_time(); - spdy_version = spdylay_npn_get_version( + spdy_version = nghttp2_npn_get_version( reinterpret_cast(next_proto.c_str()), next_proto.size()); if (spdy_version <= 0) { @@ -783,18 +783,18 @@ int communicate(const std::string& host, uint16_t port, } 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, - spdylay_data_source *source, void *user_data) + nghttp2_data_source *source, void *user_data) { - Request *req = (Request*)spdylay_session_get_stream_user_data + Request *req = (Request*)nghttp2_session_get_stream_user_data (session, stream_id); int fd = source->fd; ssize_t r; while((r = pread(fd, buf, length, req->data_offset)) == -1 && errno == EINTR); if(r == -1) { - return SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE; + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } else { if(r == 0) { *eof = 1; @@ -807,8 +807,8 @@ ssize_t file_read_callback int run(char **uris, int n) { - spdylay_session_callbacks callbacks; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); + nghttp2_session_callbacks callbacks; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = send_callback; callbacks.recv_callback = recv_callback; callbacks.on_stream_close_callback = on_stream_close_callback; @@ -828,7 +828,7 @@ int run(char **uris, int n) int failures = 0; SpdySession spdySession; int data_fd = -1; - spdylay_data_provider data_prd; + nghttp2_data_provider data_prd; struct stat data_stat; if(!config.datafile.empty()) { @@ -968,10 +968,10 @@ int main(int argc, char **argv) config.verbose = true; break; case '2': - config.spdy_version = SPDYLAY_PROTO_SPDY2; + config.spdy_version = NGHTTP2_PROTO_SPDY2; break; case '3': - config.spdy_version = SPDYLAY_PROTO_SPDY3; + config.spdy_version = NGHTTP2_PROTO_SPDY3; break; case 't': config.timeout = atoi(optarg) * 1000; @@ -1072,9 +1072,9 @@ int main(int argc, char **argv) return run(argv+optind, argc-optind); } -} // namespace spdylay +} // namespace nghttp2 int main(int argc, char **argv) { - return spdylay::main(argc, argv); + return nghttp2::main(argc, argv); } diff --git a/src/spdyd.cc b/src/spdyd.cc index 61de5630..e86d2874 100644 --- a/src/spdyd.cc +++ b/src/spdyd.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -35,12 +35,12 @@ #include #include -#include +#include -#include "spdylay_ssl.h" +#include "nghttp2_ssl.h" #include "SpdyServer.h" -namespace spdylay { +namespace nghttp2 { extern bool ssl_debug; @@ -121,10 +121,10 @@ int main(int argc, char **argv) config.verbose = true; break; case '2': - config.version = SPDYLAY_PROTO_SPDY2; + config.version = NGHTTP2_PROTO_SPDY2; break; case '3': - config.version = SPDYLAY_PROTO_SPDY3; + config.version = NGHTTP2_PROTO_SPDY3; break; case '?': exit(EXIT_FAILURE); @@ -194,9 +194,9 @@ int main(int argc, char **argv) return 0; } -} // namespace spdylay +} // namespace nghttp2 int main(int argc, char **argv) { - return spdylay::main(argc, argv); + return nghttp2::main(argc, argv); } diff --git a/src/timegm.c b/src/timegm.c index cbc158f4..43d7e856 100644 --- a/src/timegm.c +++ b/src/timegm.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2013 Tatsuhiro Tsujikawa * diff --git a/src/timegm.h b/src/timegm.h index 231d1457..2512f0dd 100644 --- a/src/timegm.h +++ b/src/timegm.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2013 Tatsuhiro Tsujikawa * diff --git a/src/util.cc b/src/util.cc index 99841424..346852aa 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -31,7 +31,7 @@ #include "timegm.h" -namespace spdylay { +namespace nghttp2 { namespace util { @@ -186,4 +186,4 @@ char upcase(char c) } // namespace util -} // namespace spdylay +} // namespace nghttp2 diff --git a/src/util.h b/src/util.h index 10d9cf55..f9fea60c 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,7 +25,7 @@ #ifndef UTIL_H #define UTIL_H -#include "spdylay_config.h" +#include "nghttp2_config.h" #include #include @@ -33,7 +33,7 @@ #include #include -namespace spdylay { +namespace nghttp2 { namespace util { @@ -358,6 +358,6 @@ std::string utos(T n) } // namespace util -} // namespace spdylay +} // namespace nghttp2 #endif // UTIL_H diff --git a/tests/Makefile.am b/tests/Makefile.am index 3544b811..cbafbf08 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa @@ -26,26 +26,26 @@ if HAVE_CUNIT check_PROGRAMS = main failmalloc -OBJECTS = main.c spdylay_pq_test.c spdylay_map_test.c spdylay_queue_test.c \ - spdylay_buffer_test.c spdylay_zlib_test.c spdylay_session_test.c \ - spdylay_frame_test.c spdylay_stream_test.c spdylay_npn_test.c \ - spdylay_client_cert_vector_test.c spdylay_gzip_test.c \ - spdylay_test_helper.c +OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \ + nghttp2_buffer_test.c nghttp2_zlib_test.c nghttp2_session_test.c \ + nghttp2_frame_test.c nghttp2_stream_test.c nghttp2_npn_test.c \ + nghttp2_client_cert_vector_test.c nghttp2_gzip_test.c \ + nghttp2_test_helper.c -HFILES = spdylay_pq_test.h spdylay_map_test.h spdylay_queue_test.h \ - spdylay_buffer_test.h spdylay_zlib_test.h spdylay_session_test.h \ - spdylay_frame_test.h spdylay_stream_test.h spdylay_npn_test.h \ - spdylay_client_cert_vector_test.h spdylay_gzip_test.h \ - spdylay_test_helper.h +HFILES = nghttp2_pq_test.h nghttp2_map_test.h nghttp2_queue_test.h \ + nghttp2_buffer_test.h nghttp2_zlib_test.h nghttp2_session_test.h \ + nghttp2_frame_test.h nghttp2_stream_test.h nghttp2_npn_test.h \ + nghttp2_client_cert_vector_test.h nghttp2_gzip_test.h \ + nghttp2_test_helper.h main_SOURCES = $(HFILES) $(OBJECTS) -main_LDADD = ${top_builddir}/lib/libspdylay.la +main_LDADD = ${top_builddir}/lib/libnghttp2.la main_LDFLAGS = -static @CUNIT_LIBS@ @TESTS_LIBS@ failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \ malloc_wrapper.c malloc_wrapper.h \ - spdylay_test_helper.c spdylay_test_helper.h + nghttp2_test_helper.c nghttp2_test_helper.h failmalloc_LDADD = $(main_LDADD) failmalloc_LDFLAGS = $(main_LDFLAGS) diff --git a/tests/failmalloc.c b/tests/failmalloc.c index d1781b9c..80f03574 100644 --- a/tests/failmalloc.c +++ b/tests/failmalloc.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) return CU_get_error(); /* add a suite to the registry */ - pSuite = CU_add_suite("libspdylay_TestSuite", init_suite1, clean_suite1); + pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); @@ -56,10 +56,10 @@ int main(int argc, char* argv[]) /* add the tests to the suite */ if(!CU_add_test(pSuite, "failmalloc_session_send", - test_spdylay_session_send) || + test_nghttp2_session_send) || !CU_add_test(pSuite, "failmalloc_session_recv", - test_spdylay_session_recv) || - !CU_add_test(pSuite, "failmalloc_frame", test_spdylay_frame)) { + test_nghttp2_session_recv) || + !CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame)) { CU_cleanup_registry(); return CU_get_error(); } diff --git a/tests/failmalloc_test.c b/tests/failmalloc_test.c index 8e9abb6c..7c300b62 100644 --- a/tests/failmalloc_test.c +++ b/tests/failmalloc_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -29,12 +29,12 @@ #include #include -#include "spdylay_session.h" -#include "spdylay_stream.h" -#include "spdylay_frame.h" -#include "spdylay_helper.h" +#include "nghttp2_session.h" +#include "nghttp2_stream.h" +#include "nghttp2_frame.h" +#include "nghttp2_helper.h" #include "malloc_wrapper.h" -#include "spdylay_test_helper.h" +#include "nghttp2_test_helper.h" static char* strcopy(const char* s) { @@ -66,29 +66,29 @@ static void data_feed_init(data_feed *df, uint8_t *data, size_t data_length) df->datalimit = df->data+data_length; } -static ssize_t null_send_callback(spdylay_session *session, +static ssize_t null_send_callback(nghttp2_session *session, const uint8_t* data, size_t len, int flags, void *user_data) { return len; } -static ssize_t data_feed_recv_callback(spdylay_session *session, +static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t* data, size_t len, int flags, void *user_data) { data_feed *df = ((my_user_data*)user_data)->df; size_t avail = df->datalimit - df->datamark; - size_t wlen = spdylay_min(avail, len); + size_t wlen = nghttp2_min(avail, len); memcpy(data, df->datamark, wlen); df->datamark += wlen; return wlen; } static ssize_t fixed_length_data_source_read_callback -(spdylay_session *session, int32_t stream_id, +(nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, int *eof, - spdylay_data_source *source, void *user_data) + nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data*)user_data; size_t wlen; @@ -104,8 +104,8 @@ static ssize_t fixed_length_data_source_read_callback return wlen; } -static ssize_t get_credential_ncerts(spdylay_session *session, - const spdylay_origin *origin, +static ssize_t get_credential_ncerts(nghttp2_session *session, + const nghttp2_origin *origin, void *user_data) { if(strcmp("example.org", origin->host) == 0 && @@ -117,8 +117,8 @@ static ssize_t get_credential_ncerts(spdylay_session *session, } } -static ssize_t get_credential_cert(spdylay_session *session, - const spdylay_origin *origin, +static ssize_t get_credential_cert(nghttp2_session *session, + const nghttp2_origin *origin, size_t idx, uint8_t *cert, size_t certlen, void *user_data) @@ -133,8 +133,8 @@ static ssize_t get_credential_cert(spdylay_session *session, } } -static ssize_t get_credential_proof(spdylay_session *session, - const spdylay_origin *origin, +static ssize_t get_credential_proof(nghttp2_session *session, + const nghttp2_origin *origin, uint8_t *proof, size_t prooflen, void *uer_data) { @@ -151,33 +151,33 @@ static ssize_t get_credential_proof(spdylay_session *session, #define TEST_FAILMALLOC_RUN(FUN) \ size_t nmalloc, i; \ \ - spdylay_failmalloc = 0; \ - spdylay_nmalloc = 0; \ + nghttp2_failmalloc = 0; \ + nghttp2_nmalloc = 0; \ FUN(); \ - nmalloc = spdylay_nmalloc; \ + nmalloc = nghttp2_nmalloc; \ \ - spdylay_failmalloc = 1; \ + nghttp2_failmalloc = 1; \ for(i = 0; i < nmalloc; ++i) { \ - spdylay_nmalloc = 0; \ - spdylay_failstart = i; \ + nghttp2_nmalloc = 0; \ + nghttp2_failstart = i; \ /* printf("i=%zu\n", i); */ \ FUN(); \ - /* printf("nmalloc=%d\n", spdylay_nmalloc); */ \ + /* printf("nmalloc=%d\n", nghttp2_nmalloc); */ \ } \ - spdylay_failmalloc = 0; + nghttp2_failmalloc = 0; -static void run_spdylay_session_send(void) +static void run_nghttp2_session_send(void) { - spdylay_session *session; - spdylay_session_callbacks callbacks; + nghttp2_session *session; + nghttp2_session_callbacks callbacks; const char *nv[] = { ":host", "example.org", ":scheme", "https", NULL }; - spdylay_data_provider data_prd; - spdylay_settings_entry iv[2]; + nghttp2_data_provider data_prd; + nghttp2_settings_entry iv[2]; my_user_data ud; int rv; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; callbacks.get_credential_ncerts = get_credential_ncerts; callbacks.get_credential_cert = get_credential_cert; @@ -186,203 +186,203 @@ static void run_spdylay_session_send(void) data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64*1024; - iv[0].settings_id = SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE; + iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE; iv[0].value = 256; - iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; iv[1].value = 100; - rv = spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, + rv = nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud); if(rv != 0) { goto client_new_fail; } - rv = spdylay_submit_request(session, 3, nv, &data_prd, NULL); + rv = nghttp2_submit_request(session, 3, nv, &data_prd, NULL); if(rv != 0) { goto fail; } - rv = spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_NONE, + rv = nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_NONE, 0, 3, nv, NULL); if(rv != 0) { goto fail; } - rv = spdylay_session_send(session); + rv = nghttp2_session_send(session); if(rv != 0) { goto fail; } /* The SYN_STREAM submitted by the previous - spdylay_submit_syn_stream will have stream ID 3. Send HEADERS to + nghttp2_submit_syn_stream will have stream ID 3. Send HEADERS to that stream. */ - rv = spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_NONE, 3, nv); + rv = nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_NONE, 3, nv); if(rv != 0) { goto fail; } - rv = spdylay_submit_data(session, 3, SPDYLAY_DATA_FLAG_FIN, &data_prd); + rv = nghttp2_submit_data(session, 3, NGHTTP2_DATA_FLAG_FIN, &data_prd); if(rv != 0) { goto fail; } - rv = spdylay_session_send(session); + rv = nghttp2_session_send(session); if(rv != 0) { goto fail; } - rv = spdylay_submit_rst_stream(session, 3, SPDYLAY_CANCEL); + rv = nghttp2_submit_rst_stream(session, 3, NGHTTP2_CANCEL); if(rv != 0) { goto fail; } - rv = spdylay_session_send(session); + rv = nghttp2_session_send(session); if(rv != 0) { goto fail; } /* Sending against half-closed stream */ - rv = spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_NONE, 3, nv); + rv = nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_NONE, 3, nv); if(rv != 0) { goto fail; } - rv = spdylay_submit_data(session, 3, SPDYLAY_DATA_FLAG_FIN, &data_prd); + rv = nghttp2_submit_data(session, 3, NGHTTP2_DATA_FLAG_FIN, &data_prd); if(rv != 0) { goto fail; } - rv = spdylay_submit_ping(session); + rv = nghttp2_submit_ping(session); if(rv != 0) { goto fail; } - rv = spdylay_submit_settings(session, SPDYLAY_FLAG_SETTINGS_NONE, iv, 2); + rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_SETTINGS_NONE, iv, 2); if(rv != 0) { goto fail; } - rv = spdylay_session_send(session); + rv = nghttp2_session_send(session); if(rv != 0) { goto fail; } - rv = spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK); + rv = nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK); if(rv != 0) { goto fail; } - rv = spdylay_session_send(session); + rv = nghttp2_session_send(session); if(rv != 0) { goto fail; } fail: - spdylay_session_del(session); + nghttp2_session_del(session); client_new_fail: ; } -void test_spdylay_session_send(void) +void test_nghttp2_session_send(void) { - TEST_FAILMALLOC_RUN(run_spdylay_session_send); + TEST_FAILMALLOC_RUN(run_nghttp2_session_send); } -static void run_spdylay_session_recv(void) +static void run_nghttp2_session_recv(void) { - spdylay_session *session; - spdylay_session_callbacks callbacks; - spdylay_zlib deflater; - spdylay_frame frame; + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + nghttp2_zlib deflater; + nghttp2_frame frame; uint8_t *buf = NULL, *nvbuf = NULL; size_t buflen = 0, nvbuflen = 0; ssize_t framelen; const char *nv[] = { ":host", "example.org", ":scheme", "https", NULL }; - spdylay_settings_entry iv[2]; - spdylay_mem_chunk proof; - spdylay_mem_chunk *certs; + nghttp2_settings_entry iv[2]; + nghttp2_mem_chunk proof; + nghttp2_mem_chunk *certs; size_t ncerts; my_user_data ud; data_feed df; int rv; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.recv_callback = data_feed_recv_callback; ud.df = &df; - spdylay_failmalloc_pause(); - spdylay_zlib_deflate_hd_init(&deflater, 1, SPDYLAY_PROTO_SPDY3); - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, &ud); - spdylay_failmalloc_unpause(); + nghttp2_failmalloc_pause(); + nghttp2_zlib_deflate_hd_init(&deflater, 1, NGHTTP2_PROTO_SPDY3); + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud); + nghttp2_failmalloc_unpause(); /* SYN_STREAM */ - spdylay_failmalloc_pause(); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_FIN, 1, 0, 2, - spdylay_frame_nv_copy(nv)); - framelen = spdylay_frame_pack_syn_stream(&buf, &buflen, + nghttp2_failmalloc_pause(); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_FIN, 1, 0, 2, + nghttp2_frame_nv_copy(nv)); + framelen = nghttp2_frame_pack_syn_stream(&buf, &buflen, &nvbuf, &nvbuflen, &frame.syn_stream, &deflater); - spdylay_frame_syn_stream_free(&frame.syn_stream); + nghttp2_frame_syn_stream_free(&frame.syn_stream); data_feed_init(&df, buf, framelen); - spdylay_failmalloc_unpause(); + nghttp2_failmalloc_unpause(); - rv = spdylay_session_recv(session); + rv = nghttp2_session_recv(session); if(rv != 0) { goto fail; } /* PING */ - spdylay_failmalloc_pause(); - spdylay_frame_ping_init(&frame.ping, SPDYLAY_PROTO_SPDY3, 1); - framelen = spdylay_frame_pack_ping(&buf, &buflen, &frame.ping); - spdylay_frame_ping_free(&frame.ping); + nghttp2_failmalloc_pause(); + nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY3, 1); + framelen = nghttp2_frame_pack_ping(&buf, &buflen, &frame.ping); + nghttp2_frame_ping_free(&frame.ping); data_feed_init(&df, buf, framelen); - spdylay_failmalloc_unpause(); + nghttp2_failmalloc_unpause(); - rv = spdylay_session_recv(session); + rv = nghttp2_session_recv(session); if(rv != 0) { goto fail; } /* RST_STREAM */ - spdylay_failmalloc_pause(); - spdylay_frame_rst_stream_init(&frame.rst_stream, SPDYLAY_PROTO_SPDY3, 1, - SPDYLAY_PROTOCOL_ERROR); - framelen = spdylay_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream); - spdylay_frame_rst_stream_free(&frame.rst_stream); - spdylay_failmalloc_unpause(); + nghttp2_failmalloc_pause(); + nghttp2_frame_rst_stream_init(&frame.rst_stream, NGHTTP2_PROTO_SPDY3, 1, + NGHTTP2_PROTOCOL_ERROR); + framelen = nghttp2_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream); + nghttp2_frame_rst_stream_free(&frame.rst_stream); + nghttp2_failmalloc_unpause(); - rv = spdylay_session_recv(session); + rv = nghttp2_session_recv(session); if(rv != 0) { goto fail; } /* SETTINGS */ - spdylay_failmalloc_pause(); - iv[0].settings_id = SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE; + nghttp2_failmalloc_pause(); + iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE; iv[0].value = 256; - iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; iv[1].value = 100; - spdylay_frame_settings_init(&frame.settings, SPDYLAY_PROTO_SPDY3, - SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS, - spdylay_frame_iv_copy(iv, 2), 2); - framelen = spdylay_frame_pack_settings(&buf, &buflen, &frame.settings); - spdylay_frame_settings_free(&frame.settings); - spdylay_failmalloc_unpause(); + nghttp2_frame_settings_init(&frame.settings, NGHTTP2_PROTO_SPDY3, + NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS, + nghttp2_frame_iv_copy(iv, 2), 2); + framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame.settings); + nghttp2_frame_settings_free(&frame.settings); + nghttp2_failmalloc_unpause(); - rv = spdylay_session_recv(session); + rv = nghttp2_session_recv(session); if(rv != 0) { goto fail; } /* CREDENTIAL */ - spdylay_failmalloc_pause(); + nghttp2_failmalloc_pause(); proof.data = (uint8_t*)strcopy("PROOF"); proof.length = strlen("PROOF"); ncerts = 2; - certs = malloc(sizeof(spdylay_mem_chunk)*ncerts); + certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts); certs[0].data = (uint8_t*)strcopy("CERT0"); certs[0].length = strlen("CERT0"); certs[1].data = (uint8_t*)strcopy("CERT1"); certs[1].length = strlen("CERT1"); - spdylay_frame_credential_init(&frame.credential, SPDYLAY_PROTO_SPDY3, + nghttp2_frame_credential_init(&frame.credential, NGHTTP2_PROTO_SPDY3, 1, &proof, certs, ncerts); - framelen = spdylay_frame_pack_credential(&buf, &buflen, &frame.credential); - spdylay_frame_credential_free(&frame.credential); - spdylay_failmalloc_unpause(); + framelen = nghttp2_frame_pack_credential(&buf, &buflen, &frame.credential); + nghttp2_frame_credential_free(&frame.credential); + nghttp2_failmalloc_unpause(); - rv = spdylay_session_recv(session); + rv = nghttp2_session_recv(session); if(rv != 0) { goto fail; } @@ -390,22 +390,22 @@ static void run_spdylay_session_recv(void) fail: free(buf); free(nvbuf); - spdylay_session_del(session); - spdylay_zlib_deflate_free(&deflater); + nghttp2_session_del(session); + nghttp2_zlib_deflate_free(&deflater); } -void test_spdylay_session_recv(void) +void test_nghttp2_session_recv(void) { - TEST_FAILMALLOC_RUN(run_spdylay_session_recv); + TEST_FAILMALLOC_RUN(run_nghttp2_session_recv); } -static void run_spdylay_frame_pack_syn_stream(void) +static void run_nghttp2_frame_pack_syn_stream(void) { - spdylay_zlib deflater, inflater; - spdylay_frame frame, oframe; + nghttp2_zlib deflater, inflater; + nghttp2_frame frame, oframe; uint8_t *buf = NULL, *nvbuf = NULL; size_t buflen = 0, nvbuflen = 0; - spdylay_buffer inflatebuf; + nghttp2_buffer inflatebuf; ssize_t framelen; const char *nv[] = { ":host", "example.org", ":scheme", "https", @@ -413,190 +413,190 @@ static void run_spdylay_frame_pack_syn_stream(void) char **nv_copy; int rv; - spdylay_buffer_init(&inflatebuf, 4096); - rv = spdylay_zlib_deflate_hd_init(&deflater, 1, SPDYLAY_PROTO_SPDY3); + nghttp2_buffer_init(&inflatebuf, 4096); + rv = nghttp2_zlib_deflate_hd_init(&deflater, 1, NGHTTP2_PROTO_SPDY3); if(rv != 0) { goto deflate_init_fail; } - rv = spdylay_zlib_inflate_hd_init(&inflater, SPDYLAY_PROTO_SPDY3); + rv = nghttp2_zlib_inflate_hd_init(&inflater, NGHTTP2_PROTO_SPDY3); if(rv != 0) { goto inflate_init_fail; } - nv_copy = spdylay_frame_nv_copy(nv); + nv_copy = nghttp2_frame_nv_copy(nv); if(nv_copy == NULL) { goto nv_copy_fail; } - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_FIN, 1, 0, 2, nv_copy); - framelen = spdylay_frame_pack_syn_stream(&buf, &buflen, + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_FIN, 1, 0, 2, nv_copy); + framelen = nghttp2_frame_pack_syn_stream(&buf, &buflen, &nvbuf, &nvbuflen, &frame.syn_stream, &deflater); if(framelen < 0) { goto fail; } - rv = unpack_frame_with_nv_block(SPDYLAY_SYN_STREAM, SPDYLAY_PROTO_SPDY3, + rv = unpack_frame_with_nv_block(NGHTTP2_SYN_STREAM, NGHTTP2_PROTO_SPDY3, &oframe, &inflater, buf, framelen); if(rv != 0) { goto fail; } - spdylay_frame_syn_stream_free(&oframe.syn_stream); + nghttp2_frame_syn_stream_free(&oframe.syn_stream); fail: free(buf); free(nvbuf); - spdylay_frame_syn_stream_free(&frame.syn_stream); + nghttp2_frame_syn_stream_free(&frame.syn_stream); nv_copy_fail: - spdylay_zlib_inflate_free(&inflater); + nghttp2_zlib_inflate_free(&inflater); inflate_init_fail: - spdylay_zlib_deflate_free(&deflater); + nghttp2_zlib_deflate_free(&deflater); deflate_init_fail: - spdylay_buffer_free(&inflatebuf); + nghttp2_buffer_free(&inflatebuf); } -static void run_spdylay_frame_pack_ping(void) +static void run_nghttp2_frame_pack_ping(void) { - spdylay_frame frame; + nghttp2_frame frame; uint8_t *buf = NULL; size_t buflen = 0; - spdylay_frame_ping_init(&frame.ping, SPDYLAY_PROTO_SPDY3, 1); - spdylay_frame_pack_ping(&buf, &buflen, &frame.ping); + nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY3, 1); + nghttp2_frame_pack_ping(&buf, &buflen, &frame.ping); free(buf); - spdylay_frame_ping_free(&frame.ping); + nghttp2_frame_ping_free(&frame.ping); } -static void run_spdylay_frame_pack_goaway(void) +static void run_nghttp2_frame_pack_goaway(void) { - spdylay_frame frame; + nghttp2_frame frame; uint8_t *buf = NULL; size_t buflen = 0; - spdylay_frame_goaway_init(&frame.goaway, SPDYLAY_PROTO_SPDY3, 1000000007, - SPDYLAY_GOAWAY_PROTOCOL_ERROR); - spdylay_frame_pack_goaway(&buf, &buflen, &frame.goaway); + nghttp2_frame_goaway_init(&frame.goaway, NGHTTP2_PROTO_SPDY3, 1000000007, + NGHTTP2_GOAWAY_PROTOCOL_ERROR); + nghttp2_frame_pack_goaway(&buf, &buflen, &frame.goaway); free(buf); - spdylay_frame_goaway_free(&frame.goaway); + nghttp2_frame_goaway_free(&frame.goaway); } -static void run_spdylay_frame_pack_rst_stream(void) +static void run_nghttp2_frame_pack_rst_stream(void) { - spdylay_frame frame; + nghttp2_frame frame; uint8_t *buf = NULL; size_t buflen = 0; - spdylay_frame_rst_stream_init(&frame.rst_stream, SPDYLAY_PROTO_SPDY3, 1, - SPDYLAY_PROTOCOL_ERROR); - spdylay_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream); + nghttp2_frame_rst_stream_init(&frame.rst_stream, NGHTTP2_PROTO_SPDY3, 1, + NGHTTP2_PROTOCOL_ERROR); + nghttp2_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream); free(buf); - spdylay_frame_rst_stream_free(&frame.rst_stream); + nghttp2_frame_rst_stream_free(&frame.rst_stream); } -static void run_spdylay_frame_pack_window_update(void) +static void run_nghttp2_frame_pack_window_update(void) { - spdylay_frame frame; + nghttp2_frame frame; uint8_t *buf = NULL; size_t buflen = 0; - spdylay_frame_window_update_init(&frame.window_update, SPDYLAY_PROTO_SPDY3, + nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_PROTO_SPDY3, 1000000007, 4096); - spdylay_frame_pack_window_update(&buf, &buflen, + nghttp2_frame_pack_window_update(&buf, &buflen, &frame.window_update); free(buf); - spdylay_frame_window_update_free(&frame.window_update); + nghttp2_frame_window_update_free(&frame.window_update); } -static void run_spdylay_frame_pack_settings(void) +static void run_nghttp2_frame_pack_settings(void) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - spdylay_settings_entry iv[2], *iv_copy; + nghttp2_settings_entry iv[2], *iv_copy; int rv; - iv[0].settings_id = SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE; + iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE; iv[0].value = 256; - iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; iv[1].value = 100; - iv_copy = spdylay_frame_iv_copy(iv, 2); + iv_copy = nghttp2_frame_iv_copy(iv, 2); if(iv_copy == NULL) { goto iv_copy_fail; } - spdylay_frame_settings_init(&frame.settings, SPDYLAY_PROTO_SPDY3, - SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS, + nghttp2_frame_settings_init(&frame.settings, NGHTTP2_PROTO_SPDY3, + NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS, iv_copy, 2); - framelen = spdylay_frame_pack_settings(&buf, &buflen, &frame.settings); + framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame.settings); if(framelen < 0) { goto fail; } - rv = spdylay_frame_unpack_settings(&oframe.settings, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH); + rv = nghttp2_frame_unpack_settings(&oframe.settings, + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH); if(rv != 0) { goto fail; } - spdylay_frame_settings_free(&oframe.settings); + nghttp2_frame_settings_free(&oframe.settings); fail: free(buf); - spdylay_frame_settings_free(&frame.settings); + nghttp2_frame_settings_free(&frame.settings); iv_copy_fail: ; } -static void run_spdylay_frame_pack_credential(void) +static void run_nghttp2_frame_pack_credential(void) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - spdylay_mem_chunk proof; - spdylay_mem_chunk *certs; + nghttp2_mem_chunk proof; + nghttp2_mem_chunk *certs; size_t ncerts; int rv; - spdylay_failmalloc_pause(); + nghttp2_failmalloc_pause(); proof.data = (uint8_t*)strcopy("PROOF"); proof.length = strlen("PROOF"); ncerts = 2; - certs = malloc(sizeof(spdylay_mem_chunk)*ncerts); + certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts); certs[0].data = (uint8_t*)strcopy("CERT0"); certs[0].length = strlen("CERT0"); certs[1].data = (uint8_t*)strcopy("CERT1"); certs[1].length = strlen("CERT1"); - spdylay_failmalloc_unpause(); + nghttp2_failmalloc_unpause(); - spdylay_frame_credential_init(&frame.credential, SPDYLAY_PROTO_SPDY3, + nghttp2_frame_credential_init(&frame.credential, NGHTTP2_PROTO_SPDY3, 1, &proof, certs, ncerts); - framelen = spdylay_frame_pack_credential(&buf, &buflen, &frame.credential); + framelen = nghttp2_frame_pack_credential(&buf, &buflen, &frame.credential); if(framelen < 0) { goto fail; } - rv = spdylay_frame_unpack_credential(&oframe.credential, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH); + rv = nghttp2_frame_unpack_credential(&oframe.credential, + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH); if(rv != 0) { goto fail; } - spdylay_frame_credential_free(&oframe.credential); + nghttp2_frame_credential_free(&oframe.credential); fail: free(buf); - spdylay_frame_credential_free(&frame.credential); + nghttp2_frame_credential_free(&frame.credential); } -static void run_spdylay_frame(void) +static void run_nghttp2_frame(void) { - run_spdylay_frame_pack_syn_stream(); - run_spdylay_frame_pack_ping(); - run_spdylay_frame_pack_goaway(); - run_spdylay_frame_pack_rst_stream(); - run_spdylay_frame_pack_window_update(); - run_spdylay_frame_pack_settings(); - run_spdylay_frame_pack_credential(); + run_nghttp2_frame_pack_syn_stream(); + run_nghttp2_frame_pack_ping(); + run_nghttp2_frame_pack_goaway(); + run_nghttp2_frame_pack_rst_stream(); + run_nghttp2_frame_pack_window_update(); + run_nghttp2_frame_pack_settings(); + run_nghttp2_frame_pack_credential(); } -void test_spdylay_frame(void) +void test_nghttp2_frame(void) { - TEST_FAILMALLOC_RUN(run_spdylay_frame); + TEST_FAILMALLOC_RUN(run_nghttp2_frame); } diff --git a/tests/failmalloc_test.h b/tests/failmalloc_test.h index 1441733a..52b2ace2 100644 --- a/tests/failmalloc_test.h +++ b/tests/failmalloc_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -25,8 +25,8 @@ #ifndef FAILMALLOC_TEST_H #define FAILMALLOC_TEST_H -void test_spdylay_session_send(void); -void test_spdylay_session_recv(void); -void test_spdylay_frame(void); +void test_nghttp2_session_send(void); +void test_nghttp2_session_recv(void); +void test_nghttp2_frame(void); #endif /* FAILMALLOC_TEST_H */ diff --git a/tests/main.c b/tests/main.c index 33b62c5f..522ef024 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -26,17 +26,17 @@ #include #include /* include test cases' include files here */ -#include "spdylay_pq_test.h" -#include "spdylay_map_test.h" -#include "spdylay_queue_test.h" -#include "spdylay_buffer_test.h" -#include "spdylay_zlib_test.h" -#include "spdylay_session_test.h" -#include "spdylay_frame_test.h" -#include "spdylay_stream_test.h" -#include "spdylay_npn_test.h" -#include "spdylay_client_cert_vector_test.h" -#include "spdylay_gzip_test.h" +#include "nghttp2_pq_test.h" +#include "nghttp2_map_test.h" +#include "nghttp2_queue_test.h" +#include "nghttp2_buffer_test.h" +#include "nghttp2_zlib_test.h" +#include "nghttp2_session_test.h" +#include "nghttp2_frame_test.h" +#include "nghttp2_stream_test.h" +#include "nghttp2_npn_test.h" +#include "nghttp2_client_cert_vector_test.h" +#include "nghttp2_gzip_test.h" static int init_suite1(void) { @@ -59,184 +59,184 @@ int main(int argc, char* argv[]) return CU_get_error(); /* add a suite to the registry */ - pSuite = CU_add_suite("libspdylay_TestSuite", init_suite1, clean_suite1); + pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); } /* add the tests to the suite */ - if(!CU_add_test(pSuite, "pq", test_spdylay_pq) || - !CU_add_test(pSuite, "map", test_spdylay_map) || - !CU_add_test(pSuite, "map_functional", test_spdylay_map_functional) || - !CU_add_test(pSuite, "map_each_free", test_spdylay_map_each_free) || - !CU_add_test(pSuite, "queue", test_spdylay_queue) || - !CU_add_test(pSuite, "buffer", test_spdylay_buffer) || - !CU_add_test(pSuite, "buffer_reader", test_spdylay_buffer_reader) || - !CU_add_test(pSuite, "zlib_spdy2", test_spdylay_zlib_spdy2) || - !CU_add_test(pSuite, "zlib_spdy3", test_spdylay_zlib_spdy3) || - !CU_add_test(pSuite, "npn", test_spdylay_npn) || + if(!CU_add_test(pSuite, "pq", test_nghttp2_pq) || + !CU_add_test(pSuite, "map", test_nghttp2_map) || + !CU_add_test(pSuite, "map_functional", test_nghttp2_map_functional) || + !CU_add_test(pSuite, "map_each_free", test_nghttp2_map_each_free) || + !CU_add_test(pSuite, "queue", test_nghttp2_queue) || + !CU_add_test(pSuite, "buffer", test_nghttp2_buffer) || + !CU_add_test(pSuite, "buffer_reader", test_nghttp2_buffer_reader) || + !CU_add_test(pSuite, "zlib_spdy2", test_nghttp2_zlib_spdy2) || + !CU_add_test(pSuite, "zlib_spdy3", test_nghttp2_zlib_spdy3) || + !CU_add_test(pSuite, "npn", test_nghttp2_npn) || !CU_add_test(pSuite, "npn_get_proto_list", - test_spdylay_npn_get_proto_list) || - !CU_add_test(pSuite, "session_recv", test_spdylay_session_recv) || + test_nghttp2_npn_get_proto_list) || + !CU_add_test(pSuite, "session_recv", test_nghttp2_session_recv) || !CU_add_test(pSuite, "session_recv_invalid_stream_id", - test_spdylay_session_recv_invalid_stream_id) || + test_nghttp2_session_recv_invalid_stream_id) || !CU_add_test(pSuite, "session_add_frame", - test_spdylay_session_add_frame) || + test_nghttp2_session_add_frame) || !CU_add_test(pSuite, "session_on_syn_stream_received", - test_spdylay_session_on_syn_stream_received) || + test_nghttp2_session_on_syn_stream_received) || !CU_add_test(pSuite, "session_on_syn_stream_received_with_push", - test_spdylay_session_on_syn_stream_received_with_push) || + test_nghttp2_session_on_syn_stream_received_with_push) || !CU_add_test(pSuite, "session_on_syn_reply_received", - test_spdylay_session_on_syn_reply_received) || + test_nghttp2_session_on_syn_reply_received) || !CU_add_test(pSuite, "session_send_syn_stream", - test_spdylay_session_send_syn_stream) || + test_nghttp2_session_send_syn_stream) || !CU_add_test(pSuite, "session_send_syn_reply", - test_spdylay_session_send_syn_reply) || - !CU_add_test(pSuite, "submit_response", test_spdylay_submit_response) || + test_nghttp2_session_send_syn_reply) || + !CU_add_test(pSuite, "submit_response", test_nghttp2_submit_response) || !CU_add_test(pSuite, "submit_response_without_data", - test_spdylay_submit_response_with_null_data_read_callback) || + test_nghttp2_submit_response_with_null_data_read_callback) || !CU_add_test(pSuite, "submit_request_with_data", - test_spdylay_submit_request_with_data) || + test_nghttp2_submit_request_with_data) || !CU_add_test(pSuite, "submit_request_without_data", - test_spdylay_submit_request_with_null_data_read_callback) || + test_nghttp2_submit_request_with_null_data_read_callback) || !CU_add_test(pSuite, "submit_syn_stream", - test_spdylay_submit_syn_stream) || - !CU_add_test(pSuite, "submit_syn_reply", test_spdylay_submit_syn_reply) || - !CU_add_test(pSuite, "submit_headers", test_spdylay_submit_headers) || + test_nghttp2_submit_syn_stream) || + !CU_add_test(pSuite, "submit_syn_reply", test_nghttp2_submit_syn_reply) || + !CU_add_test(pSuite, "submit_headers", test_nghttp2_submit_headers) || !CU_add_test(pSuite, "submit_invalid_nv", - test_spdylay_submit_invalid_nv) || + test_nghttp2_submit_invalid_nv) || !CU_add_test(pSuite, "session_reply_fail", - test_spdylay_session_reply_fail) || + test_nghttp2_session_reply_fail) || !CU_add_test(pSuite, "session_on_headers_received", - test_spdylay_session_on_headers_received) || + test_nghttp2_session_on_headers_received) || !CU_add_test(pSuite, "session_on_window_update_received", - test_spdylay_session_on_window_update_received) || + test_nghttp2_session_on_window_update_received) || !CU_add_test(pSuite, "session_on_ping_received", - test_spdylay_session_on_ping_received) || + test_nghttp2_session_on_ping_received) || !CU_add_test(pSuite, "session_on_goaway_received", - test_spdylay_session_on_goaway_received) || + test_nghttp2_session_on_goaway_received) || !CU_add_test(pSuite, "session_on_data_received", - test_spdylay_session_on_data_received) || + test_nghttp2_session_on_data_received) || !CU_add_test(pSuite, "session_on_rst_stream_received", - test_spdylay_session_on_rst_received) || + test_nghttp2_session_on_rst_received) || !CU_add_test(pSuite, "session_is_my_stream_id", - test_spdylay_session_is_my_stream_id) || + test_nghttp2_session_is_my_stream_id) || !CU_add_test(pSuite, "session_send_rst_stream", - test_spdylay_session_send_rst_stream) || + test_nghttp2_session_send_rst_stream) || !CU_add_test(pSuite, "session_get_next_ob_item", - test_spdylay_session_get_next_ob_item) || + test_nghttp2_session_get_next_ob_item) || !CU_add_test(pSuite, "session_pop_next_ob_item", - test_spdylay_session_pop_next_ob_item) || + test_nghttp2_session_pop_next_ob_item) || !CU_add_test(pSuite, "session_on_request_recv_callback", - test_spdylay_session_on_request_recv_callback) || + test_nghttp2_session_on_request_recv_callback) || !CU_add_test(pSuite, "session_on_stream_close", - test_spdylay_session_on_stream_close) || + test_nghttp2_session_on_stream_close) || !CU_add_test(pSuite, "session_max_concurrent_streams", - test_spdylay_session_max_concurrent_streams) || + test_nghttp2_session_max_concurrent_streams) || !CU_add_test(pSuite, "session_data_backoff_by_high_pri_frame", - test_spdylay_session_data_backoff_by_high_pri_frame) || + test_nghttp2_session_data_backoff_by_high_pri_frame) || !CU_add_test(pSuite, "session_stop_data_with_rst_stream", - test_spdylay_session_stop_data_with_rst_stream) || + test_nghttp2_session_stop_data_with_rst_stream) || !CU_add_test(pSuite, "session_stream_close_on_syn_stream", - test_spdylay_session_stream_close_on_syn_stream) || + test_nghttp2_session_stream_close_on_syn_stream) || !CU_add_test(pSuite, "session_recv_invalid_frame", - test_spdylay_session_recv_invalid_frame) || + test_nghttp2_session_recv_invalid_frame) || !CU_add_test(pSuite, "session_defer_data", - test_spdylay_session_defer_data) || + test_nghttp2_session_defer_data) || !CU_add_test(pSuite, "session_flow_control", - test_spdylay_session_flow_control) || + test_nghttp2_session_flow_control) || !CU_add_test(pSuite, "session_on_ctrl_not_send", - test_spdylay_session_on_ctrl_not_send) || + test_nghttp2_session_on_ctrl_not_send) || !CU_add_test(pSuite, "session_on_settings_received", - test_spdylay_session_on_settings_received) || + test_nghttp2_session_on_settings_received) || !CU_add_test(pSuite, "session_submit_settings", - test_spdylay_submit_settings) || + test_nghttp2_submit_settings) || !CU_add_test(pSuite, "session_get_outbound_queue_size", - test_spdylay_session_get_outbound_queue_size) || + test_nghttp2_session_get_outbound_queue_size) || !CU_add_test(pSuite, "session_prep_credential", - test_spdylay_session_prep_credential) || + test_nghttp2_session_prep_credential) || !CU_add_test(pSuite, "session_submit_syn_stream_with_credential", - test_spdylay_submit_syn_stream_with_credential) || + test_nghttp2_submit_syn_stream_with_credential) || !CU_add_test(pSuite, "session_set_initial_client_cert_origin", - test_spdylay_session_set_initial_client_cert_origin) || + test_nghttp2_session_set_initial_client_cert_origin) || !CU_add_test(pSuite, "session_set_option", - test_spdylay_session_set_option) || + test_nghttp2_session_set_option) || !CU_add_test(pSuite, "submit_window_update", - test_spdylay_submit_window_update) || + test_nghttp2_submit_window_update) || !CU_add_test(pSuite, "session_data_read_temporal_failure", - test_spdylay_session_data_read_temporal_failure) || + test_nghttp2_session_data_read_temporal_failure) || !CU_add_test(pSuite, "session_recv_eof", - test_spdylay_session_recv_eof) || + test_nghttp2_session_recv_eof) || !CU_add_test(pSuite, "session_recv_data", - test_spdylay_session_recv_data) || + test_nghttp2_session_recv_data) || !CU_add_test(pSuite, "frame_unpack_nv_spdy2", - test_spdylay_frame_unpack_nv_spdy2) || + test_nghttp2_frame_unpack_nv_spdy2) || !CU_add_test(pSuite, "frame_unpack_nv_spdy3", - test_spdylay_frame_unpack_nv_spdy3) || + test_nghttp2_frame_unpack_nv_spdy3) || !CU_add_test(pSuite, "frame_count_nv_space", - test_spdylay_frame_count_nv_space) || + test_nghttp2_frame_count_nv_space) || !CU_add_test(pSuite, "frame_count_unpack_nv_space", - test_spdylay_frame_count_unpack_nv_space) || - !CU_add_test(pSuite, "frame_pack_ping", test_spdylay_frame_pack_ping) || + test_nghttp2_frame_count_unpack_nv_space) || + !CU_add_test(pSuite, "frame_pack_ping", test_nghttp2_frame_pack_ping) || !CU_add_test(pSuite, "frame_pack_goaway_spdy2", - test_spdylay_frame_pack_goaway_spdy2) || + test_nghttp2_frame_pack_goaway_spdy2) || !CU_add_test(pSuite, "frame_pack_goaway_spdy3", - test_spdylay_frame_pack_goaway_spdy3) || + test_nghttp2_frame_pack_goaway_spdy3) || !CU_add_test(pSuite, "frame_pack_syn_stream_spdy2", - test_spdylay_frame_pack_syn_stream_spdy2) || + test_nghttp2_frame_pack_syn_stream_spdy2) || !CU_add_test(pSuite, "frame_pack_syn_stream_spdy3", - test_spdylay_frame_pack_syn_stream_spdy3) || + test_nghttp2_frame_pack_syn_stream_spdy3) || !CU_add_test(pSuite, "frame_pack_syn_stream_frame_too_large", - test_spdylay_frame_pack_syn_stream_frame_too_large) || + test_nghttp2_frame_pack_syn_stream_frame_too_large) || !CU_add_test(pSuite, "frame_pack_syn_reply_spdy2", - test_spdylay_frame_pack_syn_reply_spdy2) || + test_nghttp2_frame_pack_syn_reply_spdy2) || !CU_add_test(pSuite, "frame_pack_syn_reply_spdy3", - test_spdylay_frame_pack_syn_reply_spdy3) || + test_nghttp2_frame_pack_syn_reply_spdy3) || !CU_add_test(pSuite, "frame_pack_headers_spdy2", - test_spdylay_frame_pack_headers_spdy2) || + test_nghttp2_frame_pack_headers_spdy2) || !CU_add_test(pSuite, "frame_pack_headers_spdy3", - test_spdylay_frame_pack_headers_spdy3) || + test_nghttp2_frame_pack_headers_spdy3) || !CU_add_test(pSuite, "frame_pack_window_update", - test_spdylay_frame_pack_window_update) || + test_nghttp2_frame_pack_window_update) || !CU_add_test(pSuite, "frame_pack_settings_spdy2", - test_spdylay_frame_pack_settings_spdy2) || + test_nghttp2_frame_pack_settings_spdy2) || !CU_add_test(pSuite, "frame_pack_settings_spdy3", - test_spdylay_frame_pack_settings_spdy3) || + test_nghttp2_frame_pack_settings_spdy3) || !CU_add_test(pSuite, "frame_pack_credential", - test_spdylay_frame_pack_credential) || - !CU_add_test(pSuite, "frame_nv_sort", test_spdylay_frame_nv_sort) || + test_nghttp2_frame_pack_credential) || + !CU_add_test(pSuite, "frame_nv_sort", test_nghttp2_frame_nv_sort) || !CU_add_test(pSuite, "frame_nv_downcase", - test_spdylay_frame_nv_downcase) || + test_nghttp2_frame_nv_downcase) || !CU_add_test(pSuite, "frame_pack_nv_duplicate_keys", - test_spdylay_frame_pack_nv_duplicate_keys) || + test_nghttp2_frame_pack_nv_duplicate_keys) || !CU_add_test(pSuite, "frame_pack_nv_empty_value_spdy2", - test_spdylay_frame_pack_nv_empty_value_spdy2) || + test_nghttp2_frame_pack_nv_empty_value_spdy2) || !CU_add_test(pSuite, "frame_pack_nv_empty_value_spdy3", - test_spdylay_frame_pack_nv_empty_value_spdy3) || - !CU_add_test(pSuite, "frame_nv_2to3", test_spdylay_frame_nv_2to3) || - !CU_add_test(pSuite, "frame_nv_3to2", test_spdylay_frame_nv_3to2) || + test_nghttp2_frame_pack_nv_empty_value_spdy3) || + !CU_add_test(pSuite, "frame_nv_2to3", test_nghttp2_frame_nv_2to3) || + !CU_add_test(pSuite, "frame_nv_3to2", test_nghttp2_frame_nv_3to2) || !CU_add_test(pSuite, "frame_unpack_nv_check_name_spdy2", - test_spdylay_frame_unpack_nv_check_name_spdy2) || + test_nghttp2_frame_unpack_nv_check_name_spdy2) || !CU_add_test(pSuite, "frame_unpack_nv_check_name_spdy3", - test_spdylay_frame_unpack_nv_check_name_spdy3) || + test_nghttp2_frame_unpack_nv_check_name_spdy3) || !CU_add_test(pSuite, "frame_unpack_nv_last_empty_value_spdy2", - test_spdylay_frame_unpack_nv_last_empty_value_spdy2) || + test_nghttp2_frame_unpack_nv_last_empty_value_spdy2) || !CU_add_test(pSuite, "frame_unpack_nv_last_empty_value_spdy3", - test_spdylay_frame_unpack_nv_last_empty_value_spdy3) || + test_nghttp2_frame_unpack_nv_last_empty_value_spdy3) || !CU_add_test(pSuite, "frame_nv_set_origin", - test_spdylay_frame_nv_set_origin) || + test_nghttp2_frame_nv_set_origin) || !CU_add_test(pSuite, "frame_nv_check_null", - test_spdylay_frame_nv_check_null) || + test_nghttp2_frame_nv_check_null) || !CU_add_test(pSuite, "stream_add_pushed_stream", - test_spdylay_stream_add_pushed_stream) || + test_nghttp2_stream_add_pushed_stream) || !CU_add_test(pSuite, "client_cert_vector_find", - test_spdylay_client_cert_vector_find) || + test_nghttp2_client_cert_vector_find) || !CU_add_test(pSuite, "client_cert_vector_resize", - test_spdylay_client_cert_vector_resize) || + test_nghttp2_client_cert_vector_resize) || !CU_add_test(pSuite, "client_cert_vector_get_origin", - test_spdylay_client_cert_vector_get_origin) || - !CU_add_test(pSuite, "gzip_inflate", test_spdylay_gzip_inflate)) { + test_nghttp2_client_cert_vector_get_origin) || + !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate)) { CU_cleanup_registry(); return CU_get_error(); } diff --git a/tests/malloc_wrapper.c b/tests/malloc_wrapper.c index a93d79a6..1fa670f6 100644 --- a/tests/malloc_wrapper.c +++ b/tests/malloc_wrapper.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -27,10 +27,10 @@ #define __USE_GNU #include -int spdylay_failmalloc = 0; -int spdylay_failstart = 0; -int spdylay_countmalloc = 1; -int spdylay_nmalloc = 0; +int nghttp2_failmalloc = 0; +int nghttp2_failstart = 0; +int nghttp2_countmalloc = 1; +int nghttp2_nmalloc = 0; static void* (*real_malloc)(size_t) = NULL; @@ -44,11 +44,11 @@ void* malloc(size_t size) if(real_malloc == NULL) { init(); } - if(spdylay_failmalloc && spdylay_nmalloc >= spdylay_failstart) { + if(nghttp2_failmalloc && nghttp2_nmalloc >= nghttp2_failstart) { return NULL; } else { - if(spdylay_countmalloc) { - ++spdylay_nmalloc; + if(nghttp2_countmalloc) { + ++nghttp2_nmalloc; } return real_malloc(size); } @@ -56,16 +56,16 @@ void* malloc(size_t size) static int failmalloc_bk, countmalloc_bk; -void spdylay_failmalloc_pause(void) +void nghttp2_failmalloc_pause(void) { - failmalloc_bk = spdylay_failmalloc; - countmalloc_bk = spdylay_countmalloc; - spdylay_failmalloc = 0; - spdylay_countmalloc = 0; + failmalloc_bk = nghttp2_failmalloc; + countmalloc_bk = nghttp2_countmalloc; + nghttp2_failmalloc = 0; + nghttp2_countmalloc = 0; } -void spdylay_failmalloc_unpause(void) +void nghttp2_failmalloc_unpause(void) { - spdylay_failmalloc = failmalloc_bk; - spdylay_countmalloc = countmalloc_bk; + nghttp2_failmalloc = failmalloc_bk; + nghttp2_countmalloc = countmalloc_bk; } diff --git a/tests/malloc_wrapper.h b/tests/malloc_wrapper.h index bdd94ea0..a45eafdc 100644 --- a/tests/malloc_wrapper.h +++ b/tests/malloc_wrapper.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -30,27 +30,27 @@ /* Global variables to control the behavior of malloc() */ /* If nonzero, malloc failure mode is on */ -extern int spdylay_failmalloc; -/* If spdylay_failstart <= spdylay_nmalloc and spdylay_failmalloc is +extern int nghttp2_failmalloc; +/* If nghttp2_failstart <= nghttp2_nmalloc and nghttp2_failmalloc is nonzero, malloc() fails. */ -extern int spdylay_failstart; -/* If nonzero, spdylay_nmalloc is incremented if malloc() succeeds. */ -extern int spdylay_countmalloc; +extern int nghttp2_failstart; +/* If nonzero, nghttp2_nmalloc is incremented if malloc() succeeds. */ +extern int nghttp2_countmalloc; /* The number of successful invocation of malloc(). This value is only - incremented if spdylay_nmalloc is nonzero. */ -extern int spdylay_nmalloc; + incremented if nghttp2_nmalloc is nonzero. */ +extern int nghttp2_nmalloc; void* malloc(size_t size); -/* Copies spdylay_failmalloc and spdylay_countmalloc to statically +/* Copies nghttp2_failmalloc and nghttp2_countmalloc to statically allocated space and sets 0 to them. This will effectively make malloc() work like normal malloc(). This is useful when you want to disable malloc() failure mode temporarily. */ -void spdylay_failmalloc_pause(void); +void nghttp2_failmalloc_pause(void); -/* Restores the values of spdylay_failmalloc and spdylay_countmalloc +/* Restores the values of nghttp2_failmalloc and nghttp2_countmalloc with the values saved by the previous - spdylay_failmalloc_pause(). */ -void spdylay_failmalloc_unpause(void); + nghttp2_failmalloc_pause(). */ +void nghttp2_failmalloc_unpause(void); #endif /* MALLOC_WRAPPER_H */ diff --git a/tests/nghttp2_buffer_test.c b/tests/nghttp2_buffer_test.c new file mode 100644 index 00000000..edb95267 --- /dev/null +++ b/tests/nghttp2_buffer_test.c @@ -0,0 +1,124 @@ +/* + * 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_buffer_test.h" + +#include + +#include + +#include "nghttp2_buffer.h" +#include "nghttp2_net.h" + +void test_nghttp2_buffer(void) +{ + nghttp2_buffer buffer; + uint8_t out[1024]; + nghttp2_buffer_init(&buffer, 8); + CU_ASSERT(0 == nghttp2_buffer_length(&buffer)); + CU_ASSERT(0 == nghttp2_buffer_avail(&buffer)); + CU_ASSERT(NULL == nghttp2_buffer_get(&buffer)); + CU_ASSERT(0 == nghttp2_buffer_alloc(&buffer)); + + CU_ASSERT(8 == nghttp2_buffer_avail(&buffer)); + CU_ASSERT(NULL != nghttp2_buffer_get(&buffer)); + memcpy(nghttp2_buffer_get(&buffer), "012", 3); + nghttp2_buffer_advance(&buffer, 3); + CU_ASSERT(3 == nghttp2_buffer_length(&buffer)); + + CU_ASSERT(5 == nghttp2_buffer_avail(&buffer)); + memcpy(nghttp2_buffer_get(&buffer), "34567", 5); + nghttp2_buffer_advance(&buffer, 5); + CU_ASSERT(8 == nghttp2_buffer_length(&buffer)); + + CU_ASSERT(0 == nghttp2_buffer_avail(&buffer)); + CU_ASSERT(0 == nghttp2_buffer_alloc(&buffer)); + memcpy(nghttp2_buffer_get(&buffer), "89ABCDE", 7); + nghttp2_buffer_advance(&buffer, 7); + CU_ASSERT(15 == nghttp2_buffer_length(&buffer)); + + CU_ASSERT(1 == nghttp2_buffer_avail(&buffer)); + + nghttp2_buffer_serialize(&buffer, out); + CU_ASSERT(0 == memcmp("0123456789ABCDE", out, 15)); + + nghttp2_buffer_reset(&buffer); + + CU_ASSERT(0 == nghttp2_buffer_length(&buffer)); + CU_ASSERT(0 == nghttp2_buffer_avail(&buffer)); + CU_ASSERT(NULL == nghttp2_buffer_get(&buffer)); + CU_ASSERT(0 == nghttp2_buffer_alloc(&buffer)); + + CU_ASSERT(8 == nghttp2_buffer_avail(&buffer)); + memcpy(nghttp2_buffer_get(&buffer), "Hello", 5); + nghttp2_buffer_advance(&buffer, 5); + CU_ASSERT(5 == nghttp2_buffer_length(&buffer)); + + nghttp2_buffer_serialize(&buffer, out); + CU_ASSERT(0 == memcmp("Hello", out, 5)); + + nghttp2_buffer_free(&buffer); +} + +void test_nghttp2_buffer_reader(void) +{ + nghttp2_buffer buffer; + nghttp2_buffer_reader reader; + uint16_t val16; + uint32_t val32; + uint8_t temp[256]; + + nghttp2_buffer_init(&buffer, 3); + nghttp2_buffer_write(&buffer, (const uint8_t*)"hello", 5); + val16 = htons(678); + nghttp2_buffer_write(&buffer, (const uint8_t*)&val16, sizeof(uint16_t)); + val32 = htonl(1000000007); + nghttp2_buffer_write(&buffer, (const uint8_t*)&val32, sizeof(uint32_t)); + nghttp2_buffer_write(&buffer, (const uint8_t*)"world", 5); + + CU_ASSERT(5+2+4+5 == nghttp2_buffer_length(&buffer)); + + nghttp2_buffer_reader_init(&reader, &buffer); + + nghttp2_buffer_reader_data(&reader, temp, 5); + CU_ASSERT(memcmp(temp, "hello", 5) == 0); + CU_ASSERT(678 == nghttp2_buffer_reader_uint16(&reader)); + CU_ASSERT(1000000007 == nghttp2_buffer_reader_uint32(&reader)); + CU_ASSERT('w' == nghttp2_buffer_reader_uint8(&reader)); + CU_ASSERT('o' == nghttp2_buffer_reader_uint8(&reader)); + CU_ASSERT('r' == nghttp2_buffer_reader_uint8(&reader)); + CU_ASSERT('l' == nghttp2_buffer_reader_uint8(&reader)); + CU_ASSERT('d' == nghttp2_buffer_reader_uint8(&reader)); + + nghttp2_buffer_reader_init(&reader, &buffer); + nghttp2_buffer_reader_advance(&reader, 5); + CU_ASSERT(678 == nghttp2_buffer_reader_uint16(&reader)); + nghttp2_buffer_reader_advance(&reader, 1); + nghttp2_buffer_reader_advance(&reader, 1); + nghttp2_buffer_reader_advance(&reader, 1); + nghttp2_buffer_reader_advance(&reader, 1); + CU_ASSERT('w' == nghttp2_buffer_reader_uint8(&reader)); + + nghttp2_buffer_free(&buffer); +} diff --git a/tests/nghttp2_buffer_test.h b/tests/nghttp2_buffer_test.h new file mode 100644 index 00000000..e884c3a7 --- /dev/null +++ b/tests/nghttp2_buffer_test.h @@ -0,0 +1,31 @@ +/* + * 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. + */ +#ifndef NGHTTP2_BUFFER_TEST_H +#define NGHTTP2_BUFFER_TEST_H + +void test_nghttp2_buffer(void); +void test_nghttp2_buffer_reader(void); + +#endif /* NGHTTP2_BUFFER_TEST_H */ diff --git a/tests/nghttp2_client_cert_vector_test.c b/tests/nghttp2_client_cert_vector_test.c new file mode 100644 index 00000000..e7a6f72d --- /dev/null +++ b/tests/nghttp2_client_cert_vector_test.c @@ -0,0 +1,124 @@ +/* + * 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_client_cert_vector_test.h" + +#include + +#include "nghttp2_client_cert_vector.h" + +static nghttp2_origin* create_origin(const char *scheme, const char *host, + uint16_t port) +{ + nghttp2_origin *origin = malloc(sizeof(nghttp2_origin)); + nghttp2_origin_set(origin, scheme, host, port); + return origin; +} + +void test_nghttp2_client_cert_vector_find(void) +{ + nghttp2_client_cert_vector certvec; + nghttp2_origin *origin; + const nghttp2_origin *origin_get; + size_t slot; + nghttp2_client_cert_vector_init(&certvec, 3); + + origin = create_origin("https", "example.org", 443); + CU_ASSERT(0 == nghttp2_client_cert_vector_find(&certvec, origin)); + CU_ASSERT(1 == nghttp2_client_cert_vector_put(&certvec, origin)); + slot = nghttp2_client_cert_vector_find(&certvec, origin); + CU_ASSERT(1 == slot); + origin_get = nghttp2_client_cert_vector_get_origin(&certvec, slot); + CU_ASSERT(strcmp(origin->scheme, origin_get->scheme) == 0); + CU_ASSERT(strcmp(origin->host, origin_get->host) == 0); + CU_ASSERT(origin->port == origin_get->port); + + origin = create_origin("https", "example.org", 8443); + CU_ASSERT(0 == nghttp2_client_cert_vector_find(&certvec, origin)); + CU_ASSERT(2 == nghttp2_client_cert_vector_put(&certvec, origin)); + slot = nghttp2_client_cert_vector_find(&certvec, origin); + CU_ASSERT(2 == slot); + + origin = create_origin("https", "example.com", 443); + CU_ASSERT(0 == nghttp2_client_cert_vector_find(&certvec, origin)); + CU_ASSERT(3 == nghttp2_client_cert_vector_put(&certvec, origin)); + slot = nghttp2_client_cert_vector_find(&certvec, origin); + CU_ASSERT(3 == slot); + + origin = create_origin("https", "example.com", 8443); + CU_ASSERT(0 == nghttp2_client_cert_vector_find(&certvec, origin)); + CU_ASSERT(1 == nghttp2_client_cert_vector_put(&certvec, origin)); + slot = nghttp2_client_cert_vector_find(&certvec, origin); + CU_ASSERT(1 == slot); + + origin = create_origin("https", "example.org", 443); + CU_ASSERT(0 == nghttp2_client_cert_vector_find(&certvec, origin)); + free(origin); + + nghttp2_client_cert_vector_free(&certvec); +} + +void test_nghttp2_client_cert_vector_resize(void) +{ + nghttp2_client_cert_vector certvec; + nghttp2_origin *origin; + size_t i; + nghttp2_client_cert_vector_init(&certvec, 3); + + origin = create_origin("https", "example.org", 443); + nghttp2_client_cert_vector_put(&certvec, origin); + origin = create_origin("https", "example.com", 443); + nghttp2_client_cert_vector_put(&certvec, origin); + + CU_ASSERT(0 == nghttp2_client_cert_vector_resize(&certvec, 1)); + CU_ASSERT(NULL != nghttp2_client_cert_vector_get_origin(&certvec, 1)); + CU_ASSERT(1 == certvec.last_slot); + + CU_ASSERT(0 == nghttp2_client_cert_vector_resize(&certvec, 8)); + CU_ASSERT(NULL != nghttp2_client_cert_vector_get_origin(&certvec, 1)); + CU_ASSERT(1 == certvec.last_slot); + for(i = 2; i <= 8; ++i) { + CU_ASSERT(NULL == nghttp2_client_cert_vector_get_origin(&certvec, i)); + } + + nghttp2_client_cert_vector_free(&certvec); +} + +void test_nghttp2_client_cert_vector_get_origin(void) +{ + nghttp2_client_cert_vector certvec; + nghttp2_origin *origin; + nghttp2_client_cert_vector_init(&certvec, 3); + + origin = create_origin("https", "example.org", 443); + CU_ASSERT(1 == nghttp2_client_cert_vector_put(&certvec, origin)); + + CU_ASSERT(NULL == nghttp2_client_cert_vector_get_origin(&certvec, 0)); + CU_ASSERT(NULL != nghttp2_client_cert_vector_get_origin(&certvec, 1)); + CU_ASSERT(NULL == nghttp2_client_cert_vector_get_origin(&certvec, 2)); + CU_ASSERT(NULL == nghttp2_client_cert_vector_get_origin(&certvec, 3)); + CU_ASSERT(NULL == nghttp2_client_cert_vector_get_origin(&certvec, 4)); + + nghttp2_client_cert_vector_free(&certvec); +} diff --git a/tests/nghttp2_client_cert_vector_test.h b/tests/nghttp2_client_cert_vector_test.h new file mode 100644 index 00000000..151dce99 --- /dev/null +++ b/tests/nghttp2_client_cert_vector_test.h @@ -0,0 +1,32 @@ +/* + * 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. + */ +#ifndef NGHTTP2_CLIENT_CERT_VECTOR_TEST_H +#define NGHTTP2_CLIENT_CERT_VECTOR_TEST_H + +void test_nghttp2_client_cert_vector_find(void); +void test_nghttp2_client_cert_vector_resize(void); +void test_nghttp2_client_cert_vector_get_origin(void); + +#endif /* NGHTTP2_CLIENT_CERT_VECTOR_TEST_H */ diff --git a/tests/spdylay_frame_test.c b/tests/nghttp2_frame_test.c similarity index 50% rename from tests/spdylay_frame_test.c rename to tests/nghttp2_frame_test.c index 6c3edc22..076abc46 100644 --- a/tests/spdylay_frame_test.c +++ b/tests/nghttp2_frame_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,15 +22,15 @@ * 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_frame_test.h" +#include "nghttp2_frame_test.h" #include #include -#include "spdylay_frame.h" -#include "spdylay_helper.h" -#include "spdylay_test_helper.h" +#include "nghttp2_frame.h" +#include "nghttp2_helper.h" +#include "nghttp2_test_helper.h" /* Reads |len_size| byte from |data| as |len_size| byte network byte order integer, and returns it in host byte order. Currently, we @@ -38,9 +38,9 @@ static int get_packed_hd_len(uint8_t *data, size_t len_size) { if(len_size == 2) { - return spdylay_get_uint16(data); + return nghttp2_get_uint16(data); } else if(len_size == 4) { - return spdylay_get_uint32(data); + return nghttp2_get_uint32(data); } else { /* Not supported */ assert(0); @@ -59,17 +59,17 @@ static const char *headers[] = { NULL }; -static void test_spdylay_frame_unpack_nv_with(size_t len_size) +static void test_nghttp2_frame_unpack_nv_with(size_t len_size) { uint8_t out[1024]; char **nv; - size_t inlen = spdylay_frame_pack_nv(out, (char**)headers, len_size); - spdylay_buffer buffer; + size_t inlen = nghttp2_frame_pack_nv(out, (char**)headers, len_size); + nghttp2_buffer buffer; - spdylay_buffer_init(&buffer, 4096); - spdylay_buffer_write(&buffer, out, inlen); + nghttp2_buffer_init(&buffer, 4096); + nghttp2_buffer_write(&buffer, out, inlen); - CU_ASSERT(0 == spdylay_frame_unpack_nv(&nv, &buffer, len_size)); + CU_ASSERT(0 == nghttp2_frame_unpack_nv(&nv, &buffer, len_size)); CU_ASSERT(strcmp("method", nv[0]) == 0); CU_ASSERT(strcmp("GET", nv[1]) == 0); CU_ASSERT(strcmp("scheme", nv[2]) == 0); @@ -84,7 +84,7 @@ static void test_spdylay_frame_unpack_nv_with(size_t len_size) CU_ASSERT(strcmp("foo", nv[11]) == 0); CU_ASSERT(strcmp("x-head", nv[12]) == 0); CU_ASSERT(strcmp("bar", nv[13]) == 0); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); /* Create in-sequence NUL bytes */ /* Assuming first chunk has enough space to store 1st name/value @@ -93,26 +93,26 @@ static void test_spdylay_frame_unpack_nv_with(size_t len_size) len_size + strlen(headers[0]) + len_size + strlen(headers[1])-2], "\0\0", 2); - CU_ASSERT(SPDYLAY_ERR_INVALID_HEADER_BLOCK == - spdylay_frame_unpack_nv(&nv, &buffer, len_size)); + CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK == + nghttp2_frame_unpack_nv(&nv, &buffer, len_size)); - spdylay_frame_nv_del(nv); - spdylay_buffer_free(&buffer); + nghttp2_frame_nv_del(nv); + nghttp2_buffer_free(&buffer); } -void test_spdylay_frame_unpack_nv_spdy2(void) +void test_nghttp2_frame_unpack_nv_spdy2(void) { - test_spdylay_frame_unpack_nv_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY2)); + test_nghttp2_frame_unpack_nv_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY2)); } -void test_spdylay_frame_unpack_nv_spdy3(void) +void test_nghttp2_frame_unpack_nv_spdy3(void) { - test_spdylay_frame_unpack_nv_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY2)); + test_nghttp2_frame_unpack_nv_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY2)); } -void test_spdylay_frame_pack_nv_duplicate_keys(void) +void test_nghttp2_frame_pack_nv_duplicate_keys(void) { uint8_t out[1024]; size_t len_size = 2; @@ -125,78 +125,78 @@ void test_spdylay_frame_pack_nv_duplicate_keys(void) "version", "HTTP/1.1", NULL }; - char **nv = spdylay_frame_nv_norm_copy(nv_src); + char **nv = nghttp2_frame_nv_norm_copy(nv_src); const uint8_t *outptr; int pairs, len; - /* size_t inlen = */ spdylay_frame_pack_nv(out, nv, len_size); + /* size_t inlen = */ nghttp2_frame_pack_nv(out, nv, len_size); outptr = out; - pairs = spdylay_get_uint16(outptr); + pairs = nghttp2_get_uint16(outptr); CU_ASSERT(pairs == 5); outptr += 2; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 6); CU_ASSERT(memcmp(outptr, "method", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 3); CU_ASSERT(memcmp(outptr, "GET", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 6); CU_ASSERT(memcmp(outptr, "scheme", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 5); CU_ASSERT(memcmp(outptr, "https", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 3); CU_ASSERT(memcmp(outptr, "url", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 1); CU_ASSERT(memcmp(outptr, "/", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 7); CU_ASSERT(memcmp(outptr, "version", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 8); CU_ASSERT(memcmp(outptr, "HTTP/1.1", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 6); CU_ASSERT(memcmp(outptr, "x-head", len) == 0); outptr += len; - len = spdylay_get_uint16(outptr); + len = nghttp2_get_uint16(outptr); outptr += 2; CU_ASSERT(len == 7); CU_ASSERT(memcmp(outptr, "foo\0bar", len) == 0); outptr += len; - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); } static const char *multi_empty_headers1[] = { @@ -217,20 +217,20 @@ static const char *multi_empty_headers3[] = { NULL }; -void test_spdylay_frame_count_nv_space(void) +void test_nghttp2_frame_count_nv_space(void) { size_t len_size = 2; - CU_ASSERT(85 == spdylay_frame_count_nv_space((char**)headers, len_size)); + CU_ASSERT(85 == nghttp2_frame_count_nv_space((char**)headers, len_size)); len_size = 4; - CU_ASSERT(111 == spdylay_frame_count_nv_space((char**)headers, len_size)); + CU_ASSERT(111 == nghttp2_frame_count_nv_space((char**)headers, len_size)); /* only ("a", "") is counted */ - CU_ASSERT(13 == spdylay_frame_count_nv_space((char**)multi_empty_headers1, + CU_ASSERT(13 == nghttp2_frame_count_nv_space((char**)multi_empty_headers1, len_size)); /* only ("a", "/") is counted */ - CU_ASSERT(14 == spdylay_frame_count_nv_space((char**)multi_empty_headers2, + CU_ASSERT(14 == nghttp2_frame_count_nv_space((char**)multi_empty_headers2, len_size)); /* only ("a", "/") is counted */ - CU_ASSERT(14 == spdylay_frame_count_nv_space((char**)multi_empty_headers3, + CU_ASSERT(14 == nghttp2_frame_count_nv_space((char**)multi_empty_headers3, len_size)); } @@ -256,59 +256,59 @@ static void frame_pack_nv_empty_value_check(uint8_t *outptr, } } -static void test_spdylay_frame_pack_nv_empty_value_with(size_t len_size) +static void test_nghttp2_frame_pack_nv_empty_value_with(size_t len_size) { uint8_t out[256]; char **nv; ssize_t rv; int off = (len_size == 2 ? -6 : 0); - nv = spdylay_frame_nv_copy(multi_empty_headers1); - rv = spdylay_frame_pack_nv(out, nv, len_size); + nv = nghttp2_frame_nv_copy(multi_empty_headers1); + rv = nghttp2_frame_pack_nv(out, nv, len_size); CU_ASSERT(13+off == rv); frame_pack_nv_empty_value_check(out, 0, NULL, len_size); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); - nv = spdylay_frame_nv_copy(multi_empty_headers2); - rv = spdylay_frame_pack_nv(out, nv, len_size); + nv = nghttp2_frame_nv_copy(multi_empty_headers2); + rv = nghttp2_frame_pack_nv(out, nv, len_size); CU_ASSERT(14+off == rv); frame_pack_nv_empty_value_check(out, 1, "/", len_size); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); - nv = spdylay_frame_nv_copy(multi_empty_headers3); - rv = spdylay_frame_pack_nv(out, nv, len_size); + nv = nghttp2_frame_nv_copy(multi_empty_headers3); + rv = nghttp2_frame_pack_nv(out, nv, len_size); CU_ASSERT(14+off == rv); frame_pack_nv_empty_value_check(out, 1, "/", len_size); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); } -void test_spdylay_frame_pack_nv_empty_value_spdy2(void) +void test_nghttp2_frame_pack_nv_empty_value_spdy2(void) { - test_spdylay_frame_pack_nv_empty_value_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY2)); + test_nghttp2_frame_pack_nv_empty_value_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY2)); } -void test_spdylay_frame_pack_nv_empty_value_spdy3(void) +void test_nghttp2_frame_pack_nv_empty_value_spdy3(void) { - test_spdylay_frame_pack_nv_empty_value_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY3)); + test_nghttp2_frame_pack_nv_empty_value_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY3)); } -void test_spdylay_frame_count_unpack_nv_space(void) +void test_nghttp2_frame_count_unpack_nv_space(void) { size_t nvlen, buflen; uint8_t out[1024]; size_t len_size = 2; - size_t inlen = spdylay_frame_pack_nv(out, (char**)headers, len_size); + size_t inlen = nghttp2_frame_pack_nv(out, (char**)headers, len_size); uint16_t temp; size_t expected_buflen; - spdylay_buffer buffer; + nghttp2_buffer buffer; uint8_t *chunk; - spdylay_buffer_init(&buffer, 4096); - spdylay_buffer_write(&buffer, out, inlen); + nghttp2_buffer_init(&buffer, 4096); + nghttp2_buffer_write(&buffer, out, inlen); - CU_ASSERT(0 == spdylay_frame_count_unpack_nv_space(&nvlen, &buflen, + CU_ASSERT(0 == nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, len_size)); CU_ASSERT(7 == nvlen); expected_buflen = 71+(nvlen*2+1)*sizeof(char*); @@ -316,115 +316,115 @@ void test_spdylay_frame_count_unpack_nv_space(void) chunk = buffer.root.next->data; /* Change number of nv pair to a bogus value */ - temp = spdylay_get_uint16(chunk); - spdylay_put_uint16be(chunk, temp+1); - CU_ASSERT(SPDYLAY_ERR_INVALID_FRAME == - spdylay_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, + temp = nghttp2_get_uint16(chunk); + nghttp2_put_uint16be(chunk, temp+1); + CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME == + nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, len_size)); - spdylay_put_uint16be(chunk, temp); + nghttp2_put_uint16be(chunk, temp); /* Change the length of name to a bogus value */ - temp = spdylay_get_uint16(chunk+2); - spdylay_put_uint16be(chunk+2, temp+1); - CU_ASSERT(SPDYLAY_ERR_INVALID_FRAME == - spdylay_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, + temp = nghttp2_get_uint16(chunk+2); + nghttp2_put_uint16be(chunk+2, temp+1); + CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME == + nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, len_size)); - spdylay_put_uint16be(chunk+2, 65535); - CU_ASSERT(SPDYLAY_ERR_INVALID_FRAME == - spdylay_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, + nghttp2_put_uint16be(chunk+2, 65535); + CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME == + nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, len_size)); /* Trailing garbage */ - spdylay_buffer_advance(&buffer, 2); - CU_ASSERT(SPDYLAY_ERR_INVALID_FRAME == - spdylay_frame_count_unpack_nv_space(&nvlen, &buflen, + nghttp2_buffer_advance(&buffer, 2); + CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME == + nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer, len_size)); /* We advanced buffer 2 bytes, so it is not valid any more. */ - spdylay_buffer_free(&buffer); + nghttp2_buffer_free(&buffer); } -void test_spdylay_frame_pack_ping(void) +void test_nghttp2_frame_pack_ping(void) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - spdylay_frame_ping_init(&frame.ping, SPDYLAY_PROTO_SPDY2, 1); - framelen = spdylay_frame_pack_ping(&buf, &buflen, &frame.ping); - CU_ASSERT(0 == spdylay_frame_unpack_ping + nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY2, 1); + framelen = nghttp2_frame_pack_ping(&buf, &buflen, &frame.ping); + CU_ASSERT(0 == nghttp2_frame_unpack_ping (&oframe.ping, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH)); + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH)); CU_ASSERT(1 == oframe.ping.unique_id); free(buf); - spdylay_frame_ping_free(&oframe.ping); - spdylay_frame_ping_free(&frame.ping); + nghttp2_frame_ping_free(&oframe.ping); + nghttp2_frame_ping_free(&frame.ping); } -static void test_spdylay_frame_pack_goaway_version(uint16_t version) +static void test_nghttp2_frame_pack_goaway_version(uint16_t version) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - spdylay_frame_goaway_init(&frame.goaway, version, 1000000007, - SPDYLAY_GOAWAY_PROTOCOL_ERROR); - framelen = spdylay_frame_pack_goaway(&buf, &buflen, &frame.goaway); - CU_ASSERT(0 == spdylay_frame_unpack_goaway + nghttp2_frame_goaway_init(&frame.goaway, version, 1000000007, + NGHTTP2_GOAWAY_PROTOCOL_ERROR); + framelen = nghttp2_frame_pack_goaway(&buf, &buflen, &frame.goaway); + CU_ASSERT(0 == nghttp2_frame_unpack_goaway (&oframe.goaway, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH)); + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH)); CU_ASSERT(1000000007 == oframe.goaway.last_good_stream_id); - if(version == SPDYLAY_PROTO_SPDY2) { + if(version == NGHTTP2_PROTO_SPDY2) { /* The status code is ignored in SPDY/2 */ CU_ASSERT(0 == oframe.goaway.status_code); - } else if(version == SPDYLAY_PROTO_SPDY3) { - CU_ASSERT(SPDYLAY_GOAWAY_PROTOCOL_ERROR == oframe.goaway.status_code); + } else if(version == NGHTTP2_PROTO_SPDY3) { + CU_ASSERT(NGHTTP2_GOAWAY_PROTOCOL_ERROR == oframe.goaway.status_code); } CU_ASSERT(version == oframe.goaway.hd.version); - CU_ASSERT(SPDYLAY_GOAWAY == oframe.goaway.hd.type); - CU_ASSERT(SPDYLAY_CTRL_FLAG_NONE == oframe.goaway.hd.flags); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.goaway.hd.length); + CU_ASSERT(NGHTTP2_GOAWAY == oframe.goaway.hd.type); + CU_ASSERT(NGHTTP2_CTRL_FLAG_NONE == oframe.goaway.hd.flags); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.goaway.hd.length); free(buf); - spdylay_frame_goaway_free(&oframe.goaway); - spdylay_frame_goaway_free(&frame.goaway); + nghttp2_frame_goaway_free(&oframe.goaway); + nghttp2_frame_goaway_free(&frame.goaway); } -void test_spdylay_frame_pack_goaway_spdy2(void) +void test_nghttp2_frame_pack_goaway_spdy2(void) { - test_spdylay_frame_pack_goaway_version(SPDYLAY_PROTO_SPDY2); + test_nghttp2_frame_pack_goaway_version(NGHTTP2_PROTO_SPDY2); } -void test_spdylay_frame_pack_goaway_spdy3(void) +void test_nghttp2_frame_pack_goaway_spdy3(void) { - test_spdylay_frame_pack_goaway_version(SPDYLAY_PROTO_SPDY3); + test_nghttp2_frame_pack_goaway_version(NGHTTP2_PROTO_SPDY3); } -static void test_spdylay_frame_pack_syn_stream_version(uint16_t version) +static void test_nghttp2_frame_pack_syn_stream_version(uint16_t version) { - spdylay_zlib deflater, inflater; - spdylay_frame frame, oframe; + nghttp2_zlib deflater, inflater; + nghttp2_frame frame, oframe; uint8_t *buf = NULL, *nvbuf = NULL; size_t buflen = 0, nvbuflen = 0; ssize_t framelen; uint8_t pri; - if(version == SPDYLAY_PROTO_SPDY2) { + if(version == NGHTTP2_PROTO_SPDY2) { pri = 3; } else { pri = 7; } - spdylay_zlib_deflate_hd_init(&deflater, 1, version); - spdylay_zlib_inflate_hd_init(&inflater, version); - spdylay_frame_syn_stream_init(&frame.syn_stream, version, - SPDYLAY_CTRL_FLAG_FIN, 65536, 1000000007, pri, - spdylay_frame_nv_copy(headers)); - framelen = spdylay_frame_pack_syn_stream(&buf, &buflen, + nghttp2_zlib_deflate_hd_init(&deflater, 1, version); + nghttp2_zlib_inflate_hd_init(&inflater, version); + nghttp2_frame_syn_stream_init(&frame.syn_stream, version, + NGHTTP2_CTRL_FLAG_FIN, 65536, 1000000007, pri, + nghttp2_frame_nv_copy(headers)); + framelen = nghttp2_frame_pack_syn_stream(&buf, &buflen, &nvbuf, &nvbuflen, &frame.syn_stream, &deflater); - CU_ASSERT(0 == unpack_frame_with_nv_block(SPDYLAY_SYN_STREAM, + CU_ASSERT(0 == unpack_frame_with_nv_block(NGHTTP2_SYN_STREAM, version, &oframe, &inflater, @@ -432,35 +432,35 @@ static void test_spdylay_frame_pack_syn_stream_version(uint16_t version) CU_ASSERT(65536 == oframe.syn_stream.stream_id); CU_ASSERT(1000000007 == oframe.syn_stream.assoc_stream_id); CU_ASSERT(version == oframe.syn_stream.hd.version); - CU_ASSERT(SPDYLAY_SYN_STREAM == oframe.syn_stream.hd.type); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == oframe.syn_stream.hd.flags); + CU_ASSERT(NGHTTP2_SYN_STREAM == oframe.syn_stream.hd.type); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == oframe.syn_stream.hd.flags); CU_ASSERT(pri == oframe.syn_stream.pri); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.syn_stream.hd.length); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.syn_stream.hd.length); CU_ASSERT(strcmp("method", oframe.syn_stream.nv[0]) == 0); CU_ASSERT(strcmp("GET", oframe.syn_stream.nv[1]) == 0); CU_ASSERT(NULL == oframe.syn_stream.nv[14]); free(buf); free(nvbuf); - spdylay_frame_syn_stream_free(&oframe.syn_stream); - spdylay_frame_syn_stream_free(&frame.syn_stream); - spdylay_zlib_inflate_free(&inflater); - spdylay_zlib_deflate_free(&deflater); + nghttp2_frame_syn_stream_free(&oframe.syn_stream); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + nghttp2_zlib_inflate_free(&inflater); + nghttp2_zlib_deflate_free(&deflater); } -void test_spdylay_frame_pack_syn_stream_spdy2(void) +void test_nghttp2_frame_pack_syn_stream_spdy2(void) { - test_spdylay_frame_pack_syn_stream_version(SPDYLAY_PROTO_SPDY2); + test_nghttp2_frame_pack_syn_stream_version(NGHTTP2_PROTO_SPDY2); } -void test_spdylay_frame_pack_syn_stream_spdy3(void) +void test_nghttp2_frame_pack_syn_stream_spdy3(void) { - test_spdylay_frame_pack_syn_stream_version(SPDYLAY_PROTO_SPDY3); + test_nghttp2_frame_pack_syn_stream_version(NGHTTP2_PROTO_SPDY3); } -void test_spdylay_frame_pack_syn_stream_frame_too_large(void) +void test_nghttp2_frame_pack_syn_stream_frame_too_large(void) { - spdylay_zlib deflater; - spdylay_frame frame; + nghttp2_zlib deflater; + nghttp2_frame frame; uint8_t *buf = NULL, *nvbuf = NULL; size_t buflen = 0, nvbuflen = 0; ssize_t framelen; @@ -470,179 +470,179 @@ void test_spdylay_frame_pack_syn_stream_frame_too_large(void) memset(big_val, '0', big_vallen); big_val[big_vallen] = '\0'; /* No compression */ - spdylay_zlib_deflate_hd_init(&deflater, 0, SPDYLAY_PROTO_SPDY3); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_FIN, 65536, 1000000007, 3, - spdylay_frame_nv_copy(big_hds)); - framelen = spdylay_frame_pack_syn_stream(&buf, &buflen, + nghttp2_zlib_deflate_hd_init(&deflater, 0, NGHTTP2_PROTO_SPDY3); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_FIN, 65536, 1000000007, 3, + nghttp2_frame_nv_copy(big_hds)); + framelen = nghttp2_frame_pack_syn_stream(&buf, &buflen, &nvbuf, &nvbuflen, &frame.syn_stream, &deflater); - CU_ASSERT_EQUAL(SPDYLAY_ERR_FRAME_TOO_LARGE, framelen); + CU_ASSERT_EQUAL(NGHTTP2_ERR_FRAME_TOO_LARGE, framelen); - spdylay_frame_syn_stream_free(&frame.syn_stream); + nghttp2_frame_syn_stream_free(&frame.syn_stream); free(buf); free(nvbuf); free(big_val); - spdylay_zlib_deflate_free(&deflater); + nghttp2_zlib_deflate_free(&deflater); } -static void test_spdylay_frame_pack_syn_reply_version(uint16_t version) +static void test_nghttp2_frame_pack_syn_reply_version(uint16_t version) { - spdylay_zlib deflater, inflater; - spdylay_frame frame, oframe; + nghttp2_zlib deflater, inflater; + nghttp2_frame frame, oframe; uint8_t *buf = NULL, *nvbuf = NULL; size_t buflen = 0, nvbuflen = 0; ssize_t framelen; - spdylay_zlib_deflate_hd_init(&deflater, 1, version); - spdylay_zlib_inflate_hd_init(&inflater, version); - spdylay_frame_syn_reply_init(&frame.syn_reply, version, - SPDYLAY_CTRL_FLAG_FIN, 3, - spdylay_frame_nv_copy(headers)); - framelen = spdylay_frame_pack_syn_reply(&buf, &buflen, + nghttp2_zlib_deflate_hd_init(&deflater, 1, version); + nghttp2_zlib_inflate_hd_init(&inflater, version); + nghttp2_frame_syn_reply_init(&frame.syn_reply, version, + NGHTTP2_CTRL_FLAG_FIN, 3, + nghttp2_frame_nv_copy(headers)); + framelen = nghttp2_frame_pack_syn_reply(&buf, &buflen, &nvbuf, &nvbuflen, &frame.syn_reply, &deflater); - CU_ASSERT(0 == unpack_frame_with_nv_block(SPDYLAY_SYN_REPLY, + CU_ASSERT(0 == unpack_frame_with_nv_block(NGHTTP2_SYN_REPLY, version, &oframe, &inflater, buf, framelen)); CU_ASSERT(3 == oframe.syn_reply.stream_id); CU_ASSERT(version == oframe.syn_reply.hd.version); - CU_ASSERT(SPDYLAY_SYN_REPLY == oframe.syn_reply.hd.type); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == oframe.syn_reply.hd.flags); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.syn_reply.hd.length); + CU_ASSERT(NGHTTP2_SYN_REPLY == oframe.syn_reply.hd.type); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == oframe.syn_reply.hd.flags); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.syn_reply.hd.length); CU_ASSERT(strcmp("method", oframe.syn_reply.nv[0]) == 0); CU_ASSERT(strcmp("GET", oframe.syn_reply.nv[1]) == 0); CU_ASSERT(NULL == oframe.syn_reply.nv[14]); free(buf); free(nvbuf); - spdylay_frame_syn_reply_free(&oframe.syn_reply); - spdylay_frame_syn_reply_free(&frame.syn_reply); - spdylay_zlib_inflate_free(&inflater); - spdylay_zlib_deflate_free(&deflater); + nghttp2_frame_syn_reply_free(&oframe.syn_reply); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + nghttp2_zlib_inflate_free(&inflater); + nghttp2_zlib_deflate_free(&deflater); } -void test_spdylay_frame_pack_syn_reply_spdy2(void) +void test_nghttp2_frame_pack_syn_reply_spdy2(void) { - test_spdylay_frame_pack_syn_reply_version(SPDYLAY_PROTO_SPDY2); + test_nghttp2_frame_pack_syn_reply_version(NGHTTP2_PROTO_SPDY2); } -void test_spdylay_frame_pack_syn_reply_spdy3(void) +void test_nghttp2_frame_pack_syn_reply_spdy3(void) { - test_spdylay_frame_pack_syn_reply_version(SPDYLAY_PROTO_SPDY3); + test_nghttp2_frame_pack_syn_reply_version(NGHTTP2_PROTO_SPDY3); } -static void test_spdylay_frame_pack_headers_version(uint16_t version) +static void test_nghttp2_frame_pack_headers_version(uint16_t version) { - spdylay_zlib deflater, inflater; - spdylay_frame frame, oframe; + nghttp2_zlib deflater, inflater; + nghttp2_frame frame, oframe; uint8_t *buf = NULL, *nvbuf = NULL; size_t buflen = 0, nvbuflen = 0; - spdylay_buffer inflatebuf; + nghttp2_buffer inflatebuf; ssize_t framelen; - spdylay_buffer_init(&inflatebuf, 4096); - spdylay_zlib_deflate_hd_init(&deflater, 1, version); - spdylay_zlib_inflate_hd_init(&inflater, version); - spdylay_frame_headers_init(&frame.headers, version, - SPDYLAY_CTRL_FLAG_FIN, 3, - spdylay_frame_nv_copy(headers)); - framelen = spdylay_frame_pack_headers(&buf, &buflen, + nghttp2_buffer_init(&inflatebuf, 4096); + nghttp2_zlib_deflate_hd_init(&deflater, 1, version); + nghttp2_zlib_inflate_hd_init(&inflater, version); + nghttp2_frame_headers_init(&frame.headers, version, + NGHTTP2_CTRL_FLAG_FIN, 3, + nghttp2_frame_nv_copy(headers)); + framelen = nghttp2_frame_pack_headers(&buf, &buflen, &nvbuf, &nvbuflen, &frame.headers, &deflater); - CU_ASSERT(0 == unpack_frame_with_nv_block(SPDYLAY_HEADERS, + CU_ASSERT(0 == unpack_frame_with_nv_block(NGHTTP2_HEADERS, version, &oframe, &inflater, buf, framelen)); CU_ASSERT(3 == oframe.headers.stream_id); CU_ASSERT(version == oframe.headers.hd.version); - CU_ASSERT(SPDYLAY_HEADERS == oframe.headers.hd.type); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == oframe.headers.hd.flags); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.headers.hd.length); + CU_ASSERT(NGHTTP2_HEADERS == oframe.headers.hd.type); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == oframe.headers.hd.flags); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.headers.hd.length); CU_ASSERT(strcmp("method", oframe.headers.nv[0]) == 0); CU_ASSERT(strcmp("GET", oframe.headers.nv[1]) == 0); CU_ASSERT(NULL == oframe.headers.nv[14]); free(buf); free(nvbuf); - spdylay_frame_headers_free(&oframe.headers); - spdylay_frame_headers_free(&frame.headers); - spdylay_zlib_inflate_free(&inflater); - spdylay_zlib_deflate_free(&deflater); - spdylay_buffer_free(&inflatebuf); + nghttp2_frame_headers_free(&oframe.headers); + nghttp2_frame_headers_free(&frame.headers); + nghttp2_zlib_inflate_free(&inflater); + nghttp2_zlib_deflate_free(&deflater); + nghttp2_buffer_free(&inflatebuf); } -void test_spdylay_frame_pack_headers_spdy2(void) +void test_nghttp2_frame_pack_headers_spdy2(void) { - test_spdylay_frame_pack_headers_version(SPDYLAY_PROTO_SPDY2); + test_nghttp2_frame_pack_headers_version(NGHTTP2_PROTO_SPDY2); } -void test_spdylay_frame_pack_headers_spdy3(void) +void test_nghttp2_frame_pack_headers_spdy3(void) { - test_spdylay_frame_pack_headers_version(SPDYLAY_PROTO_SPDY3); + test_nghttp2_frame_pack_headers_version(NGHTTP2_PROTO_SPDY3); } -void test_spdylay_frame_pack_window_update(void) +void test_nghttp2_frame_pack_window_update(void) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - spdylay_frame_window_update_init(&frame.window_update, SPDYLAY_PROTO_SPDY3, + nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_PROTO_SPDY3, 1000000007, 4096); - framelen = spdylay_frame_pack_window_update(&buf, &buflen, + framelen = nghttp2_frame_pack_window_update(&buf, &buflen, &frame.window_update); - CU_ASSERT(0 == spdylay_frame_unpack_window_update + CU_ASSERT(0 == nghttp2_frame_unpack_window_update (&oframe.window_update, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH)); + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH)); CU_ASSERT(1000000007 == oframe.window_update.stream_id); CU_ASSERT(4096 == oframe.window_update.delta_window_size); - CU_ASSERT(SPDYLAY_PROTO_SPDY3 == oframe.window_update.hd.version); - CU_ASSERT(SPDYLAY_WINDOW_UPDATE == oframe.window_update.hd.type); - CU_ASSERT(SPDYLAY_CTRL_FLAG_NONE == oframe.window_update.hd.flags); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == + CU_ASSERT(NGHTTP2_PROTO_SPDY3 == oframe.window_update.hd.version); + CU_ASSERT(NGHTTP2_WINDOW_UPDATE == oframe.window_update.hd.type); + CU_ASSERT(NGHTTP2_CTRL_FLAG_NONE == oframe.window_update.hd.flags); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.window_update.hd.length); free(buf); - spdylay_frame_window_update_free(&oframe.window_update); - spdylay_frame_window_update_free(&frame.window_update); + nghttp2_frame_window_update_free(&oframe.window_update); + nghttp2_frame_window_update_free(&frame.window_update); } -static void test_spdylay_frame_pack_settings_version(uint16_t version) +static void test_nghttp2_frame_pack_settings_version(uint16_t version) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; int i; - spdylay_settings_entry iv[3]; - iv[0].settings_id = SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE; + nghttp2_settings_entry iv[3]; + iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE; iv[0].value = 256; - iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; iv[1].value = 100; - iv[2].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; - iv[2].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + iv[2].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[2].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; iv[2].value = 65536; - spdylay_frame_settings_init - (&frame.settings, version, SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS, - spdylay_frame_iv_copy(iv, 3), 3); - framelen = spdylay_frame_pack_settings(&buf, &buflen, &frame.settings); + nghttp2_frame_settings_init + (&frame.settings, version, NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS, + nghttp2_frame_iv_copy(iv, 3), 3); + framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame.settings); CU_ASSERT(8+4+3*8 == framelen); - CU_ASSERT(0 == spdylay_frame_unpack_settings + CU_ASSERT(0 == nghttp2_frame_unpack_settings (&oframe.settings, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH)); + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH)); CU_ASSERT(version == oframe.settings.hd.version); - CU_ASSERT(SPDYLAY_SETTINGS == oframe.settings.hd.type); - CU_ASSERT(SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS == oframe.settings.hd.flags); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.settings.hd.length); + CU_ASSERT(NGHTTP2_SETTINGS == oframe.settings.hd.type); + CU_ASSERT(NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS == oframe.settings.hd.flags); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.settings.hd.length); CU_ASSERT(3 == oframe.settings.niv); for(i = 0; i < 3; ++i) { @@ -652,18 +652,18 @@ static void test_spdylay_frame_pack_settings_version(uint16_t version) } free(buf); - spdylay_frame_settings_free(&frame.settings); - spdylay_frame_settings_free(&oframe.settings); + nghttp2_frame_settings_free(&frame.settings); + nghttp2_frame_settings_free(&oframe.settings); } -void test_spdylay_frame_pack_settings_spdy2(void) +void test_nghttp2_frame_pack_settings_spdy2(void) { - test_spdylay_frame_pack_settings_version(SPDYLAY_PROTO_SPDY2); + test_nghttp2_frame_pack_settings_version(NGHTTP2_PROTO_SPDY2); } -void test_spdylay_frame_pack_settings_spdy3(void) +void test_nghttp2_frame_pack_settings_spdy3(void) { - test_spdylay_frame_pack_settings_version(SPDYLAY_PROTO_SPDY3); + test_nghttp2_frame_pack_settings_version(NGHTTP2_PROTO_SPDY3); } static char* strcopy(const char* s) @@ -675,31 +675,31 @@ static char* strcopy(const char* s) return dest; } -void test_spdylay_frame_pack_credential(void) +void test_nghttp2_frame_pack_credential(void) { - spdylay_frame frame, oframe; + nghttp2_frame frame, oframe; uint8_t *buf = NULL; size_t buflen = 0; ssize_t framelen; - spdylay_mem_chunk proof; - spdylay_mem_chunk *certs; + nghttp2_mem_chunk proof; + nghttp2_mem_chunk *certs; size_t ncerts; proof.data = (uint8_t*)strcopy("PROOF"); proof.length = strlen("PROOF"); ncerts = 2; - certs = malloc(sizeof(spdylay_mem_chunk)*ncerts); + certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts); certs[0].data = (uint8_t*)strcopy("CERT0"); certs[0].length = strlen("CERT0"); certs[1].data = (uint8_t*)strcopy("CERT1"); certs[1].length = strlen("CERT1"); - spdylay_frame_credential_init(&frame.credential, SPDYLAY_PROTO_SPDY3, + nghttp2_frame_credential_init(&frame.credential, NGHTTP2_PROTO_SPDY3, 1, &proof, certs, ncerts); - framelen = spdylay_frame_pack_credential(&buf, &buflen, &frame.credential); - CU_ASSERT(0 == spdylay_frame_unpack_credential + framelen = nghttp2_frame_pack_credential(&buf, &buflen, &frame.credential); + CU_ASSERT(0 == nghttp2_frame_unpack_credential (&oframe.credential, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH)); + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH)); CU_ASSERT(1 == oframe.credential.slot); CU_ASSERT(5 == oframe.credential.proof.length); CU_ASSERT(memcmp("PROOF", oframe.credential.proof.data, 5) == 0); @@ -708,25 +708,25 @@ void test_spdylay_frame_pack_credential(void) CU_ASSERT(memcmp("CERT0", oframe.credential.certs[0].data, 5) == 0); CU_ASSERT(5 == oframe.credential.certs[1].length); CU_ASSERT(memcmp("CERT1", oframe.credential.certs[1].data, 5) == 0); - CU_ASSERT(SPDYLAY_PROTO_SPDY3 == oframe.credential.hd.version); - CU_ASSERT(SPDYLAY_CREDENTIAL == oframe.credential.hd.type); - CU_ASSERT(SPDYLAY_CTRL_FLAG_NONE == oframe.credential.hd.flags); - CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.credential.hd.length); - spdylay_frame_credential_free(&oframe.credential); + CU_ASSERT(NGHTTP2_PROTO_SPDY3 == oframe.credential.hd.version); + CU_ASSERT(NGHTTP2_CREDENTIAL == oframe.credential.hd.type); + CU_ASSERT(NGHTTP2_CTRL_FLAG_NONE == oframe.credential.hd.flags); + CU_ASSERT(framelen-NGHTTP2_FRAME_HEAD_LENGTH == oframe.credential.hd.length); + nghttp2_frame_credential_free(&oframe.credential); /* Put large certificate length */ - spdylay_put_uint32be(&buf[8+2+4+5], INT32_MAX); - CU_ASSERT(SPDYLAY_ERR_INVALID_FRAME == spdylay_frame_unpack_credential + nghttp2_put_uint32be(&buf[8+2+4+5], INT32_MAX); + CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME == nghttp2_frame_unpack_credential (&oframe.credential, - &buf[0], SPDYLAY_FRAME_HEAD_LENGTH, - &buf[SPDYLAY_FRAME_HEAD_LENGTH], - framelen-SPDYLAY_FRAME_HEAD_LENGTH)); + &buf[0], NGHTTP2_FRAME_HEAD_LENGTH, + &buf[NGHTTP2_FRAME_HEAD_LENGTH], + framelen-NGHTTP2_FRAME_HEAD_LENGTH)); free(buf); - spdylay_frame_credential_free(&frame.credential); + nghttp2_frame_credential_free(&frame.credential); } -void test_spdylay_frame_nv_sort(void) +void test_nghttp2_frame_nv_sort(void) { char *nv[7]; nv[0] = (char*)"version"; @@ -736,7 +736,7 @@ void test_spdylay_frame_nv_sort(void) nv[4] = (char*)"scheme"; nv[5] = (char*)"https"; nv[6] = NULL; - spdylay_frame_nv_sort(nv); + nghttp2_frame_nv_sort(nv); CU_ASSERT(strcmp("method", nv[0]) == 0); CU_ASSERT(strcmp("GET", nv[1]) == 0); CU_ASSERT(strcmp("scheme", nv[2]) == 0); @@ -745,7 +745,7 @@ void test_spdylay_frame_nv_sort(void) CU_ASSERT(strcmp("HTTP/1.1", nv[5]) == 0); } -void test_spdylay_frame_nv_downcase(void) +void test_nghttp2_frame_nv_downcase(void) { const char *nv_src[] = { "VERSION", "HTTP/1.1", @@ -753,16 +753,16 @@ void test_spdylay_frame_nv_downcase(void) NULL }; char **nv; - nv = spdylay_frame_nv_copy(nv_src); - spdylay_frame_nv_downcase(nv); + nv = nghttp2_frame_nv_copy(nv_src); + nghttp2_frame_nv_downcase(nv); CU_ASSERT(0 == strcmp("version", nv[0])); CU_ASSERT(0 == strcmp("HTTP/1.1", nv[1])); CU_ASSERT(0 == strcmp("content-length", nv[2])); CU_ASSERT(0 == strcmp("1000000007", nv[3])); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); } -void test_spdylay_frame_nv_2to3(void) +void test_nghttp2_frame_nv_2to3(void) { const char *nv_src[] = { "host", "localhost", @@ -775,8 +775,8 @@ void test_spdylay_frame_nv_2to3(void) NULL }; char **nv; - nv = spdylay_frame_nv_copy(nv_src); - spdylay_frame_nv_2to3(nv); + nv = nghttp2_frame_nv_copy(nv_src); + nghttp2_frame_nv_2to3(nv); CU_ASSERT(0 == strcmp(":host", nv[0])); CU_ASSERT(0 == strcmp(":method", nv[2])); CU_ASSERT(0 == strcmp(":path", nv[4])); @@ -784,10 +784,10 @@ void test_spdylay_frame_nv_2to3(void) CU_ASSERT(0 == strcmp(":scheme", nv[8])); CU_ASSERT(0 == strcmp(":status", nv[10])); CU_ASSERT(0 == strcmp(":version", nv[12])); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); } -void test_spdylay_frame_nv_3to2(void) +void test_nghttp2_frame_nv_3to2(void) { const char *nv_src[] = { ":host", "localhost", @@ -800,8 +800,8 @@ void test_spdylay_frame_nv_3to2(void) NULL }; char **nv; - nv = spdylay_frame_nv_copy(nv_src); - spdylay_frame_nv_3to2(nv); + nv = nghttp2_frame_nv_copy(nv_src); + nghttp2_frame_nv_3to2(nv); CU_ASSERT(0 == strcmp("host", nv[0])); CU_ASSERT(0 == strcmp("method", nv[2])); CU_ASSERT(0 == strcmp("url", nv[4])); @@ -809,23 +809,23 @@ void test_spdylay_frame_nv_3to2(void) CU_ASSERT(0 == strcmp("scheme", nv[8])); CU_ASSERT(0 == strcmp("status", nv[10])); CU_ASSERT(0 == strcmp("version", nv[12])); - spdylay_frame_nv_del(nv); + nghttp2_frame_nv_del(nv); } /* This function intentionally does not merge same header field into one */ -static size_t spdylay_pack_nv(uint8_t *buf, size_t buflen, const char **nv, +static size_t nghttp2_pack_nv(uint8_t *buf, size_t buflen, const char **nv, size_t len_size) { size_t i, n; uint8_t *buf_ptr; buf_ptr = buf; for(n = 0; nv[n]; ++n); - spdylay_frame_put_nv_len(buf_ptr, n/2, len_size); + nghttp2_frame_put_nv_len(buf_ptr, n/2, len_size); buf_ptr += len_size; for(i = 0; i < n; ++i) { size_t len = strlen(nv[i]); - spdylay_frame_put_nv_len(buf_ptr, len, len_size); + nghttp2_frame_put_nv_len(buf_ptr, len, len_size); buf_ptr += len_size; memcpy(buf_ptr, nv[i], len); buf_ptr += len; @@ -847,104 +847,104 @@ static const char *non_ascii_headers[] = { NULL }; -static void test_spdylay_frame_unpack_nv_check_name_with(size_t len_size) +static void test_nghttp2_frame_unpack_nv_check_name_with(size_t len_size) { uint8_t nvbuf[1024]; size_t nvbuflen; - spdylay_buffer buffer; + nghttp2_buffer buffer; char **nv; - spdylay_buffer_init(&buffer, 32); + nghttp2_buffer_init(&buffer, 32); - nvbuflen = spdylay_pack_nv(nvbuf, sizeof(nvbuf), headers, len_size); - spdylay_buffer_write(&buffer, nvbuf, nvbuflen); + nvbuflen = nghttp2_pack_nv(nvbuf, sizeof(nvbuf), headers, len_size); + nghttp2_buffer_write(&buffer, nvbuf, nvbuflen); - CU_ASSERT(SPDYLAY_ERR_INVALID_HEADER_BLOCK == - spdylay_frame_unpack_nv(&nv, &buffer, len_size)); + CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK == + nghttp2_frame_unpack_nv(&nv, &buffer, len_size)); - spdylay_frame_nv_del(nv); - spdylay_buffer_reset(&buffer); + nghttp2_frame_nv_del(nv); + nghttp2_buffer_reset(&buffer); - nvbuflen = spdylay_pack_nv(nvbuf, sizeof(nvbuf), empty_name_headers, + nvbuflen = nghttp2_pack_nv(nvbuf, sizeof(nvbuf), empty_name_headers, len_size); - spdylay_buffer_write(&buffer, nvbuf, nvbuflen); + nghttp2_buffer_write(&buffer, nvbuf, nvbuflen); - CU_ASSERT(SPDYLAY_ERR_INVALID_HEADER_BLOCK == - spdylay_frame_unpack_nv(&nv, &buffer, len_size)); + CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK == + nghttp2_frame_unpack_nv(&nv, &buffer, len_size)); - spdylay_frame_nv_del(nv); - spdylay_buffer_reset(&buffer); + nghttp2_frame_nv_del(nv); + nghttp2_buffer_reset(&buffer); - nvbuflen = spdylay_pack_nv(nvbuf, sizeof(nvbuf), non_ascii_headers, + nvbuflen = nghttp2_pack_nv(nvbuf, sizeof(nvbuf), non_ascii_headers, len_size); - spdylay_buffer_write(&buffer, nvbuf, nvbuflen); - CU_ASSERT(SPDYLAY_ERR_INVALID_HEADER_BLOCK == - spdylay_frame_unpack_nv(&nv, &buffer, len_size)); + nghttp2_buffer_write(&buffer, nvbuf, nvbuflen); + CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK == + nghttp2_frame_unpack_nv(&nv, &buffer, len_size)); - spdylay_frame_nv_del(nv); - spdylay_buffer_free(&buffer); + nghttp2_frame_nv_del(nv); + nghttp2_buffer_free(&buffer); } -void test_spdylay_frame_unpack_nv_check_name_spdy2(void) +void test_nghttp2_frame_unpack_nv_check_name_spdy2(void) { - test_spdylay_frame_unpack_nv_check_name_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY2)); + test_nghttp2_frame_unpack_nv_check_name_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY2)); } -void test_spdylay_frame_unpack_nv_check_name_spdy3(void) +void test_nghttp2_frame_unpack_nv_check_name_spdy3(void) { - test_spdylay_frame_unpack_nv_check_name_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY3)); + test_nghttp2_frame_unpack_nv_check_name_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY3)); } -static void test_spdylay_frame_unpack_nv_last_empty_value_with(size_t len_size) +static void test_nghttp2_frame_unpack_nv_last_empty_value_with(size_t len_size) { size_t nvbuflen; uint8_t nvbuf[256]; uint8_t *nvbufptr; - spdylay_buffer buffer; + nghttp2_buffer buffer; char **outnv = 0; const char hdname[] = "method"; nvbufptr = nvbuf; - spdylay_frame_put_nv_len(nvbufptr, 1, len_size); + nghttp2_frame_put_nv_len(nvbufptr, 1, len_size); nvbufptr += len_size; - spdylay_frame_put_nv_len(nvbufptr, sizeof(hdname)-1, len_size); + nghttp2_frame_put_nv_len(nvbufptr, sizeof(hdname)-1, len_size); nvbufptr += len_size; memcpy(nvbufptr, hdname, sizeof(hdname)-1); nvbufptr += sizeof(hdname)-1; - spdylay_frame_put_nv_len(nvbufptr, 4, len_size); + nghttp2_frame_put_nv_len(nvbufptr, 4, len_size); nvbufptr += len_size; /* Copy including terminating NULL */ memcpy(nvbufptr, "GET", 4); nvbufptr += 4; nvbuflen = nvbufptr - nvbuf; - spdylay_buffer_init(&buffer, 32); + nghttp2_buffer_init(&buffer, 32); - spdylay_buffer_write(&buffer, nvbuf, nvbuflen); - CU_ASSERT(SPDYLAY_ERR_INVALID_HEADER_BLOCK == - spdylay_frame_unpack_nv(&outnv, &buffer, len_size)); + nghttp2_buffer_write(&buffer, nvbuf, nvbuflen); + CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK == + nghttp2_frame_unpack_nv(&outnv, &buffer, len_size)); - spdylay_frame_nv_del(outnv); - spdylay_buffer_free(&buffer); + nghttp2_frame_nv_del(outnv); + nghttp2_buffer_free(&buffer); } -void test_spdylay_frame_unpack_nv_last_empty_value_spdy2(void) +void test_nghttp2_frame_unpack_nv_last_empty_value_spdy2(void) { - test_spdylay_frame_unpack_nv_last_empty_value_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY2)); + test_nghttp2_frame_unpack_nv_last_empty_value_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY2)); } -void test_spdylay_frame_unpack_nv_last_empty_value_spdy3(void) +void test_nghttp2_frame_unpack_nv_last_empty_value_spdy3(void) { - test_spdylay_frame_unpack_nv_last_empty_value_with - (spdylay_frame_get_len_size(SPDYLAY_PROTO_SPDY3)); + test_nghttp2_frame_unpack_nv_last_empty_value_with + (nghttp2_frame_get_len_size(NGHTTP2_PROTO_SPDY3)); } -void test_spdylay_frame_nv_set_origin(void) +void test_nghttp2_frame_nv_set_origin(void) { - spdylay_origin origin; + nghttp2_origin origin; const char *nv1[] = { ":host", "example.org", ":scheme", "https", @@ -968,35 +968,35 @@ void test_spdylay_frame_nv_set_origin(void) ":scheme", "https", NULL }; - CU_ASSERT(0 == spdylay_frame_nv_set_origin((char**)nv1, &origin)); + CU_ASSERT(0 == nghttp2_frame_nv_set_origin((char**)nv1, &origin)); CU_ASSERT(strcmp("https", origin.scheme) == 0); CU_ASSERT(strcmp("example.org", origin.host) == 0); CU_ASSERT(443 == origin.port); - CU_ASSERT(0 == spdylay_frame_nv_set_origin((char**)nv2, &origin)); + CU_ASSERT(0 == nghttp2_frame_nv_set_origin((char**)nv2, &origin)); CU_ASSERT(strcmp("https", origin.scheme) == 0); CU_ASSERT(strcmp("example.org", origin.host) == 0); CU_ASSERT(8443 == origin.port); - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_frame_nv_set_origin((char**)nv3, &origin)); + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_frame_nv_set_origin((char**)nv3, &origin)); - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_frame_nv_set_origin((char**)nv4, &origin)); + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_frame_nv_set_origin((char**)nv4, &origin)); - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_frame_nv_set_origin((char**)nv5, &origin)); + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_frame_nv_set_origin((char**)nv5, &origin)); } -void test_spdylay_frame_nv_check_null(void) +void test_nghttp2_frame_nv_check_null(void) { const char *headers1[] = { "path", "/", "host", "a", NULL }; const char *headers2[] = { "", "/", "host", "a", NULL }; const char *headers3[] = { "path", "/", "host\x01", "a", NULL }; const char *headers4[] = { "path", "/", "host", NULL, NULL }; - CU_ASSERT(spdylay_frame_nv_check_null(headers1)); - CU_ASSERT(0 == spdylay_frame_nv_check_null(headers2)); - CU_ASSERT(0 == spdylay_frame_nv_check_null(headers3)); - CU_ASSERT(0 == spdylay_frame_nv_check_null(headers4)); + CU_ASSERT(nghttp2_frame_nv_check_null(headers1)); + CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers2)); + CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers3)); + CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers4)); } diff --git a/tests/nghttp2_frame_test.h b/tests/nghttp2_frame_test.h new file mode 100644 index 00000000..349cf724 --- /dev/null +++ b/tests/nghttp2_frame_test.h @@ -0,0 +1,60 @@ +/* + * 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. + */ +#ifndef NGHTTP2_FRAME_TEST_H +#define NGHTTP2_FRAME_TEST_H + +void test_nghttp2_frame_unpack_nv_spdy2(void); +void test_nghttp2_frame_unpack_nv_spdy3(void); +void test_nghttp2_frame_pack_nv_duplicate_keys(void); +void test_nghttp2_frame_pack_nv_empty_value_spdy2(void); +void test_nghttp2_frame_pack_nv_empty_value_spdy3(void); +void test_nghttp2_frame_count_nv_space(void); +void test_nghttp2_frame_count_unpack_nv_space(void); +void test_nghttp2_frame_pack_ping(void); +void test_nghttp2_frame_pack_goaway_spdy2(void); +void test_nghttp2_frame_pack_goaway_spdy3(void); +void test_nghttp2_frame_pack_syn_stream_spdy2(void); +void test_nghttp2_frame_pack_syn_stream_spdy3(void); +void test_nghttp2_frame_pack_syn_stream_frame_too_large(void); +void test_nghttp2_frame_pack_syn_reply_spdy2(void); +void test_nghttp2_frame_pack_syn_reply_spdy3(void); +void test_nghttp2_frame_pack_headers_spdy2(void); +void test_nghttp2_frame_pack_headers_spdy3(void); +void test_nghttp2_frame_pack_window_update(void); +void test_nghttp2_frame_pack_settings_spdy2(void); +void test_nghttp2_frame_pack_settings_spdy3(void); +void test_nghttp2_frame_pack_credential(void); +void test_nghttp2_frame_nv_sort(void); +void test_nghttp2_frame_nv_downcase(void); +void test_nghttp2_frame_nv_2to3(void); +void test_nghttp2_frame_nv_3to2(void); +void test_nghttp2_frame_unpack_nv_check_name_spdy2(void); +void test_nghttp2_frame_unpack_nv_check_name_spdy3(void); +void test_nghttp2_frame_unpack_nv_last_empty_value_spdy2(void); +void test_nghttp2_frame_unpack_nv_last_empty_value_spdy3(void); +void test_nghttp2_frame_nv_set_origin(void); +void test_nghttp2_frame_nv_check_null(void); + +#endif /* NGHTTP2_FRAME_TEST_H */ diff --git a/tests/spdylay_gzip_test.c b/tests/nghttp2_gzip_test.c similarity index 88% rename from tests/spdylay_gzip_test.c rename to tests/nghttp2_gzip_test.c index 6f32269a..2573febb 100644 --- a/tests/spdylay_gzip_test.c +++ b/tests/nghttp2_gzip_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,7 +22,7 @@ * 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_gzip_test.h" +#include "nghttp2_gzip_test.h" #include #include @@ -31,7 +31,7 @@ #include -#include "spdylay_gzip.h" +#include "nghttp2_gzip.h" static ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) @@ -67,9 +67,9 @@ static const char input[] = "OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION " "WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; -void test_spdylay_gzip_inflate(void) +void test_nghttp2_gzip_inflate(void) { - spdylay_gzip *inflater; + nghttp2_gzip *inflater; uint8_t in[4096], out[4096], *inptr; size_t inlen = sizeof(in); size_t inproclen, outproclen; @@ -77,12 +77,12 @@ void test_spdylay_gzip_inflate(void) inlen = deflate_data(in, inlen, (const uint8_t*)input, sizeof(input)-1); - CU_ASSERT(0 == spdylay_gzip_inflate_new(&inflater)); + CU_ASSERT(0 == nghttp2_gzip_inflate_new(&inflater)); /* First 16 bytes */ inptr = in; inproclen = inlen; outproclen = 16; - CU_ASSERT(0 == spdylay_gzip_inflate(inflater, out, &outproclen, + CU_ASSERT(0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); CU_ASSERT(16 == outproclen); CU_ASSERT(inproclen > 0); @@ -93,7 +93,7 @@ void test_spdylay_gzip_inflate(void) inproclen = inlen; inputptr += outproclen; outproclen = 32; - CU_ASSERT(0 == spdylay_gzip_inflate(inflater, out, &outproclen, + CU_ASSERT(0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); CU_ASSERT(32 == outproclen); CU_ASSERT(inproclen > 0); @@ -104,7 +104,7 @@ void test_spdylay_gzip_inflate(void) inproclen = inlen; inputptr += outproclen; outproclen = sizeof(out); - CU_ASSERT(0 == spdylay_gzip_inflate(inflater, out, &outproclen, + CU_ASSERT(0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); CU_ASSERT(sizeof(input)-49 == outproclen); CU_ASSERT(inproclen > 0); @@ -113,5 +113,5 @@ void test_spdylay_gzip_inflate(void) inlen -= inproclen; CU_ASSERT(0 == inlen); - spdylay_gzip_inflate_del(inflater); + nghttp2_gzip_inflate_del(inflater); } diff --git a/tests/spdylay_gzip_test.h b/tests/nghttp2_gzip_test.h similarity index 87% rename from tests/spdylay_gzip_test.h rename to tests/nghttp2_gzip_test.h index b1143a3c..404e3c37 100644 --- a/tests/spdylay_gzip_test.h +++ b/tests/nghttp2_gzip_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,9 +22,9 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_GZIP_TEST_H -#define SPDYLAY_GZIP_TEST_H +#ifndef NGHTTP2_GZIP_TEST_H +#define NGHTTP2_GZIP_TEST_H -void test_spdylay_gzip_inflate(void); +void test_nghttp2_gzip_inflate(void); -#endif /* SPDYLAY_GZIP_TEST_H */ +#endif /* NGHTTP2_GZIP_TEST_H */ diff --git a/tests/spdylay_map_test.c b/tests/nghttp2_map_test.c similarity index 55% rename from tests/spdylay_map_test.c rename to tests/nghttp2_map_test.c index 346fe918..7c25b9e6 100644 --- a/tests/spdylay_map_test.c +++ b/tests/nghttp2_map_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,28 +22,28 @@ * 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_map_test.h" +#include "nghttp2_map_test.h" #include -#include "spdylay_map.h" +#include "nghttp2_map.h" typedef struct strentry { - spdylay_map_entry map_entry; + nghttp2_map_entry map_entry; const char *str; } strentry; static void strentry_init(strentry *entry, key_type key, const char *str) { - spdylay_map_entry_init(&entry->map_entry, key); + nghttp2_map_entry_init(&entry->map_entry, key); entry->str = str; } -void test_spdylay_map(void) +void test_nghttp2_map(void) { strentry foo, FOO, bar, baz, shrubbery; - spdylay_map map; - spdylay_map_init(&map); + nghttp2_map map; + nghttp2_map_init(&map); strentry_init(&foo, 1, "foo"); strentry_init(&FOO, 1, "FOO"); @@ -51,45 +51,45 @@ void test_spdylay_map(void) strentry_init(&baz, 3, "baz"); strentry_init(&shrubbery, 4, "shrubbery"); - CU_ASSERT(0 == spdylay_map_insert(&map, &foo.map_entry)); - CU_ASSERT(strcmp("foo", ((strentry*)spdylay_map_find(&map, 1))->str) == 0); - CU_ASSERT(1 == spdylay_map_size(&map)); + CU_ASSERT(0 == nghttp2_map_insert(&map, &foo.map_entry)); + CU_ASSERT(strcmp("foo", ((strentry*)nghttp2_map_find(&map, 1))->str) == 0); + CU_ASSERT(1 == nghttp2_map_size(&map)); - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_map_insert(&map, &FOO.map_entry)); + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_map_insert(&map, &FOO.map_entry)); - CU_ASSERT(1 == spdylay_map_size(&map)); - CU_ASSERT(strcmp("foo", ((strentry*)spdylay_map_find(&map, 1))->str) == 0); + CU_ASSERT(1 == nghttp2_map_size(&map)); + CU_ASSERT(strcmp("foo", ((strentry*)nghttp2_map_find(&map, 1))->str) == 0); - CU_ASSERT(0 == spdylay_map_insert(&map, &bar.map_entry)); - CU_ASSERT(2 == spdylay_map_size(&map)); + CU_ASSERT(0 == nghttp2_map_insert(&map, &bar.map_entry)); + CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(0 == spdylay_map_insert(&map, &baz.map_entry)); - CU_ASSERT(3 == spdylay_map_size(&map)); + CU_ASSERT(0 == nghttp2_map_insert(&map, &baz.map_entry)); + CU_ASSERT(3 == nghttp2_map_size(&map)); - CU_ASSERT(0 == spdylay_map_insert(&map, &shrubbery.map_entry)); - CU_ASSERT(4 == spdylay_map_size(&map)); + CU_ASSERT(0 == nghttp2_map_insert(&map, &shrubbery.map_entry)); + CU_ASSERT(4 == nghttp2_map_size(&map)); - CU_ASSERT(strcmp("baz", ((strentry*)spdylay_map_find(&map, 3))->str) == 0); + CU_ASSERT(strcmp("baz", ((strentry*)nghttp2_map_find(&map, 3))->str) == 0); - spdylay_map_remove(&map, 3); - CU_ASSERT(3 == spdylay_map_size(&map)); - CU_ASSERT(NULL == spdylay_map_find(&map, 3)); + nghttp2_map_remove(&map, 3); + CU_ASSERT(3 == nghttp2_map_size(&map)); + CU_ASSERT(NULL == nghttp2_map_find(&map, 3)); - spdylay_map_remove(&map, 1); - CU_ASSERT(2 == spdylay_map_size(&map)); - CU_ASSERT(NULL == spdylay_map_find(&map, 1)); + nghttp2_map_remove(&map, 1); + CU_ASSERT(2 == nghttp2_map_size(&map)); + CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); /* Erasing non-existent entry */ - spdylay_map_remove(&map, 1); - CU_ASSERT(2 == spdylay_map_size(&map)); - CU_ASSERT(NULL == spdylay_map_find(&map, 1)); + nghttp2_map_remove(&map, 1); + CU_ASSERT(2 == nghttp2_map_size(&map)); + CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); - CU_ASSERT(strcmp("bar", ((strentry*)spdylay_map_find(&map, 2))->str) == 0); + CU_ASSERT(strcmp("bar", ((strentry*)nghttp2_map_find(&map, 2))->str) == 0); CU_ASSERT(strcmp("shrubbery", - ((strentry*)spdylay_map_find(&map, 4))->str) == 0); + ((strentry*)nghttp2_map_find(&map, 4))->str) == 0); - spdylay_map_free(&map); + nghttp2_map_free(&map); } static void shuffle(int *a, int n) @@ -103,7 +103,7 @@ static void shuffle(int *a, int n) } } -static int eachfun(spdylay_map_entry *entry, void *ptr) +static int eachfun(nghttp2_map_entry *entry, void *ptr) { return 0; } @@ -112,12 +112,12 @@ static int eachfun(spdylay_map_entry *entry, void *ptr) strentry arr[NUM_ENT]; int order[NUM_ENT]; -void test_spdylay_map_functional(void) +void test_nghttp2_map_functional(void) { - spdylay_map map; + nghttp2_map map; int i; - spdylay_map_init(&map); + nghttp2_map_init(&map); for(i = 0; i < NUM_ENT; ++i) { strentry_init(&arr[i], i + 1, "foo"); order[i] = i + 1; @@ -125,19 +125,19 @@ void test_spdylay_map_functional(void) /* insertion */ shuffle(order, NUM_ENT); for(i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(0 == spdylay_map_insert(&map, &arr[order[i] - 1].map_entry)); + CU_ASSERT(0 == nghttp2_map_insert(&map, &arr[order[i] - 1].map_entry)); } /* traverse */ - spdylay_map_each(&map, eachfun, NULL); + nghttp2_map_each(&map, eachfun, NULL); /* find */ shuffle(order, NUM_ENT); for(i = 0; i < NUM_ENT; ++i) { - spdylay_map_find(&map, order[i]); + nghttp2_map_find(&map, order[i]); } /* remove */ shuffle(order, NUM_ENT); for(i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(0 == spdylay_map_remove(&map, order[i])); + CU_ASSERT(0 == nghttp2_map_remove(&map, order[i])); } /* each_free (but no op function for testing purpose) */ @@ -146,35 +146,35 @@ void test_spdylay_map_functional(void) } /* insert once again */ for(i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(0 == spdylay_map_insert(&map, &arr[i].map_entry)); + CU_ASSERT(0 == nghttp2_map_insert(&map, &arr[i].map_entry)); } - spdylay_map_each_free(&map, eachfun, NULL); + nghttp2_map_each_free(&map, eachfun, NULL); } -static int entry_free(spdylay_map_entry *entry, void *ptr) +static int entry_free(nghttp2_map_entry *entry, void *ptr) { free(entry); return 0; } -void test_spdylay_map_each_free(void) +void test_nghttp2_map_each_free(void) { strentry *foo = malloc(sizeof(strentry)), *bar = malloc(sizeof(strentry)), *baz = malloc(sizeof(strentry)), *shrubbery = malloc(sizeof(strentry)); - spdylay_map map; - spdylay_map_init(&map); + nghttp2_map map; + nghttp2_map_init(&map); strentry_init(foo, 1, "foo"); strentry_init(bar, 2, "bar"); strentry_init(baz, 3, "baz"); strentry_init(shrubbery, 4, "shrubbery"); - spdylay_map_insert(&map, &foo->map_entry); - spdylay_map_insert(&map, &bar->map_entry); - spdylay_map_insert(&map, &baz->map_entry); - spdylay_map_insert(&map, &shrubbery->map_entry); + nghttp2_map_insert(&map, &foo->map_entry); + nghttp2_map_insert(&map, &bar->map_entry); + nghttp2_map_insert(&map, &baz->map_entry); + nghttp2_map_insert(&map, &shrubbery->map_entry); - spdylay_map_each_free(&map, entry_free, NULL); + nghttp2_map_each_free(&map, entry_free, NULL); } diff --git a/tests/nghttp2_map_test.h b/tests/nghttp2_map_test.h new file mode 100644 index 00000000..8ac3fa35 --- /dev/null +++ b/tests/nghttp2_map_test.h @@ -0,0 +1,32 @@ +/* + * 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. + */ +#ifndef NGHTTP2_MAP_TEST_H +#define NGHTTP2_MAP_TEST_H + +void test_nghttp2_map(void); +void test_nghttp2_map_functional(void); +void test_nghttp2_map_each_free(void); + +#endif /* NGHTTP2_MAP_TEST_H */ diff --git a/tests/spdylay_npn_test.c b/tests/nghttp2_npn_test.c similarity index 81% rename from tests/spdylay_npn_test.c rename to tests/nghttp2_npn_test.c index a1de3d4c..29ddc217 100644 --- a/tests/spdylay_npn_test.c +++ b/tests/nghttp2_npn_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Twist Inc. * @@ -22,10 +22,10 @@ * 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_npn_test.h" +#include "nghttp2_npn_test.h" #include -#include +#include #include static void spdy2(void) @@ -37,8 +37,8 @@ static void spdy2(void) }; unsigned char outlen; unsigned char* out; - CU_ASSERT(SPDYLAY_PROTO_SPDY2 == - spdylay_select_next_protocol(&out, &outlen, spdy, sizeof(spdy))); + CU_ASSERT(NGHTTP2_PROTO_SPDY2 == + nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy))); CU_ASSERT(6 == outlen); CU_ASSERT(memcmp("spdy/2", out, outlen) == 0); } @@ -52,7 +52,7 @@ static void http11(void) }; unsigned char outlen; unsigned char* out; - CU_ASSERT(0 == spdylay_select_next_protocol(&out, &outlen, + CU_ASSERT(0 == nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy))); CU_ASSERT(8 == outlen); CU_ASSERT(memcmp("http/1.1", out, outlen) == 0); @@ -67,29 +67,29 @@ static void no_overlap(void) }; unsigned char outlen = 0; unsigned char* out = NULL; - CU_ASSERT(-1 == spdylay_select_next_protocol(&out, &outlen, + CU_ASSERT(-1 == nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy))); CU_ASSERT(0 == outlen); CU_ASSERT(NULL == out); } -void test_spdylay_npn(void) +void test_nghttp2_npn(void) { spdy2(); http11(); no_overlap(); } -void test_spdylay_npn_get_proto_list(void) +void test_nghttp2_npn_get_proto_list(void) { size_t len; - const spdylay_npn_proto *list = spdylay_npn_get_proto_list(&len); + const nghttp2_npn_proto *list = nghttp2_npn_get_proto_list(&len); CU_ASSERT_EQUAL(2, len); CU_ASSERT_STRING_EQUAL("spdy/3", list[0].proto); CU_ASSERT_EQUAL(6, list[0].len); - CU_ASSERT_EQUAL(SPDYLAY_PROTO_SPDY3, list[0].version); + CU_ASSERT_EQUAL(NGHTTP2_PROTO_SPDY3, list[0].version); CU_ASSERT_STRING_EQUAL("spdy/2", list[1].proto); CU_ASSERT_EQUAL(6, list[1].len); - CU_ASSERT_EQUAL(SPDYLAY_PROTO_SPDY2, list[1].version); + CU_ASSERT_EQUAL(NGHTTP2_PROTO_SPDY2, list[1].version); } diff --git a/tests/spdylay_npn_test.h b/tests/nghttp2_npn_test.h similarity index 85% rename from tests/spdylay_npn_test.h rename to tests/nghttp2_npn_test.h index f034e01d..1061b7ce 100644 --- a/tests/spdylay_npn_test.h +++ b/tests/nghttp2_npn_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Twist Inc. * @@ -22,10 +22,10 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_NPN_TEST_H -#define SPDYLAY_NPN_TEST_H +#ifndef NGHTTP2_NPN_TEST_H +#define NGHTTP2_NPN_TEST_H -void test_spdylay_npn(void); -void test_spdylay_npn_get_proto_list(void); +void test_nghttp2_npn(void); +void test_nghttp2_npn_get_proto_list(void); -#endif /* SPDYLAY_NPN_TEST_H */ +#endif /* NGHTTP2_NPN_TEST_H */ diff --git a/tests/nghttp2_pq_test.c b/tests/nghttp2_pq_test.c new file mode 100644 index 00000000..c03e3a0a --- /dev/null +++ b/tests/nghttp2_pq_test.c @@ -0,0 +1,79 @@ +/* + * 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_pq_test.h" + +#include + +#include "nghttp2_pq.h" + +static int pq_compar(const void *lhs, const void *rhs) +{ + return strcmp(lhs, rhs); +} + +void test_nghttp2_pq(void) +{ + int i; + nghttp2_pq pq; + nghttp2_pq_init(&pq, pq_compar); + CU_ASSERT(nghttp2_pq_empty(&pq)); + CU_ASSERT(0 == nghttp2_pq_size(&pq)); + CU_ASSERT(0 == nghttp2_pq_push(&pq, (void*)"foo")); + CU_ASSERT(0 == nghttp2_pq_empty(&pq)); + CU_ASSERT(1 == nghttp2_pq_size(&pq)); + CU_ASSERT(strcmp("foo", nghttp2_pq_top(&pq)) == 0); + CU_ASSERT(0 == nghttp2_pq_push(&pq, (void*)"bar")); + CU_ASSERT(strcmp("bar", nghttp2_pq_top(&pq)) == 0); + CU_ASSERT(0 == nghttp2_pq_push(&pq, (void*)"baz")); + CU_ASSERT(strcmp("bar", nghttp2_pq_top(&pq)) == 0); + CU_ASSERT(0 == nghttp2_pq_push(&pq, (void*)"C")); + CU_ASSERT(4 == nghttp2_pq_size(&pq)); + CU_ASSERT(strcmp("C", nghttp2_pq_top(&pq)) == 0); + nghttp2_pq_pop(&pq); + CU_ASSERT(3 == nghttp2_pq_size(&pq)); + CU_ASSERT(strcmp("bar", nghttp2_pq_top(&pq)) == 0); + nghttp2_pq_pop(&pq); + CU_ASSERT(strcmp("baz", nghttp2_pq_top(&pq)) == 0); + nghttp2_pq_pop(&pq); + CU_ASSERT(strcmp("foo", nghttp2_pq_top(&pq)) == 0); + nghttp2_pq_pop(&pq); + CU_ASSERT(nghttp2_pq_empty(&pq)); + CU_ASSERT(0 == nghttp2_pq_size(&pq)); + CU_ASSERT(NULL == nghttp2_pq_top(&pq)); + + /* Add bunch of entry to see realloc works */ + for(i = 0; i < 10000; ++i) { + CU_ASSERT(0 == nghttp2_pq_push(&pq, (void*)"foo")); + CU_ASSERT((size_t)(i+1) == nghttp2_pq_size(&pq)); + } + for(i = 10000; i > 0; --i) { + CU_ASSERT(NULL != nghttp2_pq_top(&pq)); + nghttp2_pq_pop(&pq); + CU_ASSERT((size_t)(i-1) == nghttp2_pq_size(&pq)); + } + + nghttp2_pq_free(&pq); +} + diff --git a/tests/spdylay_pq_test.h b/tests/nghttp2_pq_test.h similarity index 88% rename from tests/spdylay_pq_test.h rename to tests/nghttp2_pq_test.h index 94b3a106..bd5cfc43 100644 --- a/tests/spdylay_pq_test.h +++ b/tests/nghttp2_pq_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,9 +22,9 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_PQ_TEST_H -#define SPDYLAY_PQ_TEST_H +#ifndef NGHTTP2_PQ_TEST_H +#define NGHTTP2_PQ_TEST_H -void test_spdylay_pq(void); +void test_nghttp2_pq(void); -#endif /* SPDYLAY_PQ_TEST_H */ +#endif /* NGHTTP2_PQ_TEST_H */ diff --git a/tests/spdylay_queue_test.c b/tests/nghttp2_queue_test.c similarity index 70% rename from tests/spdylay_queue_test.c rename to tests/nghttp2_queue_test.c index 772357aa..4b2ad799 100644 --- a/tests/spdylay_queue_test.c +++ b/tests/nghttp2_queue_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,28 +22,28 @@ * 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_queue_test.h" +#include "nghttp2_queue_test.h" #include -#include "spdylay_queue.h" +#include "nghttp2_queue.h" -void test_spdylay_queue(void) +void test_nghttp2_queue(void) { int ints[] = { 1, 2, 3, 4, 5 }; int i; - spdylay_queue queue; - spdylay_queue_init(&queue); - CU_ASSERT(spdylay_queue_empty(&queue)); + nghttp2_queue queue; + nghttp2_queue_init(&queue); + CU_ASSERT(nghttp2_queue_empty(&queue)); for(i = 0; i < 5; ++i) { - spdylay_queue_push(&queue, &ints[i]); - CU_ASSERT_EQUAL(ints[0], *(int*)(spdylay_queue_front(&queue))); - CU_ASSERT(!spdylay_queue_empty(&queue)); + nghttp2_queue_push(&queue, &ints[i]); + CU_ASSERT_EQUAL(ints[0], *(int*)(nghttp2_queue_front(&queue))); + CU_ASSERT(!nghttp2_queue_empty(&queue)); } for(i = 0; i < 5; ++i) { - CU_ASSERT_EQUAL(ints[i], *(int*)(spdylay_queue_front(&queue))); - spdylay_queue_pop(&queue); + CU_ASSERT_EQUAL(ints[i], *(int*)(nghttp2_queue_front(&queue))); + nghttp2_queue_pop(&queue); } - CU_ASSERT(spdylay_queue_empty(&queue)); - spdylay_queue_free(&queue); + CU_ASSERT(nghttp2_queue_empty(&queue)); + nghttp2_queue_free(&queue); } diff --git a/tests/spdylay_queue_test.h b/tests/nghttp2_queue_test.h similarity index 87% rename from tests/spdylay_queue_test.h rename to tests/nghttp2_queue_test.h index 05a61c2b..88ec2a69 100644 --- a/tests/spdylay_queue_test.h +++ b/tests/nghttp2_queue_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,9 +22,9 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_QUEUE_TEST_H -#define SPDYLAY_QUEUE_TEST_H +#ifndef NGHTTP2_QUEUE_TEST_H +#define NGHTTP2_QUEUE_TEST_H -void test_spdylay_queue(void); +void test_nghttp2_queue(void); -#endif /* SPDYLAY_QUEUE_TEST_H */ +#endif /* NGHTTP2_QUEUE_TEST_H */ diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c new file mode 100644 index 00000000..2de432c8 --- /dev/null +++ b/tests/nghttp2_session_test.c @@ -0,0 +1,2688 @@ +/* + * 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_session_test.h" + +#include + +#include +#include + +#include "nghttp2_session.h" +#include "nghttp2_stream.h" +#include "nghttp2_net.h" +#include "nghttp2_helper.h" +#include "nghttp2_test_helper.h" + +#define OB_CTRL(ITEM) nghttp2_outbound_item_get_ctrl_frame(ITEM) +#define OB_CTRL_TYPE(ITEM) nghttp2_outbound_item_get_ctrl_frame_type(ITEM) +#define OB_DATA(ITEM) nghttp2_outbound_item_get_data_frame(ITEM) + +typedef struct { + uint8_t buf[4096]; + size_t length; +} accumulator; + +typedef struct { + uint8_t data[8192]; + uint8_t* datamark; + uint8_t* datalimit; + size_t feedseq[8192]; + size_t seqidx; +} scripted_data_feed; + +typedef struct { + accumulator *acc; + scripted_data_feed *df; + int ctrl_recv_cb_called, invalid_ctrl_recv_cb_called; + int ctrl_send_cb_called; + nghttp2_frame_type sent_frame_type; + int ctrl_not_send_cb_called; + nghttp2_frame_type not_sent_frame_type; + int not_sent_error; + int stream_close_cb_called; + size_t data_source_length; + int32_t stream_id; + size_t block_count; + int data_chunk_recv_cb_called; + int data_recv_cb_called; +} my_user_data; + +static void scripted_data_feed_init(scripted_data_feed *df, + uint8_t *data, size_t data_length) +{ + memset(df, 0, sizeof(scripted_data_feed)); + memcpy(df->data, data, data_length); + df->datamark = df->data; + df->datalimit = df->data+data_length; + df->feedseq[0] = data_length; +} + +static ssize_t null_send_callback(nghttp2_session *session, + const uint8_t* data, size_t len, int flags, + void *user_data) +{ + return len; +} + +static ssize_t fail_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, int flags, + void *user_data) +{ + return NGHTTP2_ERR_CALLBACK_FAILURE; +} + +static ssize_t scripted_recv_callback(nghttp2_session *session, + uint8_t* data, size_t len, int flags, + void *user_data) +{ + scripted_data_feed *df = ((my_user_data*)user_data)->df; + size_t wlen = df->feedseq[df->seqidx] > len ? len : df->feedseq[df->seqidx]; + memcpy(data, df->datamark, wlen); + df->datamark += wlen; + if(wlen <= len) { + ++df->seqidx; + } else { + df->feedseq[df->seqidx] -= wlen; + } + return wlen; +} + +static ssize_t eof_recv_callback(nghttp2_session *session, + uint8_t* data, size_t len, int flags, + void *user_data) +{ + return NGHTTP2_ERR_EOF; +} + +static ssize_t accumulator_send_callback(nghttp2_session *session, + const uint8_t *buf, size_t len, + int flags, void* user_data) +{ + accumulator *acc = ((my_user_data*)user_data)->acc; + assert(acc->length+len < sizeof(acc->buf)); + memcpy(acc->buf+acc->length, buf, len); + acc->length += len; + return len; +} + +static void on_ctrl_recv_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ++ud->ctrl_recv_cb_called; +} + +static void on_invalid_ctrl_recv_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, + uint32_t status_code, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ++ud->invalid_ctrl_recv_cb_called; +} + +static void on_ctrl_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ++ud->ctrl_send_cb_called; + ud->sent_frame_type = type; +} + +static void on_ctrl_not_send_callback(nghttp2_session *session, + nghttp2_frame_type type, + nghttp2_frame *frame, + int error, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ++ud->ctrl_not_send_cb_called; + ud->not_sent_frame_type = type; + ud->not_sent_error = error; +} + +static void on_data_chunk_recv_callback(nghttp2_session *session, + uint8_t flags, int32_t stream_id, + const uint8_t *data, size_t len, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ++ud->data_chunk_recv_cb_called; +} + +static void on_data_recv_callback(nghttp2_session *session, + uint8_t flags, int32_t stream_id, + int32_t length, void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ++ud->data_recv_cb_called; +} + +static ssize_t fixed_length_data_source_read_callback +(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, int *eof, + nghttp2_data_source *source, void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + size_t wlen; + if(len < ud->data_source_length) { + wlen = len; + } else { + wlen = ud->data_source_length; + } + ud->data_source_length -= wlen; + if(ud->data_source_length == 0) { + *eof = 1; + } + return wlen; +} + +static ssize_t temporal_failure_data_source_read_callback +(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, int *eof, + nghttp2_data_source *source, void *user_data) +{ + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; +} + +static ssize_t fail_data_source_read_callback +(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, int *eof, + nghttp2_data_source *source, void *user_data) +{ + return NGHTTP2_ERR_CALLBACK_FAILURE; +} + +static void on_request_recv_callback(nghttp2_session *session, + int32_t stream_id, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + ud->stream_id = stream_id; +} + +static void no_stream_user_data_stream_close_callback +(nghttp2_session *session, + int32_t stream_id, + nghttp2_status_code status_code, + void *user_data) +{ + my_user_data* my_data = (my_user_data*)user_data; + ++my_data->stream_close_cb_called; +} + +static char** dup_nv(const char **src) +{ + return nghttp2_frame_nv_copy(src); +} + +static nghttp2_settings_entry* dup_iv(const nghttp2_settings_entry *iv, + size_t niv) +{ + return nghttp2_frame_iv_copy(iv, niv); +} + +static const char *empty_name_nv[] = { "Version", "HTTP/1.1", + "", "empty name", + NULL }; + +static const char *null_val_nv[] = { "Version", "HTTP/1.1", + "Foo", NULL, + NULL }; + +void test_nghttp2_session_recv(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + scripted_data_feed df; + my_user_data user_data; + const char *nv[] = { + "url", "/", NULL + }; + const char *upcase_nv[] = { + "URL", "/", NULL + }; + const char *mid_nv[] = { + "method", "GET", + "scheme", "https", + "url", "/", + "x-head", "foo", + "x-head", "bar", + "version", "HTTP/1.1", + "x-empty", "", + NULL + }; + uint8_t *framedata = NULL, *nvbuf = NULL; + size_t framedatalen = 0, nvbuflen = 0; + ssize_t framelen; + nghttp2_frame frame; + int i; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.recv_callback = scripted_recv_callback; + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + user_data.df = &df; + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, + 1, 0, 3, dup_nv(nv)); + framelen = nghttp2_frame_pack_syn_stream(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_stream, + &session->hd_deflater); + scripted_data_feed_init(&df, framedata, framelen); + /* Send 1 byte per each read */ + for(i = 0; i < framelen; ++i) { + df.feedseq[i] = 1; + } + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + user_data.ctrl_recv_cb_called = 0; + while((ssize_t)df.seqidx < framelen) { + CU_ASSERT(0 == nghttp2_session_recv(session)); + } + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + + /* Receive SYN_STREAM with invalid header block */ + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, + 3, 0, 3, dup_nv(upcase_nv)); + framelen = nghttp2_frame_pack_syn_stream(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_stream, + &session->hd_deflater); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + scripted_data_feed_init(&df, framedata, framelen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.status_code); + CU_ASSERT(0 == nghttp2_session_send(session)); + + /* Received SYN_STREAM without name/value header block */ + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, + 5, 0, 3, dup_nv(upcase_nv)); + framelen = nghttp2_frame_pack_syn_stream(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_stream, + &session->hd_deflater); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + /* Use bytes that come before name/value header block */ + nghttp2_put_uint32be(&framedata[4], + NGHTTP2_SYN_STREAM_NV_OFFSET - NGHTTP2_HEAD_LEN); + scripted_data_feed_init(&df, framedata, NGHTTP2_SYN_STREAM_NV_OFFSET); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_GOAWAY == OB_CTRL_TYPE(item)); + + nghttp2_session_del(session); + + /* Some tests for frame too large */ + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, + &user_data); + /* made max buffer small to cause error intentionally */ + /* Inflated wire format of mid_nv will be 111 in SPDY/3. So payload + length will be 121. Setting max buffer size to 110 will cause + error while inflating name/value header block. */ + session->max_recv_ctrl_frame_buf = 110; + + /* Receive SYN_STREAM with too large payload */ + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_NONE, + 1, 0, 3, dup_nv(mid_nv)); + framelen = nghttp2_frame_pack_syn_stream(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_stream, + &session->hd_deflater); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + scripted_data_feed_init(&df, framedata, framelen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.status_code); + CU_ASSERT(1 == OB_CTRL(item)->rst_stream.stream_id); + CU_ASSERT(0 == nghttp2_session_send(session)); + + /* For SYN_REPLY and SYN_HEADERS, make max buffer even smaller */ + session->max_recv_ctrl_frame_buf = 8; + + /* Receive SYN_REPLY with too large payload */ + nghttp2_frame_syn_reply_init(&frame.syn_reply, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_NONE, + 1, dup_nv(mid_nv)); + framelen = nghttp2_frame_pack_syn_reply(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_reply, + &session->hd_deflater); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + scripted_data_feed_init(&df, framedata, framelen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.status_code); + CU_ASSERT(1 == OB_CTRL(item)->rst_stream.stream_id); + CU_ASSERT(0 == nghttp2_session_send(session)); + + /* Receive HEADERS with too large payload */ + nghttp2_frame_headers_init(&frame.headers, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_NONE, + 1, dup_nv(mid_nv)); + framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.headers, + &session->hd_deflater); + nghttp2_frame_headers_free(&frame.headers); + scripted_data_feed_init(&df, framedata, framelen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.status_code); + CU_ASSERT(1 == OB_CTRL(item)->rst_stream.stream_id); + CU_ASSERT(0 == nghttp2_session_send(session)); + + /* Receive PING with too large payload */ + nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY3, 1); + nghttp2_reserve_buffer(&framedata, &framedatalen, 77); + framelen = nghttp2_frame_pack_ping(&framedata, &framedatalen, &frame.ping); + nghttp2_frame_ping_free(&frame.ping); + nghttp2_put_uint32be(&framedata[4], framedatalen - NGHTTP2_HEAD_LEN); + scripted_data_feed_init(&df, framedata, framedatalen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_GOAWAY == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_GOAWAY_PROTOCOL_ERROR == + OB_CTRL(item)->rst_stream.status_code); + CU_ASSERT(0 == nghttp2_session_send(session)); + + nghttp2_session_del(session); + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + /* Receive SYN_REPLY with invalid header block */ + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_frame_syn_reply_init(&frame.syn_reply, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 1, dup_nv(upcase_nv)); + framelen = nghttp2_frame_pack_syn_reply(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_reply, + &session->hd_deflater); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + scripted_data_feed_init(&df, framedata, framelen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.status_code); + + CU_ASSERT(0 == nghttp2_session_send(session)); + + /* Receive HEADERS with invalid header block */ + nghttp2_session_open_stream(session, 3, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENED, NULL); + nghttp2_frame_headers_init(&frame.headers, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 3, dup_nv(upcase_nv)); + framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.headers, + &session->hd_deflater); + nghttp2_frame_headers_free(&frame.headers); + scripted_data_feed_init(&df, framedata, framelen); + user_data.ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == user_data.ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.status_code); + + free(framedata); + free(nvbuf); + nghttp2_session_del(session); +} + +void test_nghttp2_session_add_frame(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + accumulator acc; + my_user_data user_data; + const char *nv[] = { + "method", "GET", + "scheme", "https", + "url", "/", + "version", "HTTP/1.1", + NULL + }; + nghttp2_frame *frame; + nghttp2_syn_stream_aux_data *aux_data = + malloc(sizeof(nghttp2_syn_stream_aux_data)); + const uint8_t hd_ans1[] = { + 0x80, 0x02, 0x00, 0x01 + }; + uint32_t temp32; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = accumulator_send_callback; + memset(aux_data, 0, sizeof(nghttp2_syn_stream_aux_data)); + acc.length = 0; + user_data.acc = &acc; + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &user_data)); + + frame = malloc(sizeof(nghttp2_frame)); + nghttp2_frame_syn_stream_init(&frame->syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 0, 0, 3, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, + aux_data)); + CU_ASSERT(0 == nghttp2_pq_empty(&session->ob_ss_pq)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(memcmp(hd_ans1, acc.buf, 4) == 0); + /* check stream id */ + memcpy(&temp32, &acc.buf[8], 4); + temp32 = ntohl(temp32); + CU_ASSERT(1 == temp32); + /* check assoc stream id */ + memcpy(&temp32, &acc.buf[12], 4); + temp32 = ntohl(temp32); + CU_ASSERT(0 == temp32); + /* check pri */ + temp32 = (acc.buf[16] >> 6) & 0x3; + CU_ASSERT(3 == temp32); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_recv_invalid_stream_id(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + scripted_data_feed df; + my_user_data user_data; + const char *nv[] = { NULL }; + uint8_t *framedata = NULL, *nvbuf = NULL; + size_t framedatalen = 0, nvbuflen = 0; + ssize_t framelen; + nghttp2_frame frame; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.recv_callback = scripted_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + + user_data.df = &df; + user_data.invalid_ctrl_recv_cb_called = 0; + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 1, 0, 3, dup_nv(nv)); + framelen = nghttp2_frame_pack_syn_stream(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_stream, + &session->hd_deflater); + scripted_data_feed_init(&df, framedata, framelen); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + + nghttp2_frame_syn_reply_init(&frame.syn_reply, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 100, dup_nv(nv)); + framelen = nghttp2_frame_pack_syn_reply(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_reply, + &session->hd_deflater); + scripted_data_feed_init(&df, framedata, framelen); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); + + free(framedata); + free(nvbuf); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_syn_stream_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + const char *nv[] = { NULL }; + nghttp2_frame frame; + nghttp2_stream *stream; + int32_t stream_id = 1; + uint8_t pri = 3; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, + stream_id, 0, pri, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + stream = nghttp2_session_get_stream(session, stream_id); + CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + CU_ASSERT(pri == stream->pri); + + /* Same stream ID twice leads stream error */ + user_data.invalid_ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + CU_ASSERT(NGHTTP2_STREAM_CLOSING == stream->state); + + /* assoc_stream_id != 0 from client is invalid. */ + frame.syn_stream.stream_id = 3; + frame.syn_stream.assoc_stream_id = 1; + user_data.invalid_ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + + /* More than max concurrent streams leads REFUSED_STREAM */ + session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, + 5, 0, 3, dup_nv(nv)); + user_data.invalid_ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = + NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS; + + /* Stream ID less than previouly received SYN_STREAM leads session + error */ + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, + 1, 0, 3, dup_nv(nv)); + user_data.invalid_ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_FAIL_ON_SEND); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_syn_stream_received_with_push(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + const char *nv[] = { NULL }; + nghttp2_frame frame; + nghttp2_stream *stream; + int32_t stream_id = 2; + int32_t assoc_stream_id = 1; + uint8_t pri = 3; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_session_open_stream(session, assoc_stream_id, NGHTTP2_CTRL_FLAG_NONE, + pri, NGHTTP2_STREAM_OPENED, NULL); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL, + stream_id, assoc_stream_id, pri, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + stream = nghttp2_session_get_stream(session, stream_id); + CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + + /* assoc_stream_id == 0 is invalid */ + frame.syn_stream.stream_id = 4; + frame.syn_stream.assoc_stream_id = 0; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + + /* Push without NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL is invalid */ + frame.syn_stream.stream_id = 6; + frame.syn_stream.assoc_stream_id = 1; + frame.syn_stream.hd.flags = NGHTTP2_CTRL_FLAG_FIN; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); + + /* Push to non-existent stream is invalid */ + frame.syn_stream.stream_id = 8; + frame.syn_stream.assoc_stream_id = 3; + frame.syn_stream.hd.flags = NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL; + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(3 == user_data.invalid_ctrl_recv_cb_called); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_syn_reply_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + const char *nv[] = { NULL }; + nghttp2_frame frame; + nghttp2_stream *stream; + nghttp2_outbound_item *item; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_frame_syn_reply_init(&frame.syn_reply, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 1, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_on_syn_reply_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + CU_ASSERT(NGHTTP2_STREAM_OPENED == + ((nghttp2_stream*)nghttp2_map_find(&session->streams, 1))->state); + + CU_ASSERT(0 == nghttp2_session_on_syn_reply_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + CU_ASSERT(NGHTTP2_STREAM_CLOSING == + ((nghttp2_stream*)nghttp2_map_find(&session->streams, 1))->state); + + /* Check the situation when SYN_REPLY is received after peer sends + FIN */ + stream = nghttp2_session_open_stream(session, 3, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENED, NULL); + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); + frame.syn_reply.stream_id = 3; + + CU_ASSERT(0 == nghttp2_session_on_syn_reply_received(session, &frame)); + CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); + + nghttp2_frame_syn_reply_free(&frame.syn_reply); + + nghttp2_session_del(session); + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, + &user_data); + + /* Multiple SYN_REPLY frames for the same active stream ID */ + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENED, NULL); + nghttp2_frame_syn_reply_init(&frame.syn_reply, NGHTTP2_PROTO_SPDY3, + NGHTTP2_CTRL_FLAG_NONE, 1, dup_nv(nv)); + user_data.invalid_ctrl_recv_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_on_syn_reply_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_STREAM_IN_USE == OB_CTRL(item)->rst_stream.status_code); + + nghttp2_frame_syn_reply_free(&frame.syn_reply); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_send_syn_stream(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); + nghttp2_stream *stream; + nghttp2_syn_stream_aux_data *aux_data = + malloc(sizeof(nghttp2_syn_stream_aux_data)); + memset(aux_data, 0, sizeof(nghttp2_syn_stream_aux_data)); + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, NULL); + nghttp2_frame_syn_stream_init(&frame->syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 0, 0, 3, dup_nv(nv)); + nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, aux_data); + CU_ASSERT(0 == nghttp2_session_send(session)); + stream = nghttp2_session_get_stream(session, 1); + CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_send_syn_reply(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, NULL)); + nghttp2_session_open_stream(session, 2, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_frame_syn_reply_init(&frame->syn_reply, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 2, dup_nv(nv)); + nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); + CU_ASSERT(0 == nghttp2_session_send(session)); + stream = nghttp2_session_get_stream(session, 2); + CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_response(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { "Content-Length", "1024", NULL }; + int32_t stream_id = 2; + nghttp2_data_provider data_prd; + my_user_data ud; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + data_prd.read_callback = fixed_length_data_source_read_callback; + ud.data_source_length = 64*1024; + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + nghttp2_session_open_stream(session, stream_id, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + CU_ASSERT(0 == nghttp2_submit_response(session, stream_id, nv, &data_prd)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("content-length", OB_CTRL(item)->syn_reply.nv[0])); + CU_ASSERT(0 == nghttp2_session_send(session)); + nghttp2_session_del(session); +} + +void test_nghttp2_submit_response_with_null_data_read_callback(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + accumulator acc; + const char *nv[] = { ":Version", "HTTP/1.1", NULL }; + nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_outbound_item *item; + my_user_data ud; + nghttp2_frame frame; + + acc.length = 0; + ud.acc = &acc; + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.send_callback = accumulator_send_callback; + CU_ASSERT(0 == nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_FIN, 3, + NGHTTP2_STREAM_OPENING, NULL); + CU_ASSERT(0 == nghttp2_submit_response(session, 1, nv, &data_prd)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->syn_reply.nv[0])); + CU_ASSERT(OB_CTRL(item)->syn_reply.hd.flags & NGHTTP2_CTRL_FLAG_FIN); + + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == unpack_frame_with_nv_block(NGHTTP2_SYN_REPLY, + NGHTTP2_PROTO_SPDY2, + &frame, + &session->hd_inflater, + acc.buf, acc.length)); + CU_ASSERT(0 == strcmp("version", frame.syn_reply.nv[0])); + nghttp2_frame_syn_reply_free(&frame.syn_reply); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_request_with_data(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { "Version", "HTTP/1.1", NULL }; + nghttp2_data_provider data_prd; + my_user_data ud; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + data_prd.read_callback = fixed_length_data_source_read_callback; + ud.data_source_length = 64*1024; + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + CU_ASSERT(0 == nghttp2_submit_request(session, 3, nv, &data_prd, NULL)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_stream.nv[0])); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == ud.data_source_length); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_request_with_null_data_read_callback(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + accumulator acc; + const char *nv[] = { ":Version", "HTTP/1.1", NULL }; + nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_outbound_item *item; + my_user_data ud; + nghttp2_frame frame; + + acc.length = 0; + ud.acc = &acc; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = accumulator_send_callback; + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + CU_ASSERT(0 == nghttp2_submit_request(session, 3, nv, &data_prd, NULL)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->syn_stream.nv[0])); + CU_ASSERT(OB_CTRL(item)->syn_stream.hd.flags & NGHTTP2_CTRL_FLAG_FIN); + + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == unpack_frame_with_nv_block(NGHTTP2_SYN_STREAM, + NGHTTP2_PROTO_SPDY2, + &frame, + &session->hd_inflater, + acc.buf, acc.length)); + CU_ASSERT(0 == strcmp("version", frame.syn_stream.nv[0])); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_syn_stream(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { "version", "HTTP/1.1", NULL }; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, NULL)); + CU_ASSERT(0 == nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_FIN, 1, 3, + nv, NULL)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_stream.nv[0])); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == OB_CTRL(item)->syn_stream.hd.flags); + /* See assoc-stream-ID is ignored */ + CU_ASSERT(0 == OB_CTRL(item)->syn_stream.assoc_stream_id); + CU_ASSERT(3 == OB_CTRL(item)->syn_stream.pri); + + nghttp2_session_del(session); + + CU_ASSERT(0 == nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, NULL)); + CU_ASSERT(0 == nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_FIN, 1, 3, + nv, NULL)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_stream.nv[0])); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == OB_CTRL(item)->syn_stream.hd.flags); + CU_ASSERT(1 == OB_CTRL(item)->syn_stream.assoc_stream_id); + CU_ASSERT(3 == OB_CTRL(item)->syn_stream.pri); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_syn_reply(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { "version", "HTTP/1.1", NULL }; + my_user_data ud; + nghttp2_outbound_item *item; + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + + CU_ASSERT(0 == nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + CU_ASSERT(0 == nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_FIN, 1, + nv)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_reply.nv[0])); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == OB_CTRL(item)->syn_reply.hd.flags); + + ud.ctrl_send_cb_called = 0; + ud.sent_frame_type = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == ud.ctrl_send_cb_called); + + stream = nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + + CU_ASSERT(0 == nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_FIN, 1, + nv)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == ud.ctrl_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_REPLY == ud.sent_frame_type); + CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_headers(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { ":Version", "HTTP/1.1", NULL }; + my_user_data ud; + nghttp2_outbound_item *item; + nghttp2_stream *stream; + accumulator acc; + nghttp2_frame frame; + + acc.length = 0; + ud.acc = &acc; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = accumulator_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_FIN, 1, nv)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0])); + CU_ASSERT(NGHTTP2_CTRL_FLAG_FIN == OB_CTRL(item)->headers.hd.flags); + + ud.ctrl_send_cb_called = 0; + ud.sent_frame_type = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == ud.ctrl_send_cb_called); + + stream = nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + + CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_FIN, 1, nv)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == ud.ctrl_send_cb_called); + CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); + CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + + CU_ASSERT(0 == unpack_frame_with_nv_block(NGHTTP2_HEADERS, + NGHTTP2_PROTO_SPDY2, + &frame, + &session->hd_inflater, + acc.buf, acc.length)); + CU_ASSERT(0 == strcmp("version", frame.headers.nv[0])); + nghttp2_frame_headers_free(&frame.headers); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_invalid_nv(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, + &callbacks, NULL)); + + /* nghttp2_submit_request */ + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_request(session, 3, empty_name_nv, NULL, NULL)); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_request(session, 3, null_val_nv, NULL, NULL)); + + /* nghttp2_submit_response */ + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_response(session, 2, empty_name_nv, NULL)); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_response(session, 2, null_val_nv, NULL)); + + /* nghttp2_submit_syn_stream */ + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_NONE, 0, + 0, empty_name_nv, NULL)); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_NONE, 0, + 0, null_val_nv, NULL)); + + /* nghttp2_submit_syn_reply */ + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_NONE, 2, + empty_name_nv)); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_NONE, 2, + null_val_nv)); + + /* nghttp2_submit_headers */ + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_NONE, 2, + empty_name_nv)); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_NONE, 2, + null_val_nv)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_reply_fail(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + int32_t stream_id = 2; + nghttp2_data_provider data_prd; + my_user_data ud; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = fail_send_callback; + + data_prd.read_callback = fixed_length_data_source_read_callback; + ud.data_source_length = 4*1024; + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &ud)); + CU_ASSERT(0 == nghttp2_submit_response(session, stream_id, nv, &data_prd)); + CU_ASSERT(0 == nghttp2_session_send(session)); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_headers_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + const char *nv[] = { NULL }; + nghttp2_frame frame; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENED, NULL); + nghttp2_stream_shutdown(nghttp2_session_get_stream(session, 1), + NGHTTP2_SHUT_WR); + nghttp2_frame_headers_init(&frame.headers, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 1, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + CU_ASSERT(NGHTTP2_STREAM_OPENED == + nghttp2_session_get_stream(session, 1)->state); + + frame.headers.hd.flags |= NGHTTP2_CTRL_FLAG_FIN; + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(2 == user_data.ctrl_recv_cb_called); + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + + /* Check to see when NGHTTP2_STREAM_CLOSING, incoming HEADERS is + discarded. */ + nghttp2_session_open_stream(session, 3, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_CLOSING, NULL); + frame.headers.stream_id = 3; + frame.headers.hd.flags = NGHTTP2_CTRL_FLAG_NONE; + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(2 == user_data.ctrl_recv_cb_called); + CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); + + /* Server initiated stream */ + nghttp2_session_open_stream(session, 2, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENING, NULL); + + frame.headers.hd.flags = NGHTTP2_CTRL_FLAG_FIN; + frame.headers.stream_id = 2; + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(3 == user_data.ctrl_recv_cb_called); + CU_ASSERT(NGHTTP2_STREAM_OPENING == + nghttp2_session_get_stream(session, 2)->state); + CU_ASSERT(nghttp2_session_get_stream(session, 2)->shut_flags & + NGHTTP2_SHUT_RD); + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); + + nghttp2_frame_headers_free(&frame.headers); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_window_update_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_frame frame; + nghttp2_stream *stream; + nghttp2_outbound_item *data_item; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, + &user_data); + stream = nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENED, NULL); + nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_PROTO_SPDY3, + 1, 16*1024); + + CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + CU_ASSERT(64*1024+16*1024 == stream->window_size); + + data_item = malloc(sizeof(nghttp2_outbound_item)); + memset(data_item, 0, sizeof(nghttp2_outbound_item)); + data_item->frame_cat = NGHTTP2_DATA; + nghttp2_stream_defer_data(stream, data_item, NGHTTP2_DEFERRED_FLOW_CONTROL); + + CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); + CU_ASSERT(2 == user_data.ctrl_recv_cb_called); + CU_ASSERT(64*1024+16*1024*2 == stream->window_size); + CU_ASSERT(NULL == stream->deferred_data); + + nghttp2_frame_window_update_free(&frame.window_update); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_ping_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_frame frame; + nghttp2_outbound_item *top; + uint32_t unique_id; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + unique_id = 2; + nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY2, unique_id); + + CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + top = nghttp2_session_get_ob_pq_top(session); + CU_ASSERT(NGHTTP2_PING == OB_CTRL_TYPE(top)); + CU_ASSERT(unique_id == OB_CTRL(top)->ping.unique_id); + + session->last_ping_unique_id = 1; + frame.ping.unique_id = 1; + + CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); + CU_ASSERT(2 == user_data.ctrl_recv_cb_called); + + nghttp2_frame_ping_free(&frame.ping); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_goaway_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_frame frame; + int32_t stream_id = 1000000007; + user_data.ctrl_recv_cb_called = 0; + user_data.invalid_ctrl_recv_cb_called = 0; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_frame_goaway_init(&frame.goaway, NGHTTP2_PROTO_SPDY2, stream_id, + NGHTTP2_GOAWAY_OK); + + CU_ASSERT(0 == nghttp2_session_on_goaway_received(session, &frame)); + CU_ASSERT(1 == user_data.ctrl_recv_cb_called); + CU_ASSERT(session->goaway_flags == NGHTTP2_GOAWAY_RECV); + + nghttp2_frame_goaway_free(&frame.goaway); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_data_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_outbound_item *top; + int32_t stream_id = 2; + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + stream = nghttp2_session_open_stream(session, stream_id, + NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + CU_ASSERT(0 == nghttp2_session_on_data_received(session, + NGHTTP2_DATA_FLAG_NONE, + 4096, stream_id)); + CU_ASSERT(0 == stream->shut_flags); + + CU_ASSERT(0 == nghttp2_session_on_data_received(session, + NGHTTP2_DATA_FLAG_FIN, + 4096, stream_id)); + CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); + + /* If NGHTTP2_STREAM_CLOSING state, DATA frame is discarded. */ + stream_id = 4; + + nghttp2_session_open_stream(session, stream_id, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_CLOSING, NULL); + CU_ASSERT(0 == nghttp2_session_on_data_received(session, + NGHTTP2_DATA_FLAG_NONE, + 4096, stream_id)); + CU_ASSERT(NULL == nghttp2_session_get_ob_pq_top(session)); + + /* Check INVALID_STREAM case: DATA frame with stream ID which does + not exist. */ + stream_id = 6; + + CU_ASSERT(0 == nghttp2_session_on_data_received(session, + NGHTTP2_DATA_FLAG_NONE, + 4096, stream_id)); + top = nghttp2_session_get_ob_pq_top(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(top)); + CU_ASSERT(NGHTTP2_INVALID_STREAM == OB_CTRL(top)->rst_stream.status_code); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_is_my_stream_id(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, NULL); + + CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 0)); + CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 1)); + CU_ASSERT(1 == nghttp2_session_is_my_stream_id(session, 2)); + + nghttp2_session_del(session); + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, NULL); + + CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 0)); + CU_ASSERT(1 == nghttp2_session_is_my_stream_id(session, 1)); + CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 2)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_rst_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_stream *stream; + nghttp2_frame frame; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + stream = nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + /* server push */ + nghttp2_session_open_stream(session, 2, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + nghttp2_stream_add_pushed_stream(stream, 2); + nghttp2_session_open_stream(session, 4, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + nghttp2_stream_add_pushed_stream(stream, 4); + + nghttp2_frame_rst_stream_init(&frame.rst_stream, NGHTTP2_PROTO_SPDY2, 1, + NGHTTP2_CANCEL); + + CU_ASSERT(0 == nghttp2_session_on_rst_stream_received(session, &frame)); + + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 2)); + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 4)); + + nghttp2_frame_rst_stream_free(&frame.rst_stream); + nghttp2_session_del(session); +} + +void test_nghttp2_session_send_rst_stream(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_stream *stream; + nghttp2_frame *frame; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + stream = nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + /* server push */ + nghttp2_session_open_stream(session, 2, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + nghttp2_stream_add_pushed_stream(stream, 2); + nghttp2_session_open_stream(session, 4, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + nghttp2_stream_add_pushed_stream(stream, 4); + + frame = malloc(sizeof(nghttp2_frame)); + nghttp2_frame_rst_stream_init(&frame->rst_stream, NGHTTP2_PROTO_SPDY2, 1, + NGHTTP2_CANCEL); + nghttp2_session_add_frame(session, NGHTTP2_CTRL, frame, NULL); + CU_ASSERT(0 == nghttp2_session_send(session)); + + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 2)); + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 4)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_get_next_ob_item(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, NULL); + session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 2; + + CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + nghttp2_submit_ping(session); + CU_ASSERT(NGHTTP2_PING == + OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); + + nghttp2_submit_request(session, 0, nv, NULL, NULL); + CU_ASSERT(NGHTTP2_PING == + OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); + + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + + /* Incoming stream does not affect the number of outgoing max + concurrent streams. */ + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + + nghttp2_submit_request(session, 0, nv, NULL, NULL); + CU_ASSERT(NGHTTP2_SYN_STREAM == + OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); + CU_ASSERT(0 == nghttp2_session_send(session)); + + nghttp2_submit_request(session, 0, nv, NULL, NULL); + CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + + session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 3; + + CU_ASSERT(NGHTTP2_SYN_STREAM == + OB_CTRL_TYPE(nghttp2_session_get_next_ob_item(session))); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_pop_next_ob_item(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + nghttp2_outbound_item *item; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, NULL); + session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; + + CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + nghttp2_submit_ping(session); + nghttp2_submit_request(session, 1, nv, NULL, NULL); + + item = nghttp2_session_pop_next_ob_item(session); + CU_ASSERT(NGHTTP2_PING == OB_CTRL_TYPE(item)); + nghttp2_outbound_item_free(item); + free(item); + + item = nghttp2_session_pop_next_ob_item(session); + CU_ASSERT(NGHTTP2_SYN_STREAM == OB_CTRL_TYPE(item)); + nghttp2_outbound_item_free(item); + free(item); + + CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + + /* Incoming stream does not affect the number of outgoing max + concurrent streams. */ + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + + /* In-flight outgoing stream */ + nghttp2_session_open_stream(session, 4, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + + nghttp2_submit_request(session, 0, nv, NULL, NULL); + nghttp2_submit_response(session, 1, nv, NULL); + + item = nghttp2_session_pop_next_ob_item(session); + CU_ASSERT(NGHTTP2_SYN_REPLY == OB_CTRL_TYPE(item)); + nghttp2_outbound_item_free(item); + free(item); + + CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + + session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 2; + + item = nghttp2_session_pop_next_ob_item(session); + CU_ASSERT(NGHTTP2_SYN_STREAM == OB_CTRL_TYPE(item)); + nghttp2_outbound_item_free(item); + free(item); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_request_recv_callback(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + const char *nv[] = { NULL }; + nghttp2_frame frame; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_request_recv_callback = on_request_recv_callback; + user_data.stream_id = 0; + + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 1, 0, 3, dup_nv(nv)); + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(0 == user_data.stream_id); + + frame.syn_stream.stream_id = 3; + frame.syn_stream.hd.flags |= NGHTTP2_CTRL_FLAG_FIN; + + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(3 == user_data.stream_id); + + user_data.stream_id = 0; + + frame.syn_stream.stream_id = 0; + + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + CU_ASSERT(0 == user_data.stream_id); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + user_data.stream_id = 0; + + nghttp2_session_open_stream(session, 5, NGHTTP2_CTRL_FLAG_NONE, 0, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_frame_headers_init(&frame.headers, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 5, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(0 == user_data.stream_id); + + frame.headers.hd.flags |= NGHTTP2_CTRL_FLAG_FIN; + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(5 == user_data.stream_id); + + user_data.stream_id = 0; + + CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame)); + CU_ASSERT(0 == user_data.stream_id); + + nghttp2_frame_headers_free(&frame.headers); + nghttp2_session_del(session); +} + +static void stream_close_callback(nghttp2_session *session, int32_t stream_id, + nghttp2_status_code status_code, + void *user_data) +{ + my_user_data* my_data = (my_user_data*)user_data; + void *stream_data = nghttp2_session_get_stream_user_data(session, stream_id); + ++my_data->stream_close_cb_called; + CU_ASSERT(stream_data != NULL); +} + +void test_nghttp2_session_on_stream_close(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_stream *stream; + int32_t stream_id = 1; + uint8_t pri = 3; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_stream_close_callback = stream_close_callback; + user_data.stream_close_cb_called = 0; + + CU_ASSERT(nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &user_data) == 0); + stream = nghttp2_session_open_stream(session, stream_id, + NGHTTP2_CTRL_FLAG_NONE, + pri, NGHTTP2_STREAM_OPENED, &user_data); + CU_ASSERT(stream != NULL); + CU_ASSERT(nghttp2_session_close_stream(session, stream_id, NGHTTP2_OK) == 0); + CU_ASSERT(user_data.stream_close_cb_called == 1); + nghttp2_session_del(session); +} + +void test_nghttp2_session_max_concurrent_streams(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + nghttp2_frame frame; + const char *nv[] = { NULL }; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, NULL); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENED, NULL); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 3, 0, 3, dup_nv(nv)); + session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; + + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + + item = nghttp2_session_get_ob_pq_top(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_REFUSED_STREAM == OB_CTRL(item)->rst_stream.status_code) + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + nghttp2_session_del(session); +} + +static ssize_t block_count_send_callback(nghttp2_session* session, + const uint8_t *data, size_t len, + int flags, + void *user_data) +{ + my_user_data *ud = (my_user_data*)user_data; + int r; + if(ud->block_count == 0) { + r = NGHTTP2_ERR_WOULDBLOCK; + } else { + --ud->block_count; + r = len; + } + return r; +} + +void test_nghttp2_session_data_backoff_by_high_pri_frame(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + my_user_data ud; + nghttp2_data_provider data_prd; + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = block_count_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + data_prd.read_callback = fixed_length_data_source_read_callback; + + ud.ctrl_send_cb_called = 0; + ud.data_source_length = 16*1024; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, &ud); + nghttp2_submit_request(session, 3, nv, &data_prd, NULL); + + ud.block_count = 2; + /* Sends SYN_STREAM + DATA[0] */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(NGHTTP2_SYN_STREAM == ud.sent_frame_type); + /* data for DATA[1] is read from data_prd but it is not sent */ + CU_ASSERT(ud.data_source_length == 8*1024); + + nghttp2_submit_ping(session); + ud.block_count = 2; + /* Sends DATA[1] + PING, PING is interleaved in DATA sequence */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(NGHTTP2_PING == ud.sent_frame_type); + /* data for DATA[2] is read from data_prd but it is not sent */ + CU_ASSERT(ud.data_source_length == 4*1024); + + ud.block_count = 2; + /* Sends DATA[2..3] */ + CU_ASSERT(0 == nghttp2_session_send(session)); + + stream = nghttp2_session_get_stream(session, 1); + CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_stop_data_with_rst_stream(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + my_user_data ud; + nghttp2_data_provider data_prd; + nghttp2_frame frame; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + callbacks.send_callback = block_count_send_callback; + data_prd.read_callback = fixed_length_data_source_read_callback; + + ud.ctrl_send_cb_called = 0; + ud.data_source_length = 16*1024; + + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, &ud); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_submit_response(session, 1, nv, &data_prd); + + ud.block_count = 2; + /* Sends SYN_REPLY + DATA[0] */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(NGHTTP2_SYN_REPLY == ud.sent_frame_type); + /* data for DATA[1] is read from data_prd but it is not sent */ + CU_ASSERT(ud.data_source_length == 8*1024); + + nghttp2_frame_rst_stream_init(&frame.rst_stream, NGHTTP2_PROTO_SPDY2, 1, + NGHTTP2_CANCEL); + CU_ASSERT(0 == nghttp2_session_on_rst_stream_received(session, &frame)); + nghttp2_frame_rst_stream_free(&frame.rst_stream); + + /* Big enough number to send all DATA frames potentially. */ + ud.block_count = 100; + /* Nothing will be sent in the following call. */ + CU_ASSERT(0 == nghttp2_session_send(session)); + /* With RST_STREAM, stream is canceled and further DATA on that + stream are not sent. */ + CU_ASSERT(ud.data_source_length == 8*1024); + + CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + + nghttp2_session_del(session); +} + +/* + * Check that on_stream_close_callback is called when server pushed + * SYN_STREAM have NGHTTP2_CTRL_FLAG_FIN. + */ +void test_nghttp2_session_stream_close_on_syn_stream(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + my_user_data ud; + nghttp2_frame frame; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_stream_close_callback = + no_stream_user_data_stream_close_callback; + ud.stream_close_cb_called = 0; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, &ud); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_FIN | + NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL, + 2, 1, 3, dup_nv(nv)); + + CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame)); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + nghttp2_session_del(session); +} + +void test_nghttp2_session_recv_invalid_frame(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + scripted_data_feed df; + my_user_data user_data; + const char *nv[] = { + "url", "/", NULL + }; + uint8_t *framedata = NULL, *nvbuf = NULL; + size_t framedatalen = 0, nvbuflen = 0; + ssize_t framelen; + nghttp2_frame frame; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.recv_callback = scripted_recv_callback; + callbacks.send_callback = null_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + + user_data.df = &df; + user_data.ctrl_send_cb_called = 0; + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, + &user_data); + nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY2, + NGHTTP2_CTRL_FLAG_NONE, 1, 0, 3, dup_nv(nv)); + framelen = nghttp2_frame_pack_syn_stream(&framedata, &framedatalen, + &nvbuf, &nvbuflen, + &frame.syn_stream, + &session->hd_deflater); + scripted_data_feed_init(&df, framedata, framelen); + + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == user_data.ctrl_send_cb_called); + + /* Receive exactly same bytes of SYN_STREAM causes error */ + scripted_data_feed_init(&df, framedata, framelen); + + CU_ASSERT(0 == nghttp2_session_recv(session)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_send_cb_called); + CU_ASSERT(NGHTTP2_GOAWAY == user_data.sent_frame_type); + + free(framedata); + free(nvbuf); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + nghttp2_session_del(session); +} + +static ssize_t defer_data_source_read_callback +(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, int *eof, + nghttp2_data_source *source, void *user_data) +{ + return NGHTTP2_ERR_DEFERRED; +} + +void test_nghttp2_session_defer_data(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + my_user_data ud; + nghttp2_data_provider data_prd; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + callbacks.send_callback = block_count_send_callback; + data_prd.read_callback = defer_data_source_read_callback; + + ud.ctrl_send_cb_called = 0; + ud.data_source_length = 16*1024; + + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, &callbacks, &ud); + nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENING, NULL); + nghttp2_submit_response(session, 1, nv, &data_prd); + + ud.block_count = 1; + /* Sends SYN_REPLY */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(NGHTTP2_SYN_REPLY == ud.sent_frame_type); + /* No data is read */ + CU_ASSERT(ud.data_source_length == 16*1024); + + ud.block_count = 1; + nghttp2_submit_ping(session); + /* Sends PING */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(NGHTTP2_PING == ud.sent_frame_type); + + /* Resume deferred DATA */ + CU_ASSERT(0 == nghttp2_session_resume_data(session, 1)); + item = nghttp2_session_get_ob_pq_top(session); + OB_DATA(item)->data_prd.read_callback = + fixed_length_data_source_read_callback; + ud.block_count = 1; + /* Reads 2 4KiB blocks */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(ud.data_source_length == 8*1024); + + /* Deferred again */ + OB_DATA(item)->data_prd.read_callback = defer_data_source_read_callback; + /* This is needed since 4KiB block is already read and waiting to be + sent. No read_callback invocation. */ + ud.block_count = 1; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(ud.data_source_length == 8*1024); + + /* Resume deferred DATA */ + + CU_ASSERT(0 == nghttp2_session_resume_data(session, 1)); + item = nghttp2_session_get_ob_pq_top(session); + OB_DATA(item)->data_prd.read_callback = + fixed_length_data_source_read_callback; + ud.block_count = 1; + /* Reads 2 4KiB blocks */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(ud.data_source_length == 0); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_flow_control(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + my_user_data ud; + nghttp2_data_provider data_prd; + nghttp2_frame frame; + nghttp2_stream *stream; + int32_t new_initial_window_size; + nghttp2_settings_entry iv[1]; + nghttp2_frame settings_frame; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + data_prd.read_callback = fixed_length_data_source_read_callback; + + ud.ctrl_send_cb_called = 0; + ud.data_source_length = 128*1024; + + /* Initial window size is 64KiB */ + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud); + nghttp2_submit_request(session, 3, nv, &data_prd, NULL); + + /* Sends 64KiB data */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(64*1024 == ud.data_source_length); + + /* Back 32KiB */ + nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_PROTO_SPDY3, + 1, 32*1024); + nghttp2_session_on_window_update_received(session, &frame); + + /* Sends another 32KiB data */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(32*1024 == ud.data_source_length); + + stream = nghttp2_session_get_stream(session, 1); + /* Change initial window size to 16KiB. The window_size becomes + negative. */ + new_initial_window_size = 16*1024; + stream->window_size = new_initial_window_size- + (session->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE] + -stream->window_size); + session->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE] = + new_initial_window_size; + CU_ASSERT(-48*1024 == stream->window_size); + + /* Back 48KiB */ + frame.window_update.delta_window_size = 48*1024; + nghttp2_session_on_window_update_received(session, &frame); + + /* Nothing is sent because window_size is less than 0 */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(32*1024 == ud.data_source_length); + + /* Back 16KiB */ + frame.window_update.delta_window_size = 16*1024; + nghttp2_session_on_window_update_received(session, &frame); + + /* Sends another 16KiB data */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(16*1024 == ud.data_source_length); + + /* Increase initial window size to 32KiB */ + iv[0].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + iv[0].value = 32*1024; + + nghttp2_frame_settings_init(&settings_frame.settings, NGHTTP2_PROTO_SPDY3, + NGHTTP2_FLAG_SETTINGS_NONE, dup_iv(iv, 1), 1); + nghttp2_session_on_settings_received(session, &settings_frame); + nghttp2_frame_settings_free(&settings_frame.settings); + + /* Sends another 16KiB data */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == ud.data_source_length); + CU_ASSERT(nghttp2_session_get_stream(session, 1)->shut_flags & + NGHTTP2_SHUT_WR); + + nghttp2_frame_window_update_free(&frame.window_update); + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_ctrl_not_send(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_stream *stream; + const char *nv[] = { NULL }; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.on_ctrl_not_send_callback = on_ctrl_not_send_callback; + callbacks.send_callback = null_send_callback; + user_data.ctrl_not_send_cb_called = 0; + user_data.not_sent_frame_type = 0; + user_data.not_sent_error = 0; + + CU_ASSERT(nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &user_data) == 0); + stream = nghttp2_session_open_stream(session, 1, + NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENED, &user_data); + /* Check SYN_STREAM */ + CU_ASSERT(0 == nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_FIN, 3, 3, + nv, NULL)); + + user_data.ctrl_not_send_cb_called = 0; + /* Associated stream closed */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_STREAM == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == user_data.not_sent_error); + + /* Check SYN_REPLY */ + CU_ASSERT(0 == + nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_FIN, 1, nv)); + user_data.ctrl_not_send_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_REPLY == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_INVALID_STREAM_STATE == user_data.not_sent_error); + + stream->state = NGHTTP2_STREAM_OPENING; + user_data.ctrl_not_send_cb_called = 0; + /* Send bogus stream ID */ + CU_ASSERT(0 == + nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_FIN, 3, nv)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_REPLY == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == user_data.not_sent_error); + + user_data.ctrl_not_send_cb_called = 0; + /* Shutdown transmission */ + stream->shut_flags |= NGHTTP2_SHUT_WR; + CU_ASSERT(0 == + nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_FIN, 1, nv)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_REPLY == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_STREAM_SHUT_WR == user_data.not_sent_error); + + stream->shut_flags = NGHTTP2_SHUT_NONE; + user_data.ctrl_not_send_cb_called = 0; + /* Queue RST_STREAM */ + CU_ASSERT(0 == + nghttp2_submit_syn_reply(session, NGHTTP2_CTRL_FLAG_FIN, 1, nv)); + CU_ASSERT(0 == nghttp2_submit_rst_stream(session, 1, NGHTTP2_INTERNAL_ERROR)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_REPLY == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSING == user_data.not_sent_error); + + stream = nghttp2_session_open_stream(session, 3, + NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENED, &user_data); + + /* Check HEADERS */ + user_data.ctrl_not_send_cb_called = 0; + stream->state = NGHTTP2_STREAM_OPENING; + CU_ASSERT(0 == + nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_FIN, 3, nv)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_INVALID_STREAM_STATE == user_data.not_sent_error); + + stream->state = NGHTTP2_STREAM_OPENED; + user_data.ctrl_not_send_cb_called = 0; + /* Queue RST_STREAM */ + CU_ASSERT(0 == + nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_FIN, 3, nv)); + CU_ASSERT(0 == nghttp2_submit_rst_stream(session, 3, NGHTTP2_INTERNAL_ERROR)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSING == user_data.not_sent_error); + + nghttp2_session_del(session); + + /* Check SYN_STREAM */ + user_data.ctrl_not_send_cb_called = 0; + CU_ASSERT(nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY2, + &callbacks, &user_data) == 0); + /* Maximum Stream ID is reached */ + session->next_stream_id = (1u << 31)+1; + CU_ASSERT(0 == nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_FIN, 0, + 3, nv, NULL)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_STREAM == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE == user_data.not_sent_error); + + session->next_stream_id = 1; + user_data.ctrl_not_send_cb_called = 0; + /* Send GOAWAY */ + CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK)); + CU_ASSERT(0 == nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_FIN, 0, + 3, nv, NULL)); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_STREAM == user_data.not_sent_frame_type); + CU_ASSERT(NGHTTP2_ERR_SYN_STREAM_NOT_ALLOWED == user_data.not_sent_error); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_on_settings_received(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data user_data; + nghttp2_stream *stream1, *stream2; + nghttp2_frame frame; + const size_t niv = 5; + nghttp2_settings_entry iv[255]; + + iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[0].value = 1000000009; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[1].value = 50; + iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + iv[2].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[2].value = 64*1024; + iv[2].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + iv[3].settings_id = NGHTTP2_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE; + iv[3].value = 512; + iv[3].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + iv[4].settings_id = 999; + iv[4].value = 0; + iv[4].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, + &user_data); + session->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE] = 16*1024; + + stream1 = nghttp2_session_open_stream(session, 1, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + stream2 = nghttp2_session_open_stream(session, 2, NGHTTP2_CTRL_FLAG_NONE, + 3, NGHTTP2_STREAM_OPENING, NULL); + stream1->window_size = 16*1024; + stream2->window_size = -48*1024; + + nghttp2_frame_settings_init(&frame.settings, NGHTTP2_PROTO_SPDY3, + NGHTTP2_FLAG_SETTINGS_NONE, dup_iv(iv, niv), niv); + + CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame)); + + CU_ASSERT(1000000009 == + session->remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]); + CU_ASSERT(64*1024 == + session->remote_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]); + /* We limit certificate vector in reasonable size. */ + CU_ASSERT(NGHTTP2_MAX_CLIENT_CERT_VECTOR_LENGTH == + session->remote_settings + [NGHTTP2_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE]); + CU_ASSERT(NGHTTP2_MAX_CLIENT_CERT_VECTOR_LENGTH == session->cli_certvec.size); + CU_ASSERT(64*1024 == stream1->window_size); + CU_ASSERT(0 == stream2->window_size); + + frame.settings.iv[2].value = 16*1024; + + CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame)); + + CU_ASSERT(16*1024 == stream1->window_size); + CU_ASSERT(-48*1024 == stream2->window_size); + + nghttp2_frame_settings_free(&frame.settings); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_settings(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data ud; + nghttp2_outbound_item *item; + nghttp2_frame *frame; + nghttp2_settings_entry iv[3]; + + iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[0].value = 50; + iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[1].value = 16*1024; + iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + /* This is duplicate entry */ + iv[2].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[2].value = 150; + iv[2].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_settings(session, NGHTTP2_FLAG_SETTINGS_NONE, + iv, 3)); + + /* Make sure that local settings are not changed */ + CU_ASSERT(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS == + session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]); + CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == + session->local_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]); + + CU_ASSERT(0 == nghttp2_submit_settings(session, + NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS, + iv, 2)); + + /* Make sure that local settings are changed */ + CU_ASSERT(50 == + session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]); + CU_ASSERT(16*1024 == + session->local_settings[NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]); + + item = nghttp2_session_get_next_ob_item(session); + + CU_ASSERT(NGHTTP2_SETTINGS == OB_CTRL_TYPE(item)); + + frame = item->frame; + CU_ASSERT(2 == frame->settings.niv); + CU_ASSERT(NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS == frame->settings.hd.flags); + + CU_ASSERT(50 == frame->settings.iv[0].value); + CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == + frame->settings.iv[0].settings_id); + CU_ASSERT(NGHTTP2_FLAG_SETTINGS_NONE == + frame->settings.iv[0].flags); + + CU_ASSERT(16*1024 == frame->settings.iv[1].value); + CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == + frame->settings.iv[1].settings_id); + CU_ASSERT(NGHTTP2_FLAG_SETTINGS_NONE == + frame->settings.iv[1].flags); + + ud.ctrl_send_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == ud.ctrl_send_cb_called); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_get_outbound_queue_size(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { "version", "HTTP/1.1", NULL }; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, + &callbacks, NULL)); + CU_ASSERT(0 == nghttp2_session_get_outbound_queue_size(session)); + + CU_ASSERT(0 == nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_FIN, 1, 7, + nv, NULL)); + CU_ASSERT(1 == nghttp2_session_get_outbound_queue_size(session)); + + CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK)); + CU_ASSERT(2 == nghttp2_session_get_outbound_queue_size(session)); + + nghttp2_session_del(session); +} + +static ssize_t get_credential_ncerts(nghttp2_session *session, + const nghttp2_origin *origin, + void *user_data) +{ + if(strcmp("example.org", origin->host) == 0 && + strcmp("https", origin->scheme) == 0 && + 443 == origin->port) { + return 2; + } else { + return 0; + } +} + +static ssize_t get_credential_cert(nghttp2_session *session, + const nghttp2_origin *origin, + size_t idx, + uint8_t *cert, size_t certlen, + void *user_data) +{ + size_t len = strlen(origin->host); + if(certlen == 0) { + return len; + } else { + assert(certlen == len); + memcpy(cert, origin->host, len); + return 0; + } +} + +static ssize_t get_credential_proof(nghttp2_session *session, + const nghttp2_origin *origin, + uint8_t *proof, size_t prooflen, + void *uer_data) +{ + size_t len = strlen(origin->scheme); + if(prooflen == 0) { + return len; + } else { + assert(prooflen == len); + memcpy(proof, origin->scheme, len); + return 0; + } +} + +void test_nghttp2_session_prep_credential(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { ":host", "example.org", + ":scheme", "https", + NULL }; + const char *nv_nocert[] = { ":host", "nocert", + ":scheme", "https", + NULL }; + nghttp2_frame frame, *cred_frame; + nghttp2_outbound_item *item; + size_t i; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.get_credential_ncerts = get_credential_ncerts; + callbacks.get_credential_cert = get_credential_cert; + callbacks.get_credential_proof = get_credential_proof; + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, + &callbacks, NULL)); + nghttp2_frame_syn_stream_init(&frame.syn_stream, session->version, + NGHTTP2_CTRL_FLAG_NONE, 1, 0, 0, + dup_nv(nv)); + CU_ASSERT(NGHTTP2_ERR_CREDENTIAL_PENDING == + nghttp2_session_prep_credential(session, &frame.syn_stream)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_CREDENTIAL == OB_CTRL_TYPE(item)); + CU_ASSERT(NGHTTP2_OB_PRI_CREDENTIAL == item->pri); + cred_frame = OB_CTRL(item); + CU_ASSERT(strlen("https") == cred_frame->credential.proof.length); + CU_ASSERT(memcmp("https", cred_frame->credential.proof.data, + cred_frame->credential.proof.length) == 0); + CU_ASSERT(2 == cred_frame->credential.ncerts); + for(i = 0; i < cred_frame->credential.ncerts; ++i) { + CU_ASSERT(strlen("example.org") == cred_frame->credential.certs[i].length); + CU_ASSERT(memcmp("example.org", cred_frame->credential.certs[i].data, + cred_frame->credential.certs[i].length) == 0); + } + /* Next nghttp2_session_get_next_ob_item() call returns slot index */ + CU_ASSERT(1 == nghttp2_session_prep_credential(session, &frame.syn_stream)); + + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + nghttp2_frame_syn_stream_init(&frame.syn_stream, session->version, + NGHTTP2_CTRL_FLAG_NONE, 1, 0, 0, + dup_nv(nv_nocert)); + CU_ASSERT(0 == nghttp2_session_prep_credential(session, &frame.syn_stream)); + nghttp2_frame_syn_stream_free(&frame.syn_stream); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_syn_stream_with_credential(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { ":host", "example.org", + ":scheme", "https", + NULL }; + my_user_data ud; + accumulator acc; + + ud.acc = &acc; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = block_count_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + callbacks.get_credential_ncerts = get_credential_ncerts; + callbacks.get_credential_cert = get_credential_cert; + callbacks.get_credential_proof = get_credential_proof; + + CU_ASSERT(0 == nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, + &callbacks, &ud)); + + CU_ASSERT(0 == nghttp2_submit_request(session, 0, nv, NULL, NULL)); + + ud.block_count = 1; + ud.ctrl_send_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + + CU_ASSERT(1 == ud.ctrl_send_cb_called); + CU_ASSERT(NGHTTP2_CREDENTIAL == ud.sent_frame_type); + + session->callbacks.send_callback = accumulator_send_callback; + acc.length = 0; + ud.ctrl_send_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(1 == ud.ctrl_send_cb_called); + CU_ASSERT(NGHTTP2_SYN_STREAM == ud.sent_frame_type); + /* Check slot */ + CU_ASSERT(1 == acc.buf[17]); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_set_initial_client_cert_origin(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const nghttp2_origin *origin; + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, NULL); + CU_ASSERT(0 == nghttp2_session_set_initial_client_cert_origin + (session, "https", "example.org", 443)); + origin = nghttp2_session_get_client_cert_origin(session, 1); + CU_ASSERT(NULL != origin); + CU_ASSERT(strcmp("https", nghttp2_origin_get_scheme(origin)) == 0); + CU_ASSERT(strcmp("example.org", nghttp2_origin_get_host(origin)) == 0); + CU_ASSERT(443 == nghttp2_origin_get_port(origin)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_set_option(void) +{ + nghttp2_session* session; + nghttp2_session_callbacks callbacks; + int intval; + char charval; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, NULL); + + intval = 1; + CU_ASSERT(0 == + nghttp2_session_set_option(session, + NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE, + &intval, sizeof(intval))); + CU_ASSERT(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE); + + intval = 0; + CU_ASSERT(0 == + nghttp2_session_set_option(session, + NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE, + &intval, sizeof(intval))); + CU_ASSERT((session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE) == 0); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_session_set_option(session, 0, /* 0 is invalid optname */ + &intval, sizeof(intval))); + + charval = 1; + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_session_set_option(session, + NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE, + &charval, sizeof(charval))); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_window_update(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + int32_t stream_id = 2; + my_user_data ud; + nghttp2_outbound_item *item; + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, + &callbacks, &ud); + stream = nghttp2_session_open_stream(session, stream_id, + NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_OPENED, NULL); + stream->recv_window_size = 4096; + + CU_ASSERT(0 == nghttp2_submit_window_update(session, stream_id, 1024)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); + CU_ASSERT(1024 == OB_CTRL(item)->window_update.delta_window_size); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(3072 == stream->recv_window_size); + + CU_ASSERT(0 == nghttp2_submit_window_update(session, stream_id, 4096)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); + CU_ASSERT(4096 == OB_CTRL(item)->window_update.delta_window_size); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == stream->recv_window_size); + + CU_ASSERT(0 == nghttp2_submit_window_update(session, stream_id, 4096)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); + CU_ASSERT(4096 == OB_CTRL(item)->window_update.delta_window_size); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == stream->recv_window_size); + + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_window_update(session, stream_id, 0)); + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == + nghttp2_submit_window_update(session, stream_id, -1)); + CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == + nghttp2_submit_window_update(session, 4, 4096)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_data_read_temporal_failure(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { NULL }; + my_user_data ud; + nghttp2_data_provider data_prd; + nghttp2_frame frame; + nghttp2_data *data_frame; + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.on_ctrl_send_callback = on_ctrl_send_callback; + data_prd.read_callback = fixed_length_data_source_read_callback; + + ud.data_source_length = 128*1024; + + /* Initial window size is 64KiB */ + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud); + nghttp2_submit_request(session, 3, nv, &data_prd, NULL); + + /* Sends 64KiB data */ + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(64*1024 == ud.data_source_length); + + stream = nghttp2_session_get_stream(session, 1); + CU_ASSERT(NULL != stream->deferred_data); + CU_ASSERT(NGHTTP2_DATA == stream->deferred_data->frame_cat); + data_frame = (nghttp2_data*)stream->deferred_data->frame; + data_frame->data_prd.read_callback = + temporal_failure_data_source_read_callback; + + /* Back 64KiB */ + nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_PROTO_SPDY3, + 1, 64*1024); + nghttp2_session_on_window_update_received(session, &frame); + nghttp2_frame_window_update_free(&frame.window_update); + + /* Sending data will fail */ + ud.ctrl_send_cb_called = 0; + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(64*1024 == ud.data_source_length); + + CU_ASSERT(1 == ud.ctrl_send_cb_called); + CU_ASSERT(NGHTTP2_RST_STREAM == ud.sent_frame_type); + + data_prd.read_callback = fail_data_source_read_callback; + nghttp2_submit_request(session, 3, nv, &data_prd, NULL); + /* Sending data will fail */ + CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_recv_eof(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.recv_callback = eof_recv_callback; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, + &callbacks, NULL); + + CU_ASSERT(NGHTTP2_ERR_EOF == nghttp2_session_recv(session)); + + nghttp2_session_del(session); +} + +void test_nghttp2_session_recv_data(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data ud; + uint8_t data[8092]; + int rv; + nghttp2_outbound_item *item; + nghttp2_stream *stream; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback; + callbacks.on_data_recv_callback = on_data_recv_callback; + + nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud); + + /* Create DATA frame with length 4KiB */ + memset(data, 0, sizeof(data)); + nghttp2_put_uint32be(data, 1); + nghttp2_put_uint32be(data+4, 4096); + + /* stream 1 is not opened, so it must be responded with RST_STREAM */ + ud.data_chunk_recv_cb_called = 0; + ud.data_recv_cb_called = 0; + rv = nghttp2_session_mem_recv(session, data, 8+4096); + CU_ASSERT(8+4096 == rv); + + CU_ASSERT(0 == ud.data_chunk_recv_cb_called); + CU_ASSERT(0 == ud.data_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + + CU_ASSERT(0 == nghttp2_session_send(session)); + + /* Create stream 1 with CLOSING state. It is ignored. */ + stream = nghttp2_session_open_stream(session, 1, + NGHTTP2_CTRL_FLAG_NONE, 3, + NGHTTP2_STREAM_CLOSING, NULL); + + ud.data_chunk_recv_cb_called = 0; + ud.data_recv_cb_called = 0; + rv = nghttp2_session_mem_recv(session, data, 8+4096); + CU_ASSERT(8+4096 == rv); + + CU_ASSERT(0 == ud.data_chunk_recv_cb_called); + CU_ASSERT(0 == ud.data_recv_cb_called); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(NULL == item); + + /* This is normal case. DATA is acceptable. */ + stream->state = NGHTTP2_STREAM_OPENED; + + ud.data_chunk_recv_cb_called = 0; + ud.data_recv_cb_called = 0; + rv = nghttp2_session_mem_recv(session, data, 8+4096); + CU_ASSERT(8+4096 == rv); + + CU_ASSERT(1 == ud.data_chunk_recv_cb_called); + CU_ASSERT(1 == ud.data_recv_cb_called); + + nghttp2_session_del(session); +} diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h new file mode 100644 index 00000000..9bbc8238 --- /dev/null +++ b/tests/nghttp2_session_test.h @@ -0,0 +1,77 @@ +/* + * 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. + */ +#ifndef NGHTTP2_SESSION_TEST_H +#define NGHTTP2_SESSION_TEST_H + +void test_nghttp2_session_recv(void); +void test_nghttp2_session_recv_invalid_stream_id(void); +void test_nghttp2_session_add_frame(void); +void test_nghttp2_session_on_syn_stream_received(void); +void test_nghttp2_session_on_syn_stream_received_with_push(void); +void test_nghttp2_session_on_syn_reply_received(void); +void test_nghttp2_session_on_window_update_received(void); +void test_nghttp2_session_send_syn_stream(void); +void test_nghttp2_session_send_syn_reply(void); +void test_nghttp2_submit_response(void); +void test_nghttp2_submit_response_with_null_data_read_callback(void); +void test_nghttp2_submit_request_with_data(void); +void test_nghttp2_submit_request_with_null_data_read_callback(void); +void test_nghttp2_submit_syn_stream(void); +void test_nghttp2_submit_syn_reply(void); +void test_nghttp2_submit_headers(void); +void test_nghttp2_submit_invalid_nv(void); +void test_nghttp2_session_reply_fail(void); +void test_nghttp2_session_on_headers_received(void); +void test_nghttp2_session_on_ping_received(void); +void test_nghttp2_session_on_goaway_received(void); +void test_nghttp2_session_on_data_received(void); +void test_nghttp2_session_on_rst_received(void); +void test_nghttp2_session_is_my_stream_id(void); +void test_nghttp2_session_send_rst_stream(void); +void test_nghttp2_session_get_next_ob_item(void); +void test_nghttp2_session_pop_next_ob_item(void); +void test_nghttp2_session_on_request_recv_callback(void); +void test_nghttp2_session_on_stream_close(void); +void test_nghttp2_session_max_concurrent_streams(void); +void test_nghttp2_session_data_backoff_by_high_pri_frame(void); +void test_nghttp2_session_stop_data_with_rst_stream(void); +void test_nghttp2_session_stream_close_on_syn_stream(void); +void test_nghttp2_session_recv_invalid_frame(void); +void test_nghttp2_session_defer_data(void); +void test_nghttp2_session_flow_control(void); +void test_nghttp2_session_on_ctrl_not_send(void); +void test_nghttp2_session_on_settings_received(void); +void test_nghttp2_submit_settings(void); +void test_nghttp2_session_get_outbound_queue_size(void); +void test_nghttp2_session_prep_credential(void); +void test_nghttp2_submit_syn_stream_with_credential(void); +void test_nghttp2_session_set_initial_client_cert_origin(void); +void test_nghttp2_session_set_option(void); +void test_nghttp2_submit_window_update(void); +void test_nghttp2_session_data_read_temporal_failure(void); +void test_nghttp2_session_recv_eof(void); +void test_nghttp2_session_recv_data(void); + +#endif /* NGHTTP2_SESSION_TEST_H */ diff --git a/tests/spdylay_stream_test.c b/tests/nghttp2_stream_test.c similarity index 78% rename from tests/spdylay_stream_test.c rename to tests/nghttp2_stream_test.c index eadb8b59..8ce745ba 100644 --- a/tests/spdylay_stream_test.c +++ b/tests/nghttp2_stream_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,25 +22,25 @@ * 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_stream_test.h" +#include "nghttp2_stream_test.h" #include -#include "spdylay_stream.h" +#include "nghttp2_stream.h" -void test_spdylay_stream_add_pushed_stream(void) +void test_nghttp2_stream_add_pushed_stream(void) { - spdylay_stream stream; + nghttp2_stream stream; int i, n; - spdylay_stream_init(&stream, 1, SPDYLAY_CTRL_FLAG_NONE, 3, 65536, - SPDYLAY_STREAM_OPENING, NULL); + nghttp2_stream_init(&stream, 1, NGHTTP2_CTRL_FLAG_NONE, 3, 65536, + NGHTTP2_STREAM_OPENING, NULL); n = 26; for(i = 2; i < n; i += 2) { - CU_ASSERT(0 == spdylay_stream_add_pushed_stream(&stream, i)); + CU_ASSERT(0 == nghttp2_stream_add_pushed_stream(&stream, i)); CU_ASSERT((size_t)i/2 == stream.pushed_streams_length); } for(i = 2; i < n; i += 2) { CU_ASSERT(i == stream.pushed_streams[i/2-1]); } - spdylay_stream_free(&stream); + nghttp2_stream_free(&stream); } diff --git a/tests/nghttp2_stream_test.h b/tests/nghttp2_stream_test.h new file mode 100644 index 00000000..721f6d12 --- /dev/null +++ b/tests/nghttp2_stream_test.h @@ -0,0 +1,30 @@ +/* + * 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. + */ +#ifndef NGHTTP2_STREAM_TEST_H +#define NGHTTP2_STREAM_TEST_H + +void test_nghttp2_stream_add_pushed_stream(void); + +#endif /* NGHTTP2_STREAM_TEST_H */ diff --git a/tests/spdylay_test_helper.c b/tests/nghttp2_test_helper.c similarity index 57% rename from tests/spdylay_test_helper.c rename to tests/nghttp2_test_helper.c index 2ea7a20e..d535b911 100644 --- a/tests/spdylay_test_helper.c +++ b/tests/nghttp2_test_helper.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,56 +22,56 @@ * 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_test_helper.h" +#include "nghttp2_test_helper.h" #include #include -#include "spdylay_session.h" +#include "nghttp2_session.h" -ssize_t unpack_frame_with_nv_block(spdylay_frame_type type, +ssize_t unpack_frame_with_nv_block(nghttp2_frame_type type, uint16_t version, - spdylay_frame *frame, - spdylay_zlib *inflater, + nghttp2_frame *frame, + nghttp2_zlib *inflater, const uint8_t *in, size_t len) { - spdylay_buffer buffer; + nghttp2_buffer buffer; ssize_t rv; ssize_t pnvlen; - pnvlen = spdylay_frame_nv_offset(type, version) - SPDYLAY_HEAD_LEN; + pnvlen = nghttp2_frame_nv_offset(type, version) - NGHTTP2_HEAD_LEN; assert(pnvlen > 0); - spdylay_buffer_init(&buffer, 4096); - rv = spdylay_zlib_inflate_hd(inflater, &buffer, - &in[SPDYLAY_HEAD_LEN + pnvlen], - len - SPDYLAY_HEAD_LEN - pnvlen); + nghttp2_buffer_init(&buffer, 4096); + rv = nghttp2_zlib_inflate_hd(inflater, &buffer, + &in[NGHTTP2_HEAD_LEN + pnvlen], + len - NGHTTP2_HEAD_LEN - pnvlen); if(rv < 0) { return rv; } switch(type) { - case SPDYLAY_SYN_STREAM: - rv = spdylay_frame_unpack_syn_stream(&frame->syn_stream, - &in[0], SPDYLAY_HEAD_LEN, - &in[SPDYLAY_HEAD_LEN], pnvlen, + case NGHTTP2_SYN_STREAM: + rv = nghttp2_frame_unpack_syn_stream(&frame->syn_stream, + &in[0], NGHTTP2_HEAD_LEN, + &in[NGHTTP2_HEAD_LEN], pnvlen, &buffer); break; - case SPDYLAY_SYN_REPLY: - rv = spdylay_frame_unpack_syn_reply(&frame->syn_reply, - &in[0], SPDYLAY_HEAD_LEN, - &in[SPDYLAY_HEAD_LEN], pnvlen, + case NGHTTP2_SYN_REPLY: + rv = nghttp2_frame_unpack_syn_reply(&frame->syn_reply, + &in[0], NGHTTP2_HEAD_LEN, + &in[NGHTTP2_HEAD_LEN], pnvlen, &buffer); break; - case SPDYLAY_HEADERS: - rv = spdylay_frame_unpack_headers(&frame->headers, - &in[0], SPDYLAY_HEAD_LEN, - &in[SPDYLAY_HEAD_LEN], pnvlen, + case NGHTTP2_HEADERS: + rv = nghttp2_frame_unpack_headers(&frame->headers, + &in[0], NGHTTP2_HEAD_LEN, + &in[NGHTTP2_HEAD_LEN], pnvlen, &buffer); break; default: /* Must not be reachable */ assert(0); } - spdylay_buffer_free(&buffer); + nghttp2_buffer_free(&buffer); return rv; } diff --git a/tests/spdylay_test_helper.h b/tests/nghttp2_test_helper.h similarity index 78% rename from tests/spdylay_test_helper.h rename to tests/nghttp2_test_helper.h index 9735ed12..ce0663ca 100644 --- a/tests/spdylay_test_helper.h +++ b/tests/nghttp2_test_helper.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,20 +22,20 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_TEST_HELPER_H -#define SPDYLAY_TEST_HELPER_H +#ifndef NGHTTP2_TEST_HELPER_H +#define NGHTTP2_TEST_HELPER_H #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ -#include "spdylay_frame.h" -#include "spdylay_zlib.h" +#include "nghttp2_frame.h" +#include "nghttp2_zlib.h" -ssize_t unpack_frame_with_nv_block(spdylay_frame_type type, +ssize_t unpack_frame_with_nv_block(nghttp2_frame_type type, uint16_t version, - spdylay_frame *frame, - spdylay_zlib *inflater, + nghttp2_frame *frame, + nghttp2_zlib *inflater, const uint8_t *in, size_t len); -#endif /* SPDYLAY_TEST_HELPER_H */ +#endif /* NGHTTP2_TEST_HELPER_H */ diff --git a/tests/spdylay_zlib_test.c b/tests/nghttp2_zlib_test.c similarity index 69% rename from tests/spdylay_zlib_test.c rename to tests/nghttp2_zlib_test.c index 54fe0300..59d039b0 100644 --- a/tests/spdylay_zlib_test.c +++ b/tests/nghttp2_zlib_test.c @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,17 +22,17 @@ * 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_zlib_test.h" +#include "nghttp2_zlib_test.h" #include #include -#include "spdylay_zlib.h" +#include "nghttp2_zlib.h" -static void test_spdylay_zlib_with(uint16_t version) +static void test_nghttp2_zlib_with(uint16_t version) { - spdylay_zlib deflater, inflater; + nghttp2_zlib deflater, inflater; const char msg[] = "GET /chat HTTP/1.1\r\n" "Host: server.example.com\r\n" @@ -44,39 +44,39 @@ static void test_spdylay_zlib_with(uint16_t version) "Sec-WebSocket-Version: 13\r\n" "\r\n"; uint8_t inflatebuf[sizeof(msg)]; - spdylay_buffer buf; + nghttp2_buffer buf; uint8_t *deflatebuf; size_t deflatebuf_max; ssize_t deflatebuf_len; - spdylay_buffer_init(&buf, 4096); + nghttp2_buffer_init(&buf, 4096); - CU_ASSERT(0 == spdylay_zlib_deflate_hd_init(&deflater, 1, + CU_ASSERT(0 == nghttp2_zlib_deflate_hd_init(&deflater, 1, version)); - CU_ASSERT(0 == spdylay_zlib_inflate_hd_init(&inflater, version)); + CU_ASSERT(0 == nghttp2_zlib_inflate_hd_init(&inflater, version)); - deflatebuf_max = spdylay_zlib_deflate_hd_bound(&deflater, sizeof(msg)); + deflatebuf_max = nghttp2_zlib_deflate_hd_bound(&deflater, sizeof(msg)); deflatebuf = malloc(deflatebuf_max); - CU_ASSERT(0 < (deflatebuf_len = spdylay_zlib_deflate_hd + CU_ASSERT(0 < (deflatebuf_len = nghttp2_zlib_deflate_hd (&deflater, deflatebuf, deflatebuf_max, (const uint8_t*)msg, sizeof(msg)))); - CU_ASSERT(sizeof(msg) == spdylay_zlib_inflate_hd + CU_ASSERT(sizeof(msg) == nghttp2_zlib_inflate_hd (&inflater, &buf, deflatebuf, deflatebuf_len)); free(deflatebuf); - spdylay_buffer_serialize(&buf, inflatebuf); + nghttp2_buffer_serialize(&buf, inflatebuf); - spdylay_zlib_deflate_free(&deflater); - spdylay_zlib_inflate_free(&inflater); + nghttp2_zlib_deflate_free(&deflater); + nghttp2_zlib_inflate_free(&inflater); - spdylay_buffer_free(&buf); + nghttp2_buffer_free(&buf); } -void test_spdylay_zlib_spdy2(void) +void test_nghttp2_zlib_spdy2(void) { - test_spdylay_zlib_with(SPDYLAY_PROTO_SPDY2); + test_nghttp2_zlib_with(NGHTTP2_PROTO_SPDY2); } -void test_spdylay_zlib_spdy3(void) +void test_nghttp2_zlib_spdy3(void) { - test_spdylay_zlib_with(SPDYLAY_PROTO_SPDY3); + test_nghttp2_zlib_with(NGHTTP2_PROTO_SPDY3); } diff --git a/tests/spdylay_buffer_test.h b/tests/nghttp2_zlib_test.h similarity index 85% rename from tests/spdylay_buffer_test.h rename to tests/nghttp2_zlib_test.h index 6a520412..48d4581d 100644 --- a/tests/spdylay_buffer_test.h +++ b/tests/nghttp2_zlib_test.h @@ -1,5 +1,5 @@ /* - * Spdylay - SPDY Library + * nghttp2 - HTTP/2.0 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * @@ -22,10 +22,10 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SPDYLAY_BUFFER_TEST_H -#define SPDYLAY_BUFFER_TEST_H +#ifndef NGHTTP2_ZLIB_TEST_H +#define NGHTTP2_ZLIB_TEST_H -void test_spdylay_buffer(void); -void test_spdylay_buffer_reader(void); +void test_nghttp2_zlib_spdy2(void); +void test_nghttp2_zlib_spdy3(void); -#endif /* SPDYLAY_BUFFER_TEST_H */ +#endif /* NGHTTP2_ZLIB_TEST_H */ diff --git a/tests/spdylay_buffer_test.c b/tests/spdylay_buffer_test.c deleted file mode 100644 index a6179fda..00000000 --- a/tests/spdylay_buffer_test.c +++ /dev/null @@ -1,124 +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_buffer_test.h" - -#include - -#include - -#include "spdylay_buffer.h" -#include "spdylay_net.h" - -void test_spdylay_buffer(void) -{ - spdylay_buffer buffer; - uint8_t out[1024]; - spdylay_buffer_init(&buffer, 8); - CU_ASSERT(0 == spdylay_buffer_length(&buffer)); - CU_ASSERT(0 == spdylay_buffer_avail(&buffer)); - CU_ASSERT(NULL == spdylay_buffer_get(&buffer)); - CU_ASSERT(0 == spdylay_buffer_alloc(&buffer)); - - CU_ASSERT(8 == spdylay_buffer_avail(&buffer)); - CU_ASSERT(NULL != spdylay_buffer_get(&buffer)); - memcpy(spdylay_buffer_get(&buffer), "012", 3); - spdylay_buffer_advance(&buffer, 3); - CU_ASSERT(3 == spdylay_buffer_length(&buffer)); - - CU_ASSERT(5 == spdylay_buffer_avail(&buffer)); - memcpy(spdylay_buffer_get(&buffer), "34567", 5); - spdylay_buffer_advance(&buffer, 5); - CU_ASSERT(8 == spdylay_buffer_length(&buffer)); - - CU_ASSERT(0 == spdylay_buffer_avail(&buffer)); - CU_ASSERT(0 == spdylay_buffer_alloc(&buffer)); - memcpy(spdylay_buffer_get(&buffer), "89ABCDE", 7); - spdylay_buffer_advance(&buffer, 7); - CU_ASSERT(15 == spdylay_buffer_length(&buffer)); - - CU_ASSERT(1 == spdylay_buffer_avail(&buffer)); - - spdylay_buffer_serialize(&buffer, out); - CU_ASSERT(0 == memcmp("0123456789ABCDE", out, 15)); - - spdylay_buffer_reset(&buffer); - - CU_ASSERT(0 == spdylay_buffer_length(&buffer)); - CU_ASSERT(0 == spdylay_buffer_avail(&buffer)); - CU_ASSERT(NULL == spdylay_buffer_get(&buffer)); - CU_ASSERT(0 == spdylay_buffer_alloc(&buffer)); - - CU_ASSERT(8 == spdylay_buffer_avail(&buffer)); - memcpy(spdylay_buffer_get(&buffer), "Hello", 5); - spdylay_buffer_advance(&buffer, 5); - CU_ASSERT(5 == spdylay_buffer_length(&buffer)); - - spdylay_buffer_serialize(&buffer, out); - CU_ASSERT(0 == memcmp("Hello", out, 5)); - - spdylay_buffer_free(&buffer); -} - -void test_spdylay_buffer_reader(void) -{ - spdylay_buffer buffer; - spdylay_buffer_reader reader; - uint16_t val16; - uint32_t val32; - uint8_t temp[256]; - - spdylay_buffer_init(&buffer, 3); - spdylay_buffer_write(&buffer, (const uint8_t*)"hello", 5); - val16 = htons(678); - spdylay_buffer_write(&buffer, (const uint8_t*)&val16, sizeof(uint16_t)); - val32 = htonl(1000000007); - spdylay_buffer_write(&buffer, (const uint8_t*)&val32, sizeof(uint32_t)); - spdylay_buffer_write(&buffer, (const uint8_t*)"world", 5); - - CU_ASSERT(5+2+4+5 == spdylay_buffer_length(&buffer)); - - spdylay_buffer_reader_init(&reader, &buffer); - - spdylay_buffer_reader_data(&reader, temp, 5); - CU_ASSERT(memcmp(temp, "hello", 5) == 0); - CU_ASSERT(678 == spdylay_buffer_reader_uint16(&reader)); - CU_ASSERT(1000000007 == spdylay_buffer_reader_uint32(&reader)); - CU_ASSERT('w' == spdylay_buffer_reader_uint8(&reader)); - CU_ASSERT('o' == spdylay_buffer_reader_uint8(&reader)); - CU_ASSERT('r' == spdylay_buffer_reader_uint8(&reader)); - CU_ASSERT('l' == spdylay_buffer_reader_uint8(&reader)); - CU_ASSERT('d' == spdylay_buffer_reader_uint8(&reader)); - - spdylay_buffer_reader_init(&reader, &buffer); - spdylay_buffer_reader_advance(&reader, 5); - CU_ASSERT(678 == spdylay_buffer_reader_uint16(&reader)); - spdylay_buffer_reader_advance(&reader, 1); - spdylay_buffer_reader_advance(&reader, 1); - spdylay_buffer_reader_advance(&reader, 1); - spdylay_buffer_reader_advance(&reader, 1); - CU_ASSERT('w' == spdylay_buffer_reader_uint8(&reader)); - - spdylay_buffer_free(&buffer); -} diff --git a/tests/spdylay_client_cert_vector_test.c b/tests/spdylay_client_cert_vector_test.c deleted file mode 100644 index b247f3d6..00000000 --- a/tests/spdylay_client_cert_vector_test.c +++ /dev/null @@ -1,124 +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_client_cert_vector_test.h" - -#include - -#include "spdylay_client_cert_vector.h" - -static spdylay_origin* create_origin(const char *scheme, const char *host, - uint16_t port) -{ - spdylay_origin *origin = malloc(sizeof(spdylay_origin)); - spdylay_origin_set(origin, scheme, host, port); - return origin; -} - -void test_spdylay_client_cert_vector_find(void) -{ - spdylay_client_cert_vector certvec; - spdylay_origin *origin; - const spdylay_origin *origin_get; - size_t slot; - spdylay_client_cert_vector_init(&certvec, 3); - - origin = create_origin("https", "example.org", 443); - CU_ASSERT(0 == spdylay_client_cert_vector_find(&certvec, origin)); - CU_ASSERT(1 == spdylay_client_cert_vector_put(&certvec, origin)); - slot = spdylay_client_cert_vector_find(&certvec, origin); - CU_ASSERT(1 == slot); - origin_get = spdylay_client_cert_vector_get_origin(&certvec, slot); - CU_ASSERT(strcmp(origin->scheme, origin_get->scheme) == 0); - CU_ASSERT(strcmp(origin->host, origin_get->host) == 0); - CU_ASSERT(origin->port == origin_get->port); - - origin = create_origin("https", "example.org", 8443); - CU_ASSERT(0 == spdylay_client_cert_vector_find(&certvec, origin)); - CU_ASSERT(2 == spdylay_client_cert_vector_put(&certvec, origin)); - slot = spdylay_client_cert_vector_find(&certvec, origin); - CU_ASSERT(2 == slot); - - origin = create_origin("https", "example.com", 443); - CU_ASSERT(0 == spdylay_client_cert_vector_find(&certvec, origin)); - CU_ASSERT(3 == spdylay_client_cert_vector_put(&certvec, origin)); - slot = spdylay_client_cert_vector_find(&certvec, origin); - CU_ASSERT(3 == slot); - - origin = create_origin("https", "example.com", 8443); - CU_ASSERT(0 == spdylay_client_cert_vector_find(&certvec, origin)); - CU_ASSERT(1 == spdylay_client_cert_vector_put(&certvec, origin)); - slot = spdylay_client_cert_vector_find(&certvec, origin); - CU_ASSERT(1 == slot); - - origin = create_origin("https", "example.org", 443); - CU_ASSERT(0 == spdylay_client_cert_vector_find(&certvec, origin)); - free(origin); - - spdylay_client_cert_vector_free(&certvec); -} - -void test_spdylay_client_cert_vector_resize(void) -{ - spdylay_client_cert_vector certvec; - spdylay_origin *origin; - size_t i; - spdylay_client_cert_vector_init(&certvec, 3); - - origin = create_origin("https", "example.org", 443); - spdylay_client_cert_vector_put(&certvec, origin); - origin = create_origin("https", "example.com", 443); - spdylay_client_cert_vector_put(&certvec, origin); - - CU_ASSERT(0 == spdylay_client_cert_vector_resize(&certvec, 1)); - CU_ASSERT(NULL != spdylay_client_cert_vector_get_origin(&certvec, 1)); - CU_ASSERT(1 == certvec.last_slot); - - CU_ASSERT(0 == spdylay_client_cert_vector_resize(&certvec, 8)); - CU_ASSERT(NULL != spdylay_client_cert_vector_get_origin(&certvec, 1)); - CU_ASSERT(1 == certvec.last_slot); - for(i = 2; i <= 8; ++i) { - CU_ASSERT(NULL == spdylay_client_cert_vector_get_origin(&certvec, i)); - } - - spdylay_client_cert_vector_free(&certvec); -} - -void test_spdylay_client_cert_vector_get_origin(void) -{ - spdylay_client_cert_vector certvec; - spdylay_origin *origin; - spdylay_client_cert_vector_init(&certvec, 3); - - origin = create_origin("https", "example.org", 443); - CU_ASSERT(1 == spdylay_client_cert_vector_put(&certvec, origin)); - - CU_ASSERT(NULL == spdylay_client_cert_vector_get_origin(&certvec, 0)); - CU_ASSERT(NULL != spdylay_client_cert_vector_get_origin(&certvec, 1)); - CU_ASSERT(NULL == spdylay_client_cert_vector_get_origin(&certvec, 2)); - CU_ASSERT(NULL == spdylay_client_cert_vector_get_origin(&certvec, 3)); - CU_ASSERT(NULL == spdylay_client_cert_vector_get_origin(&certvec, 4)); - - spdylay_client_cert_vector_free(&certvec); -} diff --git a/tests/spdylay_client_cert_vector_test.h b/tests/spdylay_client_cert_vector_test.h deleted file mode 100644 index 553b4202..00000000 --- a/tests/spdylay_client_cert_vector_test.h +++ /dev/null @@ -1,32 +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. - */ -#ifndef SPDYLAY_CLIENT_CERT_VECTOR_TEST_H -#define SPDYLAY_CLIENT_CERT_VECTOR_TEST_H - -void test_spdylay_client_cert_vector_find(void); -void test_spdylay_client_cert_vector_resize(void); -void test_spdylay_client_cert_vector_get_origin(void); - -#endif /* SPDYLAY_CLIENT_CERT_VECTOR_TEST_H */ diff --git a/tests/spdylay_frame_test.h b/tests/spdylay_frame_test.h deleted file mode 100644 index ed66a57e..00000000 --- a/tests/spdylay_frame_test.h +++ /dev/null @@ -1,60 +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. - */ -#ifndef SPDYLAY_FRAME_TEST_H -#define SPDYLAY_FRAME_TEST_H - -void test_spdylay_frame_unpack_nv_spdy2(void); -void test_spdylay_frame_unpack_nv_spdy3(void); -void test_spdylay_frame_pack_nv_duplicate_keys(void); -void test_spdylay_frame_pack_nv_empty_value_spdy2(void); -void test_spdylay_frame_pack_nv_empty_value_spdy3(void); -void test_spdylay_frame_count_nv_space(void); -void test_spdylay_frame_count_unpack_nv_space(void); -void test_spdylay_frame_pack_ping(void); -void test_spdylay_frame_pack_goaway_spdy2(void); -void test_spdylay_frame_pack_goaway_spdy3(void); -void test_spdylay_frame_pack_syn_stream_spdy2(void); -void test_spdylay_frame_pack_syn_stream_spdy3(void); -void test_spdylay_frame_pack_syn_stream_frame_too_large(void); -void test_spdylay_frame_pack_syn_reply_spdy2(void); -void test_spdylay_frame_pack_syn_reply_spdy3(void); -void test_spdylay_frame_pack_headers_spdy2(void); -void test_spdylay_frame_pack_headers_spdy3(void); -void test_spdylay_frame_pack_window_update(void); -void test_spdylay_frame_pack_settings_spdy2(void); -void test_spdylay_frame_pack_settings_spdy3(void); -void test_spdylay_frame_pack_credential(void); -void test_spdylay_frame_nv_sort(void); -void test_spdylay_frame_nv_downcase(void); -void test_spdylay_frame_nv_2to3(void); -void test_spdylay_frame_nv_3to2(void); -void test_spdylay_frame_unpack_nv_check_name_spdy2(void); -void test_spdylay_frame_unpack_nv_check_name_spdy3(void); -void test_spdylay_frame_unpack_nv_last_empty_value_spdy2(void); -void test_spdylay_frame_unpack_nv_last_empty_value_spdy3(void); -void test_spdylay_frame_nv_set_origin(void); -void test_spdylay_frame_nv_check_null(void); - -#endif /* SPDYLAY_FRAME_TEST_H */ diff --git a/tests/spdylay_map_test.h b/tests/spdylay_map_test.h deleted file mode 100644 index 62bbaaad..00000000 --- a/tests/spdylay_map_test.h +++ /dev/null @@ -1,32 +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. - */ -#ifndef SPDYLAY_MAP_TEST_H -#define SPDYLAY_MAP_TEST_H - -void test_spdylay_map(void); -void test_spdylay_map_functional(void); -void test_spdylay_map_each_free(void); - -#endif /* SPDYLAY_MAP_TEST_H */ diff --git a/tests/spdylay_pq_test.c b/tests/spdylay_pq_test.c deleted file mode 100644 index 7cdba55d..00000000 --- a/tests/spdylay_pq_test.c +++ /dev/null @@ -1,79 +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_pq_test.h" - -#include - -#include "spdylay_pq.h" - -static int pq_compar(const void *lhs, const void *rhs) -{ - return strcmp(lhs, rhs); -} - -void test_spdylay_pq(void) -{ - int i; - spdylay_pq pq; - spdylay_pq_init(&pq, pq_compar); - CU_ASSERT(spdylay_pq_empty(&pq)); - CU_ASSERT(0 == spdylay_pq_size(&pq)); - CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"foo")); - CU_ASSERT(0 == spdylay_pq_empty(&pq)); - CU_ASSERT(1 == spdylay_pq_size(&pq)); - CU_ASSERT(strcmp("foo", spdylay_pq_top(&pq)) == 0); - CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"bar")); - CU_ASSERT(strcmp("bar", spdylay_pq_top(&pq)) == 0); - CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"baz")); - CU_ASSERT(strcmp("bar", spdylay_pq_top(&pq)) == 0); - CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"C")); - CU_ASSERT(4 == spdylay_pq_size(&pq)); - CU_ASSERT(strcmp("C", spdylay_pq_top(&pq)) == 0); - spdylay_pq_pop(&pq); - CU_ASSERT(3 == spdylay_pq_size(&pq)); - CU_ASSERT(strcmp("bar", spdylay_pq_top(&pq)) == 0); - spdylay_pq_pop(&pq); - CU_ASSERT(strcmp("baz", spdylay_pq_top(&pq)) == 0); - spdylay_pq_pop(&pq); - CU_ASSERT(strcmp("foo", spdylay_pq_top(&pq)) == 0); - spdylay_pq_pop(&pq); - CU_ASSERT(spdylay_pq_empty(&pq)); - CU_ASSERT(0 == spdylay_pq_size(&pq)); - CU_ASSERT(NULL == spdylay_pq_top(&pq)); - - /* Add bunch of entry to see realloc works */ - for(i = 0; i < 10000; ++i) { - CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"foo")); - CU_ASSERT((size_t)(i+1) == spdylay_pq_size(&pq)); - } - for(i = 10000; i > 0; --i) { - CU_ASSERT(NULL != spdylay_pq_top(&pq)); - spdylay_pq_pop(&pq); - CU_ASSERT((size_t)(i-1) == spdylay_pq_size(&pq)); - } - - spdylay_pq_free(&pq); -} - diff --git a/tests/spdylay_session_test.c b/tests/spdylay_session_test.c deleted file mode 100644 index 1c081b91..00000000 --- a/tests/spdylay_session_test.c +++ /dev/null @@ -1,2688 +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_session_test.h" - -#include - -#include -#include - -#include "spdylay_session.h" -#include "spdylay_stream.h" -#include "spdylay_net.h" -#include "spdylay_helper.h" -#include "spdylay_test_helper.h" - -#define OB_CTRL(ITEM) spdylay_outbound_item_get_ctrl_frame(ITEM) -#define OB_CTRL_TYPE(ITEM) spdylay_outbound_item_get_ctrl_frame_type(ITEM) -#define OB_DATA(ITEM) spdylay_outbound_item_get_data_frame(ITEM) - -typedef struct { - uint8_t buf[4096]; - size_t length; -} accumulator; - -typedef struct { - uint8_t data[8192]; - uint8_t* datamark; - uint8_t* datalimit; - size_t feedseq[8192]; - size_t seqidx; -} scripted_data_feed; - -typedef struct { - accumulator *acc; - scripted_data_feed *df; - int ctrl_recv_cb_called, invalid_ctrl_recv_cb_called; - int ctrl_send_cb_called; - spdylay_frame_type sent_frame_type; - int ctrl_not_send_cb_called; - spdylay_frame_type not_sent_frame_type; - int not_sent_error; - int stream_close_cb_called; - size_t data_source_length; - int32_t stream_id; - size_t block_count; - int data_chunk_recv_cb_called; - int data_recv_cb_called; -} my_user_data; - -static void scripted_data_feed_init(scripted_data_feed *df, - uint8_t *data, size_t data_length) -{ - memset(df, 0, sizeof(scripted_data_feed)); - memcpy(df->data, data, data_length); - df->datamark = df->data; - df->datalimit = df->data+data_length; - df->feedseq[0] = data_length; -} - -static ssize_t null_send_callback(spdylay_session *session, - const uint8_t* data, size_t len, int flags, - void *user_data) -{ - return len; -} - -static ssize_t fail_send_callback(spdylay_session *session, - const uint8_t *data, size_t len, int flags, - void *user_data) -{ - return SPDYLAY_ERR_CALLBACK_FAILURE; -} - -static ssize_t scripted_recv_callback(spdylay_session *session, - uint8_t* data, size_t len, int flags, - void *user_data) -{ - scripted_data_feed *df = ((my_user_data*)user_data)->df; - size_t wlen = df->feedseq[df->seqidx] > len ? len : df->feedseq[df->seqidx]; - memcpy(data, df->datamark, wlen); - df->datamark += wlen; - if(wlen <= len) { - ++df->seqidx; - } else { - df->feedseq[df->seqidx] -= wlen; - } - return wlen; -} - -static ssize_t eof_recv_callback(spdylay_session *session, - uint8_t* data, size_t len, int flags, - void *user_data) -{ - return SPDYLAY_ERR_EOF; -} - -static ssize_t accumulator_send_callback(spdylay_session *session, - const uint8_t *buf, size_t len, - int flags, void* user_data) -{ - accumulator *acc = ((my_user_data*)user_data)->acc; - assert(acc->length+len < sizeof(acc->buf)); - memcpy(acc->buf+acc->length, buf, len); - acc->length += len; - return len; -} - -static void on_ctrl_recv_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ++ud->ctrl_recv_cb_called; -} - -static void on_invalid_ctrl_recv_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, - uint32_t status_code, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ++ud->invalid_ctrl_recv_cb_called; -} - -static void on_ctrl_send_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ++ud->ctrl_send_cb_called; - ud->sent_frame_type = type; -} - -static void on_ctrl_not_send_callback(spdylay_session *session, - spdylay_frame_type type, - spdylay_frame *frame, - int error, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ++ud->ctrl_not_send_cb_called; - ud->not_sent_frame_type = type; - ud->not_sent_error = error; -} - -static void on_data_chunk_recv_callback(spdylay_session *session, - uint8_t flags, int32_t stream_id, - const uint8_t *data, size_t len, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ++ud->data_chunk_recv_cb_called; -} - -static void on_data_recv_callback(spdylay_session *session, - uint8_t flags, int32_t stream_id, - int32_t length, void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ++ud->data_recv_cb_called; -} - -static ssize_t fixed_length_data_source_read_callback -(spdylay_session *session, int32_t stream_id, - uint8_t *buf, size_t len, int *eof, - spdylay_data_source *source, void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - size_t wlen; - if(len < ud->data_source_length) { - wlen = len; - } else { - wlen = ud->data_source_length; - } - ud->data_source_length -= wlen; - if(ud->data_source_length == 0) { - *eof = 1; - } - return wlen; -} - -static ssize_t temporal_failure_data_source_read_callback -(spdylay_session *session, int32_t stream_id, - uint8_t *buf, size_t len, int *eof, - spdylay_data_source *source, void *user_data) -{ - return SPDYLAY_ERR_TEMPORAL_CALLBACK_FAILURE; -} - -static ssize_t fail_data_source_read_callback -(spdylay_session *session, int32_t stream_id, - uint8_t *buf, size_t len, int *eof, - spdylay_data_source *source, void *user_data) -{ - return SPDYLAY_ERR_CALLBACK_FAILURE; -} - -static void on_request_recv_callback(spdylay_session *session, - int32_t stream_id, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - ud->stream_id = stream_id; -} - -static void no_stream_user_data_stream_close_callback -(spdylay_session *session, - int32_t stream_id, - spdylay_status_code status_code, - void *user_data) -{ - my_user_data* my_data = (my_user_data*)user_data; - ++my_data->stream_close_cb_called; -} - -static char** dup_nv(const char **src) -{ - return spdylay_frame_nv_copy(src); -} - -static spdylay_settings_entry* dup_iv(const spdylay_settings_entry *iv, - size_t niv) -{ - return spdylay_frame_iv_copy(iv, niv); -} - -static const char *empty_name_nv[] = { "Version", "HTTP/1.1", - "", "empty name", - NULL }; - -static const char *null_val_nv[] = { "Version", "HTTP/1.1", - "Foo", NULL, - NULL }; - -void test_spdylay_session_recv(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - scripted_data_feed df; - my_user_data user_data; - const char *nv[] = { - "url", "/", NULL - }; - const char *upcase_nv[] = { - "URL", "/", NULL - }; - const char *mid_nv[] = { - "method", "GET", - "scheme", "https", - "url", "/", - "x-head", "foo", - "x-head", "bar", - "version", "HTTP/1.1", - "x-empty", "", - NULL - }; - uint8_t *framedata = NULL, *nvbuf = NULL; - size_t framedatalen = 0, nvbuflen = 0; - ssize_t framelen; - spdylay_frame frame; - int i; - spdylay_outbound_item *item; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.recv_callback = scripted_recv_callback; - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - user_data.df = &df; - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, - 1, 0, 3, dup_nv(nv)); - framelen = spdylay_frame_pack_syn_stream(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_stream, - &session->hd_deflater); - scripted_data_feed_init(&df, framedata, framelen); - /* Send 1 byte per each read */ - for(i = 0; i < framelen; ++i) { - df.feedseq[i] = 1; - } - spdylay_frame_syn_stream_free(&frame.syn_stream); - - user_data.ctrl_recv_cb_called = 0; - while((ssize_t)df.seqidx < framelen) { - CU_ASSERT(0 == spdylay_session_recv(session)); - } - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - - /* Receive SYN_STREAM with invalid header block */ - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, - 3, 0, 3, dup_nv(upcase_nv)); - framelen = spdylay_frame_pack_syn_stream(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_stream, - &session->hd_deflater); - spdylay_frame_syn_stream_free(&frame.syn_stream); - scripted_data_feed_init(&df, framedata, framelen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.status_code); - CU_ASSERT(0 == spdylay_session_send(session)); - - /* Received SYN_STREAM without name/value header block */ - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, - 5, 0, 3, dup_nv(upcase_nv)); - framelen = spdylay_frame_pack_syn_stream(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_stream, - &session->hd_deflater); - spdylay_frame_syn_stream_free(&frame.syn_stream); - /* Use bytes that come before name/value header block */ - spdylay_put_uint32be(&framedata[4], - SPDYLAY_SYN_STREAM_NV_OFFSET - SPDYLAY_HEAD_LEN); - scripted_data_feed_init(&df, framedata, SPDYLAY_SYN_STREAM_NV_OFFSET); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_GOAWAY == OB_CTRL_TYPE(item)); - - spdylay_session_del(session); - - /* Some tests for frame too large */ - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, - &user_data); - /* made max buffer small to cause error intentionally */ - /* Inflated wire format of mid_nv will be 111 in SPDY/3. So payload - length will be 121. Setting max buffer size to 110 will cause - error while inflating name/value header block. */ - session->max_recv_ctrl_frame_buf = 110; - - /* Receive SYN_STREAM with too large payload */ - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_NONE, - 1, 0, 3, dup_nv(mid_nv)); - framelen = spdylay_frame_pack_syn_stream(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_stream, - &session->hd_deflater); - spdylay_frame_syn_stream_free(&frame.syn_stream); - scripted_data_feed_init(&df, framedata, framelen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.status_code); - CU_ASSERT(1 == OB_CTRL(item)->rst_stream.stream_id); - CU_ASSERT(0 == spdylay_session_send(session)); - - /* For SYN_REPLY and SYN_HEADERS, make max buffer even smaller */ - session->max_recv_ctrl_frame_buf = 8; - - /* Receive SYN_REPLY with too large payload */ - spdylay_frame_syn_reply_init(&frame.syn_reply, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_NONE, - 1, dup_nv(mid_nv)); - framelen = spdylay_frame_pack_syn_reply(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_reply, - &session->hd_deflater); - spdylay_frame_syn_reply_free(&frame.syn_reply); - scripted_data_feed_init(&df, framedata, framelen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.status_code); - CU_ASSERT(1 == OB_CTRL(item)->rst_stream.stream_id); - CU_ASSERT(0 == spdylay_session_send(session)); - - /* Receive HEADERS with too large payload */ - spdylay_frame_headers_init(&frame.headers, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_NONE, - 1, dup_nv(mid_nv)); - framelen = spdylay_frame_pack_headers(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.headers, - &session->hd_deflater); - spdylay_frame_headers_free(&frame.headers); - scripted_data_feed_init(&df, framedata, framelen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.status_code); - CU_ASSERT(1 == OB_CTRL(item)->rst_stream.stream_id); - CU_ASSERT(0 == spdylay_session_send(session)); - - /* Receive PING with too large payload */ - spdylay_frame_ping_init(&frame.ping, SPDYLAY_PROTO_SPDY3, 1); - spdylay_reserve_buffer(&framedata, &framedatalen, 77); - framelen = spdylay_frame_pack_ping(&framedata, &framedatalen, &frame.ping); - spdylay_frame_ping_free(&frame.ping); - spdylay_put_uint32be(&framedata[4], framedatalen - SPDYLAY_HEAD_LEN); - scripted_data_feed_init(&df, framedata, framedatalen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_GOAWAY == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_GOAWAY_PROTOCOL_ERROR == - OB_CTRL(item)->rst_stream.status_code); - CU_ASSERT(0 == spdylay_session_send(session)); - - spdylay_session_del(session); - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - /* Receive SYN_REPLY with invalid header block */ - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_frame_syn_reply_init(&frame.syn_reply, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 1, dup_nv(upcase_nv)); - framelen = spdylay_frame_pack_syn_reply(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_reply, - &session->hd_deflater); - spdylay_frame_syn_reply_free(&frame.syn_reply); - scripted_data_feed_init(&df, framedata, framelen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.status_code); - - CU_ASSERT(0 == spdylay_session_send(session)); - - /* Receive HEADERS with invalid header block */ - spdylay_session_open_stream(session, 3, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENED, NULL); - spdylay_frame_headers_init(&frame.headers, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 3, dup_nv(upcase_nv)); - framelen = spdylay_frame_pack_headers(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.headers, - &session->hd_deflater); - spdylay_frame_headers_free(&frame.headers); - scripted_data_feed_init(&df, framedata, framelen); - user_data.ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == user_data.ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.status_code); - - free(framedata); - free(nvbuf); - spdylay_session_del(session); -} - -void test_spdylay_session_add_frame(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - accumulator acc; - my_user_data user_data; - const char *nv[] = { - "method", "GET", - "scheme", "https", - "url", "/", - "version", "HTTP/1.1", - NULL - }; - spdylay_frame *frame; - spdylay_syn_stream_aux_data *aux_data = - malloc(sizeof(spdylay_syn_stream_aux_data)); - const uint8_t hd_ans1[] = { - 0x80, 0x02, 0x00, 0x01 - }; - uint32_t temp32; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - memset(aux_data, 0, sizeof(spdylay_syn_stream_aux_data)); - acc.length = 0; - user_data.acc = &acc; - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &user_data)); - - frame = malloc(sizeof(spdylay_frame)); - spdylay_frame_syn_stream_init(&frame->syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 0, 0, 3, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, - aux_data)); - CU_ASSERT(0 == spdylay_pq_empty(&session->ob_ss_pq)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(memcmp(hd_ans1, acc.buf, 4) == 0); - /* check stream id */ - memcpy(&temp32, &acc.buf[8], 4); - temp32 = ntohl(temp32); - CU_ASSERT(1 == temp32); - /* check assoc stream id */ - memcpy(&temp32, &acc.buf[12], 4); - temp32 = ntohl(temp32); - CU_ASSERT(0 == temp32); - /* check pri */ - temp32 = (acc.buf[16] >> 6) & 0x3; - CU_ASSERT(3 == temp32); - - spdylay_session_del(session); -} - -void test_spdylay_session_recv_invalid_stream_id(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - scripted_data_feed df; - my_user_data user_data; - const char *nv[] = { NULL }; - uint8_t *framedata = NULL, *nvbuf = NULL; - size_t framedatalen = 0, nvbuflen = 0; - ssize_t framelen; - spdylay_frame frame; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.recv_callback = scripted_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - - user_data.df = &df; - user_data.invalid_ctrl_recv_cb_called = 0; - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 1, 0, 3, dup_nv(nv)); - framelen = spdylay_frame_pack_syn_stream(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_stream, - &session->hd_deflater); - scripted_data_feed_init(&df, framedata, framelen); - spdylay_frame_syn_stream_free(&frame.syn_stream); - - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - - spdylay_frame_syn_reply_init(&frame.syn_reply, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 100, dup_nv(nv)); - framelen = spdylay_frame_pack_syn_reply(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_reply, - &session->hd_deflater); - scripted_data_feed_init(&df, framedata, framelen); - spdylay_frame_syn_reply_free(&frame.syn_reply); - - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); - - free(framedata); - free(nvbuf); - spdylay_session_del(session); -} - -void test_spdylay_session_on_syn_stream_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - const char *nv[] = { NULL }; - spdylay_frame frame; - spdylay_stream *stream; - int32_t stream_id = 1; - uint8_t pri = 3; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, - stream_id, 0, pri, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - stream = spdylay_session_get_stream(session, stream_id); - CU_ASSERT(SPDYLAY_STREAM_OPENING == stream->state); - CU_ASSERT(pri == stream->pri); - - /* Same stream ID twice leads stream error */ - user_data.invalid_ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - CU_ASSERT(SPDYLAY_STREAM_CLOSING == stream->state); - - /* assoc_stream_id != 0 from client is invalid. */ - frame.syn_stream.stream_id = 3; - frame.syn_stream.assoc_stream_id = 1; - user_data.invalid_ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - - - /* More than max concurrent streams leads REFUSED_STREAM */ - session->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, - 5, 0, 3, dup_nv(nv)); - user_data.invalid_ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - session->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = - SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS; - - /* Stream ID less than previouly received SYN_STREAM leads session - error */ - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, - 1, 0, 3, dup_nv(nv)); - user_data.invalid_ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - CU_ASSERT(session->goaway_flags & SPDYLAY_GOAWAY_FAIL_ON_SEND); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - - spdylay_session_del(session); -} - -void test_spdylay_session_on_syn_stream_received_with_push(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - const char *nv[] = { NULL }; - spdylay_frame frame; - spdylay_stream *stream; - int32_t stream_id = 2; - int32_t assoc_stream_id = 1; - uint8_t pri = 3; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_session_open_stream(session, assoc_stream_id, SPDYLAY_CTRL_FLAG_NONE, - pri, SPDYLAY_STREAM_OPENED, NULL); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL, - stream_id, assoc_stream_id, pri, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - stream = spdylay_session_get_stream(session, stream_id); - CU_ASSERT(SPDYLAY_STREAM_OPENING == stream->state); - - /* assoc_stream_id == 0 is invalid */ - frame.syn_stream.stream_id = 4; - frame.syn_stream.assoc_stream_id = 0; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - - /* Push without SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL is invalid */ - frame.syn_stream.stream_id = 6; - frame.syn_stream.assoc_stream_id = 1; - frame.syn_stream.hd.flags = SPDYLAY_CTRL_FLAG_FIN; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); - - /* Push to non-existent stream is invalid */ - frame.syn_stream.stream_id = 8; - frame.syn_stream.assoc_stream_id = 3; - frame.syn_stream.hd.flags = SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL; - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(3 == user_data.invalid_ctrl_recv_cb_called); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - spdylay_session_del(session); -} - -void test_spdylay_session_on_syn_reply_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - const char *nv[] = { NULL }; - spdylay_frame frame; - spdylay_stream *stream; - spdylay_outbound_item *item; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_frame_syn_reply_init(&frame.syn_reply, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 1, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_on_syn_reply_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - CU_ASSERT(SPDYLAY_STREAM_OPENED == - ((spdylay_stream*)spdylay_map_find(&session->streams, 1))->state); - - CU_ASSERT(0 == spdylay_session_on_syn_reply_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - CU_ASSERT(SPDYLAY_STREAM_CLOSING == - ((spdylay_stream*)spdylay_map_find(&session->streams, 1))->state); - - /* Check the situation when SYN_REPLY is received after peer sends - FIN */ - stream = spdylay_session_open_stream(session, 3, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENED, NULL); - spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD); - frame.syn_reply.stream_id = 3; - - CU_ASSERT(0 == spdylay_session_on_syn_reply_received(session, &frame)); - CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); - - spdylay_frame_syn_reply_free(&frame.syn_reply); - - spdylay_session_del(session); - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, - &user_data); - - /* Multiple SYN_REPLY frames for the same active stream ID */ - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENED, NULL); - spdylay_frame_syn_reply_init(&frame.syn_reply, SPDYLAY_PROTO_SPDY3, - SPDYLAY_CTRL_FLAG_NONE, 1, dup_nv(nv)); - user_data.invalid_ctrl_recv_cb_called = 0; - CU_ASSERT(0 == spdylay_session_on_syn_reply_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_STREAM_IN_USE == OB_CTRL(item)->rst_stream.status_code); - - spdylay_frame_syn_reply_free(&frame.syn_reply); - - spdylay_session_del(session); -} - -void test_spdylay_session_send_syn_stream(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - spdylay_frame *frame = malloc(sizeof(spdylay_frame)); - spdylay_stream *stream; - spdylay_syn_stream_aux_data *aux_data = - malloc(sizeof(spdylay_syn_stream_aux_data)); - memset(aux_data, 0, sizeof(spdylay_syn_stream_aux_data)); - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, NULL); - spdylay_frame_syn_stream_init(&frame->syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 0, 0, 3, dup_nv(nv)); - spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, aux_data); - CU_ASSERT(0 == spdylay_session_send(session)); - stream = spdylay_session_get_stream(session, 1); - CU_ASSERT(SPDYLAY_STREAM_OPENING == stream->state); - - spdylay_session_del(session); -} - -void test_spdylay_session_send_syn_reply(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - spdylay_frame *frame = malloc(sizeof(spdylay_frame)); - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, NULL)); - spdylay_session_open_stream(session, 2, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_frame_syn_reply_init(&frame->syn_reply, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 2, dup_nv(nv)); - spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); - CU_ASSERT(0 == spdylay_session_send(session)); - stream = spdylay_session_get_stream(session, 2); - CU_ASSERT(SPDYLAY_STREAM_OPENED == stream->state); - - spdylay_session_del(session); -} - -void test_spdylay_submit_response(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { "Content-Length", "1024", NULL }; - int32_t stream_id = 2; - spdylay_data_provider data_prd; - my_user_data ud; - spdylay_outbound_item *item; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - data_prd.read_callback = fixed_length_data_source_read_callback; - ud.data_source_length = 64*1024; - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - spdylay_session_open_stream(session, stream_id, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - CU_ASSERT(0 == spdylay_submit_response(session, stream_id, nv, &data_prd)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp("content-length", OB_CTRL(item)->syn_reply.nv[0])); - CU_ASSERT(0 == spdylay_session_send(session)); - spdylay_session_del(session); -} - -void test_spdylay_submit_response_with_null_data_read_callback(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - accumulator acc; - const char *nv[] = { ":Version", "HTTP/1.1", NULL }; - spdylay_data_provider data_prd = {{-1}, NULL}; - spdylay_outbound_item *item; - my_user_data ud; - spdylay_frame frame; - - acc.length = 0; - ud.acc = &acc; - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_FIN, 3, - SPDYLAY_STREAM_OPENING, NULL); - CU_ASSERT(0 == spdylay_submit_response(session, 1, nv, &data_prd)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->syn_reply.nv[0])); - CU_ASSERT(OB_CTRL(item)->syn_reply.hd.flags & SPDYLAY_CTRL_FLAG_FIN); - - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == unpack_frame_with_nv_block(SPDYLAY_SYN_REPLY, - SPDYLAY_PROTO_SPDY2, - &frame, - &session->hd_inflater, - acc.buf, acc.length)); - CU_ASSERT(0 == strcmp("version", frame.syn_reply.nv[0])); - spdylay_frame_syn_reply_free(&frame.syn_reply); - - spdylay_session_del(session); -} - -void test_spdylay_submit_request_with_data(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { "Version", "HTTP/1.1", NULL }; - spdylay_data_provider data_prd; - my_user_data ud; - spdylay_outbound_item *item; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - data_prd.read_callback = fixed_length_data_source_read_callback; - ud.data_source_length = 64*1024; - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - CU_ASSERT(0 == spdylay_submit_request(session, 3, nv, &data_prd, NULL)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_stream.nv[0])); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); - - spdylay_session_del(session); -} - -void test_spdylay_submit_request_with_null_data_read_callback(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - accumulator acc; - const char *nv[] = { ":Version", "HTTP/1.1", NULL }; - spdylay_data_provider data_prd = {{-1}, NULL}; - spdylay_outbound_item *item; - my_user_data ud; - spdylay_frame frame; - - acc.length = 0; - ud.acc = &acc; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - CU_ASSERT(0 == spdylay_submit_request(session, 3, nv, &data_prd, NULL)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->syn_stream.nv[0])); - CU_ASSERT(OB_CTRL(item)->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN); - - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == unpack_frame_with_nv_block(SPDYLAY_SYN_STREAM, - SPDYLAY_PROTO_SPDY2, - &frame, - &session->hd_inflater, - acc.buf, acc.length)); - CU_ASSERT(0 == strcmp("version", frame.syn_stream.nv[0])); - spdylay_frame_syn_stream_free(&frame.syn_stream); - - spdylay_session_del(session); -} - -void test_spdylay_submit_syn_stream(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { "version", "HTTP/1.1", NULL }; - spdylay_outbound_item *item; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, NULL)); - CU_ASSERT(0 == spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_FIN, 1, 3, - nv, NULL)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_stream.nv[0])); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == OB_CTRL(item)->syn_stream.hd.flags); - /* See assoc-stream-ID is ignored */ - CU_ASSERT(0 == OB_CTRL(item)->syn_stream.assoc_stream_id); - CU_ASSERT(3 == OB_CTRL(item)->syn_stream.pri); - - spdylay_session_del(session); - - CU_ASSERT(0 == spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, NULL)); - CU_ASSERT(0 == spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_FIN, 1, 3, - nv, NULL)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_stream.nv[0])); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == OB_CTRL(item)->syn_stream.hd.flags); - CU_ASSERT(1 == OB_CTRL(item)->syn_stream.assoc_stream_id); - CU_ASSERT(3 == OB_CTRL(item)->syn_stream.pri); - - spdylay_session_del(session); -} - -void test_spdylay_submit_syn_reply(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { "version", "HTTP/1.1", NULL }; - my_user_data ud; - spdylay_outbound_item *item; - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - - CU_ASSERT(0 == spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - CU_ASSERT(0 == spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_FIN, 1, - nv)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp("version", OB_CTRL(item)->syn_reply.nv[0])); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == OB_CTRL(item)->syn_reply.hd.flags); - - ud.ctrl_send_cb_called = 0; - ud.sent_frame_type = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == ud.ctrl_send_cb_called); - - stream = spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - - CU_ASSERT(0 == spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_FIN, 1, - nv)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == ud.ctrl_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_REPLY == ud.sent_frame_type); - CU_ASSERT(stream->shut_flags & SPDYLAY_SHUT_WR); - - spdylay_session_del(session); -} - -void test_spdylay_submit_headers(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { ":Version", "HTTP/1.1", NULL }; - my_user_data ud; - spdylay_outbound_item *item; - spdylay_stream *stream; - accumulator acc; - spdylay_frame frame; - - acc.length = 0; - ud.acc = &acc; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - CU_ASSERT(0 == spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_FIN, 1, nv)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0])); - CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == OB_CTRL(item)->headers.hd.flags); - - ud.ctrl_send_cb_called = 0; - ud.sent_frame_type = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == ud.ctrl_send_cb_called); - - stream = spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - - CU_ASSERT(0 == spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_FIN, 1, nv)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == ud.ctrl_send_cb_called); - CU_ASSERT(SPDYLAY_HEADERS == ud.sent_frame_type); - CU_ASSERT(stream->shut_flags & SPDYLAY_SHUT_WR); - - CU_ASSERT(0 == unpack_frame_with_nv_block(SPDYLAY_HEADERS, - SPDYLAY_PROTO_SPDY2, - &frame, - &session->hd_inflater, - acc.buf, acc.length)); - CU_ASSERT(0 == strcmp("version", frame.headers.nv[0])); - spdylay_frame_headers_free(&frame.headers); - - spdylay_session_del(session); -} - -void test_spdylay_submit_invalid_nv(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, - &callbacks, NULL)); - - /* spdylay_submit_request */ - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_request(session, 3, empty_name_nv, NULL, NULL)); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_request(session, 3, null_val_nv, NULL, NULL)); - - /* spdylay_submit_response */ - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_response(session, 2, empty_name_nv, NULL)); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_response(session, 2, null_val_nv, NULL)); - - /* spdylay_submit_syn_stream */ - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_NONE, 0, - 0, empty_name_nv, NULL)); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_NONE, 0, - 0, null_val_nv, NULL)); - - /* spdylay_submit_syn_reply */ - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_NONE, 2, - empty_name_nv)); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_NONE, 2, - null_val_nv)); - - /* spdylay_submit_headers */ - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_NONE, 2, - empty_name_nv)); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_NONE, 2, - null_val_nv)); - - spdylay_session_del(session); -} - -void test_spdylay_session_reply_fail(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - int32_t stream_id = 2; - spdylay_data_provider data_prd; - my_user_data ud; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = fail_send_callback; - - data_prd.read_callback = fixed_length_data_source_read_callback; - ud.data_source_length = 4*1024; - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &ud)); - CU_ASSERT(0 == spdylay_submit_response(session, stream_id, nv, &data_prd)); - CU_ASSERT(0 == spdylay_session_send(session)); - spdylay_session_del(session); -} - -void test_spdylay_session_on_headers_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - const char *nv[] = { NULL }; - spdylay_frame frame; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENED, NULL); - spdylay_stream_shutdown(spdylay_session_get_stream(session, 1), - SPDYLAY_SHUT_WR); - spdylay_frame_headers_init(&frame.headers, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 1, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - CU_ASSERT(SPDYLAY_STREAM_OPENED == - spdylay_session_get_stream(session, 1)->state); - - frame.headers.hd.flags |= SPDYLAY_CTRL_FLAG_FIN; - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(2 == user_data.ctrl_recv_cb_called); - CU_ASSERT(NULL == spdylay_session_get_stream(session, 1)); - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - - /* Check to see when SPDYLAY_STREAM_CLOSING, incoming HEADERS is - discarded. */ - spdylay_session_open_stream(session, 3, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_CLOSING, NULL); - frame.headers.stream_id = 3; - frame.headers.hd.flags = SPDYLAY_CTRL_FLAG_NONE; - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(2 == user_data.ctrl_recv_cb_called); - CU_ASSERT(1 == user_data.invalid_ctrl_recv_cb_called); - - /* Server initiated stream */ - spdylay_session_open_stream(session, 2, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENING, NULL); - - frame.headers.hd.flags = SPDYLAY_CTRL_FLAG_FIN; - frame.headers.stream_id = 2; - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(3 == user_data.ctrl_recv_cb_called); - CU_ASSERT(SPDYLAY_STREAM_OPENING == - spdylay_session_get_stream(session, 2)->state); - CU_ASSERT(spdylay_session_get_stream(session, 2)->shut_flags & - SPDYLAY_SHUT_RD); - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(2 == user_data.invalid_ctrl_recv_cb_called); - - spdylay_frame_headers_free(&frame.headers); - - spdylay_session_del(session); -} - -void test_spdylay_session_on_window_update_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_frame frame; - spdylay_stream *stream; - spdylay_outbound_item *data_item; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, - &user_data); - stream = spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENED, NULL); - spdylay_frame_window_update_init(&frame.window_update, SPDYLAY_PROTO_SPDY3, - 1, 16*1024); - - CU_ASSERT(0 == spdylay_session_on_window_update_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - CU_ASSERT(64*1024+16*1024 == stream->window_size); - - data_item = malloc(sizeof(spdylay_outbound_item)); - memset(data_item, 0, sizeof(spdylay_outbound_item)); - data_item->frame_cat = SPDYLAY_DATA; - spdylay_stream_defer_data(stream, data_item, SPDYLAY_DEFERRED_FLOW_CONTROL); - - CU_ASSERT(0 == spdylay_session_on_window_update_received(session, &frame)); - CU_ASSERT(2 == user_data.ctrl_recv_cb_called); - CU_ASSERT(64*1024+16*1024*2 == stream->window_size); - CU_ASSERT(NULL == stream->deferred_data); - - spdylay_frame_window_update_free(&frame.window_update); - spdylay_session_del(session); -} - -void test_spdylay_session_on_ping_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_frame frame; - spdylay_outbound_item *top; - uint32_t unique_id; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - unique_id = 2; - spdylay_frame_ping_init(&frame.ping, SPDYLAY_PROTO_SPDY2, unique_id); - - CU_ASSERT(0 == spdylay_session_on_ping_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - top = spdylay_session_get_ob_pq_top(session); - CU_ASSERT(SPDYLAY_PING == OB_CTRL_TYPE(top)); - CU_ASSERT(unique_id == OB_CTRL(top)->ping.unique_id); - - session->last_ping_unique_id = 1; - frame.ping.unique_id = 1; - - CU_ASSERT(0 == spdylay_session_on_ping_received(session, &frame)); - CU_ASSERT(2 == user_data.ctrl_recv_cb_called); - - spdylay_frame_ping_free(&frame.ping); - spdylay_session_del(session); -} - -void test_spdylay_session_on_goaway_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_frame frame; - int32_t stream_id = 1000000007; - user_data.ctrl_recv_cb_called = 0; - user_data.invalid_ctrl_recv_cb_called = 0; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback; - callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_frame_goaway_init(&frame.goaway, SPDYLAY_PROTO_SPDY2, stream_id, - SPDYLAY_GOAWAY_OK); - - CU_ASSERT(0 == spdylay_session_on_goaway_received(session, &frame)); - CU_ASSERT(1 == user_data.ctrl_recv_cb_called); - CU_ASSERT(session->goaway_flags == SPDYLAY_GOAWAY_RECV); - - spdylay_frame_goaway_free(&frame.goaway); - spdylay_session_del(session); -} - -void test_spdylay_session_on_data_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_outbound_item *top; - int32_t stream_id = 2; - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - stream = spdylay_session_open_stream(session, stream_id, - SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - CU_ASSERT(0 == spdylay_session_on_data_received(session, - SPDYLAY_DATA_FLAG_NONE, - 4096, stream_id)); - CU_ASSERT(0 == stream->shut_flags); - - CU_ASSERT(0 == spdylay_session_on_data_received(session, - SPDYLAY_DATA_FLAG_FIN, - 4096, stream_id)); - CU_ASSERT(SPDYLAY_SHUT_RD == stream->shut_flags); - - /* If SPDYLAY_STREAM_CLOSING state, DATA frame is discarded. */ - stream_id = 4; - - spdylay_session_open_stream(session, stream_id, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_CLOSING, NULL); - CU_ASSERT(0 == spdylay_session_on_data_received(session, - SPDYLAY_DATA_FLAG_NONE, - 4096, stream_id)); - CU_ASSERT(NULL == spdylay_session_get_ob_pq_top(session)); - - /* Check INVALID_STREAM case: DATA frame with stream ID which does - not exist. */ - stream_id = 6; - - CU_ASSERT(0 == spdylay_session_on_data_received(session, - SPDYLAY_DATA_FLAG_NONE, - 4096, stream_id)); - top = spdylay_session_get_ob_pq_top(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(top)); - CU_ASSERT(SPDYLAY_INVALID_STREAM == OB_CTRL(top)->rst_stream.status_code); - - spdylay_session_del(session); -} - -void test_spdylay_session_is_my_stream_id(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, NULL); - - CU_ASSERT(0 == spdylay_session_is_my_stream_id(session, 0)); - CU_ASSERT(0 == spdylay_session_is_my_stream_id(session, 1)); - CU_ASSERT(1 == spdylay_session_is_my_stream_id(session, 2)); - - spdylay_session_del(session); - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, NULL); - - CU_ASSERT(0 == spdylay_session_is_my_stream_id(session, 0)); - CU_ASSERT(1 == spdylay_session_is_my_stream_id(session, 1)); - CU_ASSERT(0 == spdylay_session_is_my_stream_id(session, 2)); - - spdylay_session_del(session); -} - -void test_spdylay_session_on_rst_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_stream *stream; - spdylay_frame frame; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - stream = spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - /* server push */ - spdylay_session_open_stream(session, 2, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - spdylay_stream_add_pushed_stream(stream, 2); - spdylay_session_open_stream(session, 4, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - spdylay_stream_add_pushed_stream(stream, 4); - - spdylay_frame_rst_stream_init(&frame.rst_stream, SPDYLAY_PROTO_SPDY2, 1, - SPDYLAY_CANCEL); - - CU_ASSERT(0 == spdylay_session_on_rst_stream_received(session, &frame)); - - CU_ASSERT(NULL == spdylay_session_get_stream(session, 1)); - CU_ASSERT(NULL == spdylay_session_get_stream(session, 2)); - CU_ASSERT(NULL == spdylay_session_get_stream(session, 4)); - - spdylay_frame_rst_stream_free(&frame.rst_stream); - spdylay_session_del(session); -} - -void test_spdylay_session_send_rst_stream(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_stream *stream; - spdylay_frame *frame; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - stream = spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - /* server push */ - spdylay_session_open_stream(session, 2, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - spdylay_stream_add_pushed_stream(stream, 2); - spdylay_session_open_stream(session, 4, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - spdylay_stream_add_pushed_stream(stream, 4); - - frame = malloc(sizeof(spdylay_frame)); - spdylay_frame_rst_stream_init(&frame->rst_stream, SPDYLAY_PROTO_SPDY2, 1, - SPDYLAY_CANCEL); - spdylay_session_add_frame(session, SPDYLAY_CTRL, frame, NULL); - CU_ASSERT(0 == spdylay_session_send(session)); - - CU_ASSERT(NULL == spdylay_session_get_stream(session, 1)); - CU_ASSERT(NULL == spdylay_session_get_stream(session, 2)); - CU_ASSERT(NULL == spdylay_session_get_stream(session, 4)); - - spdylay_session_del(session); -} - -void test_spdylay_session_get_next_ob_item(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, NULL); - session->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 2; - - CU_ASSERT(NULL == spdylay_session_get_next_ob_item(session)); - spdylay_submit_ping(session); - CU_ASSERT(SPDYLAY_PING == - OB_CTRL_TYPE(spdylay_session_get_next_ob_item(session))); - - spdylay_submit_request(session, 0, nv, NULL, NULL); - CU_ASSERT(SPDYLAY_PING == - OB_CTRL_TYPE(spdylay_session_get_next_ob_item(session))); - - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(NULL == spdylay_session_get_next_ob_item(session)); - - /* Incoming stream does not affect the number of outgoing max - concurrent streams. */ - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - - spdylay_submit_request(session, 0, nv, NULL, NULL); - CU_ASSERT(SPDYLAY_SYN_STREAM == - OB_CTRL_TYPE(spdylay_session_get_next_ob_item(session))); - CU_ASSERT(0 == spdylay_session_send(session)); - - spdylay_submit_request(session, 0, nv, NULL, NULL); - CU_ASSERT(NULL == spdylay_session_get_next_ob_item(session)); - - session->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 3; - - CU_ASSERT(SPDYLAY_SYN_STREAM == - OB_CTRL_TYPE(spdylay_session_get_next_ob_item(session))); - - spdylay_session_del(session); -} - -void test_spdylay_session_pop_next_ob_item(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - spdylay_outbound_item *item; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, NULL); - session->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; - - CU_ASSERT(NULL == spdylay_session_pop_next_ob_item(session)); - spdylay_submit_ping(session); - spdylay_submit_request(session, 1, nv, NULL, NULL); - - item = spdylay_session_pop_next_ob_item(session); - CU_ASSERT(SPDYLAY_PING == OB_CTRL_TYPE(item)); - spdylay_outbound_item_free(item); - free(item); - - item = spdylay_session_pop_next_ob_item(session); - CU_ASSERT(SPDYLAY_SYN_STREAM == OB_CTRL_TYPE(item)); - spdylay_outbound_item_free(item); - free(item); - - CU_ASSERT(NULL == spdylay_session_pop_next_ob_item(session)); - - /* Incoming stream does not affect the number of outgoing max - concurrent streams. */ - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - - /* In-flight outgoing stream */ - spdylay_session_open_stream(session, 4, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - - spdylay_submit_request(session, 0, nv, NULL, NULL); - spdylay_submit_response(session, 1, nv, NULL); - - item = spdylay_session_pop_next_ob_item(session); - CU_ASSERT(SPDYLAY_SYN_REPLY == OB_CTRL_TYPE(item)); - spdylay_outbound_item_free(item); - free(item); - - CU_ASSERT(NULL == spdylay_session_pop_next_ob_item(session)); - - session->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 2; - - item = spdylay_session_pop_next_ob_item(session); - CU_ASSERT(SPDYLAY_SYN_STREAM == OB_CTRL_TYPE(item)); - spdylay_outbound_item_free(item); - free(item); - - spdylay_session_del(session); -} - -void test_spdylay_session_on_request_recv_callback(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - const char *nv[] = { NULL }; - spdylay_frame frame; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_request_recv_callback = on_request_recv_callback; - user_data.stream_id = 0; - - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 1, 0, 3, dup_nv(nv)); - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(0 == user_data.stream_id); - - frame.syn_stream.stream_id = 3; - frame.syn_stream.hd.flags |= SPDYLAY_CTRL_FLAG_FIN; - - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(3 == user_data.stream_id); - - user_data.stream_id = 0; - - frame.syn_stream.stream_id = 0; - - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - CU_ASSERT(0 == user_data.stream_id); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - - user_data.stream_id = 0; - - spdylay_session_open_stream(session, 5, SPDYLAY_CTRL_FLAG_NONE, 0, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_frame_headers_init(&frame.headers, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 5, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.stream_id); - - frame.headers.hd.flags |= SPDYLAY_CTRL_FLAG_FIN; - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(5 == user_data.stream_id); - - user_data.stream_id = 0; - - CU_ASSERT(0 == spdylay_session_on_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.stream_id); - - spdylay_frame_headers_free(&frame.headers); - spdylay_session_del(session); -} - -static void stream_close_callback(spdylay_session *session, int32_t stream_id, - spdylay_status_code status_code, - void *user_data) -{ - my_user_data* my_data = (my_user_data*)user_data; - void *stream_data = spdylay_session_get_stream_user_data(session, stream_id); - ++my_data->stream_close_cb_called; - CU_ASSERT(stream_data != NULL); -} - -void test_spdylay_session_on_stream_close(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_stream *stream; - int32_t stream_id = 1; - uint8_t pri = 3; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_stream_close_callback = stream_close_callback; - user_data.stream_close_cb_called = 0; - - CU_ASSERT(spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &user_data) == 0); - stream = spdylay_session_open_stream(session, stream_id, - SPDYLAY_CTRL_FLAG_NONE, - pri, SPDYLAY_STREAM_OPENED, &user_data); - CU_ASSERT(stream != NULL); - CU_ASSERT(spdylay_session_close_stream(session, stream_id, SPDYLAY_OK) == 0); - CU_ASSERT(user_data.stream_close_cb_called == 1); - spdylay_session_del(session); -} - -void test_spdylay_session_max_concurrent_streams(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - spdylay_frame frame; - const char *nv[] = { NULL }; - spdylay_outbound_item *item; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, NULL); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENED, NULL); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 3, 0, 3, dup_nv(nv)); - session->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS] = 1; - - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - - item = spdylay_session_get_ob_pq_top(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_REFUSED_STREAM == OB_CTRL(item)->rst_stream.status_code) - - spdylay_frame_syn_stream_free(&frame.syn_stream); - - spdylay_session_del(session); -} - -static ssize_t block_count_send_callback(spdylay_session* session, - const uint8_t *data, size_t len, - int flags, - void *user_data) -{ - my_user_data *ud = (my_user_data*)user_data; - int r; - if(ud->block_count == 0) { - r = SPDYLAY_ERR_WOULDBLOCK; - } else { - --ud->block_count; - r = len; - } - return r; -} - -void test_spdylay_session_data_backoff_by_high_pri_frame(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - my_user_data ud; - spdylay_data_provider data_prd; - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = block_count_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - data_prd.read_callback = fixed_length_data_source_read_callback; - - ud.ctrl_send_cb_called = 0; - ud.data_source_length = 16*1024; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, &ud); - spdylay_submit_request(session, 3, nv, &data_prd, NULL); - - ud.block_count = 2; - /* Sends SYN_STREAM + DATA[0] */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(SPDYLAY_SYN_STREAM == ud.sent_frame_type); - /* data for DATA[1] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == 8*1024); - - spdylay_submit_ping(session); - ud.block_count = 2; - /* Sends DATA[1] + PING, PING is interleaved in DATA sequence */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(SPDYLAY_PING == ud.sent_frame_type); - /* data for DATA[2] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == 4*1024); - - ud.block_count = 2; - /* Sends DATA[2..3] */ - CU_ASSERT(0 == spdylay_session_send(session)); - - stream = spdylay_session_get_stream(session, 1); - CU_ASSERT(stream->shut_flags & SPDYLAY_SHUT_WR); - - spdylay_session_del(session); -} - -void test_spdylay_session_stop_data_with_rst_stream(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - my_user_data ud; - spdylay_data_provider data_prd; - spdylay_frame frame; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - callbacks.send_callback = block_count_send_callback; - data_prd.read_callback = fixed_length_data_source_read_callback; - - ud.ctrl_send_cb_called = 0; - ud.data_source_length = 16*1024; - - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, &ud); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_submit_response(session, 1, nv, &data_prd); - - ud.block_count = 2; - /* Sends SYN_REPLY + DATA[0] */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(SPDYLAY_SYN_REPLY == ud.sent_frame_type); - /* data for DATA[1] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == 8*1024); - - spdylay_frame_rst_stream_init(&frame.rst_stream, SPDYLAY_PROTO_SPDY2, 1, - SPDYLAY_CANCEL); - CU_ASSERT(0 == spdylay_session_on_rst_stream_received(session, &frame)); - spdylay_frame_rst_stream_free(&frame.rst_stream); - - /* Big enough number to send all DATA frames potentially. */ - ud.block_count = 100; - /* Nothing will be sent in the following call. */ - CU_ASSERT(0 == spdylay_session_send(session)); - /* With RST_STREAM, stream is canceled and further DATA on that - stream are not sent. */ - CU_ASSERT(ud.data_source_length == 8*1024); - - CU_ASSERT(NULL == spdylay_session_get_stream(session, 1)); - - spdylay_session_del(session); -} - -/* - * Check that on_stream_close_callback is called when server pushed - * SYN_STREAM have SPDYLAY_CTRL_FLAG_FIN. - */ -void test_spdylay_session_stream_close_on_syn_stream(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - my_user_data ud; - spdylay_frame frame; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_stream_close_callback = - no_stream_user_data_stream_close_callback; - ud.stream_close_cb_called = 0; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, &ud); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_FIN | - SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL, - 2, 1, 3, dup_nv(nv)); - - CU_ASSERT(0 == spdylay_session_on_syn_stream_received(session, &frame)); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - spdylay_session_del(session); -} - -void test_spdylay_session_recv_invalid_frame(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - scripted_data_feed df; - my_user_data user_data; - const char *nv[] = { - "url", "/", NULL - }; - uint8_t *framedata = NULL, *nvbuf = NULL; - size_t framedatalen = 0, nvbuflen = 0; - ssize_t framelen; - spdylay_frame frame; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.recv_callback = scripted_recv_callback; - callbacks.send_callback = null_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - - user_data.df = &df; - user_data.ctrl_send_cb_called = 0; - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, - &user_data); - spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY2, - SPDYLAY_CTRL_FLAG_NONE, 1, 0, 3, dup_nv(nv)); - framelen = spdylay_frame_pack_syn_stream(&framedata, &framedatalen, - &nvbuf, &nvbuflen, - &frame.syn_stream, - &session->hd_deflater); - scripted_data_feed_init(&df, framedata, framelen); - - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == user_data.ctrl_send_cb_called); - - /* Receive exactly same bytes of SYN_STREAM causes error */ - scripted_data_feed_init(&df, framedata, framelen); - - CU_ASSERT(0 == spdylay_session_recv(session)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_send_cb_called); - CU_ASSERT(SPDYLAY_GOAWAY == user_data.sent_frame_type); - - free(framedata); - free(nvbuf); - spdylay_frame_syn_stream_free(&frame.syn_stream); - - spdylay_session_del(session); -} - -static ssize_t defer_data_source_read_callback -(spdylay_session *session, int32_t stream_id, - uint8_t *buf, size_t len, int *eof, - spdylay_data_source *source, void *user_data) -{ - return SPDYLAY_ERR_DEFERRED; -} - -void test_spdylay_session_defer_data(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - my_user_data ud; - spdylay_data_provider data_prd; - spdylay_outbound_item *item; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - callbacks.send_callback = block_count_send_callback; - data_prd.read_callback = defer_data_source_read_callback; - - ud.ctrl_send_cb_called = 0; - ud.data_source_length = 16*1024; - - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, &callbacks, &ud); - spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENING, NULL); - spdylay_submit_response(session, 1, nv, &data_prd); - - ud.block_count = 1; - /* Sends SYN_REPLY */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(SPDYLAY_SYN_REPLY == ud.sent_frame_type); - /* No data is read */ - CU_ASSERT(ud.data_source_length == 16*1024); - - ud.block_count = 1; - spdylay_submit_ping(session); - /* Sends PING */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(SPDYLAY_PING == ud.sent_frame_type); - - /* Resume deferred DATA */ - CU_ASSERT(0 == spdylay_session_resume_data(session, 1)); - item = spdylay_session_get_ob_pq_top(session); - OB_DATA(item)->data_prd.read_callback = - fixed_length_data_source_read_callback; - ud.block_count = 1; - /* Reads 2 4KiB blocks */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(ud.data_source_length == 8*1024); - - /* Deferred again */ - OB_DATA(item)->data_prd.read_callback = defer_data_source_read_callback; - /* This is needed since 4KiB block is already read and waiting to be - sent. No read_callback invocation. */ - ud.block_count = 1; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(ud.data_source_length == 8*1024); - - /* Resume deferred DATA */ - - CU_ASSERT(0 == spdylay_session_resume_data(session, 1)); - item = spdylay_session_get_ob_pq_top(session); - OB_DATA(item)->data_prd.read_callback = - fixed_length_data_source_read_callback; - ud.block_count = 1; - /* Reads 2 4KiB blocks */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(ud.data_source_length == 0); - - spdylay_session_del(session); -} - -void test_spdylay_session_flow_control(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - my_user_data ud; - spdylay_data_provider data_prd; - spdylay_frame frame; - spdylay_stream *stream; - int32_t new_initial_window_size; - spdylay_settings_entry iv[1]; - spdylay_frame settings_frame; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - data_prd.read_callback = fixed_length_data_source_read_callback; - - ud.ctrl_send_cb_called = 0; - ud.data_source_length = 128*1024; - - /* Initial window size is 64KiB */ - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, &ud); - spdylay_submit_request(session, 3, nv, &data_prd, NULL); - - /* Sends 64KiB data */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(64*1024 == ud.data_source_length); - - /* Back 32KiB */ - spdylay_frame_window_update_init(&frame.window_update, SPDYLAY_PROTO_SPDY3, - 1, 32*1024); - spdylay_session_on_window_update_received(session, &frame); - - /* Sends another 32KiB data */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(32*1024 == ud.data_source_length); - - stream = spdylay_session_get_stream(session, 1); - /* Change initial window size to 16KiB. The window_size becomes - negative. */ - new_initial_window_size = 16*1024; - stream->window_size = new_initial_window_size- - (session->remote_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE] - -stream->window_size); - session->remote_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE] = - new_initial_window_size; - CU_ASSERT(-48*1024 == stream->window_size); - - /* Back 48KiB */ - frame.window_update.delta_window_size = 48*1024; - spdylay_session_on_window_update_received(session, &frame); - - /* Nothing is sent because window_size is less than 0 */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(32*1024 == ud.data_source_length); - - /* Back 16KiB */ - frame.window_update.delta_window_size = 16*1024; - spdylay_session_on_window_update_received(session, &frame); - - /* Sends another 16KiB data */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(16*1024 == ud.data_source_length); - - /* Increase initial window size to 32KiB */ - iv[0].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - iv[0].value = 32*1024; - - spdylay_frame_settings_init(&settings_frame.settings, SPDYLAY_PROTO_SPDY3, - SPDYLAY_FLAG_SETTINGS_NONE, dup_iv(iv, 1), 1); - spdylay_session_on_settings_received(session, &settings_frame); - spdylay_frame_settings_free(&settings_frame.settings); - - /* Sends another 16KiB data */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); - CU_ASSERT(spdylay_session_get_stream(session, 1)->shut_flags & - SPDYLAY_SHUT_WR); - - spdylay_frame_window_update_free(&frame.window_update); - spdylay_session_del(session); -} - -void test_spdylay_session_on_ctrl_not_send(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_stream *stream; - const char *nv[] = { NULL }; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.on_ctrl_not_send_callback = on_ctrl_not_send_callback; - callbacks.send_callback = null_send_callback; - user_data.ctrl_not_send_cb_called = 0; - user_data.not_sent_frame_type = 0; - user_data.not_sent_error = 0; - - CU_ASSERT(spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &user_data) == 0); - stream = spdylay_session_open_stream(session, 1, - SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENED, &user_data); - /* Check SYN_STREAM */ - CU_ASSERT(0 == spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_FIN, 3, 3, - nv, NULL)); - - user_data.ctrl_not_send_cb_called = 0; - /* Associated stream closed */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_STREAM == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_STREAM_CLOSED == user_data.not_sent_error); - - /* Check SYN_REPLY */ - CU_ASSERT(0 == - spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_FIN, 1, nv)); - user_data.ctrl_not_send_cb_called = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_REPLY == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_INVALID_STREAM_STATE == user_data.not_sent_error); - - stream->state = SPDYLAY_STREAM_OPENING; - user_data.ctrl_not_send_cb_called = 0; - /* Send bogus stream ID */ - CU_ASSERT(0 == - spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_FIN, 3, nv)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_REPLY == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_STREAM_CLOSED == user_data.not_sent_error); - - user_data.ctrl_not_send_cb_called = 0; - /* Shutdown transmission */ - stream->shut_flags |= SPDYLAY_SHUT_WR; - CU_ASSERT(0 == - spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_FIN, 1, nv)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_REPLY == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_STREAM_SHUT_WR == user_data.not_sent_error); - - stream->shut_flags = SPDYLAY_SHUT_NONE; - user_data.ctrl_not_send_cb_called = 0; - /* Queue RST_STREAM */ - CU_ASSERT(0 == - spdylay_submit_syn_reply(session, SPDYLAY_CTRL_FLAG_FIN, 1, nv)); - CU_ASSERT(0 == spdylay_submit_rst_stream(session, 1, SPDYLAY_INTERNAL_ERROR)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_REPLY == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_STREAM_CLOSING == user_data.not_sent_error); - - stream = spdylay_session_open_stream(session, 3, - SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENED, &user_data); - - /* Check HEADERS */ - user_data.ctrl_not_send_cb_called = 0; - stream->state = SPDYLAY_STREAM_OPENING; - CU_ASSERT(0 == - spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_FIN, 3, nv)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_INVALID_STREAM_STATE == user_data.not_sent_error); - - stream->state = SPDYLAY_STREAM_OPENED; - user_data.ctrl_not_send_cb_called = 0; - /* Queue RST_STREAM */ - CU_ASSERT(0 == - spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_FIN, 3, nv)); - CU_ASSERT(0 == spdylay_submit_rst_stream(session, 3, SPDYLAY_INTERNAL_ERROR)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_STREAM_CLOSING == user_data.not_sent_error); - - spdylay_session_del(session); - - /* Check SYN_STREAM */ - user_data.ctrl_not_send_cb_called = 0; - CU_ASSERT(spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY2, - &callbacks, &user_data) == 0); - /* Maximum Stream ID is reached */ - session->next_stream_id = (1u << 31)+1; - CU_ASSERT(0 == spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_FIN, 0, - 3, nv, NULL)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_STREAM == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_STREAM_ID_NOT_AVAILABLE == user_data.not_sent_error); - - session->next_stream_id = 1; - user_data.ctrl_not_send_cb_called = 0; - /* Send GOAWAY */ - CU_ASSERT(0 == spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK)); - CU_ASSERT(0 == spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_FIN, 0, - 3, nv, NULL)); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == user_data.ctrl_not_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_STREAM == user_data.not_sent_frame_type); - CU_ASSERT(SPDYLAY_ERR_SYN_STREAM_NOT_ALLOWED == user_data.not_sent_error); - - spdylay_session_del(session); -} - -void test_spdylay_session_on_settings_received(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data user_data; - spdylay_stream *stream1, *stream2; - spdylay_frame frame; - const size_t niv = 5; - spdylay_settings_entry iv[255]; - - iv[0].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[0].value = 1000000009; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[1].value = 50; - iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - iv[2].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; - iv[2].value = 64*1024; - iv[2].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - iv[3].settings_id = SPDYLAY_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE; - iv[3].value = 512; - iv[3].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - iv[4].settings_id = 999; - iv[4].value = 0; - iv[4].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, - &user_data); - session->remote_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE] = 16*1024; - - stream1 = spdylay_session_open_stream(session, 1, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - stream2 = spdylay_session_open_stream(session, 2, SPDYLAY_CTRL_FLAG_NONE, - 3, SPDYLAY_STREAM_OPENING, NULL); - stream1->window_size = 16*1024; - stream2->window_size = -48*1024; - - spdylay_frame_settings_init(&frame.settings, SPDYLAY_PROTO_SPDY3, - SPDYLAY_FLAG_SETTINGS_NONE, dup_iv(iv, niv), niv); - - CU_ASSERT(0 == spdylay_session_on_settings_received(session, &frame)); - - CU_ASSERT(1000000009 == - session->remote_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]); - CU_ASSERT(64*1024 == - session->remote_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE]); - /* We limit certificate vector in reasonable size. */ - CU_ASSERT(SPDYLAY_MAX_CLIENT_CERT_VECTOR_LENGTH == - session->remote_settings - [SPDYLAY_SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE]); - CU_ASSERT(SPDYLAY_MAX_CLIENT_CERT_VECTOR_LENGTH == session->cli_certvec.size); - CU_ASSERT(64*1024 == stream1->window_size); - CU_ASSERT(0 == stream2->window_size); - - frame.settings.iv[2].value = 16*1024; - - CU_ASSERT(0 == spdylay_session_on_settings_received(session, &frame)); - - CU_ASSERT(16*1024 == stream1->window_size); - CU_ASSERT(-48*1024 == stream2->window_size); - - spdylay_frame_settings_free(&frame.settings); - - spdylay_session_del(session); -} - -void test_spdylay_submit_settings(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data ud; - spdylay_outbound_item *item; - spdylay_frame *frame; - spdylay_settings_entry iv[3]; - - iv[0].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[0].value = 50; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - iv[1].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; - iv[1].value = 16*1024; - iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - /* This is duplicate entry */ - iv[2].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[2].value = 150; - iv[2].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, &ud); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_settings(session, SPDYLAY_FLAG_SETTINGS_NONE, - iv, 3)); - - /* Make sure that local settings are not changed */ - CU_ASSERT(SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS == - session->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]); - CU_ASSERT(SPDYLAY_INITIAL_WINDOW_SIZE == - session->local_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE]); - - CU_ASSERT(0 == spdylay_submit_settings(session, - SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS, - iv, 2)); - - /* Make sure that local settings are changed */ - CU_ASSERT(50 == - session->local_settings[SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS]); - CU_ASSERT(16*1024 == - session->local_settings[SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE]); - - item = spdylay_session_get_next_ob_item(session); - - CU_ASSERT(SPDYLAY_SETTINGS == OB_CTRL_TYPE(item)); - - frame = item->frame; - CU_ASSERT(2 == frame->settings.niv); - CU_ASSERT(SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS == frame->settings.hd.flags); - - CU_ASSERT(50 == frame->settings.iv[0].value); - CU_ASSERT(SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS == - frame->settings.iv[0].settings_id); - CU_ASSERT(SPDYLAY_FLAG_SETTINGS_NONE == - frame->settings.iv[0].flags); - - CU_ASSERT(16*1024 == frame->settings.iv[1].value); - CU_ASSERT(SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE == - frame->settings.iv[1].settings_id); - CU_ASSERT(SPDYLAY_FLAG_SETTINGS_NONE == - frame->settings.iv[1].flags); - - ud.ctrl_send_cb_called = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == ud.ctrl_send_cb_called); - - spdylay_session_del(session); -} - -void test_spdylay_session_get_outbound_queue_size(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { "version", "HTTP/1.1", NULL }; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, - &callbacks, NULL)); - CU_ASSERT(0 == spdylay_session_get_outbound_queue_size(session)); - - CU_ASSERT(0 == spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_FIN, 1, 7, - nv, NULL)); - CU_ASSERT(1 == spdylay_session_get_outbound_queue_size(session)); - - CU_ASSERT(0 == spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK)); - CU_ASSERT(2 == spdylay_session_get_outbound_queue_size(session)); - - spdylay_session_del(session); -} - -static ssize_t get_credential_ncerts(spdylay_session *session, - const spdylay_origin *origin, - void *user_data) -{ - if(strcmp("example.org", origin->host) == 0 && - strcmp("https", origin->scheme) == 0 && - 443 == origin->port) { - return 2; - } else { - return 0; - } -} - -static ssize_t get_credential_cert(spdylay_session *session, - const spdylay_origin *origin, - size_t idx, - uint8_t *cert, size_t certlen, - void *user_data) -{ - size_t len = strlen(origin->host); - if(certlen == 0) { - return len; - } else { - assert(certlen == len); - memcpy(cert, origin->host, len); - return 0; - } -} - -static ssize_t get_credential_proof(spdylay_session *session, - const spdylay_origin *origin, - uint8_t *proof, size_t prooflen, - void *uer_data) -{ - size_t len = strlen(origin->scheme); - if(prooflen == 0) { - return len; - } else { - assert(prooflen == len); - memcpy(proof, origin->scheme, len); - return 0; - } -} - -void test_spdylay_session_prep_credential(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { ":host", "example.org", - ":scheme", "https", - NULL }; - const char *nv_nocert[] = { ":host", "nocert", - ":scheme", "https", - NULL }; - spdylay_frame frame, *cred_frame; - spdylay_outbound_item *item; - size_t i; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.get_credential_ncerts = get_credential_ncerts; - callbacks.get_credential_cert = get_credential_cert; - callbacks.get_credential_proof = get_credential_proof; - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, - &callbacks, NULL)); - spdylay_frame_syn_stream_init(&frame.syn_stream, session->version, - SPDYLAY_CTRL_FLAG_NONE, 1, 0, 0, - dup_nv(nv)); - CU_ASSERT(SPDYLAY_ERR_CREDENTIAL_PENDING == - spdylay_session_prep_credential(session, &frame.syn_stream)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_CREDENTIAL == OB_CTRL_TYPE(item)); - CU_ASSERT(SPDYLAY_OB_PRI_CREDENTIAL == item->pri); - cred_frame = OB_CTRL(item); - CU_ASSERT(strlen("https") == cred_frame->credential.proof.length); - CU_ASSERT(memcmp("https", cred_frame->credential.proof.data, - cred_frame->credential.proof.length) == 0); - CU_ASSERT(2 == cred_frame->credential.ncerts); - for(i = 0; i < cred_frame->credential.ncerts; ++i) { - CU_ASSERT(strlen("example.org") == cred_frame->credential.certs[i].length); - CU_ASSERT(memcmp("example.org", cred_frame->credential.certs[i].data, - cred_frame->credential.certs[i].length) == 0); - } - /* Next spdylay_session_get_next_ob_item() call returns slot index */ - CU_ASSERT(1 == spdylay_session_prep_credential(session, &frame.syn_stream)); - - spdylay_frame_syn_stream_free(&frame.syn_stream); - - spdylay_frame_syn_stream_init(&frame.syn_stream, session->version, - SPDYLAY_CTRL_FLAG_NONE, 1, 0, 0, - dup_nv(nv_nocert)); - CU_ASSERT(0 == spdylay_session_prep_credential(session, &frame.syn_stream)); - spdylay_frame_syn_stream_free(&frame.syn_stream); - - spdylay_session_del(session); -} - -void test_spdylay_submit_syn_stream_with_credential(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { ":host", "example.org", - ":scheme", "https", - NULL }; - my_user_data ud; - accumulator acc; - - ud.acc = &acc; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = block_count_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - callbacks.get_credential_ncerts = get_credential_ncerts; - callbacks.get_credential_cert = get_credential_cert; - callbacks.get_credential_proof = get_credential_proof; - - CU_ASSERT(0 == spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, - &callbacks, &ud)); - - CU_ASSERT(0 == spdylay_submit_request(session, 0, nv, NULL, NULL)); - - ud.block_count = 1; - ud.ctrl_send_cb_called = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - - CU_ASSERT(1 == ud.ctrl_send_cb_called); - CU_ASSERT(SPDYLAY_CREDENTIAL == ud.sent_frame_type); - - session->callbacks.send_callback = accumulator_send_callback; - acc.length = 0; - ud.ctrl_send_cb_called = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(1 == ud.ctrl_send_cb_called); - CU_ASSERT(SPDYLAY_SYN_STREAM == ud.sent_frame_type); - /* Check slot */ - CU_ASSERT(1 == acc.buf[17]); - - spdylay_session_del(session); -} - -void test_spdylay_session_set_initial_client_cert_origin(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const spdylay_origin *origin; - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, NULL); - CU_ASSERT(0 == spdylay_session_set_initial_client_cert_origin - (session, "https", "example.org", 443)); - origin = spdylay_session_get_client_cert_origin(session, 1); - CU_ASSERT(NULL != origin); - CU_ASSERT(strcmp("https", spdylay_origin_get_scheme(origin)) == 0); - CU_ASSERT(strcmp("example.org", spdylay_origin_get_host(origin)) == 0); - CU_ASSERT(443 == spdylay_origin_get_port(origin)); - - spdylay_session_del(session); -} - -void test_spdylay_session_set_option(void) -{ - spdylay_session* session; - spdylay_session_callbacks callbacks; - int intval; - char charval; - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, NULL); - - intval = 1; - CU_ASSERT(0 == - spdylay_session_set_option(session, - SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE, - &intval, sizeof(intval))); - CU_ASSERT(session->opt_flags & SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE); - - intval = 0; - CU_ASSERT(0 == - spdylay_session_set_option(session, - SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE, - &intval, sizeof(intval))); - CU_ASSERT((session->opt_flags & SPDYLAY_OPTMASK_NO_AUTO_WINDOW_UPDATE) == 0); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_session_set_option(session, 0, /* 0 is invalid optname */ - &intval, sizeof(intval))); - - charval = 1; - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_session_set_option(session, - SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE, - &charval, sizeof(charval))); - - spdylay_session_del(session); -} - -void test_spdylay_submit_window_update(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - int32_t stream_id = 2; - my_user_data ud; - spdylay_outbound_item *item; - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, - &callbacks, &ud); - stream = spdylay_session_open_stream(session, stream_id, - SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_OPENED, NULL); - stream->recv_window_size = 4096; - - CU_ASSERT(0 == spdylay_submit_window_update(session, stream_id, 1024)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_WINDOW_UPDATE == OB_CTRL_TYPE(item)); - CU_ASSERT(1024 == OB_CTRL(item)->window_update.delta_window_size); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(3072 == stream->recv_window_size); - - CU_ASSERT(0 == spdylay_submit_window_update(session, stream_id, 4096)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_WINDOW_UPDATE == OB_CTRL_TYPE(item)); - CU_ASSERT(4096 == OB_CTRL(item)->window_update.delta_window_size); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == stream->recv_window_size); - - CU_ASSERT(0 == spdylay_submit_window_update(session, stream_id, 4096)); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_WINDOW_UPDATE == OB_CTRL_TYPE(item)); - CU_ASSERT(4096 == OB_CTRL(item)->window_update.delta_window_size); - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(0 == stream->recv_window_size); - - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_window_update(session, stream_id, 0)); - CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == - spdylay_submit_window_update(session, stream_id, -1)); - CU_ASSERT(SPDYLAY_ERR_STREAM_CLOSED == - spdylay_submit_window_update(session, 4, 4096)); - - spdylay_session_del(session); -} - -void test_spdylay_session_data_read_temporal_failure(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - const char *nv[] = { NULL }; - my_user_data ud; - spdylay_data_provider data_prd; - spdylay_frame frame; - spdylay_data *data_frame; - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.on_ctrl_send_callback = on_ctrl_send_callback; - data_prd.read_callback = fixed_length_data_source_read_callback; - - ud.data_source_length = 128*1024; - - /* Initial window size is 64KiB */ - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, &ud); - spdylay_submit_request(session, 3, nv, &data_prd, NULL); - - /* Sends 64KiB data */ - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(64*1024 == ud.data_source_length); - - stream = spdylay_session_get_stream(session, 1); - CU_ASSERT(NULL != stream->deferred_data); - CU_ASSERT(SPDYLAY_DATA == stream->deferred_data->frame_cat); - data_frame = (spdylay_data*)stream->deferred_data->frame; - data_frame->data_prd.read_callback = - temporal_failure_data_source_read_callback; - - /* Back 64KiB */ - spdylay_frame_window_update_init(&frame.window_update, SPDYLAY_PROTO_SPDY3, - 1, 64*1024); - spdylay_session_on_window_update_received(session, &frame); - spdylay_frame_window_update_free(&frame.window_update); - - /* Sending data will fail */ - ud.ctrl_send_cb_called = 0; - CU_ASSERT(0 == spdylay_session_send(session)); - CU_ASSERT(64*1024 == ud.data_source_length); - - CU_ASSERT(1 == ud.ctrl_send_cb_called); - CU_ASSERT(SPDYLAY_RST_STREAM == ud.sent_frame_type); - - data_prd.read_callback = fail_data_source_read_callback; - spdylay_submit_request(session, 3, nv, &data_prd, NULL); - /* Sending data will fail */ - CU_ASSERT(SPDYLAY_ERR_CALLBACK_FAILURE == spdylay_session_send(session)); - - spdylay_session_del(session); -} - -void test_spdylay_session_recv_eof(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.recv_callback = eof_recv_callback; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, - &callbacks, NULL); - - CU_ASSERT(SPDYLAY_ERR_EOF == spdylay_session_recv(session)); - - spdylay_session_del(session); -} - -void test_spdylay_session_recv_data(void) -{ - spdylay_session *session; - spdylay_session_callbacks callbacks; - my_user_data ud; - uint8_t data[8092]; - int rv; - spdylay_outbound_item *item; - spdylay_stream *stream; - - memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback; - callbacks.on_data_recv_callback = on_data_recv_callback; - - spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, &ud); - - /* Create DATA frame with length 4KiB */ - memset(data, 0, sizeof(data)); - spdylay_put_uint32be(data, 1); - spdylay_put_uint32be(data+4, 4096); - - /* stream 1 is not opened, so it must be responded with RST_STREAM */ - ud.data_chunk_recv_cb_called = 0; - ud.data_recv_cb_called = 0; - rv = spdylay_session_mem_recv(session, data, 8+4096); - CU_ASSERT(8+4096 == rv); - - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.data_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(SPDYLAY_RST_STREAM == OB_CTRL_TYPE(item)); - - CU_ASSERT(0 == spdylay_session_send(session)); - - /* Create stream 1 with CLOSING state. It is ignored. */ - stream = spdylay_session_open_stream(session, 1, - SPDYLAY_CTRL_FLAG_NONE, 3, - SPDYLAY_STREAM_CLOSING, NULL); - - ud.data_chunk_recv_cb_called = 0; - ud.data_recv_cb_called = 0; - rv = spdylay_session_mem_recv(session, data, 8+4096); - CU_ASSERT(8+4096 == rv); - - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.data_recv_cb_called); - item = spdylay_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); - - /* This is normal case. DATA is acceptable. */ - stream->state = SPDYLAY_STREAM_OPENED; - - ud.data_chunk_recv_cb_called = 0; - ud.data_recv_cb_called = 0; - rv = spdylay_session_mem_recv(session, data, 8+4096); - CU_ASSERT(8+4096 == rv); - - CU_ASSERT(1 == ud.data_chunk_recv_cb_called); - CU_ASSERT(1 == ud.data_recv_cb_called); - - spdylay_session_del(session); -} diff --git a/tests/spdylay_session_test.h b/tests/spdylay_session_test.h deleted file mode 100644 index 78c09628..00000000 --- a/tests/spdylay_session_test.h +++ /dev/null @@ -1,77 +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. - */ -#ifndef SPDYLAY_SESSION_TEST_H -#define SPDYLAY_SESSION_TEST_H - -void test_spdylay_session_recv(void); -void test_spdylay_session_recv_invalid_stream_id(void); -void test_spdylay_session_add_frame(void); -void test_spdylay_session_on_syn_stream_received(void); -void test_spdylay_session_on_syn_stream_received_with_push(void); -void test_spdylay_session_on_syn_reply_received(void); -void test_spdylay_session_on_window_update_received(void); -void test_spdylay_session_send_syn_stream(void); -void test_spdylay_session_send_syn_reply(void); -void test_spdylay_submit_response(void); -void test_spdylay_submit_response_with_null_data_read_callback(void); -void test_spdylay_submit_request_with_data(void); -void test_spdylay_submit_request_with_null_data_read_callback(void); -void test_spdylay_submit_syn_stream(void); -void test_spdylay_submit_syn_reply(void); -void test_spdylay_submit_headers(void); -void test_spdylay_submit_invalid_nv(void); -void test_spdylay_session_reply_fail(void); -void test_spdylay_session_on_headers_received(void); -void test_spdylay_session_on_ping_received(void); -void test_spdylay_session_on_goaway_received(void); -void test_spdylay_session_on_data_received(void); -void test_spdylay_session_on_rst_received(void); -void test_spdylay_session_is_my_stream_id(void); -void test_spdylay_session_send_rst_stream(void); -void test_spdylay_session_get_next_ob_item(void); -void test_spdylay_session_pop_next_ob_item(void); -void test_spdylay_session_on_request_recv_callback(void); -void test_spdylay_session_on_stream_close(void); -void test_spdylay_session_max_concurrent_streams(void); -void test_spdylay_session_data_backoff_by_high_pri_frame(void); -void test_spdylay_session_stop_data_with_rst_stream(void); -void test_spdylay_session_stream_close_on_syn_stream(void); -void test_spdylay_session_recv_invalid_frame(void); -void test_spdylay_session_defer_data(void); -void test_spdylay_session_flow_control(void); -void test_spdylay_session_on_ctrl_not_send(void); -void test_spdylay_session_on_settings_received(void); -void test_spdylay_submit_settings(void); -void test_spdylay_session_get_outbound_queue_size(void); -void test_spdylay_session_prep_credential(void); -void test_spdylay_submit_syn_stream_with_credential(void); -void test_spdylay_session_set_initial_client_cert_origin(void); -void test_spdylay_session_set_option(void); -void test_spdylay_submit_window_update(void); -void test_spdylay_session_data_read_temporal_failure(void); -void test_spdylay_session_recv_eof(void); -void test_spdylay_session_recv_data(void); - -#endif /* SPDYLAY_SESSION_TEST_H */ diff --git a/tests/spdylay_stream_test.h b/tests/spdylay_stream_test.h deleted file mode 100644 index d60b1d06..00000000 --- a/tests/spdylay_stream_test.h +++ /dev/null @@ -1,30 +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. - */ -#ifndef SPDYLAY_STREAM_TEST_H -#define SPDYLAY_STREAM_TEST_H - -void test_spdylay_stream_add_pushed_stream(void); - -#endif /* SPDYLAY_STREAM_TEST_H */ diff --git a/tests/spdylay_zlib_test.h b/tests/spdylay_zlib_test.h deleted file mode 100644 index 4ae113fa..00000000 --- a/tests/spdylay_zlib_test.h +++ /dev/null @@ -1,31 +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. - */ -#ifndef SPDYLAY_ZLIB_TEST_H -#define SPDYLAY_ZLIB_TEST_H - -void test_spdylay_zlib_spdy2(void); -void test_spdylay_zlib_spdy3(void); - -#endif /* SPDYLAY_ZLIB_TEST_H */ diff --git a/tests/testdata/Makefile.am b/tests/testdata/Makefile.am index fe236c18..0176f40c 100644 --- a/tests/testdata/Makefile.am +++ b/tests/testdata/Makefile.am @@ -1,4 +1,4 @@ -# Spdylay - SPDY Library +# nghttp2 - HTTP/2.0 C Library # Copyright (c) 2012 Tatsuhiro Tsujikawa