mirror of
https://github.com/apache/httpd.git
synced 2025-08-06 11:06:17 +00:00
Change the indentation to resemble the rest of the project. No code change.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1125816 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
/*************************************************
|
/*************************************************
|
||||||
* Perl-Compatible Regular Expressions *
|
* Perl-Compatible Regular Expressions *
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is a library of functions to support regular expressions whose syntax
|
This is a library of functions to support regular expressions whose syntax
|
||||||
@ -55,7 +55,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Table of error strings corresponding to POSIX error codes; must be
|
/* Table of error strings corresponding to POSIX error codes; must be
|
||||||
* kept in synch with include/ap_regex.h's AP_REG_E* definitions. */
|
* kept in synch with include/ap_regex.h's AP_REG_E* definitions.
|
||||||
|
*/
|
||||||
|
|
||||||
static const char *const pstring[] = {
|
static const char *const pstring[] = {
|
||||||
"", /* Dummy for value 0 */
|
"", /* Dummy for value 0 */
|
||||||
@ -68,165 +69,180 @@ static const char *const pstring[] = {
|
|||||||
AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
|
AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
|
||||||
char *errbuf, apr_size_t errbuf_size)
|
char *errbuf, apr_size_t errbuf_size)
|
||||||
{
|
{
|
||||||
const char *message, *addmessage;
|
const char *message, *addmessage;
|
||||||
apr_size_t length, addlength;
|
apr_size_t length, addlength;
|
||||||
|
|
||||||
message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
|
message = (errcode >= (int)(sizeof(pstring) / sizeof(char *))) ?
|
||||||
"unknown error code" : pstring[errcode];
|
"unknown error code" : pstring[errcode];
|
||||||
length = strlen(message) + 1;
|
length = strlen(message) + 1;
|
||||||
|
|
||||||
addmessage = " at offset ";
|
addmessage = " at offset ";
|
||||||
addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
|
addlength = (preg != NULL && (int)preg->re_erroffset != -1) ?
|
||||||
strlen(addmessage) + 6 : 0;
|
strlen(addmessage) + 6 : 0;
|
||||||
|
|
||||||
if (errbuf_size > 0)
|
if (errbuf_size > 0) {
|
||||||
{
|
|
||||||
if (addlength > 0 && errbuf_size >= length + addlength)
|
if (addlength > 0 && errbuf_size >= length + addlength)
|
||||||
apr_snprintf(errbuf, errbuf_size,
|
apr_snprintf(errbuf, errbuf_size, "%s%s%-6d", message, addmessage,
|
||||||
"%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
|
(int)preg->re_erroffset);
|
||||||
else
|
else
|
||||||
apr_cpystrn(errbuf, message, errbuf_size);
|
apr_cpystrn(errbuf, message, errbuf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return length + addlength;
|
return length + addlength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* Free store held by a regex *
|
* Free store held by a regex *
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
AP_DECLARE(void) ap_regfree(ap_regex_t *preg)
|
AP_DECLARE(void) ap_regfree(ap_regex_t *preg)
|
||||||
{
|
{
|
||||||
(pcre_free)(preg->re_pcre);
|
(pcre_free)(preg->re_pcre);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* Compile a regular expression *
|
* Compile a regular expression *
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Arguments:
|
* Arguments:
|
||||||
preg points to a structure for recording the compiled expression
|
* preg points to a structure for recording the compiled expression
|
||||||
pattern the pattern to compile
|
* pattern the pattern to compile
|
||||||
cflags compilation flags
|
* cflags compilation flags
|
||||||
|
*
|
||||||
Returns: 0 on success
|
* Returns: 0 on success
|
||||||
various non-zero codes on failure
|
* various non-zero codes on failure
|
||||||
*/
|
*/
|
||||||
|
AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags)
|
||||||
AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *pattern, int cflags)
|
|
||||||
{
|
{
|
||||||
const char *errorptr;
|
const char *errorptr;
|
||||||
int erroffset;
|
int erroffset;
|
||||||
int options = 0;
|
int options = 0;
|
||||||
|
|
||||||
if ((cflags & AP_REG_ICASE) != 0) options |= PCRE_CASELESS;
|
if ((cflags & AP_REG_ICASE) != 0)
|
||||||
if ((cflags & AP_REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
|
options |= PCRE_CASELESS;
|
||||||
if ((cflags & AP_REG_DOTALL) != 0) options |= PCRE_DOTALL;
|
if ((cflags & AP_REG_NEWLINE) != 0)
|
||||||
|
options |= PCRE_MULTILINE;
|
||||||
|
if ((cflags & AP_REG_DOTALL) != 0)
|
||||||
|
options |= PCRE_DOTALL;
|
||||||
|
|
||||||
preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL);
|
preg->re_pcre =
|
||||||
preg->re_erroffset = erroffset;
|
pcre_compile(pattern, options, &errorptr, &erroffset, NULL);
|
||||||
|
preg->re_erroffset = erroffset;
|
||||||
|
|
||||||
if (preg->re_pcre == NULL) return AP_REG_INVARG;
|
if (preg->re_pcre == NULL)
|
||||||
|
return AP_REG_INVARG;
|
||||||
|
|
||||||
preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL);
|
preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* Match a regular expression *
|
* Match a regular expression *
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
/* Unfortunately, PCRE requires 3 ints of working space for each captured
|
/* 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
|
* 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
|
* 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
|
* 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
|
* block of store on the stack, to reduce the use of malloc/free. The threshold
|
||||||
in a macro that can be changed at configure time. */
|
* is in a macro that can be changed at configure time.
|
||||||
|
*/
|
||||||
AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
|
AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string,
|
||||||
apr_size_t nmatch, ap_regmatch_t *pmatch,
|
apr_size_t nmatch, ap_regmatch_t *pmatch,
|
||||||
int eflags)
|
int eflags)
|
||||||
{
|
{
|
||||||
return ap_regexec_len(preg, string, strlen(string), nmatch, pmatch, eflags);
|
return ap_regexec_len(preg, string, strlen(string), nmatch, pmatch,
|
||||||
|
eflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
|
AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
|
||||||
apr_size_t len, apr_size_t nmatch,
|
apr_size_t len, apr_size_t nmatch,
|
||||||
ap_regmatch_t *pmatch, int eflags)
|
ap_regmatch_t *pmatch, int eflags)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int options = 0;
|
int options = 0;
|
||||||
int *ovector = NULL;
|
int *ovector = NULL;
|
||||||
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
|
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
|
||||||
int allocated_ovector = 0;
|
int allocated_ovector = 0;
|
||||||
|
|
||||||
if ((eflags & AP_REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
|
if ((eflags & AP_REG_NOTBOL) != 0)
|
||||||
if ((eflags & AP_REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
|
options |= PCRE_NOTBOL;
|
||||||
|
if ((eflags & AP_REG_NOTEOL) != 0)
|
||||||
|
options |= PCRE_NOTEOL;
|
||||||
|
|
||||||
((ap_regex_t *)preg)->re_erroffset = (apr_size_t)(-1); /* Only has meaning after compile */
|
((ap_regex_t *)preg)->re_erroffset = (apr_size_t)(-1); /* Only has meaning after compile */
|
||||||
|
|
||||||
if (nmatch > 0)
|
if (nmatch > 0) {
|
||||||
{
|
if (nmatch <= POSIX_MALLOC_THRESHOLD) {
|
||||||
if (nmatch <= POSIX_MALLOC_THRESHOLD)
|
|
||||||
{
|
|
||||||
ovector = &(small_ovector[0]);
|
ovector = &(small_ovector[0]);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
|
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
|
||||||
if (ovector == NULL) return AP_REG_ESPACE;
|
if (ovector == NULL)
|
||||||
|
return AP_REG_ESPACE;
|
||||||
allocated_ovector = 1;
|
allocated_ovector = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, buff, (int)len,
|
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, buff, (int)len,
|
||||||
0, options, ovector, nmatch * 3);
|
0, options, ovector, nmatch * 3);
|
||||||
|
|
||||||
if (rc == 0) rc = nmatch; /* All captured slots were filled in */
|
if (rc == 0)
|
||||||
|
rc = nmatch; /* All captured slots were filled in */
|
||||||
|
|
||||||
if (rc >= 0)
|
if (rc >= 0) {
|
||||||
{
|
|
||||||
apr_size_t i;
|
apr_size_t i;
|
||||||
for (i = 0; i < (apr_size_t)rc; i++)
|
for (i = 0; i < (apr_size_t)rc; i++) {
|
||||||
{
|
pmatch[i].rm_so = ovector[i * 2];
|
||||||
pmatch[i].rm_so = ovector[i*2];
|
pmatch[i].rm_eo = ovector[i * 2 + 1];
|
||||||
pmatch[i].rm_eo = ovector[i*2+1];
|
|
||||||
}
|
}
|
||||||
if (allocated_ovector) free(ovector);
|
if (allocated_ovector)
|
||||||
for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
|
free(ovector);
|
||||||
|
for (; i < nmatch; i++)
|
||||||
|
pmatch[i].rm_so = pmatch[i].rm_eo = -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
if (allocated_ovector)
|
||||||
if (allocated_ovector) free(ovector);
|
free(ovector);
|
||||||
switch(rc)
|
switch (rc) {
|
||||||
{
|
case PCRE_ERROR_NOMATCH:
|
||||||
case PCRE_ERROR_NOMATCH: return AP_REG_NOMATCH;
|
return AP_REG_NOMATCH;
|
||||||
case PCRE_ERROR_NULL: return AP_REG_INVARG;
|
case PCRE_ERROR_NULL:
|
||||||
case PCRE_ERROR_BADOPTION: return AP_REG_INVARG;
|
return AP_REG_INVARG;
|
||||||
case PCRE_ERROR_BADMAGIC: return AP_REG_INVARG;
|
case PCRE_ERROR_BADOPTION:
|
||||||
case PCRE_ERROR_UNKNOWN_NODE: return AP_REG_ASSERT;
|
return AP_REG_INVARG;
|
||||||
case PCRE_ERROR_NOMEMORY: return AP_REG_ESPACE;
|
case PCRE_ERROR_BADMAGIC:
|
||||||
|
return AP_REG_INVARG;
|
||||||
|
case PCRE_ERROR_UNKNOWN_NODE:
|
||||||
|
return AP_REG_ASSERT;
|
||||||
|
case PCRE_ERROR_NOMEMORY:
|
||||||
|
return AP_REG_ESPACE;
|
||||||
#ifdef PCRE_ERROR_MATCHLIMIT
|
#ifdef PCRE_ERROR_MATCHLIMIT
|
||||||
case PCRE_ERROR_MATCHLIMIT: return AP_REG_ESPACE;
|
case PCRE_ERROR_MATCHLIMIT:
|
||||||
|
return AP_REG_ESPACE;
|
||||||
#endif
|
#endif
|
||||||
#ifdef PCRE_ERROR_BADUTF8
|
#ifdef PCRE_ERROR_BADUTF8
|
||||||
case PCRE_ERROR_BADUTF8: return AP_REG_INVARG;
|
case PCRE_ERROR_BADUTF8:
|
||||||
|
return AP_REG_INVARG;
|
||||||
#endif
|
#endif
|
||||||
#ifdef PCRE_ERROR_BADUTF8_OFFSET
|
#ifdef PCRE_ERROR_BADUTF8_OFFSET
|
||||||
case PCRE_ERROR_BADUTF8_OFFSET: return AP_REG_INVARG;
|
case PCRE_ERROR_BADUTF8_OFFSET:
|
||||||
|
return AP_REG_INVARG;
|
||||||
#endif
|
#endif
|
||||||
default: return AP_REG_ASSERT;
|
default:
|
||||||
|
return AP_REG_ASSERT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user