Fri Aug 24 02:25:42 2007

Asterisk developer's documentation


http.h File Reference

Support for Private Asterisk HTTP Servers. More...

#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.


Detailed Description

Support for Private Asterisk HTTP Servers.

Note:
Note: The Asterisk HTTP servers are extremely simple and minimal and only support the "GET" method.
Author:
Mark Spencer <markster@digium.com>

Definition in file http.h.


Typedef Documentation

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).

Definition at line 39 of file http.h.


Function Documentation

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.

Referenced by ast_httpd_helper_thread(), handle_uri(), and static_callback().

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(), ast_http_uri_link(), cli_http, staticuri, and statusuri.

Referenced by main().

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, ast_http_uri::uri, and uris.

Referenced by ast_http_init(), and init_manager().

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(), ast_http_uri::next, and uris.

Referenced by init_manager().

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 }


Generated on Fri Aug 24 02:25:42 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1