Asterisk - The Open Source Telephony Project GIT-master-a63eec2
|
http server for AMI access More...
#include "asterisk.h"
#include <time.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
#include "asterisk/paths.h"
#include "asterisk/cli.h"
#include "asterisk/tcptls.h"
#include "asterisk/http.h"
#include "asterisk/utils.h"
#include "asterisk/strings.h"
#include "asterisk/config.h"
#include "asterisk/stringfields.h"
#include "asterisk/ast_version.h"
#include "asterisk/manager.h"
#include "asterisk/module.h"
#include "asterisk/astobj2.h"
#include "asterisk/netsock2.h"
#include "asterisk/json.h"
Go to the source code of this file.
Data Structures | |
struct | ast_cfhttp_methods_text |
struct | ast_http_server |
struct | http_uri_redirect |
struct | http_worker_private_data |
struct | uri_redirects |
struct | uris |
Macros | |
#define | BASIC_LEN 6 |
#define | BASIC_PREFIX "Basic " |
#define | DEFAULT_PORT 8088 |
#define | DEFAULT_RESPONSE_HEADER_LENGTH 512 |
#define | DEFAULT_SESSION_INACTIVITY 30000 |
#define | DEFAULT_SESSION_KEEP_ALIVE 15000 |
#define | DEFAULT_SESSION_LIMIT 100 |
#define | DEFAULT_TLS_PORT 8089 |
#define | HTTP_SERVER_BUCKETS 5 |
Number of HTTP server buckets. | |
#define | INITIAL_RESPONSE_BODY_BUFFER 1024 |
#define | MAX_CONTENT_LENGTH 40960 |
#define | MAX_HTTP_LINE_LENGTH 4096 |
#define | MAX_HTTP_REQUEST_HEADERS 100 |
#define | MAX_PREFIX 80 |
#define | MAX_SERVER_NAME_LENGTH 128 |
#define | MIN_INITIAL_REQUEST_TIMEOUT 10000 |
Enumerations | |
enum | http_private_flags { HTTP_FLAG_HAS_BODY = (1 << 0) , HTTP_FLAG_BODY_READ = (1 << 1) , HTTP_FLAG_CLOSE_ON_COMPLETION = (1 << 2) } |
Functions | |
static int | __ast_http_load (int reload) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
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 URI handlers. | |
AO2_STRING_FIELD_CMP_FN (ast_http_server, address) | |
AO2_STRING_FIELD_HASH_FN (ast_http_server, address) | |
const char * | ast_get_http_method (enum ast_http_method method) |
Return http method name string. | |
enum ast_http_method | ast_get_http_method_from_string (const char *method) |
Return http method from string. | |
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. | |
int | ast_http_body_discard (struct ast_tcptls_session_instance *ser) |
Read and discard any unread HTTP request body. | |
void | ast_http_body_read_status (struct ast_tcptls_session_instance *ser, int read_success) |
Update the body read success status. | |
struct ast_variable * | ast_http_create_basic_auth_header (const char *userid, const char *password) |
Create an HTTP authorization header. | |
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. | |
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. | |
const char * | ast_http_ftype2mtype (const char *ftype) |
Return mime type based on extension. | |
struct ast_http_auth * | ast_http_get_auth (struct ast_variable *headers) |
Get HTTP authentication information from headers. | |
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. | |
struct ast_variable * | ast_http_get_cookies (struct ast_variable *headers) |
Get cookie from Request 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. | |
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-urlencoded. | |
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. | |
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 be located in the expected value. | |
int | ast_http_header_parse (char *buf, char **name, char **value) |
Parse a header into the given name/value strings. | |
uint32_t | ast_http_manid_from_vars (struct ast_variable *headers) |
Return manager id, if exist, from request headers. | |
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. | |
void | ast_http_prefix (char *buf, int len) |
Return the current prefix. | |
void | ast_http_request_close_on_completion (struct ast_tcptls_session_instance *ser) |
Request the HTTP connection be closed after this 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_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. | |
int | ast_http_uri_link (struct ast_http_uri *urih) |
Link the new uri into the list. | |
void | ast_http_uri_unlink (struct ast_http_uri *urih) |
Unregister a URI handler. | |
void | ast_http_uri_unlink_all_with_key (const char *key) |
Unregister all handlers with matching key. | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static struct ast_http_auth * | auth_create (const char *userid, const char *password) |
static int | chunked_atoh (const char *s, int len) |
static int | get_content_length (struct ast_variable *headers) |
Returns the value of the Content-Length header. | |
static char * | get_content_type (struct ast_variable *headers) |
Retrieves the content type specified in the "Content-Type" header. | |
static const char * | get_header (struct ast_variable *headers, const char *field_name) |
Retrieves the header with the given field name. | |
static const char * | get_transfer_encoding (struct ast_variable *headers) |
Returns the value of the Transfer-Encoding header. | |
static char * | handle_show_http (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | handle_uri (struct ast_tcptls_session_instance *ser, char *uri, enum ast_http_method method, struct ast_variable *headers) |
static int | http_body_check_chunk_sync (struct ast_tcptls_session_instance *ser) |
static int | http_body_discard_chunk_trailer_headers (struct ast_tcptls_session_instance *ser) |
static int | http_body_discard_contents (struct ast_tcptls_session_instance *ser, int length, const char *what_getting) |
static int | http_body_get_chunk_length (struct ast_tcptls_session_instance *ser) |
static int | http_body_read_contents (struct ast_tcptls_session_instance *ser, char *buf, int length, const char *what_getting) |
static int | http_check_connection_close (struct ast_variable *headers) |
static int | http_request_headers_get (struct ast_tcptls_session_instance *ser, struct ast_variable **headers) |
static void | http_request_tracking_init (struct http_worker_private_data *request) |
static int | http_request_tracking_setup (struct ast_tcptls_session_instance *ser, struct ast_variable *headers) |
static struct ast_http_server * | http_server_create (const char *name, const char *address, const struct ast_sockaddr *addr) |
static void | http_server_destroy (void *obj) |
static void | http_server_discard (struct ast_http_server *server) |
Discard/Drop a HTTP server. | |
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. | |
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_server * | http_server_get_by_host (const char *name, const char *host, uint32_t port) |
Retrieve, or create a HTTP server object by host. | |
static int | http_server_start (struct ast_http_server *server) |
static void * | httpd_helper_thread (void *arg) |
static int | httpd_process_request (struct ast_tcptls_session_instance *ser) |
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) |
static int | load_module (void) |
static struct ast_variable * | parse_cookies (const char *cookies) |
static int | reload_module (void) |
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) |
static int | unload_module (void) |
http server for AMI access
This program implements a tiny http server and was inspired by micro-httpd by Jef Poskanzer
GMime http://spruce.sourceforge.net/gmime/
AMI over HTTP support - AMI over the http protocol
Definition in file http.c.
#define DEFAULT_RESPONSE_HEADER_LENGTH 512 |
#define DEFAULT_SESSION_INACTIVITY 30000 |
#define DEFAULT_SESSION_KEEP_ALIVE 15000 |
#define HTTP_SERVER_BUCKETS 5 |
#define INITIAL_RESPONSE_BODY_BUFFER 1024 |
#define MAX_CONTENT_LENGTH 40960 |
#define MAX_HTTP_LINE_LENGTH 4096 |
#define MAX_HTTP_REQUEST_HEADERS 100 |
#define MAX_SERVER_NAME_LENGTH 128 |
#define MIN_INITIAL_REQUEST_TIMEOUT 10000 |
enum http_private_flags |
Definition at line 455 of file http.c.
|
static |
Definition at line 2440 of file http.c.
References ast_tcptls_session_args::accept_fd, add_redirect(), ast_http_server::args, AST_CERTFILE, ast_config_destroy(), ast_config_load2(), ast_copy_string(), ast_free, ast_get_version(), ast_http_uri_link(), ast_http_uri_unlink(), ast_log, ast_parse_arg(), AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_setnull(), AST_SSL_DISABLE_TLSV1, AST_SSL_SERVER_CIPHER_ORDER, ast_ssl_setup(), ast_strdup, ast_strdupa, ast_strlen_zero(), ast_tcptls_server_start(), ast_tcptls_server_stop(), ast_tls_read_conf(), ast_true(), ast_variable_browse(), bindaddr, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_PORT, DEFAULT_SESSION_INACTIVITY, DEFAULT_SESSION_KEEP_ALIVE, DEFAULT_SESSION_LIMIT, DEFAULT_TLS_PORT, ast_tls_config::enabled, enabled, ast_tls_config::flags, global_http_server, http_server_discard(), http_server_get(), http_server_name, http_tls_cfg, https_desc, ast_variable::lineno, ast_tcptls_session_args::local_address, LOG_WARNING, MAX_PREFIX, MAX_SERVER_NAME_LENGTH, ast_variable::name, ast_variable::next, NULL, PARSE_DEFAULT, PARSE_IN_RANGE, PARSE_INT32, PARSE_UINT32, prefix, ast_tls_config::pvtfile, reload(), session_inactivity, session_keep_alive, session_limit, static_uri, static_uri_enabled, status_uri, status_uri_enabled, ast_tcptls_session_args::tls_cfg, and ast_variable::value.
Referenced by load_module(), and reload_module().
|
static |
Add a new URI redirect The entries in the redirect list are sorted by length, just like the list of URI handlers.
Definition at line 2098 of file http.c.
References ast_calloc, ast_copy_string(), ast_log, AST_RWLIST_EMPTY, AST_RWLIST_FIRST, AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_INSERT_TAIL, AST_RWLIST_NEXT, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_skip_blanks(), ast_strdupa, http_uri_redirect::dest, http_uri_redirect::entry, LOG_WARNING, strsep(), http_uri_redirect::target, and value.
Referenced by __ast_http_load().
AO2_STRING_FIELD_CMP_FN | ( | ast_http_server | , |
address | |||
) |
AO2_STRING_FIELD_HASH_FN | ( | ast_http_server | , |
address | |||
) |
const char * ast_get_http_method | ( | enum ast_http_method | method | ) |
Return http method name string.
Definition at line 193 of file http.c.
References ARRAY_LEN, ast_http_methods_text, method, NULL, and ast_cfhttp_methods_text::text.
Referenced by add_allow_header(), ast_ari_callback(), ast_ari_invoke(), auth_http_callback(), and handle_options().
enum ast_http_method ast_get_http_method_from_string | ( | const char * | method | ) |
Return http method from string.
Definition at line 206 of file http.c.
References ARRAY_LEN, ast_http_methods_text, AST_HTTP_UNKNOWN, ast_strings_equal(), ast_cfhttp_methods_text::method, method, and text.
Referenced by parse_rest_request_msg().
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 at line 638 of file http.c.
References ast_http_create_response(), ast_str_create, ast_str_set(), DEFAULT_RESPONSE_HEADER_LENGTH, and text.
int ast_http_body_discard | ( | struct ast_tcptls_session_instance * | ser | ) |
Read and discard any unread HTTP request body.
ser | HTTP TCP/TLS session object. |
0 | on success. |
-1 | on error. |
Definition at line 1135 of file http.c.
References ast_assert, ast_debug, ast_set_flag, ast_test_flag, http_body_check_chunk_sync(), http_body_discard_chunk_trailer_headers(), http_body_discard_contents(), http_body_get_chunk_length(), HTTP_FLAG_BODY_READ, HTTP_FLAG_CLOSE_ON_COMPLETION, HTTP_FLAG_HAS_BODY, ast_tcptls_session_instance::private_data, and request().
Referenced by ast_http_send(), and ast_websocket_uri_cb().
void ast_http_body_read_status | ( | struct ast_tcptls_session_instance * | ser, |
int | read_success | ||
) |
Update the body read success status.
ser | HTTP TCP/TLS session object. |
read_success | TRUE if body was read successfully. |
Definition at line 914 of file http.c.
References ast_set_flag, ast_test_flag, HTTP_FLAG_BODY_READ, HTTP_FLAG_CLOSE_ON_COMPLETION, HTTP_FLAG_HAS_BODY, ast_tcptls_session_instance::private_data, and request().
Referenced by http_post_callback().
struct ast_variable * ast_http_create_basic_auth_header | ( | const char * | userid, |
const char * | password | ||
) |
Create an HTTP authorization header.
The returned ast_variable must be freed with ast_variables_destroy()
userid | User ID or "<userid>:<password>". |
password | Password if not in userid. |
NULL | if memory allocation failed. |
Definition at line 1668 of file http.c.
References ast_alloca, ast_asprintf, ast_base64encode(), ast_free, ast_strdup, ast_strlen_zero(), ast_variable_new, BASIC_LEN, BASIC_PREFIX, NULL, and RAII_VAR.
Referenced by outbound_session_handler_thread(), and websocket_client_handshake().
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.
ser | TCP/TLS session object |
status_code | HTTP response code (200/401/403/404/500) |
status_title | English equivalent to the status_code parameter |
http_header_data | The formatted text to use in the http header |
text | Additional informational text to use in the response |
The response body is created as HTML content, from the status_code, status_title, and the text parameters.
The http_header_data parameter will be freed as a result of calling function.
Definition at line 583 of file http.c.
References ast_debug, ast_free, ast_http_send(), AST_HTTP_UNKNOWN, ast_str_buffer(), ast_str_create, ast_str_set(), ast_strlen_zero(), ast_tcptls_close_session_file(), ast_xml_escape(), http_server_name, INITIAL_RESPONSE_BODY_BUFFER, MAX_SERVER_NAME_LENGTH, out, and text.
Referenced by ast_http_auth(), and ast_http_error().
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.
Definition at line 664 of file http.c.
References ast_http_create_response(), ast_str_create, ast_str_set(), DEFAULT_RESPONSE_HEADER_LENGTH, and text.
Referenced by ast_ari_callback(), ast_websocket_uri_cb(), auth_http_callback(), generic_http_callback(), handle_uri(), http_callback(), http_post_callback(), http_request_headers_get(), http_request_tracking_setup(), httpd_helper_thread(), httpd_process_request(), httpstatus_callback(), incoming_ws_http_callback(), phoneprov_callback(), static_callback(), and websocket_bad_request().
const char * ast_http_ftype2mtype | ( | const char * | ftype | ) |
Return mime type based on extension.
ftype | filename extension |
Definition at line 219 of file http.c.
References ARRAY_LEN, ext, mimetypes, and NULL.
Referenced by build_profile(), and static_callback().
struct ast_http_auth * ast_http_get_auth | ( | struct ast_variable * | headers | ) |
Get HTTP authentication information from headers.
The returned object is AO2 managed, so clean up with ao2_cleanup().
headers | HTTP request headers. |
NULL | if no supported HTTP auth headers present. |
Definition at line 1611 of file http.c.
References ast_assert, ast_base64decode(), ast_begins_with(), ast_log, auth_create(), base64, BASIC_LEN, BASIC_PREFIX, LOG_DEBUG, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, strsep(), and ast_variable::value.
Referenced by authenticate_user(), and http_callback().
|
static |
Returns the contents (body) of the HTTP request.
return_length | ptr to int that returns content length |
ser | HTTP TCP/TLS session object |
headers | List of HTTP headers |
NULL | on failure |
Definition at line 1197 of file http.c.
References ast_assert, ast_debug, ast_free, ast_log, ast_malloc, ast_realloc, ast_set_flag, ast_test_flag, buf, errno, http_body_check_chunk_sync(), http_body_discard_chunk_trailer_headers(), http_body_get_chunk_length(), http_body_read_contents(), HTTP_FLAG_BODY_READ, HTTP_FLAG_CLOSE_ON_COMPLETION, HTTP_FLAG_HAS_BODY, LOG_WARNING, MAX_CONTENT_LENGTH, NULL, ast_tcptls_session_instance::private_data, and request().
Referenced by ast_http_get_json(), and ast_http_get_post_vars().
struct ast_variable * ast_http_get_cookies | ( | struct ast_variable * | headers | ) |
Get cookie from Request headers.
Definition at line 1564 of file http.c.
References ast_variables_destroy(), ast_variable::name, ast_variable::next, NULL, parse_cookies(), and ast_variable::value.
Referenced by ast_http_manid_from_vars(), and httpstatus_callback().
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.
ser | TCP/TLS session object |
headers | List of HTTP headers |
NULL | on error, if no content, or if different content type. |
Definition at line 1330 of file http.c.
References ast_free, ast_http_get_contents(), ast_json_load_buf(), ast_strlen_zero(), buf, errno, get_content_type(), NULL, RAII_VAR, and type.
Referenced by ast_ari_callback().
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-urlencoded.
ser | TCP/TLS session object |
headers | List of HTTP headers |
Definition at line 1405 of file http.c.
References ast_free, ast_http_get_contents(), ast_http_parse_post_form(), ast_strlen_zero(), buf, errno, get_content_type(), NULL, RAII_VAR, and type.
Referenced by ast_ari_callback(), auth_http_callback(), and generic_http_callback().
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.
name | header name to check |
expected_name | the expected name of the header |
value | header value to check |
expected_value | the expected value of the header |
0 | if the name and expected name do not match |
-1 | if the value and expected value do not match |
1 | if the both the name and value match their expected value |
Definition at line 1786 of file http.c.
References ast_log, LOG_ERROR, name, and value.
Referenced by websocket_client_handshake_get_response().
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 be located in the expected value.
name | header name to check |
expected_name | the expected name of the header |
value | header value to check if in expected value |
expected_value | the expected value(s) |
0 | if the name and expected name do not match |
-1 | if the value and is not in the expected value |
1 | if the name matches expected name and value is in expected value |
Definition at line 1802 of file http.c.
References ast_log, LOG_ERROR, name, strcasestr(), and value.
Referenced by websocket_client_handshake_get_response().
int ast_http_header_parse | ( | char * | buf, |
char ** | name, | ||
char ** | value | ||
) |
Parse a header into the given name/value strings.
buf | a string containing the name/value to point to | |
[out] | name | header name |
[out] | value | header value |
-1 | if buf is empty |
0 | if buf could be separated into name and value |
1 | if name or value portion don't exist |
Definition at line 1764 of file http.c.
References ast_skip_blanks(), ast_strlen_zero(), ast_trim_blanks(), buf, name, remove_excess_lws(), strsep(), and value.
Referenced by websocket_client_handshake_get_response().
uint32_t ast_http_manid_from_vars | ( | struct ast_variable * | headers | ) |
Return manager id, if exist, from request headers.
headers | List of HTTP headers |
Definition at line 233 of file http.c.
References ast_http_get_cookies(), ast_variables_destroy(), ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by generic_http_callback(), http_post_callback(), and static_callback().
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.
buf | input buffer |
content_len | Buffer length |
content_type | Content type (must be "application/x-www-form-urlencoded") |
Definition at line 1369 of file http.c.
References ast_strlen_zero(), ast_uri_decode(), ast_uri_http_legacy, ast_variable_new, buf, errno, NULL, strsep(), and var.
Referenced by ast_http_get_post_vars(), and parse_rest_request_msg().
void ast_http_prefix | ( | char * | buf, |
int | len | ||
) |
Return the current prefix.
[out] | buf | destination buffer for previous |
[in] | len | length of prefix to copy |
Definition at line 249 of file http.c.
References ast_copy_string(), buf, len(), and prefix.
void ast_http_request_close_on_completion | ( | struct ast_tcptls_session_instance * | ser | ) |
Request the HTTP connection be closed after this HTTP request.
ser | HTTP TCP/TLS session object. |
Definition at line 853 of file http.c.
References ast_set_flag, HTTP_FLAG_CLOSE_ON_COMPLETION, ast_tcptls_session_instance::private_data, and request().
Referenced by ast_ari_callback(), ast_ari_invoke(), auth_http_callback(), generic_http_callback(), handle_uri(), http_callback(), http_post_callback(), httpstatus_callback(), static_callback(), and websocket_bad_request().
int ast_http_response_status_line | ( | const char * | buf, |
const char * | version, | ||
int | code | ||
) |
Parse the http response status line.
buf | the http response line information |
version | the expected http version (e.g. HTTP/1.1) |
code | the expected status code |
-1 | if version didn't match or status code conversion fails. |
Definition at line 1712 of file http.c.
References ast_log, buf, LOG_ERROR, and version.
Referenced by websocket_client_handshake_get_response().
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.
ser | TCP/TLS session object |
method | GET/POST/HEAD |
status_code | HTTP response code (200/401/403/404/500) |
status_title | English equivalent to the status_code parameter |
http_header | An ast_str object containing all headers |
out | An ast_str object containing the body of the response |
fd | If out is NULL, a file descriptor where the body of the response is held (otherwise -1) |
static_content | Zero if the content is dynamically generated and should not be cached; nonzero otherwise |
Extra HTTP headers MUST be present only in the http_header argument. The argument "out" should contain only content of the response (no headers!).
HTTP content can be constructed from the argument "out", if it is not NULL; otherwise, the function will read content from FD.
This function calculates the content-length http header itself.
Both the http_header and out arguments will be freed by this function; however, if FD is open, it will remain open.
Definition at line 472 of file http.c.
References ast_assert, ast_debug, ast_free, ast_http_body_discard(), AST_HTTP_HEAD, ast_iostream_printf(), ast_iostream_write(), ast_localtime(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_strlen(), ast_strftime(), ast_strlen_zero(), ast_tcptls_close_session_file(), ast_test_flag, ast_tvnow(), buf, errno, HTTP_FLAG_CLOSE_ON_COMPLETION, http_server_name, len(), MAX_SERVER_NAME_LENGTH, method, out, ast_tcptls_session_instance::private_data, request(), session_keep_alive, and ast_tcptls_session_instance::stream.
Referenced by ast_ari_callback(), ast_http_create_response(), auth_http_callback(), generic_http_callback(), handle_uri(), http_callback(), http_callback(), httpstatus_callback(), phoneprov_callback(), static_callback(), and websocket_bad_request().
int ast_http_uri_link | ( | struct ast_http_uri * | urih | ) |
Link the new uri into the list.
Register a URI handler.
They are sorted by length of the string, not alphabetically. Duplicate entries are not replaced, but the insertion order (using <= and not just <) makes sure that more recent insertions hide older ones. On a lookup, we just scan the list and stop at the first matching entry.
Definition at line 689 of file http.c.
References AST_RWLIST_EMPTY, AST_RWLIST_FIRST, AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_INSERT_TAIL, AST_RWLIST_NEXT, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_http_uri::entry, len(), ast_http_uri::prefix, prefix, and ast_http_uri::uri.
Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), load_module(), load_module(), load_module(), load_module(), load_module(), load_module(), reload_module(), and reload_module().
void ast_http_uri_unlink | ( | struct ast_http_uri * | urih | ) |
Unregister a URI handler.
Definition at line 721 of file http.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_http_uri::entry.
Referenced by __ast_http_load(), __init_manager(), load_module(), reload_module(), reload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), and unload_module().
void ast_http_uri_unlink_all_with_key | ( | const char * | key | ) |
Unregister all handlers with matching key.
Definition at line 728 of file http.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_http_uri::data, ast_http_uri::dmallocd, ast_http_uri::entry, ast_http_uri::key, and ast_http_uri::mallocd.
Referenced by __ast_http_post_load(), and unload_module().
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
|
static |
Definition at line 1577 of file http.c.
References ao2_alloc, ast_log, LOG_ERROR, NULL, ast_http_auth::password, and ast_http_auth::userid.
Referenced by ast_http_get_auth().
|
static |
Definition at line 1002 of file http.c.
References c, len(), and value.
Referenced by http_body_get_chunk_length().
|
static |
Returns the value of the Content-Length header.
headers | HTTP headers. |
0 | if header is not present. |
-1 | if header is invalid. |
Definition at line 803 of file http.c.
References get_header().
Referenced by http_request_tracking_setup().
|
static |
Retrieves the content type specified in the "Content-Type" header.
This function only returns the "type/subtype" and any trailing parameter is not included.
NULL | if the header is not found. |
Definition at line 778 of file http.c.
References ast_strndup, get_header(), and NULL.
Referenced by ast_http_get_json(), and ast_http_get_post_vars().
|
static |
Retrieves the header with the given field name.
headers | Headers to search. |
field_name | Name of the header to find. |
NULL | if header is not present. |
Definition at line 755 of file http.c.
References ast_variable::name, ast_variable::next, NULL, and ast_variable::value.
Referenced by get_content_length(), get_content_type(), get_transfer_encoding(), and http_check_connection_close().
|
static |
Returns the value of the Transfer-Encoding header.
headers | HTTP headers. |
NULL | if header is not present. |
Definition at line 828 of file http.c.
References get_header().
Referenced by http_request_tracking_setup(), and httpd_process_request().
|
static |
Definition at line 2632 of file http.c.
References a, ast_http_server::args, ast_cli(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_sockaddr_stringify(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_http_uri::description, http_uri_redirect::dest, ast_tls_config::enabled, http_uri_redirect::entry, global_http_server, ast_http_uri::has_subtree, http_server_name, http_tls_cfg, https_desc, NULL, ast_tcptls_session_args::old_address, prefix, http_uri_redirect::target, ast_http_uri::uri, and ast_cli_entry::usage.
|
static |
Definition at line 1433 of file http.c.
References ast_debug, ast_http_error(), ast_http_request_close_on_completion(), ast_http_send(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_str_create, ast_str_set(), ast_uri_decode(), ast_uri_http_legacy, ast_variable_new, ast_variables_destroy(), c, ast_http_uri::callback, cleanup(), http_uri_redirect::dest, http_uri_redirect::entry, ast_http_uri::has_subtree, method, ast_http_uri::no_decode_uri, NULL, prefix, strsep(), http_uri_redirect::target, ast_http_uri::uri, and var.
Referenced by httpd_process_request().
|
static |
Definition at line 1084 of file http.c.
References ast_iostream_read(), ast_log, LOG_WARNING, and ast_tcptls_session_instance::stream.
Referenced by ast_http_body_discard(), and ast_http_get_contents().
|
static |
Definition at line 1115 of file http.c.
References ast_iostream_gets(), ast_log, ast_strlen_zero(), ast_trim_blanks(), LOG_WARNING, MAX_HTTP_LINE_LENGTH, and ast_tcptls_session_instance::stream.
Referenced by ast_http_body_discard(), and ast_http_get_contents().
|
static |
Definition at line 979 of file http.c.
References ast_iostream_discard(), ast_log, LOG_WARNING, and ast_tcptls_session_instance::stream.
Referenced by ast_http_body_discard().
|
static |
Definition at line 1056 of file http.c.
References ast_iostream_gets(), ast_log, chunked_atoh(), LOG_WARNING, MAX_HTTP_LINE_LENGTH, and ast_tcptls_session_instance::stream.
Referenced by ast_http_body_discard(), and ast_http_get_contents().
|
static |
Definition at line 943 of file http.c.
References ast_iostream_read(), ast_log, buf, LOG_WARNING, ast_tcptls_session_instance::stream, and total.
Referenced by ast_http_get_contents().
|
static |
Definition at line 842 of file http.c.
References get_header().
Referenced by http_request_tracking_setup().
|
static |
Definition at line 1833 of file http.c.
References ast_http_error(), ast_iostream_gets(), ast_skip_blanks(), ast_strlen_zero(), ast_trim_blanks(), ast_variable_new, ast_variables_destroy(), len(), MAX_HTTP_LINE_LENGTH, MAX_HTTP_REQUEST_HEADERS, name, ast_variable::next, NULL, ast_tcptls_session_instance::stream, strsep(), and value.
Referenced by httpd_process_request().
|
static |
Definition at line 867 of file http.c.
References ast_set_flags_to, HTTP_FLAG_BODY_READ, HTTP_FLAG_CLOSE_ON_COMPLETION, HTTP_FLAG_HAS_BODY, and request().
Referenced by httpd_helper_thread(), and httpd_process_request().
|
static |
Definition at line 886 of file http.c.
References ast_http_error(), ast_set_flag, ast_set_flags_to, get_content_length(), get_transfer_encoding(), http_check_connection_close(), HTTP_FLAG_BODY_READ, HTTP_FLAG_CLOSE_ON_COMPLETION, HTTP_FLAG_HAS_BODY, ast_tcptls_session_instance::private_data, and request().
Referenced by httpd_process_request().
|
static |
Definition at line 2173 of file http.c.
References ast_tcptls_session_args::accept_fd, ast_tcptls_session_args::accept_fn, ast_http_server::address, ao2_alloc, ao2_ref, ast_http_server::args, ast_log, AST_PTHREADT_NULL, ast_sockaddr_copy(), ast_strdup, ast_tcptls_server_root(), http_server_destroy(), httpd_helper_thread(), ast_tcptls_session_args::local_address, LOG_ERROR, ast_tcptls_session_args::master, name, ast_tcptls_session_args::name, ast_http_server::name, NULL, ast_tcptls_session_args::poll_timeout, ast_tcptls_session_args::tls_cfg, and ast_tcptls_session_args::worker_fn.
Referenced by http_server_get_by_addr().
|
static |
Definition at line 2161 of file http.c.
References ast_http_server::address, ast_http_server::args, ast_free, ast_tcptls_server_stop(), ast_verb, and ast_http_server::name.
Referenced by http_server_create().
|
static |
Discard/Drop a HTTP server.
Decrements the reference to the given object, and unlinks it from the servers container if it's the last reference.
After a server object has been added to the container this method should always be called to decrement the object's reference instead of the regular ao2 methods.
server | The server object |
Definition at line 2243 of file http.c.
References ao2_ref, ao2_unlink, and http_servers.
Referenced by __ast_http_load(), and http_server_get().
|
static |
Retrieve, or create and start a HTTP server.
Resolve the given host, and retrieve a listening server object. If the server is not already listening then start it. If a replace_me parameter is given, and it points to a non-NULL value then that server is discarded and replaced.
name | The name of the server | |
host | The host to resolve, and match on or create a new object with | |
port | Optional port used if one is not specified with the host (default 8088) | |
[out] | replace_me | Optional server to be replaced |
Definition at line 2353 of file http.c.
References ao2_cleanup, ao2_lock, ao2_ref, ao2_unlock, http_server_discard(), http_server_get_by_host(), http_server_start(), http_servers, name, and NULL.
Referenced by __ast_http_load().
|
static |
Retrieve, or create a HTTP server object by sock address.
Look for, and return a matching server object by addr. If an object is not found then create a new one.
name | The name of the server |
addr | The address to match on, or create a new object with |
Definition at line 2271 of file http.c.
References ao2_find, ast_sockaddr_stringify(), ast_strlen_zero(), http_server_create(), http_servers, name, NULL, OBJ_KEY, and OBJ_NOLOCK.
Referenced by http_server_get_by_host().
|
static |
Retrieve, or create a HTTP server object by host.
Resolve the given host, and then look for, and return a matching server object. If an object is not found then create a new one.
name | The name of the server |
host | The host to resolve, and match on or create a new object with |
port | Optional port used if one is not specified with the host (default 8088) |
Definition at line 2301 of file http.c.
References AST_AF_UNSPEC, ast_free, ast_log, ast_sockaddr_port, ast_sockaddr_resolve(), ast_sockaddr_set_port, DEFAULT_PORT, http_server_get_by_addr(), LOG_WARNING, name, and NULL.
Referenced by http_server_get().
|
static |
Definition at line 2205 of file http.c.
References ast_tcptls_session_args::accept_fd, ast_http_server::address, ao2_link_flags, ast_http_server::args, ast_log, ast_tcptls_server_start(), ast_verb, http_servers, LOG_WARNING, ast_http_server::name, and OBJ_NOLOCK.
Referenced by http_server_get().
|
static |
Definition at line 2013 of file http.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_ref, ast_atomic_fetchadd_int(), ast_debug, ast_http_error(), ast_iostream_get_fd(), ast_iostream_nonblock(), ast_iostream_set_exclusive_input(), ast_iostream_set_timeout_idle_inactivity(), ast_log, ast_tcptls_close_session_file(), done, errno, http_request_tracking_init(), httpd_process_request(), LOG_WARNING, MIN_INITIAL_REQUEST_TIMEOUT, NULL, ast_tcptls_session_instance::private_data, session_count, session_inactivity, session_keep_alive, session_limit, and ast_tcptls_session_instance::stream.
Referenced by http_server_create().
|
static |
Definition at line 1915 of file http.c.
References AST_HTTP_DELETE, ast_http_error(), AST_HTTP_GET, AST_HTTP_HEAD, AST_HTTP_OPTIONS, AST_HTTP_POST, AST_HTTP_PUT, AST_HTTP_UNKNOWN, ast_iostream_gets(), ast_shutdown_final(), ast_skip_blanks(), ast_skip_nonblanks(), ast_test_flag, ast_variables_destroy(), c, get_transfer_encoding(), handle_uri(), HTTP_FLAG_CLOSE_ON_COMPLETION, http_request_headers_get(), http_request_tracking_init(), http_request_tracking_setup(), len(), MAX_HTTP_LINE_LENGTH, method, NULL, ast_tcptls_session_instance::private_data, RAII_VAR, request(), and ast_tcptls_session_instance::stream.
Referenced by httpd_helper_thread().
|
static |
Definition at line 384 of file http.c.
References ast_http_server::args, ast_http_error(), AST_HTTP_GET, ast_http_get_cookies(), AST_HTTP_HEAD, ast_http_request_close_on_completion(), ast_http_send(), ast_sockaddr_stringify(), ast_str_append(), ast_str_create, ast_variables_destroy(), ast_tls_config::enabled, global_http_server, http_server_name, http_tls_cfg, https_desc, method, ast_variable::name, ast_variable::next, NULL, ast_tcptls_session_args::old_address, out, prefix, and ast_variable::value.
|
static |
Definition at line 2729 of file http.c.
References __ast_http_load(), AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, cli_http, HTTP_SERVER_BUCKETS, http_servers, and NULL.
|
static |
Definition at line 1530 of file http.c.
References ast_debug, ast_strdupa, ast_strip(), ast_strip_quoted(), ast_strlen_zero(), ast_variable_new, name, NULL, strsep(), and var.
Referenced by ast_http_get_cookies().
|
static |
Definition at line 2687 of file http.c.
References __ast_http_load().
|
static |
Definition at line 1735 of file http.c.
References ast_free, ast_malloc, ast_skip_blanks(), ast_skip_nonblanks(), and buf.
Referenced by ast_http_header_parse().
|
static |
Definition at line 256 of file http.c.
References ast_alloca, ast_config_AST_DATA_DIR, ast_http_error(), ast_http_ftype2mtype(), AST_HTTP_GET, AST_HTTP_HEAD, ast_http_manid_from_vars(), ast_http_request_close_on_completion(), ast_http_send(), ast_localtime(), ast_str_create, ast_str_set(), ast_strftime(), ast_strlen_zero(), astman_is_authed(), len(), method, mtype, ast_variable::name, ast_variable::next, NULL, S_OR, and ast_variable::value.
|
static |
Definition at line 2696 of file http.c.
References ao2_cleanup, ARRAY_LEN, ast_cli_unregister_multiple(), ast_free, ast_http_uri_unlink(), AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_tcptls_server_stop(), ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, cli_http, ast_tls_config::enabled, http_uri_redirect::entry, global_http_server, http_servers, http_tls_cfg, https_desc, ast_tls_config::pvtfile, static_uri, static_uri_enabled, status_uri, and status_uri_enabled.
|
static |
|
static |
Referenced by ast_get_http_method(), and ast_get_http_method_from_string().
|
static |
|
static |
Definition at line 2692 of file http.c.
Referenced by load_module(), and unload_module().
const char* ext |
Definition at line 150 of file http.c.
Referenced by ast_ext_ctx(), ast_http_ftype2mtype(), ast_media_cache_create_or_update(), ast_media_cache_retrieve(), ast_rtp_interpret(), bucket_file_update_path(), build_filename(), cli_console_dial(), common_exec(), console_new(), copy_to_voicemail(), create_dirpath(), dahdi_call(), do_directory(), file_extension_from_string(), filehelper(), filename_parse(), goto_exten(), handle_cli_dialplan_save(), hintdevice_hash_cb(), invent_message(), is_recording(), json_array_from_list(), leave_voicemail(), make_dir(), make_filename(), mixmonitor_save_prep(), ooh323_request(), pbx_load_config(), pbx_load_config(), play_mailbox_owner(), process_media_file(), pvalGotoSetTarget(), read_dirs_cb(), record_exec(), register_peer_exten(), rtp_raw_write(), search_directory(), search_directory_sub(), set_rec_filename(), split_ec(), and split_ext().
struct ast_http_server* global_http_server = NULL |
The default configured HTTP server
Definition at line 129 of file http.c.
Referenced by __ast_http_load(), handle_show_http(), httpstatus_callback(), and unload_module().
|
static |
Definition at line 104 of file http.c.
Referenced by __ast_http_load(), ast_http_create_response(), ast_http_send(), handle_show_http(), and httpstatus_callback().
struct ao2_container* http_servers = NULL |
Definition at line 2156 of file http.c.
Referenced by http_server_discard(), http_server_get(), http_server_get_by_addr(), http_server_start(), load_module(), and unload_module().
|
static |
Definition at line 111 of file http.c.
Referenced by __ast_http_load(), handle_show_http(), httpstatus_callback(), and unload_module().
|
static |
Definition at line 131 of file http.c.
Referenced by __ast_http_load(), handle_show_http(), httpstatus_callback(), and unload_module().
struct { ... } mimetypes[] |
Limit the kinds of files we're willing to serve up.
Referenced by ast_http_ftype2mtype().
const char* mtype |
Definition at line 151 of file http.c.
Referenced by is_msg(), and static_callback().
|
static |
Definition at line 144 of file http.c.
Referenced by __ast_http_load(), _while_exec(), aoc_amount_str(), aoc_d_event(), aoc_e_event(), aoc_s_event(), aoc_time_str(), aor_deleted_observer(), ast_acl_output(), ast_ari_get_docs(), ast_begins_with(), ast_cli_print_timestr_fromseconds(), ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), ast_frame_dump(), ast_ha_output(), ast_http_prefix(), ast_http_uri_link(), ast_manager_build_bridge_state_string_prefix(), ast_manager_build_channel_state_string_prefix(), ast_remotecontrol(), ast_sip_location_retrieve_aor_contacts_nolock_filtered(), ast_sorcery_retrieve_by_prefix(), at_match_prefix(), clearvar_prefix(), cli_match_char_tree(), console_print(), create_prefix(), exec_clearhash(), generate_filenames_string(), get_index(), get_index(), get_key(), get_object_variables(), handle_auth(), handle_cli_database_show(), handle_show_http(), handle_uri(), hashkeys_read(), hashkeys_read2(), httpstatus_callback(), if_helper(), insert_test_duplicates(), insert_test_vector(), ip_identify_match_srv_lookup(), load_module(), log_jack_status(), manager_db_tree_get(), print_acl(), print_uptimestr(), process_config(), process_config(), refer_blind_callback(), say_date_generic(), shared_read(), shared_write(), sip_options_apply_aor_configuration(), sorcery_astdb_create(), sorcery_astdb_delete(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), sorcery_astdb_retrieve_regex(), sorcery_astdb_update(), sorcery_config_retrieve_prefix(), sorcery_memory_cache_retrieve_prefix(), sorcery_memory_retrieve_prefix(), sorcery_realtime_retrieve_prefix(), test_ao2_callback_traversal(), test_ao2_iteration(), test_expected_duplicates(), vm_authenticate(), and while_continue_exec().
|
static |
Definition at line 109 of file http.c.
Referenced by cli_fax_show_sessions(), httpd_helper_thread(), is_media_state_valid(), and manager_fax_sessions().
|
static |
Definition at line 107 of file http.c.
Referenced by __ast_http_load(), and httpd_helper_thread().
|
static |
Definition at line 108 of file http.c.
Referenced by __ast_http_load(), ast_http_send(), and httpd_helper_thread().
|
static |
Definition at line 106 of file http.c.
Referenced by __ast_http_load(), evt_gen_session_limit(), httpd_helper_thread(), and report_session_limit().
|
static |
Definition at line 446 of file http.c.
Referenced by __ast_http_load(), and unload_module().
|
static |
Definition at line 145 of file http.c.
Referenced by __ast_http_load(), and unload_module().
|
static |
Definition at line 437 of file http.c.
Referenced by __ast_http_load(), and unload_module().
|
static |
Definition at line 146 of file http.c.
Referenced by __ast_http_load(), and unload_module().
|
static |
|
static |
list of supported handlers