Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
refact.
Browse files Browse the repository at this point in the history
 - WebSocket-TCP Proxy does not handle subprotocol and locale.
   => use WebSocket Proxy instead.
 - type section is renamed into base64 section
 - rename some file names and functions.
   s/base64/mod_websocket_base64/, s/sha1/mod_websocket_sha1/, s/connector/socket/ etc.
 - use googletest
   => not tested all yet.
 - move config_parser functions into supplement.

 next, implement tests
 - handshake, frame, socket
   mod_websocket.c will be tested with jstest-driver.
  • Loading branch information
nori0428 committed Nov 14, 2013
1 parent 9e69011 commit d70231b
Show file tree
Hide file tree
Showing 39 changed files with 1,144 additions and 3,315 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
@@ -0,0 +1,4 @@
[submodule "contrib/lighttpd1.4"]
path = contrib/lighttpd1.4
url = https://github.com/lighttpd/lighttpd1.4.git
ignore = untracked
20 changes: 8 additions & 12 deletions Makefile.am
@@ -1,13 +1,15 @@
## $Id$
SUBDIRS = . stub src

if WITH_TEST
STUB_DIR = stub
SUBDIRS += test
all-local:
(cd $(top_srcdir)/contrib/gtest-1.7.0; make)
endif

SUBDIRS = \
. $(STUB_DIR) src
clean-local:
${RM} -f *~

install:
install-data-local:
@if [ -z "${LIGHTTPD_LOCATION}" ]; then \
echo "not specified lighttpd location"; \
exit 0; \
Expand All @@ -22,8 +24,6 @@ install:
fi;
@echo "copy mod_websocket files into ${LIGHTTPD_LOCATION}"
cp src/mod_websocket*.{h,c} ${LIGHTTPD_LOCATION}/src
cp src/sha1.{h,c} ${LIGHTTPD_LOCATION}/src
cp src/base64.{h,c} ${LIGHTTPD_LOCATION}/src
@echo "done"

@echo "patch the lighttpd sources"
Expand All @@ -34,10 +34,6 @@ install:
@echo
@echo "$$ cd ${LIGHTTPD_LOCATION}"
@echo "$$ ./autogen.sh"
@echo "$$ ./configure --with-websocket[=ALL/RFC-6455/IETF-00] [--without-libicu]"
@echo "$$ ./configure --with-websocket[=ALL/RFC-6455/IETF-00]"
@echo "$$ make"
@echo

include $(top_srcdir)/m4/Makefile.rules

## EOF
21 changes: 5 additions & 16 deletions bootstrap
@@ -1,18 +1,7 @@
#!/bin/sh
# $Id$

HOST_OS=`uname -s`
if test "x${HOST_OS}" = "xDarwin"; then
LIBTOOLIZE=glibtoolize
else
LIBTOOLIZE=libtoolize
fi
set -x
${LIBTOOLIZE} --force --copy
aclocal -I m4
autoheader
rm -f m4/config.guess # XXX
automake --foreign --add-missing --copy
autoconf

# EOF
set -e
git submodule sync
git submodule update --init
unzip -n contrib/gtest-1.7.0.zip -d contrib/
autoreconf --force --install --verbose
146 changes: 46 additions & 100 deletions configure.ac
@@ -1,117 +1,75 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_INIT([mod_websocket], [1.0], [nori.0428@gmail.com])
AC_CONFIG_SRCDIR([src/mod_websocket.c])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIR(m4)
AC_CONFIG_AUX_DIR(m4)
AM_INIT_AUTOMAKE
AC_INIT([mod_websocket], [2.7], [nori.0428@gmail.com])
AC_CONFIG_AUX_DIR([m4])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/mod_websocket.h])
AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_HEADERS([src/config.h])

AC_CANONICAL_HOST
case $host_os in
*darwin* )
CFLAGS="$CFLAGS -I/opt/local/include/"
LDFLAGS="$LDFLAGS -L/opt/local/lib/"
LIBS="$LIBS -lncurses";;
LDFLAGS="$LDFLAGS -L/opt/local/lib/";;
* )
CFLAGS="$CFLAGS -I/usr/local/include/"
LDFLAGS="$LDFLAGS -L/usr/local/lib/"
esac

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PROG_LEX
AC_PROG_YACC

# Checks for making test
AC_MSG_CHECKING(whether --enable-debug option specified)
AC_ARG_ENABLE([debug],
AC_HELP_STRING([--enable-debug], [no optimization@<:@default=no@:>@]),
[debug="$enableval"], [debug=no])
AC_MSG_RESULT(${debug})
if test "x${debug}" != "xno"; then
CFLAGS="$CFLAGS -g"
else
CFLAGS="$CFLAGS -O3"
fi

# Checks for making test
AC_MSG_CHECKING(whether --with-test option specified)
AC_ARG_WITH(
test,
AC_HELP_STRING([--with-test],
[make test of mod_websocket@<:@default=no@:>@]),
[ with_test=$withval ],
[ with_test=yes ])
AC_ARG_WITH([test],
AC_HELP_STRING([--with-test],
[make tests of mod_websocket@<:@default=yes@:>@]),
[with_test="$withval"], [with_test=yes])
AC_MSG_RESULT(${with_test})
if test "x${with_test}" = "xyes" ; then
AC_CHECK_LIB(ev, ev_io_start, has_libev=yes, AC_MSG_ERROR([needs libev]))
AC_CHECK_LIB(cunit, CU_basic_run_tests, has_cunit=yes, AC_MSG_ERROR([needs libcunit]))
LDFLAGS="$LDFLAGS -lev -lcunit"
fi
AM_CONDITIONAL(WITH_TEST, test x$with_test != xno)

# Checks for making sample
AC_MSG_CHECKING(whether --with-sample option specified)
AC_ARG_WITH(
sample,
AC_HELP_STRING([--with-sample],
[make sample of mod_websocket@<:@default=no@:>@]),
[ with_sample=$withval ],
[ with_sample=no ])
AC_MSG_RESULT(${with_sample})
if test "x${with_sample}" = "xyes" ; then
AC_CHECK_LIB(ev, ev_io_start, has_libev=yes, AC_MSG_ERROR([needs libev]))
LDFLAGS="$LDFLAGS -lev"
fi
AM_CONDITIONAL(WITH_SAMPLE, test x$with_sample = xyes)

# Check for libicu
AC_MSG_CHECKING(whether --with-libicu option specified)
AC_ARG_WITH(
libicu,
AC_HELP_STRING([--with-libicu],
[use ICU lib for websocket@<:@default=yes@:>@]),
[ with_libicu=$withval ],
[ with_libicu=yes ])
AC_MSG_RESULT(${with_libicu})
if test "x${with_libicu}" != "xno"; then
LIBS="$LIBS -licui18n -licuuc"
CFLAGS="$CFLAGS -D_MOD_WEBSOCKET_WITH_ICU_"
if test "x${with_libicu}" != "xyes"; then
LDFLAGS="$LDFLAGS -L${with_icu}"
fi
AC_MSG_CHECKING([for ucnv_open in -licui18n])
AC_TRY_LINK([#include <unicode/ucnv.h>],
[UErrorCode err = U_ZERO_ERROR; ucnv_open("utf-8", &err);],
AC_MSG_RESULT(yes),
[AC_MSG_RESULT(no); AC_MSG_ERROR([needs ICU libs])])
fi
AM_CONDITIONAL(WITH_LIBICU, test x$with_libicu != xno)

# Check for websocket version
AC_MSG_CHECKING(whether --with-websocket option specified)
AC_ARG_WITH(
websocket,
AC_HELP_STRING([--with-websocket@<:@=ALL/RFC-6455/IETF-00@:>@],
[specify draft version@<:@default=ALL@:>@]),
[ websocket=$withval ],
[ websocket=ALL ])
AC_ARG_WITH([websocket],
AC_HELP_STRING([--with-websocket@<:@=ALL/RFC-6455/IETF-00@:>@],
[support WebSocket version@<:@default=ALL@:>@]),
[websocket="$withval"], [websocket=ALL])
AC_MSG_RESULT(${websocket})
if test "x${websocket}" = "xall" -o "x${websocket}" = "xALL" ; then
CFLAGS="$CFLAGS -D_MOD_WEBSOCKET_SPEC_IETF_00_ -D_MOD_WEBSOCKET_SPEC_RFC_6455_"
MODULE_CFLAGS="$MODULE_CFLAGS -D_MOD_WEBSOCKET_SPEC_IETF_00_ -D_MOD_WEBSOCKET_SPEC_RFC_6455_"
elif test "x${websocket}" = "xrfc-6455" -o "x${websocket}" = "xRFC-6455" ; then
CFLAGS="$CFLAGS -D_MOD_WEBSOCKET_SPEC_RFC_6455_"
MODULE_CFLAGS="$MODULE_CFLAGS -D_MOD_WEBSOCKET_SPEC_RFC_6455_"
elif test "x${websocket}" = "xietf-00" -o "x${websocket}" = "xIETF-00" ; then
CFLAGS="$CFLAGS -D_MOD_WEBSOCKET_SPEC_IETF_00_"
MODULE_CFLAGS="$MODULE_CFLAGS -D_MOD_WEBSOCKET_SPEC_IETF_00_"
elif test "x${websocket}" != "xno" ; then
AC_MSG_ERROR([websocket option is invalid. plz specify ALL, IETF-00, RFC-6455])
fi

# Checks for typedefs, structures, and compiler characteristics.
AC_C_BIGENDIAN
if test "x$ac_cv_c_bigendian" = "xyes"; then
CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"
MODULE_CFLAGS="$MODULE_CFLAGS -DWORDS_BIGENDIAN"
fi

# Check for target lighttpd
AC_MSG_CHECKING(whether --with-lighttpd option specified)
AC_ARG_WITH(
lighttpd,
AC_HELP_STRING([--with-lighttpd@<:@=/path/to/lighttpd@:>@],
[specify lighttpd location@<:@default=no:>@]),
[ lighttpd=$withval ],
[ lighttpd=no ])
AC_ARG_WITH([lighttpd],
AC_HELP_STRING([--with-lighttpd@<:@=/path/to/lighttpd@:>@],
[specify lighttpd location@<:@default=no:>@]),
[lighttpd="$withval"],[lighttpd=no])
AC_MSG_RESULT(${lighttpd})
if test "x${lighttpd}" != "xno"; then
LIGHTTPD_LOCATION=${lighttpd}
Expand All @@ -120,29 +78,17 @@ fi

# additional CFLAGS
# add -Wno-sign-compare and remove -Wundef for flex
if test "x${with_test}" = "xyes" -o "x${with_sample}" = "xyes" ; then
MODULE_CFLAGS="-g -O3 -Werror -W -Wall -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wno-sign-compare -Waggregate-return -Wnested-externs -Wno-long-long -Wunused -Wfloat-equal -Wformat -fno-strict-aliasing"
else
MODULE_CFLAGS="-O3 -Werror -W -Wall -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wno-sign-compare -Waggregate-return -Wnested-externs -Wno-long-long -Wunused -Wfloat-equal -Wformat -fno-strict-aliasing"
fi
MODULE_CFLAGS="$MODULE_CFLAGS -Werror -W -Wall -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wno-sign-compare -Waggregate-return -Wnested-externs -Wno-long-long -Wunused -Wfloat-equal -Wformat -fno-strict-aliasing"
AC_SUBST(MODULE_CFLAGS)

AC_OUTPUT(\
Makefile \
src/Makefile \
)
if test "x${with_test}" == "xyes" ; then
AC_OUTPUT(\
stub/Makefile \
src/tests/Makefile \
)
fi
if test "x${with_sample}" == "xyes" ; then
AC_OUTPUT(\
src/samples/Makefile \
src/samples/chat/Makefile \
src/samples/chat/src/Makefile \
)
AC_CONFIG_FILES([Makefile \
stub/Makefile \
src/Makefile \
test/Makefile])

if test "x${with_test}" = "xyes" ; then
AC_CONFIG_SUBDIRS(contrib/gtest-1.7.0)
fi

# EOF
AC_OUTPUT

Binary file added contrib/gtest-1.7.0.zip
Binary file not shown.
9 changes: 0 additions & 9 deletions m4/Makefile.rules

This file was deleted.

59 changes: 11 additions & 48 deletions src/Makefile.am
@@ -1,54 +1,17 @@
## $Id$
noinst_LTLIBRARIES = libmod_websocket.la

BUILT_SOURCES = parser.h
AM_YFLAGS = -d
AM_LFLAGS = -i

if WITH_TEST
TESTS_DIR = tests
endif

if WITH_SAMPLE
SAMPLES_DIR = samples
endif

SUBDIRS = \
. $(TESTS_DIR) $(SAMPLES_DIR)

INCLUDES = \
-I${top_srcdir}/stub

noinst_LTLIBRARIES = libwebsocket.la

if WITH_LIBICU
libwebsocket_la_SOURCES = \
scanner.l \
parser.y \
base64.h \
base64.c \
sha1.h \
sha1.c \
mod_websocket.h \
mod_websocket_conv.c \
mod_websocket_connector.c \
mod_websocket_handshake.c \
mod_websocket_frame.c
libwebsocket_la_CFLAGS = $(MODULE_CFLAGS)
else
libwebsocket_la_SOURCES = \
scanner.l \
parser.y \
base64.h \
base64.c \
sha1.h \
sha1.c \
libmod_websocket_la_SOURCES = \
mod_websocket_base64.h \
mod_websocket_base64.c \
mod_websocket_sha1.h \
mod_websocket_sha1.c \
mod_websocket.h \
mod_websocket_connector.c \
mod_websocket_socket.h \
mod_websocket_socket.c \
mod_websocket_handshake.c \
mod_websocket_frame.c
libwebsocket_la_CFLAGS = $(MODULE_CFLAGS)
endif

include $(top_srcdir)/m4/Makefile.rules
libmod_websocket_la_CFLAGS = -I$(top_srcdir)/stub $(MODULE_CFLAGS)

## EOF
clean-local:
${RM} -f *~

0 comments on commit d70231b

Please sign in to comment.