diff options
author | the xhr <xhr@giessen.ccc.de> | 2021-08-24 21:22:29 +0200 |
---|---|---|
committer | the xhr <xhr@giessen.ccc.de> | 2021-08-24 21:22:29 +0200 |
commit | f224a3fe688bf2ae4c108d6b4359df4d8f03db99 (patch) | |
tree | 1d9d6fdce5671be7ae5754f51c6ef5b47bf7f0c1 /twind.h | |
parent | 0f9f2d04f9c340c761a9c900fac1c225b5a05419 (diff) |
Initial commit of twind - a small and simple gemini daemon
Diffstat (limited to 'twind.h')
-rw-r--r-- | twind.h | 79 |
1 files changed, 79 insertions, 0 deletions
@@ -0,0 +1,79 @@ +/* + * Copyright (c) 2021 Matthias Schmidt <xhr@giessen.ccc.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _TWIND_H +#define _TWIND_H + +#include <netinet/in.h> + +#include <openssl/ssl.h> + +#define VERSION "2021.a" +#define MAXREQLEN 1025 +#define _PATH_TWIND_ACCESS_LOG "logs/access.log" +#define _PATH_TWIND_ERROR_LOG "logs/error.log" + +enum status_codes { + STATUS_INPUT = 10, + STATUS_SENSITIVE_INPUT = 11, + STATUS_SUCCESS = 20, + STATUS_REDIRECT_TEMP = 30, + STATUS_REDIRECT_PERM = 31, + STATUS_TEMP_UNAVAILABLE = 40, + STATUS_SERVER_UNAVAILABLE = 41, + STATUS_CGI_ERROR = 42, + STATUS_PROXY_ERROR = 43, + STATUS_SLOW_DOWN = 44, + STATUS_PERM_FAILURE = 50, + STATUS_NOT_FOUND = 51, + STATUS_GONE = 52, + STATUS_PROXY_REQUEST_REFUSED = 53, + STATUS_BAD_REQUEST = 59, + STATUS_CLIENT_CERT_REQUIRED = 60, + STATUS_CERT_NOT_AUTHORIZED = 61, + STATUS_CERT_NOT_VALID = 62, +}; + +struct client_connection { + SSL *ssl_peer; + char client_addr[INET6_ADDRSTRLEN]; +}; + +/* gemini.c */ +int check_gemini_file(const char *); +int send_response(SSL*, int, const char *, const char *); +int send_non_success_response(SSL*, int); + +/* request.c */ +int get_path_from_request(char *, char *); + +/* mime.c */ +char* get_file_extension(const char*); +char* get_mime_type(const char *); + +/* util.c */ +void* xmalloc(size_t); +char* xstrdup(const char *); +size_t strlcpy(char *, const char *, size_t); + +/* log.c */ +void open_twind_logs(void); +void close_twind_logs(void); +void log_access(const struct client_connection *, const char *, ...); +void log_error(const struct client_connection *, const char *, ...); +void user_log(int, const char *, ...); + +#endif |