Determining if a bucket is created by !--#include or !--#echo SSI directives

2010-10-29 Thread Travis Bassetti


Apache Gurus:

Is it possible to determine the origin of a bucket in a brigade?   I have 
written a filter 


static apr_status_t mod_ssitag_content_filter(ap_filter_t *f, 
apr_bucket_brigade *bb)

 which needs to provide special processing of any bucket created from the 
#include directive via mod_include.Is there a way to tell when a bucket is 
created via #include?   I want to exclude processing the bucket if it was 
created by the #echo directive.I can't tell if there is a difference in the 
bucket type when created by #include or #echo.   Is there some other flag or 
way 
to differentiate these buckets?

Thanks for your help!

Travis


Filters before mod_include

2010-10-02 Thread Travis Bassetti
Is it possible to register an output filter that processes the request before 
mod_include?   I'm trying to build a filter which inserts extra markup around 
each #include virtual SSI directive.   I can only seem to register an output 
filter after mod_include as mod_include declares APR_HOOK_REALLY_FIRST in its 
configuration. 


I'd prefer not to have to modify the mod_include source.   Any guidance/help on 
this would be appreciated!

Travis


Customizing mod_include -- Print virtual or file attribute in handle_include method

2010-09-09 Thread Travis Bassetti


Apache Development Gurus:


I've worked with Apache for awhile now, but this is my first time tinkering 
with 
the source code for one of its modules.   I'd like to alter mod_include to 
print 
out as a HTML comment all server side include references.   My apologies if 
this 
is a trivial matter.


For instance, if an HTML page has an SSI:
 
body
!--#include virtual=”/foo/bar.html” --
/body
 
Mod_include outputs the content of /foo/bar.html:

 body
   (Content from /foo/bar.html)
 /body

 
I'd like to tweak mod_include to also output the fragment path:
 
 body
!—fragment=”/foo/bar.html” --
(Content from /foo/bar.html)/body 

I've been able to successfully print out the include path *after* the filter 
has 
processed the SSI, but I'd like to add a comment before processing of the SSI. 
   Here's a snippet of the handle_include method from mod_include.c that I've 
changed:

 //..etc..
  parsed_string = ap_ssi_parse_string(ctx, tag_val, NULL, 0,
SSI_EXPAND_DROP_NAME);

//New code

   APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(!-- fragment=', 
strlen(!-- fragment='),
ctx-pool, f-c-bucket_alloc));

APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(parsed_string, 
strlen(parsed_string),
ctx-pool, f-c-bucket_alloc));

   APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(' --, strlen(' --),
ctx-pool, f-c-bucket_alloc));

//End new code

//Original source code -- continues to process include

  if (tag[0] == 'f') {
char *newpath;
apr_status_t rv;

/* be safe; only files  in this directory or below allowed */
rv = apr_filepath_merge(newpath, NULL, parsed_string,
APR_FILEPATH_SECUREROOTTEST |
APR_FILEPATH_NOTABSOLUTE, ctx-dpool);

if (rv != APR_SUCCESS) {
error_fmt = unable to include file \%s\ in parsed file  %s;
}
else {
rr = ap_sub_req_lookup_file(newpath, r, f-next);
}
}
else {
rr = ap_sub_req_lookup_uri(parsed_string, r, f-next);
}

  //etc...

The modifications above will print the fragment path after the SSI content:

   

 body
(Content from /foo/bar.html)
!—fragment=”/foo/bar.html” --
/body 

What updates do I need to make to this code to force the fragment path to be 
printed before the SSI content:


 body
!—fragment=”/foo/bar.html” --
(Content from /foo/bar.html)
/body 

Any guidance on this matter would be greatly appreciated.   Thanks,

Travis