summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp14
-rw-r--r--core/core_bind.h3
-rw-r--r--core/crypto/crypto.cpp18
-rw-r--r--core/crypto/crypto.h20
-rw-r--r--core/object/object.cpp41
-rw-r--r--core/object/script_language_extension.h2
-rw-r--r--core/register_core_types.cpp2
-rw-r--r--core/string/translation_po.cpp90
-rw-r--r--core/string/translation_po.h14
9 files changed, 121 insertions, 83 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index e8a6a5075b..a1b7b81111 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -194,6 +194,18 @@ void ResourceSaver::_bind_methods() {
////// OS //////
+PackedByteArray OS::get_entropy(int p_bytes) {
+ PackedByteArray pba;
+ pba.resize(p_bytes);
+ Error err = ::OS::get_singleton()->get_entropy(pba.ptrw(), p_bytes);
+ ERR_FAIL_COND_V(err != OK, PackedByteArray());
+ return pba;
+}
+
+String OS::get_system_ca_certificates() {
+ return ::OS::get_singleton()->get_system_ca_certificates();
+}
+
PackedStringArray OS::get_connected_midi_inputs() {
return ::OS::get_singleton()->get_connected_midi_inputs();
}
@@ -573,6 +585,8 @@ String OS::get_unique_id() const {
OS *OS::singleton = nullptr;
void OS::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_entropy", "size"), &OS::get_entropy);
+ ClassDB::bind_method(D_METHOD("get_system_ca_certificates"), &OS::get_system_ca_certificates);
ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &OS::get_connected_midi_inputs);
ClassDB::bind_method(D_METHOD("open_midi_inputs"), &OS::open_midi_inputs);
ClassDB::bind_method(D_METHOD("close_midi_inputs"), &OS::close_midi_inputs);
diff --git a/core/core_bind.h b/core/core_bind.h
index febc33a9c1..b142a2fbbd 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -134,6 +134,9 @@ public:
RENDERING_DRIVER_D3D12,
};
+ PackedByteArray get_entropy(int p_bytes);
+ String get_system_ca_certificates();
+
virtual PackedStringArray get_connected_midi_inputs();
virtual void open_midi_inputs();
virtual void close_midi_inputs();
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp
index 7fef819159..d3d0079410 100644
--- a/core/crypto/crypto.cpp
+++ b/core/crypto/crypto.cpp
@@ -72,31 +72,26 @@ void X509Certificate::_bind_methods() {
Ref<TLSOptions> TLSOptions::client(Ref<X509Certificate> p_trusted_chain, const String &p_common_name_override) {
Ref<TLSOptions> opts;
opts.instantiate();
+ opts->mode = MODE_CLIENT;
opts->trusted_ca_chain = p_trusted_chain;
opts->common_name = p_common_name_override;
- opts->verify_mode = TLS_VERIFY_FULL;
return opts;
}
Ref<TLSOptions> TLSOptions::client_unsafe(Ref<X509Certificate> p_trusted_chain) {
Ref<TLSOptions> opts;
opts.instantiate();
+ opts->mode = MODE_CLIENT_UNSAFE;
opts->trusted_ca_chain = p_trusted_chain;
- if (p_trusted_chain.is_null()) {
- opts->verify_mode = TLS_VERIFY_NONE;
- } else {
- opts->verify_mode = TLS_VERIFY_CERT;
- }
return opts;
}
Ref<TLSOptions> TLSOptions::server(Ref<CryptoKey> p_own_key, Ref<X509Certificate> p_own_certificate) {
Ref<TLSOptions> opts;
opts.instantiate();
- opts->server_mode = true;
+ opts->mode = MODE_SERVER;
opts->own_certificate = p_own_certificate;
opts->private_key = p_own_key;
- opts->verify_mode = TLS_VERIFY_NONE;
return opts;
}
@@ -104,6 +99,13 @@ void TLSOptions::_bind_methods() {
ClassDB::bind_static_method("TLSOptions", D_METHOD("client", "trusted_chain", "common_name_override"), &TLSOptions::client, DEFVAL(Ref<X509Certificate>()), DEFVAL(String()));
ClassDB::bind_static_method("TLSOptions", D_METHOD("client_unsafe", "trusted_chain"), &TLSOptions::client_unsafe, DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_static_method("TLSOptions", D_METHOD("server", "key", "certificate"), &TLSOptions::server);
+
+ ClassDB::bind_method(D_METHOD("is_server"), &TLSOptions::is_server);
+ ClassDB::bind_method(D_METHOD("is_unsafe_client"), &TLSOptions::is_unsafe_client);
+ ClassDB::bind_method(D_METHOD("get_common_name_override"), &TLSOptions::get_common_name_override);
+ ClassDB::bind_method(D_METHOD("get_trusted_ca_chain"), &TLSOptions::get_trusted_ca_chain);
+ ClassDB::bind_method(D_METHOD("get_private_key"), &TLSOptions::get_private_key);
+ ClassDB::bind_method(D_METHOD("get_own_certificate"), &TLSOptions::get_own_certificate);
}
/// HMACContext
diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h
index fbd01be86d..16649422cf 100644
--- a/core/crypto/crypto.h
+++ b/core/crypto/crypto.h
@@ -72,17 +72,15 @@ public:
class TLSOptions : public RefCounted {
GDCLASS(TLSOptions, RefCounted);
-public:
- enum TLSVerifyMode {
- TLS_VERIFY_NONE = 0,
- TLS_VERIFY_CERT = 1,
- TLS_VERIFY_FULL = 2,
+private:
+ enum Mode {
+ MODE_CLIENT = 0,
+ MODE_CLIENT_UNSAFE = 1,
+ MODE_SERVER = 2,
};
-private:
- bool server_mode = false;
+ Mode mode = MODE_CLIENT;
String common_name;
- TLSVerifyMode verify_mode = TLS_VERIFY_FULL;
Ref<X509Certificate> trusted_ca_chain;
Ref<X509Certificate> own_certificate;
Ref<CryptoKey> private_key;
@@ -95,12 +93,12 @@ public:
static Ref<TLSOptions> client_unsafe(Ref<X509Certificate> p_trusted_chain);
static Ref<TLSOptions> server(Ref<CryptoKey> p_own_key, Ref<X509Certificate> p_own_certificate);
- TLSVerifyMode get_verify_mode() const { return verify_mode; }
- String get_common_name() const { return common_name; }
+ String get_common_name_override() const { return common_name; }
Ref<X509Certificate> get_trusted_ca_chain() const { return trusted_ca_chain; }
Ref<X509Certificate> get_own_certificate() const { return own_certificate; }
Ref<CryptoKey> get_private_key() const { return private_key; }
- bool is_server() const { return server_mode; }
+ bool is_server() const { return mode == MODE_SERVER; }
+ bool is_unsafe_client() const { return mode == MODE_CLIENT_UNSAFE; }
};
class HMACContext : public RefCounted {
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 0383753f38..97a3a405b9 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -236,20 +236,12 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
}
if (_extension && _extension->set) {
-// C style pointer casts should never trigger a compiler warning because the risk is assumed by the user, so GCC should keep quiet about it.
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wignored-qualifiers"
-#endif
- if (_extension->set(_extension_instance, (const GDExtensionStringNamePtr)&p_name, (const GDExtensionVariantPtr)&p_value)) {
+ if (_extension->set(_extension_instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value)) {
if (r_valid) {
*r_valid = true;
}
return;
}
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
}
// Try built-in setter.
@@ -323,21 +315,12 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
}
}
if (_extension && _extension->get) {
-// C style pointer casts should never trigger a compiler warning because the risk is assumed by the user, so GCC should keep quiet about it.
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wignored-qualifiers"
-#endif
-
- if (_extension->get(_extension_instance, (const GDExtensionStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret)) {
+ if (_extension->get(_extension_instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret)) {
if (r_valid) {
*r_valid = true;
}
return ret;
}
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
}
// Try built-in getter.
@@ -575,19 +558,11 @@ bool Object::property_can_revert(const StringName &p_name) const {
}
}
-// C style pointer casts should never trigger a compiler warning because the risk is assumed by the user, so GCC should keep quiet about it.
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wignored-qualifiers"
-#endif
if (_extension && _extension->property_can_revert) {
- if (_extension->property_can_revert(_extension_instance, (const GDExtensionStringNamePtr)&p_name)) {
+ if (_extension->property_can_revert(_extension_instance, (GDExtensionConstStringNamePtr)&p_name)) {
return true;
}
}
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
return _property_can_revertv(p_name);
}
@@ -601,19 +576,11 @@ Variant Object::property_get_revert(const StringName &p_name) const {
}
}
-// C style pointer casts should never trigger a compiler warning because the risk is assumed by the user, so GCC should keep quiet about it.
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wignored-qualifiers"
-#endif
if (_extension && _extension->property_get_revert) {
- if (_extension->property_get_revert(_extension_instance, (const GDExtensionStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret)) {
+ if (_extension->property_get_revert(_extension_instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret)) {
return ret;
}
}
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
if (_property_get_revertv(p_name, ret)) {
return ret;
diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h
index 8fd26c3d2c..c9344f5799 100644
--- a/core/object/script_language_extension.h
+++ b/core/object/script_language_extension.h
@@ -646,7 +646,7 @@ public:
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override {
int ret = 0;
- GDVIRTUAL_REQUIRED_CALL(_profiling_get_accumulated_data, p_info_arr, p_info_max, ret);
+ GDVIRTUAL_REQUIRED_CALL(_profiling_get_frame_data, p_info_arr, p_info_max, ret);
return ret;
}
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 8a55e4de8f..c0a86e9fb7 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -444,8 +444,8 @@ void unregister_core_types() {
unregister_global_constants();
- ClassDB::cleanup();
ResourceCache::clear();
+ ClassDB::cleanup();
CoreStringNames::free();
StringName::cleanup();
diff --git a/core/string/translation_po.cpp b/core/string/translation_po.cpp
index 06fd4717d7..8e275505b0 100644
--- a/core/string/translation_po.cpp
+++ b/core/string/translation_po.cpp
@@ -140,43 +140,87 @@ int TranslationPO::_get_plural_index(int p_n) const {
input_val.clear();
input_val.push_back(p_n);
- Variant result;
- for (int i = 0; i < equi_tests.size(); i++) {
- Error err = expr->parse(equi_tests[i], input_name);
- ERR_FAIL_COND_V_MSG(err != OK, 0, "Cannot parse expression. Error: " + expr->get_error_text());
+ return _eq_test(equi_tests, 0);
+}
- result = expr->execute(input_val);
- ERR_FAIL_COND_V_MSG(expr->has_execute_failed(), 0, "Cannot evaluate expression.");
+int TranslationPO::_eq_test(const Ref<EQNode> &p_node, const Variant &p_result) const {
+ if (p_node.is_valid()) {
+ Error err = expr->parse(p_node->regex, input_name);
+ ERR_FAIL_COND_V_MSG(err != OK, 0, vformat("Cannot parse expression \"%s\". Error: %s", p_node->regex, expr->get_error_text()));
- // Last expression. Variant result will either map to a bool or an integer, in both cases returning it will give the correct plural index.
- if (i + 1 == equi_tests.size()) {
- return result;
- }
+ Variant result = expr->execute(input_val);
+ ERR_FAIL_COND_V_MSG(expr->has_execute_failed(), 0, vformat("Cannot evaluate expression \"%s\".", p_node->regex));
if (bool(result)) {
- return i;
+ return _eq_test(p_node->left, result);
+ } else {
+ return _eq_test(p_node->right, result);
}
+ } else {
+ return p_result;
+ }
+}
+
+int TranslationPO::_find_unquoted(const String &p_src, char32_t p_chr) const {
+ const int len = p_src.length();
+ if (len == 0) {
+ return -1;
}
- ERR_FAIL_V_MSG(0, "Unexpected. Function should have returned. Please report this bug.");
+ const char32_t *src = p_src.get_data();
+ bool in_quote = false;
+ for (int i = 0; i < len; i++) {
+ if (in_quote) {
+ if (src[i] == ')') {
+ in_quote = false;
+ }
+ } else {
+ if (src[i] == '(') {
+ in_quote = true;
+ } else if (src[i] == p_chr) {
+ return i;
+ }
+ }
+ }
+
+ return -1;
}
-void TranslationPO::_cache_plural_tests(const String &p_plural_rule) {
+void TranslationPO::_cache_plural_tests(const String &p_plural_rule, Ref<EQNode> &p_node) {
// Some examples of p_plural_rule passed in can have the form:
// "n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5" (Arabic)
// "n >= 2" (French) // When evaluating the last, especially careful with this one.
// "n != 1" (English)
- int first_ques_mark = p_plural_rule.find("?");
+
+ String rule = p_plural_rule;
+ if (rule.begins_with("(") && rule.ends_with(")")) {
+ int bcount = 0;
+ for (int i = 1; i < rule.length() - 1 && bcount >= 0; i++) {
+ if (rule[i] == '(') {
+ bcount++;
+ } else if (rule[i] == ')') {
+ bcount--;
+ }
+ }
+ if (bcount == 0) {
+ rule = rule.substr(1, rule.length() - 2);
+ }
+ }
+
+ int first_ques_mark = _find_unquoted(rule, '?');
+ int first_colon = _find_unquoted(rule, ':');
+
if (first_ques_mark == -1) {
- equi_tests.push_back(p_plural_rule.strip_edges());
+ p_node->regex = rule.strip_edges();
return;
}
- String equi_test = p_plural_rule.substr(0, first_ques_mark).strip_edges();
- equi_tests.push_back(equi_test);
+ p_node->regex = rule.substr(0, first_ques_mark).strip_edges();
- String after_colon = p_plural_rule.substr(p_plural_rule.find(":") + 1, p_plural_rule.length());
- _cache_plural_tests(after_colon);
+ p_node->left.instantiate();
+ _cache_plural_tests(rule.substr(first_ques_mark + 1, first_colon - first_ques_mark - 1).strip_edges(), p_node->left);
+ p_node->right.instantiate();
+ _cache_plural_tests(rule.substr(first_colon + 1).strip_edges(), p_node->right);
}
void TranslationPO::set_plural_rule(const String &p_plural_rule) {
@@ -188,12 +232,12 @@ void TranslationPO::set_plural_rule(const String &p_plural_rule) {
int expression_start = p_plural_rule.find("=", first_semi_col) + 1;
int second_semi_col = p_plural_rule.rfind(";");
- plural_rule = p_plural_rule.substr(expression_start, second_semi_col - expression_start);
+ plural_rule = p_plural_rule.substr(expression_start, second_semi_col - expression_start).strip_edges();
// Setup the cache to make evaluating plural rule faster later on.
- plural_rule = plural_rule.replacen("(", "");
- plural_rule = plural_rule.replacen(")", "");
- _cache_plural_tests(plural_rule);
+ equi_tests.instantiate();
+ _cache_plural_tests(plural_rule, equi_tests);
+
expr.instantiate();
input_name.push_back("n");
}
diff --git a/core/string/translation_po.h b/core/string/translation_po.h
index 73f9b33a87..ba820c6ee4 100644
--- a/core/string/translation_po.h
+++ b/core/string/translation_po.h
@@ -50,7 +50,17 @@ class TranslationPO : public Translation {
String plural_rule;
// Cache temporary variables related to _get_plural_index() to make it faster
- Vector<String> equi_tests;
+ class EQNode : public RefCounted {
+ public:
+ String regex;
+ Ref<EQNode> left;
+ Ref<EQNode> right;
+ };
+ Ref<EQNode> equi_tests;
+
+ int _find_unquoted(const String &p_src, char32_t p_chr) const;
+ int _eq_test(const Ref<EQNode> &p_node, const Variant &p_result) const;
+
Vector<String> input_name;
mutable Ref<Expression> expr;
mutable Array input_val;
@@ -59,7 +69,7 @@ class TranslationPO : public Translation {
mutable int last_plural_n = -1; // Set it to an impossible value at the beginning.
mutable int last_plural_mapped_index = 0;
- void _cache_plural_tests(const String &p_plural_rule);
+ void _cache_plural_tests(const String &p_plural_rule, Ref<EQNode> &p_node);
int _get_plural_index(int p_n) const;
Vector<String> _get_message_list() const override;