home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 9 / CDACTUAL9.iso / share / Os2 / varios / APACHE / HTTPD.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-17  |  14.9 KB  |  479 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.  
  64. /* ----------------------------- config dir ------------------------------ */
  65.  
  66. /* Define this to be the default server home dir. Anything later in this
  67.  * file with a relative pathname will have this added.
  68.  */
  69. #ifdef __EMX__
  70. /* Set default for OS/2 file system */ 
  71. #define HTTPD_ROOT "/os2httpd"
  72. #else
  73. #define HTTPD_ROOT "/usr/local/etc/httpd"
  74. #endif
  75.  
  76. /* Root of server */
  77. #ifdef __EMX__
  78. /* Set default for OS/2 file system */ 
  79. #define DOCUMENT_LOCATION "/os2httpd/docs"
  80. #else
  81. #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs"
  82. #endif
  83.  
  84. /* Max. number of dynamically loaded modules */
  85. #define DYNAMIC_MODULE_LIMIT 64
  86.  
  87. /* Default administrator's address */
  88. #define DEFAULT_ADMIN "[no address given]"
  89.  
  90. /* 
  91.  * --------- You shouldn't have to edit anything below this line ----------
  92.  *
  93.  * Any modifications to any defaults not defined above should be done in the 
  94.  * respective config. file. 
  95.  *
  96.  */
  97.  
  98.  
  99. /* -------------- Port number for server running standalone --------------- */
  100.  
  101. #define DEFAULT_PORT 80
  102.  
  103. /* --------- Default user name and group name running standalone ---------- */
  104. /* --- These may be specified as numbers by placing a # before a number --- */
  105.  
  106. #define DEFAULT_USER "#-1"
  107. #define DEFAULT_GROUP "#-1"
  108.  
  109. /* The name of the log files */
  110. #ifdef __EMX__
  111. /* Set default for OS/2 file system */ 
  112. #define DEFAULT_XFERLOG "logs/access.log"
  113. #else
  114. #define DEFAULT_XFERLOG "logs/access_log"
  115. #endif
  116. #ifdef __EMX__
  117. /* Set default for OS/2 file system */ 
  118. #define DEFAULT_ERRORLOG "logs/error.log"
  119. #else
  120. #define DEFAULT_ERRORLOG "logs/error_log"
  121. #endif
  122. #define DEFAULT_PIDLOG "logs/httpd.pid"
  123. #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
  124.  
  125. /* Define this to be what your HTML directory content files are called */
  126. #define DEFAULT_INDEX "index.html"
  127.  
  128. /* Define this to 1 if you want fancy indexing, 0 otherwise */
  129. #define DEFAULT_INDEXING 0
  130.  
  131. /* Define this to be what type you'd like returned for files with unknown */
  132. /* suffixes */
  133. #define DEFAULT_TYPE "text/html"
  134.  
  135. /* Define this to be what your per-directory security files are called */
  136. #ifdef __EMX__
  137. /* Set default for OS/2 file system */ 
  138. #define DEFAULT_ACCESS_FNAME "htaccess"
  139. #else
  140. #define DEFAULT_ACCESS_FNAME ".htaccess"
  141. #endif
  142.  
  143. /* The name of the server config file */
  144. #define SERVER_CONFIG_FILE "conf/httpd.conf"
  145.  
  146. /* The name of the document config file */
  147. #define RESOURCE_CONFIG_FILE "conf/srm.conf"
  148.  
  149. /* The name of the MIME types file */
  150. #define TYPES_CONFIG_FILE "conf/mime.types"
  151.  
  152. /* The name of the access file */
  153. #define ACCESS_CONFIG_FILE "conf/access.conf"
  154.  
  155. /* Whether we should enable rfc931 identity checking */
  156. #define DEFAULT_RFC931 0
  157. /* The default directory in user's home dir */
  158. #define DEFAULT_USER_DIR "public_html"
  159.  
  160. /* The default path for CGI scripts if none is currently set */
  161. #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
  162.  
  163. /* The path to the Bourne shell, for parsed docs */
  164. #ifdef __EMX__
  165. /* Set default for OS/2 file system */ 
  166. #define SHELL_PATH "CMD.EXE"
  167. #else
  168. #define SHELL_PATH "/bin/sh"
  169. #endif
  170.  
  171. /* The default string lengths */
  172. #define MAX_STRING_LEN HUGE_STRING_LEN
  173. #define HUGE_STRING_LEN 8192
  174.  
  175. /* The timeout for waiting for messages */
  176. #define DEFAULT_TIMEOUT 1200
  177.  
  178. /* The size of the server's internal read-write buffers */
  179. #define IOBUFSIZE 8192
  180.  
  181. /* The number of header lines we will accept from a client */
  182. #define MAX_HEADERS 200
  183.  
  184. /* RFC 1123 format for date - this is what HTTP/1.0 wants */
  185. #define HTTP_TIME_FORMAT "%a, %d %b %Y %T GMT"
  186.  
  187. /* Number of servers to spawn off by default --- also, if fewer than
  188.  * this free when the caretaker checks, it will spawn more.
  189.  */
  190. #define DEFAULT_START_DAEMON 5
  191.  
  192. /* Maximum number of *free* server processes --- more than this, and
  193.  * they will die off.
  194.  */
  195.  
  196. #define DEFAULT_MAX_FREE_DAEMON 10
  197.  
  198. /* Minimum --- fewer than this, and more will be created */
  199.  
  200. #define DEFAULT_MIN_FREE_DAEMON 5
  201.  
  202. /* Limit on the total --- clients will be locked out if more servers than
  203.  * this are needed.  It is intended solely to keep the server from crashing
  204.  * when things get out of hand.
  205.  */
  206.  
  207. #define DEFAULT_SERVER_LIMIT 150
  208.  
  209. /* Number of requests to try to handle in a single process.  If <= 0,
  210.  * the children don't die off.  That's the default here, since I'm still
  211.  * interested in finding and stanching leaks.
  212.  */
  213.  
  214. #define DEFAULT_MAX_REQUESTS_PER_CHILD 0
  215.  
  216. /* ------------------------------ error types ------------------------------ */
  217.  
  218. #define SERVER_VERSION "Apache/1.0.3"
  219. #define SERVER_PROTOCOL "HTTP/1.0"
  220. #define SERVER_SUPPORT "http://www.apache.org/"
  221.  
  222. #define DECLINED -1        /* Module declines to handle */
  223. #define OK 0            /* Module has handled this stage. */
  224.  
  225. #define DOCUMENT_FOLLOWS 200
  226. #define REDIRECT 302
  227. #define USE_LOCAL_COPY 304
  228. #define BAD_REQUEST 400
  229. #define AUTH_REQUIRED 401
  230. #define FORBIDDEN 403
  231. #define NOT_FOUND 404
  232. #define SERVER_ERROR 500
  233. #define NOT_IMPLEMENTED 501
  234. #define SERVICE_UNAVAILABLE 503
  235. #define RESPONSE_CODES 10
  236.  
  237. #define METHODS 5
  238. #define M_GET 0
  239. #define M_PUT 1
  240. #define M_POST 2
  241. #define M_DELETE 3
  242. #define M_INVALID 4
  243.  
  244. #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
  245. #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
  246. #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
  247. #define MAP_FILE_MAGIC_TYPE "application/x-type-map"
  248. #define ASIS_MAGIC_TYPE "httpd/send-as-is"
  249. #define DIR_MAGIC_TYPE "httpd/unix-directory"
  250.  
  251. /* Just in case your linefeed isn't the one the other end is expecting. */
  252. #define LF 10
  253. #define CR 13
  254.  
  255. /* Things which may vary per file-lookup WITHIN a request ---
  256.  * e.g., state of MIME config.  Basically, the name of an object, info
  257.  * about the object, and any other info we may ahve which may need to
  258.  * change as we go poking around looking for it (e.g., overridden by
  259.  * .htaccess files).
  260.  *
  261.  * Note how the default state of almost all these things is properly
  262.  * zero, so that allocating it with pcalloc does the right thing without
  263.  * a whole lot of hairy initialization... so long as we are willing to
  264.  * make the (fairly) portable assumption that the bit pattern of a NULL
  265.  * pointer is, in fact, zero.
  266.  */
  267.  
  268. typedef struct conn_rec conn_rec;
  269. typedef struct server_rec server_rec;
  270. typedef struct request_rec request_rec;
  271.  
  272. struct request_rec {
  273.  
  274.   pool *pool;
  275.   conn_rec *connection;
  276.   server_rec *server;
  277.  
  278.   request_rec *next;        /* If we wind up getting redirected,
  279.                  * pointer to the request we redirected to.
  280.                  */
  281.   request_rec *prev;        /* If this is an internal redirect,
  282.                  * pointer to where we redirected *from*.
  283.                  */
  284.   
  285.   request_rec *main;        /* If this is a sub_request (see request.h) 
  286.                  * pointer back to the main request.
  287.                  */
  288.  
  289.   /* Info about the request itself... we begin with stuff that only
  290.    * protocol.c should ever touch...
  291.    */
  292.   
  293.   char *the_request;        /* First line of request, so we can log it */
  294.   int assbackwards;        /* HTTP/0.9, "simple" request */
  295.   int header_only;        /* HEAD request, as opposed to GET */
  296.   char *protocol;        /* Protocol, as given to us, or HTTP/0.9 */
  297.   
  298.   char *status_line;        /* Status line, if set by script */
  299.   int status;            /* In any case */
  300.   
  301.   /* Request method, two ways; also, protocol, etc..  Outside of protocol.c,
  302.    * look, but don't touch.
  303.    */
  304.   
  305.   char *method;            /* GET, HEAD, POST, etc. */
  306.   int method_number;        /* M_GET, M_POST, etc. */
  307.  
  308.   /* int header_bytes_sent; */
  309.   int bytes_sent;        /* body --- not headers */
  310.   
  311.   /* MIME header environments, in and out.  Also, an array containing
  312.    * environment variables to be passed to subprocesses, so people can
  313.    * write modules to add to that environment.
  314.    *
  315.    * The difference between headers_out and err_headers_out is that the
  316.    * latter are printed even on error, and persist across internal redirects
  317.    * (so the headers printed for ErrorDocument handlers will have them).
  318.    *
  319.    * The 'notes' table is for notes from one module to another, with no
  320.    * other set purpose in mind...
  321.    */
  322.   
  323.   table *headers_in;
  324.   table *headers_out;
  325.   table *err_headers_out;
  326.   table *subprocess_env;
  327.   table *notes;
  328.  
  329.   char *content_type;        /* Break these out --- we dispatch on 'em */
  330.   char *content_encoding;
  331.   char *content_language;
  332.   
  333.   int no_cache;
  334.   
  335.   /* What object is being requested (either directly, or via include
  336.    * or content-negotiation mapping).
  337.    */
  338.   
  339.   char *uri;
  340.   char *filename;
  341.   char *path_info;
  342.   char *args;            /* QUERY_ARGS, if any */
  343.   struct stat finfo;        /* ST_MODE set to zero if no such file */
  344.   
  345.   /* Various other config info which may change with .htaccess files
  346.    * These are config vectors, with one void* pointer for each module
  347.    * (the thing pointed to being the module's business).
  348.    */
  349.   
  350.   void *per_dir_config;        /* Options set in config files, etc. */
  351.   void *request_config;        /* Notes on *this* request */
  352.   
  353. };
  354.  
  355.  
  356. /* Things which are per connection
  357.  */
  358.  
  359. struct conn_rec {
  360.   
  361.   pool *pool;
  362.   server_rec *server;
  363.   
  364.   /* Information about the connection itself */
  365.   
  366.   FILE *client;            /* Connetion to the guy */
  367.   FILE *request_in;        /* Connection from the guy */
  368.   int aborted;            /* Are we still talking? */
  369.   
  370.   /* Who is the client? */
  371.   
  372.   char *remote_ip;        /* Client's IP address */
  373.   char *remote_host;        /* Client's DNS name, if known */
  374.   char *remote_name;        /* Host ID --- same as remote_host, if known;
  375.                  * otherwise same as remote_ip.
  376.                  */
  377.   char *remote_logname;        /* Only ever set if doing_rfc931 */
  378.   
  379.   char *user;            /* If an authentication check was made,
  380.                  * this gets set to the user name.  We assume
  381.                  * that there's only one user per connection(!)
  382.                  */
  383.   char *auth_type;        /* Ditto. */
  384. };
  385.  
  386. /* Per-vhost config... */
  387.  
  388. struct server_rec {
  389.  
  390.   server_rec *next;
  391.   
  392.   /* Full locations of server config info */
  393.   
  394.   char *srm_confname;
  395.   char *access_confname;
  396.   
  397.   /* Contact information */
  398.   
  399.   char *server_admin;
  400.   char *server_hostname;
  401.   
  402.   /* Log files --- note that transfer log is now in the modules... */
  403.   
  404.   char *error_fname;
  405.   FILE *error_log;
  406.   
  407.   /* Module-specific configuration for server, and defaults... */
  408.  
  409.   void *module_config;        /* Config vector containing pointers to
  410.                  * modules' per-server config structures.
  411.                  */
  412.   void *lookup_defaults;    /* MIME type info, etc., before we start
  413.                  * checking per-directory info.
  414.                  */
  415.   /* Transaction handling */
  416.  
  417.   short port;
  418.   struct in_addr host_addr;    /* Specific address, if "virtual" server */
  419.   int timeout;            /* Timeout, in seconds, before we give up */
  420.   int do_rfc931;        /* See if client is advertising a username? */
  421.   
  422. };
  423.  
  424. /* Prototypes for utilities... util.c.
  425.  */
  426.  
  427. /* Time */
  428.  
  429. struct tm *get_gmtoff(long *tz);
  430. char *get_time();
  431. char *ht_time (pool *p, time_t t, char *fmt, int gmt);     
  432. char *gm_timestr_822(pool *p, time_t t);
  433.      
  434. /* String handling */     
  435.      
  436. char *getword(pool *p, char **line, char stop);
  437. char *getword_conf (pool *p, char **line);      
  438.      
  439. int is_url(char *u);
  440. extern int unescape_url(char *url);
  441. void no2slash(char *name);
  442. void getparents(char *name);
  443. char *escape_path_segment(pool *p, const char *s);
  444. char *os_escape_path(pool *p,const char *path);
  445. char *escape_uri (pool *p, char *s);
  446. extern char *escape_html(pool *p, const char *s);
  447. char *construct_url (pool *p, char *path, server_rec *s);     
  448. char *escape_shell_cmd (pool *p, char *s);
  449.      
  450. int count_dirs(char *path);
  451. char *make_dirstr(pool *a, char *s, int n);
  452. char *make_full_path(pool *a, char *dir, char *f);
  453.      
  454. int is_matchexp(char *str);
  455. int strcmp_match(char *str, char *exp);
  456. char *uudecode (pool *, char *);
  457.  
  458. void str_tolower (char *);
  459. int ind (const char *, char);    /* Sigh... */
  460. int rind (const char *, char);     
  461.  
  462. int cfg_getline(char *s, int n, FILE *f);
  463.      
  464. /* Misc system hackery */
  465.      
  466. uid_t uname2id(char *name);
  467. gid_t gname2id(char *name);
  468. int is_directory(char *name);
  469. int can_exec(struct stat *);     
  470. void chdir_file(char *file);
  471.      
  472. char *get_local_host(pool *);
  473. struct in_addr get_local_addr (int sd);
  474. unsigned long get_virthost_addr (char *hostname, int wild_allowed);
  475. void get_remote_host(conn_rec *conn);
  476. int get_portnum(int sd);
  477.      
  478.  
  479.