| 627 | return str ? str : ""; |
| 628 | } |
| 629 | static const char *process_regexp(header_entry *hdr, const char *value, |
| 630 | request_rec *r) |
| 631 | { |
| 632 | ap_regmatch_t pmatch[AP_MAX_REG_MATCH]; |
| 633 | const char *subs; |
| 634 | const char *remainder; |
| 635 | char *ret; |
| 636 | int diffsz; |
| 637 | if (ap_regexec(hdr->regex, value, AP_MAX_REG_MATCH, pmatch, 0)) { |
| 638 | /* no match, nothing to do */ |
| 639 | return value; |
| 640 | } |
| 641 | /* Process tags in the input string rather than the resulting |
| 642 | * substitution to avoid surprises |
| 643 | */ |
| 644 | subs = ap_pregsub(r->pool, process_tags(hdr, r), value, AP_MAX_REG_MATCH, pmatch); |
| 645 | if (subs == NULL) |
| 646 | return NULL; |
| 647 | diffsz = strlen(subs) - (pmatch[0].rm_eo - pmatch[0].rm_so); |
| 648 | if (hdr->action == hdr_edit) { |
| 649 | remainder = value + pmatch[0].rm_eo; |
| 650 | } |
| 651 | else { /* recurse to edit multiple matches if applicable */ |
| 652 | remainder = process_regexp(hdr, value + pmatch[0].rm_eo, r); |
| 653 | if (remainder == NULL) |
| 654 | return NULL; |
| 655 | diffsz += strlen(remainder) - strlen(value + pmatch[0].rm_eo); |
| 656 | } |
| 657 | ret = apr_palloc(r->pool, strlen(value) + 1 + diffsz); |
| 658 | memcpy(ret, value, pmatch[0].rm_so); |
| 659 | strcpy(ret + pmatch[0].rm_so, subs); |
| 660 | strcat(ret, remainder); |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | static int echo_header(void *v, const char *key, const char *val) |
| 665 | { |
no test coverage detected