From ea96e4decaa23fc8ddfb528d4851751ec9496490 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 18 Oct 2017 07:49:59 -0700 Subject: I think this version works. It would be really cool to add more features, like pre-websocket negotiation and callbacks for serving web content, etc. --- src/unstable/protocolwebsocket.h | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/unstable/protocolwebsocket.h (limited to 'src/unstable/protocolwebsocket.h') diff --git a/src/unstable/protocolwebsocket.h b/src/unstable/protocolwebsocket.h new file mode 100644 index 0000000..cf00d34 --- /dev/null +++ b/src/unstable/protocolwebsocket.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2014 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_PROTOCOL_WEB_SOCKET_H +#define BU_PROTOCOL_WEB_SOCKET_H + +#include "bu/protocol.h" +#include "bu/hash.h" + +namespace Bu +{ + class ProtocolWebSocket : public Bu::Protocol + { + public: + enum Operation + { + Continuation = 0, + Text = 1, + Binary = 2, + ConClose = 8, + Ping = 9, + Pong = 10 + }; + + public: + ProtocolWebSocket(); + virtual ~ProtocolWebSocket(); + + virtual void onNewConnection( Bu::Client *pClient ); + virtual void onNewData( Bu::Client *pClient ); + + virtual void onHandshakeComplete()=0; + virtual void onNewMessage( const Bu::String &sData, Operation eOp )=0; + void writeMessage( const Bu::String &sData, Operation eOp=Text ); + + private: + bool stateProtoId(); + bool stateHandshake(); + bool processHeaders(); + bool headerMatch( const Bu::String &sKey, const Bu::String &sValue ); + bool readHttpHdrLine( Bu::String &sLine ); + bool parseMessage(); + + private: + enum Status + { + stProtoId = 0, + stHandshake = 1, + stReady = 10 + }; + + protected: + Bu::Client *pClient; + Status eStatus; + Bu::String sPath; + Bu::Hash hHeader; + }; +} + +#endif -- cgit v1.2.3