Better support Win32/VS2005 out-of-the-box with trunk.
* flood_farm.c
(run_farm): Accept APR_INCOMPLETE from apr_thread_join for Win32.
* flood/flood_pcre.c, flood/flood_pcre.h: Import PCRE wrappers from httpd.
* flood/flood_round_robin.c: Bring in PCRE wrappers if needed.
* flood/NOTICE: Update; note PCRE wrappers inclusion.
* flood/flood.vcproj: Add VS2005 project file.
git-svn-id: https://svn.apache.org/repos/asf/httpd/test/trunk/flood@490939 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/NOTICE b/NOTICE
index 439eb83..e9dc62c 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,3 +1,11 @@
-This product includes software developed by
+Apache Flood
+Copyright 2006 The Apache Software Foundation.
+
+This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+Regular expression support is provided by the PCRE library package,
+which is open source software, written by Philip Hazel, and copyright
+by the University of Cambridge, England. The original software is
+available from
+ ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
diff --git a/flood.vcproj b/flood.vcproj
new file mode 100644
index 0000000..2031dee
--- /dev/null
+++ b/flood.vcproj
@@ -0,0 +1,560 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="flood"
+ ProjectGUID="{8ABBD34E-7150-45D9-B143-737738BC5BFB}"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Release/flood.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ AdditionalIncludeDirectories="..\apr\include,..\apr-util\include,..\openssl-0.9.8b\inc32,..\httpd\srclib\pcre"
+ PreprocessorDefinitions="NDEBUG;WIN32;_CONSOLE;APR_DECLARE_STATIC;APU_DECLARE_STATIC;WIN32_LEAN_AND_MEAN;NO_IDEA;NO_RC5;NO_MDC2;FLOOD_USE_PCRE"
+ StringPooling="true"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ PrecompiledHeaderFile=".\Release/flood.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName="Release/flood"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="wsock32.lib ws2_32.lib apr-1.lib aprutil-1.lib xml.lib pcre.lib libeay32.lib ssleay32.lib"
+ OutputFile=".\Release/flood.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ AdditionalLibraryDirectories="..\apr\LibR,..\apr-util\LibR,..\openssl-0.9.8b\out32dll,..\httpd\srclib\pcre\LibR,..\apr-util\xml\expat\lib\LibR"
+ ProgramDatabaseFile=".\Release/flood.pdb"
+ GenerateMapFile="true"
+ MapFileName=".\Release/flood.map"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ SuppressStartupBanner="true"
+ OutputFile=".\Release/flood.bsc"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Debug/flood.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\apr\include,..\apr-util\include,..\openssl-0.9.8b\inc32,..\httpd\srclib\pcre"
+ PreprocessorDefinitions="_DEBUG;WIN32;_CONSOLE;APR_DECLARE_STATIC;APU_DECLARE_STATIC;WIN32_LEAN_AND_MEAN;NO_IDEA;NO_RC5;NO_MDC2;FLOOD_USE_PCRE"
+ RuntimeLibrary="3"
+ PrecompiledHeaderFile=".\Debug/flood.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName="Debug/flood"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="wsock32.lib ws2_32.lib apr-1.lib aprutil-1.lib pcre.lib libeay32.lib ssleay32.lib xml.lib"
+ OutputFile=".\Debug/flood.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ AdditionalLibraryDirectories="..\apr\LibD,..\apr-util\LibD,..\openssl-0.9.8b\out32dll,..\httpd\srclib\pcre\LibD,..\apr-util\xml\expat\lib\LibD"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile=".\Debug/flood.pdb"
+ GenerateMapFile="true"
+ MapFileName=".\Debug/flood.map"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ SuppressStartupBanner="true"
+ OutputFile=".\Debug/flood.bsc"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="sources"
+ Filter="*.c"
+ >
+ <File
+ RelativePath="flood.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_config.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_easy_reports.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_farm.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_farmer.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_net.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_net_ssl.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_pcre.c"
+ >
+ </File>
+ <File
+ RelativePath="flood_profile.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_report_relative_times.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_round_robin.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_simple_reports.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_socket_generic.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="flood_socket_keepalive.c"
+ >
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="includes"
+ Filter="*.h"
+ >
+ <File
+ RelativePath="flood_config.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_easy_reports.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_farm.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_farmer.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_net.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_net_ssl.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_pcre.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_profile.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_report_relative_times.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_round_robin.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_simple_reports.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_socket_generic.h"
+ >
+ </File>
+ <File
+ RelativePath="flood_socket_keepalive.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/flood_farm.c b/flood_farm.c
index eb8bbb8..01ce944 100644
--- a/flood_farm.c
+++ b/flood_farm.c
@@ -267,7 +267,8 @@
for (i = 0; i < usefarmer_count; i++) {
#if APR_HAS_THREADS
- if ((stat = apr_thread_join(&child_stat, farm->farmers[i])) != APR_SUCCESS) {
+ stat = apr_thread_join(&child_stat, farm->farmers[i]);
+ if (stat != APR_SUCCESS && stat != APR_INCOMPLETE) {
#else
if ((stat = apr_proc_wait(farm->farmers[i], NULL, NULL, APR_WAIT)) != APR_CHILD_DONE) {
#endif
diff --git a/flood_pcre.c b/flood_pcre.c
new file mode 100644
index 0000000..4c2cde0
--- /dev/null
+++ b/flood_pcre.c
@@ -0,0 +1,230 @@
+/*************************************************
+* Perl-Compatible Regular Expressions *
+*************************************************/
+
+/*
+This is a library of functions to support regular expressions whose syntax
+and semantics are as close as possible to those of the Perl 5 language. See
+the file Tech.Notes for some information on the internals.
+
+This module is a wrapper that provides a POSIX API to the underlying PCRE
+functions.
+
+Written by: Philip Hazel <ph10@cam.ac.uk>
+
+ Copyright (c) 1997-2004 University of Cambridge
+
+-----------------------------------------------------------------------------
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of the University of Cambridge nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-----------------------------------------------------------------------------
+*/
+
+#include "flood_pcre.h"
+#include "apr_strings.h"
+#include "pcre.h"
+
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+
+#ifndef POSIX_MALLOC_THRESHOLD
+#define POSIX_MALLOC_THRESHOLD (10)
+#endif
+
+/* Table of error strings corresponding to POSIX error codes; must be
+ * kept in synch with include/flood_regex.h's FLOOD_REG_E* definitions. */
+
+static const char *const pstring[] = {
+ "", /* Dummy for value 0 */
+ "internal error", /* FLOOD_REG_ASSERT */
+ "failed to get memory", /* FLOOD_REG_ESPACE */
+ "bad argument", /* FLOOD_REG_INVARG */
+ "match failed" /* FLOOD_REG_NOMATCH */
+};
+
+apr_size_t flood_regerror(int errcode, const flood_regex_t *preg,
+ char *errbuf, apr_size_t errbuf_size)
+{
+const char *message, *addmessage;
+apr_size_t length, addlength;
+
+message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
+ "unknown error code" : pstring[errcode];
+length = strlen(message) + 1;
+
+addmessage = " at offset ";
+addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
+ strlen(addmessage) + 6 : 0;
+
+if (errbuf_size > 0)
+ {
+ if (addlength > 0 && errbuf_size >= length + addlength)
+ apr_snprintf(errbuf, sizeof errbuf,
+ "%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
+ else
+ {
+ strncpy(errbuf, message, errbuf_size - 1);
+ errbuf[errbuf_size-1] = 0;
+ }
+ }
+
+return length + addlength;
+}
+
+
+
+
+/*************************************************
+* Free store held by a regex *
+*************************************************/
+
+void flood_regfree(flood_regex_t *preg)
+{
+(pcre_free)(preg->re_pcre);
+}
+
+
+
+
+/*************************************************
+* Compile a regular expression *
+*************************************************/
+
+/*
+Arguments:
+ preg points to a structure for recording the compiled expression
+ pattern the pattern to compile
+ cflags compilation flags
+
+Returns: 0 on success
+ various non-zero codes on failure
+*/
+
+int flood_regcomp(flood_regex_t *preg, const char *pattern, int cflags)
+{
+const char *errorptr;
+int erroffset;
+int options = 0;
+
+if ((cflags & FLOOD_REG_ICASE) != 0) options |= PCRE_CASELESS;
+if ((cflags & FLOOD_REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
+
+preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL);
+preg->re_erroffset = erroffset;
+
+if (preg->re_pcre == NULL) return FLOOD_REG_INVARG;
+
+preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL);
+return 0;
+}
+
+
+
+
+/*************************************************
+* Match a regular expression *
+*************************************************/
+
+/* Unfortunately, PCRE requires 3 ints of working space for each captured
+substring, so we have to get and release working store instead of just using
+the POSIX structures as was done in earlier releases when PCRE needed only 2
+ints. However, if the number of possible capturing brackets is small, use a
+block of store on the stack, to reduce the use of malloc/free. The threshold is
+in a macro that can be changed at configure time. */
+
+int flood_regexec(const flood_regex_t *preg, const char *string,
+ apr_size_t nmatch, flood_regmatch_t pmatch[],
+ int eflags)
+{
+int rc;
+int options = 0;
+int *ovector = NULL;
+int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
+int allocated_ovector = 0;
+
+if ((eflags & FLOOD_REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
+if ((eflags & FLOOD_REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
+
+((flood_regex_t *)preg)->re_erroffset = (apr_size_t)(-1); /* Only has meaning after compile */
+
+if (nmatch > 0)
+ {
+ if (nmatch <= POSIX_MALLOC_THRESHOLD)
+ {
+ ovector = &(small_ovector[0]);
+ }
+ else
+ {
+ ovector = (int *)malloc(sizeof(int) * nmatch * 3);
+ if (ovector == NULL) return FLOOD_REG_ESPACE;
+ allocated_ovector = 1;
+ }
+ }
+
+rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
+ 0, options, ovector, nmatch * 3);
+
+if (rc == 0) rc = nmatch; /* All captured slots were filled in */
+
+if (rc >= 0)
+ {
+ apr_size_t i;
+ for (i = 0; i < (apr_size_t)rc; i++)
+ {
+ pmatch[i].rm_so = ovector[i*2];
+ pmatch[i].rm_eo = ovector[i*2+1];
+ }
+ if (allocated_ovector) free(ovector);
+ for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
+ return 0;
+ }
+
+else
+ {
+ if (allocated_ovector) free(ovector);
+ switch(rc)
+ {
+ case PCRE_ERROR_NOMATCH: return FLOOD_REG_NOMATCH;
+ case PCRE_ERROR_NULL: return FLOOD_REG_INVARG;
+ case PCRE_ERROR_BADOPTION: return FLOOD_REG_INVARG;
+ case PCRE_ERROR_BADMAGIC: return FLOOD_REG_INVARG;
+ case PCRE_ERROR_UNKNOWN_NODE: return FLOOD_REG_ASSERT;
+ case PCRE_ERROR_NOMEMORY: return FLOOD_REG_ESPACE;
+#ifdef PCRE_ERROR_MATCHLIMIT
+ case PCRE_ERROR_MATCHLIMIT: return FLOOD_REG_ESPACE;
+#endif
+#ifdef PCRE_ERROR_BADUTF8
+ case PCRE_ERROR_BADUTF8: return FLOOD_REG_INVARG;
+#endif
+#ifdef PCRE_ERROR_BADUTF8_OFFSET
+ case PCRE_ERROR_BADUTF8_OFFSET: return FLOOD_REG_INVARG;
+#endif
+ default: return FLOOD_REG_ASSERT;
+ }
+ }
+}
+
+/* End of pcreposix.c */
diff --git a/flood_pcre.h b/flood_pcre.h
new file mode 100644
index 0000000..aadd005
--- /dev/null
+++ b/flood_pcre.h
@@ -0,0 +1,149 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* Derived from PCRE's pcreposix.h.
+
+ Copyright (c) 1997-2004 University of Cambridge
+
+-----------------------------------------------------------------------------
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of the University of Cambridge nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-----------------------------------------------------------------------------
+*/
+
+/**
+ * @file flood_regex.h
+ * @brief Apache Regex defines
+ */
+
+#ifndef FLOOD_REGEX_H
+#define FLOOD_REGEX_H
+
+#include "apr.h"
+
+/* Allow for C++ users */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Options for flood_regexec: */
+
+#define FLOOD_REG_ICASE 0x01 /** use a case-insensitive match */
+#define FLOOD_REG_NEWLINE 0x02 /** don't match newlines against '.' etc */
+#define FLOOD_REG_NOTBOL 0x04 /** ^ will not match against start-of-string */
+#define FLOOD_REG_NOTEOL 0x08 /** $ will not match against end-of-string */
+
+#define FLOOD_REG_EXTENDED (0) /** unused */
+#define FLOOD_REG_NOSUB (0) /** unused */
+
+/* Error values: */
+enum {
+ FLOOD_REG_ASSERT = 1, /** internal error ? */
+ FLOOD_REG_ESPACE, /** failed to get memory */
+ FLOOD_REG_INVARG, /** invalid argument */
+ FLOOD_REG_NOMATCH /** match failed */
+};
+
+/* The structure representing a compiled regular expression. */
+typedef struct {
+ void *re_pcre;
+ apr_size_t re_nsub;
+ apr_size_t re_erroffset;
+} flood_regex_t;
+
+/* The structure in which a captured offset is returned. */
+typedef struct {
+ int rm_so;
+ int rm_eo;
+} flood_regmatch_t;
+
+/* The functions */
+
+/**
+ * Compile a regular expression.
+ * @param preg Returned compiled regex
+ * @param regex The regular expression string
+ * @param cflags Must be zero (currently).
+ * @return Zero on success or non-zero on error
+ */
+int flood_regcomp(flood_regex_t *preg, const char *regex,
+ int cflags);
+
+/**
+ * Match a NUL-terminated string against a pre-compiled regex.
+ * @param preg The pre-compiled regex
+ * @param string The string to match
+ * @param nmatch Provide information regarding the location of any matches
+ * @param pmatch Provide information regarding the location of any matches
+ * @param eflags Bitwise OR of any of FLOOD_REG_* flags
+ * @return 0 for successful match, #REG_NOMATCH otherwise
+ */
+int flood_regexec(const flood_regex_t *preg, const char *string,
+ apr_size_t nmatch, flood_regmatch_t *pmatch, int eflags);
+
+/**
+ * Return the error code returned by regcomp or regexec into error messages
+ * @param errcode the error code returned by regexec or regcomp
+ * @param preg The precompiled regex
+ * @param errbuf A buffer to store the error in
+ * @param errbuf_size The size of the buffer
+ */
+apr_size_t flood_regerror(int errcode, const flood_regex_t *preg,
+ char *errbuf, apr_size_t errbuf_size);
+
+/** Destroy a pre-compiled regex.
+ * @param preg The pre-compiled regex to free.
+ */
+void flood_regfree(flood_regex_t *preg);
+
+/* Expose our API as the POSIX compatibility layer */
+#define regcomp flood_regcomp
+#define regexec flood_regexec
+#define regfree flood_regfree
+#define regex_t flood_regex_t
+#define regmatch_t flood_regmatch_t
+#define REG_EXTENDED FLOOD_REG_EXTENDED
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* FLOOD_REGEX_T */
+
diff --git a/flood_round_robin.c b/flood_round_robin.c
index 27a9274..619771f 100644
--- a/flood_round_robin.c
+++ b/flood_round_robin.c
@@ -45,7 +45,11 @@
#include <limits.h>
#endif
#include <assert.h>
+#ifdef FLOOD_USE_PCRE
+#include "flood_pcre.h"
+#else
#include "regex.h"
+#endif
#include "config.h"
#include "flood_net.h"