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.");
 
 
  393        ast_http_error(ser, 501, 
"Not Implemented", 
"Attempt to use unimplemented / unsupported method");
 
  405        "<html><title>Asterisk HTTP Status</title>\r\n" 
  406        "<body bgcolor=\"#ffffff\">\r\n" 
  407        "<table bgcolor=\"#f1f1f1\" align=\"center\"><tr><td bgcolor=\"#e0e0ff\" colspan=\"2\" width=\"500\">\r\n" 
  408        "<h2>  Asterisk™ HTTP Status</h2></td></tr>\r\n");
 
  413        ast_str_append(&
out, 0, 
"<tr><td><i>Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
 
  417        ast_str_append(&
out, 0, 
"<tr><td><i>TLS Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
 
  421    for (v = get_vars; v; v = v->
next) {
 
  427    for (v = cookies; v; v = v->
next) {
 
  432    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");
 
 
  439    .description = 
"Asterisk HTTP General Status",
 
 
  448    .description = 
"Asterisk HTTP Static Delivery",
 
 
  475    unsigned int static_content)
 
  482    int content_length = 0;
 
  483    int close_connection;
 
  487    if (!ser || !server_header_field) {
 
  510        close_connection = 1;
 
  518            close_connection = 1;
 
  520            close_connection = 0;
 
  532        content_length += lseek(fd, 0, SEEK_END);
 
  533        lseek(fd, 0, SEEK_SET);
 
  546        "Content-Length: %d\r\n" 
  549        status_code, status_title ? status_title : 
"OK",
 
  552        close_connection ? 
"Connection: close\r\n" : 
"",
 
  553        static_content ? 
"" : 
"Cache-Control: no-cache, no-store\r\n",
 
  558        ast_debug(1, 
"ast_iostream_printf() failed: %s\n", strerror(
errno));
 
  559        close_connection = 1;
 
  560    } 
else if (send_content && fd) {
 
  562        while ((
len = read(fd, 
buf, 
sizeof(
buf))) > 0) {
 
  564                ast_debug(1, 
"ast_iostream_write() failed: %s\n", strerror(
errno));
 
  565                close_connection = 1;
 
  575    if (close_connection) {
 
  576        ast_debug(1, 
"HTTP closing session.  status_code:%d\n", status_code);
 
  579        ast_debug(1, 
"HTTP keeping session open.  status_code:%d\n", status_code);
 
 
  584    const char *status_title, 
struct ast_str *http_header_data, 
const char *text)
 
  590    if (!http_header_data || !server_address || !
out) {
 
  595            ast_debug(1, 
"HTTP closing session. OOM.\n");
 
  605                    "<address>%s</address>\r\n",
 
  611                "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 
  613                "<title>%d %s</title>\r\n" 
  619                "</body></html>\r\n",
 
 
  639    const unsigned long nonce, 
const unsigned long opaque, 
int stale,
 
  642    int status_code = 401;
 
  643    char *status_title = 
"Unauthorized";
 
  646    if (http_header_data) {
 
  649                    "WWW-authenticate: Digest algorithm=MD5, realm=\"%s\", nonce=\"%08lx\", qop=\"auth\", opaque=\"%08lx\"%s\r\n" 
  650                    "Content-type: text/html\r\n",
 
  651                    realm ? realm : 
"Asterisk",
 
  654                    stale ? 
", stale=true" : 
"");
 
 
  665    const char *status_title, 
const char *text)
 
  669    if (http_header_data) {
 
  670        ast_str_set(&http_header_data, 0, 
"Content-type: text/html\r\n");
 
 
  692    int len = strlen(urih->
uri);
 
 
  733        if (!strcmp(urih->
key, 
key)) {
 
 
  759    for (v = headers; v; v = v->
next) {
 
  760        if (!strcasecmp(v->
name, field_name)) {
 
 
  780    const char *content_type = 
get_header(headers, 
"Content-Type");
 
  788    param = strchr(content_type, 
';');
 
  789    size = param ? param - content_type : strlen(content_type);
 
 
  805    const char *content_length = 
get_header(headers, 
"Content-Length");
 
  808    if (!content_length) {
 
  814    if (sscanf(content_length, 
"%30d", &length) != 1) {
 
 
  830    return get_header(headers, 
"Transfer-Encoding");
 
 
  844    const char *connection = 
get_header(headers, 
"Connection");
 
  845    int close_connection = 0;
 
  847    if (connection && !strcasecmp(connection, 
"close")) {
 
  848        close_connection = -1;
 
  850    return close_connection;
 
 
  889    const char *transfer_encoding;
 
  896    if (transfer_encoding && !strcasecmp(transfer_encoding, 
"chunked")) {
 
  903    if (0 < 
request->body_length) {
 
  905    } 
else if (
request->body_length < 0) {
 
  908        ast_http_error(ser, 400, 
"Bad Request", 
"Invalid Content-Length in request!");
 
 
  949    while (
total != length) {
 
  958    if (
total != length) {
 
  960            what_getting, length, res);
 
 
  986            what_getting, length, res);
 
 
 1020                if (*s++ == 
'\x0D') {
 
 1027        if (
c >= 
'0' && 
c <= 
'9') {
 
 1031        if (
c >= 
'a' && 
c <= 
'f') {
 
 1035        if (
c >= 
'A' && 
c <= 
'F') {
 
 
 1066    length = 
chunked_atoh(header_line, strlen(header_line));
 
 
 1091    if (res < 
sizeof(chunk_sync)) {
 
 1093            sizeof(chunk_sync));
 
 1096    if (chunk_sync[0] != 0x0D || chunk_sync[1] != 0x0A) {
 
 1098            (
unsigned char) chunk_sync[0], (
unsigned char) chunk_sync[1]);
 
 
 1147    ast_debug(1, 
"HTTP discarding unused request body\n");
 
 1150    if (0 < 
request->body_length) {
 
 
 1217    ast_debug(2, 
"HTTP consuming request body\n");
 
 1220    if (0 < 
request->body_length) {
 
 1222        content_length = 
request->body_length;
 
 1244        buf[content_length] = 0;
 
 1245        *return_length = content_length;
 
 1263        if (chunk_length < 0) {
 
 1269        if (chunk_length == 0) {
 
 1275                "Excessively long HTTP accumulated chunked body. (%d + %d > %d)\n",
 
 1284        if (content_length + chunk_length >= bufsize) {
 
 1290            } 
while (content_length + chunk_length >= bufsize);
 
 1308        content_length += chunk_length;
 
 1325    buf[content_length] = 0;
 
 1326    *return_length = content_length;
 
 
 1333    int content_length = 0;
 
 1347    if (!
buf || !content_length) {
 
 
 1370    const char *content_type)
 
 1379        strcasecmp(content_type, 
"application/x-www-form-urlencoded") != 0) {
 
 
 1408    int content_length = 0;
 
 1416        strcasecmp(
type, 
"application/x-www-form-urlencoded")) {
 
 1422    if (!
buf || !content_length) {
 
 
 1444    ast_debug(2, 
"HTTP Request URI is %s \n", uri);
 
 1472        if (!strcasecmp(uri, redirect->
target)) {
 
 1492    if (!strncasecmp(uri, 
prefix, l) && uri[l] == 
'/') {
 
 1497            l = strlen(urih->
uri);
 
 1499            ast_debug(2, 
"match request [%s] with handler [%s] len %d\n", uri, urih->
uri, l);
 
 1500            if (strncasecmp(urih->
uri, uri, l) 
 
 1501                || (*
c && *
c != 
'/')) { 
 
 1521        ast_debug(1, 
"Requested URI [%s] has no handler\n", uri);
 
 1522        ast_http_error(ser, 404, 
"Not Found", 
"The requested URL was not found on this server.");
 
 
 1536    while ((cur = 
strsep(&parse, 
";"))) {
 
 
 1568    for (v = headers; v; v = v->
next) {
 
 1569        if (!strcasecmp(v->
name, 
"Cookie")) {
 
 
 1581    size_t password_len;
 
 1588    userid_len = strlen(
userid) + 1;
 
 1589    password_len = strlen(
password) + 1;
 
 1592    auth = 
ao2_alloc(
sizeof(*auth) + userid_len + password_len, 
NULL);
 
 1598    auth->
userid = (
char *)(auth + 1);
 
 
 1608#define BASIC_PREFIX "Basic " 
 1615    for (v = headers; v; v = v->
next) {
 
 1617        char decoded[256] = {};
 
 1624        if (strcasecmp(
"Authorization", v->
name) != 0) {
 
 1630                "Unsupported Authorization scheme\n");
 
 1651            sizeof(decoded) - 1);
 
 1656        username = 
strsep(&password, 
":");
 
 
 1669    const char *password)
 
 1671    int encoded_size = 0;
 
 1672    int userinfo_len = 0;
 
 1674    char *encoded_userinfo = 
NULL;
 
 1681    if (strchr(userid, 
':')) {
 
 1683        userinfo_len = strlen(userinfo);
 
 1688        userinfo_len = 
ast_asprintf(&userinfo, 
"%s:%s", userid, password);
 
 1700    encoded_size = userinfo_len * 2 * 
sizeof(char) + 1 + 
BASIC_LEN;
 
 1704        userinfo_len, encoded_size - 
BASIC_LEN);
 
 1707        encoded_userinfo, 
"");
 
 
 1715    size_t size = strlen(
version);
 
 1726    if (sscanf(
buf, 
"%d", &status_code) != 1) {
 
 
 1751        if (buf_end != 
buf) {
 
 1755        memcpy(buf_end, p, s - p);
 
 
 1787              const char *
value, 
const char *expected_value)
 
 1789    if (strcasecmp(
name, expected_name)) {
 
 1794    if (strcasecmp(
value, expected_value)) {
 
 1796            "received %s", 
value, expected_value);
 
 
 1803                 const char *
value, 
const char *expected_value)
 
 1805    if (strcasecmp(
name, expected_name)) {
 
 1812            "in '%s'\n", 
name, 
value, expected_value);
 
 
 1820#define MAX_HTTP_REQUEST_HEADERS    100 
 1836    int remaining_headers;
 
 1850        if (header_line[
len - 1] != 
'\n') {
 
 1853                (
len == 
sizeof(header_line) - 1) ? 
"Header line too long" : 
"Timeout");
 
 1864        value = header_line;
 
 1877        if (!remaining_headers--) {
 
 1879            ast_http_error(ser, 413, 
"Request Entity Too Large", 
"Too many headers");
 
 
 1920    const char *transfer_encoding;
 
 1936    if (request_line[
len - 1] != 
'\n') {
 
 1939            (
len == 
sizeof(request_line) - 1) ? 
"Request line too long" : 
"Timeout");
 
 1950    if (!strcasecmp(
method,
"GET")) {
 
 1952    } 
else if (!strcasecmp(
method,
"POST")) {
 
 1954    } 
else if (!strcasecmp(
method,
"HEAD")) {
 
 1956    } 
else if (!strcasecmp(
method,
"PUT")) {
 
 1958    } 
else if (!strcasecmp(
method,
"DELETE")) {
 
 1960    } 
else if (!strcasecmp(
method,
"OPTIONS")) {
 
 1977        ast_http_error(ser, 503, 
"Service Unavailable", 
"Shutdown in progress");
 
 1988    if (!transfer_encoding) {
 
 1989        transfer_encoding = 
"identity";
 
 1996    if (strcasecmp(transfer_encoding, 
"identity") != 0 &&
 
 1997        strcasecmp(transfer_encoding, 
"chunked") != 0) {
 
 1999        ast_http_error(ser, 501, 
"Unimplemented", 
"Unsupported Transfer-Encoding.");
 
 2004        || 
handle_uri(ser, uri, http_method, headers)
 
 
 2029    ast_debug(1, 
"HTTP opening session.  Top level\n");
 
 2086    ast_debug(1, 
"HTTP closing session.  Top level\n");
 
 
 2100    char *target, *dest;
 
 2102    unsigned int target_len;
 
 2103    unsigned int total_len;
 
 2117    target_len = strlen(
target) + 1;
 
 2118    dest_len = strlen(
dest) + 1;
 
 2119    total_len = 
sizeof(*redirect) + target_len + dest_len;
 
 2121    if (!(redirect = 
ast_calloc(1, total_len))) {
 
 2124    redirect->
dest = redirect->
target + target_len;
 
 
 2154#define HTTP_SERVER_BUCKETS 5 
 2167    ast_verb(1, 
"Stopped http server '%s' listening at '%s'\n", server->
name, server->
address);
 
 
 2180        ast_log(
LOG_ERROR, 
"Unable to allocate HTTP server '%s' at address '%s'\n",
 
 2186        ast_log(
LOG_ERROR, 
"Unable to complete setup for HTTP server '%s' at address '%s'\n",
 
 
 2253    if (
ao2_ref(server, -1) == 2) {
 
 
 2317    for (i = 0; i < num_addrs; ++i) {
 
 
 2364        if (*replace_me == server) {
 
 2374        *replace_me = server;
 
 
 2390#ifdef TEST_FRAMEWORK 
 2415        host = 
"localhost:8088";
 
 2419        name = 
"http test server";
 
 2445    int new_static_uri_enabled = 0;
 
 2446    int new_status_uri_enabled = 1; 
 
 2452    int http_tls_was_enabled = 0;
 
 2485    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");
 
 2499    snprintf(server_name, 
sizeof(server_name), 
"Asterisk/%s", 
ast_get_version());
 
 2502    for (; v; v = v->
next) {
 
 2504        if (strcasecmp(v->
name, 
"tlscafile")
 
 2505            && strcasecmp(v->
name, 
"tlscapath")
 
 2506            && strcasecmp(v->
name, 
"tlscadir")
 
 2507            && strcasecmp(v->
name, 
"tlsverifyclient")
 
 2508            && strcasecmp(v->
name, 
"tlsdontverifyserver")
 
 2509            && strcasecmp(v->
name, 
"tlsclientmethod")
 
 2510            && strcasecmp(v->
name, 
"sslclientmethod")
 
 2515        if (!strcasecmp(v->
name, 
"servername")) {
 
 2519                server_name[0] = 
'\0';
 
 2521        } 
else if (!strcasecmp(v->
name, 
"enabled")) {
 
 2523        } 
else if (!strcasecmp(v->
name, 
"enablestatic") || !strcasecmp(v->
name, 
"enable_static")) {
 
 2525        } 
else if (!strcasecmp(v->
name, 
"enable_status")) {
 
 2527        } 
else if (!strcasecmp(v->
name, 
"bindport")) {
 
 2533        } 
else if (!strcasecmp(v->
name, 
"bindaddr")) {
 
 2535        } 
else if (!strcasecmp(v->
name, 
"prefix")) {
 
 2540                newprefix[0] = 
'\0';
 
 2542        } 
else if (!strcasecmp(v->
name, 
"redirect")) {
 
 2544        } 
else if (!strcasecmp(v->
name, 
"sessionlimit")) {
 
 2550        } 
else if (!strcasecmp(v->
name, 
"session_inactivity")) {
 
 2556        } 
else if (!strcasecmp(v->
name, 
"session_keep_alive")) {
 
 2570    if (strcmp(
prefix, newprefix)) {
 
 
 2639        e->
command = 
"http show status";
 
 2641            "Usage: http show status\n" 
 2642            "       Lists status of internal HTTP engine\n";
 
 2651    ast_cli(
a->fd, 
"HTTP Server Status:\n");
 
 2655        ast_cli(
a->fd, 
"Server Disabled\n\n");
 
 2657        ast_cli(
a->fd, 
"Server Enabled and Bound to %s\n\n",
 
 2660            ast_cli(
a->fd, 
"HTTPS Server Enabled and Bound to %s\n\n",
 
 2665    ast_cli(
a->fd, 
"Enabled URI's:\n");
 
 2675    ast_cli(
a->fd, 
"\nEnabled Redirects:\n");
 
 
 2754    .
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 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 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
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