-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpd.h
626 lines (535 loc) · 22 KB
/
httpd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/*
* ryshttpd -- simple filesharing http server.
*
* ryshttpd is copyrighted:
* Copyright (C) 2018 Andrey Rys. All rights reserved.
*
* ryshttpd is licensed to you under the terms of std. MIT/X11 license:
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _RYSHTTPD_H
#define _RYSHTTPD_H
#define PROGRAM_NAME "ryshttpd"
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#endif
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
#include "config.h"
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
#include <dirent.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <poll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <errno.h>
#include <ctype.h>
#include <sys/time.h>
#include <time.h>
#include <limits.h>
#include <libgen.h>
#include <regex.h>
#include <fnmatch.h>
#include <pwd.h>
#include <grp.h>
#include <locale.h>
#include "xmalloc.h"
#define rh_malloc xmalloc
#define rh_realloc xrealloc
#define rh_free xfree
#define rh_calloc xcalloc
#define rh_szalloc xszalloc
#include "tfdef.h"
#include "skein.h"
#ifndef FNM_CASEFOLD
#define FNM_CASEFOLD 0
#endif
#ifdef WITH_FEXECVE
#ifndef O_EXEC
#define O_EXEC O_PATH
#endif
#endif
enum { NO, YES };
#define NOSIZE ((size_t)-1) /* NOt a SIZE */
#define NOFSIZE ((rh_fsize)-1) /* NOt a FileSIZE */
#define RH_XSALLOC_MAX 262144 /* max. amount of memory to scan */
#define RH_CLIENT_READ_SZ 32768 /* temporary to read request into, and IO pool */
#define RH_ALLOC_MAX 4096 /* usual max allocation size of single object like string */
#define RH_ALLOC_SMALL 128 /* small objects preallocation size limit */
#define STAT_ARRAY_SZ(x) (sizeof(x)/sizeof(*x))
#define CSTR_SZ(x) (sizeof(x)-1)
#define ADDHALF_TO(x) ((x / 2) * 3)
/* only for rh_yesno types, boys and girls! */
#define FLIP_YESNO(x) do { \
if (x == YES) x = NO; \
else x = YES; \
} while (0)
#define HTTP_DATE_FMT "%a, %d %b %Y %H:%M:%S GMT"
#define LIST_DATE_FMT "%H:%M:%S %d%b%Y"
#define HTTP_REQUEST_MAX 4096
#define HTTP_REQHEAD_MAX 2048
typedef void (*sighandler_t)(int);
typedef unsigned long long rh_fsize;
typedef short rh_yesno;
extern char **environ;
extern char *progname;
extern pid_t svpid;
extern char *rh_hostnames;
extern char *rh_bindaddr4_s;
extern char *rh_bindaddr6_s;
extern char *rh_port_s;
extern char *rh_unixsock_path;
extern char *rh_ident;
extern char *rh_root_dir;
extern char *rh_logfile;
extern char *rh_logfmt;
extern char *rh_timefmt;
#ifdef WITH_LIBMAGIC
extern char *rh_magicdb_path;
#endif
extern char *rh_indexes_pattern;
extern char *rh_chroot_dir;
extern char *rh_switch_user;
extern char *rh_switch_euser;
extern char *rh_switch_group;
extern char *rh_switch_egroup;
extern char *rh_switch_groups;
extern char *rh_cgi_execs;
extern char *rh_nhcgi_execs;
extern char *rh_cgieh_execs;
extern char *rh_cgiserver;
extern char *rh_cgi_path;
extern char **rh_xrealips;
extern char *rh_htaccess_name;
extern char *rh_dir_prepend_path;
#ifndef WITH_LIBMAGIC
extern char *rh_content_charset;
#endif
extern char *rh_list_date_fmt;
extern char *rh_cryptpw;
extern unsigned long rh_client_request_timeout;
extern unsigned long rh_client_keepalive_timeout;
extern size_t rh_client_keepalive_requests;
extern unsigned int rh_client_ipv6_subnet;
extern int rh_cgi_mode;
extern rh_yesno rh_follow_symlinks;
extern size_t rh_rdwr_bufsize;
extern rh_yesno rh_issuper;
extern rh_yesno rh_insecure_htaccess;
extern rh_yesno rh_regex_no_case;
extern rh_yesno rh_htaccess_regex_no_case;
extern rh_yesno rh_no_dirsort;
extern rh_yesno rh_try_shell_exec;
extern rh_yesno rh_secure_httproot;
extern rh_yesno rh_allow_tar;
extern useconds_t rh_oom_timer;
extern unsigned long rh_oom_max_attempts;
extern int rh_on_fs_error;
extern rh_yesno rh_no_cache_headers;
extern void *rh_indexes_rgx;
extern void *rh_hostnames_rgx;
extern void *rh_cgiexecs_rgx;
extern void *rh_nhcgiexecs_rgx;
extern void *rh_cgiehexecs_rgx;
struct client_state; /* declared later */
#define RATELIM_START_CHUNKS 32 /* should be fully divisible */
#define RATELIM_TIME_CHUNK(nr) (1000000000UL / nr)
#define RATELIM_TIME_CHUNK_REM(nr, chunk, rem) ((RATELIM_TIME_CHUNK(nr)/chunk)*rem)
struct rate_limit {
rh_fsize total; /* total bandwidth limit */
rh_yesno calculated; /* if it was calculated, then do not touch it */
size_t chunk; /* chunk size */
size_t nr_chk; /* number of chunks per sec, starting from RATELIM_START_CHUNKS */
/* the stuff below is for smaller than "chunk" chunks */
size_t done; /* temporary: how many bytes already was done to trigger sleep */
struct timespec doneacc; /* total small chunks done time */
};
struct client_info {
/* Process and logging devices and bookkeeping */
pid_t pid; /* This client child pid */
int logfd; /* fd to logging pipe end, this is WR end */
size_t logwrit; /* how much bytes already written to log pipe? */
size_t maxlogsz; /* if != NOSIZE, then up to this size is possible to write */
/* I/O information */
int clfd; /* client fd to which writings are necessary */
struct rate_limit ralimitup; /* upload (from client) speed limit */
struct rate_limit ralimitdown; /* download (to client) speed limit */
/* Networking devices and information */
int af; /* address family */
struct ucred *ucr; /* if af == AF_UNIX, this is set to resolved peer creds */
void *sockaddr; /* raw accept'ed client sockaddr struct corresponding to family */
socklen_t sockaddrlen; /* length of sockaddr structure */
char *ipaddr; /* resolved numeric ip address */
char *port; /* remote client port number */
char *servport; /* server port that accepted connection */
};
typedef void (*rh_exit_cb)(int);
extern rh_exit_cb rh_atexit;
void rh_exit(int status);
void set_progname(const char *name);
void xerror(const char *f, ...);
void xerror_status(int status, const char *f, ...);
void rh_perror(const char *f, ...);
void xexits(const char *f, ...);
void xexits_status(int status, const char *f, ...);
char *rh_strerror(int err);
void usage(void);
void show_version(void);
void rh_vfsay(FILE *where, rh_yesno addnl, const char *fmt, va_list ap);
void rh_nvesay(const char *fmt, va_list ap);
void rh_nesay(const char *fmt, ...);
void rh_esay(const char *fmt, ...);
void rh_say(const char *fmt, ...);
void block_signals(rh_yesno block, ...);
struct fmtstr_args;
#define APPEND_FSA(pfsa, pnr_fsa, sp, sz, sfmt, vdata) \
do { \
pfsa = rh_realloc(pfsa, (pnr_fsa+1) * sizeof(struct fmtstr_args)); \
pfsa[pnr_fsa].spec = sp; \
pfsa[pnr_fsa].size = sz; \
pfsa[pnr_fsa].fmt = sfmt; \
pfsa[pnr_fsa].data = vdata; \
pnr_fsa++; \
} while (0)
void clear_environ(void);
char *rh_getenvline(char *const *envp, const char *str);
void preset_fsa(struct fmtstr_args **fsa, size_t *nr_fsa, const struct client_state *clstate);
size_t rh_strltxstr(char *str, size_t n, int *nr_reps, const char *from, const char *to);
size_t rh_strlxstr(char *str, size_t n, const char *from, const char *to);
size_t rh_strxstr(char *str, const char *from, const char *to);
void rh_memzero(void *p, size_t l);
rh_yesno memtest(void *p, size_t l, int c);
void *rh_memdup(const void *p, size_t sz);
char *rh_strndup(const char *s, size_t max);
char *rh_strdup(const char *s);
void *append_data(void *block, const void *data, size_t szdata);
rh_yesno is_number(const char *s, int sign);
int rh_fcntl(int fd, int cmd, int flags, rh_yesno set);
rh_yesno is_writable(const char *path);
void useconds_to_timeval(unsigned long long useconds, struct timeval *tv);
void skeinhash(void *hash, size_t hashsz, const void *msg, size_t msgsz);
#define PATH_IS_FILE 1
#define PATH_IS_DIR 2
char *rh_realpath(const char *path);
rh_yesno is_symlink(const char *path);
int file_or_dir(const char *path);
rh_yesno is_exec(const char *path);
char *rh_which(const char *envpath, const char *name);
char *find_index_file(const char *path);
struct netaddr {
int type;
char addr[16];
char saddr[INET6_ADDRSTRLEN];
unsigned int pfx, pmax;
};
int rh_addr_type(const char *addr);
rh_yesno rh_parse_addr(const char *addr, struct netaddr *na);
rh_yesno rh_match_addr(const struct netaddr *n, const struct netaddr *a);
#define HTA_REWRITE 494
rh_yesno is_htaccess(const char *path);
int verify_htaccess(struct client_state *clstate, const char *path, const char *rootdir);
struct fmtstr_args {
char *spec;
size_t size;
char *fmt;
const void *data;
};
struct fmtstr_state {
struct fmtstr_args *args;
int nargs;
const char *fmt;
char *result;
size_t result_sz;
int nr_parsed;
short trunc;
};
rh_yesno str_empty(const char *str);
size_t char_to_nul(char *s, size_t l, char c);
size_t rh_strlcpy_real(char *dst, const char *src, size_t size);
size_t rh_strlcpy(char *d, const char *s, size_t n);
void *rh_memmem(const void *hs, size_t hsn, const void *ne, size_t nen);
rh_yesno is_fmtstr(const char *s);
void nuke_fmtstr_templates(char *line, size_t szline);
char *parse_fmtstr(struct fmtstr_state *fst);
size_t shrink_dynstr(char **s);
void rh_astrcat(char **d, const char *s);
void rh_prepend_str(char **d, const char *s);
int rh_snprintf(char *s, size_t n, const char *fmt, ...);
int rh_snprintf_real(char *s, size_t n, const char *fmt, ...);
int rh_vsnprintf(char *s, size_t n, const char *fmt, va_list ap);
int rh_vasprintf(char **s, const char *fmt, va_list ap);
int rh_asprintf(char **s, const char *fmt, ...);
rh_yesno getxchr(char *chr, const char *s);
void parse_escapes(char *str, size_t n);
size_t filter_dotdots(char *str, size_t strsz);
void unquote(char *str, size_t strsz);
void urldecode(char *str, size_t n);
char *urlencode(const char *str);
rh_yesno is_comment(const char *s);
void *load_config(int fd);
char *get_config_line(void *config);
void free_config(void *config);
#define RH_REGEX_MAX_GROUPS 32
void *regex_compile(const char *pattern, rh_yesno nocase, rh_yesno pmatch, rh_yesno nofixup);
rh_yesno regex_exec(const void *regex, const char *string);
char *regex_get_pattern(const void *regex);
char *regex_get_match(const void *regex, const char *string, size_t idx);
rh_yesno regex_is_error(const void *regex);
char *regex_error(const void *regex);
void regex_xexits(const void *regex);
void regex_free(void *regex);
rh_yesno rh_fnmatch(const char *pattern, const char *string, rh_yesno nocase);
rh_yesno getsdate_r(time_t t, const char *fmt, rh_yesno gmt, char *str, size_t szstr);
char *getsdate(time_t t, const char *fmt, rh_yesno gmt);
time_t getdatetime_r(char *date, size_t szdate, const char *fmt);
time_t getdatetime(char **date, const char *fmt);
#define NOUID ((uid_t)-1)
#define NOGID ((gid_t)-1)
uid_t uidbyname(const char *name);
gid_t gidbyuid(uid_t uid);
gid_t gidbyname(const char *name);
int getugroups(const char *name, gid_t gr, gid_t *grps, int *ngrps);
char *namebyuid(uid_t uid);
char *namebygid(gid_t gid);
void *init_user_switch(
const char *user, const char *group,
const char *euser, const char *egroup,
const char *groups);
void user_switch_setid_policy(void *uswitch, rh_yesno nosetuid, rh_yesno nosetgid);
void apply_user_switch(const void *uswitch);
rh_yesno user_switch_issuper(const void *uswitch);
void free_user_switch(void *uswitch);
rh_fsize rh_fdsize(int fd);
rh_fsize rh_str_fsize(const char *s, char **stoi);
size_t rh_str_size(const char *s, char **stoi);
long rh_str_long(const char *s, char **stoi);
int rh_str_int(const char *s, char **stoi);
unsigned rh_str_uint(const char *s, char **stoi);
char *rh_human_fsize(rh_fsize fsize);
rh_fsize rh_str_human_fsize(const char *s, char **stoi);
#define IOS_ALL_OK 0
#define IOS_READ_ERROR 1
#define IOS_WRITE_ERROR 2
#define IOS_SEEK_ERROR 3
typedef size_t (*io_read_fn)(void *, void *, size_t);
typedef size_t (*io_write_fn)(void *, const void *, size_t);
typedef void (*io_mangle_fn)(void *, void *, size_t);
typedef rh_fsize (*io_seek_fn)(void *, rh_fsize);
struct io_stream_args {
io_read_fn rdfn; /* reading function pointer */
io_write_fn wrfn; /* writing function pointer */
io_mangle_fn mgfn; /* data preprocessing function pointer */
io_seek_fn skfn; /* seeking function pointer */
void *fn_args; /* data required for functions above */
void *workbuf; /* temporary rw buffer */
size_t wkbufsz; /* size of workbuf */
rh_fsize file_size; /* file size, to verify */
rh_fsize start_from; /* seek to this offset */
rh_fsize read_to; /* read to this offset */
rh_fsize nr_written; /* how much was written */
int error; /* actual system error */
int status; /* IOS_* flag of io request */
};
size_t xread(int fd, void *data, size_t szdata);
size_t xwrite(int fd, const void *data, size_t szdata);
size_t io_read_data(int fd, void *data, size_t szdata, rh_yesno noretry, size_t *rdd);
size_t io_write_data(int fd, const void *data, size_t szdata, rh_yesno noretry, size_t *wrd);
rh_yesno io_stream_file(struct io_stream_args *iosd_params);
void io_socket_timeout(int fd, unsigned long rcvtimeo, unsigned long sndtimeo);
size_t io_recv_data(struct client_info *clinfo, void *data, size_t szdata, rh_yesno noretry, rh_yesno nosleep);
size_t io_send_data(struct client_info *clinfo, const void *data, size_t szdata, rh_yesno noretry, rh_yesno nosleep);
char *getmyhostname(void);
rh_yesno resolve_ip(char **ipaddr, const struct client_info *cli);
rh_yesno resolve_port(char **port, const struct client_info *cli);
#ifdef WITH_LIBMAGIC
rh_yesno init_magic_db(void);
char *get_mime_fd(int fd, void *tmp, size_t tsz);
#else
void init_mime_regex(void);
char *get_mime_filename(const char *filename);
#endif
/* these three are opaque - their machinery is hidden inside. */
void add_client(pid_t pid, int logfd, const char *ipaddr);
int get_client_logfd(pid_t pid);
void delete_client(pid_t pid);
size_t count_clients(const char *ipaddr);
size_t count_all_clients(void);
#define RESTYPE_PATH 1
#define RESTYPE_NAME 2
#define RESTYPE_ARGS 3
struct embedded_resource {
char *path; /* exact virtual file path which will be served from resource instead.
NULL hides resource from public access, but "args" may expose it again.
Error pages have both "path" and "args" set to NULL, and have only "name" set. */
char *name; /* basename of path. Useful for error pages.
Even if your resource is hidden or secret, please
set this to a meaningful string. See client.c for details. */
char *args; /* sent only if this QUERY_STRING is matched.
If NULL, then strargs can be any, and resource will be matched and sent.
With NULL "path", matched and viewed only by "args". Useful for secrets.
Both "path" and "args" require path and strargs to match. */
char *mimetype; /* it's mime type (exact) to be sent */
rh_yesno is_static; /* should not be cloned and touched, mainly because it's either
a binary resource, or there is nothing to edit inside it really. */
time_t lastmod; /* last modified (dummy) timestamp. */
void *data; /* actual resource data */
size_t szdata; /* size of the resource data */
};
const struct embedded_resource *find_resource(int restype, const char *str);
const struct embedded_resource *find_resource_args(const char *path, const char *args);
struct embedded_resource *clone_resource(const struct embedded_resource *rsrc);
rh_yesno resource_prepend_path(struct embedded_resource *rsrc, const char *ppath);
void free_resource(struct embedded_resource *rsrc);
rh_yesno load_user_resource(
const char *resfpath, const char *htpath, const char *name,
const char *htargs, const char *mimetype);
struct http_header {
char *name; /* name of header */
char *value; /* it's value */
};
struct http_arg {
char *name; /* name of argument */
char *value; /* it's value */
};
struct response_status {
unsigned status; /* integer http status code, e.g. 404 */
const char *response; /* textual line to be sent, e.g. "404 Not Found".
Also this status code is displayed on a error page. */
};
const char *find_response_string(unsigned status);
void response_chunk_length(struct client_state *clstate, size_t length);
void response_chunk_end(struct client_state *clstate);
void response_error(struct client_state *clstate, unsigned status);
void response_ok(struct client_state *clstate, unsigned status, rh_yesno end_head);
size_t response_recv_data(struct client_state *clstate, void *data, size_t szdata);
void response_send_data(struct client_state *clstate, const void *data, size_t szdata);
#define REQ_METHOD_GET 1
#define REQ_METHOD_HEAD 2
#define REQ_METHOD_POST 3
#define CGI_MODE_REGULAR 1
#define CGI_MODE_NOHEADS 2
#define CGI_MODE_ENDHEAD 3
struct tf_ctx {
TF_BYTE_TYPE keyx[TF_KEY_SIZE];
TF_BYTE_TYPE keyz[TF_KEY_SIZE];
TF_BYTE_TYPE ctr[TF_BLOCK_SIZE];
};
/* keep in sync with reset_client_state@client.c */
struct client_state {
/* Connection, state and keepalive info. Not touched by reset_client_state. */
struct client_info *clinfo; /* connection info supplied */
char *ipaddr; /* for xrealip: if none is used, then it is set to clinfo->ipaddr,
if xrealip, then it contains address told by proxier to us,
but clinfo->ipaddr always holds _real_ socket address. */
size_t nr_requests; /* No. of requests processed. */
rh_yesno is_keepalive; /* do not write log on empty requests */
char *httproot; /* a copy of rh_root_dir in case if it gets changed from htaccess */
/* Client time. */
time_t request_time; /* time when we taken client request to process. */
char *request_date; /* rh_timefmt formatted date, for logging */
/* Client supplied unparsed/parsed info */
void *tail; /* data part supplied by client after "\r\n\r\n". Useful for CGI POST. */
size_t sztail; /* if already resized, then tail is of this size. */
char **request_lines; /* clean full copy of request lines, incl. method line */
rh_yesno is_crlf; /* response: lines must end with "\r\n" */
int method; /* GET or HEAD */
char *request; /* usually path. Can contain arguments (after '?'). */
char *protoversion; /* http protocol version requested, for response */
char *path; /* urldecoded, filtered path of interest, free of any args */
char *requri; /* same as path, but saved early after security filtering */
char *strargs; /* only arguments without leading '?', if any.
filtered off insecure paths. */
struct http_arg *args; /* parsed arguments above */
struct http_header *headers; /* parsed client headers */
/* Our private info necessary to provide a good response */
char *realpath; /* resolved path with rh_realpath */
int filedir; /* resolved as file or directory? */
int file_fd; /* if file, then this is it's open fd for IO ops */
rh_yesno wants_dir; /* client wants a directory, answer with error if not a directory */
rh_yesno is_exec; /* if file, will it be executed? */
rh_yesno is_rsrc; /* it was a fake file: internal resource. */
rh_yesno is_indx; /* set if was redirected by index regexmatch */
int cgi_mode; /* CGI mode of operation: regular, NoHeaders */
void *workbuf; /* response IO: temporary to read into */
size_t wkbufsz; /* size of workbuf */
rh_fsize filesize; /* measured file size, for direct files */
rh_fsize range_start, range_end; /* for partial transfers */
rh_fsize recvbytes; /* how many bytes were received already */
rh_fsize sentbytes; /* how many bytes were sent already */
int iostate; /* result of io_send_file work */
int ioerror; /* set if there was an OS error while io_send_file work */
struct http_header *sendheaders; /* additional headers which response routine must send */
/* .htaccess related items */
rh_yesno was_rewritten; /* single rewrite, without recursion, was matched before */
rh_yesno noindex; /* htaccess forbids to index this directory */
rh_yesno allow_tar; /* allow to take a whole tar archive of this directory */
void *hideindex_rgx; /* htaccess "hideindex" regex matching data */
char *prevpath; /* saved previous path in case of directory listing */
char *cryptpw; /* symmetric encryption password */
struct tf_ctx cryptctx; /* encryption context */
/* Is response sent already? */
rh_yesno sent_response_already;
/* Response status */
char *status;
/* Alternative log line string, for empty requests */
char *altlogline;
/* Prepend this path to all emitted content, if behind path appending frontend */
char *prepend_path;
};
struct http_header *parse_headers(char *const *headers, size_t start, size_t end);
void add_header(struct http_header **hdrlist, const char *name, const char *value);
void delete_header(struct http_header **hdrlist, const char *name);
struct http_header *find_header(struct http_header *hdrlist, const char *name);
char *find_header_value(struct http_header *hdrlist, const char *name);
size_t headers_fmtstr_parse(struct http_header *hdrlist, char *line, size_t szline, const char *rpl);
struct http_arg *parse_args(const char *args);
struct http_arg *find_arg(struct http_arg *args, const char *name);
char *find_arg_value(struct http_arg *args, const char *name);
size_t args_fmtstr_parse(struct http_arg *args, char *line, size_t szline, const char *rpl);
void write_log_line(struct client_state *clstate);
void run_client(struct client_info *clinfo);
#endif