#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 231 of file http.c.
References asprintf.
00232 { 00233 char *c = NULL; 00234 asprintf(&c, 00235 "Content-type: text/html\r\n" 00236 "%s" 00237 "\r\n" 00238 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n" 00239 "<html><head>\r\n" 00240 "<title>%d %s</title>\r\n" 00241 "</head><body>\r\n" 00242 "<h1>%s</h1>\r\n" 00243 "<p>%s</p>\r\n" 00244 "<hr />\r\n" 00245 "<address>Asterisk Server</address>\r\n" 00246 "</body></html>\r\n", 00247 (extra_header ? extra_header : ""), status, title, title, text); 00248 return c; 00249 }
int ast_http_init | ( | void | ) |
Definition at line 742 of file http.c.
References __ast_http_load(), ast_cli_register_multiple(), and ast_http_uri_link().
00743 { 00744 ast_http_uri_link(&statusuri); 00745 ast_http_uri_link(&staticuri); 00746 ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry)); 00747 00748 return __ast_http_load(0); 00749 }
int ast_http_reload | ( | void | ) |
Definition at line 727 of file http.c.
References __ast_http_load().
00728 { 00729 return __ast_http_load(1); 00730 }
char* ast_http_setcookie | ( | const char * | var, | |
const char * | val, | |||
int | expires, | |||
char * | buf, | |||
size_t | buflen | |||
) |
Definition at line 567 of file http.c.
References ast_build_string().
00568 { 00569 char *c; 00570 c = buf; 00571 ast_build_string(&c, &buflen, "Set-Cookie: %s=\"%s\"; Version=\"1\"", var, val); 00572 if (expires) 00573 ast_build_string(&c, &buflen, "; Max-Age=%d", expires); 00574 ast_build_string(&c, &buflen, "\r\n"); 00575 return buf; 00576 }
int ast_http_uri_link | ( | struct ast_http_uri * | urihandler | ) |
Link into the Asterisk HTTP server.
Definition at line 251 of file http.c.
References ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_http_uri::next, and ast_http_uri::uri.
00252 { 00253 struct ast_http_uri *prev; 00254 00255 ast_rwlock_wrlock(&uris_lock); 00256 prev = uris; 00257 if (!uris || strlen(uris->uri) <= strlen(urih->uri)) { 00258 urih->next = uris; 00259 uris = urih; 00260 } else { 00261 while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri))) 00262 prev = prev->next; 00263 /* Insert it here */ 00264 urih->next = prev->next; 00265 prev->next = urih; 00266 } 00267 ast_rwlock_unlock(&uris_lock); 00268 00269 return 0; 00270 }
void ast_http_uri_unlink | ( | struct ast_http_uri * | urihandler | ) |
Destroy an HTTP server.
Definition at line 272 of file http.c.
References ast_rwlock_unlock(), ast_rwlock_wrlock(), and ast_http_uri::next.
00273 { 00274 struct ast_http_uri *prev; 00275 00276 ast_rwlock_wrlock(&uris_lock); 00277 if (!uris) { 00278 ast_rwlock_unlock(&uris_lock); 00279 return; 00280 } 00281 prev = uris; 00282 if (uris == urih) { 00283 uris = uris->next; 00284 } 00285 while(prev->next) { 00286 if (prev->next == urih) { 00287 prev->next = urih->next; 00288 break; 00289 } 00290 prev = prev->next; 00291 } 00292 ast_rwlock_unlock(&uris_lock); 00293 }