Thu Jul 9 13:41:20 2009

Asterisk developer's documentation


http.h File Reference

Support for Private Asterisk HTTP Servers. More...

#include "asterisk/config.h"
#include "asterisk/tcptls.h"
#include "asterisk/linkedlists.h"

Go to the source code of this file.

Data Structures

struct  ast_http_uri
 Definition of a URI reachable in the embedded HTTP server. More...

Typedefs

typedef ast_str *(*) ast_http_callback (struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
 HTTP Callbacks take the socket.

Functions

ast_strast_http_error (int status, const char *title, const char *extra_header, const char *text)
 Return an ast_str malloc()'d string containing an HTTP error message.
int ast_http_init (void)
int ast_http_reload (void)
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>
Note:
In order to have TLS/SSL support, we need the openssl libraries. Still we can decide whether or not to use them by commenting in or out the DO_SSL macro. TLS/SSL support is basically implemented by reading from a config file (currently http.conf) the names of the certificate and cipher to use, and then run ssl_setup() to create an appropriate SSL_CTX (ssl_ctx) If we support multiple domains, presumably we need to read multiple certificates. When we are requested to open a TLS socket, we run make_file_from_fd() on the socket, to do the necessary setup. At the moment the context's name is hardwired in the function, but we can certainly make it into an extra parameter to the function. We declare most of ssl support variables unconditionally, because their number is small and this simplifies the code.

: the ssl-support variables (ssl_ctx, do_ssl, certfile, cipher) and their setup should be moved to a more central place, e.g. asterisk.conf and the source files that processes it. Similarly, ssl_setup() should be run earlier in the startup process so modules have it available.

Definition in file http.h.


Typedef Documentation

typedef struct ast_str*(*) ast_http_callback(struct ast_tcptls_session_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)

HTTP Callbacks take the socket.

Note:
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 \r\n to provide separation between user headers and content (even if no
   content is specified) 

Definition at line 68 of file http.h.


Function Documentation

struct ast_str* ast_http_error ( int  status,
const char *  title,
const char *  extra_header,
const char *  text 
)

Return an ast_str malloc()'d string containing an HTTP error message.

Definition at line 288 of file http.c.

References ast_str_create(), and ast_str_set().

Referenced by handle_uri(), httpd_helper_thread(), phoneprov_callback(), and static_callback().

00289 {
00290    struct ast_str *out = ast_str_create(512);
00291    if (out == NULL)
00292       return out;
00293    ast_str_set(&out, 0,
00294       "Content-type: text/html\r\n"
00295       "%s"
00296       "\r\n"
00297       "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
00298       "<html><head>\r\n"
00299       "<title>%d %s</title>\r\n"
00300       "</head><body>\r\n"
00301       "<h1>%s</h1>\r\n"
00302       "<p>%s</p>\r\n"
00303       "<hr />\r\n"
00304       "<address>Asterisk Server</address>\r\n"
00305       "</body></html>\r\n",
00306          (extra_header ? extra_header : ""), status, title, title, text);
00307    return out;
00308 }

int ast_http_init ( void   ) 

Definition at line 1188 of file http.c.

References __ast_http_load(), ast_cli_register_multiple(), ast_http_uri_link(), cli_http, staticuri, and statusuri.

Referenced by main().

01189 {
01190 #ifdef ENABLE_UPLOADS
01191    g_mime_init(0);
01192 #endif /* ENABLE_UPLOADS */
01193 
01194    ast_http_uri_link(&statusuri);
01195    ast_http_uri_link(&staticuri);
01196    ast_cli_register_multiple(cli_http, sizeof(cli_http) / sizeof(struct ast_cli_entry));
01197 
01198    return __ast_http_load(0);
01199 }

int ast_http_reload ( void   ) 

Definition at line 1179 of file http.c.

References __ast_http_load().

01180 {
01181    return __ast_http_load(1);
01182 }

int ast_http_uri_link ( struct ast_http_uri urih  ) 

Link into the Asterisk HTTP server.

They are sorted by length of the string, not alphabetically. Duplicate entries are not replaced, but the insertion order (using <= and not just <) makes sure that more recent insertions hide older ones. On a lookup, we just scan the list and stop at the first matching entry.

Definition at line 319 of file http.c.

References AST_RWLIST_EMPTY, AST_RWLIST_FIRST, AST_RWLIST_INSERT_AFTER, AST_RWLIST_INSERT_HEAD, AST_RWLIST_INSERT_TAIL, AST_RWLIST_NEXT, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_http_uri::entry, len(), and ast_http_uri::uri.

Referenced by ast_http_init(), and load_module().

00320 {
00321    struct ast_http_uri *uri;
00322    int len = strlen(urih->uri);
00323 
00324    AST_RWLIST_WRLOCK(&uris);
00325 
00326    if ( AST_RWLIST_EMPTY(&uris) || strlen(AST_RWLIST_FIRST(&uris)->uri) <= len ) {
00327       AST_RWLIST_INSERT_HEAD(&uris, urih, entry);
00328       AST_RWLIST_UNLOCK(&uris);
00329       return 0;
00330    }
00331 
00332    AST_RWLIST_TRAVERSE(&uris, uri, entry) {
00333       if ( AST_RWLIST_NEXT(uri, entry) 
00334          && strlen(AST_RWLIST_NEXT(uri, entry)->uri) <= len ) {
00335          AST_RWLIST_INSERT_AFTER(&uris, uri, urih, entry);
00336          AST_RWLIST_UNLOCK(&uris); 
00337          return 0;
00338       }
00339    }
00340 
00341    AST_RWLIST_INSERT_TAIL(&uris, urih, entry);
00342 
00343    AST_RWLIST_UNLOCK(&uris);
00344    
00345    return 0;
00346 }  

void ast_http_uri_unlink ( struct ast_http_uri urihandler  ) 

Destroy an HTTP server.

Definition at line 348 of file http.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_http_uri::entry.

Referenced by unload_module().

00349 {
00350    AST_RWLIST_WRLOCK(&uris);
00351    AST_RWLIST_REMOVE(&uris, urih, entry);
00352    AST_RWLIST_UNLOCK(&uris);
00353 }


Generated on Thu Jul 9 13:41:21 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7