Author: mladen.turk(a)jboss.com
Date: 2008-06-10 04:30:04 -0400 (Tue, 10 Jun 2008)
New Revision: 1681
Added:
trunk/httpd/httpd-2.2/modules/advertise/
trunk/httpd/httpd-2.2/modules/advertise/Makefile.in
trunk/httpd/httpd-2.2/modules/advertise/NMAKEadvertise
trunk/httpd/httpd-2.2/modules/advertise/NMAKEmakefile
trunk/httpd/httpd-2.2/modules/advertise/config.m4
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
trunk/httpd/httpd-2.2/modules/advertise/modules.mk
Modified:
trunk/httpd/httpd-2.2/modules/NMAKEmakefile
Log:
Add advertise module
Modified: trunk/httpd/httpd-2.2/modules/NMAKEmakefile
===================================================================
--- trunk/httpd/httpd-2.2/modules/NMAKEmakefile 2008-06-09 13:18:35 UTC (rev 1680)
+++ trunk/httpd/httpd-2.2/modules/NMAKEmakefile 2008-06-10 08:30:04 UTC (rev 1681)
@@ -46,6 +46,7 @@
metadata\~ \
ssl\~ \
proxy\~ \
+ advertise\~ \
mod_slotmem\~ \
mod_manager\~ \
jk\~
Added: trunk/httpd/httpd-2.2/modules/advertise/Makefile.in
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/Makefile.in (rev 0)
+++ trunk/httpd/httpd-2.2/modules/advertise/Makefile.in 2008-06-10 08:30:04 UTC (rev
1681)
@@ -0,0 +1,3 @@
+# a modules Makefile has no explicit targets -- they will be defined by
+# whatever modules are enabled. just grab special.mk to deal with this.
+include $(top_srcdir)/build/special.mk
Property changes on: trunk/httpd/httpd-2.2/modules/advertise/Makefile.in
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/httpd/httpd-2.2/modules/advertise/NMAKEadvertise
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/NMAKEadvertise (rev
0)
+++ trunk/httpd/httpd-2.2/modules/advertise/NMAKEadvertise 2008-06-10 08:30:04 UTC (rev
1681)
@@ -0,0 +1,63 @@
+# Copyright 2001-2008 The Apache Software Foundation or its licensors, as
+# applicable.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ====================================================================
+#
+# NMAKEmakefile mod_advertise module makefile.
+#
+# Originally contributed by Mladen Turk <mturk redhat.com>
+#
+# ====================================================================
+#
+
+TARGET=DLL
+PROJECT = mod_advertise
+
+!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
+SRCDIR = .
+!ENDIF
+
+!include <..\..\NMAKEcommon.inc>
+!include <..\..\NMAKEhttpd.inc>
+
+LDIRS = /libpath:"$(BUILDLIB)"
+LFLAGS = $(LFLAGS) user32.lib psapi.lib gdi32.lib shlwapi.lib wldap32.lib ole32.lib
$(LIBAPR) $(LIBAPU) $(LIBHTTPD)
+CFLAGS = $(CFLAGS) -DCLUSTER_DECLARE_EXPORT
+
+INCLUDES = -I$(SRCDIR) -I$(BUILDINC)
+PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
+
+BUILDBIN = $(WORKDIR)\$(PROJECT).so
+BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
+BUILDRES = $(WORKDIR)\$(PROJECT).res
+BUILDMFT = $(BUILDBIN).manifest
+
+RCFLAGS = $(RCFLAGS) /d BIN_NAME="$(PROJECT).so" /d
LONG_NAME="mod_advertise module for Apache"
+
+OBJECTS = \
+ $(WORKDIR)\mod_advertise.obj
+
+{$(SRCDIR)}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+$(BUILDRES): ..\..\build\win32\httpd.rc
+ $(RC) $(RCFLAGS) /i "$(BUILDINC)" /fo $(BUILDRES) ..\..\build\win32\httpd.rc
+
+$(BUILDBIN): $(OBJECTS) $(BUILDRES)
+ $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB)
/out:$(BUILDBIN)
+ IF EXIST $(BUILDMFT) \
+ mt -nologo -manifest $(BUILDMFT) -outputresource:$(BUILDBIN);2
+
+install: $(BUILDBIN)
Added: trunk/httpd/httpd-2.2/modules/advertise/NMAKEmakefile
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/NMAKEmakefile (rev 0)
+++ trunk/httpd/httpd-2.2/modules/advertise/NMAKEmakefile 2008-06-10 08:30:04 UTC (rev
1681)
@@ -0,0 +1,43 @@
+# Copyright 2001-2008 The Apache Software Foundation or its licensors, as
+# applicable.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ====================================================================
+#
+# NMAKEmakefile Master HTTPD cluster module makefile.
+#
+# Originally contributed by Mladen Turk <mturk redhat.com>
+#
+# ====================================================================
+#
+
+TARGET=DLL
+!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
+SRCDIR = .
+!ENDIF
+
+!include <..\..\NMAKEcommon.inc>
+!include <..\..\NMAKEhttpd.inc>
+
+MODULES = \
+ $(SRCDIR)\NMAKEadvertise
+
+$(MODULES):
+ @$(MAKE) -nologo -f $@ PREFIX=$(PREFIX) install
+
+$(WORKDIR):
+ @$(MAKEWORKDIR)
+
+install: $(WORKDIR) $(MODULES)
+ @xcopy "$(WORKDIR)\*.so" "$(BUILDMOD)" /Y /Q 2>NUL
Property changes on: trunk/httpd/httpd-2.2/modules/advertise/NMAKEmakefile
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/httpd/httpd-2.2/modules/advertise/config.m4
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/config.m4 (rev 0)
+++ trunk/httpd/httpd-2.2/modules/advertise/config.m4 2008-06-10 08:30:04 UTC (rev 1681)
@@ -0,0 +1,19 @@
+dnl modules enabled in this directory by default
+
+APACHE_MODPATH_INIT(advertise)
+
+if test "$enable_advertise" = "shared"; then
+ advertise_mods_enable=shared
+elif test "$enable_advertise" = "yes"; then
+ advertise_mods_enable=yes
+else
+ advertise_mods_enable=no
+fi
+
+advertise_objs="mod_advertise.lo"
+APACHE_MODULE(advertise, Apache advertise module, $advertise_objs, ,
$advertise_mods_enable)
+
+
+APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current/../generators])
+
+APACHE_MODPATH_FINISH
Property changes on: trunk/httpd/httpd-2.2/modules/advertise/config.m4
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c (rev
0)
+++ trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c 2008-06-10 08:30:04 UTC (rev
1681)
@@ -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 = strstr(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 = strchr(arg, '.')) || (p = strchr(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 */
+};
Property changes on: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h (rev
0)
+++ trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h 2008-06-10 08:30:04 UTC (rev
1681)
@@ -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 */
Property changes on: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/httpd/httpd-2.2/modules/advertise/modules.mk
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/modules.mk (rev 0)
+++ trunk/httpd/httpd-2.2/modules/advertise/modules.mk 2008-06-10 08:30:04 UTC (rev 1681)
@@ -0,0 +1,5 @@
+mod_advertise.la: mod_advertise.slo
+ $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_advertise.lo
$(MOD_MANAGER_LDADD)
+DISTCLEAN_TARGETS = modules.mk
+static =
+shared = mod_advertise.la