Skip to content

Commit

Permalink
parsing of http headers is case insensitive; examples statically buil…
Browse files Browse the repository at this point in the history
…t; version 1.3.1
  • Loading branch information
darrenjs committed Jun 2, 2017
1 parent 359015f commit d73160f
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 18 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
unreleased
==========

version 1.3.1
=============

Released 2017-06-02

## Fixed

- configure script can handle relative path to source, when invoked

- using case-insensitive string comparison when processing HTTP headers

- examples now are built statically

version 1.3
===========

Expand Down
5 changes: 2 additions & 3 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#define PACKAGE_NAME "wampcc"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "wampcc 1.1.1"
#define PACKAGE_STRING "wampcc 1.3.1"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "wampcc"
Expand All @@ -72,8 +72,7 @@
#define PACKAGE_URL " "

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.1.1"
#define PACKAGE_VERSION "1.3.1"


#endif

12 changes: 9 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#========== Initialisation ==========

AC_INIT([wampcc], [1.3], [wampcc@darrenjs.net], [wampcc], [ ] )
AC_INIT([wampcc], [1.3.1], [wampcc@darrenjs.net], [wampcc], [ ] )
AC_PREREQ([2.59])

AC_CONFIG_AUX_DIR([.])
Expand Down Expand Up @@ -83,10 +83,16 @@ AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE

# The user provided 'srcdir' might be a relative or an absolute path, depending
# on how the configure script was invoked. Here we obtain the absolute path to
# the srcdir.
wampcc_src_dir=`(cd "$srcdir"; pwd)`

# log some directories know to configure
# log some directories known to configure
AC_MSG_NOTICE([notice srcdir: ${srcdir}])
AC_MSG_NOTICE([notice prefix: ${prefix}])
AC_MSG_NOTICE([notice ac_pwd: ${ac_pwd}])
AC_MSG_NOTICE([notice wampcc_src_dir: ${wampcc_src_dir}])

##
## jalson - can either be included with the source code, or pulled in externally
Expand All @@ -95,7 +101,7 @@ AC_MSG_NOTICE([notice prefix: ${prefix}])

AC_MSG_NOTICE([Using bundled jalson])
internal_jalson=1
jalsoninc="$srcdir/jalson/src"
jalsoninc="$wampcc_src_dir"/jalson/src
jalsonlib="../jalson/src"
AC_SUBST(jalsoninc)
AC_SUBST(jalsonlib)
Expand Down
4 changes: 4 additions & 0 deletions examples/basic/basic_embedded_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ int main(int argc, char** argv)

auto logger = wampcc::logger::stream(
std::cout, wampcc::logger::levels_upto(wampcc::logger::eInfo), false);

std::unique_ptr<wampcc::kernel> the_kernel(
new wampcc::kernel({}, std::move(logger)));

the_kernel->get_logger().write(wampcc::logger::eInfo, wampcc::name_version(),
__FILE__, __LINE__);

/* Create an embedded wamp router. */

wampcc::wamp_router router(the_kernel.get());
Expand Down
6 changes: 5 additions & 1 deletion examples/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# it under the terms of the MIT license. See LICENSE for details.
#

# comment-out these two lines to link to shared libs
STATIC_LINK_BEGIN=-Wl,-Bstatic
STATIC_LINK_END=-Wl,-Bdynamic

ifeq ($(WAMPCC_HOME),)
$(error WAMPCC_HOME undefined - set WAMPCC_HOME to where wampcc was make-installed)
endif
Expand All @@ -28,7 +32,7 @@ JANSSON_LIBS=-L$(JANSSON_HOME)/lib -ljansson
CXXFLAGS += -MMD -MP
CXXFLAGS += -Wall -O0 -g3 -ggdb -std=c++11 -pthread $(WAMPCC_INC) $(JALSON_INC) $(LIBUV_INC)

LDLIBS +=$(WAMPCC_LIBS) $(LIBUV_LIBS) $(JALSON_LIBS) $(JANSSON_LIBS) -lcrypto -lpthread
LDLIBS += $(STATIC_LINK_BEGIN) $(WAMPCC_LIBS) $(LIBUV_LIBS) $(JANSSON_LIBS) $(STATIC_LINK_END) -lcrypto -lpthread -lssl -lrt

# default: callee

Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ libwampcc_la_LIBADD = -lpthread -lssl -lcrypto $(libuvlib)
# - REVISION: revision of current version. Incr. base on internal changes.
# - AGE: indicates compatibilty with previous version of the shlib.
#
libwampcc_la_LDFLAGS = -version-info 3:0:0
libwampcc_la_LDFLAGS = -version-info 3:1:0
2 changes: 1 addition & 1 deletion lib/wampcc/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/* Compile-time name & version */

#define WAMPCC_MAJOR_VERSION 1
#define WAMPCC_MINOR_VERSION 1
#define WAMPCC_MINOR_VERSION 3
#define WAMPCC_MICRO_VERSION 1

namespace wampcc
Expand Down
7 changes: 7 additions & 0 deletions lib/wampcc/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include <sys/time.h>
#endif

#ifdef _WIN32
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif

namespace wampcc
{

Expand Down
2 changes: 1 addition & 1 deletion lib/wampcc/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class selector_protocol : public protocol

const char* name() const override { return NAME; }

void send_msg(const json_array& j) override
void send_msg(const json_array&) override
{
throw std::runtime_error("selector_protocol cannot send");
}
Expand Down
20 changes: 12 additions & 8 deletions lib/websocket_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "wampcc/websocket_protocol.h"

#include "wampcc/platform.h"
#include "wampcc/utils.h"
#include "wampcc/tcp_socket.h"
#include "wampcc/http_parser.h"
Expand Down Expand Up @@ -65,14 +66,17 @@ inline std::string make_accept_key(const std::string& challenge)
}


static bool string_list_contains(const std::string & source,
const std::string & match)
/* Test whether a HTTP header contains a desired value. Note that when checking
* request and response headers, we are generally case
* insensitive. I.e. according to RFC2616, all header field names in both HTTP
* requests and HTTP responses are case-insensitive. */
static bool header_contains(const std::string & source,
const std::string & match)
{

for (auto & i : tokenize(source.c_str(), ',', true))
{
std::string trimmed = trim(i);
if (trimmed == match)
if (strcasecmp(trimmed.c_str(), match.c_str())==0)
return true;
}
return false;
Expand Down Expand Up @@ -226,9 +230,9 @@ void websocket_protocol::io_on_read(char* src, size_t len)
{
if ( m_http_parser->is_upgrade() &&
m_http_parser->has("Upgrade") &&
string_list_contains(m_http_parser->get("Upgrade"), "websocket") &&
header_contains(m_http_parser->get("Upgrade"), "websocket") &&
m_http_parser->has("Connection") &&
string_list_contains(m_http_parser->get("Connection"), "Upgrade") &&
header_contains(m_http_parser->get("Connection"), "Upgrade") &&
m_http_parser->has("Sec-WebSocket-Key") &&
m_http_parser->has("Sec-WebSocket-Version") )
{
Expand Down Expand Up @@ -353,9 +357,9 @@ void websocket_protocol::io_on_read(char* src, size_t len)
{
if ( m_http_parser->is_upgrade() &&
m_http_parser->has("Upgrade") &&
string_list_contains(m_http_parser->get("Upgrade"), "websocket") &&
header_contains(m_http_parser->get("Upgrade"), "websocket") &&
m_http_parser->has("Connection") &&
string_list_contains(m_http_parser->get("Connection"), "Upgrade") &&
header_contains(m_http_parser->get("Connection"), "Upgrade") &&
m_http_parser->has("Sec-WebSocket-Accept") &&
m_http_parser->http_status_phrase() == "Switching Protocols" &&
m_http_parser->http_status_code() == http_parser::status_code_switching_protocols)
Expand Down

0 comments on commit d73160f

Please sign in to comment.