1 /***
2 * ==++==
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * ==--==
17 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
18 *
19 * URI parsing implementation
20 *
21 * For the latest on this and related APIs, please see http://casablanca.codeplex.com.
22 *
23 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
24 ****/
25
26 #pragma once
27
28 #include <string>
29
30 namespace web {
namespace details
31 {
32 namespace uri_parser
33 {
34
40 bool validate(const utility::string_t &encoded_string);
41
49 bool parse(const utility::string_t &encoded_string, uri_components &components);
50
61 inline bool is_unreserved(int c)
62 {
63 return ::utility::details::is_alnum((char)c) || c == '-' || c == '.' || c == '_' || c == '~';
64 }
65
71 inline bool is_gen_delim(int c)
72 {
73 return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' || c == ']' || c == '@';
74 }
75
82 inline bool is_sub_delim(int c)
83 {
84 switch (c)
85 {
86 case '!':
87 case '$':
88 case '&':
89 case '\'':
90 case '(':
91 case ')':
92 case '*':
93 case '+':
94 case ',':
95 case ';':
96 case '=':
97 return true;
98 default:
99 return false;
100 }
101 }
102
107 inline bool is_reserved(int c)
108 {
109 return is_gen_delim(c) || is_sub_delim(c);
110 }
111
121 inline bool is_scheme_character(int c)
122 {
123 return ::utility::details::is_alnum((char)c) || c == '+' || c == '-' || c == '.';
124 }
125
133 inline bool is_user_info_character(int c)
134 {
135 return is_unreserved(c) || is_sub_delim(c) || c == '%' || c == ':';
136 }
137
147 inline bool is_host_character(int c)
148 {
149 return is_unreserved(c) || is_sub_delim(c) || c == '%' || c == ':' || c == '[' || c == ']';
150 }
151
162 inline bool is_authority_character(int c)
163 {
164 return is_unreserved(c) || is_sub_delim(c) || c == '%' || c == '@' || c == ':';
165 }
166
175 inline bool is_path_character(int c)
176 {
177 return is_unreserved(c) || is_sub_delim(c) || c == '%' || c == '/' || c == ':' || c == '@';
178 }
179
185 inline bool is_query_character(int c)
186 {
187 return is_path_character(c) || c == '?';
188 }
189
195 inline bool is_fragment_character(int c)
196 {
197 // this is intentional, they have the same set of legal characters
198 return is_query_character(c);
199 }
200
205 bool inner_parse(
206 const utility::char_t *encoded,
207 const utility::char_t **scheme_begin, const utility::char_t **scheme_end,
208 const utility::char_t **uinfo_begin, const utility::char_t **uinfo_end,
209 const utility::char_t **host_begin, const utility::char_t **host_end,
210 _Out_ int *port,
211 const utility::char_t **path_begin, const utility::char_t **path_end,
212 const utility::char_t **query_begin, const utility::char_t **query_end,
213 const utility::char_t **fragment_begin, const utility::char_t **fragment_end);
214 }
215 }}
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37