xref: /lighttpd1.4/src/plugin.h (revision eea7cd3c)
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                            struct plugin *self
54 
55 typedef struct {
56 	PLUGIN_DATA;
57 } plugin_data_base;
58 
59 struct plugin {
60 	void *data;
61 	                                                                      /* is called ... */
62 	handler_t (* handle_uri_raw)           (connection *con, void *p_d);  /* after uri_raw is set */
63 	handler_t (* handle_uri_clean)         (connection *con, void *p_d);  /* after uri is set */
64 	handler_t (* handle_docroot)           (connection *con, void *p_d);  /* getting the document-root */
65 	handler_t (* handle_physical)          (connection *con, void *p_d);  /* mapping url to physical path */
66 	handler_t (* handle_request_env)       (connection *con, void *p_d);  /* (deferred env populate) */
67 	handler_t (* handle_request_done)      (connection *con, void *p_d);  /* at the end of a request */
68 	handler_t (* handle_connection_accept) (connection *con, void *p_d);  /* after accept() socket */
69 	handler_t (* handle_connection_shut_wr)(connection *con, void *p_d);  /* done writing to socket */
70 	handler_t (* handle_connection_close)  (connection *con, void *p_d);  /* before close() of socket */
71 	handler_t (* handle_subrequest_start)  (connection *con, void *p_d);  /* when handler for request not found yet */
72 	handler_t (* handle_subrequest)        (connection *con, void *p_d);  /* */
73 	handler_t (* handle_response_start)    (connection *con, void *p_d);  /* before response headers are written */
74 	handler_t (* connection_reset)         (connection *con, void *p_d);  /* after request done or request abort */
75 
76 	handler_t (* handle_trigger)         (server *srv, void *p_d);        /* once a second */
77 	handler_t (* handle_sighup)          (server *srv, void *p_d);        /* at a sighup */
78 	handler_t (* handle_waitpid)         (server *srv, void *p_d, pid_t pid, int status); /* upon a child process exit */
79 
80 	void *(* init)                       ();
81 	handler_t (* priv_defaults)          (server *srv, void *p_d);
82 	handler_t (* set_defaults)           (server *srv, void *p_d);
83 	handler_t (* worker_init)            (server *srv, void *p_d); /* at server startup (each worker after fork()) */
84 	void (* cleanup)                     (void *p_d);
85 
86 	const char *name;/* name of the plugin */
87 	size_t version;
88 	void *lib;       /* dlopen handle */
89 };
90 
91 __attribute_cold__
92 int plugins_load(server *srv);
93 
94 __attribute_cold__
95 void plugins_free(server *srv);
96 
97 handler_t plugins_call_handle_uri_raw(connection *con);
98 handler_t plugins_call_handle_uri_clean(connection *con);
99 handler_t plugins_call_handle_subrequest_start(connection *con);
100 handler_t plugins_call_handle_subrequest(connection *con);
101 handler_t plugins_call_handle_response_start(connection *con);
102 handler_t plugins_call_handle_request_env(connection *con);
103 handler_t plugins_call_handle_request_done(connection *con);
104 handler_t plugins_call_handle_docroot(connection *con);
105 handler_t plugins_call_handle_physical(connection *con);
106 handler_t plugins_call_handle_connection_accept(connection *con);
107 handler_t plugins_call_handle_connection_shut_wr(connection *con);
108 handler_t plugins_call_handle_connection_close(connection *con);
109 handler_t plugins_call_connection_reset(connection *con);
110 
111 void plugins_call_handle_trigger(server *srv);
112 handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status);
113 
114 __attribute_cold__
115 void plugins_call_handle_sighup(server *srv);
116 
117 __attribute_cold__
118 handler_t plugins_call_init(server *srv);
119 
120 __attribute_cold__
121 handler_t plugins_call_set_defaults(server *srv);
122 
123 __attribute_cold__
124 handler_t plugins_call_worker_init(server *srv);
125 
126 #endif
127