├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── README.rst ├── android-config ├── android-make ├── configure.ac ├── doc ├── .gitignore ├── Makefile.am ├── README.rst ├── _themes │ └── sphinx_rtd_theme │ │ ├── __init__.py │ │ ├── breadcrumbs.html │ │ ├── footer.html │ │ ├── layout.html │ │ ├── layout_old.html │ │ ├── search.html │ │ ├── searchbox.html │ │ ├── static │ │ ├── css │ │ │ ├── badge_only.css │ │ │ └── theme.css │ │ ├── fonts │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ └── fontawesome-webfont.woff │ │ └── js │ │ │ └── theme.js │ │ ├── theme.conf │ │ └── versions.html ├── android-spdy-proxy.rst ├── apiref-header.rst ├── conf.py.in ├── index.rst ├── make.bat ├── mkapiref.py ├── package_README.rst └── python.rst ├── examples ├── .gitignore ├── Makefile.am ├── README.rst ├── spdy.h ├── spdycli.c └── spdynative.cc ├── fedora └── spdylay.spec ├── lib ├── Makefile.am ├── includes │ ├── Makefile.am │ └── spdylay │ │ ├── spdylay.h │ │ └── spdylayver.h.in ├── libspdylay.pc.in ├── spdylay_buffer.c ├── spdylay_buffer.h ├── spdylay_frame.c ├── spdylay_frame.h ├── spdylay_gzip.c ├── spdylay_gzip.h ├── spdylay_helper.c ├── spdylay_helper.h ├── spdylay_int.h ├── spdylay_map.c ├── spdylay_map.h ├── spdylay_net.h ├── spdylay_npn.c ├── spdylay_npn.h ├── spdylay_outbound_item.c ├── spdylay_outbound_item.h ├── spdylay_pq.c ├── spdylay_pq.h ├── spdylay_queue.c ├── spdylay_queue.h ├── spdylay_session.c ├── spdylay_session.h ├── spdylay_stream.c ├── spdylay_stream.h ├── spdylay_submit.c ├── spdylay_submit.h ├── spdylay_zlib.c └── spdylay_zlib.h ├── m4 ├── README ├── ac_compile_stdcxx_11.m4 ├── ax_check_compile_flag.m4 └── ax_have_epoll.m4 ├── makerelease.sh ├── proxy.pac.sample ├── python ├── MANIFEST.in ├── Makefile.am ├── README.rst ├── cspdylay.pxd ├── setup.py ├── spdyclient.py ├── spdylay.pyx ├── spdylay_tests.py └── spdyserv.py ├── shrpx.conf.sample ├── src ├── .gitignore ├── EventPoll.h ├── EventPollEvent.h ├── EventPoll_epoll.cc ├── EventPoll_epoll.h ├── EventPoll_kqueue.cc ├── EventPoll_kqueue.h ├── HtmlParser.cc ├── HtmlParser.h ├── Makefile.am ├── SpdyServer.cc ├── SpdyServer.h ├── base64.h ├── http-parser │ ├── 0001-Support-custom-HTTP-version-string-e.g.-ICY.patch │ ├── 0002-Allow-chars-in-32-126-except-for-58-for-TOKEN.patch │ ├── 0003-Use-http_parser-for-tunneling-connection-transparent.patch │ ├── AUTHORS │ ├── CONTRIBUTIONS │ ├── LICENSE-MIT │ ├── README.md │ ├── bench.c │ ├── contrib │ │ ├── parsertrace.c │ │ └── url_parser.c │ ├── http_parser.c │ ├── http_parser.gyp │ ├── http_parser.h │ └── test.c ├── shrpx-unittest.cc ├── shrpx.cc ├── shrpx.h ├── shrpx_accesslog.cc ├── shrpx_accesslog.h ├── shrpx_client_handler.cc ├── shrpx_client_handler.h ├── shrpx_config.cc ├── shrpx_config.h ├── shrpx_downstream.cc ├── shrpx_downstream.h ├── shrpx_downstream_connection.cc ├── shrpx_downstream_connection.h ├── shrpx_downstream_queue.cc ├── shrpx_downstream_queue.h ├── shrpx_error.h ├── shrpx_http.cc ├── shrpx_http.h ├── shrpx_http_downstream_connection.cc ├── shrpx_http_downstream_connection.h ├── shrpx_https_upstream.cc ├── shrpx_https_upstream.h ├── shrpx_io_control.cc ├── shrpx_io_control.h ├── shrpx_listen_handler.cc ├── shrpx_listen_handler.h ├── shrpx_log.cc ├── shrpx_log.h ├── shrpx_spdy_downstream_connection.cc ├── shrpx_spdy_downstream_connection.h ├── shrpx_spdy_session.cc ├── shrpx_spdy_session.h ├── shrpx_spdy_upstream.cc ├── shrpx_spdy_upstream.h ├── shrpx_ssl.cc ├── shrpx_ssl.h ├── shrpx_ssl_test.cc ├── shrpx_ssl_test.h ├── shrpx_thread_event_receiver.cc ├── shrpx_thread_event_receiver.h ├── shrpx_upstream.h ├── shrpx_worker.cc ├── shrpx_worker.h ├── spdycat.cc ├── spdyd.cc ├── spdylay_config.h ├── spdylay_ssl.cc ├── spdylay_ssl.h ├── timegm.c ├── timegm.h ├── util.cc └── util.h └── tests ├── .gitignore ├── Makefile.am ├── end_to_end.py ├── failmalloc.c ├── failmalloc_test.c ├── failmalloc_test.h ├── main.c ├── malloc_wrapper.c ├── malloc_wrapper.h ├── spdylay_buffer_test.c ├── spdylay_buffer_test.h ├── spdylay_frame_test.c ├── spdylay_frame_test.h ├── spdylay_gzip_test.c ├── spdylay_gzip_test.h ├── spdylay_map_test.c ├── spdylay_map_test.h ├── spdylay_npn_test.c ├── spdylay_npn_test.h ├── spdylay_pq_test.c ├── spdylay_pq_test.h ├── spdylay_queue_test.c ├── spdylay_queue_test.h ├── spdylay_session_test.c ├── spdylay_session_test.h ├── spdylay_stream_test.c ├── spdylay_stream_test.h ├── spdylay_test_helper.c ├── spdylay_test_helper.h ├── spdylay_zlib_test.c ├── spdylay_zlib_test.h └── testdata ├── Makefile.am ├── cacert.pem ├── index.html └── privkey.pem /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.lo 4 | *.la 5 | depcomp 6 | *.m4 7 | Makefile 8 | Makefile.in 9 | libtool 10 | missing 11 | autom4te.cache/ 12 | config.guess 13 | config.h 14 | config.h.in 15 | config.log 16 | config.status 17 | config.sub 18 | configure 19 | install-sh 20 | .deps/ 21 | .libs 22 | lib/includes/spdylay/spdylayver.h 23 | lib/libspdylay.pc 24 | ltmain.sh 25 | stamp-h1 26 | .deps/ 27 | INSTALL 28 | .DS_STORE 29 | tests/main 30 | tests/failmalloc 31 | compile 32 | test-driver 33 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Tatsuhiro Tsujikawa 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012, 2014 Tatsuhiro Tsujikawa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tatsuhiro-t/spdylay/ce6426b046722c06b0a004a82513f4f076719651/ChangeLog -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | SUBDIRS = lib src tests examples doc python 24 | 25 | ACLOCAL_AMFLAGS = -I m4 26 | 27 | dist_doc_DATA = README.rst 28 | 29 | EXTRA_DIST = shrpx.conf.sample proxy.pac.sample android-config android-make 30 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | spdylay 1.4.0 2 | ============= 3 | 4 | Release Note 5 | ------------ 6 | 7 | This release removes CREDENTIAL frame support. The API functions are 8 | still there, but they are now noop. 9 | 10 | Changes 11 | ------- 12 | 13 | * Renew test key pair 14 | 15 | * Fix OpenSSL 1.1.0 deprecation warnings 16 | 17 | * spdylay: compile against openssl-1.1.0 18 | 19 | It fails to compile against openssl 1.1.0 due to things like 20 | |shrpx_client_handler.cc:90:30: error: 'strerror' was not declared in this scope 21 | |shrpx_listen_handler.cc:112:32: error: 'memset' was not declared in this scope 22 | |shrpx_listen_handler.cc:114:43: error: 'memcpy' was not declared in this scope 23 | 24 | This resolves it. 25 | 26 | Signed-off-by: Sebastian Andrzej Siewior 27 | 28 | Patch from Sebastian Andrzej Siewior 29 | 30 | * spdycat: Fix leak in SpdySession.reqvec 31 | 32 | * Compile with IRIX 6.5.22 using GCC-4.7.4 33 | 34 | Based on the patch from Klaus Ziegler 35 | 36 | * Remove CREDENTIAL frame processing completely 37 | 38 | We just left API as is, but related functions just do nothing now. 39 | 40 | * Allocate stream ID when spdylay_submit_{syn_stream,request} is called 41 | 42 | This commit allocates stream ID when spdylay_submit_syn_stream and 43 | spdylay_submit_request is called. Also create stream when 44 | spdylay_session_predicate_syn_stream_send is failed, to provide 45 | stream to user callback (e.g., on_ctrl_not_send_callback). 46 | Allocating stream ID early ensures that we can create stream because 47 | we can catch stream ID exhaustion early and fail fast. Since stream 48 | ID is allocated serially, we have to send SYN_STREAM in the order 49 | they queued. So now all queued syn_stream have the same priority 50 | (lowest). The DATA frame has given priority by application. This 51 | does not work well with CREDENTIAL frame, since SYN_STREAM may wait 52 | for CREDENTIAL, which results in out of order transmission. Since 53 | CREDENTIAL frame was deprecated in SPDY/3.1, and no one use it, we 54 | remove its functionality in the later commit. 55 | 56 | * spdycat: --proxy-port, not --proxyport 57 | 58 | Fixes GH-132 59 | 60 | * spdycat: Check :host header field for SNI, since Host header is not allowed 61 | 62 | * spdycat: Update spdycat --help output for --header 63 | 64 | Patch from Chris Adams 65 | 66 | * spdycat: Fix resource leak found by coverity scan 67 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See README.rst 2 | -------------------------------------------------------------------------------- /android-config: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Spdylay - SPDY Library 4 | # 5 | # Copyright (c) 2013 Tatsuhiro Tsujikawa 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining 8 | # a copy of this software and associated documentation files (the 9 | # "Software"), to deal in the Software without restriction, including 10 | # without limitation the rights to use, copy, modify, merge, publish, 11 | # distribute, sublicense, and/or sell copies of the Software, and to 12 | # permit persons to whom the Software is furnished to do so, subject to 13 | # the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be 16 | # included in all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | if [ -z "$ANDROID_HOME" ]; then 27 | echo 'No $ANDROID_HOME specified.' 28 | exit 1 29 | fi 30 | PREFIX=$ANDROID_HOME/usr/local 31 | TOOLCHAIN=$ANDROID_HOME/toolchain 32 | PATH=$TOOLCHAIN/bin:$PATH 33 | 34 | ./configure \ 35 | --disable-shared \ 36 | --host=arm-linux-androideabi \ 37 | --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \ 38 | --without-libxml2 \ 39 | CPPFLAGS="-I$PREFIX/include" \ 40 | PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig" \ 41 | LDFLAGS="-L$PREFIX/lib" 42 | -------------------------------------------------------------------------------- /android-make: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Spdylay - SPDY Library 4 | # 5 | # Copyright (c) 2013 Tatsuhiro Tsujikawa 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining 8 | # a copy of this software and associated documentation files (the 9 | # "Software"), to deal in the Software without restriction, including 10 | # without limitation the rights to use, copy, modify, merge, publish, 11 | # distribute, sublicense, and/or sell copies of the Software, and to 12 | # permit persons to whom the Software is furnished to do so, subject to 13 | # the following conditions: 14 | # 15 | # The above copyright notice and this permission notice shall be 16 | # included in all copies or substantial portions of the Software. 17 | # 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | if [ -z "$ANDROID_HOME" ]; then 27 | echo 'No $ANDROID_HOME specified.' 28 | exit 1 29 | fi 30 | TOOLCHAIN=$ANDROID_HOME/toolchain 31 | PATH=$TOOLCHAIN/bin:$PATH 32 | 33 | make "$@" 34 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | apiref.rst 2 | conf.py 3 | manual 4 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/__init__.py: -------------------------------------------------------------------------------- 1 | """Sphinx ReadTheDocs theme. 2 | 3 | From https://github.com/ryan-roemer/sphinx-bootstrap-theme. 4 | 5 | """ 6 | import os 7 | 8 | VERSION = (0, 1, 5) 9 | 10 | __version__ = ".".join(str(v) for v in VERSION) 11 | __version_full__ = __version__ 12 | 13 | 14 | def get_html_theme_path(): 15 | """Return list of HTML theme paths.""" 16 | cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 17 | return cur_dir 18 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/breadcrumbs.html: -------------------------------------------------------------------------------- 1 |
2 | 18 |
19 |
20 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/footer.html: -------------------------------------------------------------------------------- 1 |
2 | {% if next or prev %} 3 | 11 | {% endif %} 12 | 13 |
14 | 15 |
16 |

17 | {%- if show_copyright %} 18 | {%- if hasdoc('copyright') %} 19 | {% trans path=pathto('copyright'), copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %} 20 | {%- else %} 21 | {% trans copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %} 22 | {%- endif %} 23 | {%- endif %} 24 | 25 | {%- if last_updated %} 26 | {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} 27 | {%- endif %} 28 |

29 |
30 | 31 | {% trans %}Sphinx theme provided by Read the Docs{% endtrans %} 32 |
33 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/search.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/search.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the search page. 6 | 7 | :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "layout.html" %} 11 | {% set title = _('Search') %} 12 | {% set script_files = script_files + ['_static/searchtools.js'] %} 13 | {% block footer %} 14 | 17 | {# this is used when loading the search index using $.ajax fails, 18 | such as on Chrome for documents on localhost #} 19 | 20 | {{ super() }} 21 | {% endblock %} 22 | {% block body %} 23 | 31 | 32 | {% if search_performed %} 33 |

{{ _('Search Results') }}

34 | {% if not search_results %} 35 |

{{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}

36 | {% endif %} 37 | {% endif %} 38 |
39 | {% if search_results %} 40 |
    41 | {% for href, caption, context in search_results %} 42 |
  • 43 | {{ caption }} 44 |

    {{ context|e }}

    45 |
  • 46 | {% endfor %} 47 |
48 | {% endif %} 49 |
50 | {% endblock %} 51 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/searchbox.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 | 6 |
7 |
8 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:"\f02d"}.icon-book:before{content:"\f02d"}.fa-caret-down:before{content:"\f0d7"}.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before{content:"\f0d8"}.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before{content:"\f0d9"}.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before{content:"\f0da"}.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}img{width:100%;height:auto}} 2 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tatsuhiro-t/spdylay/ce6426b046722c06b0a004a82513f4f076719651/doc/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tatsuhiro-t/spdylay/ce6426b046722c06b0a004a82513f4f076719651/doc/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tatsuhiro-t/spdylay/ce6426b046722c06b0a004a82513f4f076719651/doc/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tatsuhiro-t/spdylay/ce6426b046722c06b0a004a82513f4f076719651/doc/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/static/js/theme.js: -------------------------------------------------------------------------------- 1 | $( document ).ready(function() { 2 | // Shift nav in mobile when clicking the menu. 3 | $(document).on('click', "[data-toggle='wy-nav-top']", function() { 4 | $("[data-toggle='wy-nav-shift']").toggleClass("shift"); 5 | $("[data-toggle='rst-versions']").toggleClass("shift"); 6 | }); 7 | // Close menu when you click a link. 8 | $(document).on('click', ".wy-menu-vertical .current ul li a", function() { 9 | $("[data-toggle='wy-nav-shift']").removeClass("shift"); 10 | $("[data-toggle='rst-versions']").toggleClass("shift"); 11 | }); 12 | $(document).on('click', "[data-toggle='rst-current-version']", function() { 13 | $("[data-toggle='rst-versions']").toggleClass("shift-up"); 14 | }); 15 | // Make tables responsive 16 | $("table.docutils:not(.field-list)").wrap("
"); 17 | }); 18 | 19 | window.SphinxRtdTheme = (function (jquery) { 20 | var stickyNav = (function () { 21 | var navBar, 22 | win, 23 | stickyNavCssClass = 'stickynav', 24 | applyStickNav = function () { 25 | if (navBar.height() <= win.height()) { 26 | navBar.addClass(stickyNavCssClass); 27 | } else { 28 | navBar.removeClass(stickyNavCssClass); 29 | } 30 | }, 31 | enable = function () { 32 | applyStickNav(); 33 | win.on('resize', applyStickNav); 34 | }, 35 | init = function () { 36 | navBar = jquery('nav.wy-nav-side:first'); 37 | win = jquery(window); 38 | }; 39 | jquery(init); 40 | return { 41 | enable : enable 42 | }; 43 | }()); 44 | return { 45 | StickyNav : stickyNav 46 | }; 47 | }($)); 48 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = css/theme.css 4 | 5 | [options] 6 | typekit_id = hiw1hhg 7 | analytics_id = 8 | sticky_navigation = False 9 | -------------------------------------------------------------------------------- /doc/_themes/sphinx_rtd_theme/versions.html: -------------------------------------------------------------------------------- 1 | {% if READTHEDOCS %} 2 | {# Add rst-badge after rst-versions for small badge style. #} 3 |
4 | 5 | Read the Docs 6 | v: {{ current_version }} 7 | 8 | 9 |
10 |
11 |
Versions
12 | {% for slug, url in versions %} 13 |
{{ slug }}
14 | {% endfor %} 15 |
16 |
17 |
Downloads
18 | {% for type, url in downloads %} 19 |
{{ type }}
20 | {% endfor %} 21 |
22 |
23 |
On Read the Docs
24 |
25 | Project Home 26 |
27 |
28 | Builds 29 |
30 |
31 |
32 | Free document hosting provided by Read the Docs. 33 | 34 |
35 |
36 | {% endif %} 37 | 38 | -------------------------------------------------------------------------------- /doc/apiref-header.rst: -------------------------------------------------------------------------------- 1 | API Reference 2 | ============= 3 | 4 | Includes 5 | -------- 6 | 7 | To use the public APIs, include ``spdylay/spdylay.h``:: 8 | 9 | #include 10 | 11 | Remarks 12 | ------- 13 | 14 | Do not call `spdylay_session_send`, `spdylay_session_recv` or 15 | `spdylay_session_mem_recv` from the spdylay callback functions 16 | directly or indirectly. It will lead to the crash. You can submit 17 | requests or frames in the callbacks then call `spdylay_session_send`, 18 | `spdylay_session_recv` or `spdylay_session_mem_recv` outside of the 19 | callbacks. 20 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. Spdylay documentation master file, created by 2 | sphinx-quickstart on Sun Mar 11 22:57:49 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Spdylay - SPDY C Library 7 | ======================== 8 | 9 | This is an experimental implementation of Google's SPDY protocol in C. 10 | This library provides SPDY version 2, 3 and 3.1 framing layer 11 | implementation. It does not perform any I/O operations. When the 12 | library needs them, it calls the callback functions provided by the 13 | application. It also does not include any event polling mechanism, so 14 | the application can freely choose the way of handling events. This 15 | library code does not depend on any particular SSL library (except for 16 | example programs which depend on OpenSSL 1.0.1 or later). 17 | 18 | This project also develops SPDY client, server and proxy on top of 19 | Spdylay library. 20 | 21 | Contents: 22 | 23 | .. toctree:: 24 | :maxdepth: 2 25 | 26 | package_README 27 | apiref 28 | python 29 | android-spdy-proxy 30 | Download 31 | Old download 32 | Source 33 | Issues 34 | 35 | Resources 36 | --------- 37 | 38 | * http://www.chromium.org/spdy 39 | -------------------------------------------------------------------------------- /doc/package_README.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | spdynative 2 | spdycli 3 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | if ENABLE_EXAMPLES 25 | 26 | AM_CFLAGS = -Wall 27 | AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \ 28 | @OPENSSL_CFLAGS@ @DEFS@ 29 | AM_LDFLAGS = @OPENSSL_LIBS@ 30 | LDADD = $(top_builddir)/lib/libspdylay.la 31 | 32 | noinst_PROGRAMS = spdycli 33 | spdycli_SOURCES = spdycli.c 34 | 35 | endif # ENABLE_EXAMPLES 36 | 37 | EXTRA_DIST = README.rst 38 | -------------------------------------------------------------------------------- /examples/README.rst: -------------------------------------------------------------------------------- 1 | spdycat, spdyd and shrpx were moved to ``../src``. 2 | -------------------------------------------------------------------------------- /examples/spdynative.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include 26 | 27 | #include "spdy.h" 28 | 29 | int main() 30 | { 31 | spdy server; 32 | if(!server.listen("localhost", 8080, "server.key", "server.crt", 33 | [](request& req, response& res) { 34 | res.set_status(200); 35 | res.set_header("content-type", "text/plain"); 36 | res.end("C++ FTW\n"); 37 | })) 38 | return EXIT_FAILURE; 39 | 40 | std::cout << "Server running at http://localhost:8080/" << std::endl; 41 | return reactor::run(server); 42 | } 43 | -------------------------------------------------------------------------------- /fedora/spdylay.spec: -------------------------------------------------------------------------------- 1 | Prefix: %{_usr} 2 | Name: spdylay 3 | Version: 0.3.7 4 | Release: 1%{?dist} 5 | Summary: The experimental SPDY protocol version 2 and 3 implementation in C 6 | 7 | Group: System Environment/Libraries 8 | License: MIT 9 | URL: http://sourceforge.net/projects/spdylay/ 10 | Source0: %{name}-%{version}.tar.gz 11 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) 12 | 13 | BuildRequires: pkgconfig >= 0.20, zlib >= 1.2.3, gcc, gcc-c++, make 14 | BuildRequires: openssl-devel, CUnit-devel 15 | 16 | #Requires: 17 | 18 | %description 19 | This is an experimental implementation of Google's SPDY protocol in C. 20 | This library provides SPDY version 2 and 3 framing layer implementation. It does not 21 | perform any I/O operations. When the library needs them, it calls the callback functions 22 | provided by the application. It also does not include any event polling mechanism, 23 | so the application can freely choose the way of handling events. This library code does 24 | not depend on any particular SSL library (except for example programs which depend on 25 | OpenSSL 1.0.1 or later). 26 | 27 | %package devel 28 | Summary: Development files for %{name} 29 | Group: Development/Libraries 30 | Requires: %{name} = %{version}-%{release} 31 | 32 | %description devel 33 | The %{name}-devel package contains libraries and header files for 34 | developing applications that use %{name}. 35 | 36 | %prep 37 | %setup -q 38 | 39 | %build 40 | autoreconf -i 41 | %{__automake} 42 | %{__autoconf} 43 | %configure --disable-static --enable-examples --disable-xmltest 44 | %{__make} %{?_smp_mflags} 45 | 46 | %install 47 | rm -rf $RPM_BUILD_ROOT 48 | %{__make} install DESTDIR=$RPM_BUILD_ROOT 49 | 50 | %clean 51 | rm -rf $RPM_BUILD_ROOT 52 | 53 | %post -p /sbin/ldconfig 54 | 55 | %postun -p /sbin/ldconfig 56 | 57 | %files 58 | %defattr(-,root,root,-) 59 | %doc 60 | %{_libdir}/*.so.* 61 | %exclude %{_libdir}/*.la 62 | %{_bindir}/shrpx 63 | %{_bindir}/spdycat 64 | %{_bindir}/spdyd 65 | 66 | %files devel 67 | %defattr(-,root,root,-) 68 | %doc %{_docdir}/%{name} 69 | %{_includedir}/* 70 | %{_libdir}/*.so 71 | %{_libdir}/pkgconfig/*.pc 72 | 73 | %changelog 74 | * Sat Oct 27 2012 Raul Gutierrez Segales 0.3.7-DEV 75 | - Initial RPM release. 76 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | SUBDIRS = includes 24 | 25 | AM_CFLAGS = -Wall 26 | AM_CPPFLAGS = -I$(srcdir)/includes -I$(builddir)/includes @DEFS@ 27 | 28 | pkgconfigdir = $(libdir)/pkgconfig 29 | pkgconfig_DATA = libspdylay.pc 30 | DISTCLEANFILES = $(pkgconfig_DATA) 31 | 32 | lib_LTLIBRARIES = libspdylay.la 33 | 34 | OBJECTS = spdylay_pq.c spdylay_map.c spdylay_queue.c \ 35 | spdylay_buffer.c spdylay_frame.c spdylay_zlib.c \ 36 | spdylay_session.c spdylay_helper.c spdylay_stream.c spdylay_npn.c \ 37 | spdylay_submit.c spdylay_outbound_item.c \ 38 | spdylay_gzip.c 39 | 40 | HFILES = spdylay_pq.h spdylay_int.h spdylay_map.h spdylay_queue.h \ 41 | spdylay_buffer.h spdylay_frame.h spdylay_zlib.h \ 42 | spdylay_session.h spdylay_helper.h spdylay_stream.h spdylay_int.h \ 43 | spdylay_npn.h spdylay_gzip.h \ 44 | spdylay_submit.h spdylay_outbound_item.h \ 45 | spdylay_net.h 46 | 47 | libspdylay_la_SOURCES = $(HFILES) $(OBJECTS) 48 | libspdylay_la_LDFLAGS = -no-undefined \ 49 | -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) 50 | -------------------------------------------------------------------------------- /lib/includes/Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | nobase_include_HEADERS = spdylay/spdylay.h spdylay/spdylayver.h 24 | -------------------------------------------------------------------------------- /lib/includes/spdylay/spdylayver.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAYVER_H 26 | #define SPDYLAYVER_H 27 | 28 | /** 29 | * @macro 30 | * Version number of the Spdylay library release 31 | */ 32 | #define SPDYLAY_VERSION "@PACKAGE_VERSION@" 33 | 34 | #endif /* SPDYLAYVER_H */ 35 | -------------------------------------------------------------------------------- /lib/libspdylay.pc.in: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | prefix=@prefix@ 24 | exec_prefix=@exec_prefix@ 25 | libdir=@libdir@ 26 | includedir=@includedir@ 27 | 28 | Name: Spdylay 29 | Description: SPDY C library 30 | URL: http://spdylay.sourceforge.net/ 31 | Version: @VERSION@ 32 | Libs: -L${libdir} -lspdylay 33 | Requires.private: zlib 34 | Cflags: -I${includedir} 35 | -------------------------------------------------------------------------------- /lib/spdylay_gzip.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_gzip.h" 26 | 27 | #include 28 | 29 | int spdylay_gzip_inflate_new(spdylay_gzip **inflater_ptr) 30 | { 31 | int rv; 32 | *inflater_ptr = malloc(sizeof(spdylay_gzip)); 33 | if(*inflater_ptr == NULL) { 34 | return SPDYLAY_ERR_NOMEM; 35 | } 36 | (*inflater_ptr)->finished = 0; 37 | (*inflater_ptr)->zst.next_in = Z_NULL; 38 | (*inflater_ptr)->zst.avail_in = 0; 39 | (*inflater_ptr)->zst.zalloc = Z_NULL; 40 | (*inflater_ptr)->zst.zfree = Z_NULL; 41 | (*inflater_ptr)->zst.opaque = Z_NULL; 42 | rv = inflateInit2(&(*inflater_ptr)->zst, 47); 43 | if(rv != Z_OK) { 44 | free(*inflater_ptr); 45 | return SPDYLAY_ERR_GZIP; 46 | } 47 | return 0; 48 | } 49 | 50 | void spdylay_gzip_inflate_del(spdylay_gzip *inflater) 51 | { 52 | if(inflater != NULL) { 53 | inflateEnd(&inflater->zst); 54 | free(inflater); 55 | } 56 | } 57 | 58 | int spdylay_gzip_inflate(spdylay_gzip *inflater, 59 | uint8_t *out, size_t *outlen_ptr, 60 | const uint8_t *in, size_t *inlen_ptr) 61 | { 62 | int rv; 63 | if(inflater->finished) { 64 | return SPDYLAY_ERR_GZIP; 65 | } 66 | inflater->zst.avail_in = (uint)*inlen_ptr; 67 | inflater->zst.next_in = (unsigned char*)in; 68 | inflater->zst.avail_out = (uint)*outlen_ptr; 69 | inflater->zst.next_out = out; 70 | 71 | rv = inflate(&inflater->zst, Z_NO_FLUSH); 72 | 73 | *inlen_ptr -= inflater->zst.avail_in; 74 | *outlen_ptr -= inflater->zst.avail_out; 75 | switch(rv) { 76 | case Z_STREAM_END: 77 | inflater->finished = 1; 78 | case Z_OK: 79 | case Z_BUF_ERROR: 80 | return 0; 81 | case Z_DATA_ERROR: 82 | case Z_STREAM_ERROR: 83 | case Z_NEED_DICT: 84 | case Z_MEM_ERROR: 85 | return SPDYLAY_ERR_GZIP; 86 | default: 87 | assert(0); 88 | /* We need this for some compilers */ 89 | return 0; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /lib/spdylay_gzip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_GZIP_H 26 | 27 | #ifdef HAVE_CONFIG_H 28 | # include 29 | #endif /* HAVE_CONFIG_H */ 30 | #include 31 | 32 | #include 33 | 34 | struct spdylay_gzip { 35 | z_stream zst; 36 | int8_t finished; 37 | }; 38 | 39 | #endif /* SPDYLAY_GZIP_H */ 40 | -------------------------------------------------------------------------------- /lib/spdylay_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_HELPER_H 26 | #define SPDYLAY_HELPER_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | #define spdylay_min(A, B) ((A) < (B) ? (A) : (B)) 35 | #define spdylay_max(A, B) ((A) > (B) ? (A) : (B)) 36 | 37 | /* 38 | * Copies 2 byte unsigned integer |n| in host byte order to |buf| in 39 | * network byte order. 40 | */ 41 | void spdylay_put_uint16be(uint8_t *buf, uint16_t n); 42 | 43 | /* 44 | * Copies 4 byte unsigned integer |n| in host byte order to |buf| in 45 | * network byte order. 46 | */ 47 | void spdylay_put_uint32be(uint8_t *buf, uint32_t n); 48 | 49 | /* 50 | * Retrieves 2 byte unsigned integer stored in |data| in network byte 51 | * order and returns it in host byte order. 52 | */ 53 | uint16_t spdylay_get_uint16(const uint8_t *data); 54 | 55 | /* 56 | * Retrieves 4 byte unsigned integer stored in |data| in network byte 57 | * order and returns it in host byte order. 58 | */ 59 | uint32_t spdylay_get_uint32(const uint8_t *data); 60 | 61 | /* 62 | * Ensures that buffer |*buf_ptr| with |*buflen_ptr| length has at 63 | * least |min_length| bytes. If |min_length| > |*buflen_ptr|, 64 | * allocates new buffer having at least |min_length| bytes and assigns 65 | * its pointer to |*buf_ptr| and allocated number of bytes to 66 | * |*buflen_ptr|. The memory pointed by |*buf_ptr| previously is 67 | * freed. No memory copy is done between old and new buffer. 68 | * |*buf_ptr| and |*buflen_ptr| are only updated iff this function 69 | * succeeds. 70 | * 71 | * This function returns 0 if it succeeds, or one of the following 72 | * negative error codes: 73 | * 74 | * SPDYLAY_ERR_NOMEM 75 | * Out of memory. 76 | */ 77 | int spdylay_reserve_buffer(uint8_t **buf_ptr, size_t *buflen_ptr, 78 | size_t min_length); 79 | 80 | #endif /* SPDYLAY_HELPER_H */ 81 | -------------------------------------------------------------------------------- /lib/spdylay_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_INT_H 26 | #define SPDYLAY_INT_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | /* Macros, types and constants for internal use */ 35 | 36 | typedef int (*spdylay_compar)(const void *lhs, const void *rhs); 37 | 38 | #endif /* SPDYLAY_INT_H */ 39 | -------------------------------------------------------------------------------- /lib/spdylay_net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_NET_H 26 | #define SPDYLAY_NET_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #ifdef HAVE_ARPA_INET_H 33 | # include 34 | #endif /* HAVE_ARPA_INET_H */ 35 | 36 | #ifdef HAVE_NETINET_IN_H 37 | # include 38 | #endif /* HAVE_NETINET_IN_H */ 39 | 40 | #ifdef HAVE_WINSOCK2_H 41 | # include 42 | #endif /* HAVE_WINSOCK2_H */ 43 | 44 | #endif /* SPDYLAY_NET_H */ 45 | -------------------------------------------------------------------------------- /lib/spdylay_npn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_NPN_H 26 | #define SPDYLAY_NPN_H 27 | 28 | #ifdef HAVE_CONFIG 29 | # include 30 | #endif /* HAVE_CONFIG */ 31 | 32 | #include 33 | 34 | #endif /* SPDYLAY_NPN_H */ 35 | -------------------------------------------------------------------------------- /lib/spdylay_outbound_item.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_outbound_item.h" 26 | 27 | #include 28 | 29 | void spdylay_outbound_item_free(spdylay_outbound_item *item) 30 | { 31 | if(item == NULL) { 32 | return; 33 | } 34 | if(item->frame_cat == SPDYLAY_CTRL) { 35 | spdylay_frame_type frame_type; 36 | spdylay_frame *frame; 37 | frame_type = spdylay_outbound_item_get_ctrl_frame_type(item); 38 | frame = spdylay_outbound_item_get_ctrl_frame(item); 39 | switch(frame_type) { 40 | case SPDYLAY_SYN_STREAM: 41 | spdylay_frame_syn_stream_free(&frame->syn_stream); 42 | free(((spdylay_syn_stream_aux_data*)item->aux_data)->data_prd); 43 | break; 44 | case SPDYLAY_SYN_REPLY: 45 | spdylay_frame_syn_reply_free(&frame->syn_reply); 46 | break; 47 | case SPDYLAY_RST_STREAM: 48 | spdylay_frame_rst_stream_free(&frame->rst_stream); 49 | break; 50 | case SPDYLAY_SETTINGS: 51 | spdylay_frame_settings_free(&frame->settings); 52 | break; 53 | case SPDYLAY_NOOP: 54 | /* We don't have any public API to add NOOP, so here is 55 | unreachable. */ 56 | assert(0); 57 | case SPDYLAY_PING: 58 | spdylay_frame_ping_free(&frame->ping); 59 | break; 60 | case SPDYLAY_GOAWAY: 61 | spdylay_frame_goaway_free(&frame->goaway); 62 | break; 63 | case SPDYLAY_HEADERS: 64 | spdylay_frame_headers_free(&frame->headers); 65 | break; 66 | case SPDYLAY_WINDOW_UPDATE: 67 | spdylay_frame_window_update_free(&frame->window_update); 68 | break; 69 | case SPDYLAY_CREDENTIAL: 70 | assert(0); 71 | break; 72 | } 73 | } else if(item->frame_cat == SPDYLAY_DATA) { 74 | spdylay_data *data_frame; 75 | data_frame = spdylay_outbound_item_get_data_frame(item); 76 | spdylay_frame_data_free(data_frame); 77 | } else { 78 | /* Unreachable */ 79 | assert(0); 80 | } 81 | free(item->frame); 82 | free(item->aux_data); 83 | } 84 | -------------------------------------------------------------------------------- /lib/spdylay_outbound_item.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_OUTBOUND_ITEM_H 26 | #define SPDYLAY_OUTBOUND_ITEM_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | #include "spdylay_frame.h" 34 | 35 | /* Priority for PING */ 36 | #define SPDYLAY_OB_PRI_PING -10 37 | 38 | typedef struct { 39 | spdylay_data_provider *data_prd; 40 | void *stream_user_data; 41 | } spdylay_syn_stream_aux_data; 42 | 43 | typedef struct { 44 | void *frame; 45 | void *aux_data; 46 | int64_t seq; 47 | /* Type of |frame|. SPDYLAY_CTRL: spdylay_frame*, SPDYLAY_DATA: 48 | spdylay_data* */ 49 | spdylay_frame_category frame_cat; 50 | int pri; 51 | } spdylay_outbound_item; 52 | 53 | /* 54 | * Deallocates resource for |item|. If |item| is NULL, this function 55 | * does nothing. 56 | */ 57 | void spdylay_outbound_item_free(spdylay_outbound_item *item); 58 | 59 | /* Macros to cast spdylay_outbound_item.frame to the proper type. */ 60 | #define spdylay_outbound_item_get_ctrl_frame(ITEM) ((spdylay_frame*)ITEM->frame) 61 | #define spdylay_outbound_item_get_ctrl_frame_type(ITEM) \ 62 | (((spdylay_frame*)ITEM->frame)->ctrl.hd.type) 63 | #define spdylay_outbound_item_get_data_frame(ITEM) ((spdylay_data*)ITEM->frame) 64 | 65 | #endif /* SPDYLAY_OUTBOUND_ITEM_H */ 66 | -------------------------------------------------------------------------------- /lib/spdylay_pq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_PQ_H 26 | #define SPDYLAY_PQ_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | #include "spdylay_int.h" 34 | 35 | /* Implementation of priority queue */ 36 | 37 | typedef struct { 38 | /* The pointer to the pointer to the item stored */ 39 | void **q; 40 | /* The number of items sotred */ 41 | size_t length; 42 | /* The maximum number of items this pq can store. This is 43 | automatically extended when length is reached to this value. */ 44 | size_t capacity; 45 | /* The compare function between items */ 46 | spdylay_compar compar; 47 | } spdylay_pq; 48 | 49 | /* 50 | * Initializes priority queue |pq| with compare function |cmp|. 51 | * 52 | * This function returns 0 if it succeeds, or one of the following 53 | * negative error codes: 54 | * 55 | * SPDYLAY_ERR_NOMEM 56 | * Out of memory. 57 | */ 58 | int spdylay_pq_init(spdylay_pq *pq, spdylay_compar cmp); 59 | 60 | /* 61 | * Deallocates any resources allocated for |pq|. The stored items are 62 | * not freed by this function. 63 | */ 64 | void spdylay_pq_free(spdylay_pq *pq); 65 | 66 | /* 67 | * Adds |item| to the priority queue |pq|. 68 | * 69 | * This function returns 0 if it succeds, or one of the following 70 | * negative error codes: 71 | * 72 | * SPDYLAY_ERR_NOMEM 73 | * Out of memory. 74 | */ 75 | int spdylay_pq_push(spdylay_pq *pq, void *item); 76 | 77 | /* 78 | * Returns item at the top of the queue |pq|. If the queue is empty, 79 | * this function returns NULL. 80 | */ 81 | void* spdylay_pq_top(spdylay_pq *pq); 82 | 83 | /* 84 | * Pops item at the top of the queue |pq|. The popped item is not 85 | * freed by this function. 86 | */ 87 | void spdylay_pq_pop(spdylay_pq *pq); 88 | 89 | /* 90 | * Returns nonzero if the queue |pq| is empty. 91 | */ 92 | int spdylay_pq_empty(spdylay_pq *pq); 93 | 94 | /* 95 | * Returns the number of items in the queue |pq|. 96 | */ 97 | size_t spdylay_pq_size(spdylay_pq *pq); 98 | 99 | #endif /* SPDYLAY_PQ_H */ 100 | -------------------------------------------------------------------------------- /lib/spdylay_queue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_queue.h" 26 | 27 | #include 28 | #include 29 | 30 | void spdylay_queue_init(spdylay_queue *queue) 31 | { 32 | queue->front = queue->back = NULL; 33 | } 34 | 35 | void spdylay_queue_free(spdylay_queue *queue) 36 | { 37 | if(!queue) { 38 | return; 39 | } else { 40 | spdylay_queue_cell *p = queue->front; 41 | while(p) { 42 | spdylay_queue_cell *next = p->next; 43 | free(p); 44 | p = next; 45 | } 46 | } 47 | } 48 | 49 | int spdylay_queue_push(spdylay_queue *queue, void *data) 50 | { 51 | spdylay_queue_cell *new_cell = (spdylay_queue_cell*)malloc 52 | (sizeof(spdylay_queue_cell)); 53 | if(!new_cell) { 54 | return SPDYLAY_ERR_NOMEM; 55 | } 56 | new_cell->data = data; 57 | new_cell->next = NULL; 58 | if(queue->back) { 59 | queue->back->next = new_cell; 60 | queue->back = new_cell; 61 | 62 | } else { 63 | queue->front = queue->back = new_cell; 64 | } 65 | return 0; 66 | } 67 | 68 | void spdylay_queue_pop(spdylay_queue *queue) 69 | { 70 | spdylay_queue_cell *front = queue->front; 71 | assert(front); 72 | queue->front = front->next; 73 | if(front == queue->back) { 74 | queue->back = NULL; 75 | } 76 | free(front); 77 | } 78 | 79 | void* spdylay_queue_front(spdylay_queue *queue) 80 | { 81 | assert(queue->front); 82 | return queue->front->data; 83 | } 84 | 85 | void* spdylay_queue_back(spdylay_queue *queue) 86 | { 87 | assert(queue->back); 88 | return queue->back->data; 89 | } 90 | 91 | int spdylay_queue_empty(spdylay_queue *queue) 92 | { 93 | return queue->front == NULL; 94 | } 95 | -------------------------------------------------------------------------------- /lib/spdylay_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_QUEUE_H 26 | #define SPDYLAY_QUEUE_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include "config.h" 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | typedef struct spdylay_queue_cell { 35 | void *data; 36 | struct spdylay_queue_cell *next; 37 | } spdylay_queue_cell; 38 | 39 | typedef struct { 40 | spdylay_queue_cell *front, *back; 41 | } spdylay_queue; 42 | 43 | void spdylay_queue_init(spdylay_queue *queue); 44 | void spdylay_queue_free(spdylay_queue *queue); 45 | int spdylay_queue_push(spdylay_queue *queue, void *data); 46 | void spdylay_queue_pop(spdylay_queue *queue); 47 | void* spdylay_queue_front(spdylay_queue *queue); 48 | void* spdylay_queue_back(spdylay_queue *queue); 49 | int spdylay_queue_empty(spdylay_queue *queue); 50 | 51 | #endif /* SPDYLAY_QUEUE_H */ 52 | -------------------------------------------------------------------------------- /lib/spdylay_submit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_SUBMIT_H 26 | #define SPDYLAY_SUBMIT_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include 33 | 34 | #endif /* SPDYLAY_SUBMIT_H */ 35 | -------------------------------------------------------------------------------- /m4/README: -------------------------------------------------------------------------------- 1 | Empty m4 directory to make `autoreconf -i` happy. 2 | -------------------------------------------------------------------------------- /m4/ac_compile_stdcxx_11.m4: -------------------------------------------------------------------------------- 1 | # AC_COMPILE_STDCXX_11 2 | AC_DEFUN([AC_COMPILE_STDCXX_11], [ 3 | 4 | AC_CACHE_CHECK(if g++ supports C++11 features with -std=c++0x, 5 | ac_cv_cxx_compile_cxx11_cxx, 6 | [AC_LANG_SAVE 7 | AC_LANG_CPLUSPLUS 8 | ac_save_CXXFLAGS="$CXXFLAGS" 9 | CXXFLAGS="$CXXFLAGS -std=gnu++0x" 10 | AC_TRY_COMPILE([ 11 | #include 12 | std::function func; 13 | ],, 14 | ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no) 15 | CXXFLAGS="$ac_save_CXXFLAGS" 16 | AC_LANG_RESTORE 17 | ]) 18 | 19 | if test "$ac_cv_cxx_compile_cxx11_cxx" = yes; then 20 | AC_DEFINE(HAVE_STDCXX_11,,[Define if g++ supports C++11 features. ]) 21 | fi 22 | ]) 23 | -------------------------------------------------------------------------------- /m4/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # This program is free software: you can redistribute it and/or modify it 33 | # under the terms of the GNU General Public License as published by the 34 | # Free Software Foundation, either version 3 of the License, or (at your 35 | # option) any later version. 36 | # 37 | # This program is distributed in the hope that it will be useful, but 38 | # WITHOUT ANY WARRANTY; without even the implied warranty of 39 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 40 | # Public License for more details. 41 | # 42 | # You should have received a copy of the GNU General Public License along 43 | # with this program. If not, see . 44 | # 45 | # As a special exception, the respective Autoconf Macro's copyright owner 46 | # gives unlimited permission to copy, distribute and modify the configure 47 | # scripts that are the output of Autoconf when processing the Macro. You 48 | # need not follow the terms of the GNU General Public License when using 49 | # or distributing such scripts, even though portions of the text of the 50 | # Macro appear in them. The GNU General Public License (GPL) does govern 51 | # all other use of the material that constitutes the Autoconf Macro. 52 | # 53 | # This special exception to the GPL applies to versions of the Autoconf 54 | # Macro released by the Autoconf Archive. When you make and distribute a 55 | # modified version of the Autoconf Macro, you may extend this special 56 | # exception to the GPL to apply to your modified version as well. 57 | 58 | #serial 3 59 | 60 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 61 | [AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX 62 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 63 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 64 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 65 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 66 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 67 | [AS_VAR_SET(CACHEVAR,[yes])], 68 | [AS_VAR_SET(CACHEVAR,[no])]) 69 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 70 | AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 71 | [m4_default([$2], :)], 72 | [m4_default([$3], :)]) 73 | AS_VAR_POPDEF([CACHEVAR])dnl 74 | ])dnl AX_CHECK_COMPILE_FLAGS 75 | -------------------------------------------------------------------------------- /makerelease.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | TAG=$1 4 | PREV_TAG=$2 5 | 6 | git checkout refs/tags/$TAG 7 | git log --pretty=fuller --date=short refs/tags/$PREV_TAG..HEAD > ChangeLog 8 | 9 | ./configure && \ 10 | make dist-bzip2 && make dist-gzip && make dist-xz || echo "error" 11 | make distclean 12 | -------------------------------------------------------------------------------- /proxy.pac.sample: -------------------------------------------------------------------------------- 1 | function FindProxyForURL(url, host) { 2 | // For SPDY proxy 3 | return "HTTPS localhost:3000"; 4 | // For conventional HTTP proxy 5 | // return "PROXY localhost:3000"; 6 | } 7 | -------------------------------------------------------------------------------- /python/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include spdylay.pyx cspdylay.pxd spdylay_tests.py spdyclient.py spdyserv.py README.rst 2 | -------------------------------------------------------------------------------- /python/Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | EXTRA_DIST = MANIFEST.in README.rst cspdylay.pxd setup.py \ 24 | spdyclient.py spdylay.pyx spdylay_tests.py spdyserv.py 25 | -------------------------------------------------------------------------------- /python/spdyclient.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # The example SPDY client. You need Python 3.3 or later because we 4 | # use TLS NPN. 5 | # 6 | # Usage: spdyclient.py URL... 7 | # 8 | import sys 9 | import spdylay 10 | 11 | class MyStreamHandler(spdylay.BaseSPDYStreamHandler): 12 | def on_header(self, nv): 13 | sys.stdout.write('Stream#{}\n'.format(self.stream_id)) 14 | for k, v in nv: 15 | sys.stdout.write('{}: {}\n'.format(k, v)) 16 | 17 | def on_data(self, data): 18 | sys.stdout.write('Stream#{}\n'.format(self.stream_id)) 19 | sys.stdout.buffer.write(data) 20 | 21 | def on_close(self, status_code): 22 | sys.stdout.write('Stream#{} closed\n'.format(self.stream_id)) 23 | 24 | if __name__ == '__main__': 25 | uris = sys.argv[1:] 26 | spdylay.urlfetch(uris, MyStreamHandler) 27 | -------------------------------------------------------------------------------- /python/spdyserv.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # The example SPDY server. Python 3.3 or later is required because TLS 4 | # NPN is used in spdylay.ThreadedSPDYServer. Put private key and 5 | # certificate file in the current working directory. 6 | 7 | import spdylay 8 | 9 | # private key file 10 | KEY_FILE='server.key' 11 | # certificate file 12 | CERT_FILE='server.crt' 13 | 14 | class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler): 15 | 16 | def do_GET(self): 17 | if self.path == '/notfound': 18 | # Example code to return error 19 | self.send_error(404) 20 | return 21 | 22 | self.send_response(200) 23 | self.send_header('content-type', 'text/html; charset=UTF-8') 24 | 25 | content = '''\ 26 | 27 | SPDY FTW 28 | 29 |

SPDY FTW

30 |

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

31 | 32 | '''.encode('UTF-8') 33 | 34 | self.wfile.write(content) 35 | 36 | if __name__ == "__main__": 37 | HOST, PORT = "localhost", 3000 38 | 39 | server = spdylay.ThreadedSPDYServer((HOST, PORT), 40 | MySPDYRequestHandler, 41 | cert_file=CERT_FILE, 42 | key_file=KEY_FILE) 43 | server.start() 44 | -------------------------------------------------------------------------------- /shrpx.conf.sample: -------------------------------------------------------------------------------- 1 | # 2 | # Sample configuration file for Shrpx. 3 | # 4 | # * Line staring '#' is treated as comment. 5 | # 6 | # * The option name in the configuration file is the long command-line 7 | # option name with leading '--' stripped (e.g., frontend). Put '=' 8 | # between option name and value. Don't put extra leading or trailing 9 | # spaces. 10 | # 11 | # * The options which do not take argument in the command-line *take* 12 | # argument in the configuration file. Specify 'yes' as argument 13 | # (e.g., spdy-proxy=yes). If other string is given, it disables the 14 | # option. 15 | # 16 | # * To specify private key and certificate file, use private-key-file 17 | # and certificate-file. See the examples below. 18 | # 19 | # * conf option cannot be used in the configuration file. It will be 20 | # ignored. 21 | # 22 | # Examples: 23 | # 24 | # frontend=0.0.0.0,3000 25 | # backend=127.0.0.1,80 26 | # private-key-file=/path/to/server.key 27 | # certificate-file=/path/to/server.crt 28 | # spdy-proxy=no 29 | # workers=1 30 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | spdycat 2 | spdyd 3 | shrpx 4 | shrpx-unittest 5 | shrpx-unittest.log 6 | shrpx-unittest.trs 7 | test-suite.log 8 | -------------------------------------------------------------------------------- /src/EventPoll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef EVENT_POLL_H 26 | #define EVENT_POLL_H 27 | 28 | #include "spdylay_config.h" 29 | 30 | #ifdef HAVE_EPOLL 31 | # include "EventPoll_epoll.h" 32 | #elif HAVE_KQUEUE 33 | # include "EventPoll_kqueue.h" 34 | #endif // HAVE_KQUEUE 35 | 36 | #endif // EVENT_POLL_H 37 | -------------------------------------------------------------------------------- /src/EventPollEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef EVENT_POLL_EVENT_H 26 | #define EVENT_POLL_EVENT_H 27 | 28 | #include "spdylay_config.h" 29 | 30 | namespace spdylay { 31 | 32 | enum EventPollEvent { 33 | EP_POLLIN = 1, 34 | EP_POLLOUT = 1 << 1, 35 | EP_POLLHUP = 1 << 2, 36 | EP_POLLERR = 1 << 3 37 | }; 38 | 39 | enum EventPollOp { 40 | EP_ADD, 41 | EP_MOD 42 | }; 43 | 44 | } // namespace spdylay 45 | 46 | #endif // EVENT_POLL_EVENT_H 47 | -------------------------------------------------------------------------------- /src/EventPoll_epoll.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "EventPoll_epoll.h" 26 | 27 | #include 28 | 29 | #include 30 | 31 | namespace spdylay { 32 | 33 | EventPoll::EventPoll(size_t max_events) 34 | : max_events_(max_events), num_events_(0) 35 | { 36 | epfd_ = epoll_create(1); 37 | assert(epfd_ != -1); 38 | evlist_ = new epoll_event[max_events_]; 39 | } 40 | 41 | EventPoll::~EventPoll() 42 | { 43 | if(epfd_ != -1) { 44 | close(epfd_); 45 | } 46 | delete [] evlist_; 47 | } 48 | 49 | int EventPoll::poll(int timeout) 50 | { 51 | num_events_ = 0; 52 | int n = epoll_wait(epfd_, evlist_, max_events_, timeout); 53 | if(n > 0) { 54 | num_events_ = n; 55 | } 56 | return n; 57 | } 58 | 59 | size_t EventPoll::get_num_events() 60 | { 61 | return num_events_; 62 | } 63 | 64 | void* EventPoll::get_user_data(size_t p) 65 | { 66 | return evlist_[p].data.ptr; 67 | } 68 | 69 | int EventPoll::get_events(size_t p) 70 | { 71 | int events = 0; 72 | int revents = evlist_[p].events; 73 | if(revents & EPOLLIN) { 74 | events |= EP_POLLIN; 75 | } 76 | if(revents & EPOLLOUT) { 77 | events |= EP_POLLOUT; 78 | } 79 | if(revents & EPOLLHUP) { 80 | events |= EP_POLLHUP; 81 | } 82 | if(revents & EPOLLERR) { 83 | events |= EP_POLLERR; 84 | } 85 | return events; 86 | } 87 | 88 | namespace { 89 | int update_event(int epfd, int op, int fd, int events, void *user_data) 90 | { 91 | epoll_event ev; 92 | ev.events = 0; 93 | if(events & EP_POLLIN) { 94 | ev.events |= EPOLLIN; 95 | } 96 | if(events & EP_POLLOUT) { 97 | ev.events |= EPOLLOUT; 98 | } 99 | ev.data.ptr = user_data; 100 | return epoll_ctl(epfd, op, fd, &ev); 101 | } 102 | } // namespace 103 | 104 | int EventPoll::ctl_event(int op, int fd, int events, void *user_data) 105 | { 106 | if(op == EP_ADD) { 107 | op = EPOLL_CTL_ADD; 108 | } else if(op == EP_MOD) { 109 | op = EPOLL_CTL_MOD; 110 | } else { 111 | return -1; 112 | } 113 | return update_event(epfd_, op, fd, events, user_data); 114 | } 115 | 116 | } // namespace spdylay 117 | -------------------------------------------------------------------------------- /src/EventPoll_epoll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef EVENT_POLL_EPOLL_H 26 | #define EVENT_POLL_EPOLL_H 27 | 28 | #include "spdylay_config.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include "EventPollEvent.h" 35 | 36 | namespace spdylay { 37 | 38 | class EventPoll { 39 | public: 40 | EventPoll(size_t max_events); 41 | ~EventPoll(); 42 | // Returns 0 if this function succeeds, or -1. 43 | // On success 44 | int poll(int timeout); 45 | // Returns number of events detected in previous call of poll(). 46 | size_t get_num_events(); 47 | // Returns events of p-eth event. 48 | int get_events(size_t p); 49 | // Returns user data of p-th event. 50 | void* get_user_data(size_t p); 51 | // Adds/Modifies event to watch. 52 | int ctl_event(int op, int fd, int events, void *user_data); 53 | private: 54 | epoll_event *evlist_; 55 | size_t max_events_; 56 | size_t num_events_; 57 | int epfd_; 58 | }; 59 | 60 | } // namespace spdylay 61 | 62 | #endif // EVENT_POLL_EPOLL_H 63 | -------------------------------------------------------------------------------- /src/EventPoll_kqueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef EVENT_POLL_KQUEUE_H 26 | #define EVENT_POLL_KQUEUE_H 27 | 28 | #include "spdylay_config.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "EventPollEvent.h" 37 | 38 | namespace spdylay { 39 | 40 | class EventPoll { 41 | public: 42 | EventPoll(size_t max_events); 43 | ~EventPoll(); 44 | // Returns 0 if this function succeeds, or -1. 45 | // On success 46 | int poll(int timeout); 47 | // Returns number of events detected in previous call of poll(). 48 | size_t get_num_events(); 49 | // Returns events of p-eth event. 50 | int get_events(size_t p); 51 | // Returns user data of p-th event. 52 | void* get_user_data(size_t p); 53 | // Adds/Modifies event to watch. 54 | int ctl_event(int op, int fd, int events, void *user_data); 55 | private: 56 | int kq_; 57 | size_t max_events_; 58 | struct kevent *evlist_; 59 | size_t num_events_; 60 | }; 61 | 62 | } // namespace spdylay 63 | 64 | #endif // EVENT_POLL_KQUEUE_H 65 | -------------------------------------------------------------------------------- /src/HtmlParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef HTML_PARSER_H 26 | #define HTML_PARSER_H 27 | 28 | #include "spdylay_config.h" 29 | 30 | #include 31 | #include 32 | 33 | #ifdef HAVE_LIBXML2 34 | 35 | #include 36 | 37 | namespace spdylay { 38 | 39 | struct ParserData { 40 | std::string base_uri; 41 | std::vector links; 42 | ParserData(const std::string& base_uri); 43 | }; 44 | 45 | class HtmlParser { 46 | public: 47 | HtmlParser(const std::string& base_uri); 48 | ~HtmlParser(); 49 | int parse_chunk(const char *chunk, size_t size, int fin); 50 | const std::vector& get_links() const; 51 | void clear_links(); 52 | private: 53 | int parse_chunk_internal(const char *chunk, size_t size, int fin); 54 | 55 | std::string base_uri_; 56 | htmlParserCtxtPtr parser_ctx_; 57 | ParserData parser_data_; 58 | }; 59 | 60 | } // namespace spdylay 61 | 62 | #else // !HAVE_LIBXML2 63 | 64 | namespace spdylay { 65 | 66 | class HtmlParser { 67 | public: 68 | HtmlParser(const std::string& base_uri) {} 69 | ~HtmlParser() {} 70 | int parse_chunk(const char *chunk, size_t size, int fin) { return 0; } 71 | const std::vector& get_links() const { return links_; } 72 | void clear_links() {} 73 | private: 74 | std::vector links_; 75 | }; 76 | 77 | } // namespace spdylay 78 | 79 | #endif // !HAVE_LIBXML2 80 | 81 | #endif // HTML_PARSER_H 82 | -------------------------------------------------------------------------------- /src/http-parser/0001-Support-custom-HTTP-version-string-e.g.-ICY.patch: -------------------------------------------------------------------------------- 1 | From 0230de8d757d45dad9ab9fa8cb84613b53eb80b6 Mon Sep 17 00:00:00 2001 2 | From: Tatsuhiro Tsujikawa 3 | Date: Fri, 21 Feb 2014 21:59:40 +0900 4 | Subject: [PATCH 1/3] Support custom HTTP-version string (e.g., ICY) 5 | 6 | --- 7 | http_parser.c | 20 ++++++++++++++++++++ 8 | 1 file changed, 20 insertions(+) 9 | 10 | diff --git a/http_parser.c b/http_parser.c 11 | index cbe8a90..c0825b0 100644 12 | --- a/http_parser.c 13 | +++ b/http_parser.c 14 | @@ -282,6 +282,7 @@ enum state 15 | , s_start_req_or_res 16 | , s_res_or_resp_H 17 | , s_start_res 18 | + , s_res_proto_custom 19 | , s_res_H 20 | , s_res_HT 21 | , s_res_HTT 22 | @@ -761,6 +762,10 @@ reexecute: 23 | break; 24 | 25 | default: 26 | + if(TOKEN(ch)) { 27 | + parser->state = s_res_proto_custom; 28 | + break; 29 | + } 30 | SET_ERRNO(HPE_INVALID_CONSTANT); 31 | goto error; 32 | } 33 | @@ -769,6 +774,21 @@ reexecute: 34 | break; 35 | } 36 | 37 | + /* Custom HTTP-version string (e.g., ICY) */ 38 | + case s_res_proto_custom: 39 | + if (ch == ' ') { 40 | + /* We assume this is HTTP/1.0 */ 41 | + parser->http_major = 1; 42 | + parser->http_minor = 0; 43 | + parser->state = s_res_first_status_code; 44 | + break; 45 | + } 46 | + if (!TOKEN(ch)) { 47 | + SET_ERRNO(HPE_INVALID_CONSTANT); 48 | + goto error; 49 | + } 50 | + break; 51 | + 52 | case s_res_H: 53 | STRICT_CHECK(ch != 'T'); 54 | UPDATE_STATE(s_res_HT); 55 | -- 56 | 2.1.4 57 | 58 | -------------------------------------------------------------------------------- /src/http-parser/0002-Allow-chars-in-32-126-except-for-58-for-TOKEN.patch: -------------------------------------------------------------------------------- 1 | From fad236762ca992a8a4a2b7f6c7077ddb53da5888 Mon Sep 17 00:00:00 2001 2 | From: Tatsuhiro Tsujikawa 3 | Date: Fri, 21 Feb 2014 22:05:34 +0900 4 | Subject: [PATCH 2/3] Allow chars in [32, 126], except for 58 (':'), for TOKEN 5 | 6 | --- 7 | http_parser.c | 12 ++++++------ 8 | 1 file changed, 6 insertions(+), 6 deletions(-) 9 | 10 | diff --git a/http_parser.c b/http_parser.c 11 | index c0825b0..60c992e 100644 12 | --- a/http_parser.c 13 | +++ b/http_parser.c 14 | @@ -196,21 +196,21 @@ static const char tokens[256] = { 15 | /* 24 can 25 em 26 sub 27 esc 28 fs 29 gs 30 rs 31 us */ 16 | 0, 0, 0, 0, 0, 0, 0, 0, 17 | /* 32 sp 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' */ 18 | - 0, '!', 0, '#', '$', '%', '&', '\'', 19 | + ' ', '!', '"', '#', '$', '%', '&', '\'', 20 | /* 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / */ 21 | - 0, 0, '*', '+', 0, '-', '.', 0, 22 | + '(', ')', '*', '+', ',', '-', '.', '/', 23 | /* 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 */ 24 | '0', '1', '2', '3', '4', '5', '6', '7', 25 | /* 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? */ 26 | - '8', '9', 0, 0, 0, 0, 0, 0, 27 | + '8', '9', 0, ';', '<', '=', '>', '?', 28 | /* 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G */ 29 | - 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 30 | + '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 31 | /* 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O */ 32 | 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 33 | /* 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W */ 34 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 35 | /* 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ */ 36 | - 'x', 'y', 'z', 0, 0, 0, '^', '_', 37 | + 'x', 'y', 'z', '[', '\\', ']', '^', '_', 38 | /* 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g */ 39 | '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 40 | /* 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o */ 41 | @@ -218,7 +218,7 @@ static const char tokens[256] = { 42 | /* 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w */ 43 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 44 | /* 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 del */ 45 | - 'x', 'y', 'z', 0, '|', 0, '~', 0 }; 46 | + 'x', 'y', 'z', '{', '|', '}', '~', 0 }; 47 | 48 | 49 | static const int8_t unhex[256] = 50 | -- 51 | 2.1.4 52 | 53 | -------------------------------------------------------------------------------- /src/http-parser/0003-Use-http_parser-for-tunneling-connection-transparent.patch: -------------------------------------------------------------------------------- 1 | From 0bde8052816e615cb4216e5ef07233ee4e625951 Mon Sep 17 00:00:00 2001 2 | From: Tatsuhiro Tsujikawa 3 | Date: Mon, 10 Sep 2012 23:01:26 +0900 4 | Subject: [PATCH 3/3] Use http_parser for tunneling connection transparently 5 | 6 | --- 7 | http_parser.c | 11 ++++++++--- 8 | 1 file changed, 8 insertions(+), 3 deletions(-) 9 | 10 | diff --git a/http_parser.c b/http_parser.c 11 | index 60c992e..f6c84e9 100644 12 | --- a/http_parser.c 13 | +++ b/http_parser.c 14 | @@ -1857,9 +1857,14 @@ reexecute: 15 | if (parser->upgrade && (parser->method == HTTP_CONNECT || 16 | (parser->flags & F_SKIPBODY) || !hasBody)) { 17 | /* Exit, the rest of the message is in a different protocol. */ 18 | - UPDATE_STATE(NEW_MESSAGE()); 19 | - CALLBACK_NOTIFY(message_complete); 20 | - RETURN((p - data) + 1); 21 | + /* We want to use http_parser for tunneling connection 22 | + transparently */ 23 | + /* Read body until EOF */ 24 | + UPDATE_STATE(s_body_identity_eof); 25 | + break; 26 | + /* UPDATE_STATE(NEW_MESSAGE()); */ 27 | + /* CALLBACK_NOTIFY(message_complete); */ 28 | + /* RETURN((p - data) + 1); */ 29 | } 30 | 31 | if (parser->flags & F_SKIPBODY) { 32 | -- 33 | 2.1.4 34 | 35 | -------------------------------------------------------------------------------- /src/http-parser/AUTHORS: -------------------------------------------------------------------------------- 1 | # Authors ordered by first contribution. 2 | Ryan Dahl 3 | Jeremy Hinegardner 4 | Sergey Shepelev 5 | Joe Damato 6 | tomika 7 | Phoenix Sol 8 | Cliff Frey 9 | Ewen Cheslack-Postava 10 | Santiago Gala 11 | Tim Becker 12 | Jeff Terrace 13 | Ben Noordhuis 14 | Nathan Rajlich 15 | Mark Nottingham 16 | Aman Gupta 17 | Tim Becker 18 | Sean Cunningham 19 | Peter Griess 20 | Salman Haq 21 | Cliff Frey 22 | Jon Kolb 23 | Fouad Mardini 24 | Paul Querna 25 | Felix Geisendörfer 26 | koichik 27 | Andre Caron 28 | Ivo Raisr 29 | James McLaughlin 30 | David Gwynne 31 | Thomas LE ROUX 32 | Randy Rizun 33 | Andre Louis Caron 34 | Simon Zimmermann 35 | Erik Dubbelboer 36 | Martell Malone 37 | Bertrand Paquet 38 | BogDan Vatra 39 | Peter Faiman 40 | Corey Richardson 41 | Tóth Tamás 42 | Cam Swords 43 | Chris Dickinson 44 | Uli Köhler 45 | Charlie Somerville 46 | Patrik Stutz 47 | Fedor Indutny 48 | runner 49 | Alexis Campailla 50 | David Wragg 51 | Vinnie Falco 52 | Alex Butum 53 | Rex Feng 54 | Alex Kocharin 55 | Mark Koopman 56 | Helge Heß 57 | Alexis La Goutte 58 | George Miroshnykov 59 | Maciej Małecki 60 | Marc O'Morain 61 | Jeff Pinner 62 | Timothy J Fontaine 63 | Akagi201 64 | Romain Giraud 65 | Jay Satiro 66 | Arne Steen 67 | Kjell Schubert 68 | -------------------------------------------------------------------------------- /src/http-parser/CONTRIBUTIONS: -------------------------------------------------------------------------------- 1 | Contributors must agree to the Contributor License Agreement before patches 2 | can be accepted. 3 | 4 | http://spreadsheets2.google.com/viewform?hl=en&formkey=dDJXOGUwbzlYaWM4cHN1MERwQS1CSnc6MQ 5 | -------------------------------------------------------------------------------- /src/http-parser/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright 2 | Igor Sysoev. 3 | 4 | Additional changes are licensed under the same terms as NGINX and 5 | copyright Joyent, Inc. and other Node contributors. All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to 9 | deal in the Software without restriction, including without limitation the 10 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | sell copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 | IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/http-parser/contrib/url_parser.c: -------------------------------------------------------------------------------- 1 | #include "http_parser.h" 2 | #include 3 | #include 4 | 5 | void 6 | dump_url (const char *url, const struct http_parser_url *u) 7 | { 8 | unsigned int i; 9 | 10 | printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port); 11 | for (i = 0; i < UF_MAX; i++) { 12 | if ((u->field_set & (1 << i)) == 0) { 13 | printf("\tfield_data[%u]: unset\n", i); 14 | continue; 15 | } 16 | 17 | printf("\tfield_data[%u]: off: %u, len: %u, part: %.*s\n", 18 | i, 19 | u->field_data[i].off, 20 | u->field_data[i].len, 21 | u->field_data[i].len, 22 | url + u->field_data[i].off); 23 | } 24 | } 25 | 26 | int main(int argc, char ** argv) { 27 | struct http_parser_url u; 28 | int len, connect, result; 29 | 30 | if (argc != 3) { 31 | printf("Syntax : %s connect|get url\n", argv[0]); 32 | return 1; 33 | } 34 | len = strlen(argv[2]); 35 | connect = strcmp("connect", argv[1]) == 0 ? 1 : 0; 36 | printf("Parsing %s, connect %d\n", argv[2], connect); 37 | 38 | result = http_parser_parse_url(argv[2], len, connect, &u); 39 | if (result != 0) { 40 | printf("Parse error : %d\n", result); 41 | return result; 42 | } 43 | printf("Parse ok, result : \n"); 44 | dump_url(argv[2], &u); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /src/http-parser/http_parser.gyp: -------------------------------------------------------------------------------- 1 | # This file is used with the GYP meta build system. 2 | # http://code.google.com/p/gyp/ 3 | # To build try this: 4 | # svn co http://gyp.googlecode.com/svn/trunk gyp 5 | # ./gyp/gyp -f make --depth=`pwd` http_parser.gyp 6 | # ./out/Debug/test 7 | { 8 | 'target_defaults': { 9 | 'default_configuration': 'Debug', 10 | 'configurations': { 11 | # TODO: hoist these out and put them somewhere common, because 12 | # RuntimeLibrary MUST MATCH across the entire project 13 | 'Debug': { 14 | 'defines': [ 'DEBUG', '_DEBUG' ], 15 | 'cflags': [ '-Wall', '-Wextra', '-O0', '-g', '-ftrapv' ], 16 | 'msvs_settings': { 17 | 'VCCLCompilerTool': { 18 | 'RuntimeLibrary': 1, # static debug 19 | }, 20 | }, 21 | }, 22 | 'Release': { 23 | 'defines': [ 'NDEBUG' ], 24 | 'cflags': [ '-Wall', '-Wextra', '-O3' ], 25 | 'msvs_settings': { 26 | 'VCCLCompilerTool': { 27 | 'RuntimeLibrary': 0, # static release 28 | }, 29 | }, 30 | } 31 | }, 32 | 'msvs_settings': { 33 | 'VCCLCompilerTool': { 34 | }, 35 | 'VCLibrarianTool': { 36 | }, 37 | 'VCLinkerTool': { 38 | 'GenerateDebugInformation': 'true', 39 | }, 40 | }, 41 | 'conditions': [ 42 | ['OS == "win"', { 43 | 'defines': [ 44 | 'WIN32' 45 | ], 46 | }] 47 | ], 48 | }, 49 | 50 | 'targets': [ 51 | { 52 | 'target_name': 'http_parser', 53 | 'type': 'static_library', 54 | 'include_dirs': [ '.' ], 55 | 'direct_dependent_settings': { 56 | 'defines': [ 'HTTP_PARSER_STRICT=0' ], 57 | 'include_dirs': [ '.' ], 58 | }, 59 | 'defines': [ 'HTTP_PARSER_STRICT=0' ], 60 | 'sources': [ './http_parser.c', ], 61 | 'conditions': [ 62 | ['OS=="win"', { 63 | 'msvs_settings': { 64 | 'VCCLCompilerTool': { 65 | # Compile as C++. http_parser.c is actually C99, but C++ is 66 | # close enough in this case. 67 | 'CompileAs': 2, 68 | }, 69 | }, 70 | }] 71 | ], 72 | }, 73 | 74 | { 75 | 'target_name': 'http_parser_strict', 76 | 'type': 'static_library', 77 | 'include_dirs': [ '.' ], 78 | 'direct_dependent_settings': { 79 | 'defines': [ 'HTTP_PARSER_STRICT=1' ], 80 | 'include_dirs': [ '.' ], 81 | }, 82 | 'defines': [ 'HTTP_PARSER_STRICT=1' ], 83 | 'sources': [ './http_parser.c', ], 84 | 'conditions': [ 85 | ['OS=="win"', { 86 | 'msvs_settings': { 87 | 'VCCLCompilerTool': { 88 | # Compile as C++. http_parser.c is actually C99, but C++ is 89 | # close enough in this case. 90 | 'CompileAs': 2, 91 | }, 92 | }, 93 | }] 94 | ], 95 | }, 96 | 97 | { 98 | 'target_name': 'test-nonstrict', 99 | 'type': 'executable', 100 | 'dependencies': [ 'http_parser' ], 101 | 'sources': [ 'test.c' ] 102 | }, 103 | 104 | { 105 | 'target_name': 'test-strict', 106 | 'type': 'executable', 107 | 'dependencies': [ 'http_parser_strict' ], 108 | 'sources': [ 'test.c' ] 109 | } 110 | ] 111 | } 112 | -------------------------------------------------------------------------------- /src/shrpx-unittest.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2013 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | /* include test cases' include files here */ 31 | #include "shrpx_ssl_test.h" 32 | 33 | static int init_suite1(void) 34 | { 35 | return 0; 36 | } 37 | 38 | static int clean_suite1(void) 39 | { 40 | return 0; 41 | } 42 | 43 | 44 | int main(int argc, char* argv[]) 45 | { 46 | CU_pSuite pSuite = NULL; 47 | unsigned int num_tests_failed; 48 | 49 | OpenSSL_add_all_algorithms(); 50 | SSL_load_error_strings(); 51 | SSL_library_init(); 52 | 53 | /* initialize the CUnit test registry */ 54 | if (CUE_SUCCESS != CU_initialize_registry()) 55 | return CU_get_error(); 56 | 57 | /* add a suite to the registry */ 58 | pSuite = CU_add_suite("shrpx_TestSuite", init_suite1, clean_suite1); 59 | if (NULL == pSuite) { 60 | CU_cleanup_registry(); 61 | return CU_get_error(); 62 | } 63 | 64 | /* add the tests to the suite */ 65 | if(!CU_add_test(pSuite, "ssl_create_lookup_tree", 66 | shrpx::test_shrpx_ssl_create_lookup_tree) || 67 | !CU_add_test(pSuite, "ssl_cert_lookup_tree_add_cert_from_file", 68 | shrpx::test_shrpx_ssl_cert_lookup_tree_add_cert_from_file)) { 69 | CU_cleanup_registry(); 70 | return CU_get_error(); 71 | } 72 | 73 | /* Run all tests using the CUnit Basic interface */ 74 | CU_basic_set_mode(CU_BRM_VERBOSE); 75 | CU_basic_run_tests(); 76 | num_tests_failed = CU_get_number_of_tests_failed(); 77 | CU_cleanup_registry(); 78 | if(CU_get_error() == CUE_SUCCESS) { 79 | return num_tests_failed; 80 | } else { 81 | printf("CUnit Error: %s\n", CU_get_error_msg()); 82 | return CU_get_error(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/shrpx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_H 26 | #define SHRPX_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif // HAVE_CONFIG_H 31 | 32 | #include 33 | 34 | #include "shrpx_log.h" 35 | 36 | #define DIE() \ 37 | assert(0); 38 | 39 | #define SHRPX_READ_WATERMARK (64*1024) 40 | 41 | #endif // SHRPX_H 42 | -------------------------------------------------------------------------------- /src/shrpx_accesslog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_ACCESSLOG_H 26 | #define SHRPX_ACCESSLOG_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | namespace shrpx { 33 | 34 | class Downstream; 35 | 36 | void upstream_connect(const std::string& client_ip); 37 | void upstream_response(const std::string& client_ip, int status_code, 38 | Downstream *downstream); 39 | 40 | } // namespace shrpx 41 | 42 | #endif // SHRPX_LOG_H 43 | -------------------------------------------------------------------------------- /src/shrpx_client_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_CLIENT_HANDLER_H 26 | #define SHRPX_CLIENT_HANDLER_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | namespace shrpx { 38 | 39 | class Upstream; 40 | class DownstreamConnection; 41 | class SpdySession; 42 | 43 | class ClientHandler { 44 | public: 45 | ClientHandler(bufferevent *bev, 46 | bufferevent_rate_limit_group *rate_limit_group, 47 | int fd, SSL *ssl, const char *ipaddr); 48 | ~ClientHandler(); 49 | int on_read(); 50 | int on_event(); 51 | bufferevent* get_bev() const; 52 | event_base* get_evbase() const; 53 | void set_bev_cb(bufferevent_data_cb readcb, bufferevent_data_cb writecb, 54 | bufferevent_event_cb eventcb); 55 | void set_upstream_timeouts(const timeval *read_timeout, 56 | const timeval *write_timeout); 57 | int validate_next_proto(); 58 | const std::string& get_ipaddr() const; 59 | bool get_should_close_after_write() const; 60 | void set_should_close_after_write(bool f); 61 | Upstream* get_upstream(); 62 | 63 | void pool_downstream_connection(DownstreamConnection *dconn); 64 | void remove_downstream_connection(DownstreamConnection *dconn); 65 | DownstreamConnection* get_downstream_connection(); 66 | size_t get_outbuf_length(); 67 | SSL* get_ssl() const; 68 | void set_spdy_session(SpdySession *spdy); 69 | SpdySession* get_spdy_session() const; 70 | void set_tls_handshake(bool f); 71 | bool get_tls_handshake() const; 72 | void set_tls_renegotiation(bool f); 73 | bool get_tls_renegotiation() const; 74 | private: 75 | std::set dconn_pool_; 76 | std::string ipaddr_; 77 | bufferevent *bev_; 78 | SSL *ssl_; 79 | event *reneg_shutdown_timerev_; 80 | Upstream *upstream_; 81 | // Shared SPDY session for each thread. NULL if backend is not 82 | // SPDY. Not deleted by this object. 83 | SpdySession *spdy_; 84 | int fd_; 85 | bool should_close_after_write_; 86 | bool tls_handshake_; 87 | bool tls_renegotiation_; 88 | }; 89 | 90 | } // namespace shrpx 91 | 92 | #endif // SHRPX_CLIENT_HANDLER_H 93 | -------------------------------------------------------------------------------- /src/shrpx_downstream_connection.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "shrpx_downstream_connection.h" 26 | 27 | #include "shrpx_client_handler.h" 28 | #include "shrpx_downstream.h" 29 | 30 | namespace shrpx { 31 | 32 | DownstreamConnection::DownstreamConnection(ClientHandler *client_handler) 33 | : client_handler_(client_handler), 34 | downstream_(0) 35 | {} 36 | 37 | DownstreamConnection::~DownstreamConnection() 38 | {} 39 | 40 | ClientHandler* DownstreamConnection::get_client_handler() 41 | { 42 | return client_handler_; 43 | } 44 | 45 | Downstream* DownstreamConnection::get_downstream() 46 | { 47 | return downstream_; 48 | } 49 | 50 | } // namespace shrpx 51 | -------------------------------------------------------------------------------- /src/shrpx_downstream_connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_DOWNSTREAM_CONNECTION_H 26 | #define SHRPX_DOWNSTREAM_CONNECTION_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include "shrpx_io_control.h" 31 | 32 | namespace shrpx { 33 | 34 | class ClientHandler; 35 | class Downstream; 36 | 37 | class DownstreamConnection { 38 | public: 39 | DownstreamConnection(ClientHandler *client_handler); 40 | virtual ~DownstreamConnection(); 41 | virtual int attach_downstream(Downstream *downstream) = 0; 42 | virtual void detach_downstream(Downstream *downstream) = 0; 43 | 44 | virtual int push_request_headers() = 0; 45 | virtual int push_upload_data_chunk(const uint8_t *data, size_t datalen) = 0; 46 | virtual int end_upload_data() = 0; 47 | 48 | virtual void pause_read(IOCtrlReason reason) = 0; 49 | virtual int resume_read(IOCtrlReason reason) = 0; 50 | virtual void force_resume_read() = 0; 51 | 52 | virtual bool get_output_buffer_full() = 0; 53 | 54 | virtual int on_read() = 0; 55 | virtual int on_write() = 0; 56 | 57 | ClientHandler* get_client_handler(); 58 | Downstream* get_downstream(); 59 | protected: 60 | ClientHandler *client_handler_; 61 | Downstream *downstream_; 62 | }; 63 | 64 | } // namespace shrpx 65 | 66 | #endif // SHRPX_DOWNSTREAM_CONNECTION_H 67 | -------------------------------------------------------------------------------- /src/shrpx_downstream_queue.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "shrpx_downstream_queue.h" 26 | 27 | #include 28 | 29 | #include "shrpx_downstream.h" 30 | 31 | namespace shrpx { 32 | 33 | DownstreamQueue::DownstreamQueue() 34 | {} 35 | 36 | DownstreamQueue::~DownstreamQueue() 37 | { 38 | for(std::map::iterator i = downstreams_.begin(); 39 | i != downstreams_.end(); ++i) { 40 | delete (*i).second; 41 | } 42 | } 43 | 44 | void DownstreamQueue::add(Downstream *downstream) 45 | { 46 | downstreams_[downstream->get_stream_id()] = downstream; 47 | } 48 | 49 | void DownstreamQueue::remove(Downstream *downstream) 50 | { 51 | downstreams_.erase(downstream->get_stream_id()); 52 | } 53 | 54 | Downstream* DownstreamQueue::find(int32_t stream_id) 55 | { 56 | std::map::iterator i = downstreams_.find(stream_id); 57 | if(i == downstreams_.end()) { 58 | return 0; 59 | } else { 60 | return (*i).second; 61 | } 62 | } 63 | 64 | } // namespace shrpx 65 | -------------------------------------------------------------------------------- /src/shrpx_downstream_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_DOWNSTREAM_QUEUE_H 26 | #define SHRPX_DOWNSTREAM_QUEUE_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | namespace shrpx { 35 | 36 | class Downstream; 37 | 38 | class DownstreamQueue { 39 | public: 40 | DownstreamQueue(); 41 | ~DownstreamQueue(); 42 | void add(Downstream *downstream); 43 | void remove(Downstream *downstream); 44 | Downstream* find(int32_t stream_id); 45 | private: 46 | std::map downstreams_; 47 | }; 48 | 49 | } // namespace shrpx 50 | 51 | #endif // SHRPX_DOWNSTREAM_QUEUE_H 52 | -------------------------------------------------------------------------------- /src/shrpx_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_ERROR_H 26 | #define SHRPX_ERROR_H 27 | 28 | #include "shrpx.h" 29 | 30 | namespace shrpx { 31 | 32 | enum ErrorCode { 33 | SHRPX_ERR_SUCCESS = 0, 34 | SHRPX_ERR_UNKNOWN = -1, 35 | SHRPX_ERR_HTTP_PARSE = -2, 36 | SHRPX_ERR_NETWORK = -3 37 | }; 38 | 39 | } // namespace shrpx 40 | 41 | #endif // SHRPX_ERROR_H 42 | -------------------------------------------------------------------------------- /src/shrpx_http.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_HTTP_H 26 | #define SHRPX_HTTP_H 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include "http-parser/http_parser.h" 33 | 34 | namespace shrpx { 35 | 36 | namespace http { 37 | 38 | std::string get_status_string(unsigned int status_code); 39 | 40 | std::string create_error_html(unsigned int status_code); 41 | 42 | std::string create_via_header_value(int major, int minor); 43 | 44 | void capitalize(std::string& s, size_t offset); 45 | 46 | // Returns false if |value| contains \r or \n. 47 | bool check_header_value(const char *value); 48 | 49 | void sanitize_header_value(std::string& s, size_t offset); 50 | 51 | // Adds ANSI color codes to HTTP headers |hdrs|. 52 | std::string colorizeHeaders(const char *hdrs); 53 | 54 | // Copies the |field| component value from |u| and |url| to the 55 | // |dest|. If |u| does not have |field|, then this function does 56 | // nothing. 57 | void copy_url_component(std::string& dest, http_parser_url *u, int field, 58 | const char* url); 59 | 60 | // Return positive window_size_increment if WINDOW_UPDATE should be 61 | // sent for the stream |stream_id|. If |stream_id| == 0, this function 62 | // determines the necessity of the WINDOW_UPDATE for a connection. 63 | // The receiver window size is given in the |window_size|. 64 | // 65 | // If the function determines WINDOW_UPDATE is not necessary at the 66 | // moment, it returns -1. 67 | int32_t determine_window_update_transmission(spdylay_session *session, 68 | int32_t stream_id, 69 | int32_t window_size); 70 | 71 | } // namespace http 72 | 73 | } // namespace shrpx 74 | 75 | #endif // SHRPX_HTTP_H 76 | -------------------------------------------------------------------------------- /src/shrpx_http_downstream_connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_HTTP_DOWNSTREAM_CONNECTION_H 26 | #define SHRPX_HTTP_DOWNSTREAM_CONNECTION_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | #include 32 | 33 | #include "http-parser/http_parser.h" 34 | 35 | #include "shrpx_downstream_connection.h" 36 | #include "shrpx_io_control.h" 37 | 38 | namespace shrpx { 39 | 40 | class HttpDownstreamConnection : public DownstreamConnection { 41 | public: 42 | HttpDownstreamConnection(ClientHandler *client_handler); 43 | virtual ~HttpDownstreamConnection(); 44 | virtual int attach_downstream(Downstream *downstream); 45 | virtual void detach_downstream(Downstream *downstream); 46 | 47 | virtual int push_request_headers(); 48 | virtual int push_upload_data_chunk(const uint8_t *data, size_t datalen); 49 | virtual int end_upload_data(); 50 | 51 | virtual void pause_read(IOCtrlReason reason); 52 | virtual int resume_read(IOCtrlReason reason); 53 | virtual void force_resume_read(); 54 | 55 | virtual bool get_output_buffer_full(); 56 | 57 | virtual int on_read(); 58 | virtual int on_write(); 59 | 60 | bufferevent* get_bev(); 61 | private: 62 | bufferevent *bev_; 63 | IOControl ioctrl_; 64 | http_parser *response_htp_; 65 | }; 66 | 67 | } // namespace shrpx 68 | 69 | #endif // SHRPX_HTTP_DOWNSTREAM_CONNECTION_H 70 | -------------------------------------------------------------------------------- /src/shrpx_https_upstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_HTTPS_UPSTREAM_H 26 | #define SHRPX_HTTPS_UPSTREAM_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include "http-parser/http_parser.h" 33 | 34 | #include "shrpx_upstream.h" 35 | 36 | namespace shrpx { 37 | 38 | class ClientHandler; 39 | 40 | class HttpsUpstream : public Upstream { 41 | public: 42 | HttpsUpstream(ClientHandler *handler); 43 | virtual ~HttpsUpstream(); 44 | virtual int on_read(); 45 | virtual int on_write(); 46 | virtual int on_event(); 47 | //int send(); 48 | virtual ClientHandler* get_client_handler() const; 49 | virtual bufferevent_data_cb get_downstream_readcb(); 50 | virtual bufferevent_data_cb get_downstream_writecb(); 51 | virtual bufferevent_event_cb get_downstream_eventcb(); 52 | void attach_downstream(Downstream *downstream); 53 | void delete_downstream(); 54 | Downstream* get_downstream() const; 55 | int error_reply(unsigned int status_code); 56 | 57 | virtual void pause_read(IOCtrlReason reason); 58 | virtual int resume_read(IOCtrlReason reason, Downstream *downstream); 59 | 60 | virtual int on_downstream_header_complete(Downstream *downstream); 61 | virtual int on_downstream_body(Downstream *downstream, 62 | const uint8_t *data, size_t len); 63 | virtual int on_downstream_body_complete(Downstream *downstream); 64 | 65 | void reset_current_header_length(); 66 | private: 67 | ClientHandler *handler_; 68 | http_parser *htp_; 69 | size_t current_header_length_; 70 | Downstream *downstream_; 71 | IOControl ioctrl_; 72 | }; 73 | 74 | } // namespace shrpx 75 | 76 | #endif // SHRPX_HTTPS_UPSTREAM_H 77 | -------------------------------------------------------------------------------- /src/shrpx_io_control.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "shrpx_io_control.h" 26 | 27 | #include 28 | 29 | namespace shrpx { 30 | 31 | IOControl::IOControl(bufferevent *bev) 32 | : bev_(bev), 33 | rdbits_(0) 34 | {} 35 | 36 | IOControl::~IOControl() 37 | {} 38 | 39 | void IOControl::set_bev(bufferevent *bev) 40 | { 41 | bev_ = bev; 42 | } 43 | 44 | void IOControl::pause_read(IOCtrlReason reason) 45 | { 46 | rdbits_ |= reason; 47 | if(bev_) { 48 | bufferevent_disable(bev_, EV_READ); 49 | } 50 | } 51 | 52 | bool IOControl::resume_read(IOCtrlReason reason) 53 | { 54 | rdbits_ &= ~reason; 55 | if(rdbits_ == 0) { 56 | if(bev_) { 57 | bufferevent_enable(bev_, EV_READ); 58 | } 59 | return true; 60 | } else { 61 | return false; 62 | } 63 | } 64 | 65 | void IOControl::force_resume_read() 66 | { 67 | rdbits_ = 0; 68 | if(bev_) { 69 | bufferevent_enable(bev_, EV_READ); 70 | } 71 | } 72 | 73 | } // namespace shrpx 74 | -------------------------------------------------------------------------------- /src/shrpx_io_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_IO_CONTROL_H 26 | #define SHRPX_IO_CONTROL_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | namespace shrpx { 36 | 37 | enum IOCtrlReason { 38 | SHRPX_NO_BUFFER = 1 << 0, 39 | SHRPX_MSG_BLOCK = 1 << 1 40 | }; 41 | 42 | class IOControl { 43 | public: 44 | IOControl(bufferevent *bev); 45 | ~IOControl(); 46 | void set_bev(bufferevent *bev); 47 | void pause_read(IOCtrlReason reason); 48 | // Returns true if read operation is enabled after this call 49 | bool resume_read(IOCtrlReason reason); 50 | // Clear all pause flags and enable read 51 | void force_resume_read(); 52 | private: 53 | bufferevent *bev_; 54 | uint32_t rdbits_; 55 | }; 56 | 57 | } // namespace shrpx 58 | 59 | #endif // SHRPX_IO_CONTROL_H 60 | -------------------------------------------------------------------------------- /src/shrpx_listen_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_LISTEN_HANDLER_H 26 | #define SHRPX_LISTEN_HANDLER_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | namespace shrpx { 39 | 40 | struct WorkerInfo { 41 | int sv[2]; 42 | SSL_CTX *sv_ssl_ctx; 43 | SSL_CTX *cl_ssl_ctx; 44 | bufferevent *bev; 45 | }; 46 | 47 | class SpdySession; 48 | 49 | class ListenHandler { 50 | public: 51 | ListenHandler(event_base *evbase, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx); 52 | ~ListenHandler(); 53 | int accept_connection(evutil_socket_t fd, sockaddr *addr, int addrlen); 54 | void create_worker_thread(size_t num); 55 | event_base* get_evbase() const; 56 | int create_spdy_session(); 57 | private: 58 | event_base *evbase_; 59 | // The frontend server SSL_CTX 60 | SSL_CTX *sv_ssl_ctx_; 61 | // The backend server SSL_CTX 62 | SSL_CTX *cl_ssl_ctx_; 63 | unsigned int worker_round_robin_cnt_; 64 | WorkerInfo *workers_; 65 | size_t num_worker_; 66 | // Shared backend SPDY session. NULL if multi-threaded. In 67 | // multi-threaded case, see shrpx_worker.cc. 68 | SpdySession *spdy_; 69 | bufferevent_rate_limit_group *rate_limit_group_; 70 | }; 71 | 72 | } // namespace shrpx 73 | 74 | #endif // SHRPX_LISTEN_HANDLER_H 75 | -------------------------------------------------------------------------------- /src/shrpx_log.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "shrpx_log.h" 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "shrpx_config.h" 33 | 34 | namespace shrpx { 35 | 36 | namespace { 37 | const char *SEVERITY_STR[] = { 38 | "INFO", "WARN", "ERROR", "FATAL" 39 | }; 40 | } // namespace 41 | 42 | namespace { 43 | const char *SEVERITY_COLOR[] = { 44 | "\033[1;32m", // INFO 45 | "\033[1;33m", // WARN 46 | "\033[1;31m", // ERROR 47 | "\033[1;35m", // FATAL 48 | }; 49 | } // namespace 50 | 51 | int Log::severity_thres_ = WARNING; 52 | 53 | void Log::set_severity_level(int severity) 54 | { 55 | severity_thres_ = severity; 56 | } 57 | 58 | int Log::set_severity_level_by_name(const char *name) 59 | { 60 | for(size_t i = 0, max = sizeof(SEVERITY_STR)/sizeof(char*); i < max; ++i) { 61 | if(strcmp(SEVERITY_STR[i], name) == 0) { 62 | severity_thres_ = i; 63 | return 0; 64 | } 65 | } 66 | return -1; 67 | } 68 | 69 | int severity_to_syslog_level(int severity) 70 | { 71 | switch(severity) { 72 | case(INFO): 73 | return LOG_INFO; 74 | case(WARNING): 75 | return LOG_WARNING; 76 | case(ERROR): 77 | return LOG_ERR; 78 | case(FATAL): 79 | return LOG_CRIT; 80 | default: 81 | return -1; 82 | } 83 | } 84 | 85 | Log::Log(int severity, const char *filename, int linenum) 86 | : filename_(filename), 87 | severity_(severity), 88 | linenum_(linenum) 89 | {} 90 | 91 | Log::~Log() 92 | { 93 | if(log_enabled(severity_)) { 94 | fprintf(stderr, "[%s%s%s] %s\n %s(%s:%d)%s\n", 95 | get_config()->tty ? SEVERITY_COLOR[severity_] : "", 96 | SEVERITY_STR[severity_], 97 | get_config()->tty ? "\033[0m" : "", 98 | stream_.str().c_str(), 99 | get_config()->tty ? "\033[1;30m" : "", 100 | filename_, linenum_, 101 | get_config()->tty ? "\033[0m" : ""); 102 | fflush(stderr); 103 | if(get_config()->use_syslog) { 104 | syslog(severity_to_syslog_level(severity_), "%s (%s:%d)\n", 105 | stream_.str().c_str(), filename_, linenum_); 106 | } 107 | } 108 | } 109 | 110 | } // namespace shrpx 111 | -------------------------------------------------------------------------------- /src/shrpx_spdy_downstream_connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_SPDY_DOWNSTREAM_CONNECTION_H 26 | #define SHRPX_SPDY_DOWNSTREAM_CONNECTION_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include "shrpx_downstream_connection.h" 35 | 36 | namespace shrpx { 37 | 38 | struct StreamData; 39 | class SpdySession; 40 | 41 | class SpdyDownstreamConnection : public DownstreamConnection { 42 | public: 43 | SpdyDownstreamConnection(ClientHandler *client_handler); 44 | virtual ~SpdyDownstreamConnection(); 45 | virtual int attach_downstream(Downstream *downstream); 46 | virtual void detach_downstream(Downstream *downstream); 47 | 48 | virtual int push_request_headers(); 49 | virtual int push_upload_data_chunk(const uint8_t *data, size_t datalen); 50 | virtual int end_upload_data(); 51 | 52 | virtual void pause_read(IOCtrlReason reason) {} 53 | virtual int resume_read(IOCtrlReason reason); 54 | virtual void force_resume_read() {} 55 | 56 | virtual bool get_output_buffer_full(); 57 | 58 | virtual int on_read(); 59 | virtual int on_write(); 60 | 61 | int send(); 62 | 63 | int init_request_body_buf(); 64 | evbuffer* get_request_body_buf() const; 65 | 66 | void attach_stream_data(StreamData *sd); 67 | StreamData* detach_stream_data(); 68 | 69 | int submit_rst_stream(Downstream *downstream); 70 | private: 71 | SpdySession *spdy_; 72 | evbuffer *request_body_buf_; 73 | StreamData *sd_; 74 | }; 75 | 76 | } // namespace shrpx 77 | 78 | #endif // SHRPX_SPDY_DOWNSTREAM_CONNECTION_H 79 | -------------------------------------------------------------------------------- /src/shrpx_spdy_upstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_SPDY_UPSTREAM_H 26 | #define SHRPX_SPDY_UPSTREAM_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include "shrpx_upstream.h" 33 | #include "shrpx_downstream_queue.h" 34 | 35 | namespace shrpx { 36 | 37 | class ClientHandler; 38 | 39 | class SpdyUpstream : public Upstream { 40 | public: 41 | SpdyUpstream(uint16_t version, ClientHandler *handler); 42 | virtual ~SpdyUpstream(); 43 | virtual int on_read(); 44 | virtual int on_write(); 45 | virtual int on_event(); 46 | int send(); 47 | virtual ClientHandler* get_client_handler() const; 48 | virtual bufferevent_data_cb get_downstream_readcb(); 49 | virtual bufferevent_data_cb get_downstream_writecb(); 50 | virtual bufferevent_event_cb get_downstream_eventcb(); 51 | void add_downstream(Downstream *downstream); 52 | void remove_downstream(Downstream *downstream); 53 | Downstream* find_downstream(int32_t stream_id); 54 | 55 | spdylay_session* get_spdy_session(); 56 | 57 | int rst_stream(Downstream *downstream, int status_code); 58 | int window_update(Downstream *downstream, int32_t delta); 59 | int error_reply(Downstream *downstream, unsigned int status_code); 60 | 61 | virtual void pause_read(IOCtrlReason reason); 62 | virtual int resume_read(IOCtrlReason reason, Downstream *downstream); 63 | 64 | virtual int on_downstream_header_complete(Downstream *downstream); 65 | virtual int on_downstream_body(Downstream *downstream, 66 | const uint8_t *data, size_t len); 67 | virtual int on_downstream_body_complete(Downstream *downstream); 68 | 69 | bool get_flow_control() const; 70 | private: 71 | DownstreamQueue downstream_queue_; 72 | ClientHandler *handler_; 73 | spdylay_session *session_; 74 | bool flow_control_; 75 | }; 76 | 77 | } // namespace shrpx 78 | 79 | #endif // SHRPX_SPDY_UPSTREAM_H 80 | -------------------------------------------------------------------------------- /src/shrpx_ssl_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2013 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_SSL_TEST_H 26 | #define SHRPX_SSL_TEST_H 27 | 28 | namespace shrpx { 29 | 30 | void test_shrpx_ssl_create_lookup_tree(void); 31 | void test_shrpx_ssl_cert_lookup_tree_add_cert_from_file(void); 32 | 33 | } // namespace shrpx 34 | 35 | #endif /* SHRPX_SSL_TEST_H */ 36 | -------------------------------------------------------------------------------- /src/shrpx_thread_event_receiver.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "shrpx_thread_event_receiver.h" 26 | 27 | #include 28 | 29 | #include "shrpx_ssl.h" 30 | #include "shrpx_log.h" 31 | #include "shrpx_client_handler.h" 32 | #include "shrpx_spdy_session.h" 33 | 34 | namespace shrpx { 35 | 36 | ThreadEventReceiver::ThreadEventReceiver(event_base *evbase, 37 | SSL_CTX *ssl_ctx, 38 | SpdySession *spdy) 39 | : evbase_(evbase), 40 | ssl_ctx_(ssl_ctx), 41 | spdy_(spdy), 42 | rate_limit_group_(bufferevent_rate_limit_group_new 43 | (evbase_, get_config()->worker_rate_limit_cfg)) 44 | {} 45 | 46 | ThreadEventReceiver::~ThreadEventReceiver() 47 | { 48 | bufferevent_rate_limit_group_free(rate_limit_group_); 49 | } 50 | 51 | void ThreadEventReceiver::on_read(bufferevent *bev) 52 | { 53 | evbuffer *input = bufferevent_get_input(bev); 54 | while(evbuffer_get_length(input) >= sizeof(WorkerEvent)) { 55 | WorkerEvent wev; 56 | int nread = evbuffer_remove(input, &wev, sizeof(wev)); 57 | if(nread != sizeof(wev)) { 58 | TLOG(FATAL, this) << "evbuffer_remove() removed fewer bytes. Expected:" 59 | << sizeof(wev) << " Actual:" << nread; 60 | continue; 61 | } 62 | if(LOG_ENABLED(INFO)) { 63 | TLOG(INFO, this) << "WorkerEvent: client_fd=" << wev.client_fd 64 | << ", addrlen=" << wev.client_addrlen; 65 | } 66 | event_base *evbase = bufferevent_get_base(bev); 67 | ClientHandler *client_handler; 68 | client_handler = ssl::accept_connection(evbase, rate_limit_group_, 69 | ssl_ctx_, 70 | wev.client_fd, 71 | &wev.client_addr.sa, 72 | wev.client_addrlen); 73 | if(client_handler) { 74 | client_handler->set_spdy_session(spdy_); 75 | if(LOG_ENABLED(INFO)) { 76 | TLOG(INFO, this) << "CLIENT_HANDLER:" << client_handler << " created"; 77 | } 78 | } else { 79 | if(LOG_ENABLED(INFO)) { 80 | TLOG(ERROR, this) << "ClientHandler creation failed"; 81 | } 82 | close(wev.client_fd); 83 | } 84 | } 85 | } 86 | 87 | } // namespace shrpx 88 | -------------------------------------------------------------------------------- /src/shrpx_thread_event_receiver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_THREAD_EVENT_RECEIVER_H 26 | #define SHRPX_THREAD_EVENT_RECEIVER_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include "shrpx_config.h" 35 | 36 | namespace shrpx { 37 | 38 | class SpdySession; 39 | 40 | struct WorkerEvent { 41 | sockaddr_union client_addr; 42 | size_t client_addrlen; 43 | evutil_socket_t client_fd; 44 | }; 45 | 46 | class ThreadEventReceiver { 47 | public: 48 | ThreadEventReceiver(event_base *evbase, SSL_CTX *ssl_ctx, 49 | SpdySession *spdy); 50 | ~ThreadEventReceiver(); 51 | void on_read(bufferevent *bev); 52 | private: 53 | event_base *evbase_; 54 | SSL_CTX *ssl_ctx_; 55 | // Shared SPDY session for each thread. NULL if not client mode. Not 56 | // deleted by this object. 57 | SpdySession *spdy_; 58 | bufferevent_rate_limit_group *rate_limit_group_; 59 | }; 60 | 61 | } // namespace shrpx 62 | 63 | #endif // SHRPX_THREAD_EVENT_RECEIVER_H 64 | -------------------------------------------------------------------------------- /src/shrpx_upstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_UPSTREAM_H 26 | #define SHRPX_UPSTREAM_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | 32 | #include "shrpx_io_control.h" 33 | 34 | namespace shrpx { 35 | 36 | class ClientHandler; 37 | class Downstream; 38 | 39 | class Upstream { 40 | public: 41 | virtual ~Upstream() {} 42 | virtual int on_read() = 0; 43 | virtual int on_write() = 0; 44 | virtual int on_event() = 0; 45 | virtual bufferevent_data_cb get_downstream_readcb() = 0; 46 | virtual bufferevent_data_cb get_downstream_writecb() = 0; 47 | virtual bufferevent_event_cb get_downstream_eventcb() = 0; 48 | virtual ClientHandler* get_client_handler() const = 0; 49 | 50 | virtual int on_downstream_header_complete(Downstream *downstream) = 0; 51 | virtual int on_downstream_body(Downstream *downstream, 52 | const uint8_t *data, size_t len) = 0; 53 | virtual int on_downstream_body_complete(Downstream *downstream) = 0; 54 | 55 | virtual void pause_read(IOCtrlReason reason) = 0; 56 | virtual int resume_read(IOCtrlReason reason, Downstream *downstream) = 0; 57 | }; 58 | 59 | } // namespace shrpx 60 | 61 | #endif // SHRPX_UPSTREAM_H 62 | -------------------------------------------------------------------------------- /src/shrpx_worker.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "shrpx_worker.h" 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "shrpx_ssl.h" 34 | #include "shrpx_thread_event_receiver.h" 35 | #include "shrpx_log.h" 36 | #include "shrpx_spdy_session.h" 37 | 38 | namespace shrpx { 39 | 40 | Worker::Worker(WorkerInfo *info) 41 | : sv_ssl_ctx_(info->sv_ssl_ctx), 42 | cl_ssl_ctx_(info->cl_ssl_ctx), 43 | fd_(info->sv[1]) 44 | {} 45 | 46 | Worker::~Worker() 47 | { 48 | shutdown(fd_, SHUT_WR); 49 | close(fd_); 50 | } 51 | 52 | namespace { 53 | void readcb(bufferevent *bev, void *arg) 54 | { 55 | ThreadEventReceiver *receiver = static_cast(arg); 56 | receiver->on_read(bev); 57 | } 58 | } // namespace 59 | 60 | namespace { 61 | void eventcb(bufferevent *bev, short events, void *arg) 62 | { 63 | if(events & BEV_EVENT_EOF) { 64 | LOG(ERROR) << "Connection to main thread lost: eof"; 65 | } 66 | if(events & BEV_EVENT_ERROR) { 67 | LOG(ERROR) << "Connection to main thread lost: network error"; 68 | } 69 | } 70 | } // namespace 71 | 72 | void Worker::run() 73 | { 74 | event_base *evbase = event_base_new(); 75 | bufferevent *bev = bufferevent_socket_new(evbase, fd_, 76 | BEV_OPT_DEFER_CALLBACKS); 77 | SpdySession *spdy = 0; 78 | if(get_config()->downstream_proto == PROTO_SPDY) { 79 | spdy = new SpdySession(evbase, cl_ssl_ctx_); 80 | if(spdy->init_notification() == -1) { 81 | DIE(); 82 | } 83 | } 84 | ThreadEventReceiver *receiver = new ThreadEventReceiver(evbase, sv_ssl_ctx_, 85 | spdy); 86 | bufferevent_enable(bev, EV_READ); 87 | bufferevent_setcb(bev, readcb, 0, eventcb, receiver); 88 | 89 | event_base_loop(evbase, 0); 90 | 91 | delete receiver; 92 | } 93 | 94 | void* start_threaded_worker(void *arg) 95 | { 96 | WorkerInfo *info = static_cast(arg); 97 | Worker worker(info); 98 | worker.run(); 99 | return 0; 100 | } 101 | 102 | } // namespace shrpx 103 | -------------------------------------------------------------------------------- /src/shrpx_worker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SHRPX_WORKER_H 26 | #define SHRPX_WORKER_H 27 | 28 | #include "shrpx.h" 29 | 30 | #include 31 | #include 32 | 33 | #include "shrpx_listen_handler.h" 34 | 35 | namespace shrpx { 36 | 37 | class Worker { 38 | public: 39 | Worker(WorkerInfo *info); 40 | ~Worker(); 41 | void run(); 42 | private: 43 | SSL_CTX *sv_ssl_ctx_; 44 | SSL_CTX *cl_ssl_ctx_; 45 | // Channel to the main thread 46 | int fd_; 47 | }; 48 | 49 | void* start_threaded_worker(void *arg); 50 | 51 | } // namespace shrpx 52 | 53 | #endif // SHRPX_WORKER_H 54 | -------------------------------------------------------------------------------- /src/spdylay_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_CONFIG_H 26 | #define SPDYLAY_CONFIG_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif // HAVE_CONFIG_H 31 | 32 | #endif // SPDYLAY_CONFIG_H 33 | -------------------------------------------------------------------------------- /src/timegm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2013 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "timegm.h" 26 | 27 | #ifndef HAVE_TIMEGM 28 | 29 | #include 30 | 31 | /* Counter the number of leap year in the range [0, y). The |y| is the 32 | year, including century (e.g., 2012) */ 33 | static int count_leap_year(int y) 34 | { 35 | y -= 1; 36 | return y/4-y/100+y/400; 37 | } 38 | 39 | /* Returns nonzero if the |y| is the leap year. The |y| is the year, 40 | including century (e.g., 2012) */ 41 | static int is_leap_year(int y) 42 | { 43 | return y%4 == 0 && (y%100 != 0 || y%400 == 0); 44 | } 45 | 46 | /* The number of days before ith month begins */ 47 | static int daysum[] = { 48 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 49 | }; 50 | 51 | /* Based on the algorithm of Python 2.7 calendar.timegm. */ 52 | time_t timegm(struct tm *tm) 53 | { 54 | int days; 55 | int num_leap_year; 56 | int64_t t; 57 | if(tm->tm_mon > 11) { 58 | return -1; 59 | } 60 | num_leap_year = count_leap_year(tm->tm_year + 1900) - count_leap_year(1970); 61 | days = (tm->tm_year - 70) * 365 + 62 | num_leap_year + daysum[tm->tm_mon] + tm->tm_mday-1; 63 | if(tm->tm_mon >= 2 && is_leap_year(tm->tm_year + 1900)) { 64 | ++days; 65 | } 66 | t = ((int64_t)days * 24 + tm->tm_hour) * 3600 + tm->tm_min * 60 + tm->tm_sec; 67 | if(sizeof(time_t) == 4) { 68 | if(t < INT32_MIN || t > INT32_MAX) { 69 | return -1; 70 | } 71 | } 72 | return t; 73 | } 74 | 75 | #endif /* !HAVE_TIMEGM */ 76 | -------------------------------------------------------------------------------- /src/timegm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2013 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef TIMEGM_H 26 | #define TIMEGM_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif // HAVE_CONFIG_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif /* __cplusplus */ 35 | 36 | #include 37 | 38 | #ifndef HAVE_TIMEGM 39 | 40 | time_t timegm(struct tm *tm); 41 | 42 | #endif /* HAVE_TIMEGM */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif /* __cplusplus */ 47 | 48 | #endif /* TIMEGM_H */ 49 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | end_to_end.py.log 2 | end_to_end.py.trs 3 | failmalloc.log 4 | failmalloc.trs 5 | main.log 6 | main.trs 7 | test-suite.log 8 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | SUBDIRS = testdata 24 | 25 | if HAVE_CUNIT 26 | 27 | check_PROGRAMS = main failmalloc 28 | 29 | OBJECTS = main.c spdylay_pq_test.c spdylay_map_test.c spdylay_queue_test.c \ 30 | spdylay_buffer_test.c spdylay_zlib_test.c spdylay_session_test.c \ 31 | spdylay_frame_test.c spdylay_stream_test.c spdylay_npn_test.c \ 32 | spdylay_gzip_test.c \ 33 | spdylay_test_helper.c 34 | 35 | HFILES = spdylay_pq_test.h spdylay_map_test.h spdylay_queue_test.h \ 36 | spdylay_buffer_test.h spdylay_zlib_test.h spdylay_session_test.h \ 37 | spdylay_frame_test.h spdylay_stream_test.h spdylay_npn_test.h \ 38 | spdylay_gzip_test.h \ 39 | spdylay_test_helper.h 40 | 41 | main_SOURCES = $(HFILES) $(OBJECTS) 42 | 43 | main_LDADD = ${top_builddir}/lib/libspdylay.la 44 | main_LDFLAGS = -static @CUNIT_LIBS@ @TESTS_LIBS@ 45 | 46 | failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \ 47 | malloc_wrapper.c malloc_wrapper.h \ 48 | spdylay_test_helper.c spdylay_test_helper.h 49 | failmalloc_LDADD = $(main_LDADD) 50 | failmalloc_LDFLAGS = $(main_LDFLAGS) 51 | 52 | AM_CFLAGS = -Wall -I${top_srcdir}/lib -I${top_srcdir}/lib/includes -I${top_builddir}/lib/includes \ 53 | @CUNIT_CFLAGS@ @DEFS@ 54 | 55 | TESTS = main failmalloc 56 | 57 | if ENABLE_SRC 58 | 59 | EXTRA_DIST = end_to_end.py 60 | TESTS += end_to_end.py 61 | 62 | endif # ENABLE_SRC 63 | 64 | endif # HAVE_CUNIT 65 | -------------------------------------------------------------------------------- /tests/end_to_end.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """End to end tests for the utility programs. 3 | 4 | This test assumes the utilities inside src directory have already been 5 | built. 6 | 7 | At the moment top_buiddir is not in the environment, but top_builddir would be 8 | more reliable than '..', so it's worth trying to pull it from the environment. 9 | """ 10 | 11 | __author__ = 'Jim Morrison ' 12 | 13 | 14 | import os 15 | import subprocess 16 | import time 17 | import unittest 18 | 19 | 20 | _PORT = 9893 21 | 22 | 23 | def _run_server(port, args): 24 | srcdir = os.environ.get('srcdir', '.') 25 | testdata = '%s/testdata' % srcdir 26 | top_builddir = os.environ.get('top_builddir', '..') 27 | base_args = ['%s/src/spdyd' % top_builddir, '-d', testdata] 28 | if args: 29 | base_args.extend(args) 30 | base_args.extend([str(port), '%s/privkey.pem' % testdata, 31 | '%s/cacert.pem' % testdata]) 32 | return subprocess.Popen(base_args) 33 | 34 | def _check_server_up(port): 35 | # Check this check for now. 36 | time.sleep(1) 37 | 38 | def _kill_server(server): 39 | while server.returncode is None: 40 | server.terminate() 41 | time.sleep(1) 42 | server.poll() 43 | 44 | 45 | class EndToEndSpdyTests(unittest.TestCase): 46 | @classmethod 47 | def setUpClass(cls): 48 | cls.setUpServer([]) 49 | 50 | @classmethod 51 | def setUpServer(cls, args): 52 | cls.server = _run_server(_PORT, args) 53 | _check_server_up(_PORT) 54 | 55 | @classmethod 56 | def tearDownClass(cls): 57 | _kill_server(cls.server) 58 | 59 | def setUp(self): 60 | build_dir = os.environ.get('top_builddir', '..') 61 | self.client = '%s/src/spdycat' % build_dir 62 | self.stdout = 'No output' 63 | 64 | def call(self, path, args): 65 | full_args = [self.client,'http://localhost:%d%s' % (_PORT, path)] + args 66 | p = subprocess.Popen(full_args, stdout=subprocess.PIPE, 67 | stdin=subprocess.PIPE) 68 | self.stdout, self.stderr = p.communicate() 69 | return p.returncode 70 | 71 | 72 | class EndToEndSpdy2Tests(EndToEndSpdyTests): 73 | def testSimpleRequest(self): 74 | self.assertEquals(0, self.call('/', [])) 75 | 76 | def testSimpleRequestSpdy3(self): 77 | self.assertEquals(0, self.call('/', ['-v', '-3'])) 78 | self.assertIn('NPN selected the protocol: spdy/3', self.stdout) 79 | 80 | def testFailedRequests(self): 81 | self.assertEquals( 82 | 2, self.call('/', ['https://localhost:25/', 'http://localhost:79'])) 83 | 84 | def testOneFailedRequest(self): 85 | self.assertEquals(1, subprocess.call([self.client, 'http://localhost:2/'])) 86 | 87 | def testOneTimedOutRequest(self): 88 | self.assertEquals(1, self.call('/?spdyd_do_not_respond_to_req=yes', 89 | ['--timeout=2'])) 90 | self.assertEquals(0, self.call('/', ['--timeout=20'])) 91 | 92 | 93 | class EndToEndSpdy3Tests(EndToEndSpdyTests): 94 | @classmethod 95 | def setUpClass(cls): 96 | cls.setUpServer(['-3']) 97 | 98 | def testSimpleRequest(self): 99 | self.assertEquals(0, self.call('/', ['-v'])) 100 | self.assertIn('NPN selected the protocol: spdy/3', self.stdout) 101 | 102 | 103 | if __name__ == '__main__': 104 | unittest.main() 105 | -------------------------------------------------------------------------------- /tests/failmalloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include "config.h" 29 | /* include test cases' include files here */ 30 | #include "failmalloc_test.h" 31 | 32 | static int init_suite1(void) 33 | { 34 | return 0; 35 | } 36 | 37 | static int clean_suite1(void) 38 | { 39 | return 0; 40 | } 41 | 42 | int main(int argc _U_, char* argv[] _U_) 43 | { 44 | CU_pSuite pSuite = NULL; 45 | unsigned int num_tests_failed; 46 | 47 | /* initialize the CUnit test registry */ 48 | if (CUE_SUCCESS != CU_initialize_registry()) 49 | return CU_get_error(); 50 | 51 | /* add a suite to the registry */ 52 | pSuite = CU_add_suite("libspdylay_TestSuite", init_suite1, clean_suite1); 53 | if (NULL == pSuite) { 54 | CU_cleanup_registry(); 55 | return CU_get_error(); 56 | } 57 | 58 | /* add the tests to the suite */ 59 | if(!CU_add_test(pSuite, "failmalloc_session_send", 60 | test_spdylay_session_send) || 61 | !CU_add_test(pSuite, "failmalloc_session_recv", 62 | test_spdylay_session_recv) || 63 | !CU_add_test(pSuite, "failmalloc_frame", test_spdylay_frame)) { 64 | CU_cleanup_registry(); 65 | return CU_get_error(); 66 | } 67 | 68 | /* Run all tests using the CUnit Basic interface */ 69 | CU_basic_set_mode(CU_BRM_VERBOSE); 70 | CU_basic_run_tests(); 71 | num_tests_failed = CU_get_number_of_tests_failed(); 72 | CU_cleanup_registry(); 73 | if(CU_get_error() == CUE_SUCCESS) { 74 | return num_tests_failed; 75 | } else { 76 | printf("CUnit Error: %s\n", CU_get_error_msg()); 77 | return CU_get_error(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/failmalloc_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FAILMALLOC_TEST_H 26 | #define FAILMALLOC_TEST_H 27 | 28 | void test_spdylay_session_send(void); 29 | void test_spdylay_session_recv(void); 30 | void test_spdylay_frame(void); 31 | 32 | #endif /* FAILMALLOC_TEST_H */ 33 | -------------------------------------------------------------------------------- /tests/malloc_wrapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "malloc_wrapper.h" 26 | 27 | #define __USE_GNU 28 | #include 29 | 30 | int spdylay_failmalloc = 0; 31 | int spdylay_failstart = 0; 32 | int spdylay_countmalloc = 1; 33 | int spdylay_nmalloc = 0; 34 | 35 | static void* (*real_malloc)(size_t) = NULL; 36 | 37 | static void init(void) 38 | { 39 | real_malloc = dlsym(RTLD_NEXT, "malloc"); 40 | } 41 | 42 | void* malloc(size_t size) 43 | { 44 | if(real_malloc == NULL) { 45 | init(); 46 | } 47 | if(spdylay_failmalloc && spdylay_nmalloc >= spdylay_failstart) { 48 | return NULL; 49 | } else { 50 | if(spdylay_countmalloc) { 51 | ++spdylay_nmalloc; 52 | } 53 | return real_malloc(size); 54 | } 55 | } 56 | 57 | static int failmalloc_bk, countmalloc_bk; 58 | 59 | void spdylay_failmalloc_pause(void) 60 | { 61 | failmalloc_bk = spdylay_failmalloc; 62 | countmalloc_bk = spdylay_countmalloc; 63 | spdylay_failmalloc = 0; 64 | spdylay_countmalloc = 0; 65 | } 66 | 67 | void spdylay_failmalloc_unpause(void) 68 | { 69 | spdylay_failmalloc = failmalloc_bk; 70 | spdylay_countmalloc = countmalloc_bk; 71 | } 72 | -------------------------------------------------------------------------------- /tests/malloc_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef MALLOC_WRAPPER_H 26 | #define MALLOC_WRAPPER_H 27 | 28 | #include 29 | 30 | /* Global variables to control the behavior of malloc() */ 31 | 32 | /* If nonzero, malloc failure mode is on */ 33 | extern int spdylay_failmalloc; 34 | /* If spdylay_failstart <= spdylay_nmalloc and spdylay_failmalloc is 35 | nonzero, malloc() fails. */ 36 | extern int spdylay_failstart; 37 | /* If nonzero, spdylay_nmalloc is incremented if malloc() succeeds. */ 38 | extern int spdylay_countmalloc; 39 | /* The number of successful invocation of malloc(). This value is only 40 | incremented if spdylay_nmalloc is nonzero. */ 41 | extern int spdylay_nmalloc; 42 | 43 | void* malloc(size_t size); 44 | 45 | /* Copies spdylay_failmalloc and spdylay_countmalloc to statically 46 | allocated space and sets 0 to them. This will effectively make 47 | malloc() work like normal malloc(). This is useful when you want to 48 | disable malloc() failure mode temporarily. */ 49 | void spdylay_failmalloc_pause(void); 50 | 51 | /* Restores the values of spdylay_failmalloc and spdylay_countmalloc 52 | with the values saved by the previous 53 | spdylay_failmalloc_pause(). */ 54 | void spdylay_failmalloc_unpause(void); 55 | 56 | #endif /* MALLOC_WRAPPER_H */ 57 | -------------------------------------------------------------------------------- /tests/spdylay_buffer_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_BUFFER_TEST_H 26 | #define SPDYLAY_BUFFER_TEST_H 27 | 28 | void test_spdylay_buffer(void); 29 | void test_spdylay_buffer_reader(void); 30 | 31 | #endif /* SPDYLAY_BUFFER_TEST_H */ 32 | -------------------------------------------------------------------------------- /tests/spdylay_frame_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_FRAME_TEST_H 26 | #define SPDYLAY_FRAME_TEST_H 27 | 28 | void test_spdylay_frame_unpack_nv_spdy2(void); 29 | void test_spdylay_frame_unpack_nv_spdy3(void); 30 | void test_spdylay_frame_pack_nv_duplicate_keys(void); 31 | void test_spdylay_frame_pack_nv_empty_value_spdy2(void); 32 | void test_spdylay_frame_pack_nv_empty_value_spdy3(void); 33 | void test_spdylay_frame_count_nv_space(void); 34 | void test_spdylay_frame_count_unpack_nv_space(void); 35 | void test_spdylay_frame_pack_ping(void); 36 | void test_spdylay_frame_pack_goaway_spdy2(void); 37 | void test_spdylay_frame_pack_goaway_spdy3(void); 38 | void test_spdylay_frame_pack_syn_stream_spdy2(void); 39 | void test_spdylay_frame_pack_syn_stream_spdy3(void); 40 | void test_spdylay_frame_pack_syn_stream_frame_too_large(void); 41 | void test_spdylay_frame_pack_syn_reply_spdy2(void); 42 | void test_spdylay_frame_pack_syn_reply_spdy3(void); 43 | void test_spdylay_frame_pack_headers_spdy2(void); 44 | void test_spdylay_frame_pack_headers_spdy3(void); 45 | void test_spdylay_frame_pack_window_update(void); 46 | void test_spdylay_frame_pack_settings_spdy2(void); 47 | void test_spdylay_frame_pack_settings_spdy3(void); 48 | void test_spdylay_frame_nv_sort(void); 49 | void test_spdylay_frame_nv_downcase(void); 50 | void test_spdylay_frame_nv_2to3(void); 51 | void test_spdylay_frame_nv_3to2(void); 52 | void test_spdylay_frame_unpack_nv_check_name_spdy2(void); 53 | void test_spdylay_frame_unpack_nv_check_name_spdy3(void); 54 | void test_spdylay_frame_unpack_nv_last_empty_value_spdy2(void); 55 | void test_spdylay_frame_unpack_nv_last_empty_value_spdy3(void); 56 | void test_spdylay_frame_nv_check_null(void); 57 | 58 | #endif /* SPDYLAY_FRAME_TEST_H */ 59 | -------------------------------------------------------------------------------- /tests/spdylay_gzip_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_GZIP_TEST_H 26 | #define SPDYLAY_GZIP_TEST_H 27 | 28 | void test_spdylay_gzip_inflate(void); 29 | 30 | #endif /* SPDYLAY_GZIP_TEST_H */ 31 | -------------------------------------------------------------------------------- /tests/spdylay_map_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_MAP_TEST_H 26 | #define SPDYLAY_MAP_TEST_H 27 | 28 | void test_spdylay_map(void); 29 | void test_spdylay_map_functional(void); 30 | void test_spdylay_map_each_free(void); 31 | 32 | #endif /* SPDYLAY_MAP_TEST_H */ 33 | -------------------------------------------------------------------------------- /tests/spdylay_npn_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Twist Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_NPN_TEST_H 26 | #define SPDYLAY_NPN_TEST_H 27 | 28 | void test_spdylay_npn(void); 29 | void test_spdylay_npn_get_proto_list(void); 30 | void test_spdylay_npn_get_version(void); 31 | 32 | #endif /* SPDYLAY_NPN_TEST_H */ 33 | -------------------------------------------------------------------------------- /tests/spdylay_pq_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_pq_test.h" 26 | 27 | #include 28 | 29 | #include "spdylay_pq.h" 30 | 31 | static int pq_compar(const void *lhs, const void *rhs) 32 | { 33 | return strcmp(lhs, rhs); 34 | } 35 | 36 | void test_spdylay_pq(void) 37 | { 38 | int i; 39 | spdylay_pq pq; 40 | spdylay_pq_init(&pq, pq_compar); 41 | CU_ASSERT(spdylay_pq_empty(&pq)); 42 | CU_ASSERT(0 == spdylay_pq_size(&pq)); 43 | CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"foo")); 44 | CU_ASSERT(0 == spdylay_pq_empty(&pq)); 45 | CU_ASSERT(1 == spdylay_pq_size(&pq)); 46 | CU_ASSERT(strcmp("foo", spdylay_pq_top(&pq)) == 0); 47 | CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"bar")); 48 | CU_ASSERT(strcmp("bar", spdylay_pq_top(&pq)) == 0); 49 | CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"baz")); 50 | CU_ASSERT(strcmp("bar", spdylay_pq_top(&pq)) == 0); 51 | CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"C")); 52 | CU_ASSERT(4 == spdylay_pq_size(&pq)); 53 | CU_ASSERT(strcmp("C", spdylay_pq_top(&pq)) == 0); 54 | spdylay_pq_pop(&pq); 55 | CU_ASSERT(3 == spdylay_pq_size(&pq)); 56 | CU_ASSERT(strcmp("bar", spdylay_pq_top(&pq)) == 0); 57 | spdylay_pq_pop(&pq); 58 | CU_ASSERT(strcmp("baz", spdylay_pq_top(&pq)) == 0); 59 | spdylay_pq_pop(&pq); 60 | CU_ASSERT(strcmp("foo", spdylay_pq_top(&pq)) == 0); 61 | spdylay_pq_pop(&pq); 62 | CU_ASSERT(spdylay_pq_empty(&pq)); 63 | CU_ASSERT(0 == spdylay_pq_size(&pq)); 64 | CU_ASSERT(NULL == spdylay_pq_top(&pq)); 65 | 66 | /* Add bunch of entry to see realloc works */ 67 | for(i = 0; i < 10000; ++i) { 68 | CU_ASSERT(0 == spdylay_pq_push(&pq, (void*)"foo")); 69 | CU_ASSERT((size_t)(i+1) == spdylay_pq_size(&pq)); 70 | } 71 | for(i = 10000; i > 0; --i) { 72 | CU_ASSERT(NULL != spdylay_pq_top(&pq)); 73 | spdylay_pq_pop(&pq); 74 | CU_ASSERT((size_t)(i-1) == spdylay_pq_size(&pq)); 75 | } 76 | 77 | spdylay_pq_free(&pq); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /tests/spdylay_pq_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_PQ_TEST_H 26 | #define SPDYLAY_PQ_TEST_H 27 | 28 | void test_spdylay_pq(void); 29 | 30 | #endif /* SPDYLAY_PQ_TEST_H */ 31 | -------------------------------------------------------------------------------- /tests/spdylay_queue_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_queue_test.h" 26 | 27 | #include 28 | 29 | #include "spdylay_queue.h" 30 | 31 | void test_spdylay_queue(void) 32 | { 33 | int ints[] = { 1, 2, 3, 4, 5 }; 34 | int i; 35 | spdylay_queue queue; 36 | spdylay_queue_init(&queue); 37 | CU_ASSERT(spdylay_queue_empty(&queue)); 38 | for(i = 0; i < 5; ++i) { 39 | spdylay_queue_push(&queue, &ints[i]); 40 | CU_ASSERT_EQUAL(ints[0], *(int*)(spdylay_queue_front(&queue))); 41 | CU_ASSERT(!spdylay_queue_empty(&queue)); 42 | } 43 | for(i = 0; i < 5; ++i) { 44 | CU_ASSERT_EQUAL(ints[i], *(int*)(spdylay_queue_front(&queue))); 45 | spdylay_queue_pop(&queue); 46 | } 47 | CU_ASSERT(spdylay_queue_empty(&queue)); 48 | spdylay_queue_free(&queue); 49 | } 50 | -------------------------------------------------------------------------------- /tests/spdylay_queue_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_QUEUE_TEST_H 26 | #define SPDYLAY_QUEUE_TEST_H 27 | 28 | void test_spdylay_queue(void); 29 | 30 | #endif /* SPDYLAY_QUEUE_TEST_H */ 31 | -------------------------------------------------------------------------------- /tests/spdylay_stream_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_stream_test.h" 26 | 27 | #include 28 | 29 | #include "spdylay_stream.h" 30 | 31 | void test_spdylay_stream_add_pushed_stream(void) 32 | { 33 | spdylay_stream stream; 34 | int i, n; 35 | spdylay_stream_init(&stream, 1, SPDYLAY_CTRL_FLAG_NONE, 3, 65536, 36 | SPDYLAY_STREAM_OPENING, NULL); 37 | n = 26; 38 | for(i = 2; i < n; i += 2) { 39 | CU_ASSERT(0 == spdylay_stream_add_pushed_stream(&stream, i)); 40 | CU_ASSERT((size_t)i/2 == stream.pushed_streams_length); 41 | } 42 | for(i = 2; i < n; i += 2) { 43 | CU_ASSERT(i == stream.pushed_streams[i/2-1]); 44 | } 45 | spdylay_stream_free(&stream); 46 | } 47 | -------------------------------------------------------------------------------- /tests/spdylay_stream_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_STREAM_TEST_H 26 | #define SPDYLAY_STREAM_TEST_H 27 | 28 | void test_spdylay_stream_add_pushed_stream(void); 29 | 30 | #endif /* SPDYLAY_STREAM_TEST_H */ 31 | -------------------------------------------------------------------------------- /tests/spdylay_test_helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_test_helper.h" 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "spdylay_session.h" 32 | 33 | ssize_t unpack_frame_with_nv_block(spdylay_frame_type type, 34 | uint16_t version, 35 | spdylay_frame *frame, 36 | spdylay_zlib *inflater, 37 | const uint8_t *in, size_t len) 38 | { 39 | spdylay_buffer buffer; 40 | ssize_t rv; 41 | ssize_t pnvlen; 42 | pnvlen = spdylay_frame_nv_offset(type, version) - SPDYLAY_HEAD_LEN; 43 | assert(pnvlen > 0); 44 | 45 | spdylay_buffer_init(&buffer, 4096); 46 | rv = spdylay_zlib_inflate_hd(inflater, &buffer, 47 | &in[SPDYLAY_HEAD_LEN + pnvlen], 48 | len - SPDYLAY_HEAD_LEN - pnvlen); 49 | if(rv < 0) { 50 | spdylay_buffer_free(&buffer); 51 | return rv; 52 | } 53 | switch(type) { 54 | case SPDYLAY_SYN_STREAM: 55 | rv = spdylay_frame_unpack_syn_stream(&frame->syn_stream, 56 | &in[0], SPDYLAY_HEAD_LEN, 57 | &in[SPDYLAY_HEAD_LEN], pnvlen, 58 | &buffer); 59 | break; 60 | case SPDYLAY_SYN_REPLY: 61 | rv = spdylay_frame_unpack_syn_reply(&frame->syn_reply, 62 | &in[0], SPDYLAY_HEAD_LEN, 63 | &in[SPDYLAY_HEAD_LEN], pnvlen, 64 | &buffer); 65 | break; 66 | case SPDYLAY_HEADERS: 67 | rv = spdylay_frame_unpack_headers(&frame->headers, 68 | &in[0], SPDYLAY_HEAD_LEN, 69 | &in[SPDYLAY_HEAD_LEN], pnvlen, 70 | &buffer); 71 | break; 72 | default: 73 | /* Must not be reachable */ 74 | assert(0); 75 | } 76 | spdylay_buffer_free(&buffer); 77 | return rv; 78 | } 79 | -------------------------------------------------------------------------------- /tests/spdylay_test_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_TEST_HELPER_H 26 | #define SPDYLAY_TEST_HELPER_H 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif /* HAVE_CONFIG_H */ 31 | 32 | #include "spdylay_frame.h" 33 | #include "spdylay_zlib.h" 34 | 35 | ssize_t unpack_frame_with_nv_block(spdylay_frame_type type, 36 | uint16_t version, 37 | spdylay_frame *frame, 38 | spdylay_zlib *inflater, 39 | const uint8_t *in, size_t len); 40 | 41 | #endif /* SPDYLAY_TEST_HELPER_H */ 42 | -------------------------------------------------------------------------------- /tests/spdylay_zlib_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "spdylay_zlib_test.h" 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "spdylay_zlib.h" 32 | 33 | static void test_spdylay_zlib_with(uint16_t version) 34 | { 35 | spdylay_zlib deflater, inflater; 36 | const char msg[] = 37 | "GET /chat HTTP/1.1\r\n" 38 | "Host: server.example.com\r\n" 39 | "Upgrade: websocket\r\n" 40 | "Connection: Upgrade\r\n" 41 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" 42 | "Origin: http://example.com\r\n" 43 | "Sec-WebSocket-Protocol: chat, superchat\r\n" 44 | "Sec-WebSocket-Version: 13\r\n" 45 | "\r\n"; 46 | uint8_t inflatebuf[sizeof(msg)]; 47 | spdylay_buffer buf; 48 | uint8_t *deflatebuf; 49 | size_t deflatebuf_max; 50 | ssize_t deflatebuf_len; 51 | spdylay_buffer_init(&buf, 4096); 52 | 53 | CU_ASSERT(0 == spdylay_zlib_deflate_hd_init(&deflater, 1, 54 | version)); 55 | CU_ASSERT(0 == spdylay_zlib_inflate_hd_init(&inflater, version)); 56 | 57 | deflatebuf_max = spdylay_zlib_deflate_hd_bound(&deflater, sizeof(msg)); 58 | deflatebuf = malloc(deflatebuf_max); 59 | 60 | CU_ASSERT(0 < (deflatebuf_len = spdylay_zlib_deflate_hd 61 | (&deflater, deflatebuf, deflatebuf_max, 62 | (const uint8_t*)msg, sizeof(msg)))); 63 | CU_ASSERT(sizeof(msg) == spdylay_zlib_inflate_hd 64 | (&inflater, &buf, deflatebuf, deflatebuf_len)); 65 | free(deflatebuf); 66 | spdylay_buffer_serialize(&buf, inflatebuf); 67 | 68 | spdylay_zlib_deflate_free(&deflater); 69 | spdylay_zlib_inflate_free(&inflater); 70 | 71 | spdylay_buffer_free(&buf); 72 | } 73 | 74 | void test_spdylay_zlib_spdy2(void) 75 | { 76 | test_spdylay_zlib_with(SPDYLAY_PROTO_SPDY2); 77 | } 78 | 79 | void test_spdylay_zlib_spdy3(void) 80 | { 81 | test_spdylay_zlib_with(SPDYLAY_PROTO_SPDY3); 82 | } 83 | -------------------------------------------------------------------------------- /tests/spdylay_zlib_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Spdylay - SPDY Library 3 | * 4 | * Copyright (c) 2012 Tatsuhiro Tsujikawa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef SPDYLAY_ZLIB_TEST_H 26 | #define SPDYLAY_ZLIB_TEST_H 27 | 28 | void test_spdylay_zlib_spdy2(void); 29 | void test_spdylay_zlib_spdy3(void); 30 | 31 | #endif /* SPDYLAY_ZLIB_TEST_H */ 32 | -------------------------------------------------------------------------------- /tests/testdata/Makefile.am: -------------------------------------------------------------------------------- 1 | # Spdylay - SPDY Library 2 | 3 | # Copyright (c) 2012 Tatsuhiro Tsujikawa 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | EXTRA_DIST = cacert.pem index.html privkey.pem 24 | -------------------------------------------------------------------------------- /tests/testdata/cacert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDszCCApugAwIBAgIJAIwdWkdWObcIMA0GCSqGSIb3DQEBCwUAMHAxCzAJBgNV 3 | BAYTAlVTMQswCQYDVQQIDAJDQTENMAsGA1UEBwwEQ2l0eTESMBAGA1UECgwJU3Bk 4 | eSBUZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3QxHTAbBgkqhkiG9w0BCQEWDnNwZHlA 5 | bG9jYWxob3N0MB4XDTE2MDkxOTEzMTY1M1oXDTE2MTAxOTEzMTY1M1owcDELMAkG 6 | A1UEBhMCVVMxCzAJBgNVBAgMAkNBMQ0wCwYDVQQHDARDaXR5MRIwEAYDVQQKDAlT 7 | cGR5IFRlc3QxEjAQBgNVBAMMCWxvY2FsaG9zdDEdMBsGCSqGSIb3DQEJARYOc3Bk 8 | eUBsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQD6ghRI 9 | 7EZt5wRSsFr69n5gjlTV14cZD/N4OruuYAFvZH9rPc+q3LnQ/aWN5iHO94k9Uq33 10 | ENGhpDFHbhMJMqWinyZabmjH0pbXRRELLCWqz3E0nJBvQWB7vGT4glxJozHOmFzw 11 | id0zUMedjLR6XxJzP2TMJv7sZgmJd7wf2F5iTvQCq5BId16/rnuA2lIZtzCCNIgn 12 | p4Hs6BktigFrO7A2xuJHuys1bXS6M2PeiuuN/3B2KV/bzZ3Ylw7u1UYIBBgjpon9 13 | FwcGFoln8cXVadb3ZIsWNBgP2dhXSk5vDl8t7KVdTbcC/uNysQvoCuglJEwXg/7B 14 | Sf3/rpnEcKF+ChFpAgMBAAGjUDBOMB0GA1UdDgQWBBSPX3h2tbo3axwLyfRPuxnR 15 | t+IKRTAfBgNVHSMEGDAWgBSPX3h2tbo3axwLyfRPuxnRt+IKRTAMBgNVHRMEBTAD 16 | AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAQyccGq2GeJzq/mIKdEOlosDSkEpvc/siu 17 | Dsa9l4VMGZYL43RRb5bXpLBhaktmtQoTb/QegRxhw3NAaacCqlQNIR1ivdYC6EGU 18 | 7Yx5tMjUrH2pYEUNBHOWQ2+3tPzYxJ6rRtF0WxgiLiJNHbdjLzP3fl01dX2BctEG 19 | cUzdXalP9/WFlXUyaLuQsfzHVSlR6BMnBpGQTWFO3jdOL36ZjEY1nhTB6YTDQcI2 20 | J1WDUcJ98MPMCKismi5hNR0tgcBk13oucV93N7f5fwmIBM2jSwn3l4CC4jS3+9ev 21 | uSDbcEIN1is+Ly7anZ/AAgUCYJK+vN+At6Fo5XT90pehncrCfVYd 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /tests/testdata/index.html: -------------------------------------------------------------------------------- 1 | small 2 | -------------------------------------------------------------------------------- /tests/testdata/privkey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQD6ghRI7EZt5wRS 3 | sFr69n5gjlTV14cZD/N4OruuYAFvZH9rPc+q3LnQ/aWN5iHO94k9Uq33ENGhpDFH 4 | bhMJMqWinyZabmjH0pbXRRELLCWqz3E0nJBvQWB7vGT4glxJozHOmFzwid0zUMed 5 | jLR6XxJzP2TMJv7sZgmJd7wf2F5iTvQCq5BId16/rnuA2lIZtzCCNIgnp4Hs6Bkt 6 | igFrO7A2xuJHuys1bXS6M2PeiuuN/3B2KV/bzZ3Ylw7u1UYIBBgjpon9FwcGFoln 7 | 8cXVadb3ZIsWNBgP2dhXSk5vDl8t7KVdTbcC/uNysQvoCuglJEwXg/7BSf3/rpnE 8 | cKF+ChFpAgMBAAECggEAQ/hDdL3XJj7GZ4E+TlXPWHeGATenil9PmlGlVtzpxsWn 9 | 5Psye5PEPzZzUxscFUII1MC4Pw8rMgaQ8Gand5lsY8F28JaAi6dSEjrFMxjZZ409 10 | lB7e+bDtcuVdKCiGzdwfyYSBwypFAIVshA0HcySUpvyOZu41wQK2l7wLKUDV6yoj 11 | kdNsIX0qYQfbPcTizbTz62ZF0E/8FgrfG6Iba7iX10Oig7nkd01zvS0n32xXvR1W 12 | yMucxzS4SIcpi2mnpsMEGXliC98MIl5d9tmAYNkmq4rB/CJbNVypHj9cCxXZKDq0 13 | Lxr0TKPO5QfZnZw4IYj6ILottvq9YkBgRMplPSRuuQKBgQD+6uQl0GGx+bNa3/7c 14 | fQpMh3d1gLGhdltor1PbRs+GeNqQvPeXgDqwkJj4Gvi16fd3lr59X1eJQhF/7as2 15 | jO8T/OzfXxwNM7v9CH5g7zOxv1IC02IA1IWKHv4ZQLsfrlj108TkSCZ531oDGoxB 16 | BSzd4J9AvfaA8Jl9Wo/xujtmhwKBgQD7kmUPH8HjgZ9jdnFvTDsTmSfgxiV3Vr+F 17 | hr7fXwQyfz958rOQsjR6lkF2uc6hMOaLdO9IJJ7b4FOZ92o5oMNCkVqRzuJbjdj5 18 | bIBy1IKvPlQooEdCdFAYRvmuroOPOboIQHDnlPsWCNWKz8WS+SMsFK7OaI5sQht+ 19 | 3pEaE2zUjwKBgQCsDEy/WM0XGbh7dQLGPX5d+HAf1iQNHZzEItEuBbS6xYZ+eYuB 20 | rQHveShFC68g2DA1foBCjb6+3OCCvx33S1dw3hvhBoggQPJ37Oue8NKq/L2VOqXC 21 | ea1Hc3N8B7xDvaA9ChixGiEd0CkoPxq6J4wIlDnnsE5W6AwwFpdgRpkgsQKBgQDA 22 | 0WEB6Y5bSMOYoXSqIJx7Ff1Zq6WVxXh/6FotrI70AVHurxXwRpYwiy/bxuhX5boe 23 | k16/Rco4rsSFEvxo9Q4T3IK1lQMrtxnhescsvDL6DGTGyqozhiDJqsS+nWWahl1O 24 | 681dwnN8XQMHJN7DGo9ZvvSIodzfnv+iCwbeHJtigwKBgQDTAFYIVGgviVStW4+Y 25 | SyAENsfsO6w7n2Z8mwo1zfpRofsmh40RJ0DjGooOJJc+qn2tmVw3vXgb3kg+2ZDz 26 | eGfcREykoQHw+zPIPK3S7zqrn56xMhR2RgN0WNXw0GJkzGrzt8P53LPTZ9jQr8g1 27 | P7xMX3H7hPIIHA3SryD6xb/EiQ== 28 | -----END PRIVATE KEY----- 29 | --------------------------------------------------------------------------------