--- cvsroot/Net-FCP/FCP.pm 2003/09/15 00:05:32 1.20 +++ cvsroot/Net-FCP/FCP.pm 2003/09/17 05:05:33 1.22 @@ -74,7 +74,7 @@ use Carp; -$VERSION = 0.08; +$VERSION = 0.5; no warnings; @@ -109,15 +109,17 @@ Parse a metadata string and return it. -The metadata will be a hashref with key C (containing -the mandatory version header entries). +The metadata will be a hashref with key C (containing the +mandatory version header entries) and key C containing the original +metadata string. All other headers are represented by arrayrefs (they can be repeated). -Since this is confusing, here is a rather verbose example of a parsed -manifest: +Since this description is confusing, here is a rather verbose example of a +parsed manifest: ( + raw => "Version...", version => { revision => 1 }, document => [ { @@ -140,9 +142,9 @@ =cut sub parse_metadata { - my $meta; - my $data = shift; + my $meta = { raw => $data }; + if ($data =~ /^Version\015?\012/gc) { my $hdr = $meta->{version} = {}; @@ -314,18 +316,22 @@ $self->txn ("client_info"); }); -=item $txn = $fcp->txn_generate_chk ($metadata, $data) +=item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) -=item $uri = $fcp->generate_chk ($metadata, $data) +=item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) -Creates a new CHK, given the metadata and data. UNTESTED. +Calculcates a CHK, given the metadata and data. C<$cipher> is either +C or C, with the latter being the default. =cut $txn->(generate_chk => sub { - my ($self, $metadata, $data) = @_; + my ($self, $metadata, $data, $cipher) = @_; - $self->txn (generate_chk => data => "$metadata$data", metadata_length => length $metadata); + $self->txn (generate_chk => + data => "$metadata$data", + metadata_length => length $metadata, + cipher => $cipher || "Twofish"); }); =item $txn = $fcp->txn_generate_svk_pair @@ -479,7 +485,7 @@ } if (defined $data) { - $attr .= "DataLength=" . (length $data) . "\012"; + $attr .= sprintf "DataLength=%x\012", length $data; $data = "Data\012$data"; } else { $data = "EndMessage\012"; @@ -496,10 +502,10 @@ $self->{sbuf} = "\x00\x00\x00\x02" - . Net::FCP::touc $self->{type} + . (Net::FCP::touc $self->{type}) . "\012$attr$data"; - #$fh->shutdown (1); # freenet buggy?, well, it's java... + #shutdown $fh, 1; # freenet buggy?, well, it's java... $self->{fh} = $fh; @@ -717,7 +723,7 @@ sub rcv_success { my ($self, $attr) = @_; - $self->set_result ($attr); + $self->set_result ($attr->{uri}); } package Net::FCP::Txn::GenerateSVKPair; @@ -784,6 +790,7 @@ my $meta = Net::FCP::parse_metadata substr $data, 0, $self->{metalength}, ""; $self->set_result ([$meta, $data]); + $self->eof; } } @@ -831,7 +838,7 @@ use overload '""' => sub { - "Net::FCP::Exception<<$_[0][0]," . (join ":", %{$_[0][1]}) . ">>\n"; + "Net::FCP::Exception<<$_[0][0]," . (join ":", %{$_[0][1]}) . ">>"; }; =item $exc = new Net::FCP::Exception $type, \%attr