Blame


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