Anklang-0.3.0.dev956+gd75ac925 anklang-0.3.0.dev956+gd75ac925
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#pragma once
3
4#include <ase/cxxaux.hh>
5
6namespace Ase {
7
8class WebSocketServer;
9using WebSocketServerP = std::shared_ptr<WebSocketServer>;
10
11class WebSocketConnection : public virtual std::enable_shared_from_this<WebSocketConnection> {
12 friend class WebSocketServer;
13protected:
14 virtual ~WebSocketConnection () = 0;
15 struct Info { std::function<String (String)> header; StringS subs; String local, remote; int lport = 0, rport = 0; };
16 Info get_info ();
17public:
18 bool is_open () const;
19 String nickname ();
20 void log_status (int status, const String &filepath = "");
21 virtual void http_request ();
22 virtual bool authenticated (const std::string &token);
23 virtual int validate ();
24 virtual void failed ();
25 virtual void opened ();
26 virtual void message (const String &message);
27 virtual void closed ();
28 virtual void log (const String &message);
29 bool send_text (const String &message);
30 bool send_binary (const String &blob);
31 struct Internals;
32private:
33 Internals &internals_;
34 uint64_t internals_mem_[17];
35protected:
36 explicit WebSocketConnection (Internals &internals, int logflags);
37 const int logflags_ = 0;
38};
40
41class WebSocketServer : public virtual std::enable_shared_from_this<WebSocketServer> {
42protected:
43 static WebSocketConnection::Internals& internals (WebSocketConnection &c) { return c.internals_; }
44 virtual ~WebSocketServer();
45public:
47 using UnlistenCB = std::function<void ()>;
48 struct SocketInfo { int fd; String host; int port; };
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 SocketInfo &info, const UnlistenCB& = {}) = 0;
55 virtual void reset () = 0;
56 virtual void shutdown () = 0;
57 virtual void see_other (const String &uri) = 0;
58 static SocketInfo bind_port (const String &host = "", int port = 0);
59 static WebSocketServerP create (const MakeConnection &make, int logflags = 0, const std::string &session_token = "");
60 static String user_agent ();
61 static String mime_type (const String &ext, bool utf8);
62 static bool utf8_validate (const std::string &utf8string);
63};
64
65} // Ase
66
virtual void closed()
Pairs with opened().
Definition websocket.cc:508
virtual int validate()
Return true to allow opened().
Definition websocket.cc:504
virtual void http_request()
Independent of socket ops.
Definition websocket.cc:532
virtual void opened()
Pairs with closed().
Definition websocket.cc:506
bool send_binary(const String &blob)
Returns true if binary blob was sent.
Definition websocket.cc:404
virtual void message(const String &message)
Only if opened.
Definition websocket.cc:507
virtual void failed()
Never folloed by opened().
Definition websocket.cc:505
bool send_text(const String &message)
Returns true if text message was sent.
Definition websocket.cc:379
virtual bool authenticated(const std::string &token)
Return true to allow validate().
Definition websocket.cc:512
static bool utf8_validate(const std::string &utf8string)
Validate UTF-8 string with websocketpp::utf8_validator.
Definition websocket.cc:789
The Anklang C++ API namespace.
Definition api.hh:8
std::string String
Convenience alias for std::string.
Definition cxxaux.hh:34
typedef uint64_t