#ifndef BOZOHTTPD_H_
#define BOZOHTTPD_H_ 1
#include "netbsd_queue.h"
#include <stdbool.h>
#include <stdio.h>
#include <signal.h>
#include <sys/stat.h>
#ifndef NO_LUA_SUPPORT
#include <lua.h>
#endif
#ifndef NO_BLOCKLIST_SUPPORT
#include <blocklist.h>
void pfilter_notify(const int, const int);
#endif
#ifdef HAVE_NBUTIL_H
#include <nbutil.h>
#endif
typedef struct bozoheaders {
char *h_header;
char *h_value;
SIMPLEQ_ENTRY(bozoheaders) h_next;
} bozoheaders_t;
SIMPLEQ_HEAD(qheaders, bozoheaders);
#ifndef NO_LUA_SUPPORT
typedef struct lua_handler {
const char *name;
int ref;
SIMPLEQ_ENTRY(lua_handler) h_next;
} lua_handler_t;
typedef struct lua_state_map {
const char *script;
const char *prefix;
lua_State *L;
SIMPLEQ_HEAD(, lua_handler) handlers;
SIMPLEQ_ENTRY(lua_state_map) s_next;
} lua_state_map_t;
#endif
typedef struct bozo_content_map_t {
const char *name;
const char *type;
const char *encoding;
const char *encoding11;
const char *cgihandler;
} bozo_content_map_t;
typedef struct bozo_consts_t {
const char *http_09;
const char *http_10;
const char *http_11;
const char *text_plain;
} bozo_consts_t;
typedef struct bozohttpd_t {
char *rootdir;
int numeric;
char *virtbase;
int unknown_slash;
int logstderr;
int nolog;
int background;
int foreground;
char *pidfile;
size_t page_size;
char *slashdir;
const char *defbindport;
char *bindport;
char *bindaddress;
int debug;
char *virthostname;
const char *server_software;
const char *index_html;
const char *public_html;
int enable_users;
int enable_cgi_users;
int *sock;
int nsock;
struct pollfd *fds;
int request_times;
int dir_indexing;
const char *dir_readme;
int hide_dots;
int process_cgi;
char *cgibin;
unsigned ssl_timeout;
unsigned initial_timeout;
unsigned header_timeout;
unsigned request_timeout;
char *ssl_min_proto;
#ifndef NO_LUA_SUPPORT
int process_lua;
SIMPLEQ_HEAD(, lua_state_map) lua_states;
#endif
void *sslinfo;
int dynamic_content_map_size;
bozo_content_map_t *dynamic_content_map;
size_t mmapsz;
char *getln_buffer;
ssize_t getln_buflen;
char *errorbuf;
bozo_consts_t consts;
} bozohttpd_t;
typedef struct bozo_httpreq_t {
bozohttpd_t *hr_httpd;
int hr_method;
#define HTTP_GET 0x01
#define HTTP_POST 0x02
#define HTTP_HEAD 0x03
#define HTTP_OPTIONS 0x04
#define HTTP_PUT 0x05
#define HTTP_DELETE 0x06
#define HTTP_TRACE 0x07
#define HTTP_CONNECT 0x08
const char *hr_methodstr;
char *hr_virthostname;
char *hr_file_free;
char *hr_file;
char *hr_oldfile;
char *hr_query;
char *hr_host;
#ifndef NO_USER_SUPPORT
char *hr_user;
#endif
const char *hr_proto;
const char *hr_content_type;
const char *hr_content_length;
const char *hr_allow;
const char *hr_referrer;
const char *hr_range;
const char *hr_if_modified_since;
const char *hr_accept_encoding;
int hr_have_range;
off_t hr_first_byte_pos;
off_t hr_last_byte_pos;
char *hr_remotehost;
char *hr_remoteaddr;
char *hr_serverport;
#ifdef DO_HTPASSWD
char *hr_authrealm;
char *hr_authuser;
char *hr_authpass;
#endif
struct qheaders hr_headers;
struct qheaders hr_replheaders;
unsigned hr_nheaders;
size_t hr_header_bytes;
} bozo_httpreq_t;
#define BOZOHOST(HTTPD,REQUEST) ((REQUEST)->hr_virthostname ? \
(REQUEST)->hr_virthostname : \
(HTTPD)->virthostname)
typedef struct bozoprefs_t {
size_t size;
size_t count;
char **name;
char **value;
} bozoprefs_t;
#ifdef __mc68010__
#ifndef BOZO_WRSZ
#define BOZO_WRSZ (16 * 1024)
#endif
#ifndef BOZO_MMAPSZ
#define BOZO_MMAPSZ (BOZO_WRSZ * 4)
#endif
#endif
#ifndef BOZO_WRSZ
#define BOZO_WRSZ (64 * 1024)
#endif
#ifndef BOZO_MMAPSZ
#define BOZO_MMAPSZ (BOZO_WRSZ * 1024)
#endif
#define BOZO_HEADERS_MAX_SIZE (16 * 1024)
#define BOZO_MINBUFSIZE (4 * 1024)
#define DEBUG_NORMAL 1
#define DEBUG_FAT 2
#define DEBUG_OBESE 3
#define DEBUG_EXPLODING 4
#define strornull(x) ((x) ? (x) : "<null>")
#if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__lint__)
#define BOZO_PRINTFLIKE(x,y) __attribute__((__format__(__printf__, x,y)))
#define BOZO_DEAD __attribute__((__noreturn__))
#define BOZO_CHECKRET __attribute__((__warn_unused_result__))
#else
#define BOZO_PRINTFLIKE(x,y)
#define BOZO_DEAD
#define BOZO_CHECKRET
#endif
#ifdef NO_DEBUG
#define debug(x)
#define have_debug (0)
#else
void debug__(bozohttpd_t *, int, const char *, ...) BOZO_PRINTFLIKE(3, 4);
#define debug(x) debug__ x
#define have_debug (1)
#endif
#define BOZO_HTTP_PORT "80"
#define BOZO_HTTPS_PORT "443"
#ifndef REDIRECT_FILE
#define REDIRECT_FILE ".bzredirect"
#endif
#ifndef ABSREDIRECT_FILE
#define ABSREDIRECT_FILE ".bzabsredirect"
#endif
#ifndef REMAP_FILE
#define REMAP_FILE ".bzremap"
#endif
#ifndef AUTH_FILE
#define AUTH_FILE ".htpasswd"
#endif
int bozo_http_error(bozohttpd_t *, int, bozo_httpreq_t *, const char *);
int bozo_check_special_files(bozo_httpreq_t *, const char *, bool) BOZO_CHECKRET;
char *bozo_http_date(char *, size_t);
void bozo_print_header(bozo_httpreq_t *, struct stat *, const char *,
const char *);
char *bozo_escape_rfc3986(bozohttpd_t *httpd, const char *url, int absolute);
char *bozo_escape_html(bozohttpd_t *httpd, const char *url);
int bozo_decode_url_percent(bozo_httpreq_t *, char *);
void bozowarn(bozohttpd_t *, const char *, ...)
BOZO_PRINTFLIKE(2, 3);
void bozoerr(bozohttpd_t *, int, const char *, ...)
BOZO_PRINTFLIKE(3, 4)
BOZO_DEAD;
void bozoasprintf(bozohttpd_t *, char **, const char *, ...)
BOZO_PRINTFLIKE(3, 4);
char *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *,
int, void *, size_t));
char *bozostrnsep(char **, const char *, ssize_t *);
void *bozomalloc(bozohttpd_t *, size_t);
void *bozorealloc(bozohttpd_t *, void *, size_t);
char *bozostrdup(bozohttpd_t *, bozo_httpreq_t *, const char *);
#define bozo_noop do { } while (0)
#define have_core (1)
#ifdef NO_SSL_SUPPORT
#define bozo_ssl_set_opts(w, x, y) bozo_noop
#define bozo_ssl_set_ciphers(w, x) bozo_noop
#define bozo_ssl_init(x) bozo_noop
#define bozo_ssl_accept(x) (0)
#define bozo_ssl_shutdown(x) bozo_noop
#define bozo_ssl_destroy(x) bozo_noop
#define have_ssl (0)
#else
void bozo_ssl_set_opts(bozohttpd_t *, const char *, const char *);
void bozo_ssl_set_ciphers(bozohttpd_t *, const char *);
void bozo_ssl_init(bozohttpd_t *);
int bozo_ssl_accept(bozohttpd_t *);
void bozo_ssl_shutdown(bozohttpd_t *);
void bozo_ssl_destroy(bozohttpd_t *);
#define have_ssl (1)
#endif
#ifdef DO_HTPASSWD
void bozo_auth_init(bozo_httpreq_t *);
int bozo_auth_check(bozo_httpreq_t *, const char *);
void bozo_auth_cleanup(bozo_httpreq_t *);
int bozo_auth_check_headers(bozo_httpreq_t *, char *, char *, ssize_t);
void bozo_auth_check_401(bozo_httpreq_t *, int);
void bozo_auth_cgi_setenv(bozo_httpreq_t *, char ***);
int bozo_auth_cgi_count(bozo_httpreq_t *);
#else
#define bozo_auth_init(x) bozo_noop
#define bozo_auth_check(x, y) (0)
#define bozo_auth_cleanup(x) bozo_noop
#define bozo_auth_check_headers(y, z, a, b) (0)
#define bozo_auth_check_401(x, y) bozo_noop
#define bozo_auth_cgi_setenv(x, y) bozo_noop
#define bozo_auth_cgi_count(x) (0)
#endif
#ifdef NO_CGIBIN_SUPPORT
#define bozo_cgi_setbin(h,s) bozo_noop
#define bozo_process_cgi(h) (0)
#define have_cgibin (0)
#else
void bozo_cgi_setbin(bozohttpd_t *, const char *);
void bozo_setenv(bozohttpd_t *, const char *, const char *, char **);
int bozo_process_cgi(bozo_httpreq_t *);
#define have_cgibin (1)
#endif
#ifdef NO_LUA_SUPPORT
#define bozo_process_lua(h) (0)
#define bozo_add_lua_map(h,s,t) bozo_noop
#define have_lua (0)
#else
void bozo_add_lua_map(bozohttpd_t *, const char *, const char *);
int bozo_process_lua(bozo_httpreq_t *);
#define have_lua (1)
#endif
#ifdef NO_DAEMON_MODE
#define bozo_daemon_init(x) bozo_noop
#define bozo_daemon_fork(x) (0)
#define bozo_daemon_closefds(x) bozo_noop
#define have_daemon_mode (0)
#else
void bozo_daemon_init(bozohttpd_t *);
int bozo_daemon_fork(bozohttpd_t *);
void bozo_daemon_closefds(bozohttpd_t *);
#define have_daemon_mode (1)
#endif
#ifdef NO_USER_SUPPORT
#define bozo_user_transform(x) (0)
#define bozo_user_free(x)
#define have_user (0)
#else
int bozo_user_transform(bozo_httpreq_t *);
#define bozo_user_free(x) free(x)
#define have_user (1)
#endif
#ifdef NO_DIRINDEX_SUPPORT
#define bozo_dir_index(a, b, c) (0)
#define have_dirindex (0)
#else
int bozo_dir_index(bozo_httpreq_t *, const char *, int);
#define have_dirindex (1)
#endif
const char *bozo_content_type(bozo_httpreq_t *, const char *);
const char *bozo_content_encoding(bozo_httpreq_t *, const char *);
bozo_content_map_t *bozo_match_content_map(bozohttpd_t *, const char *, int);
bozo_content_map_t *bozo_get_content_map(bozohttpd_t *, const char *);
#ifdef NO_DYNAMIC_CONTENT
#define bozo_add_content_map_mime(h,s,t,u,v) bozo_noop
#define have_dynamic_content (0)
#else
void bozo_add_content_map_mime(bozohttpd_t *, const char *, const char *,
const char *, const char *);
#define have_dynamic_content (1)
#endif
#if have_cgibin && have_dynamic_content
void bozo_add_content_map_cgi(bozohttpd_t *, const char *, const char *);
#else
#define bozo_add_content_map_cgi(h,s,t)
#endif
int bozo_printf(bozohttpd_t *, const char *, ...) BOZO_PRINTFLIKE(2, 3);
ssize_t bozo_read(bozohttpd_t *, int, void *, size_t);
ssize_t bozo_write(bozohttpd_t *, int, const void *, size_t);
int bozo_flush(bozohttpd_t *, FILE *);
int bozo_init_httpd(bozohttpd_t *);
int bozo_init_prefs(bozohttpd_t *, bozoprefs_t *);
int bozo_set_defaults(bozohttpd_t *, bozoprefs_t *);
int bozo_setup(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
void bozo_cleanup(bozohttpd_t *, bozoprefs_t *);
bozo_httpreq_t *bozo_read_request(bozohttpd_t *);
void bozo_process_request(bozo_httpreq_t *);
void bozo_clean_request(bozo_httpreq_t *);
int bozo_set_timeout(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
bozoheaders_t *addmerge_reqheader(bozo_httpreq_t *, const char *,
const char *, ssize_t);
bozoheaders_t *addmerge_replheader(bozo_httpreq_t *, const char *,
const char *, ssize_t);
int bozo_set_pref(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
char *bozo_get_pref(bozoprefs_t *, const char *);
int bozo_get_version(char *, size_t );
extern volatile sig_atomic_t bozo_timeout_hit;
#endif