This tutorial shows you step by step to develop a simple plugin (module) of lighttpd.
What do you need to develop a plug in?
- Add a plugin into lighttpd package!
- Handle a URI!
- send a simple message to client!
Now, Start!
A/ Add a plugin into lighttpd package!
The best start point is the inherited mod_skeleton.c which just contains a basic skeleton and a good simple guide. The mod_skeleton.c is placed in <lighttpd directory>/src/mod_skeleton.c.
Copy & replace "skeleton" by your plugin's name as below (use "Terminal").
assume your plugin's name is "xxx":
$cd <lighttpd directory>How to compile?
$cd src
$cp mod_skeleton.c mod_xxx.c
$vi mod_xxx.c
:%s/skeleton/xxx/g
Paste the following into <lighttpd directory>/src/Makefile.am:
Then reconfigure and compile lighttpd package for ARM CROSS COMPILE again!lib_LTLIBRARIES += mod_xxx.la mod_xxx_la_SOURCES = mod_xxx.c mod_xxx_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined mod_xxx_la_LIBADD = $(common_libadd)
After all, the lighttpd still unknown your plug in, you have to add your plugin into lighttpd's configuration file as below:
server.modules = (More information about lighttpd's configuration file, refer at http://redmine.lighttpd.net/projects/1/wiki/TutorialConfiguration
"...",
"mod_xxx",
"..."
)
Done!
B/ Handle a URI!
Now, take look at your plugin, mod_xxx.c, you should see:
mod_xxx_plugin_init(plugin *p):
Each plugin has to have a ..._plugin_init function which is called when the plugin is called. In this function, need to initial plugin structure P as below:
size_t version;In this tutorial, URI will be handled by function which assign to handle_uri_clean. In your plugin, you can use others.
buffer *name; /* name of the plugin */
void *(* init)();
handler_t (* set_defaults) (server *srv, void *p_d);
handler_t (* cleanup) (server *srv, void *p_d);
handler_t (* handle_trigger) (server *srv, void *p_d); /*is called once a second */
handler_t (* handle_sighup) (server *srv, void *p_d);/* is called at a signup */
handler_t (* handle_uri_raw) (server *srv, connection *con, void *p_d); /*is called after uri_raw is set */
handler_t (* handle_uri_clean) (server *srv, connection *con, void *p_d); /*is called after uri is set */
handler_t (* handle_docroot) (server *srv, connection *con, void *p_d); /*is called getting the document-root */
handler_t (* handle_physical) (server *srv, connection *con, void *p_d); /*is called mapping url to physical path */
handler_t (* handle_request_done) (server *srv, connection *con, void *p_d); /*is called at the end of a request */
handler_t (* handle_connection_close)(server *srv, connection *con, void *p_d); /*is called at the end of a connection */
handler_t (* handle_joblist) (server *srv, connection *con, void *p_d); /*is called after all events are handled */
handler_t (* handle_subrequest_start)(server *srv, connection *con, void *p_d); /*is called when a handler for the request has to be found*/
handler_t (* handle_subrequest) (server *srv, connection *con, void *p_d);
handler_t (* connection_reset) (server *srv, connection *con, void *p_d);
void *data;
void *lib;
Other information about URI, query,.... refer in connection structure.
C/ Send a response message!
The example below show you a simple way to send response message to client:
Below is lighttpd package & mod_xxx.c:URIHANDLER_FUNC(mod_xxx_uri_handler) {
plugin_data *p = p_d;
buffer *b;
UNUSED(srv);
if (con->mode != DIRECT) return HANDLER_GO_ON;
if (con->uri.path->used == 0) return HANDLER_GO_ON;
mod_xxx_patch_connection(srv, con, p);
//Prepare response message
b = chunkqueue_get_append_buffer(con->write_queue);
buffer_copy_string_len(b, CONST_STR_LEN("This is query of request:"));
buffer_append_string(b,con->uri.query->ptr);
//Send header
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"),
CONST_STR_LEN("text/plain"));
con->file_finished = 1;
return HANDLER_FINISHED;
}
https://drive.google.com/file/d/0BzxfaBPoywomSWx4dFFZdzJ5TmM/edit?usp=sharing
Slots, Live Casino, and Table Games at Wynn Las
ReplyDeleteWynn Las Vegas and Encore 남양주 출장샵 are two extraordinary 의정부 출장마사지 gaming 구리 출장마사지 destinations in Las Vegas, created to 울산광역 출장안마 cater 문경 출장안마 all type of players. At Wynn Las Vegas, you