You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rob Hartill <ro...@imdb.com> on 1997/05/15 15:53:47 UTC
[PATCH]: request for harmless mod_include.c patch
Attached is a patch for mod_include.c that'l be VERY useful for mod_perl
users. We were going to wait until after 1.2 was out the door, but thought it
would be worth trying now since it is completely $ifdef'ed into harmlessness.
Basically, it adds <!--#perl ... --> to SSI so that any dynamically
generated perl or embedded subroutines can be called as includes.
I asked Doug for this so that I could avoid having to go through
long winded <Location /foo> type handlers to run a HTML included bit of
Perl under the control of mod_perl.
Pretty please ?. Doug's been holding off mod_perl 1.0 waiting for Apache
1.2, and it'd be nice not to need to patch things once both are
released.
--
Rob Hartill Internet Movie Database (Ltd)
http://us.imdb.com/tour .. a site for sore eyes.
( ps. mod_perl can be found at http://www.osf.org/~dougm/apache/ )
Index: mod_include.c
===================================================================
RCS file: /imdb/cvs/apache/src/mod_include.c,v
retrieving revision 1.10
diff -u -r1.10 mod_include.c
--- mod_include.c 1997/05/11 20:40:26 1.10
+++ mod_include.c 1997/05/15 12:42:23
@@ -57,7 +57,25 @@
* incorporated into the Apache module framework by rst.
*
*/
+/* to enable <!--#perl,
+ * add -I./ and -I$Config{archlibexp}/CORE to EXTRA_CFLAGS
+ *
+ * sub key may be anything a Perl*Handler can be:
+ * subroutine name, package name (defaults to package::handler),
+ * Class->method call or anoymous sub {}
+ *
+ * Child <!--#perl sub="sub {print $$}" --> accessed
+ * <!--#perl sub="sub {print ++$Access::Cnt }" --> times. <br>
+ *
+ * <!--#perl arg="one" sub="mymod::includer" -->
+ *
+ * -Doug MacEachern
+ */
+#define USE_PERL
+#ifdef USE_PERL
+#include "modules/perl/mod_perl.h"
+#else
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
@@ -66,6 +84,7 @@
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
+#endif
#define STARTING_SEQUENCE "<!--#"
#define ENDING_SEQUENCE "-->"
@@ -710,6 +729,27 @@
}
}
}
+#ifdef USE_PERL
+int handle_perl (FILE *in, request_rec *r, char *error) {
+ char tag[MAX_STRING_LEN];
+ char *tag_val;
+ SV *sub = Nullsv;
+ AV *av = newAV();
+
+ while(1) {
+ if(!(tag_val = get_tag (r->pool, in, tag, MAX_STRING_LEN, 1)))
+ break;
+ if(strnEQ(tag, "sub", 3))
+ sub = newSVpv(tag_val,0);
+ else if(strnEQ(tag, "arg", 3))
+ av_push(av, newSVpv(tag_val,0));
+ else if(strnEQ(tag,"done", 4))
+ break;
+ }
+ perl_call_handler(sub, r, av);
+ return OK;
+}
+#endif
/* error and tf must point to a string with room for at
* least MAX_STRING_LEN characters
@@ -1674,6 +1714,10 @@
ret=handle_flastmod(f, r, error, timefmt);
else if(!strcmp(directive,"printenv"))
ret=handle_printenv(f, r, error);
+#ifdef USE_PERL
+ else if(!strcmp(directive,"perl"))
+ ret=handle_perl(f, r, error);
+#endif
else {
log_printf(r->server,
"httpd: unknown directive %s in parsed doc %s",