Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Typedefs | Enumerations | Functions
http.h File Reference

Support for Private Asterisk HTTP Servers. More...

#include "asterisk/config.h"
#include "asterisk/tcptls.h"
#include "asterisk/linkedlists.h"
Include dependency graph for http.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_http_auth
 HTTP authentication information. More...
 
struct  ast_http_uri
 Definition of a URI handler. More...
 

Typedefs

typedef int(* ast_http_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_params, struct ast_variable *headers)
 HTTP Callbacks. More...
 

Enumerations

enum  ast_http_method {
  AST_HTTP_UNKNOWN = -1 , AST_HTTP_GET = 0 , AST_HTTP_POST , AST_HTTP_HEAD ,
  AST_HTTP_PUT , AST_HTTP_DELETE , AST_HTTP_OPTIONS , AST_HTTP_MAX_METHOD
}
 HTTP Request methods known by Asterisk. More...
 

Functions

const char * ast_get_http_method (enum ast_http_method method) attribute_pure
 Return http method name string. More...
 
enum ast_http_method ast_get_http_method_from_string (const char *method)
 Return http method from string. More...
 
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. More...
 
int ast_http_body_discard (struct ast_tcptls_session_instance *ser)
 Read and discard any unread HTTP request body. More...
 
void ast_http_body_read_status (struct ast_tcptls_session_instance *ser, int read_success)
 Update the body read success status. More...
 
struct ast_variableast_http_create_basic_auth_header (const char *userid, const char *password)
 Create an HTTP authorization header. More...
 
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. More...
 
void ast_http_error (struct ast_tcptls_session_instance *ser, int status, const char *title, const char *text)
 Send HTTP error message and close socket. More...
 
const char * ast_http_ftype2mtype (const char *ftype) attribute_pure
 Return mime type based on extension. More...
 
struct ast_http_authast_http_get_auth (struct ast_variable *headers)
 Get HTTP authentication information from headers. More...
 
struct ast_variableast_http_get_cookies (struct ast_variable *headers)
 Get cookie from Request headers. More...
 
struct ast_jsonast_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. More...
 
struct ast_variableast_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. More...
 
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. More...
 
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. More...
 
int ast_http_header_parse (char *buf, char **name, char **value)
 Parse a header into the given name/value strings. More...
 
uint32_t ast_http_manid_from_vars (struct ast_variable *headers) attribute_pure
 Return manager id, if exist, from request headers. More...
 
struct ast_variableast_http_parse_post_form (char *buf, int content_length, const char *content_type)
 Get post variables from an application/x-www-form-urlencoded buffer. More...
 
void ast_http_prefix (char *buf, int len)
 Return the current prefix. More...
 
void ast_http_request_close_on_completion (struct ast_tcptls_session_instance *ser)
 Request the HTTP connection be closed after this HTTP request. More...
 
int ast_http_response_status_line (const char *buf, const char *version, int code)
 Parse the http response status line. More...
 
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. More...
 
int ast_http_uri_link (struct ast_http_uri *urihandler)
 Register a URI handler. More...
 
void ast_http_uri_unlink (struct ast_http_uri *urihandler)
 Unregister a URI handler. More...
 
void ast_http_uri_unlink_all_with_key (const char *key)
 Unregister all handlers with matching key. More...
 

Detailed Description

Support for Private Asterisk HTTP Servers.

Note
Note: The Asterisk HTTP servers are extremely simple and minimal and only support the "GET" method.
Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Note
In order to have TLS/SSL support, we need the openssl libraries. Still we can decide whether or not to use them by commenting in or out the DO_SSL macro. TLS/SSL support is basically implemented by reading from a config file (currently http.conf) the names of the certificate and cipher to use, and then run ssl_setup() to create an appropriate SSL_CTX (ssl_ctx) If we support multiple domains, presumably we need to read multiple certificates. When we are requested to open a TLS socket, we run make_file_from_fd() on the socket, to do the necessary setup. At the moment the context's name is hardwired in the function, but we can certainly make it into an extra parameter to the function. We declare most of ssl support variables unconditionally, because their number is small and this simplifies the code.
: the ssl-support variables (ssl_ctx, do_ssl, certfile, cipher) and their setup should be moved to a more central place, e.g. asterisk.conf and the source files that processes it. Similarly, ssl_setup() should be run earlier in the startup process so modules have it available.

Definition in file http.h.

Typedef Documentation

◆ ast_http_callback

typedef int(* ast_http_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_params, struct ast_variable *headers)

HTTP Callbacks.

Parameters
serTCP/TLS session object
urihRegistered URI handler struct for the URI.
uriRemaining request URI path (also with the get_params removed).
methodenum ast_http_method GET, POST, etc.
get_paramsURI argument list passed with the HTTP request.
headersHTTP request header-name/value pair list
Note
Should use the ast_http_send() function for sending content allocated with ast_str and/or content from an opened file descriptor.

Status and status text should be sent as arguments to the ast_http_send() function to reflect the status of the request (200 or 304, for example). Content length is calculated by ast_http_send() automatically.

Static content may be indicated to the ast_http_send() function, to indicate that it may be cached.

For a need authentication response, the ast_http_auth() function should be used.

For an error response, the ast_http_error() function should be used.

Return values
0Continue and process the next HTTP request.
-1Fatal HTTP connection error. Force the HTTP connection closed.

Definition at line 99 of file http.h.

Enumeration Type Documentation

◆ ast_http_method

HTTP Request methods known by Asterisk.

Enumerator
AST_HTTP_UNKNOWN 

Unknown response

AST_HTTP_GET 
AST_HTTP_POST 
AST_HTTP_HEAD 
AST_HTTP_PUT 
AST_HTTP_DELETE 
AST_HTTP_OPTIONS 
AST_HTTP_MAX_METHOD 

Last entry in ast_http_method enum

Definition at line 58 of file http.h.

58 {
59 AST_HTTP_UNKNOWN = -1, /*!< Unknown response */
60 AST_HTTP_GET = 0,
66 AST_HTTP_MAX_METHOD, /*!< Last entry in ast_http_method enum */
67};
@ AST_HTTP_PUT
Definition: http.h:63
@ AST_HTTP_DELETE
Definition: http.h:64
@ AST_HTTP_POST
Definition: http.h:61
@ AST_HTTP_GET
Definition: http.h:60
@ AST_HTTP_MAX_METHOD
Definition: http.h:66
@ AST_HTTP_UNKNOWN
Definition: http.h:59
@ AST_HTTP_OPTIONS
Definition: http.h:65
@ AST_HTTP_HEAD
Definition: http.h:62

Function Documentation

◆ ast_get_http_method()

const char * ast_get_http_method ( enum ast_http_method  method)

Return http method name string.

Since
1.8

Definition at line 193 of file http.c.

194{
195 int x;
196
197 for (x = 0; x < ARRAY_LEN(ast_http_methods_text); x++) {
199 return ast_http_methods_text[x].text;
200 }
201 }
202
203 return NULL;
204}
static const struct ast_cfhttp_methods_text ast_http_methods_text[]
const char * method
Definition: res_pjsip.c:1279
#define NULL
Definition: resample.c:96
const char * text
Definition: http.c:182
#define ARRAY_LEN(a)
Definition: utils.h:666

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().

◆ ast_get_http_method_from_string()

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.

207{
208 int x;
209
210 for (x = 0; x < ARRAY_LEN(ast_http_methods_text); x++) {
213 }
214 }
215
216 return AST_HTTP_UNKNOWN;
217}
char * text
Definition: app_queue.c:1809
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition: strings.c:238
enum ast_http_method method
Definition: http.c:181

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().

◆ ast_http_auth()

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.

641{
642 int status_code = 401;
643 char *status_title = "Unauthorized";
644 struct ast_str *http_header_data = ast_str_create(DEFAULT_RESPONSE_HEADER_LENGTH);
645
646 if (http_header_data) {
647 ast_str_set(&http_header_data,
648 0,
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",
652 nonce,
653 opaque,
654 stale ? ", stale=true" : "");
655 }
656
658 status_code,
659 status_title,
660 http_header_data,
661 text);
662}
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.
Definition: http.c:583
#define DEFAULT_RESPONSE_HEADER_LENGTH
Definition: http.c:81
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
Support for dynamic strings.
Definition: strings.h:623

References ast_http_create_response(), ast_str_create, ast_str_set(), DEFAULT_RESPONSE_HEADER_LENGTH, and text.

Referenced by auth_http_callback().

◆ ast_http_body_discard()

int ast_http_body_discard ( struct ast_tcptls_session_instance ser)

Read and discard any unread HTTP request body.

Since
12.4.0
Parameters
serHTTP TCP/TLS session object.
Return values
0on success.
-1on error.

Definition at line 1135 of file http.c.

1136{
1138
1139 request = ser->private_data;
1142 /* No body to read or it has already been read. */
1143 return 0;
1144 }
1146
1147 ast_debug(1, "HTTP discarding unused request body\n");
1148
1149 ast_assert(request->body_length != 0);
1150 if (0 < request->body_length) {
1151 if (http_body_discard_contents(ser, request->body_length, "body")) {
1153 return -1;
1154 }
1155 return 0;
1156 }
1157
1158 /* parse chunked-body */
1159 for (;;) {
1160 int length;
1161
1162 length = http_body_get_chunk_length(ser);
1163 if (length < 0) {
1165 return -1;
1166 }
1167 if (length == 0) {
1168 /* parsed last-chunk */
1169 break;
1170 }
1171
1172 if (http_body_discard_contents(ser, length, "chunk-data")
1175 return -1;
1176 }
1177 }
1178
1179 /* Read and discard any trailer entity-header lines. */
1182 return -1;
1183 }
1184 return 0;
1185}
static int request(void *obj)
Definition: chan_pjsip.c:2605
static int http_body_discard_chunk_trailer_headers(struct ast_tcptls_session_instance *ser)
Definition: http.c:1115
@ HTTP_FLAG_BODY_READ
Definition: http.c:459
@ HTTP_FLAG_CLOSE_ON_COMPLETION
Definition: http.c:461
@ HTTP_FLAG_HAS_BODY
Definition: http.c:457
static int http_body_discard_contents(struct ast_tcptls_session_instance *ser, int length, const char *what_getting)
Definition: http.c:979
static int http_body_check_chunk_sync(struct ast_tcptls_session_instance *ser)
Definition: http.c:1084
static int http_body_get_chunk_length(struct ast_tcptls_session_instance *ser)
Definition: http.c:1056
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_assert(a)
Definition: utils.h:739
#define ast_set_flag(p, flag)
Definition: utils.h:70

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().

◆ ast_http_body_read_status()

void ast_http_body_read_status ( struct ast_tcptls_session_instance ser,
int  read_success 
)

Update the body read success status.

Since
12.4.0
Parameters
serHTTP TCP/TLS session object.
read_successTRUE if body was read successfully.

Definition at line 914 of file http.c.

915{
917
918 request = ser->private_data;
921 /* No body to read. */
922 return;
923 }
925 if (!read_success) {
927 }
928}

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().

◆ ast_http_create_basic_auth_header()

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()

Parameters
useridUser ID or "<userid>:<password>".
passwordPassword if not in userid.
Returns
ast_variable with name="Authorization" and value="Basic <base64enc>"
Return values
NULLif memory allocation failed.

Definition at line 1668 of file http.c.

1670{
1671 int encoded_size = 0;
1672 int userinfo_len = 0;
1673 RAII_VAR(char *, userinfo, NULL, ast_free);
1674 char *encoded_userinfo = NULL;
1675 struct ast_variable *auth_header = NULL;
1676
1677 if (ast_strlen_zero(userid)) {
1678 return NULL;
1679 }
1680
1681 if (strchr(userid, ':')) {
1682 userinfo = ast_strdup(userid);
1683 userinfo_len = strlen(userinfo);
1684 } else {
1685 if (ast_strlen_zero(password)) {
1686 return NULL;
1687 }
1688 userinfo_len = ast_asprintf(&userinfo, "%s:%s", userid, password);
1689 }
1690 if (!userinfo) {
1691 return NULL;
1692 }
1693
1694 /*
1695 * The header value is "Basic " + base64(userinfo).
1696 * Doubling the userinfo length then adding the length
1697 * of the "Basic " prefix is a conservative estimate of the
1698 * final encoded size.
1699 */
1700 encoded_size = userinfo_len * 2 * sizeof(char) + 1 + BASIC_LEN;
1701 encoded_userinfo = ast_alloca(encoded_size);
1702 strcpy(encoded_userinfo, BASIC_PREFIX); /* Safe */
1703 ast_base64encode(encoded_userinfo + BASIC_LEN, (unsigned char *)userinfo,
1704 userinfo_len, encoded_size - BASIC_LEN);
1705
1706 auth_header = ast_variable_new("Authorization",
1707 encoded_userinfo, "");
1708
1709 return auth_header;
1710}
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define BASIC_PREFIX
Definition: http.c:1608
#define BASIC_LEN
Definition: http.c:1609
#define ast_variable_new(name, value, filename)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure for variables, used for configurations and for channel variables.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
Definition: utils.c:406

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 websocket_client_handshake().

◆ ast_http_create_response()

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.

Parameters
serTCP/TLS session object
status_codeHTTP response code (200/401/403/404/500)
status_titleEnglish equivalent to the status_code parameter
http_header_dataThe formatted text to use in the http header
textAdditional informational text to use in the response
Note
Function constructs response headers from the status_code, status_title and http_header_data parameters.

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.

Since
13.2.0

Definition at line 583 of file http.c.

585{
586 char server_name[MAX_SERVER_NAME_LENGTH];
587 struct ast_str *server_address = ast_str_create(MAX_SERVER_NAME_LENGTH);
589
590 if (!http_header_data || !server_address || !out) {
591 ast_free(http_header_data);
592 ast_free(server_address);
593 ast_free(out);
594 if (ser) {
595 ast_debug(1, "HTTP closing session. OOM.\n");
597 }
598 return;
599 }
600
602 ast_xml_escape(http_server_name, server_name, sizeof(server_name));
603 ast_str_set(&server_address,
604 0,
605 "<address>%s</address>\r\n",
606 server_name);
607 }
608
610 0,
611 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
612 "<html><head>\r\n"
613 "<title>%d %s</title>\r\n"
614 "</head><body>\r\n"
615 "<h1>%s</h1>\r\n"
616 "<p>%s</p>\r\n"
617 "<hr />\r\n"
618 "%s"
619 "</body></html>\r\n",
620 status_code,
621 status_title,
622 status_title,
623 text ? text : "",
624 ast_str_buffer(server_address));
625
626 ast_free(server_address);
627
628 ast_http_send(ser,
630 status_code,
631 status_title,
632 http_header_data,
633 out,
634 0,
635 0);
636}
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.
Definition: http.c:472
#define INITIAL_RESPONSE_BODY_BUFFER
Definition: http.c:92
static char http_server_name[MAX_SERVER_NAME_LENGTH]
Definition: http.c:104
#define MAX_SERVER_NAME_LENGTH
Definition: http.c:79
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
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...
Definition: tcptls.c:923
FILE * out
Definition: utils/frame.c:33
int ast_xml_escape(const char *string, char *outbuf, size_t buflen)
Escape reserved characters for use in XML.
Definition: utils.c:864

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().

◆ ast_http_error()

void ast_http_error ( struct ast_tcptls_session_instance ser,
int  status,
const char *  title,
const char *  text 
)

Send HTTP error message and close socket.

Definition at line 664 of file http.c.

666{
667 struct ast_str *http_header_data = ast_str_create(DEFAULT_RESPONSE_HEADER_LENGTH);
668
669 if (http_header_data) {
670 ast_str_set(&http_header_data, 0, "Content-type: text/html\r\n");
671 }
672
674 status_code,
675 status_title,
676 http_header_data,
677 text);
678}

References ast_http_create_response(), ast_str_create, ast_str_set(), DEFAULT_RESPONSE_HEADER_LENGTH, and text.

Referenced by ari_ws_session_create(), 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(), phoneprov_callback(), static_callback(), websocket_attempted_cb(), and websocket_bad_request().

◆ ast_http_ftype2mtype()

const char * ast_http_ftype2mtype ( const char *  ftype)

Return mime type based on extension.

Parameters
ftypefilename extension
Returns
String containing associated MIME type
Since
1.8

Definition at line 219 of file http.c.

220{
221 int x;
222
223 if (ftype) {
224 for (x = 0; x < ARRAY_LEN(mimetypes); x++) {
225 if (!strcasecmp(ftype, mimetypes[x].ext)) {
226 return mimetypes[x].mtype;
227 }
228 }
229 }
230 return NULL;
231}
static struct @362 mimetypes[]
Limit the kinds of files we're willing to serve up.
const char * ext
Definition: http.c:150

References ARRAY_LEN, ext, mimetypes, and NULL.

Referenced by build_profile(), and static_callback().

◆ ast_http_get_auth()

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().

Parameters
headersHTTP request headers.
Returns
HTTP auth structure.
Return values
NULLif no supported HTTP auth headers present.
Since
12

Definition at line 1611 of file http.c.

1612{
1613 struct ast_variable *v;
1614
1615 for (v = headers; v; v = v->next) {
1616 const char *base64;
1617 char decoded[256] = {};
1618 char *username;
1619 char *password;
1620#ifdef AST_DEVMODE
1621 int cnt;
1622#endif /* AST_DEVMODE */
1623
1624 if (strcasecmp("Authorization", v->name) != 0) {
1625 continue;
1626 }
1627
1630 "Unsupported Authorization scheme\n");
1631 continue;
1632 }
1633
1634 /* Basic auth header parsing. RFC 2617, section 2.
1635 * credentials = "Basic" basic-credentials
1636 * basic-credentials = base64-user-pass
1637 * base64-user-pass = <base64 encoding of user-pass,
1638 * except not limited to 76 char/line>
1639 * user-pass = userid ":" password
1640 */
1641
1642 base64 = v->value + BASIC_LEN;
1643
1644 /* This will truncate "userid:password" lines to
1645 * sizeof(decoded). The array is long enough that this shouldn't
1646 * be a problem */
1647#ifdef AST_DEVMODE
1648 cnt =
1649#endif /* AST_DEVMODE */
1650 ast_base64decode((unsigned char*)decoded, base64,
1651 sizeof(decoded) - 1);
1652 ast_assert(cnt < sizeof(decoded));
1653
1654 /* Split the string at the colon */
1655 password = decoded;
1656 username = strsep(&password, ":");
1657 if (!password) {
1658 ast_log(LOG_WARNING, "Invalid Authorization header\n");
1659 return NULL;
1660 }
1661
1662 return auth_create(username, password);
1663 }
1664
1665 return NULL;
1666}
char * strsep(char **str, const char *delims)
#define ast_log
Definition: astobj2.c:42
static struct ast_http_auth * auth_create(const char *userid, const char *password)
Definition: http.c:1577
#define LOG_DEBUG
#define LOG_WARNING
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
struct ast_variable * next
static char base64[64]
Definition: utils.c:80
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
Definition: utils.c:296

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().

◆ ast_http_get_cookies()

struct ast_variable * ast_http_get_cookies ( struct ast_variable headers)

Get cookie from Request headers.

Definition at line 1564 of file http.c.

1565{
1566 struct ast_variable *v, *cookies = NULL;
1567
1568 for (v = headers; v; v = v->next) {
1569 if (!strcasecmp(v->name, "Cookie")) {
1570 ast_variables_destroy(cookies);
1571 cookies = parse_cookies(v->value);
1572 }
1573 }
1574 return cookies;
1575}
static struct ast_variable * parse_cookies(const char *cookies)
Definition: http.c:1530
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262

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().

◆ ast_http_get_json()

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.

Parameters
serTCP/TLS session object
headersList of HTTP headers
Returns
Parsed JSON content body
Return values
NULLon error, if no content, or if different content type.
Since
12

Definition at line 1330 of file http.c.

1332{
1333 int content_length = 0;
1334 struct ast_json *body;
1335 RAII_VAR(char *, buf, NULL, ast_free);
1336 RAII_VAR(char *, type, get_content_type(headers), ast_free);
1337
1338 /* Use errno to distinguish errors from no body */
1339 errno = 0;
1340
1341 if (ast_strlen_zero(type) || strcasecmp(type, "application/json")) {
1342 /* Content type is not JSON. Don't read the body. */
1343 return NULL;
1344 }
1345
1346 buf = ast_http_get_contents(&content_length, ser, headers);
1347 if (!buf || !content_length) {
1348 /*
1349 * errno already set
1350 * or it is not an error to have zero content
1351 */
1352 return NULL;
1353 }
1354
1355 body = ast_json_load_buf(buf, content_length, NULL);
1356 if (!body) {
1357 /* Failed to parse JSON; treat as an I/O error */
1358 errno = EIO;
1359 return NULL;
1360 }
1361
1362 return body;
1363}
static const char type[]
Definition: chan_ooh323.c:109
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static char * get_content_type(struct ast_variable *headers)
Retrieves the content type specified in the "Content-Type" header.
Definition: http.c:778
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.
Definition: http.c:1197
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.
Definition: json.c:585
int errno
Abstract JSON element (object, array, string, int, ...).

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().

◆ ast_http_get_post_vars()

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.

Parameters
serTCP/TLS session object
headersList of HTTP headers
Returns
List of variables within the POST body
Note
Since returned list is malloc'd, list should be free'd by the calling function
Since
1.8

Definition at line 1405 of file http.c.

1407{
1408 int content_length = 0;
1409 RAII_VAR(char *, buf, NULL, ast_free);
1410 RAII_VAR(char *, type, get_content_type(headers), ast_free);
1411
1412 /* Use errno to distinguish errors from no params */
1413 errno = 0;
1414
1415 if (ast_strlen_zero(type) ||
1416 strcasecmp(type, "application/x-www-form-urlencoded")) {
1417 /* Content type is not form data. Don't read the body. */
1418 return NULL;
1419 }
1420
1421 buf = ast_http_get_contents(&content_length, ser, headers);
1422 if (!buf || !content_length) {
1423 /*
1424 * errno already set
1425 * or it is not an error to have zero content
1426 */
1427 return NULL;
1428 }
1429
1430 return ast_http_parse_post_form(buf, content_length, type);
1431}
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.
Definition: http.c:1369

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().

◆ ast_http_header_match()

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.

Parameters
nameheader name to check
expected_namethe expected name of the header
valueheader value to check
expected_valuethe expected value of the header
Return values
0if the name and expected name do not match
-1if the value and expected value do not match
1if the both the name and value match their expected value
Since
13

Definition at line 1786 of file http.c.

1788{
1789 if (strcasecmp(name, expected_name)) {
1790 /* no value to validate if names don't match */
1791 return 0;
1792 }
1793
1794 if (strcasecmp(value, expected_value)) {
1795 ast_log(LOG_ERROR, "Invalid header value - expected %s "
1796 "received %s", value, expected_value);
1797 return -1;
1798 }
1799 return 1;
1800}
static const char name[]
Definition: format_mp3.c:68
#define LOG_ERROR
int value
Definition: syslog.c:37

References ast_log, LOG_ERROR, name, and value.

Referenced by websocket_client_handshake_get_response().

◆ ast_http_header_match_in()

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.

Note
Both header and value checks are case insensitive.
Parameters
nameheader name to check
expected_namethe expected name of the header
valueheader value to check if in expected value
expected_valuethe expected value(s)
Return values
0if the name and expected name do not match
-1if the value and is not in the expected value
1if the name matches expected name and value is in expected value
Since
13

Definition at line 1802 of file http.c.

1804{
1805 if (strcasecmp(name, expected_name)) {
1806 /* no value to validate if names don't match */
1807 return 0;
1808 }
1809
1810 if (!strcasestr(expected_value, value)) {
1811 ast_log(LOG_ERROR, "Header '%s' - could not locate '%s' "
1812 "in '%s'\n", name, value, expected_value);
1813 return -1;
1814
1815 }
1816 return 1;
1817}
char * strcasestr(const char *, const char *)

References ast_log, LOG_ERROR, name, strcasestr(), and value.

Referenced by websocket_client_handshake_get_response().

◆ ast_http_header_parse()

int ast_http_header_parse ( char *  buf,
char **  name,
char **  value 
)

Parse a header into the given name/value strings.

Note
This modifies the given buffer and the out parameters point (not allocated) to the start of the header name and header value, respectively.
Parameters
bufa string containing the name/value to point to
[out]nameheader name
[out]valueheader value
Return values
-1if buf is empty
0if buf could be separated into name and value
1if name or value portion don't exist
Since
13

Definition at line 1764 of file http.c.

1765{
1767 if (ast_strlen_zero(buf)) {
1768 return -1;
1769 }
1770
1771 *value = buf;
1772 *name = strsep(value, ":");
1773 if (!*value) {
1774 return 1;
1775 }
1776
1779 return 1;
1780 }
1781
1783 return 0;
1784}
static void remove_excess_lws(char *s)
Definition: http.c:1735
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition: strings.h:186
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:161

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().

◆ ast_http_manid_from_vars()

uint32_t ast_http_manid_from_vars ( struct ast_variable headers)

Return manager id, if exist, from request headers.

Parameters
headersList of HTTP headers
Returns
32-bit associated manager session identifier
Since
1.8

Definition at line 233 of file http.c.

234{
235 uint32_t mngid = 0;
236 struct ast_variable *v, *cookies;
237
238 cookies = ast_http_get_cookies(headers);
239 for (v = cookies; v; v = v->next) {
240 if (!strcasecmp(v->name, "mansession_id")) {
241 sscanf(v->value, "%30x", &mngid);
242 break;
243 }
244 }
245 ast_variables_destroy(cookies);
246 return mngid;
247}
struct ast_variable * ast_http_get_cookies(struct ast_variable *headers)
Get cookie from Request headers.
Definition: http.c:1564

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().

◆ ast_http_parse_post_form()

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.

Parameters
bufinput buffer
content_lenBuffer length
content_typeContent type (must be "application/x-www-form-urlencoded")
Warning
The input buffer will be modified by strsep() so pass in a copy if you need to keep the original.
Returns
List of ast_variables from the buffer. Must be freed with ast_variables_destroy().

Definition at line 1369 of file http.c.

1371{
1372 struct ast_variable *v, *post_vars=NULL, *prev = NULL;
1373 char *var, *val;
1374
1375 /* Use errno to distinguish errors from no params */
1376 errno = 0;
1377
1378 if (ast_strlen_zero(content_type) ||
1379 strcasecmp(content_type, "application/x-www-form-urlencoded") != 0) {
1380 /* Content type is not form data. Don't read the body. */
1381 return NULL;
1382 }
1383
1384 while ((val = strsep(&buf, "&"))) {
1385 var = strsep(&val, "=");
1386 if (val) {
1388 } else {
1389 val = "";
1390 }
1392 if ((v = ast_variable_new(var, val, ""))) {
1393 if (post_vars) {
1394 prev->next = v;
1395 } else {
1396 post_vars = v;
1397 }
1398 prev = v;
1399 }
1400 }
1401
1402 return post_vars;
1403}
#define var
Definition: ast_expr2f.c:605
Definition: ast_expr2.c:325
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
Definition: utils.c:762
const struct ast_flags ast_uri_http_legacy
Definition: utils.c:720

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().

◆ ast_http_prefix()

void ast_http_prefix ( char *  buf,
int  len 
)

Return the current prefix.

Parameters
[out]bufdestination buffer for previous
[in]lenlength of prefix to copy
Since
1.6.1

Definition at line 249 of file http.c.

250{
251 if (buf) {
253 }
254}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static char prefix[MAX_PREFIX]
Definition: http.c:144
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

References ast_copy_string(), buf, len(), and prefix.

◆ ast_http_request_close_on_completion()

void ast_http_request_close_on_completion ( struct ast_tcptls_session_instance ser)

Request the HTTP connection be closed after this HTTP request.

Since
12.4.0
Parameters
serHTTP TCP/TLS session object.
Note
Call before ast_http_error() to make the connection close.

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().

◆ ast_http_response_status_line()

int ast_http_response_status_line ( const char *  buf,
const char *  version,
int  code 
)

Parse the http response status line.

Parameters
bufthe http response line information
versionthe expected http version (e.g. HTTP/1.1)
codethe expected status code
Return values
-1if version didn't match or status code conversion fails.
Returns
status code (>0)
Since
13

Definition at line 1712 of file http.c.

1713{
1714 int status_code;
1715 size_t size = strlen(version);
1716
1717 if (strncmp(buf, version, size) || buf[size] != ' ') {
1718 ast_log(LOG_ERROR, "HTTP version not supported - "
1719 "expected %s\n", version);
1720 return -1;
1721 }
1722
1723 /* skip to status code (version + space) */
1724 buf += size + 1;
1725
1726 if (sscanf(buf, "%d", &status_code) != 1) {
1727 ast_log(LOG_ERROR, "Could not read HTTP status code - "
1728 "%s\n", buf);
1729 return -1;
1730 }
1731
1732 return status_code;
1733}
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391

References ast_log, buf, LOG_ERROR, and version.

Referenced by websocket_client_handshake_get_response().

◆ ast_http_send()

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.

Parameters
serTCP/TLS session object
methodGET/POST/HEAD
status_codeHTTP response code (200/401/403/404/500)
status_titleEnglish equivalent to the status_code parameter
http_headerAn ast_str object containing all headers
outAn ast_str object containing the body of the response
fdIf out is NULL, a file descriptor where the body of the response is held (otherwise -1)
static_contentZero if the content is dynamically generated and should not be cached; nonzero otherwise
Note
Function determines the HTTP response header from status_code, status_header, and http_header.

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.

Since
1.8

Definition at line 472 of file http.c.

476{
477 struct timeval now = ast_tvnow();
478 struct ast_tm tm;
479 char timebuf[80];
480 char buf[256];
481 int len;
482 int content_length = 0;
483 int close_connection;
484 struct ast_str *server_header_field = ast_str_create(MAX_SERVER_NAME_LENGTH);
485 int send_content;
486
487 if (!ser || !server_header_field) {
488 /* The connection is not open. */
489 ast_free(http_header);
490 ast_free(out);
491 ast_free(server_header_field);
492 return;
493 }
494
496 ast_str_set(&server_header_field,
497 0,
498 "Server: %s\r\n",
500 }
501
502 /*
503 * We shouldn't be sending non-final status codes to this
504 * function because we may close the connection before
505 * returning.
506 */
507 ast_assert(200 <= status_code);
508
509 if (session_keep_alive <= 0) {
510 close_connection = 1;
511 } else {
513
514 request = ser->private_data;
515 if (!request
517 || ast_http_body_discard(ser)) {
518 close_connection = 1;
519 } else {
520 close_connection = 0;
521 }
522 }
523
524 ast_strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", ast_localtime(&now, &tm, "GMT"));
525
526 /* calc content length */
527 if (out) {
528 content_length += ast_str_strlen(out);
529 }
530
531 if (fd) {
532 content_length += lseek(fd, 0, SEEK_END);
533 lseek(fd, 0, SEEK_SET);
534 }
535
536 send_content = method != AST_HTTP_HEAD || status_code >= 400;
537
538 /* send http header */
540 "HTTP/1.1 %d %s\r\n"
541 "%s"
542 "Date: %s\r\n"
543 "%s"
544 "%s"
545 "%s"
546 "Content-Length: %d\r\n"
547 "\r\n"
548 "%s",
549 status_code, status_title ? status_title : "OK",
550 ast_str_buffer(server_header_field),
551 timebuf,
552 close_connection ? "Connection: close\r\n" : "",
553 static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
554 http_header ? ast_str_buffer(http_header) : "",
555 content_length,
556 send_content && out && ast_str_strlen(out) ? ast_str_buffer(out) : ""
557 ) <= 0) {
558 ast_debug(1, "ast_iostream_printf() failed: %s\n", strerror(errno));
559 close_connection = 1;
560 } else if (send_content && fd) {
561 /* send file content */
562 while ((len = read(fd, buf, sizeof(buf))) > 0) {
563 if (ast_iostream_write(ser->stream, buf, len) != len) {
564 ast_debug(1, "ast_iostream_write() failed: %s\n", strerror(errno));
565 close_connection = 1;
566 break;
567 }
568 }
569 }
570
571 ast_free(http_header);
572 ast_free(out);
573 ast_free(server_header_field);
574
575 if (close_connection) {
576 ast_debug(1, "HTTP closing session. status_code:%d\n", status_code);
578 } else {
579 ast_debug(1, "HTTP keeping session open. status_code:%d\n", status_code);
580 }
581}
int ast_http_body_discard(struct ast_tcptls_session_instance *ser)
Read and discard any unread HTTP request body.
Definition: http.c:1135
static int session_keep_alive
Definition: http.c:108
ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format,...)
Write a formatted string to an iostream.
Definition: iostream.c:502
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
Definition: iostream.c:385
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
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...
Definition: localtime.c:2524
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
struct ast_iostream * stream
Definition: tcptls.h:162
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

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(), httpstatus_callback(), phoneprov_callback(), static_callback(), and websocket_bad_request().

◆ ast_http_uri_link()

int ast_http_uri_link ( struct ast_http_uri urih)

Register a URI handler.

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.

690{
691 struct ast_http_uri *uri;
692 int len = strlen(urih->uri);
693
695
696 urih->prefix = prefix;
697
698 if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
701 return 0;
702 }
703
705 if (AST_RWLIST_NEXT(uri, entry) &&
706 strlen(AST_RWLIST_NEXT(uri, entry)->uri) <= len) {
709
710 return 0;
711 }
712 }
713
715
717
718 return 0;
719}
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:452
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_INSERT_AFTER
Definition: linkedlists.h:702
#define AST_RWLIST_NEXT
Definition: linkedlists.h:441
#define AST_RWLIST_FIRST
Definition: linkedlists.h:423
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
Definition of a URI handler.
Definition: http.h:102
const char * prefix
Definition: http.h:106
const char * uri
Definition: http.h:105
struct ast_http_uri::@230 entry
Definition: http.c:141

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(), and reload_module().

◆ ast_http_uri_unlink()

void ast_http_uri_unlink ( struct ast_http_uri urihandler)

Unregister a URI handler.

Definition at line 721 of file http.c.

722{
724 AST_RWLIST_REMOVE(&uris, urih, entry);
726}
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885

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(), and unload_module().

◆ ast_http_uri_unlink_all_with_key()

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.

729{
730 struct ast_http_uri *urih;
733 if (!strcmp(urih->key, key)) {
735 if (urih->dmallocd) {
736 ast_free(urih->data);
737 }
738 if (urih->mallocd) {
739 ast_free(urih);
740 }
741 }
742 }
745}
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
unsigned int dmallocd
Definition: http.h:112
void * data
Definition: http.h:116
const char * key
Definition: http.h:118
unsigned int mallocd
Definition: http.h:110

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().