home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / modules / proxy / mod_proxy.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-01  |  11.0 KB  |  317 lines

  1. /* ====================================================================
  2.  * Copyright (c) 1996-1999 The Apache Group.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer. 
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by the Apache Group
  19.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  20.  *
  21.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  22.  *    endorse or promote products derived from this software without
  23.  *    prior written permission. For written permission, please contact
  24.  *    apache@apache.org.
  25.  *
  26.  * 5. Products derived from this software may not be called "Apache"
  27.  *    nor may "Apache" appear in their names without prior written
  28.  *    permission of the Apache Group.
  29.  *
  30.  * 6. Redistributions of any form whatsoever must retain the following
  31.  *    acknowledgment:
  32.  *    "This product includes software developed by the Apache Group
  33.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  36.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Group and was originally based
  51.  * on public domain software written at the National Center for
  52.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  53.  * For more information on the Apache Group and the Apache HTTP server
  54.  * project, please see <http://www.apache.org/>.
  55.  *
  56.  */
  57.  
  58. #ifndef MOD_PROXY_H
  59. #define MOD_PROXY_H 
  60.  
  61. /*
  62.  * Main include file for the Apache proxy
  63.  */
  64.  
  65. /*
  66.  
  67.    Note that the Explain() stuff is not yet complete.
  68.    Also note numerous FIXMEs and CHECKMEs which should be eliminated.
  69.  
  70.    If TESTING is set, then garbage collection doesn't delete ... probably a good
  71.    idea when hacking.
  72.  
  73.    This code is still experimental!
  74.  
  75.    Things to do:
  76.  
  77.    1. Make it garbage collect in the background, not while someone is waiting for
  78.    a response!
  79.  
  80.    2. Check the logic thoroughly.
  81.  
  82.    3. Empty directories are only removed the next time round (but this does avoid
  83.    two passes). Consider doing them the first time round.
  84.  
  85.    Ben Laurie <ben@algroup.co.uk> 30 Mar 96
  86.  
  87.    More things to do:
  88.  
  89.    0. Code cleanup (ongoing)
  90.  
  91.    1. add 230 response output for ftp now that it works
  92.  
  93.    2. Make the ftp proxy transparent, also same with (future) gopher & wais
  94.  
  95.    3. Use protocol handler struct a la Apache module handlers (Dirk van Gulik)
  96.  
  97.    4. Use a cache expiry database for more efficient GC (Jeremy Wohl)
  98.  
  99.    5. Bulletproof GC against SIGALRM
  100.  
  101.    Chuck Murcko <chuck@topsail.org> 15 April 1997
  102.  
  103.  */
  104.  
  105. #define TESTING    0
  106. #undef EXPLAIN
  107.  
  108. #include "httpd.h"
  109. #include "http_config.h"
  110. #include "http_protocol.h"
  111.  
  112. #include "explain.h"
  113.  
  114. extern module MODULE_VAR_EXPORT proxy_module;
  115.  
  116.  
  117. /* for proxy_canonenc() */
  118. enum enctype {
  119.     enc_path, enc_search, enc_user, enc_fpath, enc_parm
  120. };
  121.  
  122. #define HDR_APP (0)        /* append header, for proxy_add_header() */
  123. #define HDR_REP (1)        /* replace header, for proxy_add_header() */
  124.  
  125. /* number of characters in the hash */
  126. #define HASH_LEN (22*2)
  127.  
  128. /* maximum  'CacheDirLevels*CacheDirLength' value */
  129. #define CACHEFILE_LEN 20    /* must be less than HASH_LEN/2 */
  130.  
  131. #ifdef CHARSET_EBCDIC
  132. #define CRLF   "\r\n"
  133. #else /*CHARSET_EBCDIC*/
  134. #define CRLF   "\015\012"
  135. #endif /*CHARSET_EBCDIC*/
  136.  
  137.  
  138. #define    SEC_ONE_DAY        86400    /* one day, in seconds */
  139. #define    SEC_ONE_HR        3600    /* one hour, in seconds */
  140.  
  141. #define    DEFAULT_FTP_DATA_PORT    20
  142. #define    DEFAULT_FTP_PORT    21
  143. #define    DEFAULT_GOPHER_PORT    70
  144. #define    DEFAULT_NNTP_PORT    119
  145. #define    DEFAULT_WAIS_PORT    210
  146. #define    DEFAULT_HTTPS_PORT    443
  147. #define    DEFAULT_SNEWS_PORT    563
  148. #define    DEFAULT_PROSPERO_PORT    1525    /* WARNING: conflict w/Oracle */
  149.  
  150. /* Some WWW schemes and their default ports; this is basically /etc/services */
  151. struct proxy_services {
  152.     const char *scheme;
  153.     int port;
  154. };
  155.  
  156. /* static information about a remote proxy */
  157. struct proxy_remote {
  158.     const char *scheme;        /* the schemes handled by this proxy, or '*' */
  159.     const char *protocol;    /* the scheme used to talk to this proxy */
  160.     const char *hostname;    /* the hostname of this proxy */
  161.     int port;            /* the port for this proxy */
  162. };
  163.  
  164. struct proxy_alias {
  165.     char *real;
  166.     char *fake;
  167. };
  168.  
  169. struct dirconn_entry {
  170.     char *name;
  171.     struct in_addr addr, mask;
  172.     struct hostent *hostentry;
  173.     int (*matcher) (struct dirconn_entry * This, request_rec *r);
  174. };
  175.  
  176. struct noproxy_entry {
  177.     char *name;
  178.     struct in_addr addr;
  179. };
  180.  
  181. struct nocache_entry {
  182.     char *name;
  183.     struct in_addr addr;
  184. };
  185.  
  186. #define DEFAULT_CACHE_SPACE 5
  187. #define DEFAULT_CACHE_MAXEXPIRE SEC_ONE_DAY
  188. #define DEFAULT_CACHE_EXPIRE    SEC_ONE_HR
  189. #define DEFAULT_CACHE_LMFACTOR (0.1)
  190. #define DEFAULT_CACHE_COMPLETION (0.9)
  191.  
  192. /* static information about the local cache */
  193. struct cache_conf {
  194.     const char *root;        /* the location of the cache directory */
  195.     off_t space;            /* Maximum cache size (in 1024 bytes) */
  196.     time_t maxexpire;        /* Maximum time to keep cached files in secs */
  197.     time_t defaultexpire;    /* default time to keep cached file in secs */
  198.     double lmfactor;        /* factor for estimating expires date */
  199.     time_t gcinterval;        /* garbage collection interval, in seconds */
  200.     int dirlevels;        /* Number of levels of subdirectories */
  201.     int dirlength;        /* Length of subdirectory names */
  202.     float cache_completion;    /* Force cache completion after this point */
  203. };
  204.  
  205. typedef struct {
  206.     struct cache_conf cache;    /* cache configuration */
  207.     array_header *proxies;
  208.     array_header *aliases;
  209.     array_header *raliases;
  210.     array_header *noproxies;
  211.     array_header *dirconn;
  212.     array_header *nocaches;
  213.     array_header *allowed_connect_ports;
  214.     char *domain;        /* domain name to use in absence of a domain name in the request */
  215.     int req;            /* true if proxy requests are enabled */
  216.     enum {
  217.       via_off,
  218.       via_on,
  219.       via_block,
  220.       via_full
  221.     } viaopt;                   /* how to deal with proxy Via: headers */
  222.     size_t recv_buffer_size;
  223. } proxy_server_conf;
  224.  
  225. struct hdr_entry {
  226.     const char *field;
  227.     const char *value;
  228. };
  229.  
  230. /* caching information about a request */
  231. typedef struct {
  232.     request_rec *req;        /* the request */
  233.     char *url;            /* the URL requested */
  234.     char *filename;        /* name of the cache file, or NULL if no cache */
  235.     char *tempfile;        /* name of the temporary file, of NULL if not caching */
  236.     time_t ims;            /* if-modified-since date of request; -1 if no header */
  237.     BUFF *fp;            /* the cache file descriptor if the file is cached
  238.                    and may be returned, or NULL if the file is
  239.                    not cached (or must be reloaded) */
  240.     time_t expire;        /* calculated expire date of cached entity */
  241.     time_t lmod;        /* last-modified date of cached entity */
  242.     time_t date;        /* the date the cached file was last touched */
  243.     int version;        /* update count of the file */
  244.     off_t len;            /* content length */
  245.     char *protocol;        /* Protocol, and major/minor number, e.g. HTTP/1.1 */
  246.     int status;            /* the status of the cached file */
  247.     unsigned int written;    /* total *content* bytes written to cache */
  248.     float cache_completion;    /* specific to this request */
  249.     char *resp_line;        /* the whole status like (protocol, code + message) */
  250.     table *hdrs;        /* the HTTP headers of the file */
  251. } cache_req;
  252.  
  253. /* Additional information passed to the function called by ap_table_do() */
  254. struct tbl_do_args {
  255.     request_rec *req;
  256.     cache_req *cache;
  257. };
  258.  
  259. /* Function prototypes */
  260.  
  261. /* proxy_cache.c */
  262.  
  263. void ap_proxy_cache_tidy(cache_req *c);
  264. int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
  265.               cache_req **cr);
  266. int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
  267.                const int is_HTTP1, int nocache);
  268. void ap_proxy_garbage_coll(request_rec *r);
  269.  
  270. /* proxy_connect.c */
  271.  
  272. int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
  273.               const char *proxyhost, int proxyport);
  274.  
  275. /* proxy_ftp.c */
  276.  
  277. int ap_proxy_ftp_canon(request_rec *r, char *url);
  278. int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url);
  279.  
  280. /* proxy_http.c */
  281.  
  282. int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme,
  283.              int def_port);
  284. int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
  285.                const char *proxyhost, int proxyport);
  286.  
  287. /* proxy_util.c */
  288.  
  289. int ap_proxy_hex2c(const char *x);
  290. void ap_proxy_c2hex(int ch, char *x);
  291. char *ap_proxy_canonenc(pool *p, const char *x, int len, enum enctype t,
  292.              int isenc);
  293. char *ap_proxy_canon_netloc(pool *p, char **const urlp, char **userp,
  294.              char **passwordp, char **hostp, int *port);
  295. const char *ap_proxy_date_canon(pool *p, const char *x);
  296. table *ap_proxy_read_headers(request_rec *r, char *buffer, int size, BUFF *f);
  297. long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c);
  298. void ap_proxy_send_headers(request_rec *r, const char *respline, table *hdrs);
  299. int ap_proxy_liststr(const char *list, const char *val);
  300. void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength);
  301. int ap_proxy_hex2sec(const char *x);
  302. void ap_proxy_sec2hex(int t, char *y);
  303. cache_req *ap_proxy_cache_error(cache_req *r);
  304. int ap_proxyerror(request_rec *r, const char *message);
  305. const char *ap_proxy_host2addr(const char *host, struct hostent *reqhp);
  306. int ap_proxy_is_ipaddr(struct dirconn_entry *This, pool *p);
  307. int ap_proxy_is_domainname(struct dirconn_entry *This, pool *p);
  308. int ap_proxy_is_hostname(struct dirconn_entry *This, pool *p);
  309. int ap_proxy_is_word(struct dirconn_entry *This, pool *p);
  310. int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r);
  311. int ap_proxy_garbage_init(server_rec *, pool *);
  312. /* This function is called by ap_table_do() for all header lines */
  313. int ap_proxy_send_hdr_line(void *p, const char *key, const char *value);
  314. unsigned ap_proxy_bputs2(const char *data, BUFF *client, cache_req *cache);
  315.  
  316. #endif /*MOD_PROXY_H*/
  317.