@@ -411,7 +411,7 @@ void url_aggregator::set_hash(const std::string_view input) {
411
411
412
412
bool url_aggregator::set_href (const std::string_view input) {
413
413
ADA_ASSERT_TRUE (!helpers::overlaps (input, buffer));
414
- ada_log (" url_aggregator::set_href " , input, " [" , input.size (), " bytes]" );
414
+ ada_log (" url_aggregator::set_href " , input, " [" , input.size (), " bytes]" );
415
415
ada::result<url_aggregator> out = ada::parse<url_aggregator>(input);
416
416
ada_log (" url_aggregator::set_href, success :" , out.has_value ());
417
417
@@ -425,7 +425,8 @@ bool url_aggregator::set_href(const std::string_view input) {
425
425
}
426
426
427
427
ada_really_inline bool url_aggregator::parse_host (std::string_view input) {
428
- ada_log (" url_aggregator:parse_host " , input, " [" , input.size (), " bytes]" );
428
+ ada_log (" url_aggregator:parse_host \" " , input, " \" [" , input.size (),
429
+ " bytes]" );
429
430
ADA_ASSERT_TRUE (validate ());
430
431
ADA_ASSERT_TRUE (!helpers::overlaps (input, buffer));
431
432
if (input.empty ()) {
@@ -475,7 +476,7 @@ ada_really_inline bool url_aggregator::parse_host(std::string_view input) {
475
476
update_base_hostname (input);
476
477
if (checkers::is_ipv4 (get_hostname ())) {
477
478
ada_log (" parse_host fast path ipv4" );
478
- return parse_ipv4 (get_hostname ());
479
+ return parse_ipv4 (get_hostname (), true );
479
480
}
480
481
ada_log (" parse_host fast path " , get_hostname ());
481
482
return true ;
@@ -491,6 +492,8 @@ ada_really_inline bool url_aggregator::parse_host(std::string_view input) {
491
492
ada_log (" parse_host to_ascii returns false" );
492
493
return is_valid = false ;
493
494
}
495
+ ada_log (" parse_host to_ascii succeeded " , *host, " [" , host->size (),
496
+ " bytes]" );
494
497
495
498
if (std::any_of (host.value ().begin (), host.value ().end (),
496
499
ada::unicode::is_forbidden_domain_code_point)) {
@@ -500,8 +503,8 @@ ada_really_inline bool url_aggregator::parse_host(std::string_view input) {
500
503
// If asciiDomain ends in a number, then return the result of IPv4 parsing
501
504
// asciiDomain.
502
505
if (checkers::is_ipv4 (host.value ())) {
503
- ada_log (" parse_host got ipv4" , *host);
504
- return parse_ipv4 (host.value ());
506
+ ada_log (" parse_host got ipv4 " , *host);
507
+ return parse_ipv4 (host.value (), false );
505
508
}
506
509
507
510
update_base_hostname (host.value ());
@@ -754,7 +757,7 @@ bool url_aggregator::set_hostname(const std::string_view input) {
754
757
}
755
758
756
759
[[nodiscard]] std::string ada::url_aggregator::to_string () const {
757
- ada_log (" url_aggregator::to_string buffer:" , buffer, " [" , buffer.size (),
760
+ ada_log (" url_aggregator::to_string buffer:" , buffer, " [" , buffer.size (),
758
761
" bytes]" );
759
762
if (!is_valid) {
760
763
return " null" ;
@@ -853,8 +856,8 @@ bool url_aggregator::set_hostname(const std::string_view input) {
853
856
return checkers::verify_dns_length (get_hostname ());
854
857
}
855
858
856
- bool url_aggregator::parse_ipv4 (std::string_view input) {
857
- ada_log (" parse_ipv4 " , input, " [" , input.size (),
859
+ bool url_aggregator::parse_ipv4 (std::string_view input, bool in_place ) {
860
+ ada_log (" parse_ipv4 " , input, " [" , input.size (),
858
861
" bytes], overlaps with buffer: " ,
859
862
helpers::overlaps (input, buffer) ? " yes" : " no" );
860
863
ADA_ASSERT_TRUE (validate ());
@@ -878,20 +881,25 @@ bool url_aggregator::parse_ipv4(std::string_view input) {
878
881
} else {
879
882
std::from_chars_result r;
880
883
if (is_hex) {
884
+ ada_log (" parse_ipv4 trying to parse hex number" );
881
885
r = std::from_chars (input.data () + 2 , input.data () + input.size (),
882
886
segment_result, 16 );
883
887
} else if ((input.length () >= 2 ) && input[0 ] == ' 0' &&
884
888
checkers::is_digit (input[1 ])) {
889
+ ada_log (" parse_ipv4 trying to parse octal number" );
885
890
r = std::from_chars (input.data () + 1 , input.data () + input.size (),
886
891
segment_result, 8 );
887
892
} else {
893
+ ada_log (" parse_ipv4 trying to parse decimal number" );
888
894
pure_decimal_count++;
889
895
r = std::from_chars (input.data (), input.data () + input.size (),
890
896
segment_result, 10 );
891
897
}
892
898
if (r.ec != std::errc ()) {
899
+ ada_log (" parse_ipv4 parsing failed" );
893
900
return is_valid = false ;
894
901
}
902
+ ada_log (" parse_ipv4 parsed " , segment_result);
895
903
input.remove_prefix (r.ptr - input.data ());
896
904
}
897
905
if (input.empty ()) {
@@ -916,17 +924,22 @@ bool url_aggregator::parse_ipv4(std::string_view input) {
916
924
}
917
925
}
918
926
if ((digit_count != 4 ) || (!input.empty ())) {
927
+ ada_log (" parse_ipv4 found invalid (more than 4 numbers or empty) " );
919
928
return is_valid = false ;
920
929
}
921
930
final :
922
931
ada_log (" url_aggregator::parse_ipv4 completed " , get_href (),
923
932
" host: " , get_host ());
924
933
925
934
// We could also check r.ptr to see where the parsing ended.
926
- if (pure_decimal_count == 4 && !trailing_dot) {
935
+ if (in_place && pure_decimal_count == 4 && !trailing_dot) {
936
+ ada_log (
937
+ " url_aggregator::parse_ipv4 completed and was already correct in the "
938
+ " buffer" );
927
939
// The original input was already all decimal and we validated it. So we
928
940
// don't need to do anything.
929
941
} else {
942
+ ada_log (" url_aggregator::parse_ipv4 completed and we need to update it" );
930
943
// Optimization opportunity: Get rid of unnecessary string return in ipv4
931
944
// serializer.
932
945
// TODO: This is likely a bug because it goes back update_base_hostname, not
@@ -940,8 +953,11 @@ bool url_aggregator::parse_ipv4(std::string_view input) {
940
953
}
941
954
942
955
bool url_aggregator::parse_ipv6 (std::string_view input) {
956
+ // TODO: Implement in_place optimization: we know that input points
957
+ // in the buffer, so we can just check whether the buffer is already
958
+ // well formatted.
943
959
// TODO: Find a way to merge parse_ipv6 with url.cpp implementation.
944
- ada_log (" parse_ipv6 " , input, " [" , input.size (), " bytes]" );
960
+ ada_log (" parse_ipv6 " , input, " [" , input.size (), " bytes]" );
945
961
ADA_ASSERT_TRUE (validate ());
946
962
ADA_ASSERT_TRUE (!helpers::overlaps (input, buffer));
947
963
if (input.empty ()) {
@@ -1175,7 +1191,7 @@ bool url_aggregator::parse_ipv6(std::string_view input) {
1175
1191
}
1176
1192
1177
1193
bool url_aggregator::parse_opaque_host (std::string_view input) {
1178
- ada_log (" parse_opaque_host " , input, " [" , input.size (), " bytes]" );
1194
+ ada_log (" parse_opaque_host " , input, " [" , input.size (), " bytes]" );
1179
1195
ADA_ASSERT_TRUE (validate ());
1180
1196
ADA_ASSERT_TRUE (!helpers::overlaps (input, buffer));
1181
1197
if (std::any_of (input.begin (), input.end (),
0 commit comments