#include "asterisk/config.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_uri |
Typedefs | |
| typedef char *(*) | ast_http_callback (struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength) |
| HTTP Callbacks take the socket, the method and the path as arguments and should return the content, allocated with malloc(). Status should be changed to reflect the status of the request if it isn't 200 and title may be set to a malloc()'d string to an appropriate title for non-200 responses. Content length may also be specified. The return value may include additional headers at the front and MUST include a blank line with to provide separation between user headers and content (even if no content is specified). | |
Functions | |
| char * | ast_http_error (int status, const char *title, const char *extra_header, const char *text) |
| Return a malloc()'d string containing an HTTP error message. | |
| int | ast_http_init (void) |
| int | ast_http_reload (void) |
| char * | ast_http_setcookie (const char *var, const char *val, int expires, char *buf, size_t buflen) |
| int | ast_http_uri_link (struct ast_http_uri *urihandler) |
| Link into the Asterisk HTTP server. | |
| void | ast_http_uri_unlink (struct ast_http_uri *urihandler) |
| Destroy an HTTP server. | |
Definition in file http.h.
| typedef char*(*) ast_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength) |
HTTP Callbacks take the socket, the method and the path as arguments and should return the content, allocated with malloc(). Status should be changed to reflect the status of the request if it isn't 200 and title may be set to a malloc()'d string to an appropriate title for non-200 responses. Content length may also be specified. The return value may include additional headers at the front and MUST include a blank line with
to provide separation between user headers and content (even if no content is specified).
| char* ast_http_error | ( | int | status, | |
| const char * | title, | |||
| const char * | extra_header, | |||
| const char * | text | |||
| ) |
Return a malloc()'d string containing an HTTP error message.
Definition at line 230 of file http.c.
References asprintf.
Referenced by ast_httpd_helper_thread(), handle_uri(), and static_callback().
00231 { 00232 char *c = NULL; 00233 asprintf(&c, 00234 "Content-type: text/html\r\n" 00235 "%s" 00236 "\r\n" 00237 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 00238 "<html><head>\r\n" 00239 "<title>%d %s</title>\r\n" 00240 "</head><body>\r\n" 00241 "<h1>%s</h1>\r\n" 00242 "<p>%s</p>\r\n" 00243 "<hr />\r\n" 00244 "<address>Asterisk Server</address>\r\n" 00245 "</body></html>\r\n", 00246 (extra_header ? extra_header : ""), status, title, title, text); 00247 return c; 00248 }
| int ast_http_init | ( | void | ) |
Definition at line 734 of file http.c.
References __ast_http_load(), ast_cli_register_multiple(), ast_http_uri_link(), cli_http, staticuri, and statusuri.
Referenced by main().
00735 { 00736 ast_http_uri_link(&statusuri); 00737 ast_http_uri_link(&staticuri); 00738 ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry)); 00739 00740 return __ast_http_load(0); 00741 }
| int ast_http_reload | ( | void | ) |
Definition at line 719 of file http.c.
References __ast_http_load().
00720 { 00721 return __ast_http_load(1); 00722 }
| char* ast_http_setcookie | ( | const char * | var, | |
| const char * | val, | |||
| int | expires, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) |
Definition at line 559 of file http.c.
References ast_build_string().
00560 { 00561 char *c; 00562 c = buf; 00563 ast_build_string(&c, &buflen, "Set-Cookie: %s=\"%s\"; Version=\"1\"", var, val); 00564 if (expires) 00565 ast_build_string(&c, &buflen, "; Max-Age=%d", expires); 00566 ast_build_string(&c, &buflen, "\r\n"); 00567 return buf; 00568 }
| int ast_http_uri_link | ( | struct ast_http_uri * | urihandler | ) |
Link into the Asterisk HTTP server.
Definition at line 250 of file http.c.
References ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_http_uri::next, ast_http_uri::uri, and uris.
Referenced by ast_http_init(), and init_manager().
00251 { 00252 struct ast_http_uri *prev; 00253 00254 ast_rwlock_wrlock(&uris_lock); 00255 prev = uris; 00256 if (!uris || strlen(uris->uri) <= strlen(urih->uri)) { 00257 urih->next = uris; 00258 uris = urih; 00259 } else { 00260 while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri))) 00261 prev = prev->next; 00262 /* Insert it here */ 00263 urih->next = prev->next; 00264 prev->next = urih; 00265 } 00266 ast_rwlock_unlock(&uris_lock); 00267 00268 return 0; 00269 }
| void ast_http_uri_unlink | ( | struct ast_http_uri * | urihandler | ) |
Destroy an HTTP server.
Definition at line 271 of file http.c.
References ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_http_uri::next, and uris.
Referenced by init_manager().
00272 { 00273 struct ast_http_uri *prev; 00274 00275 ast_rwlock_wrlock(&uris_lock); 00276 if (!uris) { 00277 ast_rwlock_unlock(&uris_lock); 00278 return; 00279 } 00280 prev = uris; 00281 if (uris == urih) { 00282 uris = uris->next; 00283 } 00284 while(prev->next) { 00285 if (prev->next == urih) { 00286 prev->next = urih->next; 00287 break; 00288 } 00289 prev = prev->next; 00290 } 00291 ast_rwlock_unlock(&uris_lock); 00292 }
1.5.1