diff options
| author | Mike Buland <mbuland@penny-arcade.com> | 2017-10-18 07:49:59 -0700 |
|---|---|---|
| committer | Mike Buland <mbuland@penny-arcade.com> | 2017-10-18 07:49:59 -0700 |
| commit | ea96e4decaa23fc8ddfb528d4851751ec9496490 (patch) | |
| tree | 585ed55a2fda09b388e02f1b6812893ac234f30a /src/unstable/protocolwebsocket.h | |
| parent | 317a740f0198085937bf4fdbf032cc481d20f4ed (diff) | |
| download | libbu++-ea96e4decaa23fc8ddfb528d4851751ec9496490.tar.gz libbu++-ea96e4decaa23fc8ddfb528d4851751ec9496490.tar.bz2 libbu++-ea96e4decaa23fc8ddfb528d4851751ec9496490.tar.xz libbu++-ea96e4decaa23fc8ddfb528d4851751ec9496490.zip | |
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.
Diffstat (limited to 'src/unstable/protocolwebsocket.h')
| -rw-r--r-- | src/unstable/protocolwebsocket.h | 64 |
1 files changed, 64 insertions, 0 deletions
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2014 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_PROTOCOL_WEB_SOCKET_H | ||
| 9 | #define BU_PROTOCOL_WEB_SOCKET_H | ||
| 10 | |||
| 11 | #include "bu/protocol.h" | ||
| 12 | #include "bu/hash.h" | ||
| 13 | |||
| 14 | namespace Bu | ||
| 15 | { | ||
| 16 | class ProtocolWebSocket : public Bu::Protocol | ||
| 17 | { | ||
| 18 | public: | ||
| 19 | enum Operation | ||
| 20 | { | ||
| 21 | Continuation = 0, | ||
| 22 | Text = 1, | ||
| 23 | Binary = 2, | ||
| 24 | ConClose = 8, | ||
| 25 | Ping = 9, | ||
| 26 | Pong = 10 | ||
| 27 | }; | ||
| 28 | |||
| 29 | public: | ||
| 30 | ProtocolWebSocket(); | ||
| 31 | virtual ~ProtocolWebSocket(); | ||
| 32 | |||
| 33 | virtual void onNewConnection( Bu::Client *pClient ); | ||
| 34 | virtual void onNewData( Bu::Client *pClient ); | ||
| 35 | |||
| 36 | virtual void onHandshakeComplete()=0; | ||
| 37 | virtual void onNewMessage( const Bu::String &sData, Operation eOp )=0; | ||
| 38 | void writeMessage( const Bu::String &sData, Operation eOp=Text ); | ||
| 39 | |||
| 40 | private: | ||
| 41 | bool stateProtoId(); | ||
| 42 | bool stateHandshake(); | ||
| 43 | bool processHeaders(); | ||
| 44 | bool headerMatch( const Bu::String &sKey, const Bu::String &sValue ); | ||
| 45 | bool readHttpHdrLine( Bu::String &sLine ); | ||
| 46 | bool parseMessage(); | ||
| 47 | |||
| 48 | private: | ||
| 49 | enum Status | ||
| 50 | { | ||
| 51 | stProtoId = 0, | ||
| 52 | stHandshake = 1, | ||
| 53 | stReady = 10 | ||
| 54 | }; | ||
| 55 | |||
| 56 | protected: | ||
| 57 | Bu::Client *pClient; | ||
| 58 | Status eStatus; | ||
| 59 | Bu::String sPath; | ||
| 60 | Bu::Hash<Bu::String, Bu::StringList> hHeader; | ||
| 61 | }; | ||
| 62 | } | ||
| 63 | |||
| 64 | #endif | ||
