2008-07-22 16:58:27 +00:00
|
|
|
#ifndef _LIGHTTPD_SERVER_H_
|
|
|
|
#define _LIGHTTPD_SERVER_H_
|
2008-07-20 16:28:58 +00:00
|
|
|
|
2009-09-13 15:54:16 +00:00
|
|
|
#ifndef _LIGHTTPD_BASE_H_
|
|
|
|
#error Please include <lighttpd/base.h> instead of this file
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct lua_State;
|
|
|
|
|
2008-08-05 15:08:32 +00:00
|
|
|
#ifndef LIGHTTPD_SERVER_MAGIC
|
2009-09-13 15:54:16 +00:00
|
|
|
# define LIGHTTPD_SERVER_MAGIC ((guint)0x12AB34CD)
|
2008-08-05 15:08:32 +00:00
|
|
|
#endif
|
|
|
|
|
2009-09-08 17:09:39 +00:00
|
|
|
typedef gboolean (*liConnectionNewCB)(liConnection *con);
|
|
|
|
typedef void (*liConnectionCloseCB)(liConnection *con);
|
|
|
|
typedef liNetworkStatus (*liConnectionWriteCB)(liConnection *con, goffset write_max);
|
|
|
|
typedef liNetworkStatus (*liConnectionReadCB)(liConnection *con);
|
|
|
|
typedef void (*liServerSocketReleaseCB)(liServerSocket *srv_sock);
|
|
|
|
|
2008-08-05 15:08:32 +00:00
|
|
|
typedef enum {
|
2009-08-30 18:43:13 +00:00
|
|
|
LI_SERVER_INIT, /** start state */
|
|
|
|
LI_SERVER_LOADING, /** config loaded, prepare listeing sockets/open log files */
|
|
|
|
LI_SERVER_SUSPENDED, /** ready to go, no logs */
|
|
|
|
LI_SERVER_WARMUP, /** listen() active, no logs yet, handling remaining connections */
|
|
|
|
LI_SERVER_RUNNING, /** listen() and logs active */
|
|
|
|
LI_SERVER_SUSPENDING, /** listen() stopped, logs active, handling remaining connections */
|
|
|
|
LI_SERVER_STOPPING, /** listen() stopped, no logs, handling remaining connections */
|
|
|
|
LI_SERVER_DOWN /** exit */
|
2009-07-08 19:06:07 +00:00
|
|
|
} liServerState;
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liServerSocket {
|
2009-04-17 19:53:17 +00:00
|
|
|
gint refcount;
|
2009-07-08 19:06:07 +00:00
|
|
|
liServer *srv;
|
2008-08-05 15:08:32 +00:00
|
|
|
ev_io watcher;
|
2009-09-08 17:09:39 +00:00
|
|
|
|
|
|
|
/* Custom sockets (ssl) */
|
|
|
|
gpointer data;
|
|
|
|
liConnectionWriteCB write_cb;
|
|
|
|
liConnectionReadCB read_cb;
|
|
|
|
liConnectionNewCB new_cb;
|
|
|
|
liConnectionCloseCB close_cb;
|
|
|
|
liServerSocketReleaseCB release_cb;
|
2008-08-05 15:08:32 +00:00
|
|
|
};
|
2008-07-23 20:22:33 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liServer {
|
2008-08-05 15:08:32 +00:00
|
|
|
guint32 magic; /** server magic version, check against LIGHTTPD_SERVER_MAGIC in plugins */
|
2009-08-30 18:43:13 +00:00
|
|
|
liServerState state, dest_state; /** atomic access */
|
2009-07-08 19:06:07 +00:00
|
|
|
liAngelConnection *acon;
|
2008-07-20 16:28:58 +00:00
|
|
|
|
2009-09-13 15:54:16 +00:00
|
|
|
GMutex *lualock;
|
|
|
|
struct lua_State *L; /** NULL if compiled without Lua */
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
liWorker *main_worker;
|
2008-09-09 00:22:21 +00:00
|
|
|
guint worker_count;
|
|
|
|
GArray *workers;
|
2009-07-09 20:17:24 +00:00
|
|
|
GArray *ts_formats; /** array of (GString*), add with li_server_ts_format_add() */
|
2008-09-08 00:20:55 +00:00
|
|
|
|
2009-07-07 20:40:44 +00:00
|
|
|
struct ev_loop *loop;
|
2008-08-15 16:21:21 +00:00
|
|
|
guint loop_flags;
|
2008-09-02 18:30:39 +00:00
|
|
|
ev_signal
|
|
|
|
sig_w_INT,
|
|
|
|
sig_w_TERM,
|
|
|
|
sig_w_PIPE;
|
2009-10-04 12:25:59 +00:00
|
|
|
ev_timer srv_1sec_timer;
|
2008-07-20 16:28:58 +00:00
|
|
|
|
2009-04-03 12:29:55 +00:00
|
|
|
GPtrArray *sockets; /** array of (server_socket*) */
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
liModules *modules;
|
2008-10-22 14:54:44 +00:00
|
|
|
|
2009-08-30 17:25:01 +00:00
|
|
|
GHashTable *plugins; /**< const gchar* => (liPlugin*) */
|
2009-07-08 19:06:07 +00:00
|
|
|
liPlugin *core_plugin;
|
2008-07-23 20:26:38 +00:00
|
|
|
|
2008-07-24 11:25:40 +00:00
|
|
|
/* registered by plugins */
|
2009-08-30 17:25:01 +00:00
|
|
|
GHashTable *options; /**< const gchar* => (liServerOption*) */
|
|
|
|
GHashTable *actions; /**< const gchar* => (liServerAction*) */
|
|
|
|
GHashTable *setups; /**< const gchar* => (liServerSetup*) */
|
2008-07-23 19:34:19 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
GArray *li_plugins_handle_close; /** list of handle_close callbacks */
|
|
|
|
GArray *li_plugins_handle_vrclose; /** list of handle_vrclose callbacks */
|
2008-08-08 17:44:54 +00:00
|
|
|
|
2008-10-01 20:20:31 +00:00
|
|
|
GArray *option_def_values;/** array of option_value */
|
2009-07-08 19:06:07 +00:00
|
|
|
liAction *mainaction;
|
2008-07-20 16:28:58 +00:00
|
|
|
|
2008-09-09 16:03:18 +00:00
|
|
|
gboolean exiting; /** atomic access */
|
2008-07-20 16:28:58 +00:00
|
|
|
|
2008-09-24 21:43:22 +00:00
|
|
|
struct {
|
|
|
|
GMutex *mutex;
|
2008-09-26 22:09:12 +00:00
|
|
|
GHashTable *targets; /** const gchar* path => (log_t*) */
|
2008-09-24 21:43:22 +00:00
|
|
|
GAsyncQueue *queue;
|
|
|
|
GThread *thread;
|
2008-09-26 22:09:12 +00:00
|
|
|
gboolean thread_finish; /** finish writing logs in the queue, then exit thread; access with atomic functions */
|
|
|
|
gboolean thread_stop; /** stop thread immediately; access with atomic functions */
|
|
|
|
gboolean thread_alive; /** access with atomic functions */
|
|
|
|
GArray *timestamps; /** array of log_timestamp_t */
|
2009-07-08 19:06:07 +00:00
|
|
|
liLog *stderr;
|
2008-09-24 21:43:22 +00:00
|
|
|
} logs;
|
2008-08-13 23:05:15 +00:00
|
|
|
|
|
|
|
ev_tstamp started;
|
2008-10-24 15:50:39 +00:00
|
|
|
GString *started_str;
|
2008-08-17 16:24:09 +00:00
|
|
|
|
2009-10-04 12:25:59 +00:00
|
|
|
guint connection_load, max_connections;
|
|
|
|
gboolean connection_limit_hit; /** true if limit was hit and the sockets are disabled */
|
|
|
|
|
2008-09-08 00:20:55 +00:00
|
|
|
/* keep alive timeout */
|
2008-08-17 16:24:09 +00:00
|
|
|
guint keep_alive_queue_timeout;
|
2008-11-10 14:39:03 +00:00
|
|
|
|
2008-11-12 01:09:52 +00:00
|
|
|
gdouble io_timeout;
|
2009-03-04 01:54:38 +00:00
|
|
|
|
2009-04-16 15:02:53 +00:00
|
|
|
GArray *throttle_pools;
|
|
|
|
|
2009-03-04 01:54:38 +00:00
|
|
|
gdouble stat_cache_ttl;
|
2008-07-20 16:28:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API liServer* li_server_new(const gchar *module_dir);
|
|
|
|
LI_API void li_server_free(liServer* srv);
|
|
|
|
LI_API gboolean li_server_loop_init(liServer *srv);
|
|
|
|
LI_API gboolean li_server_worker_init(liServer *srv);
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2009-09-08 17:09:39 +00:00
|
|
|
LI_API liServerSocket* li_server_listen(liServer *srv, int fd);
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2008-09-09 00:22:21 +00:00
|
|
|
/* exit asap with cleanup */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_server_exit(liServer *srv);
|
2008-08-05 15:08:32 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API GString *li_server_current_timestamp();
|
2009-01-04 22:14:08 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_server_out_of_fds(liServer *srv);
|
2008-09-24 21:43:22 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API guint li_server_ts_format_add(liServer *srv, GString* format);
|
2009-01-07 19:59:51 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_server_socket_release(liServerSocket* sock);
|
|
|
|
LI_API void li_server_socket_acquire(liServerSocket* sock);
|
2009-04-03 12:29:55 +00:00
|
|
|
|
2009-08-30 18:43:13 +00:00
|
|
|
LI_API void li_server_goto_state(liServer *srv, liServerState state);
|
|
|
|
LI_API void li_server_reached_state(liServer *srv, liServerState state);
|
|
|
|
|
2008-07-22 16:58:27 +00:00
|
|
|
#endif
|