Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions
uri.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct ast_uriast_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. More...
 
struct ast_uriast_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. More...
 
const char * ast_uri_host (const struct ast_uri *uri)
 Retrieve the uri host. More...
 
int attribute_pure ast_uri_is_secure (const struct ast_uri *uri)
 Retrieve if the uri is of a secure type. More...
 
char * ast_uri_make_host_with_port (const struct ast_uri *uri)
 Retrieve a string of the host and port. More...
 
struct ast_uriast_uri_parse (const char *uri)
 Parse the given uri into a structure. More...
 
struct ast_uriast_uri_parse_http (const char *uri)
 Parse the given http uri into a structure. More...
 
struct ast_uriast_uri_parse_websocket (const char *uri)
 Parse the given websocket uri into a structure. More...
 
const char * ast_uri_path (const struct ast_uri *uri)
 Retrieve the uri path. More...
 
const char * ast_uri_port (const struct ast_uri *uri)
 Retrieve the uri port. More...
 
const char * ast_uri_query (const struct ast_uri *uri)
 Retrieve the uri query parameters. More...
 
const char * ast_uri_scheme (const struct ast_uri *uri)
 Retrieve the uri scheme. More...
 
const char * ast_uri_user_info (const struct ast_uri *uri)
 Retrieve the uri user information. More...
 

Function Documentation

◆ ast_uri_copy_replace()

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.

Parameters
urithe uri object to copy
schemethe uri scheme (ex: http)
user_infouser credentials (ex: <name>@<pass>)
hosthost name or ip address
portthe port
paththe path
queryquery parameters
Returns
a copy of the given uri with specified values replaced.
Return values
NULLon error
Since
13

Definition at line 101 of file uri.c.

105{
106 return ast_uri_create(
107 scheme ? scheme : uri->scheme,
108 user_info ? user_info : uri->user_info,
109 host ? host : uri->host,
110 port ? port : uri->port,
111 path ? path : uri->path,
112 query ? query : uri->query);
113}
char * host
Definition: uri.c:36
char * path
Definition: uri.c:40
char * user_info
Definition: uri.c:34
char * scheme
Definition: uri.c:32
char * port
Definition: uri.c:38
char * query
Definition: uri.c:42
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

References ast_uri_create(), ast_uri::host, ast_uri::path, ast_uri::port, ast_uri::query, ast_uri::scheme, ast_uri::uri, and ast_uri::user_info.

Referenced by uri_parse_and_default().

◆ ast_uri_create()

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.

Parameters
schemethe uri scheme (ex: http)
user_infouser credentials (ex: <name>@<pass>)
hosthost name or ip address
portthe port
paththe path
queryquery parameters
Returns
a structure containing parsed uri data.
Return values
NULLon error
Since
13

Definition at line 88 of file uri.c.

91{
92 return ast_uri_create_(
93 scheme, scheme ? strlen(scheme) + 1 : 0,
94 user_info, user_info ? strlen(user_info) + 1 : 0,
95 host, host ? strlen(host) + 1 : 0,
96 port, port ? strlen(port) + 1 : 0,
97 path, path ? strlen(path) + 1 : 0,
98 query, query ? strlen(query) + 1 : 0);
99}
static struct ast_uri * ast_uri_create_(const char *scheme, unsigned int scheme_size, const char *user_info, unsigned int user_info_size, const char *host, unsigned int host_size, const char *port, unsigned int port_size, const char *path, unsigned int path_size, const char *query, unsigned int query_size)
Construct a uri object with the given values.
Definition: uri.c:54

References ast_uri_create_(), ast_uri::host, ast_uri::path, ast_uri::port, ast_uri::query, ast_uri::scheme, and ast_uri::user_info.

Referenced by ast_uri_copy_replace().

◆ ast_uri_host()

const char * ast_uri_host ( const struct ast_uri uri)

Retrieve the uri host.

Returns
the uri host.
Since
13

Definition at line 125 of file uri.c.

126{
127 return uri->host;
128}

References ast_uri::uri.

Referenced by AST_TEST_DEFINE(), and ast_uri_make_host_with_port().

◆ ast_uri_is_secure()

int attribute_pure ast_uri_is_secure ( const struct ast_uri uri)

Retrieve if the uri is of a secure type.

Note
Secure types are recognized by an 's' at the end of the scheme.
Return values
Trueif secure.
Falseotherwise.
Since
13

Definition at line 145 of file uri.c.

146{
147 return ast_strlen_zero(uri->scheme) ? 0 :
148 *(uri->scheme + strlen(uri->scheme) - 1) == 's';
149}
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_strlen_zero(), and ast_uri::uri.

Referenced by AST_TEST_DEFINE(), and uri_parse_and_default().

◆ ast_uri_make_host_with_port()

char * ast_uri_make_host_with_port ( const struct ast_uri uri)

Retrieve a string of the host and port.

Combine the host and port (<host>:<port>) if the port is available, otherwise just return the host.

Note
Caller is responsible for release the returned string.
Parameters
urithe uri object
Returns
a string value of the host and optional port.
Since
13

Definition at line 300 of file uri.c.

301{
302 char *res;
303
304 if (ast_asprintf(&res, "%s%s%s",
305 ast_uri_host(uri) ?: "",
306 ast_uri_port(uri) ? ":" : "",
307 ast_uri_port(uri) ?: "") == -1) {
308 return NULL;
309 }
310
311 return res;
312}
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define NULL
Definition: resample.c:96
const char * ast_uri_port(const struct ast_uri *uri)
Retrieve the uri port.
Definition: uri.c:130
const char * ast_uri_host(const struct ast_uri *uri)
Retrieve the uri host.
Definition: uri.c:125

References ast_asprintf, ast_uri_host(), ast_uri_port(), NULL, and ast_uri::uri.

Referenced by websocket_client_parse_uri().

◆ ast_uri_parse()

struct ast_uri * ast_uri_parse ( const char *  uri)

Parse the given uri into a structure.

Note
Expects the following form:
<scheme>://[user:pass@]<host>[:port][/<path>] 
Parameters
uria string uri to parse
Returns
a structure containing parsed uri data.
Return values
NULLon error
Since
13

Definition at line 195 of file uri.c.

196{
197#define SET_VALUES(value) \
198 value = uri; \
199 size_##value = p - uri + 1; \
200 uri = p + 1;
201
202 const char *p, *scheme = NULL, *user_info = NULL, *host = NULL;
203 const char *port = NULL, *path = NULL, *query = NULL;
204 unsigned int size_scheme = 0, size_user_info = 0, size_host = 0;
205 unsigned int size_port = 0, size_path = 0, size_query = 0;
206
207 if ((p = strstr(uri, "://"))) {
208 scheme = uri;
209 size_scheme = p - uri + 1;
210 uri = p + 3;
211 }
212
213 if ((p = strchr(uri, '@'))) {
214 SET_VALUES(user_info);
215 }
216
217 if ((p = strchr(uri, ':'))) {
218 SET_VALUES(host);
219 }
220
221 if ((p = strchr(uri, '/'))) {
222 if (!host) {
223 SET_VALUES(host);
224 } else {
225 SET_VALUES(port);
226 }
227 }
228
229 if ((p = strchr(uri, '?'))) {
230 query = p + 1;
231 size_query = strlen(query) + 1;
232 } else {
233 p = uri + strlen(uri);
234 }
235
236 if (!host) {
237 SET_VALUES(host);
238 } else if (*(uri - 1) == ':') {
239 SET_VALUES(port);
240 } else if (*(uri - 1) == '/') {
241 SET_VALUES(path);
242 }
243
244 return ast_uri_create_(scheme, size_scheme,
245 user_info, size_user_info,
246 host, size_host,
247 port, size_port,
248 path, size_path,
249 query, size_query);
250}
#define SET_VALUES(value)

References ast_uri_create_(), ast_uri::host, NULL, ast_uri::path, ast_uri::port, ast_uri::query, ast_uri::scheme, SET_VALUES, ast_uri::uri, and ast_uri::user_info.

Referenced by AST_TEST_DEFINE(), file_extension_from_url_path(), and uri_parse_and_default().

◆ ast_uri_parse_http()

struct ast_uri * ast_uri_parse_http ( const char *  uri)

Parse the given http uri into a structure.

Note
Expects the following form:
[http[s]://][user:pass@]<host>[:port][/<path>] 
If no scheme is given it defaults to 'http' and if no port is specified it will default to 443 if marked secure, otherwise to 80.
Parameters
urian http string uri to parse
Returns
a structure containing parsed http uri data.
Return values
NULLon error
Since
13

Definition at line 290 of file uri.c.

291{
292 return uri_parse_and_default(uri, "http", "80", "443");
293}
static struct ast_uri * uri_parse_and_default(const char *uri, const char *scheme, const char *port, const char *secure_port)
Definition: uri.c:253

References ast_uri::uri, and uri_parse_and_default().

Referenced by AST_TEST_DEFINE().

◆ ast_uri_parse_websocket()

struct ast_uri * ast_uri_parse_websocket ( const char *  uri)

Parse the given websocket uri into a structure.

Note
Expects the following form:
If no scheme is given it defaults to 'ws' and if no port is specified it will default to 443 if marked secure, otherwise to 80.
Parameters
uria websocket string uri to parse
Returns
a structure containing parsed http uri data.
Return values
NULLon error
Since
13

Definition at line 295 of file uri.c.

296{
297 return uri_parse_and_default(uri, "ws", "80", "443");
298}

References ast_uri::uri, and uri_parse_and_default().

Referenced by websocket_client_parse_uri().

◆ ast_uri_path()

const char * ast_uri_path ( const struct ast_uri uri)

Retrieve the uri path.

Returns
the uri path.
Since
13

Definition at line 135 of file uri.c.

136{
137 return uri->path;
138}

References ast_uri::uri.

Referenced by AST_TEST_DEFINE(), file_extension_from_url_path(), and websocket_client_parse_uri().

◆ ast_uri_port()

const char * ast_uri_port ( const struct ast_uri uri)

Retrieve the uri port.

Returns
the uri port.
Since
13

Definition at line 130 of file uri.c.

131{
132 return uri->port;
133}

References ast_uri::uri.

Referenced by AST_TEST_DEFINE(), ast_uri_make_host_with_port(), and uri_parse_and_default().

◆ ast_uri_query()

const char * ast_uri_query ( const struct ast_uri uri)

Retrieve the uri query parameters.

Returns
the uri query parameters.
Since
13

Definition at line 140 of file uri.c.

141{
142 return uri->query;
143}

References ast_uri::uri.

Referenced by AST_TEST_DEFINE(), and websocket_client_parse_uri().

◆ ast_uri_scheme()

const char * ast_uri_scheme ( const struct ast_uri uri)

Retrieve the uri scheme.

Returns
the uri scheme.
Since
13

Definition at line 115 of file uri.c.

116{
117 return uri->scheme;
118}

References ast_uri::uri.

Referenced by AST_TEST_DEFINE().

◆ ast_uri_user_info()

const char * ast_uri_user_info ( const struct ast_uri uri)

Retrieve the uri user information.

Returns
the uri user information.
Since
13

Definition at line 120 of file uri.c.

121{
122 return uri->user_info;
123}

References ast_uri::uri.

Referenced by AST_TEST_DEFINE().