You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Douglas Sims <ra...@gmail.com> on 2009/08/20 09:20:59 UTC

Confusion over Apache2::Request and Apache2::RequestRec

I'm confused about something and I wonder if anyone can help me to
understand what's going on.  The code shown below works fine but as I was
looking over this before changing something else I realized that it probably
shouldn't.  I'm using an Apache2::Request object to return a connection
object to get the remote_ip but the documentation for Apache2::Request
doesn't show a connection method - that's in Apache2::RequestRec.

Why does connection() work on an Apache2::Request object?

Thanks!

-Doug


Apache2::Request:
http://httpd.apache.org/apreq/docs/libapreq2/group__apreq__xs__request.html
Apache2::RequestRec:
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_connection_


In the PerlResponseHandler:

  my $requestrec = shift if $ENV{MOD_PERL};
  my $request = Apache2::Request->new($requestrec);
  my $session = Sessions->new($request, $mysql);



{package Sessions;

  sub new {
    my $class=shift;
    my $self={};
    bless ($self, $class);

    $self->{REQUEST}=shift;
    $self->{DBH}=shift;

{...snip...}

        $self->{DBH}->do('INSERT INTO failedloginattempts (username,
password, ip, session, attempttime) VALUES
('.$self->{DBH}->quote($username).','.$self->{DBH}->quote($password).',
INET_ATON('.$self->{DBH}->quote(*$self->{REQUEST}->connection()->remote_ip*).'),
'.$self->{DBH}->quote($self->{SESSION}).', NOW())');

Re: Confusion over Apache2::Request and Apache2::RequestRec

Posted by Joe Schaefer <jo...@yahoo.com>.
Apache2::Request is a derived class of Apache2::RequestRec,
so what you're doing is perfectly ok.



>
>From: Douglas Sims <ra...@gmail.com>
>To: modperl <mo...@perl.apache.org>
>Sent: Thursday, August 20, 2009 3:20:59 AM
>Subject: Confusion over Apache2::Request and Apache2::RequestRec
>
>
>I'm confused about something and I wonder if anyone can help me to understand what's going on.  The code shown below works fine but as I was looking over this before changing something else I realized that it probably shouldn't.  I'm using an Apache2::Request object to return a connection object to get the remote_ip but the documentation for Apache2::Request doesn't show a connection method - that's in Apache2::RequestRec.
>
>Why does connection() work on an Apache2::Request object?
>
>Thanks!
>
>-Doug
>
>
>Apache2::Request: http://httpd.apache.org/apreq/docs/libapreq2/group__apreq__xs__request.html
>>Apache2::RequestRec: http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_connection_
>
>
>In the PerlResponseHandler:
>
>  my $requestrec = shift if $ENV{MOD_PERL};
>  my $request = Apache2::Request->new($requestrec);
>  my $session = Sessions->new($request, $mysql);
>
>
>
>{package Sessions;
>
>  sub new {
>    my $class=shift;
>>    my $self={};
>    bless ($self, $class);
>
>    $self->{REQUEST}=shift;
>    $self->{DBH}=shift;
>
>{...snip...}
>
>        $self->{DBH}->do('INSERT INTO failedloginattempts (username, password, ip, session, attempttime) VALUES ('.$self->{DBH}->quote($username).','.$self->{DBH}->quote($password).', INET_ATON('.$self->{DBH}->quote($self->{REQUEST}->connection()->remote_ip).'), '.$self->{DBH}->quote($self->{SESSION}).', NOW())');
>
>
>