1*76404edcSAsim Jamshed================ 2*76404edcSAsim JamshedPlugin Interface 3*76404edcSAsim Jamshed================ 4*76404edcSAsim Jamshed 5*76404edcSAsim Jamshed------------ 6*76404edcSAsim JamshedModule: core 7*76404edcSAsim Jamshed------------ 8*76404edcSAsim Jamshed 9*76404edcSAsim Jamshed:Author: Jan Kneschke 10*76404edcSAsim Jamshed:Date: $Date: 2004/08/01 07:01:29 $ 11*76404edcSAsim Jamshed:Revision: $Revision: 1.1 $ 12*76404edcSAsim Jamshed 13*76404edcSAsim Jamshed:abstract: 14*76404edcSAsim Jamshed The plugin interface is an integral part of lighttpd which 15*76404edcSAsim Jamshed provides a flexible way to add specific functionality to lighttpd. 16*76404edcSAsim Jamshed 17*76404edcSAsim Jamshed.. meta:: 18*76404edcSAsim Jamshed :keywords: lighttpd, plugins 19*76404edcSAsim Jamshed 20*76404edcSAsim Jamshed.. contents:: Table of Contents 21*76404edcSAsim Jamshed 22*76404edcSAsim JamshedDescription 23*76404edcSAsim Jamshed=========== 24*76404edcSAsim Jamshed 25*76404edcSAsim JamshedPlugins allow you to enhance the functionality of lighttpd without 26*76404edcSAsim Jamshedchanging the core of the webserver. They can be loaded at startup time 27*76404edcSAsim Jamshedand can change virtually any aspect of the behaviour of the webserver. 28*76404edcSAsim Jamshed 29*76404edcSAsim JamshedPlugin Entry Points 30*76404edcSAsim Jamshed------------------- 31*76404edcSAsim Jamshed 32*76404edcSAsim Jamshedlighttpd has 16 hooks which are used in different states of the 33*76404edcSAsim Jamshedexecution of the request: 34*76404edcSAsim Jamshed 35*76404edcSAsim JamshedServerwide hooks 36*76404edcSAsim Jamshed```````````````` 37*76404edcSAsim Jamshed 38*76404edcSAsim Jamshed:init_: 39*76404edcSAsim Jamshed called when the plugin is loaded 40*76404edcSAsim Jamshed:cleanup_: 41*76404edcSAsim Jamshed called when the plugin is unloaded 42*76404edcSAsim Jamshed:set_defaults_: 43*76404edcSAsim Jamshed called when the configuration has to be processed 44*76404edcSAsim Jamshed:handle_trigger_: 45*76404edcSAsim Jamshed called once a second 46*76404edcSAsim Jamshed:handle_sighup_: 47*76404edcSAsim Jamshed called when the server received a SIGHUP 48*76404edcSAsim Jamshed 49*76404edcSAsim JamshedConnectionwide hooks 50*76404edcSAsim Jamshed```````````````````` 51*76404edcSAsim Jamshed 52*76404edcSAsim JamshedMost of these hooks are called in ``http_response_prepare()`` after some 53*76404edcSAsim Jamshedfields in the connection structure are set. 54*76404edcSAsim Jamshed 55*76404edcSAsim Jamshed:handle_uri_raw_: 56*76404edcSAsim Jamshed called after uri.path_raw, uri.authority and uri.scheme are set 57*76404edcSAsim Jamshed:handle_uri_clean_: 58*76404edcSAsim Jamshed called after uri.path (a clean URI without .. and %20) is set 59*76404edcSAsim Jamshed:handle_docroot_: 60*76404edcSAsim Jamshed called at the end of the logical path handle to get a docroot 61*76404edcSAsim Jamshed:handle_subrequest_start_: 62*76404edcSAsim Jamshed called if the physical path is set up and checked 63*76404edcSAsim Jamshed:handle_subrequest_: 64*76404edcSAsim Jamshed called at the end of ``http_response_prepare()`` 65*76404edcSAsim Jamshed:handle_physical_path_: 66*76404edcSAsim Jamshed called after the physical path is created and no other handler is 67*76404edcSAsim Jamshed found for this request 68*76404edcSAsim Jamshed:handle_request_done_: 69*76404edcSAsim Jamshed called when the request is done 70*76404edcSAsim Jamshed:handle_connection_close_: 71*76404edcSAsim Jamshed called if the connection has to be closed 72*76404edcSAsim Jamshed:handle_joblist_: 73*76404edcSAsim Jamshed called after the connection_state_engine is left again and plugin 74*76404edcSAsim Jamshed internal handles have to be called 75*76404edcSAsim Jamshed:connection_reset_: 76*76404edcSAsim Jamshed called if the connection structure has to be cleaned up 77*76404edcSAsim Jamshed 78*76404edcSAsim Jamshed 79*76404edcSAsim JamshedPlugin Interface 80*76404edcSAsim Jamshed---------------- 81*76404edcSAsim Jamshed 82*76404edcSAsim Jamshed\*_plugin_init 83*76404edcSAsim Jamshed`````````````` 84*76404edcSAsim Jamshed 85*76404edcSAsim JamshedEvery plugin has a uniquely-named function which is called after the 86*76404edcSAsim Jamshedplugin is loaded. It is used to set up the ``plugin`` structure with 87*76404edcSAsim Jamshedsome useful data: 88*76404edcSAsim Jamshed 89*76404edcSAsim Jamshed- name of the plugin ``name`` 90*76404edcSAsim Jamshed- all hooks 91*76404edcSAsim Jamshed 92*76404edcSAsim JamshedThe field ``data`` and ``lib`` should not be touched in the init function. 93*76404edcSAsim Jamshed``lib`` is the library handler from dlopen and ``data`` will be the storage 94*76404edcSAsim Jamshedof the internal plugin data. 95*76404edcSAsim Jamshed 96*76404edcSAsim Jamshed:returns: 97*76404edcSAsim Jamshed 0 (not handled) 98*76404edcSAsim Jamshed 99*76404edcSAsim Jamshedinit 100*76404edcSAsim Jamshed```` 101*76404edcSAsim Jamshed 102*76404edcSAsim JamshedThe first real call of a plugin function is the init hook which is used 103*76404edcSAsim Jamshedto set up the internal plugin data. The internal plugin is assigned the 104*76404edcSAsim Jamshed``data`` field mentioned in the \*_plugin_init description. 105*76404edcSAsim Jamshed 106*76404edcSAsim Jamshed:returns: 107*76404edcSAsim Jamshed a pointer to the internal plugin data. 108*76404edcSAsim Jamshed 109*76404edcSAsim Jamshedcleanup 110*76404edcSAsim Jamshed``````` 111*76404edcSAsim Jamshed 112*76404edcSAsim JamshedThe cleanup hook is called just before the plugin is unloaded. It is meant 113*76404edcSAsim Jamshedto free all buffers allocated in ``init`` or somewhere else in the plugin 114*76404edcSAsim Jamshedwhich are still not freed and to close all handles which were opened and 115*76404edcSAsim Jamshedare not closed yet. 116*76404edcSAsim Jamshed 117*76404edcSAsim Jamshed:returns: 118*76404edcSAsim Jamshed HANDLER_GO_ON if ok (not handled) 119*76404edcSAsim Jamshed 120*76404edcSAsim Jamshedset_defaults 121*76404edcSAsim Jamshed```````````` 122*76404edcSAsim Jamshed 123*76404edcSAsim Jamshedset_defaults is your entry point into the configfile parsing. It should 124*76404edcSAsim Jamshedpass a list of options to ``config_insert_values`` and check if 125*76404edcSAsim Jamshedthe plugin configuration is valid. If it is not valid yet, it should 126*76404edcSAsim Jamshedset useful defaults or return with HANDLER_ERROR and an error message. 127*76404edcSAsim Jamshed 128*76404edcSAsim Jamshed:returns: 129*76404edcSAsim Jamshed HANDLER_GO_ON if ok 130*76404edcSAsim Jamshed 131*76404edcSAsim Jamshed HANDLER_ERROR will terminate lighttpd 132*76404edcSAsim Jamshed 133*76404edcSAsim Jamshedconnection_reset 134*76404edcSAsim Jamshed```````````````` 135*76404edcSAsim Jamshed 136*76404edcSAsim Jamshedcalled at the end of each request 137*76404edcSAsim Jamshed 138*76404edcSAsim Jamshed:returns: 139*76404edcSAsim Jamshed HANDLER_GO_ON if ok 140*76404edcSAsim Jamshed 141*76404edcSAsim Jamshed HANDLER_ERROR on error 142*76404edcSAsim Jamshed 143*76404edcSAsim Jamshedhandle_trigger 144*76404edcSAsim Jamshed`````````````` 145*76404edcSAsim Jamshed 146*76404edcSAsim Jamshedcalled once a second 147*76404edcSAsim Jamshed 148*76404edcSAsim Jamshed:returns: 149*76404edcSAsim Jamshed HANDLER_GO_ON if ok 150*76404edcSAsim Jamshed 151*76404edcSAsim Jamshed HANDLER_ERROR on error 152*76404edcSAsim Jamshed 153*76404edcSAsim Jamshedhandle_sighup 154*76404edcSAsim Jamshed````````````` 155*76404edcSAsim Jamshed 156*76404edcSAsim Jamshedcalled if a SIGHUP is received (cycling logfiles, ...) 157*76404edcSAsim Jamshed 158*76404edcSAsim Jamshed:returns: 159*76404edcSAsim Jamshed HANDLER_GO_ON if ok 160*76404edcSAsim Jamshed 161*76404edcSAsim Jamshed HANDLER_ERROR on error 162*76404edcSAsim Jamshed 163*76404edcSAsim Jamshedhandle_uri_raw 164*76404edcSAsim Jamshed`````````````` 165*76404edcSAsim Jamshed 166*76404edcSAsim Jamshedcalled after uri_raw is set 167*76404edcSAsim Jamshed 168*76404edcSAsim Jamshed:returns: 169*76404edcSAsim Jamshed HANDLER_GO_ON if ok 170*76404edcSAsim Jamshed HANDLER_FINISHED if the final output is prepared 171*76404edcSAsim Jamshed 172*76404edcSAsim Jamshed HANDLER_ERROR on error 173*76404edcSAsim Jamshed 174*76404edcSAsim Jamshedhandle_uri_clean 175*76404edcSAsim Jamshed```````````````` 176*76404edcSAsim Jamshed 177*76404edcSAsim Jamshedcalled after uri.path is set 178*76404edcSAsim Jamshed 179*76404edcSAsim Jamshed:returns: 180*76404edcSAsim Jamshed HANDLER_GO_ON if ok 181*76404edcSAsim Jamshed HANDLER_FINISHED if the final output is prepared 182*76404edcSAsim Jamshed 183*76404edcSAsim Jamshed HANDLER_ERROR on error 184*76404edcSAsim Jamshed 185*76404edcSAsim Jamshedhandle_docroot 186*76404edcSAsim Jamshed`````````````` 187*76404edcSAsim Jamshed 188*76404edcSAsim Jamshedcalled when a docroot is needed 189*76404edcSAsim Jamshed 190*76404edcSAsim Jamshed:returns: 191*76404edcSAsim Jamshed HANDLER_GO_ON if ok 192*76404edcSAsim Jamshed HANDLER_FINISHED if the final output is prepared 193*76404edcSAsim Jamshed 194*76404edcSAsim Jamshed HANDLER_ERROR on error 195*76404edcSAsim Jamshed 196*76404edcSAsim Jamshedhandle_subrequest_start 197*76404edcSAsim Jamshed``````````````````````` 198*76404edcSAsim Jamshed 199*76404edcSAsim Jamshedcalled after physical.path is set 200*76404edcSAsim Jamshed 201*76404edcSAsim Jamshed:returns: 202*76404edcSAsim Jamshed HANDLER_GO_ON if ok 203*76404edcSAsim Jamshed HANDLER_FINISHED if the final output is prepared 204*76404edcSAsim Jamshed 205*76404edcSAsim Jamshed HANDLER_ERROR on error 206*76404edcSAsim Jamshed 207*76404edcSAsim Jamshedhandle_subrequest 208*76404edcSAsim Jamshed````````````````` 209*76404edcSAsim Jamshed 210*76404edcSAsim Jamshedcalled if subrequest_start requested a COMEBACK or a WAIT_FOR_EVENT 211*76404edcSAsim Jamshed 212*76404edcSAsim Jamshed:returns: 213*76404edcSAsim Jamshed HANDLER_GO_ON if ok 214*76404edcSAsim Jamshed HANDLER_FINISHED if the final output is prepared 215*76404edcSAsim Jamshed 216*76404edcSAsim Jamshed HANDLER_ERROR on error 217*76404edcSAsim Jamshed 218*76404edcSAsim Jamshedhandle_physical_path 219*76404edcSAsim Jamshed```````````````````` 220*76404edcSAsim Jamshed 221*76404edcSAsim Jamshedcalled after physical.path is set 222*76404edcSAsim Jamshed 223*76404edcSAsim Jamshed:returns: 224*76404edcSAsim Jamshed HANDLER_GO_ON if ok 225*76404edcSAsim Jamshed HANDLER_FINISHED if the final output is prepared 226*76404edcSAsim Jamshed 227*76404edcSAsim Jamshed HANDLER_ERROR on error 228*76404edcSAsim Jamshed 229*76404edcSAsim Jamshed 230*76404edcSAsim Jamshedhandle_request_done 231*76404edcSAsim Jamshed``````````````````` 232*76404edcSAsim Jamshed 233*76404edcSAsim Jamshedcalled at the end of the request (logging, statistics, ...) 234*76404edcSAsim Jamshed 235*76404edcSAsim Jamshed:returns: 236*76404edcSAsim Jamshed HANDLER_GO_ON if ok 237*76404edcSAsim Jamshed 238*76404edcSAsim Jamshed HANDLER_ERROR on error 239*76404edcSAsim Jamshed 240*76404edcSAsim Jamshedhandle_connection_close 241*76404edcSAsim Jamshed``````````````````````` 242*76404edcSAsim Jamshed 243*76404edcSAsim Jamshedcalled if the connection is terminated 244*76404edcSAsim Jamshed 245*76404edcSAsim Jamshed:returns: 246*76404edcSAsim Jamshed HANDLER_GO_ON if ok 247*76404edcSAsim Jamshed 248*76404edcSAsim Jamshed HANDLER_ERROR on error 249*76404edcSAsim Jamshed 250*76404edcSAsim Jamshedhandle_joblist 251*76404edcSAsim Jamshed`````````````` 252*76404edcSAsim Jamshed 253*76404edcSAsim Jamshedcalled if the state of the connection has changed 254*76404edcSAsim Jamshed 255*76404edcSAsim Jamshed:returns: 256*76404edcSAsim Jamshed HANDLER_GO_ON if ok 257*76404edcSAsim Jamshed 258*76404edcSAsim Jamshed HANDLER_ERROR on error 259*76404edcSAsim Jamshed 260*76404edcSAsim Jamshed 261