/usr/share/perl5/Data/AMF/Remoting.pm is in libdata-amf-perl 0.09-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | package Data::AMF::Remoting;
use strict;
use warnings;
use Data::AMF::Message;
use Data::AMF::Packet;
use constant CLIENT_PING_OPERATION => 5;
use constant COMMAND_MESSAGE => 'flex.messaging.messages.CommandMessage';
use constant REMOTING_MESSAGE => 'flex.messaging.messages.RemotingMessage';
use constant ACKNOWLEDGE_MESSAGE => 'flex.messaging.messages.AcknowledgeMessage';
sub new {
my $class = shift;
my $self = bless {
source => undef,
data => undef,
headers_did_process => sub {},
message_did_process => sub {},
@_,
}, $class;
if (ref $self->{headers_handler} eq 'CODE') {
$self->{headers_did_process} = $self->{headers_handler};
}
if (ref $self->{message_handler} eq 'CODE') {
$self->{message_did_process} = $self->{message_handler};
}
return $self;
}
sub data { $_[0]->{'data'} }
sub run {
my $self = shift;
my $request = Data::AMF::Packet->deserialize($self->{'source'});
my @headers = @{ $request->headers };
@headers = $self->{'headers_did_process'}->(@headers);
my @messages;
for my $message (@{ $request->messages }) {
my $target_uri = $message->target_uri;
# RemoteObject
if (not defined $target_uri or $target_uri eq 'null') {
my $type = $message->value->[0]->{'_explicitType'};
my $source = $message->value->[0]->{'source'};
my $operation = $message->value->[0]->{'operation'};
if ($type eq COMMAND_MESSAGE and $operation eq CLIENT_PING_OPERATION) {
push @messages, $message->result($message->value->[0]);
}
elsif ($type eq REMOTING_MESSAGE) {
$target_uri = '';
if (defined $source and $source ne '') {
$target_uri .= $source . '.';
}
if (defined $operation and $operation ne '') {
$target_uri .= $operation;
}
my $res = $self->{'message_did_process'}->(
Data::AMF::Message->new(
target_uri => $target_uri,
response_uri => '',
value => $message->value->[0]->{'body'}
)
);
push @messages, $message->result({
correlationId => $message->value->[0]->{'messageId'},
messageId => undef,
clientId => undef,
destination => '',
timeToLive => 0,
timestamp => 0,
body => $res,
headers => {},
_explicitType => ACKNOWLEDGE_MESSAGE,
});
}
else {
die "Recived unsupported message.";
}
}
# Net Connection
else {
my $res = $self->{'message_did_process'}->($message);
push @messages, $message->result($res);
}
}
my $response = Data::AMF::Packet->new(
version => $request->version,
headers => \@headers,
messages => \@messages,
);
$self->{'data'} = $response->serialize;
return $self;
}
1;
__END__
=head1 NAME
Data::AMF::Remoting - handle Flash/Flex RPC.
=head1 SYNOPSIS
use Data::AMF::Remoting
my $remoting = Data::AMF::Remoting->new(
source => $data,
headers_handler => sub
{
my @headers = @_;
# Do authenticate or something.
return @headers;
},
message_handler => sub
{
my $message = shift;
# Call action using target_uri and value.
my ($controller_name, $action) = split '\.', $message->target_uri;
$controller_name->require;
my $controller = $controller_name->new;
return $controller->$action($message->value);
}
);
$remoting->run;
my $data = $remoting->data;
=head1 DESCRIPTION
Data::AMF::Remoting provides to handle Flash/Flex RPC.
=head1 SEE ALSO
L<Data::AMF>
=head1 METHODS
=head2 run
Handle AMF Packet data.
=head1 ACCESSORS
=head2 data
return AMF Data
=head1 AUTHOR
Takuho Yoshizu <seagirl@cpan.org>
=head1 COPYRIGHT
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut
|