Debian Codegraph @

platform/web/export/editor_http_server.h

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_http_server.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/io/image_loader.h"
34 #include "core/io/stream_peer_tls.h"
35 #include "core/io/tcp_server.h"
36 #include "core/io/zip_io.h"
37 #include "editor/file_system/editor_paths.h"
38
39 class EditorHTTPServer : public RefCounted {
40 GDSOFTCLASS(EditorHTTPServer, RefCounted);
41
42 private:
43 Ref<TCPServer> server;
44 HashMap<String, String> mimes;
45 Ref<StreamPeerTCP> tcp;
46 Ref<StreamPeerTLS> tls;
47 Ref<StreamPeer> peer;
48 Ref<CryptoKey> key;
49 Ref<X509Certificate> cert;
50 bool use_tls = false;
51 uint64_t time = 0;
52 uint8_t req_buf[4096];
53 int req_pos = 0;
54
55 SafeFlag server_quit;
56 Mutex server_lock;
57 Thread server_thread;
58
59 void _clear_client();
60 void _set_internal_certs(Ref<Crypto> p_crypto);
61 void _send_response();
62 void _poll();
63
64 static void _server_thread_poll(void *data);
65
66 public:
67 EditorHTTPServer();
68 ~EditorHTTPServer();
69
70 void stop();
71 Error listen(int p_port, IPAddress p_address, bool p_use_tls, String p_tls_key, String p_tls_cert);
72 bool is_listening() const;
73 };