Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/web/export/editor_http_server.h
10278 views
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
private:
41
Ref<TCPServer> server;
42
HashMap<String, String> mimes;
43
Ref<StreamPeerTCP> tcp;
44
Ref<StreamPeerTLS> tls;
45
Ref<StreamPeer> peer;
46
Ref<CryptoKey> key;
47
Ref<X509Certificate> cert;
48
bool use_tls = false;
49
uint64_t time = 0;
50
uint8_t req_buf[4096];
51
int req_pos = 0;
52
53
SafeFlag server_quit;
54
Mutex server_lock;
55
Thread server_thread;
56
57
void _clear_client();
58
void _set_internal_certs(Ref<Crypto> p_crypto);
59
void _send_response();
60
void _poll();
61
62
static void _server_thread_poll(void *data);
63
64
public:
65
EditorHTTPServer();
66
~EditorHTTPServer();
67
68
void stop();
69
Error listen(int p_port, IPAddress p_address, bool p_use_tls, String p_tls_key, String p_tls_cert);
70
bool is_listening() const;
71
};
72
73