Stas et all,
Here's the code that I was using to grab POSTed values and put them into a hash 0 sorry for the verbosity of this post, I won't pretend to fully understand this code, Stas wrote the majority of it way back when libapreq wouldn't compile on NetBSD, and I've been using it ever since.
If there's a better way to do this with libapreq, I'd preobably like to move my code over to using it!
Code attached, which no longer works :
I call this to fill a simple hash, eg :
my %posted_data = CB::hash_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->is_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 $string; }
sub hash_post { # this has to get called instead of read_post, as read_post() # gobbles up the POST arguments and they're no longer available... # and this calls read_post() :)
# returns a hash of all the POST values
my ($r) = shift;
my $post_string = CB::read_post($r); my %rethash = {};
my @bits = split(/&/, $post_string); foreach my $bit (@bits) { $bit =~ /^(.*)=(.*)$/; my $key = CGI::Util::unescape($1); my $value = CGI::Util::unescape($2); $rethash{$key} = $value; } return %rethash; }
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html