home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / share / os2 / varios / apache / httpd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-08  |  18.3 KB  |  561 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54.  
  55. /*
  56.  * httpd.h: header for simple (ha! not anymore) http daemon
  57.  */
  58.  
  59. /* Headers in which EVERYONE has an interest... */
  60.  
  61. #include "conf.h"
  62. #include "alloc.h"
  63. #include "buff.h"
  64.  
  65. /* ----------------------------- config dir ------------------------------ */
  66.  
  67. /* Define this to be the default server home dir. Anything later in this
  68.  * file with a relative pathname will have this added.
  69.  */
  70. #ifdef __EMX__
  71. /* Set default for OS/2 file system */ 
  72. #define HTTPD_ROOT "/os2httpd"
  73. #else
  74. #define HTTPD_ROOT "/usr/local/etc/httpd"
  75. #endif
  76.  
  77. /* Root of server */
  78. #ifdef __EMX__
  79. /* Set default for OS/2 file system */ 
  80. #define DOCUMENT_LOCATION "/os2httpd/docs"
  81. #else
  82. #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs"
  83. #endif
  84.  
  85. /* Max. number of dynamically loaded modules */
  86. #define DYNAMIC_MODULE_LIMIT 64
  87.  
  88. /* Default administrator's address */
  89. #define DEFAULT_ADMIN "[no address given]"
  90.  
  91. /* 
  92.  * --------- You shouldn't have to edit anything below this line ----------
  93.  *
  94.  * Any modifications to any defaults not defined above should be done in the 
  95.  * respective config. file. 
  96.  *
  97.  */
  98.  
  99.  
  100. /* -------------- Port number for server running standalone --------------- */
  101.  
  102. #define DEFAULT_PORT 80
  103.  
  104. /* --------- Default user name and group name running standalone ---------- */
  105. /* --- These may be specified as numbers by placing a # before a number --- */
  106.  
  107. #define DEFAULT_USER "#-1"
  108. #define DEFAULT_GROUP "#-1"
  109.  
  110. /* The name of the log files */
  111. #ifdef __EMX__
  112. /* Set default for OS/2 file system */ 
  113. #define DEFAULT_XFERLOG "logs/access.log"
  114. #else
  115. #define DEFAULT_XFERLOG "logs/access_log"
  116. #endif
  117. #ifdef __EMX__
  118. /* Set default for OS/2 file system */ 
  119. #define DEFAULT_ERRORLOG "logs/error.log"
  120. #else
  121. #define DEFAULT_ERRORLOG "logs/error_log"
  122. #endif
  123. #define DEFAULT_PIDLOG "logs/httpd.pid"
  124. #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
  125.  
  126. /* Define this to be what your HTML directory content files are called */
  127. #define DEFAULT_INDEX "index.html"
  128.  
  129. /* Define this to 1 if you want fancy indexing, 0 otherwise */
  130. #define DEFAULT_INDEXING 0
  131.  
  132. /* Define this to be what type you'd like returned for files with unknown */
  133. /* suffixes */
  134. #define DEFAULT_TYPE "text/html"
  135.  
  136. /* Define this to be what your per-directory security files are called */
  137. #ifdef __EMX__
  138. /* Set default for OS/2 file system */ 
  139. #define DEFAULT_ACCESS_FNAME "htaccess"
  140. #else
  141. #define DEFAULT_ACCESS_FNAME ".htaccess"
  142. #endif
  143.  
  144. /* The name of the server config file */
  145. #define SERVER_CONFIG_FILE "conf/httpd.conf"
  146.  
  147. /* The name of the document config file */
  148. #define RESOURCE_CONFIG_FILE "conf/srm.conf"
  149.  
  150. /* The name of the MIME types file */
  151. #define TYPES_CONFIG_FILE "conf/mime.types"
  152.  
  153. /* The name of the access file */
  154. #define ACCESS_CONFIG_FILE "conf/access.conf"
  155.  
  156. /* Whether we should enable rfc1413 identity checking */
  157. #define DEFAULT_RFC1413 0
  158. /* The default directory in user's home dir */
  159. #define DEFAULT_USER_DIR "public_html"
  160.  
  161. /* The default path for CGI scripts if none is currently set */
  162. #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
  163.  
  164. /* The path to the Bourne shell, for parsed docs */
  165. #ifdef __EMX__
  166. /* Set default for OS/2 file system */ 
  167. #define SHELL_PATH "CMD.EXE"
  168. #else
  169. #define SHELL_PATH "/bin/sh"
  170. #endif
  171.  
  172. /* The default string lengths */
  173. #define MAX_STRING_LEN HUGE_STRING_LEN
  174. #define HUGE_STRING_LEN 8192
  175.  
  176. /* The timeout for waiting for messages */
  177. #define DEFAULT_TIMEOUT 1200
  178.  
  179. /* The timeout for waiting for keepalive timeout until next request */
  180. #define DEFAULT_KEEPALIVE_TIMEOUT 15
  181.  
  182. /* The number of requests to entertain per connection */
  183. #define DEFAULT_KEEPALIVE 5
  184.  
  185. /* The size of the server's internal read-write buffers */
  186. #define IOBUFSIZE 8192
  187.  
  188. /* The number of header lines we will accept from a client */
  189. #define MAX_HEADERS 200
  190.  
  191. /* Number of servers to spawn off by default --- also, if fewer than
  192.  * this free when the caretaker checks, it will spawn more.
  193.  */
  194. #define DEFAULT_START_DAEMON 5
  195.  
  196. /* Maximum number of *free* server processes --- more than this, and
  197.  * they will die off.
  198.  */
  199.  
  200. #define DEFAULT_MAX_FREE_DAEMON 10
  201.  
  202. /* Minimum --- fewer than this, and more will be created */
  203.  
  204. #define DEFAULT_MIN_FREE_DAEMON 5
  205.  
  206. /* Limit on the total --- clients will be locked out if more servers than
  207.  * this are needed.  It is intended solely to keep the server from crashing
  208.  * when things get out of hand.
  209.  *
  210.  * We keep a hard maximum number of servers, for two reasons --- first off,
  211.  * in case something goes seriously wrong, we want to stop the fork bomb
  212.  * short of actually crashing the machine we're running on by filling some
  213.  * kernel table (I was originally going to make this 256, but it turns out
  214.  * that that would actually fill the process table on reasonably configured
  215.  * machines).  Secondly, it keeps the size of the scoreboard file small
  216.  * enough that we can read the whole thing without worrying too much about
  217.  * the overhead.
  218.  */
  219. #define HARD_SERVER_LIMIT 150
  220.  
  221. /* Number of requests to try to handle in a single process.  If <= 0,
  222.  * the children don't die off.  That's the default here, since I'm still
  223.  * interested in finding and stanching leaks.
  224.  */
  225.  
  226. #define DEFAULT_MAX_REQUESTS_PER_CHILD 0
  227.  
  228. /* If you have altered Apache and wish to change the SERVER_VERSION define
  229.  * below, please keep to the HTTP/1.0 specification.  This states that
  230.  * the identification string should consist of product tokens with an optional
  231.  * slash and version designator.  Sub-products which form a significant part 
  232.  * of the application can be listed, separated by whitespace.  The tokens
  233.  * are listed in order of their significance for identifying the application.
  234.  *
  235.  * "Product tokens should be short and to the point -- use of them for 
  236.  * advertizing or other non-essential information is explicitly forbidden."
  237.  *
  238.  * Example: "Apache/1.1b3 MrWidget/0.1-alpha" 
  239.  */
  240.  
  241. #define SERVER_VERSION "Apache/1.1.1" /* SEE COMMENTS ABOVE */
  242.  
  243. #define SERVER_PROTOCOL "HTTP/1.0"
  244. #define SERVER_SUPPORT "http://www.apache.org/"
  245.  
  246. #define DECLINED -1        /* Module declines to handle */
  247. #define OK 0            /* Module has handled this stage. */
  248.  
  249. /* ------------------------------ error types ------------------------------ */
  250.  
  251. #define DOCUMENT_FOLLOWS 200
  252. #define REDIRECT 302
  253. #define USE_LOCAL_COPY 304
  254. #define BAD_REQUEST 400
  255. #define AUTH_REQUIRED 401
  256. #define FORBIDDEN 403
  257. #define NOT_FOUND 404
  258. #define SERVER_ERROR 500
  259. #define NOT_IMPLEMENTED 501
  260. #define BAD_GATEWAY 502
  261. #define SERVICE_UNAVAILABLE 503
  262. #define RESPONSE_CODES 10
  263.  
  264. #define METHODS 6
  265. #define M_GET 0
  266. #define M_PUT 1
  267. #define M_POST 2
  268. #define M_DELETE 3
  269. #define M_CONNECT 4
  270. #define M_INVALID 5
  271.  
  272. #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
  273. #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
  274. #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
  275. #define MAP_FILE_MAGIC_TYPE "application/x-type-map"
  276. #define ASIS_MAGIC_TYPE "httpd/send-as-is"
  277. #define DIR_MAGIC_TYPE "httpd/unix-directory"
  278. #define STATUS_MAGIC_TYPE "application/x-httpd-status"
  279.  
  280. /* Just in case your linefeed isn't the one the other end is expecting. */
  281. #define LF 10
  282. #define CR 13
  283.  
  284. /* Things which may vary per file-lookup WITHIN a request ---
  285.  * e.g., state of MIME config.  Basically, the name of an object, info
  286.  * about the object, and any other info we may ahve which may need to
  287.  * change as we go poking around looking for it (e.g., overridden by
  288.  * .htaccess files).
  289.  *
  290.  * Note how the default state of almost all these things is properly
  291.  * zero, so that allocating it with pcalloc does the right thing without
  292.  * a whole lot of hairy initialization... so long as we are willing to
  293.  * make the (fairly) portable assumption that the bit pattern of a NULL
  294.  * pointer is, in fact, zero.
  295.  */
  296.  
  297. /* This represents the result of calling htaccess; these are cached for
  298.  * each request.
  299.  */
  300. struct htaccess_result
  301. {
  302.     char *dir;              /* the directory to which this applies */
  303.     int override;           /* the overrides allowed for the .htaccess file */
  304.     void *htaccess;         /* the configuration directives */
  305. /* the next one, or NULL if no more; N.B. never change this */
  306.     const struct htaccess_result *next;
  307. };
  308.  
  309.  
  310. typedef struct conn_rec conn_rec;
  311. typedef struct server_rec server_rec;
  312. typedef struct request_rec request_rec;
  313. typedef struct listen_rec listen_rec;
  314.  
  315. struct request_rec {
  316.  
  317.   pool *pool;
  318.   conn_rec *connection;
  319.   server_rec *server;
  320.  
  321.   request_rec *next;        /* If we wind up getting redirected,
  322.                  * pointer to the request we redirected to.
  323.                  */
  324.   request_rec *prev;        /* If this is an internal redirect,
  325.                  * pointer to where we redirected *from*.
  326.                  */
  327.   
  328.   request_rec *main;        /* If this is a sub_request (see request.h) 
  329.                  * pointer back to the main request.
  330.                  */
  331.  
  332.   /* Info about the request itself... we begin with stuff that only
  333.    * protocol.c should ever touch...
  334.    */
  335.   
  336.   char *the_request;        /* First line of request, so we can log it */
  337.   int assbackwards;        /* HTTP/0.9, "simple" request */
  338.   int proxyreq;                 /* A proxy request */
  339.   int header_only;        /* HEAD request, as opposed to GET */
  340.   char *protocol;        /* Protocol, as given to us, or HTTP/0.9 */
  341.   int proto_num;        /* Number version of protocol; 1.1 = 1001 */
  342.   char *hostname;        /* Host, as set by full URI or Host: */
  343.   int hostlen;            /* Length of http://host:port in full URI */
  344.  
  345.   char *status_line;        /* Status line, if set by script */
  346.   int status;            /* In any case */
  347.   
  348.   /* Request method, two ways; also, protocol, etc..  Outside of protocol.c,
  349.    * look, but don't touch.
  350.    */
  351.   
  352.   char *method;            /* GET, HEAD, POST, etc. */
  353.   int method_number;        /* M_GET, M_POST, etc. */
  354.  
  355.   int sent_bodyct;        /* byte count in stream is for body */
  356.   long bytes_sent;        /* body byte count, for easy access */
  357.   
  358.   /* MIME header environments, in and out.  Also, an array containing
  359.    * environment variables to be passed to subprocesses, so people can
  360.    * write modules to add to that environment.
  361.    *
  362.    * The difference between headers_out and err_headers_out is that the
  363.    * latter are printed even on error, and persist across internal redirects
  364.    * (so the headers printed for ErrorDocument handlers will have them).
  365.    *
  366.    * The 'notes' table is for notes from one module to another, with no
  367.    * other set purpose in mind...
  368.    */
  369.   
  370.   table *headers_in;
  371.   table *headers_out;
  372.   table *err_headers_out;
  373.   table *subprocess_env;
  374.   table *notes;
  375.  
  376.   char *content_type;        /* Break these out --- we dispatch on 'em */
  377.   char *handler;        /* What we *really* dispatch on           */
  378.  
  379.   char *content_encoding;
  380.   char *content_language;
  381.   
  382.   int no_cache;
  383.   
  384.   /* What object is being requested (either directly, or via include
  385.    * or content-negotiation mapping).
  386.    */
  387.  
  388.   char *uri;                    /* complete URI for a proxy req, or
  389.                                    URL path for a non-proxy req */
  390.   char *filename;
  391.   char *path_info;
  392.   char *args;            /* QUERY_ARGS, if any */
  393.   struct stat finfo;        /* ST_MODE set to zero if no such file */
  394.   
  395.   /* Various other config info which may change with .htaccess files
  396.    * These are config vectors, with one void* pointer for each module
  397.    * (the thing pointed to being the module's business).
  398.    */
  399.   
  400.   void *per_dir_config;        /* Options set in config files, etc. */
  401.   void *request_config;        /* Notes on *this* request */
  402.  
  403. /*
  404.  * a linked list of the configuration directives in the .htaccess files
  405.  * accessed by this request.
  406.  * N.B. always add to the head of the list, _never_ to the end.
  407.  * that way, a sub request's list can (temporarily) point to a parent's list
  408.  */
  409.   const struct htaccess_result *htaccess;
  410. };
  411.  
  412.  
  413. /* Things which are per connection
  414.  */
  415.  
  416. struct conn_rec {
  417.   
  418.   pool *pool;
  419.   server_rec *server;
  420.   
  421.   /* Information about the connection itself */
  422.  
  423.   int child_num;                /* The number of the child handling conn_rec */
  424.   BUFF *client;            /* Connetion to the guy */
  425.   int aborted;            /* Are we still talking? */
  426.   
  427.   /* Who is the client? */
  428.   
  429.   struct sockaddr_in local_addr; /* local address */
  430.   struct sockaddr_in remote_addr;/* remote address */
  431.   char *remote_ip;        /* Client's IP address */
  432.   char *remote_host;        /* Client's DNS name, if known.
  433.                                  * NULL if DNS hasn't been checked,
  434.                                  * "" if it has and no address was found.
  435.                                  * N.B. Only access this though
  436.                  * get_remote_host() */
  437.   char *remote_logname;        /* Only ever set if doing_rfc931
  438.                                  * N.B. Only access this through
  439.                  * get_remote_logname() */
  440.     char *user;            /* If an authentication check was made,
  441.                  * this gets set to the user name.  We assume
  442.                  * that there's only one user per connection(!)
  443.                  */
  444.   char *auth_type;        /* Ditto. */
  445.  
  446.   int keepalive;        /* Are we using HTTP Keep-Alive? */
  447.   int keptalive;        /* Did we use HTTP Keep-Alive? */
  448.   int keepalives;        /* How many times have we used it? */
  449. };
  450.  
  451. /* Per-vhost config... */
  452.  
  453. struct server_rec {
  454.  
  455.   server_rec *next;
  456.   
  457.   /* Full locations of server config info */
  458.   
  459.   char *srm_confname;
  460.   char *access_confname;
  461.   
  462.   /* Contact information */
  463.   
  464.   char *server_admin;
  465.   char *server_hostname;
  466.   short port;                    /* for redirects, etc. */
  467.   
  468.   /* Log files --- note that transfer log is now in the modules... */
  469.   
  470.   char *error_fname;
  471.   FILE *error_log;
  472.   
  473.   /* Module-specific configuration for server, and defaults... */
  474.  
  475.   int is_virtual;               /* true if this is the virtual server */
  476.   void *module_config;        /* Config vector containing pointers to
  477.                  * modules' per-server config structures.
  478.                  */
  479.   void *lookup_defaults;    /* MIME type info, etc., before we start
  480.                  * checking per-directory info.
  481.                  */
  482.   /* Transaction handling */
  483.  
  484.   struct in_addr host_addr;    /* The bound address, for this server */
  485.   short host_port;              /* The bound port, for this server */
  486.   int timeout;            /* Timeout, in seconds, before we give up */
  487.   int keep_alive_timeout;    /* Seconds we'll wait for another request */
  488.   int keep_alive;        /* Maximum requests per connection */
  489.  
  490.   char *path;            /* Pathname for ServerPath */
  491.   int pathlen;            /* Length of path */
  492.  
  493.   char *names;            /* Wildcarded names for HostAlias servers */
  494.   char *virthost;        /* The name given in <VirtualHost> */
  495. };
  496.  
  497. /* These are more like real hosts than virtual hosts */
  498. struct listen_rec {
  499.     listen_rec *next;
  500.     struct sockaddr_in local_addr; /* local IP address and port */
  501. /* more stuff here, like which protocol is bound to the port */
  502. };
  503.  
  504. /* Prototypes for utilities... util.c.
  505.  */
  506.  
  507. /* Time */
  508. extern const char month_snames[12][4];
  509.  
  510. struct tm *get_gmtoff(long *tz);
  511. char *get_time();
  512. char *ht_time (pool *p, time_t t, char *fmt, int gmt);     
  513. char *gm_timestr_822(pool *p, time_t t);
  514.      
  515. /* String handling */     
  516.      
  517. char *getword(pool *p, char **line, char stop);
  518. char *getword_nulls (pool *p, char **line, char stop);
  519. char *getword_conf (pool *p, char **line);      
  520.  
  521. char *get_token (pool *p, char **accept_line, int accept_white);
  522.      
  523. int is_url(char *u);
  524. extern int unescape_url(char *url);
  525. void no2slash(char *name);
  526. void getparents(char *name);
  527. char *escape_path_segment(pool *p, const char *s);
  528. char *os_escape_path(pool *p,const char *path,int partial);
  529. char *escape_uri (pool *p, char *s);
  530. extern char *escape_html(pool *p, const char *s);
  531. char *construct_url (pool *p, char *path, server_rec *s);     
  532. char *escape_shell_cmd (pool *p, char *s);
  533.      
  534. int count_dirs(char *path);
  535. char *make_dirstr(pool *a, char *s, int n);
  536. char *make_full_path(pool *a, char *dir, char *f);
  537.      
  538. int is_matchexp(char *str);
  539. int strcmp_match(char *str, char *exp);
  540. int strcasecmp_match(char *str, char *exp);
  541. char *uudecode (pool *, char *);
  542.  
  543. void str_tolower (char *);
  544. int ind (const char *, char);    /* Sigh... */
  545. int rind (const char *, char);     
  546.  
  547. int cfg_getline(char *s, int n, FILE *f);
  548.      
  549. /* Misc system hackery */
  550.      
  551. uid_t uname2id(char *name);
  552. gid_t gname2id(char *name);
  553. int is_directory(char *name);
  554. int can_exec(struct stat *);     
  555. void chdir_file(char *file);
  556.      
  557. char *get_local_host(pool *);
  558. unsigned long get_virthost_addr (char *hostname, short int *port);
  559.  
  560. extern time_t restart_time;
  561.