Skip to content

Commit d73160f

Browse files
committed
parsing of http headers is case insensitive; examples statically built; version 1.3.1
1 parent 359015f commit d73160f

File tree

10 files changed

+55
-18
lines changed

10 files changed

+55
-18
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
unreleased
22
==========
33

4+
version 1.3.1
5+
=============
6+
7+
Released 2017-06-02
8+
9+
## Fixed
10+
11+
- configure script can handle relative path to source, when invoked
12+
13+
- using case-insensitive string comparison when processing HTTP headers
14+
15+
- examples now are built statically
16+
417
version 1.3
518
===========
619

config.h.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#define PACKAGE_NAME "wampcc"
6464

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

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

7474
/* Define to the version of this package. */
75-
#define PACKAGE_VERSION "1.1.1"
75+
#define PACKAGE_VERSION "1.3.1"
7676

7777

7878
#endif
79-

configure.ac

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#========== Initialisation ==========
33

4-
AC_INIT([wampcc], [1.3], [[email protected]], [wampcc], [ ] )
4+
AC_INIT([wampcc], [1.3.1], [[email protected]], [wampcc], [ ] )
55
AC_PREREQ([2.59])
66

77
AC_CONFIG_AUX_DIR([.])
@@ -83,10 +83,16 @@ AC_HEADER_STDBOOL
8383
AC_C_CONST
8484
AC_C_INLINE
8585

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

87-
# log some directories know to configure
91+
# log some directories known to configure
8892
AC_MSG_NOTICE([notice srcdir: ${srcdir}])
8993
AC_MSG_NOTICE([notice prefix: ${prefix}])
94+
AC_MSG_NOTICE([notice ac_pwd: ${ac_pwd}])
95+
AC_MSG_NOTICE([notice wampcc_src_dir: ${wampcc_src_dir}])
9096

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

96102
AC_MSG_NOTICE([Using bundled jalson])
97103
internal_jalson=1
98-
jalsoninc="$srcdir/jalson/src"
104+
jalsoninc="$wampcc_src_dir"/jalson/src
99105
jalsonlib="../jalson/src"
100106
AC_SUBST(jalsoninc)
101107
AC_SUBST(jalsonlib)

examples/basic/basic_embedded_router.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ int main(int argc, char** argv)
2929

3030
auto logger = wampcc::logger::stream(
3131
std::cout, wampcc::logger::levels_upto(wampcc::logger::eInfo), false);
32+
3233
std::unique_ptr<wampcc::kernel> the_kernel(
3334
new wampcc::kernel({}, std::move(logger)));
3435

36+
the_kernel->get_logger().write(wampcc::logger::eInfo, wampcc::name_version(),
37+
__FILE__, __LINE__);
38+
3539
/* Create an embedded wamp router. */
3640

3741
wampcc::wamp_router router(the_kernel.get());

examples/makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
# it under the terms of the MIT license. See LICENSE for details.
66
#
77

8+
# comment-out these two lines to link to shared libs
9+
STATIC_LINK_BEGIN=-Wl,-Bstatic
10+
STATIC_LINK_END=-Wl,-Bdynamic
11+
812
ifeq ($(WAMPCC_HOME),)
913
$(error WAMPCC_HOME undefined - set WAMPCC_HOME to where wampcc was make-installed)
1014
endif
@@ -28,7 +32,7 @@ JANSSON_LIBS=-L$(JANSSON_HOME)/lib -ljansson
2832
CXXFLAGS += -MMD -MP
2933
CXXFLAGS += -Wall -O0 -g3 -ggdb -std=c++11 -pthread $(WAMPCC_INC) $(JALSON_INC) $(LIBUV_INC)
3034

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

3337
# default: callee
3438

lib/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ libwampcc_la_LIBADD = -lpthread -lssl -lcrypto $(libuvlib)
5555
# - REVISION: revision of current version. Incr. base on internal changes.
5656
# - AGE: indicates compatibilty with previous version of the shlib.
5757
#
58-
libwampcc_la_LDFLAGS = -version-info 3:0:0
58+
libwampcc_la_LDFLAGS = -version-info 3:1:0

lib/wampcc/kernel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/* Compile-time name & version */
1616

1717
#define WAMPCC_MAJOR_VERSION 1
18-
#define WAMPCC_MINOR_VERSION 1
18+
#define WAMPCC_MINOR_VERSION 3
1919
#define WAMPCC_MICRO_VERSION 1
2020

2121
namespace wampcc

lib/wampcc/platform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#include <sys/time.h>
1515
#endif
1616

17+
#ifdef _WIN32
18+
#define snprintf _snprintf
19+
#define vsnprintf _vsnprintf
20+
#define strcasecmp _stricmp
21+
#define strncasecmp _strnicmp
22+
#endif
23+
1724
namespace wampcc
1825
{
1926

lib/wampcc/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class selector_protocol : public protocol
173173

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

176-
void send_msg(const json_array& j) override
176+
void send_msg(const json_array&) override
177177
{
178178
throw std::runtime_error("selector_protocol cannot send");
179179
}

lib/websocket_protocol.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "wampcc/websocket_protocol.h"
99

10+
#include "wampcc/platform.h"
1011
#include "wampcc/utils.h"
1112
#include "wampcc/tcp_socket.h"
1213
#include "wampcc/http_parser.h"
@@ -65,14 +66,17 @@ inline std::string make_accept_key(const std::string& challenge)
6566
}
6667

6768

68-
static bool string_list_contains(const std::string & source,
69-
const std::string & match)
69+
/* Test whether a HTTP header contains a desired value. Note that when checking
70+
* request and response headers, we are generally case
71+
* insensitive. I.e. according to RFC2616, all header field names in both HTTP
72+
* requests and HTTP responses are case-insensitive. */
73+
static bool header_contains(const std::string & source,
74+
const std::string & match)
7075
{
71-
7276
for (auto & i : tokenize(source.c_str(), ',', true))
7377
{
7478
std::string trimmed = trim(i);
75-
if (trimmed == match)
79+
if (strcasecmp(trimmed.c_str(), match.c_str())==0)
7680
return true;
7781
}
7882
return false;
@@ -226,9 +230,9 @@ void websocket_protocol::io_on_read(char* src, size_t len)
226230
{
227231
if ( m_http_parser->is_upgrade() &&
228232
m_http_parser->has("Upgrade") &&
229-
string_list_contains(m_http_parser->get("Upgrade"), "websocket") &&
233+
header_contains(m_http_parser->get("Upgrade"), "websocket") &&
230234
m_http_parser->has("Connection") &&
231-
string_list_contains(m_http_parser->get("Connection"), "Upgrade") &&
235+
header_contains(m_http_parser->get("Connection"), "Upgrade") &&
232236
m_http_parser->has("Sec-WebSocket-Key") &&
233237
m_http_parser->has("Sec-WebSocket-Version") )
234238
{
@@ -353,9 +357,9 @@ void websocket_protocol::io_on_read(char* src, size_t len)
353357
{
354358
if ( m_http_parser->is_upgrade() &&
355359
m_http_parser->has("Upgrade") &&
356-
string_list_contains(m_http_parser->get("Upgrade"), "websocket") &&
360+
header_contains(m_http_parser->get("Upgrade"), "websocket") &&
357361
m_http_parser->has("Connection") &&
358-
string_list_contains(m_http_parser->get("Connection"), "Upgrade") &&
362+
header_contains(m_http_parser->get("Connection"), "Upgrade") &&
359363
m_http_parser->has("Sec-WebSocket-Accept") &&
360364
m_http_parser->http_status_phrase() == "Switching Protocols" &&
361365
m_http_parser->http_status_code() == http_parser::status_code_switching_protocols)

0 commit comments

Comments
 (0)