Mstdlib-1.24.0
m_url.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2022 Monetra Technologies, LLC.
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 deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * 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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_URL_H__
25#define __M_URL_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29__BEGIN_DECLS
30
31/*! \addtogroup m_url URL
32 * \ingroup m_formats
33 * URL Parser.
34 *
35 * This parser supports many of the features of RFC 3986, but is not
36 * a fully compliant URI parser.
37 *
38 * Specifically from RFC3986 section 1.1.2:
39 *
40 * SUPPORTED?
41 *
42 * - YES ftp://ftp.is.co.za/rfc/rfc1808.txt
43 * - YES http://www.ietf.org/rfc/rfc2396.txt
44 * - YES ldap://[2001:db8::7]/c=GB?objectClass?one
45 * - NO mailto:John.Doe@example.com
46 * - NO news:comp.infosystems.www.servers.unix
47 * - NO tel:+1-816-555-1212
48 * - YES telnet://192.0.2.16:80/
49 * - NO urn:oasis:names:specification:docbook:dtd:xml:4.1.2
50 * - YES http://http:%2f%2fhttp:%2f%2f@http://http://?http://#http://
51 *
52 * @{
53 */
54
55struct M_url;
56typedef struct M_url M_url_t;
57
58
59/*! Parse URL string into structure parts.
60 *
61 * \param[in] url_str URL string to be parsed.
62 *
63 * \return Parsed URL struct or NULL on error.
64 */
65M_API M_url_t *M_url_create(const char *url_str);
66
67/*! Getter function
68 *
69 * \param[in] url parsed URL.
70 *
71 * \return schema string (NULL if none)
72 */
73M_API const char *M_url_schema(M_url_t *url);
74
75/*! Getter function
76 *
77 * \param[in] url parsed URL.
78 *
79 * \return host string (NULL if none)
80 */
81M_API const char *M_url_host(M_url_t *url);
82
83/*! Getter function
84 *
85 * \param[in] url parsed URL.
86 *
87 * \return port string (NULL if none)
88 */
89M_API const char *M_url_port(M_url_t *url);
90
91/*! Getter function
92 *
93 * \param[in] url parsed URL.
94 *
95 * \return path string (NULL if none)
96 */
97M_API const char *M_url_path(M_url_t *url);
98
99/*! Getter function
100 *
101 * \param[in] url parsed URL.
102 *
103 * \return query string (NULL if none)
104 */
105M_API const char *M_url_query(M_url_t *url);
106
107/*! Getter function
108 *
109 * \param[in] url parsed URL.
110 *
111 * \return fragment string (NULL if none)
112 */
113M_API const char *M_url_fragment(M_url_t *url);
114
115/*! Getter function
116 *
117 * \param[in] url parsed URL.
118 *
119 * \return userinfo string (NULL if none)
120 */
121M_API const char *M_url_userinfo(M_url_t *url);
122
123/*! Getter function
124 *
125 * \param[in] url parsed URL.
126 *
127 * \return port as M_uint16 (0 if none)
128 */
129M_API M_uint16 M_url_port_u16(M_url_t *url);
130
131/*! Destroy parsed URL struct
132 *
133 * \param[in] url struct to destroy
134 */
135M_API void M_url_destroy(M_url_t *url);
136
137/*! @} */
138
139__END_DECLS
140
141#endif
M_uint16 M_url_port_u16(M_url_t *url)
const char * M_url_path(M_url_t *url)
const char * M_url_userinfo(M_url_t *url)
const char * M_url_query(M_url_t *url)
struct M_url M_url_t
Definition: m_url.h:56
const char * M_url_fragment(M_url_t *url)
void M_url_destroy(M_url_t *url)
const char * M_url_host(M_url_t *url)
const char * M_url_schema(M_url_t *url)
M_url_t * M_url_create(const char *url_str)
const char * M_url_port(M_url_t *url)