github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_2_34/include/mod_proxy.h (about)

     1  /* Licensed to the Apache Software Foundation (ASF) under one or more
     2   * contributor license agreements.  See the NOTICE file distributed with
     3   * this work for additional information regarding copyright ownership.
     4   * The ASF licenses this file to You under the Apache License, Version 2.0
     5   * (the "License"); you may not use this file except in compliance with
     6   * the License.  You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  #ifndef MOD_PROXY_H
    18  #define MOD_PROXY_H 
    19  
    20  /**
    21   * @file  mod_proxy.h
    22   * @brief Proxy Extension Module for Apache
    23   *
    24   * @defgroup MOD_PROXY mod_proxy
    25   * @ingroup  APACHE_MODS
    26   * @{
    27   */
    28  
    29  /*
    30  
    31     Also note numerous FIXMEs and CHECKMEs which should be eliminated.
    32  
    33     This code is once again experimental!
    34  
    35     Things to do:
    36  
    37     1. Make it completely work (for FTP too)
    38  
    39     2. HTTP/1.1
    40  
    41     Chuck Murcko <chuck@topsail.org> 02-06-01
    42  
    43   */
    44  
    45  #define CORE_PRIVATE
    46  
    47  #include "apr_hooks.h"
    48  #include "apr.h"
    49  #include "apr_lib.h"
    50  #include "apr_strings.h"
    51  #include "apr_buckets.h"
    52  #include "apr_md5.h"
    53  #include "apr_network_io.h"
    54  #include "apr_pools.h"
    55  #include "apr_strings.h"
    56  #include "apr_uri.h"
    57  #include "apr_date.h"
    58  #include "apr_strmatch.h"
    59  #include "apr_fnmatch.h"
    60  #include "apr_reslist.h"
    61  #define APR_WANT_STRFUNC
    62  #include "apr_want.h"
    63  
    64  #include "httpd.h"
    65  #include "http_config.h"
    66  #include "ap_config.h"
    67  #include "http_core.h"
    68  #include "http_protocol.h"
    69  #include "http_request.h"
    70  #include "http_vhost.h"
    71  #include "http_main.h"
    72  #include "http_log.h"
    73  #include "http_connection.h"
    74  #include "util_filter.h"
    75  #include "util_ebcdic.h"
    76  #include "ap_provider.h"
    77  
    78  #if APR_HAVE_NETINET_IN_H
    79  #include <netinet/in.h>
    80  #endif
    81  #if APR_HAVE_ARPA_INET_H
    82  #include <arpa/inet.h>
    83  #endif
    84  
    85  /* for proxy_canonenc() */
    86  enum enctype {
    87      enc_path, enc_search, enc_user, enc_fpath, enc_parm
    88  };
    89  
    90  #if APR_CHARSET_EBCDIC
    91  #define CRLF   "\r\n"
    92  #else /*APR_CHARSET_EBCDIC*/
    93  #define CRLF   "\015\012"
    94  #endif /*APR_CHARSET_EBCDIC*/
    95  
    96  /* default Max-Forwards header setting */
    97  /* Set this to -1, which complies with RFC2616 by not setting
    98   * max-forwards if the client didn't send it to us.
    99   */
   100  #define DEFAULT_MAX_FORWARDS    -1
   101  
   102  /* static information about a remote proxy */
   103  struct proxy_remote {
   104      const char *scheme;     /* the schemes handled by this proxy, or '*' */
   105      const char *protocol;   /* the scheme used to talk to this proxy */
   106      const char *hostname;   /* the hostname of this proxy */
   107      apr_port_t  port;       /* the port for this proxy */
   108      ap_regex_t *regexp;        /* compiled regex (if any) for the remote */
   109      int use_regex;          /* simple boolean. True if we have a regex pattern */
   110  };
   111  
   112  #define PROXYPASS_NOCANON 0x01
   113  #define PROXYPASS_INTERPOLATE 0x02
   114  struct proxy_alias {
   115      const char  *real;
   116      const char  *fake;
   117      ap_regex_t  *regex;
   118      unsigned int flags;
   119  };
   120  
   121  struct dirconn_entry {
   122      char *name;
   123      struct in_addr addr, mask;
   124      struct apr_sockaddr_t *hostaddr;
   125      int (*matcher) (struct dirconn_entry * This, request_rec *r);
   126  };
   127  
   128  struct noproxy_entry {
   129      const char *name;
   130      struct apr_sockaddr_t *addr;
   131  };
   132  
   133  typedef struct proxy_balancer  proxy_balancer;
   134  typedef struct proxy_worker    proxy_worker;
   135  typedef struct proxy_conn_pool proxy_conn_pool;
   136  typedef struct proxy_balancer_method proxy_balancer_method;
   137  
   138  typedef struct {
   139      apr_array_header_t *proxies;
   140      apr_array_header_t *sec_proxy;
   141      apr_array_header_t *aliases;
   142      apr_array_header_t *noproxies;
   143      apr_array_header_t *dirconn;
   144      apr_array_header_t *allowed_connect_ports;
   145      apr_array_header_t *workers;
   146      apr_array_header_t *balancers;
   147      proxy_worker       *forward;    /* forward proxy worker */
   148      proxy_worker       *reverse;    /* reverse "module-driven" proxy worker */
   149      const char *domain;     /* domain name to use in absence of a domain name in the request */
   150      int req;                /* true if proxy requests are enabled */
   151      char req_set;
   152      enum {
   153        via_off,
   154        via_on,
   155        via_block,
   156        via_full
   157      } viaopt;                   /* how to deal with proxy Via: headers */
   158      char viaopt_set;
   159      apr_size_t recv_buffer_size;
   160      char recv_buffer_size_set;
   161      apr_size_t io_buffer_size;
   162      char io_buffer_size_set;
   163      long maxfwd;
   164      char maxfwd_set;
   165      /** 
   166       * the following setting masks the error page
   167       * returned from the 'proxied server' and just 
   168       * forwards the status code upwards.
   169       * This allows the main server (us) to generate
   170       * the error page, (so it will look like a error
   171       * returned from the rest of the system 
   172       */
   173      int error_override;
   174      int error_override_set;
   175      int preserve_host;
   176      int preserve_host_set;
   177      apr_interval_time_t timeout;
   178      char timeout_set;
   179      enum {
   180        bad_error,
   181        bad_ignore,
   182        bad_body
   183      } badopt;                   /* how to deal with bad headers */
   184      char badopt_set;
   185  /* putting new stuff on the end maximises binary back-compatibility.
   186   * the strmatch_patterns are really a const just to have a
   187   * case-independent strstr.
   188   */
   189      enum {
   190          status_off,
   191          status_on,
   192          status_full
   193      } proxy_status;             /* Status display options */
   194      char proxy_status_set;
   195      apr_pool_t *pool;           /* Pool used for allocating this struct */
   196      server_rec *s;              /* The server_rec where this configuration was created in */
   197  } proxy_server_conf;
   198  
   199  
   200  typedef struct {
   201      const char *p;            /* The path */
   202      int         p_is_fnmatch; /* Is this path an fnmatch candidate? */
   203      ap_regex_t  *r;            /* Is this a regex? */
   204  
   205  /* ProxyPassReverse and friends are documented as working inside
   206   * <Location>.  But in fact they never have done in the case of
   207   * more than one <Location>, because the server_conf can't see it.
   208   * We need to move them to the per-dir config.
   209   * Discussed in February:
   210   * http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=110726027118798&w=2
   211   */
   212      apr_array_header_t *raliases;
   213      apr_array_header_t* cookie_paths;
   214      apr_array_header_t* cookie_domains;
   215      const apr_strmatch_pattern* cookie_path_str;
   216      const apr_strmatch_pattern* cookie_domain_str;
   217      const char *ftp_directory_charset;
   218      int interpolate_env;
   219  } proxy_dir_conf;
   220  
   221  /* if we interpolate env vars per-request, we'll need a per-request
   222   * copy of the reverse proxy config
   223   */
   224  typedef struct {
   225      apr_array_header_t *raliases;
   226      apr_array_header_t* cookie_paths;
   227      apr_array_header_t* cookie_domains;
   228  } proxy_req_conf;
   229  
   230  typedef struct {
   231      conn_rec     *connection;
   232      const char   *hostname;
   233      apr_port_t   port;
   234      int          is_ssl;
   235      apr_pool_t   *pool;     /* Subpool for hostname and addr data */
   236      apr_socket_t *sock;     /* Connection socket */
   237      apr_sockaddr_t *addr;   /* Preparsed remote address info */
   238      apr_uint32_t flags;     /* Conection flags */
   239      int          close;     /* Close 'this' connection */
   240      int          close_on_recycle; /* Close the connection when returning to pool */
   241      proxy_worker *worker;   /* Connection pool this connection belongs to */
   242      void         *data;     /* per scheme connection data */
   243  #if APR_HAS_THREADS
   244      int          inreslist; /* connection in apr_reslist? */
   245  #endif
   246      apr_pool_t   *scpool;   /* Subpool used for socket and connection data */
   247      request_rec  *r;        /* Request record of the frontend request
   248                               * which the backend currently answers. */
   249      int          need_flush;/* Flag to decide whether we need to flush the
   250                               * filter chain or not */
   251      void         *forward;  /* opaque forward proxy data */
   252      const char   *ssl_hostname;/* Hostname (SNI) in use by SSL connection */
   253  } proxy_conn_rec;
   254  
   255  typedef struct {
   256          float cache_completion; /* completion percentage */
   257          int content_length; /* length of the content */
   258  } proxy_completion;
   259  
   260  /* Connection pool */
   261  struct proxy_conn_pool {
   262      apr_pool_t     *pool;   /* The pool used in constructor and destructor calls */
   263      apr_sockaddr_t *addr;   /* Preparsed remote address info */
   264  #if APR_HAS_THREADS
   265      apr_reslist_t  *res;    /* Connection resource list */
   266  #endif
   267      proxy_conn_rec *conn;   /* Single connection for prefork mpm's */
   268  };
   269  
   270  /* worker status flags */
   271  #define PROXY_WORKER_INITIALIZED    0x0001
   272  #define PROXY_WORKER_IGNORE_ERRORS  0x0002
   273  #define PROXY_WORKER_IN_SHUTDOWN    0x0010
   274  #define PROXY_WORKER_DISABLED       0x0020
   275  #define PROXY_WORKER_STOPPED        0x0040
   276  #define PROXY_WORKER_IN_ERROR       0x0080
   277  #define PROXY_WORKER_HOT_STANDBY    0x0100
   278  
   279  #define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
   280  PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
   281  
   282  /* NOTE: these check the shared status */
   283  #define PROXY_WORKER_IS_INITIALIZED(f)   ( (f)->s && \
   284    ( (f)->s->status &  PROXY_WORKER_INITIALIZED ) )
   285  
   286  #define PROXY_WORKER_IS_STANDBY(f)   ( (f)->s && \
   287    ( (f)->s->status &  PROXY_WORKER_HOT_STANDBY ) )
   288  
   289  #define PROXY_WORKER_IS_USABLE(f)   ( (f)->s && \
   290    ( !( (f)->s->status & PROXY_WORKER_NOT_USABLE_BITMAP) ) && \
   291    PROXY_WORKER_IS_INITIALIZED(f) )
   292  
   293  /* default worker retry timeout in seconds */
   294  #define PROXY_WORKER_DEFAULT_RETRY  60
   295  #define PROXY_WORKER_MAX_ROUTE_SIZ  63
   296  
   297  /* RFC-1035 mentions limits of 255 for host-names and 253 for domain-names,
   298   * dotted together(?) this would fit the below size (+ trailing NUL).
   299   */
   300  #define PROXY_WORKER_RFC1035_NAME_SIZE  512
   301  
   302  /* Scoreboard */
   303  #if MODULE_MAGIC_NUMBER_MAJOR > 20020903
   304  #define PROXY_HAS_SCOREBOARD 1
   305  #else
   306  #define PROXY_HAS_SCOREBOARD 0
   307  #endif
   308  
   309  /* Runtime worker status informations. Shared in scoreboard */
   310  typedef struct {
   311      int             status;
   312      apr_time_t      error_time; /* time of the last error */
   313      int             retries;    /* number of retries on this worker */
   314      int             lbstatus;   /* Current lbstatus */
   315      int             lbfactor;   /* dynamic lbfactor */
   316      apr_off_t       transferred;/* Number of bytes transferred to remote */
   317      apr_off_t       read;       /* Number of bytes read from remote */
   318      apr_size_t      elected;    /* Number of times the worker was elected */
   319      char            route[PROXY_WORKER_MAX_ROUTE_SIZ+1];
   320      char            redirect[PROXY_WORKER_MAX_ROUTE_SIZ+1];
   321      void            *context;   /* general purpose storage */
   322      apr_size_t      busy;       /* busyness factor */
   323      int             lbset;      /* load balancer cluster set */
   324  #if PROXY_HAS_SCOREBOARD
   325      unsigned char   digest[APR_MD5_DIGESTSIZE]; /* hash of the worker->name */
   326  #endif
   327  } proxy_worker_stat;
   328  
   329  /* Worker configuration */
   330  struct proxy_worker {
   331      int             id;         /* scoreboard id */
   332      apr_interval_time_t retry;  /* retry interval */
   333      int             lbfactor;   /* initial load balancing factor */
   334      const char      *name;
   335      const char      *scheme;    /* scheme to use ajp|http|https */
   336      const char      *hostname;  /* remote backend address */
   337      const char      *route;     /* balancing route */
   338      const char      *redirect;  /* temporary balancing redirection route */
   339      int             status;     /* temporary worker status */
   340      apr_port_t      port;
   341      int             min;        /* Desired minimum number of available connections */
   342      int             smax;       /* Soft maximum on the total number of connections */
   343      int             hmax;       /* Hard maximum on the total number of connections */
   344      apr_interval_time_t ttl;    /* maximum amount of time in seconds a connection
   345                                   * may be available while exceeding the soft limit */
   346      apr_interval_time_t timeout; /* connection timeout */
   347      char            timeout_set;
   348      apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
   349      char            acquire_set;
   350      apr_size_t      recv_buffer_size;
   351      char            recv_buffer_size_set;
   352      apr_size_t      io_buffer_size;
   353      char            io_buffer_size_set;
   354      char            keepalive;
   355      char            keepalive_set;
   356      proxy_conn_pool     *cp;        /* Connection pool to use */
   357      proxy_worker_stat   *s;         /* Shared data */
   358      void            *opaque;    /* per scheme worker data */
   359      int             is_address_reusable;
   360  #if APR_HAS_THREADS
   361      apr_thread_mutex_t  *mutex;  /* Thread lock for updating address cache */
   362  #endif
   363      void            *context;   /* general purpose storage */
   364      enum {
   365           flush_off,
   366           flush_on,
   367           flush_auto
   368      } flush_packets;           /* control AJP flushing */
   369      int             flush_wait;  /* poll wait time in microseconds if flush_auto */
   370      int             lbset;      /* load balancer cluster set */
   371      apr_interval_time_t ping_timeout;
   372      char ping_timeout_set;
   373      char            retry_set;
   374      char            disablereuse;
   375      char            disablereuse_set;
   376      apr_interval_time_t conn_timeout;
   377      char            conn_timeout_set;
   378      server_rec      *server;    /* The server_rec where this configuration was created in */
   379  };
   380  
   381  /*
   382   * Wait 10000 microseconds to find out if more data is currently
   383   * available at the backend. Just an arbitrary choose.
   384   */
   385  #define PROXY_FLUSH_WAIT 10000
   386  
   387  struct proxy_balancer {
   388      apr_array_header_t *workers; /* array of proxy_workers */
   389      const char *name;            /* name of the load balancer */
   390      const char *sticky;          /* sticky session identifier */
   391      int         sticky_force;    /* Disable failover for sticky sessions */
   392      apr_interval_time_t timeout; /* Timeout for waiting on free connection */
   393      int                 max_attempts; /* Number of attempts before failing */
   394      char                max_attempts_set;
   395      proxy_balancer_method *lbmethod;
   396  
   397      /* XXX: Perhaps we will need the proc mutex too.
   398       * Altrough we are only using arithmetic operations
   399       * it may lead to a incorrect calculations.
   400       * For now use only the thread mutex.
   401       */
   402  #if APR_HAS_THREADS
   403      apr_thread_mutex_t  *mutex;  /* Thread lock for updating lb params */
   404  #endif
   405      void            *context;   /* general purpose storage */
   406      int             scolonsep;  /* true if ';' seps sticky session paths */
   407  
   408      apr_array_header_t *errstatuses; /* statuses to force members into error */
   409      int forcerecovery; /* Force recovery if all workers are in error state */
   410      int failontimeout;          /* Whether to mark a member in Err if IO timeout occurs */
   411  };
   412  
   413  struct proxy_balancer_method {
   414      const char *name;            /* name of the load balancer method*/
   415      proxy_worker *(*finder)(proxy_balancer *balancer,
   416                              request_rec *r);
   417      void            *context;   /* general purpose storage */
   418  };
   419  
   420  #if APR_HAS_THREADS
   421  #define PROXY_THREAD_LOCK(x)      apr_thread_mutex_lock((x)->mutex)
   422  #define PROXY_THREAD_UNLOCK(x)    apr_thread_mutex_unlock((x)->mutex)
   423  #else
   424  #define PROXY_THREAD_LOCK(x)      APR_SUCCESS
   425  #define PROXY_THREAD_UNLOCK(x)    APR_SUCCESS
   426  #endif
   427  
   428  /* hooks */
   429  
   430  /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and 
   431   * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
   432   */
   433  #if !defined(WIN32)
   434  #define PROXY_DECLARE(type)            type
   435  #define PROXY_DECLARE_NONSTD(type)     type
   436  #define PROXY_DECLARE_DATA
   437  #elif defined(PROXY_DECLARE_STATIC)
   438  #define PROXY_DECLARE(type)            type __stdcall
   439  #define PROXY_DECLARE_NONSTD(type)     type
   440  #define PROXY_DECLARE_DATA
   441  #elif defined(PROXY_DECLARE_EXPORT)
   442  #define PROXY_DECLARE(type)            __declspec(dllexport) type __stdcall
   443  #define PROXY_DECLARE_NONSTD(type)     __declspec(dllexport) type
   444  #define PROXY_DECLARE_DATA             __declspec(dllexport)
   445  #else
   446  #define PROXY_DECLARE(type)            __declspec(dllimport) type __stdcall
   447  #define PROXY_DECLARE_NONSTD(type)     __declspec(dllimport) type
   448  #define PROXY_DECLARE_DATA             __declspec(dllimport)
   449  #endif
   450  
   451  /**
   452   * Hook an optional proxy hook.  Unlike static hooks, this uses a macro
   453   * instead of a function.
   454   */
   455  #define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
   456          APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
   457  
   458  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r, 
   459                            proxy_worker *worker, proxy_server_conf *conf, char *url, 
   460                            const char *proxyhost, apr_port_t proxyport))
   461  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r, 
   462                            char *url))
   463  
   464  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
   465  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r)) 
   466  
   467  /**
   468   * pre request hook.
   469   * It will return the most suitable worker at the moment
   470   * and coresponding balancer.
   471   * The url is rewritten from balancer://cluster/uri to scheme://host:port/uri
   472   * and then the scheme_handler is called.
   473   *
   474   */
   475  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
   476                            proxy_balancer **balancer,
   477                            request_rec *r,
   478                            proxy_server_conf *conf, char **url))                          
   479  /**
   480   * post request hook.
   481   * It is called after request for updating runtime balancer status.
   482   */
   483  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, post_request, (proxy_worker *worker,
   484                            proxy_balancer *balancer, request_rec *r,
   485                            proxy_server_conf *conf))
   486  
   487  /**
   488   * request status hook
   489   * It is called after all proxy processing has been done.  This gives other
   490   * modules a chance to create default content on failure, for example
   491   */
   492  APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status,
   493                            (int *status, request_rec *r))
   494  
   495  /* proxy_util.c */
   496  
   497  PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
   498  PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
   499  PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
   500  PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
   501                                         int forcedec, int proxyreq);
   502  PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
   503                                             char **passwordp, char **hostp, apr_port_t *port);
   504  PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
   505  PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
   506  PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
   507  PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
   508  PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
   509  PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
   510  PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
   511  PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
   512  PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
   513  PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
   514  PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
   515  PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
   516  PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, apr_size_t bufflen, int *eos);
   517  PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
   518  /* DEPRECATED (will be replaced with ap_proxy_connect_backend */
   519  PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, server_rec *, apr_pool_t *);
   520  PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec *conn,
   521                                                              request_rec *r);
   522  PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
   523  PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
   524  PROXY_DECLARE(int) ap_proxy_conn_is_https(conn_rec *c);
   525  PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
   526  
   527  /* Header mapping functions, and a typedef of their signature */
   528  PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
   529  PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
   530  
   531  #if !defined(WIN32)
   532  typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
   533                         proxy_dir_conf *, const char *);
   534  #elif defined(PROXY_DECLARE_STATIC)
   535  typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
   536                                   proxy_dir_conf *, const char *);
   537  #elif defined(PROXY_DECLARE_EXPORT)
   538  typedef __declspec(dllexport) const char *
   539    (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
   540                 proxy_dir_conf *, const char *);
   541  #else
   542  typedef __declspec(dllimport) const char *
   543    (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
   544                 proxy_dir_conf *, const char *);
   545  #endif
   546  
   547  
   548  /* Connection pool API */
   549  /**
   550   * Get the worker from proxy configuration
   551   * @param p     memory pool used for finding worker
   552   * @param conf  current proxy server configuration
   553   * @param url   url to find the worker from
   554   * @return      proxy_worker or NULL if not found
   555   */
   556  PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
   557                                                    proxy_server_conf *conf,
   558                                                    const char *url);
   559  /**
   560   * Add the worker to proxy configuration
   561   * @param worker the new worker
   562   * @param p      memory pool to allocate worker from 
   563   * @param conf   current proxy server configuration
   564   * @param url    url containing worker name
   565   * @return       error message or NULL if successfull
   566   */
   567  PROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker,
   568                                                  apr_pool_t *p,
   569                                                  proxy_server_conf *conf,
   570                                                  const char *url);
   571  
   572  /**
   573   * Create new worker
   574   * @param p      memory pool to allocate worker from 
   575   * @return       new worker
   576   */
   577  PROXY_DECLARE(proxy_worker *) ap_proxy_create_worker(apr_pool_t *p);
   578  
   579  /**
   580   * Initize the worker's shared data
   581   * @param conf   current proxy server configuration
   582   * @param worker worker to initialize
   583   * @param s      current server record
   584   * @param worker worker to initialize
   585   */
   586  PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
   587                                                       proxy_worker *worker,
   588                                                       server_rec *s);
   589  
   590  
   591  /**
   592   * Initize the worker
   593   * @param worker worker to initialize
   594   * @param s      current server record
   595   * @return       APR_SUCCESS or error code
   596   */
   597  PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
   598                                                         server_rec *s);
   599  /**
   600   * Get the balancer from proxy configuration
   601   * @param p     memory pool used for finding balancer
   602   * @param conf  current proxy server configuration
   603   * @param url   url to find the worker from. Has to have balancer:// prefix
   604   * @return      proxy_balancer or NULL if not found
   605   */
   606  PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p,
   607                                                        proxy_server_conf *conf,
   608                                                        const char *url);
   609  /**
   610   * Add the balancer to proxy configuration
   611   * @param balancer the new balancer
   612   * @param p      memory pool to allocate balancer from 
   613   * @param conf   current proxy server configuration
   614   * @param url    url containing balancer name
   615   * @return       error message or NULL if successfull
   616   */
   617  PROXY_DECLARE(const char *) ap_proxy_add_balancer(proxy_balancer **balancer,
   618                                                    apr_pool_t *p,
   619                                                    proxy_server_conf *conf,
   620                                                    const char *url);
   621  
   622  /**
   623   * Add the worker to the balancer
   624   * @param pool     memory pool for adding worker 
   625   * @param balancer balancer to add to
   626   * @param balancer worker to add
   627   * @note Single worker can be added to multiple balancers.
   628   */
   629  PROXY_DECLARE(void) ap_proxy_add_worker_to_balancer(apr_pool_t *pool,
   630                                                      proxy_balancer *balancer,
   631                                                      proxy_worker *worker);
   632  /**
   633   * Get the most suitable worker and(or) balancer for the request
   634   * @param worker   worker used for processing request
   635   * @param balancer balancer used for processing request
   636   * @param r        current request
   637   * @param conf     current proxy server configuration
   638   * @param url      request url that balancer can rewrite.
   639   * @return         OK or  HTTP_XXX error 
   640   * @note It calls balancer pre_request hook if the url starts with balancer://
   641   * The balancer then rewrites the url to particular worker, like http://host:port
   642   */
   643  PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
   644                                          proxy_balancer **balancer,
   645                                          request_rec *r,
   646                                          proxy_server_conf *conf,
   647                                          char **url);
   648  /**
   649   * Post request worker and balancer cleanup
   650   * @param worker   worker used for processing request
   651   * @param balancer balancer used for processing request
   652   * @param r        current request
   653   * @param conf     current proxy server configuration
   654   * @return         OK or  HTTP_XXX error
   655   * @note When ever the pre_request is called, the post_request has to be
   656   * called too. 
   657   */
   658  PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
   659                                           proxy_balancer *balancer,
   660                                           request_rec *r,
   661                                           proxy_server_conf *conf);
   662  
   663  /**
   664   * Deternime backend hostname and port
   665   * @param p       memory pool used for processing
   666   * @param r       current request
   667   * @param conf    current proxy server configuration
   668   * @param worker  worker used for processing request
   669   * @param conn    proxy connection struct
   670   * @param uri     processed uri
   671   * @param url     request url
   672   * @param proxyname are we connecting directly or via s proxy
   673   * @param proxyport proxy host port
   674   * @param server_portstr Via headers server port
   675   * @param server_portstr_size size of the server_portstr buffer
   676   * @return         OK or HTTP_XXX error
   677   */                                         
   678  PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
   679                                                   proxy_server_conf *conf,
   680                                                   proxy_worker *worker,
   681                                                   proxy_conn_rec *conn,
   682                                                   apr_uri_t *uri,
   683                                                   char **url,
   684                                                   const char *proxyname,
   685                                                   apr_port_t proxyport,
   686                                                   char *server_portstr,
   687                                                   int server_portstr_size);
   688  /**
   689   * Mark a worker for retry
   690   * @param proxy_function calling proxy scheme (http, ajp, ...)
   691   * @param conf    current proxy server configuration
   692   * @param worker  worker used for retrying
   693   * @param s       current server record
   694   * @return        OK if marked for retry, DECLINED otherwise
   695   * @note Worker will be marker for retry if the time of the last retry
   696   * has been ellapsed. In case there is no retry option set, defaults to
   697   * number_of_retries seconds.
   698   */                                         
   699  PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
   700                                           proxy_worker *worker,
   701                                           server_rec *s);
   702  /**
   703   * Acquire a connection from workers connection pool
   704   * @param proxy_function calling proxy scheme (http, ajp, ...)
   705   * @param conn    acquired connection
   706   * @param worker  worker used for obtaining connection
   707   * @param s       current server record
   708   * @return        OK or HTTP_XXX error
   709   * @note If the number of connections is exhaused the function will
   710   * block untill the timeout is reached.
   711   */                                         
   712  PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
   713                                                 proxy_conn_rec **conn,
   714                                                 proxy_worker *worker,
   715                                                 server_rec *s);
   716  /**
   717   * Release a connection back to worker connection pool
   718   * @param proxy_function calling proxy scheme (http, ajp, ...)
   719   * @param conn    acquired connection
   720   * @param s       current server record
   721   * @return        OK or HTTP_XXX error
   722   * @note The connection will be closed if conn->close_on_release is set
   723   */                                         
   724  PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
   725                                                 proxy_conn_rec *conn,
   726                                                 server_rec *s);
   727  /**
   728   * Make a connection to the backend
   729   * @param proxy_function calling proxy scheme (http, ajp, ...)
   730   * @param conn    acquired connection
   731   * @param worker  connection worker
   732   * @param s       current server record
   733   * @return        OK or HTTP_XXX error
   734   * @note In case the socket already exists for conn, just check the link
   735   * status.
   736   */                                         
   737  PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
   738                                              proxy_conn_rec *conn,
   739                                              proxy_worker *worker,
   740                                              server_rec *s);
   741  /**
   742   * Make a connection record for backend connection
   743   * @param proxy_function calling proxy scheme (http, ajp, ...)
   744   * @param conn    acquired connection
   745   * @param c       client connection record
   746   * @param s       current server record
   747   * @return        OK or HTTP_XXX error
   748   */                                         
   749  PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
   750                                                proxy_conn_rec *conn,
   751                                                conn_rec *c, server_rec *s);
   752  
   753  /**
   754   * Determine if proxy connection can potentially be reused at the
   755   * end of this request.
   756   * @param conn proxy connection
   757   * @return non-zero if reusable, 0 otherwise
   758   * @note Even if this function returns non-zero, the connection may
   759   * be subsequently marked for closure.
   760   */
   761  PROXY_DECLARE(int) ap_proxy_connection_reusable(proxy_conn_rec *conn);
   762  
   763  /**
   764   * Signal the upstream chain that the connection to the backend broke in the
   765   * middle of the response. This is done by sending an error bucket with
   766   * status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
   767   * @param r       current request record of client request
   768   * @param brigade The brigade that is sent through the output filter chain
   769   */
   770  PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r,
   771                                             apr_bucket_brigade *brigade);
   772  
   773  /**
   774   * Transform buckets from one bucket allocator to another one by creating a
   775   * transient bucket for each data bucket and let it use the data read from
   776   * the old bucket. Metabuckets are transformed by just recreating them.
   777   * Attention: Currently only the following bucket types are handled:
   778   *
   779   * All data buckets
   780   * FLUSH
   781   * EOS
   782   *
   783   * If an other bucket type is found its type is logged as a debug message
   784   * and APR_EGENERAL is returned.
   785   * @param r    current request record of client request. Only used for logging
   786   *             purposes
   787   * @param from the brigade that contains the buckets to transform
   788   * @param to   the brigade that will receive the transformed buckets
   789   * @return     APR_SUCCESS if all buckets could be transformed APR_EGENERAL
   790   *             otherwise
   791   */
   792  PROXY_DECLARE(apr_status_t)
   793  ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from,
   794                                          apr_bucket_brigade *to);
   795  
   796  #if PROXY_HAS_SCOREBOARD
   797  PROXY_DECLARE(void*) ap_proxy_set_scoreboard_lb(proxy_worker *worker,
   798                                                  proxy_balancer *balancer,
   799                                                  server_rec *server);
   800  #endif
   801  
   802  #define PROXY_LBMETHOD "proxylbmethod"
   803  
   804  /* The number of dynamic workers that can be added when reconfiguring.
   805   * If this limit is reached you must stop and restart the server.
   806   */
   807  #define PROXY_DYNAMIC_BALANCER_LIMIT    16
   808  /**
   809   * Calculate number of maximum number of workers in scoreboard.
   810   * @return  number of workers to allocate in the scoreboard
   811   */
   812  int ap_proxy_lb_workers(void);
   813  
   814  /* For proxy_util */
   815  extern module PROXY_DECLARE_DATA proxy_module;
   816  
   817  extern int PROXY_DECLARE_DATA proxy_lb_workers;
   818  
   819  #endif /*MOD_PROXY_H*/
   820  /** @} */