ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq/* Licensed to the Apache Software Foundation (ASF) under one or more
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * contributor license agreements. See the NOTICE file distributed with
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * this work for additional information regarding copyright ownership.
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * The ASF licenses this file to You under the Apache License, Version 2.0
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * (the "License"); you may not use this file except in compliance with
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * the License. You may obtain a copy of the License at
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * Unless required by applicable law or agreed to in writing, software
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * distributed under the License is distributed on an "AS IS" BASIS,
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * See the License for the specific language governing permissions and
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * limitations under the License.
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniqAP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool,
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq const char *pattern)
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* perl style patterns
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * add support for more as and when wanted
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * substitute: s/rx/subs/
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * match: m/rx/ or just /rx/
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* allow any nonalnum delimiter as first or second char.
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * If we ever use this with non-string pattern we'll need an extra check
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq ap_rxplus_t *ret = apr_pcalloc(pool, sizeof(ap_rxplus_t));
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq else if (pattern[0] == 's' && !apr_isalnum(pattern[1])) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq else if (pattern[0] == 'm' && !apr_isalnum(pattern[1])) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* TODO: support perl's after/before */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* FIXME: fix these simplminded delims */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* we think there's a delimiter. Allow for it not to be if unmatched */
21fadb63e226ab604c422238ea1a53cbc38974d0trawick apr_pool_cleanup_register(pool, &ret->rx, rxplus_cleanup,
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* We have a delimiter. Use it to extract the regexp */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* If it's a substitution, we need the replacement string
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * TODO: possible future enhancement - support other parsing
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * in the replacement string.
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* missing replacement string is an error */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* anything after the current delimiter is flags */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq while (*++endp) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq switch (*endp) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq default: break; /* we should probably be stricter here */
21fadb63e226ab604c422238ea1a53cbc38974d0trawick apr_pool_cleanup_register(pool, &ret->rx, rxplus_cleanup,
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* count size of memory required, starting at 1 for the whole-match
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * Simpleminded should be fine 'cos regcomp already checked syntax
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq while (*rxstr) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq switch (*rxstr++) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq if (*rxstr != 0) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq ret->pmatch = apr_palloc(pool, ret->nmatch*sizeof(ap_regmatch_t));
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniqAP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx,
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq/* snrf process_regexp from mod_headers */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq if (ap_regexec(&rx->rx, pattern, rx->nmatch, rx->pmatch, rx->flags) != 0) {
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq return 0; /* no match, nothing to do */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq return 0; /* FIXME - should we do more to handle error? */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* recurse to do any further matches */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq /* a further substitution happened */
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq/* If this blows up on you, see the notes in the header/apidoc
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * rx->match is a pointer and it's your responsibility to ensure
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq * it hasn't gone out-of-scope since the last ap_rxplus_exec
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniqAP_DECLARE(void) ap_rxplus_match(ap_rxplus_t *rx, int n, int *len,
ac45a43afbf38aa4a91c1402c6beef6ef8a2696dniq const char **match)