| 139 | } |
| 140 | |
| 141 | AP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, |
| 142 | const char *pattern, char **newpattern) |
| 143 | { |
| 144 | int ret = 1; |
| 145 | int startl, oldl, newl, diffsz; |
| 146 | const char *remainder; |
| 147 | char *subs; |
| 148 | /* snrf process_regexp from mod_headers */ |
| 149 | if (ap_regexec(&rx->rx, pattern, rx->nmatch, rx->pmatch, rx->flags) != 0) { |
| 150 | rx->match = NULL; |
| 151 | return 0; /* no match, nothing to do */ |
| 152 | } |
| 153 | rx->match = pattern; |
| 154 | if (rx->subs) { |
| 155 | *newpattern = ap_pregsub(pool, rx->subs, pattern, |
| 156 | rx->nmatch, rx->pmatch); |
| 157 | if (!*newpattern) { |
| 158 | return 0; /* FIXME - should we do more to handle error? */ |
| 159 | } |
| 160 | startl = rx->pmatch[0].rm_so; |
| 161 | oldl = rx->pmatch[0].rm_eo - startl; |
| 162 | newl = strlen(*newpattern); |
| 163 | diffsz = newl - oldl; |
| 164 | remainder = pattern + startl + oldl; |
| 165 | if (rx->flags & AP_REG_MULTI) { |
| 166 | /* recurse to do any further matches */ |
| 167 | ret += ap_rxplus_exec(pool, rx, remainder, &subs); |
| 168 | if (ret > 1) { |
| 169 | /* a further substitution happened */ |
| 170 | diffsz += strlen(subs) - strlen(remainder); |
| 171 | remainder = subs; |
| 172 | } |
| 173 | } |
| 174 | subs = apr_palloc(pool, strlen(pattern) + 1 + diffsz); |
| 175 | memcpy(subs, pattern, startl); |
| 176 | memcpy(subs+startl, *newpattern, newl); |
| 177 | strcpy(subs+startl+newl, remainder); |
| 178 | *newpattern = subs; |
| 179 | } |
| 180 | return ret; |
| 181 | } |
| 182 | #ifdef DOXYGEN |
| 183 | AP_DECLARE(int) ap_rxplus_nmatch(ap_rxplus_t *rx) |
| 184 | { |
no test coverage detected