Add MK_PLUGIN_STAGE_00 to plugin stages
[MonkeyD.git] / src / include / plugin.h
blob472a37ea8053f31505ba2efa129c02a5d7e71523
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_CLOSE_CONX 100
45 #define MK_PLUGIN_RET_OWNER 200
46 #define MK_PLUGIN_RET_CONTINUE 300
48 struct plugin_stages {
49 struct plugin *stage_00;
50 struct plugin *stage_10;
51 struct plugin *stage_20;
52 struct plugin *stage_30;
53 struct plugin *stage_40;
54 struct plugin *stage_50;
55 struct plugin *stage_60;
58 struct plugin_list {
59 struct plugin *p;
60 struct plugin_list *next;
63 struct plugin_list *plg_list;
65 struct plugin {
66 char *name;
67 char *version;
68 char *path;
69 void *handler;
70 __uint32_t *stages;
72 /* Plugin external functions */
73 int (*call_init)(void *api);
74 int (*call_worker_init)();
75 int (*call_stage_10)();
76 int (*call_stage_20)(unsigned int,
77 struct sched_connection *,
78 struct client_request *);
79 int (*call_stage_30)(struct client_request *, struct request *);
80 int (*call_stage_40)(struct client_request *, struct request *);
82 struct plugin *next;
85 struct plugin_api {
86 struct server_config *config;
87 struct plugin_list *plugins;
88 struct sched_list_node **sched_list;
90 /* Exporting Functions */
91 void *(*mem_alloc)(int);
92 void *(*mem_alloc_z)(int);
93 void *(*mem_free)(void *);
94 void *(*str_build)(char **, unsigned long *, const char *, ...);
95 void *(*str_dup)(const char *);
96 void *(*str_search)(char *, char *);
97 void *(*str_search_n)(char *, char *, int);
98 void *(*str_copy_substr)(const char *, int, int);
99 void *(*str_split_line)(const char *);
100 void *(*file_to_buffer)(char *);
101 void *(*file_get_info)(char *);
102 void *(*header_send)(int,
103 struct client_request *,
104 struct request *,
105 struct log_info *);
106 void *(*iov_create)(int, int);
107 void *(*iov_free)(struct mk_iov *);
108 void *(*iov_add_entry)(struct mk_iov *,
109 char *,
110 int,
111 mk_pointer,
112 int);
113 void *(*iov_set_entry)(struct mk_iov*,
114 char *,
115 int,
116 int,
117 int);
118 void *(*iov_send)(int, struct mk_iov *, int);
119 void *(*iov_print)(struct mk_iov *);
120 void *(*pointer_set)(mk_pointer *, char *);
121 void *(*pointer_print)(mk_pointer);
122 void *(*socket_cork_flag)(int, int);
123 void *(*socket_set_tcp_nodelay)(int);
124 void *(*socket_connect)(int, char *, int);
125 void *(*socket_create)();
126 void *(*config_create)(char *);
127 void *(*config_free)(struct mk_config *);
128 void *(*config_getval)(struct mk_config *, char *, int);
129 void *(*sched_get_connection)(struct sched_list_node *, int);
132 typedef char mk_plugin_data_t[];
133 typedef __uint32_t mk_plugin_stage_t;
135 void mk_plugin_init();
136 int mk_plugin_stage_run(mk_plugin_stage_t stage,
137 unsigned int socket,
138 struct sched_connection *conx,
139 struct client_request *cr,
140 struct request *sr);
141 void mk_plugin_worker_startup();
143 #endif