Author: jfrederic.clere(a)jboss.com
Date: 2008-06-11 10:16:31 -0400 (Wed, 11 Jun 2008)
New Revision: 1693
Added:
trunk/mod_cluster/native/advertise/
trunk/mod_cluster/native/advertise/Makefile.in
trunk/mod_cluster/native/advertise/README
trunk/mod_cluster/native/advertise/buildconf
trunk/mod_cluster/native/advertise/configure.in
trunk/mod_cluster/native/advertise/mod_advertise.c
trunk/mod_cluster/native/advertise/mod_advertise.h
Removed:
trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in
trunk/httpd/httpd-2.2/modules/advertise/README
trunk/httpd/httpd-2.2/modules/advertise/buildconf
trunk/httpd/httpd-2.2/modules/advertise/configure.in
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Put the files in mod_cluster directory.
Deleted: trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in 2008-06-11 14:15:14 UTC (rev
1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in 2008-06-11 14:16:31 UTC (rev
1693)
@@ -1,23 +0,0 @@
-# Makefile.in for mod_proxy_cluster
-# copy the source in the httpd Apache source tree
-APACHE_BASE = @APACHE_BASE@
-top_builddir = @APACHE_BASE@
-# For .deps.
-builddir = @CLUSTER_BASE@
-# For the apache includes
-top_srcdir = @APACHE_BASE@
-
-include $(APACHE_BASE)/build/rules.mk
-SH_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CC) -I../include -prefer-pic -c $<
&& touch $@
-
-all: mod_advertise.so
-
-mod_advertise.so: mod_advertise.la
- $(APACHE_BASE)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_advertise.la `pwd`
-
-mod_advertise.la: mod_advertise.slo
- $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_advertise.lo
-
-clean:
- rm -f *.o *.lo *.slo
- rm -rf .libs
Deleted: trunk/httpd/httpd-2.2/modules/advertise/README
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/README 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/README 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,17 +0,0 @@
-The source could be in httpd-2.2.x source tree.
-The ./buildconf must be run again amd the configure need at least:
-./configure --enable-advertise
-
-The source could build with a installed version of httpd-2-2.x:
-sh buildconf
-./configure --with-apache=apache_installation_directory.
-make -f Makefile.apxs
-The mod_advertise.so need to be copied to apache_installation_directory/modules
-
-Configuration use something like the following in httpd.conf:
-LoadModule advertise_module modules/mod_advertise.so
-ServerAdvertise on
-AdvertiseGroup 232.0.0.2
-AdvertiseFrequency 30
-
-Note default port is 23364.
Deleted: trunk/httpd/httpd-2.2/modules/advertise/buildconf
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/buildconf 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/buildconf 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-rm -rf aclocal.m4 autom4te*.cache
-
-echo "Creating configure ..."
-### do some work to toss config.cache?
-if ${AUTOCONF:-autoconf}; then
- :
-else
- echo "autoconf failed"
- exit 1
-fi
Deleted: trunk/httpd/httpd-2.2/modules/advertise/configure.in
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/configure.in 2008-06-11 14:15:14 UTC (rev
1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/configure.in 2008-06-11 14:16:31 UTC (rev
1693)
@@ -1,24 +0,0 @@
-dnl configure for mod_manager
-dnl
-
-AC_INIT(mod_advertise.c)
-
-AC_MSG_CHECKING(for Apache httpd installation)
-AC_ARG_WITH(apache,
-[ --with-apache[=DIR] DIR is the apache base installation
-],
-[ if test "$withval" = "yes"; then
- withval=/usr/local/etc/httpd
- fi
- if test "$withval" != "no"; then
- APACHE_BASE=$withval
- else
- AC_MSG_ERROR(mod_manager need a valid apache location)
- fi
-],
-[ AC_MSG_ERROR(Please use --with-apache[=DIR])])
-CLUSTER_BASE=`pwd`
-
-AC_SUBST(APACHE_BASE)
-AC_SUBST(CLUSTER_BASE)
-AC_OUTPUT(Makefile.apxs)
Deleted: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c 2008-06-11 14:15:14 UTC (rev
1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c 2008-06-11 14:16:31 UTC (rev
1693)
@@ -1,642 +0,0 @@
-/*
- * ModAdvertise - Apache Httpd advertising module
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * @author Mladen Turk
- */
-
-#define CORE_PRIVATE
-
-#include "mod_advertise.h"
-#include "mod_core.h"
-#include "util_script.h"
-
-#ifndef MAX
-#define MAX(x,y) ((x) >= (y) ? (x) : (y))
-#endif
-
-#define MOD_SRVCONF(p) ap_get_module_config((p)->server->module_config, \
- &advertise_module)
-#define MOD_GETCONF(s) ap_get_module_config((s)->module_config, \
- &advertise_module)
-
-/*
- * Declare ourselves so the configuration routines can find and know us.
- * We'll fill it in at the end of the module.
- */
-module AP_MODULE_DECLARE_DATA advertise_module;
-
-
-
-/*
- * Server private data
- */
-static int ma_generation = 0;
-static apr_time_t ma_child_started = 0;
-static pid_t ma_parent_pid = -1;
-
-/*
- * Global configuration
- */
-static int ma_manager_strict = 0;
-static int ma_advertise_set = 0;
-static int ma_advertise_run = 0;
-static int ma_advertise_stat = 0;
-static char *ma_advertise_adrs = NULL;
-static char *ma_advertise_adsi = NULL;
-static char *ma_advertise_srvm = NULL;
-static char *ma_advertise_srvh = NULL;
-static char *ma_advertise_srvs = NULL;
-static char *ma_advertise_srvi = NULL;
-static char *ma_advertise_uuid = NULL;
-
-static char *ma_advertise_skey = NULL;
-
-
-static ma_advertise_srv_t ma_advs_server;
-
-
-/* Advertise is by default turned off */
-static apr_port_t ma_advertise_port = MA_DEFAULT_ADVPORT;
-static apr_port_t ma_advertise_srvp = 0;
-static ma_advertise_e ma_advertise_mode = ma_advertise_off;
-static apr_interval_time_t ma_advertise_freq = MA_DEFAULT_ADV_FREQ;
-
-/* Advertise sockets */
-static apr_socket_t *ma_mgroup_socket = NULL;
-static apr_socket_t *ma_listen_socket = NULL;
-static apr_sockaddr_t *ma_mgroup_sa = NULL;
-static apr_sockaddr_t *ma_listen_sa = NULL;
-
-static server_rec *ma_server_rec = NULL;
-
-/* Advertise sequence number */
-static volatile apr_int64_t ma_sequence = 0;
-
-
-/* Parent and child manager thread statuses */
-static volatile int is_mp_running = 0;
-static volatile int is_mp_created = 0;
-
-/*
- * Server global data
- */
-typedef struct ma_global_data_t {
- int generation;
- unsigned char ssalt[APR_MD5_DIGESTSIZE];
- apr_uuid_t suuid;
- char srvid[APR_UUID_FORMATTED_LENGTH + 2];
- apr_pool_t *ppool;
- apr_pool_t *cpool;
-} ma_global_data_t;
-
-/*
- * Global data instance
- * For parent, registered in process pool
- */
-static ma_global_data_t *magd = NULL;
-
-/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
- * IPv4 match-any-address, 0.0.0.0. */
-#define IS_INADDR_ANY(addr) ((addr)->family == APR_INET && \
- (addr)->sa.sin.sin_addr.s_addr == INADDR_ANY)
-
-/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
- * IPv6 match-any-address, [::]. */
-#define IS_IN6ADDR_ANY(addr) ((addr)->family == APR_INET6 && \
- IN6_IS_ADDR_UNSPECIFIED(&(addr)->sa.sin6.sin6_addr))
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* ServerAdvertise directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_m(cmd_parms *cmd, void *dummy,
- const char *arg, const char *opt)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
-
- if (strcasecmp(arg, "Off") == 0)
- ma_advertise_mode = ma_advertise_off;
- else if (strcasecmp(arg, "On") == 0)
- ma_advertise_mode = ma_advertise_on;
- else
- return "ServerAdvertise must be Off or On";
- if (opt) {
- const char *p = ap_strstr_c(opt, "://");
- if (p) {
- ma_advertise_srvm = apr_pstrndup(cmd->pool, opt, p - opt);
- opt = p + 3;
- }
- if (apr_parse_addr_port(&ma_advertise_srvs,
- &ma_advertise_srvi,
- &ma_advertise_srvp,
- opt, cmd->pool) != APR_SUCCESS ||
- !ma_advertise_srvs ||
- !ma_advertise_srvp)
- return "Invalid ServerAdvertise Address";
- }
- return NULL;
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseGroup directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_g(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- if (ma_advertise_set)
- return "Duplicate AdvertiseGroup directives are not allowed";
-
- if (apr_parse_addr_port(&ma_advertise_adrs,
- &ma_advertise_adsi,
- &ma_advertise_port,
- arg, cmd->pool) != APR_SUCCESS)
- return "Invalid AdvertiseGroup address";
- if (!ma_advertise_adrs)
- return "Missing Ip part from AdvertiseGroup address";
- if (!ma_advertise_port)
- ma_advertise_port = MA_DEFAULT_ADVPORT;
- ma_advertise_set = 1;
- return NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseFrequency directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_f(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- apr_time_t s, u = 0;
- const char *p;
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- if ((p = ap_strchr_c(arg, '.')) || (p = ap_strchr_c(arg, ',')))
- u = atoi(p + 1);
-
- s = atoi(arg);
- ma_advertise_freq = s * APR_USEC_PER_SEC + u * APR_TIME_C(1000);
- if (ma_advertise_freq == 0)
- return "Invalid AdvertiseFrequency value";
-
- return NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseSecurityKey directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_k(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- ma_advertise_skey = apr_pstrdup(cmd->pool, arg);
- return NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseManagerUrl directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_h(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- ma_advertise_srvh = apr_pstrdup(cmd->pool, arg);
- return NULL;
-}
-
-#define MA_ADVERTISE_SERVER_FMT \
- "HTTP/1.0 %s" CRLF \
- "Date: %s" CRLF \
- "Sequence: %" APR_INT64_T_FMT CRLF \
- "Digest: %s" CRLF \
- "Server: %s" CRLF
-
-static const char *hex = "0123456789abcdef";
-
-apr_status_t ma_advertise_server(server_rec *server, int type)
-{
- char buf[MA_BSIZE];
- char dat[APR_RFC822_DATE_LEN];
- unsigned char msig[APR_MD5_DIGESTSIZE];
- unsigned char ssig[APR_MD5_DIGESTSIZE * 2 + 1];
- const char *asl;
- char *p = buf;
- int i, c = 0;
- apr_size_t l = MA_BSIZE - 8;
- apr_size_t n = 0;
- apr_md5_ctx_t md;
-
- ma_sequence++;
- if (ma_sequence < 1)
- ma_sequence = 1;
- sprintf(buf, "%" APR_INT64_T_FMT, ma_sequence);
- ap_recent_rfc822_date(dat, apr_time_now());
- asl = ap_get_status_line(ma_advertise_stat);
-
- /* Create MD5 digest
- * salt + date + sequence + srvid
- */
- apr_md5_init(&md);
- apr_md5_update(&md, magd->ssalt, APR_MD5_DIGESTSIZE);
- apr_md5_update(&md, dat, strlen(dat));
- apr_md5_update(&md, buf, strlen(buf));
- apr_md5_update(&md, magd->srvid + 1, strlen(magd->srvid) - 1);
- apr_md5_final(msig, &md);
- /* Convert MD5 digest to hex string */
- for (i = 0; i < APR_MD5_DIGESTSIZE; i++) {
- ssig[c++] = hex[msig[i] >> 4];
- ssig[c++] = hex[msig[i] & 0x0F];
- }
- ssig[c] = '\0';
- n = apr_snprintf(p, l, MA_ADVERTISE_SERVER_FMT,
- asl, dat, ma_sequence, ssig, magd->srvid + 1);
- if (type == MA_ADVERTISE_SERVER) {
- l -= n;
- n += apr_snprintf(p + n, l,
- "X-Manager-Address: %s:%u" CRLF
- "X-Manager-Url: %s" CRLF
- "X-Manager-Protocol: %s" CRLF
- "X-Manager-Host: %s" CRLF,
- ma_advertise_srvs,
- ma_advertise_srvp,
- ma_advertise_srvh,
- ma_advertise_srvm,
- server->server_hostname);
-
- }
- strcat(p, CRLF);
- n += 2;
- return apr_socket_sendto(ma_mgroup_socket,
- ma_mgroup_sa, 0, buf, &n);
-}
-
-static apr_status_t ma_group_join(const char *addr, apr_port_t port,
- apr_pool_t *pool)
-{
- apr_status_t rv;
-
- if ((rv = apr_sockaddr_info_get(&ma_mgroup_sa, addr,
- APR_INET, port,
- APR_UNSPEC, pool)) != APR_SUCCESS)
- return rv;
- if ((rv = apr_socket_create(&ma_mgroup_socket,
- ma_mgroup_sa->family,
- SOCK_DGRAM,
- APR_PROTO_UDP,
- pool)) != APR_SUCCESS)
- return rv;
- if ((rv = apr_mcast_join(ma_mgroup_socket, ma_mgroup_sa,
- NULL, NULL)) != APR_SUCCESS) {
- apr_socket_close(ma_mgroup_socket);
- return rv;
- }
- if ((rv = apr_mcast_hops(ma_mgroup_socket,
- MA_ADVERTISE_HOPS)) != APR_SUCCESS) {
- apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
- NULL, NULL);
- apr_socket_close(ma_mgroup_socket);
- return rv;
- }
- return APR_SUCCESS;
-}
-
-static void ma_group_leave()
-{
- if (ma_mgroup_socket) {
- apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
- NULL, NULL);
- apr_socket_close(ma_mgroup_socket);
- ma_mgroup_socket = NULL;
- }
-}
-
-static void * APR_THREAD_FUNC parent_thread(apr_thread_t *thd, void *data)
-{
- static int current_status = 0;
- int f_time = 1;
- apr_interval_time_t a_step = 0;
- server_rec *s = (server_rec *)data;
- is_mp_created = 1;
-
- while (is_mp_running) {
- apr_sleep(MA_TM_RESOLUTION);
- if (!is_mp_running)
- break;
- if (ma_advertise_run) {
- a_step += MA_TM_RESOLUTION;
- if (current_status != ma_advertise_stat) {
- /* Force advertise on status change */
- current_status = ma_advertise_stat;
- f_time = 1;
- }
- if (a_step >= ma_advertise_freq || f_time) {
- /* Run advertise */
- ma_advertise_server(s, MA_ADVERTISE_SERVER);
- a_step = 0;
- f_time = 0;
- }
- if (!is_mp_running)
- break;
- }
- /* TODO: Implement actual work for parent thread */
- if (!is_mp_running)
- break;
- }
- is_mp_created = 0;
- return NULL;
-}
-
-static apr_status_t pconfig_cleanup(void *data);
-
-static apr_status_t process_cleanup(void *data)
-{
- int advertise_run = ma_advertise_run;
-
- is_mp_running = 0;
- ma_advertise_run = 0;
- if (advertise_run) {
- ma_advertise_stat = HTTP_FORBIDDEN;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- }
- if (is_mp_created) {
- apr_sleep(1000);
- /* Wait for the parent maintenance thread to finish */
- while (is_mp_created) {
- apr_sleep(MA_TM_RESOLUTION);
- }
- }
- if (advertise_run) {
- ma_advertise_stat = HTTP_GONE;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- ma_group_leave();
- }
- /* We don't need the post_config cleanup to run,
- */
- apr_pool_cleanup_kill(magd->cpool, magd, pconfig_cleanup);
- magd = NULL;
-
- return APR_SUCCESS;
-}
-
-static apr_status_t pconfig_cleanup(void *data)
-{
- int advertise_run = ma_advertise_run;
-
- is_mp_running = 0;
- ma_advertise_run = 0;
- if (advertise_run) {
- ma_advertise_stat = HTTP_FORBIDDEN;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- }
-
- if (is_mp_created) {
- apr_sleep(1000);
- /* Wait for the parent maintenance thread to finish */
- while (is_mp_created) {
- apr_sleep(MA_TM_RESOLUTION);
- }
- }
- if (advertise_run) {
- ma_advertise_stat = HTTP_FORBIDDEN;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- }
- if (magd) {
- /* Remove the process_cleanup.
- * We need to reattach again because the
- * module can be reloaded on different address
- */
- apr_pool_cleanup_kill(magd->ppool, magd, process_cleanup);
- }
- return APR_SUCCESS;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* Post config hook. */
-/* Create management thread in parent and initializes Manager */
-/* */
-/*--------------------------------------------------------------------------*/
-static int post_config_hook(apr_pool_t *pconf, apr_pool_t *plog,
- apr_pool_t *ptemp, server_rec *s)
-{
- apr_status_t rv;
- const char *pk = "advertise_init_module_tag";
- apr_pool_t *pproc = s->process->pool;
- apr_thread_t *tp;
-
- apr_pool_userdata_get((void *)&magd, pk, pproc);
- if (!magd) {
- if (!(magd = apr_pcalloc(pproc, sizeof(ma_global_data_t))))
- return apr_get_os_error();
- apr_pool_create(&magd->ppool, pproc);
- apr_pool_userdata_set(magd, pk, apr_pool_cleanup_null, pproc);
- /* First time config phase -- skip. */
- return OK;
- }
-#if defined(WIN32)
- {
- const char *ppid = getenv("AP_PARENT_PID");
- if (ppid) {
- ma_parent_pid = atol(ppid);
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
- "[%" APR_PID_T_FMT " - %" APR_PID_T_FMT
- "] in child post config hook",
- getpid(), ma_parent_pid);
- return OK;
- }
- }
-#endif
- ma_server_rec = s;
- if (!magd->generation) {
- /* Favor dynamic configuration */
- if (ma_advertise_skey) {
- apr_md5_ctx_t mc;
- apr_md5_init(&mc);
- apr_md5_update(&mc, ma_advertise_skey, strlen(ma_advertise_skey));
- apr_md5_final(magd->ssalt, &mc);
- }
- apr_uuid_get(&magd->suuid);
- magd->srvid[0] = '/';
- apr_uuid_format(&magd->srvid[1], &magd->suuid);
- }
- if (!ma_advertise_srvh)
- ma_advertise_srvh = magd->srvid;
- if (!ma_advertise_srvm)
- ma_advertise_srvm = apr_pstrdup(pconf, "http");
-
- /* Check if we have advertise set */
- if (ma_advertise_mode != ma_advertise_off &&
- ma_advertise_set && ma_advertise_adrs) {
- rv = ma_group_join(ma_advertise_adrs, ma_advertise_port, pconf);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
- "mod_advertise: multicast join failed for %s:%d.",
- ma_advertise_adrs, ma_advertise_port);
- ma_advertise_run = 0;
- }
- else {
- ma_advertise_run = 1;
- ma_advertise_stat = 200;
- }
- }
-
- /* Create parent management thread */
- is_mp_running = 1;
- rv = apr_thread_create(&tp, NULL, parent_thread, s, pconf);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
- "mod_advertise: parent apr_thread_create");
- return rv;
- }
- apr_thread_detach(tp);
-
- /* Create cleanup pool that will be destroyed first
- * in future use new apr_pool_pre_cleanup_register from APR 1.3
- */
- apr_pool_create(&magd->cpool, pconf);
- apr_pool_cleanup_register(magd->cpool, magd, pconfig_cleanup,
- apr_pool_cleanup_null);
-
- if (magd->generation++) {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
- "Advertise reinitialized for process %" APR_PID_T_FMT,
- getpid());
- }
- else {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
- "Advertise initialized for process %" APR_PID_T_FMT,
- getpid());
- }
-
- apr_pool_cleanup_register(magd->ppool, magd, process_cleanup,
- apr_pool_cleanup_null);
-
-
-
- return OK;
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* List of directives specific to our module. */
-/* */
-/*--------------------------------------------------------------------------*/
-static const command_rec cmd_table[] =
-{
- AP_INIT_TAKE12(
- "ServerAdvertise", /* directive name */
- cmd_advertise_m, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Server advertise mode: On | Off [Address]"
- ),
- AP_INIT_TAKE1(
- "AdvertiseGroup", /* directive name */
- cmd_advertise_g, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Multicast group address"
- ),
- AP_INIT_TAKE1(
- "AdvertiseFrequency", /* directive name */
- cmd_advertise_f, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Advertise frequency in seconds[.miliseconds]"
- ),
- AP_INIT_TAKE1(
- "AdvertiseSecurityKey", /* directive name */
- cmd_advertise_k, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Advertise security key"
- ),
- AP_INIT_TAKE1(
- "AdvertiseManagerUrl", /* directive name */
- cmd_advertise_h, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Advertise manager url"
- ),
- {NULL}
-
-};
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* Which functions are responsible for which hooks in the server. */
-/* */
-/*--------------------------------------------------------------------------*/
-static void register_hooks(apr_pool_t *p)
-{
-
- /* Post config handling
- */
- ap_hook_post_config(post_config_hook,
- NULL,
- NULL,
- APR_HOOK_LAST);
-
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* The list of callback routines and data structures that provide */
-/* the static hooks into our module from the other parts of the server. */
-/* */
-/*--------------------------------------------------------------------------*/
-module AP_MODULE_DECLARE_DATA advertise_module =
-{
- STANDARD20_MODULE_STUFF,
- NULL, /* per-directory config creator */
- NULL, /* dir config merger */
- NULL, /* server config creator */
- NULL, /* server config merger */
- cmd_table, /* command table */
- register_hooks /* set up other request processing hooks */
-};
Deleted: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h 2008-06-11 14:15:14 UTC (rev
1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h 2008-06-11 14:16:31 UTC (rev
1693)
@@ -1,145 +0,0 @@
-/*
- * ModAdvertise - Apache Httpd advertising module
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * @author Mladen Turk
- */
-
-#ifndef MOD_ADVERTISE_H
-#define MOD_ADVERTISE_H
-
-/**
- * @file mod_advertise.h
- * @brief Advertise Module for Apache Httpd
- *
- * @defgroup MOD_ADVERTISE mod_advertise
- * @ingroup APACHE_MODS
- * @{
- */
-
-#define CORE_PRIVATE
-
-#include "apr_hooks.h"
-#include "apr.h"
-#include "apr_lib.h"
-#include "apr_strings.h"
-#include "apr_buckets.h"
-#include "apr_md5.h"
-#include "apr_network_io.h"
-#include "apr_pools.h"
-#include "apr_strings.h"
-#include "apr_uri.h"
-#include "apr_date.h"
-#include "apr_uuid.h"
-#include "apr_version.h"
-#include "apr_atomic.h"
-
-#define APR_WANT_STRFUNC
-#include "apr_want.h"
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_request.h"
-#include "http_vhost.h"
-#include "http_main.h"
-#include "http_log.h"
-#include "http_connection.h"
-#include "util_filter.h"
-#include "util_ebcdic.h"
-#include "util_time.h"
-#include "ap_provider.h"
-#include "ap_mpm.h"
-
-#if APR_HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#if APR_HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#if !APR_HAS_THREADS
-#error This module does not compile unless you have a thread capable APR!
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define MA_BSIZE 4096
-#define MA_SSIZE 1024
-#define MA_DEFAULT_ADVPORT 23364
-#define MA_TM_RESOLUTION APR_TIME_C(100000)
-#define MA_DEFAULT_ADV_FREQ apr_time_from_sec(10)
-#define MA_TM_MAINTAIN_STEP 10
-
-/**
- * Multicast Time to Live (ttl) for a advertise transmission.
- */
-#define MA_ADVERTISE_HOPS 10
-
-/**
- * Advertise protocol types
- */
-#define MA_ADVERTISE_SERVER 0
-#define MA_ADVERTISE_STATUS 1
-
-/**
- * Advertise mode enumeration.
- */
-typedef enum {
- ma_advertise_off,
- ma_advertise_status,
- ma_advertise_on
-} ma_advertise_e;
-
-/**
- * Advertise header data structure
- */
-typedef struct ma_advertise_hdr_t ma_advertise_hdr_t;
-struct ma_advertise_hdr_t {
- int type;
- apr_status_t status;
- char suuid[APR_UUID_FORMATTED_LENGTH + 1];
-};
-
-/**
- * Advertise server data structure
- */
-typedef struct ma_advertise_srv_t ma_advertise_srv_t;
-struct ma_advertise_srv_t {
- const char *handle;
- const char *address;
- const char *protocol;
- server_rec *server;
- apr_port_t port;
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-/** @} */
-#endif /* MOD_ADVERTISE_H */
Copied: trunk/mod_cluster/native/advertise/Makefile.in (from rev 1691,
trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in)
===================================================================
--- trunk/mod_cluster/native/advertise/Makefile.in (rev 0)
+++ trunk/mod_cluster/native/advertise/Makefile.in 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,23 @@
+# Makefile.in for mod_proxy_cluster
+# copy the source in the httpd Apache source tree
+APACHE_BASE = @APACHE_BASE@
+top_builddir = @APACHE_BASE@
+# For .deps.
+builddir = @CLUSTER_BASE@
+# For the apache includes
+top_srcdir = @APACHE_BASE@
+
+include $(APACHE_BASE)/build/rules.mk
+SH_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CC) -I../include -prefer-pic -c $<
&& touch $@
+
+all: mod_advertise.so
+
+mod_advertise.so: mod_advertise.la
+ $(APACHE_BASE)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_advertise.la `pwd`
+
+mod_advertise.la: mod_advertise.slo
+ $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_advertise.lo
+
+clean:
+ rm -f *.o *.lo *.slo
+ rm -rf .libs
Copied: trunk/mod_cluster/native/advertise/README (from rev 1691,
trunk/httpd/httpd-2.2/modules/advertise/README)
===================================================================
--- trunk/mod_cluster/native/advertise/README (rev 0)
+++ trunk/mod_cluster/native/advertise/README 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,17 @@
+The source could be in httpd-2.2.x source tree.
+The ./buildconf must be run again amd the configure need at least:
+./configure --enable-advertise
+
+The source could build with a installed version of httpd-2-2.x:
+sh buildconf
+./configure --with-apache=apache_installation_directory.
+make -f Makefile.apxs
+The mod_advertise.so need to be copied to apache_installation_directory/modules
+
+Configuration use something like the following in httpd.conf:
+LoadModule advertise_module modules/mod_advertise.so
+ServerAdvertise on
+AdvertiseGroup 232.0.0.2
+AdvertiseFrequency 30
+
+Note default port is 23364.
Copied: trunk/mod_cluster/native/advertise/buildconf (from rev 1691,
trunk/httpd/httpd-2.2/modules/advertise/buildconf)
===================================================================
--- trunk/mod_cluster/native/advertise/buildconf (rev 0)
+++ trunk/mod_cluster/native/advertise/buildconf 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+rm -rf aclocal.m4 autom4te*.cache
+
+echo "Creating configure ..."
+### do some work to toss config.cache?
+if ${AUTOCONF:-autoconf}; then
+ :
+else
+ echo "autoconf failed"
+ exit 1
+fi
Copied: trunk/mod_cluster/native/advertise/configure.in (from rev 1691,
trunk/httpd/httpd-2.2/modules/advertise/configure.in)
===================================================================
--- trunk/mod_cluster/native/advertise/configure.in (rev 0)
+++ trunk/mod_cluster/native/advertise/configure.in 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,24 @@
+dnl configure for mod_manager
+dnl
+
+AC_INIT(mod_advertise.c)
+
+AC_MSG_CHECKING(for Apache httpd installation)
+AC_ARG_WITH(apache,
+[ --with-apache[=DIR] DIR is the apache base installation
+],
+[ if test "$withval" = "yes"; then
+ withval=/usr/local/etc/httpd
+ fi
+ if test "$withval" != "no"; then
+ APACHE_BASE=$withval
+ else
+ AC_MSG_ERROR(mod_manager need a valid apache location)
+ fi
+],
+[ AC_MSG_ERROR(Please use --with-apache[=DIR])])
+CLUSTER_BASE=`pwd`
+
+AC_SUBST(APACHE_BASE)
+AC_SUBST(CLUSTER_BASE)
+AC_OUTPUT(Makefile.apxs)
Copied: trunk/mod_cluster/native/advertise/mod_advertise.c (from rev 1691,
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c)
===================================================================
--- trunk/mod_cluster/native/advertise/mod_advertise.c (rev 0)
+++ trunk/mod_cluster/native/advertise/mod_advertise.c 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,642 @@
+/*
+ * ModAdvertise - Apache Httpd advertising module
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ */
+
+#define CORE_PRIVATE
+
+#include "mod_advertise.h"
+#include "mod_core.h"
+#include "util_script.h"
+
+#ifndef MAX
+#define MAX(x,y) ((x) >= (y) ? (x) : (y))
+#endif
+
+#define MOD_SRVCONF(p) ap_get_module_config((p)->server->module_config, \
+ &advertise_module)
+#define MOD_GETCONF(s) ap_get_module_config((s)->module_config, \
+ &advertise_module)
+
+/*
+ * Declare ourselves so the configuration routines can find and know us.
+ * We'll fill it in at the end of the module.
+ */
+module AP_MODULE_DECLARE_DATA advertise_module;
+
+
+
+/*
+ * Server private data
+ */
+static int ma_generation = 0;
+static apr_time_t ma_child_started = 0;
+static pid_t ma_parent_pid = -1;
+
+/*
+ * Global configuration
+ */
+static int ma_manager_strict = 0;
+static int ma_advertise_set = 0;
+static int ma_advertise_run = 0;
+static int ma_advertise_stat = 0;
+static char *ma_advertise_adrs = NULL;
+static char *ma_advertise_adsi = NULL;
+static char *ma_advertise_srvm = NULL;
+static char *ma_advertise_srvh = NULL;
+static char *ma_advertise_srvs = NULL;
+static char *ma_advertise_srvi = NULL;
+static char *ma_advertise_uuid = NULL;
+
+static char *ma_advertise_skey = NULL;
+
+
+static ma_advertise_srv_t ma_advs_server;
+
+
+/* Advertise is by default turned off */
+static apr_port_t ma_advertise_port = MA_DEFAULT_ADVPORT;
+static apr_port_t ma_advertise_srvp = 0;
+static ma_advertise_e ma_advertise_mode = ma_advertise_off;
+static apr_interval_time_t ma_advertise_freq = MA_DEFAULT_ADV_FREQ;
+
+/* Advertise sockets */
+static apr_socket_t *ma_mgroup_socket = NULL;
+static apr_socket_t *ma_listen_socket = NULL;
+static apr_sockaddr_t *ma_mgroup_sa = NULL;
+static apr_sockaddr_t *ma_listen_sa = NULL;
+
+static server_rec *ma_server_rec = NULL;
+
+/* Advertise sequence number */
+static volatile apr_int64_t ma_sequence = 0;
+
+
+/* Parent and child manager thread statuses */
+static volatile int is_mp_running = 0;
+static volatile int is_mp_created = 0;
+
+/*
+ * Server global data
+ */
+typedef struct ma_global_data_t {
+ int generation;
+ unsigned char ssalt[APR_MD5_DIGESTSIZE];
+ apr_uuid_t suuid;
+ char srvid[APR_UUID_FORMATTED_LENGTH + 2];
+ apr_pool_t *ppool;
+ apr_pool_t *cpool;
+} ma_global_data_t;
+
+/*
+ * Global data instance
+ * For parent, registered in process pool
+ */
+static ma_global_data_t *magd = NULL;
+
+/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
+ * IPv4 match-any-address, 0.0.0.0. */
+#define IS_INADDR_ANY(addr) ((addr)->family == APR_INET && \
+ (addr)->sa.sin.sin_addr.s_addr == INADDR_ANY)
+
+/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
+ * IPv6 match-any-address, [::]. */
+#define IS_IN6ADDR_ANY(addr) ((addr)->family == APR_INET6 && \
+ IN6_IS_ADDR_UNSPECIFIED(&(addr)->sa.sin6.sin6_addr))
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* ServerAdvertise directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_m(cmd_parms *cmd, void *dummy,
+ const char *arg, const char *opt)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+
+ if (strcasecmp(arg, "Off") == 0)
+ ma_advertise_mode = ma_advertise_off;
+ else if (strcasecmp(arg, "On") == 0)
+ ma_advertise_mode = ma_advertise_on;
+ else
+ return "ServerAdvertise must be Off or On";
+ if (opt) {
+ const char *p = ap_strstr_c(opt, "://");
+ if (p) {
+ ma_advertise_srvm = apr_pstrndup(cmd->pool, opt, p - opt);
+ opt = p + 3;
+ }
+ if (apr_parse_addr_port(&ma_advertise_srvs,
+ &ma_advertise_srvi,
+ &ma_advertise_srvp,
+ opt, cmd->pool) != APR_SUCCESS ||
+ !ma_advertise_srvs ||
+ !ma_advertise_srvp)
+ return "Invalid ServerAdvertise Address";
+ }
+ return NULL;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseGroup directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_g(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ if (ma_advertise_set)
+ return "Duplicate AdvertiseGroup directives are not allowed";
+
+ if (apr_parse_addr_port(&ma_advertise_adrs,
+ &ma_advertise_adsi,
+ &ma_advertise_port,
+ arg, cmd->pool) != APR_SUCCESS)
+ return "Invalid AdvertiseGroup address";
+ if (!ma_advertise_adrs)
+ return "Missing Ip part from AdvertiseGroup address";
+ if (!ma_advertise_port)
+ ma_advertise_port = MA_DEFAULT_ADVPORT;
+ ma_advertise_set = 1;
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseFrequency directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_f(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ apr_time_t s, u = 0;
+ const char *p;
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ if ((p = ap_strchr_c(arg, '.')) || (p = ap_strchr_c(arg, ',')))
+ u = atoi(p + 1);
+
+ s = atoi(arg);
+ ma_advertise_freq = s * APR_USEC_PER_SEC + u * APR_TIME_C(1000);
+ if (ma_advertise_freq == 0)
+ return "Invalid AdvertiseFrequency value";
+
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseSecurityKey directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_k(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ ma_advertise_skey = apr_pstrdup(cmd->pool, arg);
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseManagerUrl directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_h(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ ma_advertise_srvh = apr_pstrdup(cmd->pool, arg);
+ return NULL;
+}
+
+#define MA_ADVERTISE_SERVER_FMT \
+ "HTTP/1.0 %s" CRLF \
+ "Date: %s" CRLF \
+ "Sequence: %" APR_INT64_T_FMT CRLF \
+ "Digest: %s" CRLF \
+ "Server: %s" CRLF
+
+static const char *hex = "0123456789abcdef";
+
+apr_status_t ma_advertise_server(server_rec *server, int type)
+{
+ char buf[MA_BSIZE];
+ char dat[APR_RFC822_DATE_LEN];
+ unsigned char msig[APR_MD5_DIGESTSIZE];
+ unsigned char ssig[APR_MD5_DIGESTSIZE * 2 + 1];
+ const char *asl;
+ char *p = buf;
+ int i, c = 0;
+ apr_size_t l = MA_BSIZE - 8;
+ apr_size_t n = 0;
+ apr_md5_ctx_t md;
+
+ ma_sequence++;
+ if (ma_sequence < 1)
+ ma_sequence = 1;
+ sprintf(buf, "%" APR_INT64_T_FMT, ma_sequence);
+ ap_recent_rfc822_date(dat, apr_time_now());
+ asl = ap_get_status_line(ma_advertise_stat);
+
+ /* Create MD5 digest
+ * salt + date + sequence + srvid
+ */
+ apr_md5_init(&md);
+ apr_md5_update(&md, magd->ssalt, APR_MD5_DIGESTSIZE);
+ apr_md5_update(&md, dat, strlen(dat));
+ apr_md5_update(&md, buf, strlen(buf));
+ apr_md5_update(&md, magd->srvid + 1, strlen(magd->srvid) - 1);
+ apr_md5_final(msig, &md);
+ /* Convert MD5 digest to hex string */
+ for (i = 0; i < APR_MD5_DIGESTSIZE; i++) {
+ ssig[c++] = hex[msig[i] >> 4];
+ ssig[c++] = hex[msig[i] & 0x0F];
+ }
+ ssig[c] = '\0';
+ n = apr_snprintf(p, l, MA_ADVERTISE_SERVER_FMT,
+ asl, dat, ma_sequence, ssig, magd->srvid + 1);
+ if (type == MA_ADVERTISE_SERVER) {
+ l -= n;
+ n += apr_snprintf(p + n, l,
+ "X-Manager-Address: %s:%u" CRLF
+ "X-Manager-Url: %s" CRLF
+ "X-Manager-Protocol: %s" CRLF
+ "X-Manager-Host: %s" CRLF,
+ ma_advertise_srvs,
+ ma_advertise_srvp,
+ ma_advertise_srvh,
+ ma_advertise_srvm,
+ server->server_hostname);
+
+ }
+ strcat(p, CRLF);
+ n += 2;
+ return apr_socket_sendto(ma_mgroup_socket,
+ ma_mgroup_sa, 0, buf, &n);
+}
+
+static apr_status_t ma_group_join(const char *addr, apr_port_t port,
+ apr_pool_t *pool)
+{
+ apr_status_t rv;
+
+ if ((rv = apr_sockaddr_info_get(&ma_mgroup_sa, addr,
+ APR_INET, port,
+ APR_UNSPEC, pool)) != APR_SUCCESS)
+ return rv;
+ if ((rv = apr_socket_create(&ma_mgroup_socket,
+ ma_mgroup_sa->family,
+ SOCK_DGRAM,
+ APR_PROTO_UDP,
+ pool)) != APR_SUCCESS)
+ return rv;
+ if ((rv = apr_mcast_join(ma_mgroup_socket, ma_mgroup_sa,
+ NULL, NULL)) != APR_SUCCESS) {
+ apr_socket_close(ma_mgroup_socket);
+ return rv;
+ }
+ if ((rv = apr_mcast_hops(ma_mgroup_socket,
+ MA_ADVERTISE_HOPS)) != APR_SUCCESS) {
+ apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
+ NULL, NULL);
+ apr_socket_close(ma_mgroup_socket);
+ return rv;
+ }
+ return APR_SUCCESS;
+}
+
+static void ma_group_leave()
+{
+ if (ma_mgroup_socket) {
+ apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
+ NULL, NULL);
+ apr_socket_close(ma_mgroup_socket);
+ ma_mgroup_socket = NULL;
+ }
+}
+
+static void * APR_THREAD_FUNC parent_thread(apr_thread_t *thd, void *data)
+{
+ static int current_status = 0;
+ int f_time = 1;
+ apr_interval_time_t a_step = 0;
+ server_rec *s = (server_rec *)data;
+ is_mp_created = 1;
+
+ while (is_mp_running) {
+ apr_sleep(MA_TM_RESOLUTION);
+ if (!is_mp_running)
+ break;
+ if (ma_advertise_run) {
+ a_step += MA_TM_RESOLUTION;
+ if (current_status != ma_advertise_stat) {
+ /* Force advertise on status change */
+ current_status = ma_advertise_stat;
+ f_time = 1;
+ }
+ if (a_step >= ma_advertise_freq || f_time) {
+ /* Run advertise */
+ ma_advertise_server(s, MA_ADVERTISE_SERVER);
+ a_step = 0;
+ f_time = 0;
+ }
+ if (!is_mp_running)
+ break;
+ }
+ /* TODO: Implement actual work for parent thread */
+ if (!is_mp_running)
+ break;
+ }
+ is_mp_created = 0;
+ return NULL;
+}
+
+static apr_status_t pconfig_cleanup(void *data);
+
+static apr_status_t process_cleanup(void *data)
+{
+ int advertise_run = ma_advertise_run;
+
+ is_mp_running = 0;
+ ma_advertise_run = 0;
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_FORBIDDEN;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ }
+ if (is_mp_created) {
+ apr_sleep(1000);
+ /* Wait for the parent maintenance thread to finish */
+ while (is_mp_created) {
+ apr_sleep(MA_TM_RESOLUTION);
+ }
+ }
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_GONE;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ ma_group_leave();
+ }
+ /* We don't need the post_config cleanup to run,
+ */
+ apr_pool_cleanup_kill(magd->cpool, magd, pconfig_cleanup);
+ magd = NULL;
+
+ return APR_SUCCESS;
+}
+
+static apr_status_t pconfig_cleanup(void *data)
+{
+ int advertise_run = ma_advertise_run;
+
+ is_mp_running = 0;
+ ma_advertise_run = 0;
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_FORBIDDEN;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ }
+
+ if (is_mp_created) {
+ apr_sleep(1000);
+ /* Wait for the parent maintenance thread to finish */
+ while (is_mp_created) {
+ apr_sleep(MA_TM_RESOLUTION);
+ }
+ }
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_FORBIDDEN;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ }
+ if (magd) {
+ /* Remove the process_cleanup.
+ * We need to reattach again because the
+ * module can be reloaded on different address
+ */
+ apr_pool_cleanup_kill(magd->ppool, magd, process_cleanup);
+ }
+ return APR_SUCCESS;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* Post config hook. */
+/* Create management thread in parent and initializes Manager */
+/* */
+/*--------------------------------------------------------------------------*/
+static int post_config_hook(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp, server_rec *s)
+{
+ apr_status_t rv;
+ const char *pk = "advertise_init_module_tag";
+ apr_pool_t *pproc = s->process->pool;
+ apr_thread_t *tp;
+
+ apr_pool_userdata_get((void *)&magd, pk, pproc);
+ if (!magd) {
+ if (!(magd = apr_pcalloc(pproc, sizeof(ma_global_data_t))))
+ return apr_get_os_error();
+ apr_pool_create(&magd->ppool, pproc);
+ apr_pool_userdata_set(magd, pk, apr_pool_cleanup_null, pproc);
+ /* First time config phase -- skip. */
+ return OK;
+ }
+#if defined(WIN32)
+ {
+ const char *ppid = getenv("AP_PARENT_PID");
+ if (ppid) {
+ ma_parent_pid = atol(ppid);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+ "[%" APR_PID_T_FMT " - %" APR_PID_T_FMT
+ "] in child post config hook",
+ getpid(), ma_parent_pid);
+ return OK;
+ }
+ }
+#endif
+ ma_server_rec = s;
+ if (!magd->generation) {
+ /* Favor dynamic configuration */
+ if (ma_advertise_skey) {
+ apr_md5_ctx_t mc;
+ apr_md5_init(&mc);
+ apr_md5_update(&mc, ma_advertise_skey, strlen(ma_advertise_skey));
+ apr_md5_final(magd->ssalt, &mc);
+ }
+ apr_uuid_get(&magd->suuid);
+ magd->srvid[0] = '/';
+ apr_uuid_format(&magd->srvid[1], &magd->suuid);
+ }
+ if (!ma_advertise_srvh)
+ ma_advertise_srvh = magd->srvid;
+ if (!ma_advertise_srvm)
+ ma_advertise_srvm = apr_pstrdup(pconf, "http");
+
+ /* Check if we have advertise set */
+ if (ma_advertise_mode != ma_advertise_off &&
+ ma_advertise_set && ma_advertise_adrs) {
+ rv = ma_group_join(ma_advertise_adrs, ma_advertise_port, pconf);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+ "mod_advertise: multicast join failed for %s:%d.",
+ ma_advertise_adrs, ma_advertise_port);
+ ma_advertise_run = 0;
+ }
+ else {
+ ma_advertise_run = 1;
+ ma_advertise_stat = 200;
+ }
+ }
+
+ /* Create parent management thread */
+ is_mp_running = 1;
+ rv = apr_thread_create(&tp, NULL, parent_thread, s, pconf);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
+ "mod_advertise: parent apr_thread_create");
+ return rv;
+ }
+ apr_thread_detach(tp);
+
+ /* Create cleanup pool that will be destroyed first
+ * in future use new apr_pool_pre_cleanup_register from APR 1.3
+ */
+ apr_pool_create(&magd->cpool, pconf);
+ apr_pool_cleanup_register(magd->cpool, magd, pconfig_cleanup,
+ apr_pool_cleanup_null);
+
+ if (magd->generation++) {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+ "Advertise reinitialized for process %" APR_PID_T_FMT,
+ getpid());
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+ "Advertise initialized for process %" APR_PID_T_FMT,
+ getpid());
+ }
+
+ apr_pool_cleanup_register(magd->ppool, magd, process_cleanup,
+ apr_pool_cleanup_null);
+
+
+
+ return OK;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* List of directives specific to our module. */
+/* */
+/*--------------------------------------------------------------------------*/
+static const command_rec cmd_table[] =
+{
+ AP_INIT_TAKE12(
+ "ServerAdvertise", /* directive name */
+ cmd_advertise_m, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Server advertise mode: On | Off [Address]"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseGroup", /* directive name */
+ cmd_advertise_g, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Multicast group address"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseFrequency", /* directive name */
+ cmd_advertise_f, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Advertise frequency in seconds[.miliseconds]"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseSecurityKey", /* directive name */
+ cmd_advertise_k, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Advertise security key"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseManagerUrl", /* directive name */
+ cmd_advertise_h, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Advertise manager url"
+ ),
+ {NULL}
+
+};
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* Which functions are responsible for which hooks in the server. */
+/* */
+/*--------------------------------------------------------------------------*/
+static void register_hooks(apr_pool_t *p)
+{
+
+ /* Post config handling
+ */
+ ap_hook_post_config(post_config_hook,
+ NULL,
+ NULL,
+ APR_HOOK_LAST);
+
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* The list of callback routines and data structures that provide */
+/* the static hooks into our module from the other parts of the server. */
+/* */
+/*--------------------------------------------------------------------------*/
+module AP_MODULE_DECLARE_DATA advertise_module =
+{
+ STANDARD20_MODULE_STUFF,
+ NULL, /* per-directory config creator */
+ NULL, /* dir config merger */
+ NULL, /* server config creator */
+ NULL, /* server config merger */
+ cmd_table, /* command table */
+ register_hooks /* set up other request processing hooks */
+};
Copied: trunk/mod_cluster/native/advertise/mod_advertise.h (from rev 1691,
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h)
===================================================================
--- trunk/mod_cluster/native/advertise/mod_advertise.h (rev 0)
+++ trunk/mod_cluster/native/advertise/mod_advertise.h 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,145 @@
+/*
+ * ModAdvertise - Apache Httpd advertising module
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ */
+
+#ifndef MOD_ADVERTISE_H
+#define MOD_ADVERTISE_H
+
+/**
+ * @file mod_advertise.h
+ * @brief Advertise Module for Apache Httpd
+ *
+ * @defgroup MOD_ADVERTISE mod_advertise
+ * @ingroup APACHE_MODS
+ * @{
+ */
+
+#define CORE_PRIVATE
+
+#include "apr_hooks.h"
+#include "apr.h"
+#include "apr_lib.h"
+#include "apr_strings.h"
+#include "apr_buckets.h"
+#include "apr_md5.h"
+#include "apr_network_io.h"
+#include "apr_pools.h"
+#include "apr_strings.h"
+#include "apr_uri.h"
+#include "apr_date.h"
+#include "apr_uuid.h"
+#include "apr_version.h"
+#include "apr_atomic.h"
+
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+
+#include "httpd.h"
+#include "http_config.h"
+#include "http_core.h"
+#include "http_protocol.h"
+#include "http_request.h"
+#include "http_vhost.h"
+#include "http_main.h"
+#include "http_log.h"
+#include "http_connection.h"
+#include "util_filter.h"
+#include "util_ebcdic.h"
+#include "util_time.h"
+#include "ap_provider.h"
+#include "ap_mpm.h"
+
+#if APR_HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#if APR_HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
+#if !APR_HAS_THREADS
+#error This module does not compile unless you have a thread capable APR!
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define MA_BSIZE 4096
+#define MA_SSIZE 1024
+#define MA_DEFAULT_ADVPORT 23364
+#define MA_TM_RESOLUTION APR_TIME_C(100000)
+#define MA_DEFAULT_ADV_FREQ apr_time_from_sec(10)
+#define MA_TM_MAINTAIN_STEP 10
+
+/**
+ * Multicast Time to Live (ttl) for a advertise transmission.
+ */
+#define MA_ADVERTISE_HOPS 10
+
+/**
+ * Advertise protocol types
+ */
+#define MA_ADVERTISE_SERVER 0
+#define MA_ADVERTISE_STATUS 1
+
+/**
+ * Advertise mode enumeration.
+ */
+typedef enum {
+ ma_advertise_off,
+ ma_advertise_status,
+ ma_advertise_on
+} ma_advertise_e;
+
+/**
+ * Advertise header data structure
+ */
+typedef struct ma_advertise_hdr_t ma_advertise_hdr_t;
+struct ma_advertise_hdr_t {
+ int type;
+ apr_status_t status;
+ char suuid[APR_UUID_FORMATTED_LENGTH + 1];
+};
+
+/**
+ * Advertise server data structure
+ */
+typedef struct ma_advertise_srv_t ma_advertise_srv_t;
+struct ma_advertise_srv_t {
+ const char *handle;
+ const char *address;
+ const char *protocol;
+ server_rec *server;
+ apr_port_t port;
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+#endif /* MOD_ADVERTISE_H */
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-11 14:15:14 UTC
(rev 1692)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-11 14:16:31 UTC
(rev 1693)
@@ -179,7 +179,7 @@
balancer = apr_array_push(conf->balancers);
memset(balancer, 0, sizeof(proxy_balancer));
balancer->name = apr_pstrdup(conf->pool, name);
- balancer->lbmethod = ap_lookup_provider(PROXY_LBMETHOD,
"cluster_bytraffic", "0");
+ balancer->lbmethod = ap_lookup_provider(PROXY_LBMETHOD,
"cluster_byrequests", "0");
balancer->workers = apr_array_make(conf->pool, 5, sizeof(proxy_worker));
/* XXX Is this a right place to create mutex */
#if APR_HAS_THREADS
@@ -661,12 +661,11 @@
* context and host to prevent to route to application beeing redeploy or
* stopped in one node but not in others.
*/
-static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
+static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
request_rec *r)
{
int i;
- apr_off_t mytraffic = 0;
- apr_off_t curmin = 0;
+ int total_factor = 0;
proxy_worker *worker;
proxy_worker *mycandidate = NULL;
int cur_lbset = 0;
@@ -678,7 +677,7 @@
ap_get_module_config(sconf, &proxy_module);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: Entering bytraffic for CLUSTER (%s)",
+ "proxy: Entering byrequests for CLUSTER (%s)",
balancer->name);
/* create workers for new nodes */
@@ -723,11 +722,10 @@
mycandidate = worker;
break; /* Done */
} else {
- mytraffic =
(worker->s->transferred/worker->s->lbfactor) +
- (worker->s->read/worker->s->lbfactor);
- if (!mycandidate || mytraffic < curmin) {
+ worker->s->lbstatus += worker->s->lbfactor;
+ total_factor += worker->s->lbfactor;
+ if (!mycandidate || worker->s->lbstatus <
mycandidate->s->lbstatus) {
mycandidate = worker;
- curmin = mytraffic;
}
}
}
@@ -738,18 +736,19 @@
} while (cur_lbset <= max_lbset && !mycandidate);
if (mycandidate) {
+ mycandidate->s->lbstatus -= total_factor;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: bytraffic balancer DONE (%s)",
mycandidate->name);
+ "proxy: byrequests balancer DONE (%s)",
mycandidate->name);
} else {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: bytraffic balancer FAILED");
+ "proxy: byrequests balancer FAILED");
}
return mycandidate;
}
-static const proxy_balancer_method bytraffic =
+static const proxy_balancer_method byrequests =
{
- "bytraffic",
- &find_best_bytraffic,
+ "byrequests",
+ &find_best_byrequests,
NULL
};
@@ -1451,7 +1450,7 @@
ap_hook_post_config(proxy_cluster_post_config, NULL, NULL, APR_HOOK_MIDDLE);
/* create the provider for the proxy logic */
- ap_register_provider(p, PROXY_LBMETHOD, "cluster_bytraffic", "0",
&bytraffic);
+ ap_register_provider(p, PROXY_LBMETHOD, "cluster_byrequests",
"0", &byrequests);
/* create the "maintenance" thread */
ap_hook_child_init(proxy_cluster_child_init, NULL, NULL, APR_HOOK_MIDDLE);