Line data Source code
1 0 : /* SPDX-License-Identifier: MIT */
2 :
3 : /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
4 : *
5 : * Permission is hereby granted, free of charge, to any person obtaining a copy
6 : * of this software and associated documentation files (the "Software"), to
7 : * deal in the Software without restriction, including without limitation the
8 : * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 : * sell copies of the Software, and to permit persons to whom the Software is
10 : * furnished to do so, subject to the following conditions:
11 : *
12 : * The above copyright notice and this permission notice shall be included in
13 : * all copies or substantial portions of the Software.
14 : *
15 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 : * IN THE SOFTWARE.
22 : */
23 : #ifndef ZEPHYR_INCLUDE_NET_HTTP_PARSER_URL_H_
24 : #define ZEPHYR_INCLUDE_NET_HTTP_PARSER_URL_H_
25 :
26 : #include <sys/types.h>
27 : #include <zephyr/types.h>
28 : #include <stddef.h>
29 : #include <zephyr/net/http/parser_state.h>
30 :
31 : #ifdef __cplusplus
32 : extern "C" {
33 : #endif
34 :
35 0 : enum http_parser_url_fields {
36 : UF_SCHEMA = 0
37 : , UF_HOST = 1
38 : , UF_PORT = 2
39 : , UF_PATH = 3
40 : , UF_QUERY = 4
41 : , UF_FRAGMENT = 5
42 : , UF_USERINFO = 6
43 : , UF_MAX = 7
44 : };
45 :
46 : /* Result structure for http_parser_url_fields().
47 : *
48 : * Callers should index into field_data[] with UF_* values iff field_set
49 : * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
50 : * because we probably have padding left over), we convert any port to
51 : * a uint16_t.
52 : */
53 0 : struct http_parser_url {
54 0 : uint16_t field_set; /* Bitmask of (1 << UF_*) values */
55 0 : uint16_t port; /* Converted UF_PORT string */
56 :
57 : struct {
58 0 : uint16_t off; /* Offset into buffer in which field
59 : * starts
60 : */
61 0 : uint16_t len; /* Length of run in buffer */
62 0 : } field_data[UF_MAX];
63 : };
64 :
65 0 : enum state parse_url_char(enum state s, const char ch);
66 :
67 : /* Initialize all http_parser_url members to 0 */
68 0 : void http_parser_url_init(struct http_parser_url *u);
69 :
70 : /* Parse a URL; return nonzero on failure */
71 0 : int http_parser_parse_url(const char *buf, size_t buflen,
72 : int is_connect, struct http_parser_url *u);
73 :
74 : #ifdef __cplusplus
75 : }
76 : #endif
77 : #endif
|