69#define DEFAULT_PORT 8088
70#define DEFAULT_TLS_PORT 8089
71#define DEFAULT_SESSION_LIMIT 100
73#define DEFAULT_SESSION_INACTIVITY 30000
75#define MIN_INITIAL_REQUEST_TIMEOUT 10000
77#define DEFAULT_SESSION_KEEP_ALIVE 15000
79#define MAX_SERVER_NAME_LENGTH 128
81#define DEFAULT_RESPONSE_HEADER_LENGTH 512
84#if !defined(LOW_MEMORY)
85#define MAX_CONTENT_LENGTH 40960
87#define MAX_CONTENT_LENGTH 1024
91#if !defined(LOW_MEMORY)
92#define INITIAL_RESPONSE_BODY_BUFFER 1024
94#define INITIAL_RESPONSE_BODY_BUFFER 512
98#if !defined(LOW_MEMORY)
99#define MAX_HTTP_LINE_LENGTH 4096
101#define MAX_HTTP_LINE_LENGTH 1024
136 .name =
"https server",
153 {
"png",
"image/png" },
154 {
"xml",
"text/xml" },
155 {
"jpg",
"image/jpeg" },
156 {
"js",
"application/x-javascript" },
157 {
"wav",
"audio/x-wav" },
158 {
"mp3",
"audio/mpeg" },
159 {
"svg",
"image/svg+xml" },
160 {
"svgz",
"image/svg+xml" },
161 {
"gif",
"image/gif" },
162 {
"html",
"text/html" },
163 {
"htm",
"text/html" },
164 {
"css",
"text/css" },
165 {
"cnf",
"text/plain" },
166 {
"cfg",
"text/plain" },
167 {
"bin",
"application/octet-stream" },
168 {
"sbn",
"application/octet-stream" },
169 {
"ld",
"application/octet-stream" },
239 for (v = cookies; v; v = v->
next) {
240 if (!strcasecmp(v->
name,
"mansession_id")) {
241 sscanf(v->
value,
"%30x", &mngid);
271 char timebuf[80], etag[23];
273 int not_modified = 0;
276 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
291 if ((uri[0] < 33) || strchr(
"./|~@#$%^&*() \t", uri[0])) {
295 if (strstr(uri,
"/..")) {
299 if ((ftype = strrchr(uri,
'.'))) {
304 snprintf(wkspace,
sizeof(wkspace),
"text/%s",
S_OR(ftype,
"plain"));
315 if (stat(path, &st)) {
319 if (S_ISDIR(st.st_mode)) {
327 fd = open(path, O_RDONLY);
333 snprintf(etag,
sizeof(etag),
"\"%ld\"", (
long)st.st_mtime);
336 tv.tv_sec = st.st_mtime;
341 for (v = headers; v; v = v->
next) {
342 if (!strcasecmp(v->
name,
"If-None-Match")) {
343 if (!strcasecmp(v->
value, etag)) {
358 ast_str_set(&http_header, 0,
"Content-type: %s\r\n"
360 "Last-Modified: %s\r\n",
375 ast_http_error(ser, 404,
"Not Found",
"The requested URL was not found on this server.");
380 ast_http_error(ser, 403,
"Access Denied",
"You do not have permission to access the requested URL.");
386 const char *cur =
in;
421 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
433 "<html><title>Asterisk HTTP Status</title>\r\n"
434 "<body bgcolor=\"#ffffff\">\r\n"
435 "<table bgcolor=\"#f1f1f1\" align=\"center\"><tr><td bgcolor=\"#e0e0ff\" colspan=\"2\" width=\"500\">\r\n"
436 "<h2> Asterisk™ HTTP Status</h2></td></tr>\r\n");
441 ast_str_append(&
out, 0,
"<tr><td><i>Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
445 ast_str_append(&
out, 0,
"<tr><td><i>TLS Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
449 for (v = get_vars; v; v = v->
next) {
459 for (v = cookies; v; v = v->
next) {
468 ast_str_append(&
out, 0,
"</table><center><font size=\"-1\"><i>Asterisk and Digium are registered trademarks of Digium, Inc.</i></font></center></body></html>\r\n");
475 .description =
"Asterisk HTTP General Status",
484 .description =
"Asterisk HTTP Static Delivery",
511 unsigned int static_content)
518 int content_length = 0;
519 int close_connection;
523 if (!ser || !server_header_field) {
546 close_connection = 1;
554 close_connection = 1;
556 close_connection = 0;
568 content_length += lseek(fd, 0, SEEK_END);
569 lseek(fd, 0, SEEK_SET);
582 "Content-Length: %d\r\n"
585 status_code, status_title ? status_title :
"OK",
588 close_connection ?
"Connection: close\r\n" :
"",
589 static_content ?
"" :
"Cache-Control: no-cache, no-store\r\n",
594 ast_debug(1,
"ast_iostream_printf() failed: %s\n", strerror(
errno));
595 close_connection = 1;
596 }
else if (send_content && fd) {
598 while ((
len = read(fd,
buf,
sizeof(
buf))) > 0) {
600 ast_debug(1,
"ast_iostream_write() failed: %s\n", strerror(
errno));
601 close_connection = 1;
611 if (close_connection) {
612 ast_debug(1,
"HTTP closing session. status_code:%d\n", status_code);
615 ast_debug(1,
"HTTP keeping session open. status_code:%d\n", status_code);
620 const char *status_title,
struct ast_str *http_header_data,
const char *text)
626 if (!http_header_data || !server_address || !
out) {
631 ast_debug(1,
"HTTP closing session. OOM.\n");
641 "<address>%s</address>\r\n",
647 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
649 "<title>%d %s</title>\r\n"
655 "</body></html>\r\n",
675 const unsigned long nonce,
const unsigned long opaque,
int stale,
678 int status_code = 401;
679 char *status_title =
"Unauthorized";
682 if (http_header_data) {
685 "WWW-authenticate: Digest algorithm=MD5, realm=\"%s\", nonce=\"%08lx\", qop=\"auth\", opaque=\"%08lx\"%s\r\n"
686 "Content-type: text/html\r\n",
687 realm ? realm :
"Asterisk",
690 stale ?
", stale=true" :
"");
701 const char *status_title,
const char *text)
705 if (http_header_data) {
706 ast_str_set(&http_header_data, 0,
"Content-type: text/html\r\n");
728 int len = strlen(urih->
uri);
769 if (!strcmp(urih->
key,
key)) {
795 for (v = headers; v; v = v->
next) {
796 if (!strcasecmp(v->
name, field_name)) {
816 const char *content_type =
get_header(headers,
"Content-Type");
824 param = strchr(content_type,
';');
825 size = param ? param - content_type : strlen(content_type);
841 const char *content_length =
get_header(headers,
"Content-Length");
844 if (!content_length) {
850 if (sscanf(content_length,
"%30d", &length) != 1) {
866 return get_header(headers,
"Transfer-Encoding");
880 const char *connection =
get_header(headers,
"Connection");
881 int close_connection = 0;
883 if (connection && !strcasecmp(connection,
"close")) {
884 close_connection = -1;
886 return close_connection;
925 const char *transfer_encoding;
932 if (transfer_encoding && !strcasecmp(transfer_encoding,
"chunked")) {
939 if (0 <
request->body_length) {
941 }
else if (
request->body_length < 0) {
944 ast_http_error(ser, 400,
"Bad Request",
"Invalid Content-Length in request!");
985 while (
total != length) {
994 if (
total != length) {
996 what_getting, length, res);
1022 what_getting, length, res);
1056 if (*s++ ==
'\x0D') {
1063 if (
c >=
'0' &&
c <=
'9') {
1067 if (
c >=
'a' &&
c <=
'f') {
1071 if (
c >=
'A' &&
c <=
'F') {
1102 length =
chunked_atoh(header_line, strlen(header_line));
1127 if (res <
sizeof(chunk_sync)) {
1129 sizeof(chunk_sync));
1132 if (chunk_sync[0] != 0x0D || chunk_sync[1] != 0x0A) {
1134 (
unsigned char) chunk_sync[0], (
unsigned char) chunk_sync[1]);
1183 ast_debug(1,
"HTTP discarding unused request body\n");
1186 if (0 <
request->body_length) {
1253 ast_debug(2,
"HTTP consuming request body\n");
1256 if (0 <
request->body_length) {
1258 content_length =
request->body_length;
1280 buf[content_length] = 0;
1281 *return_length = content_length;
1299 if (chunk_length < 0) {
1305 if (chunk_length == 0) {
1311 "Excessively long HTTP accumulated chunked body. (%d + %d > %d)\n",
1320 if (content_length + chunk_length >= bufsize) {
1326 }
while (content_length + chunk_length >= bufsize);
1344 content_length += chunk_length;
1361 buf[content_length] = 0;
1362 *return_length = content_length;
1369 int content_length = 0;
1383 if (!
buf || !content_length) {
1406 const char *content_type)
1415 strcasecmp(content_type,
"application/x-www-form-urlencoded") != 0) {
1444 int content_length = 0;
1452 strcasecmp(
type,
"application/x-www-form-urlencoded")) {
1458 if (!
buf || !content_length) {
1480 ast_debug(2,
"HTTP Request URI is %s \n", uri);
1508 if (!strcasecmp(uri, redirect->
target)) {
1528 if (!strncasecmp(uri,
prefix, l) && uri[l] ==
'/') {
1533 l = strlen(urih->
uri);
1535 ast_debug(2,
"match request [%s] with handler [%s] len %d\n", uri, urih->
uri, l);
1536 if (strncasecmp(urih->
uri, uri, l)
1537 || (*
c && *
c !=
'/')) {
1557 ast_debug(1,
"Request from %s for URI [%s] has no registered handler\n",
1559 ast_http_error(ser, 404,
"Not Found",
"The requested URL was not found on this server.");
1573 while ((cur =
strsep(&parse,
";"))) {
1605 for (v = headers; v; v = v->
next) {
1606 if (!strcasecmp(v->
name,
"Cookie")) {
1618 size_t password_len;
1625 userid_len = strlen(
userid) + 1;
1626 password_len = strlen(
password) + 1;
1629 auth =
ao2_alloc(
sizeof(*auth) + userid_len + password_len,
NULL);
1635 auth->
userid = (
char *)(auth + 1);
1645#define BASIC_PREFIX "Basic "
1652 for (v = headers; v; v = v->
next) {
1654 char decoded[256] = {};
1661 if (strcasecmp(
"Authorization", v->
name) != 0) {
1667 "Unsupported Authorization scheme\n");
1688 sizeof(decoded) - 1);
1693 username =
strsep(&password,
":");
1706 const char *password)
1708 int encoded_size = 0;
1709 int userinfo_len = 0;
1711 char *encoded_userinfo =
NULL;
1718 if (strchr(userid,
':')) {
1720 userinfo_len = strlen(userinfo);
1725 userinfo_len =
ast_asprintf(&userinfo,
"%s:%s", userid, password);
1737 encoded_size = userinfo_len * 2 *
sizeof(char) + 1 +
BASIC_LEN;
1741 userinfo_len, encoded_size -
BASIC_LEN);
1744 encoded_userinfo,
"");
1752 size_t size = strlen(
version);
1763 if (sscanf(
buf,
"%d", &status_code) != 1) {
1788 if (buf_end !=
buf) {
1792 memcpy(buf_end, p, s - p);
1824 const char *
value,
const char *expected_value)
1826 if (strcasecmp(
name, expected_name)) {
1831 if (strcasecmp(
value, expected_value)) {
1833 "received %s",
value, expected_value);
1840 const char *
value,
const char *expected_value)
1842 if (strcasecmp(
name, expected_name)) {
1849 "in '%s'\n",
name,
value, expected_value);
1857#define MAX_HTTP_REQUEST_HEADERS 100
1873 int remaining_headers;
1887 if (header_line[
len - 1] !=
'\n') {
1890 (
len ==
sizeof(header_line) - 1) ?
"Header line too long" :
"Timeout");
1901 value = header_line;
1914 if (!remaining_headers--) {
1916 ast_http_error(ser, 413,
"Request Entity Too Large",
"Too many headers");
1957 const char *transfer_encoding;
1973 if (request_line[
len - 1] !=
'\n') {
1976 (
len ==
sizeof(request_line) - 1) ?
"Request line too long" :
"Timeout");
1987 if (!strcasecmp(
method,
"GET")) {
1989 }
else if (!strcasecmp(
method,
"POST")) {
1991 }
else if (!strcasecmp(
method,
"HEAD")) {
1993 }
else if (!strcasecmp(
method,
"PUT")) {
1995 }
else if (!strcasecmp(
method,
"DELETE")) {
1997 }
else if (!strcasecmp(
method,
"OPTIONS")) {
2014 ast_http_error(ser, 503,
"Service Unavailable",
"Shutdown in progress");
2025 if (!transfer_encoding) {
2026 transfer_encoding =
"identity";
2033 if (strcasecmp(transfer_encoding,
"identity") != 0 &&
2034 strcasecmp(transfer_encoding,
"chunked") != 0) {
2036 ast_http_error(ser, 501,
"Unimplemented",
"Unsupported Transfer-Encoding.");
2041 ||
handle_uri(ser, uri, http_method, headers)
2066 ast_debug(1,
"HTTP opening session. Top level\n");
2123 ast_debug(1,
"HTTP closing session. Top level\n");
2137 char *target, *dest;
2139 unsigned int target_len;
2140 unsigned int total_len;
2154 target_len = strlen(
target) + 1;
2155 dest_len = strlen(
dest) + 1;
2156 total_len =
sizeof(*redirect) + target_len + dest_len;
2158 if (!(redirect =
ast_calloc(1, total_len))) {
2161 redirect->
dest = redirect->
target + target_len;
2191#define HTTP_SERVER_BUCKETS 5
2204 ast_verb(1,
"Stopped http server '%s' listening at '%s'\n", server->
name, server->
address);
2217 ast_log(
LOG_ERROR,
"Unable to allocate HTTP server '%s' at address '%s'\n",
2223 ast_log(
LOG_ERROR,
"Unable to complete setup for HTTP server '%s' at address '%s'\n",
2290 if (
ao2_ref(server, -1) == 2) {
2354 for (i = 0; i < num_addrs; ++i) {
2401 if (*replace_me == server) {
2411 *replace_me = server;
2427#ifdef TEST_FRAMEWORK
2452 host =
"localhost:8088";
2456 name =
"http test server";
2482 int new_static_uri_enabled = 0;
2483 int new_status_uri_enabled = 0;
2489 int http_tls_was_enabled = 0;
2522 http_tls_cfg.
cipher =
ast_strdup(
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA");
2536 snprintf(server_name,
sizeof(server_name),
"Asterisk/%s",
ast_get_version());
2539 for (; v; v = v->
next) {
2541 if (strcasecmp(v->
name,
"tlscafile")
2542 && strcasecmp(v->
name,
"tlscapath")
2543 && strcasecmp(v->
name,
"tlscadir")
2544 && strcasecmp(v->
name,
"tlsverifyclient")
2545 && strcasecmp(v->
name,
"tlsdontverifyserver")
2546 && strcasecmp(v->
name,
"tlsclientmethod")
2547 && strcasecmp(v->
name,
"sslclientmethod")
2552 if (!strcasecmp(v->
name,
"servername")) {
2556 server_name[0] =
'\0';
2558 }
else if (!strcasecmp(v->
name,
"enabled")) {
2560 }
else if (!strcasecmp(v->
name,
"enablestatic") || !strcasecmp(v->
name,
"enable_static")) {
2562 }
else if (!strcasecmp(v->
name,
"enable_status")) {
2564 }
else if (!strcasecmp(v->
name,
"bindport")) {
2570 }
else if (!strcasecmp(v->
name,
"bindaddr")) {
2572 }
else if (!strcasecmp(v->
name,
"prefix")) {
2577 newprefix[0] =
'\0';
2579 }
else if (!strcasecmp(v->
name,
"redirect")) {
2581 }
else if (!strcasecmp(v->
name,
"sessionlimit")) {
2587 }
else if (!strcasecmp(v->
name,
"session_inactivity")) {
2593 }
else if (!strcasecmp(v->
name,
"session_keep_alive")) {
2607 if (strcmp(
prefix, newprefix)) {
2676 e->
command =
"http show status";
2678 "Usage: http show status\n"
2679 " Lists status of internal HTTP engine\n";
2688 ast_cli(
a->fd,
"HTTP Server Status:\n");
2692 ast_cli(
a->fd,
"Server Disabled\n\n");
2694 ast_cli(
a->fd,
"Server Enabled and Bound to %s\n\n",
2697 ast_cli(
a->fd,
"HTTPS Server Enabled and Bound to %s\n\n",
2702 ast_cli(
a->fd,
"Enabled URI's:\n");
2712 ast_cli(
a->fd,
"\nEnabled Redirects:\n");
2791 .
requires =
"extconfig",
void ast_cli_unregister_multiple(void)
Asterisk version information.
const char * ast_get_version(void)
Retrieve the Asterisk version string.
char * strsep(char **str, const char *delims)
char * strcasestr(const char *, const char *)
Asterisk main include file. File version handling, generic pbx functions.
int ast_shutdown_final(void)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_strndup(str, len)
A wrapper for strndup()
#define ast_realloc(p, len)
A wrapper for realloc()
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define ast_calloc(num, len)
A wrapper for calloc()
#define ast_malloc(len)
A wrapper for malloc()
@ AO2_ALLOC_OPT_LOCK_NOLOCK
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define AO2_STRING_FIELD_CMP_FN(stype, field)
Creates a compare function for a structure string field.
#define ao2_unlink(container, obj)
Remove an object from a container.
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc_options(data_size, destructor_fn, options)
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
#define AO2_STRING_FIELD_HASH_FN(stype, field)
Creates a hash function for a structure string field.
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
struct ast_sockaddr bindaddr
static char version[AST_MAX_EXTENSION]
static int request(void *obj)
Standard Command Line Interface.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_http_prefix(char *buf, int len)
Return the current prefix.
static int http_body_discard_chunk_trailer_headers(struct ast_tcptls_session_instance *ser)
void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method, int status_code, const char *status_title, struct ast_str *http_header, struct ast_str *out, int fd, unsigned int static_content)
Generic function for sending HTTP/1.1 response.
static void * httpd_helper_thread(void *arg)
struct ast_variable * ast_http_get_post_vars(struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
Get post variables from client Request Entity-Body, if content type is application/x-www-form-urlenco...
static int http_check_connection_close(struct ast_variable *headers)
struct ast_json * ast_http_get_json(struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
Get JSON from client Request Entity-Body, if content type is application/json.
static int httpstatus_callback(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers)
int ast_http_header_parse(char *buf, char **name, char **value)
Parse a header into the given name/value strings.
static struct ast_tls_config http_tls_cfg
const char * ast_get_http_method(enum ast_http_method method)
Return http method name string.
struct ast_variable * ast_http_get_cookies(struct ast_variable *headers)
Get cookie from Request headers.
int ast_http_header_match_in(const char *name, const char *expected_name, const char *value, const char *expected_value)
Check if the header name matches the expected header name. If so, then check to see if the value can ...
#define MIN_INITIAL_REQUEST_TIMEOUT
#define INITIAL_RESPONSE_BODY_BUFFER
static int __ast_http_load(int reload)
static int http_request_headers_get(struct ast_tcptls_session_instance *ser, struct ast_variable **headers)
static void http_server_destroy(void *obj)
struct ao2_container * http_servers
static int http_request_tracking_setup(struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
static void http_request_tracking_init(struct http_worker_private_data *request)
static int static_callback(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers)
static char http_server_name[MAX_SERVER_NAME_LENGTH]
static void add_redirect(const char *value)
Add a new URI redirect The entries in the redirect list are sorted by length, just like the list of U...
static const char * get_header(struct ast_variable *headers, const char *field_name)
Retrieves the header with the given field name.
#define MAX_HTTP_REQUEST_HEADERS
int ast_http_uri_link(struct ast_http_uri *urih)
Link the new uri into the list.
static int status_uri_enabled
int ast_http_body_discard(struct ast_tcptls_session_instance *ser)
Read and discard any unread HTTP request body.
static struct ast_cli_entry cli_http[]
enum ast_http_method ast_get_http_method_from_string(const char *method)
Return http method from string.
static int http_server_start(struct ast_http_server *server)
@ HTTP_FLAG_CLOSE_ON_COMPLETION
static struct @386 mimetypes[]
Limit the kinds of files we're willing to serve up.
void ast_http_error(struct ast_tcptls_session_instance *ser, int status_code, const char *status_title, const char *text)
Send HTTP error message and close socket.
static char prefix[MAX_PREFIX]
static int http_body_discard_contents(struct ast_tcptls_session_instance *ser, int length, const char *what_getting)
struct ast_variable * ast_http_parse_post_form(char *buf, int content_length, const char *content_type)
Get post variables from an application/x-www-form-urlencoded buffer.
static void str_append_escaped(struct ast_str **str, const char *in)
static char * get_content_type(struct ast_variable *headers)
Retrieves the content type specified in the "Content-Type" header.
static int reload_module(void)
static int session_inactivity
struct ast_variable * ast_http_create_basic_auth_header(const char *userid, const char *password)
Create an HTTP authorization header.
#define DEFAULT_SESSION_INACTIVITY
static struct ast_http_server * http_server_create(const char *name, const char *address, const struct ast_sockaddr *addr)
static struct ast_http_uri status_uri
static int http_body_check_chunk_sync(struct ast_tcptls_session_instance *ser)
struct ast_http_auth * ast_http_get_auth(struct ast_variable *headers)
Get HTTP authentication information from headers.
int ast_http_header_match(const char *name, const char *expected_name, const char *value, const char *expected_value)
Check if the header and value match (case insensitive) their associated expected values.
const char * ast_http_ftype2mtype(const char *ftype)
Return mime type based on extension.
static void remove_excess_lws(char *s)
static void http_server_discard(struct ast_http_server *server)
Discard/Drop a HTTP server.
static struct ast_http_server * http_server_get_by_host(const char *name, const char *host, uint32_t port)
Retrieve, or create a HTTP server object by host.
#define DEFAULT_SESSION_KEEP_ALIVE
static char * ast_http_get_contents(int *return_length, struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
Returns the contents (body) of the HTTP request.
int ast_http_response_status_line(const char *buf, const char *version, int code)
Parse the http response status line.
#define MAX_CONTENT_LENGTH
static int chunked_atoh(const char *s, int len)
void ast_http_request_close_on_completion(struct ast_tcptls_session_instance *ser)
Request the HTTP connection be closed after this HTTP request.
static int http_body_read_contents(struct ast_tcptls_session_instance *ser, char *buf, int length, const char *what_getting)
void ast_http_uri_unlink(struct ast_http_uri *urih)
Unregister a URI handler.
static int load_module(void)
static const char * get_transfer_encoding(struct ast_variable *headers)
Returns the value of the Transfer-Encoding header.
static struct ast_http_server * http_server_get_by_addr(const char *name, const struct ast_sockaddr *addr)
Retrieve, or create a HTTP server object by sock address.
static struct ast_http_uri static_uri
static struct ast_http_server * http_server_get(const char *name, const char *host, uint32_t port, struct ast_http_server **replace_me)
Retrieve, or create and start a HTTP server.
void ast_http_create_response(struct ast_tcptls_session_instance *ser, int status_code, const char *status_title, struct ast_str *http_header_data, const char *text)
Creates and sends a formatted http response message.
static struct ast_tcptls_session_args https_desc
static int unload_module(void)
static int static_uri_enabled
static int session_keep_alive
static int httpd_process_request(struct ast_tcptls_session_instance *ser)
static int handle_uri(struct ast_tcptls_session_instance *ser, char *uri, enum ast_http_method method, struct ast_variable *headers)
uint32_t ast_http_manid_from_vars(struct ast_variable *headers)
Return manager id, if exist, from request headers.
static struct ast_http_auth * auth_create(const char *userid, const char *password)
void ast_http_uri_unlink_all_with_key(const char *key)
Unregister all handlers with matching key.
static const struct ast_cfhttp_methods_text ast_http_methods_text[]
static struct ast_variable * parse_cookies(const char *cookies)
static char * handle_show_http(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define MAX_HTTP_LINE_LENGTH
void ast_http_body_read_status(struct ast_tcptls_session_instance *ser, int read_success)
Update the body read success status.
struct ast_http_server * global_http_server
#define DEFAULT_RESPONSE_HEADER_LENGTH
#define MAX_SERVER_NAME_LENGTH
static int http_body_get_chunk_length(struct ast_tcptls_session_instance *ser)
#define HTTP_SERVER_BUCKETS
Number of HTTP server buckets.
static int get_content_length(struct ast_variable *headers)
Returns the value of the Content-Length header.
#define DEFAULT_SESSION_LIMIT
Support for Private Asterisk HTTP Servers.
ast_http_method
HTTP Request methods known by Asterisk.
Configuration File Parser.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define ast_variable_new(name, value, filename)
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
@ CONFIG_FLAG_FILEUNCHANGED
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format,...)
Write a formatted string to an iostream.
ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size)
Read a LF-terminated string from an iostream.
void ast_iostream_set_timeout_idle_inactivity(struct ast_iostream *stream, int timeout, int timeout_reset)
Set the iostream inactivity & idle timeout timers.
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream's file descriptor.
void ast_iostream_set_exclusive_input(struct ast_iostream *stream, int exclusive_input)
Set the iostream if it can exclusively depend upon the set timeouts.
ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count)
Read data from an iostream.
void ast_iostream_nonblock(struct ast_iostream *stream)
Make an iostream non-blocking.
ssize_t ast_iostream_discard(struct ast_iostream *stream, size_t count)
Discard the specified number of bytes from an iostream.
Asterisk JSON abstraction layer.
struct ast_json * ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error)
Parse buffer with known length into a JSON object or array.
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
#define AST_RWLIST_REMOVE_HEAD
#define AST_RWLIST_INSERT_AFTER
#define AST_RWLIST_REMOVE
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_TRAVERSE
#define AST_RWLIST_INSERT_HEAD
#define AST_RWLIST_INSERT_TAIL
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
#define AST_PTHREADT_NULL
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
int astman_is_authed(uint32_t ident)
Determine if a manager session ident is authenticated.
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_ref(mod)
Hold a reference to the module.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_FAILURE
Module could not be loaded properly.
@ AST_MODULE_LOAD_SUCCESS
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized,...
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_DATA_DIR
static void cleanup(void)
Clean up any old apps that we don't need any more.
String manipulation functions.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
static force_inline int attribute_pure ast_strlen_zero(const char *s)
char *attribute_pure ast_skip_nonblanks(const char *str)
Gets a pointer to first whitespace character in a string.
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
char *attribute_pure ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
enum ast_http_method method
descriptor for a cli entry.
Structure used to handle boolean flags.
HTTP authentication information.
struct ast_tcptls_session_args args
Definition of a URI handler.
unsigned int no_decode_uri
ast_http_callback callback
struct ast_http_uri::@241 entry
Abstract JSON element (object, array, string, int, ...).
Socket address structure.
Support for dynamic strings.
arguments for the accepting thread
void *(* accept_fn)(void *)
struct ast_sockaddr local_address
void *(* worker_fn)(void *)
struct ast_sockaddr old_address
struct ast_tls_config * tls_cfg
describes a server instance
struct ast_iostream * stream
struct ast_sockaddr remote_address
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
struct http_uri_redirect::@387 entry
Generic support for tcp/tls servers in Asterisk.
void * ast_tcptls_server_root(void *)
void ast_tcptls_server_stop(struct ast_tcptls_session_args *desc)
Shutdown a running server if there is one.
int ast_ssl_setup(struct ast_tls_config *cfg)
Set up an SSL server.
void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
This is a generic (re)start routine for a TCP server, which does the socket/bind/listen and starts a ...
@ AST_SSL_SERVER_CIPHER_ORDER
int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value)
Used to parse conf files containing tls/ssl options.
void ast_tcptls_close_session_file(struct ast_tcptls_session_instance *tcptls_session)
Closes a tcptls session instance's file and/or file descriptor. The tcptls_session will be set to NUL...
Time-related functions and macros.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define ast_test_flag(p, flag)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
int ast_xml_escape(const char *string, char *outbuf, size_t buflen)
Escape reserved characters for use in XML.
#define ast_set_flag(p, flag)
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
#define ast_set_flags_to(p, flag, value)
const struct ast_flags ast_uri_http_legacy