|
NAMEhttp_servlet_tmpl —
HTTP servlet for template files
LIBRARYPDEL Library (libpdel, -lpdel)SYNOPSIS#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <openssl/ssl.h>
#include <pdel/tmpl/tmpl.h>
#include <pdel/http/http_defs.h>
#include
<pdel/http/http_server.h>
#include
<pdel/http/servlet/tmpl.h>
struct http_servlet *
extern tmpl_handler_t
http_servlet_tmpl_func_query;
DESCRIPTIONhttp_servlet_tmpl_create () creates a new servlet that
serves HTTP requests by executing a
tmpl(3)
template file. The output of the template is sent as the body of the HTTP
response. By default, the template output is buffered in memory and after
template execution has finished the HTTP response is sent.
info is a pointer to a
/* Function to free user 'arg' */ typedef void http_servlet_tmpl_free_t(void *arg); /* Information required by tmpl(3) library */ struct http_servlet_tmpl_tinfo { int flags; /* tmpl_execute() flags */ const char *mtype; /* tmpl string mem type */ tmpl_handler_t *handler; /* tmpl function handler */ tmpl_errfmtr_t *errfmtr; /* tmpl error formatter */ void *arg; /* opaque argument */ http_servlet_tmpl_free_t *freer; /* destructor for 'arg' */ }; /* Information required for the tmpl servlet */ struct http_servlet_tmpl_info { const char *path; /* template file */ const char *mime_type; /* default mime type */ const char *mime_encoding; /* default mime encoding */ http_logger_t *logger; /* http error logger */ struct http_servlet_tmpl_tinfo tinfo; /* info for tmpl(3) */ }; path is the pathname of the template file. The file is parsed when the servlet is first executed, and the parsed template is cached for use by subsequent servlet invocations. If the file modification timestamp changes, the file is parsed again. mime_type and
mime_encoding specify the default MIME type and
encoding for the template output. The template itself may change the MIME
type however. If mime_type is
The logger is a logging function whose type is defined in http_server(3). The tinfo structure provides information
required by the
tmpl(3)
library in order to create and execute the template. The
mtype, handler, and
errfmtr fields are passed to
The arg field is copied into a
struct http_servlet_tmpl_arg { void *arg; /* arg from 'tinfo' */ struct http_request *req; /* http request */ struct http_response *resp; /* http response */ }; Therefore, by casting the pointer returned from
For an HTTP POST with MIME type
“application/x-www-form-urlencoded” the servlet will
automatically read in the URL-encoded name, value pairs, making them
accessible via
http_request_get_value(3)
(see also When the servlet is destroyed, if the freer
field is not Built-in template functionsThehttp_servlet_tmpl servlet includes the following
built-in
tmpl(3)
user functions. These functions all assume the
tmpl(3)
user cookie is a struct http_servlet_tmpl_arg * .
The IMPLEMENTATION NOTESMultiple instances of the samehttp_servlet_tmpl servlet
may be executing at the same time. Therefore, any user-supplied template
functions called must be thread-safe.
Since it's running as a servlet, the thread executing
RETURN VALUESOn failure,http_servlet_tmpl_create () returns
NULL and sets errno to an
appropriate value.
The built-in
tmpl(3)
user functions return SEE ALSOhttp_request(3), http_response(3), http_server(3), http_servlet(3), libpdel(3), tmpl(3)HISTORYThe PDEL library was developed at Packet Design, LLC.http://www.packetdesign.com/
AUTHORSArchie Cobbs ⟨archie@freebsd.org⟩
Visit the GSP FreeBSD Man Page Interface. |