httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Travis Bassetti <drchong2000-apa...@yahoo.com>
Subject Customizing mod_include -- Print "virtual" or "file" attribute in handle_include method
Date Thu, 09 Sep 2010 23:30:48 GMT


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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message