00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 #ifndef _ASTERISK_HTTP_H 00020 #define _ASTERISK_HTTP_H 00021 00022 #include "asterisk/config.h" 00023 #include "asterisk/tcptls.h" 00024 #include "asterisk/linkedlists.h" 00025 00026 /*! 00027 * \file http.h 00028 * \brief Support for Private Asterisk HTTP Servers. 00029 * \note Note: The Asterisk HTTP servers are extremely simple and minimal and 00030 * only support the "GET" method. 00031 * 00032 * \author Mark Spencer <markster@digium.com> 00033 * 00034 * \note In order to have TLS/SSL support, we need the openssl libraries. 00035 * Still we can decide whether or not to use them by commenting 00036 * in or out the DO_SSL macro. 00037 * TLS/SSL support is basically implemented by reading from a config file 00038 * (currently http.conf) the names of the certificate and cipher to use, 00039 * and then run ssl_setup() to create an appropriate SSL_CTX (ssl_ctx) 00040 * If we support multiple domains, presumably we need to read multiple 00041 * certificates. 00042 * When we are requested to open a TLS socket, we run make_file_from_fd() 00043 * on the socket, to do the necessary setup. At the moment the context's name 00044 * is hardwired in the function, but we can certainly make it into an extra 00045 * parameter to the function. 00046 * We declare most of ssl support variables unconditionally, 00047 * because their number is small and this simplifies the code. 00048 * 00049 * \note: the ssl-support variables (ssl_ctx, do_ssl, certfile, cipher) 00050 * and their setup should be moved to a more central place, e.g. asterisk.conf 00051 * and the source files that processes it. Similarly, ssl_setup() should 00052 * be run earlier in the startup process so modules have it available. 00053 */ 00054 00055 00056 /*! \brief HTTP Callbacks take the socket 00057 00058 \note The method and the path as arguments and should 00059 return the content, allocated with malloc(). Status should be changed to reflect 00060 the status of the request if it isn't 200 and title may be set to a malloc()'d string 00061 to an appropriate title for non-200 responses. Content length may also be specified. 00062 \verbatim 00063 The return value may include additional headers at the front and MUST include a blank 00064 line with \r\n to provide separation between user headers and content (even if no 00065 content is specified) 00066 \endverbatim 00067 */ 00068 typedef struct ast_str *(*ast_http_callback)(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength); 00069 00070 /*! \brief Definition of a URI reachable in the embedded HTTP server */ 00071 struct ast_http_uri { 00072 AST_LIST_ENTRY(ast_http_uri) entry; 00073 const char *description; 00074 const char *uri; 00075 unsigned int has_subtree:1; 00076 /*! This URI mapping serves static content */ 00077 unsigned int static_content:1; 00078 ast_http_callback callback; 00079 }; 00080 00081 /*! \brief Link into the Asterisk HTTP server */ 00082 int ast_http_uri_link(struct ast_http_uri *urihandler); 00083 00084 /*! \brief Return an ast_str malloc()'d string containing an HTTP error message */ 00085 struct ast_str *ast_http_error(int status, const char *title, const char *extra_header, const char *text); 00086 00087 /*! \brief Destroy an HTTP server */ 00088 void ast_http_uri_unlink(struct ast_http_uri *urihandler); 00089 00090 int ast_http_init(void); 00091 int ast_http_reload(void); 00092 00093 #endif /* _ASTERISK_SRV_H */