grpc 1.33.0.pre1 → 1.34.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +342 -134
- data/include/grpc/grpc.h +1 -2
- data/include/grpc/grpc_security.h +149 -172
- data/include/grpc/impl/codegen/grpc_types.h +9 -2
- data/include/grpc/impl/codegen/port_platform.h +22 -55
- data/src/core/ext/filters/client_channel/client_channel.cc +11 -34
- data/src/core/ext/filters/client_channel/config_selector.h +2 -3
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +4 -1
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +5 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +80 -71
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +3 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +47 -17
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -5
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +16 -243
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +53 -17
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +809 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +20 -25
- data/src/core/ext/filters/client_channel/resolver.cc +3 -1
- data/src/core/ext/filters/client_channel/resolver.h +4 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +20 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +66 -7
- data/src/core/ext/filters/client_channel/resolver_registry.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +13 -25
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +2 -2
- data/src/core/ext/filters/client_channel/retry_throttle.h +1 -1
- data/src/core/ext/filters/client_channel/server_address.h +0 -4
- data/src/core/ext/filters/client_channel/service_config.cc +3 -1
- data/src/core/ext/filters/client_channel/service_config.h +1 -1
- data/src/core/ext/filters/client_channel/subchannel.cc +18 -15
- data/src/core/ext/filters/client_channel/subchannel.h +2 -2
- data/src/core/ext/filters/client_channel/subchannel_interface.h +7 -15
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +6 -2
- data/src/core/ext/filters/deadline/deadline_filter.cc +83 -77
- data/src/core/ext/filters/deadline/deadline_filter.h +7 -11
- data/src/core/ext/filters/http/client/http_client_filter.cc +1 -1
- data/src/core/ext/filters/http/server/http_server_filter.cc +3 -3
- data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +17 -3
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +7 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +4 -24
- data/src/core/ext/transport/chttp2/transport/flow_control.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +12 -8
- data/src/core/ext/transport/chttp2/transport/internal.h +0 -1
- data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/writing.cc +1 -2
- data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +38 -0
- data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.c +41 -0
- data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +254 -0
- data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +105 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +100 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +558 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +145 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.c +53 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +133 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.c +127 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.h +65 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +266 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +125 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +143 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c +66 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +263 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.h +100 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +233 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.h +70 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +228 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +80 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c +46 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.c +59 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c +110 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.h +50 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +113 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +50 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.c +146 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.c +50 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +190 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +185 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.h +65 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +62 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +97 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +915 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +280 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.c +71 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c +64 -0
- data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +511 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +115 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +48 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +166 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +105 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +249 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +60 -0
- data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.c +72 -0
- data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.c +60 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c +152 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.h +60 -0
- data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c +83 -0
- data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c +82 -0
- data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c +83 -0
- data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c +86 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.c +74 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c +64 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.c +54 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.c +53 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +73 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c +72 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.c +81 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.c +92 -0
- data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.h +65 -0
- data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.c +95 -0
- data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.c +34 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.c +59 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.c +54 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.c +47 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.c +40 -0
- data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.c +61 -0
- data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.c +38 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c +386 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.h +165 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.c +39 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.c +37 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.c +65 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.h +50 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.c +39 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.c +66 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.h +75 -0
- data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +42 -0
- data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c +70 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c +33 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c +49 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c +43 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.c +42 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.c +62 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.c +45 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.c +49 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.c +68 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.c +51 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +307 -0
- data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.h +145 -0
- data/src/core/ext/xds/certificate_provider_factory.h +7 -5
- data/src/core/ext/xds/certificate_provider_store.cc +84 -0
- data/src/core/ext/xds/certificate_provider_store.h +65 -8
- data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +119 -0
- data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +72 -0
- data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +28 -140
- data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +6 -4
- data/src/core/ext/xds/xds_api.cc +241 -718
- data/src/core/ext/xds/xds_api.h +50 -9
- data/src/core/ext/xds/xds_bootstrap.cc +172 -25
- data/src/core/ext/xds/xds_bootstrap.h +23 -7
- data/src/core/ext/xds/xds_certificate_provider.cc +240 -0
- data/src/core/ext/xds/xds_certificate_provider.h +74 -0
- data/src/core/ext/xds/xds_client.cc +161 -128
- data/src/core/ext/xds/xds_client.h +12 -11
- data/src/core/ext/xds/xds_client_stats.cc +41 -4
- data/src/core/ext/xds/xds_client_stats.h +2 -2
- data/src/core/lib/channel/channel_args.cc +2 -1
- data/src/core/lib/channel/channel_trace.cc +4 -2
- data/src/core/lib/channel/channelz.h +2 -2
- data/src/core/lib/channel/handshaker.h +2 -2
- data/src/core/lib/compression/compression.cc +8 -4
- data/src/core/lib/compression/compression_internal.cc +10 -5
- data/src/core/lib/compression/compression_internal.h +2 -1
- data/src/core/lib/compression/stream_compression_identity.cc +1 -3
- data/src/core/lib/debug/stats_data.cc +1 -0
- data/src/core/lib/gpr/cpu_iphone.cc +10 -2
- data/src/core/lib/gpr/log_linux.cc +17 -3
- data/src/core/lib/gpr/log_posix.cc +13 -1
- data/src/core/lib/gpr/log_windows.cc +16 -4
- data/src/core/lib/gpr/murmur_hash.cc +1 -1
- data/src/core/lib/gpr/string.cc +1 -1
- data/src/core/lib/gpr/time_precise.cc +3 -2
- data/src/core/lib/gpr/tls.h +4 -0
- data/src/core/lib/gpr/tls_msvc.h +2 -0
- data/src/core/lib/gpr/tls_stdcpp.h +48 -0
- data/src/core/lib/gpr/useful.h +5 -4
- data/src/core/lib/gprpp/dual_ref_counted.h +44 -49
- data/src/core/lib/gprpp/examine_stack.cc +43 -0
- data/src/core/lib/gprpp/examine_stack.h +46 -0
- data/src/core/lib/gprpp/fork.cc +2 -2
- data/src/core/lib/gprpp/manual_constructor.h +1 -1
- data/src/core/lib/gprpp/orphanable.h +4 -8
- data/src/core/lib/gprpp/ref_counted.h +40 -46
- data/src/core/lib/gprpp/ref_counted_ptr.h +9 -11
- data/src/core/lib/{security/authorization/mock_cel/statusor.h → gprpp/stat.h} +13 -25
- data/src/core/lib/gprpp/stat_posix.cc +49 -0
- data/src/core/lib/gprpp/stat_windows.cc +48 -0
- data/src/core/lib/gprpp/thd.h +2 -2
- data/src/core/lib/gprpp/thd_posix.cc +36 -36
- data/src/core/lib/http/parser.cc +46 -25
- data/src/core/lib/iomgr/error.cc +2 -1
- data/src/core/lib/iomgr/ev_epollex_linux.cc +8 -4
- data/src/core/lib/iomgr/exec_ctx.cc +1 -1
- data/src/core/lib/iomgr/executor/mpmcqueue.h +5 -5
- data/src/core/lib/iomgr/executor/threadpool.h +3 -3
- data/src/core/lib/iomgr/parse_address.cc +84 -6
- data/src/core/lib/iomgr/parse_address.h +20 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +2 -1
- data/src/core/lib/iomgr/python_util.h +3 -3
- data/src/core/lib/iomgr/resolve_address_posix.cc +1 -5
- data/src/core/lib/iomgr/tcp_posix.cc +3 -2
- data/src/core/lib/iomgr/timer_custom.cc +2 -2
- data/src/core/lib/iomgr/unix_sockets_posix.cc +27 -15
- data/src/core/lib/iomgr/unix_sockets_posix.h +5 -0
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +7 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -2
- data/src/core/lib/json/json.h +2 -2
- data/src/core/lib/json/json_reader.cc +8 -4
- data/src/core/lib/json/json_util.h +167 -0
- data/src/core/lib/json/json_writer.cc +2 -1
- data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +3 -1
- data/src/core/lib/security/authorization/mock_cel/cel_expression.h +5 -4
- data/src/core/lib/security/authorization/mock_cel/cel_value.h +4 -0
- data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +6 -6
- data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +10 -9
- data/src/core/lib/security/context/security_context.h +3 -1
- data/src/core/lib/security/credentials/credentials.cc +1 -1
- data/src/core/lib/security/credentials/credentials.h +3 -3
- data/src/core/lib/security/credentials/external/aws_request_signer.cc +208 -0
- data/src/core/lib/security/credentials/external/aws_request_signer.h +73 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.cc +311 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.h +118 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +136 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.h +49 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +211 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.h +59 -0
- data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +51 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +5 -2
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +4 -3
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +5 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +35 -5
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +12 -8
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +78 -0
- data/src/core/lib/security/{certificate_provider.h → credentials/tls/grpc_tls_certificate_provider.h} +32 -18
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +77 -149
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +58 -187
- data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -12
- data/src/core/lib/security/credentials/tls/tls_credentials.h +2 -2
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +2 -2
- data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +88 -0
- data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +70 -0
- data/src/core/lib/security/security_connector/load_system_roots.h +4 -0
- data/src/core/lib/security/security_connector/load_system_roots_linux.h +2 -0
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +2 -2
- data/src/core/lib/security/security_connector/security_connector.cc +1 -1
- data/src/core/lib/security/security_connector/security_connector.h +4 -2
- data/src/core/lib/security/security_connector/ssl_utils.h +4 -2
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +293 -275
- data/src/core/lib/security/security_connector/tls/tls_security_connector.h +106 -61
- data/src/core/lib/security/transport/security_handshaker.cc +1 -1
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -1
- data/src/core/lib/security/util/json_util.h +1 -0
- data/src/core/lib/slice/slice.cc +7 -4
- data/src/core/lib/slice/slice_buffer.cc +2 -1
- data/src/core/lib/slice/slice_intern.cc +2 -2
- data/src/core/lib/surface/call.cc +9 -8
- data/src/core/lib/surface/completion_queue.cc +7 -6
- data/src/core/lib/surface/server.cc +4 -2
- data/src/core/lib/surface/server.h +2 -2
- data/src/core/lib/surface/validate_metadata.h +3 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/authority_override.h +2 -0
- data/src/core/lib/transport/bdp_estimator.cc +1 -1
- data/src/core/lib/transport/byte_stream.h +3 -3
- data/src/core/lib/transport/connectivity_state.h +3 -3
- data/src/core/lib/transport/metadata.h +2 -2
- data/src/core/lib/transport/timeout_encoding.cc +4 -4
- data/src/core/lib/transport/transport.cc +5 -3
- data/src/core/lib/transport/transport.h +1 -1
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -4
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +4 -3
- data/src/core/tsi/fake_transport_security.cc +1 -0
- data/src/core/tsi/local_transport_security.cc +5 -1
- data/src/core/tsi/local_transport_security.h +6 -7
- data/src/core/tsi/ssl/session_cache/ssl_session.h +3 -0
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -1
- data/src/core/tsi/ssl_transport_security.cc +14 -7
- data/src/core/tsi/ssl_transport_security.h +3 -0
- data/src/core/tsi/transport_security.cc +4 -2
- data/src/ruby/ext/grpc/extconf.rb +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +22 -14
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -24
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/abseil-cpp/absl/algorithm/container.h +59 -22
- data/third_party/abseil-cpp/absl/base/attributes.h +99 -38
- data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
- data/third_party/abseil-cpp/absl/base/casts.h +9 -6
- data/third_party/abseil-cpp/absl/base/config.h +60 -17
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +428 -335
- data/third_party/abseil-cpp/absl/base/internal/bits.h +17 -16
- data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +5 -0
- data/third_party/abseil-cpp/absl/base/internal/dynamic_annotations.h +398 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +4 -4
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +1 -1
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +29 -1
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +2 -2
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +7 -5
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +25 -38
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +19 -25
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +8 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +28 -5
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +8 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +3 -1
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +2 -2
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +3 -3
- data/third_party/abseil-cpp/absl/base/macros.h +36 -109
- data/third_party/abseil-cpp/absl/base/optimization.h +61 -1
- data/third_party/abseil-cpp/absl/base/options.h +31 -4
- data/third_party/abseil-cpp/absl/base/policy_checks.h +1 -1
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +94 -39
- data/third_party/abseil-cpp/absl/container/fixed_array.h +42 -25
- data/third_party/abseil-cpp/absl/container/flat_hash_set.h +2 -1
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +33 -36
- data/third_party/abseil-cpp/absl/container/internal/common.h +6 -2
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +33 -8
- data/third_party/abseil-cpp/absl/container/internal/container_memory.h +49 -29
- data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +15 -0
- data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +24 -7
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -1
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +35 -11
- data/third_party/abseil-cpp/absl/container/internal/have_sse.h +10 -9
- data/third_party/abseil-cpp/absl/container/internal/layout.h +7 -5
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +55 -34
- data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +5 -4
- data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +66 -16
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +4 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +13 -4
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +43 -24
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +12 -3
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +10 -2
- data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +22 -1
- data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +0 -21
- data/third_party/abseil-cpp/absl/debugging/symbolize.cc +12 -1
- data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +101 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +100 -20
- data/third_party/abseil-cpp/absl/functional/bind_front.h +184 -0
- data/third_party/abseil-cpp/absl/functional/function_ref.h +1 -1
- data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +95 -0
- data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +2 -2
- data/third_party/abseil-cpp/absl/hash/hash.h +6 -5
- data/third_party/abseil-cpp/absl/hash/internal/hash.h +73 -65
- data/third_party/abseil-cpp/absl/memory/memory.h +4 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +2 -8
- data/third_party/abseil-cpp/absl/numeric/int128.cc +13 -27
- data/third_party/abseil-cpp/absl/numeric/int128.h +16 -15
- data/third_party/abseil-cpp/absl/status/internal/status_internal.h +51 -0
- data/third_party/abseil-cpp/absl/status/status.cc +4 -6
- data/third_party/abseil-cpp/absl/status/status.h +502 -113
- data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +5 -10
- data/third_party/abseil-cpp/absl/strings/charconv.cc +2 -2
- data/third_party/abseil-cpp/absl/strings/cord.cc +91 -112
- data/third_party/abseil-cpp/absl/strings/cord.h +360 -205
- data/third_party/abseil-cpp/absl/strings/escaping.cc +9 -9
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +45 -23
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +222 -136
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +136 -64
- data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +14 -21
- data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +7 -14
- data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.cc +31 -7
- data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +147 -135
- data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +999 -87
- data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +3 -3
- data/third_party/abseil-cpp/absl/strings/internal/str_format/output.h +4 -12
- data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +8 -6
- data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +13 -11
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +2 -2
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +4 -4
- data/third_party/abseil-cpp/absl/strings/str_cat.h +1 -1
- data/third_party/abseil-cpp/absl/strings/str_format.h +289 -13
- data/third_party/abseil-cpp/absl/strings/str_split.cc +2 -2
- data/third_party/abseil-cpp/absl/strings/str_split.h +1 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +26 -19
- data/third_party/abseil-cpp/absl/strings/substitute.cc +5 -5
- data/third_party/abseil-cpp/absl/strings/substitute.h +32 -29
- data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +3 -3
- data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +3 -3
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +28 -28
- data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +4 -16
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +1 -1
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +8 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -2
- data/third_party/abseil-cpp/absl/synchronization/mutex.cc +75 -64
- data/third_party/abseil-cpp/absl/synchronization/mutex.h +15 -6
- data/third_party/abseil-cpp/absl/time/civil_time.cc +9 -9
- data/third_party/abseil-cpp/absl/time/clock.cc +3 -3
- data/third_party/abseil-cpp/absl/time/duration.cc +90 -59
- data/third_party/abseil-cpp/absl/time/format.cc +43 -36
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +26 -16
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +4 -2
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +136 -29
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +13 -21
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +136 -129
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +4 -5
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +8 -7
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +6 -6
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +2 -1
- data/third_party/abseil-cpp/absl/time/time.h +15 -16
- data/third_party/abseil-cpp/absl/types/internal/variant.h +4 -4
- data/third_party/abseil-cpp/absl/types/optional.h +9 -9
- data/third_party/abseil-cpp/absl/types/span.h +49 -36
- data/third_party/abseil-cpp/absl/utility/utility.h +2 -2
- data/third_party/address_sorting/include/address_sorting/address_sorting.h +2 -0
- data/third_party/boringssl-with-bazel/err_data.c +340 -336
- data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +2 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +173 -35
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +46 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +8 -2
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +90 -63
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +60 -60
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +179 -47
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +766 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +10 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_data.c +5 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +14 -14
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +24 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +7 -5
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +5 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/des.h +6 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +3 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +202 -134
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +55 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +31 -23
- data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +435 -394
- data/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc +18 -5
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +35 -0
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +36 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +42 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +67 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +11 -14
- data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +216 -11
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +53 -11
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +133 -39
- data/third_party/upb/upb/def.c +2169 -0
- data/third_party/upb/upb/def.h +330 -0
- data/third_party/upb/upb/def.hpp +525 -0
- data/third_party/upb/upb/reflection.c +391 -0
- data/third_party/upb/upb/reflection.h +168 -0
- data/third_party/upb/upb/text_encode.c +398 -0
- data/third_party/upb/upb/text_encode.h +35 -0
- metadata +227 -37
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +0 -571
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +0 -129
@@ -44,6 +44,7 @@ enum client_hs_state_t {
|
|
44
44
|
state_server_certificate_reverify,
|
45
45
|
state_read_server_finished,
|
46
46
|
state_send_end_of_early_data,
|
47
|
+
state_send_client_encrypted_extensions,
|
47
48
|
state_send_client_certificate,
|
48
49
|
state_send_client_certificate_verify,
|
49
50
|
state_complete_second_flight,
|
@@ -487,12 +488,6 @@ static enum ssl_hs_wait_t do_read_encrypted_extensions(SSL_HANDSHAKE *hs) {
|
|
487
488
|
return ssl_hs_error;
|
488
489
|
}
|
489
490
|
|
490
|
-
// Store the negotiated ALPN in the session.
|
491
|
-
if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
|
492
|
-
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
493
|
-
return ssl_hs_error;
|
494
|
-
}
|
495
|
-
|
496
491
|
if (ssl->s3->early_data_accepted) {
|
497
492
|
if (hs->early_session->cipher != hs->new_session->cipher) {
|
498
493
|
OPENSSL_PUT_ERROR(SSL, SSL_R_CIPHER_MISMATCH_ON_EARLY_DATA);
|
@@ -505,11 +500,29 @@ static enum ssl_hs_wait_t do_read_encrypted_extensions(SSL_HANDSHAKE *hs) {
|
|
505
500
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
506
501
|
return ssl_hs_error;
|
507
502
|
}
|
508
|
-
|
503
|
+
// Channel ID and Token Binding are incompatible with 0-RTT. The ALPS
|
504
|
+
// extension should be negotiated implicitly.
|
505
|
+
if (ssl->s3->channel_id_valid || ssl->s3->token_binding_negotiated ||
|
506
|
+
hs->new_session->has_application_settings) {
|
509
507
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION_ON_EARLY_DATA);
|
510
508
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
511
509
|
return ssl_hs_error;
|
512
510
|
}
|
511
|
+
hs->new_session->has_application_settings =
|
512
|
+
hs->early_session->has_application_settings;
|
513
|
+
if (!hs->new_session->local_application_settings.CopyFrom(
|
514
|
+
hs->early_session->local_application_settings) ||
|
515
|
+
!hs->new_session->peer_application_settings.CopyFrom(
|
516
|
+
hs->early_session->peer_application_settings)) {
|
517
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
518
|
+
return ssl_hs_error;
|
519
|
+
}
|
520
|
+
}
|
521
|
+
|
522
|
+
// Store the negotiated ALPN in the session.
|
523
|
+
if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
|
524
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
525
|
+
return ssl_hs_error;
|
513
526
|
}
|
514
527
|
|
515
528
|
if (!ssl_hash_message(hs, msg)) {
|
@@ -626,8 +639,7 @@ static enum ssl_hs_wait_t do_read_server_certificate(SSL_HANDSHAKE *hs) {
|
|
626
639
|
return ssl_hs_ok;
|
627
640
|
}
|
628
641
|
|
629
|
-
static enum ssl_hs_wait_t do_read_server_certificate_verify(
|
630
|
-
SSL_HANDSHAKE *hs) {
|
642
|
+
static enum ssl_hs_wait_t do_read_server_certificate_verify(SSL_HANDSHAKE *hs) {
|
631
643
|
SSL *const ssl = hs->ssl;
|
632
644
|
SSLMessage msg;
|
633
645
|
if (!ssl->method->get_message(ssl, &msg)) {
|
@@ -654,8 +666,7 @@ static enum ssl_hs_wait_t do_read_server_certificate_verify(
|
|
654
666
|
return ssl_hs_ok;
|
655
667
|
}
|
656
668
|
|
657
|
-
static enum ssl_hs_wait_t do_server_certificate_reverify(
|
658
|
-
SSL_HANDSHAKE *hs) {
|
669
|
+
static enum ssl_hs_wait_t do_server_certificate_reverify(SSL_HANDSHAKE *hs) {
|
659
670
|
switch (ssl_reverify_peer_cert(hs, /*send_alert=*/true)) {
|
660
671
|
case ssl_verify_ok:
|
661
672
|
break;
|
@@ -718,6 +729,32 @@ static enum ssl_hs_wait_t do_send_end_of_early_data(SSL_HANDSHAKE *hs) {
|
|
718
729
|
}
|
719
730
|
}
|
720
731
|
|
732
|
+
hs->tls13_state = state_send_client_encrypted_extensions;
|
733
|
+
return ssl_hs_ok;
|
734
|
+
}
|
735
|
+
|
736
|
+
static enum ssl_hs_wait_t do_send_client_encrypted_extensions(
|
737
|
+
SSL_HANDSHAKE *hs) {
|
738
|
+
SSL *const ssl = hs->ssl;
|
739
|
+
// For now, only one extension uses client EncryptedExtensions. This function
|
740
|
+
// may be generalized if others use it in the future.
|
741
|
+
if (hs->new_session->has_application_settings &&
|
742
|
+
!ssl->s3->early_data_accepted) {
|
743
|
+
ScopedCBB cbb;
|
744
|
+
CBB body, extensions, extension;
|
745
|
+
if (!ssl->method->init_message(ssl, cbb.get(), &body,
|
746
|
+
SSL3_MT_ENCRYPTED_EXTENSIONS) ||
|
747
|
+
!CBB_add_u16_length_prefixed(&body, &extensions) ||
|
748
|
+
!CBB_add_u16(&extensions, TLSEXT_TYPE_application_settings) ||
|
749
|
+
!CBB_add_u16_length_prefixed(&extensions, &extension) ||
|
750
|
+
!CBB_add_bytes(&extension,
|
751
|
+
hs->new_session->local_application_settings.data(),
|
752
|
+
hs->new_session->local_application_settings.size()) ||
|
753
|
+
!ssl_add_message_cbb(ssl, cbb.get())) {
|
754
|
+
return ssl_hs_error;
|
755
|
+
}
|
756
|
+
}
|
757
|
+
|
721
758
|
hs->tls13_state = state_send_client_certificate;
|
722
759
|
return ssl_hs_ok;
|
723
760
|
}
|
@@ -860,6 +897,9 @@ enum ssl_hs_wait_t tls13_client_handshake(SSL_HANDSHAKE *hs) {
|
|
860
897
|
case state_send_client_certificate:
|
861
898
|
ret = do_send_client_certificate(hs);
|
862
899
|
break;
|
900
|
+
case state_send_client_encrypted_extensions:
|
901
|
+
ret = do_send_client_encrypted_extensions(hs);
|
902
|
+
break;
|
863
903
|
case state_send_client_certificate_verify:
|
864
904
|
ret = do_send_client_certificate_verify(hs);
|
865
905
|
break;
|
@@ -907,6 +947,8 @@ const char *tls13_client_handshake_state(SSL_HANDSHAKE *hs) {
|
|
907
947
|
return "TLS 1.3 client read_server_finished";
|
908
948
|
case state_send_end_of_early_data:
|
909
949
|
return "TLS 1.3 client send_end_of_early_data";
|
950
|
+
case state_send_client_encrypted_extensions:
|
951
|
+
return "TLS 1.3 client send_client_encrypted_extensions";
|
910
952
|
case state_send_client_certificate:
|
911
953
|
return "TLS 1.3 client send_client_certificate";
|
912
954
|
case state_send_client_certificate_verify:
|
@@ -354,13 +354,6 @@ static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
|
|
354
354
|
&offered_ticket, msg, &client_hello)) {
|
355
355
|
case ssl_ticket_aead_ignore_ticket:
|
356
356
|
assert(!session);
|
357
|
-
if (!ssl->enable_early_data) {
|
358
|
-
ssl->s3->early_data_reason = ssl_early_data_disabled;
|
359
|
-
} else if (!offered_ticket) {
|
360
|
-
ssl->s3->early_data_reason = ssl_early_data_no_session_offered;
|
361
|
-
} else {
|
362
|
-
ssl->s3->early_data_reason = ssl_early_data_session_not_resumed;
|
363
|
-
}
|
364
357
|
if (!ssl_get_new_session(hs, 1 /* server */)) {
|
365
358
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
366
359
|
return ssl_hs_error;
|
@@ -377,35 +370,6 @@ static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
|
|
377
370
|
return ssl_hs_error;
|
378
371
|
}
|
379
372
|
|
380
|
-
// |ssl_session_is_resumable| forbids cross-cipher resumptions even if the
|
381
|
-
// PRF hashes match.
|
382
|
-
assert(hs->new_cipher == session->cipher);
|
383
|
-
|
384
|
-
if (!ssl->enable_early_data) {
|
385
|
-
ssl->s3->early_data_reason = ssl_early_data_disabled;
|
386
|
-
} else if (session->ticket_max_early_data == 0) {
|
387
|
-
ssl->s3->early_data_reason = ssl_early_data_unsupported_for_session;
|
388
|
-
} else if (!hs->early_data_offered) {
|
389
|
-
ssl->s3->early_data_reason = ssl_early_data_peer_declined;
|
390
|
-
} else if (ssl->s3->channel_id_valid) {
|
391
|
-
// Channel ID is incompatible with 0-RTT.
|
392
|
-
ssl->s3->early_data_reason = ssl_early_data_channel_id;
|
393
|
-
} else if (ssl->s3->token_binding_negotiated) {
|
394
|
-
// Token Binding is incompatible with 0-RTT.
|
395
|
-
ssl->s3->early_data_reason = ssl_early_data_token_binding;
|
396
|
-
} else if (MakeConstSpan(ssl->s3->alpn_selected) != session->early_alpn) {
|
397
|
-
// The negotiated ALPN must match the one in the ticket.
|
398
|
-
ssl->s3->early_data_reason = ssl_early_data_alpn_mismatch;
|
399
|
-
} else if (ssl->s3->ticket_age_skew < -kMaxTicketAgeSkewSeconds ||
|
400
|
-
kMaxTicketAgeSkewSeconds < ssl->s3->ticket_age_skew) {
|
401
|
-
ssl->s3->early_data_reason = ssl_early_data_ticket_age_skew;
|
402
|
-
} else if (!quic_ticket_compatible(session.get(), hs->config)) {
|
403
|
-
ssl->s3->early_data_reason = ssl_early_data_quic_parameter_mismatch;
|
404
|
-
} else {
|
405
|
-
ssl->s3->early_data_reason = ssl_early_data_accepted;
|
406
|
-
ssl->s3->early_data_accepted = true;
|
407
|
-
}
|
408
|
-
|
409
373
|
ssl->s3->session_reused = true;
|
410
374
|
|
411
375
|
// Resumption incorporates fresh key material, so refresh the timeout.
|
@@ -422,15 +386,83 @@ static enum ssl_hs_wait_t do_select_session(SSL_HANDSHAKE *hs) {
|
|
422
386
|
return ssl_hs_pending_ticket;
|
423
387
|
}
|
424
388
|
|
389
|
+
// Negotiate ALPS now, after ALPN is negotiated and |hs->new_session| is
|
390
|
+
// initialized.
|
391
|
+
if (!ssl_negotiate_alps(hs, &alert, &client_hello)) {
|
392
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
393
|
+
return ssl_hs_error;
|
394
|
+
}
|
395
|
+
|
396
|
+
// Determine if we're negotiating 0-RTT.
|
397
|
+
if (!ssl->enable_early_data) {
|
398
|
+
ssl->s3->early_data_reason = ssl_early_data_disabled;
|
399
|
+
} else if (!offered_ticket) {
|
400
|
+
ssl->s3->early_data_reason = ssl_early_data_no_session_offered;
|
401
|
+
} else if (!session) {
|
402
|
+
ssl->s3->early_data_reason = ssl_early_data_session_not_resumed;
|
403
|
+
} else if (session->ticket_max_early_data == 0) {
|
404
|
+
ssl->s3->early_data_reason = ssl_early_data_unsupported_for_session;
|
405
|
+
} else if (!hs->early_data_offered) {
|
406
|
+
ssl->s3->early_data_reason = ssl_early_data_peer_declined;
|
407
|
+
} else if (ssl->s3->channel_id_valid) {
|
408
|
+
// Channel ID is incompatible with 0-RTT.
|
409
|
+
ssl->s3->early_data_reason = ssl_early_data_channel_id;
|
410
|
+
} else if (ssl->s3->token_binding_negotiated) {
|
411
|
+
// Token Binding is incompatible with 0-RTT.
|
412
|
+
ssl->s3->early_data_reason = ssl_early_data_token_binding;
|
413
|
+
} else if (MakeConstSpan(ssl->s3->alpn_selected) != session->early_alpn) {
|
414
|
+
// The negotiated ALPN must match the one in the ticket.
|
415
|
+
ssl->s3->early_data_reason = ssl_early_data_alpn_mismatch;
|
416
|
+
} else if (hs->new_session->has_application_settings !=
|
417
|
+
session->has_application_settings ||
|
418
|
+
MakeConstSpan(hs->new_session->local_application_settings) !=
|
419
|
+
session->local_application_settings) {
|
420
|
+
ssl->s3->early_data_reason = ssl_early_data_alps_mismatch;
|
421
|
+
} else if (ssl->s3->ticket_age_skew < -kMaxTicketAgeSkewSeconds ||
|
422
|
+
kMaxTicketAgeSkewSeconds < ssl->s3->ticket_age_skew) {
|
423
|
+
ssl->s3->early_data_reason = ssl_early_data_ticket_age_skew;
|
424
|
+
} else if (!quic_ticket_compatible(session.get(), hs->config)) {
|
425
|
+
ssl->s3->early_data_reason = ssl_early_data_quic_parameter_mismatch;
|
426
|
+
} else {
|
427
|
+
// |ssl_session_is_resumable| forbids cross-cipher resumptions even if the
|
428
|
+
// PRF hashes match.
|
429
|
+
assert(hs->new_cipher == session->cipher);
|
430
|
+
|
431
|
+
ssl->s3->early_data_reason = ssl_early_data_accepted;
|
432
|
+
ssl->s3->early_data_accepted = true;
|
433
|
+
}
|
434
|
+
|
425
435
|
// Record connection properties in the new session.
|
426
436
|
hs->new_session->cipher = hs->new_cipher;
|
427
437
|
|
428
|
-
// Store the
|
438
|
+
// Store the ALPN and ALPS values in the session for 0-RTT. Note the peer
|
439
|
+
// applications settings are not generally known until client
|
440
|
+
// EncryptedExtensions.
|
429
441
|
if (!hs->new_session->early_alpn.CopyFrom(ssl->s3->alpn_selected)) {
|
430
442
|
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
431
443
|
return ssl_hs_error;
|
432
444
|
}
|
433
445
|
|
446
|
+
// The peer applications settings are usually received later, in
|
447
|
+
// EncryptedExtensions. But, in 0-RTT handshakes, we carry over the
|
448
|
+
// values from |session|. Do this now, before |session| is discarded.
|
449
|
+
if (ssl->s3->early_data_accepted &&
|
450
|
+
hs->new_session->has_application_settings &&
|
451
|
+
!hs->new_session->peer_application_settings.CopyFrom(
|
452
|
+
session->peer_application_settings)) {
|
453
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
454
|
+
return ssl_hs_error;
|
455
|
+
}
|
456
|
+
|
457
|
+
// Copy the QUIC early data context to the session.
|
458
|
+
if (ssl->enable_early_data && ssl->quic_method) {
|
459
|
+
if (!hs->new_session->quic_early_data_context.CopyFrom(
|
460
|
+
hs->config->quic_early_data_context)) {
|
461
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
462
|
+
return ssl_hs_error;
|
463
|
+
}
|
464
|
+
}
|
465
|
+
|
434
466
|
if (ssl->ctx->dos_protection_cb != NULL &&
|
435
467
|
ssl->ctx->dos_protection_cb(&client_hello) == 0) {
|
436
468
|
// Connection rejected for DOS reasons.
|
@@ -845,6 +877,64 @@ static enum ssl_hs_wait_t do_process_end_of_early_data(SSL_HANDSHAKE *hs) {
|
|
845
877
|
hs->client_handshake_secret())) {
|
846
878
|
return ssl_hs_error;
|
847
879
|
}
|
880
|
+
hs->tls13_state = state13_read_client_encrypted_extensions;
|
881
|
+
return ssl_hs_ok;
|
882
|
+
}
|
883
|
+
|
884
|
+
static enum ssl_hs_wait_t do_read_client_encrypted_extensions(
|
885
|
+
SSL_HANDSHAKE *hs) {
|
886
|
+
SSL *const ssl = hs->ssl;
|
887
|
+
// For now, only one extension uses client EncryptedExtensions. This function
|
888
|
+
// may be generalized if others use it in the future.
|
889
|
+
if (hs->new_session->has_application_settings &&
|
890
|
+
!ssl->s3->early_data_accepted) {
|
891
|
+
SSLMessage msg;
|
892
|
+
if (!ssl->method->get_message(ssl, &msg)) {
|
893
|
+
return ssl_hs_read_message;
|
894
|
+
}
|
895
|
+
if (!ssl_check_message_type(ssl, msg, SSL3_MT_ENCRYPTED_EXTENSIONS)) {
|
896
|
+
return ssl_hs_error;
|
897
|
+
}
|
898
|
+
|
899
|
+
CBS body = msg.body, extensions;
|
900
|
+
if (!CBS_get_u16_length_prefixed(&body, &extensions) ||
|
901
|
+
CBS_len(&body) != 0) {
|
902
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
903
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
904
|
+
return ssl_hs_error;
|
905
|
+
}
|
906
|
+
|
907
|
+
// Parse out the extensions.
|
908
|
+
bool have_application_settings = false;
|
909
|
+
CBS application_settings;
|
910
|
+
SSL_EXTENSION_TYPE ext_types[] = {{TLSEXT_TYPE_application_settings,
|
911
|
+
&have_application_settings,
|
912
|
+
&application_settings}};
|
913
|
+
uint8_t alert = SSL_AD_DECODE_ERROR;
|
914
|
+
if (!ssl_parse_extensions(&extensions, &alert, ext_types,
|
915
|
+
/*ignore_unknown=*/false)) {
|
916
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
|
917
|
+
return ssl_hs_error;
|
918
|
+
}
|
919
|
+
|
920
|
+
if (!have_application_settings) {
|
921
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_EXTENSION);
|
922
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_MISSING_EXTENSION);
|
923
|
+
return ssl_hs_error;
|
924
|
+
}
|
925
|
+
|
926
|
+
// Note that, if 0-RTT was accepted, these values will already have been
|
927
|
+
// initialized earlier.
|
928
|
+
if (!hs->new_session->peer_application_settings.CopyFrom(
|
929
|
+
application_settings) ||
|
930
|
+
!ssl_hash_message(hs, msg)) {
|
931
|
+
ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
932
|
+
return ssl_hs_error;
|
933
|
+
}
|
934
|
+
|
935
|
+
ssl->method->next_message(ssl);
|
936
|
+
}
|
937
|
+
|
848
938
|
hs->tls13_state = state13_read_client_certificate;
|
849
939
|
return ssl_hs_ok;
|
850
940
|
}
|
@@ -883,8 +973,7 @@ static enum ssl_hs_wait_t do_read_client_certificate(SSL_HANDSHAKE *hs) {
|
|
883
973
|
return ssl_hs_ok;
|
884
974
|
}
|
885
975
|
|
886
|
-
static enum ssl_hs_wait_t do_read_client_certificate_verify(
|
887
|
-
SSL_HANDSHAKE *hs) {
|
976
|
+
static enum ssl_hs_wait_t do_read_client_certificate_verify(SSL_HANDSHAKE *hs) {
|
888
977
|
SSL *const ssl = hs->ssl;
|
889
978
|
if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0) {
|
890
979
|
// Skip this state.
|
@@ -1028,6 +1117,9 @@ enum ssl_hs_wait_t tls13_server_handshake(SSL_HANDSHAKE *hs) {
|
|
1028
1117
|
case state13_process_end_of_early_data:
|
1029
1118
|
ret = do_process_end_of_early_data(hs);
|
1030
1119
|
break;
|
1120
|
+
case state13_read_client_encrypted_extensions:
|
1121
|
+
ret = do_read_client_encrypted_extensions(hs);
|
1122
|
+
break;
|
1031
1123
|
case state13_read_client_certificate:
|
1032
1124
|
ret = do_read_client_certificate(hs);
|
1033
1125
|
break;
|
@@ -1084,6 +1176,8 @@ const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs) {
|
|
1084
1176
|
return "TLS 1.3 server read_second_client_flight";
|
1085
1177
|
case state13_process_end_of_early_data:
|
1086
1178
|
return "TLS 1.3 server process_end_of_early_data";
|
1179
|
+
case state13_read_client_encrypted_extensions:
|
1180
|
+
return "TLS 1.3 server read_client_encrypted_extensions";
|
1087
1181
|
case state13_read_client_certificate:
|
1088
1182
|
return "TLS 1.3 server read_client_certificate";
|
1089
1183
|
case state13_read_client_certificate_verify:
|
@@ -0,0 +1,2169 @@
|
|
1
|
+
|
2
|
+
#include "upb/def.h"
|
3
|
+
|
4
|
+
#include <ctype.h>
|
5
|
+
#include <errno.h>
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <string.h>
|
8
|
+
#include "google/protobuf/descriptor.upb.h"
|
9
|
+
|
10
|
+
#include "upb/port_def.inc"
|
11
|
+
|
12
|
+
typedef struct {
|
13
|
+
size_t len;
|
14
|
+
char str[1]; /* Null-terminated string data follows. */
|
15
|
+
} str_t;
|
16
|
+
|
17
|
+
static str_t *newstr(upb_alloc *alloc, const char *data, size_t len) {
|
18
|
+
str_t *ret = upb_malloc(alloc, sizeof(*ret) + len);
|
19
|
+
if (!ret) return NULL;
|
20
|
+
ret->len = len;
|
21
|
+
if (len) memcpy(ret->str, data, len);
|
22
|
+
ret->str[len] = '\0';
|
23
|
+
return ret;
|
24
|
+
}
|
25
|
+
|
26
|
+
struct upb_fielddef {
|
27
|
+
const upb_filedef *file;
|
28
|
+
const upb_msgdef *msgdef;
|
29
|
+
const char *full_name;
|
30
|
+
const char *json_name;
|
31
|
+
union {
|
32
|
+
int64_t sint;
|
33
|
+
uint64_t uint;
|
34
|
+
double dbl;
|
35
|
+
float flt;
|
36
|
+
bool boolean;
|
37
|
+
str_t *str;
|
38
|
+
} defaultval;
|
39
|
+
const upb_oneofdef *oneof;
|
40
|
+
union {
|
41
|
+
const upb_msgdef *msgdef;
|
42
|
+
const upb_enumdef *enumdef;
|
43
|
+
const google_protobuf_FieldDescriptorProto *unresolved;
|
44
|
+
} sub;
|
45
|
+
uint32_t number_;
|
46
|
+
uint16_t index_;
|
47
|
+
uint16_t layout_index;
|
48
|
+
uint32_t selector_base; /* Used to index into a upb::Handlers table. */
|
49
|
+
bool is_extension_;
|
50
|
+
bool lazy_;
|
51
|
+
bool packed_;
|
52
|
+
bool proto3_optional_;
|
53
|
+
upb_descriptortype_t type_;
|
54
|
+
upb_label_t label_;
|
55
|
+
};
|
56
|
+
|
57
|
+
struct upb_msgdef {
|
58
|
+
const upb_msglayout *layout;
|
59
|
+
const upb_filedef *file;
|
60
|
+
const char *full_name;
|
61
|
+
uint32_t selector_count;
|
62
|
+
uint32_t submsg_field_count;
|
63
|
+
|
64
|
+
/* Tables for looking up fields by number and name. */
|
65
|
+
upb_inttable itof;
|
66
|
+
upb_strtable ntof;
|
67
|
+
|
68
|
+
const upb_fielddef *fields;
|
69
|
+
const upb_oneofdef *oneofs;
|
70
|
+
int field_count;
|
71
|
+
int oneof_count;
|
72
|
+
int real_oneof_count;
|
73
|
+
|
74
|
+
/* Is this a map-entry message? */
|
75
|
+
bool map_entry;
|
76
|
+
upb_wellknowntype_t well_known_type;
|
77
|
+
|
78
|
+
/* TODO(haberman): proper extension ranges (there can be multiple). */
|
79
|
+
};
|
80
|
+
|
81
|
+
struct upb_enumdef {
|
82
|
+
const upb_filedef *file;
|
83
|
+
const char *full_name;
|
84
|
+
upb_strtable ntoi;
|
85
|
+
upb_inttable iton;
|
86
|
+
int32_t defaultval;
|
87
|
+
};
|
88
|
+
|
89
|
+
struct upb_oneofdef {
|
90
|
+
const upb_msgdef *parent;
|
91
|
+
const char *full_name;
|
92
|
+
uint32_t index;
|
93
|
+
upb_strtable ntof;
|
94
|
+
upb_inttable itof;
|
95
|
+
};
|
96
|
+
|
97
|
+
struct upb_filedef {
|
98
|
+
const char *name;
|
99
|
+
const char *package;
|
100
|
+
const char *phpprefix;
|
101
|
+
const char *phpnamespace;
|
102
|
+
upb_syntax_t syntax;
|
103
|
+
|
104
|
+
const upb_filedef **deps;
|
105
|
+
const upb_msgdef *msgs;
|
106
|
+
const upb_enumdef *enums;
|
107
|
+
const upb_fielddef *exts;
|
108
|
+
|
109
|
+
int dep_count;
|
110
|
+
int msg_count;
|
111
|
+
int enum_count;
|
112
|
+
int ext_count;
|
113
|
+
};
|
114
|
+
|
115
|
+
struct upb_symtab {
|
116
|
+
upb_arena *arena;
|
117
|
+
upb_strtable syms; /* full_name -> packed def ptr */
|
118
|
+
upb_strtable files; /* file_name -> upb_filedef* */
|
119
|
+
};
|
120
|
+
|
121
|
+
/* Inside a symtab we store tagged pointers to specific def types. */
|
122
|
+
typedef enum {
|
123
|
+
UPB_DEFTYPE_FIELD = 0,
|
124
|
+
|
125
|
+
/* Only inside symtab table. */
|
126
|
+
UPB_DEFTYPE_MSG = 1,
|
127
|
+
UPB_DEFTYPE_ENUM = 2,
|
128
|
+
|
129
|
+
/* Only inside message table. */
|
130
|
+
UPB_DEFTYPE_ONEOF = 1,
|
131
|
+
UPB_DEFTYPE_FIELD_JSONNAME = 2
|
132
|
+
} upb_deftype_t;
|
133
|
+
|
134
|
+
static const void *unpack_def(upb_value v, upb_deftype_t type) {
|
135
|
+
uintptr_t num = (uintptr_t)upb_value_getconstptr(v);
|
136
|
+
return (num & 3) == type ? (const void*)(num & ~3) : NULL;
|
137
|
+
}
|
138
|
+
|
139
|
+
static upb_value pack_def(const void *ptr, upb_deftype_t type) {
|
140
|
+
uintptr_t num = (uintptr_t)ptr | type;
|
141
|
+
return upb_value_constptr((const void*)num);
|
142
|
+
}
|
143
|
+
|
144
|
+
/* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */
|
145
|
+
static bool upb_isbetween(char c, char low, char high) {
|
146
|
+
return c >= low && c <= high;
|
147
|
+
}
|
148
|
+
|
149
|
+
static bool upb_isletter(char c) {
|
150
|
+
return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_';
|
151
|
+
}
|
152
|
+
|
153
|
+
static bool upb_isalphanum(char c) {
|
154
|
+
return upb_isletter(c) || upb_isbetween(c, '0', '9');
|
155
|
+
}
|
156
|
+
|
157
|
+
static bool upb_isident(upb_strview name, bool full, upb_status *s) {
|
158
|
+
const char *str = name.data;
|
159
|
+
size_t len = name.size;
|
160
|
+
bool start = true;
|
161
|
+
size_t i;
|
162
|
+
for (i = 0; i < len; i++) {
|
163
|
+
char c = str[i];
|
164
|
+
if (c == '.') {
|
165
|
+
if (start || !full) {
|
166
|
+
upb_status_seterrf(s, "invalid name: unexpected '.' (%s)", str);
|
167
|
+
return false;
|
168
|
+
}
|
169
|
+
start = true;
|
170
|
+
} else if (start) {
|
171
|
+
if (!upb_isletter(c)) {
|
172
|
+
upb_status_seterrf(
|
173
|
+
s, "invalid name: path components must start with a letter (%s)",
|
174
|
+
str);
|
175
|
+
return false;
|
176
|
+
}
|
177
|
+
start = false;
|
178
|
+
} else {
|
179
|
+
if (!upb_isalphanum(c)) {
|
180
|
+
upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)",
|
181
|
+
str);
|
182
|
+
return false;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
return !start;
|
187
|
+
}
|
188
|
+
|
189
|
+
static const char *shortdefname(const char *fullname) {
|
190
|
+
const char *p;
|
191
|
+
|
192
|
+
if (fullname == NULL) {
|
193
|
+
return NULL;
|
194
|
+
} else if ((p = strrchr(fullname, '.')) == NULL) {
|
195
|
+
/* No '.' in the name, return the full string. */
|
196
|
+
return fullname;
|
197
|
+
} else {
|
198
|
+
/* Return one past the last '.'. */
|
199
|
+
return p + 1;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
/* All submessage fields are lower than all other fields.
|
204
|
+
* Secondly, fields are increasing in order. */
|
205
|
+
uint32_t field_rank(const upb_fielddef *f) {
|
206
|
+
uint32_t ret = upb_fielddef_number(f);
|
207
|
+
const uint32_t high_bit = 1 << 30;
|
208
|
+
UPB_ASSERT(ret < high_bit);
|
209
|
+
if (!upb_fielddef_issubmsg(f))
|
210
|
+
ret |= high_bit;
|
211
|
+
return ret;
|
212
|
+
}
|
213
|
+
|
214
|
+
int cmp_fields(const void *p1, const void *p2) {
|
215
|
+
const upb_fielddef *f1 = *(upb_fielddef*const*)p1;
|
216
|
+
const upb_fielddef *f2 = *(upb_fielddef*const*)p2;
|
217
|
+
return field_rank(f1) - field_rank(f2);
|
218
|
+
}
|
219
|
+
|
220
|
+
/* A few implementation details of handlers. We put these here to avoid
|
221
|
+
* a def -> handlers dependency. */
|
222
|
+
|
223
|
+
#define UPB_STATIC_SELECTOR_COUNT 3 /* Warning: also in upb/handlers.h. */
|
224
|
+
|
225
|
+
static uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) {
|
226
|
+
return upb_fielddef_isseq(f) ? 2 : 0;
|
227
|
+
}
|
228
|
+
|
229
|
+
static uint32_t upb_handlers_selectorcount(const upb_fielddef *f) {
|
230
|
+
uint32_t ret = 1;
|
231
|
+
if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */
|
232
|
+
if (upb_fielddef_isstring(f)) ret += 2; /* [STRING]/STARTSTR/ENDSTR */
|
233
|
+
if (upb_fielddef_issubmsg(f)) {
|
234
|
+
/* ENDSUBMSG (STARTSUBMSG is at table beginning) */
|
235
|
+
ret += 0;
|
236
|
+
if (upb_fielddef_lazy(f)) {
|
237
|
+
/* STARTSTR/ENDSTR/STRING (for lazy) */
|
238
|
+
ret += 3;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
return ret;
|
242
|
+
}
|
243
|
+
|
244
|
+
static void upb_status_setoom(upb_status *status) {
|
245
|
+
upb_status_seterrmsg(status, "out of memory");
|
246
|
+
}
|
247
|
+
|
248
|
+
static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
|
249
|
+
/* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the
|
250
|
+
* lowest indexes, but we do not publicly guarantee this. */
|
251
|
+
upb_msg_field_iter j;
|
252
|
+
int i;
|
253
|
+
uint32_t selector;
|
254
|
+
int n = upb_msgdef_numfields(m);
|
255
|
+
upb_fielddef **fields;
|
256
|
+
|
257
|
+
if (n == 0) {
|
258
|
+
m->selector_count = UPB_STATIC_SELECTOR_COUNT;
|
259
|
+
m->submsg_field_count = 0;
|
260
|
+
return true;
|
261
|
+
}
|
262
|
+
|
263
|
+
fields = upb_gmalloc(n * sizeof(*fields));
|
264
|
+
if (!fields) {
|
265
|
+
upb_status_setoom(s);
|
266
|
+
return false;
|
267
|
+
}
|
268
|
+
|
269
|
+
m->submsg_field_count = 0;
|
270
|
+
for(i = 0, upb_msg_field_begin(&j, m);
|
271
|
+
!upb_msg_field_done(&j);
|
272
|
+
upb_msg_field_next(&j), i++) {
|
273
|
+
upb_fielddef *f = upb_msg_iter_field(&j);
|
274
|
+
UPB_ASSERT(f->msgdef == m);
|
275
|
+
if (upb_fielddef_issubmsg(f)) {
|
276
|
+
m->submsg_field_count++;
|
277
|
+
}
|
278
|
+
fields[i] = f;
|
279
|
+
}
|
280
|
+
|
281
|
+
qsort(fields, n, sizeof(*fields), cmp_fields);
|
282
|
+
|
283
|
+
selector = UPB_STATIC_SELECTOR_COUNT + m->submsg_field_count;
|
284
|
+
for (i = 0; i < n; i++) {
|
285
|
+
upb_fielddef *f = fields[i];
|
286
|
+
f->index_ = i;
|
287
|
+
f->selector_base = selector + upb_handlers_selectorbaseoffset(f);
|
288
|
+
selector += upb_handlers_selectorcount(f);
|
289
|
+
}
|
290
|
+
m->selector_count = selector;
|
291
|
+
|
292
|
+
upb_gfree(fields);
|
293
|
+
return true;
|
294
|
+
}
|
295
|
+
|
296
|
+
static bool check_oneofs(upb_msgdef *m, upb_status *s) {
|
297
|
+
int i;
|
298
|
+
int first_synthetic = -1;
|
299
|
+
upb_oneofdef *mutable_oneofs = (upb_oneofdef*)m->oneofs;
|
300
|
+
|
301
|
+
for (i = 0; i < m->oneof_count; i++) {
|
302
|
+
mutable_oneofs[i].index = i;
|
303
|
+
|
304
|
+
if (upb_oneofdef_issynthetic(&mutable_oneofs[i])) {
|
305
|
+
if (first_synthetic == -1) {
|
306
|
+
first_synthetic = i;
|
307
|
+
}
|
308
|
+
} else {
|
309
|
+
if (first_synthetic != -1) {
|
310
|
+
upb_status_seterrf(
|
311
|
+
s, "Synthetic oneofs must be after all other oneofs: %s",
|
312
|
+
upb_oneofdef_name(&mutable_oneofs[i]));
|
313
|
+
return false;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
if (first_synthetic == -1) {
|
319
|
+
m->real_oneof_count = m->oneof_count;
|
320
|
+
} else {
|
321
|
+
m->real_oneof_count = first_synthetic;
|
322
|
+
}
|
323
|
+
|
324
|
+
return true;
|
325
|
+
}
|
326
|
+
|
327
|
+
static void assign_msg_wellknowntype(upb_msgdef *m) {
|
328
|
+
const char *name = upb_msgdef_fullname(m);
|
329
|
+
if (name == NULL) {
|
330
|
+
m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED;
|
331
|
+
return;
|
332
|
+
}
|
333
|
+
if (!strcmp(name, "google.protobuf.Any")) {
|
334
|
+
m->well_known_type = UPB_WELLKNOWN_ANY;
|
335
|
+
} else if (!strcmp(name, "google.protobuf.FieldMask")) {
|
336
|
+
m->well_known_type = UPB_WELLKNOWN_FIELDMASK;
|
337
|
+
} else if (!strcmp(name, "google.protobuf.Duration")) {
|
338
|
+
m->well_known_type = UPB_WELLKNOWN_DURATION;
|
339
|
+
} else if (!strcmp(name, "google.protobuf.Timestamp")) {
|
340
|
+
m->well_known_type = UPB_WELLKNOWN_TIMESTAMP;
|
341
|
+
} else if (!strcmp(name, "google.protobuf.DoubleValue")) {
|
342
|
+
m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE;
|
343
|
+
} else if (!strcmp(name, "google.protobuf.FloatValue")) {
|
344
|
+
m->well_known_type = UPB_WELLKNOWN_FLOATVALUE;
|
345
|
+
} else if (!strcmp(name, "google.protobuf.Int64Value")) {
|
346
|
+
m->well_known_type = UPB_WELLKNOWN_INT64VALUE;
|
347
|
+
} else if (!strcmp(name, "google.protobuf.UInt64Value")) {
|
348
|
+
m->well_known_type = UPB_WELLKNOWN_UINT64VALUE;
|
349
|
+
} else if (!strcmp(name, "google.protobuf.Int32Value")) {
|
350
|
+
m->well_known_type = UPB_WELLKNOWN_INT32VALUE;
|
351
|
+
} else if (!strcmp(name, "google.protobuf.UInt32Value")) {
|
352
|
+
m->well_known_type = UPB_WELLKNOWN_UINT32VALUE;
|
353
|
+
} else if (!strcmp(name, "google.protobuf.BoolValue")) {
|
354
|
+
m->well_known_type = UPB_WELLKNOWN_BOOLVALUE;
|
355
|
+
} else if (!strcmp(name, "google.protobuf.StringValue")) {
|
356
|
+
m->well_known_type = UPB_WELLKNOWN_STRINGVALUE;
|
357
|
+
} else if (!strcmp(name, "google.protobuf.BytesValue")) {
|
358
|
+
m->well_known_type = UPB_WELLKNOWN_BYTESVALUE;
|
359
|
+
} else if (!strcmp(name, "google.protobuf.Value")) {
|
360
|
+
m->well_known_type = UPB_WELLKNOWN_VALUE;
|
361
|
+
} else if (!strcmp(name, "google.protobuf.ListValue")) {
|
362
|
+
m->well_known_type = UPB_WELLKNOWN_LISTVALUE;
|
363
|
+
} else if (!strcmp(name, "google.protobuf.Struct")) {
|
364
|
+
m->well_known_type = UPB_WELLKNOWN_STRUCT;
|
365
|
+
} else {
|
366
|
+
m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED;
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
|
371
|
+
/* upb_enumdef ****************************************************************/
|
372
|
+
|
373
|
+
const char *upb_enumdef_fullname(const upb_enumdef *e) {
|
374
|
+
return e->full_name;
|
375
|
+
}
|
376
|
+
|
377
|
+
const char *upb_enumdef_name(const upb_enumdef *e) {
|
378
|
+
return shortdefname(e->full_name);
|
379
|
+
}
|
380
|
+
|
381
|
+
const upb_filedef *upb_enumdef_file(const upb_enumdef *e) {
|
382
|
+
return e->file;
|
383
|
+
}
|
384
|
+
|
385
|
+
int32_t upb_enumdef_default(const upb_enumdef *e) {
|
386
|
+
UPB_ASSERT(upb_enumdef_iton(e, e->defaultval));
|
387
|
+
return e->defaultval;
|
388
|
+
}
|
389
|
+
|
390
|
+
int upb_enumdef_numvals(const upb_enumdef *e) {
|
391
|
+
return (int)upb_strtable_count(&e->ntoi);
|
392
|
+
}
|
393
|
+
|
394
|
+
void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) {
|
395
|
+
/* We iterate over the ntoi table, to account for duplicate numbers. */
|
396
|
+
upb_strtable_begin(i, &e->ntoi);
|
397
|
+
}
|
398
|
+
|
399
|
+
void upb_enum_next(upb_enum_iter *iter) { upb_strtable_next(iter); }
|
400
|
+
bool upb_enum_done(upb_enum_iter *iter) { return upb_strtable_done(iter); }
|
401
|
+
|
402
|
+
bool upb_enumdef_ntoi(const upb_enumdef *def, const char *name,
|
403
|
+
size_t len, int32_t *num) {
|
404
|
+
upb_value v;
|
405
|
+
if (!upb_strtable_lookup2(&def->ntoi, name, len, &v)) {
|
406
|
+
return false;
|
407
|
+
}
|
408
|
+
if (num) *num = upb_value_getint32(v);
|
409
|
+
return true;
|
410
|
+
}
|
411
|
+
|
412
|
+
const char *upb_enumdef_iton(const upb_enumdef *def, int32_t num) {
|
413
|
+
upb_value v;
|
414
|
+
return upb_inttable_lookup32(&def->iton, num, &v) ?
|
415
|
+
upb_value_getcstr(v) : NULL;
|
416
|
+
}
|
417
|
+
|
418
|
+
const char *upb_enum_iter_name(upb_enum_iter *iter) {
|
419
|
+
return upb_strtable_iter_key(iter).data;
|
420
|
+
}
|
421
|
+
|
422
|
+
int32_t upb_enum_iter_number(upb_enum_iter *iter) {
|
423
|
+
return upb_value_getint32(upb_strtable_iter_value(iter));
|
424
|
+
}
|
425
|
+
|
426
|
+
|
427
|
+
/* upb_fielddef ***************************************************************/
|
428
|
+
|
429
|
+
const char *upb_fielddef_fullname(const upb_fielddef *f) {
|
430
|
+
return f->full_name;
|
431
|
+
}
|
432
|
+
|
433
|
+
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) {
|
434
|
+
switch (f->type_) {
|
435
|
+
case UPB_DESCRIPTOR_TYPE_DOUBLE:
|
436
|
+
return UPB_TYPE_DOUBLE;
|
437
|
+
case UPB_DESCRIPTOR_TYPE_FLOAT:
|
438
|
+
return UPB_TYPE_FLOAT;
|
439
|
+
case UPB_DESCRIPTOR_TYPE_INT64:
|
440
|
+
case UPB_DESCRIPTOR_TYPE_SINT64:
|
441
|
+
case UPB_DESCRIPTOR_TYPE_SFIXED64:
|
442
|
+
return UPB_TYPE_INT64;
|
443
|
+
case UPB_DESCRIPTOR_TYPE_INT32:
|
444
|
+
case UPB_DESCRIPTOR_TYPE_SFIXED32:
|
445
|
+
case UPB_DESCRIPTOR_TYPE_SINT32:
|
446
|
+
return UPB_TYPE_INT32;
|
447
|
+
case UPB_DESCRIPTOR_TYPE_UINT64:
|
448
|
+
case UPB_DESCRIPTOR_TYPE_FIXED64:
|
449
|
+
return UPB_TYPE_UINT64;
|
450
|
+
case UPB_DESCRIPTOR_TYPE_UINT32:
|
451
|
+
case UPB_DESCRIPTOR_TYPE_FIXED32:
|
452
|
+
return UPB_TYPE_UINT32;
|
453
|
+
case UPB_DESCRIPTOR_TYPE_ENUM:
|
454
|
+
return UPB_TYPE_ENUM;
|
455
|
+
case UPB_DESCRIPTOR_TYPE_BOOL:
|
456
|
+
return UPB_TYPE_BOOL;
|
457
|
+
case UPB_DESCRIPTOR_TYPE_STRING:
|
458
|
+
return UPB_TYPE_STRING;
|
459
|
+
case UPB_DESCRIPTOR_TYPE_BYTES:
|
460
|
+
return UPB_TYPE_BYTES;
|
461
|
+
case UPB_DESCRIPTOR_TYPE_GROUP:
|
462
|
+
case UPB_DESCRIPTOR_TYPE_MESSAGE:
|
463
|
+
return UPB_TYPE_MESSAGE;
|
464
|
+
}
|
465
|
+
UPB_UNREACHABLE();
|
466
|
+
}
|
467
|
+
|
468
|
+
upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f) {
|
469
|
+
return f->type_;
|
470
|
+
}
|
471
|
+
|
472
|
+
uint32_t upb_fielddef_index(const upb_fielddef *f) {
|
473
|
+
return f->index_;
|
474
|
+
}
|
475
|
+
|
476
|
+
upb_label_t upb_fielddef_label(const upb_fielddef *f) {
|
477
|
+
return f->label_;
|
478
|
+
}
|
479
|
+
|
480
|
+
uint32_t upb_fielddef_number(const upb_fielddef *f) {
|
481
|
+
return f->number_;
|
482
|
+
}
|
483
|
+
|
484
|
+
bool upb_fielddef_isextension(const upb_fielddef *f) {
|
485
|
+
return f->is_extension_;
|
486
|
+
}
|
487
|
+
|
488
|
+
bool upb_fielddef_lazy(const upb_fielddef *f) {
|
489
|
+
return f->lazy_;
|
490
|
+
}
|
491
|
+
|
492
|
+
bool upb_fielddef_packed(const upb_fielddef *f) {
|
493
|
+
return f->packed_;
|
494
|
+
}
|
495
|
+
|
496
|
+
const char *upb_fielddef_name(const upb_fielddef *f) {
|
497
|
+
return shortdefname(f->full_name);
|
498
|
+
}
|
499
|
+
|
500
|
+
const char *upb_fielddef_jsonname(const upb_fielddef *f) {
|
501
|
+
return f->json_name;
|
502
|
+
}
|
503
|
+
|
504
|
+
uint32_t upb_fielddef_selectorbase(const upb_fielddef *f) {
|
505
|
+
return f->selector_base;
|
506
|
+
}
|
507
|
+
|
508
|
+
const upb_filedef *upb_fielddef_file(const upb_fielddef *f) {
|
509
|
+
return f->file;
|
510
|
+
}
|
511
|
+
|
512
|
+
const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) {
|
513
|
+
return f->msgdef;
|
514
|
+
}
|
515
|
+
|
516
|
+
const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) {
|
517
|
+
return f->oneof;
|
518
|
+
}
|
519
|
+
|
520
|
+
const upb_oneofdef *upb_fielddef_realcontainingoneof(const upb_fielddef *f) {
|
521
|
+
if (!f->oneof || upb_oneofdef_issynthetic(f->oneof)) return NULL;
|
522
|
+
return f->oneof;
|
523
|
+
}
|
524
|
+
|
525
|
+
static void chkdefaulttype(const upb_fielddef *f, int ctype) {
|
526
|
+
UPB_UNUSED(f);
|
527
|
+
UPB_UNUSED(ctype);
|
528
|
+
}
|
529
|
+
|
530
|
+
int64_t upb_fielddef_defaultint64(const upb_fielddef *f) {
|
531
|
+
chkdefaulttype(f, UPB_TYPE_INT64);
|
532
|
+
return f->defaultval.sint;
|
533
|
+
}
|
534
|
+
|
535
|
+
int32_t upb_fielddef_defaultint32(const upb_fielddef *f) {
|
536
|
+
chkdefaulttype(f, UPB_TYPE_INT32);
|
537
|
+
return (int32_t)f->defaultval.sint;
|
538
|
+
}
|
539
|
+
|
540
|
+
uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) {
|
541
|
+
chkdefaulttype(f, UPB_TYPE_UINT64);
|
542
|
+
return f->defaultval.uint;
|
543
|
+
}
|
544
|
+
|
545
|
+
uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) {
|
546
|
+
chkdefaulttype(f, UPB_TYPE_UINT32);
|
547
|
+
return (uint32_t)f->defaultval.uint;
|
548
|
+
}
|
549
|
+
|
550
|
+
bool upb_fielddef_defaultbool(const upb_fielddef *f) {
|
551
|
+
chkdefaulttype(f, UPB_TYPE_BOOL);
|
552
|
+
return f->defaultval.boolean;
|
553
|
+
}
|
554
|
+
|
555
|
+
float upb_fielddef_defaultfloat(const upb_fielddef *f) {
|
556
|
+
chkdefaulttype(f, UPB_TYPE_FLOAT);
|
557
|
+
return f->defaultval.flt;
|
558
|
+
}
|
559
|
+
|
560
|
+
double upb_fielddef_defaultdouble(const upb_fielddef *f) {
|
561
|
+
chkdefaulttype(f, UPB_TYPE_DOUBLE);
|
562
|
+
return f->defaultval.dbl;
|
563
|
+
}
|
564
|
+
|
565
|
+
const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) {
|
566
|
+
str_t *str = f->defaultval.str;
|
567
|
+
UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_STRING ||
|
568
|
+
upb_fielddef_type(f) == UPB_TYPE_BYTES ||
|
569
|
+
upb_fielddef_type(f) == UPB_TYPE_ENUM);
|
570
|
+
if (str) {
|
571
|
+
if (len) *len = str->len;
|
572
|
+
return str->str;
|
573
|
+
} else {
|
574
|
+
if (len) *len = 0;
|
575
|
+
return NULL;
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
579
|
+
const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f) {
|
580
|
+
return upb_fielddef_type(f) == UPB_TYPE_MESSAGE ? f->sub.msgdef : NULL;
|
581
|
+
}
|
582
|
+
|
583
|
+
const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) {
|
584
|
+
return upb_fielddef_type(f) == UPB_TYPE_ENUM ? f->sub.enumdef : NULL;
|
585
|
+
}
|
586
|
+
|
587
|
+
const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f) {
|
588
|
+
return &f->msgdef->layout->fields[f->layout_index];
|
589
|
+
}
|
590
|
+
|
591
|
+
bool upb_fielddef_issubmsg(const upb_fielddef *f) {
|
592
|
+
return upb_fielddef_type(f) == UPB_TYPE_MESSAGE;
|
593
|
+
}
|
594
|
+
|
595
|
+
bool upb_fielddef_isstring(const upb_fielddef *f) {
|
596
|
+
return upb_fielddef_type(f) == UPB_TYPE_STRING ||
|
597
|
+
upb_fielddef_type(f) == UPB_TYPE_BYTES;
|
598
|
+
}
|
599
|
+
|
600
|
+
bool upb_fielddef_isseq(const upb_fielddef *f) {
|
601
|
+
return upb_fielddef_label(f) == UPB_LABEL_REPEATED;
|
602
|
+
}
|
603
|
+
|
604
|
+
bool upb_fielddef_isprimitive(const upb_fielddef *f) {
|
605
|
+
return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f);
|
606
|
+
}
|
607
|
+
|
608
|
+
bool upb_fielddef_ismap(const upb_fielddef *f) {
|
609
|
+
return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) &&
|
610
|
+
upb_msgdef_mapentry(upb_fielddef_msgsubdef(f));
|
611
|
+
}
|
612
|
+
|
613
|
+
bool upb_fielddef_hassubdef(const upb_fielddef *f) {
|
614
|
+
return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM;
|
615
|
+
}
|
616
|
+
|
617
|
+
bool upb_fielddef_haspresence(const upb_fielddef *f) {
|
618
|
+
if (upb_fielddef_isseq(f)) return false;
|
619
|
+
return upb_fielddef_issubmsg(f) || upb_fielddef_containingoneof(f) ||
|
620
|
+
f->file->syntax == UPB_SYNTAX_PROTO2;
|
621
|
+
}
|
622
|
+
|
623
|
+
static bool between(int32_t x, int32_t low, int32_t high) {
|
624
|
+
return x >= low && x <= high;
|
625
|
+
}
|
626
|
+
|
627
|
+
bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); }
|
628
|
+
bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); }
|
629
|
+
bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); }
|
630
|
+
|
631
|
+
bool upb_fielddef_checkdescriptortype(int32_t type) {
|
632
|
+
return between(type, 1, 18);
|
633
|
+
}
|
634
|
+
|
635
|
+
/* upb_msgdef *****************************************************************/
|
636
|
+
|
637
|
+
const char *upb_msgdef_fullname(const upb_msgdef *m) {
|
638
|
+
return m->full_name;
|
639
|
+
}
|
640
|
+
|
641
|
+
const upb_filedef *upb_msgdef_file(const upb_msgdef *m) {
|
642
|
+
return m->file;
|
643
|
+
}
|
644
|
+
|
645
|
+
const char *upb_msgdef_name(const upb_msgdef *m) {
|
646
|
+
return shortdefname(m->full_name);
|
647
|
+
}
|
648
|
+
|
649
|
+
upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) {
|
650
|
+
return m->file->syntax;
|
651
|
+
}
|
652
|
+
|
653
|
+
size_t upb_msgdef_selectorcount(const upb_msgdef *m) {
|
654
|
+
return m->selector_count;
|
655
|
+
}
|
656
|
+
|
657
|
+
uint32_t upb_msgdef_submsgfieldcount(const upb_msgdef *m) {
|
658
|
+
return m->submsg_field_count;
|
659
|
+
}
|
660
|
+
|
661
|
+
const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) {
|
662
|
+
upb_value val;
|
663
|
+
return upb_inttable_lookup32(&m->itof, i, &val) ?
|
664
|
+
upb_value_getconstptr(val) : NULL;
|
665
|
+
}
|
666
|
+
|
667
|
+
const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
|
668
|
+
size_t len) {
|
669
|
+
upb_value val;
|
670
|
+
|
671
|
+
if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
|
672
|
+
return NULL;
|
673
|
+
}
|
674
|
+
|
675
|
+
return unpack_def(val, UPB_DEFTYPE_FIELD);
|
676
|
+
}
|
677
|
+
|
678
|
+
const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
|
679
|
+
size_t len) {
|
680
|
+
upb_value val;
|
681
|
+
|
682
|
+
if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
|
683
|
+
return NULL;
|
684
|
+
}
|
685
|
+
|
686
|
+
return unpack_def(val, UPB_DEFTYPE_ONEOF);
|
687
|
+
}
|
688
|
+
|
689
|
+
bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
|
690
|
+
const upb_fielddef **f, const upb_oneofdef **o) {
|
691
|
+
upb_value val;
|
692
|
+
|
693
|
+
if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
|
694
|
+
return false;
|
695
|
+
}
|
696
|
+
|
697
|
+
*o = unpack_def(val, UPB_DEFTYPE_ONEOF);
|
698
|
+
*f = unpack_def(val, UPB_DEFTYPE_FIELD);
|
699
|
+
return *o || *f; /* False if this was a JSON name. */
|
700
|
+
}
|
701
|
+
|
702
|
+
const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m,
|
703
|
+
const char *name, size_t len) {
|
704
|
+
upb_value val;
|
705
|
+
const upb_fielddef* f;
|
706
|
+
|
707
|
+
if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
|
708
|
+
return NULL;
|
709
|
+
}
|
710
|
+
|
711
|
+
f = unpack_def(val, UPB_DEFTYPE_FIELD);
|
712
|
+
if (!f) f = unpack_def(val, UPB_DEFTYPE_FIELD_JSONNAME);
|
713
|
+
|
714
|
+
return f;
|
715
|
+
}
|
716
|
+
|
717
|
+
int upb_msgdef_numfields(const upb_msgdef *m) {
|
718
|
+
return m->field_count;
|
719
|
+
}
|
720
|
+
|
721
|
+
int upb_msgdef_numoneofs(const upb_msgdef *m) {
|
722
|
+
return m->oneof_count;
|
723
|
+
}
|
724
|
+
|
725
|
+
int upb_msgdef_numrealoneofs(const upb_msgdef *m) {
|
726
|
+
return m->real_oneof_count;
|
727
|
+
}
|
728
|
+
|
729
|
+
const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) {
|
730
|
+
return m->layout;
|
731
|
+
}
|
732
|
+
|
733
|
+
const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i) {
|
734
|
+
if (i >= m->field_count) return NULL;
|
735
|
+
return &m->fields[i];
|
736
|
+
}
|
737
|
+
|
738
|
+
bool upb_msgdef_mapentry(const upb_msgdef *m) {
|
739
|
+
return m->map_entry;
|
740
|
+
}
|
741
|
+
|
742
|
+
upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) {
|
743
|
+
return m->well_known_type;
|
744
|
+
}
|
745
|
+
|
746
|
+
bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) {
|
747
|
+
upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
|
748
|
+
return type >= UPB_WELLKNOWN_DOUBLEVALUE &&
|
749
|
+
type <= UPB_WELLKNOWN_UINT32VALUE;
|
750
|
+
}
|
751
|
+
|
752
|
+
bool upb_msgdef_iswrapper(const upb_msgdef *m) {
|
753
|
+
upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
|
754
|
+
return type >= UPB_WELLKNOWN_DOUBLEVALUE &&
|
755
|
+
type <= UPB_WELLKNOWN_BOOLVALUE;
|
756
|
+
}
|
757
|
+
|
758
|
+
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) {
|
759
|
+
upb_inttable_begin(iter, &m->itof);
|
760
|
+
}
|
761
|
+
|
762
|
+
void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); }
|
763
|
+
|
764
|
+
bool upb_msg_field_done(const upb_msg_field_iter *iter) {
|
765
|
+
return upb_inttable_done(iter);
|
766
|
+
}
|
767
|
+
|
768
|
+
upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) {
|
769
|
+
return (upb_fielddef *)upb_value_getconstptr(upb_inttable_iter_value(iter));
|
770
|
+
}
|
771
|
+
|
772
|
+
void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) {
|
773
|
+
upb_inttable_iter_setdone(iter);
|
774
|
+
}
|
775
|
+
|
776
|
+
bool upb_msg_field_iter_isequal(const upb_msg_field_iter * iter1,
|
777
|
+
const upb_msg_field_iter * iter2) {
|
778
|
+
return upb_inttable_iter_isequal(iter1, iter2);
|
779
|
+
}
|
780
|
+
|
781
|
+
void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) {
|
782
|
+
upb_strtable_begin(iter, &m->ntof);
|
783
|
+
/* We need to skip past any initial fields. */
|
784
|
+
while (!upb_strtable_done(iter) &&
|
785
|
+
!unpack_def(upb_strtable_iter_value(iter), UPB_DEFTYPE_ONEOF)) {
|
786
|
+
upb_strtable_next(iter);
|
787
|
+
}
|
788
|
+
}
|
789
|
+
|
790
|
+
void upb_msg_oneof_next(upb_msg_oneof_iter *iter) {
|
791
|
+
/* We need to skip past fields to return only oneofs. */
|
792
|
+
do {
|
793
|
+
upb_strtable_next(iter);
|
794
|
+
} while (!upb_strtable_done(iter) &&
|
795
|
+
!unpack_def(upb_strtable_iter_value(iter), UPB_DEFTYPE_ONEOF));
|
796
|
+
}
|
797
|
+
|
798
|
+
bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) {
|
799
|
+
return upb_strtable_done(iter);
|
800
|
+
}
|
801
|
+
|
802
|
+
const upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) {
|
803
|
+
return unpack_def(upb_strtable_iter_value(iter), UPB_DEFTYPE_ONEOF);
|
804
|
+
}
|
805
|
+
|
806
|
+
void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) {
|
807
|
+
upb_strtable_iter_setdone(iter);
|
808
|
+
}
|
809
|
+
|
810
|
+
bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1,
|
811
|
+
const upb_msg_oneof_iter *iter2) {
|
812
|
+
return upb_strtable_iter_isequal(iter1, iter2);
|
813
|
+
}
|
814
|
+
|
815
|
+
/* upb_oneofdef ***************************************************************/
|
816
|
+
|
817
|
+
const char *upb_oneofdef_name(const upb_oneofdef *o) {
|
818
|
+
return shortdefname(o->full_name);
|
819
|
+
}
|
820
|
+
|
821
|
+
const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) {
|
822
|
+
return o->parent;
|
823
|
+
}
|
824
|
+
|
825
|
+
int upb_oneofdef_numfields(const upb_oneofdef *o) {
|
826
|
+
return (int)upb_strtable_count(&o->ntof);
|
827
|
+
}
|
828
|
+
|
829
|
+
uint32_t upb_oneofdef_index(const upb_oneofdef *o) {
|
830
|
+
return o->index;
|
831
|
+
}
|
832
|
+
|
833
|
+
bool upb_oneofdef_issynthetic(const upb_oneofdef *o) {
|
834
|
+
upb_inttable_iter iter;
|
835
|
+
const upb_fielddef *f;
|
836
|
+
upb_inttable_begin(&iter, &o->itof);
|
837
|
+
if (upb_oneofdef_numfields(o) != 1) return false;
|
838
|
+
f = upb_value_getptr(upb_inttable_iter_value(&iter));
|
839
|
+
UPB_ASSERT(f);
|
840
|
+
return f->proto3_optional_;
|
841
|
+
}
|
842
|
+
|
843
|
+
const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
|
844
|
+
const char *name, size_t length) {
|
845
|
+
upb_value val;
|
846
|
+
return upb_strtable_lookup2(&o->ntof, name, length, &val) ?
|
847
|
+
upb_value_getptr(val) : NULL;
|
848
|
+
}
|
849
|
+
|
850
|
+
const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num) {
|
851
|
+
upb_value val;
|
852
|
+
return upb_inttable_lookup32(&o->itof, num, &val) ?
|
853
|
+
upb_value_getptr(val) : NULL;
|
854
|
+
}
|
855
|
+
|
856
|
+
void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o) {
|
857
|
+
upb_inttable_begin(iter, &o->itof);
|
858
|
+
}
|
859
|
+
|
860
|
+
void upb_oneof_next(upb_oneof_iter *iter) {
|
861
|
+
upb_inttable_next(iter);
|
862
|
+
}
|
863
|
+
|
864
|
+
bool upb_oneof_done(upb_oneof_iter *iter) {
|
865
|
+
return upb_inttable_done(iter);
|
866
|
+
}
|
867
|
+
|
868
|
+
upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) {
|
869
|
+
return (upb_fielddef *)upb_value_getconstptr(upb_inttable_iter_value(iter));
|
870
|
+
}
|
871
|
+
|
872
|
+
void upb_oneof_iter_setdone(upb_oneof_iter *iter) {
|
873
|
+
upb_inttable_iter_setdone(iter);
|
874
|
+
}
|
875
|
+
|
876
|
+
/* Dynamic Layout Generation. *************************************************/
|
877
|
+
|
878
|
+
static size_t div_round_up(size_t n, size_t d) {
|
879
|
+
return (n + d - 1) / d;
|
880
|
+
}
|
881
|
+
|
882
|
+
static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
|
883
|
+
switch (type) {
|
884
|
+
case UPB_TYPE_DOUBLE:
|
885
|
+
case UPB_TYPE_INT64:
|
886
|
+
case UPB_TYPE_UINT64:
|
887
|
+
return 8;
|
888
|
+
case UPB_TYPE_ENUM:
|
889
|
+
case UPB_TYPE_INT32:
|
890
|
+
case UPB_TYPE_UINT32:
|
891
|
+
case UPB_TYPE_FLOAT:
|
892
|
+
return 4;
|
893
|
+
case UPB_TYPE_BOOL:
|
894
|
+
return 1;
|
895
|
+
case UPB_TYPE_MESSAGE:
|
896
|
+
return sizeof(void*);
|
897
|
+
case UPB_TYPE_BYTES:
|
898
|
+
case UPB_TYPE_STRING:
|
899
|
+
return sizeof(upb_strview);
|
900
|
+
}
|
901
|
+
UPB_UNREACHABLE();
|
902
|
+
}
|
903
|
+
|
904
|
+
static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
|
905
|
+
if (upb_msgdef_mapentry(upb_fielddef_containingtype(f))) {
|
906
|
+
upb_map_entry ent;
|
907
|
+
UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v));
|
908
|
+
return sizeof(ent.k);
|
909
|
+
} else if (upb_fielddef_isseq(f)) {
|
910
|
+
return sizeof(void*);
|
911
|
+
} else {
|
912
|
+
return upb_msgval_sizeof(upb_fielddef_type(f));
|
913
|
+
}
|
914
|
+
}
|
915
|
+
|
916
|
+
static uint32_t upb_msglayout_place(upb_msglayout *l, size_t size) {
|
917
|
+
uint32_t ret;
|
918
|
+
|
919
|
+
l->size = UPB_ALIGN_UP(l->size, size);
|
920
|
+
ret = l->size;
|
921
|
+
l->size += size;
|
922
|
+
return ret;
|
923
|
+
}
|
924
|
+
|
925
|
+
static int field_number_cmp(const void *p1, const void *p2) {
|
926
|
+
const upb_msglayout_field *f1 = p1;
|
927
|
+
const upb_msglayout_field *f2 = p2;
|
928
|
+
return f1->number - f2->number;
|
929
|
+
}
|
930
|
+
|
931
|
+
static void assign_layout_indices(const upb_msgdef *m, upb_msglayout_field *fields) {
|
932
|
+
int i;
|
933
|
+
int n = upb_msgdef_numfields(m);
|
934
|
+
for (i = 0; i < n; i++) {
|
935
|
+
upb_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number);
|
936
|
+
UPB_ASSERT(f);
|
937
|
+
f->layout_index = i;
|
938
|
+
}
|
939
|
+
}
|
940
|
+
|
941
|
+
/* This function is the dynamic equivalent of message_layout.{cc,h} in upbc.
|
942
|
+
* It computes a dynamic layout for all of the fields in |m|. */
|
943
|
+
static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) {
|
944
|
+
upb_msglayout *l = (upb_msglayout*)m->layout;
|
945
|
+
upb_msg_field_iter it;
|
946
|
+
upb_msg_oneof_iter oit;
|
947
|
+
size_t hasbit;
|
948
|
+
size_t submsg_count = m->submsg_field_count;
|
949
|
+
const upb_msglayout **submsgs;
|
950
|
+
upb_msglayout_field *fields;
|
951
|
+
upb_alloc *alloc = upb_arena_alloc(symtab->arena);
|
952
|
+
|
953
|
+
memset(l, 0, sizeof(*l));
|
954
|
+
|
955
|
+
fields = upb_malloc(alloc, upb_msgdef_numfields(m) * sizeof(*fields));
|
956
|
+
submsgs = upb_malloc(alloc, submsg_count * sizeof(*submsgs));
|
957
|
+
|
958
|
+
if ((!fields && upb_msgdef_numfields(m)) ||
|
959
|
+
(!submsgs && submsg_count)) {
|
960
|
+
/* OOM. */
|
961
|
+
return false;
|
962
|
+
}
|
963
|
+
|
964
|
+
l->field_count = upb_msgdef_numfields(m);
|
965
|
+
l->fields = fields;
|
966
|
+
l->submsgs = submsgs;
|
967
|
+
|
968
|
+
if (upb_msgdef_mapentry(m)) {
|
969
|
+
/* TODO(haberman): refactor this method so this special case is more
|
970
|
+
* elegant. */
|
971
|
+
const upb_fielddef *key = upb_msgdef_itof(m, 1);
|
972
|
+
const upb_fielddef *val = upb_msgdef_itof(m, 2);
|
973
|
+
fields[0].number = 1;
|
974
|
+
fields[1].number = 2;
|
975
|
+
fields[0].label = UPB_LABEL_OPTIONAL;
|
976
|
+
fields[1].label = UPB_LABEL_OPTIONAL;
|
977
|
+
fields[0].presence = 0;
|
978
|
+
fields[1].presence = 0;
|
979
|
+
fields[0].descriptortype = upb_fielddef_descriptortype(key);
|
980
|
+
fields[1].descriptortype = upb_fielddef_descriptortype(val);
|
981
|
+
fields[0].offset = 0;
|
982
|
+
fields[1].offset = sizeof(upb_strview);
|
983
|
+
fields[1].submsg_index = 0;
|
984
|
+
|
985
|
+
if (upb_fielddef_type(val) == UPB_TYPE_MESSAGE) {
|
986
|
+
submsgs[0] = upb_fielddef_msgsubdef(val)->layout;
|
987
|
+
}
|
988
|
+
|
989
|
+
l->field_count = 2;
|
990
|
+
l->size = 2 * sizeof(upb_strview);
|
991
|
+
l->size = UPB_ALIGN_UP(l->size, 8);
|
992
|
+
return true;
|
993
|
+
}
|
994
|
+
|
995
|
+
/* Allocate data offsets in three stages:
|
996
|
+
*
|
997
|
+
* 1. hasbits.
|
998
|
+
* 2. regular fields.
|
999
|
+
* 3. oneof fields.
|
1000
|
+
*
|
1001
|
+
* OPT: There is a lot of room for optimization here to minimize the size.
|
1002
|
+
*/
|
1003
|
+
|
1004
|
+
/* Allocate hasbits and set basic field attributes. */
|
1005
|
+
submsg_count = 0;
|
1006
|
+
for (upb_msg_field_begin(&it, m), hasbit = 0;
|
1007
|
+
!upb_msg_field_done(&it);
|
1008
|
+
upb_msg_field_next(&it)) {
|
1009
|
+
upb_fielddef* f = upb_msg_iter_field(&it);
|
1010
|
+
upb_msglayout_field *field = &fields[upb_fielddef_index(f)];
|
1011
|
+
|
1012
|
+
field->number = upb_fielddef_number(f);
|
1013
|
+
field->descriptortype = upb_fielddef_descriptortype(f);
|
1014
|
+
field->label = upb_fielddef_label(f);
|
1015
|
+
|
1016
|
+
if (field->descriptortype == UPB_DTYPE_STRING &&
|
1017
|
+
f->file->syntax == UPB_SYNTAX_PROTO2) {
|
1018
|
+
/* See TableDescriptorType() in upbc/generator.cc for details and
|
1019
|
+
* rationale. */
|
1020
|
+
field->descriptortype = UPB_DTYPE_BYTES;
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
if (upb_fielddef_ismap(f)) {
|
1024
|
+
field->label = _UPB_LABEL_MAP;
|
1025
|
+
} else if (upb_fielddef_packed(f)) {
|
1026
|
+
field->label = _UPB_LABEL_PACKED;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
if (upb_fielddef_issubmsg(f)) {
|
1030
|
+
const upb_msgdef *subm = upb_fielddef_msgsubdef(f);
|
1031
|
+
field->submsg_index = submsg_count++;
|
1032
|
+
submsgs[field->submsg_index] = subm->layout;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
if (upb_fielddef_haspresence(f) && !upb_fielddef_realcontainingoneof(f)) {
|
1036
|
+
/* We don't use hasbit 0, so that 0 can indicate "no presence" in the
|
1037
|
+
* table. This wastes one hasbit, but we don't worry about it for now. */
|
1038
|
+
field->presence = ++hasbit;
|
1039
|
+
} else {
|
1040
|
+
field->presence = 0;
|
1041
|
+
}
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
/* Account for space used by hasbits. */
|
1045
|
+
l->size = div_round_up(hasbit, 8);
|
1046
|
+
|
1047
|
+
/* Allocate non-oneof fields. */
|
1048
|
+
for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
|
1049
|
+
upb_msg_field_next(&it)) {
|
1050
|
+
const upb_fielddef* f = upb_msg_iter_field(&it);
|
1051
|
+
size_t field_size = upb_msg_fielddefsize(f);
|
1052
|
+
size_t index = upb_fielddef_index(f);
|
1053
|
+
|
1054
|
+
if (upb_fielddef_realcontainingoneof(f)) {
|
1055
|
+
/* Oneofs are handled separately below. */
|
1056
|
+
continue;
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
fields[index].offset = upb_msglayout_place(l, field_size);
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
/* Allocate oneof fields. Each oneof field consists of a uint32 for the case
|
1063
|
+
* and space for the actual data. */
|
1064
|
+
for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
|
1065
|
+
upb_msg_oneof_next(&oit)) {
|
1066
|
+
const upb_oneofdef* o = upb_msg_iter_oneof(&oit);
|
1067
|
+
upb_oneof_iter fit;
|
1068
|
+
|
1069
|
+
size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
|
1070
|
+
size_t field_size = 0;
|
1071
|
+
uint32_t case_offset;
|
1072
|
+
uint32_t data_offset;
|
1073
|
+
|
1074
|
+
if (upb_oneofdef_issynthetic(o)) continue;
|
1075
|
+
|
1076
|
+
/* Calculate field size: the max of all field sizes. */
|
1077
|
+
for (upb_oneof_begin(&fit, o);
|
1078
|
+
!upb_oneof_done(&fit);
|
1079
|
+
upb_oneof_next(&fit)) {
|
1080
|
+
const upb_fielddef* f = upb_oneof_iter_field(&fit);
|
1081
|
+
field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f));
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
/* Align and allocate case offset. */
|
1085
|
+
case_offset = upb_msglayout_place(l, case_size);
|
1086
|
+
data_offset = upb_msglayout_place(l, field_size);
|
1087
|
+
|
1088
|
+
for (upb_oneof_begin(&fit, o);
|
1089
|
+
!upb_oneof_done(&fit);
|
1090
|
+
upb_oneof_next(&fit)) {
|
1091
|
+
const upb_fielddef* f = upb_oneof_iter_field(&fit);
|
1092
|
+
fields[upb_fielddef_index(f)].offset = data_offset;
|
1093
|
+
fields[upb_fielddef_index(f)].presence = ~case_offset;
|
1094
|
+
}
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
/* Size of the entire structure should be a multiple of its greatest
|
1098
|
+
* alignment. TODO: track overall alignment for real? */
|
1099
|
+
l->size = UPB_ALIGN_UP(l->size, 8);
|
1100
|
+
|
1101
|
+
/* Sort fields by number. */
|
1102
|
+
qsort(fields, upb_msgdef_numfields(m), sizeof(*fields), field_number_cmp);
|
1103
|
+
assign_layout_indices(m, fields);
|
1104
|
+
|
1105
|
+
return true;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
/* Code to build defs from descriptor protos. *********************************/
|
1109
|
+
|
1110
|
+
/* There is a question of how much validation to do here. It will be difficult
|
1111
|
+
* to perfectly match the amount of validation performed by proto2. But since
|
1112
|
+
* this code is used to directly build defs from Ruby (for example) we do need
|
1113
|
+
* to validate important constraints like uniqueness of names and numbers. */
|
1114
|
+
|
1115
|
+
#define CHK(x) if (!(x)) { return false; }
|
1116
|
+
#define CHK_OOM(x) if (!(x)) { upb_status_setoom(ctx->status); return false; }
|
1117
|
+
|
1118
|
+
typedef struct {
|
1119
|
+
const upb_symtab *symtab;
|
1120
|
+
upb_filedef *file; /* File we are building. */
|
1121
|
+
upb_alloc *alloc; /* Allocate defs here. */
|
1122
|
+
upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */
|
1123
|
+
upb_strtable *addtab; /* full_name -> packed def ptr for new defs */
|
1124
|
+
const upb_msglayout **layouts; /* NULL if we should build layouts. */
|
1125
|
+
upb_status *status; /* Record errors here. */
|
1126
|
+
} symtab_addctx;
|
1127
|
+
|
1128
|
+
static char* strviewdup(const symtab_addctx *ctx, upb_strview view) {
|
1129
|
+
return upb_strdup2(view.data, view.size, ctx->alloc);
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
static bool streql2(const char *a, size_t n, const char *b) {
|
1133
|
+
return n == strlen(b) && memcmp(a, b, n) == 0;
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
static bool streql_view(upb_strview view, const char *b) {
|
1137
|
+
return streql2(view.data, view.size, b);
|
1138
|
+
}
|
1139
|
+
|
1140
|
+
static const char *makefullname(const symtab_addctx *ctx, const char *prefix,
|
1141
|
+
upb_strview name) {
|
1142
|
+
if (prefix) {
|
1143
|
+
/* ret = prefix + '.' + name; */
|
1144
|
+
size_t n = strlen(prefix);
|
1145
|
+
char *ret = upb_malloc(ctx->alloc, n + name.size + 2);
|
1146
|
+
CHK_OOM(ret);
|
1147
|
+
strcpy(ret, prefix);
|
1148
|
+
ret[n] = '.';
|
1149
|
+
memcpy(&ret[n + 1], name.data, name.size);
|
1150
|
+
ret[n + 1 + name.size] = '\0';
|
1151
|
+
return ret;
|
1152
|
+
} else {
|
1153
|
+
return strviewdup(ctx, name);
|
1154
|
+
}
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
size_t getjsonname(const char *name, char *buf, size_t len) {
|
1158
|
+
size_t src, dst = 0;
|
1159
|
+
bool ucase_next = false;
|
1160
|
+
|
1161
|
+
#define WRITE(byte) \
|
1162
|
+
++dst; \
|
1163
|
+
if (dst < len) buf[dst - 1] = byte; \
|
1164
|
+
else if (dst == len) buf[dst - 1] = '\0'
|
1165
|
+
|
1166
|
+
if (!name) {
|
1167
|
+
WRITE('\0');
|
1168
|
+
return 0;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
/* Implement the transformation as described in the spec:
|
1172
|
+
* 1. upper case all letters after an underscore.
|
1173
|
+
* 2. remove all underscores.
|
1174
|
+
*/
|
1175
|
+
for (src = 0; name[src]; src++) {
|
1176
|
+
if (name[src] == '_') {
|
1177
|
+
ucase_next = true;
|
1178
|
+
continue;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
if (ucase_next) {
|
1182
|
+
WRITE(toupper(name[src]));
|
1183
|
+
ucase_next = false;
|
1184
|
+
} else {
|
1185
|
+
WRITE(name[src]);
|
1186
|
+
}
|
1187
|
+
}
|
1188
|
+
|
1189
|
+
WRITE('\0');
|
1190
|
+
return dst;
|
1191
|
+
|
1192
|
+
#undef WRITE
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
static char* makejsonname(const char* name, upb_alloc *alloc) {
|
1196
|
+
size_t size = getjsonname(name, NULL, 0);
|
1197
|
+
char* json_name = upb_malloc(alloc, size);
|
1198
|
+
getjsonname(name, json_name, size);
|
1199
|
+
return json_name;
|
1200
|
+
}
|
1201
|
+
|
1202
|
+
static bool symtab_add(const symtab_addctx *ctx, const char *name,
|
1203
|
+
upb_value v) {
|
1204
|
+
upb_value tmp;
|
1205
|
+
if (upb_strtable_lookup(ctx->addtab, name, &tmp) ||
|
1206
|
+
upb_strtable_lookup(&ctx->symtab->syms, name, &tmp)) {
|
1207
|
+
upb_status_seterrf(ctx->status, "duplicate symbol '%s'", name);
|
1208
|
+
return false;
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
CHK_OOM(upb_strtable_insert3(ctx->addtab, name, strlen(name), v, ctx->tmp));
|
1212
|
+
return true;
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
/* Given a symbol and the base symbol inside which it is defined, find the
|
1216
|
+
* symbol's definition in t. */
|
1217
|
+
static bool resolvename(const upb_strtable *t, const upb_fielddef *f,
|
1218
|
+
const char *base, upb_strview sym,
|
1219
|
+
upb_deftype_t type, upb_status *status,
|
1220
|
+
const void **def) {
|
1221
|
+
if(sym.size == 0) return false;
|
1222
|
+
if(sym.data[0] == '.') {
|
1223
|
+
/* Symbols starting with '.' are absolute, so we do a single lookup.
|
1224
|
+
* Slice to omit the leading '.' */
|
1225
|
+
upb_value v;
|
1226
|
+
if (!upb_strtable_lookup2(t, sym.data + 1, sym.size - 1, &v)) {
|
1227
|
+
return false;
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
*def = unpack_def(v, type);
|
1231
|
+
|
1232
|
+
if (!*def) {
|
1233
|
+
upb_status_seterrf(status,
|
1234
|
+
"type mismatch when resolving field %s, name %s",
|
1235
|
+
f->full_name, sym.data);
|
1236
|
+
return false;
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
return true;
|
1240
|
+
} else {
|
1241
|
+
/* Remove components from base until we find an entry or run out.
|
1242
|
+
* TODO: This branch is totally broken, but currently not used. */
|
1243
|
+
(void)base;
|
1244
|
+
UPB_ASSERT(false);
|
1245
|
+
return false;
|
1246
|
+
}
|
1247
|
+
}
|
1248
|
+
|
1249
|
+
const void *symtab_resolve(const symtab_addctx *ctx, const upb_fielddef *f,
|
1250
|
+
const char *base, upb_strview sym,
|
1251
|
+
upb_deftype_t type) {
|
1252
|
+
const void *ret;
|
1253
|
+
if (!resolvename(ctx->addtab, f, base, sym, type, ctx->status, &ret) &&
|
1254
|
+
!resolvename(&ctx->symtab->syms, f, base, sym, type, ctx->status, &ret)) {
|
1255
|
+
if (upb_ok(ctx->status)) {
|
1256
|
+
upb_status_seterrf(ctx->status, "couldn't resolve name '%s'", sym.data);
|
1257
|
+
}
|
1258
|
+
return false;
|
1259
|
+
}
|
1260
|
+
return ret;
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
static bool create_oneofdef(
|
1264
|
+
const symtab_addctx *ctx, upb_msgdef *m,
|
1265
|
+
const google_protobuf_OneofDescriptorProto *oneof_proto) {
|
1266
|
+
upb_oneofdef *o;
|
1267
|
+
upb_strview name = google_protobuf_OneofDescriptorProto_name(oneof_proto);
|
1268
|
+
upb_value v;
|
1269
|
+
|
1270
|
+
o = (upb_oneofdef*)&m->oneofs[m->oneof_count++];
|
1271
|
+
o->parent = m;
|
1272
|
+
o->full_name = makefullname(ctx, m->full_name, name);
|
1273
|
+
|
1274
|
+
v = pack_def(o, UPB_DEFTYPE_ONEOF);
|
1275
|
+
CHK_OOM(symtab_add(ctx, o->full_name, v));
|
1276
|
+
CHK_OOM(upb_strtable_insert3(&m->ntof, name.data, name.size, v, ctx->alloc));
|
1277
|
+
|
1278
|
+
CHK_OOM(upb_inttable_init2(&o->itof, UPB_CTYPE_CONSTPTR, ctx->alloc));
|
1279
|
+
CHK_OOM(upb_strtable_init2(&o->ntof, UPB_CTYPE_CONSTPTR, ctx->alloc));
|
1280
|
+
|
1281
|
+
return true;
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len,
|
1285
|
+
upb_fielddef *f) {
|
1286
|
+
char *end;
|
1287
|
+
char nullz[64];
|
1288
|
+
errno = 0;
|
1289
|
+
|
1290
|
+
switch (upb_fielddef_type(f)) {
|
1291
|
+
case UPB_TYPE_INT32:
|
1292
|
+
case UPB_TYPE_INT64:
|
1293
|
+
case UPB_TYPE_UINT32:
|
1294
|
+
case UPB_TYPE_UINT64:
|
1295
|
+
case UPB_TYPE_DOUBLE:
|
1296
|
+
case UPB_TYPE_FLOAT:
|
1297
|
+
/* Standard C number parsing functions expect null-terminated strings. */
|
1298
|
+
if (len >= sizeof(nullz) - 1) {
|
1299
|
+
return false;
|
1300
|
+
}
|
1301
|
+
memcpy(nullz, str, len);
|
1302
|
+
nullz[len] = '\0';
|
1303
|
+
str = nullz;
|
1304
|
+
break;
|
1305
|
+
default:
|
1306
|
+
break;
|
1307
|
+
}
|
1308
|
+
|
1309
|
+
switch (upb_fielddef_type(f)) {
|
1310
|
+
case UPB_TYPE_INT32: {
|
1311
|
+
long val = strtol(str, &end, 0);
|
1312
|
+
CHK(val <= INT32_MAX && val >= INT32_MIN && errno != ERANGE && !*end);
|
1313
|
+
f->defaultval.sint = val;
|
1314
|
+
break;
|
1315
|
+
}
|
1316
|
+
case UPB_TYPE_ENUM: {
|
1317
|
+
const upb_enumdef *e = f->sub.enumdef;
|
1318
|
+
int32_t val;
|
1319
|
+
CHK(upb_enumdef_ntoi(e, str, len, &val));
|
1320
|
+
f->defaultval.sint = val;
|
1321
|
+
break;
|
1322
|
+
}
|
1323
|
+
case UPB_TYPE_INT64: {
|
1324
|
+
/* XXX: Need to write our own strtoll, since it's not available in c89. */
|
1325
|
+
int64_t val = strtol(str, &end, 0);
|
1326
|
+
CHK(val <= INT64_MAX && val >= INT64_MIN && errno != ERANGE && !*end);
|
1327
|
+
f->defaultval.sint = val;
|
1328
|
+
break;
|
1329
|
+
}
|
1330
|
+
case UPB_TYPE_UINT32: {
|
1331
|
+
unsigned long val = strtoul(str, &end, 0);
|
1332
|
+
CHK(val <= UINT32_MAX && errno != ERANGE && !*end);
|
1333
|
+
f->defaultval.uint = val;
|
1334
|
+
break;
|
1335
|
+
}
|
1336
|
+
case UPB_TYPE_UINT64: {
|
1337
|
+
/* XXX: Need to write our own strtoull, since it's not available in c89. */
|
1338
|
+
uint64_t val = strtoul(str, &end, 0);
|
1339
|
+
CHK(val <= UINT64_MAX && errno != ERANGE && !*end);
|
1340
|
+
f->defaultval.uint = val;
|
1341
|
+
break;
|
1342
|
+
}
|
1343
|
+
case UPB_TYPE_DOUBLE: {
|
1344
|
+
double val = strtod(str, &end);
|
1345
|
+
CHK(errno != ERANGE && !*end);
|
1346
|
+
f->defaultval.dbl = val;
|
1347
|
+
break;
|
1348
|
+
}
|
1349
|
+
case UPB_TYPE_FLOAT: {
|
1350
|
+
/* XXX: Need to write our own strtof, since it's not available in c89. */
|
1351
|
+
float val = strtod(str, &end);
|
1352
|
+
CHK(errno != ERANGE && !*end);
|
1353
|
+
f->defaultval.flt = val;
|
1354
|
+
break;
|
1355
|
+
}
|
1356
|
+
case UPB_TYPE_BOOL: {
|
1357
|
+
if (streql2(str, len, "false")) {
|
1358
|
+
f->defaultval.boolean = false;
|
1359
|
+
} else if (streql2(str, len, "true")) {
|
1360
|
+
f->defaultval.boolean = true;
|
1361
|
+
} else {
|
1362
|
+
return false;
|
1363
|
+
}
|
1364
|
+
break;
|
1365
|
+
}
|
1366
|
+
case UPB_TYPE_STRING:
|
1367
|
+
f->defaultval.str = newstr(ctx->alloc, str, len);
|
1368
|
+
break;
|
1369
|
+
case UPB_TYPE_BYTES:
|
1370
|
+
/* XXX: need to interpret the C-escaped value. */
|
1371
|
+
f->defaultval.str = newstr(ctx->alloc, str, len);
|
1372
|
+
break;
|
1373
|
+
case UPB_TYPE_MESSAGE:
|
1374
|
+
/* Should not have a default value. */
|
1375
|
+
return false;
|
1376
|
+
}
|
1377
|
+
return true;
|
1378
|
+
}
|
1379
|
+
|
1380
|
+
static void set_default_default(const symtab_addctx *ctx, upb_fielddef *f) {
|
1381
|
+
switch (upb_fielddef_type(f)) {
|
1382
|
+
case UPB_TYPE_INT32:
|
1383
|
+
case UPB_TYPE_INT64:
|
1384
|
+
case UPB_TYPE_ENUM:
|
1385
|
+
f->defaultval.sint = 0;
|
1386
|
+
break;
|
1387
|
+
case UPB_TYPE_UINT64:
|
1388
|
+
case UPB_TYPE_UINT32:
|
1389
|
+
f->defaultval.uint = 0;
|
1390
|
+
break;
|
1391
|
+
case UPB_TYPE_DOUBLE:
|
1392
|
+
case UPB_TYPE_FLOAT:
|
1393
|
+
f->defaultval.dbl = 0;
|
1394
|
+
break;
|
1395
|
+
case UPB_TYPE_STRING:
|
1396
|
+
case UPB_TYPE_BYTES:
|
1397
|
+
f->defaultval.str = newstr(ctx->alloc, NULL, 0);
|
1398
|
+
break;
|
1399
|
+
case UPB_TYPE_BOOL:
|
1400
|
+
f->defaultval.boolean = false;
|
1401
|
+
break;
|
1402
|
+
case UPB_TYPE_MESSAGE:
|
1403
|
+
break;
|
1404
|
+
}
|
1405
|
+
}
|
1406
|
+
|
1407
|
+
static bool create_fielddef(
|
1408
|
+
const symtab_addctx *ctx, const char *prefix, upb_msgdef *m,
|
1409
|
+
const google_protobuf_FieldDescriptorProto *field_proto) {
|
1410
|
+
upb_alloc *alloc = ctx->alloc;
|
1411
|
+
upb_fielddef *f;
|
1412
|
+
const google_protobuf_FieldOptions *options;
|
1413
|
+
upb_strview name;
|
1414
|
+
const char *full_name;
|
1415
|
+
const char *json_name;
|
1416
|
+
const char *shortname;
|
1417
|
+
uint32_t field_number;
|
1418
|
+
|
1419
|
+
if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) {
|
1420
|
+
upb_status_seterrmsg(ctx->status, "field has no name");
|
1421
|
+
return false;
|
1422
|
+
}
|
1423
|
+
|
1424
|
+
name = google_protobuf_FieldDescriptorProto_name(field_proto);
|
1425
|
+
CHK(upb_isident(name, false, ctx->status));
|
1426
|
+
full_name = makefullname(ctx, prefix, name);
|
1427
|
+
shortname = shortdefname(full_name);
|
1428
|
+
|
1429
|
+
if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) {
|
1430
|
+
json_name = strviewdup(
|
1431
|
+
ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto));
|
1432
|
+
} else {
|
1433
|
+
json_name = makejsonname(shortname, ctx->alloc);
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
field_number = google_protobuf_FieldDescriptorProto_number(field_proto);
|
1437
|
+
|
1438
|
+
if (field_number == 0 || field_number > UPB_MAX_FIELDNUMBER) {
|
1439
|
+
upb_status_seterrf(ctx->status, "invalid field number (%u)", field_number);
|
1440
|
+
return false;
|
1441
|
+
}
|
1442
|
+
|
1443
|
+
if (m) {
|
1444
|
+
/* direct message field. */
|
1445
|
+
upb_value v, field_v, json_v;
|
1446
|
+
size_t json_size;
|
1447
|
+
|
1448
|
+
f = (upb_fielddef*)&m->fields[m->field_count++];
|
1449
|
+
f->msgdef = m;
|
1450
|
+
f->is_extension_ = false;
|
1451
|
+
|
1452
|
+
if (upb_strtable_lookup(&m->ntof, shortname, NULL)) {
|
1453
|
+
upb_status_seterrf(ctx->status, "duplicate field name (%s)", shortname);
|
1454
|
+
return false;
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
if (upb_strtable_lookup(&m->ntof, json_name, NULL)) {
|
1458
|
+
upb_status_seterrf(ctx->status, "duplicate json_name (%s)", json_name);
|
1459
|
+
return false;
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
if (upb_inttable_lookup(&m->itof, field_number, NULL)) {
|
1463
|
+
upb_status_seterrf(ctx->status, "duplicate field number (%u)",
|
1464
|
+
field_number);
|
1465
|
+
return false;
|
1466
|
+
}
|
1467
|
+
|
1468
|
+
field_v = pack_def(f, UPB_DEFTYPE_FIELD);
|
1469
|
+
json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME);
|
1470
|
+
v = upb_value_constptr(f);
|
1471
|
+
json_size = strlen(json_name);
|
1472
|
+
|
1473
|
+
CHK_OOM(
|
1474
|
+
upb_strtable_insert3(&m->ntof, name.data, name.size, field_v, alloc));
|
1475
|
+
CHK_OOM(upb_inttable_insert2(&m->itof, field_number, v, alloc));
|
1476
|
+
|
1477
|
+
if (strcmp(shortname, json_name) != 0) {
|
1478
|
+
upb_strtable_insert3(&m->ntof, json_name, json_size, json_v, alloc);
|
1479
|
+
}
|
1480
|
+
|
1481
|
+
if (ctx->layouts) {
|
1482
|
+
const upb_msglayout_field *fields = m->layout->fields;
|
1483
|
+
int count = m->layout->field_count;
|
1484
|
+
bool found = false;
|
1485
|
+
int i;
|
1486
|
+
for (i = 0; i < count; i++) {
|
1487
|
+
if (fields[i].number == field_number) {
|
1488
|
+
f->layout_index = i;
|
1489
|
+
found = true;
|
1490
|
+
break;
|
1491
|
+
}
|
1492
|
+
}
|
1493
|
+
UPB_ASSERT(found);
|
1494
|
+
}
|
1495
|
+
} else {
|
1496
|
+
/* extension field. */
|
1497
|
+
f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count++];
|
1498
|
+
f->is_extension_ = true;
|
1499
|
+
CHK_OOM(symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_FIELD)));
|
1500
|
+
}
|
1501
|
+
|
1502
|
+
f->full_name = full_name;
|
1503
|
+
f->json_name = json_name;
|
1504
|
+
f->file = ctx->file;
|
1505
|
+
f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto);
|
1506
|
+
f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto);
|
1507
|
+
f->number_ = field_number;
|
1508
|
+
f->oneof = NULL;
|
1509
|
+
f->proto3_optional_ =
|
1510
|
+
google_protobuf_FieldDescriptorProto_proto3_optional(field_proto);
|
1511
|
+
|
1512
|
+
/* We can't resolve the subdef or (in the case of extensions) the containing
|
1513
|
+
* message yet, because it may not have been defined yet. We stash a pointer
|
1514
|
+
* to the field_proto until later when we can properly resolve it. */
|
1515
|
+
f->sub.unresolved = field_proto;
|
1516
|
+
|
1517
|
+
if (f->label_ == UPB_LABEL_REQUIRED && f->file->syntax == UPB_SYNTAX_PROTO3) {
|
1518
|
+
upb_status_seterrf(ctx->status, "proto3 fields cannot be required (%s)",
|
1519
|
+
f->full_name);
|
1520
|
+
return false;
|
1521
|
+
}
|
1522
|
+
|
1523
|
+
if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) {
|
1524
|
+
int oneof_index =
|
1525
|
+
google_protobuf_FieldDescriptorProto_oneof_index(field_proto);
|
1526
|
+
upb_oneofdef *oneof;
|
1527
|
+
upb_value v = upb_value_constptr(f);
|
1528
|
+
|
1529
|
+
if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) {
|
1530
|
+
upb_status_seterrf(ctx->status,
|
1531
|
+
"fields in oneof must have OPTIONAL label (%s)",
|
1532
|
+
f->full_name);
|
1533
|
+
return false;
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
if (!m) {
|
1537
|
+
upb_status_seterrf(ctx->status,
|
1538
|
+
"oneof_index provided for extension field (%s)",
|
1539
|
+
f->full_name);
|
1540
|
+
return false;
|
1541
|
+
}
|
1542
|
+
|
1543
|
+
if (oneof_index >= m->oneof_count) {
|
1544
|
+
upb_status_seterrf(ctx->status, "oneof_index out of range (%s)",
|
1545
|
+
f->full_name);
|
1546
|
+
return false;
|
1547
|
+
}
|
1548
|
+
|
1549
|
+
oneof = (upb_oneofdef*)&m->oneofs[oneof_index];
|
1550
|
+
f->oneof = oneof;
|
1551
|
+
|
1552
|
+
CHK(upb_inttable_insert2(&oneof->itof, f->number_, v, alloc));
|
1553
|
+
CHK(upb_strtable_insert3(&oneof->ntof, name.data, name.size, v, alloc));
|
1554
|
+
} else {
|
1555
|
+
f->oneof = NULL;
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
options = google_protobuf_FieldDescriptorProto_has_options(field_proto) ?
|
1559
|
+
google_protobuf_FieldDescriptorProto_options(field_proto) : NULL;
|
1560
|
+
|
1561
|
+
if (options && google_protobuf_FieldOptions_has_packed(options)) {
|
1562
|
+
f->packed_ = google_protobuf_FieldOptions_packed(options);
|
1563
|
+
} else {
|
1564
|
+
/* Repeated fields default to packed for proto3 only. */
|
1565
|
+
f->packed_ = upb_fielddef_isprimitive(f) &&
|
1566
|
+
f->label_ == UPB_LABEL_REPEATED && f->file->syntax == UPB_SYNTAX_PROTO3;
|
1567
|
+
}
|
1568
|
+
|
1569
|
+
if (options) {
|
1570
|
+
f->lazy_ = google_protobuf_FieldOptions_lazy(options);
|
1571
|
+
} else {
|
1572
|
+
f->lazy_ = false;
|
1573
|
+
}
|
1574
|
+
|
1575
|
+
return true;
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
static bool create_enumdef(
|
1579
|
+
const symtab_addctx *ctx, const char *prefix,
|
1580
|
+
const google_protobuf_EnumDescriptorProto *enum_proto) {
|
1581
|
+
upb_enumdef *e;
|
1582
|
+
const google_protobuf_EnumValueDescriptorProto *const *values;
|
1583
|
+
upb_strview name;
|
1584
|
+
size_t i, n;
|
1585
|
+
|
1586
|
+
name = google_protobuf_EnumDescriptorProto_name(enum_proto);
|
1587
|
+
CHK(upb_isident(name, false, ctx->status));
|
1588
|
+
|
1589
|
+
e = (upb_enumdef*)&ctx->file->enums[ctx->file->enum_count++];
|
1590
|
+
e->full_name = makefullname(ctx, prefix, name);
|
1591
|
+
CHK_OOM(symtab_add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM)));
|
1592
|
+
|
1593
|
+
CHK_OOM(upb_strtable_init2(&e->ntoi, UPB_CTYPE_INT32, ctx->alloc));
|
1594
|
+
CHK_OOM(upb_inttable_init2(&e->iton, UPB_CTYPE_CSTR, ctx->alloc));
|
1595
|
+
|
1596
|
+
e->file = ctx->file;
|
1597
|
+
e->defaultval = 0;
|
1598
|
+
|
1599
|
+
values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n);
|
1600
|
+
|
1601
|
+
if (n == 0) {
|
1602
|
+
upb_status_seterrf(ctx->status,
|
1603
|
+
"enums must contain at least one value (%s)",
|
1604
|
+
e->full_name);
|
1605
|
+
return false;
|
1606
|
+
}
|
1607
|
+
|
1608
|
+
for (i = 0; i < n; i++) {
|
1609
|
+
const google_protobuf_EnumValueDescriptorProto *value = values[i];
|
1610
|
+
upb_strview name = google_protobuf_EnumValueDescriptorProto_name(value);
|
1611
|
+
char *name2 = strviewdup(ctx, name);
|
1612
|
+
int32_t num = google_protobuf_EnumValueDescriptorProto_number(value);
|
1613
|
+
upb_value v = upb_value_int32(num);
|
1614
|
+
|
1615
|
+
if (i == 0 && e->file->syntax == UPB_SYNTAX_PROTO3 && num != 0) {
|
1616
|
+
upb_status_seterrf(ctx->status,
|
1617
|
+
"for proto3, the first enum value must be zero (%s)",
|
1618
|
+
e->full_name);
|
1619
|
+
return false;
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
if (upb_strtable_lookup(&e->ntoi, name2, NULL)) {
|
1623
|
+
upb_status_seterrf(ctx->status, "duplicate enum label '%s'", name2);
|
1624
|
+
return false;
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
CHK_OOM(name2)
|
1628
|
+
CHK_OOM(
|
1629
|
+
upb_strtable_insert3(&e->ntoi, name2, strlen(name2), v, ctx->alloc));
|
1630
|
+
|
1631
|
+
if (!upb_inttable_lookup(&e->iton, num, NULL)) {
|
1632
|
+
upb_value v = upb_value_cstr(name2);
|
1633
|
+
CHK_OOM(upb_inttable_insert2(&e->iton, num, v, ctx->alloc));
|
1634
|
+
}
|
1635
|
+
}
|
1636
|
+
|
1637
|
+
upb_inttable_compact2(&e->iton, ctx->alloc);
|
1638
|
+
|
1639
|
+
return true;
|
1640
|
+
}
|
1641
|
+
|
1642
|
+
static bool create_msgdef(symtab_addctx *ctx, const char *prefix,
|
1643
|
+
const google_protobuf_DescriptorProto *msg_proto) {
|
1644
|
+
upb_msgdef *m;
|
1645
|
+
const google_protobuf_MessageOptions *options;
|
1646
|
+
const google_protobuf_OneofDescriptorProto *const *oneofs;
|
1647
|
+
const google_protobuf_FieldDescriptorProto *const *fields;
|
1648
|
+
const google_protobuf_EnumDescriptorProto *const *enums;
|
1649
|
+
const google_protobuf_DescriptorProto *const *msgs;
|
1650
|
+
size_t i, n;
|
1651
|
+
upb_strview name;
|
1652
|
+
|
1653
|
+
name = google_protobuf_DescriptorProto_name(msg_proto);
|
1654
|
+
CHK(upb_isident(name, false, ctx->status));
|
1655
|
+
|
1656
|
+
m = (upb_msgdef*)&ctx->file->msgs[ctx->file->msg_count++];
|
1657
|
+
m->full_name = makefullname(ctx, prefix, name);
|
1658
|
+
CHK_OOM(symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG)));
|
1659
|
+
|
1660
|
+
CHK_OOM(upb_inttable_init2(&m->itof, UPB_CTYPE_CONSTPTR, ctx->alloc));
|
1661
|
+
CHK_OOM(upb_strtable_init2(&m->ntof, UPB_CTYPE_CONSTPTR, ctx->alloc));
|
1662
|
+
|
1663
|
+
m->file = ctx->file;
|
1664
|
+
m->map_entry = false;
|
1665
|
+
|
1666
|
+
options = google_protobuf_DescriptorProto_options(msg_proto);
|
1667
|
+
|
1668
|
+
if (options) {
|
1669
|
+
m->map_entry = google_protobuf_MessageOptions_map_entry(options);
|
1670
|
+
}
|
1671
|
+
|
1672
|
+
if (ctx->layouts) {
|
1673
|
+
m->layout = *ctx->layouts;
|
1674
|
+
ctx->layouts++;
|
1675
|
+
} else {
|
1676
|
+
/* Allocate now (to allow cross-linking), populate later. */
|
1677
|
+
m->layout = upb_malloc(ctx->alloc, sizeof(*m->layout));
|
1678
|
+
}
|
1679
|
+
|
1680
|
+
oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n);
|
1681
|
+
m->oneof_count = 0;
|
1682
|
+
m->oneofs = upb_malloc(ctx->alloc, sizeof(*m->oneofs) * n);
|
1683
|
+
for (i = 0; i < n; i++) {
|
1684
|
+
CHK(create_oneofdef(ctx, m, oneofs[i]));
|
1685
|
+
}
|
1686
|
+
|
1687
|
+
fields = google_protobuf_DescriptorProto_field(msg_proto, &n);
|
1688
|
+
m->field_count = 0;
|
1689
|
+
m->fields = upb_malloc(ctx->alloc, sizeof(*m->fields) * n);
|
1690
|
+
for (i = 0; i < n; i++) {
|
1691
|
+
CHK(create_fielddef(ctx, m->full_name, m, fields[i]));
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
CHK(assign_msg_indices(m, ctx->status));
|
1695
|
+
CHK(check_oneofs(m, ctx->status));
|
1696
|
+
assign_msg_wellknowntype(m);
|
1697
|
+
upb_inttable_compact2(&m->itof, ctx->alloc);
|
1698
|
+
|
1699
|
+
/* This message is built. Now build nested messages and enums. */
|
1700
|
+
|
1701
|
+
enums = google_protobuf_DescriptorProto_enum_type(msg_proto, &n);
|
1702
|
+
for (i = 0; i < n; i++) {
|
1703
|
+
CHK(create_enumdef(ctx, m->full_name, enums[i]));
|
1704
|
+
}
|
1705
|
+
|
1706
|
+
msgs = google_protobuf_DescriptorProto_nested_type(msg_proto, &n);
|
1707
|
+
for (i = 0; i < n; i++) {
|
1708
|
+
CHK(create_msgdef(ctx, m->full_name, msgs[i]));
|
1709
|
+
}
|
1710
|
+
|
1711
|
+
return true;
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
typedef struct {
|
1715
|
+
int msg_count;
|
1716
|
+
int enum_count;
|
1717
|
+
int ext_count;
|
1718
|
+
} decl_counts;
|
1719
|
+
|
1720
|
+
static void count_types_in_msg(const google_protobuf_DescriptorProto *msg_proto,
|
1721
|
+
decl_counts *counts) {
|
1722
|
+
const google_protobuf_DescriptorProto *const *msgs;
|
1723
|
+
size_t i, n;
|
1724
|
+
|
1725
|
+
counts->msg_count++;
|
1726
|
+
|
1727
|
+
msgs = google_protobuf_DescriptorProto_nested_type(msg_proto, &n);
|
1728
|
+
for (i = 0; i < n; i++) {
|
1729
|
+
count_types_in_msg(msgs[i], counts);
|
1730
|
+
}
|
1731
|
+
|
1732
|
+
google_protobuf_DescriptorProto_enum_type(msg_proto, &n);
|
1733
|
+
counts->enum_count += n;
|
1734
|
+
|
1735
|
+
google_protobuf_DescriptorProto_extension(msg_proto, &n);
|
1736
|
+
counts->ext_count += n;
|
1737
|
+
}
|
1738
|
+
|
1739
|
+
static void count_types_in_file(
|
1740
|
+
const google_protobuf_FileDescriptorProto *file_proto,
|
1741
|
+
decl_counts *counts) {
|
1742
|
+
const google_protobuf_DescriptorProto *const *msgs;
|
1743
|
+
size_t i, n;
|
1744
|
+
|
1745
|
+
msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n);
|
1746
|
+
for (i = 0; i < n; i++) {
|
1747
|
+
count_types_in_msg(msgs[i], counts);
|
1748
|
+
}
|
1749
|
+
|
1750
|
+
google_protobuf_FileDescriptorProto_enum_type(file_proto, &n);
|
1751
|
+
counts->enum_count += n;
|
1752
|
+
|
1753
|
+
google_protobuf_FileDescriptorProto_extension(file_proto, &n);
|
1754
|
+
counts->ext_count += n;
|
1755
|
+
}
|
1756
|
+
|
1757
|
+
static bool resolve_fielddef(const symtab_addctx *ctx, const char *prefix,
|
1758
|
+
upb_fielddef *f) {
|
1759
|
+
upb_strview name;
|
1760
|
+
const google_protobuf_FieldDescriptorProto *field_proto = f->sub.unresolved;
|
1761
|
+
|
1762
|
+
if (f->is_extension_) {
|
1763
|
+
if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) {
|
1764
|
+
upb_status_seterrf(ctx->status,
|
1765
|
+
"extension for field '%s' had no extendee",
|
1766
|
+
f->full_name);
|
1767
|
+
return false;
|
1768
|
+
}
|
1769
|
+
|
1770
|
+
name = google_protobuf_FieldDescriptorProto_extendee(field_proto);
|
1771
|
+
f->msgdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_MSG);
|
1772
|
+
CHK(f->msgdef);
|
1773
|
+
}
|
1774
|
+
|
1775
|
+
if ((upb_fielddef_issubmsg(f) || f->type_ == UPB_DESCRIPTOR_TYPE_ENUM) &&
|
1776
|
+
!google_protobuf_FieldDescriptorProto_has_type_name(field_proto)) {
|
1777
|
+
upb_status_seterrf(ctx->status, "field '%s' is missing type name",
|
1778
|
+
f->full_name);
|
1779
|
+
return false;
|
1780
|
+
}
|
1781
|
+
|
1782
|
+
name = google_protobuf_FieldDescriptorProto_type_name(field_proto);
|
1783
|
+
|
1784
|
+
if (upb_fielddef_issubmsg(f)) {
|
1785
|
+
f->sub.msgdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_MSG);
|
1786
|
+
CHK(f->sub.msgdef);
|
1787
|
+
} else if (f->type_ == UPB_DESCRIPTOR_TYPE_ENUM) {
|
1788
|
+
f->sub.enumdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_ENUM);
|
1789
|
+
CHK(f->sub.enumdef);
|
1790
|
+
}
|
1791
|
+
|
1792
|
+
/* Have to delay resolving of the default value until now because of the enum
|
1793
|
+
* case, since enum defaults are specified with a label. */
|
1794
|
+
if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) {
|
1795
|
+
upb_strview defaultval =
|
1796
|
+
google_protobuf_FieldDescriptorProto_default_value(field_proto);
|
1797
|
+
|
1798
|
+
if (f->file->syntax == UPB_SYNTAX_PROTO3) {
|
1799
|
+
upb_status_seterrf(ctx->status,
|
1800
|
+
"proto3 fields cannot have explicit defaults (%s)",
|
1801
|
+
f->full_name);
|
1802
|
+
return false;
|
1803
|
+
}
|
1804
|
+
|
1805
|
+
if (upb_fielddef_issubmsg(f)) {
|
1806
|
+
upb_status_seterrf(ctx->status,
|
1807
|
+
"message fields cannot have explicit defaults (%s)",
|
1808
|
+
f->full_name);
|
1809
|
+
return false;
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
if (!parse_default(ctx, defaultval.data, defaultval.size, f)) {
|
1813
|
+
upb_status_seterrf(ctx->status,
|
1814
|
+
"couldn't parse default '" UPB_STRVIEW_FORMAT
|
1815
|
+
"' for field (%s)",
|
1816
|
+
UPB_STRVIEW_ARGS(defaultval), f->full_name);
|
1817
|
+
return false;
|
1818
|
+
}
|
1819
|
+
} else {
|
1820
|
+
set_default_default(ctx, f);
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
return true;
|
1824
|
+
}
|
1825
|
+
|
1826
|
+
static bool build_filedef(
|
1827
|
+
symtab_addctx *ctx, upb_filedef *file,
|
1828
|
+
const google_protobuf_FileDescriptorProto *file_proto) {
|
1829
|
+
upb_alloc *alloc = ctx->alloc;
|
1830
|
+
const google_protobuf_FileOptions *file_options_proto;
|
1831
|
+
const google_protobuf_DescriptorProto *const *msgs;
|
1832
|
+
const google_protobuf_EnumDescriptorProto *const *enums;
|
1833
|
+
const google_protobuf_FieldDescriptorProto *const *exts;
|
1834
|
+
const upb_strview* strs;
|
1835
|
+
size_t i, n;
|
1836
|
+
decl_counts counts = {0, 0, 0};
|
1837
|
+
|
1838
|
+
count_types_in_file(file_proto, &counts);
|
1839
|
+
|
1840
|
+
file->msgs = upb_malloc(alloc, sizeof(*file->msgs) * counts.msg_count);
|
1841
|
+
file->enums = upb_malloc(alloc, sizeof(*file->enums) * counts.enum_count);
|
1842
|
+
file->exts = upb_malloc(alloc, sizeof(*file->exts) * counts.ext_count);
|
1843
|
+
|
1844
|
+
CHK_OOM(counts.msg_count == 0 || file->msgs);
|
1845
|
+
CHK_OOM(counts.enum_count == 0 || file->enums);
|
1846
|
+
CHK_OOM(counts.ext_count == 0 || file->exts);
|
1847
|
+
|
1848
|
+
/* We increment these as defs are added. */
|
1849
|
+
file->msg_count = 0;
|
1850
|
+
file->enum_count = 0;
|
1851
|
+
file->ext_count = 0;
|
1852
|
+
|
1853
|
+
if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) {
|
1854
|
+
upb_status_seterrmsg(ctx->status, "File has no name");
|
1855
|
+
return false;
|
1856
|
+
}
|
1857
|
+
|
1858
|
+
file->name =
|
1859
|
+
strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto));
|
1860
|
+
file->phpprefix = NULL;
|
1861
|
+
file->phpnamespace = NULL;
|
1862
|
+
|
1863
|
+
if (google_protobuf_FileDescriptorProto_has_package(file_proto)) {
|
1864
|
+
upb_strview package =
|
1865
|
+
google_protobuf_FileDescriptorProto_package(file_proto);
|
1866
|
+
CHK(upb_isident(package, true, ctx->status));
|
1867
|
+
file->package = strviewdup(ctx, package);
|
1868
|
+
} else {
|
1869
|
+
file->package = NULL;
|
1870
|
+
}
|
1871
|
+
|
1872
|
+
if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) {
|
1873
|
+
upb_strview syntax =
|
1874
|
+
google_protobuf_FileDescriptorProto_syntax(file_proto);
|
1875
|
+
|
1876
|
+
if (streql_view(syntax, "proto2")) {
|
1877
|
+
file->syntax = UPB_SYNTAX_PROTO2;
|
1878
|
+
} else if (streql_view(syntax, "proto3")) {
|
1879
|
+
file->syntax = UPB_SYNTAX_PROTO3;
|
1880
|
+
} else {
|
1881
|
+
upb_status_seterrf(ctx->status, "Invalid syntax '" UPB_STRVIEW_FORMAT "'",
|
1882
|
+
UPB_STRVIEW_ARGS(syntax));
|
1883
|
+
return false;
|
1884
|
+
}
|
1885
|
+
} else {
|
1886
|
+
file->syntax = UPB_SYNTAX_PROTO2;
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
/* Read options. */
|
1890
|
+
file_options_proto = google_protobuf_FileDescriptorProto_options(file_proto);
|
1891
|
+
if (file_options_proto) {
|
1892
|
+
if (google_protobuf_FileOptions_has_php_class_prefix(file_options_proto)) {
|
1893
|
+
file->phpprefix = strviewdup(
|
1894
|
+
ctx,
|
1895
|
+
google_protobuf_FileOptions_php_class_prefix(file_options_proto));
|
1896
|
+
}
|
1897
|
+
if (google_protobuf_FileOptions_has_php_namespace(file_options_proto)) {
|
1898
|
+
file->phpnamespace = strviewdup(
|
1899
|
+
ctx, google_protobuf_FileOptions_php_namespace(file_options_proto));
|
1900
|
+
}
|
1901
|
+
}
|
1902
|
+
|
1903
|
+
/* Verify dependencies. */
|
1904
|
+
strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n);
|
1905
|
+
file->deps = upb_malloc(alloc, sizeof(*file->deps) * n) ;
|
1906
|
+
CHK_OOM(n == 0 || file->deps);
|
1907
|
+
|
1908
|
+
for (i = 0; i < n; i++) {
|
1909
|
+
upb_strview dep_name = strs[i];
|
1910
|
+
upb_value v;
|
1911
|
+
if (!upb_strtable_lookup2(&ctx->symtab->files, dep_name.data,
|
1912
|
+
dep_name.size, &v)) {
|
1913
|
+
upb_status_seterrf(ctx->status,
|
1914
|
+
"Depends on file '" UPB_STRVIEW_FORMAT
|
1915
|
+
"', but it has not been loaded",
|
1916
|
+
UPB_STRVIEW_ARGS(dep_name));
|
1917
|
+
return false;
|
1918
|
+
}
|
1919
|
+
file->deps[i] = upb_value_getconstptr(v);
|
1920
|
+
}
|
1921
|
+
|
1922
|
+
/* Create messages. */
|
1923
|
+
msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n);
|
1924
|
+
for (i = 0; i < n; i++) {
|
1925
|
+
CHK(create_msgdef(ctx, file->package, msgs[i]));
|
1926
|
+
}
|
1927
|
+
|
1928
|
+
/* Create enums. */
|
1929
|
+
enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n);
|
1930
|
+
for (i = 0; i < n; i++) {
|
1931
|
+
CHK(create_enumdef(ctx, file->package, enums[i]));
|
1932
|
+
}
|
1933
|
+
|
1934
|
+
/* Create extensions. */
|
1935
|
+
exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n);
|
1936
|
+
file->exts = upb_malloc(alloc, sizeof(*file->exts) * n);
|
1937
|
+
CHK_OOM(n == 0 || file->exts);
|
1938
|
+
for (i = 0; i < n; i++) {
|
1939
|
+
CHK(create_fielddef(ctx, file->package, NULL, exts[i]));
|
1940
|
+
}
|
1941
|
+
|
1942
|
+
/* Now that all names are in the table, build layouts and resolve refs. */
|
1943
|
+
for (i = 0; i < (size_t)file->ext_count; i++) {
|
1944
|
+
CHK(resolve_fielddef(ctx, file->package, (upb_fielddef*)&file->exts[i]));
|
1945
|
+
}
|
1946
|
+
|
1947
|
+
for (i = 0; i < (size_t)file->msg_count; i++) {
|
1948
|
+
const upb_msgdef *m = &file->msgs[i];
|
1949
|
+
int j;
|
1950
|
+
for (j = 0; j < m->field_count; j++) {
|
1951
|
+
CHK(resolve_fielddef(ctx, m->full_name, (upb_fielddef*)&m->fields[j]));
|
1952
|
+
}
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
if (!ctx->layouts) {
|
1956
|
+
for (i = 0; i < (size_t)file->msg_count; i++) {
|
1957
|
+
const upb_msgdef *m = &file->msgs[i];
|
1958
|
+
make_layout(ctx->symtab, m);
|
1959
|
+
}
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
return true;
|
1963
|
+
}
|
1964
|
+
|
1965
|
+
static bool upb_symtab_addtotabs(upb_symtab *s, symtab_addctx *ctx) {
|
1966
|
+
const upb_filedef *file = ctx->file;
|
1967
|
+
upb_alloc *alloc = upb_arena_alloc(s->arena);
|
1968
|
+
upb_strtable_iter iter;
|
1969
|
+
|
1970
|
+
CHK_OOM(upb_strtable_insert3(&s->files, file->name, strlen(file->name),
|
1971
|
+
upb_value_constptr(file), alloc));
|
1972
|
+
|
1973
|
+
upb_strtable_begin(&iter, ctx->addtab);
|
1974
|
+
for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
|
1975
|
+
upb_strview key = upb_strtable_iter_key(&iter);
|
1976
|
+
upb_value value = upb_strtable_iter_value(&iter);
|
1977
|
+
CHK_OOM(upb_strtable_insert3(&s->syms, key.data, key.size, value, alloc));
|
1978
|
+
}
|
1979
|
+
|
1980
|
+
return true;
|
1981
|
+
}
|
1982
|
+
|
1983
|
+
/* upb_filedef ****************************************************************/
|
1984
|
+
|
1985
|
+
const char *upb_filedef_name(const upb_filedef *f) {
|
1986
|
+
return f->name;
|
1987
|
+
}
|
1988
|
+
|
1989
|
+
const char *upb_filedef_package(const upb_filedef *f) {
|
1990
|
+
return f->package;
|
1991
|
+
}
|
1992
|
+
|
1993
|
+
const char *upb_filedef_phpprefix(const upb_filedef *f) {
|
1994
|
+
return f->phpprefix;
|
1995
|
+
}
|
1996
|
+
|
1997
|
+
const char *upb_filedef_phpnamespace(const upb_filedef *f) {
|
1998
|
+
return f->phpnamespace;
|
1999
|
+
}
|
2000
|
+
|
2001
|
+
upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
|
2002
|
+
return f->syntax;
|
2003
|
+
}
|
2004
|
+
|
2005
|
+
int upb_filedef_msgcount(const upb_filedef *f) {
|
2006
|
+
return f->msg_count;
|
2007
|
+
}
|
2008
|
+
|
2009
|
+
int upb_filedef_depcount(const upb_filedef *f) {
|
2010
|
+
return f->dep_count;
|
2011
|
+
}
|
2012
|
+
|
2013
|
+
int upb_filedef_enumcount(const upb_filedef *f) {
|
2014
|
+
return f->enum_count;
|
2015
|
+
}
|
2016
|
+
|
2017
|
+
const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) {
|
2018
|
+
return i < 0 || i >= f->dep_count ? NULL : f->deps[i];
|
2019
|
+
}
|
2020
|
+
|
2021
|
+
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) {
|
2022
|
+
return i < 0 || i >= f->msg_count ? NULL : &f->msgs[i];
|
2023
|
+
}
|
2024
|
+
|
2025
|
+
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) {
|
2026
|
+
return i < 0 || i >= f->enum_count ? NULL : &f->enums[i];
|
2027
|
+
}
|
2028
|
+
|
2029
|
+
void upb_symtab_free(upb_symtab *s) {
|
2030
|
+
upb_arena_free(s->arena);
|
2031
|
+
upb_gfree(s);
|
2032
|
+
}
|
2033
|
+
|
2034
|
+
upb_symtab *upb_symtab_new(void) {
|
2035
|
+
upb_symtab *s = upb_gmalloc(sizeof(*s));
|
2036
|
+
upb_alloc *alloc;
|
2037
|
+
|
2038
|
+
if (!s) {
|
2039
|
+
return NULL;
|
2040
|
+
}
|
2041
|
+
|
2042
|
+
s->arena = upb_arena_new();
|
2043
|
+
alloc = upb_arena_alloc(s->arena);
|
2044
|
+
|
2045
|
+
if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, alloc) ||
|
2046
|
+
!upb_strtable_init2(&s->files, UPB_CTYPE_CONSTPTR, alloc)) {
|
2047
|
+
upb_arena_free(s->arena);
|
2048
|
+
upb_gfree(s);
|
2049
|
+
s = NULL;
|
2050
|
+
}
|
2051
|
+
return s;
|
2052
|
+
}
|
2053
|
+
|
2054
|
+
const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) {
|
2055
|
+
upb_value v;
|
2056
|
+
return upb_strtable_lookup(&s->syms, sym, &v) ?
|
2057
|
+
unpack_def(v, UPB_DEFTYPE_MSG) : NULL;
|
2058
|
+
}
|
2059
|
+
|
2060
|
+
const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym,
|
2061
|
+
size_t len) {
|
2062
|
+
upb_value v;
|
2063
|
+
return upb_strtable_lookup2(&s->syms, sym, len, &v) ?
|
2064
|
+
unpack_def(v, UPB_DEFTYPE_MSG) : NULL;
|
2065
|
+
}
|
2066
|
+
|
2067
|
+
const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) {
|
2068
|
+
upb_value v;
|
2069
|
+
return upb_strtable_lookup(&s->syms, sym, &v) ?
|
2070
|
+
unpack_def(v, UPB_DEFTYPE_ENUM) : NULL;
|
2071
|
+
}
|
2072
|
+
|
2073
|
+
const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name) {
|
2074
|
+
upb_value v;
|
2075
|
+
return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v)
|
2076
|
+
: NULL;
|
2077
|
+
}
|
2078
|
+
|
2079
|
+
const upb_filedef *upb_symtab_lookupfile2(
|
2080
|
+
const upb_symtab *s, const char *name, size_t len) {
|
2081
|
+
upb_value v;
|
2082
|
+
return upb_strtable_lookup2(&s->files, name, len, &v) ?
|
2083
|
+
upb_value_getconstptr(v) : NULL;
|
2084
|
+
}
|
2085
|
+
|
2086
|
+
int upb_symtab_filecount(const upb_symtab *s) {
|
2087
|
+
return (int)upb_strtable_count(&s->files);
|
2088
|
+
}
|
2089
|
+
|
2090
|
+
static const upb_filedef *_upb_symtab_addfile(
|
2091
|
+
upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto,
|
2092
|
+
const upb_msglayout **layouts, upb_status *status) {
|
2093
|
+
upb_arena *tmparena = upb_arena_new();
|
2094
|
+
upb_strtable addtab;
|
2095
|
+
upb_alloc *alloc = upb_arena_alloc(s->arena);
|
2096
|
+
upb_filedef *file = upb_malloc(alloc, sizeof(*file));
|
2097
|
+
bool ok;
|
2098
|
+
symtab_addctx ctx;
|
2099
|
+
|
2100
|
+
ctx.file = file;
|
2101
|
+
ctx.symtab = s;
|
2102
|
+
ctx.alloc = alloc;
|
2103
|
+
ctx.tmp = upb_arena_alloc(tmparena);
|
2104
|
+
ctx.addtab = &addtab;
|
2105
|
+
ctx.layouts = layouts;
|
2106
|
+
ctx.status = status;
|
2107
|
+
|
2108
|
+
ok = file && upb_strtable_init2(&addtab, UPB_CTYPE_CONSTPTR, ctx.tmp) &&
|
2109
|
+
build_filedef(&ctx, file, file_proto) && upb_symtab_addtotabs(s, &ctx);
|
2110
|
+
|
2111
|
+
upb_arena_free(tmparena);
|
2112
|
+
return ok ? file : NULL;
|
2113
|
+
}
|
2114
|
+
|
2115
|
+
const upb_filedef *upb_symtab_addfile(
|
2116
|
+
upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto,
|
2117
|
+
upb_status *status) {
|
2118
|
+
return _upb_symtab_addfile(s, file_proto, NULL, status);
|
2119
|
+
}
|
2120
|
+
|
2121
|
+
/* Include here since we want most of this file to be stdio-free. */
|
2122
|
+
#include <stdio.h>
|
2123
|
+
|
2124
|
+
bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) {
|
2125
|
+
/* Since this function should never fail (it would indicate a bug in upb) we
|
2126
|
+
* print errors to stderr instead of returning error status to the user. */
|
2127
|
+
upb_def_init **deps = init->deps;
|
2128
|
+
google_protobuf_FileDescriptorProto *file;
|
2129
|
+
upb_arena *arena;
|
2130
|
+
upb_status status;
|
2131
|
+
|
2132
|
+
upb_status_clear(&status);
|
2133
|
+
|
2134
|
+
if (upb_strtable_lookup(&s->files, init->filename, NULL)) {
|
2135
|
+
return true;
|
2136
|
+
}
|
2137
|
+
|
2138
|
+
arena = upb_arena_new();
|
2139
|
+
|
2140
|
+
for (; *deps; deps++) {
|
2141
|
+
if (!_upb_symtab_loaddefinit(s, *deps)) goto err;
|
2142
|
+
}
|
2143
|
+
|
2144
|
+
file = google_protobuf_FileDescriptorProto_parse(
|
2145
|
+
init->descriptor.data, init->descriptor.size, arena);
|
2146
|
+
|
2147
|
+
if (!file) {
|
2148
|
+
upb_status_seterrf(
|
2149
|
+
&status,
|
2150
|
+
"Failed to parse compiled-in descriptor for file '%s'. This should "
|
2151
|
+
"never happen.",
|
2152
|
+
init->filename);
|
2153
|
+
goto err;
|
2154
|
+
}
|
2155
|
+
|
2156
|
+
if (!_upb_symtab_addfile(s, file, init->layouts, &status)) goto err;
|
2157
|
+
|
2158
|
+
upb_arena_free(arena);
|
2159
|
+
return true;
|
2160
|
+
|
2161
|
+
err:
|
2162
|
+
fprintf(stderr, "Error loading compiled-in descriptor: %s\n",
|
2163
|
+
upb_status_errmsg(&status));
|
2164
|
+
upb_arena_free(arena);
|
2165
|
+
return false;
|
2166
|
+
}
|
2167
|
+
|
2168
|
+
#undef CHK
|
2169
|
+
#undef CHK_OOM
|