2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief http server for AMI access
23 * \author Mark Spencer <markster@digium.com>
25 * This program implements a tiny http server
26 * and was inspired by micro-httpd by Jef Poskanzer
28 * GMime http://spruce.sourceforge.net/gmime/
30 * \ref AstHTTP - AMI over the http protocol
33 /*! \li \ref http.c uses the configuration file \ref http.conf
34 * \addtogroup configuration_file
37 /*! \page http.conf http.conf
38 * \verbinclude http.conf.sample
42 <support_level>core</support_level>
47 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
52 #include <sys/signal.h>
55 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
56 #include "asterisk/cli.h"
57 #include "asterisk/tcptls.h"
58 #include "asterisk/http.h"
59 #include "asterisk/utils.h"
60 #include "asterisk/strings.h"
61 #include "asterisk/config.h"
62 #include "asterisk/stringfields.h"
63 #include "asterisk/ast_version.h"
64 #include "asterisk/manager.h"
65 #include "asterisk/_private.h"
66 #include "asterisk/astobj2.h"
67 #include "asterisk/netsock2.h"
68 #include "asterisk/json.h"
71 #define DEFAULT_PORT 8088
72 #define DEFAULT_TLS_PORT 8089
73 #define DEFAULT_SESSION_LIMIT 100
74 #define DEFAULT_SESSION_INACTIVITY 30000 /* (ms) Idle time waiting for data. */
76 static int session_limit = DEFAULT_SESSION_LIMIT;
77 static int session_inactivity = DEFAULT_SESSION_INACTIVITY;
78 static int session_count = 0;
80 static struct ast_tls_config http_tls_cfg;
82 static void *httpd_helper_thread(void *arg);
85 * we have up to two accepting threads, one for http, one for https
87 static struct ast_tcptls_session_args http_desc = {
89 .master = AST_PTHREADT_NULL,
92 .name = "http server",
93 .accept_fn = ast_tcptls_server_root,
94 .worker_fn = httpd_helper_thread,
97 static struct ast_tcptls_session_args https_desc = {
99 .master = AST_PTHREADT_NULL,
100 .tls_cfg = &http_tls_cfg,
102 .name = "https server",
103 .accept_fn = ast_tcptls_server_root,
104 .worker_fn = httpd_helper_thread,
107 static AST_RWLIST_HEAD_STATIC(uris, ast_http_uri); /*!< list of supported handlers */
109 /* all valid URIs must be prepended by the string in prefix. */
110 static char prefix[MAX_PREFIX];
111 static int enablestatic;
113 /*! \brief Limit the kinds of files we're willing to serve up */
118 { "png", "image/png" },
119 { "xml", "text/xml" },
120 { "jpg", "image/jpeg" },
121 { "js", "application/x-javascript" },
122 { "wav", "audio/x-wav" },
123 { "mp3", "audio/mpeg" },
124 { "svg", "image/svg+xml" },
125 { "svgz", "image/svg+xml" },
126 { "gif", "image/gif" },
127 { "html", "text/html" },
128 { "htm", "text/html" },
129 { "css", "text/css" },
130 { "cnf", "text/plain" },
131 { "cfg", "text/plain" },
132 { "bin", "application/octet-stream" },
133 { "sbn", "application/octet-stream" },
134 { "ld", "application/octet-stream" },
137 struct http_uri_redirect {
138 AST_LIST_ENTRY(http_uri_redirect) entry;
143 static AST_RWLIST_HEAD_STATIC(uri_redirects, http_uri_redirect);
145 static const struct ast_cfhttp_methods_text {
146 enum ast_http_method method;
148 } ast_http_methods_text[] = {
149 { AST_HTTP_UNKNOWN, "UNKNOWN" },
150 { AST_HTTP_GET, "GET" },
151 { AST_HTTP_POST, "POST" },
152 { AST_HTTP_HEAD, "HEAD" },
153 { AST_HTTP_PUT, "PUT" },
154 { AST_HTTP_DELETE, "DELETE" },
155 { AST_HTTP_OPTIONS, "OPTIONS" },
158 const char *ast_get_http_method(enum ast_http_method method)
162 for (x = 0; x < ARRAY_LEN(ast_http_methods_text); x++) {
163 if (ast_http_methods_text[x].method == method) {
164 return ast_http_methods_text[x].text;
171 const char *ast_http_ftype2mtype(const char *ftype)
176 for (x = 0; x < ARRAY_LEN(mimetypes); x++) {
177 if (!strcasecmp(ftype, mimetypes[x].ext)) {
178 return mimetypes[x].mtype;
185 uint32_t ast_http_manid_from_vars(struct ast_variable *headers)
188 struct ast_variable *v, *cookies;
190 cookies = ast_http_get_cookies(headers);
191 for (v = cookies; v; v = v->next) {
192 if (!strcasecmp(v->name, "mansession_id")) {
193 sscanf(v->value, "%30x", &mngid);
197 ast_variables_destroy(cookies);
201 void ast_http_prefix(char *buf, int len)
204 ast_copy_string(buf, prefix, len);
208 static int static_callback(struct ast_tcptls_session_instance *ser,
209 const struct ast_http_uri *urih, const char *uri,
210 enum ast_http_method method, struct ast_variable *get_vars,
211 struct ast_variable *headers)
220 struct ast_str *http_header;
223 char timebuf[80], etag[23];
224 struct ast_variable *v;
225 int not_modified = 0;
227 if (method != AST_HTTP_GET && method != AST_HTTP_HEAD) {
228 ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method");
232 /* Yuck. I'm not really sold on this, but if you don't deliver static content it makes your configuration
233 substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */
234 if (!enablestatic || ast_strlen_zero(uri)) {
238 /* Disallow any funny filenames at all (checking first character only??) */
239 if ((uri[0] < 33) || strchr("./|~@#$%^&*() \t", uri[0])) {
243 if (strstr(uri, "/..")) {
247 if ((ftype = strrchr(uri, '.'))) {
251 if (!(mtype = ast_http_ftype2mtype(ftype))) {
252 snprintf(wkspace, sizeof(wkspace), "text/%s", S_OR(ftype, "plain"));
256 /* Cap maximum length */
257 if ((len = strlen(uri) + strlen(ast_config_AST_DATA_DIR) + strlen("/static-http/") + 5) > 1024) {
261 path = ast_alloca(len);
262 sprintf(path, "%s/static-http/%s", ast_config_AST_DATA_DIR, uri);
263 if (stat(path, &st)) {
267 if (S_ISDIR(st.st_mode)) {
271 if (strstr(path, "/private/") && !astman_is_authed(ast_http_manid_from_vars(headers))) {
275 fd = open(path, O_RDONLY);
280 /* make "Etag:" http header value */
281 snprintf(etag, sizeof(etag), "\"%ld\"", (long)st.st_mtime);
283 /* make "Last-Modified:" http header value */
284 tv.tv_sec = st.st_mtime;
286 ast_strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", ast_localtime(&tv, &tm, "GMT"));
288 /* check received "If-None-Match" request header and Etag value for file */
289 for (v = headers; v; v = v->next) {
290 if (!strcasecmp(v->name, "If-None-Match")) {
291 if (!strcasecmp(v->value, etag)) {
298 if ( (http_header = ast_str_create(255)) == NULL) {
303 ast_str_set(&http_header, 0, "Content-type: %s\r\n"
305 "Last-Modified: %s\r\n",
310 /* ast_http_send() frees http_header, so we don't need to do it before returning */
312 ast_http_send(ser, method, 304, "Not Modified", http_header, NULL, 0, 1);
314 ast_http_send(ser, method, 200, NULL, http_header, NULL, fd, 1); /* static content flag is set */
320 ast_http_error(ser, 404, "Not Found", "The requested URL was not found on this server.");
324 ast_http_error(ser, 403, "Access Denied", "You do not have permission to access the requested URL.");
328 static int httpstatus_callback(struct ast_tcptls_session_instance *ser,
329 const struct ast_http_uri *urih, const char *uri,
330 enum ast_http_method method, struct ast_variable *get_vars,
331 struct ast_variable *headers)
334 struct ast_variable *v, *cookies = NULL;
336 if (method != AST_HTTP_GET && method != AST_HTTP_HEAD) {
337 ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method");
341 if ( (out = ast_str_create(512)) == NULL) {
345 ast_str_append(&out, 0,
346 "<title>Asterisk HTTP Status</title>\r\n"
347 "<body bgcolor=\"#ffffff\">\r\n"
348 "<table bgcolor=\"#f1f1f1\" align=\"center\"><tr><td bgcolor=\"#e0e0ff\" colspan=\"2\" width=\"500\">\r\n"
349 "<h2> Asterisk™ HTTP Status</h2></td></tr>\r\n");
351 ast_str_append(&out, 0, "<tr><td><i>Prefix</i></td><td><b>%s</b></td></tr>\r\n", prefix);
352 ast_str_append(&out, 0, "<tr><td><i>Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
353 ast_sockaddr_stringify_addr(&http_desc.old_address));
354 ast_str_append(&out, 0, "<tr><td><i>Bind Port</i></td><td><b>%s</b></td></tr>\r\n",
355 ast_sockaddr_stringify_port(&http_desc.old_address));
356 if (http_tls_cfg.enabled) {
357 ast_str_append(&out, 0, "<tr><td><i>SSL Bind Port</i></td><td><b>%s</b></td></tr>\r\n",
358 ast_sockaddr_stringify_port(&https_desc.old_address));
360 ast_str_append(&out, 0, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
361 for (v = get_vars; v; v = v->next) {
362 ast_str_append(&out, 0, "<tr><td><i>Submitted GET Variable '%s'</i></td><td>%s</td></tr>\r\n", v->name, v->value);
364 ast_str_append(&out, 0, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
366 cookies = ast_http_get_cookies(headers);
367 for (v = cookies; v; v = v->next) {
368 ast_str_append(&out, 0, "<tr><td><i>Cookie '%s'</i></td><td>%s</td></tr>\r\n", v->name, v->value);
370 ast_variables_destroy(cookies);
372 ast_str_append(&out, 0, "</table><center><font size=\"-1\"><i>Asterisk and Digium are registered trademarks of Digium, Inc.</i></font></center></body>\r\n");
373 ast_http_send(ser, method, 200, NULL, NULL, out, 0, 0);
377 static struct ast_http_uri statusuri = {
378 .callback = httpstatus_callback,
379 .description = "Asterisk HTTP General Status",
386 static struct ast_http_uri staticuri = {
387 .callback = static_callback,
388 .description = "Asterisk HTTP Static Delivery",
396 /* send http/1.1 response */
397 /* free content variable and close socket*/
398 void ast_http_send(struct ast_tcptls_session_instance *ser,
399 enum ast_http_method method, int status_code, const char *status_title,
400 struct ast_str *http_header, struct ast_str *out, const int fd,
401 unsigned int static_content)
403 struct timeval now = ast_tvnow();
406 int content_length = 0;
408 if (!ser || 0 == ser->f) {
412 ast_strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", ast_localtime(&now, &tm, "GMT"));
414 /* calc content length */
416 content_length += ast_str_strlen(out);
420 content_length += lseek(fd, 0, SEEK_END);
421 lseek(fd, 0, SEEK_SET);
424 /* send http header */
425 fprintf(ser->f, "HTTP/1.1 %d %s\r\n"
426 "Server: Asterisk/%s\r\n"
428 "Connection: close\r\n"
430 "Content-Length: %d\r\n"
433 status_code, status_title ? status_title : "OK",
436 static_content ? "" : "Cache-Control: no-cache, no-store\r\n",
438 http_header ? ast_str_buffer(http_header) : ""
442 if (method != AST_HTTP_HEAD || status_code >= 400) {
443 if (out && ast_str_strlen(out)) {
444 if (fwrite(ast_str_buffer(out), ast_str_strlen(out), 1, ser->f) != 1) {
445 ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
452 while ((len = read(fd, buf, sizeof(buf))) > 0) {
453 if (fwrite(buf, len, 1, ser->f) != 1) {
454 ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
462 ast_free(http_header);
468 ast_tcptls_close_session_file(ser);
472 /* Send http "401 Unauthorized" responce and close socket*/
473 void ast_http_auth(struct ast_tcptls_session_instance *ser, const char *realm,
474 const unsigned long nonce, const unsigned long opaque, int stale,
477 struct ast_str *http_headers = ast_str_create(128);
478 struct ast_str *out = ast_str_create(512);
480 if (!http_headers || !out) {
481 ast_free(http_headers);
486 ast_str_set(&http_headers, 0,
487 "WWW-authenticate: Digest algorithm=MD5, realm=\"%s\", nonce=\"%08lx\", qop=\"auth\", opaque=\"%08lx\"%s\r\n"
488 "Content-type: text/html\r\n",
489 realm ? realm : "Asterisk",
492 stale ? ", stale=true" : "");
495 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
497 "<title>401 Unauthorized</title>\r\n"
499 "<h1>401 Unauthorized</h1>\r\n"
502 "<address>Asterisk Server</address>\r\n"
503 "</body></html>\r\n",
506 ast_http_send(ser, AST_HTTP_UNKNOWN, 401, "Unauthorized", http_headers, out, 0, 0);
510 /* send http error response and close socket*/
511 void ast_http_error(struct ast_tcptls_session_instance *ser, int status_code, const char *status_title, const char *text)
513 struct ast_str *http_headers = ast_str_create(40);
514 struct ast_str *out = ast_str_create(256);
516 if (!http_headers || !out) {
517 ast_free(http_headers);
522 ast_str_set(&http_headers, 0, "Content-type: text/html\r\n");
525 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
527 "<title>%d %s</title>\r\n"
532 "<address>Asterisk Server</address>\r\n"
533 "</body></html>\r\n",
534 status_code, status_title, status_title, text);
536 ast_http_send(ser, AST_HTTP_UNKNOWN, status_code, status_title, http_headers, out, 0, 0);
541 * Link the new uri into the list.
543 * They are sorted by length of
544 * the string, not alphabetically. Duplicate entries are not replaced,
545 * but the insertion order (using <= and not just <) makes sure that
546 * more recent insertions hide older ones.
547 * On a lookup, we just scan the list and stop at the first matching entry.
549 int ast_http_uri_link(struct ast_http_uri *urih)
551 struct ast_http_uri *uri;
552 int len = strlen(urih->uri);
554 AST_RWLIST_WRLOCK(&uris);
556 if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
557 AST_RWLIST_INSERT_HEAD(&uris, urih, entry);
558 AST_RWLIST_UNLOCK(&uris);
562 AST_RWLIST_TRAVERSE(&uris, uri, entry) {
563 if (AST_RWLIST_NEXT(uri, entry) &&
564 strlen(AST_RWLIST_NEXT(uri, entry)->uri) <= len) {
565 AST_RWLIST_INSERT_AFTER(&uris, uri, urih, entry);
566 AST_RWLIST_UNLOCK(&uris);
572 AST_RWLIST_INSERT_TAIL(&uris, urih, entry);
574 AST_RWLIST_UNLOCK(&uris);
579 void ast_http_uri_unlink(struct ast_http_uri *urih)
581 AST_RWLIST_WRLOCK(&uris);
582 AST_RWLIST_REMOVE(&uris, urih, entry);
583 AST_RWLIST_UNLOCK(&uris);
586 void ast_http_uri_unlink_all_with_key(const char *key)
588 struct ast_http_uri *urih;
589 AST_RWLIST_WRLOCK(&uris);
590 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&uris, urih, entry) {
591 if (!strcmp(urih->key, key)) {
592 AST_RWLIST_REMOVE_CURRENT(entry);
593 if (urih->dmallocd) {
594 ast_free(urih->data);
601 AST_RWLIST_TRAVERSE_SAFE_END;
602 AST_RWLIST_UNLOCK(&uris);
605 #define MAX_POST_CONTENT 1025
608 * \brief Retrieves the header with the given field name.
610 * \param headers Headers to search.
611 * \param field_name Name of the header to find.
612 * \return Associated header value.
613 * \return \c NULL if header is not present.
615 static const char *get_header(struct ast_variable *headers,
616 const char *field_name)
618 struct ast_variable *v;
620 for (v = headers; v; v = v->next) {
621 if (!strcasecmp(v->name, field_name)) {
629 * \brief Retrieves the content type specified in the "Content-Type" header.
631 * This function only returns the "type/subtype" and any trailing parameter is
634 * \note the return value is an allocated string that needs to be freed.
636 * \retval the content type/subtype or NULL if the header is not found.
638 static char *get_content_type(struct ast_variable *headers)
640 const char *content_type = get_header(headers, "Content-Type");
648 param = strchr(content_type, ';');
649 size = param ? param - content_type : strlen(content_type);
651 return ast_strndup(content_type, size);
655 * \brief Returns the value of the Content-Length header.
657 * \param headers HTTP headers.
658 * \return Value of the Content-Length header.
659 * \return 0 if header is not present, or is invalid.
661 static int get_content_length(struct ast_variable *headers)
663 const char *content_length = get_header(headers, "Content-Length");
665 if (!content_length) {
666 /* Missing content length; assume zero */
670 /* atoi() will return 0 for invalid inputs, which is good enough for
671 * the HTTP parsing. */
672 return atoi(content_length);
676 * \brief Returns the value of the Transfer-Encoding header.
678 * \param headers HTTP headers.
679 * \return Value of the Transfer-Encoding header.
680 * \return 0 if header is not present, or is invalid.
682 static const char *get_transfer_encoding(struct ast_variable *headers)
684 return get_header(headers, "Transfer-Encoding");
688 * \brief decode chunked mode hexadecimal value
690 * \param s string to decode
691 * \param len length of string
692 * \return integer value or -1 for decode error
694 static int chunked_atoh(const char *s, int len)
700 /* zero value must be 0\n not just \n */
711 if (c >= '0' && c <= '9') {
715 if (c >= 'a' && c <= 'f') {
716 value += 10 + c - 'a';
719 if (c >= 'A' && c <= 'F') {
720 value += 10 + c - 'A';
723 /* invalid character */
731 * \brief Returns the contents (body) of the HTTP request
733 * \param return_length ptr to int that returns content length
734 * \param aser HTTP TCP/TLS session object
735 * \param headers List of HTTP headers
736 * \return ptr to content (zero terminated) or NULL on failure
737 * \note Since returned ptr is malloc'd, it should be free'd by caller
739 static char *ast_http_get_contents(int *return_length,
740 struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
742 const char *transfer_encoding;
744 int content_length = 0;
746 char chunk_header[8];
750 transfer_encoding = get_transfer_encoding(headers);
752 if (ast_strlen_zero(transfer_encoding) ||
753 strcasecmp(transfer_encoding, "chunked") != 0) {
754 /* handle regular non-chunked content */
755 content_length = get_content_length(headers);
756 if (content_length <= 0) {
757 /* no content - not an error */
760 if (content_length > MAX_POST_CONTENT - 1) {
762 "Excessively long HTTP content. (%d > %d)\n",
763 content_length, MAX_POST_CONTENT);
767 buf = ast_malloc(content_length + 1);
769 /* Malloc sets ENOMEM */
772 res = fread(buf, 1, content_length, ser->f);
773 if (res < content_length) {
774 /* Error, distinguishable by ferror() or feof(), but neither
775 * is good. Treat either one as I/O error */
776 ast_log(LOG_WARNING, "Short HTTP request body (%d < %d)\n",
777 res, content_length);
782 buf[content_length] = 0;
783 *return_length = content_length;
787 /* pre-allocate buffer */
788 buf = ast_malloc(bufsize);
793 /* handled chunked content */
795 /* get the line of hexadecimal giving chunk size */
796 if (!fgets(chunk_header, sizeof(chunk_header), ser->f)) {
798 "Short HTTP read of chunked header\n");
803 chunk_length = chunked_atoh(chunk_header, sizeof(chunk_header));
804 if (chunk_length < 0) {
805 ast_log(LOG_WARNING, "Invalid HTTP chunk size\n");
810 if (content_length + chunk_length > MAX_POST_CONTENT - 1) {
812 "Excessively long HTTP chunk. (%d + %d > %d)\n",
813 content_length, chunk_length, MAX_POST_CONTENT);
819 /* insure buffer is large enough +1 */
820 if (content_length + chunk_length >= bufsize)
823 buf = ast_realloc(buf, bufsize);
830 res = fread(buf + content_length, 1, chunk_length, ser->f);
831 if (res < chunk_length) {
832 ast_log(LOG_WARNING, "Short HTTP chunk read (%d < %d)\n",
838 content_length += chunk_length;
840 /* insure the next 2 bytes are CRLF */
841 res = fread(chunk_header, 1, 2, ser->f);
844 "Short HTTP chunk sync read (%d < 2)\n", res);
849 if (chunk_header[0] != 0x0D || chunk_header[1] != 0x0A) {
851 "Post HTTP chunk sync bytes wrong (%d, %d)\n",
852 chunk_header[0], chunk_header[1]);
857 } while (chunk_length);
859 buf[content_length] = 0;
860 *return_length = content_length;
864 struct ast_json *ast_http_get_json(
865 struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
867 int content_length = 0;
868 struct ast_json *body;
869 RAII_VAR(char *, buf, NULL, ast_free);
870 RAII_VAR(char *, type, get_content_type(headers), ast_free);
872 /* Use errno to distinguish errors from no body */
875 if (ast_strlen_zero(type) || strcasecmp(type, "application/json")) {
876 /* Content type is not JSON */
880 buf = ast_http_get_contents(&content_length, ser, headers);
882 /* errno already set */
886 if (!content_length) {
887 /* it is not an error to have zero content */
891 body = ast_json_load_buf(buf, content_length, NULL);
893 /* Failed to parse JSON; treat as an I/O error */
902 * get post variables from client Request Entity-Body, if content type is
903 * application/x-www-form-urlencoded
905 struct ast_variable *ast_http_get_post_vars(
906 struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
908 int content_length = 0;
909 struct ast_variable *v, *post_vars=NULL, *prev = NULL;
911 RAII_VAR(char *, buf, NULL, ast_free_ptr);
912 RAII_VAR(char *, type, get_content_type(headers), ast_free);
914 /* Use errno to distinguish errors from no params */
917 if (ast_strlen_zero(type) ||
918 strcasecmp(type, "application/x-www-form-urlencoded")) {
919 /* Content type is not form data */
923 buf = ast_http_get_contents(&content_length, ser, headers);
928 while ((val = strsep(&buf, "&"))) {
929 var = strsep(&val, "=");
931 ast_uri_decode(val, ast_uri_http_legacy);
935 ast_uri_decode(var, ast_uri_http_legacy);
936 if ((v = ast_variable_new(var, val, ""))) {
949 static int handle_uri(struct ast_tcptls_session_instance *ser, char *uri,
950 enum ast_http_method method, struct ast_variable *headers)
955 struct ast_http_uri *urih = NULL;
957 struct ast_variable *get_vars = NULL, *v, *prev = NULL;
958 struct http_uri_redirect *redirect;
960 ast_debug(2, "HTTP Request URI is %s \n", uri);
962 strsep(¶ms, "?");
963 /* Extract arguments from the request and store them in variables. */
967 while ((val = strsep(¶ms, "&"))) {
968 var = strsep(&val, "=");
970 ast_uri_decode(val, ast_uri_http_legacy);
974 ast_uri_decode(var, ast_uri_http_legacy);
975 if ((v = ast_variable_new(var, val, ""))) {
986 AST_RWLIST_RDLOCK(&uri_redirects);
987 AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry) {
988 if (!strcasecmp(uri, redirect->target)) {
989 struct ast_str *http_header = ast_str_create(128);
990 ast_str_set(&http_header, 0, "Location: %s\r\n", redirect->dest);
991 ast_http_send(ser, method, 302, "Moved Temporarily", http_header, NULL, 0, 0);
996 AST_RWLIST_UNLOCK(&uri_redirects);
1001 /* We want requests to start with the (optional) prefix and '/' */
1003 if (!strncasecmp(uri, prefix, l) && uri[l] == '/') {
1005 /* scan registered uris to see if we match one. */
1006 AST_RWLIST_RDLOCK(&uris);
1007 AST_RWLIST_TRAVERSE(&uris, urih, entry) {
1008 l = strlen(urih->uri);
1009 c = uri + l; /* candidate */
1010 ast_debug(2, "match request [%s] with handler [%s] len %d\n", uri, urih->uri, l);
1011 if (strncasecmp(urih->uri, uri, l) /* no match */
1012 || (*c && *c != '/')) { /* substring */
1018 if (!*c || urih->has_subtree) {
1023 AST_RWLIST_UNLOCK(&uris);
1026 ast_debug(1, "Match made with [%s]\n", urih->uri);
1027 if (!urih->no_decode_uri) {
1028 ast_uri_decode(uri, ast_uri_http_legacy);
1030 res = urih->callback(ser, urih, uri, method, get_vars, headers);
1032 ast_debug(1, "Requested URI [%s] has no handler\n", uri);
1033 ast_http_error(ser, 404, "Not Found", "The requested URL was not found on this server.");
1037 ast_variables_destroy(get_vars);
1041 static struct ast_variable *parse_cookies(const char *cookies)
1043 char *parse = ast_strdupa(cookies);
1045 struct ast_variable *vars = NULL, *var;
1047 while ((cur = strsep(&parse, ";"))) {
1053 if (ast_strlen_zero(name) || ast_strlen_zero(val)) {
1057 name = ast_strip(name);
1058 val = ast_strip_quoted(val, "\"", "\"");
1060 if (ast_strlen_zero(name) || ast_strlen_zero(val)) {
1064 ast_debug(1, "HTTP Cookie, Name: '%s' Value: '%s'\n", name, val);
1066 var = ast_variable_new(name, val, __FILE__);
1074 /* get cookie from Request headers */
1075 struct ast_variable *ast_http_get_cookies(struct ast_variable *headers)
1077 struct ast_variable *v, *cookies = NULL;
1079 for (v = headers; v; v = v->next) {
1080 if (!strcasecmp(v->name, "Cookie")) {
1081 ast_variables_destroy(cookies);
1082 cookies = parse_cookies(v->value);
1088 static struct ast_http_auth *auth_create(const char *userid,
1089 const char *password)
1091 RAII_VAR(struct ast_http_auth *, auth, NULL, ao2_cleanup);
1093 size_t password_len;
1095 if (!userid || !password) {
1096 ast_log(LOG_ERROR, "Invalid userid/password\n");
1100 userid_len = strlen(userid) + 1;
1101 password_len = strlen(password) + 1;
1103 /* Allocate enough room to store everything in one memory block */
1104 auth = ao2_alloc(sizeof(*auth) + userid_len + password_len, NULL);
1109 /* Put the userid right after the struct */
1110 auth->userid = (char *)(auth + 1);
1111 strcpy(auth->userid, userid);
1113 /* Put the password right after the userid */
1114 auth->password = auth->userid + userid_len;
1115 strcpy(auth->password, password);
1121 #define BASIC_PREFIX "Basic "
1122 #define BASIC_LEN 6 /*!< strlen(BASIC_PREFIX) */
1124 struct ast_http_auth *ast_http_get_auth(struct ast_variable *headers)
1126 struct ast_variable *v;
1128 for (v = headers; v; v = v->next) {
1130 char decoded[256] = {};
1135 #endif /* AST_DEVMODE */
1137 if (strcasecmp("Authorization", v->name) != 0) {
1141 if (!ast_begins_with(v->value, BASIC_PREFIX)) {
1143 "Unsupported Authorization scheme\n");
1147 /* Basic auth header parsing. RFC 2617, section 2.
1148 * credentials = "Basic" basic-credentials
1149 * basic-credentials = base64-user-pass
1150 * base64-user-pass = <base64 encoding of user-pass,
1151 * except not limited to 76 char/line>
1152 * user-pass = userid ":" password
1155 base64 = v->value + BASIC_LEN;
1157 /* This will truncate "userid:password" lines to
1158 * sizeof(decoded). The array is long enough that this shouldn't
1162 #endif /* AST_DEVMODE */
1163 ast_base64decode((unsigned char*)decoded, base64,
1164 sizeof(decoded) - 1);
1165 ast_assert(cnt < sizeof(decoded));
1167 /* Split the string at the colon */
1169 username = strsep(&password, ":");
1171 ast_log(LOG_WARNING, "Invalid Authorization header\n");
1175 return auth_create(username, password);
1181 int ast_http_response_status_line(const char *buf, const char *version, int code)
1184 size_t size = strlen(version);
1186 if (strncmp(buf, version, size) || buf[size] != ' ') {
1187 ast_log(LOG_ERROR, "HTTP version not supported - "
1188 "expected %s\n", version);
1192 /* skip to status code (version + space) */
1195 if (sscanf(buf, "%d", &status_code) != 1) {
1196 ast_log(LOG_ERROR, "Could not read HTTP status code - "
1204 static void remove_excess_lws(char *s)
1207 char *buf = ast_malloc(strlen(s) + 1);
1216 while (*s && *(s = ast_skip_blanks(s))) {
1218 s = ast_skip_nonblanks(s);
1220 if (buf_end != buf) {
1224 memcpy(buf_end, p, s - p);
1228 /* safe since buf will always be less than or equal to res */
1233 int ast_http_header_parse(char *buf, char **name, char **value)
1235 ast_trim_blanks(buf);
1236 if (ast_strlen_zero(buf)) {
1241 *name = strsep(value, ":");
1246 *value = ast_skip_blanks(*value);
1247 if (ast_strlen_zero(*value) || ast_strlen_zero(*name)) {
1251 remove_excess_lws(*value);
1255 int ast_http_header_match(const char *name, const char *expected_name,
1256 const char *value, const char *expected_value)
1258 if (strcasecmp(name, expected_name)) {
1259 /* no value to validate if names don't match */
1263 if (strcasecmp(value, expected_value)) {
1264 ast_log(LOG_ERROR, "Invalid header value - expected %s "
1265 "received %s", value, expected_value);
1271 int ast_http_header_match_in(const char *name, const char *expected_name,
1272 const char *value, const char *expected_value)
1274 if (strcasecmp(name, expected_name)) {
1275 /* no value to validate if names don't match */
1279 if (!strcasestr(expected_value, value)) {
1280 ast_log(LOG_ERROR, "Header '%s' - could not locate '%s' "
1281 "in '%s'\n", name, value, expected_value);
1288 /*! Limit the number of request headers in case the sender is being ridiculous. */
1289 #define MAX_HTTP_REQUEST_HEADERS 100
1291 static void *httpd_helper_thread(void *data)
1294 char header_line[4096];
1295 struct ast_tcptls_session_instance *ser = data;
1296 struct ast_variable *headers = NULL;
1297 struct ast_variable *tail = headers;
1299 enum ast_http_method http_method = AST_HTTP_UNKNOWN;
1300 const char *transfer_encoding;
1301 int remaining_headers;
1305 if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) {
1309 /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm.
1310 * This is necessary to prevent delays (caused by buffering) as we
1311 * write to the socket in bits and pieces. */
1312 p = getprotobyname("tcp");
1315 if( setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
1316 ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
1317 ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
1320 ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection, getprotobyname(\"tcp\") failed\n");
1321 ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
1324 /* make sure socket is non-blocking */
1325 flags = fcntl(ser->fd, F_GETFL);
1326 flags |= O_NONBLOCK;
1327 fcntl(ser->fd, F_SETFL, flags);
1329 /* We can let the stream wait for data to arrive. */
1330 ast_tcptls_stream_set_exclusive_input(ser->stream_cookie, 1);
1332 ast_tcptls_stream_set_timeout_inactivity(ser->stream_cookie, session_inactivity);
1334 if (!fgets(buf, sizeof(buf), ser->f) || feof(ser->f)) {
1339 method = ast_skip_blanks(buf);
1340 uri = ast_skip_nonblanks(method);
1345 if (!strcasecmp(method,"GET")) {
1346 http_method = AST_HTTP_GET;
1347 } else if (!strcasecmp(method,"POST")) {
1348 http_method = AST_HTTP_POST;
1349 } else if (!strcasecmp(method,"HEAD")) {
1350 http_method = AST_HTTP_HEAD;
1351 } else if (!strcasecmp(method,"PUT")) {
1352 http_method = AST_HTTP_PUT;
1353 } else if (!strcasecmp(method,"DELETE")) {
1354 http_method = AST_HTTP_DELETE;
1355 } else if (!strcasecmp(method,"OPTIONS")) {
1356 http_method = AST_HTTP_OPTIONS;
1359 uri = ast_skip_blanks(uri); /* Skip white space */
1361 if (*uri) { /* terminate at the first blank */
1362 char *c = ast_skip_nonblanks(uri);
1368 ast_http_error(ser, 400, "Bad Request", "Invalid Request");
1372 /* process "Request Headers" lines */
1373 remaining_headers = MAX_HTTP_REQUEST_HEADERS;
1378 if (!fgets(header_line, sizeof(header_line), ser->f) || feof(ser->f)) {
1379 ast_http_error(ser, 400, "Bad Request", "Timeout");
1383 /* Trim trailing characters */
1384 ast_trim_blanks(header_line);
1385 if (ast_strlen_zero(header_line)) {
1386 /* A blank line ends the request header section. */
1390 value = header_line;
1391 name = strsep(&value, ":");
1396 value = ast_skip_blanks(value);
1397 if (ast_strlen_zero(value) || ast_strlen_zero(name)) {
1401 ast_trim_blanks(name);
1403 if (!remaining_headers--) {
1404 /* Too many headers. */
1405 ast_http_error(ser, 413, "Request Entity Too Large", "Too many headers");
1409 headers = ast_variable_new(name, value, __FILE__);
1412 tail->next = ast_variable_new(name, value, __FILE__);
1417 * Variable allocation failure.
1418 * Try to make some room.
1420 ast_variables_destroy(headers);
1423 ast_http_error(ser, 500, "Server Error", "Out of memory");
1428 transfer_encoding = get_transfer_encoding(headers);
1429 /* Transfer encoding defaults to identity */
1430 if (!transfer_encoding) {
1431 transfer_encoding = "identity";
1435 * RFC 2616, section 3.6, we should respond with a 501 for any transfer-
1436 * codings we don't understand.
1438 if (strcasecmp(transfer_encoding, "identity") != 0 &&
1439 strcasecmp(transfer_encoding, "chunked") != 0) {
1440 /* Transfer encodings not supported */
1441 ast_http_error(ser, 501, "Unimplemented", "Unsupported Transfer-Encoding.");
1445 handle_uri(ser, uri, http_method, headers);
1448 ast_atomic_fetchadd_int(&session_count, -1);
1450 /* clean up all the header information */
1451 ast_variables_destroy(headers);
1454 ast_tcptls_close_session_file(ser);
1462 * \brief Add a new URI redirect
1463 * The entries in the redirect list are sorted by length, just like the list
1466 static void add_redirect(const char *value)
1468 char *target, *dest;
1469 struct http_uri_redirect *redirect, *cur;
1470 unsigned int target_len;
1471 unsigned int total_len;
1473 dest = ast_strdupa(value);
1474 dest = ast_skip_blanks(dest);
1475 target = strsep(&dest, " ");
1476 target = ast_skip_blanks(target);
1477 target = strsep(&target, " "); /* trim trailing whitespace */
1480 ast_log(LOG_WARNING, "Invalid redirect '%s'\n", value);
1484 target_len = strlen(target) + 1;
1485 total_len = sizeof(*redirect) + target_len + strlen(dest) + 1;
1487 if (!(redirect = ast_calloc(1, total_len))) {
1490 redirect->dest = redirect->target + target_len;
1491 strcpy(redirect->target, target);
1492 strcpy(redirect->dest, dest);
1494 AST_RWLIST_WRLOCK(&uri_redirects);
1496 target_len--; /* So we can compare directly with strlen() */
1497 if (AST_RWLIST_EMPTY(&uri_redirects)
1498 || strlen(AST_RWLIST_FIRST(&uri_redirects)->target) <= target_len ) {
1499 AST_RWLIST_INSERT_HEAD(&uri_redirects, redirect, entry);
1500 AST_RWLIST_UNLOCK(&uri_redirects);
1505 AST_RWLIST_TRAVERSE(&uri_redirects, cur, entry) {
1506 if (AST_RWLIST_NEXT(cur, entry)
1507 && strlen(AST_RWLIST_NEXT(cur, entry)->target) <= target_len ) {
1508 AST_RWLIST_INSERT_AFTER(&uri_redirects, cur, redirect, entry);
1509 AST_RWLIST_UNLOCK(&uri_redirects);
1514 AST_RWLIST_INSERT_TAIL(&uri_redirects, redirect, entry);
1516 AST_RWLIST_UNLOCK(&uri_redirects);
1519 static int __ast_http_load(int reload)
1521 struct ast_config *cfg;
1522 struct ast_variable *v;
1524 int newenablestatic=0;
1525 char newprefix[MAX_PREFIX] = "";
1526 struct http_uri_redirect *redirect;
1527 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
1528 uint32_t bindport = DEFAULT_PORT;
1529 RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free);
1531 int http_tls_was_enabled = 0;
1533 cfg = ast_config_load2("http.conf", "http", config_flags);
1534 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
1538 http_tls_was_enabled = (reload && http_tls_cfg.enabled);
1540 http_tls_cfg.enabled = 0;
1541 if (http_tls_cfg.certfile) {
1542 ast_free(http_tls_cfg.certfile);
1544 http_tls_cfg.certfile = ast_strdup(AST_CERTFILE);
1546 if (http_tls_cfg.pvtfile) {
1547 ast_free(http_tls_cfg.pvtfile);
1549 http_tls_cfg.pvtfile = ast_strdup("");
1551 if (http_tls_cfg.cipher) {
1552 ast_free(http_tls_cfg.cipher);
1554 http_tls_cfg.cipher = ast_strdup("");
1556 AST_RWLIST_WRLOCK(&uri_redirects);
1557 while ((redirect = AST_RWLIST_REMOVE_HEAD(&uri_redirects, entry))) {
1560 AST_RWLIST_UNLOCK(&uri_redirects);
1562 ast_sockaddr_setnull(&https_desc.local_address);
1564 session_limit = DEFAULT_SESSION_LIMIT;
1565 session_inactivity = DEFAULT_SESSION_INACTIVITY;
1568 v = ast_variable_browse(cfg, "general");
1569 for (; v; v = v->next) {
1571 /* read tls config options while preventing unsupported options from being set */
1572 if (strcasecmp(v->name, "tlscafile")
1573 && strcasecmp(v->name, "tlscapath")
1574 && strcasecmp(v->name, "tlscadir")
1575 && strcasecmp(v->name, "tlsverifyclient")
1576 && strcasecmp(v->name, "tlsdontverifyserver")
1577 && strcasecmp(v->name, "tlsclientmethod")
1578 && strcasecmp(v->name, "sslclientmethod")
1579 && strcasecmp(v->name, "tlscipher")
1580 && strcasecmp(v->name, "sslcipher")
1581 && !ast_tls_read_conf(&http_tls_cfg, &https_desc, v->name, v->value)) {
1585 if (!strcasecmp(v->name, "enabled")) {
1586 enabled = ast_true(v->value);
1587 } else if (!strcasecmp(v->name, "enablestatic")) {
1588 newenablestatic = ast_true(v->value);
1589 } else if (!strcasecmp(v->name, "bindport")) {
1590 if (ast_parse_arg(v->value, PARSE_UINT32 | PARSE_IN_RANGE | PARSE_DEFAULT, &bindport, DEFAULT_PORT, 0, 65535)) {
1591 ast_log(LOG_WARNING, "Invalid port %s specified. Using default port %"PRId32, v->value, DEFAULT_PORT);
1593 } else if (!strcasecmp(v->name, "bindaddr")) {
1594 if (!(num_addrs = ast_sockaddr_resolve(&addrs, v->value, 0, AST_AF_UNSPEC))) {
1595 ast_log(LOG_WARNING, "Invalid bind address %s\n", v->value);
1597 } else if (!strcasecmp(v->name, "prefix")) {
1598 if (!ast_strlen_zero(v->value)) {
1600 ast_copy_string(newprefix + 1, v->value, sizeof(newprefix) - 1);
1602 newprefix[0] = '\0';
1604 } else if (!strcasecmp(v->name, "redirect")) {
1605 add_redirect(v->value);
1606 } else if (!strcasecmp(v->name, "sessionlimit")) {
1607 if (ast_parse_arg(v->value, PARSE_INT32|PARSE_DEFAULT|PARSE_IN_RANGE,
1608 &session_limit, DEFAULT_SESSION_LIMIT, 1, INT_MAX)) {
1609 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of http.conf\n",
1610 v->name, v->value, v->lineno);
1612 } else if (!strcasecmp(v->name, "session_inactivity")) {
1613 if (ast_parse_arg(v->value, PARSE_INT32 |PARSE_DEFAULT | PARSE_IN_RANGE,
1614 &session_inactivity, DEFAULT_SESSION_INACTIVITY, 1, INT_MAX)) {
1615 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of http.conf\n",
1616 v->name, v->value, v->lineno);
1619 ast_log(LOG_WARNING, "Ignoring unknown option '%s' in http.conf\n", v->name);
1623 ast_config_destroy(cfg);
1626 if (strcmp(prefix, newprefix)) {
1627 ast_copy_string(prefix, newprefix, sizeof(prefix));
1629 enablestatic = newenablestatic;
1631 if (num_addrs && enabled) {
1633 for (i = 0; i < num_addrs; ++i) {
1634 ast_sockaddr_copy(&http_desc.local_address, &addrs[i]);
1635 if (!ast_sockaddr_port(&http_desc.local_address)) {
1636 ast_sockaddr_set_port(&http_desc.local_address, bindport);
1638 ast_tcptls_server_start(&http_desc);
1639 if (http_desc.accept_fd == -1) {
1640 ast_log(LOG_WARNING, "Failed to start HTTP server for address %s\n", ast_sockaddr_stringify(&addrs[i]));
1641 ast_sockaddr_setnull(&http_desc.local_address);
1643 ast_verb(1, "Bound HTTP server to address %s\n", ast_sockaddr_stringify(&addrs[i]));
1647 /* When no specific TLS bindaddr is specified, we just use
1648 * the non-TLS bindaddress here.
1650 if (ast_sockaddr_isnull(&https_desc.local_address) && http_desc.accept_fd != -1) {
1651 ast_sockaddr_copy(&https_desc.local_address, &https_desc.local_address);
1652 /* Of course, we can't use the same port though.
1653 * Since no bind address was specified, we just use the
1656 ast_sockaddr_set_port(&https_desc.local_address, DEFAULT_TLS_PORT);
1659 if (http_tls_was_enabled && !http_tls_cfg.enabled) {
1660 ast_tcptls_server_stop(&https_desc);
1661 } else if (http_tls_cfg.enabled && !ast_sockaddr_isnull(&https_desc.local_address)) {
1662 /* We can get here either because a TLS-specific address was specified
1663 * or because we copied the non-TLS address here. In the case where
1664 * we read an explicit address from the config, there may have been
1665 * no port specified, so we'll just use the default TLS port.
1667 if (!ast_sockaddr_port(&https_desc.local_address)) {
1668 ast_sockaddr_set_port(&https_desc.local_address, DEFAULT_TLS_PORT);
1670 if (ast_ssl_setup(https_desc.tls_cfg)) {
1671 ast_tcptls_server_start(&https_desc);
1678 static char *handle_show_http(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1680 struct ast_http_uri *urih;
1681 struct http_uri_redirect *redirect;
1685 e->command = "http show status";
1687 "Usage: http show status\n"
1688 " Lists status of internal HTTP engine\n";
1695 return CLI_SHOWUSAGE;
1697 ast_cli(a->fd, "HTTP Server Status:\n");
1698 ast_cli(a->fd, "Prefix: %s\n", prefix);
1699 if (ast_sockaddr_isnull(&http_desc.old_address)) {
1700 ast_cli(a->fd, "Server Disabled\n\n");
1702 ast_cli(a->fd, "Server Enabled and Bound to %s\n\n",
1703 ast_sockaddr_stringify(&http_desc.old_address));
1704 if (http_tls_cfg.enabled) {
1705 ast_cli(a->fd, "HTTPS Server Enabled and Bound to %s\n\n",
1706 ast_sockaddr_stringify(&https_desc.old_address));
1710 ast_cli(a->fd, "Enabled URI's:\n");
1711 AST_RWLIST_RDLOCK(&uris);
1712 if (AST_RWLIST_EMPTY(&uris)) {
1713 ast_cli(a->fd, "None.\n");
1715 AST_RWLIST_TRAVERSE(&uris, urih, entry)
1716 ast_cli(a->fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
1718 AST_RWLIST_UNLOCK(&uris);
1720 ast_cli(a->fd, "\nEnabled Redirects:\n");
1721 AST_RWLIST_RDLOCK(&uri_redirects);
1722 AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry)
1723 ast_cli(a->fd, " %s => %s\n", redirect->target, redirect->dest);
1724 if (AST_RWLIST_EMPTY(&uri_redirects)) {
1725 ast_cli(a->fd, " None.\n");
1727 AST_RWLIST_UNLOCK(&uri_redirects);
1732 int ast_http_reload(void)
1734 return __ast_http_load(1);
1737 static struct ast_cli_entry cli_http[] = {
1738 AST_CLI_DEFINE(handle_show_http, "Display HTTP server status"),
1741 static void http_shutdown(void)
1743 struct http_uri_redirect *redirect;
1744 ast_cli_unregister_multiple(cli_http, ARRAY_LEN(cli_http));
1746 ast_tcptls_server_stop(&http_desc);
1747 if (http_tls_cfg.enabled) {
1748 ast_tcptls_server_stop(&https_desc);
1750 ast_free(http_tls_cfg.certfile);
1751 ast_free(http_tls_cfg.pvtfile);
1752 ast_free(http_tls_cfg.cipher);
1754 ast_http_uri_unlink(&statusuri);
1755 ast_http_uri_unlink(&staticuri);
1757 AST_RWLIST_WRLOCK(&uri_redirects);
1758 while ((redirect = AST_RWLIST_REMOVE_HEAD(&uri_redirects, entry))) {
1761 AST_RWLIST_UNLOCK(&uri_redirects);
1764 int ast_http_init(void)
1766 ast_http_uri_link(&statusuri);
1767 ast_http_uri_link(&staticuri);
1768 ast_cli_register_multiple(cli_http, ARRAY_LEN(cli_http));
1769 ast_register_atexit(http_shutdown);
1771 return __ast_http_load(0);