1 /* mohawk - small HTTP server 2 ** 3 ** Copyright © 2010 by Baptiste Daroussin <bapt@FreeBSD.org>, 4 ** Copyright © 2010 by Freddy Dissaux <freddy.dsx@free.fr>, 5 ** All rights reserved. 6 ** 7 ** Redistribution and use in source and binary forms, with or without 8 ** modification, are permitted provided that the following conditions 9 ** are met: 10 ** 1. Redistributions of source code must retain the above copyright 11 ** notice, this list of conditions and the following disclaimer. 12 ** 2. Redistributions in binary form must reproduce the above copyright 13 ** notice, this list of conditions and the following disclaimer in the 14 ** documentation and/or other materials provided with the distribution. 15 ** 16 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 ** SUCH DAMAGE. 27 */ 28 29 #ifndef _MOHAWK_H 30 #define _MOHAWK_H 31 32 #ifndef MOHAWK_VERSION 33 #error "MOHAWK_VERSION not defined" 34 #endif 35 36 #include <sys/queue.h> 37 #include <sys/types.h> 38 39 #include <netinet/in.h> 40 41 #if defined(__FreeBSD__) || defined(__DragonFly__) 42 #include <libutil.h> 43 #endif 44 #if defined(__NetBSD__) 45 #include <util.h> 46 #endif 47 48 #include <event2/util.h> /* for evutil_socket_t */ 49 50 #if defined(__OpenBSD__) 51 #include "compat.h" 52 #endif 53 54 #ifndef DEFAULT_AUTH_FILE 55 #define DEFAULT_AUTH_FILE ".htpasswd" 56 #endif /* DEFAULT_AUTH_FILE */ 57 58 #ifndef DEFAULT_HTTP_PORT 59 #define DEFAULT_HTTP_PORT "80" 60 #endif /* DEFAULT_HTTP_PORT */ 61 62 #ifndef DEFAULT_LISTEN 63 #define DEFAULT_LISTEN "localhost" 64 #endif /* DEFAULT_LISTEN */ 65 66 #ifndef DEFAULT_PIDFILE 67 #if defined(__OpenBSD__) 68 #define DEFAULT_PIDFILE "mohawk" 69 #else 70 #define DEFAULT_PIDFILE "/var/run/mohawk.pid" 71 #endif 72 #endif /* DEFAULT_PIDFILE */ 73 74 #ifndef DEFAULT_ROOTDIR 75 #define DEFAULT_ROOTDIR "/tmp" 76 #endif /* DEFAULT_ROOTDIR */ 77 78 #ifndef DEFAULT_SYSLOG_FACILITY 79 #define DEFAULT_SYSLOG_FACILITY "daemon" 80 #endif /* DEFAULT_SYSLOG_FACILITY */ 81 82 #ifndef DEFAULT_USER 83 #if defined(__OpenBSD__) 84 #define DEFAULT_USER "_mohawk" 85 #else 86 #define DEFAULT_USER "nobody" 87 #endif 88 #endif /* DEFAULT_USER */ 89 90 #ifndef IPPORT_MAX 91 #define IPPORT_MAX 65535 92 #endif 93 94 struct mohawk_list { 95 char *item; 96 SLIST_ENTRY(mohawk_list) entry; 97 }; 98 99 struct mohawk_hash { 100 char *key; 101 char *value; 102 SLIST_ENTRY(mohawk_hash) entry; 103 }; 104 105 struct mohawk_address_info { 106 struct addrinfo *ai; 107 SLIST_ENTRY(mohawk_address_info) entry; 108 }; 109 110 struct mohawk_network_inet { 111 uint32_t prefix; 112 uint32_t mask; 113 int not; 114 }; 115 116 struct mohawk_network_inet6 { 117 uint8_t prefix[16]; 118 uint8_t mask[16]; 119 int not; 120 }; 121 122 struct mohawk_network { 123 const char *item; 124 int family; 125 void *network; 126 SLIST_ENTRY(mohawk_network) entry; 127 }; 128 129 struct vhost { 130 SLIST_HEAD(, mohawk_list) auth_patterns; 131 SLIST_HEAD(, mohawk_list) blacklist_patterns; 132 SLIST_HEAD(, mohawk_list) cgi_patterns; 133 SLIST_HEAD(, mohawk_list) index_names; 134 SLIST_HEAD(, mohawk_list) no_auth_patterns; 135 SLIST_HEAD(, mohawk_list) no_cgi_maps; 136 SLIST_HEAD(, mohawk_list) no_log_patterns; 137 SLIST_HEAD(, mohawk_hash) cgi_env; 138 SLIST_HEAD(, mohawk_hash) cgi_map; 139 SLIST_HEAD(, mohawk_address_info) address_infos; 140 SLIST_HEAD(, mohawk_network) grant_access; 141 SLIST_HEAD(, vhost) locations; 142 const char *email_admin; 143 const char *auth_path; 144 const char *charset; 145 const char *dirlist_css_url; 146 const char *host; 147 const char *location; 148 const char *mohawk_name; 149 const char *rootdir; 150 const char *status_url; 151 int authentication; 152 int auth_blacklistd; 153 int can_quick; 154 int cgi_env_count; 155 int cgi_expose_mohawk_version; 156 int dirlist; 157 int hostname_in_rootdir; 158 int maxage; 159 int x_forwarded_for; 160 SLIST_ENTRY(vhost) entry; 161 }; 162 163 struct callback_data { 164 struct vhost *vh; 165 struct evhttp *httpd; 166 char *host; 167 char *service; 168 int port; 169 SLIST_ENTRY(callback_data) entry; 170 }; 171 172 struct mohawk_conf { 173 SLIST_HEAD(, mohawk_hash) mime_type; 174 SLIST_HEAD(, vhost) vhosts; 175 SLIST_HEAD(, callback_data) cb_datas; 176 struct vhost *default_vhost; 177 struct pidfh *pfh; 178 char *chroot; 179 const char *pidfile; 180 const char *user; 181 const char *syslog_facility; 182 int debug; 183 int blacklistd; 184 }; 185 186 extern struct mohawk_conf conf; 187 188 void parse_command_line(const char *, const char *, const char *); 189 void parse_config(const char *); 190 int host(const char *host, const char *service); 191 int parse_number(const char *, int, int); 192 const char *facility_lookup(const char *, int *); 193 194 #endif 195 /* vim: set sw=4 sts=4 ts=4 : */ 196