#include "asterisk/config.h"
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 235 of file http.c.
References asprintf, ast_log(), errno, and LOG_WARNING.
Referenced by ast_httpd_helper_thread(), handle_uri(), and static_callback().
00236 { 00237 char *c = NULL; 00238 if (asprintf(&c, 00239 "Content-type: text/html\r\n" 00240 "%s" 00241 "\r\n" 00242 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 00243 "<html><head>\r\n" 00244 "<title>%d %s</title>\r\n" 00245 "</head><body>\r\n" 00246 "<h1>%s</h1>\r\n" 00247 "<p>%s</p>\r\n" 00248 "<hr />\r\n" 00249 "<address>Asterisk Server</address>\r\n" 00250 "</body></html>\r\n", 00251 (extra_header ? extra_header : ""), status, title, title, text) < 0) { 00252 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 00253 c = NULL; 00254 } 00255 return c; 00256 }
int ast_http_init | ( | void | ) |
Definition at line 769 of file http.c.
References __ast_http_load(), ast_cli_register_multiple(), ast_http_uri_link(), cli_http, staticuri, and statusuri.
Referenced by main().
00770 { 00771 ast_http_uri_link(&statusuri); 00772 ast_http_uri_link(&staticuri); 00773 ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry)); 00774 00775 return __ast_http_load(0); 00776 }
int ast_http_reload | ( | void | ) |
Definition at line 754 of file http.c.
References __ast_http_load().
00755 { 00756 return __ast_http_load(1); 00757 }
char* ast_http_setcookie | ( | const char * | var, | |
const char * | val, | |||
int | expires, | |||
char * | buf, | |||
size_t | buflen | |||
) |
Definition at line 585 of file http.c.
References ast_build_string().
00586 { 00587 char *c; 00588 c = buf; 00589 ast_build_string(&c, &buflen, "Set-Cookie: %s=\"%s\"; Version=1", var, val); 00590 if (expires) 00591 ast_build_string(&c, &buflen, "; Max-Age=%d", expires); 00592 ast_build_string(&c, &buflen, "\r\n"); 00593 return buf; 00594 }
int ast_http_uri_link | ( | struct ast_http_uri * | urihandler | ) |
Link into the Asterisk HTTP server.
Definition at line 258 of file http.c.
References ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_http_uri::next, ast_http_uri::uri, uris, and uris_lock.
Referenced by ast_http_init().
00259 { 00260 struct ast_http_uri *prev; 00261 00262 ast_rwlock_wrlock(&uris_lock); 00263 prev = uris; 00264 if (!uris || strlen(uris->uri) <= strlen(urih->uri)) { 00265 urih->next = uris; 00266 uris = urih; 00267 } else { 00268 while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri))) 00269 prev = prev->next; 00270 /* Insert it here */ 00271 urih->next = prev->next; 00272 prev->next = urih; 00273 } 00274 ast_rwlock_unlock(&uris_lock); 00275 00276 return 0; 00277 }
void ast_http_uri_unlink | ( | struct ast_http_uri * | urihandler | ) |
Destroy an HTTP server.
Definition at line 279 of file http.c.
References ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_http_uri::next, uris, and uris_lock.
00280 { 00281 struct ast_http_uri *prev; 00282 00283 ast_rwlock_wrlock(&uris_lock); 00284 if (!uris) { 00285 ast_rwlock_unlock(&uris_lock); 00286 return; 00287 } 00288 prev = uris; 00289 if (uris == urih) { 00290 uris = uris->next; 00291 } 00292 while(prev->next) { 00293 if (prev->next == urih) { 00294 prev->next = urih->next; 00295 break; 00296 } 00297 prev = prev->next; 00298 } 00299 ast_rwlock_unlock(&uris_lock); 00300 }