// // Copyright 2015 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include <grpc/support/port_platform.h> #include "src/core/lib/uri/uri_parser.h" #include <ctype.h> #include <stddef.h> #include <algorithm> #include <functional> #include <initializer_list> #include <map> #include <string> #include <utility> #include "absl/status/status.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" #include "absl/strings/strip.h" #include <grpc/support/log.h> namespace grpc_core { namespace { // Returns true for any sub-delim character, as defined in: // https://datatracker.ietf.org/doc/html/rfc3986#section-2.2 bool IsSubDelimChar(char c) { … } // Returns true for any unreserved character, as defined in: // https://datatracker.ietf.org/doc/html/rfc3986#section-2.3 bool IsUnreservedChar(char c) { … } // Returns true for any character in scheme, as defined in: // https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 bool IsSchemeChar(char c) { … } // Returns true for any character in authority, as defined in: // https://datatracker.ietf.org/doc/html/rfc3986#section-3.2 bool IsAuthorityChar(char c) { … } // Returns true for any character in pchar, as defined in: // https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 bool IsPChar(char c) { … } // Returns true for any character allowed in a URI path, as defined in: // https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 bool IsPathChar(char c) { … } // Returns true for any character allowed in a URI query or fragment, // as defined in: // See https://tools.ietf.org/html/rfc3986#section-3.4 bool IsQueryOrFragmentChar(char c) { … } // Same as IsQueryOrFragmentChar(), but excludes '&' and '='. bool IsQueryKeyOrValueChar(char c) { … } // Returns a copy of str, percent-encoding any character for which // is_allowed_char() returns false. std::string PercentEncode(absl::string_view str, std::function<bool(char)> is_allowed_char) { … } // Checks if this string is made up of query/fragment chars and '%' exclusively. // See https://tools.ietf.org/html/rfc3986#section-3.4 bool IsQueryOrFragmentString(absl::string_view str) { … } absl::Status MakeInvalidURIStatus(absl::string_view part_name, absl::string_view uri, absl::string_view extra) { … } } // namespace std::string URI::PercentEncodeAuthority(absl::string_view str) { … } std::string URI::PercentEncodePath(absl::string_view str) { … } // Similar to `grpc_permissive_percent_decode_slice`, this %-decodes all valid // triplets, and passes through the rest verbatim. std::string URI::PercentDecode(absl::string_view str) { … } absl::StatusOr<URI> URI::Parse(absl::string_view uri_text) { … } absl::StatusOr<URI> URI::Create(std::string scheme, std::string authority, std::string path, std::vector<QueryParam> query_parameter_pairs, std::string fragment) { … } URI::URI(std::string scheme, std::string authority, std::string path, std::vector<QueryParam> query_parameter_pairs, std::string fragment) : … { … } URI::URI(const URI& other) : … { … } URI& URI::operator=(const URI& other) { … } namespace { // A pair formatter for use with absl::StrJoin() for formatting query params. struct QueryParameterFormatter { … }; } // namespace std::string URI::ToString() const { … } } // namespace grpc_core