26 #include <uriparser/Uri.h> 55 const char *
scheme,
unsigned int scheme_size,
56 const char *
user_info,
unsigned int user_info_size,
57 const char *
host,
unsigned int host_size,
58 const char *
port,
unsigned int port_size,
59 const char *
path,
unsigned int path_size,
60 const char *
query,
unsigned int query_size)
62 #define SET_VALUE(param, field, size) \ 64 ast_copy_string(p, param, size); \ 66 p += size; } } while (0) 70 sizeof(*res) + scheme_size + user_info_size + host_size +
71 port_size + path_size + query_size,
NULL);
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);
107 scheme ? scheme : uri->
scheme,
109 host ? host : uri->
host,
110 port ? port : uri->
port,
111 path ? path : uri->
path,
112 query ? query : uri->
query);
151 #ifdef HAVE_URIPARSER 154 UriParserStateA
state;
157 unsigned int scheme_size, user_info_size, host_size;
158 unsigned int port_size, path_size, query_size;
159 const char *path_start, *path_end;
162 if (uriParseUriA(&state, uri) != URI_SUCCESS) {
164 uriFreeUriMembersA(&uria);
168 scheme_size = uria.scheme.first ?
169 uria.scheme.afterLast - uria.scheme.first + 1 : 0;
170 user_info_size = uria.userInfo.first ?
171 uria.userInfo.afterLast - uria.userInfo.first + 1 : 0;
172 host_size = uria.hostText.first ?
173 uria.hostText.afterLast - uria.hostText.first + 1 : 0;
174 port_size = uria.portText.first ?
175 uria.portText.afterLast - uria.portText.first + 1 : 0;
177 path_start = uria.pathHead && uria.pathHead->text.first ?
178 uria.pathHead->text.first :
NULL;
179 path_end = path_start ? uria.pathTail->text.afterLast :
NULL;
180 path_size = path_end ? path_end - path_start + 1 : 0;
182 query_size = uria.query.first ?
183 uria.query.afterLast - uria.query.first + 1 : 0;
186 uria.userInfo.first, user_info_size,
187 uria.hostText.first, host_size,
188 uria.portText.first, port_size,
189 path_start, path_size,
190 uria.query.first, query_size);
191 uriFreeUriMembersA(&uria);
197 #define SET_VALUES(value) \ 199 size_##value = p - uri + 1; \ 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;
207 if ((p = strstr(uri,
"://"))) {
209 size_scheme = p - uri + 1;
213 if ((p = strchr(uri,
'@'))) {
214 SET_VALUES(user_info);
217 if ((p = strchr(uri,
':'))) {
221 if ((p = strchr(uri,
'/'))) {
229 if ((p = strchr(uri,
'?'))) {
231 size_query = strlen(query) + 1;
233 p = uri + strlen(uri);
238 }
else if (*(uri - 1) ==
':') {
240 }
else if (*(uri - 1) ==
'/') {
245 user_info, size_user_info,
254 const char *
port,
const char *secure_port)
257 int len = strlen(scheme);
259 if (!strncmp(uri, scheme, len)) {
263 char *with_scheme =
ast_malloc(len + strlen(uri) + 4);
266 "scheme '%s'", uri, scheme);
273 sprintf(with_scheme,
"%s://%s", scheme, uri);
307 char *res =
ast_malloc(host_size + port_size + 1);
316 res[host_size] =
':';
317 memcpy(res + host_size + 1,
321 res[host_size + port_size] =
'\0';
struct ast_uri * ast_uri_parse_http(const char *uri)
Parse the given http uri into a structure.
enum sip_cc_notify_state state
Asterisk main include file. File version handling, generic pbx functions.
String manipulation functions.
char * ast_uri_make_host_with_port(const struct ast_uri *uri)
Retrieve a string of the host and port.
Stores parsed uri information.
int ast_uri_is_secure(const struct ast_uri *uri)
Retrieve if the uri is of a secure type.
const char * ast_uri_port(const struct ast_uri *uri)
Retrieve the uri port.
#define ast_strlen_zero(foo)
const char * ast_uri_query(const struct ast_uri *uri)
Retrieve the uri query parameters.
#define SET_VALUE(param, field, size)
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.
#define ao2_ref(o, delta)
#define ast_malloc(len)
A wrapper for malloc()
const char * ast_uri_host(const struct ast_uri *uri)
Retrieve the uri host.
struct ast_uri * ast_uri_parse_websocket(const char *uri)
Parse the given websocket uri into a structure.
const char * ast_uri_path(const struct ast_uri *uri)
Retrieve the uri path.
struct ast_uri * ast_uri_parse(const char *uri)
Parse the given uri into a structure.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ao2_alloc(data_size, destructor_fn)
const char * ast_uri_user_info(const struct ast_uri *uri)
Retrieve the uri user information.
static struct ast_uri * uri_parse_and_default(const char *uri, const char *scheme, const char *port, const char *secure_port)
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.
const char * ast_uri_scheme(const struct ast_uri *uri)
Retrieve the uri scheme.
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.