Blob


1 /*
2 * This file is in the public domain.
3 */
5 #define FD_RESERVE 5
6 #define QUERY_MAXLEN 1025 /* including NUL */
8 struct bufferevent;
9 struct event;
10 struct fcgi;
11 struct sqlite3;
12 struct sqlite3_stmt;
13 struct template;
15 enum {
16 METHOD_UNKNOWN,
17 METHOD_GET,
18 METHOD_POST,
19 };
21 #ifdef DEBUG
22 #define DPRINTF log_debug
23 #else
24 #define DPRINTF(...) do {} while (0)
25 #endif
27 struct client {
28 uint32_t clt_id;
29 int clt_fd;
30 struct fcgi *clt_fcgi;
31 char *clt_server_name;
32 char *clt_script_name;
33 char *clt_path_info;
34 char *clt_query;
35 int clt_method;
36 char clt_buf[1024];
37 size_t clt_buflen;
39 SPLAY_ENTRY(client) clt_nodes;
40 };
41 SPLAY_HEAD(client_tree, client);
43 struct fcgi {
44 uint32_t fcg_id;
45 int fcg_s;
46 struct client_tree fcg_clients;
47 struct bufferevent *fcg_bev;
48 int fcg_toread;
49 int fcg_want;
50 int fcg_padding;
51 int fcg_type;
52 int fcg_rec_id;
53 int fcg_keep_conn;
54 int fcg_done;
56 struct env *fcg_env;
58 SPLAY_ENTRY(fcgi) fcg_nodes;
59 };
60 SPLAY_HEAD(fcgi_tree, fcgi);
62 struct env {
63 int env_sockfd;
64 struct event env_sockev;
65 struct event env_pausev;
66 struct fcgi_tree env_fcgi_socks;
68 struct sqlite3 *env_db;
69 struct sqlite3_stmt *env_query;
70 };
72 /* fcgi.c */
73 int fcgi_end_request(struct client *, int);
74 int fcgi_abort_request(struct client *);
75 void fcgi_accept(int, short, void *);
76 void fcgi_read(struct bufferevent *, void *);
77 void fcgi_write(struct bufferevent *, void *);
78 void fcgi_error(struct bufferevent *, short, void *);
79 void fcgi_free(struct fcgi *);
80 int clt_putc(struct client *, char);
81 int clt_puts(struct client *, const char *);
82 int clt_putsan(struct client *, const char *);
83 int clt_putmatch(struct client *, const char *);
84 int clt_write_bufferevent(struct client *, struct bufferevent *);
85 int clt_flush(struct client *);
86 int clt_write(struct client *, const uint8_t *, size_t);
87 int clt_printf(struct client *, const char *, ...)
88 __attribute__((__format__(printf, 2, 3)))
89 __attribute__((__nonnull__(2)));
90 int fcgi_cmp(struct fcgi *, struct fcgi *);
91 int fcgi_client_cmp(struct client *, struct client *);
93 /* msearchd.c */
94 extern const char *tmpl_head;
95 extern const char *tmpl_search;
96 extern const char *tmpl_search_header;
97 extern const char *tmpl_foot;
99 /* server.c */
100 int server_main(const char *);
101 int server_handle(struct env *, struct client *);
102 void server_client_free(struct client *);
104 SPLAY_PROTOTYPE(client_tree, client, clt_nodes, fcgi_client_cmp);
105 SPLAY_PROTOTYPE(fcgi_tree, fcgi, fcg_nodes, fcgi_cmp);