Add some TRACE messages
[MonkeyD.git] / src / include / plugin.h
blob1f61f22837e3f293489ecbef33bb93d532899bac
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /* Monkey HTTP Daemon
4 * ------------------
5 * Copyright (C) 2001-2009, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef MK_PLUGIN_H
23 #define MK_PLUGIN_H
25 #include "request.h"
26 #include "memory.h"
27 #include "iov.h"
28 #include "socket.h"
29 #include "config.h"
31 #define MK_PLUGIN_LOAD "plugins.load"
33 #define MK_PLUGIN_ERROR -1 /* plugin execution error */
34 #define MK_PLUGIN_
36 #define MK_PLUGIN_STAGE_00 ((__uint32_t) 0) /* Dummy plugin */
37 #define MK_PLUGIN_STAGE_10 ((__uint32_t) 1) /* Before server's loop */
38 #define MK_PLUGIN_STAGE_20 ((__uint32_t) 2) /* Accepted connection */
39 #define MK_PLUGIN_STAGE_30 ((__uint32_t) 4) /* Connection assigned */
40 #define MK_PLUGIN_STAGE_40 ((__uint32_t) 8) /* Object Handler */
41 #define MK_PLUGIN_STAGE_50 ((__uint32_t) 16) /* Request ended */
42 #define MK_PLUGIN_STAGE_60 ((__uint32_t) 32) /* Connection closed */
44 #define MK_PLUGIN_RET_NOT_ME -1
45 #define MK_PLUGIN_RET_CONTINUE 100
46 #define MK_PLUGIN_RET_END 200
47 #define MK_PLUGIN_RET_CLOSE_CONX 300
49 /* Event return values */
50 #define MK_PLUGIN_RET_EVENT_NOT_ME -300
52 struct plugin_stages
54 struct plugin *stage_00;
55 struct plugin *stage_10;
56 struct plugin *stage_20;
57 struct plugin *stage_30;
58 struct plugin *stage_40;
59 struct plugin *stage_50;
60 struct plugin *stage_60;
63 struct plugin_list
65 struct plugin *p;
66 struct plugin_list *next;
69 struct plugin_list *plg_list;
71 struct plugin
73 char *shortname;
74 char *name;
75 char *version;
76 char *path;
77 void *handler;
78 __uint32_t *stages;
80 /* Plugin external functions */
81 int (*call_init) (void *api, char *confdir);
82 int (*call_worker_init) ();
83 int (*call_stage_10) ();
84 int (*call_stage_20) (unsigned int,
85 struct sched_connection *, struct client_request *);
86 int (*call_stage_30) (struct client_request *, struct request *);
87 int (*call_stage_40) (struct plugin *, struct client_request *, struct request *);
88 int (*call_stage_40_event_read) (struct client_request *, struct request *);
89 int (*call_stage_40_event_write)(struct client_request *, struct request *);
91 pthread_key_t thread_key;
92 struct plugin *next;
95 struct plugin_api
97 struct server_config *config;
98 struct plugin_list *plugins;
99 struct sched_list_node **sched_list;
101 /* Exporting Functions */
102 void *(*mem_alloc) (int);
103 void *(*mem_alloc_z) (int);
104 void *(*mem_free) (void *);
105 void *(*str_build) (char **, unsigned long *, const char *, ...);
106 void *(*str_dup) (const char *);
107 void *(*str_search) (char *, char *);
108 void *(*str_search_n) (char *, char *, int);
109 void *(*str_copy_substr) (const char *, int, int);
110 void *(*str_split_line) (const char *);
111 void *(*file_to_buffer) (char *);
112 void *(*file_get_info) (char *);
113 void *(*header_send) (int,
114 struct client_request *,
115 struct request *, struct log_info *);
116 void *(*iov_create) (int, int);
117 void *(*iov_free) (struct mk_iov *);
118 void *(*iov_add_entry) (struct mk_iov *, char *, int, mk_pointer, int);
119 void *(*iov_set_entry) (struct mk_iov *, char *, int, int, int);
120 void *(*iov_send) (int, struct mk_iov *, int);
121 void *(*iov_print) (struct mk_iov *);
122 void *(*pointer_set) (mk_pointer *, char *);
123 void *(*pointer_print) (mk_pointer);
124 void *(*plugin_load_symbol) (void *, char *);
125 void *(*socket_cork_flag) (int, int);
126 void *(*socket_set_tcp_nodelay) (int);
127 void *(*socket_connect) (int, char *, int);
128 void *(*socket_set_nonblocking) (int);
129 void *(*socket_create) ();
130 void *(*config_create) (char *);
131 void *(*config_free) (struct mk_config *);
132 void *(*config_getval) (struct mk_config *, char *, int);
133 void *(*sched_get_connection) (struct sched_list_node *, int);
134 void *(*event_add) (int, struct plugin *, struct client_request *,
135 struct request *);
136 void *(*event_socket_change_mode) (int, int);
138 #ifdef TRACE
139 void *(*trace)();
140 #endif
144 typedef char mk_plugin_data_t[];
145 typedef __uint32_t mk_plugin_stage_t;
147 /* Plugin events thread key */
148 pthread_key_t mk_plugin_event_k;
150 struct plugin_event {
151 int socket;
152 struct plugin *handler;
153 struct client_request *cr;
154 struct request *sr;
155 struct plugin_event *next;
158 void mk_plugin_init();
159 int mk_plugin_stage_run(mk_plugin_stage_t stage,
160 unsigned int socket,
161 struct sched_connection *conx,
162 struct client_request *cr, struct request *sr);
163 void mk_plugin_worker_startup();
165 void mk_plugin_request_handler_add(struct request *sr, struct plugin *p);
166 void mk_plugin_request_handler_del(struct request *sr, struct plugin *p);
168 void mk_plugin_preworker_calls();
170 /* Plugins events interface */
171 int mk_plugin_event_add(int socket, struct plugin *handler,
172 struct client_request *cr,
173 struct request *sr);
174 int mk_plugin_event_set_list(struct plugin_event *event);
175 struct plugin_event *mk_plugin_event_get_list();
176 int mk_plugin_event_socket_change_mode(int socket, int mode);
178 /* Plugins event handlers */
179 int mk_plugin_event_read(int socket);
180 int mk_plugin_event_write(int socket);
181 int mk_plugin_event_error(int socket);
182 int mk_plugin_event_close(int socket);
183 int mk_plugin_event_timeout(int socket);
185 #endif