apr_array_header_t *workers;
apr_array_header_t *balancers;
proxy_worker *forward; /* forward proxy worker */
+ proxy_worker *reverse; /* reverse "module-driven" proxy worker */
const char *domain; /* domain name to use in absence of a domain name in the request */
int req; /* true if proxy requests are enabled */
char req_set;
#if APR_HAS_THREADS
apr_reslist_t *res; /* Connection resource list */
#endif
- int nfree; /* Balancer free count number */
proxy_conn_rec *conn; /* Single connection for prefork mpm's */
};
#define PROXY_WORKER_DISABLED 0x0020
#define PROXY_WORKER_IN_ERROR 0x0040
-#define PROXY_WORKER_IS_USABLE(f) (!((f)->status & 0x00F0))
+#define PROXY_WORKER_IS_USABLE(f) (!((f)->s->status & 0x00F0))
+/* default worker retry timeout in seconds */
+#define PROXY_WORKER_DEFAULT_RETRY 60
+#define PROXY_WORKER_MAX_ROUTE_SIZ 63
-/* Worker configuration */
-struct proxy_worker {
+/* Runtime worker status informations. Shared in scoreboard */
+typedef struct {
int status;
apr_time_t error_time; /* time of the last error */
- apr_interval_time_t retry; /* retry interval */
int retries; /* number of retries on this worker */
+ int lbstatus; /* Current lbstatus */
+ int lbfactor; /* dynamic lbfactor */
+ apr_off_t transferred;/* Number of bytes transferred to remote */
+ apr_off_t read; /* Number of bytes read from remote */
+ apr_size_t elected; /* Number of times the worker was elected */
+ char route[PROXY_WORKER_MAX_ROUTE_SIZ+1];
+ char redirect[PROXY_WORKER_MAX_ROUTE_SIZ+1];
+} proxy_worker_stat;
+
+/* Worker configuration */
+struct proxy_worker {
+ int id; /* scoreboard id */
+ apr_interval_time_t retry; /* retry interval */
int lbfactor; /* initial load balancing factor */
const char *name;
const char *scheme; /* scheme to use ajp|http|https */
char io_buffer_size_set;
char keepalive;
char keepalive_set;
- proxy_conn_pool *cp; /* Connection pool to use */
- void *opaque; /* per scheme worker data */
+ proxy_conn_pool *cp; /* Connection pool to use */
+ proxy_worker_stat *s; /* Shared data */
+ void *opaque; /* per scheme worker data */
+ int is_address_reusable;
+#if APR_HAS_THREADS
+ apr_thread_mutex_t *mutex; /* Thread lock for updating address cache */
+#endif
};
-/* Runtime worker status informations. Shared in scoreboard */
-typedef struct {
- int id; /* scoreboard id */
- double lbstatus; /* Current lbstatus */
- double lbfactor; /* dynamic lbfactor */
- apr_size_t transfered; /* Number of bytes transfered to remote */
- apr_size_t readed; /* Number of bytes readed from remote */
- apr_size_t elected; /* Number of times the worker was elected */
-} proxy_runtime_stat;
-
-/* Runtime worker. */
-typedef struct {
- proxy_balancer *b; /* balancer containing this worker */
- proxy_worker *w;
- proxy_runtime_stat *s;
-} proxy_runtime_worker;
-
struct proxy_balancer {
- apr_array_header_t *workers; /* array of proxy_runtime_workers */
+ apr_array_header_t *workers; /* array of proxy_workers */
const char *name; /* name of the load balancer */
const char *sticky; /* sticky session identifier */
int sticky_force; /* Disable failover for sticky sessions */
apr_interval_time_t timeout; /* Timeout for waiting on free connection */
+ int max_attempts; /* Number of attempts before failing */
+ char max_attempts_set;
+ enum {
+ lbmethod_requests = 1,
+ lbmethod_traffic = 2
+ } lbmethod;
+
/* XXX: Perhaps we will need the proc mutex too.
* Altrough we are only using arithmetic operations
* it may lead to a incorrect calculations.
#endif
};
+#if APR_HAS_THREADS
+#define PROXY_THREAD_LOCK(x) apr_thread_mutex_lock((x)->mutex)
+#define PROXY_THREAD_UNLOCK(x) apr_thread_mutex_unlock((x)->mutex)
+#else
+#define PROXY_THREAD_LOCK(x) APR_SUCCESS
+#define PROXY_THREAD_UNLOCK(x) APR_SUCCESS
+#endif
+
/* hooks */
/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
- int isenc);
+ int forcedec, int proxyreq);
PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
char **passwordp, char **hostp, apr_port_t *port);
PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
+/* Header mapping functions, and a typedef of their signature */
+PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_server_conf *conf, const char *url);
+PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_server_conf *conf, const char *str);
+
+#if !defined(WIN32)
+typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
+ proxy_server_conf *, const char *);
+#elif defined(PROXY_DECLARE_STATIC)
+typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
+ proxy_server_conf *, const char *);
+#elif defined(PROXY_DECLARE_EXPORT)
+typedef __declspec(dllexport) const char *
+ (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
+ proxy_server_conf *, const char *);
+#else
+typedef __declspec(dllimport) const char *
+ (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
+ proxy_server_conf *, const char *);
+#endif
+
+
/* Connection pool API */
/**
* Get the worker from proxy configuration
apr_pool_t *p,
proxy_server_conf *conf,
const char *url);
+
+/**
+ * Create new worker
+ * @param p memory pool to allocate worker from
+ * @return new worker
+ */
+PROXY_DECLARE(proxy_worker *) ap_proxy_create_worker(apr_pool_t *p);
+
+/**
+ * Initize the worker's shared data
+ * @param conf current proxy server configuration
+ * @param worker worker to initialize
+ * @param s current server record
+ * @param worker worker to initialize
+ */
+PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
+ proxy_worker *worker,
+ server_rec *s);
+
+
+/**
+ * Initize the worker
+ * @param worker worker to initialize
+ * @param s current server record
+ * @return APR_SUCCESS or error code
+ */
+PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
+ server_rec *s);
/**
* Get the balancer from proxy configuration
* @param p memory pool used for finding balancer
* @param conf current proxy server configuration
* @param worker worker used for processing request
* @param conn proxy connection struct
- * @param ppool long living memory pool
* @param uri processed uri
* @param url request url
* @param proxyname are we connecting directly or via s proxy
proxy_server_conf *conf,
proxy_worker *worker,
proxy_conn_rec *conn,
- apr_pool_t *ppool,
apr_uri_t *uri,
char **url,
const char *proxyname,
PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
proxy_conn_rec *conn,
server_rec *s);
-/**
- * Close the connection
- * @param conn connection to close
- * @return APR_SUCCESS or error code
- */
-PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn);
-
/**
* Make a connection to the backend
* @param proxy_function calling proxy scheme (http, ajp, ...)
#else
#define PROXY_HAS_SCOREBOARD 0
#endif
-/* The number of dynamic balancers that can be added */
+
+/* The number of dynamic workers that can be added when reconfiguring.
+ * If this limit is reached you must stop and restart the server.
+ */
#define PROXY_DYNAMIC_BALANCER_LIMIT 16
-PROXY_DECLARE(int) ap_proxy_lb_workers(void);
+/**
+ * Calculate number of maximum number of workers in scoreboard.
+ * @return number of workers to allocate in the scoreboard
+ */
+int ap_proxy_lb_workers(void);
/* For proxy_util */
extern module PROXY_DECLARE_DATA proxy_module;
+extern int PROXY_DECLARE_DATA proxy_lb_workers;
+
#endif /*MOD_PROXY_H*/