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" },
226 for (v = cookies; v; v = v->
next) {
227 if (!strcasecmp(v->
name,
"mansession_id")) {
228 sscanf(v->
value,
"%30x", &mngid);
258 char timebuf[80], etag[23];
260 int not_modified = 0;
263 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
278 if ((uri[0] < 33) || strchr(
"./|~@#$%^&*() \t", uri[0])) {
282 if (strstr(uri,
"/..")) {
286 if ((ftype = strrchr(uri,
'.'))) {
291 snprintf(wkspace,
sizeof(wkspace),
"text/%s",
S_OR(ftype,
"plain"));
302 if (stat(path, &st)) {
306 if (S_ISDIR(st.st_mode)) {
314 fd = open(path, O_RDONLY);
320 snprintf(etag,
sizeof(etag),
"\"%ld\"", (
long)st.st_mtime);
323 tv.tv_sec = st.st_mtime;
328 for (v = headers; v; v = v->
next) {
329 if (!strcasecmp(v->
name,
"If-None-Match")) {
330 if (!strcasecmp(v->
value, etag)) {
345 ast_str_set(&http_header, 0,
"Content-type: %s\r\n"
347 "Last-Modified: %s\r\n",
362 ast_http_error(ser, 404,
"Not Found",
"The requested URL was not found on this server.");
367 ast_http_error(ser, 403,
"Access Denied",
"You do not have permission to access the requested URL.");
380 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
392 "<html><title>Asterisk HTTP Status</title>\r\n"
393 "<body bgcolor=\"#ffffff\">\r\n"
394 "<table bgcolor=\"#f1f1f1\" align=\"center\"><tr><td bgcolor=\"#e0e0ff\" colspan=\"2\" width=\"500\">\r\n"
395 "<h2> Asterisk™ HTTP Status</h2></td></tr>\r\n");
400 ast_str_append(&
out, 0,
"<tr><td><i>Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
404 ast_str_append(&
out, 0,
"<tr><td><i>TLS Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
408 for (v = get_vars; v; v = v->
next) {
414 for (v = cookies; v; v = v->
next) {
419 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");
426 .description =
"Asterisk HTTP General Status",
435 .description =
"Asterisk HTTP Static Delivery",
462 unsigned int static_content)
469 int content_length = 0;
470 int close_connection;
474 if (!ser || !server_header_field) {
497 close_connection = 1;
505 close_connection = 1;
507 close_connection = 0;
519 content_length += lseek(fd, 0, SEEK_END);
520 lseek(fd, 0, SEEK_SET);
533 "Content-Length: %d\r\n"
536 status_code, status_title ? status_title :
"OK",
539 close_connection ?
"Connection: close\r\n" :
"",
540 static_content ?
"" :
"Cache-Control: no-cache, no-store\r\n",
545 ast_debug(1,
"ast_iostream_printf() failed: %s\n", strerror(
errno));
546 close_connection = 1;
547 }
else if (send_content && fd) {
549 while ((
len = read(fd,
buf,
sizeof(
buf))) > 0) {
551 ast_debug(1,
"ast_iostream_write() failed: %s\n", strerror(
errno));
552 close_connection = 1;
562 if (close_connection) {
563 ast_debug(1,
"HTTP closing session. status_code:%d\n", status_code);
566 ast_debug(1,
"HTTP keeping session open. status_code:%d\n", status_code);
571 const char *status_title,
struct ast_str *http_header_data,
const char *
text)
577 if (!http_header_data || !server_address || !
out) {
582 ast_debug(1,
"HTTP closing session. OOM.\n");
592 "<address>%s</address>\r\n",
598 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
600 "<title>%d %s</title>\r\n"
606 "</body></html>\r\n",
626 const unsigned long nonce,
const unsigned long opaque,
int stale,
629 int status_code = 401;
630 char *status_title =
"Unauthorized";
633 if (http_header_data) {
636 "WWW-authenticate: Digest algorithm=MD5, realm=\"%s\", nonce=\"%08lx\", qop=\"auth\", opaque=\"%08lx\"%s\r\n"
637 "Content-type: text/html\r\n",
638 realm ? realm :
"Asterisk",
641 stale ?
", stale=true" :
"");
652 const char *status_title,
const char *
text)
656 if (http_header_data) {
657 ast_str_set(&http_header_data, 0,
"Content-type: text/html\r\n");
679 int len = strlen(urih->
uri);
720 if (!strcmp(urih->
key,
key)) {
746 for (v = headers; v; v = v->
next) {
747 if (!strcasecmp(v->
name, field_name)) {
767 const char *content_type =
get_header(headers,
"Content-Type");
775 param = strchr(content_type,
';');
776 size = param ? param - content_type : strlen(content_type);
792 const char *content_length =
get_header(headers,
"Content-Length");
795 if (!content_length) {
801 if (sscanf(content_length,
"%30d", &length) != 1) {
817 return get_header(headers,
"Transfer-Encoding");
831 const char *connection =
get_header(headers,
"Connection");
832 int close_connection = 0;
834 if (connection && !strcasecmp(connection,
"close")) {
835 close_connection = -1;
837 return close_connection;
876 const char *transfer_encoding;
883 if (transfer_encoding && !strcasecmp(transfer_encoding,
"chunked")) {
890 if (0 <
request->body_length) {
892 }
else if (
request->body_length < 0) {
895 ast_http_error(ser, 400,
"Bad Request",
"Invalid Content-Length in request!");
936 while (
total != length) {
945 if (
total != length) {
947 what_getting, length, res);
973 what_getting, length, res);
1007 if (*s++ ==
'\x0D') {
1014 if (
c >=
'0' &&
c <=
'9') {
1018 if (
c >=
'a' &&
c <=
'f') {
1022 if (
c >=
'A' &&
c <=
'F') {
1053 length =
chunked_atoh(header_line, strlen(header_line));
1078 if (res <
sizeof(chunk_sync)) {
1080 sizeof(chunk_sync));
1083 if (chunk_sync[0] != 0x0D || chunk_sync[1] != 0x0A) {
1085 (
unsigned char) chunk_sync[0], (
unsigned char) chunk_sync[1]);
1134 ast_debug(1,
"HTTP discarding unused request body\n");
1137 if (0 <
request->body_length) {
1204 ast_debug(2,
"HTTP consuming request body\n");
1207 if (0 <
request->body_length) {
1209 content_length =
request->body_length;
1231 buf[content_length] = 0;
1232 *return_length = content_length;
1250 if (chunk_length < 0) {
1256 if (chunk_length == 0) {
1262 "Excessively long HTTP accumulated chunked body. (%d + %d > %d)\n",
1271 if (content_length + chunk_length >= bufsize) {
1277 }
while (content_length + chunk_length >= bufsize);
1295 content_length += chunk_length;
1312 buf[content_length] = 0;
1313 *return_length = content_length;
1320 int content_length = 0;
1334 if (!
buf || !content_length) {
1359 int content_length = 0;
1369 strcasecmp(
type,
"application/x-www-form-urlencoded")) {
1375 if (!
buf || !content_length) {
1415 ast_debug(2,
"HTTP Request URI is %s \n", uri);
1443 if (!strcasecmp(uri, redirect->
target)) {
1463 if (!strncasecmp(uri,
prefix, l) && uri[l] ==
'/') {
1468 l = strlen(urih->
uri);
1470 ast_debug(2,
"match request [%s] with handler [%s] len %d\n", uri, urih->
uri, l);
1471 if (strncasecmp(urih->
uri, uri, l)
1472 || (*
c && *
c !=
'/')) {
1492 ast_debug(1,
"Requested URI [%s] has no handler\n", uri);
1493 ast_http_error(ser, 404,
"Not Found",
"The requested URL was not found on this server.");
1507 while ((cur =
strsep(&parse,
";"))) {
1539 for (v = headers; v; v = v->
next) {
1540 if (!strcasecmp(v->
name,
"Cookie")) {
1552 size_t password_len;
1559 userid_len = strlen(
userid) + 1;
1560 password_len = strlen(
password) + 1;
1563 auth =
ao2_alloc(
sizeof(*auth) + userid_len + password_len,
NULL);
1569 auth->
userid = (
char *)(auth + 1);
1579#define BASIC_PREFIX "Basic "
1586 for (v = headers; v; v = v->
next) {
1588 char decoded[256] = {};
1595 if (strcasecmp(
"Authorization", v->
name) != 0) {
1601 "Unsupported Authorization scheme\n");
1622 sizeof(decoded) - 1);
1627 username =
strsep(&password,
":");
1642 size_t size = strlen(
version);
1653 if (sscanf(
buf,
"%d", &status_code) != 1) {
1678 if (buf_end !=
buf) {
1682 memcpy(buf_end, p, s - p);
1714 const char *
value,
const char *expected_value)
1716 if (strcasecmp(
name, expected_name)) {
1721 if (strcasecmp(
value, expected_value)) {
1723 "received %s",
value, expected_value);
1730 const char *
value,
const char *expected_value)
1732 if (strcasecmp(
name, expected_name)) {
1739 "in '%s'\n",
name,
value, expected_value);
1747#define MAX_HTTP_REQUEST_HEADERS 100
1763 int remaining_headers;
1777 if (header_line[
len - 1] !=
'\n') {
1780 (
len ==
sizeof(header_line) - 1) ?
"Header line too long" :
"Timeout");
1791 value = header_line;
1804 if (!remaining_headers--) {
1806 ast_http_error(ser, 413,
"Request Entity Too Large",
"Too many headers");
1847 const char *transfer_encoding;
1863 if (request_line[
len - 1] !=
'\n') {
1866 (
len ==
sizeof(request_line) - 1) ?
"Request line too long" :
"Timeout");
1877 if (!strcasecmp(
method,
"GET")) {
1879 }
else if (!strcasecmp(
method,
"POST")) {
1881 }
else if (!strcasecmp(
method,
"HEAD")) {
1883 }
else if (!strcasecmp(
method,
"PUT")) {
1885 }
else if (!strcasecmp(
method,
"DELETE")) {
1887 }
else if (!strcasecmp(
method,
"OPTIONS")) {
1904 ast_http_error(ser, 503,
"Service Unavailable",
"Shutdown in progress");
1915 if (!transfer_encoding) {
1916 transfer_encoding =
"identity";
1923 if (strcasecmp(transfer_encoding,
"identity") != 0 &&
1924 strcasecmp(transfer_encoding,
"chunked") != 0) {
1926 ast_http_error(ser, 501,
"Unimplemented",
"Unsupported Transfer-Encoding.");
1931 ||
handle_uri(ser, uri, http_method, headers)
1956 ast_debug(1,
"HTTP opening session. Top level\n");
2013 ast_debug(1,
"HTTP closing session. Top level\n");
2027 char *target, *dest;
2029 unsigned int target_len;
2030 unsigned int total_len;
2044 target_len = strlen(
target) + 1;
2045 dest_len = strlen(
dest) + 1;
2046 total_len =
sizeof(*redirect) + target_len + dest_len;
2048 if (!(redirect =
ast_calloc(1, total_len))) {
2051 redirect->
dest = redirect->
target + target_len;
2081#define HTTP_SERVER_BUCKETS 5
2094 ast_verb(1,
"Stopped http server '%s' listening at '%s'\n", server->
name, server->
address);
2107 ast_log(
LOG_ERROR,
"Unable to allocate HTTP server '%s' at address '%s'\n",
2113 ast_log(
LOG_ERROR,
"Unable to complete setup for HTTP server '%s' at address '%s'\n",
2180 if (
ao2_ref(server, -1) == 2) {
2244 for (i = 0; i < num_addrs; ++i) {
2291 if (*replace_me == server) {
2301 *replace_me = server;
2317#ifdef TEST_FRAMEWORK
2342 host =
"localhost:8088";
2346 name =
"http test server";
2372 int new_static_uri_enabled = 0;
2373 int new_status_uri_enabled = 1;
2379 int http_tls_was_enabled = 0;
2412 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");
2426 snprintf(server_name,
sizeof(server_name),
"Asterisk/%s",
ast_get_version());
2429 for (; v; v = v->
next) {
2431 if (strcasecmp(v->
name,
"tlscafile")
2432 && strcasecmp(v->
name,
"tlscapath")
2433 && strcasecmp(v->
name,
"tlscadir")
2434 && strcasecmp(v->
name,
"tlsverifyclient")
2435 && strcasecmp(v->
name,
"tlsdontverifyserver")
2436 && strcasecmp(v->
name,
"tlsclientmethod")
2437 && strcasecmp(v->
name,
"sslclientmethod")
2442 if (!strcasecmp(v->
name,
"servername")) {
2446 server_name[0] =
'\0';
2448 }
else if (!strcasecmp(v->
name,
"enabled")) {
2450 }
else if (!strcasecmp(v->
name,
"enablestatic") || !strcasecmp(v->
name,
"enable_static")) {
2452 }
else if (!strcasecmp(v->
name,
"enable_status")) {
2454 }
else if (!strcasecmp(v->
name,
"bindport")) {
2460 }
else if (!strcasecmp(v->
name,
"bindaddr")) {
2462 }
else if (!strcasecmp(v->
name,
"prefix")) {
2467 newprefix[0] =
'\0';
2469 }
else if (!strcasecmp(v->
name,
"redirect")) {
2471 }
else if (!strcasecmp(v->
name,
"sessionlimit")) {
2477 }
else if (!strcasecmp(v->
name,
"session_inactivity")) {
2483 }
else if (!strcasecmp(v->
name,
"session_keep_alive")) {
2497 if (strcmp(
prefix, newprefix)) {
2566 e->
command =
"http show status";
2568 "Usage: http show status\n"
2569 " Lists status of internal HTTP engine\n";
2578 ast_cli(
a->fd,
"HTTP Server Status:\n");
2582 ast_cli(
a->fd,
"Server Disabled\n\n");
2584 ast_cli(
a->fd,
"Server Enabled and Bound to %s\n\n",
2587 ast_cli(
a->fd,
"HTTPS Server Enabled and Bound to %s\n\n",
2592 ast_cli(
a->fd,
"Enabled URI's:\n");
2602 ast_cli(
a->fd,
"\nEnabled Redirects:\n");
2681 .
requires =
"extconfig",
Asterisk version information.
const char * ast_get_version(void)
Retrieve the Asterisk version string.
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_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_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.
@ 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.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#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 ...
AO2_STRING_FIELD_CMP_FN(ast_http_server, address)
#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)
AO2_STRING_FIELD_HASH_FN(ast_http_server, address)
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[]
static int http_server_start(struct ast_http_server *server)
@ HTTP_FLAG_CLOSE_ON_COMPLETION
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)
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
#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.
void ast_http_auth(struct ast_tcptls_session_instance *ser, const char *realm, const unsigned long nonce, const unsigned long opaque, int stale, const char *text)
Send http "401 Unauthorized" response and close socket.
#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 struct @359 mimetypes[]
Limit the kinds of files we're willing to serve up.
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.
char * strsep(char **str, const char *delims)
char * strcasestr(const char *, const char *)
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.
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)
@ CONFIG_FLAG_FILEUNCHANGED
#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 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 *unused)
String manipulation functions.
char * ast_skip_nonblanks(const char *str)
Gets a pointer to first whitespace character in a string.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str 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 * 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.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
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 * 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
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
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
struct http_uri_redirect::@360 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_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