xref: /lighttpd1.4/src/plugin.h (revision 50bdb55d)
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 "plugin_config.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(connection *con, void *p_d)
15 
16 #define INIT_FUNC(x) \
17 		__attribute_cold__ \
18 		static void *x(void)
19 
20 #define FREE_FUNC(x) \
21 		__attribute_cold__ \
22 		static void x(void *p_d)
23 
24 #define SETDEFAULTS_FUNC   __attribute_cold__ SERVER_FUNC
25 #define SIGHUP_FUNC        __attribute_cold__ SERVER_FUNC
26 #define TRIGGER_FUNC       SERVER_FUNC
27 
28 #define SUBREQUEST_FUNC    CONNECTION_FUNC
29 #define PHYSICALPATH_FUNC  CONNECTION_FUNC
30 #define REQUESTDONE_FUNC   CONNECTION_FUNC
31 #define URIHANDLER_FUNC    CONNECTION_FUNC
32 
33 #define PLUGIN_DATA        int id; \
34                            int nconfig; \
35                            config_plugin_value_t *cvlist
36 
37 typedef struct {
38 	PLUGIN_DATA;
39 } plugin_data_base;
40 
41 typedef struct {
42 	void *data;
43 	                                                                      /* is called ... */
44 	handler_t (* handle_uri_raw)           (connection *con, void *p_d);  /* after uri_raw is set */
45 	handler_t (* handle_uri_clean)         (connection *con, void *p_d);  /* after uri is set */
46 	handler_t (* handle_docroot)           (connection *con, void *p_d);  /* getting the document-root */
47 	handler_t (* handle_physical)          (connection *con, void *p_d);  /* mapping url to physical path */
48 	handler_t (* handle_request_env)       (connection *con, void *p_d);  /* (deferred env populate) */
49 	handler_t (* handle_request_done)      (connection *con, void *p_d);  /* at the end of a request */
50 	handler_t (* handle_connection_accept) (connection *con, void *p_d);  /* after accept() socket */
51 	handler_t (* handle_connection_shut_wr)(connection *con, void *p_d);  /* done writing to socket */
52 	handler_t (* handle_connection_close)  (connection *con, void *p_d);  /* before close() of socket */
53 	handler_t (* handle_subrequest_start)  (connection *con, void *p_d);  /* when handler for request not found yet */
54 	handler_t (* handle_subrequest)        (connection *con, void *p_d);  /* */
55 	handler_t (* handle_response_start)    (connection *con, void *p_d);  /* before response headers are written */
56 	handler_t (* connection_reset)         (connection *con, void *p_d);  /* after request done or request abort */
57 
58 	handler_t (* handle_trigger)         (server *srv, void *p_d);        /* once a second */
59 	handler_t (* handle_sighup)          (server *srv, void *p_d);        /* at a sighup */
60 	handler_t (* handle_waitpid)         (server *srv, void *p_d, pid_t pid, int status); /* upon a child process exit */
61 
62 	void *(* init)                       ();
63 	handler_t (* priv_defaults)          (server *srv, void *p_d);
64 	handler_t (* set_defaults)           (server *srv, void *p_d);
65 	handler_t (* worker_init)            (server *srv, void *p_d); /* at server startup (each worker after fork()) */
66 	void (* cleanup)                     (void *p_d);
67 
68 	const char *name;/* name of the plugin */
69 	size_t version;
70 	void *lib;       /* dlopen handle */
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(connection *con);
80 handler_t plugins_call_handle_uri_clean(connection *con);
81 handler_t plugins_call_handle_subrequest_start(connection *con);
82 handler_t plugins_call_handle_subrequest(connection *con);
83 handler_t plugins_call_handle_response_start(connection *con);
84 handler_t plugins_call_handle_request_env(connection *con);
85 handler_t plugins_call_handle_request_done(connection *con);
86 handler_t plugins_call_handle_docroot(connection *con);
87 handler_t plugins_call_handle_physical(connection *con);
88 handler_t plugins_call_handle_connection_accept(connection *con);
89 handler_t plugins_call_handle_connection_shut_wr(connection *con);
90 handler_t plugins_call_handle_connection_close(connection *con);
91 handler_t plugins_call_connection_reset(connection *con);
92 
93 void 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 void 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 #endif
109