Blame


1 f224a3fe 2021-08-24 xhr /*
2 f224a3fe 2021-08-24 xhr * Copyright (c) 2021 Matthias Schmidt <xhr@giessen.ccc.de>
3 f224a3fe 2021-08-24 xhr *
4 f224a3fe 2021-08-24 xhr * Permission to use, copy, modify, and distribute this software for any
5 f224a3fe 2021-08-24 xhr * purpose with or without fee is hereby granted, provided that the above
6 f224a3fe 2021-08-24 xhr * copyright notice and this permission notice appear in all copies.
7 f224a3fe 2021-08-24 xhr *
8 f224a3fe 2021-08-24 xhr * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 f224a3fe 2021-08-24 xhr * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 f224a3fe 2021-08-24 xhr * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 f224a3fe 2021-08-24 xhr * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 f224a3fe 2021-08-24 xhr * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 f224a3fe 2021-08-24 xhr * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 f224a3fe 2021-08-24 xhr * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 f224a3fe 2021-08-24 xhr */
16 f224a3fe 2021-08-24 xhr
17 f224a3fe 2021-08-24 xhr #ifndef _TWIND_H
18 f224a3fe 2021-08-24 xhr #define _TWIND_H
19 f224a3fe 2021-08-24 xhr
20 f224a3fe 2021-08-24 xhr #include <netinet/in.h>
21 f224a3fe 2021-08-24 xhr
22 f224a3fe 2021-08-24 xhr #include <openssl/ssl.h>
23 f224a3fe 2021-08-24 xhr
24 75e29feb 2021-08-26 xhr #include <signal.h>
25 75e29feb 2021-08-26 xhr
26 f224a3fe 2021-08-24 xhr #define VERSION "2021.a"
27 f224a3fe 2021-08-24 xhr #define MAXREQLEN 1025
28 f224a3fe 2021-08-24 xhr #define _PATH_TWIND_ACCESS_LOG "logs/access.log"
29 f224a3fe 2021-08-24 xhr #define _PATH_TWIND_ERROR_LOG "logs/error.log"
30 f224a3fe 2021-08-24 xhr
31 f224a3fe 2021-08-24 xhr enum status_codes {
32 f224a3fe 2021-08-24 xhr STATUS_INPUT = 10,
33 f224a3fe 2021-08-24 xhr STATUS_SENSITIVE_INPUT = 11,
34 f224a3fe 2021-08-24 xhr STATUS_SUCCESS = 20,
35 f224a3fe 2021-08-24 xhr STATUS_REDIRECT_TEMP = 30,
36 f224a3fe 2021-08-24 xhr STATUS_REDIRECT_PERM = 31,
37 f224a3fe 2021-08-24 xhr STATUS_TEMP_UNAVAILABLE = 40,
38 f224a3fe 2021-08-24 xhr STATUS_SERVER_UNAVAILABLE = 41,
39 f224a3fe 2021-08-24 xhr STATUS_CGI_ERROR = 42,
40 f224a3fe 2021-08-24 xhr STATUS_PROXY_ERROR = 43,
41 f224a3fe 2021-08-24 xhr STATUS_SLOW_DOWN = 44,
42 f224a3fe 2021-08-24 xhr STATUS_PERM_FAILURE = 50,
43 f224a3fe 2021-08-24 xhr STATUS_NOT_FOUND = 51,
44 f224a3fe 2021-08-24 xhr STATUS_GONE = 52,
45 f224a3fe 2021-08-24 xhr STATUS_PROXY_REQUEST_REFUSED = 53,
46 f224a3fe 2021-08-24 xhr STATUS_BAD_REQUEST = 59,
47 f224a3fe 2021-08-24 xhr STATUS_CLIENT_CERT_REQUIRED = 60,
48 f224a3fe 2021-08-24 xhr STATUS_CERT_NOT_AUTHORIZED = 61,
49 f224a3fe 2021-08-24 xhr STATUS_CERT_NOT_VALID = 62,
50 f224a3fe 2021-08-24 xhr };
51 f224a3fe 2021-08-24 xhr
52 f224a3fe 2021-08-24 xhr struct client_connection {
53 f224a3fe 2021-08-24 xhr SSL *ssl_peer;
54 f224a3fe 2021-08-24 xhr char client_addr[INET6_ADDRSTRLEN];
55 f224a3fe 2021-08-24 xhr };
56 f224a3fe 2021-08-24 xhr
57 75e29feb 2021-08-26 xhr static volatile sig_atomic_t reload_log_files = 0;
58 75e29feb 2021-08-26 xhr
59 f224a3fe 2021-08-24 xhr /* gemini.c */
60 f224a3fe 2021-08-24 xhr int check_gemini_file(const char *);
61 f224a3fe 2021-08-24 xhr int send_response(SSL*, int, const char *, const char *);
62 f224a3fe 2021-08-24 xhr int send_non_success_response(SSL*, int);
63 f224a3fe 2021-08-24 xhr
64 f224a3fe 2021-08-24 xhr /* request.c */
65 f224a3fe 2021-08-24 xhr int get_path_from_request(char *, char *);
66 f224a3fe 2021-08-24 xhr
67 f224a3fe 2021-08-24 xhr /* mime.c */
68 f224a3fe 2021-08-24 xhr char* get_file_extension(const char*);
69 f224a3fe 2021-08-24 xhr char* get_mime_type(const char *);
70 f224a3fe 2021-08-24 xhr
71 f224a3fe 2021-08-24 xhr /* util.c */
72 f224a3fe 2021-08-24 xhr void* xmalloc(size_t);
73 f224a3fe 2021-08-24 xhr char* xstrdup(const char *);
74 f224a3fe 2021-08-24 xhr size_t strlcpy(char *, const char *, size_t);
75 f224a3fe 2021-08-24 xhr
76 f224a3fe 2021-08-24 xhr /* log.c */
77 f224a3fe 2021-08-24 xhr void open_twind_logs(void);
78 f224a3fe 2021-08-24 xhr void close_twind_logs(void);
79 f224a3fe 2021-08-24 xhr void log_access(const struct client_connection *, const char *, ...);
80 f224a3fe 2021-08-24 xhr void log_error(const struct client_connection *, const char *, ...);
81 f224a3fe 2021-08-24 xhr void user_log(int, const char *, ...);
82 f224a3fe 2021-08-24 xhr
83 f224a3fe 2021-08-24 xhr #endif