Hello mod_perl 2 users,

I have 3 questions please:

1) How do you specify the path to your custom module,
    so that Apache 2 can load it at the startup?

    I'm using mod_perl-2.0.4-6.el5 with CentOS Linux 5.5 and
    have the following lines in /etc/httpd/conf.d/perl.conf:

    LoadModule perl_module modules/mod_perl.so
    .......
    Listen 843
    <VirtualHost _default_:843>
        PerlModule                   SocketPolicy
        PerlProcessConnectionHandler SocketPolicy
    </VirtualHost>

    but this works only if I put my SocketPolicy.pm
    under /etc/httpd. Otherwise it isn't found in @INC.

2) The "perldoc APR:Socket" suggests an example:

         # read from/write to the socket (w/o handling possible failures)
         my $wanted = 1024;
         while ($sock->recv(my $buffer, $wanted)) {
             $sock->send($buffer);
         }

    and later it also says the mod_perl will handle errors for you.

    Shouldn't return values from send() be checked in
    a loop for the cases, that it wasn't able to write the
    complete buffer in 1 pass? Or does send($buffer)
    alsways write the complete $buffer to the blocking socket?

    And what does it mean "mod_perl will handle errors for you"?
    Does it catch exception coming from send()/recv()
    and print it to error_log or is is something else?

3) And the 3rd question is optional (because I'll probably find
    this in the docs soon), but maybe someone can tell me, how
    to log the IP of the socket peer in my module to access_log?

Thank you and below is my module
Alex

# cat /etc/httpd/SocketPolicy.pm
package SocketPolicy;

# Run: semanage port -a -t http_port_t -p tcp 843
# And add following lines to the httpd.conf
# Listen 843
# <VirtualHost _default_:843>
#       PerlModule                   SocketPolicy
#       PerlProcessConnectionHandler SocketPolicy
# </VirtualHost>

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

use Apache2::Connection();
use APR::Socket();

use Apache2::Const(-compile => 'OK');
use APR::Const(-compile => 'SO_NONBLOCK');

use constant POLICY =>
qq{<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd";>

<cross-domain-policy>
<allow-access-from domain="*" to-ports="8080"/>
</cross-domain-policy>
\0};

sub handler {
        my $c = shift;
        my $sock = $c->client_socket;

        # set the socket to the blocking mode
        $sock->opt_set(APR::Const::SO_NONBLOCK => 0);

        $sock->send(POLICY);

        Apache2::Const::OK;
}

1;

Reply via email to