Sun Dec 18 20:55:51 2011

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 234 of file http.c.

References asprintf.

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

00235 {
00236    char *c = NULL;
00237    asprintf(&c,
00238       "Content-type: text/html\r\n"
00239       "%s"
00240       "\r\n"
00241       "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
00242       "<html><head>\r\n"
00243       "<title>%d %s</title>\r\n"
00244       "</head><body>\r\n"
00245       "<h1>%s</h1>\r\n"
00246       "<p>%s</p>\r\n"
00247       "<hr />\r\n"
00248       "<address>Asterisk Server</address>\r\n"
00249       "</body></html>\r\n",
00250          (extra_header ? extra_header : ""), status, title, title, text);
00251    return c;
00252 }

int ast_http_init ( void   ) 

Definition at line 761 of file http.c.

References __ast_http_load(), ast_cli_register_multiple(), and ast_http_uri_link().

Referenced by main().

00762 {
00763    ast_http_uri_link(&statusuri);
00764    ast_http_uri_link(&staticuri);
00765    ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry));
00766 
00767    return __ast_http_load(0);
00768 }

int ast_http_reload ( void   ) 

Definition at line 746 of file http.c.

References __ast_http_load().

00747 {
00748    return __ast_http_load(1);
00749 }

char* ast_http_setcookie ( const char *  var,
const char *  val,
int  expires,
char *  buf,
size_t  buflen 
)

Definition at line 577 of file http.c.

References ast_build_string().

Referenced by generic_http_callback().

00578 {
00579    char *c;
00580    c = buf;
00581    ast_build_string(&c, &buflen, "Set-Cookie: %s=\"%s\"; Version=\"1\"", var, val);
00582    if (expires)
00583       ast_build_string(&c, &buflen, "; Max-Age=%d", expires);
00584    ast_build_string(&c, &buflen, "\r\n");
00585    return buf;
00586 }

int ast_http_uri_link ( struct ast_http_uri urihandler  ) 

Link into the Asterisk HTTP server.

Definition at line 254 of file http.c.

References ast_rwlock_unlock(), ast_rwlock_wrlock(), ast_http_uri::next, and ast_http_uri::uri.

Referenced by ast_http_init(), and init_manager().

00255 {
00256    struct ast_http_uri *prev;
00257 
00258    ast_rwlock_wrlock(&uris_lock);
00259    prev = uris;
00260    if (!uris || strlen(uris->uri) <= strlen(urih->uri)) {
00261       urih->next = uris;
00262       uris = urih;
00263    } else {
00264       while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri)))
00265          prev = prev->next;
00266       /* Insert it here */
00267       urih->next = prev->next;
00268       prev->next = urih;
00269    }
00270    ast_rwlock_unlock(&uris_lock);
00271 
00272    return 0;
00273 }  

void ast_http_uri_unlink ( struct ast_http_uri urihandler  ) 

Destroy an HTTP server.

Definition at line 275 of file http.c.

References ast_rwlock_unlock(), ast_rwlock_wrlock(), and ast_http_uri::next.

Referenced by init_manager().

00276 {
00277    struct ast_http_uri *prev;
00278 
00279    ast_rwlock_wrlock(&uris_lock);
00280    if (!uris) {
00281       ast_rwlock_unlock(&uris_lock);
00282       return;
00283    }
00284    prev = uris;
00285    if (uris == urih) {
00286       uris = uris->next;
00287    }
00288    while(prev->next) {
00289       if (prev->next == urih) {
00290          prev->next = urih->next;
00291          break;
00292       }
00293       prev = prev->next;
00294    }
00295    ast_rwlock_unlock(&uris_lock);
00296 }


Generated on Sun Dec 18 20:55:51 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.6