neerfri-ramf 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +166 -0
- data/README +3 -0
- data/Rakefile +17 -0
- data/lib/ramf/amf_header.rb +9 -0
- data/lib/ramf/amf_message.rb +26 -0
- data/lib/ramf/amf_object.rb +54 -0
- data/lib/ramf/configuration.rb +8 -0
- data/lib/ramf/default_operation_processor.rb +20 -0
- data/lib/ramf/deserializer/amf0_reader.rb +61 -0
- data/lib/ramf/deserializer/amf3_reader.rb +242 -0
- data/lib/ramf/deserializer/base.rb +76 -0
- data/lib/ramf/deserializer.rb +9 -0
- data/lib/ramf/extensions/class.rb +139 -0
- data/lib/ramf/extensions/exception.rb +3 -0
- data/lib/ramf/extensions/hash.rb +8 -0
- data/lib/ramf/extensions/object.rb +44 -0
- data/lib/ramf/flex_class_traits.rb +98 -0
- data/lib/ramf/flex_objects/acknowledge_message.rb +31 -0
- data/lib/ramf/flex_objects/byte_array.rb +9 -0
- data/lib/ramf/flex_objects/command_message.rb +86 -0
- data/lib/ramf/flex_objects/error_message.rb +14 -0
- data/lib/ramf/flex_objects/flex_anonymous_object.rb +37 -0
- data/lib/ramf/flex_objects/flex_object.rb +13 -0
- data/lib/ramf/flex_objects/remoting_message.rb +26 -0
- data/lib/ramf/io/common_read_write.rb +73 -0
- data/lib/ramf/io/constants.rb +79 -0
- data/lib/ramf/io/flex_class_signature.rb +16 -0
- data/lib/ramf/io/place_holder.rb +8 -0
- data/lib/ramf/io/reference_table.rb +74 -0
- data/lib/ramf/operation_processors_manager.rb +30 -0
- data/lib/ramf/operation_request.rb +51 -0
- data/lib/ramf/serializer/amf0_writer.rb +89 -0
- data/lib/ramf/serializer/amf3_writer.rb +193 -0
- data/lib/ramf/serializer/base.rb +57 -0
- data/lib/ramf/serializer.rb +9 -0
- data/lib/ramf/util.rb +34 -0
- data/lib/ramf.rb +62 -0
- data/spec/amf_object_spec.rb +85 -0
- data/spec/deserializer_spec.rb +22 -0
- data/spec/examples/examples_helper.rb +75 -0
- data/spec/examples/remoting_login_spec.rb +53 -0
- data/spec/examples/simple_amf_spec.rb +55 -0
- data/spec/examples/simple_remoting_spec.rb +60 -0
- data/spec/extensions/class_extensions_spec.rb +62 -0
- data/spec/fixtures/catalog.yml +5 -0
- data/spec/fixtures/deserializer1.bin +0 -0
- data/spec/fixtures/deserializer1.rb +31 -0
- data/spec/fixtures/deserializer2.bin +0 -0
- data/spec/fixtures/deserializer2.rb +40 -0
- data/spec/fixtures/deserializer3.bin +0 -0
- data/spec/fixtures/ping_command_message.amf +0 -0
- data/spec/fixtures/remoting_login_operation.amf +0 -0
- data/spec/fixtures/simple_remoting_message.amf +0 -0
- data/spec/flex_class_traits_spec.rb +52 -0
- data/spec/inherited_class_traits_spec.rb +58 -0
- data/spec/io/reference_table_spec.rb +38 -0
- data/spec/operation_processors_manager_spec.rb +61 -0
- data/spec/serializer/amf3_writer_spec.rb +565 -0
- data/spec/serializer/base_spec.rb +92 -0
- data/spec/serializer/full_spec.rb +172 -0
- data/spec/spec_helper.rb +28 -0
- metadata +153 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
166
|
+
|
data/README
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
RAKE_BASE = File.dirname(__FILE__)
|
|
5
|
+
CURRENT_VERSION = File.open(File.join(RAKE_BASE, "GEM_VERSION")) do |f|
|
|
6
|
+
version = nil
|
|
7
|
+
f.each_line { |l| version = $1 if l=~/^(\d+\.\d+\.\d+)/ }
|
|
8
|
+
version ? version : raise("could not find gem version in #{File.join(RAKE_BASE, 'GEM_VERSION')}")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].sort.each { |ext| load ext }
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module RAMF
|
|
2
|
+
class AMFMessage
|
|
3
|
+
attr_accessor :target_uri, :response_uri, :value, :length, :amf_version
|
|
4
|
+
KNOWN_MESSAGE_OBJECTS = ["RAMF::FlexObjects::CommandMessage","RAMF::FlexObjects::RemotingMessage"]
|
|
5
|
+
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@target_uri = options[:target_uri]
|
|
8
|
+
@response_uri = options[:response_uri]
|
|
9
|
+
@value = options[:value]
|
|
10
|
+
@length = options[:length] || -1
|
|
11
|
+
@amf_version = options[:amf_version] || 3
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_operation(options = {})
|
|
15
|
+
if KNOWN_MESSAGE_OBJECTS.include?(@value.first.class.name)
|
|
16
|
+
@value.first.to_operation
|
|
17
|
+
else
|
|
18
|
+
RAMF::OperationRequest.new :method=>RAMF::Util.method_name(target_uri),
|
|
19
|
+
:service=>RAMF::Util.service_name(target_uri),
|
|
20
|
+
:args=>Array(value),
|
|
21
|
+
:credentials=>options[:credentials]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module RAMF
|
|
2
|
+
class AMFObject
|
|
3
|
+
|
|
4
|
+
AMF0_VERSION = 0x00
|
|
5
|
+
AMF3_VERSION = 0x03
|
|
6
|
+
|
|
7
|
+
FP_CLIENT = 0x01 #for Flash Player 8
|
|
8
|
+
FLASH_COM = 0x01 #for FlashCom/FMS
|
|
9
|
+
FP9_CLIENT =0x03 #for Flash Player 9
|
|
10
|
+
|
|
11
|
+
attr_accessor :version, :client, :headers, :messages
|
|
12
|
+
|
|
13
|
+
def initialize(options={})
|
|
14
|
+
@version = options[:version] || AMF3_VERSION
|
|
15
|
+
@client = options[:client] || FP9_CLIENT
|
|
16
|
+
@headers = options[:headers] || []
|
|
17
|
+
@messages = options[:messages] || []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_header(header)
|
|
21
|
+
@headers << header
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add_message(message)
|
|
25
|
+
@messages << message
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_header_by_key(key)
|
|
29
|
+
@headers.find {|v| v.name == key.to_s}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def credentials_header
|
|
33
|
+
(header = get_header_by_key("Credentials")) ? header.value : {:userid => nil, :password => nil}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def process(*processor_args)
|
|
37
|
+
returning(RAMF::AMFObject.new(:version=>version)) do |response|
|
|
38
|
+
response.messages = messages.map do |incoming_message|
|
|
39
|
+
operation = incoming_message.to_operation(:credentials=>credentials_header)
|
|
40
|
+
begin
|
|
41
|
+
RAMF::AMFMessage.new :target_uri=>incoming_message.response_uri + "/onResult",
|
|
42
|
+
:response_uri=>"",
|
|
43
|
+
:value=>RAMF::OperationProcessorsManager.process(operation, *processor_args)
|
|
44
|
+
rescue RAMF::OperationProcessorsManager::ErrorWhileProcessing => e
|
|
45
|
+
RAMF::AMFMessage.new :target_uri=>incoming_message.response_uri + "/onStatus",
|
|
46
|
+
:response_uri=>"",
|
|
47
|
+
:value=> operation.exception_response(e.original_exception)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class RAMF::DefaultOperationProcessor
|
|
2
|
+
class OperationProcessorNotDefined <StandardError; end;
|
|
3
|
+
|
|
4
|
+
#Add self to the operation processors manger list
|
|
5
|
+
RAMF::OperationProcessorsManager.add_operation_processor(self)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
|
|
10
|
+
#This processor answers all requests, so it will always return true
|
|
11
|
+
def will_process?(operation, *args)
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#raise a fault saying there is no processor to handle the operation.
|
|
16
|
+
def process(operation, *args)
|
|
17
|
+
raise(OperationProcessorNotDefined, "No Operation processor found to process #{operation.inspect}")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module RAMF
|
|
2
|
+
module Deserializer
|
|
3
|
+
class AMF0Reader
|
|
4
|
+
include RAMF::IO::Constants
|
|
5
|
+
include RAMF::IO::CommonReadWrite
|
|
6
|
+
include RAMF::IO::ReferenceTableUser
|
|
7
|
+
|
|
8
|
+
def initialize(reference_table = nil)
|
|
9
|
+
register_reference_table(reference_table)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def read_value_type(stream)
|
|
13
|
+
marker = readU8(stream)
|
|
14
|
+
case marker
|
|
15
|
+
when AMF3_TYPE
|
|
16
|
+
AMF3Reader.new(@reference_table).read_value_type(stream)
|
|
17
|
+
when AMF0_NUMBER
|
|
18
|
+
read_double(stream)
|
|
19
|
+
when AMF0_BOOLEAN
|
|
20
|
+
(readU8(stream) == 0) ? false : true
|
|
21
|
+
when AMF0_STRING
|
|
22
|
+
readUTF8(stream)
|
|
23
|
+
when AMF0_OBJECT
|
|
24
|
+
#TODO: implement this
|
|
25
|
+
readObject(stream)
|
|
26
|
+
when AMF0_ARRAY
|
|
27
|
+
read_strict_array(stream)
|
|
28
|
+
else
|
|
29
|
+
raise "unknown amf0 value marker 0x%02X" % marker
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def read_strict_array(stream)
|
|
36
|
+
array_length = readU32(stream)
|
|
37
|
+
array = []
|
|
38
|
+
array_length.times do
|
|
39
|
+
array << read_value_type(stream)
|
|
40
|
+
end
|
|
41
|
+
array
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def readObject(stream)
|
|
45
|
+
obj = Object.new
|
|
46
|
+
member_name = readUTF8(stream)
|
|
47
|
+
while (member_name != "") do #run until we get to the empty-string marker
|
|
48
|
+
obj.eval do
|
|
49
|
+
class << self
|
|
50
|
+
attr_accessor member_name.to_sym
|
|
51
|
+
end
|
|
52
|
+
self.send(member_name+"=",readUTF_8_vr(stream))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
module RAMF
|
|
2
|
+
module Deserializer
|
|
3
|
+
class AMF3Reader
|
|
4
|
+
include RAMF::IO::Constants
|
|
5
|
+
include RAMF::IO::CommonReadWrite
|
|
6
|
+
include RAMF::IO::ReferenceTableUser
|
|
7
|
+
|
|
8
|
+
def initialize(reference_table = nil)
|
|
9
|
+
register_reference_table(reference_table)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def read_value_type(stream)
|
|
13
|
+
marker = readU8(stream)
|
|
14
|
+
case marker
|
|
15
|
+
when AMF3_UNDEFINED
|
|
16
|
+
nil
|
|
17
|
+
when AMF3_NULL
|
|
18
|
+
nil
|
|
19
|
+
when AMF3_FALSE
|
|
20
|
+
false
|
|
21
|
+
when AMF3_TRUE
|
|
22
|
+
true
|
|
23
|
+
when AMF3_INTEGER
|
|
24
|
+
readU29(stream)
|
|
25
|
+
when AMF3_DOUBLE
|
|
26
|
+
read_double(stream)
|
|
27
|
+
when AMF3_STRING
|
|
28
|
+
readUTF_8_vr(stream)
|
|
29
|
+
when AMF3_XML_DOC
|
|
30
|
+
readU29X(stream)
|
|
31
|
+
when AMF3_XML
|
|
32
|
+
readU29X(stream)
|
|
33
|
+
when AMF3_DATE
|
|
34
|
+
readU29D(stream)
|
|
35
|
+
when AMF3_ARRAY
|
|
36
|
+
readU29A(stream)
|
|
37
|
+
when AMF3_OBJECT
|
|
38
|
+
readU29O(stream)
|
|
39
|
+
when AMF3_BYTE_ARRAY
|
|
40
|
+
readU29B(stream)
|
|
41
|
+
else
|
|
42
|
+
raise "unknown amf3 value marker 0x%02X" % marker
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
#reads an integer encoded as U29
|
|
48
|
+
def readU29(stream)
|
|
49
|
+
result = 0
|
|
50
|
+
4.times do |i|
|
|
51
|
+
part = readU8(stream)
|
|
52
|
+
result = readU29_part(part, i==3, result)
|
|
53
|
+
break if (part & 0x080)==0
|
|
54
|
+
end
|
|
55
|
+
result
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def readU29_part(part, is_last, rest)
|
|
59
|
+
if is_last
|
|
60
|
+
(rest << 8) | part
|
|
61
|
+
else
|
|
62
|
+
(rest << 7) | (part & 0x7f)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# U29 Strings:
|
|
67
|
+
def readU29S_value(length,stream)
|
|
68
|
+
(str = stream.read(length)) == "" ? str : store(:string){str}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def readU29S_ref(ref,stream)
|
|
72
|
+
#retrive string from reference tables
|
|
73
|
+
retrive :string, ref
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def readU29S(stream)
|
|
77
|
+
length_or_ref = readU29(stream)
|
|
78
|
+
#check if the string is a reference or value.
|
|
79
|
+
(length_or_ref & 0x01) == 0 ? readU29S_ref(length_or_ref>>1, stream) : readU29S_value(length_or_ref>>1, stream)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#U29 Objects:
|
|
83
|
+
def readU29O(stream)
|
|
84
|
+
member_count_or_ref = readU29(stream)
|
|
85
|
+
if (member_count_or_ref & 0x01) == 0
|
|
86
|
+
readU29O_ref(member_count_or_ref>>1) #The object is a reference
|
|
87
|
+
elsif (member_count_or_ref & 0x02) == 0
|
|
88
|
+
readU29O_traits_ref(stream, member_count_or_ref>>2) #the class is a reference, the object is new.
|
|
89
|
+
elsif (member_count_or_ref & 0x04) == 0x04
|
|
90
|
+
raise "can't read IExternalizable yet"
|
|
91
|
+
elsif (member_count_or_ref & 0x08) == 0
|
|
92
|
+
#new object of a non dynamic class
|
|
93
|
+
readU29O_traits(stream, member_count_or_ref>>4, false)
|
|
94
|
+
else
|
|
95
|
+
#new object of a dynamic class
|
|
96
|
+
readU29O_traits(stream, member_count_or_ref>>4, true)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def readU29O_ref(ref_id)
|
|
101
|
+
retrive :object, ref_id
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def readU29O_traits_ref(stream,ref_id)
|
|
105
|
+
flex_class = retrive :class, ref_id
|
|
106
|
+
readU29O_object_values(stream,flex_class)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def read_object_dynamic_members(stream, obj)
|
|
110
|
+
member_name = readUTF_8_vr(stream)
|
|
111
|
+
while (member_name != "") do #run until we get to the empty-string marker
|
|
112
|
+
obj.class.flex_remoting.dynamic_members_writer.call(obj, member_name, read_value_type(stream))
|
|
113
|
+
member_name = readUTF_8_vr(stream)
|
|
114
|
+
end
|
|
115
|
+
obj
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def readU29O_traits(stream, member_count,is_dynamic)
|
|
120
|
+
class_signature = store :class do
|
|
121
|
+
RAMF::IO::FlexClassSignature.new(readUTF_8_vr(stream), is_dynamic, read_object_member_names(stream,member_count))
|
|
122
|
+
end
|
|
123
|
+
# RAMF::DEBUG_LOG.debug "Created new class signature: #{class_signature.inspect}"
|
|
124
|
+
readU29O_object_values(stream,class_signature)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def readU29O_object_values(stream,class_signature)
|
|
128
|
+
store :object do
|
|
129
|
+
object = load_or_create_object(class_signature)
|
|
130
|
+
read_object_member_values(stream,class_signature,object)
|
|
131
|
+
read_object_dynamic_members(stream, object) if class_signature.is_dynamic
|
|
132
|
+
object
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def load_or_create_object(class_signature)
|
|
137
|
+
load_or_create_class(class_signature).new
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def load_or_create_class(class_signature)
|
|
141
|
+
return RAMF::FlexClassTraits.find_ruby_class(class_signature.name) if RAMF::FlexClassTraits.find_ruby_class(class_signature.name)
|
|
142
|
+
class_name = class_signature.name.to_s.split(".").each{|s| s[0,1]=s[0,1].upcase}.join("::")
|
|
143
|
+
unless class_name=="" || (/\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ class_name)
|
|
144
|
+
raise NameError, "#{class_name.inspect} is not a valid constant name!"
|
|
145
|
+
end
|
|
146
|
+
RAMF::FlexClassTraits.find_ruby_class(class_name) || (Object.module_eval(class_name) rescue create_class(class_signature))
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def create_class(class_signature)
|
|
150
|
+
class_name = class_signature.name.to_s.split(".").each{|s| s[0,1]=s[0,1].upcase}.join("::")
|
|
151
|
+
begin
|
|
152
|
+
Object.module_eval("class #{class_name};end;", __FILE__, __LINE__)
|
|
153
|
+
rescue NameError=>e
|
|
154
|
+
raise(NameError, "Could not create #{class_name}: #{e.message}")
|
|
155
|
+
end
|
|
156
|
+
klass = Object.module_eval(class_name, __FILE__, __LINE__)
|
|
157
|
+
klass.class_eval do
|
|
158
|
+
class_signature.members.each {|m| attr_accessor m}
|
|
159
|
+
end
|
|
160
|
+
# puts "Created new class:#{klass} with members:#{class_signature.members.join(',')}"
|
|
161
|
+
klass
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def read_object_member_names(stream,member_count)
|
|
165
|
+
members = []
|
|
166
|
+
member_count.times do
|
|
167
|
+
members << readUTF_8_vr(stream)
|
|
168
|
+
end
|
|
169
|
+
members
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def read_object_member_values(stream,flex_class,obj)
|
|
173
|
+
flex_class.members.each do|key|
|
|
174
|
+
value = read_value_type(stream)
|
|
175
|
+
obj.class.flex_remoting.members_writer.call(obj, key, value)
|
|
176
|
+
end
|
|
177
|
+
obj
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def readU29X(stream)
|
|
181
|
+
length_or_ref = readU29(stream)
|
|
182
|
+
#check if the XML is a reference or value.
|
|
183
|
+
#XML references are stored in the object reference table.
|
|
184
|
+
(length_or_ref & 0x01) == 0 ? readU29O_ref(length_or_ref>>1, stream) : readU29X_value(length_or_ref>>1, stream)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def readU29X_value(length, stream)
|
|
188
|
+
store :object do
|
|
189
|
+
defined?(REXML::Document) ? REXML::Document.new(stream.read(length)) : stream.read(length)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def readU29D(stream)
|
|
194
|
+
is_ref = readU29(stream)
|
|
195
|
+
#check if the Date is a reference or value.
|
|
196
|
+
#Date references are stored in the object reference table.
|
|
197
|
+
(is_ref & 0x01) == 0 ? readU29O_ref(is_ref>>1) : readU29D_value(stream)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def readU29D_value(stream)
|
|
201
|
+
store :object do
|
|
202
|
+
milisec_value = read_double(stream).to_f
|
|
203
|
+
Time.at(milisec_value/1000)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def readU29A(stream)
|
|
208
|
+
ref_or_length = readU29(stream)
|
|
209
|
+
#check if the Array is a reference or value.
|
|
210
|
+
#Array references are stored in the object reference table.
|
|
211
|
+
(ref_or_length & 0x01) == 0 ? readU29O_ref(ref_or_length>>1) : readU29A_value(ref_or_length>>1, stream)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def readU29A_value(dense_member_count, stream)
|
|
215
|
+
store :object do
|
|
216
|
+
obj = {}
|
|
217
|
+
read_object_dynamic_members(stream, obj)
|
|
218
|
+
obj = [] if obj.empty?
|
|
219
|
+
dense_member_count.times {|i| obj[i] = read_value_type(stream)}
|
|
220
|
+
obj
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def readU29B(stream)
|
|
225
|
+
ref_or_length = readU29(stream)
|
|
226
|
+
#check if the ByteArray is a reference or value.
|
|
227
|
+
#ByteArray references are stored in the object reference table.
|
|
228
|
+
(ref_or_length & 0x01) == 0 ? readU29O_ref(ref_or_length>>1) : readU29B_value(ref_or_length>>1, stream)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def readU29B_value(length,stream)
|
|
232
|
+
RAMF::FlexObjects::ByteArray.new(stream.read(length))
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def readUTF_8_vr(stream)
|
|
236
|
+
readU29S(stream)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module RAMF
|
|
2
|
+
module Deserializer
|
|
3
|
+
class Base
|
|
4
|
+
include RAMF::IO::CommonReadWrite
|
|
5
|
+
include RAMF::IO::ReferenceTableUser
|
|
6
|
+
|
|
7
|
+
class UnknowAMFVersion <StandardError; end;
|
|
8
|
+
|
|
9
|
+
def initialize(stream)
|
|
10
|
+
@stream = stream
|
|
11
|
+
@amf_object = RAMF::AMFObject.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def process
|
|
15
|
+
read_preamble
|
|
16
|
+
read_headers
|
|
17
|
+
read_messages
|
|
18
|
+
@amf_object
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def read_preamble
|
|
22
|
+
version = readU8(@stream)
|
|
23
|
+
raise UnknowAMFVersion, "Unknow amf version: #{version}" if version != 0 && version != 3
|
|
24
|
+
client = readU8(@stream)
|
|
25
|
+
@amf_object.version, @amf_object.client = version, client
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def read_headers
|
|
29
|
+
header_count = readU16(@stream)
|
|
30
|
+
header_count.times do
|
|
31
|
+
@amf_object.add_header(read_header)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def read_header
|
|
36
|
+
register_reference_table
|
|
37
|
+
#Read header's name
|
|
38
|
+
name = readUTF8(@stream)
|
|
39
|
+
#Read the 'must-understand' flag
|
|
40
|
+
must_understand = readU8(@stream)
|
|
41
|
+
#Read the header's length
|
|
42
|
+
length = readU32(@stream)
|
|
43
|
+
|
|
44
|
+
#Read header's value
|
|
45
|
+
value = AMF0Reader.new.read_value_type(@stream)
|
|
46
|
+
AMFHeader.new(name,value,must_understand, length)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def read_messages
|
|
50
|
+
message_count = readU16(@stream)
|
|
51
|
+
message_count.times do
|
|
52
|
+
@amf_object.add_message(read_message)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def read_message
|
|
57
|
+
|
|
58
|
+
#Read message's target_uri
|
|
59
|
+
target_uri = readUTF8(@stream)
|
|
60
|
+
#Read message's response_uri
|
|
61
|
+
response_uri = readUTF8(@stream)
|
|
62
|
+
#Read the message's length
|
|
63
|
+
length = readU32(@stream)
|
|
64
|
+
|
|
65
|
+
#Read message's value
|
|
66
|
+
value = AMF0Reader.new.read_value_type(@stream)
|
|
67
|
+
AMFMessage.new :target_uri=> target_uri,
|
|
68
|
+
:response_uri=> response_uri,
|
|
69
|
+
:value=> value,
|
|
70
|
+
:length=>length
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|