Thanks Ryan and Torsten -
2010/10/21 Torsten Förtsch <[email protected]>:
> On Thursday, October 21, 2010 15:21:37 Alexander Farber wrote:
>> [error] Can't locate object method "log" via package
>> "Apache2::ServerRec" at /etc/httpd/SocketPolicy.pm line 39.\n
>
> you probably miss a "use Apache2::ServerRec ()" and perhaps a
> "use Apache2::Log ()" in your code.
3) that has helped. I've ended up with
my $slog = $c->base_server()->log();
$slog->warn('served socket policy to: ', $c->remote_ip(), ',
bytes: ', $nbytes);
- I had to take warn() because don't want to increase LogLevel.
But actually I would prefer printing to access_log and not error_log.
Is there a way for that?
2) I've looked at
http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sendrecv.c?view=markup
If APR::Socket::send() is autogenerated from apr_socket_send()
then the loop is already there and I don't need it in my Perl code.
Regards
Alex
PS: My current code:
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::ServerRec();
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);
my $nbytes = $sock->send(POLICY);
my $slog = $c->base_server()->log();
$slog->warn('served socket policy to: ', $c->remote_ip(), ',
bytes: ', $nbytes);
Apache2::Const::OK;
}
1;