xref: /lighttpd1.4/src/plugin.h (revision f1e9bcb0)
1 #ifndef _PLUGIN_H_
2 #define _PLUGIN_H_
3 #include "first.h"
4 
5 #include "base_decls.h"
6 #include "buffer.h"
7 #include "array.h"
8 #include "configfile.h"
9 
10 #define SERVER_FUNC(x) \
11 		static handler_t x(server *srv, void *p_d)
12 
13 #define CONNECTION_FUNC(x) \
14 		static handler_t x(server *srv, connection *con, void *p_d)
15 
16 #define INIT_FUNC(x) \
17 		__attribute_cold__ \
18 		static void *x(void)
19 
20 #define FREE_FUNC          __attribute_cold__ SERVER_FUNC
21 #define SETDEFAULTS_FUNC   __attribute_cold__ SERVER_FUNC
22 #define SIGHUP_FUNC        __attribute_cold__ SERVER_FUNC
23 #define TRIGGER_FUNC       SERVER_FUNC
24 
25 #define SUBREQUEST_FUNC    CONNECTION_FUNC
26 #define PHYSICALPATH_FUNC  CONNECTION_FUNC
27 #define REQUESTDONE_FUNC   CONNECTION_FUNC
28 #define URIHANDLER_FUNC    CONNECTION_FUNC
29 
30 #define PLUGIN_DATA        size_t id
31 
32 typedef struct {
33 	size_t version;
34 
35 	buffer *name; /* name of the plugin */
36 
37 	void *(* init)                       ();
38 	handler_t (* priv_defaults)          (server *srv, void *p_d);
39 	handler_t (* set_defaults)           (server *srv, void *p_d);
40 	handler_t (* worker_init)            (server *srv, void *p_d); /* at server startup (each worker after fork()) */
41 	handler_t (* cleanup)                (server *srv, void *p_d);
42 	                                                                                   /* is called ... */
43 	handler_t (* handle_trigger)         (server *srv, void *p_d);                     /* once a second */
44 	handler_t (* handle_sighup)          (server *srv, void *p_d);                     /* at a sighup */
45 	handler_t (* handle_waitpid)         (server *srv, void *p_d, pid_t pid, int status); /* upon a child process exit */
46 
47 	handler_t (* handle_uri_raw)         (server *srv, connection *con, void *p_d);    /* after uri_raw is set */
48 	handler_t (* handle_uri_clean)       (server *srv, connection *con, void *p_d);    /* after uri is set */
49 	handler_t (* handle_docroot)         (server *srv, connection *con, void *p_d);    /* getting the document-root */
50 	handler_t (* handle_physical)        (server *srv, connection *con, void *p_d);    /* mapping url to physical path */
51 	handler_t (* handle_request_env)     (server *srv, connection *con, void *p_d);    /* (deferred env populate) */
52 	handler_t (* handle_request_done)    (server *srv, connection *con, void *p_d);    /* at the end of a request */
53 	handler_t (* handle_connection_accept) (server *srv, connection *con, void *p_d);  /* after accept() socket */
54 	handler_t (* handle_connection_shut_wr)(server *srv, connection *con, void *p_d);  /* done writing to socket */
55 	handler_t (* handle_connection_close)  (server *srv, connection *con, void *p_d);  /* before close() of socket */
56 
57 
58 
59 	handler_t (* handle_subrequest_start)(server *srv, connection *con, void *p_d);
60 
61 	                                                                                   /* when a handler for the request
62 											    * has to be found
63 											    */
64 	handler_t (* handle_subrequest)      (server *srv, connection *con, void *p_d);    /* */
65 	handler_t (* handle_response_start)  (server *srv, connection *con, void *p_d);    /* before response headers are written */
66 	handler_t (* connection_reset)       (server *srv, connection *con, void *p_d);    /* after request done or request abort */
67 	void *data;
68 
69 	/* dlopen handle */
70 	void *lib;
71 } plugin;
72 
73 __attribute_cold__
74 int plugins_load(server *srv);
75 
76 __attribute_cold__
77 void plugins_free(server *srv);
78 
79 handler_t plugins_call_handle_uri_raw(server *srv, connection *con);
80 handler_t plugins_call_handle_uri_clean(server *srv, connection *con);
81 handler_t plugins_call_handle_subrequest_start(server *srv, connection *con);
82 handler_t plugins_call_handle_subrequest(server *srv, connection *con);
83 handler_t plugins_call_handle_response_start(server *srv, connection *con);
84 handler_t plugins_call_handle_request_env(server *srv, connection *con);
85 handler_t plugins_call_handle_request_done(server *srv, connection *con);
86 handler_t plugins_call_handle_docroot(server *srv, connection *con);
87 handler_t plugins_call_handle_physical(server *srv, connection *con);
88 handler_t plugins_call_handle_connection_accept(server *srv, connection *con);
89 handler_t plugins_call_handle_connection_shut_wr(server *srv, connection *con);
90 handler_t plugins_call_handle_connection_close(server *srv, connection *con);
91 handler_t plugins_call_connection_reset(server *srv, connection *con);
92 
93 handler_t plugins_call_handle_trigger(server *srv);
94 handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status);
95 
96 __attribute_cold__
97 handler_t plugins_call_handle_sighup(server *srv);
98 
99 __attribute_cold__
100 handler_t plugins_call_init(server *srv);
101 
102 __attribute_cold__
103 handler_t plugins_call_set_defaults(server *srv);
104 
105 __attribute_cold__
106 handler_t plugins_call_worker_init(server *srv);
107 
108 __attribute_cold__
109 handler_t plugins_call_cleanup(server *srv);
110 
111 #endif
112