Asterisk - The Open Source Telephony Project  18.5.0
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...
 
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...
 
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...
 
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 97 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 56 of file http.h.

56  {
57  AST_HTTP_UNKNOWN = -1, /*!< Unknown response */
58  AST_HTTP_GET = 0,
64  AST_HTTP_MAX_METHOD, /*!< Last entry in ast_http_method enum */
65 };

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 190 of file http.c.

References ARRAY_LEN, ast_http_methods_text, NULL, and ast_cfhttp_methods_text::text.

Referenced by add_allow_header(), ast_ari_invoke(), auth_http_callback(), and handle_options().

191 {
192  int x;
193 
194  for (x = 0; x < ARRAY_LEN(ast_http_methods_text); x++) {
195  if (ast_http_methods_text[x].method == method) {
196  return ast_http_methods_text[x].text;
197  }
198  }
199 
200  return NULL;
201 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const char * text
Definition: http.c:179
#define NULL
Definition: resample.c:96
const char * method
Definition: res_pjsip.c:4335
static const struct ast_cfhttp_methods_text ast_http_methods_text[]

◆ 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 622 of file http.c.

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

Referenced by auth_http_callback().

625 {
626  int status_code = 401;
627  char *status_title = "Unauthorized";
628  struct ast_str *http_header_data = ast_str_create(DEFAULT_RESPONSE_HEADER_LENGTH);
629 
630  if (http_header_data) {
631  ast_str_set(&http_header_data,
632  0,
633  "WWW-authenticate: Digest algorithm=MD5, realm=\"%s\", nonce=\"%08lx\", qop=\"auth\", opaque=\"%08lx\"%s\r\n"
634  "Content-type: text/html\r\n",
635  realm ? realm : "Asterisk",
636  nonce,
637  opaque,
638  stale ? ", stale=true" : "");
639  }
640 
642  status_code,
643  status_title,
644  http_header_data,
645  text);
646 }
char * text
Definition: app_queue.c:1508
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:1065
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
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:567
#define DEFAULT_RESPONSE_HEADER_LENGTH
Definition: http.c:81
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ 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 1120 of file http.c.

References ast_assert, ast_debug, ast_set_flag, ast_test_flag, http_worker_private_data::body_length, http_worker_private_data::flags, 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().

1121 {
1123 
1124  request = ser->private_data;
1125  if (!ast_test_flag(&request->flags, HTTP_FLAG_HAS_BODY)
1126  || ast_test_flag(&request->flags, HTTP_FLAG_BODY_READ)) {
1127  /* No body to read or it has already been read. */
1128  return 0;
1129  }
1131 
1132  ast_debug(1, "HTTP discarding unused request body\n");
1133 
1134  ast_assert(request->body_length != 0);
1135  if (0 < request->body_length) {
1136  if (http_body_discard_contents(ser, request->body_length, "body")) {
1138  return -1;
1139  }
1140  return 0;
1141  }
1142 
1143  /* parse chunked-body */
1144  for (;;) {
1145  int length;
1146 
1147  length = http_body_get_chunk_length(ser);
1148  if (length < 0) {
1150  return -1;
1151  }
1152  if (length == 0) {
1153  /* parsed last-chunk */
1154  break;
1155  }
1156 
1157  if (http_body_discard_contents(ser, length, "chunk-data")
1158  || http_body_check_chunk_sync(ser)) {
1160  return -1;
1161  }
1162  }
1163 
1164  /* Read and discard any trailer entity-header lines. */
1167  return -1;
1168  }
1169  return 0;
1170 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ast_assert(a)
Definition: utils.h:695
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
struct ast_flags flags
Definition: http.c:453
static int http_body_get_chunk_length(struct ast_tcptls_session_instance *ser)
Definition: http.c:1041
static int request(void *obj)
Definition: chan_pjsip.c:2559
static int http_body_discard_chunk_trailer_headers(struct ast_tcptls_session_instance *ser)
Definition: http.c:1100
static int http_body_discard_contents(struct ast_tcptls_session_instance *ser, int length, const char *what_getting)
Definition: http.c:964
static int http_body_check_chunk_sync(struct ast_tcptls_session_instance *ser)
Definition: http.c:1069

◆ 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.
Returns
Nothing

Definition at line 899 of file http.c.

References ast_set_flag, ast_test_flag, http_worker_private_data::flags, 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().

900 {
902 
903  request = ser->private_data;
904  if (!ast_test_flag(&request->flags, HTTP_FLAG_HAS_BODY)
905  || ast_test_flag(&request->flags, HTTP_FLAG_BODY_READ)) {
906  /* No body to read. */
907  return;
908  }
910  if (!read_success) {
912  }
913 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set_flag(p, flag)
Definition: utils.h:70
struct ast_flags flags
Definition: http.c:453
static int request(void *obj)
Definition: chan_pjsip.c:2559

◆ 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 567 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, and out.

Referenced by ast_http_auth(), and ast_http_error().

569 {
570  char server_name[MAX_SERVER_NAME_LENGTH];
571  struct ast_str *server_address = ast_str_create(MAX_SERVER_NAME_LENGTH);
573 
574  if (!http_header_data || !server_address || !out) {
575  ast_free(http_header_data);
576  ast_free(server_address);
577  ast_free(out);
578  if (ser) {
579  ast_debug(1, "HTTP closing session. OOM.\n");
581  }
582  return;
583  }
584 
586  ast_xml_escape(http_server_name, server_name, sizeof(server_name));
587  ast_str_set(&server_address,
588  0,
589  "<address>%s</address>\r\n",
590  server_name);
591  }
592 
593  ast_str_set(&out,
594  0,
595  "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
596  "<html><head>\r\n"
597  "<title>%d %s</title>\r\n"
598  "</head><body>\r\n"
599  "<h1>%s</h1>\r\n"
600  "<p>%s</p>\r\n"
601  "<hr />\r\n"
602  "%s"
603  "</body></html>\r\n",
604  status_code,
605  status_title,
606  status_title,
607  text ? text : "",
608  ast_str_buffer(server_address));
609 
610  ast_free(server_address);
611 
612  ast_http_send(ser,
614  status_code,
615  status_title,
616  http_header_data,
617  out,
618  0,
619  0);
620 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define INITIAL_RESPONSE_BODY_BUFFER
Definition: http.c:92
char * text
Definition: app_queue.c:1508
int ast_xml_escape(const char *string, char *outbuf, size_t buflen)
Escape reserved characters for use in XML.
Definition: main/utils.c:718
#define ast_strlen_zero(foo)
Definition: strings.h:52
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:1065
#define MAX_SERVER_NAME_LENGTH
Definition: http.c:79
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
static char http_server_name[MAX_SERVER_NAME_LENGTH]
Definition: http.c:104
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
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:456
#define ast_free(a)
Definition: astmm.h:182
FILE * out
Definition: utils/frame.c:33
void ast_tcptls_close_session_file(struct ast_tcptls_session_instance *tcptls_session)
Closes a tcptls session instance&#39;s file and/or file descriptor. The tcptls_session will be set to NUL...
Definition: tcptls.c:839
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ 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 648 of file http.c.

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

Referenced by ast_ari_callback(), ast_ari_events_event_websocket_ws_attempted_cb(), ast_websocket_uri_cb(), auth_http_callback(), event_session_allocation_error_handler(), 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(), static_callback(), and websocket_bad_request().

650 {
651  struct ast_str *http_header_data = ast_str_create(DEFAULT_RESPONSE_HEADER_LENGTH);
652 
653  if (http_header_data) {
654  ast_str_set(&http_header_data, 0, "Content-type: text/html\r\n");
655  }
656 
658  status_code,
659  status_title,
660  http_header_data,
661  text);
662 }
char * text
Definition: app_queue.c:1508
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:1065
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
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:567
#define DEFAULT_RESPONSE_HEADER_LENGTH
Definition: http.c:81
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ 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 203 of file http.c.

References ARRAY_LEN, ext, mimetypes, and NULL.

Referenced by build_profile(), and static_callback().

204 {
205  int x;
206 
207  if (ftype) {
208  for (x = 0; x < ARRAY_LEN(mimetypes); x++) {
209  if (!strcasecmp(ftype, mimetypes[x].ext)) {
210  return mimetypes[x].mtype;
211  }
212  }
213  }
214  return NULL;
215 }
static struct @395 mimetypes[]
Limit the kinds of files we&#39;re willing to serve up.
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define NULL
Definition: resample.c:96
const char * ext
Definition: http.c:147

◆ 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.
NULL if no supported HTTP auth headers present.
Since
12

Definition at line 1579 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, password, strsep(), and ast_variable::value.

Referenced by authenticate_user(), and http_callback().

1580 {
1581  struct ast_variable *v;
1582 
1583  for (v = headers; v; v = v->next) {
1584  const char *base64;
1585  char decoded[256] = {};
1586  char *username;
1587  char *password;
1588 #ifdef AST_DEVMODE
1589  int cnt;
1590 #endif /* AST_DEVMODE */
1591 
1592  if (strcasecmp("Authorization", v->name) != 0) {
1593  continue;
1594  }
1595 
1596  if (!ast_begins_with(v->value, BASIC_PREFIX)) {
1598  "Unsupported Authorization scheme\n");
1599  continue;
1600  }
1601 
1602  /* Basic auth header parsing. RFC 2617, section 2.
1603  * credentials = "Basic" basic-credentials
1604  * basic-credentials = base64-user-pass
1605  * base64-user-pass = <base64 encoding of user-pass,
1606  * except not limited to 76 char/line>
1607  * user-pass = userid ":" password
1608  */
1609 
1610  base64 = v->value + BASIC_LEN;
1611 
1612  /* This will truncate "userid:password" lines to
1613  * sizeof(decoded). The array is long enough that this shouldn't
1614  * be a problem */
1615 #ifdef AST_DEVMODE
1616  cnt =
1617 #endif /* AST_DEVMODE */
1618  ast_base64decode((unsigned char*)decoded, base64,
1619  sizeof(decoded) - 1);
1620  ast_assert(cnt < sizeof(decoded));
1621 
1622  /* Split the string at the colon */
1623  password = decoded;
1624  username = strsep(&password, ":");
1625  if (!password) {
1626  ast_log(LOG_WARNING, "Invalid Authorization header\n");
1627  return NULL;
1628  }
1629 
1630  return auth_create(username, password);
1631  }
1632 
1633  return NULL;
1634 }
struct ast_variable * next
#define LOG_WARNING
Definition: logger.h:274
Structure for variables, used for configurations and for channel variables.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define LOG_DEBUG
Definition: logger.h:241
static struct ast_str * password
Definition: cdr_mysql.c:77
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
Definition: main/utils.c:294
#define ast_log
Definition: astobj2.c:42
#define BASIC_LEN
Definition: http.c:1577
static struct ast_http_auth * auth_create(const char *userid, const char *password)
Definition: http.c:1545
char * strsep(char **str, const char *delims)
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Definition: strings.h:94
#define BASIC_PREFIX
Definition: http.c:1576
static char base64[64]
Definition: main/utils.c:78

◆ ast_http_get_cookies()

struct ast_variable* ast_http_get_cookies ( struct ast_variable headers)

Get cookie from Request headers.

Definition at line 1532 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().

1533 {
1534  struct ast_variable *v, *cookies = NULL;
1535 
1536  for (v = headers; v; v = v->next) {
1537  if (!strcasecmp(v->name, "Cookie")) {
1538  ast_variables_destroy(cookies);
1539  cookies = parse_cookies(v->value);
1540  }
1541  }
1542  return cookies;
1543 }
struct ast_variable * next
static struct ast_variable * parse_cookies(const char *cookies)
Definition: http.c:1498
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96

◆ 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
NULL on error, if no content, or if different content type.
Since
12

Definition at line 1314 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().

1316 {
1317  int content_length = 0;
1318  struct ast_json *body;
1319  RAII_VAR(char *, buf, NULL, ast_free);
1320  RAII_VAR(char *, type, get_content_type(headers), ast_free);
1321 
1322  /* Use errno to distinguish errors from no body */
1323  errno = 0;
1324 
1325  if (ast_strlen_zero(type) || strcasecmp(type, "application/json")) {
1326  /* Content type is not JSON. Don't read the body. */
1327  return NULL;
1328  }
1329 
1330  buf = ast_http_get_contents(&content_length, ser, headers);
1331  if (!buf || !content_length) {
1332  /*
1333  * errno already set
1334  * or it is not an error to have zero content
1335  */
1336  return NULL;
1337  }
1338 
1339  body = ast_json_load_buf(buf, content_length, NULL);
1340  if (!body) {
1341  /* Failed to parse JSON; treat as an I/O error */
1342  errno = EIO;
1343  return NULL;
1344  }
1345 
1346  return body;
1347 }
static const char type[]
Definition: chan_ooh323.c:109
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:1181
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:564
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:761
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#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:911
int errno
#define ast_free(a)
Definition: astmm.h:182
Abstract JSON element (object, array, string, int, ...).

◆ 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 1353 of file http.c.

References ast_free, ast_http_get_contents(), ast_strlen_zero, ast_uri_decode(), ast_uri_http_legacy, ast_variable_new, buf, errno, get_content_type(), NULL, RAII_VAR, strsep(), type, and var.

Referenced by ast_ari_callback(), auth_http_callback(), and generic_http_callback().

1355 {
1356  int content_length = 0;
1357  struct ast_variable *v, *post_vars=NULL, *prev = NULL;
1358  char *var, *val;
1359  RAII_VAR(char *, buf, NULL, ast_free);
1360  RAII_VAR(char *, type, get_content_type(headers), ast_free);
1361 
1362  /* Use errno to distinguish errors from no params */
1363  errno = 0;
1364 
1365  if (ast_strlen_zero(type) ||
1366  strcasecmp(type, "application/x-www-form-urlencoded")) {
1367  /* Content type is not form data. Don't read the body. */
1368  return NULL;
1369  }
1370 
1371  buf = ast_http_get_contents(&content_length, ser, headers);
1372  if (!buf || !content_length) {
1373  /*
1374  * errno already set
1375  * or it is not an error to have zero content
1376  */
1377  return NULL;
1378  }
1379 
1380  while ((val = strsep(&buf, "&"))) {
1381  var = strsep(&val, "=");
1382  if (val) {
1384  } else {
1385  val = "";
1386  }
1388  if ((v = ast_variable_new(var, val, ""))) {
1389  if (post_vars) {
1390  prev->next = v;
1391  } else {
1392  post_vars = v;
1393  }
1394  prev = v;
1395  }
1396  }
1397 
1398  return post_vars;
1399 }
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
Definition: main/utils.c:616
static const char type[]
Definition: chan_ooh323.c:109
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:1181
Definition: ast_expr2.c:325
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:761
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#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:911
#define ast_variable_new(name, value, filename)
const struct ast_flags ast_uri_http_legacy
Definition: main/utils.c:574
int errno
#define ast_free(a)
Definition: astmm.h:182
char * strsep(char **str, const char *delims)

◆ 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
Returns
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
Since
13

Definition at line 1710 of file http.c.

References ast_log, and LOG_ERROR.

Referenced by websocket_client_handshake_get_response().

1712 {
1713  if (strcasecmp(name, expected_name)) {
1714  /* no value to validate if names don't match */
1715  return 0;
1716  }
1717 
1718  if (strcasecmp(value, expected_value)) {
1719  ast_log(LOG_ERROR, "Invalid header value - expected %s "
1720  "received %s", value, expected_value);
1721  return -1;
1722  }
1723  return 1;
1724 }
int value
Definition: syslog.c:37
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
static const char name[]
Definition: cdr_mysql.c:74

◆ 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)
Returns
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
Since
13

Definition at line 1726 of file http.c.

References ast_log, LOG_ERROR, and strcasestr().

Referenced by websocket_client_handshake_get_response().

1728 {
1729  if (strcasecmp(name, expected_name)) {
1730  /* no value to validate if names don't match */
1731  return 0;
1732  }
1733 
1734  if (!strcasestr(expected_value, value)) {
1735  ast_log(LOG_ERROR, "Header '%s' - could not locate '%s' "
1736  "in '%s'\n", name, value, expected_value);
1737  return -1;
1738 
1739  }
1740  return 1;
1741 }
int value
Definition: syslog.c:37
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
char * strcasestr(const char *, const char *)
static const char name[]
Definition: cdr_mysql.c:74

◆ 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
nameout parameter pointing to the header name
valueout parameter pointing to header value
Returns
-1 if buf is empty
0 if buf could be separated into name and value
1 if name or value portion don't exist
Since
13

Definition at line 1688 of file http.c.

References ast_skip_blanks(), ast_strlen_zero, ast_trim_blanks(), buf, remove_excess_lws(), and strsep().

Referenced by websocket_client_handshake_get_response().

1689 {
1691  if (ast_strlen_zero(buf)) {
1692  return -1;
1693  }
1694 
1695  *value = buf;
1696  *name = strsep(value, ":");
1697  if (!*value) {
1698  return 1;
1699  }
1700 
1703  return 1;
1704  }
1705 
1707  return 0;
1708 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
Definition: strings.h:182
static const char name[]
Definition: cdr_mysql.c:74
char * strsep(char **str, const char *delims)
static void remove_excess_lws(char *s)
Definition: http.c:1659

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

218 {
219  uint32_t mngid = 0;
220  struct ast_variable *v, *cookies;
221 
222  cookies = ast_http_get_cookies(headers);
223  for (v = cookies; v; v = v->next) {
224  if (!strcasecmp(v->name, "mansession_id")) {
225  sscanf(v->value, "%30x", &mngid);
226  break;
227  }
228  }
229  ast_variables_destroy(cookies);
230  return mngid;
231 }
struct ast_variable * next
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
struct ast_variable * ast_http_get_cookies(struct ast_variable *headers)
Get cookie from Request headers.
Definition: http.c:1532
Structure for variables, used for configurations and for channel variables.

◆ 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 233 of file http.c.

References ast_copy_string(), and prefix.

234 {
235  if (buf) {
237  }
238 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ 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.
Returns
Nothing

Definition at line 836 of file http.c.

References ast_set_flag, http_worker_private_data::flags, HTTP_FLAG_CLOSE_ON_COMPLETION, ast_tcptls_session_instance::private_data, and request().

Referenced by ast_ari_callback(), auth_http_callback(), generic_http_callback(), handle_uri(), http_callback(), http_post_callback(), httpstatus_callback(), static_callback(), and websocket_bad_request().

837 {
839 
841 }
#define ast_set_flag(p, flag)
Definition: utils.h:70
struct ast_flags flags
Definition: http.c:453
static int request(void *obj)
Definition: chan_pjsip.c:2559

◆ 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
Returns
-1 if version didn't match or status code conversion fails.
status code (>0)
Since
13

Definition at line 1636 of file http.c.

References ast_log, and LOG_ERROR.

Referenced by websocket_client_handshake_get_response().

1637 {
1638  int status_code;
1639  size_t size = strlen(version);
1640 
1641  if (strncmp(buf, version, size) || buf[size] != ' ') {
1642  ast_log(LOG_ERROR, "HTTP version not supported - "
1643  "expected %s\n", version);
1644  return -1;
1645  }
1646 
1647  /* skip to status code (version + space) */
1648  buf += size + 1;
1649 
1650  if (sscanf(buf, "%d", &status_code) != 1) {
1651  ast_log(LOG_ERROR, "Could not read HTTP status code - "
1652  "%s\n", buf);
1653  return -1;
1654  }
1655 
1656  return status_code;
1657 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391

◆ 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 456 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_worker_private_data::flags, HTTP_FLAG_CLOSE_ON_COMPLETION, http_server_name, len(), MAX_SERVER_NAME_LENGTH, 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(), static_callback(), and websocket_bad_request().

460 {
461  struct timeval now = ast_tvnow();
462  struct ast_tm tm;
463  char timebuf[80];
464  char buf[256];
465  int len;
466  int content_length = 0;
467  int close_connection;
468  struct ast_str *server_header_field = ast_str_create(MAX_SERVER_NAME_LENGTH);
469  int send_content;
470 
471  if (!ser || !server_header_field) {
472  /* The connection is not open. */
473  ast_free(http_header);
474  ast_free(out);
475  ast_free(server_header_field);
476  return;
477  }
478 
480  ast_str_set(&server_header_field,
481  0,
482  "Server: %s\r\n",
484  }
485 
486  /*
487  * We shouldn't be sending non-final status codes to this
488  * function because we may close the connection before
489  * returning.
490  */
491  ast_assert(200 <= status_code);
492 
493  if (session_keep_alive <= 0) {
494  close_connection = 1;
495  } else {
497 
498  request = ser->private_data;
499  if (!request
501  || ast_http_body_discard(ser)) {
502  close_connection = 1;
503  } else {
504  close_connection = 0;
505  }
506  }
507 
508  ast_strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", ast_localtime(&now, &tm, "GMT"));
509 
510  /* calc content length */
511  if (out) {
512  content_length += ast_str_strlen(out);
513  }
514 
515  if (fd) {
516  content_length += lseek(fd, 0, SEEK_END);
517  lseek(fd, 0, SEEK_SET);
518  }
519 
520  send_content = method != AST_HTTP_HEAD || status_code >= 400;
521 
522  /* send http header */
523  if (ast_iostream_printf(ser->stream,
524  "HTTP/1.1 %d %s\r\n"
525  "%s"
526  "Date: %s\r\n"
527  "%s"
528  "%s"
529  "%s"
530  "Content-Length: %d\r\n"
531  "\r\n"
532  "%s",
533  status_code, status_title ? status_title : "OK",
534  ast_str_buffer(server_header_field),
535  timebuf,
536  close_connection ? "Connection: close\r\n" : "",
537  static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
538  http_header ? ast_str_buffer(http_header) : "",
539  content_length,
540  send_content && out && ast_str_strlen(out) ? ast_str_buffer(out) : ""
541  ) <= 0) {
542  ast_debug(1, "ast_iostream_printf() failed: %s\n", strerror(errno));
543  close_connection = 1;
544  } else if (send_content && fd) {
545  /* send file content */
546  while ((len = read(fd, buf, sizeof(buf))) > 0) {
547  if (ast_iostream_write(ser->stream, buf, len) != len) {
548  ast_debug(1, "ast_iostream_write() failed: %s\n", strerror(errno));
549  close_connection = 1;
550  break;
551  }
552  }
553  }
554 
555  ast_free(http_header);
556  ast_free(out);
557  ast_free(server_header_field);
558 
559  if (close_connection) {
560  ast_debug(1, "HTTP closing session. status_code:%d\n", status_code);
562  } else {
563  ast_debug(1, "HTTP keeping session open. status_code:%d\n", status_code);
564  }
565 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
Definition: iostream.c:374
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ast_assert(a)
Definition: utils.h:695
#define ast_strlen_zero(foo)
Definition: strings.h:52
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:1065
#define MAX_SERVER_NAME_LENGTH
Definition: http.c:79
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
int ast_http_body_discard(struct ast_tcptls_session_instance *ser)
Read and discard any unread HTTP request body.
Definition: http.c:1120
const char * method
Definition: res_pjsip.c:4335
ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format,...)
Write a formatted string to an iostream.
Definition: iostream.c:491
static char http_server_name[MAX_SERVER_NAME_LENGTH]
Definition: http.c:104
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_flags flags
Definition: http.c:453
int errno
#define ast_free(a)
Definition: astmm.h:182
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
static int request(void *obj)
Definition: chan_pjsip.c:2559
struct ast_iostream * stream
Definition: tcptls.h:160
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
void ast_tcptls_close_session_file(struct ast_tcptls_session_instance *tcptls_session)
Closes a tcptls session instance&#39;s file and/or file descriptor. The tcptls_session will be set to NUL...
Definition: tcptls.c:839
static int session_keep_alive
Definition: http.c:108
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ 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 673 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, 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().

674 {
675  struct ast_http_uri *uri;
676  int len = strlen(urih->uri);
677 
679 
680  urih->prefix = prefix;
681 
682  if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
685  return 0;
686  }
687 
688  AST_RWLIST_TRAVERSE(&uris, uri, entry) {
689  if (AST_RWLIST_NEXT(uri, entry) &&
690  strlen(AST_RWLIST_NEXT(uri, entry)->uri) <= len) {
691  AST_RWLIST_INSERT_AFTER(&uris, uri, urih, entry);
693 
694  return 0;
695  }
696  }
697 
699 
701 
702  return 0;
703 }
#define AST_RWLIST_NEXT
Definition: linkedlists.h:440
#define AST_RWLIST_INSERT_AFTER
Definition: linkedlists.h:701
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const char * prefix
Definition: http.h:104
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
Definition of a URI handler.
Definition: http.h:100
Definition: search.h:40
Definition: http.c:138
const char * uri
Definition: http.h:103
#define AST_RWLIST_FIRST
Definition: linkedlists.h:422
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ ast_http_uri_unlink()

void ast_http_uri_unlink ( struct ast_http_uri urihandler)

Unregister a URI handler.

Definition at line 705 of file http.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by __ast_http_load(), __init_manager(), load_module(), reload_module(), and unload_module().

706 {
708  AST_RWLIST_REMOVE(&uris, urih, entry);
710 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884
Definition: search.h:40
Definition: http.c:138

◆ 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 712 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::key, and ast_http_uri::mallocd.

Referenced by __ast_http_post_load(), and unload_module().

713 {
714  struct ast_http_uri *urih;
717  if (!strcmp(urih->key, key)) {
719  if (urih->dmallocd) {
720  ast_free(urih->data);
721  }
722  if (urih->mallocd) {
723  ast_free(urih);
724  }
725  }
726  }
729 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * key
Definition: http.h:116
unsigned int mallocd
Definition: http.h:108
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
#define ast_free(a)
Definition: astmm.h:182
Definition of a URI handler.
Definition: http.h:100
unsigned int dmallocd
Definition: http.h:110
Definition: search.h:40
Definition: http.c:138
void * data
Definition: http.h:114
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616