xref: /lighttpd1.4/src/plugin.h (revision f24e6d69)
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 
11 /**
12  * The status array can carry all the status information you want
13  * the key to the array is <module-prefix>.<name>
14  * and the values are counters
15  *
16  * example:
17  *   fastcgi.backends        = 10
18  *   fastcgi.active-backends = 6
19  *   fastcgi.backend.<key>.load = 24
20  *   fastcgi.backend.<key>....
21  *
22  *   fastcgi.backend.<key>.disconnects = ...
23  */
24 extern array plugin_stats;
25 
26 
27 #define SERVER_FUNC(x) \
28 		static handler_t x(server *srv, void *p_d)
29 
30 #define CONNECTION_FUNC(x) \
31 		static handler_t x(connection *con, void *p_d)
32 
33 #define INIT_FUNC(x) \
34 		__attribute_cold__ \
35 		static void *x(void)
36 
37 #define FREE_FUNC(x) \
38 		__attribute_cold__ \
39 		static void x(void *p_d)
40 
41 #define SETDEFAULTS_FUNC   __attribute_cold__ SERVER_FUNC
42 #define SIGHUP_FUNC        __attribute_cold__ SERVER_FUNC
43 #define TRIGGER_FUNC       SERVER_FUNC
44 
45 #define SUBREQUEST_FUNC    CONNECTION_FUNC
46 #define PHYSICALPATH_FUNC  CONNECTION_FUNC
47 #define REQUESTDONE_FUNC   CONNECTION_FUNC
48 #define URIHANDLER_FUNC    CONNECTION_FUNC
49 
50 #define PLUGIN_DATA        int id; \
51                            int nconfig; \
52                            config_plugin_value_t *cvlist
53 
54 typedef struct {
55 	PLUGIN_DATA;
56 } plugin_data_base;
57 
58 typedef struct {
59 	void *data;
60 	                                                                      /* is called ... */
61 	handler_t (* handle_uri_raw)           (connection *con, void *p_d);  /* after uri_raw is set */
62 	handler_t (* handle_uri_clean)         (connection *con, void *p_d);  /* after uri is set */
63 	handler_t (* handle_docroot)           (connection *con, void *p_d);  /* getting the document-root */
64 	handler_t (* handle_physical)          (connection *con, void *p_d);  /* mapping url to physical path */
65 	handler_t (* handle_request_env)       (connection *con, void *p_d);  /* (deferred env populate) */
66 	handler_t (* handle_request_done)      (connection *con, void *p_d);  /* at the end of a request */
67 	handler_t (* handle_connection_accept) (connection *con, void *p_d);  /* after accept() socket */
68 	handler_t (* handle_connection_shut_wr)(connection *con, void *p_d);  /* done writing to socket */
69 	handler_t (* handle_connection_close)  (connection *con, void *p_d);  /* before close() of socket */
70 	handler_t (* handle_subrequest_start)  (connection *con, void *p_d);  /* when handler for request not found yet */
71 	handler_t (* handle_subrequest)        (connection *con, void *p_d);  /* */
72 	handler_t (* handle_response_start)    (connection *con, void *p_d);  /* before response headers are written */
73 	handler_t (* connection_reset)         (connection *con, void *p_d);  /* after request done or request abort */
74 
75 	handler_t (* handle_trigger)         (server *srv, void *p_d);        /* once a second */
76 	handler_t (* handle_sighup)          (server *srv, void *p_d);        /* at a sighup */
77 	handler_t (* handle_waitpid)         (server *srv, void *p_d, pid_t pid, int status); /* upon a child process exit */
78 
79 	void *(* init)                       ();
80 	handler_t (* priv_defaults)          (server *srv, void *p_d);
81 	handler_t (* set_defaults)           (server *srv, void *p_d);
82 	handler_t (* worker_init)            (server *srv, void *p_d); /* at server startup (each worker after fork()) */
83 	void (* cleanup)                     (void *p_d);
84 
85 	const char *name;/* name of the plugin */
86 	size_t version;
87 	void *lib;       /* dlopen handle */
88 } plugin;
89 
90 __attribute_cold__
91 int plugins_load(server *srv);
92 
93 __attribute_cold__
94 void plugins_free(server *srv);
95 
96 handler_t plugins_call_handle_uri_raw(connection *con);
97 handler_t plugins_call_handle_uri_clean(connection *con);
98 handler_t plugins_call_handle_subrequest_start(connection *con);
99 handler_t plugins_call_handle_subrequest(connection *con);
100 handler_t plugins_call_handle_response_start(connection *con);
101 handler_t plugins_call_handle_request_env(connection *con);
102 handler_t plugins_call_handle_request_done(connection *con);
103 handler_t plugins_call_handle_docroot(connection *con);
104 handler_t plugins_call_handle_physical(connection *con);
105 handler_t plugins_call_handle_connection_accept(connection *con);
106 handler_t plugins_call_handle_connection_shut_wr(connection *con);
107 handler_t plugins_call_handle_connection_close(connection *con);
108 handler_t plugins_call_connection_reset(connection *con);
109 
110 void plugins_call_handle_trigger(server *srv);
111 handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status);
112 
113 __attribute_cold__
114 void plugins_call_handle_sighup(server *srv);
115 
116 __attribute_cold__
117 handler_t plugins_call_init(server *srv);
118 
119 __attribute_cold__
120 handler_t plugins_call_set_defaults(server *srv);
121 
122 __attribute_cold__
123 handler_t plugins_call_worker_init(server *srv);
124 
125 #endif
126