|
1 | | -/* auto-generated on 2024-01-22 09:15:53 -0500. Do not edit! */ |
| 1 | +/* auto-generated on 2024-01-29 13:13:24 -0500. Do not edit! */ |
2 | 2 | /* begin file src/ada.cpp */ |
3 | 3 | #include "ada.h" |
4 | 4 | /* begin file src/checkers.cpp */ |
@@ -11221,7 +11221,7 @@ ada_warn_unused std::string to_string(ada::state state) { |
11221 | 11221 | namespace ada { |
11222 | 11222 |
|
11223 | 11223 | bool url::parse_opaque_host(std::string_view input) { |
11224 | | - ada_log("parse_opaque_host ", input, "[", input.size(), " bytes]"); |
| 11224 | + ada_log("parse_opaque_host ", input, " [", input.size(), " bytes]"); |
11225 | 11225 | if (std::any_of(input.begin(), input.end(), |
11226 | 11226 | ada::unicode::is_forbidden_host_code_point)) { |
11227 | 11227 | return is_valid = false; |
@@ -11235,7 +11235,7 @@ bool url::parse_opaque_host(std::string_view input) { |
11235 | 11235 | } |
11236 | 11236 |
|
11237 | 11237 | bool url::parse_ipv4(std::string_view input) { |
11238 | | - ada_log("parse_ipv4 ", input, "[", input.size(), " bytes]"); |
| 11238 | + ada_log("parse_ipv4 ", input, " [", input.size(), " bytes]"); |
11239 | 11239 | if (input.back() == '.') { |
11240 | 11240 | input.remove_suffix(1); |
11241 | 11241 | } |
@@ -11310,7 +11310,7 @@ bool url::parse_ipv4(std::string_view input) { |
11310 | 11310 | } |
11311 | 11311 |
|
11312 | 11312 | bool url::parse_ipv6(std::string_view input) { |
11313 | | - ada_log("parse_ipv6 ", input, "[", input.size(), " bytes]"); |
| 11313 | + ada_log("parse_ipv6 ", input, " [", input.size(), " bytes]"); |
11314 | 11314 |
|
11315 | 11315 | if (input.empty()) { |
11316 | 11316 | return is_valid = false; |
@@ -11634,7 +11634,7 @@ ada_really_inline bool url::parse_scheme(const std::string_view input) { |
11634 | 11634 | } |
11635 | 11635 |
|
11636 | 11636 | ada_really_inline bool url::parse_host(std::string_view input) { |
11637 | | - ada_log("parse_host ", input, "[", input.size(), " bytes]"); |
| 11637 | + ada_log("parse_host ", input, " [", input.size(), " bytes]"); |
11638 | 11638 | if (input.empty()) { |
11639 | 11639 | return is_valid = false; |
11640 | 11640 | } // technically unnecessary. |
@@ -11686,6 +11686,8 @@ ada_really_inline bool url::parse_host(std::string_view input) { |
11686 | 11686 | ada_log("parse_host to_ascii returns false"); |
11687 | 11687 | return is_valid = false; |
11688 | 11688 | } |
| 11689 | + ada_log("parse_host to_ascii succeeded ", *host, " [", host->size(), |
| 11690 | + " bytes]"); |
11689 | 11691 |
|
11690 | 11692 | if (std::any_of(host.value().begin(), host.value().end(), |
11691 | 11693 | ada::unicode::is_forbidden_domain_code_point)) { |
@@ -11696,7 +11698,7 @@ ada_really_inline bool url::parse_host(std::string_view input) { |
11696 | 11698 | // If asciiDomain ends in a number, then return the result of IPv4 parsing |
11697 | 11699 | // asciiDomain. |
11698 | 11700 | if (checkers::is_ipv4(host.value())) { |
11699 | | - ada_log("parse_host got ipv4", *host); |
| 11701 | + ada_log("parse_host got ipv4 ", *host); |
11700 | 11702 | return parse_ipv4(host.value()); |
11701 | 11703 | } |
11702 | 11704 |
|
@@ -13571,7 +13573,7 @@ void url_aggregator::set_hash(const std::string_view input) { |
13571 | 13573 |
|
13572 | 13574 | bool url_aggregator::set_href(const std::string_view input) { |
13573 | 13575 | ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer)); |
13574 | | - ada_log("url_aggregator::set_href ", input, "[", input.size(), " bytes]"); |
| 13576 | + ada_log("url_aggregator::set_href ", input, " [", input.size(), " bytes]"); |
13575 | 13577 | ada::result<url_aggregator> out = ada::parse<url_aggregator>(input); |
13576 | 13578 | ada_log("url_aggregator::set_href, success :", out.has_value()); |
13577 | 13579 |
|
@@ -13585,7 +13587,8 @@ bool url_aggregator::set_href(const std::string_view input) { |
13585 | 13587 | } |
13586 | 13588 |
|
13587 | 13589 | ada_really_inline bool url_aggregator::parse_host(std::string_view input) { |
13588 | | - ada_log("url_aggregator:parse_host ", input, "[", input.size(), " bytes]"); |
| 13590 | + ada_log("url_aggregator:parse_host \"", input, "\" [", input.size(), |
| 13591 | + " bytes]"); |
13589 | 13592 | ADA_ASSERT_TRUE(validate()); |
13590 | 13593 | ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer)); |
13591 | 13594 | if (input.empty()) { |
@@ -13635,7 +13638,7 @@ ada_really_inline bool url_aggregator::parse_host(std::string_view input) { |
13635 | 13638 | update_base_hostname(input); |
13636 | 13639 | if (checkers::is_ipv4(get_hostname())) { |
13637 | 13640 | ada_log("parse_host fast path ipv4"); |
13638 | | - return parse_ipv4(get_hostname()); |
| 13641 | + return parse_ipv4(get_hostname(), true); |
13639 | 13642 | } |
13640 | 13643 | ada_log("parse_host fast path ", get_hostname()); |
13641 | 13644 | return true; |
@@ -13651,6 +13654,8 @@ ada_really_inline bool url_aggregator::parse_host(std::string_view input) { |
13651 | 13654 | ada_log("parse_host to_ascii returns false"); |
13652 | 13655 | return is_valid = false; |
13653 | 13656 | } |
| 13657 | + ada_log("parse_host to_ascii succeeded ", *host, " [", host->size(), |
| 13658 | + " bytes]"); |
13654 | 13659 |
|
13655 | 13660 | if (std::any_of(host.value().begin(), host.value().end(), |
13656 | 13661 | ada::unicode::is_forbidden_domain_code_point)) { |
@@ -13660,8 +13665,8 @@ ada_really_inline bool url_aggregator::parse_host(std::string_view input) { |
13660 | 13665 | // If asciiDomain ends in a number, then return the result of IPv4 parsing |
13661 | 13666 | // asciiDomain. |
13662 | 13667 | if (checkers::is_ipv4(host.value())) { |
13663 | | - ada_log("parse_host got ipv4", *host); |
13664 | | - return parse_ipv4(host.value()); |
| 13668 | + ada_log("parse_host got ipv4 ", *host); |
| 13669 | + return parse_ipv4(host.value(), false); |
13665 | 13670 | } |
13666 | 13671 |
|
13667 | 13672 | update_base_hostname(host.value()); |
@@ -13914,7 +13919,7 @@ bool url_aggregator::set_hostname(const std::string_view input) { |
13914 | 13919 | } |
13915 | 13920 |
|
13916 | 13921 | [[nodiscard]] std::string ada::url_aggregator::to_string() const { |
13917 | | - ada_log("url_aggregator::to_string buffer:", buffer, "[", buffer.size(), |
| 13922 | + ada_log("url_aggregator::to_string buffer:", buffer, " [", buffer.size(), |
13918 | 13923 | " bytes]"); |
13919 | 13924 | if (!is_valid) { |
13920 | 13925 | return "null"; |
@@ -14013,8 +14018,8 @@ bool url_aggregator::set_hostname(const std::string_view input) { |
14013 | 14018 | return checkers::verify_dns_length(get_hostname()); |
14014 | 14019 | } |
14015 | 14020 |
|
14016 | | -bool url_aggregator::parse_ipv4(std::string_view input) { |
14017 | | - ada_log("parse_ipv4 ", input, "[", input.size(), |
| 14021 | +bool url_aggregator::parse_ipv4(std::string_view input, bool in_place) { |
| 14022 | + ada_log("parse_ipv4 ", input, " [", input.size(), |
14018 | 14023 | " bytes], overlaps with buffer: ", |
14019 | 14024 | helpers::overlaps(input, buffer) ? "yes" : "no"); |
14020 | 14025 | ADA_ASSERT_TRUE(validate()); |
@@ -14038,20 +14043,25 @@ bool url_aggregator::parse_ipv4(std::string_view input) { |
14038 | 14043 | } else { |
14039 | 14044 | std::from_chars_result r; |
14040 | 14045 | if (is_hex) { |
| 14046 | + ada_log("parse_ipv4 trying to parse hex number"); |
14041 | 14047 | r = std::from_chars(input.data() + 2, input.data() + input.size(), |
14042 | 14048 | segment_result, 16); |
14043 | 14049 | } else if ((input.length() >= 2) && input[0] == '0' && |
14044 | 14050 | checkers::is_digit(input[1])) { |
| 14051 | + ada_log("parse_ipv4 trying to parse octal number"); |
14045 | 14052 | r = std::from_chars(input.data() + 1, input.data() + input.size(), |
14046 | 14053 | segment_result, 8); |
14047 | 14054 | } else { |
| 14055 | + ada_log("parse_ipv4 trying to parse decimal number"); |
14048 | 14056 | pure_decimal_count++; |
14049 | 14057 | r = std::from_chars(input.data(), input.data() + input.size(), |
14050 | 14058 | segment_result, 10); |
14051 | 14059 | } |
14052 | 14060 | if (r.ec != std::errc()) { |
| 14061 | + ada_log("parse_ipv4 parsing failed"); |
14053 | 14062 | return is_valid = false; |
14054 | 14063 | } |
| 14064 | + ada_log("parse_ipv4 parsed ", segment_result); |
14055 | 14065 | input.remove_prefix(r.ptr - input.data()); |
14056 | 14066 | } |
14057 | 14067 | if (input.empty()) { |
@@ -14076,17 +14086,22 @@ bool url_aggregator::parse_ipv4(std::string_view input) { |
14076 | 14086 | } |
14077 | 14087 | } |
14078 | 14088 | if ((digit_count != 4) || (!input.empty())) { |
| 14089 | + ada_log("parse_ipv4 found invalid (more than 4 numbers or empty) "); |
14079 | 14090 | return is_valid = false; |
14080 | 14091 | } |
14081 | 14092 | final: |
14082 | 14093 | ada_log("url_aggregator::parse_ipv4 completed ", get_href(), |
14083 | 14094 | " host: ", get_host()); |
14084 | 14095 |
|
14085 | 14096 | // We could also check r.ptr to see where the parsing ended. |
14086 | | - if (pure_decimal_count == 4 && !trailing_dot) { |
| 14097 | + if (in_place && pure_decimal_count == 4 && !trailing_dot) { |
| 14098 | + ada_log( |
| 14099 | + "url_aggregator::parse_ipv4 completed and was already correct in the " |
| 14100 | + "buffer"); |
14087 | 14101 | // The original input was already all decimal and we validated it. So we |
14088 | 14102 | // don't need to do anything. |
14089 | 14103 | } else { |
| 14104 | + ada_log("url_aggregator::parse_ipv4 completed and we need to update it"); |
14090 | 14105 | // Optimization opportunity: Get rid of unnecessary string return in ipv4 |
14091 | 14106 | // serializer. |
14092 | 14107 | // TODO: This is likely a bug because it goes back update_base_hostname, not |
@@ -14100,8 +14115,11 @@ bool url_aggregator::parse_ipv4(std::string_view input) { |
14100 | 14115 | } |
14101 | 14116 |
|
14102 | 14117 | bool url_aggregator::parse_ipv6(std::string_view input) { |
| 14118 | + // TODO: Implement in_place optimization: we know that input points |
| 14119 | + // in the buffer, so we can just check whether the buffer is already |
| 14120 | + // well formatted. |
14103 | 14121 | // TODO: Find a way to merge parse_ipv6 with url.cpp implementation. |
14104 | | - ada_log("parse_ipv6 ", input, "[", input.size(), " bytes]"); |
| 14122 | + ada_log("parse_ipv6 ", input, " [", input.size(), " bytes]"); |
14105 | 14123 | ADA_ASSERT_TRUE(validate()); |
14106 | 14124 | ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer)); |
14107 | 14125 | if (input.empty()) { |
@@ -14335,7 +14353,7 @@ bool url_aggregator::parse_ipv6(std::string_view input) { |
14335 | 14353 | } |
14336 | 14354 |
|
14337 | 14355 | bool url_aggregator::parse_opaque_host(std::string_view input) { |
14338 | | - ada_log("parse_opaque_host ", input, "[", input.size(), " bytes]"); |
| 14356 | + ada_log("parse_opaque_host ", input, " [", input.size(), " bytes]"); |
14339 | 14357 | ADA_ASSERT_TRUE(validate()); |
14340 | 14358 | ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer)); |
14341 | 14359 | if (std::any_of(input.begin(), input.end(), |
|