I have big concerns regarding Apache::compat. We already have a few compatibility wrappers which totally change the normal 2.0 API. If anything at all loads Apache::compat, handlers using normal 2.0 API may not work correctly. So any code requiring usage of Apache::compat may not be able to co-exist on the same server with normal 2.0 API handlers. The revelation will of course come through unexpected behavior in user code and multiple bug reports.

You can grep lib/Apache/compat.pm for {CODE}:

    my $notes_sub = *Apache::RequestRec::notes{CODE};
    my $sub = *APR::URI::unparse{CODE};

Now I was just about to add two new wrappers:

    my $sub = *Apache::Connection::local_addr{CODE};
    my $sub = *Apache::Connection::remote_addr{CODE};

which will make it impossible to use the normal $c->local_addr and $c->remote_addr, which in 2.0 lingo return an APR::SockAddr objects.
See the patch below.


If it was possible to use Apache::compat as a pragma, so the behavior will change only for the scope of the file it's used in that would be great. But I don't think it's quite possible.

Ideas?


Index: lib/Apache/compat.pm =================================================================== RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v retrieving revision 1.85 diff -u -r1.85 compat.pm --- lib/Apache/compat.pm 11 Apr 2003 07:34:03 -0000 1.85 +++ lib/Apache/compat.pm 2 Jun 2003 03:16:08 -0000 @@ -39,6 +39,8 @@ use APR::Util (); use mod_perl (); use Symbol (); +use APR::SockAddr (); +use Socket;

 BEGIN {
     $INC{'Apache.pm'} = __FILE__;
@@ -592,6 +594,37 @@
 # 'PerlOptions +GlobalRequest' is required
 sub auth_type { shift; Apache->request->ap_auth_type(@_) }
 sub user      { shift; Apache->request->user(@_)      }
+
+
+{
+    my $sub = *Apache::Connection::local_addr{CODE};
+
+    *Apache::Connection::local_addr = sub {
+        my $c = shift;
+        return Socket::pack_sockaddr_in(
+            $c->$sub->port_get,
+            Socket::inet_aton($c->$sub->ip_get));
+    };
+}
+
+{
+    my $sub = *Apache::Connection::remote_addr{CODE};
+    *Apache::Connection::remote_addr = sub {
+        my $c = shift;
+        if (@_) {
+            my $addr_in = shift;
+            my($port, $addr) = Socket::unpack_sockaddr_in($addr_in);
+            $c->$sub->ip_set($addr);
+            $c->$sub->port_set($port);
+        }
+        else {
+            return Socket::pack_sockaddr_in(
+                $c->$sub->port_get,
+                Socket::inet_aton($c->$sub->ip_get));
+        }
+    };
+}
+

and a test:

package TestCompat::conn;

# compat checks for
#   $r->connection->auth_type
#   $r->connection->user
# both records don't exist in 2.0 conn_rec and therefore require
# 'PerlOptions +GlobalRequest' to retrieve those via Apache->request

use strict;
use warnings FATAL => 'all';

use Apache::TestUtil;
use Apache::Test;

use Apache::compat ();

use Socket qw(sockaddr_in inet_ntoa);

use Apache::Constants qw(OK);

sub handler {

my $r = shift;

my $c = $r->connection;

plan $r, tests => 4;

    my ($local_port, $local_addr) = sockaddr_in($c->local_addr);
    t_debug inet_ntoa($local_addr) . " :$local_port";
    ok $local_port;
    ok inet_ntoa($local_addr);

    my ($remote_port, $remote_addr) = sockaddr_in($c->remote_addr);
    t_debug inet_ntoa($remote_addr) . " :$remote_port";
    ok $remote_port;
    ok inet_ntoa($remote_addr);

    OK;
}

1;

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to