Subject: | [patch] Modify Apache::XMLRPC for use with both MP1.x and MP2.x |
The attached patch allows XMLRPC to be used by either MP1 or MP2.
Subject: | XMLRPC-mp2.diff |
--- XMLRPC.pm.orig 2006-03-22 10:22:29.281190000 -0800
+++ XMLRPC.pm 2006-03-22 11:08:17.063820000 -0800
@@ -10,33 +10,60 @@
package Apache::XMLRPC;
-use Apache::Constants qw(:common);
+use strict;
+use warnings;
+
use Frontier::RPC2;
+use constant MP2 =>
+ ( exists $ENV{MOD_PERL_API_VERSION} and $ENV{MOD_PERL_API_VERSION} >= 2 );
+
+BEGIN {
+ if (MP2) {
+ require Apache2::ServerUtil;
+ require Apache2::Const;
+ Apache2::Const->import( -compile => 'OK' );
+ }
+ else {
+ require Apache::Constants;
+ Apache::Constants->import('OK');
+ }
+}
sub handler {
- my $r = shift;
+ my $r = shift;
- my $conf = $r->server_root_relative( $r->dir_config( "XMLRPC_Config" ) );
+ my $path = $r->dir_config( "XMLRPC_Config" );
+ my $conf = MP2
+ ? Apache2::ServerUtil::server_root_relative( $r->pool, $path )
+ : $r->server_root_relative( $path );
- if( -f $conf ) {
- unless( $rt = do $conf ) {
- die "Couldn\'t parse conf file ($conf): $@\n" if $@;
- die "Couldn\'t compile conf file ($conf): $!\n" unless defined $rt;
- die "Couldn\'t run conf file ($conf)\n" unless $rt;
- }
- }
+ if ( -f $conf ) {
+ unless ( my $rt = do $conf ) {
+ die "Couldn\'t parse conf file ($conf): $@\n" if $@;
+ die "Couldn\'t compile conf file ($conf): $!\n" unless defined $rt;
+ die "Couldn\'t run conf file ($conf)\n" unless $rt;
+ }
+ }
+
+ my $decoder = Frontier::RPC2->new();
+
+ my $clength = MP2
+ ? $r->headers_in->{'Content-length'}
+ : $r->header_in('Content-length');
- my $decoder = Frontier::RPC2->new();
+ if (defined $clength and $clength >= 0) {
+ my ($content, $answer);
- my $content;
- $r->read( $content, $r->header_in( 'Content-length' ) );
+ $r->read( $content, $clength );
- my $answer = $decoder->serve( $content, $Apache::XMLRPC::map );
+ no warnings 'once'; # Prevent warnings on XMLRPC::map
+ $answer = $decoder->serve( $content, $Apache::XMLRPC::map );
- $r->send_http_header();
- $r->print($answer);
+ $r->send_http_header() unless MP2;
+ $r->print( $answer );
+ }
- return OK;
+ return MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}
1;