On 10/21/2010 08:35 AM, Alexander Farber wrote:
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?
To adjust @INC at start-up:
<IfModule mod_perl.c>
PerlSwitches -I /my/perl/lib
</IfModule>
Or, you can run a perl script at startup (which contains the "use lib
'/my/perl/lib';"):
<IfModule mod_perl.c>
PerlRequire /my/startup.pl
</IfModule>
See also:
http://perl.apache.org/docs/2.0/user/config/config.html#Adjusting_C__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?
No idea...
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?
Something else: if your module dies, mod_perl will send an error
document and set the status code for the response.
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;