[BACK]Return to bozohttpd.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / libexec / httpd

Annotation of src/libexec/httpd/bozohttpd.h, Revision 1.46.2.1

1.46.2.1! pgoyette    1: /*     $NetBSD: bozohttpd.h,v 1.47 2017/01/31 14:36:09 mrg Exp $       */
1.3       tls         2:
1.20      mrg         3: /*     $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $       */
1.1       tls         4:
                      5: /*
1.46.2.1! pgoyette    6:  * Copyright (c) 1997-2017 Matthew R. Green
1.1       tls         7:  * All rights reserved.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer and
                     16:  *    dedication in the documentation and/or other materials provided
                     17:  *    with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     20:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     21:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     22:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     23:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
                     24:  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
                     25:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
                     26:  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
                     27:  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  *
                     31:  */
1.12      mrg        32: #ifndef BOZOHTTOPD_H_
                     33: #define BOZOHTTOPD_H_  1
                     34:
1.27      mrg        35: #include "netbsd_queue.h"
1.12      mrg        36:
1.1       tls        37: #include <sys/stat.h>
1.5       mrg        38:
1.30      mbalmer    39: #ifndef NO_LUA_SUPPORT
                     40: #include <lua.h>
                     41: #endif
1.1       tls        42: #include <stdio.h>
                     43:
1.36      mrg        44: /* QNX provides a lot of NetBSD things in nbutil.h */
1.37      mrg        45: #ifdef HAVE_NBUTIL_H
1.36      mrg        46: #include <nbutil.h>
                     47: #endif
                     48:
1.8       mrg        49: /* lots of "const" but gets free()'ed etc at times, sigh */
                     50:
1.1       tls        51: /* headers */
1.12      mrg        52: typedef struct bozoheaders {
1.4       rtr        53:        /*const*/ char *h_header;
1.1       tls        54:        /*const*/ char *h_value;        /* this gets free()'ed etc at times */
1.12      mrg        55:        SIMPLEQ_ENTRY(bozoheaders)      h_next;
                     56: } bozoheaders_t;
1.44      elric      57: SIMPLEQ_HEAD(qheaders, bozoheaders);
1.1       tls        58:
1.30      mbalmer    59: #ifndef NO_LUA_SUPPORT
                     60: typedef struct lua_handler {
                     61:        const char      *name;
                     62:        int              ref;
                     63:        SIMPLEQ_ENTRY(lua_handler)      h_next;
                     64: } lua_handler_t;
                     65:
                     66: typedef struct lua_state_map {
                     67:        const char      *script;
                     68:        const char      *prefix;
                     69:        lua_State       *L;
                     70:        SIMPLEQ_HEAD(, lua_handler)     handlers;
                     71:        SIMPLEQ_ENTRY(lua_state_map)    s_next;
                     72: } lua_state_map_t;
                     73: #endif
                     74:
1.12      mrg        75: typedef struct bozo_content_map_t {
                     76:        const char      *name;          /* postfix of file */
                     77:        const char      *type;          /* matching content-type */
                     78:        const char      *encoding;      /* matching content-encoding */
                     79:        const char      *encoding11;    /* matching content-encoding (HTTP/1.1) */
                     80:        const char      *cgihandler;    /* optional CGI handler */
                     81: } bozo_content_map_t;
                     82:
                     83: /* this struct holds the bozo constants */
                     84: typedef struct bozo_consts_t {
                     85:        const char      *http_09;       /* "HTTP/0.9" */
                     86:        const char      *http_10;       /* "HTTP/1.0" */
                     87:        const char      *http_11;       /* "HTTP/1.1" */
                     88:        const char      *text_plain;    /* "text/plain" */
                     89: } bozo_consts_t;
                     90:
                     91: /* this structure encapsulates all the bozo flags and control vars */
                     92: typedef struct bozohttpd_t {
                     93:        char            *rootdir;       /* root directory */
                     94:        int              numeric;       /* avoid gethostby*() */
                     95:        char            *virtbase;      /* virtual directory base */
                     96:        int              unknown_slash; /* unknown vhosts go to normal slashdir */
                     97:        int              logstderr;     /* log to stderr (even if not tty) */
                     98:        int              background;    /* drop into daemon mode */
                     99:        int              foreground;    /* keep daemon mode in foreground */
1.18      jmmv      100:        char            *pidfile;       /* path to the pid file, if any */
1.12      mrg       101:        size_t           page_size;     /* page size */
                    102:        char            *slashdir;      /* www slash directory */
                    103:        char            *bindport;      /* bind port; default "http" */
                    104:        char            *bindaddress;   /* address for binding - INADDR_ANY */
                    105:        int              debug;         /* debugging level */
                    106:        char            *virthostname;  /* my name */
                    107:        const char      *server_software;/* our brand :-) */
                    108:        const char      *index_html;    /* our home page */
                    109:        const char      *public_html;   /* ~user/public_html page */
                    110:        int              enable_users;  /* enable public_html */
1.38      shm       111:        int              enable_cgi_users;      /* use the cgi handler */
1.12      mrg       112:        int             *sock;          /* bound sockets */
                    113:        int              nsock;         /* number of above */
                    114:        struct pollfd   *fds;           /* current poll fd set */
                    115:        int              request_times; /* # times a request was processed */
                    116:        int              dir_indexing;  /* handle directories */
                    117:        int              hide_dots;     /* hide .* */
                    118:        int              process_cgi;   /* use the cgi handler */
                    119:        char            *cgibin;        /* cgi-bin directory */
1.30      mbalmer   120: #ifndef NO_LUA_SUPPORT
                    121:        int              process_lua;   /* use the Lua handler */
                    122:        SIMPLEQ_HEAD(, lua_state_map)   lua_states;
                    123: #endif
1.12      mrg       124:        void            *sslinfo;       /* pointer to ssl struct */
                    125:        int             dynamic_content_map_size;/* size of dyn cont map */
                    126:        bozo_content_map_t      *dynamic_content_map;/* dynamic content map */
                    127:        size_t           mmapsz;        /* size of region to mmap */
                    128:        char            *getln_buffer;  /* space for getln buffer */
                    129:        ssize_t          getln_buflen;  /* length of allocated space */
                    130:        char            *errorbuf;      /* no dynamic allocation allowed */
                    131:        bozo_consts_t    consts;        /* various constants */
                    132: } bozohttpd_t;
                    133:
                    134: /* bozo_httpreq_t */
                    135: typedef struct bozo_httpreq_t {
                    136:        bozohttpd_t     *hr_httpd;
                    137:        int             hr_method;
1.1       tls       138: #define        HTTP_GET        0x01
                    139: #define HTTP_POST      0x02
                    140: #define HTTP_HEAD      0x03
                    141: #define HTTP_OPTIONS   0x04    /* not supported */
                    142: #define HTTP_PUT       0x05    /* not supported */
                    143: #define HTTP_DELETE    0x06    /* not supported */
                    144: #define HTTP_TRACE     0x07    /* not supported */
                    145: #define HTTP_CONNECT   0x08    /* not supported */
                    146:        const char *hr_methodstr;
1.24      martin    147:        char    *hr_virthostname;       /* server name (if not identical
                    148:                                           to hr_httpd->virthostname) */
1.8       mrg       149:        char    *hr_file;
1.14      mrg       150:        char    *hr_oldfile;    /* if we added an index_html */
1.29      mbalmer   151:        char    *hr_query;
1.32      mrg       152:        char    *hr_host;       /* HTTP/1.1 Host: or virtual hostname,
                    153:                                   possibly including a port number */
1.38      shm       154: #ifndef NO_USER_SUPPORT
                    155:        char    *hr_user;       /* username if we hit userdir request */
                    156: #endif /* !NO_USER_SUPPORT */
1.1       tls       157:        const char *hr_proto;
                    158:        const char *hr_content_type;
                    159:        const char *hr_content_length;
                    160:        const char *hr_allow;
                    161:        const char *hr_referrer;
1.5       mrg       162:        const char *hr_range;
1.7       joerg     163:        const char *hr_if_modified_since;
1.21      elric     164:        const char *hr_accept_encoding;
1.5       mrg       165:        int         hr_have_range;
                    166:        off_t       hr_first_byte_pos;
                    167:        off_t       hr_last_byte_pos;
1.8       mrg       168:        /*const*/ char *hr_remotehost;
                    169:        /*const*/ char *hr_remoteaddr;
                    170:        /*const*/ char *hr_serverport;
1.1       tls       171: #ifdef DO_HTPASSWD
1.9       mrg       172:        /*const*/ char *hr_authrealm;
                    173:        /*const*/ char *hr_authuser;
                    174:        /*const*/ char *hr_authpass;
1.1       tls       175: #endif
1.44      elric     176:        struct qheaders         hr_headers;
                    177:        struct qheaders         hr_replheaders;
                    178:        int                     hr_nheaders;
1.12      mrg       179: } bozo_httpreq_t;
1.1       tls       180:
1.24      martin    181: /* helper to access the "active" host name from a httpd/request pair */
                    182: #define        BOZOHOST(HTTPD,REQUEST) ((REQUEST)->hr_virthostname ?           \
                    183:                                        (REQUEST)->hr_virthostname :    \
                    184:                                        (HTTPD)->virthostname)
                    185:
1.12      mrg       186: /* structure to hold string based (name, value) pairs with preferences */
                    187: typedef struct bozoprefs_t {
1.41      mrg       188:        size_t            size;         /* size of the two arrays */
                    189:        size_t            count;        /* # of entries in arrays */
1.12      mrg       190:        char            **name;         /* names of each entry */
                    191:        char            **value;        /* values for the name entries */
                    192: } bozoprefs_t;
1.1       tls       193:
1.28      pooka     194: /* by default write in upto 64KiB chunks, and mmap in upto 64MiB chunks */
                    195: #ifndef BOZO_WRSZ
1.12      mrg       196: #define BOZO_WRSZ      (64 * 1024)
1.28      pooka     197: #endif
                    198: #ifndef BOZO_MMAPSZ
1.12      mrg       199: #define BOZO_MMAPSZ    (BOZO_WRSZ * 1024)
1.28      pooka     200: #endif
1.1       tls       201:
                    202: /* debug flags */
                    203: #define DEBUG_NORMAL   1
                    204: #define DEBUG_FAT      2
                    205: #define DEBUG_OBESE    3
                    206: #define DEBUG_EXPLODING        4
                    207:
                    208: #define        strornull(x)    ((x) ? (x) : "<null>")
                    209:
1.22      joerg     210: #if defined(__GNUC__) && __GNUC__ >= 3
                    211: #define BOZO_PRINTFLIKE(x,y) __attribute__((__format__(__printf__, x,y)))
                    212: #define BOZO_DEAD __attribute__((__noreturn__))
                    213: #endif
                    214:
1.17      mrg       215: #ifndef NO_DEBUG
1.22      joerg     216: void   debug__(bozohttpd_t *, int, const char *, ...) BOZO_PRINTFLIKE(3, 4);
1.1       tls       217: #define debug(x)       debug__ x
                    218: #else
1.29      mbalmer   219: #define        debug(x)
1.17      mrg       220: #endif /* NO_DEBUG */
1.1       tls       221:
1.14      mrg       222: int    bozo_http_error(bozohttpd_t *, int, bozo_httpreq_t *, const char *);
1.1       tls       223:
1.12      mrg       224: int    bozo_check_special_files(bozo_httpreq_t *, const char *);
                    225: char   *bozo_http_date(char *, size_t);
1.41      mrg       226: void   bozo_print_header(bozo_httpreq_t *, struct stat *, const char *,
                    227:                          const char *);
1.38      shm       228: char   *bozo_escape_rfc3986(bozohttpd_t *httpd, const char *url, int absolute);
1.25      mrg       229: char   *bozo_escape_html(bozohttpd_t *httpd, const char *url);
1.45      mrg       230: int    bozo_decode_url_percent(bozo_httpreq_t *, char *);
1.1       tls       231:
1.42      mrg       232: /* these are similar to libc functions, no underscore here */
                    233: void   bozowarn(bozohttpd_t *, const char *, ...)
                    234:                BOZO_PRINTFLIKE(2, 3);
                    235: void   bozoerr(bozohttpd_t *, int, const char *, ...)
                    236:                BOZO_PRINTFLIKE(3, 4)
                    237:                BOZO_DEAD;
                    238: void   bozoasprintf(bozohttpd_t *, char **, const char *, ...)
                    239:                BOZO_PRINTFLIKE(3, 4);
1.41      mrg       240: char   *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *,
                    241:                    int, void *, size_t));
1.5       mrg       242: char   *bozostrnsep(char **, const char *, ssize_t *);
1.12      mrg       243: void   *bozomalloc(bozohttpd_t *, size_t);
                    244: void   *bozorealloc(bozohttpd_t *, void *, size_t);
1.41      mrg       245: char   *bozostrdup(bozohttpd_t *, bozo_httpreq_t *, const char *);
1.1       tls       246:
1.39      christos  247: #define bozo_noop      do { /* nothing */ } while (/*CONSTCOND*/0)
                    248:
1.1       tls       249: /* ssl-bozo.c */
1.12      mrg       250: #ifdef NO_SSL_SUPPORT
1.39      christos  251: #define bozo_ssl_set_opts(w, x, y)     bozo_noop
                    252: #define bozo_ssl_set_ciphers(w, x, y)  bozo_noop
                    253: #define bozo_ssl_init(x)               bozo_noop
1.33      mrg       254: #define bozo_ssl_accept(x)             (0)
1.39      christos  255: #define bozo_ssl_destroy(x)            bozo_noop
1.12      mrg       256: #else
1.14      mrg       257: void   bozo_ssl_set_opts(bozohttpd_t *, const char *, const char *);
1.39      christos  258: void   bozo_ssl_set_ciphers(bozohttpd_t *, const char *);
1.14      mrg       259: void   bozo_ssl_init(bozohttpd_t *);
1.33      mrg       260: int    bozo_ssl_accept(bozohttpd_t *);
1.14      mrg       261: void   bozo_ssl_destroy(bozohttpd_t *);
1.1       tls       262: #endif
                    263:
                    264:
                    265: /* auth-bozo.c */
                    266: #ifdef DO_HTPASSWD
1.34      shm       267: void   bozo_auth_init(bozo_httpreq_t *);
1.14      mrg       268: int    bozo_auth_check(bozo_httpreq_t *, const char *);
                    269: void   bozo_auth_cleanup(bozo_httpreq_t *);
                    270: int    bozo_auth_check_headers(bozo_httpreq_t *, char *, char *, ssize_t);
                    271: int    bozo_auth_check_special_files(bozo_httpreq_t *, const char *);
                    272: void   bozo_auth_check_401(bozo_httpreq_t *, int);
                    273: void   bozo_auth_cgi_setenv(bozo_httpreq_t *, char ***);
                    274: int    bozo_auth_cgi_count(bozo_httpreq_t *);
1.12      mrg       275: #else
1.39      christos  276: #define        bozo_auth_init(x)                       bozo_noop
1.14      mrg       277: #define        bozo_auth_check(x, y)                   0
1.39      christos  278: #define        bozo_auth_cleanup(x)                    bozo_noop
1.14      mrg       279: #define        bozo_auth_check_headers(y, z, a, b)     0
                    280: #define        bozo_auth_check_special_files(x, y)     0
1.39      christos  281: #define        bozo_auth_check_401(x, y)               bozo_noop
                    282: #define        bozo_auth_cgi_setenv(x, y)              bozo_noop
1.14      mrg       283: #define        bozo_auth_cgi_count(x)                  0
1.1       tls       284: #endif /* DO_HTPASSWD */
                    285:
                    286:
                    287: /* cgi-bozo.c */
1.12      mrg       288: #ifdef NO_CGIBIN_SUPPORT
1.14      mrg       289: #define        bozo_process_cgi(h)                             0
1.1       tls       290: #else
1.14      mrg       291: void   bozo_cgi_setbin(bozohttpd_t *, const char *);
                    292: void   bozo_setenv(bozohttpd_t *, const char *, const char *, char **);
                    293: int    bozo_process_cgi(bozo_httpreq_t *);
                    294: void   bozo_add_content_map_cgi(bozohttpd_t *, const char *, const char *);
1.1       tls       295: #endif /* NO_CGIBIN_SUPPORT */
                    296:
                    297:
1.30      mbalmer   298: /* lua-bozo.c */
                    299: #ifdef NO_LUA_SUPPORT
                    300: #define bozo_process_lua(h)                            0
                    301: #else
                    302: void   bozo_add_lua_map(bozohttpd_t *, const char *, const char *);
                    303: int    bozo_process_lua(bozo_httpreq_t *);
                    304: #endif /* NO_LUA_SUPPORT */
                    305:
                    306:
1.1       tls       307: /* daemon-bozo.c */
1.12      mrg       308: #ifdef NO_DAEMON_MODE
1.39      christos  309: #define bozo_daemon_init(x)                            bozo_noop
1.14      mrg       310: #define bozo_daemon_fork(x)                            0
1.39      christos  311: #define bozo_daemon_closefds(x)                                bozo_noop
1.12      mrg       312: #else
1.14      mrg       313: void   bozo_daemon_init(bozohttpd_t *);
                    314: int    bozo_daemon_fork(bozohttpd_t *);
                    315: void   bozo_daemon_closefds(bozohttpd_t *);
1.1       tls       316: #endif /* NO_DAEMON_MODE */
                    317:
                    318:
                    319: /* tilde-luzah-bozo.c */
1.12      mrg       320: #ifdef NO_USER_SUPPORT
1.38      shm       321: #define bozo_user_transform(x)                         0
                    322: #define bozo_user_free(x)                                      0
1.8       mrg       323: #else
1.38      shm       324: int    bozo_user_transform(bozo_httpreq_t *);
                    325: #define bozo_user_free(x)                                      free(x)
1.1       tls       326: #endif /* NO_USER_SUPPORT */
                    327:
                    328:
                    329: /* dir-index-bozo.c */
1.12      mrg       330: #ifdef NO_DIRINDEX_SUPPORT
1.15      mrg       331: #define bozo_dir_index(a, b, c)                                0
1.1       tls       332: #else
1.12      mrg       333: int    bozo_dir_index(bozo_httpreq_t *, const char *, int);
1.1       tls       334: #endif /* NO_DIRINDEX_SUPPORT */
                    335:
                    336:
                    337: /* content-bozo.c */
1.14      mrg       338: const char *bozo_content_type(bozo_httpreq_t *, const char *);
                    339: const char *bozo_content_encoding(bozo_httpreq_t *, const char *);
                    340: bozo_content_map_t *bozo_match_content_map(bozohttpd_t *, const char *, int);
                    341: bozo_content_map_t *bozo_get_content_map(bozohttpd_t *, const char *);
1.1       tls       342: #ifndef NO_DYNAMIC_CONTENT
1.41      mrg       343: void   bozo_add_content_map_mime(bozohttpd_t *, const char *, const char *,
                    344:                                  const char *, const char *);
1.1       tls       345: #endif
1.12      mrg       346:
                    347: /* I/O */
1.22      joerg     348: int bozo_printf(bozohttpd_t *, const char *, ...) BOZO_PRINTFLIKE(2, 3);;
1.12      mrg       349: ssize_t bozo_read(bozohttpd_t *, int, void *, size_t);
                    350: ssize_t bozo_write(bozohttpd_t *, int, const void *, size_t);
                    351: int bozo_flush(bozohttpd_t *, FILE *);
                    352:
                    353: /* misc */
                    354: int bozo_init_httpd(bozohttpd_t *);
1.41      mrg       355: int bozo_init_prefs(bozohttpd_t *, bozoprefs_t *);
1.12      mrg       356: int bozo_set_defaults(bozohttpd_t *, bozoprefs_t *);
                    357: int bozo_setup(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
                    358: bozo_httpreq_t *bozo_read_request(bozohttpd_t *);
                    359: void bozo_process_request(bozo_httpreq_t *);
                    360: void bozo_clean_request(bozo_httpreq_t *);
1.44      elric     361: bozoheaders_t *addmerge_reqheader(bozo_httpreq_t *, const char *,
                    362:                                  const char *, ssize_t);
                    363: bozoheaders_t *addmerge_replheader(bozo_httpreq_t *, const char *,
                    364:                                   const char *, ssize_t);
1.12      mrg       365:
                    366: /* variables */
1.41      mrg       367: int bozo_set_pref(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
1.12      mrg       368: char *bozo_get_pref(bozoprefs_t *, const char *);
                    369:
1.46      agc       370: int bozo_get_version(char */*buf*/, size_t /*size*/);
                    371:
1.12      mrg       372: #endif /* BOZOHTTOPD_H_ */

CVSweb <webmaster@jp.NetBSD.org>