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 #define ATTR_PRINTF(A, B) __attribute__((__format__ (printf, A, B)))
22 50794f47 2023-04-04 op
23 50794f47 2023-04-04 op struct logger {
24 50794f47 2023-04-04 op __dead void (*fatal)(int, const char *, ...) ATTR_PRINTF(2, 3);
25 50794f47 2023-04-04 op __dead void (*fatalx)(int, const char *, ...) ATTR_PRINTF(2, 3);
26 50794f47 2023-04-04 op void (*warn)(const char *, ...) ATTR_PRINTF(1, 2);
27 50794f47 2023-04-04 op void (*warnx)(const char *, ...) ATTR_PRINTF(1, 2);
28 50794f47 2023-04-04 op void (*info)(const char *, ...) ATTR_PRINTF(1, 2);
29 50794f47 2023-04-04 op void (*debug)(const char *, ...) ATTR_PRINTF(1, 2);
30 50794f47 2023-04-04 op };
31 50794f47 2023-04-04 op
32 50794f47 2023-04-04 op extern const struct logger *logger;
33 50794f47 2023-04-04 op #define fatal(...) logger->fatal(1, __VA_ARGS__)
34 50794f47 2023-04-04 op #define fatalx(...) logger->fatalx(1, __VA_ARGS__)
35 50794f47 2023-04-04 op #define log_warn(...) logger->warn(__VA_ARGS__)
36 50794f47 2023-04-04 op #define log_warnx(...) logger->warnx(__VA_ARGS__)
37 50794f47 2023-04-04 op #define log_info(...) logger->info(__VA_ARGS__)
38 50794f47 2023-04-04 op #define log_debug(...) logger->debug(__VA_ARGS__)
39 50794f47 2023-04-04 op
40 50794f47 2023-04-04 op #ifdef DEBUG
41 50794f47 2023-04-04 op #define DPRINTF log_debug
42 50794f47 2023-04-04 op #else
43 50794f47 2023-04-04 op #define DPRINTF(...) do {} while (0)
44 50794f47 2023-04-04 op #endif
45 50794f47 2023-04-04 op
46 50794f47 2023-04-04 op struct client {
47 50794f47 2023-04-04 op uint32_t clt_id;
48 50794f47 2023-04-04 op int clt_fd;
49 50794f47 2023-04-04 op struct fcgi *clt_fcgi;
50 50794f47 2023-04-04 op char *clt_server_name;
51 50794f47 2023-04-04 op char *clt_script_name;
52 50794f47 2023-04-04 op char *clt_path_info;
53 50794f47 2023-04-04 op char *clt_query;
54 50794f47 2023-04-04 op int clt_method;
55 50794f47 2023-04-04 op char clt_buf[1024];
56 50794f47 2023-04-04 op size_t clt_buflen;
57 50794f47 2023-04-04 op
58 50794f47 2023-04-04 op SPLAY_ENTRY(client) clt_nodes;
59 50794f47 2023-04-04 op };
60 50794f47 2023-04-04 op SPLAY_HEAD(client_tree, client);
61 50794f47 2023-04-04 op
62 50794f47 2023-04-04 op struct fcgi {
63 50794f47 2023-04-04 op uint32_t fcg_id;
64 50794f47 2023-04-04 op int fcg_s;
65 50794f47 2023-04-04 op struct client_tree fcg_clients;
66 50794f47 2023-04-04 op struct bufferevent *fcg_bev;
67 50794f47 2023-04-04 op int fcg_toread;
68 50794f47 2023-04-04 op int fcg_want;
69 50794f47 2023-04-04 op int fcg_padding;
70 50794f47 2023-04-04 op int fcg_type;
71 50794f47 2023-04-04 op int fcg_rec_id;
72 50794f47 2023-04-04 op int fcg_keep_conn;
73 50794f47 2023-04-04 op int fcg_done;
74 50794f47 2023-04-04 op
75 50794f47 2023-04-04 op struct env *fcg_env;
76 50794f47 2023-04-04 op
77 50794f47 2023-04-04 op SPLAY_ENTRY(fcgi) fcg_nodes;
78 50794f47 2023-04-04 op };
79 50794f47 2023-04-04 op SPLAY_HEAD(fcgi_tree, fcgi);
80 50794f47 2023-04-04 op
81 50794f47 2023-04-04 op struct env {
82 50794f47 2023-04-04 op int env_sockfd;
83 50794f47 2023-04-04 op struct event env_sockev;
84 50794f47 2023-04-04 op struct event env_pausev;
85 50794f47 2023-04-04 op struct fcgi_tree env_fcgi_socks;
86 50794f47 2023-04-04 op
87 50794f47 2023-04-04 op struct sqlite3 *env_db;
88 50794f47 2023-04-04 op struct sqlite3_stmt *env_query;
89 50794f47 2023-04-04 op };
90 50794f47 2023-04-04 op
91 50794f47 2023-04-04 op /* fcgi.c */
92 50794f47 2023-04-04 op int fcgi_end_request(struct client *, int);
93 50794f47 2023-04-04 op int fcgi_abort_request(struct client *);
94 50794f47 2023-04-04 op void fcgi_accept(int, short, void *);
95 50794f47 2023-04-04 op void fcgi_read(struct bufferevent *, void *);
96 50794f47 2023-04-04 op void fcgi_write(struct bufferevent *, void *);
97 50794f47 2023-04-04 op void fcgi_error(struct bufferevent *, short, void *);
98 50794f47 2023-04-04 op void fcgi_free(struct fcgi *);
99 50794f47 2023-04-04 op int clt_putc(struct client *, char);
100 50794f47 2023-04-04 op int clt_puts(struct client *, const char *);
101 50794f47 2023-04-04 op int clt_putsan(struct client *, const char *);
102 61acbd55 2023-09-03 op int clt_putmatch(struct client *, const char *);
103 50794f47 2023-04-04 op int clt_write_bufferevent(struct client *, struct bufferevent *);
104 50794f47 2023-04-04 op int clt_flush(struct client *);
105 50794f47 2023-04-04 op int clt_write(struct client *, const uint8_t *, size_t);
106 50794f47 2023-04-04 op int clt_printf(struct client *, const char *, ...)
107 50794f47 2023-04-04 op __attribute__((__format__(printf, 2, 3)))
108 50794f47 2023-04-04 op __attribute__((__nonnull__(2)));
109 50794f47 2023-04-04 op int fcgi_cmp(struct fcgi *, struct fcgi *);
110 50794f47 2023-04-04 op int fcgi_client_cmp(struct client *, struct client *);
111 50794f47 2023-04-04 op
112 8e5ae9ac 2023-05-05 op /* msearchd.c */
113 8e5ae9ac 2023-05-05 op extern const char *tmpl_head;
114 8e5ae9ac 2023-05-05 op extern const char *tmpl_search;
115 8e5ae9ac 2023-05-05 op extern const char *tmpl_search_header;
116 8e5ae9ac 2023-05-05 op extern const char *tmpl_foot;
117 8e5ae9ac 2023-05-05 op
118 50794f47 2023-04-04 op /* server.c */
119 50794f47 2023-04-04 op int server_main(const char *);
120 50794f47 2023-04-04 op int server_handle(struct env *, struct client *);
121 50794f47 2023-04-04 op void server_client_free(struct client *);
122 50794f47 2023-04-04 op
123 50794f47 2023-04-04 op SPLAY_PROTOTYPE(client_tree, client, clt_nodes, fcgi_client_cmp);
124 50794f47 2023-04-04 op SPLAY_PROTOTYPE(fcgi_tree, fcgi, fcg_nodes, fcgi_cmp);