Asterisk - The Open Source Telephony Project  18.5.0
uri.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2014, Digium, Inc.
5  *
6  * Kevin Harwell <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 #ifndef _ASTERISK_URI_H
20 #define _ASTERISK_URI_H
21 
22 /*! \brief Opaque structure that stores uri information. */
23 struct ast_uri;
24 
25 /*!
26  * \brief Create a uri with the given parameters
27  *
28  * \param scheme the uri scheme (ex: http)
29  * \param user_info user credentials (ex: <name>@<pass>)
30  * \param host host name or ip address
31  * \param port the port
32  * \param path the path
33  * \param query query parameters
34  * \return a structure containing parsed uri data.
35  * \return \c NULL on error
36  * \since 13
37  */
38 struct ast_uri *ast_uri_create(const char *scheme, const char *user_info,
39  const char *host, const char *port,
40  const char *path, const char *query);
41 
42 /*!
43  * \brief Copy the given uri replacing any value in the new uri with
44  * any given.
45  *
46  * \param uri the uri object to copy
47  * \param scheme the uri scheme (ex: http)
48  * \param user_info user credentials (ex: <name>@<pass>)
49  * \param host host name or ip address
50  * \param port the port
51  * \param path the path
52  * \param query query parameters
53  * \return a copy of the given uri with specified values replaced.
54  * \return \c NULL on error
55  * \since 13
56  */
57 struct ast_uri *ast_uri_copy_replace(const struct ast_uri *uri, const char *scheme,
58  const char *user_info, const char *host,
59  const char *port, const char *path,
60  const char *query);
61 /*!
62  * \brief Retrieve the uri scheme.
63  *
64  * \return the uri scheme.
65  * \since 13
66  */
67 const char *ast_uri_scheme(const struct ast_uri *uri);
68 
69 /*!
70  * \brief Retrieve the uri user information.
71  *
72  * \return the uri user information.
73  * \since 13
74  */
75 const char *ast_uri_user_info(const struct ast_uri *uri);
76 
77 /*!
78  * \brief Retrieve the uri host.
79  *
80  * \return the uri host.
81  * \since 13
82  */
83 const char *ast_uri_host(const struct ast_uri *uri);
84 
85 /*!
86  * \brief Retrieve the uri port
87  *
88  * \return the uri port.
89  * \since 13
90  */
91 const char *ast_uri_port(const struct ast_uri *uri);
92 
93 /*!
94  * \brief Retrieve the uri path.
95  *
96  * \return the uri path.
97  * \since 13
98  */
99 const char *ast_uri_path(const struct ast_uri *uri);
100 
101 /*!
102  * \brief Retrieve the uri query parameters.
103  *
104  * \return the uri query parameters.
105  * \since 13
106  */
107 const char *ast_uri_query(const struct ast_uri *uri);
108 
109 /*!
110  * \brief Retrieve if the uri is of a secure type
111  *
112  * \note Secure types are recognized by an 's' at the end
113  * of the scheme.
114  *
115  * \return True if secure, False otherwise.
116  * \since 13
117  */
118 int attribute_pure ast_uri_is_secure(const struct ast_uri *uri);
119 
120 /*!
121  * \brief Parse the given uri into a structure.
122  *
123  * \note Expects the following form:
124  * <scheme>://[user:pass@]<host>[:port][/<path>]
125  *
126  * \param uri a string uri to parse
127  * \return a structure containing parsed uri data.
128  * \return \c NULL on error
129  * \since 13
130  */
131 struct ast_uri *ast_uri_parse(const char *uri);
132 
133 /*!
134  * \brief Parse the given http uri into a structure.
135  *
136  * \note Expects the following form:
137  * [http[s]://][user:pass@]<host>[:port][/<path>]
138  *
139  * \note If no scheme is given it defaults to 'http' and if
140  * no port is specified it will default to 443 if marked
141  * secure, otherwise to 80.
142  *
143  * \param uri an http string uri to parse
144  * \return a structure containing parsed http uri data.
145  * \return \c NULL on error
146  * \since 13
147  */
148 struct ast_uri *ast_uri_parse_http(const char *uri);
149 
150 /*!
151  * \brief Parse the given websocket uri into a structure.
152  *
153  * \note Expects the following form:
154  * [ws[s]://][user:pass@]<host>[:port][/<path>]
155  *
156  * \note If no scheme is given it defaults to 'ws' and if
157  * no port is specified it will default to 443 if marked
158  * secure, otherwise to 80.
159  *
160  * \param uri a websocket string uri to parse
161  * \return a structure containing parsed http uri data.
162  * \return \c NULL on error
163  * \since 13
164  */
165 struct ast_uri *ast_uri_parse_websocket(const char *uri);
166 
167 /*!
168  * \brief Retrieve a string of the host and port.
169  *
170  * \detail Combine the host and port (<host>:<port>) if the port
171  * is available, otherwise just return the host.
172  *
173  * \note Caller is responsible for release the returned string.
174  *
175  * \param uri the uri object
176  * \return a string value of the host and optional port.
177  * \since 13
178  */
179 char *ast_uri_make_host_with_port(const struct ast_uri *uri);
180 
181 #endif /* _ASTERISK_URI_H */
#define attribute_pure
Definition: compiler.h:35
char * scheme
Definition: uri.c:32
const char * ast_uri_path(const struct ast_uri *uri)
Retrieve the uri path.
Definition: uri.c:135
Stores parsed uri information.
Definition: uri.c:30
struct ast_uri * ast_uri_parse(const char *uri)
Parse the given uri into a structure.
Definition: uri.c:152
char * user_info
Definition: uri.c:34
char * port
Definition: uri.c:38
const char * ast_uri_query(const struct ast_uri *uri)
Retrieve the uri query parameters.
Definition: uri.c:140
const char * ast_uri_user_info(const struct ast_uri *uri)
Retrieve the uri user information.
Definition: uri.c:120
struct ast_uri * ast_uri_copy_replace(const struct ast_uri *uri, const char *scheme, const char *user_info, const char *host, const char *port, const char *path, const char *query)
Copy the given uri replacing any value in the new uri with any given.
Definition: uri.c:101
char * path
Definition: uri.c:40
struct ast_uri * ast_uri_parse_http(const char *uri)
Parse the given http uri into a structure.
Definition: uri.c:290
static char host[256]
Definition: muted.c:77
int attribute_pure ast_uri_is_secure(const struct ast_uri *uri)
Retrieve if the uri is of a secure type.
Definition: uri.c:145
struct ast_uri * ast_uri_create(const char *scheme, const char *user_info, const char *host, const char *port, const char *path, const char *query)
Create a uri with the given parameters.
Definition: uri.c:88
char * ast_uri_make_host_with_port(const struct ast_uri *uri)
Retrieve a string of the host and port.
Definition: uri.c:300
const char * ast_uri_port(const struct ast_uri *uri)
Retrieve the uri port.
Definition: uri.c:130
char * query
Definition: uri.c:42
char uri[0]
Definition: uri.c:44
const char * ast_uri_scheme(const struct ast_uri *uri)
Retrieve the uri scheme.
Definition: uri.c:115
struct ast_uri * ast_uri_parse_websocket(const char *uri)
Parse the given websocket uri into a structure.
Definition: uri.c:295
const char * ast_uri_host(const struct ast_uri *uri)
Retrieve the uri host.
Definition: uri.c:125