Skip to content

Commit

Permalink
Started working on support for WebSockets.
Browse files Browse the repository at this point in the history
Fixed some compiler warnings when compiling with -Wextra

Thanks to Jan Jaeger's excellent bug report, made some changes
that should make it easier to build ShellInABox for OpenWRT.


git-svn-id: https://shellinabox.googlecode.com/svn/trunk@202 0da03de8-d603-11dd-86c2-0f8696b7b6f9
  • Loading branch information
[email protected] committed Mar 29, 2010
1 parent 5a75b2f commit 9b0a937
Show file tree
Hide file tree
Showing 29 changed files with 583 additions and 140 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2008-2009 Markus Gutschke <[email protected]>
Copyright (C) 2008-2010 Markus Gutschke <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
Expand Down
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2010-03-29 Markus Gutschke <[email protected]>

* Started working on support for WebSockets.

* Fixed some compiler warnings when compiling with -Wextra

* Thanks to Jan Jaeger's excellent bug report, made some changes
that should make it easier to build ShellInABox for OpenWRT.

2009-12-10 Markus Gutschke <[email protected]>

* Add .note.GNU-stack to all object files so that the generated
Expand Down
38 changes: 20 additions & 18 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ AM_CPPFLAGS =
AM_CFLAGS = -g -std=gnu99 -Wall
AM_LDFLAGS = -g

OBJCOPY ?= objcopy

noinst_LTLIBRARIES = libhttp.la \
liblogging.la
noinst_DATA = $(top_srcdir)/demo/demo.js
Expand Down Expand Up @@ -234,37 +236,37 @@ clean-local:
-rm -rf GNU-stack

.css.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

.gif.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack


.html.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack


.ico.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack


Expand All @@ -280,20 +282,20 @@ shellinabox/shell_in_a_box.o: shellinabox/shell_in_a_box.js config.h
"$<" >"$@"

.js.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack


.wav.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack


38 changes: 20 additions & 18 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,8 @@ uninstall-man: uninstall-man1
uninstall-man uninstall-man1


OBJCOPY ?= objcopy

libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status --recheck

Expand Down Expand Up @@ -1247,35 +1249,35 @@ clean-local:
-rm -rf GNU-stack

.css.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

.gif.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

.html.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

.ico.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

shellinabox/shell_in_a_box.o: shellinabox/shell_in_a_box.js config.h
Expand All @@ -1290,19 +1292,19 @@ shellinabox/shell_in_a_box.o: shellinabox/shell_in_a_box.js config.h
"$<" >"$@"

.js.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

.wav.o:
@echo objcopy "$<" "$@"
@objcopy -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)` \
@echo $(OBJCOPY) "$<" "$@"
@$(OBJCOPY) -I binary `$(objcopyflags)` `echo "$<" | $(renamesymbols)`\
"$<" "$@"
@-printf '\000' >GNU-stack && \
objcopy --add-section .note.GNU-stack=GNU-stack "$@"; \
$(OBJCOPY) --add-section .note.GNU-stack=GNU-stack "$@"; \
rm -f GNU-stack

# Tell versions [3.59,3.63) of GNU make to not export all variables.
Expand Down
5 changes: 4 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have support for isnan */
#define HAVE_ISNAN 1

/* Define to 1 if you have the <libutil.h> header file. */
/* #undef HAVE_LIBUTIL_H */

Expand Down Expand Up @@ -141,7 +144,7 @@
#define STDC_HEADERS 1

/* Most recent revision number in the version control system */
#define VCS_REVISION "200"
#define VCS_REVISION "202"

/* Version number of package */
#define VERSION "2.10"
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

/* Define to 1 if you have support for isnan */
#undef HAVE_ISNAN

/* Define to 1 if you have the <libutil.h> header file. */
#undef HAVE_LIBUTIL_H

Expand Down
21 changes: 20 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
ac_compiler_gnu=$ac_cv_c_compiler_gnu


VCS_REVISION=200
VCS_REVISION=202


cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -10682,6 +10682,25 @@ if ac_fn_c_try_link "$LINENO"; then :

$as_echo "#define HAVE_SIGWAIT 1" >>confdefs.h

fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <math.h>
int
main ()
{
isnan(0.0);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :

$as_echo "#define HAVE_ISNAN 1" >>confdefs.h

fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
Expand Down
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ(2.57)

dnl This is the one location where the authoritative version number is stored
AC_INIT(shellinabox, 2.10, [email protected])
VCS_REVISION=200
VCS_REVISION=202
AC_SUBST(VCS_REVISION)
AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}",
[Most recent revision number in the version control system])
Expand Down Expand Up @@ -55,6 +55,12 @@ AC_TRY_LINK([#include <pthread.h>
[AC_DEFINE(HAVE_SIGWAIT, 1,
Define to 1 if you have a working sigwait)])

dnl Not every system has support for isnan()
AC_TRY_LINK([#include <math.h>],
[isnan(0.0);],
[AC_DEFINE(HAVE_ISNAN, 1,
Define to 1 if you have support for isnan)])

dnl On some systems, calling /bin/login does not work. Disable the LOGIN
dnl feature, if the user tells us that it does not do the right thing.
AC_ARG_ENABLE(login,
Expand Down
2 changes: 1 addition & 1 deletion debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It was downloaded from http://shellinabox.com/

Upstream Author: [email protected]

Copyright (c) 2008-2009, Markus Gutschke
Copyright (c) 2008-2010, Markus Gutschke
All rights reserved.

This program is free software; you can redistribute it and/or modify
Expand Down
6 changes: 3 additions & 3 deletions demo/vt100.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// VT100.js -- JavaScript based terminal emulator
// Copyright (C) 2008-2009 Markus Gutschke <[email protected]>
// Copyright (C) 2008-2010 Markus Gutschke <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -1955,8 +1955,8 @@ VT100.prototype.toggleBell = function() {
};

VT100.prototype.about = function() {
alert("VT100 Terminal Emulator " + "2.10 (revision 200)" +
"\nCopyright 2008-2009 by Markus Gutschke\n" +
alert("VT100 Terminal Emulator " + "2.10 (revision 202)" +
"\nCopyright 2008-2010 by Markus Gutschke\n" +
"For more information check http://shellinabox.com");
};

Expand Down
15 changes: 14 additions & 1 deletion libhttp/http.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// http.h -- Library for implementing embedded custom HTTP servers
// Copyright (C) 2008-2009 Markus Gutschke <[email protected]>
// Copyright (C) 2008-2010 Markus Gutschke <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -56,7 +56,13 @@
#define HTTP_SUSPEND 3
#define HTTP_PARTIAL_REPLY 4

#define WS_START_OF_FRAME 0x0100
#define WS_END_OF_FRAME 0x0200
#define WS_CONNECTION_OPENED 0xFF00
#define WS_CONNECTION_CLOSED 0x7F00

#define NO_MSG "\001"
#define BINARY_MSG "\001%d%p"

#define NOINTR(x) ({ int i__; while ((i__ = (x)) < 0 && errno == EINTR); i__;})

Expand All @@ -77,6 +83,9 @@ void serverRegisterHttpHandler(Server *server, const char *url,
void serverRegisterStreamingHttpHandler(Server *server, const char *url,
int (*handler)(HttpConnection *, void *),
void *arg);
void serverRegisterWebSocketHandler(Server *server, const char *url,
int (*handler)(HttpConnection *, void *, int, const char *, int),
void *arg);
ServerConnection *serverAddConnection(Server *server, int fd,
int (*handleConnection)(ServerConnection *,
void *arg, short *events,
Expand Down Expand Up @@ -109,6 +118,10 @@ void *httpSetPrivate(HttpConnection *http, void *private);
void httpSendReply(HttpConnection *http, int code,
const char *msg, const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
void httpSendWebSocketTextMsg(HttpConnection *http, int type, const char *fmt,
...) __attribute__((format(printf, 3, 4)));
void httpSendWebSocketBinaryMsg(HttpConnection *http, int type,
const void *buf, int len);
void httpExitLoop(HttpConnection *http, int exitAll);
Server *httpGetServer(const HttpConnection *http);
ServerConnection *httpGetServerConnection(const HttpConnection *);
Expand Down
Loading

0 comments on commit 9b0a937

Please sign in to comment.