Stas Bekman wrote:
Carl Brewer wrote:
I'm using Stas's read_post() call from the test directory in mp1.99-10-dev, and am using it to grab POST data of the form of an email address ..
this is giving me this :
read_post returned : username=carl%40somewhere&password=foo
Escaped the @ ... of course.
I'm curios, where's the best place to unescape it? Should I do it in the read_post function, or afterwards?
Recommendations?
Look at CGI.pm, you could easily prototype your code after it, as it's written in pure perl. Hint: look at the function param().
For the archives, if anyone's interested, I used CGI::Util::unescape()
My read_lines() subroutine is now (cribbed extensively from Stas's test scripts) :
$post_params = read_post($r);
sub read_post {
use Apache::Filter ();
use APR::Bucket ();
use APR::Brigade ();
use constant IOBUFSIZE => 8192;
use Apache::Const -compile => qw(MODE_READBYTES);
use APR::Const -compile => qw(SUCCESS BLOCK_READ);use CGI::Util;
my $r = shift;
my $debug = shift || 0; my @data = ();
my $seen_eos = 0;
my $filters = $r->input_filters();
my $ba = $r->connection->bucket_alloc;
my $bb = APR::Brigade->new($r->pool, $ba); do {
my $rv = $filters->get_brigade($bb,
Apache::MODE_READBYTES, APR::BLOCK_READ, IOBUFSIZE);
if ($rv != APR::SUCCESS) {
return $rv;
} while (!$bb->empty) {
my $buf;
my $b = $bb->first;$b->remove;
if ($b->is_eos) {
warn "EOS bucket:\n" if $debug;
$seen_eos++;
last;
} my $status = $b->read($buf);
warn "DATA bucket: [$buf]\n" if $debug;
if ($status != APR::SUCCESS) {
return $status;
}
push @data, $buf;
}$bb->destroy;
} while (!$seen_eos);
my $string = join '', @data;
return CGI::Util::unescape($string);
}Seems to work ok in lieu of Apache::Request being available.
Carl
