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 123 .name =
"http server",
133 .name =
"https server",
150 {
"png",
"image/png" },
151 {
"xml",
"text/xml" },
152 {
"jpg",
"image/jpeg" },
153 {
"js",
"application/x-javascript" },
154 {
"wav",
"audio/x-wav" },
155 {
"mp3",
"audio/mpeg" },
156 {
"svg",
"image/svg+xml" },
157 {
"svgz",
"image/svg+xml" },
158 {
"gif",
"image/gif" },
159 {
"html",
"text/html" },
160 {
"htm",
"text/html" },
161 {
"css",
"text/css" },
162 {
"cnf",
"text/plain" },
163 {
"cfg",
"text/plain" },
164 {
"bin",
"application/octet-stream" },
165 {
"sbn",
"application/octet-stream" },
166 {
"ld",
"application/octet-stream" },
223 for (v = cookies; v; v = v->
next) {
224 if (!strcasecmp(v->
name,
"mansession_id")) {
225 sscanf(v->
value,
"%30x", &mngid);
255 char timebuf[80], etag[23];
257 int not_modified = 0;
260 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
275 if ((uri[0] < 33) || strchr(
"./|~@#$%^&*() \t", uri[0])) {
279 if (strstr(uri,
"/..")) {
283 if ((ftype = strrchr(uri,
'.'))) {
288 snprintf(wkspace,
sizeof(wkspace),
"text/%s",
S_OR(ftype,
"plain"));
299 if (stat(path, &st)) {
303 if (S_ISDIR(st.st_mode)) {
311 fd = open(path, O_RDONLY);
317 snprintf(etag,
sizeof(etag),
"\"%ld\"", (
long)st.st_mtime);
320 tv.tv_sec = st.st_mtime;
325 for (v = headers; v; v = v->
next) {
326 if (!strcasecmp(v->
name,
"If-None-Match")) {
327 if (!strcasecmp(v->
value, etag)) {
342 ast_str_set(&http_header, 0,
"Content-type: %s\r\n" 344 "Last-Modified: %s\r\n",
359 ast_http_error(ser, 404,
"Not Found",
"The requested URL was not found on this server.");
364 ast_http_error(ser, 403,
"Access Denied",
"You do not have permission to access the requested URL.");
377 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
389 "<html><title>Asterisk HTTP Status</title>\r\n" 390 "<body bgcolor=\"#ffffff\">\r\n" 391 "<table bgcolor=\"#f1f1f1\" align=\"center\"><tr><td bgcolor=\"#e0e0ff\" colspan=\"2\" width=\"500\">\r\n" 392 "<h2> Asterisk™ HTTP Status</h2></td></tr>\r\n");
396 ast_str_append(&out, 0,
"<tr><td><i>Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
398 ast_str_append(&out, 0,
"<tr><td><i>Bind Port</i></td><td><b>%s</b></td></tr>\r\n",
401 ast_str_append(&out, 0,
"<tr><td><i>SSL Bind Port</i></td><td><b>%s</b></td></tr>\r\n",
404 ast_str_append(&out, 0,
"<tr><td colspan=\"2\"><hr></td></tr>\r\n");
405 for (v = get_vars; v; v = v->
next) {
406 ast_str_append(&out, 0,
"<tr><td><i>Submitted GET Variable '%s'</i></td><td>%s</td></tr>\r\n", v->
name, v->
value);
408 ast_str_append(&out, 0,
"<tr><td colspan=\"2\"><hr></td></tr>\r\n");
411 for (v = cookies; v; v = v->
next) {
416 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");
423 .description =
"Asterisk HTTP General Status",
432 .description =
"Asterisk HTTP Static Delivery",
459 unsigned int static_content)
466 int content_length = 0;
467 int close_connection;
471 if (!ser || !server_header_field) {
494 close_connection = 1;
502 close_connection = 1;
504 close_connection = 0;
516 content_length += lseek(fd, 0, SEEK_END);
517 lseek(fd, 0, SEEK_SET);
520 send_content = method !=
AST_HTTP_HEAD || status_code >= 400;
530 "Content-Length: %d\r\n" 533 status_code, status_title ? status_title :
"OK",
536 close_connection ?
"Connection: close\r\n" :
"",
537 static_content ?
"" :
"Cache-Control: no-cache, no-store\r\n",
542 ast_debug(1,
"ast_iostream_printf() failed: %s\n", strerror(
errno));
543 close_connection = 1;
544 }
else if (send_content && fd) {
546 while ((len = read(fd, buf,
sizeof(buf))) > 0) {
548 ast_debug(1,
"ast_iostream_write() failed: %s\n", strerror(
errno));
549 close_connection = 1;
559 if (close_connection) {
560 ast_debug(1,
"HTTP closing session. status_code:%d\n", status_code);
563 ast_debug(1,
"HTTP keeping session open. status_code:%d\n", status_code);
568 const char *status_title,
struct ast_str *http_header_data,
const char *
text)
574 if (!http_header_data || !server_address || !out) {
579 ast_debug(1,
"HTTP closing session. OOM.\n");
589 "<address>%s</address>\r\n",
595 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 597 "<title>%d %s</title>\r\n" 603 "</body></html>\r\n",
623 const unsigned long nonce,
const unsigned long opaque,
int stale,
626 int status_code = 401;
627 char *status_title =
"Unauthorized";
630 if (http_header_data) {
633 "WWW-authenticate: Digest algorithm=MD5, realm=\"%s\", nonce=\"%08lx\", qop=\"auth\", opaque=\"%08lx\"%s\r\n" 634 "Content-type: text/html\r\n",
635 realm ? realm :
"Asterisk",
638 stale ?
", stale=true" :
"");
649 const char *status_title,
const char *
text)
653 if (http_header_data) {
654 ast_str_set(&http_header_data, 0,
"Content-type: text/html\r\n");
676 int len = strlen(urih->
uri);
717 if (!strcmp(urih->
key, key)) {
743 for (v = headers; v; v = v->
next) {
744 if (!strcasecmp(v->
name, field_name)) {
763 const char *content_type =
get_header(headers,
"Content-Type");
771 param = strchr(content_type,
';');
772 size = param ? param - content_type : strlen(content_type);
788 const char *content_length =
get_header(headers,
"Content-Length");
791 if (!content_length) {
797 if (sscanf(content_length,
"%30d", &length) != 1) {
813 return get_header(headers,
"Transfer-Encoding");
827 const char *connection =
get_header(headers,
"Connection");
828 int close_connection = 0;
830 if (connection && !strcasecmp(connection,
"close")) {
831 close_connection = -1;
833 return close_connection;
874 const char *transfer_encoding;
881 if (transfer_encoding && !strcasecmp(transfer_encoding,
"chunked")) {
893 ast_http_error(ser, 400,
"Bad Request",
"Invalid Content-Length in request!");
934 while (total != length) {
943 if (total != length) {
945 what_getting, length, res);
971 what_getting, length, res);
1005 if (*s++ ==
'\x0D') {
1012 if (c >=
'0' && c <=
'9') {
1016 if (c >=
'a' && c <=
'f') {
1017 value += 10 + c -
'a';
1020 if (c >=
'A' && c <=
'F') {
1021 value += 10 + c -
'A';
1051 length =
chunked_atoh(header_line, strlen(header_line));
1076 if (res <
sizeof(chunk_sync)) {
1078 sizeof(chunk_sync));
1081 if (chunk_sync[0] != 0x0D || chunk_sync[1] != 0x0A) {
1083 (
unsigned char) chunk_sync[0], (
unsigned char) chunk_sync[1]);
1132 ast_debug(1,
"HTTP discarding unused request body\n");
1201 ast_debug(2,
"HTTP consuming request body\n");
1228 buf[content_length] = 0;
1229 *return_length = content_length;
1247 if (chunk_length < 0) {
1253 if (chunk_length == 0) {
1259 "Excessively long HTTP accumulated chunked body. (%d + %d > %d)\n",
1268 if (content_length + chunk_length >= bufsize) {
1274 }
while (content_length + chunk_length >= bufsize);
1292 content_length += chunk_length;
1309 buf[content_length] = 0;
1310 *return_length = content_length;
1317 int content_length = 0;
1331 if (!
buf || !content_length) {
1356 int content_length = 0;
1366 strcasecmp(
type,
"application/x-www-form-urlencoded")) {
1372 if (!
buf || !content_length) {
1412 ast_debug(2,
"HTTP Request URI is %s \n", uri);
1419 while ((val =
strsep(¶ms,
"&"))) {
1440 if (!strcasecmp(uri, redirect->
target)) {
1460 if (!strncasecmp(uri,
prefix, l) && uri[l] ==
'/') {
1465 l = strlen(urih->
uri);
1467 ast_debug(2,
"match request [%s] with handler [%s] len %d\n", uri, urih->
uri, l);
1468 if (strncasecmp(urih->
uri, uri, l)
1469 || (*c && *c !=
'/')) {
1487 res = urih->
callback(ser, urih, uri, method, get_vars, headers);
1489 ast_debug(1,
"Requested URI [%s] has no handler\n", uri);
1490 ast_http_error(ser, 404,
"Not Found",
"The requested URL was not found on this server.");
1504 while ((cur =
strsep(&parse,
";"))) {
1521 ast_debug(1,
"HTTP Cookie, Name: '%s' Value: '%s'\n", name, val);
1536 for (v = headers; v; v = v->
next) {
1537 if (!strcasecmp(v->
name,
"Cookie")) {
1549 size_t password_len;
1551 if (!userid || !password) {
1556 userid_len = strlen(userid) + 1;
1557 password_len = strlen(password) + 1;
1560 auth =
ao2_alloc(
sizeof(*auth) + userid_len + password_len,
NULL);
1566 auth->
userid = (
char *)(auth + 1);
1567 strcpy(auth->
userid, userid);
1576 #define BASIC_PREFIX "Basic " 1583 for (v = headers; v; v = v->
next) {
1585 char decoded[256] = {};
1592 if (strcasecmp(
"Authorization", v->
name) != 0) {
1598 "Unsupported Authorization scheme\n");
1619 sizeof(decoded) - 1);
1624 username =
strsep(&password,
":");
1639 size_t size = strlen(version);
1641 if (strncmp(buf, version, size) || buf[size] !=
' ') {
1643 "expected %s\n", version);
1650 if (sscanf(buf,
"%d", &status_code) != 1) {
1675 if (buf_end != buf) {
1679 memcpy(buf_end, p, s - p);
1696 *name =
strsep(value,
":");
1711 const char *
value,
const char *expected_value)
1713 if (strcasecmp(name, expected_name)) {
1718 if (strcasecmp(value, expected_value)) {
1720 "received %s", value, expected_value);
1727 const char *
value,
const char *expected_value)
1729 if (strcasecmp(name, expected_name)) {
1736 "in '%s'\n", name, value, expected_value);
1744 #define MAX_HTTP_REQUEST_HEADERS 100 1760 int remaining_headers;
1774 if (header_line[len - 1] !=
'\n') {
1777 (len ==
sizeof(header_line) - 1) ?
"Header line too long" :
"Timeout");
1788 value = header_line;
1789 name =
strsep(&value,
":");
1801 if (!remaining_headers--) {
1803 ast_http_error(ser, 413,
"Request Entity Too Large",
"Too many headers");
1844 const char *transfer_encoding;
1860 if (request_line[len - 1] !=
'\n') {
1863 (len ==
sizeof(request_line) - 1) ?
"Request line too long" :
"Timeout");
1874 if (!strcasecmp(method,
"GET")) {
1876 }
else if (!strcasecmp(method,
"POST")) {
1878 }
else if (!strcasecmp(method,
"HEAD")) {
1880 }
else if (!strcasecmp(method,
"PUT")) {
1882 }
else if (!strcasecmp(method,
"DELETE")) {
1884 }
else if (!strcasecmp(method,
"OPTIONS")) {
1901 ast_http_error(ser, 503,
"Service Unavailable",
"Shutdown in progress");
1912 if (!transfer_encoding) {
1913 transfer_encoding =
"identity";
1920 if (strcasecmp(transfer_encoding,
"identity") != 0 &&
1921 strcasecmp(transfer_encoding,
"chunked") != 0) {
1923 ast_http_error(ser, 501,
"Unimplemented",
"Unsupported Transfer-Encoding.");
1928 ||
handle_uri(ser, uri, http_method, headers)
1953 ast_debug(1,
"HTTP opening session. Top level\n");
2010 ast_debug(1,
"HTTP closing session. Top level\n");
2024 char *target, *dest;
2026 unsigned int target_len;
2027 unsigned int total_len;
2032 target =
strsep(&dest,
" ");
2034 target =
strsep(&target,
" ");
2041 target_len = strlen(target) + 1;
2042 dest_len = strlen(dest) + 1;
2043 total_len =
sizeof(*redirect) + target_len + dest_len;
2045 if (!(redirect =
ast_calloc(1, total_len))) {
2048 redirect->
dest = redirect->
target + target_len;
2049 strcpy(redirect->
target, target);
2082 int new_static_uri_enabled = 0;
2083 int new_status_uri_enabled = 1;
2091 int http_tls_was_enabled = 0;
2123 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");
2137 snprintf(server_name,
sizeof(server_name),
"Asterisk/%s",
ast_get_version());
2140 for (; v; v = v->
next) {
2142 if (strcasecmp(v->
name,
"tlscafile")
2143 && strcasecmp(v->
name,
"tlscapath")
2144 && strcasecmp(v->
name,
"tlscadir")
2145 && strcasecmp(v->
name,
"tlsverifyclient")
2146 && strcasecmp(v->
name,
"tlsdontverifyserver")
2147 && strcasecmp(v->
name,
"tlsclientmethod")
2148 && strcasecmp(v->
name,
"sslclientmethod")
2153 if (!strcasecmp(v->
name,
"servername")) {
2157 server_name[0] =
'\0';
2159 }
else if (!strcasecmp(v->
name,
"enabled")) {
2161 }
else if (!strcasecmp(v->
name,
"enablestatic") || !strcasecmp(v->
name,
"enable_static")) {
2163 }
else if (!strcasecmp(v->
name,
"enable_status")) {
2165 }
else if (!strcasecmp(v->
name,
"bindport")) {
2171 }
else if (!strcasecmp(v->
name,
"bindaddr")) {
2175 }
else if (!strcasecmp(v->
name,
"prefix")) {
2180 newprefix[0] =
'\0';
2182 }
else if (!strcasecmp(v->
name,
"redirect")) {
2184 }
else if (!strcasecmp(v->
name,
"sessionlimit")) {
2190 }
else if (!strcasecmp(v->
name,
"session_inactivity")) {
2196 }
else if (!strcasecmp(v->
name,
"session_keep_alive")) {
2210 if (strcmp(
prefix, newprefix)) {
2216 if (num_addrs && enabled) {
2218 for (i = 0; i < num_addrs; ++i) {
2286 e->
command =
"http show status";
2288 "Usage: http show status\n" 2289 " Lists status of internal HTTP engine\n";
2298 ast_cli(a->
fd,
"HTTP Server Status:\n");
2304 ast_cli(a->
fd,
"Server Enabled and Bound to %s\n\n",
2307 ast_cli(a->
fd,
"HTTPS Server Enabled and Bound to %s\n\n",
2322 ast_cli(a->
fd,
"\nEnabled Redirects:\n");
2387 .requires =
"extconfig",
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.
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
struct ast_variable * next
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.
static struct ast_variable * parse_cookies(const char *cookies)
static struct @395 mimetypes[]
Limit the kinds of files we're willing to serve up.
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_realloc(p, len)
A wrapper for realloc()
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
ast_http_callback callback
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 ...
String manipulation functions.
static int http_request_headers_get(struct ast_tcptls_session_instance *ser, struct ast_variable **headers)
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.
int ast_http_response_status_line(const char *buf, const char *version, int code)
Parse the http response status line.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
int ast_ssl_setup(struct ast_tls_config *cfg)
Set up an SSL server.
#define AST_RWLIST_INSERT_AFTER
Asterisk version information.
struct ast_variable * ast_http_get_cookies(struct ast_variable *headers)
Get cookie from Request headers.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define ast_test_flag(p, flag)
uint32_t ast_http_manid_from_vars(struct ast_variable *headers)
Return manager id, if exist, from request headers.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
static int static_uri_enabled
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
Time-related functions and macros.
const char * ast_get_version(void)
Retrieve the Asterisk version string.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define ast_set_flag(p, flag)
static char * get_content_type(struct ast_variable *headers)
Retrieves the content type specified in the "Content-Type" header.
descriptor for a cli entry.
static struct ast_cli_entry cli_http[]
static int status_uri_enabled
static int chunked_atoh(const char *s, int len)
ssize_t ast_iostream_discard(struct ast_iostream *stream, size_t count)
Discard the specified number of bytes from an iostream.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define CONFIG_STATUS_FILEINVALID
void ast_http_uri_unlink(struct ast_http_uri *urih)
Unregister a URI handler.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
#define DEFAULT_SESSION_LIMIT
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
#define INITIAL_RESPONSE_BODY_BUFFER
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream's file descriptor.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
arguments for the accepting thread
#define ao2_alloc_options(data_size, destructor_fn, options)
static int get_content_length(struct ast_variable *headers)
Returns the value of the Content-Length header.
#define ast_strdup(str)
A wrapper for strdup()
static int http_request_tracking_setup(struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
Generic support for tcp/tls servers in Asterisk.
void ast_cli(int fd, const char *fmt,...)
int ast_xml_escape(const char *string, char *outbuf, size_t buflen)
Escape reserved characters for use in XML.
void ast_iostream_set_timeout_idle_inactivity(struct ast_iostream *stream, int timeout, int timeout_reset)
Set the iostream inactivity & idle timeout timers.
const char * ast_get_http_method(enum ast_http_method method)
Return http method name string.
Socket address structure.
static struct ast_str * password
#define ast_verb(level,...)
char * ast_skip_nonblanks(const char *str)
Gets a pointer to first whitespace character in a string.
void ast_http_uri_unlink_all_with_key(const char *key)
Unregister all handlers with matching key.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
#define ast_set_flags_to(p, flag, value)
#define DEFAULT_SESSION_KEEP_ALIVE
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
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)
#define ast_strlen_zero(foo)
ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count)
Read data from an iostream.
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized, or having a 0 length.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define MAX_SERVER_NAME_LENGTH
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
Configuration File Parser.
Support for Private Asterisk HTTP Servers.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
int ast_http_header_parse(char *buf, char **name, char **value)
Parse a header into the given name/value strings.
#define AST_RWLIST_INSERT_HEAD
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_debug(level,...)
Log a DEBUG message.
int astman_is_authed(uint32_t ident)
Determinie if a manager session ident is authenticated.
void * ast_tcptls_server_root(void *)
int ast_http_body_discard(struct ast_tcptls_session_instance *ser)
Read and discard any unread HTTP request body.
Asterisk JSON abstraction layer.
Asterisk file paths, configured in asterisk.conf.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define AST_PTHREADT_NULL
static int http_body_read_contents(struct ast_tcptls_session_instance *ser, char *buf, int length, const char *what_getting)
#define AST_RWLIST_TRAVERSE
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
#define ao2_ref(o, delta)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static struct ast_tls_config http_tls_cfg
#define AST_RWLIST_REMOVE_CURRENT
#define ast_strdupa(s)
duplicate a string in memory from the stack
ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format,...)
Write a formatted string to an iostream.
#define ast_malloc(len)
A wrapper for malloc()
#define ast_variable_new(name, value, filename)
void ast_http_body_read_status(struct ast_tcptls_session_instance *ser, int read_success)
Update the body read success status.
static struct ast_tcptls_session_args http_desc
describes a server instance
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define CONFIG_STATUS_FILEUNCHANGED
static char http_server_name[MAX_SERVER_NAME_LENGTH]
static void * httpd_helper_thread(void *arg)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
static int unload_module(void)
const char * ast_config_AST_DATA_DIR
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
static int httpd_process_request(struct ast_tcptls_session_instance *ser)
int ast_shutdown_final(void)
static int __ast_http_load(int reload)
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...
const struct ast_flags ast_uri_http_legacy
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
static const char * get_header(struct ast_variable *headers, const char *field_name)
Retrieves the header with the given field name.
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 len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
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.
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
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.
#define ast_strndup(str, len)
A wrapper for strndup()
static const struct ast_cfhttp_methods_text ast_http_methods_text[]
#define ao2_alloc(data_size, destructor_fn)
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
char * strcasestr(const char *, const char *)
static void http_request_tracking_init(struct http_worker_private_data *request)
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
static char version[AST_MAX_EXTENSION]
static void parse(struct mgcp_request *req)
#define ast_calloc(num, len)
A wrapper for calloc()
static const char * get_transfer_encoding(struct ast_variable *headers)
Returns the value of the Transfer-Encoding header.
void ast_http_prefix(char *buf, int len)
Return the current prefix.
static struct ast_http_auth * auth_create(const char *userid, const char *password)
Module could not be loaded properly.
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 session_inactivity
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *result,...)
The argument parsing routine.
struct ast_http_auth * ast_http_get_auth(struct ast_variable *headers)
Get HTTP authentication information from headers.
#define AST_RWLIST_REMOVE_HEAD
static int http_body_get_chunk_length(struct ast_tcptls_session_instance *ser)
struct ast_sockaddr old_address
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 MIN_INITIAL_REQUEST_TIMEOUT
static int request(void *obj)
static int http_body_discard_chunk_trailer_headers(struct ast_tcptls_session_instance *ser)
#define DEFAULT_SESSION_INACTIVITY
static void * cleanup(void *unused)
Structure used to handle boolean flags.
struct ast_iostream * stream
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
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.
#define MAX_CONTENT_LENGTH
static int handle_uri(struct ast_tcptls_session_instance *ser, char *uri, enum ast_http_method method, struct ast_variable *headers)
static int http_check_connection_close(struct ast_variable *headers)
ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size)
Read a LF-terminated string from an iostream.
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.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define AST_RWLIST_INSERT_TAIL
#define DEFAULT_RESPONSE_HEADER_LENGTH
char * strsep(char **str, const char *delims)
static int load_module(void)
int ast_http_uri_link(struct ast_http_uri *urih)
Link the new uri into the list.
static int http_body_discard_contents(struct ast_tcptls_session_instance *ser, int length, const char *what_getting)
HTTP authentication information.
Standard Command Line Interface.
static struct ast_http_uri static_uri
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
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...
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
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.
Definition of a URI handler.
static char * handle_show_http(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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 ...
static void remove_excess_lws(char *s)
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)
void ast_iostream_nonblock(struct ast_iostream *stream)
Make an iostream non-blocking.
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.
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
static int http_body_check_chunk_sync(struct ast_tcptls_session_instance *ser)
Abstract JSON element (object, array, string, int, ...).
#define AST_RWLIST_REMOVE
#define MAX_HTTP_REQUEST_HEADERS
void ast_tcptls_server_stop(struct ast_tcptls_session_args *desc)
Shutdown a running server if there is one.
struct ast_tls_config * tls_cfg
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.
struct ast_sockaddr local_address
ast_http_method
HTTP Request methods known by Asterisk.
static int reload_module(void)
#define ASTERISK_GPL_KEY
The text the key() function should return.
static int session_keep_alive
Asterisk module definitions.
static struct ast_tcptls_session_args https_desc
const char * ast_http_ftype2mtype(const char *ftype)
Return mime type based on extension.
static struct ast_http_uri status_uri
#define AST_RWLIST_TRAVERSE_SAFE_END
unsigned int no_decode_uri
#define MAX_HTTP_LINE_LENGTH
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
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 char prefix[MAX_PREFIX]