Support for Private Asterisk HTTP Servers. More...
#include "asterisk/config.h"
#include "asterisk/tcptls.h"
#include "asterisk/linkedlists.h"
Go to the source code of this file.
Data Structures | |
struct | ast_http_uri |
Definition of a URI handler. More... | |
Typedefs | |
typedef struct ast_str *(* | 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 *params, struct ast_variable *headers, int *status, char **title, int *contentlength) |
Enumerations | |
enum | ast_http_method { AST_HTTP_GET = 0, AST_HTTP_POST } |
HTTP Callbacks take the socket. More... | |
Functions | |
struct ast_str * | ast_http_error (int status, const char *title, const char *extra_header, const char *text) |
Return an ast_str malloc()'d string containing an HTTP error message. | |
void | ast_http_prefix (char *buf, int len) |
Return the current prefix. | |
int | ast_http_uri_link (struct ast_http_uri *urihandler) |
Register a URI handler. | |
void | ast_http_uri_unlink (struct ast_http_uri *urihandler) |
Unregister a URI handler. | |
void | ast_http_uri_unlink_all_with_key (const char *key) |
Unregister all handlers with matching key. |
Support for Private Asterisk HTTP Servers.
Definition in file http.h.
typedef struct ast_str*(* 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 *params, struct ast_variable *headers, int *status, char **title, int *contentlength) |
enum ast_http_method |
HTTP Callbacks take the socket.
The return value may include additional headers at the front and MUST include a blank line with \r\n to provide separation between user headers and content (even if no content is specified)
Definition at line 69 of file http.h.
{ AST_HTTP_GET = 0, AST_HTTP_POST, };
struct ast_str* ast_http_error | ( | int | status, |
const char * | title, | ||
const char * | extra_header, | ||
const char * | text | ||
) | [read] |
Return an ast_str malloc()'d string containing an HTTP error message.
Definition at line 322 of file http.c.
References ast_str_create(), and ast_str_set().
Referenced by generic_http_callback(), handle_uri(), http_post_callback(), httpd_helper_thread(), phoneprov_callback(), and static_callback().
{ struct ast_str *out = ast_str_create(512); if (out == NULL) { return out; } ast_str_set(&out, 0, "Content-type: text/html\r\n" "%s" "\r\n" "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" "<html><head>\r\n" "<title>%d %s</title>\r\n" "</head><body>\r\n" "<h1>%s</h1>\r\n" "<p>%s</p>\r\n" "<hr />\r\n" "<address>Asterisk Server</address>\r\n" "</body></html>\r\n", (extra_header ? extra_header : ""), status, title, title, text); return out; }
void ast_http_prefix | ( | char * | buf, |
int | len | ||
) |
Return the current prefix.
buf[out] | destination buffer for previous |
len[in] | length of prefix to copy |
Definition at line 160 of file http.c.
References ast_copy_string().
{ if (buf) { ast_copy_string(buf, prefix, len); } }
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 357 of file http.c.
References ast_log(), AST_RWLIST_EMPTY, AST_RWLIST_FIRST, AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_INSERT_TAIL, AST_RWLIST_NEXT, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_http_uri::description, http_uri_redirect::entry, len(), LOG_WARNING, ast_http_uri::supports_get, ast_http_uri::supports_post, and ast_http_uri::uri.
Referenced by __ast_http_post_load(), __init_manager(), ast_http_init(), and load_module().
{ struct ast_http_uri *uri; int len = strlen(urih->uri); if (!(urih->supports_get || urih->supports_post)) { ast_log(LOG_WARNING, "URI handler does not provide either GET or POST method: %s (%s)\n", urih->uri, urih->description); return -1; } AST_RWLIST_WRLOCK(&uris); if (AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len) { AST_RWLIST_INSERT_HEAD(&uris, urih, entry); AST_RWLIST_UNLOCK(&uris); return 0; } AST_RWLIST_TRAVERSE(&uris, uri, entry) { if (AST_RWLIST_NEXT(uri, entry) && strlen(AST_RWLIST_NEXT(uri, entry)->uri) <= len) { AST_RWLIST_INSERT_AFTER(&uris, uri, urih, entry); AST_RWLIST_UNLOCK(&uris); return 0; } } AST_RWLIST_INSERT_TAIL(&uris, urih, entry); AST_RWLIST_UNLOCK(&uris); return 0; }
void ast_http_uri_unlink | ( | struct ast_http_uri * | urihandler | ) |
Unregister a URI handler.
Definition at line 393 of file http.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and http_uri_redirect::entry.
Referenced by __init_manager(), and unload_module().
{ AST_RWLIST_WRLOCK(&uris); AST_RWLIST_REMOVE(&uris, urih, entry); AST_RWLIST_UNLOCK(&uris); }
void ast_http_uri_unlink_all_with_key | ( | const char * | key | ) |
Unregister all handlers with matching key.
Definition at line 400 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, http_uri_redirect::entry, ast_http_uri::key, and ast_http_uri::mallocd.
Referenced by __ast_http_post_load(), and unload_module().
{ struct ast_http_uri *urih; AST_RWLIST_WRLOCK(&uris); AST_RWLIST_TRAVERSE_SAFE_BEGIN(&uris, urih, entry) { if (!strcmp(urih->key, key)) { AST_RWLIST_REMOVE_CURRENT(entry); } if (urih->dmallocd) { ast_free(urih->data); } if (urih->mallocd) { ast_free(urih); } } AST_RWLIST_TRAVERSE_SAFE_END; AST_RWLIST_UNLOCK(&uris); }