--- cvsroot/Net-FCP/FCP.pm 2003/09/07 22:57:40 1.1 +++ cvsroot/Net-FCP/FCP.pm 2003/09/07 23:23:56 1.4 @@ -33,7 +33,7 @@ use Carp; use IO::Socket::INET; -$VERSION = 0.01; +$VERSION = 0.02; sub event_reg_cb { my ($obj) = @_; @@ -61,6 +61,19 @@ $unregcb = \&event_unreg_cb; $waitcb = \&event_wait_cb; +sub touc($) { + local $_ = shift; + 1 while s/((?:^|_)(?:svk|chk|uri)(?:_|$))/\U$1/; + s/(?:^|_)(.)/\U$1/g; + $_; +} + +sub tolc($) { + local $_ = shift; + s/(?<=[a-z])(?=[A-Z])/_/g; + lc $_; +} + =item $fcp = new Net::FCP [host => $host][, port => $port] Create a new virtual FCP connection to the given host and port (default @@ -94,7 +107,9 @@ sub txn { my ($self, $type, %attr) = @_; - my $txn = "Net::FCP::Txn::$type"->new(fcp => $self, type => $type, attr => \%attr); + $type = touc $type; + + my $txn = "Net::FCP::Txn::$type"->new(fcp => $self, type => tolc $type, attr => \%attr); $txn; } @@ -112,9 +127,9 @@ Executes a ClientHello request and returns it's results. { - MaxFileSize => "5f5e100", - Protocol => "1.2", - Node => "Fred,0.6,1.46,7050" + max_file_size => "5f5e100", + node => "Fred,0.6,1.46,7050" + protocol => "1.2", } =cut @@ -122,7 +137,7 @@ _txn client_hello => sub { my ($self) = @_; - $self->txn ("ClientHello"); + $self->txn ("client_hello"); }; =item $txn = $fcp->txn_client_info @@ -132,27 +147,27 @@ Executes a ClientInfo request and returns it's results. { - MaxFileSize => "5f5e100", - DatastoreMax => "2540be400", - NodePort => 369, - JavaName => "Java HotSpot(TM) Server VM", - OperatingSystemVersion => "2.4.20", - EstimatedLoad => 52, - FreeMemory => "5cc0148", - DatastoreFree => "5ce03400", - NodeAddress => "1.2.3.4", - ActiveJobs => "1f", - AllocatedMemory => "bde0000", - Architecture => "i386", - RoutingTime => "a5", - LeastRecentTimestamp => "f41538b878", - AvailableThreads => 17, - DatastoreUsed => "1f72bb000", - JavaVersion => "Blackdown-1.4.1-01", - IsTransient => "false", - OperatingSystem => "Linux", - JavaVendor => "http://www.blackdown.org/", - MostRecentTimestamp => "f77e2cc520" + active_jobs => "1f", + allocated_memory => "bde0000", + architecture => "i386", + available_threads => 17, + datastore_free => "5ce03400", + datastore_max => "2540be400", + datastore_used => "1f72bb000", + estimated_load => 52, + free_memory => "5cc0148", + is_transient => "false", + java_name => "Java HotSpot(_T_M) Server VM", + java_vendor => "http://www.blackdown.org/", + java_version => "Blackdown-1.4.1-01", + least_recent_timestamp => "f41538b878", + max_file_size => "5f5e100", + most_recent_timestamp => "f77e2cc520" + node_address => "1.2.3.4", + node_port => 369, + operating_system => "Linux", + operating_system_version => "2.4.20", + routing_time => "a5", } =cut @@ -160,7 +175,7 @@ _txn client_info => sub { my ($self) = @_; - $self->txn ("ClientInfo"); + $self->txn ("client_info"); }; =item $txn = $fcp->txn_generate_chk ($metadata, $data) @@ -174,7 +189,7 @@ _txn generate_chk => sub { my ($self, $metadata, $data) = @_; - $self->txn (GenerateCHK => data => "$data$metadata", MetaDataLength => length $metadata); + $self->txn (generate_chk => data => "$data$metadata", meta_data_length => length $metadata); }; =item $txn = $fcp->txn_generate_svk_pair @@ -193,7 +208,7 @@ _txn generate_svk_pair => sub { my ($self) = @_; - $self->txn ("GenerateSVKPair"); + $self->txn ("generate_svk_pair"); }; =item $txn = $fcp->txn_insert_private_key ($private) @@ -213,7 +228,7 @@ _txn insert_private_key => sub { my ($self, $privkey) = @_; - $self->txn (InvertPrivateKey => Private => $privkey); + $self->txn (invert_private_key => private => $privkey); }; =item $txn = $fcp->txn_get_size ($uri) @@ -230,7 +245,7 @@ _txn get_size => sub { my ($self, $uri) = @_; - $self->txn (GetSize => URI => $uri); + $self->txn (get_size => URI => $uri); }; =item MISSING: ClientGet, ClientPut @@ -268,7 +283,7 @@ my $data = delete $self->{attr}{data}; while (my ($k, $v) = each %{$self->{attr}}) { - $attr .= "$k=$v\012" + $attr .= (Net::FCP::touc $k) . "=$v\012" } if (defined $data) { @@ -285,14 +300,16 @@ binmode $fh, ":raw"; - print - $self->{type}, "\012", - $attr, - $data, "\012"; + if (0) { + print + Net::FCP::touc $self->{type}, "\012", + $attr, + $data, "\012"; + } print $fh "\x00\x00", "\x00\x02", # SESSID, PRESID - $self->{type}, "\012", + Net::FCP::touc $self->{type}, "\012", $attr, $data; @@ -319,7 +336,10 @@ } elsif ($self->{buf} =~ s/^DataChunk\015?\012Length=(\d+)\015?\012Data\015?\012//) { $self->{datalen} = $1; } elsif ($self->{buf} =~ s/^([a-zA-Z]+)\015?\012(.*?)\015?\012EndMessage\015?\012//s) { - $self->rcv ($1, {map { split /=/, $_, 2 } split /\015?\012/, $2}); + $self->rcv ($1, { + map { my ($a, $b) = split /=/, $_, 2; ((Net::FCP::tolc $a), $b) } + split /\015?\012/, $2 + }); } else { last; } @@ -337,9 +357,10 @@ sub rcv { my ($self, $type, $attr) = @_; - #use PApp::Util;warn "$type => ".PApp::Util::dumpval($attr); - if (my $method = $self->can("rcv_\L$type")) { + $type = Net::FCP::tolc $type; + + if (my $method = $self->can("rcv_$type")) { $method->($self, $attr, $type); } else { warn "received unexpected reply type '$type' for '$self->{type}', ignoring\n"; @@ -378,7 +399,7 @@ use base Net::FCP::Txn; -sub rcv_nodehello { +sub rcv_node_hello { my ($self, $attr) = @_; $self->eof ($attr); @@ -388,7 +409,7 @@ use base Net::FCP::Txn; -sub rcv_nodeinfo { +sub rcv_node_info { my ($self, $attr) = @_; $self->eof ($attr);