diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/http_client.cpp | 11 | ||||
-rw-r--r-- | core/io/http_client.h | 4 | ||||
-rw-r--r-- | core/io/http_client_tcp.cpp | 93 | ||||
-rw-r--r-- | core/io/http_client_tcp.h | 11 | ||||
-rw-r--r-- | core/math/bvh_split.inc | 4 | ||||
-rw-r--r-- | core/math/convex_hull.cpp | 14 | ||||
-rw-r--r-- | core/math/vector2.h | 16 | ||||
-rw-r--r-- | core/math/vector3.h | 8 | ||||
-rw-r--r-- | core/math/vector3i.cpp | 8 | ||||
-rw-r--r-- | core/math/vector3i.h | 4 | ||||
-rw-r--r-- | core/variant/binder_common.h | 3 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 12 | ||||
-rw-r--r-- | core/variant/variant_internal.h | 10 |
13 files changed, 159 insertions, 39 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 800ac779e5..5c67bc4c48 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -49,6 +49,14 @@ HTTPClient *HTTPClient::create() { return nullptr; } +void HTTPClient::set_http_proxy(const String &p_host, int p_port) { + WARN_PRINT("HTTP proxy feature is not available"); +} + +void HTTPClient::set_https_proxy(const String &p_host, int p_port) { + WARN_PRINT("HTTPS proxy feature is not available"); +} + Error HTTPClient::_request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) { int size = p_body.size(); return request(p_method, p_url, p_headers, size > 0 ? p_body.ptr() : nullptr, size); @@ -142,6 +150,9 @@ void HTTPClient::_bind_methods() { ClassDB::bind_method(D_METHOD("get_status"), &HTTPClient::get_status); ClassDB::bind_method(D_METHOD("poll"), &HTTPClient::poll); + ClassDB::bind_method(D_METHOD("set_http_proxy", "host", "port"), &HTTPClient::set_http_proxy); + ClassDB::bind_method(D_METHOD("set_https_proxy", "host", "port"), &HTTPClient::set_https_proxy); + ClassDB::bind_method(D_METHOD("query_string_from_dict", "fields"), &HTTPClient::query_string_from_dict); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_mode_enabled"), "set_blocking_mode", "is_blocking_mode_enabled"); diff --git a/core/io/http_client.h b/core/io/http_client.h index 718c3a905e..9bc0134a6a 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -192,6 +192,10 @@ public: virtual Error poll() = 0; + // Use empty string or -1 to unset + virtual void set_http_proxy(const String &p_host, int p_port); + virtual void set_https_proxy(const String &p_host, int p_port); + HTTPClient() {} virtual ~HTTPClient() {} }; diff --git a/core/io/http_client_tcp.cpp b/core/io/http_client_tcp.cpp index b3d35b3603..f2ddeddbb8 100644 --- a/core/io/http_client_tcp.cpp +++ b/core/io/http_client_tcp.cpp @@ -70,9 +70,21 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, bool p_ss connection = tcp_connection; - if (conn_host.is_valid_ip_address()) { + if (ssl && https_proxy_port != -1) { + proxy_client.instantiate(); // Needs proxy negotiation + server_host = https_proxy_host; + server_port = https_proxy_port; + } else if (!ssl && http_proxy_port != -1) { + server_host = http_proxy_host; + server_port = http_proxy_port; + } else { + server_host = conn_host; + server_port = conn_port; + } + + if (server_host.is_valid_ip_address()) { // Host contains valid IP - Error err = tcp_connection->connect_to_host(IPAddress(conn_host), p_port); + Error err = tcp_connection->connect_to_host(IPAddress(server_host), server_port); if (err) { status = STATUS_CANT_CONNECT; return err; @@ -81,7 +93,7 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, bool p_ss status = STATUS_CONNECTING; } else { // Host contains hostname and needs to be resolved to IP - resolving = IP::get_singleton()->resolve_hostname_queue_item(conn_host); + resolving = IP::get_singleton()->resolve_hostname_queue_item(server_host); status = STATUS_RESOLVING; } @@ -134,7 +146,12 @@ Error HTTPClientTCP::request(Method p_method, const String &p_url, const Vector< ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA); - String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n"; + String uri = p_url; + if (!ssl && http_proxy_port != -1) { + uri = vformat("http://%s:%d%s", conn_host, conn_port, p_url); + } + + String request = String(_methods[p_method]) + " " + uri + " HTTP/1.1\r\n"; bool add_host = true; bool add_clen = p_body_size > 0; bool add_uagent = true; @@ -229,6 +246,7 @@ void HTTPClientTCP::close() { } connection.unref(); + proxy_client.unref(); status = STATUS_DISCONNECTED; head_request = false; if (resolving != IP::RESOLVER_INVALID_ID) { @@ -265,7 +283,7 @@ Error HTTPClientTCP::poll() { Error err = ERR_BUG; // Should be at least one entry. while (ip_candidates.size() > 0) { - err = tcp_connection->connect_to_host(ip_candidates.front(), conn_port); + err = tcp_connection->connect_to_host(ip_candidates.pop_front(), server_port); if (err == OK) { break; } @@ -294,7 +312,48 @@ Error HTTPClientTCP::poll() { return OK; } break; case StreamPeerTCP::STATUS_CONNECTED: { - if (ssl) { + if (ssl && proxy_client.is_valid()) { + Error err = proxy_client->poll(); + if (err == ERR_UNCONFIGURED) { + proxy_client->set_connection(tcp_connection); + const Vector<String> headers; + err = proxy_client->request(METHOD_CONNECT, vformat("%s:%d", conn_host, conn_port), headers, nullptr, 0); + if (err != OK) { + status = STATUS_CANT_CONNECT; + return err; + } + } else if (err != OK) { + status = STATUS_CANT_CONNECT; + return err; + } + switch (proxy_client->get_status()) { + case STATUS_REQUESTING: { + return OK; + } break; + case STATUS_BODY: { + proxy_client->read_response_body_chunk(); + return OK; + } break; + case STATUS_CONNECTED: { + if (proxy_client->get_response_code() != RESPONSE_OK) { + status = STATUS_CANT_CONNECT; + return ERR_CANT_CONNECT; + } + proxy_client.unref(); + return OK; + } + case STATUS_DISCONNECTED: + case STATUS_RESOLVING: + case STATUS_CONNECTING: { + status = STATUS_CANT_CONNECT; + ERR_FAIL_V(ERR_BUG); + } break; + default: { + status = STATUS_CANT_CONNECT; + return ERR_CANT_CONNECT; + } break; + } + } else if (ssl) { Ref<StreamPeerSSL> ssl; if (!handshaking) { // Connect the StreamPeerSSL and start handshaking @@ -344,7 +403,7 @@ Error HTTPClientTCP::poll() { Error err = ERR_CANT_CONNECT; while (ip_candidates.size() > 0) { tcp_connection->disconnect_from_host(); - err = tcp_connection->connect_to_host(ip_candidates.pop_front(), conn_port); + err = tcp_connection->connect_to_host(ip_candidates.pop_front(), server_port); if (err == OK) { return OK; } @@ -678,6 +737,26 @@ int HTTPClientTCP::get_read_chunk_size() const { return read_chunk_size; } +void HTTPClientTCP::set_http_proxy(const String &p_host, int p_port) { + if (p_host.is_empty() || p_port == -1) { + http_proxy_host = ""; + http_proxy_port = -1; + } else { + http_proxy_host = p_host; + http_proxy_port = p_port; + } +} + +void HTTPClientTCP::set_https_proxy(const String &p_host, int p_port) { + if (p_host.is_empty() || p_port == -1) { + https_proxy_host = ""; + https_proxy_port = -1; + } else { + https_proxy_host = p_host; + https_proxy_port = p_port; + } +} + HTTPClientTCP::HTTPClientTCP() { tcp_connection.instantiate(); } diff --git a/core/io/http_client_tcp.h b/core/io/http_client_tcp.h index 170afb551c..40a962925e 100644 --- a/core/io/http_client_tcp.h +++ b/core/io/http_client_tcp.h @@ -38,8 +38,14 @@ private: Status status = STATUS_DISCONNECTED; IP::ResolverID resolving = IP::RESOLVER_INVALID_ID; Array ip_candidates; - int conn_port = -1; + int conn_port = -1; // Server to make requests to String conn_host; + int server_port = -1; // Server to connect to (might be a proxy server) + String server_host; + int http_proxy_port = -1; // Proxy server for http requests + String http_proxy_host; + int https_proxy_port = -1; // Proxy server for https requests + String https_proxy_host; bool ssl = false; bool ssl_verify_host = false; bool blocking = false; @@ -58,6 +64,7 @@ private: Ref<StreamPeerTCP> tcp_connection; Ref<StreamPeer> connection; + Ref<HTTPClientTCP> proxy_client; // Negotiate with proxy server int response_num = 0; Vector<String> response_headers; @@ -87,6 +94,8 @@ public: void set_read_chunk_size(int p_size) override; int get_read_chunk_size() const override; Error poll() override; + void set_http_proxy(const String &p_host, int p_port) override; + void set_https_proxy(const String &p_host, int p_port) override; HTTPClientTCP(); }; diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc index 6f54d06ce7..f19ee8a7da 100644 --- a/core/math/bvh_split.inc +++ b/core/math/bvh_split.inc @@ -30,8 +30,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u int order[Point::AXIS_COUNT]; - order[0] = size.min_axis(); - order[Point::AXIS_COUNT - 1] = size.max_axis(); + order[0] = size.min_axis_index(); + order[Point::AXIS_COUNT - 1] = size.max_axis_index(); static_assert(Point::AXIS_COUNT <= 3); if (Point::AXIS_COUNT == 3) { diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp index 2956e0cf09..6f551319df 100644 --- a/core/math/convex_hull.cpp +++ b/core/math/convex_hull.cpp @@ -606,9 +606,9 @@ private: PagedAllocator<Face> face_pool; LocalVector<Vertex *> original_vertices; int32_t merge_stamp = 0; - int32_t min_axis = 0; - int32_t med_axis = 0; - int32_t max_axis = 0; + Vector3::Axis min_axis = Vector3::Axis::AXIS_X; + Vector3::Axis med_axis = Vector3::Axis::AXIS_X; + Vector3::Axis max_axis = Vector3::Axis::AXIS_X; int32_t used_edge_pairs = 0; int32_t max_used_edge_pairs = 0; @@ -1585,12 +1585,12 @@ void ConvexHullInternal::compute(const Vector3 *p_coords, int32_t p_count) { } Vector3 s = aabb.size; - max_axis = s.max_axis(); - min_axis = s.min_axis(); + max_axis = s.max_axis_index(); + min_axis = s.min_axis_index(); if (min_axis == max_axis) { - min_axis = (max_axis + 1) % 3; + min_axis = Vector3::Axis((max_axis + 1) % 3); } - med_axis = 3 - max_axis - min_axis; + med_axis = Vector3::Axis(3 - max_axis - min_axis); s /= real_t(10216); if (((med_axis + 1) % 3) != max_axis) { diff --git a/core/math/vector2.h b/core/math/vector2.h index 0a7b9d3faf..c0a189e040 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -70,12 +70,12 @@ struct Vector2 { x = y = p_value; } - _FORCE_INLINE_ int min_axis() const { - return x < y ? 0 : 1; + _FORCE_INLINE_ Vector2::Axis min_axis_index() const { + return x < y ? Vector2::AXIS_X : Vector2::AXIS_Y; } - _FORCE_INLINE_ int max_axis() const { - return x < y ? 1 : 0; + _FORCE_INLINE_ Vector2::Axis max_axis_index() const { + return x < y ? Vector2::AXIS_Y : Vector2::AXIS_X; } void normalize(); @@ -301,12 +301,12 @@ struct Vector2i { return p_idx ? y : x; } - _FORCE_INLINE_ int min_axis() const { - return x < y ? 0 : 1; + _FORCE_INLINE_ Vector2i::Axis min_axis_index() const { + return x < y ? Vector2i::AXIS_X : Vector2i::AXIS_Y; } - _FORCE_INLINE_ int max_axis() const { - return x < y ? 1 : 0; + _FORCE_INLINE_ Vector2i::Axis max_axis_index() const { + return x < y ? Vector2i::AXIS_Y : Vector2i::AXIS_X; } Vector2i min(const Vector2i &p_vector2i) const { diff --git a/core/math/vector3.h b/core/math/vector3.h index 6c21968aae..c0f80e8f11 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -71,12 +71,12 @@ struct Vector3 { x = y = z = p_value; } - _FORCE_INLINE_ int min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); + _FORCE_INLINE_ Vector3::Axis min_axis_index() const { + return x < y ? (x < z ? Vector3::AXIS_X : Vector3::AXIS_Z) : (y < z ? Vector3::AXIS_Y : Vector3::AXIS_Z); } - _FORCE_INLINE_ int max_axis() const { - return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); + _FORCE_INLINE_ Vector3::Axis max_axis_index() const { + return x < y ? (y < z ? Vector3::AXIS_Z : Vector3::AXIS_Y) : (x < z ? Vector3::AXIS_Z : Vector3::AXIS_X); } _FORCE_INLINE_ real_t length() const; diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp index d3a57af77c..7812a0b41c 100644 --- a/core/math/vector3i.cpp +++ b/core/math/vector3i.cpp @@ -40,12 +40,12 @@ int32_t Vector3i::get_axis(const int p_axis) const { return operator[](p_axis); } -int Vector3i::min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); +Vector3i::Axis Vector3i::min_axis_index() const { + return x < y ? (x < z ? Vector3i::AXIS_X : Vector3i::AXIS_Z) : (y < z ? Vector3i::AXIS_Y : Vector3i::AXIS_Z); } -int Vector3i::max_axis() const { - return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); +Vector3i::Axis Vector3i::max_axis_index() const { + return x < y ? (y < z ? Vector3i::AXIS_Z : Vector3i::AXIS_Y) : (x < z ? Vector3i::AXIS_Z : Vector3i::AXIS_X); } Vector3i Vector3i::clamp(const Vector3i &p_min, const Vector3i &p_max) const { diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 10c28a5bb9..fba29a1f8d 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -62,8 +62,8 @@ struct Vector3i { void set_axis(const int p_axis, const int32_t p_value); int32_t get_axis(const int p_axis) const; - int min_axis() const; - int max_axis() const; + Vector3i::Axis min_axis_index() const; + Vector3i::Axis max_axis_index() const; _FORCE_INLINE_ void zero(); diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index 98be62391f..3f9f7e02b2 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -87,7 +87,10 @@ struct VariantCaster<const T &> { // Object enum casts must go here VARIANT_ENUM_CAST(Object::ConnectFlags); +VARIANT_ENUM_CAST(Vector2::Axis); +VARIANT_ENUM_CAST(Vector2i::Axis); VARIANT_ENUM_CAST(Vector3::Axis); +VARIANT_ENUM_CAST(Vector3i::Axis); VARIANT_ENUM_CAST(Basis::EulerOrder); VARIANT_ENUM_CAST(Error); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index b586757dcd..75f986bdf5 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1486,6 +1486,8 @@ static void _register_variant_builtin_methods() { bind_method(Vector2, lerp, sarray("to", "weight"), varray()); bind_method(Vector2, slerp, sarray("to", "weight"), varray()); bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray()); + bind_method(Vector2, max_axis_index, sarray(), varray()); + bind_method(Vector2, min_axis_index, sarray(), varray()); bind_method(Vector2, move_toward, sarray("to", "delta"), varray()); bind_method(Vector2, rotated, sarray("phi"), varray()); bind_method(Vector2, orthogonal, sarray(), varray()); @@ -1508,6 +1510,8 @@ static void _register_variant_builtin_methods() { /* Vector2i */ bind_method(Vector2i, aspect, sarray(), varray()); + bind_method(Vector2i, max_axis_index, sarray(), varray()); + bind_method(Vector2i, min_axis_index, sarray(), varray()); bind_method(Vector2i, sign, sarray(), varray()); bind_method(Vector2i, abs, sarray(), varray()); bind_method(Vector2i, clamp, sarray("min", "max"), varray()); @@ -1547,8 +1551,8 @@ static void _register_variant_builtin_methods() { /* Vector3 */ - bind_method(Vector3, min_axis, sarray(), varray()); - bind_method(Vector3, max_axis, sarray(), varray()); + bind_method(Vector3, min_axis_index, sarray(), varray()); + bind_method(Vector3, max_axis_index, sarray(), varray()); bind_method(Vector3, angle_to, sarray("to"), varray()); bind_method(Vector3, signed_angle_to, sarray("to", "axis"), varray()); bind_method(Vector3, direction_to, sarray("to"), varray()); @@ -1587,8 +1591,8 @@ static void _register_variant_builtin_methods() { /* Vector3i */ - bind_method(Vector3i, min_axis, sarray(), varray()); - bind_method(Vector3i, max_axis, sarray(), varray()); + bind_method(Vector3i, min_axis_index, sarray(), varray()); + bind_method(Vector3i, max_axis_index, sarray(), varray()); bind_method(Vector3i, sign, sarray(), varray()); bind_method(Vector3i, abs, sarray(), varray()); bind_method(Vector3i, clamp, sarray("min", "max"), varray()); diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 2ba24b5af8..d24f3e90f5 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -753,8 +753,14 @@ VARIANT_ACCESSOR_NUMBER(uint32_t) VARIANT_ACCESSOR_NUMBER(int64_t) VARIANT_ACCESSOR_NUMBER(uint64_t) VARIANT_ACCESSOR_NUMBER(char32_t) + +// Bind enums to allow using them as return types. VARIANT_ACCESSOR_NUMBER(Error) VARIANT_ACCESSOR_NUMBER(Side) +VARIANT_ACCESSOR_NUMBER(Vector2::Axis) +VARIANT_ACCESSOR_NUMBER(Vector2i::Axis) +VARIANT_ACCESSOR_NUMBER(Vector3::Axis) +VARIANT_ACCESSOR_NUMBER(Vector3i::Axis) template <> struct VariantInternalAccessor<Basis::EulerOrder> { @@ -1020,6 +1026,10 @@ INITIALIZER_INT(int64_t) INITIALIZER_INT(char32_t) INITIALIZER_INT(Error) INITIALIZER_INT(ObjectID) +INITIALIZER_INT(Vector2::Axis) +INITIALIZER_INT(Vector2i::Axis) +INITIALIZER_INT(Vector3::Axis) +INITIALIZER_INT(Vector3i::Axis) template <> struct VariantInitializer<double> { |