Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
websocket.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#ifndef __ASE_WEBSOCKET_HH__
3#define __ASE_WEBSOCKET_HH__
4
5#include <ase/cxxaux.hh>
6
7namespace Ase {
8
9class WebSocketServer;
10using WebSocketServerP = std::shared_ptr<WebSocketServer>;
11
12class WebSocketConnection : public virtual std::enable_shared_from_this<WebSocketConnection> {
13 friend class WebSocketServer;
14protected:
15 virtual ~WebSocketConnection () = 0;
16 struct Info { std::function<String (String)> header; StringS subs; String local, remote; int lport = 0, rport = 0; };
17 Info get_info ();
18public:
19 bool is_open () const;
20 String nickname ();
21 void log_status (int status, const String &filepath = "");
22 virtual void http_request ();
23 virtual bool authenticated (const std::string &token);
24 virtual int validate ();
25 virtual void failed ();
26 virtual void opened ();
27 virtual void message (const String &message);
28 virtual void closed ();
29 virtual void log (const String &message);
30 bool send_text (const String &message);
31 bool send_binary (const String &blob);
32 struct Internals;
33private:
34 Internals &internals_;
35 uint64_t internals_mem_[17];
36protected:
37 explicit WebSocketConnection (Internals &internals, int logflags);
38 const int logflags_ = 0;
39};
41
42class WebSocketServer : public virtual std::enable_shared_from_this<WebSocketServer> {
43protected:
44 static WebSocketConnection::Internals& internals (WebSocketConnection &c) { return c.internals_; }
45 virtual ~WebSocketServer();
46public:
48 using UnlistenCB = std::function<void ()>;
49 virtual void http_dir (const String &path) = 0;
50 virtual void http_alias (const String &webdir, const String &path) = 0;
51 virtual String map_url (const String &urlpath) = 0;
52 virtual int listen_port () const = 0;
53 virtual std::string url () const = 0;
54 virtual void listen (const String &host = "", int port = 0, const UnlistenCB& = {}) = 0;
55 virtual void reset () = 0;
56 virtual void shutdown () = 0;
57 virtual void see_other (const String &uri) = 0;
58 static WebSocketServerP create (const MakeConnection &make, int logflags = 0, const std::string &session_token = "");
59 static String user_agent ();
60 static String mime_type (const String &ext, bool utf8);
61 static bool utf8_validate (const std::string &utf8string);
62};
63
64} // Ase
65
66#endif // __ASE_WEBSOCKET_HH__
virtual void closed()
Pairs with opened().
Definition websocket.cc:387
virtual int validate()
Return true to allow opened().
Definition websocket.cc:383
virtual void http_request()
Independent of socket ops.
Definition websocket.cc:411
virtual void opened()
Pairs with closed().
Definition websocket.cc:385
bool send_binary(const String &blob)
Returns true if binary blob was sent.
Definition websocket.cc:283
virtual void message(const String &message)
Only if opened.
Definition websocket.cc:386
virtual void failed()
Never folloed by opened().
Definition websocket.cc:384
bool send_text(const String &message)
Returns true if text message was sent.
Definition websocket.cc:264
virtual bool authenticated(const std::string &token)
Return true to allow validate().
Definition websocket.cc:391
static bool utf8_validate(const std::string &utf8string)
Validate UTF-8 string with websocketpp::utf8_validator.
Definition websocket.cc:617
The Anklang C++ API namespace.
Definition api.hh:9
std::string String
Convenience alias for std::string.
Definition cxxaux.hh:35
typedef uint64_t