Commit 1a728b69 authored by Joe Orton's avatar Joe Orton
Browse files

Move the POSIX reg* implementations into the ap_* namespace;

internalise the ap_reg*<->PCRE wrapper:

* configure.in: Add srclib/pcre to the include path.

* include/ap_regex.h: Renamed from include/pcreposix.h.  Prefix all
constants with AP_; prefix all functions and types with ap_.  Define
AP_DECLARE to nothing if necessary.  Remove regcomp error codes.

* include/httpd.h: Include ap_regex.h not pcreposix.h.
(ap_pregcomp, ap_regexec, ap_regfree): s/regex_t/ap_regex_t/.
(ap_regexec, ap_regerror): Prototypes moved to ap_regex.h.

* server/util.c (regex_cleanup, ap_pregcomp, ap_pregsub, ap_pregfree):
Adjust for ap_ prefixed types.  (ap_regexec, ap_regerror): Removed.

* server/Makefile.in: Build util_pcre.c.

* server/util_pcre.c: Copied from srclib/pcre/pcreposix.c; remove use
of PCRE-internals to do error mapping; rename types to add AP_/ap_
prefixes as above.  Use APR includes.  (ap_regerror): Use apr_snprintf.

* srclib/pcre/Makefile.in: Don't build pcreposix.c into libpcre.la.

* modules/*: Update to use new type and constant names.

PR: 27750 (part one)
Submitted by: Andres Salomon <dilinger voxel.net>, Joe Orton


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@153384 13f79535-47bb-0310-9956-ffa450edef68
parent 3b7bba6d
Loading
Loading
Loading
Loading
+1 −0
Changes for configure.in: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -512,6 +512,7 @@ APACHE_HELP_STRING(--with-suexec-umask,umask for suexec'd process),[

dnl AP_LIBS specifies the actual libraries. note we have some required libs.
AP_LIBS="$abs_builddir/srclib/pcre/libpcre.la $AP_LIBS"
APR_ADDTO(CPPFLAGS, [-I$abs_builddir/srclib/pcre])

dnl APR should go after the other libs, so the right symbols can be picked up
AP_LIBS="$AP_LIBS `$apu_config --link-libtool --libs` `$apr_config --link-libtool --libs`"
+4 −1
Changes for include/ap_mmn.h: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -86,12 +86,15 @@
 *                      ap_setup_prelinked_modules, ap_process_resource_config
 * 20040425.1 (2.1.0-dev) Added ap_module_symbol_t and ap_prelinked_module_symbols
 * 20050101.0 (2.1.2-dev) Axed misnamed http_method for http_scheme (which it was!)
 * 20050127.0 (2.1.3-dev) renamed regex_t->ap_regex_t, regmatch_t->ap_regmatch_t,
 *                        REG_*->AP_REG_*, removed reg* in place of ap_reg*;
 *                        added ap_regex.h
 */

#define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */

#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20050101
#define MODULE_MAGIC_NUMBER_MAJOR 20050127
#endif
#define MODULE_MAGIC_NUMBER_MINOR 0                     /* 0...n */

+74 −46
Changes for include/ap_regex.h: 74 added lines, 46 removed lines.
Original line number Diff line number Diff line
/*************************************************
*       Perl-Compatible Regular Expressions      *
*************************************************/

#ifndef _PCREPOSIX_H
#define _PCREPOSIX_H
/* Copyright 1999-2005 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.
 */

/* This is the header for the POSIX wrapper interface to the PCRE Perl-
Compatible Regular Expression library. It defines the things POSIX says should
@@ -40,6 +49,9 @@ POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------
*/

#ifndef AP_REGEX_H
#define AP_REGEX_H

/* Have to include stdlib.h in order to ensure that size_t is defined. */

#include <stdlib.h>
@@ -50,68 +62,84 @@ POSSIBILITY OF SUCH DAMAGE.
extern "C" {
#endif

/* Options defined by POSIX. */

#define REG_ICASE     0x01
#define REG_NEWLINE   0x02
#define REG_NOTBOL    0x04
#define REG_NOTEOL    0x08

/* These are not used by PCRE, but by defining them we make it easier
to slot PCRE into existing programs that make POSIX calls. */
/* Options for ap_regexec: */

#define REG_EXTENDED  0
#define REG_NOSUB     0
#define AP_REG_ICASE    0x01 /** use a case-insensitive match */
#define AP_REG_NEWLINE  0x02 /** don't match newlines against '.' etc */
#define AP_REG_NOTBOL   0x04 /** ^ will not match against start-of-string */
#define AP_REG_NOTEOL   0x08 /** $ will not match against end-of-string */

/* Error values. Not all these are relevant or used by the wrapper. */
#define AP_REG_EXTENDED (0)  /** unused */
#define AP_REG_NOSUB    (0)  /** unused */

/* Error values: */
enum {
  REG_ASSERT = 1,  /* internal error ? */
  REG_BADBR,       /* invalid repeat counts in {} */
  REG_BADPAT,      /* pattern error */
  REG_BADRPT,      /* ? * + invalid */
  REG_EBRACE,      /* unbalanced {} */
  REG_EBRACK,      /* unbalanced [] */
  REG_ECOLLATE,    /* collation error - not relevant */
  REG_ECTYPE,      /* bad class */
  REG_EESCAPE,     /* bad escape sequence */
  REG_EMPTY,       /* empty expression */
  REG_EPAREN,      /* unbalanced () */
  REG_ERANGE,      /* bad range inside [] */
  REG_ESIZE,       /* expression too big */
  REG_ESPACE,      /* failed to get memory */
  REG_ESUBREG,     /* bad back reference */
  REG_INVARG,      /* bad argument */
  REG_NOMATCH      /* match failed */
  AP_REG_ASSERT = 1,  /** internal error ? */
  AP_REG_ESPACE,      /** failed to get memory */
  AP_REG_INVARG,      /** invalid argument */
  AP_REG_NOMATCH      /** match failed */
};


/* The structure representing a compiled regular expression. */

typedef struct {
  void *re_pcre;
  size_t re_nsub;
  size_t re_erroffset;
} regex_t;

/* The structure in which a captured offset is returned. */
} ap_regex_t;

typedef int regoff_t;

/* The structure in which a captured offset is returned. */
typedef struct {
  regoff_t rm_so;
  regoff_t rm_eo;
} regmatch_t;
} ap_regmatch_t;

#ifndef AP_DECLARE
#define AP_DECLARE(x) x
#endif /* AP_DECLARE */

/* The functions */

extern int regcomp(regex_t *, const char *, int);
extern int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
extern size_t regerror(int, const regex_t *, char *, size_t);
extern void regfree(regex_t *);
/**
 * Compile a regeular 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
 */
AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags);

/**
 * Match a null-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 AP_REG_* flags 
 * @return 0 for successful match, #REG_NOMATCH otherwise
 */ 
AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
                           size_t nmatch, ap_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
 */
AP_DECLARE(size_t) ap_regerror(int errcode, const ap_regex_t *preg, 
                               char *errbuf, size_t errbuf_size);

/** Destroy a pre-compiled regex.
 * @param preg The pre-compiled regex to free.
 */
AP_DECLARE(void) ap_regfree(ap_regex_t *preg);

#ifdef __cplusplus
}   /* extern "C" */
#endif

#endif /* End of pcreposix.h */
#endif /* AP_REGEX_T */
+1 −1
Changes for include/http_core.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -489,7 +489,7 @@ typedef struct {
    
    /* Access control */
    apr_array_header_t *sec_file;
    regex_t *r;
    ap_regex_t *r;

    const char *mime_type;       /* forced with ForceType  */
    const char *handler;         /* forced with SetHandler */
+4 −29
Changes for include/httpd.h: 4 added lines, 29 removed lines.
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@

#include "os.h"

#include "pcreposix.h"
#include "ap_regex.h"

/* Note: util_uri.h is also included, see below */

@@ -1541,7 +1541,7 @@ AP_DECLARE(char *) ap_pbase64encode(apr_pool_t *p, char *string);
 *   @li #REG_NEWLINE  - Match-any-character operators don't match new-line
 * @return The compiled regular expression
 */
AP_DECLARE(regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern,
AP_DECLARE(ap_regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern,
                                     int cflags);
    
/**
@@ -1549,32 +1549,7 @@ AP_DECLARE(regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern,
 * @param p The pool the regex was allocated from
 * @param reg The regular expression to free
 */
AP_DECLARE(void) ap_pregfree(apr_pool_t *p, regex_t *reg);

/**
 * Match a null-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:
 *   @li #REG_NOTBOL - match-beginning-of-line operator always
 *     fails to match
 *   @li #REG_NOTEOL - match-end-of-line operator always fails to match
 * @return 0 for successful match, #REG_NOMATCH otherwise
 */ 
AP_DECLARE(int)    ap_regexec(regex_t *preg, const char *string,
                              size_t nmatch, 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
 */
AP_DECLARE(size_t) ap_regerror(int errcode, const regex_t *preg, 
                               char *errbuf, size_t errbuf_size);
AP_DECLARE(void) ap_pregfree(apr_pool_t *p, ap_regex_t *reg);

/**
 * After performing a successful regex match, you may use this function to 
@@ -1588,7 +1563,7 @@ AP_DECLARE(size_t) ap_regerror(int errcode, const regex_t *preg,
 * @param pmatch the pmatch array returned from ap_pregex
 */
AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, const char *source,
                              size_t nmatch, regmatch_t pmatch[]);
                              size_t nmatch, ap_regmatch_t pmatch[]);

/**
 * We want to downcase the type/subtype for comparison purposes
Loading