You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Dr Chong <tb...@gmail.com> on 2010/09/10 00:09:02 UTC

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

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:

 







 

Mod_include outputs the content of /foo/bar.html:

               

     

           (Content from /foo/bar.html)

     

               

 

I'd like to tweak mod_include to also output the fragment path:

 

     

    

(Content from /foo/bar.html)


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("", 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:

  

     

(Content from /foo/bar.html)

    
            

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

     

    

(Content from /foo/bar.html)
            

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

Travis
-- 
View this message in context: http://old.nabble.com/Customizing-mod_include----Print-%22virtual%22-or-%22file%22-attribute-in-handle_include-method-tp29671909p29671909.html
Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.