Happy New Year, everyone.
I need some quick help with handling my content in an output filter.
I'd like to know how I can get the portion of client content before the
<head> tag (if it exists), and the portion after it. That way, I can
insert something just after the <head> tag (adult content warnings, etc).
I seem to get stuck right after finding the position of the head tag. I
can send on the tail end, but don't know how to capture the beginning
portion:
...
apr_bucket_read(e, &str, &len, APR_NONBLOCK_READ);
if ( ( position = strcasestr(str, search_tag) ) == NULL )
{
/*
* If we didn't find the <head> tag, just pass along
* everything to the next filter and we're done.
*/
ap_fputs(f->next, ctx->bb, str);
}
else
{
/*
* so, we have a <head> tag. So, lets find and process it
* and insert our notice.
*/
tail = position + 6;
head = ??? <<<<<<<<< Here's where I'm stuck...
ap_fputs(f->next, ctx->bb, "<!-- start test -->\n");
/*
ap_fputs(f->next, ctx->bb, head);
*/
ap_fputs(f->next, ctx->bb, "<html>\n<head>\n<meta />\n");
ap_fputs(f->next, ctx->bb, "<!-- after head, before tail -->\n");
ap_fputs(f->next, ctx->bb, tail);
ap_fputs(f->next, ctx->bb, "<!-- end test -->\n");
}
}
return APR_SUCCESS;
}
There's much more to code to make this thing work right, but this is my
first hurdle.
Please point out any other major idiotic mistakes I'm making.
Thanks,
--
Drew