Conditional compile for WebSocket.

WebSocket support depends on Message Digest support.
pull/16/merge
Tatsuhiro Tsujikawa 2012-04-08 00:50:25 +09:00
parent 7bc2a14d9f
commit fcbdecfd1e
7 changed files with 123 additions and 14 deletions

View File

@ -93,7 +93,7 @@ Dependency
.External Library Dependency
[options="header"]
|====================================================
|==================================================================
|features |dependency
|HTTPS |GnuTLS or OpenSSL
|BitTorrent |libnettle+libgmp or libgcrypt or OpenSSL
@ -103,7 +103,8 @@ Dependency
|Async DNS |C-Ares
|Firefox3/Chromium cookie|libsqlite3
|XML-RPC |libxml2 or Expat.
|====================================================
|JSON-RPC over WebSocket |libnettle or libgcrypt or OpenSSL
|==================================================================
Note;;

View File

@ -562,9 +562,15 @@ if test "x$have_option_const_name" = "xyes"; then
fi
AC_CONFIG_SUBDIRS([deps/wslay])
LIBS="\$(top_builddir)/deps/wslay/lib/libwslay.la $LIBS"
# $(top_srcdir) for `make distcheck`
CPPFLAGS="-I\$(top_builddir)/deps/wslay/lib/includes -I\$(top_srcdir)/deps/wslay/lib/includes $CPPFLAGS"
if test "x$enable_message_digest" = "xyes"; then
enable_websocket=yes
AC_DEFINE([ENABLE_WEBSOCKET], [1],
[Define 1 if WebSocket support is enabled.])
LIBS="\$(top_builddir)/deps/wslay/lib/libwslay.la $LIBS"
# $(top_srcdir) for `make distcheck`
CPPFLAGS="-I\$(top_builddir)/deps/wslay/lib/includes -I\$(top_srcdir)/deps/wslay/lib/includes $CPPFLAGS"
fi
AM_CONDITIONAL([ENABLE_WEBSOCKET], [test "x$enable_websocket" = "xyes"])
AC_CONFIG_FILES([Makefile
src/Makefile
@ -599,3 +605,5 @@ echo "Epoll: $have_epoll"
echo "Bittorrent: $enable_bittorrent"
echo "Metalink: $enable_metalink"
echo "XML-RPC: $enable_xml_rpc"
echo "Message Digest: $enable_message_digest"
echo "WebSocket: $enable_websocket"

View File

@ -43,7 +43,6 @@
#include "RequestGroupMan.h"
#include "HttpServerBodyCommand.h"
#include "HttpServerResponseCommand.h"
#include "WebSocketResponseCommand.h"
#include "RecoverableException.h"
#include "prefs.h"
#include "Option.h"
@ -51,9 +50,14 @@
#include "wallclock.h"
#include "fmt.h"
#include "SocketRecvBuffer.h"
#include "MessageDigest.h"
#include "message_digest_helper.h"
#include "base64.h"
#ifdef ENABLE_MESSAGE_DIGEST
# include "MessageDigest.h"
# include "message_digest_helper.h"
#endif // ENABLE_MESSAGE_DIGEST
#ifdef ENABLE_WEBSOCKET
# include "WebSocketResponseCommand.h"
#endif // ENABLE_WEBSOCKET
namespace aria2 {
@ -108,6 +112,8 @@ void HttpServerCommand::checkSocketRecvBuffer()
}
}
#ifdef ENABLE_WEBSOCKET
namespace {
// Creates server's WebSocket accept key which will be sent in
// Sec-WebSocket-Accept header field. The |clientKey| is the value
@ -139,6 +145,8 @@ int websocketHandshake(const SharedHandle<HttpHeader>& header)
}
} // namespace
#endif // ENABLE_WEBSOCKET
bool HttpServerCommand::execute()
{
if(e_->getRequestGroupMan()->downloadFinished() || e_->isHaltRequested()) {
@ -170,6 +178,7 @@ bool HttpServerCommand::execute()
const std::string& connectionHd = header->find("connection");
if(util::strieq(upgradeHd.begin(), upgradeHd.end(), "websocket") &&
util::strieq(connectionHd.begin(), connectionHd.end(), "upgrade")) {
#ifdef ENABLE_WEBSOCKET
int status = websocketHandshake(header);
Command* command;
if(status == 101) {
@ -193,6 +202,15 @@ bool HttpServerCommand::execute()
e_->addCommand(command);
e_->setNoWait(true);
return true;
#else // !ENABLE_WEBSOCKET
httpServer_->feedResponse(400);
Command* command = new HttpServerResponseCommand(getCuid(),
httpServer_, e_,
socket_);
e_->addCommand(command);
e_->setNoWait(true);
return true;
#endif // !ENABLE_WEBSOCKET
} else {
if(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE) <
httpServer_->getContentLength()) {

View File

@ -227,16 +227,23 @@ SRCS = Socket.h\
rpc_helper.cc rpc_helper.h\
WatchProcessCommand.cc WatchProcessCommand.h\
UnknownOptionException.cc UnknownOptionException.h\
WebSocketSession.cc WebSocketSession.h\
WebSocketSessionMan.cc WebSocketSessionMan.h\
WebSocketResponseCommand.cc WebSocketResponseCommand.h\
WebSocketInteractionCommand.cc WebSocketInteractionCommand.h\
Notifier.cc Notifier.h
if MINGW_BUILD
SRCS += WinConsoleFile.cc WinConsoleFile.h
endif # MINGW_BUILD
if ENABLE_WEBSOCKET
SRCS += WebSocketSession.cc WebSocketSession.h\
WebSocketSessionMan.cc WebSocketSessionMan.h\
WebSocketResponseCommand.cc WebSocketResponseCommand.h\
WebSocketInteractionCommand.cc WebSocketInteractionCommand.h
endif # ENABLE_WEBSOCKET
if !ENABLE_WEBSOCKET
SRCS += NullWebSocketMan.h
endif # !ENABLE_WEBSOCKET
if HAVE_SOME_XMLLIB
SRCS += XmlAttr.cc XmlAttr.h\
XmlParser.h\

View File

@ -63,7 +63,11 @@
#include "UriListParser.h"
#include "SingletonHolder.h"
#include "Notifier.h"
#include "WebSocketSessionMan.h"
#ifdef ENABLE_WEBSOCKET
# include "WebSocketSessionMan.h"
#else // !ENABLE_WEBSOCKET
# include "NullWebSocketSessionMan.h"
#endif // !ENABLE_WEBSOCKET
#ifdef ENABLE_SSL
# include "TLSContext.h"
#endif // ENABLE_SSL

View File

@ -34,8 +34,12 @@
/* copyright --> */
#include "Notifier.h"
#include "RequestGroup.h"
#include "WebSocketSessionMan.h"
#include "LogFactory.h"
#ifdef ENABLE_WEBSOCKET
# include "WebSocketSessionMan.h"
#else // !ENABLE_WEBSOCKET
# include "NullWebSocketSessionMan.h"
#endif // !ENABLE_WEBSOCKET
namespace aria2 {

View File

@ -0,0 +1,67 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2012 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_NULL_WEB_SOCKET_SESSION_MAN_H
#define D_NULL_WEB_SOCKET_SESSION_MAN_H
#include "common.h"
#include <string>
#include "SharedHandle.h"
// Empty implementation for build without WebSocket support.
namespace aria2 {
class RequestGroup;
namespace rpc {
class WebSocketSession {};
class WebSocketSessionMan {
public:
WebSocketSessionMan() {}
~WebSocketSessionMan() {}
void addSession(const SharedHandle<WebSocketSession>& wsSession) {}
void removeSession(const SharedHandle<WebSocketSession>& wsSession) {}
void addNotification(const std::string& method, const RequestGroup* group) {}
};
} // namespace rpc
} // aria2
#endif // D_NULL_WEB_SOCKET_SESSION_MAN_H