Blob


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