- pappend(ctx, a[1], strlen(a[1])+1) ;
- is_uri = ATTR_IGNORE ;
- if ( linkattrs ) {
- for ( linkattr = linkattrs ; *linkattr ; ++linkattr) {
- if ( !strcmp(*linkattr, *a) ) {
- is_uri = ATTR_URI ;
- break ;
- }
- }
- }
- if ( (is_uri == ATTR_IGNORE) && ctx->cfg->extfix ) {
- for ( linkattr = events; *linkattr; ++linkattr ) {
- if ( !strcmp(*linkattr, *a) ) {
- is_uri = ATTR_EVENT ;
- break ;
- }
- }
- }
- switch ( is_uri ) {
- case ATTR_URI:
- num_match = 0 ;
- for ( m = ctx->cfg->map ; m ; m = m->next ) {
- if ( ! ( m->flags & M_HTML ) )
- continue ;
- if ( m->flags & M_REGEX ) {
- nmatch = 10 ;
- if ( ! ap_regexec(m->from.r, ctx->buf, nmatch, pmatch, 0) ) {
- ++num_match ;
- offs = match = pmatch[0].rm_so ;
- s_from = pmatch[0].rm_eo - match ;
- subs = ap_pregsub(ctx->f->r->pool, m->to, ctx->buf+offs,
- nmatch, pmatch) ;
- VERBOSE( {
- const char* f = apr_pstrndup(ctx->f->r->pool,
- ctx->buf + offs , s_from ) ;
- ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
- "H/RX: match at %s, substituting %s", f, subs) ;
- } )
- s_to = strlen(subs) ;
- len = strlen(ctx->buf) ;
- if ( s_to > s_from) {
- preserve(ctx, s_to - s_from) ;
- memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
- len + 1 - s_from - offs) ;
- memcpy(ctx->buf+offs, subs, s_to) ;
- } else {
- memcpy(ctx->buf + offs, subs, s_to) ;
- memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
- len + 1 - s_from - offs) ;
- }
- }
- } else {
- s_from = strlen(m->from.c) ;
- if ( ! strncasecmp(ctx->buf, m->from.c, s_from ) ) {
- ++num_match ;
- s_to = strlen(m->to) ;
- len = strlen(ctx->buf) ;
- VERBOSE( ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
- "H: matched %s, substituting %s", m->from.c, m->to) ) ;
- if ( s_to > s_from ) {
- preserve(ctx, s_to - s_from) ;
- memmove(ctx->buf+s_to, ctx->buf+s_from,
- len + 1 - s_from ) ;
- memcpy(ctx->buf, m->to, s_to) ;
- } else { /* it fits in the existing space */
- memcpy(ctx->buf, m->to, s_to) ;
- memmove(ctx->buf+s_to, ctx->buf+s_from,
- len + 1 - s_from) ;
- }
- break ;
- }
- }
- if ( num_match > 0 ) /* URIs only want one match */
- break ;
- }
- break ;
- case ATTR_EVENT:
- for ( m = ctx->cfg->map ; m ; m = m->next ) {
- num_match = 0 ; /* reset here since we're working per-rule */
- if ( ! ( m->flags & M_EVENTS ) )
- continue ;
- if ( m->flags & M_REGEX ) {
- nmatch = 10 ;
- offs = 0 ;
- while ( ! ap_regexec(m->from.r, ctx->buf+offs,
- nmatch, pmatch, 0) ) {
- match = pmatch[0].rm_so ;
- s_from = pmatch[0].rm_eo - match ;
- subs = ap_pregsub(ctx->f->r->pool, m->to, ctx->buf+offs,
- nmatch, pmatch) ;
- VERBOSE( {
- const char* f = apr_pstrndup(ctx->f->r->pool,
- ctx->buf + offs , s_from ) ;
- ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
- "E/RX: match at %s, substituting %s", f, subs) ;
- } )
- s_to = strlen(subs) ;
- offs += match ;
- len = strlen(ctx->buf) ;
- if ( s_to > s_from) {
- preserve(ctx, s_to - s_from) ;
- memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
- len + 1 - s_from - offs) ;
- memcpy(ctx->buf+offs, subs, s_to) ;
- } else {
- memcpy(ctx->buf + offs, subs, s_to) ;
- memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
- len + 1 - s_from - offs) ;
- }
- offs += s_to ;
- ++num_match ;
- }
- } else {
- found = strstr(ctx->buf, m->from.c) ;
- if ( (m->flags & M_ATSTART) && ( found != ctx->buf) )
- continue ;
- while ( found ) {
- s_from = strlen(m->from.c) ;
- s_to = strlen(m->to) ;
- match = found - ctx->buf ;
- if ( ( s_from < strlen(found) ) && (m->flags & M_ATEND ) ) {
- found = strstr(ctx->buf+match+s_from, m->from.c) ;
- continue ;
- } else {
- found = strstr(ctx->buf+match+s_to, m->from.c) ;
- }
- VERBOSE( ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
- "E: matched %s, substituting %s", m->from.c, m->to) ) ;
- len = strlen(ctx->buf) ;
- if ( s_to > s_from ) {
- preserve(ctx, s_to - s_from) ;
- memmove(ctx->buf+match+s_to, ctx->buf+match+s_from,
- len + 1 - s_from - match) ;
- memcpy(ctx->buf+match, m->to, s_to) ;
- } else {
- memcpy(ctx->buf+match, m->to, s_to) ;
- memmove(ctx->buf+match+s_to, ctx->buf+match+s_from,
- len + 1 - s_from - match) ;
- }
- ++num_match ;
- }
- }
- if ( num_match && ( m->flags & M_LAST ) )
- break ;
- }
- break ;
- case ATTR_IGNORE:
- break ;
- }
+ pappend(ctx, a[1], strlen(a[1])+1) ;
+ is_uri = ATTR_IGNORE ;
+ if ( linkattrs ) {
+ tattr* attrs = (tattr*) linkattrs->elts;
+ for (i=0; i < linkattrs->nelts; ++i) {
+ if ( !strcmp(*a, attrs[i].val)) {
+ is_uri = ATTR_URI ;
+ break ;
+ }
+ }
+ }
+ if ( (is_uri == ATTR_IGNORE) && ctx->cfg->extfix
+ && (ctx->cfg->events != NULL) ) {
+ for (i=0; i < ctx->cfg->events->nelts; ++i) {
+ tattr* attrs = (tattr*) ctx->cfg->events->elts;
+ if ( !strcmp(*a, attrs[i].val)) {
+ is_uri = ATTR_EVENT ;
+ break ;
+ }
+ }
+ }
+ switch ( is_uri ) {
+ case ATTR_URI:
+ num_match = 0 ;
+ for ( m = themap ; m ; m = m->next ) {
+ if ( ! ( m->flags & M_HTML ) )
+ continue ;
+ if ( m->flags & M_REGEX ) {
+ nmatch = 10 ;
+ if ( ! ap_regexec(m->from.r, ctx->buf, nmatch, pmatch, 0) ) {
+ ++num_match ;
+ offs = match = pmatch[0].rm_so ;
+ s_from = pmatch[0].rm_eo - match ;
+ subs = ap_pregsub(ctx->f->r->pool, m->to, ctx->buf+offs,
+ nmatch, pmatch) ;
+ VERBOSE( {
+ const char* f = apr_pstrndup(ctx->f->r->pool,
+ ctx->buf + offs , s_from ) ;
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
+ "H/RX: match at %s, substituting %s", f, subs) ;
+ } )
+ s_to = strlen(subs) ;
+ len = strlen(ctx->buf) ;
+ if ( s_to > s_from) {
+ preserve(ctx, s_to - s_from) ;
+ memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
+ len + 1 - s_from - offs) ;
+ memcpy(ctx->buf+offs, subs, s_to) ;
+ } else {
+ memcpy(ctx->buf + offs, subs, s_to) ;
+ memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
+ len + 1 - s_from - offs) ;
+ }
+ }
+ } else {
+ s_from = strlen(m->from.c) ;
+ if ( ! strncasecmp(ctx->buf, m->from.c, s_from ) ) {
+ ++num_match ;
+ s_to = strlen(m->to) ;
+ len = strlen(ctx->buf) ;
+ VERBOSE( ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
+ "H: matched %s, substituting %s", m->from.c, m->to) ) ;
+ if ( s_to > s_from ) {
+ preserve(ctx, s_to - s_from) ;
+ memmove(ctx->buf+s_to, ctx->buf+s_from,
+ len + 1 - s_from ) ;
+ memcpy(ctx->buf, m->to, s_to) ;
+ } else { /* it fits in the existing space */
+ memcpy(ctx->buf, m->to, s_to) ;
+ memmove(ctx->buf+s_to, ctx->buf+s_from,
+ len + 1 - s_from) ;
+ }
+ break ;
+ }
+ }
+ /* URIs only want one match unless overridden in the config */
+ if ( (num_match > 0) && !( m->flags & M_NOTLAST ) )
+ break ;
+ }
+ break ;
+ case ATTR_EVENT:
+ for ( m = themap ; m ; m = m->next ) {
+ num_match = 0 ; /* reset here since we're working per-rule */
+ if ( ! ( m->flags & M_EVENTS ) )
+ continue ;
+ if ( m->flags & M_REGEX ) {
+ nmatch = 10 ;
+ offs = 0 ;
+ while ( ! ap_regexec(m->from.r, ctx->buf+offs,
+ nmatch, pmatch, 0) ) {
+ match = pmatch[0].rm_so ;
+ s_from = pmatch[0].rm_eo - match ;
+ subs = ap_pregsub(ctx->f->r->pool, m->to, ctx->buf+offs,
+ nmatch, pmatch) ;
+ VERBOSE( {
+ const char* f = apr_pstrndup(ctx->f->r->pool,
+ ctx->buf + offs , s_from ) ;
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
+ "E/RX: match at %s, substituting %s", f, subs) ;
+ } )
+ s_to = strlen(subs) ;
+ offs += match ;
+ len = strlen(ctx->buf) ;
+ if ( s_to > s_from) {
+ preserve(ctx, s_to - s_from) ;
+ memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
+ len + 1 - s_from - offs) ;
+ memcpy(ctx->buf+offs, subs, s_to) ;
+ } else {
+ memcpy(ctx->buf + offs, subs, s_to) ;
+ memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from,
+ len + 1 - s_from - offs) ;
+ }
+ offs += s_to ;
+ ++num_match ;
+ }
+ } else {
+ found = strstr(ctx->buf, m->from.c) ;
+ if ( (m->flags & M_ATSTART) && ( found != ctx->buf) )
+ continue ;
+ while ( found ) {
+ s_from = strlen(m->from.c) ;
+ s_to = strlen(m->to) ;
+ match = found - ctx->buf ;
+ if ( ( s_from < strlen(found) ) && (m->flags & M_ATEND ) ) {
+ found = strstr(ctx->buf+match+s_from, m->from.c) ;
+ continue ;
+ } else {
+ found = strstr(ctx->buf+match+s_to, m->from.c) ;
+ }
+ VERBOSE( ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r,
+ "E: matched %s, substituting %s", m->from.c, m->to) ) ;
+ len = strlen(ctx->buf) ;
+ if ( s_to > s_from ) {
+ preserve(ctx, s_to - s_from) ;
+ memmove(ctx->buf+match+s_to, ctx->buf+match+s_from,
+ len + 1 - s_from - match) ;
+ memcpy(ctx->buf+match, m->to, s_to) ;
+ } else {
+ memcpy(ctx->buf+match, m->to, s_to) ;
+ memmove(ctx->buf+match+s_to, ctx->buf+match+s_from,
+ len + 1 - s_from - match) ;
+ }
+ ++num_match ;
+ }
+ }
+ if ( num_match && ( m->flags & M_LAST ) )
+ break ;
+ }
+ break ;
+ case ATTR_IGNORE:
+ break ;
+ }