editor_http_server.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef WEB_EDITOR_HTTP_SERVER_H
  31. #define WEB_EDITOR_HTTP_SERVER_H
  32. #include "core/io/image_loader.h"
  33. #include "core/io/stream_peer_tls.h"
  34. #include "core/io/tcp_server.h"
  35. #include "core/io/zip_io.h"
  36. #include "editor/editor_paths.h"
  37. class EditorHTTPServer : public RefCounted {
  38. private:
  39. Ref<TCPServer> server;
  40. HashMap<String, String> mimes;
  41. Ref<StreamPeerTCP> tcp;
  42. Ref<StreamPeerTLS> tls;
  43. Ref<StreamPeer> peer;
  44. Ref<CryptoKey> key;
  45. Ref<X509Certificate> cert;
  46. bool use_tls = false;
  47. uint64_t time = 0;
  48. uint8_t req_buf[4096];
  49. int req_pos = 0;
  50. SafeFlag server_quit;
  51. Mutex server_lock;
  52. Thread server_thread;
  53. void _clear_client();
  54. void _set_internal_certs(Ref<Crypto> p_crypto);
  55. void _send_response();
  56. void _poll();
  57. static void _server_thread_poll(void *data);
  58. public:
  59. EditorHTTPServer();
  60. ~EditorHTTPServer();
  61. void stop();
  62. Error listen(int p_port, IPAddress p_address, bool p_use_tls, String p_tls_key, String p_tls_cert);
  63. bool is_listening() const;
  64. };
  65. #endif // WEB_EDITOR_HTTP_SERVER_H