Hello,
I have a simple protocol handler which writes a string to client
socket (source code below).
I would like to make that string configurable through httpd.conf, so
that I could say there:
Listen 843
<VirtualHost _default_:843>
MyPolicyString "<xml>blah</xml>"
PerlModule SocketPolicy
PerlProcessConnectionHandler SocketPolicy
</VirtualHost>
I keep reading http://perl.apache.org/docs/2.0/user/ and other docs,
but just can't find how to do it. Do you use PerlPostConfigHandler for
that and how would I get that string in my
PerlProcessConnectionHandler?
I've noticed, that I could use a Apache2::Directive or a
$r->dir_config("MyPerlVar") but those seem to be slower and are
mod_perl-ish. I would like to use the mod_perl method corresponding to
the command_rec structure in C, where you would use an AP_INIT_TAKE1
(I guess... I'm not an expert here).
Thanks
Alex
package SocketPolicy;
use strict;
use warnings FATAL => 'all';
use APR::Const(-compile => 'SO_NONBLOCK');
use APR::Socket();
use Apache2::ServerRec();
use Apache2::Connection();
use Apache2::Const(-compile => qw(OK DECLINED));
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 $conn = shift;
my $socket = $conn->client_socket();
my $offset = 0;
# set the socket to the blocking mode
$socket->opt_set(APR::Const::SO_NONBLOCK => 0);
# XXX use the policy string coming from httpd.conf XXX
do {
my $nbytes = $socket->send(substr(POLICY, $offset),
length(POLICY) - $offset);
# client connection closed or interrupted
return Apache2::Const::DECLINED unless $nbytes;
$offset += $nbytes;
} while ($offset < length(POLICY));
my $slog = $conn->base_server()->log();
$slog->warn('served socket policy to: ', $conn->remote_ip());
return Apache2::Const::OK;
}
1;
|